@marktiderman/genesis-config 0.0.0-stage → 0.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +461 -2
  3. package/dist/blocks.d.ts +473 -0
  4. package/dist/blocks.js +5 -0
  5. package/dist/blocks.js.map +1 -0
  6. package/dist/chunk-B6WRD3WF.js +6 -0
  7. package/dist/chunk-B6WRD3WF.js.map +1 -0
  8. package/dist/chunk-HIOKZIZP.js +218 -0
  9. package/dist/chunk-HIOKZIZP.js.map +1 -0
  10. package/dist/chunk-M7IY6LUN.js +123 -0
  11. package/dist/chunk-M7IY6LUN.js.map +1 -0
  12. package/dist/chunk-OW46SL2G.js +10 -0
  13. package/dist/chunk-OW46SL2G.js.map +1 -0
  14. package/dist/chunk-SEFG2QV6.js +413 -0
  15. package/dist/chunk-SEFG2QV6.js.map +1 -0
  16. package/dist/chunk-UD7SPYZH.js +354 -0
  17. package/dist/chunk-UD7SPYZH.js.map +1 -0
  18. package/dist/chunk-VYUX7VAX.js +52 -0
  19. package/dist/chunk-VYUX7VAX.js.map +1 -0
  20. package/dist/chunk-Y7NUBTWA.js +494 -0
  21. package/dist/chunk-Y7NUBTWA.js.map +1 -0
  22. package/dist/gate-CNTkn-Fv.d.ts +202 -0
  23. package/dist/gate-react.d.ts +48 -0
  24. package/dist/gate-react.js +37 -0
  25. package/dist/gate-react.js.map +1 -0
  26. package/dist/gate.d.ts +18 -0
  27. package/dist/gate.js +5 -0
  28. package/dist/gate.js.map +1 -0
  29. package/dist/index.d.ts +128 -0
  30. package/dist/index.js +9 -0
  31. package/dist/index.js.map +1 -0
  32. package/dist/model-uON71G4u.d.ts +437 -0
  33. package/dist/node.d.ts +159 -0
  34. package/dist/node.js +486 -0
  35. package/dist/node.js.map +1 -0
  36. package/dist/packages-CWhdXtzS.d.ts +203 -0
  37. package/dist/platforms-NR0liM8L.d.ts +10 -0
  38. package/dist/react.d.ts +60 -0
  39. package/dist/react.js +236 -0
  40. package/dist/react.js.map +1 -0
  41. package/dist/settings-protocol.d.ts +515 -0
  42. package/dist/settings-protocol.js +4 -0
  43. package/dist/settings-protocol.js.map +1 -0
  44. package/dist/settings-react.d.ts +143 -0
  45. package/dist/settings-react.js +943 -0
  46. package/dist/settings-react.js.map +1 -0
  47. package/dist/settings.d.ts +373 -0
  48. package/dist/settings.js +3 -0
  49. package/dist/settings.js.map +1 -0
  50. package/dist/types-D4hs16bJ.d.ts +39 -0
  51. package/package.json +141 -4
