autosnippet 2.7.1 → 2.8.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +13 -9
- package/bin/api-server.js +6 -0
- package/bin/cli.js +26 -0
- package/bin/mcp-server.js +22 -0
- package/dashboard/dist/assets/{index-BjfUm8p9.js → index-Duc8Qk-c.js} +30 -30
- package/dashboard/dist/index.html +1 -1
- package/lib/external/mcp/McpServer.js +11 -3
- package/lib/external/mcp/handlers/skill.js +198 -0
- package/lib/external/mcp/tools.js +54 -1
- package/lib/http/routes/candidates.js +1 -1
- package/lib/infrastructure/database/DatabaseConnection.js +11 -2
- package/lib/service/automation/handlers/AlinkHandler.js +43 -4
- package/lib/shared/PathGuard.js +2 -2
- package/package.json +1 -1
- package/skills/autosnippet-coldstart/SKILL.md +0 -2
- package/skills/autosnippet-reference-jsts/SKILL.md +0 -2
- package/skills/autosnippet-reference-objc/SKILL.md +0 -2
- package/skills/autosnippet-reference-swift/SKILL.md +0 -2
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{z as Os,j as e,r,l as pa,R as Bt,F as ha,i as ba}from"./vendor-BotF760a.js";import{a as St}from"./axios-C0Zqfgkc.js";import{Z as st,L as ga,S as fa,B as It,H as ja,C as ya,a as bt,W as Na,G as bs,b as at,c as gt,d as Qt,e as va,f as wa,D as Bs,g as Ut,P as ka,h as Sa,i as ss,j as Ca,k as Ia,l as $a,F as Us,m as Nt,n as ps,M as vt,o as mt,p as Aa,q as Ye,E as $t,r as
|
|
1
|
+
import{z as Os,j as e,r,l as pa,R as Bt,F as ha,i as ba}from"./vendor-BotF760a.js";import{a as St}from"./axios-C0Zqfgkc.js";import{Z as st,L as ga,S as fa,B as It,H as ja,C as ya,a as bt,W as Na,G as bs,b as at,c as gt,d as Qt,e as va,f as wa,D as Bs,g as Ut,P as ka,h as Sa,i as ss,j as Ca,k as Ia,l as $a,F as Us,m as Nt,n as ps,M as vt,o as mt,p as Aa,q as Ye,E as $t,r as _a,s as za,U as Hs,t as Ra,R as wt,u as ut,X as Ke,v as ze,w as _t,x as Ea,y as it,z as gs,A as Ws,I as pt,J as Ta,K as Ks,N as kt,O as Ma,Q as fs,T as Ga,V as Da,Y as Vs,_ as Pa,$ as La,a0 as Lt,a1 as Ct,a2 as ht,a3 as rs,a4 as hs,a5 as qs,a6 as js,a7 as as,a8 as Js,a9 as Tt,aa as Fa,ab as ws,ac as ks,ad as Yt,ae as Oa,af as Ys,ag as Xs,ah as Zs,ai as Mt,aj as es,ak as Ft,al as Ba,am as ts,an as ys,ao as Ua,ap as Qs,aq as Ha,ar as Ot,as as Wa,at as ea,au as Ka,av as Va,aw as qa,ax as Ja,ay as ta,az as Ya,aA as Xa,aB as Za,aC as Ss,aD as Cs,aE as Qa,aF as el,aG as tl}from"./icons-B_Xg4B-s.js";import{h as sa,o as aa}from"./syntax-highlighter-CVLHn9O5.js";import{M as sl}from"./react-markdown-BA6FB2NP.js";import"./yaml-qRaU8Ldn.js";(function(){const s=document.createElement("link").relList;if(s&&s.supports&&s.supports("modulepreload"))return;for(const n of document.querySelectorAll('link[rel="modulepreload"]'))l(n);new MutationObserver(n=>{for(const o of n)if(o.type==="childList")for(const c of o.addedNodes)c.tagName==="LINK"&&c.rel==="modulepreload"&&l(c)}).observe(document,{childList:!0,subtree:!0});function a(n){const o={};return n.integrity&&(o.integrity=n.integrity),n.referrerPolicy&&(o.referrerPolicy=n.referrerPolicy),n.crossOrigin==="use-credentials"?o.credentials="include":n.crossOrigin==="anonymous"?o.credentials="omit":o.credentials="same-origin",o}function l(n){if(n.ep)return;n.ep=!0;const o=a(n);fetch(n.href,o)}})();const al="AutoSnippet";function ll(t){if(typeof window>"u"||!("Notification"in window))return;const s=()=>{try{new Notification(al,{body:t,tag:"autosnippet"})}catch{}};if(Notification.permission==="granted"){s();return}Notification.permission!=="denied"&&Notification.requestPermission().then(a=>{a==="granted"&&s()})}const rl={success:5e3,error:8e3,info:5e3},Is={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"}},nl=()=>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"})}),il=()=>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"})}),la=()=>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"})}),ol={success:nl,error:il,info:la},cl=({visible:t,toastId:s,body:a,type:l,title:n,duration:o})=>{const c=Is[l]||Is.info,i=ol[l]||la;return e.jsxs("div",{onClick:()=>Os.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(i,{})}),e.jsxs("div",{style:{flex:1,minWidth:0},children:[n&&e.jsx("div",{style:{fontWeight:600,fontSize:13,lineHeight:1.3,color:"#1e293b",marginBottom:2},children:n}),e.jsx("div",{style:{fontSize:12.5,lineHeight:1.45,color:"#475569",wordBreak:"break-word"},children:a})]}),e.jsx("div",{style:{position:"absolute",bottom:0,left:0,height:3,width:"100%",background:c.bar,opacity:.45,animation:`toast-progress ${o}ms linear forwards`}})]})};function ee(t,s){const a=(s==null?void 0:s.type)??"success",l=s==null?void 0:s.title,n=(s==null?void 0:s.duration)??rl[a]??5e3;typeof document<"u"&&document.visibilityState==="visible"?dl(t,a,l,n):ll(l?`${l}: ${t}`:t)}function dl(t,s,a,l){Os.custom(n=>e.jsx(cl,{visible:n.visible,toastId:n.id,body:t,type:s,title:a,duration:l}),{duration:l})}if(typeof document<"u"){const t="asd-toast-progress-style";if(!document.getElementById(t)){const s=document.createElement("style");s.id=t,s.textContent=`
|
|
2
2
|
@keyframes toast-progress {
|
|
3
3
|
from { width: 100%; }
|
|
4
4
|
to { width: 0%; }
|
|
@@ -38,10 +38,10 @@ ${f}
|
|
|
38
38
|
|
|
39
39
|
${k}
|
|
40
40
|
|
|
41
|
-
`);const T=l.steps||[],L=b=>b==null?"":typeof b=="string"?b:typeof b=="number"||typeof b=="boolean"?String(b):JSON.stringify(b),U=T.map((b,R)=>{if(typeof b=="string")return`${R+1}. ${b}`;if(typeof b!="object"||b===null)return`${R+1}. ${String(b)}`;const M=L(b.title),H=L(b.description),
|
|
41
|
+
`);const T=l.steps||[],L=b=>b==null?"":typeof b=="string"?b:typeof b=="number"||typeof b=="boolean"?String(b):JSON.stringify(b),U=T.map((b,R)=>{if(typeof b=="string")return`${R+1}. ${b}`;if(typeof b!="object"||b===null)return`${R+1}. ${String(b)}`;const M=L(b.title),H=L(b.description),_=L(b.code),P=[M,H].filter(Boolean).join(": ");let p=`${R+1}. ${P||"(步骤)"}`;return _&&(p+=`
|
|
42
42
|
|
|
43
43
|
\`\`\`
|
|
44
|
-
${
|
|
44
|
+
${_}
|
|
45
45
|
\`\`\``),p}).join(`
|
|
46
46
|
`);U.trim()&&(x+=`## Best Practices
|
|
47
47
|
|
|
@@ -51,8 +51,8 @@ ${U}
|
|
|
51
51
|
|
|
52
52
|
${B}
|
|
53
53
|
|
|
54
|
-
`);const K={authority:s.overall||0,authorityScore:s.overall||0,guardUsageCount:a.applicationCount||0,humanUsageCount:a.adoptionCount||0,aiUsageCount:0,lastUsedAt:t.updatedAt||null};return{id:t.id,name:(t.title||t.name||t.id)+".md",content:x,category:t.category||"",language:t.language||"",description:t.description||"",status:t.status||"draft",kind:t.kind||void 0,knowledgeType:t.knowledgeType||void 0,v2Content:t.content||null,relations:t.relations||null,constraints:t.constraints||null,tags:t.tags||[],stats:K,usageGuide:t.usageGuideCn||t.usageGuideEn||"",usageGuide_cn:t.usageGuideCn||"",usageGuide_en:t.usageGuideEn||""}}function
|
|
55
|
-
`).map(A=>A.trim()).filter(Boolean),S=m.filter(A=>A.startsWith("- ")).map(A=>A.slice(2).trim());S.length>0&&(c.preconditions=S);const v=m.filter(A=>!A.startsWith("- ")&&!A.startsWith("**"));v.length>0&&(c.boundaries=v)}const i={title:l,language:a.language,category:a.category,description:a.summary,summaryCn:a.summary||"",summaryEn:a.summaryEn||"",usageGuideCn:a.usageGuide||"",usageGuideEn:a.usageGuideEn||"",knowledgeType:a.knowledgeType||"code-pattern",complexity:a.complexity||"intermediate",scope:a.scope||null,tags:a.tags||[],content:o,constraints:c,dimensions:n};try{const m=await ne.get(`/recipes?keyword=${encodeURIComponent(l)}&limit=5`),v=((($=(x=m.data)==null?void 0:x.data)==null?void 0:$.data)||((y=(d=m.data)==null?void 0:d.data)==null?void 0:y.items)||[]).find(A=>A.title===l);if(v){await ne.patch(`/recipes/${v.id}`,i);return}}catch{}await ne.post("/recipes",i)},async deleteRecipe(t){var o,c,i,x;const s=t.replace(/\.md$/,""),a=await ne.get(`/recipes?keyword=${encodeURIComponent(s)}&limit=5`),l=((c=(o=a.data)==null?void 0:o.data)==null?void 0:c.data)||((x=(i=a.data)==null?void 0:i.data)==null?void 0:x.items)||[],n=l.find($=>$.title===s)||l[0];if(n!=null&&n.id)await ne.delete(`/recipes/${n.id}`);else throw new Error("Recipe not found")},async getRecipeByName(t){var c,i,x,$;const s=t.replace(/\.md$/,""),a=await ne.get(`/recipes?keyword=${encodeURIComponent(s)}&limit=5`),l=((i=(c=a.data)==null?void 0:c.data)==null?void 0:i.data)||(($=(x=a.data)==null?void 0:x.data)==null?void 0:$.items)||[];if(l.length===0)throw new Error("Recipe not found");const o=l[0].content||{};return{name:t,content:o.pattern||o.markdown||""}},async setRecipeAuthority(t,s){var o,c,i,x;const a=t.replace(/\.md$/,""),l=await ne.get(`/recipes?keyword=${encodeURIComponent(a)}&limit=5`),n=((c=(o=l.data)==null?void 0:o.data)==null?void 0:c.data)||((x=(i=l.data)==null?void 0:i.data)==null?void 0:x.items)||[];n.length>0&&n[0].id&&await ne.patch(`/recipes/${n[0].id}/quality`,{codeCompleteness:s,projectAdaptation:s,documentationClarity:s})},async updateRecipeRelations(t,s){var c,i,x,$;const a=t.replace(/\.md$/,""),l=await ne.get(`/recipes?keyword=${encodeURIComponent(a)}&limit=5`),n=((i=(c=l.data)==null?void 0:c.data)==null?void 0:i.data)||(($=(x=l.data)==null?void 0:x.data)==null?void 0:$.items)||[],o=n.find(d=>d.title===a)||n[0];if(o!=null&&o.id)await ne.patch(`/recipes/${o.id}`,{relations:s});else throw new Error("Recipe not found")},async searchRecipes(t){var n;const a=((n=(await ne.get(`/search?q=${encodeURIComponent(t)}&type=recipe`)).data)==null?void 0:n.data)||{},l=a.recipes||[];return{results:l.map(o=>({name:o.title||o.name||"",content:(o.content||{}).pattern||(o.content||{}).markdown||""})),total:a.totalResults||l.length}},async getCandidate(t){var l;const a=(l=(await ne.get(`/candidates/${t}`)).data)==null?void 0:l.data;if(!a)throw new Error("Candidate not found");return
|
|
54
|
+
`);const K={authority:s.overall||0,authorityScore:s.overall||0,guardUsageCount:a.applicationCount||0,humanUsageCount:a.adoptionCount||0,aiUsageCount:0,lastUsedAt:t.updatedAt||null};return{id:t.id,name:(t.title||t.name||t.id)+".md",content:x,category:t.category||"",language:t.language||"",description:t.description||"",status:t.status||"draft",kind:t.kind||void 0,knowledgeType:t.knowledgeType||void 0,v2Content:t.content||null,relations:t.relations||null,constraints:t.constraints||null,tags:t.tags||[],stats:K,usageGuide:t.usageGuideCn||t.usageGuideEn||"",usageGuide_cn:t.usageGuideCn||"",usageGuide_en:t.usageGuideEn||""}}function _s(t){const s=t.metadata||{},a=t.reasoning||{};return{id:t.id,title:s.title||a.summary||(t.code?t.code.substring(0,60):""),summary:s.summary_cn||s.summary||a.summary||"",summary_cn:s.summary_cn||s.summary||"",summary_en:s.summary_en||"",trigger:s.trigger||"",category:s.category||t.category||"",language:t.language||"",code:t.code||"",headers:s.headers||[],headerPaths:s.headerPaths||[],moduleName:s.moduleName||"",usageGuide:s.usageGuide_cn||s.usageGuide||"",usageGuide_cn:s.usageGuide_cn||"",usageGuide_en:s.usageGuide_en||"",source:t.source||"unknown",createdAt:t.createdAt,status:t.status,quality:t.quality||s.quality||null,reviewNotes:t.reviewNotes||s.reviewNotes||null,relatedRecipes:t.relatedRecipes||s.relatedRecipes||[],knowledgeType:s.knowledgeType||t.knowledgeType||void 0,tags:s.tags||t.tags||[],reasoning:a.whyStandard?{whyStandard:a.whyStandard||"",sources:a.sources||[],confidence:a.confidence??null}:null,agentNotes:s.agentNotes||null,aiInsight:s.aiInsight||null,relations:s.relations||null,refinedConfidence:s.refinedConfidence??null,rationale:s.rationale||"",scope:s.scope||"",steps:s.steps||[],complexity:s.complexity||void 0}}function fl(t){let s="swift",a="general",l="",n="",o="",c="",i="",x="",$="",d=[],y=[],m="",S=0,v="1.0.0",A="",f="",k="",T="",L="",U=t;const B=t.match(/^---\n([\s\S]*?)\n---/);if(B){const K=B[1],b=V=>{const me=K.match(new RegExp(`^${V}:\\s*(.+)$`,"m"));return me?me[1].trim():null};s=b("language")||s,a=b("category")||a,l=b("title")||l,n=b("trigger")||"",o=b("summary_cn")||b("summary")||o,c=b("summary_en")||"",i=b("knowledge_type")||"",x=b("complexity")||"",$=b("scope")||"",m=b("difficulty")||"",v=b("version")||"1.0.0";const R=b("authority");R&&(S=parseInt(R)||0);const M=b("tags");if(M)try{d=JSON.parse(M)}catch{d=M.split(",").map(V=>V.trim()).filter(Boolean)}const H=b("headers");if(H)try{y=JSON.parse(H)}catch{y=[H]}const _=t.match(/```[\w]*\n([\s\S]*?)```/);_&&(U=_[1].trim());const P=t.replace(/^---\n[\s\S]*?\n---/,"").trim(),p=P.match(/## (?:AI Context \/ )?Usage Guide(?:\s*\(CN\))?\n\n([\s\S]*?)(?=\n## |$)/);p&&(A=p[1].trim());const w=P.match(/## (?:AI Context \/ )?Usage Guide\s*\(EN\)\n\n([\s\S]*?)(?=\n## |$)/);w&&(f=w[1].trim());const E=P.match(/## Architecture Usage\n\n([\s\S]*?)(?=\n## |$)/);E&&(k=E[1].trim());const se=P.match(/## Best Practices\n\n([\s\S]*?)(?=\n## |$)/);se&&(T=se[1].trim());const h=P.match(/## Standards\n\n([\s\S]*?)(?=\n## |$)/);h&&(L=h[1].trim())}return{title:l,language:s,category:a,trigger:n,summary:o,summaryEn:c,knowledgeType:i,complexity:x,scope:$,tags:d,headers:y,difficulty:m,authority:S,version:v,codePattern:U,usageGuide:A,usageGuideEn:f,rationaleText:k,bestPracticesText:T,standardsText:L}}function jl(t,s,a){return{code:t.code||"",language:t.language||"swift",category:Array.isArray(t.category)?t.category[0]:t.category||s||"general",source:a,reasoning:{whyStandard:t.summary_cn||t.summary||t.title||"Extracted from project",sources:[a],confidence:.6},metadata:{targetName:s||"",title:t.title||"",trigger:t.trigger||"",summary:t.summary||"",summary_cn:t.summary_cn||"",summary_en:t.summary_en||"",usageGuide:t.usageGuide||"",usageGuide_cn:t.usageGuide_cn||"",usageGuide_en:t.usageGuide_en||"",category:Array.isArray(t.category)?t.category[0]:t.category||"",headers:t.headers||[],headerPaths:t.headerPaths||[],moduleName:t.moduleName||"",isMarked:t.isMarked||!1}}}const te={async fetchData(){var x,$,d,y,m,S,v,A,f;const[t,s,a]=await Promise.all([ne.get("/recipes?limit=1000").catch(()=>({data:{success:!0,data:{data:[]}}})),ne.get("/candidates?limit=1000").catch(()=>({data:{success:!0,data:{data:[]}}})),ne.get("/ai/config").catch(()=>({data:{success:!0,data:{provider:"",model:""}}}))]),n=((($=(x=t.data)==null?void 0:x.data)==null?void 0:$.data)||((y=(d=t.data)==null?void 0:d.data)==null?void 0:y.items)||[]).map(ns),o=((S=(m=s.data)==null?void 0:m.data)==null?void 0:S.data)||((A=(v=s.data)==null?void 0:v.data)==null?void 0:A.items)||[],c={};for(const k of o){const L=(k.metadata||{}).targetName||k.category||k.language||"_pending";c[L]||(c[L]={targetName:L,scanTime:k.createdAt,items:[]}),c[L].items.push(_s(k))}const i=((f=a.data)==null?void 0:f.data)||{provider:"",model:""};return{rootSpec:{list:[]},recipes:n,candidates:c,projectRoot:"",watcherStatus:"active",aiConfig:{provider:i.provider||"",model:i.model||""}}},async fetchTargets(){var a;return(((a=(await ne.get("/spm/targets")).data)==null?void 0:a.data)||{}).targets||[]},async getTargetFiles(t,s){var n,o;const l=((n=(await ne.post("/spm/target-files",{target:t},{signal:s})).data)==null?void 0:n.data)||{};return{files:l.files||[],count:l.total||((o=l.files)==null?void 0:o.length)||0}},async scanTarget(t,s){var o;const l=((o=(await ne.post("/spm/scan",{target:t},{signal:s,timeout:6e5})).data)==null?void 0:o.data)||{};return{recipes:l.recipes||l.result||[],scannedFiles:l.scannedFiles||[],message:l.message||""}},async scanProject(t){var l;const a=((l=(await ne.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 ne.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 ne.get("/spm/bootstrap/status")).data)==null?void 0:s.data)||{status:"idle"}},async getDepGraph(t){var a;return((a=(await ne.get(`/spm/dep-graph?level=${t}`)).data)==null?void 0:a.data)||{}},async syncToXcode(){await ne.post("/commands/install")},async refreshProject(){await ne.post("/commands/spm-map")},async extractFromPath(t){var l;const a=((l=(await ne.post("/extract/path",{relativePath:t})).data)==null?void 0:l.data)||{};return{result:a.result||[],isMarked:a.isMarked||!1}},async extractFromText(t,s){var n;const l=((n=(await ne.post("/extract/text",{text:t,...s?{relativePath:s}:{}})).data)==null?void 0:n.data)||{};return Array.isArray(l.result)&&l.result.length>0?l.result[0]:l},async saveRecipe(t,s){var x,$,d,y;const a=fl(s),l=a.title||t.replace(/\.md$/,""),n={trigger:a.trigger,headers:a.headers,difficulty:a.difficulty,authority:a.authority,version:a.version},o={pattern:a.codePattern||"",rationale:a.rationaleText||"",steps:a.bestPracticesText?[a.bestPracticesText]:[],codeChanges:[],verification:null,markdown:""},c={};if(a.standardsText){const m=a.standardsText.split(`
|
|
55
|
+
`).map(A=>A.trim()).filter(Boolean),S=m.filter(A=>A.startsWith("- ")).map(A=>A.slice(2).trim());S.length>0&&(c.preconditions=S);const v=m.filter(A=>!A.startsWith("- ")&&!A.startsWith("**"));v.length>0&&(c.boundaries=v)}const i={title:l,language:a.language,category:a.category,description:a.summary,summaryCn:a.summary||"",summaryEn:a.summaryEn||"",usageGuideCn:a.usageGuide||"",usageGuideEn:a.usageGuideEn||"",knowledgeType:a.knowledgeType||"code-pattern",complexity:a.complexity||"intermediate",scope:a.scope||null,tags:a.tags||[],content:o,constraints:c,dimensions:n};try{const m=await ne.get(`/recipes?keyword=${encodeURIComponent(l)}&limit=5`),v=((($=(x=m.data)==null?void 0:x.data)==null?void 0:$.data)||((y=(d=m.data)==null?void 0:d.data)==null?void 0:y.items)||[]).find(A=>A.title===l);if(v){await ne.patch(`/recipes/${v.id}`,i);return}}catch{}await ne.post("/recipes",i)},async deleteRecipe(t){var o,c,i,x;const s=t.replace(/\.md$/,""),a=await ne.get(`/recipes?keyword=${encodeURIComponent(s)}&limit=5`),l=((c=(o=a.data)==null?void 0:o.data)==null?void 0:c.data)||((x=(i=a.data)==null?void 0:i.data)==null?void 0:x.items)||[],n=l.find($=>$.title===s)||l[0];if(n!=null&&n.id)await ne.delete(`/recipes/${n.id}`);else throw new Error("Recipe not found")},async getRecipeByName(t){var c,i,x,$;const s=t.replace(/\.md$/,""),a=await ne.get(`/recipes?keyword=${encodeURIComponent(s)}&limit=5`),l=((i=(c=a.data)==null?void 0:c.data)==null?void 0:i.data)||(($=(x=a.data)==null?void 0:x.data)==null?void 0:$.items)||[];if(l.length===0)throw new Error("Recipe not found");const o=l[0].content||{};return{name:t,content:o.pattern||o.markdown||""}},async setRecipeAuthority(t,s){var o,c,i,x;const a=t.replace(/\.md$/,""),l=await ne.get(`/recipes?keyword=${encodeURIComponent(a)}&limit=5`),n=((c=(o=l.data)==null?void 0:o.data)==null?void 0:c.data)||((x=(i=l.data)==null?void 0:i.data)==null?void 0:x.items)||[];n.length>0&&n[0].id&&await ne.patch(`/recipes/${n[0].id}/quality`,{codeCompleteness:s,projectAdaptation:s,documentationClarity:s})},async updateRecipeRelations(t,s){var c,i,x,$;const a=t.replace(/\.md$/,""),l=await ne.get(`/recipes?keyword=${encodeURIComponent(a)}&limit=5`),n=((i=(c=l.data)==null?void 0:c.data)==null?void 0:i.data)||(($=(x=l.data)==null?void 0:x.data)==null?void 0:$.items)||[],o=n.find(d=>d.title===a)||n[0];if(o!=null&&o.id)await ne.patch(`/recipes/${o.id}`,{relations:s});else throw new Error("Recipe not found")},async searchRecipes(t){var n;const a=((n=(await ne.get(`/search?q=${encodeURIComponent(t)}&type=recipe`)).data)==null?void 0:n.data)||{},l=a.recipes||[];return{results:l.map(o=>({name:o.title||o.name||"",content:(o.content||{}).pattern||(o.content||{}).markdown||""})),total:a.totalResults||l.length}},async getCandidate(t){var l;const a=(l=(await ne.get(`/candidates/${t}`)).data)==null?void 0:l.data;if(!a)throw new Error("Candidate not found");return _s(a)},async deleteCandidate(t){await ne.delete(`/candidates/${t}`)},async promoteCandidateToRecipe(t,s){var l;return((l=(await ne.post(`/candidates/${t}/promote`,s||{})).data)==null?void 0:l.data)||{recipe:null,candidate:null}},async enrichCandidates(t){var a;return((a=(await ne.post("/candidates/enrich",{candidateIds:t})).data)==null?void 0:a.data)||{enriched:0,total:0,results:[]}},async bootstrapRefine(t,s,a){var n;return((n=(await ne.post("/candidates/bootstrap-refine",{candidateIds:t,userPrompt:s,dryRun:a},{timeout:3e5})).data)==null?void 0:n.data)||{refined:0,total:0,errors:[],results:[]}},async refinePreview(t,s){var l;return((l=(await ne.post("/candidates/refine-preview",{candidateId:t,userPrompt:s},{timeout:12e4})).data)==null?void 0:l.data)||{}},async refineApply(t,s){var l;return((l=(await ne.post("/candidates/refine-apply",{candidateId:t,userPrompt:s},{timeout:12e4})).data)==null?void 0:l.data)||{}},async getKnowledgeGraph(t=500){var a;return((a=(await ne.get(`/search/graph/all?limit=${t}`)).data)==null?void 0:a.data)||{edges:[],nodeLabels:{},nodeTypes:{},nodeCategories:{}}},async getGraphStats(){var s;return((s=(await ne.get("/search/graph/stats")).data)==null?void 0:s.data)||{totalEdges:0,byRelation:{},nodeTypes:[]}},async discoverRelations(t=20){var a,l,n,o;const s=await ne.post("/recipes/discover-relations",{batchSize:t});if(!((a=s.data)!=null&&a.success))throw new Error(((n=(l=s.data)==null?void 0:l.error)==null?void 0:n.message)||"启动失败");return((o=s.data)==null?void 0:o.data)||{status:"unknown"}},async getDiscoverRelationsStatus(){var s;return((s=(await ne.get("/recipes/discover-relations/status")).data)==null?void 0:s.data)||{status:"idle"}},async deleteAllCandidatesInTarget(t){var a;return((a=(await ne.post("/candidates/batch-delete",{targetName:t})).data)==null?void 0:a.data)||{deleted:0}},async promoteToCandidate(t,s){var n,o;const a=jl(t,s,"review-promote");return{ok:!0,candidateId:((o=(n=(await ne.post("/candidates",a)).data)==null?void 0:n.data)==null?void 0:o.id)||""}},async getCandidateSimilarity(t,s){var l;return((l=(await ne.post("/candidates/similarity",{code:t,language:s})).data)==null?void 0:l.data)||{similar:[]}},async getCandidateSimilarityEx(t){var a;return((a=(await ne.post("/candidates/similarity",t)).data)==null?void 0:a.data)||{similar:[]}},async getRecipeContentByName(t){var i,x,$,d;const s=t.replace(/\.md$/,""),a=await ne.get(`/recipes?keyword=${encodeURIComponent(s)}&limit=5`),l=((x=(i=a.data)==null?void 0:i.data)==null?void 0:x.data)||((d=($=a.data)==null?void 0:$.data)==null?void 0:d.items)||[],n=l.find(y=>y.title===s)||l[0];if(!n)throw new Error("Recipe not found");const c=ns(n);return{name:t,content:c.content}},async getAiProviders(){var s;return((s=(await ne.get("/ai/providers")).data)==null?void 0:s.data)||[]},async setAiConfig(t,s){var l;return((l=(await ne.post("/ai/config",{provider:t,model:s})).data)==null?void 0:l.data)||{provider:t,model:s}},async chat(t,s,a){var o;const n=((o=(await ne.post("/ai/chat",{prompt:t,history:s},{signal:a})).data)==null?void 0:o.data)||{};return{text:n.reply||n.text||"",hasContext:n.hasContext}},async summarizeCode(t,s){var l;const a=await ne.post("/ai/summarize",{code:t,language:s});return((l=a.data)==null?void 0:l.data)||a.data||{}},async translate(t,s){var n,o;const a=await ne.post("/ai/translate",{summary:t,usageGuide:s}),l=((n=a.data)==null?void 0:n.data)||{summary_en:"",usageGuide_en:""};return(o=a.data)!=null&&o.warning&&(l.warning=a.data.warning),l},async semanticSearch(t,s=10){var o;return((((o=(await ne.get(`/search?q=${encodeURIComponent(t)}&mode=semantic&limit=${s}`)).data)==null?void 0:o.data)||{}).recipes||[]).map(c=>({name:(c.title||c.name||"")+".md",content:(c.content||{}).pattern||(c.content||{}).markdown||"",similarity:c.similarity||c.score||0,metadata:{type:"recipe",name:(c.title||c.name||"")+".md"}}))},async xcodeSimulateSearch(t){var a;return((a=(await ne.post("/search/xcode-simulate",t).catch(()=>({data:{data:{}}}))).data)==null?void 0:a.data)||{}},async contextAwareSearch(t){var a;return((a=(await ne.post("/search/context-aware",t).catch(()=>({data:{data:{}}}))).data)==null?void 0:a.data)||{}},async getGuardRules(){var n;const s=((n=(await ne.get("/rules?limit=100")).data)==null?void 0:n.data)||{},a=s.data||s.items||[],l={};for(const o of a)l[o.id]=o;return{rules:l}},async getGuardViolations(){var a;const s=((a=(await ne.get("/violations")).data)==null?void 0:a.data)||{};return{runs:s.data||s.items||[]}},async clearViolations(){await ne.post("/violations/clear")},async generateGuardRule(t){var a;return((a=(await ne.post("/violations/rules/generate",t)).data)==null?void 0:a.data)||{}},async saveGuardRule(t){var a;return((a=(await ne.post("/rules",t)).data)==null?void 0:a.data)||{}},async insertAtSearchMark(t){return{success:!1}},async searchRecipesForModal(t,s){var o;const l=((o=(await ne.get(`/search?q=${encodeURIComponent(t)}&type=recipe`,{signal:s})).data)==null?void 0:o.data)||{},n=l.recipes||[];return{results:n.map(c=>({name:(c.title||c.name||"")+".md",path:"",content:ns(c).content,qualityScore:(c.quality||{}).overall||0,recommendReason:""})),total:l.totalResults||n.length}},async listSkills(){var s;return((s=(await ne.get("/skills")).data)==null?void 0:s.data)||{skills:[],total:0}},async loadSkill(t,s){var n;const a=s?`?section=${encodeURIComponent(s)}`:"";return((n=(await ne.get(`/skills/${encodeURIComponent(t)}${a}`)).data)==null?void 0:n.data)||{}},async createSkill(t){var a;return((a=(await ne.post("/skills",t)).data)==null?void 0:a.data)||{}},async suggestSkills(){var s;return((s=(await ne.get("/skills/suggest")).data)==null?void 0:s.data)||{suggestions:[],analysisContext:{}}},async getSignalStatus(){var s;return((s=(await ne.get("/skills/signal-status")).data)==null?void 0:s.data)||{running:!1,mode:"off",snapshot:null}},async aiGenerateSkill(t){var l;return((l=(await ne.post("/ai/chat",{prompt:`你是一个 AutoSnippet Skill 文档生成助手。用户会描述他们想创建的 Skill,你需要生成完整的 SKILL.md 内容。
|
|
56
56
|
|
|
57
57
|
Skill 文档格式要求:
|
|
58
58
|
1. 开头用 Markdown 标题说明 Skill 的目的
|
|
@@ -75,42 +75,42 @@ Skill 文档格式要求:
|
|
|
75
75
|
## 使用场景
|
|
76
76
|
...
|
|
77
77
|
|
|
78
|
-
用户需求:${t}`,history:[]})).data)==null?void 0:l.data)||{reply:""}},async getLlmEnvConfig(){var s;return((s=(await ne.get("/ai/env-config")).data)==null?void 0:s.data)||{vars:{},hasEnvFile:!1,llmReady:!1}},async saveLlmEnvConfig(t){var a;return((a=(await ne.post("/ai/env-config",t)).data)==null?void 0:a.data)||{vars:{},hasEnvFile:!1,llmReady:!1}}},yl=!1,is="auth_token",os="auth_user";function Nl(){const[t,s]=r.useState(()=>localStorage.getItem(is)),[a,l]=r.useState(()=>{try{const $=localStorage.getItem(os);return $?JSON.parse($):null}catch{return null}}),[n,o]=r.useState(!1),c=r.useCallback(async($,d)=>{var y,m,S,v;o(!0);try{const f=(await St.post("/api/v1/auth/login",{username:$,password:d})).data;if(f.success){const k=f.data.token,T=f.data.user??{username:$,role:"developer"};return localStorage.setItem(is,k),localStorage.setItem(os,JSON.stringify(T)),s(k),l(T),{success:!0}}return{success:!1,error:((y=f.error)==null?void 0:y.message)||"登录失败"}}catch(A){return{success:!1,error:((v=(S=(m=A.response)==null?void 0:m.data)==null?void 0:S.error)==null?void 0:v.message)||A.message||"网络错误"}}finally{o(!1)}},[]),i=r.useCallback(()=>{localStorage.removeItem(is),localStorage.removeItem(os),s(null),l(null)},[]);r.useEffect(()=>{},[]);const x=r.useMemo(()=>!0,[t,a]);return{authEnabled:yl,isAuthenticated:x,isLoading:n,user:a,login:c,logout:i}}const vl={developer:["*"],external_agent:["read:recipes","read:guard_rules","create:candidates","submit:candidates","read:audit_logs:self","knowledge:bootstrap"],chat_agent:["read:recipes","read:candidates","create:candidates","read:guard_rules"]};function wl(t){const[s,a]=r.useState(()=>"developer"),[l,n]=r.useState("anonymous"),[o,c]=r.useState("probe"),[i,x]=r.useState(!0),[$,d]=r.useState(null),y=r.useCallback(async()=>{x(!0);try{const f=localStorage.getItem("auth_token"),k={};f&&(k.Authorization=`Bearer ${f}`);const T=await St.get("/api/v1/auth/probe",{headers:k});if(T.data.success){const L=T.data.data;a(L.role),n(L.user),c(L.mode),d(L.probeCache??null)}}catch{a("developer")}finally{x(!1)}},[]);r.useEffect(()=>{y()},[t,y]);const m=r.useCallback((f,k)=>{const T=vl[s]||[];if(T.includes("*"))return!0;const L=k?`${f}:${k}`:f;if(T.includes(L))return!0;const U=f.split(":")[0];return!!(T.includes(`${U}:*`)||U==="read"&&T.includes("read:*"))},[s]),S=r.useMemo(()=>s==="developer",[s]),v=r.useMemo(()=>s==="developer",[s]),A=r.useMemo(()=>s!=="developer",[s]);return{role:s,user:l,mode:o,isLoading:i,isAdmin:S,canWrite:v,isReadOnly:A,can:m,probeCache:$,refresh:y}}let _t=null;function ra(){return _t||(_t=pa(window.location.origin,{path:"/socket.io",transports:["websocket","polling"],reconnection:!0,reconnectionAttempts:1/0,reconnectionDelay:1e3,reconnectionDelayMax:5e3}),_t.on("connect",()=>{_t.emit("join-notifications")})),_t}const cs={activeRound:0,round1:{status:"idle"},round2:{status:"idle"},round3:{status:"idle"}};function kl(){const[t,s]=r.useState(null),[a,l]=r.useState(!1),[n,o]=r.useState(cs),c=r.useRef(null);r.useEffect(()=>{const d=ra(),y=()=>{l(!0),S()},m=()=>l(!1),S=async()=>{try{const z=await te.getBootstrapStatus();z&&z.status!=="idle"&&z.tasks&&s(P=>!P||P.id===z.id||z.progress>((P==null?void 0:P.progress)??0)?(c.current=z.id,z):P)}catch{}},v=()=>S(),A=z=>{c.current=z.sessionId,o(cs),s({id:z.sessionId,status:"running",progress:0,total:z.total,completed:0,failed:0,filling:0,skeleton:z.total,startedAt:z.startedAt||Date.now(),totalToolCalls:0,elapsedMs:0,tasks:z.tasks.map(P=>({id:P.id,status:"skeleton",meta:{type:P.type,dimId:P.dimId,label:P.label,skillWorthy:P.skillWorthy,skillMeta:P.skillMeta}}))})},f=z=>{s(P=>{if(!P)return P;const p=P.tasks.map(w=>w.id===z.taskId?{...w,status:"filling",startedAt:Date.now()}:w);return{...P,progress:z.progress,tasks:p,filling:p.filter(w=>w.status==="filling").length,skeleton:p.filter(w=>w.status==="skeleton").length}})},k=z=>{s(P=>{if(!P)return P;const p=P.tasks.map(w=>w.id===z.taskId?{...w,status:"completed",completedAt:Date.now(),result:z.result}:w);return{...P,progress:z.progress,completed:z.completed,total:z.total,totalToolCalls:z.totalToolCalls??P.totalToolCalls,elapsedMs:z.elapsedMs??P.elapsedMs,tasks:p,filling:p.filter(w=>w.status==="filling").length,skeleton:p.filter(w=>w.status==="skeleton").length}})},T=z=>{s(P=>{if(!P)return P;const p=P.tasks.map(w=>w.id===z.taskId?{...w,status:"failed",completedAt:Date.now(),error:z.error}:w);return{...P,progress:z.progress,failed:p.filter(w=>w.status==="failed").length,tasks:p,filling:p.filter(w=>w.status==="filling").length,skeleton:p.filter(w=>w.status==="skeleton").length}})},L=z=>{s(P=>{if(!P||z.sessionId&&P.id!==z.sessionId)return P;const p=P.tasks.map(w=>w.status==="skeleton"||w.status==="filling"?{...w,status:"completed",completedAt:Date.now()}:w);return{...P,status:p.some(w=>w.status==="failed")?"completed_with_errors":"completed",progress:100,completed:p.filter(w=>w.status==="completed").length,summary:z.summary,tasks:p,filling:0,skeleton:0}})},U=z=>{o(P=>({...P,activeRound:1,round1:{status:"running",total:z.total}}))},B=z=>{o(P=>({...P,activeRound:1,round1:{status:"completed",total:z.total,kept:z.kept,dropped:z.dropped,merged:z.merged}}))},K=z=>{o(P=>({...P,activeRound:2,round2:{status:"running",total:z.total}}))},b=z=>{o(P=>({...P,activeRound:2,round2:{...P.round2,status:"running",current:z.current,total:z.total,progress:z.progress}}))},R=z=>{o(P=>({...P,activeRound:2,round2:{status:"completed",total:z.total,refined:z.refined,progress:100}}))},M=z=>{o(P=>({...P,activeRound:3,round3:{status:"running",total:z.total}}))},H=z=>{o(P=>({...P,activeRound:3,round3:{status:"completed",total:z.total,afterDedup:z.afterDedup,relationsFound:z.relationsFound}}))};return d.on("connect",y),d.on("disconnect",m),d.io.on("reconnect",v),d.on("bootstrap:started",A),d.on("bootstrap:task-started",f),d.on("bootstrap:task-completed",k),d.on("bootstrap:task-failed",T),d.on("bootstrap:all-completed",L),d.on("review:round1-started",U),d.on("review:round1-completed",B),d.on("review:round2-started",K),d.on("review:round2-progress",b),d.on("review:round2-completed",R),d.on("review:round3-started",M),d.on("review:round3-completed",H),l(d.connected),d.connected&&S(),()=>{d.off("connect",y),d.off("disconnect",m),d.io.off("reconnect",v),d.off("bootstrap:started",A),d.off("bootstrap:task-started",f),d.off("bootstrap:task-completed",k),d.off("bootstrap:task-failed",T),d.off("bootstrap:all-completed",L),d.off("review:round1-started",U),d.off("review:round1-completed",B),d.off("review:round2-started",K),d.off("review:round2-progress",b),d.off("review:round2-completed",R),d.off("review:round3-started",M),d.off("review:round3-completed",H)}},[]);const i=r.useCallback(()=>{c.current=null,s(null),o(cs)},[]),x=r.useCallback(d=>{d&&s(y=>{if(y&&y.id===d.id){const m=(y.filling??0)+(y.completed??0)+(y.failed??0),S=(d.filling??0)+(d.completed??0)+(d.failed??0);if(y.progress>d.progress||m>S)return y}return c.current=d.id,d})},[]),$=(t==null?void 0:t.status)==="completed"||(t==null?void 0:t.status)==="completed_with_errors";return{session:t,isConnected:a,isAllDone:$,reviewState:n,resetSession:i,initFromApiResponse:x}}const _={xs:12,sm:14,md:16,lg:20,xl:24,xxl:32,xxxl:48},_s={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"}},Sl={token:za,probe:$t},Cl=({activeTab:t,navigateToTab:s,handleRefreshProject:a,candidateCount:l,signalSuggestionCount:n=0,isDarkMode:o=!1,currentUser:c,currentRole:i,permissionMode:x,onLogout:$,collapsed:d=!1,onToggleCollapse:y})=>{const m=_s[i||""]||_s.developer,S=Sl[x||"probe"]||$t,v=[{tab:"recipes",icon:$a,label:"Recipes"},{tab:"spm",icon:Us,label:"SPM Explorer"},{tab:"candidates",icon:Nt,label:`Candidates (${l})`},{tab:"depgraph",icon:bs,label:"依赖关系图"},{tab:"knowledgegraph",icon:ps,label:"知识图谱"},{tab:"guard",icon:bt,label:"Guard"},{tab:"skills",icon:at,label:"Skills",badge:n>0?n:void 0,badgeColor:"bg-amber-100 text-amber-700"},{tab:"ai",icon:vt,label:"AI Assistant"},{tab:"editor",icon:mt,label:"编辑器(测试)"},{tab:"help",icon:Aa,label:"使用说明"}],A=o?"bg-blue-900/30 text-blue-400 font-medium":"bg-blue-50 text-blue-700 font-medium",f=o?"text-slate-300 hover:bg-slate-700/50":"text-slate-600 hover:bg-slate-50";return e.jsxs("aside",{className:`${d?"w-16":"w-64"} ${o?"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:`${d?"px-3 py-4":"p-6"} border-b ${o?"border-[#3e3e42]":"border-slate-100"} flex items-center ${d?"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(ss,{size:_.lg})}),!d&&e.jsx("h1",{className:"font-bold text-lg truncate",children:"AutoSnippet"})]}),y&&!d&&e.jsx("button",{onClick:y,className:`p-1 rounded-md transition-colors ${o?"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(Ca,{size:16})})]}),d&&y&&e.jsx("div",{className:"flex justify-center py-2",children:e.jsx("button",{onClick:y,className:`p-1.5 rounded-md transition-colors ${o?"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(Ia,{size:16})})}),e.jsx("nav",{className:`flex-1 ${d?"px-2 py-2":"p-4"} space-y-1 overflow-y-auto scrollbar-light`,children:v.map(({tab:k,icon:T,label:L,badge:U,badgeColor:B})=>e.jsxs("button",{type:"button",onClick:()=>s(k),title:d?L:void 0,className:`w-full flex items-center ${d?"justify-center px-2 py-2.5 relative":"gap-3 px-4 py-2"} rounded-lg transition-colors ${t===k?A:f}`,children:[e.jsx(T,{size:_.lg,className:"shrink-0"}),!d&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"flex-1 text-left truncate text-[13px]",children:L}),U!=null&&e.jsxs("span",{className:`flex items-center gap-0.5 px-1.5 py-0.5 rounded-full text-[10px] font-bold ${B||"bg-blue-100 text-blue-700"}`,children:[e.jsx(Ye,{size:10}),U]})]}),d&&U!=null&&e.jsx("span",{className:"absolute top-0 right-0 w-2 h-2 rounded-full bg-amber-400"})]},k))}),e.jsxs("div",{className:`${d?"px-2 py-3":"p-4"} ${o?"border-t border-[#3e3e42]":"border-t border-slate-100"}`,children:[!d&&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 ${o?"bg-slate-700/30 border-slate-600 text-slate-400":m.bg+" "+m.color}`,children:[e.jsx(S,{size:_.xs}),e.jsx("span",{children:x==="token"?"登录":"探针"}),e.jsx("span",{className:"mx-0.5",children:"·"}),e.jsx(_a,{size:_.xs}),e.jsx("span",{children:m.label})]}),c&&e.jsxs("div",{className:`flex items-center justify-between mb-3 px-2 py-1.5 rounded-lg ${o?"bg-slate-700/30":"bg-slate-50"}`,children:[e.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[e.jsx(Hs,{size:_.sm,className:o?"text-slate-400":"text-slate-500"}),e.jsx("span",{className:`text-xs font-medium truncate ${o?"text-slate-300":"text-slate-600"}`,children:c})]}),$&&e.jsx("button",{onClick:$,title:"登出",className:`shrink-0 p-1 rounded transition-colors ${o?"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(Ra,{size:_.sm})})]})]}),e.jsxs("button",{onClick:a,title:d?"Refresh Project":void 0,className:`w-full flex items-center ${d?"justify-center py-2":"justify-center gap-2 text-[10px] font-bold uppercase"} ${o?"text-slate-400 hover:text-blue-400":"text-slate-400 hover:text-blue-600"} transition-colors`,children:[e.jsx(wt,{size:d?_.lg:_.xs}),!d&&e.jsx("span",{children:"Refresh Project"})]})]})]})},Il={objectivec:"objectivec",objc:"objectivec","objective-c":"objectivec","obj-c":"objectivec",swift:"swift",markdown:"markdown",md:"markdown"},At=({code:t,language:s="text",className:a="",showLineNumbers:l=!1})=>{const n=Il[s==null?void 0:s.toLowerCase()]||(s==null?void 0:s.toLowerCase())||"text",o=a.includes("!rounded-none");return e.jsx("div",{className:`rounded-xl overflow-hidden text-sm ${a}`,children:e.jsx(sa,{language:n,style:aa,showLineNumbers:l,customStyle:{margin:0,padding:"1rem 1.25rem",fontSize:"0.8125rem",lineHeight:1.5,borderRadius:o?0:"0.75rem"},codeTagProps:{style:{fontFamily:"ui-monospace, monospace"}},PreTag:"div",children:t})})};function Ns(t){return!t||typeof t!="string"?t:t.replace(/^---\r?\n[\s\S]*?\r?\n---\r?\n?/,"").trim()||t}const lt=({content:t,className:s="",showLineNumbers:a=!1,stripFrontmatter:l=!1})=>{const n=i=>!i||typeof i!="string"?i:i.replace(/\\\\n/g,`
|
|
78
|
+
用户需求:${t}`,history:[]})).data)==null?void 0:l.data)||{reply:""}},async getLlmEnvConfig(){var s;return((s=(await ne.get("/ai/env-config")).data)==null?void 0:s.data)||{vars:{},hasEnvFile:!1,llmReady:!1}},async saveLlmEnvConfig(t){var a;return((a=(await ne.post("/ai/env-config",t)).data)==null?void 0:a.data)||{vars:{},hasEnvFile:!1,llmReady:!1}}},yl=!1,is="auth_token",os="auth_user";function Nl(){const[t,s]=r.useState(()=>localStorage.getItem(is)),[a,l]=r.useState(()=>{try{const $=localStorage.getItem(os);return $?JSON.parse($):null}catch{return null}}),[n,o]=r.useState(!1),c=r.useCallback(async($,d)=>{var y,m,S,v;o(!0);try{const f=(await St.post("/api/v1/auth/login",{username:$,password:d})).data;if(f.success){const k=f.data.token,T=f.data.user??{username:$,role:"developer"};return localStorage.setItem(is,k),localStorage.setItem(os,JSON.stringify(T)),s(k),l(T),{success:!0}}return{success:!1,error:((y=f.error)==null?void 0:y.message)||"登录失败"}}catch(A){return{success:!1,error:((v=(S=(m=A.response)==null?void 0:m.data)==null?void 0:S.error)==null?void 0:v.message)||A.message||"网络错误"}}finally{o(!1)}},[]),i=r.useCallback(()=>{localStorage.removeItem(is),localStorage.removeItem(os),s(null),l(null)},[]);r.useEffect(()=>{},[]);const x=r.useMemo(()=>!0,[t,a]);return{authEnabled:yl,isAuthenticated:x,isLoading:n,user:a,login:c,logout:i}}const vl={developer:["*"],external_agent:["read:recipes","read:guard_rules","create:candidates","submit:candidates","read:audit_logs:self","knowledge:bootstrap"],chat_agent:["read:recipes","read:candidates","create:candidates","read:guard_rules"]};function wl(t){const[s,a]=r.useState(()=>"developer"),[l,n]=r.useState("anonymous"),[o,c]=r.useState("probe"),[i,x]=r.useState(!0),[$,d]=r.useState(null),y=r.useCallback(async()=>{x(!0);try{const f=localStorage.getItem("auth_token"),k={};f&&(k.Authorization=`Bearer ${f}`);const T=await St.get("/api/v1/auth/probe",{headers:k});if(T.data.success){const L=T.data.data;a(L.role),n(L.user),c(L.mode),d(L.probeCache??null)}}catch{a("developer")}finally{x(!1)}},[]);r.useEffect(()=>{y()},[t,y]);const m=r.useCallback((f,k)=>{const T=vl[s]||[];if(T.includes("*"))return!0;const L=k?`${f}:${k}`:f;if(T.includes(L))return!0;const U=f.split(":")[0];return!!(T.includes(`${U}:*`)||U==="read"&&T.includes("read:*"))},[s]),S=r.useMemo(()=>s==="developer",[s]),v=r.useMemo(()=>s==="developer",[s]),A=r.useMemo(()=>s!=="developer",[s]);return{role:s,user:l,mode:o,isLoading:i,isAdmin:S,canWrite:v,isReadOnly:A,can:m,probeCache:$,refresh:y}}let zt=null;function ra(){return zt||(zt=pa(window.location.origin,{path:"/socket.io",transports:["websocket","polling"],reconnection:!0,reconnectionAttempts:1/0,reconnectionDelay:1e3,reconnectionDelayMax:5e3}),zt.on("connect",()=>{zt.emit("join-notifications")})),zt}const cs={activeRound:0,round1:{status:"idle"},round2:{status:"idle"},round3:{status:"idle"}};function kl(){const[t,s]=r.useState(null),[a,l]=r.useState(!1),[n,o]=r.useState(cs),c=r.useRef(null);r.useEffect(()=>{const d=ra(),y=()=>{l(!0),S()},m=()=>l(!1),S=async()=>{try{const _=await te.getBootstrapStatus();_&&_.status!=="idle"&&_.tasks&&s(P=>!P||P.id===_.id||_.progress>((P==null?void 0:P.progress)??0)?(c.current=_.id,_):P)}catch{}},v=()=>S(),A=_=>{c.current=_.sessionId,o(cs),s({id:_.sessionId,status:"running",progress:0,total:_.total,completed:0,failed:0,filling:0,skeleton:_.total,startedAt:_.startedAt||Date.now(),totalToolCalls:0,elapsedMs:0,tasks:_.tasks.map(P=>({id:P.id,status:"skeleton",meta:{type:P.type,dimId:P.dimId,label:P.label,skillWorthy:P.skillWorthy,skillMeta:P.skillMeta}}))})},f=_=>{s(P=>{if(!P)return P;const p=P.tasks.map(w=>w.id===_.taskId?{...w,status:"filling",startedAt:Date.now()}:w);return{...P,progress:_.progress,tasks:p,filling:p.filter(w=>w.status==="filling").length,skeleton:p.filter(w=>w.status==="skeleton").length}})},k=_=>{s(P=>{if(!P)return P;const p=P.tasks.map(w=>w.id===_.taskId?{...w,status:"completed",completedAt:Date.now(),result:_.result}:w);return{...P,progress:_.progress,completed:_.completed,total:_.total,totalToolCalls:_.totalToolCalls??P.totalToolCalls,elapsedMs:_.elapsedMs??P.elapsedMs,tasks:p,filling:p.filter(w=>w.status==="filling").length,skeleton:p.filter(w=>w.status==="skeleton").length}})},T=_=>{s(P=>{if(!P)return P;const p=P.tasks.map(w=>w.id===_.taskId?{...w,status:"failed",completedAt:Date.now(),error:_.error}:w);return{...P,progress:_.progress,failed:p.filter(w=>w.status==="failed").length,tasks:p,filling:p.filter(w=>w.status==="filling").length,skeleton:p.filter(w=>w.status==="skeleton").length}})},L=_=>{s(P=>{if(!P||_.sessionId&&P.id!==_.sessionId)return P;const p=P.tasks.map(w=>w.status==="skeleton"||w.status==="filling"?{...w,status:"completed",completedAt:Date.now()}:w);return{...P,status:p.some(w=>w.status==="failed")?"completed_with_errors":"completed",progress:100,completed:p.filter(w=>w.status==="completed").length,summary:_.summary,tasks:p,filling:0,skeleton:0}})},U=_=>{o(P=>({...P,activeRound:1,round1:{status:"running",total:_.total}}))},B=_=>{o(P=>({...P,activeRound:1,round1:{status:"completed",total:_.total,kept:_.kept,dropped:_.dropped,merged:_.merged}}))},K=_=>{o(P=>({...P,activeRound:2,round2:{status:"running",total:_.total}}))},b=_=>{o(P=>({...P,activeRound:2,round2:{...P.round2,status:"running",current:_.current,total:_.total,progress:_.progress}}))},R=_=>{o(P=>({...P,activeRound:2,round2:{status:"completed",total:_.total,refined:_.refined,progress:100}}))},M=_=>{o(P=>({...P,activeRound:3,round3:{status:"running",total:_.total}}))},H=_=>{o(P=>({...P,activeRound:3,round3:{status:"completed",total:_.total,afterDedup:_.afterDedup,relationsFound:_.relationsFound}}))};return d.on("connect",y),d.on("disconnect",m),d.io.on("reconnect",v),d.on("bootstrap:started",A),d.on("bootstrap:task-started",f),d.on("bootstrap:task-completed",k),d.on("bootstrap:task-failed",T),d.on("bootstrap:all-completed",L),d.on("review:round1-started",U),d.on("review:round1-completed",B),d.on("review:round2-started",K),d.on("review:round2-progress",b),d.on("review:round2-completed",R),d.on("review:round3-started",M),d.on("review:round3-completed",H),l(d.connected),d.connected&&S(),()=>{d.off("connect",y),d.off("disconnect",m),d.io.off("reconnect",v),d.off("bootstrap:started",A),d.off("bootstrap:task-started",f),d.off("bootstrap:task-completed",k),d.off("bootstrap:task-failed",T),d.off("bootstrap:all-completed",L),d.off("review:round1-started",U),d.off("review:round1-completed",B),d.off("review:round2-started",K),d.off("review:round2-progress",b),d.off("review:round2-completed",R),d.off("review:round3-started",M),d.off("review:round3-completed",H)}},[]);const i=r.useCallback(()=>{c.current=null,s(null),o(cs)},[]),x=r.useCallback(d=>{d&&s(y=>{if(y&&y.id===d.id){const m=(y.filling??0)+(y.completed??0)+(y.failed??0),S=(d.filling??0)+(d.completed??0)+(d.failed??0);if(y.progress>d.progress||m>S)return y}return c.current=d.id,d})},[]),$=(t==null?void 0:t.status)==="completed"||(t==null?void 0:t.status)==="completed_with_errors";return{session:t,isConnected:a,isAllDone:$,reviewState:n,resetSession:i,initFromApiResponse:x}}const z={xs:12,sm:14,md:16,lg:20,xl:24,xxl:32,xxxl:48},zs={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"}},Sl={token:_a,probe:$t},Cl=({activeTab:t,navigateToTab:s,handleRefreshProject:a,candidateCount:l,signalSuggestionCount:n=0,isDarkMode:o=!1,currentUser:c,currentRole:i,permissionMode:x,onLogout:$,collapsed:d=!1,onToggleCollapse:y})=>{const m=zs[i||""]||zs.developer,S=Sl[x||"probe"]||$t,v=[{tab:"recipes",icon:$a,label:"Recipes"},{tab:"spm",icon:Us,label:"SPM Explorer"},{tab:"candidates",icon:Nt,label:`Candidates (${l})`},{tab:"depgraph",icon:bs,label:"依赖关系图"},{tab:"knowledgegraph",icon:ps,label:"知识图谱"},{tab:"guard",icon:bt,label:"Guard"},{tab:"skills",icon:at,label:"Skills",badge:n>0?n:void 0,badgeColor:"bg-amber-100 text-amber-700"},{tab:"ai",icon:vt,label:"AI Assistant"},{tab:"editor",icon:mt,label:"编辑器(测试)"},{tab:"help",icon:Aa,label:"使用说明"}],A=o?"bg-blue-900/30 text-blue-400 font-medium":"bg-blue-50 text-blue-700 font-medium",f=o?"text-slate-300 hover:bg-slate-700/50":"text-slate-600 hover:bg-slate-50";return e.jsxs("aside",{className:`${d?"w-16":"w-64"} ${o?"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:`${d?"px-3 py-4":"p-6"} border-b ${o?"border-[#3e3e42]":"border-slate-100"} flex items-center ${d?"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(ss,{size:z.lg})}),!d&&e.jsx("h1",{className:"font-bold text-lg truncate",children:"AutoSnippet"})]}),y&&!d&&e.jsx("button",{onClick:y,className:`p-1 rounded-md transition-colors ${o?"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(Ca,{size:16})})]}),d&&y&&e.jsx("div",{className:"flex justify-center py-2",children:e.jsx("button",{onClick:y,className:`p-1.5 rounded-md transition-colors ${o?"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(Ia,{size:16})})}),e.jsx("nav",{className:`flex-1 ${d?"px-2 py-2":"p-4"} space-y-1 overflow-y-auto scrollbar-light`,children:v.map(({tab:k,icon:T,label:L,badge:U,badgeColor:B})=>e.jsxs("button",{type:"button",onClick:()=>s(k),title:d?L:void 0,className:`w-full flex items-center ${d?"justify-center px-2 py-2.5 relative":"gap-3 px-4 py-2"} rounded-lg transition-colors ${t===k?A:f}`,children:[e.jsx(T,{size:z.lg,className:"shrink-0"}),!d&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"flex-1 text-left truncate text-[13px]",children:L}),U!=null&&e.jsxs("span",{className:`flex items-center gap-0.5 px-1.5 py-0.5 rounded-full text-[10px] font-bold ${B||"bg-blue-100 text-blue-700"}`,children:[e.jsx(Ye,{size:10}),U]})]}),d&&U!=null&&e.jsx("span",{className:"absolute top-0 right-0 w-2 h-2 rounded-full bg-amber-400"})]},k))}),e.jsxs("div",{className:`${d?"px-2 py-3":"p-4"} ${o?"border-t border-[#3e3e42]":"border-t border-slate-100"}`,children:[!d&&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 ${o?"bg-slate-700/30 border-slate-600 text-slate-400":m.bg+" "+m.color}`,children:[e.jsx(S,{size:z.xs}),e.jsx("span",{children:x==="token"?"登录":"探针"}),e.jsx("span",{className:"mx-0.5",children:"·"}),e.jsx(za,{size:z.xs}),e.jsx("span",{children:m.label})]}),c&&e.jsxs("div",{className:`flex items-center justify-between mb-3 px-2 py-1.5 rounded-lg ${o?"bg-slate-700/30":"bg-slate-50"}`,children:[e.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[e.jsx(Hs,{size:z.sm,className:o?"text-slate-400":"text-slate-500"}),e.jsx("span",{className:`text-xs font-medium truncate ${o?"text-slate-300":"text-slate-600"}`,children:c})]}),$&&e.jsx("button",{onClick:$,title:"登出",className:`shrink-0 p-1 rounded transition-colors ${o?"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(Ra,{size:z.sm})})]})]}),e.jsxs("button",{onClick:a,title:d?"Refresh Project":void 0,className:`w-full flex items-center ${d?"justify-center py-2":"justify-center gap-2 text-[10px] font-bold uppercase"} ${o?"text-slate-400 hover:text-blue-400":"text-slate-400 hover:text-blue-600"} transition-colors`,children:[e.jsx(wt,{size:d?z.lg:z.xs}),!d&&e.jsx("span",{children:"Refresh Project"})]})]})]})},Il={objectivec:"objectivec",objc:"objectivec","objective-c":"objectivec","obj-c":"objectivec",swift:"swift",markdown:"markdown",md:"markdown"},At=({code:t,language:s="text",className:a="",showLineNumbers:l=!1})=>{const n=Il[s==null?void 0:s.toLowerCase()]||(s==null?void 0:s.toLowerCase())||"text",o=a.includes("!rounded-none");return e.jsx("div",{className:`rounded-xl overflow-hidden text-sm ${a}`,children:e.jsx(sa,{language:n,style:aa,showLineNumbers:l,customStyle:{margin:0,padding:"1rem 1.25rem",fontSize:"0.8125rem",lineHeight:1.5,borderRadius:o?0:"0.75rem"},codeTagProps:{style:{fontFamily:"ui-monospace, monospace"}},PreTag:"div",children:t})})};function Ns(t){return!t||typeof t!="string"?t:t.replace(/^---\r?\n[\s\S]*?\r?\n---\r?\n?/,"").trim()||t}const lt=({content:t,className:s="",showLineNumbers:a=!1,stripFrontmatter:l=!1})=>{const n=i=>!i||typeof i!="string"?i:i.replace(/\\\\n/g,`
|
|
79
79
|
`),o=i=>!i||typeof i!="string"?i:i.replace(/([^\n])\n(?!\n)/g,`$1
|
|
80
80
|
`);let c=l?Ns(t):t;return c=n(c),c=o(c),e.jsx("div",{className:`markdown-body text-slate-700 ${s}`,children:e.jsx(sl,{components:{code({node:i,className:x,children:$,...d}){const y=/language-(\w+)/.exec(x||"");return String($).includes(`
|
|
81
|
-
`)&&y?e.jsx(At,{code:String($).replace(/\n$/,""),language:y[1],showLineNumbers:a}):e.jsx("code",{className:"px-1.5 py-0.5 bg-slate-100 text-slate-800 rounded text-sm font-mono",...d,children:$})},p:({children:i})=>e.jsx("p",{className:"mb-3 last:mb-0",children:i}),h1:({children:i})=>e.jsx("h1",{className:"text-xl font-bold mb-2 mt-4 first:mt-0",children:i}),h2:({children:i})=>e.jsx("h2",{className:"text-lg font-bold mb-2 mt-4",children:i}),h3:({children:i})=>e.jsx("h3",{className:"text-base font-bold mb-1 mt-3",children:i}),ul:({children:i})=>e.jsx("ul",{className:"list-disc list-inside mb-3 space-y-1",children:i}),ol:({children:i})=>e.jsx("ol",{className:"list-decimal list-inside mb-3 space-y-1",children:i}),blockquote:({children:i})=>e.jsx("blockquote",{className:"border-l-4 border-slate-200 pl-4 my-3 text-slate-600 italic",children:i}),a:({href:i,children:x})=>e.jsx("a",{href:i,className:"text-blue-600 hover:underline",target:"_blank",rel:"noopener noreferrer",children:x})},children:c})})},na="asd-chat-topics",$l=50;function Al(){return Date.now().toString(36)+Math.random().toString(36).substring(2,8)}function
|
|
82
|
-
`):String(t||"")},{key:"relations",label:"关联关系",format:t=>JSON.stringify(t||[],null,2)}];function Tl(t,s){const a=[];for(const l of El){const n=l.format||(i=>String(i??"")),o=n(t[l.key]),c=n(s[l.key]);c&&c!==o&&a.push({field:l.key,label:l.label,before:o,after:c})}return a}function Ml(t){var s;return{title:t.title||"",summary:t.summary||"",code:t.code||"",tags:t.tags||[],confidence:((s=t.reasoning)==null?void 0:s.confidence)??.6,relations:t.relations||[],insight:null,agentNotes:null}}const Gl=({diff:t})=>t.length===0?e.jsx("p",{className:"text-xs text-slate-400 italic py-2",children:"未检测到变更"}):e.jsx("div",{className:"space-y-2 mt-2",children:t.map(s=>e.jsxs("div",{className:"border border-slate-200 rounded-lg overflow-hidden",children:[e.jsxs("div",{className:"px-2.5 py-1 bg-slate-50 border-b border-slate-200 flex items-center gap-1.5",children:[e.jsx(Ws,{size:10,className:"text-emerald-500"}),e.jsx("span",{className:"text-[10px] font-bold text-slate-600",children:s.label})]}),e.jsxs("div",{className:"p-2 bg-red-50/30 border-b border-slate-200",children:[e.jsx("div",{className:"text-[9px] font-bold text-red-400 mb-0.5 uppercase",children:"Before"}),e.jsx("pre",{className:"text-[11px] text-slate-600 whitespace-pre-wrap break-words max-h-40 overflow-auto font-mono leading-relaxed scrollbar-light",children:s.before||e.jsx("span",{className:"italic text-slate-300",children:"(空)"})})]}),e.jsxs("div",{className:"p-2 bg-emerald-50/30",children:[e.jsx("div",{className:"text-[9px] font-bold text-emerald-500 mb-0.5 uppercase",children:"After"}),e.jsx("pre",{className:"text-[11px] text-slate-700 whitespace-pre-wrap break-words max-h-40 overflow-auto font-mono leading-relaxed scrollbar-light",children:s.after})]})]},s.field))}),vs=r.createContext(null),Dl=()=>r.useContext(vs),Pl=({children:t})=>{const[s,a]=r.useState(!1),[l,n]=r.useState([]),[o,c]=r.useState(!1),[i,x]=r.useState(!1),[$,d]=r.useState(null),[y,m]=r.useState(new Set),[S,v]=r.useState(""),A=r.useRef([]),f=!!$,k=$?$.candidateIds[$.currentIdx]:null,T=$?$.candidates.find(
|
|
81
|
+
`)&&y?e.jsx(At,{code:String($).replace(/\n$/,""),language:y[1],showLineNumbers:a}):e.jsx("code",{className:"px-1.5 py-0.5 bg-slate-100 text-slate-800 rounded text-sm font-mono",...d,children:$})},p:({children:i})=>e.jsx("p",{className:"mb-3 last:mb-0",children:i}),h1:({children:i})=>e.jsx("h1",{className:"text-xl font-bold mb-2 mt-4 first:mt-0",children:i}),h2:({children:i})=>e.jsx("h2",{className:"text-lg font-bold mb-2 mt-4",children:i}),h3:({children:i})=>e.jsx("h3",{className:"text-base font-bold mb-1 mt-3",children:i}),ul:({children:i})=>e.jsx("ul",{className:"list-disc list-inside mb-3 space-y-1",children:i}),ol:({children:i})=>e.jsx("ol",{className:"list-decimal list-inside mb-3 space-y-1",children:i}),blockquote:({children:i})=>e.jsx("blockquote",{className:"border-l-4 border-slate-200 pl-4 my-3 text-slate-600 italic",children:i}),a:({href:i,children:x})=>e.jsx("a",{href:i,className:"text-blue-600 hover:underline",target:"_blank",rel:"noopener noreferrer",children:x})},children:c})})},na="asd-chat-topics",$l=50;function Al(){return Date.now().toString(36)+Math.random().toString(36).substring(2,8)}function _l(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 zl(){try{const t=localStorage.getItem(na);if(!t)return[];const s=JSON.parse(t);return Array.isArray(s)?s:[]}catch{return[]}}function Rl(t){try{const s=t.slice(0,$l);localStorage.setItem(na,JSON.stringify(s))}catch(s){console.warn("[ChatTopics] localStorage save failed:",s)}}function ia(){const[t,s]=r.useState(()=>zl()),[a,l]=r.useState(null),n=r.useRef(t);r.useEffect(()=>{n.current=t},[t]);const o=r.useCallback(m=>{s(S=>{const v=typeof m=="function"?m(S):m;return Rl(v),v})},[]),c=r.useCallback(m=>{const S=Al(),v={id:S,title:m||"新话题",messages:[],createdAt:Date.now(),updatedAt:Date.now()};return o(A=>[v,...A]),l(S),S},[o]),i=r.useCallback(m=>{o(S=>S.filter(v=>v.id!==m)),l(S=>S===m?null:S)},[o]),x=r.useCallback((m,S)=>{o(v=>{const A=v.findIndex(L=>L.id===m);if(A<0)return v;const f={...v[A],messages:S,updatedAt:Date.now()},k=_l(S);k!=="新话题"&&(f.title=k);const T=[...v];return T[A]=f,T.splice(A,1),T.unshift(f),T})},[o]),$=r.useCallback(m=>n.current.find(S=>S.id===m),[]),d=r.useCallback(m=>{l(m)},[]),y=t.find(m=>m.id===a)??null;return{topics:t,activeTopicId:a,activeTopic:y,createTopic:c,deleteTopic:i,saveTopic:x,getTopic:$,switchTopic:d,setActiveTopicId:l}}const oa=r.createContext({openChat:()=>{},openRefine:()=>{},close:()=>{},toggle:()=>{},newTopic:()=>{},isOpen:!1}),Ht=()=>r.useContext(oa),xt=()=>Math.random().toString(36).substring(2,10),El=[{key:"summary",label:"摘要"},{key:"code",label:"内容文档"},{key:"tags",label:"标签",format:t=>Array.isArray(t)?t.join(", "):String(t||"")},{key:"confidence",label:"置信度",format:t=>String(t??"—")},{key:"insight",label:"AI 洞察"},{key:"agentNotes",label:"Agent 笔记",format:t=>Array.isArray(t)?t.join(`
|
|
82
|
+
`):String(t||"")},{key:"relations",label:"关联关系",format:t=>JSON.stringify(t||[],null,2)}];function Tl(t,s){const a=[];for(const l of El){const n=l.format||(i=>String(i??"")),o=n(t[l.key]),c=n(s[l.key]);c&&c!==o&&a.push({field:l.key,label:l.label,before:o,after:c})}return a}function Ml(t){var s;return{title:t.title||"",summary:t.summary||"",code:t.code||"",tags:t.tags||[],confidence:((s=t.reasoning)==null?void 0:s.confidence)??.6,relations:t.relations||[],insight:null,agentNotes:null}}const Gl=({diff:t})=>t.length===0?e.jsx("p",{className:"text-xs text-slate-400 italic py-2",children:"未检测到变更"}):e.jsx("div",{className:"space-y-2 mt-2",children:t.map(s=>e.jsxs("div",{className:"border border-slate-200 rounded-lg overflow-hidden",children:[e.jsxs("div",{className:"px-2.5 py-1 bg-slate-50 border-b border-slate-200 flex items-center gap-1.5",children:[e.jsx(Ws,{size:10,className:"text-emerald-500"}),e.jsx("span",{className:"text-[10px] font-bold text-slate-600",children:s.label})]}),e.jsxs("div",{className:"p-2 bg-red-50/30 border-b border-slate-200",children:[e.jsx("div",{className:"text-[9px] font-bold text-red-400 mb-0.5 uppercase",children:"Before"}),e.jsx("pre",{className:"text-[11px] text-slate-600 whitespace-pre-wrap break-words max-h-40 overflow-auto font-mono leading-relaxed scrollbar-light",children:s.before||e.jsx("span",{className:"italic text-slate-300",children:"(空)"})})]}),e.jsxs("div",{className:"p-2 bg-emerald-50/30",children:[e.jsx("div",{className:"text-[9px] font-bold text-emerald-500 mb-0.5 uppercase",children:"After"}),e.jsx("pre",{className:"text-[11px] text-slate-700 whitespace-pre-wrap break-words max-h-40 overflow-auto font-mono leading-relaxed scrollbar-light",children:s.after})]})]},s.field))}),vs=r.createContext(null),Dl=()=>r.useContext(vs),Pl=({children:t})=>{const[s,a]=r.useState(!1),[l,n]=r.useState([]),[o,c]=r.useState(!1),[i,x]=r.useState(!1),[$,d]=r.useState(null),[y,m]=r.useState(new Set),[S,v]=r.useState(""),A=r.useRef([]),f=!!$,k=$?$.candidateIds[$.currentIdx]:null,T=$?$.candidates.find(_=>_.id===k):void 0,L=$?$.candidateIds.length>1:!1;r.useEffect(()=>{$&&T&&(n(_=>[..._,{id:xt(),role:"system",content:`🎯 润色模式 — **${T.title}**
|
|
83
83
|
|
|
84
84
|
当前摘要: ${T.summary||"(无)"}
|
|
85
85
|
|
|
86
|
-
**输入润色指令,AI 将根据你的指令定向修改候选内容**,下方有常用指令可直接点击使用。`,timestamp:Date.now()}]),v(""))},[$==null?void 0:$.currentIdx]);const U=r.useCallback(()=>{d(null),a(!0)},[]),B=r.useCallback(z=>{d({...z,currentIdx:0}),m(new Set),n([]),A.current=[],a(!0)},[]),K=r.useCallback(()=>a(!1),[]),b=r.useCallback(()=>a(z=>!z),[]),R=r.useCallback(()=>{n([]),A.current=[],v(""),d(null),m(new Set)},[]),M={openChat:U,openRefine:B,close:K,toggle:b,newTopic:R,isOpen:s},H={messages:l,setMessages:n,loading:o,setLoading:c,applying:i,setApplying:x,refineCtx:$,setRefineCtx:d,applied:y,setApplied:m,lastPrompt:S,setLastPrompt:v,chatHistoryRef:A,isRefineMode:f,currentRefineId:k,currentRefineCandidate:T,isBatchRefine:L,close:K};return e.jsx(oa.Provider,{value:M,children:e.jsx(vs.Provider,{value:H,children:t})})},Ll=()=>{const t=r.useContext(vs),{messages:s,setMessages:a,loading:l,setLoading:n,applying:o,setApplying:c,refineCtx:i,setRefineCtx:x,applied:$,setApplied:d,lastPrompt:y,setLastPrompt:m,chatHistoryRef:S,isRefineMode:v,currentRefineId:A,currentRefineCandidate:f,isBatchRefine:k,close:T}=t,L=r.useRef(null),U=r.useRef(null),[B,K]=r.useState(""),b=ia(),R=r.useRef(null),M=r.useRef(!1);r.useEffect(()=>{if(v&&f){M.current=!0;const h=b.createTopic(`润色: ${f.title||"未命名"}`);R.current=h,setTimeout(()=>{M.current=!1},50)}},[i]),r.useEffect(()=>{M.current||R.current&&s.length>0&&b.saveTopic(R.current,s)},[s]);const H=r.useCallback(()=>{if(!R.current){M.current=!0;const h=b.createTopic();R.current=h,setTimeout(()=>{M.current=!1},50)}},[b]);r.useEffect(()=>{var h;(h=L.current)==null||h.scrollIntoView({behavior:"smooth"})},[s,l]),r.useEffect(()=>{setTimeout(()=>{var h;return(h=U.current)==null?void 0:h.focus()},200)},[]);const z=v&&A&&s.some(h=>h.role==="assistant"&&h.diff&&h.diff.length>0)&&!$.has(A),P=r.useCallback(async()=>{const h=B.trim();if(!(!h||l)){if(v||H(),K(""),a(V=>[...V,{id:xt(),role:"user",content:h,timestamp:Date.now()}]),n(!0),v&&A){m(h);try{const V=await te.refinePreview(A,h),me=V.before||(f?Ml(f):{}),F=Tl(me,V.after||{});a(X=>[...X,{id:xt(),role:"assistant",content:F.length>0?`已生成润色预览,共 ${F.length} 个字段变更:`:"未检测到变更,请尝试更具体的指令。",diff:F.length>0?F:void 0,preview:F.length>0?V.preview:void 0,timestamp:Date.now()}])}catch(V){a(me=>{var F,X;return[...me,{id:xt(),role:"assistant",content:`润色预览失败: ${((X=(F=V.response)==null?void 0:F.data)==null?void 0:X.error)||V.message}`,timestamp:Date.now()}]})}}else{S.current.push({role:"user",content:h});try{const V=await te.chat(h,S.current);S.current.push({role:"model",content:V.text}),a(me=>[...me,{id:xt(),role:"assistant",content:V.text,timestamp:Date.now()}])}catch(V){a(me=>[...me,{id:xt(),role:"assistant",content:`请求失败: ${V.message}`,timestamp:Date.now()}])}}n(!1)}},[B,l,v,A,f,H]),p=r.useCallback(async()=>{var h,V,me;if(!(o||!A||!i)){c(!0);try{await te.refineApply(A,y),d(F=>new Set(F).add(A)),(h=i.onCandidateUpdated)==null||h.call(i,A),a(F=>[...F,{id:xt(),role:"system",content:"✅ 变更已应用到候选!",timestamp:Date.now()}]),ee("候选内容已更新为润色后版本",{title:"润色已应用"})}catch(F){ee(((me=(V=F.response)==null?void 0:V.data)==null?void 0:me.error)||F.message,{title:"应用失败",type:"error"})}finally{c(!1)}}},[o,A,y,i]),w=r.useCallback(()=>{!i||i.currentIdx>=i.candidateIds.length-1||x(h=>h?{...h,currentIdx:h.currentIdx+1}:null)},[i]),E=r.useCallback(()=>{R.current=null,x(null),a(h=>[...h,{id:xt(),role:"system",content:"已退出润色模式,回到通用对话。",timestamp:Date.now()}])},[]),se=r.useCallback(h=>{h.key==="Enter"&&!h.shiftKey&&(h.preventDefault(),P())},[P]);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:v?e.jsx(Ye,{className:"text-emerald-500",size:16}):e.jsx(vt,{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:[v?"AI 润色":"AI Chat",v&&k&&e.jsxs("span",{className:"text-[10px] px-1.5 py-0.5 rounded-full bg-emerald-50 text-emerald-600 font-medium",children:[((i==null?void 0:i.currentIdx)??0)+1,"/",i==null?void 0:i.candidateIds.length]})]}),e.jsx("p",{className:"text-[10px] text-slate-400 truncate max-w-[250px]",children:v?(f==null?void 0:f.title)||"润色中...":"询问任何关于项目的问题"})]})]}),e.jsxs("div",{className:"flex items-center gap-1",children:[v&&e.jsx("button",{onClick:E,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:"退出润色"}),!v&&s.length>0&&e.jsx("button",{onClick:()=>{R.current=null,a([]),S.current=[],m("")},className:"p-1.5 hover:bg-slate-100 rounded-lg transition-colors",title:"开启新话题",children:e.jsx(ut,{size:16,className:"text-slate-400"})}),e.jsx("button",{onClick:T,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"})})]})]}),v&&f&&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:f.title}),f.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:f.language})]})}),e.jsxs("div",{className:"flex-1 overflow-y-auto p-4 space-y-3 min-h-0 scrollbar-light",children:[s.length===0&&!v&&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(vt,{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(h=>e.jsx("button",{onClick:()=>{var V;K(h),(V=U.current)==null||V.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:h},h))})]}),v&&s.length<=1&&e.jsx("div",{className:"flex flex-wrap gap-1.5 mt-2",children:["增加具体使用案例,不要修改其他内容","优化代码注释和说明","补充常见错误用法和注意事项","提升摘要质量,更简洁专业","补充性能注意事项"].map(h=>e.jsx("button",{onClick:()=>{var V;K(h),(V=U.current)==null||V.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:h},h))}),s.map(h=>e.jsx("div",{className:`flex ${h.role==="user"?"justify-end":"justify-start"}`,children:e.jsxs("div",{className:`max-w-[95%] ${h.role==="user"?"bg-blue-600 text-white rounded-2xl rounded-tr-md px-3.5 py-2":h.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:[h.role==="assistant"&&e.jsxs("div",{className:"flex items-center gap-1.5 mb-1.5",children:[e.jsx(It,{size:12,className:v?"text-emerald-500":"text-blue-500"}),e.jsx("span",{className:`text-[10px] font-bold ${v?"text-emerald-600":"text-blue-600"}`,children:v?"AI 润色助手":"AI 助手"})]}),h.role==="assistant"&&!h.diff?e.jsx(lt,{content:h.content,className:"text-xs text-slate-700"}):e.jsx("p",{className:`text-xs leading-relaxed whitespace-pre-wrap ${h.role==="user"?"":h.role==="system"?"text-slate-500":"text-slate-700"}`,children:h.content}),h.diff&&h.diff.length>0&&e.jsx(Gl,{diff:h.diff})]})},h.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(_e,{size:12,className:`animate-spin ${v?"text-emerald-500":"text-blue-500"}`}),e.jsx("span",{className:"text-xs text-slate-500",children:v?"AI 正在分析...":"AI 思考中..."})]})})}),e.jsx("div",{ref:L})]}),v&&z&&!l&&e.jsxs("div",{className:"px-4 py-2 border-t border-slate-100 bg-emerald-50/50 flex items-center gap-2 shrink-0",children:[e.jsxs("button",{onClick:p,disabled:o,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:[o?e.jsx(_e,{size:11,className:"animate-spin"}):e.jsx(zt,{size:11}),o?"应用中...":"确认应用"]}),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(Ea,{size:11})," 继续调整"]}),k&&$.has(A)&&i.currentIdx<i.candidateIds.length-1&&e.jsxs("button",{onClick:w,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(it,{size:11})]})]}),v&&!z&&!l&&k&&$.has(A)&&i.currentIdx<i.candidateIds.length-1&&e.jsx("div",{className:"px-4 py-2 border-t border-slate-100 flex items-center justify-center shrink-0",children:e.jsxs("button",{onClick:w,className:"flex items-center gap-1 px-3 py-1.5 text-[11px] font-bold text-blue-600 hover:text-blue-700 rounded-lg bg-blue-50 hover:bg-blue-100 transition-colors",children:["下一条 (",((i==null?void 0:i.currentIdx)??0)+2,"/",i==null?void 0:i.candidateIds.length,") ",e.jsx(it,{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:U,value:B,onChange:h=>K(h.target.value),onKeyDown:se,placeholder:v?'输入定向润色指令,如"增加使用案例"、"优化摘要"...':"输入你的问题...",rows:2,className:`flex-1 px-3 py-2 text-sm border border-slate-200 rounded-xl focus:outline-none focus:ring-2 ${v?"focus:ring-emerald-200 focus:border-emerald-400":"focus:ring-blue-200 focus:border-blue-400"} resize-none placeholder:text-slate-300`,disabled:l||o}),e.jsx("button",{onClick:P,disabled:!B.trim()||l||o,className:`self-stretch w-9 flex items-center justify-center rounded-xl bg-gradient-to-r ${v?"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(gs,{size:14})})]}),e.jsx("p",{className:"text-[9px] text-slate-400 mt-1",children:v?"Enter 发送 · Shift+Enter 换行 · 先预览再应用":"Enter 发送 · Shift+Enter 换行"})]})]})},Fl=({searchQuery:t,setSearchQuery:s,setShowCreateModal:a,handleSyncToXcode:l,aiConfig:n,llmReady:o=!0,onOpenLlmConfig:c,onSemanticSearchResults:i,onBeforeAiSwitch:x,onAiConfigChange:$,isDarkMode:d=!1})=>{const{toggle:y,isOpen:m}=Ht(),[S,v]=r.useState(!1),[A,f]=r.useState(!1),[k,T]=r.useState([]),[L,U]=r.useState(!1),B=r.useRef(null);r.useEffect(()=>{A&&k.length===0&&te.getAiProviders().then(R=>T(R)).catch(()=>{})},[A,k.length]),r.useEffect(()=>{const R=M=>{B.current&&!B.current.contains(M.target)&&f(!1)};return document.addEventListener("click",R),()=>document.removeEventListener("click",R)},[]);const K=async()=>{if(t){v(!0);try{const R=await te.semanticSearch(t);i&&i(R)}catch(R){console.error("Semantic search failed",R),alert("语义搜索失败。请确保已运行 asd embed 构建索引。")}finally{v(!1)}}},b=async R=>{U(!0);try{x==null||x(),await te.setAiConfig(R.id,R.defaultModel),f(!1),$&&$()}catch(M){console.error("AI config update failed",M),alert("切换 AI 失败,请检查项目根目录是否可写。")}finally{U(!1)}};return e.jsxs("header",{className:`h-16 ${d?"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(pt,{className:`absolute left-3 top-1/2 -translate-y-1/2 ${d?"text-slate-500":"text-slate-400"}`,size:_.md}),e.jsx("input",{type:"text",placeholder:"Search knowledge...",className:`w-full pl-10 pr-4 py-2 ${d?"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:R=>s(R.target.value),onKeyDown:R=>R.key==="Enter"&&K()})]}),e.jsxs("button",{onClick:K,disabled:!t||S,className:`flex items-center gap-2 px-3 py-2 rounded-lg text-xs font-bold transition-all ${S?"bg-blue-50 text-blue-400":"bg-blue-50 text-blue-600 hover:bg-blue-100"}`,title:"Semantic Search (Brain AI)",children:[S?e.jsx(_e,{size:_.sm,className:"animate-spin"}):e.jsx(Ta,{size:_.sm}),"Semantic"]})]}),e.jsxs("div",{className:"flex items-center gap-4",children:[o?n?e.jsxs("div",{className:"relative",ref:B,children:[e.jsxs("button",{type:"button",onClick:R=>{R.stopPropagation(),f(M=>!M)},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(Ut,{size:_.sm}),n.provider," / ",n.model,e.jsx(kt,{size:_.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:()=>{f(!1),c==null||c()},className:"text-blue-500 hover:underline",children:"修改 .env 配置"})}),k.length===0?e.jsx("div",{className:"px-3 py-2 text-xs text-slate-400",children:"加载中..."}):k.map(R=>e.jsxs("button",{type:"button",disabled:L,onClick:()=>b(R),className:`w-full text-left px-3 py-2 text-sm hover:bg-slate-50 flex items-center justify-between ${n.provider===R.id?"bg-blue-50 text-blue-700 font-medium":"text-slate-700"}`,children:[e.jsx("span",{children:R.label}),n.provider===R.id&&e.jsx("span",{className:"text-xs",children:"✓"})]},R.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(Ks,{size:_.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 ${m?"bg-blue-100 text-blue-700 ring-1 ring-blue-200":d?"bg-slate-700 text-slate-300 hover:bg-slate-600":"bg-slate-100 text-slate-600 hover:bg-slate-200"}`,title:m?"关闭 AI Chat":"打开 AI Chat",children:[e.jsx(vt,{size:_.sm}),!m&&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(ut,{size:_.md})," New Recipe"]}),e.jsxs("button",{onClick:l,className:"flex items-center gap-2 px-4 py-2 bg-blue-600 text-white rounded-lg text-sm font-medium hover:bg-blue-700 transition-colors shadow-sm",children:[e.jsx(wt,{size:_.md})," Sync to Xcode"]})]})]})},Ol=({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(Xe).map(([a,l])=>{const n=l.icon,o=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
|
|
87
|
-
${o?`${l.bg} ${l.color} ${l.border} shadow-sm scale-105`:"bg-white text-slate-400 border-slate-100 hover:border-slate-200 hover:text-slate-600"}`,children:[e.jsx(n,{size:
|
|
86
|
+
**输入润色指令,AI 将根据你的指令定向修改候选内容**,下方有常用指令可直接点击使用。`,timestamp:Date.now()}]),v(""))},[$==null?void 0:$.currentIdx]);const U=r.useCallback(()=>{d(null),a(!0)},[]),B=r.useCallback(_=>{d({..._,currentIdx:0}),m(new Set),n([]),A.current=[],a(!0)},[]),K=r.useCallback(()=>a(!1),[]),b=r.useCallback(()=>a(_=>!_),[]),R=r.useCallback(()=>{n([]),A.current=[],v(""),d(null),m(new Set)},[]),M={openChat:U,openRefine:B,close:K,toggle:b,newTopic:R,isOpen:s},H={messages:l,setMessages:n,loading:o,setLoading:c,applying:i,setApplying:x,refineCtx:$,setRefineCtx:d,applied:y,setApplied:m,lastPrompt:S,setLastPrompt:v,chatHistoryRef:A,isRefineMode:f,currentRefineId:k,currentRefineCandidate:T,isBatchRefine:L,close:K};return e.jsx(oa.Provider,{value:M,children:e.jsx(vs.Provider,{value:H,children:t})})},Ll=()=>{const t=r.useContext(vs),{messages:s,setMessages:a,loading:l,setLoading:n,applying:o,setApplying:c,refineCtx:i,setRefineCtx:x,applied:$,setApplied:d,lastPrompt:y,setLastPrompt:m,chatHistoryRef:S,isRefineMode:v,currentRefineId:A,currentRefineCandidate:f,isBatchRefine:k,close:T}=t,L=r.useRef(null),U=r.useRef(null),[B,K]=r.useState(""),b=ia(),R=r.useRef(null),M=r.useRef(!1);r.useEffect(()=>{if(v&&f){M.current=!0;const h=b.createTopic(`润色: ${f.title||"未命名"}`);R.current=h,setTimeout(()=>{M.current=!1},50)}},[i]),r.useEffect(()=>{M.current||R.current&&s.length>0&&b.saveTopic(R.current,s)},[s]);const H=r.useCallback(()=>{if(!R.current){M.current=!0;const h=b.createTopic();R.current=h,setTimeout(()=>{M.current=!1},50)}},[b]);r.useEffect(()=>{var h;(h=L.current)==null||h.scrollIntoView({behavior:"smooth"})},[s,l]),r.useEffect(()=>{setTimeout(()=>{var h;return(h=U.current)==null?void 0:h.focus()},200)},[]);const _=v&&A&&s.some(h=>h.role==="assistant"&&h.diff&&h.diff.length>0)&&!$.has(A),P=r.useCallback(async()=>{const h=B.trim();if(!(!h||l)){if(v||H(),K(""),a(V=>[...V,{id:xt(),role:"user",content:h,timestamp:Date.now()}]),n(!0),v&&A){m(h);try{const V=await te.refinePreview(A,h),me=V.before||(f?Ml(f):{}),F=Tl(me,V.after||{});a(X=>[...X,{id:xt(),role:"assistant",content:F.length>0?`已生成润色预览,共 ${F.length} 个字段变更:`:"未检测到变更,请尝试更具体的指令。",diff:F.length>0?F:void 0,preview:F.length>0?V.preview:void 0,timestamp:Date.now()}])}catch(V){a(me=>{var F,X;return[...me,{id:xt(),role:"assistant",content:`润色预览失败: ${((X=(F=V.response)==null?void 0:F.data)==null?void 0:X.error)||V.message}`,timestamp:Date.now()}]})}}else{S.current.push({role:"user",content:h});try{const V=await te.chat(h,S.current);S.current.push({role:"model",content:V.text}),a(me=>[...me,{id:xt(),role:"assistant",content:V.text,timestamp:Date.now()}])}catch(V){a(me=>[...me,{id:xt(),role:"assistant",content:`请求失败: ${V.message}`,timestamp:Date.now()}])}}n(!1)}},[B,l,v,A,f,H]),p=r.useCallback(async()=>{var h,V,me;if(!(o||!A||!i)){c(!0);try{await te.refineApply(A,y),d(F=>new Set(F).add(A)),(h=i.onCandidateUpdated)==null||h.call(i,A),a(F=>[...F,{id:xt(),role:"system",content:"✅ 变更已应用到候选!",timestamp:Date.now()}]),ee("候选内容已更新为润色后版本",{title:"润色已应用"})}catch(F){ee(((me=(V=F.response)==null?void 0:V.data)==null?void 0:me.error)||F.message,{title:"应用失败",type:"error"})}finally{c(!1)}}},[o,A,y,i]),w=r.useCallback(()=>{!i||i.currentIdx>=i.candidateIds.length-1||x(h=>h?{...h,currentIdx:h.currentIdx+1}:null)},[i]),E=r.useCallback(()=>{R.current=null,x(null),a(h=>[...h,{id:xt(),role:"system",content:"已退出润色模式,回到通用对话。",timestamp:Date.now()}])},[]),se=r.useCallback(h=>{h.key==="Enter"&&!h.shiftKey&&(h.preventDefault(),P())},[P]);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:v?e.jsx(Ye,{className:"text-emerald-500",size:16}):e.jsx(vt,{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:[v?"AI 润色":"AI Chat",v&&k&&e.jsxs("span",{className:"text-[10px] px-1.5 py-0.5 rounded-full bg-emerald-50 text-emerald-600 font-medium",children:[((i==null?void 0:i.currentIdx)??0)+1,"/",i==null?void 0:i.candidateIds.length]})]}),e.jsx("p",{className:"text-[10px] text-slate-400 truncate max-w-[250px]",children:v?(f==null?void 0:f.title)||"润色中...":"询问任何关于项目的问题"})]})]}),e.jsxs("div",{className:"flex items-center gap-1",children:[v&&e.jsx("button",{onClick:E,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:"退出润色"}),!v&&s.length>0&&e.jsx("button",{onClick:()=>{R.current=null,a([]),S.current=[],m("")},className:"p-1.5 hover:bg-slate-100 rounded-lg transition-colors",title:"开启新话题",children:e.jsx(ut,{size:16,className:"text-slate-400"})}),e.jsx("button",{onClick:T,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"})})]})]}),v&&f&&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:f.title}),f.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:f.language})]})}),e.jsxs("div",{className:"flex-1 overflow-y-auto p-4 space-y-3 min-h-0 scrollbar-light",children:[s.length===0&&!v&&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(vt,{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(h=>e.jsx("button",{onClick:()=>{var V;K(h),(V=U.current)==null||V.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:h},h))})]}),v&&s.length<=1&&e.jsx("div",{className:"flex flex-wrap gap-1.5 mt-2",children:["增加具体使用案例,不要修改其他内容","优化代码注释和说明","补充常见错误用法和注意事项","提升摘要质量,更简洁专业","补充性能注意事项"].map(h=>e.jsx("button",{onClick:()=>{var V;K(h),(V=U.current)==null||V.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:h},h))}),s.map(h=>e.jsx("div",{className:`flex ${h.role==="user"?"justify-end":"justify-start"}`,children:e.jsxs("div",{className:`max-w-[95%] ${h.role==="user"?"bg-blue-600 text-white rounded-2xl rounded-tr-md px-3.5 py-2":h.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:[h.role==="assistant"&&e.jsxs("div",{className:"flex items-center gap-1.5 mb-1.5",children:[e.jsx(It,{size:12,className:v?"text-emerald-500":"text-blue-500"}),e.jsx("span",{className:`text-[10px] font-bold ${v?"text-emerald-600":"text-blue-600"}`,children:v?"AI 润色助手":"AI 助手"})]}),h.role==="assistant"&&!h.diff?e.jsx(lt,{content:h.content,className:"text-xs text-slate-700"}):e.jsx("p",{className:`text-xs leading-relaxed whitespace-pre-wrap ${h.role==="user"?"":h.role==="system"?"text-slate-500":"text-slate-700"}`,children:h.content}),h.diff&&h.diff.length>0&&e.jsx(Gl,{diff:h.diff})]})},h.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(ze,{size:12,className:`animate-spin ${v?"text-emerald-500":"text-blue-500"}`}),e.jsx("span",{className:"text-xs text-slate-500",children:v?"AI 正在分析...":"AI 思考中..."})]})})}),e.jsx("div",{ref:L})]}),v&&_&&!l&&e.jsxs("div",{className:"px-4 py-2 border-t border-slate-100 bg-emerald-50/50 flex items-center gap-2 shrink-0",children:[e.jsxs("button",{onClick:p,disabled:o,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:[o?e.jsx(ze,{size:11,className:"animate-spin"}):e.jsx(_t,{size:11}),o?"应用中...":"确认应用"]}),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(Ea,{size:11})," 继续调整"]}),k&&$.has(A)&&i.currentIdx<i.candidateIds.length-1&&e.jsxs("button",{onClick:w,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(it,{size:11})]})]}),v&&!_&&!l&&k&&$.has(A)&&i.currentIdx<i.candidateIds.length-1&&e.jsx("div",{className:"px-4 py-2 border-t border-slate-100 flex items-center justify-center shrink-0",children:e.jsxs("button",{onClick:w,className:"flex items-center gap-1 px-3 py-1.5 text-[11px] font-bold text-blue-600 hover:text-blue-700 rounded-lg bg-blue-50 hover:bg-blue-100 transition-colors",children:["下一条 (",((i==null?void 0:i.currentIdx)??0)+2,"/",i==null?void 0:i.candidateIds.length,") ",e.jsx(it,{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:U,value:B,onChange:h=>K(h.target.value),onKeyDown:se,placeholder:v?'输入定向润色指令,如"增加使用案例"、"优化摘要"...':"输入你的问题...",rows:2,className:`flex-1 px-3 py-2 text-sm border border-slate-200 rounded-xl focus:outline-none focus:ring-2 ${v?"focus:ring-emerald-200 focus:border-emerald-400":"focus:ring-blue-200 focus:border-blue-400"} resize-none placeholder:text-slate-300`,disabled:l||o}),e.jsx("button",{onClick:P,disabled:!B.trim()||l||o,className:`self-stretch w-9 flex items-center justify-center rounded-xl bg-gradient-to-r ${v?"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(gs,{size:14})})]}),e.jsx("p",{className:"text-[9px] text-slate-400 mt-1",children:v?"Enter 发送 · Shift+Enter 换行 · 先预览再应用":"Enter 发送 · Shift+Enter 换行"})]})]})},Fl=({searchQuery:t,setSearchQuery:s,setShowCreateModal:a,handleSyncToXcode:l,aiConfig:n,llmReady:o=!0,onOpenLlmConfig:c,onSemanticSearchResults:i,onBeforeAiSwitch:x,onAiConfigChange:$,isDarkMode:d=!1})=>{const{toggle:y,isOpen:m}=Ht(),[S,v]=r.useState(!1),[A,f]=r.useState(!1),[k,T]=r.useState([]),[L,U]=r.useState(!1),B=r.useRef(null);r.useEffect(()=>{A&&k.length===0&&te.getAiProviders().then(R=>T(R)).catch(()=>{})},[A,k.length]),r.useEffect(()=>{const R=M=>{B.current&&!B.current.contains(M.target)&&f(!1)};return document.addEventListener("click",R),()=>document.removeEventListener("click",R)},[]);const K=async()=>{if(t){v(!0);try{const R=await te.semanticSearch(t);i&&i(R)}catch(R){console.error("Semantic search failed",R),alert("语义搜索失败。请确保已运行 asd embed 构建索引。")}finally{v(!1)}}},b=async R=>{U(!0);try{x==null||x(),await te.setAiConfig(R.id,R.defaultModel),f(!1),$&&$()}catch(M){console.error("AI config update failed",M),alert("切换 AI 失败,请检查项目根目录是否可写。")}finally{U(!1)}};return e.jsxs("header",{className:`h-16 ${d?"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(pt,{className:`absolute left-3 top-1/2 -translate-y-1/2 ${d?"text-slate-500":"text-slate-400"}`,size:z.md}),e.jsx("input",{type:"text",placeholder:"Search knowledge...",className:`w-full pl-10 pr-4 py-2 ${d?"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:R=>s(R.target.value),onKeyDown:R=>R.key==="Enter"&&K()})]}),e.jsxs("button",{onClick:K,disabled:!t||S,className:`flex items-center gap-2 px-3 py-2 rounded-lg text-xs font-bold transition-all ${S?"bg-blue-50 text-blue-400":"bg-blue-50 text-blue-600 hover:bg-blue-100"}`,title:"Semantic Search (Brain AI)",children:[S?e.jsx(ze,{size:z.sm,className:"animate-spin"}):e.jsx(Ta,{size:z.sm}),"Semantic"]})]}),e.jsxs("div",{className:"flex items-center gap-4",children:[o?n?e.jsxs("div",{className:"relative",ref:B,children:[e.jsxs("button",{type:"button",onClick:R=>{R.stopPropagation(),f(M=>!M)},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(Ut,{size:z.sm}),n.provider," / ",n.model,e.jsx(kt,{size:z.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:()=>{f(!1),c==null||c()},className:"text-blue-500 hover:underline",children:"修改 .env 配置"})}),k.length===0?e.jsx("div",{className:"px-3 py-2 text-xs text-slate-400",children:"加载中..."}):k.map(R=>e.jsxs("button",{type:"button",disabled:L,onClick:()=>b(R),className:`w-full text-left px-3 py-2 text-sm hover:bg-slate-50 flex items-center justify-between ${n.provider===R.id?"bg-blue-50 text-blue-700 font-medium":"text-slate-700"}`,children:[e.jsx("span",{children:R.label}),n.provider===R.id&&e.jsx("span",{className:"text-xs",children:"✓"})]},R.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(Ks,{size:z.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 ${m?"bg-blue-100 text-blue-700 ring-1 ring-blue-200":d?"bg-slate-700 text-slate-300 hover:bg-slate-600":"bg-slate-100 text-slate-600 hover:bg-slate-200"}`,title:m?"关闭 AI Chat":"打开 AI Chat",children:[e.jsx(vt,{size:z.sm}),!m&&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(ut,{size:z.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(wt,{size:z.md})," Sync to Xcode"]})]})]})},Ol=({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(Xe).map(([a,l])=>{const n=l.icon,o=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
|
|
87
|
+
${o?`${l.bg} ${l.color} ${l.border} shadow-sm scale-105`:"bg-white text-slate-400 border-slate-100 hover:border-slate-200 hover:text-slate-600"}`,children:[e.jsx(n,{size:z.xs}),a]},a)})})}),ca="asd-drawer-wide";function Bl(){try{return localStorage.getItem(ca)==="1"}catch{return!1}}function da(){const[t,s]=r.useState(Bl),a=r.useCallback(()=>{s(l=>{const n=!l;try{localStorage.setItem(ca,n?"1":"0")}catch{}return n})},[]);return{isWide:t,toggle:a}}const xa=({currentPage:t,totalPages:s,totalItems:a,pageSize:l,onPageChange:n,onPageSizeChange:o,pageSizeOptions:c=[12,24,48,96]})=>{if(s<=1&&a<=c[0])return null;const i=(t-1)*l+1,x=Math.min(t*l,a),$=()=>{const d=[];if(s<=7)for(let m=1;m<=s;m++)d.push(m);else if(t<=3){for(let m=1;m<=5;m++)d.push(m);d.push("..."),d.push(s)}else if(t>=s-2){d.push(1),d.push("...");for(let m=s-5+1;m<=s;m++)d.push(m)}else{d.push(1),d.push("...");for(let m=t-1;m<=t+1;m++)d.push(m);d.push("..."),d.push(s)}return d};return e.jsxs("div",{className:"flex items-center justify-between mt-6 px-2",children:[e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsxs("span",{className:"text-sm text-slate-500",children:["显示 ",i,"-",x,",共 ",a," 条"]}),o&&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:d=>o(Number(d.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(d=>e.jsx("option",{value:d,children:d},d))}),e.jsx("span",{className:"text-sm text-slate-500",children:"条"})]})]}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("button",{onClick:()=>n(1),disabled:t===1,className:"p-1.5 rounded-md hover:bg-slate-100 disabled:opacity-30 disabled:cursor-not-allowed transition-colors",title:"第一页",children:e.jsx(Ma,{size:z.md,className:"text-slate-600"})}),e.jsx("button",{onClick:()=>n(t-1),disabled:t===1,className:"p-1.5 rounded-md hover:bg-slate-100 disabled:opacity-30 disabled:cursor-not-allowed transition-colors",title:"上一页",children:e.jsx(fs,{size:z.md,className:"text-slate-600"})}),e.jsx("div",{className:"flex items-center gap-1 mx-2",children:$().map((d,y)=>typeof d=="number"?e.jsx("button",{onClick:()=>n(d),className:`min-w-[32px] h-8 px-2 rounded-md text-sm font-medium transition-colors ${t===d?"bg-blue-600 text-white":"hover:bg-slate-100 text-slate-600"}`,children:d},y):e.jsx("span",{className:"px-1 text-slate-400",children:d},y))}),e.jsx("button",{onClick:()=>n(t+1),disabled:t===s,className:"p-1.5 rounded-md hover:bg-slate-100 disabled:opacity-30 disabled:cursor-not-allowed transition-colors",title:"下一页",children:e.jsx(it,{size:z.md,className:"text-slate-600"})}),e.jsx("button",{onClick:()=>n(s),disabled:t===s,className:"p-1.5 rounded-md hover:bg-slate-100 disabled:opacity-30 disabled:cursor-not-allowed transition-colors",title:"最后一页",children:e.jsx(Ga,{size:z.md,className:"text-slate-600"})})]})]})},Ul=Bt.memo(({code:t,lang:s,editorStyles:a})=>e.jsx(sa,{language:s,style:aa,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]===`
|
|
88
88
|
`?l+" ":l})()})),Kt=19.5,Hl=Bt.memo(({totalLines:t,scrollTop:s,viewportHeight:a,fontSize:l,lineHeight:n,fontFamily:o})=>{const i=Math.max(0,Math.floor(s/Kt)-10),x=Math.ceil(a/Kt)+20,$=Math.min(t,i+x),d=i*Kt,y=Math.max(0,(t-$)*Kt),m=[];for(let S=i;S<$;S++)m.push(e.jsx("div",{children:S+1},S));return e.jsx("div",{style:{paddingTop:d,paddingBottom:y,fontSize:l,lineHeight:n,fontFamily:o},children:m})}),ls=({value:t,onChange:s,onCursorChange:a,language:l="javascript",height:n="400px",className:o="",placeholder:c="",rows:i,showLineNumbers:x=!0})=>{const $=r.useRef(null),d=r.useRef(null),y=r.useRef(null),m=r.useRef(null),[S,v]=r.useState(t),A=r.useRef(void 0);r.useEffect(()=>{const M=t.length>5e3?200:t.length>1e3?80:0;if(M===0){v(t);return}return A.current=setTimeout(()=>v(t),M),()=>clearTimeout(A.current)},[t]);const[f,k]=r.useState({top:0,height:400}),L={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",U=r.useMemo(()=>({padding:"1rem 1.25rem",fontSize:"0.8125rem",lineHeight:1.5,fontFamily:"ui-monospace, monospace",minHeight:"200px"}),[]),B=r.useCallback(M=>{const H=M.currentTarget;y.current&&(y.current.scrollTop=H.scrollTop,y.current.scrollLeft=H.scrollLeft),m.current&&(m.current.scrollTop=H.scrollTop),k({top:H.scrollTop,height:H.clientHeight})},[]),K=r.useCallback(M=>{s(M.target.value),a&&a(M.target.selectionStart||0)},[s,a]),b=r.useCallback(M=>{a&&a(M.currentTarget.selectionStart||0)},[a]),R=r.useMemo(()=>(t||"").split(`
|
|
89
89
|
`).length,[t]);return r.useEffect(()=>{d.current&&k(M=>({...M,height:d.current.clientHeight}))},[]),e.jsxs("div",{ref:$,className:`relative overflow-hidden ${o}`,style:{height:i?"auto":n,minHeight:U.minHeight,display:"flex",borderRadius:"0",backgroundColor:"#282c34"},children:[x&&e.jsx("div",{ref:m,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(Hl,{totalLines:R,scrollTop:f.top,viewportHeight:f.height,fontSize:U.fontSize,lineHeight:U.lineHeight,fontFamily:U.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(Ul,{code:S||c,lang:L,editorStyles:U})}),e.jsx("textarea",{ref:d,value:t,onChange:K,onSelect:b,onKeyUp:b,onClick:b,onScroll:B,rows:i,placeholder:c,className:"absolute inset-0 w-full h-full resize-none outline-none",style:{padding:U.padding,lineHeight:U.lineHeight,fontSize:U.fontSize,fontFamily:U.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"}})]})]})},Wl=420,Kl=({className:t="bg-black/20 backdrop-blur-[1px]"})=>e.jsx("div",{className:`absolute inset-0 ${t}`}),We=({children:t,onClick:s,className:a="",style:l})=>{const{isOpen:n}=Ht();return e.jsx("div",{className:`fixed inset-0 overflow-hidden ${a}`,style:{right:n?Wl:0,...l},onClick:s,children:t})};We.Backdrop=Kl;const ds={rule:{label:"Rule",color:"text-red-700",bg:"bg-red-50",border:"border-red-200",icon:bt},pattern:{label:"Pattern",color:"text-violet-700",bg:"bg-violet-50",border:"border-violet-200",icon:Lt},fact:{label:"Fact",color:"text-cyan-700",bg:"bg-cyan-50",border:"border-cyan-200",icon:at}},Rs={active:{color:"text-green-700",bg:"bg-green-50",border:"border-green-200"},published:{color:"text-green-700",bg:"bg-green-50",border:"border-green-200"},draft:{color:"text-slate-500",bg:"bg-slate-50",border:"border-slate-200"},archived:{color:"text-orange-600",bg:"bg-orange-50",border:"border-orange-200"}};function et(t){return t.name||t.title||"Untitled"}function ft(t){if(typeof t.content=="string")return t.content;const s=t.content;return(s==null?void 0:s.pattern)||(s==null?void 0:s.markdown)||JSON.stringify(t.content,null,2)}function Vl(t){var a,l;const s=ft(t);return t.description||((a=t.v2Content)==null?void 0:a.rationale)||((l=t.v2Content)==null?void 0:l.pattern)||(typeof s=="string"?s:"")}function ql(t){if(t==null)return!1;const s=typeof t=="string"?new Date(t).getTime():t;return!isNaN(s)&&s>9466848e5}function xs(t){return ql(t)?(typeof t=="string"?new Date(t):new Date(t)).toLocaleDateString("zh-CN",{year:"numeric",month:"2-digit",day:"2-digit"}):"从未使用"}function Es(t){const s=t.split(`
|
|
90
90
|
`),a={};let l=0,n=!1;for(let c=0;c<s.length;c++){const i=s[c].trim();if(i==="---"){if(!n&&c===0){n=!0;continue}else if(n){n=!1,l=c+1;break}}const x=i.match(/^([a-zA-Z0-9_-]+):\s*(.*)/);if(x)a[x[1]]=x[2],n||(l=c+1);else if(!n&&i!==""){l=c;break}}const o=s.slice(l).join(`
|
|
91
|
-
`).trim();return{metadata:a,body:o}}const Jl=({recipes:t,handleDeleteRecipe:s,onRefresh:a,currentPage:l,onPageChange:n,pageSize:o,onPageSizeChange:c})=>{const[i,x]=r.useState("default"),[$,d]=r.useState("desc"),y=[{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,S]=r.useState(1),[v,A]=r.useState(12),f=l??m,k=o??v,T=n??S,L=c?u=>c(u):u=>{A(u),S(1)},{isWide:U,toggle:B}=da(),[K,b]=r.useState(null),[R,M]=r.useState("view"),[H,z]=r.useState(""),[P,p]=r.useState(!1),w=r.useRef(!0),[E,se]=r.useState(null),[h,V]=r.useState(!1),[me,F]=r.useState("related"),[X,Y]=r.useState("");r.useEffect(()=>()=>{w.current=!1},[]);const ie=u=>{b(u),M("view"),z(ft(u)),se(null),V(!1),Y("")},Ne=()=>{b(null),M("view"),se(null),V(!1),Y("")},Re=async()=>{if(!(!K||P)){p(!0);try{await te.saveRecipe(K.name,H),w.current&&(M("view"),a==null||a())}catch(u){alert((u==null?void 0:u.message)||"保存 Recipe 失败")}finally{w.current&&p(!1)}}},fe=async u=>{if(K)try{await te.setRecipeAuthority(K.name,u),a==null||a()}catch(I){ee((I==null?void 0:I.message)||"设置权威分失败",{title:"操作失败",type:"error"})}},Q=[{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:"⊃"}],ve=u=>{const I=u.replace(/\.md$/i,"").toLowerCase();return t.find(G=>et(G).replace(/\.md$/i,"").toLowerCase()===I)},Le=u=>{const I=ve(u);I&&se(I)},Ge=()=>se(null),we=async(u,I)=>{if(!K)return;const G={};if(K.relations)for(const[ae,ue]of Object.entries(K.relations))G[ae]=[...ue];const C=G[u]||[],q=I.replace(/\.md$/i,"");if(!C.some(ae=>(typeof ae=="string"?ae:ae.id||ae.title||"").replace(/\.md$/i,"").toLowerCase()===q.toLowerCase())){G[u]=[...C,q];try{await te.updateRecipeRelations(K.name,G),b({...K,relations:G}),V(!1),Y(""),a==null||a()}catch(ae){alert((ae==null?void 0:ae.message)||"添加关联失败")}}},Fe=async(u,I)=>{if(!K)return;const G={};if(K.relations)for(const[q,ae]of Object.entries(K.relations))G[q]=[...ae];const C=G[u]||[];G[u]=C.filter(q=>(typeof q=="string"?q:q.id||q.title||"").replace(/\.md$/i,"").toLowerCase()!==I.replace(/\.md$/i,"").toLowerCase()),G[u].length===0&&delete G[u];try{await te.updateRecipeRelations(K.name,G),b({...K,relations:G}),a==null||a()}catch(q){alert((q==null?void 0:q.message)||"移除关联失败")}};r.useEffect(()=>{K&&!t.find(u=>et(u)===et(K))&&Ne()},[t,K]),r.useEffect(()=>{l==null&&S(1)},[t.length,l]);const Ee=Bt.useMemo(()=>{if(i==="default")return t;const u=[...t],I=$==="asc"?1:-1;return u.sort((G,C)=>{var ue,oe,Ie,re,ye,Se,Be,Ae,He,Qe,de,j;let q=0,ae=0;switch(i){case"name":return q=et(G).toLowerCase(),ae=et(C).toLowerCase(),I*(q<ae?-1:q>ae?1:0);case"authorityScore":q=((ue=G.stats)==null?void 0:ue.authorityScore)??-1,ae=((oe=C.stats)==null?void 0:oe.authorityScore)??-1;break;case"authority":q=((Ie=G.stats)==null?void 0:Ie.authority)??-1,ae=((re=C.stats)==null?void 0:re.authority)??-1;break;case"totalUsage":q=(((ye=G.stats)==null?void 0:ye.guardUsageCount)??0)+(((Se=G.stats)==null?void 0:Se.humanUsageCount)??0)+(((Be=G.stats)==null?void 0:Be.aiUsageCount)??0),ae=(((Ae=C.stats)==null?void 0:Ae.guardUsageCount)??0)+(((He=C.stats)==null?void 0:He.humanUsageCount)??0)+(((Qe=C.stats)==null?void 0:Qe.aiUsageCount)??0);break;case"lastUsed":{const he=(de=G.stats)!=null&&de.lastUsedAt?new Date(G.stats.lastUsedAt).getTime():0,Ce=(j=C.stats)!=null&&j.lastUsedAt?new Date(C.stats.lastUsedAt).getTime():0;q=isNaN(he)?0:he,ae=isNaN(Ce)?0:Ce;break}case"category":return q=(G.category||"").toLowerCase(),ae=(C.category||"").toLowerCase(),I*(q<ae?-1:q>ae?1:0)}return I*(q-ae)}),u},[t,i,$]),ke=Math.ceil(Ee.length/k),De=(f-1)*k,Ze=Ee.slice(De,De+k),Ve=u=>{T(u),window.scrollTo({top:0,behavior:"smooth"})},g=K?Ee.findIndex(u=>et(u)===et(K)):-1,J=()=>{g>0&&b(Ee[g-1])},Z=()=>{g<Ee.length-1&&b(Ee[g+1])};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(Da,{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(Vs,{size:14,className:"text-slate-400 shrink-0"}),y.map(u=>{const I=i===u.key;return e.jsxs("button",{onClick:()=>{I?d(G=>G==="asc"?"desc":"asc"):(x(u.key),d(u.defaultDir)),T(1)},className:`px-2 py-1 rounded-md flex items-center gap-0.5 transition-colors ${I?"bg-blue-50 text-blue-700 font-medium border border-blue-200":"text-slate-500 hover:bg-slate-100 border border-transparent"}`,children:[u.label,I&&i!=="default"&&($==="asc"?e.jsx(Pa,{size:12}):e.jsx(La,{size:12}))]},u.key)})]}),e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-6",children:Ze.map(u=>{var Ie,re;const I=et(u),G=ft(u),C=Vl(u),q=u.kind?ds[u.kind]:null,ae=(q==null?void 0:q.icon)||Ct,ue=Rs[u.status||""]||null,oe=K&&et(K)===I;return e.jsxs("div",{onClick:()=>ie(u),className:`bg-white p-6 rounded-xl border shadow-sm hover:shadow-md transition-all group relative cursor-pointer ${oe?"border-blue-300 ring-1 ring-blue-200":"border-slate-200"}`,children:[e.jsxs("div",{className:"absolute top-4 right-4 flex gap-2 opacity-0 group-hover:opacity-100 transition-opacity z-10",children:[e.jsx("button",{onClick:ye=>{ye.stopPropagation(),b(u),M("edit"),z(ft(u))},className:"p-1.5 bg-slate-50 text-slate-400 hover:text-blue-600 hover:bg-blue-50 rounded-md transition-colors",title:"编辑",children:e.jsx(mt,{size:_.sm})}),e.jsx("button",{onClick:ye=>{ye.stopPropagation(),s(u.name||u.id)},className:"p-1.5 bg-slate-50 text-slate-400 hover:text-red-600 hover:bg-red-50 rounded-md transition-colors",title:"删除",children:e.jsx(ht,{size:_.sm})})]}),e.jsxs("div",{className:"flex justify-between items-start mb-2 pr-12 gap-2",children:[e.jsx("h3",{className:"font-bold text-slate-900 break-words min-w-0",children:I}),e.jsxs("div",{className:"flex items-center gap-1.5 shrink-0",children:[q&&e.jsxs("span",{className:`text-[8px] font-bold px-1.5 py-0.5 rounded uppercase flex items-center gap-1 border ${q.bg} ${q.color} ${q.border}`,children:[e.jsx(ae,{size:_.xs}),q.label]}),(()=>{var Ae,He;const ye=u.category||(typeof G=="string"?(He=(Ae=G.match(/category:\s*(.*)/))==null?void 0:Ae[1])==null?void 0:He.trim():null)||"Utility",Se=Xe[ye]||Xe.Utility,Be=Se.icon;return e.jsxs("span",{className:`text-[8px] font-bold px-1.5 py-0.5 rounded uppercase flex items-center gap-1 border ${Se.bg} ${Se.color} ${Se.border}`,children:[e.jsx(Be,{size:_.xs}),ye]})})(),ue&&u.status!=="active"&&u.status!=="published"&&e.jsx("span",{className:`text-[8px] font-bold px-1.5 py-0.5 rounded uppercase border ${ue.bg} ${ue.color} ${ue.border}`,children:u.status}),typeof G=="string"&&G.includes("type: preview")&&e.jsx("span",{className:"text-[10px] bg-amber-50 text-amber-700 border border-amber-200 px-1.5 py-0.5 rounded font-bold uppercase",children:"Preview Only"})]})]}),(u.knowledgeType||u.language||u.tags&&u.tags.length>0)&&e.jsxs("div",{className:"flex flex-wrap items-center gap-1.5 mb-2",children:[u.knowledgeType&&e.jsx("span",{className:"text-[9px] font-medium px-1.5 py-0.5 rounded bg-indigo-50 text-indigo-600 border border-indigo-100",children:u.knowledgeType}),u.language&&e.jsx("span",{className:"text-[9px] font-medium px-1.5 py-0.5 rounded bg-slate-100 text-slate-500 uppercase",children:u.language}),u.tags&&u.tags.length>0&&u.tags.slice(0,4).map((ye,Se)=>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(rs,{size:8}),ye]},Se)),u.tags&&u.tags.length>4&&e.jsxs("span",{className:"text-[9px] text-slate-400",children:["+",u.tags.length-4]})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2 mb-2 text-[10px] text-slate-500",children:[e.jsxs("span",{children:["权威 ",u.stats!=null?u.stats.authority:"—"]}),e.jsx("span",{children:"·"}),e.jsx("span",{children:u.stats!=null?`g:${u.stats.guardUsageCount} h:${u.stats.humanUsageCount} a:${u.stats.aiUsageCount}`:"g:0 h:0 a:0"}),e.jsx("span",{children:"·"}),e.jsxs("span",{children:["综合分 ",((Ie=u.stats)==null?void 0:Ie.authorityScore)!=null?u.stats.authorityScore.toFixed(2):"—"]}),e.jsx("span",{children:"·"}),e.jsxs("span",{children:["最近 ",xs((re=u.stats)==null?void 0:re.lastUsedAt)]})]}),e.jsx("div",{className:"text-xs text-slate-500 bg-slate-50 p-4 rounded-lg overflow-hidden line-clamp-4 font-mono whitespace-pre-wrap",children:C}),(u.relations||u.constraints)&&e.jsxs("div",{className:"flex flex-wrap items-center gap-2 mt-2",children:[u.relations&&Object.entries(u.relations).some(([,ye])=>Array.isArray(ye)&&ye.length>0)&&e.jsxs("span",{className:"text-[9px] font-medium px-1.5 py-0.5 rounded bg-purple-50 text-purple-600 border border-purple-100",children:["关系 ",Object.values(u.relations).flat().length]}),u.constraints&&(()=>{var Se,Be,Ae,He;const ye=(((Se=u.constraints.guards)==null?void 0:Se.length)||0)+(((Be=u.constraints.boundaries)==null?void 0:Be.length)||0)+(((Ae=u.constraints.preconditions)==null?void 0:Ae.length)||0)+(((He=u.constraints.sideEffects)==null?void 0:He.length)||0);return ye>0?e.jsxs("span",{className:"text-[9px] font-medium px-1.5 py-0.5 rounded bg-amber-50 text-amber-600 border border-amber-100",children:["约束 ",ye]}):null})()]})]},I)})})]}),t.length>0&&e.jsx(xa,{currentPage:f,totalPages:ke,totalItems:Ee.length,pageSize:k,onPageChange:Ve,onPageSizeChange:L}),K&&(()=>{var Se,Be,Ae,He,Qe,de;const u=K,I=et(u),G=ft(u),C=u.kind?ds[u.kind]:null,q=(C==null?void 0:C.icon)||Ct,ae=Rs[u.status||""]||null,ue=u.category||(typeof G=="string"?(Be=(Se=G.match(/category:\s*(.*)/))==null?void 0:Se[1])==null?void 0:Be.trim():null)||"Utility",oe=Xe[ue]||Xe.Utility,Ie=oe.icon,{metadata:re,body:ye}=Es(G);return e.jsxs(We,{className:"z-30 flex justify-end",onClick:()=>{Ne()},children:[e.jsx(We.Backdrop,{}),E&&(()=>{var N,D,W,O,pe;const j=E,he=et(j),Ce=ft(j),je=j.kind?ds[j.kind]:null,Te=(je==null?void 0:je.icon)||Ct,Me=j.category||(typeof Ce=="string"?(D=(N=Ce.match(/category:\s*(.*)/))==null?void 0:N[1])==null?void 0:D.trim():null)||"Utility",Pe=Xe[Me]||Xe.Utility,be=Pe.icon,{metadata:Ue,body:ze}=Es(Ce);return e.jsxs("div",{className:`relative h-full bg-white shadow-2xl flex flex-col border-r border-slate-200 ${U?"w-[720px] max-w-[50vw]":"w-[520px] max-w-[40vw]"}`,style:{animation:"slideInRight 0.2s ease-out"},onClick:le=>le.stopPropagation(),children:[e.jsxs("div",{className:"flex items-center justify-between px-5 py-3 border-b border-slate-200 bg-purple-50/50 shrink-0",children:[e.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[e.jsx(hs,{size:14,className:"text-purple-400 shrink-0"}),e.jsx("h3",{className:"font-bold text-slate-800 text-sm leading-snug break-words min-w-0",children:he.replace(/\.md$/i,"")})]}),e.jsx("button",{onClick:Ge,className:"p-1.5 hover:bg-slate-100 rounded-lg transition-colors shrink-0",title:"关闭",children:e.jsx(Ke,{size:14})})]}),e.jsxs("div",{className:"flex-1 overflow-y-auto",children:[e.jsxs("div",{className:"px-5 py-3 border-b border-slate-100 flex flex-wrap items-center gap-2",children:[je&&e.jsxs("span",{className:`text-[9px] font-bold px-2 py-0.5 rounded uppercase flex items-center gap-1 border ${je.bg} ${je.color} ${je.border}`,children:[e.jsx(Te,{size:_.xs}),je.label]}),e.jsxs("span",{className:`text-[9px] font-bold px-2 py-0.5 rounded uppercase flex items-center gap-1 border ${Pe.bg} ${Pe.color} ${Pe.border}`,children:[e.jsx(be,{size:_.xs}),Me]}),j.language&&e.jsx("span",{className:"text-[9px] font-medium px-2 py-0.5 rounded bg-slate-100 text-slate-500 uppercase",children:j.language}),j.knowledgeType&&e.jsx("span",{className:"text-[9px] font-medium px-2 py-0.5 rounded bg-indigo-50 text-indigo-600 border border-indigo-100",children:j.knowledgeType})]}),j.tags&&j.tags.length>0&&e.jsx("div",{className:"px-5 py-2.5 border-b border-slate-100 flex flex-wrap items-center gap-1.5",children:j.tags.map((le,xe)=>e.jsxs("span",{className:"text-[9px] px-2 py-0.5 rounded bg-blue-50 text-blue-600 border border-blue-100 flex items-center gap-0.5",children:[e.jsx(rs,{size:8}),le]},xe))}),e.jsx("div",{className:"px-5 py-3 border-b border-slate-100",children:e.jsxs("div",{className:"grid grid-cols-4 gap-2",children:[e.jsxs("div",{className:"bg-slate-50 rounded-lg p-2 text-center",children:[e.jsx("div",{className:"text-sm font-bold text-slate-800",children:((W=j.stats)==null?void 0:W.authority)??"—"}),e.jsx("div",{className:"text-[8px] text-slate-400 font-medium",children:"权威"})]}),e.jsxs("div",{className:"bg-slate-50 rounded-lg p-2 text-center",children:[e.jsx("div",{className:"text-sm font-bold text-slate-800",children:((O=j.stats)==null?void 0:O.authorityScore)!=null?j.stats.authorityScore.toFixed(1):"—"}),e.jsx("div",{className:"text-[8px] text-slate-400 font-medium",children:"综合分"})]}),e.jsxs("div",{className:"bg-slate-50 rounded-lg p-2 text-center",children:[e.jsx("div",{className:"text-sm font-bold text-slate-800",children:j.stats!=null?j.stats.guardUsageCount+j.stats.humanUsageCount+j.stats.aiUsageCount:0}),e.jsx("div",{className:"text-[8px] text-slate-400 font-medium",children:"总使用"})]}),e.jsxs("div",{className:"bg-slate-50 rounded-lg p-2 text-center",children:[e.jsx("div",{className:"text-[10px] font-bold text-slate-800",children:xs((pe=j.stats)==null?void 0:pe.lastUsedAt)}),e.jsx("div",{className:"text-[8px] text-slate-400 font-medium",children:"最近使用"})]})]})}),j.description&&e.jsxs("div",{className:"px-5 py-3 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-xs text-slate-600 leading-relaxed",children:j.description})]}),Object.keys(Ue).length>0&&e.jsxs("div",{className:"px-5 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:"grid grid-cols-2 gap-y-2 gap-x-4",children:Object.entries(Ue).filter(([le])=>!["tags","headers","summary_cn","summary_en","summary"].includes(le)).map(([le,xe])=>{let ce=xe;if(le==="updatedAt"||le==="createdAt"){const ge=parseInt(xe,10);!isNaN(ge)&&ge>9466848e5&&(ce=new Date(ge).toLocaleString("zh-CN",{year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit"}))}return e.jsxs("div",{className:"flex flex-col",children:[e.jsx("span",{className:"text-[9px] text-slate-400 font-bold uppercase",children:le}),e.jsx("span",{className:"text-[10px] text-slate-700 break-all font-medium",children:ce})]},le)})})]}),e.jsxs("div",{className:"px-5 py-4",children:[e.jsx("label",{className:"text-[10px] font-bold text-slate-400 uppercase mb-2 block",children:"内容"}),ze?e.jsx("div",{className:"markdown-body text-slate-700 text-xs",children:e.jsx(lt,{content:ze,showLineNumbers:!0})}):e.jsx("div",{className:"text-xs text-slate-300 italic py-6 text-center",children:"暂无正文内容"})]})]}),e.jsxs("div",{className:"px-4 py-2 border-t border-slate-200 flex items-center justify-between shrink-0 bg-slate-50",children:[e.jsx("span",{className:"text-[10px] text-slate-400",children:"关联 Recipe 预览"}),e.jsxs("button",{onClick:()=>{ie(j)},className:"text-[10px] px-3 py-1 bg-blue-600 text-white rounded font-bold hover:bg-blue-700 flex items-center gap-1",children:[e.jsx($t,{size:10})," 打开完整视图"]})]})]})})(),e.jsxs("div",{className:`relative h-full bg-white shadow-2xl flex flex-col ${U?"w-[min(92vw,1100px)]":"w-[min(92vw,800px)]"}`,style:{animation:"slideInRight 0.25s ease-out"},onClick:j=>j.stopPropagation(),children:[e.jsxs("div",{className:"flex items-center justify-between px-5 py-3 border-b border-slate-200 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:I})}),e.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[e.jsx("button",{onClick:J,disabled:g<=0,className:"p-1.5 hover:bg-slate-100 rounded-lg transition-colors disabled:opacity-30 disabled:cursor-not-allowed",title:"上一条",children:e.jsx(fs,{size:_.md})}),e.jsxs("span",{className:"text-xs text-slate-400 tabular-nums",children:[g+1,"/",t.length]}),e.jsx("button",{onClick:Z,disabled:g>=t.length-1,className:"p-1.5 hover:bg-slate-100 rounded-lg transition-colors disabled:opacity-30 disabled:cursor-not-allowed",title:"下一条",children:e.jsx(it,{size:_.md})}),e.jsx("div",{className:"w-px h-5 bg-slate-200 mx-1"}),e.jsxs("div",{className:"flex bg-slate-100 p-0.5 rounded-lg mr-1",children:[e.jsxs("button",{onClick:()=>M("view"),className:`px-2.5 py-1 rounded-md text-xs font-bold transition-all flex items-center gap-1 ${R==="view"?"bg-white shadow-sm text-blue-600":"text-slate-400 hover:text-slate-600"}`,children:[e.jsx($t,{size:_.sm})," 预览"]}),e.jsxs("button",{onClick:()=>{M("edit"),z(ft(u))},className:`px-2.5 py-1 rounded-md text-xs font-bold transition-all flex items-center gap-1 ${R==="edit"?"bg-white shadow-sm text-blue-600":"text-slate-400 hover:text-slate-600"}`,children:[e.jsx(mt,{size:_.sm})," 编辑"]})]}),e.jsx("button",{onClick:B,className:"p-1.5 hover:bg-slate-100 rounded-lg transition-colors text-slate-400",title:U?"收窄面板":"展开更宽",children:U?e.jsx(qs,{size:_.md}):e.jsx(js,{size:_.md})}),e.jsx("button",{onClick:()=>{s(u.name||u.id),Ne()},className:"p-1.5 hover:bg-red-50 rounded-lg text-red-500 transition-colors",title:"删除",children:e.jsx(ht,{size:_.md})}),e.jsx("button",{onClick:Ne,className:"p-1.5 hover:bg-slate-100 rounded-lg transition-colors",children:e.jsx(Ke,{size:_.md})})]})]}),R==="edit"?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex-1 flex flex-col min-h-0 p-4",children:[e.jsx("label",{className:"text-[10px] font-bold text-slate-400 uppercase mb-2 block",children:"Markdown 内容"}),e.jsx("div",{className:"flex-1 min-h-0",children:e.jsx(ls,{value:H,onChange:z,language:"markdown",height:"100%",showLineNumbers:!0})})]}),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.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:((Ae=u.stats)==null?void 0:Ae.authority)??3,onChange:j=>fe(parseInt(j.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.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{onClick:()=>M("view"),disabled:P,className:"px-4 py-1.5 text-sm text-slate-600 font-medium rounded-lg hover:bg-slate-50",children:"取消"}),e.jsxs("button",{onClick:Re,disabled:P,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:[P?e.jsx(_e,{size:_.sm,className:"animate-spin"}):e.jsx(as,{size:_.sm}),P?"保存中...":"保存"]})]})]})]}):e.jsxs("div",{className:"flex-1 overflow-y-auto",children:[e.jsxs("div",{className:"px-5 py-3 border-b border-slate-100 flex flex-wrap items-center gap-2",children:[C&&e.jsxs("span",{className:`text-[9px] font-bold px-2 py-0.5 rounded uppercase flex items-center gap-1 border ${C.bg} ${C.color} ${C.border}`,children:[e.jsx(q,{size:_.xs}),C.label]}),e.jsxs("span",{className:`text-[9px] font-bold px-2 py-0.5 rounded uppercase flex items-center gap-1 border ${oe.bg} ${oe.color} ${oe.border}`,children:[e.jsx(Ie,{size:_.xs}),ue]}),ae&&e.jsx("span",{className:`text-[9px] font-bold px-2 py-0.5 rounded uppercase border ${ae.bg} ${ae.color} ${ae.border}`,children:u.status}),u.knowledgeType&&e.jsx("span",{className:"text-[9px] font-medium px-2 py-0.5 rounded bg-indigo-50 text-indigo-600 border border-indigo-100",children:u.knowledgeType}),u.language&&e.jsx("span",{className:"text-[9px] font-medium px-2 py-0.5 rounded bg-slate-100 text-slate-500 uppercase",children:u.language}),u.trigger&&e.jsx("span",{className:"text-[9px] font-mono font-bold px-2 py-0.5 rounded bg-blue-50 text-blue-600 border border-blue-100",children:u.trigger})]}),u.tags&&u.tags.length>0&&e.jsx("div",{className:"px-5 py-2.5 border-b border-slate-100 flex flex-wrap items-center gap-1.5",children:u.tags.map((j,he)=>e.jsxs("span",{className:"text-[9px] px-2 py-0.5 rounded bg-blue-50 text-blue-600 border border-blue-100 flex items-center gap-0.5",children:[e.jsx(rs,{size:8}),j]},he))}),e.jsxs("div",{className:"px-5 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-slate-50 rounded-lg p-3 text-center",children:[e.jsx("div",{className:"text-lg font-bold text-slate-800",children:((He=u.stats)==null?void 0:He.authority)??"—"}),e.jsx("div",{className:"text-[10px] text-slate-400 font-medium",children:"权威"})]}),e.jsxs("div",{className:"bg-slate-50 rounded-lg p-3 text-center",children:[e.jsx("div",{className:"text-lg font-bold text-slate-800",children:((Qe=u.stats)==null?void 0:Qe.authorityScore)!=null?u.stats.authorityScore.toFixed(1):"—"}),e.jsx("div",{className:"text-[10px] text-slate-400 font-medium",children:"综合分"})]}),e.jsxs("div",{className:"bg-slate-50 rounded-lg p-3 text-center",children:[e.jsx("div",{className:"text-lg font-bold text-slate-800",children:u.stats!=null?u.stats.guardUsageCount+u.stats.humanUsageCount+u.stats.aiUsageCount:0}),e.jsx("div",{className:"text-[10px] text-slate-400 font-medium",children:"总使用"})]}),e.jsxs("div",{className:"bg-slate-50 rounded-lg p-3 text-center",children:[e.jsx("div",{className:"text-sm font-bold text-slate-800",children:xs((de=u.stats)==null?void 0:de.lastUsedAt)}),e.jsx("div",{className:"text-[10px] text-slate-400 font-medium",children:"最近使用"})]})]}),u.stats!=null&&e.jsxs("div",{className:"flex items-center gap-4 mt-2 text-[10px] text-slate-400",children:[e.jsxs("span",{children:["Guard: ",u.stats.guardUsageCount]}),e.jsxs("span",{children:["Human: ",u.stats.humanUsageCount]}),e.jsxs("span",{children:["AI: ",u.stats.aiUsageCount]})]})]}),Object.keys(re).length>0&&e.jsxs("div",{className:"px-5 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:"grid grid-cols-2 sm:grid-cols-3 gap-y-2.5 gap-x-6",children:Object.entries(re).filter(([j])=>!["tags","headers","summary_cn","summary_en","summary","usageGuide","usageGuide_cn","usageGuide_en"].includes(j)).map(([j,he])=>{let Ce=he;if(j==="updatedAt"||j==="createdAt"){const je=parseInt(he,10);!isNaN(je)&&je>9466848e5&&(Ce=new Date(je).toLocaleString("zh-CN",{year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit"}))}return e.jsxs("div",{className:"flex flex-col",children:[e.jsx("span",{className:"text-[9px] text-slate-400 font-bold uppercase",children:j}),e.jsx("span",{className:"text-xs text-slate-700 break-all font-medium",children:Ce})]},j)})}),re.headers&&e.jsxs("div",{className:"mt-2.5",children:[e.jsx("span",{className:"text-[9px] text-slate-400 font-bold uppercase block mb-1",children:"Headers"}),e.jsx("div",{className:"flex flex-wrap gap-1.5",children:(()=>{try{const j=JSON.parse(re.headers);return(Array.isArray(j)?j:[re.headers]).map((he,Ce)=>e.jsx("code",{className:"px-2 py-0.5 bg-violet-50 text-violet-700 border border-violet-100 rounded text-[10px] font-mono",children:he},Ce))}catch{return e.jsx("code",{className:"text-xs text-slate-700 font-mono",children:re.headers})}})()})]}),(re.summary_cn||re.summary)&&e.jsxs("div",{className:"mt-2.5",children:[e.jsx("span",{className:"text-[9px] text-slate-400 font-bold uppercase block mb-1",children:"摘要"}),e.jsx("p",{className:"text-xs text-slate-600 leading-relaxed",children:re.summary_cn||re.summary})]}),re.summary_en&&e.jsxs("div",{className:"mt-2",children:[e.jsx("span",{className:"text-[9px] text-slate-400 font-bold uppercase block mb-1",children:"Summary (EN)"}),e.jsx("p",{className:"text-xs text-slate-600 leading-relaxed",children:re.summary_en})]})]}),e.jsxs("div",{className:"px-5 py-3 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(hs,{size:12,className:"text-purple-400"}),e.jsx("label",{className:"text-[10px] font-bold text-slate-400 uppercase",children:"关联 Recipes"}),(()=>{const j=u.relations?Object.values(u.relations).flat().length:0;return j>0?e.jsx("span",{className:"text-[9px] bg-purple-100 text-purple-600 px-1.5 py-0.5 rounded-full font-bold",children:j}):null})()]}),e.jsx("button",{onClick:()=>{V(!h),Y("")},className:`text-[9px] px-2 py-0.5 rounded font-bold flex items-center gap-1 transition-colors ${h?"bg-slate-200 text-slate-600 hover:bg-slate-300":"bg-purple-500 text-white hover:bg-purple-600"}`,children:h?e.jsxs(e.Fragment,{children:[e.jsx(Ke,{size:10})," 取消"]}):e.jsxs(e.Fragment,{children:[e.jsx(ut,{size:10})," 添加关联"]})})]}),h&&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:me,onChange:j=>F(j.target.value),className:"text-[10px] font-bold bg-white border border-purple-200 text-purple-700 rounded px-2 py-1 outline-none focus:ring-1 focus:ring-purple-400",children:Q.map(j=>e.jsxs("option",{value:j.key,children:[j.icon," ",j.label]},j.key))}),e.jsxs("div",{className:"flex-1 relative",children:[e.jsx(pt,{size:12,className:"absolute left-2 top-1/2 -translate-y-1/2 text-slate-300"}),e.jsx("input",{type:"text",placeholder:"搜索 Recipe 名称...",value:X,onChange:j=>Y(j.target.value),className:"w-full text-xs bg-white border border-purple-200 rounded pl-7 pr-2 py-1 outline-none focus:ring-1 focus:ring-purple-400",autoFocus:!0})]})]}),X.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 j=t.filter(he=>et(he)===I?!1:et(he).toLowerCase().includes(X.toLowerCase())).slice(0,10);return j.length===0?e.jsx("div",{className:"text-xs text-slate-400 py-3 text-center",children:"未找到匹配的 Recipe"}):j.map(he=>{const Ce=et(he),je=u.relations&&Object.values(u.relations).flat().some(Te=>(typeof Te=="string"?Te:Te.id||Te.title||"").replace(/\.md$/i,"").toLowerCase()===Ce.replace(/\.md$/i,"").toLowerCase());return e.jsxs("div",{className:`flex items-center justify-between px-3 py-1.5 text-xs transition-colors ${je?"bg-slate-50 text-slate-400":"hover:bg-purple-50 cursor-pointer"}`,onClick:()=>!je&&we(me,Ce),children:[e.jsx("span",{className:"font-medium truncate mr-2",children:Ce.replace(/\.md$/i,"")}),je?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:"+ 添加"})]},Ce)})})()})]}),u.relations&&Object.entries(u.relations).some(([,j])=>Array.isArray(j)&&j.length>0)?e.jsx("div",{className:"space-y-1.5",children:Q.map(({key:j,label:he,icon:Ce})=>{var Te;const je=(Te=u.relations)==null?void 0:Te[j];return!je||!Array.isArray(je)||je.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:[Ce," ",he]}),e.jsx("div",{className:"flex flex-wrap gap-1",children:je.map((Me,Pe)=>{const be=typeof Me=="string"?Me:Me.id||Me.title||JSON.stringify(Me),Ue=!!ve(be);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 ${Ue?"bg-purple-50 border-purple-200 text-purple-700 cursor-pointer hover:bg-purple-100 hover:border-purple-300":"bg-white border-slate-200 text-slate-600"}`,onClick:()=>Ue&&Le(be),title:Ue?"点击查看详情":be,children:[be.replace(/\.md$/i,""),e.jsx("button",{onClick:ze=>{ze.stopPropagation(),Fe(j,be)},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})})]},Pe)})})]},j)})}):!h&&e.jsx("div",{className:"text-xs text-slate-300 py-2 text-center",children:"暂无关联,点击上方按钮添加"})]}),u.constraints&&(()=>{var Ce,je,Te,Me,Pe,be,Ue,ze;const j=u.constraints;return(((Ce=j.guards)==null?void 0:Ce.length)||0)+(((je=j.boundaries)==null?void 0:je.length)||0)+(((Te=j.preconditions)==null?void 0:Te.length)||0)+(((Me=j.sideEffects)==null?void 0:Me.length)||0)>0?e.jsxs("div",{className:"px-5 py-3 border-b border-slate-100",children:[e.jsx("label",{className:"text-[10px] font-bold text-slate-400 uppercase mb-1.5 block",children:"约束条件"}),e.jsxs("div",{className:"space-y-1.5 text-xs text-slate-600",children:[(Pe=j.guards)==null?void 0:Pe.map((N,D)=>e.jsxs("div",{className:"flex gap-1.5 items-start",children:[e.jsx("span",{className:`text-xs mt-0.5 ${N.severity==="error"?"text-red-500":"text-yellow-500"}`,children:"●"}),e.jsx("code",{className:"font-mono text-[10px] bg-slate-100 px-1 py-0.5 rounded",children:N.pattern}),N.message&&e.jsxs("span",{className:"text-[10px] text-slate-400",children:["— ",N.message]})]},D)),(be=j.boundaries)==null?void 0:be.map((N,D)=>e.jsxs("div",{className:"flex gap-1.5",children:[e.jsx("span",{className:"text-orange-400",children:"●"}),N]},D)),(Ue=j.preconditions)==null?void 0:Ue.map((N,D)=>e.jsxs("div",{className:"flex gap-1.5",children:[e.jsx("span",{className:"text-blue-400",children:"◆"}),N]},D)),(ze=j.sideEffects)==null?void 0:ze.map((N,D)=>e.jsxs("div",{className:"flex gap-1.5",children:[e.jsx("span",{className:"text-pink-400",children:"⚡"}),N]},D))]})]}):null})(),u.description&&u.description!==(re.summary_cn||re.summary||"")&&e.jsxs("div",{className:"px-5 py-3 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:u.description})]}),(u.usageGuide||u.usageGuide_cn||re.usageGuide||re.usageGuide_cn||re.usageGuide_en)&&e.jsxs("div",{className:"px-5 py-3 border-b border-slate-100",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-blue-400"})," 使用指南"]}),e.jsx("div",{className:"markdown-body text-sm text-slate-600",children:e.jsx(lt,{content:u.usageGuide||u.usageGuide_cn||re.usageGuide||re.usageGuide_cn||""})}),(u.usageGuide_en||re.usageGuide_en)&&e.jsxs("div",{className:"mt-2 pt-2 border-t border-slate-100",children:[e.jsx("span",{className:"text-[9px] text-slate-400 font-bold uppercase block mb-1",children:"Usage Guide (EN)"}),e.jsx("div",{className:"markdown-body text-sm text-slate-500",children:e.jsx(lt,{content:u.usageGuide_en||re.usageGuide_en||""})})]})]}),u.v2Content&&(()=>{const j=u.v2Content,he=j.pattern&&ye&&ye.includes(j.pattern.trim());return j.rationale||j.pattern&&!he||j.steps&&j.steps.length>0||j.codeChanges&&j.codeChanges.length>0||j.verification?e.jsxs("div",{className:"px-5 py-3 border-b border-slate-100 space-y-3",children:[j.rationale&&e.jsxs("div",{children:[e.jsx("label",{className:"text-[10px] font-bold text-slate-400 uppercase mb-1 block",children:"设计原理"}),e.jsx("p",{className:"text-sm text-slate-600 leading-relaxed",children:j.rationale})]}),j.pattern&&!he&&e.jsxs("div",{children:[e.jsx("label",{className:"text-[10px] font-bold text-slate-400 uppercase mb-1 block",children:"模式"}),e.jsx("div",{className:"markdown-body text-sm text-slate-600",children:e.jsx(lt,{content:j.pattern,showLineNumbers:!0})})]}),j.steps&&j.steps.length>0&&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:"space-y-2",children:j.steps.map((je,Te)=>{if(typeof je=="string")return e.jsx("div",{className:"bg-slate-50 rounded-lg p-3 border border-slate-100",children:e.jsxs("div",{className:"flex items-start gap-2",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",children:je})]})},Te);const Me=typeof je.title=="string"?je.title:"",Pe=typeof je.description=="string"?je.description:"",be=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:Te+1}),Me&&e.jsx("span",{className:"text-xs font-bold text-slate-700",children:Me})]}),Pe&&e.jsx("p",{className:"text-xs text-slate-600 ml-7",children:Pe}),be&&e.jsx("pre",{className:"text-[11px] font-mono bg-slate-800 text-green-300 p-2 rounded mt-1 ml-7 overflow-x-auto whitespace-pre-wrap",children:be})]},Te)})})]}),j.codeChanges&&j.codeChanges.length>0&&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:"space-y-2",children:j.codeChanges.map((je,Te)=>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(Js,{size:11,className:"text-blue-400"}),e.jsx("code",{className:"text-[10px] font-mono text-slate-600",children:je.file})]}),je.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:je.explanation}),e.jsxs("div",{className:"p-2 bg-red-50/30 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:je.before||"(空)"})]}),e.jsxs("div",{className:"p-2 bg-emerald-50/30",children:[e.jsx("div",{className:"text-[9px] font-bold text-emerald-500 mb-0.5 uppercase",children:"After"}),e.jsx("pre",{className:"text-[11px] text-slate-700 whitespace-pre-wrap break-words font-mono",children:je.after})]})]},Te))})]}),j.verification&&e.jsxs("div",{children:[e.jsx("label",{className:"text-[10px] font-bold text-slate-400 uppercase mb-1 block",children:"验证方法"}),e.jsxs("div",{className:"bg-teal-50/50 border border-teal-100 rounded-lg p-3 space-y-1.5",children:[j.verification.method&&e.jsxs("p",{className:"text-xs text-slate-600",children:[e.jsx("span",{className:"font-bold text-teal-600",children:"方法:"})," ",j.verification.method]}),j.verification.expectedResult&&e.jsxs("p",{className:"text-xs text-slate-600",children:[e.jsx("span",{className:"font-bold text-teal-600",children:"预期结果:"})," ",j.verification.expectedResult]}),j.verification.testCode&&e.jsx("pre",{className:"text-[11px] font-mono bg-slate-800 text-green-300 p-2 rounded overflow-x-auto whitespace-pre-wrap mt-1",children:j.verification.testCode})]})]})]}):null})(),e.jsxs("div",{className:"px-5 py-4",children:[e.jsx("label",{className:"text-[10px] font-bold text-slate-400 uppercase mb-2 block",children:"内容"}),ye?e.jsx("div",{className:"markdown-body text-slate-700",children:e.jsx(lt,{content:ye,showLineNumbers:!0})}):e.jsx("div",{className:"text-sm text-slate-300 italic py-8 text-center",children:"暂无正文内容"})]})]})]})]})})()]})},Yl=()=>{const[t,s]=r.useState(new Set(["quick-start"])),a=n=>{const o=new Set(t);o.has(n)?o.delete(n):o.add(n),s(o)},l=({id:n,title:o,icon:c,children:i})=>{const x=t.has(n);return e.jsxs("section",{className:"border border-slate-200 rounded-lg overflow-hidden",children:[e.jsxs("button",{onClick:()=>a(n),className:"w-full flex items-center justify-between p-4 bg-slate-50 hover:bg-slate-100 transition-colors",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[c,e.jsx("h2",{className:"text-lg font-bold text-slate-800",children:o})]}),x?e.jsx(kt,{size:_.lg}):e.jsx(it,{size:_.lg})]}),x&&e.jsx("div",{className:"p-4 bg-white",children:i})]})};return e.jsxs("div",{className:"max-w-5xl mx-auto py-8 px-4",children:[e.jsxs("div",{className:"mb-8 text-center",children:[e.jsxs("h1",{className:"text-4xl font-bold text-slate-900 mb-4 flex items-center justify-center gap-3",children:[e.jsx(at,{size:_.xxl,className:"text-blue-600"}),"AutoSnippet V2 使用说明"]}),e.jsx("p",{className:"text-slate-600 text-lg max-w-3xl mx-auto whitespace-nowrap",children:"连接开发者、AI 与项目知识库:Dual-Agent 智能对话 + 4 层检索管线 + .md Source of Truth"}),e.jsx("p",{className:"text-slate-400 text-sm mt-2",children:"Node.js ≥ 20 · 36 MCP 工具 · 10 Skills · Dual-Agent 对话 · 4 层检索管线"}),e.jsxs("div",{className:"mt-6 flex gap-4 justify-center text-sm",children:[e.jsx("a",{href:"https://github.com/GxFn/AutoSnippet",target:"_blank",rel:"noopener noreferrer",className:"px-4 py-2 bg-blue-600 text-white rounded-lg hover:bg-blue-700 transition-colors",children:"查看 GitHub"}),e.jsx("a",{href:"https://github.com/GxFn/AutoSnippet/blob/main/README.md",target:"_blank",rel:"noopener noreferrer",className:"px-4 py-2 border border-slate-300 text-slate-700 rounded-lg hover:bg-slate-50 transition-colors",children:"完整文档"})]})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsx(l,{id:"quick-start",title:"快速开始",icon:e.jsx(Tt,{size:_.xl,className:"text-blue-600"}),children:e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-4 gap-4",children:[e.jsxs("div",{className:"bg-blue-50 rounded-lg p-4 border border-blue-200",children:[e.jsx("div",{className:"bg-blue-600 text-white rounded-full w-8 h-8 flex items-center justify-center mb-3 font-bold",children:"1"}),e.jsx("h3",{className:"font-semibold text-slate-800 mb-2",children:"安装与初始化"}),e.jsx("pre",{className:"bg-blue-100/70 text-blue-900 px-3 py-2 rounded text-xs overflow-hidden",children:e.jsxs("code",{children:["npm install -g autosnippet",`
|
|
91
|
+
`).trim();return{metadata:a,body:o}}const Jl=({recipes:t,handleDeleteRecipe:s,onRefresh:a,currentPage:l,onPageChange:n,pageSize:o,onPageSizeChange:c})=>{const[i,x]=r.useState("default"),[$,d]=r.useState("desc"),y=[{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,S]=r.useState(1),[v,A]=r.useState(12),f=l??m,k=o??v,T=n??S,L=c?u=>c(u):u=>{A(u),S(1)},{isWide:U,toggle:B}=da(),[K,b]=r.useState(null),[R,M]=r.useState("view"),[H,_]=r.useState(""),[P,p]=r.useState(!1),w=r.useRef(!0),[E,se]=r.useState(null),[h,V]=r.useState(!1),[me,F]=r.useState("related"),[X,Y]=r.useState("");r.useEffect(()=>()=>{w.current=!1},[]);const ie=u=>{b(u),M("view"),_(ft(u)),se(null),V(!1),Y("")},Ne=()=>{b(null),M("view"),se(null),V(!1),Y("")},Re=async()=>{if(!(!K||P)){p(!0);try{await te.saveRecipe(K.name,H),w.current&&(M("view"),a==null||a())}catch(u){alert((u==null?void 0:u.message)||"保存 Recipe 失败")}finally{w.current&&p(!1)}}},fe=async u=>{if(K)try{await te.setRecipeAuthority(K.name,u),a==null||a()}catch(I){ee((I==null?void 0:I.message)||"设置权威分失败",{title:"操作失败",type:"error"})}},Q=[{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:"⊃"}],ve=u=>{const I=u.replace(/\.md$/i,"").toLowerCase();return t.find(G=>et(G).replace(/\.md$/i,"").toLowerCase()===I)},Le=u=>{const I=ve(u);I&&se(I)},Ge=()=>se(null),we=async(u,I)=>{if(!K)return;const G={};if(K.relations)for(const[ae,ue]of Object.entries(K.relations))G[ae]=[...ue];const C=G[u]||[],q=I.replace(/\.md$/i,"");if(!C.some(ae=>(typeof ae=="string"?ae:ae.id||ae.title||"").replace(/\.md$/i,"").toLowerCase()===q.toLowerCase())){G[u]=[...C,q];try{await te.updateRecipeRelations(K.name,G),b({...K,relations:G}),V(!1),Y(""),a==null||a()}catch(ae){alert((ae==null?void 0:ae.message)||"添加关联失败")}}},Fe=async(u,I)=>{if(!K)return;const G={};if(K.relations)for(const[q,ae]of Object.entries(K.relations))G[q]=[...ae];const C=G[u]||[];G[u]=C.filter(q=>(typeof q=="string"?q:q.id||q.title||"").replace(/\.md$/i,"").toLowerCase()!==I.replace(/\.md$/i,"").toLowerCase()),G[u].length===0&&delete G[u];try{await te.updateRecipeRelations(K.name,G),b({...K,relations:G}),a==null||a()}catch(q){alert((q==null?void 0:q.message)||"移除关联失败")}};r.useEffect(()=>{K&&!t.find(u=>et(u)===et(K))&&Ne()},[t,K]),r.useEffect(()=>{l==null&&S(1)},[t.length,l]);const Ee=Bt.useMemo(()=>{if(i==="default")return t;const u=[...t],I=$==="asc"?1:-1;return u.sort((G,C)=>{var ue,oe,Ie,re,ye,Se,Be,Ae,He,Qe,de,j;let q=0,ae=0;switch(i){case"name":return q=et(G).toLowerCase(),ae=et(C).toLowerCase(),I*(q<ae?-1:q>ae?1:0);case"authorityScore":q=((ue=G.stats)==null?void 0:ue.authorityScore)??-1,ae=((oe=C.stats)==null?void 0:oe.authorityScore)??-1;break;case"authority":q=((Ie=G.stats)==null?void 0:Ie.authority)??-1,ae=((re=C.stats)==null?void 0:re.authority)??-1;break;case"totalUsage":q=(((ye=G.stats)==null?void 0:ye.guardUsageCount)??0)+(((Se=G.stats)==null?void 0:Se.humanUsageCount)??0)+(((Be=G.stats)==null?void 0:Be.aiUsageCount)??0),ae=(((Ae=C.stats)==null?void 0:Ae.guardUsageCount)??0)+(((He=C.stats)==null?void 0:He.humanUsageCount)??0)+(((Qe=C.stats)==null?void 0:Qe.aiUsageCount)??0);break;case"lastUsed":{const he=(de=G.stats)!=null&&de.lastUsedAt?new Date(G.stats.lastUsedAt).getTime():0,Ce=(j=C.stats)!=null&&j.lastUsedAt?new Date(C.stats.lastUsedAt).getTime():0;q=isNaN(he)?0:he,ae=isNaN(Ce)?0:Ce;break}case"category":return q=(G.category||"").toLowerCase(),ae=(C.category||"").toLowerCase(),I*(q<ae?-1:q>ae?1:0)}return I*(q-ae)}),u},[t,i,$]),ke=Math.ceil(Ee.length/k),De=(f-1)*k,Ze=Ee.slice(De,De+k),Ve=u=>{T(u),window.scrollTo({top:0,behavior:"smooth"})},g=K?Ee.findIndex(u=>et(u)===et(K)):-1,J=()=>{g>0&&b(Ee[g-1])},Z=()=>{g<Ee.length-1&&b(Ee[g+1])};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(Da,{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(Vs,{size:14,className:"text-slate-400 shrink-0"}),y.map(u=>{const I=i===u.key;return e.jsxs("button",{onClick:()=>{I?d(G=>G==="asc"?"desc":"asc"):(x(u.key),d(u.defaultDir)),T(1)},className:`px-2 py-1 rounded-md flex items-center gap-0.5 transition-colors ${I?"bg-blue-50 text-blue-700 font-medium border border-blue-200":"text-slate-500 hover:bg-slate-100 border border-transparent"}`,children:[u.label,I&&i!=="default"&&($==="asc"?e.jsx(Pa,{size:12}):e.jsx(La,{size:12}))]},u.key)})]}),e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-6",children:Ze.map(u=>{var Ie,re;const I=et(u),G=ft(u),C=Vl(u),q=u.kind?ds[u.kind]:null,ae=(q==null?void 0:q.icon)||Ct,ue=Rs[u.status||""]||null,oe=K&&et(K)===I;return e.jsxs("div",{onClick:()=>ie(u),className:`bg-white p-6 rounded-xl border shadow-sm hover:shadow-md transition-all group relative cursor-pointer ${oe?"border-blue-300 ring-1 ring-blue-200":"border-slate-200"}`,children:[e.jsxs("div",{className:"absolute top-4 right-4 flex gap-2 opacity-0 group-hover:opacity-100 transition-opacity z-10",children:[e.jsx("button",{onClick:ye=>{ye.stopPropagation(),b(u),M("edit"),_(ft(u))},className:"p-1.5 bg-slate-50 text-slate-400 hover:text-blue-600 hover:bg-blue-50 rounded-md transition-colors",title:"编辑",children:e.jsx(mt,{size:z.sm})}),e.jsx("button",{onClick:ye=>{ye.stopPropagation(),s(u.name||u.id)},className:"p-1.5 bg-slate-50 text-slate-400 hover:text-red-600 hover:bg-red-50 rounded-md transition-colors",title:"删除",children:e.jsx(ht,{size:z.sm})})]}),e.jsxs("div",{className:"flex justify-between items-start mb-2 pr-12 gap-2",children:[e.jsx("h3",{className:"font-bold text-slate-900 break-words min-w-0",children:I}),e.jsxs("div",{className:"flex items-center gap-1.5 shrink-0",children:[q&&e.jsxs("span",{className:`text-[8px] font-bold px-1.5 py-0.5 rounded uppercase flex items-center gap-1 border ${q.bg} ${q.color} ${q.border}`,children:[e.jsx(ae,{size:z.xs}),q.label]}),(()=>{var Ae,He;const ye=u.category||(typeof G=="string"?(He=(Ae=G.match(/category:\s*(.*)/))==null?void 0:Ae[1])==null?void 0:He.trim():null)||"Utility",Se=Xe[ye]||Xe.Utility,Be=Se.icon;return e.jsxs("span",{className:`text-[8px] font-bold px-1.5 py-0.5 rounded uppercase flex items-center gap-1 border ${Se.bg} ${Se.color} ${Se.border}`,children:[e.jsx(Be,{size:z.xs}),ye]})})(),ue&&u.status!=="active"&&u.status!=="published"&&e.jsx("span",{className:`text-[8px] font-bold px-1.5 py-0.5 rounded uppercase border ${ue.bg} ${ue.color} ${ue.border}`,children:u.status}),typeof G=="string"&&G.includes("type: preview")&&e.jsx("span",{className:"text-[10px] bg-amber-50 text-amber-700 border border-amber-200 px-1.5 py-0.5 rounded font-bold uppercase",children:"Preview Only"})]})]}),(u.knowledgeType||u.language||u.tags&&u.tags.length>0)&&e.jsxs("div",{className:"flex flex-wrap items-center gap-1.5 mb-2",children:[u.knowledgeType&&e.jsx("span",{className:"text-[9px] font-medium px-1.5 py-0.5 rounded bg-indigo-50 text-indigo-600 border border-indigo-100",children:u.knowledgeType}),u.language&&e.jsx("span",{className:"text-[9px] font-medium px-1.5 py-0.5 rounded bg-slate-100 text-slate-500 uppercase",children:u.language}),u.tags&&u.tags.length>0&&u.tags.slice(0,4).map((ye,Se)=>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(rs,{size:8}),ye]},Se)),u.tags&&u.tags.length>4&&e.jsxs("span",{className:"text-[9px] text-slate-400",children:["+",u.tags.length-4]})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2 mb-2 text-[10px] text-slate-500",children:[e.jsxs("span",{children:["权威 ",u.stats!=null?u.stats.authority:"—"]}),e.jsx("span",{children:"·"}),e.jsx("span",{children:u.stats!=null?`g:${u.stats.guardUsageCount} h:${u.stats.humanUsageCount} a:${u.stats.aiUsageCount}`:"g:0 h:0 a:0"}),e.jsx("span",{children:"·"}),e.jsxs("span",{children:["综合分 ",((Ie=u.stats)==null?void 0:Ie.authorityScore)!=null?u.stats.authorityScore.toFixed(2):"—"]}),e.jsx("span",{children:"·"}),e.jsxs("span",{children:["最近 ",xs((re=u.stats)==null?void 0:re.lastUsedAt)]})]}),e.jsx("div",{className:"text-xs text-slate-500 bg-slate-50 p-4 rounded-lg overflow-hidden line-clamp-4 font-mono whitespace-pre-wrap",children:C}),(u.relations||u.constraints)&&e.jsxs("div",{className:"flex flex-wrap items-center gap-2 mt-2",children:[u.relations&&Object.entries(u.relations).some(([,ye])=>Array.isArray(ye)&&ye.length>0)&&e.jsxs("span",{className:"text-[9px] font-medium px-1.5 py-0.5 rounded bg-purple-50 text-purple-600 border border-purple-100",children:["关系 ",Object.values(u.relations).flat().length]}),u.constraints&&(()=>{var Se,Be,Ae,He;const ye=(((Se=u.constraints.guards)==null?void 0:Se.length)||0)+(((Be=u.constraints.boundaries)==null?void 0:Be.length)||0)+(((Ae=u.constraints.preconditions)==null?void 0:Ae.length)||0)+(((He=u.constraints.sideEffects)==null?void 0:He.length)||0);return ye>0?e.jsxs("span",{className:"text-[9px] font-medium px-1.5 py-0.5 rounded bg-amber-50 text-amber-600 border border-amber-100",children:["约束 ",ye]}):null})()]})]},I)})})]}),t.length>0&&e.jsx(xa,{currentPage:f,totalPages:ke,totalItems:Ee.length,pageSize:k,onPageChange:Ve,onPageSizeChange:L}),K&&(()=>{var Se,Be,Ae,He,Qe,de;const u=K,I=et(u),G=ft(u),C=u.kind?ds[u.kind]:null,q=(C==null?void 0:C.icon)||Ct,ae=Rs[u.status||""]||null,ue=u.category||(typeof G=="string"?(Be=(Se=G.match(/category:\s*(.*)/))==null?void 0:Se[1])==null?void 0:Be.trim():null)||"Utility",oe=Xe[ue]||Xe.Utility,Ie=oe.icon,{metadata:re,body:ye}=Es(G);return e.jsxs(We,{className:"z-30 flex justify-end",onClick:()=>{Ne()},children:[e.jsx(We.Backdrop,{}),E&&(()=>{var N,D,W,O,pe;const j=E,he=et(j),Ce=ft(j),je=j.kind?ds[j.kind]:null,Te=(je==null?void 0:je.icon)||Ct,Me=j.category||(typeof Ce=="string"?(D=(N=Ce.match(/category:\s*(.*)/))==null?void 0:N[1])==null?void 0:D.trim():null)||"Utility",Pe=Xe[Me]||Xe.Utility,be=Pe.icon,{metadata:Ue,body:_e}=Es(Ce);return e.jsxs("div",{className:`relative h-full bg-white shadow-2xl flex flex-col border-r border-slate-200 ${U?"w-[720px] max-w-[50vw]":"w-[520px] max-w-[40vw]"}`,style:{animation:"slideInRight 0.2s ease-out"},onClick:le=>le.stopPropagation(),children:[e.jsxs("div",{className:"flex items-center justify-between px-5 py-3 border-b border-slate-200 bg-purple-50/50 shrink-0",children:[e.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[e.jsx(hs,{size:14,className:"text-purple-400 shrink-0"}),e.jsx("h3",{className:"font-bold text-slate-800 text-sm leading-snug break-words min-w-0",children:he.replace(/\.md$/i,"")})]}),e.jsx("button",{onClick:Ge,className:"p-1.5 hover:bg-slate-100 rounded-lg transition-colors shrink-0",title:"关闭",children:e.jsx(Ke,{size:14})})]}),e.jsxs("div",{className:"flex-1 overflow-y-auto",children:[e.jsxs("div",{className:"px-5 py-3 border-b border-slate-100 flex flex-wrap items-center gap-2",children:[je&&e.jsxs("span",{className:`text-[9px] font-bold px-2 py-0.5 rounded uppercase flex items-center gap-1 border ${je.bg} ${je.color} ${je.border}`,children:[e.jsx(Te,{size:z.xs}),je.label]}),e.jsxs("span",{className:`text-[9px] font-bold px-2 py-0.5 rounded uppercase flex items-center gap-1 border ${Pe.bg} ${Pe.color} ${Pe.border}`,children:[e.jsx(be,{size:z.xs}),Me]}),j.language&&e.jsx("span",{className:"text-[9px] font-medium px-2 py-0.5 rounded bg-slate-100 text-slate-500 uppercase",children:j.language}),j.knowledgeType&&e.jsx("span",{className:"text-[9px] font-medium px-2 py-0.5 rounded bg-indigo-50 text-indigo-600 border border-indigo-100",children:j.knowledgeType})]}),j.tags&&j.tags.length>0&&e.jsx("div",{className:"px-5 py-2.5 border-b border-slate-100 flex flex-wrap items-center gap-1.5",children:j.tags.map((le,xe)=>e.jsxs("span",{className:"text-[9px] px-2 py-0.5 rounded bg-blue-50 text-blue-600 border border-blue-100 flex items-center gap-0.5",children:[e.jsx(rs,{size:8}),le]},xe))}),e.jsx("div",{className:"px-5 py-3 border-b border-slate-100",children:e.jsxs("div",{className:"grid grid-cols-4 gap-2",children:[e.jsxs("div",{className:"bg-slate-50 rounded-lg p-2 text-center",children:[e.jsx("div",{className:"text-sm font-bold text-slate-800",children:((W=j.stats)==null?void 0:W.authority)??"—"}),e.jsx("div",{className:"text-[8px] text-slate-400 font-medium",children:"权威"})]}),e.jsxs("div",{className:"bg-slate-50 rounded-lg p-2 text-center",children:[e.jsx("div",{className:"text-sm font-bold text-slate-800",children:((O=j.stats)==null?void 0:O.authorityScore)!=null?j.stats.authorityScore.toFixed(1):"—"}),e.jsx("div",{className:"text-[8px] text-slate-400 font-medium",children:"综合分"})]}),e.jsxs("div",{className:"bg-slate-50 rounded-lg p-2 text-center",children:[e.jsx("div",{className:"text-sm font-bold text-slate-800",children:j.stats!=null?j.stats.guardUsageCount+j.stats.humanUsageCount+j.stats.aiUsageCount:0}),e.jsx("div",{className:"text-[8px] text-slate-400 font-medium",children:"总使用"})]}),e.jsxs("div",{className:"bg-slate-50 rounded-lg p-2 text-center",children:[e.jsx("div",{className:"text-[10px] font-bold text-slate-800",children:xs((pe=j.stats)==null?void 0:pe.lastUsedAt)}),e.jsx("div",{className:"text-[8px] text-slate-400 font-medium",children:"最近使用"})]})]})}),j.description&&e.jsxs("div",{className:"px-5 py-3 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-xs text-slate-600 leading-relaxed",children:j.description})]}),Object.keys(Ue).length>0&&e.jsxs("div",{className:"px-5 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:"grid grid-cols-2 gap-y-2 gap-x-4",children:Object.entries(Ue).filter(([le])=>!["tags","headers","summary_cn","summary_en","summary"].includes(le)).map(([le,xe])=>{let ce=xe;if(le==="updatedAt"||le==="createdAt"){const ge=parseInt(xe,10);!isNaN(ge)&&ge>9466848e5&&(ce=new Date(ge).toLocaleString("zh-CN",{year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit"}))}return e.jsxs("div",{className:"flex flex-col",children:[e.jsx("span",{className:"text-[9px] text-slate-400 font-bold uppercase",children:le}),e.jsx("span",{className:"text-[10px] text-slate-700 break-all font-medium",children:ce})]},le)})})]}),e.jsxs("div",{className:"px-5 py-4",children:[e.jsx("label",{className:"text-[10px] font-bold text-slate-400 uppercase mb-2 block",children:"内容"}),_e?e.jsx("div",{className:"markdown-body text-slate-700 text-xs",children:e.jsx(lt,{content:_e,showLineNumbers:!0})}):e.jsx("div",{className:"text-xs text-slate-300 italic py-6 text-center",children:"暂无正文内容"})]})]}),e.jsxs("div",{className:"px-4 py-2 border-t border-slate-200 flex items-center justify-between shrink-0 bg-slate-50",children:[e.jsx("span",{className:"text-[10px] text-slate-400",children:"关联 Recipe 预览"}),e.jsxs("button",{onClick:()=>{ie(j)},className:"text-[10px] px-3 py-1 bg-blue-600 text-white rounded font-bold hover:bg-blue-700 flex items-center gap-1",children:[e.jsx($t,{size:10})," 打开完整视图"]})]})]})})(),e.jsxs("div",{className:`relative h-full bg-white shadow-2xl flex flex-col ${U?"w-[min(92vw,1100px)]":"w-[min(92vw,800px)]"}`,style:{animation:"slideInRight 0.25s ease-out"},onClick:j=>j.stopPropagation(),children:[e.jsxs("div",{className:"flex items-center justify-between px-5 py-3 border-b border-slate-200 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:I})}),e.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[e.jsx("button",{onClick:J,disabled:g<=0,className:"p-1.5 hover:bg-slate-100 rounded-lg transition-colors disabled:opacity-30 disabled:cursor-not-allowed",title:"上一条",children:e.jsx(fs,{size:z.md})}),e.jsxs("span",{className:"text-xs text-slate-400 tabular-nums",children:[g+1,"/",t.length]}),e.jsx("button",{onClick:Z,disabled:g>=t.length-1,className:"p-1.5 hover:bg-slate-100 rounded-lg transition-colors disabled:opacity-30 disabled:cursor-not-allowed",title:"下一条",children:e.jsx(it,{size:z.md})}),e.jsx("div",{className:"w-px h-5 bg-slate-200 mx-1"}),e.jsxs("div",{className:"flex bg-slate-100 p-0.5 rounded-lg mr-1",children:[e.jsxs("button",{onClick:()=>M("view"),className:`px-2.5 py-1 rounded-md text-xs font-bold transition-all flex items-center gap-1 ${R==="view"?"bg-white shadow-sm text-blue-600":"text-slate-400 hover:text-slate-600"}`,children:[e.jsx($t,{size:z.sm})," 预览"]}),e.jsxs("button",{onClick:()=>{M("edit"),_(ft(u))},className:`px-2.5 py-1 rounded-md text-xs font-bold transition-all flex items-center gap-1 ${R==="edit"?"bg-white shadow-sm text-blue-600":"text-slate-400 hover:text-slate-600"}`,children:[e.jsx(mt,{size:z.sm})," 编辑"]})]}),e.jsx("button",{onClick:B,className:"p-1.5 hover:bg-slate-100 rounded-lg transition-colors text-slate-400",title:U?"收窄面板":"展开更宽",children:U?e.jsx(qs,{size:z.md}):e.jsx(js,{size:z.md})}),e.jsx("button",{onClick:()=>{s(u.name||u.id),Ne()},className:"p-1.5 hover:bg-red-50 rounded-lg text-red-500 transition-colors",title:"删除",children:e.jsx(ht,{size:z.md})}),e.jsx("button",{onClick:Ne,className:"p-1.5 hover:bg-slate-100 rounded-lg transition-colors",children:e.jsx(Ke,{size:z.md})})]})]}),R==="edit"?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex-1 flex flex-col min-h-0 p-4",children:[e.jsx("label",{className:"text-[10px] font-bold text-slate-400 uppercase mb-2 block",children:"Markdown 内容"}),e.jsx("div",{className:"flex-1 min-h-0",children:e.jsx(ls,{value:H,onChange:_,language:"markdown",height:"100%",showLineNumbers:!0})})]}),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.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:((Ae=u.stats)==null?void 0:Ae.authority)??3,onChange:j=>fe(parseInt(j.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.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{onClick:()=>M("view"),disabled:P,className:"px-4 py-1.5 text-sm text-slate-600 font-medium rounded-lg hover:bg-slate-50",children:"取消"}),e.jsxs("button",{onClick:Re,disabled:P,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:[P?e.jsx(ze,{size:z.sm,className:"animate-spin"}):e.jsx(as,{size:z.sm}),P?"保存中...":"保存"]})]})]})]}):e.jsxs("div",{className:"flex-1 overflow-y-auto",children:[e.jsxs("div",{className:"px-5 py-3 border-b border-slate-100 flex flex-wrap items-center gap-2",children:[C&&e.jsxs("span",{className:`text-[9px] font-bold px-2 py-0.5 rounded uppercase flex items-center gap-1 border ${C.bg} ${C.color} ${C.border}`,children:[e.jsx(q,{size:z.xs}),C.label]}),e.jsxs("span",{className:`text-[9px] font-bold px-2 py-0.5 rounded uppercase flex items-center gap-1 border ${oe.bg} ${oe.color} ${oe.border}`,children:[e.jsx(Ie,{size:z.xs}),ue]}),ae&&e.jsx("span",{className:`text-[9px] font-bold px-2 py-0.5 rounded uppercase border ${ae.bg} ${ae.color} ${ae.border}`,children:u.status}),u.knowledgeType&&e.jsx("span",{className:"text-[9px] font-medium px-2 py-0.5 rounded bg-indigo-50 text-indigo-600 border border-indigo-100",children:u.knowledgeType}),u.language&&e.jsx("span",{className:"text-[9px] font-medium px-2 py-0.5 rounded bg-slate-100 text-slate-500 uppercase",children:u.language}),u.trigger&&e.jsx("span",{className:"text-[9px] font-mono font-bold px-2 py-0.5 rounded bg-blue-50 text-blue-600 border border-blue-100",children:u.trigger})]}),u.tags&&u.tags.length>0&&e.jsx("div",{className:"px-5 py-2.5 border-b border-slate-100 flex flex-wrap items-center gap-1.5",children:u.tags.map((j,he)=>e.jsxs("span",{className:"text-[9px] px-2 py-0.5 rounded bg-blue-50 text-blue-600 border border-blue-100 flex items-center gap-0.5",children:[e.jsx(rs,{size:8}),j]},he))}),e.jsxs("div",{className:"px-5 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-slate-50 rounded-lg p-3 text-center",children:[e.jsx("div",{className:"text-lg font-bold text-slate-800",children:((He=u.stats)==null?void 0:He.authority)??"—"}),e.jsx("div",{className:"text-[10px] text-slate-400 font-medium",children:"权威"})]}),e.jsxs("div",{className:"bg-slate-50 rounded-lg p-3 text-center",children:[e.jsx("div",{className:"text-lg font-bold text-slate-800",children:((Qe=u.stats)==null?void 0:Qe.authorityScore)!=null?u.stats.authorityScore.toFixed(1):"—"}),e.jsx("div",{className:"text-[10px] text-slate-400 font-medium",children:"综合分"})]}),e.jsxs("div",{className:"bg-slate-50 rounded-lg p-3 text-center",children:[e.jsx("div",{className:"text-lg font-bold text-slate-800",children:u.stats!=null?u.stats.guardUsageCount+u.stats.humanUsageCount+u.stats.aiUsageCount:0}),e.jsx("div",{className:"text-[10px] text-slate-400 font-medium",children:"总使用"})]}),e.jsxs("div",{className:"bg-slate-50 rounded-lg p-3 text-center",children:[e.jsx("div",{className:"text-sm font-bold text-slate-800",children:xs((de=u.stats)==null?void 0:de.lastUsedAt)}),e.jsx("div",{className:"text-[10px] text-slate-400 font-medium",children:"最近使用"})]})]}),u.stats!=null&&e.jsxs("div",{className:"flex items-center gap-4 mt-2 text-[10px] text-slate-400",children:[e.jsxs("span",{children:["Guard: ",u.stats.guardUsageCount]}),e.jsxs("span",{children:["Human: ",u.stats.humanUsageCount]}),e.jsxs("span",{children:["AI: ",u.stats.aiUsageCount]})]})]}),Object.keys(re).length>0&&e.jsxs("div",{className:"px-5 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:"grid grid-cols-2 sm:grid-cols-3 gap-y-2.5 gap-x-6",children:Object.entries(re).filter(([j])=>!["tags","headers","summary_cn","summary_en","summary","usageGuide","usageGuide_cn","usageGuide_en"].includes(j)).map(([j,he])=>{let Ce=he;if(j==="updatedAt"||j==="createdAt"){const je=parseInt(he,10);!isNaN(je)&&je>9466848e5&&(Ce=new Date(je).toLocaleString("zh-CN",{year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit"}))}return e.jsxs("div",{className:"flex flex-col",children:[e.jsx("span",{className:"text-[9px] text-slate-400 font-bold uppercase",children:j}),e.jsx("span",{className:"text-xs text-slate-700 break-all font-medium",children:Ce})]},j)})}),re.headers&&e.jsxs("div",{className:"mt-2.5",children:[e.jsx("span",{className:"text-[9px] text-slate-400 font-bold uppercase block mb-1",children:"Headers"}),e.jsx("div",{className:"flex flex-wrap gap-1.5",children:(()=>{try{const j=JSON.parse(re.headers);return(Array.isArray(j)?j:[re.headers]).map((he,Ce)=>e.jsx("code",{className:"px-2 py-0.5 bg-violet-50 text-violet-700 border border-violet-100 rounded text-[10px] font-mono",children:he},Ce))}catch{return e.jsx("code",{className:"text-xs text-slate-700 font-mono",children:re.headers})}})()})]}),(re.summary_cn||re.summary)&&e.jsxs("div",{className:"mt-2.5",children:[e.jsx("span",{className:"text-[9px] text-slate-400 font-bold uppercase block mb-1",children:"摘要"}),e.jsx("p",{className:"text-xs text-slate-600 leading-relaxed",children:re.summary_cn||re.summary})]}),re.summary_en&&e.jsxs("div",{className:"mt-2",children:[e.jsx("span",{className:"text-[9px] text-slate-400 font-bold uppercase block mb-1",children:"Summary (EN)"}),e.jsx("p",{className:"text-xs text-slate-600 leading-relaxed",children:re.summary_en})]})]}),e.jsxs("div",{className:"px-5 py-3 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(hs,{size:12,className:"text-purple-400"}),e.jsx("label",{className:"text-[10px] font-bold text-slate-400 uppercase",children:"关联 Recipes"}),(()=>{const j=u.relations?Object.values(u.relations).flat().length:0;return j>0?e.jsx("span",{className:"text-[9px] bg-purple-100 text-purple-600 px-1.5 py-0.5 rounded-full font-bold",children:j}):null})()]}),e.jsx("button",{onClick:()=>{V(!h),Y("")},className:`text-[9px] px-2 py-0.5 rounded font-bold flex items-center gap-1 transition-colors ${h?"bg-slate-200 text-slate-600 hover:bg-slate-300":"bg-purple-500 text-white hover:bg-purple-600"}`,children:h?e.jsxs(e.Fragment,{children:[e.jsx(Ke,{size:10})," 取消"]}):e.jsxs(e.Fragment,{children:[e.jsx(ut,{size:10})," 添加关联"]})})]}),h&&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:me,onChange:j=>F(j.target.value),className:"text-[10px] font-bold bg-white border border-purple-200 text-purple-700 rounded px-2 py-1 outline-none focus:ring-1 focus:ring-purple-400",children:Q.map(j=>e.jsxs("option",{value:j.key,children:[j.icon," ",j.label]},j.key))}),e.jsxs("div",{className:"flex-1 relative",children:[e.jsx(pt,{size:12,className:"absolute left-2 top-1/2 -translate-y-1/2 text-slate-300"}),e.jsx("input",{type:"text",placeholder:"搜索 Recipe 名称...",value:X,onChange:j=>Y(j.target.value),className:"w-full text-xs bg-white border border-purple-200 rounded pl-7 pr-2 py-1 outline-none focus:ring-1 focus:ring-purple-400",autoFocus:!0})]})]}),X.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 j=t.filter(he=>et(he)===I?!1:et(he).toLowerCase().includes(X.toLowerCase())).slice(0,10);return j.length===0?e.jsx("div",{className:"text-xs text-slate-400 py-3 text-center",children:"未找到匹配的 Recipe"}):j.map(he=>{const Ce=et(he),je=u.relations&&Object.values(u.relations).flat().some(Te=>(typeof Te=="string"?Te:Te.id||Te.title||"").replace(/\.md$/i,"").toLowerCase()===Ce.replace(/\.md$/i,"").toLowerCase());return e.jsxs("div",{className:`flex items-center justify-between px-3 py-1.5 text-xs transition-colors ${je?"bg-slate-50 text-slate-400":"hover:bg-purple-50 cursor-pointer"}`,onClick:()=>!je&&we(me,Ce),children:[e.jsx("span",{className:"font-medium truncate mr-2",children:Ce.replace(/\.md$/i,"")}),je?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:"+ 添加"})]},Ce)})})()})]}),u.relations&&Object.entries(u.relations).some(([,j])=>Array.isArray(j)&&j.length>0)?e.jsx("div",{className:"space-y-1.5",children:Q.map(({key:j,label:he,icon:Ce})=>{var Te;const je=(Te=u.relations)==null?void 0:Te[j];return!je||!Array.isArray(je)||je.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:[Ce," ",he]}),e.jsx("div",{className:"flex flex-wrap gap-1",children:je.map((Me,Pe)=>{const be=typeof Me=="string"?Me:Me.id||Me.title||JSON.stringify(Me),Ue=!!ve(be);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 ${Ue?"bg-purple-50 border-purple-200 text-purple-700 cursor-pointer hover:bg-purple-100 hover:border-purple-300":"bg-white border-slate-200 text-slate-600"}`,onClick:()=>Ue&&Le(be),title:Ue?"点击查看详情":be,children:[be.replace(/\.md$/i,""),e.jsx("button",{onClick:_e=>{_e.stopPropagation(),Fe(j,be)},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})})]},Pe)})})]},j)})}):!h&&e.jsx("div",{className:"text-xs text-slate-300 py-2 text-center",children:"暂无关联,点击上方按钮添加"})]}),u.constraints&&(()=>{var Ce,je,Te,Me,Pe,be,Ue,_e;const j=u.constraints;return(((Ce=j.guards)==null?void 0:Ce.length)||0)+(((je=j.boundaries)==null?void 0:je.length)||0)+(((Te=j.preconditions)==null?void 0:Te.length)||0)+(((Me=j.sideEffects)==null?void 0:Me.length)||0)>0?e.jsxs("div",{className:"px-5 py-3 border-b border-slate-100",children:[e.jsx("label",{className:"text-[10px] font-bold text-slate-400 uppercase mb-1.5 block",children:"约束条件"}),e.jsxs("div",{className:"space-y-1.5 text-xs text-slate-600",children:[(Pe=j.guards)==null?void 0:Pe.map((N,D)=>e.jsxs("div",{className:"flex gap-1.5 items-start",children:[e.jsx("span",{className:`text-xs mt-0.5 ${N.severity==="error"?"text-red-500":"text-yellow-500"}`,children:"●"}),e.jsx("code",{className:"font-mono text-[10px] bg-slate-100 px-1 py-0.5 rounded",children:N.pattern}),N.message&&e.jsxs("span",{className:"text-[10px] text-slate-400",children:["— ",N.message]})]},D)),(be=j.boundaries)==null?void 0:be.map((N,D)=>e.jsxs("div",{className:"flex gap-1.5",children:[e.jsx("span",{className:"text-orange-400",children:"●"}),N]},D)),(Ue=j.preconditions)==null?void 0:Ue.map((N,D)=>e.jsxs("div",{className:"flex gap-1.5",children:[e.jsx("span",{className:"text-blue-400",children:"◆"}),N]},D)),(_e=j.sideEffects)==null?void 0:_e.map((N,D)=>e.jsxs("div",{className:"flex gap-1.5",children:[e.jsx("span",{className:"text-pink-400",children:"⚡"}),N]},D))]})]}):null})(),u.description&&u.description!==(re.summary_cn||re.summary||"")&&e.jsxs("div",{className:"px-5 py-3 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:u.description})]}),(u.usageGuide||u.usageGuide_cn||re.usageGuide||re.usageGuide_cn||re.usageGuide_en)&&e.jsxs("div",{className:"px-5 py-3 border-b border-slate-100",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-blue-400"})," 使用指南"]}),e.jsx("div",{className:"markdown-body text-sm text-slate-600",children:e.jsx(lt,{content:u.usageGuide||u.usageGuide_cn||re.usageGuide||re.usageGuide_cn||""})}),(u.usageGuide_en||re.usageGuide_en)&&e.jsxs("div",{className:"mt-2 pt-2 border-t border-slate-100",children:[e.jsx("span",{className:"text-[9px] text-slate-400 font-bold uppercase block mb-1",children:"Usage Guide (EN)"}),e.jsx("div",{className:"markdown-body text-sm text-slate-500",children:e.jsx(lt,{content:u.usageGuide_en||re.usageGuide_en||""})})]})]}),u.v2Content&&(()=>{const j=u.v2Content,he=j.pattern&&ye&&ye.includes(j.pattern.trim());return j.rationale||j.pattern&&!he||j.steps&&j.steps.length>0||j.codeChanges&&j.codeChanges.length>0||j.verification?e.jsxs("div",{className:"px-5 py-3 border-b border-slate-100 space-y-3",children:[j.rationale&&e.jsxs("div",{children:[e.jsx("label",{className:"text-[10px] font-bold text-slate-400 uppercase mb-1 block",children:"设计原理"}),e.jsx("p",{className:"text-sm text-slate-600 leading-relaxed",children:j.rationale})]}),j.pattern&&!he&&e.jsxs("div",{children:[e.jsx("label",{className:"text-[10px] font-bold text-slate-400 uppercase mb-1 block",children:"模式"}),e.jsx("div",{className:"markdown-body text-sm text-slate-600",children:e.jsx(lt,{content:j.pattern,showLineNumbers:!0})})]}),j.steps&&j.steps.length>0&&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:"space-y-2",children:j.steps.map((je,Te)=>{if(typeof je=="string")return e.jsx("div",{className:"bg-slate-50 rounded-lg p-3 border border-slate-100",children:e.jsxs("div",{className:"flex items-start gap-2",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",children:je})]})},Te);const Me=typeof je.title=="string"?je.title:"",Pe=typeof je.description=="string"?je.description:"",be=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:Te+1}),Me&&e.jsx("span",{className:"text-xs font-bold text-slate-700",children:Me})]}),Pe&&e.jsx("p",{className:"text-xs text-slate-600 ml-7",children:Pe}),be&&e.jsx("pre",{className:"text-[11px] font-mono bg-slate-800 text-green-300 p-2 rounded mt-1 ml-7 overflow-x-auto whitespace-pre-wrap",children:be})]},Te)})})]}),j.codeChanges&&j.codeChanges.length>0&&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:"space-y-2",children:j.codeChanges.map((je,Te)=>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(Js,{size:11,className:"text-blue-400"}),e.jsx("code",{className:"text-[10px] font-mono text-slate-600",children:je.file})]}),je.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:je.explanation}),e.jsxs("div",{className:"p-2 bg-red-50/30 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:je.before||"(空)"})]}),e.jsxs("div",{className:"p-2 bg-emerald-50/30",children:[e.jsx("div",{className:"text-[9px] font-bold text-emerald-500 mb-0.5 uppercase",children:"After"}),e.jsx("pre",{className:"text-[11px] text-slate-700 whitespace-pre-wrap break-words font-mono",children:je.after})]})]},Te))})]}),j.verification&&e.jsxs("div",{children:[e.jsx("label",{className:"text-[10px] font-bold text-slate-400 uppercase mb-1 block",children:"验证方法"}),e.jsxs("div",{className:"bg-teal-50/50 border border-teal-100 rounded-lg p-3 space-y-1.5",children:[j.verification.method&&e.jsxs("p",{className:"text-xs text-slate-600",children:[e.jsx("span",{className:"font-bold text-teal-600",children:"方法:"})," ",j.verification.method]}),j.verification.expectedResult&&e.jsxs("p",{className:"text-xs text-slate-600",children:[e.jsx("span",{className:"font-bold text-teal-600",children:"预期结果:"})," ",j.verification.expectedResult]}),j.verification.testCode&&e.jsx("pre",{className:"text-[11px] font-mono bg-slate-800 text-green-300 p-2 rounded overflow-x-auto whitespace-pre-wrap mt-1",children:j.verification.testCode})]})]})]}):null})(),e.jsxs("div",{className:"px-5 py-4",children:[e.jsx("label",{className:"text-[10px] font-bold text-slate-400 uppercase mb-2 block",children:"内容"}),ye?e.jsx("div",{className:"markdown-body text-slate-700",children:e.jsx(lt,{content:ye,showLineNumbers:!0})}):e.jsx("div",{className:"text-sm text-slate-300 italic py-8 text-center",children:"暂无正文内容"})]})]})]})]})})()]})},Yl=()=>{const[t,s]=r.useState(new Set(["quick-start"])),a=n=>{const o=new Set(t);o.has(n)?o.delete(n):o.add(n),s(o)},l=({id:n,title:o,icon:c,children:i})=>{const x=t.has(n);return e.jsxs("section",{className:"border border-slate-200 rounded-lg overflow-hidden",children:[e.jsxs("button",{onClick:()=>a(n),className:"w-full flex items-center justify-between p-4 bg-slate-50 hover:bg-slate-100 transition-colors",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[c,e.jsx("h2",{className:"text-lg font-bold text-slate-800",children:o})]}),x?e.jsx(kt,{size:z.lg}):e.jsx(it,{size:z.lg})]}),x&&e.jsx("div",{className:"p-4 bg-white",children:i})]})};return e.jsxs("div",{className:"max-w-5xl mx-auto py-8 px-4",children:[e.jsxs("div",{className:"mb-8 text-center",children:[e.jsxs("h1",{className:"text-4xl font-bold text-slate-900 mb-4 flex items-center justify-center gap-3",children:[e.jsx(at,{size:z.xxl,className:"text-blue-600"}),"AutoSnippet V2 使用说明"]}),e.jsx("p",{className:"text-slate-600 text-lg max-w-3xl mx-auto whitespace-nowrap",children:"连接开发者、AI 与项目知识库:ChatAgent 智能对话 · Skills 开放平台 · 知识库持续生长"}),e.jsx("p",{className:"text-slate-400 text-sm mt-2",children:"Node.js ≥ 20 · 13 Skills · AI 可自建 · 38 MCP 工具 · ChatAgent 对话 · 4 层检索管线"}),e.jsxs("div",{className:"mt-6 flex gap-4 justify-center text-sm",children:[e.jsx("a",{href:"https://github.com/GxFn/AutoSnippet",target:"_blank",rel:"noopener noreferrer",className:"px-4 py-2 bg-blue-600 text-white rounded-lg hover:bg-blue-700 transition-colors",children:"查看 GitHub"}),e.jsx("a",{href:"https://github.com/GxFn/AutoSnippet/blob/main/README.md",target:"_blank",rel:"noopener noreferrer",className:"px-4 py-2 border border-slate-300 text-slate-700 rounded-lg hover:bg-slate-50 transition-colors",children:"完整文档"})]})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsx(l,{id:"quick-start",title:"快速开始",icon:e.jsx(Tt,{size:z.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",`
|
|
92
92
|
`,"cd your-project",`
|
|
93
|
-
`,"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(Bs,{size:_.xl,className:"text-blue-600"}),children:[e.jsxs("div",{className:"mb-6",children:[e.jsx("h3",{className:"text-lg font-semibold text-slate-700 mb-3",children:"三大角色"}),e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"min-w-full border border-slate-200 rounded-lg text-sm",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"bg-slate-50",children:[e.jsx("th",{className:"px-4 py-3 border-b text-left font-semibold",children:"角色"}),e.jsx("th",{className:"px-4 py-3 border-b text-left font-semibold",children:"职责"}),e.jsx("th",{className:"px-4 py-3 border-b text-left font-semibold",children:"能力"})]})}),e.jsxs("tbody",{children:[e.jsxs("tr",{className:"hover:bg-slate-50",children:[e.jsx("td",{className:"px-4 py-3 border-b font-medium text-blue-700",children:"开发者"}),e.jsx("td",{className:"px-4 py-3 border-b",children:"审核与决策、维护项目标准"}),e.jsxs("td",{className:"px-4 py-3 border-b text-xs",children:["Dashboard 审核候选、保存 Recipe;Snippet 补全、",e.jsx("code",{className:"bg-slate-100 px-1 rounded",children:"// as:search"}),";运行 ",e.jsx("code",{className:"bg-slate-100 px-1 rounded",children:"asd ui"})]})]}),e.jsxs("tr",{className:"hover:bg-slate-50",children:[e.jsx("td",{className:"px-4 py-3 border-b font-medium text-green-700",children:"Cursor Agent"}),e.jsx("td",{className:"px-4 py-3 border-b",children:"按规范生成代码、检索知识库"}),e.jsx("td",{className:"px-4 py-3 border-b text-xs",children:"13 个 Skills 理解规范;36 个 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:"项目内 AI"}),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-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(Js,{size:_.lg}),"Recipe(配方)"]}),e.jsx("p",{className:"text-blue-800 text-sm mb-3",children:"Markdown 知识文档(Source of Truth)"}),e.jsxs("ul",{className:"text-blue-700 text-xs space-y-1 list-disc list-inside",children:[e.jsxs("li",{children:["位置:",e.jsx("code",{className:"bg-blue-100 px-1 rounded",children:"AutoSnippet/recipes/*.md"})]}),e.jsx("li",{children:".md 文件 = 唯一数据源,DB 仅作索引缓存"}),e.jsxs("li",{children:[e.jsx("code",{className:"bg-blue-100 px-1 rounded",children:"asd sync"})," 增量同步 .md → DB"]})]})]}),e.jsxs("div",{className:"bg-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(st,{size:_.lg}),"Bootstrap(冷启动)"]}),e.jsx("p",{className:"text-green-800 text-sm mb-3",children:"9 维度自动知识提取引擎"}),e.jsxs("ul",{className:"text-green-700 text-xs space-y-1 list-disc list-inside",children:[e.jsx("li",{children:"扫描 SPM Target + AST 分析源码"}),e.jsx("li",{children:"启发式提取 → AI 精炼 → 生成 Candidate"}),e.jsxs("li",{children:["MCP 工具:",e.jsx("code",{className:"bg-green-100 px-1 rounded",children:"bootstrap_knowledge"})," / ",e.jsx("code",{className:"bg-green-100 px-1 rounded",children:"bootstrap_refine"})]})]})]}),e.jsxs("div",{className:"bg-purple-50 rounded-lg p-4 border border-purple-200",children:[e.jsxs("h4",{className:"font-semibold text-purple-900 mb-2 flex items-center gap-2",children:[e.jsx(Fa,{size:_.lg}),"Candidates(候选)"]}),e.jsx("p",{className:"text-purple-800 text-sm mb-3",children:"待审核的 Recipe 草案"}),e.jsxs("ul",{className:"text-purple-700 text-xs space-y-1 list-disc list-inside",children:[e.jsx("li",{children:"来源:AI 扫描、Cursor、剪贴板、Dashboard"}),e.jsx("li",{children:"审核后入库为 Recipe,确保质量"}),e.jsx("li",{children:"Reasoning 字段记录 AI 推理过程"})]})]}),e.jsxs("div",{className:"bg-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(ws,{size:_.lg}),"Dual-Agent(智能对话)"]}),e.jsx("p",{className:"text-indigo-800 text-sm mb-3",children:"Analyst + Producer 双代理架构"}),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(pt,{size:_.lg}),"4 层检索管线"]}),e.jsx("p",{className:"text-amber-800 text-sm mb-3",children:"多模式语义搜索引擎"}),e.jsxs("ul",{className:"text-amber-700 text-xs space-y-1 list-disc list-inside",children:[e.jsx("li",{children:"InvertedIndex → CoarseRanker → MultiSignalRanker → RetrievalFunnel"}),e.jsx("li",{children:"BM25 + keyword + semantic 三路融合"}),e.jsx("li",{children:"4 个搜索 MCP 工具:search / context / keyword / semantic"})]})]}),e.jsxs("div",{className:"bg-rose-50 rounded-lg p-4 border border-rose-200",children:[e.jsxs("h4",{className:"font-semibold text-rose-900 mb-2 flex items-center gap-2",children:[e.jsx(bt,{size:_.lg}),"Guard(代码审查)"]}),e.jsx("p",{className:"text-rose-800 text-sm mb-3",children:"知识库驱动的代码审查"}),e.jsxs("ul",{className:"text-rose-700 text-xs space-y-1 list-disc list-inside",children:[e.jsx("li",{children:"内建规则 + 自定义规则 + Recipe 关联"}),e.jsxs("li",{children:[e.jsx("code",{className:"bg-rose-100 px-1 rounded",children:"// as:audit"})," 触发 / ",e.jsx("code",{className:"bg-rose-100 px-1 rounded",children:"asd guard <file>"})]}),e.jsxs("li",{children:["MCP:",e.jsx("code",{className:"bg-rose-100 px-1 rounded",children:"guard_check"})," / ",e.jsx("code",{className:"bg-rose-100 px-1 rounded",children:"guard_audit_files"})," / ",e.jsx("code",{className:"bg-rose-100 px-1 rounded",children:"scan_project"})]})]})]})]})]}),e.jsxs("div",{className:"mt-6 bg-gradient-to-r from-blue-50 to-purple-50 rounded-lg p-5 border border-slate-200",children:[e.jsx("h3",{className:"text-lg font-semibold text-slate-700 mb-4",children:"知识库闭环"}),e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[e.jsxs("div",{className:"flex-1 min-w-[100px] text-center",children:[e.jsx("div",{className:"bg-blue-500 text-white rounded-full w-10 h-10 flex items-center justify-center mx-auto mb-2 font-bold text-lg",children:"1"}),e.jsx("p",{className:"text-slate-700 font-medium text-sm",children:"扫描提取"}),e.jsx("p",{className:"text-slate-500 text-xs",children:"AI/Cursor"})]}),e.jsx("div",{className:"text-slate-400 text-2xl",children:"→"}),e.jsxs("div",{className:"flex-1 min-w-[100px] text-center",children:[e.jsx("div",{className:"bg-green-500 text-white rounded-full w-10 h-10 flex items-center justify-center mx-auto mb-2 font-bold text-lg",children:"2"}),e.jsx("p",{className:"text-slate-700 font-medium text-sm",children:"人工审核"}),e.jsx("p",{className:"text-slate-500 text-xs",children:"Dashboard"})]}),e.jsx("div",{className:"text-slate-400 text-2xl",children:"→"}),e.jsxs("div",{className:"flex-1 min-w-[100px] text-center",children:[e.jsx("div",{className:"bg-purple-500 text-white rounded-full w-10 h-10 flex items-center justify-center mx-auto mb-2 font-bold text-lg",children:"3"}),e.jsx("p",{className:"text-slate-700 font-medium text-sm",children:"知识沉淀"}),e.jsx("p",{className:"text-slate-500 text-xs",children:".md 落盘"})]}),e.jsx("div",{className:"text-slate-400 text-2xl",children:"→"}),e.jsxs("div",{className:"flex-1 min-w-[100px] text-center",children:[e.jsx("div",{className:"bg-amber-500 text-white rounded-full w-10 h-10 flex items-center justify-center mx-auto mb-2 font-bold text-lg",children:"4"}),e.jsx("p",{className:"text-slate-700 font-medium text-sm",children:"智能使用"}),e.jsx("p",{className:"text-slate-500 text-xs",children:"Cursor/Xcode"})]}),e.jsx("div",{className:"text-slate-400 text-2xl",children:"→"}),e.jsxs("div",{className:"flex-1 min-w-[100px] text-center",children:[e.jsx("div",{className:"bg-rose-500 text-white rounded-full w-10 h-10 flex items-center justify-center mx-auto mb-2 font-bold text-lg",children:"5"}),e.jsx("p",{className:"text-slate-700 font-medium text-sm",children:"持续优化"}),e.jsx("p",{className:"text-slate-500 text-xs",children:"asd sync"})]})]})]})]}),e.jsx(l,{id:"features",title:"核心功能",icon:e.jsx(st,{size:_.xl,className:"text-blue-600"}),children:e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-5",children:[e.jsxs("div",{className:"border border-slate-200 rounded-lg p-5 hover:shadow-lg transition-shadow",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[e.jsx(ss,{size:_.lg,className:"text-blue-600"}),e.jsx("h3",{className:"font-semibold text-slate-800",children:"知识库构建"})]}),e.jsxs("ul",{className:"text-slate-600 text-sm space-y-2 list-disc list-inside",children:[e.jsxs("li",{children:[e.jsx("strong",{children:"AI 扫描"}),":",e.jsx("code",{className:"bg-slate-100 px-1 rounded text-xs",children:"asd ais [Target]"})," 批量提取"]}),e.jsxs("li",{children:[e.jsx("strong",{children:"Cursor 扫描"}),':对 Copilot 说 "扫描 Module"']}),e.jsxs("li",{children:[e.jsx("strong",{children:"手动创建"}),":New Recipe → Use Copied Code"]}),e.jsxs("li",{children:[e.jsx("strong",{children:"编辑器内"}),":复制代码 → ",e.jsx("code",{className:"bg-slate-100 px-1 rounded text-xs",children:"// as:create -c"})]})]})]}),e.jsxs("div",{className:"border border-slate-200 rounded-lg p-5 hover:shadow-lg transition-shadow",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[e.jsx(pt,{size:_.lg,className:"text-blue-600"}),e.jsx("h3",{className:"font-semibold text-slate-800",children:"语义检索"})]}),e.jsxs("ul",{className:"text-slate-600 text-sm space-y-2 list-disc list-inside",children:[e.jsxs("li",{children:[e.jsx("strong",{children:"4 层管线"}),":InvertedIndex → CoarseRanker → MultiSignalRanker → RetrievalFunnel"]}),e.jsxs("li",{children:[e.jsx("strong",{children:"编辑器内"}),":",e.jsx("code",{className:"bg-slate-100 px-1 rounded text-xs",children:"// as:search keyword"})]}),e.jsxs("li",{children:[e.jsx("strong",{children:"Cursor MCP"}),":4 个搜索工具(search / context / keyword / semantic)"]}),e.jsxs("li",{children:[e.jsx("strong",{children:"Dashboard"}),":搜索框支持语义 + 关键词"]})]})]}),e.jsxs("div",{className:"border border-slate-200 rounded-lg p-5 hover:shadow-lg transition-shadow",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[e.jsx(bt,{size:_.lg,className:"text-blue-600"}),e.jsx("h3",{className:"font-semibold text-slate-800",children:"代码审查(Audit)"})]}),e.jsxs("ul",{className:"text-slate-600 text-sm space-y-2 list-disc list-inside",children:[e.jsxs("li",{children:[e.jsx("strong",{children:"文件审查"}),":",e.jsx("code",{className:"bg-slate-100 px-1 rounded text-xs",children:"// as:audit"})]}),e.jsxs("li",{children:[e.jsx("strong",{children:"Target 审查"}),":",e.jsx("code",{className:"bg-slate-100 px-1 rounded text-xs",children:"// as:audit target"})]}),e.jsxs("li",{children:[e.jsx("strong",{children:"合规报告"}),":MCP ",e.jsx("code",{className:"bg-slate-100 px-1 rounded text-xs",children:"compliance_report"})]}),e.jsxs("li",{children:[e.jsx("strong",{children:"Dashboard"}),":Guard 页面可视化审查"]})]})]}),e.jsxs("div",{className:"border border-slate-200 rounded-lg p-5 hover:shadow-lg transition-shadow",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[e.jsx(wt,{size:_.lg,className:"text-blue-600"}),e.jsx("h3",{className:"font-semibold text-slate-800",children:"数据同步"})]}),e.jsxs("ul",{className:"text-slate-600 text-sm space-y-2 list-disc list-inside",children:[e.jsxs("li",{children:[e.jsx("strong",{children:"同步"}),":",e.jsx("code",{className:"bg-slate-100 px-1 rounded text-xs",children:"asd sync"})," .md → DB(增量)"]}),e.jsxs("li",{children:[e.jsx("strong",{children:"Hash 校验"}),":",e.jsx("code",{className:"bg-slate-100 px-1 rounded text-xs",children:"_contentHash"})," 检测手动编辑"]}),e.jsxs("li",{children:[e.jsx("strong",{children:"向量索引"}),":启动时自动构建语义索引"]}),e.jsxs("li",{children:[e.jsx("strong",{children:"依赖图"}),":",e.jsx("code",{className:"bg-slate-100 px-1 rounded text-xs",children:"get_targets"})," / ",e.jsx("code",{className:"bg-slate-100 px-1 rounded text-xs",children:"get_target_files"})," MCP 工具"]})]})]})]})}),e.jsxs(l,{id:"editor-directives",title:"编辑器指令",icon:e.jsx(ks,{size:_.xl,className:"text-blue-600"}),children:[e.jsxs("p",{className:"text-slate-600 text-sm mb-4",children:["需先运行 ",e.jsx("code",{className:"bg-slate-100 px-1 rounded",children:"asd watch"})," 或 ",e.jsx("code",{className:"bg-slate-100 px-1 rounded",children:"asd ui"}),";支持快捷写法 ",e.jsx("code",{className:"bg-slate-100 px-1 rounded",children:"asc"})," ",e.jsx("code",{className:"bg-slate-100 px-1 rounded",children:"ass"})," ",e.jsx("code",{className:"bg-slate-100 px-1 rounded",children:"asa"})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"bg-slate-50 rounded-lg p-4 border border-slate-200",children:[e.jsxs("h4",{className:"font-semibold text-slate-800 mb-2",children:[e.jsx("code",{className:"bg-slate-200 px-2 py-1 rounded",children:"// as:create"})," · ",e.jsx("code",{className:"bg-slate-200 px-2 py-1 rounded",children:"asc"})]}),e.jsx("p",{className:"text-slate-600 text-sm mb-2",children:"创建 Recipe/Snippet"}),e.jsxs("ul",{className:"text-slate-600 text-xs space-y-1 list-disc list-inside",children:[e.jsx("li",{children:"无选项:打开 Dashboard"}),e.jsxs("li",{children:[e.jsx("code",{children:"-c"}),":从剪贴板静默创建"]}),e.jsxs("li",{children:[e.jsx("code",{children:"-f"}),":扫描当前文件"]})]})]}),e.jsxs("div",{className:"bg-slate-50 rounded-lg p-4 border border-slate-200",children:[e.jsxs("h4",{className:"font-semibold text-slate-800 mb-2",children:[e.jsx("code",{className:"bg-slate-200 px-2 py-1 rounded",children:"// as:search"})," · ",e.jsx("code",{className:"bg-slate-200 px-2 py-1 rounded",children:"ass"})]}),e.jsx("p",{className:"text-slate-600 text-sm mb-2",children:"搜索并插入"}),e.jsxs("ul",{className:"text-slate-600 text-xs space-y-1 list-disc list-inside",children:[e.jsx("li",{children:"从知识库检索 Recipe/Snippet"}),e.jsx("li",{children:"选择后插入代码,替换该行"}),e.jsx("li",{children:"记录一次人工使用"})]})]}),e.jsxs("div",{className:"bg-slate-50 rounded-lg p-4 border border-slate-200",children:[e.jsxs("h4",{className:"font-semibold text-slate-800 mb-2",children:[e.jsx("code",{className:"bg-slate-200 px-2 py-1 rounded",children:"// as:audit"})," · ",e.jsx("code",{className:"bg-slate-200 px-2 py-1 rounded",children:"asa"})]}),e.jsx("p",{className:"text-slate-600 text-sm mb-2",children:"代码审查"}),e.jsxs("ul",{className:"text-slate-600 text-xs space-y-1 list-disc list-inside",children:[e.jsx("li",{children:"无后缀:审查当前文件"}),e.jsxs("li",{children:[e.jsx("code",{children:"target"}),":审查当前 Target"]}),e.jsxs("li",{children:[e.jsx("code",{children:"project"}),":审查整个项目"]})]})]}),e.jsxs("div",{className:"bg-slate-50 rounded-lg p-4 border border-slate-200",children:[e.jsxs("h4",{className:"font-semibold text-slate-800 mb-2",children:[e.jsx("code",{className:"bg-slate-200 px-2 py-1 rounded",children:"// as:include"})," · ",e.jsx("code",{className:"bg-slate-200 px-2 py-1 rounded",children:"// as:import"})]}),e.jsx("p",{className:"text-slate-600 text-sm mb-2",children:"自动注入头文件/模块"}),e.jsxs("ul",{className:"text-slate-600 text-xs space-y-1 list-disc list-inside",children:[e.jsx("li",{children:"Snippet 中包含此标记"}),e.jsx("li",{children:"补全后自动注入 import"})]})]})]})]}),e.jsxs(l,{id:"cursor-integration",title:"Cursor AI 集成",icon:e.jsx(vt,{size:_.xl,className:"text-blue-600"}),children:[e.jsxs("div",{className:"mb-5",children:[e.jsx("h3",{className:"font-semibold text-slate-800 mb-3",children:"10 个 Skills"}),e.jsx("div",{className:"grid grid-cols-2 md:grid-cols-5 gap-2",children:[{name:"intent",desc:"意图路由"},{name:"concepts",desc:"概念教学"},{name:"candidates",desc:"候选提交"},{name:"recipes",desc:"Recipe 检索"},{name:"guard",desc:"代码合规"},{name:"structure",desc:"项目结构"},{name:"analysis",desc:"深度分析"},{name:"coldstart",desc:"冷启动"},{name:"create",desc:"引导创建"},{name:"lifecycle",desc:"生命周期"}].map(n=>e.jsxs("div",{className:"bg-slate-50 border border-slate-200 rounded-lg px-3 py-2 text-center",children:[e.jsx("p",{className:"text-xs font-mono text-blue-600",children:n.name}),e.jsx("p",{className:"text-xs text-slate-500 mt-0.5",children:n.desc})]},n.name))})]}),e.jsxs("div",{className:"mb-5",children:[e.jsx("h3",{className:"font-semibold text-slate-800 mb-3",children:"36 个 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:"suggest_skills"})]}),e.jsx("td",{className:"px-3 py-2 text-center",children:"4"})]})]})]})}),e.jsx("p",{className:"text-xs text-slate-500 mt-2",children:"其中 9 个写操作工具(submit_candidate, submit_candidates, submit_draft_recipes, enrich_candidates, guard_audit_files, scan_project, bootstrap_knowledge, bootstrap_refine, create_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(gt,{size:_.xl,className:"text-blue-600"}),children:e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-5",children:[e.jsxs("div",{className:"border border-slate-200 rounded-lg p-5",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[e.jsx(st,{size:_.lg,className:"text-indigo-600"}),e.jsx("h3",{className:"font-semibold text-slate-800",children:"Bootstrap 冷启动引擎"})]}),e.jsx("p",{className:"text-slate-600 text-sm mb-2",children:"3 步完成知识库从 0 → 1:"}),e.jsxs("div",{className:"bg-slate-50 rounded p-3 text-xs font-mono text-slate-700 space-y-1",children:[e.jsx("p",{children:"① 项目扫描 → 依赖 / 目录 / 入口分析"}),e.jsx("p",{children:"② AI 批量提取 → Candidate 候选列表"}),e.jsx("p",{children:"③ 审阅 + Promote → Recipe 知识库就绪"})]}),e.jsx("p",{className:"text-slate-500 text-xs mt-2",children:"支持 bootstrap_refine 持续迭代、resume 断点续跑"})]}),e.jsxs("div",{className:"border border-slate-200 rounded-lg p-5",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[e.jsx(pt,{size:_.lg,className:"text-indigo-600"}),e.jsx("h3",{className:"font-semibold text-slate-800",children:"4 层检索管线"})]}),e.jsx("p",{className:"text-slate-600 text-sm mb-2",children:"多信号融合的精准检索:"}),e.jsxs("div",{className:"space-y-2 text-xs",children:[e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsx("span",{className:"bg-blue-100 text-blue-700 px-2 py-0.5 rounded font-medium shrink-0",children:"L1"}),e.jsx("span",{className:"text-slate-600",children:"InvertedIndex — 倒排索引快速召回"})]}),e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsx("span",{className:"bg-green-100 text-green-700 px-2 py-0.5 rounded font-medium shrink-0",children:"L2"}),e.jsx("span",{className:"text-slate-600",children:"CoarseRanker — BM25 + TF-IDF 粗排"})]}),e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsx("span",{className:"bg-amber-100 text-amber-700 px-2 py-0.5 rounded font-medium shrink-0",children:"L3"}),e.jsx("span",{className:"text-slate-600",children:"MultiSignalRanker — 多维信号精排"})]}),e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsx("span",{className:"bg-red-100 text-red-700 px-2 py-0.5 rounded font-medium shrink-0",children:"L4"}),e.jsx("span",{className:"text-slate-600",children:"RetrievalFunnel — 漏斗截断 + 上下文装配"})]})]})]}),e.jsxs("div",{className:"border border-slate-200 rounded-lg p-5",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[e.jsx(ws,{size:_.lg,className:"text-indigo-600"}),e.jsx("h3",{className:"font-semibold text-slate-800",children:"Dual-Agent 对话系统"})]}),e.jsx("p",{className:"text-slate-600 text-sm mb-2",children:"Analyst + Producer 双代理架构:"}),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(bs,{size:_.lg,className:"text-indigo-600"}),e.jsx("h3",{className:"font-semibold text-slate-800",children:"五个入口通道"})]}),e.jsxs("div",{className:"space-y-2 text-xs",children:[e.jsxs("div",{className:"flex justify-between bg-slate-50 px-3 py-2 rounded",children:[e.jsx("span",{className:"font-medium",children:"CLI"}),e.jsx("span",{className:"text-slate-500",children:"asd × 10 命令"})]}),e.jsxs("div",{className:"flex justify-between bg-slate-50 px-3 py-2 rounded",children:[e.jsx("span",{className:"font-medium",children:"MCP Server"}),e.jsx("span",{className:"text-slate-500",children:"stdio × 36 工具"})]}),e.jsxs("div",{className:"flex justify-between bg-slate-50 px-3 py-2 rounded",children:[e.jsx("span",{className:"font-medium",children:"HTTP API"}),e.jsx("span",{className:"text-slate-500",children:"Express × 14 路由模块"})]}),e.jsxs("div",{className:"flex justify-between bg-slate-50 px-3 py-2 rounded",children:[e.jsx("span",{className:"font-medium",children:"Dashboard"}),e.jsx("span",{className:"text-slate-500",children:"React 19 + Vite 6 + Tailwind 4"})]}),e.jsxs("div",{className:"flex justify-between bg-slate-50 px-3 py-2 rounded",children:[e.jsx("span",{className:"font-medium",children:"Skills"}),e.jsx("span",{className:"text-slate-500",children:"13 个 Cursor/Copilot"})]})]})]})]})}),e.jsx(l,{id:"cli-reference",title:"命令行速查",icon:e.jsx(ks,{size:_.xl,className:"text-blue-600"}),children:e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"font-semibold text-slate-800 mb-2",children:"初始化与环境"}),e.jsxs("div",{className:"space-y-1 text-sm",children:[e.jsxs("div",{className:"flex justify-between bg-slate-50 px-3 py-2 rounded",children:[e.jsx("code",{children:"asd setup"}),e.jsx("span",{className:"text-slate-500 text-xs",children:"初始化项目"})]}),e.jsxs("div",{className:"flex justify-between bg-slate-50 px-3 py-2 rounded",children:[e.jsx("code",{children:"asd status"}),e.jsx("span",{className:"text-slate-500 text-xs",children:"环境自检"})]}),e.jsxs("div",{className:"flex justify-between bg-slate-50 px-3 py-2 rounded",children:[e.jsx("code",{children:"asd ui"}),e.jsx("span",{className:"text-slate-500 text-xs",children:"启动 Dashboard"})]}),e.jsxs("div",{className:"flex justify-between bg-slate-50 px-3 py-2 rounded",children:[e.jsx("code",{children:"asd upgrade"}),e.jsx("span",{className:"text-slate-500 text-xs",children:"升级 IDE 集成"})]})]})]}),e.jsxs("div",{children:[e.jsx("h3",{className:"font-semibold text-slate-800 mb-2",children:"知识库管理"}),e.jsxs("div",{className:"space-y-1 text-sm",children:[e.jsxs("div",{className:"flex justify-between bg-slate-50 px-3 py-2 rounded",children:[e.jsx("code",{children:"asd sync"}),e.jsx("span",{className:"text-slate-500 text-xs",children:".md → DB 增量同步"})]}),e.jsxs("div",{className:"flex justify-between bg-slate-50 px-3 py-2 rounded",children:[e.jsx("code",{children:"asd ais [Target]"}),e.jsx("span",{className:"text-slate-500 text-xs",children:"AI 扫描提取 Candidates"})]}),e.jsxs("div",{className:"flex justify-between bg-slate-50 px-3 py-2 rounded",children:[e.jsx("code",{children:"asd ais --force"}),e.jsx("span",{className:"text-slate-500 text-xs",children:"强制重新扫描全量"})]}),e.jsxs("div",{className:"flex justify-between bg-slate-50 px-3 py-2 rounded",children:[e.jsx("code",{children:"asd watch"}),e.jsx("span",{className:"text-slate-500 text-xs",children:"文件监控 + 指令触发"})]})]})]}),e.jsxs("div",{children:[e.jsx("h3",{className:"font-semibold text-slate-800 mb-2",children:"搜索与审查"}),e.jsxs("div",{className:"space-y-1 text-sm",children:[e.jsxs("div",{className:"flex justify-between bg-slate-50 px-3 py-2 rounded",children:[e.jsx("code",{children:"asd search <query>"}),e.jsx("span",{className:"text-slate-500 text-xs",children:"搜索知识库"})]}),e.jsxs("div",{className:"flex justify-between bg-slate-50 px-3 py-2 rounded",children:[e.jsx("code",{children:"asd search -m semantic"}),e.jsx("span",{className:"text-slate-500 text-xs",children:"语义搜索模式"})]}),e.jsxs("div",{className:"flex justify-between bg-slate-50 px-3 py-2 rounded",children:[e.jsx("code",{children:"asd guard <file>"}),e.jsx("span",{className:"text-slate-500 text-xs",children:"Guard 规则检查"})]}),e.jsxs("div",{className:"flex justify-between bg-slate-50 px-3 py-2 rounded",children:[e.jsx("code",{children:"asd server"}),e.jsx("span",{className:"text-slate-500 text-xs",children:"单独启动 API 服务"})]})]})]}),e.jsxs("div",{children:[e.jsx("h3",{className:"font-semibold text-slate-800 mb-2",children:"维护与升级"}),e.jsxs("div",{className:"space-y-1 text-sm",children:[e.jsxs("div",{className:"flex justify-between bg-slate-50 px-3 py-2 rounded",children:[e.jsx("code",{children:"asd upgrade"}),e.jsx("span",{className:"text-slate-500 text-xs",children:"升级 MCP / Skills / Rules"})]}),e.jsxs("div",{className:"flex justify-between bg-slate-50 px-3 py-2 rounded",children:[e.jsx("code",{children:"asd install:full"}),e.jsx("span",{className:"text-slate-500 text-xs",children:"全量安装 IDE 集成"})]}),e.jsxs("div",{className:"flex justify-between bg-slate-50 px-3 py-2 rounded",children:[e.jsx("code",{children:"asd sync --force"}),e.jsx("span",{className:"text-slate-500 text-xs",children:"全量重建 DB"})]}),e.jsxs("div",{className:"flex justify-between bg-slate-50 px-3 py-2 rounded",children:[e.jsx("code",{children:"asd sync --dry-run"}),e.jsx("span",{className:"text-slate-500 text-xs",children:"预览同步变更"})]})]})]})]})})]}),e.jsx("div",{className:"mt-8 p-4 bg-blue-50 border border-blue-200 rounded-lg text-center",children:e.jsxs("p",{className:"text-slate-700 text-sm",children:["需要更详细的说明?查看 ",e.jsx("a",{href:"https://github.com/GxFn/AutoSnippet",target:"_blank",rel:"noopener noreferrer",className:"text-blue-600 hover:underline font-medium",children:"GitHub README"})," 或运行 ",e.jsx("code",{className:"bg-blue-100 px-1.5 py-0.5 rounded text-xs",children:"asd status"})," 检查环境"]})})]})};function Xl(){const[t,s]=r.useState(null);r.useEffect(()=>{const o=ra(),c=y=>{s({status:"running",total:y.total,current:0,progress:0,refined:0,failed:0,items:y.candidateIds.map(m=>({candidateId:m,title:"",status:"pending"}))})},i=y=>{s(m=>m&&{...m,current:y.current,progress:y.progress,items:m.items.map(S=>S.candidateId===y.candidateId?{...S,title:y.title,status:"refining"}:S)})},x=y=>{s(m=>m&&{...m,current:y.current,progress:y.progress,refined:y.refinedSoFar,items:m.items.map(S=>S.candidateId===y.candidateId?{...S,title:y.title,status:"done",refined:y.refined}:S)})},$=y=>{s(m=>m&&{...m,current:y.current,progress:y.progress,failed:m.failed+1,items:m.items.map(S=>S.candidateId===y.candidateId?{...S,title:y.title,status:"failed",error:y.error}:S)})},d=y=>{s(m=>m&&{...m,status:"completed",progress:100,refined:y.refined,failed:y.failed})};return o.on("refine:started",c),o.on("refine:item-started",i),o.on("refine:item-completed",x),o.on("refine:item-failed",$),o.on("refine:completed",d),()=>{o.off("refine:started",c),o.off("refine:item-started",i),o.off("refine:item-completed",x),o.off("refine:item-failed",$),o.off("refine:completed",d)}},[]);const a=r.useCallback(()=>s(null),[]),l=(t==null?void 0:t.status)==="running",n=(t==null?void 0:t.status)==="completed";return{refine:t,isRefining:l,isRefineDone:n,resetRefine:a}}const Zl=({refine:t,isRefineDone:s,onDismiss:a})=>{const l=r.useRef(!1);if(r.useEffect(()=>{if(s&&t&&!l.current){l.current=!0;const c=t.failed>0?`${t.refined} 条已更新,${t.failed} 条失败`:`${t.refined}/${t.total} 条候选已更新`;ee(c,{title:"AI 润色完成",type:t.failed>0?"error":"success"})}},[s,t]),r.useEffect(()=>{t||(l.current=!1)},[t]),!t)return null;const n=t.items.find(c=>c.status==="refining"),o=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(zt,{className:"w-4 h-4 text-emerald-600"}):e.jsx(Ye,{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} 条失败`:""}`:`${o}/${t.total} 条候选`,n&&!s&&e.jsxs("span",{className:"ml-2 text-blue-600",children:[e.jsx(_e,{className:"w-3 h-3 inline animate-spin mr-1"}),n.title||n.candidateId.slice(0,8)]})]})]})]}),s&&a&&e.jsx("button",{onClick:a,className:"text-xs px-2.5 py-1 rounded-lg bg-slate-100 hover:bg-slate-200 text-slate-600 transition-colors",children:"关闭"})]}),e.jsx("div",{className:"w-full h-1.5 bg-slate-100 rounded-full overflow-hidden",children:e.jsx("div",{className:`h-full rounded-full transition-all duration-500 ease-out ${s?t.failed>0?"bg-amber-400":"bg-emerald-500":"bg-blue-500"}`,style:{width:`${t.progress}%`}})}),s&&t.failed>0&&e.jsxs("div",{className:"mt-2 text-xs text-red-500 flex items-center gap-1",children:[e.jsx(Ke,{className:"w-3 h-3"}),t.items.filter(c=>c.status==="failed").map(c=>c.title||c.candidateId.slice(0,8)).join("、")]})]})},Ts={_watch:"as:create",_draft:"草稿",_cli:"CLI",_pending:"待审核(24h)",_recipe:"New Recipe"};function Ql(t,s,a,l){return[...t].sort(([n],[o])=>{const c=l(n),i=l(o);if(c&&!i)return 1;if(!c&&i)return-1;const x=a(n),$=a(o);if(x&&!$)return-1;if(!x&&$)return 1;const d=s(n),y=s(o);return d&&!y?1:!d&&y?-1:n.localeCompare(o)})}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 o=new Date().getTime()-l.getTime();if(o<0)return l.toLocaleDateString("zh-CN");const c=Math.floor(o/6e4);if(c<1)return"刚刚";if(c<60)return`${c} 分钟前`;const i=Math.floor(c/60);if(i<24)return`${i} 小时前`;const x=Math.floor(i/24);return x<7?`${x} 天前`:l.toLocaleDateString("zh-CN")}function er(t,s=4){return t?t.split(`
|
|
93
|
+
`,"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(Bs,{size:z.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(st,{size:z.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(Fa,{size:z.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(Js,{size:z.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(ws,{size:z.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(pt,{size:z.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(bt,{size:z.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(st,{size:z.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(ss,{size:z.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(pt,{size:z.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(bt,{size:z.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(wt,{size:z.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(ks,{size:z.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(vt,{size:z.xl,className:"text-blue-600"}),children:[e.jsxs("div",{className:"mb-5",children:[e.jsx("h3",{className:"font-semibold text-slate-800 mb-3",children:"10 个 Skills"}),e.jsx("div",{className:"grid grid-cols-2 md:grid-cols-5 gap-2",children:[{name:"intent",desc:"意图路由"},{name:"concepts",desc:"概念教学"},{name:"candidates",desc:"候选提交"},{name:"recipes",desc:"Recipe 检索"},{name:"guard",desc:"代码合规"},{name:"structure",desc:"项目结构"},{name:"analysis",desc:"深度分析"},{name:"coldstart",desc:"冷启动"},{name:"create",desc:"引导创建"},{name:"lifecycle",desc:"生命周期"}].map(n=>e.jsxs("div",{className:"bg-slate-50 border border-slate-200 rounded-lg px-3 py-2 text-center",children:[e.jsx("p",{className:"text-xs font-mono text-blue-600",children:n.name}),e.jsx("p",{className:"text-xs text-slate-500 mt-0.5",children:n.desc})]},n.name))})]}),e.jsxs("div",{className:"mb-5",children:[e.jsx("h3",{className:"font-semibold text-slate-800 mb-3",children:"38 个 MCP 工具"}),e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"min-w-full border border-slate-200 rounded-lg text-xs",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"bg-slate-50",children:[e.jsx("th",{className:"px-3 py-2 border-b text-left",children:"分组"}),e.jsx("th",{className:"px-3 py-2 border-b text-left",children:"工具"}),e.jsx("th",{className:"px-3 py-2 border-b text-left text-center",children:"数量"})]})}),e.jsxs("tbody",{children:[e.jsxs("tr",{children:[e.jsx("td",{className:"px-3 py-2 border-b font-medium",children:"system"}),e.jsxs("td",{className:"px-3 py-2 border-b",children:[e.jsx("code",{children:"health"}),", ",e.jsx("code",{children:"capabilities"})]}),e.jsx("td",{className:"px-3 py-2 border-b text-center",children:"2"})]}),e.jsxs("tr",{children:[e.jsx("td",{className:"px-3 py-2 border-b font-medium",children:"search"}),e.jsxs("td",{className:"px-3 py-2 border-b",children:[e.jsx("code",{children:"search"}),", ",e.jsx("code",{children:"context_search"}),", ",e.jsx("code",{children:"keyword_search"}),", ",e.jsx("code",{children:"semantic_search"})]}),e.jsx("td",{className:"px-3 py-2 border-b text-center",children:"4"})]}),e.jsxs("tr",{children:[e.jsx("td",{className:"px-3 py-2 border-b font-medium",children:"browse"}),e.jsxs("td",{className:"px-3 py-2 border-b",children:[e.jsx("code",{children:"list_rules"}),", ",e.jsx("code",{children:"list_patterns"}),", ",e.jsx("code",{children:"list_facts"}),", ",e.jsx("code",{children:"list_recipes"}),", ",e.jsx("code",{children:"get_recipe"}),", ",e.jsx("code",{children:"recipe_insights"}),", ",e.jsx("code",{children:"compliance_report"}),", ",e.jsx("code",{children:"confirm_usage"})]}),e.jsx("td",{className:"px-3 py-2 border-b text-center",children:"8"})]}),e.jsxs("tr",{children:[e.jsx("td",{className:"px-3 py-2 border-b font-medium",children:"structure"}),e.jsxs("td",{className:"px-3 py-2 border-b",children:[e.jsx("code",{children:"get_targets"}),", ",e.jsx("code",{children:"get_target_files"}),", ",e.jsx("code",{children:"get_target_metadata"}),", ",e.jsx("code",{children:"graph_query"}),", ",e.jsx("code",{children:"graph_impact"}),", ",e.jsx("code",{children:"graph_path"}),", ",e.jsx("code",{children:"graph_stats"})]}),e.jsx("td",{className:"px-3 py-2 border-b text-center",children:"7"})]}),e.jsxs("tr",{children:[e.jsx("td",{className:"px-3 py-2 border-b font-medium",children:"candidate"}),e.jsxs("td",{className:"px-3 py-2 border-b",children:[e.jsx("code",{children:"validate_candidate"}),", ",e.jsx("code",{children:"check_duplicate"}),", ",e.jsx("code",{children:"submit_candidate"}),", ",e.jsx("code",{children:"submit_candidates"}),", ",e.jsx("code",{children:"submit_draft_recipes"}),", ",e.jsx("code",{children:"enrich_candidates"})]}),e.jsx("td",{className:"px-3 py-2 border-b text-center",children:"6"})]}),e.jsxs("tr",{children:[e.jsx("td",{className:"px-3 py-2 border-b font-medium",children:"guard"}),e.jsxs("td",{className:"px-3 py-2 border-b",children:[e.jsx("code",{children:"guard_check"}),", ",e.jsx("code",{children:"guard_audit_files"}),", ",e.jsx("code",{children:"scan_project"})]}),e.jsx("td",{className:"px-3 py-2 border-b text-center",children:"3"})]}),e.jsxs("tr",{children:[e.jsx("td",{className:"px-3 py-2 border-b font-medium",children:"bootstrap"}),e.jsxs("td",{className:"px-3 py-2 border-b",children:[e.jsx("code",{children:"bootstrap_knowledge"}),", ",e.jsx("code",{children:"bootstrap_refine"})]}),e.jsx("td",{className:"px-3 py-2 border-b text-center",children:"2"})]}),e.jsxs("tr",{children:[e.jsx("td",{className:"px-3 py-2 font-medium",children:"skills"}),e.jsxs("td",{className:"px-3 py-2",children:[e.jsx("code",{children:"list_skills"}),", ",e.jsx("code",{children:"load_skill"}),", ",e.jsx("code",{children:"create_skill"}),", ",e.jsx("code",{children:"delete_skill"}),", ",e.jsx("code",{children:"update_skill"}),", ",e.jsx("code",{children:"suggest_skills"})]}),e.jsx("td",{className:"px-3 py-2 text-center",children:"6"})]})]})]})}),e.jsx("p",{className:"text-xs text-slate-500 mt-2",children:"其中 11 个写操作工具(submit_candidate, submit_candidates, submit_draft_recipes, enrich_candidates, guard_audit_files, scan_project, bootstrap_knowledge, bootstrap_refine, create_skill, delete_skill, update_skill)通过 Gateway 权限保护。"})]}),e.jsxs("div",{children:[e.jsx("h3",{className:"font-semibold text-slate-800 mb-3",children:"使用示例"}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"bg-blue-50 rounded p-3 border border-blue-200",children:[e.jsx("p",{className:"font-medium text-blue-900 text-sm mb-1",children:"检索知识库"}),e.jsx("p",{className:"text-blue-800 text-xs",children:'对 Cursor 说:"查找网络请求错误处理的代码"'})]}),e.jsxs("div",{className:"bg-green-50 rounded p-3 border border-green-200",children:[e.jsx("p",{className:"font-medium text-green-900 text-sm mb-1",children:"批量扫描"}),e.jsx("p",{className:"text-green-800 text-xs",children:'对 Cursor 说:"扫描 NetworkModule,生成 Recipes 到候选"'})]}),e.jsxs("div",{className:"bg-purple-50 rounded p-3 border border-purple-200",children:[e.jsx("p",{className:"font-medium text-purple-900 text-sm mb-1",children:"提交代码"}),e.jsx("p",{className:"text-purple-800 text-xs",children:'对 Cursor 说:"把这段代码保存为 Recipe"'})]})]})]})]}),e.jsx(l,{id:"v2-architecture",title:"V2 架构",icon:e.jsx(gt,{size:z.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(st,{size:z.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(pt,{size:z.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(ws,{size:z.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(bs,{size:z.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(ks,{size:z.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 Xl(){const[t,s]=r.useState(null);r.useEffect(()=>{const o=ra(),c=y=>{s({status:"running",total:y.total,current:0,progress:0,refined:0,failed:0,items:y.candidateIds.map(m=>({candidateId:m,title:"",status:"pending"}))})},i=y=>{s(m=>m&&{...m,current:y.current,progress:y.progress,items:m.items.map(S=>S.candidateId===y.candidateId?{...S,title:y.title,status:"refining"}:S)})},x=y=>{s(m=>m&&{...m,current:y.current,progress:y.progress,refined:y.refinedSoFar,items:m.items.map(S=>S.candidateId===y.candidateId?{...S,title:y.title,status:"done",refined:y.refined}:S)})},$=y=>{s(m=>m&&{...m,current:y.current,progress:y.progress,failed:m.failed+1,items:m.items.map(S=>S.candidateId===y.candidateId?{...S,title:y.title,status:"failed",error:y.error}:S)})},d=y=>{s(m=>m&&{...m,status:"completed",progress:100,refined:y.refined,failed:y.failed})};return o.on("refine:started",c),o.on("refine:item-started",i),o.on("refine:item-completed",x),o.on("refine:item-failed",$),o.on("refine:completed",d),()=>{o.off("refine:started",c),o.off("refine:item-started",i),o.off("refine:item-completed",x),o.off("refine:item-failed",$),o.off("refine:completed",d)}},[]);const a=r.useCallback(()=>s(null),[]),l=(t==null?void 0:t.status)==="running",n=(t==null?void 0:t.status)==="completed";return{refine:t,isRefining:l,isRefineDone:n,resetRefine:a}}const Zl=({refine:t,isRefineDone:s,onDismiss:a})=>{const l=r.useRef(!1);if(r.useEffect(()=>{if(s&&t&&!l.current){l.current=!0;const c=t.failed>0?`${t.refined} 条已更新,${t.failed} 条失败`:`${t.refined}/${t.total} 条候选已更新`;ee(c,{title:"AI 润色完成",type:t.failed>0?"error":"success"})}},[s,t]),r.useEffect(()=>{t||(l.current=!1)},[t]),!t)return null;const n=t.items.find(c=>c.status==="refining"),o=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(_t,{className:"w-4 h-4 text-emerald-600"}):e.jsx(Ye,{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} 条失败`:""}`:`${o}/${t.total} 条候选`,n&&!s&&e.jsxs("span",{className:"ml-2 text-blue-600",children:[e.jsx(ze,{className:"w-3 h-3 inline animate-spin mr-1"}),n.title||n.candidateId.slice(0,8)]})]})]})]}),s&&a&&e.jsx("button",{onClick:a,className:"text-xs px-2.5 py-1 rounded-lg bg-slate-100 hover:bg-slate-200 text-slate-600 transition-colors",children:"关闭"})]}),e.jsx("div",{className:"w-full h-1.5 bg-slate-100 rounded-full overflow-hidden",children:e.jsx("div",{className:`h-full rounded-full transition-all duration-500 ease-out ${s?t.failed>0?"bg-amber-400":"bg-emerald-500":"bg-blue-500"}`,style:{width:`${t.progress}%`}})}),s&&t.failed>0&&e.jsxs("div",{className:"mt-2 text-xs text-red-500 flex items-center gap-1",children:[e.jsx(Ke,{className:"w-3 h-3"}),t.items.filter(c=>c.status==="failed").map(c=>c.title||c.candidateId.slice(0,8)).join("、")]})]})},Ts={_watch:"as:create",_draft:"草稿",_cli:"CLI",_pending:"待审核(24h)",_recipe:"New Recipe"};function Ql(t,s,a,l){return[...t].sort(([n],[o])=>{const c=l(n),i=l(o);if(c&&!i)return 1;if(!c&&i)return-1;const x=a(n),$=a(o);if(x&&!$)return-1;if(!x&&$)return 1;const d=s(n),y=s(o);return d&&!y?1:!d&&y?-1:n.localeCompare(o)})}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 o=new Date().getTime()-l.getTime();if(o<0)return l.toLocaleDateString("zh-CN");const c=Math.floor(o/6e4);if(c<1)return"刚刚";if(c<60)return`${c} 分钟前`;const i=Math.floor(c/60);if(i<24)return`${i} 小时前`;const x=Math.floor(i/24);return x<7?`${x} 天前`:l.toLocaleDateString("zh-CN")}function er(t,s=4){return t?t.split(`
|
|
94
94
|
`).slice(0,s).join(`
|
|
95
|
-
`):""}function tr(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 sr(t){return t==="high"?{bg:"bg-red-50",text:"text-red-700",border:"border-red-200",icon:"🔴"}:t==="medium"?{bg:"bg-amber-50",text:"text-amber-700",border:"border-amber-200",icon:"🟡"}:t==="low"?{bg:"bg-slate-50",text:"text-slate-600",border:"border-slate-200",icon:"⚪"}:null}const Ms={"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"}},Gs=({value:t,size:s=36})=>{const a=(s-6)/2,l=2*Math.PI*a,n=t!=null?Math.max(0,Math.min(1,t)):0,o=l*(1-n),{ring:c,text:i}=tr(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:o,style:{transition:"stroke-dashoffset 0.5s ease"}})]}),e.jsx("span",{className:`absolute text-[9px] font-bold ${i}`,children:t!=null?`${Math.round(t*100)}`:"—"})]})},ar=({data:t,isShellTarget:s,isSilentTarget:a=()=>!1,isPendingTarget:l=()=>!1,handleDeleteCandidate:n,handleDeleteAllInTarget:o,onAuditCandidate:c,onAuditAllInTarget:i,onEditRecipe:x,onColdStart:$,isScanning:d,isBootstrapping:y,onRefresh:m})=>{var u;const[S,v]=r.useState(null),{isWide:A,toggle:f}=da(),[k,T]=r.useState(new Set),[L,U]=r.useState(new Set),[B,K]=r.useState(!1),[b,R]=r.useState(!1),M=Ht(),{refine:H,isRefining:
|
|
96
|
-
${ue?`${(oe==null?void 0:oe.bg)||"bg-blue-50"} ${(oe==null?void 0:oe.color)||"text-blue-700"} ${(oe==null?void 0:oe.border)||"border-blue-200"} shadow-sm ring-1 ring-inset ${(oe==null?void 0:oe.border)||"ring-blue-200"}`:"bg-slate-50/80 text-slate-600 border-slate-100 hover:border-slate-200 hover:bg-slate-100"}`,children:[(()=>{const re=(oe==null?void 0:oe.icon)||Qt;return e.jsx(re,{size:
|
|
95
|
+
`):""}function tr(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 sr(t){return t==="high"?{bg:"bg-red-50",text:"text-red-700",border:"border-red-200",icon:"🔴"}:t==="medium"?{bg:"bg-amber-50",text:"text-amber-700",border:"border-amber-200",icon:"🟡"}:t==="low"?{bg:"bg-slate-50",text:"text-slate-600",border:"border-slate-200",icon:"⚪"}:null}const Ms={"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"}},Gs=({value:t,size:s=36})=>{const a=(s-6)/2,l=2*Math.PI*a,n=t!=null?Math.max(0,Math.min(1,t)):0,o=l*(1-n),{ring:c,text:i}=tr(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:o,style:{transition:"stroke-dashoffset 0.5s ease"}})]}),e.jsx("span",{className:`absolute text-[9px] font-bold ${i}`,children:t!=null?`${Math.round(t*100)}`:"—"})]})},ar=({data:t,isShellTarget:s,isSilentTarget:a=()=>!1,isPendingTarget:l=()=>!1,handleDeleteCandidate:n,handleDeleteAllInTarget:o,onAuditCandidate:c,onAuditAllInTarget:i,onEditRecipe:x,onColdStart:$,isScanning:d,isBootstrapping:y,onRefresh:m})=>{var u;const[S,v]=r.useState(null),{isWide:A,toggle:f}=da(),[k,T]=r.useState(new Set),[L,U]=r.useState(new Set),[B,K]=r.useState(!1),[b,R]=r.useState(!1),M=Ht(),{refine:H,isRefining:_,isRefineDone:P,resetRefine:p}=Xl(),[w,E]=r.useState({}),[se,h]=r.useState(null),[V,me]=r.useState({}),[F,X]=r.useState(null),[Y,ie]=r.useState({}),[Ne,Re]=r.useState({priority:"all",sort:"default",onlySimilar:!1}),[fe,Q]=r.useState(null),ve=r.useRef(new Set),Le=r.useCallback(async(I,G)=>{if(!ve.current.has(G)){ve.current.add(G),X(G);try{const C=await te.getCandidateSimilarityEx({targetName:I,candidateId:G});me(q=>({...q,[G]:C.similar||[]}))}catch{me(q=>({...q,[G]:[]}))}finally{X(null)}}},[]),Ge=r.useCallback(async(I,G,C,q=[])=>{var re,ye,Se,Be;const ae=C.replace(/\.md$/i,"");let ue="";const oe=(re=t==null?void 0:t.recipes)==null?void 0:re.find(Ae=>Ae.name===ae||Ae.name.endsWith("/"+ae));if(oe!=null&&oe.content)ue=oe.content;else try{ue=(await te.getRecipeContentByName(ae)).content}catch(Ae){const He=(ye=Ae.response)==null?void 0:ye.status,Qe=((Be=(Se=Ae.response)==null?void 0:Se.data)==null?void 0:Be.message)||Ae.message;He===404?ee(`"${ae}" 不存在于当前知识库`,{title:"Recipe 不存在",type:"error"}):ee(Qe,{title:"加载 Recipe 失败",type:"error"});return}const Ie={[ae]:ue};v(I.id),Q({candidate:I,targetName:G,recipeName:ae,recipeContent:ue,similarList:q.slice(0,3),recipeContents:Ie})},[t==null?void 0:t.recipes]),we=t!=null&&t.candidates?Object.entries(t.candidates):[],Fe=Ql(we,s,a,l),Ee=Fe.map(([I])=>I),ke=se&&Ee.includes(se)?se:Ee[0]??null;r.useEffect(()=>{Ee.length>0&&(!se||!Ee.includes(se))&&h(Ee[0])},[Ee.join(","),se]),r.useEffect(()=>{S&&ke&&Le(ke,S)},[S,ke,Le]);const De=r.useMemo(()=>{var re;if(!ke||!((re=t==null?void 0:t.candidates)!=null&&re[ke]))return null;const I=t.candidates[ke].items,G=I.length,C=I.filter(ye=>{var Se;return((Se=ye.reviewNotes)==null?void 0:Se.priority)==="high"}).length,q=I.filter(ye=>{var Se;return((Se=ye.reviewNotes)==null?void 0:Se.priority)==="medium"}).length,ae=I.filter(ye=>{var Se;return((Se=ye.reviewNotes)==null?void 0:Se.priority)==="low"}).length,ue=I.reduce((ye,Se)=>{var Be;return ye+(((Be=Se.reasoning)==null?void 0:Be.confidence)??0)},0)/(G||1),oe=I.filter(ye=>ye.code&&ye.code.trim().length>0).length,Ie=new Map;return I.forEach(ye=>{const Se=ye.source||"unknown";Ie.set(Se,(Ie.get(Se)||0)+1)}),{total:G,high:C,medium:q,low:ae,avgConfidence:ue,withCode:oe,sources:Ie}},[ke,t==null?void 0:t.candidates]),Ze=r.useCallback(async I=>{var G,C,q,ae,ue;if(!k.has(I)){T(oe=>new Set(oe).add(I));try{const oe=await te.enrichCandidates([I]);oe.enriched>0?ee(`已补齐 ${((q=(C=(G=oe.results)==null?void 0:G[0])==null?void 0:C.filledFields)==null?void 0:q.length)||0} 个结构字段`,{title:"AI 补齐完成"}):ee("无缺失字段,均已完整",{title:"无需补齐",type:"info"});try{const Ie=await te.getCandidate(I);ie(re=>({...re,[I]:Ie}))}catch{}}catch(oe){ee(((ue=(ae=oe.response)==null?void 0:ae.data)==null?void 0:ue.error)||oe.message,{title:"AI 补齐失败",type:"error"})}finally{T(oe=>{const Ie=new Set(oe);return Ie.delete(I),Ie})}}},[k,m]),Ve=r.useCallback(async()=>{var G,C,q;if(B||!ke||!((G=t==null?void 0:t.candidates)!=null&&G[ke]))return;const I=t.candidates[ke].items;if(I.length!==0){K(!0);try{let ae=0;for(let ue=0;ue<I.length;ue+=20){const oe=I.slice(ue,ue+20).map(re=>re.id),Ie=await te.enrichCandidates(oe);ae+=Ie.enriched}ee(`${ae}/${I.length} 条候选已更新`,{title:"① 结构补齐完成"}),m==null||m()}catch(ae){ee(((q=(C=ae.response)==null?void 0:C.data)==null?void 0:q.error)||ae.message,{title:"① 结构补齐失败",type:"error"})}finally{K(!1)}}},[B,ke,t==null?void 0:t.candidates,m]),g=r.useCallback(async I=>{try{const G=await te.getCandidate(I);ie(C=>({...C,[I]:G}))}catch{}},[]),J=r.useCallback(()=>{var C;if(!ke||!((C=t==null?void 0:t.candidates)!=null&&C[ke]))return;const I=t.candidates[ke].items,G=I.map(q=>q.id);M.openRefine({candidateIds:G,candidates:I,onCandidateUpdated:g})},[ke,t==null?void 0:t.candidates,M,g]),Z=r.useCallback(I=>{var C;if(!ke||!((C=t==null?void 0:t.candidates)!=null&&C[ke]))return;Q(null),v(I);const G=t.candidates[ke].items;M.openRefine({candidateIds:[I],candidates:G,onCandidateUpdated:g})},[ke,t==null?void 0:t.candidates,M,g]);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(Ye,{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:[$&&!y&&e.jsxs("button",{onClick:$,disabled:d,className:`flex items-center gap-1.5 px-3.5 py-2 rounded-lg text-xs font-bold transition-all ${d?"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:[d?e.jsx(ze,{size:14,className:"animate-spin"}):e.jsx(Tt,{size:14}),d?"初始化中...":"冷启动"]}),De&&De.total>0&&e.jsxs("button",{onClick:Ve,disabled:B||b,className:`flex items-center gap-1.5 px-3 py-2 rounded-lg text-xs font-bold transition-all ${B||b?"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:[B?e.jsx(ze,{size:14,className:"animate-spin"}):e.jsx(Yt,{size:14}),B?"补齐中...":"① 结构补齐"]}),De&&De.total>0&&e.jsxs("button",{onClick:J,disabled:b||B||_,className:`flex items-center gap-1.5 px-3 py-2 rounded-lg text-xs font-bold transition-all ${b||B||_?"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:[b||_?e.jsx(ze,{size:14,className:"animate-spin"}):e.jsx(Ye,{size:14}),b||_?"润色中...":"② 内容润色"]}),De&&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(Oa,{size:14,className:"text-slate-400"}),e.jsxs("span",{className:"text-slate-500",children:["共 ",e.jsx("strong",{className:"text-slate-700",children:De.total})," 条"]}),De.withCode<De.total&&e.jsxs("span",{className:"text-slate-400 ml-1",children:["(含代码 ",De.withCode,")"]})]}),De.high>0&&e.jsxs("div",{className:"flex items-center gap-1 px-2.5 py-1.5 rounded-lg bg-red-50 border border-red-100",children:[e.jsx("span",{className:"text-red-600 font-bold",children:De.high}),e.jsx("span",{className:"text-red-500",children:"高优先"})]}),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(De.avgConfidence*100),"%"]})]})]})]})]}),H&&e.jsx(Zl,{refine:H,isRefineDone:P,onDismiss:()=>{p(),m==null||m()}}),we.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:Ee.map(I=>{var Ie;s(I);const G=a(I),C=Ts[I],q=t.candidates[I],ae=((Ie=q==null?void 0:q.items)==null?void 0:Ie.length)??0,ue=ke===I,oe=Xe[I]||Xe.All;return e.jsxs("button",{onClick:()=>h(I),className:`flex items-center gap-2 px-3 py-2 rounded-lg text-sm font-bold whitespace-nowrap transition-all border
|
|
96
|
+
${ue?`${(oe==null?void 0:oe.bg)||"bg-blue-50"} ${(oe==null?void 0:oe.color)||"text-blue-700"} ${(oe==null?void 0:oe.border)||"border-blue-200"} shadow-sm ring-1 ring-inset ${(oe==null?void 0:oe.border)||"ring-blue-200"}`:"bg-slate-50/80 text-slate-600 border-slate-100 hover:border-slate-200 hover:bg-slate-100"}`,children:[(()=>{const re=(oe==null?void 0:oe.icon)||Qt;return e.jsx(re,{size:z.sm,className:ue?"":"text-slate-400"})})(),e.jsx("span",{children:$s[I]||I}),G&&C&&e.jsx("span",{className:"text-[9px] text-amber-600 border border-amber-200 px-1 rounded",children:C}),e.jsx("span",{className:`text-[10px] font-normal rounded-full px-1.5 ${ue?"bg-white/60":"bg-slate-200/60 text-slate-400"}`,children:ae})]},I)})})}),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(Ys,{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 命令手动创建"}),$&&e.jsxs("button",{onClick:$,disabled:d,className:`mt-4 flex items-center gap-2 px-5 py-2.5 rounded-xl text-sm font-bold transition-all ${d?"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:[d?e.jsx(ze,{size:16,className:"animate-spin"}):e.jsx(Tt,{size:16}),d?"正在初始化...":"冷启动:初始化知识库"]}),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(ze,{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&&ke&&Fe.filter(([I])=>I===ke).map(([I,G])=>{const C=s(I),q=a(I),ae=Ts[I]||"静默",ue=w[I]||{page:1,pageSize:12},oe=ue.page,Ie=ue.pageSize,re=G.items.filter(j=>{var he;if(Ne.priority!=="all"&&((he=j.reviewNotes)==null?void 0:he.priority)!==Ne.priority)return!1;if(Ne.onlySimilar){const Ce=j.relatedRecipes;if(!Array.isArray(Ce)||Ce.length===0)return!1}return!0}).sort((j,he)=>{var Ce,je,Te,Me,Pe,be;if(Ne.sort==="default")return 0;if(Ne.sort==="score-desc")return(((Ce=he.quality)==null?void 0:Ce.overallScore)??0)-(((je=j.quality)==null?void 0:je.overallScore)??0);if(Ne.sort==="score-asc")return(((Te=j.quality)==null?void 0:Te.overallScore)??0)-(((Me=he.quality)==null?void 0:Me.overallScore)??0);if(Ne.sort==="confidence-desc")return(((Pe=he.reasoning)==null?void 0:Pe.confidence)??0)-(((be=j.reasoning)==null?void 0:be.confidence)??0);if(Ne.sort==="date-desc"){const Ue=typeof j.createdAt=="number"?j.createdAt:Number(j.createdAt)||0;return(typeof he.createdAt=="number"?he.createdAt:Number(he.createdAt)||0)-Ue}return 0}),ye=re.length,Se=Math.ceil(ye/Ie),Be=(oe-1)*Ie,Ae=re.slice(Be,Be+Ie),He=j=>{E(he=>({...he,[I]:{...ue,page:j}}))},Qe=j=>{E(he=>({...he,[I]:{page:1,pageSize:j}}))},de=Xe[I]||Xe.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 j=(de==null?void 0:de.icon)||Qt;return e.jsx(j,{size:18,className:(de==null?void 0:de.color)||"text-blue-600"})})(),e.jsx("span",{className:"text-base font-bold text-slate-800 truncate",children:$s[I]||I}),q&&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:ae}),C&&!q&&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(Nt,{size:11}),"扫描于 ",Rt(G.scanTime)||new Date(G.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(Xs,{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:Ne.priority,onChange:j=>Re(he=>({...he,priority:j.target.value})),children:[e.jsx("option",{value:"all",children:"全部优先级"}),e.jsx("option",{value:"high",children:"🔴 高优先"}),e.jsx("option",{value:"medium",children:"🟡 中优先"}),e.jsx("option",{value:"low",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(Vs,{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:Ne.sort,onChange:j=>Re(he=>({...he,sort:j.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:Ne.onlySimilar,onChange:j=>Re(he=>({...he,onlySimilar:j.target.checked})),className:"rounded text-blue-600 w-3 h-3"}),"只看相似"]}),(Ne.priority!=="all"||Ne.sort!=="default"||Ne.onlySimilar)&&e.jsx("button",{onClick:()=>Re({priority:"all",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:[ye," 条"]}),e.jsx("button",{onClick:()=>i(Ae,I),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(`确定移除当前页的 ${Ae.length} 条候选?`))return;const he=(await Promise.allSettled(Ae.map(Ce=>n(I,Ce.id)))).filter(Ce=>Ce.status==="rejected").length;he>0&&ee(`${he} 条候选移除时出错`,{title:"部分删除失败",type:"error"}),m==null||m()},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:()=>o(I),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:Ae.map(j=>{var D,W,O,pe,le;const he=S===j.id,Ce=((D=j.reasoning)==null?void 0:D.confidence)??null,je=((W=j.quality)==null?void 0:W.overallScore)??null,Te=(O=j.reviewNotes)==null?void 0:O.priority,Me=sr(Te),Pe=(pe=j.relatedRecipes)==null?void 0:pe[0],be=V[j.id]||[],Ue=Ms[j.source||""]||{label:j.source||"",color:"text-slate-500 bg-slate-50 border-slate-200"},_e=Xe[j.category||""]||Xe.All||{},N=((_e==null?void 0:_e.color)||"text-blue-600").replace("text-","border-l-");return e.jsxs("div",{onClick:()=>v(he?null:j.id),className:`bg-white rounded-xl border overflow-hidden hover:shadow-lg transition-all duration-200 flex flex-col group cursor-pointer
|
|
97
97
|
${C?"opacity-75":""}
|
|
98
|
-
${he?"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] ${N} 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 ${(
|
|
98
|
+
${he?"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] ${N} px-4 pt-3.5 pb-2`,children:e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-1.5 mb-1.5",children:[e.jsxs("span",{className:`text-[10px] font-bold px-1.5 py-0.5 rounded uppercase flex items-center gap-1 border ${(_e==null?void 0:_e.bg)||"bg-slate-50"} ${(_e==null?void 0:_e.color)||"text-slate-400"} ${(_e==null?void 0:_e.border)||"border-slate-100"}`,children:[(()=>{const xe=(_e==null?void 0:_e.icon)||gt;return e.jsx(xe,{size:10})})(),j.category||"general"]}),j.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:j.knowledgeType}),j.source&&j.source!=="unknown"&&e.jsx("span",{className:`text-[10px] font-medium px-1.5 py-0.5 rounded border ${Ue.color}`,children:Ue.label}),j.complexity&&e.jsx("span",{className:`text-[10px] font-medium px-1.5 py-0.5 rounded border
|
|
99
99
|
${j.complexity==="advanced"?"bg-red-50 text-red-600 border-red-100":j.complexity==="intermediate"?"bg-amber-50 text-amber-600 border-amber-100":"bg-emerald-50 text-emerald-600 border-emerald-100"}`,children:j.complexity==="advanced"?"高级":j.complexity==="intermediate"?"中级":"初级"})]}),e.jsx("h3",{className:"font-bold text-sm text-slate-800 leading-snug mb-1 line-clamp-1",children:j.title}),e.jsx("p",{className:"text-xs text-slate-500 line-clamp-2 leading-relaxed",children:j.summary||j.summary_cn||""})]}),e.jsxs("div",{className:"flex flex-col items-center gap-1 shrink-0",children:[e.jsx(Gs,{value:Ce}),e.jsx("span",{className:"text-[9px] text-slate-400 font-medium",children:"置信度"})]})]})}),((le=j.reasoning)==null?void 0:le.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(It,{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:j.reasoning.whyStandard})]})}),(je!=null||Me||Pe)&&e.jsxs("div",{className:"flex flex-wrap items-center gap-1.5 px-4 py-2 border-t border-slate-50",children:[je!=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(Zs,{size:10}),"综合 ",(je*100).toFixed(0),"%"]}),Me&&e.jsxs("span",{className:`text-[10px] font-bold px-2 py-0.5 rounded-full border flex items-center gap-1 ${Me.bg} ${Me.text} ${Me.border}`,children:[Me.icon," ",Te==="high"?"高优先":Te==="medium"?"中优先":"低优先"]}),Pe&&e.jsxs("button",{onClick:xe=>{xe.stopPropagation();const ce=String(Pe.id||Pe.title||"").trim();ce&&Ge(j,I,ce,be)},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(Mt,{size:10}),"相似 ",String(Pe.title||Pe.id||"").replace(/\.md$/i,"")," ",((Pe.similarity??0)*100).toFixed(0),"%"]})]}),j.code&&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(es,{size:11,className:"text-slate-500"}),e.jsx("span",{className:"text-[10px] text-slate-400 font-mono uppercase tracking-wide",children:j.language||"code"})]}),e.jsxs("span",{className:"text-[10px] text-slate-500 font-mono tabular-nums",children:[j.code.split(`
|
|
100
100
|
`).length," 行"]})]}),e.jsxs("div",{className:"relative max-h-[80px] overflow-hidden",children:[e.jsx(At,{code:er(j.code,3),language:j.language==="objc"?"objectivec":j.language,className:"!rounded-none"}),j.code.split(`
|
|
101
|
-
`).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:xe=>xe.stopPropagation(),children:[e.jsxs("div",{className:"flex items-center gap-2 flex-wrap min-w-0",children:[j.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:j.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:j.language}),j.tags&&j.tags.length>0&&j.tags.slice(0,3).map((xe,ce)=>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 xe=="string"?xe:String(xe)},ce)),j.tags&&j.tags.length>3&&e.jsxs("span",{className:"text-[9px] text-slate-400",children:["+",j.tags.length-3]}),j.createdAt&&Rt(j.createdAt)&&e.jsxs("span",{className:"text-[9px] text-slate-400 flex items-center gap-0.5",children:[e.jsx(Nt,{size:9}),Rt(j.createdAt)]})]}),e.jsxs("div",{className:"flex items-center gap-1.5 shrink-0",children:[e.jsx("button",{onClick:()=>Ze(j.id),disabled:k.has(j.id),title:"① 结构补齐:填充缺失的语义字段(rationale / knowledgeType / complexity 等)",className:`p-1.5 rounded-lg transition-colors flex items-center gap-1 text-[11px] font-medium ${k.has(j.id)?"text-slate-300 cursor-not-allowed":"text-amber-500 hover:text-amber-600 hover:bg-amber-50"}`,children:k.has(j.id)?e.jsx(
|
|
101
|
+
`).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:xe=>xe.stopPropagation(),children:[e.jsxs("div",{className:"flex items-center gap-2 flex-wrap min-w-0",children:[j.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:j.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:j.language}),j.tags&&j.tags.length>0&&j.tags.slice(0,3).map((xe,ce)=>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 xe=="string"?xe:String(xe)},ce)),j.tags&&j.tags.length>3&&e.jsxs("span",{className:"text-[9px] text-slate-400",children:["+",j.tags.length-3]}),j.createdAt&&Rt(j.createdAt)&&e.jsxs("span",{className:"text-[9px] text-slate-400 flex items-center gap-0.5",children:[e.jsx(Nt,{size:9}),Rt(j.createdAt)]})]}),e.jsxs("div",{className:"flex items-center gap-1.5 shrink-0",children:[e.jsx("button",{onClick:()=>Ze(j.id),disabled:k.has(j.id),title:"① 结构补齐:填充缺失的语义字段(rationale / knowledgeType / complexity 等)",className:`p-1.5 rounded-lg transition-colors flex items-center gap-1 text-[11px] font-medium ${k.has(j.id)?"text-slate-300 cursor-not-allowed":"text-amber-500 hover:text-amber-600 hover:bg-amber-50"}`,children:k.has(j.id)?e.jsx(ze,{size:14,className:"animate-spin"}):e.jsx(Yt,{size:14})}),e.jsx("button",{onClick:()=>Z(j.id),disabled:L.has(j.id),title:"② 内容润色:改善描述、补充洞察、推断关联(支持自定义提示词)",className:`p-1.5 rounded-lg transition-colors flex items-center gap-1 text-[11px] font-medium ${L.has(j.id)?"text-slate-300 cursor-not-allowed":"text-emerald-500 hover:text-emerald-600 hover:bg-emerald-50"}`,children:L.has(j.id)?e.jsx(ze,{size:14,className:"animate-spin"}):e.jsx(Ye,{size:14})}),e.jsx("button",{onClick:()=>{n(I,j.id),S===j.id&&(v(null),Q(null))},title:"忽略",className:"p-1.5 hover:bg-red-50 text-slate-400 hover:text-red-500 rounded-lg transition-colors",children:e.jsx(ht,{size:14})}),e.jsxs("button",{onClick:()=>c(j,I),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(mt,{size:12})," 审核并保存"]}),j.status==="approved"&&e.jsxs("button",{onClick:async()=>{try{await te.promoteCandidateToRecipe(j.id),ee("候选已成功提升为正式 Recipe",{title:"提升成功"}),m==null||m()}catch(xe){ee(xe.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(Tt,{size:12})," 提升为 Recipe"]})]})]})]},j.id)})}),ye>12&&e.jsx(xa,{currentPage:oe,totalPages:Se,totalItems:ye,pageSize:Ie,onPageChange:He,onPageSizeChange:Qe})]},I)})]}),S&&ke&&((u=t==null?void 0:t.candidates)==null?void 0:u[ke])&&(()=>{var Qe;const I=t.candidates[ke].items,G=I.find(de=>de.id===S);if(!G)return null;const C=Y[S]||G,q=I.findIndex(de=>de.id===S),ae=q>0,ue=q<I.length-1,oe=()=>{ae&&(v(I[q-1].id),Q(null))},Ie=()=>{ue&&(v(I[q+1].id),Q(null))},re=C.reasoning,ye=re&&(re.whyStandard||re.sources&&re.sources.length>0||re.confidence!=null),Se=V[C.id]||[],Be=F===C.id,Ae=Xe[C.category||""]||Xe.All||{},He=Ms[C.source||""]||{label:C.source||"",color:"text-slate-500 bg-slate-50 border-slate-200"};return e.jsxs(We,{className:"z-30 flex justify-end",onClick:()=>{v(null),Q(null)},children:[e.jsx(We.Backdrop,{className:"bg-black/15 backdrop-blur-[1px]"}),fe&&(()=>{const de=fe.candidate,j=de.language==="objc"||de.language==="objective-c"?"objectivec":de.language||"text",he=()=>{const be=[];de.code&&be.push("## Snippet / Code Reference\n\n```"+j+`
|
|
102
102
|
`+de.code+"\n```"),de.usageGuide&&be.push(`
|
|
103
103
|
## AI Context / Usage Guide
|
|
104
104
|
|
|
105
105
|
`+de.usageGuide),navigator.clipboard.writeText(be.join(`
|
|
106
|
-
`)||"").then(()=>ee("候选内容已复制到剪贴板",{title:"已复制"}))},Ce=()=>{const be=Ns(fe.recipeContent);navigator.clipboard.writeText(be).then(()=>ee("Recipe 内容已复制到剪贴板",{title:"已复制"}))},je=async be=>{var ze;if(be===fe.recipeName)return;const Ue=fe.recipeContents[be];if(Ue)Q(N=>N?{...N,recipeName:be,recipeContent:Ue}:null);else{let N="";const D=(ze=t==null?void 0:t.recipes)==null?void 0:ze.find(W=>W.name===be||W.name.endsWith("/"+be));if(D!=null&&D.content)N=D.content;else try{N=(await te.getRecipeContentByName(be)).content}catch{return}Q(W=>W?{...W,recipeName:be,recipeContent:N,recipeContents:{...W.recipeContents,[be]:N}}:null)}},Te=async()=>{if(window.confirm("确定删除该候选?"))try{await n(fe.targetName,de.id),Q(null)}catch(be){ee((be==null?void 0:be.message)||"删除失败",{title:"删除失败",type:"error"})}},Me=()=>{c(de,fe.targetName),Q(null)},Pe=()=>{var Ue;const be=((Ue=t==null?void 0:t.recipes)==null?void 0:Ue.find(ze=>ze.name===fe.recipeName||ze.name.endsWith("/"+fe.recipeName)))||{name:fe.recipeName,content:fe.recipeContent};x==null||x(be),Q(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:be=>be.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(Mt,{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:fe.recipeName.replace(/\.md$/i,"")})]})]}),e.jsxs("div",{className:"flex items-center gap-1.5 shrink-0 ml-2",children:[e.jsx("button",{onClick:()=>Ce(),className:"p-1.5 hover:bg-emerald-100 rounded-lg text-emerald-600 transition-colors",title:"复制",children:e.jsx(Ft,{size:14})}),e.jsx("button",{onClick:Pe,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:()=>Q(null),className:"p-1.5 hover:bg-slate-200 rounded-lg transition-colors text-slate-400",children:e.jsx(Ke,{size:16})})]})]}),fe.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:fe.similarList.map(be=>e.jsxs("button",{onClick:()=>je(be.recipeName),className:`text-[10px] font-bold px-2 py-1 rounded transition-colors ${fe.recipeName===be.recipeName?"bg-emerald-200 text-emerald-800":"bg-white text-emerald-600 hover:bg-emerald-50 border border-emerald-100"}`,children:[be.recipeName.replace(/\.md$/i,"")," ",(be.similarity*100).toFixed(0),"%"]},be.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:Te,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(ht,{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(mt,{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(Ft,{size:12})," 复制候选"]})]}),e.jsx("div",{className:"flex-1 overflow-auto p-5 min-h-0",children:e.jsx(lt,{content:fe.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:de=>de.stopPropagation(),children:[e.jsxs("div",{className:"flex items-center justify-between px-5 py-3.5 border-b border-slate-200 shrink-0 bg-slate-50/80",children:[e.jsxs("div",{className:"flex items-center gap-3 flex-1 min-w-0",children:[e.jsx(Gs,{value:((Qe=C.reasoning)==null?void 0:Qe.confidence)??null,size:40}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("h3",{className:"font-bold text-sm text-slate-800 truncate",children:C.title}),e.jsxs("div",{className:"flex items-center gap-1.5 mt-0.5 flex-wrap",children:[e.jsx("span",{className:`text-[10px] font-bold px-1.5 py-0.5 rounded uppercase flex items-center gap-1 border ${(Ae==null?void 0:Ae.bg)||"bg-slate-50"} ${(Ae==null?void 0:Ae.color)||"text-slate-400"} ${(Ae==null?void 0:Ae.border)||"border-slate-100"}`,children:C.category||"general"}),C.source&&C.source!=="unknown"&&e.jsx("span",{className:`text-[10px] font-medium px-1.5 py-0.5 rounded border ${He.color}`,children:He.label}),e.jsxs("span",{className:"text-[10px] text-slate-400",children:[q+1,"/",I.length]})]})]})]}),e.jsxs("div",{className:"flex items-center gap-1 shrink-0 ml-2",children:[e.jsx("button",{onClick:oe,disabled:!ae,title:"上一条",className:`p-1.5 rounded-lg transition-colors ${ae?"hover:bg-slate-200 text-slate-500":"text-slate-300 cursor-not-allowed"}`,children:e.jsx(Ba,{size:16})}),e.jsx("button",{onClick:Ie,disabled:!ue,title:"下一条",className:`p-1.5 rounded-lg transition-colors ${ue?"hover:bg-slate-200 text-slate-500":"text-slate-300 cursor-not-allowed"}`,children:e.jsx(kt,{size:16})}),e.jsx("button",{onClick:f,className:"p-1.5 hover:bg-slate-200 rounded-lg transition-colors text-slate-400",title:A?"收窄面板":"展开更宽",children:A?e.jsx(qs,{size:16}):e.jsx(js,{size:16})}),e.jsx("button",{onClick:()=>{v(null),Q(null)},className:"p-1.5 hover:bg-slate-200 rounded-lg transition-colors text-slate-400",children:e.jsx(Ke,{size:18})})]})]}),e.jsxs("div",{className:"flex-1 overflow-y-auto px-5 py-4 space-y-4",children:[e.jsx("p",{className:"text-sm text-slate-600 leading-relaxed",children:C.summary||C.summary_cn||""}),e.jsxs("div",{className:"flex flex-wrap gap-1.5",children:[C.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:C.knowledgeType}),C.complexity&&e.jsx("span",{className:`text-[10px] font-medium px-1.5 py-0.5 rounded border ${C.complexity==="advanced"?"bg-red-50 text-red-600 border-red-100":C.complexity==="intermediate"?"bg-amber-50 text-amber-600 border-amber-100":"bg-emerald-50 text-emerald-600 border-emerald-100"}`,children:C.complexity==="advanced"?"高级":C.complexity==="intermediate"?"中级":"初级"}),C.trigger&&e.jsx("span",{className:"text-[10px] font-mono px-1.5 py-0.5 rounded bg-white border border-slate-200 text-slate-600 font-bold",children:C.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",children:C.language}),C.tags&&C.tags.slice(0,5).map((de,j)=>e.jsx("span",{className:"text-[9px] px-1.5 py-0.5 rounded bg-blue-50 text-blue-600 border border-blue-100 font-medium",children:typeof de=="string"?de:String(de)},j)),C.createdAt&&Rt(C.createdAt)&&e.jsxs("span",{className:"text-[9px] text-slate-400 flex items-center gap-0.5",children:[e.jsx(Nt,{size:9})," ",Rt(C.createdAt)]})]}),(ye||C.quality)&&e.jsxs("div",{className:"rounded-xl border border-indigo-100 bg-indigo-50/40 p-4 text-xs space-y-3",children:[e.jsxs("div",{className:"flex items-center gap-1.5 text-indigo-700 font-bold text-[11px]",children:[e.jsx(It,{size:14}),"AI 推理过程"]}),ye?e.jsxs(e.Fragment,{children:[re.whyStandard&&e.jsxs("div",{children:[e.jsxs("span",{className:"text-indigo-600 font-bold flex items-center gap-1 mb-0.5",children:[e.jsx(ts,{size:10})," 为什么是标准用法"]}),e.jsx("p",{className:"text-slate-600 leading-relaxed pl-3",children:re.whyStandard})]}),re.sources&&re.sources.length>0&&e.jsxs("div",{children:[e.jsxs("span",{className:"text-indigo-600 font-bold flex items-center gap-1 mb-0.5",children:[e.jsx(at,{size:10})," 来源"]}),e.jsx("ul",{className:"pl-3 text-slate-600 space-y-0.5",children:re.sources.map((de,j)=>e.jsxs("li",{className:"flex items-start gap-1",children:[e.jsx("span",{className:"text-indigo-400 mt-0.5",children:"•"}),de]},j))})]}),re.confidence!=null&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-indigo-600 font-bold",children:"置信度"}),e.jsx("div",{className:"flex-1 max-w-[200px] bg-indigo-100 rounded-full h-2 overflow-hidden",children:e.jsx("div",{className:`h-full rounded-full transition-all ${re.confidence>=.7?"bg-emerald-500":re.confidence>=.4?"bg-amber-500":"bg-red-500"}`,style:{width:`${Math.round((re.confidence??0)*100)}%`}})}),e.jsxs("span",{className:`font-bold ${re.confidence>=.7?"text-emerald-600":re.confidence>=.4?"text-amber-600":"text-red-600"}`,children:[Math.round((re.confidence??0)*100),"%"]})]})]}):e.jsx("p",{className:"text-slate-400 italic pl-3",children:"暂无推理信息"})]}),(C.agentNotes||C.aiInsight||C.refinedConfidence!=null||C.relations&&C.relations.length>0)&&e.jsxs("div",{className:"rounded-xl border border-emerald-100 bg-emerald-50/40 p-4 text-xs space-y-3",children:[e.jsxs("div",{className:"flex items-center gap-1.5 text-emerald-700 font-bold text-[11px]",children:[e.jsx(Ye,{size:14}),"润色增强信息",C.refinedConfidence!=null&&e.jsxs("span",{className:"ml-auto text-emerald-600 font-mono text-[10px]",children:["润色置信度: ",Math.round(C.refinedConfidence*100),"%"]})]}),C.aiInsight&&e.jsxs("div",{children:[e.jsxs("span",{className:"text-emerald-600 font-bold flex items-center gap-1 mb-0.5",children:[e.jsx(Lt,{size:10})," 架构洞察"]}),e.jsx("p",{className:"text-slate-600 leading-relaxed pl-3",children:C.aiInsight})]}),C.agentNotes&&C.agentNotes.length>0&&e.jsxs("div",{children:[e.jsxs("span",{className:"text-emerald-600 font-bold flex items-center gap-1 mb-0.5",children:[e.jsx(Ct,{size:10})," Agent 笔记"]}),e.jsx("ul",{className:"pl-3 text-slate-600 space-y-0.5",children:C.agentNotes.map((de,j)=>e.jsxs("li",{className:"flex items-start gap-1",children:[e.jsx("span",{className:"text-emerald-400 mt-0.5",children:"•"}),de]},j))})]}),C.relations&&C.relations.length>0&&e.jsxs("div",{children:[e.jsxs("span",{className:"text-emerald-600 font-bold flex items-center gap-1 mb-0.5",children:[e.jsx(Mt,{size:10})," 关联关系"]}),e.jsx("div",{className:"pl-3 space-y-1",children:C.relations.map((de,j)=>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:de.type}),e.jsx("span",{className:"font-medium text-slate-700",children:de.target}),de.description&&e.jsxs("span",{className:"text-slate-400",children:["— ",de.description]})]},j))})]})]}),(Se.length>0||Be)&&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:"}),Be?e.jsx("span",{className:"text-[10px] text-slate-400 animate-pulse",children:"加载中..."}):Se.slice(0,5).map(de=>e.jsxs("button",{onClick:()=>Ge(C,ke,de.recipeName,Se),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:`与 ${de.recipeName} 相似 ${(de.similarity*100).toFixed(0)}%`,children:[e.jsx(Mt,{size:10}),de.recipeName.replace(/\.md$/i,"")," ",(de.similarity*100).toFixed(0),"%"]},de.recipeName))]}),C.code&&e.jsxs("div",{className:"-mx-5 overflow-hidden border-y border-slate-200",children:[e.jsxs("div",{className:"flex items-center justify-between px-3 py-2",style:{background:"#282c34"},children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(es,{size:12,className:"text-slate-400"}),e.jsx("span",{className:"text-[11px] text-slate-400 font-mono uppercase tracking-wide",children:C.language||"code"})]}),e.jsxs("span",{className:"text-[10px] text-slate-500 font-mono tabular-nums",children:[C.code.split(`
|
|
107
|
-
`).length," 行"]})]}),e.jsx(At,{code:C.code,language:C.language==="objc"?"objectivec":C.language,showLineNumbers:!0,className:"!rounded-none"})]}),C.usageGuide&&e.jsxs("div",{className:"rounded-xl border border-slate-100 bg-white p-4",children:[e.jsxs("div",{className:"flex items-center gap-1.5 text-[11px] font-bold text-slate-600 mb-2",children:[e.jsx(at,{size:12})," 使用指南"]}),e.jsx("div",{className:"prose prose-sm prose-slate max-w-none",children:e.jsx(lt,{content:C.usageGuide})})]}),(C.scope||C.headers&&C.headers.length>0||C.steps&&C.steps.length>0||C.rationale)&&e.jsxs("div",{className:"rounded-xl border border-slate-100 bg-slate-50 p-4 space-y-2",children:[e.jsxs("div",{className:"text-[11px] font-bold text-slate-600 flex items-center gap-1.5 mb-1",children:[e.jsx(gt,{size:12})," 附加信息"]}),C.scope&&e.jsxs("div",{className:"text-xs text-slate-500",children:["范围:",e.jsx("strong",{className:"text-slate-700",children:C.scope==="universal"?"通用":C.scope==="project-specific"?"项目级":"模块级"})]}),C.headers&&C.headers.length>0&&e.jsxs("div",{className:"text-xs text-slate-500",children:["头文件:",e.jsx("strong",{className:"text-slate-700",children:C.headers.join(", ")})]}),C.steps&&C.steps.length>0&&e.jsxs("div",{className:"text-xs text-slate-500",children:[e.jsxs("span",{className:"font-medium",children:["实施步骤(",C.steps.length," 步):"]}),e.jsx("ol",{className:"mt-1 ml-4 list-decimal space-y-0.5",children:C.steps.map((de,j)=>e.jsx("li",{className:"text-slate-600",children:typeof de=="string"?de:de.description||String(de)},j))})]}),C.rationale&&e.jsxs("div",{className:"text-xs text-slate-500",children:["设计原理:",e.jsx("span",{className:"text-slate-700",children:C.rationale})]})]})]}),e.jsxs("div",{className:"shrink-0 border-t border-slate-200 px-5 py-3 bg-slate-50/80 flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("button",{onClick:()=>Ze(C.id),disabled:k.has(C.id),title:"① 结构补齐",className:`flex items-center gap-1.5 px-3 py-2 rounded-lg text-xs font-medium transition-colors ${k.has(C.id)?"text-slate-300 cursor-not-allowed":"text-amber-600 hover:bg-amber-50 border border-amber-200"}`,children:[k.has(C.id)?e.jsx(_e,{size:14,className:"animate-spin"}):e.jsx(Yt,{size:14}),"补齐"]}),e.jsxs("button",{onClick:()=>Z(C.id),disabled:L.has(C.id),title:"② 内容润色",className:`flex items-center gap-1.5 px-3 py-2 rounded-lg text-xs font-medium transition-colors ${L.has(C.id)?"text-slate-300 cursor-not-allowed":"text-emerald-600 hover:bg-emerald-50 border border-emerald-200"}`,children:[L.has(C.id)?e.jsx(_e,{size:14,className:"animate-spin"}):e.jsx(Ye,{size:14}),"润色"]}),e.jsxs("button",{onClick:()=>{n(ke,C.id),v(null),Q(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(ht,{size:14})," 删除"]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[C.status==="approved"&&e.jsxs("button",{onClick:async()=>{try{await te.promoteCandidateToRecipe(C.id),ee("候选已成功提升为正式 Recipe",{title:"提升成功"}),m==null||m()}catch(de){ee(de.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(Tt,{size:14})," 提升为 Recipe"]}),e.jsxs("button",{onClick:()=>{c(C,ke),v(null),Q(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(mt,{size:14})," 审核并保存"]})]})]})]})]})})()]})},lr=({isOpen:t,onClose:s,currentFile:a,targetName:l,language:n="swift",onSelectRecipe:o})=>{var K,b,R,M;const[c,i]=r.useState(""),[x,$]=r.useState([]),[d,y]=r.useState(null),[m,S]=r.useState(!1),[v,A]=r.useState(null),[f,k]=r.useState(!1),[T,L]=r.useState(null),U=async()=>{if(c.trim()){S(!0);try{const H=await te.contextAwareSearch({keyword:c,targetName:l,currentFile:a,language:n,limit:10});$(H.results||[]),y(H.context)}catch(H){console.error("Context-aware search failed:",H),alert("搜索失败。请重试。")}finally{S(!1)}}},B=H=>{H.key==="Enter"&&U()};return t?e.jsxs(We,{className:"z-30 flex",children:[e.jsx(We.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:_.lg,className:"text-slate-500"})})]}),d&&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(st,{size:_.md,className:"text-blue-600 mt-0.5 shrink-0"}),e.jsxs("div",{className:"flex-1",children:[((K=d.targetInfo)==null?void 0:K.targetName)&&e.jsxs("div",{className:"text-blue-900 font-medium flex items-center gap-2 mb-1",children:[e.jsx(ts,{size:_.sm}),"Target: ",d.targetInfo.targetName]}),((b=d.fileInfo)==null?void 0:b.imports)&&d.fileInfo.imports.length>0&&e.jsxs("div",{className:"text-blue-800 text-xs mt-2",children:[e.jsx("strong",{children:"导入的框架:"})," ",d.fileInfo.imports.slice(0,3).join(", "),d.fileInfo.imports.length>3&&` +${d.fileInfo.imports.length-3}`]}),((R=d.targetInfo)==null?void 0:R.suggestedApis)&&d.targetInfo.suggestedApis.length>0&&e.jsxs("div",{className:"text-blue-800 text-xs mt-1",children:[e.jsx("strong",{children:"相关 APIs:"})," ",d.targetInfo.suggestedApis.slice(0,3).join(", ")]})]})]})}),e.jsxs("div",{className:"relative",children:[e.jsx(pt,{className:"absolute left-3 top-1/2 -translate-y-1/2 text-slate-400",size:_.md}),e.jsx("input",{type:"text",placeholder:"输入搜索关键词...",value:c,onChange:H=>i(H.target.value),onKeyDown:B,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:U,disabled:!c.trim()||m,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:[m&&e.jsx(_e,{size:_.sm,className:"animate-spin"}),m?"搜索中...":"搜索"]})]}),e.jsxs("div",{className:"flex-1 overflow-auto",children:[x.length===0&&!m&&e.jsx("div",{className:"flex items-center justify-center h-full text-slate-500",children:e.jsxs("div",{className:"text-center",children:[e.jsx(ss,{size:_.xxl,className:"mx-auto mb-2 opacity-50"}),e.jsx("p",{className:"text-sm",children:"输入关键词后点击搜索"})]})}),x.map((H,z)=>e.jsxs("div",{className:"border-b border-slate-200 p-4 hover:bg-slate-50 transition-colors cursor-pointer",onClick:()=>{A(v===z?null:z),H.name&&(o==null||o(H.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:H.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(st,{size:_.xs}),Math.round(H.similarity*100),"%"]}),H.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(ts,{size:_.xs}),"上下文相关"]}),H.matchType&&e.jsx("span",{className:"text-xs text-slate-500",children:H.matchType==="semantic"?"语义匹配":"关键词匹配"})]})]}),e.jsx("button",{onClick:P=>{P.stopPropagation(),A(v===z?null:z)},className:"p-1 hover:bg-slate-200 rounded transition-colors",children:v===z?"▼":"▶"})]}),H.stats&&e.jsxs("div",{className:"text-xs text-slate-500 mb-2 flex gap-3",children:[H.stats.authorityScore!==void 0&&e.jsxs("span",{children:["权威分: ",H.stats.authorityScore]}),H.usageCount!==void 0&&e.jsxs("span",{children:["使用: ",H.usageCount,"次"]})]}),v===z&&e.jsxs("div",{className:"mt-3 pt-3 border-t border-slate-200",children:[H.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:H.recommendReason})]}),e.jsxs("div",{className:"text-xs text-slate-600 max-h-[200px] overflow-auto bg-slate-50 p-3 rounded",children:[H.content.substring(0,500),"..."]}),e.jsx("button",{onClick:P=>{P.stopPropagation(),L(H),k(!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:"查看完整内容"})]})]},z)),m&&e.jsx("div",{className:"flex items-center justify-center h-32",children:e.jsx(_e,{size:_.lg,className:"animate-spin text-blue-600"})}),x.length===0&&c&&!m&&e.jsx("div",{className:"flex items-center justify-center h-32",children:e.jsxs("div",{className:"text-center text-slate-500",children:[e.jsx(ys,{size:_.xl,className:"mx-auto mb-2 opacity-50"}),e.jsx("p",{className:"text-sm",children:"未找到匹配的结果"})]})})]})]}),f&&T&&e.jsxs(We,{className:"z-40 flex items-center justify-center p-4",children:[e.jsx(We.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:T.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(T.similarity*100),"%"]}),T.isContextRelevant&&e.jsx("span",{className:"text-xs bg-green-100 text-green-700 px-2 py-1 rounded",children:"✓ 上下文相关"}),T.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:["🤖 质量: ",(T.qualityScore*100).toFixed(0),"%"]}),((M=T.stats)==null?void 0:M.authorityScore)!==void 0&&e.jsxs("span",{className:"text-xs bg-purple-100 text-purple-700 px-2 py-1 rounded",children:["权威分: ",Math.round(T.stats.authorityScore*100)/100]})]})]}),e.jsx("button",{onClick:()=>k(!1),className:"p-1 hover:bg-slate-100 rounded transition-colors shrink-0",children:e.jsx(Ke,{size:_.lg,className:"text-slate-500"})})]}),e.jsx("div",{className:"overflow-auto flex-1 p-6",children:e.jsx("div",{className:"prose prose-sm max-w-none",children:T.content?e.jsx(At,{code:T.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:()=>k(!1),className:"px-4 py-2 text-slate-700 hover:bg-slate-200 rounded transition-colors text-sm font-medium",children:"关闭"}),o&&e.jsxs("button",{onClick:()=>{o(T.name),k(!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(it,{size:_.md}),"使用此片段"]})]})]})]})]}):null},Ds=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 n=t.match(/^import\s+(\w+)/);n&&s.push(n[1]);const o=t.match(/@import\s+(\w+)/);return o&&s.push(o[1]),[...new Set(s.filter(Boolean))]}function Et(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 nr(t){return t.startsWith("#import ")||t.startsWith("import ")||t.startsWith("@import ")?t.trim():t.startsWith("<")||t.startsWith('"')?`#import ${t.trim()}`:t.trim()}const ir=({res:t,index:s,editingCodeIndex:a,setEditingCodeIndex:l,translatingIndex:n,expandedEditIndex:o,setExpandedEditIndex:c,similarityMap:i,handleUpdateScanResult:x,handleSaveExtracted:$,handlePromoteToCandidate:d,handleContentLangChange:y,openCompare:m,isSavingRecipe:S=!1})=>{const v=o===s,A=t.headers||[];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:"Recipe Title"}),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(gt,{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(st,{size:10})," ",t.candidateTargetName||"TARGET"]}):null]}),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:f=>x(s,{title:f.target.value})})]}),e.jsxs("div",{className:"flex gap-2 shrink-0 pt-3",children:[d&&e.jsxs("button",{onClick:()=>d(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(Ua,{size:_.md}),"Candidate"]}),e.jsxs("button",{onClick:()=>$(t),disabled: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 disabled:opacity-60 disabled:cursor-not-allowed whitespace-nowrap ${t.mode==="full"?"bg-blue-600 text-white hover:bg-blue-700":"bg-amber-600 text-white hover:bg-amber-700"}`,children:[S?e.jsx(_e,{size:_.md,className:"animate-spin"}):e.jsx(Qs,{size:_.md}),S?"保存中...":"保存为 Recipe"]})]})]}),e.jsxs("div",{className:"flex items-end gap-4 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-40",value:t.trigger,placeholder:"@cmd",onChange:f=>x(s,{trigger:f.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:"Category"}),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:f=>x(s,{category:f.target.value}),children:xl.filter(f=>f!=="All").map(f=>e.jsx("option",{value:f,children:f},f))})]}),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:"Language"}),e.jsxs("div",{className:"flex bg-slate-100 p-0.5 rounded-md",children:[e.jsx("button",{onClick:()=>x(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:()=>x(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"})]})]}),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:"Lang"}),e.jsxs("div",{className:"flex bg-slate-100 p-0.5 rounded-md items-center",children:[e.jsx("button",{onClick:()=>y(s,"cn",t),disabled:n!==null,className:`px-2.5 py-0.5 rounded text-[10px] font-bold transition-all ${t.lang==="cn"?"bg-white shadow-sm text-blue-600":"text-slate-400 hover:text-slate-500"} disabled:opacity-50 disabled:cursor-not-allowed`,children:"CN"}),e.jsxs("button",{onClick:()=>y(s,"en",t),disabled:n!==null,className:`px-2.5 py-0.5 rounded text-[10px] font-bold transition-all flex items-center gap-0.5 ${t.lang==="en"?"bg-white shadow-sm text-blue-600":"text-slate-400 hover:text-slate-500"} disabled:opacity-50 disabled:cursor-not-allowed`,children:[n===s?e.jsx(_e,{size:10,className:"animate-spin"}):null,"EN"]})]})]}),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:"Mode"}),e.jsxs("div",{className:"flex bg-slate-100 p-0.5 rounded-md",children:[e.jsx("button",{onClick:()=>x(s,{mode:"full"}),className:`px-2.5 py-0.5 rounded text-[10px] font-bold transition-all ${t.mode==="full"?"bg-white shadow-sm text-blue-600":"text-slate-400 hover:text-slate-500"}`,children:"Snippet+Recipe"}),e.jsx("button",{onClick:()=>x(s,{mode:"preview"}),className:`px-2.5 py-0.5 rounded text-[10px] font-bold transition-all ${t.mode==="preview"?"bg-white shadow-sm text-amber-600":"text-slate-400 hover:text-slate-500"}`,children:"Recipe Only"})]})]}),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:"Difficulty"}),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:f=>x(s,{difficulty:f.target.value}),children:[e.jsx("option",{value:"beginner",children:"Beginner"}),e.jsx("option",{value:"intermediate",children:"Intermediate"}),e.jsx("option",{value:"advanced",children:"Advanced"})]})]}),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:"Authority"}),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||3,onChange:f=>x(s,{authority:parseInt(f.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.jsxs("div",{className:"px-6 pt-5 pb-0 space-y-3",children:[e.jsxs("div",{className:"flex flex-wrap gap-x-4 gap-y-2 items-end",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:"Knowledge Type"}),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.knowledgeType||"code-pattern",onChange:f=>x(s,{knowledgeType:f.target.value}),children:[e.jsx("option",{value:"code-pattern",children:"Code Pattern"}),e.jsx("option",{value:"architecture",children:"Architecture"}),e.jsx("option",{value:"best-practice",children:"Best Practice"}),e.jsx("option",{value:"rule",children:"Rule"})]})]}),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:"Scope"}),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.scope||"project-specific",onChange:f=>x(s,{scope:f.target.value}),children:[e.jsx("option",{value:"universal",children:"Universal"}),e.jsx("option",{value:"project-specific",children:"Project Specific"}),e.jsx("option",{value:"target-specific",children:"Target Specific"})]})]}),e.jsx("div",{className:"w-px h-6 bg-slate-200 self-end mb-0.5"}),t.moduleName&&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:"Module"}),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})]}),A.length>0&&e.jsxs("div",{className:"flex items-end gap-2",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:"Headers"}),e.jsxs("button",{onClick:()=>c(o===s?null:s),className:`text-[11px] font-bold px-2 py-1 rounded-md transition-colors border ${v?"text-blue-700 bg-blue-100 border-blue-300":"text-blue-600 bg-blue-50 border-blue-100 hover:bg-blue-100"}`,children:[v?"收起":"编辑"," (",A.length,")"]})]}),e.jsxs("div",{className:"flex items-center gap-1.5 mb-0.5",children:[e.jsx("span",{className:"text-[9px] text-slate-400",children:"Snippet:"}),e.jsx("button",{onClick:()=>x(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"})]})]}),e.jsx("div",{className:"w-px h-6 bg-slate-200 self-end mb-0.5"}),e.jsxs("div",{className:"flex flex-col flex-1 min-w-[160px]",children:[e.jsx("label",{className:"text-[9px] font-bold text-slate-400 uppercase tracking-wider ml-0.5 mb-1",children:"Tags"}),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:[(t.tags||[]).map((f,k)=>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:[f,e.jsx("button",{onClick:()=>{const T=[...t.tags||[]];T.splice(k,1),x(s,{tags:T})},className:"text-blue-400 hover:text-red-500 transition-colors leading-none text-[10px]",title:"移除",children:"×"})]},k)),e.jsx("input",{className:"flex-1 min-w-[80px] text-[11px] text-slate-600 outline-none bg-transparent py-0.5",placeholder:(t.tags||[]).length===0?"按 Enter/逗号添加...":"",onKeyDown:f=>{const k=f.currentTarget,T=k.value.trim();if((f.key==="Enter"||f.key===","||f.key===",")&&T){f.preventDefault();const L=T.replace(/[,,]/g,"").trim();L&&!(t.tags||[]).includes(L)&&x(s,{tags:[...t.tags||[],L]}),k.value=""}else if(f.key==="Backspace"&&!k.value&&(t.tags||[]).length>0){const L=[...t.tags||[]];L.pop(),x(s,{tags:L})}},onBlur:f=>{const k=f.currentTarget.value.trim().replace(/[,,]/g,"").trim();k&&!(t.tags||[]).includes(k)&&x(s,{tags:[...t.tags||[],k]}),f.currentTarget.value=""}})]})]})]}),v&&A.length>0&&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-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("label",{className:"text-[9px] font-bold text-slate-400 uppercase tracking-wider",children:"导入头文件"}),(()=>{const f=A.filter(T=>Et(T,t.code)==="used").length,k=A.filter(T=>Et(T,t.code)==="unused").length;return e.jsxs("span",{className:"text-[9px] text-slate-400",children:[f>0&&e.jsxs("span",{className:"text-green-600 font-bold",children:[f," 引用"]}),f>0&&k>0&&" · ",k>0&&e.jsxs("span",{className:"text-amber-600 font-bold",children:[k," 未引用"]})]})})()]}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("button",{onClick:()=>{const f=A.map(k=>nr(k));x(s,{headers:f})},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(f=>Et(f,t.code)==="unused")&&e.jsx("button",{onClick:()=>{const f=A.filter(k=>Et(k,t.code)!=="unused");x(s,{headers:f})},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 f=[...A,t.language==="objectivec"?"#import <Module/Header.h>":"import ModuleName"];x(s,{headers:f})},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((f,k)=>{const T=Et(f,t.code);return e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:`w-2 h-2 rounded-full shrink-0 ${T==="used"?"bg-green-500":T==="unused"?"bg-amber-400":"bg-slate-300"}`,title:T==="used"?"代码中有引用":T==="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 ${T==="unused"?"border-amber-300 text-amber-700":"border-slate-200"}`,value:f,onChange:L=>{const U=[...A];U[k]=L.target.value,x(s,{headers:U})},placeholder:t.language==="objectivec"?"#import <Module/Header.h>":"import ModuleName"}),T==="unused"&&e.jsx("span",{className:"text-[8px] text-amber-500 font-bold shrink-0",children:"未引用"}),e.jsx("button",{onClick:()=>{const L=A.filter((U,B)=>B!==k);x(s,{headers:L})},className:"px-2 py-1 bg-red-500 text-white rounded hover:bg-red-600 text-[9px] font-bold shrink-0",children:"删除"})]},k)})})]})]}),e.jsxs("div",{className:"px-6 pb-6 pt-3 space-y-3",children:[e.jsxs("div",{children:[e.jsxs("label",{className:"block text-[10px] font-bold text-slate-400 uppercase mb-1",children:["Summary (摘要) - ",t.lang==="cn"?"中文":"EN"]}),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:t.summary,onChange:f=>x(s,{summary:f.target.value})})]}),e.jsxs("div",{children:[e.jsxs("label",{className:"block text-[10px] font-bold text-slate-400 uppercase mb-1",children:["Usage Guide (使用指南) - ",t.lang==="cn"?"中文":"EN"]}),e.jsx("textarea",{rows:3,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",value:typeof t.usageGuide=="object"?JSON.stringify(t.usageGuide):t.usageGuide||"",onChange:f=>x(s,{usageGuide:f.target.value}),placeholder:"何时用 / 关键点 / 依赖..."})]}),(()=>{const f=t.candidateId??`scan-${s}`,k=i[f],T=(k||[]).filter(B=>B.similarity>=.6);if(T.length===0)return null;const L=T.filter(B=>B.similarity>=.85),U=L.length>0;return e.jsxs("div",{className:"space-y-1.5",children:[U&&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:"高重复风险:"}),L.map(B=>e.jsxs("button",{onClick:()=>m(t,B.recipeName,k||[]),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:[B.recipeName.replace(/\.md$/i,"")," ",(B.similarity*100).toFixed(0),"%"]},B.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:"}),T.slice(0,5).map(B=>e.jsxs("button",{onClick:()=>m(t,B.recipeName,k||[]),className:`text-[10px] font-bold px-2 py-1 rounded border transition-colors flex items-center gap-1 ${B.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:`与 ${B.recipeName} 相似 ${(B.similarity*100).toFixed(0)}%,点击对比`,children:[e.jsx(Mt,{size:_.xs}),B.recipeName.replace(/\.md$/i,"")," ",(B.similarity*100).toFixed(0),"%"]},B.recipeName))]})]})})(),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:"Standardized Usage Example (标准使用示例)"}),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(zt,{size:_.xs})," 完成"]}):e.jsxs("button",{type:"button",onClick:()=>l(s),className:"flex items-center gap-1 text-[10px] font-bold text-slate-500 hover:text-slate-700 px-2 py-1 rounded hover:bg-slate-100",title:"编辑代码",children:[e.jsx(Ha,{size:_.xs})," 编辑"]})]}),a===s?e.jsx("div",{className:"rounded-xl overflow-hidden",children:e.jsx(ls,{value:t.code,onChange:f=>x(s,{code:f}),language:Ds(t),height:`${Math.min(12,t.code.split(`
|
|
106
|
+
`)||"").then(()=>ee("候选内容已复制到剪贴板",{title:"已复制"}))},Ce=()=>{const be=Ns(fe.recipeContent);navigator.clipboard.writeText(be).then(()=>ee("Recipe 内容已复制到剪贴板",{title:"已复制"}))},je=async be=>{var _e;if(be===fe.recipeName)return;const Ue=fe.recipeContents[be];if(Ue)Q(N=>N?{...N,recipeName:be,recipeContent:Ue}:null);else{let N="";const D=(_e=t==null?void 0:t.recipes)==null?void 0:_e.find(W=>W.name===be||W.name.endsWith("/"+be));if(D!=null&&D.content)N=D.content;else try{N=(await te.getRecipeContentByName(be)).content}catch{return}Q(W=>W?{...W,recipeName:be,recipeContent:N,recipeContents:{...W.recipeContents,[be]:N}}:null)}},Te=async()=>{if(window.confirm("确定删除该候选?"))try{await n(fe.targetName,de.id),Q(null)}catch(be){ee((be==null?void 0:be.message)||"删除失败",{title:"删除失败",type:"error"})}},Me=()=>{c(de,fe.targetName),Q(null)},Pe=()=>{var Ue;const be=((Ue=t==null?void 0:t.recipes)==null?void 0:Ue.find(_e=>_e.name===fe.recipeName||_e.name.endsWith("/"+fe.recipeName)))||{name:fe.recipeName,content:fe.recipeContent};x==null||x(be),Q(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:be=>be.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(Mt,{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:fe.recipeName.replace(/\.md$/i,"")})]})]}),e.jsxs("div",{className:"flex items-center gap-1.5 shrink-0 ml-2",children:[e.jsx("button",{onClick:()=>Ce(),className:"p-1.5 hover:bg-emerald-100 rounded-lg text-emerald-600 transition-colors",title:"复制",children:e.jsx(Ft,{size:14})}),e.jsx("button",{onClick:Pe,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:()=>Q(null),className:"p-1.5 hover:bg-slate-200 rounded-lg transition-colors text-slate-400",children:e.jsx(Ke,{size:16})})]})]}),fe.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:fe.similarList.map(be=>e.jsxs("button",{onClick:()=>je(be.recipeName),className:`text-[10px] font-bold px-2 py-1 rounded transition-colors ${fe.recipeName===be.recipeName?"bg-emerald-200 text-emerald-800":"bg-white text-emerald-600 hover:bg-emerald-50 border border-emerald-100"}`,children:[be.recipeName.replace(/\.md$/i,"")," ",(be.similarity*100).toFixed(0),"%"]},be.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:Te,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(ht,{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(mt,{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(Ft,{size:12})," 复制候选"]})]}),e.jsx("div",{className:"flex-1 overflow-auto p-5 min-h-0",children:e.jsx(lt,{content:fe.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:de=>de.stopPropagation(),children:[e.jsxs("div",{className:"flex items-center justify-between px-5 py-3.5 border-b border-slate-200 shrink-0 bg-slate-50/80",children:[e.jsxs("div",{className:"flex items-center gap-3 flex-1 min-w-0",children:[e.jsx(Gs,{value:((Qe=C.reasoning)==null?void 0:Qe.confidence)??null,size:40}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("h3",{className:"font-bold text-sm text-slate-800 truncate",children:C.title}),e.jsxs("div",{className:"flex items-center gap-1.5 mt-0.5 flex-wrap",children:[e.jsx("span",{className:`text-[10px] font-bold px-1.5 py-0.5 rounded uppercase flex items-center gap-1 border ${(Ae==null?void 0:Ae.bg)||"bg-slate-50"} ${(Ae==null?void 0:Ae.color)||"text-slate-400"} ${(Ae==null?void 0:Ae.border)||"border-slate-100"}`,children:C.category||"general"}),C.source&&C.source!=="unknown"&&e.jsx("span",{className:`text-[10px] font-medium px-1.5 py-0.5 rounded border ${He.color}`,children:He.label}),e.jsxs("span",{className:"text-[10px] text-slate-400",children:[q+1,"/",I.length]})]})]})]}),e.jsxs("div",{className:"flex items-center gap-1 shrink-0 ml-2",children:[e.jsx("button",{onClick:oe,disabled:!ae,title:"上一条",className:`p-1.5 rounded-lg transition-colors ${ae?"hover:bg-slate-200 text-slate-500":"text-slate-300 cursor-not-allowed"}`,children:e.jsx(Ba,{size:16})}),e.jsx("button",{onClick:Ie,disabled:!ue,title:"下一条",className:`p-1.5 rounded-lg transition-colors ${ue?"hover:bg-slate-200 text-slate-500":"text-slate-300 cursor-not-allowed"}`,children:e.jsx(kt,{size:16})}),e.jsx("button",{onClick:f,className:"p-1.5 hover:bg-slate-200 rounded-lg transition-colors text-slate-400",title:A?"收窄面板":"展开更宽",children:A?e.jsx(qs,{size:16}):e.jsx(js,{size:16})}),e.jsx("button",{onClick:()=>{v(null),Q(null)},className:"p-1.5 hover:bg-slate-200 rounded-lg transition-colors text-slate-400",children:e.jsx(Ke,{size:18})})]})]}),e.jsxs("div",{className:"flex-1 overflow-y-auto px-5 py-4 space-y-4",children:[e.jsx("p",{className:"text-sm text-slate-600 leading-relaxed",children:C.summary||C.summary_cn||""}),e.jsxs("div",{className:"flex flex-wrap gap-1.5",children:[C.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:C.knowledgeType}),C.complexity&&e.jsx("span",{className:`text-[10px] font-medium px-1.5 py-0.5 rounded border ${C.complexity==="advanced"?"bg-red-50 text-red-600 border-red-100":C.complexity==="intermediate"?"bg-amber-50 text-amber-600 border-amber-100":"bg-emerald-50 text-emerald-600 border-emerald-100"}`,children:C.complexity==="advanced"?"高级":C.complexity==="intermediate"?"中级":"初级"}),C.trigger&&e.jsx("span",{className:"text-[10px] font-mono px-1.5 py-0.5 rounded bg-white border border-slate-200 text-slate-600 font-bold",children:C.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",children:C.language}),C.tags&&C.tags.slice(0,5).map((de,j)=>e.jsx("span",{className:"text-[9px] px-1.5 py-0.5 rounded bg-blue-50 text-blue-600 border border-blue-100 font-medium",children:typeof de=="string"?de:String(de)},j)),C.createdAt&&Rt(C.createdAt)&&e.jsxs("span",{className:"text-[9px] text-slate-400 flex items-center gap-0.5",children:[e.jsx(Nt,{size:9})," ",Rt(C.createdAt)]})]}),(ye||C.quality)&&e.jsxs("div",{className:"rounded-xl border border-indigo-100 bg-indigo-50/40 p-4 text-xs space-y-3",children:[e.jsxs("div",{className:"flex items-center gap-1.5 text-indigo-700 font-bold text-[11px]",children:[e.jsx(It,{size:14}),"AI 推理过程"]}),ye?e.jsxs(e.Fragment,{children:[re.whyStandard&&e.jsxs("div",{children:[e.jsxs("span",{className:"text-indigo-600 font-bold flex items-center gap-1 mb-0.5",children:[e.jsx(ts,{size:10})," 为什么是标准用法"]}),e.jsx("p",{className:"text-slate-600 leading-relaxed pl-3",children:re.whyStandard})]}),re.sources&&re.sources.length>0&&e.jsxs("div",{children:[e.jsxs("span",{className:"text-indigo-600 font-bold flex items-center gap-1 mb-0.5",children:[e.jsx(at,{size:10})," 来源"]}),e.jsx("ul",{className:"pl-3 text-slate-600 space-y-0.5",children:re.sources.map((de,j)=>e.jsxs("li",{className:"flex items-start gap-1",children:[e.jsx("span",{className:"text-indigo-400 mt-0.5",children:"•"}),de]},j))})]}),re.confidence!=null&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-indigo-600 font-bold",children:"置信度"}),e.jsx("div",{className:"flex-1 max-w-[200px] bg-indigo-100 rounded-full h-2 overflow-hidden",children:e.jsx("div",{className:`h-full rounded-full transition-all ${re.confidence>=.7?"bg-emerald-500":re.confidence>=.4?"bg-amber-500":"bg-red-500"}`,style:{width:`${Math.round((re.confidence??0)*100)}%`}})}),e.jsxs("span",{className:`font-bold ${re.confidence>=.7?"text-emerald-600":re.confidence>=.4?"text-amber-600":"text-red-600"}`,children:[Math.round((re.confidence??0)*100),"%"]})]})]}):e.jsx("p",{className:"text-slate-400 italic pl-3",children:"暂无推理信息"})]}),(C.agentNotes||C.aiInsight||C.refinedConfidence!=null||C.relations&&C.relations.length>0)&&e.jsxs("div",{className:"rounded-xl border border-emerald-100 bg-emerald-50/40 p-4 text-xs space-y-3",children:[e.jsxs("div",{className:"flex items-center gap-1.5 text-emerald-700 font-bold text-[11px]",children:[e.jsx(Ye,{size:14}),"润色增强信息",C.refinedConfidence!=null&&e.jsxs("span",{className:"ml-auto text-emerald-600 font-mono text-[10px]",children:["润色置信度: ",Math.round(C.refinedConfidence*100),"%"]})]}),C.aiInsight&&e.jsxs("div",{children:[e.jsxs("span",{className:"text-emerald-600 font-bold flex items-center gap-1 mb-0.5",children:[e.jsx(Lt,{size:10})," 架构洞察"]}),e.jsx("p",{className:"text-slate-600 leading-relaxed pl-3",children:C.aiInsight})]}),C.agentNotes&&C.agentNotes.length>0&&e.jsxs("div",{children:[e.jsxs("span",{className:"text-emerald-600 font-bold flex items-center gap-1 mb-0.5",children:[e.jsx(Ct,{size:10})," Agent 笔记"]}),e.jsx("ul",{className:"pl-3 text-slate-600 space-y-0.5",children:C.agentNotes.map((de,j)=>e.jsxs("li",{className:"flex items-start gap-1",children:[e.jsx("span",{className:"text-emerald-400 mt-0.5",children:"•"}),de]},j))})]}),C.relations&&C.relations.length>0&&e.jsxs("div",{children:[e.jsxs("span",{className:"text-emerald-600 font-bold flex items-center gap-1 mb-0.5",children:[e.jsx(Mt,{size:10})," 关联关系"]}),e.jsx("div",{className:"pl-3 space-y-1",children:C.relations.map((de,j)=>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:de.type}),e.jsx("span",{className:"font-medium text-slate-700",children:de.target}),de.description&&e.jsxs("span",{className:"text-slate-400",children:["— ",de.description]})]},j))})]})]}),(Se.length>0||Be)&&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:"}),Be?e.jsx("span",{className:"text-[10px] text-slate-400 animate-pulse",children:"加载中..."}):Se.slice(0,5).map(de=>e.jsxs("button",{onClick:()=>Ge(C,ke,de.recipeName,Se),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:`与 ${de.recipeName} 相似 ${(de.similarity*100).toFixed(0)}%`,children:[e.jsx(Mt,{size:10}),de.recipeName.replace(/\.md$/i,"")," ",(de.similarity*100).toFixed(0),"%"]},de.recipeName))]}),C.code&&e.jsxs("div",{className:"-mx-5 overflow-hidden border-y border-slate-200",children:[e.jsxs("div",{className:"flex items-center justify-between px-3 py-2",style:{background:"#282c34"},children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(es,{size:12,className:"text-slate-400"}),e.jsx("span",{className:"text-[11px] text-slate-400 font-mono uppercase tracking-wide",children:C.language||"code"})]}),e.jsxs("span",{className:"text-[10px] text-slate-500 font-mono tabular-nums",children:[C.code.split(`
|
|
107
|
+
`).length," 行"]})]}),e.jsx(At,{code:C.code,language:C.language==="objc"?"objectivec":C.language,showLineNumbers:!0,className:"!rounded-none"})]}),C.usageGuide&&e.jsxs("div",{className:"rounded-xl border border-slate-100 bg-white p-4",children:[e.jsxs("div",{className:"flex items-center gap-1.5 text-[11px] font-bold text-slate-600 mb-2",children:[e.jsx(at,{size:12})," 使用指南"]}),e.jsx("div",{className:"prose prose-sm prose-slate max-w-none",children:e.jsx(lt,{content:C.usageGuide})})]}),(C.scope||C.headers&&C.headers.length>0||C.steps&&C.steps.length>0||C.rationale)&&e.jsxs("div",{className:"rounded-xl border border-slate-100 bg-slate-50 p-4 space-y-2",children:[e.jsxs("div",{className:"text-[11px] font-bold text-slate-600 flex items-center gap-1.5 mb-1",children:[e.jsx(gt,{size:12})," 附加信息"]}),C.scope&&e.jsxs("div",{className:"text-xs text-slate-500",children:["范围:",e.jsx("strong",{className:"text-slate-700",children:C.scope==="universal"?"通用":C.scope==="project-specific"?"项目级":"模块级"})]}),C.headers&&C.headers.length>0&&e.jsxs("div",{className:"text-xs text-slate-500",children:["头文件:",e.jsx("strong",{className:"text-slate-700",children:C.headers.join(", ")})]}),C.steps&&C.steps.length>0&&e.jsxs("div",{className:"text-xs text-slate-500",children:[e.jsxs("span",{className:"font-medium",children:["实施步骤(",C.steps.length," 步):"]}),e.jsx("ol",{className:"mt-1 ml-4 list-decimal space-y-0.5",children:C.steps.map((de,j)=>e.jsx("li",{className:"text-slate-600",children:typeof de=="string"?de:de.description||String(de)},j))})]}),C.rationale&&e.jsxs("div",{className:"text-xs text-slate-500",children:["设计原理:",e.jsx("span",{className:"text-slate-700",children:C.rationale})]})]})]}),e.jsxs("div",{className:"shrink-0 border-t border-slate-200 px-5 py-3 bg-slate-50/80 flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("button",{onClick:()=>Ze(C.id),disabled:k.has(C.id),title:"① 结构补齐",className:`flex items-center gap-1.5 px-3 py-2 rounded-lg text-xs font-medium transition-colors ${k.has(C.id)?"text-slate-300 cursor-not-allowed":"text-amber-600 hover:bg-amber-50 border border-amber-200"}`,children:[k.has(C.id)?e.jsx(ze,{size:14,className:"animate-spin"}):e.jsx(Yt,{size:14}),"补齐"]}),e.jsxs("button",{onClick:()=>Z(C.id),disabled:L.has(C.id),title:"② 内容润色",className:`flex items-center gap-1.5 px-3 py-2 rounded-lg text-xs font-medium transition-colors ${L.has(C.id)?"text-slate-300 cursor-not-allowed":"text-emerald-600 hover:bg-emerald-50 border border-emerald-200"}`,children:[L.has(C.id)?e.jsx(ze,{size:14,className:"animate-spin"}):e.jsx(Ye,{size:14}),"润色"]}),e.jsxs("button",{onClick:()=>{n(ke,C.id),v(null),Q(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(ht,{size:14})," 删除"]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[C.status==="approved"&&e.jsxs("button",{onClick:async()=>{try{await te.promoteCandidateToRecipe(C.id),ee("候选已成功提升为正式 Recipe",{title:"提升成功"}),m==null||m()}catch(de){ee(de.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(Tt,{size:14})," 提升为 Recipe"]}),e.jsxs("button",{onClick:()=>{c(C,ke),v(null),Q(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(mt,{size:14})," 审核并保存"]})]})]})]})]})})()]})},lr=({isOpen:t,onClose:s,currentFile:a,targetName:l,language:n="swift",onSelectRecipe:o})=>{var K,b,R,M;const[c,i]=r.useState(""),[x,$]=r.useState([]),[d,y]=r.useState(null),[m,S]=r.useState(!1),[v,A]=r.useState(null),[f,k]=r.useState(!1),[T,L]=r.useState(null),U=async()=>{if(c.trim()){S(!0);try{const H=await te.contextAwareSearch({keyword:c,targetName:l,currentFile:a,language:n,limit:10});$(H.results||[]),y(H.context)}catch(H){console.error("Context-aware search failed:",H),alert("搜索失败。请重试。")}finally{S(!1)}}},B=H=>{H.key==="Enter"&&U()};return t?e.jsxs(We,{className:"z-30 flex",children:[e.jsx(We.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:z.lg,className:"text-slate-500"})})]}),d&&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(st,{size:z.md,className:"text-blue-600 mt-0.5 shrink-0"}),e.jsxs("div",{className:"flex-1",children:[((K=d.targetInfo)==null?void 0:K.targetName)&&e.jsxs("div",{className:"text-blue-900 font-medium flex items-center gap-2 mb-1",children:[e.jsx(ts,{size:z.sm}),"Target: ",d.targetInfo.targetName]}),((b=d.fileInfo)==null?void 0:b.imports)&&d.fileInfo.imports.length>0&&e.jsxs("div",{className:"text-blue-800 text-xs mt-2",children:[e.jsx("strong",{children:"导入的框架:"})," ",d.fileInfo.imports.slice(0,3).join(", "),d.fileInfo.imports.length>3&&` +${d.fileInfo.imports.length-3}`]}),((R=d.targetInfo)==null?void 0:R.suggestedApis)&&d.targetInfo.suggestedApis.length>0&&e.jsxs("div",{className:"text-blue-800 text-xs mt-1",children:[e.jsx("strong",{children:"相关 APIs:"})," ",d.targetInfo.suggestedApis.slice(0,3).join(", ")]})]})]})}),e.jsxs("div",{className:"relative",children:[e.jsx(pt,{className:"absolute left-3 top-1/2 -translate-y-1/2 text-slate-400",size:z.md}),e.jsx("input",{type:"text",placeholder:"输入搜索关键词...",value:c,onChange:H=>i(H.target.value),onKeyDown:B,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:U,disabled:!c.trim()||m,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:[m&&e.jsx(ze,{size:z.sm,className:"animate-spin"}),m?"搜索中...":"搜索"]})]}),e.jsxs("div",{className:"flex-1 overflow-auto",children:[x.length===0&&!m&&e.jsx("div",{className:"flex items-center justify-center h-full text-slate-500",children:e.jsxs("div",{className:"text-center",children:[e.jsx(ss,{size:z.xxl,className:"mx-auto mb-2 opacity-50"}),e.jsx("p",{className:"text-sm",children:"输入关键词后点击搜索"})]})}),x.map((H,_)=>e.jsxs("div",{className:"border-b border-slate-200 p-4 hover:bg-slate-50 transition-colors cursor-pointer",onClick:()=>{A(v===_?null:_),H.name&&(o==null||o(H.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:H.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(st,{size:z.xs}),Math.round(H.similarity*100),"%"]}),H.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(ts,{size:z.xs}),"上下文相关"]}),H.matchType&&e.jsx("span",{className:"text-xs text-slate-500",children:H.matchType==="semantic"?"语义匹配":"关键词匹配"})]})]}),e.jsx("button",{onClick:P=>{P.stopPropagation(),A(v===_?null:_)},className:"p-1 hover:bg-slate-200 rounded transition-colors",children:v===_?"▼":"▶"})]}),H.stats&&e.jsxs("div",{className:"text-xs text-slate-500 mb-2 flex gap-3",children:[H.stats.authorityScore!==void 0&&e.jsxs("span",{children:["权威分: ",H.stats.authorityScore]}),H.usageCount!==void 0&&e.jsxs("span",{children:["使用: ",H.usageCount,"次"]})]}),v===_&&e.jsxs("div",{className:"mt-3 pt-3 border-t border-slate-200",children:[H.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:H.recommendReason})]}),e.jsxs("div",{className:"text-xs text-slate-600 max-h-[200px] overflow-auto bg-slate-50 p-3 rounded",children:[H.content.substring(0,500),"..."]}),e.jsx("button",{onClick:P=>{P.stopPropagation(),L(H),k(!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:"查看完整内容"})]})]},_)),m&&e.jsx("div",{className:"flex items-center justify-center h-32",children:e.jsx(ze,{size:z.lg,className:"animate-spin text-blue-600"})}),x.length===0&&c&&!m&&e.jsx("div",{className:"flex items-center justify-center h-32",children:e.jsxs("div",{className:"text-center text-slate-500",children:[e.jsx(ys,{size:z.xl,className:"mx-auto mb-2 opacity-50"}),e.jsx("p",{className:"text-sm",children:"未找到匹配的结果"})]})})]})]}),f&&T&&e.jsxs(We,{className:"z-40 flex items-center justify-center p-4",children:[e.jsx(We.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:T.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(T.similarity*100),"%"]}),T.isContextRelevant&&e.jsx("span",{className:"text-xs bg-green-100 text-green-700 px-2 py-1 rounded",children:"✓ 上下文相关"}),T.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:["🤖 质量: ",(T.qualityScore*100).toFixed(0),"%"]}),((M=T.stats)==null?void 0:M.authorityScore)!==void 0&&e.jsxs("span",{className:"text-xs bg-purple-100 text-purple-700 px-2 py-1 rounded",children:["权威分: ",Math.round(T.stats.authorityScore*100)/100]})]})]}),e.jsx("button",{onClick:()=>k(!1),className:"p-1 hover:bg-slate-100 rounded transition-colors shrink-0",children:e.jsx(Ke,{size:z.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:T.content?e.jsx(At,{code:T.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:()=>k(!1),className:"px-4 py-2 text-slate-700 hover:bg-slate-200 rounded transition-colors text-sm font-medium",children:"关闭"}),o&&e.jsxs("button",{onClick:()=>{o(T.name),k(!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(it,{size:z.md}),"使用此片段"]})]})]})]})]}):null},Ds=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 n=t.match(/^import\s+(\w+)/);n&&s.push(n[1]);const o=t.match(/@import\s+(\w+)/);return o&&s.push(o[1]),[...new Set(s.filter(Boolean))]}function Et(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 nr(t){return t.startsWith("#import ")||t.startsWith("import ")||t.startsWith("@import ")?t.trim():t.startsWith("<")||t.startsWith('"')?`#import ${t.trim()}`:t.trim()}const ir=({res:t,index:s,editingCodeIndex:a,setEditingCodeIndex:l,translatingIndex:n,expandedEditIndex:o,setExpandedEditIndex:c,similarityMap:i,handleUpdateScanResult:x,handleSaveExtracted:$,handlePromoteToCandidate:d,handleContentLangChange:y,openCompare:m,isSavingRecipe:S=!1})=>{const v=o===s,A=t.headers||[];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:"Recipe Title"}),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(gt,{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(st,{size:10})," ",t.candidateTargetName||"TARGET"]}):null]}),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:f=>x(s,{title:f.target.value})})]}),e.jsxs("div",{className:"flex gap-2 shrink-0 pt-3",children:[d&&e.jsxs("button",{onClick:()=>d(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(Ua,{size:z.md}),"Candidate"]}),e.jsxs("button",{onClick:()=>$(t),disabled: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 disabled:opacity-60 disabled:cursor-not-allowed whitespace-nowrap ${t.mode==="full"?"bg-blue-600 text-white hover:bg-blue-700":"bg-amber-600 text-white hover:bg-amber-700"}`,children:[S?e.jsx(ze,{size:z.md,className:"animate-spin"}):e.jsx(Qs,{size:z.md}),S?"保存中...":"保存为 Recipe"]})]})]}),e.jsxs("div",{className:"flex items-end gap-4 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-40",value:t.trigger,placeholder:"@cmd",onChange:f=>x(s,{trigger:f.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:"Category"}),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:f=>x(s,{category:f.target.value}),children:xl.filter(f=>f!=="All").map(f=>e.jsx("option",{value:f,children:f},f))})]}),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:"Language"}),e.jsxs("div",{className:"flex bg-slate-100 p-0.5 rounded-md",children:[e.jsx("button",{onClick:()=>x(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:()=>x(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"})]})]}),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:"Lang"}),e.jsxs("div",{className:"flex bg-slate-100 p-0.5 rounded-md items-center",children:[e.jsx("button",{onClick:()=>y(s,"cn",t),disabled:n!==null,className:`px-2.5 py-0.5 rounded text-[10px] font-bold transition-all ${t.lang==="cn"?"bg-white shadow-sm text-blue-600":"text-slate-400 hover:text-slate-500"} disabled:opacity-50 disabled:cursor-not-allowed`,children:"CN"}),e.jsxs("button",{onClick:()=>y(s,"en",t),disabled:n!==null,className:`px-2.5 py-0.5 rounded text-[10px] font-bold transition-all flex items-center gap-0.5 ${t.lang==="en"?"bg-white shadow-sm text-blue-600":"text-slate-400 hover:text-slate-500"} disabled:opacity-50 disabled:cursor-not-allowed`,children:[n===s?e.jsx(ze,{size:10,className:"animate-spin"}):null,"EN"]})]})]}),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:"Mode"}),e.jsxs("div",{className:"flex bg-slate-100 p-0.5 rounded-md",children:[e.jsx("button",{onClick:()=>x(s,{mode:"full"}),className:`px-2.5 py-0.5 rounded text-[10px] font-bold transition-all ${t.mode==="full"?"bg-white shadow-sm text-blue-600":"text-slate-400 hover:text-slate-500"}`,children:"Snippet+Recipe"}),e.jsx("button",{onClick:()=>x(s,{mode:"preview"}),className:`px-2.5 py-0.5 rounded text-[10px] font-bold transition-all ${t.mode==="preview"?"bg-white shadow-sm text-amber-600":"text-slate-400 hover:text-slate-500"}`,children:"Recipe Only"})]})]}),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:"Difficulty"}),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:f=>x(s,{difficulty:f.target.value}),children:[e.jsx("option",{value:"beginner",children:"Beginner"}),e.jsx("option",{value:"intermediate",children:"Intermediate"}),e.jsx("option",{value:"advanced",children:"Advanced"})]})]}),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:"Authority"}),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||3,onChange:f=>x(s,{authority:parseInt(f.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.jsxs("div",{className:"px-6 pt-5 pb-0 space-y-3",children:[e.jsxs("div",{className:"flex flex-wrap gap-x-4 gap-y-2 items-end",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:"Knowledge Type"}),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.knowledgeType||"code-pattern",onChange:f=>x(s,{knowledgeType:f.target.value}),children:[e.jsx("option",{value:"code-pattern",children:"Code Pattern"}),e.jsx("option",{value:"architecture",children:"Architecture"}),e.jsx("option",{value:"best-practice",children:"Best Practice"}),e.jsx("option",{value:"rule",children:"Rule"})]})]}),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:"Scope"}),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.scope||"project-specific",onChange:f=>x(s,{scope:f.target.value}),children:[e.jsx("option",{value:"universal",children:"Universal"}),e.jsx("option",{value:"project-specific",children:"Project Specific"}),e.jsx("option",{value:"target-specific",children:"Target Specific"})]})]}),e.jsx("div",{className:"w-px h-6 bg-slate-200 self-end mb-0.5"}),t.moduleName&&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:"Module"}),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})]}),A.length>0&&e.jsxs("div",{className:"flex items-end gap-2",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:"Headers"}),e.jsxs("button",{onClick:()=>c(o===s?null:s),className:`text-[11px] font-bold px-2 py-1 rounded-md transition-colors border ${v?"text-blue-700 bg-blue-100 border-blue-300":"text-blue-600 bg-blue-50 border-blue-100 hover:bg-blue-100"}`,children:[v?"收起":"编辑"," (",A.length,")"]})]}),e.jsxs("div",{className:"flex items-center gap-1.5 mb-0.5",children:[e.jsx("span",{className:"text-[9px] text-slate-400",children:"Snippet:"}),e.jsx("button",{onClick:()=>x(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"})]})]}),e.jsx("div",{className:"w-px h-6 bg-slate-200 self-end mb-0.5"}),e.jsxs("div",{className:"flex flex-col flex-1 min-w-[160px]",children:[e.jsx("label",{className:"text-[9px] font-bold text-slate-400 uppercase tracking-wider ml-0.5 mb-1",children:"Tags"}),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:[(t.tags||[]).map((f,k)=>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:[f,e.jsx("button",{onClick:()=>{const T=[...t.tags||[]];T.splice(k,1),x(s,{tags:T})},className:"text-blue-400 hover:text-red-500 transition-colors leading-none text-[10px]",title:"移除",children:"×"})]},k)),e.jsx("input",{className:"flex-1 min-w-[80px] text-[11px] text-slate-600 outline-none bg-transparent py-0.5",placeholder:(t.tags||[]).length===0?"按 Enter/逗号添加...":"",onKeyDown:f=>{const k=f.currentTarget,T=k.value.trim();if((f.key==="Enter"||f.key===","||f.key===",")&&T){f.preventDefault();const L=T.replace(/[,,]/g,"").trim();L&&!(t.tags||[]).includes(L)&&x(s,{tags:[...t.tags||[],L]}),k.value=""}else if(f.key==="Backspace"&&!k.value&&(t.tags||[]).length>0){const L=[...t.tags||[]];L.pop(),x(s,{tags:L})}},onBlur:f=>{const k=f.currentTarget.value.trim().replace(/[,,]/g,"").trim();k&&!(t.tags||[]).includes(k)&&x(s,{tags:[...t.tags||[],k]}),f.currentTarget.value=""}})]})]})]}),v&&A.length>0&&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-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("label",{className:"text-[9px] font-bold text-slate-400 uppercase tracking-wider",children:"导入头文件"}),(()=>{const f=A.filter(T=>Et(T,t.code)==="used").length,k=A.filter(T=>Et(T,t.code)==="unused").length;return e.jsxs("span",{className:"text-[9px] text-slate-400",children:[f>0&&e.jsxs("span",{className:"text-green-600 font-bold",children:[f," 引用"]}),f>0&&k>0&&" · ",k>0&&e.jsxs("span",{className:"text-amber-600 font-bold",children:[k," 未引用"]})]})})()]}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("button",{onClick:()=>{const f=A.map(k=>nr(k));x(s,{headers:f})},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(f=>Et(f,t.code)==="unused")&&e.jsx("button",{onClick:()=>{const f=A.filter(k=>Et(k,t.code)!=="unused");x(s,{headers:f})},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 f=[...A,t.language==="objectivec"?"#import <Module/Header.h>":"import ModuleName"];x(s,{headers:f})},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((f,k)=>{const T=Et(f,t.code);return e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:`w-2 h-2 rounded-full shrink-0 ${T==="used"?"bg-green-500":T==="unused"?"bg-amber-400":"bg-slate-300"}`,title:T==="used"?"代码中有引用":T==="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 ${T==="unused"?"border-amber-300 text-amber-700":"border-slate-200"}`,value:f,onChange:L=>{const U=[...A];U[k]=L.target.value,x(s,{headers:U})},placeholder:t.language==="objectivec"?"#import <Module/Header.h>":"import ModuleName"}),T==="unused"&&e.jsx("span",{className:"text-[8px] text-amber-500 font-bold shrink-0",children:"未引用"}),e.jsx("button",{onClick:()=>{const L=A.filter((U,B)=>B!==k);x(s,{headers:L})},className:"px-2 py-1 bg-red-500 text-white rounded hover:bg-red-600 text-[9px] font-bold shrink-0",children:"删除"})]},k)})})]})]}),e.jsxs("div",{className:"px-6 pb-6 pt-3 space-y-3",children:[e.jsxs("div",{children:[e.jsxs("label",{className:"block text-[10px] font-bold text-slate-400 uppercase mb-1",children:["Summary (摘要) - ",t.lang==="cn"?"中文":"EN"]}),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:t.summary,onChange:f=>x(s,{summary:f.target.value})})]}),e.jsxs("div",{children:[e.jsxs("label",{className:"block text-[10px] font-bold text-slate-400 uppercase mb-1",children:["Usage Guide (使用指南) - ",t.lang==="cn"?"中文":"EN"]}),e.jsx("textarea",{rows:3,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",value:typeof t.usageGuide=="object"?JSON.stringify(t.usageGuide):t.usageGuide||"",onChange:f=>x(s,{usageGuide:f.target.value}),placeholder:"何时用 / 关键点 / 依赖..."})]}),(()=>{const f=t.candidateId??`scan-${s}`,k=i[f],T=(k||[]).filter(B=>B.similarity>=.6);if(T.length===0)return null;const L=T.filter(B=>B.similarity>=.85),U=L.length>0;return e.jsxs("div",{className:"space-y-1.5",children:[U&&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:"高重复风险:"}),L.map(B=>e.jsxs("button",{onClick:()=>m(t,B.recipeName,k||[]),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:[B.recipeName.replace(/\.md$/i,"")," ",(B.similarity*100).toFixed(0),"%"]},B.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:"}),T.slice(0,5).map(B=>e.jsxs("button",{onClick:()=>m(t,B.recipeName,k||[]),className:`text-[10px] font-bold px-2 py-1 rounded border transition-colors flex items-center gap-1 ${B.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:`与 ${B.recipeName} 相似 ${(B.similarity*100).toFixed(0)}%,点击对比`,children:[e.jsx(Mt,{size:z.xs}),B.recipeName.replace(/\.md$/i,"")," ",(B.similarity*100).toFixed(0),"%"]},B.recipeName))]})]})})(),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:"Standardized Usage Example (标准使用示例)"}),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(_t,{size:z.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(Ha,{size:z.xs})," 编辑"]})]}),a===s?e.jsx("div",{className:"rounded-xl overflow-hidden",children:e.jsx(ls,{value:t.code,onChange:f=>x(s,{code:f}),language:Ds(t),height:`${Math.min(12,t.code.split(`
|
|
108
108
|
`).length)*20+16}px`})}):e.jsx(At,{code:t.code,language:Ds(t),showLineNumbers:!0})]})]})]})},or=t=>{const s=(t.language||"").toLowerCase();return s==="objectivec"||s==="objc"||s==="objective-c"||s==="obj-c"?"objectivec":t.language||"swift"},cr=({data:t,onClose:s,onDataChange:a,recipes:l,handleSaveExtracted:n,handleDeleteCandidate:o,onEditRecipe:c,isSavingRecipe:i=!1})=>{const x=t.candidate,$=or(x),d=()=>{const f=[];x.code&&f.push("## Snippet / Code Reference\n\n```"+$+`
|
|
109
109
|
`+x.code+"\n```"),x.usageGuide&&f.push(`
|
|
110
110
|
## AI Context / Usage Guide
|
|
111
111
|
|
|
112
112
|
`+x.usageGuide),navigator.clipboard.writeText(f.join(`
|
|
113
|
-
`)||"").then(()=>ee("候选内容已复制到剪贴板",{title:"已复制"}))},y=()=>{const f=Ns(t.recipeContent);navigator.clipboard.writeText(f).then(()=>ee("Recipe 内容已复制到剪贴板",{title:"已复制"}))},m=async f=>{if(f===t.recipeName)return;const k=t.recipeContents[f];if(k)a({...t,recipeName:f,recipeContent:k});else{let T="";const L=l==null?void 0:l.find(U=>U.name===f||U.name.endsWith("/"+f));if(L!=null&&L.content)T=L.content;else try{T=(await te.getRecipeContentByName(f)).content}catch{return}a({...t,recipeName:f,recipeContent:T,recipeContents:{...t.recipeContents,[f]:T}})}},S=async()=>{if(!(!x.candidateId||!t.targetName||!o)&&window.confirm("确定删除该候选?"))try{await o(t.targetName,x.candidateId),s()}catch(f){ee((f==null?void 0:f.message)||"删除失败",{title:"删除失败",type:"error"})}},v=()=>{n(x),s()},A=()=>{const f=(l==null?void 0:l.find(k=>k.name===t.recipeName||k.name.endsWith("/"+t.recipeName)))||{name:t.recipeName,content:t.recipeContent};c==null||c(f),s()};return e.jsxs(We,{className:"z-30 flex justify-end",onClick:s,children:[e.jsx(We.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:f=>f.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:[x.candidateId&&t.targetName&&e.jsx("button",{onClick:S,className:"text-xs text-red-600 hover:bg-red-50 px-2 py-1 rounded transition-colors",children:"删除候选"}),e.jsxs("button",{onClick:v,disabled:i,className:"text-xs text-blue-600 hover:bg-blue-50 px-2 py-1 rounded disabled:opacity-50 disabled:cursor-not-allowed flex items-center gap-1 transition-colors",children:[i?e.jsx(_e,{size:_.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:_.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(f=>e.jsxs("button",{onClick:()=>m(f.recipeName),className:`text-[10px] font-bold px-2 py-1 rounded transition-colors ${t.recipeName===f.recipeName?"bg-emerald-200 text-emerald-800":"bg-white text-emerald-600 hover:bg-emerald-100 border border-emerald-200"}`,children:[f.recipeName.replace(/\.md$/i,"")," ",(f.similarity*100).toFixed(0),"%"]},f.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:["候选:",x.title]}),e.jsx("button",{onClick:d,className:"p-1 hover:bg-blue-100 rounded text-blue-500 shrink-0",title:"复制候选",children:e.jsx(Ft,{size:_.xs})})]}),e.jsx("div",{className:"flex-1 overflow-y-auto p-4",children:e.jsxs("div",{className:"markdown-body text-slate-700 space-y-4",children:[e.jsx("h3",{className:"text-sm font-bold",children:"Snippet / Code Reference"}),x.code?e.jsx(At,{code:x.code,language:$,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 / Usage Guide"}),x.usageGuide?e.jsx(lt,{content:x.usageGuide}):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(Ft,{size:_.xs})})]}),e.jsx("div",{className:"flex-1 overflow-y-auto p-4",children:e.jsx(lt,{content:t.recipeContent,stripFrontmatter:!0})})]})]})]})]})},dr=({targets:t,filteredTargets:s,selectedTargetName:a,isScanning:l,scanProgress:n,scanFileList:o,scanResults:c,guardAudit:i,handleScanTarget:x,handleScanProject:$,handleUpdateScanResult:d,handleSaveExtracted:y,handlePromoteToCandidate:m,handleDeleteCandidate:S,onEditRecipe:v,isShellTarget:A,recipes:f=[],isSavingRecipe:k=!1})=>{var fe;const[T,L]=r.useState(null),[U,B]=r.useState(null),[K,b]=r.useState(null),[R,M]=r.useState({}),[H,z]=r.useState(null),[P,p]=r.useState(null),[w,E]=r.useState(!1),[se,h]=r.useState(),[V,me]=r.useState(),F=r.useRef(new Set),X=r.useRef([]),Y=r.useRef(!1),ie=r.useCallback(async(Q,ve)=>{if(!F.current.has(Q)){F.current.add(Q),z(Q);try{const Le=ve.candidateId&&ve.targetName?{targetName:ve.targetName,candidateId:ve.candidateId}:{candidate:ve.candidate||{}},Ge=await te.getCandidateSimilarityEx(Le);M(we=>({...we,[Q]:Ge.similar||[]}))}catch{M(Ge=>({...Ge,[Q]:[]}))}finally{z(null)}}},[]),Ne=r.useCallback(async(Q,ve,Le=[])=>{var De,Ze,Ve;const Ge=Q.candidateTargetName||"",we=ve.replace(/\.md$/i,"");let Fe="";const Ee=f==null?void 0:f.find(g=>g.name===we||g.name.endsWith("/"+we));if(Ee!=null&&Ee.content)Fe=Ee.content;else try{Fe=(await te.getRecipeContentByName(we)).content}catch(g){const J=(De=g.response)==null?void 0:De.status,Z=((Ve=(Ze=g.response)==null?void 0:Ze.data)==null?void 0:Ve.message)||g.message;J===404?ee(`"${we}" 不存在于当前知识库`,{title:"Recipe 不存在",type:"error"}):ee(Z,{title:"加载 Recipe 失败",type:"error"});return}const ke={[we]:Fe};p({candidate:Q,targetName:Ge,recipeName:we,recipeContent:Fe,similarList:Le.slice(0,3),recipeContents:ke})},[f]),Re=r.useCallback(async(Q,ve,Le)=>{var Ve,g;if(Y.current)return;if(ve==="cn"){d(Q,{lang:"cn"});return}const Ge=Le;if(!Ge)return;const we=!!Ge.summary_en,Fe=!!Ge.usageGuide_en;if(we&&Fe){d(Q,{lang:"en"});return}const Ee=Ge.summary_cn??Ge.summary??"",ke=String(Ge.usageGuide_cn??Ge.usageGuide??""),De=!we&&Ee.trim().length>0,Ze=!Fe&&ke.trim().length>0;if(!De&&!Ze){d(Q,{lang:"en"});return}Y.current=!0,B(Q);try{const J=await te.translate(De?Ee:"",Ze?ke:"");if(J!=null&&J.warning){ee(J.warning,{title:"翻译降级",type:"error"});return}const Z={lang:"en"};J!=null&&J.summary_en&&(Z.summary_en=J.summary_en,Z.summary=J.summary_en),J!=null&&J.usageGuide_en&&(Z.usageGuide_en=J.usageGuide_en,Z.usageGuide=J.usageGuide_en),d(Q,Z),ee("摘要与使用指南已切换为英文版本",{title:"翻译完成"})}catch(J){ee(((g=(Ve=J==null?void 0:J.response)==null?void 0:Ve.data)==null?void 0:g.error)||(J==null?void 0:J.message)||"请检查网络或重试",{title:"翻译失败",type:"error"})}finally{Y.current=!1,B(null)}},[d]);return r.useEffect(()=>{const Q=c.map((we,Fe)=>we.candidateId??`scan-${Fe}`),ve=X.current;(Q.length!==ve.length||Q.some((we,Fe)=>we!==ve[Fe]))&&(F.current.clear(),X.current=Q);const Ge=setTimeout(()=>{c.forEach((we,Fe)=>{const Ee=we.candidateId??`scan-${Fe}`;we.candidateId&&we.candidateTargetName?ie(Ee,{targetName:we.candidateTargetName,candidateId:we.candidateId}):ie(Ee,{candidate:{title:we.title,summary:we.summary,code:we.code,usageGuide:we.usageGuide}})})},800);return()=>clearTimeout(Ge)},[c,ie]),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.jsx("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,")"]})}),e.jsx("div",{className:"flex-1 overflow-y-auto p-2 space-y-1",children:s.map(Q=>{const ve=A(Q.name),Le=a===Q.name;return e.jsxs("button",{onClick:()=>x(Q),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"} ${Le?"bg-blue-50 border-blue-200 ring-1 ring-blue-200":"bg-white border-transparent"} ${ve?"opacity-90":""}`,children:[e.jsxs("div",{className:`flex flex-col max-w-[85%] ${ve?"opacity-60":""}`,children:[e.jsxs("div",{className:"flex items-center gap-2",children:[!ve&&e.jsx("div",{className:"w-1.5 h-1.5 rounded-full shrink-0 bg-blue-600"}),e.jsx("span",{className:`text-sm truncate ${ve?"font-medium":"font-bold"} ${Le?"text-blue-700":""}`,children:Q.name})]}),e.jsx("span",{className:"text-[10px] text-slate-400 truncate pl-3",children:Q.packageName})]}),ve?e.jsx("span",{className:"text-[9px] font-bold text-slate-300 border border-slate-100 px-1 rounded",children:"SHELL"}):e.jsx(st,{size:_.sm,className:`shrink-0 ${Le?"text-blue-500 opacity-100":"text-blue-500 opacity-0 group-hover:opacity-100"} transition-opacity`})]},Q.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(gt,{size:_.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(st,{size:_.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(mt,{size:_.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," 条",(fe=c[0])!=null&&fe.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(Ut,{size:_.xxl,className:"absolute inset-0 m-auto text-blue-600 animate-pulse"})]}),e.jsx("p",{className:"font-bold text-lg animate-pulse mb-1",children:a==="__project__"?"全项目扫描中":`Target 扫描: ${a||"..."}`}),e.jsx("p",{className:"text-sm text-slate-500 mb-4",children:n.status}),o.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:["本次扫描的文件 (",o.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:o.map((Q,ve)=>e.jsx("div",{className:"text-xs font-mono text-slate-600 truncate",title:Q.path,children:Q.name},ve))})]}),e.jsx("div",{className:"w-full max-w-md bg-slate-100 rounded-full h-2.5 overflow-hidden",children:e.jsx("div",{className:"h-full bg-blue-600 rounded-full transition-all duration-500 ease-out",style:{width:`${Math.min(n.total?n.current/n.total*100:0,98)}%`}})}),e.jsx("p",{className:"text-xs text-slate-400 mt-3",children:n.total?`${Math.round(n.current/n.total*100)}%`:"0%"})]}),!l&&c.length===0&&e.jsxs("div",{className:"h-full flex flex-col items-center justify-center text-slate-400 text-center",children:[e.jsx(Qt,{size:_.xxxl,className:"mb-4 opacity-20"}),e.jsx("p",{className:"font-medium text-slate-600",children:"知识提取"}),e.jsxs("p",{className:"text-xs mt-2 max-w-sm leading-relaxed",children:["在左侧选择 ",e.jsx("span",{className:"font-bold text-blue-600",children:"Target"})," 扫描单个模块,",e.jsx("br",{}),"提取代码模式并生成 Recipe 知识卡片。"]})]}),!l&&o.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:["本次扫描的文件 (",o.length,")"]}),e.jsx("div",{className:"flex flex-wrap gap-2",children:o.map((Q,ve)=>e.jsx("span",{className:"text-xs font-mono bg-white border border-slate-200 text-slate-600 px-2 py-1 rounded",title:Q.path,children:Q.name},ve))})]}),!l&&a==="__project__"&&(i==null?void 0:i.summary)&&e.jsxs("div",{className:`rounded-xl border p-4 ${i.summary.totalViolations>0?"border-amber-200 bg-amber-50":"border-emerald-200 bg-emerald-50"}`,children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsx(bt,{size:_.md,className:i.summary.totalViolations>0?"text-amber-600":"text-emerald-600"}),e.jsx("span",{className:"text-sm font-bold text-slate-700",children:"Guard 审计摘要"}),e.jsx("span",{className:"text-[10px] font-bold px-2 py-0.5 rounded-full bg-indigo-100 text-indigo-700 border border-indigo-200",children:"PROJECT SCAN"})]}),e.jsxs("div",{className:"flex gap-6 text-sm",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"text-slate-500",children:"已审计文件:"}),e.jsx("span",{className:"font-bold text-slate-700",children:i.summary.totalFiles})]}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"text-slate-500",children:"违反总数:"}),e.jsx("span",{className:`font-bold ${i.summary.totalViolations>0?"text-amber-700":"text-emerald-700"}`,children:i.summary.totalViolations})]}),i.summary.errors>0&&e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(Ot,{size:_.sm,className:"text-red-500"}),e.jsxs("span",{className:"font-bold text-red-700",children:[i.summary.errors," 错误"]})]}),i.summary.warnings>0&&e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(Ot,{size:_.sm,className:"text-amber-500"}),e.jsxs("span",{className:"font-bold text-amber-700",children:[i.summary.warnings," 警告"]})]})]})]}),c.map((Q,ve)=>e.jsx(ir,{res:Q,index:ve,editingCodeIndex:T,setEditingCodeIndex:L,translatingIndex:U,expandedEditIndex:K,setExpandedEditIndex:b,similarityMap:R,handleUpdateScanResult:d,handleSaveExtracted:y,handlePromoteToCandidate:m,handleContentLangChange:Re,openCompare:Ne,isSavingRecipe:k},ve))]})]}),P&&e.jsx(cr,{data:P,onClose:()=>p(null),onDataChange:p,recipes:f,handleSaveExtracted:y,handleDeleteCandidate:S,onEditRecipe:v,isSavingRecipe:k}),e.jsx(lr,{isOpen:w,onClose:()=>E(!1),targetName:V,currentFile:se,language:"swift",onSelectRecipe:Q=>{}})]})},xr=72,mr=52,Zt=24,Dt=40,ma=36,yt=140,Gt=40,Pt=8;function ur(t,s){const a=new Set(t.map(i=>i.id)),l=new Map;for(const i of s)!a.has(i.from)||!a.has(i.to)||(l.has(i.from)||l.set(i.from,[]),l.get(i.from).push(i.to));const n=new Map,o=new Set;function c(i){if(n.has(i))return n.get(i);if(o.has(i))return 0;o.add(i);const x=l.get(i);if(!x||x.length===0)return n.set(i,0),o.delete(i),0;const $=1+Math.max(...x.map(c));return n.set(i,$),o.delete(i),$}return t.forEach(i=>c(i.id)),n}function pr(t){return Math.ceil(t/Pt)}function hr(t,s){const a=ur(t,s),l=new Map;for(const y of t){const m=a.get(y.id)??0;l.has(m)||l.set(m,[]),l.get(m).push(y.id)}const n=[...new Set(a.values())].sort((y,m)=>y-m),o=[...n].reverse(),c=new Map,i=new Map,x=Math.min(Pt,Math.max(...n.map(y=>(l.get(y)??[]).length),1)),$=(x-1)*Zt+x*yt;let d=Dt;return o.forEach(y=>{const m=l.get(y)??[],S=pr(m.length),v=d;for(let f=0;f<S;f++){const k=m.slice(f*Pt,(f+1)*Pt),T=(k.length-1)*Zt+k.length*yt,L=($-T)/2;k.forEach((U,B)=>{const K=Dt+ma+L+B*(yt+Zt)+yt/2,b=d+Gt/2;c.set(U,{x:K,y:b})}),d+=f<S-1?mr:xr}const A=d-v;i.set(y,{y:v,h:A})}),{positions:c,tiers:a,tierOrder:n,tierYRanges:i}}const br=()=>{const[t,s]=r.useState(null),[a,l]=r.useState(!0),[n,o]=r.useState(null),[c,i]=r.useState(null),[x,$]=r.useState("package"),d=async()=>{var p,w;l(!0),o(null);try{const E=await te.getDepGraph(x);s({nodes:Array.isArray(E==null?void 0:E.nodes)?E.nodes:[],edges:Array.isArray(E==null?void 0:E.edges)?E.edges:[],projectRoot:(E==null?void 0:E.projectRoot)??null,generatedAt:E==null?void 0:E.generatedAt})}catch(E){o(((w=(p=E.response)==null?void 0:p.data)==null?void 0:w.error)||E.message||"Failed to load dependency graph")}finally{l(!1)}};r.useEffect(()=>{d()},[x]);const y=Array.isArray(t==null?void 0:t.nodes)?t.nodes:[],m=Array.isArray(t==null?void 0:t.edges)?t.edges:[],{positions:S,tiers:v,tierOrder:A,tierYRanges:f}=r.useMemo(()=>hr(y,m),[y,m]),k=r.useMemo(()=>{const p=new Map;return y.forEach(w=>{const E=v.get(w.id)??0;p.has(E)||p.set(E,[]),p.get(E).push(w.id)}),p},[y,v]),T=r.useMemo(()=>[...A].reverse(),[A]),{dependsOn:L,dependedBy:U}=r.useMemo(()=>{const p=new Map,w=new Map;return m.forEach(E=>{p.has(E.from)||p.set(E.from,[]),p.get(E.from).push(E.to),w.has(E.to)||w.set(E.to,[]),w.get(E.to).push(E.from)}),{dependsOn:p,dependedBy:w}},[m]),B=Math.min(Pt,Math.max(...A.map(p=>(k.get(p)??[]).length),1)),b=(B-1)*Zt+B*yt+ma*2,R=Math.max(600,Dt*2+b),M=Math.max(...[...S.values()].map(p=>p.y),0),H=Math.max(420,M+Gt/2+Dt+20),z=[{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)"}],P=p=>z[Math.min(p,z.length-1)]??z[0];return a?e.jsx("div",{className:"flex items-center justify-center min-h-[320px]",children:e.jsx("div",{className:"animate-spin rounded-full h-10 w-10 border-2 border-blue-600 border-t-transparent"})}):n?e.jsxs("div",{className:"rounded-xl border border-red-200 bg-red-50 p-6 text-red-700 shadow-sm",children:[e.jsx("p",{children:n}),e.jsx("button",{type:"button",onClick:d,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:"w-full max-w-[1400px] mx-auto space-y-6",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-4",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"flex items-center justify-center w-10 h-10 rounded-xl bg-blue-50 border border-blue-100",children:e.jsx(gt,{size:_.lg,className:"text-blue-600"})}),e.jsxs("div",{children:[e.jsx("h2",{className:"text-xl font-bold text-slate-900",children:"项目依赖关系图"}),t.projectRoot&&e.jsxs("p",{className:"text-sm text-slate-500 mt-0.5",children:["项目根: ",e.jsx("code",{className:"bg-slate-100 px-1.5 py-0.5 rounded text-slate-600",children:t.projectRoot}),t.generatedAt&&e.jsxs("span",{className:"ml-2",children:["· 生成于 ",new Date(t.generatedAt).toLocaleString()]})]})]})]}),e.jsxs("button",{type:"button",onClick:()=>{d()},className:"flex items-center gap-2 px-4 py-2 rounded-lg border border-slate-200 bg-white hover:bg-slate-50 text-slate-700 font-medium text-sm shadow-sm transition-colors",children:[e.jsx(wt,{size:_.md})," 刷新"]})]}),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:H,viewBox:`0 0 ${R} ${H}`,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"})})}),T.map((p,w)=>{const E=P(w),se=f.get(p);return se?e.jsx("rect",{x:Dt,y:se.y-Gt/2-4,width:b,height:se.h+8,rx:8,fill:E.bg,stroke:E.border,strokeWidth:"1",opacity:.6},p):null}),y.map(p=>{const w=S.get(p.id);if(!w)return null;const E=v.get(p.id)??0,se=P(T.indexOf(E)),h=p.label.length>14?p.label.slice(0,13)+"…":p.label,V=c===p.id,me=c?(L.get(c)??[]).includes(p.id):!1,F=c?(U.get(c)??[]).includes(p.id):!1,X=c&&!V&&!me&&!F,Y=c?V?{fill:"white",stroke:"rgb(59 130 246)",text:"rgb(30 64 175)",strokeWidth:3,opacity:1}:me?{fill:"rgb(240 253 244)",stroke:"rgb(34 197 94)",text:"rgb(22 101 52)",strokeWidth:2,opacity:1}:F?{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:se.border,text:se.text,strokeWidth:2,opacity:1};return e.jsxs("g",{style:{cursor:"pointer",opacity:Y.opacity},onClick:()=>i(V?null:p.id),children:[e.jsx("rect",{x:w.x-yt/2,y:w.y-Gt/2,width:yt,height:Gt,rx:10,ry:10,fill:Y.fill,stroke:Y.stroke,strokeWidth:Y.strokeWidth,filter:X?void 0:"url(#nodeShadow)"}),e.jsx("text",{x:w.x,y:w.y,textAnchor:"middle",dominantBaseline:"middle",fontSize:"12",fontWeight:"600",fill:Y.text,pointerEvents:"none",children:h})]},p.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:()=>i(null),className:"text-slate-400 hover:text-slate-600 text-lg leading-none","aria-label":"关闭",children:"×"})]}),e.jsxs("div",{className:"space-y-3 text-sm",children:[e.jsxs("div",{children:[e.jsx("div",{className:"font-semibold text-slate-600 mb-1",children:"依赖"}),e.jsx("ul",{className:"text-slate-700 space-y-0.5",children:(L.get(c)??[]).length===0?e.jsx("li",{className:"text-slate-400",children:"无"}):(L.get(c)??[]).map(p=>e.jsxs("li",{children:["→ ",p]},p))})]}),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:(U.get(c)??[]).length===0?e.jsx("li",{className:"text-slate-400",children:"无"}):(U.get(c)??[]).map(p=>e.jsxs("li",{children:["← ",p]},p))})]})]})]})]}),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(p=>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:p.id}),p.packageDir&&e.jsxs("span",{className:"text-slate-500 text-xs",children:["· ",p.packageDir]})]}),p.targets&&p.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:p.targets.join(", ")})]})]},p.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:["依赖关系(小图)(",m.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:m.map((p,w)=>e.jsxs("li",{className:"flex items-center gap-2 text-slate-700",children:[e.jsx("span",{className:"font-semibold text-slate-800",children:p.from}),e.jsx("span",{className:"text-slate-400 shrink-0",children:"→"}),e.jsx("span",{className:"font-semibold text-slate-800",children:p.to})]},`${p.from}-${p.to}-${w}`))})]}),x==="target"&&e.jsxs("p",{className:"text-xs text-slate-500 mt-2",children:["Target 级节点格式:",e.jsx("span",{className:"font-mono",children:"Package::Target"})]})]})]})},gr=({onRefresh:t})=>{const[s,a]=r.useState({}),[l,n]=r.useState([]),[o,c]=r.useState(null),[i,x]=r.useState(!0),[$,d]=r.useState(!1),[y,m]=r.useState(!1),[S,v]=r.useState(""),[A,f]=r.useState(!1),[k,T]=r.useState({ruleId:"",message:"",severity:"warning",pattern:"",languages:["objc","swift"],note:"",dimension:""}),[L,U]=r.useState(!1),[B,K]=r.useState(""),b=async()=>{try{const[w,E]=await Promise.all([te.getGuardRules(),te.getGuardViolations()]);a((w==null?void 0:w.rules)||{}),n((E==null?void 0:E.runs)||[])}catch{a({}),n([])}finally{x(!1)}};r.useEffect(()=>{b()},[]);const R=async()=>{if(window.confirm("确定清空所有 Guard 违反记录?"))try{await te.clearViolations(),b(),t==null||t()}catch(w){ee((w==null?void 0:w.message)||"清空违反记录失败",{title:"操作失败",type:"error"})}},M=w=>{T(E=>({...E,languages:E.languages.includes(w)?E.languages.filter(se=>se!==w):[...E.languages,w]}))},H=async()=>{var w,E;if(!S.trim()){K("请先输入语义描述");return}K(""),f(!0);try{const h=await te.generateGuardRule({description:S.trim()}),V=h.dimension;T({ruleId:h.ruleId||"",message:h.message||"",severity:h.severity==="error"?"error":"warning",pattern:h.pattern||"",languages:Array.isArray(h.languages)&&h.languages.length>0?h.languages:["objc","swift"],note:h.note!=null?String(h.note):"",dimension:V==="file"||V==="target"||V==="project"?V:""}),m(!0)}catch(se){K(((E=(w=se==null?void 0:se.response)==null?void 0:w.data)==null?void 0:E.error)||(se==null?void 0:se.message)||"AI 生成失败")}finally{f(!1)}},z=async w=>{var E,se;if(w.preventDefault(),K(""),!k.ruleId.trim()||!k.message.trim()||!k.pattern.trim()||k.languages.length===0){K("请填写规则 ID、说明、正则和至少一种语言");return}U(!0);try{await te.saveGuardRule({ruleId:k.ruleId.trim(),message:k.message.trim(),severity:k.severity,pattern:k.pattern.trim(),languages:k.languages,note:k.note.trim()||void 0,...k.dimension?{dimension:k.dimension}:{}}),T({ruleId:"",message:"",severity:"warning",pattern:"",languages:["objc","swift"],note:"",dimension:""}),v(""),m(!1),b(),t==null||t()}catch(h){K(((se=(E=h==null?void 0:h.response)==null?void 0:E.data)==null?void 0:se.error)||(h==null?void 0:h.message)||"写入失败")}finally{U(!1)}};if(i)return e.jsx("div",{className:"p-6 text-slate-500",children:"加载中..."});const P=Object.entries(s),p=l.reduce((w,E)=>w+E.violations.length,0);return e.jsxs("div",{className:"p-6",children:[e.jsxs("div",{className:"flex items-center justify-between mb-6",children:[e.jsxs("h2",{className:"text-xl font-bold text-slate-900 flex items-center gap-2",children:[e.jsx(bt,{size:_.xl,className:"text-blue-600"}),"Guard 规则与违反记录"]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("a",{href:ul,target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1.5 px-3 py-1.5 text-sm text-slate-600 hover:text-slate-900 hover:bg-slate-100 rounded-lg transition-colors",children:[e.jsx(Wa,{size:_.md})," 提交误报/建议"]}),e.jsxs("button",{type:"button",onClick:()=>d(!$),className:"flex items-center gap-1.5 px-3 py-1.5 text-sm text-slate-600 hover:text-slate-900 hover:bg-slate-100 rounded-lg transition-colors",children:[$?e.jsx(kt,{size:_.md}):e.jsx(it,{size:_.md}),"AI 写入规则"]}),l.length>0&&e.jsxs("button",{type:"button",onClick:R,className:"flex items-center gap-2 px-3 py-1.5 text-sm text-slate-500 hover:text-red-600 hover:bg-red-50 rounded-lg transition-colors",children:[e.jsx(ht,{size:_.sm})," 清空历史"]})]})]}),$&&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:S,onChange:w=>{v(w.target.value),K("")},className:"w-full px-3 py-2 border border-slate-200 rounded-lg text-sm resize-y min-h-[80px]",placeholder:"例如:禁止在主线程使用 dispatch_sync 调用 main queue,易死锁",rows:3}),e.jsx("button",{type:"button",onClick:H,disabled:A||!S.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 生成"}),B&&e.jsx("p",{className:"mt-2 text-sm text-red-600",children:B})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{type:"button",onClick:()=>m(!y),className:"text-sm font-medium text-blue-600 hover:text-blue-700",children:y?"收起表单":"展开 / 编辑表单"}),k.ruleId&&e.jsxs("span",{className:"text-xs text-slate-500",children:["已生成规则 ID:",k.ruleId]})]})]}),y&&e.jsxs("form",{onSubmit:z,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:k.ruleId,onChange:w=>T(E=>({...E,ruleId:w.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:k.severity,onChange:w=>T(E=>({...E,severity:w.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:k.message,onChange:w=>T(E=>({...E,message:w.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:k.pattern,onChange:w=>T(E=>({...E,pattern:w.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:k.languages.includes("objc"),onChange:()=>M("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:k.languages.includes("swift"),onChange:()=>M("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:k.dimension,onChange:w=>T(E=>({...E,dimension:w.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:k.note,onChange:w=>T(E=>({...E,note:w.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:L,className:"px-4 py-2 bg-blue-600 text-white text-sm rounded-lg hover:bg-blue-700 disabled:opacity-50",children:L?"写入中...":"确认写入"}),e.jsx("button",{type:"button",onClick:()=>m(!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:P.length===0?e.jsx("tr",{children:e.jsx("td",{colSpan:5,className:"py-4 px-4 text-slate-500",children:"暂无规则"})}):P.map(([w,E])=>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:w}),e.jsx("td",{className:"py-2 px-4",children:e.jsx("span",{className:`text-xs font-medium px-1.5 py-0.5 rounded ${E.severity==="error"?"bg-red-100 text-red-700":"bg-amber-100 text-amber-700"}`,children:E.severity})}),e.jsx("td",{className:"py-2 px-4 text-slate-700",children:E.message}),e.jsx("td",{className:"py-2 px-4 text-slate-500",children:(E.languages||[]).join(", ")}),e.jsx("td",{className:"py-2 px-4 text-slate-500 text-xs",children:E.dimension==="file"?"同文件":E.dimension==="target"?"同 target":E.dimension==="project"?"同项目":"—"})]},w))})]})})]}),e.jsxs("section",{children:[e.jsxs("h3",{className:"text-sm font-semibold text-slate-700 mb-3",children:["违反记录(共 ",l.length," 次运行,",p," 处违反)"]}),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(w=>{const E=o===w.id,se=w.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(E?null:w.id),className:"w-full flex items-center gap-2 py-3 px-4 text-left hover:bg-slate-50 transition-colors",children:[E?e.jsx(kt,{size:_.md}):e.jsx(it,{size:_.md}),e.jsx("span",{className:"font-mono text-sm text-slate-700",children:w.filePath}),e.jsx("span",{className:"text-xs text-slate-400",children:new Date(w.triggeredAt).toLocaleString()}),se?e.jsxs("span",{className:"ml-auto flex items-center gap-1 text-amber-600 text-xs font-medium",children:[e.jsx(Ot,{size:_.sm})," ",w.violations.length," 处违反"]}):e.jsx("span",{className:"ml-auto text-slate-400 text-xs",children:"无违反"})]}),E&&e.jsx("div",{className:"border-t border-slate-100 bg-slate-50/50 p-4",children:w.violations.length===0?e.jsx("p",{className:"text-sm text-slate-500",children:"本次运行未发现违反。"}):e.jsx("ul",{className:"space-y-2",children:w.violations.map((h,V)=>{var F;const me=s[h.ruleId];return e.jsxs("li",{className:"flex items-start gap-2 text-sm",children:[h.severity==="error"?e.jsx(ys,{size:_.md,className:"text-red-500 shrink-0 mt-0.5"}):e.jsx(Ot,{size:_.md,className:"text-amber-500 shrink-0 mt-0.5"}),e.jsxs("div",{className:"flex-1 space-y-1.5",children:[e.jsxs("div",{children:[e.jsxs("span",{className:"font-mono text-xs text-slate-500",children:["[",h.ruleId,"] ",h.filePath?`${h.filePath}:${h.line}`:`L${h.line}`]}),h.dimension&&e.jsx("span",{className:"ml-1.5 text-xs px-1.5 py-0.5 rounded bg-slate-200 text-slate-600",children:h.dimension==="file"?"同文件":h.dimension==="target"?"同 target":"同项目"}),e.jsx("span",{className:"text-slate-700 ml-2",children:h.message})]}),h.snippet&&e.jsx("pre",{className:"text-xs text-slate-600 bg-slate-100 p-2 rounded overflow-x-auto",children:h.snippet}),me&&(me.rationale||((F=me.fixSuggestions)==null?void 0:F.length)||me.sourceRecipe||me.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:[me.rationale&&e.jsxs("div",{className:"flex items-start gap-1.5",children:[e.jsx(at,{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:me.rationale})]})]}),me.fixSuggestions&&me.fixSuggestions.length>0&&e.jsxs("div",{className:"flex items-start gap-1.5",children:[e.jsx(ea,{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:me.fixSuggestions.map((X,Y)=>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:X}),e.jsx("button",{className:"ml-1 text-blue-500 hover:text-blue-700",title:"复制修复建议",onClick:()=>navigator.clipboard.writeText(X),children:"⎘"})]},Y))})]})]}),me.sourceRecipe&&e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(hs,{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:me.sourceRecipe})]}),!me.rationale&&me.note&&e.jsxs("div",{className:"text-slate-500 italic",children:["备注:",me.note]})]})]})]},V)})})})]},w.id)})})]})]})},ms=()=>Math.random().toString(36).substring(2,10),fr=({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(Ws,{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 jr(t){const s=new Date(t),l=new Date().getTime()-s.getTime(),n=Math.floor(l/6e4);if(n<1)return"刚刚";if(n<60)return`${n}分钟前`;const o=Math.floor(n/60);if(o<24)return`${o}小时前`;const c=Math.floor(o/24);return c<7?`${c}天前`:s.toLocaleDateString("zh-CN",{month:"short",day:"numeric"})}const yr=()=>{const t=Dl(),{close:s,isOpen:a}=Ht(),{messages:l,setMessages:n,loading:o,setLoading:c,chatHistoryRef:i}=t,x=ia(),{topics:$,activeTopicId:d,activeTopic:y,createTopic:m,deleteTopic:S,saveTopic:v,switchTopic:A,setActiveTopicId:f}=x,k=r.useRef(null),T=r.useRef(null),[L,U]=r.useState(""),[B,K]=r.useState(!1),b=r.useRef(!1);r.useEffect(()=>{a&&s()},[]),r.useEffect(()=>{var p;(p=k.current)==null||p.scrollIntoView({behavior:"smooth"})},[l,o]),r.useEffect(()=>{setTimeout(()=>{var p;return(p=T.current)==null?void 0:p.focus()},200)},[]),r.useEffect(()=>{b.current||d&&l.length>0&&v(d,l)},[l,d,v]);const R=r.useCallback(()=>{b.current=!0,m(),n([]),i.current=[],setTimeout(()=>{b.current=!1},50)},[m,n,i]),M=r.useCallback(p=>{if(p===d)return;b.current=!0,A(p);const w=x.getTopic(p);w?(n(w.messages),i.current=w.messages.filter(E=>E.role==="user"||E.role==="assistant").map(E=>({role:E.role==="assistant"?"model":E.role,content:E.content}))):(n([]),i.current=[]),setTimeout(()=>{b.current=!1},50)},[d,A,x,n,i]),H=r.useCallback((p,w)=>{p.stopPropagation(),S(w),w===d&&(b.current=!0,n([]),i.current=[],setTimeout(()=>{b.current=!1},50))},[S,d,n,i]),z=r.useCallback(async()=>{const p=L.trim();if(!p||o)return;let w=d;w||(b.current=!0,w=m(),setTimeout(()=>{b.current=!1},50)),U(""),n(E=>[...E,{id:ms(),role:"user",content:p,timestamp:Date.now()}]),c(!0),i.current.push({role:"user",content:p});try{const E=await te.chat(p,i.current);i.current.push({role:"model",content:E.text}),n(se=>[...se,{id:ms(),role:"assistant",content:E.text,timestamp:Date.now()}])}catch(E){n(se=>[...se,{id:ms(),role:"assistant",content:`请求失败: ${E.message}`,timestamp:Date.now()}])}c(!1)},[L,o,d,m]),P=r.useCallback(p=>{p.key==="Enter"&&!p.shiftKey&&(p.preventDefault(),z())},[z]);return e.jsxs("div",{className:"flex-1 flex h-full bg-slate-50",children:[e.jsx("div",{className:`${B?"w-10":"w-64"} shrink-0 bg-white border-r border-slate-200 flex flex-col transition-all duration-200`,children:B?e.jsxs("div",{className:"flex flex-col items-center py-3 gap-2",children:[e.jsx("button",{onClick:()=>K(!1),className:"p-1.5 hover:bg-slate-100 rounded-lg transition-colors text-slate-400 hover:text-slate-600",title:"展开话题列表",children:e.jsx(it,{size:16})}),e.jsx("button",{onClick:R,className:"p-1.5 hover:bg-blue-50 rounded-lg transition-colors text-blue-500",title:"新建话题",children:e.jsx(ut,{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:R,className:"p-1.5 hover:bg-blue-50 rounded-lg transition-colors text-slate-400 hover:text-blue-600",title:"新建话题",children:e.jsx(ut,{size:14})}),e.jsx("button",{onClick:()=>K(!0),className:"p-1.5 hover:bg-slate-100 rounded-lg transition-colors text-slate-400 hover:text-slate-600",title:"折叠",children:e.jsx(fs,{size:14})})]})]}),e.jsx("div",{className:"flex-1 overflow-y-auto scrollbar-light",children:$.length===0?e.jsxs("div",{className:"px-4 py-8 text-center",children:[e.jsx(vt,{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:$.map(p=>{const w=p.id===d,E=p.messages.filter(se=>se.role==="user").length;return e.jsx("div",{onClick:()=>M(p.id),className:`group mx-1.5 mb-0.5 px-3 py-2 rounded-lg cursor-pointer transition-colors ${w?"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 ${w?"text-blue-700":"text-slate-700"}`,children:p.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(Nt,{size:9}),jr(p.updatedAt)]}),E>0&&e.jsxs("span",{className:"text-[10px] text-slate-300",children:[E," 条"]})]})]}),e.jsx("button",{onClick:se=>H(se,p.id),className:`p-1 rounded transition-colors shrink-0 ${w?"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(ht,{size:12})})]})},p.id)})})}),$.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:[$.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(vt,{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:"询问任何关于项目的问题"})]})]}),l.length>0&&e.jsxs("button",{onClick:R,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(ut,{size:14}),"开启新话题"]})]}),e.jsx("div",{className:"flex-1 overflow-y-auto min-h-0 scrollbar-light",children:e.jsxs("div",{className:"max-w-3xl mx-auto p-6 space-y-4",children:[l.length===0&&e.jsxs("div",{className:"flex flex-col items-center justify-center py-20 text-center",children:[e.jsx("div",{className:"w-16 h-16 rounded-2xl bg-gradient-to-br from-blue-50 to-indigo-50 border border-blue-100 flex items-center justify-center mb-4",children:e.jsx(Ye,{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(p=>e.jsx("button",{onClick:()=>{var w;U(p),(w=T.current)==null||w.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:p},p))})]}),l.map(p=>e.jsx("div",{className:`flex ${p.role==="user"?"justify-end":"justify-start"}`,children:e.jsxs("div",{className:`max-w-[80%] ${p.role==="user"?"bg-blue-600 text-white rounded-2xl rounded-tr-md px-4 py-2.5":p.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:[p.role==="assistant"&&e.jsxs("div",{className:"flex items-center gap-1.5 mb-2",children:[e.jsx(It,{size:13,className:"text-blue-500"}),e.jsx("span",{className:"text-[11px] font-bold text-blue-600",children:"AI 助手"})]}),p.role==="assistant"&&!p.diff?e.jsx(lt,{content:p.content,className:"text-sm text-slate-700"}):e.jsx("p",{className:`text-sm leading-relaxed whitespace-pre-wrap ${p.role==="user"?"":"text-slate-600"}`,children:p.content}),p.diff&&p.diff.length>0&&e.jsx("div",{className:"space-y-2 mt-2",children:p.diff.map(w=>e.jsx(fr,{d:w},w.field))})]})},p.id)),o&&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(_e,{size:14,className:"animate-spin text-blue-500"}),e.jsx("span",{className:"text-sm text-slate-500",children:"AI 思考中..."})]})})}),e.jsx("div",{ref:k})]})}),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:T,value:L,onChange:p=>U(p.target.value),onKeyDown:P,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:o}),e.jsx("button",{onClick:z,disabled:!L.trim()||o,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(gs,{size:16})})]}),e.jsx("p",{className:"text-[10px] text-slate-400 mt-1.5",children:"Enter 发送 · Shift+Enter 换行"})]})})]})]})},Nr=28,vr=22,wr=50,kr=11,Sr=10,ct={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"},Vt={depends_on:"依赖",requires:"需要",extends:"扩展",implements:"实现",inherits:"继承",enforces:"约束",related:"关联",conflicts:"冲突",calls:"调用",prerequisite:"前置",data_flow_to:"数据流",references:"引用",alternative:"替代",deprecated_by:"废弃",solves:"解决"},qt=[{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 jt(t){return Math.min(wr,Math.max(vr,Nr+t*2))}function Ps(t,s){return t.length<=s?t:t.substring(0,s-1)+"…"}function Cr(t,s,a,l){const n=new Map;for(const d of t)n.set(d.fromId,(n.get(d.fromId)||0)+1),n.set(d.toId,(n.get(d.toId)||0)+1);const o=[...n.keys()],c=[...new Set(o.map(d=>l[d]||"general"))].sort(),i=new Map,x=Math.ceil(Math.sqrt(c.length)),$=400;return c.forEach((d,y)=>{const m=y%x,S=Math.floor(y/x);i.set(d,{x:450+(m-(x-1)/2)*$,y:350+(S-(Math.ceil(c.length/x)-1)/2)*$})}),o.map(d=>{const y=l[d]||"general",m=i.get(y)||{x:450,y:350},S=Math.random()*2*Math.PI,v=40+Math.random()*80;return{id:d,label:s[d]||d,type:a[d]||"recipe",group:y,x:m.x+v*Math.cos(S),y:m.y+v*Math.sin(S),vx:0,vy:0,degree:n.get(d)||1}})}function Ir(t,s,a=200){const l=t.map(c=>({...c})),n=new Map(l.map(c=>[c.id,c]));function o(){const c=new Map;for(const i of l){const x=c.get(i.group);x?(x.x+=i.x,x.y+=i.y,x.count++):c.set(i.group,{x:i.x,y:i.y,count:1})}for(const[,i]of c)i.x/=i.count,i.y/=i.count;return c}for(let c=0;c<a;c++){const i=1-c/a,x=18e3*i,$=.015,d=.8,y=o();for(let S=0;S<l.length;S++)for(let v=S+1;v<l.length;v++){const A=l[S],f=l[v];let k=f.x-A.x,T=f.y-A.y,L=Math.sqrt(k*k+T*T)||1;const U=jt(A.degree)+jt(f.degree)+60,B=Math.max(L,1),K=A.group===f.group?.6:1.4,b=x*K/(B*B),R=L<U?(U-L)*.5:0,M=b+R,H=k/B*M,z=T/B*M;A.vx-=H,A.vy-=z,f.vx+=H,f.vy+=z}for(const S of s){const v=n.get(S.fromId),A=n.get(S.toId);if(!v||!A)continue;let f=A.x-v.x,k=A.y-v.y,T=Math.sqrt(f*f+k*k)||1;const L=v.group===A.group?140:280,U=$*(T-L),B=f/T*U,K=k/T*U;v.vx+=B,v.vy+=K,A.vx-=B,A.vy-=K}const m=.008*i;for(const S of l){const v=y.get(S.group);v&&(S.vx+=(v.x-S.x)*m,S.vy+=(v.y-S.y)*m)}for(const S of l)S.vx*=d,S.vy*=d,S.x+=S.vx,S.y+=S.vy}return l}function $r(t,s,a,l,n,o,c=0){const i=a-t,x=l-s,$=Math.sqrt(i*i+x*x)||1,d=i/$,y=x/$,m=t+d*n,S=s+y*n,v=a-d*o,A=l-y*o;if(c===0)return`M${m},${S}L${v},${A}`;const f=(m+v)/2+-y*c,k=(S+A)/2+d*c;return`M${m},${S}Q${f},${k},${v},${A}`}const Ar=()=>{const[t,s]=r.useState([]),[a,l]=r.useState({}),[n,o]=r.useState({}),[c,i]=r.useState({}),[x,$]=r.useState(null),[d,y]=r.useState(!0),[m,S]=r.useState(null),[v,A]=r.useState(null),[f,k]=r.useState(null),[T,L]=r.useState(null),[U,B]=r.useState(!1),[K,b]=r.useState(null),[R,M]=r.useState(1),[H,z]=r.useState({x:0,y:0}),P=r.useRef(null),p=r.useRef(null),w=r.useRef(!1),E=r.useRef({x:0,y:0}),se=async()=>{var g,J;y(!0),S(null);try{const[Z,u]=await Promise.all([te.getKnowledgeGraph(),te.getGraphStats()]);s(Z.edges||[]),l(Z.nodeLabels||{}),o(Z.nodeTypes||{}),i(Z.nodeCategories||{}),$(u)}catch(Z){S(((J=(g=Z.response)==null?void 0:g.data)==null?void 0:J.error)||Z.message||"加载知识图谱失败")}finally{y(!1)}};r.useEffect(()=>{se()},[]),r.useEffect(()=>{te.getDiscoverRelationsStatus().then(g=>{g.status==="running"&&(B(!0),b(`AI 分析中…(已运行 ${g.elapsed??0}s)`))}).catch(()=>{})},[]),r.useEffect(()=>{if(!U)return;let g=0;const J=240,Z=setInterval(async()=>{if(g++,g>J){clearInterval(Z),B(!1),b("轮询超时,任务可能仍在后台运行。请稍后刷新页面查看结果。");return}try{const u=await te.getDiscoverRelationsStatus();if(u.status==="done"){B(!1);const I=u.discovered??0,G=u.totalPairs??0,C=u.batchErrors??0;I===0&&C===0?b(`分析完成,共检查 ${G} 对 Recipe,未发现关系。待 Recipe 数量增加后可再次尝试。`):I===0&&C>0?b(`分析完成,但 ${C} 个批次 AI 调用失败,未发现关系。请检查 AI Provider 配置。`):b(`发现 ${I} 条关系(共分析 ${G} 对${C>0?`,${C} 个批次失败`:""})`),se()}else if(u.status==="error"){B(!1);const I=u.error||"未知错误";I.includes("AI Provider")||I.includes("API Key")?b(`AI 服务未配置: ${I}`):I.includes("超时")||I.includes("timeout")?b(`任务超时: ${I}`):b(`发现失败: ${I}`)}else u.status==="running"&&b(`AI 分析中…(已运行 ${u.elapsed??0}s)`)}catch{}},3e3);return()=>clearInterval(Z)},[U]);const h=r.useCallback(async()=>{var g,J,Z;b(null);try{const u=await te.discoverRelations();if(u.status==="empty"){b(u.message||"Recipe 数量不足,无法分析");return}if(u.status==="timeout"){b(u.error||"上次任务超时,请重试");return}if(u.status==="running"){B(!0),b("AI 分析仍在进行中…");return}B(!0),b("AI 分析已启动,正在后台运行…")}catch(u){const I=((Z=(J=(g=u==null?void 0:u.response)==null?void 0:g.data)==null?void 0:J.error)==null?void 0:Z.message)||u.message||"未知错误";I.includes("ChatAgent")||I.includes("AI Provider")?b(`AI 服务不可用: ${I}`):b(`启动失败: ${I}`)}},[]),V=r.useMemo(()=>{if(t.length===0)return[];const g=Cr(t,a,n,c);return Ir(g,t)},[t,a,n,c]),me=r.useMemo(()=>{const g=new Map;for(const u of V){const I=g.get(u.group)||[];I.push(u),g.set(u.group,I)}const J=[],Z=[...g.keys()].sort();for(const u of Z){const I=g.get(u);if(I.length===0)continue;let G=0,C=0;for(const ue of I)G+=ue.x,C+=ue.y;G/=I.length,C/=I.length;let q=0,ae=0;for(const ue of I){const oe=jt(ue.degree);q=Math.max(q,Math.abs(ue.x-G)+oe+35),ae=Math.max(ae,Math.abs(ue.y-C)+oe+35)}J.push({group:u,cx:G,cy:C,rx:Math.max(q,60),ry:Math.max(ae,60),count:I.length})}return J},[V]),F=r.useMemo(()=>{const g=[...new Set(V.map(Z=>Z.group))].sort(),J={};return g.forEach((Z,u)=>{J[Z]=qt[u%qt.length]}),J},[V]),X=r.useMemo(()=>{if(V.length===0)return{x:0,y:0,w:900,h:700};let g=1/0,J=1/0,Z=-1/0,u=-1/0;for(const I of V){const G=jt(I.degree);g=Math.min(g,I.x-G-80),J=Math.min(J,I.y-G-40),Z=Math.max(Z,I.x+G+80),u=Math.max(u,I.y+G+40)}return{x:g,y:J,w:Z-g,h:u-J}},[V]),Y=r.useMemo(()=>new Map(V.map(g=>[g.id,g])),[V]),{connectedEdgeIds:ie,connectedNodeIds:Ne}=r.useMemo(()=>{const g=v||f;if(!g)return{connectedEdgeIds:new Set,connectedNodeIds:new Set};const J=new Set,Z=new Set([g]);for(const u of t)(u.fromId===g||u.toId===g)&&(J.add(u.id),Z.add(u.fromId),Z.add(u.toId));return{connectedEdgeIds:J,connectedNodeIds:Z}},[v,f,t]),Re=r.useMemo(()=>{const g=new Map,J=new Map;for(const u of t){const I=[u.fromId,u.toId].sort().join("|"),G=g.get(I)||0;J.set(u.id,G),g.set(I,G+1)}const Z=new Map;for(const u of t){const I=[u.fromId,u.toId].sort().join("|"),G=g.get(I)||1;if(G<=1){Z.set(u.id,0);continue}const C=J.get(u.id)||0;Z.set(u.id,(C-(G-1)/2)*40)}return Z},[t]),[fe,Q]=r.useState(new Set);r.useEffect(()=>{Q(new Set(t.map(g=>g.relation)))},[t]);const ve=r.useMemo(()=>t.filter(g=>fe.has(g.relation)),[t,fe]),Le=g=>{Q(J=>{const Z=new Set(J);return Z.has(g)?Z.delete(g):Z.add(g),Z})},Ge=r.useCallback(g=>{g.button===0&&(w.current=!0,E.current={x:g.clientX,y:g.clientY})},[]),we=r.useCallback(g=>{if(!w.current)return;const J=g.clientX-E.current.x,Z=g.clientY-E.current.y;E.current={x:g.clientX,y:g.clientY},z(u=>({x:u.x+J,y:u.y+Z}))},[]),Fe=r.useCallback(()=>{w.current=!1},[]),Ee=r.useCallback(g=>{g.preventDefault();const J=g.deltaY>0?-.1:.1;M(Z=>Math.min(3,Math.max(.2,Z+J)))},[]),ke=g=>`kg-arrow-${g.replace(/[^a-z_]/g,"")}`;if(d)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(m)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:m}),e.jsx("button",{onClick:se,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(ps,{size:48,className:"text-slate-300"}),e.jsx("p",{className:"text-lg font-medium",children:"知识图谱为空"}),e.jsx("p",{className:"text-sm text-center max-w-md",children:"当前没有 Recipe 之间的关系数据。点击下方按钮让 AI 自动分析已有 Recipe 之间的潜在关系(requires / extends / enforces / calls 等)。"}),K&&e.jsx("p",{className:`text-sm ${K.startsWith("发现失败")?"text-red-500":"text-green-600"}`,children:K}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("button",{onClick:h,disabled:U,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:U?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(Ye,{size:_.sm})," AI 发现关系"]})}),e.jsxs("button",{onClick:se,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(wt,{size:_.sm})," 刷新"]})]})]});const De=[...new Set(t.map(g=>g.relation))].sort(),Ve=!!(v||f);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(ps,{size:_.lg,className:"text-blue-600"}),e.jsx("h2",{className:"text-lg font-bold text-slate-800",children:"知识图谱"}),x&&e.jsxs("span",{className:"text-xs text-slate-500 bg-slate-100 px-2 py-1 rounded-full",children:[V.length," 节点 · ",x.totalEdges," 关系"]})]}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("button",{onClick:()=>M(g=>Math.min(g+.2,3)),className:"p-1.5 rounded-lg bg-slate-100 hover:bg-slate-200 transition-colors",title:"放大",children:e.jsx(Ka,{size:_.sm})}),e.jsx("button",{onClick:()=>M(g=>Math.max(g-.2,.2)),className:"p-1.5 rounded-lg bg-slate-100 hover:bg-slate-200 transition-colors",title:"缩小",children:e.jsx(Va,{size:_.sm})}),e.jsx("button",{onClick:()=>{M(1),z({x:0,y:0})},className:"p-1.5 rounded-lg bg-slate-100 hover:bg-slate-200 transition-colors",title:"重置",children:e.jsx(js,{size:_.sm})}),e.jsx("button",{onClick:se,className:"p-1.5 rounded-lg bg-slate-100 hover:bg-slate-200 transition-colors",title:"刷新",children:e.jsx(wt,{size:_.sm})}),e.jsx("button",{onClick:h,disabled:U,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:U?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(Ye,{size:_.sm})," 发现关系"]})})]})]}),e.jsx("div",{className:"flex flex-wrap gap-1.5 mb-3 flex-shrink-0",children:De.map(g=>{var J;return e.jsxs("button",{onClick:()=>Le(g),className:`flex items-center gap-1 px-2 py-0.5 rounded-full text-[11px] font-medium transition-all border ${fe.has(g)?"border-transparent shadow-sm":"border-slate-200 bg-white text-slate-400 opacity-40"}`,style:fe.has(g)?{backgroundColor:(ct[g]||"#6b7280")+"18",color:ct[g]||"#6b7280"}:{},children:[e.jsx("span",{className:"w-2 h-2 rounded-full",style:{backgroundColor:ct[g]||"#6b7280"}}),Vt[g]||g,((J=x==null?void 0:x.byRelation)==null?void 0:J[g])!=null&&e.jsxs("span",{className:"opacity-60",children:["(",x.byRelation[g],")"]})]},g)})}),e.jsxs("div",{ref:p,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:w.current?"grabbing":"grab"},onWheel:Ee,children:[e.jsxs("svg",{ref:P,width:"100%",height:"100%",viewBox:`${X.x} ${X.y} ${X.w} ${X.h}`,onMouseDown:Ge,onMouseMove:we,onMouseUp:Fe,onMouseLeave:Fe,style:{transform:`scale(${R}) translate(${H.x/R}px, ${H.y/R}px)`},children:[e.jsxs("defs",{children:[De.map(g=>e.jsx("marker",{id:ke(g),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:ct[g]||"#6b7280"})},g)),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:me.map(g=>{const J=F[g.group]||qt[0];return e.jsxs("g",{children:[e.jsx("ellipse",{cx:g.cx,cy:g.cy,rx:g.rx,ry:g.ry,fill:J.bg,stroke:J.border,strokeWidth:1.5,strokeDasharray:"6,4",opacity:.6}),e.jsxs("text",{x:g.cx,y:g.cy-g.ry+14,textAnchor:"middle",fontSize:11,fontWeight:600,fill:J.text,opacity:.8,style:{pointerEvents:"none",userSelect:"none"},children:[g.group||"general"," (",g.count,")"]})]},g.group)})}),e.jsx("g",{children:ve.map(g=>{const J=Y.get(g.fromId),Z=Y.get(g.toId);if(!J||!Z)return null;const u=Ve?ie.has(g.id):!1,I=T===g.id,G=Ve?u?.85:.06:I?.9:.35,C=jt(J.degree),q=jt(Z.degree),ae=Re.get(g.id)||0,ue=$r(J.x,J.y,Z.x,Z.y,C,q,ae);return e.jsxs("g",{children:[e.jsx("path",{d:ue,fill:"none",stroke:"transparent",strokeWidth:12,onMouseEnter:()=>L(g.id),onMouseLeave:()=>L(null),style:{cursor:"pointer"}}),e.jsx("path",{d:ue,fill:"none",stroke:ct[g.relation]||"#6b7280",strokeWidth:I||u?2:1.2,opacity:G,markerEnd:`url(#${ke(g.relation)})`,strokeDasharray:g.relation==="related"?"6,3":void 0,style:{transition:"opacity 0.25s, stroke-width 0.15s",pointerEvents:"none"}}),I&&(()=>{const oe=(J.x+Z.x)/2,Ie=(J.y+Z.y)/2;return e.jsxs("g",{children:[e.jsx("rect",{x:oe-24,y:Ie-16,width:48,height:18,rx:4,fill:"white",stroke:ct[g.relation]||"#6b7280",strokeWidth:.8,opacity:.95}),e.jsx("text",{x:oe,y:Ie-4,textAnchor:"middle",fontSize:9,fontWeight:600,fill:ct[g.relation]||"#6b7280",children:Vt[g.relation]||g.relation})]})})()]},g.id)})}),e.jsx("g",{children:V.map(g=>{const J=jt(g.degree),Z=v===g.id,u=Ve&&Ne.has(g.id),I=Z||g.id===f,G=Ve&&!u,C=G?.12:1,q=F[g.group]||qt[0],ae=I?q.border:q.bg,ue=I?q.text:q.border,oe=I?"#ffffff":q.text,Ie=I?q.text:"#64748b";return e.jsxs("g",{onClick:re=>{re.stopPropagation(),A(Z?null:g.id)},onMouseEnter:()=>k(g.id),onMouseLeave:()=>k(null),style:{cursor:"pointer",transition:"opacity 0.25s"},opacity:C,filter:I?"url(#kg-glow)":void 0,children:[e.jsx("circle",{cx:g.x,cy:g.y,r:J,fill:ae,stroke:ue,strokeWidth:I?2.5:1.5}),e.jsx("text",{x:g.x,y:g.y+4,textAnchor:"middle",fontSize:Math.min(kr,J*.7),fill:oe,fontWeight:700,style:{pointerEvents:"none",userSelect:"none"},children:Ps(g.label,4).toUpperCase()}),e.jsx("text",{x:g.x,y:g.y+J+14,textAnchor:"middle",fontSize:Sr,fill:Ie,fontWeight:I?600:400,style:{pointerEvents:"none",userSelect:"none"},children:Ps(g.label,18)}),g.degree>=3&&!G&&e.jsxs("g",{children:[e.jsx("circle",{cx:g.x+J*.7,cy:g.y-J*.7,r:8,fill:"#3b82f6",stroke:"white",strokeWidth:1.5}),e.jsx("text",{x:g.x+J*.7,y:g.y-J*.7+3.5,textAnchor:"middle",fontSize:8,fill:"white",fontWeight:700,style:{pointerEvents:"none"},children:g.degree})]})]},g.id)})})]}),v&&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:"取消选中"})]}),v&&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(qa,{size:14,className:"text-blue-500"}),e.jsx("h3",{className:"font-semibold text-sm text-slate-800",children:a[v]||v}),e.jsxs("span",{className:"text-[10px] text-slate-400 ml-auto",children:["ID: ",v]})]}),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(g=>g.fromId===v&&fe.has(g.relation)).map(g=>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:ct[g.relation]||"#6b7280"}}),e.jsx("span",{className:"text-slate-500",children:Vt[g.relation]||g.relation}),e.jsx("span",{className:"text-slate-400",children:"→"}),e.jsx("button",{className:"text-blue-600 hover:underline truncate",onClick:()=>A(g.toId),children:a[g.toId]||g.toId.substring(0,16)})]},g.id)),t.filter(g=>g.fromId===v&&fe.has(g.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(g=>g.toId===v&&fe.has(g.relation)).map(g=>e.jsxs("li",{className:"flex items-center gap-1.5",children:[e.jsx("button",{className:"text-blue-600 hover:underline truncate",onClick:()=>A(g.fromId),children:a[g.fromId]||g.fromId.substring(0,16)}),e.jsx("span",{className:"text-slate-400",children:"→"}),e.jsx("span",{className:"text-slate-500",children:Vt[g.relation]||g.relation}),e.jsx("span",{className:"w-1.5 h-1.5 rounded-full flex-shrink-0",style:{backgroundColor:ct[g.relation]||"#6b7280"}})]},g.id)),t.filter(g=>g.toId===v&&fe.has(g.relation)).length===0&&e.jsx("li",{className:"text-slate-400",children:"无"})]})]})]})]})]})},Jt={manual:{label:"手动",color:"bg-slate-100 text-slate-600",icon:Hs},"user-ai":{label:"AI 协助",color:"bg-violet-100 text-violet-600",icon:Ye},"system-ai":{label:"自动",color:"bg-amber-100 text-amber-600",icon:Ut},"external-ai":{label:"外部 AI",color:"bg-cyan-100 text-cyan-600",icon:ta}},zr=({onRefresh:t,signalSuggestionCount:s=0,onSuggestionCountChange:a})=>{const[l,n]=r.useState([]),[o,c]=r.useState(!0),[i,x]=r.useState(null),[$,d]=r.useState(!1),[y,m]=r.useState(!1),[S,v]=r.useState("all"),[A,f]=r.useState(!1),[k,T]=r.useState([]),[L,U]=r.useState(!1),[B,K]=r.useState(!1),[b,R]=r.useState(null),M=r.useCallback(async()=>{var h;c(!0);try{const V=await te.listSkills();n(V.skills||[])}catch(V){((h=V.response)==null?void 0:h.status)!==404&&ee(V.message||"",{title:"获取 Skills 列表失败",type:"error"}),n([])}finally{c(!1)}},[]);r.useEffect(()=>{M()},[M]);const H=async h=>{if((i==null?void 0:i.skillName)===h){x(null);return}d(!0);try{const V=await te.loadSkill(h);x(V)}catch{ee(`"${h}" 不存在或读取出错`,{title:"加载 Skill 失败",type:"error"})}finally{d(!1)}},z=()=>{i!=null&&i.content&&(navigator.clipboard.writeText(i.content),f(!0),setTimeout(()=>f(!1),2e3))},P=async()=>{U(!0),K(!0);try{const[h,V]=await Promise.allSettled([te.suggestSkills(),te.getSignalStatus()]),me=h.status==="fulfilled"?h.value.suggestions||[]:[],F=V.status==="fulfilled"?V.value.suggestions||[]:[],X=new Map;for(const ie of me)X.set(ie.name,ie);for(const ie of F)X.set(ie.name,{...X.get(ie.name),...ie});const Y=[...X.values()];T(Y),a==null||a(Y.length)}catch(h){ee(h.message||"",{title:"获取 Skill 推荐失败",type:"error"}),T([]),a==null||a(0)}finally{U(!1)}};r.useEffect(()=>{s>0&&k.length===0&&!B&&P()},[]);const p=async h=>{R(h.name);try{const V=h.description||h.rationale||h.name,me=`请为以下场景创建一个 Skill 文档:
|
|
113
|
+
`)||"").then(()=>ee("候选内容已复制到剪贴板",{title:"已复制"}))},y=()=>{const f=Ns(t.recipeContent);navigator.clipboard.writeText(f).then(()=>ee("Recipe 内容已复制到剪贴板",{title:"已复制"}))},m=async f=>{if(f===t.recipeName)return;const k=t.recipeContents[f];if(k)a({...t,recipeName:f,recipeContent:k});else{let T="";const L=l==null?void 0:l.find(U=>U.name===f||U.name.endsWith("/"+f));if(L!=null&&L.content)T=L.content;else try{T=(await te.getRecipeContentByName(f)).content}catch{return}a({...t,recipeName:f,recipeContent:T,recipeContents:{...t.recipeContents,[f]:T}})}},S=async()=>{if(!(!x.candidateId||!t.targetName||!o)&&window.confirm("确定删除该候选?"))try{await o(t.targetName,x.candidateId),s()}catch(f){ee((f==null?void 0:f.message)||"删除失败",{title:"删除失败",type:"error"})}},v=()=>{n(x),s()},A=()=>{const f=(l==null?void 0:l.find(k=>k.name===t.recipeName||k.name.endsWith("/"+t.recipeName)))||{name:t.recipeName,content:t.recipeContent};c==null||c(f),s()};return e.jsxs(We,{className:"z-30 flex justify-end",onClick:s,children:[e.jsx(We.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:f=>f.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:[x.candidateId&&t.targetName&&e.jsx("button",{onClick:S,className:"text-xs text-red-600 hover:bg-red-50 px-2 py-1 rounded transition-colors",children:"删除候选"}),e.jsxs("button",{onClick:v,disabled:i,className:"text-xs text-blue-600 hover:bg-blue-50 px-2 py-1 rounded disabled:opacity-50 disabled:cursor-not-allowed flex items-center gap-1 transition-colors",children:[i?e.jsx(ze,{size:z.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:z.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(f=>e.jsxs("button",{onClick:()=>m(f.recipeName),className:`text-[10px] font-bold px-2 py-1 rounded transition-colors ${t.recipeName===f.recipeName?"bg-emerald-200 text-emerald-800":"bg-white text-emerald-600 hover:bg-emerald-100 border border-emerald-200"}`,children:[f.recipeName.replace(/\.md$/i,"")," ",(f.similarity*100).toFixed(0),"%"]},f.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:["候选:",x.title]}),e.jsx("button",{onClick:d,className:"p-1 hover:bg-blue-100 rounded text-blue-500 shrink-0",title:"复制候选",children:e.jsx(Ft,{size:z.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"}),x.code?e.jsx(At,{code:x.code,language:$,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 / Usage Guide"}),x.usageGuide?e.jsx(lt,{content:x.usageGuide}):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(Ft,{size:z.xs})})]}),e.jsx("div",{className:"flex-1 overflow-y-auto p-4",children:e.jsx(lt,{content:t.recipeContent,stripFrontmatter:!0})})]})]})]})]})},dr=({targets:t,filteredTargets:s,selectedTargetName:a,isScanning:l,scanProgress:n,scanFileList:o,scanResults:c,guardAudit:i,handleScanTarget:x,handleScanProject:$,handleUpdateScanResult:d,handleSaveExtracted:y,handlePromoteToCandidate:m,handleDeleteCandidate:S,onEditRecipe:v,isShellTarget:A,recipes:f=[],isSavingRecipe:k=!1})=>{var fe;const[T,L]=r.useState(null),[U,B]=r.useState(null),[K,b]=r.useState(null),[R,M]=r.useState({}),[H,_]=r.useState(null),[P,p]=r.useState(null),[w,E]=r.useState(!1),[se,h]=r.useState(),[V,me]=r.useState(),F=r.useRef(new Set),X=r.useRef([]),Y=r.useRef(!1),ie=r.useCallback(async(Q,ve)=>{if(!F.current.has(Q)){F.current.add(Q),_(Q);try{const Le=ve.candidateId&&ve.targetName?{targetName:ve.targetName,candidateId:ve.candidateId}:{candidate:ve.candidate||{}},Ge=await te.getCandidateSimilarityEx(Le);M(we=>({...we,[Q]:Ge.similar||[]}))}catch{M(Ge=>({...Ge,[Q]:[]}))}finally{_(null)}}},[]),Ne=r.useCallback(async(Q,ve,Le=[])=>{var De,Ze,Ve;const Ge=Q.candidateTargetName||"",we=ve.replace(/\.md$/i,"");let Fe="";const Ee=f==null?void 0:f.find(g=>g.name===we||g.name.endsWith("/"+we));if(Ee!=null&&Ee.content)Fe=Ee.content;else try{Fe=(await te.getRecipeContentByName(we)).content}catch(g){const J=(De=g.response)==null?void 0:De.status,Z=((Ve=(Ze=g.response)==null?void 0:Ze.data)==null?void 0:Ve.message)||g.message;J===404?ee(`"${we}" 不存在于当前知识库`,{title:"Recipe 不存在",type:"error"}):ee(Z,{title:"加载 Recipe 失败",type:"error"});return}const ke={[we]:Fe};p({candidate:Q,targetName:Ge,recipeName:we,recipeContent:Fe,similarList:Le.slice(0,3),recipeContents:ke})},[f]),Re=r.useCallback(async(Q,ve,Le)=>{var Ve,g;if(Y.current)return;if(ve==="cn"){d(Q,{lang:"cn"});return}const Ge=Le;if(!Ge)return;const we=!!Ge.summary_en,Fe=!!Ge.usageGuide_en;if(we&&Fe){d(Q,{lang:"en"});return}const Ee=Ge.summary_cn??Ge.summary??"",ke=String(Ge.usageGuide_cn??Ge.usageGuide??""),De=!we&&Ee.trim().length>0,Ze=!Fe&&ke.trim().length>0;if(!De&&!Ze){d(Q,{lang:"en"});return}Y.current=!0,B(Q);try{const J=await te.translate(De?Ee:"",Ze?ke:"");if(J!=null&&J.warning){ee(J.warning,{title:"翻译降级",type:"error"});return}const Z={lang:"en"};J!=null&&J.summary_en&&(Z.summary_en=J.summary_en,Z.summary=J.summary_en),J!=null&&J.usageGuide_en&&(Z.usageGuide_en=J.usageGuide_en,Z.usageGuide=J.usageGuide_en),d(Q,Z),ee("摘要与使用指南已切换为英文版本",{title:"翻译完成"})}catch(J){ee(((g=(Ve=J==null?void 0:J.response)==null?void 0:Ve.data)==null?void 0:g.error)||(J==null?void 0:J.message)||"请检查网络或重试",{title:"翻译失败",type:"error"})}finally{Y.current=!1,B(null)}},[d]);return r.useEffect(()=>{const Q=c.map((we,Fe)=>we.candidateId??`scan-${Fe}`),ve=X.current;(Q.length!==ve.length||Q.some((we,Fe)=>we!==ve[Fe]))&&(F.current.clear(),X.current=Q);const Ge=setTimeout(()=>{c.forEach((we,Fe)=>{const Ee=we.candidateId??`scan-${Fe}`;we.candidateId&&we.candidateTargetName?ie(Ee,{targetName:we.candidateTargetName,candidateId:we.candidateId}):ie(Ee,{candidate:{title:we.title,summary:we.summary,code:we.code,usageGuide:we.usageGuide}})})},800);return()=>clearTimeout(Ge)},[c,ie]),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.jsx("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,")"]})}),e.jsx("div",{className:"flex-1 overflow-y-auto p-2 space-y-1",children:s.map(Q=>{const ve=A(Q.name),Le=a===Q.name;return e.jsxs("button",{onClick:()=>x(Q),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"} ${Le?"bg-blue-50 border-blue-200 ring-1 ring-blue-200":"bg-white border-transparent"} ${ve?"opacity-90":""}`,children:[e.jsxs("div",{className:`flex flex-col max-w-[85%] ${ve?"opacity-60":""}`,children:[e.jsxs("div",{className:"flex items-center gap-2",children:[!ve&&e.jsx("div",{className:"w-1.5 h-1.5 rounded-full shrink-0 bg-blue-600"}),e.jsx("span",{className:`text-sm truncate ${ve?"font-medium":"font-bold"} ${Le?"text-blue-700":""}`,children:Q.name})]}),e.jsx("span",{className:"text-[10px] text-slate-400 truncate pl-3",children:Q.packageName})]}),ve?e.jsx("span",{className:"text-[9px] font-bold text-slate-300 border border-slate-100 px-1 rounded",children:"SHELL"}):e.jsx(st,{size:z.sm,className:`shrink-0 ${Le?"text-blue-500 opacity-100":"text-blue-500 opacity-0 group-hover:opacity-100"} transition-opacity`})]},Q.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(gt,{size:z.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(st,{size:z.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(mt,{size:z.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," 条",(fe=c[0])!=null&&fe.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(Ut,{size:z.xxl,className:"absolute inset-0 m-auto text-blue-600 animate-pulse"})]}),e.jsx("p",{className:"font-bold text-lg animate-pulse mb-1",children:a==="__project__"?"全项目扫描中":`Target 扫描: ${a||"..."}`}),e.jsx("p",{className:"text-sm text-slate-500 mb-4",children:n.status}),o.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:["本次扫描的文件 (",o.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:o.map((Q,ve)=>e.jsx("div",{className:"text-xs font-mono text-slate-600 truncate",title:Q.path,children:Q.name},ve))})]}),e.jsx("div",{className:"w-full max-w-md bg-slate-100 rounded-full h-2.5 overflow-hidden",children:e.jsx("div",{className:"h-full bg-blue-600 rounded-full transition-all duration-500 ease-out",style:{width:`${Math.min(n.total?n.current/n.total*100:0,98)}%`}})}),e.jsx("p",{className:"text-xs text-slate-400 mt-3",children:n.total?`${Math.round(n.current/n.total*100)}%`:"0%"})]}),!l&&c.length===0&&e.jsxs("div",{className:"h-full flex flex-col items-center justify-center text-slate-400 text-center",children:[e.jsx(Qt,{size:z.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&&o.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:["本次扫描的文件 (",o.length,")"]}),e.jsx("div",{className:"flex flex-wrap gap-2",children:o.map((Q,ve)=>e.jsx("span",{className:"text-xs font-mono bg-white border border-slate-200 text-slate-600 px-2 py-1 rounded",title:Q.path,children:Q.name},ve))})]}),!l&&a==="__project__"&&(i==null?void 0:i.summary)&&e.jsxs("div",{className:`rounded-xl border p-4 ${i.summary.totalViolations>0?"border-amber-200 bg-amber-50":"border-emerald-200 bg-emerald-50"}`,children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsx(bt,{size:z.md,className:i.summary.totalViolations>0?"text-amber-600":"text-emerald-600"}),e.jsx("span",{className:"text-sm font-bold text-slate-700",children:"Guard 审计摘要"}),e.jsx("span",{className:"text-[10px] font-bold px-2 py-0.5 rounded-full bg-indigo-100 text-indigo-700 border border-indigo-200",children:"PROJECT SCAN"})]}),e.jsxs("div",{className:"flex gap-6 text-sm",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"text-slate-500",children:"已审计文件:"}),e.jsx("span",{className:"font-bold text-slate-700",children:i.summary.totalFiles})]}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"text-slate-500",children:"违反总数:"}),e.jsx("span",{className:`font-bold ${i.summary.totalViolations>0?"text-amber-700":"text-emerald-700"}`,children:i.summary.totalViolations})]}),i.summary.errors>0&&e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(Ot,{size:z.sm,className:"text-red-500"}),e.jsxs("span",{className:"font-bold text-red-700",children:[i.summary.errors," 错误"]})]}),i.summary.warnings>0&&e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(Ot,{size:z.sm,className:"text-amber-500"}),e.jsxs("span",{className:"font-bold text-amber-700",children:[i.summary.warnings," 警告"]})]})]})]}),c.map((Q,ve)=>e.jsx(ir,{res:Q,index:ve,editingCodeIndex:T,setEditingCodeIndex:L,translatingIndex:U,expandedEditIndex:K,setExpandedEditIndex:b,similarityMap:R,handleUpdateScanResult:d,handleSaveExtracted:y,handlePromoteToCandidate:m,handleContentLangChange:Re,openCompare:Ne,isSavingRecipe:k},ve))]})]}),P&&e.jsx(cr,{data:P,onClose:()=>p(null),onDataChange:p,recipes:f,handleSaveExtracted:y,handleDeleteCandidate:S,onEditRecipe:v,isSavingRecipe:k}),e.jsx(lr,{isOpen:w,onClose:()=>E(!1),targetName:V,currentFile:se,language:"swift",onSelectRecipe:Q=>{}})]})},xr=72,mr=52,Zt=24,Dt=40,ma=36,yt=140,Gt=40,Pt=8;function ur(t,s){const a=new Set(t.map(i=>i.id)),l=new Map;for(const i of s)!a.has(i.from)||!a.has(i.to)||(l.has(i.from)||l.set(i.from,[]),l.get(i.from).push(i.to));const n=new Map,o=new Set;function c(i){if(n.has(i))return n.get(i);if(o.has(i))return 0;o.add(i);const x=l.get(i);if(!x||x.length===0)return n.set(i,0),o.delete(i),0;const $=1+Math.max(...x.map(c));return n.set(i,$),o.delete(i),$}return t.forEach(i=>c(i.id)),n}function pr(t){return Math.ceil(t/Pt)}function hr(t,s){const a=ur(t,s),l=new Map;for(const y of t){const m=a.get(y.id)??0;l.has(m)||l.set(m,[]),l.get(m).push(y.id)}const n=[...new Set(a.values())].sort((y,m)=>y-m),o=[...n].reverse(),c=new Map,i=new Map,x=Math.min(Pt,Math.max(...n.map(y=>(l.get(y)??[]).length),1)),$=(x-1)*Zt+x*yt;let d=Dt;return o.forEach(y=>{const m=l.get(y)??[],S=pr(m.length),v=d;for(let f=0;f<S;f++){const k=m.slice(f*Pt,(f+1)*Pt),T=(k.length-1)*Zt+k.length*yt,L=($-T)/2;k.forEach((U,B)=>{const K=Dt+ma+L+B*(yt+Zt)+yt/2,b=d+Gt/2;c.set(U,{x:K,y:b})}),d+=f<S-1?mr:xr}const A=d-v;i.set(y,{y:v,h:A})}),{positions:c,tiers:a,tierOrder:n,tierYRanges:i}}const br=()=>{const[t,s]=r.useState(null),[a,l]=r.useState(!0),[n,o]=r.useState(null),[c,i]=r.useState(null),[x,$]=r.useState("package"),d=async()=>{var p,w;l(!0),o(null);try{const E=await te.getDepGraph(x);s({nodes:Array.isArray(E==null?void 0:E.nodes)?E.nodes:[],edges:Array.isArray(E==null?void 0:E.edges)?E.edges:[],projectRoot:(E==null?void 0:E.projectRoot)??null,generatedAt:E==null?void 0:E.generatedAt})}catch(E){o(((w=(p=E.response)==null?void 0:p.data)==null?void 0:w.error)||E.message||"Failed to load dependency graph")}finally{l(!1)}};r.useEffect(()=>{d()},[x]);const y=Array.isArray(t==null?void 0:t.nodes)?t.nodes:[],m=Array.isArray(t==null?void 0:t.edges)?t.edges:[],{positions:S,tiers:v,tierOrder:A,tierYRanges:f}=r.useMemo(()=>hr(y,m),[y,m]),k=r.useMemo(()=>{const p=new Map;return y.forEach(w=>{const E=v.get(w.id)??0;p.has(E)||p.set(E,[]),p.get(E).push(w.id)}),p},[y,v]),T=r.useMemo(()=>[...A].reverse(),[A]),{dependsOn:L,dependedBy:U}=r.useMemo(()=>{const p=new Map,w=new Map;return m.forEach(E=>{p.has(E.from)||p.set(E.from,[]),p.get(E.from).push(E.to),w.has(E.to)||w.set(E.to,[]),w.get(E.to).push(E.from)}),{dependsOn:p,dependedBy:w}},[m]),B=Math.min(Pt,Math.max(...A.map(p=>(k.get(p)??[]).length),1)),b=(B-1)*Zt+B*yt+ma*2,R=Math.max(600,Dt*2+b),M=Math.max(...[...S.values()].map(p=>p.y),0),H=Math.max(420,M+Gt/2+Dt+20),_=[{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)"}],P=p=>_[Math.min(p,_.length-1)]??_[0];return a?e.jsx("div",{className:"flex items-center justify-center min-h-[320px]",children:e.jsx("div",{className:"animate-spin rounded-full h-10 w-10 border-2 border-blue-600 border-t-transparent"})}):n?e.jsxs("div",{className:"rounded-xl border border-red-200 bg-red-50 p-6 text-red-700 shadow-sm",children:[e.jsx("p",{children:n}),e.jsx("button",{type:"button",onClick:d,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:"w-full max-w-[1400px] mx-auto space-y-6",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-4",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"flex items-center justify-center w-10 h-10 rounded-xl bg-blue-50 border border-blue-100",children:e.jsx(gt,{size:z.lg,className:"text-blue-600"})}),e.jsxs("div",{children:[e.jsx("h2",{className:"text-xl font-bold text-slate-900",children:"项目依赖关系图"}),t.projectRoot&&e.jsxs("p",{className:"text-sm text-slate-500 mt-0.5",children:["项目根: ",e.jsx("code",{className:"bg-slate-100 px-1.5 py-0.5 rounded text-slate-600",children:t.projectRoot}),t.generatedAt&&e.jsxs("span",{className:"ml-2",children:["· 生成于 ",new Date(t.generatedAt).toLocaleString()]})]})]})]}),e.jsxs("button",{type:"button",onClick:()=>{d()},className:"flex items-center gap-2 px-4 py-2 rounded-lg border border-slate-200 bg-white hover:bg-slate-50 text-slate-700 font-medium text-sm shadow-sm transition-colors",children:[e.jsx(wt,{size:z.md})," 刷新"]})]}),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:H,viewBox:`0 0 ${R} ${H}`,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"})})}),T.map((p,w)=>{const E=P(w),se=f.get(p);return se?e.jsx("rect",{x:Dt,y:se.y-Gt/2-4,width:b,height:se.h+8,rx:8,fill:E.bg,stroke:E.border,strokeWidth:"1",opacity:.6},p):null}),y.map(p=>{const w=S.get(p.id);if(!w)return null;const E=v.get(p.id)??0,se=P(T.indexOf(E)),h=p.label.length>14?p.label.slice(0,13)+"…":p.label,V=c===p.id,me=c?(L.get(c)??[]).includes(p.id):!1,F=c?(U.get(c)??[]).includes(p.id):!1,X=c&&!V&&!me&&!F,Y=c?V?{fill:"white",stroke:"rgb(59 130 246)",text:"rgb(30 64 175)",strokeWidth:3,opacity:1}:me?{fill:"rgb(240 253 244)",stroke:"rgb(34 197 94)",text:"rgb(22 101 52)",strokeWidth:2,opacity:1}:F?{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:se.border,text:se.text,strokeWidth:2,opacity:1};return e.jsxs("g",{style:{cursor:"pointer",opacity:Y.opacity},onClick:()=>i(V?null:p.id),children:[e.jsx("rect",{x:w.x-yt/2,y:w.y-Gt/2,width:yt,height:Gt,rx:10,ry:10,fill:Y.fill,stroke:Y.stroke,strokeWidth:Y.strokeWidth,filter:X?void 0:"url(#nodeShadow)"}),e.jsx("text",{x:w.x,y:w.y,textAnchor:"middle",dominantBaseline:"middle",fontSize:"12",fontWeight:"600",fill:Y.text,pointerEvents:"none",children:h})]},p.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:()=>i(null),className:"text-slate-400 hover:text-slate-600 text-lg leading-none","aria-label":"关闭",children:"×"})]}),e.jsxs("div",{className:"space-y-3 text-sm",children:[e.jsxs("div",{children:[e.jsx("div",{className:"font-semibold text-slate-600 mb-1",children:"依赖"}),e.jsx("ul",{className:"text-slate-700 space-y-0.5",children:(L.get(c)??[]).length===0?e.jsx("li",{className:"text-slate-400",children:"无"}):(L.get(c)??[]).map(p=>e.jsxs("li",{children:["→ ",p]},p))})]}),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:(U.get(c)??[]).length===0?e.jsx("li",{className:"text-slate-400",children:"无"}):(U.get(c)??[]).map(p=>e.jsxs("li",{children:["← ",p]},p))})]})]})]})]}),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(p=>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:p.id}),p.packageDir&&e.jsxs("span",{className:"text-slate-500 text-xs",children:["· ",p.packageDir]})]}),p.targets&&p.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:p.targets.join(", ")})]})]},p.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:["依赖关系(小图)(",m.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:m.map((p,w)=>e.jsxs("li",{className:"flex items-center gap-2 text-slate-700",children:[e.jsx("span",{className:"font-semibold text-slate-800",children:p.from}),e.jsx("span",{className:"text-slate-400 shrink-0",children:"→"}),e.jsx("span",{className:"font-semibold text-slate-800",children:p.to})]},`${p.from}-${p.to}-${w}`))})]}),x==="target"&&e.jsxs("p",{className:"text-xs text-slate-500 mt-2",children:["Target 级节点格式:",e.jsx("span",{className:"font-mono",children:"Package::Target"})]})]})]})},gr=({onRefresh:t})=>{const[s,a]=r.useState({}),[l,n]=r.useState([]),[o,c]=r.useState(null),[i,x]=r.useState(!0),[$,d]=r.useState(!1),[y,m]=r.useState(!1),[S,v]=r.useState(""),[A,f]=r.useState(!1),[k,T]=r.useState({ruleId:"",message:"",severity:"warning",pattern:"",languages:["objc","swift"],note:"",dimension:""}),[L,U]=r.useState(!1),[B,K]=r.useState(""),b=async()=>{try{const[w,E]=await Promise.all([te.getGuardRules(),te.getGuardViolations()]);a((w==null?void 0:w.rules)||{}),n((E==null?void 0:E.runs)||[])}catch{a({}),n([])}finally{x(!1)}};r.useEffect(()=>{b()},[]);const R=async()=>{if(window.confirm("确定清空所有 Guard 违反记录?"))try{await te.clearViolations(),b(),t==null||t()}catch(w){ee((w==null?void 0:w.message)||"清空违反记录失败",{title:"操作失败",type:"error"})}},M=w=>{T(E=>({...E,languages:E.languages.includes(w)?E.languages.filter(se=>se!==w):[...E.languages,w]}))},H=async()=>{var w,E;if(!S.trim()){K("请先输入语义描述");return}K(""),f(!0);try{const h=await te.generateGuardRule({description:S.trim()}),V=h.dimension;T({ruleId:h.ruleId||"",message:h.message||"",severity:h.severity==="error"?"error":"warning",pattern:h.pattern||"",languages:Array.isArray(h.languages)&&h.languages.length>0?h.languages:["objc","swift"],note:h.note!=null?String(h.note):"",dimension:V==="file"||V==="target"||V==="project"?V:""}),m(!0)}catch(se){K(((E=(w=se==null?void 0:se.response)==null?void 0:w.data)==null?void 0:E.error)||(se==null?void 0:se.message)||"AI 生成失败")}finally{f(!1)}},_=async w=>{var E,se;if(w.preventDefault(),K(""),!k.ruleId.trim()||!k.message.trim()||!k.pattern.trim()||k.languages.length===0){K("请填写规则 ID、说明、正则和至少一种语言");return}U(!0);try{await te.saveGuardRule({ruleId:k.ruleId.trim(),message:k.message.trim(),severity:k.severity,pattern:k.pattern.trim(),languages:k.languages,note:k.note.trim()||void 0,...k.dimension?{dimension:k.dimension}:{}}),T({ruleId:"",message:"",severity:"warning",pattern:"",languages:["objc","swift"],note:"",dimension:""}),v(""),m(!1),b(),t==null||t()}catch(h){K(((se=(E=h==null?void 0:h.response)==null?void 0:E.data)==null?void 0:se.error)||(h==null?void 0:h.message)||"写入失败")}finally{U(!1)}};if(i)return e.jsx("div",{className:"p-6 text-slate-500",children:"加载中..."});const P=Object.entries(s),p=l.reduce((w,E)=>w+E.violations.length,0);return e.jsxs("div",{className:"p-6",children:[e.jsxs("div",{className:"flex items-center justify-between mb-6",children:[e.jsxs("h2",{className:"text-xl font-bold text-slate-900 flex items-center gap-2",children:[e.jsx(bt,{size:z.xl,className:"text-blue-600"}),"Guard 规则与违反记录"]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("a",{href:ul,target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1.5 px-3 py-1.5 text-sm text-slate-600 hover:text-slate-900 hover:bg-slate-100 rounded-lg transition-colors",children:[e.jsx(Wa,{size:z.md})," 提交误报/建议"]}),e.jsxs("button",{type:"button",onClick:()=>d(!$),className:"flex items-center gap-1.5 px-3 py-1.5 text-sm text-slate-600 hover:text-slate-900 hover:bg-slate-100 rounded-lg transition-colors",children:[$?e.jsx(kt,{size:z.md}):e.jsx(it,{size:z.md}),"AI 写入规则"]}),l.length>0&&e.jsxs("button",{type:"button",onClick:R,className:"flex items-center gap-2 px-3 py-1.5 text-sm text-slate-500 hover:text-red-600 hover:bg-red-50 rounded-lg transition-colors",children:[e.jsx(ht,{size:z.sm})," 清空历史"]})]})]}),$&&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:S,onChange:w=>{v(w.target.value),K("")},className:"w-full px-3 py-2 border border-slate-200 rounded-lg text-sm resize-y min-h-[80px]",placeholder:"例如:禁止在主线程使用 dispatch_sync 调用 main queue,易死锁",rows:3}),e.jsx("button",{type:"button",onClick:H,disabled:A||!S.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 生成"}),B&&e.jsx("p",{className:"mt-2 text-sm text-red-600",children:B})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{type:"button",onClick:()=>m(!y),className:"text-sm font-medium text-blue-600 hover:text-blue-700",children:y?"收起表单":"展开 / 编辑表单"}),k.ruleId&&e.jsxs("span",{className:"text-xs text-slate-500",children:["已生成规则 ID:",k.ruleId]})]})]}),y&&e.jsxs("form",{onSubmit:_,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:k.ruleId,onChange:w=>T(E=>({...E,ruleId:w.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:k.severity,onChange:w=>T(E=>({...E,severity:w.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:k.message,onChange:w=>T(E=>({...E,message:w.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:k.pattern,onChange:w=>T(E=>({...E,pattern:w.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:k.languages.includes("objc"),onChange:()=>M("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:k.languages.includes("swift"),onChange:()=>M("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:k.dimension,onChange:w=>T(E=>({...E,dimension:w.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:k.note,onChange:w=>T(E=>({...E,note:w.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:L,className:"px-4 py-2 bg-blue-600 text-white text-sm rounded-lg hover:bg-blue-700 disabled:opacity-50",children:L?"写入中...":"确认写入"}),e.jsx("button",{type:"button",onClick:()=>m(!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:P.length===0?e.jsx("tr",{children:e.jsx("td",{colSpan:5,className:"py-4 px-4 text-slate-500",children:"暂无规则"})}):P.map(([w,E])=>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:w}),e.jsx("td",{className:"py-2 px-4",children:e.jsx("span",{className:`text-xs font-medium px-1.5 py-0.5 rounded ${E.severity==="error"?"bg-red-100 text-red-700":"bg-amber-100 text-amber-700"}`,children:E.severity})}),e.jsx("td",{className:"py-2 px-4 text-slate-700",children:E.message}),e.jsx("td",{className:"py-2 px-4 text-slate-500",children:(E.languages||[]).join(", ")}),e.jsx("td",{className:"py-2 px-4 text-slate-500 text-xs",children:E.dimension==="file"?"同文件":E.dimension==="target"?"同 target":E.dimension==="project"?"同项目":"—"})]},w))})]})})]}),e.jsxs("section",{children:[e.jsxs("h3",{className:"text-sm font-semibold text-slate-700 mb-3",children:["违反记录(共 ",l.length," 次运行,",p," 处违反)"]}),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(w=>{const E=o===w.id,se=w.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(E?null:w.id),className:"w-full flex items-center gap-2 py-3 px-4 text-left hover:bg-slate-50 transition-colors",children:[E?e.jsx(kt,{size:z.md}):e.jsx(it,{size:z.md}),e.jsx("span",{className:"font-mono text-sm text-slate-700",children:w.filePath}),e.jsx("span",{className:"text-xs text-slate-400",children:new Date(w.triggeredAt).toLocaleString()}),se?e.jsxs("span",{className:"ml-auto flex items-center gap-1 text-amber-600 text-xs font-medium",children:[e.jsx(Ot,{size:z.sm})," ",w.violations.length," 处违反"]}):e.jsx("span",{className:"ml-auto text-slate-400 text-xs",children:"无违反"})]}),E&&e.jsx("div",{className:"border-t border-slate-100 bg-slate-50/50 p-4",children:w.violations.length===0?e.jsx("p",{className:"text-sm text-slate-500",children:"本次运行未发现违反。"}):e.jsx("ul",{className:"space-y-2",children:w.violations.map((h,V)=>{var F;const me=s[h.ruleId];return e.jsxs("li",{className:"flex items-start gap-2 text-sm",children:[h.severity==="error"?e.jsx(ys,{size:z.md,className:"text-red-500 shrink-0 mt-0.5"}):e.jsx(Ot,{size:z.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:["[",h.ruleId,"] ",h.filePath?`${h.filePath}:${h.line}`:`L${h.line}`]}),h.dimension&&e.jsx("span",{className:"ml-1.5 text-xs px-1.5 py-0.5 rounded bg-slate-200 text-slate-600",children:h.dimension==="file"?"同文件":h.dimension==="target"?"同 target":"同项目"}),e.jsx("span",{className:"text-slate-700 ml-2",children:h.message})]}),h.snippet&&e.jsx("pre",{className:"text-xs text-slate-600 bg-slate-100 p-2 rounded overflow-x-auto",children:h.snippet}),me&&(me.rationale||((F=me.fixSuggestions)==null?void 0:F.length)||me.sourceRecipe||me.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:[me.rationale&&e.jsxs("div",{className:"flex items-start gap-1.5",children:[e.jsx(at,{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:me.rationale})]})]}),me.fixSuggestions&&me.fixSuggestions.length>0&&e.jsxs("div",{className:"flex items-start gap-1.5",children:[e.jsx(ea,{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:me.fixSuggestions.map((X,Y)=>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:X}),e.jsx("button",{className:"ml-1 text-blue-500 hover:text-blue-700",title:"复制修复建议",onClick:()=>navigator.clipboard.writeText(X),children:"⎘"})]},Y))})]})]}),me.sourceRecipe&&e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(hs,{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:me.sourceRecipe})]}),!me.rationale&&me.note&&e.jsxs("div",{className:"text-slate-500 italic",children:["备注:",me.note]})]})]})]},V)})})})]},w.id)})})]})]})},ms=()=>Math.random().toString(36).substring(2,10),fr=({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(Ws,{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 jr(t){const s=new Date(t),l=new Date().getTime()-s.getTime(),n=Math.floor(l/6e4);if(n<1)return"刚刚";if(n<60)return`${n}分钟前`;const o=Math.floor(n/60);if(o<24)return`${o}小时前`;const c=Math.floor(o/24);return c<7?`${c}天前`:s.toLocaleDateString("zh-CN",{month:"short",day:"numeric"})}const yr=()=>{const t=Dl(),{close:s,isOpen:a}=Ht(),{messages:l,setMessages:n,loading:o,setLoading:c,chatHistoryRef:i}=t,x=ia(),{topics:$,activeTopicId:d,activeTopic:y,createTopic:m,deleteTopic:S,saveTopic:v,switchTopic:A,setActiveTopicId:f}=x,k=r.useRef(null),T=r.useRef(null),[L,U]=r.useState(""),[B,K]=r.useState(!1),b=r.useRef(!1);r.useEffect(()=>{a&&s()},[]),r.useEffect(()=>{var p;(p=k.current)==null||p.scrollIntoView({behavior:"smooth"})},[l,o]),r.useEffect(()=>{setTimeout(()=>{var p;return(p=T.current)==null?void 0:p.focus()},200)},[]),r.useEffect(()=>{b.current||d&&l.length>0&&v(d,l)},[l,d,v]);const R=r.useCallback(()=>{b.current=!0,m(),n([]),i.current=[],setTimeout(()=>{b.current=!1},50)},[m,n,i]),M=r.useCallback(p=>{if(p===d)return;b.current=!0,A(p);const w=x.getTopic(p);w?(n(w.messages),i.current=w.messages.filter(E=>E.role==="user"||E.role==="assistant").map(E=>({role:E.role==="assistant"?"model":E.role,content:E.content}))):(n([]),i.current=[]),setTimeout(()=>{b.current=!1},50)},[d,A,x,n,i]),H=r.useCallback((p,w)=>{p.stopPropagation(),S(w),w===d&&(b.current=!0,n([]),i.current=[],setTimeout(()=>{b.current=!1},50))},[S,d,n,i]),_=r.useCallback(async()=>{const p=L.trim();if(!p||o)return;let w=d;w||(b.current=!0,w=m(),setTimeout(()=>{b.current=!1},50)),U(""),n(E=>[...E,{id:ms(),role:"user",content:p,timestamp:Date.now()}]),c(!0),i.current.push({role:"user",content:p});try{const E=await te.chat(p,i.current);i.current.push({role:"model",content:E.text}),n(se=>[...se,{id:ms(),role:"assistant",content:E.text,timestamp:Date.now()}])}catch(E){n(se=>[...se,{id:ms(),role:"assistant",content:`请求失败: ${E.message}`,timestamp:Date.now()}])}c(!1)},[L,o,d,m]),P=r.useCallback(p=>{p.key==="Enter"&&!p.shiftKey&&(p.preventDefault(),_())},[_]);return e.jsxs("div",{className:"flex-1 flex h-full bg-slate-50",children:[e.jsx("div",{className:`${B?"w-10":"w-64"} shrink-0 bg-white border-r border-slate-200 flex flex-col transition-all duration-200`,children:B?e.jsxs("div",{className:"flex flex-col items-center py-3 gap-2",children:[e.jsx("button",{onClick:()=>K(!1),className:"p-1.5 hover:bg-slate-100 rounded-lg transition-colors text-slate-400 hover:text-slate-600",title:"展开话题列表",children:e.jsx(it,{size:16})}),e.jsx("button",{onClick:R,className:"p-1.5 hover:bg-blue-50 rounded-lg transition-colors text-blue-500",title:"新建话题",children:e.jsx(ut,{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:R,className:"p-1.5 hover:bg-blue-50 rounded-lg transition-colors text-slate-400 hover:text-blue-600",title:"新建话题",children:e.jsx(ut,{size:14})}),e.jsx("button",{onClick:()=>K(!0),className:"p-1.5 hover:bg-slate-100 rounded-lg transition-colors text-slate-400 hover:text-slate-600",title:"折叠",children:e.jsx(fs,{size:14})})]})]}),e.jsx("div",{className:"flex-1 overflow-y-auto scrollbar-light",children:$.length===0?e.jsxs("div",{className:"px-4 py-8 text-center",children:[e.jsx(vt,{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:$.map(p=>{const w=p.id===d,E=p.messages.filter(se=>se.role==="user").length;return e.jsx("div",{onClick:()=>M(p.id),className:`group mx-1.5 mb-0.5 px-3 py-2 rounded-lg cursor-pointer transition-colors ${w?"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 ${w?"text-blue-700":"text-slate-700"}`,children:p.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(Nt,{size:9}),jr(p.updatedAt)]}),E>0&&e.jsxs("span",{className:"text-[10px] text-slate-300",children:[E," 条"]})]})]}),e.jsx("button",{onClick:se=>H(se,p.id),className:`p-1 rounded transition-colors shrink-0 ${w?"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(ht,{size:12})})]})},p.id)})})}),$.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:[$.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(vt,{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:"询问任何关于项目的问题"})]})]}),l.length>0&&e.jsxs("button",{onClick:R,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(ut,{size:14}),"开启新话题"]})]}),e.jsx("div",{className:"flex-1 overflow-y-auto min-h-0 scrollbar-light",children:e.jsxs("div",{className:"max-w-3xl mx-auto p-6 space-y-4",children:[l.length===0&&e.jsxs("div",{className:"flex flex-col items-center justify-center py-20 text-center",children:[e.jsx("div",{className:"w-16 h-16 rounded-2xl bg-gradient-to-br from-blue-50 to-indigo-50 border border-blue-100 flex items-center justify-center mb-4",children:e.jsx(Ye,{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(p=>e.jsx("button",{onClick:()=>{var w;U(p),(w=T.current)==null||w.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:p},p))})]}),l.map(p=>e.jsx("div",{className:`flex ${p.role==="user"?"justify-end":"justify-start"}`,children:e.jsxs("div",{className:`max-w-[80%] ${p.role==="user"?"bg-blue-600 text-white rounded-2xl rounded-tr-md px-4 py-2.5":p.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:[p.role==="assistant"&&e.jsxs("div",{className:"flex items-center gap-1.5 mb-2",children:[e.jsx(It,{size:13,className:"text-blue-500"}),e.jsx("span",{className:"text-[11px] font-bold text-blue-600",children:"AI 助手"})]}),p.role==="assistant"&&!p.diff?e.jsx(lt,{content:p.content,className:"text-sm text-slate-700"}):e.jsx("p",{className:`text-sm leading-relaxed whitespace-pre-wrap ${p.role==="user"?"":"text-slate-600"}`,children:p.content}),p.diff&&p.diff.length>0&&e.jsx("div",{className:"space-y-2 mt-2",children:p.diff.map(w=>e.jsx(fr,{d:w},w.field))})]})},p.id)),o&&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(ze,{size:14,className:"animate-spin text-blue-500"}),e.jsx("span",{className:"text-sm text-slate-500",children:"AI 思考中..."})]})})}),e.jsx("div",{ref:k})]})}),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:T,value:L,onChange:p=>U(p.target.value),onKeyDown:P,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:o}),e.jsx("button",{onClick:_,disabled:!L.trim()||o,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(gs,{size:16})})]}),e.jsx("p",{className:"text-[10px] text-slate-400 mt-1.5",children:"Enter 发送 · Shift+Enter 换行"})]})})]})]})},Nr=28,vr=22,wr=50,kr=11,Sr=10,ct={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"},Vt={depends_on:"依赖",requires:"需要",extends:"扩展",implements:"实现",inherits:"继承",enforces:"约束",related:"关联",conflicts:"冲突",calls:"调用",prerequisite:"前置",data_flow_to:"数据流",references:"引用",alternative:"替代",deprecated_by:"废弃",solves:"解决"},qt=[{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 jt(t){return Math.min(wr,Math.max(vr,Nr+t*2))}function Ps(t,s){return t.length<=s?t:t.substring(0,s-1)+"…"}function Cr(t,s,a,l){const n=new Map;for(const d of t)n.set(d.fromId,(n.get(d.fromId)||0)+1),n.set(d.toId,(n.get(d.toId)||0)+1);const o=[...n.keys()],c=[...new Set(o.map(d=>l[d]||"general"))].sort(),i=new Map,x=Math.ceil(Math.sqrt(c.length)),$=400;return c.forEach((d,y)=>{const m=y%x,S=Math.floor(y/x);i.set(d,{x:450+(m-(x-1)/2)*$,y:350+(S-(Math.ceil(c.length/x)-1)/2)*$})}),o.map(d=>{const y=l[d]||"general",m=i.get(y)||{x:450,y:350},S=Math.random()*2*Math.PI,v=40+Math.random()*80;return{id:d,label:s[d]||d,type:a[d]||"recipe",group:y,x:m.x+v*Math.cos(S),y:m.y+v*Math.sin(S),vx:0,vy:0,degree:n.get(d)||1}})}function Ir(t,s,a=200){const l=t.map(c=>({...c})),n=new Map(l.map(c=>[c.id,c]));function o(){const c=new Map;for(const i of l){const x=c.get(i.group);x?(x.x+=i.x,x.y+=i.y,x.count++):c.set(i.group,{x:i.x,y:i.y,count:1})}for(const[,i]of c)i.x/=i.count,i.y/=i.count;return c}for(let c=0;c<a;c++){const i=1-c/a,x=18e3*i,$=.015,d=.8,y=o();for(let S=0;S<l.length;S++)for(let v=S+1;v<l.length;v++){const A=l[S],f=l[v];let k=f.x-A.x,T=f.y-A.y,L=Math.sqrt(k*k+T*T)||1;const U=jt(A.degree)+jt(f.degree)+60,B=Math.max(L,1),K=A.group===f.group?.6:1.4,b=x*K/(B*B),R=L<U?(U-L)*.5:0,M=b+R,H=k/B*M,_=T/B*M;A.vx-=H,A.vy-=_,f.vx+=H,f.vy+=_}for(const S of s){const v=n.get(S.fromId),A=n.get(S.toId);if(!v||!A)continue;let f=A.x-v.x,k=A.y-v.y,T=Math.sqrt(f*f+k*k)||1;const L=v.group===A.group?140:280,U=$*(T-L),B=f/T*U,K=k/T*U;v.vx+=B,v.vy+=K,A.vx-=B,A.vy-=K}const m=.008*i;for(const S of l){const v=y.get(S.group);v&&(S.vx+=(v.x-S.x)*m,S.vy+=(v.y-S.y)*m)}for(const S of l)S.vx*=d,S.vy*=d,S.x+=S.vx,S.y+=S.vy}return l}function $r(t,s,a,l,n,o,c=0){const i=a-t,x=l-s,$=Math.sqrt(i*i+x*x)||1,d=i/$,y=x/$,m=t+d*n,S=s+y*n,v=a-d*o,A=l-y*o;if(c===0)return`M${m},${S}L${v},${A}`;const f=(m+v)/2+-y*c,k=(S+A)/2+d*c;return`M${m},${S}Q${f},${k},${v},${A}`}const Ar=()=>{const[t,s]=r.useState([]),[a,l]=r.useState({}),[n,o]=r.useState({}),[c,i]=r.useState({}),[x,$]=r.useState(null),[d,y]=r.useState(!0),[m,S]=r.useState(null),[v,A]=r.useState(null),[f,k]=r.useState(null),[T,L]=r.useState(null),[U,B]=r.useState(!1),[K,b]=r.useState(null),[R,M]=r.useState(1),[H,_]=r.useState({x:0,y:0}),P=r.useRef(null),p=r.useRef(null),w=r.useRef(!1),E=r.useRef({x:0,y:0}),se=async()=>{var g,J;y(!0),S(null);try{const[Z,u]=await Promise.all([te.getKnowledgeGraph(),te.getGraphStats()]);s(Z.edges||[]),l(Z.nodeLabels||{}),o(Z.nodeTypes||{}),i(Z.nodeCategories||{}),$(u)}catch(Z){S(((J=(g=Z.response)==null?void 0:g.data)==null?void 0:J.error)||Z.message||"加载知识图谱失败")}finally{y(!1)}};r.useEffect(()=>{se()},[]),r.useEffect(()=>{te.getDiscoverRelationsStatus().then(g=>{g.status==="running"&&(B(!0),b(`AI 分析中…(已运行 ${g.elapsed??0}s)`))}).catch(()=>{})},[]),r.useEffect(()=>{if(!U)return;let g=0;const J=240,Z=setInterval(async()=>{if(g++,g>J){clearInterval(Z),B(!1),b("轮询超时,任务可能仍在后台运行。请稍后刷新页面查看结果。");return}try{const u=await te.getDiscoverRelationsStatus();if(u.status==="done"){B(!1);const I=u.discovered??0,G=u.totalPairs??0,C=u.batchErrors??0;I===0&&C===0?b(`分析完成,共检查 ${G} 对 Recipe,未发现关系。待 Recipe 数量增加后可再次尝试。`):I===0&&C>0?b(`分析完成,但 ${C} 个批次 AI 调用失败,未发现关系。请检查 AI Provider 配置。`):b(`发现 ${I} 条关系(共分析 ${G} 对${C>0?`,${C} 个批次失败`:""})`),se()}else if(u.status==="error"){B(!1);const I=u.error||"未知错误";I.includes("AI Provider")||I.includes("API Key")?b(`AI 服务未配置: ${I}`):I.includes("超时")||I.includes("timeout")?b(`任务超时: ${I}`):b(`发现失败: ${I}`)}else u.status==="running"&&b(`AI 分析中…(已运行 ${u.elapsed??0}s)`)}catch{}},3e3);return()=>clearInterval(Z)},[U]);const h=r.useCallback(async()=>{var g,J,Z;b(null);try{const u=await te.discoverRelations();if(u.status==="empty"){b(u.message||"Recipe 数量不足,无法分析");return}if(u.status==="timeout"){b(u.error||"上次任务超时,请重试");return}if(u.status==="running"){B(!0),b("AI 分析仍在进行中…");return}B(!0),b("AI 分析已启动,正在后台运行…")}catch(u){const I=((Z=(J=(g=u==null?void 0:u.response)==null?void 0:g.data)==null?void 0:J.error)==null?void 0:Z.message)||u.message||"未知错误";I.includes("ChatAgent")||I.includes("AI Provider")?b(`AI 服务不可用: ${I}`):b(`启动失败: ${I}`)}},[]),V=r.useMemo(()=>{if(t.length===0)return[];const g=Cr(t,a,n,c);return Ir(g,t)},[t,a,n,c]),me=r.useMemo(()=>{const g=new Map;for(const u of V){const I=g.get(u.group)||[];I.push(u),g.set(u.group,I)}const J=[],Z=[...g.keys()].sort();for(const u of Z){const I=g.get(u);if(I.length===0)continue;let G=0,C=0;for(const ue of I)G+=ue.x,C+=ue.y;G/=I.length,C/=I.length;let q=0,ae=0;for(const ue of I){const oe=jt(ue.degree);q=Math.max(q,Math.abs(ue.x-G)+oe+35),ae=Math.max(ae,Math.abs(ue.y-C)+oe+35)}J.push({group:u,cx:G,cy:C,rx:Math.max(q,60),ry:Math.max(ae,60),count:I.length})}return J},[V]),F=r.useMemo(()=>{const g=[...new Set(V.map(Z=>Z.group))].sort(),J={};return g.forEach((Z,u)=>{J[Z]=qt[u%qt.length]}),J},[V]),X=r.useMemo(()=>{if(V.length===0)return{x:0,y:0,w:900,h:700};let g=1/0,J=1/0,Z=-1/0,u=-1/0;for(const I of V){const G=jt(I.degree);g=Math.min(g,I.x-G-80),J=Math.min(J,I.y-G-40),Z=Math.max(Z,I.x+G+80),u=Math.max(u,I.y+G+40)}return{x:g,y:J,w:Z-g,h:u-J}},[V]),Y=r.useMemo(()=>new Map(V.map(g=>[g.id,g])),[V]),{connectedEdgeIds:ie,connectedNodeIds:Ne}=r.useMemo(()=>{const g=v||f;if(!g)return{connectedEdgeIds:new Set,connectedNodeIds:new Set};const J=new Set,Z=new Set([g]);for(const u of t)(u.fromId===g||u.toId===g)&&(J.add(u.id),Z.add(u.fromId),Z.add(u.toId));return{connectedEdgeIds:J,connectedNodeIds:Z}},[v,f,t]),Re=r.useMemo(()=>{const g=new Map,J=new Map;for(const u of t){const I=[u.fromId,u.toId].sort().join("|"),G=g.get(I)||0;J.set(u.id,G),g.set(I,G+1)}const Z=new Map;for(const u of t){const I=[u.fromId,u.toId].sort().join("|"),G=g.get(I)||1;if(G<=1){Z.set(u.id,0);continue}const C=J.get(u.id)||0;Z.set(u.id,(C-(G-1)/2)*40)}return Z},[t]),[fe,Q]=r.useState(new Set);r.useEffect(()=>{Q(new Set(t.map(g=>g.relation)))},[t]);const ve=r.useMemo(()=>t.filter(g=>fe.has(g.relation)),[t,fe]),Le=g=>{Q(J=>{const Z=new Set(J);return Z.has(g)?Z.delete(g):Z.add(g),Z})},Ge=r.useCallback(g=>{g.button===0&&(w.current=!0,E.current={x:g.clientX,y:g.clientY})},[]),we=r.useCallback(g=>{if(!w.current)return;const J=g.clientX-E.current.x,Z=g.clientY-E.current.y;E.current={x:g.clientX,y:g.clientY},_(u=>({x:u.x+J,y:u.y+Z}))},[]),Fe=r.useCallback(()=>{w.current=!1},[]),Ee=r.useCallback(g=>{g.preventDefault();const J=g.deltaY>0?-.1:.1;M(Z=>Math.min(3,Math.max(.2,Z+J)))},[]),ke=g=>`kg-arrow-${g.replace(/[^a-z_]/g,"")}`;if(d)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(m)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:m}),e.jsx("button",{onClick:se,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(ps,{size:48,className:"text-slate-300"}),e.jsx("p",{className:"text-lg font-medium",children:"知识图谱为空"}),e.jsx("p",{className:"text-sm text-center max-w-md",children:"当前没有 Recipe 之间的关系数据。点击下方按钮让 AI 自动分析已有 Recipe 之间的潜在关系(requires / extends / enforces / calls 等)。"}),K&&e.jsx("p",{className:`text-sm ${K.startsWith("发现失败")?"text-red-500":"text-green-600"}`,children:K}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("button",{onClick:h,disabled:U,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:U?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(Ye,{size:z.sm})," AI 发现关系"]})}),e.jsxs("button",{onClick:se,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(wt,{size:z.sm})," 刷新"]})]})]});const De=[...new Set(t.map(g=>g.relation))].sort(),Ve=!!(v||f);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(ps,{size:z.lg,className:"text-blue-600"}),e.jsx("h2",{className:"text-lg font-bold text-slate-800",children:"知识图谱"}),x&&e.jsxs("span",{className:"text-xs text-slate-500 bg-slate-100 px-2 py-1 rounded-full",children:[V.length," 节点 · ",x.totalEdges," 关系"]})]}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("button",{onClick:()=>M(g=>Math.min(g+.2,3)),className:"p-1.5 rounded-lg bg-slate-100 hover:bg-slate-200 transition-colors",title:"放大",children:e.jsx(Ka,{size:z.sm})}),e.jsx("button",{onClick:()=>M(g=>Math.max(g-.2,.2)),className:"p-1.5 rounded-lg bg-slate-100 hover:bg-slate-200 transition-colors",title:"缩小",children:e.jsx(Va,{size:z.sm})}),e.jsx("button",{onClick:()=>{M(1),_({x:0,y:0})},className:"p-1.5 rounded-lg bg-slate-100 hover:bg-slate-200 transition-colors",title:"重置",children:e.jsx(js,{size:z.sm})}),e.jsx("button",{onClick:se,className:"p-1.5 rounded-lg bg-slate-100 hover:bg-slate-200 transition-colors",title:"刷新",children:e.jsx(wt,{size:z.sm})}),e.jsx("button",{onClick:h,disabled:U,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:U?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(Ye,{size:z.sm})," 发现关系"]})})]})]}),e.jsx("div",{className:"flex flex-wrap gap-1.5 mb-3 flex-shrink-0",children:De.map(g=>{var J;return e.jsxs("button",{onClick:()=>Le(g),className:`flex items-center gap-1 px-2 py-0.5 rounded-full text-[11px] font-medium transition-all border ${fe.has(g)?"border-transparent shadow-sm":"border-slate-200 bg-white text-slate-400 opacity-40"}`,style:fe.has(g)?{backgroundColor:(ct[g]||"#6b7280")+"18",color:ct[g]||"#6b7280"}:{},children:[e.jsx("span",{className:"w-2 h-2 rounded-full",style:{backgroundColor:ct[g]||"#6b7280"}}),Vt[g]||g,((J=x==null?void 0:x.byRelation)==null?void 0:J[g])!=null&&e.jsxs("span",{className:"opacity-60",children:["(",x.byRelation[g],")"]})]},g)})}),e.jsxs("div",{ref:p,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:w.current?"grabbing":"grab"},onWheel:Ee,children:[e.jsxs("svg",{ref:P,width:"100%",height:"100%",viewBox:`${X.x} ${X.y} ${X.w} ${X.h}`,onMouseDown:Ge,onMouseMove:we,onMouseUp:Fe,onMouseLeave:Fe,style:{transform:`scale(${R}) translate(${H.x/R}px, ${H.y/R}px)`},children:[e.jsxs("defs",{children:[De.map(g=>e.jsx("marker",{id:ke(g),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:ct[g]||"#6b7280"})},g)),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:me.map(g=>{const J=F[g.group]||qt[0];return e.jsxs("g",{children:[e.jsx("ellipse",{cx:g.cx,cy:g.cy,rx:g.rx,ry:g.ry,fill:J.bg,stroke:J.border,strokeWidth:1.5,strokeDasharray:"6,4",opacity:.6}),e.jsxs("text",{x:g.cx,y:g.cy-g.ry+14,textAnchor:"middle",fontSize:11,fontWeight:600,fill:J.text,opacity:.8,style:{pointerEvents:"none",userSelect:"none"},children:[g.group||"general"," (",g.count,")"]})]},g.group)})}),e.jsx("g",{children:ve.map(g=>{const J=Y.get(g.fromId),Z=Y.get(g.toId);if(!J||!Z)return null;const u=Ve?ie.has(g.id):!1,I=T===g.id,G=Ve?u?.85:.06:I?.9:.35,C=jt(J.degree),q=jt(Z.degree),ae=Re.get(g.id)||0,ue=$r(J.x,J.y,Z.x,Z.y,C,q,ae);return e.jsxs("g",{children:[e.jsx("path",{d:ue,fill:"none",stroke:"transparent",strokeWidth:12,onMouseEnter:()=>L(g.id),onMouseLeave:()=>L(null),style:{cursor:"pointer"}}),e.jsx("path",{d:ue,fill:"none",stroke:ct[g.relation]||"#6b7280",strokeWidth:I||u?2:1.2,opacity:G,markerEnd:`url(#${ke(g.relation)})`,strokeDasharray:g.relation==="related"?"6,3":void 0,style:{transition:"opacity 0.25s, stroke-width 0.15s",pointerEvents:"none"}}),I&&(()=>{const oe=(J.x+Z.x)/2,Ie=(J.y+Z.y)/2;return e.jsxs("g",{children:[e.jsx("rect",{x:oe-24,y:Ie-16,width:48,height:18,rx:4,fill:"white",stroke:ct[g.relation]||"#6b7280",strokeWidth:.8,opacity:.95}),e.jsx("text",{x:oe,y:Ie-4,textAnchor:"middle",fontSize:9,fontWeight:600,fill:ct[g.relation]||"#6b7280",children:Vt[g.relation]||g.relation})]})})()]},g.id)})}),e.jsx("g",{children:V.map(g=>{const J=jt(g.degree),Z=v===g.id,u=Ve&&Ne.has(g.id),I=Z||g.id===f,G=Ve&&!u,C=G?.12:1,q=F[g.group]||qt[0],ae=I?q.border:q.bg,ue=I?q.text:q.border,oe=I?"#ffffff":q.text,Ie=I?q.text:"#64748b";return e.jsxs("g",{onClick:re=>{re.stopPropagation(),A(Z?null:g.id)},onMouseEnter:()=>k(g.id),onMouseLeave:()=>k(null),style:{cursor:"pointer",transition:"opacity 0.25s"},opacity:C,filter:I?"url(#kg-glow)":void 0,children:[e.jsx("circle",{cx:g.x,cy:g.y,r:J,fill:ae,stroke:ue,strokeWidth:I?2.5:1.5}),e.jsx("text",{x:g.x,y:g.y+4,textAnchor:"middle",fontSize:Math.min(kr,J*.7),fill:oe,fontWeight:700,style:{pointerEvents:"none",userSelect:"none"},children:Ps(g.label,4).toUpperCase()}),e.jsx("text",{x:g.x,y:g.y+J+14,textAnchor:"middle",fontSize:Sr,fill:Ie,fontWeight:I?600:400,style:{pointerEvents:"none",userSelect:"none"},children:Ps(g.label,18)}),g.degree>=3&&!G&&e.jsxs("g",{children:[e.jsx("circle",{cx:g.x+J*.7,cy:g.y-J*.7,r:8,fill:"#3b82f6",stroke:"white",strokeWidth:1.5}),e.jsx("text",{x:g.x+J*.7,y:g.y-J*.7+3.5,textAnchor:"middle",fontSize:8,fill:"white",fontWeight:700,style:{pointerEvents:"none"},children:g.degree})]})]},g.id)})})]}),v&&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:"取消选中"})]}),v&&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(qa,{size:14,className:"text-blue-500"}),e.jsx("h3",{className:"font-semibold text-sm text-slate-800",children:a[v]||v}),e.jsxs("span",{className:"text-[10px] text-slate-400 ml-auto",children:["ID: ",v]})]}),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(g=>g.fromId===v&&fe.has(g.relation)).map(g=>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:ct[g.relation]||"#6b7280"}}),e.jsx("span",{className:"text-slate-500",children:Vt[g.relation]||g.relation}),e.jsx("span",{className:"text-slate-400",children:"→"}),e.jsx("button",{className:"text-blue-600 hover:underline truncate",onClick:()=>A(g.toId),children:a[g.toId]||g.toId.substring(0,16)})]},g.id)),t.filter(g=>g.fromId===v&&fe.has(g.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(g=>g.toId===v&&fe.has(g.relation)).map(g=>e.jsxs("li",{className:"flex items-center gap-1.5",children:[e.jsx("button",{className:"text-blue-600 hover:underline truncate",onClick:()=>A(g.fromId),children:a[g.fromId]||g.fromId.substring(0,16)}),e.jsx("span",{className:"text-slate-400",children:"→"}),e.jsx("span",{className:"text-slate-500",children:Vt[g.relation]||g.relation}),e.jsx("span",{className:"w-1.5 h-1.5 rounded-full flex-shrink-0",style:{backgroundColor:ct[g.relation]||"#6b7280"}})]},g.id)),t.filter(g=>g.toId===v&&fe.has(g.relation)).length===0&&e.jsx("li",{className:"text-slate-400",children:"无"})]})]})]})]})]})},Jt={manual:{label:"手动",color:"bg-slate-100 text-slate-600",icon:Hs},"user-ai":{label:"AI 协助",color:"bg-violet-100 text-violet-600",icon:Ye},"system-ai":{label:"自动",color:"bg-amber-100 text-amber-600",icon:Ut},"external-ai":{label:"外部 AI",color:"bg-cyan-100 text-cyan-600",icon:ta}},_r=({onRefresh:t,signalSuggestionCount:s=0,onSuggestionCountChange:a})=>{const[l,n]=r.useState([]),[o,c]=r.useState(!0),[i,x]=r.useState(null),[$,d]=r.useState(!1),[y,m]=r.useState(!1),[S,v]=r.useState("all"),[A,f]=r.useState(!1),[k,T]=r.useState([]),[L,U]=r.useState(!1),[B,K]=r.useState(!1),[b,R]=r.useState(null),M=r.useCallback(async()=>{var h;c(!0);try{const V=await te.listSkills();n(V.skills||[])}catch(V){((h=V.response)==null?void 0:h.status)!==404&&ee(V.message||"",{title:"获取 Skills 列表失败",type:"error"}),n([])}finally{c(!1)}},[]);r.useEffect(()=>{M()},[M]);const H=async h=>{if((i==null?void 0:i.skillName)===h){x(null);return}d(!0);try{const V=await te.loadSkill(h);x(V)}catch{ee(`"${h}" 不存在或读取出错`,{title:"加载 Skill 失败",type:"error"})}finally{d(!1)}},_=()=>{i!=null&&i.content&&(navigator.clipboard.writeText(i.content),f(!0),setTimeout(()=>f(!1),2e3))},P=async()=>{U(!0),K(!0);try{const[h,V]=await Promise.allSettled([te.suggestSkills(),te.getSignalStatus()]),me=h.status==="fulfilled"?h.value.suggestions||[]:[],F=V.status==="fulfilled"?V.value.suggestions||[]:[],X=new Map;for(const ie of me)X.set(ie.name,ie);for(const ie of F)X.set(ie.name,{...X.get(ie.name),...ie});const Y=[...X.values()];T(Y),a==null||a(Y.length)}catch(h){ee(h.message||"",{title:"获取 Skill 推荐失败",type:"error"}),T([]),a==null||a(0)}finally{U(!1)}};r.useEffect(()=>{s>0&&k.length===0&&!B&&P()},[]);const p=async h=>{R(h.name);try{const V=h.description||h.rationale||h.name,me=`请为以下场景创建一个 Skill 文档:
|
|
114
114
|
|
|
115
115
|
名称:${h.name}
|
|
116
116
|
描述:${V}
|
|
@@ -118,15 +118,15 @@ Skill 文档格式要求:
|
|
|
118
118
|
|
|
119
119
|
请直接生成 Skill 正文内容(Markdown 格式),不需要 frontmatter,不需要输出 JSON 元数据。内容应该详细、实用,包含具体的操作指南和示例。`;let X=(await te.aiGenerateSkill(me)).reply||h.body||`# ${V}
|
|
120
120
|
|
|
121
|
-
${h.rationale||""}`;X=X.replace(/^\s*\{["']name["']\s*:.*\}\s*\n?/,"").trim(),await te.createSkill({name:h.name,description:V,content:X,createdBy:"user-ai"}),ee("已创建并加入知识库",{title:`Skill "${h.name}" 创建成功`}),T(Y=>{const ie=Y.filter(Ne=>Ne.name!==h.name);return a==null||a(ie.length),ie}),M()}catch(V){ee(V.message||"",{title:"创建 Skill 失败",type:"error"})}finally{R(null)}},w=l.filter(h=>S==="all"?!0:h.source===S).sort((h,V)=>h.source===V.source?h.name.localeCompare(V.name):h.source==="project"?-1:1),E=l.filter(h=>h.source==="builtin").length,se=l.filter(h=>h.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(at,{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:P,disabled:L,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:[L?e.jsx(
|
|
121
|
+
${h.rationale||""}`;X=X.replace(/^\s*\{["']name["']\s*:.*\}\s*\n?/,"").trim(),await te.createSkill({name:h.name,description:V,content:X,createdBy:"user-ai"}),ee("已创建并加入知识库",{title:`Skill "${h.name}" 创建成功`}),T(Y=>{const ie=Y.filter(Ne=>Ne.name!==h.name);return a==null||a(ie.length),ie}),M()}catch(V){ee(V.message||"",{title:"创建 Skill 失败",type:"error"})}finally{R(null)}},w=l.filter(h=>S==="all"?!0:h.source===S).sort((h,V)=>h.source===V.source?h.name.localeCompare(V.name):h.source==="project"?-1:1),E=l.filter(h=>h.source==="builtin").length,se=l.filter(h=>h.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(at,{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:P,disabled:L,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:[L?e.jsx(ze,{size:14,className:"animate-spin"}):e.jsx(Lt,{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(wt,{size:16})}),e.jsxs("button",{onClick:()=>m(!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(Ye,{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:se,icon:Us},{key:"builtin",label:"内置",count:E,icon:Ja}].map(h=>e.jsxs("button",{onClick:()=>v(h.key),className:`flex items-center gap-1.5 px-3 py-1.5 rounded-md text-xs font-medium transition-colors ${S===h.key?"bg-white text-violet-700 shadow-sm":"text-slate-500 hover:text-slate-700"}`,children:[h.icon&&e.jsx(h.icon,{size:12}),h.label,e.jsx("span",{className:`ml-0.5 px-1.5 py-0.5 rounded-full text-[10px] ${S===h.key?"bg-violet-100 text-violet-600":"bg-slate-200 text-slate-500"}`,children:h.count})]},h.key))}),B&&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(Lt,{size:16,className:"text-amber-600"}),e.jsx("span",{className:"text-sm font-semibold text-amber-800",children:"推荐创建的 Skills"}),k.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:k.length})]}),e.jsx("button",{onClick:()=>K(!1),className:"p-1 text-amber-400 hover:text-amber-600",children:e.jsx(Ke,{size:14})})]}),L?e.jsxs("div",{className:"flex items-center gap-2 text-amber-600 text-xs py-2",children:[e.jsx(ze,{size:14,className:"animate-spin"}),"分析使用模式中..."]}):k.length===0?e.jsx("p",{className:"text-xs text-amber-600/70",children:"当前暂无推荐。继续使用后会积累更多信号。"}):e.jsx("div",{className:"space-y-2",children:k.map(h=>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:h.name}),e.jsx("span",{className:`px-1.5 py-0.5 rounded text-[9px] font-bold uppercase ${h.priority==="high"?"bg-red-100 text-red-600":h.priority==="medium"?"bg-amber-100 text-amber-600":"bg-slate-100 text-slate-500"}`,children:h.priority}),e.jsx("span",{className:"text-[10px] text-slate-400",children:h.source})]}),e.jsx("p",{className:"text-xs text-slate-600 mb-1",children:h.description}),e.jsx("p",{className:"text-[11px] text-slate-400 line-clamp-2",children:h.rationale})]}),e.jsx("button",{onClick:()=>p(h),disabled:b===h.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:b===h.name?e.jsxs(e.Fragment,{children:[e.jsx(ze,{size:12,className:"animate-spin"})," 创建中"]}):e.jsxs(e.Fragment,{children:[e.jsx(st,{size:12})," AI 创建"]})})]},h.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:o?e.jsx("div",{className:"flex items-center justify-center py-20",children:e.jsx(ze,{size:24,className:"animate-spin text-violet-400"})}):w.length===0?e.jsxs("div",{className:"text-center py-20 text-slate-400",children:[e.jsx(at,{size:40,className:"mx-auto mb-3 opacity-40"}),e.jsx("p",{children:"暂无 Skills"})]}):w.map(h=>e.jsx("button",{onClick:()=>H(h.name),className:`w-full text-left p-4 rounded-xl border transition-all ${(i==null?void 0:i.skillName)===h.name?"border-violet-300 bg-violet-50 shadow-sm":"border-slate-200 bg-white hover:border-slate-300 hover:shadow-sm"}`,children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("div",{className:`mt-0.5 shrink-0 ${(i==null?void 0:i.skillName)===h.name?"text-violet-500":"text-slate-400"}`,children:(i==null?void 0:i.skillName)===h.name?e.jsx(kt,{size:16}):e.jsx(it,{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:h.name}),e.jsx("span",{className:`px-1.5 py-0.5 rounded text-[10px] font-bold uppercase tracking-wider ${h.source==="builtin"?"bg-blue-100 text-blue-600":"bg-emerald-100 text-emerald-600"}`,children:h.source==="builtin"?"内置":"项目"}),h.createdBy&&Jt[h.createdBy]&&(()=>{const V=Jt[h.createdBy],me=V.icon;return e.jsxs("span",{className:`flex items-center gap-0.5 px-1.5 py-0.5 rounded text-[10px] font-medium ${V.color}`,children:[e.jsx(me,{size:10}),V.label]})})()]}),e.jsx("p",{className:"text-xs text-slate-500 line-clamp-2",children:h.summary}),h.useCase&&e.jsxs("p",{className:"text-[11px] text-violet-500 mt-1 italic",children:["适用:",h.useCase]})]})]})},h.name))}),e.jsx("div",{className:"w-1/2 overflow-y-auto border border-slate-200 rounded-xl bg-white",children:$?e.jsx("div",{className:"flex items-center justify-center h-full",children:e.jsx(ze,{size:24,className:"animate-spin text-violet-400"})}):i?e.jsxs("div",{className:"h-full flex flex-col",children:[e.jsxs("div",{className:"flex items-center justify-between p-4 border-b border-slate-100",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Ct,{size:16,className:"text-violet-500"}),e.jsx("span",{className:"font-mono font-semibold text-sm",children:i.skillName}),e.jsx("span",{className:`px-1.5 py-0.5 rounded text-[10px] font-bold uppercase ${i.source==="builtin"?"bg-blue-100 text-blue-600":"bg-emerald-100 text-emerald-600"}`,children:i.source==="builtin"?"内置":"项目"}),i.createdBy&&Jt[i.createdBy]&&(()=>{const h=Jt[i.createdBy],V=h.icon;return e.jsxs("span",{className:`flex items-center gap-0.5 px-1.5 py-0.5 rounded text-[10px] font-medium ${h.color}`,children:[e.jsx(V,{size:10}),h.label,"创建"]})})()]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("span",{className:"text-[10px] text-slate-400",children:[i.charCount," 字符"]}),e.jsx("button",{onClick:_,className:"p-1.5 rounded-md hover:bg-slate-100 transition-colors text-slate-400 hover:text-slate-600",title:"复制内容",children:A?e.jsx(_t,{size:14,className:"text-emerald-500"}):e.jsx(Ft,{size:14})})]})]}),i.relatedSkills.length>0&&e.jsxs("div",{className:"px-4 py-2 border-b border-slate-50 flex items-center gap-2 flex-wrap",children:[e.jsx("span",{className:"text-[10px] text-slate-400 uppercase font-bold",children:"相关:"}),i.relatedSkills.map(h=>e.jsx("button",{onClick:()=>H(h),className:"text-[11px] text-violet-600 hover:text-violet-800 bg-violet-50 px-2 py-0.5 rounded-full transition-colors",children:h},h))]}),e.jsx("div",{className:"flex-1 overflow-y-auto p-4",children:e.jsx("pre",{className:"whitespace-pre-wrap text-xs text-slate-700 font-mono leading-relaxed",children:i.content})})]}):e.jsx("div",{className:"flex items-center justify-center h-full text-slate-400",children:e.jsxs("div",{className:"text-center",children:[e.jsx(at,{size:40,className:"mx-auto mb-3 opacity-30"}),e.jsx("p",{className:"text-sm",children:"选择左侧 Skill 查看详情"})]})})})]}),y&&e.jsx(zr,{onClose:()=>m(!1),onCreated:()=>{m(!1),M(),t==null||t()}})]})},zr=({onClose:t,onCreated:s})=>{const[a,l]=r.useState("ai"),[n,o]=r.useState(""),[c,i]=r.useState(!1),[x,$]=r.useState(""),[d,y]=r.useState(""),[m,S]=r.useState(""),[v,A]=r.useState(!1),[f,k]=r.useState(""),[T,L]=r.useState(!1),U=async()=>{if(n.trim()){i(!0),k("");try{const b=(await te.aiGenerateSkill(n)).reply||"";let R="",M="",H=b;const _=/```(?:json)?\s*\n?\s*(\{[^}]*"name"[^}]*\})\s*\n?\s*```/i,P=b.match(_);if(P)try{const p=JSON.parse(P[1]);R=p.name||"",M=p.description||"",H=b.replace(P[0],"").trim()}catch{}if(!R){const p=b.split(`
|
|
122
122
|
`);for(let w=0;w<Math.min(p.length,5);w++){const E=p[w].trim();if(!(!E||E.startsWith("```"))&&E.startsWith("{")&&E.endsWith("}"))try{const se=JSON.parse(E);if(se.name){R=se.name,M=se.description||"";let h=w+1;for(;h<p.length&&!p[h].trim();)h++;H=p.slice(h).join(`
|
|
123
|
-
`).trim();break}}catch{}}}if(!R){const p=/"name"\s*:\s*"([a-z][a-z0-9-]{1,62}[a-z0-9])"/,w=/"description"\s*:\s*"([^"]+)"/,E=b.match(p),se=b.match(w);E&&(R=E[1]),se&&(M=se[1])}H=H.replace(/```(?:json)?\s*\n?\s*\{[^}]*"name"[^}]*\}\s*\n?\s*```/gi,"").replace(/^\s*\{[^}]*"name"[^}]*\}\s*$/gm,"").trim(),R&&$(R),M&&y(M),S(H||b.trim()),L(!0),l("manual"),ee("请检查并确认生成的内容",{title:"AI 已生成 Skill"})}catch(K){k("AI 生成失败: "+(K.message||""))}finally{i(!1)}}},B=async()=>{var K,b,R;if(!x.trim()||!d.trim()||!m.trim()){k("请填写名称、描述和内容");return}A(!0),k("");try{await te.createSkill({name:x.trim(),description:d.trim(),content:m.trim(),createdBy:T?"user-ai":"manual"}),ee("已保存到知识库",{title:`Skill "${x}" 创建成功`}),s()}catch(M){const H=((R=(b=(K=M.response)==null?void 0:K.data)==null?void 0:b.error)==null?void 0:R.message)||M.message||"";k("创建失败: "+H)}finally{A(!1)}};return e.jsxs(We,{className:"z-40 flex items-center justify-center",children:[e.jsx(We.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(Ye,{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(Ye,{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(Ct,{size:12}),"手动填写"]})]})}),e.jsxs("div",{className:"flex-1 overflow-y-auto px-6 py-4 space-y-4",children:[a==="ai"?e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-slate-700 mb-1.5",children:"描述你想创建的 Skill"}),e.jsx("div",{className:"relative",children:e.jsx("textarea",{value:n,onChange:K=>o(K.target.value),placeholder:"例如:创建一个关于 SwiftUI 动画最佳实践的 Skill,包含常见动画模式、性能优化建议和代码示例...",className:"w-full h-32 px-4 py-3 border border-slate-200 rounded-xl text-sm resize-none focus:outline-none focus:ring-2 focus:ring-violet-300 focus:border-violet-400",disabled:c})})]}),e.jsx("button",{onClick:U,disabled:c||!n.trim(),className:"w-full flex items-center justify-center gap-2 px-4 py-3 bg-violet-600 text-white rounded-xl hover:bg-violet-700 disabled:opacity-50 disabled:cursor-not-allowed transition-colors font-medium",children:c?e.jsxs(e.Fragment,{children:[e.jsx(
|
|
123
|
+
`).trim();break}}catch{}}}if(!R){const p=/"name"\s*:\s*"([a-z][a-z0-9-]{1,62}[a-z0-9])"/,w=/"description"\s*:\s*"([^"]+)"/,E=b.match(p),se=b.match(w);E&&(R=E[1]),se&&(M=se[1])}H=H.replace(/```(?:json)?\s*\n?\s*\{[^}]*"name"[^}]*\}\s*\n?\s*```/gi,"").replace(/^\s*\{[^}]*"name"[^}]*\}\s*$/gm,"").trim(),R&&$(R),M&&y(M),S(H||b.trim()),L(!0),l("manual"),ee("请检查并确认生成的内容",{title:"AI 已生成 Skill"})}catch(K){k("AI 生成失败: "+(K.message||""))}finally{i(!1)}}},B=async()=>{var K,b,R;if(!x.trim()||!d.trim()||!m.trim()){k("请填写名称、描述和内容");return}A(!0),k("");try{await te.createSkill({name:x.trim(),description:d.trim(),content:m.trim(),createdBy:T?"user-ai":"manual"}),ee("已保存到知识库",{title:`Skill "${x}" 创建成功`}),s()}catch(M){const H=((R=(b=(K=M.response)==null?void 0:K.data)==null?void 0:b.error)==null?void 0:R.message)||M.message||"";k("创建失败: "+H)}finally{A(!1)}};return e.jsxs(We,{className:"z-40 flex items-center justify-center",children:[e.jsx(We.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(Ye,{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(Ye,{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(Ct,{size:12}),"手动填写"]})]})}),e.jsxs("div",{className:"flex-1 overflow-y-auto px-6 py-4 space-y-4",children:[a==="ai"?e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-slate-700 mb-1.5",children:"描述你想创建的 Skill"}),e.jsx("div",{className:"relative",children:e.jsx("textarea",{value:n,onChange:K=>o(K.target.value),placeholder:"例如:创建一个关于 SwiftUI 动画最佳实践的 Skill,包含常见动画模式、性能优化建议和代码示例...",className:"w-full h-32 px-4 py-3 border border-slate-200 rounded-xl text-sm resize-none focus:outline-none focus:ring-2 focus:ring-violet-300 focus:border-violet-400",disabled:c})})]}),e.jsx("button",{onClick:U,disabled:c||!n.trim(),className:"w-full flex items-center justify-center gap-2 px-4 py-3 bg-violet-600 text-white rounded-xl hover:bg-violet-700 disabled:opacity-50 disabled:cursor-not-allowed transition-colors font-medium",children:c?e.jsxs(e.Fragment,{children:[e.jsx(ze,{size:16,className:"animate-spin"}),"AI 正在生成..."]}):e.jsxs(e.Fragment,{children:[e.jsx(gs,{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:x,onChange:K=>$(K.target.value),placeholder:"my-custom-skill",className:"w-full px-3 py-2 border border-slate-200 rounded-lg text-sm font-mono focus:outline-none focus:ring-2 focus:ring-violet-300 focus:border-violet-400"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-slate-700 mb-1.5",children:"一句话描述"}),e.jsx("input",{type:"text",value:d,onChange:K=>y(K.target.value),placeholder:"SwiftUI 动画最佳实践指南",className:"w-full px-3 py-2 border border-slate-200 rounded-lg text-sm focus:outline-none focus:ring-2 focus:ring-violet-300 focus:border-violet-400"})]})]}),e.jsxs("div",{children:[e.jsxs("label",{className:"block text-sm font-medium text-slate-700 mb-1.5",children:["Skill 文档内容 ",e.jsx("span",{className:"text-slate-400 text-xs",children:"(Markdown)"})]}),e.jsx("textarea",{value:m,onChange:K=>S(K.target.value),placeholder:`# My Custom Skill
|
|
124
124
|
|
|
125
125
|
## 使用场景
|
|
126
126
|
...
|
|
127
127
|
|
|
128
128
|
## 操作步骤
|
|
129
|
-
...`,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"})]})]}),f&&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(ys,{size:16,className:"shrink-0 mt-0.5"}),e.jsx("span",{children:f})]})]}),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:B,disabled:v||!x.trim()||!d.trim()||!m.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:v?e.jsxs(e.Fragment,{children:[e.jsx(
|
|
129
|
+
...`,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"})]})]}),f&&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(ys,{size:16,className:"shrink-0 mt-0.5"}),e.jsx("span",{children:f})]})]}),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:B,disabled:v||!x.trim()||!d.trim()||!m.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:v?e.jsxs(e.Fragment,{children:[e.jsx(ze,{size:14,className:"animate-spin"}),"保存中..."]}):e.jsxs(e.Fragment,{children:[e.jsx(ut,{size:14}),"创建 Skill"]})})]})]})]})},Ls=["objc-deep-scan","category-scan","project-profile","code-standard","architecture","code-pattern","event-and-data-flow","best-practice","agent-guidelines"],Rr={"code-standard":e.jsx(at,{className:"w-5 h-5"}),"code-pattern":e.jsx(es,{className:"w-5 h-5"}),architecture:e.jsx(gt,{className:"w-5 h-5"}),"best-practice":e.jsx(Ye,{className:"w-5 h-5"}),"event-and-data-flow":e.jsx(st,{className:"w-5 h-5"}),"project-profile":e.jsx(Ks,{className:"w-5 h-5"}),"agent-guidelines":e.jsx(ta,{className:"w-5 h-5"})};function Er(t){return Rr[t]||e.jsx(es,{className:"w-5 h-5"})}const Tr=({task:t})=>{const{status:s,meta:a}=t,l={skeleton:"bg-slate-50 border-slate-200",filling:"bg-blue-50 border-blue-300",completed:"bg-emerald-50 border-emerald-300",failed:"bg-red-50 border-red-300"},n={skeleton:e.jsxs("span",{className:"flex items-center gap-1 text-xs text-slate-400",children:[e.jsx("div",{className:"w-2 h-2 rounded-full bg-slate-300"}),"等待中"]}),filling:e.jsxs("span",{className:"flex items-center gap-1 text-xs text-blue-600",children:[e.jsx(ze,{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(_t,{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:Er(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 o=t.result,c=o.sourceCount??0,i=o.extracted??0;return o.type==="empty"?"✓ 无匹配内容":o.type==="skill"?o.empty?"✓ 无匹配内容":i>0?`✓ ${c} 项特征 · ${i} 条候选`:`✓ ${c} 项特征`:i>0?`✓ ${i} 条候选`:"✓ 无匹配内容"})()}),t.error&&s==="failed"&&e.jsx("span",{className:"ml-2 text-red-500 truncate max-w-[200px] inline-block align-bottom",children:t.error})]})]})]}),e.jsx("div",{className:"flex-shrink-0",children:n[s]})]})]})},Mr=[{key:"round1",label:"资格审查",desc:"过滤误报 · 识别合并",icon:e.jsx(Xs,{className:"w-4 h-4"})},{key:"round2",label:"内容精炼",desc:"AI 改写摘要 · 动态置信度",icon:e.jsx(Yt,{className:"w-4 h-4"})},{key:"round3",label:"去重 & 关系",desc:"语义去重 · 关系推断",icon:e.jsx(Ya,{className:"w-4 h-4"})}],Gr=({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(It,{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:Mr.map(({key:s,label:a,desc:l,icon:n})=>{const o=t[s],c=o.status==="running",i=o.status==="completed",x=o.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":i?"border-emerald-300 bg-emerald-50/60":"border-slate-200 bg-white/40"}`,children:[e.jsx("div",{className:`flex-shrink-0 p-1.5 rounded-md ${c?"bg-purple-200 text-purple-700":i?"bg-emerald-100 text-emerald-600":"bg-slate-100 text-slate-400"}`,children:n}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:`text-sm font-medium ${x?"text-slate-400":"text-slate-800"}`,children:a}),e.jsx("span",{className:"text-xs text-slate-400",children:l})]}),s==="round1"&&i&&e.jsxs("p",{className:"text-xs text-emerald-600 mt-0.5",children:["保留 ",t.round1.kept??"?"," · 合并 ",t.round1.merged??0," · 丢弃 ",t.round1.dropped??0]}),s==="round2"&&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"&&i&&e.jsxs("p",{className:"text-xs text-emerald-600 mt-0.5",children:["已精炼 ",t.round2.refined??"?","/",t.round2.total??"?"," 条"]}),s==="round3"&&i&&e.jsxs("p",{className:"text-xs text-emerald-600 mt-0.5",children:["去重后 ",t.round3.afterDedup??"?"," 条 · ",t.round3.relationsFound??0," 条关系"]})]}),e.jsxs("div",{className:"flex-shrink-0",children:[c&&e.jsx(ze,{className:"w-4 h-4 text-purple-500 animate-spin"}),i&&e.jsx(_t,{className:"w-4 h-4 text-emerald-500"})]})]},s)})})]});function Fs(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 Dr=({session:t,isAllDone:s,reviewState:a,onDismiss:l})=>{const n=r.useRef(!1),[o,c]=r.useState(Date.now());if(r.useEffect(()=>{if(!t||t.status!=="running")return;const v=setInterval(()=>c(Date.now()),1e3);return()=>clearInterval(v)},[t==null?void 0:t.status]),r.useEffect(()=>{if(s&&t&&!n.current){n.current=!0;const v=t.failed>0?`${t.completed}/${t.total} 成功,${t.failed} 失败`:`${t.completed} 个维度全部填充成功`;ee(v,{title:"冷启动完成",type:t.failed>0?"error":"success"})}},[s,t]),r.useEffect(()=>{t||(n.current=!1)},[t==null?void 0:t.id]),!t)return null;const i=t.startedAt?o-t.startedAt:t.elapsedMs??0,x=t.completed+t.failed,$=t.total-x,d=t.elapsedMs??0,y=x>0&&d>0?Math.round(d/x*$):-1,m=t.totalToolCalls??0,S=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:"冷启动进度"}),S&&e.jsx("p",{className:"text-sm text-slate-500 mt-0.5",children:S})]}),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(Nt,{size:14,className:"text-slate-400"}),e.jsxs("span",{children:["已用 ",e.jsx("span",{className:"font-medium text-slate-800",children:Fs(i)})]})]}),t.status==="running"&&$>0&&y>0&&e.jsxs("div",{className:"flex items-center gap-1.5 text-slate-600",children:[e.jsx(Nt,{size:14,className:"text-blue-400"}),e.jsxs("span",{children:["预计剩余 ",e.jsx("span",{className:"font-medium text-blue-600",children:Fs(y)})]})]}),e.jsxs("div",{className:"flex items-center gap-1.5 text-slate-600",children:[e.jsx(ea,{size:14,className:"text-slate-400"}),e.jsxs("span",{children:["工具调用 ",e.jsx("span",{className:"font-medium text-slate-800",children:m})]})]}),e.jsxs("div",{className:"text-slate-400 text-xs",children:[x,"/",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((v,A)=>{var T,L;const f=Ls.indexOf(((T=v.meta)==null?void 0:T.dimId)??v.id),k=Ls.indexOf(((L=A.meta)==null?void 0:L.dimId)??A.id);return(f===-1?999:f)-(k===-1?999:k)}).map(v=>e.jsx(Tr,{task:v},v.id))}),a&&a.activeRound>0&&e.jsx(Gr,{review:a})]})},Pr=()=>{const t=r.useRef(null),s=r.useRef(!0),a=`// AutoSnippet Xcode 模拟器
|
|
130
130
|
// 支持的指令:
|
|
131
131
|
// // as:search <query> - 搜索代码片段
|
|
132
132
|
// // as:create <query> - 创建代码片段
|
|
@@ -137,17 +137,17 @@ ${h.rationale||""}`;X=X.replace(/^\s*\{["']name["']\s*:.*\}\s*\n?/,"").trim(),aw
|
|
|
137
137
|
// // as:create custom form validation utility
|
|
138
138
|
// // as:audit /src/components
|
|
139
139
|
`,l=r.useRef(a),n=r.useRef(0),[o,c]=r.useState({content:a,cursorPos:0,cursorLine:0,cursorCol:0}),[i,x]=r.useState([]),[$,d]=r.useState(""),[y,m]=r.useState(!1),[S,v]=r.useState(!1),[A,f]=r.useState(!0),[k,T]=r.useState(null),[L,U]=r.useState(new Set),[B,K]=r.useState(""),[b,R]=r.useState(null),M=(F,X)=>{const Y=F.split(`
|
|
140
|
-
`);let ie=0,Ne=0,Re=0;for(let fe=0;fe<Y.length;fe++){if(Re+Y[fe].length+1>X){ie=fe,Ne=X-Re;break}Re+=Y[fe].length+1}return{line:ie,col:Ne}},H=(F,X=0)=>{l.current=F,n.current=X;const{line:Y,col:ie}=M(F,X);c({content:F,cursorPos:X,cursorLine:Y,cursorCol:ie}),P(F)},
|
|
140
|
+
`);let ie=0,Ne=0,Re=0;for(let fe=0;fe<Y.length;fe++){if(Re+Y[fe].length+1>X){ie=fe,Ne=X-Re;break}Re+=Y[fe].length+1}return{line:ie,col:Ne}},H=(F,X=0)=>{l.current=F,n.current=X;const{line:Y,col:ie}=M(F,X);c({content:F,cursorPos:X,cursorLine:Y,cursorCol:ie}),P(F)},_=F=>{n.current=F;const{line:X,col:Y}=M(l.current,F);c(ie=>({...ie,cursorPos:F,cursorLine:X,cursorCol:Y}))};r.useEffect(()=>{s.current=!0,P(o.content),p();const F=()=>{t.current&&t.current.clientHeight};return window.addEventListener("resize",F),()=>{s.current=!1,window.removeEventListener("resize",F)}},[]);const P=(F=o.content)=>{const X=F.split(`
|
|
141
141
|
`),Y=[];X.forEach((ie,Ne)=>{const Re=ie.match(/\/\/\s*as:(search|create|audit)\s+(.+)/);Re&&Y.push({line:Ne,type:Re[1],directive:Re[0],query:Re[2].trim()})}),x(Y)},p=async()=>{try{const F=await fetch("/api/v1/commands/files/tree");if(F.ok){const X=await F.json(),Y=X.data||X.tree||X;if(Y&&Y.children&&Y.children.length>0){T(Y),Y.path&&U(new Set([Y.path]));return}}}catch(F){console.error("Failed to load file tree from API:",F)}T(null)},w=async F=>{var X;try{const Y=await fetch(`/api/v1/commands/files/read?path=${encodeURIComponent(F)}`);if(!Y.ok)throw new Error(`Open failed with status ${Y.status}`);const ie=await Y.json(),Ne=ie.data||ie,Re=Ne.content||"";H(Re,0),K(Ne.path||F);const fe=((X=F.split(".").pop())==null?void 0:X.toLowerCase())||"",Q={h:"objc",m:"objc",swift:"swift"};d("")}catch(Y){console.error("Open file failed:",Y),d(`✗ 打开文件失败: ${Y instanceof Error?Y.message:"未知错误"}`)}},E=async()=>{try{await fetch("/api/v1/commands/files/save",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:B,content:o.content})})}catch(F){console.error("Save failed:",F)}},se=()=>{window.confirm("确定要清空编辑器吗?")&&H("",0)},h=async F=>{var X;m(!0),R(i.indexOf(F));try{console.log(`[Execute] 触发 ${F.type} 指令...`,{query:F.query,line:F.line});const Y=await fetch("/api/v1/commands/execute",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({type:F.type,query:F.query,line:F.line,content:o.content,source:"simulator"})}),ie=await Y.json();if(console.log("[Execute] 响应:",ie),!Y.ok)throw new Error(ie.error||"执行失败");if(F.type==="search"&&ie.results&&ie.results.length>0){console.log(`[Execute] 搜索到 ${ie.results.length} 个结果,准备显示 NativeUI 弹窗`);const Ne=ie.results.map((Q,ve)=>`${ve+1}. ${Q.title} (${Q.category||"uncategorized"})`),fe=await(await fetch("/api/v1/commands/execute",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({type:"list",title:`搜索结果: ${F.query}`,options:Ne})})).json();if(fe.success&&((X=fe.result)==null?void 0:X.selectedIndex)>=0){const Q=ie.results[fe.result.selectedIndex];console.log(`[Execute] 用户选择了: ${Q.title}`);const ve=o.content.split(`
|
|
142
142
|
`),Le=F.line+1,we=(Q.body||`// ${Q.title}`).split(`
|
|
143
143
|
`);ve.splice(Le,0,...we);const Fe=ve.join(`
|
|
144
144
|
`),Ee=o.content.split(`
|
|
145
145
|
`).slice(0,Le).join(`
|
|
146
|
-
`).length+1;H(Fe,Ee),console.log(`✓ 已插入代码片段: ${Q.title}`)}else console.log("[Execute] 用户取消了选择")}else F.type==="search"&&console.warn("[Execute] 未找到匹配的搜索结果");ie.success&&console.log(`✓ 指令已执行: ${ie.message}`)}catch(Y){console.error(`✗ 错误: ${Y instanceof Error?Y.message:"执行失败"}`)}finally{m(!1)}},V=(F,X=60)=>{if(F.length<=X)return F;const Y=F.split("/");if(Y.length<=2)return F;const ie=Y[Y.length-1],Ne=Y.slice(0,2).join("/");if(Ne.length+ie.length+5>X){const fe=X-ie.length-5;return`${Ne.substring(0,Math.max(10,fe))}/.../${ie}`}const Re=X-Ne.length-ie.length-5;if(Re>0&&Y.length>3){let Q=Y.slice(2,-1).join("/");return Q.length>Re&&(Q="..."),`${Ne}/${Q}/${ie}`}return`${Ne}/.../${ie}`},me=(F,X=0)=>{if(!F)return null;if(F.type==="folder"){const Y=L.has(F.path);return e.jsxs("div",{children:[e.jsxs("div",{className:"file-tree-item folder-item",onClick:()=>{const ie=new Set(L);Y?ie.delete(F.path):ie.add(F.path),U(ie)},style:{paddingLeft:`${X*16}px`},children:[e.jsx(kt,{size:
|
|
147
|
-
`).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(ts,{size:
|
|
148
|
-
`),M={};let H=0,
|
|
149
|
-
`).trim();return{metadata:M,body:P}},{metadata:y,body:m}=d(t.content||""),S=b=>{const R=[],M=[],H=V=>(b[V]||"").trim(),z=H("title"),P=H("trigger"),p=H("category"),w=H("language").toLowerCase(),E=H("summary_cn")||H("summary"),se=H("summary_en"),h=H("headers");return z||R.push("缺少 title"),(!P||!P.startsWith("@"))&&R.push("trigger 必须以 @ 开头"),(!p||!x.includes(p))&&R.push(`category 必须为以下之一:${x.join(", ")}`),(!w||w!=="swift"&&w!=="objectivec"&&w!=="markdown")&&R.push("language 必须为 swift 或 objectivec"),E||R.push("缺少 summary/summary_cn"),se||M.push("缺少 summary_en"),h?(h.startsWith("[")?h.slice(1,-1).split(",").map(F=>F.trim().replace(/^["']|["']$/g,"")).filter(Boolean):[h.replace(/^["']|["']$/g,"")]).filter(F=>!(F.startsWith("import ")||F.startsWith("#import "))).length>0&&M.push("headers 建议为完整 import 语句(Swift: import X / ObjC: #import <X/Y.h>)"):M.push("缺少 headers(建议填写完整 import 语句)"),{errors:R,warnings:M}},{errors:v,warnings:A}=S(y),f=b=>b?new Date(b).toLocaleString("zh-CN",{year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit"}):"";return e.jsxs(We,{className:"z-40 flex items-center justify-center p-4",children:[e.jsx(We.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 R={rule:{label:"Rule",color:"text-red-700",bg:"bg-red-50",border:"border-red-200",icon:bt},pattern:{label:"Pattern",color:"text-violet-700",bg:"bg-violet-50",border:"border-violet-200",icon:Lt},fact:{label:"Fact",color:"text-cyan-700",bg:"bg-cyan-50",border:"border-cyan-200",icon:at}}[t.kind];if(!R)return null;const M=R.icon;return e.jsxs("span",{className:`text-[10px] font-bold px-2 py-1 rounded uppercase flex items-center gap-1 border ${R.bg} ${R.color} ${R.border}`,children:[e.jsx(M,{size:_.sm}),R.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:"权威分"}),o==="preview"?e.jsx("span",{className:"text-sm text-slate-700",children:((k=t.stats)==null?void 0:k.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:((T=t.stats)==null?void 0:T.authority)??3,onChange:b=>$(parseInt(b.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 ${o==="preview"?"bg-white shadow-sm text-blue-600":"text-slate-400"}`,children:[e.jsx($t,{size:_.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 ${o==="edit"?"bg-white shadow-sm text-blue-600":"text-slate-400"}`,children:[e.jsx(mt,{size:_.sm})," Edit"]})]}),e.jsx("button",{onClick:l,className:"p-2 hover:bg-slate-100 rounded-full",children:e.jsx(Ke,{size:_.lg})})]})]}),e.jsxs("div",{className:"p-6 space-y-4 flex-1 flex flex-col overflow-hidden",children:[o==="edit"&&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:b=>s({...t,name:b.target.value})})]}),(v.length>0||A.length>0)&&e.jsxs("div",{className:"rounded-xl border p-4 text-xs space-y-2 bg-amber-50 border-amber-200 text-amber-800",children:[e.jsx("div",{className:"font-bold",children:"Frontmatter 校验提示"}),v.length>0&&e.jsxs("div",{children:[e.jsx("div",{className:"font-semibold",children:"错误"}),e.jsx("ul",{className:"list-disc pl-5",children:v.map((b,R)=>e.jsx("li",{children:b},R))})]}),A.length>0&&e.jsxs("div",{children:[e.jsx("div",{className:"font-semibold",children:"建议"}),e.jsx("ul",{className:"list-disc pl-5",children:A.map((b,R)=>e.jsx("li",{children:b},R))})]})]}),e.jsx("div",{className:"flex-1 flex flex-col min-h-0",children:o==="edit"?e.jsxs(e.Fragment,{children:[e.jsx("label",{className:"block text-xs font-bold text-slate-400 uppercase mb-2",children:"Markdown Content"}),e.jsx(ls,{value:t.content||"",onChange:b=>s({...t,content:b}),language:"markdown",height:"100%",showLineNumbers:!0})]}):e.jsxs("div",{className:"flex-1 overflow-y-auto space-y-6 scrollbar-light",children:[Object.keys(y).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:"Recipe Metadata"}),e.jsxs("div",{className:"space-y-4",children:[e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-y-4 gap-x-8",children:["title","trigger","language","category","knowledge_type","complexity","scope","difficulty","authority","status","version","updatedAt"].filter(b=>y[b]).map(b=>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:b==="updatedAt"?f(parseInt(y[b])):y[b]})]},b))}),y.tags&&e.jsxs("div",{className:"pt-3 border-t border-slate-200",children:[e.jsx("span",{className:"text-[10px] text-slate-400 font-bold uppercase mb-2 block",children:"Tags"}),e.jsx("div",{className:"flex flex-wrap gap-1.5",children:(()=>{try{const b=JSON.parse(y.tags);return(Array.isArray(b)?b:[y.tags]).map((R,M)=>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:R},M))}catch{return e.jsx("span",{className:"text-sm text-slate-700",children:y.tags})}})()})]}),y.headers&&e.jsxs("div",{className:"pt-3 border-t border-slate-200",children:[e.jsx("span",{className:"text-[10px] text-slate-400 font-bold uppercase mb-2 block",children:"Headers (Import)"}),e.jsx("div",{className:"flex flex-wrap gap-1.5",children:(()=>{try{const b=JSON.parse(y.headers);return(Array.isArray(b)?b:[y.headers]).map((R,M)=>e.jsx("code",{className:"px-2.5 py-1 bg-violet-50 text-violet-700 border border-violet-100 rounded-lg text-xs font-mono",children:R},M))}catch{return e.jsx("code",{className:"text-sm text-slate-700 font-mono",children:y.headers})}})()})]}),(y.summary_cn||y.summary)&&e.jsxs("div",{className:"pt-3 border-t border-slate-200",children:[e.jsx("span",{className:"text-[10px] text-slate-400 font-bold uppercase mb-2 block",children:"Summary (Chinese)"}),e.jsx("p",{className:"text-sm text-slate-700 leading-relaxed",children:y.summary_cn||y.summary})]}),y.summary_en&&e.jsxs("div",{className:"pt-3 border-t border-slate-200",children:[e.jsx("span",{className:"text-[10px] text-slate-400 font-bold uppercase mb-2 block",children:"Summary (English)"}),e.jsx("p",{className:"text-sm text-slate-700 leading-relaxed",children:y.summary_en})]}),(()=>{const b=new Set(["title","trigger","language","category","knowledge_type","complexity","scope","difficulty","authority","status","version","updatedAt","tags","headers","summary","summary_cn","summary_en","id"]),R=Object.entries(y).filter(([M])=>!b.has(M));return R.length===0?null:e.jsx("div",{className:"pt-3 border-t border-slate-200",children:e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-y-3 gap-x-8",children:R.map(([M,H])=>e.jsxs("div",{className:"flex flex-col",children:[e.jsx("span",{className:"text-[10px] text-slate-400 font-bold uppercase mb-1",children:M}),e.jsx("span",{className:"text-sm text-slate-700 break-all font-medium",children:H})]},M))})})})()]})]}),e.jsx("div",{className:"bg-white p-8 rounded-2xl border border-slate-100 shadow-sm min-h-[400px]",children:m?e.jsx(lt,{content:m,showLineNumbers:!0}):e.jsx("div",{className:"flex items-center justify-center h-full text-slate-300 italic",children:"No content body"})}),t.tags&&t.tags.length>0&&!y.tags&&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-3",children:"标签 (Tags)"}),e.jsx("div",{className:"flex flex-wrap gap-1.5",children:t.tags.map((b,R)=>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:b},R))})]}),!!(t.constraints&&((L=t.constraints.guards)!=null&&L.length||(U=t.constraints.boundaries)!=null&&U.length||(B=t.constraints.preconditions)!=null&&B.length||(K=t.constraints.sideEffects)!=null&&K.length))&&e.jsxs("div",{className:"bg-slate-50 border border-slate-200 rounded-2xl p-6 space-y-4",children:[e.jsx("h3",{className:"text-[10px] font-bold text-slate-400 uppercase tracking-widest",children:"约束条件 (Constraints)"}),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((b,R)=>e.jsxs("li",{className:"flex gap-2 items-start",children:[e.jsx("span",{className:`text-xs mt-0.5 ${b.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:b.pattern}),b.message&&e.jsxs("span",{className:"text-xs text-slate-400",children:["— ",b.message]})]},R))})]}),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((b,R)=>e.jsxs("li",{className:"flex gap-2",children:[e.jsx("span",{className:"text-orange-400",children:"●"}),b]},R))})]}),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((b,R)=>e.jsxs("li",{className:"flex gap-2",children:[e.jsx("span",{className:"text-blue-400",children:"◆"}),b]},R))})]}),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((b,R)=>e.jsxs("li",{className:"flex gap-2",children:[e.jsx("span",{className:"text-pink-400",children:"⚡"}),b]},R))})]})]}),t.relations&&Object.entries(t.relations).some(([,b])=>Array.isArray(b)&&b.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:b,label:R,color:M,icon:H})=>{var P;const z=(P=t.relations)==null?void 0:P[b];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 ${M} w-16 shrink-0 pt-0.5`,children:[H," ",R]}),e.jsx("div",{className:"flex flex-wrap gap-1.5",children:z.map((p,w)=>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 p=="string"?p:p.id||p.title||JSON.stringify(p)},w))})]},b)})})]})]})})]}),e.jsxs("div",{className:"p-6 border-t border-slate-100 flex justify-end gap-3",children:[e.jsx("button",{onClick:l,disabled:n,className:"px-4 py-2 text-slate-600 font-medium disabled:opacity-50",children:"Cancel"}),e.jsxs("button",{onClick:a,disabled:n,className:"px-6 py-2 bg-blue-600 text-white rounded-lg font-medium flex items-center gap-2 hover:bg-blue-700 disabled:opacity-60 disabled:cursor-not-allowed",children:[n?e.jsx(_e,{size:_.lg,className:"animate-spin"}):e.jsx(as,{size:_.lg}),n?"保存中...":"Save Changes"]})]})]})]})},Or=({setShowCreateModal:t,createPath:s,setCreatePath:a,handleCreateFromPath:l,handleCreateFromClipboard:n,isExtracting:o})=>e.jsxs(We,{className:"z-40 flex items-center justify-center p-4",children:[e.jsx(We.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(ut,{size:_.xl,className:"text-blue-600"})," New Recipe"]}),e.jsx("button",{onClick:()=>t(!1),className:"p-2 hover:bg-white rounded-full transition-colors",children:e.jsx(Ke,{size:_.lg})})]}),e.jsxs("div",{className:"p-8 space-y-6",children:[e.jsxs("div",{className:"space-y-3",children:[e.jsxs("label",{className:"flex items-center gap-2 text-xs font-bold text-slate-400 uppercase tracking-widest",children:[e.jsx(Ys,{size:_.sm})," Import from Project Path"]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("input",{className:"flex-1 p-3 bg-slate-100 border-none rounded-xl text-sm outline-none focus:ring-2 focus:ring-blue-500",placeholder:"e.g. Sources/MyModule/Auth.swift",value:s,onChange:c=>a(c.target.value)}),e.jsx("button",{onClick:l,disabled:!s||o,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(el,{size:_.sm})," Import from Clipboard"]}),e.jsxs("button",{onClick:()=>n(),disabled:o,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(st,{size:_.lg})," Use Copied Code"]})]})]}),o&&e.jsxs("div",{className:"bg-blue-600 text-white p-4 flex items-center justify-center gap-3 animate-pulse",children:[e.jsx(Ut,{size:_.lg,className:"animate-spin"}),e.jsx("span",{className:"font-bold text-sm",children:"AI is thinking..."})]})]})]});function Br(t){const s=t.replace(/^---[\s\S]*?---\s*\n?/,"").trim(),a=s.match(/```[\w]*\n([\s\S]*?)```/);return a&&a[1]?a[1].trim():s.slice(0,8e3)}const Ur=({searchQ:t,insertPath:s,onClose:a})=>{const[l,n]=r.useState([]),[o,c]=r.useState(!0),[i,x]=r.useState(null),$=r.useRef(!0),d=r.useRef(null);r.useEffect(()=>($.current=!0,d.current=new AbortController,te.searchRecipesForModal(t||"",d.current.signal).then(m=>{$.current&&n(m.results||[])}).catch(m=>{m.name!=="AbortError"&&$.current&&n([])}).finally(()=>{$.current&&c(!1)}),()=>{$.current=!1,d.current&&d.current.abort()}),[t]);const y=async m=>{x(m.name);try{const S=Br(m.content);await te.insertAtSearchMark({path:s,content:S}),$.current&&(alert("✅ 已插入到 "+s),a())}catch{$.current&&alert("❌ 插入失败")}finally{$.current&&x(null)}};return e.jsxs(We,{className:"z-40 flex items-center justify-center p-4",children:[e.jsx(We.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(pt,{size:_.xl,className:"text-blue-600"})," as:search — 选择并插入"]}),e.jsx("button",{onClick:a,className:"p-2 hover:bg-white rounded-full transition-colors",children:e.jsx(Ke,{size:_.lg})})]}),e.jsxs("div",{className:"p-4 text-sm text-slate-500 border-b border-slate-100",children:["关键词: ",t||"(全部)"," · 插入到: ",s]}),e.jsx("div",{className:"flex-1 overflow-y-auto p-4",children:o?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(m=>e.jsx("li",{children:e.jsxs("button",{type:"button",onClick:()=>y(m),disabled:i!==null,className:"w-full flex items-center justify-between gap-3 p-4 rounded-xl border border-slate-200 hover:border-blue-300 hover:bg-blue-50/50 transition-all text-left disabled:opacity-50",children:[e.jsxs("div",{className:"flex-1 flex flex-col gap-1",children:[e.jsx("span",{className:"font-medium text-slate-800 truncate",children:m.name}),(m.qualityScore!==void 0||m.recommendReason)&&e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[m.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:["🤖 质量: ",(m.qualityScore*100).toFixed(0),"%"]}),m.recommendReason&&e.jsx("span",{className:"text-xs text-slate-600 italic truncate max-w-xs",children:m.recommendReason})]})]}),i===m.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(Qs,{size:_.md})," 插入"]})]})},m.name))})})]})]})},us=[{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:""}],Hr=({onClose:t,onSaved:s})=>{const[a,l]=r.useState(!0),[n,o]=r.useState(!1),[c,i]=r.useState(!1),[x,$]=r.useState("google"),[d,y]=r.useState("gemini-2.0-flash"),[m,S]=r.useState(""),[v,A]=r.useState(""),[f,k]=r.useState(!1),[T,L]=r.useState({}),[U,B]=r.useState(!1);r.useEffect(()=>{K()},[]);const K=async()=>{l(!0);try{const p=await te.getLlmEnvConfig();i(p.hasEnvFile);const w=p.vars||{};w.ASD_AI_PROVIDER&&$(w.ASD_AI_PROVIDER),w.ASD_AI_MODEL&&y(w.ASD_AI_MODEL),w.ASD_AI_PROXY&&A(w.ASD_AI_PROXY),L(w)}catch{}finally{l(!1)}},b=us.find(p=>p.id===x),R=(b==null?void 0:b.keyEnv)||"",M=R?!!T[R]:!0,H=p=>{$(p);const w=us.find(E=>E.id===p);w&&y(w.defaultModel),S("")},z=async()=>{if(x){if(R&&!M&&!m.trim()){alert("请填写 API Key");return}o(!0),B(!1);try{await te.saveLlmEnvConfig({provider:x,model:d||void 0,apiKey:m.trim()||void 0,proxy:v.trim()||void 0}),B(!0),setTimeout(()=>{s(),t()},800)}catch(p){alert((p==null?void 0:p.message)||"保存失败")}finally{o(!1)}}},P=p=>!p||p.length<10?p?"••••••":"":`${p.slice(0,6)}••••${p.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:p=>p.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:_.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(_e,{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(Ot,{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:us.map(p=>e.jsx("button",{type:"button",onClick:()=>H(p.id),className:`px-3 py-2 rounded-lg text-sm font-medium border transition-all ${x===p.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:p.label},p.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:d,onChange:p=>y(p.target.value),placeholder:(b==null?void 0:b.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"})]}),R&&e.jsxs("div",{children:[e.jsxs("label",{className:"block text-sm font-medium text-slate-700 mb-1.5",children:["API Key",M&&e.jsxs("span",{className:"ml-2 text-xs text-green-600 font-normal",children:["(已配置: ",P(T[R]),")"]})]}),e.jsxs("div",{className:"relative",children:[e.jsx("input",{type:f?"text":"password",value:m,onChange:p=>S(p.target.value),placeholder:M?"留空保持当前 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:()=>k(p=>!p),className:"absolute right-2 top-1/2 -translate-y-1/2 p-1 text-slate-400 hover:text-slate-600",children:f?e.jsx(tl,{size:16}):e.jsx($t,{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:v,onChange:p=>A(p.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:z,disabled:n||a||U,className:`flex items-center gap-2 px-5 py-2 rounded-lg text-sm font-medium transition-all ${U?"bg-green-500 text-white":"bg-blue-600 text-white hover:bg-blue-700 shadow-sm"} disabled:opacity-60`,children:[n?e.jsx(_e,{size:16,className:"animate-spin"}):U?e.jsx(Zs,{size:16}):e.jsx(as,{size:16}),U?"已保存":"保存到 .env"]})]})]})})};class Wr extends Bt.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 tt(t){return t?typeof t=="string"?t:typeof t=="object"?Object.entries(t).map(([a,l])=>`${a}: ${Array.isArray(l)?l.join("; "):l}`).join(`
|
|
150
|
-
`):String(t):""}const Kr=()=>{var Ue,ze;const t=Nl(),s=wl((Ue=t.user)==null?void 0:Ue.role),a=kl(),l=()=>{const N=window.location.pathname.replace(/^\//,"").split("/")[0]||"";return ml.includes(N)?N:"help"},[n,o]=r.useState(null),[c,i]=r.useState(l()),[x,$]=r.useState(!1),[d,y]=r.useState(""),[m,S]=r.useState(!0),[v,A]=r.useState(null),[f,k]=r.useState([]),[T,L]=r.useState(null),[U,B]=r.useState(!1),[K,b]=r.useState({current:0,total:0,status:""}),[R,M]=r.useState([]),[H,z]=r.useState([]),[P,p]=r.useState(null),[w,E]=r.useState("All"),[se,h]=r.useState(1),[V,me]=r.useState(12),[F,X]=r.useState(!1),[Y,ie]=r.useState(""),[Ne,Re]=r.useState(!1),[fe,Q]=r.useState(null),[ve,Le]=r.useState(null),[Ge,we]=r.useState(!1),[Fe,Ee]=r.useState(!0),[ke,De]=r.useState(!1),[Ze,Ve]=r.useState(0),g=r.useRef(null);r.useEffect(()=>{h(1)},[d,w]);const J=()=>{g.current&&g.current.abort()};r.useEffect(()=>{let N=!1;const D=async()=>{var O,pe,le;try{const xe=await te.getSignalStatus();if(!N){const ce=((O=xe==null?void 0:xe.suggestions)==null?void 0:O.length)||0,ge=((le=(pe=xe==null?void 0:xe.snapshot)==null?void 0:pe.lastResult)==null?void 0:le.newSuggestions)||0;Ve(ce||ge)}}catch{}};D();const W=setInterval(D,300*1e3);return()=>{N=!0,clearInterval(W)}},[]),r.useEffect(()=>{a.isAllDone&&G()},[a.isAllDone]);const Z=(N,D)=>{i(N);const W=D!=null&&D.preserveSearch&&window.location.search?window.location.search:"";window.history.pushState({},document.title,`/${N}${W}`)},u=N=>{A(N),i("recipes");const D=new URLSearchParams(window.location.search);D.set("edit",encodeURIComponent(N.name)),window.history.pushState({},document.title,`/recipes?${D.toString()}`)},I=()=>{A(null),window.history.replaceState({},document.title,"/recipes")};r.useEffect(()=>{d===""&&Q(null)},[d]),r.useEffect(()=>{i(l())},[]),r.useEffect(()=>{if(!n)return;const N=window.location.pathname.replace(/^\//,"").split("/")[0],W=new URLSearchParams(window.location.search).get("edit");if(N==="recipes"&&W&&n.recipes)try{const O=decodeURIComponent(W),pe=n.recipes.find(le=>le.name===O);pe&&!v&&(i("recipes"),u(pe))}catch{}},[n]),r.useEffect(()=>{G(),C(),q();const N=()=>{i(l())};window.addEventListener("popstate",N);const D=new URLSearchParams(window.location.search),W=D.get("action"),O=D.get("path"),pe=D.get("q")||"";return W==="search"&&O?Le({q:pe,path:O}):W==="create"&&O&&(ie(O),X(!0),D.get("autoScan")==="1"&&setTimeout(()=>oe(O),500)),()=>{window.removeEventListener("popstate",N)}},[]);const G=async()=>{S(!0);try{const N=await te.fetchData();if(N.candidates){const D={};Object.entries(N.candidates).forEach(([W,O])=>{const pe=O.items.map(le=>{const xe=le.summary_cn||le.summary||"",ce=le.summary_en&&le.summary_en!==xe?le.summary_en:void 0,ge=tt(le.usageGuide_cn||le.usageGuide||""),$e=le.usageGuide_en&&tt(le.usageGuide_en)!==ge?tt(le.usageGuide_en):void 0;return{...le,summary_cn:xe,summary_en:ce,usageGuide_cn:ge,usageGuide_en:$e}});D[W]={...O,items:pe}}),N.candidates=D}o(N)}catch(N){ee((N==null?void 0:N.message)||"无法加载项目数据",{title:"加载失败",type:"error"})}finally{S(!1)}},C=async()=>{try{const N=await te.fetchTargets();k(N)}catch(N){console.warn("删除候选残留失败:",N==null?void 0:N.message)}},q=async()=>{try{const N=await te.getLlmEnvConfig();Ee(N.llmReady)}catch{}},ae=async()=>{try{await te.syncToXcode(),ee("Recipes 已同步到 Xcode CodeSnippets 目录",{title:"Xcode 同步成功"})}catch{ee("请检查 Xcode 是否已安装并重试",{title:"同步失败",type:"error"})}},ue=async()=>{try{await te.refreshProject(),C(),ee("Target 列表与文件树已更新",{title:"项目结构已刷新"})}catch{ee("请确认项目路径有效后重试",{title:"刷新失败",type:"error"})}},oe=async N=>{var D;Re(!0);try{const W=await te.extractFromPath(N);z(W.result.map(O=>{const pe=O.summary_cn||O.summary||"",le=O.summary_en&&O.summary_en!==pe?O.summary_en:void 0,xe=tt(O.usageGuide_cn||O.usageGuide||""),ce=O.usageGuide_en&&tt(O.usageGuide_en)!==xe?tt(O.usageGuide_en):void 0;return{...O,summary_cn:pe,summary_en:le,usageGuide_cn:xe,usageGuide_en:ce,tags:Array.isArray(O.tags)?O.tags:[],mode:"full",lang:"cn",includeHeaders:!0,category:O.category||"Utility",summary:pe,usageGuide:xe}})),Z("spm",{preserveSearch:!0}),X(!1),G(),((D=W.result)==null?void 0:D.length)>0&&ee("提取结果已进入候选池,请在 Candidates 页审核",{title:"提取完成"})}catch{ee("Extraction failed",{type:"error"})}finally{Re(!1)}},Ie=async()=>{var N;if(Y){Re(!0);try{const D=await te.extractFromPath(Y);z(D.result.map(W=>{const O=W.summary_cn||W.summary||"",pe=W.summary_en&&W.summary_en!==O?W.summary_en:void 0,le=tt(W.usageGuide_cn||W.usageGuide||""),xe=W.usageGuide_en&&tt(W.usageGuide_en)!==le?tt(W.usageGuide_en):void 0;return{...W,summary_cn:O,summary_en:pe,usageGuide_cn:le,usageGuide_en:xe,tags:Array.isArray(W.tags)?W.tags:[],mode:"full",lang:"cn",includeHeaders:!0,category:W.category||"Utility",summary:O,usageGuide:le}})),Z("spm"),X(!1),G(),((N=D.result)==null?void 0:N.length)>0?ee(D.isMarked?"精准锁定标记代码,已加入候选池":"提取结果已加入候选池",{title:"提取完成"}):D.isMarked||ee("未找到 ASD 标记,AI 将分析完整文件",{title:"提取中",type:"info"})}catch{ee("Extraction failed",{type:"error"})}finally{Re(!1)}}},re=async N=>{var D,W,O,pe;try{const le=await navigator.clipboard.readText();if(!le)return ee("请先复制代码到剪贴板",{title:"剪贴板为空",type:"info"});ee("已收到代码,AI 正在识别可复用模式...",{title:"剪贴板分析中",type:"info"}),Re(!0);const xe=N||Y;try{const ce=await te.extractFromText(le,xe||void 0),ge=ce.summary_cn||ce.summary||"",$e=ce.summary_en&&ce.summary_en!==ge?ce.summary_en:void 0,Oe=tt(ce.usageGuide_cn||ce.usageGuide||""),rt=ce.usageGuide_en&&tt(ce.usageGuide_en)!==Oe?tt(ce.usageGuide_en):void 0,qe=ce._multipleCount;z([{...ce,summary_cn:ge,summary_en:$e,usageGuide_cn:Oe,usageGuide_en:rt,tags:Array.isArray(ce.tags)?ce.tags:[],mode:"full",lang:"cn",includeHeaders:!0,category:ce.category||"Utility",summary:ge,usageGuide:Oe}]),Z("spm",{preserveSearch:!0}),X(!1),G(),ee(qe?`已识别 ${qe} 条 Recipe,请在候选池审核`:"提取结果已加入候选池",{title:"AI 识别完成"})}catch(ce){const ge=((W=(D=ce.response)==null?void 0:D.data)==null?void 0:W.aiError)===!0,$e=((pe=(O=ce.response)==null?void 0:O.data)==null?void 0:pe.error)||ce.message;ge?ee($e,{title:"AI 识别失败",type:"error"}):ee($e,{title:"操作失败",type:"error"})}}catch{ee("浏览器可能未授权剪贴板访问",{title:"剪贴板读取失败",type:"error"})}finally{Re(!1)}},ye=[{status:"正在读取 Target 源文件...",percent:15},{status:"正在发送到 AI 分析...",percent:35},{status:"正在识别可复用代码片段...",percent:55},{status:"正在生成摘要与使用指南...",percent:75},{status:"即将完成...",percent:92}],Se=async N=>{var le,xe,ce,ge;if(U)return;g.current&&g.current.abort();const D=new AbortController;g.current=D,L(N.name),B(!0),z([]),p(null),M([]),b({current:0,total:100,status:"正在获取待扫描文件列表..."});const W=4e3;let O=0;const pe=setInterval(()=>{O=Math.min(O+1,ye.length);const $e=ye[O-1];$e&&b(Oe=>({...Oe,current:$e.percent,status:$e.status}))},W);try{const $e=await te.getTargetFiles(N,D.signal),Oe=$e.files||[],rt=$e.count??Oe.length;M(Oe),b(nt=>({...nt,current:10,status:`正在分析 ${rt} 个文件...`}));const qe=await te.scanTarget(N,D.signal);clearInterval(pe),b({current:100,total:100,status:"扫描完成"});const Je=qe.recipes||[],dt=(le=qe.scannedFiles)!=null&&le.length?qe.scannedFiles:Oe;if(Je.length>0||dt.length>0){const nt=typeof N=="string"?N:(N==null?void 0:N.name)||"unknown",ua=Je.map(ot=>({...ot,mode:"full",lang:"cn",includeHeaders:ot.includeHeaders!==!1,category:ot.category||"Utility",summary:tt(ot.summary_cn||ot.summary||""),usageGuide:tt(ot.usageGuide_cn||ot.usageGuide||""),tags:Array.isArray(ot.tags)?ot.tags:[],candidateTargetName:nt,scanMode:"target"}));z(ua),M(dt),G(),Je.length>0?ee(`发现 ${Je.length} 条可复用代码模式,请在右侧审核`,{title:"Target 扫描完成"}):qe.message?ee(qe.message,{title:"AI 扫描未返回结果",type:"error"}):ee("该 Target 中未找到可复用的代码片段",{title:"扫描完成",type:"info"})}else ee("请确认 Target 包含有效的源代码文件",{title:"扫描失败",type:"error"})}catch($e){if(clearInterval(pe),St.isCancel($e))return;const Oe=$e.code==="ECONNABORTED"||((xe=$e.message)==null?void 0:xe.includes("timeout")),rt=Oe?"扫描超时,请尝试减少 Target 文件数量":((ge=(ce=$e.response)==null?void 0:ce.data)==null?void 0:ge.error)||$e.message;ee(rt,{title:Oe?"扫描超时":"扫描出错",type:"error"})}finally{g.current===D&&(B(!1),b({current:0,total:0,status:""}),g.current=null)}},Be=async()=>{var D,W,O,pe,le,xe;if(U)return;g.current&&g.current.abort();const N=new AbortController;g.current=N,Z("candidates"),B(!0),z([]),p(null),M([]),b({current:0,total:100,status:"正在收集项目结构..."}),a.resetSession();try{const ce=await te.bootstrap(N.signal);b({current:100,total:100,status:"骨架已创建,正在后台填充..."}),ce.bootstrapSession&&a.initFromApiResponse(ce.bootstrapSession),G();const ge=ce.report||{},$e=((D=ce.targets)==null?void 0:D.length)||0,Oe=((W=ge.totals)==null?void 0:W.files)||0,rt=((O=ge.totals)==null?void 0:O.graphEdges)||0,qe=ce.guardSummary,Je=qe?`, Guard: ${qe.totalViolations} 项违规`:"";ee(`冷启动骨架已创建: ${$e} 个 Target, ${Oe} 个文件, ${rt} 条依赖${Je},正在后台逐维度填充...`)}catch(ce){if(St.isCancel(ce))return;const $e=ce.code==="ECONNABORTED"||((pe=ce.message)==null?void 0:pe.includes("timeout"))?"冷启动超时,请检查项目文件数量":((xe=(le=ce.response)==null?void 0:le.data)==null?void 0:xe.error)||ce.message;ee($e,{type:"error"})}finally{g.current===N&&(B(!1),b({current:0,total:0,status:""}),g.current=null)}},Ae=async()=>{var pe,le,xe,ce;if(U)return;g.current&&g.current.abort();const N=new AbortController;g.current=N,Z("spm"),L("__project__"),B(!0),z([]),p(null),M([]),b({current:0,total:100,status:"正在收集所有 Target 文件..."});const D=[{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 W=0;const O=setInterval(()=>{W=Math.min(W+1,D.length);const ge=D[W-1];ge&&b($e=>({...$e,current:ge.percent,status:ge.status}))},15e3);try{const ge=await te.scanProject(N.signal);clearInterval(O),b({current:100,total:100,status:ge.partial?"扫描部分完成(超时)":"全项目扫描完成"});const $e=ge.recipes||[],Oe=ge.scannedFiles||[];if($e.length>0||Oe.length>0){const rt=$e.map(nt=>({...nt,mode:"full",lang:"cn",includeHeaders:nt.includeHeaders!==!1,category:nt.category||"Utility",summary:nt.summary_cn||nt.summary||"",usageGuide:nt.usageGuide_cn||nt.usageGuide||"",candidateTargetName:"__project__",scanMode:"project"}));z(rt),M(Oe),p(ge.guardAudit||null),G();const qe=(pe=ge.guardAudit)==null?void 0:pe.summary,Je=qe?`, Guard: ${qe.totalViolations} 处违反`:"",dt=ge.partial?"(部分结果,AI 超时)":"";ee(`全项目扫描完成: ${$e.length} 条候选${Je}${dt}`)}else ee("全项目扫描完成,未发现可提取内容")}catch(ge){if(clearInterval(O),St.isCancel(ge))return;const Oe=ge.code==="ECONNABORTED"||((le=ge.message)==null?void 0:le.includes("timeout"))?"扫描超时,请尝试减少项目文件数量或分 Target 扫描":((ce=(xe=ge.response)==null?void 0:xe.data)==null?void 0:ce.error)||ge.message;ee(Oe,{type:"error"})}finally{g.current===N&&(B(!1),b({current:0,total:0,status:""}),g.current=null)}},He=(N,D)=>{const W=[...H],O={...W[N],...D};!O.summary_cn&&O.summary&&!O.summary_en&&(O.summary_cn=O.summary),!O.usageGuide_cn&&O.usageGuide&&!O.usageGuide_en&&(O.usageGuide_cn=O.usageGuide),D.lang!==void 0&&D.summary===void 0&&(O.summary=D.lang==="cn"?O.summary_cn||O.summary:O.summary_en||O.summary),D.lang!==void 0&&D.usageGuide===void 0&&(O.usageGuide=D.lang==="cn"?O.usageGuide_cn||O.usageGuide:O.usageGuide_en||O.usageGuide),D.summary!==void 0&&D.lang===void 0&&(O.lang==="cn"?O.summary_cn=D.summary:O.summary_en=D.summary),D.usageGuide!==void 0&&D.lang===void 0&&(O.lang==="cn"?O.usageGuide_cn=D.usageGuide:O.usageGuide_en=D.usageGuide),W[N]=O,z(W)},Qe=async N=>{if(!Ge){we(!0);try{const D=(N.trigger||"").split(/[,,\s]+/).map(Je=>Je.trim()).filter(Boolean);if(D.length===0){ee("请输入 Trigger",{type:"error"}),we(!1);return}const W=crypto.randomUUID().toUpperCase(),O=`${(N.title||"Untitled").replace(/\s+/g,"-")}.md`,pe=N.summary_cn||N.summary||"",le=N.summary_en||N.summary||"",xe=N.usageGuide_cn||N.usageGuide||"",ce=N.usageGuide_en||N.usageGuide||"";let ge=`---
|
|
146
|
+
`).length+1;H(Fe,Ee),console.log(`✓ 已插入代码片段: ${Q.title}`)}else console.log("[Execute] 用户取消了选择")}else F.type==="search"&&console.warn("[Execute] 未找到匹配的搜索结果");ie.success&&console.log(`✓ 指令已执行: ${ie.message}`)}catch(Y){console.error(`✗ 错误: ${Y instanceof Error?Y.message:"执行失败"}`)}finally{m(!1)}},V=(F,X=60)=>{if(F.length<=X)return F;const Y=F.split("/");if(Y.length<=2)return F;const ie=Y[Y.length-1],Ne=Y.slice(0,2).join("/");if(Ne.length+ie.length+5>X){const fe=X-ie.length-5;return`${Ne.substring(0,Math.max(10,fe))}/.../${ie}`}const Re=X-Ne.length-ie.length-5;if(Re>0&&Y.length>3){let Q=Y.slice(2,-1).join("/");return Q.length>Re&&(Q="..."),`${Ne}/${Q}/${ie}`}return`${Ne}/.../${ie}`},me=(F,X=0)=>{if(!F)return null;if(F.type==="folder"){const Y=L.has(F.path);return e.jsxs("div",{children:[e.jsxs("div",{className:"file-tree-item folder-item",onClick:()=>{const ie=new Set(L);Y?ie.delete(F.path):ie.add(F.path),U(ie)},style:{paddingLeft:`${X*16}px`},children:[e.jsx(kt,{size:z.sm,className:`folder-toggle ${Y?"expanded":""}`}),e.jsx(Ss,{size:z.sm,className:"folder-icon"}),e.jsx("span",{className:"file-name",children:F.name})]}),Y&&F.children&&e.jsx("div",{children:F.children.map(ie=>me(ie,X+1))})]},F.path)}else return e.jsxs("div",{className:`file-tree-item file-item ${B===F.path?"active":""}`,onClick:()=>w(F.path),style:{paddingLeft:`${X*16}px`},children:[e.jsx(Cs,{size:z.sm,className:"file-icon"}),e.jsx("span",{className:"file-name",children:F.name})]},F.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:()=>f(!A),title:"切换侧栏",children:e.jsx(Xa,{size:z.md})}),e.jsxs("div",{className:"file-info",title:B,children:[e.jsx(ss,{size:z.sm}),e.jsx("span",{className:"file-name",children:V(B||"untitled.js",80)})]})]}),e.jsxs("div",{className:"toolbar-right",children:[e.jsx("button",{className:"toolbar-btn",onClick:E,title:"保存",children:e.jsx(as,{size:z.md})}),e.jsx("button",{className:"toolbar-btn",onClick:se,title:"清空",children:e.jsx(ht,{size:z.md})}),e.jsx("button",{className:"toolbar-btn",title:"更多选项",children:e.jsx(Za,{size:z.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(Ss,{size:z.md}),e.jsx("h3",{children:"文件浏览"})]}),e.jsx("div",{className:"file-tree",children:k?me(k):e.jsxs("div",{className:"empty-state",style:{padding:"16px 8px"},children:[e.jsx(Cs,{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(ls,{value:o.content,onChange:F=>H(F,n.current),onCursorChange:_,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 ",o.cursorLine+1,", Col ",o.cursorCol+1]}),e.jsx("span",{children:"|"}),e.jsxs("span",{children:[o.content.length," characters"]}),e.jsx("span",{children:"|"}),e.jsxs("span",{children:[o.content.split(`
|
|
147
|
+
`).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(ts,{size:z.md}),e.jsx("h3",{children:"检测到的指令"}),e.jsx("span",{className:"count",children:i.length})]}),i.length===0?e.jsxs("div",{className:"empty-state",children:[e.jsx(Ye,{size:32}),e.jsx("p",{children:"暂无指令"}),e.jsx("small",{children:"在代码中添加 // as:search 来创建指令"})]}):e.jsx("div",{className:"directives-list",children:i.map((F,X)=>e.jsxs("div",{className:`directive-card ${F.type} ${b===X?"active":""}`,onClick:()=>R(X),children:[e.jsxs("div",{className:"directive-header",children:[e.jsx("div",{className:"type-badge",children:F.type.toUpperCase()}),e.jsxs("div",{className:"line-badge",children:["L",F.line+1]})]}),e.jsx("div",{className:"directive-query",children:F.query}),e.jsx("button",{className:"execute-btn",onClick:Y=>{Y.stopPropagation(),h(F)},disabled:y,children:y&&b===X?e.jsxs(e.Fragment,{children:[e.jsx(ze,{size:z.xs,className:"spin"}),"执行中..."]}):e.jsxs(e.Fragment,{children:[e.jsx(Qa,{size:z.xs}),"执行"]})})]},X))})]}),$&&e.jsxs("div",{className:"result-section result",children:[e.jsxs("div",{className:"section-header",children:[e.jsx(pt,{size:z.md}),e.jsx("h3",{children:"执行结果"})]}),e.jsx("div",{className:"result-content",children:e.jsx("pre",{children:$})})]})]})]}),S&&e.jsx("div",{className:"result-modal-backdrop",onClick:()=>v(!1),children:e.jsxs("div",{className:"result-modal",onClick:F=>F.stopPropagation(),children:[e.jsxs("div",{className:"result-modal-header",children:[e.jsx("h2",{children:"执行结果"}),e.jsx("button",{className:"result-modal-close",onClick:()=>v(!1),children:"✕"})]}),e.jsx("div",{className:"result-modal-content",children:e.jsx("pre",{children:$})}),e.jsxs("div",{className:"result-modal-footer",children:[e.jsx("button",{className:"result-modal-btn",onClick:()=>{navigator.clipboard.writeText($)},children:"复制"}),e.jsx("button",{className:"result-modal-btn",onClick:()=>v(!1),children:"关闭"})]})]})})]})},Lr={authority:0,guardUsageCount:0,humanUsageCount:0,aiUsageCount:0,lastUsedAt:null,authorityScore:0},Fr=({editingRecipe:t,setEditingRecipe:s,handleSaveRecipe:a,closeRecipeEdit:l,isSavingRecipe:n=!1})=>{var k,T,L,U,B,K;const[o,c]=r.useState("preview"),i=r.useRef(!0);r.useEffect(()=>()=>{i.current=!1},[]);const x=["View","Service","Tool","Model","Network","Storage","UI","Utility"],$=async b=>{try{if(await te.setRecipeAuthority(t.name,b),i.current){const R=t.stats?{...t.stats,authority:b}:{...Lr,authority:b};s({...t,stats:R})}}catch(R){console.warn("设置权威分失败:",R==null?void 0:R.message)}},d=b=>{const R=b.split(`
|
|
148
|
+
`),M={};let H=0,_=!1;for(let p=0;p<R.length;p++){const w=R[p].trim();if(w==="---"){if(!_&&p===0){_=!0;continue}else if(_){_=!1,H=p+1;break}}const E=w.match(/^([a-zA-Z0-9_-]+):\s*(.*)/);if(E)M[E[1]]=E[2],_||(H=p+1);else if(!_&&w!==""){H=p;break}}const P=R.slice(H).join(`
|
|
149
|
+
`).trim();return{metadata:M,body:P}},{metadata:y,body:m}=d(t.content||""),S=b=>{const R=[],M=[],H=V=>(b[V]||"").trim(),_=H("title"),P=H("trigger"),p=H("category"),w=H("language").toLowerCase(),E=H("summary_cn")||H("summary"),se=H("summary_en"),h=H("headers");return _||R.push("缺少 title"),(!P||!P.startsWith("@"))&&R.push("trigger 必须以 @ 开头"),(!p||!x.includes(p))&&R.push(`category 必须为以下之一:${x.join(", ")}`),(!w||w!=="swift"&&w!=="objectivec"&&w!=="markdown")&&R.push("language 必须为 swift 或 objectivec"),E||R.push("缺少 summary/summary_cn"),se||M.push("缺少 summary_en"),h?(h.startsWith("[")?h.slice(1,-1).split(",").map(F=>F.trim().replace(/^["']|["']$/g,"")).filter(Boolean):[h.replace(/^["']|["']$/g,"")]).filter(F=>!(F.startsWith("import ")||F.startsWith("#import "))).length>0&&M.push("headers 建议为完整 import 语句(Swift: import X / ObjC: #import <X/Y.h>)"):M.push("缺少 headers(建议填写完整 import 语句)"),{errors:R,warnings:M}},{errors:v,warnings:A}=S(y),f=b=>b?new Date(b).toLocaleString("zh-CN",{year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit"}):"";return e.jsxs(We,{className:"z-40 flex items-center justify-center p-4",children:[e.jsx(We.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 R={rule:{label:"Rule",color:"text-red-700",bg:"bg-red-50",border:"border-red-200",icon:bt},pattern:{label:"Pattern",color:"text-violet-700",bg:"bg-violet-50",border:"border-violet-200",icon:Lt},fact:{label:"Fact",color:"text-cyan-700",bg:"bg-cyan-50",border:"border-cyan-200",icon:at}}[t.kind];if(!R)return null;const M=R.icon;return e.jsxs("span",{className:`text-[10px] font-bold px-2 py-1 rounded uppercase flex items-center gap-1 border ${R.bg} ${R.color} ${R.border}`,children:[e.jsx(M,{size:z.sm}),R.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:"权威分"}),o==="preview"?e.jsx("span",{className:"text-sm text-slate-700",children:((k=t.stats)==null?void 0:k.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:((T=t.stats)==null?void 0:T.authority)??3,onChange:b=>$(parseInt(b.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 ${o==="preview"?"bg-white shadow-sm text-blue-600":"text-slate-400"}`,children:[e.jsx($t,{size:z.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 ${o==="edit"?"bg-white shadow-sm text-blue-600":"text-slate-400"}`,children:[e.jsx(mt,{size:z.sm})," Edit"]})]}),e.jsx("button",{onClick:l,className:"p-2 hover:bg-slate-100 rounded-full",children:e.jsx(Ke,{size:z.lg})})]})]}),e.jsxs("div",{className:"p-6 space-y-4 flex-1 flex flex-col overflow-hidden",children:[o==="edit"&&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:b=>s({...t,name:b.target.value})})]}),(v.length>0||A.length>0)&&e.jsxs("div",{className:"rounded-xl border p-4 text-xs space-y-2 bg-amber-50 border-amber-200 text-amber-800",children:[e.jsx("div",{className:"font-bold",children:"Frontmatter 校验提示"}),v.length>0&&e.jsxs("div",{children:[e.jsx("div",{className:"font-semibold",children:"错误"}),e.jsx("ul",{className:"list-disc pl-5",children:v.map((b,R)=>e.jsx("li",{children:b},R))})]}),A.length>0&&e.jsxs("div",{children:[e.jsx("div",{className:"font-semibold",children:"建议"}),e.jsx("ul",{className:"list-disc pl-5",children:A.map((b,R)=>e.jsx("li",{children:b},R))})]})]}),e.jsx("div",{className:"flex-1 flex flex-col min-h-0",children:o==="edit"?e.jsxs(e.Fragment,{children:[e.jsx("label",{className:"block text-xs font-bold text-slate-400 uppercase mb-2",children:"Markdown Content"}),e.jsx(ls,{value:t.content||"",onChange:b=>s({...t,content:b}),language:"markdown",height:"100%",showLineNumbers:!0})]}):e.jsxs("div",{className:"flex-1 overflow-y-auto space-y-6 scrollbar-light",children:[Object.keys(y).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:"Recipe Metadata"}),e.jsxs("div",{className:"space-y-4",children:[e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-y-4 gap-x-8",children:["title","trigger","language","category","knowledge_type","complexity","scope","difficulty","authority","status","version","updatedAt"].filter(b=>y[b]).map(b=>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:b==="updatedAt"?f(parseInt(y[b])):y[b]})]},b))}),y.tags&&e.jsxs("div",{className:"pt-3 border-t border-slate-200",children:[e.jsx("span",{className:"text-[10px] text-slate-400 font-bold uppercase mb-2 block",children:"Tags"}),e.jsx("div",{className:"flex flex-wrap gap-1.5",children:(()=>{try{const b=JSON.parse(y.tags);return(Array.isArray(b)?b:[y.tags]).map((R,M)=>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:R},M))}catch{return e.jsx("span",{className:"text-sm text-slate-700",children:y.tags})}})()})]}),y.headers&&e.jsxs("div",{className:"pt-3 border-t border-slate-200",children:[e.jsx("span",{className:"text-[10px] text-slate-400 font-bold uppercase mb-2 block",children:"Headers (Import)"}),e.jsx("div",{className:"flex flex-wrap gap-1.5",children:(()=>{try{const b=JSON.parse(y.headers);return(Array.isArray(b)?b:[y.headers]).map((R,M)=>e.jsx("code",{className:"px-2.5 py-1 bg-violet-50 text-violet-700 border border-violet-100 rounded-lg text-xs font-mono",children:R},M))}catch{return e.jsx("code",{className:"text-sm text-slate-700 font-mono",children:y.headers})}})()})]}),(y.summary_cn||y.summary)&&e.jsxs("div",{className:"pt-3 border-t border-slate-200",children:[e.jsx("span",{className:"text-[10px] text-slate-400 font-bold uppercase mb-2 block",children:"Summary (Chinese)"}),e.jsx("p",{className:"text-sm text-slate-700 leading-relaxed",children:y.summary_cn||y.summary})]}),y.summary_en&&e.jsxs("div",{className:"pt-3 border-t border-slate-200",children:[e.jsx("span",{className:"text-[10px] text-slate-400 font-bold uppercase mb-2 block",children:"Summary (English)"}),e.jsx("p",{className:"text-sm text-slate-700 leading-relaxed",children:y.summary_en})]}),(()=>{const b=new Set(["title","trigger","language","category","knowledge_type","complexity","scope","difficulty","authority","status","version","updatedAt","tags","headers","summary","summary_cn","summary_en","id"]),R=Object.entries(y).filter(([M])=>!b.has(M));return R.length===0?null:e.jsx("div",{className:"pt-3 border-t border-slate-200",children:e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-y-3 gap-x-8",children:R.map(([M,H])=>e.jsxs("div",{className:"flex flex-col",children:[e.jsx("span",{className:"text-[10px] text-slate-400 font-bold uppercase mb-1",children:M}),e.jsx("span",{className:"text-sm text-slate-700 break-all font-medium",children:H})]},M))})})})()]})]}),e.jsx("div",{className:"bg-white p-8 rounded-2xl border border-slate-100 shadow-sm min-h-[400px]",children:m?e.jsx(lt,{content:m,showLineNumbers:!0}):e.jsx("div",{className:"flex items-center justify-center h-full text-slate-300 italic",children:"No content body"})}),t.tags&&t.tags.length>0&&!y.tags&&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-3",children:"标签 (Tags)"}),e.jsx("div",{className:"flex flex-wrap gap-1.5",children:t.tags.map((b,R)=>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:b},R))})]}),!!(t.constraints&&((L=t.constraints.guards)!=null&&L.length||(U=t.constraints.boundaries)!=null&&U.length||(B=t.constraints.preconditions)!=null&&B.length||(K=t.constraints.sideEffects)!=null&&K.length))&&e.jsxs("div",{className:"bg-slate-50 border border-slate-200 rounded-2xl p-6 space-y-4",children:[e.jsx("h3",{className:"text-[10px] font-bold text-slate-400 uppercase tracking-widest",children:"约束条件 (Constraints)"}),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((b,R)=>e.jsxs("li",{className:"flex gap-2 items-start",children:[e.jsx("span",{className:`text-xs mt-0.5 ${b.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:b.pattern}),b.message&&e.jsxs("span",{className:"text-xs text-slate-400",children:["— ",b.message]})]},R))})]}),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((b,R)=>e.jsxs("li",{className:"flex gap-2",children:[e.jsx("span",{className:"text-orange-400",children:"●"}),b]},R))})]}),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((b,R)=>e.jsxs("li",{className:"flex gap-2",children:[e.jsx("span",{className:"text-blue-400",children:"◆"}),b]},R))})]}),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((b,R)=>e.jsxs("li",{className:"flex gap-2",children:[e.jsx("span",{className:"text-pink-400",children:"⚡"}),b]},R))})]})]}),t.relations&&Object.entries(t.relations).some(([,b])=>Array.isArray(b)&&b.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:b,label:R,color:M,icon:H})=>{var P;const _=(P=t.relations)==null?void 0:P[b];return!_||!Array.isArray(_)||_.length===0?null:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsxs("span",{className:`text-xs font-mono ${M} w-16 shrink-0 pt-0.5`,children:[H," ",R]}),e.jsx("div",{className:"flex flex-wrap gap-1.5",children:_.map((p,w)=>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 p=="string"?p:p.id||p.title||JSON.stringify(p)},w))})]},b)})})]})]})})]}),e.jsxs("div",{className:"p-6 border-t border-slate-100 flex justify-end gap-3",children:[e.jsx("button",{onClick:l,disabled:n,className:"px-4 py-2 text-slate-600 font-medium disabled:opacity-50",children:"Cancel"}),e.jsxs("button",{onClick:a,disabled:n,className:"px-6 py-2 bg-blue-600 text-white rounded-lg font-medium flex items-center gap-2 hover:bg-blue-700 disabled:opacity-60 disabled:cursor-not-allowed",children:[n?e.jsx(ze,{size:z.lg,className:"animate-spin"}):e.jsx(as,{size:z.lg}),n?"保存中...":"Save Changes"]})]})]})]})},Or=({setShowCreateModal:t,createPath:s,setCreatePath:a,handleCreateFromPath:l,handleCreateFromClipboard:n,isExtracting:o})=>e.jsxs(We,{className:"z-40 flex items-center justify-center p-4",children:[e.jsx(We.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(ut,{size:z.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:z.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(Ys,{size:z.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||o,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(el,{size:z.sm})," Import from Clipboard"]}),e.jsxs("button",{onClick:()=>n(),disabled:o,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(st,{size:z.lg})," Use Copied Code"]})]})]}),o&&e.jsxs("div",{className:"bg-blue-600 text-white p-4 flex items-center justify-center gap-3 animate-pulse",children:[e.jsx(Ut,{size:z.lg,className:"animate-spin"}),e.jsx("span",{className:"font-bold text-sm",children:"AI is thinking..."})]})]})]});function Br(t){const s=t.replace(/^---[\s\S]*?---\s*\n?/,"").trim(),a=s.match(/```[\w]*\n([\s\S]*?)```/);return a&&a[1]?a[1].trim():s.slice(0,8e3)}const Ur=({searchQ:t,insertPath:s,onClose:a})=>{const[l,n]=r.useState([]),[o,c]=r.useState(!0),[i,x]=r.useState(null),$=r.useRef(!0),d=r.useRef(null);r.useEffect(()=>($.current=!0,d.current=new AbortController,te.searchRecipesForModal(t||"",d.current.signal).then(m=>{$.current&&n(m.results||[])}).catch(m=>{m.name!=="AbortError"&&$.current&&n([])}).finally(()=>{$.current&&c(!1)}),()=>{$.current=!1,d.current&&d.current.abort()}),[t]);const y=async m=>{x(m.name);try{const S=Br(m.content);await te.insertAtSearchMark({path:s,content:S}),$.current&&(alert("✅ 已插入到 "+s),a())}catch{$.current&&alert("❌ 插入失败")}finally{$.current&&x(null)}};return e.jsxs(We,{className:"z-40 flex items-center justify-center p-4",children:[e.jsx(We.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(pt,{size:z.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:z.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:o?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(m=>e.jsx("li",{children:e.jsxs("button",{type:"button",onClick:()=>y(m),disabled:i!==null,className:"w-full flex items-center justify-between gap-3 p-4 rounded-xl border border-slate-200 hover:border-blue-300 hover:bg-blue-50/50 transition-all text-left disabled:opacity-50",children:[e.jsxs("div",{className:"flex-1 flex flex-col gap-1",children:[e.jsx("span",{className:"font-medium text-slate-800 truncate",children:m.name}),(m.qualityScore!==void 0||m.recommendReason)&&e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[m.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:["🤖 质量: ",(m.qualityScore*100).toFixed(0),"%"]}),m.recommendReason&&e.jsx("span",{className:"text-xs text-slate-600 italic truncate max-w-xs",children:m.recommendReason})]})]}),i===m.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(Qs,{size:z.md})," 插入"]})]})},m.name))})})]})]})},us=[{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:""}],Hr=({onClose:t,onSaved:s})=>{const[a,l]=r.useState(!0),[n,o]=r.useState(!1),[c,i]=r.useState(!1),[x,$]=r.useState("google"),[d,y]=r.useState("gemini-2.0-flash"),[m,S]=r.useState(""),[v,A]=r.useState(""),[f,k]=r.useState(!1),[T,L]=r.useState({}),[U,B]=r.useState(!1);r.useEffect(()=>{K()},[]);const K=async()=>{l(!0);try{const p=await te.getLlmEnvConfig();i(p.hasEnvFile);const w=p.vars||{};w.ASD_AI_PROVIDER&&$(w.ASD_AI_PROVIDER),w.ASD_AI_MODEL&&y(w.ASD_AI_MODEL),w.ASD_AI_PROXY&&A(w.ASD_AI_PROXY),L(w)}catch{}finally{l(!1)}},b=us.find(p=>p.id===x),R=(b==null?void 0:b.keyEnv)||"",M=R?!!T[R]:!0,H=p=>{$(p);const w=us.find(E=>E.id===p);w&&y(w.defaultModel),S("")},_=async()=>{if(x){if(R&&!M&&!m.trim()){alert("请填写 API Key");return}o(!0),B(!1);try{await te.saveLlmEnvConfig({provider:x,model:d||void 0,apiKey:m.trim()||void 0,proxy:v.trim()||void 0}),B(!0),setTimeout(()=>{s(),t()},800)}catch(p){alert((p==null?void 0:p.message)||"保存失败")}finally{o(!1)}}},P=p=>!p||p.length<10?p?"••••••":"":`${p.slice(0,6)}••••${p.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:p=>p.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:z.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(ze,{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(Ot,{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:us.map(p=>e.jsx("button",{type:"button",onClick:()=>H(p.id),className:`px-3 py-2 rounded-lg text-sm font-medium border transition-all ${x===p.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:p.label},p.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:d,onChange:p=>y(p.target.value),placeholder:(b==null?void 0:b.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"})]}),R&&e.jsxs("div",{children:[e.jsxs("label",{className:"block text-sm font-medium text-slate-700 mb-1.5",children:["API Key",M&&e.jsxs("span",{className:"ml-2 text-xs text-green-600 font-normal",children:["(已配置: ",P(T[R]),")"]})]}),e.jsxs("div",{className:"relative",children:[e.jsx("input",{type:f?"text":"password",value:m,onChange:p=>S(p.target.value),placeholder:M?"留空保持当前 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:()=>k(p=>!p),className:"absolute right-2 top-1/2 -translate-y-1/2 p-1 text-slate-400 hover:text-slate-600",children:f?e.jsx(tl,{size:16}):e.jsx($t,{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:v,onChange:p=>A(p.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:_,disabled:n||a||U,className:`flex items-center gap-2 px-5 py-2 rounded-lg text-sm font-medium transition-all ${U?"bg-green-500 text-white":"bg-blue-600 text-white hover:bg-blue-700 shadow-sm"} disabled:opacity-60`,children:[n?e.jsx(ze,{size:16,className:"animate-spin"}):U?e.jsx(Zs,{size:16}):e.jsx(as,{size:16}),U?"已保存":"保存到 .env"]})]})]})})};class Wr extends Bt.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 tt(t){return t?typeof t=="string"?t:typeof t=="object"?Object.entries(t).map(([a,l])=>`${a}: ${Array.isArray(l)?l.join("; "):l}`).join(`
|
|
150
|
+
`):String(t):""}const Kr=()=>{var Ue,_e;const t=Nl(),s=wl((Ue=t.user)==null?void 0:Ue.role),a=kl(),l=()=>{const N=window.location.pathname.replace(/^\//,"").split("/")[0]||"";return ml.includes(N)?N:"help"},[n,o]=r.useState(null),[c,i]=r.useState(l()),[x,$]=r.useState(!1),[d,y]=r.useState(""),[m,S]=r.useState(!0),[v,A]=r.useState(null),[f,k]=r.useState([]),[T,L]=r.useState(null),[U,B]=r.useState(!1),[K,b]=r.useState({current:0,total:0,status:""}),[R,M]=r.useState([]),[H,_]=r.useState([]),[P,p]=r.useState(null),[w,E]=r.useState("All"),[se,h]=r.useState(1),[V,me]=r.useState(12),[F,X]=r.useState(!1),[Y,ie]=r.useState(""),[Ne,Re]=r.useState(!1),[fe,Q]=r.useState(null),[ve,Le]=r.useState(null),[Ge,we]=r.useState(!1),[Fe,Ee]=r.useState(!0),[ke,De]=r.useState(!1),[Ze,Ve]=r.useState(0),g=r.useRef(null);r.useEffect(()=>{h(1)},[d,w]);const J=()=>{g.current&&g.current.abort()};r.useEffect(()=>{let N=!1;const D=async()=>{var O,pe,le;try{const xe=await te.getSignalStatus();if(!N){const ce=((O=xe==null?void 0:xe.suggestions)==null?void 0:O.length)||0,ge=((le=(pe=xe==null?void 0:xe.snapshot)==null?void 0:pe.lastResult)==null?void 0:le.newSuggestions)||0;Ve(ce||ge)}}catch{}};D();const W=setInterval(D,300*1e3);return()=>{N=!0,clearInterval(W)}},[]),r.useEffect(()=>{a.isAllDone&&G()},[a.isAllDone]);const Z=(N,D)=>{i(N);const W=D!=null&&D.preserveSearch&&window.location.search?window.location.search:"";window.history.pushState({},document.title,`/${N}${W}`)},u=N=>{A(N),i("recipes");const D=new URLSearchParams(window.location.search);D.set("edit",encodeURIComponent(N.name)),window.history.pushState({},document.title,`/recipes?${D.toString()}`)},I=()=>{A(null),window.history.replaceState({},document.title,"/recipes")};r.useEffect(()=>{d===""&&Q(null)},[d]),r.useEffect(()=>{i(l())},[]),r.useEffect(()=>{if(!n)return;const N=window.location.pathname.replace(/^\//,"").split("/")[0],W=new URLSearchParams(window.location.search).get("edit");if(N==="recipes"&&W&&n.recipes)try{const O=decodeURIComponent(W),pe=n.recipes.find(le=>le.name===O);pe&&!v&&(i("recipes"),u(pe))}catch{}},[n]),r.useEffect(()=>{G(),C(),q();const N=()=>{i(l())};window.addEventListener("popstate",N);const D=new URLSearchParams(window.location.search),W=D.get("action"),O=D.get("path"),pe=D.get("q")||"";return W==="search"&&O?Le({q:pe,path:O}):W==="create"&&O&&(ie(O),X(!0),D.get("autoScan")==="1"&&setTimeout(()=>oe(O),500)),()=>{window.removeEventListener("popstate",N)}},[]);const G=async()=>{S(!0);try{const N=await te.fetchData();if(N.candidates){const D={};Object.entries(N.candidates).forEach(([W,O])=>{const pe=O.items.map(le=>{const xe=le.summary_cn||le.summary||"",ce=le.summary_en&&le.summary_en!==xe?le.summary_en:void 0,ge=tt(le.usageGuide_cn||le.usageGuide||""),$e=le.usageGuide_en&&tt(le.usageGuide_en)!==ge?tt(le.usageGuide_en):void 0;return{...le,summary_cn:xe,summary_en:ce,usageGuide_cn:ge,usageGuide_en:$e}});D[W]={...O,items:pe}}),N.candidates=D}o(N)}catch(N){ee((N==null?void 0:N.message)||"无法加载项目数据",{title:"加载失败",type:"error"})}finally{S(!1)}},C=async()=>{try{const N=await te.fetchTargets();k(N)}catch(N){console.warn("删除候选残留失败:",N==null?void 0:N.message)}},q=async()=>{try{const N=await te.getLlmEnvConfig();Ee(N.llmReady)}catch{}},ae=async()=>{try{await te.syncToXcode(),ee("Recipes 已同步到 Xcode CodeSnippets 目录",{title:"Xcode 同步成功"})}catch{ee("请检查 Xcode 是否已安装并重试",{title:"同步失败",type:"error"})}},ue=async()=>{try{await te.refreshProject(),C(),ee("Target 列表与文件树已更新",{title:"项目结构已刷新"})}catch{ee("请确认项目路径有效后重试",{title:"刷新失败",type:"error"})}},oe=async N=>{var D;Re(!0);try{const W=await te.extractFromPath(N);_(W.result.map(O=>{const pe=O.summary_cn||O.summary||"",le=O.summary_en&&O.summary_en!==pe?O.summary_en:void 0,xe=tt(O.usageGuide_cn||O.usageGuide||""),ce=O.usageGuide_en&&tt(O.usageGuide_en)!==xe?tt(O.usageGuide_en):void 0;return{...O,summary_cn:pe,summary_en:le,usageGuide_cn:xe,usageGuide_en:ce,tags:Array.isArray(O.tags)?O.tags:[],mode:"full",lang:"cn",includeHeaders:!0,category:O.category||"Utility",summary:pe,usageGuide:xe}})),Z("spm",{preserveSearch:!0}),X(!1),G(),((D=W.result)==null?void 0:D.length)>0&&ee("提取结果已进入候选池,请在 Candidates 页审核",{title:"提取完成"})}catch{ee("Extraction failed",{type:"error"})}finally{Re(!1)}},Ie=async()=>{var N;if(Y){Re(!0);try{const D=await te.extractFromPath(Y);_(D.result.map(W=>{const O=W.summary_cn||W.summary||"",pe=W.summary_en&&W.summary_en!==O?W.summary_en:void 0,le=tt(W.usageGuide_cn||W.usageGuide||""),xe=W.usageGuide_en&&tt(W.usageGuide_en)!==le?tt(W.usageGuide_en):void 0;return{...W,summary_cn:O,summary_en:pe,usageGuide_cn:le,usageGuide_en:xe,tags:Array.isArray(W.tags)?W.tags:[],mode:"full",lang:"cn",includeHeaders:!0,category:W.category||"Utility",summary:O,usageGuide:le}})),Z("spm"),X(!1),G(),((N=D.result)==null?void 0:N.length)>0?ee(D.isMarked?"精准锁定标记代码,已加入候选池":"提取结果已加入候选池",{title:"提取完成"}):D.isMarked||ee("未找到 ASD 标记,AI 将分析完整文件",{title:"提取中",type:"info"})}catch{ee("Extraction failed",{type:"error"})}finally{Re(!1)}}},re=async N=>{var D,W,O,pe;try{const le=await navigator.clipboard.readText();if(!le)return ee("请先复制代码到剪贴板",{title:"剪贴板为空",type:"info"});ee("已收到代码,AI 正在识别可复用模式...",{title:"剪贴板分析中",type:"info"}),Re(!0);const xe=N||Y;try{const ce=await te.extractFromText(le,xe||void 0),ge=ce.summary_cn||ce.summary||"",$e=ce.summary_en&&ce.summary_en!==ge?ce.summary_en:void 0,Oe=tt(ce.usageGuide_cn||ce.usageGuide||""),rt=ce.usageGuide_en&&tt(ce.usageGuide_en)!==Oe?tt(ce.usageGuide_en):void 0,qe=ce._multipleCount;_([{...ce,summary_cn:ge,summary_en:$e,usageGuide_cn:Oe,usageGuide_en:rt,tags:Array.isArray(ce.tags)?ce.tags:[],mode:"full",lang:"cn",includeHeaders:!0,category:ce.category||"Utility",summary:ge,usageGuide:Oe}]),Z("spm",{preserveSearch:!0}),X(!1),G(),ee(qe?`已识别 ${qe} 条 Recipe,请在候选池审核`:"提取结果已加入候选池",{title:"AI 识别完成"})}catch(ce){const ge=((W=(D=ce.response)==null?void 0:D.data)==null?void 0:W.aiError)===!0,$e=((pe=(O=ce.response)==null?void 0:O.data)==null?void 0:pe.error)||ce.message;ge?ee($e,{title:"AI 识别失败",type:"error"}):ee($e,{title:"操作失败",type:"error"})}}catch{ee("浏览器可能未授权剪贴板访问",{title:"剪贴板读取失败",type:"error"})}finally{Re(!1)}},ye=[{status:"正在读取 Target 源文件...",percent:15},{status:"正在发送到 AI 分析...",percent:35},{status:"正在识别可复用代码片段...",percent:55},{status:"正在生成摘要与使用指南...",percent:75},{status:"即将完成...",percent:92}],Se=async N=>{var le,xe,ce,ge;if(U)return;g.current&&g.current.abort();const D=new AbortController;g.current=D,L(N.name),B(!0),_([]),p(null),M([]),b({current:0,total:100,status:"正在获取待扫描文件列表..."});const W=4e3;let O=0;const pe=setInterval(()=>{O=Math.min(O+1,ye.length);const $e=ye[O-1];$e&&b(Oe=>({...Oe,current:$e.percent,status:$e.status}))},W);try{const $e=await te.getTargetFiles(N,D.signal),Oe=$e.files||[],rt=$e.count??Oe.length;M(Oe),b(nt=>({...nt,current:10,status:`正在分析 ${rt} 个文件...`}));const qe=await te.scanTarget(N,D.signal);clearInterval(pe),b({current:100,total:100,status:"扫描完成"});const Je=qe.recipes||[],dt=(le=qe.scannedFiles)!=null&&le.length?qe.scannedFiles:Oe;if(Je.length>0||dt.length>0){const nt=typeof N=="string"?N:(N==null?void 0:N.name)||"unknown",ua=Je.map(ot=>({...ot,mode:"full",lang:"cn",includeHeaders:ot.includeHeaders!==!1,category:ot.category||"Utility",summary:tt(ot.summary_cn||ot.summary||""),usageGuide:tt(ot.usageGuide_cn||ot.usageGuide||""),tags:Array.isArray(ot.tags)?ot.tags:[],candidateTargetName:nt,scanMode:"target"}));_(ua),M(dt),G(),Je.length>0?ee(`发现 ${Je.length} 条可复用代码模式,请在右侧审核`,{title:"Target 扫描完成"}):qe.message?ee(qe.message,{title:"AI 扫描未返回结果",type:"error"}):ee("该 Target 中未找到可复用的代码片段",{title:"扫描完成",type:"info"})}else ee("请确认 Target 包含有效的源代码文件",{title:"扫描失败",type:"error"})}catch($e){if(clearInterval(pe),St.isCancel($e))return;const Oe=$e.code==="ECONNABORTED"||((xe=$e.message)==null?void 0:xe.includes("timeout")),rt=Oe?"扫描超时,请尝试减少 Target 文件数量":((ge=(ce=$e.response)==null?void 0:ce.data)==null?void 0:ge.error)||$e.message;ee(rt,{title:Oe?"扫描超时":"扫描出错",type:"error"})}finally{g.current===D&&(B(!1),b({current:0,total:0,status:""}),g.current=null)}},Be=async()=>{var D,W,O,pe,le,xe;if(U)return;g.current&&g.current.abort();const N=new AbortController;g.current=N,Z("candidates"),B(!0),_([]),p(null),M([]),b({current:0,total:100,status:"正在收集项目结构..."}),a.resetSession();try{const ce=await te.bootstrap(N.signal);b({current:100,total:100,status:"骨架已创建,正在后台填充..."}),ce.bootstrapSession&&a.initFromApiResponse(ce.bootstrapSession),G();const ge=ce.report||{},$e=((D=ce.targets)==null?void 0:D.length)||0,Oe=((W=ge.totals)==null?void 0:W.files)||0,rt=((O=ge.totals)==null?void 0:O.graphEdges)||0,qe=ce.guardSummary,Je=qe?`, Guard: ${qe.totalViolations} 项违规`:"";ee(`冷启动骨架已创建: ${$e} 个 Target, ${Oe} 个文件, ${rt} 条依赖${Je},正在后台逐维度填充...`)}catch(ce){if(St.isCancel(ce))return;const $e=ce.code==="ECONNABORTED"||((pe=ce.message)==null?void 0:pe.includes("timeout"))?"冷启动超时,请检查项目文件数量":((xe=(le=ce.response)==null?void 0:le.data)==null?void 0:xe.error)||ce.message;ee($e,{type:"error"})}finally{g.current===N&&(B(!1),b({current:0,total:0,status:""}),g.current=null)}},Ae=async()=>{var pe,le,xe,ce;if(U)return;g.current&&g.current.abort();const N=new AbortController;g.current=N,Z("spm"),L("__project__"),B(!0),_([]),p(null),M([]),b({current:0,total:100,status:"正在收集所有 Target 文件..."});const D=[{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 W=0;const O=setInterval(()=>{W=Math.min(W+1,D.length);const ge=D[W-1];ge&&b($e=>({...$e,current:ge.percent,status:ge.status}))},15e3);try{const ge=await te.scanProject(N.signal);clearInterval(O),b({current:100,total:100,status:ge.partial?"扫描部分完成(超时)":"全项目扫描完成"});const $e=ge.recipes||[],Oe=ge.scannedFiles||[];if($e.length>0||Oe.length>0){const rt=$e.map(nt=>({...nt,mode:"full",lang:"cn",includeHeaders:nt.includeHeaders!==!1,category:nt.category||"Utility",summary:nt.summary_cn||nt.summary||"",usageGuide:nt.usageGuide_cn||nt.usageGuide||"",candidateTargetName:"__project__",scanMode:"project"}));_(rt),M(Oe),p(ge.guardAudit||null),G();const qe=(pe=ge.guardAudit)==null?void 0:pe.summary,Je=qe?`, Guard: ${qe.totalViolations} 处违反`:"",dt=ge.partial?"(部分结果,AI 超时)":"";ee(`全项目扫描完成: ${$e.length} 条候选${Je}${dt}`)}else ee("全项目扫描完成,未发现可提取内容")}catch(ge){if(clearInterval(O),St.isCancel(ge))return;const Oe=ge.code==="ECONNABORTED"||((le=ge.message)==null?void 0:le.includes("timeout"))?"扫描超时,请尝试减少项目文件数量或分 Target 扫描":((ce=(xe=ge.response)==null?void 0:xe.data)==null?void 0:ce.error)||ge.message;ee(Oe,{type:"error"})}finally{g.current===N&&(B(!1),b({current:0,total:0,status:""}),g.current=null)}},He=(N,D)=>{const W=[...H],O={...W[N],...D};!O.summary_cn&&O.summary&&!O.summary_en&&(O.summary_cn=O.summary),!O.usageGuide_cn&&O.usageGuide&&!O.usageGuide_en&&(O.usageGuide_cn=O.usageGuide),D.lang!==void 0&&D.summary===void 0&&(O.summary=D.lang==="cn"?O.summary_cn||O.summary:O.summary_en||O.summary),D.lang!==void 0&&D.usageGuide===void 0&&(O.usageGuide=D.lang==="cn"?O.usageGuide_cn||O.usageGuide:O.usageGuide_en||O.usageGuide),D.summary!==void 0&&D.lang===void 0&&(O.lang==="cn"?O.summary_cn=D.summary:O.summary_en=D.summary),D.usageGuide!==void 0&&D.lang===void 0&&(O.lang==="cn"?O.usageGuide_cn=D.usageGuide:O.usageGuide_en=D.usageGuide),W[N]=O,_(W)},Qe=async N=>{if(!Ge){we(!0);try{const D=(N.trigger||"").split(/[,,\s]+/).map(Je=>Je.trim()).filter(Boolean);if(D.length===0){ee("请输入 Trigger",{type:"error"}),we(!1);return}const W=crypto.randomUUID().toUpperCase(),O=`${(N.title||"Untitled").replace(/\s+/g,"-")}.md`,pe=N.summary_cn||N.summary||"",le=N.summary_en||N.summary||"",xe=N.usageGuide_cn||N.usageGuide||"",ce=N.usageGuide_en||N.usageGuide||"";let ge=`---
|
|
151
151
|
id: ${N.mode==="full"?W:"preview-only"}
|
|
152
152
|
title: ${N.title||"Untitled Recipe"}
|
|
153
153
|
language: ${N.language||"swift"}
|
|
@@ -193,5 +193,5 @@ ${N.steps.map((Je,dt)=>`${dt+1}. ${Je}`).join(`
|
|
|
193
193
|
|
|
194
194
|
**Preconditions:**
|
|
195
195
|
${N.preconditions.map(Je=>`- ${Je}`).join(`
|
|
196
|
-
`)}`);const Oe=ge+$e;await te.saveRecipe(O,Oe),ee(N.mode==="full"?"已保存为 Recipe(Snippet 将自动生成)":"已保存到 KB"),
|
|
197
|
-
## AI Context / Usage Guide (EN)`,W=N.indexOf(D);if(W!==-1){const O=N.substring(W+D.length),pe=O.indexOf(D);if(pe!==-1){const le=O.match(/\n## /);let xe=O.length;le&&le.index!==void 0&&le.index<pe?(xe=le.index,N=N.substring(0,W+D.length)+O.substring(0,xe)):N=N.substring(0,W+D.length)+O.substring(0,pe)}}await te.saveRecipe(v.name,N),I(),G()}catch(N){const D=As(N)??Xt(N);ee(D??"保存 Recipe 失败",{type:"error"})}finally{we(!1)}}},j=async N=>{if(window.confirm("Are you sure?"))try{await te.deleteRecipe(N),G()}catch(D){const W=Xt(D);ee(W??"删除失败",{type:"error"})}},he=async(N,D)=>{try{await te.deleteCandidate(D),
|
|
196
|
+
`)}`);const Oe=ge+$e;await te.saveRecipe(O,Oe),ee(N.mode==="full"?"已保存为 Recipe(Snippet 将自动生成)":"已保存到 KB"),_(Je=>Je.filter(dt=>dt.title!==N.title));const rt=N.candidateTargetName,qe=N.candidateId;if(rt&&qe)try{await te.deleteCandidate(qe)}catch{}G()}catch(D){const W=As(D)??Xt(D);ee(W??"保存失败",{type:"error"})}finally{we(!1)}}},de=async()=>{if(!(!v||Ge)){we(!0);try{let N=v.content;const D=`
|
|
197
|
+
## AI Context / Usage Guide (EN)`,W=N.indexOf(D);if(W!==-1){const O=N.substring(W+D.length),pe=O.indexOf(D);if(pe!==-1){const le=O.match(/\n## /);let xe=O.length;le&&le.index!==void 0&&le.index<pe?(xe=le.index,N=N.substring(0,W+D.length)+O.substring(0,xe)):N=N.substring(0,W+D.length)+O.substring(0,pe)}}await te.saveRecipe(v.name,N),I(),G()}catch(N){const D=As(N)??Xt(N);ee(D??"保存 Recipe 失败",{type:"error"})}finally{we(!1)}}},j=async N=>{if(window.confirm("Are you sure?"))try{await te.deleteRecipe(N),G()}catch(D){const W=Xt(D);ee(W??"删除失败",{type:"error"})}},he=async(N,D)=>{try{await te.deleteCandidate(D),_(W=>W.filter(O=>!(O.candidateId===D&&O.candidateTargetName===N))),o(W=>{if(!(W!=null&&W.candidates))return W;const O={...W.candidates};if(O[N]){const pe=O[N].items.filter(le=>le.id!==D);pe.length===0?delete O[N]:O[N]={...O[N],items:pe}}return{...W,candidates:O}})}catch{ee("操作失败",{type:"error"})}},Ce=async N=>{if(window.confirm(`确定移除「${N}」下的全部候选?`))try{await te.deleteAllCandidatesInTarget(N),G(),ee(`已移除 ${N} 下的全部候选`)}catch{ee("操作失败",{type:"error"})}},je=async(N,D)=>{var W,O;try{await te.promoteToCandidate(N,N.candidateTargetName||T||"_review"),ee("已加入 Candidate 待审核队列"),_(pe=>pe.filter((le,xe)=>xe!==D)),G()}catch(pe){ee(((O=(W=pe.response)==null?void 0:W.data)==null?void 0:O.error)||"创建 Candidate 失败",{type:"error"})}},Te=((n==null?void 0:n.recipes)||[]).filter(N=>{if(fe)return fe.some(xe=>xe.metadata.type==="recipe"&&xe.metadata.name===N.name);const D=N.name||"",W=N.content||"",O=D.toLowerCase().includes(d.toLowerCase())||W.toLowerCase().includes(d.toLowerCase());if(w==="All")return O;const pe=W?W.match(/category:\s*(.*)/):null,le=pe?pe[1].trim():"Utility";return O&&le===w}).sort((N,D)=>{var pe,le,xe,ce;if(fe){const ge=((pe=fe.find(Oe=>Oe.metadata.name===N.name))==null?void 0:pe.similarity)||0;return(((le=fe.find(Oe=>Oe.metadata.name===D.name))==null?void 0:le.similarity)||0)-ge}const W=((xe=N.stats)==null?void 0:xe.authorityScore)??0;return(((ce=D.stats)==null?void 0:ce.authorityScore)??0)-W}),Me=f.filter(N=>N.name.toLowerCase().includes(d.toLowerCase())).sort((N,D)=>{const W=Wt(N.name),O=Wt(D.name);return W&&!O?1:!W&&O?-1:N.name.localeCompare(D.name)}),Pe=Object.values((n==null?void 0:n.candidates)||{}).reduce((N,D)=>N+D.items.length,0),be=c==="editor";return e.jsx(Wr,{children:e.jsx(Pl,{children:e.jsxs("div",{className:`flex h-screen ${be?"bg-[#1e1e1e] text-slate-200":"bg-slate-50 text-slate-900"} overflow-hidden font-sans`,children:[e.jsx(ha,{position:"top-center",toastOptions:{duration:5e3},containerStyle:{top:24}}),e.jsx(Cl,{activeTab:c,navigateToTab:Z,handleRefreshProject:ue,candidateCount:Pe,signalSuggestionCount:Ze,isDarkMode:be,currentUser:s.user!=="anonymous"?s.user:void 0,currentRole:s.role,permissionMode:s.mode,onLogout:void 0,collapsed:x,onToggleCollapse:()=>$(N=>!N)}),e.jsxs("main",{className:"flex-1 flex flex-col overflow-hidden relative",children:[e.jsx(Fl,{searchQuery:d,setSearchQuery:y,setShowCreateModal:X,handleSyncToXcode:ae,aiConfig:n==null?void 0:n.aiConfig,llmReady:Fe,onOpenLlmConfig:()=>De(!0),onBeforeAiSwitch:J,onAiConfigChange:G,isDarkMode:be,onSemanticSearchResults:N=>{Q(N),c!=="recipes"&&Z("recipes")}}),c==="recipes"&&e.jsx(Ol,{selectedCategory:w,setSelectedCategory:E}),e.jsx("div",{className:`flex-1 overflow-y-auto ${c==="editor"?"":"p-8"}`,children:m?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(Jl,{recipes:Te,openRecipeEdit:u,handleDeleteRecipe:j,onRefresh:G,currentPage:se,onPageChange:h,pageSize:V,onPageSizeChange:N=>{me(N),h(1)}}):c==="guard"?e.jsx(gr,{onRefresh:G}):c==="skills"?e.jsx(_r,{onRefresh:G,signalSuggestionCount:Ze,onSuggestionCountChange:Ve}):c==="candidates"?e.jsxs(e.Fragment,{children:[a.session&&e.jsx("div",{className:"mb-4",children:e.jsx(Dr,{session:a.session,isAllDone:a.isAllDone,reviewState:a.reviewState,onDismiss:()=>a.resetSession()})}),e.jsx(ar,{data:n,isShellTarget:Wt,isSilentTarget:pl,isPendingTarget:hl,handleDeleteCandidate:he,onEditRecipe:u,onColdStart:Be,isScanning:U,isBootstrapping:((_e=a.session)==null?void 0:_e.status)==="running",onRefresh:G,onAuditCandidate:(N,D)=>{_([{...N,mode:"full",lang:"cn",includeHeaders:!0,summary:N.summary_cn||N.summary||"",usageGuide:N.usageGuide_cn||N.usageGuide||"",candidateId:N.id,candidateTargetName:D}]),Z("spm")},onAuditAllInTarget:(N,D)=>{_(N.map(W=>({...W,mode:"full",lang:"cn",includeHeaders:!0,summary:W.summary_cn||W.summary||"",usageGuide:W.usageGuide_cn||W.usageGuide||"",candidateId:W.id,candidateTargetName:D}))),Z("spm")},handleDeleteAllInTarget:Ce})]}):c==="depgraph"?e.jsx(br,{}):c==="knowledgegraph"?e.jsx(Ar,{}):c==="spm"?e.jsx(dr,{targets:f,filteredTargets:Me,selectedTargetName:T,isScanning:U,scanProgress:K,scanFileList:R,scanResults:H,guardAudit:P,handleScanTarget:Se,handleScanProject:Ae,handleUpdateScanResult:He,handleSaveExtracted:Qe,handlePromoteToCandidate:je,handleDeleteCandidate:he,onEditRecipe:u,isShellTarget:Wt,recipes:(n==null?void 0:n.recipes)??[],isSavingRecipe:Ge}):c==="editor"?e.jsx(Pr,{}):c==="help"?e.jsx(Yl,{}):e.jsx(yr,{})}),v&&e.jsx(Fr,{editingRecipe:v,setEditingRecipe:A,handleSaveRecipe:de,closeRecipeEdit:I,isSavingRecipe:Ge}),F&&e.jsx(Or,{setShowCreateModal:X,createPath:Y,setCreatePath:ie,handleCreateFromPath:Ie,handleCreateFromClipboard:re,isExtracting:Ne}),ve&&e.jsx(Ur,{searchQ:ve.q,insertPath:ve.path,onClose:()=>{Le(null),window.history.replaceState({},document.title,window.location.pathname)}}),ke&&e.jsx(Hr,{onClose:()=>De(!1),onSaved:()=>{q(),G()}})]}),e.jsx(Vr,{})]})})})},Vr=()=>{const{isOpen:t}=Ht();return t?e.jsx(Ll,{}):null};ba.createRoot(document.getElementById("root")).render(e.jsx(Bt.StrictMode,{children:e.jsx(Kr,{})}));
|