@edspencer/paddock 0.71.1 → 0.71.2

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 (76) hide show
  1. package/package.json +1 -1
  2. package/packages/server/dist/cli/args.d.ts +11 -3
  3. package/packages/server/dist/cli/args.js +20 -2
  4. package/packages/server/dist/cli/service/backend.d.ts +33 -0
  5. package/packages/server/dist/cli/service/index.d.ts +3 -3
  6. package/packages/server/dist/cli/service/index.js +124 -2
  7. package/packages/server/dist/cli/service/launchd.d.ts +27 -4
  8. package/packages/server/dist/cli/service/launchd.js +88 -14
  9. package/packages/server/dist/cli/service/systemd.d.ts +21 -2
  10. package/packages/server/dist/cli/service/systemd.js +58 -5
  11. package/packages/server/package.json +1 -1
  12. package/packages/web/dist/assets/{Chip-Db--PJFH.js → Chip-Cp32dDmz.js} +1 -1
  13. package/packages/web/dist/assets/DiscoverPage-Cs439wTf.js +2 -0
  14. package/packages/web/dist/assets/{DiscoverView-C4hOB3nr.js → DiscoverView-DoGAlUXT.js} +1 -1
  15. package/packages/web/dist/assets/{InstanceConfigPage-U78M95nW.js → InstanceConfigPage-BDypeo_r.js} +1 -1
  16. package/packages/web/dist/assets/{MarkdownRenderer-DdoNl0Ao.js → MarkdownRenderer-DA5CpdGI.js} +1 -1
  17. package/packages/web/dist/assets/{ProjectMenu-BxQu14ze.js → ProjectMenu-DXXXtXeh.js} +1 -1
  18. package/packages/web/dist/assets/{ProjectRedirect-QuGeN-qx.js → ProjectRedirect-k10uM_63.js} +1 -1
  19. package/packages/web/dist/assets/ProjectView-BxjcMlSO.js +13 -0
  20. package/packages/web/dist/assets/{ProjectsGrid-CUFNVTif.js → ProjectsGrid-DrzZ7R8M.js} +1 -1
  21. package/packages/web/dist/assets/{RootHome-SIxo-xX9.js → RootHome-rWodzOC8.js} +1 -1
  22. package/packages/web/dist/assets/{arc-C0DRwCCT.js → arc-BKAVFR26.js} +1 -1
  23. package/packages/web/dist/assets/{architectureDiagram-3BPJPVTR-Wwpf4cvW.js → architectureDiagram-3BPJPVTR-UzIlxaCQ.js} +1 -1
  24. package/packages/web/dist/assets/{blockDiagram-GPEHLZMM-DKmCbgWk.js → blockDiagram-GPEHLZMM-Eu4BV7Ea.js} +1 -1
  25. package/packages/web/dist/assets/{c4Diagram-AAUBKEIU-CJ8LiLsj.js → c4Diagram-AAUBKEIU-DR8PZaoa.js} +1 -1
  26. package/packages/web/dist/assets/channel-C-sodtn7.js +2 -0
  27. package/packages/web/dist/assets/{chunk-2J33WTMH-C3P-O4C3.js → chunk-2J33WTMH-CgvIIrI1.js} +1 -1
  28. package/packages/web/dist/assets/{chunk-4BX2VUAB-Cs9u7x61.js → chunk-4BX2VUAB-CyJWrZqN.js} +1 -1
  29. package/packages/web/dist/assets/{chunk-55IACEB6-C1st284U.js → chunk-55IACEB6-DXEnZN1d.js} +1 -1
  30. package/packages/web/dist/assets/{chunk-727SXJPM-BjCAWo7B.js → chunk-727SXJPM-Co89QTmp.js} +1 -1
  31. package/packages/web/dist/assets/{chunk-AQP2D5EJ-BP6S9w2Q.js → chunk-AQP2D5EJ-BRxTzfev.js} +1 -1
  32. package/packages/web/dist/assets/{chunk-FMBD7UC4-C3ySTaPs.js → chunk-FMBD7UC4-DUj18CvF.js} +1 -1
  33. package/packages/web/dist/assets/{chunk-ND2GUHAM-eNPD4vzc.js → chunk-ND2GUHAM-BQMMJobN.js} +1 -1
  34. package/packages/web/dist/assets/{chunk-QZHKN3VN-BbBpgHkO.js → chunk-QZHKN3VN-COx8LZCe.js} +1 -1
  35. package/packages/web/dist/assets/classDiagram-4FO5ZUOK-D2eBPVdq.js +2 -0
  36. package/packages/web/dist/assets/classDiagram-v2-Q7XG4LA2-D2eBPVdq.js +2 -0
  37. package/packages/web/dist/assets/{core-ZwDDec0y.js → core-DnpcT0s6.js} +1 -1
  38. package/packages/web/dist/assets/{cose-bilkent-S5V4N54A-DiM4eeF5.js → cose-bilkent-S5V4N54A-B-4NadKI.js} +1 -1
  39. package/packages/web/dist/assets/{dagre-BM42HDAG-DKIEUM4M.js → dagre-BM42HDAG-CuaYJexd.js} +1 -1
  40. package/packages/web/dist/assets/{diagram-2AECGRRQ-CqlX7j8t.js → diagram-2AECGRRQ-C9_anxrA.js} +1 -1
  41. package/packages/web/dist/assets/{diagram-5GNKFQAL-Dph5apqo.js → diagram-5GNKFQAL-Ckf3kFlY.js} +1 -1
  42. package/packages/web/dist/assets/{diagram-KO2AKTUF-TW6LyHGt.js → diagram-KO2AKTUF-BrpUuY5x.js} +1 -1
  43. package/packages/web/dist/assets/{diagram-LMA3HP47-BxxIIv5a.js → diagram-LMA3HP47-B9lyXZXW.js} +1 -1
  44. package/packages/web/dist/assets/{diagram-OG6HWLK6-B8M0DeV7.js → diagram-OG6HWLK6-DT7ro32m.js} +1 -1
  45. package/packages/web/dist/assets/{erDiagram-TEJ5UH35-Bfpy6UQa.js → erDiagram-TEJ5UH35-ZZn9bHQh.js} +1 -1
  46. package/packages/web/dist/assets/{flowDiagram-I6XJVG4X-DstRzxek.js → flowDiagram-I6XJVG4X-BxQ82PY_.js} +1 -1
  47. package/packages/web/dist/assets/{ganttDiagram-6RSMTGT7-Bg0oFbAl.js → ganttDiagram-6RSMTGT7-BxliloOH.js} +1 -1
  48. package/packages/web/dist/assets/{gitGraphDiagram-PVQCEYII-CX4IozE-.js → gitGraphDiagram-PVQCEYII-BlwODdH9.js} +1 -1
  49. package/packages/web/dist/assets/{index-ASW1Jl0Y.js → index-Cx9y6c3f.js} +2 -2
  50. package/packages/web/dist/assets/{infoDiagram-5YYISTIA-CG2qCk6u.js → infoDiagram-5YYISTIA-nanSBFyG.js} +1 -1
  51. package/packages/web/dist/assets/{ishikawaDiagram-YF4QCWOH-CPErvl3a.js → ishikawaDiagram-YF4QCWOH-yZHr_s28.js} +1 -1
  52. package/packages/web/dist/assets/{journeyDiagram-JHISSGLW-Bm6krUsf.js → journeyDiagram-JHISSGLW-BKjDqQEQ.js} +1 -1
  53. package/packages/web/dist/assets/{kanban-definition-UN3LZRKU-B4CC8CAx.js → kanban-definition-UN3LZRKU-QusvHqc6.js} +1 -1
  54. package/packages/web/dist/assets/{linear-CJ1DbrOX.js → linear-4xRoD38Z.js} +1 -1
  55. package/packages/web/dist/assets/{mermaid.core-Dk2kkhf9.js → mermaid.core-CeulYvDv.js} +4 -4
  56. package/packages/web/dist/assets/{mindmap-definition-RKZ34NQL-CThvf_YD.js → mindmap-definition-RKZ34NQL-DSjYt2Kp.js} +1 -1
  57. package/packages/web/dist/assets/{pieDiagram-4H26LBE5-DvkHcng6.js → pieDiagram-4H26LBE5-Ci0gO3CA.js} +1 -1
  58. package/packages/web/dist/assets/{quadrantDiagram-W4KKPZXB-CqhrTh9q.js → quadrantDiagram-W4KKPZXB-y2qHkaHP.js} +1 -1
  59. package/packages/web/dist/assets/{requirementDiagram-4Y6WPE33-CZykiLym.js → requirementDiagram-4Y6WPE33-D9hiWbad.js} +1 -1
  60. package/packages/web/dist/assets/{sankeyDiagram-5OEKKPKP-D-TzCKMx.js → sankeyDiagram-5OEKKPKP-DA3Mvoze.js} +1 -1
  61. package/packages/web/dist/assets/{sequenceDiagram-3UESZ5HK-C5pIItVu.js → sequenceDiagram-3UESZ5HK-DWACrljw.js} +1 -1
  62. package/packages/web/dist/assets/{stateDiagram-AJRCARHV-DE6G2JfB.js → stateDiagram-AJRCARHV-CFGEhoTb.js} +1 -1
  63. package/packages/web/dist/assets/stateDiagram-v2-BHNVJYJU-CLfbDXLX.js +2 -0
  64. package/packages/web/dist/assets/{timeline-definition-PNZ67QCA-C1VK2OfU.js → timeline-definition-PNZ67QCA-Cjygpd9e.js} +1 -1
  65. package/packages/web/dist/assets/{vennDiagram-CIIHVFJN-CtOozEwa.js → vennDiagram-CIIHVFJN-zQnLaxgv.js} +1 -1
  66. package/packages/web/dist/assets/{wardley-L42UT6IY-DvHGK-lb.js → wardley-L42UT6IY-DGmt-Lo2.js} +1 -1
  67. package/packages/web/dist/assets/{wardleyDiagram-YWT4CUSO-DxKwZ3-G.js → wardleyDiagram-YWT4CUSO-Dj3vDukN.js} +1 -1
  68. package/packages/web/dist/assets/{xychartDiagram-2RQKCTM6-HM4j3l6y.js → xychartDiagram-2RQKCTM6-C0bGbwbL.js} +1 -1
  69. package/packages/web/dist/index.html +1 -1
  70. package/packages/web/dist/sw.js +1 -1
  71. package/packages/web/dist/assets/DiscoverPage-BFo4FTzZ.js +0 -2
  72. package/packages/web/dist/assets/ProjectView-FUcyJMUf.js +0 -13
  73. package/packages/web/dist/assets/channel-DEmtNKeB.js +0 -2
  74. package/packages/web/dist/assets/classDiagram-4FO5ZUOK-dAGAuccL.js +0 -2
  75. package/packages/web/dist/assets/classDiagram-v2-Q7XG4LA2-dAGAuccL.js +0 -2
  76. package/packages/web/dist/assets/stateDiagram-v2-BHNVJYJU-BP6oowh1.js +0 -2
