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
+37 -11
View File
@@ -6,7 +6,9 @@
* adds one, deletes one. A token is write-only here: the server never returns
* one, so the form starts blank and the list shows only that one is saved.
* The git bar's login form saves into the same store. A right-click on a row
* opens the same Replace / Remove (plus Copy host) as a menu.
* opens the same Replace / Remove (plus Copy host) as a menu. A bare host
* (`git.example.com`) means https; Replace keeps the host fixed (it replaces
* that host's login, never moves it), and a remove asks through `confirmDialog`.
* @author Nguyễn Ngọc Trí Vĩ <vinnt@smartgift.vn>
*/
import { useCallback, useEffect, useState } from "react";
@@ -14,6 +16,9 @@ import { useTranslation } from "react-i18next";
import { Pencil, Plus, Trash2 } from "lucide-react";
import { api, type GitCredential } from "../lib/api";
import { ContextMenu, MenuItem, MenuSeparator, useContextMenu } from "../components/ContextMenu";
import { confirmDialog } from "../lib/confirm";
import { copyText } from "../lib/clipboard";
import { toast } from "../lib/toast";
const INPUT =
"w-full rounded border border-border-light bg-surface-0 px-2 py-1 text-xs text-fg-primary placeholder:text-fg-muted focus:border-accent focus:outline-none";
@@ -22,7 +27,15 @@ export function GitCredentialsConfig() {
const { t } = useTranslation("settings");
const [items, setItems] = useState<GitCredential[]>([]);
const [error, setError] = useState<string | null>(null);
const [form, setForm] = useState<{ url: string; username: string; token: string } | null>(null);
// `replacing`: the host is the saved one's and stays fixed.
const [form, setForm] = useState<{
url: string;
username: string;
token: string;
replacing?: boolean;
} | null>(null);
const [loading, setLoading] = useState(true);
const [saving, setSaving] = useState(false);
const ctx = useContextMenu<GitCredential>();
// A menu item: close the menu, then act on the row it was opened on.
const pick = (fn: (c: GitCredential) => unknown) => () => {
@@ -36,6 +49,8 @@ export function GitCredentialsConfig() {
setItems((await api.gitCredentials.list()).items);
} catch (e) {
setError(e instanceof Error ? e.message : String(e));
} finally {
setLoading(false);
}
}, []);
useEffect(() => {
@@ -46,12 +61,15 @@ export function GitCredentialsConfig() {
if (!form) return;
setError(null);
let url: URL;
const typed = form.url.trim();
try {
url = new URL(form.url.trim());
// A bare host (no scheme) is the common case: take it as https.
url = new URL(/^[a-z][a-z0-9+.-]*:\/\//i.test(typed) ? typed : `https://${typed}`);
} catch {
setError(t("gitCreds.badUrl"));
return;
}
setSaving(true);
try {
const r = await api.gitCredentials.save({
protocol: url.protocol.replace(/:$/, ""),
@@ -61,16 +79,25 @@ export function GitCredentialsConfig() {
});
setItems(r.items);
setForm(null);
toast.success(t("gitCreds.saved", { host: url.host }));
} catch (e) {
setError(e instanceof Error ? e.message : String(e));
} finally {
setSaving(false);
}
};
const replace = (c: GitCredential) =>
setForm({ url: `${c.protocol}://${c.host}`, username: c.username, token: "" });
setForm({ url: `${c.protocol}://${c.host}`, username: c.username, token: "", replacing: true });
const remove = async (c: GitCredential) => {
if (!window.confirm(t("gitCreds.removeConfirm"))) return;
if (
!(await confirmDialog({
title: t("gitCreds.removeConfirm"),
confirmLabel: t("gitCreds.remove"),
}))
)
return;
try {
setItems((await api.gitCredentials.remove(c.protocol, c.host)).items);
} catch (e) {
@@ -111,8 +138,9 @@ export function GitCredentialsConfig() {
aria-label={t("gitCreds.fieldHost")}
placeholder="https://git.example.com"
value={form.url}
readOnly={form.replacing}
onChange={(e) => setForm({ ...form, url: e.target.value })}
className={`${INPUT} font-mono`}
className={`${INPUT} font-mono read-only:opacity-70`}
/>
<input
aria-label={t("gitCreds.fieldUser")}
@@ -134,7 +162,7 @@ export function GitCredentialsConfig() {
<div className="flex gap-2 sm:col-span-3">
<button
type="submit"
disabled={!form.url.trim() || !form.username.trim() || !form.token}
disabled={saving || !form.url.trim() || !form.username.trim() || !form.token}
className="rounded border border-accent/40 bg-accent/15 px-3 py-1 text-xs text-accent hover:bg-accent/25 disabled:cursor-not-allowed disabled:opacity-40"
>
{t("gitCreds.save")}
@@ -199,7 +227,7 @@ export function GitCredentialsConfig() {
{items.length === 0 && (
<tr className="border-t border-border">
<td colSpan={4} className="px-3 py-4 text-center text-fg-muted">
{t("gitCreds.empty")}
{loading ? t("gitCreds.loading") : t("gitCreds.empty")}
</td>
</tr>
)}
@@ -209,9 +237,7 @@ export function GitCredentialsConfig() {
{ctx.menu && (
<ContextMenu x={ctx.menu.x} y={ctx.menu.y} onClose={ctx.close} testId="git-cred-menu">
<MenuItem onSelect={pick(replace)}>{t("gitCreds.replace")}</MenuItem>
<MenuItem onSelect={pick((c) => void navigator.clipboard.writeText(c.host))}>
{t("rowMenu.copyHost")}
</MenuItem>
<MenuItem onSelect={pick((c) => void copyText(c.host))}>{t("rowMenu.copyHost")}</MenuItem>
<MenuSeparator />
<MenuItem danger onSelect={pick((c) => void remove(c))}>
{t("gitCreds.remove")}