feat(settings): data-safe editors, deep-linked search, Data/About/Cost pages

- EditorModal loads once per path (a parent re-render no longer reloads the
  file over the user's typing), refuses Save after a failed load, opens a
  truncated (>256 KB) file read-only, and asks before overwriting a file
  that changed on disk or could not be re-read.
- Settings/Hooks editors unset only keys from the snapshot taken at Edit,
  warn when the file changed underneath, keep a renamed key's value, and
  refuse a new key named like a redacted one (env) or a read-only hook
  event, which used to replace the secret/hooks.
- Project scope shows its resolved folder and is disabled inside the
  plugin cache. Account-profile, pricing-row and pet deletes confirm;
  two-click actions disarm after 3 s; unsaved drafts ask before closing.
- Search indexes every Claude Code / Codex sub-tab, opens it via ?tab= and
  scrolls to + highlights the row; the active config tab is in the URL.
- General splits into General / Data / About; Pricing moves to a Cost
  group with one shared load; config tabs group as Content / Extensions /
  Config with arrow-key roving; Promise.allSettled per tab.
- Data: browser-preferences export/import (allowlisted keys), per-section
  reset, housekeeping dry-run first, clear-all behind a typed phrase.
  Server: purge days must be a whole number >= 1 (INVALID_PURGE_DAYS) and
  dry_run returns exactly what the real run would delete.
- Alerts can be edited; webhooks/alerts/remote-source failures toast;
  copies go through copyText; modals get dialog roles and useDialog.
- Sagi: Ctrl/Cmd+B only when shown and not typing, default spot clear of
  row controls, arrow keys move it, reduced motion honoured; the dead
  /run launch link goes to the workspace.
This commit is contained in:
2026-10-05 13:22:08 +07:00
parent 03f1673fce
commit 6715fbd971
68 changed files with 4817 additions and 1374 deletions
+58 -6
View File
@@ -7,7 +7,10 @@
* default model (`PUT /api/ai-tools/:id {defaultModel}`) for a tool with a
* model flag; its vendor's pricing table; and the config files its catalog
* file lists, each opened over a sha and saved by the server only if it is
* still that sha, valid, and backed up. Antigravity adds its hooks card.
* still that sha, valid, and backed up — a refusal because the file changed
* (ESTALE) offers a reload and keeps the user's text to copy, and an edited
* file asks before another file or Close drops it. Antigravity adds its hooks
* card.
* @author Nguyễn Ngọc Trí Vĩ <vinnt@smartgift.vn>
*/
@@ -16,6 +19,10 @@ import { Link } from "react-router-dom";
import { useTranslation } from "react-i18next";
import { Cpu, ExternalLink, FileCog, RefreshCw } from "lucide-react";
import { api, type AiToolConfigFile } from "../lib/api";
import { toast } from "../lib/toast";
import { confirmDiscard } from "../lib/confirm";
import { copyText } from "../lib/clipboard";
import { useUnsavedGuard } from "../hooks/useUnsavedGuard";
import type { Lane } from "../lib/types";
import { useAiTools } from "../hooks/useAiTools";
import { AiToolIcon } from "../components/AiToolIcon";
@@ -39,6 +46,7 @@ function DefaultModel({ toolId, saved }: { toolId: string; saved: string }) {
setError(null);
try {
await aiTools.update(toolId, { defaultModel: value || null });
toast.success(t("toolTab.defaultModelSaved"));
} catch (err) {
setError(message(err));
}
@@ -70,8 +78,14 @@ function ConfigFiles({ toolId }: { toolId: string }) {
const [files, setFiles] = useState<AiToolConfigFile[] | null>(null);
const [open, setOpen] = useState<{ index: number; path: string; sha: string } | null>(null);
const [text, setText] = useState("");
// The text as opened/saved: an edit differs from it.
const [base, setBase] = useState("");
const [busy, setBusy] = useState(false);
const [note, setNote] = useState<{ ok: boolean; text: string } | null>(null);
// Set when a save was refused because the file changed on disk.
const [stale, setStale] = useState(false);
const dirty = open !== null && text !== base;
useUnsavedGuard(dirty);
useEffect(() => {
api.aiTools
@@ -80,26 +94,42 @@ function ConfigFiles({ toolId }: { toolId: string }) {
.catch((err) => setNote({ ok: false, text: message(err) }));
}, [toolId]);
const openFile = async (f: AiToolConfigFile) => {
const load = async (index: number) => {
setNote(null);
setStale(false);
try {
const r = await api.aiTools.readConfig(toolId, f.index);
setOpen({ index: f.index, path: r.path, sha: r.sha });
const r = await api.aiTools.readConfig(toolId, index);
setOpen({ index, path: r.path, sha: r.sha });
setText(r.text);
setBase(r.text);
} catch (err) {
setNote({ ok: false, text: message(err) });
}
};
const openFile = async (f: AiToolConfigFile) => {
if (dirty && !(await confirmDiscard())) return;
await load(f.index);
};
const close = async () => {
if (dirty && !(await confirmDiscard())) return;
setOpen(null);
setStale(false);
};
const save = async () => {
if (!open) return;
setBusy(true);
setNote(null);
setStale(false);
try {
const r = await api.aiTools.saveConfig(toolId, open.index, text, open.sha);
setOpen({ ...open, sha: r.sha });
setBase(text);
setNote({ ok: true, text: t("toolTab.saved", { backup: r.backup }) });
} catch (err) {
setStale((err as { code?: string }).code === "ESTALE");
setNote({ ok: false, text: message(err) });
} finally {
setBusy(false);
@@ -141,16 +171,38 @@ function ConfigFiles({ toolId }: { toolId: string }) {
<button
type="button"
onClick={save}
disabled={busy}
disabled={busy || !dirty}
className="btn-ghost text-xs disabled:opacity-50"
>
{busy && <RefreshCw className="h-3.5 w-3.5 animate-spin" />}
{t("toolTab.save")}
</button>
<button type="button" onClick={() => setOpen(null)} className="btn-ghost text-xs">
<button type="button" onClick={() => void close()} className="btn-ghost text-xs">
{t("toolTab.close")}
</button>
</div>
{stale && (
<div
role="alert"
className="flex flex-wrap items-center gap-2 rounded-md border border-status-warning/40 bg-status-warning/10 px-3 py-2 text-xs text-fg-primary"
>
<span className="flex-1">{t("toolTab.staleBody")}</span>
<button
type="button"
onClick={() => void copyText(text)}
className="btn-ghost text-xs"
>
{t("toolTab.copyMine")}
</button>
<button
type="button"
onClick={() => void load(open.index)}
className="btn-ghost text-xs"
>
{t("toolTab.reloadDiscard")}
</button>
</div>
)}
</div>
)}
{note && (