autosnippet 2.19.8 → 3.0.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.
@@ -1,8 +1,8 @@
1
- import{z as na,j as e,r as n,l as Ma,h as oa,o as ia,m as ca,M as Ra,a as La,R as St,F as Da,b as Pa}from"./vendor-CEnWn7aV.js";import{a as Wt}from"./axios-C0Zqfgkc.js";import{Z as Je,L as da,S as Fa,B as Jt,H as Gt,C as Oa,a as nt,W as Ba,G as Cs,b as Ye,c as Qe,d as us,e as qa,f as Ha,D as xa,g as Yt,P as Wa,h as wt,i as ps,j as Ga,k as Ua,l as Ka,F as Et,m as it,n as ys,o as et,M as kt,p as bt,q as Va,r as Ue,E as Xt,s as Ja,t as Ya,U as ma,u as Xa,v as gt,X as Ke,w as Ee,x as ft,R as ua,y as st,z as Ss,A as pa,I as dt,J as Za,K as ha,N as Ct,O as pt,Q as Qa,T as Zt,V as el,Y as tl,_ as ba,$ as sl,a0 as al,a1 as tt,a2 as Ut,a3 as xt,a4 as Is,a5 as hs,a6 as At,a7 as Qt,a8 as $s,a9 as ht,aa as ga,ab as Ot,ac as ll,ad as Rs,ae as Ls,af as cs,ag as fa,ah as es,ai as ds,aj as _t,ak as vs,al as Kt,am as rl,an as ja,ao as ws,ap as zt,aq as nl,ar as Na,as as ol,at as il,au as cl,av as ks,aw as dl,ax as zs,ay as xl,az as ml,aA as ul,aB as pl,aC as Ds,aD as Ps,aE as hl,aF as bl,aG as gl,aH as fl,aI as jl}from"./icons-CEfgGaZi.js";import"./yaml-qRaU8Ldn.js";(function(){const s=document.createElement("link").relList;if(s&&s.supports&&s.supports("modulepreload"))return;for(const r of document.querySelectorAll('link[rel="modulepreload"]'))l(r);new MutationObserver(r=>{for(const i of r)if(i.type==="childList")for(const c of i.addedNodes)c.tagName==="LINK"&&c.rel==="modulepreload"&&l(c)}).observe(document,{childList:!0,subtree:!0});function a(r){const i={};return r.integrity&&(i.integrity=r.integrity),r.referrerPolicy&&(i.referrerPolicy=r.referrerPolicy),r.crossOrigin==="use-credentials"?i.credentials="include":r.crossOrigin==="anonymous"?i.credentials="omit":i.credentials="same-origin",i}function l(r){if(r.ep)return;r.ep=!0;const i=a(r);fetch(r.href,i)}})();const Nl="AutoSnippet";function yl(t){if(typeof window>"u"||!("Notification"in window))return;const s=()=>{try{new Notification(Nl,{body:t,tag:"autosnippet"})}catch{}};if(Notification.permission==="granted"){s();return}Notification.permission!=="denied"&&Notification.requestPermission().then(a=>{a==="granted"&&s()})}const vl={success:5e3,error:8e3,info:5e3},Fs={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"}},wl=()=>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"})}),kl=()=>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"})}),ya=()=>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"})}),Cl={success:wl,error:kl,info:ya},Sl=({visible:t,toastId:s,body:a,type:l,title:r,duration:i})=>{const c=Fs[l]||Fs.info,o=Cl[l]||ya;return e.jsxs("div",{onClick:()=>na.dismiss(s),style:{background:c.bg,borderLeft:`4px solid ${c.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(o,{})}),e.jsxs("div",{style:{flex:1,minWidth:0},children:[r&&e.jsx("div",{style:{fontWeight:600,fontSize:13,lineHeight:1.3,color:"#1e293b",marginBottom:2},children:r}),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:c.bar,opacity:.45,animation:`toast-progress ${i}ms linear forwards`}})]})};function le(t,s){const a=(s==null?void 0:s.type)??"success",l=s==null?void 0:s.title,r=(s==null?void 0:s.duration)??vl[a]??5e3;typeof document<"u"&&document.visibilityState==="visible"?Il(t,a,l,r):yl(l?`${l}: ${t}`:t)}function Il(t,s,a,l){na.custom(r=>e.jsx(Sl,{visible:r.visible,toastId:r.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=`
1
+ import{z as na,j as e,r as n,l as _a,h as oa,o as ia,m as ca,M as Ra,a as La,R as St,F as Da,b as Pa}from"./vendor-CEnWn7aV.js";import{a as Gt}from"./axios-C0Zqfgkc.js";import{Z as Je,L as da,S as Fa,B as Jt,H as Wt,C as Oa,a as nt,W as Ba,G as Cs,b as Ye,c as Qe,d as us,e as qa,f as Ha,D as xa,g as Yt,P as Ga,h as wt,i as ps,j as Wa,k as Ua,l as Ka,F as Tt,m as it,n as ys,o as et,M as kt,p as bt,q as Va,r as Ue,E as Xt,s as Ja,t as Ya,U as ma,u as Xa,v as gt,X as Ke,w as Te,x as ft,R as ua,y as st,z as Ss,A as pa,I as dt,J as Za,K as ha,N as Ct,O as pt,Q as Qa,T as Zt,V as el,Y as tl,_ as ba,$ as sl,a0 as al,a1 as tt,a2 as Ut,a3 as xt,a4 as Is,a5 as hs,a6 as At,a7 as Qt,a8 as $s,a9 as ht,aa as ga,ab as Ot,ac as ll,ad as Rs,ae as Ls,af as cs,ag as fa,ah as es,ai as ds,aj as Et,ak as vs,al as Kt,am as rl,an as ja,ao as ws,ap as zt,aq as nl,ar as Na,as as ol,at as il,au as cl,av as ks,aw as dl,ax as zs,ay as xl,az as ml,aA as ul,aB as pl,aC as Ds,aD as Ps,aE as hl,aF as bl,aG as gl,aH as fl,aI as jl}from"./icons-CEfgGaZi.js";import"./yaml-qRaU8Ldn.js";(function(){const s=document.createElement("link").relList;if(s&&s.supports&&s.supports("modulepreload"))return;for(const r of document.querySelectorAll('link[rel="modulepreload"]'))l(r);new MutationObserver(r=>{for(const i of r)if(i.type==="childList")for(const c of i.addedNodes)c.tagName==="LINK"&&c.rel==="modulepreload"&&l(c)}).observe(document,{childList:!0,subtree:!0});function a(r){const i={};return r.integrity&&(i.integrity=r.integrity),r.referrerPolicy&&(i.referrerPolicy=r.referrerPolicy),r.crossOrigin==="use-credentials"?i.credentials="include":r.crossOrigin==="anonymous"?i.credentials="omit":i.credentials="same-origin",i}function l(r){if(r.ep)return;r.ep=!0;const i=a(r);fetch(r.href,i)}})();const Nl="AutoSnippet";function yl(t){if(typeof window>"u"||!("Notification"in window))return;const s=()=>{try{new Notification(Nl,{body:t,tag:"autosnippet"})}catch{}};if(Notification.permission==="granted"){s();return}Notification.permission!=="denied"&&Notification.requestPermission().then(a=>{a==="granted"&&s()})}const vl={success:5e3,error:8e3,info:5e3},Fs={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"}},wl=()=>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"})}),kl=()=>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"})}),ya=()=>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"})}),Cl={success:wl,error:kl,info:ya},Sl=({visible:t,toastId:s,body:a,type:l,title:r,duration:i})=>{const c=Fs[l]||Fs.info,o=Cl[l]||ya;return e.jsxs("div",{onClick:()=>na.dismiss(s),style:{background:c.bg,borderLeft:`4px solid ${c.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(o,{})}),e.jsxs("div",{style:{flex:1,minWidth:0},children:[r&&e.jsx("div",{style:{fontWeight:600,fontSize:13,lineHeight:1.3,color:"#1e293b",marginBottom:2},children:r}),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:c.bar,opacity:.45,animation:`toast-progress ${i}ms linear forwards`}})]})};function le(t,s){const a=(s==null?void 0:s.type)??"success",l=s==null?void 0:s.title,r=(s==null?void 0:s.duration)??vl[a]??5e3;typeof document<"u"&&document.visibilityState==="visible"?Il(t,a,l,r):yl(l?`${l}: ${t}`:t)}function Il(t,s,a,l){na.custom(r=>e.jsx(Sl,{visible:r.visible,toastId:r.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
2
  @keyframes toast-progress {
3
3
  from { width: 100%; }
4
4
  to { width: 0%; }
5
- }`,document.head.appendChild(s)}}const Os={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:wt,color:"text-slate-600",bg:"bg-slate-100",border:"border-slate-200"},View:{icon:Wa,color:"text-pink-600",bg:"bg-pink-50",border:"border-pink-100"},Service:{icon:Yt,color:"text-indigo-600",bg:"bg-indigo-50",border:"border-indigo-100"},Tool:{icon:Je,color:"text-amber-600",bg:"bg-amber-50",border:"border-amber-100"},Model:{icon:xa,color:"text-emerald-600",bg:"bg-emerald-50",border:"border-emerald-100"},Network:{icon:Ha,color:"text-blue-600",bg:"bg-blue-50",border:"border-blue-100"},Storage:{icon:qa,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:Qe,color:"text-orange-600",bg:"bg-orange-50",border:"border-orange-100"},"code-standard":{icon:Ye,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:Ba,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:Oa,color:"text-amber-600",bg:"bg-amber-50",border:"border-amber-100"},"project-profile":{icon:Gt,color:"text-teal-600",bg:"bg-teal-50",border:"border-teal-100"},"agent-guidelines":{icon:Jt,color:"text-rose-600",bg:"bg-rose-50",border:"border-rose-100"},"objc-deep-scan":{icon:Fa,color:"text-indigo-600",bg:"bg-indigo-50",border:"border-indigo-100"},"category-scan":{icon:da,color:"text-cyan-600",bg:"bg-cyan-50",border:"border-cyan-100"},bootstrap:{icon:Je,color:"text-violet-600",bg:"bg-violet-50",border:"border-violet-100"}},$l=["All","View","Service","Tool","Model","Network","Storage","UI","Utility"],zl=["recipes","ai","spm","candidates","knowledge","depgraph","knowledgegraph","guard","skills","wiki","editor","help"],Al="https://github.com/GxFn/AutoSnippet/issues/new?title=Guard%20误报%2F建议%3A%20&body=请描述误报的规则ID、代码片段或改进建议。",ss=t=>["Example","Demo","Sample","Tests","Spec","Mock","Runner"].some(a=>t.endsWith(a)||t.includes(a)),_l=t=>t.startsWith("_"),El=t=>t==="_pending",Tl="您暂无写入权限,无法保存。如需此权限请联系管理员;请勿擅自修改核心代码或安装包,以免影响团队协作与数据安全。";function xs(t){var r,i;const s=t==null?void 0:t.response;if((s==null?void 0:s.status)!==403)return null;const a=(r=s.data)==null?void 0:r.code,l=(i=s.data)==null?void 0:i.error;return a==="RECIPE_WRITE_FORBIDDEN"||typeof l=="string"&&l.includes("没权限")?Tl:null}const Ml="保存过于频繁,请稍后再试。";function Bs(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"?Ml:null:null}const de=Wt.create({baseURL:"/api/v1"});function qs(t){const s=t.quality||{},a=t.stats||t.statistics||{},l=t.content||{},r=t.trigger||"@"+(t.title||"").replace(/[\s_-]+(.)?/g,(c,o)=>o?o.toUpperCase():""),i={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:i,trigger:r,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 Rl(t){let s="swift",a="general",l="",r="",i="",c="",o="",j="",g="",h=[],y=[],x="",m=0,u="1.0.0",A="",S="",I="",P="",B="",R="",K="",X="",$="",H="",C=t;const p=t.match(/^---\n([\s\S]*?)\n---/);if(p){const O=p[1],k=se=>{const V=O.match(new RegExp(`^${se}:\\s*(.+)$`,"m"));return V?V[1].trim():null};s=k("language")||s,a=k("category")||a,l=k("title")||l,r=k("trigger")||"",i=k("summary_cn")||k("summary")||k("description")||i,c=k("summary_en")||"",o=k("knowledge_type")||k("knowledgeType")||"",j=k("complexity")||"",g=k("scope")||"",x=k("difficulty")||"",u=k("version")||"1.0.0";const b=k("authority");b&&(m=parseInt(b)||0);const f=k("tags");if(f)try{h=JSON.parse(f)}catch{h=f.split(",").map(se=>se.trim()).filter(Boolean)}const w=k("headers");if(w)try{y=JSON.parse(w)}catch{y=[w]}R=k("kind")||"",K=k("doClause")||"",X=k("dontClause")||"",$=k("whenClause")||"",H=k("topicHint")||"";const Z=t.match(/```[\w]*\n([\s\S]*?)```/);Z&&(C=Z[1].trim());const q=t.replace(/^---\n[\s\S]*?\n---/,"").trim(),ue=q.match(/## (?:AI Context \/ )?Usage Guide(?:\s*\(CN\))?\n\n([\s\S]*?)(?=\n## |$)/);ue&&(A=ue[1].trim());const M=q.match(/## (?:AI Context \/ )?Usage Guide\s*\(EN\)\n\n([\s\S]*?)(?=\n## |$)/);M&&(S=M[1].trim());const T=q.match(/## Architecture Usage\n\n([\s\S]*?)(?=\n## |$)/);T&&(I=T[1].trim());const ee=q.match(/## Best Practices\n\n([\s\S]*?)(?=\n## |$)/);ee&&(P=ee[1].trim());const J=q.match(/## Standards\n\n([\s\S]*?)(?=\n## |$)/);J&&(B=J[1].trim())}return{title:l,language:s,category:a,trigger:r,summary:i,summaryEn:c,knowledgeType:o,complexity:j,scope:g,tags:h,headers:y,difficulty:x,authority:m,version:u,codePattern:C,usageGuide:A,usageGuideEn:S,rationaleText:I,bestPracticesText:P,standardsText:B,kind:R,doClause:K,dontClause:X,whenClause:$,topicHint:H}}function Ll(t,s,a){var r;const l=Array.isArray(t.category)?t.category[0]:t.category||s||"general";return{title:t.title||"Untitled",content:t.content||{pattern:((r=t.content)==null?void 0:r.pattern)||"",markdown:"",rationale:""},description:t.description||"",trigger:t.trigger||"",language:t.language||"swift",category:l,kind:t.kind||"pattern",knowledgeType:t.knowledgeType||"code-pattern",complexity:t.complexity||"intermediate",source:a,lifecycle:"pending",tags:t.tags||[],sourceFile:t.sourceFile||"",moduleName:t.moduleName||"",headers:t.headers||[],headerPaths:t.headerPaths||[],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:l,headers:t.headers||[],headerPaths:t.headerPaths||[],moduleName:t.moduleName||"",isMarked:t.isMarked||!1}}}async function It(t){var i,c,o;const s=t.replace(/\.md$/i,"");if(/^[a-f0-9-]{8,}$/i.test(s))return s;const a=await de.get("/knowledge?limit=1000"),r=(((c=(i=a.data)==null?void 0:i.data)==null?void 0:c.data)||((o=a.data)==null?void 0:o.data)||[]).find(j=>{const g=j.title||j.name||"";return g===s||g+".md"===t});if(r!=null&&r.id)return r.id;throw new Error(`Knowledge entry not found: ${t}`)}async function Dl(t,s){var c;const a=(c=t.body)==null?void 0:c.getReader();if(!a)throw new Error("ReadableStream not available");const l=new TextDecoder;let r="",i="";for(;;){const{done:o,value:j}=await a.read();if(o)break;const g=l.decode(j,{stream:!0});r+=g;const h=r.split(`
5
+ }`,document.head.appendChild(s)}}const Os={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:wt,color:"text-slate-600",bg:"bg-slate-100",border:"border-slate-200"},View:{icon:Ga,color:"text-pink-600",bg:"bg-pink-50",border:"border-pink-100"},Service:{icon:Yt,color:"text-indigo-600",bg:"bg-indigo-50",border:"border-indigo-100"},Tool:{icon:Je,color:"text-amber-600",bg:"bg-amber-50",border:"border-amber-100"},Model:{icon:xa,color:"text-emerald-600",bg:"bg-emerald-50",border:"border-emerald-100"},Network:{icon:Ha,color:"text-blue-600",bg:"bg-blue-50",border:"border-blue-100"},Storage:{icon:qa,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:Qe,color:"text-orange-600",bg:"bg-orange-50",border:"border-orange-100"},"code-standard":{icon:Ye,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:Ba,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:Oa,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:Jt,color:"text-rose-600",bg:"bg-rose-50",border:"border-rose-100"},"objc-deep-scan":{icon:Fa,color:"text-indigo-600",bg:"bg-indigo-50",border:"border-indigo-100"},"category-scan":{icon:da,color:"text-cyan-600",bg:"bg-cyan-50",border:"border-cyan-100"},bootstrap:{icon:Je,color:"text-violet-600",bg:"bg-violet-50",border:"border-violet-100"}},$l=["All","View","Service","Tool","Model","Network","Storage","UI","Utility"],zl=["recipes","ai","spm","candidates","knowledge","depgraph","knowledgegraph","guard","skills","wiki","editor","help"],Al="https://github.com/GxFn/AutoSnippet/issues/new?title=Guard%20误报%2F建议%3A%20&body=请描述误报的规则ID、代码片段或改进建议。",ss=t=>["Example","Demo","Sample","Tests","Spec","Mock","Runner"].some(a=>t.endsWith(a)||t.includes(a)),El=t=>t.startsWith("_"),Tl=t=>t==="_pending",Ml="您暂无写入权限,无法保存。如需此权限请联系管理员;请勿擅自修改核心代码或安装包,以免影响团队协作与数据安全。";function xs(t){var r,i;const s=t==null?void 0:t.response;if((s==null?void 0:s.status)!==403)return null;const a=(r=s.data)==null?void 0:r.code,l=(i=s.data)==null?void 0:i.error;return a==="RECIPE_WRITE_FORBIDDEN"||typeof l=="string"&&l.includes("没权限")?Ml:null}const _l="保存过于频繁,请稍后再试。";function Bs(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 de=Gt.create({baseURL:"/api/v1"});function qs(t){const s=t.quality||{},a=t.stats||t.statistics||{},l=t.content||{},r=t.trigger||"@"+(t.title||"").replace(/[\s_-]+(.)?/g,(c,o)=>o?o.toUpperCase():""),i={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:i,trigger:r,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 Rl(t){let s="swift",a="general",l="",r="",i="",c="",o="",j="",g="",h=[],y=[],x="",m=0,u="1.0.0",A="",S="",I="",P="",B="",R="",K="",X="",$="",H="",C=t;const p=t.match(/^---\n([\s\S]*?)\n---/);if(p){const O=p[1],k=se=>{const V=O.match(new RegExp(`^${se}:\\s*(.+)$`,"m"));return V?V[1].trim():null};s=k("language")||s,a=k("category")||a,l=k("title")||l,r=k("trigger")||"",i=k("summary_cn")||k("summary")||k("description")||i,c=k("summary_en")||"",o=k("knowledge_type")||k("knowledgeType")||"",j=k("complexity")||"",g=k("scope")||"",x=k("difficulty")||"",u=k("version")||"1.0.0";const b=k("authority");b&&(m=parseInt(b)||0);const f=k("tags");if(f)try{h=JSON.parse(f)}catch{h=f.split(",").map(se=>se.trim()).filter(Boolean)}const w=k("headers");if(w)try{y=JSON.parse(w)}catch{y=[w]}R=k("kind")||"",K=k("doClause")||"",X=k("dontClause")||"",$=k("whenClause")||"",H=k("topicHint")||"";const Z=t.match(/```[\w]*\n([\s\S]*?)```/);Z&&(C=Z[1].trim());const q=t.replace(/^---\n[\s\S]*?\n---/,"").trim(),ue=q.match(/## (?:AI Context \/ )?Usage Guide(?:\s*\(CN\))?\n\n([\s\S]*?)(?=\n## |$)/);ue&&(A=ue[1].trim());const _=q.match(/## (?:AI Context \/ )?Usage Guide\s*\(EN\)\n\n([\s\S]*?)(?=\n## |$)/);_&&(S=_[1].trim());const M=q.match(/## Architecture Usage\n\n([\s\S]*?)(?=\n## |$)/);M&&(I=M[1].trim());const ee=q.match(/## Best Practices\n\n([\s\S]*?)(?=\n## |$)/);ee&&(P=ee[1].trim());const J=q.match(/## Standards\n\n([\s\S]*?)(?=\n## |$)/);J&&(B=J[1].trim())}return{title:l,language:s,category:a,trigger:r,summary:i,summaryEn:c,knowledgeType:o,complexity:j,scope:g,tags:h,headers:y,difficulty:x,authority:m,version:u,codePattern:C,usageGuide:A,usageGuideEn:S,rationaleText:I,bestPracticesText:P,standardsText:B,kind:R,doClause:K,dontClause:X,whenClause:$,topicHint:H}}function Ll(t,s,a){var r;const l=Array.isArray(t.category)?t.category[0]:t.category||s||"general";return{title:t.title||"Untitled",content:t.content||{pattern:((r=t.content)==null?void 0:r.pattern)||"",markdown:"",rationale:""},description:t.description||"",trigger:t.trigger||"",language:t.language||"swift",category:l,kind:t.kind||"pattern",knowledgeType:t.knowledgeType||"code-pattern",complexity:t.complexity||"intermediate",source:a,lifecycle:"pending",tags:t.tags||[],sourceFile:t.sourceFile||"",moduleName:t.moduleName||"",headers:t.headers||[],headerPaths:t.headerPaths||[],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:l,headers:t.headers||[],headerPaths:t.headerPaths||[],moduleName:t.moduleName||"",isMarked:t.isMarked||!1}}}async function It(t){var i,c,o;const s=t.replace(/\.md$/i,"");if(/^[a-f0-9-]{8,}$/i.test(s))return s;const a=await de.get("/knowledge?limit=1000"),r=(((c=(i=a.data)==null?void 0:i.data)==null?void 0:c.data)||((o=a.data)==null?void 0:o.data)||[]).find(j=>{const g=j.title||j.name||"";return g===s||g+".md"===t});if(r!=null&&r.id)return r.id;throw new Error(`Knowledge entry not found: ${t}`)}async function Dl(t,s){var c;const a=(c=t.body)==null?void 0:c.getReader();if(!a)throw new Error("ReadableStream not available");const l=new TextDecoder;let r="",i="";for(;;){const{done:o,value:j}=await a.read();if(o)break;const g=l.decode(j,{stream:!0});r+=g;const h=r.split(`
6
6
  `);r=h.pop()||"";for(const y of h){if(y.startsWith(":")||!y.startsWith("data: "))continue;const x=y.slice(6).trim();if(!(!x||x==="[DONE]"))try{const m=JSON.parse(x);if(s(m),m.type==="text:delta"&&m.delta)i+=m.delta;else if(m.type==="stream:done"&&m.text)i=m.text;else if(m.type==="stream:error")throw new Error(m.message||"Stream error")}catch(m){if(m instanceof SyntaxError)continue;throw m}}}return i}const re={async fetchData(){var g,h,y,x,m;const[t,s]=await Promise.all([de.get("/knowledge?limit=1000").catch(()=>({data:{success:!0,data:{data:[]}}})),de.get("/ai/config").catch(()=>({data:{success:!0,data:{provider:"",model:""}}}))]),a=((h=(g=t.data)==null?void 0:g.data)==null?void 0:h.data)||((x=(y=t.data)==null?void 0:y.data)==null?void 0:x.items)||[],r=a.filter(u=>u.lifecycle==="active").map(qs),i=a.filter(u=>u.lifecycle==="pending"),c={};for(const u of i){const A=u.category||u.language||"_pending";c[A]||(c[A]={targetName:A,scanTime:u.createdAt,items:[]}),c[A].items.push(u)}const o=((m=s.data)==null?void 0:m.data)||{provider:"",model:""},j={};for(const u of a)u.id&&u.title&&(j[u.id]=u.title);return{rootSpec:{list:[]},recipes:r,candidates:c,projectRoot:"",watcherStatus:"active",aiConfig:{provider:o.provider||"",model:o.model||""},idTitleMap:j}},async fetchTargets(){var a;return(((a=(await de.get("/spm/targets")).data)==null?void 0:a.data)||{}).targets||[]},async getTargetFiles(t,s){var r,i;const l=((r=(await de.post("/spm/target-files",{target:t},{signal:s})).data)==null?void 0:r.data)||{};return{files:l.files||[],count:l.total||((i=l.files)==null?void 0:i.length)||0}},async scanTarget(t,s){var i;const l=((i=(await de.post("/spm/scan",{target:t},{signal:s,timeout:6e5})).data)==null?void 0:i.data)||{};return{recipes:l.recipes||l.result||[],scannedFiles:l.scannedFiles||[],message:l.message||""}},async scanTargetStream(t,s,a){const l=await fetch("/api/v1/spm/scan/stream",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({target:t}),signal:a});if(!l.ok)throw new Error(`Scan stream start failed: ${l.status}`);const i=(await l.json()).sessionId;if(!i)throw new Error("No sessionId returned");return new Promise((c,o)=>{const j=`/api/v1/spm/scan/events/${i}`,g=new EventSource(j);let h=!1,y={recipes:[],scannedFiles:[],message:""};function x(){g.close()}if(g.onmessage=m=>{try{const u=JSON.parse(m.data);s(u),u.type==="scan:result"&&(y={recipes:u.recipes||[],scannedFiles:u.scannedFiles||[],message:u.message||""}),u.type==="stream:done"&&(x(),h=!0,c(y)),u.type==="stream:error"&&(x(),h=!0,o(new Error(u.message||"Scan stream error")))}catch{}},g.onerror=()=>{h||(x(),h=!0,y.recipes.length>0?c(y):o(new Error("EventSource connection failed")))},a){const m=()=>{h||(x(),h=!0,o(new DOMException("The operation was aborted.","AbortError")))};if(a.aborted){m();return}a.addEventListener("abort",m,{once:!0})}})},async scanProject(t){var l;const a=((l=(await de.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 de.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 de.get("/spm/bootstrap/status")).data)==null?void 0:s.data)||{status:"idle"}},async getDepGraph(t){var a;return((a=(await de.get(`/spm/dep-graph?level=${t}`)).data)==null?void 0:a.data)||{}},async syncToXcode(){await de.post("/commands/install")},async refreshProject(){await de.post("/commands/spm-map")},async extractFromPath(t){var l;const a=((l=(await de.post("/extract/path",{relativePath:t})).data)==null?void 0:l.data)||{};return{result:a.result||[],isMarked:a.isMarked||!1}},async extractFromText(t,s){var r;const l=((r=(await de.post("/extract/text",{text:t,...s?{relativePath:s}:{}})).data)==null?void 0:r.data)||{};return Array.isArray(l.result)&&l.result.length>0?l.result[0]:l},async saveRecipe(t,s){const a=Rl(s),l=a.title||t.replace(/\.md$/,""),r={trigger:a.trigger,headers:a.headers,difficulty:a.difficulty,authority:a.authority,version:a.version},i={pattern:a.codePattern||"",rationale:a.rationaleText||"",steps:a.bestPracticesText?[a.bestPracticesText]:[],codeChanges:[],verification:null,markdown:a.usageGuide||""},c={};if(a.standardsText){const j=a.standardsText.split(`
7
7
  `).map(y=>y.trim()).filter(Boolean),g=j.filter(y=>y.startsWith("- ")).map(y=>y.slice(2).trim());g.length>0&&(c.preconditions=g);const h=j.filter(y=>!y.startsWith("- ")&&!y.startsWith("**"));h.length>0&&(c.boundaries=h)}const o={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:i,constraints:c,dimensions:r};a.kind&&(o.kind=a.kind),a.doClause&&(o.doClause=a.doClause),a.dontClause&&(o.dontClause=a.dontClause),a.whenClause&&(o.whenClause=a.whenClause),a.topicHint&&(o.topicHint=a.topicHint);try{const j=await It(t);await de.patch(`/knowledge/${j}`,o);return}catch{}await de.post("/knowledge",o)},async deleteRecipe(t){const s=await It(t);await de.delete(`/knowledge/${s}`)},async getRecipeByName(t){var i;const s=await It(t),l=(i=(await de.get(`/knowledge/${s}`)).data)==null?void 0:i.data;if(!l)throw new Error("Recipe not found");const r=l.content||{};return{name:t,content:r.pattern||r.markdown||""}},async setRecipeAuthority(t,s){const a=await It(t);await de.patch(`/knowledge/${a}/quality`,{codeCompleteness:s,projectAdaptation:s,documentationClarity:s})},async updateRecipeRelations(t,s){const a=await It(t);await de.patch(`/knowledge/${a}`,{relations:s})},async getCandidate(t){var l;const a=(l=(await de.get(`/knowledge/${t}`)).data)==null?void 0:l.data;if(!a)throw new Error("Knowledge entry not found");return a},async deleteCandidate(t){await de.delete(`/knowledge/${t}`)},async promoteCandidateToRecipe(t,s){var r;const l=(r=(await de.patch(`/knowledge/${t}/publish`)).data)==null?void 0:r.data;return{recipe:l,candidate:l}},async enrichCandidates(t){var a;return((a=(await de.post("/candidates/enrich",{candidateIds:t})).data)==null?void 0:a.data)||{enriched:0,total:0,results:[]}},async bootstrapRefine(t,s,a){var r;return((r=(await de.post("/candidates/bootstrap-refine",{candidateIds:t,userPrompt:s,dryRun:a},{timeout:3e5})).data)==null?void 0:r.data)||{refined:0,total:0,errors:[],results:[]}},async refinePreview(t,s){var l;return((l=(await de.post("/candidates/refine-preview",{candidateId:t,userPrompt:s},{timeout:12e4})).data)==null?void 0:l.data)||{}},async refineApply(t,s,a){var r;return((r=(await de.post("/candidates/refine-apply",{candidateId:t,userPrompt:s,preview:a},{timeout:12e4})).data)==null?void 0:r.data)||{}},async getKnowledgeGraph(t=500){var a;return((a=(await de.get(`/search/graph/all?limit=${t}`)).data)==null?void 0:a.data)||{edges:[],nodeLabels:{},nodeTypes:{},nodeCategories:{}}},async getGraphStats(){var s;return((s=(await de.get("/search/graph/stats")).data)==null?void 0:s.data)||{totalEdges:0,byRelation:{},nodeTypes:[]}},async discoverRelations(t=20){var a,l,r,i;const s=await de.post("/recipes/discover-relations",{batchSize:t});if(!((a=s.data)!=null&&a.success))throw new Error(((r=(l=s.data)==null?void 0:l.error)==null?void 0:r.message)||"启动失败");return((i=s.data)==null?void 0:i.data)||{status:"unknown"}},async getDiscoverRelationsStatus(){var s;return((s=(await de.get("/recipes/discover-relations/status")).data)==null?void 0:s.data)||{status:"idle"}},async deleteAllCandidatesInTarget(t){var r,i;const a=((i=(r=(await de.get(`/knowledge?category=${encodeURIComponent(t)}&limit=1000`)).data)==null?void 0:r.data)==null?void 0:i.data)||[];let l=0;for(const c of a)try{await de.delete(`/knowledge/${c.id}`),l++}catch{}return{deleted:l}},async promoteToCandidate(t,s){var r,i;const a=Ll(t,s,"review-promote");return{ok:!0,candidateId:((i=(r=(await de.post("/knowledge",a)).data)==null?void 0:r.data)==null?void 0:i.id)||""}},async getCandidateSimilarity(t,s){var l;return((l=(await de.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 de.post("/search/similarity",t).catch(()=>({data:{data:{similar:[]}}}))).data)==null?void 0:a.data)||{similar:[]}},async getRecipeContentByName(t){var o;const s=await It(t),l=(o=(await de.get(`/knowledge/${s}`)).data)==null?void 0:o.data;if(!l)throw new Error("Recipe not found");const i=qs(l).content,c=[i==null?void 0:i.pattern,i==null?void 0:i.markdown].filter(Boolean).join(`
8
8
 
@@ -29,9 +29,9 @@ Skill 文档格式要求:
29
29
  ## 使用场景
30
30
  ...
31
31
 
32
- 用户需求:${t}`,history:[]})).data)==null?void 0:l.data)||{reply:""}},async getLlmEnvConfig(){var s;return((s=(await de.get("/ai/env-config")).data)==null?void 0:s.data)||{vars:{},hasEnvFile:!1,llmReady:!1}},async getTokenUsage7Days(){var s;return((s=(await de.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 de.post("/ai/env-config",t)).data)==null?void 0:a.data)||{vars:{},hasEnvFile:!1,llmReady:!1}},async knowledgeList(t={}){var r;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((r=(await de.get(`/knowledge${a?`?${a}`:""}`)).data)==null?void 0:r.data)||{data:[],pagination:{page:1,pageSize:20,total:0}}},async knowledgeStats(){var s;return((s=(await de.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 de.get(`/knowledge/${t}`)).data)==null?void 0:a.data},async knowledgeCreate(t){var a;return(a=(await de.post("/knowledge",t)).data)==null?void 0:a.data},async knowledgeUpdate(t,s){var l;return(l=(await de.patch(`/knowledge/${t}`,s)).data)==null?void 0:l.data},async knowledgeDelete(t){await de.delete(`/knowledge/${t}`)},async knowledgeLifecycle(t,s,a){var r;return(r=(await de.patch(`/knowledge/${t}/${s}`,a?{reason:a}:{})).data)==null?void 0:r.data},async knowledgeBatchPublish(t){var a;return((a=(await de.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 de.post(`/knowledge/${t}/usage`,{type:s,feedback:a})},async knowledgeUpdateQuality(t){var a;return((a=(await de.patch(`/knowledge/${t}/quality`)).data)==null?void 0:a.data)||{quality:{}}},async wikiGenerate(){await de.post("/wiki/generate")},async wikiUpdate(){await de.post("/wiki/update")},async wikiAbort(){await de.post("/wiki/abort")},async wikiStatus(){var s;return((s=(await de.get("/wiki/status")).data)==null?void 0:s.data)||{task:{status:"idle"}}},async wikiFiles(){var s;return((s=(await de.get("/wiki/files")).data)==null?void 0:s.data)||{files:[],exists:!1}},async wikiFileContent(t){var a;return((a=(await de.get(`/wiki/file/${t}`)).data)==null?void 0:a.data)||{path:t,content:"",size:0}}},Pl=!1,gs="auth_token",fs="auth_user";function Fl(){const[t,s]=n.useState(()=>localStorage.getItem(gs)),[a,l]=n.useState(()=>{try{const g=localStorage.getItem(fs);return g?JSON.parse(g):null}catch{return null}}),[r,i]=n.useState(!1),c=n.useCallback(async(g,h)=>{var y,x,m,u;i(!0);try{const S=(await Wt.post("/api/v1/auth/login",{username:g,password:h})).data;if(S.success){const I=S.data.token,P=S.data.user??{username:g,role:"developer"};return localStorage.setItem(gs,I),localStorage.setItem(fs,JSON.stringify(P)),s(I),l(P),{success:!0}}return{success:!1,error:((y=S.error)==null?void 0:y.message)||"登录失败"}}catch(A){return{success:!1,error:((u=(m=(x=A.response)==null?void 0:x.data)==null?void 0:m.error)==null?void 0:u.message)||A.message||"网络错误"}}finally{i(!1)}},[]),o=n.useCallback(()=>{localStorage.removeItem(gs),localStorage.removeItem(fs),s(null),l(null)},[]);n.useEffect(()=>{},[]);const j=n.useMemo(()=>!0,[t,a]);return{authEnabled:Pl,isAuthenticated:j,isLoading:r,user:a,login:c,logout:o}}const Ol={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 Bl(t){const[s,a]=n.useState(()=>"developer"),[l,r]=n.useState("anonymous"),[i,c]=n.useState("probe"),[o,j]=n.useState(!0),[g,h]=n.useState(null),y=n.useCallback(async()=>{j(!0);try{const S=localStorage.getItem("auth_token"),I={};S&&(I.Authorization=`Bearer ${S}`);const P=await Wt.get("/api/v1/auth/probe",{headers:I});if(P.data.success){const B=P.data.data;a(B.role),r(B.user),c(B.mode),h(B.probeCache??null)}}catch{a("developer")}finally{j(!1)}},[]);n.useEffect(()=>{y()},[t,y]);const x=n.useCallback((S,I)=>{const P=Ol[s]||[];if(P.includes("*"))return!0;const B=I?`${S}:${I}`:S;if(P.includes(B))return!0;const R=S.split(":")[0];return!!(P.includes(`${R}:*`)||R==="read"&&P.includes("read:*"))},[s]),m=n.useMemo(()=>s==="developer",[s]),u=n.useMemo(()=>s==="developer",[s]),A=n.useMemo(()=>s!=="developer",[s]);return{role:s,user:l,mode:i,isLoading:o,isAdmin:m,canWrite:u,isReadOnly:A,can:x,probeCache:g,refresh:y}}let Mt=null;function As(){return Mt||(Mt=Ma(window.location.origin,{path:"/socket.io",transports:["websocket"],reconnection:!0,reconnectionAttempts:1/0,reconnectionDelay:2e3,reconnectionDelayMax:1e4}),Mt.on("connect",()=>{Mt.emit("join-notifications")})),Mt}const js={activeRound:0,round1:{status:"idle"},round2:{status:"idle"},round3:{status:"idle"}};function ql(){const[t,s]=n.useState(null),[a,l]=n.useState(!1),[r,i]=n.useState(js),[c,o]=n.useState(0),j=n.useRef(null),g=n.useRef(null);n.useEffect(()=>{const m=As(),u=()=>{l(!0),g.current&&clearTimeout(g.current),g.current=setTimeout(()=>S(),500)},A=()=>l(!1),S=async()=>{try{const f=await re.getBootstrapStatus();f&&f.status==="running"&&f.tasks&&s(w=>!w||w.id===f.id||f.progress>((w==null?void 0:w.progress)??0)?(j.current=f.id,f):w)}catch{}},I=()=>S(),P=f=>{j.current=f.sessionId,i(js),s({id:f.sessionId,status:"running",progress:0,total:f.total,completed:0,failed:0,filling:0,skeleton:f.total,startedAt:f.startedAt||Date.now(),totalToolCalls:0,elapsedMs:0,tasks:f.tasks.map(w=>({id:w.id,status:"skeleton",meta:{type:w.type,dimId:w.dimId,label:w.label,skillWorthy:w.skillWorthy,skillMeta:w.skillMeta}}))})},B=f=>{s(w=>{if(!w)return w;const Z=w.tasks.map(q=>q.id===f.taskId?{...q,status:"filling",startedAt:Date.now()}:q);return{...w,progress:f.progress,tasks:Z,filling:Z.filter(q=>q.status==="filling").length,skeleton:Z.filter(q=>q.status==="skeleton").length}})},R=f=>{var Z,q;s(ue=>{if(!ue)return ue;const M=ue.tasks.map(T=>T.id===f.taskId?{...T,status:"completed",completedAt:Date.now(),result:f.result}:T);return{...ue,progress:f.progress,completed:f.completed,total:f.total,totalToolCalls:f.totalToolCalls??ue.totalToolCalls,elapsedMs:f.elapsedMs??ue.elapsedMs,tasks:M,filling:M.filter(T=>T.status==="filling").length,skeleton:M.filter(T=>T.status==="skeleton").length}}),(Number((Z=f.result)==null?void 0:Z.created)||Number((q=f.result)==null?void 0:q.extracted)||0)>0&&o(ue=>ue+1)},K=f=>{s(w=>{if(!w)return w;const Z=w.tasks.map(q=>q.id===f.taskId?{...q,status:"failed",completedAt:Date.now(),error:f.error}:q);return{...w,progress:f.progress,failed:Z.filter(q=>q.status==="failed").length,tasks:Z,filling:Z.filter(q=>q.status==="filling").length,skeleton:Z.filter(q=>q.status==="skeleton").length}})},X=f=>{s(w=>{if(!w||f.sessionId&&w.id!==f.sessionId)return w;const Z=w.tasks.map(q=>q.status==="skeleton"||q.status==="filling"?{...q,status:"completed",completedAt:Date.now()}:q);return{...w,status:Z.some(q=>q.status==="failed")?"completed_with_errors":"completed",progress:100,completed:Z.filter(q=>q.status==="completed").length,summary:f.summary,tasks:Z,filling:0,skeleton:0}})},$=f=>{i(w=>({...w,activeRound:1,round1:{status:"running",total:f.total}}))},H=f=>{i(w=>({...w,activeRound:1,round1:{status:"completed",total:f.total,kept:f.kept,dropped:f.dropped,merged:f.merged}}))},C=f=>{i(w=>({...w,activeRound:2,round2:{status:"running",total:f.total}}))},p=f=>{i(w=>({...w,activeRound:2,round2:{...w.round2,status:"running",current:f.current,total:f.total,progress:f.progress}}))},O=f=>{i(w=>({...w,activeRound:2,round2:{status:"completed",total:f.total,refined:f.refined,progress:100}}))},k=f=>{i(w=>({...w,activeRound:3,round3:{status:"running",total:f.total}}))},b=f=>{i(w=>({...w,activeRound:3,round3:{status:"completed",total:f.total,afterDedup:f.afterDedup,relationsFound:f.relationsFound}}))};return m.on("connect",u),m.on("disconnect",A),m.io.on("reconnect",I),m.on("bootstrap:started",P),m.on("bootstrap:task-started",B),m.on("bootstrap:task-completed",R),m.on("bootstrap:task-failed",K),m.on("bootstrap:all-completed",X),m.on("review:round1-started",$),m.on("review:round1-completed",H),m.on("review:round2-started",C),m.on("review:round2-progress",p),m.on("review:round2-completed",O),m.on("review:round3-started",k),m.on("review:round3-completed",b),l(m.connected),m.connected&&S(),()=>{g.current&&clearTimeout(g.current),m.off("connect",u),m.off("disconnect",A),m.io.off("reconnect",I),m.off("bootstrap:started",P),m.off("bootstrap:task-started",B),m.off("bootstrap:task-completed",R),m.off("bootstrap:task-failed",K),m.off("bootstrap:all-completed",X),m.off("review:round1-started",$),m.off("review:round1-completed",H),m.off("review:round2-started",C),m.off("review:round2-progress",p),m.off("review:round2-completed",O),m.off("review:round3-started",k),m.off("review:round3-completed",b)}},[]);const h=n.useCallback(()=>{j.current=null,s(null),i(js)},[]),y=n.useCallback(m=>{m&&s(u=>{if(u&&u.id===m.id){const A=(u.filling??0)+(u.completed??0)+(u.failed??0),S=(m.filling??0)+(m.completed??0)+(m.failed??0);if(u.progress>m.progress||A>S)return u}return j.current=m.id,m})},[]),x=(t==null?void 0:t.status)==="completed"||(t==null?void 0:t.status)==="completed_with_errors";return{session:t,isConnected:a,isAllDone:x,reviewState:r,candidateCreatedTick:c,resetSession:h,initFromApiResponse:y}}const E={xs:12,sm:14,md:16,lg:20,xl:24,xxl:32,xxxl:48};function Hs(t){return t>=1e6?(t/1e6).toFixed(1)+"M":t>=1e3?(t/1e3).toFixed(1)+"k":String(t)}const Ws={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"}},Hl={token:Ja,probe:Xt},Wl=({activeTab:t,navigateToTab:s,candidateCount:a,signalSuggestionCount:l=0,isDarkMode:r=!1,currentUser:i,currentRole:c,permissionMode:o,onLogout:j,collapsed:g=!1,onToggleCollapse:h})=>{const y=Ws[c||""]||Ws.developer,x=Hl[o||"probe"]||Xt,[m,u]=n.useState(null),A=n.useCallback(()=>{re.getTokenUsage7Days().then(B=>u(B.summary)).catch(()=>{})},[]);n.useEffect(()=>{A();const B=As(),R=()=>A();return B.on("candidate-created",R),B.on("bootstrap:all-completed",R),B.on("token-usage-updated",R),()=>{B.off("candidate-created",R),B.off("bootstrap:all-completed",R),B.off("token-usage-updated",R)}},[A]);const S=[{tab:"recipes",icon:Ka,label:"Recipes"},{tab:"spm",icon:Et,label:"SPM Explorer"},{tab:"candidates",icon:it,label:`Candidates (${a})`},{tab:"knowledge",icon:da,label:"批量管理"},{tab:"depgraph",icon:Cs,label:"依赖关系图"},{tab:"knowledgegraph",icon:ys,label:"知识图谱"},{tab:"guard",icon:nt,label:"Guard"},{tab:"skills",icon:Ye,label:"Skills",badge:l>0?l:void 0,badgeColor:"bg-amber-100 text-amber-700"},{tab:"wiki",icon:et,label:"Repo Wiki"},{tab:"ai",icon:kt,label:"AI Assistant"},{tab:"editor",icon:bt,label:"编辑器(测试)"},{tab:"help",icon:Va,label:"使用说明"}],I=r?"bg-blue-900/30 text-blue-400 font-medium":"bg-blue-50 text-blue-700 font-medium",P=r?"text-slate-300 hover:bg-slate-700/50":"text-slate-600 hover:bg-slate-50";return e.jsxs("aside",{className:`${g?"w-16":"w-64"} ${r?"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:`${g?"px-3 py-4":"p-6"} border-b ${r?"border-[#3e3e42]":"border-slate-100"} flex items-center ${g?"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:E.lg})}),!g&&e.jsx("h1",{className:"font-bold text-lg truncate",children:"AutoSnippet"})]}),h&&!g&&e.jsx("button",{onClick:h,className:`p-1 rounded-md transition-colors ${r?"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(Ga,{size:16})})]}),g&&h&&e.jsx("div",{className:"flex justify-center py-2",children:e.jsx("button",{onClick:h,className:`p-1.5 rounded-md transition-colors ${r?"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(Ua,{size:16})})}),e.jsx("nav",{className:`flex-1 ${g?"px-2 py-2":"p-4"} space-y-1 overflow-y-auto scrollbar-light`,children:S.map(({tab:B,icon:R,label:K,badge:X,badgeColor:$})=>e.jsxs("button",{type:"button",onClick:()=>s(B),title:g?K:void 0,className:`w-full flex items-center ${g?"justify-center px-2 py-2.5 relative":"gap-3 px-4 py-2"} rounded-lg transition-colors ${t===B?I:P}`,children:[e.jsx(R,{size:E.lg,className:"shrink-0"}),!g&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"flex-1 text-left truncate text-[13px]",children:K}),X!=null&&e.jsxs("span",{className:`flex items-center gap-0.5 px-1.5 py-0.5 rounded-full text-[10px] font-bold ${$||"bg-blue-100 text-blue-700"}`,children:[e.jsx(Ue,{size:10}),X]})]}),g&&X!=null&&e.jsx("span",{className:"absolute top-0 right-0 w-2 h-2 rounded-full bg-amber-400"})]},B))}),e.jsxs("div",{className:`${g?"px-2 py-3":"p-4"} ${r?"border-t border-[#3e3e42]":"border-t border-slate-100"}`,children:[!g&&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 ${r?"bg-slate-700/30 border-slate-600 text-slate-400":y.bg+" "+y.color}`,children:[e.jsx(x,{size:E.xs}),e.jsx("span",{children:o==="token"?"登录":"探针"}),e.jsx("span",{className:"mx-0.5",children:"·"}),e.jsx(Ya,{size:E.xs}),e.jsx("span",{children:y.label})]}),i&&e.jsxs("div",{className:`flex items-center justify-between mb-3 px-2 py-1.5 rounded-lg ${r?"bg-slate-700/30":"bg-slate-50"}`,children:[e.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[e.jsx(ma,{size:E.sm,className:r?"text-slate-400":"text-slate-500"}),e.jsx("span",{className:`text-xs font-medium truncate ${r?"text-slate-300":"text-slate-600"}`,children:i})]}),j&&e.jsx("button",{onClick:j,title:"登出",className:`shrink-0 p-1 rounded transition-colors ${r?"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(Xa,{size:E.sm})})]})]}),m&&m.total_tokens>0&&e.jsxs("button",{onClick:()=>s("help"),title:g?`7日 Token: ${Hs(m.total_tokens)} (${m.call_count} 次 AI 调用)`:void 0,className:`w-full flex items-center ${g?"justify-center py-2 mb-1":"gap-2 px-2 py-1.5 mb-2"} rounded-lg transition-colors ${r?"bg-slate-700/30 hover:bg-slate-700/50 text-slate-400":"bg-amber-50 hover:bg-amber-100 text-amber-700"}`,children:[e.jsx(Je,{size:g?E.lg:E.sm,className:r?"text-amber-400":"text-amber-500"}),!g&&e.jsxs("div",{className:"flex flex-col items-start min-w-0",children:[e.jsx("span",{className:"text-[10px] font-bold uppercase tracking-wider",children:"7日 Token"}),e.jsxs("span",{className:`text-xs font-mono font-semibold ${r?"text-amber-300":"text-amber-800"}`,children:[Hs(m.total_tokens),e.jsxs("span",{className:`ml-1 text-[10px] font-normal ${r?"text-slate-500":"text-amber-600/70"}`,children:["(",m.call_count,"次调用)"]})]})]})]})]})]})},Gl={objectivec:"objectivec",objc:"objectivec","objective-c":"objectivec","obj-c":"objectivec",swift:"swift",markdown:"markdown",md:"markdown"};function _s(t){if(!t)return t;let s=t;!s.includes(`
32
+ 用户需求:${t}`,history:[]})).data)==null?void 0:l.data)||{reply:""}},async getLlmEnvConfig(){var s;return((s=(await de.get("/ai/env-config")).data)==null?void 0:s.data)||{vars:{},hasEnvFile:!1,llmReady:!1}},async getTokenUsage7Days(){var s;return((s=(await de.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 de.post("/ai/env-config",t)).data)==null?void 0:a.data)||{vars:{},hasEnvFile:!1,llmReady:!1}},async knowledgeList(t={}){var r;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((r=(await de.get(`/knowledge${a?`?${a}`:""}`)).data)==null?void 0:r.data)||{data:[],pagination:{page:1,pageSize:20,total:0}}},async knowledgeStats(){var s;return((s=(await de.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 de.get(`/knowledge/${t}`)).data)==null?void 0:a.data},async knowledgeCreate(t){var a;return(a=(await de.post("/knowledge",t)).data)==null?void 0:a.data},async knowledgeUpdate(t,s){var l;return(l=(await de.patch(`/knowledge/${t}`,s)).data)==null?void 0:l.data},async knowledgeDelete(t){await de.delete(`/knowledge/${t}`)},async knowledgeLifecycle(t,s,a){var r;return(r=(await de.patch(`/knowledge/${t}/${s}`,a?{reason:a}:{})).data)==null?void 0:r.data},async knowledgeBatchPublish(t){var a;return((a=(await de.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 de.post(`/knowledge/${t}/usage`,{type:s,feedback:a})},async knowledgeUpdateQuality(t){var a;return((a=(await de.patch(`/knowledge/${t}/quality`)).data)==null?void 0:a.data)||{quality:{}}},async wikiGenerate(){await de.post("/wiki/generate")},async wikiUpdate(){await de.post("/wiki/update")},async wikiAbort(){await de.post("/wiki/abort")},async wikiStatus(){var s;return((s=(await de.get("/wiki/status")).data)==null?void 0:s.data)||{task:{status:"idle"}}},async wikiFiles(){var s;return((s=(await de.get("/wiki/files")).data)==null?void 0:s.data)||{files:[],exists:!1}},async wikiFileContent(t){var a;return((a=(await de.get(`/wiki/file/${t}`)).data)==null?void 0:a.data)||{path:t,content:"",size:0}}},Pl=!1,gs="auth_token",fs="auth_user";function Fl(){const[t,s]=n.useState(()=>localStorage.getItem(gs)),[a,l]=n.useState(()=>{try{const g=localStorage.getItem(fs);return g?JSON.parse(g):null}catch{return null}}),[r,i]=n.useState(!1),c=n.useCallback(async(g,h)=>{var y,x,m,u;i(!0);try{const S=(await Gt.post("/api/v1/auth/login",{username:g,password:h})).data;if(S.success){const I=S.data.token,P=S.data.user??{username:g,role:"developer"};return localStorage.setItem(gs,I),localStorage.setItem(fs,JSON.stringify(P)),s(I),l(P),{success:!0}}return{success:!1,error:((y=S.error)==null?void 0:y.message)||"登录失败"}}catch(A){return{success:!1,error:((u=(m=(x=A.response)==null?void 0:x.data)==null?void 0:m.error)==null?void 0:u.message)||A.message||"网络错误"}}finally{i(!1)}},[]),o=n.useCallback(()=>{localStorage.removeItem(gs),localStorage.removeItem(fs),s(null),l(null)},[]);n.useEffect(()=>{},[]);const j=n.useMemo(()=>!0,[t,a]);return{authEnabled:Pl,isAuthenticated:j,isLoading:r,user:a,login:c,logout:o}}const Ol={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 Bl(t){const[s,a]=n.useState(()=>"developer"),[l,r]=n.useState("anonymous"),[i,c]=n.useState("probe"),[o,j]=n.useState(!0),[g,h]=n.useState(null),y=n.useCallback(async()=>{j(!0);try{const S=localStorage.getItem("auth_token"),I={};S&&(I.Authorization=`Bearer ${S}`);const P=await Gt.get("/api/v1/auth/probe",{headers:I});if(P.data.success){const B=P.data.data;a(B.role),r(B.user),c(B.mode),h(B.probeCache??null)}}catch{a("developer")}finally{j(!1)}},[]);n.useEffect(()=>{y()},[t,y]);const x=n.useCallback((S,I)=>{const P=Ol[s]||[];if(P.includes("*"))return!0;const B=I?`${S}:${I}`:S;if(P.includes(B))return!0;const R=S.split(":")[0];return!!(P.includes(`${R}:*`)||R==="read"&&P.includes("read:*"))},[s]),m=n.useMemo(()=>s==="developer",[s]),u=n.useMemo(()=>s==="developer",[s]),A=n.useMemo(()=>s!=="developer",[s]);return{role:s,user:l,mode:i,isLoading:o,isAdmin:m,canWrite:u,isReadOnly:A,can:x,probeCache:g,refresh:y}}let _t=null;function As(){return _t||(_t=_a(window.location.origin,{path:"/socket.io",transports:["websocket"],reconnection:!0,reconnectionAttempts:1/0,reconnectionDelay:2e3,reconnectionDelayMax:1e4}),_t.on("connect",()=>{_t.emit("join-notifications")})),_t}const js={activeRound:0,round1:{status:"idle"},round2:{status:"idle"},round3:{status:"idle"}};function ql(){const[t,s]=n.useState(null),[a,l]=n.useState(!1),[r,i]=n.useState(js),[c,o]=n.useState(0),j=n.useRef(null),g=n.useRef(null);n.useEffect(()=>{const m=As(),u=()=>{l(!0),g.current&&clearTimeout(g.current),g.current=setTimeout(()=>S(),500)},A=()=>l(!1),S=async()=>{try{const f=await re.getBootstrapStatus();f&&f.status==="running"&&f.tasks&&s(w=>!w||w.id===f.id||f.progress>((w==null?void 0:w.progress)??0)?(j.current=f.id,f):w)}catch{}},I=()=>S(),P=f=>{j.current=f.sessionId,i(js),s({id:f.sessionId,status:"running",progress:0,total:f.total,completed:0,failed:0,filling:0,skeleton:f.total,startedAt:f.startedAt||Date.now(),totalToolCalls:0,elapsedMs:0,tasks:f.tasks.map(w=>({id:w.id,status:"skeleton",meta:{type:w.type,dimId:w.dimId,label:w.label,skillWorthy:w.skillWorthy,skillMeta:w.skillMeta}}))})},B=f=>{s(w=>{if(!w)return w;const Z=w.tasks.map(q=>q.id===f.taskId?{...q,status:"filling",startedAt:Date.now()}:q);return{...w,progress:f.progress,tasks:Z,filling:Z.filter(q=>q.status==="filling").length,skeleton:Z.filter(q=>q.status==="skeleton").length}})},R=f=>{var Z,q;s(ue=>{if(!ue)return ue;const _=ue.tasks.map(M=>M.id===f.taskId?{...M,status:"completed",completedAt:Date.now(),result:f.result}:M);return{...ue,progress:f.progress,completed:f.completed,total:f.total,totalToolCalls:f.totalToolCalls??ue.totalToolCalls,elapsedMs:f.elapsedMs??ue.elapsedMs,tasks:_,filling:_.filter(M=>M.status==="filling").length,skeleton:_.filter(M=>M.status==="skeleton").length}}),(Number((Z=f.result)==null?void 0:Z.created)||Number((q=f.result)==null?void 0:q.extracted)||0)>0&&o(ue=>ue+1)},K=f=>{s(w=>{if(!w)return w;const Z=w.tasks.map(q=>q.id===f.taskId?{...q,status:"failed",completedAt:Date.now(),error:f.error}:q);return{...w,progress:f.progress,failed:Z.filter(q=>q.status==="failed").length,tasks:Z,filling:Z.filter(q=>q.status==="filling").length,skeleton:Z.filter(q=>q.status==="skeleton").length}})},X=f=>{s(w=>{if(!w||f.sessionId&&w.id!==f.sessionId)return w;const Z=w.tasks.map(q=>q.status==="skeleton"||q.status==="filling"?{...q,status:"completed",completedAt:Date.now()}:q);return{...w,status:Z.some(q=>q.status==="failed")?"completed_with_errors":"completed",progress:100,completed:Z.filter(q=>q.status==="completed").length,summary:f.summary,tasks:Z,filling:0,skeleton:0}})},$=f=>{i(w=>({...w,activeRound:1,round1:{status:"running",total:f.total}}))},H=f=>{i(w=>({...w,activeRound:1,round1:{status:"completed",total:f.total,kept:f.kept,dropped:f.dropped,merged:f.merged}}))},C=f=>{i(w=>({...w,activeRound:2,round2:{status:"running",total:f.total}}))},p=f=>{i(w=>({...w,activeRound:2,round2:{...w.round2,status:"running",current:f.current,total:f.total,progress:f.progress}}))},O=f=>{i(w=>({...w,activeRound:2,round2:{status:"completed",total:f.total,refined:f.refined,progress:100}}))},k=f=>{i(w=>({...w,activeRound:3,round3:{status:"running",total:f.total}}))},b=f=>{i(w=>({...w,activeRound:3,round3:{status:"completed",total:f.total,afterDedup:f.afterDedup,relationsFound:f.relationsFound}}))};return m.on("connect",u),m.on("disconnect",A),m.io.on("reconnect",I),m.on("bootstrap:started",P),m.on("bootstrap:task-started",B),m.on("bootstrap:task-completed",R),m.on("bootstrap:task-failed",K),m.on("bootstrap:all-completed",X),m.on("review:round1-started",$),m.on("review:round1-completed",H),m.on("review:round2-started",C),m.on("review:round2-progress",p),m.on("review:round2-completed",O),m.on("review:round3-started",k),m.on("review:round3-completed",b),l(m.connected),m.connected&&S(),()=>{g.current&&clearTimeout(g.current),m.off("connect",u),m.off("disconnect",A),m.io.off("reconnect",I),m.off("bootstrap:started",P),m.off("bootstrap:task-started",B),m.off("bootstrap:task-completed",R),m.off("bootstrap:task-failed",K),m.off("bootstrap:all-completed",X),m.off("review:round1-started",$),m.off("review:round1-completed",H),m.off("review:round2-started",C),m.off("review:round2-progress",p),m.off("review:round2-completed",O),m.off("review:round3-started",k),m.off("review:round3-completed",b)}},[]);const h=n.useCallback(()=>{j.current=null,s(null),i(js)},[]),y=n.useCallback(m=>{m&&s(u=>{if(u&&u.id===m.id){const A=(u.filling??0)+(u.completed??0)+(u.failed??0),S=(m.filling??0)+(m.completed??0)+(m.failed??0);if(u.progress>m.progress||A>S)return u}return j.current=m.id,m})},[]),x=(t==null?void 0:t.status)==="completed"||(t==null?void 0:t.status)==="completed_with_errors";return{session:t,isConnected:a,isAllDone:x,reviewState:r,candidateCreatedTick:c,resetSession:h,initFromApiResponse:y}}const T={xs:12,sm:14,md:16,lg:20,xl:24,xxl:32,xxxl:48};function Hs(t){return t>=1e6?(t/1e6).toFixed(1)+"M":t>=1e3?(t/1e3).toFixed(1)+"k":String(t)}const 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"}},Hl={token:Ja,probe:Xt},Gl=({activeTab:t,navigateToTab:s,candidateCount:a,signalSuggestionCount:l=0,isDarkMode:r=!1,currentUser:i,currentRole:c,permissionMode:o,onLogout:j,collapsed:g=!1,onToggleCollapse:h})=>{const y=Gs[c||""]||Gs.developer,x=Hl[o||"probe"]||Xt,[m,u]=n.useState(null),A=n.useCallback(()=>{re.getTokenUsage7Days().then(B=>u(B.summary)).catch(()=>{})},[]);n.useEffect(()=>{A();const B=As(),R=()=>A();return B.on("candidate-created",R),B.on("bootstrap:all-completed",R),B.on("token-usage-updated",R),()=>{B.off("candidate-created",R),B.off("bootstrap:all-completed",R),B.off("token-usage-updated",R)}},[A]);const S=[{tab:"recipes",icon:Ka,label:"Recipes"},{tab:"spm",icon:Tt,label:"SPM Explorer"},{tab:"candidates",icon:it,label:`Candidates (${a})`},{tab:"knowledge",icon:da,label:"批量管理"},{tab:"depgraph",icon:Cs,label:"依赖关系图"},{tab:"knowledgegraph",icon:ys,label:"知识图谱"},{tab:"guard",icon:nt,label:"Guard"},{tab:"skills",icon:Ye,label:"Skills",badge:l>0?l:void 0,badgeColor:"bg-amber-100 text-amber-700"},{tab:"wiki",icon:et,label:"Repo Wiki"},{tab:"ai",icon:kt,label:"AI Assistant"},{tab:"editor",icon:bt,label:"编辑器(测试)"},{tab:"help",icon:Va,label:"使用说明"}],I=r?"bg-blue-900/30 text-blue-400 font-medium":"bg-blue-50 text-blue-700 font-medium",P=r?"text-slate-300 hover:bg-slate-700/50":"text-slate-600 hover:bg-slate-50";return e.jsxs("aside",{className:`${g?"w-16":"w-64"} ${r?"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:`${g?"px-3 py-4":"p-6"} border-b ${r?"border-[#3e3e42]":"border-slate-100"} flex items-center ${g?"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:T.lg})}),!g&&e.jsx("h1",{className:"font-bold text-lg truncate",children:"AutoSnippet"})]}),h&&!g&&e.jsx("button",{onClick:h,className:`p-1 rounded-md transition-colors ${r?"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(Wa,{size:16})})]}),g&&h&&e.jsx("div",{className:"flex justify-center py-2",children:e.jsx("button",{onClick:h,className:`p-1.5 rounded-md transition-colors ${r?"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(Ua,{size:16})})}),e.jsx("nav",{className:`flex-1 ${g?"px-2 py-2":"p-4"} space-y-1 overflow-y-auto scrollbar-light`,children:S.map(({tab:B,icon:R,label:K,badge:X,badgeColor:$})=>e.jsxs("button",{type:"button",onClick:()=>s(B),title:g?K:void 0,className:`w-full flex items-center ${g?"justify-center px-2 py-2.5 relative":"gap-3 px-4 py-2"} rounded-lg transition-colors ${t===B?I:P}`,children:[e.jsx(R,{size:T.lg,className:"shrink-0"}),!g&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"flex-1 text-left truncate text-[13px]",children:K}),X!=null&&e.jsxs("span",{className:`flex items-center gap-0.5 px-1.5 py-0.5 rounded-full text-[10px] font-bold ${$||"bg-blue-100 text-blue-700"}`,children:[e.jsx(Ue,{size:10}),X]})]}),g&&X!=null&&e.jsx("span",{className:"absolute top-0 right-0 w-2 h-2 rounded-full bg-amber-400"})]},B))}),e.jsxs("div",{className:`${g?"px-2 py-3":"p-4"} ${r?"border-t border-[#3e3e42]":"border-t border-slate-100"}`,children:[!g&&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 ${r?"bg-slate-700/30 border-slate-600 text-slate-400":y.bg+" "+y.color}`,children:[e.jsx(x,{size:T.xs}),e.jsx("span",{children:o==="token"?"登录":"探针"}),e.jsx("span",{className:"mx-0.5",children:"·"}),e.jsx(Ya,{size:T.xs}),e.jsx("span",{children:y.label})]}),i&&e.jsxs("div",{className:`flex items-center justify-between mb-3 px-2 py-1.5 rounded-lg ${r?"bg-slate-700/30":"bg-slate-50"}`,children:[e.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[e.jsx(ma,{size:T.sm,className:r?"text-slate-400":"text-slate-500"}),e.jsx("span",{className:`text-xs font-medium truncate ${r?"text-slate-300":"text-slate-600"}`,children:i})]}),j&&e.jsx("button",{onClick:j,title:"登出",className:`shrink-0 p-1 rounded transition-colors ${r?"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(Xa,{size:T.sm})})]})]}),m&&m.total_tokens>0&&e.jsxs("button",{onClick:()=>s("help"),title:g?`7日 Token: ${Hs(m.total_tokens)} (${m.call_count} 次 AI 调用)`:void 0,className:`w-full flex items-center ${g?"justify-center py-2 mb-1":"gap-2 px-2 py-1.5 mb-2"} rounded-lg transition-colors ${r?"bg-slate-700/30 hover:bg-slate-700/50 text-slate-400":"bg-amber-50 hover:bg-amber-100 text-amber-700"}`,children:[e.jsx(Je,{size:g?T.lg:T.sm,className:r?"text-amber-400":"text-amber-500"}),!g&&e.jsxs("div",{className:"flex flex-col items-start min-w-0",children:[e.jsx("span",{className:"text-[10px] font-bold uppercase tracking-wider",children:"7日 Token"}),e.jsxs("span",{className:`text-xs font-mono font-semibold ${r?"text-amber-300":"text-amber-800"}`,children:[Hs(m.total_tokens),e.jsxs("span",{className:`ml-1 text-[10px] font-normal ${r?"text-slate-500":"text-amber-600/70"}`,children:["(",m.call_count,"次调用)"]})]})]})]})]})]})},Wl={objectivec:"objectivec",objc:"objectivec","objective-c":"objectivec","obj-c":"objectivec",swift:"swift",markdown:"markdown",md:"markdown"};function Es(t){if(!t)return t;let s=t;!s.includes(`
33
33
  `)&&s.includes("\\n")&&(s=s.replace(/\\n/g,`
34
- `));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 r=Gl[s==null?void 0:s.toLowerCase()]||(s==null?void 0:s.toLowerCase())||"text",i=a.includes("!rounded-none"),c=_s(t);return e.jsx("div",{className:`rounded-xl overflow-x-auto text-sm min-w-0 ${a}`,children:e.jsx(oa,{language:r,style:ia,showLineNumbers:l,customStyle:{margin:0,padding:"1rem 1.25rem",fontSize:"0.8125rem",lineHeight:1.5,borderRadius:i?0:"0.75rem",overflowX:"auto"},codeTagProps:{className:"language-highlighted",style:{fontFamily:"ui-monospace, monospace"}},PreTag:"div",children:c})})};let Gs=!1,Ul=0;function Kl(){Gs||(ca.initialize({startOnLoad:!1,theme:"default",securityLevel:"loose",fontFamily:"ui-sans-serif, system-ui, -apple-system, sans-serif"}),Gs=!0)}const va=({code:t})=>{const[s,a]=n.useState(""),[l,r]=n.useState("");return n.useEffect(()=>{let i=!1;const c=`mermaid_${Ul++}`;async function o(){var j;Kl();try{const{svg:g}=await ca.render(c,t.trim());i||(a(g),r(""))}catch(g){i||(r((g==null?void 0:g.message)||"Mermaid render failed"),a(""));try{(j=document.getElementById("d"+c))==null||j.remove()}catch{}}}return o(),()=>{i=!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 Vl(t){return!t||typeof t!="string"?t:t.replace(/\\\\n/g,`
34
+ `));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 r=Wl[s==null?void 0:s.toLowerCase()]||(s==null?void 0:s.toLowerCase())||"text",i=a.includes("!rounded-none"),c=Es(t);return e.jsx("div",{className:`rounded-xl overflow-x-auto text-sm min-w-0 ${a}`,children:e.jsx(oa,{language:r,style:ia,showLineNumbers:l,customStyle:{margin:0,padding:"1rem 1.25rem",fontSize:"0.8125rem",lineHeight:1.5,borderRadius:i?0:"0.75rem",overflowX:"auto"},codeTagProps:{className:"language-highlighted",style:{fontFamily:"ui-monospace, monospace"}},PreTag:"div",children:c})})};let Ws=!1,Ul=0;function Kl(){Ws||(ca.initialize({startOnLoad:!1,theme:"default",securityLevel:"loose",fontFamily:"ui-sans-serif, system-ui, -apple-system, sans-serif"}),Ws=!0)}const va=({code:t})=>{const[s,a]=n.useState(""),[l,r]=n.useState("");return n.useEffect(()=>{let i=!1;const c=`mermaid_${Ul++}`;async function o(){var j;Kl();try{const{svg:g}=await ca.render(c,t.trim());i||(a(g),r(""))}catch(g){i||(r((g==null?void 0:g.message)||"Mermaid render failed"),a(""));try{(j=document.getElementById("d"+c))==null||j.remove()}catch{}}}return o(),()=>{i=!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 Ts(t){return!t||typeof t!="string"?t:t.replace(/^---\r?\n[\s\S]*?\r?\n---\r?\n?/,"").trim()||t}function Vl(t){return!t||typeof t!="string"?t:t.replace(/\\\\n/g,`
35
35
  `)}function Jl(t){if(!t||typeof t!="string")return t;const s=t.split(`
36
36
  `),a=[];let l=!1;for(let r=0;r<s.length;r++){const i=s[r];if(/^\s*(`{3,}|~{3,})/.test(i)){l=!l,a.push(i);continue}if(l){a.push(i);continue}const c=s[r+1];i!==""&&c!==void 0&&c!==""?a.push(i+" "):a.push(i)}return a.join(`
37
37
  `)}const Yl=/^\s*(graph|flowchart|sequenceDiagram|classDiagram|stateDiagram|erDiagram|gantt|pie|gitGraph|mindmap|timeline|journey|quadrantChart|sankey|xychart|block)\b/i;function Xl(t){const s=[],a=t.split(`
@@ -40,7 +40,7 @@ Skill 文档格式要求:
40
40
  `)}),r=!1,c=[];continue}if(i&&g){i=!1,l.push(j);continue}r?c.push(j):l.push(j)}return r&&c.length>0&&s.push({type:"mermaid",content:c.join(`
41
41
  `)}),l.length>0&&s.push({type:"markdown",content:l.join(`
42
42
  `)}),s}const Zl=t=>({pre({children:s}){return e.jsx("div",{className:"min-w-0",children:s})},code({node:s,className:a,children:l,...r}){const i=/language-(\w+)/.exec(a||""),c=Array.isArray(l)?l.join(""):String(l),o=c.replace(/\n$/,""),j=c.includes(`
43
- `)||!!i;return j&&Yl.test(o)?e.jsx(va,{code:o}):j&&i?e.jsx(rt,{code:o,language:i[1],showLineNumbers:t}):j?e.jsx(rt,{code:o,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",...r,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 i,c,o,j;const l=a.node,r=((c=(i=l==null?void 0:l.children)==null?void 0:i[0])==null?void 0:c.type)==="element"&&((j=(o=l==null?void 0:l.children)==null?void 0:o[0])==null?void 0:j.tagName)==="input";return e.jsx("li",{className:`leading-7 ${r?"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"})}),mt=({content:t,className:s="",showLineNumbers:a=!1,stripFrontmatter:l=!1})=>{const r=n.useMemo(()=>Zl(a),[a]),i=n.useMemo(()=>{let c=l?Es(t):t;return c=Vl(c),c=Jl(c),Xl(c)},[t,l]);return e.jsx("div",{className:`markdown-body text-slate-700 ${s}`,children:i.map((c,o)=>c.type==="mermaid"?e.jsx(va,{code:c.content},`mermaid-${o}`):e.jsx(Ra,{remarkPlugins:[La],components:r,children:c.content},`md-${o}`))})},wa="asd-chat-topics",Ql=50;function er(){return Date.now().toString(36)+Math.random().toString(36).substring(2,8)}function tr(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 sr(){try{const t=localStorage.getItem(wa);if(!t)return[];const s=JSON.parse(t);return Array.isArray(s)?s:[]}catch{return[]}}function ar(t){try{const s=t.slice(0,Ql);localStorage.setItem(wa,JSON.stringify(s))}catch(s){console.warn("[ChatTopics] localStorage save failed:",s)}}function ka(){const[t,s]=n.useState(()=>sr()),[a,l]=n.useState(null),r=n.useRef(t);n.useEffect(()=>{r.current=t},[t]);const i=n.useCallback(x=>{s(m=>{const u=typeof x=="function"?x(m):x;return ar(u),u})},[]),c=n.useCallback(x=>{const m=er(),u={id:m,title:x||"新话题",messages:[],createdAt:Date.now(),updatedAt:Date.now()};return i(A=>[u,...A]),l(m),m},[i]),o=n.useCallback(x=>{i(m=>m.filter(u=>u.id!==x)),l(m=>m===x?null:m)},[i]),j=n.useCallback((x,m)=>{i(u=>{const A=u.findIndex(B=>B.id===x);if(A<0)return u;const S={...u[A],messages:m,updatedAt:Date.now()},I=tr(m);I!=="新话题"&&(S.title=I);const P=[...u];return P[A]=S,P.splice(A,1),P.unshift(S),P})},[i]),g=n.useCallback(x=>r.current.find(m=>m.id===x),[]),h=n.useCallback(x=>{l(x)},[]),y=t.find(x=>x.id===a)??null;return{topics:t,activeTopicId:a,activeTopic:y,createTopic:c,deleteTopic:o,saveTopic:j,getTopic:g,switchTopic:h,setActiveTopicId:l}}const lr={get_project_overview:"获取项目概况",list_project_structure:"浏览目录结构",read_project_file:"读取文件内容",search_project_code:"搜索代码",get_file_summary:"获取文件摘要",semantic_search_code:"语义搜索代码",get_class_hierarchy:"分析类继承关系",get_class_info:"获取类详情",get_protocol_info:"获取协议信息",get_method_overrides:"分析方法重写",get_category_map:"获取分类扩展",search_knowledge:"搜索知识库",search_recipes:"搜索代码片段",search_candidates:"搜索候选条目",get_recipe_detail:"获取片段详情",get_related_recipes:"查找关联片段",get_project_stats:"获取项目统计",knowledge_overview:"知识库概览",summarize_code:"生成代码摘要",ai_translate:"翻译文本",analyze_code:"分析代码",extract_recipes:"提取代码片段",enrich_candidate:"丰富候选内容",refine_bootstrap_candidates:"润色候选批次",check_duplicate:"查重检测",discover_relations:"发现关联关系",add_graph_edge:"添加知识图谱边",validate_candidate:"校验候选",quality_score:"质量评分",submit_knowledge:"提交知识条目",submit_with_check:"提交并查重",save_document:"保存文档",approve_candidate:"审批候选",reject_candidate:"驳回候选",publish_recipe:"发布片段",deprecate_recipe:"废弃片段",update_recipe:"更新片段",record_usage:"记录使用",guard_check_code:"代码规范检查",query_violations:"查询违规记录",generate_guard_rule:"生成守卫规则",list_guard_rules:"列出守卫规则",get_recommendations:"获取推荐",get_feedback_stats:"获取反馈统计",graph_impact_analysis:"影响分析",rebuild_index:"重建索引",query_audit_log:"查询审计日志",bootstrap_knowledge:"引导知识采集",load_skill:"加载技能",create_skill:"创建技能",suggest_skills:"推荐技能",plan_task:"规划任务",review_my_output:"自检输出质量",get_tool_details:"查看工具说明",get_previous_analysis:"回顾历史分析",note_finding:"记录发现",get_previous_evidence:"查阅已有证据"};function rr(t){return lr[t]||t}function nr(t,s){if(!s)return"";switch(t){case"read_project_file":{const a=s.filePath||(Array.isArray(s.filePaths)?s.filePaths[0]:"");if(!a)return"";const l=String(a).split("/").pop()||a,r=Array.isArray(s.filePaths)&&s.filePaths.length>1?` 等 ${s.filePaths.length} 个文件`:"";return`${l}${r}`}case"list_project_structure":{const a=s.directory||s.path||"";return a?String(a):""}case"search_project_code":{const a=s.patterns||s.pattern||s.query||"";return Array.isArray(a)?a.slice(0,2).join(", ")+(a.length>2?" …":""):String(a).slice(0,40)}case"semantic_search_code":case"search_knowledge":case"search_recipes":case"search_candidates":{const a=s.query||s.keyword||"";return String(a).slice(0,40)}case"get_class_info":case"get_protocol_info":return s.className||s.name||s.protocolName||"";case"get_file_summary":{const a=s.filePath||"";return a&&String(a).split("/").pop()||""}case"summarize_code":case"analyze_code":{const a=s.language||"";return a?`${a}`:""}case"get_class_hierarchy":return s.rootClass||"";case"check_duplicate":return s.title||"";default:return""}}function Us(t,s){const a=rr(t),l=nr(t,s);return l?`${a}: ${l}`:a}function Ca(t,s){const a=[],l=[];let r="";function i(o){s(j=>j.map(g=>g.id===t?{...g,content:o}:g))}function c(o){switch(o.type){case"step:start":{const j=o.phase==="user"?"":` [${o.phase}]`,g=a.length>0?a.join(`
43
+ `)||!!i;return j&&Yl.test(o)?e.jsx(va,{code:o}):j&&i?e.jsx(rt,{code:o,language:i[1],showLineNumbers:t}):j?e.jsx(rt,{code:o,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",...r,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 i,c,o,j;const l=a.node,r=((c=(i=l==null?void 0:l.children)==null?void 0:i[0])==null?void 0:c.type)==="element"&&((j=(o=l==null?void 0:l.children)==null?void 0:o[0])==null?void 0:j.tagName)==="input";return e.jsx("li",{className:`leading-7 ${r?"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"})}),mt=({content:t,className:s="",showLineNumbers:a=!1,stripFrontmatter:l=!1})=>{const r=n.useMemo(()=>Zl(a),[a]),i=n.useMemo(()=>{let c=l?Ts(t):t;return c=Vl(c),c=Jl(c),Xl(c)},[t,l]);return e.jsx("div",{className:`markdown-body text-slate-700 ${s}`,children:i.map((c,o)=>c.type==="mermaid"?e.jsx(va,{code:c.content},`mermaid-${o}`):e.jsx(Ra,{remarkPlugins:[La],components:r,children:c.content},`md-${o}`))})},wa="asd-chat-topics",Ql=50;function er(){return Date.now().toString(36)+Math.random().toString(36).substring(2,8)}function tr(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 sr(){try{const t=localStorage.getItem(wa);if(!t)return[];const s=JSON.parse(t);return Array.isArray(s)?s:[]}catch{return[]}}function ar(t){try{const s=t.slice(0,Ql);localStorage.setItem(wa,JSON.stringify(s))}catch(s){console.warn("[ChatTopics] localStorage save failed:",s)}}function ka(){const[t,s]=n.useState(()=>sr()),[a,l]=n.useState(null),r=n.useRef(t);n.useEffect(()=>{r.current=t},[t]);const i=n.useCallback(x=>{s(m=>{const u=typeof x=="function"?x(m):x;return ar(u),u})},[]),c=n.useCallback(x=>{const m=er(),u={id:m,title:x||"新话题",messages:[],createdAt:Date.now(),updatedAt:Date.now()};return i(A=>[u,...A]),l(m),m},[i]),o=n.useCallback(x=>{i(m=>m.filter(u=>u.id!==x)),l(m=>m===x?null:m)},[i]),j=n.useCallback((x,m)=>{i(u=>{const A=u.findIndex(B=>B.id===x);if(A<0)return u;const S={...u[A],messages:m,updatedAt:Date.now()},I=tr(m);I!=="新话题"&&(S.title=I);const P=[...u];return P[A]=S,P.splice(A,1),P.unshift(S),P})},[i]),g=n.useCallback(x=>r.current.find(m=>m.id===x),[]),h=n.useCallback(x=>{l(x)},[]),y=t.find(x=>x.id===a)??null;return{topics:t,activeTopicId:a,activeTopic:y,createTopic:c,deleteTopic:o,saveTopic:j,getTopic:g,switchTopic:h,setActiveTopicId:l}}const lr={get_project_overview:"获取项目概况",list_project_structure:"浏览目录结构",read_project_file:"读取文件内容",search_project_code:"搜索代码",get_file_summary:"获取文件摘要",semantic_search_code:"语义搜索代码",get_class_hierarchy:"分析类继承关系",get_class_info:"获取类详情",get_protocol_info:"获取协议信息",get_method_overrides:"分析方法重写",get_category_map:"获取分类扩展",search_knowledge:"搜索知识库",search_recipes:"搜索代码片段",search_candidates:"搜索候选条目",get_recipe_detail:"获取片段详情",get_related_recipes:"查找关联片段",get_project_stats:"获取项目统计",knowledge_overview:"知识库概览",summarize_code:"生成代码摘要",ai_translate:"翻译文本",analyze_code:"分析代码",extract_recipes:"提取代码片段",enrich_candidate:"丰富候选内容",refine_bootstrap_candidates:"润色候选批次",check_duplicate:"查重检测",discover_relations:"发现关联关系",add_graph_edge:"添加知识图谱边",validate_candidate:"校验候选",quality_score:"质量评分",submit_knowledge:"提交知识条目",submit_with_check:"提交并查重",save_document:"保存文档",approve_candidate:"审批候选",reject_candidate:"驳回候选",publish_recipe:"发布片段",deprecate_recipe:"废弃片段",update_recipe:"更新片段",record_usage:"记录使用",guard_check_code:"代码规范检查",query_violations:"查询违规记录",generate_guard_rule:"生成守卫规则",list_guard_rules:"列出守卫规则",get_recommendations:"获取推荐",get_feedback_stats:"获取反馈统计",graph_impact_analysis:"影响分析",rebuild_index:"重建索引",query_audit_log:"查询审计日志",bootstrap_knowledge:"引导知识采集",load_skill:"加载技能",create_skill:"创建技能",suggest_skills:"推荐技能",plan_task:"规划任务",review_my_output:"自检输出质量",get_tool_details:"查看工具说明",get_previous_analysis:"回顾历史分析",note_finding:"记录发现",get_previous_evidence:"查阅已有证据"};function rr(t){return lr[t]||t}function nr(t,s){if(!s)return"";switch(t){case"read_project_file":{const a=s.filePath||(Array.isArray(s.filePaths)?s.filePaths[0]:"");if(!a)return"";const l=String(a).split("/").pop()||a,r=Array.isArray(s.filePaths)&&s.filePaths.length>1?` 等 ${s.filePaths.length} 个文件`:"";return`${l}${r}`}case"list_project_structure":{const a=s.directory||s.path||"";return a?String(a):""}case"search_project_code":{const a=s.patterns||s.pattern||s.query||"";return Array.isArray(a)?a.slice(0,2).join(", ")+(a.length>2?" …":""):String(a).slice(0,40)}case"semantic_search_code":case"search_knowledge":case"search_recipes":case"search_candidates":{const a=s.query||s.keyword||"";return String(a).slice(0,40)}case"get_class_info":case"get_protocol_info":return s.className||s.name||s.protocolName||"";case"get_file_summary":{const a=s.filePath||"";return a&&String(a).split("/").pop()||""}case"summarize_code":case"analyze_code":{const a=s.language||"";return a?`${a}`:""}case"get_class_hierarchy":return s.rootClass||"";case"check_duplicate":return s.title||"";default:return""}}function Us(t,s){const a=rr(t),l=nr(t,s);return l?`${a}: ${l}`:a}function Ca(t,s){const a=[],l=[];let r="";function i(o){s(j=>j.map(g=>g.id===t?{...g,content:o}:g))}function c(o){switch(o.type){case"step:start":{const j=o.phase==="user"?"":` [${o.phase}]`,g=a.length>0?a.join(`
44
44
  `)+`
45
45
 
46
46
  🔄 第 ${o.step}/${o.maxSteps} 轮推理${j}...`:`🔄 第 ${o.step}/${o.maxSteps} 轮推理${j}...`;i(g);break}case"tool:start":{a.push(`🔧 ${Us(o.tool,o.args)}...`),l.push({tool:o.tool,args:o.args}),i(a.join(`
@@ -55,29 +55,29 @@ Skill 文档格式要求:
55
55
 
56
56
  当前摘要: ${P.description||"(无)"}
57
57
 
58
- **输入润色指令,AI 将根据你的指令定向修改候选内容**,下方有常用指令可直接点击使用。`,timestamp:Date.now()}]),u(""))},[g==null?void 0:g.currentIdx]);const R=n.useCallback(()=>{h(null),a(!0)},[]),K=n.useCallback(O=>{h({...O,currentIdx:0}),x(new Set),r([]),A.current=[],a(!0)},[]),X=n.useCallback(()=>a(!1),[]),$=n.useCallback(()=>a(O=>!O),[]),H=n.useCallback(()=>{r([]),A.current=[],u(""),h(null),x(new Set)},[]),C={openChat:R,openRefine:K,close:X,toggle:$,newTopic:H,isOpen:s},p={messages:l,setMessages:r,loading:i,setLoading:c,applying:o,setApplying:j,refineCtx:g,setRefineCtx:h,applied:y,setApplied:x,lastPrompt:m,setLastPrompt:u,chatHistoryRef:A,isRefineMode:S,currentRefineId:I,currentRefineCandidate:P,isBatchRefine:B,close:X};return e.jsx(Sa.Provider,{value:C,children:e.jsx(Ia.Provider,{value:p,children:t})})},xr=()=>{const t=n.useContext(Ia),{messages:s,setMessages:a,loading:l,setLoading:r,applying:i,setApplying:c,refineCtx:o,setRefineCtx:j,applied:g,setApplied:h,lastPrompt:y,setLastPrompt:x,chatHistoryRef:m,isRefineMode:u,currentRefineId:A,currentRefineCandidate:S,isBatchRefine:I,close:P}=t,B=n.useRef(null),R=n.useRef(null),[K,X]=n.useState(""),$=ka(),H=n.useRef(null),C=n.useRef(!1);n.useEffect(()=>{if(u&&S){C.current=!0;const M=$.createTopic(`润色: ${S.title||"未命名"}`);H.current=M,setTimeout(()=>{C.current=!1},50)}},[o]),n.useEffect(()=>{C.current||H.current&&s.length>0&&$.saveTopic(H.current,s)},[s]);const p=n.useCallback(()=>{if(!H.current){C.current=!0;const M=$.createTopic();H.current=M,setTimeout(()=>{C.current=!1},50)}},[$]);n.useEffect(()=>{var M;(M=B.current)==null||M.scrollIntoView({behavior:"smooth"})},[s,l]),n.useEffect(()=>{setTimeout(()=>{var M;return(M=R.current)==null?void 0:M.focus()},200)},[]);const O=u&&A&&s.some(M=>{if(M.role!=="assistant"||!M.diff||M.diff.length===0)return!1;const T=M.excludedFields||[];return M.diff.some(ee=>!T.includes(ee.field))})&&!g.has(A),k=n.useCallback((M,T)=>{a(ee=>ee.map(J=>{if(J.id!==M)return J;const se=J.excludedFields||[],V=se.includes(T)?se.filter(Q=>Q!==T):[...se,T];return{...J,excludedFields:V}}))},[]),b=n.useRef(null),f=n.useCallback(async()=>{const M=K.trim();if(!(!M||l)){if(u||p(),X(""),a(T=>[...T,{id:$t(),role:"user",content:M,timestamp:Date.now()}]),r(!0),u&&A){x(M);const T=$t();a(J=>[...J,{id:T,role:"assistant",content:"🔄 AI 润色中...",timestamp:Date.now()}]);const ee=new AbortController;b.current=ee;try{const J=await re.refinePreviewStream(A,M,Q=>{if(Q.type==="data:progress"){const ae=Q.message||Q.stage||"处理中...";a(ye=>ye.map(Se=>Se.id===T?{...Se,content:`🔄 ${ae}`}:Se))}},ee.signal),se=J.before||(S?Ks(S):{}),V=ir(se,J.after||{});a(Q=>Q.map(ae=>ae.id===T?{...ae,content:V.length>0?`已生成润色预览,共 ${V.length} 个字段变更(可单独关闭变更):`:"未检测到变更,请尝试更具体的指令。",diff:V.length>0?V:void 0,preview:V.length>0?J.preview??void 0:void 0,excludedFields:[]}:ae))}catch(J){J.name==="AbortError"?a(se=>se.map(V=>V.id===T?{...V,content:"(已取消)"}:V)):a(se=>se.map(V=>{var Q,ae;return V.id===T?{...V,content:`润色预览失败: ${((ae=(Q=J.response)==null?void 0:Q.data)==null?void 0:ae.error)||J.message}`}:V}))}finally{b.current=null}}else{m.current.push({role:"user",content:M});const T=$t();a(Q=>[...Q,{id:T,role:"assistant",content:"🔄 AI 思考中...",timestamp:Date.now()}]);const ee=new AbortController;b.current=ee;const{onEvent:J,getState:se}=Ca(T,a);let V="";try{const ae=(await re.chatStream(M,m.current,ye=>{J(ye),V=se().answerText},ee.signal)).text||V;m.current.push({role:"model",content:ae}),a(ye=>ye.map(Se=>Se.id===T?{...Se,content:ae}:Se))}catch(Q){if(Q.name==="AbortError"){const{answerText:ae,toolLogs:ye}=se(),Se=ae||(ye.length>0?ye.join(`
58
+ **输入润色指令,AI 将根据你的指令定向修改候选内容**,下方有常用指令可直接点击使用。`,timestamp:Date.now()}]),u(""))},[g==null?void 0:g.currentIdx]);const R=n.useCallback(()=>{h(null),a(!0)},[]),K=n.useCallback(O=>{h({...O,currentIdx:0}),x(new Set),r([]),A.current=[],a(!0)},[]),X=n.useCallback(()=>a(!1),[]),$=n.useCallback(()=>a(O=>!O),[]),H=n.useCallback(()=>{r([]),A.current=[],u(""),h(null),x(new Set)},[]),C={openChat:R,openRefine:K,close:X,toggle:$,newTopic:H,isOpen:s},p={messages:l,setMessages:r,loading:i,setLoading:c,applying:o,setApplying:j,refineCtx:g,setRefineCtx:h,applied:y,setApplied:x,lastPrompt:m,setLastPrompt:u,chatHistoryRef:A,isRefineMode:S,currentRefineId:I,currentRefineCandidate:P,isBatchRefine:B,close:X};return e.jsx(Sa.Provider,{value:C,children:e.jsx(Ia.Provider,{value:p,children:t})})},xr=()=>{const t=n.useContext(Ia),{messages:s,setMessages:a,loading:l,setLoading:r,applying:i,setApplying:c,refineCtx:o,setRefineCtx:j,applied:g,setApplied:h,lastPrompt:y,setLastPrompt:x,chatHistoryRef:m,isRefineMode:u,currentRefineId:A,currentRefineCandidate:S,isBatchRefine:I,close:P}=t,B=n.useRef(null),R=n.useRef(null),[K,X]=n.useState(""),$=ka(),H=n.useRef(null),C=n.useRef(!1);n.useEffect(()=>{if(u&&S){C.current=!0;const _=$.createTopic(`润色: ${S.title||"未命名"}`);H.current=_,setTimeout(()=>{C.current=!1},50)}},[o]),n.useEffect(()=>{C.current||H.current&&s.length>0&&$.saveTopic(H.current,s)},[s]);const p=n.useCallback(()=>{if(!H.current){C.current=!0;const _=$.createTopic();H.current=_,setTimeout(()=>{C.current=!1},50)}},[$]);n.useEffect(()=>{var _;(_=B.current)==null||_.scrollIntoView({behavior:"smooth"})},[s,l]),n.useEffect(()=>{setTimeout(()=>{var _;return(_=R.current)==null?void 0:_.focus()},200)},[]);const O=u&&A&&s.some(_=>{if(_.role!=="assistant"||!_.diff||_.diff.length===0)return!1;const M=_.excludedFields||[];return _.diff.some(ee=>!M.includes(ee.field))})&&!g.has(A),k=n.useCallback((_,M)=>{a(ee=>ee.map(J=>{if(J.id!==_)return J;const se=J.excludedFields||[],V=se.includes(M)?se.filter(Q=>Q!==M):[...se,M];return{...J,excludedFields:V}}))},[]),b=n.useRef(null),f=n.useCallback(async()=>{const _=K.trim();if(!(!_||l)){if(u||p(),X(""),a(M=>[...M,{id:$t(),role:"user",content:_,timestamp:Date.now()}]),r(!0),u&&A){x(_);const M=$t();a(J=>[...J,{id:M,role:"assistant",content:"🔄 AI 润色中...",timestamp:Date.now()}]);const ee=new AbortController;b.current=ee;try{const J=await re.refinePreviewStream(A,_,Q=>{if(Q.type==="data:progress"){const ae=Q.message||Q.stage||"处理中...";a(ye=>ye.map(Se=>Se.id===M?{...Se,content:`🔄 ${ae}`}:Se))}},ee.signal),se=J.before||(S?Ks(S):{}),V=ir(se,J.after||{});a(Q=>Q.map(ae=>ae.id===M?{...ae,content:V.length>0?`已生成润色预览,共 ${V.length} 个字段变更(可单独关闭变更):`:"未检测到变更,请尝试更具体的指令。",diff:V.length>0?V:void 0,preview:V.length>0?J.preview??void 0:void 0,excludedFields:[]}:ae))}catch(J){J.name==="AbortError"?a(se=>se.map(V=>V.id===M?{...V,content:"(已取消)"}:V)):a(se=>se.map(V=>{var Q,ae;return V.id===M?{...V,content:`润色预览失败: ${((ae=(Q=J.response)==null?void 0:Q.data)==null?void 0:ae.error)||J.message}`}:V}))}finally{b.current=null}}else{m.current.push({role:"user",content:_});const M=$t();a(Q=>[...Q,{id:M,role:"assistant",content:"🔄 AI 思考中...",timestamp:Date.now()}]);const ee=new AbortController;b.current=ee;const{onEvent:J,getState:se}=Ca(M,a);let V="";try{const ae=(await re.chatStream(_,m.current,ye=>{J(ye),V=se().answerText},ee.signal)).text||V;m.current.push({role:"model",content:ae}),a(ye=>ye.map(Se=>Se.id===M?{...Se,content:ae}:Se))}catch(Q){if(Q.name==="AbortError"){const{answerText:ae,toolLogs:ye}=se(),Se=ae||(ye.length>0?ye.join(`
59
59
  `)+`
60
60
 
61
- (已取消)`:"(已取消)");ae&&m.current.push({role:"model",content:ae}),a(De=>De.map(D=>D.id===T?{...D,content:Se}:D))}else a(ae=>ae.map(ye=>ye.id===T?{...ye,content:`请求失败: ${Q.message}`}:ye))}finally{b.current=null}}r(!1)}},[K,l,u,A,S,p]),w=n.useCallback(async()=>{var M,T,ee,J;if(!(i||!A||!o)){c(!0);try{const se=[...s].reverse().find(Q=>Q.role==="assistant"&&Q.preview);let V=se==null?void 0:se.preview;if(V&&((M=se==null?void 0:se.excludedFields)!=null&&M.length)&&se.diff){V={...V};const Q=S?Ks(S):{};for(const ae of se.excludedFields)ae in Q&&(V[ae]=Q[ae])}await re.refineApply(A,y,V),h(Q=>new Set(Q).add(A)),(T=o.onCandidateUpdated)==null||T.call(o,A),a(Q=>[...Q,{id:$t(),role:"system",content:"✅ 变更已应用到候选!",timestamp:Date.now()}]),le("候选内容已更新为润色后版本",{title:"润色已应用"})}catch(se){const V=(J=(ee=se.response)==null?void 0:ee.data)==null?void 0:J.error;le(typeof V=="string"?V:(V==null?void 0:V.message)||se.message,{title:"应用失败",type:"error"})}finally{c(!1)}}},[i,A,y,o]),Z=n.useCallback(()=>{!o||o.currentIdx>=o.candidateIds.length-1||j(M=>M?{...M,currentIdx:M.currentIdx+1}:null)},[o]),q=n.useCallback(()=>{H.current=null,j(null),a(M=>[...M,{id:$t(),role:"system",content:"已退出润色模式,回到通用对话。",timestamp:Date.now()}])},[]),ue=n.useCallback(M=>{M.key==="Enter"&&!M.shiftKey&&(M.preventDefault(),f())},[f]);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:u?e.jsx(Ue,{className:"text-emerald-500",size:16}):e.jsx(kt,{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:[u?"AI 润色":"AI Chat",u&&I&&e.jsxs("span",{className:"text-[10px] px-1.5 py-0.5 rounded-full bg-emerald-50 text-emerald-600 font-medium",children:[((o==null?void 0:o.currentIdx)??0)+1,"/",o==null?void 0:o.candidateIds.length]})]}),e.jsx("p",{className:"text-[10px] text-slate-400 truncate max-w-[250px]",children:u?(S==null?void 0:S.title)||"润色中...":"询问任何关于项目的问题"})]})]}),e.jsxs("div",{className:"flex items-center gap-1",children:[u&&e.jsx("button",{onClick:q,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:"退出润色"}),!u&&s.length>0&&e.jsx("button",{onClick:()=>{H.current=null,a([]),m.current=[],x("")},className:"p-1.5 hover:bg-slate-100 rounded-lg transition-colors",title:"开启新话题",children:e.jsx(gt,{size:16,className:"text-slate-400"})}),e.jsx("button",{onClick:P,className:"p-1.5 hover:bg-slate-100 rounded-lg transition-colors",title:"关闭 AI Chat",children:e.jsx(Ke,{size:16,className:"text-slate-400"})})]})]}),u&&S&&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:S.title}),S.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:S.language})]})}),e.jsxs("div",{className:"flex-1 overflow-y-auto p-4 space-y-3 min-h-0 scrollbar-light",children:[s.length===0&&!u&&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(kt,{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(M=>e.jsx("button",{onClick:()=>{var T;X(M),(T=R.current)==null||T.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:M},M))})]}),u&&s.length<=1&&e.jsx("div",{className:"flex flex-wrap gap-1.5 mt-2",children:["增加具体使用案例,不要修改其他内容","优化代码注释和说明","补充常见错误用法和注意事项","提升摘要质量,更简洁专业","补充性能注意事项"].map(M=>e.jsx("button",{onClick:()=>{var T;X(M),(T=R.current)==null||T.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:M},M))}),s.map(M=>e.jsx("div",{className:`flex ${M.role==="user"?"justify-end":"justify-start"}`,children:e.jsxs("div",{className:`max-w-[95%] ${M.role==="user"?"bg-blue-600 text-white rounded-2xl rounded-tr-md px-3.5 py-2":M.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:[M.role==="assistant"&&e.jsxs("div",{className:"flex items-center gap-1.5 mb-1.5",children:[e.jsx(Jt,{size:12,className:u?"text-emerald-500":"text-blue-500"}),e.jsx("span",{className:`text-[10px] font-bold ${u?"text-emerald-600":"text-blue-600"}`,children:u?"AI 润色助手":"AI 助手"})]}),M.role==="assistant"&&!M.diff?e.jsx(mt,{content:M.content,className:"text-xs text-slate-700"}):e.jsx("p",{className:`text-xs leading-relaxed whitespace-pre-wrap ${M.role==="user"?"":M.role==="system"?"text-slate-500":"text-slate-700"}`,children:M.content}),M.diff&&M.diff.length>0&&e.jsx(cr,{diff:M.diff,excludedFields:M.excludedFields,onToggleField:u&&!g.has(A)?T=>k(M.id,T):void 0})]})},M.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(Ee,{size:12,className:`animate-spin ${u?"text-emerald-500":"text-blue-500"}`}),e.jsx("span",{className:"text-xs text-slate-500",children:u?"AI 正在分析...":"AI 思考中..."}),b.current&&e.jsx("button",{onClick:()=>{var M;return(M=b.current)==null?void 0:M.abort()},className:"ml-1 px-1.5 py-0.5 text-[10px] font-bold text-red-500 border border-red-200 rounded hover:bg-red-50 transition-colors",children:"停止"})]})})}),e.jsx("div",{ref:B})]}),u&&O&&!l&&(()=>{var se,V;const M=[...s].reverse().find(Q=>Q.role==="assistant"&&Q.diff&&Q.diff.length>0),T=((se=M==null?void 0:M.diff)==null?void 0:se.length)||0,ee=((V=M==null?void 0:M.excludedFields)==null?void 0:V.length)||0,J=T-ee;return 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:w,disabled:i,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:[i?e.jsx(Ee,{size:11,className:"animate-spin"}):e.jsx(ft,{size:11}),i?"应用中...":ee>0?`确认应用 (${J}/${T})`:"确认应用"]}),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(ua,{size:11})," 继续调整"]}),I&&g.has(A)&&o.currentIdx<o.candidateIds.length-1&&e.jsxs("button",{onClick:Z,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(st,{size:11})]})]})})(),u&&!O&&!l&&I&&g.has(A)&&o.currentIdx<o.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:Z,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:["下一条 (",((o==null?void 0:o.currentIdx)??0)+2,"/",o==null?void 0:o.candidateIds.length,") ",e.jsx(st,{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:R,value:K,onChange:M=>X(M.target.value),onKeyDown:ue,placeholder:u?'输入定向润色指令,如"增加使用案例"、"优化摘要"...':"输入你的问题...",rows:2,className:`flex-1 px-3 py-2 text-sm border border-slate-200 rounded-xl focus:outline-none focus:ring-2 ${u?"focus:ring-emerald-200 focus:border-emerald-400":"focus:ring-blue-200 focus:border-blue-400"} resize-none placeholder:text-slate-300`,disabled:l||i}),e.jsx("button",{onClick:f,disabled:!K.trim()||l||i,className:`self-stretch w-9 flex items-center justify-center rounded-xl bg-gradient-to-r ${u?"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:u?"Enter 发送 · Shift+Enter 换行 · 先预览再应用":"Enter 发送 · Shift+Enter 换行"})]})]})},mr=({searchQuery:t,setSearchQuery:s,setShowCreateModal:a,handleSyncToXcode:l,aiConfig:r,llmReady:i=!0,onOpenLlmConfig:c,onSemanticSearchResults:o,onBeforeAiSwitch:j,onAiConfigChange:g,isDarkMode:h=!1})=>{const{toggle:y,isOpen:x}=ts(),[m,u]=n.useState(!1),[A,S]=n.useState(!1),[I,P]=n.useState([]),[B,R]=n.useState(!1),K=n.useRef(null);n.useEffect(()=>{A&&I.length===0&&re.getAiProviders().then(H=>P(H)).catch(()=>{})},[A,I.length]),n.useEffect(()=>{const H=C=>{K.current&&!K.current.contains(C.target)&&S(!1)};return document.addEventListener("click",H),()=>document.removeEventListener("click",H)},[]);const X=async()=>{if(t){u(!0);try{const C=((await re.search(t,{mode:"semantic"})).items||[]).map(p=>{var O,k,b;return{name:(p.title||p.name||"")+".md",content:((O=p.content)==null?void 0:O.pattern)||((k=p.content)==null?void 0:k.markdown)||((b=p.content)==null?void 0:b.code)||"",similarity:p.score||0,metadata:{type:"recipe",name:(p.title||p.name||"")+".md"}}});o&&o(C)}catch(H){console.error("Semantic search failed",H),alert("语义搜索失败。请确保已运行 asd embed 构建索引。")}finally{u(!1)}}},$=async H=>{R(!0);try{j==null||j(),await re.setAiConfig(H.id,H.defaultModel),S(!1),g&&g()}catch(C){console.error("AI config update failed",C),alert("切换 AI 失败,请检查项目根目录是否可写。")}finally{R(!1)}};return e.jsxs("header",{className:`h-16 ${h?"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(dt,{className:`absolute left-3 top-1/2 -translate-y-1/2 ${h?"text-slate-500":"text-slate-400"}`,size:E.md}),e.jsx("input",{type:"text",placeholder:"Search knowledge...",className:`w-full pl-10 pr-4 py-2 ${h?"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:H=>s(H.target.value),onKeyDown:H=>H.key==="Enter"&&X()})]}),e.jsxs("button",{onClick:X,disabled:!t||m,className:`flex items-center gap-2 px-3 py-2 rounded-lg text-xs font-bold transition-all ${m?"bg-blue-50 text-blue-400":"bg-blue-50 text-blue-600 hover:bg-blue-100"}`,title:"Semantic Search (Brain AI)",children:[m?e.jsx(Ee,{size:E.sm,className:"animate-spin"}):e.jsx(Za,{size:E.sm}),"Semantic"]})]}),e.jsxs("div",{className:"flex items-center gap-4",children:[i?r?e.jsxs("div",{className:"relative",ref:K,children:[e.jsxs("button",{type:"button",onClick:H=>{H.stopPropagation(),S(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(Yt,{size:E.sm}),r.provider," / ",r.model,e.jsx(Ct,{size:E.xs,className:A?"rotate-180":""})]}),A&&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:()=>{S(!1),c==null||c()},className:"text-blue-500 hover:underline",children:"修改 .env 配置"})}),I.length===0?e.jsx("div",{className:"px-3 py-2 text-xs text-slate-400",children:"加载中..."}):I.map(H=>e.jsxs("button",{type:"button",disabled:B,onClick:()=>$(H),className:`w-full text-left px-3 py-2 text-sm hover:bg-slate-50 flex items-center justify-between ${r.provider===H.id?"bg-blue-50 text-blue-700 font-medium":"text-slate-700"}`,children:[e.jsx("span",{children:H.label}),r.provider===H.id&&e.jsx("span",{className:"text-xs",children:"✓"})]},H.id))]})]}):null:e.jsxs("button",{type:"button",onClick:c,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(ha,{size:E.sm}),"配置 LLM"]}),e.jsxs("button",{onClick:y,className:`flex items-center gap-2 px-3 py-2 rounded-lg text-sm font-medium transition-colors ${x?"bg-blue-100 text-blue-700 ring-1 ring-blue-200":h?"bg-slate-700 text-slate-300 hover:bg-slate-600":"bg-slate-100 text-slate-600 hover:bg-slate-200"}`,title:x?"关闭 AI Chat":"打开 AI Chat",children:[e.jsx(kt,{size:E.sm}),!x&&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(gt,{size:E.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(pt,{size:E.md})," Sync to Xcode"]})]})]})},ur=({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 r=l.icon,i=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
62
- ${i?`${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(r,{size:E.xs}),a]},a)})})}),$a="asd-drawer-wide";function pr(){try{return localStorage.getItem($a)==="1"}catch{return!1}}function Ts(){const[t,s]=n.useState(pr),a=n.useCallback(()=>{s(l=>{const r=!l;try{localStorage.setItem($a,r?"1":"0")}catch{}return r})},[]);return{isWide:t,toggle:a}}const Ms=({currentPage:t,totalPages:s,totalItems:a,pageSize:l,onPageChange:r,onPageSizeChange:i,pageSizeOptions:c=[12,24,48,96]})=>{if(s<=1&&a<=c[0])return null;const o=(t-1)*l+1,j=Math.min(t*l,a),g=()=>{const h=[];if(s<=7)for(let x=1;x<=s;x++)h.push(x);else if(t<=3){for(let x=1;x<=5;x++)h.push(x);h.push("..."),h.push(s)}else if(t>=s-2){h.push(1),h.push("...");for(let x=s-5+1;x<=s;x++)h.push(x)}else{h.push(1),h.push("...");for(let x=t-1;x<=t+1;x++)h.push(x);h.push("..."),h.push(s)}return h};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:["显示 ",o,"-",j,",共 ",a," 条"]}),i&&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:h=>i(Number(h.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:c.map(h=>e.jsx("option",{value:h,children:h},h))}),e.jsx("span",{className:"text-sm text-slate-500",children:"条"})]})]}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("button",{onClick:()=>r(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(Qa,{size:E.md,className:"text-slate-600"})}),e.jsx("button",{onClick:()=>r(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:E.md,className:"text-slate-600"})}),e.jsx("div",{className:"flex items-center gap-1 mx-2",children:g().map((h,y)=>typeof h=="number"?e.jsx("button",{onClick:()=>r(h),className:`min-w-[32px] h-8 px-2 rounded-md text-sm font-medium transition-colors ${t===h?"bg-blue-600 text-white":"hover:bg-slate-100 text-slate-600"}`,children:h},y):e.jsx("span",{className:"px-1 text-slate-400",children:h},y))}),e.jsx("button",{onClick:()=>r(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(st,{size:E.md,className:"text-slate-600"})}),e.jsx("button",{onClick:()=>r(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(el,{size:E.md,className:"text-slate-600"})})]})]})},hr=St.memo(({code:t,lang:s,editorStyles:a})=>e.jsx(oa,{language:s,style:ia,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]===`
61
+ (已取消)`:"(已取消)");ae&&m.current.push({role:"model",content:ae}),a(De=>De.map(D=>D.id===M?{...D,content:Se}:D))}else a(ae=>ae.map(ye=>ye.id===M?{...ye,content:`请求失败: ${Q.message}`}:ye))}finally{b.current=null}}r(!1)}},[K,l,u,A,S,p]),w=n.useCallback(async()=>{var _,M,ee,J;if(!(i||!A||!o)){c(!0);try{const se=[...s].reverse().find(Q=>Q.role==="assistant"&&Q.preview);let V=se==null?void 0:se.preview;if(V&&((_=se==null?void 0:se.excludedFields)!=null&&_.length)&&se.diff){V={...V};const Q=S?Ks(S):{};for(const ae of se.excludedFields)ae in Q&&(V[ae]=Q[ae])}await re.refineApply(A,y,V),h(Q=>new Set(Q).add(A)),(M=o.onCandidateUpdated)==null||M.call(o,A),a(Q=>[...Q,{id:$t(),role:"system",content:"✅ 变更已应用到候选!",timestamp:Date.now()}]),le("候选内容已更新为润色后版本",{title:"润色已应用"})}catch(se){const V=(J=(ee=se.response)==null?void 0:ee.data)==null?void 0:J.error;le(typeof V=="string"?V:(V==null?void 0:V.message)||se.message,{title:"应用失败",type:"error"})}finally{c(!1)}}},[i,A,y,o]),Z=n.useCallback(()=>{!o||o.currentIdx>=o.candidateIds.length-1||j(_=>_?{..._,currentIdx:_.currentIdx+1}:null)},[o]),q=n.useCallback(()=>{H.current=null,j(null),a(_=>[..._,{id:$t(),role:"system",content:"已退出润色模式,回到通用对话。",timestamp:Date.now()}])},[]),ue=n.useCallback(_=>{_.key==="Enter"&&!_.shiftKey&&(_.preventDefault(),f())},[f]);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:u?e.jsx(Ue,{className:"text-emerald-500",size:16}):e.jsx(kt,{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:[u?"AI 润色":"AI Chat",u&&I&&e.jsxs("span",{className:"text-[10px] px-1.5 py-0.5 rounded-full bg-emerald-50 text-emerald-600 font-medium",children:[((o==null?void 0:o.currentIdx)??0)+1,"/",o==null?void 0:o.candidateIds.length]})]}),e.jsx("p",{className:"text-[10px] text-slate-400 truncate max-w-[250px]",children:u?(S==null?void 0:S.title)||"润色中...":"询问任何关于项目的问题"})]})]}),e.jsxs("div",{className:"flex items-center gap-1",children:[u&&e.jsx("button",{onClick:q,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:"退出润色"}),!u&&s.length>0&&e.jsx("button",{onClick:()=>{H.current=null,a([]),m.current=[],x("")},className:"p-1.5 hover:bg-slate-100 rounded-lg transition-colors",title:"开启新话题",children:e.jsx(gt,{size:16,className:"text-slate-400"})}),e.jsx("button",{onClick:P,className:"p-1.5 hover:bg-slate-100 rounded-lg transition-colors",title:"关闭 AI Chat",children:e.jsx(Ke,{size:16,className:"text-slate-400"})})]})]}),u&&S&&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:S.title}),S.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:S.language})]})}),e.jsxs("div",{className:"flex-1 overflow-y-auto p-4 space-y-3 min-h-0 scrollbar-light",children:[s.length===0&&!u&&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(kt,{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(_=>e.jsx("button",{onClick:()=>{var M;X(_),(M=R.current)==null||M.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:_},_))})]}),u&&s.length<=1&&e.jsx("div",{className:"flex flex-wrap gap-1.5 mt-2",children:["增加具体使用案例,不要修改其他内容","优化代码注释和说明","补充常见错误用法和注意事项","提升摘要质量,更简洁专业","补充性能注意事项"].map(_=>e.jsx("button",{onClick:()=>{var M;X(_),(M=R.current)==null||M.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:_},_))}),s.map(_=>e.jsx("div",{className:`flex ${_.role==="user"?"justify-end":"justify-start"}`,children:e.jsxs("div",{className:`max-w-[95%] ${_.role==="user"?"bg-blue-600 text-white rounded-2xl rounded-tr-md px-3.5 py-2":_.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:[_.role==="assistant"&&e.jsxs("div",{className:"flex items-center gap-1.5 mb-1.5",children:[e.jsx(Jt,{size:12,className:u?"text-emerald-500":"text-blue-500"}),e.jsx("span",{className:`text-[10px] font-bold ${u?"text-emerald-600":"text-blue-600"}`,children:u?"AI 润色助手":"AI 助手"})]}),_.role==="assistant"&&!_.diff?e.jsx(mt,{content:_.content,className:"text-xs text-slate-700"}):e.jsx("p",{className:`text-xs leading-relaxed whitespace-pre-wrap ${_.role==="user"?"":_.role==="system"?"text-slate-500":"text-slate-700"}`,children:_.content}),_.diff&&_.diff.length>0&&e.jsx(cr,{diff:_.diff,excludedFields:_.excludedFields,onToggleField:u&&!g.has(A)?M=>k(_.id,M):void 0})]})},_.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 ${u?"text-emerald-500":"text-blue-500"}`}),e.jsx("span",{className:"text-xs text-slate-500",children:u?"AI 正在分析...":"AI 思考中..."}),b.current&&e.jsx("button",{onClick:()=>{var _;return(_=b.current)==null?void 0:_.abort()},className:"ml-1 px-1.5 py-0.5 text-[10px] font-bold text-red-500 border border-red-200 rounded hover:bg-red-50 transition-colors",children:"停止"})]})})}),e.jsx("div",{ref:B})]}),u&&O&&!l&&(()=>{var se,V;const _=[...s].reverse().find(Q=>Q.role==="assistant"&&Q.diff&&Q.diff.length>0),M=((se=_==null?void 0:_.diff)==null?void 0:se.length)||0,ee=((V=_==null?void 0:_.excludedFields)==null?void 0:V.length)||0,J=M-ee;return 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:w,disabled:i,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:[i?e.jsx(Te,{size:11,className:"animate-spin"}):e.jsx(ft,{size:11}),i?"应用中...":ee>0?`确认应用 (${J}/${M})`:"确认应用"]}),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(ua,{size:11})," 继续调整"]}),I&&g.has(A)&&o.currentIdx<o.candidateIds.length-1&&e.jsxs("button",{onClick:Z,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(st,{size:11})]})]})})(),u&&!O&&!l&&I&&g.has(A)&&o.currentIdx<o.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:Z,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:["下一条 (",((o==null?void 0:o.currentIdx)??0)+2,"/",o==null?void 0:o.candidateIds.length,") ",e.jsx(st,{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:R,value:K,onChange:_=>X(_.target.value),onKeyDown:ue,placeholder:u?'输入定向润色指令,如"增加使用案例"、"优化摘要"...':"输入你的问题...",rows:2,className:`flex-1 px-3 py-2 text-sm border border-slate-200 rounded-xl focus:outline-none focus:ring-2 ${u?"focus:ring-emerald-200 focus:border-emerald-400":"focus:ring-blue-200 focus:border-blue-400"} resize-none placeholder:text-slate-300`,disabled:l||i}),e.jsx("button",{onClick:f,disabled:!K.trim()||l||i,className:`self-stretch w-9 flex items-center justify-center rounded-xl bg-gradient-to-r ${u?"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:u?"Enter 发送 · Shift+Enter 换行 · 先预览再应用":"Enter 发送 · Shift+Enter 换行"})]})]})},mr=({searchQuery:t,setSearchQuery:s,setShowCreateModal:a,handleSyncToXcode:l,aiConfig:r,llmReady:i=!0,onOpenLlmConfig:c,onSemanticSearchResults:o,onBeforeAiSwitch:j,onAiConfigChange:g,isDarkMode:h=!1})=>{const{toggle:y,isOpen:x}=ts(),[m,u]=n.useState(!1),[A,S]=n.useState(!1),[I,P]=n.useState([]),[B,R]=n.useState(!1),K=n.useRef(null);n.useEffect(()=>{A&&I.length===0&&re.getAiProviders().then(H=>P(H)).catch(()=>{})},[A,I.length]),n.useEffect(()=>{const H=C=>{K.current&&!K.current.contains(C.target)&&S(!1)};return document.addEventListener("click",H),()=>document.removeEventListener("click",H)},[]);const X=async()=>{if(t){u(!0);try{const C=((await re.search(t,{mode:"semantic"})).items||[]).map(p=>{var O,k,b;return{name:(p.title||p.name||"")+".md",content:((O=p.content)==null?void 0:O.pattern)||((k=p.content)==null?void 0:k.markdown)||((b=p.content)==null?void 0:b.code)||"",similarity:p.score||0,metadata:{type:"recipe",name:(p.title||p.name||"")+".md"}}});o&&o(C)}catch(H){console.error("Semantic search failed",H),alert("语义搜索失败。请确保已运行 asd embed 构建索引。")}finally{u(!1)}}},$=async H=>{R(!0);try{j==null||j(),await re.setAiConfig(H.id,H.defaultModel),S(!1),g&&g()}catch(C){console.error("AI config update failed",C),alert("切换 AI 失败,请检查项目根目录是否可写。")}finally{R(!1)}};return e.jsxs("header",{className:`h-16 ${h?"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(dt,{className:`absolute left-3 top-1/2 -translate-y-1/2 ${h?"text-slate-500":"text-slate-400"}`,size:T.md}),e.jsx("input",{type:"text",placeholder:"Search knowledge...",className:`w-full pl-10 pr-4 py-2 ${h?"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:H=>s(H.target.value),onKeyDown:H=>H.key==="Enter"&&X()})]}),e.jsxs("button",{onClick:X,disabled:!t||m,className:`flex items-center gap-2 px-3 py-2 rounded-lg text-xs font-bold transition-all ${m?"bg-blue-50 text-blue-400":"bg-blue-50 text-blue-600 hover:bg-blue-100"}`,title:"Semantic Search (Brain AI)",children:[m?e.jsx(Te,{size:T.sm,className:"animate-spin"}):e.jsx(Za,{size:T.sm}),"Semantic"]})]}),e.jsxs("div",{className:"flex items-center gap-4",children:[i?r?e.jsxs("div",{className:"relative",ref:K,children:[e.jsxs("button",{type:"button",onClick:H=>{H.stopPropagation(),S(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(Yt,{size:T.sm}),r.provider," / ",r.model,e.jsx(Ct,{size:T.xs,className:A?"rotate-180":""})]}),A&&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:()=>{S(!1),c==null||c()},className:"text-blue-500 hover:underline",children:"修改 .env 配置"})}),I.length===0?e.jsx("div",{className:"px-3 py-2 text-xs text-slate-400",children:"加载中..."}):I.map(H=>e.jsxs("button",{type:"button",disabled:B,onClick:()=>$(H),className:`w-full text-left px-3 py-2 text-sm hover:bg-slate-50 flex items-center justify-between ${r.provider===H.id?"bg-blue-50 text-blue-700 font-medium":"text-slate-700"}`,children:[e.jsx("span",{children:H.label}),r.provider===H.id&&e.jsx("span",{className:"text-xs",children:"✓"})]},H.id))]})]}):null:e.jsxs("button",{type:"button",onClick:c,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(ha,{size:T.sm}),"配置 LLM"]}),e.jsxs("button",{onClick:y,className:`flex items-center gap-2 px-3 py-2 rounded-lg text-sm font-medium transition-colors ${x?"bg-blue-100 text-blue-700 ring-1 ring-blue-200":h?"bg-slate-700 text-slate-300 hover:bg-slate-600":"bg-slate-100 text-slate-600 hover:bg-slate-200"}`,title:x?"关闭 AI Chat":"打开 AI Chat",children:[e.jsx(kt,{size:T.sm}),!x&&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(gt,{size:T.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(pt,{size:T.md})," Sync to Xcode"]})]})]})},ur=({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 r=l.icon,i=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
62
+ ${i?`${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(r,{size:T.xs}),a]},a)})})}),$a="asd-drawer-wide";function pr(){try{return localStorage.getItem($a)==="1"}catch{return!1}}function Ms(){const[t,s]=n.useState(pr),a=n.useCallback(()=>{s(l=>{const r=!l;try{localStorage.setItem($a,r?"1":"0")}catch{}return r})},[]);return{isWide:t,toggle:a}}const _s=({currentPage:t,totalPages:s,totalItems:a,pageSize:l,onPageChange:r,onPageSizeChange:i,pageSizeOptions:c=[12,24,48,96]})=>{if(s<=1&&a<=c[0])return null;const o=(t-1)*l+1,j=Math.min(t*l,a),g=()=>{const h=[];if(s<=7)for(let x=1;x<=s;x++)h.push(x);else if(t<=3){for(let x=1;x<=5;x++)h.push(x);h.push("..."),h.push(s)}else if(t>=s-2){h.push(1),h.push("...");for(let x=s-5+1;x<=s;x++)h.push(x)}else{h.push(1),h.push("...");for(let x=t-1;x<=t+1;x++)h.push(x);h.push("..."),h.push(s)}return h};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:["显示 ",o,"-",j,",共 ",a," 条"]}),i&&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:h=>i(Number(h.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:c.map(h=>e.jsx("option",{value:h,children:h},h))}),e.jsx("span",{className:"text-sm text-slate-500",children:"条"})]})]}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("button",{onClick:()=>r(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(Qa,{size:T.md,className:"text-slate-600"})}),e.jsx("button",{onClick:()=>r(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:T.md,className:"text-slate-600"})}),e.jsx("div",{className:"flex items-center gap-1 mx-2",children:g().map((h,y)=>typeof h=="number"?e.jsx("button",{onClick:()=>r(h),className:`min-w-[32px] h-8 px-2 rounded-md text-sm font-medium transition-colors ${t===h?"bg-blue-600 text-white":"hover:bg-slate-100 text-slate-600"}`,children:h},y):e.jsx("span",{className:"px-1 text-slate-400",children:h},y))}),e.jsx("button",{onClick:()=>r(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(st,{size:T.md,className:"text-slate-600"})}),e.jsx("button",{onClick:()=>r(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(el,{size:T.md,className:"text-slate-600"})})]})]})},hr=St.memo(({code:t,lang:s,editorStyles:a})=>e.jsx(oa,{language:s,style:ia,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]===`
63
63
  `?l+" ":l})()})),as=19.5,br=St.memo(({totalLines:t,scrollTop:s,viewportHeight:a,fontSize:l,lineHeight:r,fontFamily:i})=>{const o=Math.max(0,Math.floor(s/as)-10),j=Math.ceil(a/as)+20,g=Math.min(t,o+j),h=o*as,y=Math.max(0,(t-g)*as),x=[];for(let m=o;m<g;m++)x.push(e.jsx("div",{children:m+1},m));return e.jsx("div",{style:{paddingTop:h,paddingBottom:y,fontSize:l,lineHeight:r,fontFamily:i},children:x})}),Vt=({value:t,onChange:s,onCursorChange:a,language:l="javascript",height:r="400px",className:i="",placeholder:c="",rows:o,showLineNumbers:j=!0})=>{const g=n.useRef(null),h=n.useRef(null),y=n.useRef(null),x=n.useRef(null),[m,u]=n.useState(t),A=n.useRef(void 0);n.useEffect(()=>{const C=t.length>5e3?200:t.length>1e3?80:0;if(C===0){u(t);return}return A.current=setTimeout(()=>u(t),C),()=>clearTimeout(A.current)},[t]);const[S,I]=n.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",R=n.useMemo(()=>({padding:"1rem 1.25rem",fontSize:"0.8125rem",lineHeight:1.5,fontFamily:"ui-monospace, monospace",minHeight:"200px"}),[]),K=n.useCallback(C=>{const p=C.currentTarget;y.current&&(y.current.scrollTop=p.scrollTop,y.current.scrollLeft=p.scrollLeft),x.current&&(x.current.scrollTop=p.scrollTop),I({top:p.scrollTop,height:p.clientHeight})},[]),X=n.useCallback(C=>{s(C.target.value),a&&a(C.target.selectionStart||0)},[s,a]),$=n.useCallback(C=>{a&&a(C.currentTarget.selectionStart||0)},[a]),H=n.useMemo(()=>(t||"").split(`
64
64
  `).length,[t]);return n.useEffect(()=>{h.current&&I(C=>({...C,height:h.current.clientHeight}))},[]),e.jsxs("div",{ref:g,className:`relative overflow-hidden ${i}`,style:{height:o?"auto":r,minHeight:R.minHeight,display:"flex",borderRadius:"0",backgroundColor:"#282c34"},children:[j&&e.jsx("div",{ref:x,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(br,{totalLines:H,scrollTop:S.top,viewportHeight:S.height,fontSize:R.fontSize,lineHeight:R.lineHeight,fontFamily:R.fontFamily})}),e.jsxs("div",{className:"relative flex-1",style:{borderRadius:"0",backgroundColor:"#282c34"},children:[e.jsx("div",{ref:y,className:"absolute inset-0 pointer-events-none highlight-scroll-hidden",style:{zIndex:0,overflow:"scroll"},children:e.jsx(hr,{code:m||c,lang:B,editorStyles:R})}),e.jsx("textarea",{ref:h,value:t,onChange:X,onSelect:$,onKeyUp:$,onClick:$,onScroll:K,rows:o,placeholder:c,className:"absolute inset-0 w-full h-full resize-none outline-none",style:{padding:R.padding,lineHeight:R.lineHeight,fontSize:R.fontSize,fontFamily:R.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"}})]})]})},gr=420,fr=({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:r}=ts();return e.jsx("div",{className:`fixed inset-0 overflow-hidden ${a}`,style:{right:r?gr:0,...l},onClick:s,children:t})};Ve.Backdrop=fr;const jr={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:ht},fact:{label:"Fact",color:"text-cyan-700",bg:"bg-cyan-50",border:"border-cyan-200",icon:Ye}},Nr={"code-pattern":"代码模式",architecture:"架构设计","best-practice":"最佳实践","code-standard":"代码规范","call-chain":"调用链路",rule:"规则"};function Ze(t){return(t.name||t.title||"Untitled").replace(/\.md$/i,"")}function yr(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(`
65
65
 
66
- `):JSON.stringify(s,null,2)}function Vs(t){var s;return((s=t.content)==null?void 0:s.pattern)||""}function Js(t){const s=(t.language||"").toLowerCase();return["objectivec","objc","objective-c","obj-c"].includes(s)?"objectivec":t.language||"swift"}function za(t){if(t==null)return!1;const s=typeof t=="string"?new Date(t).getTime():t;return!isNaN(s)&&s>9466848e5}function Ys(t){return za(t)?(typeof t=="string"?new Date(t):new Date(t)).toLocaleDateString("zh-CN",{year:"numeric",month:"2-digit",day:"2-digit"}):""}const vr=({recipes:t,handleDeleteRecipe:s,onRefresh:a,idTitleMap:l,currentPage:r,onPageChange:i,pageSize:c,onPageSizeChange:o})=>{const[j,g]=n.useState("default"),[h,y]=n.useState("desc"),x=[{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"}],[m,u]=n.useState(1),[A,S]=n.useState(12),I=r??m,P=c??A,B=i??u,R=o?d=>o(d):d=>{S(d),u(1)},{isWide:K,toggle:X}=Ts(),[$,H]=n.useState(null),[C,p]=n.useState("view"),[O,k]=n.useState(""),[b,f]=n.useState({title:"",description:"",markdown:"",codePattern:"",rationale:"",tags:[],tagInput:""}),[w,Z]=n.useState(!1),q=n.useRef(!0),[ue,M]=n.useState(!1),[T,ee]=n.useState("related"),[J,se]=n.useState("");n.useEffect(()=>()=>{q.current=!1},[]);const V=[{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:"⊃"}],Q=d=>{var L,N,pe,W;H(d),p("view"),k(yr(d)),f({title:((L=d.name)==null?void 0:L.replace(/\.md$/,""))||"",description:d.description||"",markdown:((N=d.content)==null?void 0:N.markdown)||"",codePattern:((pe=d.content)==null?void 0:pe.pattern)||"",rationale:((W=d.content)==null?void 0:W.rationale)||"",tags:d.tags||[],tagInput:""}),M(!1),se("")},ae=()=>{H(null),p("view"),M(!1),se("")},ye=async()=>{if(!(!$||w)){Z(!0);try{const d=$.id||$.name;await re.knowledgeUpdate(d,{title:b.title,description:b.description,tags:b.tags,content:{...$.content||{},pattern:b.codePattern,markdown:b.markdown,rationale:b.rationale}}),q.current&&(p("view"),a==null||a())}catch(d){le((d==null?void 0:d.message)||"保存失败",{title:"操作失败",type:"error"})}finally{q.current&&Z(!1)}}},Se=async d=>{if($)try{await re.setRecipeAuthority($.id||$.name,d),a==null||a()}catch(L){le((L==null?void 0:L.message)||"设置权威分失败",{title:"操作失败",type:"error"})}},De=d=>{const L=d.replace(/\.md$/i,"").toLowerCase();return t.find(N=>Ze(N).toLowerCase()===L)},D=n.useMemo(()=>{const d=new Map;if(l)for(const[L,N]of Object.entries(l))d.set(L,N);for(const L of t)L.id&&d.set(L.id,Ze(L)),L.name&&d.set(L.name,Ze(L));return d},[t,l]),_=async(d,L)=>{if(!$)return;const N={};if($.relations)for(const[oe,F]of Object.entries($.relations))N[oe]=[...F];const pe=N[d]||[],W=L.replace(/\.md$/i,"");if(!pe.some(oe=>(typeof oe=="string"?oe:oe.id||oe.title||"").replace(/\.md$/i,"").toLowerCase()===W.toLowerCase())){N[d]=[...pe,W];try{await re.updateRecipeRelations($.id||$.name,N),H({...$,relations:N}),M(!1),se(""),a==null||a()}catch(oe){le((oe==null?void 0:oe.message)||"添加关联失败",{title:"操作失败",type:"error"})}}},xe=async(d,L)=>{if(!$)return;const N={};if($.relations)for(const[W,oe]of Object.entries($.relations))N[W]=[...oe];const pe=N[d]||[];N[d]=pe.filter(W=>(typeof W=="string"?W:W.id||W.title||"").replace(/\.md$/i,"").toLowerCase()!==L.replace(/\.md$/i,"").toLowerCase()),N[d].length===0&&delete N[d];try{await re.updateRecipeRelations($.id||$.name,N),H({...$,relations:N}),a==null||a()}catch(W){le((W==null?void 0:W.message)||"移除关联失败",{title:"操作失败",type:"error"})}};n.useEffect(()=>{$&&!t.find(d=>Ze(d)===Ze($))&&ae()},[t,$]),n.useEffect(()=>{r==null&&u(1)},[t.length,r]);const Ie=St.useMemo(()=>{if(j==="default")return t;const d=[...t],L=h==="asc"?1:-1;return d.sort((N,pe)=>{var F,te,ge,G,be,Re,Te,Me,qe,Ge,U,$e;let W=0,oe=0;switch(j){case"name":return W=Ze(N).toLowerCase(),oe=Ze(pe).toLowerCase(),L*(W<oe?-1:W>oe?1:0);case"authorityScore":W=((F=N.stats)==null?void 0:F.authorityScore)??-1,oe=((te=pe.stats)==null?void 0:te.authorityScore)??-1;break;case"authority":W=((ge=N.stats)==null?void 0:ge.authority)??-1,oe=((G=pe.stats)==null?void 0:G.authority)??-1;break;case"totalUsage":W=(((be=N.stats)==null?void 0:be.guardUsageCount)??0)+(((Re=N.stats)==null?void 0:Re.humanUsageCount)??0)+(((Te=N.stats)==null?void 0:Te.aiUsageCount)??0),oe=(((Me=pe.stats)==null?void 0:Me.guardUsageCount)??0)+(((qe=pe.stats)==null?void 0:qe.humanUsageCount)??0)+(((Ge=pe.stats)==null?void 0:Ge.aiUsageCount)??0);break;case"lastUsed":{const We=(U=N.stats)!=null&&U.lastUsedAt?new Date(N.stats.lastUsedAt).getTime():0,Be=($e=pe.stats)!=null&&$e.lastUsedAt?new Date(pe.stats.lastUsedAt).getTime():0;W=isNaN(We)?0:We,oe=isNaN(Be)?0:Be;break}case"category":return W=(N.category||"").toLowerCase(),oe=(pe.category||"").toLowerCase(),L*(W<oe?-1:W>oe?1:0)}return L*(W-oe)}),d},[t,j,h]),fe=Math.ceil(Ie.length/P),Ae=(I-1)*P,Oe=Ie.slice(Ae,Ae+P),_e=d=>{B(d),window.scrollTo({top:0,behavior:"smooth"})},v=$?Ie.findIndex(d=>Ze(d)===Ze($)):-1,ne=()=>{v>0&&Q(Ie[v-1])},ve=()=>{v<Ie.length-1&&Q(Ie[v+1])},ce=({recipe:d,compact:L})=>{const N=d.kind?jr[d.kind]:null,pe=(N==null?void 0:N.icon)||et,W=d.category||"Utility",oe=lt[W]||lt.Utility,F=oe.icon,te=d.knowledgeType,ge=L?"text-[8px]":"text-[9px]";return e.jsxs("div",{className:"flex flex-wrap items-center gap-1.5",children:[N&&e.jsxs("span",{className:`${ge} font-bold px-1.5 py-0.5 rounded uppercase flex items-center gap-1 border ${N.bg} ${N.color} ${N.border}`,children:[e.jsx(pe,{size:L?9:10}),N.label]}),e.jsxs("span",{className:`${ge} font-bold px-1.5 py-0.5 rounded uppercase flex items-center gap-1 border ${oe.bg} ${oe.color} ${oe.border}`,children:[e.jsx(F,{size:L?9:10}),W]}),te&&e.jsx("span",{className:`${ge} font-medium px-1.5 py-0.5 rounded bg-indigo-50 text-indigo-600 border border-indigo-100`,children:Nr[te]||te}),d.language&&e.jsx("span",{className:`${ge} font-medium px-1.5 py-0.5 rounded bg-slate-100 text-slate-500 uppercase`,children:d.language}),d.trigger&&e.jsx("span",{className:`${ge} font-mono font-bold px-1.5 py-0.5 rounded bg-blue-50 text-blue-600 border border-blue-100`,children:d.trigger})]})},he=({recipe:d})=>{const L=[];return d.scope&&L.push({icon:wt,iconClass:"text-teal-400",label:"作用域",value:d.scope==="universal"?"通用":d.scope==="project-specific"?"项目级":d.scope}),d.complexity&&L.push({icon:Qe,iconClass:"text-orange-400",label:"复杂度",value:d.complexity==="advanced"?"高级":d.complexity==="intermediate"?"中级":d.complexity==="basic"?"初级":d.complexity}),d.difficulty&&d.difficulty!==d.complexity&&L.push({icon:Qe,iconClass:"text-amber-400",label:"难度",value:d.difficulty}),d.moduleName&&L.push({icon:Qe,iconClass:"text-purple-400",label:"模块",value:d.moduleName,mono:!0}),d.source&&d.source!=="unknown"&&L.push({icon:wt,iconClass:"text-violet-400",label:"来源",value:d.source==="bootstrap-scan"?"AI 扫描":d.source==="agent"?"AI Agent":d.source}),d.version&&L.push({icon:Gt,iconClass:"text-slate-400",label:"版本",value:d.version}),d.updatedAt&&za(d.updatedAt)&&L.push({icon:Gt,iconClass:"text-slate-400",label:"更新",value:Ys(d.updatedAt)}),L.length===0&&!d.sourceFile?null:e.jsxs("div",{className:"flex flex-wrap gap-x-5 gap-y-2 text-xs",children:[L.map((N,pe)=>{const W=N.icon;return e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(W,{size:11,className:`${N.iconClass} shrink-0`}),e.jsx("span",{className:"text-slate-400",children:N.label}),e.jsx("span",{className:`font-medium text-slate-600 ${N.mono?"font-mono text-[11px]":""}`,children:N.value})]},pe)}),d.sourceFile&&e.jsxs("div",{className:"flex items-center gap-1.5 basis-full mt-0.5",children:[e.jsx(Et,{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:d.sourceFile,children:d.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(tl,{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(ba,{size:14,className:"text-slate-400 shrink-0"}),x.map(d=>{const L=j===d.key;return e.jsxs("button",{onClick:()=>{L?y(N=>N==="asc"?"desc":"asc"):(g(d.key),y(d.defaultDir)),B(1)},className:`px-2 py-1 rounded-md flex items-center gap-0.5 transition-colors ${L?"bg-blue-50 text-blue-700 font-medium border border-blue-200":"text-slate-500 hover:bg-slate-100 border border-transparent"}`,children:[d.label,L&&j!=="default"&&(h==="asc"?e.jsx(sl,{size:12}):e.jsx(al,{size:12}))]},d.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(d=>{var oe,F;const L=Ze(d),N=Vs(d),pe=d.description||d.usageGuide||"",W=$&&Ze($)===L;return e.jsxs("div",{onClick:()=>Q(d),className:`bg-white rounded-xl border shadow-sm hover:shadow-md transition-all group relative cursor-pointer overflow-hidden ${W?"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:te=>{te.stopPropagation(),Q(d),p("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(bt,{size:E.sm})}),e.jsx("button",{onClick:te=>{te.stopPropagation(),s(d.name||d.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(tt,{size:E.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:L}),e.jsx(ce,{recipe:d,compact:!0})]}),d.tags&&d.tags.length>0&&e.jsxs("div",{className:"px-5 pb-2 flex flex-wrap gap-1",children:[d.tags.slice(0,4).map((te,ge)=>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}),te]},ge)),d.tags.length>4&&e.jsxs("span",{className:"text-[9px] text-slate-400",children:["+",d.tags.length-4]})]}),pe&&e.jsx("div",{className:"px-5 pb-3",children:e.jsx("p",{className:"text-xs text-slate-500 line-clamp-2 leading-relaxed",children:pe.replace(/^#+\s*/gm,"").replace(/\*\*/g,"")})}),((oe=d.content)==null?void 0:oe.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(et,{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:d.content.markdown.replace(/^#+\s*/gm,"").replace(/\*\*/g,"").replace(/```[\s\S]*?```/g,"").trim().slice(0,200)})})]}),N&&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(xt,{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:N.split(`
66
+ `):JSON.stringify(s,null,2)}function Vs(t){var s;return((s=t.content)==null?void 0:s.pattern)||""}function Js(t){const s=(t.language||"").toLowerCase();return["objectivec","objc","objective-c","obj-c"].includes(s)?"objectivec":t.language||"swift"}function za(t){if(t==null)return!1;const s=typeof t=="string"?new Date(t).getTime():t;return!isNaN(s)&&s>9466848e5}function Ys(t){return za(t)?(typeof t=="string"?new Date(t):new Date(t)).toLocaleDateString("zh-CN",{year:"numeric",month:"2-digit",day:"2-digit"}):""}const vr=({recipes:t,handleDeleteRecipe:s,onRefresh:a,idTitleMap:l,currentPage:r,onPageChange:i,pageSize:c,onPageSizeChange:o})=>{const[j,g]=n.useState("default"),[h,y]=n.useState("desc"),x=[{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"}],[m,u]=n.useState(1),[A,S]=n.useState(12),I=r??m,P=c??A,B=i??u,R=o?d=>o(d):d=>{S(d),u(1)},{isWide:K,toggle:X}=Ms(),[$,H]=n.useState(null),[C,p]=n.useState("view"),[O,k]=n.useState(""),[b,f]=n.useState({title:"",description:"",markdown:"",codePattern:"",rationale:"",tags:[],tagInput:""}),[w,Z]=n.useState(!1),q=n.useRef(!0),[ue,_]=n.useState(!1),[M,ee]=n.useState("related"),[J,se]=n.useState("");n.useEffect(()=>()=>{q.current=!1},[]);const V=[{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:"⊃"}],Q=d=>{var L,N,pe,G;H(d),p("view"),k(yr(d)),f({title:((L=d.name)==null?void 0:L.replace(/\.md$/,""))||"",description:d.description||"",markdown:((N=d.content)==null?void 0:N.markdown)||"",codePattern:((pe=d.content)==null?void 0:pe.pattern)||"",rationale:((G=d.content)==null?void 0:G.rationale)||"",tags:d.tags||[],tagInput:""}),_(!1),se("")},ae=()=>{H(null),p("view"),_(!1),se("")},ye=async()=>{if(!(!$||w)){Z(!0);try{const d=$.id||$.name;await re.knowledgeUpdate(d,{title:b.title,description:b.description,tags:b.tags,content:{...$.content||{},pattern:b.codePattern,markdown:b.markdown,rationale:b.rationale}}),q.current&&(p("view"),a==null||a())}catch(d){le((d==null?void 0:d.message)||"保存失败",{title:"操作失败",type:"error"})}finally{q.current&&Z(!1)}}},Se=async d=>{if($)try{await re.setRecipeAuthority($.id||$.name,d),a==null||a()}catch(L){le((L==null?void 0:L.message)||"设置权威分失败",{title:"操作失败",type:"error"})}},De=d=>{const L=d.replace(/\.md$/i,"").toLowerCase();return t.find(N=>Ze(N).toLowerCase()===L)},D=n.useMemo(()=>{const d=new Map;if(l)for(const[L,N]of Object.entries(l))d.set(L,N);for(const L of t)L.id&&d.set(L.id,Ze(L)),L.name&&d.set(L.name,Ze(L));return d},[t,l]),E=async(d,L)=>{if(!$)return;const N={};if($.relations)for(const[oe,F]of Object.entries($.relations))N[oe]=[...F];const pe=N[d]||[],G=L.replace(/\.md$/i,"");if(!pe.some(oe=>(typeof oe=="string"?oe:oe.id||oe.title||"").replace(/\.md$/i,"").toLowerCase()===G.toLowerCase())){N[d]=[...pe,G];try{await re.updateRecipeRelations($.id||$.name,N),H({...$,relations:N}),_(!1),se(""),a==null||a()}catch(oe){le((oe==null?void 0:oe.message)||"添加关联失败",{title:"操作失败",type:"error"})}}},xe=async(d,L)=>{if(!$)return;const N={};if($.relations)for(const[G,oe]of Object.entries($.relations))N[G]=[...oe];const pe=N[d]||[];N[d]=pe.filter(G=>(typeof G=="string"?G:G.id||G.title||"").replace(/\.md$/i,"").toLowerCase()!==L.replace(/\.md$/i,"").toLowerCase()),N[d].length===0&&delete N[d];try{await re.updateRecipeRelations($.id||$.name,N),H({...$,relations:N}),a==null||a()}catch(G){le((G==null?void 0:G.message)||"移除关联失败",{title:"操作失败",type:"error"})}};n.useEffect(()=>{$&&!t.find(d=>Ze(d)===Ze($))&&ae()},[t,$]),n.useEffect(()=>{r==null&&u(1)},[t.length,r]);const Ie=St.useMemo(()=>{if(j==="default")return t;const d=[...t],L=h==="asc"?1:-1;return d.sort((N,pe)=>{var F,te,ge,W,be,Re,Me,_e,qe,We,U,$e;let G=0,oe=0;switch(j){case"name":return G=Ze(N).toLowerCase(),oe=Ze(pe).toLowerCase(),L*(G<oe?-1:G>oe?1:0);case"authorityScore":G=((F=N.stats)==null?void 0:F.authorityScore)??-1,oe=((te=pe.stats)==null?void 0:te.authorityScore)??-1;break;case"authority":G=((ge=N.stats)==null?void 0:ge.authority)??-1,oe=((W=pe.stats)==null?void 0:W.authority)??-1;break;case"totalUsage":G=(((be=N.stats)==null?void 0:be.guardUsageCount)??0)+(((Re=N.stats)==null?void 0:Re.humanUsageCount)??0)+(((Me=N.stats)==null?void 0:Me.aiUsageCount)??0),oe=(((_e=pe.stats)==null?void 0:_e.guardUsageCount)??0)+(((qe=pe.stats)==null?void 0:qe.humanUsageCount)??0)+(((We=pe.stats)==null?void 0:We.aiUsageCount)??0);break;case"lastUsed":{const Ge=(U=N.stats)!=null&&U.lastUsedAt?new Date(N.stats.lastUsedAt).getTime():0,Be=($e=pe.stats)!=null&&$e.lastUsedAt?new Date(pe.stats.lastUsedAt).getTime():0;G=isNaN(Ge)?0:Ge,oe=isNaN(Be)?0:Be;break}case"category":return G=(N.category||"").toLowerCase(),oe=(pe.category||"").toLowerCase(),L*(G<oe?-1:G>oe?1:0)}return L*(G-oe)}),d},[t,j,h]),fe=Math.ceil(Ie.length/P),Ae=(I-1)*P,Oe=Ie.slice(Ae,Ae+P),Ee=d=>{B(d),window.scrollTo({top:0,behavior:"smooth"})},v=$?Ie.findIndex(d=>Ze(d)===Ze($)):-1,ne=()=>{v>0&&Q(Ie[v-1])},ve=()=>{v<Ie.length-1&&Q(Ie[v+1])},ce=({recipe:d,compact:L})=>{const N=d.kind?jr[d.kind]:null,pe=(N==null?void 0:N.icon)||et,G=d.category||"Utility",oe=lt[G]||lt.Utility,F=oe.icon,te=d.knowledgeType,ge=L?"text-[8px]":"text-[9px]";return e.jsxs("div",{className:"flex flex-wrap items-center gap-1.5",children:[N&&e.jsxs("span",{className:`${ge} font-bold px-1.5 py-0.5 rounded uppercase flex items-center gap-1 border ${N.bg} ${N.color} ${N.border}`,children:[e.jsx(pe,{size:L?9:10}),N.label]}),e.jsxs("span",{className:`${ge} font-bold px-1.5 py-0.5 rounded uppercase flex items-center gap-1 border ${oe.bg} ${oe.color} ${oe.border}`,children:[e.jsx(F,{size:L?9:10}),G]}),te&&e.jsx("span",{className:`${ge} font-medium px-1.5 py-0.5 rounded bg-indigo-50 text-indigo-600 border border-indigo-100`,children:Nr[te]||te}),d.language&&e.jsx("span",{className:`${ge} font-medium px-1.5 py-0.5 rounded bg-slate-100 text-slate-500 uppercase`,children:d.language}),d.trigger&&e.jsx("span",{className:`${ge} font-mono font-bold px-1.5 py-0.5 rounded bg-blue-50 text-blue-600 border border-blue-100`,children:d.trigger})]})},he=({recipe:d})=>{const L=[];return d.scope&&L.push({icon:wt,iconClass:"text-teal-400",label:"作用域",value:d.scope==="universal"?"通用":d.scope==="project-specific"?"项目级":d.scope}),d.complexity&&L.push({icon:Qe,iconClass:"text-orange-400",label:"复杂度",value:d.complexity==="advanced"?"高级":d.complexity==="intermediate"?"中级":d.complexity==="basic"?"初级":d.complexity}),d.difficulty&&d.difficulty!==d.complexity&&L.push({icon:Qe,iconClass:"text-amber-400",label:"难度",value:d.difficulty}),d.moduleName&&L.push({icon:Qe,iconClass:"text-purple-400",label:"模块",value:d.moduleName,mono:!0}),d.source&&d.source!=="unknown"&&L.push({icon:wt,iconClass:"text-violet-400",label:"来源",value:d.source==="bootstrap-scan"?"AI 扫描":d.source==="agent"?"AI Agent":d.source}),d.version&&L.push({icon:Wt,iconClass:"text-slate-400",label:"版本",value:d.version}),d.updatedAt&&za(d.updatedAt)&&L.push({icon:Wt,iconClass:"text-slate-400",label:"更新",value:Ys(d.updatedAt)}),L.length===0&&!d.sourceFile?null:e.jsxs("div",{className:"flex flex-wrap gap-x-5 gap-y-2 text-xs",children:[L.map((N,pe)=>{const G=N.icon;return e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(G,{size:11,className:`${N.iconClass} shrink-0`}),e.jsx("span",{className:"text-slate-400",children:N.label}),e.jsx("span",{className:`font-medium text-slate-600 ${N.mono?"font-mono text-[11px]":""}`,children:N.value})]},pe)}),d.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:d.sourceFile,children:d.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(tl,{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(ba,{size:14,className:"text-slate-400 shrink-0"}),x.map(d=>{const L=j===d.key;return e.jsxs("button",{onClick:()=>{L?y(N=>N==="asc"?"desc":"asc"):(g(d.key),y(d.defaultDir)),B(1)},className:`px-2 py-1 rounded-md flex items-center gap-0.5 transition-colors ${L?"bg-blue-50 text-blue-700 font-medium border border-blue-200":"text-slate-500 hover:bg-slate-100 border border-transparent"}`,children:[d.label,L&&j!=="default"&&(h==="asc"?e.jsx(sl,{size:12}):e.jsx(al,{size:12}))]},d.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(d=>{var oe,F;const L=Ze(d),N=Vs(d),pe=d.description||d.usageGuide||"",G=$&&Ze($)===L;return e.jsxs("div",{onClick:()=>Q(d),className:`bg-white rounded-xl border shadow-sm hover:shadow-md transition-all group relative cursor-pointer overflow-hidden ${G?"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:te=>{te.stopPropagation(),Q(d),p("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(bt,{size:T.sm})}),e.jsx("button",{onClick:te=>{te.stopPropagation(),s(d.name||d.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(tt,{size:T.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:L}),e.jsx(ce,{recipe:d,compact:!0})]}),d.tags&&d.tags.length>0&&e.jsxs("div",{className:"px-5 pb-2 flex flex-wrap gap-1",children:[d.tags.slice(0,4).map((te,ge)=>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}),te]},ge)),d.tags.length>4&&e.jsxs("span",{className:"text-[9px] text-slate-400",children:["+",d.tags.length-4]})]}),pe&&e.jsx("div",{className:"px-5 pb-3",children:e.jsx("p",{className:"text-xs text-slate-500 line-clamp-2 leading-relaxed",children:pe.replace(/^#+\s*/gm,"").replace(/\*\*/g,"")})}),((oe=d.content)==null?void 0:oe.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(et,{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:d.content.markdown.replace(/^#+\s*/gm,"").replace(/\*\*/g,"").replace(/```[\s\S]*?```/g,"").trim().slice(0,200)})})]}),N&&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(xt,{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:N.split(`
67
67
  `).slice(0,6).join(`
68
- `),language:Js(d)})})]}),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:["★ ",((F=d.stats)==null?void 0:F.authority)??0]}),e.jsxs("span",{children:["使用 ",d.stats?d.stats.guardUsageCount+d.stats.humanUsageCount+d.stats.aiUsageCount:0]}),d.source&&d.source!=="unknown"&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-slate-200",children:"|"}),e.jsx("span",{children:d.source==="bootstrap-scan"?"AI 扫描":d.source==="agent"?"AI Agent":d.source})]}),d.moduleName&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-slate-200",children:"|"}),e.jsx("span",{className:"font-mono",children:d.moduleName})]}),d.relations&&Object.values(d.relations).flat().length>0&&e.jsxs("span",{className:"ml-auto text-purple-500 font-medium",children:["关系 ",Object.values(d.relations).flat().length]})]})]},d.id||L)})})]}),t.length>0&&e.jsx(Ms,{currentPage:I,totalPages:fe,totalItems:Ie.length,pageSize:P,onPageChange:_e,onPageSizeChange:R}),$&&(()=>{var oe,F,te,ge;const d=$,L=Ze(d),N=Vs(d),pe=Js(d),W=d.content;return e.jsxs(Ve,{className:"z-30 flex justify-end",onClick:ae,children:[e.jsx(Ve.Backdrop,{}),e.jsxs("div",{className:`relative h-full bg-white shadow-2xl flex flex-col ${K?"w-[min(92vw,1100px)]":"w-[min(92vw,800px)]"}`,style:{animation:"slideInRight 0.25s ease-out"},onClick:G=>G.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:L})}),e.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[e.jsx("button",{onClick:ne,disabled:v<=0,className:"p-1.5 hover:bg-slate-100 rounded-lg transition-colors disabled:opacity-30",title:"上一条",children:e.jsx(Zt,{size:E.md})}),e.jsxs("span",{className:"text-xs text-slate-400 tabular-nums",children:[v+1,"/",Ie.length]}),e.jsx("button",{onClick:ve,disabled:v>=Ie.length-1,className:"p-1.5 hover:bg-slate-100 rounded-lg transition-colors disabled:opacity-30",title:"下一条",children:e.jsx(st,{size:E.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:()=>p("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:E.sm})," 预览"]}),e.jsxs("button",{onClick:()=>{p("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(bt,{size:E.sm})," 编辑"]})]}),e.jsx("button",{onClick:X,className:"p-1.5 hover:bg-slate-100 rounded-lg transition-colors text-slate-400",title:K?"收窄":"展宽",children:K?e.jsx(Is,{size:E.md}):e.jsx(hs,{size:E.md})}),e.jsx("button",{onClick:()=>{s(d.name||d.id),ae()},className:"p-1.5 hover:bg-red-50 rounded-lg text-red-500 transition-colors",title:"删除",children:e.jsx(tt,{size:E.md})}),e.jsx("button",{onClick:ae,className:"p-1.5 hover:bg-slate-100 rounded-lg transition-colors",children:e.jsx(Ke,{size:E.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:b.title,onChange:G=>f(be=>({...be,title:G.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:b.description,onChange:G=>f(be=>({...be,description:G.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:b.tags.map((G,be)=>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:[G,e.jsx("button",{onClick:()=>f(Re=>({...Re,tags:Re.tags.filter((Te,Me)=>Me!==be)})),className:"text-blue-400 hover:text-red-500",children:e.jsx(Ke,{size:10})})]},be))}),e.jsx("div",{className:"flex gap-2",children:e.jsx("input",{type:"text",value:b.tagInput,onChange:G=>f(be=>({...be,tagInput:G.target.value})),onKeyDown:G=>{G.key==="Enter"&&b.tagInput.trim()&&(G.preventDefault(),f(be=>({...be,tags:[...be.tags,be.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(et,{size:11,className:"text-blue-400"})," Markdown 文档"]}),e.jsx("textarea",{value:b.markdown,onChange:G=>f(be=>({...be,markdown:G.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(At,{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:b.codePattern,onChange:G=>f(be=>({...be,codePattern:G})),language:pe,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:b.rationale,onChange:G=>f(be=>({...be,rationale:G.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:((oe=d.stats)==null?void 0:oe.authority)??3,onChange:G=>Se(parseInt(G.target.value)),children:[1,2,3,4,5].map(G=>e.jsxs("option",{value:G,children:["⭐".repeat(G)," ",G]},G))})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{onClick:()=>p("view"),disabled:w,className:"px-4 py-1.5 text-sm text-slate-600 font-medium rounded-lg hover:bg-slate-50",children:"取消"}),e.jsxs("button",{onClick:ye,disabled:w,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:[w?e.jsx(Ee,{size:E.sm,className:"animate-spin"}):e.jsx(Qt,{size:E.sm}),w?"保存中...":"保存"]})]})]})]}):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(ce,{recipe:d}),e.jsx(he,{recipe:d})]}),d.tags&&d.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"}),d.tags.map((G,be)=>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:G},be))]}),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($s,{size:12,className:"text-purple-400"}),e.jsx("label",{className:"text-[10px] font-bold text-slate-400 uppercase",children:"关联知识"}),(()=>{const G=d.relations?Object.values(d.relations).flat().length:0;return G>0?e.jsx("span",{className:"text-[9px] bg-purple-100 text-purple-600 px-1.5 py-0.5 rounded-full font-bold",children:G}):null})()]}),e.jsx("button",{onClick:()=>{M(!ue),se("")},className:`text-[9px] px-2 py-0.5 rounded font-bold flex items-center gap-1 transition-colors ${ue?"bg-slate-200 text-slate-600":"bg-purple-500 text-white hover:bg-purple-600"}`,children:ue?e.jsxs(e.Fragment,{children:[e.jsx(Ke,{size:10})," 取消"]}):e.jsxs(e.Fragment,{children:[e.jsx(gt,{size:10})," 添加"]})})]}),ue&&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:T,onChange:G=>ee(G.target.value),className:"text-[10px] font-bold bg-white border border-purple-200 text-purple-700 rounded px-2 py-1 outline-none",children:V.map(G=>e.jsxs("option",{value:G.key,children:[G.icon," ",G.label]},G.key))}),e.jsxs("div",{className:"flex-1 relative",children:[e.jsx(dt,{size:12,className:"absolute left-2 top-1/2 -translate-y-1/2 text-slate-300"}),e.jsx("input",{type:"text",placeholder:"搜索...",value:J,onChange:G=>se(G.target.value),className:"w-full text-xs bg-white border border-purple-200 rounded pl-7 pr-2 py-1 outline-none",autoFocus:!0})]})]}),J.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 G=t.filter(be=>Ze(be)===L?!1:Ze(be).toLowerCase().includes(J.toLowerCase())).slice(0,10);return G.length?G.map(be=>{const Re=Ze(be),Te=d.relations&&Object.values(d.relations).flat().some(Me=>(typeof Me=="string"?Me:Me.target||Me.id||Me.title||"").replace(/\.md$/i,"").toLowerCase()===Re.toLowerCase());return e.jsxs("div",{className:`flex items-center justify-between px-3 py-1.5 text-xs ${Te?"bg-slate-50 text-slate-400":"hover:bg-purple-50 cursor-pointer"}`,onClick:()=>!Te&&_(T,Re),children:[e.jsx("span",{className:"font-medium truncate mr-2",children:Re}),Te?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:"+ 添加"})]},Re)}):e.jsx("div",{className:"text-xs text-slate-400 py-3 text-center",children:"未找到"})})()})]}),d.relations&&Object.entries(d.relations).some(([,G])=>Array.isArray(G)&&G.length>0)?e.jsx("div",{className:"space-y-1.5",children:V.map(({key:G,label:be,icon:Re})=>{var Me;const Te=(Me=d.relations)==null?void 0:Me[G];return!Te||!Array.isArray(Te)||Te.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:[Re," ",be]}),e.jsx("div",{className:"flex flex-wrap gap-1",children:Te.map((qe,Ge)=>{const U=typeof qe=="string"?qe:qe.target||qe.id||qe.title||JSON.stringify(qe),$e=De(U)||(D.has(U)?De(D.get(U)):void 0),We=$e?Ze($e):D.get(U)||U;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 ${$e?"bg-purple-50 border-purple-200 text-purple-700 cursor-pointer hover:bg-purple-100":"bg-white border-slate-200 text-slate-600"}`,onClick:()=>$e&&Q($e),title:$e?"点击查看":We,children:[We.replace(/\.md$/i,""),e.jsx("button",{onClick:Be=>{Be.stopPropagation(),xe(G,U)},className:"opacity-0 group-hover/rel:opacity-100 text-red-400 hover:text-red-600 transition-opacity ml-0.5",title:"移除",children:e.jsx(Ke,{size:10})})]},Ge)})})]},G)})}):!ue&&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:((F=d.stats)==null?void 0:F.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:((te=d.stats)==null?void 0:te.authorityScore)!=null?d.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:d.stats?d.stats.guardUsageCount+d.stats.humanUsageCount+d.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:Ys((ge=d.stats)==null?void 0:ge.lastUsedAt)||"从未使用"}),e.jsx("div",{className:"text-[10px] text-slate-400 font-medium",children:"最近使用"})]})]}),d.stats!=null&&(d.stats.guardUsageCount>0||d.stats.humanUsageCount>0||d.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: ",d.stats.guardUsageCount]}),e.jsxs("span",{children:["Human: ",d.stats.humanUsageCount]}),e.jsxs("span",{children:["AI: ",d.stats.aiUsageCount]})]})]}),d.reasoning&&(d.reasoning.whyStandard||d.reasoning.sources&&d.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(ht,{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:[d.reasoning.whyStandard&&e.jsx("p",{className:"text-sm text-slate-700 leading-relaxed",children:d.reasoning.whyStandard}),d.reasoning.sources&&d.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:"来源:"}),d.reasoning.sources.map((G,be)=>e.jsx("code",{className:"text-[10px] px-2 py-0.5 bg-white border border-amber-200 rounded text-amber-700 font-mono",children:G},be))]}),d.reasoning.confidence!=null&&d.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(d.reasoning.confidence*100)}%`}})}),e.jsxs("span",{className:"text-[10px] font-bold text-amber-600",children:[Math.round(d.reasoning.confidence*100),"%"]})]}),d.reasoning.alternatives&&d.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:"备选:"}),d.reasoning.alternatives.map((G,be)=>e.jsx("span",{className:"text-[10px] px-1.5 py-0.5 bg-slate-100 border border-slate-200 rounded text-slate-600",children:G},be))]})]})]}),d.quality&&d.quality.grade&&d.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 ${d.quality.grade==="A"?"text-emerald-600":d.quality.grade==="B"?"text-blue-600":d.quality.grade==="C"?"text-amber-600":d.quality.grade==="D"?"text-orange-600":"text-slate-400"}`,children:d.quality.grade}),e.jsxs("div",{className:"flex-1 grid grid-cols-3 gap-2 text-[10px]",children:[d.quality.completeness!=null&&d.quality.completeness>0&&e.jsxs("div",{className:"text-center",children:[e.jsx("div",{className:"font-bold text-slate-700",children:d.quality.completeness}),e.jsx("div",{className:"text-slate-400",children:"完整性"})]}),d.quality.adaptation!=null&&d.quality.adaptation>0&&e.jsxs("div",{className:"text-center",children:[e.jsx("div",{className:"font-bold text-slate-700",children:d.quality.adaptation}),e.jsx("div",{className:"text-slate-400",children:"适配度"})]}),d.quality.documentation!=null&&d.quality.documentation>0&&e.jsxs("div",{className:"text-center",children:[e.jsx("div",{className:"font-bold text-slate-700",children:d.quality.documentation}),e.jsx("div",{className:"text-slate-400",children:"文档度"})]})]})]})]}),d.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:d.description})]}),(W==null?void 0:W.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(et,{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(mt,{content:W.markdown})})})]}),d.headers&&d.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:d.headers.map((G,be)=>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:G},be))})]}),N&&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(xt,{size:11,className:"text-emerald-500"})," 代码 / 标准用法"]}),e.jsx(rt,{code:N,language:pe,showLineNumbers:!0})]}),(W==null?void 0:W.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:W.rationale})})]}),(W==null?void 0:W.steps)&&W.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:W.steps.map((G,be)=>{if(typeof G=="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:be+1}),e.jsx("p",{className:"text-xs text-slate-700 leading-relaxed",children:G})]},be);const Re=typeof G.title=="string"?G.title:"",Te=typeof G.description=="string"?G.description:"",Me=typeof G.code=="string"?G.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:be+1}),Re&&e.jsx("span",{className:"text-xs font-bold text-slate-700",children:Re})]}),Te&&e.jsx("p",{className:"text-xs text-slate-600 ml-7 leading-relaxed",children:Te}),Me&&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:Me})]},be)})})]}),(W==null?void 0:W.codeChanges)&&W.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:W.codeChanges.map((G,be)=>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(xt,{size:11,className:"text-blue-400"}),e.jsx("code",{className:"text-[10px] font-mono text-slate-600",children:G.file})]}),G.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:G.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:G.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:G.after})]})]},be))})]}),(W==null?void 0:W.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:[W.verification.method&&e.jsxs("p",{className:"text-xs text-slate-600",children:[e.jsx("span",{className:"font-bold text-teal-600",children:"方法:"})," ",W.verification.method]}),W.verification.expectedResult&&e.jsxs("p",{className:"text-xs text-slate-600",children:[e.jsx("span",{className:"font-bold text-teal-600",children:"预期:"})," ",W.verification.expectedResult]}),W.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:W.verification.testCode})]})]}),d.constraints&&(()=>{var Re,Te,Me,qe,Ge,U,$e,We;const G=d.constraints,be=(((Re=G.guards)==null?void 0:Re.length)||0)+(((Te=G.boundaries)==null?void 0:Te.length)||0)+(((Me=G.preconditions)==null?void 0:Me.length)||0)+(((qe=G.sideEffects)==null?void 0:qe.length)||0);return be?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:be})]}),e.jsxs("div",{className:"space-y-1.5 text-xs text-slate-600",children:[(Ge=G.guards)==null?void 0:Ge.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)),(U=G.boundaries)==null?void 0:U.map((Be,Xe)=>e.jsxs("div",{className:"flex gap-1.5",children:[e.jsx("span",{className:"text-orange-400",children:"●"}),Be]},Xe)),($e=G.preconditions)==null?void 0:$e.map((Be,Xe)=>e.jsxs("div",{className:"flex gap-1.5",children:[e.jsx("span",{className:"text-blue-400",children:"◆"}),Be]},Xe)),(We=G.sideEffects)==null?void 0:We.map((Be,Xe)=>e.jsxs("div",{className:"flex gap-1.5",children:[e.jsx("span",{className:"text-pink-400",children:"⚡"}),Be]},Xe))]})]}):null})()]})]})]})})()]})};function Nt(t){return t>=1e6?(t/1e6).toFixed(1)+"M":t>=1e3?(t/1e3).toFixed(1)+"k":String(t)}function wr(t){const s=new Map(t.map(l=>[l.date,l])),a=[];for(let l=6;l>=0;l--){const r=new Date;r.setDate(r.getDate()-l);const i=r.toISOString().slice(0,10);a.push(s.get(i)||{date:i,input_tokens:0,output_tokens:0,total_tokens:0,call_count:0})}return a}const kr={user:"bg-blue-500",mcp:"bg-purple-500",bootstrap:"bg-amber-500",guard:"bg-rose-500",analyst:"bg-indigo-500",producer:"bg-green-500"},Cr=()=>{const[t,s]=n.useState([]),[a,l]=n.useState([]),[r,i]=n.useState({input_tokens:0,output_tokens:0,total_tokens:0,call_count:0,avg_per_call:0}),[c,o]=n.useState(!0),[j,g]=n.useState(null);n.useEffect(()=>{let m=!1;return(async()=>{try{const u=await re.getTokenUsage7Days();if(m)return;s(u.daily||[]),l(u.bySource||[]),i(u.summary||{input_tokens:0,output_tokens:0,total_tokens:0,call_count:0,avg_per_call:0})}catch(u){m||g(u.message||"加载失败")}finally{m||o(!1)}})(),()=>{m=!0}},[]);const h=n.useMemo(()=>wr(t),[t]),y=n.useMemo(()=>Math.max(...h.map(m=>m.total_tokens),1),[h]);if(c)return e.jsxs("div",{className:"flex items-center justify-center py-10",children:[e.jsx("div",{className:"animate-spin rounded-full h-6 w-6 border-2 border-blue-500 border-t-transparent"}),e.jsx("span",{className:"ml-2 text-slate-500 text-sm",children:"加载 Token 用量…"})]});if(j)return e.jsx("p",{className:"text-red-500 text-sm py-4 text-center",children:j});const x=r.total_tokens===0;return e.jsxs("div",{className:"space-y-5",children:[e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-3",children:[e.jsx(ls,{label:"总 Token",value:Nt(r.total_tokens),sub:"7 日合计",color:"blue"}),e.jsx(ls,{label:"输入",value:Nt(r.input_tokens),sub:"Prompt",color:"green"}),e.jsx(ls,{label:"输出",value:Nt(r.output_tokens),sub:"Completion",color:"purple"}),e.jsx(ls,{label:"调用",value:String(r.call_count),sub:`均 ${Nt(r.avg_per_call)}/次`,color:"amber"})]}),x?e.jsx("div",{className:"text-center py-8 text-slate-400 text-sm",children:"暂无 Token 使用记录,使用 ChatAgent 或 MCP 后数据将自动记录"}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{children:[e.jsx("h4",{className:"text-sm font-semibold text-slate-700 mb-3",children:"每日用量"}),e.jsx("div",{className:"flex items-end gap-1.5 h-40",children:h.map(m=>{const u=m.input_tokens/y*100,A=m.output_tokens/y*100,S=["日","一","二","三","四","五","六"][new Date(m.date+"T00:00:00").getDay()];return e.jsxs("div",{className:"flex-1 flex flex-col items-center gap-1 group relative",children:[e.jsxs("div",{className:"absolute -top-16 left-1/2 -translate-x-1/2 bg-slate-800 text-white text-xs rounded px-2 py-1 opacity-0 group-hover:opacity-100 transition-opacity whitespace-nowrap pointer-events-none z-10",children:[e.jsx("p",{children:m.date}),e.jsxs("p",{children:["输入 ",Nt(m.input_tokens)," · 输出 ",Nt(m.output_tokens)]}),e.jsxs("p",{children:[m.call_count," 次调用"]})]}),e.jsxs("div",{className:"w-full flex flex-col justify-end",style:{height:"120px"},children:[e.jsx("div",{className:"bg-green-400 rounded-t-sm w-full transition-all",style:{height:`${u}%`,minHeight:m.input_tokens>0?"2px":"0"}}),e.jsx("div",{className:"bg-purple-400 rounded-b-sm w-full transition-all",style:{height:`${A}%`,minHeight:m.output_tokens>0?"2px":"0"}})]}),e.jsx("span",{className:"text-[10px] text-slate-400",children:S})]},m.date)})}),e.jsxs("div",{className:"flex gap-4 mt-2 text-xs text-slate-500 justify-center",children:[e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx("span",{className:"w-2.5 h-2.5 rounded-sm bg-green-400 inline-block"})," 输入"]}),e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx("span",{className:"w-2.5 h-2.5 rounded-sm bg-purple-400 inline-block"})," 输出"]})]})]}),a.length>0&&e.jsxs("div",{children:[e.jsx("h4",{className:"text-sm font-semibold text-slate-700 mb-3",children:"来源分布"}),e.jsx("div",{className:"space-y-2",children:a.map(m=>{const u=r.total_tokens>0?m.total_tokens/r.total_tokens*100:0,A=kr[m.source]||"bg-slate-400";return e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("span",{className:"w-20 text-xs text-slate-600 text-right truncate",children:m.source}),e.jsx("div",{className:"flex-1 bg-slate-100 rounded-full h-3 overflow-hidden",children:e.jsx("div",{className:`${A} h-full rounded-full transition-all`,style:{width:`${u}%`,minWidth:u>0?"4px":"0"}})}),e.jsx("span",{className:"w-16 text-xs text-slate-500 text-right",children:Nt(m.total_tokens)}),e.jsxs("span",{className:"w-12 text-xs text-slate-400 text-right",children:[u.toFixed(0),"%"]})]},m.source)})})]})]})]})};function ls({label:t,value:s,sub:a,color:l}){const r={blue:"bg-blue-50 border-blue-200 text-blue-700",green:"bg-green-50 border-green-200 text-green-700",purple:"bg-purple-50 border-purple-200 text-purple-700",amber:"bg-amber-50 border-amber-200 text-amber-700"},i=r[l]||r.blue;return e.jsxs("div",{className:`rounded-lg border p-3 ${i}`,children:[e.jsx("p",{className:"text-xs opacity-70",children:t}),e.jsx("p",{className:"text-xl font-bold",children:s}),e.jsx("p",{className:"text-[10px] opacity-60",children:a})]})}const Sr=()=>{const[t,s]=n.useState(new Set(["quick-start"])),a=r=>{const i=new Set(t);i.has(r)?i.delete(r):i.add(r),s(i)},l=({id:r,title:i,icon:c,children:o})=>{const j=t.has(r);return e.jsxs("section",{className:"border border-slate-200 rounded-lg overflow-hidden",children:[e.jsxs("button",{onClick:()=>a(r),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:[c,e.jsx("h2",{className:"text-lg font-bold text-slate-800",children:i})]}),j?e.jsx(Ct,{size:E.lg}):e.jsx(st,{size:E.lg})]}),j&&e.jsx("div",{className:"p-4 bg-white",children:o})]})};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(Ye,{size:E.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:"token-usage",title:"Token 用量(近 7 日)",icon:e.jsx(ga,{size:E.xl,className:"text-blue-600"}),children:e.jsx(Cr,{})}),e.jsx(l,{id:"quick-start",title:"快速开始",icon:e.jsx(Ot,{size:E.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",`
68
+ `),language:Js(d)})})]}),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:["★ ",((F=d.stats)==null?void 0:F.authority)??0]}),e.jsxs("span",{children:["使用 ",d.stats?d.stats.guardUsageCount+d.stats.humanUsageCount+d.stats.aiUsageCount:0]}),d.source&&d.source!=="unknown"&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-slate-200",children:"|"}),e.jsx("span",{children:d.source==="bootstrap-scan"?"AI 扫描":d.source==="agent"?"AI Agent":d.source})]}),d.moduleName&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-slate-200",children:"|"}),e.jsx("span",{className:"font-mono",children:d.moduleName})]}),d.relations&&Object.values(d.relations).flat().length>0&&e.jsxs("span",{className:"ml-auto text-purple-500 font-medium",children:["关系 ",Object.values(d.relations).flat().length]})]})]},d.id||L)})})]}),t.length>0&&e.jsx(_s,{currentPage:I,totalPages:fe,totalItems:Ie.length,pageSize:P,onPageChange:Ee,onPageSizeChange:R}),$&&(()=>{var oe,F,te,ge;const d=$,L=Ze(d),N=Vs(d),pe=Js(d),G=d.content;return e.jsxs(Ve,{className:"z-30 flex justify-end",onClick:ae,children:[e.jsx(Ve.Backdrop,{}),e.jsxs("div",{className:`relative h-full bg-white shadow-2xl flex flex-col ${K?"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:L})}),e.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[e.jsx("button",{onClick:ne,disabled:v<=0,className:"p-1.5 hover:bg-slate-100 rounded-lg transition-colors disabled:opacity-30",title:"上一条",children:e.jsx(Zt,{size:T.md})}),e.jsxs("span",{className:"text-xs text-slate-400 tabular-nums",children:[v+1,"/",Ie.length]}),e.jsx("button",{onClick:ve,disabled:v>=Ie.length-1,className:"p-1.5 hover:bg-slate-100 rounded-lg transition-colors disabled:opacity-30",title:"下一条",children:e.jsx(st,{size:T.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:()=>p("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:T.sm})," 预览"]}),e.jsxs("button",{onClick:()=>{p("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(bt,{size:T.sm})," 编辑"]})]}),e.jsx("button",{onClick:X,className:"p-1.5 hover:bg-slate-100 rounded-lg transition-colors text-slate-400",title:K?"收窄":"展宽",children:K?e.jsx(Is,{size:T.md}):e.jsx(hs,{size:T.md})}),e.jsx("button",{onClick:()=>{s(d.name||d.id),ae()},className:"p-1.5 hover:bg-red-50 rounded-lg text-red-500 transition-colors",title:"删除",children:e.jsx(tt,{size:T.md})}),e.jsx("button",{onClick:ae,className:"p-1.5 hover:bg-slate-100 rounded-lg transition-colors",children:e.jsx(Ke,{size:T.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:b.title,onChange:W=>f(be=>({...be,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:b.description,onChange:W=>f(be=>({...be,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:b.tags.map((W,be)=>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:()=>f(Re=>({...Re,tags:Re.tags.filter((Me,_e)=>_e!==be)})),className:"text-blue-400 hover:text-red-500",children:e.jsx(Ke,{size:10})})]},be))}),e.jsx("div",{className:"flex gap-2",children:e.jsx("input",{type:"text",value:b.tagInput,onChange:W=>f(be=>({...be,tagInput:W.target.value})),onKeyDown:W=>{W.key==="Enter"&&b.tagInput.trim()&&(W.preventDefault(),f(be=>({...be,tags:[...be.tags,be.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(et,{size:11,className:"text-blue-400"})," Markdown 文档"]}),e.jsx("textarea",{value:b.markdown,onChange:W=>f(be=>({...be,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(At,{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:b.codePattern,onChange:W=>f(be=>({...be,codePattern:W})),language:pe,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:b.rationale,onChange:W=>f(be=>({...be,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:((oe=d.stats)==null?void 0:oe.authority)??3,onChange:W=>Se(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:()=>p("view"),disabled:w,className:"px-4 py-1.5 text-sm text-slate-600 font-medium rounded-lg hover:bg-slate-50",children:"取消"}),e.jsxs("button",{onClick:ye,disabled:w,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:[w?e.jsx(Te,{size:T.sm,className:"animate-spin"}):e.jsx(Qt,{size:T.sm}),w?"保存中...":"保存"]})]})]})]}):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(ce,{recipe:d}),e.jsx(he,{recipe:d})]}),d.tags&&d.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"}),d.tags.map((W,be)=>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},be))]}),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($s,{size:12,className:"text-purple-400"}),e.jsx("label",{className:"text-[10px] font-bold text-slate-400 uppercase",children:"关联知识"}),(()=>{const W=d.relations?Object.values(d.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:()=>{_(!ue),se("")},className:`text-[9px] px-2 py-0.5 rounded font-bold flex items-center gap-1 transition-colors ${ue?"bg-slate-200 text-slate-600":"bg-purple-500 text-white hover:bg-purple-600"}`,children:ue?e.jsxs(e.Fragment,{children:[e.jsx(Ke,{size:10})," 取消"]}):e.jsxs(e.Fragment,{children:[e.jsx(gt,{size:10})," 添加"]})})]}),ue&&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:M,onChange:W=>ee(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:V.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(dt,{size:12,className:"absolute left-2 top-1/2 -translate-y-1/2 text-slate-300"}),e.jsx("input",{type:"text",placeholder:"搜索...",value:J,onChange:W=>se(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})]})]}),J.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(be=>Ze(be)===L?!1:Ze(be).toLowerCase().includes(J.toLowerCase())).slice(0,10);return W.length?W.map(be=>{const Re=Ze(be),Me=d.relations&&Object.values(d.relations).flat().some(_e=>(typeof _e=="string"?_e:_e.target||_e.id||_e.title||"").replace(/\.md$/i,"").toLowerCase()===Re.toLowerCase());return e.jsxs("div",{className:`flex items-center justify-between px-3 py-1.5 text-xs ${Me?"bg-slate-50 text-slate-400":"hover:bg-purple-50 cursor-pointer"}`,onClick:()=>!Me&&E(M,Re),children:[e.jsx("span",{className:"font-medium truncate mr-2",children:Re}),Me?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:"+ 添加"})]},Re)}):e.jsx("div",{className:"text-xs text-slate-400 py-3 text-center",children:"未找到"})})()})]}),d.relations&&Object.entries(d.relations).some(([,W])=>Array.isArray(W)&&W.length>0)?e.jsx("div",{className:"space-y-1.5",children:V.map(({key:W,label:be,icon:Re})=>{var _e;const Me=(_e=d.relations)==null?void 0:_e[W];return!Me||!Array.isArray(Me)||Me.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:[Re," ",be]}),e.jsx("div",{className:"flex flex-wrap gap-1",children:Me.map((qe,We)=>{const U=typeof qe=="string"?qe:qe.target||qe.id||qe.title||JSON.stringify(qe),$e=De(U)||(D.has(U)?De(D.get(U)):void 0),Ge=$e?Ze($e):D.get(U)||U;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 ${$e?"bg-purple-50 border-purple-200 text-purple-700 cursor-pointer hover:bg-purple-100":"bg-white border-slate-200 text-slate-600"}`,onClick:()=>$e&&Q($e),title:$e?"点击查看":Ge,children:[Ge.replace(/\.md$/i,""),e.jsx("button",{onClick:Be=>{Be.stopPropagation(),xe(W,U)},className:"opacity-0 group-hover/rel:opacity-100 text-red-400 hover:text-red-600 transition-opacity ml-0.5",title:"移除",children:e.jsx(Ke,{size:10})})]},We)})})]},W)})}):!ue&&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:((F=d.stats)==null?void 0:F.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:((te=d.stats)==null?void 0:te.authorityScore)!=null?d.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:d.stats?d.stats.guardUsageCount+d.stats.humanUsageCount+d.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:Ys((ge=d.stats)==null?void 0:ge.lastUsedAt)||"从未使用"}),e.jsx("div",{className:"text-[10px] text-slate-400 font-medium",children:"最近使用"})]})]}),d.stats!=null&&(d.stats.guardUsageCount>0||d.stats.humanUsageCount>0||d.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: ",d.stats.guardUsageCount]}),e.jsxs("span",{children:["Human: ",d.stats.humanUsageCount]}),e.jsxs("span",{children:["AI: ",d.stats.aiUsageCount]})]})]}),d.reasoning&&(d.reasoning.whyStandard||d.reasoning.sources&&d.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(ht,{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:[d.reasoning.whyStandard&&e.jsx("p",{className:"text-sm text-slate-700 leading-relaxed",children:d.reasoning.whyStandard}),d.reasoning.sources&&d.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:"来源:"}),d.reasoning.sources.map((W,be)=>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},be))]}),d.reasoning.confidence!=null&&d.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(d.reasoning.confidence*100)}%`}})}),e.jsxs("span",{className:"text-[10px] font-bold text-amber-600",children:[Math.round(d.reasoning.confidence*100),"%"]})]}),d.reasoning.alternatives&&d.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:"备选:"}),d.reasoning.alternatives.map((W,be)=>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},be))]})]})]}),d.quality&&d.quality.grade&&d.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 ${d.quality.grade==="A"?"text-emerald-600":d.quality.grade==="B"?"text-blue-600":d.quality.grade==="C"?"text-amber-600":d.quality.grade==="D"?"text-orange-600":"text-slate-400"}`,children:d.quality.grade}),e.jsxs("div",{className:"flex-1 grid grid-cols-3 gap-2 text-[10px]",children:[d.quality.completeness!=null&&d.quality.completeness>0&&e.jsxs("div",{className:"text-center",children:[e.jsx("div",{className:"font-bold text-slate-700",children:d.quality.completeness}),e.jsx("div",{className:"text-slate-400",children:"完整性"})]}),d.quality.adaptation!=null&&d.quality.adaptation>0&&e.jsxs("div",{className:"text-center",children:[e.jsx("div",{className:"font-bold text-slate-700",children:d.quality.adaptation}),e.jsx("div",{className:"text-slate-400",children:"适配度"})]}),d.quality.documentation!=null&&d.quality.documentation>0&&e.jsxs("div",{className:"text-center",children:[e.jsx("div",{className:"font-bold text-slate-700",children:d.quality.documentation}),e.jsx("div",{className:"text-slate-400",children:"文档度"})]})]})]})]}),d.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:d.description})]}),(G==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(et,{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(mt,{content:G.markdown})})})]}),d.headers&&d.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:d.headers.map((W,be)=>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},be))})]}),N&&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(xt,{size:11,className:"text-emerald-500"})," 代码 / 标准用法"]}),e.jsx(rt,{code:N,language:pe,showLineNumbers:!0})]}),(G==null?void 0:G.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:G.rationale})})]}),(G==null?void 0:G.steps)&&G.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:G.steps.map((W,be)=>{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:be+1}),e.jsx("p",{className:"text-xs text-slate-700 leading-relaxed",children:W})]},be);const Re=typeof W.title=="string"?W.title:"",Me=typeof W.description=="string"?W.description:"",_e=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:be+1}),Re&&e.jsx("span",{className:"text-xs font-bold text-slate-700",children:Re})]}),Me&&e.jsx("p",{className:"text-xs text-slate-600 ml-7 leading-relaxed",children:Me}),_e&&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:_e})]},be)})})]}),(G==null?void 0:G.codeChanges)&&G.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:G.codeChanges.map((W,be)=>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(xt,{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})]})]},be))})]}),(G==null?void 0:G.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:[G.verification.method&&e.jsxs("p",{className:"text-xs text-slate-600",children:[e.jsx("span",{className:"font-bold text-teal-600",children:"方法:"})," ",G.verification.method]}),G.verification.expectedResult&&e.jsxs("p",{className:"text-xs text-slate-600",children:[e.jsx("span",{className:"font-bold text-teal-600",children:"预期:"})," ",G.verification.expectedResult]}),G.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:G.verification.testCode})]})]}),d.constraints&&(()=>{var Re,Me,_e,qe,We,U,$e,Ge;const W=d.constraints,be=(((Re=W.guards)==null?void 0:Re.length)||0)+(((Me=W.boundaries)==null?void 0:Me.length)||0)+(((_e=W.preconditions)==null?void 0:_e.length)||0)+(((qe=W.sideEffects)==null?void 0:qe.length)||0);return be?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:be})]}),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)),(U=W.boundaries)==null?void 0:U.map((Be,Xe)=>e.jsxs("div",{className:"flex gap-1.5",children:[e.jsx("span",{className:"text-orange-400",children:"●"}),Be]},Xe)),($e=W.preconditions)==null?void 0:$e.map((Be,Xe)=>e.jsxs("div",{className:"flex gap-1.5",children:[e.jsx("span",{className:"text-blue-400",children:"◆"}),Be]},Xe)),(Ge=W.sideEffects)==null?void 0:Ge.map((Be,Xe)=>e.jsxs("div",{className:"flex gap-1.5",children:[e.jsx("span",{className:"text-pink-400",children:"⚡"}),Be]},Xe))]})]}):null})()]})]})]})})()]})};function Nt(t){return t>=1e6?(t/1e6).toFixed(1)+"M":t>=1e3?(t/1e3).toFixed(1)+"k":String(t)}function wr(t){const s=new Map(t.map(l=>[l.date,l])),a=[];for(let l=6;l>=0;l--){const r=new Date;r.setDate(r.getDate()-l);const i=r.toISOString().slice(0,10);a.push(s.get(i)||{date:i,input_tokens:0,output_tokens:0,total_tokens:0,call_count:0})}return a}const kr={user:"bg-blue-500",mcp:"bg-purple-500",bootstrap:"bg-amber-500",guard:"bg-rose-500",analyst:"bg-indigo-500",producer:"bg-green-500"},Cr=()=>{const[t,s]=n.useState([]),[a,l]=n.useState([]),[r,i]=n.useState({input_tokens:0,output_tokens:0,total_tokens:0,call_count:0,avg_per_call:0}),[c,o]=n.useState(!0),[j,g]=n.useState(null);n.useEffect(()=>{let m=!1;return(async()=>{try{const u=await re.getTokenUsage7Days();if(m)return;s(u.daily||[]),l(u.bySource||[]),i(u.summary||{input_tokens:0,output_tokens:0,total_tokens:0,call_count:0,avg_per_call:0})}catch(u){m||g(u.message||"加载失败")}finally{m||o(!1)}})(),()=>{m=!0}},[]);const h=n.useMemo(()=>wr(t),[t]),y=n.useMemo(()=>Math.max(...h.map(m=>m.total_tokens),1),[h]);if(c)return e.jsxs("div",{className:"flex items-center justify-center py-10",children:[e.jsx("div",{className:"animate-spin rounded-full h-6 w-6 border-2 border-blue-500 border-t-transparent"}),e.jsx("span",{className:"ml-2 text-slate-500 text-sm",children:"加载 Token 用量…"})]});if(j)return e.jsx("p",{className:"text-red-500 text-sm py-4 text-center",children:j});const x=r.total_tokens===0;return e.jsxs("div",{className:"space-y-5",children:[e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-3",children:[e.jsx(ls,{label:"总 Token",value:Nt(r.total_tokens),sub:"7 日合计",color:"blue"}),e.jsx(ls,{label:"输入",value:Nt(r.input_tokens),sub:"Prompt",color:"green"}),e.jsx(ls,{label:"输出",value:Nt(r.output_tokens),sub:"Completion",color:"purple"}),e.jsx(ls,{label:"调用",value:String(r.call_count),sub:`均 ${Nt(r.avg_per_call)}/次`,color:"amber"})]}),x?e.jsx("div",{className:"text-center py-8 text-slate-400 text-sm",children:"暂无 Token 使用记录,使用 ChatAgent 或 MCP 后数据将自动记录"}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{children:[e.jsx("h4",{className:"text-sm font-semibold text-slate-700 mb-3",children:"每日用量"}),e.jsx("div",{className:"flex items-end gap-1.5 h-40",children:h.map(m=>{const u=m.input_tokens/y*100,A=m.output_tokens/y*100,S=["日","一","二","三","四","五","六"][new Date(m.date+"T00:00:00").getDay()];return e.jsxs("div",{className:"flex-1 flex flex-col items-center gap-1 group relative",children:[e.jsxs("div",{className:"absolute -top-16 left-1/2 -translate-x-1/2 bg-slate-800 text-white text-xs rounded px-2 py-1 opacity-0 group-hover:opacity-100 transition-opacity whitespace-nowrap pointer-events-none z-10",children:[e.jsx("p",{children:m.date}),e.jsxs("p",{children:["输入 ",Nt(m.input_tokens)," · 输出 ",Nt(m.output_tokens)]}),e.jsxs("p",{children:[m.call_count," 次调用"]})]}),e.jsxs("div",{className:"w-full flex flex-col justify-end",style:{height:"120px"},children:[e.jsx("div",{className:"bg-green-400 rounded-t-sm w-full transition-all",style:{height:`${u}%`,minHeight:m.input_tokens>0?"2px":"0"}}),e.jsx("div",{className:"bg-purple-400 rounded-b-sm w-full transition-all",style:{height:`${A}%`,minHeight:m.output_tokens>0?"2px":"0"}})]}),e.jsx("span",{className:"text-[10px] text-slate-400",children:S})]},m.date)})}),e.jsxs("div",{className:"flex gap-4 mt-2 text-xs text-slate-500 justify-center",children:[e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx("span",{className:"w-2.5 h-2.5 rounded-sm bg-green-400 inline-block"})," 输入"]}),e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx("span",{className:"w-2.5 h-2.5 rounded-sm bg-purple-400 inline-block"})," 输出"]})]})]}),a.length>0&&e.jsxs("div",{children:[e.jsx("h4",{className:"text-sm font-semibold text-slate-700 mb-3",children:"来源分布"}),e.jsx("div",{className:"space-y-2",children:a.map(m=>{const u=r.total_tokens>0?m.total_tokens/r.total_tokens*100:0,A=kr[m.source]||"bg-slate-400";return e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("span",{className:"w-20 text-xs text-slate-600 text-right truncate",children:m.source}),e.jsx("div",{className:"flex-1 bg-slate-100 rounded-full h-3 overflow-hidden",children:e.jsx("div",{className:`${A} h-full rounded-full transition-all`,style:{width:`${u}%`,minWidth:u>0?"4px":"0"}})}),e.jsx("span",{className:"w-16 text-xs text-slate-500 text-right",children:Nt(m.total_tokens)}),e.jsxs("span",{className:"w-12 text-xs text-slate-400 text-right",children:[u.toFixed(0),"%"]})]},m.source)})})]})]})]})};function ls({label:t,value:s,sub:a,color:l}){const r={blue:"bg-blue-50 border-blue-200 text-blue-700",green:"bg-green-50 border-green-200 text-green-700",purple:"bg-purple-50 border-purple-200 text-purple-700",amber:"bg-amber-50 border-amber-200 text-amber-700"},i=r[l]||r.blue;return e.jsxs("div",{className:`rounded-lg border p-3 ${i}`,children:[e.jsx("p",{className:"text-xs opacity-70",children:t}),e.jsx("p",{className:"text-xl font-bold",children:s}),e.jsx("p",{className:"text-[10px] opacity-60",children:a})]})}const Sr=()=>{const[t,s]=n.useState(new Set(["quick-start"])),a=r=>{const i=new Set(t);i.has(r)?i.delete(r):i.add(r),s(i)},l=({id:r,title:i,icon:c,children:o})=>{const j=t.has(r);return e.jsxs("section",{className:"border border-slate-200 rounded-lg overflow-hidden",children:[e.jsxs("button",{onClick:()=>a(r),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:[c,e.jsx("h2",{className:"text-lg font-bold text-slate-800",children:i})]}),j?e.jsx(Ct,{size:T.lg}):e.jsx(st,{size:T.lg})]}),j&&e.jsx("div",{className:"p-4 bg-white",children:o})]})};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(Ye,{size:T.xxl,className:"text-blue-600"}),"AutoSnippet V3 使用说明"]}),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 可自建 · 16 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:"token-usage",title:"Token 用量(近 7 日)",icon:e.jsx(ga,{size:T.xl,className:"text-blue-600"}),children:e.jsx(Cr,{})}),e.jsx(l,{id:"quick-start",title:"快速开始",icon:e.jsx(Ot,{size:T.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",`
69
69
  `,"cd your-project",`
70
- `,"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(xa,{size:E.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(Je,{size:E.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(ll,{size:E.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(xt,{size:E.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(Rs,{size:E.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(dt,{size:E.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:E.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(Je,{size:E.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:E.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(dt,{size:E.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:E.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(pt,{size:E.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(Ls,{size:E.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(kt,{size:E.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(r=>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:r.name}),e.jsx("p",{className:"text-xs text-slate-500 mt-0.5",children:r.desc})]},r.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(Qe,{size:E.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(Je,{size:E.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(dt,{size:E.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(Rs,{size:E.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:E.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(Ls,{size:E.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 Ir(){const[t,s]=n.useState(null);n.useEffect(()=>{const i=As(),c=y=>{s({status:"running",total:y.total,current:0,progress:0,refined:0,failed:0,items:y.candidateIds.map(x=>({candidateId:x,title:"",status:"pending"}))})},o=y=>{s(x=>x&&{...x,current:y.current,progress:y.progress,items:x.items.map(m=>m.candidateId===y.candidateId?{...m,title:y.title,status:"refining"}:m)})},j=y=>{s(x=>x&&{...x,current:y.current,progress:y.progress,refined:y.refinedSoFar,items:x.items.map(m=>m.candidateId===y.candidateId?{...m,title:y.title,status:"done",refined:y.refined}:m)})},g=y=>{s(x=>x&&{...x,current:y.current,progress:y.progress,failed:x.failed+1,items:x.items.map(m=>m.candidateId===y.candidateId?{...m,title:y.title,status:"failed",error:y.error}:m)})},h=y=>{s(x=>x&&{...x,status:"completed",progress:100,refined:y.refined,failed:y.failed})};return i.on("refine:started",c),i.on("refine:item-started",o),i.on("refine:item-completed",j),i.on("refine:item-failed",g),i.on("refine:completed",h),()=>{i.off("refine:started",c),i.off("refine:item-started",o),i.off("refine:item-completed",j),i.off("refine:item-failed",g),i.off("refine:completed",h)}},[]);const a=n.useCallback(()=>s(null),[]),l=(t==null?void 0:t.status)==="running",r=(t==null?void 0:t.status)==="completed";return{refine:t,isRefining:l,isRefineDone:r,resetRefine:a}}const $r=({refine:t,isRefineDone:s,onDismiss:a})=>{const l=n.useRef(!1);if(n.useEffect(()=>{if(s&&t&&!l.current){l.current=!0;const c=t.failed>0?`${t.refined} 条已更新,${t.failed} 条失败`:`${t.refined}/${t.total} 条候选已更新`;le(c,{title:"AI 润色完成",type:t.failed>0?"error":"success"})}},[s,t]),n.useEffect(()=>{t||(l.current=!1)},[t]),!t)return null;const r=t.items.find(c=>c.status==="refining"),i=t.items.filter(c=>c.status==="done"||c.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(ft,{className:"w-4 h-4 text-emerald-600"}):e.jsx(Ue,{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} 条失败`:""}`:`${i}/${t.total} 条候选`,r&&!s&&e.jsxs("span",{className:"ml-2 text-blue-600",children:[e.jsx(Ee,{className:"w-3 h-3 inline animate-spin mr-1"}),r.title||r.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(Ke,{className:"w-3 h-3"}),t.items.filter(c=>c.status==="failed").map(c=>c.title||c.candidateId.slice(0,8)).join("、")]})]})},Xs={_watch:"as:create",_draft:"草稿",_cli:"CLI",_pending:"待审核(24h)",_recipe:"New Recipe"};function zr(t,s,a,l){return[...t].sort(([r],[i])=>{const c=l(r),o=l(i);if(c&&!o)return 1;if(!c&&o)return-1;const j=a(r),g=a(i);if(j&&!g)return-1;if(!j&&g)return 1;const h=s(r),y=s(i);return h&&!y?1:!h&&y?-1:r.localeCompare(i)})}function Rt(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 i=new Date().getTime()-l.getTime();if(i<0)return l.toLocaleDateString("zh-CN");const c=Math.floor(i/6e4);if(c<1)return"刚刚";if(c<60)return`${c} 分钟前`;const o=Math.floor(c/60);if(o<24)return`${o} 小时前`;const j=Math.floor(o/24);return j<7?`${j} 天前`:l.toLocaleDateString("zh-CN")}function Ar(t,s=4){return t?_s(t).split(`
70
+ `,"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(xa,{size:T.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 理解规范;16 个 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(Je,{size:T.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"}),"(operation: knowledge / refine / scan)"]})]})]}),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(ll,{size:T.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(xt,{size:T.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(Rs,{size:T.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(dt,{size:T.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:"search MCP 工具:mode 参数路由 auto / keyword / semantic / context 四种模式"})]})]}),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:T.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"}),"(code=单文件 / files=批量)、",e.jsx("code",{className:"bg-rose-100 px-1 rounded",children:"bootstrap"}),"(operation: scan)"]})]})]})]})]}),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(Je,{size:T.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:T.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(dt,{size:T.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"}),":search 统合工具(mode 路由 4 种模式)"]}),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:T.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:"Guard 审查"}),":MCP ",e.jsx("code",{className:"bg-slate-100 px-1 rounded text-xs",children:"guard"}),"(code / files 参数)"]}),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(pt,{size:T.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:"structure"}),"(operation: targets / files)MCP 工具"]})]})]})]})}),e.jsxs(l,{id:"editor-directives",title:"编辑器指令",icon:e.jsx(Ls,{size:T.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(kt,{size:T.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(r=>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:r.name}),e.jsx("p",{className:"text-xs text-slate-500 mt-0.5",children:r.desc})]},r.name))})]}),e.jsxs("div",{className:"mb-5",children:[e.jsx("h3",{className:"font-semibold text-slate-800 mb-3",children:"16 个 MCP 工具(V3 参数化统合)"}),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",children:"说明"})]})}),e.jsxs("tbody",{children:[e.jsx("tr",{className:"bg-blue-50/30",children:e.jsx("td",{colSpan:3,className:"px-3 py-1.5 border-b font-semibold text-blue-700 text-xs",children:"Agent 层(12 个)— 默认对外暴露"})}),e.jsxs("tr",{children:[e.jsx("td",{className:"px-3 py-2 border-b font-medium",children:"agent"}),e.jsx("td",{className:"px-3 py-2 border-b",children:e.jsx("code",{children:"health"})}),e.jsx("td",{className:"px-3 py-2 border-b",children:"服务健康检查"})]}),e.jsxs("tr",{children:[e.jsx("td",{className:"px-3 py-2 border-b font-medium",children:"agent"}),e.jsx("td",{className:"px-3 py-2 border-b",children:e.jsx("code",{children:"capabilities"})}),e.jsx("td",{className:"px-3 py-2 border-b",children:"服务能力清单(Agent 自发现)"})]}),e.jsxs("tr",{children:[e.jsx("td",{className:"px-3 py-2 border-b font-medium",children:"agent"}),e.jsx("td",{className:"px-3 py-2 border-b",children:e.jsx("code",{children:"search"})}),e.jsx("td",{className:"px-3 py-2 border-b",children:"mode 路由 auto / keyword / semantic / context"})]}),e.jsxs("tr",{children:[e.jsx("td",{className:"px-3 py-2 border-b font-medium",children:"agent"}),e.jsx("td",{className:"px-3 py-2 border-b",children:e.jsx("code",{children:"knowledge"})}),e.jsx("td",{className:"px-3 py-2 border-b",children:"operation 路由 list / get / insights / confirm_usage"})]}),e.jsxs("tr",{children:[e.jsx("td",{className:"px-3 py-2 border-b font-medium",children:"agent"}),e.jsx("td",{className:"px-3 py-2 border-b",children:e.jsx("code",{children:"structure"})}),e.jsx("td",{className:"px-3 py-2 border-b",children:"operation 路由 targets / files / metadata"})]}),e.jsxs("tr",{children:[e.jsx("td",{className:"px-3 py-2 border-b font-medium",children:"agent"}),e.jsx("td",{className:"px-3 py-2 border-b",children:e.jsx("code",{children:"graph"})}),e.jsx("td",{className:"px-3 py-2 border-b",children:"operation 路由 query / impact / path / stats"})]}),e.jsxs("tr",{children:[e.jsx("td",{className:"px-3 py-2 border-b font-medium",children:"agent"}),e.jsx("td",{className:"px-3 py-2 border-b",children:e.jsx("code",{children:"guard"})}),e.jsx("td",{className:"px-3 py-2 border-b",children:"code=单文件审查 / files=批量审查"})]}),e.jsxs("tr",{children:[e.jsx("td",{className:"px-3 py-2 border-b font-medium",children:"agent"}),e.jsxs("td",{className:"px-3 py-2 border-b",children:[e.jsx("code",{children:"submit_knowledge"})," / ",e.jsx("code",{children:"submit_knowledge_batch"})," / ",e.jsx("code",{children:"save_document"})]}),e.jsx("td",{className:"px-3 py-2 border-b",children:"提交候选 / 批量 / 保存文档"})]}),e.jsxs("tr",{children:[e.jsx("td",{className:"px-3 py-2 border-b font-medium",children:"agent"}),e.jsx("td",{className:"px-3 py-2 border-b",children:e.jsx("code",{children:"skill"})}),e.jsx("td",{className:"px-3 py-2 border-b",children:"operation 路由 list / load / create / update / delete / suggest"})]}),e.jsxs("tr",{children:[e.jsx("td",{className:"px-3 py-2 border-b font-medium",children:"agent"}),e.jsx("td",{className:"px-3 py-2 border-b",children:e.jsx("code",{children:"bootstrap"})}),e.jsx("td",{className:"px-3 py-2 border-b",children:"operation 路由 knowledge / refine / scan"})]}),e.jsx("tr",{className:"bg-amber-50/30",children:e.jsx("td",{colSpan:3,className:"px-3 py-1.5 border-b font-semibold text-amber-700 text-xs",children:"Admin 层(4 个)— 需设置 ASD_MCP_TIER=admin"})}),e.jsxs("tr",{children:[e.jsx("td",{className:"px-3 py-2 border-b font-medium",children:"admin"}),e.jsxs("td",{className:"px-3 py-2 border-b",children:[e.jsx("code",{children:"enrich_candidates"})," / ",e.jsx("code",{children:"validate_candidate"})," / ",e.jsx("code",{children:"check_duplicate"})]}),e.jsx("td",{className:"px-3 py-2 border-b",children:"AI 润色 / 校验 / 查重"})]}),e.jsxs("tr",{children:[e.jsx("td",{className:"px-3 py-2 font-medium",children:"admin"}),e.jsx("td",{className:"px-3 py-2",children:e.jsx("code",{children:"knowledge_lifecycle"})}),e.jsx("td",{className:"px-3 py-2",children:"批量生命周期操作"})]})]})]})}),e.jsx("p",{className:"text-xs text-slate-500 mt-2",children:"写操作工具(submit_knowledge、guard、bootstrap 等)通过 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:"V3 架构",icon:e.jsx(Qe,{size:T.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(Je,{size:T.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 工具(operation: 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(dt,{size:T.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(Rs,{size:T.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:T.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 × 16 工具"})]}),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(Ls,{size:T.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 Ir(){const[t,s]=n.useState(null);n.useEffect(()=>{const i=As(),c=y=>{s({status:"running",total:y.total,current:0,progress:0,refined:0,failed:0,items:y.candidateIds.map(x=>({candidateId:x,title:"",status:"pending"}))})},o=y=>{s(x=>x&&{...x,current:y.current,progress:y.progress,items:x.items.map(m=>m.candidateId===y.candidateId?{...m,title:y.title,status:"refining"}:m)})},j=y=>{s(x=>x&&{...x,current:y.current,progress:y.progress,refined:y.refinedSoFar,items:x.items.map(m=>m.candidateId===y.candidateId?{...m,title:y.title,status:"done",refined:y.refined}:m)})},g=y=>{s(x=>x&&{...x,current:y.current,progress:y.progress,failed:x.failed+1,items:x.items.map(m=>m.candidateId===y.candidateId?{...m,title:y.title,status:"failed",error:y.error}:m)})},h=y=>{s(x=>x&&{...x,status:"completed",progress:100,refined:y.refined,failed:y.failed})};return i.on("refine:started",c),i.on("refine:item-started",o),i.on("refine:item-completed",j),i.on("refine:item-failed",g),i.on("refine:completed",h),()=>{i.off("refine:started",c),i.off("refine:item-started",o),i.off("refine:item-completed",j),i.off("refine:item-failed",g),i.off("refine:completed",h)}},[]);const a=n.useCallback(()=>s(null),[]),l=(t==null?void 0:t.status)==="running",r=(t==null?void 0:t.status)==="completed";return{refine:t,isRefining:l,isRefineDone:r,resetRefine:a}}const $r=({refine:t,isRefineDone:s,onDismiss:a})=>{const l=n.useRef(!1);if(n.useEffect(()=>{if(s&&t&&!l.current){l.current=!0;const c=t.failed>0?`${t.refined} 条已更新,${t.failed} 条失败`:`${t.refined}/${t.total} 条候选已更新`;le(c,{title:"AI 润色完成",type:t.failed>0?"error":"success"})}},[s,t]),n.useEffect(()=>{t||(l.current=!1)},[t]),!t)return null;const r=t.items.find(c=>c.status==="refining"),i=t.items.filter(c=>c.status==="done"||c.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(ft,{className:"w-4 h-4 text-emerald-600"}):e.jsx(Ue,{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} 条失败`:""}`:`${i}/${t.total} 条候选`,r&&!s&&e.jsxs("span",{className:"ml-2 text-blue-600",children:[e.jsx(Te,{className:"w-3 h-3 inline animate-spin mr-1"}),r.title||r.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(Ke,{className:"w-3 h-3"}),t.items.filter(c=>c.status==="failed").map(c=>c.title||c.candidateId.slice(0,8)).join("、")]})]})},Xs={_watch:"as:create",_draft:"草稿",_cli:"CLI",_pending:"待审核(24h)",_recipe:"New Recipe"};function zr(t,s,a,l){return[...t].sort(([r],[i])=>{const c=l(r),o=l(i);if(c&&!o)return 1;if(!c&&o)return-1;const j=a(r),g=a(i);if(j&&!g)return-1;if(!j&&g)return 1;const h=s(r),y=s(i);return h&&!y?1:!h&&y?-1:r.localeCompare(i)})}function Rt(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 i=new Date().getTime()-l.getTime();if(i<0)return l.toLocaleDateString("zh-CN");const c=Math.floor(i/6e4);if(c<1)return"刚刚";if(c<60)return`${c} 分钟前`;const o=Math.floor(c/60);if(o<24)return`${o} 小时前`;const j=Math.floor(o/24);return j<7?`${j} 天前`:l.toLocaleDateString("zh-CN")}function Ar(t,s=4){return t?Es(t).split(`
71
71
  `).slice(0,s).join(`
72
- `):""}function _r(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 Zs={"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"}},Er=({value:t,size:s=36})=>{const a=(s-6)/2,l=2*Math.PI*a,r=t!=null?Math.max(0,Math.min(1,t)):0,i=l*(1-r),{ring:c,text:o}=_r(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:c,strokeDasharray:l,strokeDashoffset:i,style:{transition:"stroke-dashoffset 0.5s ease"}})]}),e.jsx("span",{className:`absolute text-[9px] font-bold ${o}`,children:t!=null?`${Math.round(t*100)}`:"—"})]})},Tr=({data:t,isShellTarget:s,isSilentTarget:a=()=>!1,isPendingTarget:l=()=>!1,handleDeleteCandidate:r,handleDeleteAllInTarget:i,onAuditCandidate:c,onAuditAllInTarget:o,onEditRecipe:j,onColdStart:g,isScanning:h,isBootstrapping:y,onRefresh:x})=>{var he;const[m,u]=n.useState(null),{isWide:A,toggle:S}=Ts(),[I,P]=n.useState(new Set),[B,R]=n.useState(new Set),[K,X]=n.useState(!1),[$,H]=n.useState(!1),C=ts(),{refine:p,isRefining:O,isRefineDone:k,resetRefine:b}=Ir(),[f,w]=n.useState({}),[Z,q]=n.useState(null),[ue,M]=n.useState({}),[T,ee]=n.useState(null),[J,se]=n.useState({}),[V,Q]=n.useState({sort:"default",onlySimilar:!1}),[ae,ye]=n.useState(null),Se=n.useRef(new Set),De=n.useCallback(async(d,L)=>{if(!Se.current.has(L)){Se.current.add(L),ee(L);try{const N=await re.getCandidateSimilarityEx({targetName:d,candidateId:L});M(pe=>({...pe,[L]:N.similar||[]}))}catch{M(pe=>({...pe,[L]:[]}))}finally{ee(null)}}},[]),D=n.useCallback(async(d,L,N,pe=[])=>{var ge,G,be,Re;const W=N.replace(/\.md$/i,"");let oe="";const F=(ge=t==null?void 0:t.recipes)==null?void 0:ge.find(Te=>Te.name===W||Te.name.endsWith("/"+W));if(F!=null&&F.content)oe=[F.content.pattern,F.content.markdown].filter(Boolean).join(`
72
+ `):""}function Er(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 Zs={"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"}},Tr=({value:t,size:s=36})=>{const a=(s-6)/2,l=2*Math.PI*a,r=t!=null?Math.max(0,Math.min(1,t)):0,i=l*(1-r),{ring:c,text:o}=Er(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:c,strokeDasharray:l,strokeDashoffset:i,style:{transition:"stroke-dashoffset 0.5s ease"}})]}),e.jsx("span",{className:`absolute text-[9px] font-bold ${o}`,children:t!=null?`${Math.round(t*100)}`:"—"})]})},Mr=({data:t,isShellTarget:s,isSilentTarget:a=()=>!1,isPendingTarget:l=()=>!1,handleDeleteCandidate:r,handleDeleteAllInTarget:i,onAuditCandidate:c,onAuditAllInTarget:o,onEditRecipe:j,onColdStart:g,isScanning:h,isBootstrapping:y,onRefresh:x})=>{var he;const[m,u]=n.useState(null),{isWide:A,toggle:S}=Ms(),[I,P]=n.useState(new Set),[B,R]=n.useState(new Set),[K,X]=n.useState(!1),[$,H]=n.useState(!1),C=ts(),{refine:p,isRefining:O,isRefineDone:k,resetRefine:b}=Ir(),[f,w]=n.useState({}),[Z,q]=n.useState(null),[ue,_]=n.useState({}),[M,ee]=n.useState(null),[J,se]=n.useState({}),[V,Q]=n.useState({sort:"default",onlySimilar:!1}),[ae,ye]=n.useState(null),Se=n.useRef(new Set),De=n.useCallback(async(d,L)=>{if(!Se.current.has(L)){Se.current.add(L),ee(L);try{const N=await re.getCandidateSimilarityEx({targetName:d,candidateId:L});_(pe=>({...pe,[L]:N.similar||[]}))}catch{_(pe=>({...pe,[L]:[]}))}finally{ee(null)}}},[]),D=n.useCallback(async(d,L,N,pe=[])=>{var ge,W,be,Re;const G=N.replace(/\.md$/i,"");let oe="";const F=(ge=t==null?void 0:t.recipes)==null?void 0:ge.find(Me=>Me.name===G||Me.name.endsWith("/"+G));if(F!=null&&F.content)oe=[F.content.pattern,F.content.markdown].filter(Boolean).join(`
73
73
 
74
- `)||"";else try{oe=(await re.getRecipeContentByName(W)).content}catch(Te){const Me=(G=Te.response)==null?void 0:G.status,qe=((Re=(be=Te.response)==null?void 0:be.data)==null?void 0:Re.message)||Te.message;Me===404?le(`"${W}" 不存在于当前知识库`,{title:"Recipe 不存在",type:"error"}):le(qe,{title:"加载 Recipe 失败",type:"error"});return}const te={[W]:oe};u(d.id),ye({candidate:d,targetName:L,recipeName:W,recipeContent:oe,similarList:pe.slice(0,3),recipeContents:te})},[t==null?void 0:t.recipes]),_=t!=null&&t.candidates?Object.entries(t.candidates):[],xe=zr(_,s,a,l),Ie=xe.map(([d])=>d),fe=Z&&Ie.includes(Z)?Z:Ie[0]??null;n.useEffect(()=>{Ie.length>0&&(!Z||!Ie.includes(Z))&&q(Ie[0])},[Ie.join(","),Z]),n.useEffect(()=>{m&&fe&&De(fe,m)},[m,fe,De]);const Ae=n.useMemo(()=>{var oe;if(!fe||!((oe=t==null?void 0:t.candidates)!=null&&oe[fe]))return null;const d=t.candidates[fe].items,L=d.length,N=d.reduce((F,te)=>{var ge;return F+(((ge=te.reasoning)==null?void 0:ge.confidence)??0)},0)/(L||1),pe=d.filter(F=>{var te;return((te=F.content)==null?void 0:te.pattern)&&F.content.pattern.trim().length>0}).length,W=new Map;return d.forEach(F=>{const te=F.source||"unknown";W.set(te,(W.get(te)||0)+1)}),{total:L,avgConfidence:N,withCode:pe,sources:W}},[fe,t==null?void 0:t.candidates]),Oe=n.useMemo(()=>{const d=new Map;if(t!=null&&t.idTitleMap)for(const[L,N]of Object.entries(t.idTitleMap))d.set(L,N);if(t!=null&&t.candidates)for(const L of Object.values(t.candidates))for(const N of L.items)N.id&&N.title&&d.set(N.id,N.title);if(t!=null&&t.recipes)for(const L of t.recipes)L.id&&L.name&&d.set(L.id,L.name.replace(/\.md$/i,""));return d},[t==null?void 0:t.idTitleMap,t==null?void 0:t.candidates,t==null?void 0:t.recipes]),_e=n.useCallback(async d=>{var L,N,pe,W,oe;if(!I.has(d)){P(F=>new Set(F).add(d));try{const F=await re.enrichCandidates([d]);F.enriched>0?le(`已补齐 ${((pe=(N=(L=F.results)==null?void 0:L[0])==null?void 0:N.filledFields)==null?void 0:pe.length)||0} 个结构字段`,{title:"AI 补齐完成"}):le("无缺失字段,均已完整",{title:"无需补齐",type:"info"});try{const te=await re.getCandidate(d);se(ge=>({...ge,[d]:te}))}catch{}}catch(F){const te=(oe=(W=F.response)==null?void 0:W.data)==null?void 0:oe.error;le(typeof te=="string"?te:(te==null?void 0:te.message)||F.message,{title:"AI 补齐失败",type:"error"})}finally{P(F=>{const te=new Set(F);return te.delete(d),te})}}},[I,x]),v=n.useCallback(async()=>{var L,N,pe;if(K||!fe||!((L=t==null?void 0:t.candidates)!=null&&L[fe]))return;const d=t.candidates[fe].items;if(d.length!==0){X(!0);try{let W=0;for(let oe=0;oe<d.length;oe+=20){const F=d.slice(oe,oe+20).map(ge=>ge.id),te=await re.enrichCandidates(F);W+=te.enriched}le(`${W}/${d.length} 条候选已更新`,{title:"① 结构补齐完成"}),x==null||x()}catch(W){const oe=(pe=(N=W.response)==null?void 0:N.data)==null?void 0:pe.error;le(typeof oe=="string"?oe:(oe==null?void 0:oe.message)||W.message,{title:"① 结构补齐失败",type:"error"})}finally{X(!1)}}},[K,fe,t==null?void 0:t.candidates,x]),ne=n.useCallback(async d=>{try{const L=await re.getCandidate(d);se(N=>({...N,[d]:L}))}catch{}},[]),ve=n.useCallback(()=>{var N;if(!fe||!((N=t==null?void 0:t.candidates)!=null&&N[fe]))return;const d=t.candidates[fe].items,L=d.map(pe=>pe.id);C.openRefine({candidateIds:L,candidates:d,onCandidateUpdated:ne})},[fe,t==null?void 0:t.candidates,C,ne]),ce=n.useCallback(d=>{var N;if(!fe||!((N=t==null?void 0:t.candidates)!=null&&N[fe]))return;ye(null),u(d);const L=t.candidates[fe].items;C.openRefine({candidateIds:[d],candidates:L,onCandidateUpdated:ne})},[fe,t==null?void 0:t.candidates,C,ne]);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(Ue,{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:[g&&!y&&e.jsxs("button",{onClick:g,disabled:h,className:`flex items-center gap-1.5 px-3.5 py-2 rounded-lg text-xs font-bold transition-all ${h?"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:[h?e.jsx(Ee,{size:14,className:"animate-spin"}):e.jsx(Ot,{size:14}),h?"初始化中...":"冷启动"]}),Ae&&Ae.total>0&&e.jsxs("button",{onClick:v,disabled:K||$,className:`flex items-center gap-1.5 px-3 py-2 rounded-lg text-xs font-bold transition-all ${K||$?"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:[K?e.jsx(Ee,{size:14,className:"animate-spin"}):e.jsx(cs,{size:14}),K?"补齐中...":"① 结构补齐"]}),Ae&&Ae.total>0&&e.jsxs("button",{onClick:ve,disabled:$||K||O,className:`flex items-center gap-1.5 px-3 py-2 rounded-lg text-xs font-bold transition-all ${$||K||O?"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:[$||O?e.jsx(Ee,{size:14,className:"animate-spin"}):e.jsx(Ue,{size:14}),$||O?"润色中...":"② 内容润色"]}),Ae&&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(ga,{size:14,className:"text-slate-400"}),e.jsxs("span",{className:"text-slate-500",children:["共 ",e.jsx("strong",{className:"text-slate-700",children:Ae.total})," 条"]}),Ae.withCode<Ae.total&&e.jsxs("span",{className:"text-slate-400 ml-1",children:["(含代码 ",Ae.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(Ae.avgConfidence*100),"%"]})]})]})]})]}),p&&e.jsx($r,{refine:p,isRefineDone:k,onDismiss:()=>{b(),x==null||x()}}),_.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:Ie.map(d=>{var te;s(d);const L=a(d),N=Xs[d],pe=t.candidates[d],W=((te=pe==null?void 0:pe.items)==null?void 0:te.length)??0,oe=fe===d,F=lt[d]||lt.All;return e.jsxs("button",{onClick:()=>q(d),className:`flex items-center gap-2 px-3 py-2 rounded-lg text-sm font-bold whitespace-nowrap transition-all border
75
- ${oe?`${(F==null?void 0:F.bg)||"bg-blue-50"} ${(F==null?void 0:F.color)||"text-blue-700"} ${(F==null?void 0:F.border)||"border-blue-200"} shadow-sm ring-1 ring-inset ${(F==null?void 0:F.border)||"ring-blue-200"}`:"bg-slate-50/80 text-slate-600 border-slate-100 hover:border-slate-200 hover:bg-slate-100"}`,children:[(()=>{const ge=(F==null?void 0:F.icon)||us;return e.jsx(ge,{size:E.sm,className:oe?"":"text-slate-400"})})(),e.jsx("span",{children:Os[d]||d}),L&&N&&e.jsx("span",{className:"text-[9px] text-amber-600 border border-amber-200 px-1 rounded",children:N}),e.jsx("span",{className:`text-[10px] font-normal rounded-full px-1.5 ${oe?"bg-white/60":"bg-slate-200/60 text-slate-400"}`,children:W})]},d)})})}),e.jsxs("div",{className:"flex-1 overflow-y-auto pr-1",children:[(!(t!=null&&t.candidates)||Object.keys(t.candidates).length===0)&&!y&&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(fa,{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 命令手动创建"}),g&&e.jsxs("button",{onClick:g,disabled:h,className:`mt-4 flex items-center gap-2 px-5 py-2.5 rounded-xl text-sm font-bold transition-all ${h?"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:[h?e.jsx(Ee,{size:16,className:"animate-spin"}):e.jsx(Ot,{size:16}),h?"正在初始化...":"冷启动:初始化知识库"]}),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)&&y&&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(Ee,{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&&fe&&xe.filter(([d])=>d===fe).map(([d,L])=>{const N=s(d),pe=a(d),W=Xs[d]||"静默",oe=f[d]||{page:1,pageSize:12},F=oe.page,te=oe.pageSize,ge=L.items.filter(U=>{var $e;if(V.onlySimilar){const We=($e=U.relations)==null?void 0:$e.related;if(!Array.isArray(We)||We.length===0)return!1}return!0}).sort((U,$e)=>{var We,Be,Xe,je,Pe,He;if(V.sort==="default")return 0;if(V.sort==="score-desc")return(((We=$e.quality)==null?void 0:We.overall)??0)-(((Be=U.quality)==null?void 0:Be.overall)??0);if(V.sort==="score-asc")return(((Xe=U.quality)==null?void 0:Xe.overall)??0)-(((je=$e.quality)==null?void 0:je.overall)??0);if(V.sort==="confidence-desc")return(((Pe=$e.reasoning)==null?void 0:Pe.confidence)??0)-(((He=U.reasoning)==null?void 0:He.confidence)??0);if(V.sort==="date-desc"){const Le=typeof U.createdAt=="number"?U.createdAt:0;return(typeof $e.createdAt=="number"?$e.createdAt:0)-Le}return 0}),G=ge.length,be=Math.ceil(G/te),Re=(F-1)*te,Te=ge.slice(Re,Re+te),Me=U=>{w($e=>({...$e,[d]:{...oe,page:U}}))},qe=U=>{w($e=>({...$e,[d]:{page:1,pageSize:U}}))},Ge=lt[d]||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 U=(Ge==null?void 0:Ge.icon)||us;return e.jsx(U,{size:18,className:(Ge==null?void 0:Ge.color)||"text-blue-600"})})(),e.jsx("span",{className:"text-base font-bold text-slate-800 truncate",children:Os[d]||d}),pe&&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:W}),N&&!pe&&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}),"扫描于 ",Rt(L.scanTime)||new Date(L.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(ba,{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:V.sort,onChange:U=>Q($e=>({...$e,sort:U.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:V.onlySimilar,onChange:U=>Q($e=>({...$e,onlySimilar:U.target.checked})),className:"rounded text-blue-600 w-3 h-3"}),"只看相似"]}),(V.sort!=="default"||V.onlySimilar)&&e.jsx("button",{onClick:()=>Q({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:[G," 条"]}),e.jsx("button",{onClick:()=>o(Te,d),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(`确定移除当前页的 ${Te.length} 条候选?`))return;const $e=(await Promise.allSettled(Te.map(We=>r(d,We.id)))).filter(We=>We.status==="rejected").length;$e>0&&le(`${$e} 条候选移除时出错`,{title:"部分删除失败",type:"error"}),x==null||x()},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:()=>i(d),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:Te.map(U=>{var z,me,ie,Y,ke;const $e=m===U.id,We=((z=U.reasoning)==null?void 0:z.confidence)??null,Be=(((me=U.quality)==null?void 0:me.overall)??0)>0?U.quality.overall:null,je=(((ie=U.relations)==null?void 0:ie.related)||[])[0],Pe=ue[U.id]||[],He=Zs[U.source||""]||{label:U.source||"",color:"text-slate-500 bg-slate-50 border-slate-200"},Le=lt[U.category||""]||lt.All||{},ot=((Le==null?void 0:Le.color)||"text-blue-600").replace("text-","border-l-");return e.jsxs("div",{onClick:()=>u($e?null:U.id),className:`bg-white rounded-xl border overflow-hidden hover:shadow-lg transition-all duration-200 flex flex-col group cursor-pointer
74
+ `)||"";else try{oe=(await re.getRecipeContentByName(G)).content}catch(Me){const _e=(W=Me.response)==null?void 0:W.status,qe=((Re=(be=Me.response)==null?void 0:be.data)==null?void 0:Re.message)||Me.message;_e===404?le(`"${G}" 不存在于当前知识库`,{title:"Recipe 不存在",type:"error"}):le(qe,{title:"加载 Recipe 失败",type:"error"});return}const te={[G]:oe};u(d.id),ye({candidate:d,targetName:L,recipeName:G,recipeContent:oe,similarList:pe.slice(0,3),recipeContents:te})},[t==null?void 0:t.recipes]),E=t!=null&&t.candidates?Object.entries(t.candidates):[],xe=zr(E,s,a,l),Ie=xe.map(([d])=>d),fe=Z&&Ie.includes(Z)?Z:Ie[0]??null;n.useEffect(()=>{Ie.length>0&&(!Z||!Ie.includes(Z))&&q(Ie[0])},[Ie.join(","),Z]),n.useEffect(()=>{m&&fe&&De(fe,m)},[m,fe,De]);const Ae=n.useMemo(()=>{var oe;if(!fe||!((oe=t==null?void 0:t.candidates)!=null&&oe[fe]))return null;const d=t.candidates[fe].items,L=d.length,N=d.reduce((F,te)=>{var ge;return F+(((ge=te.reasoning)==null?void 0:ge.confidence)??0)},0)/(L||1),pe=d.filter(F=>{var te;return((te=F.content)==null?void 0:te.pattern)&&F.content.pattern.trim().length>0}).length,G=new Map;return d.forEach(F=>{const te=F.source||"unknown";G.set(te,(G.get(te)||0)+1)}),{total:L,avgConfidence:N,withCode:pe,sources:G}},[fe,t==null?void 0:t.candidates]),Oe=n.useMemo(()=>{const d=new Map;if(t!=null&&t.idTitleMap)for(const[L,N]of Object.entries(t.idTitleMap))d.set(L,N);if(t!=null&&t.candidates)for(const L of Object.values(t.candidates))for(const N of L.items)N.id&&N.title&&d.set(N.id,N.title);if(t!=null&&t.recipes)for(const L of t.recipes)L.id&&L.name&&d.set(L.id,L.name.replace(/\.md$/i,""));return d},[t==null?void 0:t.idTitleMap,t==null?void 0:t.candidates,t==null?void 0:t.recipes]),Ee=n.useCallback(async d=>{var L,N,pe,G,oe;if(!I.has(d)){P(F=>new Set(F).add(d));try{const F=await re.enrichCandidates([d]);F.enriched>0?le(`已补齐 ${((pe=(N=(L=F.results)==null?void 0:L[0])==null?void 0:N.filledFields)==null?void 0:pe.length)||0} 个结构字段`,{title:"AI 补齐完成"}):le("无缺失字段,均已完整",{title:"无需补齐",type:"info"});try{const te=await re.getCandidate(d);se(ge=>({...ge,[d]:te}))}catch{}}catch(F){const te=(oe=(G=F.response)==null?void 0:G.data)==null?void 0:oe.error;le(typeof te=="string"?te:(te==null?void 0:te.message)||F.message,{title:"AI 补齐失败",type:"error"})}finally{P(F=>{const te=new Set(F);return te.delete(d),te})}}},[I,x]),v=n.useCallback(async()=>{var L,N,pe;if(K||!fe||!((L=t==null?void 0:t.candidates)!=null&&L[fe]))return;const d=t.candidates[fe].items;if(d.length!==0){X(!0);try{let G=0;for(let oe=0;oe<d.length;oe+=20){const F=d.slice(oe,oe+20).map(ge=>ge.id),te=await re.enrichCandidates(F);G+=te.enriched}le(`${G}/${d.length} 条候选已更新`,{title:"① 结构补齐完成"}),x==null||x()}catch(G){const oe=(pe=(N=G.response)==null?void 0:N.data)==null?void 0:pe.error;le(typeof oe=="string"?oe:(oe==null?void 0:oe.message)||G.message,{title:"① 结构补齐失败",type:"error"})}finally{X(!1)}}},[K,fe,t==null?void 0:t.candidates,x]),ne=n.useCallback(async d=>{try{const L=await re.getCandidate(d);se(N=>({...N,[d]:L}))}catch{}},[]),ve=n.useCallback(()=>{var N;if(!fe||!((N=t==null?void 0:t.candidates)!=null&&N[fe]))return;const d=t.candidates[fe].items,L=d.map(pe=>pe.id);C.openRefine({candidateIds:L,candidates:d,onCandidateUpdated:ne})},[fe,t==null?void 0:t.candidates,C,ne]),ce=n.useCallback(d=>{var N;if(!fe||!((N=t==null?void 0:t.candidates)!=null&&N[fe]))return;ye(null),u(d);const L=t.candidates[fe].items;C.openRefine({candidateIds:[d],candidates:L,onCandidateUpdated:ne})},[fe,t==null?void 0:t.candidates,C,ne]);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(Ue,{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:[g&&!y&&e.jsxs("button",{onClick:g,disabled:h,className:`flex items-center gap-1.5 px-3.5 py-2 rounded-lg text-xs font-bold transition-all ${h?"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:[h?e.jsx(Te,{size:14,className:"animate-spin"}):e.jsx(Ot,{size:14}),h?"初始化中...":"冷启动"]}),Ae&&Ae.total>0&&e.jsxs("button",{onClick:v,disabled:K||$,className:`flex items-center gap-1.5 px-3 py-2 rounded-lg text-xs font-bold transition-all ${K||$?"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:[K?e.jsx(Te,{size:14,className:"animate-spin"}):e.jsx(cs,{size:14}),K?"补齐中...":"① 结构补齐"]}),Ae&&Ae.total>0&&e.jsxs("button",{onClick:ve,disabled:$||K||O,className:`flex items-center gap-1.5 px-3 py-2 rounded-lg text-xs font-bold transition-all ${$||K||O?"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:[$||O?e.jsx(Te,{size:14,className:"animate-spin"}):e.jsx(Ue,{size:14}),$||O?"润色中...":"② 内容润色"]}),Ae&&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(ga,{size:14,className:"text-slate-400"}),e.jsxs("span",{className:"text-slate-500",children:["共 ",e.jsx("strong",{className:"text-slate-700",children:Ae.total})," 条"]}),Ae.withCode<Ae.total&&e.jsxs("span",{className:"text-slate-400 ml-1",children:["(含代码 ",Ae.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(Ae.avgConfidence*100),"%"]})]})]})]})]}),p&&e.jsx($r,{refine:p,isRefineDone:k,onDismiss:()=>{b(),x==null||x()}}),E.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:Ie.map(d=>{var te;s(d);const L=a(d),N=Xs[d],pe=t.candidates[d],G=((te=pe==null?void 0:pe.items)==null?void 0:te.length)??0,oe=fe===d,F=lt[d]||lt.All;return e.jsxs("button",{onClick:()=>q(d),className:`flex items-center gap-2 px-3 py-2 rounded-lg text-sm font-bold whitespace-nowrap transition-all border
75
+ ${oe?`${(F==null?void 0:F.bg)||"bg-blue-50"} ${(F==null?void 0:F.color)||"text-blue-700"} ${(F==null?void 0:F.border)||"border-blue-200"} shadow-sm ring-1 ring-inset ${(F==null?void 0:F.border)||"ring-blue-200"}`:"bg-slate-50/80 text-slate-600 border-slate-100 hover:border-slate-200 hover:bg-slate-100"}`,children:[(()=>{const ge=(F==null?void 0:F.icon)||us;return e.jsx(ge,{size:T.sm,className:oe?"":"text-slate-400"})})(),e.jsx("span",{children:Os[d]||d}),L&&N&&e.jsx("span",{className:"text-[9px] text-amber-600 border border-amber-200 px-1 rounded",children:N}),e.jsx("span",{className:`text-[10px] font-normal rounded-full px-1.5 ${oe?"bg-white/60":"bg-slate-200/60 text-slate-400"}`,children:G})]},d)})})}),e.jsxs("div",{className:"flex-1 overflow-y-auto pr-1",children:[(!(t!=null&&t.candidates)||Object.keys(t.candidates).length===0)&&!y&&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(fa,{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 命令手动创建"}),g&&e.jsxs("button",{onClick:g,disabled:h,className:`mt-4 flex items-center gap-2 px-5 py-2.5 rounded-xl text-sm font-bold transition-all ${h?"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:[h?e.jsx(Te,{size:16,className:"animate-spin"}):e.jsx(Ot,{size:16}),h?"正在初始化...":"冷启动:初始化知识库"]}),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)&&y&&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&&fe&&xe.filter(([d])=>d===fe).map(([d,L])=>{const N=s(d),pe=a(d),G=Xs[d]||"静默",oe=f[d]||{page:1,pageSize:12},F=oe.page,te=oe.pageSize,ge=L.items.filter(U=>{var $e;if(V.onlySimilar){const Ge=($e=U.relations)==null?void 0:$e.related;if(!Array.isArray(Ge)||Ge.length===0)return!1}return!0}).sort((U,$e)=>{var Ge,Be,Xe,je,Pe,He;if(V.sort==="default")return 0;if(V.sort==="score-desc")return(((Ge=$e.quality)==null?void 0:Ge.overall)??0)-(((Be=U.quality)==null?void 0:Be.overall)??0);if(V.sort==="score-asc")return(((Xe=U.quality)==null?void 0:Xe.overall)??0)-(((je=$e.quality)==null?void 0:je.overall)??0);if(V.sort==="confidence-desc")return(((Pe=$e.reasoning)==null?void 0:Pe.confidence)??0)-(((He=U.reasoning)==null?void 0:He.confidence)??0);if(V.sort==="date-desc"){const Le=typeof U.createdAt=="number"?U.createdAt:0;return(typeof $e.createdAt=="number"?$e.createdAt:0)-Le}return 0}),W=ge.length,be=Math.ceil(W/te),Re=(F-1)*te,Me=ge.slice(Re,Re+te),_e=U=>{w($e=>({...$e,[d]:{...oe,page:U}}))},qe=U=>{w($e=>({...$e,[d]:{page:1,pageSize:U}}))},We=lt[d]||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 U=(We==null?void 0:We.icon)||us;return e.jsx(U,{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:Os[d]||d}),pe&&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:G}),N&&!pe&&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}),"扫描于 ",Rt(L.scanTime)||new Date(L.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(ba,{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:V.sort,onChange:U=>Q($e=>({...$e,sort:U.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:V.onlySimilar,onChange:U=>Q($e=>({...$e,onlySimilar:U.target.checked})),className:"rounded text-blue-600 w-3 h-3"}),"只看相似"]}),(V.sort!=="default"||V.onlySimilar)&&e.jsx("button",{onClick:()=>Q({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:()=>o(Me,d),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(`确定移除当前页的 ${Me.length} 条候选?`))return;const $e=(await Promise.allSettled(Me.map(Ge=>r(d,Ge.id)))).filter(Ge=>Ge.status==="rejected").length;$e>0&&le(`${$e} 条候选移除时出错`,{title:"部分删除失败",type:"error"}),x==null||x()},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:()=>i(d),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:Me.map(U=>{var z,me,ie,Y,ke;const $e=m===U.id,Ge=((z=U.reasoning)==null?void 0:z.confidence)??null,Be=(((me=U.quality)==null?void 0:me.overall)??0)>0?U.quality.overall:null,je=(((ie=U.relations)==null?void 0:ie.related)||[])[0],Pe=ue[U.id]||[],He=Zs[U.source||""]||{label:U.source||"",color:"text-slate-500 bg-slate-50 border-slate-200"},Le=lt[U.category||""]||lt.All||{},ot=((Le==null?void 0:Le.color)||"text-blue-600").replace("text-","border-l-");return e.jsxs("div",{onClick:()=>u($e?null:U.id),className:`bg-white rounded-xl border overflow-hidden hover:shadow-lg transition-all duration-200 flex flex-col group cursor-pointer
76
76
  ${N?"opacity-75":""}
77
77
  ${$e?"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] ${ot} 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 ${(Le==null?void 0:Le.bg)||"bg-slate-50"} ${(Le==null?void 0:Le.color)||"text-slate-400"} ${(Le==null?void 0:Le.border)||"border-slate-100"}`,children:[(()=>{const Ne=(Le==null?void 0:Le.icon)||Qe;return e.jsx(Ne,{size:10})})(),U.category||"general"]}),U.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:U.knowledgeType}),U.source&&U.source!=="unknown"&&e.jsx("span",{className:`text-[10px] font-medium px-1.5 py-0.5 rounded border ${He.color}`,children:He.label}),U.complexity&&e.jsx("span",{className:`text-[10px] font-medium px-1.5 py-0.5 rounded border
78
- ${U.complexity==="advanced"?"bg-red-50 text-red-600 border-red-100":U.complexity==="intermediate"?"bg-amber-50 text-amber-600 border-amber-100":"bg-emerald-50 text-emerald-600 border-emerald-100"}`,children:U.complexity==="advanced"?"高级":U.complexity==="intermediate"?"中级":"初级"})]}),e.jsx("h3",{className:"font-bold text-sm text-slate-800 leading-snug mb-1 line-clamp-1",children:U.title}),e.jsx("p",{className:"text-xs text-slate-500 line-clamp-2 leading-relaxed",children:U.description||""})]}),e.jsxs("div",{className:"flex flex-col items-center gap-1 shrink-0",children:[e.jsx(Er,{value:We}),e.jsx("span",{className:"text-[9px] text-slate-400 font-medium",children:"置信度"})]})]})}),((Y=U.reasoning)==null?void 0:Y.whyStandard)&&!/^Submitted via /i.test(U.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(Jt,{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:U.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:Ne=>{Ne.stopPropagation();const we=String(je.target||"").trim();we&&D(U,d,we,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,"")]})]}),((ke=U.content)==null?void 0:ke.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(At,{size:11,className:"text-slate-500"}),e.jsx("span",{className:"text-[10px] text-slate-400 font-mono uppercase tracking-wide",children:U.language||"code"})]}),e.jsxs("span",{className:"text-[10px] text-slate-500 font-mono tabular-nums",children:[U.content.pattern.split(`
78
+ ${U.complexity==="advanced"?"bg-red-50 text-red-600 border-red-100":U.complexity==="intermediate"?"bg-amber-50 text-amber-600 border-amber-100":"bg-emerald-50 text-emerald-600 border-emerald-100"}`,children:U.complexity==="advanced"?"高级":U.complexity==="intermediate"?"中级":"初级"})]}),e.jsx("h3",{className:"font-bold text-sm text-slate-800 leading-snug mb-1 line-clamp-1",children:U.title}),e.jsx("p",{className:"text-xs text-slate-500 line-clamp-2 leading-relaxed",children:U.description||""})]}),e.jsxs("div",{className:"flex flex-col items-center gap-1 shrink-0",children:[e.jsx(Tr,{value:Ge}),e.jsx("span",{className:"text-[9px] text-slate-400 font-medium",children:"置信度"})]})]})}),((Y=U.reasoning)==null?void 0:Y.whyStandard)&&!/^Submitted via /i.test(U.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(Jt,{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:U.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:Ne=>{Ne.stopPropagation();const we=String(je.target||"").trim();we&&D(U,d,we,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,"")]})]}),((ke=U.content)==null?void 0:ke.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(At,{size:11,className:"text-slate-500"}),e.jsx("span",{className:"text-[10px] text-slate-400 font-mono uppercase tracking-wide",children:U.language||"code"})]}),e.jsxs("span",{className:"text-[10px] text-slate-500 font-mono tabular-nums",children:[U.content.pattern.split(`
79
79
  `).length," 行"]})]}),e.jsxs("div",{className:"relative max-h-[80px] overflow-hidden",children:[e.jsx(rt,{code:Ar(U.content.pattern,3),language:U.language==="objc"?"objectivec":U.language,className:"!rounded-none"}),U.content.pattern.split(`
80
- `).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:Ne=>Ne.stopPropagation(),children:[e.jsxs("div",{className:"flex items-center gap-2 flex-wrap min-w-0",children:[U.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:U.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:U.language}),U.tags&&U.tags.length>0&&U.tags.slice(0,3).map((Ne,we)=>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 Ne=="string"?Ne:String(Ne)},we)),U.tags&&U.tags.length>3&&e.jsxs("span",{className:"text-[9px] text-slate-400",children:["+",U.tags.length-3]}),U.createdAt&&Rt(U.createdAt)&&e.jsxs("span",{className:"text-[9px] text-slate-400 flex items-center gap-0.5",children:[e.jsx(it,{size:9}),Rt(U.createdAt)]})]}),e.jsxs("div",{className:"flex items-center gap-1.5 shrink-0",children:[e.jsx("button",{onClick:()=>_e(U.id),disabled:I.has(U.id),title:"① 结构补齐:填充缺失的语义字段(rationale / knowledgeType / complexity 等)",className:`p-1.5 rounded-lg transition-colors flex items-center gap-1 text-[11px] font-medium ${I.has(U.id)?"text-slate-300 cursor-not-allowed":"text-amber-500 hover:text-amber-600 hover:bg-amber-50"}`,children:I.has(U.id)?e.jsx(Ee,{size:14,className:"animate-spin"}):e.jsx(cs,{size:14})}),e.jsx("button",{onClick:()=>ce(U.id),disabled:B.has(U.id),title:"② 内容润色:改善描述、补充洞察、推断关联(支持自定义提示词)",className:`p-1.5 rounded-lg transition-colors flex items-center gap-1 text-[11px] font-medium ${B.has(U.id)?"text-slate-300 cursor-not-allowed":"text-emerald-500 hover:text-emerald-600 hover:bg-emerald-50"}`,children:B.has(U.id)?e.jsx(Ee,{size:14,className:"animate-spin"}):e.jsx(Ue,{size:14})}),e.jsx("button",{onClick:()=>{r(d,U.id),m===U.id&&(u(null),ye(null))},title:"忽略",className:"p-1.5 hover:bg-red-50 text-slate-400 hover:text-red-500 rounded-lg transition-colors",children:e.jsx(tt,{size:14})}),e.jsxs("button",{onClick:()=>c(U,d),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(bt,{size:12})," 审核并保存"]}),U.lifecycle==="pending"&&e.jsxs("button",{onClick:async()=>{try{await re.promoteCandidateToRecipe(U.id),le("已成功发布为正式 Recipe",{title:"发布成功"}),x==null||x()}catch(Ne){le(Ne.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(Ot,{size:12})," 发布"]})]})]})]},U.id)})}),G>12&&e.jsx(Ms,{currentPage:F,totalPages:be,totalItems:G,pageSize:te,onPageChange:Me,onPageSizeChange:qe})]},d)})]}),m&&fe&&((he=t==null?void 0:t.candidates)==null?void 0:he[fe])&&(()=>{var Ge,U,$e,We,Be,Xe;const d=t.candidates[fe].items,L=d.find(je=>je.id===m);if(!L)return null;const N=J[m]||L,pe=d.findIndex(je=>je.id===m),W=pe>0,oe=pe<d.length-1,F=()=>{W&&(u(d[pe-1].id),ye(null))},te=()=>{oe&&(u(d[pe+1].id),ye(null))},ge=N.reasoning,G=(ge==null?void 0:ge.whyStandard)&&!/^Submitted via /i.test(ge.whyStandard),be=ge&&(G||ge.sources&&ge.sources.length>0||ge.confidence!=null),Re=ue[N.id]||[],Te=T===N.id,Me=lt[N.category||""]||lt.All||{},qe=Zs[N.source||""]||{label:N.source||"",color:"text-slate-500 bg-slate-50 border-slate-200"};return e.jsxs(Ve,{className:"z-30 flex justify-end",onClick:()=>{u(null),ye(null)},children:[e.jsx(Ve.Backdrop,{className:"bg-black/15 backdrop-blur-[1px]"}),ae&&(()=>{const je=ae.candidate,Pe=je.language==="objc"||je.language==="objective-c"?"objectivec":je.language||"text",He=()=>{var ke,Ne;const Y=[];(ke=je.content)!=null&&ke.pattern&&Y.push("## Snippet / Code Reference\n\n```"+Pe+`
80
+ `).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:Ne=>Ne.stopPropagation(),children:[e.jsxs("div",{className:"flex items-center gap-2 flex-wrap min-w-0",children:[U.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:U.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:U.language}),U.tags&&U.tags.length>0&&U.tags.slice(0,3).map((Ne,we)=>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 Ne=="string"?Ne:String(Ne)},we)),U.tags&&U.tags.length>3&&e.jsxs("span",{className:"text-[9px] text-slate-400",children:["+",U.tags.length-3]}),U.createdAt&&Rt(U.createdAt)&&e.jsxs("span",{className:"text-[9px] text-slate-400 flex items-center gap-0.5",children:[e.jsx(it,{size:9}),Rt(U.createdAt)]})]}),e.jsxs("div",{className:"flex items-center gap-1.5 shrink-0",children:[e.jsx("button",{onClick:()=>Ee(U.id),disabled:I.has(U.id),title:"① 结构补齐:填充缺失的语义字段(rationale / knowledgeType / complexity 等)",className:`p-1.5 rounded-lg transition-colors flex items-center gap-1 text-[11px] font-medium ${I.has(U.id)?"text-slate-300 cursor-not-allowed":"text-amber-500 hover:text-amber-600 hover:bg-amber-50"}`,children:I.has(U.id)?e.jsx(Te,{size:14,className:"animate-spin"}):e.jsx(cs,{size:14})}),e.jsx("button",{onClick:()=>ce(U.id),disabled:B.has(U.id),title:"② 内容润色:改善描述、补充洞察、推断关联(支持自定义提示词)",className:`p-1.5 rounded-lg transition-colors flex items-center gap-1 text-[11px] font-medium ${B.has(U.id)?"text-slate-300 cursor-not-allowed":"text-emerald-500 hover:text-emerald-600 hover:bg-emerald-50"}`,children:B.has(U.id)?e.jsx(Te,{size:14,className:"animate-spin"}):e.jsx(Ue,{size:14})}),e.jsx("button",{onClick:()=>{r(d,U.id),m===U.id&&(u(null),ye(null))},title:"忽略",className:"p-1.5 hover:bg-red-50 text-slate-400 hover:text-red-500 rounded-lg transition-colors",children:e.jsx(tt,{size:14})}),e.jsxs("button",{onClick:()=>c(U,d),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(bt,{size:12})," 审核并保存"]}),U.lifecycle==="pending"&&e.jsxs("button",{onClick:async()=>{try{await re.promoteCandidateToRecipe(U.id),le("已成功发布为正式 Recipe",{title:"发布成功"}),x==null||x()}catch(Ne){le(Ne.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(Ot,{size:12})," 发布"]})]})]})]},U.id)})}),W>12&&e.jsx(_s,{currentPage:F,totalPages:be,totalItems:W,pageSize:te,onPageChange:_e,onPageSizeChange:qe})]},d)})]}),m&&fe&&((he=t==null?void 0:t.candidates)==null?void 0:he[fe])&&(()=>{var We,U,$e,Ge,Be,Xe;const d=t.candidates[fe].items,L=d.find(je=>je.id===m);if(!L)return null;const N=J[m]||L,pe=d.findIndex(je=>je.id===m),G=pe>0,oe=pe<d.length-1,F=()=>{G&&(u(d[pe-1].id),ye(null))},te=()=>{oe&&(u(d[pe+1].id),ye(null))},ge=N.reasoning,W=(ge==null?void 0:ge.whyStandard)&&!/^Submitted via /i.test(ge.whyStandard),be=ge&&(W||ge.sources&&ge.sources.length>0||ge.confidence!=null),Re=ue[N.id]||[],Me=M===N.id,_e=lt[N.category||""]||lt.All||{},qe=Zs[N.source||""]||{label:N.source||"",color:"text-slate-500 bg-slate-50 border-slate-200"};return e.jsxs(Ve,{className:"z-30 flex justify-end",onClick:()=>{u(null),ye(null)},children:[e.jsx(Ve.Backdrop,{className:"bg-black/15 backdrop-blur-[1px]"}),ae&&(()=>{const je=ae.candidate,Pe=je.language==="objc"||je.language==="objective-c"?"objectivec":je.language||"text",He=()=>{var ke,Ne;const Y=[];(ke=je.content)!=null&&ke.pattern&&Y.push("## Snippet / Code Reference\n\n```"+Pe+`
81
81
  `+je.content.pattern+"\n```"),(Ne=je.content)!=null&&Ne.markdown?Y.push(`
82
82
  ## 项目特写
83
83
 
@@ -85,39 +85,39 @@ Skill 文档格式要求:
85
85
  ## AI Context / Usage Guide
86
86
 
87
87
  `+je.doClause),navigator.clipboard.writeText(Y.join(`
88
- `)||"").then(()=>le("候选内容已复制到剪贴板",{title:"已复制"}))},Le=()=>{const Y=Es(ae.recipeContent);navigator.clipboard.writeText(Y).then(()=>le("Recipe 内容已复制到剪贴板",{title:"已复制"}))},ot=async Y=>{var Ne;if(Y===ae.recipeName)return;const ke=ae.recipeContents[Y];if(ke)ye(we=>we?{...we,recipeName:Y,recipeContent:ke}:null);else{let we="";const ze=(Ne=t==null?void 0:t.recipes)==null?void 0:Ne.find(Ce=>Ce.name===Y||Ce.name.endsWith("/"+Y));if(ze!=null&&ze.content)we=[ze.content.pattern,ze.content.markdown].filter(Boolean).join(`
88
+ `)||"").then(()=>le("候选内容已复制到剪贴板",{title:"已复制"}))},Le=()=>{const Y=Ts(ae.recipeContent);navigator.clipboard.writeText(Y).then(()=>le("Recipe 内容已复制到剪贴板",{title:"已复制"}))},ot=async Y=>{var Ne;if(Y===ae.recipeName)return;const ke=ae.recipeContents[Y];if(ke)ye(we=>we?{...we,recipeName:Y,recipeContent:ke}:null);else{let we="";const ze=(Ne=t==null?void 0:t.recipes)==null?void 0:Ne.find(Ce=>Ce.name===Y||Ce.name.endsWith("/"+Y));if(ze!=null&&ze.content)we=[ze.content.pattern,ze.content.markdown].filter(Boolean).join(`
89
89
 
90
- `)||"";else try{we=(await re.getRecipeContentByName(Y)).content}catch{return}ye(Ce=>Ce?{...Ce,recipeName:Y,recipeContent:we,recipeContents:{...Ce.recipeContents,[Y]:we}}:null)}},z=async()=>{if(window.confirm("确定删除该候选?"))try{await r(ae.targetName,je.id),ye(null)}catch(Y){le((Y==null?void 0:Y.message)||"删除失败",{title:"删除失败",type:"error"})}},me=()=>{c(je,ae.targetName),ye(null)},ie=()=>{var ke;const Y=(ke=t==null?void 0:t.recipes)==null?void 0:ke.find(Ne=>Ne.name===ae.recipeName||Ne.name.endsWith("/"+ae.recipeName));Y?j==null||j(Y):j==null||j({name:ae.recipeName,content:{markdown:ae.recipeContent}}),ye(null)};return e.jsxs("div",{className:`relative h-full bg-white shadow-2xl flex flex-col border-l border-slate-200 ${A?"w-[800px] max-w-[55vw]":"w-[600px] max-w-[45vw]"}`,style:{animation:"slideInRight 0.2s ease-out"},onClick:Y=>Y.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:ae.recipeName.replace(/\.md$/i,"")})]})]}),e.jsxs("div",{className:"flex items-center gap-1.5 shrink-0 ml-2",children:[e.jsx("button",{onClick:()=>Le(),className:"p-1.5 hover:bg-emerald-100 rounded-lg text-emerald-600 transition-colors",title:"复制",children:e.jsx(_t,{size:14})}),e.jsx("button",{onClick:ie,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:()=>ye(null),className:"p-1.5 hover:bg-slate-200 rounded-lg transition-colors text-slate-400",children:e.jsx(Ke,{size:16})})]})]}),ae.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:ae.similarList.map(Y=>e.jsxs("button",{onClick:()=>ot(Y.recipeName),className:`text-[10px] font-bold px-2 py-1 rounded transition-colors ${ae.recipeName===Y.recipeName?"bg-emerald-200 text-emerald-800":"bg-white text-emerald-600 hover:bg-emerald-50 border border-emerald-100"}`,children:[Y.recipeName.replace(/\.md$/i,"")," ",(Y.similarity*100).toFixed(0),"%"]},Y.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:z,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(tt,{size:12})," 删除候选"]}),e.jsxs("button",{onClick:me,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(bt,{size:12})," 审核候选"]}),e.jsxs("button",{onClick:()=>He(),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(_t,{size:12})," 复制候选"]})]}),e.jsx("div",{className:"flex-1 overflow-auto p-5 min-h-0",children:e.jsx(mt,{content:ae.recipeContent,stripFrontmatter:!0})})]})})(),e.jsxs("div",{className:`relative h-full bg-white shadow-2xl flex flex-col border-l border-slate-200 ${A?"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:N.title})}),e.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[e.jsx("button",{onClick:F,disabled:!W,className:"p-1.5 hover:bg-slate-100 rounded-lg transition-colors disabled:opacity-30",title:"上一条",children:e.jsx(Zt,{size:E.md})}),e.jsxs("span",{className:"text-xs text-slate-400 tabular-nums",children:[pe+1,"/",d.length]}),e.jsx("button",{onClick:te,disabled:!oe,className:"p-1.5 hover:bg-slate-100 rounded-lg transition-colors disabled:opacity-30",title:"下一条",children:e.jsx(st,{size:E.md})}),e.jsx("div",{className:"w-px h-5 bg-slate-200 mx-1"}),e.jsx("button",{onClick:S,className:"p-1.5 hover:bg-slate-100 rounded-lg transition-colors text-slate-400",title:A?"收窄":"展宽",children:A?e.jsx(Is,{size:E.md}):e.jsx(hs,{size:E.md})}),e.jsx("button",{onClick:()=>{r(fe,N.id),u(null),ye(null)},className:"p-1.5 hover:bg-red-50 rounded-lg text-red-500 transition-colors",title:"删除",children:e.jsx(tt,{size:E.md})}),e.jsx("button",{onClick:()=>{u(null),ye(null)},className:"p-1.5 hover:bg-slate-100 rounded-lg transition-colors",children:e.jsx(Ke,{size:E.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 ${(Me==null?void 0:Me.bg)||"bg-slate-50"} ${(Me==null?void 0:Me.color)||"text-slate-400"} ${(Me==null?void 0:Me.border)||"border-slate-100"}`,children:N.category||"general"}),N.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:N.knowledgeType}),N.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:N.language}),N.complexity&&e.jsx("span",{className:`text-[10px] font-medium px-1.5 py-0.5 rounded border ${N.complexity==="advanced"?"bg-red-50 text-red-600 border-red-100":N.complexity==="intermediate"?"bg-amber-50 text-amber-600 border-amber-100":"bg-emerald-50 text-emerald-600 border-emerald-100"}`,children:N.complexity==="advanced"?"高级":N.complexity==="intermediate"?"中级":"初级"}),N.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:N.trigger}),N.source&&N.source!=="unknown"&&e.jsx("span",{className:`text-[10px] font-medium px-1.5 py-0.5 rounded border ${qe.color}`,children:qe.label}),N.lifecycle&&N.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:N.lifecycle})]}),e.jsx("div",{className:"flex flex-wrap gap-x-5 gap-y-2 text-xs",children:(()=>{const je=[];return N.scope&&je.push({icon:wt,iconClass:"text-teal-400",label:"范围",value:N.scope==="universal"?"通用":N.scope==="project-specific"?"项目级":N.scope==="module-level"?"模块级":N.scope}),N.source&&N.source!=="unknown"&&je.push({icon:wt,iconClass:"text-violet-400",label:"来源",value:qe.label}),N.createdAt&&Rt(N.createdAt)&&je.push({icon:it,iconClass:"text-slate-400",label:"创建",value:Rt(N.createdAt)}),je.map((Pe,He)=>{const Le=Pe.icon;return e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(Le,{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})]},He)})})()})]}),N.tags&&N.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"}),N.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))]}),N.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:N.description})]}),be&&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(ht,{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((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))]}),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((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))]})]})]}),N.quality&&N.quality.grade&&N.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 ${N.quality.grade==="A"?"text-emerald-600":N.quality.grade==="B"?"text-blue-600":N.quality.grade==="C"?"text-amber-600":N.quality.grade==="D"?"text-orange-600":"text-slate-400"}`,children:N.quality.grade}),e.jsxs("div",{className:"flex-1 grid grid-cols-3 gap-2 text-[10px]",children:[N.quality.completeness!=null&&N.quality.completeness>0&&e.jsxs("div",{className:"text-center",children:[e.jsx("div",{className:"font-bold text-slate-700",children:N.quality.completeness}),e.jsx("div",{className:"text-slate-400",children:"完整性"})]}),N.quality.adaptation!=null&&N.quality.adaptation>0&&e.jsxs("div",{className:"text-center",children:[e.jsx("div",{className:"font-bold text-slate-700",children:N.quality.adaptation}),e.jsx("div",{className:"text-slate-400",children:"适配度"})]}),N.quality.documentation!=null&&N.quality.documentation>0&&e.jsxs("div",{className:"text-center",children:[e.jsx("div",{className:"font-bold text-slate-700",children:N.quality.documentation}),e.jsx("div",{className:"text-slate-400",children:"文档度"})]})]})]})]}),(()=>{const je=N.relations?Object.entries(N.relations).flatMap(([He,Le])=>Array.isArray(Le)?Le.map(ot=>({...ot,type:He})):[]):[];return N.agentNotes||N.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(Ue,{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:[N.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:N.aiInsight})]}),N.agentNotes&&N.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:N.agentNotes.map((He,Le)=>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:"•"}),He]},Le))})]}),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((He,Le)=>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:He.type}),e.jsx("span",{className:"font-medium text-slate-700",children:Oe.get(He.target)||He.target}),He.description&&e.jsxs("span",{className:"text-slate-400",children:["— ",He.description]})]},Le))})]})]})]}):null})(),(Re.length>0||Te)&&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:Te?e.jsx("span",{className:"text-[10px] text-slate-400 animate-pulse",children:"加载中..."}):Re.slice(0,5).map(je=>e.jsxs("button",{onClick:()=>D(N,fe,je.recipeName,Re),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))})]}),((Ge=N.content)==null?void 0:Ge.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(xt,{size:11,className:"text-emerald-500"})," 代码 / 标准用法"]}),e.jsx(rt,{code:N.content.pattern,language:N.language==="objc"?"objectivec":N.language,showLineNumbers:!0})]}),((U=N.content)==null?void 0:U.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(et,{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(mt,{content:N.content.markdown})})})]}),(N.doClause||N.whenClause||N.dontClause||N.topicHint||N.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(Qe,{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:[N.topicHint&&e.jsxs("div",{children:[e.jsx("span",{className:"text-indigo-500 font-medium",children:"Topic:"}),e.jsx("span",{className:"text-slate-700",children:N.topicHint})]}),N.whenClause&&e.jsxs("div",{children:[e.jsx("span",{className:"text-blue-500 font-medium",children:"When:"}),e.jsx("span",{className:"text-slate-700",children:N.whenClause})]}),N.doClause&&e.jsxs("div",{children:[e.jsx("span",{className:"text-emerald-500 font-medium",children:"Do:"}),e.jsx("span",{className:"text-slate-700",children:N.doClause})]}),N.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:N.dontClause})]}),N.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:N.coreCode,language:N.language==="objectivec"||N.language==="objc"?"objectivec":N.language||"swift"})})]})]})]}),(N.scope||N.headers&&N.headers.length>0||(($e=N.content)==null?void 0:$e.steps)&&N.content.steps.length>0||((We=N.content)==null?void 0:We.rationale))&&e.jsxs(e.Fragment,{children:[((Be=N.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:N.content.rationale})})]}),N.headers&&N.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:N.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=N.content)==null?void 0:Xe.steps)&&N.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:N.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 He=typeof je.title=="string"?je.title:"",Le=typeof je.description=="string"?je.description:"",ot=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}),He&&e.jsx("span",{className:"text-xs font-bold text-slate-700",children:He})]}),Le&&e.jsx("p",{className:"text-xs text-slate-600 ml-7 leading-relaxed",children:Le}),ot&&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:ot})]},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:()=>_e(N.id),disabled:I.has(N.id),title:"① 结构补齐",className:`flex items-center gap-1.5 px-3 py-2 rounded-lg text-xs font-medium transition-colors ${I.has(N.id)?"text-slate-300 cursor-not-allowed":"text-amber-600 hover:bg-amber-50 border border-amber-200"}`,children:[I.has(N.id)?e.jsx(Ee,{size:14,className:"animate-spin"}):e.jsx(cs,{size:14}),"补齐"]}),e.jsxs("button",{onClick:()=>ce(N.id),disabled:B.has(N.id),title:"② 内容润色",className:`flex items-center gap-1.5 px-3 py-2 rounded-lg text-xs font-medium transition-colors ${B.has(N.id)?"text-slate-300 cursor-not-allowed":"text-emerald-600 hover:bg-emerald-50 border border-emerald-200"}`,children:[B.has(N.id)?e.jsx(Ee,{size:14,className:"animate-spin"}):e.jsx(Ue,{size:14}),"润色"]}),e.jsxs("button",{onClick:()=>{r(fe,N.id),u(null),ye(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(tt,{size:14})," 删除"]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[N.lifecycle==="pending"&&e.jsxs("button",{onClick:async()=>{try{await re.promoteCandidateToRecipe(N.id),le("已成功发布为正式 Recipe",{title:"发布成功"}),x==null||x()}catch(je){le(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(Ot,{size:14})," 发布"]}),e.jsxs("button",{onClick:()=>{c(N,fe),u(null),ye(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(bt,{size:14})," 审核并保存"]})]})]})]})]})})()]})},Mr=({isOpen:t,onClose:s,currentFile:a,targetName:l,language:r="swift",onSelectRecipe:i})=>{var X,$,H,C;const[c,o]=n.useState(""),[j,g]=n.useState([]),[h,y]=n.useState(null),[x,m]=n.useState(!1),[u,A]=n.useState(null),[S,I]=n.useState(!1),[P,B]=n.useState(null),R=async()=>{if(c.trim()){m(!0);try{const p=await re.search(c,{context:{language:r},limit:10});g((p.items||[]).map(O=>{var k,b,f;return{name:(O.title||O.name||"")+".md",content:((k=O.content)==null?void 0:k.pattern)||((b=O.content)==null?void 0:b.markdown)||((f=O.content)==null?void 0:f.code)||"",similarity:O.score||0,authority:O.authorityScore||0,matchType:O.matchType||"ranked",qualityScore:O.qualityScore||0,usageCount:O.usageCount||0}})),y(null)}catch(p){console.error("Context-aware search failed:",p),alert("搜索失败。请重试。")}finally{m(!1)}}},K=p=>{p.key==="Enter"&&R()};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(Ke,{size:E.lg,className:"text-slate-500"})})]}),h&&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(Je,{size:E.md,className:"text-blue-600 mt-0.5 shrink-0"}),e.jsxs("div",{className:"flex-1",children:[((X=h.targetInfo)==null?void 0:X.targetName)&&e.jsxs("div",{className:"text-blue-900 font-medium flex items-center gap-2 mb-1",children:[e.jsx(vs,{size:E.sm}),"Target: ",h.targetInfo.targetName]}),(($=h.fileInfo)==null?void 0:$.imports)&&h.fileInfo.imports.length>0&&e.jsxs("div",{className:"text-blue-800 text-xs mt-2",children:[e.jsx("strong",{children:"导入的框架:"})," ",h.fileInfo.imports.slice(0,3).join(", "),h.fileInfo.imports.length>3&&` +${h.fileInfo.imports.length-3}`]}),((H=h.targetInfo)==null?void 0:H.suggestedApis)&&h.targetInfo.suggestedApis.length>0&&e.jsxs("div",{className:"text-blue-800 text-xs mt-1",children:[e.jsx("strong",{children:"相关 APIs:"})," ",h.targetInfo.suggestedApis.slice(0,3).join(", ")]})]})]})}),e.jsxs("div",{className:"relative",children:[e.jsx(dt,{className:"absolute left-3 top-1/2 -translate-y-1/2 text-slate-400",size:E.md}),e.jsx("input",{type:"text",placeholder:"输入搜索关键词...",value:c,onChange:p=>o(p.target.value),onKeyDown:K,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:R,disabled:!c.trim()||x,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:[x&&e.jsx(Ee,{size:E.sm,className:"animate-spin"}),x?"搜索中...":"搜索"]})]}),e.jsxs("div",{className:"flex-1 overflow-auto",children:[j.length===0&&!x&&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:E.xxl,className:"mx-auto mb-2 opacity-50"}),e.jsx("p",{className:"text-sm",children:"输入关键词后点击搜索"})]})}),j.map((p,O)=>e.jsxs("div",{className:"border-b border-slate-200 p-4 hover:bg-slate-50 transition-colors cursor-pointer",onClick:()=>{A(u===O?null:O),p.name&&(i==null||i(p.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:p.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(Je,{size:E.xs}),Math.round(p.similarity*100),"%"]}),p.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:E.xs}),"上下文相关"]}),p.matchType&&e.jsx("span",{className:"text-xs text-slate-500",children:p.matchType==="semantic"?"语义匹配":"关键词匹配"})]})]}),e.jsx("button",{onClick:k=>{k.stopPropagation(),A(u===O?null:O)},className:"p-1 hover:bg-slate-200 rounded transition-colors",children:u===O?"▼":"▶"})]}),p.stats&&e.jsxs("div",{className:"text-xs text-slate-500 mb-2 flex gap-3",children:[p.stats.authorityScore!==void 0&&e.jsxs("span",{children:["权威分: ",p.stats.authorityScore]}),p.usageCount!==void 0&&e.jsxs("span",{children:["使用: ",p.usageCount,"次"]})]}),u===O&&e.jsxs("div",{className:"mt-3 pt-3 border-t border-slate-200",children:[p.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:p.recommendReason})]}),e.jsxs("div",{className:"text-xs text-slate-600 max-h-[200px] overflow-auto bg-slate-50 p-3 rounded",children:[p.content.substring(0,500),"..."]}),e.jsx("button",{onClick:k=>{k.stopPropagation(),B(p),I(!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:"查看完整内容"})]})]},O)),x&&e.jsx("div",{className:"flex items-center justify-center h-32",children:e.jsx(Ee,{size:E.lg,className:"animate-spin text-blue-600"})}),j.length===0&&c&&!x&&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:E.xl,className:"mx-auto mb-2 opacity-50"}),e.jsx("p",{className:"text-sm",children:"未找到匹配的结果"})]})})]})]}),S&&P&&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:P.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(P.similarity*100),"%"]}),P.isContextRelevant&&e.jsx("span",{className:"text-xs bg-green-100 text-green-700 px-2 py-1 rounded",children:"✓ 上下文相关"}),P.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:["🤖 质量: ",(P.qualityScore*100).toFixed(0),"%"]}),((C=P.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(P.stats.authorityScore*100)/100]})]})]}),e.jsx("button",{onClick:()=>I(!1),className:"p-1 hover:bg-slate-100 rounded transition-colors shrink-0",children:e.jsx(Ke,{size:E.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:P.content?e.jsx(rt,{code:P.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:()=>I(!1),className:"px-4 py-2 text-slate-700 hover:bg-slate-200 rounded transition-colors text-sm font-medium",children:"关闭"}),i&&e.jsxs("button",{onClick:()=>{i(P.name),I(!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(st,{size:E.md}),"使用此片段"]})]})]})]})]}):null},Qs=t=>{const s=(t.language||"").toLowerCase();return s==="objectivec"||s==="objc"||s==="objective-c"||s==="obj-c"?"objectivec":t.language||"swift"};function Rr(t){const s=[],a=t.match(/#import\s+"([^"]+)"/);if(a){const c=a[1].replace(/\.h$/,"");s.push(c)}const l=t.match(/#import\s+<([^>]+)>/);if(l){const c=l[1].replace(/\.h$/,"").split("/");s.push(...c)}const r=t.match(/^import\s+(\w+)/);r&&s.push(r[1]);const i=t.match(/@import\s+(\w+)/);return i&&s.push(i[1]),[...new Set(s.filter(Boolean))]}function Lt(t,s){if(!s||!s.trim())return"unknown";const a=Rr(t);return a.length===0?"unknown":a.some(l=>s.includes(l))?"used":"unused"}function Lr(t){return t.startsWith("#import ")||t.startsWith("import ")||t.startsWith("@import ")?t.trim():t.startsWith("<")||t.startsWith('"')?`#import ${t.trim()}`:t.trim()}const Dr=[{value:"",label:"—"},{value:"networking",label:"Networking"},{value:"ui",label:"UI"},{value:"data",label:"Data"},{value:"architecture",label:"Architecture"},{value:"conventions",label:"Conventions"}],Pr=t=>{var r;const s=(((r=t.content)==null?void 0:r.pattern)||"").trim();if(!s)return!1;const a=s.split(`
91
- `).filter(i=>i.trim());return!(a.filter(i=>/^\s*(#{1,6}\s|[-*>]\s|\d+\.\s)/.test(i)).length>a.length*.3)},Fr=({res:t,index:s,editingCodeIndex:a,setEditingCodeIndex:l,expandedEditIndex:r,setExpandedEditIndex:i,similarityMap:c,handleUpdateScanResult:o,handleSaveExtracted:j,handlePromoteToCandidate:g,openCompare:h,isSavingRecipe:y=!1})=>{var X,$,H;const[x,m]=n.useState(!1),u=r===s,A=t.headers||[],S=((X=t.content)==null?void 0:X.pattern)||"",I=(($=t.content)==null?void 0:$.markdown)||"",P=t.description||"",B=t.tags||[],R=Pr(t),K=(C,p)=>{o(s,{content:{...t.content||{},[C]:p}})};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(Qe,{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(Je,{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=>o(s,{title:C.target.value})})]}),e.jsxs("div",{className:"flex gap-2 shrink-0 pt-3",children:[g&&e.jsxs("button",{onClick:()=>g(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(rl,{size:E.md}),"Candidate"]}),e.jsxs("button",{onClick:()=>j(t),disabled:y,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 ${R&&t.mode==="full"?"bg-blue-600 text-white hover:bg-blue-700":"bg-amber-600 text-white hover:bg-amber-700"}`,children:[y?e.jsx(Ee,{size:E.md,className:"animate-spin"}):e.jsx(ja,{size:E.md}),y?"保存中...":R?"保存为 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=>o(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=>o(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=>o(s,{topicHint:C.target.value}),children:Dr.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=>o(s,{category:C.target.value}),children:$l.filter(C=>C!=="All").map(C=>e.jsx("option",{value:C,children:C},C))})]}),R&&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:()=>o(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:()=>o(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"}),R&&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:()=>o(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:()=>o(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=>o(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??((H=t.stats)==null?void 0:H.authority)??3,onChange:C=>o(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,p)=>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 O=[...B];O.splice(p,1),o(s,{tags:O})},className:"text-blue-400 hover:text-red-500 transition-colors leading-none text-[10px]",title:"移除",children:"×"})]},p)),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 p=C.currentTarget,O=p.value.trim();if((C.key==="Enter"||C.key===","||C.key===",")&&O){C.preventDefault();const k=O.replace(/[,,]/g,"").trim();k&&!B.includes(k)&&o(s,{tags:[...B,k]}),p.value=""}else if(C.key==="Backspace"&&!p.value&&B.length>0){const k=[...B];k.pop(),o(s,{tags:k})}},onBlur:C=>{const p=C.currentTarget.value.trim().replace(/[,,]/g,"").trim();p&&!B.includes(p)&&o(s,{tags:[...B,p]}),C.currentTarget.value=""}})]})}),R&&A.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:()=>i(r===s?null:s),className:`text-[10px] font-bold px-2 py-0.5 rounded-md transition-colors border ${u?"text-blue-700 bg-blue-100 border-blue-300":"text-blue-600 bg-blue-50 border-blue-100 hover:bg-blue-100"}`,children:[u?"收起":"编辑"," (",A.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:()=>o(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=A.filter(O=>Lt(O,S)==="used").length,p=A.filter(O=>Lt(O,S)==="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&&p>0&&" · ",p>0&&e.jsxs("span",{className:"text-amber-600 font-bold",children:[p," 未引用"]})]})})()]}),u&&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=A.map(p=>Lr(p));o(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:"格式化"}),A.some(C=>Lt(C,S)==="unused")&&e.jsx("button",{onClick:()=>{const C=A.filter(p=>Lt(p,S)!=="unused");o(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=[...A,t.language==="objectivec"?"#import <Module/Header.h>":"import ModuleName"];o(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:A.map((C,p)=>{const O=Lt(C,S);return e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:`w-2 h-2 rounded-full shrink-0 ${O==="used"?"bg-green-500":O==="unused"?"bg-amber-400":"bg-slate-300"}`,title:O==="used"?"代码中有引用":O==="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 ${O==="unused"?"border-amber-300 text-amber-700":"border-slate-200"}`,value:C,onChange:k=>{const b=[...A];b[p]=k.target.value,o(s,{headers:b})},placeholder:t.language==="objectivec"?"#import <Module/Header.h>":"import ModuleName"}),O==="unused"&&e.jsx("span",{className:"text-[8px] text-amber-500 font-bold shrink-0",children:"未引用"}),e.jsx("button",{onClick:()=>{const k=A.filter((b,f)=>f!==p);o(s,{headers:k})},className:"px-2 py-1 bg-red-500 text-white rounded hover:bg-red-600 text-[9px] font-bold shrink-0",children:"删除"})]},p)})})]})]})]}),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(Je,{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=>o(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=>o(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=>o(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:P,onChange:C=>o(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:()=>m(!x),className:`flex items-center gap-1 text-[10px] font-bold px-2 py-1 rounded transition-colors ${x?"text-blue-600 hover:text-blue-700 bg-blue-50":"text-slate-500 hover:text-slate-700 hover:bg-slate-100"}`,children:x?e.jsxs(e.Fragment,{children:[e.jsx(ft,{size:E.xs})," 完成"]}):e.jsxs(e.Fragment,{children:[e.jsx(ws,{size:E.xs})," 编辑"]})})]}),x?e.jsx("textarea",{rows:Math.max(6,(I||"").split(`
92
- `).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:I,onChange:C=>K("markdown",C.target.value)}):I?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:I}):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(ft,{size:E.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:E.xs})," 编辑"]})]}),a===s?e.jsx("div",{className:"rounded-xl overflow-hidden",children:e.jsx(Vt,{value:S,onChange:C=>K("pattern",C),language:Qs(t),height:`${Math.min(12,S.split(`
93
- `).length)*20+16}px`})}):S?e.jsx(rt,{code:S,language:Qs(t),showLineNumbers:!0}):e.jsx("p",{className:"text-xs text-slate-400 italic py-4",children:"(无代码模板)"})]}),(()=>{const C=t.candidateId??t.id??`scan-${s}`,p=c[C],O=(p||[]).filter(f=>f.similarity>=.6);if(O.length===0)return null;const k=O.filter(f=>f.similarity>=.85),b=k.length>0;return e.jsxs("div",{className:"space-y-1.5",children:[b&&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:"高重复风险:"}),k.map(f=>e.jsxs("button",{onClick:()=>h(t,f.recipeName,p||[]),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:[f.recipeName.replace(/\.md$/i,"")," ",(f.similarity*100).toFixed(0),"%"]},f.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:"}),O.slice(0,5).map(f=>e.jsxs("button",{onClick:()=>h(t,f.recipeName,p||[]),className:`text-[10px] font-bold px-2 py-1 rounded border transition-colors flex items-center gap-1 ${f.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:`与 ${f.recipeName} 相似 ${(f.similarity*100).toFixed(0)}%,点击对比`,children:[e.jsx(ds,{size:E.xs}),f.recipeName.replace(/\.md$/i,"")," ",(f.similarity*100).toFixed(0),"%"]},f.recipeName))]})]})})()]})]})},Or=t=>{const s=(t.language||"").toLowerCase();return s==="objectivec"||s==="objc"||s==="objective-c"||s==="obj-c"?"objectivec":t.language||"swift"},Br=({data:t,onClose:s,onDataChange:a,recipes:l,handleSaveExtracted:r,handleDeleteCandidate:i,onEditRecipe:c,isSavingRecipe:o=!1})=>{var S,I,P,B;const j=t.candidate,g=Or(j),h=()=>{var $,H;const R=[],K=(($=j.content)==null?void 0:$.pattern)||"",X=((H=j.content)==null?void 0:H.markdown)||j.doClause||"";K&&R.push("## Snippet / Code Reference\n\n```"+g+`
90
+ `)||"";else try{we=(await re.getRecipeContentByName(Y)).content}catch{return}ye(Ce=>Ce?{...Ce,recipeName:Y,recipeContent:we,recipeContents:{...Ce.recipeContents,[Y]:we}}:null)}},z=async()=>{if(window.confirm("确定删除该候选?"))try{await r(ae.targetName,je.id),ye(null)}catch(Y){le((Y==null?void 0:Y.message)||"删除失败",{title:"删除失败",type:"error"})}},me=()=>{c(je,ae.targetName),ye(null)},ie=()=>{var ke;const Y=(ke=t==null?void 0:t.recipes)==null?void 0:ke.find(Ne=>Ne.name===ae.recipeName||Ne.name.endsWith("/"+ae.recipeName));Y?j==null||j(Y):j==null||j({name:ae.recipeName,content:{markdown:ae.recipeContent}}),ye(null)};return e.jsxs("div",{className:`relative h-full bg-white shadow-2xl flex flex-col border-l border-slate-200 ${A?"w-[800px] max-w-[55vw]":"w-[600px] max-w-[45vw]"}`,style:{animation:"slideInRight 0.2s ease-out"},onClick:Y=>Y.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:ae.recipeName.replace(/\.md$/i,"")})]})]}),e.jsxs("div",{className:"flex items-center gap-1.5 shrink-0 ml-2",children:[e.jsx("button",{onClick:()=>Le(),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:ie,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:()=>ye(null),className:"p-1.5 hover:bg-slate-200 rounded-lg transition-colors text-slate-400",children:e.jsx(Ke,{size:16})})]})]}),ae.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:ae.similarList.map(Y=>e.jsxs("button",{onClick:()=>ot(Y.recipeName),className:`text-[10px] font-bold px-2 py-1 rounded transition-colors ${ae.recipeName===Y.recipeName?"bg-emerald-200 text-emerald-800":"bg-white text-emerald-600 hover:bg-emerald-50 border border-emerald-100"}`,children:[Y.recipeName.replace(/\.md$/i,"")," ",(Y.similarity*100).toFixed(0),"%"]},Y.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:z,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(tt,{size:12})," 删除候选"]}),e.jsxs("button",{onClick:me,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(bt,{size:12})," 审核候选"]}),e.jsxs("button",{onClick:()=>He(),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(mt,{content:ae.recipeContent,stripFrontmatter:!0})})]})})(),e.jsxs("div",{className:`relative h-full bg-white shadow-2xl flex flex-col border-l border-slate-200 ${A?"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:N.title})}),e.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[e.jsx("button",{onClick:F,disabled:!G,className:"p-1.5 hover:bg-slate-100 rounded-lg transition-colors disabled:opacity-30",title:"上一条",children:e.jsx(Zt,{size:T.md})}),e.jsxs("span",{className:"text-xs text-slate-400 tabular-nums",children:[pe+1,"/",d.length]}),e.jsx("button",{onClick:te,disabled:!oe,className:"p-1.5 hover:bg-slate-100 rounded-lg transition-colors disabled:opacity-30",title:"下一条",children:e.jsx(st,{size:T.md})}),e.jsx("div",{className:"w-px h-5 bg-slate-200 mx-1"}),e.jsx("button",{onClick:S,className:"p-1.5 hover:bg-slate-100 rounded-lg transition-colors text-slate-400",title:A?"收窄":"展宽",children:A?e.jsx(Is,{size:T.md}):e.jsx(hs,{size:T.md})}),e.jsx("button",{onClick:()=>{r(fe,N.id),u(null),ye(null)},className:"p-1.5 hover:bg-red-50 rounded-lg text-red-500 transition-colors",title:"删除",children:e.jsx(tt,{size:T.md})}),e.jsx("button",{onClick:()=>{u(null),ye(null)},className:"p-1.5 hover:bg-slate-100 rounded-lg transition-colors",children:e.jsx(Ke,{size:T.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 ${(_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:N.category||"general"}),N.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:N.knowledgeType}),N.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:N.language}),N.complexity&&e.jsx("span",{className:`text-[10px] font-medium px-1.5 py-0.5 rounded border ${N.complexity==="advanced"?"bg-red-50 text-red-600 border-red-100":N.complexity==="intermediate"?"bg-amber-50 text-amber-600 border-amber-100":"bg-emerald-50 text-emerald-600 border-emerald-100"}`,children:N.complexity==="advanced"?"高级":N.complexity==="intermediate"?"中级":"初级"}),N.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:N.trigger}),N.source&&N.source!=="unknown"&&e.jsx("span",{className:`text-[10px] font-medium px-1.5 py-0.5 rounded border ${qe.color}`,children:qe.label}),N.lifecycle&&N.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:N.lifecycle})]}),e.jsx("div",{className:"flex flex-wrap gap-x-5 gap-y-2 text-xs",children:(()=>{const je=[];return N.scope&&je.push({icon:wt,iconClass:"text-teal-400",label:"范围",value:N.scope==="universal"?"通用":N.scope==="project-specific"?"项目级":N.scope==="module-level"?"模块级":N.scope}),N.source&&N.source!=="unknown"&&je.push({icon:wt,iconClass:"text-violet-400",label:"来源",value:qe.label}),N.createdAt&&Rt(N.createdAt)&&je.push({icon:it,iconClass:"text-slate-400",label:"创建",value:Rt(N.createdAt)}),je.map((Pe,He)=>{const Le=Pe.icon;return e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(Le,{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})]},He)})})()})]}),N.tags&&N.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"}),N.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))]}),N.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:N.description})]}),be&&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(ht,{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((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))]}),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((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))]})]})]}),N.quality&&N.quality.grade&&N.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 ${N.quality.grade==="A"?"text-emerald-600":N.quality.grade==="B"?"text-blue-600":N.quality.grade==="C"?"text-amber-600":N.quality.grade==="D"?"text-orange-600":"text-slate-400"}`,children:N.quality.grade}),e.jsxs("div",{className:"flex-1 grid grid-cols-3 gap-2 text-[10px]",children:[N.quality.completeness!=null&&N.quality.completeness>0&&e.jsxs("div",{className:"text-center",children:[e.jsx("div",{className:"font-bold text-slate-700",children:N.quality.completeness}),e.jsx("div",{className:"text-slate-400",children:"完整性"})]}),N.quality.adaptation!=null&&N.quality.adaptation>0&&e.jsxs("div",{className:"text-center",children:[e.jsx("div",{className:"font-bold text-slate-700",children:N.quality.adaptation}),e.jsx("div",{className:"text-slate-400",children:"适配度"})]}),N.quality.documentation!=null&&N.quality.documentation>0&&e.jsxs("div",{className:"text-center",children:[e.jsx("div",{className:"font-bold text-slate-700",children:N.quality.documentation}),e.jsx("div",{className:"text-slate-400",children:"文档度"})]})]})]})]}),(()=>{const je=N.relations?Object.entries(N.relations).flatMap(([He,Le])=>Array.isArray(Le)?Le.map(ot=>({...ot,type:He})):[]):[];return N.agentNotes||N.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(Ue,{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:[N.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:N.aiInsight})]}),N.agentNotes&&N.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:N.agentNotes.map((He,Le)=>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:"•"}),He]},Le))})]}),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((He,Le)=>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:He.type}),e.jsx("span",{className:"font-medium text-slate-700",children:Oe.get(He.target)||He.target}),He.description&&e.jsxs("span",{className:"text-slate-400",children:["— ",He.description]})]},Le))})]})]})]}):null})(),(Re.length>0||Me)&&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:Me?e.jsx("span",{className:"text-[10px] text-slate-400 animate-pulse",children:"加载中..."}):Re.slice(0,5).map(je=>e.jsxs("button",{onClick:()=>D(N,fe,je.recipeName,Re),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=N.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(xt,{size:11,className:"text-emerald-500"})," 代码 / 标准用法"]}),e.jsx(rt,{code:N.content.pattern,language:N.language==="objc"?"objectivec":N.language,showLineNumbers:!0})]}),((U=N.content)==null?void 0:U.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(et,{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(mt,{content:N.content.markdown})})})]}),(N.doClause||N.whenClause||N.dontClause||N.topicHint||N.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(Qe,{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:[N.topicHint&&e.jsxs("div",{children:[e.jsx("span",{className:"text-indigo-500 font-medium",children:"Topic:"}),e.jsx("span",{className:"text-slate-700",children:N.topicHint})]}),N.whenClause&&e.jsxs("div",{children:[e.jsx("span",{className:"text-blue-500 font-medium",children:"When:"}),e.jsx("span",{className:"text-slate-700",children:N.whenClause})]}),N.doClause&&e.jsxs("div",{children:[e.jsx("span",{className:"text-emerald-500 font-medium",children:"Do:"}),e.jsx("span",{className:"text-slate-700",children:N.doClause})]}),N.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:N.dontClause})]}),N.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:N.coreCode,language:N.language==="objectivec"||N.language==="objc"?"objectivec":N.language||"swift"})})]})]})]}),(N.scope||N.headers&&N.headers.length>0||(($e=N.content)==null?void 0:$e.steps)&&N.content.steps.length>0||((Ge=N.content)==null?void 0:Ge.rationale))&&e.jsxs(e.Fragment,{children:[((Be=N.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:N.content.rationale})})]}),N.headers&&N.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:N.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=N.content)==null?void 0:Xe.steps)&&N.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:N.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 He=typeof je.title=="string"?je.title:"",Le=typeof je.description=="string"?je.description:"",ot=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}),He&&e.jsx("span",{className:"text-xs font-bold text-slate-700",children:He})]}),Le&&e.jsx("p",{className:"text-xs text-slate-600 ml-7 leading-relaxed",children:Le}),ot&&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:ot})]},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(N.id),disabled:I.has(N.id),title:"① 结构补齐",className:`flex items-center gap-1.5 px-3 py-2 rounded-lg text-xs font-medium transition-colors ${I.has(N.id)?"text-slate-300 cursor-not-allowed":"text-amber-600 hover:bg-amber-50 border border-amber-200"}`,children:[I.has(N.id)?e.jsx(Te,{size:14,className:"animate-spin"}):e.jsx(cs,{size:14}),"补齐"]}),e.jsxs("button",{onClick:()=>ce(N.id),disabled:B.has(N.id),title:"② 内容润色",className:`flex items-center gap-1.5 px-3 py-2 rounded-lg text-xs font-medium transition-colors ${B.has(N.id)?"text-slate-300 cursor-not-allowed":"text-emerald-600 hover:bg-emerald-50 border border-emerald-200"}`,children:[B.has(N.id)?e.jsx(Te,{size:14,className:"animate-spin"}):e.jsx(Ue,{size:14}),"润色"]}),e.jsxs("button",{onClick:()=>{r(fe,N.id),u(null),ye(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(tt,{size:14})," 删除"]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[N.lifecycle==="pending"&&e.jsxs("button",{onClick:async()=>{try{await re.promoteCandidateToRecipe(N.id),le("已成功发布为正式 Recipe",{title:"发布成功"}),x==null||x()}catch(je){le(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(Ot,{size:14})," 发布"]}),e.jsxs("button",{onClick:()=>{c(N,fe),u(null),ye(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(bt,{size:14})," 审核并保存"]})]})]})]})]})})()]})},_r=({isOpen:t,onClose:s,currentFile:a,targetName:l,language:r="swift",onSelectRecipe:i})=>{var X,$,H,C;const[c,o]=n.useState(""),[j,g]=n.useState([]),[h,y]=n.useState(null),[x,m]=n.useState(!1),[u,A]=n.useState(null),[S,I]=n.useState(!1),[P,B]=n.useState(null),R=async()=>{if(c.trim()){m(!0);try{const p=await re.search(c,{context:{language:r},limit:10});g((p.items||[]).map(O=>{var k,b,f;return{name:(O.title||O.name||"")+".md",content:((k=O.content)==null?void 0:k.pattern)||((b=O.content)==null?void 0:b.markdown)||((f=O.content)==null?void 0:f.code)||"",similarity:O.score||0,authority:O.authorityScore||0,matchType:O.matchType||"ranked",qualityScore:O.qualityScore||0,usageCount:O.usageCount||0}})),y(null)}catch(p){console.error("Context-aware search failed:",p),alert("搜索失败。请重试。")}finally{m(!1)}}},K=p=>{p.key==="Enter"&&R()};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(Ke,{size:T.lg,className:"text-slate-500"})})]}),h&&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(Je,{size:T.md,className:"text-blue-600 mt-0.5 shrink-0"}),e.jsxs("div",{className:"flex-1",children:[((X=h.targetInfo)==null?void 0:X.targetName)&&e.jsxs("div",{className:"text-blue-900 font-medium flex items-center gap-2 mb-1",children:[e.jsx(vs,{size:T.sm}),"Target: ",h.targetInfo.targetName]}),(($=h.fileInfo)==null?void 0:$.imports)&&h.fileInfo.imports.length>0&&e.jsxs("div",{className:"text-blue-800 text-xs mt-2",children:[e.jsx("strong",{children:"导入的框架:"})," ",h.fileInfo.imports.slice(0,3).join(", "),h.fileInfo.imports.length>3&&` +${h.fileInfo.imports.length-3}`]}),((H=h.targetInfo)==null?void 0:H.suggestedApis)&&h.targetInfo.suggestedApis.length>0&&e.jsxs("div",{className:"text-blue-800 text-xs mt-1",children:[e.jsx("strong",{children:"相关 APIs:"})," ",h.targetInfo.suggestedApis.slice(0,3).join(", ")]})]})]})}),e.jsxs("div",{className:"relative",children:[e.jsx(dt,{className:"absolute left-3 top-1/2 -translate-y-1/2 text-slate-400",size:T.md}),e.jsx("input",{type:"text",placeholder:"输入搜索关键词...",value:c,onChange:p=>o(p.target.value),onKeyDown:K,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:R,disabled:!c.trim()||x,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:[x&&e.jsx(Te,{size:T.sm,className:"animate-spin"}),x?"搜索中...":"搜索"]})]}),e.jsxs("div",{className:"flex-1 overflow-auto",children:[j.length===0&&!x&&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:T.xxl,className:"mx-auto mb-2 opacity-50"}),e.jsx("p",{className:"text-sm",children:"输入关键词后点击搜索"})]})}),j.map((p,O)=>e.jsxs("div",{className:"border-b border-slate-200 p-4 hover:bg-slate-50 transition-colors cursor-pointer",onClick:()=>{A(u===O?null:O),p.name&&(i==null||i(p.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:p.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(Je,{size:T.xs}),Math.round(p.similarity*100),"%"]}),p.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:T.xs}),"上下文相关"]}),p.matchType&&e.jsx("span",{className:"text-xs text-slate-500",children:p.matchType==="semantic"?"语义匹配":"关键词匹配"})]})]}),e.jsx("button",{onClick:k=>{k.stopPropagation(),A(u===O?null:O)},className:"p-1 hover:bg-slate-200 rounded transition-colors",children:u===O?"▼":"▶"})]}),p.stats&&e.jsxs("div",{className:"text-xs text-slate-500 mb-2 flex gap-3",children:[p.stats.authorityScore!==void 0&&e.jsxs("span",{children:["权威分: ",p.stats.authorityScore]}),p.usageCount!==void 0&&e.jsxs("span",{children:["使用: ",p.usageCount,"次"]})]}),u===O&&e.jsxs("div",{className:"mt-3 pt-3 border-t border-slate-200",children:[p.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:p.recommendReason})]}),e.jsxs("div",{className:"text-xs text-slate-600 max-h-[200px] overflow-auto bg-slate-50 p-3 rounded",children:[p.content.substring(0,500),"..."]}),e.jsx("button",{onClick:k=>{k.stopPropagation(),B(p),I(!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:"查看完整内容"})]})]},O)),x&&e.jsx("div",{className:"flex items-center justify-center h-32",children:e.jsx(Te,{size:T.lg,className:"animate-spin text-blue-600"})}),j.length===0&&c&&!x&&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:T.xl,className:"mx-auto mb-2 opacity-50"}),e.jsx("p",{className:"text-sm",children:"未找到匹配的结果"})]})})]})]}),S&&P&&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:P.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(P.similarity*100),"%"]}),P.isContextRelevant&&e.jsx("span",{className:"text-xs bg-green-100 text-green-700 px-2 py-1 rounded",children:"✓ 上下文相关"}),P.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:["🤖 质量: ",(P.qualityScore*100).toFixed(0),"%"]}),((C=P.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(P.stats.authorityScore*100)/100]})]})]}),e.jsx("button",{onClick:()=>I(!1),className:"p-1 hover:bg-slate-100 rounded transition-colors shrink-0",children:e.jsx(Ke,{size:T.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:P.content?e.jsx(rt,{code:P.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:()=>I(!1),className:"px-4 py-2 text-slate-700 hover:bg-slate-200 rounded transition-colors text-sm font-medium",children:"关闭"}),i&&e.jsxs("button",{onClick:()=>{i(P.name),I(!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(st,{size:T.md}),"使用此片段"]})]})]})]})]}):null},Qs=t=>{const s=(t.language||"").toLowerCase();return s==="objectivec"||s==="objc"||s==="objective-c"||s==="obj-c"?"objectivec":t.language||"swift"};function Rr(t){const s=[],a=t.match(/#import\s+"([^"]+)"/);if(a){const c=a[1].replace(/\.h$/,"");s.push(c)}const l=t.match(/#import\s+<([^>]+)>/);if(l){const c=l[1].replace(/\.h$/,"").split("/");s.push(...c)}const r=t.match(/^import\s+(\w+)/);r&&s.push(r[1]);const i=t.match(/@import\s+(\w+)/);return i&&s.push(i[1]),[...new Set(s.filter(Boolean))]}function Lt(t,s){if(!s||!s.trim())return"unknown";const a=Rr(t);return a.length===0?"unknown":a.some(l=>s.includes(l))?"used":"unused"}function Lr(t){return t.startsWith("#import ")||t.startsWith("import ")||t.startsWith("@import ")?t.trim():t.startsWith("<")||t.startsWith('"')?`#import ${t.trim()}`:t.trim()}const Dr=[{value:"",label:"—"},{value:"networking",label:"Networking"},{value:"ui",label:"UI"},{value:"data",label:"Data"},{value:"architecture",label:"Architecture"},{value:"conventions",label:"Conventions"}],Pr=t=>{var r;const s=(((r=t.content)==null?void 0:r.pattern)||"").trim();if(!s)return!1;const a=s.split(`
91
+ `).filter(i=>i.trim());return!(a.filter(i=>/^\s*(#{1,6}\s|[-*>]\s|\d+\.\s)/.test(i)).length>a.length*.3)},Fr=({res:t,index:s,editingCodeIndex:a,setEditingCodeIndex:l,expandedEditIndex:r,setExpandedEditIndex:i,similarityMap:c,handleUpdateScanResult:o,handleSaveExtracted:j,handlePromoteToCandidate:g,openCompare:h,isSavingRecipe:y=!1})=>{var X,$,H;const[x,m]=n.useState(!1),u=r===s,A=t.headers||[],S=((X=t.content)==null?void 0:X.pattern)||"",I=(($=t.content)==null?void 0:$.markdown)||"",P=t.description||"",B=t.tags||[],R=Pr(t),K=(C,p)=>{o(s,{content:{...t.content||{},[C]:p}})};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(Qe,{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(Je,{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=>o(s,{title:C.target.value})})]}),e.jsxs("div",{className:"flex gap-2 shrink-0 pt-3",children:[g&&e.jsxs("button",{onClick:()=>g(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(rl,{size:T.md}),"Candidate"]}),e.jsxs("button",{onClick:()=>j(t),disabled:y,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 ${R&&t.mode==="full"?"bg-blue-600 text-white hover:bg-blue-700":"bg-amber-600 text-white hover:bg-amber-700"}`,children:[y?e.jsx(Te,{size:T.md,className:"animate-spin"}):e.jsx(ja,{size:T.md}),y?"保存中...":R?"保存为 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=>o(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=>o(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=>o(s,{topicHint:C.target.value}),children:Dr.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=>o(s,{category:C.target.value}),children:$l.filter(C=>C!=="All").map(C=>e.jsx("option",{value:C,children:C},C))})]}),R&&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:()=>o(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:()=>o(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"}),R&&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:()=>o(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:()=>o(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=>o(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??((H=t.stats)==null?void 0:H.authority)??3,onChange:C=>o(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,p)=>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 O=[...B];O.splice(p,1),o(s,{tags:O})},className:"text-blue-400 hover:text-red-500 transition-colors leading-none text-[10px]",title:"移除",children:"×"})]},p)),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 p=C.currentTarget,O=p.value.trim();if((C.key==="Enter"||C.key===","||C.key===",")&&O){C.preventDefault();const k=O.replace(/[,,]/g,"").trim();k&&!B.includes(k)&&o(s,{tags:[...B,k]}),p.value=""}else if(C.key==="Backspace"&&!p.value&&B.length>0){const k=[...B];k.pop(),o(s,{tags:k})}},onBlur:C=>{const p=C.currentTarget.value.trim().replace(/[,,]/g,"").trim();p&&!B.includes(p)&&o(s,{tags:[...B,p]}),C.currentTarget.value=""}})]})}),R&&A.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:()=>i(r===s?null:s),className:`text-[10px] font-bold px-2 py-0.5 rounded-md transition-colors border ${u?"text-blue-700 bg-blue-100 border-blue-300":"text-blue-600 bg-blue-50 border-blue-100 hover:bg-blue-100"}`,children:[u?"收起":"编辑"," (",A.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:()=>o(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=A.filter(O=>Lt(O,S)==="used").length,p=A.filter(O=>Lt(O,S)==="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&&p>0&&" · ",p>0&&e.jsxs("span",{className:"text-amber-600 font-bold",children:[p," 未引用"]})]})})()]}),u&&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=A.map(p=>Lr(p));o(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:"格式化"}),A.some(C=>Lt(C,S)==="unused")&&e.jsx("button",{onClick:()=>{const C=A.filter(p=>Lt(p,S)!=="unused");o(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=[...A,t.language==="objectivec"?"#import <Module/Header.h>":"import ModuleName"];o(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:A.map((C,p)=>{const O=Lt(C,S);return e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:`w-2 h-2 rounded-full shrink-0 ${O==="used"?"bg-green-500":O==="unused"?"bg-amber-400":"bg-slate-300"}`,title:O==="used"?"代码中有引用":O==="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 ${O==="unused"?"border-amber-300 text-amber-700":"border-slate-200"}`,value:C,onChange:k=>{const b=[...A];b[p]=k.target.value,o(s,{headers:b})},placeholder:t.language==="objectivec"?"#import <Module/Header.h>":"import ModuleName"}),O==="unused"&&e.jsx("span",{className:"text-[8px] text-amber-500 font-bold shrink-0",children:"未引用"}),e.jsx("button",{onClick:()=>{const k=A.filter((b,f)=>f!==p);o(s,{headers:k})},className:"px-2 py-1 bg-red-500 text-white rounded hover:bg-red-600 text-[9px] font-bold shrink-0",children:"删除"})]},p)})})]})]})]}),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(Je,{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=>o(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=>o(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=>o(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:P,onChange:C=>o(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:()=>m(!x),className:`flex items-center gap-1 text-[10px] font-bold px-2 py-1 rounded transition-colors ${x?"text-blue-600 hover:text-blue-700 bg-blue-50":"text-slate-500 hover:text-slate-700 hover:bg-slate-100"}`,children:x?e.jsxs(e.Fragment,{children:[e.jsx(ft,{size:T.xs})," 完成"]}):e.jsxs(e.Fragment,{children:[e.jsx(ws,{size:T.xs})," 编辑"]})})]}),x?e.jsx("textarea",{rows:Math.max(6,(I||"").split(`
92
+ `).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:I,onChange:C=>K("markdown",C.target.value)}):I?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:I}):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(ft,{size:T.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:T.xs})," 编辑"]})]}),a===s?e.jsx("div",{className:"rounded-xl overflow-hidden",children:e.jsx(Vt,{value:S,onChange:C=>K("pattern",C),language:Qs(t),height:`${Math.min(12,S.split(`
93
+ `).length)*20+16}px`})}):S?e.jsx(rt,{code:S,language:Qs(t),showLineNumbers:!0}):e.jsx("p",{className:"text-xs text-slate-400 italic py-4",children:"(无代码模板)"})]}),(()=>{const C=t.candidateId??t.id??`scan-${s}`,p=c[C],O=(p||[]).filter(f=>f.similarity>=.6);if(O.length===0)return null;const k=O.filter(f=>f.similarity>=.85),b=k.length>0;return e.jsxs("div",{className:"space-y-1.5",children:[b&&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:"高重复风险:"}),k.map(f=>e.jsxs("button",{onClick:()=>h(t,f.recipeName,p||[]),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:[f.recipeName.replace(/\.md$/i,"")," ",(f.similarity*100).toFixed(0),"%"]},f.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:"}),O.slice(0,5).map(f=>e.jsxs("button",{onClick:()=>h(t,f.recipeName,p||[]),className:`text-[10px] font-bold px-2 py-1 rounded border transition-colors flex items-center gap-1 ${f.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:`与 ${f.recipeName} 相似 ${(f.similarity*100).toFixed(0)}%,点击对比`,children:[e.jsx(ds,{size:T.xs}),f.recipeName.replace(/\.md$/i,"")," ",(f.similarity*100).toFixed(0),"%"]},f.recipeName))]})]})})()]})]})},Or=t=>{const s=(t.language||"").toLowerCase();return s==="objectivec"||s==="objc"||s==="objective-c"||s==="obj-c"?"objectivec":t.language||"swift"},Br=({data:t,onClose:s,onDataChange:a,recipes:l,handleSaveExtracted:r,handleDeleteCandidate:i,onEditRecipe:c,isSavingRecipe:o=!1})=>{var S,I,P,B;const j=t.candidate,g=Or(j),h=()=>{var $,H;const R=[],K=(($=j.content)==null?void 0:$.pattern)||"",X=((H=j.content)==null?void 0:H.markdown)||j.doClause||"";K&&R.push("## Snippet / Code Reference\n\n```"+g+`
94
94
  `+K+"\n```"),X&&R.push(`
95
95
  ## AI Context / Usage Guide
96
96
 
97
97
  `+X),navigator.clipboard.writeText(R.join(`
98
- `)||"").then(()=>le("候选内容已复制到剪贴板",{title:"已复制"}))},y=()=>{const R=Es(t.recipeContent);navigator.clipboard.writeText(R).then(()=>le("Recipe 内容已复制到剪贴板",{title:"已复制"}))},x=async R=>{if(R===t.recipeName)return;const K=t.recipeContents[R];if(K)a({...t,recipeName:R,recipeContent:K});else{let X="";const $=l==null?void 0:l.find(H=>H.name===R||H.name.endsWith("/"+R));if($!=null&&$.content)X=[$.content.pattern,$.content.markdown].filter(Boolean).join(`
98
+ `)||"").then(()=>le("候选内容已复制到剪贴板",{title:"已复制"}))},y=()=>{const R=Ts(t.recipeContent);navigator.clipboard.writeText(R).then(()=>le("Recipe 内容已复制到剪贴板",{title:"已复制"}))},x=async R=>{if(R===t.recipeName)return;const K=t.recipeContents[R];if(K)a({...t,recipeName:R,recipeContent:K});else{let X="";const $=l==null?void 0:l.find(H=>H.name===R||H.name.endsWith("/"+R));if($!=null&&$.content)X=[$.content.pattern,$.content.markdown].filter(Boolean).join(`
99
99
 
100
- `)||"";else try{X=(await re.getRecipeContentByName(R)).content}catch{return}a({...t,recipeName:R,recipeContent:X,recipeContents:{...t.recipeContents,[R]:X}})}},m=async()=>{if(!(!j.candidateId||!t.targetName||!i)&&window.confirm("确定删除该候选?"))try{await i(t.targetName,j.candidateId),s()}catch(R){le((R==null?void 0:R.message)||"删除失败",{title:"删除失败",type:"error"})}},u=()=>{r(j),s()},A=()=>{const R=l==null?void 0:l.find(K=>K.name===t.recipeName||K.name.endsWith("/"+t.recipeName));R?c==null||c(R):c==null||c({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:R=>R.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:[j.candidateId&&t.targetName&&e.jsx("button",{onClick:m,className:"text-xs text-red-600 hover:bg-red-50 px-2 py-1 rounded transition-colors",children:"删除候选"}),e.jsxs("button",{onClick:u,disabled:o,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:[o?e.jsx(Ee,{size:E.xs,className:"animate-spin"}):null,"审核候选"]}),e.jsx("button",{onClick:A,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(Ke,{size:E.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(R=>e.jsxs("button",{onClick:()=>x(R.recipeName),className:`text-[10px] font-bold px-2 py-1 rounded transition-colors ${t.recipeName===R.recipeName?"bg-emerald-200 text-emerald-800":"bg-white text-emerald-600 hover:bg-emerald-100 border border-emerald-200"}`,children:[R.recipeName.replace(/\.md$/i,"")," ",(R.similarity*100).toFixed(0),"%"]},R.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:["候选:",j.title]}),e.jsx("button",{onClick:h,className:"p-1 hover:bg-blue-100 rounded text-blue-500 shrink-0",title:"复制候选",children:e.jsx(_t,{size:E.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"}),(S=j.content)!=null&&S.pattern?e.jsx(rt,{code:((I=j.content)==null?void 0:I.pattern)||"",language:g,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 / 项目特写"}),(P=j.content)!=null&&P.markdown||j.doClause?e.jsx(mt,{content:((B=j.content)==null?void 0:B.markdown)||j.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:y,className:"p-1 hover:bg-emerald-100 rounded text-emerald-500 shrink-0",title:"复制 Recipe",children:e.jsx(_t,{size:E.xs})})]}),e.jsx("div",{className:"flex-1 overflow-y-auto p-4",children:e.jsx(mt,{content:t.recipeContent,stripFrontmatter:!0})})]})]})]})]})},qr=({targets:t,filteredTargets:s,selectedTargetName:a,isScanning:l,scanProgress:r,scanFileList:i,scanResults:c,guardAudit:o,handleScanTarget:j,handleScanProject:g,handleUpdateScanResult:h,handleSaveExtracted:y,handlePromoteToCandidate:x,handleDeleteCandidate:m,onEditRecipe:u,isShellTarget:A,recipes:S=[],isSavingRecipe:I=!1,handleRefreshProject:P})=>{var se;const[B,R]=n.useState(null),[K,X]=n.useState(null),[$,H]=n.useState({}),[C,p]=n.useState(null),[O,k]=n.useState(null),[b,f]=n.useState(!1),[w,Z]=n.useState(),[q,ue]=n.useState(),M=n.useRef(new Set),T=n.useRef([]),ee=n.useCallback(async(V,Q)=>{if(!M.current.has(V)){M.current.add(V),p(V);try{const ae=Q.candidateId&&Q.targetName?{targetName:Q.targetName,candidateId:Q.candidateId}:{candidate:Q.candidate||{}},ye=await re.getCandidateSimilarityEx(ae);H(Se=>({...Se,[V]:ye.similar||[]}))}catch{H(ye=>({...ye,[V]:[]}))}finally{p(null)}}},[]),J=n.useCallback(async(V,Q,ae=[])=>{var xe,Ie,fe;const ye=V.candidateTargetName||"",Se=Q.replace(/\.md$/i,"");let De="";const D=S==null?void 0:S.find(Ae=>Ae.name===Se||Ae.name.endsWith("/"+Se));if(D!=null&&D.content)De=[D.content.pattern,D.content.markdown].filter(Boolean).join(`
100
+ `)||"";else try{X=(await re.getRecipeContentByName(R)).content}catch{return}a({...t,recipeName:R,recipeContent:X,recipeContents:{...t.recipeContents,[R]:X}})}},m=async()=>{if(!(!j.candidateId||!t.targetName||!i)&&window.confirm("确定删除该候选?"))try{await i(t.targetName,j.candidateId),s()}catch(R){le((R==null?void 0:R.message)||"删除失败",{title:"删除失败",type:"error"})}},u=()=>{r(j),s()},A=()=>{const R=l==null?void 0:l.find(K=>K.name===t.recipeName||K.name.endsWith("/"+t.recipeName));R?c==null||c(R):c==null||c({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:R=>R.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:[j.candidateId&&t.targetName&&e.jsx("button",{onClick:m,className:"text-xs text-red-600 hover:bg-red-50 px-2 py-1 rounded transition-colors",children:"删除候选"}),e.jsxs("button",{onClick:u,disabled:o,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:[o?e.jsx(Te,{size:T.xs,className:"animate-spin"}):null,"审核候选"]}),e.jsx("button",{onClick:A,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(Ke,{size:T.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(R=>e.jsxs("button",{onClick:()=>x(R.recipeName),className:`text-[10px] font-bold px-2 py-1 rounded transition-colors ${t.recipeName===R.recipeName?"bg-emerald-200 text-emerald-800":"bg-white text-emerald-600 hover:bg-emerald-100 border border-emerald-200"}`,children:[R.recipeName.replace(/\.md$/i,"")," ",(R.similarity*100).toFixed(0),"%"]},R.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:["候选:",j.title]}),e.jsx("button",{onClick:h,className:"p-1 hover:bg-blue-100 rounded text-blue-500 shrink-0",title:"复制候选",children:e.jsx(Et,{size:T.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"}),(S=j.content)!=null&&S.pattern?e.jsx(rt,{code:((I=j.content)==null?void 0:I.pattern)||"",language:g,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 / 项目特写"}),(P=j.content)!=null&&P.markdown||j.doClause?e.jsx(mt,{content:((B=j.content)==null?void 0:B.markdown)||j.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:y,className:"p-1 hover:bg-emerald-100 rounded text-emerald-500 shrink-0",title:"复制 Recipe",children:e.jsx(Et,{size:T.xs})})]}),e.jsx("div",{className:"flex-1 overflow-y-auto p-4",children:e.jsx(mt,{content:t.recipeContent,stripFrontmatter:!0})})]})]})]})]})},qr=({targets:t,filteredTargets:s,selectedTargetName:a,isScanning:l,scanProgress:r,scanFileList:i,scanResults:c,guardAudit:o,handleScanTarget:j,handleScanProject:g,handleUpdateScanResult:h,handleSaveExtracted:y,handlePromoteToCandidate:x,handleDeleteCandidate:m,onEditRecipe:u,isShellTarget:A,recipes:S=[],isSavingRecipe:I=!1,handleRefreshProject:P})=>{var se;const[B,R]=n.useState(null),[K,X]=n.useState(null),[$,H]=n.useState({}),[C,p]=n.useState(null),[O,k]=n.useState(null),[b,f]=n.useState(!1),[w,Z]=n.useState(),[q,ue]=n.useState(),_=n.useRef(new Set),M=n.useRef([]),ee=n.useCallback(async(V,Q)=>{if(!_.current.has(V)){_.current.add(V),p(V);try{const ae=Q.candidateId&&Q.targetName?{targetName:Q.targetName,candidateId:Q.candidateId}:{candidate:Q.candidate||{}},ye=await re.getCandidateSimilarityEx(ae);H(Se=>({...Se,[V]:ye.similar||[]}))}catch{H(ye=>({...ye,[V]:[]}))}finally{p(null)}}},[]),J=n.useCallback(async(V,Q,ae=[])=>{var xe,Ie,fe;const ye=V.candidateTargetName||"",Se=Q.replace(/\.md$/i,"");let De="";const D=S==null?void 0:S.find(Ae=>Ae.name===Se||Ae.name.endsWith("/"+Se));if(D!=null&&D.content)De=[D.content.pattern,D.content.markdown].filter(Boolean).join(`
101
101
 
102
- `)||"";else try{De=(await re.getRecipeContentByName(Se)).content}catch(Ae){const Oe=(xe=Ae.response)==null?void 0:xe.status,_e=((fe=(Ie=Ae.response)==null?void 0:Ie.data)==null?void 0:fe.message)||Ae.message;Oe===404?le(`"${Se}" 不存在于当前知识库`,{title:"Recipe 不存在",type:"error"}):le(_e,{title:"加载 Recipe 失败",type:"error"});return}const _={[Se]:De};k({candidate:V,targetName:ye,recipeName:Se,recipeContent:De,similarList:ae.slice(0,3),recipeContents:_})},[S]);return n.useEffect(()=>{const V=c.map((Se,De)=>Se.candidateId??`scan-${De}`),Q=T.current;(V.length!==Q.length||V.some((Se,De)=>Se!==Q[De]))&&(M.current.clear(),T.current=V);const ye=setTimeout(()=>{c.forEach((Se,De)=>{var _,xe;const D=Se.candidateId??Se.id??`scan-${De}`;Se.candidateId&&Se.candidateTargetName?ee(D,{targetName:Se.candidateTargetName,candidateId:Se.candidateId}):ee(D,{candidate:{title:Se.title,summary:Se.description||"",code:((_=Se.content)==null?void 0:_.pattern)||"",usageGuide:((xe=Se.content)==null?void 0:xe.markdown)||""}})})},800);return()=>clearTimeout(ye)},[c,ee]),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,")"]}),P&&e.jsx("button",{onClick:P,title:"刷新项目结构",className:"p-1 rounded hover:bg-slate-200 text-slate-400 hover:text-blue-600 transition-colors",children:e.jsx(pt,{size:E.sm})})]}),e.jsx("div",{className:"flex-1 overflow-y-auto p-2 space-y-1",children:s.map(V=>{const Q=A(V.name),ae=a===V.name;return e.jsxs("button",{onClick:()=>j(V),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"} ${ae?"bg-blue-50 border-blue-200 ring-1 ring-blue-200":"bg-white border-transparent"} ${Q?"opacity-90":""}`,children:[e.jsxs("div",{className:`flex flex-col max-w-[85%] ${Q?"opacity-60":""}`,children:[e.jsxs("div",{className:"flex items-center gap-2",children:[!Q&&e.jsx("div",{className:"w-1.5 h-1.5 rounded-full shrink-0 bg-blue-600"}),e.jsx("span",{className:`text-sm truncate ${Q?"font-medium":"font-bold"} ${ae?"text-blue-700":""}`,children:V.name})]}),e.jsx("span",{className:"text-[10px] text-slate-400 truncate pl-3",children:V.packageName})]}),Q?e.jsx("span",{className:"text-[9px] font-bold text-slate-300 border border-slate-100 px-1 rounded",children:"SHELL"}):e.jsx(Je,{size:E.sm,className:`shrink-0 ${ae?"text-blue-500 opacity-100":"text-blue-500 opacity-0 group-hover:opacity-100"} transition-opacity`})]},V.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(Qe,{size:E.md,className:"text-indigo-500"}),e.jsx("span",{children:"全项目扫描结果"}),c.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(Je,{size:E.md,className:"text-blue-500"}),e.jsxs("span",{children:["Target: ",a]}),c.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(bt,{size:E.md,className:"text-slate-400"}),e.jsx("span",{children:"审核提取结果"})]}),c.length>0&&e.jsxs("span",{className:"text-slate-400 font-normal text-xs ml-1",children:["(",c.length," 条",(se=c[0])!=null&&se.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(Yt,{size:E.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:r.status}),i.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:["本次扫描的文件 (",i.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:i.map((V,Q)=>e.jsx("div",{className:"text-xs font-mono text-slate-600 truncate",title:V.path,children:V.name},Q))})]}),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(r.total?r.current/r.total*100:0,98)}%`}})}),e.jsx("p",{className:"text-xs text-slate-400 mt-3",children:r.total?`${Math.round(r.current/r.total*100)}%`:"0%"})]}),!l&&c.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:E.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&&i.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:["本次扫描的文件 (",i.length,")"]}),e.jsx("div",{className:"flex flex-wrap gap-2",children:i.map((V,Q)=>e.jsx("span",{className:"text-xs font-mono bg-white border border-slate-200 text-slate-600 px-2 py-1 rounded",title:V.path,children:V.name},Q))})]}),!l&&a==="__project__"&&(o==null?void 0:o.summary)&&e.jsxs("div",{className:`rounded-xl border p-4 ${o.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:E.md,className:o.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:o.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 ${o.summary.totalViolations>0?"text-amber-700":"text-emerald-700"}`,children:o.summary.totalViolations})]}),o.summary.errors>0&&e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(zt,{size:E.sm,className:"text-red-500"}),e.jsxs("span",{className:"font-bold text-red-700",children:[o.summary.errors," 错误"]})]}),o.summary.warnings>0&&e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(zt,{size:E.sm,className:"text-amber-500"}),e.jsxs("span",{className:"font-bold text-amber-700",children:[o.summary.warnings," 警告"]})]})]})]}),c.map((V,Q)=>e.jsx(Fr,{res:V,index:Q,editingCodeIndex:B,setEditingCodeIndex:R,expandedEditIndex:K,setExpandedEditIndex:X,similarityMap:$,handleUpdateScanResult:h,handleSaveExtracted:y,handlePromoteToCandidate:x,openCompare:J,isSavingRecipe:I},Q))]})]}),O&&e.jsx(Br,{data:O,onClose:()=>k(null),onDataChange:k,recipes:S,handleSaveExtracted:y,handleDeleteCandidate:m,onEditRecipe:u,isSavingRecipe:I}),e.jsx(Mr,{isOpen:b,onClose:()=>f(!1),targetName:q,currentFile:w,language:"swift",onSelectRecipe:V=>{}})]})},Hr=72,Wr=52,ms=24,qt=40,Aa=36,vt=140,Bt=40,Ht=8;function Gr(t,s){const a=new Set(t.map(o=>o.id)),l=new Map;for(const o of s)!a.has(o.from)||!a.has(o.to)||(l.has(o.from)||l.set(o.from,[]),l.get(o.from).push(o.to));const r=new Map,i=new Set;function c(o){if(r.has(o))return r.get(o);if(i.has(o))return 0;i.add(o);const j=l.get(o);if(!j||j.length===0)return r.set(o,0),i.delete(o),0;const g=1+Math.max(...j.map(c));return r.set(o,g),i.delete(o),g}return t.forEach(o=>c(o.id)),r}function Ur(t){return Math.ceil(t/Ht)}function Kr(t,s){const a=Gr(t,s),l=new Map;for(const y of t){const x=a.get(y.id)??0;l.has(x)||l.set(x,[]),l.get(x).push(y.id)}const r=[...new Set(a.values())].sort((y,x)=>y-x),i=[...r].reverse(),c=new Map,o=new Map,j=Math.min(Ht,Math.max(...r.map(y=>(l.get(y)??[]).length),1)),g=(j-1)*ms+j*vt;let h=qt;return i.forEach(y=>{const x=l.get(y)??[],m=Ur(x.length),u=h;for(let S=0;S<m;S++){const I=x.slice(S*Ht,(S+1)*Ht),P=(I.length-1)*ms+I.length*vt,B=(g-P)/2;I.forEach((R,K)=>{const X=qt+Aa+B+K*(vt+ms)+vt/2,$=h+Bt/2;c.set(R,{x:X,y:$})}),h+=S<m-1?Wr:Hr}const A=h-u;o.set(y,{y:u,h:A})}),{positions:c,tiers:a,tierOrder:r,tierYRanges:o}}const Vr=()=>{const[t,s]=n.useState(null),[a,l]=n.useState(!0),[r,i]=n.useState(null),[c,o]=n.useState(null),[j,g]=n.useState("package"),h=async()=>{var b,f;l(!0),i(null);try{const w=await re.getDepGraph(j);s({nodes:Array.isArray(w==null?void 0:w.nodes)?w.nodes:[],edges:Array.isArray(w==null?void 0:w.edges)?w.edges:[],projectRoot:(w==null?void 0:w.projectRoot)??null,generatedAt:w==null?void 0:w.generatedAt})}catch(w){i(((f=(b=w.response)==null?void 0:b.data)==null?void 0:f.error)||w.message||"Failed to load dependency graph")}finally{l(!1)}};n.useEffect(()=>{h()},[j]);const y=Array.isArray(t==null?void 0:t.nodes)?t.nodes:[],x=Array.isArray(t==null?void 0:t.edges)?t.edges:[],{positions:m,tiers:u,tierOrder:A,tierYRanges:S}=n.useMemo(()=>Kr(y,x),[y,x]),I=n.useMemo(()=>{const b=new Map;return y.forEach(f=>{const w=u.get(f.id)??0;b.has(w)||b.set(w,[]),b.get(w).push(f.id)}),b},[y,u]),P=n.useMemo(()=>[...A].reverse(),[A]),{dependsOn:B,dependedBy:R}=n.useMemo(()=>{const b=new Map,f=new Map;return x.forEach(w=>{b.has(w.from)||b.set(w.from,[]),b.get(w.from).push(w.to),f.has(w.to)||f.set(w.to,[]),f.get(w.to).push(w.from)}),{dependsOn:b,dependedBy:f}},[x]),K=Math.min(Ht,Math.max(...A.map(b=>(I.get(b)??[]).length),1)),$=(K-1)*ms+K*vt+Aa*2,H=Math.max(600,qt*2+$),C=Math.max(...[...m.values()].map(b=>b.y),0),p=Math.max(420,C+Bt/2+qt+20),O=[{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)"}],k=b=>O[Math.min(b,O.length-1)]??O[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"})}):r?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:r}),e.jsx("button",{type:"button",onClick:h,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||y.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(Qe,{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:()=>{h()},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(pt,{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(Qe,{size:14,className:"text-slate-400"}),e.jsxs("span",{className:"text-slate-500",children:["包 ",e.jsx("strong",{className:"text-slate-700",children:y.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:x.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:p,viewBox:`0 0 ${H} ${p}`,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"})})}),P.map((b,f)=>{const w=k(f),Z=S.get(b);return Z?e.jsx("rect",{x:qt,y:Z.y-Bt/2-4,width:$,height:Z.h+8,rx:8,fill:w.bg,stroke:w.border,strokeWidth:"1",opacity:.6},b):null}),y.map(b=>{const f=m.get(b.id);if(!f)return null;const w=u.get(b.id)??0,Z=k(P.indexOf(w)),q=b.label.length>14?b.label.slice(0,13)+"…":b.label,ue=c===b.id,M=c?(B.get(c)??[]).includes(b.id):!1,T=c?(R.get(c)??[]).includes(b.id):!1,ee=c&&!ue&&!M&&!T,J=c?ue?{fill:"white",stroke:"rgb(59 130 246)",text:"rgb(30 64 175)",strokeWidth:3,opacity:1}:M?{fill:"rgb(240 253 244)",stroke:"rgb(34 197 94)",text:"rgb(22 101 52)",strokeWidth:2,opacity:1}:T?{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:Z.border,text:Z.text,strokeWidth:2,opacity:1};return e.jsxs("g",{style:{cursor:"pointer",opacity:J.opacity},onClick:()=>o(ue?null:b.id),children:[e.jsx("rect",{x:f.x-vt/2,y:f.y-Bt/2,width:vt,height:Bt,rx:10,ry:10,fill:J.fill,stroke:J.stroke,strokeWidth:J.strokeWidth,filter:ee?void 0:"url(#nodeShadow)"}),e.jsx("text",{x:f.x,y:f.y,textAnchor:"middle",dominantBaseline:"middle",fontSize:"12",fontWeight:"600",fill:J.text,pointerEvents:"none",children:q})]},b.id)})]}),c&&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:c}),e.jsx("button",{type:"button",onClick:()=>o(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(c)??[]).length===0?e.jsx("li",{className:"text-slate-400",children:"无"}):(B.get(c)??[]).map(b=>e.jsxs("li",{children:["→ ",b]},b))})]}),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:(R.get(c)??[]).length===0?e.jsx("li",{className:"text-slate-400",children:"无"}):(R.get(c)??[]).map(b=>e.jsxs("li",{children:["← ",b]},b))})]})]})]})]}),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:["包列表 (",y.length,")"]}),e.jsx("ul",{className:"text-sm space-y-3 max-h-[280px] overflow-y-auto pr-1",children:y.map(b=>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:b.id}),b.packageDir&&e.jsxs("span",{className:"text-slate-500 text-xs",children:["· ",b.packageDir]})]}),b.targets&&b.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:b.targets.join(", ")})]})]},b.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:["依赖关系(小图)(",x.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:x.map((b,f)=>e.jsxs("li",{className:"flex items-center gap-2 text-slate-700",children:[e.jsx("span",{className:"font-semibold text-slate-800",children:b.from}),e.jsx("span",{className:"text-slate-400 shrink-0",children:"→"}),e.jsx("span",{className:"font-semibold text-slate-800",children:b.to})]},`${b.from}-${b.to}-${f}`))})]}),j==="target"&&e.jsxs("p",{className:"text-xs text-slate-500 mt-2",children:["Target 级节点格式:",e.jsx("span",{className:"font-mono",children:"Package::Target"})]})]})]})]})},Jr=({onRefresh:t})=>{const[s,a]=n.useState({}),[l,r]=n.useState([]),[i,c]=n.useState(null),[o,j]=n.useState(!0),[g,h]=n.useState(!1),[y,x]=n.useState(!1),[m,u]=n.useState(""),[A,S]=n.useState(!1),[I,P]=n.useState({ruleId:"",message:"",severity:"warning",pattern:"",languages:["objc","swift"],note:"",dimension:""}),[B,R]=n.useState(!1),[K,X]=n.useState(""),$=async()=>{try{const[f,w]=await Promise.all([re.getGuardRules(),re.getGuardViolations()]);a((f==null?void 0:f.rules)||{}),r((w==null?void 0:w.runs)||[])}catch{a({}),r([])}finally{j(!1)}};n.useEffect(()=>{$()},[]);const H=async()=>{if(window.confirm("确定清空所有 Guard 违反记录?"))try{await re.clearViolations(),$(),t==null||t()}catch(f){le((f==null?void 0:f.message)||"清空违反记录失败",{title:"操作失败",type:"error"})}},C=f=>{P(w=>({...w,languages:w.languages.includes(f)?w.languages.filter(Z=>Z!==f):[...w.languages,f]}))},p=async()=>{var f,w;if(!m.trim()){X("请先输入语义描述");return}X(""),S(!0);try{const q=await re.generateGuardRule({description:m.trim()}),ue=q.dimension;P({ruleId:q.ruleId||"",message:q.message||"",severity:q.severity==="error"?"error":"warning",pattern:q.pattern||"",languages:Array.isArray(q.languages)&&q.languages.length>0?q.languages:["objc","swift"],note:q.note!=null?String(q.note):"",dimension:ue==="file"||ue==="target"||ue==="project"?ue:""}),x(!0)}catch(Z){X(((w=(f=Z==null?void 0:Z.response)==null?void 0:f.data)==null?void 0:w.error)||(Z==null?void 0:Z.message)||"AI 生成失败")}finally{S(!1)}},O=async f=>{var w,Z;if(f.preventDefault(),X(""),!I.ruleId.trim()||!I.message.trim()||!I.pattern.trim()||I.languages.length===0){X("请填写规则 ID、说明、正则和至少一种语言");return}R(!0);try{await re.saveGuardRule({ruleId:I.ruleId.trim(),message:I.message.trim(),severity:I.severity,pattern:I.pattern.trim(),languages:I.languages,note:I.note.trim()||void 0,...I.dimension?{dimension:I.dimension}:{}}),P({ruleId:"",message:"",severity:"warning",pattern:"",languages:["objc","swift"],note:"",dimension:""}),u(""),x(!1),$(),t==null||t()}catch(q){X(((Z=(w=q==null?void 0:q.response)==null?void 0:w.data)==null?void 0:Z.error)||(q==null?void 0:q.message)||"写入失败")}finally{R(!1)}};if(o)return e.jsx("div",{className:"p-6 text-slate-500",children:"加载中..."});const k=Object.entries(s),b=l.reduce((f,w)=>f+w.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:Al,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(nl,{size:14})," 提交误报"]}),e.jsxs("button",{type:"button",onClick:()=>h(!g),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:[g?e.jsx(Ct,{size:14}):e.jsx(st,{size:14}),"AI 写入规则"]}),l.length>0&&e.jsxs("button",{type:"button",onClick:H,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(tt,{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:k.length})," 条"]})]}),b>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(zt,{size:14,className:"text-amber-400"}),e.jsxs("span",{className:"text-amber-600",children:["违反 ",e.jsx("strong",{className:"text-amber-700",children:b})]})]})]})]})]}),e.jsxs("div",{className:"flex-1 overflow-y-auto pr-1",children:[g&&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:m,onChange:f=>{u(f.target.value),X("")},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:p,disabled:A||!m.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:A?"生成中...":"AI 生成"}),K&&e.jsx("p",{className:"mt-2 text-sm text-red-600",children:K})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{type:"button",onClick:()=>x(!y),className:"text-sm font-medium text-blue-600 hover:text-blue-700",children:y?"收起表单":"展开 / 编辑表单"}),I.ruleId&&e.jsxs("span",{className:"text-xs text-slate-500",children:["已生成规则 ID:",I.ruleId]})]})]}),y&&e.jsxs("form",{onSubmit:O,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:I.ruleId,onChange:f=>P(w=>({...w,ruleId:f.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:I.severity,onChange:f=>P(w=>({...w,severity:f.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:I.message,onChange:f=>P(w=>({...w,message:f.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:I.pattern,onChange:f=>P(w=>({...w,pattern:f.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:I.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:I.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:I.dimension,onChange:f=>P(w=>({...w,dimension:f.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:I.note,onChange:f=>P(w=>({...w,note:f.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:()=>x(!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:k.length===0?e.jsx("tr",{children:e.jsx("td",{colSpan:5,className:"py-4 px-4 text-slate-500",children:"暂无规则"})}):k.map(([f,w])=>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:f}),e.jsx("td",{className:"py-2 px-4",children:e.jsx("span",{className:`text-xs font-medium px-1.5 py-0.5 rounded ${w.severity==="error"?"bg-red-100 text-red-700":"bg-amber-100 text-amber-700"}`,children:w.severity})}),e.jsx("td",{className:"py-2 px-4 text-slate-700",children:w.message}),e.jsx("td",{className:"py-2 px-4 text-slate-500",children:(w.languages||[]).join(", ")}),e.jsx("td",{className:"py-2 px-4 text-slate-500 text-xs",children:w.dimension==="file"?"同文件":w.dimension==="target"?"同 target":w.dimension==="project"?"同项目":"—"})]},f))})]})})]}),e.jsxs("section",{children:[e.jsxs("h3",{className:"text-sm font-semibold text-slate-700 mb-3",children:["违反记录(共 ",l.length," 次运行,",b," 处违反)"]}),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(f=>{const w=i===f.id,Z=f.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:()=>c(w?null:f.id),className:"w-full flex items-center gap-2 py-3 px-4 text-left hover:bg-slate-50 transition-colors",children:[w?e.jsx(Ct,{size:E.md}):e.jsx(st,{size:E.md}),e.jsx("span",{className:"font-mono text-sm text-slate-700",children:f.filePath}),e.jsx("span",{className:"text-xs text-slate-400",children:new Date(f.triggeredAt).toLocaleString()}),Z?e.jsxs("span",{className:"ml-auto flex items-center gap-1 text-amber-600 text-xs font-medium",children:[e.jsx(zt,{size:E.sm})," ",f.violations.length," 处违反"]}):e.jsx("span",{className:"ml-auto text-slate-400 text-xs",children:"无违反"})]}),w&&e.jsx("div",{className:"border-t border-slate-100 bg-slate-50/50 p-4",children:f.violations.length===0?e.jsx("p",{className:"text-sm text-slate-500",children:"本次运行未发现违反。"}):e.jsx("ul",{className:"space-y-2",children:f.violations.map((q,ue)=>{var T;const M=s[q.ruleId];return e.jsxs("li",{className:"flex items-start gap-2 text-sm",children:[q.severity==="error"?e.jsx(Kt,{size:E.md,className:"text-red-500 shrink-0 mt-0.5"}):e.jsx(zt,{size:E.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:["[",q.ruleId,"] ",q.filePath?`${q.filePath}:${q.line}`:`L${q.line}`]}),q.dimension&&e.jsx("span",{className:"ml-1.5 text-xs px-1.5 py-0.5 rounded bg-slate-200 text-slate-600",children:q.dimension==="file"?"同文件":q.dimension==="target"?"同 target":"同项目"}),e.jsx("span",{className:"text-slate-700 ml-2",children:q.message})]}),q.snippet&&e.jsx("pre",{className:"text-xs text-slate-600 bg-slate-100 p-2 rounded overflow-x-auto",children:q.snippet}),M&&(M.rationale||((T=M.fixSuggestions)==null?void 0:T.length)||M.sourceRecipe||M.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:[M.rationale&&e.jsxs("div",{className:"flex items-start gap-1.5",children:[e.jsx(Ye,{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:M.rationale})]})]}),M.fixSuggestions&&M.fixSuggestions.length>0&&e.jsxs("div",{className:"flex items-start gap-1.5",children:[e.jsx(Na,{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:M.fixSuggestions.map((ee,J)=>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:ee}),e.jsx("button",{className:"ml-1 text-blue-500 hover:text-blue-700",title:"复制修复建议",onClick:()=>navigator.clipboard.writeText(ee),children:"⎘"})]},J))})]})]}),M.sourceRecipe&&e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx($s,{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:M.sourceRecipe})]}),!M.rationale&&M.note&&e.jsxs("div",{className:"text-slate-500 italic",children:["备注:",M.note]})]})]})]},ue)})})})]},f.id)})})]})]})]})},ea=()=>Math.random().toString(36).substring(2,10),Yr=({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(pa,{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 Xr(t){const s=new Date(t),l=new Date().getTime()-s.getTime(),r=Math.floor(l/6e4);if(r<1)return"刚刚";if(r<60)return`${r}分钟前`;const i=Math.floor(r/60);if(i<24)return`${i}小时前`;const c=Math.floor(i/24);return c<7?`${c}天前`:s.toLocaleDateString("zh-CN",{month:"short",day:"numeric"})}const Zr=()=>{const{close:t,isOpen:s}=ts(),[a,l]=n.useState([]),[r,i]=n.useState(!1),c=n.useRef([]),o=n.useRef(null),j=ka(),{topics:g,activeTopicId:h,activeTopic:y,createTopic:x,deleteTopic:m,saveTopic:u,switchTopic:A,setActiveTopicId:S}=j,I=n.useRef(null),P=n.useRef(null),[B,R]=n.useState(""),[K,X]=n.useState(!1),$=n.useRef(!1);n.useEffect(()=>{s&&t()},[]),n.useEffect(()=>{var b;(b=I.current)==null||b.scrollIntoView({behavior:"smooth"})},[a,r]),n.useEffect(()=>{setTimeout(()=>{var b;return(b=P.current)==null?void 0:b.focus()},200)},[]),n.useEffect(()=>{$.current||h&&a.length>0&&u(h,a)},[a,h,u]);const H=n.useCallback(()=>{$.current=!0,x(),l([]),c.current=[],setTimeout(()=>{$.current=!1},50)},[x,l,c]),C=n.useCallback(b=>{if(b===h)return;$.current=!0,A(b);const f=j.getTopic(b);f?(l(f.messages),c.current=f.messages.filter(w=>w.role==="user"||w.role==="assistant").map(w=>({role:w.role==="assistant"?"model":w.role,content:w.content}))):(l([]),c.current=[]),setTimeout(()=>{$.current=!1},50)},[h,A,j,l,c]),p=n.useCallback((b,f)=>{b.stopPropagation(),m(f),f===h&&($.current=!0,l([]),c.current=[],setTimeout(()=>{$.current=!1},50))},[m,h,l,c]),O=n.useCallback(async()=>{const b=B.trim();if(!b||r)return;let f=h;f||($.current=!0,f=x(),setTimeout(()=>{$.current=!1},50)),R(""),l(q=>[...q,{id:ea(),role:"user",content:b,timestamp:Date.now()}]),i(!0);const w=ea();l(q=>[...q,{id:w,role:"assistant",content:"🔄 AI 思考中...",timestamp:Date.now()}]),c.current.push({role:"user",content:b});const Z=new AbortController;o.current=Z;try{const{onEvent:q,getState:ue}=Ca(w,l),T=(await re.chatStream(b,c.current,ee=>{q(ee)},Z.signal)).text||ue().answerText;c.current.push({role:"model",content:T}),l(ee=>ee.map(J=>J.id===w?{...J,content:T}:J))}catch(q){if(q.name==="AbortError"){const ue="(已取消)";l(M=>M.map(T=>T.id===w?{...T,content:ue}:T))}else l(ue=>ue.map(M=>M.id===w?{...M,content:`请求失败: ${q.message}`}:M))}finally{o.current=null}i(!1)},[B,r,h,x]),k=n.useCallback(b=>{b.key==="Enter"&&!b.shiftKey&&(b.preventDefault(),O())},[O]);return e.jsxs("div",{className:"flex-1 flex h-full bg-slate-50",children:[e.jsx("div",{className:`${K?"w-10":"w-64"} shrink-0 bg-white border-r border-slate-200 flex flex-col transition-all duration-200`,children:K?e.jsxs("div",{className:"flex flex-col items-center py-3 gap-2",children:[e.jsx("button",{onClick:()=>X(!1),className:"p-1.5 hover:bg-slate-100 rounded-lg transition-colors text-slate-400 hover:text-slate-600",title:"展开话题列表",children:e.jsx(st,{size:16})}),e.jsx("button",{onClick:H,className:"p-1.5 hover:bg-blue-50 rounded-lg transition-colors text-blue-500",title:"新建话题",children:e.jsx(gt,{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:H,className:"p-1.5 hover:bg-blue-50 rounded-lg transition-colors text-slate-400 hover:text-blue-600",title:"新建话题",children:e.jsx(gt,{size:14})}),e.jsx("button",{onClick:()=>X(!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:g.length===0?e.jsxs("div",{className:"px-4 py-8 text-center",children:[e.jsx(kt,{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:g.map(b=>{const f=b.id===h,w=b.messages.filter(Z=>Z.role==="user").length;return e.jsx("div",{onClick:()=>C(b.id),className:`group mx-1.5 mb-0.5 px-3 py-2 rounded-lg cursor-pointer transition-colors ${f?"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 ${f?"text-blue-700":"text-slate-700"}`,children:b.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}),Xr(b.updatedAt)]}),w>0&&e.jsxs("span",{className:"text-[10px] text-slate-300",children:[w," 条"]})]})]}),e.jsx("button",{onClick:Z=>p(Z,b.id),className:`p-1 rounded transition-colors shrink-0 ${f?"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(tt,{size:12})})]})},b.id)})})}),g.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:[g.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(kt,{className:"text-blue-600",size:18})}),e.jsxs("div",{children:[e.jsx("h2",{className:"text-sm font-bold text-slate-800",children:y?y.title:"AI Chat"}),e.jsx("p",{className:"text-[11px] text-slate-400",children:"询问任何关于项目的问题"})]})]}),a.length>0&&e.jsxs("button",{onClick:H,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(gt,{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:[a.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(Ue,{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(b=>e.jsx("button",{onClick:()=>{var f;R(b),(f=P.current)==null||f.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:b},b))})]}),a.map(b=>e.jsx("div",{className:`flex ${b.role==="user"?"justify-end":"justify-start"}`,children:e.jsxs("div",{className:`max-w-[80%] ${b.role==="user"?"bg-blue-600 text-white rounded-2xl rounded-tr-md px-4 py-2.5":b.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:[b.role==="assistant"&&e.jsxs("div",{className:"flex items-center gap-1.5 mb-2",children:[e.jsx(Jt,{size:13,className:"text-blue-500"}),e.jsx("span",{className:"text-[11px] font-bold text-blue-600",children:"AI 助手"})]}),b.role==="assistant"&&!b.diff?e.jsx(mt,{content:b.content,className:"text-sm text-slate-700"}):e.jsx("p",{className:`text-sm leading-relaxed whitespace-pre-wrap ${b.role==="user"?"":"text-slate-600"}`,children:b.content}),b.diff&&b.diff.length>0&&e.jsx("div",{className:"space-y-2 mt-2",children:b.diff.map(f=>e.jsx(Yr,{d:f},f.field))})]})},b.id)),r&&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(Ee,{size:14,className:"animate-spin text-blue-500"}),e.jsx("span",{className:"text-sm text-slate-500",children:"AI 思考中..."}),o.current&&e.jsx("button",{onClick:()=>{var b;return(b=o.current)==null?void 0:b.abort()},className:"ml-1 px-1.5 py-0.5 text-[10px] font-bold text-red-500 border border-red-200 rounded hover:bg-red-50 transition-colors",children:"停止"})]})})}),e.jsx("div",{ref:I})]})}),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:P,value:B,onChange:b=>R(b.target.value),onKeyDown:k,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:r}),e.jsx("button",{onClick:O,disabled:!B.trim()||r,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 换行"})]})})]})]})},Qr=28,en=22,tn=50,sn=11,an=10,ut={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 yt(t){return Math.min(tn,Math.max(en,Qr+t*2))}function ta(t,s){return t.length<=s?t:t.substring(0,s-1)+"…"}function ln(t,s,a,l){const r=new Map;for(const h of t)r.set(h.fromId,(r.get(h.fromId)||0)+1),r.set(h.toId,(r.get(h.toId)||0)+1);const i=[...r.keys()],c=[...new Set(i.map(h=>l[h]||"general"))].sort(),o=new Map,j=Math.ceil(Math.sqrt(c.length)),g=400;return c.forEach((h,y)=>{const x=y%j,m=Math.floor(y/j);o.set(h,{x:450+(x-(j-1)/2)*g,y:350+(m-(Math.ceil(c.length/j)-1)/2)*g})}),i.map(h=>{const y=l[h]||"general",x=o.get(y)||{x:450,y:350},m=Math.random()*2*Math.PI,u=40+Math.random()*80;return{id:h,label:s[h]||h,type:a[h]||"recipe",group:y,x:x.x+u*Math.cos(m),y:x.y+u*Math.sin(m),vx:0,vy:0,degree:r.get(h)||1}})}function rn(t,s,a=200){const l=t.map(c=>({...c})),r=new Map(l.map(c=>[c.id,c]));function i(){const c=new Map;for(const o of l){const j=c.get(o.group);j?(j.x+=o.x,j.y+=o.y,j.count++):c.set(o.group,{x:o.x,y:o.y,count:1})}for(const[,o]of c)o.x/=o.count,o.y/=o.count;return c}for(let c=0;c<a;c++){const o=1-c/a,j=18e3*o,g=.015,h=.8,y=i();for(let m=0;m<l.length;m++)for(let u=m+1;u<l.length;u++){const A=l[m],S=l[u];let I=S.x-A.x,P=S.y-A.y,B=Math.sqrt(I*I+P*P)||1;const R=yt(A.degree)+yt(S.degree)+60,K=Math.max(B,1),X=A.group===S.group?.6:1.4,$=j*X/(K*K),H=B<R?(R-B)*.5:0,C=$+H,p=I/K*C,O=P/K*C;A.vx-=p,A.vy-=O,S.vx+=p,S.vy+=O}for(const m of s){const u=r.get(m.fromId),A=r.get(m.toId);if(!u||!A)continue;let S=A.x-u.x,I=A.y-u.y,P=Math.sqrt(S*S+I*I)||1;const B=u.group===A.group?140:280,R=g*(P-B),K=S/P*R,X=I/P*R;u.vx+=K,u.vy+=X,A.vx-=K,A.vy-=X}const x=.008*o;for(const m of l){const u=y.get(m.group);u&&(m.vx+=(u.x-m.x)*x,m.vy+=(u.y-m.y)*x)}for(const m of l)m.vx*=h,m.vy*=h,m.x+=m.vx,m.y+=m.vy}return l}function nn(t,s,a,l,r,i,c=0){const o=a-t,j=l-s,g=Math.sqrt(o*o+j*j)||1,h=o/g,y=j/g,x=t+h*r,m=s+y*r,u=a-h*i,A=l-y*i;if(c===0)return`M${x},${m}L${u},${A}`;const S=(x+u)/2+-y*c,I=(m+A)/2+h*c;return`M${x},${m}Q${S},${I},${u},${A}`}const on=()=>{const[t,s]=n.useState([]),[a,l]=n.useState({}),[r,i]=n.useState({}),[c,o]=n.useState({}),[j,g]=n.useState(null),[h,y]=n.useState(!0),[x,m]=n.useState(null),[u,A]=n.useState(null),[S,I]=n.useState(null),[P,B]=n.useState(null),[R,K]=n.useState(!1),[X,$]=n.useState(null),[H,C]=n.useState(1),[p,O]=n.useState({x:0,y:0}),k=n.useRef(null),b=n.useRef(null),f=n.useRef(!1),w=n.useRef({x:0,y:0}),Z=async()=>{var v,ne;y(!0),m(null);try{const[ve,ce]=await Promise.all([re.getKnowledgeGraph(),re.getGraphStats()]);s(ve.edges||[]),l(ve.nodeLabels||{}),i(ve.nodeTypes||{}),o(ve.nodeCategories||{}),g(ce)}catch(ve){m(((ne=(v=ve.response)==null?void 0:v.data)==null?void 0:ne.error)||ve.message||"加载知识图谱失败")}finally{y(!1)}};n.useEffect(()=>{Z()},[]),n.useEffect(()=>{re.getDiscoverRelationsStatus().then(v=>{v.status==="running"&&(K(!0),$(`AI 分析中…(已运行 ${v.elapsed??0}s)`))}).catch(()=>{})},[]),n.useEffect(()=>{if(!R)return;let v=0;const ne=240,ve=setInterval(async()=>{if(v++,v>ne){clearInterval(ve),K(!1),$("轮询超时,任务可能仍在后台运行。请稍后刷新页面查看结果。");return}try{const ce=await re.getDiscoverRelationsStatus();if(ce.status==="done"){K(!1);const he=ce.discovered??0,d=ce.totalPairs??0,L=ce.batchErrors??0;he===0&&L===0?$(`分析完成,共检查 ${d} 对 Recipe,未发现关系。待 Recipe 数量增加后可再次尝试。`):he===0&&L>0?$(`分析完成,但 ${L} 个批次 AI 调用失败,未发现关系。请检查 AI Provider 配置。`):$(`发现 ${he} 条关系(共分析 ${d} 对${L>0?`,${L} 个批次失败`:""})`),Z()}else if(ce.status==="error"){K(!1);const he=ce.error||"未知错误";he.includes("AI Provider")||he.includes("API Key")?$(`AI 服务未配置: ${he}`):he.includes("超时")||he.includes("timeout")?$(`任务超时: ${he}`):$(`发现失败: ${he}`)}else ce.status==="running"&&$(`AI 分析中…(已运行 ${ce.elapsed??0}s)`)}catch{}},3e3);return()=>clearInterval(ve)},[R]);const q=n.useCallback(async()=>{var v,ne,ve;$(null);try{const ce=await re.discoverRelations();if(ce.status==="empty"){$(ce.message||"Recipe 数量不足,无法分析");return}if(ce.status==="timeout"){$(ce.error||"上次任务超时,请重试");return}if(ce.status==="running"){K(!0),$("AI 分析仍在进行中…");return}K(!0),$("AI 分析已启动,正在后台运行…")}catch(ce){const he=((ve=(ne=(v=ce==null?void 0:ce.response)==null?void 0:v.data)==null?void 0:ne.error)==null?void 0:ve.message)||ce.message||"未知错误";he.includes("ChatAgent")||he.includes("AI Provider")?$(`AI 服务不可用: ${he}`):$(`启动失败: ${he}`)}},[]),ue=n.useMemo(()=>{if(t.length===0)return[];const v=ln(t,a,r,c);return rn(v,t)},[t,a,r,c]),M=n.useMemo(()=>{const v=new Map;for(const ce of ue){const he=v.get(ce.group)||[];he.push(ce),v.set(ce.group,he)}const ne=[],ve=[...v.keys()].sort();for(const ce of ve){const he=v.get(ce);if(he.length===0)continue;let d=0,L=0;for(const W of he)d+=W.x,L+=W.y;d/=he.length,L/=he.length;let N=0,pe=0;for(const W of he){const oe=yt(W.degree);N=Math.max(N,Math.abs(W.x-d)+oe+35),pe=Math.max(pe,Math.abs(W.y-L)+oe+35)}ne.push({group:ce,cx:d,cy:L,rx:Math.max(N,60),ry:Math.max(pe,60),count:he.length})}return ne},[ue]),T=n.useMemo(()=>{const v=[...new Set(ue.map(ve=>ve.group))].sort(),ne={};return v.forEach((ve,ce)=>{ne[ve]=ns[ce%ns.length]}),ne},[ue]),ee=n.useMemo(()=>{if(ue.length===0)return{x:0,y:0,w:900,h:700};let v=1/0,ne=1/0,ve=-1/0,ce=-1/0;for(const he of ue){const d=yt(he.degree);v=Math.min(v,he.x-d-80),ne=Math.min(ne,he.y-d-40),ve=Math.max(ve,he.x+d+80),ce=Math.max(ce,he.y+d+40)}return{x:v,y:ne,w:ve-v,h:ce-ne}},[ue]),J=n.useMemo(()=>new Map(ue.map(v=>[v.id,v])),[ue]),{connectedEdgeIds:se,connectedNodeIds:V}=n.useMemo(()=>{const v=u||S;if(!v)return{connectedEdgeIds:new Set,connectedNodeIds:new Set};const ne=new Set,ve=new Set([v]);for(const ce of t)(ce.fromId===v||ce.toId===v)&&(ne.add(ce.id),ve.add(ce.fromId),ve.add(ce.toId));return{connectedEdgeIds:ne,connectedNodeIds:ve}},[u,S,t]),Q=n.useMemo(()=>{const v=new Map,ne=new Map;for(const ce of t){const he=[ce.fromId,ce.toId].sort().join("|"),d=v.get(he)||0;ne.set(ce.id,d),v.set(he,d+1)}const ve=new Map;for(const ce of t){const he=[ce.fromId,ce.toId].sort().join("|"),d=v.get(he)||1;if(d<=1){ve.set(ce.id,0);continue}const L=ne.get(ce.id)||0;ve.set(ce.id,(L-(d-1)/2)*40)}return ve},[t]),[ae,ye]=n.useState(new Set);n.useEffect(()=>{ye(new Set(t.map(v=>v.relation)))},[t]);const Se=n.useMemo(()=>t.filter(v=>ae.has(v.relation)),[t,ae]),De=v=>{ye(ne=>{const ve=new Set(ne);return ve.has(v)?ve.delete(v):ve.add(v),ve})},D=n.useCallback(v=>{v.button===0&&(f.current=!0,w.current={x:v.clientX,y:v.clientY})},[]),_=n.useCallback(v=>{if(!f.current)return;const ne=v.clientX-w.current.x,ve=v.clientY-w.current.y;w.current={x:v.clientX,y:v.clientY},O(ce=>({x:ce.x+ne,y:ce.y+ve}))},[]),xe=n.useCallback(()=>{f.current=!1},[]),Ie=n.useCallback(v=>{v.preventDefault();const ne=v.deltaY>0?-.1:.1;C(ve=>Math.min(3,Math.max(.2,ve+ne)))},[]),fe=v=>`kg-arrow-${v.replace(/[^a-z_]/g,"")}`;if(h)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(x)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:x}),e.jsx("button",{onClick:Z,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 等)。"}),X&&e.jsx("p",{className:`text-sm ${X.startsWith("发现失败")?"text-red-500":"text-green-600"}`,children:X}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("button",{onClick:q,disabled:R,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:R?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(Ue,{size:E.sm})," AI 发现关系"]})}),e.jsxs("button",{onClick:Z,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(pt,{size:E.sm})," 刷新"]})]})]});const Ae=[...new Set(t.map(v=>v.relation))].sort(),_e=!!(u||S);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:E.lg,className:"text-blue-600"}),e.jsx("h2",{className:"text-lg font-bold text-slate-800",children:"知识图谱"}),j&&e.jsxs("span",{className:"text-xs text-slate-500 bg-slate-100 px-2 py-1 rounded-full",children:[ue.length," 节点 · ",j.totalEdges," 关系"]})]}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("button",{onClick:()=>C(v=>Math.min(v+.2,3)),className:"p-1.5 rounded-lg bg-slate-100 hover:bg-slate-200 transition-colors",title:"放大",children:e.jsx(ol,{size:E.sm})}),e.jsx("button",{onClick:()=>C(v=>Math.max(v-.2,.2)),className:"p-1.5 rounded-lg bg-slate-100 hover:bg-slate-200 transition-colors",title:"缩小",children:e.jsx(il,{size:E.sm})}),e.jsx("button",{onClick:()=>{C(1),O({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:E.sm})}),e.jsx("button",{onClick:Z,className:"p-1.5 rounded-lg bg-slate-100 hover:bg-slate-200 transition-colors",title:"刷新",children:e.jsx(pt,{size:E.sm})}),e.jsx("button",{onClick:q,disabled:R,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:R?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(Ue,{size:E.sm})," 发现关系"]})})]})]}),e.jsx("div",{className:"flex flex-wrap gap-1.5 mb-3 flex-shrink-0",children:Ae.map(v=>{var ne;return e.jsxs("button",{onClick:()=>De(v),className:`flex items-center gap-1 px-2 py-0.5 rounded-full text-[11px] font-medium transition-all border ${ae.has(v)?"border-transparent shadow-sm":"border-slate-200 bg-white text-slate-400 opacity-40"}`,style:ae.has(v)?{backgroundColor:(ut[v]||"#6b7280")+"18",color:ut[v]||"#6b7280"}:{},children:[e.jsx("span",{className:"w-2 h-2 rounded-full",style:{backgroundColor:ut[v]||"#6b7280"}}),rs[v]||v,((ne=j==null?void 0:j.byRelation)==null?void 0:ne[v])!=null&&e.jsxs("span",{className:"opacity-60",children:["(",j.byRelation[v],")"]})]},v)})}),e.jsxs("div",{ref:b,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:f.current?"grabbing":"grab"},onWheel:Ie,children:[e.jsxs("svg",{ref:k,width:"100%",height:"100%",viewBox:`${ee.x} ${ee.y} ${ee.w} ${ee.h}`,onMouseDown:D,onMouseMove:_,onMouseUp:xe,onMouseLeave:xe,style:{transform:`scale(${H}) translate(${p.x/H}px, ${p.y/H}px)`},children:[e.jsxs("defs",{children:[Ae.map(v=>e.jsx("marker",{id:fe(v),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:ut[v]||"#6b7280"})},v)),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:M.map(v=>{const ne=T[v.group]||ns[0];return e.jsxs("g",{children:[e.jsx("ellipse",{cx:v.cx,cy:v.cy,rx:v.rx,ry:v.ry,fill:ne.bg,stroke:ne.border,strokeWidth:1.5,strokeDasharray:"6,4",opacity:.6}),e.jsxs("text",{x:v.cx,y:v.cy-v.ry+14,textAnchor:"middle",fontSize:11,fontWeight:600,fill:ne.text,opacity:.8,style:{pointerEvents:"none",userSelect:"none"},children:[v.group||"general"," (",v.count,")"]})]},v.group)})}),e.jsx("g",{children:Se.map(v=>{const ne=J.get(v.fromId),ve=J.get(v.toId);if(!ne||!ve)return null;const ce=_e?se.has(v.id):!1,he=P===v.id,d=_e?ce?.85:.06:he?.9:.35,L=yt(ne.degree),N=yt(ve.degree),pe=Q.get(v.id)||0,W=nn(ne.x,ne.y,ve.x,ve.y,L,N,pe);return e.jsxs("g",{children:[e.jsx("path",{d:W,fill:"none",stroke:"transparent",strokeWidth:12,onMouseEnter:()=>B(v.id),onMouseLeave:()=>B(null),style:{cursor:"pointer"}}),e.jsx("path",{d:W,fill:"none",stroke:ut[v.relation]||"#6b7280",strokeWidth:he||ce?2:1.2,opacity:d,markerEnd:`url(#${fe(v.relation)})`,strokeDasharray:v.relation==="related"?"6,3":void 0,style:{transition:"opacity 0.25s, stroke-width 0.15s",pointerEvents:"none"}}),he&&(()=>{const oe=(ne.x+ve.x)/2,F=(ne.y+ve.y)/2;return e.jsxs("g",{children:[e.jsx("rect",{x:oe-24,y:F-16,width:48,height:18,rx:4,fill:"white",stroke:ut[v.relation]||"#6b7280",strokeWidth:.8,opacity:.95}),e.jsx("text",{x:oe,y:F-4,textAnchor:"middle",fontSize:9,fontWeight:600,fill:ut[v.relation]||"#6b7280",children:rs[v.relation]||v.relation})]})})()]},v.id)})}),e.jsx("g",{children:ue.map(v=>{const ne=yt(v.degree),ve=u===v.id,ce=_e&&V.has(v.id),he=ve||v.id===S,d=_e&&!ce,L=d?.12:1,N=T[v.group]||ns[0],pe=he?N.border:N.bg,W=he?N.text:N.border,oe=he?"#ffffff":N.text,F=he?N.text:"#64748b";return e.jsxs("g",{onClick:te=>{te.stopPropagation(),A(ve?null:v.id)},onMouseEnter:()=>I(v.id),onMouseLeave:()=>I(null),style:{cursor:"pointer",transition:"opacity 0.25s"},opacity:L,filter:he?"url(#kg-glow)":void 0,children:[e.jsx("circle",{cx:v.x,cy:v.y,r:ne,fill:pe,stroke:W,strokeWidth:he?2.5:1.5}),e.jsx("text",{x:v.x,y:v.y+4,textAnchor:"middle",fontSize:Math.min(sn,ne*.7),fill:oe,fontWeight:700,style:{pointerEvents:"none",userSelect:"none"},children:ta(v.label,4).toUpperCase()}),e.jsx("text",{x:v.x,y:v.y+ne+14,textAnchor:"middle",fontSize:an,fill:F,fontWeight:he?600:400,style:{pointerEvents:"none",userSelect:"none"},children:ta(v.label,18)}),v.degree>=3&&!d&&e.jsxs("g",{children:[e.jsx("circle",{cx:v.x+ne*.7,cy:v.y-ne*.7,r:8,fill:"#3b82f6",stroke:"white",strokeWidth:1.5}),e.jsx("text",{x:v.x+ne*.7,y:v.y-ne*.7+3.5,textAnchor:"middle",fontSize:8,fill:"white",fontWeight:700,style:{pointerEvents:"none"},children:v.degree})]})]},v.id)})})]}),u&&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:()=>A(null),children:"取消选中"})]}),u&&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(cl,{size:14,className:"text-blue-500"}),e.jsx("h3",{className:"font-semibold text-sm text-slate-800",children:a[u]||u}),e.jsxs("span",{className:"text-[10px] text-slate-400 ml-auto",children:["ID: ",u]})]}),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(v=>v.fromId===u&&ae.has(v.relation)).map(v=>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:ut[v.relation]||"#6b7280"}}),e.jsx("span",{className:"text-slate-500",children:rs[v.relation]||v.relation}),e.jsx("span",{className:"text-slate-400",children:"→"}),e.jsx("button",{className:"text-blue-600 hover:underline truncate",onClick:()=>A(v.toId),children:a[v.toId]||v.toId.substring(0,16)})]},v.id)),t.filter(v=>v.fromId===u&&ae.has(v.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(v=>v.toId===u&&ae.has(v.relation)).map(v=>e.jsxs("li",{className:"flex items-center gap-1.5",children:[e.jsx("button",{className:"text-blue-600 hover:underline truncate",onClick:()=>A(v.fromId),children:a[v.fromId]||v.fromId.substring(0,16)}),e.jsx("span",{className:"text-slate-400",children:"→"}),e.jsx("span",{className:"text-slate-500",children:rs[v.relation]||v.relation}),e.jsx("span",{className:"w-1.5 h-1.5 rounded-full flex-shrink-0",style:{backgroundColor:ut[v.relation]||"#6b7280"}})]},v.id)),t.filter(v=>v.toId===u&&ae.has(v.relation)).length===0&&e.jsx("li",{className:"text-slate-400",children:"无"})]})]})]})]})]})},ct={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}},Dt={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:ht},fact:{label:"Fact",color:"text-cyan-700",bg:"bg-cyan-50",border:"border-cyan-200",icon:Ye}},cn={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:ua}]};function Pt(t){if(!t)return"";const s=t<1e12?t*1e3:t,a=new Date(s);if(isNaN(a.getTime())||a.getFullYear()<2e3)return"";const r=Date.now()-s;if(r<0)return a.toLocaleDateString("zh-CN");const i=Math.floor(r/6e4);if(i<1)return"刚刚";if(i<60)return`${i} 分钟前`;const c=Math.floor(i/60);if(c<24)return`${c} 小时前`;const o=Math.floor(c/24);return o<7?`${o} 天前`:a.toLocaleDateString("zh-CN")}function dn(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 xn(t,s=4){return t?_s(t).split(`
102
+ `)||"";else try{De=(await re.getRecipeContentByName(Se)).content}catch(Ae){const Oe=(xe=Ae.response)==null?void 0:xe.status,Ee=((fe=(Ie=Ae.response)==null?void 0:Ie.data)==null?void 0:fe.message)||Ae.message;Oe===404?le(`"${Se}" 不存在于当前知识库`,{title:"Recipe 不存在",type:"error"}):le(Ee,{title:"加载 Recipe 失败",type:"error"});return}const E={[Se]:De};k({candidate:V,targetName:ye,recipeName:Se,recipeContent:De,similarList:ae.slice(0,3),recipeContents:E})},[S]);return n.useEffect(()=>{const V=c.map((Se,De)=>Se.candidateId??`scan-${De}`),Q=M.current;(V.length!==Q.length||V.some((Se,De)=>Se!==Q[De]))&&(_.current.clear(),M.current=V);const ye=setTimeout(()=>{c.forEach((Se,De)=>{var E,xe;const D=Se.candidateId??Se.id??`scan-${De}`;Se.candidateId&&Se.candidateTargetName?ee(D,{targetName:Se.candidateTargetName,candidateId:Se.candidateId}):ee(D,{candidate:{title:Se.title,summary:Se.description||"",code:((E=Se.content)==null?void 0:E.pattern)||"",usageGuide:((xe=Se.content)==null?void 0:xe.markdown)||""}})})},800);return()=>clearTimeout(ye)},[c,ee]),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,")"]}),P&&e.jsx("button",{onClick:P,title:"刷新项目结构",className:"p-1 rounded hover:bg-slate-200 text-slate-400 hover:text-blue-600 transition-colors",children:e.jsx(pt,{size:T.sm})})]}),e.jsx("div",{className:"flex-1 overflow-y-auto p-2 space-y-1",children:s.map(V=>{const Q=A(V.name),ae=a===V.name;return e.jsxs("button",{onClick:()=>j(V),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"} ${ae?"bg-blue-50 border-blue-200 ring-1 ring-blue-200":"bg-white border-transparent"} ${Q?"opacity-90":""}`,children:[e.jsxs("div",{className:`flex flex-col max-w-[85%] ${Q?"opacity-60":""}`,children:[e.jsxs("div",{className:"flex items-center gap-2",children:[!Q&&e.jsx("div",{className:"w-1.5 h-1.5 rounded-full shrink-0 bg-blue-600"}),e.jsx("span",{className:`text-sm truncate ${Q?"font-medium":"font-bold"} ${ae?"text-blue-700":""}`,children:V.name})]}),e.jsx("span",{className:"text-[10px] text-slate-400 truncate pl-3",children:V.packageName})]}),Q?e.jsx("span",{className:"text-[9px] font-bold text-slate-300 border border-slate-100 px-1 rounded",children:"SHELL"}):e.jsx(Je,{size:T.sm,className:`shrink-0 ${ae?"text-blue-500 opacity-100":"text-blue-500 opacity-0 group-hover:opacity-100"} transition-opacity`})]},V.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(Qe,{size:T.md,className:"text-indigo-500"}),e.jsx("span",{children:"全项目扫描结果"}),c.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(Je,{size:T.md,className:"text-blue-500"}),e.jsxs("span",{children:["Target: ",a]}),c.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(bt,{size:T.md,className:"text-slate-400"}),e.jsx("span",{children:"审核提取结果"})]}),c.length>0&&e.jsxs("span",{className:"text-slate-400 font-normal text-xs ml-1",children:["(",c.length," 条",(se=c[0])!=null&&se.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(Yt,{size:T.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:r.status}),i.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:["本次扫描的文件 (",i.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:i.map((V,Q)=>e.jsx("div",{className:"text-xs font-mono text-slate-600 truncate",title:V.path,children:V.name},Q))})]}),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(r.total?r.current/r.total*100:0,98)}%`}})}),e.jsx("p",{className:"text-xs text-slate-400 mt-3",children:r.total?`${Math.round(r.current/r.total*100)}%`:"0%"})]}),!l&&c.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:T.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&&i.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:["本次扫描的文件 (",i.length,")"]}),e.jsx("div",{className:"flex flex-wrap gap-2",children:i.map((V,Q)=>e.jsx("span",{className:"text-xs font-mono bg-white border border-slate-200 text-slate-600 px-2 py-1 rounded",title:V.path,children:V.name},Q))})]}),!l&&a==="__project__"&&(o==null?void 0:o.summary)&&e.jsxs("div",{className:`rounded-xl border p-4 ${o.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:T.md,className:o.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:o.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 ${o.summary.totalViolations>0?"text-amber-700":"text-emerald-700"}`,children:o.summary.totalViolations})]}),o.summary.errors>0&&e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(zt,{size:T.sm,className:"text-red-500"}),e.jsxs("span",{className:"font-bold text-red-700",children:[o.summary.errors," 错误"]})]}),o.summary.warnings>0&&e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(zt,{size:T.sm,className:"text-amber-500"}),e.jsxs("span",{className:"font-bold text-amber-700",children:[o.summary.warnings," 警告"]})]})]})]}),c.map((V,Q)=>e.jsx(Fr,{res:V,index:Q,editingCodeIndex:B,setEditingCodeIndex:R,expandedEditIndex:K,setExpandedEditIndex:X,similarityMap:$,handleUpdateScanResult:h,handleSaveExtracted:y,handlePromoteToCandidate:x,openCompare:J,isSavingRecipe:I},Q))]})]}),O&&e.jsx(Br,{data:O,onClose:()=>k(null),onDataChange:k,recipes:S,handleSaveExtracted:y,handleDeleteCandidate:m,onEditRecipe:u,isSavingRecipe:I}),e.jsx(_r,{isOpen:b,onClose:()=>f(!1),targetName:q,currentFile:w,language:"swift",onSelectRecipe:V=>{}})]})},Hr=72,Gr=52,ms=24,qt=40,Aa=36,vt=140,Bt=40,Ht=8;function Wr(t,s){const a=new Set(t.map(o=>o.id)),l=new Map;for(const o of s)!a.has(o.from)||!a.has(o.to)||(l.has(o.from)||l.set(o.from,[]),l.get(o.from).push(o.to));const r=new Map,i=new Set;function c(o){if(r.has(o))return r.get(o);if(i.has(o))return 0;i.add(o);const j=l.get(o);if(!j||j.length===0)return r.set(o,0),i.delete(o),0;const g=1+Math.max(...j.map(c));return r.set(o,g),i.delete(o),g}return t.forEach(o=>c(o.id)),r}function Ur(t){return Math.ceil(t/Ht)}function Kr(t,s){const a=Wr(t,s),l=new Map;for(const y of t){const x=a.get(y.id)??0;l.has(x)||l.set(x,[]),l.get(x).push(y.id)}const r=[...new Set(a.values())].sort((y,x)=>y-x),i=[...r].reverse(),c=new Map,o=new Map,j=Math.min(Ht,Math.max(...r.map(y=>(l.get(y)??[]).length),1)),g=(j-1)*ms+j*vt;let h=qt;return i.forEach(y=>{const x=l.get(y)??[],m=Ur(x.length),u=h;for(let S=0;S<m;S++){const I=x.slice(S*Ht,(S+1)*Ht),P=(I.length-1)*ms+I.length*vt,B=(g-P)/2;I.forEach((R,K)=>{const X=qt+Aa+B+K*(vt+ms)+vt/2,$=h+Bt/2;c.set(R,{x:X,y:$})}),h+=S<m-1?Gr:Hr}const A=h-u;o.set(y,{y:u,h:A})}),{positions:c,tiers:a,tierOrder:r,tierYRanges:o}}const Vr=()=>{const[t,s]=n.useState(null),[a,l]=n.useState(!0),[r,i]=n.useState(null),[c,o]=n.useState(null),[j,g]=n.useState("package"),h=async()=>{var b,f;l(!0),i(null);try{const w=await re.getDepGraph(j);s({nodes:Array.isArray(w==null?void 0:w.nodes)?w.nodes:[],edges:Array.isArray(w==null?void 0:w.edges)?w.edges:[],projectRoot:(w==null?void 0:w.projectRoot)??null,generatedAt:w==null?void 0:w.generatedAt})}catch(w){i(((f=(b=w.response)==null?void 0:b.data)==null?void 0:f.error)||w.message||"Failed to load dependency graph")}finally{l(!1)}};n.useEffect(()=>{h()},[j]);const y=Array.isArray(t==null?void 0:t.nodes)?t.nodes:[],x=Array.isArray(t==null?void 0:t.edges)?t.edges:[],{positions:m,tiers:u,tierOrder:A,tierYRanges:S}=n.useMemo(()=>Kr(y,x),[y,x]),I=n.useMemo(()=>{const b=new Map;return y.forEach(f=>{const w=u.get(f.id)??0;b.has(w)||b.set(w,[]),b.get(w).push(f.id)}),b},[y,u]),P=n.useMemo(()=>[...A].reverse(),[A]),{dependsOn:B,dependedBy:R}=n.useMemo(()=>{const b=new Map,f=new Map;return x.forEach(w=>{b.has(w.from)||b.set(w.from,[]),b.get(w.from).push(w.to),f.has(w.to)||f.set(w.to,[]),f.get(w.to).push(w.from)}),{dependsOn:b,dependedBy:f}},[x]),K=Math.min(Ht,Math.max(...A.map(b=>(I.get(b)??[]).length),1)),$=(K-1)*ms+K*vt+Aa*2,H=Math.max(600,qt*2+$),C=Math.max(...[...m.values()].map(b=>b.y),0),p=Math.max(420,C+Bt/2+qt+20),O=[{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)"}],k=b=>O[Math.min(b,O.length-1)]??O[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"})}):r?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:r}),e.jsx("button",{type:"button",onClick:h,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||y.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(Qe,{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:()=>{h()},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(pt,{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(Qe,{size:14,className:"text-slate-400"}),e.jsxs("span",{className:"text-slate-500",children:["包 ",e.jsx("strong",{className:"text-slate-700",children:y.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:x.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:p,viewBox:`0 0 ${H} ${p}`,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"})})}),P.map((b,f)=>{const w=k(f),Z=S.get(b);return Z?e.jsx("rect",{x:qt,y:Z.y-Bt/2-4,width:$,height:Z.h+8,rx:8,fill:w.bg,stroke:w.border,strokeWidth:"1",opacity:.6},b):null}),y.map(b=>{const f=m.get(b.id);if(!f)return null;const w=u.get(b.id)??0,Z=k(P.indexOf(w)),q=b.label.length>14?b.label.slice(0,13)+"…":b.label,ue=c===b.id,_=c?(B.get(c)??[]).includes(b.id):!1,M=c?(R.get(c)??[]).includes(b.id):!1,ee=c&&!ue&&!_&&!M,J=c?ue?{fill:"white",stroke:"rgb(59 130 246)",text:"rgb(30 64 175)",strokeWidth:3,opacity:1}:_?{fill:"rgb(240 253 244)",stroke:"rgb(34 197 94)",text:"rgb(22 101 52)",strokeWidth:2,opacity:1}:M?{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:Z.border,text:Z.text,strokeWidth:2,opacity:1};return e.jsxs("g",{style:{cursor:"pointer",opacity:J.opacity},onClick:()=>o(ue?null:b.id),children:[e.jsx("rect",{x:f.x-vt/2,y:f.y-Bt/2,width:vt,height:Bt,rx:10,ry:10,fill:J.fill,stroke:J.stroke,strokeWidth:J.strokeWidth,filter:ee?void 0:"url(#nodeShadow)"}),e.jsx("text",{x:f.x,y:f.y,textAnchor:"middle",dominantBaseline:"middle",fontSize:"12",fontWeight:"600",fill:J.text,pointerEvents:"none",children:q})]},b.id)})]}),c&&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:c}),e.jsx("button",{type:"button",onClick:()=>o(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(c)??[]).length===0?e.jsx("li",{className:"text-slate-400",children:"无"}):(B.get(c)??[]).map(b=>e.jsxs("li",{children:["→ ",b]},b))})]}),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:(R.get(c)??[]).length===0?e.jsx("li",{className:"text-slate-400",children:"无"}):(R.get(c)??[]).map(b=>e.jsxs("li",{children:["← ",b]},b))})]})]})]})]}),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:["包列表 (",y.length,")"]}),e.jsx("ul",{className:"text-sm space-y-3 max-h-[280px] overflow-y-auto pr-1",children:y.map(b=>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:b.id}),b.packageDir&&e.jsxs("span",{className:"text-slate-500 text-xs",children:["· ",b.packageDir]})]}),b.targets&&b.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:b.targets.join(", ")})]})]},b.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:["依赖关系(小图)(",x.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:x.map((b,f)=>e.jsxs("li",{className:"flex items-center gap-2 text-slate-700",children:[e.jsx("span",{className:"font-semibold text-slate-800",children:b.from}),e.jsx("span",{className:"text-slate-400 shrink-0",children:"→"}),e.jsx("span",{className:"font-semibold text-slate-800",children:b.to})]},`${b.from}-${b.to}-${f}`))})]}),j==="target"&&e.jsxs("p",{className:"text-xs text-slate-500 mt-2",children:["Target 级节点格式:",e.jsx("span",{className:"font-mono",children:"Package::Target"})]})]})]})]})},Jr=({onRefresh:t})=>{const[s,a]=n.useState({}),[l,r]=n.useState([]),[i,c]=n.useState(null),[o,j]=n.useState(!0),[g,h]=n.useState(!1),[y,x]=n.useState(!1),[m,u]=n.useState(""),[A,S]=n.useState(!1),[I,P]=n.useState({ruleId:"",message:"",severity:"warning",pattern:"",languages:["objc","swift"],note:"",dimension:""}),[B,R]=n.useState(!1),[K,X]=n.useState(""),$=async()=>{try{const[f,w]=await Promise.all([re.getGuardRules(),re.getGuardViolations()]);a((f==null?void 0:f.rules)||{}),r((w==null?void 0:w.runs)||[])}catch{a({}),r([])}finally{j(!1)}};n.useEffect(()=>{$()},[]);const H=async()=>{if(window.confirm("确定清空所有 Guard 违反记录?"))try{await re.clearViolations(),$(),t==null||t()}catch(f){le((f==null?void 0:f.message)||"清空违反记录失败",{title:"操作失败",type:"error"})}},C=f=>{P(w=>({...w,languages:w.languages.includes(f)?w.languages.filter(Z=>Z!==f):[...w.languages,f]}))},p=async()=>{var f,w;if(!m.trim()){X("请先输入语义描述");return}X(""),S(!0);try{const q=await re.generateGuardRule({description:m.trim()}),ue=q.dimension;P({ruleId:q.ruleId||"",message:q.message||"",severity:q.severity==="error"?"error":"warning",pattern:q.pattern||"",languages:Array.isArray(q.languages)&&q.languages.length>0?q.languages:["objc","swift"],note:q.note!=null?String(q.note):"",dimension:ue==="file"||ue==="target"||ue==="project"?ue:""}),x(!0)}catch(Z){X(((w=(f=Z==null?void 0:Z.response)==null?void 0:f.data)==null?void 0:w.error)||(Z==null?void 0:Z.message)||"AI 生成失败")}finally{S(!1)}},O=async f=>{var w,Z;if(f.preventDefault(),X(""),!I.ruleId.trim()||!I.message.trim()||!I.pattern.trim()||I.languages.length===0){X("请填写规则 ID、说明、正则和至少一种语言");return}R(!0);try{await re.saveGuardRule({ruleId:I.ruleId.trim(),message:I.message.trim(),severity:I.severity,pattern:I.pattern.trim(),languages:I.languages,note:I.note.trim()||void 0,...I.dimension?{dimension:I.dimension}:{}}),P({ruleId:"",message:"",severity:"warning",pattern:"",languages:["objc","swift"],note:"",dimension:""}),u(""),x(!1),$(),t==null||t()}catch(q){X(((Z=(w=q==null?void 0:q.response)==null?void 0:w.data)==null?void 0:Z.error)||(q==null?void 0:q.message)||"写入失败")}finally{R(!1)}};if(o)return e.jsx("div",{className:"p-6 text-slate-500",children:"加载中..."});const k=Object.entries(s),b=l.reduce((f,w)=>f+w.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:Al,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(nl,{size:14})," 提交误报"]}),e.jsxs("button",{type:"button",onClick:()=>h(!g),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:[g?e.jsx(Ct,{size:14}):e.jsx(st,{size:14}),"AI 写入规则"]}),l.length>0&&e.jsxs("button",{type:"button",onClick:H,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(tt,{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:k.length})," 条"]})]}),b>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(zt,{size:14,className:"text-amber-400"}),e.jsxs("span",{className:"text-amber-600",children:["违反 ",e.jsx("strong",{className:"text-amber-700",children:b})]})]})]})]})]}),e.jsxs("div",{className:"flex-1 overflow-y-auto pr-1",children:[g&&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:m,onChange:f=>{u(f.target.value),X("")},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:p,disabled:A||!m.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:A?"生成中...":"AI 生成"}),K&&e.jsx("p",{className:"mt-2 text-sm text-red-600",children:K})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{type:"button",onClick:()=>x(!y),className:"text-sm font-medium text-blue-600 hover:text-blue-700",children:y?"收起表单":"展开 / 编辑表单"}),I.ruleId&&e.jsxs("span",{className:"text-xs text-slate-500",children:["已生成规则 ID:",I.ruleId]})]})]}),y&&e.jsxs("form",{onSubmit:O,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:I.ruleId,onChange:f=>P(w=>({...w,ruleId:f.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:I.severity,onChange:f=>P(w=>({...w,severity:f.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:I.message,onChange:f=>P(w=>({...w,message:f.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:I.pattern,onChange:f=>P(w=>({...w,pattern:f.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:I.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:I.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:I.dimension,onChange:f=>P(w=>({...w,dimension:f.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:I.note,onChange:f=>P(w=>({...w,note:f.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:()=>x(!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:k.length===0?e.jsx("tr",{children:e.jsx("td",{colSpan:5,className:"py-4 px-4 text-slate-500",children:"暂无规则"})}):k.map(([f,w])=>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:f}),e.jsx("td",{className:"py-2 px-4",children:e.jsx("span",{className:`text-xs font-medium px-1.5 py-0.5 rounded ${w.severity==="error"?"bg-red-100 text-red-700":"bg-amber-100 text-amber-700"}`,children:w.severity})}),e.jsx("td",{className:"py-2 px-4 text-slate-700",children:w.message}),e.jsx("td",{className:"py-2 px-4 text-slate-500",children:(w.languages||[]).join(", ")}),e.jsx("td",{className:"py-2 px-4 text-slate-500 text-xs",children:w.dimension==="file"?"同文件":w.dimension==="target"?"同 target":w.dimension==="project"?"同项目":"—"})]},f))})]})})]}),e.jsxs("section",{children:[e.jsxs("h3",{className:"text-sm font-semibold text-slate-700 mb-3",children:["违反记录(共 ",l.length," 次运行,",b," 处违反)"]}),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(f=>{const w=i===f.id,Z=f.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:()=>c(w?null:f.id),className:"w-full flex items-center gap-2 py-3 px-4 text-left hover:bg-slate-50 transition-colors",children:[w?e.jsx(Ct,{size:T.md}):e.jsx(st,{size:T.md}),e.jsx("span",{className:"font-mono text-sm text-slate-700",children:f.filePath}),e.jsx("span",{className:"text-xs text-slate-400",children:new Date(f.triggeredAt).toLocaleString()}),Z?e.jsxs("span",{className:"ml-auto flex items-center gap-1 text-amber-600 text-xs font-medium",children:[e.jsx(zt,{size:T.sm})," ",f.violations.length," 处违反"]}):e.jsx("span",{className:"ml-auto text-slate-400 text-xs",children:"无违反"})]}),w&&e.jsx("div",{className:"border-t border-slate-100 bg-slate-50/50 p-4",children:f.violations.length===0?e.jsx("p",{className:"text-sm text-slate-500",children:"本次运行未发现违反。"}):e.jsx("ul",{className:"space-y-2",children:f.violations.map((q,ue)=>{var M;const _=s[q.ruleId];return e.jsxs("li",{className:"flex items-start gap-2 text-sm",children:[q.severity==="error"?e.jsx(Kt,{size:T.md,className:"text-red-500 shrink-0 mt-0.5"}):e.jsx(zt,{size:T.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:["[",q.ruleId,"] ",q.filePath?`${q.filePath}:${q.line}`:`L${q.line}`]}),q.dimension&&e.jsx("span",{className:"ml-1.5 text-xs px-1.5 py-0.5 rounded bg-slate-200 text-slate-600",children:q.dimension==="file"?"同文件":q.dimension==="target"?"同 target":"同项目"}),e.jsx("span",{className:"text-slate-700 ml-2",children:q.message})]}),q.snippet&&e.jsx("pre",{className:"text-xs text-slate-600 bg-slate-100 p-2 rounded overflow-x-auto",children:q.snippet}),_&&(_.rationale||((M=_.fixSuggestions)==null?void 0:M.length)||_.sourceRecipe||_.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:[_.rationale&&e.jsxs("div",{className:"flex items-start gap-1.5",children:[e.jsx(Ye,{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:_.rationale})]})]}),_.fixSuggestions&&_.fixSuggestions.length>0&&e.jsxs("div",{className:"flex items-start gap-1.5",children:[e.jsx(Na,{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:_.fixSuggestions.map((ee,J)=>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:ee}),e.jsx("button",{className:"ml-1 text-blue-500 hover:text-blue-700",title:"复制修复建议",onClick:()=>navigator.clipboard.writeText(ee),children:"⎘"})]},J))})]})]}),_.sourceRecipe&&e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx($s,{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:_.sourceRecipe})]}),!_.rationale&&_.note&&e.jsxs("div",{className:"text-slate-500 italic",children:["备注:",_.note]})]})]})]},ue)})})})]},f.id)})})]})]})]})},ea=()=>Math.random().toString(36).substring(2,10),Yr=({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(pa,{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 Xr(t){const s=new Date(t),l=new Date().getTime()-s.getTime(),r=Math.floor(l/6e4);if(r<1)return"刚刚";if(r<60)return`${r}分钟前`;const i=Math.floor(r/60);if(i<24)return`${i}小时前`;const c=Math.floor(i/24);return c<7?`${c}天前`:s.toLocaleDateString("zh-CN",{month:"short",day:"numeric"})}const Zr=()=>{const{close:t,isOpen:s}=ts(),[a,l]=n.useState([]),[r,i]=n.useState(!1),c=n.useRef([]),o=n.useRef(null),j=ka(),{topics:g,activeTopicId:h,activeTopic:y,createTopic:x,deleteTopic:m,saveTopic:u,switchTopic:A,setActiveTopicId:S}=j,I=n.useRef(null),P=n.useRef(null),[B,R]=n.useState(""),[K,X]=n.useState(!1),$=n.useRef(!1);n.useEffect(()=>{s&&t()},[]),n.useEffect(()=>{var b;(b=I.current)==null||b.scrollIntoView({behavior:"smooth"})},[a,r]),n.useEffect(()=>{setTimeout(()=>{var b;return(b=P.current)==null?void 0:b.focus()},200)},[]),n.useEffect(()=>{$.current||h&&a.length>0&&u(h,a)},[a,h,u]);const H=n.useCallback(()=>{$.current=!0,x(),l([]),c.current=[],setTimeout(()=>{$.current=!1},50)},[x,l,c]),C=n.useCallback(b=>{if(b===h)return;$.current=!0,A(b);const f=j.getTopic(b);f?(l(f.messages),c.current=f.messages.filter(w=>w.role==="user"||w.role==="assistant").map(w=>({role:w.role==="assistant"?"model":w.role,content:w.content}))):(l([]),c.current=[]),setTimeout(()=>{$.current=!1},50)},[h,A,j,l,c]),p=n.useCallback((b,f)=>{b.stopPropagation(),m(f),f===h&&($.current=!0,l([]),c.current=[],setTimeout(()=>{$.current=!1},50))},[m,h,l,c]),O=n.useCallback(async()=>{const b=B.trim();if(!b||r)return;let f=h;f||($.current=!0,f=x(),setTimeout(()=>{$.current=!1},50)),R(""),l(q=>[...q,{id:ea(),role:"user",content:b,timestamp:Date.now()}]),i(!0);const w=ea();l(q=>[...q,{id:w,role:"assistant",content:"🔄 AI 思考中...",timestamp:Date.now()}]),c.current.push({role:"user",content:b});const Z=new AbortController;o.current=Z;try{const{onEvent:q,getState:ue}=Ca(w,l),M=(await re.chatStream(b,c.current,ee=>{q(ee)},Z.signal)).text||ue().answerText;c.current.push({role:"model",content:M}),l(ee=>ee.map(J=>J.id===w?{...J,content:M}:J))}catch(q){if(q.name==="AbortError"){const ue="(已取消)";l(_=>_.map(M=>M.id===w?{...M,content:ue}:M))}else l(ue=>ue.map(_=>_.id===w?{..._,content:`请求失败: ${q.message}`}:_))}finally{o.current=null}i(!1)},[B,r,h,x]),k=n.useCallback(b=>{b.key==="Enter"&&!b.shiftKey&&(b.preventDefault(),O())},[O]);return e.jsxs("div",{className:"flex-1 flex h-full bg-slate-50",children:[e.jsx("div",{className:`${K?"w-10":"w-64"} shrink-0 bg-white border-r border-slate-200 flex flex-col transition-all duration-200`,children:K?e.jsxs("div",{className:"flex flex-col items-center py-3 gap-2",children:[e.jsx("button",{onClick:()=>X(!1),className:"p-1.5 hover:bg-slate-100 rounded-lg transition-colors text-slate-400 hover:text-slate-600",title:"展开话题列表",children:e.jsx(st,{size:16})}),e.jsx("button",{onClick:H,className:"p-1.5 hover:bg-blue-50 rounded-lg transition-colors text-blue-500",title:"新建话题",children:e.jsx(gt,{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:H,className:"p-1.5 hover:bg-blue-50 rounded-lg transition-colors text-slate-400 hover:text-blue-600",title:"新建话题",children:e.jsx(gt,{size:14})}),e.jsx("button",{onClick:()=>X(!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:g.length===0?e.jsxs("div",{className:"px-4 py-8 text-center",children:[e.jsx(kt,{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:g.map(b=>{const f=b.id===h,w=b.messages.filter(Z=>Z.role==="user").length;return e.jsx("div",{onClick:()=>C(b.id),className:`group mx-1.5 mb-0.5 px-3 py-2 rounded-lg cursor-pointer transition-colors ${f?"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 ${f?"text-blue-700":"text-slate-700"}`,children:b.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}),Xr(b.updatedAt)]}),w>0&&e.jsxs("span",{className:"text-[10px] text-slate-300",children:[w," 条"]})]})]}),e.jsx("button",{onClick:Z=>p(Z,b.id),className:`p-1 rounded transition-colors shrink-0 ${f?"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(tt,{size:12})})]})},b.id)})})}),g.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:[g.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(kt,{className:"text-blue-600",size:18})}),e.jsxs("div",{children:[e.jsx("h2",{className:"text-sm font-bold text-slate-800",children:y?y.title:"AI Chat"}),e.jsx("p",{className:"text-[11px] text-slate-400",children:"询问任何关于项目的问题"})]})]}),a.length>0&&e.jsxs("button",{onClick:H,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(gt,{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:[a.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(Ue,{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(b=>e.jsx("button",{onClick:()=>{var f;R(b),(f=P.current)==null||f.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:b},b))})]}),a.map(b=>e.jsx("div",{className:`flex ${b.role==="user"?"justify-end":"justify-start"}`,children:e.jsxs("div",{className:`max-w-[80%] ${b.role==="user"?"bg-blue-600 text-white rounded-2xl rounded-tr-md px-4 py-2.5":b.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:[b.role==="assistant"&&e.jsxs("div",{className:"flex items-center gap-1.5 mb-2",children:[e.jsx(Jt,{size:13,className:"text-blue-500"}),e.jsx("span",{className:"text-[11px] font-bold text-blue-600",children:"AI 助手"})]}),b.role==="assistant"&&!b.diff?e.jsx(mt,{content:b.content,className:"text-sm text-slate-700"}):e.jsx("p",{className:`text-sm leading-relaxed whitespace-pre-wrap ${b.role==="user"?"":"text-slate-600"}`,children:b.content}),b.diff&&b.diff.length>0&&e.jsx("div",{className:"space-y-2 mt-2",children:b.diff.map(f=>e.jsx(Yr,{d:f},f.field))})]})},b.id)),r&&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 思考中..."}),o.current&&e.jsx("button",{onClick:()=>{var b;return(b=o.current)==null?void 0:b.abort()},className:"ml-1 px-1.5 py-0.5 text-[10px] font-bold text-red-500 border border-red-200 rounded hover:bg-red-50 transition-colors",children:"停止"})]})})}),e.jsx("div",{ref:I})]})}),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:P,value:B,onChange:b=>R(b.target.value),onKeyDown:k,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:r}),e.jsx("button",{onClick:O,disabled:!B.trim()||r,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 换行"})]})})]})]})},Qr=28,en=22,tn=50,sn=11,an=10,ut={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 yt(t){return Math.min(tn,Math.max(en,Qr+t*2))}function ta(t,s){return t.length<=s?t:t.substring(0,s-1)+"…"}function ln(t,s,a,l){const r=new Map;for(const h of t)r.set(h.fromId,(r.get(h.fromId)||0)+1),r.set(h.toId,(r.get(h.toId)||0)+1);const i=[...r.keys()],c=[...new Set(i.map(h=>l[h]||"general"))].sort(),o=new Map,j=Math.ceil(Math.sqrt(c.length)),g=400;return c.forEach((h,y)=>{const x=y%j,m=Math.floor(y/j);o.set(h,{x:450+(x-(j-1)/2)*g,y:350+(m-(Math.ceil(c.length/j)-1)/2)*g})}),i.map(h=>{const y=l[h]||"general",x=o.get(y)||{x:450,y:350},m=Math.random()*2*Math.PI,u=40+Math.random()*80;return{id:h,label:s[h]||h,type:a[h]||"recipe",group:y,x:x.x+u*Math.cos(m),y:x.y+u*Math.sin(m),vx:0,vy:0,degree:r.get(h)||1}})}function rn(t,s,a=200){const l=t.map(c=>({...c})),r=new Map(l.map(c=>[c.id,c]));function i(){const c=new Map;for(const o of l){const j=c.get(o.group);j?(j.x+=o.x,j.y+=o.y,j.count++):c.set(o.group,{x:o.x,y:o.y,count:1})}for(const[,o]of c)o.x/=o.count,o.y/=o.count;return c}for(let c=0;c<a;c++){const o=1-c/a,j=18e3*o,g=.015,h=.8,y=i();for(let m=0;m<l.length;m++)for(let u=m+1;u<l.length;u++){const A=l[m],S=l[u];let I=S.x-A.x,P=S.y-A.y,B=Math.sqrt(I*I+P*P)||1;const R=yt(A.degree)+yt(S.degree)+60,K=Math.max(B,1),X=A.group===S.group?.6:1.4,$=j*X/(K*K),H=B<R?(R-B)*.5:0,C=$+H,p=I/K*C,O=P/K*C;A.vx-=p,A.vy-=O,S.vx+=p,S.vy+=O}for(const m of s){const u=r.get(m.fromId),A=r.get(m.toId);if(!u||!A)continue;let S=A.x-u.x,I=A.y-u.y,P=Math.sqrt(S*S+I*I)||1;const B=u.group===A.group?140:280,R=g*(P-B),K=S/P*R,X=I/P*R;u.vx+=K,u.vy+=X,A.vx-=K,A.vy-=X}const x=.008*o;for(const m of l){const u=y.get(m.group);u&&(m.vx+=(u.x-m.x)*x,m.vy+=(u.y-m.y)*x)}for(const m of l)m.vx*=h,m.vy*=h,m.x+=m.vx,m.y+=m.vy}return l}function nn(t,s,a,l,r,i,c=0){const o=a-t,j=l-s,g=Math.sqrt(o*o+j*j)||1,h=o/g,y=j/g,x=t+h*r,m=s+y*r,u=a-h*i,A=l-y*i;if(c===0)return`M${x},${m}L${u},${A}`;const S=(x+u)/2+-y*c,I=(m+A)/2+h*c;return`M${x},${m}Q${S},${I},${u},${A}`}const on=()=>{const[t,s]=n.useState([]),[a,l]=n.useState({}),[r,i]=n.useState({}),[c,o]=n.useState({}),[j,g]=n.useState(null),[h,y]=n.useState(!0),[x,m]=n.useState(null),[u,A]=n.useState(null),[S,I]=n.useState(null),[P,B]=n.useState(null),[R,K]=n.useState(!1),[X,$]=n.useState(null),[H,C]=n.useState(1),[p,O]=n.useState({x:0,y:0}),k=n.useRef(null),b=n.useRef(null),f=n.useRef(!1),w=n.useRef({x:0,y:0}),Z=async()=>{var v,ne;y(!0),m(null);try{const[ve,ce]=await Promise.all([re.getKnowledgeGraph(),re.getGraphStats()]);s(ve.edges||[]),l(ve.nodeLabels||{}),i(ve.nodeTypes||{}),o(ve.nodeCategories||{}),g(ce)}catch(ve){m(((ne=(v=ve.response)==null?void 0:v.data)==null?void 0:ne.error)||ve.message||"加载知识图谱失败")}finally{y(!1)}};n.useEffect(()=>{Z()},[]),n.useEffect(()=>{re.getDiscoverRelationsStatus().then(v=>{v.status==="running"&&(K(!0),$(`AI 分析中…(已运行 ${v.elapsed??0}s)`))}).catch(()=>{})},[]),n.useEffect(()=>{if(!R)return;let v=0;const ne=240,ve=setInterval(async()=>{if(v++,v>ne){clearInterval(ve),K(!1),$("轮询超时,任务可能仍在后台运行。请稍后刷新页面查看结果。");return}try{const ce=await re.getDiscoverRelationsStatus();if(ce.status==="done"){K(!1);const he=ce.discovered??0,d=ce.totalPairs??0,L=ce.batchErrors??0;he===0&&L===0?$(`分析完成,共检查 ${d} 对 Recipe,未发现关系。待 Recipe 数量增加后可再次尝试。`):he===0&&L>0?$(`分析完成,但 ${L} 个批次 AI 调用失败,未发现关系。请检查 AI Provider 配置。`):$(`发现 ${he} 条关系(共分析 ${d} 对${L>0?`,${L} 个批次失败`:""})`),Z()}else if(ce.status==="error"){K(!1);const he=ce.error||"未知错误";he.includes("AI Provider")||he.includes("API Key")?$(`AI 服务未配置: ${he}`):he.includes("超时")||he.includes("timeout")?$(`任务超时: ${he}`):$(`发现失败: ${he}`)}else ce.status==="running"&&$(`AI 分析中…(已运行 ${ce.elapsed??0}s)`)}catch{}},3e3);return()=>clearInterval(ve)},[R]);const q=n.useCallback(async()=>{var v,ne,ve;$(null);try{const ce=await re.discoverRelations();if(ce.status==="empty"){$(ce.message||"Recipe 数量不足,无法分析");return}if(ce.status==="timeout"){$(ce.error||"上次任务超时,请重试");return}if(ce.status==="running"){K(!0),$("AI 分析仍在进行中…");return}K(!0),$("AI 分析已启动,正在后台运行…")}catch(ce){const he=((ve=(ne=(v=ce==null?void 0:ce.response)==null?void 0:v.data)==null?void 0:ne.error)==null?void 0:ve.message)||ce.message||"未知错误";he.includes("ChatAgent")||he.includes("AI Provider")?$(`AI 服务不可用: ${he}`):$(`启动失败: ${he}`)}},[]),ue=n.useMemo(()=>{if(t.length===0)return[];const v=ln(t,a,r,c);return rn(v,t)},[t,a,r,c]),_=n.useMemo(()=>{const v=new Map;for(const ce of ue){const he=v.get(ce.group)||[];he.push(ce),v.set(ce.group,he)}const ne=[],ve=[...v.keys()].sort();for(const ce of ve){const he=v.get(ce);if(he.length===0)continue;let d=0,L=0;for(const G of he)d+=G.x,L+=G.y;d/=he.length,L/=he.length;let N=0,pe=0;for(const G of he){const oe=yt(G.degree);N=Math.max(N,Math.abs(G.x-d)+oe+35),pe=Math.max(pe,Math.abs(G.y-L)+oe+35)}ne.push({group:ce,cx:d,cy:L,rx:Math.max(N,60),ry:Math.max(pe,60),count:he.length})}return ne},[ue]),M=n.useMemo(()=>{const v=[...new Set(ue.map(ve=>ve.group))].sort(),ne={};return v.forEach((ve,ce)=>{ne[ve]=ns[ce%ns.length]}),ne},[ue]),ee=n.useMemo(()=>{if(ue.length===0)return{x:0,y:0,w:900,h:700};let v=1/0,ne=1/0,ve=-1/0,ce=-1/0;for(const he of ue){const d=yt(he.degree);v=Math.min(v,he.x-d-80),ne=Math.min(ne,he.y-d-40),ve=Math.max(ve,he.x+d+80),ce=Math.max(ce,he.y+d+40)}return{x:v,y:ne,w:ve-v,h:ce-ne}},[ue]),J=n.useMemo(()=>new Map(ue.map(v=>[v.id,v])),[ue]),{connectedEdgeIds:se,connectedNodeIds:V}=n.useMemo(()=>{const v=u||S;if(!v)return{connectedEdgeIds:new Set,connectedNodeIds:new Set};const ne=new Set,ve=new Set([v]);for(const ce of t)(ce.fromId===v||ce.toId===v)&&(ne.add(ce.id),ve.add(ce.fromId),ve.add(ce.toId));return{connectedEdgeIds:ne,connectedNodeIds:ve}},[u,S,t]),Q=n.useMemo(()=>{const v=new Map,ne=new Map;for(const ce of t){const he=[ce.fromId,ce.toId].sort().join("|"),d=v.get(he)||0;ne.set(ce.id,d),v.set(he,d+1)}const ve=new Map;for(const ce of t){const he=[ce.fromId,ce.toId].sort().join("|"),d=v.get(he)||1;if(d<=1){ve.set(ce.id,0);continue}const L=ne.get(ce.id)||0;ve.set(ce.id,(L-(d-1)/2)*40)}return ve},[t]),[ae,ye]=n.useState(new Set);n.useEffect(()=>{ye(new Set(t.map(v=>v.relation)))},[t]);const Se=n.useMemo(()=>t.filter(v=>ae.has(v.relation)),[t,ae]),De=v=>{ye(ne=>{const ve=new Set(ne);return ve.has(v)?ve.delete(v):ve.add(v),ve})},D=n.useCallback(v=>{v.button===0&&(f.current=!0,w.current={x:v.clientX,y:v.clientY})},[]),E=n.useCallback(v=>{if(!f.current)return;const ne=v.clientX-w.current.x,ve=v.clientY-w.current.y;w.current={x:v.clientX,y:v.clientY},O(ce=>({x:ce.x+ne,y:ce.y+ve}))},[]),xe=n.useCallback(()=>{f.current=!1},[]),Ie=n.useCallback(v=>{v.preventDefault();const ne=v.deltaY>0?-.1:.1;C(ve=>Math.min(3,Math.max(.2,ve+ne)))},[]),fe=v=>`kg-arrow-${v.replace(/[^a-z_]/g,"")}`;if(h)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(x)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:x}),e.jsx("button",{onClick:Z,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 等)。"}),X&&e.jsx("p",{className:`text-sm ${X.startsWith("发现失败")?"text-red-500":"text-green-600"}`,children:X}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("button",{onClick:q,disabled:R,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:R?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(Ue,{size:T.sm})," AI 发现关系"]})}),e.jsxs("button",{onClick:Z,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(pt,{size:T.sm})," 刷新"]})]})]});const Ae=[...new Set(t.map(v=>v.relation))].sort(),Ee=!!(u||S);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:T.lg,className:"text-blue-600"}),e.jsx("h2",{className:"text-lg font-bold text-slate-800",children:"知识图谱"}),j&&e.jsxs("span",{className:"text-xs text-slate-500 bg-slate-100 px-2 py-1 rounded-full",children:[ue.length," 节点 · ",j.totalEdges," 关系"]})]}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("button",{onClick:()=>C(v=>Math.min(v+.2,3)),className:"p-1.5 rounded-lg bg-slate-100 hover:bg-slate-200 transition-colors",title:"放大",children:e.jsx(ol,{size:T.sm})}),e.jsx("button",{onClick:()=>C(v=>Math.max(v-.2,.2)),className:"p-1.5 rounded-lg bg-slate-100 hover:bg-slate-200 transition-colors",title:"缩小",children:e.jsx(il,{size:T.sm})}),e.jsx("button",{onClick:()=>{C(1),O({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:T.sm})}),e.jsx("button",{onClick:Z,className:"p-1.5 rounded-lg bg-slate-100 hover:bg-slate-200 transition-colors",title:"刷新",children:e.jsx(pt,{size:T.sm})}),e.jsx("button",{onClick:q,disabled:R,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:R?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(Ue,{size:T.sm})," 发现关系"]})})]})]}),e.jsx("div",{className:"flex flex-wrap gap-1.5 mb-3 flex-shrink-0",children:Ae.map(v=>{var ne;return e.jsxs("button",{onClick:()=>De(v),className:`flex items-center gap-1 px-2 py-0.5 rounded-full text-[11px] font-medium transition-all border ${ae.has(v)?"border-transparent shadow-sm":"border-slate-200 bg-white text-slate-400 opacity-40"}`,style:ae.has(v)?{backgroundColor:(ut[v]||"#6b7280")+"18",color:ut[v]||"#6b7280"}:{},children:[e.jsx("span",{className:"w-2 h-2 rounded-full",style:{backgroundColor:ut[v]||"#6b7280"}}),rs[v]||v,((ne=j==null?void 0:j.byRelation)==null?void 0:ne[v])!=null&&e.jsxs("span",{className:"opacity-60",children:["(",j.byRelation[v],")"]})]},v)})}),e.jsxs("div",{ref:b,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:f.current?"grabbing":"grab"},onWheel:Ie,children:[e.jsxs("svg",{ref:k,width:"100%",height:"100%",viewBox:`${ee.x} ${ee.y} ${ee.w} ${ee.h}`,onMouseDown:D,onMouseMove:E,onMouseUp:xe,onMouseLeave:xe,style:{transform:`scale(${H}) translate(${p.x/H}px, ${p.y/H}px)`},children:[e.jsxs("defs",{children:[Ae.map(v=>e.jsx("marker",{id:fe(v),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:ut[v]||"#6b7280"})},v)),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:_.map(v=>{const ne=M[v.group]||ns[0];return e.jsxs("g",{children:[e.jsx("ellipse",{cx:v.cx,cy:v.cy,rx:v.rx,ry:v.ry,fill:ne.bg,stroke:ne.border,strokeWidth:1.5,strokeDasharray:"6,4",opacity:.6}),e.jsxs("text",{x:v.cx,y:v.cy-v.ry+14,textAnchor:"middle",fontSize:11,fontWeight:600,fill:ne.text,opacity:.8,style:{pointerEvents:"none",userSelect:"none"},children:[v.group||"general"," (",v.count,")"]})]},v.group)})}),e.jsx("g",{children:Se.map(v=>{const ne=J.get(v.fromId),ve=J.get(v.toId);if(!ne||!ve)return null;const ce=Ee?se.has(v.id):!1,he=P===v.id,d=Ee?ce?.85:.06:he?.9:.35,L=yt(ne.degree),N=yt(ve.degree),pe=Q.get(v.id)||0,G=nn(ne.x,ne.y,ve.x,ve.y,L,N,pe);return e.jsxs("g",{children:[e.jsx("path",{d:G,fill:"none",stroke:"transparent",strokeWidth:12,onMouseEnter:()=>B(v.id),onMouseLeave:()=>B(null),style:{cursor:"pointer"}}),e.jsx("path",{d:G,fill:"none",stroke:ut[v.relation]||"#6b7280",strokeWidth:he||ce?2:1.2,opacity:d,markerEnd:`url(#${fe(v.relation)})`,strokeDasharray:v.relation==="related"?"6,3":void 0,style:{transition:"opacity 0.25s, stroke-width 0.15s",pointerEvents:"none"}}),he&&(()=>{const oe=(ne.x+ve.x)/2,F=(ne.y+ve.y)/2;return e.jsxs("g",{children:[e.jsx("rect",{x:oe-24,y:F-16,width:48,height:18,rx:4,fill:"white",stroke:ut[v.relation]||"#6b7280",strokeWidth:.8,opacity:.95}),e.jsx("text",{x:oe,y:F-4,textAnchor:"middle",fontSize:9,fontWeight:600,fill:ut[v.relation]||"#6b7280",children:rs[v.relation]||v.relation})]})})()]},v.id)})}),e.jsx("g",{children:ue.map(v=>{const ne=yt(v.degree),ve=u===v.id,ce=Ee&&V.has(v.id),he=ve||v.id===S,d=Ee&&!ce,L=d?.12:1,N=M[v.group]||ns[0],pe=he?N.border:N.bg,G=he?N.text:N.border,oe=he?"#ffffff":N.text,F=he?N.text:"#64748b";return e.jsxs("g",{onClick:te=>{te.stopPropagation(),A(ve?null:v.id)},onMouseEnter:()=>I(v.id),onMouseLeave:()=>I(null),style:{cursor:"pointer",transition:"opacity 0.25s"},opacity:L,filter:he?"url(#kg-glow)":void 0,children:[e.jsx("circle",{cx:v.x,cy:v.y,r:ne,fill:pe,stroke:G,strokeWidth:he?2.5:1.5}),e.jsx("text",{x:v.x,y:v.y+4,textAnchor:"middle",fontSize:Math.min(sn,ne*.7),fill:oe,fontWeight:700,style:{pointerEvents:"none",userSelect:"none"},children:ta(v.label,4).toUpperCase()}),e.jsx("text",{x:v.x,y:v.y+ne+14,textAnchor:"middle",fontSize:an,fill:F,fontWeight:he?600:400,style:{pointerEvents:"none",userSelect:"none"},children:ta(v.label,18)}),v.degree>=3&&!d&&e.jsxs("g",{children:[e.jsx("circle",{cx:v.x+ne*.7,cy:v.y-ne*.7,r:8,fill:"#3b82f6",stroke:"white",strokeWidth:1.5}),e.jsx("text",{x:v.x+ne*.7,y:v.y-ne*.7+3.5,textAnchor:"middle",fontSize:8,fill:"white",fontWeight:700,style:{pointerEvents:"none"},children:v.degree})]})]},v.id)})})]}),u&&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:()=>A(null),children:"取消选中"})]}),u&&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(cl,{size:14,className:"text-blue-500"}),e.jsx("h3",{className:"font-semibold text-sm text-slate-800",children:a[u]||u}),e.jsxs("span",{className:"text-[10px] text-slate-400 ml-auto",children:["ID: ",u]})]}),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(v=>v.fromId===u&&ae.has(v.relation)).map(v=>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:ut[v.relation]||"#6b7280"}}),e.jsx("span",{className:"text-slate-500",children:rs[v.relation]||v.relation}),e.jsx("span",{className:"text-slate-400",children:"→"}),e.jsx("button",{className:"text-blue-600 hover:underline truncate",onClick:()=>A(v.toId),children:a[v.toId]||v.toId.substring(0,16)})]},v.id)),t.filter(v=>v.fromId===u&&ae.has(v.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(v=>v.toId===u&&ae.has(v.relation)).map(v=>e.jsxs("li",{className:"flex items-center gap-1.5",children:[e.jsx("button",{className:"text-blue-600 hover:underline truncate",onClick:()=>A(v.fromId),children:a[v.fromId]||v.fromId.substring(0,16)}),e.jsx("span",{className:"text-slate-400",children:"→"}),e.jsx("span",{className:"text-slate-500",children:rs[v.relation]||v.relation}),e.jsx("span",{className:"w-1.5 h-1.5 rounded-full flex-shrink-0",style:{backgroundColor:ut[v.relation]||"#6b7280"}})]},v.id)),t.filter(v=>v.toId===u&&ae.has(v.relation)).length===0&&e.jsx("li",{className:"text-slate-400",children:"无"})]})]})]})]})]})},ct={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}},Dt={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:ht},fact:{label:"Fact",color:"text-cyan-700",bg:"bg-cyan-50",border:"border-cyan-200",icon:Ye}},cn={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:ua}]};function Pt(t){if(!t)return"";const s=t<1e12?t*1e3:t,a=new Date(s);if(isNaN(a.getTime())||a.getFullYear()<2e3)return"";const r=Date.now()-s;if(r<0)return a.toLocaleDateString("zh-CN");const i=Math.floor(r/6e4);if(i<1)return"刚刚";if(i<60)return`${i} 分钟前`;const c=Math.floor(i/60);if(c<24)return`${c} 小时前`;const o=Math.floor(c/24);return o<7?`${o} 天前`:a.toLocaleDateString("zh-CN")}function dn(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 xn(t,s=4){return t?Es(t).split(`
103
103
  `).slice(0,s).join(`
104
- `):""}const sa={"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"}},mn=({onRefresh:t,idTitleMap:s})=>{const[a,l]=n.useState([]),[r,i]=n.useState(null),[c,o]=n.useState(!0),[j,g]=n.useState(1),[h,y]=n.useState(20),[x,m]=n.useState(0),[u,A]=n.useState(""),[S,I]=n.useState(""),[P,B]=n.useState(""),[R,K]=n.useState(""),[X,$]=n.useState(""),{isWide:H,toggle:C}=Ts(),[p,O]=n.useState(null),[k,b]=n.useState(!1),[f,w]=n.useState(new Set),[Z,q]=n.useState(!1),ue=n.useRef(!0);n.useEffect(()=>(ue.current=!0,()=>{ue.current=!1}),[]);const M=n.useCallback(async()=>{var D;o(!0);try{const _=await re.knowledgeList({page:j,limit:h,lifecycle:u||void 0,kind:S||void 0,category:P||void 0,keyword:R||void 0});ue.current&&(l(_.data||[]),m(((D=_.pagination)==null?void 0:D.total)||0))}catch(_){le((_==null?void 0:_.message)||"加载知识条目失败",{title:"加载失败",type:"error"})}finally{ue.current&&o(!1)}},[j,h,u,S,P,R]),T=n.useCallback(async()=>{try{const D=await re.knowledgeStats();ue.current&&i(D)}catch{}},[]);n.useEffect(()=>{M()},[M]),n.useEffect(()=>{T()},[T]),n.useEffect(()=>{const D=setTimeout(()=>{K(X),g(1)},300);return()=>clearTimeout(D)},[X]),n.useEffect(()=>{g(1)},[u,S,P]);const ee=n.useCallback(()=>{M(),T(),t==null||t()},[M,T,t]),J=n.useMemo(()=>{const D=new Map;if(s)for(const[_,xe]of Object.entries(s))D.set(_,xe);for(const _ of a)_.id&&_.title&&D.set(_.id,_.title);return D},[a,s]),se=async(D,_,xe)=>{var Ie,fe,Ae,Oe;b(!0);try{const _e=await re.knowledgeLifecycle(D.id,_,xe);le(`${D.title} → ${((Ie=ct[_e.lifecycle])==null?void 0:Ie.label)||_e.lifecycle}`,{title:"操作成功"}),l(v=>v.map(ne=>ne.id===D.id?_e:ne)),(p==null?void 0:p.id)===D.id&&O(_e),T()}catch(_e){le(((Oe=(Ae=(fe=_e==null?void 0:_e.response)==null?void 0:fe.data)==null?void 0:Ae.error)==null?void 0:Oe.message)||(_e==null?void 0:_e.message)||"操作失败",{title:"操作失败",type:"error"})}finally{ue.current&&b(!1)}},V=async D=>{if(confirm(`确定删除「${D.title}」?此操作不可恢复。`))try{await re.knowledgeDelete(D.id),le(`已删除「${D.title}」`,{title:"删除成功"}),l(_=>_.filter(xe=>xe.id!==D.id)),(p==null?void 0:p.id)===D.id&&O(null),T()}catch(_){le((_==null?void 0:_.message)||"删除失败",{title:"删除失败",type:"error"})}},Q=async()=>{if(f.size!==0){q(!0);try{const D=await re.knowledgeBatchPublish([...f]);le(`发布 ${D.successCount} 条,失败 ${D.failureCount} 条`,{title:"批量发布"}),w(new Set),ee()}catch(D){le((D==null?void 0:D.message)||"批量发布失败",{title:"操作失败",type:"error"})}finally{q(!1)}}},ae=async()=>{q(!0);try{const _=((await re.knowledgeList({lifecycle:"pending",limit:500})).data||[]).filter(Ie=>Ie.autoApprovable).map(Ie=>Ie.id);if(_.length===0){le("当前没有可自动通过的待审核条目",{title:"无可发布项"});return}const xe=await re.knowledgeBatchPublish(_);le(`已发布 ${xe.successCount} 条可自动通过的条目`,{title:"批量发布完成"}),ee()}catch(D){le((D==null?void 0:D.message)||"批量发布失败",{title:"操作失败",type:"error"})}finally{q(!1)}},ye=D=>{w(_=>{const xe=new Set(_);return xe.has(D)?xe.delete(D):xe.add(D),xe})},Se=()=>{f.size===a.length?w(new Set):w(new Set(a.map(D=>D.id)))},De=(D,_)=>{const xe=prompt("请输入废弃原因:");xe&&se(D,_,xe)};return e.jsxs("div",{className:"space-y-4",children:[r&&e.jsx("div",{className:"grid grid-cols-3 gap-3",children:Object.entries(ct).map(([D,_])=>{const xe=r[D]||0,Ie=_.icon;return e.jsxs("button",{onClick:()=>{A(u===D?"":D)},className:`flex items-center gap-2 px-3 py-2 rounded-lg border transition-all text-left ${u===D?`${_.bg} ${_.border} ${_.color} ring-1 ring-current`:"bg-white border-slate-200 text-slate-600 hover:bg-slate-50"}`,children:[e.jsx(Ie,{size:14}),e.jsxs("div",{children:[e.jsx("div",{className:"text-xs font-medium",children:_.label}),e.jsx("div",{className:"text-lg font-bold",children:xe})]})]},D)})}),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(dt,{className:"absolute left-3 top-1/2 -translate-y-1/2 text-slate-400",size:16}),e.jsx("input",{type:"text",placeholder:"搜索知识条目...",value:X,onChange:D=>$(D.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(Dt).map(([D,_])=>{const xe=_.icon;return e.jsxs("button",{onClick:()=>I(S===D?"":D),className:`flex items-center gap-1 px-2.5 py-1.5 rounded-md text-xs font-medium border transition-all ${S===D?`${_.bg} ${_.border} ${_.color}`:"bg-white border-slate-200 text-slate-500 hover:bg-slate-50"}`,children:[e.jsx(xe,{size:12}),_.label]},D)})}),e.jsxs("select",{value:P,onChange:D=>B(D.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(D=>e.jsx("option",{value:D,children:D},D))]}),e.jsx("button",{onClick:ee,className:"p-2 rounded-md text-slate-400 hover:bg-slate-100",title:"刷新",children:e.jsx(pt,{size:16})}),f.size>0&&e.jsxs("div",{className:"flex items-center gap-2 ml-auto",children:[e.jsxs("span",{className:"text-xs text-slate-500",children:["已选 ",f.size," 条"]}),e.jsx("button",{onClick:Q,disabled:Z,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:Z?e.jsx(Ee,{size:12,className:"animate-spin"}):"批量发布"}),e.jsx("button",{onClick:()=>w(new Set),className:"p-1 text-slate-400 hover:text-slate-600",children:e.jsx(Ke,{size:14})})]}),f.size===0&&e.jsxs("button",{onClick:ae,disabled:Z,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:[Z?e.jsx(Ee,{size:12,className:"animate-spin"}):e.jsx(Je,{size:12}),"快速批量发布"]})]}),c?e.jsxs("div",{className:"flex items-center justify-center py-20 text-slate-400",children:[e.jsx(Ee,{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(Ye,{size:48,className:"mb-4 opacity-30"}),e.jsx("p",{className:"text-sm",children:"暂无知识条目"}),(R||u||S||P)&&e.jsx("button",{onClick:()=>{$(""),A(""),I(""),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:f.size===a.length&&a.length>0,onChange:Se,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:["共 ",x," 条"]})]}),e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:a.map(D=>{var Oe,_e,v,ne,ve,ce;const _=ct[D.lifecycle]||ct.pending,xe=Dt[D.kind]||Dt.pattern,Ie=_.icon,fe=xe.icon,Ae=dn((Oe=D.reasoning)==null?void 0:Oe.confidence);return e.jsxs("div",{onClick:()=>O(D),className:`group bg-white rounded-xl border shadow-sm hover:shadow-md cursor-pointer transition-all overflow-hidden ${(p==null?void 0:p.id)===D.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:f.has(D.id),onChange:he=>{he.stopPropagation(),ye(D.id)},onClick:he=>he.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 ${_.bg} ${_.color} ${_.border} border`,children:[e.jsx(Ie,{size:10}),_.label]}),e.jsxs("span",{className:`inline-flex items-center gap-1 px-1.5 py-0.5 rounded text-[10px] font-medium ${xe.bg} ${xe.color} ${xe.border} border`,children:[e.jsx(fe,{size:10}),xe.label]}),D.category&&e.jsx("span",{className:"text-[10px] text-slate-400",children:D.category}),e.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded ${Ae.bg} ${Ae.text}`,children:((_e=D.reasoning)==null?void 0:_e.confidence)!=null?`${Math.round(D.reasoning.confidence*100)}%`:"—"}),D.autoApprovable&&D.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(Je,{size:9}),"可自动通过"]})]}),e.jsx("h3",{className:"text-sm font-bold text-slate-900 mb-1 break-words leading-snug",children:D.title}),(D.description||((v=D.content)==null?void 0:v.rationale))&&e.jsx("p",{className:"text-xs text-slate-500 line-clamp-2 leading-relaxed",children:D.description||((ne=D.content)==null?void 0:ne.rationale)||""}),((ve=D.content)==null?void 0:ve.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:xn(D.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:[(ce=D.tags)==null?void 0:ce.slice(0,3).map(he=>e.jsx("span",{className:"text-[10px] px-1.5 py-0.5 rounded bg-blue-50 text-blue-600 border border-blue-100",children:he},he)),D.tags&&D.tags.length>3&&e.jsxs("span",{className:"text-[10px] text-slate-400",children:["+",D.tags.length-3]}),e.jsxs("span",{className:"text-[10px] text-slate-300 ml-auto",children:[D.trigger&&e.jsx("span",{className:"text-blue-400 mr-2",children:D.trigger}),D.source&&e.jsx("span",{className:"mr-2",children:D.source}),Pt(D.updatedAt)]})]})]},D.id)})}),e.jsx(Ms,{currentPage:j,totalPages:Math.ceil(x/h),onPageChange:g,pageSize:h,onPageSizeChange:D=>{y(D),g(1)},totalItems:x})]}),p&&(()=>{var ce,he,d,L,N,pe,W,oe;const D=ct[p.lifecycle]||ct.pending,_=D.icon,xe=Dt[p.kind]||Dt.pattern,Ie=lt[p.category||""]||lt.All||{};sa[p.source||""]||p.source;const fe=p.reasoning,Ae=fe&&(fe.whyStandard||fe.sources&&fe.sources.length>0||fe.confidence!=null),Oe=a.findIndex(F=>F.id===p.id),_e=Oe>0,v=Oe<a.length-1,ne=()=>{_e&&O(a[Oe-1])},ve=()=>{v&&O(a[Oe+1])};return e.jsxs(Ve,{className:"z-30 flex justify-end",onClick:()=>O(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 ${H?"w-[960px] max-w-[92vw]":"w-[700px] max-w-[92vw]"}`,style:{animation:"slideInRight 0.25s ease-out"},onClick:F=>F.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:p.title})}),e.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[e.jsx("button",{onClick:ne,disabled:!_e,className:"p-1.5 hover:bg-slate-100 rounded-lg transition-colors disabled:opacity-30",title:"上一条",children:e.jsx(Zt,{size:E.md})}),e.jsxs("span",{className:"text-xs text-slate-400 tabular-nums",children:[Oe+1,"/",a.length]}),e.jsx("button",{onClick:ve,disabled:!v,className:"p-1.5 hover:bg-slate-100 rounded-lg transition-colors disabled:opacity-30",title:"下一条",children:e.jsx(st,{size:E.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:H?"收窄":"展宽",children:H?e.jsx(Is,{size:E.md}):e.jsx(hs,{size:E.md})}),e.jsx("button",{onClick:()=>{V(p),O(null)},className:"p-1.5 hover:bg-red-50 rounded-lg text-red-500 transition-colors",title:"删除",children:e.jsx(tt,{size:E.md})}),e.jsx("button",{onClick:()=>O(null),className:"p-1.5 hover:bg-slate-100 rounded-lg transition-colors",children:e.jsx(Ke,{size:E.md})})]})]}),e.jsxs("div",{className:"flex-1 overflow-y-auto",children:[p.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:p.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 ${D.bg} ${D.color} ${D.border} border`,children:[e.jsx(_,{size:10}),D.label]}),e.jsxs("span",{className:`inline-flex items-center gap-1 px-1.5 py-0.5 rounded text-[10px] font-medium ${xe.bg} ${xe.color} ${xe.border} border`,children:[St.createElement(xe.icon,{size:10}),xe.label]}),e.jsx("span",{className:`text-[10px] font-bold px-1.5 py-0.5 rounded uppercase flex items-center gap-1 border ${(Ie==null?void 0:Ie.bg)||"bg-slate-50"} ${(Ie==null?void 0:Ie.color)||"text-slate-400"} ${(Ie==null?void 0:Ie.border)||"border-slate-100"}`,children:p.category||"general"}),p.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:p.knowledgeType}),p.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:p.language}),p.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:p.trigger})]}),e.jsxs("div",{className:"flex flex-wrap gap-x-5 gap-y-2 text-xs",children:[(()=>{const F=[];return p.scope&&F.push({icon:wt,iconClass:"text-teal-400",label:"范围",value:p.scope==="universal"?"通用":p.scope==="project-specific"?"项目级":p.scope==="module-level"?"模块级":p.scope}),p.complexity&&F.push({icon:Qe,iconClass:"text-orange-400",label:"复杂度",value:p.complexity==="advanced"?"高级":p.complexity==="intermediate"?"中级":p.complexity==="beginner"?"初级":p.complexity}),p.source&&p.source!=="unknown"&&F.push({icon:wt,iconClass:"text-violet-400",label:"来源",value:(sa[p.source||""]||{label:p.source||"-"}).label}),p.createdAt&&F.push({icon:it,iconClass:"text-slate-400",label:"创建",value:Pt(p.createdAt)}),p.updatedAt&&F.push({icon:it,iconClass:"text-slate-400",label:"更新",value:Pt(p.updatedAt)}),p.publishedAt&&F.push({icon:es,iconClass:"text-emerald-400",label:"发布",value:Pt(p.publishedAt)}),F.map((te,ge)=>{const G=te.icon;return e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(G,{size:11,className:`${te.iconClass} shrink-0`}),e.jsx("span",{className:"text-slate-400",children:te.label}),e.jsx("span",{className:`font-medium text-slate-600 ${te.mono?"font-mono text-[11px]":""}`,children:te.value})]},ge)})})(),e.jsxs("div",{className:"flex items-center gap-1.5 basis-full mt-0.5",children:[e.jsx(Gt,{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:p.id})]}),p.sourceFile&&e.jsxs("div",{className:"flex items-center gap-1.5 basis-full",children:[e.jsx(Et,{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:p.sourceFile})]})]})]}),p.tags&&p.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"}),p.tags.map((F,te)=>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:F},te))]}),p.relations&&Object.entries(p.relations).some(([,F])=>Array.isArray(F)&&F.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($s,{size:12,className:"text-purple-400"}),e.jsx("label",{className:"text-[10px] font-bold text-slate-400 uppercase",children:"关联知识"}),(()=>{const F=Object.values(p.relations).flat().length;return F>0?e.jsx("span",{className:"text-[9px] bg-purple-100 text-purple-600 px-1.5 py-0.5 rounded-full font-bold",children:F}):null})()]}),e.jsx("div",{className:"space-y-1.5",children:Object.entries(p.relations).map(([F,te])=>!Array.isArray(te)||te.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:F}),e.jsx("div",{className:"flex flex-wrap gap-1",children:te.map((ge,G)=>{const be=ge.target||(typeof ge=="string"?ge:JSON.stringify(ge)),Re=J.get(be)||be;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:be,children:Re},G)})})]},F))})]}),p.stats&&Object.values(p.stats).some(F=>F>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:((ce=p.stats)==null?void 0:ce.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:((he=p.stats)==null?void 0:he.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:((d=p.stats)==null?void 0:d.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:((L=p.stats)==null?void 0:L.searchHits)??0}),e.jsx("div",{className:"text-[10px] text-blue-500 font-medium",children:"搜索"})]})]}),(p.stats.views>0||p.stats.applications>0)&&e.jsxs("div",{className:"flex items-center gap-4 mt-2 text-[10px] text-slate-400",children:[e.jsxs("span",{children:["浏览: ",p.stats.views]}),e.jsxs("span",{children:["应用: ",p.stats.applications]})]})]}),Ae&&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(ht,{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:[fe.whyStandard&&!/^Submitted via /i.test(fe.whyStandard)&&e.jsx("p",{className:"text-sm text-slate-700 leading-relaxed",children:fe.whyStandard}),fe.sources&&fe.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:"来源:"}),fe.sources.map((F,te)=>e.jsx("code",{className:"text-[10px] px-2 py-0.5 bg-white border border-amber-200 rounded text-amber-700 font-mono",children:F},te))]}),fe.confidence!=null&&fe.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((fe.confidence??0)*100)}%`}})}),e.jsxs("span",{className:"text-[10px] font-bold text-amber-600",children:[Math.round((fe.confidence??0)*100),"%"]})]}),fe.alternatives&&fe.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:"备选:"}),fe.alternatives.map((F,te)=>e.jsx("span",{className:"text-[10px] px-1.5 py-0.5 bg-slate-100 border border-slate-200 rounded text-slate-600",children:F},te))]})]})]}),p.quality&&p.quality.grade&&p.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 ${p.quality.grade==="A"?"text-emerald-600":p.quality.grade==="B"?"text-blue-600":p.quality.grade==="C"?"text-amber-600":p.quality.grade==="D"?"text-orange-600":"text-slate-400"}`,children:p.quality.grade}),e.jsxs("div",{className:"flex-1 grid grid-cols-3 gap-2 text-[10px]",children:[p.quality.completeness!=null&&p.quality.completeness>0&&e.jsxs("div",{className:"text-center",children:[e.jsx("div",{className:"font-bold text-slate-700",children:p.quality.completeness.toFixed(2)}),e.jsx("div",{className:"text-slate-400",children:"完整性"})]}),p.quality.adaptation!=null&&p.quality.adaptation>0&&e.jsxs("div",{className:"text-center",children:[e.jsx("div",{className:"font-bold text-slate-700",children:p.quality.adaptation.toFixed(2)}),e.jsx("div",{className:"text-slate-400",children:"适配度"})]}),p.quality.documentation!=null&&p.quality.documentation>0&&e.jsxs("div",{className:"text-center",children:[e.jsx("div",{className:"font-bold text-slate-700",children:p.quality.documentation.toFixed(2)}),e.jsx("div",{className:"text-slate-400",children:"文档度"})]})]})]})]}),p.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:p.description})]}),((N=p.content)==null?void 0:N.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(et,{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(mt,{content:p.content.markdown})})})]}),p.headers&&p.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:p.headers.map((F,te)=>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:F},te))})]}),((pe=p.content)==null?void 0:pe.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(xt,{size:11,className:"text-emerald-500"})," 代码 / 标准用法"]}),e.jsx(rt,{code:p.content.pattern,language:p.language==="objc"?"objectivec":p.language,showLineNumbers:!0})]}),(p.doClause||p.whenClause||p.dontClause||p.topicHint||p.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(Qe,{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:[p.topicHint&&e.jsxs("div",{children:[e.jsx("span",{className:"text-indigo-500 font-medium",children:"Topic:"}),e.jsx("span",{className:"text-slate-700",children:p.topicHint})]}),p.whenClause&&e.jsxs("div",{children:[e.jsx("span",{className:"text-blue-500 font-medium",children:"When:"}),e.jsx("span",{className:"text-slate-700",children:p.whenClause})]}),p.doClause&&e.jsxs("div",{children:[e.jsx("span",{className:"text-emerald-500 font-medium",children:"Do:"}),e.jsx("span",{className:"text-slate-700",children:p.doClause})]}),p.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:p.dontClause})]}),p.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:p.coreCode,language:p.language==="objc"?"objectivec":p.language||"text"})})]})]})]}),((W=p.content)==null?void 0:W.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:p.content.rationale})})]}),((oe=p.content)==null?void 0:oe.steps)&&p.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:p.content.steps.map((F,te)=>{if(typeof F=="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:te+1}),e.jsx("p",{className:"text-xs text-slate-700 leading-relaxed",children:F})]},te);const ge=typeof F.title=="string"?F.title:"",G=typeof F.description=="string"?F.description:"",be=typeof F.code=="string"?F.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:te+1}),ge&&e.jsx("span",{className:"text-xs font-bold text-slate-700",children:ge})]}),G&&e.jsx("p",{className:"text-xs text-slate-600 ml-7 leading-relaxed",children:G}),be&&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:be})]},te)})})]}),p.constraints&&(()=>{var ge,G,be,Re,Te,Me,qe,Ge;const F=p.constraints,te=(((ge=F.guards)==null?void 0:ge.length)||0)+(((G=F.boundaries)==null?void 0:G.length)||0)+(((be=F.preconditions)==null?void 0:be.length)||0)+(((Re=F.sideEffects)==null?void 0:Re.length)||0);return te?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:te})]}),e.jsxs("div",{className:"space-y-1.5 text-xs text-slate-600",children:[(Te=F.guards)==null?void 0:Te.map((U,$e)=>e.jsxs("div",{className:"flex gap-1.5 items-start",children:[e.jsx("span",{className:`text-xs mt-0.5 ${U.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:U.pattern}),U.message&&e.jsxs("span",{className:"text-[10px] text-slate-400",children:["— ",U.message]})]},$e)),(Me=F.boundaries)==null?void 0:Me.map((U,$e)=>e.jsxs("div",{className:"flex gap-1.5",children:[e.jsx("span",{className:"text-orange-400",children:"●"}),U]},$e)),(qe=F.preconditions)==null?void 0:qe.map((U,$e)=>e.jsxs("div",{className:"flex gap-1.5",children:[e.jsx("span",{className:"text-blue-400",children:"◆"}),U]},$e)),(Ge=F.sideEffects)==null?void 0:Ge.map((U,$e)=>e.jsxs("div",{className:"flex gap-1.5",children:[e.jsx("span",{className:"text-pink-400",children:"⚡"}),U]},$e))]})]}):null})(),p.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(ht,{size:11,className:"text-cyan-400"})," AI 洞察"]}),e.jsx("p",{className:"text-sm text-slate-600 leading-relaxed",children:p.aiInsight})]}),(()=>{const F=Array.isArray(p.lifecycleHistory)?p.lifecycleHistory:(()=>{try{const te=typeof p.lifecycleHistory=="string"?JSON.parse(p.lifecycleHistory):null;return Array.isArray(te)?te:[]}catch{return[]}})();return F.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:F.map((te,ge)=>{const G=ct[te.from]||ct.pending,be=ct[te.to]||ct.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:Pt(te.at)}),e.jsx("span",{className:`${G.color}`,children:G.label}),e.jsx("span",{className:"text-slate-300",children:"→"}),e.jsx("span",{className:`${be.color} font-medium`,children:be.label}),e.jsxs("span",{className:"text-slate-400 ml-auto",children:["by ",te.by]})]},ge)})})]}):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:()=>{V(p),O(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(tt,{size:14})," 删除"]})}),e.jsx("div",{className:"flex items-center gap-2",children:(cn[p.lifecycle]||[]).map(F=>{const te=F.icon;return e.jsxs("button",{onClick:()=>F.needsReason?De(p,F.action):se(p,F.action),disabled:k,className:`flex items-center gap-1.5 px-4 py-2 rounded-lg text-xs font-bold border transition-colors disabled:opacity-50 ${F.bg} ${F.color} border-current/20`,children:[k?e.jsx(Ee,{size:14,className:"animate-spin"}):e.jsx(te,{size:14}),F.label]},F.action)})})]})]})]})})()]})},os={manual:{label:"手动",color:"bg-slate-100 text-slate-600",icon:ma},"user-ai":{label:"AI 协助",color:"bg-violet-100 text-violet-600",icon:Ue},"system-ai":{label:"自动",color:"bg-amber-100 text-amber-600",icon:Yt},"external-ai":{label:"外部 AI",color:"bg-cyan-100 text-cyan-600",icon:zs}},un=({onRefresh:t,signalSuggestionCount:s=0,onSuggestionCountChange:a})=>{const[l,r]=n.useState([]),[i,c]=n.useState(!0),[o,j]=n.useState(null),[g,h]=n.useState(!1),[y,x]=n.useState(!1),[m,u]=n.useState("all"),[A,S]=n.useState(!1),[I,P]=n.useState([]),[B,R]=n.useState(!1),[K,X]=n.useState(!1),[$,H]=n.useState(null),[C,p]=n.useState(!1),[O,k]=n.useState(""),[b,f]=n.useState(!1),[w,Z]=n.useState(!1),[q,ue]=n.useState(!1),M=n.useCallback(async()=>{var _;c(!0);try{const xe=await re.listSkills();r(xe.skills||[])}catch(xe){((_=xe.response)==null?void 0:_.status)!==404&&le(xe.message||"",{title:"获取 Skills 列表失败",type:"error"}),r([])}finally{c(!1)}},[]);n.useEffect(()=>{M()},[M]);const T=async _=>{if((o==null?void 0:o.skillName)===_){j(null);return}p(!1),Z(!1),h(!0);try{const xe=await re.loadSkill(_);j(xe)}catch{le(`"${_}" 不存在或读取出错`,{title:"加载 Skill 失败",type:"error"})}finally{h(!1)}},ee=()=>{o!=null&&o.content&&(navigator.clipboard.writeText(o.content),S(!0),setTimeout(()=>S(!1),2e3))},J=()=>{o&&(k(o.content),p(!0))},se=()=>{p(!1),k("")},V=async()=>{if(!(!o||!O.trim())){f(!0);try{await re.updateSkill(o.skillName,{content:O}),le("已保存",{title:`Skill "${o.skillName}" 更新成功`}),p(!1);const _=await re.loadSkill(o.skillName);j(_)}catch(_){le(_.message||"",{title:"更新 Skill 失败",type:"error"})}finally{f(!1)}}},Q=async()=>{if(o){ue(!0);try{await re.deleteSkill(o.skillName),le("已删除",{title:`Skill "${o.skillName}" 删除成功`}),j(null),Z(!1),p(!1),M(),t==null||t()}catch(_){le(_.message||"",{title:"删除 Skill 失败",type:"error"})}finally{ue(!1)}}},ae=async()=>{R(!0),X(!0);try{const[_,xe]=await Promise.allSettled([re.suggestSkills(),re.getSignalStatus()]),Ie=_.status==="fulfilled"?_.value.suggestions||[]:[],fe=xe.status==="fulfilled"?xe.value.suggestions||[]:[],Ae=new Map;for(const _e of Ie)Ae.set(_e.name,_e);for(const _e of fe)Ae.set(_e.name,{...Ae.get(_e.name),..._e});const Oe=[...Ae.values()];P(Oe),a==null||a(Oe.length)}catch(_){le(_.message||"",{title:"获取 Skill 推荐失败",type:"error"}),P([]),a==null||a(0)}finally{R(!1)}};n.useEffect(()=>{s>0&&I.length===0&&!K&&ae()},[]);const ye=async _=>{H(_.name);try{const xe=_.description||_.rationale||_.name,Ie=`请为以下场景创建一个 Skill 文档:
104
+ `):""}const sa={"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"}},mn=({onRefresh:t,idTitleMap:s})=>{const[a,l]=n.useState([]),[r,i]=n.useState(null),[c,o]=n.useState(!0),[j,g]=n.useState(1),[h,y]=n.useState(20),[x,m]=n.useState(0),[u,A]=n.useState(""),[S,I]=n.useState(""),[P,B]=n.useState(""),[R,K]=n.useState(""),[X,$]=n.useState(""),{isWide:H,toggle:C}=Ms(),[p,O]=n.useState(null),[k,b]=n.useState(!1),[f,w]=n.useState(new Set),[Z,q]=n.useState(!1),ue=n.useRef(!0);n.useEffect(()=>(ue.current=!0,()=>{ue.current=!1}),[]);const _=n.useCallback(async()=>{var D;o(!0);try{const E=await re.knowledgeList({page:j,limit:h,lifecycle:u||void 0,kind:S||void 0,category:P||void 0,keyword:R||void 0});ue.current&&(l(E.data||[]),m(((D=E.pagination)==null?void 0:D.total)||0))}catch(E){le((E==null?void 0:E.message)||"加载知识条目失败",{title:"加载失败",type:"error"})}finally{ue.current&&o(!1)}},[j,h,u,S,P,R]),M=n.useCallback(async()=>{try{const D=await re.knowledgeStats();ue.current&&i(D)}catch{}},[]);n.useEffect(()=>{_()},[_]),n.useEffect(()=>{M()},[M]),n.useEffect(()=>{const D=setTimeout(()=>{K(X),g(1)},300);return()=>clearTimeout(D)},[X]),n.useEffect(()=>{g(1)},[u,S,P]);const ee=n.useCallback(()=>{_(),M(),t==null||t()},[_,M,t]),J=n.useMemo(()=>{const D=new Map;if(s)for(const[E,xe]of Object.entries(s))D.set(E,xe);for(const E of a)E.id&&E.title&&D.set(E.id,E.title);return D},[a,s]),se=async(D,E,xe)=>{var Ie,fe,Ae,Oe;b(!0);try{const Ee=await re.knowledgeLifecycle(D.id,E,xe);le(`${D.title} → ${((Ie=ct[Ee.lifecycle])==null?void 0:Ie.label)||Ee.lifecycle}`,{title:"操作成功"}),l(v=>v.map(ne=>ne.id===D.id?Ee:ne)),(p==null?void 0:p.id)===D.id&&O(Ee),M()}catch(Ee){le(((Oe=(Ae=(fe=Ee==null?void 0:Ee.response)==null?void 0:fe.data)==null?void 0:Ae.error)==null?void 0:Oe.message)||(Ee==null?void 0:Ee.message)||"操作失败",{title:"操作失败",type:"error"})}finally{ue.current&&b(!1)}},V=async D=>{if(confirm(`确定删除「${D.title}」?此操作不可恢复。`))try{await re.knowledgeDelete(D.id),le(`已删除「${D.title}」`,{title:"删除成功"}),l(E=>E.filter(xe=>xe.id!==D.id)),(p==null?void 0:p.id)===D.id&&O(null),M()}catch(E){le((E==null?void 0:E.message)||"删除失败",{title:"删除失败",type:"error"})}},Q=async()=>{if(f.size!==0){q(!0);try{const D=await re.knowledgeBatchPublish([...f]);le(`发布 ${D.successCount} 条,失败 ${D.failureCount} 条`,{title:"批量发布"}),w(new Set),ee()}catch(D){le((D==null?void 0:D.message)||"批量发布失败",{title:"操作失败",type:"error"})}finally{q(!1)}}},ae=async()=>{q(!0);try{const E=((await re.knowledgeList({lifecycle:"pending",limit:500})).data||[]).filter(Ie=>Ie.autoApprovable).map(Ie=>Ie.id);if(E.length===0){le("当前没有可自动通过的待审核条目",{title:"无可发布项"});return}const xe=await re.knowledgeBatchPublish(E);le(`已发布 ${xe.successCount} 条可自动通过的条目`,{title:"批量发布完成"}),ee()}catch(D){le((D==null?void 0:D.message)||"批量发布失败",{title:"操作失败",type:"error"})}finally{q(!1)}},ye=D=>{w(E=>{const xe=new Set(E);return xe.has(D)?xe.delete(D):xe.add(D),xe})},Se=()=>{f.size===a.length?w(new Set):w(new Set(a.map(D=>D.id)))},De=(D,E)=>{const xe=prompt("请输入废弃原因:");xe&&se(D,E,xe)};return e.jsxs("div",{className:"space-y-4",children:[r&&e.jsx("div",{className:"grid grid-cols-3 gap-3",children:Object.entries(ct).map(([D,E])=>{const xe=r[D]||0,Ie=E.icon;return e.jsxs("button",{onClick:()=>{A(u===D?"":D)},className:`flex items-center gap-2 px-3 py-2 rounded-lg border transition-all text-left ${u===D?`${E.bg} ${E.border} ${E.color} ring-1 ring-current`:"bg-white border-slate-200 text-slate-600 hover:bg-slate-50"}`,children:[e.jsx(Ie,{size:14}),e.jsxs("div",{children:[e.jsx("div",{className:"text-xs font-medium",children:E.label}),e.jsx("div",{className:"text-lg font-bold",children:xe})]})]},D)})}),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(dt,{className:"absolute left-3 top-1/2 -translate-y-1/2 text-slate-400",size:16}),e.jsx("input",{type:"text",placeholder:"搜索知识条目...",value:X,onChange:D=>$(D.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(Dt).map(([D,E])=>{const xe=E.icon;return e.jsxs("button",{onClick:()=>I(S===D?"":D),className:`flex items-center gap-1 px-2.5 py-1.5 rounded-md text-xs font-medium border transition-all ${S===D?`${E.bg} ${E.border} ${E.color}`:"bg-white border-slate-200 text-slate-500 hover:bg-slate-50"}`,children:[e.jsx(xe,{size:12}),E.label]},D)})}),e.jsxs("select",{value:P,onChange:D=>B(D.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(D=>e.jsx("option",{value:D,children:D},D))]}),e.jsx("button",{onClick:ee,className:"p-2 rounded-md text-slate-400 hover:bg-slate-100",title:"刷新",children:e.jsx(pt,{size:16})}),f.size>0&&e.jsxs("div",{className:"flex items-center gap-2 ml-auto",children:[e.jsxs("span",{className:"text-xs text-slate-500",children:["已选 ",f.size," 条"]}),e.jsx("button",{onClick:Q,disabled:Z,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:Z?e.jsx(Te,{size:12,className:"animate-spin"}):"批量发布"}),e.jsx("button",{onClick:()=>w(new Set),className:"p-1 text-slate-400 hover:text-slate-600",children:e.jsx(Ke,{size:14})})]}),f.size===0&&e.jsxs("button",{onClick:ae,disabled:Z,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:[Z?e.jsx(Te,{size:12,className:"animate-spin"}):e.jsx(Je,{size:12}),"快速批量发布"]})]}),c?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(Ye,{size:48,className:"mb-4 opacity-30"}),e.jsx("p",{className:"text-sm",children:"暂无知识条目"}),(R||u||S||P)&&e.jsx("button",{onClick:()=>{$(""),A(""),I(""),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:f.size===a.length&&a.length>0,onChange:Se,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:["共 ",x," 条"]})]}),e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:a.map(D=>{var Oe,Ee,v,ne,ve,ce;const E=ct[D.lifecycle]||ct.pending,xe=Dt[D.kind]||Dt.pattern,Ie=E.icon,fe=xe.icon,Ae=dn((Oe=D.reasoning)==null?void 0:Oe.confidence);return e.jsxs("div",{onClick:()=>O(D),className:`group bg-white rounded-xl border shadow-sm hover:shadow-md cursor-pointer transition-all overflow-hidden ${(p==null?void 0:p.id)===D.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:f.has(D.id),onChange:he=>{he.stopPropagation(),ye(D.id)},onClick:he=>he.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 ${E.bg} ${E.color} ${E.border} border`,children:[e.jsx(Ie,{size:10}),E.label]}),e.jsxs("span",{className:`inline-flex items-center gap-1 px-1.5 py-0.5 rounded text-[10px] font-medium ${xe.bg} ${xe.color} ${xe.border} border`,children:[e.jsx(fe,{size:10}),xe.label]}),D.category&&e.jsx("span",{className:"text-[10px] text-slate-400",children:D.category}),e.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded ${Ae.bg} ${Ae.text}`,children:((Ee=D.reasoning)==null?void 0:Ee.confidence)!=null?`${Math.round(D.reasoning.confidence*100)}%`:"—"}),D.autoApprovable&&D.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(Je,{size:9}),"可自动通过"]})]}),e.jsx("h3",{className:"text-sm font-bold text-slate-900 mb-1 break-words leading-snug",children:D.title}),(D.description||((v=D.content)==null?void 0:v.rationale))&&e.jsx("p",{className:"text-xs text-slate-500 line-clamp-2 leading-relaxed",children:D.description||((ne=D.content)==null?void 0:ne.rationale)||""}),((ve=D.content)==null?void 0:ve.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:xn(D.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:[(ce=D.tags)==null?void 0:ce.slice(0,3).map(he=>e.jsx("span",{className:"text-[10px] px-1.5 py-0.5 rounded bg-blue-50 text-blue-600 border border-blue-100",children:he},he)),D.tags&&D.tags.length>3&&e.jsxs("span",{className:"text-[10px] text-slate-400",children:["+",D.tags.length-3]}),e.jsxs("span",{className:"text-[10px] text-slate-300 ml-auto",children:[D.trigger&&e.jsx("span",{className:"text-blue-400 mr-2",children:D.trigger}),D.source&&e.jsx("span",{className:"mr-2",children:D.source}),Pt(D.updatedAt)]})]})]},D.id)})}),e.jsx(_s,{currentPage:j,totalPages:Math.ceil(x/h),onPageChange:g,pageSize:h,onPageSizeChange:D=>{y(D),g(1)},totalItems:x})]}),p&&(()=>{var ce,he,d,L,N,pe,G,oe;const D=ct[p.lifecycle]||ct.pending,E=D.icon,xe=Dt[p.kind]||Dt.pattern,Ie=lt[p.category||""]||lt.All||{};sa[p.source||""]||p.source;const fe=p.reasoning,Ae=fe&&(fe.whyStandard||fe.sources&&fe.sources.length>0||fe.confidence!=null),Oe=a.findIndex(F=>F.id===p.id),Ee=Oe>0,v=Oe<a.length-1,ne=()=>{Ee&&O(a[Oe-1])},ve=()=>{v&&O(a[Oe+1])};return e.jsxs(Ve,{className:"z-30 flex justify-end",onClick:()=>O(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 ${H?"w-[960px] max-w-[92vw]":"w-[700px] max-w-[92vw]"}`,style:{animation:"slideInRight 0.25s ease-out"},onClick:F=>F.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:p.title})}),e.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[e.jsx("button",{onClick:ne,disabled:!Ee,className:"p-1.5 hover:bg-slate-100 rounded-lg transition-colors disabled:opacity-30",title:"上一条",children:e.jsx(Zt,{size:T.md})}),e.jsxs("span",{className:"text-xs text-slate-400 tabular-nums",children:[Oe+1,"/",a.length]}),e.jsx("button",{onClick:ve,disabled:!v,className:"p-1.5 hover:bg-slate-100 rounded-lg transition-colors disabled:opacity-30",title:"下一条",children:e.jsx(st,{size:T.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:H?"收窄":"展宽",children:H?e.jsx(Is,{size:T.md}):e.jsx(hs,{size:T.md})}),e.jsx("button",{onClick:()=>{V(p),O(null)},className:"p-1.5 hover:bg-red-50 rounded-lg text-red-500 transition-colors",title:"删除",children:e.jsx(tt,{size:T.md})}),e.jsx("button",{onClick:()=>O(null),className:"p-1.5 hover:bg-slate-100 rounded-lg transition-colors",children:e.jsx(Ke,{size:T.md})})]})]}),e.jsxs("div",{className:"flex-1 overflow-y-auto",children:[p.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:p.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 ${D.bg} ${D.color} ${D.border} border`,children:[e.jsx(E,{size:10}),D.label]}),e.jsxs("span",{className:`inline-flex items-center gap-1 px-1.5 py-0.5 rounded text-[10px] font-medium ${xe.bg} ${xe.color} ${xe.border} border`,children:[St.createElement(xe.icon,{size:10}),xe.label]}),e.jsx("span",{className:`text-[10px] font-bold px-1.5 py-0.5 rounded uppercase flex items-center gap-1 border ${(Ie==null?void 0:Ie.bg)||"bg-slate-50"} ${(Ie==null?void 0:Ie.color)||"text-slate-400"} ${(Ie==null?void 0:Ie.border)||"border-slate-100"}`,children:p.category||"general"}),p.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:p.knowledgeType}),p.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:p.language}),p.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:p.trigger})]}),e.jsxs("div",{className:"flex flex-wrap gap-x-5 gap-y-2 text-xs",children:[(()=>{const F=[];return p.scope&&F.push({icon:wt,iconClass:"text-teal-400",label:"范围",value:p.scope==="universal"?"通用":p.scope==="project-specific"?"项目级":p.scope==="module-level"?"模块级":p.scope}),p.complexity&&F.push({icon:Qe,iconClass:"text-orange-400",label:"复杂度",value:p.complexity==="advanced"?"高级":p.complexity==="intermediate"?"中级":p.complexity==="beginner"?"初级":p.complexity}),p.source&&p.source!=="unknown"&&F.push({icon:wt,iconClass:"text-violet-400",label:"来源",value:(sa[p.source||""]||{label:p.source||"-"}).label}),p.createdAt&&F.push({icon:it,iconClass:"text-slate-400",label:"创建",value:Pt(p.createdAt)}),p.updatedAt&&F.push({icon:it,iconClass:"text-slate-400",label:"更新",value:Pt(p.updatedAt)}),p.publishedAt&&F.push({icon:es,iconClass:"text-emerald-400",label:"发布",value:Pt(p.publishedAt)}),F.map((te,ge)=>{const W=te.icon;return e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(W,{size:11,className:`${te.iconClass} shrink-0`}),e.jsx("span",{className:"text-slate-400",children:te.label}),e.jsx("span",{className:`font-medium text-slate-600 ${te.mono?"font-mono text-[11px]":""}`,children:te.value})]},ge)})})(),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:p.id})]}),p.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:p.sourceFile})]})]})]}),p.tags&&p.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"}),p.tags.map((F,te)=>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:F},te))]}),p.relations&&Object.entries(p.relations).some(([,F])=>Array.isArray(F)&&F.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($s,{size:12,className:"text-purple-400"}),e.jsx("label",{className:"text-[10px] font-bold text-slate-400 uppercase",children:"关联知识"}),(()=>{const F=Object.values(p.relations).flat().length;return F>0?e.jsx("span",{className:"text-[9px] bg-purple-100 text-purple-600 px-1.5 py-0.5 rounded-full font-bold",children:F}):null})()]}),e.jsx("div",{className:"space-y-1.5",children:Object.entries(p.relations).map(([F,te])=>!Array.isArray(te)||te.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:F}),e.jsx("div",{className:"flex flex-wrap gap-1",children:te.map((ge,W)=>{const be=ge.target||(typeof ge=="string"?ge:JSON.stringify(ge)),Re=J.get(be)||be;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:be,children:Re},W)})})]},F))})]}),p.stats&&Object.values(p.stats).some(F=>F>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:((ce=p.stats)==null?void 0:ce.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:((he=p.stats)==null?void 0:he.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:((d=p.stats)==null?void 0:d.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:((L=p.stats)==null?void 0:L.searchHits)??0}),e.jsx("div",{className:"text-[10px] text-blue-500 font-medium",children:"搜索"})]})]}),(p.stats.views>0||p.stats.applications>0)&&e.jsxs("div",{className:"flex items-center gap-4 mt-2 text-[10px] text-slate-400",children:[e.jsxs("span",{children:["浏览: ",p.stats.views]}),e.jsxs("span",{children:["应用: ",p.stats.applications]})]})]}),Ae&&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(ht,{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:[fe.whyStandard&&!/^Submitted via /i.test(fe.whyStandard)&&e.jsx("p",{className:"text-sm text-slate-700 leading-relaxed",children:fe.whyStandard}),fe.sources&&fe.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:"来源:"}),fe.sources.map((F,te)=>e.jsx("code",{className:"text-[10px] px-2 py-0.5 bg-white border border-amber-200 rounded text-amber-700 font-mono",children:F},te))]}),fe.confidence!=null&&fe.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((fe.confidence??0)*100)}%`}})}),e.jsxs("span",{className:"text-[10px] font-bold text-amber-600",children:[Math.round((fe.confidence??0)*100),"%"]})]}),fe.alternatives&&fe.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:"备选:"}),fe.alternatives.map((F,te)=>e.jsx("span",{className:"text-[10px] px-1.5 py-0.5 bg-slate-100 border border-slate-200 rounded text-slate-600",children:F},te))]})]})]}),p.quality&&p.quality.grade&&p.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 ${p.quality.grade==="A"?"text-emerald-600":p.quality.grade==="B"?"text-blue-600":p.quality.grade==="C"?"text-amber-600":p.quality.grade==="D"?"text-orange-600":"text-slate-400"}`,children:p.quality.grade}),e.jsxs("div",{className:"flex-1 grid grid-cols-3 gap-2 text-[10px]",children:[p.quality.completeness!=null&&p.quality.completeness>0&&e.jsxs("div",{className:"text-center",children:[e.jsx("div",{className:"font-bold text-slate-700",children:p.quality.completeness.toFixed(2)}),e.jsx("div",{className:"text-slate-400",children:"完整性"})]}),p.quality.adaptation!=null&&p.quality.adaptation>0&&e.jsxs("div",{className:"text-center",children:[e.jsx("div",{className:"font-bold text-slate-700",children:p.quality.adaptation.toFixed(2)}),e.jsx("div",{className:"text-slate-400",children:"适配度"})]}),p.quality.documentation!=null&&p.quality.documentation>0&&e.jsxs("div",{className:"text-center",children:[e.jsx("div",{className:"font-bold text-slate-700",children:p.quality.documentation.toFixed(2)}),e.jsx("div",{className:"text-slate-400",children:"文档度"})]})]})]})]}),p.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:p.description})]}),((N=p.content)==null?void 0:N.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(et,{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(mt,{content:p.content.markdown})})})]}),p.headers&&p.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:p.headers.map((F,te)=>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:F},te))})]}),((pe=p.content)==null?void 0:pe.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(xt,{size:11,className:"text-emerald-500"})," 代码 / 标准用法"]}),e.jsx(rt,{code:p.content.pattern,language:p.language==="objc"?"objectivec":p.language,showLineNumbers:!0})]}),(p.doClause||p.whenClause||p.dontClause||p.topicHint||p.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(Qe,{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:[p.topicHint&&e.jsxs("div",{children:[e.jsx("span",{className:"text-indigo-500 font-medium",children:"Topic:"}),e.jsx("span",{className:"text-slate-700",children:p.topicHint})]}),p.whenClause&&e.jsxs("div",{children:[e.jsx("span",{className:"text-blue-500 font-medium",children:"When:"}),e.jsx("span",{className:"text-slate-700",children:p.whenClause})]}),p.doClause&&e.jsxs("div",{children:[e.jsx("span",{className:"text-emerald-500 font-medium",children:"Do:"}),e.jsx("span",{className:"text-slate-700",children:p.doClause})]}),p.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:p.dontClause})]}),p.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:p.coreCode,language:p.language==="objc"?"objectivec":p.language||"text"})})]})]})]}),((G=p.content)==null?void 0:G.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:p.content.rationale})})]}),((oe=p.content)==null?void 0:oe.steps)&&p.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:p.content.steps.map((F,te)=>{if(typeof F=="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:te+1}),e.jsx("p",{className:"text-xs text-slate-700 leading-relaxed",children:F})]},te);const ge=typeof F.title=="string"?F.title:"",W=typeof F.description=="string"?F.description:"",be=typeof F.code=="string"?F.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:te+1}),ge&&e.jsx("span",{className:"text-xs font-bold text-slate-700",children:ge})]}),W&&e.jsx("p",{className:"text-xs text-slate-600 ml-7 leading-relaxed",children:W}),be&&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:be})]},te)})})]}),p.constraints&&(()=>{var ge,W,be,Re,Me,_e,qe,We;const F=p.constraints,te=(((ge=F.guards)==null?void 0:ge.length)||0)+(((W=F.boundaries)==null?void 0:W.length)||0)+(((be=F.preconditions)==null?void 0:be.length)||0)+(((Re=F.sideEffects)==null?void 0:Re.length)||0);return te?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:te})]}),e.jsxs("div",{className:"space-y-1.5 text-xs text-slate-600",children:[(Me=F.guards)==null?void 0:Me.map((U,$e)=>e.jsxs("div",{className:"flex gap-1.5 items-start",children:[e.jsx("span",{className:`text-xs mt-0.5 ${U.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:U.pattern}),U.message&&e.jsxs("span",{className:"text-[10px] text-slate-400",children:["— ",U.message]})]},$e)),(_e=F.boundaries)==null?void 0:_e.map((U,$e)=>e.jsxs("div",{className:"flex gap-1.5",children:[e.jsx("span",{className:"text-orange-400",children:"●"}),U]},$e)),(qe=F.preconditions)==null?void 0:qe.map((U,$e)=>e.jsxs("div",{className:"flex gap-1.5",children:[e.jsx("span",{className:"text-blue-400",children:"◆"}),U]},$e)),(We=F.sideEffects)==null?void 0:We.map((U,$e)=>e.jsxs("div",{className:"flex gap-1.5",children:[e.jsx("span",{className:"text-pink-400",children:"⚡"}),U]},$e))]})]}):null})(),p.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(ht,{size:11,className:"text-cyan-400"})," AI 洞察"]}),e.jsx("p",{className:"text-sm text-slate-600 leading-relaxed",children:p.aiInsight})]}),(()=>{const F=Array.isArray(p.lifecycleHistory)?p.lifecycleHistory:(()=>{try{const te=typeof p.lifecycleHistory=="string"?JSON.parse(p.lifecycleHistory):null;return Array.isArray(te)?te:[]}catch{return[]}})();return F.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:F.map((te,ge)=>{const W=ct[te.from]||ct.pending,be=ct[te.to]||ct.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:Pt(te.at)}),e.jsx("span",{className:`${W.color}`,children:W.label}),e.jsx("span",{className:"text-slate-300",children:"→"}),e.jsx("span",{className:`${be.color} font-medium`,children:be.label}),e.jsxs("span",{className:"text-slate-400 ml-auto",children:["by ",te.by]})]},ge)})})]}):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:()=>{V(p),O(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(tt,{size:14})," 删除"]})}),e.jsx("div",{className:"flex items-center gap-2",children:(cn[p.lifecycle]||[]).map(F=>{const te=F.icon;return e.jsxs("button",{onClick:()=>F.needsReason?De(p,F.action):se(p,F.action),disabled:k,className:`flex items-center gap-1.5 px-4 py-2 rounded-lg text-xs font-bold border transition-colors disabled:opacity-50 ${F.bg} ${F.color} border-current/20`,children:[k?e.jsx(Te,{size:14,className:"animate-spin"}):e.jsx(te,{size:14}),F.label]},F.action)})})]})]})]})})()]})},os={manual:{label:"手动",color:"bg-slate-100 text-slate-600",icon:ma},"user-ai":{label:"AI 协助",color:"bg-violet-100 text-violet-600",icon:Ue},"system-ai":{label:"自动",color:"bg-amber-100 text-amber-600",icon:Yt},"external-ai":{label:"外部 AI",color:"bg-cyan-100 text-cyan-600",icon:zs}},un=({onRefresh:t,signalSuggestionCount:s=0,onSuggestionCountChange:a})=>{const[l,r]=n.useState([]),[i,c]=n.useState(!0),[o,j]=n.useState(null),[g,h]=n.useState(!1),[y,x]=n.useState(!1),[m,u]=n.useState("all"),[A,S]=n.useState(!1),[I,P]=n.useState([]),[B,R]=n.useState(!1),[K,X]=n.useState(!1),[$,H]=n.useState(null),[C,p]=n.useState(!1),[O,k]=n.useState(""),[b,f]=n.useState(!1),[w,Z]=n.useState(!1),[q,ue]=n.useState(!1),_=n.useCallback(async()=>{var E;c(!0);try{const xe=await re.listSkills();r(xe.skills||[])}catch(xe){((E=xe.response)==null?void 0:E.status)!==404&&le(xe.message||"",{title:"获取 Skills 列表失败",type:"error"}),r([])}finally{c(!1)}},[]);n.useEffect(()=>{_()},[_]);const M=async E=>{if((o==null?void 0:o.skillName)===E){j(null);return}p(!1),Z(!1),h(!0);try{const xe=await re.loadSkill(E);j(xe)}catch{le(`"${E}" 不存在或读取出错`,{title:"加载 Skill 失败",type:"error"})}finally{h(!1)}},ee=()=>{o!=null&&o.content&&(navigator.clipboard.writeText(o.content),S(!0),setTimeout(()=>S(!1),2e3))},J=()=>{o&&(k(o.content),p(!0))},se=()=>{p(!1),k("")},V=async()=>{if(!(!o||!O.trim())){f(!0);try{await re.updateSkill(o.skillName,{content:O}),le("已保存",{title:`Skill "${o.skillName}" 更新成功`}),p(!1);const E=await re.loadSkill(o.skillName);j(E)}catch(E){le(E.message||"",{title:"更新 Skill 失败",type:"error"})}finally{f(!1)}}},Q=async()=>{if(o){ue(!0);try{await re.deleteSkill(o.skillName),le("已删除",{title:`Skill "${o.skillName}" 删除成功`}),j(null),Z(!1),p(!1),_(),t==null||t()}catch(E){le(E.message||"",{title:"删除 Skill 失败",type:"error"})}finally{ue(!1)}}},ae=async()=>{R(!0),X(!0);try{const[E,xe]=await Promise.allSettled([re.suggestSkills(),re.getSignalStatus()]),Ie=E.status==="fulfilled"?E.value.suggestions||[]:[],fe=xe.status==="fulfilled"?xe.value.suggestions||[]:[],Ae=new Map;for(const Ee of Ie)Ae.set(Ee.name,Ee);for(const Ee of fe)Ae.set(Ee.name,{...Ae.get(Ee.name),...Ee});const Oe=[...Ae.values()];P(Oe),a==null||a(Oe.length)}catch(E){le(E.message||"",{title:"获取 Skill 推荐失败",type:"error"}),P([]),a==null||a(0)}finally{R(!1)}};n.useEffect(()=>{s>0&&I.length===0&&!K&&ae()},[]);const ye=async E=>{H(E.name);try{const xe=E.description||E.rationale||E.name,Ie=`请为以下场景创建一个 Skill 文档:
105
105
 
106
- 名称:${_.name}
106
+ 名称:${E.name}
107
107
  描述:${xe}
108
- 推荐原因:${_.rationale}
108
+ 推荐原因:${E.rationale}
109
109
 
110
- 请直接生成 Skill 正文内容(Markdown 格式),不需要 frontmatter,不需要输出 JSON 元数据。内容应该详细、实用,包含具体的操作指南和示例。`;let Ae=(await re.aiGenerateSkill(Ie)).reply||_.body||`# ${xe}
110
+ 请直接生成 Skill 正文内容(Markdown 格式),不需要 frontmatter,不需要输出 JSON 元数据。内容应该详细、实用,包含具体的操作指南和示例。`;let Ae=(await re.aiGenerateSkill(Ie)).reply||E.body||`# ${xe}
111
111
 
112
- ${_.rationale||""}`;Ae=Ae.replace(/^\s*\{["']name["']\s*:.*\}\s*\n?/,"").trim(),await re.createSkill({name:_.name,description:xe,content:Ae,createdBy:"user-ai"}),le("已创建并加入知识库",{title:`Skill "${_.name}" 创建成功`}),P(Oe=>{const _e=Oe.filter(v=>v.name!==_.name);return a==null||a(_e.length),_e}),M()}catch(xe){le(xe.message||"",{title:"创建 Skill 失败",type:"error"})}finally{H(null)}},Se=l.filter(_=>m==="all"?!0:_.source===m).sort((_,xe)=>_.source===xe.source?_.name.localeCompare(xe.name):_.source==="project"?-1:1),De=l.filter(_=>_.source==="builtin").length,D=l.filter(_=>_.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(Ye,{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:ae,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(Ee,{size:14,className:"animate-spin"}):e.jsx(ht,{size:14}),"推荐"]}),e.jsx("button",{onClick:M,className:"p-2 rounded-lg text-slate-400 hover:text-slate-600 hover:bg-slate-100 transition-colors",title:"刷新",children:e.jsx(pt,{size:16})}),e.jsxs("button",{onClick:()=>x(!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(Ue,{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:D,icon:Et},{key:"builtin",label:"内置",count:De,icon:dl}].map(_=>e.jsxs("button",{onClick:()=>u(_.key),className:`flex items-center gap-1.5 px-3 py-1.5 rounded-md text-xs font-medium transition-colors ${m===_.key?"bg-white text-violet-700 shadow-sm":"text-slate-500 hover:text-slate-700"}`,children:[_.icon&&e.jsx(_.icon,{size:12}),_.label,e.jsx("span",{className:`ml-0.5 px-1.5 py-0.5 rounded-full text-[10px] ${m===_.key?"bg-violet-100 text-violet-600":"bg-slate-200 text-slate-500"}`,children:_.count})]},_.key))}),K&&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(ht,{size:16,className:"text-amber-600"}),e.jsx("span",{className:"text-sm font-semibold text-amber-800",children:"推荐创建的 Skills"}),I.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:I.length})]}),e.jsx("button",{onClick:()=>X(!1),className:"p-1 text-amber-400 hover:text-amber-600",children:e.jsx(Ke,{size:14})})]}),B?e.jsxs("div",{className:"flex items-center gap-2 text-amber-600 text-xs py-2",children:[e.jsx(Ee,{size:14,className:"animate-spin"}),"分析使用模式中..."]}):I.length===0?e.jsx("p",{className:"text-xs text-amber-600/70",children:"当前暂无推荐。继续使用后会积累更多信号。"}):e.jsx("div",{className:"space-y-2",children:I.map(_=>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:_.name}),e.jsx("span",{className:`px-1.5 py-0.5 rounded text-[9px] font-bold uppercase ${_.priority==="high"?"bg-red-100 text-red-600":_.priority==="medium"?"bg-amber-100 text-amber-600":"bg-slate-100 text-slate-500"}`,children:_.priority}),e.jsx("span",{className:"text-[10px] text-slate-400",children:_.source})]}),e.jsx("p",{className:"text-xs text-slate-600 mb-1",children:_.description}),e.jsx("p",{className:"text-[11px] text-slate-400 line-clamp-2",children:_.rationale})]}),e.jsx("button",{onClick:()=>ye(_),disabled:$===_.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:$===_.name?e.jsxs(e.Fragment,{children:[e.jsx(Ee,{size:12,className:"animate-spin"})," 创建中"]}):e.jsxs(e.Fragment,{children:[e.jsx(Je,{size:12})," AI 创建"]})})]},_.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:i?e.jsx("div",{className:"flex items-center justify-center py-20",children:e.jsx(Ee,{size:24,className:"animate-spin text-violet-400"})}):Se.length===0?e.jsxs("div",{className:"text-center py-20 text-slate-400",children:[e.jsx(Ye,{size:40,className:"mx-auto mb-3 opacity-40"}),e.jsx("p",{children:"暂无 Skills"})]}):Se.map(_=>e.jsx("button",{onClick:()=>T(_.name),className:`w-full text-left p-4 rounded-xl border transition-all ${(o==null?void 0:o.skillName)===_.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 ${(o==null?void 0:o.skillName)===_.name?"text-violet-500":"text-slate-400"}`,children:(o==null?void 0:o.skillName)===_.name?e.jsx(Ct,{size:16}):e.jsx(st,{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:_.name}),e.jsx("span",{className:`px-1.5 py-0.5 rounded text-[10px] font-bold uppercase tracking-wider ${_.source==="builtin"?"bg-blue-100 text-blue-600":"bg-emerald-100 text-emerald-600"}`,children:_.source==="builtin"?"内置":"项目"}),_.createdBy&&os[_.createdBy]&&(()=>{const xe=os[_.createdBy],Ie=xe.icon;return e.jsxs("span",{className:`flex items-center gap-0.5 px-1.5 py-0.5 rounded text-[10px] font-medium ${xe.color}`,children:[e.jsx(Ie,{size:10}),xe.label]})})()]}),e.jsx("p",{className:"text-xs text-slate-500 line-clamp-2",children:_.summary}),_.useCase&&e.jsxs("p",{className:"text-[11px] text-violet-500 mt-1 italic",children:["适用:",_.useCase]})]})]})},_.name))}),e.jsx("div",{className:"w-1/2 overflow-y-auto border border-slate-200 rounded-xl bg-white",children:g?e.jsx("div",{className:"flex items-center justify-center h-full",children:e.jsx(Ee,{size:24,className:"animate-spin text-violet-400"})}):o?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(et,{size:16,className:"text-violet-500"}),e.jsx("span",{className:"font-mono font-semibold text-sm",children:o.skillName}),e.jsx("span",{className:`px-1.5 py-0.5 rounded text-[10px] font-bold uppercase ${o.source==="builtin"?"bg-blue-100 text-blue-600":"bg-emerald-100 text-emerald-600"}`,children:o.source==="builtin"?"内置":"项目"}),o.createdBy&&os[o.createdBy]&&(()=>{const _=os[o.createdBy],xe=_.icon;return e.jsxs("span",{className:`flex items-center gap-0.5 px-1.5 py-0.5 rounded text-[10px] font-medium ${_.color}`,children:[e.jsx(xe,{size:10}),_.label,"创建"]})})()]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("span",{className:"text-[10px] text-slate-400",children:[o.charCount," 字符"]}),e.jsx("button",{onClick:ee,className:"p-1.5 rounded-md hover:bg-slate-100 transition-colors text-slate-400 hover:text-slate-600",title:"复制内容",children:A?e.jsx(ft,{size:14,className:"text-emerald-500"}):e.jsx(_t,{size:14})}),o.source==="project"&&!C&&e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:J,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:()=>Z(!0),className:"p-1.5 rounded-md hover:bg-red-50 transition-colors text-slate-400 hover:text-red-500",title:"删除",children:e.jsx(tt,{size:14})})]}),C&&e.jsxs(e.Fragment,{children:[e.jsxs("button",{onClick:V,disabled:b,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:[b?e.jsx(Ee,{size:12,className:"animate-spin"}):e.jsx(Qt,{size:12}),"保存"]}),e.jsx("button",{onClick:se,className:"px-2.5 py-1 border border-slate-200 text-slate-500 rounded-md hover:bg-slate-50 transition-colors text-xs",children:"取消"})]})]})]}),o.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:"相关:"}),o.relatedSkills.map(_=>e.jsx("button",{onClick:()=>T(_),className:"text-[11px] text-violet-600 hover:text-violet-800 bg-violet-50 px-2 py-0.5 rounded-full transition-colors",children:_},_))]}),e.jsxs("div",{className:"flex-1 overflow-y-auto p-4 relative",children:[C?e.jsx("textarea",{value:O,onChange:_=>k(_.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:o.content}),w&&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(tt,{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:o.skillName}),'"?此操作不可撤销。']}),e.jsxs("div",{className:"flex gap-3 justify-center",children:[e.jsx("button",{onClick:()=>Z(!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:Q,disabled:q,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:[q?e.jsx(Ee,{size:14,className:"animate-spin"}):e.jsx(tt,{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(Ye,{size:40,className:"mx-auto mb-3 opacity-30"}),e.jsx("p",{className:"text-sm",children:"选择左侧 Skill 查看详情"})]})})})]}),y&&e.jsx(pn,{onClose:()=>x(!1),onCreated:()=>{x(!1),M(),t==null||t()}})]})},pn=({onClose:t,onCreated:s})=>{const[a,l]=n.useState("ai"),[r,i]=n.useState(""),[c,o]=n.useState(!1),[j,g]=n.useState(""),[h,y]=n.useState(""),[x,m]=n.useState(""),[u,A]=n.useState(!1),[S,I]=n.useState(""),[P,B]=n.useState(!1),R=async()=>{if(r.trim()){o(!0),I("");try{const $=(await re.aiGenerateSkill(r)).reply||"";let H="",C="",p=$;const O=/```(?:json)?\s*\n?\s*(\{[^}]*"name"[^}]*\})\s*\n?\s*```/i,k=$.match(O);if(k)try{const b=JSON.parse(k[1]);H=b.name||"",C=b.description||"",p=$.replace(k[0],"").trim()}catch{}if(!H){const b=$.split(`
112
+ ${E.rationale||""}`;Ae=Ae.replace(/^\s*\{["']name["']\s*:.*\}\s*\n?/,"").trim(),await re.createSkill({name:E.name,description:xe,content:Ae,createdBy:"user-ai"}),le("已创建并加入知识库",{title:`Skill "${E.name}" 创建成功`}),P(Oe=>{const Ee=Oe.filter(v=>v.name!==E.name);return a==null||a(Ee.length),Ee}),_()}catch(xe){le(xe.message||"",{title:"创建 Skill 失败",type:"error"})}finally{H(null)}},Se=l.filter(E=>m==="all"?!0:E.source===m).sort((E,xe)=>E.source===xe.source?E.name.localeCompare(xe.name):E.source==="project"?-1:1),De=l.filter(E=>E.source==="builtin").length,D=l.filter(E=>E.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(Ye,{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:ae,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(ht,{size:14}),"推荐"]}),e.jsx("button",{onClick:_,className:"p-2 rounded-lg text-slate-400 hover:text-slate-600 hover:bg-slate-100 transition-colors",title:"刷新",children:e.jsx(pt,{size:16})}),e.jsxs("button",{onClick:()=>x(!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(Ue,{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:D,icon:Tt},{key:"builtin",label:"内置",count:De,icon:dl}].map(E=>e.jsxs("button",{onClick:()=>u(E.key),className:`flex items-center gap-1.5 px-3 py-1.5 rounded-md text-xs font-medium transition-colors ${m===E.key?"bg-white text-violet-700 shadow-sm":"text-slate-500 hover:text-slate-700"}`,children:[E.icon&&e.jsx(E.icon,{size:12}),E.label,e.jsx("span",{className:`ml-0.5 px-1.5 py-0.5 rounded-full text-[10px] ${m===E.key?"bg-violet-100 text-violet-600":"bg-slate-200 text-slate-500"}`,children:E.count})]},E.key))}),K&&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(ht,{size:16,className:"text-amber-600"}),e.jsx("span",{className:"text-sm font-semibold text-amber-800",children:"推荐创建的 Skills"}),I.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:I.length})]}),e.jsx("button",{onClick:()=>X(!1),className:"p-1 text-amber-400 hover:text-amber-600",children:e.jsx(Ke,{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"}),"分析使用模式中..."]}):I.length===0?e.jsx("p",{className:"text-xs text-amber-600/70",children:"当前暂无推荐。继续使用后会积累更多信号。"}):e.jsx("div",{className:"space-y-2",children:I.map(E=>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:E.name}),e.jsx("span",{className:`px-1.5 py-0.5 rounded text-[9px] font-bold uppercase ${E.priority==="high"?"bg-red-100 text-red-600":E.priority==="medium"?"bg-amber-100 text-amber-600":"bg-slate-100 text-slate-500"}`,children:E.priority}),e.jsx("span",{className:"text-[10px] text-slate-400",children:E.source})]}),e.jsx("p",{className:"text-xs text-slate-600 mb-1",children:E.description}),e.jsx("p",{className:"text-[11px] text-slate-400 line-clamp-2",children:E.rationale})]}),e.jsx("button",{onClick:()=>ye(E),disabled:$===E.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:$===E.name?e.jsxs(e.Fragment,{children:[e.jsx(Te,{size:12,className:"animate-spin"})," 创建中"]}):e.jsxs(e.Fragment,{children:[e.jsx(Je,{size:12})," AI 创建"]})})]},E.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:i?e.jsx("div",{className:"flex items-center justify-center py-20",children:e.jsx(Te,{size:24,className:"animate-spin text-violet-400"})}):Se.length===0?e.jsxs("div",{className:"text-center py-20 text-slate-400",children:[e.jsx(Ye,{size:40,className:"mx-auto mb-3 opacity-40"}),e.jsx("p",{children:"暂无 Skills"})]}):Se.map(E=>e.jsx("button",{onClick:()=>M(E.name),className:`w-full text-left p-4 rounded-xl border transition-all ${(o==null?void 0:o.skillName)===E.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 ${(o==null?void 0:o.skillName)===E.name?"text-violet-500":"text-slate-400"}`,children:(o==null?void 0:o.skillName)===E.name?e.jsx(Ct,{size:16}):e.jsx(st,{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:E.name}),e.jsx("span",{className:`px-1.5 py-0.5 rounded text-[10px] font-bold uppercase tracking-wider ${E.source==="builtin"?"bg-blue-100 text-blue-600":"bg-emerald-100 text-emerald-600"}`,children:E.source==="builtin"?"内置":"项目"}),E.createdBy&&os[E.createdBy]&&(()=>{const xe=os[E.createdBy],Ie=xe.icon;return e.jsxs("span",{className:`flex items-center gap-0.5 px-1.5 py-0.5 rounded text-[10px] font-medium ${xe.color}`,children:[e.jsx(Ie,{size:10}),xe.label]})})()]}),e.jsx("p",{className:"text-xs text-slate-500 line-clamp-2",children:E.summary}),E.useCase&&e.jsxs("p",{className:"text-[11px] text-violet-500 mt-1 italic",children:["适用:",E.useCase]})]})]})},E.name))}),e.jsx("div",{className:"w-1/2 overflow-y-auto border border-slate-200 rounded-xl bg-white",children:g?e.jsx("div",{className:"flex items-center justify-center h-full",children:e.jsx(Te,{size:24,className:"animate-spin text-violet-400"})}):o?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(et,{size:16,className:"text-violet-500"}),e.jsx("span",{className:"font-mono font-semibold text-sm",children:o.skillName}),e.jsx("span",{className:`px-1.5 py-0.5 rounded text-[10px] font-bold uppercase ${o.source==="builtin"?"bg-blue-100 text-blue-600":"bg-emerald-100 text-emerald-600"}`,children:o.source==="builtin"?"内置":"项目"}),o.createdBy&&os[o.createdBy]&&(()=>{const E=os[o.createdBy],xe=E.icon;return e.jsxs("span",{className:`flex items-center gap-0.5 px-1.5 py-0.5 rounded text-[10px] font-medium ${E.color}`,children:[e.jsx(xe,{size:10}),E.label,"创建"]})})()]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("span",{className:"text-[10px] text-slate-400",children:[o.charCount," 字符"]}),e.jsx("button",{onClick:ee,className:"p-1.5 rounded-md hover:bg-slate-100 transition-colors text-slate-400 hover:text-slate-600",title:"复制内容",children:A?e.jsx(ft,{size:14,className:"text-emerald-500"}):e.jsx(Et,{size:14})}),o.source==="project"&&!C&&e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:J,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:()=>Z(!0),className:"p-1.5 rounded-md hover:bg-red-50 transition-colors text-slate-400 hover:text-red-500",title:"删除",children:e.jsx(tt,{size:14})})]}),C&&e.jsxs(e.Fragment,{children:[e.jsxs("button",{onClick:V,disabled:b,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:[b?e.jsx(Te,{size:12,className:"animate-spin"}):e.jsx(Qt,{size:12}),"保存"]}),e.jsx("button",{onClick:se,className:"px-2.5 py-1 border border-slate-200 text-slate-500 rounded-md hover:bg-slate-50 transition-colors text-xs",children:"取消"})]})]})]}),o.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:"相关:"}),o.relatedSkills.map(E=>e.jsx("button",{onClick:()=>M(E),className:"text-[11px] text-violet-600 hover:text-violet-800 bg-violet-50 px-2 py-0.5 rounded-full transition-colors",children:E},E))]}),e.jsxs("div",{className:"flex-1 overflow-y-auto p-4 relative",children:[C?e.jsx("textarea",{value:O,onChange:E=>k(E.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:o.content}),w&&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(tt,{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:o.skillName}),'"?此操作不可撤销。']}),e.jsxs("div",{className:"flex gap-3 justify-center",children:[e.jsx("button",{onClick:()=>Z(!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:Q,disabled:q,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:[q?e.jsx(Te,{size:14,className:"animate-spin"}):e.jsx(tt,{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(Ye,{size:40,className:"mx-auto mb-3 opacity-30"}),e.jsx("p",{className:"text-sm",children:"选择左侧 Skill 查看详情"})]})})})]}),y&&e.jsx(pn,{onClose:()=>x(!1),onCreated:()=>{x(!1),_(),t==null||t()}})]})},pn=({onClose:t,onCreated:s})=>{const[a,l]=n.useState("ai"),[r,i]=n.useState(""),[c,o]=n.useState(!1),[j,g]=n.useState(""),[h,y]=n.useState(""),[x,m]=n.useState(""),[u,A]=n.useState(!1),[S,I]=n.useState(""),[P,B]=n.useState(!1),R=async()=>{if(r.trim()){o(!0),I("");try{const $=(await re.aiGenerateSkill(r)).reply||"";let H="",C="",p=$;const O=/```(?:json)?\s*\n?\s*(\{[^}]*"name"[^}]*\})\s*\n?\s*```/i,k=$.match(O);if(k)try{const b=JSON.parse(k[1]);H=b.name||"",C=b.description||"",p=$.replace(k[0],"").trim()}catch{}if(!H){const b=$.split(`
113
113
  `);for(let f=0;f<Math.min(b.length,5);f++){const w=b[f].trim();if(!(!w||w.startsWith("```"))&&w.startsWith("{")&&w.endsWith("}"))try{const Z=JSON.parse(w);if(Z.name){H=Z.name,C=Z.description||"";let q=f+1;for(;q<b.length&&!b[q].trim();)q++;p=b.slice(q).join(`
114
- `).trim();break}}catch{}}}if(!H){const b=/"name"\s*:\s*"([a-z][a-z0-9-]{1,62}[a-z0-9])"/,f=/"description"\s*:\s*"([^"]+)"/,w=$.match(b),Z=$.match(f);w&&(H=w[1]),Z&&(C=Z[1])}p=p.replace(/```(?:json)?\s*\n?\s*\{[^}]*"name"[^}]*\}\s*\n?\s*```/gi,"").replace(/^\s*\{[^}]*"name"[^}]*\}\s*$/gm,"").trim(),H&&g(H),C&&y(C),m(p||$.trim()),B(!0),l("manual"),le("请检查并确认生成的内容",{title:"AI 已生成 Skill"})}catch(X){I("AI 生成失败: "+(X.message||""))}finally{o(!1)}}},K=async()=>{var X,$,H;if(!j.trim()||!h.trim()||!x.trim()){I("请填写名称、描述和内容");return}A(!0),I("");try{await re.createSkill({name:j.trim(),description:h.trim(),content:x.trim(),createdBy:P?"user-ai":"manual"}),le("已保存到知识库",{title:`Skill "${j}" 创建成功`}),s()}catch(C){const p=((H=($=(X=C.response)==null?void 0:X.data)==null?void 0:$.error)==null?void 0:H.message)||C.message||"";I("创建失败: "+p)}finally{A(!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(Ue,{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(Ke,{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(Ue,{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(et,{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:r,onChange:X=>i(X.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:c})})]}),e.jsx("button",{onClick:R,disabled:c||!r.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:c?e.jsxs(e.Fragment,{children:[e.jsx(Ee,{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:j,onChange:X=>g(X.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:h,onChange:X=>y(X.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:x,onChange:X=>m(X.target.value),placeholder:`# My Custom Skill
114
+ `).trim();break}}catch{}}}if(!H){const b=/"name"\s*:\s*"([a-z][a-z0-9-]{1,62}[a-z0-9])"/,f=/"description"\s*:\s*"([^"]+)"/,w=$.match(b),Z=$.match(f);w&&(H=w[1]),Z&&(C=Z[1])}p=p.replace(/```(?:json)?\s*\n?\s*\{[^}]*"name"[^}]*\}\s*\n?\s*```/gi,"").replace(/^\s*\{[^}]*"name"[^}]*\}\s*$/gm,"").trim(),H&&g(H),C&&y(C),m(p||$.trim()),B(!0),l("manual"),le("请检查并确认生成的内容",{title:"AI 已生成 Skill"})}catch(X){I("AI 生成失败: "+(X.message||""))}finally{o(!1)}}},K=async()=>{var X,$,H;if(!j.trim()||!h.trim()||!x.trim()){I("请填写名称、描述和内容");return}A(!0),I("");try{await re.createSkill({name:j.trim(),description:h.trim(),content:x.trim(),createdBy:P?"user-ai":"manual"}),le("已保存到知识库",{title:`Skill "${j}" 创建成功`}),s()}catch(C){const p=((H=($=(X=C.response)==null?void 0:X.data)==null?void 0:$.error)==null?void 0:H.message)||C.message||"";I("创建失败: "+p)}finally{A(!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(Ue,{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(Ke,{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(Ue,{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(et,{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:r,onChange:X=>i(X.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:c})})]}),e.jsx("button",{onClick:R,disabled:c||!r.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:c?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:j,onChange:X=>g(X.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:h,onChange:X=>y(X.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:x,onChange:X=>m(X.target.value),placeholder:`# My Custom Skill
115
115
 
116
116
  ## 使用场景
117
117
  ...
118
118
 
119
119
  ## 操作步骤
120
- ...`,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"})]})]}),S&&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:S})]})]}),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:K,disabled:u||!j.trim()||!h.trim()||!x.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:u?e.jsxs(e.Fragment,{children:[e.jsx(Ee,{size:14,className:"animate-spin"}),"保存中..."]}):e.jsxs(e.Fragment,{children:[e.jsx(gt,{size:14}),"创建 Skill"]})})]})]})]})},aa=["objc-deep-scan","category-scan","project-profile","code-standard","architecture","code-pattern","event-and-data-flow","best-practice","agent-guidelines"],hn={"code-standard":e.jsx(Ye,{className:"w-5 h-5"}),"code-pattern":e.jsx(At,{className:"w-5 h-5"}),architecture:e.jsx(Qe,{className:"w-5 h-5"}),"best-practice":e.jsx(Ue,{className:"w-5 h-5"}),"event-and-data-flow":e.jsx(Je,{className:"w-5 h-5"}),"project-profile":e.jsx(ha,{className:"w-5 h-5"}),"agent-guidelines":e.jsx(zs,{className:"w-5 h-5"})};function bn(t){return hn[t]||e.jsx(At,{className:"w-5 h-5"})}const gn=({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"},r={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(Ee,{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(ft,{className:"w-3 h-3"}),"已完成"]}),failed:e.jsxs("span",{className:"flex items-center gap-1 text-xs text-red-600",children:[e.jsx(Ke,{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:bn(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 i=t.result,c=i.sourceCount??0,o=i.extracted??0;return i.type==="empty"?"✓ 无匹配内容":i.type==="skill"?i.empty?"✓ 无匹配内容":o>0?`✓ ${c} 项特征 · ${o} 条候选`:`✓ ${c} 项特征`:o>0?`✓ ${o} 条候选`:"✓ 无匹配内容"})()}),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:r[s]})]})]})},fn=[{key:"round1",label:"资格审查",desc:"过滤误报 · 识别合并",icon:e.jsx(xl,{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(ml,{className:"w-4 h-4"})}],jn=({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(Jt,{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:fn.map(({key:s,label:a,desc:l,icon:r})=>{const i=t[s],c=i.status==="running",o=i.status==="completed",j=i.status==="idle";return e.jsxs("div",{className:`flex items-center gap-3 p-2.5 rounded-lg border transition-all duration-300 ${c?"border-purple-300 bg-purple-100/60":o?"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 ${c?"bg-purple-200 text-purple-700":o?"bg-emerald-100 text-emerald-600":"bg-slate-100 text-slate-400"}`,children:r}),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 ${j?"text-slate-400":"text-slate-800"}`,children:a}),e.jsx("span",{className:"text-xs text-slate-400",children:l})]}),s==="round1"&&o&&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"&&c&&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"&&o&&e.jsxs("p",{className:"text-xs text-emerald-600 mt-0.5",children:["已精炼 ",t.round2.refined??"?","/",t.round2.total??"?"," 条"]}),s==="round3"&&o&&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:[c&&e.jsx(Ee,{className:"w-4 h-4 text-purple-500 animate-spin"}),o&&e.jsx(ft,{className:"w-4 h-4 text-emerald-500"})]})]},s)})})]});function la(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 Nn=({session:t,isAllDone:s,reviewState:a,onDismiss:l})=>{const r=n.useRef(!1),[i,c]=n.useState(Date.now());if(n.useEffect(()=>{if(!t||t.status!=="running")return;const u=setInterval(()=>c(Date.now()),1e3);return()=>clearInterval(u)},[t==null?void 0:t.status]),n.useEffect(()=>{if(s&&t&&!r.current){r.current=!0;const u=t.failed>0?`${t.completed}/${t.total} 成功,${t.failed} 失败`:`${t.completed} 个维度全部填充成功`;le(u,{title:"冷启动完成",type:t.failed>0?"error":"success"})}},[s,t]),n.useEffect(()=>{t||(r.current=!1)},[t==null?void 0:t.id]),!t)return null;const o=t.startedAt?i-t.startedAt:t.elapsedMs??0,j=t.completed+t.failed,g=t.total-j,h=t.elapsedMs??0,y=j>0&&h>0?Math.round(h/j*g):-1,x=t.totalToolCalls??0,m=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:"冷启动进度"}),m&&e.jsx("p",{className:"text-sm text-slate-500 mt-0.5",children:m})]}),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:la(o)})]})]}),t.status==="running"&&g>0&&y>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:la(y)})]})]}),e.jsxs("div",{className:"flex items-center gap-1.5 text-slate-600",children:[e.jsx(Na,{size:14,className:"text-slate-400"}),e.jsxs("span",{children:["工具调用 ",e.jsx("span",{className:"font-medium text-slate-800",children:x})]})]}),e.jsxs("div",{className:"text-slate-400 text-xs",children:[j,"/",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((u,A)=>{var P,B;const S=aa.indexOf(((P=u.meta)==null?void 0:P.dimId)??u.id),I=aa.indexOf(((B=A.meta)==null?void 0:B.dimId)??A.id);return(S===-1?999:S)-(I===-1?999:I)}).map(u=>e.jsx(gn,{task:u},u.id))}),a&&a.activeRound>0&&e.jsx(jn,{review:a})]})},yn=()=>{const t=n.useRef(null),s=n.useRef(!0),a=`// AutoSnippet Xcode 模拟器
120
+ ...`,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"})]})]}),S&&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:S})]})]}),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:K,disabled:u||!j.trim()||!h.trim()||!x.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:u?e.jsxs(e.Fragment,{children:[e.jsx(Te,{size:14,className:"animate-spin"}),"保存中..."]}):e.jsxs(e.Fragment,{children:[e.jsx(gt,{size:14}),"创建 Skill"]})})]})]})]})},aa=["objc-deep-scan","category-scan","project-profile","code-standard","architecture","code-pattern","event-and-data-flow","best-practice","agent-guidelines"],hn={"code-standard":e.jsx(Ye,{className:"w-5 h-5"}),"code-pattern":e.jsx(At,{className:"w-5 h-5"}),architecture:e.jsx(Qe,{className:"w-5 h-5"}),"best-practice":e.jsx(Ue,{className:"w-5 h-5"}),"event-and-data-flow":e.jsx(Je,{className:"w-5 h-5"}),"project-profile":e.jsx(ha,{className:"w-5 h-5"}),"agent-guidelines":e.jsx(zs,{className:"w-5 h-5"})};function bn(t){return hn[t]||e.jsx(At,{className:"w-5 h-5"})}const gn=({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"},r={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(ft,{className:"w-3 h-3"}),"已完成"]}),failed:e.jsxs("span",{className:"flex items-center gap-1 text-xs text-red-600",children:[e.jsx(Ke,{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:bn(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 i=t.result,c=i.sourceCount??0,o=i.extracted??0;return i.type==="empty"?"✓ 无匹配内容":i.type==="skill"?i.empty?"✓ 无匹配内容":o>0?`✓ ${c} 项特征 · ${o} 条候选`:`✓ ${c} 项特征`:o>0?`✓ ${o} 条候选`:"✓ 无匹配内容"})()}),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:r[s]})]})]})},fn=[{key:"round1",label:"资格审查",desc:"过滤误报 · 识别合并",icon:e.jsx(xl,{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(ml,{className:"w-4 h-4"})}],jn=({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(Jt,{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:fn.map(({key:s,label:a,desc:l,icon:r})=>{const i=t[s],c=i.status==="running",o=i.status==="completed",j=i.status==="idle";return e.jsxs("div",{className:`flex items-center gap-3 p-2.5 rounded-lg border transition-all duration-300 ${c?"border-purple-300 bg-purple-100/60":o?"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 ${c?"bg-purple-200 text-purple-700":o?"bg-emerald-100 text-emerald-600":"bg-slate-100 text-slate-400"}`,children:r}),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 ${j?"text-slate-400":"text-slate-800"}`,children:a}),e.jsx("span",{className:"text-xs text-slate-400",children:l})]}),s==="round1"&&o&&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"&&c&&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"&&o&&e.jsxs("p",{className:"text-xs text-emerald-600 mt-0.5",children:["已精炼 ",t.round2.refined??"?","/",t.round2.total??"?"," 条"]}),s==="round3"&&o&&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:[c&&e.jsx(Te,{className:"w-4 h-4 text-purple-500 animate-spin"}),o&&e.jsx(ft,{className:"w-4 h-4 text-emerald-500"})]})]},s)})})]});function la(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 Nn=({session:t,isAllDone:s,reviewState:a,onDismiss:l})=>{const r=n.useRef(!1),[i,c]=n.useState(Date.now());if(n.useEffect(()=>{if(!t||t.status!=="running")return;const u=setInterval(()=>c(Date.now()),1e3);return()=>clearInterval(u)},[t==null?void 0:t.status]),n.useEffect(()=>{if(s&&t&&!r.current){r.current=!0;const u=t.failed>0?`${t.completed}/${t.total} 成功,${t.failed} 失败`:`${t.completed} 个维度全部填充成功`;le(u,{title:"冷启动完成",type:t.failed>0?"error":"success"})}},[s,t]),n.useEffect(()=>{t||(r.current=!1)},[t==null?void 0:t.id]),!t)return null;const o=t.startedAt?i-t.startedAt:t.elapsedMs??0,j=t.completed+t.failed,g=t.total-j,h=t.elapsedMs??0,y=j>0&&h>0?Math.round(h/j*g):-1,x=t.totalToolCalls??0,m=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:"冷启动进度"}),m&&e.jsx("p",{className:"text-sm text-slate-500 mt-0.5",children:m})]}),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:la(o)})]})]}),t.status==="running"&&g>0&&y>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:la(y)})]})]}),e.jsxs("div",{className:"flex items-center gap-1.5 text-slate-600",children:[e.jsx(Na,{size:14,className:"text-slate-400"}),e.jsxs("span",{children:["工具调用 ",e.jsx("span",{className:"font-medium text-slate-800",children:x})]})]}),e.jsxs("div",{className:"text-slate-400 text-xs",children:[j,"/",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((u,A)=>{var P,B;const S=aa.indexOf(((P=u.meta)==null?void 0:P.dimId)??u.id),I=aa.indexOf(((B=A.meta)==null?void 0:B.dimId)??A.id);return(S===-1?999:S)-(I===-1?999:I)}).map(u=>e.jsx(gn,{task:u},u.id))}),a&&a.activeRound>0&&e.jsx(jn,{review:a})]})},yn=()=>{const t=n.useRef(null),s=n.useRef(!0),a=`// AutoSnippet Xcode 模拟器
121
121
  // 支持的指令:
122
122
  // // as:search <query> - 搜索代码片段
123
123
  // // as:create <query> - 创建代码片段
@@ -127,17 +127,17 @@ ${_.rationale||""}`;Ae=Ae.replace(/^\s*\{["']name["']\s*:.*\}\s*\n?/,"").trim(),
127
127
  // // as:search useState hooks
128
128
  // // as:create custom form validation utility
129
129
  // // as:audit /src/components
130
- `,l=n.useRef(a),r=n.useRef(0),[i,c]=n.useState({content:a,cursorPos:0,cursorLine:0,cursorCol:0}),[o,j]=n.useState([]),[g,h]=n.useState(""),[y,x]=n.useState(!1),[m,u]=n.useState(!1),[A,S]=n.useState(!0),[I,P]=n.useState(null),[B,R]=n.useState(new Set),[K,X]=n.useState(""),[$,H]=n.useState(null),C=(T,ee)=>{const J=T.split(`
131
- `);let se=0,V=0,Q=0;for(let ae=0;ae<J.length;ae++){if(Q+J[ae].length+1>ee){se=ae,V=ee-Q;break}Q+=J[ae].length+1}return{line:se,col:V}},p=(T,ee=0)=>{l.current=T,r.current=ee;const{line:J,col:se}=C(T,ee);c({content:T,cursorPos:ee,cursorLine:J,cursorCol:se}),k(T)},O=T=>{r.current=T;const{line:ee,col:J}=C(l.current,T);c(se=>({...se,cursorPos:T,cursorLine:ee,cursorCol:J}))};n.useEffect(()=>{s.current=!0,k(i.content),b();const T=()=>{t.current&&t.current.clientHeight};return window.addEventListener("resize",T),()=>{s.current=!1,window.removeEventListener("resize",T)}},[]);const k=(T=i.content)=>{const ee=T.split(`
132
- `),J=[];ee.forEach((se,V)=>{const Q=se.match(/\/\/\s*as:(search|create|audit)\s+(.+)/);Q&&J.push({line:V,type:Q[1],directive:Q[0],query:Q[2].trim()})}),j(J)},b=async()=>{try{const T=await fetch("/api/v1/commands/files/tree");if(T.ok){const ee=await T.json(),J=ee.data||ee.tree||ee;if(J&&J.children&&J.children.length>0){P(J),J.path&&R(new Set([J.path]));return}}}catch(T){console.error("Failed to load file tree from API:",T)}P(null)},f=async T=>{var ee;try{const J=await fetch(`/api/v1/commands/files/read?path=${encodeURIComponent(T)}`);if(!J.ok)throw new Error(`Open failed with status ${J.status}`);const se=await J.json(),V=se.data||se,Q=V.content||"";p(Q,0),X(V.path||T);const ae=((ee=T.split(".").pop())==null?void 0:ee.toLowerCase())||"",ye={h:"objc",m:"objc",swift:"swift"};h("")}catch(J){console.error("Open file failed:",J),h(`✗ 打开文件失败: ${J instanceof Error?J.message:"未知错误"}`)}},w=async()=>{try{await fetch("/api/v1/commands/files/save",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:K,content:i.content})})}catch(T){console.error("Save failed:",T)}},Z=()=>{window.confirm("确定要清空编辑器吗?")&&p("",0)},q=async T=>{var ee;x(!0),H(o.indexOf(T));try{console.log(`[Execute] 触发 ${T.type} 指令...`,{query:T.query,line:T.line});const J=await fetch("/api/v1/commands/execute",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({type:T.type,query:T.query,line:T.line,content:i.content,source:"simulator"})}),se=await J.json();if(console.log("[Execute] 响应:",se),!J.ok)throw new Error(se.error||"执行失败");if(T.type==="search"&&se.results&&se.results.length>0){console.log(`[Execute] 搜索到 ${se.results.length} 个结果,准备显示 NativeUI 弹窗`);const V=se.results.map((ye,Se)=>`${Se+1}. ${ye.title} (${ye.category||"uncategorized"})`),ae=await(await fetch("/api/v1/commands/execute",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({type:"list",title:`搜索结果: ${T.query}`,options:V})})).json();if(ae.success&&((ee=ae.result)==null?void 0:ee.selectedIndex)>=0){const ye=se.results[ae.result.selectedIndex];console.log(`[Execute] 用户选择了: ${ye.title}`);const Se=i.content.split(`
133
- `),De=T.line+1,_=(ye.body||`// ${ye.title}`).split(`
134
- `);Se.splice(De,0,..._);const xe=Se.join(`
130
+ `,l=n.useRef(a),r=n.useRef(0),[i,c]=n.useState({content:a,cursorPos:0,cursorLine:0,cursorCol:0}),[o,j]=n.useState([]),[g,h]=n.useState(""),[y,x]=n.useState(!1),[m,u]=n.useState(!1),[A,S]=n.useState(!0),[I,P]=n.useState(null),[B,R]=n.useState(new Set),[K,X]=n.useState(""),[$,H]=n.useState(null),C=(M,ee)=>{const J=M.split(`
131
+ `);let se=0,V=0,Q=0;for(let ae=0;ae<J.length;ae++){if(Q+J[ae].length+1>ee){se=ae,V=ee-Q;break}Q+=J[ae].length+1}return{line:se,col:V}},p=(M,ee=0)=>{l.current=M,r.current=ee;const{line:J,col:se}=C(M,ee);c({content:M,cursorPos:ee,cursorLine:J,cursorCol:se}),k(M)},O=M=>{r.current=M;const{line:ee,col:J}=C(l.current,M);c(se=>({...se,cursorPos:M,cursorLine:ee,cursorCol:J}))};n.useEffect(()=>{s.current=!0,k(i.content),b();const M=()=>{t.current&&t.current.clientHeight};return window.addEventListener("resize",M),()=>{s.current=!1,window.removeEventListener("resize",M)}},[]);const k=(M=i.content)=>{const ee=M.split(`
132
+ `),J=[];ee.forEach((se,V)=>{const Q=se.match(/\/\/\s*as:(search|create|audit)\s+(.+)/);Q&&J.push({line:V,type:Q[1],directive:Q[0],query:Q[2].trim()})}),j(J)},b=async()=>{try{const M=await fetch("/api/v1/commands/files/tree");if(M.ok){const ee=await M.json(),J=ee.data||ee.tree||ee;if(J&&J.children&&J.children.length>0){P(J),J.path&&R(new Set([J.path]));return}}}catch(M){console.error("Failed to load file tree from API:",M)}P(null)},f=async M=>{var ee;try{const J=await fetch(`/api/v1/commands/files/read?path=${encodeURIComponent(M)}`);if(!J.ok)throw new Error(`Open failed with status ${J.status}`);const se=await J.json(),V=se.data||se,Q=V.content||"";p(Q,0),X(V.path||M);const ae=((ee=M.split(".").pop())==null?void 0:ee.toLowerCase())||"",ye={h:"objc",m:"objc",swift:"swift"};h("")}catch(J){console.error("Open file failed:",J),h(`✗ 打开文件失败: ${J instanceof Error?J.message:"未知错误"}`)}},w=async()=>{try{await fetch("/api/v1/commands/files/save",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:K,content:i.content})})}catch(M){console.error("Save failed:",M)}},Z=()=>{window.confirm("确定要清空编辑器吗?")&&p("",0)},q=async M=>{var ee;x(!0),H(o.indexOf(M));try{console.log(`[Execute] 触发 ${M.type} 指令...`,{query:M.query,line:M.line});const J=await fetch("/api/v1/commands/execute",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({type:M.type,query:M.query,line:M.line,content:i.content,source:"simulator"})}),se=await J.json();if(console.log("[Execute] 响应:",se),!J.ok)throw new Error(se.error||"执行失败");if(M.type==="search"&&se.results&&se.results.length>0){console.log(`[Execute] 搜索到 ${se.results.length} 个结果,准备显示 NativeUI 弹窗`);const V=se.results.map((ye,Se)=>`${Se+1}. ${ye.title} (${ye.category||"uncategorized"})`),ae=await(await fetch("/api/v1/commands/execute",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({type:"list",title:`搜索结果: ${M.query}`,options:V})})).json();if(ae.success&&((ee=ae.result)==null?void 0:ee.selectedIndex)>=0){const ye=se.results[ae.result.selectedIndex];console.log(`[Execute] 用户选择了: ${ye.title}`);const Se=i.content.split(`
133
+ `),De=M.line+1,E=(ye.body||`// ${ye.title}`).split(`
134
+ `);Se.splice(De,0,...E);const xe=Se.join(`
135
135
  `),Ie=i.content.split(`
136
136
  `).slice(0,De).join(`
137
- `).length+1;p(xe,Ie),console.log(`✓ 已插入代码片段: ${ye.title}`)}else console.log("[Execute] 用户取消了选择")}else T.type==="search"&&console.warn("[Execute] 未找到匹配的搜索结果");se.success&&console.log(`✓ 指令已执行: ${se.message}`)}catch(J){console.error(`✗ 错误: ${J instanceof Error?J.message:"执行失败"}`)}finally{x(!1)}},ue=(T,ee=60)=>{if(T.length<=ee)return T;const J=T.split("/");if(J.length<=2)return T;const se=J[J.length-1],V=J.slice(0,2).join("/");if(V.length+se.length+5>ee){const ae=ee-se.length-5;return`${V.substring(0,Math.max(10,ae))}/.../${se}`}const Q=ee-V.length-se.length-5;if(Q>0&&J.length>3){let ye=J.slice(2,-1).join("/");return ye.length>Q&&(ye="..."),`${V}/${ye}/${se}`}return`${V}/.../${se}`},M=(T,ee=0)=>{if(!T)return null;if(T.type==="folder"){const J=B.has(T.path);return e.jsxs("div",{children:[e.jsxs("div",{className:"file-tree-item folder-item",onClick:()=>{const se=new Set(B);J?se.delete(T.path):se.add(T.path),R(se)},style:{paddingLeft:`${ee*16}px`},children:[e.jsx(Ct,{size:E.sm,className:`folder-toggle ${J?"expanded":""}`}),e.jsx(Ds,{size:E.sm,className:"folder-icon"}),e.jsx("span",{className:"file-name",children:T.name})]}),J&&T.children&&e.jsx("div",{children:T.children.map(se=>M(se,ee+1))})]},T.path)}else return e.jsxs("div",{className:`file-tree-item file-item ${K===T.path?"active":""}`,onClick:()=>f(T.path),style:{paddingLeft:`${ee*16}px`},children:[e.jsx(Ps,{size:E.sm,className:"file-icon"}),e.jsx("span",{className:"file-name",children:T.name})]},T.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:()=>S(!A),title:"切换侧栏",children:e.jsx(ul,{size:E.md})}),e.jsxs("div",{className:"file-info",title:K,children:[e.jsx(ps,{size:E.sm}),e.jsx("span",{className:"file-name",children:ue(K||"untitled.js",80)})]})]}),e.jsxs("div",{className:"toolbar-right",children:[e.jsx("button",{className:"toolbar-btn",onClick:w,title:"保存",children:e.jsx(Qt,{size:E.md})}),e.jsx("button",{className:"toolbar-btn",onClick:Z,title:"清空",children:e.jsx(tt,{size:E.md})}),e.jsx("button",{className:"toolbar-btn",title:"更多选项",children:e.jsx(pl,{size:E.md})})]})]}),e.jsxs("div",{className:"xcode-main",children:[A&&e.jsxs("div",{className:"xcode-sidebar",children:[e.jsxs("div",{className:"sidebar-header",children:[e.jsx(Ds,{size:E.md}),e.jsx("h3",{children:"文件浏览"})]}),e.jsx("div",{className:"file-tree",children:I?M(I):e.jsxs("div",{className:"empty-state",style:{padding:"16px 8px"},children:[e.jsx(Ps,{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:i.content,onChange:T=>p(T,r.current),onCursorChange:O,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 ",i.cursorLine+1,", Col ",i.cursorCol+1]}),e.jsx("span",{children:"|"}),e.jsxs("span",{children:[i.content.length," characters"]}),e.jsx("span",{children:"|"}),e.jsxs("span",{children:[i.content.split(`
138
- `).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:E.md}),e.jsx("h3",{children:"检测到的指令"}),e.jsx("span",{className:"count",children:o.length})]}),o.length===0?e.jsxs("div",{className:"empty-state",children:[e.jsx(Ue,{size:32}),e.jsx("p",{children:"暂无指令"}),e.jsx("small",{children:"在代码中添加 // as:search 来创建指令"})]}):e.jsx("div",{className:"directives-list",children:o.map((T,ee)=>e.jsxs("div",{className:`directive-card ${T.type} ${$===ee?"active":""}`,onClick:()=>H(ee),children:[e.jsxs("div",{className:"directive-header",children:[e.jsx("div",{className:"type-badge",children:T.type.toUpperCase()}),e.jsxs("div",{className:"line-badge",children:["L",T.line+1]})]}),e.jsx("div",{className:"directive-query",children:T.query}),e.jsx("button",{className:"execute-btn",onClick:J=>{J.stopPropagation(),q(T)},disabled:y,children:y&&$===ee?e.jsxs(e.Fragment,{children:[e.jsx(Ee,{size:E.xs,className:"spin"}),"执行中..."]}):e.jsxs(e.Fragment,{children:[e.jsx(hl,{size:E.xs}),"执行"]})})]},ee))})]}),g&&e.jsxs("div",{className:"result-section result",children:[e.jsxs("div",{className:"section-header",children:[e.jsx(dt,{size:E.md}),e.jsx("h3",{children:"执行结果"})]}),e.jsx("div",{className:"result-content",children:e.jsx("pre",{children:g})})]})]})]}),m&&e.jsx("div",{className:"result-modal-backdrop",onClick:()=>u(!1),children:e.jsxs("div",{className:"result-modal",onClick:T=>T.stopPropagation(),children:[e.jsxs("div",{className:"result-modal-header",children:[e.jsx("h2",{children:"执行结果"}),e.jsx("button",{className:"result-modal-close",onClick:()=>u(!1),children:"✕"})]}),e.jsx("div",{className:"result-modal-content",children:e.jsx("pre",{children:g})}),e.jsxs("div",{className:"result-modal-footer",children:[e.jsx("button",{className:"result-modal-btn",onClick:()=>{navigator.clipboard.writeText(g)},children:"复制"}),e.jsx("button",{className:"result-modal-btn",onClick:()=>u(!1),children:"关闭"})]})]})})]})},is={index:{icon:Ye,color:"text-blue-600",label:"项目概述"},architecture:{icon:Qe,color:"text-violet-600",label:"架构总览"},"getting-started":{icon:xt,color:"text-emerald-600",label:"快速上手"},protocols:{icon:Ue,color:"text-amber-600",label:"协议与组件"},components:{icon:xt,color:"text-emerald-600",label:"组件清单"},patterns:{icon:Ue,color:"text-amber-600",label:"代码模式"},module:{icon:Et,color:"text-cyan-600",label:"模块文档"},document:{icon:et,color:"text-orange-600",label:"开发文档"},_index:{icon:Gt,color:"text-slate-500",label:"目录索引"}};function vn(t){var a;const s=((a=t.split("/").pop())==null?void 0:a.replace(".md",""))||"";return s==="_index"?is._index:t.startsWith("modules/")?is.module:t.startsWith("documents/")?is.document:is[s]||{icon:et,color:"text-slate-500",label:"文档"}}const wn={"cursor-devdocs":{label:"Cursor Docs",color:"text-orange-700",bg:"bg-orange-50 border-orange-200"}},kn={modules:"模块",documents:"开发文档"};function _a(t){return t<1e3?`${t}ms`:`${(t/1e3).toFixed(1)}s`}function Cn(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 Sn=({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:E.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:E.md,className:"text-amber-600"})}),e.jsx("span",{className:"text-sm text-amber-700",children:"检测到代码变更,Wiki 可能已过期,建议增量更新"})]}):null;function In(t,s){const a=[],l=new Map((s==null?void 0:s.map(g=>[g.path,g]))||[]),r=[],i=new Map;for(const g of t){const h=g.path.split("/"),y=l.get(g.path);if(h.length===1)r.push({name:h[0],path:g.path,isDir:!1,file:g,metaInfo:y});else{const x=h[0];i.has(x)||i.set(x,[]),i.get(x).push({name:h.slice(1).join("/"),path:g.path,isDir:!1,file:g,metaInfo:y})}}const c=["index.md","architecture.md","getting-started.md","patterns.md","protocols.md","components.md"];r.sort((g,h)=>{const y=c.indexOf(g.name),x=c.indexOf(h.name);return y!==-1&&x!==-1?y-x:y!==-1?-1:x!==-1?1:g.name.localeCompare(h.name)}),a.push(...r);const o=["modules","patterns","documents"],j=[...i.entries()].sort(([g],[h])=>{const y=o.indexOf(g),x=o.indexOf(h);return y!==-1&&x!==-1?y-x:y!==-1?-1:x!==-1?1:g.localeCompare(h)});for(const[g,h]of j){const y=h.filter(x=>!x.name.startsWith("_index")).sort((x,m)=>x.name.localeCompare(m.name));a.push({name:g,path:g,isDir:!0,children:y})}return a}const $n=({tree:t,selectedFile:s,onSelect:a,searchQuery:l})=>{const[r,i]=n.useState(new Set(["modules","documents"])),c=g=>{i(h=>{const y=new Set(h);return y.has(g)?y.delete(g):y.add(g),y})},j=(g=>{if(!l)return g;const h=l.toLowerCase();return g.filter(y=>{var x;return y.isDir?(x=y.children)==null?void 0:x.some(m=>m.name.toLowerCase().includes(h)||m.path.toLowerCase().includes(h)):y.name.toLowerCase().includes(h)||y.path.toLowerCase().includes(h)})})(t);return e.jsx("div",{className:"space-y-0.5",children:j.map(g=>{var h;if(g.isDir){const y=r.has(g.path),x=l.toLowerCase(),m=l?(h=g.children)==null?void 0:h.filter(u=>u.name.toLowerCase().includes(x)||u.path.toLowerCase().includes(x)):g.children;return e.jsxs("div",{children:[e.jsxs("button",{onClick:()=>c(g.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:[y?e.jsx(Ct,{size:14,className:"text-slate-400 flex-shrink-0"}):e.jsx(st,{size:14,className:"text-slate-400 flex-shrink-0"}),e.jsx(Et,{size:14,className:"text-amber-500 flex-shrink-0"}),e.jsx("span",{className:"font-medium truncate",children:kn[g.name]||g.name}),e.jsx("span",{className:"ml-auto text-xs text-slate-400",children:(m==null?void 0:m.length)||0})]}),y&&m&&e.jsx("div",{className:"ml-3",children:m.map(u=>e.jsx(ra,{node:u,isActive:s===u.path,onSelect:a},u.path))})]},g.path)}return e.jsx(ra,{node:g,isActive:s===g.path,onSelect:a},g.path)})})},ra=({node:t,isActive:s,onSelect:a})=>{var o,j;const l=vn(t.path),r=l.icon,i=(o=t.metaInfo)==null?void 0:o.polished,c=(j=t.metaInfo)==null?void 0:j.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(r,{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:[i&&e.jsx("span",{title:"AI 增强",children:e.jsx(Ue,{size:10,className:"text-violet-400"})}),c&&e.jsx("span",{title:`来源: ${c}`,children:e.jsx(gl,{size:10,className:"text-orange-400"})})]})]})},zn=({filePath:t,content:s,loading:a,meta:l,onBack:r})=>{var y;const[i,c]=n.useState(!1),o=(y=l==null?void 0:l.files)==null?void 0:y.find(x=>x.path===t),j=()=>{navigator.clipboard.writeText(s),c(!0),setTimeout(()=>c(!1),2e3)},g=t.split("/"),h=g.map((x,m)=>({label:m===g.length-1?x.replace(".md",""):x,isLast:m===g.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:r,className:"p-1.5 hover:bg-slate-200 rounded-lg transition-colors lg:hidden",title:"返回文件列表",children:e.jsx(bl,{size:E.md})}),e.jsxs("div",{className:"flex items-center gap-1 text-sm",children:[e.jsx(Ye,{size:14,className:"text-slate-400"}),e.jsx("span",{className:"text-slate-400",children:"wiki"}),h.map((x,m)=>e.jsxs(St.Fragment,{children:[e.jsx(st,{size:12,className:"text-slate-300"}),e.jsx("span",{className:x.isLast?"font-medium text-slate-700":"text-slate-400",children:x.label})]},m))]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[(o==null?void 0:o.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(Ue,{size:10}),"AI 增强"]}),(o==null?void 0:o.source)&&(()=>{const x=wn[o.source];return e.jsx("span",{className:`flex items-center gap-1 text-xs border px-2 py-0.5 rounded-full ${(x==null?void 0:x.bg)||"bg-slate-50 border-slate-200"} ${(x==null?void 0:x.color)||"text-slate-600"}`,children:(x==null?void 0:x.label)||o.source})})(),e.jsxs("button",{onClick:j,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:[i?e.jsx(ft,{size:12,className:"text-emerald-500"}):e.jsx(_t,{size:12}),i?"已复制":"复制"]})]})]}),e.jsx("div",{className:"flex-1 overflow-auto scrollbar-light",style:{scrollbarGutter:"stable"},children:a?e.jsx("div",{className:"flex items-center justify-center py-20",children:e.jsx(Ee,{size:E.xl,className:"text-blue-500 animate-spin"})}):e.jsx("div",{className:"px-8 py-6 max-w-4xl mx-auto",children:e.jsx(mt,{content:s,className:"wiki-reader"})})})]})},An=()=>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(Ye,{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"})," 增量更新"]})]}),_n=({meta:t,onSelectFile:s,isGenerating:a,progress:l,message:r})=>{var j;const i=[{path:"index.md",label:"项目概述",desc:"项目信息、技术栈与数据统计",icon:Ye,color:"bg-blue-50 text-blue-600 border-blue-200"},{path:"architecture.md",label:"架构总览",desc:"模块依赖图、SPM Target 结构",icon:Qe,color:"bg-violet-50 text-violet-600 border-violet-200"},{path:"getting-started.md",label:"快速上手",desc:"构建、运行与入口分析",icon:xt,color:"bg-emerald-50 text-emerald-600 border-emerald-200"},{path:"protocols.md",label:"协议与组件",desc:"核心协议、委托和组件关系",icon:Ue,color:"bg-amber-50 text-amber-600 border-amber-200"}],c=new Set(((j=t==null?void 0:t.files)==null?void 0:j.map(g=>g.path||g.name))??[]),o=i.filter(g=>c.size===0||c.has(g.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(zs,{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:r||"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(et,{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:o.map(g=>{const h=g.icon;return e.jsxs("button",{onClick:()=>s(g.path),className:`text-left p-4 rounded-xl border ${g.color} hover:shadow-sm transition-all group`,children:[e.jsx(h,{size:20,className:"mb-2 opacity-70 group-hover:opacity-100"}),e.jsx("div",{className:"font-medium text-sm",children:g.label}),e.jsx("div",{className:"text-xs opacity-60 mt-0.5",children:g.desc})]},g.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&&` · 耗时 ${_a(t.duration)}`,t.version&&` · v${t.version}`]})]})},En=()=>{const[t,s]=n.useState({task:{status:"idle"}}),[a,l]=n.useState([]),[r,i]=n.useState(!1),[c,o]=n.useState(null),[j,g]=n.useState(""),[h,y]=n.useState(!1),[x,m]=n.useState(!0),[u,A]=n.useState(""),[S,I]=n.useState(null),P=n.useRef(null),B=n.useCallback(async()=>{try{const k=await re.wikiStatus();return s(k),k}catch{return null}},[]),R=n.useCallback(async()=>{try{const k=await re.wikiFiles();l(k.files||[]),i(k.exists)}catch{}},[]),K=n.useCallback(async()=>{try{const k=await re.wikiFileContent("meta.json");k!=null&&k.content&&I(JSON.parse(k.content))}catch{}},[]);n.useEffect(()=>{(async()=>{m(!0),await Promise.all([B(),R(),K()]),m(!1)})()},[B,R,K]),n.useEffect(()=>{if(t.task.status==="running"){let k=0;P.current=setInterval(async()=>{const b=await B();k++,k%3===0&&await R(),b&&b.task.status!=="running"&&(await Promise.all([R(),K()]),P.current&&clearInterval(P.current))},1500)}else P.current&&clearInterval(P.current);return()=>{P.current&&clearInterval(P.current)}},[t.task.status,B,R,K]);const X=async()=>{try{await re.wikiUpdate(),s(k=>({...k,task:{...k.task,status:"running",progress:0,message:"增量更新中..."}}))}catch(k){console.error("Wiki update failed:",k)}},$=async k=>{if(k!=="meta.json"){o(k),y(!0);try{const b=await re.wikiFileContent(k);g(b.content)}catch{g(`# 加载失败
137
+ `).length+1;p(xe,Ie),console.log(`✓ 已插入代码片段: ${ye.title}`)}else console.log("[Execute] 用户取消了选择")}else M.type==="search"&&console.warn("[Execute] 未找到匹配的搜索结果");se.success&&console.log(`✓ 指令已执行: ${se.message}`)}catch(J){console.error(`✗ 错误: ${J instanceof Error?J.message:"执行失败"}`)}finally{x(!1)}},ue=(M,ee=60)=>{if(M.length<=ee)return M;const J=M.split("/");if(J.length<=2)return M;const se=J[J.length-1],V=J.slice(0,2).join("/");if(V.length+se.length+5>ee){const ae=ee-se.length-5;return`${V.substring(0,Math.max(10,ae))}/.../${se}`}const Q=ee-V.length-se.length-5;if(Q>0&&J.length>3){let ye=J.slice(2,-1).join("/");return ye.length>Q&&(ye="..."),`${V}/${ye}/${se}`}return`${V}/.../${se}`},_=(M,ee=0)=>{if(!M)return null;if(M.type==="folder"){const J=B.has(M.path);return e.jsxs("div",{children:[e.jsxs("div",{className:"file-tree-item folder-item",onClick:()=>{const se=new Set(B);J?se.delete(M.path):se.add(M.path),R(se)},style:{paddingLeft:`${ee*16}px`},children:[e.jsx(Ct,{size:T.sm,className:`folder-toggle ${J?"expanded":""}`}),e.jsx(Ds,{size:T.sm,className:"folder-icon"}),e.jsx("span",{className:"file-name",children:M.name})]}),J&&M.children&&e.jsx("div",{children:M.children.map(se=>_(se,ee+1))})]},M.path)}else return e.jsxs("div",{className:`file-tree-item file-item ${K===M.path?"active":""}`,onClick:()=>f(M.path),style:{paddingLeft:`${ee*16}px`},children:[e.jsx(Ps,{size:T.sm,className:"file-icon"}),e.jsx("span",{className:"file-name",children:M.name})]},M.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:()=>S(!A),title:"切换侧栏",children:e.jsx(ul,{size:T.md})}),e.jsxs("div",{className:"file-info",title:K,children:[e.jsx(ps,{size:T.sm}),e.jsx("span",{className:"file-name",children:ue(K||"untitled.js",80)})]})]}),e.jsxs("div",{className:"toolbar-right",children:[e.jsx("button",{className:"toolbar-btn",onClick:w,title:"保存",children:e.jsx(Qt,{size:T.md})}),e.jsx("button",{className:"toolbar-btn",onClick:Z,title:"清空",children:e.jsx(tt,{size:T.md})}),e.jsx("button",{className:"toolbar-btn",title:"更多选项",children:e.jsx(pl,{size:T.md})})]})]}),e.jsxs("div",{className:"xcode-main",children:[A&&e.jsxs("div",{className:"xcode-sidebar",children:[e.jsxs("div",{className:"sidebar-header",children:[e.jsx(Ds,{size:T.md}),e.jsx("h3",{children:"文件浏览"})]}),e.jsx("div",{className:"file-tree",children:I?_(I):e.jsxs("div",{className:"empty-state",style:{padding:"16px 8px"},children:[e.jsx(Ps,{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:i.content,onChange:M=>p(M,r.current),onCursorChange:O,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 ",i.cursorLine+1,", Col ",i.cursorCol+1]}),e.jsx("span",{children:"|"}),e.jsxs("span",{children:[i.content.length," characters"]}),e.jsx("span",{children:"|"}),e.jsxs("span",{children:[i.content.split(`
138
+ `).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:T.md}),e.jsx("h3",{children:"检测到的指令"}),e.jsx("span",{className:"count",children:o.length})]}),o.length===0?e.jsxs("div",{className:"empty-state",children:[e.jsx(Ue,{size:32}),e.jsx("p",{children:"暂无指令"}),e.jsx("small",{children:"在代码中添加 // as:search 来创建指令"})]}):e.jsx("div",{className:"directives-list",children:o.map((M,ee)=>e.jsxs("div",{className:`directive-card ${M.type} ${$===ee?"active":""}`,onClick:()=>H(ee),children:[e.jsxs("div",{className:"directive-header",children:[e.jsx("div",{className:"type-badge",children:M.type.toUpperCase()}),e.jsxs("div",{className:"line-badge",children:["L",M.line+1]})]}),e.jsx("div",{className:"directive-query",children:M.query}),e.jsx("button",{className:"execute-btn",onClick:J=>{J.stopPropagation(),q(M)},disabled:y,children:y&&$===ee?e.jsxs(e.Fragment,{children:[e.jsx(Te,{size:T.xs,className:"spin"}),"执行中..."]}):e.jsxs(e.Fragment,{children:[e.jsx(hl,{size:T.xs}),"执行"]})})]},ee))})]}),g&&e.jsxs("div",{className:"result-section result",children:[e.jsxs("div",{className:"section-header",children:[e.jsx(dt,{size:T.md}),e.jsx("h3",{children:"执行结果"})]}),e.jsx("div",{className:"result-content",children:e.jsx("pre",{children:g})})]})]})]}),m&&e.jsx("div",{className:"result-modal-backdrop",onClick:()=>u(!1),children:e.jsxs("div",{className:"result-modal",onClick:M=>M.stopPropagation(),children:[e.jsxs("div",{className:"result-modal-header",children:[e.jsx("h2",{children:"执行结果"}),e.jsx("button",{className:"result-modal-close",onClick:()=>u(!1),children:"✕"})]}),e.jsx("div",{className:"result-modal-content",children:e.jsx("pre",{children:g})}),e.jsxs("div",{className:"result-modal-footer",children:[e.jsx("button",{className:"result-modal-btn",onClick:()=>{navigator.clipboard.writeText(g)},children:"复制"}),e.jsx("button",{className:"result-modal-btn",onClick:()=>u(!1),children:"关闭"})]})]})})]})},is={index:{icon:Ye,color:"text-blue-600",label:"项目概述"},architecture:{icon:Qe,color:"text-violet-600",label:"架构总览"},"getting-started":{icon:xt,color:"text-emerald-600",label:"快速上手"},protocols:{icon:Ue,color:"text-amber-600",label:"协议与组件"},components:{icon:xt,color:"text-emerald-600",label:"组件清单"},patterns:{icon:Ue,color:"text-amber-600",label:"代码模式"},module:{icon:Tt,color:"text-cyan-600",label:"模块文档"},document:{icon:et,color:"text-orange-600",label:"开发文档"},_index:{icon:Wt,color:"text-slate-500",label:"目录索引"}};function vn(t){var a;const s=((a=t.split("/").pop())==null?void 0:a.replace(".md",""))||"";return s==="_index"?is._index:t.startsWith("modules/")?is.module:t.startsWith("documents/")?is.document:is[s]||{icon:et,color:"text-slate-500",label:"文档"}}const wn={"cursor-devdocs":{label:"Cursor Docs",color:"text-orange-700",bg:"bg-orange-50 border-orange-200"}},kn={modules:"模块",documents:"开发文档"};function Ea(t){return t<1e3?`${t}ms`:`${(t/1e3).toFixed(1)}s`}function Cn(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 Sn=({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:T.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:T.md,className:"text-amber-600"})}),e.jsx("span",{className:"text-sm text-amber-700",children:"检测到代码变更,Wiki 可能已过期,建议增量更新"})]}):null;function In(t,s){const a=[],l=new Map((s==null?void 0:s.map(g=>[g.path,g]))||[]),r=[],i=new Map;for(const g of t){const h=g.path.split("/"),y=l.get(g.path);if(h.length===1)r.push({name:h[0],path:g.path,isDir:!1,file:g,metaInfo:y});else{const x=h[0];i.has(x)||i.set(x,[]),i.get(x).push({name:h.slice(1).join("/"),path:g.path,isDir:!1,file:g,metaInfo:y})}}const c=["index.md","architecture.md","getting-started.md","patterns.md","protocols.md","components.md"];r.sort((g,h)=>{const y=c.indexOf(g.name),x=c.indexOf(h.name);return y!==-1&&x!==-1?y-x:y!==-1?-1:x!==-1?1:g.name.localeCompare(h.name)}),a.push(...r);const o=["modules","patterns","documents"],j=[...i.entries()].sort(([g],[h])=>{const y=o.indexOf(g),x=o.indexOf(h);return y!==-1&&x!==-1?y-x:y!==-1?-1:x!==-1?1:g.localeCompare(h)});for(const[g,h]of j){const y=h.filter(x=>!x.name.startsWith("_index")).sort((x,m)=>x.name.localeCompare(m.name));a.push({name:g,path:g,isDir:!0,children:y})}return a}const $n=({tree:t,selectedFile:s,onSelect:a,searchQuery:l})=>{const[r,i]=n.useState(new Set(["modules","documents"])),c=g=>{i(h=>{const y=new Set(h);return y.has(g)?y.delete(g):y.add(g),y})},j=(g=>{if(!l)return g;const h=l.toLowerCase();return g.filter(y=>{var x;return y.isDir?(x=y.children)==null?void 0:x.some(m=>m.name.toLowerCase().includes(h)||m.path.toLowerCase().includes(h)):y.name.toLowerCase().includes(h)||y.path.toLowerCase().includes(h)})})(t);return e.jsx("div",{className:"space-y-0.5",children:j.map(g=>{var h;if(g.isDir){const y=r.has(g.path),x=l.toLowerCase(),m=l?(h=g.children)==null?void 0:h.filter(u=>u.name.toLowerCase().includes(x)||u.path.toLowerCase().includes(x)):g.children;return e.jsxs("div",{children:[e.jsxs("button",{onClick:()=>c(g.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:[y?e.jsx(Ct,{size:14,className:"text-slate-400 flex-shrink-0"}):e.jsx(st,{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:kn[g.name]||g.name}),e.jsx("span",{className:"ml-auto text-xs text-slate-400",children:(m==null?void 0:m.length)||0})]}),y&&m&&e.jsx("div",{className:"ml-3",children:m.map(u=>e.jsx(ra,{node:u,isActive:s===u.path,onSelect:a},u.path))})]},g.path)}return e.jsx(ra,{node:g,isActive:s===g.path,onSelect:a},g.path)})})},ra=({node:t,isActive:s,onSelect:a})=>{var o,j;const l=vn(t.path),r=l.icon,i=(o=t.metaInfo)==null?void 0:o.polished,c=(j=t.metaInfo)==null?void 0:j.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(r,{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:[i&&e.jsx("span",{title:"AI 增强",children:e.jsx(Ue,{size:10,className:"text-violet-400"})}),c&&e.jsx("span",{title:`来源: ${c}`,children:e.jsx(gl,{size:10,className:"text-orange-400"})})]})]})},zn=({filePath:t,content:s,loading:a,meta:l,onBack:r})=>{var y;const[i,c]=n.useState(!1),o=(y=l==null?void 0:l.files)==null?void 0:y.find(x=>x.path===t),j=()=>{navigator.clipboard.writeText(s),c(!0),setTimeout(()=>c(!1),2e3)},g=t.split("/"),h=g.map((x,m)=>({label:m===g.length-1?x.replace(".md",""):x,isLast:m===g.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:r,className:"p-1.5 hover:bg-slate-200 rounded-lg transition-colors lg:hidden",title:"返回文件列表",children:e.jsx(bl,{size:T.md})}),e.jsxs("div",{className:"flex items-center gap-1 text-sm",children:[e.jsx(Ye,{size:14,className:"text-slate-400"}),e.jsx("span",{className:"text-slate-400",children:"wiki"}),h.map((x,m)=>e.jsxs(St.Fragment,{children:[e.jsx(st,{size:12,className:"text-slate-300"}),e.jsx("span",{className:x.isLast?"font-medium text-slate-700":"text-slate-400",children:x.label})]},m))]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[(o==null?void 0:o.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(Ue,{size:10}),"AI 增强"]}),(o==null?void 0:o.source)&&(()=>{const x=wn[o.source];return e.jsx("span",{className:`flex items-center gap-1 text-xs border px-2 py-0.5 rounded-full ${(x==null?void 0:x.bg)||"bg-slate-50 border-slate-200"} ${(x==null?void 0:x.color)||"text-slate-600"}`,children:(x==null?void 0:x.label)||o.source})})(),e.jsxs("button",{onClick:j,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:[i?e.jsx(ft,{size:12,className:"text-emerald-500"}):e.jsx(Et,{size:12}),i?"已复制":"复制"]})]})]}),e.jsx("div",{className:"flex-1 overflow-auto scrollbar-light",style:{scrollbarGutter:"stable"},children:a?e.jsx("div",{className:"flex items-center justify-center py-20",children:e.jsx(Te,{size:T.xl,className:"text-blue-500 animate-spin"})}):e.jsx("div",{className:"px-8 py-6 max-w-4xl mx-auto",children:e.jsx(mt,{content:s,className:"wiki-reader"})})})]})},An=()=>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(Ye,{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"})," 增量更新"]})]}),En=({meta:t,onSelectFile:s,isGenerating:a,progress:l,message:r})=>{var j;const i=[{path:"index.md",label:"项目概述",desc:"项目信息、技术栈与数据统计",icon:Ye,color:"bg-blue-50 text-blue-600 border-blue-200"},{path:"architecture.md",label:"架构总览",desc:"模块依赖图、SPM Target 结构",icon:Qe,color:"bg-violet-50 text-violet-600 border-violet-200"},{path:"getting-started.md",label:"快速上手",desc:"构建、运行与入口分析",icon:xt,color:"bg-emerald-50 text-emerald-600 border-emerald-200"},{path:"protocols.md",label:"协议与组件",desc:"核心协议、委托和组件关系",icon:Ue,color:"bg-amber-50 text-amber-600 border-amber-200"}],c=new Set(((j=t==null?void 0:t.files)==null?void 0:j.map(g=>g.path||g.name))??[]),o=i.filter(g=>c.size===0||c.has(g.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(zs,{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:r||"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(et,{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:o.map(g=>{const h=g.icon;return e.jsxs("button",{onClick:()=>s(g.path),className:`text-left p-4 rounded-xl border ${g.color} hover:shadow-sm transition-all group`,children:[e.jsx(h,{size:20,className:"mb-2 opacity-70 group-hover:opacity-100"}),e.jsx("div",{className:"font-medium text-sm",children:g.label}),e.jsx("div",{className:"text-xs opacity-60 mt-0.5",children:g.desc})]},g.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&&` · 耗时 ${Ea(t.duration)}`,t.version&&` · v${t.version}`]})]})},Tn=()=>{const[t,s]=n.useState({task:{status:"idle"}}),[a,l]=n.useState([]),[r,i]=n.useState(!1),[c,o]=n.useState(null),[j,g]=n.useState(""),[h,y]=n.useState(!1),[x,m]=n.useState(!0),[u,A]=n.useState(""),[S,I]=n.useState(null),P=n.useRef(null),B=n.useCallback(async()=>{try{const k=await re.wikiStatus();return s(k),k}catch{return null}},[]),R=n.useCallback(async()=>{try{const k=await re.wikiFiles();l(k.files||[]),i(k.exists)}catch{}},[]),K=n.useCallback(async()=>{try{const k=await re.wikiFileContent("meta.json");k!=null&&k.content&&I(JSON.parse(k.content))}catch{}},[]);n.useEffect(()=>{(async()=>{m(!0),await Promise.all([B(),R(),K()]),m(!1)})()},[B,R,K]),n.useEffect(()=>{if(t.task.status==="running"){let k=0;P.current=setInterval(async()=>{const b=await B();k++,k%3===0&&await R(),b&&b.task.status!=="running"&&(await Promise.all([R(),K()]),P.current&&clearInterval(P.current))},1500)}else P.current&&clearInterval(P.current);return()=>{P.current&&clearInterval(P.current)}},[t.task.status,B,R,K]);const X=async()=>{try{await re.wikiUpdate(),s(k=>({...k,task:{...k.task,status:"running",progress:0,message:"增量更新中..."}}))}catch(k){console.error("Wiki update failed:",k)}},$=async k=>{if(k!=="meta.json"){o(k),y(!0);try{const b=await re.wikiFileContent(k);g(b.content)}catch{g(`# 加载失败
139
139
 
140
- 无法读取文件内容。`)}finally{y(!1)}}},H=()=>{o(null),g("")},C=n.useMemo(()=>a.filter(k=>k.path!=="meta.json"),[a]),p=n.useMemo(()=>In(C,S==null?void 0:S.files),[C,S]);if(x)return e.jsx("div",{className:"flex items-center justify-center h-64",children:e.jsx(Ee,{size:E.xl,className:"text-blue-500 animate-spin"})});const O=!r&&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(Sn,{task:t.task,wiki:t.wiki}),O?e.jsx(An,{}):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(Ee,{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 ${c?"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(Ye,{size:16,className:"text-blue-500"}),e.jsx("span",{className:"text-sm font-semibold text-slate-700",children:"Wiki"}),(S==null?void 0:S.version)&&e.jsxs("span",{className:"text-[10px] text-slate-300",children:["v",S.version]})]}),e.jsxs("div",{className:"flex items-center gap-1",children:[r&&e.jsxs("span",{className:"text-[10px] text-slate-400",children:[C.length," 篇"]}),t.task.status!=="running"&&r&&e.jsx("button",{onClick:X,title:"增量更新",className:"p-1 rounded-md text-blue-500 hover:bg-blue-50 transition-colors",children:e.jsx(pt,{size:13})})]})]}),e.jsxs("div",{className:"relative",children:[e.jsx(dt,{size:14,className:"absolute left-3 top-1/2 -translate-y-1/2 text-slate-400"}),e.jsx("input",{type:"text",placeholder:"搜索文件...",value:u,onChange:k=>A(k.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($n,{tree:p,selectedFile:c,onSelect:$,searchQuery:u}),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(Ee,{size:12,className:"text-blue-500 animate-spin flex-shrink-0"}),e.jsx("span",{className:"text-[11px] text-blue-600 leading-tight",children:"文件生成中,新文档将自动出现…"})]})]}),(S==null?void 0:S.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:Cn(S.generatedAt)}),S.duration!=null&&e.jsxs("span",{children:["· ",_a(S.duration)]})]})})]}),e.jsx("div",{className:`flex-1 bg-white border border-slate-200 rounded-xl overflow-hidden flex flex-col min-h-0 ${c?"":"hidden lg:flex"}`,children:c?e.jsx(zn,{filePath:c,content:j,loading:h,meta:S,onBack:H}):e.jsx(_n,{meta:S,onSelectFile:$,isGenerating:t.task.status==="running",progress:t.task.progress,message:t.task.message})})]})]})]})},Tn={authority:0,guardUsageCount:0,humanUsageCount:0,aiUsageCount:0,lastUsedAt:null,authorityScore:0},Mn=({editingRecipe:t,setEditingRecipe:s,handleSaveRecipe:a,closeRecipeEdit:l,isSavingRecipe:r=!1})=>{var y,x,m,u,A,S,I,P,B,R,K,X,$,H,C,p,O;const[i,c]=n.useState("preview"),o=n.useRef(!0);n.useEffect(()=>()=>{o.current=!1},[]);const j=(()=>{const k=(t.language||"").toLowerCase();return["objectivec","objc","objective-c","obj-c"].includes(k)?"objectivec":t.language||"swift"})(),g=async k=>{try{if(await re.setRecipeAuthority(t.name,k),o.current){const b=t.stats?{...t.stats,authority:k}:{...Tn,authority:k};s({...t,stats:b})}}catch(b){console.warn("设置权威分失败:",b==null?void 0:b.message)}},h=k=>{if(!k)return"";const b=typeof k=="string"?new Date(k).getTime():k;return isNaN(b)?"":new Date(b).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 b={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:ht},fact:{label:"Fact",color:"text-cyan-700",bg:"bg-cyan-50",border:"border-cyan-200",icon:Ye}}[t.kind];if(!b)return null;const f=b.icon;return e.jsxs("span",{className:`text-[10px] font-bold px-2 py-1 rounded uppercase flex items-center gap-1 border ${b.bg} ${b.color} ${b.border}`,children:[e.jsx(f,{size:E.sm}),b.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:"权威分"}),i==="preview"?e.jsx("span",{className:"text-sm text-slate-700",children:((y=t.stats)==null?void 0:y.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:((x=t.stats)==null?void 0:x.authority)??3,onChange:k=>g(parseInt(k.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:()=>c("preview"),className:`px-4 py-1.5 rounded-md text-xs font-bold transition-all flex items-center gap-2 ${i==="preview"?"bg-white shadow-sm text-blue-600":"text-slate-400"}`,children:[e.jsx(Xt,{size:E.sm})," Preview"]}),e.jsxs("button",{onClick:()=>c("edit"),className:`px-4 py-1.5 rounded-md text-xs font-bold transition-all flex items-center gap-2 ${i==="edit"?"bg-white shadow-sm text-blue-600":"text-slate-400"}`,children:[e.jsx(bt,{size:E.sm})," Edit"]})]}),e.jsx("button",{onClick:l,className:"p-2 hover:bg-slate-100 rounded-full",children:e.jsx(Ke,{size:E.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:i==="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:k=>s({...t,name:k.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:k=>s({...t,description:k.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(et,{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:((m=t.content)==null?void 0:m.markdown)||"",onChange:k=>s({...t,content:{...t.content,markdown:k}}),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(At,{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:((u=t.content)==null?void 0:u.pattern)||"",onChange:k=>s({...t,content:{...t.content,pattern:k}}),language:j,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:((A=t.content)==null?void 0:A.rationale)||"",onChange:k=>s({...t,content:{...t.content,rationale:k.target.value}}),placeholder:"为何采用此方案..."})]})]}):e.jsxs("div",{className:"flex-1 overflow-y-auto space-y-6 scrollbar-light",children:[(()=>{const k=[["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?h(t.updatedAt):void 0]].filter(([,b])=>!!b);return k.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:k.map(([b,f])=>e.jsxs("div",{className:"flex flex-col",children:[e.jsx("span",{className:"text-[10px] text-slate-400 font-bold uppercase mb-1",children:b}),e.jsx("span",{className:"text-sm text-slate-700 break-all font-medium",children:f})]},b))})]})})(),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})]}),((S=t.content)==null?void 0:S.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(et,{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(mt,{content:t.content.markdown})})})]}),((I=t.content)==null?void 0:I.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(At,{size:11,className:"text-emerald-500"})," 代码 / 标准用法"]}),e.jsx(rt,{code:t.content.pattern,language:j,showLineNumbers:!0})]}),((P=t.content)==null?void 0:P.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((k,b)=>typeof k=="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:b+1}),e.jsx("p",{className:"text-xs text-slate-700 leading-relaxed",children:k})]},b):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:b+1}),k.title&&e.jsx("span",{className:"text-xs font-bold text-slate-700",children:k.title})]}),k.description&&e.jsx("p",{className:"text-xs text-slate-600 ml-7 leading-relaxed",children:k.description}),k.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:k.code})]},b))})]}),((R=t.content)==null?void 0:R.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((k,b)=>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(xt,{size:11,className:"text-blue-400"}),e.jsx("code",{className:"text-[10px] font-mono text-slate-600",children:k.file})]}),k.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:k.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:k.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:k.after})]})]},b))})]}),((K=t.content)==null?void 0:K.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((k,b)=>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:k},b))})]}),!!(t.constraints&&((X=t.constraints.guards)!=null&&X.length||($=t.constraints.boundaries)!=null&&$.length||(H=t.constraints.preconditions)!=null&&H.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((k,b)=>e.jsxs("li",{className:"flex gap-2 items-start",children:[e.jsx("span",{className:`text-xs mt-0.5 ${k.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:k.pattern}),k.message&&e.jsxs("span",{className:"text-xs text-slate-400",children:["— ",k.message]})]},b))})]}),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((k,b)=>e.jsxs("li",{className:"flex gap-2",children:[e.jsx("span",{className:"text-orange-400",children:"●"}),k]},b))})]}),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((k,b)=>e.jsxs("li",{className:"flex gap-2",children:[e.jsx("span",{className:"text-blue-400",children:"◆"}),k]},b))})]}),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((k,b)=>e.jsxs("li",{className:"flex gap-2",children:[e.jsx("span",{className:"text-pink-400",children:"⚡"}),k]},b))})]})]}),t.relations&&Object.entries(t.relations).some(([,k])=>Array.isArray(k)&&k.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:k,label:b,color:f,icon:w})=>{var q;const Z=(q=t.relations)==null?void 0:q[k];return!Z||!Array.isArray(Z)||Z.length===0?null:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsxs("span",{className:`text-xs font-mono ${f} w-16 shrink-0 pt-0.5`,children:[w," ",b]}),e.jsx("div",{className:"flex flex-wrap gap-1.5",children:Z.map((ue,M)=>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 ue=="string"?ue:ue.id||ue.title||JSON.stringify(ue)},M))})]},k)})})]}),!((p=t.content)!=null&&p.markdown)&&!((O=t.content)!=null&&O.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:r,className:"px-4 py-2 text-slate-600 font-medium disabled:opacity-50",children:"Cancel"}),e.jsxs("button",{onClick:a,disabled:r,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:[r?e.jsx(Ee,{size:E.lg,className:"animate-spin"}):e.jsx(Qt,{size:E.lg}),r?"保存中...":"Save Changes"]})]})]})]})},Rn=({setShowCreateModal:t,createPath:s,setCreatePath:a,handleCreateFromPath:l,handleCreateFromClipboard:r,isExtracting:i})=>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(gt,{size:E.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(Ke,{size:E.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(fa,{size:E.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:c=>a(c.target.value)}),e.jsx("button",{onClick:l,disabled:!s||i,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(fl,{size:E.sm})," Import from Clipboard"]}),e.jsxs("button",{onClick:()=>r(),disabled:i,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(Je,{size:E.lg})," Use Copied Code"]})]})]}),i&&e.jsxs("div",{className:"bg-blue-600 text-white p-4 flex items-center justify-center gap-3 animate-pulse",children:[e.jsx(Yt,{size:E.lg,className:"animate-spin"}),e.jsx("span",{className:"font-bold text-sm",children:"AI is thinking..."})]})]})]});function Ln(t){if(!t)return"";if(typeof t=="object"){const r=t.code||t.pattern||t.markdown||t.snippet||t.body||"";if(r)return r}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 Dn=({searchQ:t,insertPath:s,onClose:a})=>{const[l,r]=n.useState([]),[i,c]=n.useState(!0),[o,j]=n.useState(null),g=n.useRef(!0),h=n.useRef(null);n.useEffect(()=>(g.current=!0,h.current=new AbortController,re.search(t||"",{mode:"bm25",type:"recipe",signal:h.current.signal}).then(x=>{g.current&&r((x.items||[]).map(m=>({name:(m.title||m.name||"")+".md",path:"",content:m.content,qualityScore:(m.quality||{}).overall||m.qualityScore||0,recommendReason:""})))}).catch(x=>{x.name!=="AbortError"&&g.current&&r([])}).finally(()=>{g.current&&c(!1)}),()=>{g.current=!1,h.current&&h.current.abort()}),[t]);const y=async x=>{j(x.name);try{const m=Ln(x.content);await re.insertAtSearchMark({path:s,content:m}),g.current&&(alert("✅ 已插入到 "+s),a())}catch{g.current&&alert("❌ 插入失败")}finally{g.current&&j(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(dt,{size:E.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(Ke,{size:E.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:i?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(x=>e.jsx("li",{children:e.jsxs("button",{type:"button",onClick:()=>y(x),disabled:o!==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:x.name}),(x.qualityScore!==void 0||x.recommendReason)&&e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[x.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:["🤖 质量: ",(x.qualityScore*100).toFixed(0),"%"]}),x.recommendReason&&e.jsx("span",{className:"text-xs text-slate-600 italic truncate max-w-xs",children:x.recommendReason})]})]}),o===x.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(ja,{size:E.md})," 插入"]})]})},x.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:""}],Pn=({onClose:t,onSaved:s})=>{const[a,l]=n.useState(!0),[r,i]=n.useState(!1),[c,o]=n.useState(!1),[j,g]=n.useState("google"),[h,y]=n.useState("gemini-2.0-flash"),[x,m]=n.useState(""),[u,A]=n.useState(""),[S,I]=n.useState(!1),[P,B]=n.useState({}),[R,K]=n.useState(!1);n.useEffect(()=>{X()},[]);const X=async()=>{l(!0);try{const b=await re.getLlmEnvConfig();o(b.hasEnvFile);const f=b.vars||{};f.ASD_AI_PROVIDER&&g(f.ASD_AI_PROVIDER),f.ASD_AI_MODEL&&y(f.ASD_AI_MODEL),f.ASD_AI_PROXY&&A(f.ASD_AI_PROXY),B(f)}catch{}finally{l(!1)}},$=Ns.find(b=>b.id===j),H=($==null?void 0:$.keyEnv)||"",C=H?!!P[H]:!0,p=b=>{g(b);const f=Ns.find(w=>w.id===b);f&&y(f.defaultModel),m("")},O=async()=>{if(j){if(H&&!C&&!x.trim()){alert("请填写 API Key");return}i(!0),K(!1);try{await re.saveLlmEnvConfig({provider:j,model:h||void 0,apiKey:x.trim()||void 0,proxy:u.trim()||void 0}),K(!0),setTimeout(()=>{s(),t()},800)}catch(b){alert((b==null?void 0:b.message)||"保存失败")}finally{i(!1)}}},k=b=>!b||b.length<10?b?"••••••":"":`${b.slice(0,6)}••••${b.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:b=>b.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(Ke,{size:E.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(Ee,{size:24,className:"animate-spin text-blue-500"})}):e.jsxs(e.Fragment,{children:[!c&&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(zt,{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(b=>e.jsx("button",{type:"button",onClick:()=>p(b.id),className:`px-3 py-2 rounded-lg text-sm font-medium border transition-all ${j===b.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:b.label},b.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:h,onChange:b=>y(b.target.value),placeholder:($==null?void 0:$.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"})]}),H&&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:["(已配置: ",k(P[H]),")"]})]}),e.jsxs("div",{className:"relative",children:[e.jsx("input",{type:S?"text":"password",value:x,onChange:b=>m(b.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:()=>I(b=>!b),className:"absolute right-2 top-1/2 -translate-y-1/2 p-1 text-slate-400 hover:text-slate-600",children:S?e.jsx(jl,{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:u,onChange:b=>A(b.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:O,disabled:r||a||R,className:`flex items-center gap-2 px-5 py-2 rounded-lg text-sm font-medium transition-all ${R?"bg-green-500 text-white":"bg-blue-600 text-white hover:bg-blue-700 shadow-sm"} disabled:opacity-60`,children:[r?e.jsx(Ee,{size:16,className:"animate-spin"}):R?e.jsx(es,{size:16}):e.jsx(Qt,{size:16}),R?"已保存":"保存到 .env"]})]})]})})};class Fn extends St.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 Ft(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 On=()=>{var Le,ot;const t=Fl(),s=Bl((Le=t.user)==null?void 0:Le.role),a=ql(),l=()=>{const z=window.location.pathname.replace(/^\//,"").split("/")[0]||"";return zl.includes(z)?z:"help"},[r,i]=n.useState(null),[c,o]=n.useState(l()),[j,g]=n.useState(!1),[h,y]=n.useState(""),[x,m]=n.useState(!0),[u,A]=n.useState(null),[S,I]=n.useState([]),[P,B]=n.useState(null),[R,K]=n.useState(!1),[X,$]=n.useState({current:0,total:0,status:""}),[H,C]=n.useState([]),[p,O]=n.useState([]),[k,b]=n.useState(null),[f,w]=n.useState("All"),[Z,q]=n.useState(1),[ue,M]=n.useState(12),[T,ee]=n.useState(!1),[J,se]=n.useState(""),[V,Q]=n.useState(!1),[ae,ye]=n.useState(null),[Se,De]=n.useState(null),[D,_]=n.useState(!1),[xe,Ie]=n.useState(!0),[fe,Ae]=n.useState(!1),[Oe,_e]=n.useState(0),v=n.useRef(null),ne=n.useRef(null);n.useEffect(()=>{q(1)},[h,f]);const ve=()=>{v.current&&v.current.abort()};n.useEffect(()=>{let z=!1;const me=async()=>{var Y,ke,Ne;try{const we=await re.getSignalStatus();if(!z){const ze=((Y=we==null?void 0:we.suggestions)==null?void 0:Y.length)||0,Ce=((Ne=(ke=we==null?void 0:we.snapshot)==null?void 0:ke.lastResult)==null?void 0:Ne.newSuggestions)||0;_e(ze||Ce)}}catch{}};me();const ie=setInterval(me,300*1e3);return()=>{z=!0,clearInterval(ie)}},[]),n.useEffect(()=>{a.isAllDone&&L()},[a.isAllDone]),n.useEffect(()=>{if(a.candidateCreatedTick>0){const z=setTimeout(()=>L(),2e3);return()=>clearTimeout(z)}},[a.candidateCreatedTick]);const ce=(z,me)=>{o(z);const ie=me!=null&&me.preserveSearch&&window.location.search?window.location.search:"";window.history.pushState({},document.title,`/${z}${ie}`)},he=z=>{A(z),o("recipes");const me=new URLSearchParams(window.location.search);me.set("edit",encodeURIComponent(z.name)),window.history.pushState({},document.title,`/recipes?${me.toString()}`)},d=()=>{A(null),window.history.replaceState({},document.title,"/recipes")};n.useEffect(()=>{h===""&&ye(null)},[h]),n.useEffect(()=>{o(l())},[]),n.useEffect(()=>{if(!r)return;const z=window.location.pathname.replace(/^\//,"").split("/")[0],ie=new URLSearchParams(window.location.search).get("edit");if(z==="recipes"&&ie&&r.recipes)try{const Y=decodeURIComponent(ie),ke=r.recipes.find(Ne=>Ne.name===Y);ke&&!u&&(o("recipes"),he(ke))}catch{}},[r]),n.useEffect(()=>{L(),N(),pe();const z=()=>{o(l())};window.addEventListener("popstate",z);const me=new URLSearchParams(window.location.search),ie=me.get("action"),Y=me.get("path"),ke=me.get("q")||"";return ie==="search"&&Y?De({q:ke,path:Y}):ie==="create"&&Y&&(se(Y),ee(!0),me.get("autoScan")==="1"&&setTimeout(()=>F(Y),500)),ie&&window.history.replaceState({},document.title,window.location.pathname),()=>{window.removeEventListener("popstate",z)}},[]);const L=async()=>{m(!0);try{const z=await re.fetchData();i(z)}catch(z){le((z==null?void 0:z.message)||"无法加载项目数据",{title:"加载失败",type:"error"})}finally{m(!1)}},N=async()=>{try{const z=await re.fetchTargets();I(z)}catch(z){console.warn("删除候选残留失败:",z==null?void 0:z.message)}},pe=async()=>{try{const z=await re.getLlmEnvConfig();Ie(z.llmReady)}catch{}},W=async()=>{try{await re.syncToXcode(),le("Recipes 已同步到 Xcode CodeSnippets 目录",{title:"Xcode 同步成功"})}catch{le("请检查 Xcode 是否已安装并重试",{title:"同步失败",type:"error"})}},oe=async()=>{try{await re.refreshProject(),N(),le("Target 列表与文件树已更新",{title:"项目结构已刷新"})}catch{le("请确认项目路径有效后重试",{title:"刷新失败",type:"error"})}},F=async z=>{var me;Q(!0);try{const ie=await re.extractFromPath(z);O(ie.result.map(Y=>({...Ft(Y,"extract"),mode:"full",lang:"cn"}))),ce("spm"),ee(!1),L(),((me=ie.result)==null?void 0:me.length)>0&&le("提取结果已进入候选池,请在 Candidates 页审核",{title:"提取完成"})}catch{le("Extraction failed",{type:"error"})}finally{Q(!1)}},te=async()=>{var z;if(J){Q(!0);try{const me=await re.extractFromPath(J);O(me.result.map(ie=>({...Ft(ie,"extract"),mode:"full",lang:"cn"}))),ce("spm"),ee(!1),L(),((z=me.result)==null?void 0:z.length)>0?le(me.isMarked?"精准锁定标记代码,已加入候选池":"提取结果已加入候选池",{title:"提取完成"}):me.isMarked||le("未找到 ASD 标记,AI 将分析完整文件",{title:"提取中",type:"info"})}catch{le("Extraction failed",{type:"error"})}finally{Q(!1)}}},ge=async z=>{var me,ie,Y,ke;try{const Ne=await navigator.clipboard.readText();if(!Ne)return le("请先复制代码到剪贴板",{title:"剪贴板为空",type:"info"});le("已收到代码,AI 正在识别可复用模式...",{title:"剪贴板分析中",type:"info"}),Q(!0);const we=z||J;try{const ze=await re.extractFromText(Ne,we||void 0),Ce=ze._multipleCount;O([{...Ft(ze,"clipboard"),mode:"full",lang:"cn"}]),ce("spm"),ee(!1),L(),le(Ce?`已识别 ${Ce} 条 Recipe,请在候选池审核`:"提取结果已加入候选池",{title:"AI 识别完成"})}catch(ze){const Ce=((ie=(me=ze.response)==null?void 0:me.data)==null?void 0:ie.aiError)===!0,Fe=((ke=(Y=ze.response)==null?void 0:Y.data)==null?void 0:ke.error)||ze.message;Ce?le(Fe,{title:"AI 识别失败",type:"error"}):le(Fe,{title:"操作失败",type:"error"})}}catch{le("浏览器可能未授权剪贴板访问",{title:"剪贴板读取失败",type:"error"})}finally{Q(!1)}},G={"scan:started":{percent:5,status:"正在启动扫描..."},"scan:files-loaded":{percent:15,status:z=>`已加载 ${z.count||0} 个源文件`},"scan:reading":{percent:25,status:z=>`正在读取 ${z.count||0} 个文件内容...`},"scan:ai-extracting":{percent:40,status:"正在 AI 分析提取可复用模式..."},"scan:enriching":{percent:85,status:z=>`正在增强 ${z.recipeCount||0} 条结果...`},"scan:completed":{percent:95,status:"扫描完成,正在加载结果..."}},be=async z=>{var ie;if(R)return;v.current&&v.current.abort(),ne.current&&(clearInterval(ne.current),ne.current=null);const me=new AbortController;v.current=me,B(z.name),K(!0),O([]),b(null),C([]),$({current:0,total:100,status:"正在建立流式连接..."});try{const Y=await re.scanTargetStream(z,we=>{const ze=G[we.type];if(ze){const Ce=typeof ze.status=="function"?ze.status(we):ze.status;$({current:ze.percent,total:100,status:Ce})}we.type==="scan:files-loaded"&&we.files&&C(we.files),we.type==="scan:ai-extracting"&&(ne.current&&clearInterval(ne.current),ne.current=setInterval(()=>{$(Ce=>({...Ce,current:Math.min(Ce.current+1,80)}))},3e3)),(we.type==="scan:enriching"||we.type==="scan:completed")&&ne.current&&(clearInterval(ne.current),ne.current=null)},me.signal);ne.current&&(clearInterval(ne.current),ne.current=null),$({current:100,total:100,status:"扫描完成"});const ke=Y.recipes||[],Ne=Y.scannedFiles||[];if(ke.length>0||Ne.length>0){const we=typeof z=="string"?z:(z==null?void 0:z.name)||"unknown",ze=ke.map(Ce=>({...Ft(Ce,"ai-scan"),mode:"full",lang:"cn",candidateTargetName:we,scanMode:"target"}));O(ze),Ne.length>0&&C(Ne),L(),ke.length>0?le(`发现 ${ke.length} 条可复用代码模式,请在右侧审核`,{title:"Target 扫描完成"}):Y.message?le(Y.message,{title:"AI 扫描未返回结果",type:"error"}):le("该 Target 中未找到可复用的代码片段",{title:"扫描完成",type:"info"})}else le("请确认 Target 包含有效的源代码文件",{title:"扫描失败",type:"error"})}catch(Y){if(ne.current&&(clearInterval(ne.current),ne.current=null),Y.name==="AbortError")return;const ke=(ie=Y.message)==null?void 0:ie.includes("timeout"),Ne=ke?"扫描超时,请尝试减少 Target 文件数量":Y.message||"未知错误";le(Ne,{title:ke?"扫描超时":"扫描出错",type:"error"})}finally{v.current===me&&(K(!1),$({current:0,total:0,status:""}),v.current=null)}},Re=async()=>{var me,ie,Y,ke,Ne,we;if(R)return;v.current&&v.current.abort();const z=new AbortController;v.current=z,ce("candidates"),K(!0),O([]),b(null),C([]),$({current:0,total:100,status:"正在收集项目结构..."}),a.resetSession();try{const ze=await re.bootstrap(z.signal);$({current:100,total:100,status:"骨架已创建,正在后台填充..."}),ze.bootstrapSession&&a.initFromApiResponse(ze.bootstrapSession),L();const Ce=ze.report||{},Fe=((me=ze.targets)==null?void 0:me.length)||0,at=((ie=Ce.totals)==null?void 0:ie.files)||0,jt=((Y=Ce.totals)==null?void 0:Y.graphEdges)||0,Tt=ze.guardSummary,bs=Tt?`, Guard: ${Tt.totalViolations} 项违规`:"";le(`冷启动骨架已创建: ${Fe} 个 Target, ${at} 个文件, ${jt} 条依赖${bs},正在后台逐维度填充...`)}catch(ze){if(Wt.isCancel(ze))return;const Fe=ze.code==="ECONNABORTED"||((ke=ze.message)==null?void 0:ke.includes("timeout"))?"冷启动超时,请检查项目文件数量":((we=(Ne=ze.response)==null?void 0:Ne.data)==null?void 0:we.error)||ze.message;le(Fe,{type:"error"})}finally{v.current===z&&(K(!1),$({current:0,total:0,status:""}),v.current=null)}},Te=async()=>{var ke,Ne,we,ze;if(R)return;v.current&&v.current.abort();const z=new AbortController;v.current=z,ce("spm"),B("__project__"),K(!0),O([]),b(null),C([]),$({current:0,total:100,status:"正在收集所有 Target 文件..."});const me=[{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 ie=0;const Y=setInterval(()=>{ie=Math.min(ie+1,me.length);const Ce=me[ie-1];Ce&&$(Fe=>({...Fe,current:Ce.percent,status:Ce.status}))},15e3);try{const Ce=await re.scanProject(z.signal);clearInterval(Y),$({current:100,total:100,status:Ce.partial?"扫描部分完成(超时)":"全项目扫描完成"});const Fe=Ce.recipes||[],at=Ce.scannedFiles||[];if(Fe.length>0||at.length>0){const jt=Fe.map(Ta=>({...Ft(Ta,"ai-scan"),mode:"full",lang:"cn",candidateTargetName:"__project__",scanMode:"project"}));O(jt),C(at),b(Ce.guardAudit||null),L();const Tt=(ke=Ce.guardAudit)==null?void 0:ke.summary,bs=Tt?`, Guard: ${Tt.totalViolations} 处违反`:"",Ea=Ce.partial?"(部分结果,AI 超时)":"";le(`全项目扫描完成: ${Fe.length} 条候选${bs}${Ea}`)}else le("全项目扫描完成,未发现可提取内容")}catch(Ce){if(clearInterval(Y),Wt.isCancel(Ce))return;const at=Ce.code==="ECONNABORTED"||((Ne=Ce.message)==null?void 0:Ne.includes("timeout"))?"扫描超时,请尝试减少项目文件数量或分 Target 扫描":((ze=(we=Ce.response)==null?void 0:we.data)==null?void 0:ze.error)||Ce.message;le(at,{type:"error"})}finally{v.current===z&&(K(!1),$({current:0,total:0,status:""}),v.current=null)}},Me=(z,me)=>{const ie=[...p],Y={...ie[z],...me};ie[z]=Y,O(ie)},qe=async z=>{var me;if(!D){_(!0);try{const ie=(((me=z.content)==null?void 0:me.pattern)||"").trim(),Y=(()=>{if(!ie)return!1;const Fe=ie.split(`
141
- `).filter(jt=>jt.trim());return Fe.filter(jt=>/^\s*(#{1,6}\s|[-*>]\s|\d+\.\s)/.test(jt)).length<=Fe.length*.3})(),ke=(z.trigger||"").split(/[,,\s]+/).map(Fe=>Fe.trim()).filter(Boolean);if(Y&&ke.length===0){le("请输入 Trigger",{type:"error"}),_(!1);return}const Ne={title:z.title||"Untitled",description:z.description||"",trigger:ke.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},we=await re.knowledgeCreate(Ne);if(we!=null&&we.id)try{await re.knowledgeLifecycle(we.id,"publish")}catch(Fe){console.warn("auto-publish after save failed:",Fe)}le(Y?"已保存并发布为 Recipe":"已保存到 KB"),O(Fe=>Fe.filter(at=>at.title!==z.title));const ze=z.candidateTargetName,Ce=z.candidateId;if(ze&&Ce)try{await re.deleteCandidate(Ce)}catch{}L()}catch(ie){const Y=Bs(ie)??xs(ie);le(Y??"保存失败",{type:"error"})}finally{_(!1)}}},Ge=async()=>{var z,me;if(!(!u||D)){_(!0);try{const ie=u.id||((z=u.name)==null?void 0:z.replace(/\.md$/,"")),Y=typeof u.content=="string"?{pattern:u.content,markdown:"",rationale:"",steps:[],codeChanges:[],verification:null}:u.content||{};await re.knowledgeUpdate(ie,{title:((me=u.name)==null?void 0:me.replace(/\.md$/,""))||"",description:u.description||"",content:Y,tags:u.tags||[],kind:u.kind,language:u.language,category:u.category}),d(),L()}catch(ie){const Y=Bs(ie)??xs(ie);le(Y??"保存 Recipe 失败",{type:"error"})}finally{_(!1)}}},U=async z=>{if(window.confirm("Are you sure?"))try{await re.deleteRecipe(z),L()}catch(me){const ie=xs(me);le(ie??"删除失败",{type:"error"})}},$e=async(z,me)=>{try{await re.deleteCandidate(me),O(ie=>ie.filter(Y=>!(Y.candidateId===me&&Y.candidateTargetName===z))),i(ie=>{if(!(ie!=null&&ie.candidates))return ie;const Y={...ie.candidates};if(Y[z]){const ke=Y[z].items.filter(Ne=>Ne.id!==me);ke.length===0?delete Y[z]:Y[z]={...Y[z],items:ke}}return{...ie,candidates:Y}})}catch{le("操作失败",{type:"error"})}},We=async z=>{if(window.confirm(`确定移除「${z}」下的全部候选?`))try{await re.deleteAllCandidatesInTarget(z),L(),le(`已移除 ${z} 下的全部候选`)}catch{le("操作失败",{type:"error"})}},Be=async(z,me)=>{var ie,Y;try{await re.promoteToCandidate(z,z.candidateTargetName||P||"_review"),le("已加入 Candidate 待审核队列"),O(ke=>ke.filter((Ne,we)=>we!==me)),L()}catch(ke){const Ne=(Y=(ie=ke.response)==null?void 0:ie.data)==null?void 0:Y.error,we=typeof Ne=="string"?Ne:(Ne==null?void 0:Ne.message)||"创建 Candidate 失败";le(we,{type:"error"})}},Xe=((r==null?void 0:r.recipes)||[]).filter(z=>{var we,ze;if(ae)return ae.some(Ce=>Ce.metadata.type==="recipe"&&Ce.metadata.name===z.name);const me=z.name||"",ie=typeof z.content=="string"?z.content:[(we=z.content)==null?void 0:we.pattern,(ze=z.content)==null?void 0:ze.markdown].filter(Boolean).join(" "),Y=me.toLowerCase().includes(h.toLowerCase())||ie.toLowerCase().includes(h.toLowerCase())||(z.description||"").toLowerCase().includes(h.toLowerCase());if(f==="All")return Y;const ke=ie?ie.match(/category:\s*(.*)/):null,Ne=ke?ke[1].trim():"Utility";return Y&&Ne===f}).sort((z,me)=>{var ke,Ne,we,ze;if(ae){const Ce=((ke=ae.find(at=>at.metadata.name===z.name))==null?void 0:ke.similarity)||0;return(((Ne=ae.find(at=>at.metadata.name===me.name))==null?void 0:Ne.similarity)||0)-Ce}const ie=((we=z.stats)==null?void 0:we.authorityScore)??0;return(((ze=me.stats)==null?void 0:ze.authorityScore)??0)-ie}),je=S.filter(z=>z.name.toLowerCase().includes(h.toLowerCase())).sort((z,me)=>{const ie=ss(z.name),Y=ss(me.name);return ie&&!Y?1:!ie&&Y?-1:z.name.localeCompare(me.name)}),Pe=Object.values((r==null?void 0:r.candidates)||{}).reduce((z,me)=>z+me.items.length,0),He=c==="editor";return e.jsx(Fn,{children:e.jsx(dr,{children:e.jsxs("div",{className:`flex h-screen ${He?"bg-[#1e1e1e] text-slate-200":"bg-slate-50 text-slate-900"} overflow-hidden font-sans`,children:[e.jsx(Da,{position:"top-center",toastOptions:{duration:5e3},containerStyle:{top:24}}),e.jsx(Wl,{activeTab:c,navigateToTab:ce,candidateCount:Pe,signalSuggestionCount:Oe,isDarkMode:He,currentUser:s.user!=="anonymous"?s.user:void 0,currentRole:s.role,permissionMode:s.mode,onLogout:void 0,collapsed:j,onToggleCollapse:()=>g(z=>!z)}),e.jsxs("main",{className:"flex-1 flex flex-col overflow-hidden relative",children:[e.jsx(mr,{searchQuery:h,setSearchQuery:y,setShowCreateModal:ee,handleSyncToXcode:W,aiConfig:r==null?void 0:r.aiConfig,llmReady:xe,onOpenLlmConfig:()=>Ae(!0),onBeforeAiSwitch:ve,onAiConfigChange:L,isDarkMode:He,onSemanticSearchResults:z=>{ye(z),c!=="recipes"&&ce("recipes")}}),c==="recipes"&&e.jsx(ur,{selectedCategory:f,setSelectedCategory:w}),e.jsx("div",{className:`flex-1 ${c==="editor"||c==="wiki"?"overflow-hidden":"overflow-y-auto p-8"}`,children:x?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"})}):c==="recipes"?e.jsx(vr,{recipes:Xe,openRecipeEdit:he,handleDeleteRecipe:U,onRefresh:L,idTitleMap:r==null?void 0:r.idTitleMap,currentPage:Z,onPageChange:q,pageSize:ue,onPageSizeChange:z=>{M(z),q(1)}}):c==="guard"?e.jsx(Jr,{onRefresh:L}):c==="skills"?e.jsx(un,{onRefresh:L,signalSuggestionCount:Oe,onSuggestionCountChange:_e}):c==="candidates"?e.jsxs(e.Fragment,{children:[a.session&&e.jsx("div",{className:"mb-4",children:e.jsx(Nn,{session:a.session,isAllDone:a.isAllDone,reviewState:a.reviewState,onDismiss:()=>a.resetSession()})}),e.jsx(Tr,{data:r,isShellTarget:ss,isSilentTarget:_l,isPendingTarget:El,handleDeleteCandidate:$e,onEditRecipe:he,onColdStart:Re,isScanning:R,isBootstrapping:((ot=a.session)==null?void 0:ot.status)==="running",onRefresh:L,onAuditCandidate:(z,me)=>{var ke,Ne;const ie=(((ke=z.content)==null?void 0:ke.pattern)||"").trim(),Y=!!ie&&(()=>{const we=ie.split(`
140
+ 无法读取文件内容。`)}finally{y(!1)}}},H=()=>{o(null),g("")},C=n.useMemo(()=>a.filter(k=>k.path!=="meta.json"),[a]),p=n.useMemo(()=>In(C,S==null?void 0:S.files),[C,S]);if(x)return e.jsx("div",{className:"flex items-center justify-center h-64",children:e.jsx(Te,{size:T.xl,className:"text-blue-500 animate-spin"})});const O=!r&&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(Sn,{task:t.task,wiki:t.wiki}),O?e.jsx(An,{}):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 ${c?"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(Ye,{size:16,className:"text-blue-500"}),e.jsx("span",{className:"text-sm font-semibold text-slate-700",children:"Wiki"}),(S==null?void 0:S.version)&&e.jsxs("span",{className:"text-[10px] text-slate-300",children:["v",S.version]})]}),e.jsxs("div",{className:"flex items-center gap-1",children:[r&&e.jsxs("span",{className:"text-[10px] text-slate-400",children:[C.length," 篇"]}),t.task.status!=="running"&&r&&e.jsx("button",{onClick:X,title:"增量更新",className:"p-1 rounded-md text-blue-500 hover:bg-blue-50 transition-colors",children:e.jsx(pt,{size:13})})]})]}),e.jsxs("div",{className:"relative",children:[e.jsx(dt,{size:14,className:"absolute left-3 top-1/2 -translate-y-1/2 text-slate-400"}),e.jsx("input",{type:"text",placeholder:"搜索文件...",value:u,onChange:k=>A(k.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($n,{tree:p,selectedFile:c,onSelect:$,searchQuery:u}),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:"文件生成中,新文档将自动出现…"})]})]}),(S==null?void 0:S.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:Cn(S.generatedAt)}),S.duration!=null&&e.jsxs("span",{children:["· ",Ea(S.duration)]})]})})]}),e.jsx("div",{className:`flex-1 bg-white border border-slate-200 rounded-xl overflow-hidden flex flex-col min-h-0 ${c?"":"hidden lg:flex"}`,children:c?e.jsx(zn,{filePath:c,content:j,loading:h,meta:S,onBack:H}):e.jsx(En,{meta:S,onSelectFile:$,isGenerating:t.task.status==="running",progress:t.task.progress,message:t.task.message})})]})]})]})},Mn={authority:0,guardUsageCount:0,humanUsageCount:0,aiUsageCount:0,lastUsedAt:null,authorityScore:0},_n=({editingRecipe:t,setEditingRecipe:s,handleSaveRecipe:a,closeRecipeEdit:l,isSavingRecipe:r=!1})=>{var y,x,m,u,A,S,I,P,B,R,K,X,$,H,C,p,O;const[i,c]=n.useState("preview"),o=n.useRef(!0);n.useEffect(()=>()=>{o.current=!1},[]);const j=(()=>{const k=(t.language||"").toLowerCase();return["objectivec","objc","objective-c","obj-c"].includes(k)?"objectivec":t.language||"swift"})(),g=async k=>{try{if(await re.setRecipeAuthority(t.name,k),o.current){const b=t.stats?{...t.stats,authority:k}:{...Mn,authority:k};s({...t,stats:b})}}catch(b){console.warn("设置权威分失败:",b==null?void 0:b.message)}},h=k=>{if(!k)return"";const b=typeof k=="string"?new Date(k).getTime():k;return isNaN(b)?"":new Date(b).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 b={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:ht},fact:{label:"Fact",color:"text-cyan-700",bg:"bg-cyan-50",border:"border-cyan-200",icon:Ye}}[t.kind];if(!b)return null;const f=b.icon;return e.jsxs("span",{className:`text-[10px] font-bold px-2 py-1 rounded uppercase flex items-center gap-1 border ${b.bg} ${b.color} ${b.border}`,children:[e.jsx(f,{size:T.sm}),b.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:"权威分"}),i==="preview"?e.jsx("span",{className:"text-sm text-slate-700",children:((y=t.stats)==null?void 0:y.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:((x=t.stats)==null?void 0:x.authority)??3,onChange:k=>g(parseInt(k.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:()=>c("preview"),className:`px-4 py-1.5 rounded-md text-xs font-bold transition-all flex items-center gap-2 ${i==="preview"?"bg-white shadow-sm text-blue-600":"text-slate-400"}`,children:[e.jsx(Xt,{size:T.sm})," Preview"]}),e.jsxs("button",{onClick:()=>c("edit"),className:`px-4 py-1.5 rounded-md text-xs font-bold transition-all flex items-center gap-2 ${i==="edit"?"bg-white shadow-sm text-blue-600":"text-slate-400"}`,children:[e.jsx(bt,{size:T.sm})," Edit"]})]}),e.jsx("button",{onClick:l,className:"p-2 hover:bg-slate-100 rounded-full",children:e.jsx(Ke,{size:T.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:i==="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:k=>s({...t,name:k.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:k=>s({...t,description:k.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(et,{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:((m=t.content)==null?void 0:m.markdown)||"",onChange:k=>s({...t,content:{...t.content,markdown:k}}),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(At,{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:((u=t.content)==null?void 0:u.pattern)||"",onChange:k=>s({...t,content:{...t.content,pattern:k}}),language:j,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:((A=t.content)==null?void 0:A.rationale)||"",onChange:k=>s({...t,content:{...t.content,rationale:k.target.value}}),placeholder:"为何采用此方案..."})]})]}):e.jsxs("div",{className:"flex-1 overflow-y-auto space-y-6 scrollbar-light",children:[(()=>{const k=[["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?h(t.updatedAt):void 0]].filter(([,b])=>!!b);return k.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:k.map(([b,f])=>e.jsxs("div",{className:"flex flex-col",children:[e.jsx("span",{className:"text-[10px] text-slate-400 font-bold uppercase mb-1",children:b}),e.jsx("span",{className:"text-sm text-slate-700 break-all font-medium",children:f})]},b))})]})})(),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})]}),((S=t.content)==null?void 0:S.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(et,{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(mt,{content:t.content.markdown})})})]}),((I=t.content)==null?void 0:I.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(At,{size:11,className:"text-emerald-500"})," 代码 / 标准用法"]}),e.jsx(rt,{code:t.content.pattern,language:j,showLineNumbers:!0})]}),((P=t.content)==null?void 0:P.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((k,b)=>typeof k=="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:b+1}),e.jsx("p",{className:"text-xs text-slate-700 leading-relaxed",children:k})]},b):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:b+1}),k.title&&e.jsx("span",{className:"text-xs font-bold text-slate-700",children:k.title})]}),k.description&&e.jsx("p",{className:"text-xs text-slate-600 ml-7 leading-relaxed",children:k.description}),k.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:k.code})]},b))})]}),((R=t.content)==null?void 0:R.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((k,b)=>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(xt,{size:11,className:"text-blue-400"}),e.jsx("code",{className:"text-[10px] font-mono text-slate-600",children:k.file})]}),k.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:k.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:k.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:k.after})]})]},b))})]}),((K=t.content)==null?void 0:K.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((k,b)=>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:k},b))})]}),!!(t.constraints&&((X=t.constraints.guards)!=null&&X.length||($=t.constraints.boundaries)!=null&&$.length||(H=t.constraints.preconditions)!=null&&H.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((k,b)=>e.jsxs("li",{className:"flex gap-2 items-start",children:[e.jsx("span",{className:`text-xs mt-0.5 ${k.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:k.pattern}),k.message&&e.jsxs("span",{className:"text-xs text-slate-400",children:["— ",k.message]})]},b))})]}),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((k,b)=>e.jsxs("li",{className:"flex gap-2",children:[e.jsx("span",{className:"text-orange-400",children:"●"}),k]},b))})]}),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((k,b)=>e.jsxs("li",{className:"flex gap-2",children:[e.jsx("span",{className:"text-blue-400",children:"◆"}),k]},b))})]}),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((k,b)=>e.jsxs("li",{className:"flex gap-2",children:[e.jsx("span",{className:"text-pink-400",children:"⚡"}),k]},b))})]})]}),t.relations&&Object.entries(t.relations).some(([,k])=>Array.isArray(k)&&k.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:k,label:b,color:f,icon:w})=>{var q;const Z=(q=t.relations)==null?void 0:q[k];return!Z||!Array.isArray(Z)||Z.length===0?null:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsxs("span",{className:`text-xs font-mono ${f} w-16 shrink-0 pt-0.5`,children:[w," ",b]}),e.jsx("div",{className:"flex flex-wrap gap-1.5",children:Z.map((ue,_)=>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 ue=="string"?ue:ue.id||ue.title||JSON.stringify(ue)},_))})]},k)})})]}),!((p=t.content)!=null&&p.markdown)&&!((O=t.content)!=null&&O.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:r,className:"px-4 py-2 text-slate-600 font-medium disabled:opacity-50",children:"Cancel"}),e.jsxs("button",{onClick:a,disabled:r,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:[r?e.jsx(Te,{size:T.lg,className:"animate-spin"}):e.jsx(Qt,{size:T.lg}),r?"保存中...":"Save Changes"]})]})]})]})},Rn=({setShowCreateModal:t,createPath:s,setCreatePath:a,handleCreateFromPath:l,handleCreateFromClipboard:r,isExtracting:i})=>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(gt,{size:T.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(Ke,{size:T.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(fa,{size:T.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:c=>a(c.target.value)}),e.jsx("button",{onClick:l,disabled:!s||i,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(fl,{size:T.sm})," Import from Clipboard"]}),e.jsxs("button",{onClick:()=>r(),disabled:i,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(Je,{size:T.lg})," Use Copied Code"]})]})]}),i&&e.jsxs("div",{className:"bg-blue-600 text-white p-4 flex items-center justify-center gap-3 animate-pulse",children:[e.jsx(Yt,{size:T.lg,className:"animate-spin"}),e.jsx("span",{className:"font-bold text-sm",children:"AI is thinking..."})]})]})]});function Ln(t){if(!t)return"";if(typeof t=="object"){const r=t.code||t.pattern||t.markdown||t.snippet||t.body||"";if(r)return r}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 Dn=({searchQ:t,insertPath:s,onClose:a})=>{const[l,r]=n.useState([]),[i,c]=n.useState(!0),[o,j]=n.useState(null),g=n.useRef(!0),h=n.useRef(null);n.useEffect(()=>(g.current=!0,h.current=new AbortController,re.search(t||"",{mode:"bm25",type:"recipe",signal:h.current.signal}).then(x=>{g.current&&r((x.items||[]).map(m=>({name:(m.title||m.name||"")+".md",path:"",content:m.content,qualityScore:(m.quality||{}).overall||m.qualityScore||0,recommendReason:""})))}).catch(x=>{x.name!=="AbortError"&&g.current&&r([])}).finally(()=>{g.current&&c(!1)}),()=>{g.current=!1,h.current&&h.current.abort()}),[t]);const y=async x=>{j(x.name);try{const m=Ln(x.content);await re.insertAtSearchMark({path:s,content:m}),g.current&&(alert("✅ 已插入到 "+s),a())}catch{g.current&&alert("❌ 插入失败")}finally{g.current&&j(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(dt,{size:T.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(Ke,{size:T.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:i?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(x=>e.jsx("li",{children:e.jsxs("button",{type:"button",onClick:()=>y(x),disabled:o!==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:x.name}),(x.qualityScore!==void 0||x.recommendReason)&&e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[x.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:["🤖 质量: ",(x.qualityScore*100).toFixed(0),"%"]}),x.recommendReason&&e.jsx("span",{className:"text-xs text-slate-600 italic truncate max-w-xs",children:x.recommendReason})]})]}),o===x.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(ja,{size:T.md})," 插入"]})]})},x.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:""}],Pn=({onClose:t,onSaved:s})=>{const[a,l]=n.useState(!0),[r,i]=n.useState(!1),[c,o]=n.useState(!1),[j,g]=n.useState("google"),[h,y]=n.useState("gemini-2.0-flash"),[x,m]=n.useState(""),[u,A]=n.useState(""),[S,I]=n.useState(!1),[P,B]=n.useState({}),[R,K]=n.useState(!1);n.useEffect(()=>{X()},[]);const X=async()=>{l(!0);try{const b=await re.getLlmEnvConfig();o(b.hasEnvFile);const f=b.vars||{};f.ASD_AI_PROVIDER&&g(f.ASD_AI_PROVIDER),f.ASD_AI_MODEL&&y(f.ASD_AI_MODEL),f.ASD_AI_PROXY&&A(f.ASD_AI_PROXY),B(f)}catch{}finally{l(!1)}},$=Ns.find(b=>b.id===j),H=($==null?void 0:$.keyEnv)||"",C=H?!!P[H]:!0,p=b=>{g(b);const f=Ns.find(w=>w.id===b);f&&y(f.defaultModel),m("")},O=async()=>{if(j){if(H&&!C&&!x.trim()){alert("请填写 API Key");return}i(!0),K(!1);try{await re.saveLlmEnvConfig({provider:j,model:h||void 0,apiKey:x.trim()||void 0,proxy:u.trim()||void 0}),K(!0),setTimeout(()=>{s(),t()},800)}catch(b){alert((b==null?void 0:b.message)||"保存失败")}finally{i(!1)}}},k=b=>!b||b.length<10?b?"••••••":"":`${b.slice(0,6)}••••${b.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:b=>b.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(Ke,{size:T.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:[!c&&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(zt,{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(b=>e.jsx("button",{type:"button",onClick:()=>p(b.id),className:`px-3 py-2 rounded-lg text-sm font-medium border transition-all ${j===b.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:b.label},b.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:h,onChange:b=>y(b.target.value),placeholder:($==null?void 0:$.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"})]}),H&&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:["(已配置: ",k(P[H]),")"]})]}),e.jsxs("div",{className:"relative",children:[e.jsx("input",{type:S?"text":"password",value:x,onChange:b=>m(b.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:()=>I(b=>!b),className:"absolute right-2 top-1/2 -translate-y-1/2 p-1 text-slate-400 hover:text-slate-600",children:S?e.jsx(jl,{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:u,onChange:b=>A(b.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:O,disabled:r||a||R,className:`flex items-center gap-2 px-5 py-2 rounded-lg text-sm font-medium transition-all ${R?"bg-green-500 text-white":"bg-blue-600 text-white hover:bg-blue-700 shadow-sm"} disabled:opacity-60`,children:[r?e.jsx(Te,{size:16,className:"animate-spin"}):R?e.jsx(es,{size:16}):e.jsx(Qt,{size:16}),R?"已保存":"保存到 .env"]})]})]})})};class Fn extends St.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 Ft(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 On=()=>{var Le,ot;const t=Fl(),s=Bl((Le=t.user)==null?void 0:Le.role),a=ql(),l=()=>{const z=window.location.pathname.replace(/^\//,"").split("/")[0]||"";return zl.includes(z)?z:"help"},[r,i]=n.useState(null),[c,o]=n.useState(l()),[j,g]=n.useState(!1),[h,y]=n.useState(""),[x,m]=n.useState(!0),[u,A]=n.useState(null),[S,I]=n.useState([]),[P,B]=n.useState(null),[R,K]=n.useState(!1),[X,$]=n.useState({current:0,total:0,status:""}),[H,C]=n.useState([]),[p,O]=n.useState([]),[k,b]=n.useState(null),[f,w]=n.useState("All"),[Z,q]=n.useState(1),[ue,_]=n.useState(12),[M,ee]=n.useState(!1),[J,se]=n.useState(""),[V,Q]=n.useState(!1),[ae,ye]=n.useState(null),[Se,De]=n.useState(null),[D,E]=n.useState(!1),[xe,Ie]=n.useState(!0),[fe,Ae]=n.useState(!1),[Oe,Ee]=n.useState(0),v=n.useRef(null),ne=n.useRef(null);n.useEffect(()=>{q(1)},[h,f]);const ve=()=>{v.current&&v.current.abort()};n.useEffect(()=>{let z=!1;const me=async()=>{var Y,ke,Ne;try{const we=await re.getSignalStatus();if(!z){const ze=((Y=we==null?void 0:we.suggestions)==null?void 0:Y.length)||0,Ce=((Ne=(ke=we==null?void 0:we.snapshot)==null?void 0:ke.lastResult)==null?void 0:Ne.newSuggestions)||0;Ee(ze||Ce)}}catch{}};me();const ie=setInterval(me,300*1e3);return()=>{z=!0,clearInterval(ie)}},[]),n.useEffect(()=>{a.isAllDone&&L()},[a.isAllDone]),n.useEffect(()=>{if(a.candidateCreatedTick>0){const z=setTimeout(()=>L(),2e3);return()=>clearTimeout(z)}},[a.candidateCreatedTick]);const ce=(z,me)=>{o(z);const ie=me!=null&&me.preserveSearch&&window.location.search?window.location.search:"";window.history.pushState({},document.title,`/${z}${ie}`)},he=z=>{A(z),o("recipes");const me=new URLSearchParams(window.location.search);me.set("edit",encodeURIComponent(z.name)),window.history.pushState({},document.title,`/recipes?${me.toString()}`)},d=()=>{A(null),window.history.replaceState({},document.title,"/recipes")};n.useEffect(()=>{h===""&&ye(null)},[h]),n.useEffect(()=>{o(l())},[]),n.useEffect(()=>{if(!r)return;const z=window.location.pathname.replace(/^\//,"").split("/")[0],ie=new URLSearchParams(window.location.search).get("edit");if(z==="recipes"&&ie&&r.recipes)try{const Y=decodeURIComponent(ie),ke=r.recipes.find(Ne=>Ne.name===Y);ke&&!u&&(o("recipes"),he(ke))}catch{}},[r]),n.useEffect(()=>{L(),N(),pe();const z=()=>{o(l())};window.addEventListener("popstate",z);const me=new URLSearchParams(window.location.search),ie=me.get("action"),Y=me.get("path"),ke=me.get("q")||"";return ie==="search"&&Y?De({q:ke,path:Y}):ie==="create"&&Y&&(se(Y),ee(!0),me.get("autoScan")==="1"&&setTimeout(()=>F(Y),500)),ie&&window.history.replaceState({},document.title,window.location.pathname),()=>{window.removeEventListener("popstate",z)}},[]);const L=async()=>{m(!0);try{const z=await re.fetchData();i(z)}catch(z){le((z==null?void 0:z.message)||"无法加载项目数据",{title:"加载失败",type:"error"})}finally{m(!1)}},N=async()=>{try{const z=await re.fetchTargets();I(z)}catch(z){console.warn("删除候选残留失败:",z==null?void 0:z.message)}},pe=async()=>{try{const z=await re.getLlmEnvConfig();Ie(z.llmReady)}catch{}},G=async()=>{try{await re.syncToXcode(),le("Recipes 已同步到 Xcode CodeSnippets 目录",{title:"Xcode 同步成功"})}catch{le("请检查 Xcode 是否已安装并重试",{title:"同步失败",type:"error"})}},oe=async()=>{try{await re.refreshProject(),N(),le("Target 列表与文件树已更新",{title:"项目结构已刷新"})}catch{le("请确认项目路径有效后重试",{title:"刷新失败",type:"error"})}},F=async z=>{var me;Q(!0);try{const ie=await re.extractFromPath(z);O(ie.result.map(Y=>({...Ft(Y,"extract"),mode:"full",lang:"cn"}))),ce("spm"),ee(!1),L(),((me=ie.result)==null?void 0:me.length)>0&&le("提取结果已进入候选池,请在 Candidates 页审核",{title:"提取完成"})}catch{le("Extraction failed",{type:"error"})}finally{Q(!1)}},te=async()=>{var z;if(J){Q(!0);try{const me=await re.extractFromPath(J);O(me.result.map(ie=>({...Ft(ie,"extract"),mode:"full",lang:"cn"}))),ce("spm"),ee(!1),L(),((z=me.result)==null?void 0:z.length)>0?le(me.isMarked?"精准锁定标记代码,已加入候选池":"提取结果已加入候选池",{title:"提取完成"}):me.isMarked||le("未找到 ASD 标记,AI 将分析完整文件",{title:"提取中",type:"info"})}catch{le("Extraction failed",{type:"error"})}finally{Q(!1)}}},ge=async z=>{var me,ie,Y,ke;try{const Ne=await navigator.clipboard.readText();if(!Ne)return le("请先复制代码到剪贴板",{title:"剪贴板为空",type:"info"});le("已收到代码,AI 正在识别可复用模式...",{title:"剪贴板分析中",type:"info"}),Q(!0);const we=z||J;try{const ze=await re.extractFromText(Ne,we||void 0),Ce=ze._multipleCount;O([{...Ft(ze,"clipboard"),mode:"full",lang:"cn"}]),ce("spm"),ee(!1),L(),le(Ce?`已识别 ${Ce} 条 Recipe,请在候选池审核`:"提取结果已加入候选池",{title:"AI 识别完成"})}catch(ze){const Ce=((ie=(me=ze.response)==null?void 0:me.data)==null?void 0:ie.aiError)===!0,Fe=((ke=(Y=ze.response)==null?void 0:Y.data)==null?void 0:ke.error)||ze.message;Ce?le(Fe,{title:"AI 识别失败",type:"error"}):le(Fe,{title:"操作失败",type:"error"})}}catch{le("浏览器可能未授权剪贴板访问",{title:"剪贴板读取失败",type:"error"})}finally{Q(!1)}},W={"scan:started":{percent:5,status:"正在启动扫描..."},"scan:files-loaded":{percent:15,status:z=>`已加载 ${z.count||0} 个源文件`},"scan:reading":{percent:25,status:z=>`正在读取 ${z.count||0} 个文件内容...`},"scan:ai-extracting":{percent:40,status:"正在 AI 分析提取可复用模式..."},"scan:enriching":{percent:85,status:z=>`正在增强 ${z.recipeCount||0} 条结果...`},"scan:completed":{percent:95,status:"扫描完成,正在加载结果..."}},be=async z=>{var ie;if(R)return;v.current&&v.current.abort(),ne.current&&(clearInterval(ne.current),ne.current=null);const me=new AbortController;v.current=me,B(z.name),K(!0),O([]),b(null),C([]),$({current:0,total:100,status:"正在建立流式连接..."});try{const Y=await re.scanTargetStream(z,we=>{const ze=W[we.type];if(ze){const Ce=typeof ze.status=="function"?ze.status(we):ze.status;$({current:ze.percent,total:100,status:Ce})}we.type==="scan:files-loaded"&&we.files&&C(we.files),we.type==="scan:ai-extracting"&&(ne.current&&clearInterval(ne.current),ne.current=setInterval(()=>{$(Ce=>({...Ce,current:Math.min(Ce.current+1,80)}))},3e3)),(we.type==="scan:enriching"||we.type==="scan:completed")&&ne.current&&(clearInterval(ne.current),ne.current=null)},me.signal);ne.current&&(clearInterval(ne.current),ne.current=null),$({current:100,total:100,status:"扫描完成"});const ke=Y.recipes||[],Ne=Y.scannedFiles||[];if(ke.length>0||Ne.length>0){const we=typeof z=="string"?z:(z==null?void 0:z.name)||"unknown",ze=ke.map(Ce=>({...Ft(Ce,"ai-scan"),mode:"full",lang:"cn",candidateTargetName:we,scanMode:"target"}));O(ze),Ne.length>0&&C(Ne),L(),ke.length>0?le(`发现 ${ke.length} 条可复用代码模式,请在右侧审核`,{title:"Target 扫描完成"}):Y.message?le(Y.message,{title:"AI 扫描未返回结果",type:"error"}):le("该 Target 中未找到可复用的代码片段",{title:"扫描完成",type:"info"})}else le("请确认 Target 包含有效的源代码文件",{title:"扫描失败",type:"error"})}catch(Y){if(ne.current&&(clearInterval(ne.current),ne.current=null),Y.name==="AbortError")return;const ke=(ie=Y.message)==null?void 0:ie.includes("timeout"),Ne=ke?"扫描超时,请尝试减少 Target 文件数量":Y.message||"未知错误";le(Ne,{title:ke?"扫描超时":"扫描出错",type:"error"})}finally{v.current===me&&(K(!1),$({current:0,total:0,status:""}),v.current=null)}},Re=async()=>{var me,ie,Y,ke,Ne,we;if(R)return;v.current&&v.current.abort();const z=new AbortController;v.current=z,ce("candidates"),K(!0),O([]),b(null),C([]),$({current:0,total:100,status:"正在收集项目结构..."}),a.resetSession();try{const ze=await re.bootstrap(z.signal);$({current:100,total:100,status:"骨架已创建,正在后台填充..."}),ze.bootstrapSession&&a.initFromApiResponse(ze.bootstrapSession),L();const Ce=ze.report||{},Fe=((me=ze.targets)==null?void 0:me.length)||0,at=((ie=Ce.totals)==null?void 0:ie.files)||0,jt=((Y=Ce.totals)==null?void 0:Y.graphEdges)||0,Mt=ze.guardSummary,bs=Mt?`, Guard: ${Mt.totalViolations} 项违规`:"";le(`冷启动骨架已创建: ${Fe} 个 Target, ${at} 个文件, ${jt} 条依赖${bs},正在后台逐维度填充...`)}catch(ze){if(Gt.isCancel(ze))return;const Fe=ze.code==="ECONNABORTED"||((ke=ze.message)==null?void 0:ke.includes("timeout"))?"冷启动超时,请检查项目文件数量":((we=(Ne=ze.response)==null?void 0:Ne.data)==null?void 0:we.error)||ze.message;le(Fe,{type:"error"})}finally{v.current===z&&(K(!1),$({current:0,total:0,status:""}),v.current=null)}},Me=async()=>{var ke,Ne,we,ze;if(R)return;v.current&&v.current.abort();const z=new AbortController;v.current=z,ce("spm"),B("__project__"),K(!0),O([]),b(null),C([]),$({current:0,total:100,status:"正在收集所有 Target 文件..."});const me=[{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 ie=0;const Y=setInterval(()=>{ie=Math.min(ie+1,me.length);const Ce=me[ie-1];Ce&&$(Fe=>({...Fe,current:Ce.percent,status:Ce.status}))},15e3);try{const Ce=await re.scanProject(z.signal);clearInterval(Y),$({current:100,total:100,status:Ce.partial?"扫描部分完成(超时)":"全项目扫描完成"});const Fe=Ce.recipes||[],at=Ce.scannedFiles||[];if(Fe.length>0||at.length>0){const jt=Fe.map(Ma=>({...Ft(Ma,"ai-scan"),mode:"full",lang:"cn",candidateTargetName:"__project__",scanMode:"project"}));O(jt),C(at),b(Ce.guardAudit||null),L();const Mt=(ke=Ce.guardAudit)==null?void 0:ke.summary,bs=Mt?`, Guard: ${Mt.totalViolations} 处违反`:"",Ta=Ce.partial?"(部分结果,AI 超时)":"";le(`全项目扫描完成: ${Fe.length} 条候选${bs}${Ta}`)}else le("全项目扫描完成,未发现可提取内容")}catch(Ce){if(clearInterval(Y),Gt.isCancel(Ce))return;const at=Ce.code==="ECONNABORTED"||((Ne=Ce.message)==null?void 0:Ne.includes("timeout"))?"扫描超时,请尝试减少项目文件数量或分 Target 扫描":((ze=(we=Ce.response)==null?void 0:we.data)==null?void 0:ze.error)||Ce.message;le(at,{type:"error"})}finally{v.current===z&&(K(!1),$({current:0,total:0,status:""}),v.current=null)}},_e=(z,me)=>{const ie=[...p],Y={...ie[z],...me};ie[z]=Y,O(ie)},qe=async z=>{var me;if(!D){E(!0);try{const ie=(((me=z.content)==null?void 0:me.pattern)||"").trim(),Y=(()=>{if(!ie)return!1;const Fe=ie.split(`
141
+ `).filter(jt=>jt.trim());return Fe.filter(jt=>/^\s*(#{1,6}\s|[-*>]\s|\d+\.\s)/.test(jt)).length<=Fe.length*.3})(),ke=(z.trigger||"").split(/[,,\s]+/).map(Fe=>Fe.trim()).filter(Boolean);if(Y&&ke.length===0){le("请输入 Trigger",{type:"error"}),E(!1);return}const Ne={title:z.title||"Untitled",description:z.description||"",trigger:ke.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},we=await re.knowledgeCreate(Ne);if(we!=null&&we.id)try{await re.knowledgeLifecycle(we.id,"publish")}catch(Fe){console.warn("auto-publish after save failed:",Fe)}le(Y?"已保存并发布为 Recipe":"已保存到 KB"),O(Fe=>Fe.filter(at=>at.title!==z.title));const ze=z.candidateTargetName,Ce=z.candidateId;if(ze&&Ce)try{await re.deleteCandidate(Ce)}catch{}L()}catch(ie){const Y=Bs(ie)??xs(ie);le(Y??"保存失败",{type:"error"})}finally{E(!1)}}},We=async()=>{var z,me;if(!(!u||D)){E(!0);try{const ie=u.id||((z=u.name)==null?void 0:z.replace(/\.md$/,"")),Y=typeof u.content=="string"?{pattern:u.content,markdown:"",rationale:"",steps:[],codeChanges:[],verification:null}:u.content||{};await re.knowledgeUpdate(ie,{title:((me=u.name)==null?void 0:me.replace(/\.md$/,""))||"",description:u.description||"",content:Y,tags:u.tags||[],kind:u.kind,language:u.language,category:u.category}),d(),L()}catch(ie){const Y=Bs(ie)??xs(ie);le(Y??"保存 Recipe 失败",{type:"error"})}finally{E(!1)}}},U=async z=>{if(window.confirm("Are you sure?"))try{await re.deleteRecipe(z),L()}catch(me){const ie=xs(me);le(ie??"删除失败",{type:"error"})}},$e=async(z,me)=>{try{await re.deleteCandidate(me),O(ie=>ie.filter(Y=>!(Y.candidateId===me&&Y.candidateTargetName===z))),i(ie=>{if(!(ie!=null&&ie.candidates))return ie;const Y={...ie.candidates};if(Y[z]){const ke=Y[z].items.filter(Ne=>Ne.id!==me);ke.length===0?delete Y[z]:Y[z]={...Y[z],items:ke}}return{...ie,candidates:Y}})}catch{le("操作失败",{type:"error"})}},Ge=async z=>{if(window.confirm(`确定移除「${z}」下的全部候选?`))try{await re.deleteAllCandidatesInTarget(z),L(),le(`已移除 ${z} 下的全部候选`)}catch{le("操作失败",{type:"error"})}},Be=async(z,me)=>{var ie,Y;try{await re.promoteToCandidate(z,z.candidateTargetName||P||"_review"),le("已加入 Candidate 待审核队列"),O(ke=>ke.filter((Ne,we)=>we!==me)),L()}catch(ke){const Ne=(Y=(ie=ke.response)==null?void 0:ie.data)==null?void 0:Y.error,we=typeof Ne=="string"?Ne:(Ne==null?void 0:Ne.message)||"创建 Candidate 失败";le(we,{type:"error"})}},Xe=((r==null?void 0:r.recipes)||[]).filter(z=>{var we,ze;if(ae)return ae.some(Ce=>Ce.metadata.type==="recipe"&&Ce.metadata.name===z.name);const me=z.name||"",ie=typeof z.content=="string"?z.content:[(we=z.content)==null?void 0:we.pattern,(ze=z.content)==null?void 0:ze.markdown].filter(Boolean).join(" "),Y=me.toLowerCase().includes(h.toLowerCase())||ie.toLowerCase().includes(h.toLowerCase())||(z.description||"").toLowerCase().includes(h.toLowerCase());if(f==="All")return Y;const ke=ie?ie.match(/category:\s*(.*)/):null,Ne=ke?ke[1].trim():"Utility";return Y&&Ne===f}).sort((z,me)=>{var ke,Ne,we,ze;if(ae){const Ce=((ke=ae.find(at=>at.metadata.name===z.name))==null?void 0:ke.similarity)||0;return(((Ne=ae.find(at=>at.metadata.name===me.name))==null?void 0:Ne.similarity)||0)-Ce}const ie=((we=z.stats)==null?void 0:we.authorityScore)??0;return(((ze=me.stats)==null?void 0:ze.authorityScore)??0)-ie}),je=S.filter(z=>z.name.toLowerCase().includes(h.toLowerCase())).sort((z,me)=>{const ie=ss(z.name),Y=ss(me.name);return ie&&!Y?1:!ie&&Y?-1:z.name.localeCompare(me.name)}),Pe=Object.values((r==null?void 0:r.candidates)||{}).reduce((z,me)=>z+me.items.length,0),He=c==="editor";return e.jsx(Fn,{children:e.jsx(dr,{children:e.jsxs("div",{className:`flex h-screen ${He?"bg-[#1e1e1e] text-slate-200":"bg-slate-50 text-slate-900"} overflow-hidden font-sans`,children:[e.jsx(Da,{position:"top-center",toastOptions:{duration:5e3},containerStyle:{top:24}}),e.jsx(Gl,{activeTab:c,navigateToTab:ce,candidateCount:Pe,signalSuggestionCount:Oe,isDarkMode:He,currentUser:s.user!=="anonymous"?s.user:void 0,currentRole:s.role,permissionMode:s.mode,onLogout:void 0,collapsed:j,onToggleCollapse:()=>g(z=>!z)}),e.jsxs("main",{className:"flex-1 flex flex-col overflow-hidden relative",children:[e.jsx(mr,{searchQuery:h,setSearchQuery:y,setShowCreateModal:ee,handleSyncToXcode:G,aiConfig:r==null?void 0:r.aiConfig,llmReady:xe,onOpenLlmConfig:()=>Ae(!0),onBeforeAiSwitch:ve,onAiConfigChange:L,isDarkMode:He,onSemanticSearchResults:z=>{ye(z),c!=="recipes"&&ce("recipes")}}),c==="recipes"&&e.jsx(ur,{selectedCategory:f,setSelectedCategory:w}),e.jsx("div",{className:`flex-1 ${c==="editor"||c==="wiki"?"overflow-hidden":"overflow-y-auto p-8"}`,children:x?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"})}):c==="recipes"?e.jsx(vr,{recipes:Xe,openRecipeEdit:he,handleDeleteRecipe:U,onRefresh:L,idTitleMap:r==null?void 0:r.idTitleMap,currentPage:Z,onPageChange:q,pageSize:ue,onPageSizeChange:z=>{_(z),q(1)}}):c==="guard"?e.jsx(Jr,{onRefresh:L}):c==="skills"?e.jsx(un,{onRefresh:L,signalSuggestionCount:Oe,onSuggestionCountChange:Ee}):c==="candidates"?e.jsxs(e.Fragment,{children:[a.session&&e.jsx("div",{className:"mb-4",children:e.jsx(Nn,{session:a.session,isAllDone:a.isAllDone,reviewState:a.reviewState,onDismiss:()=>a.resetSession()})}),e.jsx(Mr,{data:r,isShellTarget:ss,isSilentTarget:El,isPendingTarget:Tl,handleDeleteCandidate:$e,onEditRecipe:he,onColdStart:Re,isScanning:R,isBootstrapping:((ot=a.session)==null?void 0:ot.status)==="running",onRefresh:L,onAuditCandidate:(z,me)=>{var ke,Ne;const ie=(((ke=z.content)==null?void 0:ke.pattern)||"").trim(),Y=!!ie&&(()=>{const we=ie.split(`
142
142
  `).filter(Ce=>Ce.trim());return we.filter(Ce=>/^\s*(#{1,6}\s|[-*>]\s|\d+\.\s)/.test(Ce)).length<=we.length*.3})();O([{...z,mode:Y?"full":"preview",lang:"cn",includeHeaders:!0,difficulty:z.difficulty||z.complexity||"intermediate",authority:((Ne=z.stats)==null?void 0:Ne.authority)||3,candidateId:z.id,candidateTargetName:me}]),ce("spm")},onAuditAllInTarget:(z,me)=>{O(z.map(ie=>{var Ne,we;const Y=(((Ne=ie.content)==null?void 0:Ne.pattern)||"").trim(),ke=!!Y&&(()=>{const ze=Y.split(`
143
- `).filter(Fe=>Fe.trim());return ze.filter(Fe=>/^\s*(#{1,6}\s|[-*>]\s|\d+\.\s)/.test(Fe)).length<=ze.length*.3})();return{...ie,mode:ke?"full":"preview",lang:"cn",includeHeaders:!0,difficulty:ie.difficulty||ie.complexity||"intermediate",authority:((we=ie.stats)==null?void 0:we.authority)||3,candidateId:ie.id,candidateTargetName:me}})),ce("spm")},handleDeleteAllInTarget:We})]}):c==="knowledge"?e.jsx(mn,{onRefresh:oe,idTitleMap:r==null?void 0:r.idTitleMap}):c==="depgraph"?e.jsx(Vr,{}):c==="knowledgegraph"?e.jsx(on,{}):c==="spm"?e.jsx(qr,{targets:S,filteredTargets:je,selectedTargetName:P,isScanning:R,scanProgress:X,scanFileList:H,scanResults:p,guardAudit:k,handleScanTarget:be,handleScanProject:Te,handleUpdateScanResult:Me,handleSaveExtracted:qe,handlePromoteToCandidate:Be,handleDeleteCandidate:$e,onEditRecipe:he,isShellTarget:ss,recipes:(r==null?void 0:r.recipes)??[],isSavingRecipe:D,handleRefreshProject:oe}):c==="wiki"?e.jsx(En,{}):c==="editor"?e.jsx(yn,{}):c==="help"?e.jsx(Sr,{}):e.jsx(Zr,{})}),u&&e.jsx(Mn,{editingRecipe:u,setEditingRecipe:A,handleSaveRecipe:Ge,closeRecipeEdit:d,isSavingRecipe:D}),T&&e.jsx(Rn,{setShowCreateModal:ee,createPath:J,setCreatePath:se,handleCreateFromPath:te,handleCreateFromClipboard:ge,isExtracting:V}),Se&&e.jsx(Dn,{searchQ:Se.q,insertPath:Se.path,onClose:()=>{De(null),window.history.replaceState({},document.title,window.location.pathname)}}),fe&&e.jsx(Pn,{onClose:()=>Ae(!1),onSaved:()=>{pe(),L()}})]}),e.jsx(Bn,{})]})})})},Bn=()=>{const{isOpen:t}=ts();return t?e.jsx(xr,{}):null};Pa.createRoot(document.getElementById("root")).render(e.jsx(St.StrictMode,{children:e.jsx(On,{})}));
143
+ `).filter(Fe=>Fe.trim());return ze.filter(Fe=>/^\s*(#{1,6}\s|[-*>]\s|\d+\.\s)/.test(Fe)).length<=ze.length*.3})();return{...ie,mode:ke?"full":"preview",lang:"cn",includeHeaders:!0,difficulty:ie.difficulty||ie.complexity||"intermediate",authority:((we=ie.stats)==null?void 0:we.authority)||3,candidateId:ie.id,candidateTargetName:me}})),ce("spm")},handleDeleteAllInTarget:Ge})]}):c==="knowledge"?e.jsx(mn,{onRefresh:oe,idTitleMap:r==null?void 0:r.idTitleMap}):c==="depgraph"?e.jsx(Vr,{}):c==="knowledgegraph"?e.jsx(on,{}):c==="spm"?e.jsx(qr,{targets:S,filteredTargets:je,selectedTargetName:P,isScanning:R,scanProgress:X,scanFileList:H,scanResults:p,guardAudit:k,handleScanTarget:be,handleScanProject:Me,handleUpdateScanResult:_e,handleSaveExtracted:qe,handlePromoteToCandidate:Be,handleDeleteCandidate:$e,onEditRecipe:he,isShellTarget:ss,recipes:(r==null?void 0:r.recipes)??[],isSavingRecipe:D,handleRefreshProject:oe}):c==="wiki"?e.jsx(Tn,{}):c==="editor"?e.jsx(yn,{}):c==="help"?e.jsx(Sr,{}):e.jsx(Zr,{})}),u&&e.jsx(_n,{editingRecipe:u,setEditingRecipe:A,handleSaveRecipe:We,closeRecipeEdit:d,isSavingRecipe:D}),M&&e.jsx(Rn,{setShowCreateModal:ee,createPath:J,setCreatePath:se,handleCreateFromPath:te,handleCreateFromClipboard:ge,isExtracting:V}),Se&&e.jsx(Dn,{searchQ:Se.q,insertPath:Se.path,onClose:()=>{De(null),window.history.replaceState({},document.title,window.location.pathname)}}),fe&&e.jsx(Pn,{onClose:()=>Ae(!1),onSaved:()=>{pe(),L()}})]}),e.jsx(Bn,{})]})})})},Bn=()=>{const{isOpen:t}=ts();return t?e.jsx(xr,{}):null};Pa.createRoot(document.getElementById("root")).render(e.jsx(St.StrictMode,{children:e.jsx(On,{})}));