@spencerboucher/switchyard 0.16.0 → 0.17.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 (63) hide show
  1. package/README.md +1 -1
  2. package/dist/policies/worker.js +27 -1
  3. package/dist/switchyard.mjs +140 -15
  4. package/package.json +1 -1
  5. package/web-dist/assets/{AutomationView-D8xBiO8V.js → AutomationView-BMQuTl3j.js} +2 -2
  6. package/web-dist/assets/{AutomationView-D8xBiO8V.js.map → AutomationView-BMQuTl3j.js.map} +1 -1
  7. package/web-dist/assets/{InteractionCard-DebpdBi7.js → InteractionCard-CdBv3Sm7.js} +2 -2
  8. package/web-dist/assets/{InteractionCard-DebpdBi7.js.map → InteractionCard-CdBv3Sm7.js.map} +1 -1
  9. package/web-dist/assets/{Overlay-Dlhi9c84.js → Overlay-Cv0SIpoa.js} +2 -2
  10. package/web-dist/assets/{Overlay-Dlhi9c84.js.map → Overlay-Cv0SIpoa.js.map} +1 -1
  11. package/web-dist/assets/{Priority-C5Glky7C.js → Priority-aNWh1i4H.js} +2 -2
  12. package/web-dist/assets/{Priority-C5Glky7C.js.map → Priority-aNWh1i4H.js.map} +1 -1
  13. package/web-dist/assets/{Select-aZSSgs66.js → Select-Dv-F-HZR.js} +2 -2
  14. package/web-dist/assets/{Select-aZSSgs66.js.map → Select-Dv-F-HZR.js.map} +1 -1
  15. package/web-dist/assets/{Tabs-BtcfgH4N.js → Tabs-DPj-rKor.js} +2 -2
  16. package/web-dist/assets/{Tabs-BtcfgH4N.js.map → Tabs-DPj-rKor.js.map} +1 -1
  17. package/web-dist/assets/{UINodeRenderer-C6UI3QVH.js → UINodeRenderer-GbSP56mL.js} +2 -2
  18. package/web-dist/assets/{UINodeRenderer-C6UI3QVH.js.map → UINodeRenderer-GbSP56mL.js.map} +1 -1
  19. package/web-dist/assets/{ViewSelect-z38PW0fi.js → ViewSelect-DTXqcHvg.js} +2 -2
  20. package/web-dist/assets/{ViewSelect-z38PW0fi.js.map → ViewSelect-DTXqcHvg.js.map} +1 -1
  21. package/web-dist/assets/{attention-D6MFVno_.js → attention-eEYmUIPZ.js} +2 -2
  22. package/web-dist/assets/{attention-D6MFVno_.js.map → attention-eEYmUIPZ.js.map} +1 -1
  23. package/web-dist/assets/{auth-Dp9eZwp6.js → auth-e3n8h2VO.js} +2 -2
  24. package/web-dist/assets/{auth-Dp9eZwp6.js.map → auth-e3n8h2VO.js.map} +1 -1
  25. package/web-dist/assets/{automations-D7SN92MH.js → automations-DQMWPvqT.js} +2 -2
  26. package/web-dist/assets/{automations-D7SN92MH.js.map → automations-DQMWPvqT.js.map} +1 -1
  27. package/web-dist/assets/{board-dkcdNQmy.js → board-CxPUJBjR.js} +2 -2
  28. package/web-dist/assets/{board-dkcdNQmy.js.map → board-CxPUJBjR.js.map} +1 -1
  29. package/web-dist/assets/{code-CFjMSo7b.js → code-BfD33VCt.js} +16 -16
  30. package/web-dist/assets/code-BfD33VCt.js.map +1 -0
  31. package/web-dist/assets/{describe-DzuCgJir.js → describe-ype6dIHS.js} +2 -2
  32. package/web-dist/assets/{describe-DzuCgJir.js.map → describe-ype6dIHS.js.map} +1 -1
  33. package/web-dist/assets/{enroll-BTCRpn9h.js → enroll-BTNVVoWB.js} +2 -2
  34. package/web-dist/assets/{enroll-BTCRpn9h.js.map → enroll-BTNVVoWB.js.map} +1 -1
  35. package/web-dist/assets/index-BE-Sxt6h.css +2 -0
  36. package/web-dist/assets/{index-BWi8eZxK.js → index-xw7YOYjs.js} +4 -4
  37. package/web-dist/assets/{index-BWi8eZxK.js.map → index-xw7YOYjs.js.map} +1 -1
  38. package/web-dist/assets/{more-KjCC48BM.js → more-AZ4rHFG5.js} +2 -2
  39. package/web-dist/assets/{more-KjCC48BM.js.map → more-AZ4rHFG5.js.map} +1 -1
  40. package/web-dist/assets/{policyLogic-nylxViIk.js → policyLogic-AZSVROoe.js} +2 -2
  41. package/web-dist/assets/{policyLogic-nylxViIk.js.map → policyLogic-AZSVROoe.js.map} +1 -1
  42. package/web-dist/assets/{queue-BE-I-CIR.js → queue-LyV9HFK4.js} +2 -2
  43. package/web-dist/assets/{queue-BE-I-CIR.js.map → queue-LyV9HFK4.js.map} +1 -1
  44. package/web-dist/assets/{repo-DvbQh_v5.js → repo-CRmEGTNk.js} +2 -2
  45. package/web-dist/assets/{repo-DvbQh_v5.js.map → repo-CRmEGTNk.js.map} +1 -1
  46. package/web-dist/assets/{selection-DKEV1Jcg.js → selection-BgO3-HZn.js} +2 -2
  47. package/web-dist/assets/{selection-DKEV1Jcg.js.map → selection-BgO3-HZn.js.map} +1 -1
  48. package/web-dist/assets/{settings-CfHCWzlJ.js → settings-CK-9B48D.js} +2 -2
  49. package/web-dist/assets/{settings-CfHCWzlJ.js.map → settings-CK-9B48D.js.map} +1 -1
  50. package/web-dist/assets/states-D7g0-4EY.js +58 -0
  51. package/web-dist/assets/states-D7g0-4EY.js.map +1 -0
  52. package/web-dist/assets/{terminal-login-BFVSosBA.js → terminal-login-B20sSCfk.js} +2 -2
  53. package/web-dist/assets/{terminal-login-BFVSosBA.js.map → terminal-login-B20sSCfk.js.map} +1 -1
  54. package/web-dist/assets/{useNow-kkVAYV7Y.js → useNow-DvXAU3dJ.js} +2 -2
  55. package/web-dist/assets/{useNow-kkVAYV7Y.js.map → useNow-DvXAU3dJ.js.map} +1 -1
  56. package/web-dist/assets/{useResource-CiJX4Lk_.js → useResource-CFaJYaSY.js} +2 -2
  57. package/web-dist/assets/{useResource-CiJX4Lk_.js.map → useResource-CFaJYaSY.js.map} +1 -1
  58. package/web-dist/index.html +5 -5
  59. package/web-dist/sw.js +1 -1
  60. package/web-dist/assets/code-CFjMSo7b.js.map +0 -1
  61. package/web-dist/assets/index-B1pFvZNV.css +0 -2
  62. package/web-dist/assets/states-DOYtBI1P.js +0 -58
  63. package/web-dist/assets/states-DOYtBI1P.js.map +0 -1
package/README.md CHANGED
@@ -118,7 +118,7 @@ switchyard up
118
118
  ```sh
119
119
  docker run -d --name switchyard -p 127.0.0.1:7400:7400 -v switchyard-data:/data \
120
120
  -e SWITCHYARD_PUBLIC_URL=https://switchyard.example.com \
121
- ghcr.io/justmytwospence/switchyard:0.16.0
121
+ ghcr.io/justmytwospence/switchyard:0.17.0
122
122
  # Single sign-on is required off localhost: see docs/auth.md
123
123
  ```
124
124
 