@@ -62,8 +62,17 @@ export function unitPath(homeDir, xdgConfigHome) {
62
62
  /**
63
63
  * Render the unit.
64
64
  *
65
- * `Restart=on-failure` rather than `always`, matching launchd's `SuccessfulExit:
66
- * false` — a clean shutdown should stay shut down.
65
+ * `Restart=always`, matching launchd's `KeepAlive=<true/>` (#872). It was
66
+ * `on-failure`, which for a service is the wrong default for the same reason it
67
+ * was wrong there: `start.ts` exits `0` on SIGTERM, so a logout — or anything
68
+ * else that signals the user manager — was read as an intended stop and Paddock
69
+ * stayed down.
70
+ *
71
+ * `always` does not make the unit unstoppable. systemd never restarts a unit it
72
+ * was itself asked to stop, so `systemctl --user stop` (and therefore
73
+ * `uninstall`) remains the clean, explicit way to put it down. That is the
74
+ * difference between an exit code, which has to guess at intent, and a command,
75
+ * which carries it.
67
76
  *
68
77
  * `WantedBy=default.target` is what makes `systemctl --user enable` mean
69
78
  * "start at login" for a user unit; `multi-user.target` is the system-unit
@@ -84,13 +93,25 @@ Type=simple
84
93
  ExecStart=${exec}
85
94
  WorkingDirectory=${spec.workingDirectory}
86
95
  Environment=PATH=${spec.pathEnv}
87
- Restart=on-failure
96
+ Restart=always
88
97
  RestartSec=10
89
98
 
90
99
  [Install]
91
100
  WantedBy=default.target
92
101
  `;
93
102
  }
103
+ /**
104
+ * Does an installed unit carry `Restart=always` (#872)?
105
+ *
106
+ * The counterpart to `plistKeepsAlive`, and narrow for the same reason: the
107
+ * value it has to reject is the `on-failure` this file used to write, which
108
+ * leaves Paddock down after the graceful exit `start.ts` performs on SIGTERM.
109
+ * Anything unrecognised reads as "not the fixed shape", which at worst tells a
110
+ * hand-edited unit's owner to re-run install.
111
+ */
112
+ export function unitKeepsAlive(text) {
113
+ return /^Restart=always\s*$/m.test(text);
114
+ }
94
115
  /** Read `ExecStart=` back out of an installed unit, split into an argv. */
95
116
  export function parseUnitArgv(text) {
96
117
  const m = /^ExecStart=(.*)$/m.exec(text);
@@ -98,6 +119,14 @@ export function parseUnitArgv(text) {
98
119
  return [];
99
120
  return m[1].trim().split(/\s+/).filter(Boolean);
100
121
  }
122
+ /** Run a `systemctl` and turn a non-zero exit into the manager's own words. */
123
+ function systemctlOrThrow(run, args) {
124
+ const r = run("systemctl", args);
125
+ if (r.status === 0)
126
+ return;
127
+ throw new Error(`systemctl ${args.join(" ")} failed (exit ${String(r.status)}).\n` +
128
+ `${r.stderr || r.stdout}`.trim());
129
+ }
101
130
  export function createSystemdBackend(run, homeDir, xdgConfigHome) {
102
131
  // Both forwarded, neither defaulted here: `unitPath` owns the precedence, and
103
132
  // defaulting `homeDir` to `os.homedir()` at this layer would collapse "the
@@ -129,10 +158,33 @@ export function createSystemdBackend(run, homeDir, xdgConfigHome) {
129
158
  run("systemctl", ["--user", "daemon-reload"]);
130
159
  return existed;
131
160
  },
161
+ /**
162
+ * The lifecycle three (#873), which on systemd are just the verbs.
163
+ *
164
+ * None of them touches `enable`/`disable`: those decide whether Paddock
165
+ * comes back at your NEXT login, which is a different question from whether
166
+ * it is running now, and quietly answering both would make `stop` a
167
+ * surprise the following morning. `uninstall` is where that link is cut.
168
+ *
169
+ * `restart` re-reads the unit itself, but a `daemon-reload` first is what
170
+ * makes an EDITED unit take effect rather than the manager's cached copy —
171
+ * the same reason `install` reloads before enabling.
172
+ */
173
+ start() {
174
+ systemctlOrThrow(run, ["--user", "start", SYSTEMD_UNIT]);
175
+ },
176
+ stop() {
177
+ systemctlOrThrow(run, ["--user", "stop", SYSTEMD_UNIT]);
178
+ },
179
+ restart() {
180
+ run("systemctl", ["--user", "daemon-reload"]);
181
+ systemctlOrThrow(run, ["--user", "restart", SYSTEMD_UNIT]);
182
+ },
132
183
  status() {
133
184
  if (!fs.existsSync(file))
134
- return { registered: false, running: false, argv: [] };
135
- const argv = parseUnitArgv(fs.readFileSync(file, "utf8"));
185
+ return { registered: false, running: false, argv: [], keepsAlive: true };
186
+ const text = fs.readFileSync(file, "utf8");
187
+ const argv = parseUnitArgv(text);
136
188
  const active = run("systemctl", ["--user", "is-active", SYSTEMD_UNIT]);
137
189
  const pid = run("systemctl", ["--user", "show", "-p", "MainPID", "--value", SYSTEMD_UNIT]);
138
190
  const mainPid = pid.stdout.trim();
@@ -141,6 +193,7 @@ export function createSystemdBackend(run, homeDir, xdgConfigHome) {
141
193
  running: active.stdout.trim() === "active",
142
194
  ...(mainPid !== "" && mainPid !== "0" ? { pid: mainPid } : {}),
143
195
  argv: argv.slice(2),
196
+ keepsAlive: unitKeepsAlive(text),
144
197
  };
145
198
  },
146
199
  logsHint() {
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@paddock/server",
3
- "version": "0.71.1",
3
+ "version": "0.71.2",
4
4
  "private": true,
5
5
  "type": "module"
6
6
  }
@@ -1,2 +1,2 @@
1
- import{j as e,q as c,r as u}from"./index-ASW1Jl0Y.js";const h={primary:"bg-accent-solid text-accent-fg shadow-xs hover:bg-accent-solid-hover active:scale-[0.98]",ghost:"bg-surface-active text-fg hover:bg-surface-selected",subtle:"text-fg-muted hover:bg-surface-hover hover:text-fg",danger:"bg-danger-solid text-danger-fg shadow-xs hover:brightness-110 active:scale-[0.98]",link:"text-accent underline underline-offset-2 hover:no-underline"},p={sm:"gap-1.5 px-2 py-1 text-xs rounded-md",md:"gap-2 px-3.5 py-2 text-sm rounded-lg","icon-sm":"h-6 w-6 justify-center rounded-md","icon-md":"h-9 w-9 justify-center rounded-lg"};function w({variant:s="ghost",size:t="md",icon:r,loading:a=!1,loadingLabel:n,align:o="center",className:d,children:l,disabled:i,type:m="button",...b}){return e.jsxs("button",{type:m,disabled:i||a,"aria-busy":a||void 0,className:c("inline-flex select-none items-center font-medium","motion-fast transition-[color,background-color,border-color,box-shadow,transform]","disabled:cursor-not-allowed disabled:opacity-50",o==="start"?"justify-start text-left":"justify-center",p[t],h[s],d),...b,children:[r,a&&n?n:l]})}function j({interactive:s=!1,flush:t=!1,className:r,...a}){return e.jsx("div",{className:c("rounded-2xl border border-edge bg-surface-raised shadow-xs",t?"":"p-4",s&&"motion-fast transition-[border-color,box-shadow] hover:border-edge-strong hover:shadow-sm",r),...a})}function v({title:s,description:t,action:r,id:a,variant:n="card",first:o=!1,flush:d=!1,className:l,children:i}){return e.jsxs("section",{id:a,className:c("scroll-mt-4",n==="rule"&&!o&&"mt-9 border-t border-edge pt-7",n==="rule"?"":"mb-6",l),children:[e.jsxs("div",{className:"flex items-baseline justify-between gap-3",children:[e.jsx("h3",{className:c(n==="rule"?"text-base font-semibold tracking-tight text-fg":"text-sm font-semibold uppercase tracking-wide text-fg-muted"),children:s}),r]}),t&&e.jsx("p",{className:"mt-0.5 text-xs leading-snug text-fg-muted",children:t}),n==="card"?e.jsx(j,{className:"mt-2",flush:d,children:i}):e.jsx("div",{className:"mt-4",children:i})]})}function y({title:s,body:t,action:r,icon:a,variant:n="inline",className:o}){return n==="inline"?e.jsxs("div",{className:c("px-1 py-2",o),children:[e.jsx("p",{className:"text-sm text-fg-muted",children:s}),t&&e.jsx("p",{className:"mt-0.5 text-xs text-fg-subtle",children:t}),r&&e.jsx("div",{className:"mt-2",children:r})]}):e.jsxs("div",{className:c("mx-auto max-w-lg rounded-2xl border border-dashed border-edge px-8 py-12 text-center",o),children:[a&&e.jsx("div",{className:"mx-auto mb-4 flex h-14 w-14 items-center justify-center rounded-2xl bg-accent-soft text-accent",children:a}),e.jsx("h3",{className:"text-base font-semibold text-fg",children:s}),t&&e.jsx("p",{className:"mx-auto mt-1.5 max-w-sm text-sm text-fg-muted",children:t}),r&&e.jsx("div",{className:"mt-5 flex items-center justify-center gap-2",children:r})]})}const x=["w-full rounded-lg border border-edge-strong bg-surface-sunken px-3 py-2 text-sm text-fg","outline-none motion-fast transition-[border-color,box-shadow]","focus:border-accent focus:ring-2 focus:ring-accent/25","disabled:cursor-not-allowed disabled:opacity-60","aria-[invalid=true]:border-danger aria-[invalid=true]:focus:ring-danger/25"].join(" ");function k({className:s,...t}){return e.jsx("input",{className:c(x,s),...t})}function S({className:s,...t}){return e.jsx("textarea",{className:c(x,"resize-y",s),...t})}function E({className:s,...t}){return e.jsx("select",{className:c(x,s),...t})}function C({checked:s,onChange:t,label:r,disabled:a,id:n,className:o}){const d=u.useId(),l=n??d;return e.jsxs("label",{htmlFor:l,className:c("relative inline-block shrink-0 cursor-pointer",o),children:[e.jsx("input",{id:l,type:"checkbox","aria-label":r,className:"peer sr-only",checked:s,disabled:a,onChange:i=>t(i.target.checked)}),e.jsx("span",{className:c("block h-[18px] w-8 rounded-full bg-edge-strong","motion-fast transition-colors","after:absolute after:left-0.5 after:top-0.5 after:h-3.5 after:w-3.5 after:rounded-full","after:bg-surface-raised after:shadow-2xs after:transition-transform after:content-['']","peer-checked:bg-accent-solid peer-checked:after:translate-x-3.5","peer-focus-visible:ring-2 peer-focus-visible:ring-accent/50","peer-disabled:opacity-50")})]})}function T({label:s,description:t,indeterminate:r=!1,className:a,...n}){const o=u.useRef(null);u.useEffect(()=>{o.current&&(o.current.indeterminate=r)},[r]);const d=e.jsx("input",{ref:o,type:"checkbox",...r?{"aria-checked":"mixed"}:{},className:c("h-4 w-4 shrink-0 cursor-pointer rounded border-edge-strong accent-[var(--accent-solid)]","disabled:cursor-not-allowed disabled:opacity-50",s?"mt-0.5":"",a),...n});return s?e.jsxs("label",{className:"flex cursor-pointer items-start gap-2 text-sm text-fg",children:[d,e.jsxs("span",{className:"min-w-0",children:[s,t&&e.jsx("span",{className:"block text-xs leading-snug text-fg-muted",children:t})]})]}):d}const f={neutral:"bg-surface-active text-fg-muted",accent:"bg-accent-soft text-accent",success:"bg-success-soft text-success",warn:"bg-warn-soft text-warn",danger:"bg-danger-soft text-danger",info:"bg-info-soft text-info",lineage:"bg-lineage-soft text-lineage"},g={neutral:"bg-fg-subtle",accent:"bg-accent-solid",success:"bg-success-solid",warn:"bg-warn-solid",danger:"bg-danger-solid",info:"bg-info-solid",lineage:"bg-lineage-solid"};function I({tone:s="neutral",shape:t="tag",size:r="md",dot:a=!1,icon:n,title:o,className:d,children:l}){return e.jsxs("span",{title:o,className:c("inline-flex items-center gap-1 font-medium leading-none",t==="pill"?"rounded-full px-2 py-0.5":"rounded-md px-1.5 py-0.5",r==="sm"?"text-3xs":"text-2xs",f[s],d),children:[a&&e.jsx("span",{className:c("h-1.5 w-1.5 shrink-0 rounded-full",g[s])}),n,l]})}function O({tone:s="neutral",pulse:t=!1,className:r}){return e.jsx("span",{className:c("inline-block h-2 w-2 shrink-0 rounded-full",g[s],t&&"animate-pulse",r)})}function R({tone:s="info",icon:t,className:r,children:a}){const n={neutral:"border-edge",accent:"border-accent-edge",success:"border-success-edge",warn:"border-warn-edge",danger:"border-danger-edge",info:"border-info-edge",lineage:"border-lineage-edge"};return e.jsxs("div",{role:s==="danger"?"alert":void 0,className:c("flex items-start gap-2 rounded-lg border px-3 py-2 text-sm",f[s],n[s],r),children:[t&&e.jsx("span",{className:"mt-0.5 shrink-0",children:t}),e.jsx("div",{className:"min-w-0",children:a})]})}export{w as B,I as C,y as E,k as I,O as S,C as T,v as a,R as b,E as c,S as d,j as e,T as f};
1
+ import{j as e,q as c,r as u}from"./index-Cx9y6c3f.js";const h={primary:"bg-accent-solid text-accent-fg shadow-xs hover:bg-accent-solid-hover active:scale-[0.98]",ghost:"bg-surface-active text-fg hover:bg-surface-selected",subtle:"text-fg-muted hover:bg-surface-hover hover:text-fg",danger:"bg-danger-solid text-danger-fg shadow-xs hover:brightness-110 active:scale-[0.98]",link:"text-accent underline underline-offset-2 hover:no-underline"},p={sm:"gap-1.5 px-2 py-1 text-xs rounded-md",md:"gap-2 px-3.5 py-2 text-sm rounded-lg","icon-sm":"h-6 w-6 justify-center rounded-md","icon-md":"h-9 w-9 justify-center rounded-lg"};function w({variant:s="ghost",size:t="md",icon:r,loading:a=!1,loadingLabel:n,align:o="center",className:d,children:l,disabled:i,type:m="button",...b}){return e.jsxs("button",{type:m,disabled:i||a,"aria-busy":a||void 0,className:c("inline-flex select-none items-center font-medium","motion-fast transition-[color,background-color,border-color,box-shadow,transform]","disabled:cursor-not-allowed disabled:opacity-50",o==="start"?"justify-start text-left":"justify-center",p[t],h[s],d),...b,children:[r,a&&n?n:l]})}function j({interactive:s=!1,flush:t=!1,className:r,...a}){return e.jsx("div",{className:c("rounded-2xl border border-edge bg-surface-raised shadow-xs",t?"":"p-4",s&&"motion-fast transition-[border-color,box-shadow] hover:border-edge-strong hover:shadow-sm",r),...a})}function v({title:s,description:t,action:r,id:a,variant:n="card",first:o=!1,flush:d=!1,className:l,children:i}){return e.jsxs("section",{id:a,className:c("scroll-mt-4",n==="rule"&&!o&&"mt-9 border-t border-edge pt-7",n==="rule"?"":"mb-6",l),children:[e.jsxs("div",{className:"flex items-baseline justify-between gap-3",children:[e.jsx("h3",{className:c(n==="rule"?"text-base font-semibold tracking-tight text-fg":"text-sm font-semibold uppercase tracking-wide text-fg-muted"),children:s}),r]}),t&&e.jsx("p",{className:"mt-0.5 text-xs leading-snug text-fg-muted",children:t}),n==="card"?e.jsx(j,{className:"mt-2",flush:d,children:i}):e.jsx("div",{className:"mt-4",children:i})]})}function y({title:s,body:t,action:r,icon:a,variant:n="inline",className:o}){return n==="inline"?e.jsxs("div",{className:c("px-1 py-2",o),children:[e.jsx("p",{className:"text-sm text-fg-muted",children:s}),t&&e.jsx("p",{className:"mt-0.5 text-xs text-fg-subtle",children:t}),r&&e.jsx("div",{className:"mt-2",children:r})]}):e.jsxs("div",{className:c("mx-auto max-w-lg rounded-2xl border border-dashed border-edge px-8 py-12 text-center",o),children:[a&&e.jsx("div",{className:"mx-auto mb-4 flex h-14 w-14 items-center justify-center rounded-2xl bg-accent-soft text-accent",children:a}),e.jsx("h3",{className:"text-base font-semibold text-fg",children:s}),t&&e.jsx("p",{className:"mx-auto mt-1.5 max-w-sm text-sm text-fg-muted",children:t}),r&&e.jsx("div",{className:"mt-5 flex items-center justify-center gap-2",children:r})]})}const x=["w-full rounded-lg border border-edge-strong bg-surface-sunken px-3 py-2 text-sm text-fg","outline-none motion-fast transition-[border-color,box-shadow]","focus:border-accent focus:ring-2 focus:ring-accent/25","disabled:cursor-not-allowed disabled:opacity-60","aria-[invalid=true]:border-danger aria-[invalid=true]:focus:ring-danger/25"].join(" ");function k({className:s,...t}){return e.jsx("input",{className:c(x,s),...t})}function S({className:s,...t}){return e.jsx("textarea",{className:c(x,"resize-y",s),...t})}function E({className:s,...t}){return e.jsx("select",{className:c(x,s),...t})}function C({checked:s,onChange:t,label:r,disabled:a,id:n,className:o}){const d=u.useId(),l=n??d;return e.jsxs("label",{htmlFor:l,className:c("relative inline-block shrink-0 cursor-pointer",o),children:[e.jsx("input",{id:l,type:"checkbox","aria-label":r,className:"peer sr-only",checked:s,disabled:a,onChange:i=>t(i.target.checked)}),e.jsx("span",{className:c("block h-[18px] w-8 rounded-full bg-edge-strong","motion-fast transition-colors","after:absolute after:left-0.5 after:top-0.5 after:h-3.5 after:w-3.5 after:rounded-full","after:bg-surface-raised after:shadow-2xs after:transition-transform after:content-['']","peer-checked:bg-accent-solid peer-checked:after:translate-x-3.5","peer-focus-visible:ring-2 peer-focus-visible:ring-accent/50","peer-disabled:opacity-50")})]})}function T({label:s,description:t,indeterminate:r=!1,className:a,...n}){const o=u.useRef(null);u.useEffect(()=>{o.current&&(o.current.indeterminate=r)},[r]);const d=e.jsx("input",{ref:o,type:"checkbox",...r?{"aria-checked":"mixed"}:{},className:c("h-4 w-4 shrink-0 cursor-pointer rounded border-edge-strong accent-[var(--accent-solid)]","disabled:cursor-not-allowed disabled:opacity-50",s?"mt-0.5":"",a),...n});return s?e.jsxs("label",{className:"flex cursor-pointer items-start gap-2 text-sm text-fg",children:[d,e.jsxs("span",{className:"min-w-0",children:[s,t&&e.jsx("span",{className:"block text-xs leading-snug text-fg-muted",children:t})]})]}):d}const f={neutral:"bg-surface-active text-fg-muted",accent:"bg-accent-soft text-accent",success:"bg-success-soft text-success",warn:"bg-warn-soft text-warn",danger:"bg-danger-soft text-danger",info:"bg-info-soft text-info",lineage:"bg-lineage-soft text-lineage"},g={neutral:"bg-fg-subtle",accent:"bg-accent-solid",success:"bg-success-solid",warn:"bg-warn-solid",danger:"bg-danger-solid",info:"bg-info-solid",lineage:"bg-lineage-solid"};function I({tone:s="neutral",shape:t="tag",size:r="md",dot:a=!1,icon:n,title:o,className:d,children:l}){return e.jsxs("span",{title:o,className:c("inline-flex items-center gap-1 font-medium leading-none",t==="pill"?"rounded-full px-2 py-0.5":"rounded-md px-1.5 py-0.5",r==="sm"?"text-3xs":"text-2xs",f[s],d),children:[a&&e.jsx("span",{className:c("h-1.5 w-1.5 shrink-0 rounded-full",g[s])}),n,l]})}function O({tone:s="neutral",pulse:t=!1,className:r}){return e.jsx("span",{className:c("inline-block h-2 w-2 shrink-0 rounded-full",g[s],t&&"animate-pulse",r)})}function R({tone:s="info",icon:t,className:r,children:a}){const n={neutral:"border-edge",accent:"border-accent-edge",success:"border-success-edge",warn:"border-warn-edge",danger:"border-danger-edge",info:"border-info-edge",lineage:"border-lineage-edge"};return e.jsxs("div",{role:s==="danger"?"alert":void 0,className:c("flex items-start gap-2 rounded-lg border px-3 py-2 text-sm",f[s],n[s],r),children:[t&&e.jsx("span",{className:"mt-0.5 shrink-0",children:t}),e.jsx("div",{className:"min-w-0",children:a})]})}export{w as B,I as C,y as E,k as I,O as S,C as T,v as a,R as b,E as c,S as d,j as e,T as f};
2
2
 
@@ -0,0 +1,2 @@
1
+ import{j as r}from"./index-Cx9y6c3f.js";import{D as o}from"./DiscoverView-DoGAlUXT.js";import"./Chip-Cp32dDmz.js";function s(){return r.jsx(o,{})}export{s as DiscoverPage};
2
+
@@ -1,2 +1,2 @@
1
- import{a as oe,u as ie,H as de,r as u,b as A,j as s,D as X,J as Y,M as ce,E as le,P as he,K as ue,q,O as pe,h as xe}from"./index-ASW1Jl0Y.js";import{b as Z,E as O,B as $,e as me,f as J,C as T,T as V}from"./Chip-Db--PJFH.js";function ge(e){const t={};for(const n of e)t[n.path]={checked:!0,expanded:!1,loading:!1,error:null};return t}function fe(e){if(!e.sessions||!e.selected)return e.checked?"on":"off";const t=e.sessions.sessions.length,n=e.selected.size;return t===0||n===0?"off":n===t?"on":"mixed"}function C(e,t){return e.sessions&&e.selected?e.selected.size:e.checked?t.sessionCount:0}function je(e,t){return t.reduce((n,r)=>n+C(e[r.path]??R(),r),0)}function be(e,t){return t.filter(n=>C(e[n.path]??R(),n)>0)}function we(e,t,n){const r=e[t];if(!r)return e;const a={...r,checked:n};return r.sessions&&(a.selected=n?new Set(r.sessions.sessions.map(c=>c.sessionId)):new Set),{...e,[t]:a}}function ye(e,t,n){const r=e[t];if(!r||!r.sessions)return e;const a=new Set(r.selected??[]);return a.delete(n)||a.add(n),{...e,[t]:{...r,selected:a,checked:a.size>0}}}function ve(e,t,n){const r=e[t];if(!r)return e;const a=r.checked?new Set(n.sessions.map(c=>c.sessionId)):new Set;return{...e,[t]:{...r,sessions:n,selected:a,loading:!1,error:null}}}function D(e,t,n){const r=e[t];return r?{...e,[t]:{...r,...n}}:e}function Ne(e,t){const n=e??R();return C(n,t)===0?null:n.sessions&&n.selected?{sessionIds:[...n.selected]}:{}}function R(){return{checked:!1,expanded:!1,loading:!1,error:null}}function ke(e){return e.error!==void 0?e.stage==="create"?"danger":"warn":e.adopted>0?"success":"warn"}async function Se(e,t,n){let r;try{r=await e.createProject({name:t.name,slug:t.suggestedSlug,path:t.path,managed:!1})}catch(a){return{stage:"create",adopted:0,skipped:[],error:Q(a)}}try{const a=await e.adoptChats(r.slug,{sourceCwd:r.workingDir,...n.sessionIds?{sessionIds:n.sessionIds}:{}});return{project:r,adopted:a.adopted.length,skipped:a.skipped}}catch(a){return{stage:"import",project:r,adopted:0,skipped:[],error:Q(a)}}}async function $e(e,t,n){const r=[];for(const a of t){n(a.candidate.path,"running");const c=await Se(e,a.candidate,a.plan);r.push(c),n(a.candidate.path,"done",c)}return r}const Ce={sidechain:"sub-agent transcript","already-adopted":"already adopted","destination-exists":"a chat with that id already exists here","attributed-to-run":"belongs to a Paddock run",unreadable:"transcript unreadable","placement-failed":"copy failed","record-failed":"could not be recorded"};function _(e){if(e.length===0)return"";const t=[...new Set(e.map(n=>Ce[n.reason]??n.reason))];return`${e.length} skipped (${t.join(", ")})`}function Ie(e,t){var l;if(e.stage==="create")return`Couldn't create the project: ${e.error}`;const n=((l=e.project)==null?void 0:l.slug)??t.suggestedSlug;if(e.stage==="import")return`Project “${n}” was created, but importing its chats failed: ${e.error}. It is there and empty — you can import them from the project itself.`;if(e.adopted===0){const m=_(e.skipped);return t.recordedPath!==void 0?`Project “${n}” was created but no chats came with it. Its transcripts record ${t.recordedPath}, a different spelling of ${t.path}, and an import matches on the exact path.`:m?`Project “${n}” was created but no chats came with it — ${m}.`:`Project “${n}” was created but no chats came with it.`}const r=e.adopted,a=_(e.skipped),c=`Adopted ${r} chat${r===1?"":"s"} into “${n}”`;return a?`${c} — ${a}.`:`${c}.`}function Q(e){return e instanceof Error?e.message:String(e)}function Be({firstRun:e=!1,embedded:t=!1,onLeave:n,onStartChat:r}){const a=oe(),{refresh:c}=ie(),l=de(),[m,d]=u.useState(!1),[j,I]=u.useState(!1),[h,x]=u.useState(null),[y,z]=u.useState(null),[H,P]=u.useState(!0),[f,v]=u.useState({}),[k,B]=u.useState(!1),[L,F]=u.useState({}),[E,G]=u.useState({}),[S,ee]=u.useState(!1);u.useEffect(()=>{let o=!0;return P(!0),z(null),A.discover({includeNonGit:m,includeOutsideHome:j}).then(i=>{o&&(x(i),v(ge(i.candidates)),P(!1))}).catch(i=>{o&&(z(i instanceof Error?i.message:"Discovery failed"),P(!1))}),()=>{o=!1}},[m,j]);const w=(h==null?void 0:h.candidates)??[],M=u.useMemo(()=>je(f,w),[f,w]),b=u.useMemo(()=>be(f,w),[f,w]),se=u.useCallback(o=>{v(p=>{const g=p[o.path];if(!g)return p;const N=D(p,o.path,{expanded:!g.expanded});return g.expanded||g.sessions||g.loading?N:D(N,o.path,{loading:!0,error:null})});const i=f[o.path];!i||i.expanded||i.sessions||i.loading||A.discoverSessions(o.path).then(p=>v(g=>ve(g,o.path,p))).catch(p=>v(g=>D(g,o.path,{loading:!1,error:p instanceof Error?p.message:"Could not read this directory's sessions"})))},[f]),te=u.useCallback(async()=>{if(k)return;B(!0),F(Object.fromEntries(b.map(i=>[i.path,"pending"]))),G({});const o=b.map(i=>({candidate:i,plan:Ne(f[i.path],i)??{}}));await $e(A,o,(i,p,g)=>{F(N=>({...N,[i]:p})),g&&G(N=>({...N,[i]:g}))}),B(!1),ee(!0),await c()},[b,f,k,c]),ne=u.useCallback(async()=>{await c(),n==null||n(),a("/")},[a,c,n]),ae=Object.values(E).reduce((o,i)=>o+i.adopted,0),re=Object.values(E).filter(o=>o.project).length,K=s.jsxs(s.Fragment,{children:[s.jsx("p",{className:"mb-5 text-sm text-fg-muted",children:e?"If you have used Claude Code in a terminal on this machine, Paddock can adopt that history: each directory becomes a project with its conversations already in it.":"Directories on this machine with existing Claude Code history. Adopting one links it as a project and brings its conversations in; your own history is never moved or deleted."}),S&&s.jsx(Te,{imported:ae,projects:re,onGetStarted:ne}),y!==null&&s.jsx(Z,{tone:"danger",icon:s.jsx(X,{width:16,height:16}),children:y}),H&&s.jsx(De,{}),!H&&y===null&&h!==null&&s.jsxs(s.Fragment,{children:[h.scanned===0?s.jsx(Ae,{claudeHome:h.claudeHome,onStartChat:r}):w.length===0?s.jsx(O,{variant:"panel",icon:s.jsx(Y,{width:22,height:22}),title:"Nothing to adopt",body:"Paddock found Claude Code history on this machine, but none of it is available to adopt right now. The tally below says what was skipped, and the two toggles relax the rules that are safe to relax."}):s.jsx("ul",{className:"space-y-2",children:w.map(o=>s.jsx(Pe,{candidate:o,row:f[o.path],status:L[o.path],outcome:E[o.path],locked:k||S,onToggleRow:i=>v(p=>we(p,o.path,i)),onToggleSession:i=>v(p=>ye(p,o.path,i)),onToggleExpanded:()=>se(o)},o.path))}),!S&&h.scanned>0&&s.jsx(Ee,{result:h,includeNonGit:m,includeOutsideHome:j,disabled:k,onIncludeNonGit:d,onIncludeOutsideHome:I}),w.length>0&&!S&&s.jsxs("div",{className:"mt-5 flex items-center justify-between gap-3 border-t border-edge pt-4",children:[s.jsxs("span",{className:"text-sm text-fg-muted",children:[M," conversation",M===1?"":"s"," from ",b.length," director",b.length===1?"y":"ies"]}),s.jsxs($,{variant:"primary",onClick:()=>void te(),disabled:b.length===0,loading:k,loadingLabel:"Adopting…",children:["Adopt ",b.length," project",b.length===1?"":"s"]})]})]})]});return t?K:s.jsxs("div",{className:"flex h-full min-h-0 flex-col",children:[s.jsxs("header",{className:"pt-safe flex items-center gap-2 border-b border-edge px-3 pb-2.5 sm:px-6 lg:py-4",children:[s.jsx("button",{type:"button",onClick:()=>l==null?void 0:l.openNav(),"aria-label":"Open menu",className:"btn-subtle -ml-1 shrink-0 px-2 py-1.5 lg:hidden",children:s.jsx(ce,{width:20,height:20})}),s.jsx(le,{width:18,height:18,className:"shrink-0 text-fg-subtle"}),s.jsx("h1",{className:"text-md font-semibold tracking-tight",children:"Discover"})]}),s.jsx("div",{className:"flex-1 overflow-y-auto overscroll-contain",children:s.jsx("div",{className:"mx-auto max-w-3xl px-6 py-6",children:K})})]})}function Pe({candidate:e,row:t,status:n,outcome:r,locked:a,onToggleRow:c,onToggleSession:l,onToggleExpanded:m}){const d=t??{checked:!1,expanded:!1,loading:!1,error:null},j=fe(d),I=C(d,e),h=r?ke(r):null;return s.jsx("li",{children:s.jsxs(me,{flush:!0,className:q("overflow-hidden",h==="success"&&"border-success-edge bg-success-soft",h==="warn"&&"border-warn-edge bg-warn-soft",h==="danger"&&"border-danger-edge bg-danger-soft",n==="running"&&"border-accent-edge"),"data-testid":`discover-row-${e.suggestedSlug}`,"data-tone":h??void 0,children:[s.jsxs("div",{className:"flex items-start gap-3 px-3 py-2.5",children:[s.jsx(J,{className:"mt-1",checked:j==="on",indeterminate:j==="mixed",disabled:a,"aria-label":`Adopt ${e.path}`,onChange:x=>c(x.target.checked)}),s.jsxs("div",{className:"min-w-0 flex-1",children:[s.jsx("code",{className:"block break-all text-sm text-fg",children:e.path}),s.jsxs("div",{className:"mt-1 flex flex-wrap items-center gap-x-2 gap-y-1 text-xs text-fg-muted",children:[s.jsxs("span",{className:"tabular",children:[e.sessionCount," conversation",e.sessionCount===1?"":"s"]}),e.filteredCount>0&&s.jsxs("span",{className:"tabular",title:"Empty, slash-command-only or sweeper transcripts, withheld as noise",children:["· ",e.filteredCount," filtered out"]}),e.lastSessionAt!==void 0&&s.jsxs("span",{className:"tabular",children:["· last ",W(e.lastSessionAt)]}),e.gitRemote!==void 0&&s.jsx(T,{tone:"lineage",size:"sm",children:e.gitRemote}),!e.hasGit&&s.jsx(T,{tone:"neutral",size:"sm",children:"no git"}),!e.insideHome&&s.jsx(T,{tone:"neutral",size:"sm",children:"outside home"})]}),e.recordedPath!==void 0&&s.jsx(Z,{tone:"warn",className:"mt-2",icon:s.jsx(X,{width:14,height:14}),children:s.jsxs("span",{className:"text-xs",children:["These transcripts record"," ",s.jsx("code",{className:"break-all",children:e.recordedPath})," — a different spelling of this path. The import matches on the exact path, so it may bring nothing in."]})}),r&&s.jsx("p",{className:q("mt-2 text-xs",h==="success"&&"text-success",h==="warn"&&"text-warn",h==="danger"&&"text-danger"),children:Ie(r,e)}),n==="running"&&!r&&s.jsx("p",{className:"mt-2 text-xs text-fg-muted",children:"Adopting…"})]}),s.jsxs("span",{className:"flex shrink-0 items-center gap-1",children:[s.jsx("span",{className:"tabular text-xs text-fg-subtle",children:I}),s.jsx($,{size:"icon-sm",variant:"subtle","aria-label":d.expanded?"Hide conversations":"Show conversations","aria-expanded":d.expanded,onClick:m,children:d.expanded?s.jsx(pe,{width:14,height:14}):s.jsx(xe,{width:14,height:14})})]})]}),d.expanded&&s.jsxs("div",{className:"border-t border-edge px-3 py-2",children:[d.loading&&s.jsx("p",{className:"py-2 text-xs text-fg-muted",children:"Reading transcripts…"}),d.error!==null&&s.jsx("p",{className:"py-2 text-xs text-danger",children:d.error}),d.sessions&&d.sessions.sessions.length===0&&s.jsx("p",{className:"py-2 text-xs text-fg-muted",children:"Nothing to adopt here any more — it may have been adopted since the scan."}),d.sessions&&d.sessions.sessions.length>0&&s.jsx("ul",{className:"space-y-1",children:d.sessions.sessions.map(x=>{var y;return s.jsx("li",{children:s.jsxs("label",{className:"flex cursor-pointer items-start gap-2 rounded-lg px-2 py-1.5 transition-colors hover:bg-surface-hover",children:[s.jsx(J,{checked:((y=d.selected)==null?void 0:y.has(x.sessionId))??!1,disabled:a,"aria-label":U(x),onChange:()=>l(x.sessionId)}),s.jsxs("span",{className:"min-w-0 flex-1",children:[s.jsx("span",{className:"block truncate text-xs text-fg",children:U(x)}),s.jsxs("span",{className:"tabular mt-0.5 block text-3xs text-fg-muted",children:[W(x.mtime)," · ",Re(x.sizeBytes)]})]})]})},x.sessionId)})}),d.sessions&&d.sessions.filtered.length>0&&s.jsxs("p",{className:"mt-2 px-2 text-3xs text-fg-subtle",children:[d.sessions.filtered.length," more withheld as noise (",[...new Set(d.sessions.filtered.map(x=>x.reason))].join(", "),")."]})]})]})})}function Ee({result:e,includeNonGit:t,includeOutsideHome:n,disabled:r,onIncludeNonGit:a,onIncludeOutsideHome:c}){const l=e.excluded["no-git"]??0,m=e.excluded["outside-home"]??0,d=l>0||t,j=m>0||n;return e.scanned===0?null:s.jsxs("div",{className:"mt-5 space-y-2 border-t border-edge pt-4",children:[s.jsx("p",{className:"text-xs text-fg-muted",children:Oe(e)}),d&&s.jsxs("div",{className:"flex items-center gap-2 text-xs text-fg-muted",children:[s.jsx(V,{checked:t,disabled:r,onChange:a,label:"Also offer directories without a git repository"}),s.jsxs("span",{children:["Also offer directories without a git repository",l>0&&` (${l} hidden)`]})]}),j&&s.jsxs("div",{className:"flex items-center gap-2 text-xs text-fg-muted",children:[s.jsx(V,{checked:n,disabled:r,onChange:c,label:"Also offer directories outside your home directory"}),s.jsxs("span",{children:["Also offer directories outside ",s.jsx("code",{children:e.homeDir}),m>0&&` (${m} hidden)`]})]})]})}function Ae({claudeHome:e,onStartChat:t}){return s.jsx(O,{variant:"panel",icon:s.jsx(ue,{width:22,height:22}),title:"Nothing to adopt yet",body:s.jsxs(s.Fragment,{children:["No Claude Code history has been recorded under"," ",s.jsx("code",{className:"break-all",children:e}),". That is normal on a new install, and on a container whose Claude home is its own rather than yours — nothing is wrong. Start a chat here and Paddock writes its own history; or bind-mount an existing one there and re-open this page, or import it headlessly with ",s.jsx("code",{children:"npm run import-chats"}),"."]}),action:t&&s.jsx($,{variant:"primary",icon:s.jsx(he,{width:14,height:14}),onClick:t,children:"Start a chat"})})}function Te({imported:e,projects:t,onGetStarted:n}){return s.jsx("div",{className:"mb-6",children:s.jsx(O,{variant:"panel",icon:s.jsx(Y,{width:22,height:22}),title:t===0?"Nothing was adopted":`${t} project${t===1?"":"s"}, ${e} conversation${e===1?"":"s"}`,body:t===0?"Every row failed. Each one says why below.":"They are in the sidebar now. Anything that did not land says why below.",action:s.jsx($,{variant:"primary",onClick:()=>void n(),children:"Get started"})})})}function De(){return s.jsx("div",{className:"space-y-2","aria-label":"Scanning",role:"status",children:[0,1,2].map(e=>s.jsx("div",{className:"h-16 animate-pulse rounded-2xl bg-surface-active"},e))})}function Oe(e){const t=[],n=[["temp-root",a=>`${a} in temp directories`],["no-git",a=>`${a} without a git repository`],["outside-home",a=>`${a} outside your home directory`],["already-managed",a=>`${a} already a project`],["no-sessions",a=>`${a} with nothing to adopt`],["no-recorded-cwd",a=>`${a} with no recorded directory`],["missing",a=>`${a} no longer on disk`],["home-root",a=>`${a} your home directory itself`],["system-path",a=>`${a} system directories`],["paddock-internal",a=>`${a} inside Paddock's own data`]];for(const[a,c]of n){const l=e.excluded[a];l!==void 0&&l>0&&t.push(c(l))}const r=`${e.scanned} transcript folder${e.scanned===1?"":"s"} scanned`;return t.length===0?`${r}.`:`${r}; skipped ${t.join(", ")}.`}function U(e){var r,a;const t=(r=e.autoName)==null?void 0:r.trim();if(t!==void 0&&t!=="")return t;const n=(a=e.preview)==null?void 0:a.trim();return n!==void 0&&n!==""?n:e.sessionId}function W(e){const t=new Date(e);return Number.isNaN(t.getTime())?"unknown date":t.toLocaleDateString(void 0,{year:"numeric",month:"short",day:"numeric"})}function Re(e){return e<1024?`${e} B`:e<1024*1024?`${Math.round(e/1024)} kB`:`${(e/(1024*1024)).toFixed(1)} MB`}export{Be as D};
1
+ import{a as oe,u as ie,H as de,r as u,b as A,j as s,D as X,J as Y,M as ce,E as le,P as he,K as ue,q,O as pe,h as xe}from"./index-Cx9y6c3f.js";import{b as Z,E as O,B as $,e as me,f as J,C as T,T as V}from"./Chip-Cp32dDmz.js";function ge(e){const t={};for(const n of e)t[n.path]={checked:!0,expanded:!1,loading:!1,error:null};return t}function fe(e){if(!e.sessions||!e.selected)return e.checked?"on":"off";const t=e.sessions.sessions.length,n=e.selected.size;return t===0||n===0?"off":n===t?"on":"mixed"}function C(e,t){return e.sessions&&e.selected?e.selected.size:e.checked?t.sessionCount:0}function je(e,t){return t.reduce((n,r)=>n+C(e[r.path]??R(),r),0)}function be(e,t){return t.filter(n=>C(e[n.path]??R(),n)>0)}function we(e,t,n){const r=e[t];if(!r)return e;const a={...r,checked:n};return r.sessions&&(a.selected=n?new Set(r.sessions.sessions.map(c=>c.sessionId)):new Set),{...e,[t]:a}}function ye(e,t,n){const r=e[t];if(!r||!r.sessions)return e;const a=new Set(r.selected??[]);return a.delete(n)||a.add(n),{...e,[t]:{...r,selected:a,checked:a.size>0}}}function ve(e,t,n){const r=e[t];if(!r)return e;const a=r.checked?new Set(n.sessions.map(c=>c.sessionId)):new Set;return{...e,[t]:{...r,sessions:n,selected:a,loading:!1,error:null}}}function D(e,t,n){const r=e[t];return r?{...e,[t]:{...r,...n}}:e}function Ne(e,t){const n=e??R();return C(n,t)===0?null:n.sessions&&n.selected?{sessionIds:[...n.selected]}:{}}function R(){return{checked:!1,expanded:!1,loading:!1,error:null}}function ke(e){return e.error!==void 0?e.stage==="create"?"danger":"warn":e.adopted>0?"success":"warn"}async function Se(e,t,n){let r;try{r=await e.createProject({name:t.name,slug:t.suggestedSlug,path:t.path,managed:!1})}catch(a){return{stage:"create",adopted:0,skipped:[],error:Q(a)}}try{const a=await e.adoptChats(r.slug,{sourceCwd:r.workingDir,...n.sessionIds?{sessionIds:n.sessionIds}:{}});return{project:r,adopted:a.adopted.length,skipped:a.skipped}}catch(a){return{stage:"import",project:r,adopted:0,skipped:[],error:Q(a)}}}async function $e(e,t,n){const r=[];for(const a of t){n(a.candidate.path,"running");const c=await Se(e,a.candidate,a.plan);r.push(c),n(a.candidate.path,"done",c)}return r}const Ce={sidechain:"sub-agent transcript","already-adopted":"already adopted","destination-exists":"a chat with that id already exists here","attributed-to-run":"belongs to a Paddock run",unreadable:"transcript unreadable","placement-failed":"copy failed","record-failed":"could not be recorded"};function _(e){if(e.length===0)return"";const t=[...new Set(e.map(n=>Ce[n.reason]??n.reason))];return`${e.length} skipped (${t.join(", ")})`}function Ie(e,t){var l;if(e.stage==="create")return`Couldn't create the project: ${e.error}`;const n=((l=e.project)==null?void 0:l.slug)??t.suggestedSlug;if(e.stage==="import")return`Project “${n}” was created, but importing its chats failed: ${e.error}. It is there and empty — you can import them from the project itself.`;if(e.adopted===0){const m=_(e.skipped);return t.recordedPath!==void 0?`Project “${n}” was created but no chats came with it. Its transcripts record ${t.recordedPath}, a different spelling of ${t.path}, and an import matches on the exact path.`:m?`Project “${n}” was created but no chats came with it — ${m}.`:`Project “${n}” was created but no chats came with it.`}const r=e.adopted,a=_(e.skipped),c=`Adopted ${r} chat${r===1?"":"s"} into “${n}”`;return a?`${c} — ${a}.`:`${c}.`}function Q(e){return e instanceof Error?e.message:String(e)}function Be({firstRun:e=!1,embedded:t=!1,onLeave:n,onStartChat:r}){const a=oe(),{refresh:c}=ie(),l=de(),[m,d]=u.useState(!1),[j,I]=u.useState(!1),[h,x]=u.useState(null),[y,z]=u.useState(null),[H,P]=u.useState(!0),[f,v]=u.useState({}),[k,B]=u.useState(!1),[L,F]=u.useState({}),[E,G]=u.useState({}),[S,ee]=u.useState(!1);u.useEffect(()=>{let o=!0;return P(!0),z(null),A.discover({includeNonGit:m,includeOutsideHome:j}).then(i=>{o&&(x(i),v(ge(i.candidates)),P(!1))}).catch(i=>{o&&(z(i instanceof Error?i.message:"Discovery failed"),P(!1))}),()=>{o=!1}},[m,j]);const w=(h==null?void 0:h.candidates)??[],M=u.useMemo(()=>je(f,w),[f,w]),b=u.useMemo(()=>be(f,w),[f,w]),se=u.useCallback(o=>{v(p=>{const g=p[o.path];if(!g)return p;const N=D(p,o.path,{expanded:!g.expanded});return g.expanded||g.sessions||g.loading?N:D(N,o.path,{loading:!0,error:null})});const i=f[o.path];!i||i.expanded||i.sessions||i.loading||A.discoverSessions(o.path).then(p=>v(g=>ve(g,o.path,p))).catch(p=>v(g=>D(g,o.path,{loading:!1,error:p instanceof Error?p.message:"Could not read this directory's sessions"})))},[f]),te=u.useCallback(async()=>{if(k)return;B(!0),F(Object.fromEntries(b.map(i=>[i.path,"pending"]))),G({});const o=b.map(i=>({candidate:i,plan:Ne(f[i.path],i)??{}}));await $e(A,o,(i,p,g)=>{F(N=>({...N,[i]:p})),g&&G(N=>({...N,[i]:g}))}),B(!1),ee(!0),await c()},[b,f,k,c]),ne=u.useCallback(async()=>{await c(),n==null||n(),a("/")},[a,c,n]),ae=Object.values(E).reduce((o,i)=>o+i.adopted,0),re=Object.values(E).filter(o=>o.project).length,K=s.jsxs(s.Fragment,{children:[s.jsx("p",{className:"mb-5 text-sm text-fg-muted",children:e?"If you have used Claude Code in a terminal on this machine, Paddock can adopt that history: each directory becomes a project with its conversations already in it.":"Directories on this machine with existing Claude Code history. Adopting one links it as a project and brings its conversations in; your own history is never moved or deleted."}),S&&s.jsx(Te,{imported:ae,projects:re,onGetStarted:ne}),y!==null&&s.jsx(Z,{tone:"danger",icon:s.jsx(X,{width:16,height:16}),children:y}),H&&s.jsx(De,{}),!H&&y===null&&h!==null&&s.jsxs(s.Fragment,{children:[h.scanned===0?s.jsx(Ae,{claudeHome:h.claudeHome,onStartChat:r}):w.length===0?s.jsx(O,{variant:"panel",icon:s.jsx(Y,{width:22,height:22}),title:"Nothing to adopt",body:"Paddock found Claude Code history on this machine, but none of it is available to adopt right now. The tally below says what was skipped, and the two toggles relax the rules that are safe to relax."}):s.jsx("ul",{className:"space-y-2",children:w.map(o=>s.jsx(Pe,{candidate:o,row:f[o.path],status:L[o.path],outcome:E[o.path],locked:k||S,onToggleRow:i=>v(p=>we(p,o.path,i)),onToggleSession:i=>v(p=>ye(p,o.path,i)),onToggleExpanded:()=>se(o)},o.path))}),!S&&h.scanned>0&&s.jsx(Ee,{result:h,includeNonGit:m,includeOutsideHome:j,disabled:k,onIncludeNonGit:d,onIncludeOutsideHome:I}),w.length>0&&!S&&s.jsxs("div",{className:"mt-5 flex items-center justify-between gap-3 border-t border-edge pt-4",children:[s.jsxs("span",{className:"text-sm text-fg-muted",children:[M," conversation",M===1?"":"s"," from ",b.length," director",b.length===1?"y":"ies"]}),s.jsxs($,{variant:"primary",onClick:()=>void te(),disabled:b.length===0,loading:k,loadingLabel:"Adopting…",children:["Adopt ",b.length," project",b.length===1?"":"s"]})]})]})]});return t?K:s.jsxs("div",{className:"flex h-full min-h-0 flex-col",children:[s.jsxs("header",{className:"pt-safe flex items-center gap-2 border-b border-edge px-3 pb-2.5 sm:px-6 lg:py-4",children:[s.jsx("button",{type:"button",onClick:()=>l==null?void 0:l.openNav(),"aria-label":"Open menu",className:"btn-subtle -ml-1 shrink-0 px-2 py-1.5 lg:hidden",children:s.jsx(ce,{width:20,height:20})}),s.jsx(le,{width:18,height:18,className:"shrink-0 text-fg-subtle"}),s.jsx("h1",{className:"text-md font-semibold tracking-tight",children:"Discover"})]}),s.jsx("div",{className:"flex-1 overflow-y-auto overscroll-contain",children:s.jsx("div",{className:"mx-auto max-w-3xl px-6 py-6",children:K})})]})}function Pe({candidate:e,row:t,status:n,outcome:r,locked:a,onToggleRow:c,onToggleSession:l,onToggleExpanded:m}){const d=t??{checked:!1,expanded:!1,loading:!1,error:null},j=fe(d),I=C(d,e),h=r?ke(r):null;return s.jsx("li",{children:s.jsxs(me,{flush:!0,className:q("overflow-hidden",h==="success"&&"border-success-edge bg-success-soft",h==="warn"&&"border-warn-edge bg-warn-soft",h==="danger"&&"border-danger-edge bg-danger-soft",n==="running"&&"border-accent-edge"),"data-testid":`discover-row-${e.suggestedSlug}`,"data-tone":h??void 0,children:[s.jsxs("div",{className:"flex items-start gap-3 px-3 py-2.5",children:[s.jsx(J,{className:"mt-1",checked:j==="on",indeterminate:j==="mixed",disabled:a,"aria-label":`Adopt ${e.path}`,onChange:x=>c(x.target.checked)}),s.jsxs("div",{className:"min-w-0 flex-1",children:[s.jsx("code",{className:"block break-all text-sm text-fg",children:e.path}),s.jsxs("div",{className:"mt-1 flex flex-wrap items-center gap-x-2 gap-y-1 text-xs text-fg-muted",children:[s.jsxs("span",{className:"tabular",children:[e.sessionCount," conversation",e.sessionCount===1?"":"s"]}),e.filteredCount>0&&s.jsxs("span",{className:"tabular",title:"Empty, slash-command-only or sweeper transcripts, withheld as noise",children:["· ",e.filteredCount," filtered out"]}),e.lastSessionAt!==void 0&&s.jsxs("span",{className:"tabular",children:["· last ",W(e.lastSessionAt)]}),e.gitRemote!==void 0&&s.jsx(T,{tone:"lineage",size:"sm",children:e.gitRemote}),!e.hasGit&&s.jsx(T,{tone:"neutral",size:"sm",children:"no git"}),!e.insideHome&&s.jsx(T,{tone:"neutral",size:"sm",children:"outside home"})]}),e.recordedPath!==void 0&&s.jsx(Z,{tone:"warn",className:"mt-2",icon:s.jsx(X,{width:14,height:14}),children:s.jsxs("span",{className:"text-xs",children:["These transcripts record"," ",s.jsx("code",{className:"break-all",children:e.recordedPath})," — a different spelling of this path. The import matches on the exact path, so it may bring nothing in."]})}),r&&s.jsx("p",{className:q("mt-2 text-xs",h==="success"&&"text-success",h==="warn"&&"text-warn",h==="danger"&&"text-danger"),children:Ie(r,e)}),n==="running"&&!r&&s.jsx("p",{className:"mt-2 text-xs text-fg-muted",children:"Adopting…"})]}),s.jsxs("span",{className:"flex shrink-0 items-center gap-1",children:[s.jsx("span",{className:"tabular text-xs text-fg-subtle",children:I}),s.jsx($,{size:"icon-sm",variant:"subtle","aria-label":d.expanded?"Hide conversations":"Show conversations","aria-expanded":d.expanded,onClick:m,children:d.expanded?s.jsx(pe,{width:14,height:14}):s.jsx(xe,{width:14,height:14})})]})]}),d.expanded&&s.jsxs("div",{className:"border-t border-edge px-3 py-2",children:[d.loading&&s.jsx("p",{className:"py-2 text-xs text-fg-muted",children:"Reading transcripts…"}),d.error!==null&&s.jsx("p",{className:"py-2 text-xs text-danger",children:d.error}),d.sessions&&d.sessions.sessions.length===0&&s.jsx("p",{className:"py-2 text-xs text-fg-muted",children:"Nothing to adopt here any more — it may have been adopted since the scan."}),d.sessions&&d.sessions.sessions.length>0&&s.jsx("ul",{className:"space-y-1",children:d.sessions.sessions.map(x=>{var y;return s.jsx("li",{children:s.jsxs("label",{className:"flex cursor-pointer items-start gap-2 rounded-lg px-2 py-1.5 transition-colors hover:bg-surface-hover",children:[s.jsx(J,{checked:((y=d.selected)==null?void 0:y.has(x.sessionId))??!1,disabled:a,"aria-label":U(x),onChange:()=>l(x.sessionId)}),s.jsxs("span",{className:"min-w-0 flex-1",children:[s.jsx("span",{className:"block truncate text-xs text-fg",children:U(x)}),s.jsxs("span",{className:"tabular mt-0.5 block text-3xs text-fg-muted",children:[W(x.mtime)," · ",Re(x.sizeBytes)]})]})]})},x.sessionId)})}),d.sessions&&d.sessions.filtered.length>0&&s.jsxs("p",{className:"mt-2 px-2 text-3xs text-fg-subtle",children:[d.sessions.filtered.length," more withheld as noise (",[...new Set(d.sessions.filtered.map(x=>x.reason))].join(", "),")."]})]})]})})}function Ee({result:e,includeNonGit:t,includeOutsideHome:n,disabled:r,onIncludeNonGit:a,onIncludeOutsideHome:c}){const l=e.excluded["no-git"]??0,m=e.excluded["outside-home"]??0,d=l>0||t,j=m>0||n;return e.scanned===0?null:s.jsxs("div",{className:"mt-5 space-y-2 border-t border-edge pt-4",children:[s.jsx("p",{className:"text-xs text-fg-muted",children:Oe(e)}),d&&s.jsxs("div",{className:"flex items-center gap-2 text-xs text-fg-muted",children:[s.jsx(V,{checked:t,disabled:r,onChange:a,label:"Also offer directories without a git repository"}),s.jsxs("span",{children:["Also offer directories without a git repository",l>0&&` (${l} hidden)`]})]}),j&&s.jsxs("div",{className:"flex items-center gap-2 text-xs text-fg-muted",children:[s.jsx(V,{checked:n,disabled:r,onChange:c,label:"Also offer directories outside your home directory"}),s.jsxs("span",{children:["Also offer directories outside ",s.jsx("code",{children:e.homeDir}),m>0&&` (${m} hidden)`]})]})]})}function Ae({claudeHome:e,onStartChat:t}){return s.jsx(O,{variant:"panel",icon:s.jsx(ue,{width:22,height:22}),title:"Nothing to adopt yet",body:s.jsxs(s.Fragment,{children:["No Claude Code history has been recorded under"," ",s.jsx("code",{className:"break-all",children:e}),". That is normal on a new install, and on a container whose Claude home is its own rather than yours — nothing is wrong. Start a chat here and Paddock writes its own history; or bind-mount an existing one there and re-open this page, or import it headlessly with ",s.jsx("code",{children:"npm run import-chats"}),"."]}),action:t&&s.jsx($,{variant:"primary",icon:s.jsx(he,{width:14,height:14}),onClick:t,children:"Start a chat"})})}function Te({imported:e,projects:t,onGetStarted:n}){return s.jsx("div",{className:"mb-6",children:s.jsx(O,{variant:"panel",icon:s.jsx(Y,{width:22,height:22}),title:t===0?"Nothing was adopted":`${t} project${t===1?"":"s"}, ${e} conversation${e===1?"":"s"}`,body:t===0?"Every row failed. Each one says why below.":"They are in the sidebar now. Anything that did not land says why below.",action:s.jsx($,{variant:"primary",onClick:()=>void n(),children:"Get started"})})})}function De(){return s.jsx("div",{className:"space-y-2","aria-label":"Scanning",role:"status",children:[0,1,2].map(e=>s.jsx("div",{className:"h-16 animate-pulse rounded-2xl bg-surface-active"},e))})}function Oe(e){const t=[],n=[["temp-root",a=>`${a} in temp directories`],["no-git",a=>`${a} without a git repository`],["outside-home",a=>`${a} outside your home directory`],["already-managed",a=>`${a} already a project`],["no-sessions",a=>`${a} with nothing to adopt`],["no-recorded-cwd",a=>`${a} with no recorded directory`],["missing",a=>`${a} no longer on disk`],["home-root",a=>`${a} your home directory itself`],["system-path",a=>`${a} system directories`],["paddock-internal",a=>`${a} inside Paddock's own data`]];for(const[a,c]of n){const l=e.excluded[a];l!==void 0&&l>0&&t.push(c(l))}const r=`${e.scanned} transcript folder${e.scanned===1?"":"s"} scanned`;return t.length===0?`${r}.`:`${r}; skipped ${t.join(", ")}.`}function U(e){var r,a;const t=(r=e.autoName)==null?void 0:r.trim();if(t!==void 0&&t!=="")return t;const n=(a=e.preview)==null?void 0:a.trim();return n!==void 0&&n!==""?n:e.sessionId}function W(e){const t=new Date(e);return Number.isNaN(t.getTime())?"unknown date":t.toLocaleDateString(void 0,{year:"numeric",month:"short",day:"numeric"})}function Re(e){return e<1024?`${e} B`:e<1024*1024?`${Math.round(e/1024)} kB`:`${(e/(1024*1024)).toFixed(1)} MB`}export{Be as D};
2
2
 
@@ -1,2 +1,2 @@
1
- import{r as u,m as W,s as Z,A as ee,n as pe,j as e,p as ae,q as b,t as ie,v as be,w as je,x as le,y as ve,z as ye,b as O,D as oe,E as we,X as Ne,F as ke,G as Ce,H as Se,M as Ae,I as Ee}from"./index-ASW1Jl0Y.js";import{B as A,C as ce,S as L,a as te,I as B,b as Re,T as $e,c as Me,d as Pe}from"./Chip-Db--PJFH.js";const Ie=Array.from({length:72},(t,n)=>n*5),S=[...ie].sort((t,n)=>t.hue-n.hue),z=(t,n)=>Math.min(Math.abs(t-n),360-Math.abs(t-n));function ne(t){const n=S.reduce((a,s)=>z(s.hue,t)<z(a.hue,t)?s:a);if(z(n.hue,t)<=8)return n.name;const r=S.find(a=>a.hue>t)??S[0];return`between ${S[(S.indexOf(r)-1+S.length)%S.length].name} and ${r.name}`}function Fe({theme:t,dark:n,hue:r,className:c}){const a=u.useRef(null);return u.useLayoutEffect(()=>{const s=a.current;s&&(r===null?je(s):le(r,s))},[t,n,r]),e.jsx("div",{ref:a,"data-theme":t,className:b("overflow-hidden rounded-lg border border-edge",n&&"dark",c),children:e.jsxs("div",{className:"flex h-full items-center gap-2 bg-surface p-2",children:[e.jsxs("div",{className:"flex-1 rounded-md border border-edge-subtle bg-surface-raised p-1.5",children:[e.jsx("div",{className:"h-1 w-4/5 rounded-full bg-fg"}),e.jsx("div",{className:"mt-1 h-1 w-3/5 rounded-full bg-fg-subtle"})]}),e.jsx("div",{className:"grid h-6 w-6 shrink-0 place-items-center rounded-md bg-accent-solid",children:e.jsx("div",{className:"h-1 w-3 rounded-full bg-accent-fg"})})]})})}function Te({hexes:t,hue:n,active:r,onCommit:c}){const a=u.useRef(null),s=u.useRef(null),d=u.useRef(null),x=u.useRef(0),h=u.useRef(null),p=u.useRef(!1),g=u.useRef(null),l=u.useMemo(()=>{if(t.length===0)return;const m=t.map((j,y)=>`${j} ${(y/t.length*100).toFixed(2)}%`);return m.push(`${t[0]} 100%`),`linear-gradient(to right, ${m.join(", ")})`},[t]),f=u.useCallback(m=>{s.current&&(s.current.style.left=`${m/360*100}%`),d.current&&(d.current.textContent=ne(m))},[]);u.useEffect(()=>{p.current||f(n)},[n,f]);const N=m=>{var $;const j=($=a.current)==null?void 0:$.getBoundingClientRect();if(!j||j.width===0)return 0;const y=Math.min(1,Math.max(0,(m-j.left)/j.width));return Math.round(y*360)%360},w=u.useCallback(m=>{h.current=m,!x.current&&(x.current=requestAnimationFrame(()=>{x.current=0;const j=h.current;h.current=null,j!==null&&(f(j),le(j,document.documentElement,{context:g.current??void 0,live:!0}))}))},[f]);u.useEffect(()=>()=>cancelAnimationFrame(x.current),[]);const F=m=>{p.current=!1,g.current=null,cancelAnimationFrame(x.current),x.current=0,h.current=null,c(m)};return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"mt-2 flex items-baseline justify-between gap-2",children:[e.jsx("span",{className:"text-3xs text-fg-subtle",children:"Drag along the strip"}),e.jsx("span",{ref:d,className:"text-3xs font-medium text-fg-muted","aria-hidden":!0})]}),e.jsx("div",{ref:a,role:"slider",tabIndex:0,"aria-label":"Accent colour","aria-valuemin":0,"aria-valuemax":359,"aria-valuenow":n,"aria-valuetext":r?ne(n):"the theme’s own colour",onPointerDown:m=>{m.currentTarget.setPointerCapture(m.pointerId),p.current=!0,g.current=ve(),w(N(m.clientX))},onPointerMove:m=>{p.current&&w(N(m.clientX))},onPointerUp:m=>{p.current&&F(N(m.clientX))},onPointerCancel:()=>{p.current&&F(n)},onKeyDown:m=>{const j=m.key==="PageUp"||m.key==="PageDown"?15:m.shiftKey?10:2;let y=null;m.key==="ArrowLeft"||m.key==="ArrowDown"||m.key==="PageDown"?y=(n-j+360)%360:m.key==="ArrowRight"||m.key==="ArrowUp"||m.key==="PageUp"?y=(n+j)%360:m.key==="Home"?y=0:m.key==="End"&&(y=359),y!==null&&(m.preventDefault(),c(y))},style:{backgroundImage:l,touchAction:"none"},className:b("relative mt-1 h-8 cursor-pointer rounded-lg border border-edge shadow-xs select-none","focus-visible:focus-ring"),children:e.jsx("div",{ref:s,"aria-hidden":!0,style:{left:`${n/360*100}%`},className:b("pointer-events-none absolute top-1/2 h-[calc(100%+6px)] w-1.5 -translate-x-1/2 -translate-y-1/2 rounded-full","border border-fg bg-surface-raised shadow-sm",!r&&"opacity-0")})})]})}function Oe({className:t}){const[n,r]=u.useState(W),[c,a]=u.useState(null),s=typeof document<"u"&&document.documentElement.classList.contains("dark"),d=u.useRef(n),x=u.useCallback(l=>{const f={...d.current,...l};d.current=f,r(f),a(Z(f))},[]);u.useEffect(()=>{const l=f=>a(f.detail);return window.addEventListener(ee,l),a(Z(W())),()=>window.removeEventListener(ee,l)},[]);const h=u.useMemo(()=>pe(Ie),[n.theme,s,c==null?void 0:c.mode]),p=(c==null?void 0:c.hue)??0,g=n.hue!==null;return e.jsxs("div",{className:b("space-y-5",t),children:[e.jsxs("fieldset",{children:[e.jsx("legend",{className:"text-2xs font-semibold uppercase tracking-wide text-fg-muted",children:"Theme"}),e.jsx("div",{className:b("mt-2 grid gap-2","grid-cols-2 sm:grid-cols-4"),children:ae.map(l=>{const f=n.theme===l.id;return e.jsxs("button",{type:"button","aria-pressed":f,title:`${l.label} — ${l.blurb}`,onClick:()=>x({theme:l.id}),className:b("motion-fast rounded-xl border text-left transition-[border-color,box-shadow]","focus-visible:focus-ring","p-1.5",f?"border-accent-edge bg-accent-soft shadow-xs":"border-edge bg-surface-raised hover:border-edge-strong"),children:[e.jsx(Fe,{theme:l.id,dark:s,hue:n.hue,className:"h-10"}),e.jsxs("div",{className:"mt-1.5 min-w-0 px-0.5 pb-0.5",children:[e.jsx("span",{className:"block truncate text-xs font-semibold text-fg",children:l.label}),e.jsx("span",{className:"mt-0.5 line-clamp-2 text-3xs leading-snug text-fg-muted",children:l.blurb})]})]},l.id)})})]}),e.jsxs("div",{className:b("grid gap-5 lg:grid-cols-[minmax(0,1fr)_15rem] lg:items-start"),children:[e.jsxs("fieldset",{children:[e.jsx("legend",{className:"text-2xs font-semibold uppercase tracking-wide text-fg-muted",children:"Accent colour"}),e.jsx("p",{className:"mt-1 text-3xs leading-snug text-fg-subtle",children:"Pick any colour. The theme adjusts it so buttons and labels stay readable in both light and dark."}),e.jsx(Te,{hexes:h,hue:p,active:g,onCommit:l=>x({hue:l})}),e.jsxs("div",{className:"mt-2 flex flex-wrap gap-1",children:[e.jsx("button",{type:"button",onClick:()=>x({hue:null}),"aria-pressed":!g,className:b("motion-fast rounded-md border px-2 py-1 text-3xs transition-colors","focus-visible:focus-ring",g?"border-edge text-fg-muted hover:border-edge-strong hover:text-fg":"border-accent-edge bg-accent-soft text-accent"),children:"Theme’s own"}),ie.map(l=>{const f=g&&Math.abs(p-l.hue)<2.5;return e.jsxs("button",{type:"button","aria-pressed":f,onClick:()=>x({hue:l.hue}),className:b("motion-fast inline-flex items-center gap-1.5 rounded-md border px-2 py-1 text-3xs transition-colors","focus-visible:focus-ring",f?"border-edge-strong bg-surface-active text-fg":"border-edge text-fg-muted hover:border-edge-strong hover:text-fg"),children:[e.jsx("span",{"aria-hidden":!0,className:"h-2.5 w-2.5 rounded-full",style:{backgroundColor:h[Math.round(l.hue/5)%h.length]}}),l.name]},l.name)})]})]}),e.jsxs("fieldset",{children:[e.jsx("legend",{className:"text-2xs font-semibold uppercase tracking-wide text-fg-muted",children:"Tint the background"}),e.jsx("p",{className:"mt-1 text-3xs leading-snug text-fg-subtle",children:"Colours the whole page a little, not just the buttons. Useful for telling two Paddock instances apart at a glance."}),e.jsx("div",{className:"mt-2 inline-flex rounded-lg border border-edge p-0.5",children:be.map(l=>e.jsx("button",{type:"button","aria-pressed":n.tint===l.level,onClick:()=>x({tint:l.level}),className:b("motion-fast rounded-md px-2.5 py-1 text-3xs transition-colors","focus-visible:focus-ring",n.tint===l.level?"bg-surface-active font-medium text-fg":"text-fg-muted hover:text-fg"),children:l.label},l.level))})]})]}),e.jsx(Le,{})]})}function Le(){return e.jsxs("div",{children:[e.jsx("p",{className:"text-2xs font-semibold uppercase tracking-wide text-fg-muted",children:"Preview"}),e.jsxs("div",{className:"mt-2 flex flex-wrap items-center gap-2 rounded-xl border border-edge bg-surface p-3",children:[e.jsx(A,{variant:"primary",size:"sm",children:"Send"}),e.jsx(A,{variant:"ghost",size:"sm",children:"Cancel"}),e.jsx(A,{variant:"link",size:"sm",children:"A link"}),e.jsx("span",{className:"inline-flex items-center gap-1 rounded-md border border-accent-edge bg-accent-soft px-1.5 py-0.5 text-2xs font-medium text-accent",children:"accent chip"}),e.jsx(ce,{tone:"accent",shape:"pill",dot:!0,children:"running"}),e.jsxs("span",{className:"inline-flex items-center gap-1.5 text-2xs text-fg-subtle",children:[e.jsx("span",{className:"h-4 w-4 rounded-md border border-edge bg-accent-solid-hover","aria-hidden":!0}),"hovered"]}),e.jsxs("span",{className:"ml-auto inline-flex items-center gap-1.5",children:[e.jsx(L,{tone:"success"}),e.jsx(L,{tone:"warn"}),e.jsx(L,{tone:"danger"}),e.jsx(L,{tone:"info"}),e.jsx("span",{className:"text-2xs text-fg-subtle",children:"status hues (theme’s, not yours)"})]})]})]})}const _="mx-auto w-full max-w-4xl",De="sm:w-64";function Ve(){const[t,n]=u.useState(null),[r,c]=u.useState(!0),[a,s]=u.useState(null),[d,x]=u.useState({}),[h,p]=u.useState(!1),[g,l]=u.useState(null),[f,N]=u.useState(!1),[w,F]=u.useState(""),[m,j]=u.useState(!1),[y,$]=u.useState(null),K=u.useRef(null),de=ye("(min-width: 1024px)");u.useEffect(()=>{let i=!0;return c(!0),O.getInstanceConfig().then(o=>{i&&(n(o),s(null))}).catch(o=>i&&s(o instanceof Error?o.message:String(o))).finally(()=>i&&c(!1)),()=>{i=!1}},[]);const ue=(i,o)=>{N(!1),l(null),x(v=>({...v,[i]:o}))},me=i=>se(i,d),U=u.useMemo(()=>t?t.groups.flatMap(i=>i.fields):[],[t]),k=u.useMemo(()=>U.filter(i=>i.editable&&!i.envOverridden).filter(i=>Object.prototype.hasOwnProperty.call(d,i.key)).filter(i=>!re(d[i.key],q(i))).map(i=>i.key),[U,d]),X=u.useMemo(()=>new Set(k),[k]),C=u.useMemo(()=>{if(!t)return[];const i=w.trim().toLowerCase(),o=[];for(const v of t.groups){const P=i!==""&&v.label.toLowerCase().includes(i),I=v.fields.filter(E=>{const T=se(E,d);return m&&re(T,E.default)?!1:i===""||P?!0:Ye(E).includes(i)});I.length>0&&o.push({...v,fields:I})}return o},[t,w,m,d]),J=C.reduce((i,o)=>i+o.fields.length,0),xe=w.trim()!==""||m,H=!m&&(w.trim()===""||We.includes(w.trim().toLowerCase())),M=u.useMemo(()=>H?[V,...C]:C,[H,C]),he=C.some(i=>i.fields.some(o=>o.envOverridden)),Y=Qe(C,X);u.useEffect(()=>{const i=K.current;if(!i||M.length===0)return;const o=M.map(P=>P.id),v=()=>{const P=i.getBoundingClientRect().top;let I=o[0];for(const E of o){const T=document.getElementById(D(E));if(T)if(T.getBoundingClientRect().top-P<=80)I=E;else break}$(I)};return v(),i.addEventListener("scroll",v,{passive:!0}),()=>i.removeEventListener("scroll",v)},[M]);const Q=i=>{var v;const o=document.getElementById(D(i));(v=o==null?void 0:o.scrollIntoView)==null||v.call(o,{behavior:"smooth",block:"start"}),$(i)},fe=async()=>{if(k.length===0||!t)return;const i={};for(const o of k)i[o]=d[o];p(!0),l(null);try{await O.updateInstanceConfig(i,t.configVersion);const o=await O.getInstanceConfig();n(o),x({}),N(!0)}catch(o){if(o instanceof Ce&&o.status===409)try{n(await O.getInstanceConfig())}catch{}l(o instanceof Error?o.message:String(o))}finally{p(!1)}},ge=()=>{x({}),l(null),N(!1)};return e.jsxs("div",{className:"flex min-h-0 flex-1",children:[t&&e.jsx(Be,{groups:M,active:y,onJump:Q,dirtyCount:Y}),e.jsxs("div",{className:"flex min-h-0 min-w-0 flex-1 flex-col",children:[t&&e.jsx("div",{className:"border-b border-edge px-4 py-2.5 sm:px-6",children:e.jsxs("div",{className:_,children:[e.jsx(He,{query:w,onQuery:F,modifiedOnly:m,onModifiedOnly:j,visibleCount:J,totalCount:U.length,filtering:xe,autoFocus:de}),e.jsx(Ue,{groups:M,active:y,onJump:Q,dirtyCount:Y})]})}),e.jsx("div",{ref:K,className:"min-h-0 flex-1 overflow-y-auto px-4 py-5 sm:px-6",children:e.jsxs("div",{className:_,children:[H&&e.jsx("div",{className:"mb-8 border-b border-edge pb-7",children:e.jsx(te,{id:D(V.id),title:V.label,description:V.description,variant:"rule",first:!0,children:e.jsx(Oe,{})})}),e.jsx(ze,{saved:f,configPath:t==null?void 0:t.configPath,restartRequired:(t==null?void 0:t.restartRequired)??!1,fileError:t==null?void 0:t.configFileError}),r&&e.jsx("p",{className:"text-sm text-fg-muted",children:"Loading…"}),a&&e.jsxs("p",{className:"text-sm text-danger",role:"alert",children:["Failed to load settings: ",a]}),t&&he&&e.jsx(_e,{}),t&&J===0&&e.jsxs("p",{className:"py-8 text-center text-sm text-fg-muted",children:["No settings match"," ",w.trim()?e.jsxs(e.Fragment,{children:["“",e.jsx("span",{className:"font-medium",children:w.trim()}),"”"]}):"this filter","."]}),C.map(i=>e.jsx(te,{id:D(i.id),title:i.label,description:i.description,variant:"card",flush:!0,children:e.jsx("div",{className:"divide-y divide-edge-subtle",children:i.fields.map(o=>e.jsx(Ge,{field:o,value:me(o),dirty:X.has(o.key),onChange:v=>ue(o.key,v)},o.key))})},i.id))]})}),t&&e.jsx("footer",{className:"border-t border-edge px-4 py-3 sm:px-6",children:e.jsxs("div",{className:`${_} flex items-center gap-3`,children:[g&&e.jsxs("span",{className:"flex min-w-0 items-center gap-1.5 text-sm text-danger",role:"alert",children:[e.jsx(oe,{width:14,height:14,className:"shrink-0"}),e.jsx("span",{className:"truncate",children:g})]}),e.jsx("span",{className:"ml-auto shrink-0 text-xs tabular text-fg-subtle",children:k.length>0?`${k.length} unsaved change${k.length===1?"":"s"}`:"No changes"}),e.jsx(A,{variant:"subtle",onClick:ge,disabled:k.length===0||h,children:"Reset"}),e.jsx(A,{variant:"primary",onClick:fe,disabled:k.length===0,loading:h,loadingLabel:"Saving…",children:"Save changes"})]})})]})]})}function Be({groups:t,active:n,onJump:r,dirtyCount:c}){return e.jsx("nav",{"aria-label":"Config sections",className:"hidden w-52 shrink-0 overflow-y-auto border-r border-edge px-2 py-4 lg:block",children:e.jsx("ul",{className:"space-y-0.5",children:t.map(a=>{const s=a.id===n,d=c[a.id]??0;return e.jsx("li",{children:e.jsxs("button",{type:"button",onClick:()=>r(a.id),"aria-current":s?"true":void 0,className:b("motion-fast flex w-full items-center gap-2 rounded-md px-2.5 py-1.5 text-left text-sm transition-colors",s?"bg-surface-selected font-medium text-fg":"text-fg-muted hover:bg-surface-hover hover:text-fg"),children:[e.jsx("span",{className:"min-w-0 flex-1 truncate",children:a.label}),d>0&&e.jsx("span",{className:"h-1.5 w-1.5 shrink-0 rounded-full bg-accent-solid","aria-label":`${d} unsaved`}),a.fields.length>0&&e.jsx("span",{className:"shrink-0 text-2xs tabular text-fg-subtle",children:a.fields.length})]})},a.id)})})})}function Ue({groups:t,active:n,onJump:r,dirtyCount:c}){return t.length===0?null:e.jsx("nav",{"aria-label":"Config sections",className:"-mx-1 mt-2 flex gap-1 overflow-x-auto px-1 pb-0.5 lg:hidden",children:t.map(a=>{const s=a.id===n,d=c[a.id]??0;return e.jsxs("button",{type:"button",onClick:()=>r(a.id),"aria-current":s?"true":void 0,className:b("motion-fast flex shrink-0 items-center gap-1.5 rounded-md px-2.5 py-1 text-xs transition-colors",s?"bg-surface-selected font-medium text-fg":"text-fg-muted hover:bg-surface-hover hover:text-fg"),children:[a.label,d>0&&e.jsx("span",{className:"h-1.5 w-1.5 rounded-full bg-accent-solid","aria-label":`${d} unsaved`})]},a.id)})})}function He({query:t,onQuery:n,modifiedOnly:r,onModifiedOnly:c,visibleCount:a,totalCount:s,filtering:d,autoFocus:x}){return e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsxs("div",{className:"relative min-w-0 flex-1 sm:max-w-sm",children:[e.jsx(we,{width:14,height:14,className:"pointer-events-none absolute left-2.5 top-1/2 -translate-y-1/2 text-fg-subtle"}),e.jsx(B,{type:"search","aria-label":"Search settings",placeholder:"Search settings, keys, env vars…",className:"h-8 py-0 pl-8 pr-7 [&::-webkit-search-cancel-button]:appearance-none",value:t,autoFocus:x,onChange:h=>n(h.target.value),onKeyDown:h=>{h.key==="Escape"&&t!==""&&(h.preventDefault(),n(""))}}),t!==""&&e.jsx("button",{type:"button","aria-label":"Clear search",onClick:()=>n(""),className:"absolute right-2 top-1/2 -translate-y-1/2 text-fg-subtle hover:text-fg",children:e.jsx(Ne,{width:13,height:13})})]}),e.jsx("button",{type:"button","aria-pressed":r,onClick:()=>c(!r),className:b("motion-fast shrink-0 rounded-md border px-2.5 py-1 text-xs transition-colors",r?"border-accent-edge bg-accent-soft text-accent":"border-edge text-fg-muted hover:text-fg"),children:"Modified only"}),e.jsx("span",{className:"shrink-0 text-xs tabular text-fg-subtle",children:d?`${a} of ${s}`:`${s} settings`})]})}function ze({saved:t,configPath:n,restartRequired:r,fileError:c}){const a=c?"danger":t?"success":"warn";return e.jsx(Re,{tone:a,className:"mb-5 leading-snug",icon:a==="success"?e.jsx(ke,{width:15,height:15}):e.jsx(oe,{width:15,height:15}),children:e.jsx("span",{role:"status",children:c?e.jsxs(e.Fragment,{children:[e.jsxs("strong",{children:["Could not read ",G(n),"."]})," ",c," — the values below are the running instance's; what a restart would load is unknown until the file parses."]}):t?e.jsxs(e.Fragment,{children:[e.jsx("strong",{children:"Saved to disk."})," These changes take effect only after the server restarts."]}):r?e.jsxs(e.Fragment,{children:[e.jsx("strong",{children:"Restart pending."})," ",e.jsx("code",{className:"font-mono text-xs",children:G(n)})," holds changes the running instance has not picked up — the fields below marked"," ",e.jsx(R,{tone:"warn",children:"restart"})," differ from what is in force right now."]}):e.jsxs(e.Fragment,{children:["Changes here are written to"," ",e.jsx("code",{className:"font-mono text-xs",children:G(n)})," and take effect only after the server restarts — the running instance keeps its current config until then."]})})})}function _e(){return e.jsxs("p",{className:"mb-5 text-xs leading-snug text-fg-muted",children:["Settings marked ",e.jsx(R,{tone:"neutral",children:"env"})," are overridden by an environment variable, which wins over this file — edit that variable (and restart) to change them."]})}function Ge({field:t,value:n,dirty:r,onChange:c}){const a=!t.editable||t.envOverridden,s=`cfg-${t.key}`,d=t.help?`${s}-help`:void 0,x=t.type==="boolean",h=u.useMemo(()=>Je(t,q(t)),[t]),p=x&&!a,g=!t.help&&!t.envOverridden&&!t.pendingRestart,l=g?"items-center":"items-start",f=g?"sm:items-center":"sm:items-start",N=a?e.jsx(Xe,{field:t,value:n}):x?e.jsx($e,{id:s,checked:!!n,onChange:c,label:t.label}):e.jsx(Ke,{field:t,value:n,onChange:c,inputId:s,describedBy:d});return e.jsxs("div",{className:"relative px-4 py-3",children:[r&&e.jsx("span",{"aria-hidden":!0,className:"absolute inset-y-2 left-0 w-0.5 rounded-full bg-accent-solid"}),e.jsxs("div",{className:b(h?"":p?`flex gap-4 ${l}`:`sm:flex sm:gap-6 ${f}`),children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-1.5",children:[e.jsx("label",{htmlFor:a?void 0:s,className:"text-sm font-medium text-fg",children:t.label}),t.sensitive&&e.jsx(R,{tone:"warn",children:"sensitive"}),t.envOverridden&&e.jsx(R,{tone:"neutral",title:`Overridden by environment variable ${t.envVar} — edit that env var (and restart) to change it.`,children:"env"}),!t.editable&&!t.envOverridden&&e.jsx(R,{tone:"neutral",children:"read-only"}),t.pendingRestart&&e.jsx(R,{tone:"warn",title:"The config file and the running instance disagree on this field — restart to apply.",children:"restart"})]}),t.help&&e.jsx("p",{id:d,className:"mt-0.5 text-xs leading-snug text-fg-muted",children:t.help}),t.envOverridden&&e.jsx("p",{className:"mt-1 truncate font-mono text-2xs text-fg-subtle",children:t.envVar}),t.pendingRestart&&e.jsxs("p",{className:"mt-1 text-2xs leading-snug text-warn",children:["In force now: ",e.jsx("span",{className:"font-mono",children:qe(t.value)})]})]}),e.jsx("div",{className:b(h?"mt-2":p?"flex shrink-0 justify-end":`mt-2 sm:mt-0 sm:shrink-0 ${De}`),children:N})]})]})}function qe(t){if(t==null||t==="")return"(not set)";const r=(Array.isArray(t)?t.join(", "):String(t)).replace(/\s+/g," ").trim();return r.length>60?`${r.slice(0,60)}…`:r}function R({children:t,tone:n,title:r}){return e.jsx(ce,{tone:n,size:"sm",title:r,className:"uppercase tracking-wide",children:t})}function Ke({field:t,value:n,onChange:r,inputId:c,describedBy:a}){if(t.type==="enum")return e.jsx(Me,{id:c,"aria-describedby":a,value:String(n??""),onChange:s=>r(s.target.value),children:(t.enumValues??[]).map(s=>e.jsx("option",{value:s,children:s},s))});if(t.type==="number")return e.jsx(B,{id:c,type:"number","aria-describedby":a,className:"tabular",value:n==null?"":String(n),placeholder:t.default===null?"default":String(t.default),onChange:s=>r(s.target.value===""?null:Number(s.target.value))});if(t.type==="text"){const s=n==null||n===t.default,d=n==null?String(t.default??""):String(n),x=typeof t.default=="string"&&!s;return e.jsxs("div",{children:[e.jsx(Pe,{id:c,"aria-describedby":a,className:"min-h-[7rem] font-mono text-xs leading-relaxed",rows:6,spellCheck:!1,value:d,onChange:h=>r(h.target.value)}),e.jsxs("div",{className:"mt-1 flex items-center justify-between gap-3 text-xs text-fg-muted",children:[e.jsx("span",{children:s?"Using the built-in default.":n===""?"Empty — nothing will be appended.":`${d.length.toLocaleString()} characters.`}),x&&e.jsx(A,{variant:"link",size:"sm",className:"shrink-0",onClick:()=>r(null),children:"Restore default"})]})]})}if(t.type==="string-list"){const s=Array.isArray(t.default)?t.default.map(String):null,d=Array.isArray(n)?n.map(String):null,x=d===null||s!==null&&d.length===s.length&&d.every((g,l)=>g===s[l]),h=d!==null?d.join(", "):(s==null?void 0:s.join(", "))??"",p=s!==null&&!x;return e.jsxs("div",{children:[e.jsx(B,{id:c,type:"text","aria-describedby":a,value:h,placeholder:(s==null?void 0:s.join(", "))??"",onChange:g=>r(g.target.value.split(",").map(l=>l.trim()).filter(Boolean))}),e.jsxs("div",{className:"mt-1 flex items-center justify-between gap-3 text-xs text-fg-muted",children:[e.jsx("span",{children:x?"Using the built-in default.":d!==null&&d.length===0?"Empty — none offered.":`${(d==null?void 0:d.length)??0} in the list.`}),p&&e.jsx(A,{variant:"link",size:"sm",className:"shrink-0",onClick:()=>r(null),children:"Restore default"})]})]})}return e.jsx(B,{id:c,type:"text","aria-describedby":a,value:n==null?"":String(n),placeholder:t.default===null?"":String(t.default),onChange:s=>r(s.target.value)})}function Xe({field:t,value:n}){const r="rounded-lg bg-surface-sunken px-3 py-2 font-mono text-xs text-fg-muted";return t.type==="boolean"?e.jsx("div",{className:r,children:n?"true":"false"}):n==null||n===""?e.jsx("div",{className:r,children:e.jsx("span",{className:"italic text-fg-subtle",children:t.type==="text"&&n===""?"(empty — nothing appended)":"(not set)"})}):t.type==="text"?e.jsx("div",{className:b(r,"max-h-40 overflow-y-auto whitespace-pre-wrap leading-relaxed"),children:String(n)}):e.jsx("div",{className:b(r,"break-all"),children:Array.isArray(n)?n.join(", "):String(n)})}function Je(t,n){return t.type==="text"||t.type==="string-list"?!0:(Array.isArray(n)?n.join(", "):n==null?"":String(n)).length>38}function Ye(t){return[t.label,t.key,t.help,t.envVar,...t.enumValues??[]].filter(Boolean).join(" ").toLowerCase()}function Qe(t,n){const r={};for(const c of t)r[c.id]=c.fields.filter(a=>n.has(a.key)).length;return r}const D=t=>`cfg-section-${t}`,V={id:"appearance",label:"Appearance",description:"Theme and accent colour for this browser. Applies immediately — no save, no restart.",fields:[]},We=["appearance theme themes colour color accent tint dark light font",...ae.map(t=>t.id)].join(" ");function q(t){return t.pendingValue===void 0?t.value:t.pendingValue}function se(t,n){return Object.prototype.hasOwnProperty.call(n,t.key)?n[t.key]:q(t)}function re(t,n){return Array.isArray(t)&&Array.isArray(n)?t.length===n.length&&t.every((r,c)=>r===n[c]):t===n}function G(t){if(!t)return"paddock.config.yaml";const n=t.split("/");return n[n.length-1]||t}function tt(){const t=Se(),n=(t==null?void 0:t.openNav)??(()=>{});return e.jsxs("div",{className:"flex h-full min-h-0 flex-col",children:[e.jsxs("header",{className:"pt-safe flex items-center gap-2 border-b border-edge px-3 pb-2.5 sm:px-6 lg:py-4",children:[e.jsx("button",{type:"button",onClick:n,"aria-label":"Open menu",className:"btn-subtle -ml-1 shrink-0 px-2 py-1.5 lg:hidden",children:e.jsx(Ae,{width:20,height:20})}),e.jsx(Ee,{width:18,height:18,className:"shrink-0 text-fg-subtle"}),e.jsx("h1",{className:"text-md font-semibold tracking-tight",children:"Config"})]}),e.jsx(Ve,{})]})}export{tt as InstanceConfigPage};
1
+ import{r as u,m as W,s as Z,A as ee,n as pe,j as e,p as ae,q as b,t as ie,v as be,w as je,x as le,y as ve,z as ye,b as O,D as oe,E as we,X as Ne,F as ke,G as Ce,H as Se,M as Ae,I as Ee}from"./index-Cx9y6c3f.js";import{B as A,C as ce,S as L,a as te,I as B,b as Re,T as $e,c as Me,d as Pe}from"./Chip-Cp32dDmz.js";const Ie=Array.from({length:72},(t,n)=>n*5),S=[...ie].sort((t,n)=>t.hue-n.hue),z=(t,n)=>Math.min(Math.abs(t-n),360-Math.abs(t-n));function ne(t){const n=S.reduce((a,s)=>z(s.hue,t)<z(a.hue,t)?s:a);if(z(n.hue,t)<=8)return n.name;const r=S.find(a=>a.hue>t)??S[0];return`between ${S[(S.indexOf(r)-1+S.length)%S.length].name} and ${r.name}`}function Fe({theme:t,dark:n,hue:r,className:c}){const a=u.useRef(null);return u.useLayoutEffect(()=>{const s=a.current;s&&(r===null?je(s):le(r,s))},[t,n,r]),e.jsx("div",{ref:a,"data-theme":t,className:b("overflow-hidden rounded-lg border border-edge",n&&"dark",c),children:e.jsxs("div",{className:"flex h-full items-center gap-2 bg-surface p-2",children:[e.jsxs("div",{className:"flex-1 rounded-md border border-edge-subtle bg-surface-raised p-1.5",children:[e.jsx("div",{className:"h-1 w-4/5 rounded-full bg-fg"}),e.jsx("div",{className:"mt-1 h-1 w-3/5 rounded-full bg-fg-subtle"})]}),e.jsx("div",{className:"grid h-6 w-6 shrink-0 place-items-center rounded-md bg-accent-solid",children:e.jsx("div",{className:"h-1 w-3 rounded-full bg-accent-fg"})})]})})}function Te({hexes:t,hue:n,active:r,onCommit:c}){const a=u.useRef(null),s=u.useRef(null),d=u.useRef(null),x=u.useRef(0),h=u.useRef(null),p=u.useRef(!1),g=u.useRef(null),l=u.useMemo(()=>{if(t.length===0)return;const m=t.map((j,y)=>`${j} ${(y/t.length*100).toFixed(2)}%`);return m.push(`${t[0]} 100%`),`linear-gradient(to right, ${m.join(", ")})`},[t]),f=u.useCallback(m=>{s.current&&(s.current.style.left=`${m/360*100}%`),d.current&&(d.current.textContent=ne(m))},[]);u.useEffect(()=>{p.current||f(n)},[n,f]);const N=m=>{var $;const j=($=a.current)==null?void 0:$.getBoundingClientRect();if(!j||j.width===0)return 0;const y=Math.min(1,Math.max(0,(m-j.left)/j.width));return Math.round(y*360)%360},w=u.useCallback(m=>{h.current=m,!x.current&&(x.current=requestAnimationFrame(()=>{x.current=0;const j=h.current;h.current=null,j!==null&&(f(j),le(j,document.documentElement,{context:g.current??void 0,live:!0}))}))},[f]);u.useEffect(()=>()=>cancelAnimationFrame(x.current),[]);const F=m=>{p.current=!1,g.current=null,cancelAnimationFrame(x.current),x.current=0,h.current=null,c(m)};return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"mt-2 flex items-baseline justify-between gap-2",children:[e.jsx("span",{className:"text-3xs text-fg-subtle",children:"Drag along the strip"}),e.jsx("span",{ref:d,className:"text-3xs font-medium text-fg-muted","aria-hidden":!0})]}),e.jsx("div",{ref:a,role:"slider",tabIndex:0,"aria-label":"Accent colour","aria-valuemin":0,"aria-valuemax":359,"aria-valuenow":n,"aria-valuetext":r?ne(n):"the theme’s own colour",onPointerDown:m=>{m.currentTarget.setPointerCapture(m.pointerId),p.current=!0,g.current=ve(),w(N(m.clientX))},onPointerMove:m=>{p.current&&w(N(m.clientX))},onPointerUp:m=>{p.current&&F(N(m.clientX))},onPointerCancel:()=>{p.current&&F(n)},onKeyDown:m=>{const j=m.key==="PageUp"||m.key==="PageDown"?15:m.shiftKey?10:2;let y=null;m.key==="ArrowLeft"||m.key==="ArrowDown"||m.key==="PageDown"?y=(n-j+360)%360:m.key==="ArrowRight"||m.key==="ArrowUp"||m.key==="PageUp"?y=(n+j)%360:m.key==="Home"?y=0:m.key==="End"&&(y=359),y!==null&&(m.preventDefault(),c(y))},style:{backgroundImage:l,touchAction:"none"},className:b("relative mt-1 h-8 cursor-pointer rounded-lg border border-edge shadow-xs select-none","focus-visible:focus-ring"),children:e.jsx("div",{ref:s,"aria-hidden":!0,style:{left:`${n/360*100}%`},className:b("pointer-events-none absolute top-1/2 h-[calc(100%+6px)] w-1.5 -translate-x-1/2 -translate-y-1/2 rounded-full","border border-fg bg-surface-raised shadow-sm",!r&&"opacity-0")})})]})}function Oe({className:t}){const[n,r]=u.useState(W),[c,a]=u.useState(null),s=typeof document<"u"&&document.documentElement.classList.contains("dark"),d=u.useRef(n),x=u.useCallback(l=>{const f={...d.current,...l};d.current=f,r(f),a(Z(f))},[]);u.useEffect(()=>{const l=f=>a(f.detail);return window.addEventListener(ee,l),a(Z(W())),()=>window.removeEventListener(ee,l)},[]);const h=u.useMemo(()=>pe(Ie),[n.theme,s,c==null?void 0:c.mode]),p=(c==null?void 0:c.hue)??0,g=n.hue!==null;return e.jsxs("div",{className:b("space-y-5",t),children:[e.jsxs("fieldset",{children:[e.jsx("legend",{className:"text-2xs font-semibold uppercase tracking-wide text-fg-muted",children:"Theme"}),e.jsx("div",{className:b("mt-2 grid gap-2","grid-cols-2 sm:grid-cols-4"),children:ae.map(l=>{const f=n.theme===l.id;return e.jsxs("button",{type:"button","aria-pressed":f,title:`${l.label} — ${l.blurb}`,onClick:()=>x({theme:l.id}),className:b("motion-fast rounded-xl border text-left transition-[border-color,box-shadow]","focus-visible:focus-ring","p-1.5",f?"border-accent-edge bg-accent-soft shadow-xs":"border-edge bg-surface-raised hover:border-edge-strong"),children:[e.jsx(Fe,{theme:l.id,dark:s,hue:n.hue,className:"h-10"}),e.jsxs("div",{className:"mt-1.5 min-w-0 px-0.5 pb-0.5",children:[e.jsx("span",{className:"block truncate text-xs font-semibold text-fg",children:l.label}),e.jsx("span",{className:"mt-0.5 line-clamp-2 text-3xs leading-snug text-fg-muted",children:l.blurb})]})]},l.id)})})]}),e.jsxs("div",{className:b("grid gap-5 lg:grid-cols-[minmax(0,1fr)_15rem] lg:items-start"),children:[e.jsxs("fieldset",{children:[e.jsx("legend",{className:"text-2xs font-semibold uppercase tracking-wide text-fg-muted",children:"Accent colour"}),e.jsx("p",{className:"mt-1 text-3xs leading-snug text-fg-subtle",children:"Pick any colour. The theme adjusts it so buttons and labels stay readable in both light and dark."}),e.jsx(Te,{hexes:h,hue:p,active:g,onCommit:l=>x({hue:l})}),e.jsxs("div",{className:"mt-2 flex flex-wrap gap-1",children:[e.jsx("button",{type:"button",onClick:()=>x({hue:null}),"aria-pressed":!g,className:b("motion-fast rounded-md border px-2 py-1 text-3xs transition-colors","focus-visible:focus-ring",g?"border-edge text-fg-muted hover:border-edge-strong hover:text-fg":"border-accent-edge bg-accent-soft text-accent"),children:"Theme’s own"}),ie.map(l=>{const f=g&&Math.abs(p-l.hue)<2.5;return e.jsxs("button",{type:"button","aria-pressed":f,onClick:()=>x({hue:l.hue}),className:b("motion-fast inline-flex items-center gap-1.5 rounded-md border px-2 py-1 text-3xs transition-colors","focus-visible:focus-ring",f?"border-edge-strong bg-surface-active text-fg":"border-edge text-fg-muted hover:border-edge-strong hover:text-fg"),children:[e.jsx("span",{"aria-hidden":!0,className:"h-2.5 w-2.5 rounded-full",style:{backgroundColor:h[Math.round(l.hue/5)%h.length]}}),l.name]},l.name)})]})]}),e.jsxs("fieldset",{children:[e.jsx("legend",{className:"text-2xs font-semibold uppercase tracking-wide text-fg-muted",children:"Tint the background"}),e.jsx("p",{className:"mt-1 text-3xs leading-snug text-fg-subtle",children:"Colours the whole page a little, not just the buttons. Useful for telling two Paddock instances apart at a glance."}),e.jsx("div",{className:"mt-2 inline-flex rounded-lg border border-edge p-0.5",children:be.map(l=>e.jsx("button",{type:"button","aria-pressed":n.tint===l.level,onClick:()=>x({tint:l.level}),className:b("motion-fast rounded-md px-2.5 py-1 text-3xs transition-colors","focus-visible:focus-ring",n.tint===l.level?"bg-surface-active font-medium text-fg":"text-fg-muted hover:text-fg"),children:l.label},l.level))})]})]}),e.jsx(Le,{})]})}function Le(){return e.jsxs("div",{children:[e.jsx("p",{className:"text-2xs font-semibold uppercase tracking-wide text-fg-muted",children:"Preview"}),e.jsxs("div",{className:"mt-2 flex flex-wrap items-center gap-2 rounded-xl border border-edge bg-surface p-3",children:[e.jsx(A,{variant:"primary",size:"sm",children:"Send"}),e.jsx(A,{variant:"ghost",size:"sm",children:"Cancel"}),e.jsx(A,{variant:"link",size:"sm",children:"A link"}),e.jsx("span",{className:"inline-flex items-center gap-1 rounded-md border border-accent-edge bg-accent-soft px-1.5 py-0.5 text-2xs font-medium text-accent",children:"accent chip"}),e.jsx(ce,{tone:"accent",shape:"pill",dot:!0,children:"running"}),e.jsxs("span",{className:"inline-flex items-center gap-1.5 text-2xs text-fg-subtle",children:[e.jsx("span",{className:"h-4 w-4 rounded-md border border-edge bg-accent-solid-hover","aria-hidden":!0}),"hovered"]}),e.jsxs("span",{className:"ml-auto inline-flex items-center gap-1.5",children:[e.jsx(L,{tone:"success"}),e.jsx(L,{tone:"warn"}),e.jsx(L,{tone:"danger"}),e.jsx(L,{tone:"info"}),e.jsx("span",{className:"text-2xs text-fg-subtle",children:"status hues (theme’s, not yours)"})]})]})]})}const _="mx-auto w-full max-w-4xl",De="sm:w-64";function Ve(){const[t,n]=u.useState(null),[r,c]=u.useState(!0),[a,s]=u.useState(null),[d,x]=u.useState({}),[h,p]=u.useState(!1),[g,l]=u.useState(null),[f,N]=u.useState(!1),[w,F]=u.useState(""),[m,j]=u.useState(!1),[y,$]=u.useState(null),K=u.useRef(null),de=ye("(min-width: 1024px)");u.useEffect(()=>{let i=!0;return c(!0),O.getInstanceConfig().then(o=>{i&&(n(o),s(null))}).catch(o=>i&&s(o instanceof Error?o.message:String(o))).finally(()=>i&&c(!1)),()=>{i=!1}},[]);const ue=(i,o)=>{N(!1),l(null),x(v=>({...v,[i]:o}))},me=i=>se(i,d),U=u.useMemo(()=>t?t.groups.flatMap(i=>i.fields):[],[t]),k=u.useMemo(()=>U.filter(i=>i.editable&&!i.envOverridden).filter(i=>Object.prototype.hasOwnProperty.call(d,i.key)).filter(i=>!re(d[i.key],q(i))).map(i=>i.key),[U,d]),X=u.useMemo(()=>new Set(k),[k]),C=u.useMemo(()=>{if(!t)return[];const i=w.trim().toLowerCase(),o=[];for(const v of t.groups){const P=i!==""&&v.label.toLowerCase().includes(i),I=v.fields.filter(E=>{const T=se(E,d);return m&&re(T,E.default)?!1:i===""||P?!0:Ye(E).includes(i)});I.length>0&&o.push({...v,fields:I})}return o},[t,w,m,d]),J=C.reduce((i,o)=>i+o.fields.length,0),xe=w.trim()!==""||m,H=!m&&(w.trim()===""||We.includes(w.trim().toLowerCase())),M=u.useMemo(()=>H?[V,...C]:C,[H,C]),he=C.some(i=>i.fields.some(o=>o.envOverridden)),Y=Qe(C,X);u.useEffect(()=>{const i=K.current;if(!i||M.length===0)return;const o=M.map(P=>P.id),v=()=>{const P=i.getBoundingClientRect().top;let I=o[0];for(const E of o){const T=document.getElementById(D(E));if(T)if(T.getBoundingClientRect().top-P<=80)I=E;else break}$(I)};return v(),i.addEventListener("scroll",v,{passive:!0}),()=>i.removeEventListener("scroll",v)},[M]);const Q=i=>{var v;const o=document.getElementById(D(i));(v=o==null?void 0:o.scrollIntoView)==null||v.call(o,{behavior:"smooth",block:"start"}),$(i)},fe=async()=>{if(k.length===0||!t)return;const i={};for(const o of k)i[o]=d[o];p(!0),l(null);try{await O.updateInstanceConfig(i,t.configVersion);const o=await O.getInstanceConfig();n(o),x({}),N(!0)}catch(o){if(o instanceof Ce&&o.status===409)try{n(await O.getInstanceConfig())}catch{}l(o instanceof Error?o.message:String(o))}finally{p(!1)}},ge=()=>{x({}),l(null),N(!1)};return e.jsxs("div",{className:"flex min-h-0 flex-1",children:[t&&e.jsx(Be,{groups:M,active:y,onJump:Q,dirtyCount:Y}),e.jsxs("div",{className:"flex min-h-0 min-w-0 flex-1 flex-col",children:[t&&e.jsx("div",{className:"border-b border-edge px-4 py-2.5 sm:px-6",children:e.jsxs("div",{className:_,children:[e.jsx(He,{query:w,onQuery:F,modifiedOnly:m,onModifiedOnly:j,visibleCount:J,totalCount:U.length,filtering:xe,autoFocus:de}),e.jsx(Ue,{groups:M,active:y,onJump:Q,dirtyCount:Y})]})}),e.jsx("div",{ref:K,className:"min-h-0 flex-1 overflow-y-auto px-4 py-5 sm:px-6",children:e.jsxs("div",{className:_,children:[H&&e.jsx("div",{className:"mb-8 border-b border-edge pb-7",children:e.jsx(te,{id:D(V.id),title:V.label,description:V.description,variant:"rule",first:!0,children:e.jsx(Oe,{})})}),e.jsx(ze,{saved:f,configPath:t==null?void 0:t.configPath,restartRequired:(t==null?void 0:t.restartRequired)??!1,fileError:t==null?void 0:t.configFileError}),r&&e.jsx("p",{className:"text-sm text-fg-muted",children:"Loading…"}),a&&e.jsxs("p",{className:"text-sm text-danger",role:"alert",children:["Failed to load settings: ",a]}),t&&he&&e.jsx(_e,{}),t&&J===0&&e.jsxs("p",{className:"py-8 text-center text-sm text-fg-muted",children:["No settings match"," ",w.trim()?e.jsxs(e.Fragment,{children:["“",e.jsx("span",{className:"font-medium",children:w.trim()}),"”"]}):"this filter","."]}),C.map(i=>e.jsx(te,{id:D(i.id),title:i.label,description:i.description,variant:"card",flush:!0,children:e.jsx("div",{className:"divide-y divide-edge-subtle",children:i.fields.map(o=>e.jsx(Ge,{field:o,value:me(o),dirty:X.has(o.key),onChange:v=>ue(o.key,v)},o.key))})},i.id))]})}),t&&e.jsx("footer",{className:"border-t border-edge px-4 py-3 sm:px-6",children:e.jsxs("div",{className:`${_} flex items-center gap-3`,children:[g&&e.jsxs("span",{className:"flex min-w-0 items-center gap-1.5 text-sm text-danger",role:"alert",children:[e.jsx(oe,{width:14,height:14,className:"shrink-0"}),e.jsx("span",{className:"truncate",children:g})]}),e.jsx("span",{className:"ml-auto shrink-0 text-xs tabular text-fg-subtle",children:k.length>0?`${k.length} unsaved change${k.length===1?"":"s"}`:"No changes"}),e.jsx(A,{variant:"subtle",onClick:ge,disabled:k.length===0||h,children:"Reset"}),e.jsx(A,{variant:"primary",onClick:fe,disabled:k.length===0,loading:h,loadingLabel:"Saving…",children:"Save changes"})]})})]})]})}function Be({groups:t,active:n,onJump:r,dirtyCount:c}){return e.jsx("nav",{"aria-label":"Config sections",className:"hidden w-52 shrink-0 overflow-y-auto border-r border-edge px-2 py-4 lg:block",children:e.jsx("ul",{className:"space-y-0.5",children:t.map(a=>{const s=a.id===n,d=c[a.id]??0;return e.jsx("li",{children:e.jsxs("button",{type:"button",onClick:()=>r(a.id),"aria-current":s?"true":void 0,className:b("motion-fast flex w-full items-center gap-2 rounded-md px-2.5 py-1.5 text-left text-sm transition-colors",s?"bg-surface-selected font-medium text-fg":"text-fg-muted hover:bg-surface-hover hover:text-fg"),children:[e.jsx("span",{className:"min-w-0 flex-1 truncate",children:a.label}),d>0&&e.jsx("span",{className:"h-1.5 w-1.5 shrink-0 rounded-full bg-accent-solid","aria-label":`${d} unsaved`}),a.fields.length>0&&e.jsx("span",{className:"shrink-0 text-2xs tabular text-fg-subtle",children:a.fields.length})]})},a.id)})})})}function Ue({groups:t,active:n,onJump:r,dirtyCount:c}){return t.length===0?null:e.jsx("nav",{"aria-label":"Config sections",className:"-mx-1 mt-2 flex gap-1 overflow-x-auto px-1 pb-0.5 lg:hidden",children:t.map(a=>{const s=a.id===n,d=c[a.id]??0;return e.jsxs("button",{type:"button",onClick:()=>r(a.id),"aria-current":s?"true":void 0,className:b("motion-fast flex shrink-0 items-center gap-1.5 rounded-md px-2.5 py-1 text-xs transition-colors",s?"bg-surface-selected font-medium text-fg":"text-fg-muted hover:bg-surface-hover hover:text-fg"),children:[a.label,d>0&&e.jsx("span",{className:"h-1.5 w-1.5 rounded-full bg-accent-solid","aria-label":`${d} unsaved`})]},a.id)})})}function He({query:t,onQuery:n,modifiedOnly:r,onModifiedOnly:c,visibleCount:a,totalCount:s,filtering:d,autoFocus:x}){return e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsxs("div",{className:"relative min-w-0 flex-1 sm:max-w-sm",children:[e.jsx(we,{width:14,height:14,className:"pointer-events-none absolute left-2.5 top-1/2 -translate-y-1/2 text-fg-subtle"}),e.jsx(B,{type:"search","aria-label":"Search settings",placeholder:"Search settings, keys, env vars…",className:"h-8 py-0 pl-8 pr-7 [&::-webkit-search-cancel-button]:appearance-none",value:t,autoFocus:x,onChange:h=>n(h.target.value),onKeyDown:h=>{h.key==="Escape"&&t!==""&&(h.preventDefault(),n(""))}}),t!==""&&e.jsx("button",{type:"button","aria-label":"Clear search",onClick:()=>n(""),className:"absolute right-2 top-1/2 -translate-y-1/2 text-fg-subtle hover:text-fg",children:e.jsx(Ne,{width:13,height:13})})]}),e.jsx("button",{type:"button","aria-pressed":r,onClick:()=>c(!r),className:b("motion-fast shrink-0 rounded-md border px-2.5 py-1 text-xs transition-colors",r?"border-accent-edge bg-accent-soft text-accent":"border-edge text-fg-muted hover:text-fg"),children:"Modified only"}),e.jsx("span",{className:"shrink-0 text-xs tabular text-fg-subtle",children:d?`${a} of ${s}`:`${s} settings`})]})}function ze({saved:t,configPath:n,restartRequired:r,fileError:c}){const a=c?"danger":t?"success":"warn";return e.jsx(Re,{tone:a,className:"mb-5 leading-snug",icon:a==="success"?e.jsx(ke,{width:15,height:15}):e.jsx(oe,{width:15,height:15}),children:e.jsx("span",{role:"status",children:c?e.jsxs(e.Fragment,{children:[e.jsxs("strong",{children:["Could not read ",G(n),"."]})," ",c," — the values below are the running instance's; what a restart would load is unknown until the file parses."]}):t?e.jsxs(e.Fragment,{children:[e.jsx("strong",{children:"Saved to disk."})," These changes take effect only after the server restarts."]}):r?e.jsxs(e.Fragment,{children:[e.jsx("strong",{children:"Restart pending."})," ",e.jsx("code",{className:"font-mono text-xs",children:G(n)})," holds changes the running instance has not picked up — the fields below marked"," ",e.jsx(R,{tone:"warn",children:"restart"})," differ from what is in force right now."]}):e.jsxs(e.Fragment,{children:["Changes here are written to"," ",e.jsx("code",{className:"font-mono text-xs",children:G(n)})," and take effect only after the server restarts — the running instance keeps its current config until then."]})})})}function _e(){return e.jsxs("p",{className:"mb-5 text-xs leading-snug text-fg-muted",children:["Settings marked ",e.jsx(R,{tone:"neutral",children:"env"})," are overridden by an environment variable, which wins over this file — edit that variable (and restart) to change them."]})}function Ge({field:t,value:n,dirty:r,onChange:c}){const a=!t.editable||t.envOverridden,s=`cfg-${t.key}`,d=t.help?`${s}-help`:void 0,x=t.type==="boolean",h=u.useMemo(()=>Je(t,q(t)),[t]),p=x&&!a,g=!t.help&&!t.envOverridden&&!t.pendingRestart,l=g?"items-center":"items-start",f=g?"sm:items-center":"sm:items-start",N=a?e.jsx(Xe,{field:t,value:n}):x?e.jsx($e,{id:s,checked:!!n,onChange:c,label:t.label}):e.jsx(Ke,{field:t,value:n,onChange:c,inputId:s,describedBy:d});return e.jsxs("div",{className:"relative px-4 py-3",children:[r&&e.jsx("span",{"aria-hidden":!0,className:"absolute inset-y-2 left-0 w-0.5 rounded-full bg-accent-solid"}),e.jsxs("div",{className:b(h?"":p?`flex gap-4 ${l}`:`sm:flex sm:gap-6 ${f}`),children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-1.5",children:[e.jsx("label",{htmlFor:a?void 0:s,className:"text-sm font-medium text-fg",children:t.label}),t.sensitive&&e.jsx(R,{tone:"warn",children:"sensitive"}),t.envOverridden&&e.jsx(R,{tone:"neutral",title:`Overridden by environment variable ${t.envVar} — edit that env var (and restart) to change it.`,children:"env"}),!t.editable&&!t.envOverridden&&e.jsx(R,{tone:"neutral",children:"read-only"}),t.pendingRestart&&e.jsx(R,{tone:"warn",title:"The config file and the running instance disagree on this field — restart to apply.",children:"restart"})]}),t.help&&e.jsx("p",{id:d,className:"mt-0.5 text-xs leading-snug text-fg-muted",children:t.help}),t.envOverridden&&e.jsx("p",{className:"mt-1 truncate font-mono text-2xs text-fg-subtle",children:t.envVar}),t.pendingRestart&&e.jsxs("p",{className:"mt-1 text-2xs leading-snug text-warn",children:["In force now: ",e.jsx("span",{className:"font-mono",children:qe(t.value)})]})]}),e.jsx("div",{className:b(h?"mt-2":p?"flex shrink-0 justify-end":`mt-2 sm:mt-0 sm:shrink-0 ${De}`),children:N})]})]})}function qe(t){if(t==null||t==="")return"(not set)";const r=(Array.isArray(t)?t.join(", "):String(t)).replace(/\s+/g," ").trim();return r.length>60?`${r.slice(0,60)}…`:r}function R({children:t,tone:n,title:r}){return e.jsx(ce,{tone:n,size:"sm",title:r,className:"uppercase tracking-wide",children:t})}function Ke({field:t,value:n,onChange:r,inputId:c,describedBy:a}){if(t.type==="enum")return e.jsx(Me,{id:c,"aria-describedby":a,value:String(n??""),onChange:s=>r(s.target.value),children:(t.enumValues??[]).map(s=>e.jsx("option",{value:s,children:s},s))});if(t.type==="number")return e.jsx(B,{id:c,type:"number","aria-describedby":a,className:"tabular",value:n==null?"":String(n),placeholder:t.default===null?"default":String(t.default),onChange:s=>r(s.target.value===""?null:Number(s.target.value))});if(t.type==="text"){const s=n==null||n===t.default,d=n==null?String(t.default??""):String(n),x=typeof t.default=="string"&&!s;return e.jsxs("div",{children:[e.jsx(Pe,{id:c,"aria-describedby":a,className:"min-h-[7rem] font-mono text-xs leading-relaxed",rows:6,spellCheck:!1,value:d,onChange:h=>r(h.target.value)}),e.jsxs("div",{className:"mt-1 flex items-center justify-between gap-3 text-xs text-fg-muted",children:[e.jsx("span",{children:s?"Using the built-in default.":n===""?"Empty — nothing will be appended.":`${d.length.toLocaleString()} characters.`}),x&&e.jsx(A,{variant:"link",size:"sm",className:"shrink-0",onClick:()=>r(null),children:"Restore default"})]})]})}if(t.type==="string-list"){const s=Array.isArray(t.default)?t.default.map(String):null,d=Array.isArray(n)?n.map(String):null,x=d===null||s!==null&&d.length===s.length&&d.every((g,l)=>g===s[l]),h=d!==null?d.join(", "):(s==null?void 0:s.join(", "))??"",p=s!==null&&!x;return e.jsxs("div",{children:[e.jsx(B,{id:c,type:"text","aria-describedby":a,value:h,placeholder:(s==null?void 0:s.join(", "))??"",onChange:g=>r(g.target.value.split(",").map(l=>l.trim()).filter(Boolean))}),e.jsxs("div",{className:"mt-1 flex items-center justify-between gap-3 text-xs text-fg-muted",children:[e.jsx("span",{children:x?"Using the built-in default.":d!==null&&d.length===0?"Empty — none offered.":`${(d==null?void 0:d.length)??0} in the list.`}),p&&e.jsx(A,{variant:"link",size:"sm",className:"shrink-0",onClick:()=>r(null),children:"Restore default"})]})]})}return e.jsx(B,{id:c,type:"text","aria-describedby":a,value:n==null?"":String(n),placeholder:t.default===null?"":String(t.default),onChange:s=>r(s.target.value)})}function Xe({field:t,value:n}){const r="rounded-lg bg-surface-sunken px-3 py-2 font-mono text-xs text-fg-muted";return t.type==="boolean"?e.jsx("div",{className:r,children:n?"true":"false"}):n==null||n===""?e.jsx("div",{className:r,children:e.jsx("span",{className:"italic text-fg-subtle",children:t.type==="text"&&n===""?"(empty — nothing appended)":"(not set)"})}):t.type==="text"?e.jsx("div",{className:b(r,"max-h-40 overflow-y-auto whitespace-pre-wrap leading-relaxed"),children:String(n)}):e.jsx("div",{className:b(r,"break-all"),children:Array.isArray(n)?n.join(", "):String(n)})}function Je(t,n){return t.type==="text"||t.type==="string-list"?!0:(Array.isArray(n)?n.join(", "):n==null?"":String(n)).length>38}function Ye(t){return[t.label,t.key,t.help,t.envVar,...t.enumValues??[]].filter(Boolean).join(" ").toLowerCase()}function Qe(t,n){const r={};for(const c of t)r[c.id]=c.fields.filter(a=>n.has(a.key)).length;return r}const D=t=>`cfg-section-${t}`,V={id:"appearance",label:"Appearance",description:"Theme and accent colour for this browser. Applies immediately — no save, no restart.",fields:[]},We=["appearance theme themes colour color accent tint dark light font",...ae.map(t=>t.id)].join(" ");function q(t){return t.pendingValue===void 0?t.value:t.pendingValue}function se(t,n){return Object.prototype.hasOwnProperty.call(n,t.key)?n[t.key]:q(t)}function re(t,n){return Array.isArray(t)&&Array.isArray(n)?t.length===n.length&&t.every((r,c)=>r===n[c]):t===n}function G(t){if(!t)return"paddock.config.yaml";const n=t.split("/");return n[n.length-1]||t}function tt(){const t=Se(),n=(t==null?void 0:t.openNav)??(()=>{});return e.jsxs("div",{className:"flex h-full min-h-0 flex-col",children:[e.jsxs("header",{className:"pt-safe flex items-center gap-2 border-b border-edge px-3 pb-2.5 sm:px-6 lg:py-4",children:[e.jsx("button",{type:"button",onClick:n,"aria-label":"Open menu",className:"btn-subtle -ml-1 shrink-0 px-2 py-1.5 lg:hidden",children:e.jsx(Ae,{width:20,height:20})}),e.jsx(Ee,{width:18,height:18,className:"shrink-0 text-fg-subtle"}),e.jsx("h1",{className:"text-md font-semibold tracking-tight",children:"Config"})]}),e.jsx(Ve,{})]})}export{tt as InstanceConfigPage};
2
2