autosnippet 2.16.1 → 2.18.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.
- package/dashboard/dist/assets/index-9byoG7kd.js +129 -0
- package/dashboard/dist/index.html +1 -1
- package/lib/cli/SetupService.js +24 -0
- package/lib/cli/UpgradeService.js +51 -0
- package/lib/external/mcp/handlers/search.js +24 -116
- package/lib/http/routes/search.js +64 -23
- package/lib/service/automation/handlers/SearchHandler.js +95 -6
- package/lib/service/knowledge/KnowledgeService.js +3 -1
- package/lib/service/search/CoarseRanker.js +6 -1
- package/lib/service/search/InvertedIndex.js +4 -16
- package/lib/service/search/MultiSignalRanker.js +6 -1
- package/lib/service/search/SearchEngine.js +213 -25
- package/package.json +1 -1
- package/resources/native-ui/combined-window.swift +5 -5
- package/dashboard/dist/assets/index-Cl1XJniU.js +0 -129
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import{z as aa,j as e,r,l as za,m as la,i as $a,R as It,F as Aa,k as Ma}from"./vendor-Ba1BZjav.js";import{a as $t}from"./axios-C0Zqfgkc.js";import{Z as Qe,L as ra,S as Ea,B as Yt,H as Wt,C as Ta,a as nt,W as La,G as Cs,b as Je,c as et,d as us,e as Ra,f as Da,D as na,g as Jt,P as _a,h as kt,i as ps,j as Pa,k as Fa,l as Oa,F as Tt,m as it,n as ys,o as tt,M as Ct,p as jt,q as Ba,r as Ke,E as Xt,s as qa,t as Ha,U as ia,u as Ga,v as Nt,X as Ye,w as Te,x as yt,R as oa,y as at,z as Ss,A as ca,I as xt,J as Wa,K as da,N as St,O as ht,Q as Ua,T as Zt,V as Ka,Y as Va,_ as xa,$ as Ya,a0 as Ja,a1 as st,a2 as Ut,a3 as mt,a4 as Is,a5 as hs,a6 as Mt,a7 as Qt,a8 as zs,a9 as bt,aa as Bt,ab as Xa,ac as Ds,ad as _s,ae as cs,af as Za,ag as ma,ah as es,ai as ds,aj as Et,ak as vs,al as Kt,am as Qa,an as ua,ao as ws,ap as At,aq as el,ar as pa,as as tl,at as sl,au as al,av as ks,aw as ll,ax as $s,ay as rl,az as nl,aA as il,aB as ol,aC as Ps,aD as Fs,aE as cl,aF as dl,aG as xl,aH as ml,aI as ul}from"./icons-C6kshpB1.js";import{h as ha,o as ba}from"./syntax-highlighter-BkDyUteW.js";import{M as pl}from"./react-markdown-Dc1U8Kko.js";import"./yaml-qRaU8Ldn.js";(function(){const s=document.createElement("link").relList;if(s&&s.supports&&s.supports("modulepreload"))return;for(const n of document.querySelectorAll('link[rel="modulepreload"]'))l(n);new MutationObserver(n=>{for(const c of n)if(c.type==="childList")for(const x of c.addedNodes)x.tagName==="LINK"&&x.rel==="modulepreload"&&l(x)}).observe(document,{childList:!0,subtree:!0});function a(n){const c={};return n.integrity&&(c.integrity=n.integrity),n.referrerPolicy&&(c.referrerPolicy=n.referrerPolicy),n.crossOrigin==="use-credentials"?c.credentials="include":n.crossOrigin==="anonymous"?c.credentials="omit":c.credentials="same-origin",c}function l(n){if(n.ep)return;n.ep=!0;const c=a(n);fetch(n.href,c)}})();const hl="AutoSnippet";function bl(t){if(typeof window>"u"||!("Notification"in window))return;const s=()=>{try{new Notification(hl,{body:t,tag:"autosnippet"})}catch{}};if(Notification.permission==="granted"){s();return}Notification.permission!=="denied"&&Notification.requestPermission().then(a=>{a==="granted"&&s()})}const gl={success:5e3,error:8e3,info:5e3},Os={success:{bg:"linear-gradient(135deg,#ecfdf5 0%,#f0fdf4 100%)",border:"#10b981",bar:"#10b981"},error:{bg:"linear-gradient(135deg,#fef2f2 0%,#fff1f2 100%)",border:"#ef4444",bar:"#ef4444"},info:{bg:"linear-gradient(135deg,#eff6ff 0%,#f0f9ff 100%)",border:"#3b82f6",bar:"#3b82f6"}},fl=()=>e.jsx("svg",{viewBox:"0 0 20 20",fill:"currentColor",className:"w-5 h-5 text-emerald-500 shrink-0",children:e.jsx("path",{fillRule:"evenodd",d:"M10 18a8 8 0 100-16 8 8 0 000 16zm3.857-9.809a.75.75 0 00-1.214-.882l-3.483 4.79-1.88-1.88a.75.75 0 10-1.06 1.061l2.5 2.5a.75.75 0 001.137-.089l4-5.5z",clipRule:"evenodd"})}),jl=()=>e.jsx("svg",{viewBox:"0 0 20 20",fill:"currentColor",className:"w-5 h-5 text-red-400 shrink-0",children:e.jsx("path",{fillRule:"evenodd",d:"M18 10a8 8 0 11-16 0 8 8 0 0116 0zm-8-5a.75.75 0 01.75.75v4.5a.75.75 0 01-1.5 0v-4.5A.75.75 0 0110 5zm0 10a1 1 0 100-2 1 1 0 000 2z",clipRule:"evenodd"})}),ga=()=>e.jsx("svg",{viewBox:"0 0 20 20",fill:"currentColor",className:"w-5 h-5 text-blue-400 shrink-0",children:e.jsx("path",{fillRule:"evenodd",d:"M18 10a8 8 0 11-16 0 8 8 0 0116 0zm-7-4a1 1 0 11-2 0 1 1 0 012 0zM9 9a.75.75 0 000 1.5h.253a.25.25 0 01.244.304l-.459 2.066A1.75 1.75 0 0010.747 15H11a.75.75 0 000-1.5h-.253a.25.25 0 01-.244-.304l.459-2.066A1.75 1.75 0 009.253 9H9z",clipRule:"evenodd"})}),Nl={success:fl,error:jl,info:ga},yl=({visible:t,toastId:s,body:a,type:l,title:n,duration:c})=>{const x=Os[l]||Os.info,i=Nl[l]||ga;return e.jsxs("div",{onClick:()=>aa.dismiss(s),style:{background:x.bg,borderLeft:`4px solid ${x.border}`,borderRadius:10,boxShadow:"0 8px 30px rgba(0,0,0,.12),0 2px 8px rgba(0,0,0,.06)",padding:"12px 16px 10px 14px",display:"flex",alignItems:"flex-start",gap:10,minWidth:280,maxWidth:420,position:"relative",overflow:"hidden",cursor:"pointer",opacity:t?1:0,transform:`translateY(${t?0:-8}px)`,transition:"opacity .25s ease, transform .25s ease"},children:[e.jsx("div",{style:{marginTop:1},children:e.jsx(i,{})}),e.jsxs("div",{style:{flex:1,minWidth:0},children:[n&&e.jsx("div",{style:{fontWeight:600,fontSize:13,lineHeight:1.3,color:"#1e293b",marginBottom:2},children:n}),e.jsx("div",{style:{fontSize:12.5,lineHeight:1.45,color:"#475569",wordBreak:"break-word"},children:a})]}),e.jsx("div",{style:{position:"absolute",bottom:0,left:0,height:3,width:"100%",background:x.bar,opacity:.45,animation:`toast-progress ${c}ms linear forwards`}})]})};function V(t,s){const a=(s==null?void 0:s.type)??"success",l=s==null?void 0:s.title,n=(s==null?void 0:s.duration)??gl[a]??5e3;typeof document<"u"&&document.visibilityState==="visible"?vl(t,a,l,n):bl(l?`${l}: ${t}`:t)}function vl(t,s,a,l){aa.custom(n=>e.jsx(yl,{visible:n.visible,toastId:n.id,body:t,type:s,title:a,duration:l}),{duration:l})}if(typeof document<"u"){const t="asd-toast-progress-style";if(!document.getElementById(t)){const s=document.createElement("style");s.id=t,s.textContent=`
|
|
2
|
+
@keyframes toast-progress {
|
|
3
|
+
from { width: 100%; }
|
|
4
|
+
to { width: 0%; }
|
|
5
|
+
}`,document.head.appendChild(s)}}const Bs={architecture:"架构与设计","best-practice":"规范与实践","event-and-data-flow":"事件与数据流","objc-deep-scan":"深度扫描","agent-guidelines":"Agent 注意事项",bootstrap:"Bootstrap","code-standard":"代码规范","code-pattern":"设计模式","project-profile":"项目特征","category-scan":"Category 分类方法"},lt={All:{icon:kt,color:"text-slate-600",bg:"bg-slate-100",border:"border-slate-200"},View:{icon:_a,color:"text-pink-600",bg:"bg-pink-50",border:"border-pink-100"},Service:{icon:Jt,color:"text-indigo-600",bg:"bg-indigo-50",border:"border-indigo-100"},Tool:{icon:Qe,color:"text-amber-600",bg:"bg-amber-50",border:"border-amber-100"},Model:{icon:na,color:"text-emerald-600",bg:"bg-emerald-50",border:"border-emerald-100"},Network:{icon:Da,color:"text-blue-600",bg:"bg-blue-50",border:"border-blue-100"},Storage:{icon:Ra,color:"text-purple-600",bg:"bg-purple-50",border:"border-purple-100"},UI:{icon:us,color:"text-cyan-600",bg:"bg-cyan-50",border:"border-cyan-100"},Utility:{icon:et,color:"text-orange-600",bg:"bg-orange-50",border:"border-orange-100"},"code-standard":{icon:Je,color:"text-violet-600",bg:"bg-violet-50",border:"border-violet-100"},"code-pattern":{icon:Cs,color:"text-fuchsia-600",bg:"bg-fuchsia-50",border:"border-fuchsia-100"},architecture:{icon:La,color:"text-sky-600",bg:"bg-sky-50",border:"border-sky-100"},"best-practice":{icon:nt,color:"text-emerald-600",bg:"bg-emerald-50",border:"border-emerald-100"},"event-and-data-flow":{icon:Ta,color:"text-amber-600",bg:"bg-amber-50",border:"border-amber-100"},"project-profile":{icon:Wt,color:"text-teal-600",bg:"bg-teal-50",border:"border-teal-100"},"agent-guidelines":{icon:Yt,color:"text-rose-600",bg:"bg-rose-50",border:"border-rose-100"},"objc-deep-scan":{icon:Ea,color:"text-indigo-600",bg:"bg-indigo-50",border:"border-indigo-100"},"category-scan":{icon:ra,color:"text-cyan-600",bg:"bg-cyan-50",border:"border-cyan-100"},bootstrap:{icon:Qe,color:"text-violet-600",bg:"bg-violet-50",border:"border-violet-100"}},wl=["All","View","Service","Tool","Model","Network","Storage","UI","Utility"],kl=["recipes","ai","spm","candidates","knowledge","depgraph","knowledgegraph","guard","skills","wiki","editor","help"],Cl="https://github.com/GxFn/AutoSnippet/issues/new?title=Guard%20误报%2F建议%3A%20&body=请描述误报的规则ID、代码片段或改进建议。",as=t=>["Example","Demo","Sample","Tests","Spec","Mock","Runner"].some(a=>t.endsWith(a)||t.includes(a)),Sl=t=>t.startsWith("_"),Il=t=>t==="_pending",zl="您暂无写入权限,无法保存。如需此权限请联系管理员;请勿擅自修改核心代码或安装包,以免影响团队协作与数据安全。";function xs(t){var n,c;const s=t==null?void 0:t.response;if((s==null?void 0:s.status)!==403)return null;const a=(n=s.data)==null?void 0:n.code,l=(c=s.data)==null?void 0:c.error;return a==="RECIPE_WRITE_FORBIDDEN"||typeof l=="string"&&l.includes("没权限")?zl:null}const $l="保存过于频繁,请稍后再试。";function qs(t){var a;const s=t==null?void 0:t.response;return s!=null&&s.data?s.status===403?xs(t)??null:s.status===429&&((a=s.data)==null?void 0:a.code)==="RECIPE_SAVE_RATE_LIMIT"?$l:null:null}const Q=$t.create({baseURL:"/api/v1"});function Hs(t){const s=t.quality||{},a=t.stats||t.statistics||{},l=t.content||{},n=t.trigger||"@"+(t.title||"").replace(/[\s_-]+(.)?/g,(x,i)=>i?i.toUpperCase():""),c={authority:a.authority||s.overall||0,authorityScore:a.authority||s.overall||0,guardUsageCount:a.applications||0,humanUsageCount:a.adoptions||0,aiUsageCount:0,lastUsedAt:t.updatedAt||null};return{id:t.id,name:(t.title||t.name||t.id)+".md",content:l,category:t.category||"",language:t.language||"",description:t.description||"",status:t.lifecycle||t.status||"pending",kind:t.kind||void 0,knowledgeType:t.knowledgeType||void 0,relations:t.relations||null,constraints:t.constraints||null,tags:t.tags||[],stats:c,trigger:n,source:t.source||"",sourceFile:t.sourceFile||"",moduleName:t.moduleName||"",usageGuide:l.markdown||t.doClause||"",reasoning:t.reasoning||null,quality:t.quality||null,scope:t.scope||"",complexity:t.complexity||"",difficulty:t.difficulty||t.complexity||"",version:t.version||"",headers:t.headers||[],updatedAt:t.updatedAt||null}}function Al(t){let s="swift",a="general",l="",n="",c="",x="",i="",N="",j="",g=[],p=[],u="",w=0,f="1.0.0",E="",A="",M="",R="",B="",T="",U="",K="",S="",q="",C=t;const m=t.match(/^---\n([\s\S]*?)\n---/);if(m){const P=m[1],h=ye=>{const oe=P.match(new RegExp(`^${ye}:\\s*(.+)$`,"m"));return oe?oe[1].trim():null};s=h("language")||s,a=h("category")||a,l=h("title")||l,n=h("trigger")||"",c=h("summary_cn")||h("summary")||h("description")||c,x=h("summary_en")||"",i=h("knowledge_type")||h("knowledgeType")||"",N=h("complexity")||"",j=h("scope")||"",u=h("difficulty")||"",f=h("version")||"1.0.0";const d=h("authority");d&&(w=parseInt(d)||0);const v=h("tags");if(v)try{g=JSON.parse(v)}catch{g=v.split(",").map(ye=>ye.trim()).filter(Boolean)}const k=h("headers");if(k)try{p=JSON.parse(k)}catch{p=[k]}T=h("kind")||"",U=h("doClause")||"",K=h("dontClause")||"",S=h("whenClause")||"",q=h("topicHint")||"";const ee=t.match(/```[\w]*\n([\s\S]*?)```/);ee&&(C=ee[1].trim());const L=t.replace(/^---\n[\s\S]*?\n---/,"").trim(),Z=L.match(/## (?:AI Context \/ )?Usage Guide(?:\s*\(CN\))?\n\n([\s\S]*?)(?=\n## |$)/);Z&&(E=Z[1].trim());const fe=L.match(/## (?:AI Context \/ )?Usage Guide\s*\(EN\)\n\n([\s\S]*?)(?=\n## |$)/);fe&&(A=fe[1].trim());const O=L.match(/## Architecture Usage\n\n([\s\S]*?)(?=\n## |$)/);O&&(M=O[1].trim());const re=L.match(/## Best Practices\n\n([\s\S]*?)(?=\n## |$)/);re&&(R=re[1].trim());const ae=L.match(/## Standards\n\n([\s\S]*?)(?=\n## |$)/);ae&&(B=ae[1].trim())}return{title:l,language:s,category:a,trigger:n,summary:c,summaryEn:x,knowledgeType:i,complexity:N,scope:j,tags:g,headers:p,difficulty:u,authority:w,version:f,codePattern:C,usageGuide:E,usageGuideEn:A,rationaleText:M,bestPracticesText:R,standardsText:B,kind:T,doClause:U,dontClause:K,whenClause:S,topicHint:q}}function Ml(t,s,a){var l;return{code:((l=t.content)==null?void 0:l.pattern)||"",language:t.language||"swift",category:Array.isArray(t.category)?t.category[0]:t.category||s||"general",source:a,reasoning:{whyStandard:t.description||t.title||"Extracted from project",sources:[a],confidence:.6},metadata:{targetName:s||"",title:t.title||"",trigger:t.trigger||"",description:t.description||"",category:Array.isArray(t.category)?t.category[0]:t.category||"",headers:t.headers||[],headerPaths:t.headerPaths||[],moduleName:t.moduleName||"",isMarked:t.isMarked||!1}}}async function zt(t){var c,x,i;const s=t.replace(/\.md$/i,"");if(/^[a-f0-9-]{8,}$/i.test(s))return s;const a=await Q.get("/knowledge?limit=1000"),n=(((x=(c=a.data)==null?void 0:c.data)==null?void 0:x.data)||((i=a.data)==null?void 0:i.data)||[]).find(N=>{const j=N.title||N.name||"";return j===s||j+".md"===t});if(n!=null&&n.id)return n.id;throw new Error(`Knowledge entry not found: ${t}`)}const Y={async fetchData(){var j,g,p,u,w;const[t,s]=await Promise.all([Q.get("/knowledge?limit=1000").catch(()=>({data:{success:!0,data:{data:[]}}})),Q.get("/ai/config").catch(()=>({data:{success:!0,data:{provider:"",model:""}}}))]),a=((g=(j=t.data)==null?void 0:j.data)==null?void 0:g.data)||((u=(p=t.data)==null?void 0:p.data)==null?void 0:u.items)||[],n=a.filter(f=>f.lifecycle==="active").map(Hs),c=a.filter(f=>f.lifecycle==="pending"),x={};for(const f of c){const E=f.category||f.language||"_pending";x[E]||(x[E]={targetName:E,scanTime:f.createdAt,items:[]}),x[E].items.push(f)}const i=((w=s.data)==null?void 0:w.data)||{provider:"",model:""},N={};for(const f of a)f.id&&f.title&&(N[f.id]=f.title);return{rootSpec:{list:[]},recipes:n,candidates:x,projectRoot:"",watcherStatus:"active",aiConfig:{provider:i.provider||"",model:i.model||""},idTitleMap:N}},async fetchTargets(){var a;return(((a=(await Q.get("/spm/targets")).data)==null?void 0:a.data)||{}).targets||[]},async getTargetFiles(t,s){var n,c;const l=((n=(await Q.post("/spm/target-files",{target:t},{signal:s})).data)==null?void 0:n.data)||{};return{files:l.files||[],count:l.total||((c=l.files)==null?void 0:c.length)||0}},async scanTarget(t,s){var c;const l=((c=(await Q.post("/spm/scan",{target:t},{signal:s,timeout:6e5})).data)==null?void 0:c.data)||{};return{recipes:l.recipes||l.result||[],scannedFiles:l.scannedFiles||[],message:l.message||""}},async scanProject(t){var l;const a=((l=(await Q.post("/spm/scan-project",{},{signal:t,timeout:6e5})).data)==null?void 0:l.data)||{};return{targets:a.targets||[],recipes:a.recipes||[],guardAudit:a.guardAudit||null,scannedFiles:a.scannedFiles||[],partial:a.partial||!1}},async bootstrap(t){var l;const a=((l=(await Q.post("/spm/bootstrap",{},{signal:t,timeout:3e5})).data)==null?void 0:l.data)||{};return{report:a.report||{},targets:a.targets||[],filesByTarget:a.filesByTarget||{},dependencyGraph:a.dependencyGraph||null,languageStats:a.languageStats||{},primaryLanguage:a.primaryLanguage||"",guardSummary:a.guardSummary||null,guardViolationFiles:a.guardViolationFiles||[],bootstrapCandidates:a.bootstrapCandidates||{created:0,failed:0},bootstrapSession:a.bootstrapSession||null,asyncFill:a.asyncFill||!1,message:a.message||""}},async getBootstrapStatus(){var s;return((s=(await Q.get("/spm/bootstrap/status")).data)==null?void 0:s.data)||{status:"idle"}},async getDepGraph(t){var a;return((a=(await Q.get(`/spm/dep-graph?level=${t}`)).data)==null?void 0:a.data)||{}},async syncToXcode(){await Q.post("/commands/install")},async refreshProject(){await Q.post("/commands/spm-map")},async extractFromPath(t){var l;const a=((l=(await Q.post("/extract/path",{relativePath:t})).data)==null?void 0:l.data)||{};return{result:a.result||[],isMarked:a.isMarked||!1}},async extractFromText(t,s){var n;const l=((n=(await Q.post("/extract/text",{text:t,...s?{relativePath:s}:{}})).data)==null?void 0:n.data)||{};return Array.isArray(l.result)&&l.result.length>0?l.result[0]:l},async saveRecipe(t,s){const a=Al(s),l=a.title||t.replace(/\.md$/,""),n={trigger:a.trigger,headers:a.headers,difficulty:a.difficulty,authority:a.authority,version:a.version},c={pattern:a.codePattern||"",rationale:a.rationaleText||"",steps:a.bestPracticesText?[a.bestPracticesText]:[],codeChanges:[],verification:null,markdown:a.usageGuide||""},x={};if(a.standardsText){const N=a.standardsText.split(`
|
|
6
|
+
`).map(p=>p.trim()).filter(Boolean),j=N.filter(p=>p.startsWith("- ")).map(p=>p.slice(2).trim());j.length>0&&(x.preconditions=j);const g=N.filter(p=>!p.startsWith("- ")&&!p.startsWith("**"));g.length>0&&(x.boundaries=g)}const i={title:l,language:a.language,category:a.category,description:a.summary,knowledgeType:a.knowledgeType||"code-pattern",complexity:a.complexity||"intermediate",scope:a.scope||null,tags:a.tags||[],content:c,constraints:x,dimensions:n};a.kind&&(i.kind=a.kind),a.doClause&&(i.doClause=a.doClause),a.dontClause&&(i.dontClause=a.dontClause),a.whenClause&&(i.whenClause=a.whenClause),a.topicHint&&(i.topicHint=a.topicHint);try{const N=await zt(t);await Q.patch(`/knowledge/${N}`,i);return}catch{}await Q.post("/knowledge",i)},async deleteRecipe(t){const s=await zt(t);await Q.delete(`/knowledge/${s}`)},async getRecipeByName(t){var c;const s=await zt(t),l=(c=(await Q.get(`/knowledge/${s}`)).data)==null?void 0:c.data;if(!l)throw new Error("Recipe not found");const n=l.content||{};return{name:t,content:n.pattern||n.markdown||""}},async setRecipeAuthority(t,s){const a=await zt(t);await Q.patch(`/knowledge/${a}/quality`,{codeCompleteness:s,projectAdaptation:s,documentationClarity:s})},async updateRecipeRelations(t,s){const a=await zt(t);await Q.patch(`/knowledge/${a}`,{relations:s})},async getCandidate(t){var l;const a=(l=(await Q.get(`/knowledge/${t}`)).data)==null?void 0:l.data;if(!a)throw new Error("Knowledge entry not found");return a},async deleteCandidate(t){await Q.delete(`/knowledge/${t}`)},async promoteCandidateToRecipe(t,s){var n;const l=(n=(await Q.patch(`/knowledge/${t}/publish`)).data)==null?void 0:n.data;return{recipe:l,candidate:l}},async enrichCandidates(t){var a;return((a=(await Q.post("/candidates/enrich",{candidateIds:t})).data)==null?void 0:a.data)||{enriched:0,total:0,results:[]}},async bootstrapRefine(t,s,a){var n;return((n=(await Q.post("/candidates/bootstrap-refine",{candidateIds:t,userPrompt:s,dryRun:a},{timeout:3e5})).data)==null?void 0:n.data)||{refined:0,total:0,errors:[],results:[]}},async refinePreview(t,s){var l;return((l=(await Q.post("/candidates/refine-preview",{candidateId:t,userPrompt:s},{timeout:12e4})).data)==null?void 0:l.data)||{}},async refineApply(t,s){var l;return((l=(await Q.post("/candidates/refine-apply",{candidateId:t,userPrompt:s},{timeout:12e4})).data)==null?void 0:l.data)||{}},async getKnowledgeGraph(t=500){var a;return((a=(await Q.get(`/search/graph/all?limit=${t}`)).data)==null?void 0:a.data)||{edges:[],nodeLabels:{},nodeTypes:{},nodeCategories:{}}},async getGraphStats(){var s;return((s=(await Q.get("/search/graph/stats")).data)==null?void 0:s.data)||{totalEdges:0,byRelation:{},nodeTypes:[]}},async discoverRelations(t=20){var a,l,n,c;const s=await Q.post("/recipes/discover-relations",{batchSize:t});if(!((a=s.data)!=null&&a.success))throw new Error(((n=(l=s.data)==null?void 0:l.error)==null?void 0:n.message)||"启动失败");return((c=s.data)==null?void 0:c.data)||{status:"unknown"}},async getDiscoverRelationsStatus(){var s;return((s=(await Q.get("/recipes/discover-relations/status")).data)==null?void 0:s.data)||{status:"idle"}},async deleteAllCandidatesInTarget(t){var n,c;const a=((c=(n=(await Q.get(`/knowledge?category=${encodeURIComponent(t)}&limit=1000`)).data)==null?void 0:n.data)==null?void 0:c.data)||[];let l=0;for(const x of a)try{await Q.delete(`/knowledge/${x.id}`),l++}catch{}return{deleted:l}},async promoteToCandidate(t,s){var n,c;const a=Ml(t,s,"review-promote");return{ok:!0,candidateId:((c=(n=(await Q.post("/knowledge",a)).data)==null?void 0:n.data)==null?void 0:c.id)||""}},async getCandidateSimilarity(t,s){var l;return((l=(await Q.post("/search/similarity",{code:t,language:s}).catch(()=>({data:{data:{similar:[]}}}))).data)==null?void 0:l.data)||{similar:[]}},async getCandidateSimilarityEx(t){var a;return((a=(await Q.post("/search/similarity",t).catch(()=>({data:{data:{similar:[]}}}))).data)==null?void 0:a.data)||{similar:[]}},async getRecipeContentByName(t){var i;const s=await zt(t),l=(i=(await Q.get(`/knowledge/${s}`)).data)==null?void 0:i.data;if(!l)throw new Error("Recipe not found");const c=Hs(l).content,x=[c==null?void 0:c.pattern,c==null?void 0:c.markdown].filter(Boolean).join(`
|
|
7
|
+
|
|
8
|
+
`)||"";return{name:t,content:x}},async getAiProviders(){var s;return((s=(await Q.get("/ai/providers")).data)==null?void 0:s.data)||[]},async setAiConfig(t,s){var l;return((l=(await Q.post("/ai/config",{provider:t,model:s})).data)==null?void 0:l.data)||{provider:t,model:s}},async chat(t,s,a){var c;const n=((c=(await Q.post("/ai/chat",{prompt:t,history:s},{signal:a})).data)==null?void 0:c.data)||{};return{text:n.reply||n.text||"",hasContext:n.hasContext}},async summarizeCode(t,s){var l;const a=await Q.post("/ai/summarize",{code:t,language:s});return((l=a.data)==null?void 0:l.data)||a.data||{}},async translate(t,s){var n,c;const a=await Q.post("/ai/translate",{summary:t,usageGuide:s}),l=((n=a.data)==null?void 0:n.data)||{summaryEn:"",usageGuideEn:""};return(c=a.data)!=null&&c.warning&&(l.warning=a.data.warning),l},async search(t,s={}){var u,w;const{mode:a="bm25",type:l,limit:n=20,signal:c,context:x}=s,i=f=>{if(!f)return{};if(typeof f=="object")return f;try{return JSON.parse(f)}catch{return{markdown:f}}};if(x){const E=((u=(await Q.post("/search/context-aware",{keyword:t,limit:n,language:x.language,sessionHistory:x.sessionHistory||[]},{signal:c}).catch(()=>({data:{data:{}}}))).data)==null?void 0:u.data)||{},A=(E.results||[]).map(M=>{const R=i(M.content);return{title:(M.name||"").replace(/\.md$/,""),content:R,score:M.similarity||0,qualityScore:M.qualityScore||0,usageCount:M.usageCount||0,authorityScore:M.authority||0,matchType:M.matchType}});return{items:A,total:E.total||A.length,mode:"bm25",ranked:!0}}const N=new URLSearchParams({q:t,mode:a,limit:String(n)});l&&N.set("type",l);const g=((w=(await Q.get(`/search?${N}`,{signal:c})).data)==null?void 0:w.data)||{},p=(g.items||[]).map(f=>({...f,content:i(f.content)}));return{items:p,total:g.totalResults||g.total||p.length,mode:g.mode,ranked:g.ranked}},async semanticSearch(t,s=10){return(await this.search(t,{mode:"semantic",limit:s})).items.map(l=>{var n,c,x;return{name:(l.title||l.name||"")+".md",content:((n=l.content)==null?void 0:n.pattern)||((c=l.content)==null?void 0:c.markdown)||((x=l.content)==null?void 0:x.code)||"",similarity:l.score||0,metadata:{type:"recipe",name:(l.title||l.name||"")+".md"}}})},async contextAwareSearch(t){var a;return((a=(await Q.post("/search/context-aware",t).catch(()=>({data:{data:{}}}))).data)==null?void 0:a.data)||{}},async xcodeSimulateSearch(t){var a;return((a=(await Q.post("/search/xcode-simulate",t).catch(()=>({data:{data:{}}}))).data)==null?void 0:a.data)||{}},async getGuardRules(){var n;const s=((n=(await Q.get("/rules?limit=100")).data)==null?void 0:n.data)||{},a=s.data||s.items||[],l={};for(const c of a)l[c.id]=c;return{rules:l}},async getGuardViolations(){var a;const s=((a=(await Q.get("/violations")).data)==null?void 0:a.data)||{};return{runs:s.data||s.items||[]}},async clearViolations(){await Q.post("/violations/clear")},async generateGuardRule(t){var a;return((a=(await Q.post("/violations/rules/generate",t)).data)==null?void 0:a.data)||{}},async saveGuardRule(t){var a;return((a=(await Q.post("/rules",t)).data)==null?void 0:a.data)||{}},async insertAtSearchMark(t){return{success:!1}},async searchRecipesForModal(t,s){const a=await this.search(t,{mode:"bm25",type:"recipe",signal:s});return{results:a.items.map(l=>({name:(l.title||l.name||"")+".md",path:"",content:l.content,qualityScore:(l.quality||{}).overall||l.qualityScore||0,recommendReason:""})),total:a.total}},async listSkills(){var s;return((s=(await Q.get("/skills")).data)==null?void 0:s.data)||{skills:[],total:0}},async loadSkill(t,s){var n;const a=s?`?section=${encodeURIComponent(s)}`:"";return((n=(await Q.get(`/skills/${encodeURIComponent(t)}${a}`)).data)==null?void 0:n.data)||{}},async createSkill(t){var a;return((a=(await Q.post("/skills",t)).data)==null?void 0:a.data)||{}},async updateSkill(t,s){var l;return((l=(await Q.put(`/skills/${encodeURIComponent(t)}`,s)).data)==null?void 0:l.data)||{}},async deleteSkill(t){var a;return((a=(await Q.delete(`/skills/${encodeURIComponent(t)}`)).data)==null?void 0:a.data)||{}},async suggestSkills(){var s;return((s=(await Q.get("/skills/suggest")).data)==null?void 0:s.data)||{suggestions:[],analysisContext:{}}},async getSignalStatus(){var s;return((s=(await Q.get("/skills/signal-status")).data)==null?void 0:s.data)||{running:!1,mode:"off",snapshot:null}},async aiGenerateSkill(t){var l;return((l=(await Q.post("/ai/chat",{prompt:`你是一个 AutoSnippet Skill 文档生成助手。用户会描述他们想创建的 Skill,你需要生成完整的 SKILL.md 内容。
|
|
9
|
+
|
|
10
|
+
Skill 文档格式要求:
|
|
11
|
+
1. 开头用 Markdown 标题说明 Skill 的目的
|
|
12
|
+
2. 包含清晰的使用场景说明
|
|
13
|
+
3. 列出具体的操作步骤和指南
|
|
14
|
+
4. 如有必要,包含代码示例
|
|
15
|
+
5. 使用中文撰写
|
|
16
|
+
|
|
17
|
+
请严格按以下格式输出(不要用代码块包裹 JSON):
|
|
18
|
+
|
|
19
|
+
第一行:一个 JSON 对象,包含 name(kebab-case,3-64 字符)和 description(一句话中文描述)
|
|
20
|
+
第二行:空行
|
|
21
|
+
第三行起:Skill 文档正文内容(Markdown 格式,不含 frontmatter)
|
|
22
|
+
|
|
23
|
+
示例输出:
|
|
24
|
+
{"name": "swiftui-animation-guide", "description": "SwiftUI 动画最佳实践指南"}
|
|
25
|
+
|
|
26
|
+
# SwiftUI 动画最佳实践
|
|
27
|
+
|
|
28
|
+
## 使用场景
|
|
29
|
+
...
|
|
30
|
+
|
|
31
|
+
用户需求:${t}`,history:[]})).data)==null?void 0:l.data)||{reply:""}},async getLlmEnvConfig(){var s;return((s=(await Q.get("/ai/env-config")).data)==null?void 0:s.data)||{vars:{},hasEnvFile:!1,llmReady:!1}},async getTokenUsage7Days(){var s;return((s=(await Q.get("/ai/token-usage")).data)==null?void 0:s.data)||{daily:[],bySource:[],summary:{input_tokens:0,output_tokens:0,total_tokens:0,call_count:0,avg_per_call:0}}},async saveLlmEnvConfig(t){var a;return((a=(await Q.post("/ai/env-config",t)).data)==null?void 0:a.data)||{vars:{},hasEnvFile:!1,llmReady:!1}},async knowledgeList(t={}){var n;const s=new URLSearchParams;t.page&&s.set("page",String(t.page)),t.limit&&s.set("limit",String(t.limit)),t.lifecycle&&s.set("lifecycle",t.lifecycle),t.kind&&s.set("kind",t.kind),t.category&&s.set("category",t.category),t.language&&s.set("language",t.language),t.keyword&&s.set("keyword",t.keyword),t.tag&&s.set("tag",t.tag),t.source&&s.set("source",t.source);const a=s.toString();return((n=(await Q.get(`/knowledge${a?`?${a}`:""}`)).data)==null?void 0:n.data)||{data:[],pagination:{page:1,pageSize:20,total:0}}},async knowledgeStats(){var s;return((s=(await Q.get("/knowledge/stats")).data)==null?void 0:s.data)||{total:0,pending:0,active:0,deprecated:0,rules:0,patterns:0,facts:0}},async knowledgeGet(t){var a;return(a=(await Q.get(`/knowledge/${t}`)).data)==null?void 0:a.data},async knowledgeCreate(t){var a;return(a=(await Q.post("/knowledge",t)).data)==null?void 0:a.data},async knowledgeUpdate(t,s){var l;return(l=(await Q.patch(`/knowledge/${t}`,s)).data)==null?void 0:l.data},async knowledgeDelete(t){await Q.delete(`/knowledge/${t}`)},async knowledgeLifecycle(t,s,a){var n;return(n=(await Q.patch(`/knowledge/${t}/${s}`,a?{reason:a}:{})).data)==null?void 0:n.data},async knowledgeBatchPublish(t){var a;return((a=(await Q.post("/knowledge/batch-publish",{ids:t})).data)==null?void 0:a.data)||{published:[],failed:[],successCount:0,failureCount:0}},async knowledgeRecordUsage(t,s="adoption",a){await Q.post(`/knowledge/${t}/usage`,{type:s,feedback:a})},async knowledgeUpdateQuality(t){var a;return((a=(await Q.patch(`/knowledge/${t}/quality`)).data)==null?void 0:a.data)||{quality:{}}},async wikiGenerate(){await Q.post("/wiki/generate")},async wikiUpdate(){await Q.post("/wiki/update")},async wikiAbort(){await Q.post("/wiki/abort")},async wikiStatus(){var s;return((s=(await Q.get("/wiki/status")).data)==null?void 0:s.data)||{task:{status:"idle"}}},async wikiFiles(){var s;return((s=(await Q.get("/wiki/files")).data)==null?void 0:s.data)||{files:[],exists:!1}},async wikiFileContent(t){var a;return((a=(await Q.get(`/wiki/file/${t}`)).data)==null?void 0:a.data)||{path:t,content:"",size:0}}},El=!1,bs="auth_token",gs="auth_user";function Tl(){const[t,s]=r.useState(()=>localStorage.getItem(bs)),[a,l]=r.useState(()=>{try{const j=localStorage.getItem(gs);return j?JSON.parse(j):null}catch{return null}}),[n,c]=r.useState(!1),x=r.useCallback(async(j,g)=>{var p,u,w,f;c(!0);try{const A=(await $t.post("/api/v1/auth/login",{username:j,password:g})).data;if(A.success){const M=A.data.token,R=A.data.user??{username:j,role:"developer"};return localStorage.setItem(bs,M),localStorage.setItem(gs,JSON.stringify(R)),s(M),l(R),{success:!0}}return{success:!1,error:((p=A.error)==null?void 0:p.message)||"登录失败"}}catch(E){return{success:!1,error:((f=(w=(u=E.response)==null?void 0:u.data)==null?void 0:w.error)==null?void 0:f.message)||E.message||"网络错误"}}finally{c(!1)}},[]),i=r.useCallback(()=>{localStorage.removeItem(bs),localStorage.removeItem(gs),s(null),l(null)},[]);r.useEffect(()=>{},[]);const N=r.useMemo(()=>!0,[t,a]);return{authEnabled:El,isAuthenticated:N,isLoading:n,user:a,login:x,logout:i}}const Ll={developer:["*"],external_agent:["read:recipes","read:guard_rules","create:candidates","submit:knowledge","read:audit_logs:self","knowledge:bootstrap"],chat_agent:["read:recipes","read:candidates","create:candidates","read:guard_rules"]};function Rl(t){const[s,a]=r.useState(()=>"developer"),[l,n]=r.useState("anonymous"),[c,x]=r.useState("probe"),[i,N]=r.useState(!0),[j,g]=r.useState(null),p=r.useCallback(async()=>{N(!0);try{const A=localStorage.getItem("auth_token"),M={};A&&(M.Authorization=`Bearer ${A}`);const R=await $t.get("/api/v1/auth/probe",{headers:M});if(R.data.success){const B=R.data.data;a(B.role),n(B.user),x(B.mode),g(B.probeCache??null)}}catch{a("developer")}finally{N(!1)}},[]);r.useEffect(()=>{p()},[t,p]);const u=r.useCallback((A,M)=>{const R=Ll[s]||[];if(R.includes("*"))return!0;const B=M?`${A}:${M}`:A;if(R.includes(B))return!0;const T=A.split(":")[0];return!!(R.includes(`${T}:*`)||T==="read"&&R.includes("read:*"))},[s]),w=r.useMemo(()=>s==="developer",[s]),f=r.useMemo(()=>s==="developer",[s]),E=r.useMemo(()=>s!=="developer",[s]);return{role:s,user:l,mode:c,isLoading:i,isAdmin:w,canWrite:f,isReadOnly:E,can:u,probeCache:j,refresh:p}}let Rt=null;function As(){return Rt||(Rt=za(window.location.origin,{path:"/socket.io",transports:["websocket"],reconnection:!0,reconnectionAttempts:1/0,reconnectionDelay:2e3,reconnectionDelayMax:1e4}),Rt.on("connect",()=>{Rt.emit("join-notifications")})),Rt}const fs={activeRound:0,round1:{status:"idle"},round2:{status:"idle"},round3:{status:"idle"}};function Dl(){const[t,s]=r.useState(null),[a,l]=r.useState(!1),[n,c]=r.useState(fs),x=r.useRef(null),i=r.useRef(null);r.useEffect(()=>{const p=As(),u=()=>{l(!0),i.current&&clearTimeout(i.current),i.current=setTimeout(()=>f(),500)},w=()=>l(!1),f=async()=>{try{const h=await Y.getBootstrapStatus();h&&h.status==="running"&&h.tasks&&s(d=>!d||d.id===h.id||h.progress>((d==null?void 0:d.progress)??0)?(x.current=h.id,h):d)}catch{}},E=()=>f(),A=h=>{x.current=h.sessionId,c(fs),s({id:h.sessionId,status:"running",progress:0,total:h.total,completed:0,failed:0,filling:0,skeleton:h.total,startedAt:h.startedAt||Date.now(),totalToolCalls:0,elapsedMs:0,tasks:h.tasks.map(d=>({id:d.id,status:"skeleton",meta:{type:d.type,dimId:d.dimId,label:d.label,skillWorthy:d.skillWorthy,skillMeta:d.skillMeta}}))})},M=h=>{s(d=>{if(!d)return d;const v=d.tasks.map(k=>k.id===h.taskId?{...k,status:"filling",startedAt:Date.now()}:k);return{...d,progress:h.progress,tasks:v,filling:v.filter(k=>k.status==="filling").length,skeleton:v.filter(k=>k.status==="skeleton").length}})},R=h=>{s(d=>{if(!d)return d;const v=d.tasks.map(k=>k.id===h.taskId?{...k,status:"completed",completedAt:Date.now(),result:h.result}:k);return{...d,progress:h.progress,completed:h.completed,total:h.total,totalToolCalls:h.totalToolCalls??d.totalToolCalls,elapsedMs:h.elapsedMs??d.elapsedMs,tasks:v,filling:v.filter(k=>k.status==="filling").length,skeleton:v.filter(k=>k.status==="skeleton").length}})},B=h=>{s(d=>{if(!d)return d;const v=d.tasks.map(k=>k.id===h.taskId?{...k,status:"failed",completedAt:Date.now(),error:h.error}:k);return{...d,progress:h.progress,failed:v.filter(k=>k.status==="failed").length,tasks:v,filling:v.filter(k=>k.status==="filling").length,skeleton:v.filter(k=>k.status==="skeleton").length}})},T=h=>{s(d=>{if(!d||h.sessionId&&d.id!==h.sessionId)return d;const v=d.tasks.map(k=>k.status==="skeleton"||k.status==="filling"?{...k,status:"completed",completedAt:Date.now()}:k);return{...d,status:v.some(k=>k.status==="failed")?"completed_with_errors":"completed",progress:100,completed:v.filter(k=>k.status==="completed").length,summary:h.summary,tasks:v,filling:0,skeleton:0}})},U=h=>{c(d=>({...d,activeRound:1,round1:{status:"running",total:h.total}}))},K=h=>{c(d=>({...d,activeRound:1,round1:{status:"completed",total:h.total,kept:h.kept,dropped:h.dropped,merged:h.merged}}))},S=h=>{c(d=>({...d,activeRound:2,round2:{status:"running",total:h.total}}))},q=h=>{c(d=>({...d,activeRound:2,round2:{...d.round2,status:"running",current:h.current,total:h.total,progress:h.progress}}))},C=h=>{c(d=>({...d,activeRound:2,round2:{status:"completed",total:h.total,refined:h.refined,progress:100}}))},m=h=>{c(d=>({...d,activeRound:3,round3:{status:"running",total:h.total}}))},P=h=>{c(d=>({...d,activeRound:3,round3:{status:"completed",total:h.total,afterDedup:h.afterDedup,relationsFound:h.relationsFound}}))};return p.on("connect",u),p.on("disconnect",w),p.io.on("reconnect",E),p.on("bootstrap:started",A),p.on("bootstrap:task-started",M),p.on("bootstrap:task-completed",R),p.on("bootstrap:task-failed",B),p.on("bootstrap:all-completed",T),p.on("review:round1-started",U),p.on("review:round1-completed",K),p.on("review:round2-started",S),p.on("review:round2-progress",q),p.on("review:round2-completed",C),p.on("review:round3-started",m),p.on("review:round3-completed",P),l(p.connected),p.connected&&f(),()=>{i.current&&clearTimeout(i.current),p.off("connect",u),p.off("disconnect",w),p.io.off("reconnect",E),p.off("bootstrap:started",A),p.off("bootstrap:task-started",M),p.off("bootstrap:task-completed",R),p.off("bootstrap:task-failed",B),p.off("bootstrap:all-completed",T),p.off("review:round1-started",U),p.off("review:round1-completed",K),p.off("review:round2-started",S),p.off("review:round2-progress",q),p.off("review:round2-completed",C),p.off("review:round3-started",m),p.off("review:round3-completed",P)}},[]);const N=r.useCallback(()=>{x.current=null,s(null),c(fs)},[]),j=r.useCallback(p=>{p&&s(u=>{if(u&&u.id===p.id){const w=(u.filling??0)+(u.completed??0)+(u.failed??0),f=(p.filling??0)+(p.completed??0)+(p.failed??0);if(u.progress>p.progress||w>f)return u}return x.current=p.id,p})},[]),g=(t==null?void 0:t.status)==="completed"||(t==null?void 0:t.status)==="completed_with_errors";return{session:t,isConnected:a,isAllDone:g,reviewState:n,resetSession:N,initFromApiResponse:j}}const $={xs:12,sm:14,md:16,lg:20,xl:24,xxl:32,xxxl:48},Gs={developer:{label:"开发者",color:"text-emerald-700",bg:"bg-emerald-50 border-emerald-200"},external_agent:{label:"Agent",color:"text-purple-700",bg:"bg-purple-50 border-purple-200"},chat_agent:{label:"ChatAgent",color:"text-blue-700",bg:"bg-blue-50 border-blue-200"}},_l={token:qa,probe:Xt},Pl=({activeTab:t,navigateToTab:s,candidateCount:a,signalSuggestionCount:l=0,isDarkMode:n=!1,currentUser:c,currentRole:x,permissionMode:i,onLogout:N,collapsed:j=!1,onToggleCollapse:g})=>{const p=Gs[x||""]||Gs.developer,u=_l[i||"probe"]||Xt,[w,f]=r.useState(null),E=r.useCallback(()=>{Y.getTokenUsage7Days().then(B=>f(B.summary)).catch(()=>{})},[]);r.useEffect(()=>{E();const B=As(),T=()=>E();return B.on("candidate-created",T),B.on("bootstrap:all-completed",T),B.on("token-usage-updated",T),()=>{B.off("candidate-created",T),B.off("bootstrap:all-completed",T),B.off("token-usage-updated",T)}},[E]);const A=[{tab:"recipes",icon:Oa,label:"Recipes"},{tab:"spm",icon:Tt,label:"SPM Explorer"},{tab:"candidates",icon:it,label:`Candidates (${a})`},{tab:"knowledge",icon:ra,label:"批量管理"},{tab:"depgraph",icon:Cs,label:"依赖关系图"},{tab:"knowledgegraph",icon:ys,label:"知识图谱"},{tab:"guard",icon:nt,label:"Guard"},{tab:"skills",icon:Je,label:"Skills",badge:l>0?l:void 0,badgeColor:"bg-amber-100 text-amber-700"},{tab:"wiki",icon:tt,label:"Repo Wiki"},{tab:"ai",icon:Ct,label:"AI Assistant"},{tab:"editor",icon:jt,label:"编辑器(测试)"},{tab:"help",icon:Ba,label:"使用说明"}],M=n?"bg-blue-900/30 text-blue-400 font-medium":"bg-blue-50 text-blue-700 font-medium",R=n?"text-slate-300 hover:bg-slate-700/50":"text-slate-600 hover:bg-slate-50";return e.jsxs("aside",{className:`${j?"w-16":"w-64"} ${n?"bg-[#252526] border-r border-[#3e3e42]":"bg-white border-r border-slate-200"} flex flex-col shrink-0 transition-all duration-200`,children:[e.jsxs("div",{className:`${j?"px-3 py-4":"p-6"} border-b ${n?"border-[#3e3e42]":"border-slate-100"} flex items-center ${j?"justify-center":"justify-between"}`,children:[e.jsxs("div",{className:"flex items-center gap-3 min-w-0",children:[e.jsx("div",{className:"w-8 h-8 bg-blue-600 rounded-lg flex items-center justify-center text-white shrink-0",children:e.jsx(ps,{size:$.lg})}),!j&&e.jsx("h1",{className:"font-bold text-lg truncate",children:"AutoSnippet"})]}),g&&!j&&e.jsx("button",{onClick:g,className:`p-1 rounded-md transition-colors ${n?"text-slate-500 hover:text-slate-300 hover:bg-slate-700/50":"text-slate-400 hover:text-slate-600 hover:bg-slate-100"}`,title:"折叠导航",children:e.jsx(Pa,{size:16})})]}),j&&g&&e.jsx("div",{className:"flex justify-center py-2",children:e.jsx("button",{onClick:g,className:`p-1.5 rounded-md transition-colors ${n?"text-slate-500 hover:text-slate-300 hover:bg-slate-700/50":"text-slate-400 hover:text-slate-600 hover:bg-slate-100"}`,title:"展开导航",children:e.jsx(Fa,{size:16})})}),e.jsx("nav",{className:`flex-1 ${j?"px-2 py-2":"p-4"} space-y-1 overflow-y-auto scrollbar-light`,children:A.map(({tab:B,icon:T,label:U,badge:K,badgeColor:S})=>e.jsxs("button",{type:"button",onClick:()=>s(B),title:j?U:void 0,className:`w-full flex items-center ${j?"justify-center px-2 py-2.5 relative":"gap-3 px-4 py-2"} rounded-lg transition-colors ${t===B?M:R}`,children:[e.jsx(T,{size:$.lg,className:"shrink-0"}),!j&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"flex-1 text-left truncate text-[13px]",children:U}),K!=null&&e.jsxs("span",{className:`flex items-center gap-0.5 px-1.5 py-0.5 rounded-full text-[10px] font-bold ${S||"bg-blue-100 text-blue-700"}`,children:[e.jsx(Ke,{size:10}),K]})]}),j&&K!=null&&e.jsx("span",{className:"absolute top-0 right-0 w-2 h-2 rounded-full bg-amber-400"})]},B))}),e.jsx("div",{className:`${j?"px-2 py-3":"p-4"} ${n?"border-t border-[#3e3e42]":"border-t border-slate-100"}`,children:!j&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:`flex items-center gap-1.5 mb-3 px-2 py-1.5 rounded-lg border text-[10px] font-bold uppercase tracking-wider ${n?"bg-slate-700/30 border-slate-600 text-slate-400":p.bg+" "+p.color}`,children:[e.jsx(u,{size:$.xs}),e.jsx("span",{children:i==="token"?"登录":"探针"}),e.jsx("span",{className:"mx-0.5",children:"·"}),e.jsx(Ha,{size:$.xs}),e.jsx("span",{children:p.label})]}),c&&e.jsxs("div",{className:`flex items-center justify-between mb-3 px-2 py-1.5 rounded-lg ${n?"bg-slate-700/30":"bg-slate-50"}`,children:[e.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[e.jsx(ia,{size:$.sm,className:n?"text-slate-400":"text-slate-500"}),e.jsx("span",{className:`text-xs font-medium truncate ${n?"text-slate-300":"text-slate-600"}`,children:c})]}),N&&e.jsx("button",{onClick:N,title:"登出",className:`shrink-0 p-1 rounded transition-colors ${n?"text-slate-500 hover:text-red-400 hover:bg-slate-700/50":"text-slate-400 hover:text-red-500 hover:bg-red-50"}`,children:e.jsx(Ga,{size:$.sm})})]})]})})]})},Fl={objectivec:"objectivec",objc:"objectivec","objective-c":"objectivec","obj-c":"objectivec",swift:"swift",markdown:"markdown",md:"markdown"};function Ms(t){if(!t)return t;let s=t;!s.includes(`
|
|
32
|
+
`)&&s.includes("\\n")&&(s=s.replace(/\\n/g,`
|
|
33
|
+
`));const a=s.match(/\\(?=[\[\]{}()*+?^$.|])/g);return a&&a.length>=3&&(s=s.replace(/\\([\[\]{}()*+?^$.|])/g,"$1")),s}const rt=({code:t,language:s="text",className:a="",showLineNumbers:l=!1})=>{const n=Fl[s==null?void 0:s.toLowerCase()]||(s==null?void 0:s.toLowerCase())||"text",c=a.includes("!rounded-none"),x=Ms(t);return e.jsx("div",{className:`rounded-xl overflow-x-auto text-sm min-w-0 ${a}`,children:e.jsx(ha,{language:n,style:ba,showLineNumbers:l,customStyle:{margin:0,padding:"1rem 1.25rem",fontSize:"0.8125rem",lineHeight:1.5,borderRadius:c?0:"0.75rem",overflowX:"auto"},codeTagProps:{className:"language-highlighted",style:{fontFamily:"ui-monospace, monospace"}},PreTag:"div",children:x})})};let Ws=!1,Ol=0;function Bl(){Ws||(la.initialize({startOnLoad:!1,theme:"default",securityLevel:"loose",fontFamily:"ui-sans-serif, system-ui, -apple-system, sans-serif"}),Ws=!0)}const fa=({code:t})=>{const[s,a]=r.useState(""),[l,n]=r.useState("");return r.useEffect(()=>{let c=!1;const x=`mermaid_${Ol++}`;async function i(){var N;Bl();try{const{svg:j}=await la.render(x,t.trim());c||(a(j),n(""))}catch(j){c||(n((j==null?void 0:j.message)||"Mermaid render failed"),a(""));try{(N=document.getElementById("d"+x))==null||N.remove()}catch{}}}return i(),()=>{c=!0}},[t]),l?e.jsx("div",{className:"my-4 p-4 bg-slate-800 text-slate-200 rounded-lg overflow-x-auto text-sm font-mono whitespace-pre-wrap",children:t}):s?e.jsx("div",{className:"my-5 flex justify-center overflow-x-auto rounded-lg border border-slate-200 bg-white p-4",dangerouslySetInnerHTML:{__html:s}}):e.jsx("div",{className:"my-4 flex items-center justify-center py-8 text-slate-400 text-sm",children:"渲染图表中…"})};function Es(t){return!t||typeof t!="string"?t:t.replace(/^---\r?\n[\s\S]*?\r?\n---\r?\n?/,"").trim()||t}function ql(t){return!t||typeof t!="string"?t:t.replace(/\\\\n/g,`
|
|
34
|
+
`)}function Hl(t){if(!t||typeof t!="string")return t;const s=t.split(`
|
|
35
|
+
`),a=[];let l=!1;for(let n=0;n<s.length;n++){const c=s[n];if(/^\s*(`{3,}|~{3,})/.test(c)){l=!l,a.push(c);continue}if(l){a.push(c);continue}const x=s[n+1];c!==""&&x!==void 0&&x!==""?a.push(c+" "):a.push(c)}return a.join(`
|
|
36
|
+
`)}const Gl=/^\s*(graph|flowchart|sequenceDiagram|classDiagram|stateDiagram|erDiagram|gantt|pie|gitGraph|mindmap|timeline|journey|quadrantChart|sankey|xychart|block)\b/i;function Wl(t){const s=[],a=t.split(`
|
|
37
|
+
`);let l=[],n=!1,c=!1,x=[];for(let i=0;i<a.length;i++){const N=a[i],j=/^\s*(`{3,}|~{3,})(.*)$/.exec(N);if(j&&!c&&!n)if(j[2].trim().toLowerCase()==="mermaid"){l.length>0&&(s.push({type:"markdown",content:l.join(`
|
|
38
|
+
`)}),l=[]),n=!0,x=[];continue}else{c=!0,l.push(N);continue}if(n&&j){s.push({type:"mermaid",content:x.join(`
|
|
39
|
+
`)}),n=!1,x=[];continue}if(c&&j){c=!1,l.push(N);continue}n?x.push(N):l.push(N)}return n&&x.length>0&&s.push({type:"mermaid",content:x.join(`
|
|
40
|
+
`)}),l.length>0&&s.push({type:"markdown",content:l.join(`
|
|
41
|
+
`)}),s}const Ul=t=>({pre({children:s}){return e.jsx("div",{className:"min-w-0",children:s})},code({node:s,className:a,children:l,...n}){const c=/language-(\w+)/.exec(a||""),x=Array.isArray(l)?l.join(""):String(l),i=x.replace(/\n$/,""),N=x.includes(`
|
|
42
|
+
`)||!!c;return N&&Gl.test(i)?e.jsx(fa,{code:i}):N&&c?e.jsx(rt,{code:i,language:c[1],showLineNumbers:t}):N?e.jsx(rt,{code:i,language:"text",showLineNumbers:t}):e.jsx("code",{className:"px-1.5 py-0.5 bg-slate-100 text-slate-800 rounded text-[0.9em] font-mono border border-slate-200/60",...n,children:l})},p:({children:s})=>e.jsx("p",{className:"mb-4 leading-7 last:mb-0",children:s}),h1:({children:s,...a})=>{const l=typeof s=="string"?s.toLowerCase().replace(/[^a-z0-9\u4e00-\u9fff]+/g,"-").replace(/(^-|-$)/g,""):void 0;return e.jsx("h1",{id:l,className:"text-[1.75rem] font-bold mb-4 mt-8 first:mt-0 pb-2 border-b border-slate-200/70 text-slate-900 leading-tight scroll-mt-20",...a,children:s})},h2:({children:s,...a})=>{const l=typeof s=="string"?s.toLowerCase().replace(/[^a-z0-9\u4e00-\u9fff]+/g,"-").replace(/(^-|-$)/g,""):void 0;return e.jsx("h2",{id:l,className:"text-xl font-bold mb-3 mt-8 pb-1.5 border-b border-slate-100 text-slate-800 leading-snug scroll-mt-20",...a,children:s})},h3:({children:s,...a})=>{const l=typeof s=="string"?s.toLowerCase().replace(/[^a-z0-9\u4e00-\u9fff]+/g,"-").replace(/(^-|-$)/g,""):void 0;return e.jsx("h3",{id:l,className:"text-lg font-semibold mb-2 mt-6 text-slate-800 leading-snug scroll-mt-20",...a,children:s})},h4:({children:s,...a})=>{const l=typeof s=="string"?s.toLowerCase().replace(/[^a-z0-9\u4e00-\u9fff]+/g,"-").replace(/(^-|-$)/g,""):void 0;return e.jsx("h4",{id:l,className:"text-base font-semibold mb-2 mt-5 text-slate-700 scroll-mt-20",...a,children:s})},strong:({children:s})=>e.jsx("strong",{className:"font-semibold text-slate-900",children:s}),em:({children:s})=>e.jsx("em",{className:"italic text-slate-600",children:s}),del:({children:s})=>e.jsx("del",{className:"line-through text-slate-400",children:s}),hr:()=>e.jsx("hr",{className:"my-8 border-0 h-px bg-slate-200"}),ul:({children:s})=>e.jsx("ul",{className:"list-disc pl-6 mb-4 space-y-1.5 marker:text-slate-400",children:s}),ol:({children:s})=>e.jsx("ol",{className:"list-decimal pl-6 mb-4 space-y-1.5 marker:text-slate-500",children:s}),li:({children:s,...a})=>{var c,x,i,N;const l=a.node,n=((x=(c=l==null?void 0:l.children)==null?void 0:c[0])==null?void 0:x.type)==="element"&&((N=(i=l==null?void 0:l.children)==null?void 0:i[0])==null?void 0:N.tagName)==="input";return e.jsx("li",{className:`leading-7 ${n?"list-none -ml-6 flex items-start gap-2":""}`,children:s})},blockquote:({children:s})=>e.jsx("blockquote",{className:"border-l-4 border-blue-300 bg-blue-50/40 pl-4 pr-3 py-2 my-4 text-slate-600 rounded-r-lg [&>p]:mb-2 [&>p:last-child]:mb-0",children:s}),a:({href:s,children:a})=>s!=null&&s.startsWith("#")?e.jsx("a",{href:s,className:"text-blue-600 hover:text-blue-700 hover:underline underline-offset-2 decoration-blue-300/70 transition-colors",children:a}):e.jsx("a",{href:s,className:"text-blue-600 hover:text-blue-700 hover:underline underline-offset-2 decoration-blue-300/70 transition-colors",target:"_blank",rel:"noopener noreferrer",children:a}),img:({src:s,alt:a})=>e.jsx("img",{src:s,alt:a||"",className:"max-w-full h-auto rounded-lg border border-slate-200 my-4",loading:"lazy"}),table:({children:s})=>e.jsx("div",{className:"my-5 overflow-x-auto rounded-lg border border-slate-200",children:e.jsx("table",{className:"w-full border-collapse text-sm",children:s})}),thead:({children:s})=>e.jsx("thead",{className:"bg-slate-50 border-b border-slate-200",children:s}),tbody:({children:s})=>e.jsx("tbody",{className:"divide-y divide-slate-100",children:s}),tr:({children:s})=>e.jsx("tr",{className:"hover:bg-slate-50/50 transition-colors",children:s}),th:({children:s})=>e.jsx("th",{className:"px-4 py-2.5 text-left text-xs font-semibold text-slate-600 uppercase tracking-wider",children:s}),td:({children:s})=>e.jsx("td",{className:"px-4 py-2.5 text-slate-700 align-top",children:s}),input:({checked:s})=>e.jsx("input",{type:"checkbox",checked:s,readOnly:!0,className:"mt-1 w-4 h-4 rounded border-slate-300 text-blue-600 cursor-default"})}),ut=({content:t,className:s="",showLineNumbers:a=!1,stripFrontmatter:l=!1})=>{const n=r.useMemo(()=>Ul(a),[a]),c=r.useMemo(()=>{let x=l?Es(t):t;return x=ql(x),x=Hl(x),Wl(x)},[t,l]);return e.jsx("div",{className:`markdown-body text-slate-700 ${s}`,children:c.map((x,i)=>x.type==="mermaid"?e.jsx(fa,{code:x.content},`mermaid-${i}`):e.jsx(pl,{remarkPlugins:[$a],components:n,children:x.content},`md-${i}`))})},ja="asd-chat-topics",Kl=50;function Vl(){return Date.now().toString(36)+Math.random().toString(36).substring(2,8)}function Yl(t){const s=t.find(l=>l.role==="user");if(!s)return"新话题";const a=s.content.trim().replace(/\n/g," ");return a.length>30?a.slice(0,30)+"…":a}function Jl(){try{const t=localStorage.getItem(ja);if(!t)return[];const s=JSON.parse(t);return Array.isArray(s)?s:[]}catch{return[]}}function Xl(t){try{const s=t.slice(0,Kl);localStorage.setItem(ja,JSON.stringify(s))}catch(s){console.warn("[ChatTopics] localStorage save failed:",s)}}function Na(){const[t,s]=r.useState(()=>Jl()),[a,l]=r.useState(null),n=r.useRef(t);r.useEffect(()=>{n.current=t},[t]);const c=r.useCallback(u=>{s(w=>{const f=typeof u=="function"?u(w):u;return Xl(f),f})},[]),x=r.useCallback(u=>{const w=Vl(),f={id:w,title:u||"新话题",messages:[],createdAt:Date.now(),updatedAt:Date.now()};return c(E=>[f,...E]),l(w),w},[c]),i=r.useCallback(u=>{c(w=>w.filter(f=>f.id!==u)),l(w=>w===u?null:w)},[c]),N=r.useCallback((u,w)=>{c(f=>{const E=f.findIndex(B=>B.id===u);if(E<0)return f;const A={...f[E],messages:w,updatedAt:Date.now()},M=Yl(w);M!=="新话题"&&(A.title=M);const R=[...f];return R[E]=A,R.splice(E,1),R.unshift(A),R})},[c]),j=r.useCallback(u=>n.current.find(w=>w.id===u),[]),g=r.useCallback(u=>{l(u)},[]),p=t.find(u=>u.id===a)??null;return{topics:t,activeTopicId:a,activeTopic:p,createTopic:x,deleteTopic:i,saveTopic:N,getTopic:j,switchTopic:g,setActiveTopicId:l}}const ya=r.createContext({openChat:()=>{},openRefine:()=>{},close:()=>{},toggle:()=>{},newTopic:()=>{},isOpen:!1}),ts=()=>r.useContext(ya),ft=()=>Math.random().toString(36).substring(2,10),Zl=[{key:"description",label:"摘要"},{key:"pattern",label:"内容文档"},{key:"tags",label:"标签",format:t=>Array.isArray(t)?t.join(", "):String(t||"")},{key:"confidence",label:"置信度",format:t=>String(t??"—")},{key:"aiInsight",label:"AI 洞察"},{key:"agentNotes",label:"Agent 笔记",format:t=>Array.isArray(t)?t.join(`
|
|
43
|
+
`):String(t||"")},{key:"relations",label:"关联关系",format:t=>JSON.stringify(t||{},null,2)}];function Ql(t,s){const a=[];for(const l of Zl){const n=l.format||(i=>String(i??"")),c=n(t[l.key]),x=n(s[l.key]);x&&x!==c&&a.push({field:l.key,label:l.label,before:c,after:x})}return a}function er(t){var s,a;return{title:t.title||"",description:t.description||"",pattern:((s=t.content)==null?void 0:s.pattern)||"",tags:t.tags||[],confidence:((a=t.reasoning)==null?void 0:a.confidence)??.6,relations:t.relations||{},aiInsight:t.aiInsight||null,agentNotes:t.agentNotes||null}}const tr=({diff:t})=>t.length===0?e.jsx("p",{className:"text-xs text-slate-400 italic py-2",children:"未检测到变更"}):e.jsx("div",{className:"space-y-2 mt-2",children:t.map(s=>e.jsxs("div",{className:"border border-slate-200 rounded-lg overflow-hidden",children:[e.jsxs("div",{className:"px-2.5 py-1 bg-slate-50 border-b border-slate-200 flex items-center gap-1.5",children:[e.jsx(ca,{size:10,className:"text-emerald-500"}),e.jsx("span",{className:"text-[10px] font-bold text-slate-600",children:s.label})]}),e.jsxs("div",{className:"p-2 bg-red-50/30 border-b border-slate-200",children:[e.jsx("div",{className:"text-[9px] font-bold text-red-400 mb-0.5 uppercase",children:"Before"}),e.jsx("pre",{className:"text-[11px] text-slate-600 whitespace-pre-wrap break-words max-h-40 overflow-auto font-mono leading-relaxed scrollbar-light",children:s.before||e.jsx("span",{className:"italic text-slate-300",children:"(空)"})})]}),e.jsxs("div",{className:"p-2 bg-emerald-50/30",children:[e.jsx("div",{className:"text-[9px] font-bold text-emerald-500 mb-0.5 uppercase",children:"After"}),e.jsx("pre",{className:"text-[11px] text-slate-700 whitespace-pre-wrap break-words max-h-40 overflow-auto font-mono leading-relaxed scrollbar-light",children:s.after})]})]},s.field))}),Ts=r.createContext(null),sr=()=>r.useContext(Ts),ar=({children:t})=>{const[s,a]=r.useState(!1),[l,n]=r.useState([]),[c,x]=r.useState(!1),[i,N]=r.useState(!1),[j,g]=r.useState(null),[p,u]=r.useState(new Set),[w,f]=r.useState(""),E=r.useRef([]),A=!!j,M=j?j.candidateIds[j.currentIdx]:null,R=j?j.candidates.find(P=>P.id===M):void 0,B=j?j.candidateIds.length>1:!1;r.useEffect(()=>{j&&R&&(n(P=>[...P,{id:ft(),role:"system",content:`🎯 润色模式 — **${R.title}**
|
|
44
|
+
|
|
45
|
+
当前摘要: ${R.description||"(无)"}
|
|
46
|
+
|
|
47
|
+
**输入润色指令,AI 将根据你的指令定向修改候选内容**,下方有常用指令可直接点击使用。`,timestamp:Date.now()}]),f(""))},[j==null?void 0:j.currentIdx]);const T=r.useCallback(()=>{g(null),a(!0)},[]),U=r.useCallback(P=>{g({...P,currentIdx:0}),u(new Set),n([]),E.current=[],a(!0)},[]),K=r.useCallback(()=>a(!1),[]),S=r.useCallback(()=>a(P=>!P),[]),q=r.useCallback(()=>{n([]),E.current=[],f(""),g(null),u(new Set)},[]),C={openChat:T,openRefine:U,close:K,toggle:S,newTopic:q,isOpen:s},m={messages:l,setMessages:n,loading:c,setLoading:x,applying:i,setApplying:N,refineCtx:j,setRefineCtx:g,applied:p,setApplied:u,lastPrompt:w,setLastPrompt:f,chatHistoryRef:E,isRefineMode:A,currentRefineId:M,currentRefineCandidate:R,isBatchRefine:B,close:K};return e.jsx(ya.Provider,{value:C,children:e.jsx(Ts.Provider,{value:m,children:t})})},lr=()=>{const t=r.useContext(Ts),{messages:s,setMessages:a,loading:l,setLoading:n,applying:c,setApplying:x,refineCtx:i,setRefineCtx:N,applied:j,setApplied:g,lastPrompt:p,setLastPrompt:u,chatHistoryRef:w,isRefineMode:f,currentRefineId:E,currentRefineCandidate:A,isBatchRefine:M,close:R}=t,B=r.useRef(null),T=r.useRef(null),[U,K]=r.useState(""),S=Na(),q=r.useRef(null),C=r.useRef(!1);r.useEffect(()=>{if(f&&A){C.current=!0;const L=S.createTopic(`润色: ${A.title||"未命名"}`);q.current=L,setTimeout(()=>{C.current=!1},50)}},[i]),r.useEffect(()=>{C.current||q.current&&s.length>0&&S.saveTopic(q.current,s)},[s]);const m=r.useCallback(()=>{if(!q.current){C.current=!0;const L=S.createTopic();q.current=L,setTimeout(()=>{C.current=!1},50)}},[S]);r.useEffect(()=>{var L;(L=B.current)==null||L.scrollIntoView({behavior:"smooth"})},[s,l]),r.useEffect(()=>{setTimeout(()=>{var L;return(L=T.current)==null?void 0:L.focus()},200)},[]);const P=f&&E&&s.some(L=>L.role==="assistant"&&L.diff&&L.diff.length>0)&&!j.has(E),h=r.useCallback(async()=>{const L=U.trim();if(!(!L||l)){if(f||m(),K(""),a(Z=>[...Z,{id:ft(),role:"user",content:L,timestamp:Date.now()}]),n(!0),f&&E){u(L);try{const Z=await Y.refinePreview(E,L),fe=Z.before||(A?er(A):{}),O=Ql(fe,Z.after||{});a(re=>[...re,{id:ft(),role:"assistant",content:O.length>0?`已生成润色预览,共 ${O.length} 个字段变更:`:"未检测到变更,请尝试更具体的指令。",diff:O.length>0?O:void 0,preview:O.length>0?Z.preview:void 0,timestamp:Date.now()}])}catch(Z){a(fe=>{var O,re;return[...fe,{id:ft(),role:"assistant",content:`润色预览失败: ${((re=(O=Z.response)==null?void 0:O.data)==null?void 0:re.error)||Z.message}`,timestamp:Date.now()}]})}}else{w.current.push({role:"user",content:L});try{const Z=await Y.chat(L,w.current);w.current.push({role:"model",content:Z.text}),a(fe=>[...fe,{id:ft(),role:"assistant",content:Z.text,timestamp:Date.now()}])}catch(Z){a(fe=>[...fe,{id:ft(),role:"assistant",content:`请求失败: ${Z.message}`,timestamp:Date.now()}])}}n(!1)}},[U,l,f,E,A,m]),d=r.useCallback(async()=>{var L,Z,fe;if(!(c||!E||!i)){x(!0);try{await Y.refineApply(E,p),g(O=>new Set(O).add(E)),(L=i.onCandidateUpdated)==null||L.call(i,E),a(O=>[...O,{id:ft(),role:"system",content:"✅ 变更已应用到候选!",timestamp:Date.now()}]),V("候选内容已更新为润色后版本",{title:"润色已应用"})}catch(O){V(((fe=(Z=O.response)==null?void 0:Z.data)==null?void 0:fe.error)||O.message,{title:"应用失败",type:"error"})}finally{x(!1)}}},[c,E,p,i]),v=r.useCallback(()=>{!i||i.currentIdx>=i.candidateIds.length-1||N(L=>L?{...L,currentIdx:L.currentIdx+1}:null)},[i]),k=r.useCallback(()=>{q.current=null,N(null),a(L=>[...L,{id:ft(),role:"system",content:"已退出润色模式,回到通用对话。",timestamp:Date.now()}])},[]),ee=r.useCallback(L=>{L.key==="Enter"&&!L.shiftKey&&(L.preventDefault(),h())},[h]);return e.jsxs("aside",{className:"w-[420px] h-full bg-white border-l border-slate-200 flex flex-col shrink-0",children:[e.jsxs("div",{className:"px-4 py-2.5 border-b border-slate-200 flex items-center justify-between shrink-0",children:[e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsx("div",{className:"w-8 h-8 rounded-lg bg-gradient-to-br from-blue-50 to-indigo-50 border border-blue-100 flex items-center justify-center",children:f?e.jsx(Ke,{className:"text-emerald-500",size:16}):e.jsx(Ct,{className:"text-blue-600",size:16})}),e.jsxs("div",{children:[e.jsxs("h3",{className:"text-[13px] font-bold text-slate-800 flex items-center gap-2",children:[f?"AI 润色":"AI Chat",f&&M&&e.jsxs("span",{className:"text-[10px] px-1.5 py-0.5 rounded-full bg-emerald-50 text-emerald-600 font-medium",children:[((i==null?void 0:i.currentIdx)??0)+1,"/",i==null?void 0:i.candidateIds.length]})]}),e.jsx("p",{className:"text-[10px] text-slate-400 truncate max-w-[250px]",children:f?(A==null?void 0:A.title)||"润色中...":"询问任何关于项目的问题"})]})]}),e.jsxs("div",{className:"flex items-center gap-1",children:[f&&e.jsx("button",{onClick:k,className:"px-2 py-1 text-[10px] font-medium text-slate-500 hover:text-slate-700 hover:bg-slate-100 rounded-md transition-colors",children:"退出润色"}),!f&&s.length>0&&e.jsx("button",{onClick:()=>{q.current=null,a([]),w.current=[],u("")},className:"p-1.5 hover:bg-slate-100 rounded-lg transition-colors",title:"开启新话题",children:e.jsx(Nt,{size:16,className:"text-slate-400"})}),e.jsx("button",{onClick:R,className:"p-1.5 hover:bg-slate-100 rounded-lg transition-colors",title:"关闭 AI Chat",children:e.jsx(Ye,{size:16,className:"text-slate-400"})})]})]}),f&&A&&e.jsx("div",{className:"border-b border-slate-100 bg-emerald-50/30 px-4 py-2 shrink-0",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-[10px] font-bold text-emerald-700 truncate flex-1",children:A.title}),A.language&&e.jsx("span",{className:"text-[9px] px-1.5 py-0.5 rounded bg-blue-50 text-blue-600 border border-blue-100",children:A.language})]})}),e.jsxs("div",{className:"flex-1 overflow-y-auto p-4 space-y-3 min-h-0 scrollbar-light",children:[s.length===0&&!f&&e.jsxs("div",{className:"flex flex-col items-center justify-center h-full text-center py-10",children:[e.jsx("div",{className:"w-12 h-12 rounded-2xl bg-blue-50 border border-blue-100 flex items-center justify-center mb-3",children:e.jsx(Ct,{className:"text-blue-500",size:20})}),e.jsx("h4",{className:"text-sm font-bold text-slate-700 mb-1",children:"AI Chat"}),e.jsx("p",{className:"text-xs text-slate-400 max-w-[280px] leading-relaxed mb-3",children:"询问项目相关问题,或使用 AI 功能分析代码、润色候选等。"}),e.jsx("div",{className:"flex flex-wrap gap-1.5 justify-center",children:["分析项目架构","查找重复代码","推荐优化方向"].map(L=>e.jsx("button",{onClick:()=>{var Z;K(L),(Z=T.current)==null||Z.focus()},className:"text-[10px] px-2.5 py-1 rounded-md bg-slate-100 text-slate-600 hover:bg-blue-50 hover:text-blue-700 transition-colors",children:L},L))})]}),f&&s.length<=1&&e.jsx("div",{className:"flex flex-wrap gap-1.5 mt-2",children:["增加具体使用案例,不要修改其他内容","优化代码注释和说明","补充常见错误用法和注意事项","提升摘要质量,更简洁专业","补充性能注意事项"].map(L=>e.jsx("button",{onClick:()=>{var Z;K(L),(Z=T.current)==null||Z.focus()},className:"text-[10px] px-2.5 py-1 rounded-md bg-emerald-50 text-emerald-700 border border-emerald-200 hover:bg-emerald-100 transition-colors",children:L},L))}),s.map(L=>e.jsx("div",{className:`flex ${L.role==="user"?"justify-end":"justify-start"}`,children:e.jsxs("div",{className:`max-w-[95%] ${L.role==="user"?"bg-blue-600 text-white rounded-2xl rounded-tr-md px-3.5 py-2":L.role==="system"?"bg-slate-50 border border-slate-200 text-slate-600 rounded-2xl px-3.5 py-2 w-full":"bg-white border border-slate-200 rounded-2xl rounded-tl-md px-3.5 py-2.5 shadow-sm w-full"}`,children:[L.role==="assistant"&&e.jsxs("div",{className:"flex items-center gap-1.5 mb-1.5",children:[e.jsx(Yt,{size:12,className:f?"text-emerald-500":"text-blue-500"}),e.jsx("span",{className:`text-[10px] font-bold ${f?"text-emerald-600":"text-blue-600"}`,children:f?"AI 润色助手":"AI 助手"})]}),L.role==="assistant"&&!L.diff?e.jsx(ut,{content:L.content,className:"text-xs text-slate-700"}):e.jsx("p",{className:`text-xs leading-relaxed whitespace-pre-wrap ${L.role==="user"?"":L.role==="system"?"text-slate-500":"text-slate-700"}`,children:L.content}),L.diff&&L.diff.length>0&&e.jsx(tr,{diff:L.diff})]})},L.id)),l&&e.jsx("div",{className:"flex justify-start",children:e.jsx("div",{className:"bg-white border border-slate-200 rounded-2xl rounded-tl-md px-3.5 py-2.5 shadow-sm",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Te,{size:12,className:`animate-spin ${f?"text-emerald-500":"text-blue-500"}`}),e.jsx("span",{className:"text-xs text-slate-500",children:f?"AI 正在分析...":"AI 思考中..."})]})})}),e.jsx("div",{ref:B})]}),f&&P&&!l&&e.jsxs("div",{className:"px-4 py-2 border-t border-slate-100 bg-emerald-50/50 flex items-center gap-2 shrink-0",children:[e.jsxs("button",{onClick:d,disabled:c,className:"flex items-center gap-1 px-3 py-1.5 text-[11px] font-bold text-white bg-gradient-to-r from-emerald-500 to-teal-600 hover:from-emerald-600 hover:to-teal-700 rounded-lg shadow-sm disabled:opacity-50",children:[c?e.jsx(Te,{size:11,className:"animate-spin"}):e.jsx(yt,{size:11}),c?"应用中...":"确认应用"]}),e.jsxs("button",{className:"flex items-center gap-1 px-2.5 py-1.5 text-[11px] font-bold text-slate-500 hover:text-slate-700 rounded-lg hover:bg-slate-100 transition-colors",children:[e.jsx(oa,{size:11})," 继续调整"]}),M&&j.has(E)&&i.currentIdx<i.candidateIds.length-1&&e.jsxs("button",{onClick:v,className:"flex items-center gap-1 px-2.5 py-1.5 text-[11px] font-bold text-blue-600 hover:text-blue-700 rounded-lg hover:bg-blue-50 transition-colors ml-auto",children:["下一条 ",e.jsx(at,{size:11})]})]}),f&&!P&&!l&&M&&j.has(E)&&i.currentIdx<i.candidateIds.length-1&&e.jsx("div",{className:"px-4 py-2 border-t border-slate-100 flex items-center justify-center shrink-0",children:e.jsxs("button",{onClick:v,className:"flex items-center gap-1 px-3 py-1.5 text-[11px] font-bold text-blue-600 hover:text-blue-700 rounded-lg bg-blue-50 hover:bg-blue-100 transition-colors",children:["下一条 (",((i==null?void 0:i.currentIdx)??0)+2,"/",i==null?void 0:i.candidateIds.length,") ",e.jsx(at,{size:12})]})}),e.jsxs("div",{className:"px-4 py-2.5 border-t border-slate-200 bg-white shrink-0",children:[e.jsxs("div",{className:"flex gap-2",children:[e.jsx("textarea",{ref:T,value:U,onChange:L=>K(L.target.value),onKeyDown:ee,placeholder:f?'输入定向润色指令,如"增加使用案例"、"优化摘要"...':"输入你的问题...",rows:2,className:`flex-1 px-3 py-2 text-sm border border-slate-200 rounded-xl focus:outline-none focus:ring-2 ${f?"focus:ring-emerald-200 focus:border-emerald-400":"focus:ring-blue-200 focus:border-blue-400"} resize-none placeholder:text-slate-300`,disabled:l||c}),e.jsx("button",{onClick:h,disabled:!U.trim()||l||c,className:`self-stretch w-9 flex items-center justify-center rounded-xl bg-gradient-to-r ${f?"from-emerald-500 to-teal-600 hover:from-emerald-600 hover:to-teal-700":"from-blue-500 to-indigo-600 hover:from-blue-600 hover:to-indigo-700"} text-white disabled:opacity-40 disabled:cursor-not-allowed transition-all shadow-sm shrink-0`,children:e.jsx(Ss,{size:14})})]}),e.jsx("p",{className:"text-[9px] text-slate-400 mt-1",children:f?"Enter 发送 · Shift+Enter 换行 · 先预览再应用":"Enter 发送 · Shift+Enter 换行"})]})]})},rr=({searchQuery:t,setSearchQuery:s,setShowCreateModal:a,handleSyncToXcode:l,aiConfig:n,llmReady:c=!0,onOpenLlmConfig:x,onSemanticSearchResults:i,onBeforeAiSwitch:N,onAiConfigChange:j,isDarkMode:g=!1})=>{const{toggle:p,isOpen:u}=ts(),[w,f]=r.useState(!1),[E,A]=r.useState(!1),[M,R]=r.useState([]),[B,T]=r.useState(!1),U=r.useRef(null);r.useEffect(()=>{E&&M.length===0&&Y.getAiProviders().then(q=>R(q)).catch(()=>{})},[E,M.length]),r.useEffect(()=>{const q=C=>{U.current&&!U.current.contains(C.target)&&A(!1)};return document.addEventListener("click",q),()=>document.removeEventListener("click",q)},[]);const K=async()=>{if(t){f(!0);try{const C=((await Y.search(t,{mode:"semantic"})).items||[]).map(m=>{var P,h,d;return{name:(m.title||m.name||"")+".md",content:((P=m.content)==null?void 0:P.pattern)||((h=m.content)==null?void 0:h.markdown)||((d=m.content)==null?void 0:d.code)||"",similarity:m.score||0,metadata:{type:"recipe",name:(m.title||m.name||"")+".md"}}});i&&i(C)}catch(q){console.error("Semantic search failed",q),alert("语义搜索失败。请确保已运行 asd embed 构建索引。")}finally{f(!1)}}},S=async q=>{T(!0);try{N==null||N(),await Y.setAiConfig(q.id,q.defaultModel),A(!1),j&&j()}catch(C){console.error("AI config update failed",C),alert("切换 AI 失败,请检查项目根目录是否可写。")}finally{T(!1)}};return e.jsxs("header",{className:`h-16 ${g?"bg-[#252526] border-b border-[#3e3e42]":"bg-white border-b border-slate-200"} flex items-center justify-between px-8 shrink-0`,children:[e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsxs("div",{className:"relative w-96",children:[e.jsx(xt,{className:`absolute left-3 top-1/2 -translate-y-1/2 ${g?"text-slate-500":"text-slate-400"}`,size:$.md}),e.jsx("input",{type:"text",placeholder:"Search knowledge...",className:`w-full pl-10 pr-4 py-2 ${g?"bg-[#1e1e1e] text-slate-300 placeholder-slate-500":"bg-slate-100 text-slate-900"} border-transparent rounded-lg text-sm outline-none focus:ring-2 focus:ring-blue-500/20 transition-all`,value:t,onChange:q=>s(q.target.value),onKeyDown:q=>q.key==="Enter"&&K()})]}),e.jsxs("button",{onClick:K,disabled:!t||w,className:`flex items-center gap-2 px-3 py-2 rounded-lg text-xs font-bold transition-all ${w?"bg-blue-50 text-blue-400":"bg-blue-50 text-blue-600 hover:bg-blue-100"}`,title:"Semantic Search (Brain AI)",children:[w?e.jsx(Te,{size:$.sm,className:"animate-spin"}):e.jsx(Wa,{size:$.sm}),"Semantic"]})]}),e.jsxs("div",{className:"flex items-center gap-4",children:[c?n?e.jsxs("div",{className:"relative",ref:U,children:[e.jsxs("button",{type:"button",onClick:q=>{q.stopPropagation(),A(C=>!C)},className:"flex items-center gap-2 px-3 py-1.5 rounded-lg bg-slate-100 text-slate-600 text-xs font-medium hover:bg-slate-200 transition-colors",title:"点击切换 AI 提供商",children:[e.jsx(Jt,{size:$.sm}),n.provider," / ",n.model,e.jsx(St,{size:$.xs,className:E?"rotate-180":""})]}),E&&e.jsxs("div",{className:"absolute top-full right-0 mt-1 py-1 rounded-lg border border-slate-200 bg-white shadow-lg z-20 min-w-[200px]",children:[e.jsx("div",{className:"px-3 py-2 text-xs text-slate-500 border-b border-slate-100",children:"切换 AI"}),e.jsx("div",{className:"px-3 py-1.5 text-[11px] text-slate-400 border-b border-slate-100",children:e.jsx("button",{type:"button",onClick:()=>{A(!1),x==null||x()},className:"text-blue-500 hover:underline",children:"修改 .env 配置"})}),M.length===0?e.jsx("div",{className:"px-3 py-2 text-xs text-slate-400",children:"加载中..."}):M.map(q=>e.jsxs("button",{type:"button",disabled:B,onClick:()=>S(q),className:`w-full text-left px-3 py-2 text-sm hover:bg-slate-50 flex items-center justify-between ${n.provider===q.id?"bg-blue-50 text-blue-700 font-medium":"text-slate-700"}`,children:[e.jsx("span",{children:q.label}),n.provider===q.id&&e.jsx("span",{className:"text-xs",children:"✓"})]},q.id))]})]}):null:e.jsxs("button",{type:"button",onClick:x,className:"flex items-center gap-2 px-3 py-1.5 rounded-lg bg-amber-50 text-amber-700 border border-amber-200 text-xs font-medium hover:bg-amber-100 transition-colors animate-pulse",title:"AI 未配置 — 点击设置 LLM",children:[e.jsx(da,{size:$.sm}),"配置 LLM"]}),e.jsxs("button",{onClick:p,className:`flex items-center gap-2 px-3 py-2 rounded-lg text-sm font-medium transition-colors ${u?"bg-blue-100 text-blue-700 ring-1 ring-blue-200":g?"bg-slate-700 text-slate-300 hover:bg-slate-600":"bg-slate-100 text-slate-600 hover:bg-slate-200"}`,title:u?"关闭 AI Chat":"打开 AI Chat",children:[e.jsx(Ct,{size:$.sm}),!u&&e.jsx("span",{className:"text-xs",children:"AI Chat"})]}),e.jsxs("button",{onClick:()=>a(!0),className:"flex items-center gap-2 px-4 py-2 bg-slate-900 text-white rounded-lg text-sm font-medium hover:bg-slate-800 transition-colors",children:[e.jsx(Nt,{size:$.md})," New Recipe"]}),e.jsxs("button",{onClick:l,className:"flex items-center gap-2 px-4 py-2 bg-blue-600 text-white rounded-lg text-sm font-medium hover:bg-blue-700 transition-colors shadow-sm",children:[e.jsx(ht,{size:$.md})," Sync to Xcode"]})]})]})},nr=({selectedCategory:t,setSelectedCategory:s})=>e.jsx("div",{className:"bg-white border-b border-slate-100 shrink-0 overflow-hidden",children:e.jsx("div",{className:"flex items-center gap-2 overflow-x-auto no-scrollbar px-8 py-3",children:Object.entries(lt).map(([a,l])=>{const n=l.icon,c=t===a;return e.jsxs("button",{onClick:()=>s(a),className:`flex items-center gap-1.5 px-3 py-1.5 rounded-full text-[10px] font-bold transition-all border whitespace-nowrap
|
|
48
|
+
${c?`${l.bg} ${l.color} ${l.border} shadow-sm scale-105`:"bg-white text-slate-400 border-slate-100 hover:border-slate-200 hover:text-slate-600"}`,children:[e.jsx(n,{size:$.xs}),a]},a)})})}),va="asd-drawer-wide";function ir(){try{return localStorage.getItem(va)==="1"}catch{return!1}}function Ls(){const[t,s]=r.useState(ir),a=r.useCallback(()=>{s(l=>{const n=!l;try{localStorage.setItem(va,n?"1":"0")}catch{}return n})},[]);return{isWide:t,toggle:a}}const Rs=({currentPage:t,totalPages:s,totalItems:a,pageSize:l,onPageChange:n,onPageSizeChange:c,pageSizeOptions:x=[12,24,48,96]})=>{if(s<=1&&a<=x[0])return null;const i=(t-1)*l+1,N=Math.min(t*l,a),j=()=>{const g=[];if(s<=7)for(let u=1;u<=s;u++)g.push(u);else if(t<=3){for(let u=1;u<=5;u++)g.push(u);g.push("..."),g.push(s)}else if(t>=s-2){g.push(1),g.push("...");for(let u=s-5+1;u<=s;u++)g.push(u)}else{g.push(1),g.push("...");for(let u=t-1;u<=t+1;u++)g.push(u);g.push("..."),g.push(s)}return g};return e.jsxs("div",{className:"flex items-center justify-between mt-6 px-2",children:[e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsxs("span",{className:"text-sm text-slate-500",children:["显示 ",i,"-",N,",共 ",a," 条"]}),c&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-sm text-slate-500",children:"每页"}),e.jsx("select",{value:l,onChange:g=>c(Number(g.target.value)),className:"text-sm border border-slate-200 rounded-md px-2 py-1 bg-white focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-transparent",children:x.map(g=>e.jsx("option",{value:g,children:g},g))}),e.jsx("span",{className:"text-sm text-slate-500",children:"条"})]})]}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("button",{onClick:()=>n(1),disabled:t===1,className:"p-1.5 rounded-md hover:bg-slate-100 disabled:opacity-30 disabled:cursor-not-allowed transition-colors",title:"第一页",children:e.jsx(Ua,{size:$.md,className:"text-slate-600"})}),e.jsx("button",{onClick:()=>n(t-1),disabled:t===1,className:"p-1.5 rounded-md hover:bg-slate-100 disabled:opacity-30 disabled:cursor-not-allowed transition-colors",title:"上一页",children:e.jsx(Zt,{size:$.md,className:"text-slate-600"})}),e.jsx("div",{className:"flex items-center gap-1 mx-2",children:j().map((g,p)=>typeof g=="number"?e.jsx("button",{onClick:()=>n(g),className:`min-w-[32px] h-8 px-2 rounded-md text-sm font-medium transition-colors ${t===g?"bg-blue-600 text-white":"hover:bg-slate-100 text-slate-600"}`,children:g},p):e.jsx("span",{className:"px-1 text-slate-400",children:g},p))}),e.jsx("button",{onClick:()=>n(t+1),disabled:t===s,className:"p-1.5 rounded-md hover:bg-slate-100 disabled:opacity-30 disabled:cursor-not-allowed transition-colors",title:"下一页",children:e.jsx(at,{size:$.md,className:"text-slate-600"})}),e.jsx("button",{onClick:()=>n(s),disabled:t===s,className:"p-1.5 rounded-md hover:bg-slate-100 disabled:opacity-30 disabled:cursor-not-allowed transition-colors",title:"最后一页",children:e.jsx(Ka,{size:$.md,className:"text-slate-600"})})]})]})},or=It.memo(({code:t,lang:s,editorStyles:a})=>e.jsx(ha,{language:s,style:ba,showLineNumbers:!1,customStyle:{margin:0,padding:a.padding,fontSize:a.fontSize,lineHeight:a.lineHeight,borderRadius:"0",whiteSpace:"pre",verticalAlign:"top",display:"inline-block",minWidth:"100%",minHeight:"100%",backgroundColor:"#282c34"},codeTagProps:{style:{fontFamily:a.fontFamily,whiteSpace:"pre",verticalAlign:"top",fontSize:a.fontSize,lineHeight:a.lineHeight}},PreTag:"div",children:(()=>{const l=t;return l[l.length-1]===`
|
|
49
|
+
`?l+" ":l})()})),ls=19.5,cr=It.memo(({totalLines:t,scrollTop:s,viewportHeight:a,fontSize:l,lineHeight:n,fontFamily:c})=>{const i=Math.max(0,Math.floor(s/ls)-10),N=Math.ceil(a/ls)+20,j=Math.min(t,i+N),g=i*ls,p=Math.max(0,(t-j)*ls),u=[];for(let w=i;w<j;w++)u.push(e.jsx("div",{children:w+1},w));return e.jsx("div",{style:{paddingTop:g,paddingBottom:p,fontSize:l,lineHeight:n,fontFamily:c},children:u})}),Vt=({value:t,onChange:s,onCursorChange:a,language:l="javascript",height:n="400px",className:c="",placeholder:x="",rows:i,showLineNumbers:N=!0})=>{const j=r.useRef(null),g=r.useRef(null),p=r.useRef(null),u=r.useRef(null),[w,f]=r.useState(t),E=r.useRef(void 0);r.useEffect(()=>{const C=t.length>5e3?200:t.length>1e3?80:0;if(C===0){f(t);return}return E.current=setTimeout(()=>f(t),C),()=>clearTimeout(E.current)},[t]);const[A,M]=r.useState({top:0,height:400}),B={objectivec:"objectivec","objective-c":"objectivec","obj-c":"objectivec",objc:"objectivec",swift:"swift",javascript:"javascript",js:"javascript",typescript:"typescript",ts:"typescript",python:"python",py:"python",bash:"bash",shell:"bash",markdown:"markdown",md:"markdown",json:"json",text:"text"}[l==null?void 0:l.toLowerCase()]||(l==null?void 0:l.toLowerCase())||"text",T=r.useMemo(()=>({padding:"1rem 1.25rem",fontSize:"0.8125rem",lineHeight:1.5,fontFamily:"ui-monospace, monospace",minHeight:"200px"}),[]),U=r.useCallback(C=>{const m=C.currentTarget;p.current&&(p.current.scrollTop=m.scrollTop,p.current.scrollLeft=m.scrollLeft),u.current&&(u.current.scrollTop=m.scrollTop),M({top:m.scrollTop,height:m.clientHeight})},[]),K=r.useCallback(C=>{s(C.target.value),a&&a(C.target.selectionStart||0)},[s,a]),S=r.useCallback(C=>{a&&a(C.currentTarget.selectionStart||0)},[a]),q=r.useMemo(()=>(t||"").split(`
|
|
50
|
+
`).length,[t]);return r.useEffect(()=>{g.current&&M(C=>({...C,height:g.current.clientHeight}))},[]),e.jsxs("div",{ref:j,className:`relative overflow-hidden ${c}`,style:{height:i?"auto":n,minHeight:T.minHeight,display:"flex",borderRadius:"0",backgroundColor:"#282c34"},children:[N&&e.jsx("div",{ref:u,className:"flex-shrink-0 overflow-hidden pointer-events-none select-none",style:{width:"3.5em",backgroundColor:"#282c34",color:"#5c6370",textAlign:"right",paddingTop:"1rem",paddingRight:"0.75em",paddingBottom:"1rem",borderRadius:"0"},children:e.jsx(cr,{totalLines:q,scrollTop:A.top,viewportHeight:A.height,fontSize:T.fontSize,lineHeight:T.lineHeight,fontFamily:T.fontFamily})}),e.jsxs("div",{className:"relative flex-1",style:{borderRadius:"0",backgroundColor:"#282c34"},children:[e.jsx("div",{ref:p,className:"absolute inset-0 pointer-events-none highlight-scroll-hidden",style:{zIndex:0,overflow:"scroll"},children:e.jsx(or,{code:w||x,lang:B,editorStyles:T})}),e.jsx("textarea",{ref:g,value:t,onChange:K,onSelect:S,onKeyUp:S,onClick:S,onScroll:U,rows:i,placeholder:x,className:"absolute inset-0 w-full h-full resize-none outline-none",style:{padding:T.padding,lineHeight:T.lineHeight,fontSize:T.fontSize,fontFamily:T.fontFamily,caretColor:"#61afef",backgroundColor:"transparent",color:"transparent",WebkitTextFillColor:"transparent",zIndex:10,border:"none",margin:0,overflow:"auto",WebkitAppearance:"none",appearance:"none",boxSizing:"border-box",whiteSpace:"pre"}})]})]})},dr=420,xr=({className:t="bg-black/20 backdrop-blur-[1px]"})=>e.jsx("div",{className:`absolute inset-0 ${t}`}),Ve=({children:t,onClick:s,className:a="",style:l})=>{const{isOpen:n}=ts();return e.jsx("div",{className:`fixed inset-0 overflow-hidden ${a}`,style:{right:n?dr:0,...l},onClick:s,children:t})};Ve.Backdrop=xr;const mr={rule:{label:"Rule",color:"text-red-700",bg:"bg-red-50",border:"border-red-200",icon:nt},pattern:{label:"Pattern",color:"text-violet-700",bg:"bg-violet-50",border:"border-violet-200",icon:bt},fact:{label:"Fact",color:"text-cyan-700",bg:"bg-cyan-50",border:"border-cyan-200",icon:Je}},ur={"code-pattern":"代码模式",architecture:"架构设计","best-practice":"最佳实践","code-standard":"代码规范","call-chain":"调用链路",rule:"规则"};function Ze(t){return(t.name||t.title||"Untitled").replace(/\.md$/i,"")}function pr(t){const s=t.content;if(!s)return"";if(typeof s=="string")return s;const a=[];return s.pattern&&a.push(s.pattern),s.markdown&&a.push(s.markdown),a.length>0?a.join(`
|
|
51
|
+
|
|
52
|
+
`):JSON.stringify(s,null,2)}function Us(t){var s;return((s=t.content)==null?void 0:s.pattern)||""}function Ks(t){const s=(t.language||"").toLowerCase();return["objectivec","objc","objective-c","obj-c"].includes(s)?"objectivec":t.language||"swift"}function wa(t){if(t==null)return!1;const s=typeof t=="string"?new Date(t).getTime():t;return!isNaN(s)&&s>9466848e5}function Vs(t){return wa(t)?(typeof t=="string"?new Date(t):new Date(t)).toLocaleDateString("zh-CN",{year:"numeric",month:"2-digit",day:"2-digit"}):""}const hr=({recipes:t,handleDeleteRecipe:s,onRefresh:a,idTitleMap:l,currentPage:n,onPageChange:c,pageSize:x,onPageSizeChange:i})=>{const[N,j]=r.useState("default"),[g,p]=r.useState("desc"),u=[{key:"default",label:"默认",defaultDir:"desc"},{key:"authorityScore",label:"综合分",defaultDir:"desc"},{key:"authority",label:"权威分",defaultDir:"desc"},{key:"totalUsage",label:"使用",defaultDir:"desc"},{key:"lastUsed",label:"最近",defaultDir:"desc"},{key:"name",label:"名称",defaultDir:"asc"},{key:"category",label:"分类",defaultDir:"asc"}],[w,f]=r.useState(1),[E,A]=r.useState(12),M=n??w,R=x??E,B=c??f,T=i?o=>i(o):o=>{A(o),f(1)},{isWide:U,toggle:K}=Ls(),[S,q]=r.useState(null),[C,m]=r.useState("view"),[P,h]=r.useState(""),[d,v]=r.useState({title:"",description:"",markdown:"",codePattern:"",rationale:"",tags:[],tagInput:""}),[k,ee]=r.useState(!1),L=r.useRef(!0),[Z,fe]=r.useState(!1),[O,re]=r.useState("related"),[ae,ye]=r.useState("");r.useEffect(()=>()=>{L.current=!1},[]);const oe=[{key:"related",label:"关联",icon:"∼"},{key:"dependsOn",label:"依赖",icon:"⊕"},{key:"inherits",label:"继承",icon:"↑"},{key:"implements",label:"实现",icon:"◇"},{key:"calls",label:"调用",icon:"→"},{key:"dataFlow",label:"数据流",icon:"⇢"},{key:"conflicts",label:"冲突",icon:"✕"},{key:"extends",label:"扩展",icon:"⊃"}],Ne=o=>{var F,b,xe,H;q(o),m("view"),h(pr(o)),v({title:((F=o.name)==null?void 0:F.replace(/\.md$/,""))||"",description:o.description||"",markdown:((b=o.content)==null?void 0:b.markdown)||"",codePattern:((xe=o.content)==null?void 0:xe.pattern)||"",rationale:((H=o.content)==null?void 0:H.rationale)||"",tags:o.tags||[],tagInput:""}),fe(!1),ye("")},be=()=>{q(null),m("view"),fe(!1),ye("")},Ce=async()=>{if(!(!S||k)){ee(!0);try{const o=S.id||S.name;await Y.knowledgeUpdate(o,{title:d.title,description:d.description,tags:d.tags,content:{...S.content||{},pattern:d.codePattern,markdown:d.markdown,rationale:d.rationale}}),L.current&&(m("view"),a==null||a())}catch(o){V((o==null?void 0:o.message)||"保存失败",{title:"操作失败",type:"error"})}finally{L.current&&ee(!1)}}},Ae=async o=>{if(S)try{await Y.setRecipeAuthority(S.id||S.name,o),a==null||a()}catch(F){V((F==null?void 0:F.message)||"设置权威分失败",{title:"操作失败",type:"error"})}},Fe=o=>{const F=o.replace(/\.md$/i,"").toLowerCase();return t.find(b=>Ze(b).toLowerCase()===F)},_=r.useMemo(()=>{const o=new Map;if(l)for(const[F,b]of Object.entries(l))o.set(F,b);for(const F of t)F.id&&o.set(F.id,Ze(F)),F.name&&o.set(F.name,Ze(F));return o},[t,l]),I=async(o,F)=>{if(!S)return;const b={};if(S.relations)for(const[se,D]of Object.entries(S.relations))b[se]=[...D];const xe=b[o]||[],H=F.replace(/\.md$/i,"");if(!xe.some(se=>(typeof se=="string"?se:se.id||se.title||"").replace(/\.md$/i,"").toLowerCase()===H.toLowerCase())){b[o]=[...xe,H];try{await Y.updateRecipeRelations(S.id||S.name,b),q({...S,relations:b}),fe(!1),ye(""),a==null||a()}catch(se){V((se==null?void 0:se.message)||"添加关联失败",{title:"操作失败",type:"error"})}}},le=async(o,F)=>{if(!S)return;const b={};if(S.relations)for(const[H,se]of Object.entries(S.relations))b[H]=[...se];const xe=b[o]||[];b[o]=xe.filter(H=>(typeof H=="string"?H:H.id||H.title||"").replace(/\.md$/i,"").toLowerCase()!==F.replace(/\.md$/i,"").toLowerCase()),b[o].length===0&&delete b[o];try{await Y.updateRecipeRelations(S.id||S.name,b),q({...S,relations:b}),a==null||a()}catch(H){V((H==null?void 0:H.message)||"移除关联失败",{title:"操作失败",type:"error"})}};r.useEffect(()=>{S&&!t.find(o=>Ze(o)===Ze(S))&&be()},[t,S]),r.useEffect(()=>{n==null&&f(1)},[t.length,n]);const we=It.useMemo(()=>{if(N==="default")return t;const o=[...t],F=g==="asc"?1:-1;return o.sort((b,xe)=>{var D,J,me,W,ue,De,Le,Re,qe,We,G,ze;let H=0,se=0;switch(N){case"name":return H=Ze(b).toLowerCase(),se=Ze(xe).toLowerCase(),F*(H<se?-1:H>se?1:0);case"authorityScore":H=((D=b.stats)==null?void 0:D.authorityScore)??-1,se=((J=xe.stats)==null?void 0:J.authorityScore)??-1;break;case"authority":H=((me=b.stats)==null?void 0:me.authority)??-1,se=((W=xe.stats)==null?void 0:W.authority)??-1;break;case"totalUsage":H=(((ue=b.stats)==null?void 0:ue.guardUsageCount)??0)+(((De=b.stats)==null?void 0:De.humanUsageCount)??0)+(((Le=b.stats)==null?void 0:Le.aiUsageCount)??0),se=(((Re=xe.stats)==null?void 0:Re.guardUsageCount)??0)+(((qe=xe.stats)==null?void 0:qe.humanUsageCount)??0)+(((We=xe.stats)==null?void 0:We.aiUsageCount)??0);break;case"lastUsed":{const He=(G=b.stats)!=null&&G.lastUsedAt?new Date(b.stats.lastUsedAt).getTime():0,Be=(ze=xe.stats)!=null&&ze.lastUsedAt?new Date(xe.stats.lastUsedAt).getTime():0;H=isNaN(He)?0:He,se=isNaN(Be)?0:Be;break}case"category":return H=(b.category||"").toLowerCase(),se=(xe.category||"").toLowerCase(),F*(H<se?-1:H>se?1:0)}return F*(H-se)}),o},[t,N,g]),ge=Math.ceil(we.length/R),Me=(M-1)*R,Oe=we.slice(Me,Me+R),Ee=o=>{B(o),window.scrollTo({top:0,behavior:"smooth"})},y=S?we.findIndex(o=>Ze(o)===Ze(S)):-1,de=()=>{y>0&&Ne(we[y-1])},ce=()=>{y<we.length-1&&Ne(we[y+1])},te=({recipe:o,compact:F})=>{const b=o.kind?mr[o.kind]:null,xe=(b==null?void 0:b.icon)||tt,H=o.category||"Utility",se=lt[H]||lt.Utility,D=se.icon,J=o.knowledgeType,me=F?"text-[8px]":"text-[9px]";return e.jsxs("div",{className:"flex flex-wrap items-center gap-1.5",children:[b&&e.jsxs("span",{className:`${me} font-bold px-1.5 py-0.5 rounded uppercase flex items-center gap-1 border ${b.bg} ${b.color} ${b.border}`,children:[e.jsx(xe,{size:F?9:10}),b.label]}),e.jsxs("span",{className:`${me} font-bold px-1.5 py-0.5 rounded uppercase flex items-center gap-1 border ${se.bg} ${se.color} ${se.border}`,children:[e.jsx(D,{size:F?9:10}),H]}),J&&e.jsx("span",{className:`${me} font-medium px-1.5 py-0.5 rounded bg-indigo-50 text-indigo-600 border border-indigo-100`,children:ur[J]||J}),o.language&&e.jsx("span",{className:`${me} font-medium px-1.5 py-0.5 rounded bg-slate-100 text-slate-500 uppercase`,children:o.language}),o.trigger&&e.jsx("span",{className:`${me} font-mono font-bold px-1.5 py-0.5 rounded bg-blue-50 text-blue-600 border border-blue-100`,children:o.trigger})]})},pe=({recipe:o})=>{const F=[];return o.scope&&F.push({icon:kt,iconClass:"text-teal-400",label:"作用域",value:o.scope==="universal"?"通用":o.scope==="project-specific"?"项目级":o.scope}),o.complexity&&F.push({icon:et,iconClass:"text-orange-400",label:"复杂度",value:o.complexity==="advanced"?"高级":o.complexity==="intermediate"?"中级":o.complexity==="basic"?"初级":o.complexity}),o.difficulty&&o.difficulty!==o.complexity&&F.push({icon:et,iconClass:"text-amber-400",label:"难度",value:o.difficulty}),o.moduleName&&F.push({icon:et,iconClass:"text-purple-400",label:"模块",value:o.moduleName,mono:!0}),o.source&&o.source!=="unknown"&&F.push({icon:kt,iconClass:"text-violet-400",label:"来源",value:o.source==="bootstrap-scan"?"AI 扫描":o.source==="agent"?"AI Agent":o.source}),o.version&&F.push({icon:Wt,iconClass:"text-slate-400",label:"版本",value:o.version}),o.updatedAt&&wa(o.updatedAt)&&F.push({icon:Wt,iconClass:"text-slate-400",label:"更新",value:Vs(o.updatedAt)}),F.length===0&&!o.sourceFile?null:e.jsxs("div",{className:"flex flex-wrap gap-x-5 gap-y-2 text-xs",children:[F.map((b,xe)=>{const H=b.icon;return e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(H,{size:11,className:`${b.iconClass} shrink-0`}),e.jsx("span",{className:"text-slate-400",children:b.label}),e.jsx("span",{className:`font-medium text-slate-600 ${b.mono?"font-mono text-[11px]":""}`,children:b.value})]},xe)}),o.sourceFile&&e.jsxs("div",{className:"flex items-center gap-1.5 basis-full mt-0.5",children:[e.jsx(Tt,{size:11,className:"text-slate-300 shrink-0"}),e.jsx("span",{className:"text-slate-400",children:"源文件"}),e.jsx("code",{className:"font-mono text-[11px] text-slate-500 break-all",title:o.sourceFile,children:o.sourceFile})]})]})};return e.jsxs("div",{className:"relative",children:[t.length===0?e.jsxs("div",{className:"flex flex-col items-center justify-center py-24 text-center",children:[e.jsx(Va,{size:48,className:"text-slate-200 mb-4"}),e.jsx("p",{className:"font-medium text-slate-600 mb-1",children:"暂无 Recipe"}),e.jsx("p",{className:"text-sm text-slate-400",children:"通过 SPM 扫描或手动创建来添加知识条目"})]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center gap-2 mb-4 text-xs",children:[e.jsx(xa,{size:14,className:"text-slate-400 shrink-0"}),u.map(o=>{const F=N===o.key;return e.jsxs("button",{onClick:()=>{F?p(b=>b==="asc"?"desc":"asc"):(j(o.key),p(o.defaultDir)),B(1)},className:`px-2 py-1 rounded-md flex items-center gap-0.5 transition-colors ${F?"bg-blue-50 text-blue-700 font-medium border border-blue-200":"text-slate-500 hover:bg-slate-100 border border-transparent"}`,children:[o.label,F&&N!=="default"&&(g==="asc"?e.jsx(Ya,{size:12}):e.jsx(Ja,{size:12}))]},o.key)}),e.jsxs("span",{className:"ml-auto text-slate-400",children:[t.length," 条"]})]}),e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-5",children:Oe.map(o=>{var se,D;const F=Ze(o),b=Us(o),xe=o.description||o.usageGuide||"",H=S&&Ze(S)===F;return e.jsxs("div",{onClick:()=>Ne(o),className:`bg-white rounded-xl border shadow-sm hover:shadow-md transition-all group relative cursor-pointer overflow-hidden ${H?"border-blue-300 ring-1 ring-blue-200":"border-slate-200"}`,children:[e.jsxs("div",{className:"absolute top-3 right-3 flex gap-1.5 opacity-0 group-hover:opacity-100 transition-opacity z-10",children:[e.jsx("button",{onClick:J=>{J.stopPropagation(),Ne(o),m("edit")},className:"p-1.5 bg-white/90 text-slate-400 hover:text-blue-600 hover:bg-blue-50 rounded-md transition-colors shadow-sm border border-slate-100",title:"编辑",children:e.jsx(jt,{size:$.sm})}),e.jsx("button",{onClick:J=>{J.stopPropagation(),s(o.name||o.id)},className:"p-1.5 bg-white/90 text-slate-400 hover:text-red-600 hover:bg-red-50 rounded-md transition-colors shadow-sm border border-slate-100",title:"删除",children:e.jsx(st,{size:$.sm})})]}),e.jsxs("div",{className:"px-5 pt-4 pb-3",children:[e.jsx("h3",{className:"font-bold text-slate-900 text-sm mb-2 pr-16 break-words leading-snug",children:F}),e.jsx(te,{recipe:o,compact:!0})]}),o.tags&&o.tags.length>0&&e.jsxs("div",{className:"px-5 pb-2 flex flex-wrap gap-1",children:[o.tags.slice(0,4).map((J,me)=>e.jsxs("span",{className:"text-[9px] px-1.5 py-0.5 rounded bg-blue-50 text-blue-600 border border-blue-100 flex items-center gap-0.5",children:[e.jsx(Ut,{size:7}),J]},me)),o.tags.length>4&&e.jsxs("span",{className:"text-[9px] text-slate-400",children:["+",o.tags.length-4]})]}),xe&&e.jsx("div",{className:"px-5 pb-3",children:e.jsx("p",{className:"text-xs text-slate-500 line-clamp-2 leading-relaxed",children:xe.replace(/^#+\s*/gm,"").replace(/\*\*/g,"")})}),((se=o.content)==null?void 0:se.markdown)&&e.jsxs("div",{className:"mx-4 mb-2",children:[e.jsxs("div",{className:"flex items-center gap-1 mb-1 px-0.5",children:[e.jsx(tt,{size:9,className:"text-blue-400"}),e.jsx("span",{className:"text-[9px] font-bold text-blue-400 uppercase",children:"Markdown"})]}),e.jsx("div",{className:"bg-blue-50/30 border border-blue-100 rounded-lg px-3 py-2 max-h-[60px] overflow-hidden",children:e.jsx("p",{className:"text-[11px] text-slate-600 line-clamp-2 leading-relaxed",children:o.content.markdown.replace(/^#+\s*/gm,"").replace(/\*\*/g,"").replace(/```[\s\S]*?```/g,"").trim().slice(0,200)})})]}),b&&e.jsxs("div",{className:"mx-4 mb-3",children:[e.jsxs("div",{className:"flex items-center gap-1 mb-1 px-0.5",children:[e.jsx(mt,{size:9,className:"text-emerald-400"}),e.jsx("span",{className:"text-[9px] font-bold text-emerald-400 uppercase",children:"Code"})]}),e.jsx("div",{className:"rounded-lg overflow-hidden max-h-[120px]",children:e.jsx(rt,{code:b.split(`
|
|
53
|
+
`).slice(0,6).join(`
|
|
54
|
+
`),language:Ks(o)})})]}),e.jsxs("div",{className:"px-5 py-2.5 bg-slate-50/80 border-t border-slate-100 flex items-center gap-3 text-[10px] text-slate-400",children:[e.jsxs("span",{className:"font-bold text-amber-600",children:["★ ",((D=o.stats)==null?void 0:D.authority)??0]}),e.jsxs("span",{children:["使用 ",o.stats?o.stats.guardUsageCount+o.stats.humanUsageCount+o.stats.aiUsageCount:0]}),o.source&&o.source!=="unknown"&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-slate-200",children:"|"}),e.jsx("span",{children:o.source==="bootstrap-scan"?"AI 扫描":o.source==="agent"?"AI Agent":o.source})]}),o.moduleName&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-slate-200",children:"|"}),e.jsx("span",{className:"font-mono",children:o.moduleName})]}),o.relations&&Object.values(o.relations).flat().length>0&&e.jsxs("span",{className:"ml-auto text-purple-500 font-medium",children:["关系 ",Object.values(o.relations).flat().length]})]})]},o.id||F)})})]}),t.length>0&&e.jsx(Rs,{currentPage:M,totalPages:ge,totalItems:we.length,pageSize:R,onPageChange:Ee,onPageSizeChange:T}),S&&(()=>{var se,D,J,me;const o=S,F=Ze(o),b=Us(o),xe=Ks(o),H=o.content;return e.jsxs(Ve,{className:"z-30 flex justify-end",onClick:be,children:[e.jsx(Ve.Backdrop,{}),e.jsxs("div",{className:`relative h-full bg-white shadow-2xl flex flex-col ${U?"w-[min(92vw,1100px)]":"w-[min(92vw,800px)]"}`,style:{animation:"slideInRight 0.25s ease-out"},onClick:W=>W.stopPropagation(),children:[e.jsxs("div",{className:"flex items-center justify-between px-5 py-3 border-b border-slate-200 bg-gradient-to-b from-white to-slate-50/50 shrink-0",children:[e.jsx("div",{className:"flex-1 min-w-0 mr-3",children:e.jsx("h3",{className:"font-bold text-slate-800 text-lg leading-snug break-words",children:F})}),e.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[e.jsx("button",{onClick:de,disabled:y<=0,className:"p-1.5 hover:bg-slate-100 rounded-lg transition-colors disabled:opacity-30",title:"上一条",children:e.jsx(Zt,{size:$.md})}),e.jsxs("span",{className:"text-xs text-slate-400 tabular-nums",children:[y+1,"/",we.length]}),e.jsx("button",{onClick:ce,disabled:y>=we.length-1,className:"p-1.5 hover:bg-slate-100 rounded-lg transition-colors disabled:opacity-30",title:"下一条",children:e.jsx(at,{size:$.md})}),e.jsx("div",{className:"w-px h-5 bg-slate-200 mx-1"}),e.jsxs("div",{className:"flex bg-slate-100 p-0.5 rounded-lg mr-1",children:[e.jsxs("button",{onClick:()=>m("view"),className:`px-2.5 py-1 rounded-md text-xs font-bold transition-all flex items-center gap-1 ${C==="view"?"bg-white shadow-sm text-blue-600":"text-slate-400 hover:text-slate-600"}`,children:[e.jsx(Xt,{size:$.sm})," 预览"]}),e.jsxs("button",{onClick:()=>{m("edit")},className:`px-2.5 py-1 rounded-md text-xs font-bold transition-all flex items-center gap-1 ${C==="edit"?"bg-white shadow-sm text-blue-600":"text-slate-400 hover:text-slate-600"}`,children:[e.jsx(jt,{size:$.sm})," 编辑"]})]}),e.jsx("button",{onClick:K,className:"p-1.5 hover:bg-slate-100 rounded-lg transition-colors text-slate-400",title:U?"收窄":"展宽",children:U?e.jsx(Is,{size:$.md}):e.jsx(hs,{size:$.md})}),e.jsx("button",{onClick:()=>{s(o.name||o.id),be()},className:"p-1.5 hover:bg-red-50 rounded-lg text-red-500 transition-colors",title:"删除",children:e.jsx(st,{size:$.md})}),e.jsx("button",{onClick:be,className:"p-1.5 hover:bg-slate-100 rounded-lg transition-colors",children:e.jsx(Ye,{size:$.md})})]})]}),C==="edit"?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex-1 overflow-y-auto p-5 space-y-5",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-[10px] font-bold text-slate-400 uppercase mb-1.5 block",children:"标题"}),e.jsx("input",{type:"text",value:d.title,onChange:W=>v(ue=>({...ue,title:W.target.value})),className:"w-full px-3 py-2 text-sm border border-slate-200 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-300 focus:border-blue-300"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-[10px] font-bold text-slate-400 uppercase mb-1.5 block",children:"描述"}),e.jsx("textarea",{value:d.description,onChange:W=>v(ue=>({...ue,description:W.target.value})),rows:2,className:"w-full px-3 py-2 text-sm border border-slate-200 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-300 resize-none"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-[10px] font-bold text-slate-400 uppercase mb-1.5 block",children:"标签"}),e.jsx("div",{className:"flex flex-wrap gap-1.5 mb-2",children:d.tags.map((W,ue)=>e.jsxs("span",{className:"inline-flex items-center gap-1 text-[10px] px-2 py-0.5 rounded bg-blue-50 text-blue-600 border border-blue-100 font-medium",children:[W,e.jsx("button",{onClick:()=>v(De=>({...De,tags:De.tags.filter((Le,Re)=>Re!==ue)})),className:"text-blue-400 hover:text-red-500",children:e.jsx(Ye,{size:10})})]},ue))}),e.jsx("div",{className:"flex gap-2",children:e.jsx("input",{type:"text",value:d.tagInput,onChange:W=>v(ue=>({...ue,tagInput:W.target.value})),onKeyDown:W=>{W.key==="Enter"&&d.tagInput.trim()&&(W.preventDefault(),v(ue=>({...ue,tags:[...ue.tags,ue.tagInput.trim()],tagInput:""})))},placeholder:"输入标签后按 Enter",className:"flex-1 px-3 py-1.5 text-xs border border-slate-200 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-300"})})]}),e.jsxs("div",{children:[e.jsxs("label",{className:"text-[10px] font-bold text-slate-400 uppercase mb-1.5 block flex items-center gap-1.5",children:[e.jsx(tt,{size:11,className:"text-blue-400"})," Markdown 文档"]}),e.jsx("textarea",{value:d.markdown,onChange:W=>v(ue=>({...ue,markdown:W.target.value})),rows:4,className:"w-full px-3 py-2 text-sm border border-slate-200 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-300 resize-y font-mono",placeholder:"Markdown 格式..."})]}),e.jsxs("div",{children:[e.jsxs("label",{className:"text-[10px] font-bold text-slate-400 uppercase mb-1.5 block flex items-center gap-1.5",children:[e.jsx(Mt,{size:11,className:"text-emerald-500"})," 代码 / 标准用法"]}),e.jsx("div",{className:"border border-slate-200 rounded-lg overflow-hidden",style:{minHeight:200},children:e.jsx(Vt,{value:d.codePattern,onChange:W=>v(ue=>({...ue,codePattern:W})),language:xe,height:"200px",showLineNumbers:!0})})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-[10px] font-bold text-slate-400 uppercase mb-1.5 block",children:"设计原理"}),e.jsx("textarea",{value:d.rationale,onChange:W=>v(ue=>({...ue,rationale:W.target.value})),rows:3,className:"w-full px-3 py-2 text-sm border border-slate-200 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-300 resize-y",placeholder:"为何采用此方案..."})]})]}),e.jsxs("div",{className:"px-5 py-3 border-t border-slate-200 flex items-center justify-between shrink-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-xs text-slate-400",children:"权威分"}),e.jsx("select",{className:"font-bold text-amber-600 bg-amber-50 border border-amber-100 px-2 py-1 rounded-lg outline-none text-[10px]",value:((se=o.stats)==null?void 0:se.authority)??3,onChange:W=>Ae(parseInt(W.target.value)),children:[1,2,3,4,5].map(W=>e.jsxs("option",{value:W,children:["⭐".repeat(W)," ",W]},W))})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{onClick:()=>m("view"),disabled:k,className:"px-4 py-1.5 text-sm text-slate-600 font-medium rounded-lg hover:bg-slate-50",children:"取消"}),e.jsxs("button",{onClick:Ce,disabled:k,className:"px-5 py-1.5 bg-blue-600 text-white text-sm font-medium rounded-lg flex items-center gap-1.5 hover:bg-blue-700 disabled:opacity-60",children:[k?e.jsx(Te,{size:$.sm,className:"animate-spin"}):e.jsx(Qt,{size:$.sm}),k?"保存中...":"保存"]})]})]})]}):e.jsxs("div",{className:"flex-1 overflow-y-auto",children:[e.jsxs("div",{className:"px-6 py-4 border-b border-slate-100 space-y-3",children:[e.jsx(te,{recipe:o}),e.jsx(pe,{recipe:o})]}),o.tags&&o.tags.length>0&&e.jsxs("div",{className:"px-6 py-3 border-b border-slate-100 flex flex-wrap items-center gap-1.5",children:[e.jsx(Ut,{size:11,className:"text-slate-300 mr-0.5"}),o.tags.map((W,ue)=>e.jsx("span",{className:"text-[9px] px-2 py-0.5 rounded bg-blue-50 text-blue-600 border border-blue-100 font-medium",children:W},ue))]}),e.jsxs("div",{className:"px-6 py-4 border-b border-slate-100",children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(zs,{size:12,className:"text-purple-400"}),e.jsx("label",{className:"text-[10px] font-bold text-slate-400 uppercase",children:"关联知识"}),(()=>{const W=o.relations?Object.values(o.relations).flat().length:0;return W>0?e.jsx("span",{className:"text-[9px] bg-purple-100 text-purple-600 px-1.5 py-0.5 rounded-full font-bold",children:W}):null})()]}),e.jsx("button",{onClick:()=>{fe(!Z),ye("")},className:`text-[9px] px-2 py-0.5 rounded font-bold flex items-center gap-1 transition-colors ${Z?"bg-slate-200 text-slate-600":"bg-purple-500 text-white hover:bg-purple-600"}`,children:Z?e.jsxs(e.Fragment,{children:[e.jsx(Ye,{size:10})," 取消"]}):e.jsxs(e.Fragment,{children:[e.jsx(Nt,{size:10})," 添加"]})})]}),Z&&e.jsxs("div",{className:"mb-3 bg-purple-50/80 border border-purple-200 rounded-lg p-3 space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("select",{value:O,onChange:W=>re(W.target.value),className:"text-[10px] font-bold bg-white border border-purple-200 text-purple-700 rounded px-2 py-1 outline-none",children:oe.map(W=>e.jsxs("option",{value:W.key,children:[W.icon," ",W.label]},W.key))}),e.jsxs("div",{className:"flex-1 relative",children:[e.jsx(xt,{size:12,className:"absolute left-2 top-1/2 -translate-y-1/2 text-slate-300"}),e.jsx("input",{type:"text",placeholder:"搜索...",value:ae,onChange:W=>ye(W.target.value),className:"w-full text-xs bg-white border border-purple-200 rounded pl-7 pr-2 py-1 outline-none",autoFocus:!0})]})]}),ae.length>0&&e.jsx("div",{className:"max-h-36 overflow-y-auto rounded border border-purple-100 bg-white divide-y divide-slate-100",children:(()=>{const W=t.filter(ue=>Ze(ue)===F?!1:Ze(ue).toLowerCase().includes(ae.toLowerCase())).slice(0,10);return W.length?W.map(ue=>{const De=Ze(ue),Le=o.relations&&Object.values(o.relations).flat().some(Re=>(typeof Re=="string"?Re:Re.target||Re.id||Re.title||"").replace(/\.md$/i,"").toLowerCase()===De.toLowerCase());return e.jsxs("div",{className:`flex items-center justify-between px-3 py-1.5 text-xs ${Le?"bg-slate-50 text-slate-400":"hover:bg-purple-50 cursor-pointer"}`,onClick:()=>!Le&&I(O,De),children:[e.jsx("span",{className:"font-medium truncate mr-2",children:De}),Le?e.jsx("span",{className:"text-[9px] text-slate-400 font-bold shrink-0",children:"已关联"}):e.jsx("span",{className:"text-[9px] text-purple-600 font-bold shrink-0",children:"+ 添加"})]},De)}):e.jsx("div",{className:"text-xs text-slate-400 py-3 text-center",children:"未找到"})})()})]}),o.relations&&Object.entries(o.relations).some(([,W])=>Array.isArray(W)&&W.length>0)?e.jsx("div",{className:"space-y-1.5",children:oe.map(({key:W,label:ue,icon:De})=>{var Re;const Le=(Re=o.relations)==null?void 0:Re[W];return!Le||!Array.isArray(Le)||Le.length===0?null:e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsxs("span",{className:"text-[10px] font-mono text-slate-500 w-14 shrink-0 pt-0.5",children:[De," ",ue]}),e.jsx("div",{className:"flex flex-wrap gap-1",children:Le.map((qe,We)=>{const G=typeof qe=="string"?qe:qe.target||qe.id||qe.title||JSON.stringify(qe),ze=Fe(G)||(_.has(G)?Fe(_.get(G)):void 0),He=ze?Ze(ze):_.get(G)||G;return e.jsxs("span",{className:`group/rel inline-flex items-center gap-1 px-1.5 py-0.5 border rounded text-[10px] font-mono transition-colors ${ze?"bg-purple-50 border-purple-200 text-purple-700 cursor-pointer hover:bg-purple-100":"bg-white border-slate-200 text-slate-600"}`,onClick:()=>ze&&Ne(ze),title:ze?"点击查看":He,children:[He.replace(/\.md$/i,""),e.jsx("button",{onClick:Be=>{Be.stopPropagation(),le(W,G)},className:"opacity-0 group-hover/rel:opacity-100 text-red-400 hover:text-red-600 transition-opacity ml-0.5",title:"移除",children:e.jsx(Ye,{size:10})})]},We)})})]},W)})}):!Z&&e.jsx("div",{className:"text-xs text-slate-300 py-2 text-center",children:"暂无关联"})]}),e.jsxs("div",{className:"px-6 py-3 border-b border-slate-100",children:[e.jsxs("div",{className:"grid grid-cols-2 sm:grid-cols-4 gap-3",children:[e.jsxs("div",{className:"bg-amber-50/60 rounded-xl p-3 text-center border border-amber-100",children:[e.jsx("div",{className:"text-lg font-bold text-amber-700",children:((D=o.stats)==null?void 0:D.authority)??"—"}),e.jsx("div",{className:"text-[10px] text-amber-500 font-medium",children:"权威分"})]}),e.jsxs("div",{className:"bg-blue-50/60 rounded-xl p-3 text-center border border-blue-100",children:[e.jsx("div",{className:"text-lg font-bold text-blue-700",children:((J=o.stats)==null?void 0:J.authorityScore)!=null?o.stats.authorityScore.toFixed(1):"—"}),e.jsx("div",{className:"text-[10px] text-blue-500 font-medium",children:"综合分"})]}),e.jsxs("div",{className:"bg-slate-50 rounded-xl p-3 text-center border border-slate-100",children:[e.jsx("div",{className:"text-lg font-bold text-slate-800",children:o.stats?o.stats.guardUsageCount+o.stats.humanUsageCount+o.stats.aiUsageCount:0}),e.jsx("div",{className:"text-[10px] text-slate-400 font-medium",children:"总使用"})]}),e.jsxs("div",{className:"bg-slate-50 rounded-xl p-3 text-center border border-slate-100",children:[e.jsx("div",{className:"text-sm font-bold text-slate-700",children:Vs((me=o.stats)==null?void 0:me.lastUsedAt)||"从未使用"}),e.jsx("div",{className:"text-[10px] text-slate-400 font-medium",children:"最近使用"})]})]}),o.stats!=null&&(o.stats.guardUsageCount>0||o.stats.humanUsageCount>0||o.stats.aiUsageCount>0)&&e.jsxs("div",{className:"flex items-center gap-4 mt-2 text-[10px] text-slate-400",children:[e.jsxs("span",{children:["Guard: ",o.stats.guardUsageCount]}),e.jsxs("span",{children:["Human: ",o.stats.humanUsageCount]}),e.jsxs("span",{children:["AI: ",o.stats.aiUsageCount]})]})]}),o.reasoning&&(o.reasoning.whyStandard||o.reasoning.sources&&o.reasoning.sources.length>0)&&e.jsxs("div",{className:"px-6 py-4 border-b border-slate-100",children:[e.jsxs("label",{className:"text-[10px] font-bold text-slate-400 uppercase mb-2 block flex items-center gap-1.5",children:[e.jsx(bt,{size:11,className:"text-amber-400"})," 推理依据"]}),e.jsxs("div",{className:"bg-amber-50/30 border border-amber-100 rounded-xl p-4 space-y-2.5",children:[o.reasoning.whyStandard&&e.jsx("p",{className:"text-sm text-slate-700 leading-relaxed",children:o.reasoning.whyStandard}),o.reasoning.sources&&o.reasoning.sources.length>0&&e.jsxs("div",{className:"flex flex-wrap items-center gap-1.5",children:[e.jsx("span",{className:"text-[10px] text-slate-400 font-bold",children:"来源:"}),o.reasoning.sources.map((W,ue)=>e.jsx("code",{className:"text-[10px] px-2 py-0.5 bg-white border border-amber-200 rounded text-amber-700 font-mono",children:W},ue))]}),o.reasoning.confidence!=null&&o.reasoning.confidence>0&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-[10px] text-slate-400 font-bold",children:"置信度:"}),e.jsx("div",{className:"flex-1 max-w-[160px] h-1.5 bg-slate-200 rounded-full overflow-hidden",children:e.jsx("div",{className:"h-full bg-amber-400 rounded-full",style:{width:`${Math.round(o.reasoning.confidence*100)}%`}})}),e.jsxs("span",{className:"text-[10px] font-bold text-amber-600",children:[Math.round(o.reasoning.confidence*100),"%"]})]}),o.reasoning.alternatives&&o.reasoning.alternatives.length>0&&e.jsxs("div",{className:"flex flex-wrap items-center gap-1.5 pt-1",children:[e.jsx("span",{className:"text-[10px] text-slate-400 font-bold",children:"备选:"}),o.reasoning.alternatives.map((W,ue)=>e.jsx("span",{className:"text-[10px] px-1.5 py-0.5 bg-slate-100 border border-slate-200 rounded text-slate-600",children:W},ue))]})]})]}),o.quality&&o.quality.grade&&o.quality.grade!=="F"&&e.jsxs("div",{className:"px-6 py-3 border-b border-slate-100",children:[e.jsx("label",{className:"text-[10px] font-bold text-slate-400 uppercase mb-2 block",children:"质量评级"}),e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx("span",{className:`text-2xl font-black ${o.quality.grade==="A"?"text-emerald-600":o.quality.grade==="B"?"text-blue-600":o.quality.grade==="C"?"text-amber-600":o.quality.grade==="D"?"text-orange-600":"text-slate-400"}`,children:o.quality.grade}),e.jsxs("div",{className:"flex-1 grid grid-cols-3 gap-2 text-[10px]",children:[o.quality.completeness!=null&&o.quality.completeness>0&&e.jsxs("div",{className:"text-center",children:[e.jsx("div",{className:"font-bold text-slate-700",children:o.quality.completeness}),e.jsx("div",{className:"text-slate-400",children:"完整性"})]}),o.quality.adaptation!=null&&o.quality.adaptation>0&&e.jsxs("div",{className:"text-center",children:[e.jsx("div",{className:"font-bold text-slate-700",children:o.quality.adaptation}),e.jsx("div",{className:"text-slate-400",children:"适配度"})]}),o.quality.documentation!=null&&o.quality.documentation>0&&e.jsxs("div",{className:"text-center",children:[e.jsx("div",{className:"font-bold text-slate-700",children:o.quality.documentation}),e.jsx("div",{className:"text-slate-400",children:"文档度"})]})]})]})]}),o.description&&e.jsxs("div",{className:"px-6 py-4 border-b border-slate-100",children:[e.jsx("label",{className:"text-[10px] font-bold text-slate-400 uppercase mb-1.5 block",children:"摘要"}),e.jsx("p",{className:"text-sm text-slate-600 leading-relaxed",children:o.description})]}),(H==null?void 0:H.markdown)&&e.jsxs("div",{className:"px-6 py-4 border-b border-slate-100",children:[e.jsxs("label",{className:"text-[10px] font-bold text-slate-400 uppercase mb-2 block flex items-center gap-1.5",children:[e.jsx(tt,{size:11,className:"text-blue-400"})," Markdown 文档"]}),e.jsx("div",{className:"bg-blue-50/30 border border-blue-100 rounded-xl p-4",children:e.jsx("div",{className:"markdown-body text-sm text-slate-700 leading-relaxed",children:e.jsx(ut,{content:H.markdown})})})]}),o.headers&&o.headers.length>0&&e.jsxs("div",{className:"px-6 py-3 border-b border-slate-100",children:[e.jsx("label",{className:"text-[10px] font-bold text-slate-400 uppercase mb-2 block",children:"导入头文件"}),e.jsx("div",{className:"flex flex-wrap gap-1.5",children:o.headers.map((W,ue)=>e.jsx("code",{className:"px-2.5 py-1 bg-violet-50 text-violet-700 border border-violet-100 rounded-md text-[10px] font-mono font-medium",children:W},ue))})]}),b&&e.jsxs("div",{className:"px-6 py-4 border-b border-slate-100",children:[e.jsxs("label",{className:"text-[10px] font-bold text-slate-400 uppercase mb-2 block flex items-center gap-1.5",children:[e.jsx(mt,{size:11,className:"text-emerald-500"})," 代码 / 标准用法"]}),e.jsx(rt,{code:b,language:xe,showLineNumbers:!0})]}),(H==null?void 0:H.rationale)&&e.jsxs("div",{className:"px-6 py-4 border-b border-slate-100",children:[e.jsx("label",{className:"text-[10px] font-bold text-slate-400 uppercase mb-2 block",children:"设计原理"}),e.jsx("div",{className:"bg-slate-50 border border-slate-100 rounded-xl p-4",children:e.jsx("p",{className:"text-sm text-slate-600 leading-relaxed",children:H.rationale})})]}),(H==null?void 0:H.steps)&&H.steps.length>0&&e.jsxs("div",{className:"px-6 py-4 border-b border-slate-100",children:[e.jsx("label",{className:"text-[10px] font-bold text-slate-400 uppercase mb-2 block",children:"实施步骤"}),e.jsx("div",{className:"space-y-2",children:H.steps.map((W,ue)=>{if(typeof W=="string")return e.jsxs("div",{className:"bg-slate-50 rounded-lg p-3 border border-slate-100 flex items-start gap-2.5",children:[e.jsx("span",{className:"text-[10px] font-bold text-blue-600 bg-blue-50 rounded-full w-5 h-5 flex items-center justify-center shrink-0 mt-0.5",children:ue+1}),e.jsx("p",{className:"text-xs text-slate-700 leading-relaxed",children:W})]},ue);const De=typeof W.title=="string"?W.title:"",Le=typeof W.description=="string"?W.description:"",Re=typeof W.code=="string"?W.code:"";return e.jsxs("div",{className:"bg-slate-50 rounded-lg p-3 border border-slate-100",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[e.jsx("span",{className:"text-[10px] font-bold text-blue-600 bg-blue-50 rounded-full w-5 h-5 flex items-center justify-center shrink-0",children:ue+1}),De&&e.jsx("span",{className:"text-xs font-bold text-slate-700",children:De})]}),Le&&e.jsx("p",{className:"text-xs text-slate-600 ml-7 leading-relaxed",children:Le}),Re&&e.jsx("pre",{className:"text-[11px] font-mono bg-slate-800 text-green-300 p-2.5 rounded-md mt-1.5 ml-7 overflow-x-auto whitespace-pre-wrap",children:Re})]},ue)})})]}),(H==null?void 0:H.codeChanges)&&H.codeChanges.length>0&&e.jsxs("div",{className:"px-6 py-4 border-b border-slate-100",children:[e.jsx("label",{className:"text-[10px] font-bold text-slate-400 uppercase mb-2 block",children:"代码变更"}),e.jsx("div",{className:"space-y-2",children:H.codeChanges.map((W,ue)=>e.jsxs("div",{className:"border border-slate-200 rounded-lg overflow-hidden",children:[e.jsxs("div",{className:"px-3 py-1.5 bg-slate-50 border-b border-slate-200 flex items-center gap-2",children:[e.jsx(mt,{size:11,className:"text-blue-400"}),e.jsx("code",{className:"text-[10px] font-mono text-slate-600",children:W.file})]}),W.explanation&&e.jsx("p",{className:"text-[11px] text-slate-500 px-3 py-1.5 border-b border-slate-100 bg-yellow-50/30",children:W.explanation}),e.jsxs("div",{className:"p-2 bg-red-50/20 border-b border-slate-100",children:[e.jsx("div",{className:"text-[9px] font-bold text-red-400 mb-0.5 uppercase",children:"Before"}),e.jsx("pre",{className:"text-[11px] text-slate-600 whitespace-pre-wrap break-words font-mono",children:W.before||"(空)"})]}),e.jsxs("div",{className:"p-2 bg-emerald-50/20",children:[e.jsx("div",{className:"text-[9px] font-bold text-emerald-500 mb-0.5 uppercase",children:"After"}),e.jsx("pre",{className:"text-[11px] text-slate-700 whitespace-pre-wrap break-words font-mono",children:W.after})]})]},ue))})]}),(H==null?void 0:H.verification)&&e.jsxs("div",{className:"px-6 py-4 border-b border-slate-100",children:[e.jsx("label",{className:"text-[10px] font-bold text-slate-400 uppercase mb-2 block",children:"验证方法"}),e.jsxs("div",{className:"bg-teal-50/50 border border-teal-100 rounded-xl p-4 space-y-1.5",children:[H.verification.method&&e.jsxs("p",{className:"text-xs text-slate-600",children:[e.jsx("span",{className:"font-bold text-teal-600",children:"方法:"})," ",H.verification.method]}),H.verification.expectedResult&&e.jsxs("p",{className:"text-xs text-slate-600",children:[e.jsx("span",{className:"font-bold text-teal-600",children:"预期:"})," ",H.verification.expectedResult]}),H.verification.testCode&&e.jsx("pre",{className:"text-[11px] font-mono bg-slate-800 text-green-300 p-2.5 rounded-md overflow-x-auto whitespace-pre-wrap mt-1",children:H.verification.testCode})]})]}),o.constraints&&(()=>{var De,Le,Re,qe,We,G,ze,He;const W=o.constraints,ue=(((De=W.guards)==null?void 0:De.length)||0)+(((Le=W.boundaries)==null?void 0:Le.length)||0)+(((Re=W.preconditions)==null?void 0:Re.length)||0)+(((qe=W.sideEffects)==null?void 0:qe.length)||0);return ue?e.jsxs("div",{className:"px-6 py-4 border-b border-slate-100",children:[e.jsxs("label",{className:"text-[10px] font-bold text-slate-400 uppercase mb-2 block flex items-center gap-1.5",children:[e.jsx(nt,{size:11,className:"text-amber-500"})," 约束条件 ",e.jsx("span",{className:"text-amber-500 font-mono",children:ue})]}),e.jsxs("div",{className:"space-y-1.5 text-xs text-slate-600",children:[(We=W.guards)==null?void 0:We.map((Be,Xe)=>e.jsxs("div",{className:"flex gap-1.5 items-start",children:[e.jsx("span",{className:`text-xs mt-0.5 ${Be.severity==="error"?"text-red-500":"text-yellow-500"}`,children:"●"}),e.jsx("code",{className:"font-mono text-[10px] bg-slate-100 px-1.5 py-0.5 rounded",children:Be.pattern}),Be.message&&e.jsxs("span",{className:"text-[10px] text-slate-400",children:["— ",Be.message]})]},Xe)),(G=W.boundaries)==null?void 0:G.map((Be,Xe)=>e.jsxs("div",{className:"flex gap-1.5",children:[e.jsx("span",{className:"text-orange-400",children:"●"}),Be]},Xe)),(ze=W.preconditions)==null?void 0:ze.map((Be,Xe)=>e.jsxs("div",{className:"flex gap-1.5",children:[e.jsx("span",{className:"text-blue-400",children:"◆"}),Be]},Xe)),(He=W.sideEffects)==null?void 0:He.map((Be,Xe)=>e.jsxs("div",{className:"flex gap-1.5",children:[e.jsx("span",{className:"text-pink-400",children:"⚡"}),Be]},Xe))]})]}):null})()]})]})]})})()]})},br=()=>{const[t,s]=r.useState(new Set(["quick-start"])),a=n=>{const c=new Set(t);c.has(n)?c.delete(n):c.add(n),s(c)},l=({id:n,title:c,icon:x,children:i})=>{const N=t.has(n);return e.jsxs("section",{className:"border border-slate-200 rounded-lg overflow-hidden",children:[e.jsxs("button",{onClick:()=>a(n),className:"w-full flex items-center justify-between p-4 bg-slate-50 hover:bg-slate-100 transition-colors",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[x,e.jsx("h2",{className:"text-lg font-bold text-slate-800",children:c})]}),N?e.jsx(St,{size:$.lg}):e.jsx(at,{size:$.lg})]}),N&&e.jsx("div",{className:"p-4 bg-white",children:i})]})};return e.jsxs("div",{className:"max-w-5xl mx-auto py-8 px-4",children:[e.jsxs("div",{className:"mb-8 text-center",children:[e.jsxs("h1",{className:"text-4xl font-bold text-slate-900 mb-4 flex items-center justify-center gap-3",children:[e.jsx(Je,{size:$.xxl,className:"text-blue-600"}),"AutoSnippet V2 使用说明"]}),e.jsx("p",{className:"text-slate-600 text-lg max-w-3xl mx-auto whitespace-nowrap",children:"连接开发者、AI 与项目知识库:ChatAgent 智能对话 · Skills 开放平台 · 知识库持续生长"}),e.jsx("p",{className:"text-slate-400 text-sm mt-2",children:"Node.js ≥ 20 · 13 Skills · AI 可自建 · 38 MCP 工具 · ChatAgent 对话 · 4 层检索管线"}),e.jsxs("div",{className:"mt-6 flex gap-4 justify-center text-sm",children:[e.jsx("a",{href:"https://github.com/GxFn/AutoSnippet",target:"_blank",rel:"noopener noreferrer",className:"px-4 py-2 bg-blue-600 text-white rounded-lg hover:bg-blue-700 transition-colors",children:"查看 GitHub"}),e.jsx("a",{href:"https://github.com/GxFn/AutoSnippet/blob/main/README.md",target:"_blank",rel:"noopener noreferrer",className:"px-4 py-2 border border-slate-300 text-slate-700 rounded-lg hover:bg-slate-50 transition-colors",children:"完整文档"})]})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsx(l,{id:"quick-start",title:"快速开始",icon:e.jsx(Bt,{size:$.xl,className:"text-blue-600"}),children:e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-4 gap-4",children:[e.jsxs("div",{className:"bg-blue-50 rounded-lg p-4 border border-blue-200",children:[e.jsx("div",{className:"bg-blue-600 text-white rounded-full w-8 h-8 flex items-center justify-center mb-3 font-bold",children:"1"}),e.jsx("h3",{className:"font-semibold text-slate-800 mb-2",children:"安装与初始化"}),e.jsx("pre",{className:"bg-blue-100/70 text-blue-900 px-3 py-2 rounded text-xs overflow-hidden",children:e.jsxs("code",{children:["npm install -g autosnippet",`
|
|
55
|
+
`,"cd your-project",`
|
|
56
|
+
`,"asd setup"]})})]}),e.jsxs("div",{className:"bg-green-50 rounded-lg p-4 border border-green-200",children:[e.jsx("div",{className:"bg-green-600 text-white rounded-full w-8 h-8 flex items-center justify-center mb-3 font-bold",children:"2"}),e.jsx("h3",{className:"font-semibold text-slate-800 mb-2",children:"启动 Dashboard"}),e.jsx("pre",{className:"bg-green-100/70 text-green-900 px-3 py-2 rounded text-xs overflow-hidden",children:e.jsx("code",{children:"asd ui"})}),e.jsx("p",{className:"text-slate-600 text-xs mt-2",children:"启动 HTTP API + Dashboard + FileWatcher"})]}),e.jsxs("div",{className:"bg-purple-50 rounded-lg p-4 border border-purple-200",children:[e.jsx("div",{className:"bg-purple-600 text-white rounded-full w-8 h-8 flex items-center justify-center mb-3 font-bold",children:"3"}),e.jsx("h3",{className:"font-semibold text-slate-800 mb-2",children:"IDE 集成"}),e.jsx("pre",{className:"bg-purple-100/70 text-purple-900 px-3 py-2 rounded text-xs overflow-hidden",children:e.jsx("code",{children:"asd upgrade"})}),e.jsx("p",{className:"text-slate-600 text-xs mt-2",children:"安装 MCP + Skills + Cursor Rules"})]}),e.jsxs("div",{className:"bg-amber-50 rounded-lg p-4 border border-amber-200",children:[e.jsx("div",{className:"bg-amber-600 text-white rounded-full w-8 h-8 flex items-center justify-center mb-3 font-bold",children:"4"}),e.jsx("h3",{className:"font-semibold text-slate-800 mb-2",children:"创建第一个 Recipe"}),e.jsxs("p",{className:"text-slate-600 text-sm mb-1",children:["Dashboard → ",e.jsx("strong",{children:"New Recipe"})]}),e.jsx("p",{className:"text-slate-600 text-sm",children:"Use Copied Code → AI 填充 → 保存"})]})]})}),e.jsxs(l,{id:"concepts",title:"核心概念",icon:e.jsx(na,{size:$.xl,className:"text-blue-600"}),children:[e.jsxs("div",{className:"mb-6",children:[e.jsx("h3",{className:"text-lg font-semibold text-slate-700 mb-3",children:"三大角色"}),e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"min-w-full border border-slate-200 rounded-lg text-sm",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"bg-slate-50",children:[e.jsx("th",{className:"px-4 py-3 border-b text-left font-semibold",children:"角色"}),e.jsx("th",{className:"px-4 py-3 border-b text-left font-semibold",children:"职责"}),e.jsx("th",{className:"px-4 py-3 border-b text-left font-semibold",children:"能力"})]})}),e.jsxs("tbody",{children:[e.jsxs("tr",{className:"hover:bg-slate-50",children:[e.jsx("td",{className:"px-4 py-3 border-b font-medium text-blue-700",children:"开发者"}),e.jsx("td",{className:"px-4 py-3 border-b",children:"审核与决策、维护项目标准"}),e.jsxs("td",{className:"px-4 py-3 border-b text-xs",children:["Dashboard 审核候选、保存 Recipe;Snippet 补全、",e.jsx("code",{className:"bg-slate-100 px-1 rounded",children:"// as:search"}),";运行 ",e.jsx("code",{className:"bg-slate-100 px-1 rounded",children:"asd ui"})]})]}),e.jsxs("tr",{className:"hover:bg-slate-50",children:[e.jsx("td",{className:"px-4 py-3 border-b font-medium text-green-700",children:"Cursor Agent"}),e.jsx("td",{className:"px-4 py-3 border-b",children:"按规范生成代码、检索知识库"}),e.jsx("td",{className:"px-4 py-3 border-b text-xs",children:"13 个 Skills 理解规范;38 个 MCP 工具按需检索、提交候选;写操作经 Gateway 审核"})]}),e.jsxs("tr",{className:"hover:bg-slate-50",children:[e.jsx("td",{className:"px-4 py-3 font-medium text-purple-700",children:"ChatAgent"}),e.jsx("td",{className:"px-4 py-3",children:"提取、摘要、扫描、审查"}),e.jsxs("td",{className:"px-4 py-3 text-xs",children:[e.jsx("code",{className:"bg-slate-100 px-1 rounded",children:"asd ais"})," 批量扫描;分析剪贴板;Guard 审查;Dashboard RAG"]})]})]})]})})]}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-semibold text-slate-700 mb-3",children:"核心组件"}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4",children:[e.jsxs("div",{className:"bg-green-50 rounded-lg p-4 border border-green-200",children:[e.jsxs("h4",{className:"font-semibold text-green-900 mb-2 flex items-center gap-2",children:[e.jsx(Qe,{size:$.lg}),"Bootstrap(冷启动)"]}),e.jsx("p",{className:"text-green-800 text-sm mb-3",children:"9 维度自动知识提取引擎"}),e.jsxs("ul",{className:"text-green-700 text-xs space-y-1 list-disc list-inside",children:[e.jsx("li",{children:"扫描 SPM Target + AST 分析源码"}),e.jsx("li",{children:"启发式提取 → AI 精炼 → 生成 Candidate"}),e.jsxs("li",{children:["MCP 工具:",e.jsx("code",{className:"bg-green-100 px-1 rounded",children:"bootstrap_knowledge"})," / ",e.jsx("code",{className:"bg-green-100 px-1 rounded",children:"bootstrap_refine"})]})]})]}),e.jsxs("div",{className:"bg-purple-50 rounded-lg p-4 border border-purple-200",children:[e.jsxs("h4",{className:"font-semibold text-purple-900 mb-2 flex items-center gap-2",children:[e.jsx(Xa,{size:$.lg}),"Candidates(候选)"]}),e.jsx("p",{className:"text-purple-800 text-sm mb-3",children:"待审核的 Recipe 草案"}),e.jsxs("ul",{className:"text-purple-700 text-xs space-y-1 list-disc list-inside",children:[e.jsx("li",{children:"来源:AI 扫描、Cursor、剪贴板、Dashboard"}),e.jsx("li",{children:"审核后入库为 Recipe,确保质量"}),e.jsx("li",{children:"Reasoning 字段记录 AI 推理过程"})]})]}),e.jsxs("div",{className:"bg-blue-50 rounded-lg p-4 border border-blue-200",children:[e.jsxs("h4",{className:"font-semibold text-blue-900 mb-2 flex items-center gap-2",children:[e.jsx(mt,{size:$.lg}),"Recipe(配方)"]}),e.jsx("p",{className:"text-blue-800 text-sm mb-3",children:"Markdown 知识文档(Source of Truth)"}),e.jsxs("ul",{className:"text-blue-700 text-xs space-y-1 list-disc list-inside",children:[e.jsxs("li",{children:["位置:",e.jsx("code",{className:"bg-blue-100 px-1 rounded",children:"AutoSnippet/recipes/*.md"})]}),e.jsx("li",{children:".md 文件 = 唯一数据源,DB 仅作索引缓存"}),e.jsxs("li",{children:[e.jsx("code",{className:"bg-blue-100 px-1 rounded",children:"asd sync"})," 增量同步 .md → DB"]})]})]}),e.jsxs("div",{className:"bg-indigo-50 rounded-lg p-4 border border-indigo-200",children:[e.jsxs("h4",{className:"font-semibold text-indigo-900 mb-2 flex items-center gap-2",children:[e.jsx(Ds,{size:$.lg}),"ChatAgent(智能对话)"]}),e.jsx("p",{className:"text-indigo-800 text-sm mb-3",children:"多 Agent 协作架构,可持续扩展"}),e.jsxs("ul",{className:"text-indigo-700 text-xs space-y-1 list-disc list-inside",children:[e.jsx("li",{children:"AnalystAgent 分析意图 → ProducerAgent 执行操作"}),e.jsx("li",{children:"HandoffProtocol 自动切换 + 轻量记忆持久化"}),e.jsx("li",{children:"项目感知:自动注入知识库状态上下文"})]})]}),e.jsxs("div",{className:"bg-amber-50 rounded-lg p-4 border border-amber-200",children:[e.jsxs("h4",{className:"font-semibold text-amber-900 mb-2 flex items-center gap-2",children:[e.jsx(xt,{size:$.lg}),"4 层检索管线"]}),e.jsx("p",{className:"text-amber-800 text-sm mb-3",children:"多模式语义搜索引擎"}),e.jsxs("ul",{className:"text-amber-700 text-xs space-y-1 list-disc list-inside",children:[e.jsx("li",{children:"InvertedIndex → CoarseRanker → MultiSignalRanker → RetrievalFunnel"}),e.jsx("li",{children:"BM25 + keyword + semantic 三路融合"}),e.jsx("li",{children:"4 个搜索 MCP 工具:search / context / keyword / semantic"})]})]}),e.jsxs("div",{className:"bg-rose-50 rounded-lg p-4 border border-rose-200",children:[e.jsxs("h4",{className:"font-semibold text-rose-900 mb-2 flex items-center gap-2",children:[e.jsx(nt,{size:$.lg}),"Guard(代码审查)"]}),e.jsx("p",{className:"text-rose-800 text-sm mb-3",children:"知识库驱动的代码审查"}),e.jsxs("ul",{className:"text-rose-700 text-xs space-y-1 list-disc list-inside",children:[e.jsx("li",{children:"内建规则 + 自定义规则 + Recipe 关联"}),e.jsxs("li",{children:[e.jsx("code",{className:"bg-rose-100 px-1 rounded",children:"// as:audit"})," 触发 / ",e.jsx("code",{className:"bg-rose-100 px-1 rounded",children:"asd guard <file>"})]}),e.jsxs("li",{children:["MCP:",e.jsx("code",{className:"bg-rose-100 px-1 rounded",children:"guard_check"})," / ",e.jsx("code",{className:"bg-rose-100 px-1 rounded",children:"guard_audit_files"})," / ",e.jsx("code",{className:"bg-rose-100 px-1 rounded",children:"scan_project"})]})]})]})]})]}),e.jsxs("div",{className:"mt-6 bg-gradient-to-r from-blue-50 to-purple-50 rounded-lg p-5 border border-slate-200",children:[e.jsx("h3",{className:"text-lg font-semibold text-slate-700 mb-4",children:"知识库闭环"}),e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[e.jsxs("div",{className:"flex-1 min-w-[100px] text-center",children:[e.jsx("div",{className:"bg-blue-500 text-white rounded-full w-10 h-10 flex items-center justify-center mx-auto mb-2 font-bold text-lg",children:"1"}),e.jsx("p",{className:"text-slate-700 font-medium text-sm",children:"扫描提取"}),e.jsx("p",{className:"text-slate-500 text-xs",children:"AI/Cursor"})]}),e.jsx("div",{className:"text-slate-400 text-2xl",children:"→"}),e.jsxs("div",{className:"flex-1 min-w-[100px] text-center",children:[e.jsx("div",{className:"bg-green-500 text-white rounded-full w-10 h-10 flex items-center justify-center mx-auto mb-2 font-bold text-lg",children:"2"}),e.jsx("p",{className:"text-slate-700 font-medium text-sm",children:"人工审核"}),e.jsx("p",{className:"text-slate-500 text-xs",children:"Dashboard"})]}),e.jsx("div",{className:"text-slate-400 text-2xl",children:"→"}),e.jsxs("div",{className:"flex-1 min-w-[100px] text-center",children:[e.jsx("div",{className:"bg-purple-500 text-white rounded-full w-10 h-10 flex items-center justify-center mx-auto mb-2 font-bold text-lg",children:"3"}),e.jsx("p",{className:"text-slate-700 font-medium text-sm",children:"知识沉淀"}),e.jsx("p",{className:"text-slate-500 text-xs",children:".md 落盘"})]}),e.jsx("div",{className:"text-slate-400 text-2xl",children:"→"}),e.jsxs("div",{className:"flex-1 min-w-[100px] text-center",children:[e.jsx("div",{className:"bg-amber-500 text-white rounded-full w-10 h-10 flex items-center justify-center mx-auto mb-2 font-bold text-lg",children:"4"}),e.jsx("p",{className:"text-slate-700 font-medium text-sm",children:"智能使用"}),e.jsx("p",{className:"text-slate-500 text-xs",children:"Cursor/Xcode"})]}),e.jsx("div",{className:"text-slate-400 text-2xl",children:"→"}),e.jsxs("div",{className:"flex-1 min-w-[100px] text-center",children:[e.jsx("div",{className:"bg-rose-500 text-white rounded-full w-10 h-10 flex items-center justify-center mx-auto mb-2 font-bold text-lg",children:"5"}),e.jsx("p",{className:"text-slate-700 font-medium text-sm",children:"持续优化"}),e.jsx("p",{className:"text-slate-500 text-xs",children:"asd sync"})]})]})]})]}),e.jsx(l,{id:"features",title:"核心功能",icon:e.jsx(Qe,{size:$.xl,className:"text-blue-600"}),children:e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-5",children:[e.jsxs("div",{className:"border border-slate-200 rounded-lg p-5 hover:shadow-lg transition-shadow",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[e.jsx(ps,{size:$.lg,className:"text-blue-600"}),e.jsx("h3",{className:"font-semibold text-slate-800",children:"知识库构建"})]}),e.jsxs("ul",{className:"text-slate-600 text-sm space-y-2 list-disc list-inside",children:[e.jsxs("li",{children:[e.jsx("strong",{children:"AI 扫描"}),":",e.jsx("code",{className:"bg-slate-100 px-1 rounded text-xs",children:"asd ais [Target]"})," 批量提取"]}),e.jsxs("li",{children:[e.jsx("strong",{children:"Cursor 扫描"}),':对 Copilot 说 "扫描 Module"']}),e.jsxs("li",{children:[e.jsx("strong",{children:"手动创建"}),":New Recipe → Use Copied Code"]}),e.jsxs("li",{children:[e.jsx("strong",{children:"编辑器内"}),":复制代码 → ",e.jsx("code",{className:"bg-slate-100 px-1 rounded text-xs",children:"// as:create -c"})]})]})]}),e.jsxs("div",{className:"border border-slate-200 rounded-lg p-5 hover:shadow-lg transition-shadow",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[e.jsx(xt,{size:$.lg,className:"text-blue-600"}),e.jsx("h3",{className:"font-semibold text-slate-800",children:"语义检索"})]}),e.jsxs("ul",{className:"text-slate-600 text-sm space-y-2 list-disc list-inside",children:[e.jsxs("li",{children:[e.jsx("strong",{children:"4 层管线"}),":InvertedIndex → CoarseRanker → MultiSignalRanker → RetrievalFunnel"]}),e.jsxs("li",{children:[e.jsx("strong",{children:"编辑器内"}),":",e.jsx("code",{className:"bg-slate-100 px-1 rounded text-xs",children:"// as:search keyword"})]}),e.jsxs("li",{children:[e.jsx("strong",{children:"Cursor MCP"}),":4 个搜索工具(search / context / keyword / semantic)"]}),e.jsxs("li",{children:[e.jsx("strong",{children:"Dashboard"}),":搜索框支持语义 + 关键词"]})]})]}),e.jsxs("div",{className:"border border-slate-200 rounded-lg p-5 hover:shadow-lg transition-shadow",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[e.jsx(nt,{size:$.lg,className:"text-blue-600"}),e.jsx("h3",{className:"font-semibold text-slate-800",children:"代码审查(Audit)"})]}),e.jsxs("ul",{className:"text-slate-600 text-sm space-y-2 list-disc list-inside",children:[e.jsxs("li",{children:[e.jsx("strong",{children:"文件审查"}),":",e.jsx("code",{className:"bg-slate-100 px-1 rounded text-xs",children:"// as:audit"})]}),e.jsxs("li",{children:[e.jsx("strong",{children:"Target 审查"}),":",e.jsx("code",{className:"bg-slate-100 px-1 rounded text-xs",children:"// as:audit target"})]}),e.jsxs("li",{children:[e.jsx("strong",{children:"合规报告"}),":MCP ",e.jsx("code",{className:"bg-slate-100 px-1 rounded text-xs",children:"compliance_report"})]}),e.jsxs("li",{children:[e.jsx("strong",{children:"Dashboard"}),":Guard 页面可视化审查"]})]})]}),e.jsxs("div",{className:"border border-slate-200 rounded-lg p-5 hover:shadow-lg transition-shadow",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[e.jsx(ht,{size:$.lg,className:"text-blue-600"}),e.jsx("h3",{className:"font-semibold text-slate-800",children:"数据同步"})]}),e.jsxs("ul",{className:"text-slate-600 text-sm space-y-2 list-disc list-inside",children:[e.jsxs("li",{children:[e.jsx("strong",{children:"同步"}),":",e.jsx("code",{className:"bg-slate-100 px-1 rounded text-xs",children:"asd sync"})," .md → DB(增量)"]}),e.jsxs("li",{children:[e.jsx("strong",{children:"Hash 校验"}),":",e.jsx("code",{className:"bg-slate-100 px-1 rounded text-xs",children:"_contentHash"})," 检测手动编辑"]}),e.jsxs("li",{children:[e.jsx("strong",{children:"向量索引"}),":启动时自动构建语义索引"]}),e.jsxs("li",{children:[e.jsx("strong",{children:"依赖图"}),":",e.jsx("code",{className:"bg-slate-100 px-1 rounded text-xs",children:"get_targets"})," / ",e.jsx("code",{className:"bg-slate-100 px-1 rounded text-xs",children:"get_target_files"})," MCP 工具"]})]})]})]})}),e.jsxs(l,{id:"editor-directives",title:"编辑器指令",icon:e.jsx(_s,{size:$.xl,className:"text-blue-600"}),children:[e.jsxs("p",{className:"text-slate-600 text-sm mb-4",children:["需先运行 ",e.jsx("code",{className:"bg-slate-100 px-1 rounded",children:"asd watch"})," 或 ",e.jsx("code",{className:"bg-slate-100 px-1 rounded",children:"asd ui"}),";支持快捷写法 ",e.jsx("code",{className:"bg-slate-100 px-1 rounded",children:"asc"})," ",e.jsx("code",{className:"bg-slate-100 px-1 rounded",children:"ass"})," ",e.jsx("code",{className:"bg-slate-100 px-1 rounded",children:"asa"})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"bg-slate-50 rounded-lg p-4 border border-slate-200",children:[e.jsxs("h4",{className:"font-semibold text-slate-800 mb-2",children:[e.jsx("code",{className:"bg-slate-200 px-2 py-1 rounded",children:"// as:create"})," · ",e.jsx("code",{className:"bg-slate-200 px-2 py-1 rounded",children:"asc"})]}),e.jsx("p",{className:"text-slate-600 text-sm mb-2",children:"创建 Recipe/Snippet"}),e.jsxs("ul",{className:"text-slate-600 text-xs space-y-1 list-disc list-inside",children:[e.jsx("li",{children:"无选项:打开 Dashboard"}),e.jsxs("li",{children:[e.jsx("code",{children:"-c"}),":从剪贴板静默创建"]}),e.jsxs("li",{children:[e.jsx("code",{children:"-f"}),":扫描当前文件"]})]})]}),e.jsxs("div",{className:"bg-slate-50 rounded-lg p-4 border border-slate-200",children:[e.jsxs("h4",{className:"font-semibold text-slate-800 mb-2",children:[e.jsx("code",{className:"bg-slate-200 px-2 py-1 rounded",children:"// as:search"})," · ",e.jsx("code",{className:"bg-slate-200 px-2 py-1 rounded",children:"ass"})]}),e.jsx("p",{className:"text-slate-600 text-sm mb-2",children:"搜索并插入"}),e.jsxs("ul",{className:"text-slate-600 text-xs space-y-1 list-disc list-inside",children:[e.jsx("li",{children:"从知识库检索 Recipe/Snippet"}),e.jsx("li",{children:"选择后插入代码,替换该行"}),e.jsx("li",{children:"记录一次人工使用"})]})]}),e.jsxs("div",{className:"bg-slate-50 rounded-lg p-4 border border-slate-200",children:[e.jsxs("h4",{className:"font-semibold text-slate-800 mb-2",children:[e.jsx("code",{className:"bg-slate-200 px-2 py-1 rounded",children:"// as:audit"})," · ",e.jsx("code",{className:"bg-slate-200 px-2 py-1 rounded",children:"asa"})]}),e.jsx("p",{className:"text-slate-600 text-sm mb-2",children:"代码审查"}),e.jsxs("ul",{className:"text-slate-600 text-xs space-y-1 list-disc list-inside",children:[e.jsx("li",{children:"无后缀:审查当前文件"}),e.jsxs("li",{children:[e.jsx("code",{children:"target"}),":审查当前 Target"]}),e.jsxs("li",{children:[e.jsx("code",{children:"project"}),":审查整个项目"]})]})]}),e.jsxs("div",{className:"bg-slate-50 rounded-lg p-4 border border-slate-200",children:[e.jsxs("h4",{className:"font-semibold text-slate-800 mb-2",children:[e.jsx("code",{className:"bg-slate-200 px-2 py-1 rounded",children:"// as:include"})," · ",e.jsx("code",{className:"bg-slate-200 px-2 py-1 rounded",children:"// as:import"})]}),e.jsx("p",{className:"text-slate-600 text-sm mb-2",children:"自动注入头文件/模块"}),e.jsxs("ul",{className:"text-slate-600 text-xs space-y-1 list-disc list-inside",children:[e.jsx("li",{children:"Snippet 中包含此标记"}),e.jsx("li",{children:"补全后自动注入 import"})]})]})]})]}),e.jsxs(l,{id:"cursor-integration",title:"Cursor AI 集成",icon:e.jsx(Ct,{size:$.xl,className:"text-blue-600"}),children:[e.jsxs("div",{className:"mb-5",children:[e.jsx("h3",{className:"font-semibold text-slate-800 mb-3",children:"10 个 Skills"}),e.jsx("div",{className:"grid grid-cols-2 md:grid-cols-5 gap-2",children:[{name:"intent",desc:"意图路由"},{name:"concepts",desc:"概念教学"},{name:"candidates",desc:"候选提交"},{name:"recipes",desc:"Recipe 检索"},{name:"guard",desc:"代码合规"},{name:"structure",desc:"项目结构"},{name:"analysis",desc:"深度分析"},{name:"coldstart",desc:"冷启动"},{name:"create",desc:"引导创建"},{name:"lifecycle",desc:"生命周期"}].map(n=>e.jsxs("div",{className:"bg-slate-50 border border-slate-200 rounded-lg px-3 py-2 text-center",children:[e.jsx("p",{className:"text-xs font-mono text-blue-600",children:n.name}),e.jsx("p",{className:"text-xs text-slate-500 mt-0.5",children:n.desc})]},n.name))})]}),e.jsxs("div",{className:"mb-5",children:[e.jsx("h3",{className:"font-semibold text-slate-800 mb-3",children:"38 个 MCP 工具"}),e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"min-w-full border border-slate-200 rounded-lg text-xs",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"bg-slate-50",children:[e.jsx("th",{className:"px-3 py-2 border-b text-left",children:"分组"}),e.jsx("th",{className:"px-3 py-2 border-b text-left",children:"工具"}),e.jsx("th",{className:"px-3 py-2 border-b text-left text-center",children:"数量"})]})}),e.jsxs("tbody",{children:[e.jsxs("tr",{children:[e.jsx("td",{className:"px-3 py-2 border-b font-medium",children:"system"}),e.jsxs("td",{className:"px-3 py-2 border-b",children:[e.jsx("code",{children:"health"}),", ",e.jsx("code",{children:"capabilities"})]}),e.jsx("td",{className:"px-3 py-2 border-b text-center",children:"2"})]}),e.jsxs("tr",{children:[e.jsx("td",{className:"px-3 py-2 border-b font-medium",children:"search"}),e.jsxs("td",{className:"px-3 py-2 border-b",children:[e.jsx("code",{children:"search"}),", ",e.jsx("code",{children:"context_search"}),", ",e.jsx("code",{children:"keyword_search"}),", ",e.jsx("code",{children:"semantic_search"})]}),e.jsx("td",{className:"px-3 py-2 border-b text-center",children:"4"})]}),e.jsxs("tr",{children:[e.jsx("td",{className:"px-3 py-2 border-b font-medium",children:"browse"}),e.jsxs("td",{className:"px-3 py-2 border-b",children:[e.jsx("code",{children:"list_rules"}),", ",e.jsx("code",{children:"list_patterns"}),", ",e.jsx("code",{children:"list_facts"}),", ",e.jsx("code",{children:"list_recipes"}),", ",e.jsx("code",{children:"get_recipe"}),", ",e.jsx("code",{children:"recipe_insights"}),", ",e.jsx("code",{children:"compliance_report"}),", ",e.jsx("code",{children:"confirm_usage"})]}),e.jsx("td",{className:"px-3 py-2 border-b text-center",children:"8"})]}),e.jsxs("tr",{children:[e.jsx("td",{className:"px-3 py-2 border-b font-medium",children:"structure"}),e.jsxs("td",{className:"px-3 py-2 border-b",children:[e.jsx("code",{children:"get_targets"}),", ",e.jsx("code",{children:"get_target_files"}),", ",e.jsx("code",{children:"get_target_metadata"}),", ",e.jsx("code",{children:"graph_query"}),", ",e.jsx("code",{children:"graph_impact"}),", ",e.jsx("code",{children:"graph_path"}),", ",e.jsx("code",{children:"graph_stats"})]}),e.jsx("td",{className:"px-3 py-2 border-b text-center",children:"7"})]}),e.jsxs("tr",{children:[e.jsx("td",{className:"px-3 py-2 border-b font-medium",children:"candidate"}),e.jsxs("td",{className:"px-3 py-2 border-b",children:[e.jsx("code",{children:"validate_candidate"}),", ",e.jsx("code",{children:"check_duplicate"}),", ",e.jsx("code",{children:"submit_candidate"}),", ",e.jsx("code",{children:"submit_candidates"}),", ",e.jsx("code",{children:"submit_draft_recipes"}),", ",e.jsx("code",{children:"enrich_candidates"})]}),e.jsx("td",{className:"px-3 py-2 border-b text-center",children:"6"})]}),e.jsxs("tr",{children:[e.jsx("td",{className:"px-3 py-2 border-b font-medium",children:"guard"}),e.jsxs("td",{className:"px-3 py-2 border-b",children:[e.jsx("code",{children:"guard_check"}),", ",e.jsx("code",{children:"guard_audit_files"}),", ",e.jsx("code",{children:"scan_project"})]}),e.jsx("td",{className:"px-3 py-2 border-b text-center",children:"3"})]}),e.jsxs("tr",{children:[e.jsx("td",{className:"px-3 py-2 border-b font-medium",children:"bootstrap"}),e.jsxs("td",{className:"px-3 py-2 border-b",children:[e.jsx("code",{children:"bootstrap_knowledge"}),", ",e.jsx("code",{children:"bootstrap_refine"})]}),e.jsx("td",{className:"px-3 py-2 border-b text-center",children:"2"})]}),e.jsxs("tr",{children:[e.jsx("td",{className:"px-3 py-2 font-medium",children:"skills"}),e.jsxs("td",{className:"px-3 py-2",children:[e.jsx("code",{children:"list_skills"}),", ",e.jsx("code",{children:"load_skill"}),", ",e.jsx("code",{children:"create_skill"}),", ",e.jsx("code",{children:"delete_skill"}),", ",e.jsx("code",{children:"update_skill"}),", ",e.jsx("code",{children:"suggest_skills"})]}),e.jsx("td",{className:"px-3 py-2 text-center",children:"6"})]})]})]})}),e.jsx("p",{className:"text-xs text-slate-500 mt-2",children:"其中 11 个写操作工具(submit_candidate, submit_candidates, submit_draft_recipes, enrich_candidates, guard_audit_files, scan_project, bootstrap_knowledge, bootstrap_refine, create_skill, delete_skill, update_skill)通过 Gateway 权限保护。"})]}),e.jsxs("div",{children:[e.jsx("h3",{className:"font-semibold text-slate-800 mb-3",children:"使用示例"}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"bg-blue-50 rounded p-3 border border-blue-200",children:[e.jsx("p",{className:"font-medium text-blue-900 text-sm mb-1",children:"检索知识库"}),e.jsx("p",{className:"text-blue-800 text-xs",children:'对 Cursor 说:"查找网络请求错误处理的代码"'})]}),e.jsxs("div",{className:"bg-green-50 rounded p-3 border border-green-200",children:[e.jsx("p",{className:"font-medium text-green-900 text-sm mb-1",children:"批量扫描"}),e.jsx("p",{className:"text-green-800 text-xs",children:'对 Cursor 说:"扫描 NetworkModule,生成 Recipes 到候选"'})]}),e.jsxs("div",{className:"bg-purple-50 rounded p-3 border border-purple-200",children:[e.jsx("p",{className:"font-medium text-purple-900 text-sm mb-1",children:"提交代码"}),e.jsx("p",{className:"text-purple-800 text-xs",children:'对 Cursor 说:"把这段代码保存为 Recipe"'})]})]})]})]}),e.jsx(l,{id:"v2-architecture",title:"V2 架构",icon:e.jsx(et,{size:$.xl,className:"text-blue-600"}),children:e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-5",children:[e.jsxs("div",{className:"border border-slate-200 rounded-lg p-5",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[e.jsx(Qe,{size:$.lg,className:"text-indigo-600"}),e.jsx("h3",{className:"font-semibold text-slate-800",children:"Bootstrap 冷启动引擎"})]}),e.jsx("p",{className:"text-slate-600 text-sm mb-2",children:"3 步完成知识库从 0 → 1:"}),e.jsxs("div",{className:"bg-slate-50 rounded p-3 text-xs font-mono text-slate-700 space-y-1",children:[e.jsx("p",{children:"① 项目扫描 → 依赖 / 目录 / 入口分析"}),e.jsx("p",{children:"② AI 批量提取 → Candidate 候选列表"}),e.jsx("p",{children:"③ 审阅 + Promote → Recipe 知识库就绪"})]}),e.jsx("p",{className:"text-slate-500 text-xs mt-2",children:"支持 bootstrap_refine 持续迭代、resume 断点续跑"})]}),e.jsxs("div",{className:"border border-slate-200 rounded-lg p-5",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[e.jsx(xt,{size:$.lg,className:"text-indigo-600"}),e.jsx("h3",{className:"font-semibold text-slate-800",children:"4 层检索管线"})]}),e.jsx("p",{className:"text-slate-600 text-sm mb-2",children:"多信号融合的精准检索:"}),e.jsxs("div",{className:"space-y-2 text-xs",children:[e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsx("span",{className:"bg-blue-100 text-blue-700 px-2 py-0.5 rounded font-medium shrink-0",children:"L1"}),e.jsx("span",{className:"text-slate-600",children:"InvertedIndex — 倒排索引快速召回"})]}),e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsx("span",{className:"bg-green-100 text-green-700 px-2 py-0.5 rounded font-medium shrink-0",children:"L2"}),e.jsx("span",{className:"text-slate-600",children:"CoarseRanker — BM25 + TF-IDF 粗排"})]}),e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsx("span",{className:"bg-amber-100 text-amber-700 px-2 py-0.5 rounded font-medium shrink-0",children:"L3"}),e.jsx("span",{className:"text-slate-600",children:"MultiSignalRanker — 多维信号精排"})]}),e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsx("span",{className:"bg-red-100 text-red-700 px-2 py-0.5 rounded font-medium shrink-0",children:"L4"}),e.jsx("span",{className:"text-slate-600",children:"RetrievalFunnel — 漏斗截断 + 上下文装配"})]})]})]}),e.jsxs("div",{className:"border border-slate-200 rounded-lg p-5",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[e.jsx(Ds,{size:$.lg,className:"text-indigo-600"}),e.jsx("h3",{className:"font-semibold text-slate-800",children:"ChatAgent 对话系统"})]}),e.jsx("p",{className:"text-slate-600 text-sm mb-2",children:"多 Agent 协作架构,可持续扩展:"}),e.jsxs("div",{className:"bg-slate-50 rounded p-3 text-xs text-slate-700 space-y-1.5",children:[e.jsxs("p",{children:[e.jsx("strong",{children:"AnalystAgent"}),":分析用户意图 → 检索知识库 → 给出建议 → 信心信号分级"]}),e.jsxs("p",{children:[e.jsx("strong",{children:"ProducerAgent"}),":生成代码 → 创建候选 → 执行操作 → 结果聚合"]}),e.jsxs("p",{children:[e.jsx("strong",{children:"HandoffProtocol"}),":两个 Agent 之间的自动切换协议"]}),e.jsxs("p",{children:[e.jsx("strong",{children:"轻量记忆"}),":跨对话偏好/决策/上下文持久化(JSONL,TTL 过期)"]}),e.jsxs("p",{children:[e.jsx("strong",{children:"项目感知"}),":自动注入知识库状态(Recipe 分布、候选积压量、Guard 规则数)"]})]})]}),e.jsxs("div",{className:"border border-slate-200 rounded-lg p-5",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[e.jsx(Cs,{size:$.lg,className:"text-indigo-600"}),e.jsx("h3",{className:"font-semibold text-slate-800",children:"五个入口通道"})]}),e.jsxs("div",{className:"space-y-2 text-xs",children:[e.jsxs("div",{className:"flex justify-between bg-slate-50 px-3 py-2 rounded",children:[e.jsx("span",{className:"font-medium",children:"CLI"}),e.jsx("span",{className:"text-slate-500",children:"asd × 10 命令"})]}),e.jsxs("div",{className:"flex justify-between bg-slate-50 px-3 py-2 rounded",children:[e.jsx("span",{className:"font-medium",children:"MCP Server"}),e.jsx("span",{className:"text-slate-500",children:"stdio × 36 工具"})]}),e.jsxs("div",{className:"flex justify-between bg-slate-50 px-3 py-2 rounded",children:[e.jsx("span",{className:"font-medium",children:"HTTP API"}),e.jsx("span",{className:"text-slate-500",children:"Express × 14 路由模块"})]}),e.jsxs("div",{className:"flex justify-between bg-slate-50 px-3 py-2 rounded",children:[e.jsx("span",{className:"font-medium",children:"Dashboard"}),e.jsx("span",{className:"text-slate-500",children:"React 19 + Vite 6 + Tailwind 4"})]}),e.jsxs("div",{className:"flex justify-between bg-slate-50 px-3 py-2 rounded",children:[e.jsx("span",{className:"font-medium",children:"Skills"}),e.jsx("span",{className:"text-slate-500",children:"13 个 Cursor/Copilot"})]})]})]})]})}),e.jsx(l,{id:"cli-reference",title:"命令行速查",icon:e.jsx(_s,{size:$.xl,className:"text-blue-600"}),children:e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"font-semibold text-slate-800 mb-2",children:"初始化与环境"}),e.jsxs("div",{className:"space-y-1 text-sm",children:[e.jsxs("div",{className:"flex justify-between bg-slate-50 px-3 py-2 rounded",children:[e.jsx("code",{children:"asd setup"}),e.jsx("span",{className:"text-slate-500 text-xs",children:"初始化项目"})]}),e.jsxs("div",{className:"flex justify-between bg-slate-50 px-3 py-2 rounded",children:[e.jsx("code",{children:"asd status"}),e.jsx("span",{className:"text-slate-500 text-xs",children:"环境自检"})]}),e.jsxs("div",{className:"flex justify-between bg-slate-50 px-3 py-2 rounded",children:[e.jsx("code",{children:"asd ui"}),e.jsx("span",{className:"text-slate-500 text-xs",children:"启动 Dashboard"})]}),e.jsxs("div",{className:"flex justify-between bg-slate-50 px-3 py-2 rounded",children:[e.jsx("code",{children:"asd upgrade"}),e.jsx("span",{className:"text-slate-500 text-xs",children:"升级 IDE 集成"})]})]})]}),e.jsxs("div",{children:[e.jsx("h3",{className:"font-semibold text-slate-800 mb-2",children:"知识库管理"}),e.jsxs("div",{className:"space-y-1 text-sm",children:[e.jsxs("div",{className:"flex justify-between bg-slate-50 px-3 py-2 rounded",children:[e.jsx("code",{children:"asd sync"}),e.jsx("span",{className:"text-slate-500 text-xs",children:".md → DB 增量同步"})]}),e.jsxs("div",{className:"flex justify-between bg-slate-50 px-3 py-2 rounded",children:[e.jsx("code",{children:"asd ais [Target]"}),e.jsx("span",{className:"text-slate-500 text-xs",children:"AI 扫描提取 Candidates"})]}),e.jsxs("div",{className:"flex justify-between bg-slate-50 px-3 py-2 rounded",children:[e.jsx("code",{children:"asd ais --force"}),e.jsx("span",{className:"text-slate-500 text-xs",children:"强制重新扫描全量"})]}),e.jsxs("div",{className:"flex justify-between bg-slate-50 px-3 py-2 rounded",children:[e.jsx("code",{children:"asd watch"}),e.jsx("span",{className:"text-slate-500 text-xs",children:"文件监控 + 指令触发"})]})]})]}),e.jsxs("div",{children:[e.jsx("h3",{className:"font-semibold text-slate-800 mb-2",children:"搜索与审查"}),e.jsxs("div",{className:"space-y-1 text-sm",children:[e.jsxs("div",{className:"flex justify-between bg-slate-50 px-3 py-2 rounded",children:[e.jsx("code",{children:"asd search <query>"}),e.jsx("span",{className:"text-slate-500 text-xs",children:"搜索知识库"})]}),e.jsxs("div",{className:"flex justify-between bg-slate-50 px-3 py-2 rounded",children:[e.jsx("code",{children:"asd search -m semantic"}),e.jsx("span",{className:"text-slate-500 text-xs",children:"语义搜索模式"})]}),e.jsxs("div",{className:"flex justify-between bg-slate-50 px-3 py-2 rounded",children:[e.jsx("code",{children:"asd guard <file>"}),e.jsx("span",{className:"text-slate-500 text-xs",children:"Guard 规则检查"})]}),e.jsxs("div",{className:"flex justify-between bg-slate-50 px-3 py-2 rounded",children:[e.jsx("code",{children:"asd server"}),e.jsx("span",{className:"text-slate-500 text-xs",children:"单独启动 API 服务"})]})]})]}),e.jsxs("div",{children:[e.jsx("h3",{className:"font-semibold text-slate-800 mb-2",children:"维护与升级"}),e.jsxs("div",{className:"space-y-1 text-sm",children:[e.jsxs("div",{className:"flex justify-between bg-slate-50 px-3 py-2 rounded",children:[e.jsx("code",{children:"asd upgrade"}),e.jsx("span",{className:"text-slate-500 text-xs",children:"升级 MCP / Skills / Rules"})]}),e.jsxs("div",{className:"flex justify-between bg-slate-50 px-3 py-2 rounded",children:[e.jsx("code",{children:"asd install:full"}),e.jsx("span",{className:"text-slate-500 text-xs",children:"全量安装 IDE 集成"})]}),e.jsxs("div",{className:"flex justify-between bg-slate-50 px-3 py-2 rounded",children:[e.jsx("code",{children:"asd sync --force"}),e.jsx("span",{className:"text-slate-500 text-xs",children:"全量重建 DB"})]}),e.jsxs("div",{className:"flex justify-between bg-slate-50 px-3 py-2 rounded",children:[e.jsx("code",{children:"asd sync --dry-run"}),e.jsx("span",{className:"text-slate-500 text-xs",children:"预览同步变更"})]})]})]})]})})]}),e.jsx("div",{className:"mt-8 p-4 bg-blue-50 border border-blue-200 rounded-lg text-center",children:e.jsxs("p",{className:"text-slate-700 text-sm",children:["需要更详细的说明?查看 ",e.jsx("a",{href:"https://github.com/GxFn/AutoSnippet",target:"_blank",rel:"noopener noreferrer",className:"text-blue-600 hover:underline font-medium",children:"GitHub README"})," 或运行 ",e.jsx("code",{className:"bg-blue-100 px-1.5 py-0.5 rounded text-xs",children:"asd status"})," 检查环境"]})})]})};function gr(){const[t,s]=r.useState(null);r.useEffect(()=>{const c=As(),x=p=>{s({status:"running",total:p.total,current:0,progress:0,refined:0,failed:0,items:p.candidateIds.map(u=>({candidateId:u,title:"",status:"pending"}))})},i=p=>{s(u=>u&&{...u,current:p.current,progress:p.progress,items:u.items.map(w=>w.candidateId===p.candidateId?{...w,title:p.title,status:"refining"}:w)})},N=p=>{s(u=>u&&{...u,current:p.current,progress:p.progress,refined:p.refinedSoFar,items:u.items.map(w=>w.candidateId===p.candidateId?{...w,title:p.title,status:"done",refined:p.refined}:w)})},j=p=>{s(u=>u&&{...u,current:p.current,progress:p.progress,failed:u.failed+1,items:u.items.map(w=>w.candidateId===p.candidateId?{...w,title:p.title,status:"failed",error:p.error}:w)})},g=p=>{s(u=>u&&{...u,status:"completed",progress:100,refined:p.refined,failed:p.failed})};return c.on("refine:started",x),c.on("refine:item-started",i),c.on("refine:item-completed",N),c.on("refine:item-failed",j),c.on("refine:completed",g),()=>{c.off("refine:started",x),c.off("refine:item-started",i),c.off("refine:item-completed",N),c.off("refine:item-failed",j),c.off("refine:completed",g)}},[]);const a=r.useCallback(()=>s(null),[]),l=(t==null?void 0:t.status)==="running",n=(t==null?void 0:t.status)==="completed";return{refine:t,isRefining:l,isRefineDone:n,resetRefine:a}}const fr=({refine:t,isRefineDone:s,onDismiss:a})=>{const l=r.useRef(!1);if(r.useEffect(()=>{if(s&&t&&!l.current){l.current=!0;const x=t.failed>0?`${t.refined} 条已更新,${t.failed} 条失败`:`${t.refined}/${t.total} 条候选已更新`;V(x,{title:"AI 润色完成",type:t.failed>0?"error":"success"})}},[s,t]),r.useEffect(()=>{t||(l.current=!1)},[t]),!t)return null;const n=t.items.find(x=>x.status==="refining"),c=t.items.filter(x=>x.status==="done"||x.status==="failed").length;return e.jsxs("div",{className:"bg-white rounded-xl border border-slate-200 shadow-sm p-4 mb-4",children:[e.jsxs("div",{className:"flex items-center justify-between mb-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:`p-1.5 rounded-lg ${s?"bg-emerald-50":"bg-blue-50"}`,children:s?e.jsx(yt,{className:"w-4 h-4 text-emerald-600"}):e.jsx(Ke,{className:"w-4 h-4 text-blue-600"})}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-semibold text-slate-800",children:s?"AI 润色完成":"AI 润色中"}),e.jsxs("p",{className:"text-xs text-slate-500",children:[s?`${t.refined} 条已更新${t.failed>0?`,${t.failed} 条失败`:""}`:`${c}/${t.total} 条候选`,n&&!s&&e.jsxs("span",{className:"ml-2 text-blue-600",children:[e.jsx(Te,{className:"w-3 h-3 inline animate-spin mr-1"}),n.title||n.candidateId.slice(0,8)]})]})]})]}),s&&a&&e.jsx("button",{onClick:a,className:"text-xs px-2.5 py-1 rounded-lg bg-slate-100 hover:bg-slate-200 text-slate-600 transition-colors",children:"关闭"})]}),e.jsx("div",{className:"w-full h-1.5 bg-slate-100 rounded-full overflow-hidden",children:e.jsx("div",{className:`h-full rounded-full transition-all duration-500 ease-out ${s?t.failed>0?"bg-amber-400":"bg-emerald-500":"bg-blue-500"}`,style:{width:`${t.progress}%`}})}),s&&t.failed>0&&e.jsxs("div",{className:"mt-2 text-xs text-red-500 flex items-center gap-1",children:[e.jsx(Ye,{className:"w-3 h-3"}),t.items.filter(x=>x.status==="failed").map(x=>x.title||x.candidateId.slice(0,8)).join("、")]})]})},Ys={_watch:"as:create",_draft:"草稿",_cli:"CLI",_pending:"待审核(24h)",_recipe:"New Recipe"};function jr(t,s,a,l){return[...t].sort(([n],[c])=>{const x=l(n),i=l(c);if(x&&!i)return 1;if(!x&&i)return-1;const N=a(n),j=a(c);if(N&&!j)return-1;if(!N&&j)return 1;const g=s(n),p=s(c);return g&&!p?1:!g&&p?-1:n.localeCompare(c)})}function Dt(t){if(!t)return"";const s=typeof t=="number"?t:Number(t),a=s<1e12?s*1e3:s,l=new Date(a);if(isNaN(l.getTime())||l.getFullYear()<2e3)return"";const c=new Date().getTime()-l.getTime();if(c<0)return l.toLocaleDateString("zh-CN");const x=Math.floor(c/6e4);if(x<1)return"刚刚";if(x<60)return`${x} 分钟前`;const i=Math.floor(x/60);if(i<24)return`${i} 小时前`;const N=Math.floor(i/24);return N<7?`${N} 天前`:l.toLocaleDateString("zh-CN")}function Nr(t,s=4){return t?Ms(t).split(`
|
|
57
|
+
`).slice(0,s).join(`
|
|
58
|
+
`):""}function yr(t){return t==null?{ring:"stroke-slate-200",text:"text-slate-400",bg:"bg-slate-50",label:"—"}:t>=.8?{ring:"stroke-emerald-500",text:"text-emerald-700",bg:"bg-emerald-50",label:"高"}:t>=.6?{ring:"stroke-blue-500",text:"text-blue-700",bg:"bg-blue-50",label:"中"}:t>=.4?{ring:"stroke-amber-500",text:"text-amber-700",bg:"bg-amber-50",label:"中低"}:{ring:"stroke-red-500",text:"text-red-700",bg:"bg-red-50",label:"低"}}const Js={"bootstrap-scan":{label:"AI 全量扫描",color:"text-violet-600 bg-violet-50 border-violet-200"},mcp:{label:"MCP 提交",color:"text-blue-600 bg-blue-50 border-blue-200"},manual:{label:"手动创建",color:"text-emerald-600 bg-emerald-50 border-emerald-200"},"file-watcher":{label:"文件监听",color:"text-orange-600 bg-orange-50 border-orange-200"},clipboard:{label:"剪贴板",color:"text-pink-600 bg-pink-50 border-pink-200"},cli:{label:"CLI",color:"text-slate-600 bg-slate-50 border-slate-200"},agent:{label:"AI Agent",color:"text-violet-600 bg-violet-50 border-violet-200"},submit_with_check:{label:"AI 审查提交",color:"text-teal-600 bg-teal-50 border-teal-200"}},vr=({value:t,size:s=36})=>{const a=(s-6)/2,l=2*Math.PI*a,n=t!=null?Math.max(0,Math.min(1,t)):0,c=l*(1-n),{ring:x,text:i}=yr(t);return e.jsxs("div",{className:"relative flex items-center justify-center",style:{width:s,height:s},children:[e.jsxs("svg",{width:s,height:s,className:"-rotate-90",children:[e.jsx("circle",{cx:s/2,cy:s/2,r:a,fill:"none",stroke:"currentColor",strokeWidth:3,className:"text-slate-100"}),e.jsx("circle",{cx:s/2,cy:s/2,r:a,fill:"none",strokeWidth:3,strokeLinecap:"round",className:x,strokeDasharray:l,strokeDashoffset:c,style:{transition:"stroke-dashoffset 0.5s ease"}})]}),e.jsx("span",{className:`absolute text-[9px] font-bold ${i}`,children:t!=null?`${Math.round(t*100)}`:"—"})]})},wr=({data:t,isShellTarget:s,isSilentTarget:a=()=>!1,isPendingTarget:l=()=>!1,handleDeleteCandidate:n,handleDeleteAllInTarget:c,onAuditCandidate:x,onAuditAllInTarget:i,onEditRecipe:N,onColdStart:j,isScanning:g,isBootstrapping:p,onRefresh:u})=>{var pe;const[w,f]=r.useState(null),{isWide:E,toggle:A}=Ls(),[M,R]=r.useState(new Set),[B,T]=r.useState(new Set),[U,K]=r.useState(!1),[S,q]=r.useState(!1),C=ts(),{refine:m,isRefining:P,isRefineDone:h,resetRefine:d}=gr(),[v,k]=r.useState({}),[ee,L]=r.useState(null),[Z,fe]=r.useState({}),[O,re]=r.useState(null),[ae,ye]=r.useState({}),[oe,Ne]=r.useState({sort:"default",onlySimilar:!1}),[be,Ce]=r.useState(null),Ae=r.useRef(new Set),Fe=r.useCallback(async(o,F)=>{if(!Ae.current.has(F)){Ae.current.add(F),re(F);try{const b=await Y.getCandidateSimilarityEx({targetName:o,candidateId:F});fe(xe=>({...xe,[F]:b.similar||[]}))}catch{fe(xe=>({...xe,[F]:[]}))}finally{re(null)}}},[]),_=r.useCallback(async(o,F,b,xe=[])=>{var me,W,ue,De;const H=b.replace(/\.md$/i,"");let se="";const D=(me=t==null?void 0:t.recipes)==null?void 0:me.find(Le=>Le.name===H||Le.name.endsWith("/"+H));if(D!=null&&D.content)se=[D.content.pattern,D.content.markdown].filter(Boolean).join(`
|
|
59
|
+
|
|
60
|
+
`)||"";else try{se=(await Y.getRecipeContentByName(H)).content}catch(Le){const Re=(W=Le.response)==null?void 0:W.status,qe=((De=(ue=Le.response)==null?void 0:ue.data)==null?void 0:De.message)||Le.message;Re===404?V(`"${H}" 不存在于当前知识库`,{title:"Recipe 不存在",type:"error"}):V(qe,{title:"加载 Recipe 失败",type:"error"});return}const J={[H]:se};f(o.id),Ce({candidate:o,targetName:F,recipeName:H,recipeContent:se,similarList:xe.slice(0,3),recipeContents:J})},[t==null?void 0:t.recipes]),I=t!=null&&t.candidates?Object.entries(t.candidates):[],le=jr(I,s,a,l),we=le.map(([o])=>o),ge=ee&&we.includes(ee)?ee:we[0]??null;r.useEffect(()=>{we.length>0&&(!ee||!we.includes(ee))&&L(we[0])},[we.join(","),ee]),r.useEffect(()=>{w&&ge&&Fe(ge,w)},[w,ge,Fe]);const Me=r.useMemo(()=>{var se;if(!ge||!((se=t==null?void 0:t.candidates)!=null&&se[ge]))return null;const o=t.candidates[ge].items,F=o.length,b=o.reduce((D,J)=>{var me;return D+(((me=J.reasoning)==null?void 0:me.confidence)??0)},0)/(F||1),xe=o.filter(D=>{var J;return((J=D.content)==null?void 0:J.pattern)&&D.content.pattern.trim().length>0}).length,H=new Map;return o.forEach(D=>{const J=D.source||"unknown";H.set(J,(H.get(J)||0)+1)}),{total:F,avgConfidence:b,withCode:xe,sources:H}},[ge,t==null?void 0:t.candidates]),Oe=r.useMemo(()=>{const o=new Map;if(t!=null&&t.idTitleMap)for(const[F,b]of Object.entries(t.idTitleMap))o.set(F,b);if(t!=null&&t.candidates)for(const F of Object.values(t.candidates))for(const b of F.items)b.id&&b.title&&o.set(b.id,b.title);if(t!=null&&t.recipes)for(const F of t.recipes)F.id&&F.name&&o.set(F.id,F.name.replace(/\.md$/i,""));return o},[t==null?void 0:t.idTitleMap,t==null?void 0:t.candidates,t==null?void 0:t.recipes]),Ee=r.useCallback(async o=>{var F,b,xe,H,se;if(!M.has(o)){R(D=>new Set(D).add(o));try{const D=await Y.enrichCandidates([o]);D.enriched>0?V(`已补齐 ${((xe=(b=(F=D.results)==null?void 0:F[0])==null?void 0:b.filledFields)==null?void 0:xe.length)||0} 个结构字段`,{title:"AI 补齐完成"}):V("无缺失字段,均已完整",{title:"无需补齐",type:"info"});try{const J=await Y.getCandidate(o);ye(me=>({...me,[o]:J}))}catch{}}catch(D){V(((se=(H=D.response)==null?void 0:H.data)==null?void 0:se.error)||D.message,{title:"AI 补齐失败",type:"error"})}finally{R(D=>{const J=new Set(D);return J.delete(o),J})}}},[M,u]),y=r.useCallback(async()=>{var F,b,xe;if(U||!ge||!((F=t==null?void 0:t.candidates)!=null&&F[ge]))return;const o=t.candidates[ge].items;if(o.length!==0){K(!0);try{let H=0;for(let se=0;se<o.length;se+=20){const D=o.slice(se,se+20).map(me=>me.id),J=await Y.enrichCandidates(D);H+=J.enriched}V(`${H}/${o.length} 条候选已更新`,{title:"① 结构补齐完成"}),u==null||u()}catch(H){V(((xe=(b=H.response)==null?void 0:b.data)==null?void 0:xe.error)||H.message,{title:"① 结构补齐失败",type:"error"})}finally{K(!1)}}},[U,ge,t==null?void 0:t.candidates,u]),de=r.useCallback(async o=>{try{const F=await Y.getCandidate(o);ye(b=>({...b,[o]:F}))}catch{}},[]),ce=r.useCallback(()=>{var b;if(!ge||!((b=t==null?void 0:t.candidates)!=null&&b[ge]))return;const o=t.candidates[ge].items,F=o.map(xe=>xe.id);C.openRefine({candidateIds:F,candidates:o,onCandidateUpdated:de})},[ge,t==null?void 0:t.candidates,C,de]),te=r.useCallback(o=>{var b;if(!ge||!((b=t==null?void 0:t.candidates)!=null&&b[ge]))return;Ce(null),f(o);const F=t.candidates[ge].items;C.openRefine({candidateIds:[o],candidates:F,onCandidateUpdated:de})},[ge,t==null?void 0:t.candidates,C,de]);return e.jsxs("div",{className:"flex-1 flex flex-col overflow-hidden",children:[e.jsxs("div",{className:"mb-4 flex justify-between items-center shrink-0",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-10 h-10 rounded-xl bg-blue-50 border border-blue-100 flex items-center justify-center",children:e.jsx(Ke,{className:"text-blue-600",size:20})}),e.jsxs("div",{children:[e.jsx("h2",{className:"text-xl font-bold text-slate-800",children:"AI Scan Candidates"}),e.jsx("p",{className:"text-xs text-slate-400 mt-0.5",children:"AI 批量扫描后生成的候选内容,等待审核入库"})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[j&&!p&&e.jsxs("button",{onClick:j,disabled:g,className:`flex items-center gap-1.5 px-3.5 py-2 rounded-lg text-xs font-bold transition-all ${g?"text-slate-400 bg-slate-100 cursor-not-allowed":"text-white bg-gradient-to-r from-violet-500 to-purple-600 hover:from-violet-600 hover:to-purple-700 shadow-sm hover:shadow"}`,title:"冷启动:结构收集 + 9 维度 Candidate 创建(与 MCP 一致)",children:[g?e.jsx(Te,{size:14,className:"animate-spin"}):e.jsx(Bt,{size:14}),g?"初始化中...":"冷启动"]}),Me&&Me.total>0&&e.jsxs("button",{onClick:y,disabled:U||S,className:`flex items-center gap-1.5 px-3 py-2 rounded-lg text-xs font-bold transition-all ${U||S?"text-slate-400 bg-slate-100 cursor-not-allowed":"text-amber-700 bg-amber-50 border border-amber-200 hover:bg-amber-100"}`,title:"① 结构补齐:填充缺失的 rationale / knowledgeType / complexity / scope / steps / constraints(只填空不覆盖,建议先于润色执行)",children:[U?e.jsx(Te,{size:14,className:"animate-spin"}):e.jsx(cs,{size:14}),U?"补齐中...":"① 结构补齐"]}),Me&&Me.total>0&&e.jsxs("button",{onClick:ce,disabled:S||U||P,className:`flex items-center gap-1.5 px-3 py-2 rounded-lg text-xs font-bold transition-all ${S||U||P?"text-slate-400 bg-slate-100 cursor-not-allowed":"text-emerald-700 bg-emerald-50 border border-emerald-200 hover:bg-emerald-100"}`,title:"② 内容润色:改善 summary 描述、补充架构洞察、推断 relations 关联、调整 confidence 评分(逐条 AI 精炼,建议在结构补齐之后执行)",children:[S||P?e.jsx(Te,{size:14,className:"animate-spin"}):e.jsx(Ke,{size:14}),S||P?"润色中...":"② 内容润色"]}),Me&&e.jsxs("div",{className:"flex items-center gap-3 text-xs",children:[e.jsxs("div",{className:"flex items-center gap-1.5 px-3 py-1.5 rounded-lg bg-slate-50 border border-slate-100",children:[e.jsx(Za,{size:14,className:"text-slate-400"}),e.jsxs("span",{className:"text-slate-500",children:["共 ",e.jsx("strong",{className:"text-slate-700",children:Me.total})," 条"]}),Me.withCode<Me.total&&e.jsxs("span",{className:"text-slate-400 ml-1",children:["(含代码 ",Me.withCode,")"]})]}),e.jsxs("div",{className:"flex items-center gap-1.5 px-3 py-1.5 rounded-lg bg-emerald-50 border border-emerald-100",children:[e.jsx("span",{className:"text-emerald-500",children:"平均置信度"}),e.jsxs("strong",{className:"text-emerald-700",children:[Math.round(Me.avgConfidence*100),"%"]})]})]})]})]}),m&&e.jsx(fr,{refine:m,isRefineDone:h,onDismiss:()=>{d(),u==null||u()}}),I.length>0&&e.jsx("div",{className:"shrink-0 bg-white border border-slate-100 rounded-xl px-3 py-2 mb-4 shadow-sm",children:e.jsx("div",{className:"flex items-center gap-1.5 overflow-x-auto no-scrollbar",children:we.map(o=>{var J;s(o);const F=a(o),b=Ys[o],xe=t.candidates[o],H=((J=xe==null?void 0:xe.items)==null?void 0:J.length)??0,se=ge===o,D=lt[o]||lt.All;return e.jsxs("button",{onClick:()=>L(o),className:`flex items-center gap-2 px-3 py-2 rounded-lg text-sm font-bold whitespace-nowrap transition-all border
|
|
61
|
+
${se?`${(D==null?void 0:D.bg)||"bg-blue-50"} ${(D==null?void 0:D.color)||"text-blue-700"} ${(D==null?void 0:D.border)||"border-blue-200"} shadow-sm ring-1 ring-inset ${(D==null?void 0:D.border)||"ring-blue-200"}`:"bg-slate-50/80 text-slate-600 border-slate-100 hover:border-slate-200 hover:bg-slate-100"}`,children:[(()=>{const me=(D==null?void 0:D.icon)||us;return e.jsx(me,{size:$.sm,className:se?"":"text-slate-400"})})(),e.jsx("span",{children:Bs[o]||o}),F&&b&&e.jsx("span",{className:"text-[9px] text-amber-600 border border-amber-200 px-1 rounded",children:b}),e.jsx("span",{className:`text-[10px] font-normal rounded-full px-1.5 ${se?"bg-white/60":"bg-slate-200/60 text-slate-400"}`,children:H})]},o)})})}),e.jsxs("div",{className:"flex-1 overflow-y-auto pr-1",children:[(!(t!=null&&t.candidates)||Object.keys(t.candidates).length===0)&&!p&&e.jsxs("div",{className:"h-72 flex flex-col items-center justify-center bg-white rounded-2xl border border-dashed border-slate-200 text-slate-400",children:[e.jsx("div",{className:"w-16 h-16 rounded-2xl bg-slate-50 flex items-center justify-center mb-4",children:e.jsx(ma,{size:32,className:"text-slate-300"})}),e.jsx("p",{className:"text-sm font-medium text-slate-500",children:"未发现候选内容"}),e.jsx("p",{className:"mt-2 text-xs max-w-sm text-center leading-relaxed text-slate-400",children:"点击下方按钮冷启动知识库,或使用 CLI 命令手动创建"}),j&&e.jsxs("button",{onClick:j,disabled:g,className:`mt-4 flex items-center gap-2 px-5 py-2.5 rounded-xl text-sm font-bold transition-all ${g?"text-slate-400 bg-slate-100 cursor-not-allowed":"text-white bg-gradient-to-r from-violet-500 to-purple-600 hover:from-violet-600 hover:to-purple-700 shadow-md hover:shadow-lg"}`,children:[g?e.jsx(Te,{size:16,className:"animate-spin"}):e.jsx(Bt,{size:16}),g?"正在初始化...":"冷启动:初始化知识库"]}),e.jsxs("p",{className:"mt-3 text-[11px] text-slate-400",children:["或 ",e.jsx("code",{className:"text-blue-600 bg-blue-50 px-1 rounded",children:"asd ais --all"})," 全量扫描 ·",e.jsx("code",{className:"text-blue-600 bg-blue-50 px-1 rounded ml-1",children:"asd candidate"})," 从剪贴板创建"]})]}),(!(t!=null&&t.candidates)||Object.keys(t.candidates).length===0)&&p&&e.jsxs("div",{className:"h-72 flex flex-col items-center justify-center bg-white rounded-2xl border border-dashed border-violet-200 text-slate-400",children:[e.jsx("div",{className:"w-16 h-16 rounded-2xl bg-violet-50 flex items-center justify-center mb-4",children:e.jsx(Te,{size:32,className:"text-violet-400 animate-spin"})}),e.jsx("p",{className:"text-sm font-medium text-violet-600",children:"冷启动正在进行中…"}),e.jsx("p",{className:"mt-2 text-xs max-w-sm text-center leading-relaxed text-slate-400",children:"各维度知识正在后台提取并接受 AI 审查,完成后候选内容将自动展示"})]}),t&&ge&&le.filter(([o])=>o===ge).map(([o,F])=>{const b=s(o),xe=a(o),H=Ys[o]||"静默",se=v[o]||{page:1,pageSize:12},D=se.page,J=se.pageSize,me=F.items.filter(G=>{var ze;if(oe.onlySimilar){const He=(ze=G.relations)==null?void 0:ze.related;if(!Array.isArray(He)||He.length===0)return!1}return!0}).sort((G,ze)=>{var He,Be,Xe,je,Pe,Ge;if(oe.sort==="default")return 0;if(oe.sort==="score-desc")return(((He=ze.quality)==null?void 0:He.overall)??0)-(((Be=G.quality)==null?void 0:Be.overall)??0);if(oe.sort==="score-asc")return(((Xe=G.quality)==null?void 0:Xe.overall)??0)-(((je=ze.quality)==null?void 0:je.overall)??0);if(oe.sort==="confidence-desc")return(((Pe=ze.reasoning)==null?void 0:Pe.confidence)??0)-(((Ge=G.reasoning)==null?void 0:Ge.confidence)??0);if(oe.sort==="date-desc"){const _e=typeof G.createdAt=="number"?G.createdAt:0;return(typeof ze.createdAt=="number"?ze.createdAt:0)-_e}return 0}),W=me.length,ue=Math.ceil(W/J),De=(D-1)*J,Le=me.slice(De,De+J),Re=G=>{k(ze=>({...ze,[o]:{...se,page:G}}))},qe=G=>{k(ze=>({...ze,[o]:{page:1,pageSize:G}}))},We=lt[o]||lt.All;return e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center gap-3 px-4 py-2.5 rounded-xl bg-white border border-slate-100 shadow-sm",children:[e.jsxs("div",{className:"flex items-center gap-2 flex-1 min-w-0",children:[(()=>{const G=(We==null?void 0:We.icon)||us;return e.jsx(G,{size:18,className:(We==null?void 0:We.color)||"text-blue-600"})})(),e.jsx("span",{className:"text-base font-bold text-slate-800 truncate",children:Bs[o]||o}),xe&&e.jsx("span",{className:"text-[10px] font-bold text-amber-600 border border-amber-200 bg-amber-50 px-1.5 py-0.5 rounded",children:H}),b&&!xe&&e.jsx("span",{className:"text-[10px] font-bold text-slate-400 border border-slate-200 bg-slate-50 px-1.5 py-0.5 rounded",children:"SHELL"}),e.jsxs("span",{className:"text-[11px] text-slate-400 flex items-center gap-1",children:[e.jsx(it,{size:11}),"扫描于 ",Dt(F.scanTime)||new Date(F.scanTime).toLocaleString()]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("div",{className:"flex items-center gap-1 px-2 py-1 rounded-lg bg-slate-50 border border-slate-100",children:[e.jsx(xa,{size:12,className:"text-slate-400"}),e.jsxs("select",{className:"text-[11px] font-medium bg-transparent border-none outline-none text-slate-600 pr-1 cursor-pointer",value:oe.sort,onChange:G=>Ne(ze=>({...ze,sort:G.target.value})),children:[e.jsx("option",{value:"default",children:"默认排序"}),e.jsx("option",{value:"score-desc",children:"综合分 高→低"}),e.jsx("option",{value:"score-asc",children:"综合分 低→高"}),e.jsx("option",{value:"confidence-desc",children:"置信度 高→低"}),e.jsx("option",{value:"date-desc",children:"最新优先"})]})]}),e.jsxs("label",{className:"text-[11px] font-medium text-slate-500 flex items-center gap-1.5 px-2 py-1 rounded-lg bg-slate-50 border border-slate-100 cursor-pointer hover:bg-slate-100 transition-colors select-none",children:[e.jsx("input",{type:"checkbox",checked:oe.onlySimilar,onChange:G=>Ne(ze=>({...ze,onlySimilar:G.target.checked})),className:"rounded text-blue-600 w-3 h-3"}),"只看相似"]}),(oe.sort!=="default"||oe.onlySimilar)&&e.jsx("button",{onClick:()=>Ne({sort:"default",onlySimilar:!1}),className:"text-[11px] font-medium text-slate-500 hover:text-slate-700 px-2 py-1 rounded-lg border border-slate-200 bg-white hover:bg-slate-50 transition-colors",children:"重置"})]}),e.jsx("div",{className:"h-5 w-px bg-slate-200"}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsxs("span",{className:"text-[11px] text-slate-400 font-medium",children:[W," 条"]}),e.jsx("button",{onClick:()=>i(Le,o),className:"text-[11px] font-bold text-blue-600 hover:text-blue-700 px-2.5 py-1.5 rounded-lg hover:bg-blue-50 transition-colors",children:"当前页进入审核"}),e.jsx("button",{onClick:async()=>{if(!window.confirm(`确定移除当前页的 ${Le.length} 条候选?`))return;const ze=(await Promise.allSettled(Le.map(He=>n(o,He.id)))).filter(He=>He.status==="rejected").length;ze>0&&V(`${ze} 条候选移除时出错`,{title:"部分删除失败",type:"error"}),u==null||u()},className:"text-[11px] font-bold text-orange-500 hover:text-orange-600 px-2.5 py-1.5 rounded-lg hover:bg-orange-50 transition-colors",children:"移除当前页"}),e.jsx("button",{onClick:()=>c(o),className:"text-[11px] font-bold text-red-500 hover:text-red-600 px-2.5 py-1.5 rounded-lg hover:bg-red-50 transition-colors border border-red-200",children:"全部删除"})]})]}),e.jsx("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-3",children:Le.map(G=>{var ne,X,he,ie,$e;const ze=w===G.id,He=((ne=G.reasoning)==null?void 0:ne.confidence)??null,Be=(((X=G.quality)==null?void 0:X.overall)??0)>0?G.quality.overall:null,je=(((he=G.relations)==null?void 0:he.related)||[])[0],Pe=Z[G.id]||[],Ge=Js[G.source||""]||{label:G.source||"",color:"text-slate-500 bg-slate-50 border-slate-200"},_e=lt[G.category||""]||lt.All||{},z=((_e==null?void 0:_e.color)||"text-blue-600").replace("text-","border-l-");return e.jsxs("div",{onClick:()=>f(ze?null:G.id),className:`bg-white rounded-xl border overflow-hidden hover:shadow-lg transition-all duration-200 flex flex-col group cursor-pointer
|
|
62
|
+
${b?"opacity-75":""}
|
|
63
|
+
${ze?"ring-2 ring-blue-300 border-blue-300 shadow-md":"border-slate-200 hover:border-slate-300"}`,children:[e.jsx("div",{className:`border-l-[4px] ${z} px-4 pt-3.5 pb-2`,children:e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-1.5 mb-1.5",children:[e.jsxs("span",{className:`text-[10px] font-bold px-1.5 py-0.5 rounded uppercase flex items-center gap-1 border ${(_e==null?void 0:_e.bg)||"bg-slate-50"} ${(_e==null?void 0:_e.color)||"text-slate-400"} ${(_e==null?void 0:_e.border)||"border-slate-100"}`,children:[(()=>{const ve=(_e==null?void 0:_e.icon)||et;return e.jsx(ve,{size:10})})(),G.category||"general"]}),G.knowledgeType&&e.jsx("span",{className:"text-[10px] font-medium px-1.5 py-0.5 rounded bg-indigo-50 text-indigo-600 border border-indigo-100",children:G.knowledgeType}),G.source&&G.source!=="unknown"&&e.jsx("span",{className:`text-[10px] font-medium px-1.5 py-0.5 rounded border ${Ge.color}`,children:Ge.label}),G.complexity&&e.jsx("span",{className:`text-[10px] font-medium px-1.5 py-0.5 rounded border
|
|
64
|
+
${G.complexity==="advanced"?"bg-red-50 text-red-600 border-red-100":G.complexity==="intermediate"?"bg-amber-50 text-amber-600 border-amber-100":"bg-emerald-50 text-emerald-600 border-emerald-100"}`,children:G.complexity==="advanced"?"高级":G.complexity==="intermediate"?"中级":"初级"})]}),e.jsx("h3",{className:"font-bold text-sm text-slate-800 leading-snug mb-1 line-clamp-1",children:G.title}),e.jsx("p",{className:"text-xs text-slate-500 line-clamp-2 leading-relaxed",children:G.description||""})]}),e.jsxs("div",{className:"flex flex-col items-center gap-1 shrink-0",children:[e.jsx(vr,{value:He}),e.jsx("span",{className:"text-[9px] text-slate-400 font-medium",children:"置信度"})]})]})}),((ie=G.reasoning)==null?void 0:ie.whyStandard)&&!/^Submitted via /i.test(G.reasoning.whyStandard)&&e.jsx("div",{className:"px-4 py-2 bg-gradient-to-r from-indigo-50/50 to-transparent border-t border-indigo-50",children:e.jsxs("div",{className:"flex items-start gap-1.5",children:[e.jsx(Yt,{size:12,className:"text-indigo-400 mt-0.5 shrink-0"}),e.jsx("p",{className:"text-[11px] text-indigo-600/80 line-clamp-1 leading-relaxed",children:G.reasoning.whyStandard})]})}),(Be!=null||je)&&e.jsxs("div",{className:"flex flex-wrap items-center gap-1.5 px-4 py-2 border-t border-slate-50",children:[Be!=null&&e.jsxs("span",{className:"text-[10px] font-bold px-2 py-0.5 rounded-full bg-emerald-50 text-emerald-700 border border-emerald-200 flex items-center gap-1",children:[e.jsx(es,{size:10}),"综合 ",(Be*100).toFixed(0),"%"]}),je&&e.jsxs("button",{onClick:ve=>{ve.stopPropagation();const ke=String(je.target||"").trim();ke&&_(G,o,ke,Pe)},className:"text-[10px] font-bold px-2 py-0.5 rounded-full bg-amber-50 text-amber-700 border border-amber-200 hover:bg-amber-100 transition-colors flex items-center gap-1",title:"点击对比相似 Recipe",children:[e.jsx(ds,{size:10}),"相似 ",Oe.get(String(je.target||""))||String(je.target||"").replace(/\.md$/i,"")]})]}),(($e=G.content)==null?void 0:$e.pattern)&&e.jsxs("div",{className:"overflow-hidden border-t border-slate-200/60",children:[e.jsxs("div",{className:"flex items-center justify-between px-3 py-1.5",style:{background:"#282c34"},children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Mt,{size:11,className:"text-slate-500"}),e.jsx("span",{className:"text-[10px] text-slate-400 font-mono uppercase tracking-wide",children:G.language||"code"})]}),e.jsxs("span",{className:"text-[10px] text-slate-500 font-mono tabular-nums",children:[G.content.pattern.split(`
|
|
65
|
+
`).length," 行"]})]}),e.jsxs("div",{className:"relative max-h-[80px] overflow-hidden",children:[e.jsx(rt,{code:Nr(G.content.pattern,3),language:G.language==="objc"?"objectivec":G.language,className:"!rounded-none"}),G.content.pattern.split(`
|
|
66
|
+
`).length>3&&e.jsx("div",{className:"absolute bottom-0 left-0 right-0 h-6 bg-gradient-to-t from-[#282c34] to-transparent pointer-events-none"})]})]}),e.jsxs("div",{className:"flex justify-between items-center px-4 py-2.5 border-t border-slate-100 bg-slate-50/50 mt-auto",onClick:ve=>ve.stopPropagation(),children:[e.jsxs("div",{className:"flex items-center gap-2 flex-wrap min-w-0",children:[G.trigger&&e.jsx("span",{className:"text-[10px] font-mono px-2 py-0.5 rounded-md bg-white border border-slate-200 text-slate-600 font-bold",children:G.trigger}),e.jsx("span",{className:"text-[10px] uppercase font-bold text-slate-400 bg-white border border-slate-200 px-1.5 py-0.5 rounded-md",children:G.language}),G.tags&&G.tags.length>0&&G.tags.slice(0,3).map((ve,ke)=>e.jsx("span",{className:"text-[9px] px-1.5 py-0.5 rounded-md bg-blue-50 text-blue-600 border border-blue-100 font-medium",children:typeof ve=="string"?ve:String(ve)},ke)),G.tags&&G.tags.length>3&&e.jsxs("span",{className:"text-[9px] text-slate-400",children:["+",G.tags.length-3]}),G.createdAt&&Dt(G.createdAt)&&e.jsxs("span",{className:"text-[9px] text-slate-400 flex items-center gap-0.5",children:[e.jsx(it,{size:9}),Dt(G.createdAt)]})]}),e.jsxs("div",{className:"flex items-center gap-1.5 shrink-0",children:[e.jsx("button",{onClick:()=>Ee(G.id),disabled:M.has(G.id),title:"① 结构补齐:填充缺失的语义字段(rationale / knowledgeType / complexity 等)",className:`p-1.5 rounded-lg transition-colors flex items-center gap-1 text-[11px] font-medium ${M.has(G.id)?"text-slate-300 cursor-not-allowed":"text-amber-500 hover:text-amber-600 hover:bg-amber-50"}`,children:M.has(G.id)?e.jsx(Te,{size:14,className:"animate-spin"}):e.jsx(cs,{size:14})}),e.jsx("button",{onClick:()=>te(G.id),disabled:B.has(G.id),title:"② 内容润色:改善描述、补充洞察、推断关联(支持自定义提示词)",className:`p-1.5 rounded-lg transition-colors flex items-center gap-1 text-[11px] font-medium ${B.has(G.id)?"text-slate-300 cursor-not-allowed":"text-emerald-500 hover:text-emerald-600 hover:bg-emerald-50"}`,children:B.has(G.id)?e.jsx(Te,{size:14,className:"animate-spin"}):e.jsx(Ke,{size:14})}),e.jsx("button",{onClick:()=>{n(o,G.id),w===G.id&&(f(null),Ce(null))},title:"忽略",className:"p-1.5 hover:bg-red-50 text-slate-400 hover:text-red-500 rounded-lg transition-colors",children:e.jsx(st,{size:14})}),e.jsxs("button",{onClick:()=>x(G,o),className:"text-[11px] font-bold text-blue-600 hover:text-blue-700 px-3 py-1.5 rounded-lg bg-blue-50 hover:bg-blue-100 transition-colors flex items-center gap-1",children:[e.jsx(jt,{size:12})," 审核并保存"]}),G.lifecycle==="pending"&&e.jsxs("button",{onClick:async()=>{try{await Y.promoteCandidateToRecipe(G.id),V("已成功发布为正式 Recipe",{title:"发布成功"}),u==null||u()}catch(ve){V(ve.message,{title:"发布失败",type:"error"})}},className:"text-[11px] font-bold text-emerald-600 hover:text-emerald-700 px-3 py-1.5 rounded-lg bg-emerald-50 hover:bg-emerald-100 transition-colors flex items-center gap-1",title:"一键发布为 Recipe",children:[e.jsx(Bt,{size:12})," 发布"]})]})]})]},G.id)})}),W>12&&e.jsx(Rs,{currentPage:D,totalPages:ue,totalItems:W,pageSize:J,onPageChange:Re,onPageSizeChange:qe})]},o)})]}),w&&ge&&((pe=t==null?void 0:t.candidates)==null?void 0:pe[ge])&&(()=>{var We,G,ze,He,Be,Xe;const o=t.candidates[ge].items,F=o.find(je=>je.id===w);if(!F)return null;const b=ae[w]||F,xe=o.findIndex(je=>je.id===w),H=xe>0,se=xe<o.length-1,D=()=>{H&&(f(o[xe-1].id),Ce(null))},J=()=>{se&&(f(o[xe+1].id),Ce(null))},me=b.reasoning,W=(me==null?void 0:me.whyStandard)&&!/^Submitted via /i.test(me.whyStandard),ue=me&&(W||me.sources&&me.sources.length>0||me.confidence!=null),De=Z[b.id]||[],Le=O===b.id,Re=lt[b.category||""]||lt.All||{},qe=Js[b.source||""]||{label:b.source||"",color:"text-slate-500 bg-slate-50 border-slate-200"};return e.jsxs(Ve,{className:"z-30 flex justify-end",onClick:()=>{f(null),Ce(null)},children:[e.jsx(Ve.Backdrop,{className:"bg-black/15 backdrop-blur-[1px]"}),be&&(()=>{const je=be.candidate,Pe=je.language==="objc"||je.language==="objective-c"?"objectivec":je.language||"text",Ge=()=>{var $e,ve;const ie=[];($e=je.content)!=null&&$e.pattern&&ie.push("## Snippet / Code Reference\n\n```"+Pe+`
|
|
67
|
+
`+je.content.pattern+"\n```"),(ve=je.content)!=null&&ve.markdown?ie.push(`
|
|
68
|
+
## 项目特写
|
|
69
|
+
|
|
70
|
+
`+je.content.markdown):je.doClause&&ie.push(`
|
|
71
|
+
## AI Context / Usage Guide
|
|
72
|
+
|
|
73
|
+
`+je.doClause),navigator.clipboard.writeText(ie.join(`
|
|
74
|
+
`)||"").then(()=>V("候选内容已复制到剪贴板",{title:"已复制"}))},_e=()=>{const ie=Es(be.recipeContent);navigator.clipboard.writeText(ie).then(()=>V("Recipe 内容已复制到剪贴板",{title:"已复制"}))},z=async ie=>{var ve;if(ie===be.recipeName)return;const $e=be.recipeContents[ie];if($e)Ce(ke=>ke?{...ke,recipeName:ie,recipeContent:$e}:null);else{let ke="";const Ie=(ve=t==null?void 0:t.recipes)==null?void 0:ve.find(Se=>Se.name===ie||Se.name.endsWith("/"+ie));if(Ie!=null&&Ie.content)ke=[Ie.content.pattern,Ie.content.markdown].filter(Boolean).join(`
|
|
75
|
+
|
|
76
|
+
`)||"";else try{ke=(await Y.getRecipeContentByName(ie)).content}catch{return}Ce(Se=>Se?{...Se,recipeName:ie,recipeContent:ke,recipeContents:{...Se.recipeContents,[ie]:ke}}:null)}},ne=async()=>{if(window.confirm("确定删除该候选?"))try{await n(be.targetName,je.id),Ce(null)}catch(ie){V((ie==null?void 0:ie.message)||"删除失败",{title:"删除失败",type:"error"})}},X=()=>{x(je,be.targetName),Ce(null)},he=()=>{var $e;const ie=($e=t==null?void 0:t.recipes)==null?void 0:$e.find(ve=>ve.name===be.recipeName||ve.name.endsWith("/"+be.recipeName));ie?N==null||N(ie):N==null||N({name:be.recipeName,content:{markdown:be.recipeContent}}),Ce(null)};return e.jsxs("div",{className:`relative h-full bg-white shadow-2xl flex flex-col border-l border-slate-200 ${E?"w-[800px] max-w-[55vw]":"w-[600px] max-w-[45vw]"}`,style:{animation:"slideInRight 0.2s ease-out"},onClick:ie=>ie.stopPropagation(),children:[e.jsxs("div",{className:"flex items-center justify-between px-5 py-3.5 border-b border-slate-200 shrink-0 bg-emerald-50/60",children:[e.jsxs("div",{className:"flex items-center gap-3 flex-1 min-w-0",children:[e.jsx("div",{className:"w-8 h-8 rounded-lg bg-gradient-to-br from-emerald-500 to-teal-600 flex items-center justify-center",children:e.jsx(ds,{size:16,className:"text-white"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("h3",{className:"font-bold text-sm text-emerald-800 truncate",children:"Recipe 对比"}),e.jsx("span",{className:"text-[11px] text-emerald-600 truncate block",children:be.recipeName.replace(/\.md$/i,"")})]})]}),e.jsxs("div",{className:"flex items-center gap-1.5 shrink-0 ml-2",children:[e.jsx("button",{onClick:()=>_e(),className:"p-1.5 hover:bg-emerald-100 rounded-lg text-emerald-600 transition-colors",title:"复制",children:e.jsx(Et,{size:14})}),e.jsx("button",{onClick:he,className:"text-[11px] font-medium text-emerald-600 hover:bg-emerald-100 px-2 py-1.5 rounded-lg transition-colors",children:"审核 Recipe"}),e.jsx("button",{onClick:()=>Ce(null),className:"p-1.5 hover:bg-slate-200 rounded-lg transition-colors text-slate-400",children:e.jsx(Ye,{size:16})})]})]}),be.similarList.length>1&&e.jsx("div",{className:"flex flex-wrap gap-1 px-5 py-2 border-b border-slate-100 bg-white shrink-0",children:be.similarList.map(ie=>e.jsxs("button",{onClick:()=>z(ie.recipeName),className:`text-[10px] font-bold px-2 py-1 rounded transition-colors ${be.recipeName===ie.recipeName?"bg-emerald-200 text-emerald-800":"bg-white text-emerald-600 hover:bg-emerald-50 border border-emerald-100"}`,children:[ie.recipeName.replace(/\.md$/i,"")," ",(ie.similarity*100).toFixed(0),"%"]},ie.recipeName))}),e.jsxs("div",{className:"flex items-center gap-1.5 px-5 py-2 border-b border-slate-100 bg-white shrink-0",children:[e.jsxs("button",{onClick:ne,className:"text-xs font-medium text-red-600 hover:bg-red-50 px-2.5 py-1.5 rounded-lg transition-colors flex items-center gap-1",children:[e.jsx(st,{size:12})," 删除候选"]}),e.jsxs("button",{onClick:X,className:"text-xs font-medium text-blue-600 hover:bg-blue-50 px-2.5 py-1.5 rounded-lg transition-colors flex items-center gap-1",children:[e.jsx(jt,{size:12})," 审核候选"]}),e.jsxs("button",{onClick:()=>Ge(),className:"text-xs font-medium text-slate-500 hover:bg-slate-50 px-2.5 py-1.5 rounded-lg transition-colors flex items-center gap-1",children:[e.jsx(Et,{size:12})," 复制候选"]})]}),e.jsx("div",{className:"flex-1 overflow-auto p-5 min-h-0",children:e.jsx(ut,{content:be.recipeContent,stripFrontmatter:!0})})]})})(),e.jsxs("div",{className:`relative h-full bg-white shadow-2xl flex flex-col border-l border-slate-200 ${E?"w-[960px] max-w-[92vw]":"w-[700px] max-w-[92vw]"}`,style:{animation:"slideInRight 0.25s ease-out"},onClick:je=>je.stopPropagation(),children:[e.jsxs("div",{className:"flex items-center justify-between px-5 py-3 border-b border-slate-200 bg-gradient-to-b from-white to-slate-50/50 shrink-0",children:[e.jsx("div",{className:"flex-1 min-w-0 mr-3",children:e.jsx("h3",{className:"font-bold text-slate-800 text-lg leading-snug break-words",children:b.title})}),e.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[e.jsx("button",{onClick:D,disabled:!H,className:"p-1.5 hover:bg-slate-100 rounded-lg transition-colors disabled:opacity-30",title:"上一条",children:e.jsx(Zt,{size:$.md})}),e.jsxs("span",{className:"text-xs text-slate-400 tabular-nums",children:[xe+1,"/",o.length]}),e.jsx("button",{onClick:J,disabled:!se,className:"p-1.5 hover:bg-slate-100 rounded-lg transition-colors disabled:opacity-30",title:"下一条",children:e.jsx(at,{size:$.md})}),e.jsx("div",{className:"w-px h-5 bg-slate-200 mx-1"}),e.jsx("button",{onClick:A,className:"p-1.5 hover:bg-slate-100 rounded-lg transition-colors text-slate-400",title:E?"收窄":"展宽",children:E?e.jsx(Is,{size:$.md}):e.jsx(hs,{size:$.md})}),e.jsx("button",{onClick:()=>{n(ge,b.id),f(null),Ce(null)},className:"p-1.5 hover:bg-red-50 rounded-lg text-red-500 transition-colors",title:"删除",children:e.jsx(st,{size:$.md})}),e.jsx("button",{onClick:()=>{f(null),Ce(null)},className:"p-1.5 hover:bg-slate-100 rounded-lg transition-colors",children:e.jsx(Ye,{size:$.md})})]})]}),e.jsxs("div",{className:"flex-1 overflow-y-auto",children:[e.jsxs("div",{className:"px-6 py-4 border-b border-slate-100 space-y-3",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-1.5",children:[e.jsx("span",{className:`text-[10px] font-bold px-1.5 py-0.5 rounded uppercase flex items-center gap-1 border ${(Re==null?void 0:Re.bg)||"bg-slate-50"} ${(Re==null?void 0:Re.color)||"text-slate-400"} ${(Re==null?void 0:Re.border)||"border-slate-100"}`,children:b.category||"general"}),b.knowledgeType&&e.jsx("span",{className:"text-[10px] font-medium px-1.5 py-0.5 rounded bg-purple-50 text-purple-700 border border-purple-200",children:b.knowledgeType}),b.language&&e.jsx("span",{className:"text-[10px] uppercase font-bold text-slate-500 bg-slate-50 border border-slate-200 px-1.5 py-0.5 rounded",children:b.language}),b.complexity&&e.jsx("span",{className:`text-[10px] font-medium px-1.5 py-0.5 rounded border ${b.complexity==="advanced"?"bg-red-50 text-red-600 border-red-100":b.complexity==="intermediate"?"bg-amber-50 text-amber-600 border-amber-100":"bg-emerald-50 text-emerald-600 border-emerald-100"}`,children:b.complexity==="advanced"?"高级":b.complexity==="intermediate"?"中级":"初级"}),b.trigger&&e.jsx("span",{className:"text-[10px] font-mono px-1.5 py-0.5 rounded bg-amber-50 text-amber-700 border border-amber-200 font-bold",children:b.trigger}),b.source&&b.source!=="unknown"&&e.jsx("span",{className:`text-[10px] font-medium px-1.5 py-0.5 rounded border ${qe.color}`,children:qe.label}),b.lifecycle&&b.lifecycle!=="pending"&&e.jsx("span",{className:"text-[10px] font-medium px-1.5 py-0.5 rounded bg-blue-50 text-blue-600 border border-blue-200",children:b.lifecycle})]}),e.jsx("div",{className:"flex flex-wrap gap-x-5 gap-y-2 text-xs",children:(()=>{const je=[];return b.scope&&je.push({icon:kt,iconClass:"text-teal-400",label:"范围",value:b.scope==="universal"?"通用":b.scope==="project-specific"?"项目级":b.scope==="module-level"?"模块级":b.scope}),b.source&&b.source!=="unknown"&&je.push({icon:kt,iconClass:"text-violet-400",label:"来源",value:qe.label}),b.createdAt&&Dt(b.createdAt)&&je.push({icon:it,iconClass:"text-slate-400",label:"创建",value:Dt(b.createdAt)}),je.map((Pe,Ge)=>{const _e=Pe.icon;return e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(_e,{size:11,className:`${Pe.iconClass} shrink-0`}),e.jsx("span",{className:"text-slate-400",children:Pe.label}),e.jsx("span",{className:`font-medium text-slate-600 ${Pe.mono?"font-mono text-[11px]":""}`,children:Pe.value})]},Ge)})})()})]}),b.tags&&b.tags.length>0&&e.jsxs("div",{className:"px-6 py-3 border-b border-slate-100 flex flex-wrap items-center gap-1.5",children:[e.jsx(Ut,{size:11,className:"text-slate-300 mr-0.5"}),b.tags.slice(0,10).map((je,Pe)=>e.jsx("span",{className:"text-[9px] px-2 py-0.5 rounded bg-blue-50 text-blue-600 border border-blue-100 font-medium",children:typeof je=="string"?je:String(je)},Pe))]}),b.description&&e.jsxs("div",{className:"px-6 py-4 border-b border-slate-100",children:[e.jsx("label",{className:"text-[10px] font-bold text-slate-400 uppercase mb-1.5 block",children:"摘要"}),e.jsx("p",{className:"text-sm text-slate-600 leading-relaxed",children:b.description})]}),ue&&e.jsxs("div",{className:"px-6 py-4 border-b border-slate-100",children:[e.jsxs("label",{className:"text-[10px] font-bold text-slate-400 uppercase mb-2 block flex items-center gap-1.5",children:[e.jsx(bt,{size:11,className:"text-amber-400"})," 推理依据"]}),e.jsxs("div",{className:"bg-amber-50/30 border border-amber-100 rounded-xl p-4 space-y-2.5",children:[me.whyStandard&&!/^Submitted via /i.test(me.whyStandard)&&e.jsx("p",{className:"text-sm text-slate-700 leading-relaxed",children:me.whyStandard}),me.sources&&me.sources.length>0&&e.jsxs("div",{className:"flex flex-wrap items-center gap-1.5",children:[e.jsx("span",{className:"text-[10px] text-slate-400 font-bold",children:"来源:"}),me.sources.map((je,Pe)=>e.jsx("code",{className:"text-[10px] px-2 py-0.5 bg-white border border-amber-200 rounded text-amber-700 font-mono",children:je},Pe))]}),me.confidence!=null&&me.confidence>0&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-[10px] text-slate-400 font-bold",children:"置信度:"}),e.jsx("div",{className:"flex-1 max-w-[160px] h-1.5 bg-slate-200 rounded-full overflow-hidden",children:e.jsx("div",{className:"h-full bg-amber-400 rounded-full",style:{width:`${Math.round((me.confidence??0)*100)}%`}})}),e.jsxs("span",{className:"text-[10px] font-bold text-amber-600",children:[Math.round((me.confidence??0)*100),"%"]})]}),me.alternatives&&me.alternatives.length>0&&e.jsxs("div",{className:"flex flex-wrap items-center gap-1.5 pt-1",children:[e.jsx("span",{className:"text-[10px] text-slate-400 font-bold",children:"备选:"}),me.alternatives.map((je,Pe)=>e.jsx("span",{className:"text-[10px] px-1.5 py-0.5 bg-slate-100 border border-slate-200 rounded text-slate-600",children:je},Pe))]})]})]}),b.quality&&b.quality.grade&&b.quality.grade!=="F"&&e.jsxs("div",{className:"px-6 py-3 border-b border-slate-100",children:[e.jsx("label",{className:"text-[10px] font-bold text-slate-400 uppercase mb-2 block",children:"质量评级"}),e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx("span",{className:`text-2xl font-black ${b.quality.grade==="A"?"text-emerald-600":b.quality.grade==="B"?"text-blue-600":b.quality.grade==="C"?"text-amber-600":b.quality.grade==="D"?"text-orange-600":"text-slate-400"}`,children:b.quality.grade}),e.jsxs("div",{className:"flex-1 grid grid-cols-3 gap-2 text-[10px]",children:[b.quality.completeness!=null&&b.quality.completeness>0&&e.jsxs("div",{className:"text-center",children:[e.jsx("div",{className:"font-bold text-slate-700",children:b.quality.completeness}),e.jsx("div",{className:"text-slate-400",children:"完整性"})]}),b.quality.adaptation!=null&&b.quality.adaptation>0&&e.jsxs("div",{className:"text-center",children:[e.jsx("div",{className:"font-bold text-slate-700",children:b.quality.adaptation}),e.jsx("div",{className:"text-slate-400",children:"适配度"})]}),b.quality.documentation!=null&&b.quality.documentation>0&&e.jsxs("div",{className:"text-center",children:[e.jsx("div",{className:"font-bold text-slate-700",children:b.quality.documentation}),e.jsx("div",{className:"text-slate-400",children:"文档度"})]})]})]})]}),(()=>{const je=b.relations?Object.entries(b.relations).flatMap(([Ge,_e])=>Array.isArray(_e)?_e.map(z=>({...z,type:Ge})):[]):[];return b.agentNotes||b.aiInsight||je.length>0?e.jsxs("div",{className:"px-6 py-4 border-b border-slate-100",children:[e.jsxs("label",{className:"text-[10px] font-bold text-slate-400 uppercase mb-2 block flex items-center gap-1.5",children:[e.jsx(Ke,{size:11,className:"text-emerald-400"})," 润色增强信息"]}),e.jsxs("div",{className:"bg-emerald-50/30 border border-emerald-100 rounded-xl p-4 space-y-2.5 text-xs",children:[b.aiInsight&&e.jsxs("div",{children:[e.jsx("span",{className:"text-[10px] text-slate-400 font-bold",children:"架构洞察:"}),e.jsx("p",{className:"text-sm text-slate-700 leading-relaxed mt-0.5",children:b.aiInsight})]}),b.agentNotes&&b.agentNotes.length>0&&e.jsxs("div",{children:[e.jsx("span",{className:"text-[10px] text-slate-400 font-bold",children:"Agent 笔记:"}),e.jsx("ul",{className:"mt-1 space-y-0.5",children:b.agentNotes.map((Ge,_e)=>e.jsxs("li",{className:"flex items-start gap-1.5 text-slate-600",children:[e.jsx("span",{className:"text-emerald-400 mt-0.5",children:"•"}),Ge]},_e))})]}),je.length>0&&e.jsxs("div",{children:[e.jsx("span",{className:"text-[10px] text-slate-400 font-bold",children:"关联关系:"}),e.jsx("div",{className:"mt-1 space-y-1",children:je.map((Ge,_e)=>e.jsxs("div",{className:"flex items-start gap-1.5 text-slate-600",children:[e.jsx("span",{className:"text-[9px] font-bold px-1 py-0.5 rounded bg-emerald-100 text-emerald-700 shrink-0 uppercase",children:Ge.type}),e.jsx("span",{className:"font-medium text-slate-700",children:Oe.get(Ge.target)||Ge.target}),Ge.description&&e.jsxs("span",{className:"text-slate-400",children:["— ",Ge.description]})]},_e))})]})]})]}):null})(),(De.length>0||Le)&&e.jsxs("div",{className:"px-6 py-3 border-b border-slate-100",children:[e.jsx("label",{className:"text-[10px] font-bold text-slate-400 uppercase mb-2 block",children:"相似 Recipe"}),e.jsx("div",{className:"flex flex-wrap gap-1.5",children:Le?e.jsx("span",{className:"text-[10px] text-slate-400 animate-pulse",children:"加载中..."}):De.slice(0,5).map(je=>e.jsxs("button",{onClick:()=>_(b,ge,je.recipeName,De),className:"text-[10px] font-bold px-2 py-1 rounded-lg bg-amber-50 text-amber-700 border border-amber-200 hover:bg-amber-100 transition-colors flex items-center gap-1",title:`与 ${je.recipeName} 相似 ${(je.similarity*100).toFixed(0)}%`,children:[e.jsx(ds,{size:10}),je.recipeName.replace(/\.md$/i,"")," ",(je.similarity*100).toFixed(0),"%"]},je.recipeName))})]}),((We=b.content)==null?void 0:We.pattern)&&e.jsxs("div",{className:"px-6 py-4 border-b border-slate-100",children:[e.jsxs("label",{className:"text-[10px] font-bold text-slate-400 uppercase mb-2 block flex items-center gap-1.5",children:[e.jsx(mt,{size:11,className:"text-emerald-500"})," 代码 / 标准用法"]}),e.jsx(rt,{code:b.content.pattern,language:b.language==="objc"?"objectivec":b.language,showLineNumbers:!0})]}),((G=b.content)==null?void 0:G.markdown)&&e.jsxs("div",{className:"px-6 py-4 border-b border-slate-100",children:[e.jsxs("label",{className:"text-[10px] font-bold text-slate-400 uppercase mb-2 block flex items-center gap-1.5",children:[e.jsx(tt,{size:11,className:"text-blue-400"})," Markdown 文档"]}),e.jsx("div",{className:"bg-blue-50/30 border border-blue-100 rounded-xl p-4",children:e.jsx("div",{className:"markdown-body text-sm text-slate-700 leading-relaxed",children:e.jsx(ut,{content:b.content.markdown})})})]}),(b.doClause||b.whenClause||b.dontClause||b.topicHint||b.coreCode)&&e.jsxs("div",{className:"px-6 py-4 border-b border-slate-100",children:[e.jsxs("label",{className:"text-[10px] font-bold text-slate-400 uppercase mb-2 block flex items-center gap-1.5",children:[e.jsx(et,{size:11,className:"text-indigo-400"})," Cursor Delivery"]}),e.jsxs("div",{className:"bg-indigo-50/30 border border-indigo-100 rounded-xl p-4 text-xs space-y-1.5",children:[b.topicHint&&e.jsxs("div",{children:[e.jsx("span",{className:"text-indigo-500 font-medium",children:"Topic:"}),e.jsx("span",{className:"text-slate-700",children:b.topicHint})]}),b.whenClause&&e.jsxs("div",{children:[e.jsx("span",{className:"text-blue-500 font-medium",children:"When:"}),e.jsx("span",{className:"text-slate-700",children:b.whenClause})]}),b.doClause&&e.jsxs("div",{children:[e.jsx("span",{className:"text-emerald-500 font-medium",children:"Do:"}),e.jsx("span",{className:"text-slate-700",children:b.doClause})]}),b.dontClause&&e.jsxs("div",{children:[e.jsx("span",{className:"text-red-500 font-medium",children:"Don't:"}),e.jsx("span",{className:"text-slate-700",children:b.dontClause})]}),b.coreCode&&e.jsxs("div",{children:[e.jsx("span",{className:"text-purple-500 font-medium",children:"Core Code:"}),e.jsx("div",{className:"mt-1",children:e.jsx(rt,{code:b.coreCode,language:b.language==="objectivec"||b.language==="objc"?"objectivec":b.language||"swift"})})]})]})]}),(b.scope||b.headers&&b.headers.length>0||((ze=b.content)==null?void 0:ze.steps)&&b.content.steps.length>0||((He=b.content)==null?void 0:He.rationale))&&e.jsxs(e.Fragment,{children:[((Be=b.content)==null?void 0:Be.rationale)&&e.jsxs("div",{className:"px-6 py-4 border-b border-slate-100",children:[e.jsx("label",{className:"text-[10px] font-bold text-slate-400 uppercase mb-2 block",children:"设计原理"}),e.jsx("div",{className:"bg-slate-50 border border-slate-100 rounded-xl p-4",children:e.jsx("p",{className:"text-sm text-slate-600 leading-relaxed",children:b.content.rationale})})]}),b.headers&&b.headers.length>0&&e.jsxs("div",{className:"px-6 py-3 border-b border-slate-100",children:[e.jsx("label",{className:"text-[10px] font-bold text-slate-400 uppercase mb-2 block",children:"导入头文件"}),e.jsx("div",{className:"flex flex-wrap gap-1.5",children:b.headers.map((je,Pe)=>e.jsx("code",{className:"px-2.5 py-1 bg-violet-50 text-violet-700 border border-violet-100 rounded-md text-[10px] font-mono font-medium",children:je},Pe))})]}),((Xe=b.content)==null?void 0:Xe.steps)&&b.content.steps.length>0&&e.jsxs("div",{className:"px-6 py-4 border-b border-slate-100",children:[e.jsx("label",{className:"text-[10px] font-bold text-slate-400 uppercase mb-2 block",children:"实施步骤"}),e.jsx("div",{className:"space-y-2",children:b.content.steps.map((je,Pe)=>{if(typeof je=="string")return e.jsxs("div",{className:"bg-slate-50 rounded-lg p-3 border border-slate-100 flex items-start gap-2.5",children:[e.jsx("span",{className:"text-[10px] font-bold text-blue-600 bg-blue-50 rounded-full w-5 h-5 flex items-center justify-center shrink-0 mt-0.5",children:Pe+1}),e.jsx("p",{className:"text-xs text-slate-700 leading-relaxed",children:je})]},Pe);const Ge=typeof je.title=="string"?je.title:"",_e=typeof je.description=="string"?je.description:"",z=typeof je.code=="string"?je.code:"";return e.jsxs("div",{className:"bg-slate-50 rounded-lg p-3 border border-slate-100",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[e.jsx("span",{className:"text-[10px] font-bold text-blue-600 bg-blue-50 rounded-full w-5 h-5 flex items-center justify-center shrink-0",children:Pe+1}),Ge&&e.jsx("span",{className:"text-xs font-bold text-slate-700",children:Ge})]}),_e&&e.jsx("p",{className:"text-xs text-slate-600 ml-7 leading-relaxed",children:_e}),z&&e.jsx("pre",{className:"text-[11px] font-mono bg-slate-800 text-green-300 p-2.5 rounded-md mt-1.5 ml-7 overflow-x-auto whitespace-pre-wrap",children:z})]},Pe)})})]})]})]}),e.jsxs("div",{className:"shrink-0 border-t border-slate-200 px-5 py-3 bg-gradient-to-b from-slate-50/80 to-white flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("button",{onClick:()=>Ee(b.id),disabled:M.has(b.id),title:"① 结构补齐",className:`flex items-center gap-1.5 px-3 py-2 rounded-lg text-xs font-medium transition-colors ${M.has(b.id)?"text-slate-300 cursor-not-allowed":"text-amber-600 hover:bg-amber-50 border border-amber-200"}`,children:[M.has(b.id)?e.jsx(Te,{size:14,className:"animate-spin"}):e.jsx(cs,{size:14}),"补齐"]}),e.jsxs("button",{onClick:()=>te(b.id),disabled:B.has(b.id),title:"② 内容润色",className:`flex items-center gap-1.5 px-3 py-2 rounded-lg text-xs font-medium transition-colors ${B.has(b.id)?"text-slate-300 cursor-not-allowed":"text-emerald-600 hover:bg-emerald-50 border border-emerald-200"}`,children:[B.has(b.id)?e.jsx(Te,{size:14,className:"animate-spin"}):e.jsx(Ke,{size:14}),"润色"]}),e.jsxs("button",{onClick:()=>{n(ge,b.id),f(null),Ce(null)},title:"忽略",className:"flex items-center gap-1.5 px-3 py-2 rounded-lg text-xs font-medium text-red-500 hover:bg-red-50 border border-red-200 transition-colors",children:[e.jsx(st,{size:14})," 删除"]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[b.lifecycle==="pending"&&e.jsxs("button",{onClick:async()=>{try{await Y.promoteCandidateToRecipe(b.id),V("已成功发布为正式 Recipe",{title:"发布成功"}),u==null||u()}catch(je){V(je.message,{title:"发布失败",type:"error"})}},className:"flex items-center gap-1.5 px-4 py-2 rounded-lg text-xs font-bold text-emerald-700 bg-emerald-50 hover:bg-emerald-100 border border-emerald-200 transition-colors",children:[e.jsx(Bt,{size:14})," 发布"]}),e.jsxs("button",{onClick:()=>{x(b,ge),f(null),Ce(null)},className:"flex items-center gap-1.5 px-4 py-2 rounded-lg text-xs font-bold text-white bg-blue-600 hover:bg-blue-700 transition-colors shadow-sm",children:[e.jsx(jt,{size:14})," 审核并保存"]})]})]})]})]})})()]})},kr=({isOpen:t,onClose:s,currentFile:a,targetName:l,language:n="swift",onSelectRecipe:c})=>{var K,S,q,C;const[x,i]=r.useState(""),[N,j]=r.useState([]),[g,p]=r.useState(null),[u,w]=r.useState(!1),[f,E]=r.useState(null),[A,M]=r.useState(!1),[R,B]=r.useState(null),T=async()=>{if(x.trim()){w(!0);try{const m=await Y.search(x,{context:{language:n},limit:10});j((m.items||[]).map(P=>{var h,d,v;return{name:(P.title||P.name||"")+".md",content:((h=P.content)==null?void 0:h.pattern)||((d=P.content)==null?void 0:d.markdown)||((v=P.content)==null?void 0:v.code)||"",similarity:P.score||0,authority:P.authorityScore||0,matchType:P.matchType||"ranked",qualityScore:P.qualityScore||0,usageCount:P.usageCount||0}})),p(null)}catch(m){console.error("Context-aware search failed:",m),alert("搜索失败。请重试。")}finally{w(!1)}}},U=m=>{m.key==="Enter"&&T()};return t?e.jsxs(Ve,{className:"z-30 flex",children:[e.jsx(Ve.Backdrop,{className:"bg-black/20"}),e.jsxs("div",{className:"relative w-full max-w-2xl ml-auto bg-white shadow-xl flex flex-col max-h-screen",children:[e.jsxs("div",{className:"border-b border-slate-200 p-6",children:[e.jsxs("div",{className:"flex items-center justify-between mb-4",children:[e.jsx("h2",{className:"text-xl font-bold text-slate-900",children:"智能搜索"}),e.jsx("button",{onClick:s,className:"p-1 hover:bg-slate-100 rounded-lg transition-colors",children:e.jsx(Ye,{size:$.lg,className:"text-slate-500"})})]}),g&&e.jsx("div",{className:"mb-4 p-3 bg-blue-50 border border-blue-200 rounded-lg text-sm",children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(Qe,{size:$.md,className:"text-blue-600 mt-0.5 shrink-0"}),e.jsxs("div",{className:"flex-1",children:[((K=g.targetInfo)==null?void 0:K.targetName)&&e.jsxs("div",{className:"text-blue-900 font-medium flex items-center gap-2 mb-1",children:[e.jsx(vs,{size:$.sm}),"Target: ",g.targetInfo.targetName]}),((S=g.fileInfo)==null?void 0:S.imports)&&g.fileInfo.imports.length>0&&e.jsxs("div",{className:"text-blue-800 text-xs mt-2",children:[e.jsx("strong",{children:"导入的框架:"})," ",g.fileInfo.imports.slice(0,3).join(", "),g.fileInfo.imports.length>3&&` +${g.fileInfo.imports.length-3}`]}),((q=g.targetInfo)==null?void 0:q.suggestedApis)&&g.targetInfo.suggestedApis.length>0&&e.jsxs("div",{className:"text-blue-800 text-xs mt-1",children:[e.jsx("strong",{children:"相关 APIs:"})," ",g.targetInfo.suggestedApis.slice(0,3).join(", ")]})]})]})}),e.jsxs("div",{className:"relative",children:[e.jsx(xt,{className:"absolute left-3 top-1/2 -translate-y-1/2 text-slate-400",size:$.md}),e.jsx("input",{type:"text",placeholder:"输入搜索关键词...",value:x,onChange:m=>i(m.target.value),onKeyDown:U,className:"w-full pl-10 pr-4 py-2 border border-slate-300 rounded-lg text-sm outline-none focus:ring-2 focus:ring-blue-500/20 transition-all"})]}),e.jsxs("button",{onClick:T,disabled:!x.trim()||u,className:"mt-3 w-full py-2 bg-blue-600 text-white rounded-lg text-sm font-medium hover:bg-blue-700 disabled:bg-blue-300 transition-colors flex items-center justify-center gap-2",children:[u&&e.jsx(Te,{size:$.sm,className:"animate-spin"}),u?"搜索中...":"搜索"]})]}),e.jsxs("div",{className:"flex-1 overflow-auto",children:[N.length===0&&!u&&e.jsx("div",{className:"flex items-center justify-center h-full text-slate-500",children:e.jsxs("div",{className:"text-center",children:[e.jsx(ps,{size:$.xxl,className:"mx-auto mb-2 opacity-50"}),e.jsx("p",{className:"text-sm",children:"输入关键词后点击搜索"})]})}),N.map((m,P)=>e.jsxs("div",{className:"border-b border-slate-200 p-4 hover:bg-slate-50 transition-colors cursor-pointer",onClick:()=>{E(f===P?null:P),m.name&&(c==null||c(m.name))},children:[e.jsxs("div",{className:"flex items-start justify-between mb-2",children:[e.jsxs("div",{className:"flex-1",children:[e.jsx("h3",{className:"font-semibold text-slate-900 text-sm",children:m.name}),e.jsxs("div",{className:"flex items-center gap-2 mt-1 flex-wrap",children:[e.jsxs("span",{className:"inline-flex items-center gap-1 px-2 py-0.5 bg-slate-100 rounded text-xs text-slate-600",children:[e.jsx(Qe,{size:$.xs}),Math.round(m.similarity*100),"%"]}),m.isContextRelevant&&e.jsxs("span",{className:"inline-flex items-center gap-1 px-2 py-0.5 bg-green-100 rounded text-xs text-green-700",children:[e.jsx(vs,{size:$.xs}),"上下文相关"]}),m.matchType&&e.jsx("span",{className:"text-xs text-slate-500",children:m.matchType==="semantic"?"语义匹配":"关键词匹配"})]})]}),e.jsx("button",{onClick:h=>{h.stopPropagation(),E(f===P?null:P)},className:"p-1 hover:bg-slate-200 rounded transition-colors",children:f===P?"▼":"▶"})]}),m.stats&&e.jsxs("div",{className:"text-xs text-slate-500 mb-2 flex gap-3",children:[m.stats.authorityScore!==void 0&&e.jsxs("span",{children:["权威分: ",m.stats.authorityScore]}),m.usageCount!==void 0&&e.jsxs("span",{children:["使用: ",m.usageCount,"次"]})]}),f===P&&e.jsxs("div",{className:"mt-3 pt-3 border-t border-slate-200",children:[m.recommendReason&&e.jsxs("div",{className:"text-xs text-slate-600 bg-blue-50 p-2 rounded mb-2 border border-blue-100",children:[e.jsx("p",{className:"font-medium text-blue-700 mb-0.5",children:"推荐理由"}),e.jsx("p",{children:m.recommendReason})]}),e.jsxs("div",{className:"text-xs text-slate-600 max-h-[200px] overflow-auto bg-slate-50 p-3 rounded",children:[m.content.substring(0,500),"..."]}),e.jsx("button",{onClick:h=>{h.stopPropagation(),B(m),M(!0)},className:"mt-2 w-full py-1.5 bg-blue-50 text-blue-600 rounded text-xs font-medium hover:bg-blue-100 transition-colors",children:"查看完整内容"})]})]},P)),u&&e.jsx("div",{className:"flex items-center justify-center h-32",children:e.jsx(Te,{size:$.lg,className:"animate-spin text-blue-600"})}),N.length===0&&x&&!u&&e.jsx("div",{className:"flex items-center justify-center h-32",children:e.jsxs("div",{className:"text-center text-slate-500",children:[e.jsx(Kt,{size:$.xl,className:"mx-auto mb-2 opacity-50"}),e.jsx("p",{className:"text-sm",children:"未找到匹配的结果"})]})})]})]}),A&&R&&e.jsxs(Ve,{className:"z-40 flex items-center justify-center p-4",children:[e.jsx(Ve.Backdrop,{className:"bg-black/40"}),e.jsxs("div",{className:"relative bg-white rounded-lg shadow-2xl w-full max-w-2xl max-h-[90vh] flex flex-col overflow-hidden",children:[e.jsxs("div",{className:"border-b border-slate-200 p-6 flex items-start justify-between shrink-0",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-bold text-slate-900",children:R.name}),e.jsxs("div",{className:"flex items-center gap-4 mt-2",children:[e.jsxs("span",{className:"text-xs bg-blue-100 text-blue-700 px-2 py-1 rounded",children:["相似度: ",Math.round(R.similarity*100),"%"]}),R.isContextRelevant&&e.jsx("span",{className:"text-xs bg-green-100 text-green-700 px-2 py-1 rounded",children:"✓ 上下文相关"}),R.qualityScore!==void 0&&e.jsxs("span",{className:"inline-flex items-center gap-1 px-2 py-0.5 bg-blue-100 rounded text-xs text-blue-700 font-medium",children:["🤖 质量: ",(R.qualityScore*100).toFixed(0),"%"]}),((C=R.stats)==null?void 0:C.authorityScore)!==void 0&&e.jsxs("span",{className:"text-xs bg-purple-100 text-purple-700 px-2 py-1 rounded",children:["权威分: ",Math.round(R.stats.authorityScore*100)/100]})]})]}),e.jsx("button",{onClick:()=>M(!1),className:"p-1 hover:bg-slate-100 rounded transition-colors shrink-0",children:e.jsx(Ye,{size:$.lg,className:"text-slate-500"})})]}),e.jsx("div",{className:"overflow-auto flex-1 p-6",children:e.jsx("div",{className:"prose prose-sm max-w-none",children:R.content?e.jsx(rt,{code:R.content,language:"markdown"}):e.jsx("p",{className:"text-slate-500 text-sm",children:"无内容"})})}),e.jsxs("div",{className:"border-t border-slate-200 p-4 bg-slate-50 flex justify-end gap-2 shrink-0",children:[e.jsx("button",{onClick:()=>M(!1),className:"px-4 py-2 text-slate-700 hover:bg-slate-200 rounded transition-colors text-sm font-medium",children:"关闭"}),c&&e.jsxs("button",{onClick:()=>{c(R.name),M(!1)},className:"px-4 py-2 bg-blue-600 text-white hover:bg-blue-700 rounded transition-colors text-sm font-medium flex items-center gap-2",children:[e.jsx(at,{size:$.md}),"使用此片段"]})]})]})]})]}):null},Xs=t=>{const s=(t.language||"").toLowerCase();return s==="objectivec"||s==="objc"||s==="objective-c"||s==="obj-c"?"objectivec":t.language||"swift"};function Cr(t){const s=[],a=t.match(/#import\s+"([^"]+)"/);if(a){const x=a[1].replace(/\.h$/,"");s.push(x)}const l=t.match(/#import\s+<([^>]+)>/);if(l){const x=l[1].replace(/\.h$/,"").split("/");s.push(...x)}const n=t.match(/^import\s+(\w+)/);n&&s.push(n[1]);const c=t.match(/@import\s+(\w+)/);return c&&s.push(c[1]),[...new Set(s.filter(Boolean))]}function _t(t,s){if(!s||!s.trim())return"unknown";const a=Cr(t);return a.length===0?"unknown":a.some(l=>s.includes(l))?"used":"unused"}function Sr(t){return t.startsWith("#import ")||t.startsWith("import ")||t.startsWith("@import ")?t.trim():t.startsWith("<")||t.startsWith('"')?`#import ${t.trim()}`:t.trim()}const Ir=[{value:"",label:"—"},{value:"networking",label:"Networking"},{value:"ui",label:"UI"},{value:"data",label:"Data"},{value:"architecture",label:"Architecture"},{value:"conventions",label:"Conventions"}],zr=t=>{var n;const s=(((n=t.content)==null?void 0:n.pattern)||"").trim();if(!s)return!1;const a=s.split(`
|
|
77
|
+
`).filter(c=>c.trim());return!(a.filter(c=>/^\s*(#{1,6}\s|[-*>]\s|\d+\.\s)/.test(c)).length>a.length*.3)},$r=({res:t,index:s,editingCodeIndex:a,setEditingCodeIndex:l,expandedEditIndex:n,setExpandedEditIndex:c,similarityMap:x,handleUpdateScanResult:i,handleSaveExtracted:N,handlePromoteToCandidate:j,openCompare:g,isSavingRecipe:p=!1})=>{var K,S,q;const[u,w]=r.useState(!1),f=n===s,E=t.headers||[],A=((K=t.content)==null?void 0:K.pattern)||"",M=((S=t.content)==null?void 0:S.markdown)||"",R=t.description||"",B=t.tags||[],T=zr(t),U=(C,m)=>{i(s,{content:{...t.content||{},[C]:m}})};return e.jsxs("div",{className:"bg-slate-50 rounded-2xl border border-slate-200 overflow-hidden shadow-sm",children:[e.jsxs("div",{className:"px-5 pt-4 pb-3 bg-gradient-to-b from-white to-slate-50/50 border-b border-slate-100",children:[e.jsxs("div",{className:"flex items-start justify-between gap-4 mb-3",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[e.jsx("label",{className:"text-[9px] font-bold text-slate-400 uppercase tracking-wider ml-0.5",children:"知识条目标题"}),t.scanMode==="project"?e.jsxs("span",{className:"text-[9px] font-bold px-1.5 py-0.5 rounded bg-indigo-100 text-indigo-700 border border-indigo-200 flex items-center gap-1",children:[e.jsx(et,{size:10})," PROJECT"]}):t.scanMode==="target"?e.jsxs("span",{className:"text-[9px] font-bold px-1.5 py-0.5 rounded bg-blue-100 text-blue-700 border border-blue-200 flex items-center gap-1",children:[e.jsx(Qe,{size:10})," ",t.candidateTargetName||"TARGET"]}):t.lifecycle?e.jsx("span",{className:`text-[9px] font-bold px-1.5 py-0.5 rounded flex items-center gap-1 ${t.lifecycle==="pending"?"bg-amber-100 text-amber-700 border border-amber-200":t.lifecycle==="active"?"bg-green-100 text-green-700 border border-green-200":"bg-slate-100 text-slate-600 border border-slate-200"}`,children:t.lifecycle==="pending"?"待审核":t.lifecycle==="active"?"已发布":t.lifecycle==="deprecated"?"已废弃":t.lifecycle}):null,t.source&&t.source!=="unknown"&&e.jsx("span",{className:"text-[9px] font-medium px-1.5 py-0.5 rounded bg-violet-50 text-violet-600 border border-violet-100",children:t.source==="agent"?"AI Agent":t.source==="bootstrap-scan"?"AI 扫描":t.source})]}),e.jsx("input",{className:"font-semibold bg-transparent border-b-2 border-transparent hover:border-slate-200 focus:border-blue-500 outline-none px-0.5 text-lg w-full text-slate-800 placeholder:text-slate-300",value:t.title||"",onChange:C=>i(s,{title:C.target.value})})]}),e.jsxs("div",{className:"flex gap-2 shrink-0 pt-3",children:[j&&e.jsxs("button",{onClick:()=>j(t,s),className:"text-xs px-4 py-2 rounded-lg font-bold transition-all shadow-sm flex items-center gap-1.5 active:scale-95 bg-white text-emerald-600 border border-emerald-200 hover:bg-emerald-50 whitespace-nowrap",children:[e.jsx(Qa,{size:$.md}),"Candidate"]}),e.jsxs("button",{onClick:()=>N(t),disabled:p,className:`text-xs px-4 py-2 rounded-lg font-bold transition-all shadow-sm flex items-center gap-1.5 active:scale-95 disabled:opacity-60 disabled:cursor-not-allowed whitespace-nowrap ${T&&t.mode==="full"?"bg-blue-600 text-white hover:bg-blue-700":"bg-amber-600 text-white hover:bg-amber-700"}`,children:[p?e.jsx(Te,{size:$.md,className:"animate-spin"}):e.jsx(ua,{size:$.md}),p?"保存中...":T?"保存为 Recipe":"保存知识"]})]})]}),e.jsxs("div",{className:"flex items-end gap-3 flex-wrap",children:[e.jsxs("div",{className:"flex flex-col",children:[e.jsx("label",{className:"text-[9px] font-bold text-slate-400 uppercase tracking-wider ml-0.5 mb-1",children:"Trigger"}),e.jsx("input",{className:"font-mono font-bold text-blue-600 bg-blue-50/80 border border-blue-100 px-2.5 py-1 rounded-md outline-none text-xs focus:ring-2 focus:ring-blue-500/20 w-44",value:t.trigger||"",placeholder:"@kebab-case-id",onChange:C=>i(s,{trigger:C.target.value})})]}),e.jsxs("div",{className:"flex flex-col",children:[e.jsx("label",{className:"text-[9px] font-bold text-slate-400 uppercase tracking-wider ml-0.5 mb-1",children:"Kind"}),e.jsxs("select",{className:"font-bold text-slate-600 bg-white border border-slate-200 px-2 py-1 rounded-md outline-none text-[11px] focus:ring-2 focus:ring-blue-500/20",value:t.kind||"pattern",onChange:C=>i(s,{kind:C.target.value}),children:[e.jsx("option",{value:"rule",children:"Rule"}),e.jsx("option",{value:"pattern",children:"Pattern"}),e.jsx("option",{value:"fact",children:"Fact"})]})]}),e.jsxs("div",{className:"flex flex-col",children:[e.jsx("label",{className:"text-[9px] font-bold text-slate-400 uppercase tracking-wider ml-0.5 mb-1",children:"Topic"}),e.jsx("select",{className:"font-bold text-slate-600 bg-white border border-slate-200 px-2 py-1 rounded-md outline-none text-[11px] focus:ring-2 focus:ring-blue-500/20",value:t.topicHint||"",onChange:C=>i(s,{topicHint:C.target.value}),children:Ir.map(C=>e.jsx("option",{value:C.value,children:C.label},C.value))})]}),e.jsxs("div",{className:"flex flex-col",children:[e.jsx("label",{className:"text-[9px] font-bold text-slate-400 uppercase tracking-wider ml-0.5 mb-1",children:"分类"}),e.jsx("select",{className:"font-bold text-slate-600 bg-white border border-slate-200 px-2 py-1 rounded-md outline-none text-[11px] focus:ring-2 focus:ring-blue-500/20",value:t.category||"",onChange:C=>i(s,{category:C.target.value}),children:wl.filter(C=>C!=="All").map(C=>e.jsx("option",{value:C,children:C},C))})]}),T&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"w-px h-6 bg-slate-200 self-end mb-0.5"}),e.jsxs("div",{className:"flex flex-col",children:[e.jsx("label",{className:"text-[9px] font-bold text-slate-400 uppercase tracking-wider ml-0.5 mb-1",children:"语言"}),e.jsxs("div",{className:"flex bg-slate-100 p-0.5 rounded-md",children:[e.jsx("button",{onClick:()=>i(s,{language:"swift"}),className:`px-2.5 py-0.5 rounded text-[10px] font-bold transition-all ${t.language==="swift"?"bg-white shadow-sm text-blue-600":"text-slate-400 hover:text-slate-500"}`,children:"Swift"}),e.jsx("button",{onClick:()=>i(s,{language:"objectivec"}),className:`px-2.5 py-0.5 rounded text-[10px] font-bold transition-all ${t.language==="objectivec"||t.language==="objc"?"bg-white shadow-sm text-blue-600":"text-slate-400 hover:text-slate-500"}`,children:"ObjC"})]})]})]}),t.moduleName&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"w-px h-6 bg-slate-200 self-end mb-0.5"}),e.jsxs("div",{className:"flex flex-col",children:[e.jsx("label",{className:"text-[9px] font-bold text-slate-400 uppercase tracking-wider ml-0.5 mb-1",children:"模块"}),e.jsx("span",{className:"text-[11px] bg-purple-50 text-purple-700 border border-purple-100 px-2 py-1 rounded-md font-mono font-bold",children:t.moduleName})]})]}),e.jsx("div",{className:"w-px h-6 bg-slate-200 self-end mb-0.5"}),T&&e.jsxs("div",{className:"flex flex-col",children:[e.jsx("label",{className:"text-[9px] font-bold text-slate-400 uppercase tracking-wider ml-0.5 mb-1",children:"模式"}),e.jsxs("div",{className:"flex bg-white p-0.5 rounded-md border border-slate-200",children:[e.jsx("button",{onClick:()=>i(s,{mode:"full"}),className:`px-2.5 py-0.5 rounded text-[10px] font-bold transition-all ${t.mode==="full"?"bg-blue-100 shadow-sm text-blue-600":"text-slate-400 hover:text-slate-500"}`,children:"Snippet+Recipe"}),e.jsx("button",{onClick:()=>i(s,{mode:"preview"}),className:`px-2.5 py-0.5 rounded text-[10px] font-bold transition-all ${t.mode==="preview"?"bg-amber-100 shadow-sm text-amber-600":"text-slate-400 hover:text-slate-500"}`,children:"Recipe Only"})]})]}),e.jsxs("div",{className:"flex flex-col",children:[e.jsx("label",{className:"text-[9px] font-bold text-slate-400 uppercase tracking-wider ml-0.5 mb-1",children:"难度"}),e.jsxs("select",{className:"font-bold text-slate-600 bg-white border border-slate-200 px-2 py-1 rounded-md outline-none text-[11px] focus:ring-2 focus:ring-purple-500/20",value:t.difficulty||"intermediate",onChange:C=>i(s,{difficulty:C.target.value,complexity:C.target.value}),children:[e.jsx("option",{value:"beginner",children:"初级"}),e.jsx("option",{value:"intermediate",children:"中级"}),e.jsx("option",{value:"advanced",children:"高级"})]})]}),e.jsxs("div",{className:"flex flex-col",children:[e.jsx("label",{className:"text-[9px] font-bold text-slate-400 uppercase tracking-wider ml-0.5 mb-1",children:"权威分"}),e.jsxs("select",{className:"font-bold text-amber-600 bg-amber-50/60 border border-amber-100 px-2 py-1 rounded-md outline-none text-[11px] focus:ring-2 focus:ring-amber-500/20",value:t.authority??((q=t.stats)==null?void 0:q.authority)??3,onChange:C=>i(s,{authority:parseInt(C.target.value)}),children:[e.jsx("option",{value:"1",children:"⭐ 1"}),e.jsx("option",{value:"2",children:"⭐⭐ 2"}),e.jsx("option",{value:"3",children:"⭐⭐⭐ 3"}),e.jsx("option",{value:"4",children:"⭐⭐⭐⭐ 4"}),e.jsx("option",{value:"5",children:"⭐⭐⭐⭐⭐ 5"})]})]})]}),e.jsx("div",{className:"mt-2.5",children:e.jsxs("div",{className:"flex flex-wrap gap-1 items-center bg-white border border-slate-200 rounded-md px-1.5 py-0.5 min-h-[28px] focus-within:ring-2 focus-within:ring-blue-500/20",children:[B.map((C,m)=>e.jsxs("span",{className:"flex items-center gap-0.5 text-[10px] font-bold bg-blue-50 text-blue-700 border border-blue-200 px-1.5 py-0 rounded",children:[C,e.jsx("button",{onClick:()=>{const P=[...B];P.splice(m,1),i(s,{tags:P})},className:"text-blue-400 hover:text-red-500 transition-colors leading-none text-[10px]",title:"移除",children:"×"})]},m)),e.jsx("input",{className:"flex-1 min-w-[80px] text-[11px] text-slate-600 outline-none bg-transparent py-0.5",placeholder:B.length===0?"标签: 按 Enter/逗号添加...":"",onKeyDown:C=>{const m=C.currentTarget,P=m.value.trim();if((C.key==="Enter"||C.key===","||C.key===",")&&P){C.preventDefault();const h=P.replace(/[,,]/g,"").trim();h&&!B.includes(h)&&i(s,{tags:[...B,h]}),m.value=""}else if(C.key==="Backspace"&&!m.value&&B.length>0){const h=[...B];h.pop(),i(s,{tags:h})}},onBlur:C=>{const m=C.currentTarget.value.trim().replace(/[,,]/g,"").trim();m&&!B.includes(m)&&i(s,{tags:[...B,m]}),C.currentTarget.value=""}})]})}),T&&E.length>0&&e.jsxs("div",{className:"mt-2 space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("label",{className:"text-[10px] font-bold text-slate-400 uppercase",children:"Headers"}),e.jsxs("button",{onClick:()=>c(n===s?null:s),className:`text-[10px] font-bold px-2 py-0.5 rounded-md transition-colors border ${f?"text-blue-700 bg-blue-100 border-blue-300":"text-blue-600 bg-blue-50 border-blue-100 hover:bg-blue-100"}`,children:[f?"收起":"编辑"," (",E.length,")"]}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"text-[9px] text-slate-400",children:"Snippet:"}),e.jsx("button",{onClick:()=>i(s,{includeHeaders:t.includeHeaders===!1}),className:`w-7 h-4 rounded-full relative transition-colors ${t.includeHeaders!==!1?"bg-blue-600":"bg-slate-300"}`,title:t.includeHeaders!==!1?"开启:snippet 内写入 // as:include 标记":"关闭:不写入头文件标记",children:e.jsx("div",{className:`absolute top-0.5 w-2.5 h-2.5 bg-white rounded-full transition-all ${t.includeHeaders!==!1?"right-0.5":"left-0.5"}`})}),e.jsx("span",{className:"text-[9px] font-bold text-slate-600",children:t.includeHeaders!==!1?"ON":"OFF"})]}),(()=>{const C=E.filter(P=>_t(P,A)==="used").length,m=E.filter(P=>_t(P,A)==="unused").length;return e.jsxs("span",{className:"text-[9px] text-slate-400",children:[C>0&&e.jsxs("span",{className:"text-green-600 font-bold",children:[C," 引用"]}),C>0&&m>0&&" · ",m>0&&e.jsxs("span",{className:"text-amber-600 font-bold",children:[m," 未引用"]})]})})()]}),f&&e.jsxs("div",{className:"space-y-2 bg-slate-50/80 rounded-lg p-3 border border-slate-200",children:[e.jsxs("div",{className:"flex items-center justify-end gap-1.5",children:[e.jsx("button",{onClick:()=>{const C=E.map(m=>Sr(m));i(s,{headers:C})},className:"text-[9px] px-2 py-0.5 bg-slate-200 text-slate-600 rounded hover:bg-slate-300 font-bold",title:"统一 #import 格式",children:"格式化"}),E.some(C=>_t(C,A)==="unused")&&e.jsx("button",{onClick:()=>{const C=E.filter(m=>_t(m,A)!=="unused");i(s,{headers:C})},className:"text-[9px] px-2 py-0.5 bg-amber-100 text-amber-700 rounded hover:bg-amber-200 font-bold",title:"移除代码中未引用的头文件",children:"清理未引用"}),e.jsx("button",{onClick:()=>{const C=[...E,t.language==="objectivec"?"#import <Module/Header.h>":"import ModuleName"];i(s,{headers:C})},className:"text-[9px] px-2 py-0.5 bg-green-500 text-white rounded hover:bg-green-600 font-bold",children:"+ 添加"})]}),e.jsx("div",{className:"space-y-1",children:E.map((C,m)=>{const P=_t(C,A);return e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:`w-2 h-2 rounded-full shrink-0 ${P==="used"?"bg-green-500":P==="unused"?"bg-amber-400":"bg-slate-300"}`,title:P==="used"?"代码中有引用":P==="unused"?"代码中未找到引用":"无法判断"}),e.jsx("input",{className:`flex-1 text-xs font-mono bg-white border rounded px-2 py-1 outline-none focus:border-blue-400 ${P==="unused"?"border-amber-300 text-amber-700":"border-slate-200"}`,value:C,onChange:h=>{const d=[...E];d[m]=h.target.value,i(s,{headers:d})},placeholder:t.language==="objectivec"?"#import <Module/Header.h>":"import ModuleName"}),P==="unused"&&e.jsx("span",{className:"text-[8px] text-amber-500 font-bold shrink-0",children:"未引用"}),e.jsx("button",{onClick:()=>{const h=E.filter((d,v)=>v!==m);i(s,{headers:h})},className:"px-2 py-1 bg-red-500 text-white rounded hover:bg-red-600 text-[9px] font-bold shrink-0",children:"删除"})]},m)})})]})]})]}),e.jsxs("div",{className:"px-6 pb-6 pt-4 space-y-4",children:[e.jsxs("div",{className:"rounded-xl border border-cyan-200 bg-gradient-to-br from-cyan-50/60 to-blue-50/40 p-4 space-y-3",children:[e.jsxs("div",{className:"text-[10px] font-bold text-cyan-700 uppercase tracking-wider flex items-center gap-1.5",children:[e.jsx(Qe,{size:12}),"Cursor Delivery"]}),e.jsxs("div",{className:"grid grid-cols-[auto_1fr] gap-x-3 gap-y-2 items-start",children:[e.jsx("span",{className:"text-[10px] font-bold text-emerald-600 uppercase pt-1.5 select-none",children:"Do"}),e.jsx("input",{className:"text-sm text-slate-700 bg-white/80 border border-slate-200 rounded-lg px-3 py-1.5 outline-none focus:ring-2 focus:ring-cyan-500/20",value:t.doClause||"",onChange:C=>i(s,{doClause:C.target.value}),placeholder:"English imperative ≤60 tokens, e.g. Use dispatch_once for thread-safe singleton"}),e.jsx("span",{className:"text-[10px] font-bold text-red-500 uppercase pt-1.5 select-none",children:"Don't"}),e.jsx("input",{className:"text-sm text-slate-700 bg-white/80 border border-slate-200 rounded-lg px-3 py-1.5 outline-none focus:ring-2 focus:ring-cyan-500/20",value:t.dontClause||"",onChange:C=>i(s,{dontClause:C.target.value}),placeholder:"English constraint (omit 'Don't' prefix), e.g. use @synchronized for singleton"}),e.jsx("span",{className:"text-[10px] font-bold text-amber-600 uppercase pt-1.5 select-none",children:"When"}),e.jsx("input",{className:"text-sm text-slate-700 bg-white/80 border border-slate-200 rounded-lg px-3 py-1.5 outline-none focus:ring-2 focus:ring-cyan-500/20",value:t.whenClause||"",onChange:C=>i(s,{whenClause:C.target.value}),placeholder:"When implementing singleton pattern or global shared instance"})]})]}),t.reasoning&&(t.reasoning.confidence!=null||t.reasoning.whyStandard&&!/^Submitted via /i.test(t.reasoning.whyStandard))&&e.jsxs("div",{className:"rounded-xl border border-indigo-100 bg-indigo-50/40 p-3 text-xs space-y-1.5",children:[e.jsxs("div",{className:"flex items-center gap-1.5 text-indigo-600 font-bold text-[10px]",children:["AI 推理",t.reasoning.confidence!=null&&e.jsxs("span",{className:`ml-auto font-mono text-[10px] ${t.reasoning.confidence>=.7?"text-emerald-600":t.reasoning.confidence>=.4?"text-amber-600":"text-red-600"}`,children:["置信度 ",Math.round(t.reasoning.confidence*100),"%"]})]}),t.reasoning.whyStandard&&!/^Submitted via /i.test(t.reasoning.whyStandard)&&e.jsx("p",{className:"text-slate-600",children:t.reasoning.whyStandard}),t.reasoning.sources&&t.reasoning.sources.length>0&&e.jsxs("p",{className:"text-slate-400",children:["来源: ",t.reasoning.sources.join(", ")]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-[10px] font-bold text-slate-400 uppercase mb-1",children:"描述"}),e.jsx("textarea",{rows:1,className:"w-full text-sm text-slate-600 bg-white border border-slate-200 rounded-xl px-3 py-2 outline-none resize-none leading-relaxed focus:ring-2 focus:ring-blue-500/10",value:R,onChange:C=>i(s,{description:C.target.value,summary:C.target.value}),placeholder:"中文简述 ≤80 字,引用真实类名"})]}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-1",children:[e.jsx("label",{className:"text-[10px] font-bold text-slate-400 uppercase",children:"项目特写"}),e.jsx("button",{type:"button",onClick:()=>w(!u),className:`flex items-center gap-1 text-[10px] font-bold px-2 py-1 rounded transition-colors ${u?"text-blue-600 hover:text-blue-700 bg-blue-50":"text-slate-500 hover:text-slate-700 hover:bg-slate-100"}`,children:u?e.jsxs(e.Fragment,{children:[e.jsx(yt,{size:$.xs})," 完成"]}):e.jsxs(e.Fragment,{children:[e.jsx(ws,{size:$.xs})," 编辑"]})})]}),u?e.jsx("textarea",{rows:Math.max(6,(M||"").split(`
|
|
78
|
+
`).length),className:"w-full text-sm text-slate-600 bg-white border border-slate-200 rounded-xl px-3 py-2 outline-none resize-y leading-relaxed focus:ring-2 focus:ring-blue-500/10 font-mono",value:M,onChange:C=>U("markdown",C.target.value)}):M?e.jsx("div",{className:"text-sm text-slate-600 bg-white border border-slate-200 rounded-xl px-4 py-3 leading-relaxed whitespace-pre-wrap max-h-64 overflow-y-auto",children:M}):e.jsx("p",{className:"text-xs text-slate-400 italic py-2",children:"(无项目特写内容)"})]}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-1",children:[e.jsx("label",{className:"text-[10px] font-bold text-slate-400 uppercase",children:"代码模板"}),a===s?e.jsxs("button",{type:"button",onClick:()=>l(null),className:"flex items-center gap-1 text-[10px] font-bold text-blue-600 hover:text-blue-700 px-2 py-1 rounded bg-blue-50",children:[e.jsx(yt,{size:$.xs})," 完成"]}):e.jsxs("button",{type:"button",onClick:()=>l(s),className:"flex items-center gap-1 text-[10px] font-bold text-slate-500 hover:text-slate-700 px-2 py-1 rounded hover:bg-slate-100",title:"编辑代码",children:[e.jsx(ws,{size:$.xs})," 编辑"]})]}),a===s?e.jsx("div",{className:"rounded-xl overflow-hidden",children:e.jsx(Vt,{value:A,onChange:C=>U("pattern",C),language:Xs(t),height:`${Math.min(12,A.split(`
|
|
79
|
+
`).length)*20+16}px`})}):A?e.jsx(rt,{code:A,language:Xs(t),showLineNumbers:!0}):e.jsx("p",{className:"text-xs text-slate-400 italic py-4",children:"(无代码模板)"})]}),(()=>{const C=t.candidateId??t.id??`scan-${s}`,m=x[C],P=(m||[]).filter(v=>v.similarity>=.6);if(P.length===0)return null;const h=P.filter(v=>v.similarity>=.85),d=h.length>0;return e.jsxs("div",{className:"space-y-1.5",children:[d&&e.jsxs("div",{className:"flex items-center gap-2 bg-red-50 border border-red-200 rounded-lg px-3 py-2",children:[e.jsx("span",{className:"text-red-500 text-sm",children:"⚠️"}),e.jsx("span",{className:"text-[11px] font-bold text-red-700",children:"高重复风险:"}),h.map(v=>e.jsxs("button",{onClick:()=>g(t,v.recipeName,m||[]),className:"text-[11px] font-bold px-2 py-0.5 rounded bg-red-100 text-red-800 border border-red-300 hover:bg-red-200 transition-colors",children:[v.recipeName.replace(/\.md$/i,"")," ",(v.similarity*100).toFixed(0),"%"]},v.recipeName)),e.jsx("span",{className:"text-[10px] text-red-500",children:"建议先对比再保存"})]}),e.jsxs("div",{className:"flex flex-wrap gap-1.5 items-center",children:[e.jsx("span",{className:"text-[10px] text-slate-400 font-bold",children:"相似 Recipe:"}),P.slice(0,5).map(v=>e.jsxs("button",{onClick:()=>g(t,v.recipeName,m||[]),className:`text-[10px] font-bold px-2 py-1 rounded border transition-colors flex items-center gap-1 ${v.similarity>=.85?"bg-red-50 text-red-700 border-red-200 hover:bg-red-100":"bg-amber-50 text-amber-700 border-amber-200 hover:bg-amber-100"}`,title:`与 ${v.recipeName} 相似 ${(v.similarity*100).toFixed(0)}%,点击对比`,children:[e.jsx(ds,{size:$.xs}),v.recipeName.replace(/\.md$/i,"")," ",(v.similarity*100).toFixed(0),"%"]},v.recipeName))]})]})})()]})]})},Ar=t=>{const s=(t.language||"").toLowerCase();return s==="objectivec"||s==="objc"||s==="objective-c"||s==="obj-c"?"objectivec":t.language||"swift"},Mr=({data:t,onClose:s,onDataChange:a,recipes:l,handleSaveExtracted:n,handleDeleteCandidate:c,onEditRecipe:x,isSavingRecipe:i=!1})=>{var A,M,R,B;const N=t.candidate,j=Ar(N),g=()=>{var S,q;const T=[],U=((S=N.content)==null?void 0:S.pattern)||"",K=((q=N.content)==null?void 0:q.markdown)||N.doClause||"";U&&T.push("## Snippet / Code Reference\n\n```"+j+`
|
|
80
|
+
`+U+"\n```"),K&&T.push(`
|
|
81
|
+
## AI Context / Usage Guide
|
|
82
|
+
|
|
83
|
+
`+K),navigator.clipboard.writeText(T.join(`
|
|
84
|
+
`)||"").then(()=>V("候选内容已复制到剪贴板",{title:"已复制"}))},p=()=>{const T=Es(t.recipeContent);navigator.clipboard.writeText(T).then(()=>V("Recipe 内容已复制到剪贴板",{title:"已复制"}))},u=async T=>{if(T===t.recipeName)return;const U=t.recipeContents[T];if(U)a({...t,recipeName:T,recipeContent:U});else{let K="";const S=l==null?void 0:l.find(q=>q.name===T||q.name.endsWith("/"+T));if(S!=null&&S.content)K=[S.content.pattern,S.content.markdown].filter(Boolean).join(`
|
|
85
|
+
|
|
86
|
+
`)||"";else try{K=(await Y.getRecipeContentByName(T)).content}catch{return}a({...t,recipeName:T,recipeContent:K,recipeContents:{...t.recipeContents,[T]:K}})}},w=async()=>{if(!(!N.candidateId||!t.targetName||!c)&&window.confirm("确定删除该候选?"))try{await c(t.targetName,N.candidateId),s()}catch(T){V((T==null?void 0:T.message)||"删除失败",{title:"删除失败",type:"error"})}},f=()=>{n(N),s()},E=()=>{const T=l==null?void 0:l.find(U=>U.name===t.recipeName||U.name.endsWith("/"+t.recipeName));T?x==null||x(T):x==null||x({name:t.recipeName,content:{markdown:t.recipeContent}}),s()};return e.jsxs(Ve,{className:"z-30 flex justify-end",onClick:s,children:[e.jsx(Ve.Backdrop,{className:"bg-black/30 backdrop-blur-[1px]"}),e.jsxs("div",{className:"relative w-[min(96vw,1280px)] h-full bg-white shadow-2xl flex flex-col",style:{animation:"slideInRight 0.25s ease-out"},onClick:T=>T.stopPropagation(),children:[e.jsxs("div",{className:"flex items-center justify-between px-5 py-3 border-b border-slate-200 shrink-0",children:[e.jsxs("div",{className:"flex items-center gap-3 flex-1 min-w-0",children:[e.jsx("h3",{className:"font-bold text-slate-800",children:"对比:候选 vs Recipe"}),e.jsxs("div",{className:"flex items-center gap-1.5 shrink-0",children:[N.candidateId&&t.targetName&&e.jsx("button",{onClick:w,className:"text-xs text-red-600 hover:bg-red-50 px-2 py-1 rounded transition-colors",children:"删除候选"}),e.jsxs("button",{onClick:f,disabled:i,className:"text-xs text-blue-600 hover:bg-blue-50 px-2 py-1 rounded disabled:opacity-50 disabled:cursor-not-allowed flex items-center gap-1 transition-colors",children:[i?e.jsx(Te,{size:$.xs,className:"animate-spin"}):null,"审核候选"]}),e.jsx("button",{onClick:E,className:"text-xs text-emerald-600 hover:bg-emerald-50 px-2 py-1 rounded transition-colors",children:"编辑 Recipe"})]})]}),e.jsx("button",{onClick:s,className:"p-2 hover:bg-slate-100 rounded-lg transition-colors shrink-0 ml-2",children:e.jsx(Ye,{size:$.md})})]}),t.similarList.length>1&&e.jsxs("div",{className:"flex flex-wrap gap-1.5 px-5 py-2 border-b border-slate-100 bg-slate-50/50 shrink-0",children:[e.jsx("span",{className:"text-[10px] text-slate-400 font-bold self-center",children:"切换 Recipe:"}),t.similarList.map(T=>e.jsxs("button",{onClick:()=>u(T.recipeName),className:`text-[10px] font-bold px-2 py-1 rounded transition-colors ${t.recipeName===T.recipeName?"bg-emerald-200 text-emerald-800":"bg-white text-emerald-600 hover:bg-emerald-100 border border-emerald-200"}`,children:[T.recipeName.replace(/\.md$/i,"")," ",(T.similarity*100).toFixed(0),"%"]},T.recipeName))]}),e.jsxs("div",{className:"flex-1 flex min-h-0",children:[e.jsxs("div",{className:"flex-1 flex flex-col min-w-0 border-r border-slate-200",children:[e.jsxs("div",{className:"flex items-center justify-between px-4 py-2 border-b border-slate-100 bg-blue-50/40 shrink-0",children:[e.jsxs("span",{className:"text-xs font-bold text-blue-700 truncate",children:["候选:",N.title]}),e.jsx("button",{onClick:g,className:"p-1 hover:bg-blue-100 rounded text-blue-500 shrink-0",title:"复制候选",children:e.jsx(Et,{size:$.xs})})]}),e.jsx("div",{className:"flex-1 overflow-y-auto p-4",children:e.jsxs("div",{className:"markdown-body text-slate-700 space-y-4",children:[e.jsx("h3",{className:"text-sm font-bold",children:"Snippet / Code Reference"}),(A=N.content)!=null&&A.pattern?e.jsx(rt,{code:((M=N.content)==null?void 0:M.pattern)||"",language:j,className:"!overflow-visible"}):e.jsx("p",{className:"text-slate-400 italic text-xs",children:"(无代码)"}),e.jsx("h3",{className:"text-sm font-bold mt-4",children:"AI Context / 项目特写"}),(R=N.content)!=null&&R.markdown||N.doClause?e.jsx(ut,{content:((B=N.content)==null?void 0:B.markdown)||N.doClause||""}):e.jsx("p",{className:"text-slate-400 italic text-xs",children:"(无使用指南)"})]})})]}),e.jsxs("div",{className:"flex-1 flex flex-col min-w-0",children:[e.jsxs("div",{className:"flex items-center justify-between px-4 py-2 border-b border-slate-100 bg-emerald-50/40 shrink-0",children:[e.jsxs("span",{className:"text-xs font-bold text-emerald-700 truncate",children:["Recipe:",t.recipeName.replace(/\.md$/i,"")]}),e.jsx("button",{onClick:p,className:"p-1 hover:bg-emerald-100 rounded text-emerald-500 shrink-0",title:"复制 Recipe",children:e.jsx(Et,{size:$.xs})})]}),e.jsx("div",{className:"flex-1 overflow-y-auto p-4",children:e.jsx(ut,{content:t.recipeContent,stripFrontmatter:!0})})]})]})]})]})},Er=({targets:t,filteredTargets:s,selectedTargetName:a,isScanning:l,scanProgress:n,scanFileList:c,scanResults:x,guardAudit:i,handleScanTarget:N,handleScanProject:j,handleUpdateScanResult:g,handleSaveExtracted:p,handlePromoteToCandidate:u,handleDeleteCandidate:w,onEditRecipe:f,isShellTarget:E,recipes:A=[],isSavingRecipe:M=!1,handleRefreshProject:R})=>{var ye;const[B,T]=r.useState(null),[U,K]=r.useState(null),[S,q]=r.useState({}),[C,m]=r.useState(null),[P,h]=r.useState(null),[d,v]=r.useState(!1),[k,ee]=r.useState(),[L,Z]=r.useState(),fe=r.useRef(new Set),O=r.useRef([]),re=r.useCallback(async(oe,Ne)=>{if(!fe.current.has(oe)){fe.current.add(oe),m(oe);try{const be=Ne.candidateId&&Ne.targetName?{targetName:Ne.targetName,candidateId:Ne.candidateId}:{candidate:Ne.candidate||{}},Ce=await Y.getCandidateSimilarityEx(be);q(Ae=>({...Ae,[oe]:Ce.similar||[]}))}catch{q(Ce=>({...Ce,[oe]:[]}))}finally{m(null)}}},[]),ae=r.useCallback(async(oe,Ne,be=[])=>{var le,we,ge;const Ce=oe.candidateTargetName||"",Ae=Ne.replace(/\.md$/i,"");let Fe="";const _=A==null?void 0:A.find(Me=>Me.name===Ae||Me.name.endsWith("/"+Ae));if(_!=null&&_.content)Fe=[_.content.pattern,_.content.markdown].filter(Boolean).join(`
|
|
87
|
+
|
|
88
|
+
`)||"";else try{Fe=(await Y.getRecipeContentByName(Ae)).content}catch(Me){const Oe=(le=Me.response)==null?void 0:le.status,Ee=((ge=(we=Me.response)==null?void 0:we.data)==null?void 0:ge.message)||Me.message;Oe===404?V(`"${Ae}" 不存在于当前知识库`,{title:"Recipe 不存在",type:"error"}):V(Ee,{title:"加载 Recipe 失败",type:"error"});return}const I={[Ae]:Fe};h({candidate:oe,targetName:Ce,recipeName:Ae,recipeContent:Fe,similarList:be.slice(0,3),recipeContents:I})},[A]);return r.useEffect(()=>{const oe=x.map((Ae,Fe)=>Ae.candidateId??`scan-${Fe}`),Ne=O.current;(oe.length!==Ne.length||oe.some((Ae,Fe)=>Ae!==Ne[Fe]))&&(fe.current.clear(),O.current=oe);const Ce=setTimeout(()=>{x.forEach((Ae,Fe)=>{var I,le;const _=Ae.candidateId??Ae.id??`scan-${Fe}`;Ae.candidateId&&Ae.candidateTargetName?re(_,{targetName:Ae.candidateTargetName,candidateId:Ae.candidateId}):re(_,{candidate:{title:Ae.title,summary:Ae.description||"",code:((I=Ae.content)==null?void 0:I.pattern)||"",usageGuide:((le=Ae.content)==null?void 0:le.markdown)||""}})})},800);return()=>clearTimeout(Ce)},[x,re]),e.jsxs("div",{className:"flex gap-8 h-full",children:[e.jsxs("div",{className:"w-80 bg-white rounded-xl border border-slate-200 flex flex-col overflow-hidden shrink-0",children:[e.jsxs("div",{className:"p-4 bg-slate-50 border-b border-slate-200 flex items-center justify-between",children:[e.jsxs("span",{className:"font-bold text-sm",children:["项目 Target (",t.length,")"]}),R&&e.jsx("button",{onClick:R,title:"刷新项目结构",className:"p-1 rounded hover:bg-slate-200 text-slate-400 hover:text-blue-600 transition-colors",children:e.jsx(ht,{size:$.sm})})]}),e.jsx("div",{className:"flex-1 overflow-y-auto p-2 space-y-1",children:s.map(oe=>{const Ne=E(oe.name),be=a===oe.name;return e.jsxs("button",{onClick:()=>N(oe),disabled:l,className:`w-full text-left p-3 rounded-lg flex items-center justify-between group transition-all border ${l?"opacity-50 cursor-not-allowed":"hover:bg-slate-50"} ${be?"bg-blue-50 border-blue-200 ring-1 ring-blue-200":"bg-white border-transparent"} ${Ne?"opacity-90":""}`,children:[e.jsxs("div",{className:`flex flex-col max-w-[85%] ${Ne?"opacity-60":""}`,children:[e.jsxs("div",{className:"flex items-center gap-2",children:[!Ne&&e.jsx("div",{className:"w-1.5 h-1.5 rounded-full shrink-0 bg-blue-600"}),e.jsx("span",{className:`text-sm truncate ${Ne?"font-medium":"font-bold"} ${be?"text-blue-700":""}`,children:oe.name})]}),e.jsx("span",{className:"text-[10px] text-slate-400 truncate pl-3",children:oe.packageName})]}),Ne?e.jsx("span",{className:"text-[9px] font-bold text-slate-300 border border-slate-100 px-1 rounded",children:"SHELL"}):e.jsx(Qe,{size:$.sm,className:`shrink-0 ${be?"text-blue-500 opacity-100":"text-blue-500 opacity-0 group-hover:opacity-100"} transition-opacity`})]},oe.name)})})]}),e.jsxs("div",{className:"flex-1 bg-white rounded-xl border border-slate-200 flex flex-col overflow-hidden relative",children:[e.jsx("div",{className:"p-4 bg-slate-50 border-b border-slate-200 font-bold text-sm flex justify-between items-center",children:e.jsxs("div",{className:"flex items-center gap-2",children:[a==="__project__"?e.jsxs(e.Fragment,{children:[e.jsx(et,{size:$.md,className:"text-indigo-500"}),e.jsx("span",{children:"全项目扫描结果"}),x.length>0&&e.jsx("span",{className:"text-[10px] font-bold px-2 py-0.5 rounded-full bg-indigo-100 text-indigo-700 border border-indigo-200",children:"PROJECT"})]}):a?e.jsxs(e.Fragment,{children:[e.jsx(Qe,{size:$.md,className:"text-blue-500"}),e.jsxs("span",{children:["Target: ",a]}),x.length>0&&e.jsx("span",{className:"text-[10px] font-bold px-2 py-0.5 rounded-full bg-blue-100 text-blue-700 border border-blue-200",children:"TARGET"})]}):e.jsxs(e.Fragment,{children:[e.jsx(jt,{size:$.md,className:"text-slate-400"}),e.jsx("span",{children:"审核提取结果"})]}),x.length>0&&e.jsxs("span",{className:"text-slate-400 font-normal text-xs ml-1",children:["(",x.length," 条",(ye=x[0])!=null&&ye.trigger?" Candidate":"",")"]})]})}),e.jsxs("div",{className:"flex-1 overflow-y-auto p-6 space-y-8 relative",children:[l&&e.jsxs("div",{className:"absolute inset-0 bg-white/90 backdrop-blur-[2px] z-10 flex flex-col items-center justify-center text-blue-600 px-8 overflow-y-auto",children:[e.jsxs("div",{className:"relative mb-6",children:[e.jsx("div",{className:"w-16 h-16 border-4 border-blue-100 border-t-blue-600 rounded-full animate-spin"}),e.jsx(Jt,{size:$.xxl,className:"absolute inset-0 m-auto text-blue-600 animate-pulse"})]}),e.jsx("p",{className:"font-bold text-lg animate-pulse mb-1",children:a==="__project__"?"全项目扫描中":`Target 扫描: ${a||"..."}`}),e.jsx("p",{className:"text-sm text-slate-500 mb-4",children:n.status}),c.length>0&&e.jsxs("div",{className:"w-full max-w-lg mb-4 text-left",children:[e.jsxs("p",{className:"text-[10px] font-bold text-slate-400 uppercase mb-2",children:["本次扫描的文件 (",c.length,")"]}),e.jsx("div",{className:"max-h-32 overflow-y-auto space-y-1 rounded-lg bg-slate-50 border border-slate-200 p-2",children:c.map((oe,Ne)=>e.jsx("div",{className:"text-xs font-mono text-slate-600 truncate",title:oe.path,children:oe.name},Ne))})]}),e.jsx("div",{className:"w-full max-w-md bg-slate-100 rounded-full h-2.5 overflow-hidden",children:e.jsx("div",{className:"h-full bg-blue-600 rounded-full transition-all duration-500 ease-out",style:{width:`${Math.min(n.total?n.current/n.total*100:0,98)}%`}})}),e.jsx("p",{className:"text-xs text-slate-400 mt-3",children:n.total?`${Math.round(n.current/n.total*100)}%`:"0%"})]}),!l&&x.length===0&&e.jsxs("div",{className:"h-full flex flex-col items-center justify-center text-slate-400 text-center",children:[e.jsx(us,{size:$.xxxl,className:"mb-4 opacity-20"}),e.jsx("p",{className:"font-medium text-slate-600",children:"知识提取"}),e.jsxs("p",{className:"text-xs mt-2 max-w-sm leading-relaxed",children:["在左侧选择 ",e.jsx("span",{className:"font-bold text-blue-600",children:"Target"})," 扫描单个模块,",e.jsx("br",{}),"提取代码模式并生成 Recipe 知识卡片。"]})]}),!l&&c.length>0&&e.jsxs("div",{className:"rounded-xl border border-slate-200 bg-slate-50 p-4",children:[e.jsxs("p",{className:"text-[10px] font-bold text-slate-400 uppercase mb-2",children:["本次扫描的文件 (",c.length,")"]}),e.jsx("div",{className:"flex flex-wrap gap-2",children:c.map((oe,Ne)=>e.jsx("span",{className:"text-xs font-mono bg-white border border-slate-200 text-slate-600 px-2 py-1 rounded",title:oe.path,children:oe.name},Ne))})]}),!l&&a==="__project__"&&(i==null?void 0:i.summary)&&e.jsxs("div",{className:`rounded-xl border p-4 ${i.summary.totalViolations>0?"border-amber-200 bg-amber-50":"border-emerald-200 bg-emerald-50"}`,children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsx(nt,{size:$.md,className:i.summary.totalViolations>0?"text-amber-600":"text-emerald-600"}),e.jsx("span",{className:"text-sm font-bold text-slate-700",children:"Guard 审计摘要"}),e.jsx("span",{className:"text-[10px] font-bold px-2 py-0.5 rounded-full bg-indigo-100 text-indigo-700 border border-indigo-200",children:"PROJECT SCAN"})]}),e.jsxs("div",{className:"flex gap-6 text-sm",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"text-slate-500",children:"已审计文件:"}),e.jsx("span",{className:"font-bold text-slate-700",children:i.summary.totalFiles})]}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"text-slate-500",children:"违反总数:"}),e.jsx("span",{className:`font-bold ${i.summary.totalViolations>0?"text-amber-700":"text-emerald-700"}`,children:i.summary.totalViolations})]}),i.summary.errors>0&&e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(At,{size:$.sm,className:"text-red-500"}),e.jsxs("span",{className:"font-bold text-red-700",children:[i.summary.errors," 错误"]})]}),i.summary.warnings>0&&e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(At,{size:$.sm,className:"text-amber-500"}),e.jsxs("span",{className:"font-bold text-amber-700",children:[i.summary.warnings," 警告"]})]})]})]}),x.map((oe,Ne)=>e.jsx($r,{res:oe,index:Ne,editingCodeIndex:B,setEditingCodeIndex:T,expandedEditIndex:U,setExpandedEditIndex:K,similarityMap:S,handleUpdateScanResult:g,handleSaveExtracted:p,handlePromoteToCandidate:u,openCompare:ae,isSavingRecipe:M},Ne))]})]}),P&&e.jsx(Mr,{data:P,onClose:()=>h(null),onDataChange:h,recipes:A,handleSaveExtracted:p,handleDeleteCandidate:w,onEditRecipe:f,isSavingRecipe:M}),e.jsx(kr,{isOpen:d,onClose:()=>v(!1),targetName:L,currentFile:k,language:"swift",onSelectRecipe:oe=>{}})]})},Tr=72,Lr=52,ms=24,Ht=40,ka=36,wt=140,qt=40,Gt=8;function Rr(t,s){const a=new Set(t.map(i=>i.id)),l=new Map;for(const i of s)!a.has(i.from)||!a.has(i.to)||(l.has(i.from)||l.set(i.from,[]),l.get(i.from).push(i.to));const n=new Map,c=new Set;function x(i){if(n.has(i))return n.get(i);if(c.has(i))return 0;c.add(i);const N=l.get(i);if(!N||N.length===0)return n.set(i,0),c.delete(i),0;const j=1+Math.max(...N.map(x));return n.set(i,j),c.delete(i),j}return t.forEach(i=>x(i.id)),n}function Dr(t){return Math.ceil(t/Gt)}function _r(t,s){const a=Rr(t,s),l=new Map;for(const p of t){const u=a.get(p.id)??0;l.has(u)||l.set(u,[]),l.get(u).push(p.id)}const n=[...new Set(a.values())].sort((p,u)=>p-u),c=[...n].reverse(),x=new Map,i=new Map,N=Math.min(Gt,Math.max(...n.map(p=>(l.get(p)??[]).length),1)),j=(N-1)*ms+N*wt;let g=Ht;return c.forEach(p=>{const u=l.get(p)??[],w=Dr(u.length),f=g;for(let A=0;A<w;A++){const M=u.slice(A*Gt,(A+1)*Gt),R=(M.length-1)*ms+M.length*wt,B=(j-R)/2;M.forEach((T,U)=>{const K=Ht+ka+B+U*(wt+ms)+wt/2,S=g+qt/2;x.set(T,{x:K,y:S})}),g+=A<w-1?Lr:Tr}const E=g-f;i.set(p,{y:f,h:E})}),{positions:x,tiers:a,tierOrder:n,tierYRanges:i}}const Pr=()=>{const[t,s]=r.useState(null),[a,l]=r.useState(!0),[n,c]=r.useState(null),[x,i]=r.useState(null),[N,j]=r.useState("package"),g=async()=>{var d,v;l(!0),c(null);try{const k=await Y.getDepGraph(N);s({nodes:Array.isArray(k==null?void 0:k.nodes)?k.nodes:[],edges:Array.isArray(k==null?void 0:k.edges)?k.edges:[],projectRoot:(k==null?void 0:k.projectRoot)??null,generatedAt:k==null?void 0:k.generatedAt})}catch(k){c(((v=(d=k.response)==null?void 0:d.data)==null?void 0:v.error)||k.message||"Failed to load dependency graph")}finally{l(!1)}};r.useEffect(()=>{g()},[N]);const p=Array.isArray(t==null?void 0:t.nodes)?t.nodes:[],u=Array.isArray(t==null?void 0:t.edges)?t.edges:[],{positions:w,tiers:f,tierOrder:E,tierYRanges:A}=r.useMemo(()=>_r(p,u),[p,u]),M=r.useMemo(()=>{const d=new Map;return p.forEach(v=>{const k=f.get(v.id)??0;d.has(k)||d.set(k,[]),d.get(k).push(v.id)}),d},[p,f]),R=r.useMemo(()=>[...E].reverse(),[E]),{dependsOn:B,dependedBy:T}=r.useMemo(()=>{const d=new Map,v=new Map;return u.forEach(k=>{d.has(k.from)||d.set(k.from,[]),d.get(k.from).push(k.to),v.has(k.to)||v.set(k.to,[]),v.get(k.to).push(k.from)}),{dependsOn:d,dependedBy:v}},[u]),U=Math.min(Gt,Math.max(...E.map(d=>(M.get(d)??[]).length),1)),S=(U-1)*ms+U*wt+ka*2,q=Math.max(600,Ht*2+S),C=Math.max(...[...w.values()].map(d=>d.y),0),m=Math.max(420,C+qt/2+Ht+20),P=[{bg:"rgb(239 246 255)",border:"rgb(147 197 253)",text:"rgb(30 64 175)"},{bg:"rgb(240 253 244)",border:"rgb(134 239 172)",text:"rgb(22 101 52)"},{bg:"rgb(254 249 195)",border:"rgb(253 224 71)",text:"rgb(113 63 18)"},{bg:"rgb(254 243 199)",border:"rgb(253 186 116)",text:"rgb(154 52 18)"},{bg:"rgb(243 232 255)",border:"rgb(216 180 254)",text:"rgb(91 33 182)"}],h=d=>P[Math.min(d,P.length-1)]??P[0];return a?e.jsx("div",{className:"flex items-center justify-center min-h-[320px]",children:e.jsx("div",{className:"animate-spin rounded-full h-10 w-10 border-2 border-blue-600 border-t-transparent"})}):n?e.jsxs("div",{className:"rounded-xl border border-red-200 bg-red-50 p-6 text-red-700 shadow-sm",children:[e.jsx("p",{children:n}),e.jsx("button",{type:"button",onClick:g,className:"mt-4 px-4 py-2 rounded-lg bg-red-100 hover:bg-red-200 text-red-800 font-medium text-sm transition-colors",children:"重试"})]}):!t||p.length===0?e.jsxs("div",{className:"rounded-xl border border-slate-200 bg-slate-50 p-8 text-slate-600 shadow-sm",children:[e.jsx("p",{className:"font-medium text-slate-700",children:"当前项目内未扫描到 SPM 包依赖关系。"}),e.jsxs("p",{className:"mt-2 text-sm",children:["请确保项目根目录下存在 ",e.jsx("code",{className:"bg-slate-200 px-1.5 py-0.5 rounded text-slate-800",children:"Package.swift"})," 或子目录中的 SPM 包,然后点击「Refresh Project」或执行 ",e.jsx("code",{className:"bg-slate-200 px-1.5 py-0.5 rounded",children:"asd spm-map"})," 刷新。"]})]}):e.jsxs("div",{className:"flex-1 flex flex-col overflow-hidden",children:[e.jsxs("div",{className:"mb-4 flex justify-between items-center shrink-0",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-10 h-10 rounded-xl bg-blue-50 border border-blue-100 flex items-center justify-center",children:e.jsx(et,{className:"text-blue-600",size:20})}),e.jsxs("div",{children:[e.jsx("h2",{className:"text-xl font-bold text-slate-800",children:"项目依赖关系图"}),e.jsxs("p",{className:"text-xs text-slate-400 mt-0.5",children:["SPM 包依赖结构可视化",t.projectRoot&&e.jsxs("span",{className:"ml-1",children:["· ",t.projectRoot]})]})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("button",{type:"button",onClick:()=>{g()},className:"flex items-center gap-1.5 px-3 py-2 rounded-lg text-xs font-bold transition-all text-slate-600 bg-slate-50 border border-slate-200 hover:bg-slate-100",children:[e.jsx(ht,{size:14})," 刷新"]}),e.jsxs("div",{className:"flex items-center gap-3 text-xs",children:[e.jsxs("div",{className:"flex items-center gap-1.5 px-3 py-1.5 rounded-lg bg-slate-50 border border-slate-100",children:[e.jsx(et,{size:14,className:"text-slate-400"}),e.jsxs("span",{className:"text-slate-500",children:["包 ",e.jsx("strong",{className:"text-slate-700",children:p.length})]})]}),e.jsxs("div",{className:"flex items-center gap-1.5 px-3 py-1.5 rounded-lg bg-emerald-50 border border-emerald-100",children:[e.jsx("span",{className:"text-emerald-500",children:"依赖"}),e.jsx("strong",{className:"text-emerald-700",children:u.length})]}),t.generatedAt&&e.jsx("div",{className:"flex items-center gap-1.5 px-3 py-1.5 rounded-lg bg-blue-50 border border-blue-100",children:e.jsx("span",{className:"text-blue-500",children:new Date(t.generatedAt).toLocaleString("zh-CN")})})]})]})]}),e.jsxs("div",{className:"flex-1 overflow-y-auto pr-1 space-y-6",children:[e.jsxs("div",{className:"rounded-xl border border-slate-200 bg-slate-50/50 overflow-auto shadow-sm min-h-[480px] flex items-center justify-center relative",children:[e.jsxs("svg",{width:"100%",height:m,viewBox:`0 0 ${q} ${m}`,className:"block min-h-[480px] w-full",style:{maxHeight:640},children:[e.jsx("defs",{children:e.jsx("filter",{id:"nodeShadow",x:"-20%",y:"-20%",width:"140%",height:"140%",children:e.jsx("feDropShadow",{dx:"0",dy:"2",stdDeviation:"2",floodOpacity:"0.12"})})}),R.map((d,v)=>{const k=h(v),ee=A.get(d);return ee?e.jsx("rect",{x:Ht,y:ee.y-qt/2-4,width:S,height:ee.h+8,rx:8,fill:k.bg,stroke:k.border,strokeWidth:"1",opacity:.6},d):null}),p.map(d=>{const v=w.get(d.id);if(!v)return null;const k=f.get(d.id)??0,ee=h(R.indexOf(k)),L=d.label.length>14?d.label.slice(0,13)+"…":d.label,Z=x===d.id,fe=x?(B.get(x)??[]).includes(d.id):!1,O=x?(T.get(x)??[]).includes(d.id):!1,re=x&&!Z&&!fe&&!O,ae=x?Z?{fill:"white",stroke:"rgb(59 130 246)",text:"rgb(30 64 175)",strokeWidth:3,opacity:1}:fe?{fill:"rgb(240 253 244)",stroke:"rgb(34 197 94)",text:"rgb(22 101 52)",strokeWidth:2,opacity:1}:O?{fill:"rgb(245 243 255)",stroke:"rgb(139 92 246)",text:"rgb(91 33 182)",strokeWidth:2,opacity:1}:{fill:"rgb(248 250 252)",stroke:"rgb(203 213 225)",text:"rgb(148 163 184)",strokeWidth:1,opacity:.6}:{fill:"white",stroke:ee.border,text:ee.text,strokeWidth:2,opacity:1};return e.jsxs("g",{style:{cursor:"pointer",opacity:ae.opacity},onClick:()=>i(Z?null:d.id),children:[e.jsx("rect",{x:v.x-wt/2,y:v.y-qt/2,width:wt,height:qt,rx:10,ry:10,fill:ae.fill,stroke:ae.stroke,strokeWidth:ae.strokeWidth,filter:re?void 0:"url(#nodeShadow)"}),e.jsx("text",{x:v.x,y:v.y,textAnchor:"middle",dominantBaseline:"middle",fontSize:"12",fontWeight:"600",fill:ae.text,pointerEvents:"none",children:L})]},d.id)})]}),x&&e.jsxs("div",{className:"absolute top-4 right-4 w-72 rounded-xl border border-slate-200 bg-white shadow-lg z-10 p-4",role:"dialog","aria-label":"依赖关系",children:[e.jsxs("div",{className:"flex items-center justify-between mb-3 pb-2 border-b border-slate-100",children:[e.jsx("span",{className:"font-bold text-slate-800",children:x}),e.jsx("button",{type:"button",onClick:()=>i(null),className:"text-slate-400 hover:text-slate-600 text-lg leading-none","aria-label":"关闭",children:"×"})]}),e.jsxs("div",{className:"space-y-3 text-sm",children:[e.jsxs("div",{children:[e.jsx("div",{className:"font-semibold text-slate-600 mb-1",children:"依赖"}),e.jsx("ul",{className:"text-slate-700 space-y-0.5",children:(B.get(x)??[]).length===0?e.jsx("li",{className:"text-slate-400",children:"无"}):(B.get(x)??[]).map(d=>e.jsxs("li",{children:["→ ",d]},d))})]}),e.jsxs("div",{children:[e.jsx("div",{className:"font-semibold text-slate-600 mb-1",children:"被依赖"}),e.jsx("ul",{className:"text-slate-700 space-y-0.5",children:(T.get(x)??[]).length===0?e.jsx("li",{className:"text-slate-400",children:"无"}):(T.get(x)??[]).map(d=>e.jsxs("li",{children:["← ",d]},d))})]})]})]})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-6",children:[e.jsxs("div",{className:"rounded-xl border border-slate-200 bg-white p-5 shadow-sm",children:[e.jsxs("h3",{className:"text-sm font-bold text-slate-800 mb-3 pb-2 border-b border-slate-100",children:["包列表 (",p.length,")"]}),e.jsx("ul",{className:"text-sm space-y-3 max-h-[280px] overflow-y-auto pr-1",children:p.map(d=>e.jsxs("li",{className:"pb-3 border-b border-slate-100 last:border-0 last:pb-0",children:[e.jsxs("div",{className:"flex items-baseline gap-2 flex-wrap",children:[e.jsx("span",{className:"font-semibold text-slate-800",children:d.id}),d.packageDir&&e.jsxs("span",{className:"text-slate-500 text-xs",children:["· ",d.packageDir]})]}),d.targets&&d.targets.length>0&&e.jsxs("div",{className:"mt-1.5 text-slate-500 text-xs pl-0",children:["Targets: ",e.jsx("span",{className:"text-slate-600",children:d.targets.join(", ")})]})]},d.id))})]}),e.jsxs("div",{className:"rounded-xl border border-slate-200 bg-white p-5 shadow-sm",children:[e.jsxs("h3",{className:"text-sm font-bold text-slate-800 mb-3 pb-2 border-b border-slate-100",children:["依赖关系(小图)(",u.length,")"]}),e.jsx("p",{className:"text-xs text-slate-500 mb-2",children:"主图不显示连线,点击节点可在浮窗查看该包依赖;此处列出全部 From → To。"}),e.jsx("ul",{className:"text-sm space-y-2 max-h-[280px] overflow-y-auto pr-1",children:u.map((d,v)=>e.jsxs("li",{className:"flex items-center gap-2 text-slate-700",children:[e.jsx("span",{className:"font-semibold text-slate-800",children:d.from}),e.jsx("span",{className:"text-slate-400 shrink-0",children:"→"}),e.jsx("span",{className:"font-semibold text-slate-800",children:d.to})]},`${d.from}-${d.to}-${v}`))})]}),N==="target"&&e.jsxs("p",{className:"text-xs text-slate-500 mt-2",children:["Target 级节点格式:",e.jsx("span",{className:"font-mono",children:"Package::Target"})]})]})]})]})},Fr=({onRefresh:t})=>{const[s,a]=r.useState({}),[l,n]=r.useState([]),[c,x]=r.useState(null),[i,N]=r.useState(!0),[j,g]=r.useState(!1),[p,u]=r.useState(!1),[w,f]=r.useState(""),[E,A]=r.useState(!1),[M,R]=r.useState({ruleId:"",message:"",severity:"warning",pattern:"",languages:["objc","swift"],note:"",dimension:""}),[B,T]=r.useState(!1),[U,K]=r.useState(""),S=async()=>{try{const[v,k]=await Promise.all([Y.getGuardRules(),Y.getGuardViolations()]);a((v==null?void 0:v.rules)||{}),n((k==null?void 0:k.runs)||[])}catch{a({}),n([])}finally{N(!1)}};r.useEffect(()=>{S()},[]);const q=async()=>{if(window.confirm("确定清空所有 Guard 违反记录?"))try{await Y.clearViolations(),S(),t==null||t()}catch(v){V((v==null?void 0:v.message)||"清空违反记录失败",{title:"操作失败",type:"error"})}},C=v=>{R(k=>({...k,languages:k.languages.includes(v)?k.languages.filter(ee=>ee!==v):[...k.languages,v]}))},m=async()=>{var v,k;if(!w.trim()){K("请先输入语义描述");return}K(""),A(!0);try{const L=await Y.generateGuardRule({description:w.trim()}),Z=L.dimension;R({ruleId:L.ruleId||"",message:L.message||"",severity:L.severity==="error"?"error":"warning",pattern:L.pattern||"",languages:Array.isArray(L.languages)&&L.languages.length>0?L.languages:["objc","swift"],note:L.note!=null?String(L.note):"",dimension:Z==="file"||Z==="target"||Z==="project"?Z:""}),u(!0)}catch(ee){K(((k=(v=ee==null?void 0:ee.response)==null?void 0:v.data)==null?void 0:k.error)||(ee==null?void 0:ee.message)||"AI 生成失败")}finally{A(!1)}},P=async v=>{var k,ee;if(v.preventDefault(),K(""),!M.ruleId.trim()||!M.message.trim()||!M.pattern.trim()||M.languages.length===0){K("请填写规则 ID、说明、正则和至少一种语言");return}T(!0);try{await Y.saveGuardRule({ruleId:M.ruleId.trim(),message:M.message.trim(),severity:M.severity,pattern:M.pattern.trim(),languages:M.languages,note:M.note.trim()||void 0,...M.dimension?{dimension:M.dimension}:{}}),R({ruleId:"",message:"",severity:"warning",pattern:"",languages:["objc","swift"],note:"",dimension:""}),f(""),u(!1),S(),t==null||t()}catch(L){K(((ee=(k=L==null?void 0:L.response)==null?void 0:k.data)==null?void 0:ee.error)||(L==null?void 0:L.message)||"写入失败")}finally{T(!1)}};if(i)return e.jsx("div",{className:"p-6 text-slate-500",children:"加载中..."});const h=Object.entries(s),d=l.reduce((v,k)=>v+k.violations.length,0);return e.jsxs("div",{className:"flex-1 flex flex-col overflow-hidden",children:[e.jsxs("div",{className:"mb-4 flex justify-between items-center shrink-0",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-10 h-10 rounded-xl bg-blue-50 border border-blue-100 flex items-center justify-center",children:e.jsx(nt,{className:"text-blue-600",size:20})}),e.jsxs("div",{children:[e.jsx("h2",{className:"text-xl font-bold text-slate-800",children:"Guard 规则与违反记录"}),e.jsx("p",{className:"text-xs text-slate-400 mt-0.5",children:"静态规则检查 · 自动审计代码变更"})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("a",{href:Cl,target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1.5 px-3 py-2 rounded-lg text-xs font-bold transition-all text-slate-600 bg-slate-50 border border-slate-200 hover:bg-slate-100",children:[e.jsx(el,{size:14})," 提交误报"]}),e.jsxs("button",{type:"button",onClick:()=>g(!j),className:"flex items-center gap-1.5 px-3 py-2 rounded-lg text-xs font-bold transition-all text-blue-700 bg-blue-50 border border-blue-200 hover:bg-blue-100",children:[j?e.jsx(St,{size:14}):e.jsx(at,{size:14}),"AI 写入规则"]}),l.length>0&&e.jsxs("button",{type:"button",onClick:q,className:"flex items-center gap-1.5 px-3 py-2 rounded-lg text-xs font-bold transition-all text-red-600 bg-red-50 border border-red-200 hover:bg-red-100",children:[e.jsx(st,{size:14})," 清空历史"]}),e.jsxs("div",{className:"flex items-center gap-3 text-xs",children:[e.jsxs("div",{className:"flex items-center gap-1.5 px-3 py-1.5 rounded-lg bg-slate-50 border border-slate-100",children:[e.jsx(nt,{size:14,className:"text-slate-400"}),e.jsxs("span",{className:"text-slate-500",children:["规则 ",e.jsx("strong",{className:"text-slate-700",children:h.length})," 条"]})]}),d>0&&e.jsxs("div",{className:"flex items-center gap-1.5 px-3 py-1.5 rounded-lg bg-amber-50 border border-amber-100",children:[e.jsx(At,{size:14,className:"text-amber-400"}),e.jsxs("span",{className:"text-amber-600",children:["违反 ",e.jsx("strong",{className:"text-amber-700",children:d})]})]})]})]})]}),e.jsxs("div",{className:"flex-1 overflow-y-auto pr-1",children:[j&&e.jsxs("section",{className:"mb-6",children:[e.jsxs("div",{className:"p-4 bg-slate-50 border border-slate-200 rounded-xl space-y-3",children:[e.jsxs("div",{children:[e.jsx("label",{htmlFor:"semantic-input",className:"block text-xs font-medium text-slate-600 mb-1",children:"语义描述(由 AI 生成规则表单)"}),e.jsx("textarea",{id:"semantic-input",name:"semanticInput",value:w,onChange:v=>{f(v.target.value),K("")},className:"w-full px-3 py-2 border border-slate-200 rounded-lg text-sm resize-y min-h-[80px]",placeholder:"例如:禁止在主线程使用 dispatch_sync 调用 main queue,易死锁",rows:3}),e.jsx("button",{type:"button",onClick:m,disabled:E||!w.trim(),className:"mt-2 px-4 py-2 bg-slate-600 text-white text-sm rounded-lg hover:bg-slate-700 disabled:opacity-50",children:E?"生成中...":"AI 生成"}),U&&e.jsx("p",{className:"mt-2 text-sm text-red-600",children:U})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{type:"button",onClick:()=>u(!p),className:"text-sm font-medium text-blue-600 hover:text-blue-700",children:p?"收起表单":"展开 / 编辑表单"}),M.ruleId&&e.jsxs("span",{className:"text-xs text-slate-500",children:["已生成规则 ID:",M.ruleId]})]})]}),p&&e.jsxs("form",{onSubmit:P,className:"mt-3 p-4 bg-white border border-slate-200 rounded-xl space-y-3",children:[e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-3",children:[e.jsxs("div",{children:[e.jsx("label",{htmlFor:"rule-id",className:"block text-xs font-medium text-slate-600 mb-1",children:"规则 ID(英文,如 no-force-unwrap)"}),e.jsx("input",{id:"rule-id",name:"ruleId",type:"text",value:M.ruleId,onChange:v=>R(k=>({...k,ruleId:v.target.value})),className:"w-full px-3 py-2 border border-slate-200 rounded-lg text-sm",placeholder:"my-rule-id"})]}),e.jsxs("div",{children:[e.jsx("label",{htmlFor:"rule-severity",className:"block text-xs font-medium text-slate-600 mb-1",children:"严重性"}),e.jsxs("select",{id:"rule-severity",name:"severity",value:M.severity,onChange:v=>R(k=>({...k,severity:v.target.value})),className:"w-full px-3 py-2 border border-slate-200 rounded-lg text-sm",children:[e.jsx("option",{value:"warning",children:"warning"}),e.jsx("option",{value:"error",children:"error"})]})]})]}),e.jsxs("div",{children:[e.jsx("label",{htmlFor:"rule-message",className:"block text-xs font-medium text-slate-600 mb-1",children:"说明(违反时提示)"}),e.jsx("input",{id:"rule-message",name:"message",type:"text",value:M.message,onChange:v=>R(k=>({...k,message:v.target.value})),className:"w-full px-3 py-2 border border-slate-200 rounded-lg text-sm",placeholder:"禁止在主线程上使用 dispatch_sync(main)"})]}),e.jsxs("div",{children:[e.jsx("label",{htmlFor:"rule-pattern",className:"block text-xs font-medium text-slate-600 mb-1",children:"正则(对每行匹配,JSON 中反斜杠需双写)"}),e.jsx("input",{id:"rule-pattern",name:"pattern",type:"text",value:M.pattern,onChange:v=>R(k=>({...k,pattern:v.target.value})),className:"w-full px-3 py-2 border border-slate-200 rounded-lg text-sm font-mono",placeholder:"dispatch_sync\\\\s*\\\\([^)]*main"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-medium text-slate-600 mb-1",children:"适用语言"}),e.jsxs("div",{className:"flex gap-4",children:[e.jsxs("label",{htmlFor:"lang-objc",className:"flex items-center gap-2 text-sm",children:[e.jsx("input",{id:"lang-objc",name:"languages",type:"checkbox",checked:M.languages.includes("objc"),onChange:()=>C("objc")}),"objc"]}),e.jsxs("label",{htmlFor:"lang-swift",className:"flex items-center gap-2 text-sm",children:[e.jsx("input",{id:"lang-swift",name:"languages",type:"checkbox",checked:M.languages.includes("swift"),onChange:()=>C("swift")}),"swift"]})]})]}),e.jsxs("div",{children:[e.jsx("label",{htmlFor:"rule-dimension",className:"block text-xs font-medium text-slate-600 mb-1",children:"审查规模(可选,as:audit 后缀可限定)"}),e.jsxs("select",{id:"rule-dimension",name:"dimension",value:M.dimension,onChange:v=>R(k=>({...k,dimension:v.target.value})),className:"w-full px-3 py-2 border border-slate-200 rounded-lg text-sm",children:[e.jsx("option",{value:"",children:"不限制(任意 as:audit / as:audit file / as:audit target / as:audit project 均运行)"}),e.jsx("option",{value:"file",children:"同文件(仅 as:audit file 时运行)"}),e.jsx("option",{value:"target",children:"同 target(仅 as:audit target 时运行)"}),e.jsx("option",{value:"project",children:"同项目(仅 as:audit project 时运行)"})]})]}),e.jsxs("div",{children:[e.jsx("label",{htmlFor:"rule-note",className:"block text-xs font-medium text-slate-600 mb-1",children:"备注(可选)"}),e.jsx("input",{id:"rule-note",name:"note",type:"text",value:M.note,onChange:v=>R(k=>({...k,note:v.target.value})),className:"w-full px-3 py-2 border border-slate-200 rounded-lg text-sm",placeholder:"仅作简单模式提示"})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("button",{type:"submit",disabled:B,className:"px-4 py-2 bg-blue-600 text-white text-sm rounded-lg hover:bg-blue-700 disabled:opacity-50",children:B?"写入中...":"确认写入"}),e.jsx("button",{type:"button",onClick:()=>u(!1),className:"px-4 py-2 text-slate-600 text-sm rounded-lg hover:bg-slate-100",children:"收起"})]})]})]}),e.jsxs("section",{className:"mb-8",children:[e.jsx("h3",{className:"text-sm font-semibold text-slate-700 mb-3",children:"iOS 版本规则(guard-rules.json)"}),e.jsx("div",{className:"bg-white border border-slate-200 rounded-xl overflow-hidden",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{className:"bg-slate-50 border-b border-slate-200",children:e.jsxs("tr",{children:[e.jsx("th",{className:"text-left py-2 px-4 font-medium text-slate-600",children:"规则 ID"}),e.jsx("th",{className:"text-left py-2 px-4 font-medium text-slate-600",children:"严重性"}),e.jsx("th",{className:"text-left py-2 px-4 font-medium text-slate-600",children:"说明"}),e.jsx("th",{className:"text-left py-2 px-4 font-medium text-slate-600",children:"适用语言"}),e.jsx("th",{className:"text-left py-2 px-4 font-medium text-slate-600",children:"审查规模"})]})}),e.jsx("tbody",{children:h.length===0?e.jsx("tr",{children:e.jsx("td",{colSpan:5,className:"py-4 px-4 text-slate-500",children:"暂无规则"})}):h.map(([v,k])=>e.jsxs("tr",{className:"border-b border-slate-100 last:border-0",children:[e.jsx("td",{className:"py-2 px-4 font-mono text-xs",children:v}),e.jsx("td",{className:"py-2 px-4",children:e.jsx("span",{className:`text-xs font-medium px-1.5 py-0.5 rounded ${k.severity==="error"?"bg-red-100 text-red-700":"bg-amber-100 text-amber-700"}`,children:k.severity})}),e.jsx("td",{className:"py-2 px-4 text-slate-700",children:k.message}),e.jsx("td",{className:"py-2 px-4 text-slate-500",children:(k.languages||[]).join(", ")}),e.jsx("td",{className:"py-2 px-4 text-slate-500 text-xs",children:k.dimension==="file"?"同文件":k.dimension==="target"?"同 target":k.dimension==="project"?"同项目":"—"})]},v))})]})})]}),e.jsxs("section",{children:[e.jsxs("h3",{className:"text-sm font-semibold text-slate-700 mb-3",children:["违反记录(共 ",l.length," 次运行,",d," 处违反)"]}),l.length===0?e.jsxs("div",{className:"bg-slate-50 border border-slate-200 rounded-xl py-12 text-center text-slate-500",children:["暂无违反记录。在源码中写入 ",e.jsx("code",{className:"bg-slate-200 px-1 rounded",children:"// as:audit"})," 并保存,watch 会执行静态规则检查并记录在此。"]}):e.jsx("div",{className:"space-y-2",children:l.map(v=>{const k=c===v.id,ee=v.violations.length>0;return e.jsxs("div",{className:"bg-white border border-slate-200 rounded-xl overflow-hidden",children:[e.jsxs("button",{type:"button",onClick:()=>x(k?null:v.id),className:"w-full flex items-center gap-2 py-3 px-4 text-left hover:bg-slate-50 transition-colors",children:[k?e.jsx(St,{size:$.md}):e.jsx(at,{size:$.md}),e.jsx("span",{className:"font-mono text-sm text-slate-700",children:v.filePath}),e.jsx("span",{className:"text-xs text-slate-400",children:new Date(v.triggeredAt).toLocaleString()}),ee?e.jsxs("span",{className:"ml-auto flex items-center gap-1 text-amber-600 text-xs font-medium",children:[e.jsx(At,{size:$.sm})," ",v.violations.length," 处违反"]}):e.jsx("span",{className:"ml-auto text-slate-400 text-xs",children:"无违反"})]}),k&&e.jsx("div",{className:"border-t border-slate-100 bg-slate-50/50 p-4",children:v.violations.length===0?e.jsx("p",{className:"text-sm text-slate-500",children:"本次运行未发现违反。"}):e.jsx("ul",{className:"space-y-2",children:v.violations.map((L,Z)=>{var O;const fe=s[L.ruleId];return e.jsxs("li",{className:"flex items-start gap-2 text-sm",children:[L.severity==="error"?e.jsx(Kt,{size:$.md,className:"text-red-500 shrink-0 mt-0.5"}):e.jsx(At,{size:$.md,className:"text-amber-500 shrink-0 mt-0.5"}),e.jsxs("div",{className:"flex-1 space-y-1.5",children:[e.jsxs("div",{children:[e.jsxs("span",{className:"font-mono text-xs text-slate-500",children:["[",L.ruleId,"] ",L.filePath?`${L.filePath}:${L.line}`:`L${L.line}`]}),L.dimension&&e.jsx("span",{className:"ml-1.5 text-xs px-1.5 py-0.5 rounded bg-slate-200 text-slate-600",children:L.dimension==="file"?"同文件":L.dimension==="target"?"同 target":"同项目"}),e.jsx("span",{className:"text-slate-700 ml-2",children:L.message})]}),L.snippet&&e.jsx("pre",{className:"text-xs text-slate-600 bg-slate-100 p-2 rounded overflow-x-auto",children:L.snippet}),fe&&(fe.rationale||((O=fe.fixSuggestions)==null?void 0:O.length)||fe.sourceRecipe||fe.note)&&e.jsxs("div",{className:"mt-1 rounded-lg border border-blue-100 bg-blue-50/50 p-2.5 text-xs space-y-1.5",children:[fe.rationale&&e.jsxs("div",{className:"flex items-start gap-1.5",children:[e.jsx(Je,{size:12,className:"text-blue-500 shrink-0 mt-0.5"}),e.jsxs("div",{children:[e.jsx("span",{className:"font-bold text-blue-700",children:"技术原因:"}),e.jsx("span",{className:"text-slate-600",children:fe.rationale})]})]}),fe.fixSuggestions&&fe.fixSuggestions.length>0&&e.jsxs("div",{className:"flex items-start gap-1.5",children:[e.jsx(pa,{size:12,className:"text-emerald-500 shrink-0 mt-0.5"}),e.jsxs("div",{children:[e.jsx("span",{className:"font-bold text-emerald-700",children:"修复建议:"}),e.jsx("ul",{className:"mt-0.5 space-y-0.5 text-slate-600",children:fe.fixSuggestions.map((re,ae)=>e.jsxs("li",{className:"flex items-start gap-1",children:[e.jsx("span",{className:"text-emerald-400 mt-0.5",children:"•"}),e.jsx("span",{children:re}),e.jsx("button",{className:"ml-1 text-blue-500 hover:text-blue-700",title:"复制修复建议",onClick:()=>navigator.clipboard.writeText(re),children:"⎘"})]},ae))})]})]}),fe.sourceRecipe&&e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(zs,{size:12,className:"text-indigo-500 shrink-0"}),e.jsx("span",{className:"font-bold text-indigo-700",children:"来源 Recipe:"}),e.jsx("span",{className:"text-indigo-600 font-mono",children:fe.sourceRecipe})]}),!fe.rationale&&fe.note&&e.jsxs("div",{className:"text-slate-500 italic",children:["备注:",fe.note]})]})]})]},Z)})})})]},v.id)})})]})]})]})},js=()=>Math.random().toString(36).substring(2,10),Or=({d:t})=>e.jsxs("div",{className:"border border-slate-200 rounded-lg overflow-hidden",children:[e.jsxs("div",{className:"px-2.5 py-1 bg-slate-50 border-b border-slate-200 flex items-center gap-1.5",children:[e.jsx(ca,{size:10,className:"text-emerald-500"}),e.jsx("span",{className:"text-[10px] font-bold text-slate-600",children:t.label})]}),e.jsxs("div",{className:"p-2.5 bg-red-50/30 border-b border-slate-200",children:[e.jsx("div",{className:"text-[9px] font-bold text-red-400 mb-0.5 uppercase",children:"Before"}),e.jsx("pre",{className:"text-[11px] text-slate-600 whitespace-pre-wrap break-words max-h-48 overflow-auto font-mono leading-relaxed scrollbar-light",children:t.before||e.jsx("span",{className:"italic text-slate-300",children:"(空)"})})]}),e.jsxs("div",{className:"p-2.5 bg-emerald-50/30",children:[e.jsx("div",{className:"text-[9px] font-bold text-emerald-500 mb-0.5 uppercase",children:"After"}),e.jsx("pre",{className:"text-[11px] text-slate-700 whitespace-pre-wrap break-words max-h-48 overflow-auto font-mono leading-relaxed scrollbar-light",children:t.after})]})]});function Br(t){const s=new Date(t),l=new Date().getTime()-s.getTime(),n=Math.floor(l/6e4);if(n<1)return"刚刚";if(n<60)return`${n}分钟前`;const c=Math.floor(n/60);if(c<24)return`${c}小时前`;const x=Math.floor(c/24);return x<7?`${x}天前`:s.toLocaleDateString("zh-CN",{month:"short",day:"numeric"})}const qr=()=>{const t=sr(),{close:s,isOpen:a}=ts(),{messages:l,setMessages:n,loading:c,setLoading:x,chatHistoryRef:i}=t,N=Na(),{topics:j,activeTopicId:g,activeTopic:p,createTopic:u,deleteTopic:w,saveTopic:f,switchTopic:E,setActiveTopicId:A}=N,M=r.useRef(null),R=r.useRef(null),[B,T]=r.useState(""),[U,K]=r.useState(!1),S=r.useRef(!1);r.useEffect(()=>{a&&s()},[]),r.useEffect(()=>{var d;(d=M.current)==null||d.scrollIntoView({behavior:"smooth"})},[l,c]),r.useEffect(()=>{setTimeout(()=>{var d;return(d=R.current)==null?void 0:d.focus()},200)},[]),r.useEffect(()=>{S.current||g&&l.length>0&&f(g,l)},[l,g,f]);const q=r.useCallback(()=>{S.current=!0,u(),n([]),i.current=[],setTimeout(()=>{S.current=!1},50)},[u,n,i]),C=r.useCallback(d=>{if(d===g)return;S.current=!0,E(d);const v=N.getTopic(d);v?(n(v.messages),i.current=v.messages.filter(k=>k.role==="user"||k.role==="assistant").map(k=>({role:k.role==="assistant"?"model":k.role,content:k.content}))):(n([]),i.current=[]),setTimeout(()=>{S.current=!1},50)},[g,E,N,n,i]),m=r.useCallback((d,v)=>{d.stopPropagation(),w(v),v===g&&(S.current=!0,n([]),i.current=[],setTimeout(()=>{S.current=!1},50))},[w,g,n,i]),P=r.useCallback(async()=>{const d=B.trim();if(!d||c)return;let v=g;v||(S.current=!0,v=u(),setTimeout(()=>{S.current=!1},50)),T(""),n(k=>[...k,{id:js(),role:"user",content:d,timestamp:Date.now()}]),x(!0),i.current.push({role:"user",content:d});try{const k=await Y.chat(d,i.current);i.current.push({role:"model",content:k.text}),n(ee=>[...ee,{id:js(),role:"assistant",content:k.text,timestamp:Date.now()}])}catch(k){n(ee=>[...ee,{id:js(),role:"assistant",content:`请求失败: ${k.message}`,timestamp:Date.now()}])}x(!1)},[B,c,g,u]),h=r.useCallback(d=>{d.key==="Enter"&&!d.shiftKey&&(d.preventDefault(),P())},[P]);return e.jsxs("div",{className:"flex-1 flex h-full bg-slate-50",children:[e.jsx("div",{className:`${U?"w-10":"w-64"} shrink-0 bg-white border-r border-slate-200 flex flex-col transition-all duration-200`,children:U?e.jsxs("div",{className:"flex flex-col items-center py-3 gap-2",children:[e.jsx("button",{onClick:()=>K(!1),className:"p-1.5 hover:bg-slate-100 rounded-lg transition-colors text-slate-400 hover:text-slate-600",title:"展开话题列表",children:e.jsx(at,{size:16})}),e.jsx("button",{onClick:q,className:"p-1.5 hover:bg-blue-50 rounded-lg transition-colors text-blue-500",title:"新建话题",children:e.jsx(Nt,{size:16})})]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"px-3 py-2.5 border-b border-slate-100 flex items-center justify-between shrink-0",children:[e.jsx("span",{className:"text-xs font-bold text-slate-500 uppercase tracking-wider",children:"话题记录"}),e.jsxs("div",{className:"flex items-center gap-0.5",children:[e.jsx("button",{onClick:q,className:"p-1.5 hover:bg-blue-50 rounded-lg transition-colors text-slate-400 hover:text-blue-600",title:"新建话题",children:e.jsx(Nt,{size:14})}),e.jsx("button",{onClick:()=>K(!0),className:"p-1.5 hover:bg-slate-100 rounded-lg transition-colors text-slate-400 hover:text-slate-600",title:"折叠",children:e.jsx(Zt,{size:14})})]})]}),e.jsx("div",{className:"flex-1 overflow-y-auto scrollbar-light",children:j.length===0?e.jsxs("div",{className:"px-4 py-8 text-center",children:[e.jsx(Ct,{size:24,className:"text-slate-200 mx-auto mb-2"}),e.jsx("p",{className:"text-xs text-slate-400",children:"暂无聊天记录"}),e.jsx("p",{className:"text-[10px] text-slate-300 mt-1",children:"开始对话后自动保存"})]}):e.jsx("div",{className:"py-1",children:j.map(d=>{const v=d.id===g,k=d.messages.filter(ee=>ee.role==="user").length;return e.jsx("div",{onClick:()=>C(d.id),className:`group mx-1.5 mb-0.5 px-3 py-2 rounded-lg cursor-pointer transition-colors ${v?"bg-blue-50 border border-blue-200":"hover:bg-slate-50 border border-transparent"}`,children:e.jsxs("div",{className:"flex items-start justify-between gap-1.5",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:`text-xs font-medium truncate leading-snug ${v?"text-blue-700":"text-slate-700"}`,children:d.title}),e.jsxs("div",{className:"flex items-center gap-2 mt-0.5",children:[e.jsxs("span",{className:"text-[10px] text-slate-400 flex items-center gap-0.5",children:[e.jsx(it,{size:9}),Br(d.updatedAt)]}),k>0&&e.jsxs("span",{className:"text-[10px] text-slate-300",children:[k," 条"]})]})]}),e.jsx("button",{onClick:ee=>m(ee,d.id),className:`p-1 rounded transition-colors shrink-0 ${v?"text-blue-400 hover:text-red-500 hover:bg-red-50":"text-transparent group-hover:text-slate-300 hover:!text-red-500 hover:!bg-red-50"}`,title:"删除话题",children:e.jsx(st,{size:12})})]})},d.id)})})}),j.length>0&&e.jsx("div",{className:"px-3 py-2 border-t border-slate-100 shrink-0",children:e.jsxs("span",{className:"text-[10px] text-slate-400",children:[j.length," 个话题 · 本地存储"]})})]})}),e.jsxs("div",{className:"flex-1 flex flex-col min-w-0",children:[e.jsxs("div",{className:"px-6 py-3 border-b border-slate-200 bg-white flex items-center justify-between shrink-0",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-9 h-9 rounded-xl bg-gradient-to-br from-blue-50 to-indigo-50 border border-blue-100 flex items-center justify-center",children:e.jsx(Ct,{className:"text-blue-600",size:18})}),e.jsxs("div",{children:[e.jsx("h2",{className:"text-sm font-bold text-slate-800",children:p?p.title:"AI Chat"}),e.jsx("p",{className:"text-[11px] text-slate-400",children:"询问任何关于项目的问题"})]})]}),l.length>0&&e.jsxs("button",{onClick:q,className:"flex items-center gap-1.5 px-3 py-1.5 text-xs font-medium text-slate-500 hover:text-blue-600 hover:bg-blue-50 rounded-lg transition-colors border border-slate-200 hover:border-blue-200",children:[e.jsx(Nt,{size:14}),"开启新话题"]})]}),e.jsx("div",{className:"flex-1 overflow-y-auto min-h-0 scrollbar-light",children:e.jsxs("div",{className:"max-w-3xl mx-auto p-6 space-y-4",children:[l.length===0&&e.jsxs("div",{className:"flex flex-col items-center justify-center py-20 text-center",children:[e.jsx("div",{className:"w-16 h-16 rounded-2xl bg-gradient-to-br from-blue-50 to-indigo-50 border border-blue-100 flex items-center justify-center mb-4",children:e.jsx(Ke,{className:"text-blue-500",size:28})}),e.jsx("h3",{className:"text-base font-bold text-slate-700 mb-2",children:"开始 AI 对话"}),e.jsx("p",{className:"text-sm text-slate-400 max-w-md leading-relaxed mb-5",children:"询问关于你项目的任何问题 — 代码分析、架构建议、优化方向等。"}),e.jsx("div",{className:"flex flex-wrap gap-2 justify-center",children:["分析项目架构","查找重复代码","推荐优化方向","总结项目概况"].map(d=>e.jsx("button",{onClick:()=>{var v;T(d),(v=R.current)==null||v.focus()},className:"text-xs px-3.5 py-2 rounded-lg bg-white border border-slate-200 text-slate-600 hover:bg-blue-50 hover:text-blue-700 hover:border-blue-200 transition-colors shadow-sm",children:d},d))})]}),l.map(d=>e.jsx("div",{className:`flex ${d.role==="user"?"justify-end":"justify-start"}`,children:e.jsxs("div",{className:`max-w-[80%] ${d.role==="user"?"bg-blue-600 text-white rounded-2xl rounded-tr-md px-4 py-2.5":d.role==="system"?"bg-slate-100 border border-slate-200 text-slate-600 rounded-2xl px-4 py-2.5 w-full":"bg-white border border-slate-200 rounded-2xl rounded-tl-md px-4 py-3 shadow-sm w-full"}`,children:[d.role==="assistant"&&e.jsxs("div",{className:"flex items-center gap-1.5 mb-2",children:[e.jsx(Yt,{size:13,className:"text-blue-500"}),e.jsx("span",{className:"text-[11px] font-bold text-blue-600",children:"AI 助手"})]}),d.role==="assistant"&&!d.diff?e.jsx(ut,{content:d.content,className:"text-sm text-slate-700"}):e.jsx("p",{className:`text-sm leading-relaxed whitespace-pre-wrap ${d.role==="user"?"":"text-slate-600"}`,children:d.content}),d.diff&&d.diff.length>0&&e.jsx("div",{className:"space-y-2 mt-2",children:d.diff.map(v=>e.jsx(Or,{d:v},v.field))})]})},d.id)),c&&e.jsx("div",{className:"flex justify-start",children:e.jsx("div",{className:"bg-white border border-slate-200 rounded-2xl rounded-tl-md px-4 py-3 shadow-sm",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Te,{size:14,className:"animate-spin text-blue-500"}),e.jsx("span",{className:"text-sm text-slate-500",children:"AI 思考中..."})]})})}),e.jsx("div",{ref:M})]})}),e.jsx("div",{className:"border-t border-slate-200 bg-white shrink-0",children:e.jsxs("div",{className:"max-w-3xl mx-auto px-6 py-3",children:[e.jsxs("div",{className:"flex gap-2",children:[e.jsx("textarea",{ref:R,value:B,onChange:d=>T(d.target.value),onKeyDown:h,placeholder:"输入你的问题...",rows:2,className:"flex-1 px-4 py-2.5 text-sm border border-slate-200 rounded-xl focus:outline-none focus:ring-2 focus:ring-blue-200 focus:border-blue-400 resize-none placeholder:text-slate-300",disabled:c}),e.jsx("button",{onClick:P,disabled:!B.trim()||c,className:"self-stretch w-10 flex items-center justify-center rounded-xl bg-gradient-to-r from-blue-500 to-indigo-600 hover:from-blue-600 hover:to-indigo-700 text-white disabled:opacity-40 disabled:cursor-not-allowed transition-all shadow-sm shrink-0",children:e.jsx(Ss,{size:16})})]}),e.jsx("p",{className:"text-[10px] text-slate-400 mt-1.5",children:"Enter 发送 · Shift+Enter 换行"})]})})]})]})},Hr=28,Gr=22,Wr=50,Ur=11,Kr=10,pt={depends_on:"#3b82f6",requires:"#3b82f6",extends:"#10b981",implements:"#10b981",inherits:"#10b981",enforces:"#f59e0b",related:"#8b5cf6",conflicts:"#ef4444",calls:"#06b6d4",prerequisite:"#f97316",data_flow_to:"#14b8a6",references:"#6b7280",alternative:"#a855f7",deprecated_by:"#dc2626",solves:"#22c55e"},rs={depends_on:"依赖",requires:"需要",extends:"扩展",implements:"实现",inherits:"继承",enforces:"约束",related:"关联",conflicts:"冲突",calls:"调用",prerequisite:"前置",data_flow_to:"数据流",references:"引用",alternative:"替代",deprecated_by:"废弃",solves:"解决"},ns=[{bg:"#eff6ff",border:"#bfdbfe",text:"#1d4ed8"},{bg:"#f0fdf4",border:"#bbf7d0",text:"#15803d"},{bg:"#fef3c7",border:"#fde68a",text:"#b45309"},{bg:"#fdf2f8",border:"#fbcfe8",text:"#be185d"},{bg:"#f5f3ff",border:"#ddd6fe",text:"#7c3aed"},{bg:"#ecfeff",border:"#a5f3fc",text:"#0e7490"},{bg:"#fff7ed",border:"#fed7aa",text:"#c2410c"},{bg:"#f0f9ff",border:"#bae6fd",text:"#0369a1"},{bg:"#fefce8",border:"#fef08a",text:"#a16207"},{bg:"#f1f5f9",border:"#cbd5e1",text:"#475569"}];function vt(t){return Math.min(Wr,Math.max(Gr,Hr+t*2))}function Zs(t,s){return t.length<=s?t:t.substring(0,s-1)+"…"}function Vr(t,s,a,l){const n=new Map;for(const g of t)n.set(g.fromId,(n.get(g.fromId)||0)+1),n.set(g.toId,(n.get(g.toId)||0)+1);const c=[...n.keys()],x=[...new Set(c.map(g=>l[g]||"general"))].sort(),i=new Map,N=Math.ceil(Math.sqrt(x.length)),j=400;return x.forEach((g,p)=>{const u=p%N,w=Math.floor(p/N);i.set(g,{x:450+(u-(N-1)/2)*j,y:350+(w-(Math.ceil(x.length/N)-1)/2)*j})}),c.map(g=>{const p=l[g]||"general",u=i.get(p)||{x:450,y:350},w=Math.random()*2*Math.PI,f=40+Math.random()*80;return{id:g,label:s[g]||g,type:a[g]||"recipe",group:p,x:u.x+f*Math.cos(w),y:u.y+f*Math.sin(w),vx:0,vy:0,degree:n.get(g)||1}})}function Yr(t,s,a=200){const l=t.map(x=>({...x})),n=new Map(l.map(x=>[x.id,x]));function c(){const x=new Map;for(const i of l){const N=x.get(i.group);N?(N.x+=i.x,N.y+=i.y,N.count++):x.set(i.group,{x:i.x,y:i.y,count:1})}for(const[,i]of x)i.x/=i.count,i.y/=i.count;return x}for(let x=0;x<a;x++){const i=1-x/a,N=18e3*i,j=.015,g=.8,p=c();for(let w=0;w<l.length;w++)for(let f=w+1;f<l.length;f++){const E=l[w],A=l[f];let M=A.x-E.x,R=A.y-E.y,B=Math.sqrt(M*M+R*R)||1;const T=vt(E.degree)+vt(A.degree)+60,U=Math.max(B,1),K=E.group===A.group?.6:1.4,S=N*K/(U*U),q=B<T?(T-B)*.5:0,C=S+q,m=M/U*C,P=R/U*C;E.vx-=m,E.vy-=P,A.vx+=m,A.vy+=P}for(const w of s){const f=n.get(w.fromId),E=n.get(w.toId);if(!f||!E)continue;let A=E.x-f.x,M=E.y-f.y,R=Math.sqrt(A*A+M*M)||1;const B=f.group===E.group?140:280,T=j*(R-B),U=A/R*T,K=M/R*T;f.vx+=U,f.vy+=K,E.vx-=U,E.vy-=K}const u=.008*i;for(const w of l){const f=p.get(w.group);f&&(w.vx+=(f.x-w.x)*u,w.vy+=(f.y-w.y)*u)}for(const w of l)w.vx*=g,w.vy*=g,w.x+=w.vx,w.y+=w.vy}return l}function Jr(t,s,a,l,n,c,x=0){const i=a-t,N=l-s,j=Math.sqrt(i*i+N*N)||1,g=i/j,p=N/j,u=t+g*n,w=s+p*n,f=a-g*c,E=l-p*c;if(x===0)return`M${u},${w}L${f},${E}`;const A=(u+f)/2+-p*x,M=(w+E)/2+g*x;return`M${u},${w}Q${A},${M},${f},${E}`}const Xr=()=>{const[t,s]=r.useState([]),[a,l]=r.useState({}),[n,c]=r.useState({}),[x,i]=r.useState({}),[N,j]=r.useState(null),[g,p]=r.useState(!0),[u,w]=r.useState(null),[f,E]=r.useState(null),[A,M]=r.useState(null),[R,B]=r.useState(null),[T,U]=r.useState(!1),[K,S]=r.useState(null),[q,C]=r.useState(1),[m,P]=r.useState({x:0,y:0}),h=r.useRef(null),d=r.useRef(null),v=r.useRef(!1),k=r.useRef({x:0,y:0}),ee=async()=>{var y,de;p(!0),w(null);try{const[ce,te]=await Promise.all([Y.getKnowledgeGraph(),Y.getGraphStats()]);s(ce.edges||[]),l(ce.nodeLabels||{}),c(ce.nodeTypes||{}),i(ce.nodeCategories||{}),j(te)}catch(ce){w(((de=(y=ce.response)==null?void 0:y.data)==null?void 0:de.error)||ce.message||"加载知识图谱失败")}finally{p(!1)}};r.useEffect(()=>{ee()},[]),r.useEffect(()=>{Y.getDiscoverRelationsStatus().then(y=>{y.status==="running"&&(U(!0),S(`AI 分析中…(已运行 ${y.elapsed??0}s)`))}).catch(()=>{})},[]),r.useEffect(()=>{if(!T)return;let y=0;const de=240,ce=setInterval(async()=>{if(y++,y>de){clearInterval(ce),U(!1),S("轮询超时,任务可能仍在后台运行。请稍后刷新页面查看结果。");return}try{const te=await Y.getDiscoverRelationsStatus();if(te.status==="done"){U(!1);const pe=te.discovered??0,o=te.totalPairs??0,F=te.batchErrors??0;pe===0&&F===0?S(`分析完成,共检查 ${o} 对 Recipe,未发现关系。待 Recipe 数量增加后可再次尝试。`):pe===0&&F>0?S(`分析完成,但 ${F} 个批次 AI 调用失败,未发现关系。请检查 AI Provider 配置。`):S(`发现 ${pe} 条关系(共分析 ${o} 对${F>0?`,${F} 个批次失败`:""})`),ee()}else if(te.status==="error"){U(!1);const pe=te.error||"未知错误";pe.includes("AI Provider")||pe.includes("API Key")?S(`AI 服务未配置: ${pe}`):pe.includes("超时")||pe.includes("timeout")?S(`任务超时: ${pe}`):S(`发现失败: ${pe}`)}else te.status==="running"&&S(`AI 分析中…(已运行 ${te.elapsed??0}s)`)}catch{}},3e3);return()=>clearInterval(ce)},[T]);const L=r.useCallback(async()=>{var y,de,ce;S(null);try{const te=await Y.discoverRelations();if(te.status==="empty"){S(te.message||"Recipe 数量不足,无法分析");return}if(te.status==="timeout"){S(te.error||"上次任务超时,请重试");return}if(te.status==="running"){U(!0),S("AI 分析仍在进行中…");return}U(!0),S("AI 分析已启动,正在后台运行…")}catch(te){const pe=((ce=(de=(y=te==null?void 0:te.response)==null?void 0:y.data)==null?void 0:de.error)==null?void 0:ce.message)||te.message||"未知错误";pe.includes("ChatAgent")||pe.includes("AI Provider")?S(`AI 服务不可用: ${pe}`):S(`启动失败: ${pe}`)}},[]),Z=r.useMemo(()=>{if(t.length===0)return[];const y=Vr(t,a,n,x);return Yr(y,t)},[t,a,n,x]),fe=r.useMemo(()=>{const y=new Map;for(const te of Z){const pe=y.get(te.group)||[];pe.push(te),y.set(te.group,pe)}const de=[],ce=[...y.keys()].sort();for(const te of ce){const pe=y.get(te);if(pe.length===0)continue;let o=0,F=0;for(const H of pe)o+=H.x,F+=H.y;o/=pe.length,F/=pe.length;let b=0,xe=0;for(const H of pe){const se=vt(H.degree);b=Math.max(b,Math.abs(H.x-o)+se+35),xe=Math.max(xe,Math.abs(H.y-F)+se+35)}de.push({group:te,cx:o,cy:F,rx:Math.max(b,60),ry:Math.max(xe,60),count:pe.length})}return de},[Z]),O=r.useMemo(()=>{const y=[...new Set(Z.map(ce=>ce.group))].sort(),de={};return y.forEach((ce,te)=>{de[ce]=ns[te%ns.length]}),de},[Z]),re=r.useMemo(()=>{if(Z.length===0)return{x:0,y:0,w:900,h:700};let y=1/0,de=1/0,ce=-1/0,te=-1/0;for(const pe of Z){const o=vt(pe.degree);y=Math.min(y,pe.x-o-80),de=Math.min(de,pe.y-o-40),ce=Math.max(ce,pe.x+o+80),te=Math.max(te,pe.y+o+40)}return{x:y,y:de,w:ce-y,h:te-de}},[Z]),ae=r.useMemo(()=>new Map(Z.map(y=>[y.id,y])),[Z]),{connectedEdgeIds:ye,connectedNodeIds:oe}=r.useMemo(()=>{const y=f||A;if(!y)return{connectedEdgeIds:new Set,connectedNodeIds:new Set};const de=new Set,ce=new Set([y]);for(const te of t)(te.fromId===y||te.toId===y)&&(de.add(te.id),ce.add(te.fromId),ce.add(te.toId));return{connectedEdgeIds:de,connectedNodeIds:ce}},[f,A,t]),Ne=r.useMemo(()=>{const y=new Map,de=new Map;for(const te of t){const pe=[te.fromId,te.toId].sort().join("|"),o=y.get(pe)||0;de.set(te.id,o),y.set(pe,o+1)}const ce=new Map;for(const te of t){const pe=[te.fromId,te.toId].sort().join("|"),o=y.get(pe)||1;if(o<=1){ce.set(te.id,0);continue}const F=de.get(te.id)||0;ce.set(te.id,(F-(o-1)/2)*40)}return ce},[t]),[be,Ce]=r.useState(new Set);r.useEffect(()=>{Ce(new Set(t.map(y=>y.relation)))},[t]);const Ae=r.useMemo(()=>t.filter(y=>be.has(y.relation)),[t,be]),Fe=y=>{Ce(de=>{const ce=new Set(de);return ce.has(y)?ce.delete(y):ce.add(y),ce})},_=r.useCallback(y=>{y.button===0&&(v.current=!0,k.current={x:y.clientX,y:y.clientY})},[]),I=r.useCallback(y=>{if(!v.current)return;const de=y.clientX-k.current.x,ce=y.clientY-k.current.y;k.current={x:y.clientX,y:y.clientY},P(te=>({x:te.x+de,y:te.y+ce}))},[]),le=r.useCallback(()=>{v.current=!1},[]),we=r.useCallback(y=>{y.preventDefault();const de=y.deltaY>0?-.1:.1;C(ce=>Math.min(3,Math.max(.2,ce+de)))},[]),ge=y=>`kg-arrow-${y.replace(/[^a-z_]/g,"")}`;if(g)return e.jsx("div",{className:"flex items-center justify-center h-full",children:e.jsx("div",{className:"animate-spin rounded-full h-8 w-8 border-b-2 border-blue-600"})});if(u)return e.jsxs("div",{className:"flex flex-col items-center justify-center h-full gap-4",children:[e.jsx("p",{className:"text-red-500",children:u}),e.jsx("button",{onClick:ee,className:"px-4 py-2 bg-blue-600 text-white rounded-lg hover:bg-blue-700 transition-colors",children:"重试"})]});if(t.length===0)return e.jsxs("div",{className:"flex flex-col items-center justify-center h-full gap-4 text-slate-500",children:[e.jsx(ys,{size:48,className:"text-slate-300"}),e.jsx("p",{className:"text-lg font-medium",children:"知识图谱为空"}),e.jsx("p",{className:"text-sm text-center max-w-md",children:"当前没有 Recipe 之间的关系数据。点击下方按钮让 AI 自动分析已有 Recipe 之间的潜在关系(requires / extends / enforces / calls 等)。"}),K&&e.jsx("p",{className:`text-sm ${K.startsWith("发现失败")?"text-red-500":"text-green-600"}`,children:K}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("button",{onClick:L,disabled:T,className:"px-4 py-2 bg-violet-600 text-white rounded-lg hover:bg-violet-700 transition-colors flex items-center gap-2 disabled:opacity-50",children:T?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"animate-spin rounded-full h-4 w-4 border-b-2 border-white"})," AI 分析中…"]}):e.jsxs(e.Fragment,{children:[e.jsx(Ke,{size:$.sm})," AI 发现关系"]})}),e.jsxs("button",{onClick:ee,className:"px-4 py-2 bg-blue-600 text-white rounded-lg hover:bg-blue-700 transition-colors flex items-center gap-2",children:[e.jsx(ht,{size:$.sm})," 刷新"]})]})]});const Me=[...new Set(t.map(y=>y.relation))].sort(),Ee=!!(f||A);return e.jsxs("div",{className:"h-full flex flex-col overflow-hidden",children:[e.jsxs("div",{className:"flex items-center justify-between mb-3 flex-shrink-0",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(ys,{size:$.lg,className:"text-blue-600"}),e.jsx("h2",{className:"text-lg font-bold text-slate-800",children:"知识图谱"}),N&&e.jsxs("span",{className:"text-xs text-slate-500 bg-slate-100 px-2 py-1 rounded-full",children:[Z.length," 节点 · ",N.totalEdges," 关系"]})]}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("button",{onClick:()=>C(y=>Math.min(y+.2,3)),className:"p-1.5 rounded-lg bg-slate-100 hover:bg-slate-200 transition-colors",title:"放大",children:e.jsx(tl,{size:$.sm})}),e.jsx("button",{onClick:()=>C(y=>Math.max(y-.2,.2)),className:"p-1.5 rounded-lg bg-slate-100 hover:bg-slate-200 transition-colors",title:"缩小",children:e.jsx(sl,{size:$.sm})}),e.jsx("button",{onClick:()=>{C(1),P({x:0,y:0})},className:"p-1.5 rounded-lg bg-slate-100 hover:bg-slate-200 transition-colors",title:"重置",children:e.jsx(hs,{size:$.sm})}),e.jsx("button",{onClick:ee,className:"p-1.5 rounded-lg bg-slate-100 hover:bg-slate-200 transition-colors",title:"刷新",children:e.jsx(ht,{size:$.sm})}),e.jsx("button",{onClick:L,disabled:T,className:"flex items-center gap-1 px-2.5 py-1 rounded-lg bg-violet-50 hover:bg-violet-100 text-violet-700 text-xs font-medium transition-colors disabled:opacity-50",title:"AI 自动发现 Recipe 关系",children:T?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"animate-spin rounded-full h-3 w-3 border-b-2 border-violet-600"})," 分析中…"]}):e.jsxs(e.Fragment,{children:[e.jsx(Ke,{size:$.sm})," 发现关系"]})})]})]}),e.jsx("div",{className:"flex flex-wrap gap-1.5 mb-3 flex-shrink-0",children:Me.map(y=>{var de;return e.jsxs("button",{onClick:()=>Fe(y),className:`flex items-center gap-1 px-2 py-0.5 rounded-full text-[11px] font-medium transition-all border ${be.has(y)?"border-transparent shadow-sm":"border-slate-200 bg-white text-slate-400 opacity-40"}`,style:be.has(y)?{backgroundColor:(pt[y]||"#6b7280")+"18",color:pt[y]||"#6b7280"}:{},children:[e.jsx("span",{className:"w-2 h-2 rounded-full",style:{backgroundColor:pt[y]||"#6b7280"}}),rs[y]||y,((de=N==null?void 0:N.byRelation)==null?void 0:de[y])!=null&&e.jsxs("span",{className:"opacity-60",children:["(",N.byRelation[y],")"]})]},y)})}),e.jsxs("div",{ref:d,className:"flex-1 rounded-xl border border-slate-200 bg-gradient-to-br from-slate-50 to-white overflow-hidden relative min-h-0",style:{cursor:v.current?"grabbing":"grab"},onWheel:we,children:[e.jsxs("svg",{ref:h,width:"100%",height:"100%",viewBox:`${re.x} ${re.y} ${re.w} ${re.h}`,onMouseDown:_,onMouseMove:I,onMouseUp:le,onMouseLeave:le,style:{transform:`scale(${q}) translate(${m.x/q}px, ${m.y/q}px)`},children:[e.jsxs("defs",{children:[Me.map(y=>e.jsx("marker",{id:ge(y),viewBox:"0 0 10 8",refX:"10",refY:"4",markerWidth:"7",markerHeight:"5",orient:"auto-start-reverse",children:e.jsx("path",{d:"M0,0 L10,4 L0,8 Z",fill:pt[y]||"#6b7280"})},y)),e.jsxs("filter",{id:"kg-glow",x:"-50%",y:"-50%",width:"200%",height:"200%",children:[e.jsx("feGaussianBlur",{in:"SourceAlpha",stdDeviation:"4",result:"blur"}),e.jsx("feFlood",{floodColor:"#3b82f6",floodOpacity:"0.3",result:"color"}),e.jsx("feComposite",{in:"color",in2:"blur",operator:"in",result:"shadow"}),e.jsxs("feMerge",{children:[e.jsx("feMergeNode",{in:"shadow"}),e.jsx("feMergeNode",{in:"SourceGraphic"})]})]})]}),e.jsx("g",{children:fe.map(y=>{const de=O[y.group]||ns[0];return e.jsxs("g",{children:[e.jsx("ellipse",{cx:y.cx,cy:y.cy,rx:y.rx,ry:y.ry,fill:de.bg,stroke:de.border,strokeWidth:1.5,strokeDasharray:"6,4",opacity:.6}),e.jsxs("text",{x:y.cx,y:y.cy-y.ry+14,textAnchor:"middle",fontSize:11,fontWeight:600,fill:de.text,opacity:.8,style:{pointerEvents:"none",userSelect:"none"},children:[y.group||"general"," (",y.count,")"]})]},y.group)})}),e.jsx("g",{children:Ae.map(y=>{const de=ae.get(y.fromId),ce=ae.get(y.toId);if(!de||!ce)return null;const te=Ee?ye.has(y.id):!1,pe=R===y.id,o=Ee?te?.85:.06:pe?.9:.35,F=vt(de.degree),b=vt(ce.degree),xe=Ne.get(y.id)||0,H=Jr(de.x,de.y,ce.x,ce.y,F,b,xe);return e.jsxs("g",{children:[e.jsx("path",{d:H,fill:"none",stroke:"transparent",strokeWidth:12,onMouseEnter:()=>B(y.id),onMouseLeave:()=>B(null),style:{cursor:"pointer"}}),e.jsx("path",{d:H,fill:"none",stroke:pt[y.relation]||"#6b7280",strokeWidth:pe||te?2:1.2,opacity:o,markerEnd:`url(#${ge(y.relation)})`,strokeDasharray:y.relation==="related"?"6,3":void 0,style:{transition:"opacity 0.25s, stroke-width 0.15s",pointerEvents:"none"}}),pe&&(()=>{const se=(de.x+ce.x)/2,D=(de.y+ce.y)/2;return e.jsxs("g",{children:[e.jsx("rect",{x:se-24,y:D-16,width:48,height:18,rx:4,fill:"white",stroke:pt[y.relation]||"#6b7280",strokeWidth:.8,opacity:.95}),e.jsx("text",{x:se,y:D-4,textAnchor:"middle",fontSize:9,fontWeight:600,fill:pt[y.relation]||"#6b7280",children:rs[y.relation]||y.relation})]})})()]},y.id)})}),e.jsx("g",{children:Z.map(y=>{const de=vt(y.degree),ce=f===y.id,te=Ee&&oe.has(y.id),pe=ce||y.id===A,o=Ee&&!te,F=o?.12:1,b=O[y.group]||ns[0],xe=pe?b.border:b.bg,H=pe?b.text:b.border,se=pe?"#ffffff":b.text,D=pe?b.text:"#64748b";return e.jsxs("g",{onClick:J=>{J.stopPropagation(),E(ce?null:y.id)},onMouseEnter:()=>M(y.id),onMouseLeave:()=>M(null),style:{cursor:"pointer",transition:"opacity 0.25s"},opacity:F,filter:pe?"url(#kg-glow)":void 0,children:[e.jsx("circle",{cx:y.x,cy:y.y,r:de,fill:xe,stroke:H,strokeWidth:pe?2.5:1.5}),e.jsx("text",{x:y.x,y:y.y+4,textAnchor:"middle",fontSize:Math.min(Ur,de*.7),fill:se,fontWeight:700,style:{pointerEvents:"none",userSelect:"none"},children:Zs(y.label,4).toUpperCase()}),e.jsx("text",{x:y.x,y:y.y+de+14,textAnchor:"middle",fontSize:Kr,fill:D,fontWeight:pe?600:400,style:{pointerEvents:"none",userSelect:"none"},children:Zs(y.label,18)}),y.degree>=3&&!o&&e.jsxs("g",{children:[e.jsx("circle",{cx:y.x+de*.7,cy:y.y-de*.7,r:8,fill:"#3b82f6",stroke:"white",strokeWidth:1.5}),e.jsx("text",{x:y.x+de*.7,y:y.y-de*.7+3.5,textAnchor:"middle",fontSize:8,fill:"white",fontWeight:700,style:{pointerEvents:"none"},children:y.degree})]})]},y.id)})})]}),f&&e.jsx("button",{className:"absolute top-2 right-2 text-xs text-slate-400 hover:text-slate-600 bg-white/90 px-2 py-1 rounded-md shadow-sm border border-slate-200",onClick:()=>E(null),children:"取消选中"})]}),f&&e.jsxs("div",{className:"mt-3 p-4 bg-white rounded-xl border border-slate-200 shadow-sm flex-shrink-0 max-h-48 overflow-y-auto scrollbar-light",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-3 pb-2 border-b border-slate-100",children:[e.jsx(al,{size:14,className:"text-blue-500"}),e.jsx("h3",{className:"font-semibold text-sm text-slate-800",children:a[f]||f}),e.jsxs("span",{className:"text-[10px] text-slate-400 ml-auto",children:["ID: ",f]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4 text-xs",children:[e.jsxs("div",{children:[e.jsx("span",{className:"text-slate-500 font-medium",children:"出边(依赖)"}),e.jsxs("ul",{className:"mt-1.5 space-y-1",children:[t.filter(y=>y.fromId===f&&be.has(y.relation)).map(y=>e.jsxs("li",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"w-1.5 h-1.5 rounded-full flex-shrink-0",style:{backgroundColor:pt[y.relation]||"#6b7280"}}),e.jsx("span",{className:"text-slate-500",children:rs[y.relation]||y.relation}),e.jsx("span",{className:"text-slate-400",children:"→"}),e.jsx("button",{className:"text-blue-600 hover:underline truncate",onClick:()=>E(y.toId),children:a[y.toId]||y.toId.substring(0,16)})]},y.id)),t.filter(y=>y.fromId===f&&be.has(y.relation)).length===0&&e.jsx("li",{className:"text-slate-400",children:"无"})]})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-slate-500 font-medium",children:"入边(被依赖)"}),e.jsxs("ul",{className:"mt-1.5 space-y-1",children:[t.filter(y=>y.toId===f&&be.has(y.relation)).map(y=>e.jsxs("li",{className:"flex items-center gap-1.5",children:[e.jsx("button",{className:"text-blue-600 hover:underline truncate",onClick:()=>E(y.fromId),children:a[y.fromId]||y.fromId.substring(0,16)}),e.jsx("span",{className:"text-slate-400",children:"→"}),e.jsx("span",{className:"text-slate-500",children:rs[y.relation]||y.relation}),e.jsx("span",{className:"w-1.5 h-1.5 rounded-full flex-shrink-0",style:{backgroundColor:pt[y.relation]||"#6b7280"}})]},y.id)),t.filter(y=>y.toId===f&&be.has(y.relation)).length===0&&e.jsx("li",{className:"text-slate-400",children:"无"})]})]})]})]})]})},dt={pending:{label:"待审核",color:"text-amber-700",bg:"bg-amber-50",border:"border-amber-200",icon:it},active:{label:"已发布",color:"text-green-700",bg:"bg-green-50",border:"border-green-200",icon:es},deprecated:{label:"已废弃",color:"text-orange-600",bg:"bg-orange-50",border:"border-orange-200",icon:ks}},Pt={rule:{label:"Rule",color:"text-red-700",bg:"bg-red-50",border:"border-red-200",icon:nt},pattern:{label:"Pattern",color:"text-violet-700",bg:"bg-violet-50",border:"border-violet-200",icon:bt},fact:{label:"Fact",color:"text-cyan-700",bg:"bg-cyan-50",border:"border-cyan-200",icon:Je}},Zr={pending:[{action:"publish",label:"发布",color:"text-green-700",bg:"bg-green-50 hover:bg-green-100",icon:es},{action:"deprecate",label:"废弃",color:"text-orange-700",bg:"bg-orange-50 hover:bg-orange-100",icon:ks,needsReason:!0}],active:[{action:"deprecate",label:"废弃",color:"text-orange-700",bg:"bg-orange-50 hover:bg-orange-100",icon:ks,needsReason:!0}],deprecated:[{action:"reactivate",label:"重新激活",color:"text-green-700",bg:"bg-green-50 hover:bg-green-100",icon:oa}]};function Ft(t){if(!t)return"";const s=t<1e12?t*1e3:t,a=new Date(s);if(isNaN(a.getTime())||a.getFullYear()<2e3)return"";const n=Date.now()-s;if(n<0)return a.toLocaleDateString("zh-CN");const c=Math.floor(n/6e4);if(c<1)return"刚刚";if(c<60)return`${c} 分钟前`;const x=Math.floor(c/60);if(x<24)return`${x} 小时前`;const i=Math.floor(x/24);return i<7?`${i} 天前`:a.toLocaleDateString("zh-CN")}function Qr(t){return t==null?{ring:"stroke-slate-200",text:"text-slate-400",bg:"bg-slate-50",label:"—"}:t>=.8?{ring:"stroke-emerald-500",text:"text-emerald-700",bg:"bg-emerald-50",label:"高"}:t>=.6?{ring:"stroke-blue-500",text:"text-blue-700",bg:"bg-blue-50",label:"中"}:t>=.4?{ring:"stroke-amber-500",text:"text-amber-700",bg:"bg-amber-50",label:"中低"}:{ring:"stroke-red-500",text:"text-red-700",bg:"bg-red-50",label:"低"}}function en(t,s=4){return t?Ms(t).split(`
|
|
89
|
+
`).slice(0,s).join(`
|
|
90
|
+
`):""}const Qs={"bootstrap-scan":{label:"AI 全量扫描",color:"text-violet-600 bg-violet-50 border-violet-200"},mcp:{label:"MCP 提交",color:"text-blue-600 bg-blue-50 border-blue-200"},manual:{label:"手动创建",color:"text-emerald-600 bg-emerald-50 border-emerald-200"},"file-watcher":{label:"文件监听",color:"text-orange-600 bg-orange-50 border-orange-200"},clipboard:{label:"剪贴板",color:"text-pink-600 bg-pink-50 border-pink-200"},cli:{label:"CLI",color:"text-slate-600 bg-slate-50 border-slate-200"},agent:{label:"AI Agent",color:"text-violet-600 bg-violet-50 border-violet-200"},submit_with_check:{label:"AI 审查提交",color:"text-teal-600 bg-teal-50 border-teal-200"}},tn=({onRefresh:t,idTitleMap:s})=>{const[a,l]=r.useState([]),[n,c]=r.useState(null),[x,i]=r.useState(!0),[N,j]=r.useState(1),[g,p]=r.useState(20),[u,w]=r.useState(0),[f,E]=r.useState(""),[A,M]=r.useState(""),[R,B]=r.useState(""),[T,U]=r.useState(""),[K,S]=r.useState(""),{isWide:q,toggle:C}=Ls(),[m,P]=r.useState(null),[h,d]=r.useState(!1),[v,k]=r.useState(new Set),[ee,L]=r.useState(!1),Z=r.useRef(!0);r.useEffect(()=>(Z.current=!0,()=>{Z.current=!1}),[]);const fe=r.useCallback(async()=>{var _;i(!0);try{const I=await Y.knowledgeList({page:N,limit:g,lifecycle:f||void 0,kind:A||void 0,category:R||void 0,keyword:T||void 0});Z.current&&(l(I.data||[]),w(((_=I.pagination)==null?void 0:_.total)||0))}catch(I){V((I==null?void 0:I.message)||"加载知识条目失败",{title:"加载失败",type:"error"})}finally{Z.current&&i(!1)}},[N,g,f,A,R,T]),O=r.useCallback(async()=>{try{const _=await Y.knowledgeStats();Z.current&&c(_)}catch{}},[]);r.useEffect(()=>{fe()},[fe]),r.useEffect(()=>{O()},[O]),r.useEffect(()=>{const _=setTimeout(()=>{U(K),j(1)},300);return()=>clearTimeout(_)},[K]),r.useEffect(()=>{j(1)},[f,A,R]);const re=r.useCallback(()=>{fe(),O(),t==null||t()},[fe,O,t]),ae=r.useMemo(()=>{const _=new Map;if(s)for(const[I,le]of Object.entries(s))_.set(I,le);for(const I of a)I.id&&I.title&&_.set(I.id,I.title);return _},[a,s]),ye=async(_,I,le)=>{var we,ge,Me,Oe;d(!0);try{const Ee=await Y.knowledgeLifecycle(_.id,I,le);V(`${_.title} → ${((we=dt[Ee.lifecycle])==null?void 0:we.label)||Ee.lifecycle}`,{title:"操作成功"}),l(y=>y.map(de=>de.id===_.id?Ee:de)),(m==null?void 0:m.id)===_.id&&P(Ee),O()}catch(Ee){V(((Oe=(Me=(ge=Ee==null?void 0:Ee.response)==null?void 0:ge.data)==null?void 0:Me.error)==null?void 0:Oe.message)||(Ee==null?void 0:Ee.message)||"操作失败",{title:"操作失败",type:"error"})}finally{Z.current&&d(!1)}},oe=async _=>{if(confirm(`确定删除「${_.title}」?此操作不可恢复。`))try{await Y.knowledgeDelete(_.id),V(`已删除「${_.title}」`,{title:"删除成功"}),l(I=>I.filter(le=>le.id!==_.id)),(m==null?void 0:m.id)===_.id&&P(null),O()}catch(I){V((I==null?void 0:I.message)||"删除失败",{title:"删除失败",type:"error"})}},Ne=async()=>{if(v.size!==0){L(!0);try{const _=await Y.knowledgeBatchPublish([...v]);V(`发布 ${_.successCount} 条,失败 ${_.failureCount} 条`,{title:"批量发布"}),k(new Set),re()}catch(_){V((_==null?void 0:_.message)||"批量发布失败",{title:"操作失败",type:"error"})}finally{L(!1)}}},be=async()=>{L(!0);try{const I=((await Y.knowledgeList({lifecycle:"pending",limit:500})).data||[]).filter(we=>we.autoApprovable).map(we=>we.id);if(I.length===0){V("当前没有可自动通过的待审核条目",{title:"无可发布项"});return}const le=await Y.knowledgeBatchPublish(I);V(`已发布 ${le.successCount} 条可自动通过的条目`,{title:"批量发布完成"}),re()}catch(_){V((_==null?void 0:_.message)||"批量发布失败",{title:"操作失败",type:"error"})}finally{L(!1)}},Ce=_=>{k(I=>{const le=new Set(I);return le.has(_)?le.delete(_):le.add(_),le})},Ae=()=>{v.size===a.length?k(new Set):k(new Set(a.map(_=>_.id)))},Fe=(_,I)=>{const le=prompt("请输入废弃原因:");le&&ye(_,I,le)};return e.jsxs("div",{className:"space-y-4",children:[n&&e.jsx("div",{className:"grid grid-cols-3 gap-3",children:Object.entries(dt).map(([_,I])=>{const le=n[_]||0,we=I.icon;return e.jsxs("button",{onClick:()=>{E(f===_?"":_)},className:`flex items-center gap-2 px-3 py-2 rounded-lg border transition-all text-left ${f===_?`${I.bg} ${I.border} ${I.color} ring-1 ring-current`:"bg-white border-slate-200 text-slate-600 hover:bg-slate-50"}`,children:[e.jsx(we,{size:14}),e.jsxs("div",{children:[e.jsx("div",{className:"text-xs font-medium",children:I.label}),e.jsx("div",{className:"text-lg font-bold",children:le})]})]},_)})}),e.jsxs("div",{className:"flex flex-wrap items-center gap-3",children:[e.jsxs("div",{className:"relative flex-1 min-w-[200px] max-w-md",children:[e.jsx(xt,{className:"absolute left-3 top-1/2 -translate-y-1/2 text-slate-400",size:16}),e.jsx("input",{type:"text",placeholder:"搜索知识条目...",value:K,onChange:_=>S(_.target.value),className:"w-full pl-9 pr-3 py-2 rounded-lg border border-slate-200 text-sm focus:outline-none focus:ring-2 focus:ring-blue-300"})]}),e.jsx("div",{className:"flex gap-1",children:Object.entries(Pt).map(([_,I])=>{const le=I.icon;return e.jsxs("button",{onClick:()=>M(A===_?"":_),className:`flex items-center gap-1 px-2.5 py-1.5 rounded-md text-xs font-medium border transition-all ${A===_?`${I.bg} ${I.border} ${I.color}`:"bg-white border-slate-200 text-slate-500 hover:bg-slate-50"}`,children:[e.jsx(le,{size:12}),I.label]},_)})}),e.jsxs("select",{value:R,onChange:_=>B(_.target.value),className:"px-2.5 py-1.5 rounded-md text-xs border border-slate-200 bg-white text-slate-600 focus:outline-none",children:[e.jsx("option",{value:"",children:"所有分类"}),["View","Service","Tool","Model","Network","Storage","UI","Utility"].map(_=>e.jsx("option",{value:_,children:_},_))]}),e.jsx("button",{onClick:re,className:"p-2 rounded-md text-slate-400 hover:bg-slate-100",title:"刷新",children:e.jsx(ht,{size:16})}),v.size>0&&e.jsxs("div",{className:"flex items-center gap-2 ml-auto",children:[e.jsxs("span",{className:"text-xs text-slate-500",children:["已选 ",v.size," 条"]}),e.jsx("button",{onClick:Ne,disabled:ee,className:"px-2.5 py-1 text-xs font-medium text-green-700 bg-green-50 border border-green-200 rounded-md hover:bg-green-100 disabled:opacity-50",children:ee?e.jsx(Te,{size:12,className:"animate-spin"}):"批量发布"}),e.jsx("button",{onClick:()=>k(new Set),className:"p-1 text-slate-400 hover:text-slate-600",children:e.jsx(Ye,{size:14})})]}),v.size===0&&e.jsxs("button",{onClick:be,disabled:ee,className:"ml-auto px-3 py-1.5 text-xs font-medium text-cyan-700 bg-cyan-50 border border-cyan-200 rounded-md hover:bg-cyan-100 disabled:opacity-50 flex items-center gap-1.5",children:[ee?e.jsx(Te,{size:12,className:"animate-spin"}):e.jsx(Qe,{size:12}),"快速批量发布"]})]}),x?e.jsxs("div",{className:"flex items-center justify-center py-20 text-slate-400",children:[e.jsx(Te,{size:24,className:"animate-spin mr-2"}),e.jsx("span",{children:"加载中..."})]}):a.length===0?e.jsxs("div",{className:"flex flex-col items-center justify-center py-20 text-slate-400",children:[e.jsx(Je,{size:48,className:"mb-4 opacity-30"}),e.jsx("p",{className:"text-sm",children:"暂无知识条目"}),(T||f||A||R)&&e.jsx("button",{onClick:()=>{S(""),E(""),M(""),B("")},className:"mt-2 text-xs text-blue-500 hover:text-blue-700",children:"清除筛选条件"})]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center gap-2 px-1",children:[e.jsx("input",{type:"checkbox",checked:v.size===a.length&&a.length>0,onChange:Ae,className:"rounded border-slate-300"}),e.jsx("span",{className:"text-xs text-slate-400",children:"全选"}),e.jsxs("span",{className:"text-xs text-slate-400 ml-auto",children:["共 ",u," 条"]})]}),e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:a.map(_=>{var Oe,Ee,y,de,ce,te;const I=dt[_.lifecycle]||dt.pending,le=Pt[_.kind]||Pt.pattern,we=I.icon,ge=le.icon,Me=Qr((Oe=_.reasoning)==null?void 0:Oe.confidence);return e.jsxs("div",{onClick:()=>P(_),className:`group bg-white rounded-xl border shadow-sm hover:shadow-md cursor-pointer transition-all overflow-hidden ${(m==null?void 0:m.id)===_.id?"ring-2 ring-blue-300 border-blue-200":"border-slate-200"}`,children:[e.jsxs("div",{className:"px-4 pt-3 pb-2",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1.5",children:[e.jsx("input",{type:"checkbox",checked:v.has(_.id),onChange:pe=>{pe.stopPropagation(),Ce(_.id)},onClick:pe=>pe.stopPropagation(),className:"rounded border-slate-300"}),e.jsxs("span",{className:`inline-flex items-center gap-1 px-1.5 py-0.5 rounded text-[10px] font-medium ${I.bg} ${I.color} ${I.border} border`,children:[e.jsx(we,{size:10}),I.label]}),e.jsxs("span",{className:`inline-flex items-center gap-1 px-1.5 py-0.5 rounded text-[10px] font-medium ${le.bg} ${le.color} ${le.border} border`,children:[e.jsx(ge,{size:10}),le.label]}),_.category&&e.jsx("span",{className:"text-[10px] text-slate-400",children:_.category}),e.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded ${Me.bg} ${Me.text}`,children:((Ee=_.reasoning)==null?void 0:Ee.confidence)!=null?`${Math.round(_.reasoning.confidence*100)}%`:"—"}),_.autoApprovable&&_.lifecycle==="pending"&&e.jsxs("span",{className:"inline-flex items-center gap-0.5 text-[10px] px-1.5 py-0.5 rounded bg-cyan-50 text-cyan-600 border border-cyan-200",children:[e.jsx(Qe,{size:9}),"可自动通过"]})]}),e.jsx("h3",{className:"text-sm font-bold text-slate-900 mb-1 break-words leading-snug",children:_.title}),(_.description||((y=_.content)==null?void 0:y.rationale))&&e.jsx("p",{className:"text-xs text-slate-500 line-clamp-2 leading-relaxed",children:_.description||((de=_.content)==null?void 0:de.rationale)||""}),((ce=_.content)==null?void 0:ce.pattern)&&e.jsx("pre",{className:"mt-1.5 text-[10px] text-slate-500 bg-slate-50 rounded p-1.5 line-clamp-3 font-mono overflow-hidden",children:en(_.content.pattern,3)})]}),e.jsxs("div",{className:"px-4 py-2 bg-slate-50/80 border-t border-slate-100 flex items-center gap-2",children:[(te=_.tags)==null?void 0:te.slice(0,3).map(pe=>e.jsx("span",{className:"text-[10px] px-1.5 py-0.5 rounded bg-blue-50 text-blue-600 border border-blue-100",children:pe},pe)),_.tags&&_.tags.length>3&&e.jsxs("span",{className:"text-[10px] text-slate-400",children:["+",_.tags.length-3]}),e.jsxs("span",{className:"text-[10px] text-slate-300 ml-auto",children:[_.trigger&&e.jsx("span",{className:"text-blue-400 mr-2",children:_.trigger}),_.source&&e.jsx("span",{className:"mr-2",children:_.source}),Ft(_.updatedAt)]})]})]},_.id)})}),e.jsx(Rs,{currentPage:N,totalPages:Math.ceil(u/g),onPageChange:j,pageSize:g,onPageSizeChange:_=>{p(_),j(1)},totalItems:u})]}),m&&(()=>{var te,pe,o,F,b,xe,H,se;const _=dt[m.lifecycle]||dt.pending,I=_.icon,le=Pt[m.kind]||Pt.pattern,we=lt[m.category||""]||lt.All||{};Qs[m.source||""]||m.source;const ge=m.reasoning,Me=ge&&(ge.whyStandard||ge.sources&&ge.sources.length>0||ge.confidence!=null),Oe=a.findIndex(D=>D.id===m.id),Ee=Oe>0,y=Oe<a.length-1,de=()=>{Ee&&P(a[Oe-1])},ce=()=>{y&&P(a[Oe+1])};return e.jsxs(Ve,{className:"z-30 flex justify-end",onClick:()=>P(null),children:[e.jsx(Ve.Backdrop,{className:"bg-black/15 backdrop-blur-[1px]"}),e.jsxs("div",{className:`relative h-full bg-white shadow-2xl flex flex-col border-l border-slate-200 ${q?"w-[960px] max-w-[92vw]":"w-[700px] max-w-[92vw]"}`,style:{animation:"slideInRight 0.25s ease-out"},onClick:D=>D.stopPropagation(),children:[e.jsxs("div",{className:"flex items-center justify-between px-5 py-3 border-b border-slate-200 bg-gradient-to-b from-white to-slate-50/50 shrink-0",children:[e.jsx("div",{className:"flex-1 min-w-0 mr-3",children:e.jsx("h3",{className:"font-bold text-slate-800 text-lg leading-snug break-words",children:m.title})}),e.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[e.jsx("button",{onClick:de,disabled:!Ee,className:"p-1.5 hover:bg-slate-100 rounded-lg transition-colors disabled:opacity-30",title:"上一条",children:e.jsx(Zt,{size:$.md})}),e.jsxs("span",{className:"text-xs text-slate-400 tabular-nums",children:[Oe+1,"/",a.length]}),e.jsx("button",{onClick:ce,disabled:!y,className:"p-1.5 hover:bg-slate-100 rounded-lg transition-colors disabled:opacity-30",title:"下一条",children:e.jsx(at,{size:$.md})}),e.jsx("div",{className:"w-px h-5 bg-slate-200 mx-1"}),e.jsx("button",{onClick:C,className:"p-1.5 hover:bg-slate-100 rounded-lg transition-colors text-slate-400",title:q?"收窄":"展宽",children:q?e.jsx(Is,{size:$.md}):e.jsx(hs,{size:$.md})}),e.jsx("button",{onClick:()=>{oe(m),P(null)},className:"p-1.5 hover:bg-red-50 rounded-lg text-red-500 transition-colors",title:"删除",children:e.jsx(st,{size:$.md})}),e.jsx("button",{onClick:()=>P(null),className:"p-1.5 hover:bg-slate-100 rounded-lg transition-colors",children:e.jsx(Ye,{size:$.md})})]})]}),e.jsxs("div",{className:"flex-1 overflow-y-auto",children:[m.rejectionReason&&e.jsxs("div",{className:"px-6 py-3 border-b border-red-200 bg-red-50/80",children:[e.jsx("label",{className:"text-[10px] font-bold text-red-500 uppercase mb-1.5 block",children:"驳回原因"}),e.jsx("p",{className:"text-xs text-red-600",children:m.rejectionReason})]}),e.jsxs("div",{className:"px-6 py-4 border-b border-slate-100 space-y-3",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-1.5",children:[e.jsxs("span",{className:`inline-flex items-center gap-1 px-1.5 py-0.5 rounded text-[10px] font-medium ${_.bg} ${_.color} ${_.border} border`,children:[e.jsx(I,{size:10}),_.label]}),e.jsxs("span",{className:`inline-flex items-center gap-1 px-1.5 py-0.5 rounded text-[10px] font-medium ${le.bg} ${le.color} ${le.border} border`,children:[It.createElement(le.icon,{size:10}),le.label]}),e.jsx("span",{className:`text-[10px] font-bold px-1.5 py-0.5 rounded uppercase flex items-center gap-1 border ${(we==null?void 0:we.bg)||"bg-slate-50"} ${(we==null?void 0:we.color)||"text-slate-400"} ${(we==null?void 0:we.border)||"border-slate-100"}`,children:m.category||"general"}),m.knowledgeType&&e.jsx("span",{className:"text-[10px] font-medium px-1.5 py-0.5 rounded bg-purple-50 text-purple-700 border border-purple-200",children:m.knowledgeType}),m.language&&e.jsx("span",{className:"text-[10px] uppercase font-bold text-slate-500 bg-slate-50 border border-slate-200 px-1.5 py-0.5 rounded",children:m.language}),m.trigger&&e.jsx("span",{className:"text-[10px] font-mono px-1.5 py-0.5 rounded bg-amber-50 text-amber-700 border border-amber-200 font-bold",children:m.trigger})]}),e.jsxs("div",{className:"flex flex-wrap gap-x-5 gap-y-2 text-xs",children:[(()=>{const D=[];return m.scope&&D.push({icon:kt,iconClass:"text-teal-400",label:"范围",value:m.scope==="universal"?"通用":m.scope==="project-specific"?"项目级":m.scope==="module-level"?"模块级":m.scope}),m.complexity&&D.push({icon:et,iconClass:"text-orange-400",label:"复杂度",value:m.complexity==="advanced"?"高级":m.complexity==="intermediate"?"中级":m.complexity==="beginner"?"初级":m.complexity}),m.source&&m.source!=="unknown"&&D.push({icon:kt,iconClass:"text-violet-400",label:"来源",value:(Qs[m.source||""]||{label:m.source||"-"}).label}),m.createdAt&&D.push({icon:it,iconClass:"text-slate-400",label:"创建",value:Ft(m.createdAt)}),m.updatedAt&&D.push({icon:it,iconClass:"text-slate-400",label:"更新",value:Ft(m.updatedAt)}),m.publishedAt&&D.push({icon:es,iconClass:"text-emerald-400",label:"发布",value:Ft(m.publishedAt)}),D.map((J,me)=>{const W=J.icon;return e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(W,{size:11,className:`${J.iconClass} shrink-0`}),e.jsx("span",{className:"text-slate-400",children:J.label}),e.jsx("span",{className:`font-medium text-slate-600 ${J.mono?"font-mono text-[11px]":""}`,children:J.value})]},me)})})(),e.jsxs("div",{className:"flex items-center gap-1.5 basis-full mt-0.5",children:[e.jsx(Wt,{size:11,className:"text-slate-300 shrink-0"}),e.jsx("span",{className:"text-slate-400",children:"ID"}),e.jsx("code",{className:"font-mono text-[11px] text-slate-500 break-all",children:m.id})]}),m.sourceFile&&e.jsxs("div",{className:"flex items-center gap-1.5 basis-full",children:[e.jsx(Tt,{size:11,className:"text-slate-300 shrink-0"}),e.jsx("span",{className:"text-slate-400",children:"源文件"}),e.jsx("code",{className:"font-mono text-[11px] text-slate-500 break-all",children:m.sourceFile})]})]})]}),m.tags&&m.tags.length>0&&e.jsxs("div",{className:"px-6 py-3 border-b border-slate-100 flex flex-wrap items-center gap-1.5",children:[e.jsx(Ut,{size:11,className:"text-slate-300 mr-0.5"}),m.tags.map((D,J)=>e.jsx("span",{className:"text-[9px] px-2 py-0.5 rounded bg-blue-50 text-blue-600 border border-blue-100 font-medium",children:D},J))]}),m.relations&&Object.entries(m.relations).some(([,D])=>Array.isArray(D)&&D.length>0)&&e.jsxs("div",{className:"px-6 py-4 border-b border-slate-100",children:[e.jsxs("div",{className:"flex items-center gap-1.5 mb-2",children:[e.jsx(zs,{size:12,className:"text-purple-400"}),e.jsx("label",{className:"text-[10px] font-bold text-slate-400 uppercase",children:"关联知识"}),(()=>{const D=Object.values(m.relations).flat().length;return D>0?e.jsx("span",{className:"text-[9px] bg-purple-100 text-purple-600 px-1.5 py-0.5 rounded-full font-bold",children:D}):null})()]}),e.jsx("div",{className:"space-y-1.5",children:Object.entries(m.relations).map(([D,J])=>!Array.isArray(J)||J.length===0?null:e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsx("span",{className:"text-[10px] font-mono text-slate-500 w-14 shrink-0 pt-0.5 uppercase",children:D}),e.jsx("div",{className:"flex flex-wrap gap-1",children:J.map((me,W)=>{const ue=me.target||(typeof me=="string"?me:JSON.stringify(me)),De=ae.get(ue)||ue;return e.jsx("span",{className:"inline-flex items-center gap-1 px-1.5 py-0.5 border rounded text-[10px] font-mono bg-purple-50 border-purple-200 text-purple-700",title:ue,children:De},W)})})]},D))})]}),m.stats&&Object.values(m.stats).some(D=>D>0)&&e.jsxs("div",{className:"px-6 py-3 border-b border-slate-100",children:[e.jsxs("div",{className:"grid grid-cols-2 sm:grid-cols-4 gap-3",children:[e.jsxs("div",{className:"bg-amber-50/60 rounded-xl p-3 text-center border border-amber-100",children:[e.jsx("div",{className:"text-lg font-bold text-amber-700",children:((te=m.stats)==null?void 0:te.authority)??"—"}),e.jsx("div",{className:"text-[10px] text-amber-500 font-medium",children:"权威分"})]}),e.jsxs("div",{className:"bg-slate-50 rounded-xl p-3 text-center border border-slate-100",children:[e.jsx("div",{className:"text-lg font-bold text-slate-800",children:((pe=m.stats)==null?void 0:pe.guardHits)??0}),e.jsx("div",{className:"text-[10px] text-slate-400 font-medium",children:"Guard"})]}),e.jsxs("div",{className:"bg-slate-50 rounded-xl p-3 text-center border border-slate-100",children:[e.jsx("div",{className:"text-lg font-bold text-slate-800",children:((o=m.stats)==null?void 0:o.adoptions)??0}),e.jsx("div",{className:"text-[10px] text-slate-400 font-medium",children:"采纳"})]}),e.jsxs("div",{className:"bg-blue-50/60 rounded-xl p-3 text-center border border-blue-100",children:[e.jsx("div",{className:"text-lg font-bold text-blue-700",children:((F=m.stats)==null?void 0:F.searchHits)??0}),e.jsx("div",{className:"text-[10px] text-blue-500 font-medium",children:"搜索"})]})]}),(m.stats.views>0||m.stats.applications>0)&&e.jsxs("div",{className:"flex items-center gap-4 mt-2 text-[10px] text-slate-400",children:[e.jsxs("span",{children:["浏览: ",m.stats.views]}),e.jsxs("span",{children:["应用: ",m.stats.applications]})]})]}),Me&&e.jsxs("div",{className:"px-6 py-4 border-b border-slate-100",children:[e.jsxs("label",{className:"text-[10px] font-bold text-slate-400 uppercase mb-2 block flex items-center gap-1.5",children:[e.jsx(bt,{size:11,className:"text-amber-400"})," 推理依据"]}),e.jsxs("div",{className:"bg-amber-50/30 border border-amber-100 rounded-xl p-4 space-y-2.5",children:[ge.whyStandard&&!/^Submitted via /i.test(ge.whyStandard)&&e.jsx("p",{className:"text-sm text-slate-700 leading-relaxed",children:ge.whyStandard}),ge.sources&&ge.sources.length>0&&e.jsxs("div",{className:"flex flex-wrap items-center gap-1.5",children:[e.jsx("span",{className:"text-[10px] text-slate-400 font-bold",children:"来源:"}),ge.sources.map((D,J)=>e.jsx("code",{className:"text-[10px] px-2 py-0.5 bg-white border border-amber-200 rounded text-amber-700 font-mono",children:D},J))]}),ge.confidence!=null&&ge.confidence>0&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-[10px] text-slate-400 font-bold",children:"置信度:"}),e.jsx("div",{className:"flex-1 max-w-[160px] h-1.5 bg-slate-200 rounded-full overflow-hidden",children:e.jsx("div",{className:"h-full bg-amber-400 rounded-full",style:{width:`${Math.round((ge.confidence??0)*100)}%`}})}),e.jsxs("span",{className:"text-[10px] font-bold text-amber-600",children:[Math.round((ge.confidence??0)*100),"%"]})]}),ge.alternatives&&ge.alternatives.length>0&&e.jsxs("div",{className:"flex flex-wrap items-center gap-1.5 pt-1",children:[e.jsx("span",{className:"text-[10px] text-slate-400 font-bold",children:"备选:"}),ge.alternatives.map((D,J)=>e.jsx("span",{className:"text-[10px] px-1.5 py-0.5 bg-slate-100 border border-slate-200 rounded text-slate-600",children:D},J))]})]})]}),m.quality&&m.quality.grade&&m.quality.grade!=="F"&&e.jsxs("div",{className:"px-6 py-3 border-b border-slate-100",children:[e.jsx("label",{className:"text-[10px] font-bold text-slate-400 uppercase mb-2 block",children:"质量评级"}),e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx("span",{className:`text-2xl font-black ${m.quality.grade==="A"?"text-emerald-600":m.quality.grade==="B"?"text-blue-600":m.quality.grade==="C"?"text-amber-600":m.quality.grade==="D"?"text-orange-600":"text-slate-400"}`,children:m.quality.grade}),e.jsxs("div",{className:"flex-1 grid grid-cols-3 gap-2 text-[10px]",children:[m.quality.completeness!=null&&m.quality.completeness>0&&e.jsxs("div",{className:"text-center",children:[e.jsx("div",{className:"font-bold text-slate-700",children:m.quality.completeness.toFixed(2)}),e.jsx("div",{className:"text-slate-400",children:"完整性"})]}),m.quality.adaptation!=null&&m.quality.adaptation>0&&e.jsxs("div",{className:"text-center",children:[e.jsx("div",{className:"font-bold text-slate-700",children:m.quality.adaptation.toFixed(2)}),e.jsx("div",{className:"text-slate-400",children:"适配度"})]}),m.quality.documentation!=null&&m.quality.documentation>0&&e.jsxs("div",{className:"text-center",children:[e.jsx("div",{className:"font-bold text-slate-700",children:m.quality.documentation.toFixed(2)}),e.jsx("div",{className:"text-slate-400",children:"文档度"})]})]})]})]}),m.description&&e.jsxs("div",{className:"px-6 py-4 border-b border-slate-100",children:[e.jsx("label",{className:"text-[10px] font-bold text-slate-400 uppercase mb-1.5 block",children:"摘要"}),e.jsx("p",{className:"text-sm text-slate-600 leading-relaxed",children:m.description})]}),((b=m.content)==null?void 0:b.markdown)&&e.jsxs("div",{className:"px-6 py-4 border-b border-slate-100",children:[e.jsxs("label",{className:"text-[10px] font-bold text-slate-400 uppercase mb-2 block flex items-center gap-1.5",children:[e.jsx(tt,{size:11,className:"text-blue-400"})," Markdown 文档"]}),e.jsx("div",{className:"bg-blue-50/30 border border-blue-100 rounded-xl p-4",children:e.jsx("div",{className:"markdown-body text-sm text-slate-700 leading-relaxed",children:e.jsx(ut,{content:m.content.markdown})})})]}),m.headers&&m.headers.length>0&&e.jsxs("div",{className:"px-6 py-3 border-b border-slate-100",children:[e.jsx("label",{className:"text-[10px] font-bold text-slate-400 uppercase mb-2 block",children:"导入头文件"}),e.jsx("div",{className:"flex flex-wrap gap-1.5",children:m.headers.map((D,J)=>e.jsx("code",{className:"px-2.5 py-1 bg-violet-50 text-violet-700 border border-violet-100 rounded-md text-[10px] font-mono font-medium",children:D},J))})]}),((xe=m.content)==null?void 0:xe.pattern)&&e.jsxs("div",{className:"px-6 py-4 border-b border-slate-100",children:[e.jsxs("label",{className:"text-[10px] font-bold text-slate-400 uppercase mb-2 block flex items-center gap-1.5",children:[e.jsx(mt,{size:11,className:"text-emerald-500"})," 代码 / 标准用法"]}),e.jsx(rt,{code:m.content.pattern,language:m.language==="objc"?"objectivec":m.language,showLineNumbers:!0})]}),(m.doClause||m.whenClause||m.dontClause||m.topicHint||m.coreCode)&&e.jsxs("div",{className:"px-6 py-4 border-b border-slate-100",children:[e.jsxs("label",{className:"text-[10px] font-bold text-slate-400 uppercase mb-2 block flex items-center gap-1.5",children:[e.jsx(et,{size:11,className:"text-indigo-400"})," Cursor Delivery"]}),e.jsxs("div",{className:"bg-indigo-50/30 border border-indigo-100 rounded-xl p-4 space-y-1.5 text-xs",children:[m.topicHint&&e.jsxs("div",{children:[e.jsx("span",{className:"text-indigo-500 font-medium",children:"Topic:"}),e.jsx("span",{className:"text-slate-700",children:m.topicHint})]}),m.whenClause&&e.jsxs("div",{children:[e.jsx("span",{className:"text-blue-500 font-medium",children:"When:"}),e.jsx("span",{className:"text-slate-700",children:m.whenClause})]}),m.doClause&&e.jsxs("div",{children:[e.jsx("span",{className:"text-emerald-500 font-medium",children:"Do:"}),e.jsx("span",{className:"text-slate-700",children:m.doClause})]}),m.dontClause&&e.jsxs("div",{children:[e.jsx("span",{className:"text-red-500 font-medium",children:"Don't:"}),e.jsx("span",{className:"text-slate-700",children:m.dontClause})]}),m.coreCode&&e.jsxs("div",{children:[e.jsx("span",{className:"text-purple-500 font-medium",children:"Core Code:"}),e.jsx("div",{className:"mt-1",children:e.jsx(rt,{code:m.coreCode,language:m.language==="objc"?"objectivec":m.language||"text"})})]})]})]}),((H=m.content)==null?void 0:H.rationale)&&e.jsxs("div",{className:"px-6 py-4 border-b border-slate-100",children:[e.jsx("label",{className:"text-[10px] font-bold text-slate-400 uppercase mb-2 block",children:"设计原理"}),e.jsx("div",{className:"bg-slate-50 border border-slate-100 rounded-xl p-4",children:e.jsx("p",{className:"text-sm text-slate-600 leading-relaxed",children:m.content.rationale})})]}),((se=m.content)==null?void 0:se.steps)&&m.content.steps.length>0&&e.jsxs("div",{className:"px-6 py-4 border-b border-slate-100",children:[e.jsx("label",{className:"text-[10px] font-bold text-slate-400 uppercase mb-2 block",children:"实施步骤"}),e.jsx("div",{className:"space-y-2",children:m.content.steps.map((D,J)=>{if(typeof D=="string")return e.jsxs("div",{className:"bg-slate-50 rounded-lg p-3 border border-slate-100 flex items-start gap-2.5",children:[e.jsx("span",{className:"text-[10px] font-bold text-blue-600 bg-blue-50 rounded-full w-5 h-5 flex items-center justify-center shrink-0 mt-0.5",children:J+1}),e.jsx("p",{className:"text-xs text-slate-700 leading-relaxed",children:D})]},J);const me=typeof D.title=="string"?D.title:"",W=typeof D.description=="string"?D.description:"",ue=typeof D.code=="string"?D.code:"";return e.jsxs("div",{className:"bg-slate-50 rounded-lg p-3 border border-slate-100",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[e.jsx("span",{className:"text-[10px] font-bold text-blue-600 bg-blue-50 rounded-full w-5 h-5 flex items-center justify-center shrink-0",children:J+1}),me&&e.jsx("span",{className:"text-xs font-bold text-slate-700",children:me})]}),W&&e.jsx("p",{className:"text-xs text-slate-600 ml-7 leading-relaxed",children:W}),ue&&e.jsx("pre",{className:"text-[11px] font-mono bg-slate-800 text-green-300 p-2.5 rounded-md mt-1.5 ml-7 overflow-x-auto whitespace-pre-wrap",children:ue})]},J)})})]}),m.constraints&&(()=>{var me,W,ue,De,Le,Re,qe,We;const D=m.constraints,J=(((me=D.guards)==null?void 0:me.length)||0)+(((W=D.boundaries)==null?void 0:W.length)||0)+(((ue=D.preconditions)==null?void 0:ue.length)||0)+(((De=D.sideEffects)==null?void 0:De.length)||0);return J?e.jsxs("div",{className:"px-6 py-4 border-b border-slate-100",children:[e.jsxs("label",{className:"text-[10px] font-bold text-slate-400 uppercase mb-2 block flex items-center gap-1.5",children:[e.jsx(nt,{size:11,className:"text-amber-500"})," 约束条件 ",e.jsx("span",{className:"text-amber-500 font-mono",children:J})]}),e.jsxs("div",{className:"space-y-1.5 text-xs text-slate-600",children:[(Le=D.guards)==null?void 0:Le.map((G,ze)=>e.jsxs("div",{className:"flex gap-1.5 items-start",children:[e.jsx("span",{className:`text-xs mt-0.5 ${G.severity==="error"?"text-red-500":"text-yellow-500"}`,children:"●"}),e.jsx("code",{className:"font-mono text-[10px] bg-slate-100 px-1.5 py-0.5 rounded",children:G.pattern}),G.message&&e.jsxs("span",{className:"text-[10px] text-slate-400",children:["— ",G.message]})]},ze)),(Re=D.boundaries)==null?void 0:Re.map((G,ze)=>e.jsxs("div",{className:"flex gap-1.5",children:[e.jsx("span",{className:"text-orange-400",children:"●"}),G]},ze)),(qe=D.preconditions)==null?void 0:qe.map((G,ze)=>e.jsxs("div",{className:"flex gap-1.5",children:[e.jsx("span",{className:"text-blue-400",children:"◆"}),G]},ze)),(We=D.sideEffects)==null?void 0:We.map((G,ze)=>e.jsxs("div",{className:"flex gap-1.5",children:[e.jsx("span",{className:"text-pink-400",children:"⚡"}),G]},ze))]})]}):null})(),m.aiInsight&&e.jsxs("div",{className:"px-6 py-4 border-b border-slate-100",children:[e.jsxs("label",{className:"text-[10px] font-bold text-slate-400 uppercase mb-2 block flex items-center gap-1.5",children:[e.jsx(bt,{size:11,className:"text-cyan-400"})," AI 洞察"]}),e.jsx("p",{className:"text-sm text-slate-600 leading-relaxed",children:m.aiInsight})]}),(()=>{const D=Array.isArray(m.lifecycleHistory)?m.lifecycleHistory:(()=>{try{const J=typeof m.lifecycleHistory=="string"?JSON.parse(m.lifecycleHistory):null;return Array.isArray(J)?J:[]}catch{return[]}})();return D.length>0?e.jsxs("div",{className:"px-6 py-4 border-b border-slate-100",children:[e.jsxs("label",{className:"text-[10px] font-bold text-slate-400 uppercase mb-2 block flex items-center gap-1.5",children:[e.jsx(it,{size:11,className:"text-slate-400"})," 生命周期历史"]}),e.jsx("div",{className:"space-y-1",children:D.map((J,me)=>{const W=dt[J.from]||dt.pending,ue=dt[J.to]||dt.pending;return e.jsxs("div",{className:"flex items-center gap-2 text-[10px]",children:[e.jsx("span",{className:"text-slate-400 w-20 shrink-0",children:Ft(J.at)}),e.jsx("span",{className:`${W.color}`,children:W.label}),e.jsx("span",{className:"text-slate-300",children:"→"}),e.jsx("span",{className:`${ue.color} font-medium`,children:ue.label}),e.jsxs("span",{className:"text-slate-400 ml-auto",children:["by ",J.by]})]},me)})})]}):null})()]}),e.jsxs("div",{className:"shrink-0 border-t border-slate-200 px-5 py-3 bg-gradient-to-b from-slate-50/80 to-white flex items-center justify-between",children:[e.jsx("div",{className:"flex items-center gap-2",children:e.jsxs("button",{onClick:()=>{oe(m),P(null)},className:"flex items-center gap-1.5 px-3 py-2 rounded-lg text-xs font-medium text-red-500 hover:bg-red-50 border border-red-200 transition-colors",children:[e.jsx(st,{size:14})," 删除"]})}),e.jsx("div",{className:"flex items-center gap-2",children:(Zr[m.lifecycle]||[]).map(D=>{const J=D.icon;return e.jsxs("button",{onClick:()=>D.needsReason?Fe(m,D.action):ye(m,D.action),disabled:h,className:`flex items-center gap-1.5 px-4 py-2 rounded-lg text-xs font-bold border transition-colors disabled:opacity-50 ${D.bg} ${D.color} border-current/20`,children:[h?e.jsx(Te,{size:14,className:"animate-spin"}):e.jsx(J,{size:14}),D.label]},D.action)})})]})]})]})})()]})},is={manual:{label:"手动",color:"bg-slate-100 text-slate-600",icon:ia},"user-ai":{label:"AI 协助",color:"bg-violet-100 text-violet-600",icon:Ke},"system-ai":{label:"自动",color:"bg-amber-100 text-amber-600",icon:Jt},"external-ai":{label:"外部 AI",color:"bg-cyan-100 text-cyan-600",icon:$s}},sn=({onRefresh:t,signalSuggestionCount:s=0,onSuggestionCountChange:a})=>{const[l,n]=r.useState([]),[c,x]=r.useState(!0),[i,N]=r.useState(null),[j,g]=r.useState(!1),[p,u]=r.useState(!1),[w,f]=r.useState("all"),[E,A]=r.useState(!1),[M,R]=r.useState([]),[B,T]=r.useState(!1),[U,K]=r.useState(!1),[S,q]=r.useState(null),[C,m]=r.useState(!1),[P,h]=r.useState(""),[d,v]=r.useState(!1),[k,ee]=r.useState(!1),[L,Z]=r.useState(!1),fe=r.useCallback(async()=>{var I;x(!0);try{const le=await Y.listSkills();n(le.skills||[])}catch(le){((I=le.response)==null?void 0:I.status)!==404&&V(le.message||"",{title:"获取 Skills 列表失败",type:"error"}),n([])}finally{x(!1)}},[]);r.useEffect(()=>{fe()},[fe]);const O=async I=>{if((i==null?void 0:i.skillName)===I){N(null);return}m(!1),ee(!1),g(!0);try{const le=await Y.loadSkill(I);N(le)}catch{V(`"${I}" 不存在或读取出错`,{title:"加载 Skill 失败",type:"error"})}finally{g(!1)}},re=()=>{i!=null&&i.content&&(navigator.clipboard.writeText(i.content),A(!0),setTimeout(()=>A(!1),2e3))},ae=()=>{i&&(h(i.content),m(!0))},ye=()=>{m(!1),h("")},oe=async()=>{if(!(!i||!P.trim())){v(!0);try{await Y.updateSkill(i.skillName,{content:P}),V("已保存",{title:`Skill "${i.skillName}" 更新成功`}),m(!1);const I=await Y.loadSkill(i.skillName);N(I)}catch(I){V(I.message||"",{title:"更新 Skill 失败",type:"error"})}finally{v(!1)}}},Ne=async()=>{if(i){Z(!0);try{await Y.deleteSkill(i.skillName),V("已删除",{title:`Skill "${i.skillName}" 删除成功`}),N(null),ee(!1),m(!1),fe(),t==null||t()}catch(I){V(I.message||"",{title:"删除 Skill 失败",type:"error"})}finally{Z(!1)}}},be=async()=>{T(!0),K(!0);try{const[I,le]=await Promise.allSettled([Y.suggestSkills(),Y.getSignalStatus()]),we=I.status==="fulfilled"?I.value.suggestions||[]:[],ge=le.status==="fulfilled"?le.value.suggestions||[]:[],Me=new Map;for(const Ee of we)Me.set(Ee.name,Ee);for(const Ee of ge)Me.set(Ee.name,{...Me.get(Ee.name),...Ee});const Oe=[...Me.values()];R(Oe),a==null||a(Oe.length)}catch(I){V(I.message||"",{title:"获取 Skill 推荐失败",type:"error"}),R([]),a==null||a(0)}finally{T(!1)}};r.useEffect(()=>{s>0&&M.length===0&&!U&&be()},[]);const Ce=async I=>{q(I.name);try{const le=I.description||I.rationale||I.name,we=`请为以下场景创建一个 Skill 文档:
|
|
91
|
+
|
|
92
|
+
名称:${I.name}
|
|
93
|
+
描述:${le}
|
|
94
|
+
推荐原因:${I.rationale}
|
|
95
|
+
|
|
96
|
+
请直接生成 Skill 正文内容(Markdown 格式),不需要 frontmatter,不需要输出 JSON 元数据。内容应该详细、实用,包含具体的操作指南和示例。`;let Me=(await Y.aiGenerateSkill(we)).reply||I.body||`# ${le}
|
|
97
|
+
|
|
98
|
+
${I.rationale||""}`;Me=Me.replace(/^\s*\{["']name["']\s*:.*\}\s*\n?/,"").trim(),await Y.createSkill({name:I.name,description:le,content:Me,createdBy:"user-ai"}),V("已创建并加入知识库",{title:`Skill "${I.name}" 创建成功`}),R(Oe=>{const Ee=Oe.filter(y=>y.name!==I.name);return a==null||a(Ee.length),Ee}),fe()}catch(le){V(le.message||"",{title:"创建 Skill 失败",type:"error"})}finally{q(null)}},Ae=l.filter(I=>w==="all"?!0:I.source===w).sort((I,le)=>I.source===le.source?I.name.localeCompare(le.name):I.source==="project"?-1:1),Fe=l.filter(I=>I.source==="builtin").length,_=l.filter(I=>I.source==="project").length;return e.jsxs("div",{className:"h-full flex flex-col",children:[e.jsxs("div",{className:"flex items-center justify-between mb-6",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-10 h-10 bg-violet-100 rounded-xl flex items-center justify-center",children:e.jsx(Je,{size:20,className:"text-violet-600"})}),e.jsxs("div",{children:[e.jsx("h2",{className:"text-xl font-bold text-slate-800",children:"Skills"}),e.jsx("p",{className:"text-sm text-slate-500",children:"Agent 技能文档 — 指导 AI 如何正确使用 AutoSnippet 工具"})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("button",{onClick:be,disabled:B,className:"flex items-center gap-2 px-3 py-2 border border-amber-300 text-amber-700 bg-amber-50 rounded-lg hover:bg-amber-100 transition-colors text-sm font-medium disabled:opacity-50",title:"基于使用模式分析推荐 Skill",children:[B?e.jsx(Te,{size:14,className:"animate-spin"}):e.jsx(bt,{size:14}),"推荐"]}),e.jsx("button",{onClick:fe,className:"p-2 rounded-lg text-slate-400 hover:text-slate-600 hover:bg-slate-100 transition-colors",title:"刷新",children:e.jsx(ht,{size:16})}),e.jsxs("button",{onClick:()=>u(!0),className:"flex items-center gap-2 px-4 py-2 bg-violet-600 text-white rounded-lg hover:bg-violet-700 transition-colors text-sm font-medium",children:[e.jsx(Ke,{size:14}),"AI 新建 Skill"]})]})]}),e.jsx("div",{className:"flex items-center gap-1 mb-4 p-1 bg-slate-100 rounded-lg w-fit",children:[{key:"all",label:"全部",count:l.length},{key:"project",label:"项目级",count:_,icon:Tt},{key:"builtin",label:"内置",count:Fe,icon:ll}].map(I=>e.jsxs("button",{onClick:()=>f(I.key),className:`flex items-center gap-1.5 px-3 py-1.5 rounded-md text-xs font-medium transition-colors ${w===I.key?"bg-white text-violet-700 shadow-sm":"text-slate-500 hover:text-slate-700"}`,children:[I.icon&&e.jsx(I.icon,{size:12}),I.label,e.jsx("span",{className:`ml-0.5 px-1.5 py-0.5 rounded-full text-[10px] ${w===I.key?"bg-violet-100 text-violet-600":"bg-slate-200 text-slate-500"}`,children:I.count})]},I.key))}),U&&e.jsxs("div",{className:"mb-4 border border-amber-200 bg-amber-50/50 rounded-xl p-4",children:[e.jsxs("div",{className:"flex items-center justify-between mb-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(bt,{size:16,className:"text-amber-600"}),e.jsx("span",{className:"text-sm font-semibold text-amber-800",children:"推荐创建的 Skills"}),M.length>0&&e.jsx("span",{className:"px-1.5 py-0.5 bg-amber-200 text-amber-700 text-[10px] font-bold rounded-full",children:M.length})]}),e.jsx("button",{onClick:()=>K(!1),className:"p-1 text-amber-400 hover:text-amber-600",children:e.jsx(Ye,{size:14})})]}),B?e.jsxs("div",{className:"flex items-center gap-2 text-amber-600 text-xs py-2",children:[e.jsx(Te,{size:14,className:"animate-spin"}),"分析使用模式中..."]}):M.length===0?e.jsx("p",{className:"text-xs text-amber-600/70",children:"当前暂无推荐。继续使用后会积累更多信号。"}):e.jsx("div",{className:"space-y-2",children:M.map(I=>e.jsxs("div",{className:"flex items-start gap-3 p-3 bg-white rounded-lg border border-amber-100",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[e.jsx("span",{className:"font-mono text-xs font-semibold text-slate-800",children:I.name}),e.jsx("span",{className:`px-1.5 py-0.5 rounded text-[9px] font-bold uppercase ${I.priority==="high"?"bg-red-100 text-red-600":I.priority==="medium"?"bg-amber-100 text-amber-600":"bg-slate-100 text-slate-500"}`,children:I.priority}),e.jsx("span",{className:"text-[10px] text-slate-400",children:I.source})]}),e.jsx("p",{className:"text-xs text-slate-600 mb-1",children:I.description}),e.jsx("p",{className:"text-[11px] text-slate-400 line-clamp-2",children:I.rationale})]}),e.jsx("button",{onClick:()=>Ce(I),disabled:S===I.name,className:"shrink-0 flex items-center gap-1.5 px-3 py-1.5 bg-amber-500 text-white rounded-lg hover:bg-amber-600 transition-colors text-xs font-medium disabled:opacity-50",children:S===I.name?e.jsxs(e.Fragment,{children:[e.jsx(Te,{size:12,className:"animate-spin"})," 创建中"]}):e.jsxs(e.Fragment,{children:[e.jsx(Qe,{size:12})," AI 创建"]})})]},I.name))})]}),e.jsxs("div",{className:"flex-1 flex gap-6 min-h-0 overflow-hidden",children:[e.jsx("div",{className:"w-1/2 overflow-y-auto pr-2 space-y-2",children:c?e.jsx("div",{className:"flex items-center justify-center py-20",children:e.jsx(Te,{size:24,className:"animate-spin text-violet-400"})}):Ae.length===0?e.jsxs("div",{className:"text-center py-20 text-slate-400",children:[e.jsx(Je,{size:40,className:"mx-auto mb-3 opacity-40"}),e.jsx("p",{children:"暂无 Skills"})]}):Ae.map(I=>e.jsx("button",{onClick:()=>O(I.name),className:`w-full text-left p-4 rounded-xl border transition-all ${(i==null?void 0:i.skillName)===I.name?"border-violet-300 bg-violet-50 shadow-sm":"border-slate-200 bg-white hover:border-slate-300 hover:shadow-sm"}`,children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("div",{className:`mt-0.5 shrink-0 ${(i==null?void 0:i.skillName)===I.name?"text-violet-500":"text-slate-400"}`,children:(i==null?void 0:i.skillName)===I.name?e.jsx(St,{size:16}):e.jsx(at,{size:16})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[e.jsx("span",{className:"font-mono text-sm font-semibold text-slate-800",children:I.name}),e.jsx("span",{className:`px-1.5 py-0.5 rounded text-[10px] font-bold uppercase tracking-wider ${I.source==="builtin"?"bg-blue-100 text-blue-600":"bg-emerald-100 text-emerald-600"}`,children:I.source==="builtin"?"内置":"项目"}),I.createdBy&&is[I.createdBy]&&(()=>{const le=is[I.createdBy],we=le.icon;return e.jsxs("span",{className:`flex items-center gap-0.5 px-1.5 py-0.5 rounded text-[10px] font-medium ${le.color}`,children:[e.jsx(we,{size:10}),le.label]})})()]}),e.jsx("p",{className:"text-xs text-slate-500 line-clamp-2",children:I.summary}),I.useCase&&e.jsxs("p",{className:"text-[11px] text-violet-500 mt-1 italic",children:["适用:",I.useCase]})]})]})},I.name))}),e.jsx("div",{className:"w-1/2 overflow-y-auto border border-slate-200 rounded-xl bg-white",children:j?e.jsx("div",{className:"flex items-center justify-center h-full",children:e.jsx(Te,{size:24,className:"animate-spin text-violet-400"})}):i?e.jsxs("div",{className:"h-full flex flex-col",children:[e.jsxs("div",{className:"flex items-center justify-between p-4 border-b border-slate-100",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(tt,{size:16,className:"text-violet-500"}),e.jsx("span",{className:"font-mono font-semibold text-sm",children:i.skillName}),e.jsx("span",{className:`px-1.5 py-0.5 rounded text-[10px] font-bold uppercase ${i.source==="builtin"?"bg-blue-100 text-blue-600":"bg-emerald-100 text-emerald-600"}`,children:i.source==="builtin"?"内置":"项目"}),i.createdBy&&is[i.createdBy]&&(()=>{const I=is[i.createdBy],le=I.icon;return e.jsxs("span",{className:`flex items-center gap-0.5 px-1.5 py-0.5 rounded text-[10px] font-medium ${I.color}`,children:[e.jsx(le,{size:10}),I.label,"创建"]})})()]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("span",{className:"text-[10px] text-slate-400",children:[i.charCount," 字符"]}),e.jsx("button",{onClick:re,className:"p-1.5 rounded-md hover:bg-slate-100 transition-colors text-slate-400 hover:text-slate-600",title:"复制内容",children:E?e.jsx(yt,{size:14,className:"text-emerald-500"}):e.jsx(Et,{size:14})}),i.source==="project"&&!C&&e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:ae,className:"p-1.5 rounded-md hover:bg-blue-50 transition-colors text-slate-400 hover:text-blue-600",title:"编辑",children:e.jsx(ws,{size:14})}),e.jsx("button",{onClick:()=>ee(!0),className:"p-1.5 rounded-md hover:bg-red-50 transition-colors text-slate-400 hover:text-red-500",title:"删除",children:e.jsx(st,{size:14})})]}),C&&e.jsxs(e.Fragment,{children:[e.jsxs("button",{onClick:oe,disabled:d,className:"flex items-center gap-1 px-2.5 py-1 bg-blue-600 text-white rounded-md hover:bg-blue-700 transition-colors text-xs font-medium disabled:opacity-50",children:[d?e.jsx(Te,{size:12,className:"animate-spin"}):e.jsx(Qt,{size:12}),"保存"]}),e.jsx("button",{onClick:ye,className:"px-2.5 py-1 border border-slate-200 text-slate-500 rounded-md hover:bg-slate-50 transition-colors text-xs",children:"取消"})]})]})]}),i.relatedSkills.length>0&&e.jsxs("div",{className:"px-4 py-2 border-b border-slate-50 flex items-center gap-2 flex-wrap",children:[e.jsx("span",{className:"text-[10px] text-slate-400 uppercase font-bold",children:"相关:"}),i.relatedSkills.map(I=>e.jsx("button",{onClick:()=>O(I),className:"text-[11px] text-violet-600 hover:text-violet-800 bg-violet-50 px-2 py-0.5 rounded-full transition-colors",children:I},I))]}),e.jsxs("div",{className:"flex-1 overflow-y-auto p-4 relative",children:[C?e.jsx("textarea",{value:P,onChange:I=>h(I.target.value),className:"w-full h-full min-h-[300px] text-xs text-slate-700 font-mono leading-relaxed border border-blue-200 rounded-lg p-3 focus:outline-none focus:ring-2 focus:ring-blue-300 resize-none bg-blue-50/30",spellCheck:!1}):e.jsx("pre",{className:"whitespace-pre-wrap text-xs text-slate-700 font-mono leading-relaxed",children:i.content}),k&&e.jsx("div",{className:"absolute inset-0 bg-white/90 backdrop-blur-sm flex items-center justify-center z-10",children:e.jsxs("div",{className:"bg-white border border-red-200 rounded-xl shadow-lg p-6 max-w-sm text-center",children:[e.jsx(st,{size:32,className:"mx-auto mb-3 text-red-400"}),e.jsx("h3",{className:"font-semibold text-slate-800 mb-2",children:"确认删除"}),e.jsxs("p",{className:"text-sm text-slate-500 mb-4",children:['删除 Skill "',e.jsx("span",{className:"font-mono font-bold",children:i.skillName}),'"?此操作不可撤销。']}),e.jsxs("div",{className:"flex gap-3 justify-center",children:[e.jsx("button",{onClick:()=>ee(!1),className:"px-4 py-2 border border-slate-200 text-slate-600 rounded-lg hover:bg-slate-50 text-sm",children:"取消"}),e.jsxs("button",{onClick:Ne,disabled:L,className:"flex items-center gap-1.5 px-4 py-2 bg-red-600 text-white rounded-lg hover:bg-red-700 text-sm font-medium disabled:opacity-50",children:[L?e.jsx(Te,{size:14,className:"animate-spin"}):e.jsx(st,{size:14}),"确认删除"]})]})]})})]})]}):e.jsx("div",{className:"flex items-center justify-center h-full text-slate-400",children:e.jsxs("div",{className:"text-center",children:[e.jsx(Je,{size:40,className:"mx-auto mb-3 opacity-30"}),e.jsx("p",{className:"text-sm",children:"选择左侧 Skill 查看详情"})]})})})]}),p&&e.jsx(an,{onClose:()=>u(!1),onCreated:()=>{u(!1),fe(),t==null||t()}})]})},an=({onClose:t,onCreated:s})=>{const[a,l]=r.useState("ai"),[n,c]=r.useState(""),[x,i]=r.useState(!1),[N,j]=r.useState(""),[g,p]=r.useState(""),[u,w]=r.useState(""),[f,E]=r.useState(!1),[A,M]=r.useState(""),[R,B]=r.useState(!1),T=async()=>{if(n.trim()){i(!0),M("");try{const S=(await Y.aiGenerateSkill(n)).reply||"";let q="",C="",m=S;const P=/```(?:json)?\s*\n?\s*(\{[^}]*"name"[^}]*\})\s*\n?\s*```/i,h=S.match(P);if(h)try{const d=JSON.parse(h[1]);q=d.name||"",C=d.description||"",m=S.replace(h[0],"").trim()}catch{}if(!q){const d=S.split(`
|
|
99
|
+
`);for(let v=0;v<Math.min(d.length,5);v++){const k=d[v].trim();if(!(!k||k.startsWith("```"))&&k.startsWith("{")&&k.endsWith("}"))try{const ee=JSON.parse(k);if(ee.name){q=ee.name,C=ee.description||"";let L=v+1;for(;L<d.length&&!d[L].trim();)L++;m=d.slice(L).join(`
|
|
100
|
+
`).trim();break}}catch{}}}if(!q){const d=/"name"\s*:\s*"([a-z][a-z0-9-]{1,62}[a-z0-9])"/,v=/"description"\s*:\s*"([^"]+)"/,k=S.match(d),ee=S.match(v);k&&(q=k[1]),ee&&(C=ee[1])}m=m.replace(/```(?:json)?\s*\n?\s*\{[^}]*"name"[^}]*\}\s*\n?\s*```/gi,"").replace(/^\s*\{[^}]*"name"[^}]*\}\s*$/gm,"").trim(),q&&j(q),C&&p(C),w(m||S.trim()),B(!0),l("manual"),V("请检查并确认生成的内容",{title:"AI 已生成 Skill"})}catch(K){M("AI 生成失败: "+(K.message||""))}finally{i(!1)}}},U=async()=>{var K,S,q;if(!N.trim()||!g.trim()||!u.trim()){M("请填写名称、描述和内容");return}E(!0),M("");try{await Y.createSkill({name:N.trim(),description:g.trim(),content:u.trim(),createdBy:R?"user-ai":"manual"}),V("已保存到知识库",{title:`Skill "${N}" 创建成功`}),s()}catch(C){const m=((q=(S=(K=C.response)==null?void 0:K.data)==null?void 0:S.error)==null?void 0:q.message)||C.message||"";M("创建失败: "+m)}finally{E(!1)}};return e.jsxs(Ve,{className:"z-40 flex items-center justify-center",children:[e.jsx(Ve.Backdrop,{className:"bg-black/40 backdrop-blur-sm"}),e.jsxs("div",{className:"relative bg-white rounded-2xl shadow-2xl w-[720px] max-h-[85vh] flex flex-col",children:[e.jsxs("div",{className:"flex items-center justify-between px-6 py-4 border-b border-slate-100",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-8 h-8 bg-violet-100 rounded-lg flex items-center justify-center",children:e.jsx(Ke,{size:16,className:"text-violet-600"})}),e.jsx("h3",{className:"font-bold text-lg",children:"新建 Skill"})]}),e.jsx("button",{onClick:t,className:"p-1.5 rounded-lg hover:bg-slate-100 transition-colors",children:e.jsx(Ye,{size:18,className:"text-slate-400"})})]}),e.jsx("div",{className:"px-6 pt-4",children:e.jsxs("div",{className:"inline-flex items-center gap-1 p-1 bg-slate-100 rounded-lg",children:[e.jsxs("button",{onClick:()=>l("ai"),className:`flex items-center gap-1.5 px-3 py-1.5 rounded-md text-xs font-medium transition-colors ${a==="ai"?"bg-white text-violet-700 shadow-sm":"text-slate-500 hover:text-slate-700"}`,children:[e.jsx(Ke,{size:12}),"AI 生成"]}),e.jsxs("button",{onClick:()=>l("manual"),className:`flex items-center gap-1.5 px-3 py-1.5 rounded-md text-xs font-medium transition-colors ${a==="manual"?"bg-white text-violet-700 shadow-sm":"text-slate-500 hover:text-slate-700"}`,children:[e.jsx(tt,{size:12}),"手动填写"]})]})}),e.jsxs("div",{className:"flex-1 overflow-y-auto px-6 py-4 space-y-4",children:[a==="ai"?e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-slate-700 mb-1.5",children:"描述你想创建的 Skill"}),e.jsx("div",{className:"relative",children:e.jsx("textarea",{value:n,onChange:K=>c(K.target.value),placeholder:"例如:创建一个关于 SwiftUI 动画最佳实践的 Skill,包含常见动画模式、性能优化建议和代码示例...",className:"w-full h-32 px-4 py-3 border border-slate-200 rounded-xl text-sm resize-none focus:outline-none focus:ring-2 focus:ring-violet-300 focus:border-violet-400",disabled:x})})]}),e.jsx("button",{onClick:T,disabled:x||!n.trim(),className:"w-full flex items-center justify-center gap-2 px-4 py-3 bg-violet-600 text-white rounded-xl hover:bg-violet-700 disabled:opacity-50 disabled:cursor-not-allowed transition-colors font-medium",children:x?e.jsxs(e.Fragment,{children:[e.jsx(Te,{size:16,className:"animate-spin"}),"AI 正在生成..."]}):e.jsxs(e.Fragment,{children:[e.jsx(Ss,{size:16}),"生成 Skill"]})})]}):e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsxs("label",{className:"block text-sm font-medium text-slate-700 mb-1.5",children:["名称 ",e.jsx("span",{className:"text-slate-400 text-xs",children:"(kebab-case)"})]}),e.jsx("input",{type:"text",value:N,onChange:K=>j(K.target.value),placeholder:"my-custom-skill",className:"w-full px-3 py-2 border border-slate-200 rounded-lg text-sm font-mono focus:outline-none focus:ring-2 focus:ring-violet-300 focus:border-violet-400"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-slate-700 mb-1.5",children:"一句话描述"}),e.jsx("input",{type:"text",value:g,onChange:K=>p(K.target.value),placeholder:"SwiftUI 动画最佳实践指南",className:"w-full px-3 py-2 border border-slate-200 rounded-lg text-sm focus:outline-none focus:ring-2 focus:ring-violet-300 focus:border-violet-400"})]})]}),e.jsxs("div",{children:[e.jsxs("label",{className:"block text-sm font-medium text-slate-700 mb-1.5",children:["Skill 文档内容 ",e.jsx("span",{className:"text-slate-400 text-xs",children:"(Markdown)"})]}),e.jsx("textarea",{value:u,onChange:K=>w(K.target.value),placeholder:`# My Custom Skill
|
|
101
|
+
|
|
102
|
+
## 使用场景
|
|
103
|
+
...
|
|
104
|
+
|
|
105
|
+
## 操作步骤
|
|
106
|
+
...`,className:"w-full h-64 px-4 py-3 border border-slate-200 rounded-xl text-sm font-mono resize-none focus:outline-none focus:ring-2 focus:ring-violet-300 focus:border-violet-400 leading-relaxed"})]})]}),A&&e.jsxs("div",{className:"flex items-start gap-2 p-3 bg-red-50 border border-red-200 rounded-lg text-sm text-red-700",children:[e.jsx(Kt,{size:16,className:"shrink-0 mt-0.5"}),e.jsx("span",{children:A})]})]}),e.jsxs("div",{className:"px-6 py-4 border-t border-slate-100 flex items-center justify-end gap-3",children:[e.jsx("button",{onClick:t,className:"px-4 py-2 text-sm text-slate-600 hover:text-slate-800 transition-colors",children:"取消"}),a==="manual"&&e.jsx("button",{onClick:U,disabled:f||!N.trim()||!g.trim()||!u.trim(),className:"flex items-center gap-2 px-5 py-2 bg-violet-600 text-white rounded-lg hover:bg-violet-700 disabled:opacity-50 disabled:cursor-not-allowed transition-colors text-sm font-medium",children:f?e.jsxs(e.Fragment,{children:[e.jsx(Te,{size:14,className:"animate-spin"}),"保存中..."]}):e.jsxs(e.Fragment,{children:[e.jsx(Nt,{size:14}),"创建 Skill"]})})]})]})]})},ea=["objc-deep-scan","category-scan","project-profile","code-standard","architecture","code-pattern","event-and-data-flow","best-practice","agent-guidelines"],ln={"code-standard":e.jsx(Je,{className:"w-5 h-5"}),"code-pattern":e.jsx(Mt,{className:"w-5 h-5"}),architecture:e.jsx(et,{className:"w-5 h-5"}),"best-practice":e.jsx(Ke,{className:"w-5 h-5"}),"event-and-data-flow":e.jsx(Qe,{className:"w-5 h-5"}),"project-profile":e.jsx(da,{className:"w-5 h-5"}),"agent-guidelines":e.jsx($s,{className:"w-5 h-5"})};function rn(t){return ln[t]||e.jsx(Mt,{className:"w-5 h-5"})}const nn=({task:t})=>{const{status:s,meta:a}=t,l={skeleton:"bg-slate-50 border-slate-200",filling:"bg-blue-50 border-blue-300",completed:"bg-emerald-50 border-emerald-300",failed:"bg-red-50 border-red-300"},n={skeleton:e.jsxs("span",{className:"flex items-center gap-1 text-xs text-slate-400",children:[e.jsx("div",{className:"w-2 h-2 rounded-full bg-slate-300"}),"等待中"]}),filling:e.jsxs("span",{className:"flex items-center gap-1 text-xs text-blue-600",children:[e.jsx(Te,{className:"w-3 h-3 animate-spin"}),"填充中"]}),completed:e.jsxs("span",{className:"flex items-center gap-1 text-xs text-emerald-600",children:[e.jsx(yt,{className:"w-3 h-3"}),"已完成"]}),failed:e.jsxs("span",{className:"flex items-center gap-1 text-xs text-red-600",children:[e.jsx(Ye,{className:"w-3 h-3"}),"失败"]})};return e.jsxs("div",{className:`relative rounded-xl border p-4 transition-all duration-300 ${l[s]||l.skeleton}`,children:[s==="skeleton"&&e.jsx("div",{className:"absolute inset-0 rounded-xl overflow-hidden",children:e.jsx("div",{className:"animate-pulse bg-gradient-to-r from-transparent via-slate-200/40 to-transparent h-full w-full"})}),s==="filling"&&e.jsx("div",{className:"absolute inset-0 rounded-xl overflow-hidden",children:e.jsx("div",{className:"animate-pulse bg-gradient-to-r from-transparent via-blue-200/30 to-transparent h-full w-full"})}),e.jsxs("div",{className:"relative z-10 flex items-start justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:`flex-shrink-0 p-2 rounded-lg ${s==="completed"?"bg-emerald-100 text-emerald-600":s==="filling"?"bg-blue-100 text-blue-600":s==="failed"?"bg-red-100 text-red-600":"bg-slate-100 text-slate-400"}`,children:rn(t.id)}),e.jsxs("div",{children:[e.jsx("h3",{className:`font-medium text-sm ${s==="skeleton"?"text-slate-400":"text-slate-800"}`,children:a.label}),e.jsxs("p",{className:"text-xs text-slate-500 mt-0.5",children:[a.skillWorthy?"Skill":"Candidate",t.result&&s==="completed"&&e.jsx("span",{className:"ml-2 text-emerald-600",children:(()=>{const c=t.result,x=c.sourceCount??0,i=c.extracted??0;return c.type==="empty"?"✓ 无匹配内容":c.type==="skill"?c.empty?"✓ 无匹配内容":i>0?`✓ ${x} 项特征 · ${i} 条候选`:`✓ ${x} 项特征`:i>0?`✓ ${i} 条候选`:"✓ 无匹配内容"})()}),t.error&&s==="failed"&&e.jsx("span",{className:"ml-2 text-red-500 truncate max-w-[200px] inline-block align-bottom",children:t.error})]})]})]}),e.jsx("div",{className:"flex-shrink-0",children:n[s]})]})]})},on=[{key:"round1",label:"资格审查",desc:"过滤误报 · 识别合并",icon:e.jsx(rl,{className:"w-4 h-4"})},{key:"round2",label:"内容精炼",desc:"AI 改写摘要 · 动态置信度",icon:e.jsx(cs,{className:"w-4 h-4"})},{key:"round3",label:"去重 & 关系",desc:"语义去重 · 关系推断",icon:e.jsx(nl,{className:"w-4 h-4"})}],cn=({review:t})=>t.activeRound===0?null:e.jsxs("div",{className:"mt-5 border border-purple-200 rounded-xl bg-purple-50/50 p-4",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[e.jsx(Yt,{className:"w-5 h-5 text-purple-600"}),e.jsx("h3",{className:"text-sm font-semibold text-purple-800",children:"AI 审查管线"})]}),e.jsx("div",{className:"space-y-2.5",children:on.map(({key:s,label:a,desc:l,icon:n})=>{const c=t[s],x=c.status==="running",i=c.status==="completed",N=c.status==="idle";return e.jsxs("div",{className:`flex items-center gap-3 p-2.5 rounded-lg border transition-all duration-300 ${x?"border-purple-300 bg-purple-100/60":i?"border-emerald-300 bg-emerald-50/60":"border-slate-200 bg-white/40"}`,children:[e.jsx("div",{className:`flex-shrink-0 p-1.5 rounded-md ${x?"bg-purple-200 text-purple-700":i?"bg-emerald-100 text-emerald-600":"bg-slate-100 text-slate-400"}`,children:n}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:`text-sm font-medium ${N?"text-slate-400":"text-slate-800"}`,children:a}),e.jsx("span",{className:"text-xs text-slate-400",children:l})]}),s==="round1"&&i&&e.jsxs("p",{className:"text-xs text-emerald-600 mt-0.5",children:["保留 ",t.round1.kept??"?"," · 合并 ",t.round1.merged??0," · 丢弃 ",t.round1.dropped??0]}),s==="round2"&&x&&typeof t.round2.progress=="number"&&e.jsxs("div",{className:"mt-1.5",children:[e.jsx("div",{className:"w-full h-1.5 bg-purple-200 rounded-full overflow-hidden",children:e.jsx("div",{className:"h-full bg-purple-500 rounded-full transition-all duration-300",style:{width:`${t.round2.progress}%`}})}),e.jsxs("p",{className:"text-xs text-purple-600 mt-0.5",children:[t.round2.current??0,"/",t.round2.total??"?"," 条"]})]}),s==="round2"&&i&&e.jsxs("p",{className:"text-xs text-emerald-600 mt-0.5",children:["已精炼 ",t.round2.refined??"?","/",t.round2.total??"?"," 条"]}),s==="round3"&&i&&e.jsxs("p",{className:"text-xs text-emerald-600 mt-0.5",children:["去重后 ",t.round3.afterDedup??"?"," 条 · ",t.round3.relationsFound??0," 条关系"]})]}),e.jsxs("div",{className:"flex-shrink-0",children:[x&&e.jsx(Te,{className:"w-4 h-4 text-purple-500 animate-spin"}),i&&e.jsx(yt,{className:"w-4 h-4 text-emerald-500"})]})]},s)})})]});function ta(t){if(t<0)return"--";const s=Math.floor(t/1e3),a=Math.floor(s/60),l=s%60;return a===0?`${l}s`:`${a}m ${l.toString().padStart(2,"0")}s`}const dn=({session:t,isAllDone:s,reviewState:a,onDismiss:l})=>{const n=r.useRef(!1),[c,x]=r.useState(Date.now());if(r.useEffect(()=>{if(!t||t.status!=="running")return;const f=setInterval(()=>x(Date.now()),1e3);return()=>clearInterval(f)},[t==null?void 0:t.status]),r.useEffect(()=>{if(s&&t&&!n.current){n.current=!0;const f=t.failed>0?`${t.completed}/${t.total} 成功,${t.failed} 失败`:`${t.completed} 个维度全部填充成功`;V(f,{title:"冷启动完成",type:t.failed>0?"error":"success"})}},[s,t]),r.useEffect(()=>{t||(n.current=!1)},[t==null?void 0:t.id]),!t)return null;const i=t.startedAt?c-t.startedAt:t.elapsedMs??0,N=t.completed+t.failed,j=t.total-N,g=t.elapsedMs??0,p=N>0&&g>0?Math.round(g/N*j):-1,u=t.totalToolCalls??0,w=t.status==="completed"?"全部完成":t.status==="completed_with_errors"?"完成(有错误)":null;return e.jsxs("div",{className:"bg-white rounded-2xl border border-slate-200 shadow-sm p-6",children:[e.jsxs("div",{className:"flex items-center justify-between mb-5",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-lg font-semibold text-slate-800",children:"冷启动进度"}),w&&e.jsx("p",{className:"text-sm text-slate-500 mt-0.5",children:w})]}),s&&l&&e.jsx("button",{onClick:l,className:"text-sm px-3 py-1.5 rounded-lg bg-slate-100 hover:bg-slate-200 text-slate-600 transition-colors",children:"关闭"})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-4 mb-5 text-sm",children:[e.jsxs("div",{className:"flex items-center gap-1.5 text-slate-600",children:[e.jsx(it,{size:14,className:"text-slate-400"}),e.jsxs("span",{children:["已用 ",e.jsx("span",{className:"font-medium text-slate-800",children:ta(i)})]})]}),t.status==="running"&&j>0&&p>0&&e.jsxs("div",{className:"flex items-center gap-1.5 text-slate-600",children:[e.jsx(it,{size:14,className:"text-blue-400"}),e.jsxs("span",{children:["预计剩余 ",e.jsx("span",{className:"font-medium text-blue-600",children:ta(p)})]})]}),e.jsxs("div",{className:"flex items-center gap-1.5 text-slate-600",children:[e.jsx(pa,{size:14,className:"text-slate-400"}),e.jsxs("span",{children:["工具调用 ",e.jsx("span",{className:"font-medium text-slate-800",children:u})]})]}),e.jsxs("div",{className:"text-slate-400 text-xs",children:[N,"/",t.total," 维度"]})]}),e.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-3",children:[...t.tasks].sort((f,E)=>{var R,B;const A=ea.indexOf(((R=f.meta)==null?void 0:R.dimId)??f.id),M=ea.indexOf(((B=E.meta)==null?void 0:B.dimId)??E.id);return(A===-1?999:A)-(M===-1?999:M)}).map(f=>e.jsx(nn,{task:f},f.id))}),a&&a.activeRound>0&&e.jsx(cn,{review:a})]})},xn=()=>{const t=r.useRef(null),s=r.useRef(!0),a=`// AutoSnippet Xcode 模拟器
|
|
107
|
+
// 支持的指令:
|
|
108
|
+
// // as:search <query> - 搜索代码片段
|
|
109
|
+
// // as:create <query> - 创建代码片段
|
|
110
|
+
// // as:audit <path> - 审计代码
|
|
111
|
+
//
|
|
112
|
+
// 示例:
|
|
113
|
+
// // as:search useState hooks
|
|
114
|
+
// // as:create custom form validation utility
|
|
115
|
+
// // as:audit /src/components
|
|
116
|
+
`,l=r.useRef(a),n=r.useRef(0),[c,x]=r.useState({content:a,cursorPos:0,cursorLine:0,cursorCol:0}),[i,N]=r.useState([]),[j,g]=r.useState(""),[p,u]=r.useState(!1),[w,f]=r.useState(!1),[E,A]=r.useState(!0),[M,R]=r.useState(null),[B,T]=r.useState(new Set),[U,K]=r.useState(""),[S,q]=r.useState(null),C=(O,re)=>{const ae=O.split(`
|
|
117
|
+
`);let ye=0,oe=0,Ne=0;for(let be=0;be<ae.length;be++){if(Ne+ae[be].length+1>re){ye=be,oe=re-Ne;break}Ne+=ae[be].length+1}return{line:ye,col:oe}},m=(O,re=0)=>{l.current=O,n.current=re;const{line:ae,col:ye}=C(O,re);x({content:O,cursorPos:re,cursorLine:ae,cursorCol:ye}),h(O)},P=O=>{n.current=O;const{line:re,col:ae}=C(l.current,O);x(ye=>({...ye,cursorPos:O,cursorLine:re,cursorCol:ae}))};r.useEffect(()=>{s.current=!0,h(c.content),d();const O=()=>{t.current&&t.current.clientHeight};return window.addEventListener("resize",O),()=>{s.current=!1,window.removeEventListener("resize",O)}},[]);const h=(O=c.content)=>{const re=O.split(`
|
|
118
|
+
`),ae=[];re.forEach((ye,oe)=>{const Ne=ye.match(/\/\/\s*as:(search|create|audit)\s+(.+)/);Ne&&ae.push({line:oe,type:Ne[1],directive:Ne[0],query:Ne[2].trim()})}),N(ae)},d=async()=>{try{const O=await fetch("/api/v1/commands/files/tree");if(O.ok){const re=await O.json(),ae=re.data||re.tree||re;if(ae&&ae.children&&ae.children.length>0){R(ae),ae.path&&T(new Set([ae.path]));return}}}catch(O){console.error("Failed to load file tree from API:",O)}R(null)},v=async O=>{var re;try{const ae=await fetch(`/api/v1/commands/files/read?path=${encodeURIComponent(O)}`);if(!ae.ok)throw new Error(`Open failed with status ${ae.status}`);const ye=await ae.json(),oe=ye.data||ye,Ne=oe.content||"";m(Ne,0),K(oe.path||O);const be=((re=O.split(".").pop())==null?void 0:re.toLowerCase())||"",Ce={h:"objc",m:"objc",swift:"swift"};g("")}catch(ae){console.error("Open file failed:",ae),g(`✗ 打开文件失败: ${ae instanceof Error?ae.message:"未知错误"}`)}},k=async()=>{try{await fetch("/api/v1/commands/files/save",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:U,content:c.content})})}catch(O){console.error("Save failed:",O)}},ee=()=>{window.confirm("确定要清空编辑器吗?")&&m("",0)},L=async O=>{var re;u(!0),q(i.indexOf(O));try{console.log(`[Execute] 触发 ${O.type} 指令...`,{query:O.query,line:O.line});const ae=await fetch("/api/v1/commands/execute",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({type:O.type,query:O.query,line:O.line,content:c.content,source:"simulator"})}),ye=await ae.json();if(console.log("[Execute] 响应:",ye),!ae.ok)throw new Error(ye.error||"执行失败");if(O.type==="search"&&ye.results&&ye.results.length>0){console.log(`[Execute] 搜索到 ${ye.results.length} 个结果,准备显示 NativeUI 弹窗`);const oe=ye.results.map((Ce,Ae)=>`${Ae+1}. ${Ce.title} (${Ce.category||"uncategorized"})`),be=await(await fetch("/api/v1/commands/execute",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({type:"list",title:`搜索结果: ${O.query}`,options:oe})})).json();if(be.success&&((re=be.result)==null?void 0:re.selectedIndex)>=0){const Ce=ye.results[be.result.selectedIndex];console.log(`[Execute] 用户选择了: ${Ce.title}`);const Ae=c.content.split(`
|
|
119
|
+
`),Fe=O.line+1,I=(Ce.body||`// ${Ce.title}`).split(`
|
|
120
|
+
`);Ae.splice(Fe,0,...I);const le=Ae.join(`
|
|
121
|
+
`),we=c.content.split(`
|
|
122
|
+
`).slice(0,Fe).join(`
|
|
123
|
+
`).length+1;m(le,we),console.log(`✓ 已插入代码片段: ${Ce.title}`)}else console.log("[Execute] 用户取消了选择")}else O.type==="search"&&console.warn("[Execute] 未找到匹配的搜索结果");ye.success&&console.log(`✓ 指令已执行: ${ye.message}`)}catch(ae){console.error(`✗ 错误: ${ae instanceof Error?ae.message:"执行失败"}`)}finally{u(!1)}},Z=(O,re=60)=>{if(O.length<=re)return O;const ae=O.split("/");if(ae.length<=2)return O;const ye=ae[ae.length-1],oe=ae.slice(0,2).join("/");if(oe.length+ye.length+5>re){const be=re-ye.length-5;return`${oe.substring(0,Math.max(10,be))}/.../${ye}`}const Ne=re-oe.length-ye.length-5;if(Ne>0&&ae.length>3){let Ce=ae.slice(2,-1).join("/");return Ce.length>Ne&&(Ce="..."),`${oe}/${Ce}/${ye}`}return`${oe}/.../${ye}`},fe=(O,re=0)=>{if(!O)return null;if(O.type==="folder"){const ae=B.has(O.path);return e.jsxs("div",{children:[e.jsxs("div",{className:"file-tree-item folder-item",onClick:()=>{const ye=new Set(B);ae?ye.delete(O.path):ye.add(O.path),T(ye)},style:{paddingLeft:`${re*16}px`},children:[e.jsx(St,{size:$.sm,className:`folder-toggle ${ae?"expanded":""}`}),e.jsx(Ps,{size:$.sm,className:"folder-icon"}),e.jsx("span",{className:"file-name",children:O.name})]}),ae&&O.children&&e.jsx("div",{children:O.children.map(ye=>fe(ye,re+1))})]},O.path)}else return e.jsxs("div",{className:`file-tree-item file-item ${U===O.path?"active":""}`,onClick:()=>v(O.path),style:{paddingLeft:`${re*16}px`},children:[e.jsx(Fs,{size:$.sm,className:"file-icon"}),e.jsx("span",{className:"file-name",children:O.name})]},O.path)};return e.jsxs("div",{className:"xcode-container",ref:t,children:[e.jsxs("div",{className:"xcode-toolbar",children:[e.jsxs("div",{className:"toolbar-left",children:[e.jsx("button",{className:"toolbar-btn toggle-sidebar",onClick:()=>A(!E),title:"切换侧栏",children:e.jsx(il,{size:$.md})}),e.jsxs("div",{className:"file-info",title:U,children:[e.jsx(ps,{size:$.sm}),e.jsx("span",{className:"file-name",children:Z(U||"untitled.js",80)})]})]}),e.jsxs("div",{className:"toolbar-right",children:[e.jsx("button",{className:"toolbar-btn",onClick:k,title:"保存",children:e.jsx(Qt,{size:$.md})}),e.jsx("button",{className:"toolbar-btn",onClick:ee,title:"清空",children:e.jsx(st,{size:$.md})}),e.jsx("button",{className:"toolbar-btn",title:"更多选项",children:e.jsx(ol,{size:$.md})})]})]}),e.jsxs("div",{className:"xcode-main",children:[E&&e.jsxs("div",{className:"xcode-sidebar",children:[e.jsxs("div",{className:"sidebar-header",children:[e.jsx(Ps,{size:$.md}),e.jsx("h3",{children:"文件浏览"})]}),e.jsx("div",{className:"file-tree",children:M?fe(M):e.jsxs("div",{className:"empty-state",style:{padding:"16px 8px"},children:[e.jsx(Fs,{size:24}),e.jsx("small",{children:"项目中未找到 .h / .m / .swift 文件"})]})})]}),e.jsxs("div",{className:"xcode-editor-wrapper",children:[e.jsx("div",{className:"xcode-editor",children:e.jsx(Vt,{value:c.content,onChange:O=>m(O,n.current),onCursorChange:P,language:"javascript",height:"100%",className:"w-full h-full",showLineNumbers:!0,placeholder:"// Start typing..."})}),e.jsxs("div",{className:"editor-status",children:[e.jsxs("span",{children:["Ln ",c.cursorLine+1,", Col ",c.cursorCol+1]}),e.jsx("span",{children:"|"}),e.jsxs("span",{children:[c.content.length," characters"]}),e.jsx("span",{children:"|"}),e.jsxs("span",{children:[c.content.split(`
|
|
124
|
+
`).length," lines"]})]})]}),e.jsxs("div",{className:"xcode-result-panel",children:[e.jsxs("div",{className:"result-section directives",children:[e.jsxs("div",{className:"section-header",children:[e.jsx(vs,{size:$.md}),e.jsx("h3",{children:"检测到的指令"}),e.jsx("span",{className:"count",children:i.length})]}),i.length===0?e.jsxs("div",{className:"empty-state",children:[e.jsx(Ke,{size:32}),e.jsx("p",{children:"暂无指令"}),e.jsx("small",{children:"在代码中添加 // as:search 来创建指令"})]}):e.jsx("div",{className:"directives-list",children:i.map((O,re)=>e.jsxs("div",{className:`directive-card ${O.type} ${S===re?"active":""}`,onClick:()=>q(re),children:[e.jsxs("div",{className:"directive-header",children:[e.jsx("div",{className:"type-badge",children:O.type.toUpperCase()}),e.jsxs("div",{className:"line-badge",children:["L",O.line+1]})]}),e.jsx("div",{className:"directive-query",children:O.query}),e.jsx("button",{className:"execute-btn",onClick:ae=>{ae.stopPropagation(),L(O)},disabled:p,children:p&&S===re?e.jsxs(e.Fragment,{children:[e.jsx(Te,{size:$.xs,className:"spin"}),"执行中..."]}):e.jsxs(e.Fragment,{children:[e.jsx(cl,{size:$.xs}),"执行"]})})]},re))})]}),j&&e.jsxs("div",{className:"result-section result",children:[e.jsxs("div",{className:"section-header",children:[e.jsx(xt,{size:$.md}),e.jsx("h3",{children:"执行结果"})]}),e.jsx("div",{className:"result-content",children:e.jsx("pre",{children:j})})]})]})]}),w&&e.jsx("div",{className:"result-modal-backdrop",onClick:()=>f(!1),children:e.jsxs("div",{className:"result-modal",onClick:O=>O.stopPropagation(),children:[e.jsxs("div",{className:"result-modal-header",children:[e.jsx("h2",{children:"执行结果"}),e.jsx("button",{className:"result-modal-close",onClick:()=>f(!1),children:"✕"})]}),e.jsx("div",{className:"result-modal-content",children:e.jsx("pre",{children:j})}),e.jsxs("div",{className:"result-modal-footer",children:[e.jsx("button",{className:"result-modal-btn",onClick:()=>{navigator.clipboard.writeText(j)},children:"复制"}),e.jsx("button",{className:"result-modal-btn",onClick:()=>f(!1),children:"关闭"})]})]})})]})},os={index:{icon:Je,color:"text-blue-600",label:"项目概述"},architecture:{icon:et,color:"text-violet-600",label:"架构总览"},"getting-started":{icon:mt,color:"text-emerald-600",label:"快速上手"},protocols:{icon:Ke,color:"text-amber-600",label:"协议与组件"},components:{icon:mt,color:"text-emerald-600",label:"组件清单"},patterns:{icon:Ke,color:"text-amber-600",label:"代码模式"},module:{icon:Tt,color:"text-cyan-600",label:"模块文档"},document:{icon:tt,color:"text-orange-600",label:"开发文档"},_index:{icon:Wt,color:"text-slate-500",label:"目录索引"}};function mn(t){var a;const s=((a=t.split("/").pop())==null?void 0:a.replace(".md",""))||"";return s==="_index"?os._index:t.startsWith("modules/")?os.module:t.startsWith("documents/")?os.document:os[s]||{icon:tt,color:"text-slate-500",label:"文档"}}const un={"cursor-devdocs":{label:"Cursor Docs",color:"text-orange-700",bg:"bg-orange-50 border-orange-200"}},pn={modules:"模块",documents:"开发文档"};function Ca(t){return t<1e3?`${t}ms`:`${(t/1e3).toFixed(1)}s`}function hn(t){if(!t)return"";const s=new Date(t);if(isNaN(s.getTime()))return"";const l=Date.now()-s.getTime();return l<6e4?"刚刚":l<36e5?`${Math.floor(l/6e4)} 分钟前`:l<864e5?`${Math.floor(l/36e5)} 小时前`:l<6048e5?`${Math.floor(l/864e5)} 天前`:s.toLocaleDateString("zh-CN")}const bn=({task:t,wiki:s})=>t.status==="running"?null:t.status==="error"?e.jsxs("div",{className:"bg-red-50 border border-red-200 rounded-xl p-4 mb-6 flex items-center gap-3",children:[e.jsx("div",{className:"p-1.5 bg-red-100 rounded-lg",children:e.jsx(Kt,{size:$.md,className:"text-red-600"})}),e.jsxs("div",{children:[e.jsx("span",{className:"font-semibold text-red-800",children:"生成失败"}),e.jsx("span",{className:"text-sm text-red-600 ml-3",children:t.error||"未知错误"})]})]}):s!=null&&s.exists&&s.hasChanges?e.jsxs("div",{className:"bg-amber-50 border border-amber-200 rounded-xl p-4 mb-6 flex items-center gap-3",children:[e.jsx("div",{className:"p-1.5 bg-amber-100 rounded-lg",children:e.jsx(Kt,{size:$.md,className:"text-amber-600"})}),e.jsx("span",{className:"text-sm text-amber-700",children:"检测到代码变更,Wiki 可能已过期,建议增量更新"})]}):null;function gn(t,s){const a=[],l=new Map((s==null?void 0:s.map(j=>[j.path,j]))||[]),n=[],c=new Map;for(const j of t){const g=j.path.split("/"),p=l.get(j.path);if(g.length===1)n.push({name:g[0],path:j.path,isDir:!1,file:j,metaInfo:p});else{const u=g[0];c.has(u)||c.set(u,[]),c.get(u).push({name:g.slice(1).join("/"),path:j.path,isDir:!1,file:j,metaInfo:p})}}const x=["index.md","architecture.md","getting-started.md","patterns.md","protocols.md","components.md"];n.sort((j,g)=>{const p=x.indexOf(j.name),u=x.indexOf(g.name);return p!==-1&&u!==-1?p-u:p!==-1?-1:u!==-1?1:j.name.localeCompare(g.name)}),a.push(...n);const i=["modules","patterns","documents"],N=[...c.entries()].sort(([j],[g])=>{const p=i.indexOf(j),u=i.indexOf(g);return p!==-1&&u!==-1?p-u:p!==-1?-1:u!==-1?1:j.localeCompare(g)});for(const[j,g]of N){const p=g.filter(u=>!u.name.startsWith("_index")).sort((u,w)=>u.name.localeCompare(w.name));a.push({name:j,path:j,isDir:!0,children:p})}return a}const fn=({tree:t,selectedFile:s,onSelect:a,searchQuery:l})=>{const[n,c]=r.useState(new Set(["modules","documents"])),x=j=>{c(g=>{const p=new Set(g);return p.has(j)?p.delete(j):p.add(j),p})},N=(j=>{if(!l)return j;const g=l.toLowerCase();return j.filter(p=>{var u;return p.isDir?(u=p.children)==null?void 0:u.some(w=>w.name.toLowerCase().includes(g)||w.path.toLowerCase().includes(g)):p.name.toLowerCase().includes(g)||p.path.toLowerCase().includes(g)})})(t);return e.jsx("div",{className:"space-y-0.5",children:N.map(j=>{var g;if(j.isDir){const p=n.has(j.path),u=l.toLowerCase(),w=l?(g=j.children)==null?void 0:g.filter(f=>f.name.toLowerCase().includes(u)||f.path.toLowerCase().includes(u)):j.children;return e.jsxs("div",{children:[e.jsxs("button",{onClick:()=>x(j.path),className:"w-full flex items-center gap-2 px-3 py-2 text-sm text-slate-600 hover:bg-slate-50 rounded-lg transition-colors",children:[p?e.jsx(St,{size:14,className:"text-slate-400 flex-shrink-0"}):e.jsx(at,{size:14,className:"text-slate-400 flex-shrink-0"}),e.jsx(Tt,{size:14,className:"text-amber-500 flex-shrink-0"}),e.jsx("span",{className:"font-medium truncate",children:pn[j.name]||j.name}),e.jsx("span",{className:"ml-auto text-xs text-slate-400",children:(w==null?void 0:w.length)||0})]}),p&&w&&e.jsx("div",{className:"ml-3",children:w.map(f=>e.jsx(sa,{node:f,isActive:s===f.path,onSelect:a},f.path))})]},j.path)}return e.jsx(sa,{node:j,isActive:s===j.path,onSelect:a},j.path)})})},sa=({node:t,isActive:s,onSelect:a})=>{var i,N;const l=mn(t.path),n=l.icon,c=(i=t.metaInfo)==null?void 0:i.polished,x=(N=t.metaInfo)==null?void 0:N.source;return e.jsxs("button",{onClick:()=>a(t.path),className:`w-full flex items-center gap-2 px-3 py-2 text-sm rounded-lg transition-all ${s?"bg-blue-50 text-blue-700 border border-blue-200 shadow-sm":"text-slate-600 hover:bg-slate-50"}`,children:[e.jsx(n,{size:14,className:`flex-shrink-0 ${s?"text-blue-500":l.color}`}),e.jsx("span",{className:"truncate text-left",children:t.name.replace(".md","")}),e.jsxs("span",{className:"ml-auto flex items-center gap-1 flex-shrink-0",children:[c&&e.jsx("span",{title:"AI 增强",children:e.jsx(Ke,{size:10,className:"text-violet-400"})}),x&&e.jsx("span",{title:`来源: ${x}`,children:e.jsx(xl,{size:10,className:"text-orange-400"})})]})]})},jn=({filePath:t,content:s,loading:a,meta:l,onBack:n})=>{var p;const[c,x]=r.useState(!1),i=(p=l==null?void 0:l.files)==null?void 0:p.find(u=>u.path===t),N=()=>{navigator.clipboard.writeText(s),x(!0),setTimeout(()=>x(!1),2e3)},j=t.split("/"),g=j.map((u,w)=>({label:w===j.length-1?u.replace(".md",""):u,isLast:w===j.length-1}));return e.jsxs("div",{className:"flex flex-col h-full",children:[e.jsxs("div",{className:"flex items-center justify-between px-5 py-3 bg-slate-50 border-b border-slate-200 flex-shrink-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{onClick:n,className:"p-1.5 hover:bg-slate-200 rounded-lg transition-colors lg:hidden",title:"返回文件列表",children:e.jsx(dl,{size:$.md})}),e.jsxs("div",{className:"flex items-center gap-1 text-sm",children:[e.jsx(Je,{size:14,className:"text-slate-400"}),e.jsx("span",{className:"text-slate-400",children:"wiki"}),g.map((u,w)=>e.jsxs(It.Fragment,{children:[e.jsx(at,{size:12,className:"text-slate-300"}),e.jsx("span",{className:u.isLast?"font-medium text-slate-700":"text-slate-400",children:u.label})]},w))]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[(i==null?void 0:i.polished)&&e.jsxs("span",{className:"flex items-center gap-1 text-xs text-violet-700 bg-violet-50 border border-violet-200 px-2 py-0.5 rounded-full",children:[e.jsx(Ke,{size:10}),"AI 增强"]}),(i==null?void 0:i.source)&&(()=>{const u=un[i.source];return e.jsx("span",{className:`flex items-center gap-1 text-xs border px-2 py-0.5 rounded-full ${(u==null?void 0:u.bg)||"bg-slate-50 border-slate-200"} ${(u==null?void 0:u.color)||"text-slate-600"}`,children:(u==null?void 0:u.label)||i.source})})(),e.jsxs("button",{onClick:N,className:"flex items-center gap-1 px-2.5 py-1 text-xs text-slate-500 hover:text-slate-700 hover:bg-slate-100 rounded-md transition-colors",children:[c?e.jsx(yt,{size:12,className:"text-emerald-500"}):e.jsx(Et,{size:12}),c?"已复制":"复制"]})]})]}),e.jsx("div",{className:"flex-1 overflow-auto scrollbar-light",children:a?e.jsx("div",{className:"flex items-center justify-center py-20",children:e.jsx(Te,{size:$.xl,className:"text-blue-500 animate-spin"})}):e.jsx("div",{className:"px-8 py-6 max-w-4xl mx-auto",children:e.jsx(ut,{content:s,className:"wiki-reader"})})})]})},Nn=()=>e.jsxs("div",{className:"h-72 flex flex-col items-center justify-center bg-white rounded-2xl border border-dashed border-slate-200 text-slate-400",children:[e.jsx("div",{className:"w-16 h-16 rounded-2xl bg-slate-50 flex items-center justify-center mb-4",children:e.jsx(Je,{size:32,className:"text-slate-300"})}),e.jsx("p",{className:"text-sm font-medium text-slate-500",children:"尚未生成 Repo Wiki"}),e.jsx("p",{className:"mt-2 text-xs max-w-sm text-center leading-relaxed text-slate-400",children:"Wiki 在冷启动时自动全量生成,后续通过增量更新保持同步"}),e.jsxs("p",{className:"mt-3 text-[11px] text-slate-400",children:["运行 ",e.jsx("code",{className:"text-blue-600 bg-blue-50 px-1 rounded",children:"asd setup"})," 冷启动 ·",e.jsx("code",{className:"text-blue-600 bg-blue-50 px-1 rounded ml-1",children:"asd wiki --update"})," 增量更新"]})]}),yn=({meta:t,onSelectFile:s,isGenerating:a,progress:l,message:n})=>{var N;const c=[{path:"index.md",label:"项目概述",desc:"项目信息、技术栈与数据统计",icon:Je,color:"bg-blue-50 text-blue-600 border-blue-200"},{path:"architecture.md",label:"架构总览",desc:"模块依赖图、SPM Target 结构",icon:et,color:"bg-violet-50 text-violet-600 border-violet-200"},{path:"getting-started.md",label:"快速上手",desc:"构建、运行与入口分析",icon:mt,color:"bg-emerald-50 text-emerald-600 border-emerald-200"},{path:"protocols.md",label:"协议与组件",desc:"核心协议、委托和组件关系",icon:Ke,color:"bg-amber-50 text-amber-600 border-amber-200"}],x=new Set(((N=t==null?void 0:t.files)==null?void 0:N.map(j=>j.path||j.name))??[]),i=c.filter(j=>x.size===0||x.has(j.path));return e.jsxs("div",{className:"p-8 overflow-y-auto flex-1",children:[a&&e.jsxs("div",{className:"mb-8 flex flex-col items-center",children:[e.jsxs("div",{className:"relative w-20 h-20 mb-5",children:[e.jsx("span",{className:"absolute inset-0 rounded-full bg-blue-100 animate-ping opacity-20"}),e.jsx("span",{className:"absolute inset-2 rounded-full bg-blue-50 animate-pulse"}),e.jsx("div",{className:"absolute inset-0 flex items-center justify-center",children:e.jsx($s,{size:36,className:"text-blue-500 animate-pulse"})})]}),e.jsx("h3",{className:"text-lg font-semibold text-slate-700 mb-1",children:"Wiki 正在生成中…"}),e.jsx("p",{className:"text-sm text-slate-500 max-w-md text-center leading-relaxed",children:n||"AI 正在分析项目结构并撰写文档,新文件会自动出现在左侧文件树中"}),typeof l=="number"&&e.jsxs("div",{className:"mt-4 w-48",children:[e.jsx("div",{className:"w-full bg-slate-100 rounded-full h-2",children:e.jsx("div",{className:"bg-gradient-to-r from-blue-500 to-indigo-500 h-2 rounded-full transition-all duration-700 ease-out",style:{width:`${Math.max(l,3)}%`}})}),e.jsxs("p",{className:"text-xs text-center text-blue-500 mt-1.5 font-mono",children:[l,"%"]})]})]}),!a&&e.jsxs("div",{className:"text-center mb-8",children:[e.jsx("div",{className:"w-12 h-12 bg-slate-100 rounded-xl flex items-center justify-center mx-auto mb-3",children:e.jsx(tt,{size:24,className:"text-slate-400"})}),e.jsx("h3",{className:"text-lg font-semibold text-slate-700",children:"选择一个文件开始阅读"}),e.jsx("p",{className:"text-sm text-slate-500 mt-1",children:"从左侧文件树选择,或使用下方快捷入口"})]}),e.jsx("div",{className:"grid grid-cols-2 gap-3 max-w-lg mx-auto",children:i.map(j=>{const g=j.icon;return e.jsxs("button",{onClick:()=>s(j.path),className:`text-left p-4 rounded-xl border ${j.color} hover:shadow-sm transition-all group`,children:[e.jsx(g,{size:20,className:"mb-2 opacity-70 group-hover:opacity-100"}),e.jsx("div",{className:"font-medium text-sm",children:j.label}),e.jsx("div",{className:"text-xs opacity-60 mt-0.5",children:j.desc})]},j.path)})}),t&&e.jsxs("div",{className:"mt-8 text-center text-xs text-slate-400",children:[t.generatedAt&&`最后生成: ${new Date(t.generatedAt).toLocaleString("zh-CN")}`,t.duration!=null&&` · 耗时 ${Ca(t.duration)}`,t.version&&` · v${t.version}`]})]})},vn=()=>{const[t,s]=r.useState({task:{status:"idle"}}),[a,l]=r.useState([]),[n,c]=r.useState(!1),[x,i]=r.useState(null),[N,j]=r.useState(""),[g,p]=r.useState(!1),[u,w]=r.useState(!0),[f,E]=r.useState(""),[A,M]=r.useState(null),R=r.useRef(null),B=r.useCallback(async()=>{try{const h=await Y.wikiStatus();return s(h),h}catch{return null}},[]),T=r.useCallback(async()=>{try{const h=await Y.wikiFiles();l(h.files||[]),c(h.exists)}catch{}},[]),U=r.useCallback(async()=>{try{const h=await Y.wikiFileContent("meta.json");h!=null&&h.content&&M(JSON.parse(h.content))}catch{}},[]);r.useEffect(()=>{(async()=>{w(!0),await Promise.all([B(),T(),U()]),w(!1)})()},[B,T,U]),r.useEffect(()=>{if(t.task.status==="running"){let h=0;R.current=setInterval(async()=>{const d=await B();h++,h%3===0&&await T(),d&&d.task.status!=="running"&&(await Promise.all([T(),U()]),R.current&&clearInterval(R.current))},1500)}else R.current&&clearInterval(R.current);return()=>{R.current&&clearInterval(R.current)}},[t.task.status,B,T,U]);const K=async()=>{try{await Y.wikiUpdate(),s(h=>({...h,task:{...h.task,status:"running",progress:0,message:"增量更新中..."}}))}catch(h){console.error("Wiki update failed:",h)}},S=async h=>{if(h!=="meta.json"){i(h),p(!0);try{const d=await Y.wikiFileContent(h);j(d.content)}catch{j(`# 加载失败
|
|
125
|
+
|
|
126
|
+
无法读取文件内容。`)}finally{p(!1)}}},q=()=>{i(null),j("")},C=r.useMemo(()=>a.filter(h=>h.path!=="meta.json"),[a]),m=r.useMemo(()=>gn(C,A==null?void 0:A.files),[C,A]);if(u)return e.jsx("div",{className:"flex items-center justify-center h-64",children:e.jsx(Te,{size:$.xl,className:"text-blue-500 animate-spin"})});const P=!n&&C.length===0&&t.task.status!=="running";return e.jsxs("div",{className:"h-full flex flex-col overflow-hidden p-6 pt-4",children:[e.jsx(bn,{task:t.task,wiki:t.wiki}),P?e.jsx(Nn,{}):e.jsxs(e.Fragment,{children:[t.task.status==="running"&&e.jsxs("div",{className:"mb-3 flex items-center gap-3 px-4 py-2.5 bg-gradient-to-r from-blue-50 to-indigo-50 border border-blue-200/70 rounded-xl shrink-0",children:[e.jsxs("div",{className:"relative flex items-center justify-center w-6 h-6",children:[e.jsx("span",{className:"absolute inline-flex h-full w-full rounded-full bg-blue-400 opacity-30 animate-ping"}),e.jsx(Te,{size:16,className:"text-blue-600 animate-spin relative"})]}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("span",{className:"text-sm font-medium text-blue-800",children:"Wiki 正在生成中"}),t.task.message&&e.jsx("span",{className:"text-xs text-blue-500 ml-2 truncate",children:t.task.message})]}),e.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0",children:[e.jsx("div",{className:"w-24 bg-blue-100 rounded-full h-1.5",children:e.jsx("div",{className:"bg-blue-500 h-1.5 rounded-full transition-all duration-700 ease-out",style:{width:`${Math.max(t.task.progress||0,3)}%`}})}),e.jsxs("span",{className:"text-xs font-mono text-blue-600 w-8 text-right",children:[t.task.progress||0,"%"]})]})]}),e.jsxs("div",{className:"flex gap-4 flex-1 min-h-0 overflow-hidden",children:[e.jsxs("div",{className:`w-64 flex-shrink-0 bg-white border border-slate-200 rounded-xl flex flex-col overflow-hidden ${x?"hidden lg:flex":""}`,children:[e.jsxs("div",{className:"px-3 pt-3 pb-2 border-b border-slate-100 shrink-0",children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Je,{size:16,className:"text-blue-500"}),e.jsx("span",{className:"text-sm font-semibold text-slate-700",children:"Wiki"}),(A==null?void 0:A.version)&&e.jsxs("span",{className:"text-[10px] text-slate-300",children:["v",A.version]})]}),e.jsxs("div",{className:"flex items-center gap-1",children:[n&&e.jsxs("span",{className:"text-[10px] text-slate-400",children:[C.length," 篇"]}),t.task.status!=="running"&&n&&e.jsx("button",{onClick:K,title:"增量更新",className:"p-1 rounded-md text-blue-500 hover:bg-blue-50 transition-colors",children:e.jsx(ht,{size:13})})]})]}),e.jsxs("div",{className:"relative",children:[e.jsx(xt,{size:14,className:"absolute left-3 top-1/2 -translate-y-1/2 text-slate-400"}),e.jsx("input",{type:"text",placeholder:"搜索文件...",value:f,onChange:h=>E(h.target.value),className:"w-full pl-8 pr-3 py-2 text-sm bg-slate-50 border border-slate-200 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-200 focus:border-blue-300 transition-all"})]})]}),e.jsxs("div",{className:"p-2 overflow-y-auto flex-1 min-h-0 scrollbar-light",children:[e.jsx(fn,{tree:m,selectedFile:x,onSelect:S,searchQuery:f}),t.task.status==="running"&&e.jsxs("div",{className:"mx-2 mt-3 mb-1 flex items-center gap-2 px-3 py-2 bg-blue-50 border border-blue-100 rounded-lg",children:[e.jsx(Te,{size:12,className:"text-blue-500 animate-spin flex-shrink-0"}),e.jsx("span",{className:"text-[11px] text-blue-600 leading-tight",children:"文件生成中,新文档将自动出现…"})]})]}),(A==null?void 0:A.generatedAt)&&e.jsx("div",{className:"px-3 py-2 border-t border-slate-100 shrink-0",children:e.jsxs("div",{className:"flex items-center gap-1.5 text-[10px] text-slate-400",children:[e.jsx(it,{size:10}),e.jsx("span",{children:hn(A.generatedAt)}),A.duration!=null&&e.jsxs("span",{children:["· ",Ca(A.duration)]})]})})]}),e.jsx("div",{className:`flex-1 bg-white border border-slate-200 rounded-xl overflow-hidden flex flex-col min-h-0 ${x?"":"hidden lg:flex"}`,children:x?e.jsx(jn,{filePath:x,content:N,loading:g,meta:A,onBack:q}):e.jsx(yn,{meta:A,onSelectFile:S,isGenerating:t.task.status==="running",progress:t.task.progress,message:t.task.message})})]})]})]})},wn={authority:0,guardUsageCount:0,humanUsageCount:0,aiUsageCount:0,lastUsedAt:null,authorityScore:0},kn=({editingRecipe:t,setEditingRecipe:s,handleSaveRecipe:a,closeRecipeEdit:l,isSavingRecipe:n=!1})=>{var p,u,w,f,E,A,M,R,B,T,U,K,S,q,C,m,P;const[c,x]=r.useState("preview"),i=r.useRef(!0);r.useEffect(()=>()=>{i.current=!1},[]);const N=(()=>{const h=(t.language||"").toLowerCase();return["objectivec","objc","objective-c","obj-c"].includes(h)?"objectivec":t.language||"swift"})(),j=async h=>{try{if(await Y.setRecipeAuthority(t.name,h),i.current){const d=t.stats?{...t.stats,authority:h}:{...wn,authority:h};s({...t,stats:d})}}catch(d){console.warn("设置权威分失败:",d==null?void 0:d.message)}},g=h=>{if(!h)return"";const d=typeof h=="string"?new Date(h).getTime():h;return isNaN(d)?"":new Date(d).toLocaleString("zh-CN",{year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit"})};return e.jsxs(Ve,{className:"z-40 flex items-center justify-center p-4",children:[e.jsx(Ve.Backdrop,{className:"bg-slate-900/50 backdrop-blur-sm"}),e.jsxs("div",{className:"relative bg-white w-full max-w-6xl rounded-2xl shadow-2xl flex flex-col h-[85vh]",children:[e.jsxs("div",{className:"p-6 border-b border-slate-100 flex justify-between items-center flex-wrap gap-4",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("h2",{className:"text-xl font-bold",children:"Edit Recipe"}),t.kind&&(()=>{const d={rule:{label:"Rule",color:"text-red-700",bg:"bg-red-50",border:"border-red-200",icon:nt},pattern:{label:"Pattern",color:"text-violet-700",bg:"bg-violet-50",border:"border-violet-200",icon:bt},fact:{label:"Fact",color:"text-cyan-700",bg:"bg-cyan-50",border:"border-cyan-200",icon:Je}}[t.kind];if(!d)return null;const v=d.icon;return e.jsxs("span",{className:`text-[10px] font-bold px-2 py-1 rounded uppercase flex items-center gap-1 border ${d.bg} ${d.color} ${d.border}`,children:[e.jsx(v,{size:$.sm}),d.label]})})(),t.status&&t.status!=="active"&&t.status!=="published"&&e.jsx("span",{className:`text-[10px] font-bold px-2 py-1 rounded uppercase border ${t.status==="draft"?"bg-slate-50 text-slate-500 border-slate-200":t.status==="archived"?"bg-orange-50 text-orange-600 border-orange-200":"bg-slate-50 text-slate-500 border-slate-200"}`,children:t.status})]}),e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-xs font-medium text-slate-500",children:"权威分"}),c==="preview"?e.jsx("span",{className:"text-sm text-slate-700",children:((p=t.stats)==null?void 0:p.authority)??3}):e.jsxs("select",{className:"font-bold text-amber-600 bg-amber-50 border border-amber-100 px-2 py-1 rounded-lg outline-none text-[10px] focus:ring-2 focus:ring-amber-500",value:((u=t.stats)==null?void 0:u.authority)??3,onChange:h=>j(parseInt(h.target.value)),children:[e.jsx("option",{value:"1",children:"⭐ 1 - Basic"}),e.jsx("option",{value:"2",children:"⭐⭐ 2 - Good"}),e.jsx("option",{value:"3",children:"⭐⭐⭐ 3 - Solid"}),e.jsx("option",{value:"4",children:"⭐⭐⭐⭐ 4 - Great"}),e.jsx("option",{value:"5",children:"⭐⭐⭐⭐⭐ 5 - Excellent"})]})]}),e.jsxs("div",{className:"flex bg-slate-100 p-1 rounded-lg mr-4",children:[e.jsxs("button",{onClick:()=>x("preview"),className:`px-4 py-1.5 rounded-md text-xs font-bold transition-all flex items-center gap-2 ${c==="preview"?"bg-white shadow-sm text-blue-600":"text-slate-400"}`,children:[e.jsx(Xt,{size:$.sm})," Preview"]}),e.jsxs("button",{onClick:()=>x("edit"),className:`px-4 py-1.5 rounded-md text-xs font-bold transition-all flex items-center gap-2 ${c==="edit"?"bg-white shadow-sm text-blue-600":"text-slate-400"}`,children:[e.jsx(jt,{size:$.sm})," Edit"]})]}),e.jsx("button",{onClick:l,className:"p-2 hover:bg-slate-100 rounded-full",children:e.jsx(Ye,{size:$.lg})})]})]}),e.jsx("div",{className:"p-6 space-y-4 flex-1 flex flex-col overflow-hidden",children:e.jsx("div",{className:"flex-1 flex flex-col min-h-0",children:c==="edit"?e.jsxs("div",{className:"flex-1 overflow-y-auto space-y-5 pr-1",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-bold text-slate-400 uppercase mb-1",children:"Path"}),e.jsx("input",{className:"w-full p-2 bg-slate-50 border border-slate-200 rounded-lg text-sm",value:t.name,onChange:h=>s({...t,name:h.target.value})})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-bold text-slate-400 uppercase mb-1",children:"描述"}),e.jsx("textarea",{className:"w-full px-3 py-2 text-sm border border-slate-200 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-300 resize-none",rows:2,value:t.description||"",onChange:h=>s({...t,description:h.target.value}),placeholder:"Recipe 摘要描述..."})]}),e.jsxs("div",{children:[e.jsxs("label",{className:"block text-xs font-bold text-slate-400 uppercase mb-1.5 flex items-center gap-1.5",children:[e.jsx(tt,{size:11,className:"text-blue-400"})," Markdown 文档"]}),e.jsx("div",{className:"border border-slate-200 rounded-lg overflow-hidden",style:{minHeight:180},children:e.jsx(Vt,{value:((w=t.content)==null?void 0:w.markdown)||"",onChange:h=>s({...t,content:{...t.content,markdown:h}}),language:"markdown",height:"180px",showLineNumbers:!0})})]}),e.jsxs("div",{children:[e.jsxs("label",{className:"block text-xs font-bold text-slate-400 uppercase mb-1.5 flex items-center gap-1.5",children:[e.jsx(Mt,{size:11,className:"text-emerald-500"})," 代码 / 标准用法"]}),e.jsx("div",{className:"border border-slate-200 rounded-lg overflow-hidden",style:{minHeight:180},children:e.jsx(Vt,{value:((f=t.content)==null?void 0:f.pattern)||"",onChange:h=>s({...t,content:{...t.content,pattern:h}}),language:N,height:"180px",showLineNumbers:!0})})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-bold text-slate-400 uppercase mb-1",children:"设计原理"}),e.jsx("textarea",{className:"w-full px-3 py-2 text-sm border border-slate-200 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-300 resize-y",rows:3,value:((E=t.content)==null?void 0:E.rationale)||"",onChange:h=>s({...t,content:{...t.content,rationale:h.target.value}}),placeholder:"为何采用此方案..."})]})]}):e.jsxs("div",{className:"flex-1 overflow-y-auto space-y-6 scrollbar-light",children:[(()=>{const h=[["trigger",t.trigger],["language",t.language],["category",t.category],["kind",t.kind],["knowledgeType",t.knowledgeType],["status",t.status],["complexity",t.complexity],["scope",t.scope],["source",t.source],["updatedAt",t.updatedAt?g(t.updatedAt):void 0]].filter(([,d])=>!!d);return h.length===0?null:e.jsxs("div",{className:"bg-slate-50 border border-slate-200 rounded-2xl p-6",children:[e.jsx("h3",{className:"text-[10px] font-bold text-slate-400 uppercase tracking-widest mb-4",children:"Recipe Metadata"}),e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-y-4 gap-x-8",children:h.map(([d,v])=>e.jsxs("div",{className:"flex flex-col",children:[e.jsx("span",{className:"text-[10px] text-slate-400 font-bold uppercase mb-1",children:d}),e.jsx("span",{className:"text-sm text-slate-700 break-all font-medium",children:v})]},d))})]})})(),t.description&&e.jsxs("div",{className:"bg-white rounded-2xl border border-slate-100 p-6",children:[e.jsx("label",{className:"text-[10px] font-bold text-slate-400 uppercase mb-2 block",children:"摘要"}),e.jsx("p",{className:"text-sm text-slate-600 leading-relaxed",children:t.description})]}),((A=t.content)==null?void 0:A.markdown)&&e.jsxs("div",{className:"bg-white rounded-2xl border border-blue-100 p-6",children:[e.jsxs("label",{className:"text-[10px] font-bold text-slate-400 uppercase mb-3 block flex items-center gap-1.5",children:[e.jsx(tt,{size:11,className:"text-blue-400"})," Markdown 文档"]}),e.jsx("div",{className:"bg-blue-50/30 border border-blue-100 rounded-xl p-4",children:e.jsx("div",{className:"markdown-body text-sm text-slate-700 leading-relaxed",children:e.jsx(ut,{content:t.content.markdown})})})]}),((M=t.content)==null?void 0:M.pattern)&&e.jsxs("div",{className:"bg-white rounded-2xl border border-emerald-100 p-6",children:[e.jsxs("label",{className:"text-[10px] font-bold text-slate-400 uppercase mb-3 block flex items-center gap-1.5",children:[e.jsx(Mt,{size:11,className:"text-emerald-500"})," 代码 / 标准用法"]}),e.jsx(rt,{code:t.content.pattern,language:N,showLineNumbers:!0})]}),((R=t.content)==null?void 0:R.rationale)&&e.jsxs("div",{className:"bg-white rounded-2xl border border-slate-100 p-6",children:[e.jsx("label",{className:"text-[10px] font-bold text-slate-400 uppercase mb-2 block",children:"设计原理"}),e.jsx("div",{className:"bg-slate-50 border border-slate-100 rounded-xl p-4",children:e.jsx("p",{className:"text-sm text-slate-600 leading-relaxed",children:t.content.rationale})})]}),((B=t.content)==null?void 0:B.steps)&&t.content.steps.length>0&&e.jsxs("div",{className:"bg-white rounded-2xl border border-slate-100 p-6",children:[e.jsx("label",{className:"text-[10px] font-bold text-slate-400 uppercase mb-2 block",children:"实施步骤"}),e.jsx("div",{className:"space-y-2",children:t.content.steps.map((h,d)=>typeof h=="string"?e.jsxs("div",{className:"bg-slate-50 rounded-lg p-3 border border-slate-100 flex items-start gap-2.5",children:[e.jsx("span",{className:"text-[10px] font-bold text-blue-600 bg-blue-50 rounded-full w-5 h-5 flex items-center justify-center shrink-0 mt-0.5",children:d+1}),e.jsx("p",{className:"text-xs text-slate-700 leading-relaxed",children:h})]},d):e.jsxs("div",{className:"bg-slate-50 rounded-lg p-3 border border-slate-100",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[e.jsx("span",{className:"text-[10px] font-bold text-blue-600 bg-blue-50 rounded-full w-5 h-5 flex items-center justify-center shrink-0",children:d+1}),h.title&&e.jsx("span",{className:"text-xs font-bold text-slate-700",children:h.title})]}),h.description&&e.jsx("p",{className:"text-xs text-slate-600 ml-7 leading-relaxed",children:h.description}),h.code&&e.jsx("pre",{className:"text-[11px] font-mono bg-slate-800 text-green-300 p-2.5 rounded-md mt-1.5 ml-7 overflow-x-auto whitespace-pre-wrap",children:h.code})]},d))})]}),((T=t.content)==null?void 0:T.codeChanges)&&t.content.codeChanges.length>0&&e.jsxs("div",{className:"bg-white rounded-2xl border border-slate-100 p-6",children:[e.jsx("label",{className:"text-[10px] font-bold text-slate-400 uppercase mb-2 block",children:"代码变更"}),e.jsx("div",{className:"space-y-2",children:t.content.codeChanges.map((h,d)=>e.jsxs("div",{className:"border border-slate-200 rounded-lg overflow-hidden",children:[e.jsxs("div",{className:"px-3 py-1.5 bg-slate-50 border-b border-slate-200 flex items-center gap-2",children:[e.jsx(mt,{size:11,className:"text-blue-400"}),e.jsx("code",{className:"text-[10px] font-mono text-slate-600",children:h.file})]}),h.explanation&&e.jsx("p",{className:"text-[11px] text-slate-500 px-3 py-1.5 border-b border-slate-100 bg-yellow-50/30",children:h.explanation}),e.jsxs("div",{className:"p-2 bg-red-50/20 border-b border-slate-100",children:[e.jsx("div",{className:"text-[9px] font-bold text-red-400 mb-0.5 uppercase",children:"Before"}),e.jsx("pre",{className:"text-[11px] text-slate-600 whitespace-pre-wrap break-words font-mono",children:h.before||"(空)"})]}),e.jsxs("div",{className:"p-2 bg-emerald-50/20",children:[e.jsx("div",{className:"text-[9px] font-bold text-emerald-500 mb-0.5 uppercase",children:"After"}),e.jsx("pre",{className:"text-[11px] text-slate-700 whitespace-pre-wrap break-words font-mono",children:h.after})]})]},d))})]}),((U=t.content)==null?void 0:U.verification)&&e.jsxs("div",{className:"bg-white rounded-2xl border border-teal-100 p-6",children:[e.jsx("label",{className:"text-[10px] font-bold text-slate-400 uppercase mb-2 block",children:"验证方法"}),e.jsxs("div",{className:"bg-teal-50/50 border border-teal-100 rounded-xl p-4 space-y-1.5",children:[t.content.verification.method&&e.jsxs("p",{className:"text-xs text-slate-600",children:[e.jsx("span",{className:"font-bold text-teal-600",children:"方法:"})," ",t.content.verification.method]}),t.content.verification.expectedResult&&e.jsxs("p",{className:"text-xs text-slate-600",children:[e.jsx("span",{className:"font-bold text-teal-600",children:"预期:"})," ",t.content.verification.expectedResult]}),t.content.verification.testCode&&e.jsx("pre",{className:"text-[11px] font-mono bg-slate-800 text-green-300 p-2.5 rounded-md overflow-x-auto whitespace-pre-wrap mt-1",children:t.content.verification.testCode})]})]}),t.tags&&t.tags.length>0&&e.jsxs("div",{className:"bg-slate-50 border border-slate-200 rounded-2xl p-6",children:[e.jsxs("h3",{className:"text-[10px] font-bold text-slate-400 uppercase tracking-widest mb-3 flex items-center gap-1.5",children:[e.jsx(Ut,{size:11,className:"text-blue-400"})," 标签"]}),e.jsx("div",{className:"flex flex-wrap gap-1.5",children:t.tags.map((h,d)=>e.jsx("span",{className:"px-2.5 py-1 bg-blue-50 text-blue-700 border border-blue-100 rounded-full text-xs font-medium",children:h},d))})]}),!!(t.constraints&&((K=t.constraints.guards)!=null&&K.length||(S=t.constraints.boundaries)!=null&&S.length||(q=t.constraints.preconditions)!=null&&q.length||(C=t.constraints.sideEffects)!=null&&C.length))&&e.jsxs("div",{className:"bg-slate-50 border border-slate-200 rounded-2xl p-6 space-y-4",children:[e.jsxs("h3",{className:"text-[10px] font-bold text-slate-400 uppercase tracking-widest flex items-center gap-1.5",children:[e.jsx(nt,{size:11,className:"text-amber-500"})," 约束条件"]}),t.constraints.guards&&t.constraints.guards.length>0&&e.jsxs("div",{children:[e.jsx("span",{className:"text-xs font-semibold text-slate-500 block mb-1.5",children:"Guard 规则"}),e.jsx("ul",{className:"text-sm text-slate-600 space-y-1",children:t.constraints.guards.map((h,d)=>e.jsxs("li",{className:"flex gap-2 items-start",children:[e.jsx("span",{className:`text-xs mt-0.5 ${h.severity==="error"?"text-red-500":"text-yellow-500"}`,children:"●"}),e.jsx("code",{className:"font-mono text-xs bg-slate-100 px-1.5 py-0.5 rounded",children:h.pattern}),h.message&&e.jsxs("span",{className:"text-xs text-slate-400",children:["— ",h.message]})]},d))})]}),t.constraints.boundaries&&t.constraints.boundaries.length>0&&e.jsxs("div",{children:[e.jsx("span",{className:"text-xs font-semibold text-slate-500 block mb-1.5",children:"边界约束"}),e.jsx("ul",{className:"text-sm text-slate-600 space-y-1",children:t.constraints.boundaries.map((h,d)=>e.jsxs("li",{className:"flex gap-2",children:[e.jsx("span",{className:"text-orange-400",children:"●"}),h]},d))})]}),t.constraints.preconditions&&t.constraints.preconditions.length>0&&e.jsxs("div",{children:[e.jsx("span",{className:"text-xs font-semibold text-slate-500 block mb-1.5",children:"前置条件"}),e.jsx("ul",{className:"text-sm text-slate-600 space-y-1",children:t.constraints.preconditions.map((h,d)=>e.jsxs("li",{className:"flex gap-2",children:[e.jsx("span",{className:"text-blue-400",children:"◆"}),h]},d))})]}),t.constraints.sideEffects&&t.constraints.sideEffects.length>0&&e.jsxs("div",{children:[e.jsx("span",{className:"text-xs font-semibold text-slate-500 block mb-1.5",children:"副作用"}),e.jsx("ul",{className:"text-sm text-slate-600 space-y-1",children:t.constraints.sideEffects.map((h,d)=>e.jsxs("li",{className:"flex gap-2",children:[e.jsx("span",{className:"text-pink-400",children:"⚡"}),h]},d))})]})]}),t.relations&&Object.entries(t.relations).some(([,h])=>Array.isArray(h)&&h.length>0)&&e.jsxs("div",{className:"bg-slate-50 border border-slate-200 rounded-2xl p-6",children:[e.jsx("h3",{className:"text-[10px] font-bold text-slate-400 uppercase tracking-widest mb-4",children:"关系图 (Relations)"}),e.jsx("div",{className:"space-y-2",children:[{key:"inherits",label:"继承",color:"text-green-600",icon:"↑"},{key:"implements",label:"实现",color:"text-blue-600",icon:"◇"},{key:"calls",label:"调用",color:"text-cyan-600",icon:"→"},{key:"dependsOn",label:"依赖",color:"text-yellow-600",icon:"⊕"},{key:"dataFlow",label:"数据流",color:"text-purple-600",icon:"⇢"},{key:"conflicts",label:"冲突",color:"text-red-600",icon:"✕"},{key:"extends",label:"扩展",color:"text-teal-600",icon:"⊃"},{key:"related",label:"关联",color:"text-slate-500",icon:"∼"}].map(({key:h,label:d,color:v,icon:k})=>{var L;const ee=(L=t.relations)==null?void 0:L[h];return!ee||!Array.isArray(ee)||ee.length===0?null:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsxs("span",{className:`text-xs font-mono ${v} w-16 shrink-0 pt-0.5`,children:[k," ",d]}),e.jsx("div",{className:"flex flex-wrap gap-1.5",children:ee.map((Z,fe)=>e.jsx("span",{className:"px-2 py-0.5 bg-white border border-slate-200 text-slate-600 rounded-lg text-xs font-mono",children:typeof Z=="string"?Z:Z.id||Z.title||JSON.stringify(Z)},fe))})]},h)})})]}),!((m=t.content)!=null&&m.markdown)&&!((P=t.content)!=null&&P.pattern)&&!t.description&&e.jsx("div",{className:"bg-white p-8 rounded-2xl border border-slate-100 shadow-sm min-h-[200px] flex items-center justify-center",children:e.jsx("div",{className:"text-slate-300 italic",children:"No content"})})]})})}),e.jsxs("div",{className:"p-6 border-t border-slate-100 flex justify-end gap-3",children:[e.jsx("button",{onClick:l,disabled:n,className:"px-4 py-2 text-slate-600 font-medium disabled:opacity-50",children:"Cancel"}),e.jsxs("button",{onClick:a,disabled:n,className:"px-6 py-2 bg-blue-600 text-white rounded-lg font-medium flex items-center gap-2 hover:bg-blue-700 disabled:opacity-60 disabled:cursor-not-allowed",children:[n?e.jsx(Te,{size:$.lg,className:"animate-spin"}):e.jsx(Qt,{size:$.lg}),n?"保存中...":"Save Changes"]})]})]})]})},Cn=({setShowCreateModal:t,createPath:s,setCreatePath:a,handleCreateFromPath:l,handleCreateFromClipboard:n,isExtracting:c})=>e.jsxs(Ve,{className:"z-40 flex items-center justify-center p-4",children:[e.jsx(Ve.Backdrop,{className:"bg-slate-900/50 backdrop-blur-sm"}),e.jsxs("div",{className:"relative bg-white w-full max-w-lg rounded-2xl shadow-2xl overflow-hidden",children:[e.jsxs("div",{className:"p-6 border-b border-slate-100 flex justify-between items-center bg-slate-50",children:[e.jsxs("h2",{className:"text-xl font-bold flex items-center gap-2 text-slate-800",children:[e.jsx(Nt,{size:$.xl,className:"text-blue-600"})," New Recipe"]}),e.jsx("button",{onClick:()=>t(!1),className:"p-2 hover:bg-white rounded-full transition-colors",children:e.jsx(Ye,{size:$.lg})})]}),e.jsxs("div",{className:"p-8 space-y-6",children:[e.jsxs("div",{className:"space-y-3",children:[e.jsxs("label",{className:"flex items-center gap-2 text-xs font-bold text-slate-400 uppercase tracking-widest",children:[e.jsx(ma,{size:$.sm})," Import from Project Path"]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("input",{className:"flex-1 p-3 bg-slate-100 border-none rounded-xl text-sm outline-none focus:ring-2 focus:ring-blue-500",placeholder:"e.g. Sources/MyModule/Auth.swift",value:s,onChange:x=>a(x.target.value)}),e.jsx("button",{onClick:l,disabled:!s||c,className:"bg-slate-900 text-white px-4 py-2 rounded-xl text-sm font-bold hover:bg-slate-800 disabled:opacity-50",children:"Scan File"})]})]}),e.jsxs("div",{className:"relative",children:[e.jsx("div",{className:"absolute inset-0 flex items-center",children:e.jsx("div",{className:"w-full border-t border-slate-100"})}),e.jsx("div",{className:"relative flex justify-center text-xs uppercase",children:e.jsx("span",{className:"bg-white px-2 text-slate-300 font-bold",children:"Or"})})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("label",{className:"flex items-center gap-2 text-xs font-bold text-slate-400 uppercase tracking-widest",children:[e.jsx(ml,{size:$.sm})," Import from Clipboard"]}),e.jsxs("button",{onClick:()=>n(),disabled:c,className:"w-full flex items-center justify-center gap-3 p-4 bg-blue-50 text-blue-700 rounded-xl font-bold hover:bg-blue-100 transition-all border border-blue-100",children:[e.jsx(Qe,{size:$.lg})," Use Copied Code"]})]})]}),c&&e.jsxs("div",{className:"bg-blue-600 text-white p-4 flex items-center justify-center gap-3 animate-pulse",children:[e.jsx(Jt,{size:$.lg,className:"animate-spin"}),e.jsx("span",{className:"font-bold text-sm",children:"AI is thinking..."})]})]})]});function Sn(t){if(!t)return"";if(typeof t=="object"){const n=t.code||t.pattern||t.markdown||t.snippet||t.body||"";if(n)return n}const a=(typeof t=="string"?t:JSON.stringify(t)).replace(/^---[\s\S]*?---\s*\n?/,"").trim(),l=a.match(/```[\w]*\n([\s\S]*?)```/);return l&&l[1]?l[1].trim():a.slice(0,8e3)}const In=({searchQ:t,insertPath:s,onClose:a})=>{const[l,n]=r.useState([]),[c,x]=r.useState(!0),[i,N]=r.useState(null),j=r.useRef(!0),g=r.useRef(null);r.useEffect(()=>(j.current=!0,g.current=new AbortController,Y.search(t||"",{mode:"bm25",type:"recipe",signal:g.current.signal}).then(u=>{j.current&&n((u.items||[]).map(w=>({name:(w.title||w.name||"")+".md",path:"",content:w.content,qualityScore:(w.quality||{}).overall||w.qualityScore||0,recommendReason:""})))}).catch(u=>{u.name!=="AbortError"&&j.current&&n([])}).finally(()=>{j.current&&x(!1)}),()=>{j.current=!1,g.current&&g.current.abort()}),[t]);const p=async u=>{N(u.name);try{const w=Sn(u.content);await Y.insertAtSearchMark({path:s,content:w}),j.current&&(alert("✅ 已插入到 "+s),a())}catch{j.current&&alert("❌ 插入失败")}finally{j.current&&N(null)}};return e.jsxs(Ve,{className:"z-40 flex items-center justify-center p-4",children:[e.jsx(Ve.Backdrop,{className:"bg-slate-900/50 backdrop-blur-sm"}),e.jsxs("div",{className:"relative bg-white w-full max-w-2xl rounded-2xl shadow-2xl overflow-hidden flex flex-col max-h-[85vh]",children:[e.jsxs("div",{className:"p-6 border-b border-slate-100 flex justify-between items-center bg-slate-50",children:[e.jsxs("h2",{className:"text-xl font-bold flex items-center gap-2 text-slate-800",children:[e.jsx(xt,{size:$.xl,className:"text-blue-600"})," as:search — 选择并插入"]}),e.jsx("button",{onClick:a,className:"p-2 hover:bg-white rounded-full transition-colors",children:e.jsx(Ye,{size:$.lg})})]}),e.jsxs("div",{className:"p-4 text-sm text-slate-500 border-b border-slate-100",children:["关键词: ",t||"(全部)"," · 插入到: ",s]}),e.jsx("div",{className:"flex-1 overflow-y-auto p-4",children:c?e.jsx("div",{className:"flex items-center justify-center py-12",children:e.jsx("div",{className:"animate-spin rounded-full h-8 w-8 border-b-2 border-blue-600"})}):l.length===0?e.jsx("div",{className:"text-slate-500 text-center py-8",children:"未找到匹配的 Recipe"}):e.jsx("ul",{className:"space-y-2",children:l.map(u=>e.jsx("li",{children:e.jsxs("button",{type:"button",onClick:()=>p(u),disabled:i!==null,className:"w-full flex items-center justify-between gap-3 p-4 rounded-xl border border-slate-200 hover:border-blue-300 hover:bg-blue-50/50 transition-all text-left disabled:opacity-50",children:[e.jsxs("div",{className:"flex-1 flex flex-col gap-1",children:[e.jsx("span",{className:"font-medium text-slate-800 truncate",children:u.name}),(u.qualityScore!==void 0||u.recommendReason)&&e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[u.qualityScore!==void 0&&e.jsxs("span",{className:"inline-flex items-center gap-1 px-2 py-0.5 bg-blue-100 rounded text-xs text-blue-700 font-medium",children:["🤖 质量: ",(u.qualityScore*100).toFixed(0),"%"]}),u.recommendReason&&e.jsx("span",{className:"text-xs text-slate-600 italic truncate max-w-xs",children:u.recommendReason})]})]}),i===u.name?e.jsxs("span",{className:"text-blue-600 text-sm flex items-center gap-1",children:[e.jsx("span",{className:"animate-spin",children:"⏳"})," 插入中..."]}):e.jsxs("span",{className:"text-blue-600 text-sm flex items-center gap-1",children:[e.jsx(ua,{size:$.md})," 插入"]})]})},u.name))})})]})]})},Ns=[{id:"google",label:"Google Gemini",defaultModel:"gemini-2.0-flash",keyEnv:"ASD_GOOGLE_API_KEY"},{id:"openai",label:"OpenAI",defaultModel:"gpt-4o",keyEnv:"ASD_OPENAI_API_KEY"},{id:"deepseek",label:"DeepSeek",defaultModel:"deepseek-chat",keyEnv:"ASD_DEEPSEEK_API_KEY"},{id:"claude",label:"Claude",defaultModel:"claude-3-5-sonnet-20240620",keyEnv:"ASD_CLAUDE_API_KEY"},{id:"ollama",label:"Ollama (本地)",defaultModel:"llama3",keyEnv:""}],zn=({onClose:t,onSaved:s})=>{const[a,l]=r.useState(!0),[n,c]=r.useState(!1),[x,i]=r.useState(!1),[N,j]=r.useState("google"),[g,p]=r.useState("gemini-2.0-flash"),[u,w]=r.useState(""),[f,E]=r.useState(""),[A,M]=r.useState(!1),[R,B]=r.useState({}),[T,U]=r.useState(!1);r.useEffect(()=>{K()},[]);const K=async()=>{l(!0);try{const d=await Y.getLlmEnvConfig();i(d.hasEnvFile);const v=d.vars||{};v.ASD_AI_PROVIDER&&j(v.ASD_AI_PROVIDER),v.ASD_AI_MODEL&&p(v.ASD_AI_MODEL),v.ASD_AI_PROXY&&E(v.ASD_AI_PROXY),B(v)}catch{}finally{l(!1)}},S=Ns.find(d=>d.id===N),q=(S==null?void 0:S.keyEnv)||"",C=q?!!R[q]:!0,m=d=>{j(d);const v=Ns.find(k=>k.id===d);v&&p(v.defaultModel),w("")},P=async()=>{if(N){if(q&&!C&&!u.trim()){alert("请填写 API Key");return}c(!0),U(!1);try{await Y.saveLlmEnvConfig({provider:N,model:g||void 0,apiKey:u.trim()||void 0,proxy:f.trim()||void 0}),U(!0),setTimeout(()=>{s(),t()},800)}catch(d){alert((d==null?void 0:d.message)||"保存失败")}finally{c(!1)}}},h=d=>!d||d.length<10?d?"••••••":"":`${d.slice(0,6)}••••${d.slice(-4)}`;return e.jsx("div",{className:"fixed inset-0 bg-black/40 flex items-center justify-center z-50",onClick:t,children:e.jsxs("div",{className:"bg-white rounded-2xl shadow-2xl w-full max-w-lg mx-4 overflow-hidden",onClick:d=>d.stopPropagation(),children:[e.jsxs("div",{className:"flex items-center justify-between px-6 py-4 border-b border-slate-100",children:[e.jsx("h2",{className:"text-lg font-semibold text-slate-800",children:"LLM 配置"}),e.jsx("button",{onClick:t,className:"p-1 rounded-lg hover:bg-slate-100 transition-colors",children:e.jsx(Ye,{size:$.md,className:"text-slate-400"})})]}),e.jsx("div",{className:"px-6 py-5 space-y-5",children:a?e.jsx("div",{className:"flex items-center justify-center py-12",children:e.jsx(Te,{size:24,className:"animate-spin text-blue-500"})}):e.jsxs(e.Fragment,{children:[!x&&e.jsxs("div",{className:"flex items-start gap-2 p-3 bg-amber-50 border border-amber-200 rounded-lg text-sm text-amber-700",children:[e.jsx(At,{size:16,className:"mt-0.5 shrink-0"}),e.jsx("span",{children:"项目尚未配置 .env 文件,保存后将自动创建。"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-slate-700 mb-2",children:"AI Provider"}),e.jsx("div",{className:"grid grid-cols-2 sm:grid-cols-3 gap-2",children:Ns.map(d=>e.jsx("button",{type:"button",onClick:()=>m(d.id),className:`px-3 py-2 rounded-lg text-sm font-medium border transition-all ${N===d.id?"bg-blue-50 border-blue-300 text-blue-700 ring-1 ring-blue-200":"bg-white border-slate-200 text-slate-600 hover:border-slate-300 hover:bg-slate-50"}`,children:d.label},d.id))})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-slate-700 mb-1.5",children:"Model"}),e.jsx("input",{type:"text",value:g,onChange:d=>p(d.target.value),placeholder:(S==null?void 0:S.defaultModel)||"",className:"w-full px-3 py-2 border border-slate-200 rounded-lg text-sm focus:outline-none focus:ring-2 focus:ring-blue-500/20 focus:border-blue-300"})]}),q&&e.jsxs("div",{children:[e.jsxs("label",{className:"block text-sm font-medium text-slate-700 mb-1.5",children:["API Key",C&&e.jsxs("span",{className:"ml-2 text-xs text-green-600 font-normal",children:["(已配置: ",h(R[q]),")"]})]}),e.jsxs("div",{className:"relative",children:[e.jsx("input",{type:A?"text":"password",value:u,onChange:d=>w(d.target.value),placeholder:C?"留空保持当前 Key 不变":"请输入 API Key",className:"w-full px-3 py-2 pr-10 border border-slate-200 rounded-lg text-sm focus:outline-none focus:ring-2 focus:ring-blue-500/20 focus:border-blue-300"}),e.jsx("button",{type:"button",onClick:()=>M(d=>!d),className:"absolute right-2 top-1/2 -translate-y-1/2 p-1 text-slate-400 hover:text-slate-600",children:A?e.jsx(ul,{size:16}):e.jsx(Xt,{size:16})})]})]}),e.jsxs("div",{children:[e.jsxs("label",{className:"block text-sm font-medium text-slate-700 mb-1.5",children:["代理 ",e.jsx("span",{className:"text-xs text-slate-400 font-normal",children:"(可选)"})]}),e.jsx("input",{type:"text",value:f,onChange:d=>E(d.target.value),placeholder:"http://127.0.0.1:7890",className:"w-full px-3 py-2 border border-slate-200 rounded-lg text-sm focus:outline-none focus:ring-2 focus:ring-blue-500/20 focus:border-blue-300"})]})]})}),e.jsxs("div",{className:"flex items-center justify-end gap-3 px-6 py-4 border-t border-slate-100 bg-slate-50/50",children:[e.jsx("button",{onClick:t,className:"px-4 py-2 text-sm font-medium text-slate-600 hover:text-slate-800 transition-colors",children:"取消"}),e.jsxs("button",{onClick:P,disabled:n||a||T,className:`flex items-center gap-2 px-5 py-2 rounded-lg text-sm font-medium transition-all ${T?"bg-green-500 text-white":"bg-blue-600 text-white hover:bg-blue-700 shadow-sm"} disabled:opacity-60`,children:[n?e.jsx(Te,{size:16,className:"animate-spin"}):T?e.jsx(es,{size:16}):e.jsx(Qt,{size:16}),T?"已保存":"保存到 .env"]})]})]})})};class $n extends It.Component{constructor(s){super(s),this.state={hasError:!1,error:null}}static getDerivedStateFromError(s){return{hasError:!0,error:s}}render(){var s;return this.state.hasError?e.jsxs("div",{style:{padding:40,textAlign:"center"},children:[e.jsx("h2",{style:{color:"#ef4444",marginBottom:12},children:"页面出现异常"}),e.jsx("pre",{style:{fontSize:12,color:"#64748b",whiteSpace:"pre-wrap",maxWidth:600,margin:"0 auto"},children:(s=this.state.error)==null?void 0:s.message}),e.jsx("button",{onClick:()=>{this.setState({hasError:!1,error:null}),window.location.reload()},style:{marginTop:16,padding:"8px 20px",background:"#3b82f6",color:"#fff",border:"none",borderRadius:8,cursor:"pointer"},children:"刷新页面"})]}):this.props.children}}function Ot(t,s="ai-scan"){return{title:t.title||"",description:t.description||"",trigger:t.trigger||"",language:t.language||"",category:t.category||"",tags:t.tags||[],kind:t.kind||"",knowledgeType:t.knowledgeType||"",scope:t.scope||"",complexity:t.complexity||"",difficulty:t.difficulty||"",authority:t.authority,lifecycle:t.lifecycle||"pending",source:t.source||s,doClause:t.doClause||"",dontClause:t.dontClause||"",whenClause:t.whenClause||"",topicHint:t.topicHint||"",coreCode:t.coreCode||"",content:t.content||{},constraints:t.constraints||{},reasoning:t.reasoning||{},quality:t.quality||{},stats:t.stats||{},relations:t.relations||{},headers:t.headers||[],headerPaths:t.headerPaths,moduleName:t.moduleName,includeHeaders:t.includeHeaders,createdAt:t.createdAt,updatedAt:t.updatedAt}}const An=()=>{var Ge,_e;const t=Tl(),s=Rl((Ge=t.user)==null?void 0:Ge.role),a=Dl(),l=()=>{const z=window.location.pathname.replace(/^\//,"").split("/")[0]||"";return kl.includes(z)?z:"help"},[n,c]=r.useState(null),[x,i]=r.useState(l()),[N,j]=r.useState(!1),[g,p]=r.useState(""),[u,w]=r.useState(!0),[f,E]=r.useState(null),[A,M]=r.useState([]),[R,B]=r.useState(null),[T,U]=r.useState(!1),[K,S]=r.useState({current:0,total:0,status:""}),[q,C]=r.useState([]),[m,P]=r.useState([]),[h,d]=r.useState(null),[v,k]=r.useState("All"),[ee,L]=r.useState(1),[Z,fe]=r.useState(12),[O,re]=r.useState(!1),[ae,ye]=r.useState(""),[oe,Ne]=r.useState(!1),[be,Ce]=r.useState(null),[Ae,Fe]=r.useState(null),[_,I]=r.useState(!1),[le,we]=r.useState(!0),[ge,Me]=r.useState(!1),[Oe,Ee]=r.useState(0),y=r.useRef(null);r.useEffect(()=>{L(1)},[g,v]);const de=()=>{y.current&&y.current.abort()};r.useEffect(()=>{let z=!1;const ne=async()=>{var he,ie,$e;try{const ve=await Y.getSignalStatus();if(!z){const ke=((he=ve==null?void 0:ve.suggestions)==null?void 0:he.length)||0,Ie=(($e=(ie=ve==null?void 0:ve.snapshot)==null?void 0:ie.lastResult)==null?void 0:$e.newSuggestions)||0;Ee(ke||Ie)}}catch{}};ne();const X=setInterval(ne,300*1e3);return()=>{z=!0,clearInterval(X)}},[]),r.useEffect(()=>{a.isAllDone&&o()},[a.isAllDone]);const ce=(z,ne)=>{i(z);const X=ne!=null&&ne.preserveSearch&&window.location.search?window.location.search:"";window.history.pushState({},document.title,`/${z}${X}`)},te=z=>{E(z),i("recipes");const ne=new URLSearchParams(window.location.search);ne.set("edit",encodeURIComponent(z.name)),window.history.pushState({},document.title,`/recipes?${ne.toString()}`)},pe=()=>{E(null),window.history.replaceState({},document.title,"/recipes")};r.useEffect(()=>{g===""&&Ce(null)},[g]),r.useEffect(()=>{i(l())},[]),r.useEffect(()=>{if(!n)return;const z=window.location.pathname.replace(/^\//,"").split("/")[0],X=new URLSearchParams(window.location.search).get("edit");if(z==="recipes"&&X&&n.recipes)try{const he=decodeURIComponent(X),ie=n.recipes.find($e=>$e.name===he);ie&&!f&&(i("recipes"),te(ie))}catch{}},[n]),r.useEffect(()=>{o(),F(),b();const z=()=>{i(l())};window.addEventListener("popstate",z);const ne=new URLSearchParams(window.location.search),X=ne.get("action"),he=ne.get("path"),ie=ne.get("q")||"";return X==="search"&&he?Fe({q:ie,path:he}):X==="create"&&he&&(ye(he),re(!0),ne.get("autoScan")==="1"&&setTimeout(()=>se(he),500)),X&&window.history.replaceState({},document.title,window.location.pathname),()=>{window.removeEventListener("popstate",z)}},[]);const o=async()=>{w(!0);try{const z=await Y.fetchData();c(z)}catch(z){V((z==null?void 0:z.message)||"无法加载项目数据",{title:"加载失败",type:"error"})}finally{w(!1)}},F=async()=>{try{const z=await Y.fetchTargets();M(z)}catch(z){console.warn("删除候选残留失败:",z==null?void 0:z.message)}},b=async()=>{try{const z=await Y.getLlmEnvConfig();we(z.llmReady)}catch{}},xe=async()=>{try{await Y.syncToXcode(),V("Recipes 已同步到 Xcode CodeSnippets 目录",{title:"Xcode 同步成功"})}catch{V("请检查 Xcode 是否已安装并重试",{title:"同步失败",type:"error"})}},H=async()=>{try{await Y.refreshProject(),F(),V("Target 列表与文件树已更新",{title:"项目结构已刷新"})}catch{V("请确认项目路径有效后重试",{title:"刷新失败",type:"error"})}},se=async z=>{var ne;Ne(!0);try{const X=await Y.extractFromPath(z);P(X.result.map(he=>({...Ot(he,"extract"),mode:"full",lang:"cn"}))),ce("spm"),re(!1),o(),((ne=X.result)==null?void 0:ne.length)>0&&V("提取结果已进入候选池,请在 Candidates 页审核",{title:"提取完成"})}catch{V("Extraction failed",{type:"error"})}finally{Ne(!1)}},D=async()=>{var z;if(ae){Ne(!0);try{const ne=await Y.extractFromPath(ae);P(ne.result.map(X=>({...Ot(X,"extract"),mode:"full",lang:"cn"}))),ce("spm"),re(!1),o(),((z=ne.result)==null?void 0:z.length)>0?V(ne.isMarked?"精准锁定标记代码,已加入候选池":"提取结果已加入候选池",{title:"提取完成"}):ne.isMarked||V("未找到 ASD 标记,AI 将分析完整文件",{title:"提取中",type:"info"})}catch{V("Extraction failed",{type:"error"})}finally{Ne(!1)}}},J=async z=>{var ne,X,he,ie;try{const $e=await navigator.clipboard.readText();if(!$e)return V("请先复制代码到剪贴板",{title:"剪贴板为空",type:"info"});V("已收到代码,AI 正在识别可复用模式...",{title:"剪贴板分析中",type:"info"}),Ne(!0);const ve=z||ae;try{const ke=await Y.extractFromText($e,ve||void 0),Ie=ke._multipleCount;P([{...Ot(ke,"clipboard"),mode:"full",lang:"cn"}]),ce("spm"),re(!1),o(),V(Ie?`已识别 ${Ie} 条 Recipe,请在候选池审核`:"提取结果已加入候选池",{title:"AI 识别完成"})}catch(ke){const Ie=((X=(ne=ke.response)==null?void 0:ne.data)==null?void 0:X.aiError)===!0,Se=((ie=(he=ke.response)==null?void 0:he.data)==null?void 0:ie.error)||ke.message;Ie?V(Se,{title:"AI 识别失败",type:"error"}):V(Se,{title:"操作失败",type:"error"})}}catch{V("浏览器可能未授权剪贴板访问",{title:"剪贴板读取失败",type:"error"})}finally{Ne(!1)}},me=[{status:"正在读取 Target 源文件...",percent:15},{status:"正在发送到 AI 分析...",percent:35},{status:"正在识别可复用代码片段...",percent:55},{status:"正在生成摘要与使用指南...",percent:75},{status:"即将完成...",percent:92}],W=async z=>{var $e,ve,ke,Ie;if(T)return;y.current&&y.current.abort();const ne=new AbortController;y.current=ne,B(z.name),U(!0),P([]),d(null),C([]),S({current:0,total:100,status:"正在获取待扫描文件列表..."});const X=4e3;let he=0;const ie=setInterval(()=>{he=Math.min(he+1,me.length);const Se=me[he-1];Se&&S(Ue=>({...Ue,current:Se.percent,status:Se.status}))},X);try{const Se=await Y.getTargetFiles(z,ne.signal),Ue=Se.files||[],ot=Se.count??Ue.length;C(Ue),S(Lt=>({...Lt,current:10,status:`正在分析 ${ot} 个文件...`}));const ct=await Y.scanTarget(z,ne.signal);clearInterval(ie),S({current:100,total:100,status:"扫描完成"});const gt=ct.recipes||[],ss=($e=ct.scannedFiles)!=null&&$e.length?ct.scannedFiles:Ue;if(gt.length>0||ss.length>0){const Lt=typeof z=="string"?z:(z==null?void 0:z.name)||"unknown",Sa=gt.map(Ia=>({...Ot(Ia,"ai-scan"),mode:"full",lang:"cn",candidateTargetName:Lt,scanMode:"target"}));P(Sa),C(ss),o(),gt.length>0?V(`发现 ${gt.length} 条可复用代码模式,请在右侧审核`,{title:"Target 扫描完成"}):ct.message?V(ct.message,{title:"AI 扫描未返回结果",type:"error"}):V("该 Target 中未找到可复用的代码片段",{title:"扫描完成",type:"info"})}else V("请确认 Target 包含有效的源代码文件",{title:"扫描失败",type:"error"})}catch(Se){if(clearInterval(ie),$t.isCancel(Se))return;const Ue=Se.code==="ECONNABORTED"||((ve=Se.message)==null?void 0:ve.includes("timeout")),ot=Ue?"扫描超时,请尝试减少 Target 文件数量":((Ie=(ke=Se.response)==null?void 0:ke.data)==null?void 0:Ie.error)||Se.message;V(ot,{title:Ue?"扫描超时":"扫描出错",type:"error"})}finally{y.current===ne&&(U(!1),S({current:0,total:0,status:""}),y.current=null)}},ue=async()=>{var ne,X,he,ie,$e,ve;if(T)return;y.current&&y.current.abort();const z=new AbortController;y.current=z,ce("candidates"),U(!0),P([]),d(null),C([]),S({current:0,total:100,status:"正在收集项目结构..."}),a.resetSession();try{const ke=await Y.bootstrap(z.signal);S({current:100,total:100,status:"骨架已创建,正在后台填充..."}),ke.bootstrapSession&&a.initFromApiResponse(ke.bootstrapSession),o();const Ie=ke.report||{},Se=((ne=ke.targets)==null?void 0:ne.length)||0,Ue=((X=Ie.totals)==null?void 0:X.files)||0,ot=((he=Ie.totals)==null?void 0:he.graphEdges)||0,ct=ke.guardSummary,gt=ct?`, Guard: ${ct.totalViolations} 项违规`:"";V(`冷启动骨架已创建: ${Se} 个 Target, ${Ue} 个文件, ${ot} 条依赖${gt},正在后台逐维度填充...`)}catch(ke){if($t.isCancel(ke))return;const Se=ke.code==="ECONNABORTED"||((ie=ke.message)==null?void 0:ie.includes("timeout"))?"冷启动超时,请检查项目文件数量":((ve=($e=ke.response)==null?void 0:$e.data)==null?void 0:ve.error)||ke.message;V(Se,{type:"error"})}finally{y.current===z&&(U(!1),S({current:0,total:0,status:""}),y.current=null)}},De=async()=>{var ie,$e,ve,ke;if(T)return;y.current&&y.current.abort();const z=new AbortController;y.current=z,ce("spm"),B("__project__"),U(!0),P([]),d(null),C([]),S({current:0,total:100,status:"正在收集所有 Target 文件..."});const ne=[{status:"正在收集源文件...",percent:5},{status:"正在 AI 分析代码模式...",percent:15},{status:"AI 提取中(大项目可能需要数分钟)...",percent:25},{status:"AI 提取中...",percent:35},{status:"AI 深度分析中...",percent:45},{status:"持续处理中...",percent:55},{status:"正在运行 Guard 审计...",percent:65},{status:"正在汇总结果...",percent:75},{status:"即将完成...",percent:85}];let X=0;const he=setInterval(()=>{X=Math.min(X+1,ne.length);const Ie=ne[X-1];Ie&&S(Se=>({...Se,current:Ie.percent,status:Ie.status}))},15e3);try{const Ie=await Y.scanProject(z.signal);clearInterval(he),S({current:100,total:100,status:Ie.partial?"扫描部分完成(超时)":"全项目扫描完成"});const Se=Ie.recipes||[],Ue=Ie.scannedFiles||[];if(Se.length>0||Ue.length>0){const ot=Se.map(Lt=>({...Ot(Lt,"ai-scan"),mode:"full",lang:"cn",candidateTargetName:"__project__",scanMode:"project"}));P(ot),C(Ue),d(Ie.guardAudit||null),o();const ct=(ie=Ie.guardAudit)==null?void 0:ie.summary,gt=ct?`, Guard: ${ct.totalViolations} 处违反`:"",ss=Ie.partial?"(部分结果,AI 超时)":"";V(`全项目扫描完成: ${Se.length} 条候选${gt}${ss}`)}else V("全项目扫描完成,未发现可提取内容")}catch(Ie){if(clearInterval(he),$t.isCancel(Ie))return;const Ue=Ie.code==="ECONNABORTED"||(($e=Ie.message)==null?void 0:$e.includes("timeout"))?"扫描超时,请尝试减少项目文件数量或分 Target 扫描":((ke=(ve=Ie.response)==null?void 0:ve.data)==null?void 0:ke.error)||Ie.message;V(Ue,{type:"error"})}finally{y.current===z&&(U(!1),S({current:0,total:0,status:""}),y.current=null)}},Le=(z,ne)=>{const X=[...m],he={...X[z],...ne};X[z]=he,P(X)},Re=async z=>{var ne;if(!_){I(!0);try{const X=(((ne=z.content)==null?void 0:ne.pattern)||"").trim(),he=(()=>{if(!X)return!1;const Se=X.split(`
|
|
127
|
+
`).filter(ot=>ot.trim());return Se.filter(ot=>/^\s*(#{1,6}\s|[-*>]\s|\d+\.\s)/.test(ot)).length<=Se.length*.3})(),ie=(z.trigger||"").split(/[,,\s]+/).map(Se=>Se.trim()).filter(Boolean);if(he&&ie.length===0){V("请输入 Trigger",{type:"error"}),I(!1);return}const $e={title:z.title||"Untitled",description:z.description||"",trigger:ie.join(", ")||"",language:z.language||"swift",category:z.category||"Utility",kind:z.kind||"pattern",knowledgeType:z.knowledgeType||"code-pattern",complexity:z.complexity||"intermediate",scope:z.scope||null,difficulty:z.difficulty||"",tags:z.tags||[],source:z.source||"ai-scan",sourceFile:z.sourceFile||"",moduleName:z.moduleName||"",doClause:z.doClause||"",dontClause:z.dontClause||"",whenClause:z.whenClause||"",topicHint:z.topicHint||"",coreCode:z.coreCode||"",content:z.content||{},reasoning:z.reasoning||{},quality:z.quality||{},constraints:z.constraints||{},relations:z.relations||{},stats:z.stats||{},headers:z.headers||[],headerPaths:z.headerPaths||[],includeHeaders:z.includeHeaders||!1},ve=await Y.knowledgeCreate($e);if(ve!=null&&ve.id)try{await Y.knowledgeLifecycle(ve.id,"publish")}catch(Se){console.warn("auto-publish after save failed:",Se)}V(he?"已保存并发布为 Recipe":"已保存到 KB"),P(Se=>Se.filter(Ue=>Ue.title!==z.title));const ke=z.candidateTargetName,Ie=z.candidateId;if(ke&&Ie)try{await Y.deleteCandidate(Ie)}catch{}o()}catch(X){const he=qs(X)??xs(X);V(he??"保存失败",{type:"error"})}finally{I(!1)}}},qe=async()=>{var z,ne;if(!(!f||_)){I(!0);try{const X=f.id||((z=f.name)==null?void 0:z.replace(/\.md$/,"")),he=typeof f.content=="string"?{pattern:f.content,markdown:"",rationale:"",steps:[],codeChanges:[],verification:null}:f.content||{};await Y.knowledgeUpdate(X,{title:((ne=f.name)==null?void 0:ne.replace(/\.md$/,""))||"",description:f.description||"",content:he,tags:f.tags||[],kind:f.kind,language:f.language,category:f.category}),pe(),o()}catch(X){const he=qs(X)??xs(X);V(he??"保存 Recipe 失败",{type:"error"})}finally{I(!1)}}},We=async z=>{if(window.confirm("Are you sure?"))try{await Y.deleteRecipe(z),o()}catch(ne){const X=xs(ne);V(X??"删除失败",{type:"error"})}},G=async(z,ne)=>{try{await Y.deleteCandidate(ne),P(X=>X.filter(he=>!(he.candidateId===ne&&he.candidateTargetName===z))),c(X=>{if(!(X!=null&&X.candidates))return X;const he={...X.candidates};if(he[z]){const ie=he[z].items.filter($e=>$e.id!==ne);ie.length===0?delete he[z]:he[z]={...he[z],items:ie}}return{...X,candidates:he}})}catch{V("操作失败",{type:"error"})}},ze=async z=>{if(window.confirm(`确定移除「${z}」下的全部候选?`))try{await Y.deleteAllCandidatesInTarget(z),o(),V(`已移除 ${z} 下的全部候选`)}catch{V("操作失败",{type:"error"})}},He=async(z,ne)=>{var X,he;try{await Y.promoteToCandidate(z,z.candidateTargetName||R||"_review"),V("已加入 Candidate 待审核队列"),P(ie=>ie.filter(($e,ve)=>ve!==ne)),o()}catch(ie){V(((he=(X=ie.response)==null?void 0:X.data)==null?void 0:he.error)||"创建 Candidate 失败",{type:"error"})}},Be=((n==null?void 0:n.recipes)||[]).filter(z=>{var ve,ke;if(be)return be.some(Ie=>Ie.metadata.type==="recipe"&&Ie.metadata.name===z.name);const ne=z.name||"",X=typeof z.content=="string"?z.content:[(ve=z.content)==null?void 0:ve.pattern,(ke=z.content)==null?void 0:ke.markdown].filter(Boolean).join(" "),he=ne.toLowerCase().includes(g.toLowerCase())||X.toLowerCase().includes(g.toLowerCase())||(z.description||"").toLowerCase().includes(g.toLowerCase());if(v==="All")return he;const ie=X?X.match(/category:\s*(.*)/):null,$e=ie?ie[1].trim():"Utility";return he&&$e===v}).sort((z,ne)=>{var ie,$e,ve,ke;if(be){const Ie=((ie=be.find(Ue=>Ue.metadata.name===z.name))==null?void 0:ie.similarity)||0;return((($e=be.find(Ue=>Ue.metadata.name===ne.name))==null?void 0:$e.similarity)||0)-Ie}const X=((ve=z.stats)==null?void 0:ve.authorityScore)??0;return(((ke=ne.stats)==null?void 0:ke.authorityScore)??0)-X}),Xe=A.filter(z=>z.name.toLowerCase().includes(g.toLowerCase())).sort((z,ne)=>{const X=as(z.name),he=as(ne.name);return X&&!he?1:!X&&he?-1:z.name.localeCompare(ne.name)}),je=Object.values((n==null?void 0:n.candidates)||{}).reduce((z,ne)=>z+ne.items.length,0),Pe=x==="editor";return e.jsx($n,{children:e.jsx(ar,{children:e.jsxs("div",{className:`flex h-screen ${Pe?"bg-[#1e1e1e] text-slate-200":"bg-slate-50 text-slate-900"} overflow-hidden font-sans`,children:[e.jsx(Aa,{position:"top-center",toastOptions:{duration:5e3},containerStyle:{top:24}}),e.jsx(Pl,{activeTab:x,navigateToTab:ce,candidateCount:je,signalSuggestionCount:Oe,isDarkMode:Pe,currentUser:s.user!=="anonymous"?s.user:void 0,currentRole:s.role,permissionMode:s.mode,onLogout:void 0,collapsed:N,onToggleCollapse:()=>j(z=>!z)}),e.jsxs("main",{className:"flex-1 flex flex-col overflow-hidden relative",children:[e.jsx(rr,{searchQuery:g,setSearchQuery:p,setShowCreateModal:re,handleSyncToXcode:xe,aiConfig:n==null?void 0:n.aiConfig,llmReady:le,onOpenLlmConfig:()=>Me(!0),onBeforeAiSwitch:de,onAiConfigChange:o,isDarkMode:Pe,onSemanticSearchResults:z=>{Ce(z),x!=="recipes"&&ce("recipes")}}),x==="recipes"&&e.jsx(nr,{selectedCategory:v,setSelectedCategory:k}),e.jsx("div",{className:`flex-1 overflow-y-auto ${x==="editor"||x==="wiki"?"":"p-8"}`,children:u?e.jsx("div",{className:"flex items-center justify-center h-full",children:e.jsx("div",{className:"animate-spin rounded-full h-8 w-8 border-b-2 border-blue-600"})}):x==="recipes"?e.jsx(hr,{recipes:Be,openRecipeEdit:te,handleDeleteRecipe:We,onRefresh:o,idTitleMap:n==null?void 0:n.idTitleMap,currentPage:ee,onPageChange:L,pageSize:Z,onPageSizeChange:z=>{fe(z),L(1)}}):x==="guard"?e.jsx(Fr,{onRefresh:o}):x==="skills"?e.jsx(sn,{onRefresh:o,signalSuggestionCount:Oe,onSuggestionCountChange:Ee}):x==="candidates"?e.jsxs(e.Fragment,{children:[a.session&&e.jsx("div",{className:"mb-4",children:e.jsx(dn,{session:a.session,isAllDone:a.isAllDone,reviewState:a.reviewState,onDismiss:()=>a.resetSession()})}),e.jsx(wr,{data:n,isShellTarget:as,isSilentTarget:Sl,isPendingTarget:Il,handleDeleteCandidate:G,onEditRecipe:te,onColdStart:ue,isScanning:T,isBootstrapping:((_e=a.session)==null?void 0:_e.status)==="running",onRefresh:o,onAuditCandidate:(z,ne)=>{var ie,$e;const X=(((ie=z.content)==null?void 0:ie.pattern)||"").trim(),he=!!X&&(()=>{const ve=X.split(`
|
|
128
|
+
`).filter(Ie=>Ie.trim());return ve.filter(Ie=>/^\s*(#{1,6}\s|[-*>]\s|\d+\.\s)/.test(Ie)).length<=ve.length*.3})();P([{...z,mode:he?"full":"preview",lang:"cn",includeHeaders:!0,difficulty:z.difficulty||z.complexity||"intermediate",authority:(($e=z.stats)==null?void 0:$e.authority)||3,candidateId:z.id,candidateTargetName:ne}]),ce("spm")},onAuditAllInTarget:(z,ne)=>{P(z.map(X=>{var $e,ve;const he=((($e=X.content)==null?void 0:$e.pattern)||"").trim(),ie=!!he&&(()=>{const ke=he.split(`
|
|
129
|
+
`).filter(Se=>Se.trim());return ke.filter(Se=>/^\s*(#{1,6}\s|[-*>]\s|\d+\.\s)/.test(Se)).length<=ke.length*.3})();return{...X,mode:ie?"full":"preview",lang:"cn",includeHeaders:!0,difficulty:X.difficulty||X.complexity||"intermediate",authority:((ve=X.stats)==null?void 0:ve.authority)||3,candidateId:X.id,candidateTargetName:ne}})),ce("spm")},handleDeleteAllInTarget:ze})]}):x==="knowledge"?e.jsx(tn,{onRefresh:H,idTitleMap:n==null?void 0:n.idTitleMap}):x==="depgraph"?e.jsx(Pr,{}):x==="knowledgegraph"?e.jsx(Xr,{}):x==="spm"?e.jsx(Er,{targets:A,filteredTargets:Xe,selectedTargetName:R,isScanning:T,scanProgress:K,scanFileList:q,scanResults:m,guardAudit:h,handleScanTarget:W,handleScanProject:De,handleUpdateScanResult:Le,handleSaveExtracted:Re,handlePromoteToCandidate:He,handleDeleteCandidate:G,onEditRecipe:te,isShellTarget:as,recipes:(n==null?void 0:n.recipes)??[],isSavingRecipe:_,handleRefreshProject:H}):x==="wiki"?e.jsx(vn,{}):x==="editor"?e.jsx(xn,{}):x==="help"?e.jsx(br,{}):e.jsx(qr,{})}),f&&e.jsx(kn,{editingRecipe:f,setEditingRecipe:E,handleSaveRecipe:qe,closeRecipeEdit:pe,isSavingRecipe:_}),O&&e.jsx(Cn,{setShowCreateModal:re,createPath:ae,setCreatePath:ye,handleCreateFromPath:D,handleCreateFromClipboard:J,isExtracting:oe}),Ae&&e.jsx(In,{searchQ:Ae.q,insertPath:Ae.path,onClose:()=>{Fe(null),window.history.replaceState({},document.title,window.location.pathname)}}),ge&&e.jsx(zn,{onClose:()=>Me(!1),onSaved:()=>{b(),o()}})]}),e.jsx(Mn,{})]})})})},Mn=()=>{const{isOpen:t}=ts();return t?e.jsx(lr,{}):null};Ma.createRoot(document.getElementById("root")).render(e.jsx(It.StrictMode,{children:e.jsx(An,{})}));
|