@@ -2143,6 +2143,7 @@ var TermCoordinatorMsg = z12.discriminatedUnion("t", [
2143
2143
 
2144
2144
  // packages/protocol/dist/host-wire.js
2145
2145
  var Origin = z13.enum(["human", "automation"]);
2146
+ var DiffRev = z13.string().regex(/^(uncommitted|[0-9a-f]{40})$/);
2146
2147
  var HostCommand = z13.discriminatedUnion("type", [
2147
2148
  z13.object({
2148
2149
  type: z13.literal("session.start"),
@@ -2285,7 +2286,15 @@ var HostCommand = z13.discriminatedUnion("type", [
2285
2286
  type: z13.literal("workspace.diff"),
2286
2287
  path: z13.string(),
2287
2288
  base: z13.string().nullable(),
2288
- file: z13.string().nullable()
2289
+ file: z13.string().nullable(),
2290
+ /** Hosts without gitLog.v1 never receive it. */
2291
+ rev: DiffRev.optional()
2292
+ }),
2293
+ z13.object({
2294
+ type: z13.literal("workspace.log"),
2295
+ path: z13.string(),
2296
+ base: z13.string().nullable(),
2297
+ limit: z13.number().int().min(1).max(200)
2289
2298
  }),
2290
2299
  z13.object({ type: z13.literal("workspace.files"), path: z13.string(), dir: z13.string() }),
2291
2300
  z13.object({ type: z13.literal("workspace.readFile"), path: z13.string(), file: z13.string() }),
@@ -2369,6 +2378,23 @@ var ProjectSuggestion = z13.object({
2369
2378
  lastActivityAt: z13.string()
2370
2379
  });
2371
2380
  var ProjectSuggestions = z13.object({ suggestions: z13.array(ProjectSuggestion) });
2381
+ var GitCommit = z13.object({
2382
+ sha: z13.string().regex(/^[0-9a-f]{40}$/),
2383
+ subject: z13.string().max(300),
2384
+ author: z13.string().max(200),
2385
+ authoredAt: z13.string(),
2386
+ pushed: z13.boolean()
2387
+ });
2388
+ var LogResult = z13.object({
2389
+ /** The base branch the commits are counted from. */
2390
+ base: z13.string(),
2391
+ /** `branch`: commits since the merge base; `recent`: HEAD's latest commits (no commits of its own). */
2392
+ scope: z13.enum(["branch", "recent"]),
2393
+ commits: z13.array(GitCommit).max(200),
2394
+ truncated: z13.boolean(),
2395
+ /** Changed and untracked files not committed yet. */
2396
+ uncommitted: z13.number().int().min(0)
2397
+ });
2372
2398
  var DiffFile = z13.object({
2373
2399
  path: z13.string(),
2374
2400
  oldPath: z13.string().nullable(),
@@ -2221,6 +2221,8 @@ var TermCoordinatorMsg = z12.discriminatedUnion("t", [
2221
2221
 
2222
2222
  // packages/protocol/dist/host-wire.js
2223
2223
  var Origin = z13.enum(["human", "automation"]);
2224
+ var GIT_LOG_FEATURE = "gitLog.v1";
2225
+ var DiffRev = z13.string().regex(/^(uncommitted|[0-9a-f]{40})$/);
2224
2226
  var HostCommand = z13.discriminatedUnion("type", [
2225
2227
  z13.object({
2226
2228
  type: z13.literal("session.start"),
@@ -2363,7 +2365,15 @@ var HostCommand = z13.discriminatedUnion("type", [
2363
2365
  type: z13.literal("workspace.diff"),
2364
2366
  path: z13.string(),
2365
2367
  base: z13.string().nullable(),
2366
- file: z13.string().nullable()
2368
+ file: z13.string().nullable(),
2369
+ /** Hosts without gitLog.v1 never receive it. */
2370
+ rev: DiffRev.optional()
2371
+ }),
2372
+ z13.object({
2373
+ type: z13.literal("workspace.log"),
2374
+ path: z13.string(),
2375
+ base: z13.string().nullable(),
2376
+ limit: z13.number().int().min(1).max(200)
2367
2377
  }),
2368
2378
  z13.object({ type: z13.literal("workspace.files"), path: z13.string(), dir: z13.string() }),
2369
2379
  z13.object({ type: z13.literal("workspace.readFile"), path: z13.string(), file: z13.string() }),
@@ -2447,6 +2457,23 @@ var ProjectSuggestion = z13.object({
2447
2457
  lastActivityAt: z13.string()
2448
2458
  });
2449
2459
  var ProjectSuggestions = z13.object({ suggestions: z13.array(ProjectSuggestion) });
2460
+ var GitCommit = z13.object({
2461
+ sha: z13.string().regex(/^[0-9a-f]{40}$/),
2462
+ subject: z13.string().max(300),
2463
+ author: z13.string().max(200),
2464
+ authoredAt: z13.string(),
2465
+ pushed: z13.boolean()
2466
+ });
2467
+ var LogResult = z13.object({
2468
+ /** The base branch the commits are counted from. */
2469
+ base: z13.string(),
2470
+ /** `branch`: commits since the merge base; `recent`: HEAD's latest commits (no commits of its own). */
2471
+ scope: z13.enum(["branch", "recent"]),
2472
+ commits: z13.array(GitCommit).max(200),
2473
+ truncated: z13.boolean(),
2474
+ /** Changed and untracked files not committed yet. */
2475
+ uncommitted: z13.number().int().min(0)
2476
+ });
2450
2477
  var DiffFile = z13.object({
2451
2478
  path: z13.string(),
2452
2479
  oldPath: z13.string().nullable(),
@@ -12801,6 +12828,7 @@ function installBuiltins(app, ctx, opts = {}) {
12801
12828
  const lifetime = new AbortController();
12802
12829
  const policies = new PolicyService({
12803
12830
  store: ctx.store,
12831
+ evaluator: opts.policyEvaluator,
12804
12832
  get publicUrl() {
12805
12833
  return ctx.config.publicUrl;
12806
12834
  },
@@ -14176,6 +14204,10 @@ var HostHub = class {
14176
14204
  if (command.type === "session.deliverMessage" || command.type === "session.messageStatus") {
14177
14205
  return conn.features.has("agentRequests.v1");
14178
14206
  }
14207
+ if (command.type === "workspace.log")
14208
+ return conn.gitLog;
14209
+ if (command.type === "workspace.diff" && command.rev !== void 0)
14210
+ return conn.gitLog;
14179
14211
  if (command.type.startsWith("tracker."))
14180
14212
  return conn.trackers;
14181
14213
  if ((command.type === "session.start" || command.type === "dispatch.start") && command.policyRequired !== void 0) {
@@ -14318,7 +14350,8 @@ var HostHub = class {
14318
14350
  alive: true,
14319
14351
  features,
14320
14352
  github: hello.github !== void 0,
14321
- trackers: hello.features?.includes(TRACKERS_FEATURE) === true
14353
+ trackers: hello.features?.includes(TRACKERS_FEATURE) === true,
14354
+ gitLog: hello.features?.includes(GIT_LOG_FEATURE) === true
14322
14355
  });
14323
14356
  if (old && old.socket !== socket)
14324
14357
  old.socket.close(4e3, "replaced by a newer connection");
@@ -16860,7 +16893,8 @@ var ListQuery6 = z29.object({
16860
16893
  projectId: z29.string().optional(),
16861
16894
  includeArchived: z29.enum(["true", "false"]).optional()
16862
16895
  });
16863
- var DiffQuery = z29.object({ file: z29.string().optional() });
16896
+ var DiffQuery = z29.object({ file: z29.string().optional(), rev: DiffRev.optional() });
16897
+ var CommitsQuery = z29.object({ limit: z29.coerce.number().int().min(1).max(200).default(50) });
16864
16898
  var FilesQuery = z29.object({ dir: z29.string().default("") });
16865
16899
  var FileQuery = z29.object({ path: z29.string().min(1) });
16866
16900
  function registerWorkspaceRoutes(app, ctx) {
@@ -16903,7 +16937,19 @@ function registerWorkspaceRoutes(app, ctx) {
16903
16937
  type: "workspace.diff",
16904
16938
  path: ws.path,
16905
16939
  base: baseFor(ctx, ws),
16906
- file: q.file ?? null
16940
+ file: q.file ?? null,
16941
+ ...q.rev ? { rev: q.rev } : {}
16942
+ });
16943
+ });
16944
+ app.get("/api/workspaces/:id/commits", async (req) => {
16945
+ const ws = ctx.store.workspaces.require(req.params.id);
16946
+ const q = parse(CommitsQuery, req.query, "query");
16947
+ requireConnected(ctx, ws.hostId);
16948
+ return ctx.hostHub.request(ws.hostId, {
16949
+ type: "workspace.log",
16950
+ path: ws.path,
16951
+ base: baseFor(ctx, ws),
16952
+ limit: q.limit
16907
16953
  });
16908
16954
  });
16909
16955
  app.get("/api/workspaces/:id/files", async (req) => {
@@ -20721,7 +20767,7 @@ new file mode ${mode2}
20721
20767
  patch += "\\n";
20722
20768
  return { path: rel, lines, patch };
20723
20769
  }
20724
- async function diffWorkspace(path3, base, file) {
20770
+ async function branchPoint(path3, base) {
20725
20771
  const top = await realpathOr((await runGit(path3, ["rev-parse", "--show-toplevel"])).stdout.trim());
20726
20772
  const baseRef = base ?? (await inspectCheckout2(top)).defaultBranch;
20727
20773
  let mergeBase;
@@ -20730,10 +20776,30 @@ async function diffWorkspace(path3, base, file) {
20730
20776
  mergeBase = mb.stdout.trim();
20731
20777
  else
20732
20778
  mergeBase = await refResolves(top, "HEAD") ? "HEAD" : EMPTY_TREE;
20779
+ return { top, baseRef, mergeBase };
20780
+ }
20781
+ async function diffWorkspace(path3, base, file, rev = null) {
20782
+ const { top, baseRef, mergeBase } = await branchPoint(path3, base);
20783
+ let range = [mergeBase];
20784
+ let label = baseRef;
20785
+ let withUntracked = true;
20786
+ if (rev === "uncommitted") {
20787
+ range = [await refResolves(top, "HEAD") ? "HEAD" : EMPTY_TREE];
20788
+ label = "HEAD";
20789
+ } else if (rev !== null) {
20790
+ const exists2 = await runGit(top, ["cat-file", "-e", `${rev}^{commit}`], { allowFail: true });
20791
+ const onBranch = exists2.code === 0 ? await runGit(top, ["merge-base", "--is-ancestor", rev, "HEAD"], { allowFail: true }) : null;
20792
+ if (onBranch?.code !== 0) {
20793
+ throw new SwitchyardError("not_found", "That commit is not on this branch");
20794
+ }
20795
+ range = [await refResolves(top, `${rev}^`) ? `${rev}^` : EMPTY_TREE, rev];
20796
+ label = `${rev.slice(0, 7)}^`;
20797
+ withUntracked = false;
20798
+ }
20733
20799
  const [numstatOut, nameStatusOut, untrackedOut] = await Promise.all([
20734
- runGit(top, ["diff", "--no-color", "-M", "--numstat", "-z", mergeBase, "--"]),
20735
- runGit(top, ["diff", "--no-color", "-M", "--name-status", "-z", mergeBase, "--"]),
20736
- runGit(top, ["ls-files", "--others", "--exclude-standard", "-z"])
20800
+ runGit(top, ["diff", "--no-color", "-M", "--numstat", "-z", ...range, "--"]),
20801
+ runGit(top, ["diff", "--no-color", "-M", "--name-status", "-z", ...range, "--"]),
20802
+ withUntracked ? runGit(top, ["ls-files", "--others", "--exclude-standard", "-z"]) : Promise.resolve({ stdout: "", stderr: "", code: 0 })
20737
20803
  ]);
20738
20804
  const numstat = parseNumstat(numstatOut.stdout);
20739
20805
  const nameStatus = parseNameStatus(nameStatusOut.stdout);
@@ -20762,14 +20828,56 @@ async function diffWorkspace(path3, base, file) {
20762
20828
  status: "untracked"
20763
20829
  });
20764
20830
  }
20765
- const diffArgs = ["--literal-pathspecs", "diff", "--no-color", "-M", mergeBase, "--"];
20831
+ const diffArgs = ["--literal-pathspecs", "diff", "--no-color", "-M", ...range, "--"];
20766
20832
  if (file !== null)
20767
20833
  diffArgs.push(file);
20768
20834
  let patch = (await runGit(top, diffArgs)).stdout;
20769
20835
  for (const p of wanted)
20770
20836
  patch += untracked.get(p).patch;
20771
20837
  const limitPatch = file === null && Buffer.byteLength(patch, "utf8") > MAX_PATCH_BYTES;
20772
- return { base: baseRef, files, patch: limitPatch ? null : patch };
20838
+ return { base: label, files, patch: limitPatch ? null : patch };
20839
+ }
20840
+ async function logWorkspace(path3, base, limit) {
20841
+ const { top, baseRef, mergeBase } = await branchPoint(path3, base);
20842
+ const uncommitted = (await worktreeStatus(top, baseRef)).changedFiles;
20843
+ if (!await refResolves(top, "HEAD")) {
20844
+ return { base: baseRef, scope: "branch", commits: [], truncated: false, uncommitted };
20845
+ }
20846
+ const own = mergeBase !== "HEAD" && mergeBase !== EMPTY_TREE ? Number((await runGit(top, ["rev-list", "--count", `${mergeBase}..HEAD`])).stdout.trim()) : 0;
20847
+ const range = own > 0 ? `${mergeBase}..HEAD` : "HEAD";
20848
+ const out = await runGit(top, [
20849
+ "log",
20850
+ "-z",
20851
+ "--no-color",
20852
+ "--format=%H%x1f%an%x1f%aI%x1f%s",
20853
+ "-n",
20854
+ String(limit + 1),
20855
+ range
20856
+ ]);
20857
+ const rows = out.stdout.split("\0").map((r) => r.replace(/^\n+/, "")).filter((r) => r !== "").map((r) => r.split(""));
20858
+ const truncated = rows.length > limit;
20859
+ let upstream = null;
20860
+ const up2 = await runGit(top, ["rev-parse", "--verify", "--quiet", "@{u}"], { allowFail: true });
20861
+ if (up2.code === 0 && up2.stdout.trim() !== "")
20862
+ upstream = up2.stdout.trim();
20863
+ else {
20864
+ const br = await runGit(top, ["symbolic-ref", "--quiet", "--short", "HEAD"], {
20865
+ allowFail: true
20866
+ });
20867
+ const name = br.code === 0 ? br.stdout.trim() : "";
20868
+ if (name && await refResolves(top, `refs/remotes/origin/${name}`)) {
20869
+ upstream = `refs/remotes/origin/${name}`;
20870
+ }
20871
+ }
20872
+ const unpushed = upstream ? new Set((await runGit(top, ["rev-list", `${upstream}..HEAD`])).stdout.split("\n").map((l) => l.trim()).filter(Boolean)) : null;
20873
+ const commits = rows.slice(0, limit).map(([sha2 = "", author = "", at = "", subject = ""]) => ({
20874
+ sha: sha2,
20875
+ subject: subject.slice(0, 300),
20876
+ author: author.slice(0, 200),
20877
+ authoredAt: at,
20878
+ pushed: unpushed ? !unpushed.has(sha2) : false
20879
+ }));
20880
+ return { base: baseRef, scope: own > 0 ? "branch" : "recent", commits, truncated, uncommitted };
20773
20881
  }
20774
20882
  async function removeWorktree(opts) {
20775
20883
  let real;
@@ -24540,6 +24648,7 @@ var READ_ONLY_COMMANDS = /* @__PURE__ */ new Set([
24540
24648
  "workspace.discover",
24541
24649
  "workspace.status",
24542
24650
  "workspace.diff",
24651
+ "workspace.log",
24543
24652
  "workspace.files",
24544
24653
  "workspace.readFile",
24545
24654
  "workspace.prView",
@@ -24570,6 +24679,7 @@ var RERUNNABLE = /* @__PURE__ */ new Set([
24570
24679
  "workspace.discover",
24571
24680
  "workspace.status",
24572
24681
  "workspace.diff",
24682
+ "workspace.log",
24573
24683
  "workspace.files",
24574
24684
  "workspace.readFile",
24575
24685
  "workspace.prView",
@@ -24909,7 +25019,9 @@ var CommandRouter = class {
24909
25019
  case "workspace.remove":
24910
25020
  return workspaces.remove(c.path, c.checkoutPath, c.base, c.force, c.deleteBranch === true);
24911
25021
  case "workspace.diff":
24912
- return diffWorkspace(c.path, c.base, c.file);
25022
+ return diffWorkspace(c.path, c.base, c.file, c.rev ?? null);
25023
+ case "workspace.log":
25024
+ return logWorkspace(c.path, c.base, c.limit);
24913
25025
  case "workspace.files":
24914
25026
  return listDir(c.path, c.dir);
24915
25027
  case "workspace.readFile":
@@ -25554,7 +25666,7 @@ import WebSocket3 from "ws";
25554
25666
  var OUTBOX_RETENTION_MS = 24 * 60 * 60 * 1e3;
25555
25667
  var ACKED_META = "outbox.ackedHostSeq";
25556
25668
  var AGENT_FEATURES = ["agentRequests.v1", "policies.v1"];
25557
- var HOST_FEATURES = [TRACKERS_FEATURE];
25669
+ var HOST_FEATURES = [TRACKERS_FEATURE, GIT_LOG_FEATURE];
25558
25670
  function hostSocketUrl(coordinatorUrl) {
25559
25671
  const u = new URL(coordinatorUrl);
25560
25672
  if (u.protocol === "http:")
@@ -26813,6 +26925,7 @@ var ExternalSessionWatcher = class {
26813
26925
  // packages/host-agent/dist/github.js
26814
26926
  import { spawn as spawn4 } from "node:child_process";
26815
26927
  import { createHash as createHash10 } from "node:crypto";
26928
+ import { once } from "node:events";
26816
26929
  import { realpath as realpath7 } from "node:fs/promises";
26817
26930
 
26818
26931
  // packages/host-agent/dist/github-trackers.js
@@ -28116,8 +28229,16 @@ var GitHubService2 = class {
28116
28229
  const children2 = [...this.children];
28117
28230
  for (const child of children2)
28118
28231
  signalGroup(child, "SIGTERM");
28119
- if (children2.length || this.kills.size)
28120
- await new Promise((resolve16) => setTimeout(resolve16, 3e3));
28232
+ if (children2.length) {
28233
+ let grace;
28234
+ await Promise.race([
28235
+ Promise.all(children2.map((child) => child.exitCode !== null || child.signalCode !== null ? void 0 : once(child, "exit"))),
28236
+ new Promise((resolve16) => {
28237
+ grace = setTimeout(resolve16, 3e3);
28238
+ })
28239
+ ]);
28240
+ clearTimeout(grace);
28241
+ }
28121
28242
  for (const child of children2)
28122
28243
  signalGroup(child, "SIGKILL");
28123
28244
  for (const timer of this.kills)
@@ -31595,7 +31716,11 @@ async function runHostAgent(opts = {}) {
31595
31716
  policies: agentSupport,
31596
31717
  adapterDevelopment: true
31597
31718
  } : null,
31598
- features: [...agentSupport ? ["agentRequests.v1", "policies.v1"] : [], TRACKERS_FEATURE],
31719
+ features: [
31720
+ ...agentSupport ? ["agentRequests.v1", "policies.v1"] : [],
31721
+ TRACKERS_FEATURE,
31722
+ GIT_LOG_FEATURE
31723
+ ],
31599
31724
  protocolVersion: PROTOCOL_VERSION,
31600
31725
  github: github.github
31601
31726
  }),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@spencerboucher/switchyard",
3
- "version": "0.16.0",
3
+ "version": "0.17.0",
4
4
  "description": "Self-hosted hub for Pi coding agents: run them on your machines, drive them from your phone, browser or terminal",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -1,2 +1,2 @@
1
- import{S as e,_ as t,a as n,h as r,i,l as a,o,t as s,v as c,y as l}from"./Button-BKQW9doW.js";import{A as u,T as d,h as f,j as ee,k as p,l as m,t as te,w as h}from"./Overlay-Dlhi9c84.js";import{At as ne,Ft as g,It as _,L as v,M as re,Mt as ie,Nt as y,O as ae,at as b,c as x,f as S,i as oe,jt as C,m as w,n as T,r as E,s as se,t as D,tt as O,u as k}from"./states-DOYtBI1P.js";import{t as A}from"./calendar-clock-CwOgyN2z.js";import{n as ce,r as j}from"./Copy-D6U5ewFc.js";import{n as le,r as ue,t as de}from"./Priority-C5Glky7C.js";import{a as fe,c as pe,i as me,p as M,s as N,t as he}from"./useBreakpoint-kT0J1Dnk.js";import{t as ge}from"./play-j138GLHB.js";import{t as _e}from"./plus-D935l0Os.js";import{n as ve,t as ye}from"./DangerZone-Ch2KNmob.js";import{c as be,s as P,t as xe,u as Se}from"./policyLogic-nylxViIk.js";import{Kt as F,Yt as Ce,qt as I,tn as L}from"./index-BWi8eZxK.js";import{t as R}from"./TextLink-CCc3WEdm.js";import{t as z}from"./SegmentedControl-D2kj3j7u.js";import{t as B}from"./Card-WONLvqGM.js";import{t as V}from"./Select-aZSSgs66.js";import{t as H}from"./Switch-DHX-YYPr.js";import{E as U,O as we,S as Te,T as W,a as G,b as Ee,d as De,f as K,g as q,h as Oe,i as ke,l as Ae,m as je,n as Me,o as Ne,p as J,r as Pe,s as Fe,t as Ie,u as Le,v as Re,w as Y,x as ze,y as Be}from"./describe-DzuCgJir.js";var Ve={name:`scroll-text`,size:24,node:[[`path`,{d:`M15 12h-5`,key:`r7krc0`}],[`path`,{d:`M15 8h-5`,key:`1khuty`}],[`path`,{d:`M19 17V5a2 2 0 0 0-2-2H4`,key:`zz82l3`}],[`path`,{d:`M8 21h12a2 2 0 0 0 2-2v-1a1 1 0 0 0-1-1H11a1 1 0 0 0-1 1v1a2 2 0 1 1-4 0V5a2 2 0 1 0-4 0v2a1 1 0 0 0 1 1h3`,key:`1ph1d7`}]]};Ve.node;var He=o(Ve),X=e(l(),1),Z=i(),Ue=e=>`/tasks/${encodeURIComponent(e)}`;function Q(e){return _(e)&&(e.status===404||e.status===405||e.status===501)}function We({summary:e,errorCount:t}){return(0,Z.jsxs)(B,{stack:!0,title:`Summary`,testId:`automation-summary`,children:[(0,Z.jsx)(`p`,{className:`text-sm break-words`,children:e}),t>0&&(0,Z.jsxs)(`p`,{className:`flex items-center gap-1.5 text-sm text-danger`,children:[(0,Z.jsx)(w,{"aria-hidden":!0,className:`size-4 shrink-0`}),t===1?`1 field needs attention`:`${t} fields need attention`]})]})}async function Ge(e,t,n){return e&&!n?C(Y(e,`/preview`)):y(`/api/automations/preview`,t)}function Ke({automationId:e,dirty:t,getInput:n,currentKey:r}){let[i,a]=(0,X.useState)({status:`idle`}),o=async()=>{let r=n();if(!r)N.error(`Fix the highlighted fields to preview the task`);else{a({status:`loading`});try{let n=await Ge(e,r,t);a({status:`done`,preview:n,key:JSON.stringify(r)})}catch(e){a(Q(e)?{status:`unsupported`}:{status:`error`,error:e})}}};return(0,Z.jsxs)(B,{stack:!0,title:`Preview`,description:`See the task an occurrence would create, and when it would run next.`,testId:`automation-preview`,children:[(0,Z.jsx)(`div`,{children:(0,Z.jsx)(s,{icon:(0,Z.jsx)(d,{className:`size-4`}),busy:i.status===`loading`,onClick:()=>void o(),children:`Preview resulting task`})}),i.status===`unsupported`&&(0,Z.jsx)(k,{capability:`Task preview`,reason:`This coordinator does not offer automation previews.`,fallback:`Read the summary above, or save and use Run now to see a real task.`}),i.status===`error`&&(0,Z.jsx)(T,{compact:!0,title:`Could not preview`,error:i.error,onRetry:()=>void o()}),i.status===`done`&&(0,Z.jsx)(qe,{preview:i.preview,stale:i.key!==r})]})}function qe({preview:e,stale:t}){let{task:n}=e;return(0,Z.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-3`,children:[t&&(0,Z.jsxs)(`p`,{className:`flex items-center gap-1.5 text-xs text-warning`,role:`status`,children:[(0,Z.jsx)(w,{"aria-hidden":!0,className:`size-3.5 shrink-0`}),`The form changed since this preview. Preview again to refresh it.`]}),(0,Z.jsx)(`p`,{className:`text-sm break-words text-muted`,children:e.summary}),(0,Z.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-2 rounded-md border border-border bg-surface-2 p-3`,children:[(0,Z.jsxs)(`div`,{className:`flex min-w-0 items-start justify-between gap-2`,children:[(0,Z.jsx)(`h3`,{className:`min-w-0 font-medium break-words`,children:n.title}),(0,Z.jsx)(le,{priority:n.priority,muted:!0,className:`shrink-0 text-xs`})]}),n.objective?(0,Z.jsx)(`p`,{className:`text-sm break-words whitespace-pre-wrap`,children:n.objective}):(0,Z.jsx)(`p`,{className:`text-sm text-muted`,children:`No objective.`}),n.acceptanceCriteria.length>0&&(0,Z.jsxs)(`div`,{children:[(0,Z.jsxs)(`h4`,{className:`flex items-center gap-1 text-xs font-medium text-muted`,children:[(0,Z.jsx)(h,{"aria-hidden":!0,className:`size-3.5`}),`Acceptance criteria`]}),(0,Z.jsx)(`ul`,{className:`mt-1 list-disc pl-5 text-sm`,children:n.acceptanceCriteria.map((e,t)=>(0,Z.jsx)(`li`,{className:`break-words`,children:e},t))})]})]}),(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`h3`,{className:`text-sm font-medium`,children:`Next occurrences`}),e.next.length===0?(0,Z.jsx)(`p`,{className:`text-sm text-muted`,children:`No scheduled times: this trigger fires on demand, on a webhook, or when a task is done.`}):(0,Z.jsx)(`ol`,{className:`mt-1 flex flex-col gap-0.5 text-sm`,children:e.next.slice(0,5).map(e=>(0,Z.jsxs)(`li`,{className:`flex flex-wrap gap-x-2`,children:[(0,Z.jsx)(`time`,{dateTime:e,children:J(e)}),(0,Z.jsx)(`span`,{className:`text-muted`,children:S(e)})]},e))})]})]})}function Je({label:e,value:t,mono:n=!0}){return(0,Z.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-1`,children:[(0,Z.jsx)(`span`,{className:`text-xs font-medium text-muted`,children:e}),(0,Z.jsxs)(`div`,{className:`flex min-w-0 items-start gap-2`,children:[(0,Z.jsx)(`code`,{className:`min-w-0 flex-1 rounded border border-border bg-surface px-2 py-1.5 text-xs break-all select-all ${n?`font-mono`:``}`,children:t}),(0,Z.jsx)(s,{size:`sm`,icon:(0,Z.jsx)(j,{className:`size-3.5`}),onClick:()=>void ce(t,`${e} copied`),"aria-label":`Copy ${e.toLowerCase()}`,children:`Copy`})]})]})}function Ye({automation:e}){let[t,n]=(0,X.useState)(!1),[r,i]=(0,X.useState)(!1),[a,o]=(0,X.useState)(null),[c,l]=(0,X.useState)(!1),d=e.webhookTokenSet||a!==null,f=async()=>{i(!1),n(!0);try{let t=await y(Y(e.id,`/webhook-token`)),n=O.safeParse(t);if(!n.success)throw Error(`The coordinator returned an unexpected token response`);let r=new URL(n.data.url,window.location.origin).toString();o({token:n.data.token,url:r}),N.success(d?`Webhook token rotated`:`Webhook token created`)}catch(e){Q(e)?l(!0):N.error(`Could not issue a webhook token: ${g(e)}`)}finally{n(!1)}};return(0,Z.jsxs)(B,{stack:!0,title:`Webhook`,description:`POST JSON to the URL with the token as a Bearer header. Filters decide which payloads fire.`,testId:`webhook-token`,children:[(0,Z.jsx)(`p`,{className:`flex items-center gap-1.5 text-sm`,children:d?(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(M,{"aria-hidden":!0,className:`size-4 shrink-0 text-success`}),`A token is set`]}):(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(u,{"aria-hidden":!0,className:`size-4 shrink-0 text-muted`}),`No token yet: webhook calls are rejected until you create one`]})}),c?(0,Z.jsx)(k,{capability:`Webhook tokens`,reason:`This coordinator does not issue webhook tokens.`}):(0,Z.jsx)(`div`,{children:(0,Z.jsx)(s,{icon:(0,Z.jsx)(L,{className:`size-4`}),busy:t,onClick:()=>d?i(!0):void f(),children:d?`Rotate token`:`Create token`})}),a&&(0,Z.jsxs)(`div`,{role:`alert`,className:`flex min-w-0 flex-col gap-3 rounded-md border border-warning bg-warning-soft p-3`,children:[(0,Z.jsxs)(`p`,{className:`flex items-center gap-1.5 text-sm font-medium`,children:[(0,Z.jsx)(w,{"aria-hidden":!0,className:`size-4 shrink-0 text-warning`}),`This token is shown once. Copy it now.`]}),(0,Z.jsx)(Je,{label:`Token`,value:a.token}),(0,Z.jsx)(Je,{label:`URL`,value:a.url}),(0,Z.jsx)(Je,{label:`Example`,value:Ne(a.token,a.url)}),(0,Z.jsx)(`div`,{children:(0,Z.jsx)(s,{size:`sm`,onClick:()=>o(null),children:`I have copied it`})})]}),(0,Z.jsx)(te,{open:r,onClose:()=>i(!1),title:`Rotate webhook token?`,description:`The current token stops working immediately. Update every sender with the new token.`,confirmLabel:`Rotate token`,busy:t,onConfirm:()=>void f()})]})}var Xe=[];function Ze({automationId:e,refreshKey:t,onRun:n}){let r=v(t=>t.occurrences[e]??Xe),i=v(e=>e.tasks),[a,o]=(0,X.useState)({status:`loading`}),s=(0,X.useCallback)(async t=>{o(e=>e.status===`done`?e:{status:`loading`});try{let n=await C(Y(e,`/history`),{},t);o({status:`done`,items:Re(n)})}catch(e){if(t?.aborted)return;o(Q(e)?{status:`unsupported`}:{status:`error`,error:e})}},[e]);(0,X.useEffect)(()=>{let e=new AbortController;return s(e.signal),()=>e.abort()},[s,t]);let c=q(a.status===`done`?a.items:[],r);return(0,Z.jsxs)(B,{stack:!0,title:`History`,description:`Occurrences of this automation. Routine successes are hidden from the board and appear only here.`,testId:`automation-history`,children:[a.status===`unsupported`&&(0,Z.jsx)(k,{capability:`Automation history`,reason:`This coordinator does not serve stored history; only occurrences seen live in this session are shown.`}),a.status===`error`&&(0,Z.jsx)(T,{compact:!0,title:`Could not load history`,error:a.error,onRetry:()=>void s()}),a.status===`loading`&&c.length===0?(0,Z.jsx)(x,{label:`Loading history…`,className:`py-4`}):c.length===0&&a.status!==`error`?(0,Z.jsx)(D,{className:`py-4`,icon:(0,Z.jsx)(He,{className:`size-6`}),title:`No occurrences yet`,description:`Occurrences appear here when the trigger fires or you run it.`,action:{label:`Run now`,onClick:n,icon:(0,Z.jsx)(ge,{className:`size-4`})}}):(0,Z.jsx)(`ol`,{className:`flex flex-col divide-y divide-border`,children:c.map(e=>{let t=Be(e),n=e.taskId?i[e.taskId]:void 0,r=[e.reason,e.outcome].filter(Boolean).join(` · `);return(0,Z.jsxs)(`li`,{className:`flex min-w-0 flex-col gap-1 py-2 first:pt-0 last:pb-0`,children:[(0,Z.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-2 gap-y-1`,children:[(0,Z.jsx)(f,{kind:`occurrence`,value:e.state,size:`sm`}),(0,Z.jsx)(`time`,{dateTime:t,className:`text-sm`,children:J(t)}),(0,Z.jsx)(`span`,{className:`text-xs text-muted`,children:S(t)})]}),r&&(0,Z.jsx)(`p`,{className:`text-sm break-words text-muted`,children:r}),e.taskId&&(0,Z.jsxs)(R,{to:Ue(e.taskId),variant:`action`,size:`sm`,className:`self-start`,children:[(0,Z.jsx)(`span`,{className:`min-w-0 truncate`,children:n?`Task: ${n.title}`:`Open task`}),n?.hiddenFromBoard&&(0,Z.jsx)(`span`,{className:`shrink-0 text-xs text-muted`,children:`(hidden from board)`})]})]},e.id)})})]})}var Qe=`/automations`,$e=e=>`/automations/${encodeURIComponent(e)}`,et=`sy:automation-draft`;function tt(){let{automationId:e=`new`}=c();return(0,Z.jsx)(nt,{automationId:e},e)}function nt({automationId:e}){let t=e===`new`,n=v(e=>e.hydrated),r=U(t?void 0:e),[i,a]=(0,X.useState)({status:`idle`}),o=(0,X.useCallback)(async()=>{a({status:`loading`});try{let t=await C(Y(e)),n=b.safeParse(t);if(!n.success){a({status:`fatal`,error:Error(`The coordinator returned this automation in an unexpected format.`)});return}W.getState().put(n.data),a({status:`idle`})}catch(e){_(e)&&e.status===404?a({status:`notfound`}):a({status:`error`,error:e})}},[e]),s=!t&&!r;return(0,X.useEffect)(()=>{s&&i.status===`idle`&&o()},[s,i.status,o]),t?(0,Z.jsx)(ot,{automation:null}):r?(0,Z.jsx)(ot,{automation:r}):i.status===`notfound`?(0,Z.jsx)(D,{icon:(0,Z.jsx)(Ce,{className:`size-8`}),title:`Automation not found`,description:`It may have been deleted, or the link is wrong.`,action:{label:`Back to automations`,to:Qe}}):i.status===`error`?(0,Z.jsx)(T,{title:`Could not load this automation`,error:i.error,onRetry:()=>void o()}):i.status===`fatal`?(0,Z.jsx)(E,{error:i.error}):(0,Z.jsx)(x,{label:n?`Loading automation…`:`Loading…`})}function rt(e){let t=De({projectId:e,timezone:Oe()});try{let e=sessionStorage.getItem(et);if(!e)return t;let n=JSON.parse(e);return!n||typeof n!=`object`?t:{...t,...n,filters:Array.isArray(n.filters)?n.filters:[]}}catch{return t}}function it(e){try{e?sessionStorage.setItem(et,JSON.stringify(e)):sessionStorage.removeItem(et)}catch{}}var $=e=>JSON.stringify(Le(e));function at(e){if(!_(e))return{};let t=e.details,n=Array.isArray(t)?t:t&&typeof t==`object`&&Array.isArray(t.issues)?t.issues:[],r={};for(let e of n){if(!e||typeof e!=`object`)continue;let{path:t,message:n}=e;if(!Array.isArray(t)||typeof n!=`string`)continue;let i=K(t);i!==`form`&&!r[i]&&(r[i]=n)}return r}function ot({automation:e}){let i=t(),o=r(),c=fe(Qe),l=he(),u=l===`desktop`,d=re(),f=ae(),m=v(e=>e.hosts),h=v(e=>e.profiles),_=v(e=>e.tasks),b=v(e=>e.projects),x=e===null,S=(0,X.useId)(),C=(0,X.useRef)(null),[T,E]=(0,X.useState)(()=>e?Ae(e):rt(d[0]?.id)),[D,O]=(0,X.useState)(()=>$(T)),[k,A]=(0,X.useState)(!1),[ce,j]=(0,X.useState)({}),[le,ue]=(0,X.useState)(!1),[de,M]=(0,X.useState)(!1),[_e,P]=(0,X.useState)(!1),[xe,F]=(0,X.useState)(!1),[Ce,I]=(0,X.useState)(0),L=(0,X.useRef)(e?.updatedAt),R=$(T),z=R!==D;(0,X.useEffect)(()=>{if(!e||e.updatedAt===L.current)return;L.current=e.updatedAt;let t=Ae(e),n=$(t);R===D?(E(t),F(!1)):n!==R&&F(!0),O(n)},[e,R,D]),(0,X.useEffect)(()=>{x&&it(T)},[x,T]),(0,X.useEffect)(()=>{x&&!T.projectId&&d[0]&&E(e=>e.projectId?e:{...e,projectId:d[0].id})},[x,T.projectId,d]);let B=(0,X.useCallback)((e,t)=>{E(n=>({...n,[e]:t})),j(e=>Object.keys(e).length?{}:e)},[]),V=(0,X.useMemo)(()=>Te(T),[T]),H={...ce,...k?V.errors:{}},U=e=>H[e],G=b[T.projectId],K=T.hostId||G?.defaultHostId||null,q=K?m[K]:void 0,ke=T.profileId||G?.defaultProfileId||null,je=(0,X.useCallback)(e=>_[e]?.title,[_]),Me=(0,X.useMemo)(()=>Ee(Le(T),{projectName:G?.name,hostName:T.hostId?m[T.hostId]?.name??null:null,profileName:T.profileId?h[T.profileId]?.name??null:null,taskTitle:je}),[T,G?.name,m,h,je]),Ne=()=>{requestAnimationFrame(()=>{C.current?.querySelector(`[aria-invalid="true"]`)?.focus()})},J=()=>(A(!0),V.input||Ne(),V.input),Pe=async()=>{let t=J();if(!t)N.error(`Fix the highlighted fields before saving`);else{ue(!0);try{if(x){let e=await y(`/api/automations`,t);if(!e||typeof e!=`object`||!e.id)throw Error(`The coordinator did not return the new automation`);W.getState().put(e),it(null),N.success(`Created ${e.name}`),i($e(e.id),{replace:!0,state:o.state});return}let n=await ie(Y(e.id),t);if(n&&typeof n==`object`&&n.id){W.getState().put(n),L.current=n.updatedAt;let e=Ae(n);E(e),O($(e))}else O(R);F(!1),A(!1),N.success(`Saved ${t.name}`)}catch(e){let t=at(e);j(t),Object.keys(t).length&&Ne(),N.error(`Could not save: ${g(e)}. Your changes are kept.`)}finally{ue(!1)}}},Fe=async()=>{if(e){M(!0);try{await ne(Y(e.id)),P(!1),N.success(`Deleted ${e.name}`),c(),W.getState().remove(e.id)}catch(e){N.error(`Could not delete: ${g(e)}`)}finally{M(!1)}}},{busy:Ie,run:Re}=we(()=>I(e=>e+1)),ze=e?!!Ie[e.id]:!1,Be=()=>e&&void Re(e),Ve=()=>{let e=De({projectId:d[0]?.id,timezone:Oe()});E(e),A(!1),it(null)},He=x?`New automation`:e.name,Ue=(0,Z.jsxs)(Z.Fragment,{children:[!x&&(0,Z.jsx)(s,{icon:(0,Z.jsx)(ge,{className:`size-4`}),busy:ze,onClick:Be,title:z?`Runs the saved version`:void 0,children:`Run now`}),x&&z&&(0,Z.jsx)(s,{variant:`ghost`,icon:(0,Z.jsx)(pe,{className:`size-4`}),onClick:Ve,children:`Discard draft`})]}),Q=e=>(0,Z.jsx)(s,{type:`submit`,form:S,variant:`primary`,busy:le,block:e,icon:(0,Z.jsx)(ve,{className:`size-4`}),children:x?`Create automation`:`Save`}),Ge=(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(We,{summary:Me,errorCount:k?Object.keys(V.errors).length:0}),(0,Z.jsx)(Ke,{automationId:e?.id??null,dirty:z,getInput:J,currentKey:JSON.stringify(V.input)}),e&&e.trigger.kind===`webhook`&&(0,Z.jsx)(Ye,{automation:e}),e&&(0,Z.jsx)(Ze,{automationId:e.id,refreshKey:Ce,onRun:Be})]});return(0,Z.jsxs)(`div`,{"data-testid":`automation-editor`,className:`flex w-full min-w-0 flex-col gap-4 px-4 pt-4 md:px-6`,children:[(0,Z.jsxs)(`header`,{className:`flex min-w-0 flex-col gap-2`,children:[(0,Z.jsxs)(a,{to:Qe,onClick:me(c),className:`tap inline-flex items-center gap-1 self-start rounded text-sm text-muted hover:text-text`,children:[(0,Z.jsx)(ee,{"aria-hidden":!0,className:`size-4`}),`Automations`]}),(0,Z.jsxs)(`div`,{className:`flex min-w-0 flex-wrap items-center justify-between gap-2`,children:[(0,Z.jsxs)(`div`,{className:`flex min-w-0 flex-wrap items-center gap-2`,children:[(0,Z.jsx)(`h1`,{className:`min-w-0 text-lg font-semibold break-words`,children:He}),z&&(0,Z.jsxs)(`span`,{className:`inline-flex items-center gap-1 text-xs text-muted`,children:[(0,Z.jsx)(p,{"aria-hidden":!0,className:`size-3.5`}),`Unsaved changes`]})]}),(0,Z.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[Ue,u&&Q()]})]})]}),(0,Z.jsx)(se,{subject:`automations`,consequence:`Changes are sent once the coordinator is reachable again.`}),q&&q.connectivity!==`connected`&&(0,Z.jsx)(oe,{compact:!0,hostName:q.name,connectivity:q.connectivity,lastSeenAt:q.lastSeenAt,detail:`Occurrences are still recorded; their tasks wait until the host is reachable.`}),xe&&(0,Z.jsxs)(`p`,{role:`status`,className:`flex items-start gap-1.5 rounded-md border border-border bg-warning-soft px-3 py-2 text-sm`,children:[(0,Z.jsx)(w,{"aria-hidden":!0,className:`mt-0.5 size-4 shrink-0 text-warning`}),`This automation changed elsewhere. Saving overwrites those changes with yours.`]}),(0,Z.jsxs)(`div`,{className:n(`grid min-w-0 gap-4`,u?`grid-cols-[minmax(0,1fr)_minmax(320px,400px)] items-start`:`grid-cols-1`),children:[(0,Z.jsxs)(`form`,{id:S,ref:C,noValidate:!0,"aria-label":He,onSubmit:e=>{e.preventDefault(),Pe()},className:`flex min-w-0 flex-col gap-4`,children:[(0,Z.jsx)(st,{draft:T,update:B,err:U,projects:d}),(0,Z.jsx)(ut,{draft:T,update:B,err:U,tasks:_,projectsById:b,savedAutomation:e,segmented:l!==`mobile`}),(0,Z.jsx)(dt,{draft:T,setDraft:E,err:U}),(0,Z.jsx)(ft,{draft:T,update:B,err:U}),(0,Z.jsx)(mt,{draft:T,update:B,err:U,hosts:f,profiles:Object.values(h).sort((e,t)=>e.name.localeCompare(t.name)),defaultHostName:G?.defaultHostId?m[G.defaultHostId]?.name:void 0,defaultProfileName:G?.defaultProfileId?h[G.defaultProfileId]?.name:void 0,selectedProfileMissing:!!ke&&!h[ke]}),(0,Z.jsx)(ht,{draft:T,update:B}),(0,Z.jsx)(gt,{draft:T,update:B,err:U}),(0,Z.jsx)(_t,{draft:T,update:B,err:U,projectChecks:G?.checks}),H.form&&(0,Z.jsx)(be,{children:H.form})]}),(0,Z.jsx)(`aside`,{"aria-label":`Summary, preview and history`,className:`flex min-w-0 flex-col gap-4`,children:Ge})]}),!x&&e&&(0,Z.jsx)(ye,{description:`Future occurrences stop. Tasks it already created stay on the board; its history is removed.`,children:(0,Z.jsx)(s,{variant:`danger`,icon:(0,Z.jsx)(Se,{className:`size-4`}),onClick:()=>P(!0),children:`Delete automation`})}),u?(0,Z.jsx)(`div`,{className:`h-4`}):(0,Z.jsxs)(`div`,{className:`sticky bottom-0 z-10 -mx-4 flex items-center gap-3 border-t border-border bg-surface px-4 py-2 md:-mx-6 md:px-6`,children:[(0,Z.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-sm text-muted`,children:z?`Unsaved changes`:x?`Not saved yet`:`All changes saved`}),Q()]}),(0,Z.jsx)(te,{open:_e,onClose:()=>P(!1),title:`Delete ${e?.name??`automation`}?`,description:`Future occurrences stop. Tasks it already created stay on the board; its history is removed.`,confirmLabel:`Delete automation`,confirmIcon:(0,Z.jsx)(Se,{className:`size-4`}),busy:de,onConfirm:()=>void Fe()})]})}function st({draft:e,update:t,err:n,projects:r}){return(0,Z.jsxs)(B,{stack:!0,title:`Basics`,children:[(0,Z.jsx)(P,{label:`Name`,error:n(`name`),children:n=>(0,Z.jsx)(I,{...n,value:e.name,onChange:e=>t(`name`,e.target.value),placeholder:`Daily dependency check`,autoComplete:`off`})}),(0,Z.jsxs)(`div`,{className:`grid gap-4 sm:grid-cols-2`,children:[(0,Z.jsx)(P,{label:`Project`,error:n(`projectId`),hint:r.length===0?(0,Z.jsxs)(Z.Fragment,{children:[`No projects yet.`,` `,(0,Z.jsx)(R,{to:`/settings/projects`,children:`Add a project in Settings`}),`.`]}):void 0,children:n=>(0,Z.jsxs)(V,{...n,value:e.projectId,onChange:e=>t(`projectId`,e.target.value),children:[(0,Z.jsx)(`option`,{value:``,children:`Choose a project`}),r.map(e=>(0,Z.jsx)(`option`,{value:e.id,children:e.name},e.id))]})}),(0,Z.jsx)(P,{label:`Status`,hint:`Disabled automations keep their history and can still run manually.`,children:n=>(0,Z.jsx)(H,{...n,checked:e.enabled,onChange:e=>t(`enabled`,e),label:`Enabled`,onText:`Enabled`,offText:`Disabled`,className:`self-start`})})]})]})}var ct=[`manual`,`once`,`cron`,`webhook`,`dependency`],lt={manual:`Runs only when you press Run now (or from the CLI).`,once:`Runs a single time at the chosen moment.`,cron:`Runs on a timezone-aware cron schedule.`,webhook:`Runs when an authenticated JSON POST arrives at this automation's webhook URL.`,dependency:`Runs when the chosen task is done.`};function ut({draft:e,update:t,err:n,tasks:r,projectsById:i,savedAutomation:a,segmented:o}){let s=v(e=>e.hydrated),c=e.triggerKind===`cron`?ze(e.cronExpr):null,l=e.triggerKind===`cron`&&!c?Fe(e.cronExpr,e.cronTimezone.trim()||void 0)??`Valid expression (no plain-language description available)`:null,u=(0,X.useMemo)(()=>{try{return Intl.supportedValuesOf?.(`timeZone`)}catch{return}},[]),d=(0,X.useId)(),f=Oe(),ee=(0,X.useMemo)(()=>Object.values(r).filter(t=>t.state!==`canceled`||t.id===e.dependencyTaskId).sort((e,t)=>e.title.localeCompare(t.title)),[r,e.dependencyTaskId]),p=e.triggerKind===`once`?je(e.onceAt):``;return(0,Z.jsxs)(B,{stack:!0,title:`Trigger`,description:lt[e.triggerKind],children:[o?(0,Z.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-1`,children:[(0,Z.jsx)(`span`,{"aria-hidden":!0,className:`text-sm font-medium`,children:`Trigger kind`}),(0,Z.jsx)(`div`,{className:`overflow-x-auto`,children:(0,Z.jsx)(z,{label:`Trigger kind`,value:e.triggerKind,onChange:e=>t(`triggerKind`,e),options:ct.map(e=>({value:e,label:G[e]}))})})]}):(0,Z.jsx)(P,{label:`Trigger kind`,children:n=>(0,Z.jsx)(V,{...n,value:e.triggerKind,onChange:e=>t(`triggerKind`,e.target.value),children:ct.map(e=>(0,Z.jsx)(`option`,{value:e,children:G[e]},e))})}),e.triggerKind===`once`&&(0,Z.jsx)(P,{label:`Run at`,error:n(`onceAt`),hint:`Local time (${f})${p?`; saved as ${p}`:``}.`,children:n=>(0,Z.jsx)(I,{...n,type:`datetime-local`,value:e.onceAt,onChange:e=>t(`onceAt`,e.target.value)})}),e.triggerKind===`cron`&&(0,Z.jsxs)(`div`,{className:`grid gap-4 sm:grid-cols-2`,children:[(0,Z.jsx)(P,{label:`Cron expression`,error:n(`cronExpr`)??c??void 0,hint:`minute hour day-of-month month day-of-week, e.g. 0 9 * * 1-5`,children:n=>(0,Z.jsx)(I,{...n,"aria-invalid":c?!0:n[`aria-invalid`],value:e.cronExpr,onChange:e=>t(`cronExpr`,e.target.value),className:`font-mono`,autoComplete:`off`,spellCheck:!1,autoCapitalize:`off`})}),(0,Z.jsx)(P,{label:`Timezone`,error:n(`cronTimezone`),hint:e.cronTimezone.trim()===f?`IANA timezone name; daylight saving is handled.`:(0,Z.jsxs)(R,{onClick:()=>t(`cronTimezone`,f),children:[`Use this device's timezone (`,f,`)`]}),children:n=>(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(I,{...n,list:u?d:void 0,value:e.cronTimezone,onChange:e=>t(`cronTimezone`,e.target.value),autoComplete:`off`,spellCheck:!1,autoCapitalize:`off`}),u&&(0,Z.jsx)(`datalist`,{id:d,children:u.map(e=>(0,Z.jsx)(`option`,{value:e},e))})]})}),l&&(0,Z.jsxs)(`p`,{className:`flex items-start gap-1.5 text-sm sm:col-span-2`,"aria-live":`polite`,"data-testid":`cron-description`,children:[(0,Z.jsx)(A,{"aria-hidden":!0,className:`mt-0.5 size-4 shrink-0 text-muted`}),(0,Z.jsx)(`span`,{className:`min-w-0 break-words`,children:l})]})]}),e.triggerKind===`webhook`&&(0,Z.jsxs)(`div`,{className:`flex flex-col gap-1 text-sm text-muted`,children:[(0,Z.jsxs)(`p`,{children:[`Senders POST a JSON body (up to 256 KB) with`,` `,(0,Z.jsx)(`code`,{children:`Authorization: Bearer <token>`}),`. Use the filters below to fire only for matching payloads, and `,(0,Z.jsx)(`code`,{children:`{{payload.<path>}}`}),` to copy payload values into the task.`]}),a?a.trigger.kind===`webhook`?(0,Z.jsxs)(`p`,{children:[`Token:`,` `,a.webhookTokenSet?`set (see Webhook below to rotate)`:`not created yet`]}):(0,Z.jsx)(`p`,{children:`Save to switch this automation to a webhook trigger, then create a token.`}):(0,Z.jsx)(`p`,{children:`Save the automation to create its webhook token and URL.`})]}),e.triggerKind===`dependency`&&(0,Z.jsx)(P,{label:`When this task is done`,error:n(`dependencyTaskId`),hint:`Fires once each time the task enters Done.`,children:n=>(0,Z.jsxs)(V,{...n,value:e.dependencyTaskId,onChange:e=>t(`dependencyTaskId`,e.target.value),children:[(0,Z.jsx)(`option`,{value:``,children:`Choose a task`}),e.dependencyTaskId&&!r[e.dependencyTaskId]&&(0,Z.jsx)(`option`,{value:e.dependencyTaskId,children:s?`Deleted task`:`Loading task…`}),ee.map(e=>(0,Z.jsxs)(`option`,{value:e.id,children:[e.title,i[e.projectId]?` (${i[e.projectId].name})`:``,e.state===`done`?` - done`:``]},e.id))]})})]})}function dt({draft:e,setDraft:t,err:n}){let r=(e,n)=>t(t=>({...t,filters:t.filters.map((t,r)=>r===e?{...t,...n}:t)})),i=e.triggerKind===`webhook`;return(0,Z.jsxs)(B,{stack:!0,title:`Filters`,description:`Filters apply to webhook payloads. Each row compares a dot path (for example pull_request.base.ref) with an exact value; all rows must match. Payloads that do not match are recorded as Filtered out.`,children:[!i&&(0,Z.jsx)(`p`,{className:`text-sm text-muted`,children:`Filters are ignored unless the trigger is Webhook.`}),e.filters.length===0&&(0,Z.jsx)(`p`,{className:`text-sm text-muted`,children:`No filters: every payload fires.`}),e.filters.map((e,i)=>(0,Z.jsxs)(`div`,{className:`grid min-w-0 grid-cols-[minmax(0,1fr)_auto] items-end gap-2 sm:grid-cols-[minmax(0,1fr)_minmax(0,1fr)_auto]`,children:[(0,Z.jsx)(P,{label:`Path ${i+1}`,error:n(`filters.${i}.path`),children:t=>(0,Z.jsx)(I,{...t,value:e.path,onChange:e=>r(i,{path:e.target.value}),placeholder:`action`,className:`font-mono`,autoCapitalize:`off`,spellCheck:!1})}),(0,Z.jsx)(P,{label:`Equals ${i+1}`,error:n(`filters.${i}.equals`),className:`col-start-1 row-start-2 sm:col-start-auto sm:row-start-auto`,children:t=>(0,Z.jsx)(I,{...t,value:e.equals,onChange:e=>r(i,{equals:e.target.value}),placeholder:`opened`})}),(0,Z.jsx)(m,{label:`Remove filter ${i+1}`,icon:(0,Z.jsx)(pe,{className:`size-4`}),onClick:()=>t(e=>({...e,filters:e.filters.filter((e,t)=>t!==i)}))})]},i)),(0,Z.jsx)(`div`,{children:(0,Z.jsx)(s,{size:`sm`,icon:(0,Z.jsx)(_e,{className:`size-3.5`}),onClick:()=>t(e=>({...e,filters:[...e.filters,{path:``,equals:``}]})),children:`Add filter`})})]})}function ft({draft:e,update:t,err:n}){return(0,Z.jsxs)(B,{stack:!0,title:`Task template`,description:`Use ${ke.join(`, `)} in the title, objective, criteria and grouping key.`,children:[(0,Z.jsx)(P,{label:`Task title`,error:n(`title`),children:n=>(0,Z.jsx)(I,{...n,value:e.title,onChange:e=>t(`title`,e.target.value),placeholder:`Triage new issues for {{date}}`})}),(0,Z.jsx)(P,{label:`Objective`,error:n(`objective`),children:n=>(0,Z.jsx)(F,{...n,minRows:4,value:e.objective,onChange:e=>t(`objective`,e.target.value)})}),(0,Z.jsx)(P,{label:`Acceptance criteria`,error:n(`criteria`),hint:`One criterion per line.`,optional:!0,children:n=>(0,Z.jsx)(F,{...n,minRows:3,value:e.criteria,onChange:e=>t(`criteria`,e.target.value)})}),(0,Z.jsx)(P,{label:`Priority`,error:n(`priority`),children:n=>(0,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Z.jsx)(de,{priority:e.priority}),(0,Z.jsx)(ue,{...n,value:e.priority,onChange:e=>t(`priority`,e),className:`sm:max-w-48`})]})})]})}function pt({legend:e,value:t,options:r,onChange:i,hint:a}){let o=(0,X.useId)();return(0,Z.jsxs)(`fieldset`,{className:`flex min-w-0 flex-col gap-2`,children:[(0,Z.jsx)(`legend`,{className:`mb-1 text-sm font-medium`,children:e}),(0,Z.jsx)(`div`,{className:`grid min-w-0 gap-2 sm:grid-cols-3`,children:r.map(e=>(0,Z.jsxs)(`label`,{className:n(`tap flex min-w-0 cursor-pointer items-start gap-2 rounded-md border p-2.5 text-sm`,`has-[:focus-visible]:outline-2 has-[:focus-visible]:outline-offset-1`,t===e.value?`border-accent bg-accent-soft`:`border-border hover:bg-surface-2`),children:[(0,Z.jsx)(`input`,{type:`radio`,name:o,value:e.value,checked:t===e.value,onChange:()=>i(e.value),className:`mt-0.5 size-4 shrink-0 accent-[var(--color-accent)]`}),(0,Z.jsxs)(`span`,{className:`min-w-0`,children:[(0,Z.jsx)(`span`,{className:`block font-medium`,children:e.label}),(0,Z.jsx)(`span`,{className:`block text-xs text-muted`,children:e.explanation})]})]},e.value))}),a&&(0,Z.jsx)(`p`,{className:`text-xs text-muted`,children:a})]})}function mt({draft:e,update:t,err:n,hosts:r,profiles:i,defaultHostName:a,defaultProfileName:o,selectedProfileMissing:s}){return(0,Z.jsxs)(B,{stack:!0,title:`Where and how it runs`,children:[(0,Z.jsxs)(`div`,{className:`grid gap-4 sm:grid-cols-2`,children:[(0,Z.jsx)(P,{label:`Host`,error:n(`hostId`),children:n=>(0,Z.jsxs)(V,{...n,value:e.hostId,onChange:e=>t(`hostId`,e.target.value),children:[(0,Z.jsxs)(`option`,{value:``,children:[`Project default`,a?` (${a})`:``]}),e.hostId&&!r.some(t=>t.id===e.hostId)&&(0,Z.jsx)(`option`,{value:e.hostId,children:`Unknown host`}),r.map(e=>(0,Z.jsxs)(`option`,{value:e.id,children:[e.name,e.connectivity===`connected`?``:` (${e.connectivity})`]},e.id))]})}),(0,Z.jsx)(P,{label:`Profile`,error:n(`profileId`),hint:s?`The selected profile is no longer available.`:void 0,children:n=>(0,Z.jsxs)(V,{...n,value:e.profileId,onChange:e=>t(`profileId`,e.target.value),children:[(0,Z.jsxs)(`option`,{value:``,children:[`Project default`,o?` (${o})`:``]}),e.profileId&&!i.some(t=>t.id===e.profileId)&&(0,Z.jsx)(`option`,{value:e.profileId,children:`Unknown profile`}),i.map(e=>(0,Z.jsx)(`option`,{value:e.id,children:e.name},e.id))]})})]}),(0,Z.jsx)(pt,{legend:`Mode`,value:e.mode,options:Me,onChange:e=>t(`mode`,e)}),(0,Z.jsx)(P,{label:`Grouping key`,optional:e.mode!==`continue`,error:n(`groupingKey`),hint:`Occurrences with the same rendered key are the same work: Continue reuses that task and overlap checks compare it. Supports template variables, e.g. pr-{{payload.number}}.`,children:n=>(0,Z.jsx)(I,{...n,value:e.groupingKey,onChange:e=>t(`groupingKey`,e.target.value),className:`font-mono`,autoCapitalize:`off`,spellCheck:!1})})]})}function ht({draft:e,update:t}){let n=e.triggerKind===`cron`||e.triggerKind===`once`;return(0,Z.jsxs)(B,{stack:!0,title:`Overlap and missed runs`,children:[(0,Z.jsx)(pt,{legend:`When previous work is still open`,value:e.overlap,options:Pe,onChange:e=>t(`overlap`,e)}),(0,Z.jsx)(pt,{legend:`Missed runs`,value:e.missed,options:Ie,onChange:e=>t(`missed`,e),hint:n?`A run is missed when the coordinator was down at its scheduled time.`:`Only applies to Schedule and Once triggers.`})]})}function gt({draft:e,update:t,err:n}){return(0,Z.jsxs)(B,{stack:!0,title:`Limits`,description:`Continuation prompts the agent to keep going after a turn ends without finishing. It is off by default.`,children:[(0,Z.jsx)(P,{label:`Automatic continuation`,children:n=>(0,Z.jsx)(H,{...n,checked:e.continuationEnabled,onChange:e=>t(`continuationEnabled`,e),label:`Automatic continuation`,className:`self-start`})}),e.continuationEnabled&&(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(P,{label:`Continuation objective`,error:n(`continuationObjective`),hint:`What the agent must achieve before it reports done.`,children:n=>(0,Z.jsx)(F,{...n,minRows:2,value:e.continuationObjective,onChange:e=>t(`continuationObjective`,e.target.value)})}),(0,Z.jsxs)(`div`,{className:`grid gap-4 sm:grid-cols-2`,children:[(0,Z.jsx)(P,{label:`Max continuations`,error:n(`maxContinuations`),hint:`1–50`,children:n=>(0,Z.jsx)(I,{...n,type:`number`,inputMode:`numeric`,min:1,max:50,step:1,value:e.maxContinuations,onChange:e=>t(`maxContinuations`,e.target.value)})}),(0,Z.jsx)(P,{label:`Max elapsed minutes`,error:n(`maxElapsedMinutes`),hint:`1–1440`,children:n=>(0,Z.jsx)(I,{...n,type:`number`,inputMode:`numeric`,min:1,max:1440,step:1,value:e.maxElapsedMinutes,onChange:e=>t(`maxElapsedMinutes`,e.target.value)})}),(0,Z.jsx)(P,{label:`Continuation budget: tokens`,optional:!0,error:n(`maxTokens`),children:n=>(0,Z.jsx)(I,{...n,type:`number`,inputMode:`numeric`,min:1,step:1,value:e.maxTokens,onChange:e=>t(`maxTokens`,e.target.value)})}),(0,Z.jsx)(P,{label:`Continuation budget: cost (USD)`,optional:!0,error:n(`maxCostUsd`),children:n=>(0,Z.jsx)(I,{...n,type:`number`,inputMode:`decimal`,min:.01,step:.01,value:e.maxCostUsd,onChange:e=>t(`maxCostUsd`,e.target.value)})})]}),(0,Z.jsx)(`p`,{className:`text-xs text-muted`,children:xe})]})]})}function _t({draft:e,update:t,err:n,projectChecks:r}){let i=r&&r.length>0?`the project's checks (${r.join(`, `)})`:`the project's checks`;return(0,Z.jsxs)(B,{stack:!0,title:`Review`,children:[(0,Z.jsx)(P,{label:`Checks`,optional:!0,error:n(`checks`),hint:`One command per line. Leave empty to use ${i}.`,children:n=>(0,Z.jsx)(F,{...n,minRows:2,value:e.checks,onChange:e=>t(`checks`,e.target.value),className:`font-mono`,spellCheck:!1,autoCapitalize:`off`})}),(0,Z.jsx)(P,{label:`Human review`,hint:`When on, finished work waits in Review for you instead of completing on passing checks.`,children:n=>(0,Z.jsx)(H,{...n,checked:e.requireHumanReview,onChange:e=>t(`requireHumanReview`,e),label:`Require human review`,onText:`Required`,offText:`Not required`,className:`self-start`})})]})}export{tt as default};
2
- //# sourceMappingURL=AutomationView-D8xBiO8V.js.map
1
+ import{S as e,_ as t,a as n,h as r,i,l as a,o,t as s,v as c,y as l}from"./Button-BKQW9doW.js";import{A as u,T as d,h as f,j as ee,k as p,l as m,t as te,w as h}from"./Overlay-Cv0SIpoa.js";import{At as ne,Ft as g,It as _,L as v,M as re,Mt as ie,Nt as y,O as ae,at as b,c as x,f as S,i as oe,jt as C,m as w,n as T,r as E,s as se,t as D,tt as O,u as k}from"./states-D7g0-4EY.js";import{t as A}from"./calendar-clock-CwOgyN2z.js";import{n as ce,r as j}from"./Copy-D6U5ewFc.js";import{n as le,r as ue,t as de}from"./Priority-aNWh1i4H.js";import{a as fe,c as pe,i as me,p as M,s as N,t as he}from"./useBreakpoint-kT0J1Dnk.js";import{t as ge}from"./play-j138GLHB.js";import{t as _e}from"./plus-D935l0Os.js";import{n as ve,t as ye}from"./DangerZone-Ch2KNmob.js";import{c as be,s as P,t as xe,u as Se}from"./policyLogic-AZSVROoe.js";import{Kt as F,Yt as Ce,qt as I,tn as L}from"./index-xw7YOYjs.js";import{t as R}from"./TextLink-CCc3WEdm.js";import{t as z}from"./SegmentedControl-D2kj3j7u.js";import{t as B}from"./Card-WONLvqGM.js";import{t as V}from"./Select-Dv-F-HZR.js";import{t as H}from"./Switch-DHX-YYPr.js";import{E as U,O as we,S as Te,T as W,a as G,b as Ee,d as De,f as K,g as q,h as Oe,i as ke,l as Ae,m as je,n as Me,o as Ne,p as J,r as Pe,s as Fe,t as Ie,u as Le,v as Re,w as Y,x as ze,y as Be}from"./describe-ype6dIHS.js";var Ve={name:`scroll-text`,size:24,node:[[`path`,{d:`M15 12h-5`,key:`r7krc0`}],[`path`,{d:`M15 8h-5`,key:`1khuty`}],[`path`,{d:`M19 17V5a2 2 0 0 0-2-2H4`,key:`zz82l3`}],[`path`,{d:`M8 21h12a2 2 0 0 0 2-2v-1a1 1 0 0 0-1-1H11a1 1 0 0 0-1 1v1a2 2 0 1 1-4 0V5a2 2 0 1 0-4 0v2a1 1 0 0 0 1 1h3`,key:`1ph1d7`}]]};Ve.node;var He=o(Ve),X=e(l(),1),Z=i(),Ue=e=>`/tasks/${encodeURIComponent(e)}`;function Q(e){return _(e)&&(e.status===404||e.status===405||e.status===501)}function We({summary:e,errorCount:t}){return(0,Z.jsxs)(B,{stack:!0,title:`Summary`,testId:`automation-summary`,children:[(0,Z.jsx)(`p`,{className:`text-sm break-words`,children:e}),t>0&&(0,Z.jsxs)(`p`,{className:`flex items-center gap-1.5 text-sm text-danger`,children:[(0,Z.jsx)(w,{"aria-hidden":!0,className:`size-4 shrink-0`}),t===1?`1 field needs attention`:`${t} fields need attention`]})]})}async function Ge(e,t,n){return e&&!n?C(Y(e,`/preview`)):y(`/api/automations/preview`,t)}function Ke({automationId:e,dirty:t,getInput:n,currentKey:r}){let[i,a]=(0,X.useState)({status:`idle`}),o=async()=>{let r=n();if(!r)N.error(`Fix the highlighted fields to preview the task`);else{a({status:`loading`});try{let n=await Ge(e,r,t);a({status:`done`,preview:n,key:JSON.stringify(r)})}catch(e){a(Q(e)?{status:`unsupported`}:{status:`error`,error:e})}}};return(0,Z.jsxs)(B,{stack:!0,title:`Preview`,description:`See the task an occurrence would create, and when it would run next.`,testId:`automation-preview`,children:[(0,Z.jsx)(`div`,{children:(0,Z.jsx)(s,{icon:(0,Z.jsx)(d,{className:`size-4`}),busy:i.status===`loading`,onClick:()=>void o(),children:`Preview resulting task`})}),i.status===`unsupported`&&(0,Z.jsx)(k,{capability:`Task preview`,reason:`This coordinator does not offer automation previews.`,fallback:`Read the summary above, or save and use Run now to see a real task.`}),i.status===`error`&&(0,Z.jsx)(T,{compact:!0,title:`Could not preview`,error:i.error,onRetry:()=>void o()}),i.status===`done`&&(0,Z.jsx)(qe,{preview:i.preview,stale:i.key!==r})]})}function qe({preview:e,stale:t}){let{task:n}=e;return(0,Z.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-3`,children:[t&&(0,Z.jsxs)(`p`,{className:`flex items-center gap-1.5 text-xs text-warning`,role:`status`,children:[(0,Z.jsx)(w,{"aria-hidden":!0,className:`size-3.5 shrink-0`}),`The form changed since this preview. Preview again to refresh it.`]}),(0,Z.jsx)(`p`,{className:`text-sm break-words text-muted`,children:e.summary}),(0,Z.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-2 rounded-md border border-border bg-surface-2 p-3`,children:[(0,Z.jsxs)(`div`,{className:`flex min-w-0 items-start justify-between gap-2`,children:[(0,Z.jsx)(`h3`,{className:`min-w-0 font-medium break-words`,children:n.title}),(0,Z.jsx)(le,{priority:n.priority,muted:!0,className:`shrink-0 text-xs`})]}),n.objective?(0,Z.jsx)(`p`,{className:`text-sm break-words whitespace-pre-wrap`,children:n.objective}):(0,Z.jsx)(`p`,{className:`text-sm text-muted`,children:`No objective.`}),n.acceptanceCriteria.length>0&&(0,Z.jsxs)(`div`,{children:[(0,Z.jsxs)(`h4`,{className:`flex items-center gap-1 text-xs font-medium text-muted`,children:[(0,Z.jsx)(h,{"aria-hidden":!0,className:`size-3.5`}),`Acceptance criteria`]}),(0,Z.jsx)(`ul`,{className:`mt-1 list-disc pl-5 text-sm`,children:n.acceptanceCriteria.map((e,t)=>(0,Z.jsx)(`li`,{className:`break-words`,children:e},t))})]})]}),(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`h3`,{className:`text-sm font-medium`,children:`Next occurrences`}),e.next.length===0?(0,Z.jsx)(`p`,{className:`text-sm text-muted`,children:`No scheduled times: this trigger fires on demand, on a webhook, or when a task is done.`}):(0,Z.jsx)(`ol`,{className:`mt-1 flex flex-col gap-0.5 text-sm`,children:e.next.slice(0,5).map(e=>(0,Z.jsxs)(`li`,{className:`flex flex-wrap gap-x-2`,children:[(0,Z.jsx)(`time`,{dateTime:e,children:J(e)}),(0,Z.jsx)(`span`,{className:`text-muted`,children:S(e)})]},e))})]})]})}function Je({label:e,value:t,mono:n=!0}){return(0,Z.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-1`,children:[(0,Z.jsx)(`span`,{className:`text-xs font-medium text-muted`,children:e}),(0,Z.jsxs)(`div`,{className:`flex min-w-0 items-start gap-2`,children:[(0,Z.jsx)(`code`,{className:`min-w-0 flex-1 rounded border border-border bg-surface px-2 py-1.5 text-xs break-all select-all ${n?`font-mono`:``}`,children:t}),(0,Z.jsx)(s,{size:`sm`,icon:(0,Z.jsx)(j,{className:`size-3.5`}),onClick:()=>void ce(t,`${e} copied`),"aria-label":`Copy ${e.toLowerCase()}`,children:`Copy`})]})]})}function Ye({automation:e}){let[t,n]=(0,X.useState)(!1),[r,i]=(0,X.useState)(!1),[a,o]=(0,X.useState)(null),[c,l]=(0,X.useState)(!1),d=e.webhookTokenSet||a!==null,f=async()=>{i(!1),n(!0);try{let t=await y(Y(e.id,`/webhook-token`)),n=O.safeParse(t);if(!n.success)throw Error(`The coordinator returned an unexpected token response`);let r=new URL(n.data.url,window.location.origin).toString();o({token:n.data.token,url:r}),N.success(d?`Webhook token rotated`:`Webhook token created`)}catch(e){Q(e)?l(!0):N.error(`Could not issue a webhook token: ${g(e)}`)}finally{n(!1)}};return(0,Z.jsxs)(B,{stack:!0,title:`Webhook`,description:`POST JSON to the URL with the token as a Bearer header. Filters decide which payloads fire.`,testId:`webhook-token`,children:[(0,Z.jsx)(`p`,{className:`flex items-center gap-1.5 text-sm`,children:d?(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(M,{"aria-hidden":!0,className:`size-4 shrink-0 text-success`}),`A token is set`]}):(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(u,{"aria-hidden":!0,className:`size-4 shrink-0 text-muted`}),`No token yet: webhook calls are rejected until you create one`]})}),c?(0,Z.jsx)(k,{capability:`Webhook tokens`,reason:`This coordinator does not issue webhook tokens.`}):(0,Z.jsx)(`div`,{children:(0,Z.jsx)(s,{icon:(0,Z.jsx)(L,{className:`size-4`}),busy:t,onClick:()=>d?i(!0):void f(),children:d?`Rotate token`:`Create token`})}),a&&(0,Z.jsxs)(`div`,{role:`alert`,className:`flex min-w-0 flex-col gap-3 rounded-md border border-warning bg-warning-soft p-3`,children:[(0,Z.jsxs)(`p`,{className:`flex items-center gap-1.5 text-sm font-medium`,children:[(0,Z.jsx)(w,{"aria-hidden":!0,className:`size-4 shrink-0 text-warning`}),`This token is shown once. Copy it now.`]}),(0,Z.jsx)(Je,{label:`Token`,value:a.token}),(0,Z.jsx)(Je,{label:`URL`,value:a.url}),(0,Z.jsx)(Je,{label:`Example`,value:Ne(a.token,a.url)}),(0,Z.jsx)(`div`,{children:(0,Z.jsx)(s,{size:`sm`,onClick:()=>o(null),children:`I have copied it`})})]}),(0,Z.jsx)(te,{open:r,onClose:()=>i(!1),title:`Rotate webhook token?`,description:`The current token stops working immediately. Update every sender with the new token.`,confirmLabel:`Rotate token`,busy:t,onConfirm:()=>void f()})]})}var Xe=[];function Ze({automationId:e,refreshKey:t,onRun:n}){let r=v(t=>t.occurrences[e]??Xe),i=v(e=>e.tasks),[a,o]=(0,X.useState)({status:`loading`}),s=(0,X.useCallback)(async t=>{o(e=>e.status===`done`?e:{status:`loading`});try{let n=await C(Y(e,`/history`),{},t);o({status:`done`,items:Re(n)})}catch(e){if(t?.aborted)return;o(Q(e)?{status:`unsupported`}:{status:`error`,error:e})}},[e]);(0,X.useEffect)(()=>{let e=new AbortController;return s(e.signal),()=>e.abort()},[s,t]);let c=q(a.status===`done`?a.items:[],r);return(0,Z.jsxs)(B,{stack:!0,title:`History`,description:`Occurrences of this automation. Routine successes are hidden from the board and appear only here.`,testId:`automation-history`,children:[a.status===`unsupported`&&(0,Z.jsx)(k,{capability:`Automation history`,reason:`This coordinator does not serve stored history; only occurrences seen live in this session are shown.`}),a.status===`error`&&(0,Z.jsx)(T,{compact:!0,title:`Could not load history`,error:a.error,onRetry:()=>void s()}),a.status===`loading`&&c.length===0?(0,Z.jsx)(x,{label:`Loading history…`,className:`py-4`}):c.length===0&&a.status!==`error`?(0,Z.jsx)(D,{className:`py-4`,icon:(0,Z.jsx)(He,{className:`size-6`}),title:`No occurrences yet`,description:`Occurrences appear here when the trigger fires or you run it.`,action:{label:`Run now`,onClick:n,icon:(0,Z.jsx)(ge,{className:`size-4`})}}):(0,Z.jsx)(`ol`,{className:`flex flex-col divide-y divide-border`,children:c.map(e=>{let t=Be(e),n=e.taskId?i[e.taskId]:void 0,r=[e.reason,e.outcome].filter(Boolean).join(` · `);return(0,Z.jsxs)(`li`,{className:`flex min-w-0 flex-col gap-1 py-2 first:pt-0 last:pb-0`,children:[(0,Z.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-2 gap-y-1`,children:[(0,Z.jsx)(f,{kind:`occurrence`,value:e.state,size:`sm`}),(0,Z.jsx)(`time`,{dateTime:t,className:`text-sm`,children:J(t)}),(0,Z.jsx)(`span`,{className:`text-xs text-muted`,children:S(t)})]}),r&&(0,Z.jsx)(`p`,{className:`text-sm break-words text-muted`,children:r}),e.taskId&&(0,Z.jsxs)(R,{to:Ue(e.taskId),variant:`action`,size:`sm`,className:`self-start`,children:[(0,Z.jsx)(`span`,{className:`min-w-0 truncate`,children:n?`Task: ${n.title}`:`Open task`}),n?.hiddenFromBoard&&(0,Z.jsx)(`span`,{className:`shrink-0 text-xs text-muted`,children:`(hidden from board)`})]})]},e.id)})})]})}var Qe=`/automations`,$e=e=>`/automations/${encodeURIComponent(e)}`,et=`sy:automation-draft`;function tt(){let{automationId:e=`new`}=c();return(0,Z.jsx)(nt,{automationId:e},e)}function nt({automationId:e}){let t=e===`new`,n=v(e=>e.hydrated),r=U(t?void 0:e),[i,a]=(0,X.useState)({status:`idle`}),o=(0,X.useCallback)(async()=>{a({status:`loading`});try{let t=await C(Y(e)),n=b.safeParse(t);if(!n.success){a({status:`fatal`,error:Error(`The coordinator returned this automation in an unexpected format.`)});return}W.getState().put(n.data),a({status:`idle`})}catch(e){_(e)&&e.status===404?a({status:`notfound`}):a({status:`error`,error:e})}},[e]),s=!t&&!r;return(0,X.useEffect)(()=>{s&&i.status===`idle`&&o()},[s,i.status,o]),t?(0,Z.jsx)(ot,{automation:null}):r?(0,Z.jsx)(ot,{automation:r}):i.status===`notfound`?(0,Z.jsx)(D,{icon:(0,Z.jsx)(Ce,{className:`size-8`}),title:`Automation not found`,description:`It may have been deleted, or the link is wrong.`,action:{label:`Back to automations`,to:Qe}}):i.status===`error`?(0,Z.jsx)(T,{title:`Could not load this automation`,error:i.error,onRetry:()=>void o()}):i.status===`fatal`?(0,Z.jsx)(E,{error:i.error}):(0,Z.jsx)(x,{label:n?`Loading automation…`:`Loading…`})}function rt(e){let t=De({projectId:e,timezone:Oe()});try{let e=sessionStorage.getItem(et);if(!e)return t;let n=JSON.parse(e);return!n||typeof n!=`object`?t:{...t,...n,filters:Array.isArray(n.filters)?n.filters:[]}}catch{return t}}function it(e){try{e?sessionStorage.setItem(et,JSON.stringify(e)):sessionStorage.removeItem(et)}catch{}}var $=e=>JSON.stringify(Le(e));function at(e){if(!_(e))return{};let t=e.details,n=Array.isArray(t)?t:t&&typeof t==`object`&&Array.isArray(t.issues)?t.issues:[],r={};for(let e of n){if(!e||typeof e!=`object`)continue;let{path:t,message:n}=e;if(!Array.isArray(t)||typeof n!=`string`)continue;let i=K(t);i!==`form`&&!r[i]&&(r[i]=n)}return r}function ot({automation:e}){let i=t(),o=r(),c=fe(Qe),l=he(),u=l===`desktop`,d=re(),f=ae(),m=v(e=>e.hosts),h=v(e=>e.profiles),_=v(e=>e.tasks),b=v(e=>e.projects),x=e===null,S=(0,X.useId)(),C=(0,X.useRef)(null),[T,E]=(0,X.useState)(()=>e?Ae(e):rt(d[0]?.id)),[D,O]=(0,X.useState)(()=>$(T)),[k,A]=(0,X.useState)(!1),[ce,j]=(0,X.useState)({}),[le,ue]=(0,X.useState)(!1),[de,M]=(0,X.useState)(!1),[_e,P]=(0,X.useState)(!1),[xe,F]=(0,X.useState)(!1),[Ce,I]=(0,X.useState)(0),L=(0,X.useRef)(e?.updatedAt),R=$(T),z=R!==D;(0,X.useEffect)(()=>{if(!e||e.updatedAt===L.current)return;L.current=e.updatedAt;let t=Ae(e),n=$(t);R===D?(E(t),F(!1)):n!==R&&F(!0),O(n)},[e,R,D]),(0,X.useEffect)(()=>{x&&it(T)},[x,T]),(0,X.useEffect)(()=>{x&&!T.projectId&&d[0]&&E(e=>e.projectId?e:{...e,projectId:d[0].id})},[x,T.projectId,d]);let B=(0,X.useCallback)((e,t)=>{E(n=>({...n,[e]:t})),j(e=>Object.keys(e).length?{}:e)},[]),V=(0,X.useMemo)(()=>Te(T),[T]),H={...ce,...k?V.errors:{}},U=e=>H[e],G=b[T.projectId],K=T.hostId||G?.defaultHostId||null,q=K?m[K]:void 0,ke=T.profileId||G?.defaultProfileId||null,je=(0,X.useCallback)(e=>_[e]?.title,[_]),Me=(0,X.useMemo)(()=>Ee(Le(T),{projectName:G?.name,hostName:T.hostId?m[T.hostId]?.name??null:null,profileName:T.profileId?h[T.profileId]?.name??null:null,taskTitle:je}),[T,G?.name,m,h,je]),Ne=()=>{requestAnimationFrame(()=>{C.current?.querySelector(`[aria-invalid="true"]`)?.focus()})},J=()=>(A(!0),V.input||Ne(),V.input),Pe=async()=>{let t=J();if(!t)N.error(`Fix the highlighted fields before saving`);else{ue(!0);try{if(x){let e=await y(`/api/automations`,t);if(!e||typeof e!=`object`||!e.id)throw Error(`The coordinator did not return the new automation`);W.getState().put(e),it(null),N.success(`Created ${e.name}`),i($e(e.id),{replace:!0,state:o.state});return}let n=await ie(Y(e.id),t);if(n&&typeof n==`object`&&n.id){W.getState().put(n),L.current=n.updatedAt;let e=Ae(n);E(e),O($(e))}else O(R);F(!1),A(!1),N.success(`Saved ${t.name}`)}catch(e){let t=at(e);j(t),Object.keys(t).length&&Ne(),N.error(`Could not save: ${g(e)}. Your changes are kept.`)}finally{ue(!1)}}},Fe=async()=>{if(e){M(!0);try{await ne(Y(e.id)),P(!1),N.success(`Deleted ${e.name}`),c(),W.getState().remove(e.id)}catch(e){N.error(`Could not delete: ${g(e)}`)}finally{M(!1)}}},{busy:Ie,run:Re}=we(()=>I(e=>e+1)),ze=e?!!Ie[e.id]:!1,Be=()=>e&&void Re(e),Ve=()=>{let e=De({projectId:d[0]?.id,timezone:Oe()});E(e),A(!1),it(null)},He=x?`New automation`:e.name,Ue=(0,Z.jsxs)(Z.Fragment,{children:[!x&&(0,Z.jsx)(s,{icon:(0,Z.jsx)(ge,{className:`size-4`}),busy:ze,onClick:Be,title:z?`Runs the saved version`:void 0,children:`Run now`}),x&&z&&(0,Z.jsx)(s,{variant:`ghost`,icon:(0,Z.jsx)(pe,{className:`size-4`}),onClick:Ve,children:`Discard draft`})]}),Q=e=>(0,Z.jsx)(s,{type:`submit`,form:S,variant:`primary`,busy:le,block:e,icon:(0,Z.jsx)(ve,{className:`size-4`}),children:x?`Create automation`:`Save`}),Ge=(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(We,{summary:Me,errorCount:k?Object.keys(V.errors).length:0}),(0,Z.jsx)(Ke,{automationId:e?.id??null,dirty:z,getInput:J,currentKey:JSON.stringify(V.input)}),e&&e.trigger.kind===`webhook`&&(0,Z.jsx)(Ye,{automation:e}),e&&(0,Z.jsx)(Ze,{automationId:e.id,refreshKey:Ce,onRun:Be})]});return(0,Z.jsxs)(`div`,{"data-testid":`automation-editor`,className:`flex w-full min-w-0 flex-col gap-4 px-4 pt-4 md:px-6`,children:[(0,Z.jsxs)(`header`,{className:`flex min-w-0 flex-col gap-2`,children:[(0,Z.jsxs)(a,{to:Qe,onClick:me(c),className:`tap inline-flex items-center gap-1 self-start rounded text-sm text-muted hover:text-text`,children:[(0,Z.jsx)(ee,{"aria-hidden":!0,className:`size-4`}),`Automations`]}),(0,Z.jsxs)(`div`,{className:`flex min-w-0 flex-wrap items-center justify-between gap-2`,children:[(0,Z.jsxs)(`div`,{className:`flex min-w-0 flex-wrap items-center gap-2`,children:[(0,Z.jsx)(`h1`,{className:`min-w-0 text-lg font-semibold break-words`,children:He}),z&&(0,Z.jsxs)(`span`,{className:`inline-flex items-center gap-1 text-xs text-muted`,children:[(0,Z.jsx)(p,{"aria-hidden":!0,className:`size-3.5`}),`Unsaved changes`]})]}),(0,Z.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[Ue,u&&Q()]})]})]}),(0,Z.jsx)(se,{subject:`automations`,consequence:`Changes are sent once the coordinator is reachable again.`}),q&&q.connectivity!==`connected`&&(0,Z.jsx)(oe,{compact:!0,hostName:q.name,connectivity:q.connectivity,lastSeenAt:q.lastSeenAt,detail:`Occurrences are still recorded; their tasks wait until the host is reachable.`}),xe&&(0,Z.jsxs)(`p`,{role:`status`,className:`flex items-start gap-1.5 rounded-md border border-border bg-warning-soft px-3 py-2 text-sm`,children:[(0,Z.jsx)(w,{"aria-hidden":!0,className:`mt-0.5 size-4 shrink-0 text-warning`}),`This automation changed elsewhere. Saving overwrites those changes with yours.`]}),(0,Z.jsxs)(`div`,{className:n(`grid min-w-0 gap-4`,u?`grid-cols-[minmax(0,1fr)_minmax(320px,400px)] items-start`:`grid-cols-1`),children:[(0,Z.jsxs)(`form`,{id:S,ref:C,noValidate:!0,"aria-label":He,onSubmit:e=>{e.preventDefault(),Pe()},className:`flex min-w-0 flex-col gap-4`,children:[(0,Z.jsx)(st,{draft:T,update:B,err:U,projects:d}),(0,Z.jsx)(ut,{draft:T,update:B,err:U,tasks:_,projectsById:b,savedAutomation:e,segmented:l!==`mobile`}),(0,Z.jsx)(dt,{draft:T,setDraft:E,err:U}),(0,Z.jsx)(ft,{draft:T,update:B,err:U}),(0,Z.jsx)(mt,{draft:T,update:B,err:U,hosts:f,profiles:Object.values(h).sort((e,t)=>e.name.localeCompare(t.name)),defaultHostName:G?.defaultHostId?m[G.defaultHostId]?.name:void 0,defaultProfileName:G?.defaultProfileId?h[G.defaultProfileId]?.name:void 0,selectedProfileMissing:!!ke&&!h[ke]}),(0,Z.jsx)(ht,{draft:T,update:B}),(0,Z.jsx)(gt,{draft:T,update:B,err:U}),(0,Z.jsx)(_t,{draft:T,update:B,err:U,projectChecks:G?.checks}),H.form&&(0,Z.jsx)(be,{children:H.form})]}),(0,Z.jsx)(`aside`,{"aria-label":`Summary, preview and history`,className:`flex min-w-0 flex-col gap-4`,children:Ge})]}),!x&&e&&(0,Z.jsx)(ye,{description:`Future occurrences stop. Tasks it already created stay on the board; its history is removed.`,children:(0,Z.jsx)(s,{variant:`danger`,icon:(0,Z.jsx)(Se,{className:`size-4`}),onClick:()=>P(!0),children:`Delete automation`})}),u?(0,Z.jsx)(`div`,{className:`h-4`}):(0,Z.jsxs)(`div`,{className:`sticky bottom-0 z-10 -mx-4 flex items-center gap-3 border-t border-border bg-surface px-4 py-2 md:-mx-6 md:px-6`,children:[(0,Z.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-sm text-muted`,children:z?`Unsaved changes`:x?`Not saved yet`:`All changes saved`}),Q()]}),(0,Z.jsx)(te,{open:_e,onClose:()=>P(!1),title:`Delete ${e?.name??`automation`}?`,description:`Future occurrences stop. Tasks it already created stay on the board; its history is removed.`,confirmLabel:`Delete automation`,confirmIcon:(0,Z.jsx)(Se,{className:`size-4`}),busy:de,onConfirm:()=>void Fe()})]})}function st({draft:e,update:t,err:n,projects:r}){return(0,Z.jsxs)(B,{stack:!0,title:`Basics`,children:[(0,Z.jsx)(P,{label:`Name`,error:n(`name`),children:n=>(0,Z.jsx)(I,{...n,value:e.name,onChange:e=>t(`name`,e.target.value),placeholder:`Daily dependency check`,autoComplete:`off`})}),(0,Z.jsxs)(`div`,{className:`grid gap-4 sm:grid-cols-2`,children:[(0,Z.jsx)(P,{label:`Project`,error:n(`projectId`),hint:r.length===0?(0,Z.jsxs)(Z.Fragment,{children:[`No projects yet.`,` `,(0,Z.jsx)(R,{to:`/settings/projects`,children:`Add a project in Settings`}),`.`]}):void 0,children:n=>(0,Z.jsxs)(V,{...n,value:e.projectId,onChange:e=>t(`projectId`,e.target.value),children:[(0,Z.jsx)(`option`,{value:``,children:`Choose a project`}),r.map(e=>(0,Z.jsx)(`option`,{value:e.id,children:e.name},e.id))]})}),(0,Z.jsx)(P,{label:`Status`,hint:`Disabled automations keep their history and can still run manually.`,children:n=>(0,Z.jsx)(H,{...n,checked:e.enabled,onChange:e=>t(`enabled`,e),label:`Enabled`,onText:`Enabled`,offText:`Disabled`,className:`self-start`})})]})]})}var ct=[`manual`,`once`,`cron`,`webhook`,`dependency`],lt={manual:`Runs only when you press Run now (or from the CLI).`,once:`Runs a single time at the chosen moment.`,cron:`Runs on a timezone-aware cron schedule.`,webhook:`Runs when an authenticated JSON POST arrives at this automation's webhook URL.`,dependency:`Runs when the chosen task is done.`};function ut({draft:e,update:t,err:n,tasks:r,projectsById:i,savedAutomation:a,segmented:o}){let s=v(e=>e.hydrated),c=e.triggerKind===`cron`?ze(e.cronExpr):null,l=e.triggerKind===`cron`&&!c?Fe(e.cronExpr,e.cronTimezone.trim()||void 0)??`Valid expression (no plain-language description available)`:null,u=(0,X.useMemo)(()=>{try{return Intl.supportedValuesOf?.(`timeZone`)}catch{return}},[]),d=(0,X.useId)(),f=Oe(),ee=(0,X.useMemo)(()=>Object.values(r).filter(t=>t.state!==`canceled`||t.id===e.dependencyTaskId).sort((e,t)=>e.title.localeCompare(t.title)),[r,e.dependencyTaskId]),p=e.triggerKind===`once`?je(e.onceAt):``;return(0,Z.jsxs)(B,{stack:!0,title:`Trigger`,description:lt[e.triggerKind],children:[o?(0,Z.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-1`,children:[(0,Z.jsx)(`span`,{"aria-hidden":!0,className:`text-sm font-medium`,children:`Trigger kind`}),(0,Z.jsx)(`div`,{className:`overflow-x-auto`,children:(0,Z.jsx)(z,{label:`Trigger kind`,value:e.triggerKind,onChange:e=>t(`triggerKind`,e),options:ct.map(e=>({value:e,label:G[e]}))})})]}):(0,Z.jsx)(P,{label:`Trigger kind`,children:n=>(0,Z.jsx)(V,{...n,value:e.triggerKind,onChange:e=>t(`triggerKind`,e.target.value),children:ct.map(e=>(0,Z.jsx)(`option`,{value:e,children:G[e]},e))})}),e.triggerKind===`once`&&(0,Z.jsx)(P,{label:`Run at`,error:n(`onceAt`),hint:`Local time (${f})${p?`; saved as ${p}`:``}.`,children:n=>(0,Z.jsx)(I,{...n,type:`datetime-local`,value:e.onceAt,onChange:e=>t(`onceAt`,e.target.value)})}),e.triggerKind===`cron`&&(0,Z.jsxs)(`div`,{className:`grid gap-4 sm:grid-cols-2`,children:[(0,Z.jsx)(P,{label:`Cron expression`,error:n(`cronExpr`)??c??void 0,hint:`minute hour day-of-month month day-of-week, e.g. 0 9 * * 1-5`,children:n=>(0,Z.jsx)(I,{...n,"aria-invalid":c?!0:n[`aria-invalid`],value:e.cronExpr,onChange:e=>t(`cronExpr`,e.target.value),className:`font-mono`,autoComplete:`off`,spellCheck:!1,autoCapitalize:`off`})}),(0,Z.jsx)(P,{label:`Timezone`,error:n(`cronTimezone`),hint:e.cronTimezone.trim()===f?`IANA timezone name; daylight saving is handled.`:(0,Z.jsxs)(R,{onClick:()=>t(`cronTimezone`,f),children:[`Use this device's timezone (`,f,`)`]}),children:n=>(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(I,{...n,list:u?d:void 0,value:e.cronTimezone,onChange:e=>t(`cronTimezone`,e.target.value),autoComplete:`off`,spellCheck:!1,autoCapitalize:`off`}),u&&(0,Z.jsx)(`datalist`,{id:d,children:u.map(e=>(0,Z.jsx)(`option`,{value:e},e))})]})}),l&&(0,Z.jsxs)(`p`,{className:`flex items-start gap-1.5 text-sm sm:col-span-2`,"aria-live":`polite`,"data-testid":`cron-description`,children:[(0,Z.jsx)(A,{"aria-hidden":!0,className:`mt-0.5 size-4 shrink-0 text-muted`}),(0,Z.jsx)(`span`,{className:`min-w-0 break-words`,children:l})]})]}),e.triggerKind===`webhook`&&(0,Z.jsxs)(`div`,{className:`flex flex-col gap-1 text-sm text-muted`,children:[(0,Z.jsxs)(`p`,{children:[`Senders POST a JSON body (up to 256 KB) with`,` `,(0,Z.jsx)(`code`,{children:`Authorization: Bearer <token>`}),`. Use the filters below to fire only for matching payloads, and `,(0,Z.jsx)(`code`,{children:`{{payload.<path>}}`}),` to copy payload values into the task.`]}),a?a.trigger.kind===`webhook`?(0,Z.jsxs)(`p`,{children:[`Token:`,` `,a.webhookTokenSet?`set (see Webhook below to rotate)`:`not created yet`]}):(0,Z.jsx)(`p`,{children:`Save to switch this automation to a webhook trigger, then create a token.`}):(0,Z.jsx)(`p`,{children:`Save the automation to create its webhook token and URL.`})]}),e.triggerKind===`dependency`&&(0,Z.jsx)(P,{label:`When this task is done`,error:n(`dependencyTaskId`),hint:`Fires once each time the task enters Done.`,children:n=>(0,Z.jsxs)(V,{...n,value:e.dependencyTaskId,onChange:e=>t(`dependencyTaskId`,e.target.value),children:[(0,Z.jsx)(`option`,{value:``,children:`Choose a task`}),e.dependencyTaskId&&!r[e.dependencyTaskId]&&(0,Z.jsx)(`option`,{value:e.dependencyTaskId,children:s?`Deleted task`:`Loading task…`}),ee.map(e=>(0,Z.jsxs)(`option`,{value:e.id,children:[e.title,i[e.projectId]?` (${i[e.projectId].name})`:``,e.state===`done`?` - done`:``]},e.id))]})})]})}function dt({draft:e,setDraft:t,err:n}){let r=(e,n)=>t(t=>({...t,filters:t.filters.map((t,r)=>r===e?{...t,...n}:t)})),i=e.triggerKind===`webhook`;return(0,Z.jsxs)(B,{stack:!0,title:`Filters`,description:`Filters apply to webhook payloads. Each row compares a dot path (for example pull_request.base.ref) with an exact value; all rows must match. Payloads that do not match are recorded as Filtered out.`,children:[!i&&(0,Z.jsx)(`p`,{className:`text-sm text-muted`,children:`Filters are ignored unless the trigger is Webhook.`}),e.filters.length===0&&(0,Z.jsx)(`p`,{className:`text-sm text-muted`,children:`No filters: every payload fires.`}),e.filters.map((e,i)=>(0,Z.jsxs)(`div`,{className:`grid min-w-0 grid-cols-[minmax(0,1fr)_auto] items-end gap-2 sm:grid-cols-[minmax(0,1fr)_minmax(0,1fr)_auto]`,children:[(0,Z.jsx)(P,{label:`Path ${i+1}`,error:n(`filters.${i}.path`),children:t=>(0,Z.jsx)(I,{...t,value:e.path,onChange:e=>r(i,{path:e.target.value}),placeholder:`action`,className:`font-mono`,autoCapitalize:`off`,spellCheck:!1})}),(0,Z.jsx)(P,{label:`Equals ${i+1}`,error:n(`filters.${i}.equals`),className:`col-start-1 row-start-2 sm:col-start-auto sm:row-start-auto`,children:t=>(0,Z.jsx)(I,{...t,value:e.equals,onChange:e=>r(i,{equals:e.target.value}),placeholder:`opened`})}),(0,Z.jsx)(m,{label:`Remove filter ${i+1}`,icon:(0,Z.jsx)(pe,{className:`size-4`}),onClick:()=>t(e=>({...e,filters:e.filters.filter((e,t)=>t!==i)}))})]},i)),(0,Z.jsx)(`div`,{children:(0,Z.jsx)(s,{size:`sm`,icon:(0,Z.jsx)(_e,{className:`size-3.5`}),onClick:()=>t(e=>({...e,filters:[...e.filters,{path:``,equals:``}]})),children:`Add filter`})})]})}function ft({draft:e,update:t,err:n}){return(0,Z.jsxs)(B,{stack:!0,title:`Task template`,description:`Use ${ke.join(`, `)} in the title, objective, criteria and grouping key.`,children:[(0,Z.jsx)(P,{label:`Task title`,error:n(`title`),children:n=>(0,Z.jsx)(I,{...n,value:e.title,onChange:e=>t(`title`,e.target.value),placeholder:`Triage new issues for {{date}}`})}),(0,Z.jsx)(P,{label:`Objective`,error:n(`objective`),children:n=>(0,Z.jsx)(F,{...n,minRows:4,value:e.objective,onChange:e=>t(`objective`,e.target.value)})}),(0,Z.jsx)(P,{label:`Acceptance criteria`,error:n(`criteria`),hint:`One criterion per line.`,optional:!0,children:n=>(0,Z.jsx)(F,{...n,minRows:3,value:e.criteria,onChange:e=>t(`criteria`,e.target.value)})}),(0,Z.jsx)(P,{label:`Priority`,error:n(`priority`),children:n=>(0,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Z.jsx)(de,{priority:e.priority}),(0,Z.jsx)(ue,{...n,value:e.priority,onChange:e=>t(`priority`,e),className:`sm:max-w-48`})]})})]})}function pt({legend:e,value:t,options:r,onChange:i,hint:a}){let o=(0,X.useId)();return(0,Z.jsxs)(`fieldset`,{className:`flex min-w-0 flex-col gap-2`,children:[(0,Z.jsx)(`legend`,{className:`mb-1 text-sm font-medium`,children:e}),(0,Z.jsx)(`div`,{className:`grid min-w-0 gap-2 sm:grid-cols-3`,children:r.map(e=>(0,Z.jsxs)(`label`,{className:n(`tap flex min-w-0 cursor-pointer items-start gap-2 rounded-md border p-2.5 text-sm`,`has-[:focus-visible]:outline-2 has-[:focus-visible]:outline-offset-1`,t===e.value?`border-accent bg-accent-soft`:`border-border hover:bg-surface-2`),children:[(0,Z.jsx)(`input`,{type:`radio`,name:o,value:e.value,checked:t===e.value,onChange:()=>i(e.value),className:`mt-0.5 size-4 shrink-0 accent-[var(--color-accent)]`}),(0,Z.jsxs)(`span`,{className:`min-w-0`,children:[(0,Z.jsx)(`span`,{className:`block font-medium`,children:e.label}),(0,Z.jsx)(`span`,{className:`block text-xs text-muted`,children:e.explanation})]})]},e.value))}),a&&(0,Z.jsx)(`p`,{className:`text-xs text-muted`,children:a})]})}function mt({draft:e,update:t,err:n,hosts:r,profiles:i,defaultHostName:a,defaultProfileName:o,selectedProfileMissing:s}){return(0,Z.jsxs)(B,{stack:!0,title:`Where and how it runs`,children:[(0,Z.jsxs)(`div`,{className:`grid gap-4 sm:grid-cols-2`,children:[(0,Z.jsx)(P,{label:`Host`,error:n(`hostId`),children:n=>(0,Z.jsxs)(V,{...n,value:e.hostId,onChange:e=>t(`hostId`,e.target.value),children:[(0,Z.jsxs)(`option`,{value:``,children:[`Project default`,a?` (${a})`:``]}),e.hostId&&!r.some(t=>t.id===e.hostId)&&(0,Z.jsx)(`option`,{value:e.hostId,children:`Unknown host`}),r.map(e=>(0,Z.jsxs)(`option`,{value:e.id,children:[e.name,e.connectivity===`connected`?``:` (${e.connectivity})`]},e.id))]})}),(0,Z.jsx)(P,{label:`Profile`,error:n(`profileId`),hint:s?`The selected profile is no longer available.`:void 0,children:n=>(0,Z.jsxs)(V,{...n,value:e.profileId,onChange:e=>t(`profileId`,e.target.value),children:[(0,Z.jsxs)(`option`,{value:``,children:[`Project default`,o?` (${o})`:``]}),e.profileId&&!i.some(t=>t.id===e.profileId)&&(0,Z.jsx)(`option`,{value:e.profileId,children:`Unknown profile`}),i.map(e=>(0,Z.jsx)(`option`,{value:e.id,children:e.name},e.id))]})})]}),(0,Z.jsx)(pt,{legend:`Mode`,value:e.mode,options:Me,onChange:e=>t(`mode`,e)}),(0,Z.jsx)(P,{label:`Grouping key`,optional:e.mode!==`continue`,error:n(`groupingKey`),hint:`Occurrences with the same rendered key are the same work: Continue reuses that task and overlap checks compare it. Supports template variables, e.g. pr-{{payload.number}}.`,children:n=>(0,Z.jsx)(I,{...n,value:e.groupingKey,onChange:e=>t(`groupingKey`,e.target.value),className:`font-mono`,autoCapitalize:`off`,spellCheck:!1})})]})}function ht({draft:e,update:t}){let n=e.triggerKind===`cron`||e.triggerKind===`once`;return(0,Z.jsxs)(B,{stack:!0,title:`Overlap and missed runs`,children:[(0,Z.jsx)(pt,{legend:`When previous work is still open`,value:e.overlap,options:Pe,onChange:e=>t(`overlap`,e)}),(0,Z.jsx)(pt,{legend:`Missed runs`,value:e.missed,options:Ie,onChange:e=>t(`missed`,e),hint:n?`A run is missed when the coordinator was down at its scheduled time.`:`Only applies to Schedule and Once triggers.`})]})}function gt({draft:e,update:t,err:n}){return(0,Z.jsxs)(B,{stack:!0,title:`Limits`,description:`Continuation prompts the agent to keep going after a turn ends without finishing. It is off by default.`,children:[(0,Z.jsx)(P,{label:`Automatic continuation`,children:n=>(0,Z.jsx)(H,{...n,checked:e.continuationEnabled,onChange:e=>t(`continuationEnabled`,e),label:`Automatic continuation`,className:`self-start`})}),e.continuationEnabled&&(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(P,{label:`Continuation objective`,error:n(`continuationObjective`),hint:`What the agent must achieve before it reports done.`,children:n=>(0,Z.jsx)(F,{...n,minRows:2,value:e.continuationObjective,onChange:e=>t(`continuationObjective`,e.target.value)})}),(0,Z.jsxs)(`div`,{className:`grid gap-4 sm:grid-cols-2`,children:[(0,Z.jsx)(P,{label:`Max continuations`,error:n(`maxContinuations`),hint:`1–50`,children:n=>(0,Z.jsx)(I,{...n,type:`number`,inputMode:`numeric`,min:1,max:50,step:1,value:e.maxContinuations,onChange:e=>t(`maxContinuations`,e.target.value)})}),(0,Z.jsx)(P,{label:`Max elapsed minutes`,error:n(`maxElapsedMinutes`),hint:`1–1440`,children:n=>(0,Z.jsx)(I,{...n,type:`number`,inputMode:`numeric`,min:1,max:1440,step:1,value:e.maxElapsedMinutes,onChange:e=>t(`maxElapsedMinutes`,e.target.value)})}),(0,Z.jsx)(P,{label:`Continuation budget: tokens`,optional:!0,error:n(`maxTokens`),children:n=>(0,Z.jsx)(I,{...n,type:`number`,inputMode:`numeric`,min:1,step:1,value:e.maxTokens,onChange:e=>t(`maxTokens`,e.target.value)})}),(0,Z.jsx)(P,{label:`Continuation budget: cost (USD)`,optional:!0,error:n(`maxCostUsd`),children:n=>(0,Z.jsx)(I,{...n,type:`number`,inputMode:`decimal`,min:.01,step:.01,value:e.maxCostUsd,onChange:e=>t(`maxCostUsd`,e.target.value)})})]}),(0,Z.jsx)(`p`,{className:`text-xs text-muted`,children:xe})]})]})}function _t({draft:e,update:t,err:n,projectChecks:r}){let i=r&&r.length>0?`the project's checks (${r.join(`, `)})`:`the project's checks`;return(0,Z.jsxs)(B,{stack:!0,title:`Review`,children:[(0,Z.jsx)(P,{label:`Checks`,optional:!0,error:n(`checks`),hint:`One command per line. Leave empty to use ${i}.`,children:n=>(0,Z.jsx)(F,{...n,minRows:2,value:e.checks,onChange:e=>t(`checks`,e.target.value),className:`font-mono`,spellCheck:!1,autoCapitalize:`off`})}),(0,Z.jsx)(P,{label:`Human review`,hint:`When on, finished work waits in Review for you instead of completing on passing checks.`,children:n=>(0,Z.jsx)(H,{...n,checked:e.requireHumanReview,onChange:e=>t(`requireHumanReview`,e),label:`Require human review`,onText:`Required`,offText:`Not required`,className:`self-start`})})]})}export{tt as default};
2
+ //# sourceMappingURL=AutomationView-BMQuTl3j.js.map