@@ -0,0 +1,943 @@
1
+ "use client";
2
+ import { intersectCapabilities, settingWritability, preferredWriteLayer, settingFileSnippet, safeHref, canSetSecret, secretNames, auditValuesVisible, SettingsProtocolError } from './chunk-HIOKZIZP.js';
3
+ import { SETTINGS_LAYERS, settingValueProblem } from './chunk-UD7SPYZH.js';
4
+ import { useMemo, useState, useCallback, useEffect, useId, useRef } from 'react';
5
+ import { Lock } from 'lucide-react';
6
+ import { Button, InlineAlert, PageLoading, Tabs, TabsList, TabsTrigger, Badge, TabsContent, Label, Input, EmptyState, Section, SettingsRow, Sheet, SheetContent, SheetHeader, SheetTitle, SheetDescription, RadioGroup, RadioGroupItem, Checkbox, SheetFooter, Collapsible, CollapsibleTrigger, CollapsibleContent, AlertDialog, AlertDialogContent, AlertDialogHeader, AlertDialogTitle, AlertDialogDescription, AlertDialogFooter, AlertDialogCancel, AlertDialogAction, Switch, Select, SelectTrigger, SelectValue, SelectContent, SelectItem, Textarea } from '@marktiderman/genesis-ui';
7
+ import { PageHeader } from '@marktiderman/genesis-ui/layout';
8
+ import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
9
+
10
+ var GENESIS_SETTINGS_COPY = {
11
+ title: "Genesis settings",
12
+ description: "Every setting, where its value comes from, and what needs attention.",
13
+ refresh: "Refresh",
14
+ loading: "Loading settings\u2026",
15
+ loadFailed: "The settings couldn't be loaded.",
16
+ retry: "Try again",
17
+ tabs: { values: "Values", health: "Health", secrets: "Secrets", upgrades: "Upgrades", audit: "Audit" },
18
+ layers: { default: "Default", preset: "Preset", file: "File", database: "Database", tenant: "Tenant", person: "Person" },
19
+ filterLabel: "Filter settings",
20
+ filterPlaceholder: "Filter by key or description",
21
+ noMatches: "No settings match.",
22
+ notSet: "Not set",
23
+ on: "On",
24
+ off: "Off",
25
+ lockedBy: (layer) => `Locked by ${layer}`,
26
+ buildOnly: "Build",
27
+ edit: "Edit",
28
+ editLabel: (key) => `Edit ${key}`,
29
+ editTitle: (key) => `Edit ${key}`,
30
+ editDescription: "A later layer wins unless an earlier one locked the value.",
31
+ overriddenBy: (layer) => `${layer} overrides this layer, so the change won't show until that value is cleared.`,
32
+ writeLayer: "Save in",
33
+ lock: "Lock",
34
+ lockHint: "Later layers can't change a locked value.",
35
+ save: "Save",
36
+ cancel: "Cancel",
37
+ clearLayer: (layer) => `Clear the ${layer} value`,
38
+ invalidJson: "That isn't valid JSON.",
39
+ changeInRepo: "Change in repo",
40
+ changeInRepoLabel: (key) => `Change ${key} in the repo`,
41
+ changeInRepoTitle: (key) => `Change ${key} in the repo`,
42
+ changeInRepoDescription: "This key is set in genesis.config.json and reviewed like code. Commit this change:",
43
+ openPullRequest: "Open pull request",
44
+ pullRequestOpened: "Pull request opened.",
45
+ readOnly: "Read-only here",
46
+ healthEmpty: "Nothing needs attention",
47
+ healthEmptyDescription: "The doctor found no problems.",
48
+ levels: { error: "Error", warn: "Warning", info: "Info" },
49
+ fix: "Fix\u2026",
50
+ fixLabel: (rule) => `Fix ${rule}`,
51
+ findingsCount: (n) => ` (${n} ${n === 1 ? "finding" : "findings"})`,
52
+ howToFix: "How to fix",
53
+ openStep: "Open step",
54
+ runInTerminal: "Run in a terminal:",
55
+ planTitle: (fixId) => `Fix ${fixId}`,
56
+ planLoading: "Planning\u2026",
57
+ planFiles: "Files it writes",
58
+ planCommands: "Commands it runs",
59
+ planSecrets: "Secrets it needs",
60
+ planManual: "Then, by hand",
61
+ planNeeds: "This host can't apply this fix. Run it from the CLI instead:",
62
+ apply: "Apply\u2026",
63
+ confirmTitle: "Apply this fix?",
64
+ confirmBody: (files, commands) => `It writes ${files} ${files === 1 ? "file" : "files"} and runs ${commands} ${commands === 1 ? "command" : "commands"}.`,
65
+ confirmApply: "Apply",
66
+ applied: "Applied and verified.",
67
+ appliedUnverified: "Applied, but its check hasn't passed yet.",
68
+ stalePlan: "Something changed since this plan was made.",
69
+ planAgain: "Plan again",
70
+ secretsEmpty: "No setting needs a secret.",
71
+ secretStatus: { set: "Set", missing: "Missing", unknown: "Unknown" },
72
+ secretStores: { vault: "Vault", edge: "Edge Function secret", "server-env": "Server environment", ci: "CI secret" },
73
+ neededBy: (keys) => `Needed by ${keys}`,
74
+ lastRotated: (when) => `Last set ${when}`,
75
+ secretHint: "Set secrets with genesis setup. Their values never reach this screen.",
76
+ setSecret: "Set\u2026",
77
+ rotateSecret: "Rotate\u2026",
78
+ secretLabel: (name) => `Set ${name}`,
79
+ setSecretTitle: (name) => `Set ${name}`,
80
+ setSecretDescription: "The value goes straight to the Vault. It is never shown again, here or anywhere.",
81
+ secretValue: "Value",
82
+ upgradesEmpty: "No release information yet.",
83
+ checkAgain: "Check again",
84
+ checkedAt: (when) => `Checked ${when}`,
85
+ offline: "Offline: showing the last check.",
86
+ distance: { current: "Up to date", patch: "Patch behind", minor: "Minor behind", major: "Major behind", unknown: "Unknown" },
87
+ advisory: "Advisory",
88
+ releaseNotes: "Release notes",
89
+ openUpgradePr: "Open upgrade PR\u2026",
90
+ auditEmpty: "No changes yet.",
91
+ loadMore: "Load more",
92
+ auditActions: { set: "Set", clear: "Cleared", fix: "Fixed", upgrade: "Upgraded", secret: "Secret changed" },
93
+ formatTime: (iso) => {
94
+ const d = new Date(iso);
95
+ return Number.isNaN(d.getTime()) ? iso : d.toLocaleString();
96
+ }
97
+ };
98
+ var LEVEL_ORDER = { error: 0, warn: 1, info: 2 };
99
+ var LEVEL_VARIANT = { error: "destructive", warn: "warning", info: "info" };
100
+ var SECRET_VARIANT = { set: "success", missing: "destructive", unknown: "muted" };
101
+ var DISTANCE_VARIANT = { current: "success", patch: "info", minor: "warning", major: "warning", unknown: "muted" };
102
+ function tid(...parts) {
103
+ return parts.map((p) => p.replace(/[^a-zA-Z0-9._-]+/g, "-")).join("-");
104
+ }
105
+ function layerLabel(copy, layer) {
106
+ return copy.layers[layer] ?? layer;
107
+ }
108
+ function formatValue(value, copy) {
109
+ if (value === null || value === void 0) return copy.notSet;
110
+ if (value === true) return copy.on;
111
+ if (value === false) return copy.off;
112
+ if (Array.isArray(value)) return value.length ? value.join(", ") : "[]";
113
+ if (typeof value === "object") return JSON.stringify(value);
114
+ return String(value);
115
+ }
116
+ function errorMessage(error) {
117
+ return error instanceof Error ? error.message : String(error);
118
+ }
119
+ function Code({ children }) {
120
+ return /* @__PURE__ */ jsx("code", { className: "rounded bg-muted px-1 py-0.5 font-mono text-xs text-foreground", children });
121
+ }
122
+ function GenesisSettings({
123
+ client,
124
+ capabilities: narrow,
125
+ copy: copyOverride,
126
+ defaultTab = "values",
127
+ onOpenStep,
128
+ auditPageSize = 25,
129
+ header = true,
130
+ testID = "genesis-settings",
131
+ className
132
+ }) {
133
+ const copy = useMemo(() => ({ ...GENESIS_SETTINGS_COPY, ...copyOverride }), [copyOverride]);
134
+ const [state, setState] = useState(null);
135
+ const [loadError, setLoadError] = useState(null);
136
+ const [loading, setLoading] = useState(true);
137
+ const [tab, setTab] = useState(defaultTab);
138
+ const load = useCallback(async () => {
139
+ setLoading(true);
140
+ try {
141
+ setState(await client.state({ auditLimit: auditPageSize }));
142
+ setLoadError(null);
143
+ } catch (error) {
144
+ setLoadError(errorMessage(error));
145
+ } finally {
146
+ setLoading(false);
147
+ }
148
+ }, [client, auditPageSize]);
149
+ useEffect(() => {
150
+ void load();
151
+ }, [load]);
152
+ const caps = useMemo(() => state ? intersectCapabilities(state.capabilities, narrow) : null, [state, narrow]);
153
+ const refresh = /* @__PURE__ */ jsx(Button, { variant: "outline", size: "sm", onClick: () => void load(), disabled: loading, testID: tid(testID, "refresh"), children: copy.refresh });
154
+ return /* @__PURE__ */ jsxs("div", { "data-slot": "genesis-settings", "data-testid": testID, className: ["flex flex-col gap-6", className].filter(Boolean).join(" "), children: [
155
+ header ? /* @__PURE__ */ jsx(
156
+ PageHeader,
157
+ {
158
+ title: copy.title,
159
+ subtitle: state ? `${state.app.name} \xB7 ${copy.description}` : copy.description,
160
+ actions: refresh
161
+ }
162
+ ) : /* @__PURE__ */ jsx("div", { className: "flex justify-end", children: refresh }),
163
+ loadError ? /* @__PURE__ */ jsx(
164
+ InlineAlert,
165
+ {
166
+ variant: "destructive",
167
+ title: copy.loadFailed,
168
+ description: loadError,
169
+ testID: tid(testID, "load-error"),
170
+ actions: /* @__PURE__ */ jsx(Button, { size: "sm", variant: "outline", onClick: () => void load(), testID: tid(testID, "retry"), children: copy.retry })
171
+ }
172
+ ) : null,
173
+ !state || !caps ? loading ? /* @__PURE__ */ jsx(PageLoading, { label: copy.loading, testID: tid(testID, "loading") }) : null : /* @__PURE__ */ jsxs(Tabs, { value: tab, onValueChange: (v) => setTab(v), defaultValue: defaultTab, children: [
174
+ /* @__PURE__ */ jsx(TabsList, { className: "max-w-full justify-start overflow-x-auto [scrollbar-width:thin]", children: ["values", "health", "secrets", "upgrades", "audit"].map((t) => /* @__PURE__ */ jsxs(TabsTrigger, { value: t, "data-testid": tid(testID, "tab", t), children: [
175
+ copy.tabs[t],
176
+ t === "health" && state.findings.length ? /* @__PURE__ */ jsxs(Fragment, { children: [
177
+ /* @__PURE__ */ jsx(Badge, { variant: state.findings.some((f) => f.level === "error") ? "destructive" : "muted", className: "ml-1.5", "aria-hidden": true, children: state.findings.length }),
178
+ /* @__PURE__ */ jsx("span", { className: "sr-only", "data-testid": tid(testID, "health-count"), children: copy.findingsCount(state.findings.length) })
179
+ ] }) : null
180
+ ] }, t)) }),
181
+ /* @__PURE__ */ jsx(TabsContent, { value: "values", className: "pt-4", children: /* @__PURE__ */ jsx(ValuesTab, { state, caps, client, copy, testID, onChanged: load }) }),
182
+ /* @__PURE__ */ jsx(TabsContent, { value: "health", className: "pt-4", children: /* @__PURE__ */ jsx(HealthTab, { state, caps, client, copy, testID, onChanged: load, onOpenStep }) }),
183
+ /* @__PURE__ */ jsx(TabsContent, { value: "secrets", className: "pt-4", children: /* @__PURE__ */ jsx(SecretsTab, { secrets: state.secrets, caps, client, copy, testID, onChanged: load }) }),
184
+ /* @__PURE__ */ jsx(TabsContent, { value: "upgrades", className: "pt-4", children: /* @__PURE__ */ jsx(UpgradesTab, { initial: state.upgrades, caps, client, copy, testID, onChanged: load }) }),
185
+ /* @__PURE__ */ jsx(TabsContent, { value: "audit", className: "pt-4", children: /* @__PURE__ */ jsx(AuditTab, { state, client, copy, testID, pageSize: auditPageSize }) })
186
+ ] })
187
+ ] });
188
+ }
189
+ function useReturnFocus() {
190
+ const opener = useRef(null);
191
+ const remember = useCallback((el) => {
192
+ opener.current = el;
193
+ }, []);
194
+ const returnFocus = useCallback((event) => {
195
+ const el = opener.current;
196
+ if (el && el.isConnected) {
197
+ event.preventDefault();
198
+ el.focus();
199
+ }
200
+ }, []);
201
+ return { remember, returnFocus };
202
+ }
203
+ function ValuesTab({ state, caps, client, copy, testID, onChanged }) {
204
+ const [filter, setFilter] = useState("");
205
+ const [editing, setEditing] = useState(null);
206
+ const [open, setOpen] = useState(false);
207
+ const { remember, returnFocus } = useReturnFocus();
208
+ const filterId = useId();
209
+ const groups = useMemo(() => {
210
+ const q = filter.trim().toLowerCase();
211
+ const byNs = /* @__PURE__ */ new Map();
212
+ for (const def of [...state.catalogue].sort((a, b) => a.key.localeCompare(b.key))) {
213
+ if (q && !def.key.toLowerCase().includes(q) && !(def.summary ?? "").toLowerCase().includes(q)) continue;
214
+ byNs.set(def.namespace, [...byNs.get(def.namespace) ?? [], def]);
215
+ }
216
+ return [...byNs.entries()].sort(([a], [b]) => a.localeCompare(b));
217
+ }, [state.catalogue, filter]);
218
+ return /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-6", children: [
219
+ /* @__PURE__ */ jsxs("div", { className: "flex max-w-sm flex-col gap-1.5", children: [
220
+ /* @__PURE__ */ jsx(Label, { htmlFor: filterId, children: copy.filterLabel }),
221
+ /* @__PURE__ */ jsx(
222
+ Input,
223
+ {
224
+ id: filterId,
225
+ type: "search",
226
+ value: filter,
227
+ placeholder: copy.filterPlaceholder,
228
+ onChange: (e) => setFilter(e.target.value),
229
+ "data-testid": tid(testID, "filter")
230
+ }
231
+ )
232
+ ] }),
233
+ groups.length === 0 ? /* @__PURE__ */ jsx(EmptyState, { title: copy.noMatches }) : null,
234
+ groups.map(([namespace, defs]) => /* @__PURE__ */ jsx(Section, { title: namespace, testID: tid(testID, "namespace", namespace), children: /* @__PURE__ */ jsx("div", { className: "divide-y", children: defs.map((def) => /* @__PURE__ */ jsx(
235
+ ValueRow,
236
+ {
237
+ def,
238
+ value: state.resolved.values[def.key],
239
+ source: state.resolved.sources[def.key],
240
+ caps,
241
+ copy,
242
+ testID,
243
+ onEdit: (mode, opener) => {
244
+ remember(opener);
245
+ setEditing((prev) => ({ def, mode, nonce: (prev?.nonce ?? 0) + 1 }));
246
+ setOpen(true);
247
+ }
248
+ },
249
+ def.key
250
+ )) }) }, namespace)),
251
+ /* @__PURE__ */ jsx(
252
+ ValueSheet,
253
+ {
254
+ returnFocus,
255
+ open,
256
+ editing,
257
+ state,
258
+ caps,
259
+ client,
260
+ copy,
261
+ testID,
262
+ onClose: () => setOpen(false),
263
+ onChanged
264
+ }
265
+ )
266
+ ] });
267
+ }
268
+ function ValueRow({
269
+ def,
270
+ value,
271
+ source,
272
+ caps,
273
+ copy,
274
+ testID,
275
+ onEdit
276
+ }) {
277
+ const writable = settingWritability(def, source, caps);
278
+ const repoOnly = !writable.layers.length && writable.refused.file === "capability" && (def.applies === "build" || source?.lockedBy === "file");
279
+ const rowId = tid(testID, "row", def.key);
280
+ return /* @__PURE__ */ jsxs(
281
+ SettingsRow,
282
+ {
283
+ testID: rowId,
284
+ label: /* @__PURE__ */ jsx("span", { className: "break-all font-mono text-sm", children: def.key }),
285
+ description: /* @__PURE__ */ jsxs("span", { className: "flex flex-col gap-1.5", children: [
286
+ def.summary ? /* @__PURE__ */ jsx("span", { children: def.summary }) : null,
287
+ /* @__PURE__ */ jsxs("span", { className: "flex flex-wrap items-center gap-1.5", children: [
288
+ /* @__PURE__ */ jsx(Badge, { variant: "outline", "data-testid": tid(rowId, "source"), "data-layer": source?.layer, children: layerLabel(copy, source?.layer ?? "default") }),
289
+ source?.lockedBy ? /* @__PURE__ */ jsxs(Badge, { variant: "warning", "data-testid": tid(rowId, "lock"), "data-layer": source.lockedBy, children: [
290
+ /* @__PURE__ */ jsx(Lock, { "aria-hidden": true, className: "mr-1 size-3" }),
291
+ copy.lockedBy(layerLabel(copy, source.lockedBy))
292
+ ] }) : null,
293
+ def.applies === "build" ? /* @__PURE__ */ jsx(Badge, { variant: "muted", children: copy.buildOnly }) : null,
294
+ /* @__PURE__ */ jsx("span", { className: "min-w-0 break-all text-foreground sm:hidden", "data-testid": tid(rowId, "value-narrow"), children: formatValue(value, copy) })
295
+ ] })
296
+ ] }),
297
+ children: [
298
+ /* @__PURE__ */ jsx("span", { className: "hidden max-w-[16rem] truncate text-sm text-foreground sm:inline", "data-testid": tid(rowId, "value"), title: formatValue(value, copy), children: formatValue(value, copy) }),
299
+ writable.layers.length ? /* @__PURE__ */ jsx(Button, { variant: "outline", size: "sm", onClick: (e) => onEdit("edit", e.currentTarget), "aria-label": copy.editLabel(def.key), testID: tid(rowId, "edit"), children: copy.edit }) : repoOnly ? /* @__PURE__ */ jsx(Button, { variant: "ghost", size: "sm", onClick: (e) => onEdit("repo", e.currentTarget), testID: tid(rowId, "repo"), "aria-label": copy.changeInRepoLabel(def.key), children: copy.changeInRepo }) : !source?.lockedBy ? /* @__PURE__ */ jsx("span", { className: "sr-only", children: copy.readOnly }) : null
300
+ ]
301
+ }
302
+ );
303
+ }
304
+ function ValueInput({
305
+ def,
306
+ draft,
307
+ onDraft,
308
+ id,
309
+ copy,
310
+ testID,
311
+ problemId
312
+ }) {
313
+ const a11y = problemId ? { "aria-invalid": true, "aria-describedby": problemId } : {};
314
+ if (def.type === "boolean") {
315
+ return /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-3", children: [
316
+ /* @__PURE__ */ jsx(Switch, { id, checked: draft === "true", onCheckedChange: (on) => onDraft(on ? "true" : "false"), "data-testid": tid(testID, "input"), ...a11y }),
317
+ /* @__PURE__ */ jsx(Label, { htmlFor: id, children: draft === "true" ? copy.on : copy.off })
318
+ ] });
319
+ }
320
+ if (def.options && (def.type === "string" || def.type === "number")) {
321
+ return /* @__PURE__ */ jsxs(Select, { value: draft, onValueChange: onDraft, children: [
322
+ /* @__PURE__ */ jsx(SelectTrigger, { id, "data-testid": tid(testID, "input"), ...a11y, children: /* @__PURE__ */ jsx(SelectValue, {}) }),
323
+ /* @__PURE__ */ jsx(SelectContent, { children: def.options.map((o) => /* @__PURE__ */ jsx(SelectItem, { value: String(o), children: String(o) }, String(o))) })
324
+ ] });
325
+ }
326
+ if (def.type === "list" || def.type === "object") {
327
+ return /* @__PURE__ */ jsx(Textarea, { id, value: draft, onChange: (e) => onDraft(e.target.value), rows: 5, className: "font-mono text-sm", "data-testid": tid(testID, "input"), ...a11y });
328
+ }
329
+ return /* @__PURE__ */ jsx(
330
+ Input,
331
+ {
332
+ id,
333
+ type: def.type === "number" ? "number" : "text",
334
+ value: draft,
335
+ onChange: (e) => onDraft(e.target.value),
336
+ ...def.min !== void 0 ? { min: def.min } : {},
337
+ ...def.max !== void 0 ? { max: def.max } : {},
338
+ "data-testid": tid(testID, "input"),
339
+ ...a11y
340
+ }
341
+ );
342
+ }
343
+ function toDraft(def, value) {
344
+ if (value === null || value === void 0) return "";
345
+ if (def.type === "list" || def.type === "object") return JSON.stringify(value, null, 2);
346
+ return String(value);
347
+ }
348
+ function fromDraft(def, draft, copy) {
349
+ let value;
350
+ if (draft.trim() === "" && def.nullable && def.type !== "boolean") value = null;
351
+ else if (def.type === "boolean") value = draft === "true";
352
+ else if (def.type === "number") value = draft.trim() === "" ? Number.NaN : Number(draft);
353
+ else if (def.type === "list" || def.type === "object") {
354
+ try {
355
+ value = JSON.parse(draft);
356
+ } catch {
357
+ return { problem: copy.invalidJson };
358
+ }
359
+ } else value = draft;
360
+ const problem = settingValueProblem(def, value);
361
+ return problem ? { problem } : { value };
362
+ }
363
+ function ValueSheet({ open, ...props }) {
364
+ return /* @__PURE__ */ jsx(Sheet, { open: open && props.editing !== null, onOpenChange: (o) => o ? void 0 : props.onClose(), children: props.editing ? /* @__PURE__ */ jsx(ValueSheetBody, { ...props, editing: props.editing }, props.editing.nonce) : null });
365
+ }
366
+ function ValueSheetBody({
367
+ returnFocus,
368
+ editing,
369
+ state,
370
+ caps,
371
+ client,
372
+ copy,
373
+ testID,
374
+ onClose,
375
+ onChanged
376
+ }) {
377
+ const def = editing.def;
378
+ const source = state.resolved.sources[def.key];
379
+ const writable = settingWritability(def, source, caps);
380
+ const preferred = preferredWriteLayer(writable, source);
381
+ const lockedIn = (l) => l ? state.layers[l]?.[def.key]?.locked === true : source?.lockedBy === "file";
382
+ const [layer, setLayerState] = useState(preferred);
383
+ const [draft, setDraft] = useState(() => toDraft(def, state.resolved.values[def.key]));
384
+ const [locked, setLocked] = useState(() => lockedIn(preferred));
385
+ const setLayer = (l) => {
386
+ setLayerState(l);
387
+ setLocked(lockedIn(l));
388
+ };
389
+ const overriddenBy = !editing || editing.mode !== "edit" || !layer || !source || SETTINGS_LAYERS.indexOf(source.layer) <= SETTINGS_LAYERS.indexOf(layer) ? null : source.layer;
390
+ const [busy, setBusy] = useState(false);
391
+ const [error, setError] = useState(null);
392
+ const [proposal, setProposal] = useState(null);
393
+ const baseId = useId();
394
+ const sheetId = tid(testID, "value-sheet");
395
+ const parsed = fromDraft(def, draft, copy);
396
+ const problem = "problem" in parsed ? parsed.problem : null;
397
+ const layerHas = layer ? Object.prototype.hasOwnProperty.call(state.layers[layer] ?? {}, def.key) : false;
398
+ const run = async (work) => {
399
+ setBusy(true);
400
+ setError(null);
401
+ try {
402
+ await work();
403
+ } catch (e) {
404
+ setError(errorMessage(e));
405
+ } finally {
406
+ setBusy(false);
407
+ }
408
+ };
409
+ const save = () => run(async () => {
410
+ if (!layer || "problem" in parsed) return;
411
+ await client.setValue({ key: def.key, value: parsed.value, locked, layer });
412
+ onClose();
413
+ await onChanged();
414
+ });
415
+ const clear = () => run(async () => {
416
+ if (!layer) return;
417
+ await client.clearValue({ key: def.key, layer });
418
+ onClose();
419
+ await onChanged();
420
+ });
421
+ const propose = () => run(async () => {
422
+ if ("problem" in parsed) return;
423
+ const result = await client.propose({ key: def.key, value: parsed.value, locked });
424
+ setProposal(result.pullRequestUrl ?? result.snippet);
425
+ });
426
+ const repo = editing.mode === "repo";
427
+ const inputId = `${baseId}-value`;
428
+ return /* @__PURE__ */ jsx(Fragment, { children: /* @__PURE__ */ jsxs(SheetContent, { "data-testid": sheetId, className: "flex flex-col gap-4 sm:max-w-lg", onCloseAutoFocus: returnFocus, children: [
429
+ /* @__PURE__ */ jsxs(SheetHeader, { children: [
430
+ /* @__PURE__ */ jsx(SheetTitle, { children: repo ? copy.changeInRepoTitle(def.key) : copy.editTitle(def.key) }),
431
+ /* @__PURE__ */ jsx(SheetDescription, { children: repo ? copy.changeInRepoDescription : def.summary ?? copy.editDescription })
432
+ ] }),
433
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-4 px-4", children: [
434
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-1.5", children: [
435
+ /* @__PURE__ */ jsx(Label, { htmlFor: inputId, children: def.key }),
436
+ /* @__PURE__ */ jsx(ValueInput, { def, draft, onDraft: setDraft, id: inputId, copy, testID: sheetId, problemId: problem ? `${baseId}-problem` : void 0 }),
437
+ problem ? /* @__PURE__ */ jsx("p", { id: `${baseId}-problem`, className: "text-sm text-destructive", role: "alert", "data-testid": tid(sheetId, "problem"), children: problem }) : null
438
+ ] }),
439
+ !repo && writable.layers.length > 1 ? /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-1.5", children: [
440
+ /* @__PURE__ */ jsx("span", { className: "text-sm font-medium", id: `${baseId}-layer`, children: copy.writeLayer }),
441
+ /* @__PURE__ */ jsx(RadioGroup, { "aria-labelledby": `${baseId}-layer`, value: layer, onValueChange: (v) => setLayer(v), className: "flex gap-4", children: writable.layers.map((l) => /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", children: [
442
+ /* @__PURE__ */ jsx(RadioGroupItem, { id: `${baseId}-layer-${l}`, value: l, "data-testid": tid(sheetId, "layer", l) }),
443
+ /* @__PURE__ */ jsx(Label, { htmlFor: `${baseId}-layer-${l}`, children: layerLabel(copy, l) })
444
+ ] }, l)) })
445
+ ] }) : null,
446
+ /* @__PURE__ */ jsxs("div", { className: "flex items-start gap-2", children: [
447
+ /* @__PURE__ */ jsx(Checkbox, { id: `${baseId}-lock`, checked: locked, onCheckedChange: (c) => setLocked(c === true), "data-testid": tid(sheetId, "lock") }),
448
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-0.5", children: [
449
+ /* @__PURE__ */ jsx(Label, { htmlFor: `${baseId}-lock`, children: copy.lock }),
450
+ /* @__PURE__ */ jsx("span", { className: "text-xs text-muted-foreground", children: copy.lockHint })
451
+ ] })
452
+ ] }),
453
+ overriddenBy ? /* @__PURE__ */ jsx(InlineAlert, { variant: "info", description: copy.overriddenBy(layerLabel(copy, overriddenBy)), testID: tid(sheetId, "overridden") }) : null,
454
+ repo ? /* @__PURE__ */ jsx("pre", { className: "max-h-64 overflow-auto rounded-md bg-muted p-3 font-mono text-xs", "data-testid": tid(sheetId, "snippet"), children: settingFileSnippet(def.key, "value" in parsed ? parsed.value : draft, locked) }) : null,
455
+ proposal ? /* @__PURE__ */ jsx(InlineAlert, { variant: "success", title: copy.pullRequestOpened, description: proposal, testID: tid(sheetId, "proposal") }) : null,
456
+ error ? /* @__PURE__ */ jsx(InlineAlert, { variant: "destructive", description: error, testID: tid(sheetId, "error") }) : null
457
+ ] }),
458
+ /* @__PURE__ */ jsxs(SheetFooter, { className: "mt-auto flex-col gap-2 sm:flex-row sm:justify-end", children: [
459
+ !repo && layer && layerHas ? /* @__PURE__ */ jsx(Button, { variant: "ghost", onClick: () => void clear(), disabled: busy, testID: tid(sheetId, "clear"), children: copy.clearLayer(layerLabel(copy, layer)) }) : null,
460
+ /* @__PURE__ */ jsx(Button, { variant: "outline", onClick: onClose, testID: tid(sheetId, "cancel"), children: copy.cancel }),
461
+ repo ? caps.proposeChanges ? /* @__PURE__ */ jsx(Button, { onClick: () => void propose(), disabled: busy || problem !== null, testID: tid(sheetId, "propose"), children: copy.openPullRequest }) : null : /* @__PURE__ */ jsx(Button, { onClick: () => void save(), disabled: busy || problem !== null || !layer, testID: tid(sheetId, "save"), children: copy.save })
462
+ ] })
463
+ ] }) });
464
+ }
465
+ function canAutoFix(caps, fix) {
466
+ return caps.writeFiles || caps.runCli || fix.databaseOnly === true && caps.writeDatabase;
467
+ }
468
+ function HealthTab({
469
+ state,
470
+ caps,
471
+ client,
472
+ copy,
473
+ testID,
474
+ onChanged,
475
+ onOpenStep
476
+ }) {
477
+ const [fixing, setFixing] = useState(null);
478
+ const { remember, returnFocus } = useReturnFocus();
479
+ const findings = useMemo(() => [...state.findings].sort((a, b) => (LEVEL_ORDER[a.level] ?? 3) - (LEVEL_ORDER[b.level] ?? 3)), [state.findings]);
480
+ if (!findings.length) return /* @__PURE__ */ jsx(EmptyState, { title: copy.healthEmpty, description: copy.healthEmptyDescription });
481
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
482
+ /* @__PURE__ */ jsx("div", { className: "divide-y", children: findings.map((f) => /* @__PURE__ */ jsx(
483
+ FindingRow,
484
+ {
485
+ finding: f,
486
+ caps,
487
+ copy,
488
+ testID,
489
+ onFix: (id, opener) => {
490
+ remember(opener);
491
+ setFixing(id);
492
+ },
493
+ onOpenStep
494
+ },
495
+ f.id
496
+ )) }),
497
+ /* @__PURE__ */ jsx(PlanSheet, { fixId: fixing, caps, client, copy, testID, onClose: () => setFixing(null), onChanged, returnFocus })
498
+ ] });
499
+ }
500
+ function FindingRow({
501
+ finding,
502
+ caps,
503
+ copy,
504
+ testID,
505
+ onFix,
506
+ onOpenStep
507
+ }) {
508
+ const fix = finding.fix;
509
+ const href = safeHref(fix?.href);
510
+ const rowId = tid(testID, "finding", finding.id);
511
+ const where = finding.file ? `${finding.file}${finding.line ? `:${finding.line}` : ""}` : null;
512
+ return /* @__PURE__ */ jsx(
513
+ SettingsRow,
514
+ {
515
+ testID: rowId,
516
+ label: /* @__PURE__ */ jsx("span", { className: "whitespace-normal leading-snug", children: finding.message }),
517
+ description: /* @__PURE__ */ jsxs("span", { className: "flex flex-col gap-1.5", children: [
518
+ /* @__PURE__ */ jsxs("span", { className: "flex flex-wrap items-center gap-1.5", children: [
519
+ /* @__PURE__ */ jsx(Badge, { variant: LEVEL_VARIANT[finding.level] ?? "muted", children: copy.levels[finding.level] ?? finding.level }),
520
+ /* @__PURE__ */ jsx(Code, { children: finding.rule }),
521
+ where ? /* @__PURE__ */ jsx("span", { className: "break-all", children: where }) : null
522
+ ] }),
523
+ fix ? /* @__PURE__ */ jsx(FixHint, { fix, caps, copy, testID: rowId, onOpenStep }) : null
524
+ ] }),
525
+ children: fix?.kind === "auto" && canAutoFix(caps, fix) ? /* @__PURE__ */ jsx(Button, { size: "sm", onClick: (e) => onFix(fix.id, e.currentTarget), testID: tid(rowId, "fix"), "aria-label": copy.fixLabel(finding.rule), children: copy.fix }) : fix?.kind === "guided" && (href || onOpenStep && fix.step) ? href ? /* @__PURE__ */ jsx(Button, { size: "sm", variant: "outline", asChild: true, children: /* @__PURE__ */ jsx("a", { href, "data-testid": tid(rowId, "step"), children: copy.openStep }) }) : /* @__PURE__ */ jsx(Button, { size: "sm", variant: "outline", onClick: () => onOpenStep?.(fix.step), testID: tid(rowId, "step"), children: copy.openStep }) : null
526
+ }
527
+ );
528
+ }
529
+ function FixHint({
530
+ fix,
531
+ caps,
532
+ copy,
533
+ testID,
534
+ onOpenStep
535
+ }) {
536
+ if (fix.kind === "auto" && !canAutoFix(caps, fix)) {
537
+ return /* @__PURE__ */ jsxs("span", { "data-testid": tid(testID, "cli"), children: [
538
+ copy.runInTerminal,
539
+ " ",
540
+ /* @__PURE__ */ jsxs(Code, { children: [
541
+ "genesis fix ",
542
+ fix.id
543
+ ] })
544
+ ] });
545
+ }
546
+ if (fix.kind === "guided" && !safeHref(fix.href) && !(onOpenStep && fix.step)) {
547
+ return /* @__PURE__ */ jsxs("span", { "data-testid": tid(testID, "cli"), children: [
548
+ copy.runInTerminal,
549
+ " ",
550
+ /* @__PURE__ */ jsx(Code, { children: fix.step ? `genesis setup --step ${fix.step}` : `genesis fix ${fix.id}` })
551
+ ] });
552
+ }
553
+ if (fix.kind === "manual" && fix.instructions) {
554
+ return /* @__PURE__ */ jsxs(Collapsible, { children: [
555
+ /* @__PURE__ */ jsx(CollapsibleTrigger, { asChild: true, children: /* @__PURE__ */ jsx(Button, { variant: "link", size: "sm", className: "h-auto px-0", testID: tid(testID, "how"), children: copy.howToFix }) }),
556
+ /* @__PURE__ */ jsx(CollapsibleContent, { children: /* @__PURE__ */ jsx("span", { className: "block whitespace-pre-wrap text-sm text-foreground", "data-testid": tid(testID, "instructions"), children: fix.instructions }) })
557
+ ] });
558
+ }
559
+ return null;
560
+ }
561
+ function missingFor(plan, caps) {
562
+ const out = [];
563
+ if (plan.files.length && !caps.writeFiles) out.push("writeFiles");
564
+ if (plan.commands.length && !caps.runCli) out.push("runCli");
565
+ if (plan.secrets.length && caps.setSecrets !== true) out.push("setSecrets");
566
+ for (const layer of plan.layers ?? []) {
567
+ if (layer === "database" && !caps.writeDatabase) out.push("writeDatabase");
568
+ if (layer === "file" && !caps.writeFiles && !out.includes("writeFiles")) out.push("writeFiles");
569
+ }
570
+ return out;
571
+ }
572
+ function PlanSheet({ fixId, caps, client, copy, testID, onClose, onChanged, returnFocus }) {
573
+ const [plan, setPlan] = useState(null);
574
+ const [error, setError] = useState(null);
575
+ const [result, setResult] = useState(null);
576
+ const [confirming, setConfirming] = useState(false);
577
+ const [busy, setBusy] = useState(false);
578
+ const sheetId = tid(testID, "plan-sheet");
579
+ const makePlan = useCallback(async (id) => {
580
+ setBusy(true);
581
+ setPlan(null);
582
+ setError(null);
583
+ setResult(null);
584
+ try {
585
+ setPlan(await client.plan(id));
586
+ } catch (e) {
587
+ setError({ message: errorMessage(e), stale: false });
588
+ } finally {
589
+ setBusy(false);
590
+ }
591
+ }, [client]);
592
+ useEffect(() => {
593
+ if (fixId) void makePlan(fixId);
594
+ }, [fixId, makePlan]);
595
+ const apply = async () => {
596
+ if (!plan) return;
597
+ setConfirming(false);
598
+ setBusy(true);
599
+ setError(null);
600
+ try {
601
+ setResult(await client.apply(plan.fixId, plan.hash));
602
+ await onChanged();
603
+ } catch (e) {
604
+ const stale = e instanceof SettingsProtocolError && e.code === "stale_plan";
605
+ setError({ message: stale ? copy.stalePlan : errorMessage(e), stale });
606
+ } finally {
607
+ setBusy(false);
608
+ }
609
+ };
610
+ const missing = plan ? missingFor(plan, caps) : [];
611
+ return /* @__PURE__ */ jsxs(Sheet, { open: fixId !== null, onOpenChange: (open) => open ? void 0 : onClose(), children: [
612
+ /* @__PURE__ */ jsxs(SheetContent, { "data-testid": sheetId, className: "flex flex-col gap-4 sm:max-w-2xl", onCloseAutoFocus: returnFocus, children: [
613
+ /* @__PURE__ */ jsxs(SheetHeader, { children: [
614
+ /* @__PURE__ */ jsx(SheetTitle, { children: copy.planTitle(fixId ?? "") }),
615
+ /* @__PURE__ */ jsx(SheetDescription, { children: plan ? plan.summary : copy.planLoading })
616
+ ] }),
617
+ /* @__PURE__ */ jsxs("div", { className: "flex min-h-0 flex-col gap-4 px-4", children: [
618
+ busy && !plan ? /* @__PURE__ */ jsx(PageLoading, { label: copy.planLoading }) : null,
619
+ plan ? /* @__PURE__ */ jsxs(Fragment, { children: [
620
+ plan.files.length ? /* @__PURE__ */ jsx(Section, { title: copy.planFiles, level: 3, children: /* @__PURE__ */ jsx("ul", { className: "flex flex-col gap-3", "data-testid": tid(sheetId, "files"), children: plan.files.map((f) => /* @__PURE__ */ jsxs("li", { className: "flex flex-col gap-1", children: [
621
+ /* @__PURE__ */ jsx("span", { className: "break-all font-mono text-sm", children: f.path }),
622
+ /* @__PURE__ */ jsx("span", { className: "text-xs text-muted-foreground", children: f.why }),
623
+ f.diff ? /* @__PURE__ */ jsx("pre", { className: "max-h-64 overflow-auto rounded-md bg-muted p-3 font-mono text-xs", children: f.diff }) : null
624
+ ] }, f.path)) }) }) : null,
625
+ plan.commands.length ? /* @__PURE__ */ jsx(Section, { title: copy.planCommands, level: 3, children: /* @__PURE__ */ jsx("ul", { className: "flex flex-col gap-2", "data-testid": tid(sheetId, "commands"), children: plan.commands.map((c, i) => /* @__PURE__ */ jsxs("li", { className: "flex flex-col gap-1", children: [
626
+ /* @__PURE__ */ jsx(Code, { children: [c.tool, ...c.args].join(" ") }),
627
+ /* @__PURE__ */ jsx("span", { className: "text-xs text-muted-foreground", children: c.why })
628
+ ] }, i)) }) }) : null,
629
+ plan.secrets.length ? /* @__PURE__ */ jsx(Section, { title: copy.planSecrets, level: 3, children: /* @__PURE__ */ jsx("p", { className: "text-sm", "data-testid": tid(sheetId, "secrets"), children: plan.secrets.join(", ") }) }) : null,
630
+ plan.manual ? /* @__PURE__ */ jsx(Section, { title: copy.planManual, level: 3, children: /* @__PURE__ */ jsx("p", { className: "whitespace-pre-wrap text-sm", children: plan.manual }) }) : null,
631
+ missing.length ? /* @__PURE__ */ jsx(
632
+ InlineAlert,
633
+ {
634
+ variant: "warning",
635
+ description: /* @__PURE__ */ jsxs(Fragment, { children: [
636
+ copy.planNeeds,
637
+ " ",
638
+ /* @__PURE__ */ jsxs(Code, { children: [
639
+ "genesis fix ",
640
+ plan.fixId
641
+ ] })
642
+ ] }),
643
+ testID: tid(sheetId, "needs")
644
+ }
645
+ ) : null
646
+ ] }) : null,
647
+ result ? /* @__PURE__ */ jsx(
648
+ InlineAlert,
649
+ {
650
+ variant: result.verified ? "success" : "warning",
651
+ title: result.verified ? copy.applied : copy.appliedUnverified,
652
+ description: result.pullRequestUrl ?? result.message,
653
+ testID: tid(sheetId, "result")
654
+ }
655
+ ) : null,
656
+ error ? /* @__PURE__ */ jsx(
657
+ InlineAlert,
658
+ {
659
+ variant: "destructive",
660
+ description: error.message,
661
+ testID: tid(sheetId, "error"),
662
+ actions: error.stale && fixId ? /* @__PURE__ */ jsx(Button, { size: "sm", variant: "outline", onClick: () => void makePlan(fixId), testID: tid(sheetId, "replan"), children: copy.planAgain }) : void 0
663
+ }
664
+ ) : null
665
+ ] }),
666
+ /* @__PURE__ */ jsxs(SheetFooter, { className: "mt-auto flex-col gap-2 sm:flex-row sm:justify-end", children: [
667
+ /* @__PURE__ */ jsx(Button, { variant: "outline", onClick: onClose, testID: tid(sheetId, "cancel"), children: copy.cancel }),
668
+ plan && !result && !missing.length ? /* @__PURE__ */ jsx(Button, { onClick: () => setConfirming(true), disabled: busy, testID: tid(sheetId, "apply"), children: copy.apply }) : null
669
+ ] })
670
+ ] }),
671
+ /* @__PURE__ */ jsx(AlertDialog, { open: confirming, onOpenChange: setConfirming, children: /* @__PURE__ */ jsxs(AlertDialogContent, { "data-testid": tid(sheetId, "confirm"), children: [
672
+ /* @__PURE__ */ jsxs(AlertDialogHeader, { children: [
673
+ /* @__PURE__ */ jsx(AlertDialogTitle, { children: copy.confirmTitle }),
674
+ /* @__PURE__ */ jsx(AlertDialogDescription, { children: plan ? copy.confirmBody(plan.files.length, plan.commands.length) : null })
675
+ ] }),
676
+ /* @__PURE__ */ jsxs(AlertDialogFooter, { children: [
677
+ /* @__PURE__ */ jsx(AlertDialogCancel, { "data-testid": tid(sheetId, "confirm-cancel"), children: copy.cancel }),
678
+ /* @__PURE__ */ jsx(AlertDialogAction, { onClick: () => void apply(), "data-testid": tid(sheetId, "confirm-apply"), children: copy.confirmApply })
679
+ ] })
680
+ ] }) })
681
+ ] });
682
+ }
683
+ function SecretsTab({ secrets, caps, client, copy, testID, onChanged }) {
684
+ const [setting, setSetting] = useState(null);
685
+ const [open, setOpen] = useState(false);
686
+ const { remember, returnFocus } = useReturnFocus();
687
+ if (!secrets.length) return /* @__PURE__ */ jsx(EmptyState, { title: copy.secretsEmpty });
688
+ const canVault = canSetSecret(caps, "vault") && typeof client.setSecret === "function";
689
+ return /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-4", children: [
690
+ /* @__PURE__ */ jsx("p", { className: "text-sm text-muted-foreground", children: copy.secretHint }),
691
+ /* @__PURE__ */ jsx("div", { className: "divide-y", children: [...secrets].sort((a, b) => a.name.localeCompare(b.name)).map((s) => {
692
+ const rowId = tid(testID, "secret", s.name);
693
+ const neededBy = Array.isArray(s.neededBy) ? s.neededBy : [];
694
+ return /* @__PURE__ */ jsxs(
695
+ SettingsRow,
696
+ {
697
+ testID: rowId,
698
+ label: /* @__PURE__ */ jsx("span", { className: "break-all font-mono text-sm", children: s.name }),
699
+ description: /* @__PURE__ */ jsxs("span", { className: "flex flex-col gap-0.5", children: [
700
+ /* @__PURE__ */ jsx("span", { children: copy.secretStores[s.store] ?? s.store }),
701
+ neededBy.length ? /* @__PURE__ */ jsx("span", { className: "break-words", children: copy.neededBy(neededBy.join(", ")) }) : null,
702
+ s.lastRotated ? /* @__PURE__ */ jsx("span", { children: copy.lastRotated(copy.formatTime(s.lastRotated)) }) : null
703
+ ] }),
704
+ children: [
705
+ /* @__PURE__ */ jsx(Badge, { variant: SECRET_VARIANT[s.status] ?? "muted", "data-testid": tid(rowId, "status"), "data-status": s.status, children: copy.secretStatus[s.status] ?? s.status }),
706
+ canVault && s.store === "vault" ? /* @__PURE__ */ jsx(
707
+ Button,
708
+ {
709
+ size: "sm",
710
+ variant: "outline",
711
+ onClick: (e) => {
712
+ remember(e.currentTarget);
713
+ setSetting((prev) => ({ name: s.name, nonce: (prev?.nonce ?? 0) + 1 }));
714
+ setOpen(true);
715
+ },
716
+ "aria-label": copy.secretLabel(s.name),
717
+ testID: tid(rowId, "set"),
718
+ children: s.status === "set" ? copy.rotateSecret : copy.setSecret
719
+ }
720
+ ) : null
721
+ ]
722
+ },
723
+ `${s.store}:${s.name}`
724
+ );
725
+ }) }),
726
+ /* @__PURE__ */ jsx(Sheet, { open: open && setting !== null, onOpenChange: (o) => o ? void 0 : setOpen(false), children: setting ? /* @__PURE__ */ jsx(
727
+ SecretSheet,
728
+ {
729
+ name: setting.name,
730
+ caps,
731
+ client,
732
+ copy,
733
+ testID,
734
+ onClose: () => setOpen(false),
735
+ onChanged,
736
+ returnFocus
737
+ },
738
+ setting.nonce
739
+ ) : null })
740
+ ] });
741
+ }
742
+ function redact(text, secret) {
743
+ return secret ? text.split(secret).join("\u2022\u2022\u2022") : text;
744
+ }
745
+ function SecretSheet({ name, client, copy, testID, onClose, onChanged, returnFocus }) {
746
+ const input = useRef(null);
747
+ const [empty, setEmpty] = useState(true);
748
+ const [busy, setBusy] = useState(false);
749
+ const [error, setError] = useState(null);
750
+ const inputId = useId();
751
+ const sheetId = tid(testID, "secret-sheet");
752
+ const clear = () => {
753
+ if (input.current) input.current.value = "";
754
+ setEmpty(true);
755
+ };
756
+ useEffect(() => {
757
+ const el = input.current;
758
+ return () => {
759
+ if (el) el.value = "";
760
+ };
761
+ }, []);
762
+ const close = () => {
763
+ clear();
764
+ onClose();
765
+ };
766
+ const save = async () => {
767
+ const value = input.current?.value ?? "";
768
+ if (!value || !client.setSecret) return;
769
+ setBusy(true);
770
+ setError(null);
771
+ try {
772
+ await client.setSecret({ name, store: "vault", value });
773
+ close();
774
+ await onChanged();
775
+ } catch (e) {
776
+ clear();
777
+ setError(redact(errorMessage(e), value));
778
+ } finally {
779
+ setBusy(false);
780
+ }
781
+ };
782
+ return /* @__PURE__ */ jsxs(SheetContent, { "data-testid": sheetId, className: "flex flex-col gap-4 sm:max-w-lg", onCloseAutoFocus: returnFocus, children: [
783
+ /* @__PURE__ */ jsxs(SheetHeader, { children: [
784
+ /* @__PURE__ */ jsx(SheetTitle, { children: copy.setSecretTitle(name) }),
785
+ /* @__PURE__ */ jsx(SheetDescription, { children: copy.setSecretDescription })
786
+ ] }),
787
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-1.5 px-4", children: [
788
+ /* @__PURE__ */ jsx(Label, { htmlFor: inputId, children: copy.secretValue }),
789
+ /* @__PURE__ */ jsx(
790
+ Input,
791
+ {
792
+ ref: input,
793
+ id: inputId,
794
+ type: "password",
795
+ autoComplete: "off",
796
+ spellCheck: false,
797
+ defaultValue: "",
798
+ onInput: (e) => setEmpty(e.currentTarget.value === ""),
799
+ "data-testid": tid(sheetId, "input")
800
+ }
801
+ ),
802
+ error ? /* @__PURE__ */ jsx(InlineAlert, { variant: "destructive", description: error, testID: tid(sheetId, "error") }) : null
803
+ ] }),
804
+ /* @__PURE__ */ jsxs(SheetFooter, { className: "mt-auto flex-col gap-2 sm:flex-row sm:justify-end", children: [
805
+ /* @__PURE__ */ jsx(Button, { variant: "outline", onClick: close, testID: tid(sheetId, "cancel"), children: copy.cancel }),
806
+ /* @__PURE__ */ jsx(Button, { onClick: () => void save(), disabled: busy || empty, testID: tid(sheetId, "save"), children: copy.save })
807
+ ] })
808
+ ] });
809
+ }
810
+ function UpgradesTab({ initial, caps, client, copy, testID, onChanged }) {
811
+ const [upgrades, setUpgrades] = useState(initial);
812
+ const [busy, setBusy] = useState(false);
813
+ const [error, setError] = useState(null);
814
+ const [fixing, setFixing] = useState(null);
815
+ const { remember, returnFocus } = useReturnFocus();
816
+ useEffect(() => setUpgrades(initial), [initial]);
817
+ const check = async (refresh) => {
818
+ setBusy(true);
819
+ setError(null);
820
+ try {
821
+ setUpgrades(await client.upgrades({ refresh }));
822
+ } catch (e) {
823
+ setError(errorMessage(e));
824
+ } finally {
825
+ setBusy(false);
826
+ }
827
+ };
828
+ return /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-4", children: [
829
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-wrap items-center justify-between gap-2", children: [
830
+ /* @__PURE__ */ jsxs("p", { className: "text-sm text-muted-foreground", children: [
831
+ upgrades?.checkedAt ? copy.checkedAt(copy.formatTime(upgrades.checkedAt)) : null,
832
+ upgrades?.offline ? ` ${copy.offline}` : null
833
+ ] }),
834
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-wrap gap-2", children: [
835
+ /* @__PURE__ */ jsx(Button, { variant: "outline", size: "sm", onClick: () => void check(true), disabled: busy, testID: tid(testID, "upgrades-check"), children: copy.checkAgain }),
836
+ upgrades?.fix && caps.runCli ? /* @__PURE__ */ jsx(Button, { size: "sm", onClick: (e) => {
837
+ remember(e.currentTarget);
838
+ setFixing(upgrades.fix.id);
839
+ }, testID: tid(testID, "upgrades-pr"), children: copy.openUpgradePr }) : null
840
+ ] })
841
+ ] }),
842
+ upgrades?.fix && !caps.runCli ? /* @__PURE__ */ jsxs("p", { className: "text-sm text-muted-foreground", "data-testid": tid(testID, "upgrades-cli"), children: [
843
+ copy.runInTerminal,
844
+ " ",
845
+ /* @__PURE__ */ jsx(Code, { children: "genesis upgrade" })
846
+ ] }) : null,
847
+ error ? /* @__PURE__ */ jsx(InlineAlert, { variant: "destructive", description: error, testID: tid(testID, "upgrades-error") }) : null,
848
+ !upgrades?.packages.length ? /* @__PURE__ */ jsx(EmptyState, { title: copy.upgradesEmpty }) : /* @__PURE__ */ jsx("div", { className: "divide-y", children: upgrades.packages.map((p) => {
849
+ const rowId = tid(testID, "upgrade", p.name);
850
+ return /* @__PURE__ */ jsxs(
851
+ SettingsRow,
852
+ {
853
+ testID: rowId,
854
+ label: /* @__PURE__ */ jsx("span", { className: "break-all font-mono text-sm", children: p.name }),
855
+ description: /* @__PURE__ */ jsxs("span", { className: "flex flex-col gap-1", children: [
856
+ /* @__PURE__ */ jsxs("span", { children: [
857
+ p.current,
858
+ p.latest && p.latest !== p.current ? ` \u2192 ${p.latest}` : ""
859
+ ] }),
860
+ p.notes ? /* @__PURE__ */ jsx("span", { className: "whitespace-pre-wrap", children: p.notes }) : null,
861
+ safeHref(p.notesUrl) ? /* @__PURE__ */ jsx("a", { className: "text-primary-text underline-offset-4 hover:underline", href: safeHref(p.notesUrl), target: "_blank", rel: "noreferrer", children: copy.releaseNotes }) : null
862
+ ] }),
863
+ children: [
864
+ p.advisory ? /* @__PURE__ */ jsx(Badge, { variant: "destructive", children: copy.advisory }) : null,
865
+ /* @__PURE__ */ jsx(Badge, { variant: DISTANCE_VARIANT[p.distance] ?? "muted", "data-testid": tid(rowId, "distance"), children: copy.distance[p.distance] ?? p.distance })
866
+ ]
867
+ },
868
+ p.name
869
+ );
870
+ }) }),
871
+ /* @__PURE__ */ jsx(PlanSheet, { fixId: fixing, caps, client, copy, testID, onClose: () => setFixing(null), onChanged, returnFocus })
872
+ ] });
873
+ }
874
+ function AuditTab({
875
+ state,
876
+ client,
877
+ copy,
878
+ testID,
879
+ pageSize
880
+ }) {
881
+ const initial = state.audit;
882
+ const [entries, setEntries] = useState(initial?.entries ?? []);
883
+ const [next, setNext] = useState(initial?.next);
884
+ const [fetched, setFetched] = useState(initial !== void 0);
885
+ const [busy, setBusy] = useState(false);
886
+ const [error, setError] = useState(null);
887
+ const names = useMemo(() => secretNames(state.catalogue, state.secrets), [state.catalogue, state.secrets]);
888
+ const load = useCallback(
889
+ async (cursor, append) => {
890
+ setBusy(true);
891
+ setError(null);
892
+ try {
893
+ const page = await client.audit({ ...cursor !== void 0 ? { cursor } : {}, limit: pageSize });
894
+ const got = Array.isArray(page?.entries) ? page.entries : [];
895
+ setEntries((prev) => append ? [...prev, ...got] : got);
896
+ setNext(page?.next);
897
+ } catch (e) {
898
+ setError(errorMessage(e));
899
+ } finally {
900
+ setBusy(false);
901
+ setFetched(true);
902
+ }
903
+ },
904
+ [client, pageSize]
905
+ );
906
+ useEffect(() => {
907
+ if (initial) {
908
+ setEntries(initial.entries ?? []);
909
+ setNext(initial.next);
910
+ setFetched(true);
911
+ } else void load(void 0, false);
912
+ }, [initial, load]);
913
+ if (!fetched) return /* @__PURE__ */ jsx(PageLoading, { label: copy.loading, testID: tid(testID, "audit-loading") });
914
+ if (!entries.length && !next && !error) return /* @__PURE__ */ jsx(EmptyState, { title: copy.auditEmpty });
915
+ return /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-4", children: [
916
+ /* @__PURE__ */ jsx("div", { className: "divide-y", children: entries.map((e) => {
917
+ const change = auditValuesVisible(e, state.catalogue, names) && (e.before !== void 0 || e.after !== void 0) ? `${formatValue(e.before, copy)} \u2192 ${formatValue(e.after, copy)}` : null;
918
+ return /* @__PURE__ */ jsx(
919
+ SettingsRow,
920
+ {
921
+ testID: tid(testID, "audit", e.id),
922
+ label: /* @__PURE__ */ jsxs("span", { className: "whitespace-normal break-words leading-snug", children: [
923
+ copy.auditActions[e.action] ?? e.action,
924
+ " ",
925
+ /* @__PURE__ */ jsx("span", { className: "font-mono", children: e.subject })
926
+ ] }),
927
+ description: /* @__PURE__ */ jsxs("span", { className: "flex flex-col gap-0.5", children: [
928
+ e.summary ? /* @__PURE__ */ jsx("span", { children: e.summary }) : null,
929
+ change ? /* @__PURE__ */ jsx("span", { className: "break-all", children: change }) : null,
930
+ /* @__PURE__ */ jsx("span", { children: [e.actor, copy.formatTime(e.at), e.layer ? layerLabel(copy, e.layer) : null, e.locked ? copy.lock : null].filter(Boolean).join(" \xB7 ") })
931
+ ] })
932
+ },
933
+ e.id
934
+ );
935
+ }) }),
936
+ error ? /* @__PURE__ */ jsx(InlineAlert, { variant: "destructive", description: error, testID: tid(testID, "audit-error") }) : null,
937
+ next ? /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(Button, { variant: "outline", size: "sm", onClick: () => void load(next, true), disabled: busy, testID: tid(testID, "audit-more"), children: copy.loadMore }) }) : null
938
+ ] });
939
+ }
940
+
941
+ export { GENESIS_SETTINGS_COPY, GenesisSettings };
942
+ //# sourceMappingURL=settings-react.js.map
943
+ //# sourceMappingURL=settings-react.js.map