Wave 3.1:老板十项返工(kimi 换代 kimi-code/授权检测/可更新判定/模型列表+测试连通/系统环境诊断/外链/命令复制/官方图标主色)
Co-authored-by: multica-agent <github@multica.ai>
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
import { useMemo, useState } from "react";
|
||||
import { useEffect, useMemo, useState } from "react";
|
||||
import { Search } from "lucide-react";
|
||||
import { useCatalog } from "../hooks/useCatalog";
|
||||
import { useDetectAll } from "../hooks/useDetectAll";
|
||||
import { checkUpdate } from "../ipc";
|
||||
import type { UpdateCheckResult } from "../ipc/types";
|
||||
import { StatusBadge } from "../components/StatusBadge";
|
||||
import { CliMonogram } from "../components/CliMonogram";
|
||||
import { MonoChip } from "../components/MonoChip";
|
||||
@@ -22,13 +24,46 @@ const PLATFORM_FILTERS: { key: PlatformFilter; label: string }[] = [
|
||||
{ key: "linux", label: "Linux" },
|
||||
];
|
||||
|
||||
/** CLI 目录页(视觉规范 §3.2 + PRD §7):搜索 + 筛选 + 14 张卡片(数据来自 catalog.yaml + 真机 detect) */
|
||||
/** CLI 目录页(视觉规范 §3.2 + PRD §7):搜索 + 筛选 + 14 张卡片(数据来自 catalog.yaml + 真机 detect + 官方源可更新判定) */
|
||||
export function CatalogPage({ onOpenDetail }: { onOpenDetail: (id: string) => void }) {
|
||||
const { entries, loading, error } = useCatalog();
|
||||
const { detectMap, loading: detecting } = useDetectAll();
|
||||
const [query, setQuery] = useState("");
|
||||
const [status, setStatus] = useState<StatusFilter>("all");
|
||||
const [platform, setPlatform] = useState<PlatformFilter>("all");
|
||||
const [updates, setUpdates] = useState<Record<string, UpdateCheckResult>>({});
|
||||
const [checkingUpdates, setCheckingUpdates] = useState(false);
|
||||
|
||||
// 「可更新」筛选:仅当用户点选时才对已装工具查询官方源最新版本(Wave 3.1 Req 4)
|
||||
useEffect(() => {
|
||||
if (status !== "update" || checkingUpdates) return;
|
||||
let cancelled = false;
|
||||
setCheckingUpdates(true);
|
||||
const installedIds = entries.filter((e) => detectMap[e.id]?.status === "installed").map((e) => e.id);
|
||||
Promise.all(
|
||||
installedIds.map(async (id) => {
|
||||
try {
|
||||
return await checkUpdate(id);
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}),
|
||||
)
|
||||
.then((results) => {
|
||||
if (cancelled) return;
|
||||
const m: Record<string, UpdateCheckResult> = {};
|
||||
results.forEach((r, i) => {
|
||||
if (r) m[installedIds[i]] = r;
|
||||
});
|
||||
setUpdates(m);
|
||||
})
|
||||
.finally(() => {
|
||||
if (!cancelled) setCheckingUpdates(false);
|
||||
});
|
||||
return () => {
|
||||
cancelled = true;
|
||||
};
|
||||
}, [status, entries, detectMap, checkingUpdates]);
|
||||
|
||||
const filtered = useMemo(() => {
|
||||
const q = query.trim().toLowerCase();
|
||||
@@ -41,13 +76,13 @@ export function CatalogPage({ onOpenDetail }: { onOpenDetail: (id: string) => vo
|
||||
// 状态筛选:接真机 detect 结果
|
||||
if (status === "installed" && !installed) return false;
|
||||
if (status === "uninstalled" && installed) return false;
|
||||
// 可更新:Wave 2.1 不检测可更新,恒为空(诚实)
|
||||
if (status === "update") return false;
|
||||
// 可更新:官方源最新版本 vs 本地已装版本(真实数据,Wave 3.1 Req 4)
|
||||
if (status === "update") return updates[e.id]?.update_available === true;
|
||||
// 平台:全部 14 个均支持 Windows + Ubuntu(调研底稿结论),筛选不改变集合
|
||||
if (platform === "windows" || platform === "linux") return true;
|
||||
return true;
|
||||
});
|
||||
}, [entries, query, status, platform, detectMap]);
|
||||
}, [entries, query, status, platform, detectMap, updates]);
|
||||
|
||||
return (
|
||||
<div className="catalog">
|
||||
@@ -128,11 +163,18 @@ export function CatalogPage({ onOpenDetail }: { onOpenDetail: (id: string) => vo
|
||||
)}
|
||||
<span className="catalog-platforms">Windows · Linux</span>
|
||||
</div>
|
||||
{updates[entry.id]?.update_available && (
|
||||
<div className="catalog-update">
|
||||
可更新 {updates[entry.id].latest}(依据 {updates[entry.id].source_zh})
|
||||
</div>
|
||||
)}
|
||||
</article>
|
||||
);
|
||||
})}
|
||||
{!loading && filtered.length === 0 && (
|
||||
<p className="panel-empty catalog-empty">没有符合条件的 CLI</p>
|
||||
<p className="panel-empty catalog-empty">
|
||||
{status === "update" && checkingUpdates ? "正在查询官方源最新版本…" : "没有符合条件的 CLI"}
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -6,13 +6,14 @@ import {
|
||||
ChevronDown,
|
||||
CircleHelp,
|
||||
ClipboardList,
|
||||
Copy,
|
||||
Loader2,
|
||||
ShieldAlert,
|
||||
Terminal,
|
||||
Trash2,
|
||||
} from "lucide-react";
|
||||
import { useCliDetail } from "../hooks/useCliDetail";
|
||||
import { diagnose, onCliAction, previewAction, runAction } from "../ipc";
|
||||
import { diagnose, onCliAction, openExternal, previewAction, runAction } from "../ipc";
|
||||
import type {
|
||||
ActionEvent,
|
||||
Adapter,
|
||||
@@ -249,7 +250,7 @@ export function CliDetailPage({
|
||||
|
||||
<section className="cli-detail-body">
|
||||
{tab === "overview" && <OverviewTab adapter={adapter} detect={detect} auth={auth} />}
|
||||
{tab === "config" && <ConfigForm id={id} onAuthChanged={refresh} />}
|
||||
{tab === "config" && <ConfigForm id={id} onAuthChanged={refresh} canTestConnection={adapter.authorization?.test != null} />}
|
||||
{tab === "docs" && <DocsTab adapter={adapter} />}
|
||||
{tab === "diag" && <DiagTab id={id} />}
|
||||
</section>
|
||||
@@ -552,12 +553,20 @@ function OverviewTab({
|
||||
<h3 className="detail-block-title">官方链接</h3>
|
||||
<div className="detail-links">
|
||||
{adapter.official?.homepage && (
|
||||
<a className="detail-link" href={adapter.official.homepage} target="_blank" rel="noreferrer">
|
||||
<a
|
||||
className="detail-link"
|
||||
href={adapter.official.homepage}
|
||||
onClick={(e) => { e.preventDefault(); void openExternal(adapter.official!.homepage!); }}
|
||||
>
|
||||
官方主页
|
||||
</a>
|
||||
)}
|
||||
{adapter.official?.docs && (
|
||||
<a className="detail-link" href={adapter.official.docs} target="_blank" rel="noreferrer">
|
||||
<a
|
||||
className="detail-link"
|
||||
href={adapter.official.docs}
|
||||
onClick={(e) => { e.preventDefault(); void openExternal(adapter.official!.docs!); }}
|
||||
>
|
||||
官方文档
|
||||
</a>
|
||||
)}
|
||||
@@ -589,6 +598,37 @@ function authModeLabel(mode: string): string {
|
||||
}
|
||||
}
|
||||
|
||||
/** 可复制命令块(Wave 3.1 Req 9):hover 高亮 + 点击复制 + 复制成功轻提示 */
|
||||
function CopyableCommand({ text }: { text: string }) {
|
||||
const [copied, setCopied] = useState(false);
|
||||
async function copy() {
|
||||
try {
|
||||
await navigator.clipboard.writeText(text);
|
||||
} catch {
|
||||
const ta = document.createElement("textarea");
|
||||
ta.value = text;
|
||||
document.body.appendChild(ta);
|
||||
ta.select();
|
||||
document.execCommand("copy");
|
||||
document.body.removeChild(ta);
|
||||
}
|
||||
setCopied(true);
|
||||
window.setTimeout(() => setCopied(false), 1500);
|
||||
}
|
||||
return (
|
||||
<button type="button" className="command-copy" onClick={copy} title="点击复制命令" aria-label={`复制命令 ${text}`}>
|
||||
<MonoChip>{text}</MonoChip>
|
||||
{copied ? (
|
||||
<span className="command-copied">
|
||||
<Check size={12} strokeWidth={1.5} aria-hidden="true" /> 已复制
|
||||
</span>
|
||||
) : (
|
||||
<Copy size={12} strokeWidth={1.5} aria-hidden="true" />
|
||||
)}
|
||||
</button>
|
||||
);
|
||||
}
|
||||
|
||||
function DocsTab({ adapter }: { adapter: Adapter }) {
|
||||
const doc = adapter.documentation;
|
||||
const docUrl = adapter.official?.docs;
|
||||
@@ -622,7 +662,7 @@ function DocsTab({ adapter }: { adapter: Adapter }) {
|
||||
<ul className="detail-commands">
|
||||
{doc!.commands!.map((c) => (
|
||||
<li key={c.cmd} className="detail-command">
|
||||
<MonoChip>{c.cmd}</MonoChip>
|
||||
<CopyableCommand text={c.cmd} />
|
||||
{c.desc_zh && <span className="detail-command-desc">{c.desc_zh}</span>}
|
||||
</li>
|
||||
))}
|
||||
@@ -635,7 +675,7 @@ function DocsTab({ adapter }: { adapter: Adapter }) {
|
||||
<ul className="detail-commands">
|
||||
{doc!.params!.map((p) => (
|
||||
<li key={p.param} className="detail-command">
|
||||
<MonoChip>{p.param}</MonoChip>
|
||||
<CopyableCommand text={p.param} />
|
||||
{p.desc_zh && <span className="detail-command-desc">{p.desc_zh}</span>}
|
||||
</li>
|
||||
))}
|
||||
@@ -654,7 +694,11 @@ function DocsTab({ adapter }: { adapter: Adapter }) {
|
||||
)}
|
||||
<div className="detail-block detail-doc-footer">
|
||||
{docUrl && (
|
||||
<a className="detail-link" href={docUrl} target="_blank" rel="noreferrer">
|
||||
<a
|
||||
className="detail-link"
|
||||
href={docUrl}
|
||||
onClick={(e) => { e.preventDefault(); void openExternal(docUrl); }}
|
||||
>
|
||||
官方文档原文
|
||||
</a>
|
||||
)}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import { useEffect, useState } from "react";
|
||||
import { Activity, Archive, Download, Loader2, Lock, Plus, ScanSearch } from "lucide-react";
|
||||
import { Activity, Archive, Cpu, Download, Loader2, Lock, Plus, ScanSearch } from "lucide-react";
|
||||
import { useEnv } from "../hooks/useEnv";
|
||||
import { useCatalog } from "../hooks/useCatalog";
|
||||
import { useDetectAll } from "../hooks/useDetectAll";
|
||||
import { diagnoseAll } from "../ipc";
|
||||
import { diagnoseAll, diagnoseSystem } from "../ipc";
|
||||
import type {
|
||||
CatalogEntry,
|
||||
DetectResult,
|
||||
@@ -11,6 +11,7 @@ import type {
|
||||
PlatformEnv,
|
||||
RuntimeInfo,
|
||||
RuntimeStatus,
|
||||
SystemEnvReport,
|
||||
} from "../ipc/types";
|
||||
import { KpiCard } from "../components/KpiCard";
|
||||
import { MonoChip } from "../components/MonoChip";
|
||||
@@ -82,8 +83,8 @@ function RuntimeItem({
|
||||
<span className="runtime-missing">{meta.missingText}</span>
|
||||
)}
|
||||
{meta.needsInstall && (
|
||||
<button type="button" className="link-btn runtime-action" onClick={() => onInstall(name)}>
|
||||
<Download size={12} strokeWidth={1.5} aria-hidden="true" /> 安装
|
||||
<button type="button" className="btn btn-secondary btn-sm runtime-action" onClick={() => onInstall(name)}>
|
||||
<Download size={13} strokeWidth={1.5} aria-hidden="true" /> 安装
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
@@ -92,8 +93,10 @@ function RuntimeItem({
|
||||
|
||||
function EnvPanel({
|
||||
onInstallRuntime,
|
||||
onSystemDiagnose,
|
||||
}: {
|
||||
onInstallRuntime: (runtime: string) => void;
|
||||
onSystemDiagnose: () => void;
|
||||
}) {
|
||||
const { env, loading } = useEnv();
|
||||
const [showAllPath, setShowAllPath] = useState(false);
|
||||
@@ -132,6 +135,9 @@ function EnvPanel({
|
||||
<div className="panel-head">
|
||||
<h2 className="panel-title">本机环境</h2>
|
||||
{loading && <span className="panel-hint">刷新中…</span>}
|
||||
<button type="button" className="btn btn-secondary btn-sm env-diag-btn" onClick={onSystemDiagnose}>
|
||||
<Cpu size={13} strokeWidth={1.5} aria-hidden="true" /> 系统环境诊断
|
||||
</button>
|
||||
</div>
|
||||
<div className="env-grid">
|
||||
<div className="env-basic">
|
||||
@@ -408,6 +414,9 @@ export function OverviewPage({ onNavigate, onOpenDetail, pendingRuntime, onRunti
|
||||
const [diagOpen, setDiagOpen] = useState(false);
|
||||
const [diagReports, setDiagReports] = useState<DiagnosticReport[] | null>(null);
|
||||
const [diagBusy, setDiagBusy] = useState(false);
|
||||
const [sysDiagOpen, setSysDiagOpen] = useState(false);
|
||||
const [sysDiag, setSysDiag] = useState<SystemEnvReport | null>(null);
|
||||
const [sysDiagBusy, setSysDiagBusy] = useState(false);
|
||||
|
||||
// 外部跳转(详情页错误内联按钮「去安装 Node.js」)
|
||||
useEffect(() => {
|
||||
@@ -431,6 +440,21 @@ export function OverviewPage({ onNavigate, onOpenDetail, pendingRuntime, onRunti
|
||||
}
|
||||
}
|
||||
|
||||
async function runSystemDiagnose() {
|
||||
setSysDiagOpen(true);
|
||||
setSysDiagBusy(true);
|
||||
setSysDiag(null);
|
||||
try {
|
||||
const report = await diagnoseSystem();
|
||||
setSysDiag(report);
|
||||
} catch (e) {
|
||||
setSysDiag({ findings: [] });
|
||||
void e;
|
||||
} finally {
|
||||
setSysDiagBusy(false);
|
||||
}
|
||||
}
|
||||
|
||||
const installedCount = entries.filter((e) => detectMap[e.id]?.status === "installed").length;
|
||||
// 检测未完成(首次、无缓存)时不得判空态
|
||||
const ready = !detecting && !catalogLoading;
|
||||
@@ -495,7 +519,7 @@ export function OverviewPage({ onNavigate, onOpenDetail, pendingRuntime, onRunti
|
||||
)}
|
||||
|
||||
{/* ④ 本机环境(真实检测结果,架构 §5;超宽断点上提为第三栏) */}
|
||||
<EnvPanel onInstallRuntime={setRuntimeInstall} />
|
||||
<EnvPanel onInstallRuntime={setRuntimeInstall} onSystemDiagnose={runSystemDiagnose} />
|
||||
|
||||
{/* 运行时一键安装弹窗 */}
|
||||
{runtimeInstall && (
|
||||
@@ -508,6 +532,13 @@ export function OverviewPage({ onNavigate, onOpenDetail, pendingRuntime, onRunti
|
||||
<DiagSummary busy={diagBusy} reports={diagReports} />
|
||||
</Modal>
|
||||
)}
|
||||
|
||||
{/* 系统环境诊断弹窗(Wave 3.1 Req 7) */}
|
||||
{sysDiagOpen && (
|
||||
<Modal title="系统环境诊断" onClose={() => setSysDiagOpen(false)}>
|
||||
<SystemDiagSummary busy={sysDiagBusy} report={sysDiag} onInstall={setRuntimeInstall} />
|
||||
</Modal>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -559,3 +590,72 @@ function DiagSummary({ busy, reports }: { busy: boolean; reports: DiagnosticRepo
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
/** 系统环境诊断(Wave 3.1 Req 7):每项标注影响哪些 CLI,缺失项带一键安装 */
|
||||
function SystemDiagSummary({
|
||||
busy,
|
||||
report,
|
||||
onInstall,
|
||||
}: {
|
||||
busy: boolean;
|
||||
report: SystemEnvReport | null;
|
||||
onInstall: (runtime: string) => void;
|
||||
}) {
|
||||
if (busy) {
|
||||
return (
|
||||
<p className="panel-empty">
|
||||
<Loader2 size={14} strokeWidth={1.5} className="spin" aria-hidden="true" /> 正在检查系统环境依赖…
|
||||
</p>
|
||||
);
|
||||
}
|
||||
if (!report) return null;
|
||||
const problems = report.findings.filter((f) => f.status !== "installed");
|
||||
const allOk = problems.length === 0;
|
||||
return (
|
||||
<div className="sys-diag">
|
||||
<div className="diag-summary">
|
||||
{allOk ? (
|
||||
<>
|
||||
<span className="status-dot ok" aria-hidden="true" />
|
||||
<span>系统环境依赖完整,无缺失</span>
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
<span className="status-dot warn" aria-hidden="true" />
|
||||
<span>发现 {problems.length} 项环境依赖缺失或版本过低</span>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
{report.findings.map((f) => {
|
||||
const missing = f.status !== "installed";
|
||||
return (
|
||||
<div key={f.runtime_id} className="sys-diag-item">
|
||||
<span className={`status-dot ${missing ? "warn" : "ok"}`} aria-hidden="true" />
|
||||
<div className="sys-diag-main">
|
||||
<div className="sys-diag-head">
|
||||
<span className="sys-diag-name">{f.label_zh}</span>
|
||||
{f.version && <MonoChip>{f.version}</MonoChip>}
|
||||
<span className={`sys-diag-status ${missing ? "warn" : ""}`}>
|
||||
{missing ? "缺失 / 需更新" : "正常"}
|
||||
</span>
|
||||
</div>
|
||||
<p className="sys-diag-msg">{f.message_zh}</p>
|
||||
{f.affected_cli.length > 0 && (
|
||||
<p className="sys-diag-affected">影响:{f.affected_cli.join(" · ")}</p>
|
||||
)}
|
||||
</div>
|
||||
{missing && (
|
||||
<button
|
||||
type="button"
|
||||
className="btn btn-secondary btn-sm"
|
||||
onClick={() => onInstall(f.runtime_id)}
|
||||
>
|
||||
<Download size={13} strokeWidth={1.5} aria-hidden="true" /> 安装
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user