mirror of
https://github.com/binaricat/Netcatty.git
synced 2026-11-17 21:10:48 +00:00
* feat(ai): add Claude auth-presence detection helper Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * fix(ai): surface actionable Claude auth errors and reap stuck agent processes Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * feat(ai): add pure helpers for Claude config dir + env editor Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * feat(ai): let users set Claude config dir and env vars in settings Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * polish(ai): harden Claude config env, de-dupe error text, label a11y - buildClaudeEnv: drop managed keys (CLAUDE_CONFIG_DIR/CLAUDE_CODE_EXECUTABLE) if a user types them into the free-text env editor, so they can't clobber the config-dir field or the discovered executable path (+ regression test). - bridge: only append error data fields not already shown as message/code, so the actionable error text doesn't echo the same code/message twice. - ClaudeCodeCard: associate the new config-dir/env labels with their inputs via htmlFor/id. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * feat(ai): make the Claude auth & config section collapsible The optional "Authentication & config" section now has a collapsible header (chevron toggle). Collapsed by default to keep the card tidy, but auto-expanded when the user already has a config directory or env vars set so existing config isn't hidden. Local UI state, not persisted. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * fix(ai): preserve raw env editor text; don't encourage plaintext secrets P1: the env textarea was bound to the persisted value, which is the parsed env re-serialized — so typing a key before its "=" was erased mid-entry (buildClaudeEnv drops lines without "="). Keep the raw typed text in local draft state and only resync from the persisted value on genuine external changes (not our own parse→serialize round-trip). P2: the env editor persists to localStorage in plaintext (no credential encryption). Stop suggesting ANTHROPIC_API_KEY in the placeholder and warn that values are stored in plaintext, steering credentials to the config directory (a `claude` login) — consistent with keeping Claude auth CLI/config-owned (#705). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * fix(ai): expand ~ in Claude config directory before passing to the agent CLAUDE_CONFIG_DIR is handed to the spawned agent as an env var, which is not shell-expanded — so "~/.claude" was treated as a literal "~" directory. Expand a leading ~ at consume time (normalizeAgentEnv + getClaudeConfigDir) rather than on save, so the stored value stays portable across machines (cloud sync) and each device expands to its own home. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * fix(ai): recreate cached Claude provider when its env config changes Claude ACP providers are cached per chat session and reused unless one of the fingerprinted dimensions changes. authFingerprint was null for Claude, so editing the config directory / env vars in Settings didn't take effect on an already-running session. Fingerprint the Claude agent env so a config change invalidates the cached provider and the next turn respawns with it. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
162 lines
6.5 KiB
TypeScript
162 lines
6.5 KiB
TypeScript
import React, { useEffect, useState } from "react";
|
|
import { ChevronDown, RefreshCw } from "lucide-react";
|
|
import { useI18n } from "../../../../application/i18n/I18nProvider";
|
|
import { Button } from "../../../ui/button";
|
|
import { cn } from "../../../../lib/utils";
|
|
import type { AgentPathInfo } from "./types";
|
|
import { ProviderIconBadge } from "./ProviderIconBadge";
|
|
import { parseEnvLines, serializeEnvLines } from "./claudeConfigEnv";
|
|
|
|
export const ClaudeCodeCard: React.FC<{
|
|
pathInfo: AgentPathInfo | null;
|
|
isResolvingPath: boolean;
|
|
customPath: string;
|
|
onCustomPathChange: (path: string) => void;
|
|
onRecheckPath: () => void;
|
|
configDir: string;
|
|
onConfigDirChange: (value: string) => void;
|
|
envText: string;
|
|
onEnvTextChange: (value: string) => void;
|
|
}> = ({
|
|
pathInfo,
|
|
isResolvingPath,
|
|
customPath,
|
|
onCustomPathChange,
|
|
onRecheckPath,
|
|
configDir,
|
|
onConfigDirChange,
|
|
envText,
|
|
onEnvTextChange,
|
|
}) => {
|
|
const { t } = useI18n();
|
|
const found = pathInfo?.available;
|
|
// Collapsed by default; auto-expand when the user already has config so it
|
|
// isn't hidden. Local UI state — not persisted.
|
|
const [configOpen, setConfigOpen] = useState(
|
|
() => Boolean(configDir.trim() || envText.trim()),
|
|
);
|
|
|
|
// The env editor keeps the raw text the user types. Persisting parses it into
|
|
// a record (dropping incomplete lines), so binding the textarea directly to
|
|
// the persisted value would erase a key the moment it's typed before its "=".
|
|
// Only resync from the persisted value when it changes for some reason other
|
|
// than our own parse→serialize round-trip.
|
|
const [envDraft, setEnvDraft] = useState(envText);
|
|
useEffect(() => {
|
|
setEnvDraft((prev) =>
|
|
serializeEnvLines(parseEnvLines(prev)) === envText ? prev : envText,
|
|
);
|
|
}, [envText]);
|
|
|
|
const statusText = isResolvingPath
|
|
? t('ai.claude.detecting')
|
|
: found
|
|
? t('ai.claude.detected')
|
|
: t('ai.claude.notFound');
|
|
|
|
const statusClassName = isResolvingPath
|
|
? "text-muted-foreground"
|
|
: found
|
|
? "text-emerald-500"
|
|
: "text-amber-500";
|
|
|
|
return (
|
|
<div className="rounded-lg border border-border/60 bg-muted/20 p-4 space-y-3">
|
|
<div className="flex items-start justify-between gap-4">
|
|
<div className="min-w-0">
|
|
<div className="flex items-center gap-2">
|
|
<ProviderIconBadge providerId="claude" size="sm" />
|
|
<span className="text-sm font-medium">{t('ai.claude.title')}</span>
|
|
</div>
|
|
<p className="text-xs text-muted-foreground mt-2 leading-5">
|
|
{t('ai.claude.description')}
|
|
</p>
|
|
</div>
|
|
<div className={cn("text-xs font-medium shrink-0", statusClassName)}>
|
|
{statusText}
|
|
</div>
|
|
</div>
|
|
|
|
{/* Path detection info */}
|
|
{found ? (
|
|
<div className="flex items-center gap-2 text-xs">
|
|
<span className="text-muted-foreground">{t('ai.claude.path')}</span>
|
|
<span className="font-mono text-foreground truncate">{pathInfo.path}</span>
|
|
{pathInfo.version && (
|
|
<>
|
|
<span className="text-muted-foreground">|</span>
|
|
<span className="text-muted-foreground">{pathInfo.version}</span>
|
|
</>
|
|
)}
|
|
</div>
|
|
) : !isResolvingPath ? (
|
|
<div className="space-y-2">
|
|
<p className="text-xs text-amber-500">
|
|
{t('ai.claude.notFoundHint')}
|
|
</p>
|
|
<div className="flex items-center gap-2">
|
|
<input
|
|
type="text"
|
|
value={customPath}
|
|
onChange={(e) => onCustomPathChange(e.target.value)}
|
|
placeholder={t('ai.claude.customPathPlaceholder')}
|
|
className="flex-1 h-8 rounded-md border border-input bg-background px-3 text-sm font-mono placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring"
|
|
/>
|
|
<Button variant="outline" size="sm" onClick={onRecheckPath} disabled={!customPath.trim()}>
|
|
<RefreshCw size={14} className="mr-1.5" />
|
|
{t('ai.claude.check')}
|
|
</Button>
|
|
</div>
|
|
</div>
|
|
) : null}
|
|
|
|
{/* Authentication & config (optional, collapsible) */}
|
|
<div className="border-t border-border/60 pt-3">
|
|
<button
|
|
type="button"
|
|
onClick={() => setConfigOpen((v) => !v)}
|
|
aria-expanded={configOpen}
|
|
className="flex w-full items-center justify-between gap-2 text-left"
|
|
>
|
|
<span className="text-xs font-medium text-muted-foreground">
|
|
{t('ai.claude.configSection')}
|
|
</span>
|
|
<ChevronDown
|
|
size={14}
|
|
className={cn("text-muted-foreground transition-transform", configOpen && "rotate-180")}
|
|
/>
|
|
</button>
|
|
{configOpen && (
|
|
<div className="space-y-3 mt-3">
|
|
<div className="space-y-1.5">
|
|
<label htmlFor="claude-config-dir" className="text-xs text-muted-foreground">{t('ai.claude.configDir')}</label>
|
|
<input
|
|
id="claude-config-dir"
|
|
type="text"
|
|
value={configDir}
|
|
onChange={(e) => onConfigDirChange(e.target.value)}
|
|
placeholder={t('ai.claude.configDir.placeholder')}
|
|
className="w-full h-8 rounded-md border border-input bg-background px-3 text-sm font-mono placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring"
|
|
/>
|
|
<p className="text-[11px] text-muted-foreground leading-4">{t('ai.claude.configDir.hint')}</p>
|
|
</div>
|
|
<div className="space-y-1.5">
|
|
<label htmlFor="claude-env-vars" className="text-xs text-muted-foreground">{t('ai.claude.envVars')}</label>
|
|
<textarea
|
|
id="claude-env-vars"
|
|
value={envDraft}
|
|
onChange={(e) => { setEnvDraft(e.target.value); onEnvTextChange(e.target.value); }}
|
|
placeholder={t('ai.claude.envVars.placeholder')}
|
|
rows={3}
|
|
spellCheck={false}
|
|
className="w-full rounded-md border border-input bg-background px-3 py-2 text-sm font-mono placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring resize-y"
|
|
/>
|
|
<p className="text-[11px] text-muted-foreground leading-4">{t('ai.claude.envVars.hint')}</p>
|
|
</div>
|
|
</div>
|
|
)}
|
|
</div>
|
|
</div>
|
|
);
|
|
};
|