autosnippet 2.0.2 → 2.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. package/README.md +189 -113
  2. package/bin/api-server.js +1 -4
  3. package/bin/cli.js +1 -50
  4. package/config/constitution.yaml +33 -107
  5. package/dashboard/dist/assets/{icons-B4FfLfBA.js → icons-B5rs8uNb.js} +85 -80
  6. package/dashboard/dist/assets/index-0YzLw2ga.css +1 -0
  7. package/dashboard/dist/assets/index-B9py3ybr.js +154 -0
  8. package/dashboard/dist/index.html +3 -3
  9. package/lib/bootstrap.js +5 -31
  10. package/lib/cli/SetupService.js +16 -14
  11. package/lib/core/capability/CapabilityProbe.js +8 -6
  12. package/lib/core/constitution/Constitution.js +13 -4
  13. package/lib/core/constitution/ConstitutionValidator.js +106 -211
  14. package/lib/core/gateway/Gateway.js +34 -98
  15. package/lib/core/gateway/GatewayActionRegistry.js +12 -1
  16. package/lib/core/permission/PermissionManager.js +2 -2
  17. package/lib/external/mcp/McpServer.js +4 -7
  18. package/lib/external/mcp/handlers/bootstrap.js +13 -1
  19. package/lib/external/mcp/handlers/browse.js +0 -7
  20. package/lib/external/mcp/handlers/candidate.js +1 -1
  21. package/lib/external/mcp/handlers/guard.js +11 -0
  22. package/lib/external/mcp/handlers/skill.js +186 -18
  23. package/lib/external/mcp/tools.js +40 -1
  24. package/lib/http/middleware/roleResolver.js +1 -1
  25. package/lib/http/routes/auth.js +2 -2
  26. package/lib/http/routes/commands.js +58 -3
  27. package/lib/http/routes/monitoring.js +4 -4
  28. package/lib/http/routes/recipes.js +96 -4
  29. package/lib/http/routes/search.js +34 -35
  30. package/lib/injection/ServiceContainer.js +21 -40
  31. package/lib/service/candidate/CandidateService.js +12 -1
  32. package/lib/service/chat/ChatAgent.js +171 -30
  33. package/lib/service/chat/Memory.js +104 -0
  34. package/lib/service/chat/tools.js +244 -10
  35. package/lib/service/guard/GuardCheckEngine.js +9 -1
  36. package/lib/service/knowledge/KnowledgeGraphService.js +20 -9
  37. package/lib/service/recipe/RecipeService.js +8 -0
  38. package/lib/service/skills/SkillHooks.js +126 -0
  39. package/package.json +1 -1
  40. package/scripts/init-db.js +1 -2
  41. package/templates/constitution.yaml +29 -85
  42. package/dashboard/dist/assets/index-ChxJxX4B.js +0 -154
  43. package/dashboard/dist/assets/index-DwAp1mx5.css +0 -1
  44. package/lib/core/session/SessionManager.js +0 -232
  45. package/lib/infrastructure/logging/ReasoningLogger.js +0 -269
  46. package/lib/infrastructure/monitoring/RoleDriftMonitor.js +0 -259
  47. package/lib/infrastructure/quality/ComplianceEvaluator.js +0 -326
@@ -1,154 +0,0 @@
1
- import{n as Wt,r as n,j as e,F as hs,i as bs,R as gs}from"./vendor-Cky7Jynh.js";import{a as Je}from"./axios-C0Zqfgkc.js";import{L as rt,B as kt,H as fs,W as js,D as es,Z as Be,C as At,P as ys,G as Ns,a as zt,b as vs,F as ws,c as Ft,d as ts,S as Ot,e as Ve,M as Bt,f as pt,g as Cs,E as Ht,h as Ss,i as ks,U as Is,j as $s,R as nt,k as it,l as ze,m as _s,n as Qe,o as ss,p as As,q as zs,r as et,s as Es,t as ot,u as as,v as Rs,T as Et,w as Ts,x as Nt,y as Gs,z as Ms,A as Vt,I as Kt,J as Ps,X as Ke,K as ls,N as Dt,O as Ls,Q as rs,V as Fs,Y as Os,_ as vt,$ as Xt,a0 as Ds,a1 as ns,a2 as Bs,a3 as Hs,a4 as Us,a5 as wt,a6 as It,a7 as qs,a8 as $t,a9 as is,aa as _t,ab as Ws,ac as os,ad as Vs,ae as Ks,af as Xs,ag as Js,ah as Ys,ai as Zs,aj as Qs,ak as ea,al as cs,am as ta,an as Jt,ao as sa,ap as aa,aq as la}from"./icons-B4FfLfBA.js";import{h as ds,o as xs}from"./syntax-highlighter-C6bvFtpx.js";import{M as ra}from"./react-markdown-Bp8u1wRC.js";import"./yaml-qRaU8Ldn.js";(function(){const s=document.createElement("link").relList;if(s&&s.supports&&s.supports("modulepreload"))return;for(const l of document.querySelectorAll('link[rel="modulepreload"]'))r(l);new MutationObserver(l=>{for(const o of l)if(o.type==="childList")for(const d of o.addedNodes)d.tagName==="LINK"&&d.rel==="modulepreload"&&r(d)}).observe(document,{childList:!0,subtree:!0});function a(l){const o={};return l.integrity&&(o.integrity=l.integrity),l.referrerPolicy&&(o.referrerPolicy=l.referrerPolicy),l.crossOrigin==="use-credentials"?o.credentials="include":l.crossOrigin==="anonymous"?o.credentials="omit":o.credentials="same-origin",o}function r(l){if(l.ep)return;l.ep=!0;const o=a(l);fetch(l.href,o)}})();const na="AutoSnippet";function ia(t){if(typeof window>"u"||!("Notification"in window))return;const s=()=>{try{new Notification(na,{body:t,tag:"autosnippet"})}catch{}};if(Notification.permission==="granted"){s();return}Notification.permission!=="denied"&&Notification.requestPermission().then(a=>{a==="granted"&&s()})}function ae(t,s){typeof document<"u"&&document.visibilityState==="visible"?(s==null?void 0:s.type)==="error"?Wt.error(t):Wt.success(t):ia(t)}const De={All:{icon:Ns,color:"text-slate-600",bg:"bg-slate-100",border:"border-slate-200"},View:{icon:ys,color:"text-pink-600",bg:"bg-pink-50",border:"border-pink-100"},Service:{icon:At,color:"text-indigo-600",bg:"bg-indigo-50",border:"border-indigo-100"},Tool:{icon:Be,color:"text-amber-600",bg:"bg-amber-50",border:"border-amber-100"},Model:{icon:es,color:"text-emerald-600",bg:"bg-emerald-50",border:"border-emerald-100"},Network:{icon:js,color:"text-blue-600",bg:"bg-blue-50",border:"border-blue-100"},Storage:{icon:fs,color:"text-purple-600",bg:"bg-purple-50",border:"border-purple-100"},UI:{icon:kt,color:"text-cyan-600",bg:"bg-cyan-50",border:"border-cyan-100"},Utility:{icon:rt,color:"text-orange-600",bg:"bg-orange-50",border:"border-orange-100"}},oa=["All","View","Service","Tool","Model","Network","Storage","UI","Utility"],ca=["recipes","ai","spm","candidates","depgraph","knowledgegraph","guard","editor","help"],da="https://github.com/GxFn/AutoSnippet/issues/new?title=Guard%20误报%2F建议%3A%20&body=请描述误报的规则ID、代码片段或改进建议。",gt=t=>["Example","Demo","Sample","Tests","Spec","Mock","Runner"].some(a=>t.endsWith(a)||t.includes(a)),xa=t=>t.startsWith("_"),ma=t=>t==="_pending",ua="您暂无写入权限,无法保存。如需此权限请联系管理员;请勿擅自修改核心代码或安装包,以免影响团队协作与数据安全。";function Ct(t){var l,o;const s=t==null?void 0:t.response;if((s==null?void 0:s.status)!==403)return null;const a=(l=s.data)==null?void 0:l.code,r=(o=s.data)==null?void 0:o.error;return a==="RECIPE_WRITE_FORBIDDEN"||typeof r=="string"&&r.includes("没权限")?ua:null}const pa="保存过于频繁,请稍后再试。";function Yt(t){var a;const s=t==null?void 0:t.response;return s!=null&&s.data?s.status===403?Ct(t)??null:s.status===429&&((a=s.data)==null?void 0:a.code)==="RECIPE_SAVE_RATE_LIMIT"?pa:null:null}const le=Je.create({baseURL:"/api/v1"});function Gt(t){const s=t.quality||{},a=t.statistics||{},r=t.content||{},l=t.dimensions||{},o=l.trigger||"@"+(t.title||"").replace(/[\s_-]+(.)?/g,(Z,N)=>N?N.toUpperCase():""),d=t.tags||[],c=l.headers||[];let u=`---
2
- `;u+=`title: ${t.title||""}
3
- `,u+=`trigger: ${o}
4
- `,u+=`language: ${t.language||"swift"}
5
- `,u+=`category: ${t.category||"Utility"}
6
- `;const S=t.summaryCn||t.description||"",x=t.summaryEn||"";u+=`summary: ${S}
7
- `,u+=`summary_cn: ${S}
8
- `,x&&(u+=`summary_en: ${x}
9
- `),t.scope&&(u+=`scope: ${t.scope}
10
- `),t.knowledgeType&&(u+=`knowledge_type: ${t.knowledgeType}
11
- `),t.complexity&&(u+=`complexity: ${t.complexity}
12
- `),d.length>0&&(u+=`tags: ${JSON.stringify(d)}
13
- `),c.length>0&&(u+=`headers: ${JSON.stringify(c)}
14
- `);const h=l.difficulty||t.complexity||"";h&&(u+=`difficulty: ${h}
15
- `);const j=s.overall||l.authority||0;j&&(u+=`authority: ${j}
16
- `),u+=`version: ${l.version||"1.0.0"}
17
- `,u+=`status: ${t.status||"draft"}
18
- `;const M=t.updatedAt?t.updatedAt<1e12?t.updatedAt*1e3:t.updatedAt:Date.now();u+=`updatedAt: ${M}
19
- `,u+=`---
20
-
21
- `;const P=r.pattern||"";P&&(u+=`\`\`\`${t.language||"swift"}
22
- ${P}
23
- \`\`\`
24
-
25
- `);const O=r.rationale||"";O&&(u+=`## Architecture Usage
26
-
27
- ${O}
28
-
29
- `);const z=t.usageGuideCn||"",C=t.usageGuideEn||"";z&&(u+=`## AI Context / Usage Guide
30
-
31
- ${z}
32
-
33
- `),C&&(u+=`## AI Context / Usage Guide (EN)
34
-
35
- ${C}
36
-
37
- `);const p=(r.steps||[]).map(Z=>typeof Z=="string"?Z:Z.description||"").join(`
38
- `);p.trim()&&(u+=`## Best Practices
39
-
40
- ${p}
41
-
42
- `);const I=(t.constraints||{}).standards||"";I&&(u+=`## Standards
43
-
44
- ${I}
45
-
46
- `);const W={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:u,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:W}}function ha(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}}function ba(t){let s="swift",a="general",r="",l="",o="",d="",c="",u="",S="",x=[],h=[],j="",M=0,P="1.0.0",O="",z="",C="",E="",p="",I=t;const W=t.match(/^---\n([\s\S]*?)\n---/);if(W){const Z=W[1],N=te=>{const i=Z.match(new RegExp(`^${te}:\\s*(.+)$`,"m"));return i?i[1].trim():null};s=N("language")||s,a=N("category")||a,r=N("title")||r,l=N("trigger")||"",o=N("summary_cn")||N("summary")||o,d=N("summary_en")||"",c=N("knowledge_type")||"",u=N("complexity")||"",S=N("scope")||"",j=N("difficulty")||"",P=N("version")||"1.0.0";const G=N("authority");G&&(M=parseInt(G)||0);const Q=N("tags");if(Q)try{x=JSON.parse(Q)}catch{x=Q.split(",").map(te=>te.trim()).filter(Boolean)}const R=N("headers");if(R)try{h=JSON.parse(R)}catch{h=[R]}const V=t.match(/```[\w]*\n([\s\S]*?)```/);V&&(I=V[1].trim());const q=t.replace(/^---\n[\s\S]*?\n---/,"").trim(),v=q.match(/## (?:AI Context \/ )?Usage Guide(?:\s*\(CN\))?\n\n([\s\S]*?)(?=\n## |$)/);v&&(O=v[1].trim());const _=q.match(/## (?:AI Context \/ )?Usage Guide\s*\(EN\)\n\n([\s\S]*?)(?=\n## |$)/);_&&(z=_[1].trim());const w=q.match(/## Architecture Usage\n\n([\s\S]*?)(?=\n## |$)/);w&&(C=w[1].trim());const D=q.match(/## Best Practices\n\n([\s\S]*?)(?=\n## |$)/);D&&(E=D[1].trim());const K=q.match(/## Standards\n\n([\s\S]*?)(?=\n## |$)/);K&&(p=K[1].trim())}return{title:r,language:s,category:a,trigger:l,summary:o,summaryEn:d,knowledgeType:c,complexity:u,scope:S,tags:x,headers:h,difficulty:j,authority:M,version:P,codePattern:I,usageGuide:O,usageGuideEn:z,rationaleText:C,bestPracticesText:E,standardsText:p}}function ga(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 ie={async fetchData(){var u,S,x,h,j,M,P,O,z;const[t,s,a]=await Promise.all([le.get("/recipes?limit=1000").catch(()=>({data:{success:!0,data:{data:[]}}})),le.get("/candidates?limit=1000").catch(()=>({data:{success:!0,data:{data:[]}}})),le.get("/ai/config").catch(()=>({data:{success:!0,data:{provider:"",model:""}}}))]),l=(((S=(u=t.data)==null?void 0:u.data)==null?void 0:S.data)||((h=(x=t.data)==null?void 0:x.data)==null?void 0:h.items)||[]).map(Gt),o=((M=(j=s.data)==null?void 0:j.data)==null?void 0:M.data)||((O=(P=s.data)==null?void 0:P.data)==null?void 0:O.items)||[],d={};for(const C of o){const p=(C.metadata||{}).targetName||C.category||C.language||"_pending";d[p]||(d[p]={targetName:p,scanTime:C.createdAt,items:[]}),d[p].items.push(ha(C))}const c=((z=a.data)==null?void 0:z.data)||{provider:"",model:""};return{rootSpec:{list:[]},recipes:l,candidates:d,projectRoot:"",watcherStatus:"active",aiConfig:{provider:c.provider||"",model:c.model||""}}},async fetchTargets(){var a;return(((a=(await le.get("/spm/targets")).data)==null?void 0:a.data)||{}).targets||[]},async getTargetFiles(t,s){var l,o;const r=((l=(await le.post("/spm/target-files",{target:t},{signal:s})).data)==null?void 0:l.data)||{};return{files:r.files||[],count:r.total||((o=r.files)==null?void 0:o.length)||0}},async scanTarget(t,s){var o;const r=((o=(await le.post("/spm/scan",{target:t},{signal:s,timeout:6e5})).data)==null?void 0:o.data)||{};return{recipes:r.recipes||r.result||[],scannedFiles:r.scannedFiles||[],message:r.message||""}},async scanProject(t){var r;const a=((r=(await le.post("/spm/scan-project",{},{signal:t,timeout:6e5})).data)==null?void 0:r.data)||{};return{targets:a.targets||[],recipes:a.recipes||[],guardAudit:a.guardAudit||null,scannedFiles:a.scannedFiles||[],partial:a.partial||!1}},async bootstrap(t){var r;const a=((r=(await le.post("/spm/bootstrap",{},{signal:t,timeout:3e5})).data)==null?void 0:r.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},message:a.message||"",aiEnhancement:a.aiEnhancement||null}},async getDepGraph(t){var a;return((a=(await le.get(`/spm/dep-graph?level=${t}`)).data)==null?void 0:a.data)||{}},async syncToXcode(){await le.post("/commands/install")},async refreshProject(){await le.post("/commands/spm-map")},async extractFromPath(t){var r;const a=((r=(await le.post("/extract/path",{relativePath:t})).data)==null?void 0:r.data)||{};return{result:a.result||[],isMarked:a.isMarked||!1}},async extractFromText(t,s){var l;const r=((l=(await le.post("/extract/text",{text:t,...s?{relativePath:s}:{}})).data)==null?void 0:l.data)||{};return Array.isArray(r.result)&&r.result.length>0?r.result[0]:r},async saveRecipe(t,s){var u,S,x,h;const a=ba(s),r=a.title||t.replace(/\.md$/,""),l={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:""},d={};if(a.standardsText){const j=a.standardsText.split(`
47
- `).map(O=>O.trim()).filter(Boolean),M=j.filter(O=>O.startsWith("- ")).map(O=>O.slice(2).trim());M.length>0&&(d.preconditions=M);const P=j.filter(O=>!O.startsWith("- ")&&!O.startsWith("**"));P.length>0&&(d.boundaries=P)}const c={title:r,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:d,dimensions:l};try{const j=await le.get(`/recipes?keyword=${encodeURIComponent(r)}&limit=5`),P=(((S=(u=j.data)==null?void 0:u.data)==null?void 0:S.data)||((h=(x=j.data)==null?void 0:x.data)==null?void 0:h.items)||[]).find(O=>O.title===r);if(P){await le.patch(`/recipes/${P.id}`,c);return}}catch{}await le.post("/recipes",c)},async deleteRecipe(t){var o,d,c,u;const s=t.replace(/\.md$/,""),a=await le.get(`/recipes?keyword=${encodeURIComponent(s)}&limit=5`),r=((d=(o=a.data)==null?void 0:o.data)==null?void 0:d.data)||((u=(c=a.data)==null?void 0:c.data)==null?void 0:u.items)||[],l=r.find(S=>S.title===s)||r[0];if(l!=null&&l.id)await le.delete(`/recipes/${l.id}`);else throw new Error("Recipe not found")},async getRecipeByName(t){var d,c,u,S;const s=t.replace(/\.md$/,""),a=await le.get(`/recipes?keyword=${encodeURIComponent(s)}&limit=5`),r=((c=(d=a.data)==null?void 0:d.data)==null?void 0:c.data)||((S=(u=a.data)==null?void 0:u.data)==null?void 0:S.items)||[];if(r.length===0)throw new Error("Recipe not found");const o=r[0].content||{};return{name:t,content:o.pattern||o.markdown||""}},async setRecipeAuthority(t,s){var o,d,c,u;const a=t.replace(/\.md$/,""),r=await le.get(`/recipes?keyword=${encodeURIComponent(a)}&limit=5`),l=((d=(o=r.data)==null?void 0:o.data)==null?void 0:d.data)||((u=(c=r.data)==null?void 0:c.data)==null?void 0:u.items)||[];l.length>0&&l[0].id&&await le.patch(`/recipes/${l[0].id}/quality`,{codeCompleteness:s,projectAdaptation:s,documentationClarity:s})},async searchRecipes(t){var l;const a=((l=(await le.get(`/search?q=${encodeURIComponent(t)}&type=recipe`)).data)==null?void 0:l.data)||{},r=a.recipes||[];return{results:r.map(o=>({name:o.title||o.name||"",content:(o.content||{}).pattern||(o.content||{}).markdown||""})),total:a.totalResults||r.length}},async deleteCandidate(t){await le.delete(`/candidates/${t}`)},async promoteCandidateToRecipe(t,s){var r;return((r=(await le.post(`/candidates/${t}/promote`,s||{})).data)==null?void 0:r.data)||{recipe:null,candidate:null}},async enrichCandidates(t){var a;return((a=(await le.post("/candidates/enrich",{candidateIds:t})).data)==null?void 0:a.data)||{enriched:0,total:0,results:[]}},async bootstrapRefine(t,s,a){var l;return((l=(await le.post("/candidates/bootstrap-refine",{candidateIds:t,userPrompt:s,dryRun:a},{timeout:3e5})).data)==null?void 0:l.data)||{refined:0,total:0,errors:[],results:[]}},async refinePreview(t,s){var r;return((r=(await le.post("/candidates/refine-preview",{candidateId:t,userPrompt:s},{timeout:12e4})).data)==null?void 0:r.data)||{}},async refineApply(t,s){var r;return((r=(await le.post("/candidates/refine-apply",{candidateId:t,userPrompt:s},{timeout:12e4})).data)==null?void 0:r.data)||{}},async getKnowledgeGraph(t=500){var a;return((a=(await le.get(`/search/graph/all?limit=${t}`)).data)==null?void 0:a.data)||{edges:[],nodeLabels:{}}},async getGraphStats(){var s;return((s=(await le.get("/search/graph/stats")).data)==null?void 0:s.data)||{totalEdges:0,byRelation:{},nodeTypes:[]}},async deleteAllCandidatesInTarget(t){var a;return((a=(await le.post("/candidates/batch-delete",{targetName:t})).data)==null?void 0:a.data)||{deleted:0}},async promoteToCandidate(t,s){var l,o;const a=ga(t,s,"review-promote");return{ok:!0,candidateId:((o=(l=(await le.post("/candidates",a)).data)==null?void 0:l.data)==null?void 0:o.id)||""}},async getCandidateSimilarity(t,s){var r;return((r=(await le.post("/candidates/similarity",{code:t,language:s})).data)==null?void 0:r.data)||{similar:[]}},async getCandidateSimilarityEx(t){var a;return((a=(await le.post("/candidates/similarity",t)).data)==null?void 0:a.data)||{similar:[]}},async getRecipeContentByName(t){var c,u,S,x;const s=t.replace(/\.md$/,""),a=await le.get(`/recipes?keyword=${encodeURIComponent(s)}&limit=5`),r=((u=(c=a.data)==null?void 0:c.data)==null?void 0:u.data)||((x=(S=a.data)==null?void 0:S.data)==null?void 0:x.items)||[],l=r.find(h=>h.title===s)||r[0];if(!l)throw new Error("Recipe not found");const d=Gt(l);return{name:t,content:d.content}},async getAiProviders(){var s;return((s=(await le.get("/ai/providers")).data)==null?void 0:s.data)||[]},async setAiConfig(t,s){var r;return((r=(await le.post("/ai/config",{provider:t,model:s})).data)==null?void 0:r.data)||{provider:t,model:s}},async chat(t,s,a){var o;const l=((o=(await le.post("/ai/chat",{prompt:t,history:s},{signal:a})).data)==null?void 0:o.data)||{};return{text:l.reply||l.text||"",hasContext:l.hasContext}},async summarizeCode(t,s){var r;const a=await le.post("/ai/summarize",{code:t,language:s});return((r=a.data)==null?void 0:r.data)||a.data||{}},async translate(t,s){var l,o;const a=await le.post("/ai/translate",{summary:t,usageGuide:s}),r=((l=a.data)==null?void 0:l.data)||{summary_en:"",usageGuide_en:""};return(o=a.data)!=null&&o.warning&&(r.warning=a.data.warning),r},async semanticSearch(t,s=10){var o;return((((o=(await le.get(`/search?q=${encodeURIComponent(t)}&mode=semantic&limit=${s}`)).data)==null?void 0:o.data)||{}).recipes||[]).map(d=>({name:(d.title||d.name||"")+".md",content:(d.content||{}).pattern||(d.content||{}).markdown||"",similarity:d.similarity||d.score||0,metadata:{type:"recipe",name:(d.title||d.name||"")+".md"}}))},async xcodeSimulateSearch(t){var a;return((a=(await le.post("/search/xcode-simulate",t).catch(()=>({data:{data:{}}}))).data)==null?void 0:a.data)||{}},async contextAwareSearch(t){var a;return((a=(await le.post("/search/context-aware",t).catch(()=>({data:{data:{}}}))).data)==null?void 0:a.data)||{}},async getGuardRules(){var l;const s=((l=(await le.get("/rules?limit=100")).data)==null?void 0:l.data)||{},a=s.data||s.items||[],r={};for(const o of a)r[o.id]=o;return{rules:r}},async getGuardViolations(){var a;const s=((a=(await le.get("/violations")).data)==null?void 0:a.data)||{};return{runs:s.data||s.items||[]}},async clearViolations(){await le.post("/violations/clear")},async generateGuardRule(t){var a;return((a=(await le.post("/violations/rules/generate",t)).data)==null?void 0:a.data)||{}},async saveGuardRule(t){var a;return((a=(await le.post("/rules",t)).data)==null?void 0:a.data)||{}},async insertAtSearchMark(t){return{success:!1}},async searchRecipesForModal(t,s){var o;const r=((o=(await le.get(`/search?q=${encodeURIComponent(t)}&type=recipe`,{signal:s})).data)==null?void 0:o.data)||{},l=r.recipes||[];return{results:l.map(d=>({name:(d.title||d.name||"")+".md",path:"",content:Gt(d).content,qualityScore:(d.quality||{}).overall||0,recommendReason:""})),total:r.totalResults||l.length}}},fa=!1,Mt="auth_token",Pt="auth_user";function ja(){const[t,s]=n.useState(()=>localStorage.getItem(Mt)),[a,r]=n.useState(()=>{try{const S=localStorage.getItem(Pt);return S?JSON.parse(S):null}catch{return null}}),[l,o]=n.useState(!1),d=n.useCallback(async(S,x)=>{var h,j,M,P;o(!0);try{const z=(await Je.post("/api/v1/auth/login",{username:S,password:x})).data;if(z.success){const C=z.data.token,E=z.data.user??{username:S,role:"developer"};return localStorage.setItem(Mt,C),localStorage.setItem(Pt,JSON.stringify(E)),s(C),r(E),{success:!0}}return{success:!1,error:((h=z.error)==null?void 0:h.message)||"登录失败"}}catch(O){return{success:!1,error:((P=(M=(j=O.response)==null?void 0:j.data)==null?void 0:M.error)==null?void 0:P.message)||O.message||"网络错误"}}finally{o(!1)}},[]),c=n.useCallback(()=>{localStorage.removeItem(Mt),localStorage.removeItem(Pt),s(null),r(null)},[]);n.useEffect(()=>{},[]);const u=n.useMemo(()=>!0,[t,a]);return{authEnabled:fa,isAuthenticated:u,isLoading:l,user:a,login:d,logout:c}}const ya={developer_admin:["*"],developer_contributor:["read:*","approve:candidates","reject:candidates","create:recipes","create:candidates","recipe:create","recipe:publish","candidate:create","candidate:approve","candidate:reject","search:query"],visitor:["read:recipes","read:candidates","read:guard_rules","search:query"],cursor_agent:["read:recipes","read:guard_rules","create:candidates","submit:candidates","read:audit_logs:self"],asd_ais:["read:recipes","read:candidates","create:candidates","read:guard_rules"],guard_engine:["read:candidates","read:guard_rules","write:audit_logs"]};function Na(t){const[s,a]=n.useState(()=>"visitor"),[r,l]=n.useState("anonymous"),[o,d]=n.useState("probe"),[c,u]=n.useState(!0),[S,x]=n.useState(null),h=n.useCallback(async()=>{u(!0);try{const z=localStorage.getItem("auth_token"),C={};z&&(C.Authorization=`Bearer ${z}`);const E=await Je.get("/api/v1/auth/probe",{headers:C});if(E.data.success){const p=E.data.data;a(p.role),l(p.user),d(p.mode),x(p.probeCache??null)}}catch{a("visitor")}finally{u(!1)}},[]);n.useEffect(()=>{h()},[t,h]);const j=n.useCallback((z,C)=>{const E=ya[s]||[];if(E.includes("*"))return!0;const p=C?`${z}:${C}`:z;if(E.includes(p))return!0;const I=z.split(":")[0];return!!(E.includes(`${I}:*`)||I==="read"&&E.includes("read:*"))},[s]),M=n.useMemo(()=>s==="developer_admin",[s]),P=n.useMemo(()=>s==="developer_admin"||s==="developer_contributor",[s]),O=n.useMemo(()=>!P,[P]);return{role:s,user:r,mode:o,isLoading:c,isAdmin:M,canWrite:P,isReadOnly:O,can:j,probeCache:S,refresh:h}}const b={xs:12,sm:14,md:16,lg:20,xl:24,xxl:32,xxxl:48},Zt={developer_admin:{label:"管理员",color:"text-emerald-700",bg:"bg-emerald-50 border-emerald-200"},developer_contributor:{label:"贡献者",color:"text-blue-700",bg:"bg-blue-50 border-blue-200"},visitor:{label:"访客",color:"text-slate-500",bg:"bg-slate-100 border-slate-200"},cursor_agent:{label:"Agent",color:"text-purple-700",bg:"bg-purple-50 border-purple-200"}},va={token:Ss,probe:Ht},wa=({activeTab:t,navigateToTab:s,handleRefreshProject:a,candidateCount:r,isDarkMode:l=!1,currentUser:o,currentRole:d,permissionMode:c,onLogout:u})=>{const S=Zt[d||""]||Zt.visitor,x=va[c||"probe"]||Ht;return e.jsxs("aside",{className:`w-64 ${l?"bg-[#252526] border-r border-[#3e3e42]":"bg-white border-r border-slate-200"} flex flex-col shrink-0`,children:[e.jsxs("div",{className:`p-6 border-b ${l?"border-[#3e3e42]":"border-slate-100"} flex items-center gap-3`,children:[e.jsx("div",{className:"w-8 h-8 bg-blue-600 rounded-lg flex items-center justify-center text-white",children:e.jsx(zt,{size:b.lg})}),e.jsx("h1",{className:"font-bold text-lg",children:"AutoSnippet"})]}),e.jsxs("nav",{className:"flex-1 p-4 space-y-2 overflow-y-auto",children:[e.jsxs("button",{type:"button",onClick:()=>s("recipes"),className:`w-full flex items-center gap-3 px-4 py-2 rounded-lg transition-colors ${t==="recipes"?l?"bg-blue-900/30 text-blue-400 font-medium":"bg-blue-50 text-blue-700 font-medium":l?"text-slate-300 hover:bg-slate-700/50":"text-slate-600 hover:bg-slate-50"}`,children:[e.jsx(vs,{size:b.lg}),e.jsx("span",{children:"Recipes"})]}),e.jsxs("button",{type:"button",onClick:()=>s("spm"),className:`w-full flex items-center gap-3 px-4 py-2 rounded-lg transition-colors ${t==="spm"?l?"bg-blue-900/30 text-blue-400 font-medium":"bg-blue-50 text-blue-700 font-medium":l?"text-slate-300 hover:bg-slate-700/50":"text-slate-600 hover:bg-slate-50"}`,children:[e.jsx(ws,{size:b.lg}),e.jsx("span",{children:"SPM Explorer"})]}),e.jsxs("button",{type:"button",onClick:()=>s("candidates"),className:`w-full flex items-center gap-3 px-4 py-2 rounded-lg transition-colors ${t==="candidates"?l?"bg-blue-900/30 text-blue-400 font-medium":"bg-blue-50 text-blue-700 font-medium":l?"text-slate-300 hover:bg-slate-700/50":"text-slate-600 hover:bg-slate-50"}`,children:[e.jsx(Ft,{size:b.lg}),e.jsxs("span",{children:["Candidates (",r,")"]})]}),e.jsxs("button",{type:"button",onClick:()=>s("depgraph"),className:`w-full flex items-center gap-3 px-4 py-2 rounded-lg transition-colors ${t==="depgraph"?l?"bg-blue-900/30 text-blue-400 font-medium":"bg-blue-50 text-blue-700 font-medium":l?"text-slate-300 hover:bg-slate-700/50":"text-slate-600 hover:bg-slate-50"}`,children:[e.jsx(ts,{size:b.lg}),e.jsx("span",{children:"依赖关系图"})]}),e.jsxs("button",{type:"button",onClick:()=>s("knowledgegraph"),className:`w-full flex items-center gap-3 px-4 py-2 rounded-lg transition-colors ${t==="knowledgegraph"?l?"bg-blue-900/30 text-blue-400 font-medium":"bg-blue-50 text-blue-700 font-medium":l?"text-slate-300 hover:bg-slate-700/50":"text-slate-600 hover:bg-slate-50"}`,children:[e.jsx(Ot,{size:b.lg}),e.jsx("span",{children:"知识图谱"})]}),e.jsxs("button",{type:"button",onClick:()=>s("guard"),className:`w-full flex items-center gap-3 px-4 py-2 rounded-lg transition-colors ${t==="guard"?l?"bg-blue-900/30 text-blue-400 font-medium":"bg-blue-50 text-blue-700 font-medium":l?"text-slate-300 hover:bg-slate-700/50":"text-slate-600 hover:bg-slate-50"}`,children:[e.jsx(Ve,{size:b.lg}),e.jsx("span",{children:"Guard"})]}),e.jsxs("button",{type:"button",onClick:()=>s("ai"),className:`w-full flex items-center gap-3 px-4 py-2 rounded-lg transition-colors ${t==="ai"?l?"bg-blue-900/30 text-blue-400 font-medium":"bg-blue-50 text-blue-700 font-medium":l?"text-slate-300 hover:bg-slate-700/50":"text-slate-600 hover:bg-slate-50"}`,children:[e.jsx(Bt,{size:b.lg}),e.jsx("span",{children:"AI Assistant"})]}),e.jsxs("button",{type:"button",onClick:()=>s("editor"),className:`w-full flex items-center gap-3 px-4 py-2 rounded-lg transition-colors ${t==="editor"?l?"bg-blue-900/30 text-blue-400 font-medium":"bg-blue-50 text-blue-700 font-medium":l?"text-slate-300 hover:bg-slate-700/50":"text-slate-600 hover:bg-slate-50"}`,children:[e.jsx(pt,{size:b.lg}),e.jsx("span",{children:"编辑器(测试)"})]}),e.jsxs("button",{type:"button",onClick:()=>s("help"),className:`w-full flex items-center gap-3 px-4 py-2 rounded-lg transition-colors ${t==="help"?l?"bg-blue-900/30 text-blue-400 font-medium":"bg-blue-50 text-blue-700 font-medium":l?"text-slate-300 hover:bg-slate-700/50":"text-slate-600 hover:bg-slate-50"}`,children:[e.jsx(Cs,{size:b.lg}),e.jsx("span",{children:"使用说明"})]})]}),e.jsxs("div",{className:`p-4 ${l?"border-t border-[#3e3e42]":"border-t border-slate-100"}`,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 ${l?"bg-slate-700/30 border-slate-600 text-slate-400":S.bg+" "+S.color}`,children:[e.jsx(x,{size:b.xs}),e.jsx("span",{children:c==="token"?"登录":"探针"}),e.jsx("span",{className:"mx-0.5",children:"·"}),e.jsx(ks,{size:b.xs}),e.jsx("span",{children:S.label})]}),o&&e.jsxs("div",{className:`flex items-center justify-between mb-3 px-2 py-1.5 rounded-lg ${l?"bg-slate-700/30":"bg-slate-50"}`,children:[e.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[e.jsx(Is,{size:b.sm,className:l?"text-slate-400":"text-slate-500"}),e.jsx("span",{className:`text-xs font-medium truncate ${l?"text-slate-300":"text-slate-600"}`,children:o})]}),u&&e.jsx("button",{onClick:u,title:"登出",className:`shrink-0 p-1 rounded transition-colors ${l?"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($s,{size:b.sm})})]}),e.jsxs("button",{onClick:a,className:`w-full flex items-center justify-center gap-2 text-[10px] font-bold ${l?"text-slate-400 hover:text-blue-400":"text-slate-400 hover:text-blue-600"} uppercase transition-colors`,children:[e.jsx(nt,{size:b.xs})," Refresh Project"]})]})]})},Ca=({searchQuery:t,setSearchQuery:s,setShowCreateModal:a,handleSyncToXcode:r,aiConfig:l,onSemanticSearchResults:o,onBeforeAiSwitch:d,onAiConfigChange:c,isDarkMode:u=!1})=>{const[S,x]=n.useState(!1),[h,j]=n.useState(!1),[M,P]=n.useState([]),[O,z]=n.useState(!1),C=n.useRef(null);n.useEffect(()=>{h&&M.length===0&&ie.getAiProviders().then(I=>P(I)).catch(()=>{})},[h,M.length]),n.useEffect(()=>{const I=W=>{C.current&&!C.current.contains(W.target)&&j(!1)};return document.addEventListener("click",I),()=>document.removeEventListener("click",I)},[]);const E=async()=>{if(t){x(!0);try{const I=await ie.semanticSearch(t);o&&o(I)}catch(I){console.error("Semantic search failed",I),alert("语义搜索失败。请确保已运行 asd embed 构建索引。")}finally{x(!1)}}},p=async I=>{z(!0);try{d==null||d(),await ie.setAiConfig(I.id,I.defaultModel),j(!1),c&&c()}catch(W){console.error("AI config update failed",W),alert("切换 AI 失败,请检查项目根目录是否可写。")}finally{z(!1)}};return e.jsxs("header",{className:`h-16 ${u?"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(it,{className:`absolute left-3 top-1/2 -translate-y-1/2 ${u?"text-slate-500":"text-slate-400"}`,size:b.md}),e.jsx("input",{type:"text",placeholder:"Search knowledge...",className:`w-full pl-10 pr-4 py-2 ${u?"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:I=>s(I.target.value),onKeyDown:I=>I.key==="Enter"&&E()})]}),e.jsxs("button",{onClick:E,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:b.sm,className:"animate-spin"}):e.jsx(_s,{size:b.sm}),"Semantic"]})]}),e.jsxs("div",{className:"flex items-center gap-4",children:[l&&e.jsxs("div",{className:"relative",ref:C,children:[e.jsxs("button",{type:"button",onClick:I=>{I.stopPropagation(),j(W=>!W)},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(At,{size:b.sm}),l.provider," / ",l.model,e.jsx(Qe,{size:b.xs,className:h?"rotate-180":""})]}),h&&e.jsxs("div",{className:"absolute top-full right-0 mt-1 py-1 rounded-lg border border-slate-200 bg-white shadow-lg z-50 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:"API Key 仍从 .env 读取"}),M.length===0?e.jsx("div",{className:"px-3 py-2 text-xs text-slate-400",children:"加载中..."}):M.map(I=>e.jsxs("button",{type:"button",disabled:O,onClick:()=>p(I),className:`w-full text-left px-3 py-2 text-sm hover:bg-slate-50 flex items-center justify-between ${l.provider===I.id?"bg-blue-50 text-blue-700 font-medium":"text-slate-700"}`,children:[e.jsx("span",{children:I.label}),l.provider===I.id&&e.jsx("span",{className:"text-xs",children:"✓"})]},I.id))]})]}),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(ss,{size:b.md})," New Recipe"]}),e.jsxs("button",{onClick:r,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(nt,{size:b.md})," Sync to Xcode"]})]})]})},Sa=({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(De).map(([a,r])=>{const l=r.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
48
- ${o?`${r.bg} ${r.color} ${r.border} shadow-sm scale-105`:"bg-white text-slate-400 border-slate-100 hover:border-slate-200 hover:text-slate-600"}`,children:[e.jsx(l,{size:b.xs}),a]},a)})})}),ms=({currentPage:t,totalPages:s,totalItems:a,pageSize:r,onPageChange:l,onPageSizeChange:o,pageSizeOptions:d=[12,24,48,96]})=>{if(s<=1&&a<=d[0])return null;const c=(t-1)*r+1,u=Math.min(t*r,a),S=()=>{const x=[];if(s<=7)for(let j=1;j<=s;j++)x.push(j);else if(t<=3){for(let j=1;j<=5;j++)x.push(j);x.push("..."),x.push(s)}else if(t>=s-2){x.push(1),x.push("...");for(let j=s-5+1;j<=s;j++)x.push(j)}else{x.push(1),x.push("...");for(let j=t-1;j<=t+1;j++)x.push(j);x.push("..."),x.push(s)}return x};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:["显示 ",c,"-",u,",共 ",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:r,onChange:x=>o(Number(x.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:d.map(x=>e.jsx("option",{value:x,children:x},x))}),e.jsx("span",{className:"text-sm text-slate-500",children:"条"})]})]}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("button",{onClick:()=>l(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(As,{size:b.md,className:"text-slate-600"})}),e.jsx("button",{onClick:()=>l(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(zs,{size:b.md,className:"text-slate-600"})}),e.jsx("div",{className:"flex items-center gap-1 mx-2",children:S().map((x,h)=>typeof x=="number"?e.jsx("button",{onClick:()=>l(x),className:`min-w-[32px] h-8 px-2 rounded-md text-sm font-medium transition-colors ${t===x?"bg-blue-600 text-white":"hover:bg-slate-100 text-slate-600"}`,children:x},h):e.jsx("span",{className:"px-1 text-slate-400",children:x},h))}),e.jsx("button",{onClick:()=>l(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(et,{size:b.md,className:"text-slate-600"})}),e.jsx("button",{onClick:()=>l(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(Es,{size:b.md,className:"text-slate-600"})})]})]})},ka={rule:{label:"Rule",color:"text-red-700",bg:"bg-red-50",border:"border-red-200",icon:Ve},pattern:{label:"Pattern",color:"text-violet-700",bg:"bg-violet-50",border:"border-violet-200",icon:as},fact:{label:"Fact",color:"text-cyan-700",bg:"bg-cyan-50",border:"border-cyan-200",icon:ot}},Ia={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"}},$a=({recipes:t,openRecipeEdit:s,handleDeleteRecipe:a,currentPage:r,onPageChange:l,pageSize:o,onPageSizeChange:d})=>{const[c,u]=n.useState(1),[S,x]=n.useState(12),h=r??c,j=o??S,M=l??u,P=d?p=>d(p):p=>{x(p),u(1)};n.useEffect(()=>{r==null&&u(1)},[t.length,r]);const O=Math.ceil(t.length/j),z=(h-1)*j,C=t.slice(z,z+j),E=p=>{M(p),window.scrollTo({top:0,behavior:"smooth"})};return e.jsxs("div",{children:[e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-6",children:C.map(p=>{var R,V,q,v,_,w;const I=p.name||p.title||"Untitled",W=typeof p.content=="string"?p.content:((R=p.content)==null?void 0:R.pattern)||((V=p.content)==null?void 0:V.markdown)||JSON.stringify(p.content,null,2),Z=p.description||((q=p.v2Content)==null?void 0:q.rationale)||((v=p.v2Content)==null?void 0:v.pattern)||(typeof W=="string"?W:""),N=p.kind?ka[p.kind]:null,G=(N==null?void 0:N.icon)||Rs,Q=Ia[p.status||""]||null;return e.jsxs("div",{className:"bg-white p-6 rounded-xl border border-slate-200 shadow-sm hover:shadow-md transition-all group relative",children:[e.jsxs("div",{className:"absolute top-4 right-4 flex gap-2 opacity-0 group-hover:opacity-100 transition-opacity",children:[e.jsx("button",{onClick:D=>{D.stopPropagation(),s(p)},className:"p-1.5 bg-slate-50 text-slate-400 hover:text-blue-600 hover:bg-blue-50 rounded-md transition-colors",children:e.jsx(pt,{size:b.sm})}),e.jsx("button",{onClick:D=>{D.stopPropagation(),a(p.name||p.id)},className:"p-1.5 bg-slate-50 text-slate-400 hover:text-red-600 hover:bg-red-50 rounded-md transition-colors",children:e.jsx(Et,{size:b.sm})})]}),e.jsxs("div",{onClick:()=>s(p),className:"cursor-pointer",children:[e.jsxs("div",{className:"flex justify-between items-center mb-2 pr-12",children:[e.jsx("h3",{className:"font-bold text-slate-900 truncate",children:I}),e.jsxs("div",{className:"flex items-center gap-1.5 shrink-0",children:[N&&e.jsxs("span",{className:`text-[8px] font-bold px-1.5 py-0.5 rounded uppercase flex items-center gap-1 border ${N.bg} ${N.color} ${N.border}`,children:[e.jsx(G,{size:b.xs}),N.label]}),(()=>{var i,f;const D=p.category||(typeof W=="string"?(f=(i=W.match(/category:\s*(.*)/))==null?void 0:i[1])==null?void 0:f.trim():null)||"Utility",K=De[D]||De.Utility,te=K.icon;return e.jsxs("span",{className:`text-[8px] font-bold px-1.5 py-0.5 rounded uppercase flex items-center gap-1 border ${K.bg} ${K.color} ${K.border}`,children:[e.jsx(te,{size:b.xs}),D]})})(),Q&&p.status!=="active"&&p.status!=="published"&&e.jsx("span",{className:`text-[8px] font-bold px-1.5 py-0.5 rounded uppercase border ${Q.bg} ${Q.color} ${Q.border}`,children:p.status}),typeof W=="string"&&W.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"})]})]}),(p.knowledgeType||p.language||p.tags&&p.tags.length>0)&&e.jsxs("div",{className:"flex flex-wrap items-center gap-1.5 mb-2",children:[p.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:p.knowledgeType}),p.language&&e.jsx("span",{className:"text-[9px] font-medium px-1.5 py-0.5 rounded bg-slate-100 text-slate-500 uppercase",children:p.language}),p.tags&&p.tags.length>0&&p.tags.slice(0,4).map((D,K)=>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(Ts,{size:8}),D]},K)),p.tags&&p.tags.length>4&&e.jsxs("span",{className:"text-[9px] text-slate-400",children:["+",p.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:["权威 ",p.stats!=null?p.stats.authority:"—"]}),e.jsx("span",{children:"·"}),e.jsx("span",{children:p.stats!=null?`g:${p.stats.guardUsageCount} h:${p.stats.humanUsageCount} a:${p.stats.aiUsageCount}`:"g:0 h:0 a:0"}),e.jsx("span",{children:"·"}),e.jsxs("span",{children:["综合分 ",((_=p.stats)==null?void 0:_.authorityScore)!=null?p.stats.authorityScore.toFixed(2):"—"]}),((w=p.stats)==null?void 0:w.lastUsedAt)&&e.jsxs(e.Fragment,{children:[e.jsx("span",{children:"·"}),e.jsxs("span",{children:["最近 ",new Date(p.stats.lastUsedAt).toLocaleDateString()]})]})]}),e.jsx("div",{className:"text-xs text-slate-500 bg-slate-50 p-4 rounded-lg overflow-hidden line-clamp-6 font-mono whitespace-pre-wrap",children:Z}),(p.relations||p.constraints)&&e.jsxs("div",{className:"flex flex-wrap items-center gap-2 mt-2",children:[p.relations&&Object.entries(p.relations).some(([,D])=>Array.isArray(D)&&D.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(p.relations).flat().length]}),p.constraints&&(()=>{var K,te,i,f;const D=(((K=p.constraints.guards)==null?void 0:K.length)||0)+(((te=p.constraints.boundaries)==null?void 0:te.length)||0)+(((i=p.constraints.preconditions)==null?void 0:i.length)||0)+(((f=p.constraints.sideEffects)==null?void 0:f.length)||0);return D>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:["约束 ",D]}):null})()]})]})]},I)})}),e.jsx(ms,{currentPage:h,totalPages:O,totalItems:t.length,pageSize:j,onPageChange:E,onPageSizeChange:P})]})},_a=()=>{const[t,s]=n.useState(new Set(["quick-start"])),a=l=>{const o=new Set(t);o.has(l)?o.delete(l):o.add(l),s(o)},r=({id:l,title:o,icon:d,children:c})=>{const u=t.has(l);return e.jsxs("section",{className:"border border-slate-200 rounded-lg overflow-hidden",children:[e.jsxs("button",{onClick:()=>a(l),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:[d,e.jsx("h2",{className:"text-lg font-bold text-slate-800",children:o})]}),u?e.jsx(Qe,{size:b.lg}):e.jsx(et,{size:b.lg})]}),u&&e.jsx("div",{className:"p-4 bg-white",children:c})]})};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(ot,{size:b.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 与项目知识库:Gateway 统一控制平面 + Constitution 宪法体系 + .md Source of Truth"}),e.jsx("p",{className:"text-slate-400 text-sm mt-2",children:"Node.js ≥ 20 · 31 MCP 工具 · 10 Skills · 27 Gateway Actions"}),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(r,{id:"quick-start",title:"快速开始",icon:e.jsx(Nt,{size:b.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",`
49
- `,"cd your-project",`
50
- `,"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(r,{id:"concepts",title:"核心概念",icon:e.jsx(es,{size:b.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:"10 个 Skills 理解规范;31 个 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(Gs,{size:b.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(Be,{size:b.lg}),"Snippet(代码片段)"]}),e.jsx("p",{className:"text-green-800 text-sm mb-3",children:"Xcode 代码补全片段"}),e.jsxs("ul",{className:"text-green-700 text-xs space-y-1 list-disc list-inside",children:[e.jsx("li",{children:"触发:在 Xcode 输入 trigger 自动补全"}),e.jsx("li",{children:"关联:通常与 Recipe 一一对应"}),e.jsxs("li",{children:[e.jsx("code",{className:"bg-green-100 px-1 rounded",children:"asd extract"})," 同步到 Xcode"]})]})]}),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(Ms,{size:b.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(Vt,{size:b.lg}),"Gateway(控制平面)"]}),e.jsx("p",{className:"text-indigo-800 text-sm mb-3",children:"V2 统一调度中枢"}),e.jsxs("ul",{className:"text-indigo-700 text-xs space-y-1 list-disc list-inside",children:[e.jsx("li",{children:"27 个 Action:validate → permission → dispatch"}),e.jsx("li",{children:"Constitution 宪法 P1-P4 优先级验证"}),e.jsx("li",{children:"6 角色权限 + 能力探测(git write)"})]})]}),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(it,{size:b.lg}),"向量索引(Context)"]}),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.jsxs("li",{children:[e.jsx("code",{className:"bg-amber-100 px-1 rounded",children:"asd embed"})," 或启动时自动构建"]}),e.jsx("li",{children:"BM25 + keyword + semantic 混合检索"}),e.jsx("li",{children:"用于搜索、相似度匹配、推荐"})]})]}),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(Ve,{size:b.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.jsxs("li",{children:[e.jsx("code",{className:"bg-rose-100 px-1 rounded",children:"asd compliance"})," 生成合规报告"]})]})]})]})]}),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(r,{id:"features",title:"核心功能",icon:e.jsx(Be,{size:b.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(zt,{size:b.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(it,{size:b.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:"混合搜索"}),":BM25 + keyword + semantic 三路融合"]}),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"}),":31 个工具按需检索知识库"]}),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(Ve,{size:b.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:"合规报告"}),":",e.jsx("code",{className:"bg-slate-100 px-1 rounded text-xs",children:"asd compliance"})," P1-P4 评分"]}),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(nt,{size:b.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.jsx("code",{className:"bg-slate-100 px-1 rounded text-xs",children:"asd embed"})]}),e.jsxs("li",{children:[e.jsx("strong",{children:"依赖图"}),":",e.jsx("code",{className:"bg-slate-100 px-1 rounded text-xs",children:"asd spm-map"})]})]})]})]})}),e.jsxs(r,{id:"editor-directives",title:"编辑器指令",icon:e.jsx(Kt,{size:b.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.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:"// as:c"})]}),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:"// as:s"})]}),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:"// as:a"})]}),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(r,{id:"cursor-integration",title:"Cursor AI 集成",icon:e.jsx(Bt,{size:b.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(l=>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:l.name}),e.jsx("p",{className:"text-xs text-slate-500 mt-0.5",children:l.desc})]},l.name))})]}),e.jsxs("div",{className:"mb-5",children:[e.jsx("h3",{className:"font-semibold text-slate-800 mb-3",children:"31 个 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 font-medium",children:"bootstrap"}),e.jsx("td",{className:"px-3 py-2",children:e.jsx("code",{children:"bootstrap_knowledge"})}),e.jsx("td",{className:"px-3 py-2 text-center",children:"1"})]})]})]})}),e.jsx("p",{className:"text-xs text-slate-500 mt-2",children:"其中 7 个写操作工具(submit_candidate、submit_candidates、submit_draft_recipes、enrich_candidates、guard_check、guard_audit_files、scan_project)通过 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(r,{id:"v2-architecture",title:"V2 架构",icon:e.jsx(rt,{size:b.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(Vt,{size:b.lg,className:"text-indigo-600"}),e.jsx("h3",{className:"font-semibold text-slate-800",children:"Gateway 控制平面"})]}),e.jsx("p",{className:"text-slate-600 text-sm mb-2",children:"所有写操作经过统一流水线:"}),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:"validate → permission → constitution"}),e.jsx("p",{children:"→ plugin(pre) → handler → plugin(post)"}),e.jsx("p",{children:"→ audit"})]}),e.jsx("p",{className:"text-slate-500 text-xs mt-2",children:"27 个 Action 跨 candidate / recipe / guard_rule / search 四域"})]}),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(Ve,{size:b.lg,className:"text-indigo-600"}),e.jsx("h3",{className:"font-semibold text-slate-800",children:"Constitution 宪法体系"})]}),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:"治理层"}),e.jsx("span",{className:"text-slate-600",children:"P1 数据完整 → P2 人工监督 → P3 AI 透明 → P4 有用性"})]}),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:"角色层"}),e.jsx("span",{className:"text-slate-600",children:"cursor_agent · asd_ais · guard_engine · developer_admin · contributor · visitor"})]}),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:"能力层"}),e.jsx("span",{className:"text-slate-600",children:"git push --dry-run 探测 → 自动分配角色,24h TTL 缓存"})]})]})]}),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(Ps,{size:b.lg,className:"text-indigo-600"}),e.jsx("h3",{className:"font-semibold text-slate-800",children:"ChatAgent 统一 AI 入口"})]}),e.jsx("p",{className:"text-slate-600 text-sm mb-2",children:"ReAct 循环(最多 6 轮迭代):"}),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:"工具集"}),":31 个工具(查询/AI分析/Guard安全/生命周期/质量反馈/知识图谱/基础设施)"]}),e.jsxs("p",{children:[e.jsx("strong",{children:"任务集"}),":5 个预定义任务(check_and_submit / discover_all_relations / full_enrich / quality_audit / guard_full_scan)"]}),e.jsxs("p",{children:[e.jsx("strong",{children:"调用链"}),":HTTP API Route / 内部自动化 Service → ChatAgent → prompt → AI 推理 → 工具调用 → 结果聚合"]}),e.jsxs("p",{children:[e.jsx("strong",{children:"调用源"}),":HTTP API (11 端点) / CreateHandler / DraftHandler / SpmService。MCP·CLI·Skills 不经过 ChatAgent"]})]})]}),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(ts,{size:b.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 × 31 工具"})]}),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 × ~91 端点"})]}),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"})]}),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:"10 个 Cursor/Copilot"})]})]})]})]})}),e.jsx(r,{id:"cli-reference",title:"命令行速查",icon:e.jsx(Kt,{size:b.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:"Recipe/Snippet 管理"}),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:"// as:create -c"}),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 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 extract"}),e.jsx("span",{className:"text-slate-500 text-xs",children:"同步到 Xcode"})]}),e.jsxs("div",{className:"flex justify-between bg-slate-50 px-3 py-2 rounded",children:[e.jsx("code",{children:"asd candidate"}),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 [keyword]"}),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 [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 ais [Target]"}),e.jsx("span",{className:"text-slate-500 text-xs",children:"AI 扫描"})]}),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",{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 compliance"}),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 embed"}),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 spm-map"}),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 install:full"}),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"})," 检查环境"]})})]})},Aa={objectivec:"objectivec",objc:"objectivec","objective-c":"objectivec","obj-c":"objectivec",swift:"swift",markdown:"markdown",md:"markdown"},Ze=({code:t,language:s="text",className:a="",showLineNumbers:r=!1})=>{const l=Aa[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(ds,{language:l,style:xs,showLineNumbers:r,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 Ut(t){return!t||typeof t!="string"?t:t.replace(/^---\r?\n[\s\S]*?\r?\n---\r?\n?/,"").trim()||t}const We=({content:t,className:s="",showLineNumbers:a=!1,stripFrontmatter:r=!1})=>{const l=c=>!c||typeof c!="string"?c:c.replace(/\\\\n/g,`
51
- `),o=c=>!c||typeof c!="string"?c:c.replace(/([^\n])\n(?!\n)/g,`$1
52
- `);let d=r?Ut(t):t;return d=l(d),d=o(d),e.jsx("div",{className:`markdown-body text-slate-700 ${s}`,children:e.jsx(ra,{components:{code({node:c,className:u,children:S,...x}){const h=/language-(\w+)/.exec(u||"");return String(S).includes(`
53
- `)&&h?e.jsx(Ze,{code:String(S).replace(/\n$/,""),language:h[1],showLineNumbers:a}):e.jsx("code",{className:"px-1.5 py-0.5 bg-slate-100 text-slate-800 rounded text-sm font-mono",...x,children:S})},p:({children:c})=>e.jsx("p",{className:"mb-3 last:mb-0",children:c}),h1:({children:c})=>e.jsx("h1",{className:"text-xl font-bold mb-2 mt-4 first:mt-0",children:c}),h2:({children:c})=>e.jsx("h2",{className:"text-lg font-bold mb-2 mt-4",children:c}),h3:({children:c})=>e.jsx("h3",{className:"text-base font-bold mb-1 mt-3",children:c}),ul:({children:c})=>e.jsx("ul",{className:"list-disc list-inside mb-3 space-y-1",children:c}),ol:({children:c})=>e.jsx("ol",{className:"list-decimal list-inside mb-3 space-y-1",children:c}),blockquote:({children:c})=>e.jsx("blockquote",{className:"border-l-4 border-slate-200 pl-4 my-3 text-slate-600 italic",children:c}),a:({href:c,children:u})=>e.jsx("a",{href:c,className:"text-blue-600 hover:underline",target:"_blank",rel:"noopener noreferrer",children:u})},children:d})})},dt=()=>Math.random().toString(36).substring(2,10),za={emerald:{iconBg:"from-emerald-50 to-teal-50",iconBorder:"border-emerald-100",iconText:"text-emerald-600",sendBtn:"from-emerald-500 to-teal-600 hover:from-emerald-600 hover:to-teal-700",focusRing:"focus:ring-emerald-200 focus:border-emerald-400",userBubble:"bg-emerald-600",assistantIcon:"text-emerald-500",assistantLabel:"text-emerald-600",loadingIcon:"text-emerald-500",suggestionHover:"hover:bg-emerald-50 hover:text-emerald-700 hover:border-emerald-200",emptyIconBg:"bg-emerald-50 border-emerald-100",emptyIconColor:"text-emerald-500"},blue:{iconBg:"from-blue-50 to-indigo-50",iconBorder:"border-blue-100",iconText:"text-blue-600",sendBtn:"from-blue-500 to-indigo-600 hover:from-blue-600 hover:to-indigo-700",focusRing:"focus:ring-blue-200 focus:border-blue-400",userBubble:"bg-blue-600",assistantIcon:"text-blue-500",assistantLabel:"text-blue-600",loadingIcon:"text-blue-500",suggestionHover:"hover:bg-blue-50 hover:text-blue-700 hover:border-blue-200",emptyIconBg:"bg-blue-50 border-blue-100",emptyIconColor:"text-blue-500"},violet:{iconBg:"from-violet-50 to-purple-50",iconBorder:"border-violet-100",iconText:"text-violet-600",sendBtn:"from-violet-500 to-purple-600 hover:from-violet-600 hover:to-purple-700",focusRing:"focus:ring-violet-200 focus:border-violet-400",userBubble:"bg-violet-600",assistantIcon:"text-violet-500",assistantLabel:"text-violet-600",loadingIcon:"text-violet-500",suggestionHover:"hover:bg-violet-50 hover:text-violet-700 hover:border-violet-200",emptyIconBg:"bg-violet-50 border-violet-100",emptyIconColor:"text-violet-500"},amber:{iconBg:"from-amber-50 to-orange-50",iconBorder:"border-amber-100",iconText:"text-amber-600",sendBtn:"from-amber-500 to-orange-600 hover:from-amber-600 hover:to-orange-700",focusRing:"focus:ring-amber-200 focus:border-amber-400",userBubble:"bg-amber-600",assistantIcon:"text-amber-500",assistantLabel:"text-amber-600",loadingIcon:"text-amber-500",suggestionHover:"hover:bg-amber-50 hover:text-amber-700 hover:border-amber-200",emptyIconBg:"bg-amber-50 border-amber-100",emptyIconColor:"text-amber-500"}},Ea=({title:t,titleBadge:s,subtitle:a,headerIcon:r,widthClass:l="w-[680px] max-w-[90vw]",themeColor:o="emerald",context:d,defaultCodeExpanded:c=!0,messages:u,loading:S=!1,loadingText:x="AI 正在处理...",emptyTitle:h="输入指令开始对话",emptyDescription:j="描述你希望执行的操作,AI 将为你处理。",suggestions:M,emptyIcon:P,assistantName:O="AI 助手",renderMessageExtra:z,placeholder:C="输入指令...",inputHint:E="Enter 发送 · Shift+Enter 换行",inputDisabled:p=!1,onSend:I,onClose:W,onSuggestionClick:Z,renderActions:N,children:G})=>{const[Q,R]=n.useState(""),[V,q]=n.useState(c),v=n.useRef(null),_=n.useRef(null),w=za[o];n.useEffect(()=>{var i;(i=v.current)==null||i.scrollIntoView({behavior:"smooth"})},[u]),n.useEffect(()=>{setTimeout(()=>{var i;return(i=_.current)==null?void 0:i.focus()},300)},[]);const D=n.useCallback(()=>{if(!Q.trim()||S||p)return;const i=Q.trim();R(""),I(i)},[Q,S,p,I]),K=n.useCallback(i=>{i.key==="Enter"&&!i.shiftKey&&(i.preventDefault(),D())},[D]),te=n.useCallback(i=>{var f;Z?Z(i):(R(i),(f=_.current)==null||f.focus())},[Z]);return e.jsxs("div",{className:"fixed inset-0 z-50 flex",children:[e.jsx("div",{className:"flex-1 bg-black/30 backdrop-blur-sm",onClick:W}),e.jsxs("div",{className:`${l} bg-white shadow-2xl flex flex-col animate-slide-in-right`,children:[e.jsxs("div",{className:"px-5 py-3 border-b border-slate-200 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 ${w.iconBg} border ${w.iconBorder} flex items-center justify-center`,children:r||e.jsx(Bt,{className:w.iconText,size:18})}),e.jsxs("div",{children:[e.jsxs("h3",{className:"text-sm font-bold text-slate-800 flex items-center gap-2",children:[t,s&&e.jsx("span",{className:`text-[10px] px-2 py-0.5 rounded-full bg-emerald-50 ${w.assistantLabel} font-medium`,children:s})]}),a&&e.jsx("p",{className:"text-[11px] text-slate-400 truncate max-w-[400px]",children:a})]})]}),e.jsx("button",{onClick:W,className:"p-2 hover:bg-slate-100 rounded-lg transition-colors",children:e.jsx(Ke,{size:18,className:"text-slate-400"})})]}),d&&e.jsxs("div",{className:"border-b border-slate-100 bg-slate-50/50 shrink-0",children:[e.jsx("div",{className:"px-5 py-3",children:e.jsxs("div",{className:"flex items-start gap-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("span",{className:"text-xs font-bold text-slate-700 truncate",children:d.title}),d.badge&&e.jsx("span",{className:"text-[10px] px-1.5 py-0.5 rounded bg-blue-50 text-blue-600 border border-blue-100",children:d.badge})]}),d.subtitle&&e.jsx("p",{className:"text-[11px] text-slate-500 line-clamp-2 leading-relaxed",children:d.subtitle}),d.tags&&d.tags.length>0&&e.jsxs("div",{className:"flex items-center gap-1 mt-1.5 flex-wrap",children:[d.tags.slice(0,8).map(i=>e.jsx("span",{className:"text-[10px] px-1.5 py-0.5 rounded bg-slate-100 text-slate-500",children:i},i)),d.tags.length>8&&e.jsxs("span",{className:"text-[10px] text-slate-400",children:["+",d.tags.length-8]})]})]}),d.indicator&&e.jsxs("div",{className:"text-center shrink-0",children:[e.jsx("div",{className:"text-[10px] text-slate-400",children:d.indicator.label}),e.jsx("div",{className:"text-sm font-bold text-slate-700",children:d.indicator.value})]})]})}),d.code&&e.jsxs("div",{className:"border-t border-slate-200/60",children:[e.jsxs("button",{onClick:()=>q(i=>!i),className:"w-full px-5 py-2 flex items-center gap-1.5 text-[11px] font-medium text-slate-500 hover:text-slate-700 hover:bg-slate-100/50 transition-colors",children:[e.jsx(ls,{size:12}),e.jsx("span",{children:d.codeLabel||"文档内容"}),e.jsx(Qe,{size:12,className:`ml-auto transition-transform ${V?"":"-rotate-90"}`})]}),V&&e.jsx("div",{className:"px-5 pb-3",children:e.jsx("pre",{className:"text-[11px] text-slate-600 bg-slate-100/80 border border-slate-200/60 rounded-lg p-3 overflow-auto max-h-52 font-mono leading-relaxed whitespace-pre-wrap break-words scrollbar-light",children:d.code})})]})]}),e.jsxs("div",{className:"flex-1 overflow-y-auto p-5 space-y-4 min-h-0 scrollbar-light",children:[u.length===0&&e.jsxs("div",{className:"flex flex-col items-center justify-center h-full text-center py-12",children:[e.jsx("div",{className:`w-14 h-14 rounded-2xl ${w.emptyIconBg} border flex items-center justify-center mb-4`,children:P||e.jsxs("svg",{className:w.emptyIconColor,width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"m12 3-1.912 5.813a2 2 0 0 1-1.275 1.275L3 12l5.813 1.912a2 2 0 0 1 1.275 1.275L12 21l1.912-5.813a2 2 0 0 1 1.275-1.275L21 12l-5.813-1.912a2 2 0 0 1-1.275-1.275L12 3Z"}),e.jsx("path",{d:"M5 3v4"}),e.jsx("path",{d:"M19 17v4"}),e.jsx("path",{d:"M3 5h4"}),e.jsx("path",{d:"M17 19h4"})]})}),e.jsx("h4",{className:"text-sm font-bold text-slate-700 mb-1",children:h}),e.jsx("p",{className:"text-xs text-slate-400 max-w-sm leading-relaxed mb-4",children:j}),M&&M.length>0&&e.jsx("div",{className:"flex flex-wrap gap-2 justify-center",children:M.map(i=>e.jsx("button",{onClick:()=>te(i),className:`text-[11px] px-3 py-1.5 rounded-lg bg-slate-100 text-slate-600 ${w.suggestionHover} transition-colors border border-transparent`,children:i},i))})]}),u.map(i=>e.jsx("div",{className:`flex ${i.role==="user"?"justify-end":"justify-start"}`,children:e.jsxs("div",{className:`max-w-[95%] ${i.role==="user"?`${w.userBubble} text-white rounded-2xl rounded-tr-md px-4 py-2.5`:i.role==="system"?"bg-slate-50 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:[i.role==="assistant"&&e.jsxs("div",{className:"flex items-center gap-1.5 mb-2",children:[e.jsx(Dt,{size:14,className:w.assistantIcon}),e.jsx("span",{className:`text-[11px] font-bold ${w.assistantLabel}`,children:O})]}),e.jsx("p",{className:`text-xs leading-relaxed whitespace-pre-wrap ${i.role==="user"?"":i.role==="system"?"text-slate-500":"text-slate-700"}`,children:i.content}),z==null?void 0:z(i)]})},i.id)),S&&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 ${w.loadingIcon}`}),e.jsx("span",{className:"text-xs text-slate-500",children:x})]})})}),e.jsx("div",{ref:v})]}),N==null?void 0:N(),G,e.jsxs("div",{className:"px-5 py-3 border-t border-slate-200 bg-white shrink-0",children:[e.jsxs("div",{className:"flex gap-2",children:[e.jsx("textarea",{ref:_,value:Q,onChange:i=>R(i.target.value),onKeyDown:K,placeholder:C,rows:2,className:`flex-1 px-3 py-2.5 text-sm border border-slate-200 rounded-xl focus:outline-none focus:ring-2 ${w.focusRing} resize-none placeholder:text-slate-300`,disabled:S||p}),e.jsx("button",{onClick:D,disabled:!Q.trim()||S||p,className:`self-stretch w-10 flex items-center justify-center rounded-xl bg-gradient-to-r ${w.sendBtn} text-white disabled:opacity-40 disabled:cursor-not-allowed transition-all shadow-sm shrink-0`,children:e.jsx(Ls,{size:16})})]}),E&&e.jsx("p",{className:"text-[10px] text-slate-400 mt-1.5",children:E})]})]}),e.jsx("style",{children:`
54
- @keyframes slide-in-right {
55
- from { transform: translateX(100%); }
56
- to { transform: translateX(0); }
57
- }
58
- .animate-slide-in-right {
59
- animation: slide-in-right 0.25s ease-out;
60
- }
61
- `})]})};function Ra(t,s){const a=[],r=[{key:"summary",label:"摘要 (summary)"},{key:"code",label:"代码 (code)"},{key:"tags",label:"标签 (tags)",format:l=>Array.isArray(l)?l.join(", "):String(l||"")},{key:"confidence",label:"置信度 (confidence)",format:l=>String(l??"—")},{key:"insight",label:"AI 洞察 (insight)"},{key:"agentNotes",label:"Agent 笔记",format:l=>Array.isArray(l)?l.join(`
62
- `):String(l||"")},{key:"relations",label:"关联关系 (relations)",format:l=>JSON.stringify(l||[],null,2)}];for(const l of r){const o=t[l.key],d=s[l.key],c=l.format||(x=>String(x??"")),u=c(o),S=c(d);S&&S!==u&&a.push({field:l.key,label:l.label,before:u,after:S,changed:!0})}return a}function Ta(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 Ga=({diff:t})=>t.length===0?e.jsx("p",{className:"text-xs text-slate-400 italic py-2",children:"未检测到变更"}):e.jsx("div",{className:"space-y-3",children:t.map(s=>e.jsxs("div",{className:"border border-slate-200 rounded-xl overflow-hidden",children:[e.jsxs("div",{className:"px-3 py-1.5 bg-slate-50 border-b border-slate-200 flex items-center gap-1.5",children:[e.jsx(Os,{size:12,className:"text-emerald-500"}),e.jsx("span",{className:"text-[11px] font-bold text-slate-600",children:s.label})]}),e.jsxs("div",{className:"grid grid-cols-2 divide-x divide-slate-200",children:[e.jsxs("div",{className:"p-3 bg-red-50/30",children:[e.jsx("div",{className:"text-[10px] font-bold text-red-400 mb-1 uppercase",children:"Before"}),e.jsx("pre",{className:"text-xs 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-3 bg-emerald-50/30",children:[e.jsx("div",{className:"text-[10px] font-bold text-emerald-500 mb-1 uppercase",children:"After"}),e.jsx("pre",{className:"text-xs text-slate-700 whitespace-pre-wrap break-words max-h-40 overflow-auto font-mono leading-relaxed scrollbar-light",children:s.after})]})]})]},s.field))}),Ma=({candidateIds:t,candidates:s,onClose:a,onCandidateUpdated:r})=>{var R;const[l,o]=n.useState(0),[d,c]=n.useState([]),[u,S]=n.useState(!1),[x,h]=n.useState(!1),[j,M]=n.useState(""),[P,O]=n.useState(new Set),z=t[l],C=s.find(V=>V.id===z),E=t.length>1;n.useEffect(()=>{C&&(c([{id:dt(),role:"system",content:`正在润色: **${C.title}**
63
-
64
- 当前摘要: ${C.summary||"(无)"}`,timestamp:Date.now()}]),M(""))},[l]);const p=n.useCallback(async V=>{if(u||!z)return;M(V);const q={id:dt(),role:"user",content:V,timestamp:Date.now()};c(v=>[...v,q]),S(!0);try{const v=await ie.refinePreview(z,V),_=v.before||Ta(C),w=v.after||{},D=Ra(_,w),K={id:dt(),role:"assistant",content:D.length>0?`已生成润色预览,共 ${D.length} 个字段变更:`:"未检测到需要变更的内容,请尝试更具体的指令。",extra:D.length>0?{diff:D,preview:v.preview}:void 0,timestamp:Date.now()};c(te=>[...te,K])}catch(v){c(_=>{var w,D;return[..._,{id:dt(),role:"assistant",content:`润色预览失败: ${((D=(w=v.response)==null?void 0:w.data)==null?void 0:D.error)||v.message}`,timestamp:Date.now()}]})}finally{S(!1)}},[u,z,C]),I=n.useCallback(async()=>{var V,q;if(!(x||!z)){h(!0);try{await ie.refineApply(z,j),O(v=>new Set(v).add(z)),r(z),c(v=>[...v,{id:dt(),role:"system",content:"✅ 变更已应用!",timestamp:Date.now()}]),ae("润色已应用")}catch(v){ae(`应用失败: ${((q=(V=v.response)==null?void 0:V.data)==null?void 0:q.error)||v.message}`,{type:"error"})}finally{h(!1)}}},[x,z,j,r]),W=n.useCallback(()=>{l<t.length-1&&o(V=>V+1)},[l,t.length]),Z=d.some(V=>{var q,v;return V.role==="assistant"&&((v=(q=V.extra)==null?void 0:q.diff)==null?void 0:v.length)>0})&&!P.has(z),N=C?{title:C.title||"(未命名)",subtitle:C.summary||"(无摘要)",badge:C.language||void 0,tags:C.tags,indicator:((R=C.reasoning)==null?void 0:R.confidence)!=null?{label:"置信度",value:`${Math.round(C.reasoning.confidence*100)}%`}:void 0,code:C.code||void 0,codeLabel:"文档内容"}:void 0,G=n.useCallback(V=>{var v;const q=(v=V.extra)==null?void 0:v.diff;return!q||q.length===0?null:e.jsx("div",{className:"mt-3",children:e.jsx(Ga,{diff:q})})},[]),Q=n.useCallback(()=>Z&&!u?e.jsxs("div",{className:"px-5 py-2.5 border-t border-slate-100 bg-emerald-50/50 flex items-center gap-2 shrink-0",children:[e.jsxs("button",{onClick:I,disabled:x,className:"flex items-center gap-1.5 px-4 py-2 text-xs 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 transition-all disabled:opacity-50",children:[x?e.jsx(ze,{size:12,className:"animate-spin"}):e.jsx(rs,{size:12}),x?"应用中...":"确认应用变更"]}),e.jsxs("button",{className:"flex items-center gap-1.5 px-3 py-2 text-xs font-bold text-slate-500 hover:text-slate-700 rounded-lg hover:bg-slate-100 transition-colors",children:[e.jsx(Fs,{size:12}),"继续调整"]}),E&&P.has(z)&&l<t.length-1&&e.jsxs("button",{onClick:W,className:"flex items-center gap-1.5 px-3 py-2 text-xs font-bold text-blue-600 hover:text-blue-700 rounded-lg hover:bg-blue-50 transition-colors ml-auto",children:["下一条 ",e.jsx(et,{size:12})]})]}):E&&P.has(z)&&!u&&l<t.length-1?e.jsx("div",{className:"px-5 py-2.5 border-t border-slate-100 flex items-center justify-center shrink-0",children:e.jsxs("button",{onClick:W,className:"flex items-center gap-1.5 px-4 py-2 text-xs font-bold text-blue-600 hover:text-blue-700 rounded-lg bg-blue-50 hover:bg-blue-100 transition-colors",children:["润色下一条 (",l+2," / ",t.length,") ",e.jsx(et,{size:14})]})}):null,[Z,u,x,I,W,E,P,z,l,t.length]);return e.jsx(Ea,{title:"对话式润色",titleBadge:E?`${l+1} / ${t.length}`:void 0,subtitle:(C==null?void 0:C.title)||"(未命名)",themeColor:"emerald",context:N,defaultCodeExpanded:!0,messages:d,loading:u,loadingText:"AI 正在分析并生成润色预览...",emptyTitle:"输入润色指令",emptyDescription:"描述你希望如何改善这条候选的内容。AI 将生成预览,你可以确认后再应用变更。",suggestions:["改善 summary 描述,使其更精准","补充架构洞察和设计模式分析","侧重线程安全和内存管理","用更简洁的语言改写"],assistantName:"AI 润色助手",renderMessageExtra:G,placeholder:"输入润色指令...",inputHint:"Enter 发送 · Shift+Enter 换行 · AI 先预览 diff 再确认应用",inputDisabled:x,onSend:p,onClose:a,renderActions:Q})},Qt={_watch:"as:create",_draft:"草稿",_cli:"CLI",_pending:"待审核(24h)",_recipe:"New Recipe"};function Pa(t,s,a,r){return[...t].sort(([l],[o])=>{const d=r(l),c=r(o);if(d&&!c)return 1;if(!d&&c)return-1;const u=a(l),S=a(o);if(u&&!S)return-1;if(!u&&S)return 1;const x=s(l),h=s(o);return x&&!h?1:!x&&h?-1:l.localeCompare(o)})}function Lt(t){if(!t)return"";const s=typeof t=="number"?t:Number(t),a=s<1e12?s*1e3:s,r=new Date(a);if(isNaN(r.getTime())||r.getFullYear()<2e3)return"";const o=new Date().getTime()-r.getTime();if(o<0)return r.toLocaleDateString("zh-CN");const d=Math.floor(o/6e4);if(d<1)return"刚刚";if(d<60)return`${d} 分钟前`;const c=Math.floor(d/60);if(c<24)return`${c} 小时前`;const u=Math.floor(c/24);return u<7?`${u} 天前`:r.toLocaleDateString("zh-CN")}function La(t,s=4){return t?t.split(`
65
- `).slice(0,s).join(`
66
- `):""}function Fa(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 Oa(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 Da={"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"}},Ba=({value:t,size:s=36})=>{const a=(s-6)/2,r=2*Math.PI*a,l=t!=null?Math.max(0,Math.min(1,t)):0,o=r*(1-l),{ring:d,text:c}=Fa(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:d,strokeDasharray:r,strokeDashoffset:o,style:{transition:"stroke-dashoffset 0.5s ease"}})]}),e.jsx("span",{className:`absolute text-[9px] font-bold ${c}`,children:t!=null?`${Math.round(t*100)}`:"—"})]})},Ha=({data:t,isShellTarget:s,isSilentTarget:a=()=>!1,isPendingTarget:r=()=>!1,handleDeleteCandidate:l,handleDeleteAllInTarget:o,onAuditCandidate:d,onAuditAllInTarget:c,onEditRecipe:u,onColdStart:S,isScanning:x,onRefresh:h})=>{var ce;const[j,M]=n.useState(null),[P,O]=n.useState(new Set),[z,C]=n.useState(new Set),[E,p]=n.useState(!1),[I,W]=n.useState(!1),[Z,N]=n.useState(null),[G,Q]=n.useState({}),[R,V]=n.useState(null),[q,v]=n.useState({}),[_,w]=n.useState(null),[D,K]=n.useState({priority:"all",sort:"default",onlySimilar:!1}),[te,i]=n.useState(null),f=n.useRef(new Set),L=n.useCallback(async($,X)=>{if(!f.current.has(X)){f.current.add(X),w(X);try{const J=await ie.getCandidateSimilarityEx({targetName:$,candidateId:X});v(he=>({...he,[X]:J.similar||[]}))}catch{v(he=>({...he,[X]:[]}))}finally{w(null)}}},[]),U=n.useCallback(async($,X,J,he=[])=>{var ue,we,Ce,Ie;const Y=J.replace(/\.md$/i,"");let de="";const B=(ue=t==null?void 0:t.recipes)==null?void 0:ue.find(ke=>ke.name===Y||ke.name.endsWith("/"+Y));if(B!=null&&B.content)de=B.content;else try{de=(await ie.getRecipeContentByName(Y)).content}catch(ke){const Re=(we=ke.response)==null?void 0:we.status,tt=((Ie=(Ce=ke.response)==null?void 0:Ce.data)==null?void 0:Ie.message)||ke.message;Re===404?ae(`Recipe 不存在: ${Y}`,{type:"error"}):ae(`加载 Recipe 失败: ${tt}`,{type:"error"});return}const ne={[Y]:de};i({candidate:$,targetName:X,recipeName:Y,recipeContent:de,similarList:he.slice(0,3),recipeContents:ne})},[t==null?void 0:t.recipes]),ee=t!=null&&t.candidates?Object.entries(t.candidates):[],ye=Pa(ee,s,a,r),Ne=ye.map(([$])=>$),xe=R&&Ne.includes(R)?R:Ne[0]??null;n.useEffect(()=>{Ne.length>0&&(!R||!Ne.includes(R))&&V(Ne[0])},[Ne.join(","),R]),n.useEffect(()=>{j&&xe&&L(xe,j)},[j,xe,L]);const fe=n.useMemo(()=>{var ue;if(!xe||!((ue=t==null?void 0:t.candidates)!=null&&ue[xe]))return null;const $=t.candidates[xe].items,X=$.length,J=$.filter(we=>{var Ce;return((Ce=we.reviewNotes)==null?void 0:Ce.priority)==="high"}).length,he=$.filter(we=>{var Ce;return((Ce=we.reviewNotes)==null?void 0:Ce.priority)==="medium"}).length,Y=$.filter(we=>{var Ce;return((Ce=we.reviewNotes)==null?void 0:Ce.priority)==="low"}).length,de=$.reduce((we,Ce)=>{var Ie;return we+(((Ie=Ce.reasoning)==null?void 0:Ie.confidence)??0)},0)/(X||1),B=$.filter(we=>we.code&&we.code.trim().length>0).length,ne=new Map;return $.forEach(we=>{const Ce=we.source||"unknown";ne.set(Ce,(ne.get(Ce)||0)+1)}),{total:X,high:J,medium:he,low:Y,avgConfidence:de,withCode:B,sources:ne}},[xe,t==null?void 0:t.candidates]),y=n.useCallback(async $=>{var X,J,he,Y,de;if(!P.has($)){O(B=>new Set(B).add($));try{const B=await ie.enrichCandidates([$]);B.enriched>0?ae(`已补齐 ${((he=(J=(X=B.results)==null?void 0:X[0])==null?void 0:J.filledFields)==null?void 0:he.length)||0} 个结构字段`):ae("所有结构字段已完整,无需补齐"),h==null||h()}catch(B){ae(`AI 补齐失败: ${((de=(Y=B.response)==null?void 0:Y.data)==null?void 0:de.error)||B.message}`,{type:"error"})}finally{O(B=>{const ne=new Set(B);return ne.delete($),ne})}}},[P,h]),F=n.useCallback(async()=>{var X,J,he;if(E||!xe||!((X=t==null?void 0:t.candidates)!=null&&X[xe]))return;const $=t.candidates[xe].items;if($.length!==0){p(!0);try{let Y=0;for(let de=0;de<$.length;de+=20){const B=$.slice(de,de+20).map(ue=>ue.id),ne=await ie.enrichCandidates(B);Y+=ne.enriched}ae(`① 结构补齐完成: ${Y}/${$.length} 条候选已更新`),h==null||h()}catch(Y){ae(`① 结构补齐失败: ${((he=(J=Y.response)==null?void 0:J.data)==null?void 0:he.error)||Y.message}`,{type:"error"})}finally{p(!1)}}},[E,xe,t==null?void 0:t.candidates,h]),Se=n.useCallback(()=>{var X;if(!xe||!((X=t==null?void 0:t.candidates)!=null&&X[xe]))return;const $=t.candidates[xe].items.map(J=>J.id);N({candidateIds:$})},[xe,t==null?void 0:t.candidates]),oe=n.useCallback($=>{N({candidateIds:[$]})},[]),H=n.useCallback($=>{h==null||h()},[h]);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(vt,{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:[S&&e.jsxs("button",{onClick:S,disabled:x,className:`flex items-center gap-1.5 px-3.5 py-2 rounded-lg text-xs font-bold transition-all ${x?"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:[x?e.jsx(ze,{size:14,className:"animate-spin"}):e.jsx(Nt,{size:14}),x?"初始化中...":"冷启动"]}),fe&&fe.total>0&&e.jsxs("button",{onClick:F,disabled:E||I,className:`flex items-center gap-1.5 px-3 py-2 rounded-lg text-xs font-bold transition-all ${E||I?"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:[E?e.jsx(ze,{size:14,className:"animate-spin"}):e.jsx(Xt,{size:14}),E?"补齐中...":"① 结构补齐"]}),fe&&fe.total>0&&e.jsxs("button",{onClick:Se,disabled:I||E,className:`flex items-center gap-1.5 px-3 py-2 rounded-lg text-xs font-bold transition-all ${I||E?"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:[I?e.jsx(ze,{size:14,className:"animate-spin"}):e.jsx(vt,{size:14}),I?"润色中...":"② 内容润色"]}),fe&&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(Ds,{size:14,className:"text-slate-400"}),e.jsxs("span",{className:"text-slate-500",children:["共 ",e.jsx("strong",{className:"text-slate-700",children:fe.total})," 条"]}),fe.withCode<fe.total&&e.jsxs("span",{className:"text-slate-400 ml-1",children:["(含代码 ",fe.withCode,")"]})]}),fe.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:fe.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(fe.avgConfidence*100),"%"]})]})]})]})]}),ee.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:Ne.map($=>{var ne;s($);const X=a($),J=Qt[$],he=t.candidates[$],Y=((ne=he==null?void 0:he.items)==null?void 0:ne.length)??0,de=xe===$,B=De[$]||De.All;return e.jsxs("button",{onClick:()=>V($),className:`flex items-center gap-2 px-3 py-2 rounded-lg text-sm font-bold whitespace-nowrap transition-all border
67
- ${de?`${(B==null?void 0:B.bg)||"bg-blue-50"} ${(B==null?void 0:B.color)||"text-blue-700"} ${(B==null?void 0:B.border)||"border-blue-200"} shadow-sm ring-1 ring-inset ${(B==null?void 0:B.border)||"ring-blue-200"}`:"bg-slate-50/80 text-slate-600 border-slate-100 hover:border-slate-200 hover:bg-slate-100"}`,children:[(()=>{const ue=(B==null?void 0:B.icon)||kt;return e.jsx(ue,{size:b.sm,className:de?"":"text-slate-400"})})(),e.jsx("span",{children:$}),X&&J&&e.jsx("span",{className:"text-[9px] text-amber-600 border border-amber-200 px-1 rounded",children:J}),e.jsx("span",{className:`text-[10px] font-normal rounded-full px-1.5 ${de?"bg-white/60":"bg-slate-200/60 text-slate-400"}`,children:Y})]},$)})})}),e.jsxs("div",{className:"flex-1 overflow-y-auto pr-1",children:[(!(t!=null&&t.candidates)||Object.keys(t.candidates).length===0)&&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(ns,{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 命令手动创建"}),S&&e.jsxs("button",{onClick:S,disabled:x,className:`mt-4 flex items-center gap-2 px-5 py-2.5 rounded-xl text-sm font-bold transition-all ${x?"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:[x?e.jsx(ze,{size:16,className:"animate-spin"}):e.jsx(Nt,{size:16}),x?"正在初始化...":"冷启动:初始化知识库"]}),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&&xe&&ye.filter(([$])=>$===xe).map(([$,X])=>{const J=s($),he=a($),Y=Qt[$]||"静默",de=G[$]||{page:1,pageSize:12},B=de.page,ne=de.pageSize,ue=X.items.filter(k=>{var ve;if(D.priority!=="all"&&((ve=k.reviewNotes)==null?void 0:ve.priority)!==D.priority)return!1;if(D.onlySimilar){const Fe=k.relatedRecipes;if(!Array.isArray(Fe)||Fe.length===0)return!1}return!0}).sort((k,ve)=>{var Fe,Ue,qe,Pe,Ge,st;if(D.sort==="default")return 0;if(D.sort==="score-desc")return(((Fe=ve.quality)==null?void 0:Fe.overallScore)??0)-(((Ue=k.quality)==null?void 0:Ue.overallScore)??0);if(D.sort==="score-asc")return(((qe=k.quality)==null?void 0:qe.overallScore)??0)-(((Pe=ve.quality)==null?void 0:Pe.overallScore)??0);if(D.sort==="confidence-desc")return(((Ge=ve.reasoning)==null?void 0:Ge.confidence)??0)-(((st=k.reasoning)==null?void 0:st.confidence)??0);if(D.sort==="date-desc"){const at=typeof k.createdAt=="number"?k.createdAt:Number(k.createdAt)||0;return(typeof ve.createdAt=="number"?ve.createdAt:Number(ve.createdAt)||0)-at}return 0}),we=ue.length,Ce=Math.ceil(we/ne),Ie=(B-1)*ne,ke=ue.slice(Ie,Ie+ne),Re=k=>{Q(ve=>({...ve,[$]:{...de,page:k}}))},tt=k=>{Q(ve=>({...ve,[$]:{page:1,pageSize:k}}))},He=De[$]||De.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 k=(He==null?void 0:He.icon)||kt;return e.jsx(k,{size:18,className:(He==null?void 0:He.color)||"text-blue-600"})})(),e.jsx("span",{className:"text-base font-bold text-slate-800 truncate",children:$}),he&&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:Y}),J&&!he&&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(Ft,{size:11}),"扫描于 ",Lt(X.scanTime)||new Date(X.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(Bs,{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:D.priority,onChange:k=>K(ve=>({...ve,priority:k.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(Hs,{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:D.sort,onChange:k=>K(ve=>({...ve,sort:k.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:D.onlySimilar,onChange:k=>K(ve=>({...ve,onlySimilar:k.target.checked})),className:"rounded text-blue-600 w-3 h-3"}),"只看相似"]}),(D.priority!=="all"||D.sort!=="default"||D.onlySimilar)&&e.jsx("button",{onClick:()=>K({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:[we," 条"]}),e.jsx("button",{onClick:()=>c(ke,$),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:()=>{window.confirm(`确定移除当前页的 ${ke.length} 条候选?`)&&ke.forEach(k=>l($,k.id))},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($),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:ke.map(k=>{var ht,bt,lt,ct,m;const ve=j===k.id,Fe=((ht=k.reasoning)==null?void 0:ht.confidence)??null,Ue=((bt=k.quality)==null?void 0:bt.overallScore)??null,qe=(lt=k.reviewNotes)==null?void 0:lt.priority,Pe=Oa(qe),Ge=(ct=k.relatedRecipes)==null?void 0:ct[0],st=q[k.id]||[],at=Da[k.source||""]||{label:k.source||"",color:"text-slate-500 bg-slate-50 border-slate-200"},$e=De[k.category||""]||De.All||{},Rt=(($e==null?void 0:$e.color)||"text-blue-600").replace("text-","border-l-");return e.jsxs("div",{className:`bg-white rounded-xl border border-slate-200 overflow-hidden hover:shadow-lg transition-all duration-200 flex flex-col group
68
- ${J?"opacity-75":""}
69
- ${ve?"ring-2 ring-blue-200 shadow-lg":"hover:border-slate-300"}`,children:[e.jsx("div",{className:`border-l-[4px] ${Rt} 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 g=($e==null?void 0:$e.icon)||rt;return e.jsx(g,{size:10})})(),k.category||"general"]}),k.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:k.knowledgeType}),k.source&&k.source!=="unknown"&&e.jsx("span",{className:`text-[10px] font-medium px-1.5 py-0.5 rounded border ${at.color}`,children:at.label}),k.complexity&&e.jsx("span",{className:`text-[10px] font-medium px-1.5 py-0.5 rounded border
70
- ${k.complexity==="advanced"?"bg-red-50 text-red-600 border-red-100":k.complexity==="intermediate"?"bg-amber-50 text-amber-600 border-amber-100":"bg-emerald-50 text-emerald-600 border-emerald-100"}`,children:k.complexity==="advanced"?"高级":k.complexity==="intermediate"?"中级":"初级"})]}),e.jsx("h3",{className:"font-bold text-sm text-slate-800 leading-snug mb-1 line-clamp-1",children:k.title}),e.jsx("p",{className:"text-xs text-slate-500 line-clamp-2 leading-relaxed",children:k.summary||k.summary_cn||""})]}),e.jsxs("div",{className:"flex flex-col items-center gap-1 shrink-0",children:[e.jsx(Ba,{value:Fe}),e.jsx("span",{className:"text-[9px] text-slate-400 font-medium",children:"置信度"})]})]})}),((m=k.reasoning)==null?void 0:m.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(Dt,{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:k.reasoning.whyStandard})]})}),(Ue!=null||Pe||Ge)&&e.jsxs("div",{className:"flex flex-wrap items-center gap-1.5 px-4 py-2 border-t border-slate-50",children:[Ue!=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(Us,{size:10}),"综合 ",(Ue*100).toFixed(0),"%"]}),Pe&&e.jsxs("span",{className:`text-[10px] font-bold px-2 py-0.5 rounded-full border flex items-center gap-1 ${Pe.bg} ${Pe.text} ${Pe.border}`,children:[Pe.icon," ",qe==="high"?"高优先":qe==="medium"?"中优先":"低优先"]}),Ge&&e.jsxs("button",{onClick:()=>{const g=String(Ge.id||Ge.title||"").trim();g&&U(k,$,g,st)},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(wt,{size:10}),"相似 ",String(Ge.title||Ge.id||"").replace(/\.md$/i,"")," ",(Ge.similarity*100).toFixed(0),"%"]})]}),k.code&&e.jsxs("div",{className:"mx-3 mb-2 rounded-xl overflow-hidden border border-slate-200/60 shadow-sm",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(ls,{size:11,className:"text-slate-500"}),e.jsx("span",{className:"text-[10px] text-slate-400 font-mono uppercase tracking-wide",children:k.language||"code"})]}),e.jsxs("span",{className:"text-[10px] text-slate-500 font-mono tabular-nums",children:[k.code.split(`
71
- `).length," 行"]})]}),e.jsxs("div",{className:"relative max-h-[80px] overflow-hidden",children:[e.jsx(Ze,{code:La(k.code,3),language:k.language==="objc"?"objectivec":k.language,className:"!rounded-none"}),k.code.split(`
72
- `).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"})]})]}),ve&&e.jsxs("div",{className:"px-4 pb-3 space-y-3 border-t border-slate-100 pt-3 animate-in fade-in slide-in-from-top-1 duration-200",children:[(()=>{const g=k.reasoning,T=g&&(g.whyStandard||g.sources&&g.sources.length>0||g.confidence!=null);return!T&&!k.quality?null:e.jsxs("div",{className:"rounded-xl border border-indigo-100 bg-indigo-50/40 p-3 text-xs space-y-2.5",children:[e.jsxs("div",{className:"flex items-center gap-1.5 text-indigo-700 font-bold text-[11px]",children:[e.jsx(Dt,{size:14}),"AI 推理过程"]}),T?e.jsxs(e.Fragment,{children:[g.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(It,{size:10})," 为什么是标准用法"]}),e.jsx("p",{className:"text-slate-600 leading-relaxed pl-3",children:g.whyStandard})]}),g.sources&&g.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(ot,{size:10})," 来源"]}),e.jsx("ul",{className:"pl-3 text-slate-600 space-y-0.5",children:g.sources.map((A,se)=>e.jsxs("li",{className:"flex items-start gap-1",children:[e.jsx("span",{className:"text-indigo-400 mt-0.5",children:"•"}),A]},se))})]}),g.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 ${g.confidence>=.7?"bg-emerald-500":g.confidence>=.4?"bg-amber-500":"bg-red-500"}`,style:{width:`${Math.round((g.confidence??0)*100)}%`}})}),e.jsxs("span",{className:`font-bold ${g.confidence>=.7?"text-emerald-600":g.confidence>=.4?"text-amber-600":"text-red-600"}`,children:[Math.round((g.confidence??0)*100),"%"]})]})]}):e.jsx("p",{className:"text-slate-400 italic pl-3",children:"暂无推理信息"})]})})(),(()=>{const g=q[k.id],T=_===k.id;return((g==null?void 0:g.length)??0)>0||T?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?e.jsx("span",{className:"text-[10px] text-slate-400 animate-pulse",children:"加载中..."}):(g||[]).slice(0,3).map(se=>e.jsxs("button",{onClick:()=>U(k,$,se.recipeName,g||[]),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:`与 ${se.recipeName} 相似 ${(se.similarity*100).toFixed(0)}%`,children:[e.jsx(wt,{size:10}),se.recipeName.replace(/\.md$/i,"")," ",(se.similarity*100).toFixed(0),"%"]},se.recipeName))]}):null})(),e.jsx("div",{className:"rounded-xl overflow-hidden border border-slate-100 bg-slate-50 max-h-72 overflow-y-auto",children:k.code?e.jsx(Ze,{code:k.code,language:k.language==="objc"?"objectivec":k.language,showLineNumbers:!0}):e.jsx("div",{className:"p-4",children:e.jsx(We,{content:k.usageGuide||""})})}),k.code&&k.usageGuide&&e.jsxs("div",{className:"rounded-xl overflow-hidden border border-slate-100 bg-white p-3 max-h-48 overflow-y-auto",children:[e.jsxs("div",{className:"flex items-center gap-1.5 text-[11px] font-bold text-slate-600 mb-2",children:[e.jsx(ot,{size:12})," 使用指南"]}),e.jsx(We,{content:k.usageGuide})]}),e.jsxs("div",{className:"flex flex-wrap gap-x-4 gap-y-1 text-[10px] text-slate-400",children:[k.scope&&e.jsxs("span",{children:["范围: ",e.jsx("strong",{className:"text-slate-600",children:k.scope==="universal"?"通用":k.scope==="project-specific"?"项目级":"模块级"})]}),k.headers&&k.headers.length>0&&e.jsxs("span",{children:["头文件: ",e.jsx("strong",{className:"text-slate-600",children:k.headers.join(", ")})]}),k.steps&&k.steps.length>0&&e.jsxs("span",{children:["实施步骤: ",e.jsxs("strong",{className:"text-slate-600",children:[k.steps.length," 步"]})]}),k.rationale&&e.jsxs("span",{title:k.rationale,children:["设计原理: ",e.jsxs("strong",{className:"text-slate-600 line-clamp-1",children:[k.rationale.substring(0,60),k.rationale.length>60?"...":""]})]})]})]}),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",children:[e.jsxs("div",{className:"flex items-center gap-2 flex-wrap min-w-0",children:[e.jsxs("button",{onClick:()=>M(ve?null:k.id),className:`flex items-center gap-1 px-2 py-1 rounded-lg text-[11px] font-medium transition-colors
73
- ${ve?"bg-blue-100 text-blue-700":"bg-white text-slate-500 hover:text-blue-600 hover:bg-blue-50 border border-slate-200"}`,title:ve?"收起详情":"展开详情",children:[ve?e.jsx(qs,{size:12}):e.jsx(Qe,{size:12}),ve?"收起":"详情"]}),k.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:k.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:k.language}),k.tags&&k.tags.length>0&&k.tags.slice(0,3).map((g,T)=>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 g=="string"?g:String(g)},T)),k.tags&&k.tags.length>3&&e.jsxs("span",{className:"text-[9px] text-slate-400",children:["+",k.tags.length-3]}),k.createdAt&&Lt(k.createdAt)&&e.jsxs("span",{className:"text-[9px] text-slate-400 flex items-center gap-0.5",children:[e.jsx(Ft,{size:9}),Lt(k.createdAt)]})]}),e.jsxs("div",{className:"flex items-center gap-1.5 shrink-0",children:[e.jsx("button",{onClick:()=>y(k.id),disabled:P.has(k.id),title:"① 结构补齐:填充缺失的语义字段(rationale / knowledgeType / complexity 等)",className:`p-1.5 rounded-lg transition-colors flex items-center gap-1 text-[11px] font-medium ${P.has(k.id)?"text-slate-300 cursor-not-allowed":"text-amber-500 hover:text-amber-600 hover:bg-amber-50"}`,children:P.has(k.id)?e.jsx(ze,{size:14,className:"animate-spin"}):e.jsx(Xt,{size:14})}),e.jsx("button",{onClick:()=>oe(k.id),disabled:z.has(k.id),title:"② 内容润色:改善描述、补充洞察、推断关联(支持自定义提示词)",className:`p-1.5 rounded-lg transition-colors flex items-center gap-1 text-[11px] font-medium ${z.has(k.id)?"text-slate-300 cursor-not-allowed":"text-emerald-500 hover:text-emerald-600 hover:bg-emerald-50"}`,children:z.has(k.id)?e.jsx(ze,{size:14,className:"animate-spin"}):e.jsx(vt,{size:14})}),e.jsx("button",{onClick:()=>l($,k.id),title:"忽略",className:"p-1.5 hover:bg-red-50 text-slate-400 hover:text-red-500 rounded-lg transition-colors",children:e.jsx(Et,{size:14})}),e.jsxs("button",{onClick:()=>d(k,$),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(pt,{size:12})," 审核并保存"]}),k.status==="approved"&&e.jsxs("button",{onClick:async()=>{try{await ie.promoteCandidateToRecipe(k.id),ae("已提升为 Recipe"),h==null||h()}catch(g){ae(`提升失败: ${g.message}`,{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(Nt,{size:12})," 提升为 Recipe"]})]})]})]},k.id)})}),we>12&&e.jsx(ms,{currentPage:B,totalPages:Ce,totalItems:we,pageSize:ne,onPageChange:Re,onPageSizeChange:tt})]},$)})]}),te&&(()=>{const $=te.candidate,X=$.language==="objc"||$.language==="objective-c"?"objectivec":$.language||"text",J=()=>{const ue=[];$.code&&ue.push("## Snippet / Code Reference\n\n```"+X+`
74
- `+$.code+"\n```"),$.usageGuide&&ue.push(`
75
- ## AI Context / Usage Guide
76
-
77
- `+$.usageGuide),navigator.clipboard.writeText(ue.join(`
78
- `)||"").then(()=>ae("已复制候选内容"))},he=()=>{const ue=Ut(te.recipeContent);navigator.clipboard.writeText(ue).then(()=>ae("已复制 Recipe 内容"))},Y=async ue=>{var Ce;if(ue===te.recipeName)return;const we=te.recipeContents[ue];if(we)i(Ie=>Ie?{...Ie,recipeName:ue,recipeContent:we}:null);else{let Ie="";const ke=(Ce=t==null?void 0:t.recipes)==null?void 0:Ce.find(Re=>Re.name===ue||Re.name.endsWith("/"+ue));if(ke!=null&&ke.content)Ie=ke.content;else try{Ie=(await ie.getRecipeContentByName(ue)).content}catch{return}i(Re=>Re?{...Re,recipeName:ue,recipeContent:Ie,recipeContents:{...Re.recipeContents,[ue]:Ie}}:null)}},de=async()=>{if(window.confirm("确定删除该候选?"))try{await l(te.targetName,$.id),i(null)}catch{}},B=()=>{d($,te.targetName),i(null)},ne=()=>{var we;const ue=((we=t==null?void 0:t.recipes)==null?void 0:we.find(Ce=>Ce.name===te.recipeName||Ce.name.endsWith("/"+te.recipeName)))||{name:te.recipeName,content:te.recipeContent};u==null||u(ue),i(null)};return e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/50 backdrop-blur-sm p-4",onClick:()=>i(null),children:e.jsxs("div",{className:"bg-white rounded-2xl shadow-2xl w-[min(95vw,1600px)] max-h-[92vh] flex flex-col",onClick:ue=>ue.stopPropagation(),children:[e.jsxs("div",{className:"flex justify-between items-center px-5 py-3.5 border-b border-slate-200 shrink-0",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-8 h-8 rounded-lg bg-gradient-to-br from-blue-500 to-indigo-600 flex items-center justify-center",children:e.jsx(wt,{size:16,className:"text-white"})}),e.jsx("h3",{className:"font-bold text-slate-800",children:"候选 vs Recipe 对比"}),e.jsxs("div",{className:"flex items-center gap-1.5 ml-2",children:[e.jsx("button",{onClick:de,className:"text-xs font-medium text-red-600 hover:bg-red-50 px-2.5 py-1.5 rounded-lg transition-colors",children:"删除候选"}),e.jsx("button",{onClick:B,className:"text-xs font-medium text-blue-600 hover:bg-blue-50 px-2.5 py-1.5 rounded-lg transition-colors",children:"审核候选"}),e.jsx("button",{onClick:ne,className:"text-xs font-medium text-emerald-600 hover:bg-emerald-50 px-2.5 py-1.5 rounded-lg transition-colors",children:"审核 Recipe"})]})]}),e.jsx("button",{onClick:()=>i(null),className:"p-2 hover:bg-slate-100 rounded-lg transition-colors",children:e.jsx(Ke,{size:20})})]}),e.jsxs("div",{className:"flex-1 grid grid-cols-2 overflow-hidden min-h-0",style:{gridTemplateRows:"auto 1fr"},children:[e.jsxs("div",{className:"px-5 py-3 bg-blue-50 border-b border-r border-slate-100 flex flex-col justify-center min-h-0",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsxs("span",{className:"text-sm font-bold text-blue-700 truncate flex-1 min-w-0",title:$.title,children:["候选:",$.title]}),e.jsx("button",{onClick:J,className:"p-1.5 hover:bg-blue-100 rounded-lg text-blue-600 shrink-0",title:"复制",children:e.jsx($t,{size:14})})]}),e.jsx("div",{className:"min-h-[28px] mt-2 shrink-0"})]}),e.jsxs("div",{className:"px-5 py-3 bg-emerald-50 border-b border-slate-100 flex flex-col justify-center min-h-0",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsxs("span",{className:"text-sm font-bold text-emerald-700 truncate flex-1 min-w-0",title:te.recipeName,children:["Recipe:",te.recipeName.replace(/\.md$/i,"")]}),e.jsx("button",{onClick:he,className:"p-1.5 hover:bg-emerald-100 rounded-lg text-emerald-600 shrink-0",title:"复制",children:e.jsx($t,{size:14})})]}),te.similarList.length>1?e.jsx("div",{className:"flex flex-wrap gap-1 mt-2 shrink-0",children:te.similarList.map(ue=>e.jsxs("button",{onClick:()=>Y(ue.recipeName),className:`text-[10px] font-bold px-2 py-1 rounded transition-colors ${te.recipeName===ue.recipeName?"bg-emerald-200 text-emerald-800":"bg-white/80 text-emerald-600 hover:bg-emerald-100"}`,children:[ue.recipeName.replace(/\.md$/i,"")," ",(ue.similarity*100).toFixed(0),"%"]},ue.recipeName))}):e.jsx("div",{className:"min-h-[28px] mt-2 shrink-0"})]}),e.jsxs("div",{className:"flex-1 overflow-auto p-5 min-h-0 border-r border-slate-200 markdown-body text-slate-700",children:[e.jsx("h2",{className:"text-lg font-bold mb-2 mt-4",children:"Snippet / Code Reference"}),$.code?e.jsx(Ze,{code:$.code,language:X,className:"!overflow-visible"}):e.jsx("p",{className:"text-slate-400 italic mb-3",children:"(无代码)"}),e.jsx("h2",{className:"text-lg font-bold mb-2 mt-4",children:"AI Context / Usage Guide"}),$.usageGuide?e.jsx(We,{content:$.usageGuide}):e.jsx("p",{className:"text-slate-400 italic",children:"(无使用指南)"})]}),e.jsx("div",{className:"flex-1 overflow-auto p-5 min-h-0",children:e.jsx(We,{content:te.recipeContent,stripFrontmatter:!0})})]})]})})})(),Z&&xe&&((ce=t==null?void 0:t.candidates)==null?void 0:ce[xe])&&e.jsx(Ma,{candidateIds:Z.candidateIds,candidates:t.candidates[xe].items,onClose:()=>N(null),onCandidateUpdated:H})]})},qt=({value:t,onChange:s,onCursorChange:a,language:r="javascript",height:l="400px",className:o="",placeholder:d="",rows:c,showLineNumbers:u=!0})=>{const S=n.useRef(null),x=n.useRef(null),h=n.useRef(null),j=n.useRef(null),P={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"}[r==null?void 0:r.toLowerCase()]||(r==null?void 0:r.toLowerCase())||"text",O=I=>{const W=I.currentTarget;h.current&&(h.current.scrollTop=W.scrollTop,h.current.scrollLeft=W.scrollLeft),j.current&&(j.current.scrollTop=W.scrollTop)},z=I=>{s(I.target.value),a&&a(I.target.selectionStart||0)},C=I=>{if(!a)return;const W=I.currentTarget;a(W.selectionStart||0)},E=(t||"").split(`
79
- `).length,p={padding:"1rem 1.25rem",fontSize:"0.8125rem",lineHeight:1.5,fontFamily:"ui-monospace, monospace",minHeight:"200px"};return e.jsxs("div",{ref:S,className:`relative overflow-hidden ${o}`,style:{height:c?"auto":l,minHeight:p.minHeight,display:"flex",borderRadius:"0",backgroundColor:"#282c34"},children:[u&&e.jsx("div",{ref:j,className:"flex-shrink-0 overflow-hidden pointer-events-none select-none",style:{width:"3.5em",backgroundColor:"#282c34",color:"#5c6370",fontSize:p.fontSize,lineHeight:p.lineHeight,textAlign:"right",paddingTop:"1rem",paddingRight:"0.75em",paddingBottom:"1rem",borderRadius:"0",fontFamily:p.fontFamily},children:Array.from({length:E},(I,W)=>e.jsx("div",{children:W+1},W))}),e.jsxs("div",{className:"relative flex-1",style:{borderRadius:"0",backgroundColor:"#282c34"},children:[e.jsx("div",{ref:h,className:"absolute inset-0 pointer-events-none highlight-scroll-hidden",style:{zIndex:0,overflow:"scroll"},children:e.jsx(ds,{language:P,style:xs,showLineNumbers:!1,customStyle:{margin:0,padding:p.padding,fontSize:p.fontSize,lineHeight:p.lineHeight,borderRadius:"0",whiteSpace:"pre",verticalAlign:"top",display:"inline-block",minWidth:"100%",minHeight:"100%",backgroundColor:"#282c34"},codeTagProps:{style:{fontFamily:p.fontFamily,whiteSpace:"pre",verticalAlign:"top",fontSize:p.fontSize,lineHeight:p.lineHeight}},PreTag:"div",children:(()=>{const I=t||d;return I[I.length-1]===`
80
- `?I+" ":I})()})}),e.jsx("textarea",{ref:x,value:t,onChange:z,onSelect:C,onKeyUp:C,onClick:C,onScroll:O,rows:c,placeholder:d,className:"absolute inset-0 w-full h-full resize-none outline-none",style:{padding:p.padding,lineHeight:p.lineHeight,fontSize:p.fontSize,fontFamily:p.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"}})]})]})},Ua=({isOpen:t,onClose:s,currentFile:a,targetName:r,language:l="swift",onSelectRecipe:o})=>{var Z,N,G,Q;const[d,c]=n.useState(""),[u,S]=n.useState([]),[x,h]=n.useState(null),[j,M]=n.useState(!1),[P,O]=n.useState(null),[z,C]=n.useState(!1),[E,p]=n.useState(null),I=async()=>{if(d.trim()){M(!0);try{const R=await ie.contextAwareSearch({keyword:d,targetName:r,currentFile:a,language:l,limit:10});S(R.results||[]),h(R.context)}catch(R){console.error("Context-aware search failed:",R),alert("搜索失败。请重试。")}finally{M(!1)}}},W=R=>{R.key==="Enter"&&I()};return t?e.jsxs("div",{className:"fixed inset-0 bg-black/20 z-50 flex",children:[e.jsxs("div",{className:"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:b.lg,className:"text-slate-500"})})]}),x&&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(Be,{size:b.md,className:"text-blue-600 mt-0.5 shrink-0"}),e.jsxs("div",{className:"flex-1",children:[((Z=x.targetInfo)==null?void 0:Z.targetName)&&e.jsxs("div",{className:"text-blue-900 font-medium flex items-center gap-2 mb-1",children:[e.jsx(It,{size:b.sm}),"Target: ",x.targetInfo.targetName]}),((N=x.fileInfo)==null?void 0:N.imports)&&x.fileInfo.imports.length>0&&e.jsxs("div",{className:"text-blue-800 text-xs mt-2",children:[e.jsx("strong",{children:"导入的框架:"})," ",x.fileInfo.imports.slice(0,3).join(", "),x.fileInfo.imports.length>3&&` +${x.fileInfo.imports.length-3}`]}),((G=x.targetInfo)==null?void 0:G.suggestedApis)&&x.targetInfo.suggestedApis.length>0&&e.jsxs("div",{className:"text-blue-800 text-xs mt-1",children:[e.jsx("strong",{children:"相关 APIs:"})," ",x.targetInfo.suggestedApis.slice(0,3).join(", ")]})]})]})}),e.jsxs("div",{className:"relative",children:[e.jsx(it,{className:"absolute left-3 top-1/2 -translate-y-1/2 text-slate-400",size:b.md}),e.jsx("input",{type:"text",placeholder:"输入搜索关键词...",value:d,onChange:R=>c(R.target.value),onKeyDown:W,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:I,disabled:!d.trim()||j,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:[j&&e.jsx(ze,{size:b.sm,className:"animate-spin"}),j?"搜索中...":"搜索"]})]}),e.jsxs("div",{className:"flex-1 overflow-auto",children:[u.length===0&&!j&&e.jsx("div",{className:"flex items-center justify-center h-full text-slate-500",children:e.jsxs("div",{className:"text-center",children:[e.jsx(zt,{size:b.xxl,className:"mx-auto mb-2 opacity-50"}),e.jsx("p",{className:"text-sm",children:"输入关键词后点击搜索"})]})}),u.map((R,V)=>e.jsxs("div",{className:"border-b border-slate-200 p-4 hover:bg-slate-50 transition-colors cursor-pointer",onClick:()=>{O(P===V?null:V),R.name&&(o==null||o(R.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:R.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(Be,{size:b.xs}),Math.round(R.similarity*100),"%"]}),R.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(It,{size:b.xs}),"上下文相关"]}),R.matchType&&e.jsx("span",{className:"text-xs text-slate-500",children:R.matchType==="semantic"?"语义匹配":"关键词匹配"})]})]}),e.jsx("button",{onClick:q=>{q.stopPropagation(),O(P===V?null:V)},className:"p-1 hover:bg-slate-200 rounded transition-colors",children:P===V?"▼":"▶"})]}),R.stats&&e.jsxs("div",{className:"text-xs text-slate-500 mb-2 flex gap-3",children:[R.stats.authorityScore!==void 0&&e.jsxs("span",{children:["权威分: ",R.stats.authorityScore]}),R.usageCount!==void 0&&e.jsxs("span",{children:["使用: ",R.usageCount,"次"]})]}),P===V&&e.jsxs("div",{className:"mt-3 pt-3 border-t border-slate-200",children:[R.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:R.recommendReason})]}),e.jsxs("div",{className:"text-xs text-slate-600 max-h-[200px] overflow-auto bg-slate-50 p-3 rounded",children:[R.content.substring(0,500),"..."]}),e.jsx("button",{onClick:q=>{q.stopPropagation(),p(R),C(!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:"查看完整内容"})]})]},V)),j&&e.jsx("div",{className:"flex items-center justify-center h-32",children:e.jsx(ze,{size:b.lg,className:"animate-spin text-blue-600"})}),u.length===0&&d&&!j&&e.jsx("div",{className:"flex items-center justify-center h-32",children:e.jsxs("div",{className:"text-center text-slate-500",children:[e.jsx(is,{size:b.xl,className:"mx-auto mb-2 opacity-50"}),e.jsx("p",{className:"text-sm",children:"未找到匹配的结果"})]})})]})]}),z&&E&&e.jsx("div",{className:"fixed inset-0 bg-black/40 z-50 flex items-center justify-center p-4",children:e.jsxs("div",{className:"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:E.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(E.similarity*100),"%"]}),E.isContextRelevant&&e.jsx("span",{className:"text-xs bg-green-100 text-green-700 px-2 py-1 rounded",children:"✓ 上下文相关"}),E.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:["🤖 质量: ",(E.qualityScore*100).toFixed(0),"%"]}),((Q=E.stats)==null?void 0:Q.authorityScore)!==void 0&&e.jsxs("span",{className:"text-xs bg-purple-100 text-purple-700 px-2 py-1 rounded",children:["权威分: ",Math.round(E.stats.authorityScore*100)/100]})]})]}),e.jsx("button",{onClick:()=>C(!1),className:"p-1 hover:bg-slate-100 rounded transition-colors shrink-0",children:e.jsx(Ke,{size:b.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:E.content?e.jsx(Ze,{code:E.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:()=>C(!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(E.name),C(!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(et,{size:b.md}),"使用此片段"]})]})]})})]}):null},qa=({targets:t,filteredTargets:s,selectedTargetName:a,isScanning:r,scanProgress:l,scanFileList:o,scanResults:d,guardAudit:c,handleScanTarget:u,handleScanProject:S,handleUpdateScanResult:x,handleSaveExtracted:h,handlePromoteToCandidate:j,handleDeleteCandidate:M,onEditRecipe:P,isShellTarget:O,recipes:z=[],isSavingRecipe:C=!1})=>{var fe;const[E,p]=n.useState(null),[I,W]=n.useState(null),[Z,N]=n.useState(null),[G,Q]=n.useState({}),[R,V]=n.useState(null),[q,v]=n.useState(null),[_,w]=n.useState(!1),[D,K]=n.useState(),[te,i]=n.useState(),f=n.useRef(new Set),L=n.useRef([]),U=n.useRef(!1),ee=y=>{const F=(y.language||"").toLowerCase();return F==="objectivec"||F==="objc"||F==="objective-c"||F==="obj-c"?"objectivec":y.language||"swift"},ye=n.useCallback(async(y,F)=>{if(!f.current.has(y)){f.current.add(y),V(y);try{const Se=F.candidateId&&F.targetName?{targetName:F.targetName,candidateId:F.candidateId}:{candidate:F.candidate||{}},oe=await ie.getCandidateSimilarityEx(Se);Q(H=>({...H,[y]:oe.similar||[]}))}catch{Q(oe=>({...oe,[y]:[]}))}finally{V(null)}}},[]),Ne=n.useCallback(async(y,F,Se=[])=>{var J,he,Y;const oe=y.candidateTargetName||"",H=F.replace(/\.md$/i,"");let ce="";const $=z==null?void 0:z.find(de=>de.name===H||de.name.endsWith("/"+H));if($!=null&&$.content)ce=$.content;else try{ce=(await ie.getRecipeContentByName(H)).content}catch(de){const B=(J=de.response)==null?void 0:J.status,ne=((Y=(he=de.response)==null?void 0:he.data)==null?void 0:Y.message)||de.message;B===404?ae(`Recipe 不存在: ${H}`,{type:"error"}):ae(`加载 Recipe 失败: ${ne}`,{type:"error"});return}const X={[H]:ce};v({candidate:y,targetName:oe,recipeName:H,recipeContent:ce,similarList:Se.slice(0,3),recipeContents:X})},[z]),xe=n.useCallback(async(y,F,Se)=>{var Y,de;if(U.current)return;if(F==="cn"){x(y,{lang:"cn"});return}const oe=Se;if(!oe)return;const H=!!oe.summary_en,ce=!!oe.usageGuide_en;if(H&&ce){x(y,{lang:"en"});return}const $=oe.summary_cn??oe.summary??"",X=String(oe.usageGuide_cn??oe.usageGuide??""),J=!H&&$.trim().length>0,he=!ce&&X.trim().length>0;if(!J&&!he){x(y,{lang:"en"});return}U.current=!0,W(y);try{const B=await ie.translate(J?$:"",he?X:"");if(B!=null&&B.warning){ae(B.warning,{type:"error"});return}const ne={lang:"en"};B!=null&&B.summary_en&&(ne.summary_en=B.summary_en,ne.summary=B.summary_en),B!=null&&B.usageGuide_en&&(ne.usageGuide_en=B.usageGuide_en,ne.usageGuide=B.usageGuide_en),x(y,ne),ae("已翻译并切换到英文")}catch(B){ae(((de=(Y=B==null?void 0:B.response)==null?void 0:Y.data)==null?void 0:de.error)||(B==null?void 0:B.message)||"翻译失败,请检查网络或重试",{type:"error"})}finally{U.current=!1,W(null)}},[x]);return n.useEffect(()=>{const y=d.map((oe,H)=>oe.candidateId??`scan-${H}`),F=L.current;(y.length!==F.length||y.some((oe,H)=>oe!==F[H]))&&(f.current.clear(),L.current=y),d.forEach((oe,H)=>{const ce=oe.candidateId??`scan-${H}`;oe.candidateId&&oe.candidateTargetName?ye(ce,{targetName:oe.candidateTargetName,candidateId:oe.candidateId}):ye(ce,{candidate:{title:oe.title,summary:oe.summary,code:oe.code,usageGuide:oe.usageGuide}})})},[d,ye]),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(y=>{const F=O(y.name),Se=a===y.name;return e.jsxs("button",{onClick:()=>u(y),disabled:r,className:`w-full text-left p-3 rounded-lg flex items-center justify-between group transition-all border ${r?"opacity-50 cursor-not-allowed":"hover:bg-slate-50"} ${Se?"bg-blue-50 border-blue-200 ring-1 ring-blue-200":"bg-white border-transparent"} ${F?"opacity-90":""}`,children:[e.jsxs("div",{className:`flex flex-col max-w-[85%] ${F?"opacity-60":""}`,children:[e.jsxs("div",{className:"flex items-center gap-2",children:[!F&&e.jsx("div",{className:"w-1.5 h-1.5 rounded-full shrink-0 bg-blue-600"}),e.jsx("span",{className:`text-sm truncate ${F?"font-medium":"font-bold"} ${Se?"text-blue-700":""}`,children:y.name})]}),e.jsx("span",{className:"text-[10px] text-slate-400 truncate pl-3",children:y.packageName})]}),F?e.jsx("span",{className:"text-[9px] font-bold text-slate-300 border border-slate-100 px-1 rounded",children:"SHELL"}):e.jsx(Be,{size:b.sm,className:`shrink-0 ${Se?"text-blue-500 opacity-100":"text-blue-500 opacity-0 group-hover:opacity-100"} transition-opacity`})]},y.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(rt,{size:b.md,className:"text-indigo-500"}),e.jsx("span",{children:"全项目扫描结果"}),d.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(Be,{size:b.md,className:"text-blue-500"}),e.jsxs("span",{children:["Target: ",a]}),d.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(pt,{size:b.md,className:"text-slate-400"}),e.jsx("span",{children:"审核提取结果"})]}),d.length>0&&e.jsxs("span",{className:"text-slate-400 font-normal text-xs ml-1",children:["(",d.length," 条",(fe=d[0])!=null&&fe.trigger?" Candidate":"",")"]})]})}),e.jsxs("div",{className:"flex-1 overflow-y-auto p-6 space-y-8 relative",children:[r&&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(At,{size:b.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:l.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((y,F)=>e.jsx("div",{className:"text-xs font-mono text-slate-600 truncate",title:y.path,children:y.name},F))})]}),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(l.total?l.current/l.total*100:0,98)}%`}})}),e.jsx("p",{className:"text-xs text-slate-400 mt-3",children:l.total?`${Math.round(l.current/l.total*100)}%`:"0%"})]}),!r&&d.length===0&&e.jsxs("div",{className:"h-full flex flex-col items-center justify-center text-slate-400 text-center",children:[e.jsx(kt,{size:b.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-xs",children:["从左侧选择一个 ",e.jsx("span",{className:"font-bold text-blue-600",children:"Target"})," 进行单模块扫描,或点击 ",e.jsx("span",{className:"font-bold text-indigo-600",children:"全项目扫描"})," 对所有模块进行 AI 提取 + Guard 审计。"]})]}),!r&&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((y,F)=>e.jsx("span",{className:"text-xs font-mono bg-white border border-slate-200 text-slate-600 px-2 py-1 rounded",title:y.path,children:y.name},F))})]}),!r&&a==="__project__"&&(c==null?void 0:c.summary)&&e.jsxs("div",{className:`rounded-xl border p-4 ${c.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(Ve,{size:b.md,className:c.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:c.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 ${c.summary.totalViolations>0?"text-amber-700":"text-emerald-700"}`,children:c.summary.totalViolations})]}),c.summary.errors>0&&e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(_t,{size:b.sm,className:"text-red-500"}),e.jsxs("span",{className:"font-bold text-red-700",children:[c.summary.errors," 错误"]})]}),c.summary.warnings>0&&e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(_t,{size:b.sm,className:"text-amber-500"}),e.jsxs("span",{className:"font-bold text-amber-700",children:[c.summary.warnings," 警告"]})]})]})]}),d.map((y,F)=>{const Se=Z===F,oe=y.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"}),y.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(rt,{size:10})," PROJECT"]}):y.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(Be,{size:10})," ",y.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:y.title,onChange:H=>x(F,{title:H.target.value})})]}),e.jsxs("div",{className:"flex gap-2 shrink-0 pt-3",children:[j&&e.jsxs("button",{onClick:()=>j(y,F),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(Ws,{size:b.md}),"Candidate"]}),e.jsxs("button",{onClick:()=>h(y),disabled:C,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 ${y.mode==="full"?"bg-blue-600 text-white hover:bg-blue-700":"bg-amber-600 text-white hover:bg-amber-700"}`,children:[C?e.jsx(ze,{size:b.md,className:"animate-spin"}):e.jsx(os,{size:b.md}),C?"保存中...":"保存为 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:y.trigger,placeholder:"@cmd",onChange:H=>x(F,{trigger:H.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:y.category,onChange:H=>x(F,{category:H.target.value}),children:oa.filter(H=>H!=="All").map(H=>e.jsx("option",{value:H,children:H},H))})]}),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(F,{language:"swift"}),className:`px-2.5 py-0.5 rounded text-[10px] font-bold transition-all ${y.language==="swift"?"bg-white shadow-sm text-blue-600":"text-slate-400 hover:text-slate-500"}`,children:"Swift"}),e.jsx("button",{onClick:()=>x(F,{language:"objectivec"}),className:`px-2.5 py-0.5 rounded text-[10px] font-bold transition-all ${y.language==="objectivec"||y.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:()=>xe(F,"cn",y),disabled:I!==null,className:`px-2.5 py-0.5 rounded text-[10px] font-bold transition-all ${y.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:()=>xe(F,"en",y),disabled:I!==null,className:`px-2.5 py-0.5 rounded text-[10px] font-bold transition-all flex items-center gap-0.5 ${y.lang==="en"?"bg-white shadow-sm text-blue-600":"text-slate-400 hover:text-slate-500"} disabled:opacity-50 disabled:cursor-not-allowed`,children:[I===F?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(F,{mode:"full"}),className:`px-2.5 py-0.5 rounded text-[10px] font-bold transition-all ${y.mode==="full"?"bg-white shadow-sm text-blue-600":"text-slate-400 hover:text-slate-500"}`,children:"Snippet+Recipe"}),e.jsx("button",{onClick:()=>x(F,{mode:"preview"}),className:`px-2.5 py-0.5 rounded text-[10px] font-bold transition-all ${y.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:y.difficulty||"intermediate",onChange:H=>x(F,{difficulty:H.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:y.authority||3,onChange:H=>x(F,{authority:parseInt(H.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:y.knowledgeType||"code-pattern",onChange:H=>x(F,{knowledgeType:H.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:y.scope||"project-specific",onChange:H=>x(F,{scope:H.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"}),y.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:y.moduleName})]}),oe.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:()=>N(Z===F?null:F),className:`text-[11px] font-bold px-2 py-1 rounded-md transition-colors border ${Se?"text-blue-700 bg-blue-100 border-blue-300":"text-blue-600 bg-blue-50 border-blue-100 hover:bg-blue-100"}`,children:[Se?"收起":"编辑"," (",oe.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(F,{includeHeaders:y.includeHeaders===!1}),className:`w-7 h-4 rounded-full relative transition-colors ${y.includeHeaders!==!1?"bg-blue-600":"bg-slate-300"}`,title:y.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 ${y.includeHeaders!==!1?"right-0.5":"left-0.5"}`})}),e.jsx("span",{className:"text-[9px] font-bold text-slate-600",children:y.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:[(y.tags||[]).map((H,ce)=>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:[H,e.jsx("button",{onClick:()=>{const $=[...y.tags||[]];$.splice(ce,1),x(F,{tags:$})},className:"text-blue-400 hover:text-red-500 transition-colors leading-none text-[10px]",title:"移除",children:"×"})]},ce)),e.jsx("input",{className:"flex-1 min-w-[80px] text-[11px] text-slate-600 outline-none bg-transparent py-0.5",placeholder:(y.tags||[]).length===0?"按 Enter/逗号添加...":"",onKeyDown:H=>{const ce=H.currentTarget,$=ce.value.trim();if((H.key==="Enter"||H.key===","||H.key===",")&&$){H.preventDefault();const X=$.replace(/[,,]/g,"").trim();X&&!(y.tags||[]).includes(X)&&x(F,{tags:[...y.tags||[],X]}),ce.value=""}else if(H.key==="Backspace"&&!ce.value&&(y.tags||[]).length>0){const X=[...y.tags||[]];X.pop(),x(F,{tags:X})}},onBlur:H=>{const ce=H.currentTarget.value.trim().replace(/[,,]/g,"").trim();ce&&!(y.tags||[]).includes(ce)&&x(F,{tags:[...y.tags||[],ce]}),H.currentTarget.value=""}})]})]})]}),Se&&oe.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.jsx("label",{className:"text-[9px] font-bold text-slate-400 uppercase tracking-wider",children:"导入头文件"}),e.jsx("button",{onClick:()=>{const H=[...oe,y.language==="objectivec"?"#import <Module/Header.h>":"import ModuleName"];x(F,{headers:H})},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:oe.map((H,ce)=>e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("input",{className:"flex-1 text-xs font-mono bg-white border border-slate-200 rounded px-2 py-1 outline-none focus:border-blue-400",value:H,onChange:$=>{const X=[...oe];X[ce]=$.target.value,x(F,{headers:X})},placeholder:y.language==="objectivec"?"#import <Module/Header.h>":"import ModuleName"}),e.jsx("button",{onClick:()=>{const $=oe.filter((X,J)=>J!==ce);x(F,{headers:$})},className:"px-2 py-1 bg-red-500 text-white rounded hover:bg-red-600 text-[9px] font-bold",children:"删除"})]},ce))})]})]}),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 (摘要) - ",y.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:y.summary,onChange:H=>x(F,{summary:H.target.value})})]}),e.jsxs("div",{children:[e.jsxs("label",{className:"block text-[10px] font-bold text-slate-400 uppercase mb-1",children:["Usage Guide (使用指南) - ",y.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 y.usageGuide=="object"?JSON.stringify(y.usageGuide):y.usageGuide||"",onChange:H=>x(F,{usageGuide:H.target.value}),placeholder:"何时用 / 关键点 / 依赖..."})]}),(()=>{const H=y.candidateId??`scan-${F}`,ce=G[H],$=R===H,X=((ce==null?void 0:ce.length)??0)>0,J=(ce||[]).filter(Y=>Y.similarity>=.85),he=J.length>0;return X||$?e.jsxs("div",{className:"space-y-1.5",children:[he&&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:"高重复风险:"}),J.map(Y=>e.jsxs("button",{onClick:()=>Ne(y,Y.recipeName,ce||[]),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:[Y.recipeName.replace(/\.md$/i,"")," ",(Y.similarity*100).toFixed(0),"%"]},Y.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:"}),$?e.jsx("span",{className:"text-[10px] text-slate-400",children:"加载中..."}):(ce||[]).slice(0,5).map(Y=>e.jsxs("button",{onClick:()=>Ne(y,Y.recipeName,ce||[]),className:`text-[10px] font-bold px-2 py-1 rounded border transition-colors flex items-center gap-1 ${Y.similarity>=.85?"bg-red-50 text-red-700 border-red-200 hover:bg-red-100":Y.similarity>=.6?"bg-amber-50 text-amber-700 border-amber-200 hover:bg-amber-100":"bg-slate-50 text-slate-600 border-slate-200 hover:bg-slate-100"}`,title:`与 ${Y.recipeName} 相似 ${(Y.similarity*100).toFixed(0)}%,点击对比`,children:[e.jsx(wt,{size:b.xs}),Y.recipeName.replace(/\.md$/i,"")," ",(Y.similarity*100).toFixed(0),"%"]},Y.recipeName))]})]}):null})(),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 (标准使用示例)"}),E===F?e.jsxs("button",{type:"button",onClick:()=>p(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(rs,{size:b.xs})," 完成"]}):e.jsxs("button",{type:"button",onClick:()=>p(F),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(Vs,{size:b.xs})," 编辑"]})]}),E===F?e.jsx("div",{className:"rounded-xl overflow-hidden",children:e.jsx(qt,{value:y.code,onChange:H=>x(F,{code:H}),language:ee(y),height:`${Math.min(12,y.code.split(`
81
- `).length)*20+16}px`})}):e.jsx(Ze,{code:y.code,language:ee(y),showLineNumbers:!0})]})]})]},F)})]})]}),q&&(()=>{const y=q.candidate,F=ee(y),Se=()=>{const J=[];y.code&&J.push("## Snippet / Code Reference\n\n```"+F+`
82
- `+y.code+"\n```"),y.usageGuide&&J.push(`
83
- ## AI Context / Usage Guide
84
-
85
- `+y.usageGuide),navigator.clipboard.writeText(J.join(`
86
- `)||"").then(()=>ae("已复制候选内容"))},oe=()=>{const J=Ut(q.recipeContent);navigator.clipboard.writeText(J).then(()=>ae("已复制 Recipe 内容"))},H=async J=>{if(J===q.recipeName)return;const he=q.recipeContents[J];if(he)v(Y=>Y?{...Y,recipeName:J,recipeContent:he}:null);else{let Y="";const de=z==null?void 0:z.find(B=>B.name===J||B.name.endsWith("/"+J));if(de!=null&&de.content)Y=de.content;else try{Y=(await ie.getRecipeContentByName(J)).content}catch{return}v(B=>B?{...B,recipeName:J,recipeContent:Y,recipeContents:{...B.recipeContents,[J]:Y}}:null)}},ce=async()=>{if(!(!y.candidateId||!q.targetName||!M)&&window.confirm("确定删除该候选?"))try{await M(q.targetName,y.candidateId),v(null)}catch{}},$=()=>{h(y),v(null)},X=()=>{const J=(z==null?void 0:z.find(he=>he.name===q.recipeName||he.name.endsWith("/"+q.recipeName)))||{name:q.recipeName,content:q.recipeContent};P==null||P(J),v(null)};return e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/50 p-2",onClick:()=>v(null),children:e.jsxs("div",{className:"bg-white rounded-2xl shadow-2xl w-[min(95vw,1600px)] max-h-[92vh] flex flex-col",onClick:J=>J.stopPropagation(),children:[e.jsxs("div",{className:"flex justify-between items-center px-4 py-3 border-b border-slate-200 shrink-0",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("h3",{className:"font-bold text-slate-800",children:"候选 vs Recipe 对比"}),y.candidateId&&q.targetName&&e.jsx("button",{onClick:ce,className:"text-xs text-red-600 hover:bg-red-50 px-2 py-1 rounded",children:"删除候选"}),e.jsxs("button",{onClick:$,disabled:C,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",children:[C?e.jsx(ze,{size:b.xs,className:"animate-spin"}):null,"审核候选"]}),e.jsx("button",{onClick:X,className:"text-xs text-emerald-600 hover:bg-emerald-50 px-2 py-1 rounded",children:"审核 Recipe"})]}),e.jsx("button",{onClick:()=>v(null),className:"p-2 hover:bg-slate-100 rounded-lg transition-colors",children:e.jsx(Ke,{size:b.md})})]}),e.jsxs("div",{className:"flex-1 grid grid-cols-2 overflow-hidden min-h-0",style:{gridTemplateRows:"auto 1fr"},children:[e.jsxs("div",{className:"px-4 py-3 bg-blue-50 border-b border-r border-slate-100 flex flex-col justify-center min-h-0",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsxs("span",{className:"text-sm font-bold text-blue-700 truncate flex-1 min-w-0",title:y.title,children:["候选:",y.title]}),e.jsxs("button",{onClick:Se,className:"p-1.5 hover:bg-blue-100 rounded-lg text-blue-600 shrink-0",title:"复制",children:[" ",e.jsx($t,{size:b.sm})," "]})]}),e.jsx("div",{className:"min-h-[28px] mt-2 shrink-0"})]}),e.jsxs("div",{className:"px-4 py-3 bg-emerald-50 border-b border-slate-100 flex flex-col justify-center min-h-0",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsxs("span",{className:"text-sm font-bold text-emerald-700 truncate flex-1 min-w-0",title:q.recipeName,children:["Recipe:",q.recipeName.replace(/\.md$/i,"")]}),e.jsxs("button",{onClick:oe,className:"p-1.5 hover:bg-emerald-100 rounded-lg text-emerald-600 shrink-0",title:"复制",children:[" ",e.jsx($t,{size:b.sm})," "]})]}),q.similarList.length>1?e.jsx("div",{className:"flex flex-wrap gap-1 mt-2 shrink-0",children:q.similarList.map(J=>e.jsxs("button",{onClick:()=>H(J.recipeName),className:`text-[10px] font-bold px-2 py-1 rounded transition-colors ${q.recipeName===J.recipeName?"bg-emerald-200 text-emerald-800":"bg-white/80 text-emerald-600 hover:bg-emerald-100"}`,children:[J.recipeName.replace(/\.md$/i,"")," ",(J.similarity*100).toFixed(0),"%"]},J.recipeName))}):e.jsx("div",{className:"min-h-[28px] mt-2 shrink-0"})]}),e.jsxs("div",{className:"flex-1 overflow-auto p-4 min-h-0 border-r border-slate-200 markdown-body text-slate-700",children:[e.jsx("h2",{className:"text-lg font-bold mb-2 mt-4",children:"Snippet / Code Reference"}),y.code?e.jsx(Ze,{code:y.code,language:F,className:"!overflow-visible"}):e.jsx("p",{className:"text-slate-400 italic mb-3",children:"(无代码)"}),e.jsx("h2",{className:"text-lg font-bold mb-2 mt-4",children:"AI Context / Usage Guide"}),y.usageGuide?e.jsx(We,{content:y.usageGuide}):e.jsx("p",{className:"text-slate-400 italic",children:"(无使用指南)"})]}),e.jsx("div",{className:"flex-1 overflow-auto p-4 min-h-0",children:e.jsx(We,{content:q.recipeContent,stripFrontmatter:!0})})]})]})})})(),e.jsx(Ua,{isOpen:_,onClose:()=>w(!1),targetName:te,currentFile:D,language:"swift",onSelectRecipe:y=>{console.log("Selected recipe:",y)}})]})},Wa=72,Va=52,St=24,mt=40,us=36,Ye=140,xt=40,ut=8;function Ka(t,s){const a=new Set(t.map(c=>c.id)),r=new Map;for(const c of s)!a.has(c.from)||!a.has(c.to)||(r.has(c.from)||r.set(c.from,[]),r.get(c.from).push(c.to));const l=new Map,o=new Set;function d(c){if(l.has(c))return l.get(c);if(o.has(c))return 0;o.add(c);const u=r.get(c);if(!u||u.length===0)return l.set(c,0),o.delete(c),0;const S=1+Math.max(...u.map(d));return l.set(c,S),o.delete(c),S}return t.forEach(c=>d(c.id)),l}function Xa(t){return Math.ceil(t/ut)}function Ja(t,s){const a=Ka(t,s),r=new Map;for(const h of t){const j=a.get(h.id)??0;r.has(j)||r.set(j,[]),r.get(j).push(h.id)}const l=[...new Set(a.values())].sort((h,j)=>h-j),o=[...l].reverse(),d=new Map,c=new Map,u=Math.min(ut,Math.max(...l.map(h=>(r.get(h)??[]).length),1)),S=(u-1)*St+u*Ye;let x=mt;return o.forEach(h=>{const j=r.get(h)??[],M=Xa(j.length),P=x;for(let z=0;z<M;z++){const C=j.slice(z*ut,(z+1)*ut),E=(C.length-1)*St+C.length*Ye,p=(S-E)/2;C.forEach((I,W)=>{const Z=mt+us+p+W*(Ye+St)+Ye/2,N=x+xt/2;d.set(I,{x:Z,y:N})}),x+=z<M-1?Va:Wa}const O=x-P;c.set(h,{y:P,h:O})}),{positions:d,tiers:a,tierOrder:l,tierYRanges:c}}const Ya=()=>{const[t,s]=n.useState(null),[a,r]=n.useState(!0),[l,o]=n.useState(null),[d,c]=n.useState(null),[u,S]=n.useState("package"),x=async()=>{var v,_;r(!0),o(null);try{const w=await ie.getDepGraph(u);s({nodes:Array.isArray(w==null?void 0:w.nodes)?w.nodes:[],edges:Array.isArray(w==null?void 0:w.edges)?w.edges:[],projectRoot:(w==null?void 0:w.projectRoot)??null,generatedAt:w==null?void 0:w.generatedAt})}catch(w){o(((_=(v=w.response)==null?void 0:v.data)==null?void 0:_.error)||w.message||"Failed to load dependency graph")}finally{r(!1)}};n.useEffect(()=>{x()},[u]);const h=Array.isArray(t==null?void 0:t.nodes)?t.nodes:[],j=Array.isArray(t==null?void 0:t.edges)?t.edges:[],{positions:M,tiers:P,tierOrder:O,tierYRanges:z}=n.useMemo(()=>Ja(h,j),[h,j]),C=n.useMemo(()=>{const v=new Map;return h.forEach(_=>{const w=P.get(_.id)??0;v.has(w)||v.set(w,[]),v.get(w).push(_.id)}),v},[h,P]),E=n.useMemo(()=>[...O].reverse(),[O]),{dependsOn:p,dependedBy:I}=n.useMemo(()=>{const v=new Map,_=new Map;return j.forEach(w=>{v.has(w.from)||v.set(w.from,[]),v.get(w.from).push(w.to),_.has(w.to)||_.set(w.to,[]),_.get(w.to).push(w.from)}),{dependsOn:v,dependedBy:_}},[j]),W=Math.min(ut,Math.max(...O.map(v=>(C.get(v)??[]).length),1)),N=(W-1)*St+W*Ye+us*2,G=Math.max(600,mt*2+N),Q=Math.max(...[...M.values()].map(v=>v.y),0),R=Math.max(420,Q+xt/2+mt+20),V=[{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)"}],q=v=>V[Math.min(v,V.length-1)]??V[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"})}):l?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:l}),e.jsx("button",{type:"button",onClick:x,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||h.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(rt,{size:b.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:()=>{x()},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(nt,{size:b.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:R,viewBox:`0 0 ${G} ${R}`,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"})})}),E.map((v,_)=>{const w=q(_),D=z.get(v);return D?e.jsx("rect",{x:mt,y:D.y-xt/2-4,width:N,height:D.h+8,rx:8,fill:w.bg,stroke:w.border,strokeWidth:"1",opacity:.6},v):null}),h.map(v=>{const _=M.get(v.id);if(!_)return null;const w=P.get(v.id)??0,D=q(E.indexOf(w)),K=v.label.length>14?v.label.slice(0,13)+"…":v.label,te=d===v.id,i=d?(p.get(d)??[]).includes(v.id):!1,f=d?(I.get(d)??[]).includes(v.id):!1,L=d&&!te&&!i&&!f,U=d?te?{fill:"white",stroke:"rgb(59 130 246)",text:"rgb(30 64 175)",strokeWidth:3,opacity:1}:i?{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:D.border,text:D.text,strokeWidth:2,opacity:1};return e.jsxs("g",{style:{cursor:"pointer",opacity:U.opacity},onClick:()=>c(te?null:v.id),children:[e.jsx("rect",{x:_.x-Ye/2,y:_.y-xt/2,width:Ye,height:xt,rx:10,ry:10,fill:U.fill,stroke:U.stroke,strokeWidth:U.strokeWidth,filter:L?void 0:"url(#nodeShadow)"}),e.jsx("text",{x:_.x,y:_.y,textAnchor:"middle",dominantBaseline:"middle",fontSize:"12",fontWeight:"600",fill:U.text,pointerEvents:"none",children:K})]},v.id)})]}),d&&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:d}),e.jsx("button",{type:"button",onClick:()=>c(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:(p.get(d)??[]).length===0?e.jsx("li",{className:"text-slate-400",children:"无"}):(p.get(d)??[]).map(v=>e.jsxs("li",{children:["→ ",v]},v))})]}),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:(I.get(d)??[]).length===0?e.jsx("li",{className:"text-slate-400",children:"无"}):(I.get(d)??[]).map(v=>e.jsxs("li",{children:["← ",v]},v))})]})]})]})]}),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:["包列表 (",h.length,")"]}),e.jsx("ul",{className:"text-sm space-y-3 max-h-[280px] overflow-y-auto pr-1",children:h.map(v=>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:v.id}),v.packageDir&&e.jsxs("span",{className:"text-slate-500 text-xs",children:["· ",v.packageDir]})]}),v.targets&&v.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:v.targets.join(", ")})]})]},v.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:["依赖关系(小图)(",j.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:j.map((v,_)=>e.jsxs("li",{className:"flex items-center gap-2 text-slate-700",children:[e.jsx("span",{className:"font-semibold text-slate-800",children:v.from}),e.jsx("span",{className:"text-slate-400 shrink-0",children:"→"}),e.jsx("span",{className:"font-semibold text-slate-800",children:v.to})]},`${v.from}-${v.to}-${_}`))})]}),u==="target"&&e.jsxs("p",{className:"text-xs text-slate-500 mt-2",children:["Target 级节点格式:",e.jsx("span",{className:"font-mono",children:"Package::Target"})]})]})]})},Za=({onRefresh:t})=>{const[s,a]=n.useState({}),[r,l]=n.useState([]),[o,d]=n.useState(null),[c,u]=n.useState(!0),[S,x]=n.useState(!1),[h,j]=n.useState(!1),[M,P]=n.useState(""),[O,z]=n.useState(!1),[C,E]=n.useState({ruleId:"",message:"",severity:"warning",pattern:"",languages:["objc","swift"],note:"",dimension:""}),[p,I]=n.useState(!1),[W,Z]=n.useState(""),N=async()=>{try{const[_,w]=await Promise.all([ie.getGuardRules(),ie.getGuardViolations()]);a((_==null?void 0:_.rules)||{}),l((w==null?void 0:w.runs)||[])}catch{a({}),l([])}finally{u(!1)}};n.useEffect(()=>{N()},[]);const G=async()=>{if(window.confirm("确定清空所有 Guard 违反记录?"))try{await ie.clearViolations(),N(),t==null||t()}catch{}},Q=_=>{E(w=>({...w,languages:w.languages.includes(_)?w.languages.filter(D=>D!==_):[...w.languages,_]}))},R=async()=>{var _,w;if(!M.trim()){Z("请先输入语义描述");return}Z(""),z(!0);try{const K=await ie.generateGuardRule({description:M.trim()}),te=K.dimension;E({ruleId:K.ruleId||"",message:K.message||"",severity:K.severity==="error"?"error":"warning",pattern:K.pattern||"",languages:Array.isArray(K.languages)&&K.languages.length>0?K.languages:["objc","swift"],note:K.note!=null?String(K.note):"",dimension:te==="file"||te==="target"||te==="project"?te:""}),j(!0)}catch(D){Z(((w=(_=D==null?void 0:D.response)==null?void 0:_.data)==null?void 0:w.error)||(D==null?void 0:D.message)||"AI 生成失败")}finally{z(!1)}},V=async _=>{var w,D;if(_.preventDefault(),Z(""),!C.ruleId.trim()||!C.message.trim()||!C.pattern.trim()||C.languages.length===0){Z("请填写规则 ID、说明、正则和至少一种语言");return}I(!0);try{await ie.saveGuardRule({ruleId:C.ruleId.trim(),message:C.message.trim(),severity:C.severity,pattern:C.pattern.trim(),languages:C.languages,note:C.note.trim()||void 0,...C.dimension?{dimension:C.dimension}:{}}),E({ruleId:"",message:"",severity:"warning",pattern:"",languages:["objc","swift"],note:"",dimension:""}),P(""),j(!1),N(),t==null||t()}catch(K){Z(((D=(w=K==null?void 0:K.response)==null?void 0:w.data)==null?void 0:D.error)||(K==null?void 0:K.message)||"写入失败")}finally{I(!1)}};if(c)return e.jsx("div",{className:"p-6 text-slate-500",children:"加载中..."});const q=Object.entries(s),v=r.reduce((_,w)=>_+w.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(Ve,{size:b.xl,className:"text-blue-600"}),"Guard 规则与违反记录"]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("a",{href:da,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(Ks,{size:b.md})," 提交误报/建议"]}),e.jsxs("button",{type:"button",onClick:()=>x(!S),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:[S?e.jsx(Qe,{size:b.md}):e.jsx(et,{size:b.md}),"AI 写入规则"]}),r.length>0&&e.jsxs("button",{type:"button",onClick:G,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(Et,{size:b.sm})," 清空历史"]})]})]}),S&&e.jsxs("section",{className:"mb-6",children:[e.jsxs("div",{className:"p-4 bg-slate-50 border border-slate-200 rounded-xl space-y-3",children:[e.jsxs("div",{children:[e.jsx("label",{htmlFor:"semantic-input",className:"block text-xs font-medium text-slate-600 mb-1",children:"语义描述(由 AI 生成规则表单)"}),e.jsx("textarea",{id:"semantic-input",name:"semanticInput",value:M,onChange:_=>{P(_.target.value),Z("")},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:R,disabled:O||!M.trim(),className:"mt-2 px-4 py-2 bg-slate-600 text-white text-sm rounded-lg hover:bg-slate-700 disabled:opacity-50",children:O?"生成中...":"AI 生成"}),W&&e.jsx("p",{className:"mt-2 text-sm text-red-600",children:W})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{type:"button",onClick:()=>j(!h),className:"text-sm font-medium text-blue-600 hover:text-blue-700",children:h?"收起表单":"展开 / 编辑表单"}),C.ruleId&&e.jsxs("span",{className:"text-xs text-slate-500",children:["已生成规则 ID:",C.ruleId]})]})]}),h&&e.jsxs("form",{onSubmit:V,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:C.ruleId,onChange:_=>E(w=>({...w,ruleId:_.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:C.severity,onChange:_=>E(w=>({...w,severity:_.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:C.message,onChange:_=>E(w=>({...w,message:_.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:C.pattern,onChange:_=>E(w=>({...w,pattern:_.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:C.languages.includes("objc"),onChange:()=>Q("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:C.languages.includes("swift"),onChange:()=>Q("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:C.dimension,onChange:_=>E(w=>({...w,dimension:_.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:C.note,onChange:_=>E(w=>({...w,note:_.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:p,className:"px-4 py-2 bg-blue-600 text-white text-sm rounded-lg hover:bg-blue-700 disabled:opacity-50",children:p?"写入中...":"确认写入"}),e.jsx("button",{type:"button",onClick:()=>j(!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:q.length===0?e.jsx("tr",{children:e.jsx("td",{colSpan:5,className:"py-4 px-4 text-slate-500",children:"暂无规则"})}):q.map(([_,w])=>e.jsxs("tr",{className:"border-b border-slate-100 last:border-0",children:[e.jsx("td",{className:"py-2 px-4 font-mono text-xs",children:_}),e.jsx("td",{className:"py-2 px-4",children:e.jsx("span",{className:`text-xs font-medium px-1.5 py-0.5 rounded ${w.severity==="error"?"bg-red-100 text-red-700":"bg-amber-100 text-amber-700"}`,children:w.severity})}),e.jsx("td",{className:"py-2 px-4 text-slate-700",children:w.message}),e.jsx("td",{className:"py-2 px-4 text-slate-500",children:(w.languages||[]).join(", ")}),e.jsx("td",{className:"py-2 px-4 text-slate-500 text-xs",children:w.dimension==="file"?"同文件":w.dimension==="target"?"同 target":w.dimension==="project"?"同项目":"—"})]},_))})]})})]}),e.jsxs("section",{children:[e.jsxs("h3",{className:"text-sm font-semibold text-slate-700 mb-3",children:["违反记录(共 ",r.length," 次运行,",v," 处违反)"]}),r.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:r.map(_=>{const w=o===_.id,D=_.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:()=>d(w?null:_.id),className:"w-full flex items-center gap-2 py-3 px-4 text-left hover:bg-slate-50 transition-colors",children:[w?e.jsx(Qe,{size:b.md}):e.jsx(et,{size:b.md}),e.jsx("span",{className:"font-mono text-sm text-slate-700",children:_.filePath}),e.jsx("span",{className:"text-xs text-slate-400",children:new Date(_.triggeredAt).toLocaleString()}),D?e.jsxs("span",{className:"ml-auto flex items-center gap-1 text-amber-600 text-xs font-medium",children:[e.jsx(_t,{size:b.sm})," ",_.violations.length," 处违反"]}):e.jsx("span",{className:"ml-auto text-slate-400 text-xs",children:"无违反"})]}),w&&e.jsx("div",{className:"border-t border-slate-100 bg-slate-50/50 p-4",children:_.violations.length===0?e.jsx("p",{className:"text-sm text-slate-500",children:"本次运行未发现违反。"}):e.jsx("ul",{className:"space-y-2",children:_.violations.map((K,te)=>{var f;const i=s[K.ruleId];return e.jsxs("li",{className:"flex items-start gap-2 text-sm",children:[K.severity==="error"?e.jsx(is,{size:b.md,className:"text-red-500 shrink-0 mt-0.5"}):e.jsx(_t,{size:b.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:["[",K.ruleId,"] ",K.filePath?`${K.filePath}:${K.line}`:`L${K.line}`]}),K.dimension&&e.jsx("span",{className:"ml-1.5 text-xs px-1.5 py-0.5 rounded bg-slate-200 text-slate-600",children:K.dimension==="file"?"同文件":K.dimension==="target"?"同 target":"同项目"}),e.jsx("span",{className:"text-slate-700 ml-2",children:K.message})]}),K.snippet&&e.jsx("pre",{className:"text-xs text-slate-600 bg-slate-100 p-2 rounded overflow-x-auto",children:K.snippet}),i&&(i.rationale||((f=i.fixSuggestions)==null?void 0:f.length)||i.sourceRecipe||i.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:[i.rationale&&e.jsxs("div",{className:"flex items-start gap-1.5",children:[e.jsx(ot,{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:i.rationale})]})]}),i.fixSuggestions&&i.fixSuggestions.length>0&&e.jsxs("div",{className:"flex items-start gap-1.5",children:[e.jsx(Xs,{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:i.fixSuggestions.map((L,U)=>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:L}),e.jsx("button",{className:"ml-1 text-blue-500 hover:text-blue-700",title:"复制修复建议",onClick:()=>navigator.clipboard.writeText(L),children:"⎘"})]},U))})]})]}),i.sourceRecipe&&e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(Js,{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:i.sourceRecipe})]}),!i.rationale&&i.note&&e.jsxs("div",{className:"text-slate-500 italic",children:["备注:",i.note]})]})]})]},te)})})})]},_.id)})})]})]})},Qa=({chatHistory:t,userInput:s,setUserInput:a,handleChat:r,isAiThinking:l})=>{const o=n.useRef(null),d=n.useRef(null);n.useEffect(()=>{const u=requestAnimationFrame(()=>{var S;(S=o.current)==null||S.scrollIntoView({behavior:"smooth"})});return()=>cancelAnimationFrame(u)},[t,l]);const c=(u,S)=>S==="model"?e.jsx(We,{content:u,className:"text-slate-800"}):e.jsx("div",{className:"whitespace-pre-wrap break-words",children:u});return e.jsxs("div",{className:"max-w-4xl mx-auto flex flex-col h-full bg-slate-50",children:[e.jsxs("div",{ref:d,className:"flex-1 overflow-y-auto space-y-3 p-4",children:[t.length===0?e.jsx("div",{className:"text-center text-slate-400 mt-8",children:e.jsx("p",{className:"text-sm",children:"开始聊天吧,询问关于你的项目的任何问题"})}):t.map((u,S)=>e.jsx("div",{className:`flex ${u.role==="user"?"justify-end":"justify-start"}`,children:e.jsx("div",{className:`max-w-[75%] p-3 rounded-lg text-sm ${u.role==="user"?"bg-blue-600 text-white rounded-br-none":"bg-white border border-slate-200 text-slate-800 rounded-bl-none shadow-sm"}`,children:c(u.text,u.role)})},S)),l&&e.jsx("div",{className:"flex justify-start",children:e.jsx("div",{className:"bg-white border border-slate-200 text-slate-800 p-3 rounded-lg rounded-bl-none shadow-sm",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("div",{className:"flex gap-1",children:[e.jsx("div",{className:"w-2 h-2 bg-slate-400 rounded-full animate-bounce",style:{animationDelay:"0ms"}}),e.jsx("div",{className:"w-2 h-2 bg-slate-400 rounded-full animate-bounce",style:{animationDelay:"150ms"}}),e.jsx("div",{className:"w-2 h-2 bg-slate-400 rounded-full animate-bounce",style:{animationDelay:"300ms"}})]}),e.jsx("span",{className:"text-xs text-slate-400",children:"AI 思考中..."})]})})}),e.jsx("div",{ref:o})]}),e.jsx("div",{className:"border-t border-slate-200 p-4 bg-white",children:e.jsxs("form",{onSubmit:r,className:"flex gap-2",children:[e.jsx("input",{type:"text",value:s,onChange:u=>a(u.target.value),placeholder:"Ask anything about your project...",disabled:l,className:"flex-1 px-4 py-2 outline-none text-sm border border-slate-200 rounded-lg focus:border-blue-500 focus:ring-1 focus:ring-blue-500 disabled:bg-slate-100 disabled:text-slate-400"}),e.jsx("button",{type:"submit",disabled:l||!s.trim(),className:"bg-blue-600 text-white px-5 py-2 rounded-lg text-sm font-medium hover:bg-blue-700 transition-colors disabled:bg-slate-300 disabled:cursor-not-allowed",children:"Ask"})]})})]})},ft=24,el=11,jt=60,Xe={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"},yt={depends_on:"依赖",requires:"需要",extends:"扩展",implements:"实现",inherits:"继承",enforces:"约束",related:"关联",conflicts:"冲突",calls:"调用",prerequisite:"前置",data_flow_to:"数据流",references:"引用",alternative:"替代",deprecated_by:"废弃",solves:"解决"};function tl(t,s){const a=new Set;for(const c of t)a.add(c.fromId),a.add(c.toId);const r=[],l=400,o=300;let d=0;for(const c of a){const u=d/a.size*2*Math.PI,S=150+Math.random()*100;r.push({id:c,label:s[c]||c.substring(0,12),type:"recipe",x:l+S*Math.cos(u),y:o+S*Math.sin(u),vx:0,vy:0}),d++}return r}function sl(t,s,a=120){const r=t.map(c=>({...c})),l=new Map(r.map(c=>[c.id,c])),o=400,d=300;for(let c=0;c<a;c++){const S=8e3*(1-c/a),x=.02,h=.005,j=.85;for(let M=0;M<r.length;M++)for(let P=M+1;P<r.length;P++){const O=r[M],z=r[P];let C=z.x-O.x,E=z.y-O.y,p=Math.sqrt(C*C+E*E)||1;const I=S/(p*p),W=C/p*I,Z=E/p*I;O.vx-=W,O.vy-=Z,z.vx+=W,z.vy+=Z}for(const M of s){const P=l.get(M.fromId),O=l.get(M.toId);if(!P||!O)continue;let z=O.x-P.x,C=O.y-P.y,E=Math.sqrt(z*z+C*C)||1;const I=x*(E-120),W=z/E*I,Z=C/E*I;P.vx+=W,P.vy+=Z,O.vx-=W,O.vy-=Z}for(const M of r)M.vx+=(o-M.x)*h,M.vy+=(d-M.y)*h;for(const M of r)M.vx*=j,M.vy*=j,M.x+=M.vx,M.y+=M.vy}return r}const al=()=>{const[t,s]=n.useState([]),[a,r]=n.useState({}),[l,o]=n.useState(null),[d,c]=n.useState(!0),[u,S]=n.useState(null),[x,h]=n.useState(null),[j,M]=n.useState(null),[P,O]=n.useState(1),[z,C]=n.useState({x:0,y:0}),E=n.useRef(null),p=n.useRef(!1),I=n.useRef({x:0,y:0}),W=async()=>{var i,f;c(!0),S(null);try{const[L,U]=await Promise.all([ie.getKnowledgeGraph(),ie.getGraphStats()]);s(L.edges||[]),r(L.nodeLabels||{}),o(U)}catch(L){S(((f=(i=L.response)==null?void 0:i.data)==null?void 0:f.error)||L.message||"加载知识图谱失败")}finally{c(!1)}};n.useEffect(()=>{W()},[]);const Z=n.useMemo(()=>{if(t.length===0)return[];const i=tl(t,a);return sl(i,t)},[t,a]),N=n.useMemo(()=>{if(Z.length===0)return{x:0,y:0,w:800,h:600};let i=1/0,f=1/0,L=-1/0,U=-1/0;for(const ee of Z)i=Math.min(i,ee.x),f=Math.min(f,ee.y),L=Math.max(L,ee.x),U=Math.max(U,ee.y);return{x:i-jt*2,y:f-jt*2,w:L-i+jt*4,h:U-f+jt*4}},[Z]),G=n.useMemo(()=>new Map(Z.map(i=>[i.id,i])),[Z]),Q=n.useMemo(()=>x?new Set(t.filter(i=>i.fromId===x||i.toId===x).map(i=>i.id)):new Set,[x,t]),[R,V]=n.useState(new Set);n.useEffect(()=>{const i=new Set(t.map(f=>f.relation));V(i)},[t]);const q=n.useMemo(()=>t.filter(i=>R.has(i.relation)),[t,R]),v=i=>{V(f=>{const L=new Set(f);return L.has(i)?L.delete(i):L.add(i),L})},_=n.useCallback(i=>{i.button===0&&(p.current=!0,I.current={x:i.clientX,y:i.clientY})},[]),w=n.useCallback(i=>{if(!p.current)return;const f=i.clientX-I.current.x,L=i.clientY-I.current.y;I.current={x:i.clientX,y:i.clientY},C(U=>({x:U.x+f,y:U.y+L}))},[]),D=n.useCallback(()=>{p.current=!1},[]),K=i=>`arrow-${i.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(u)return e.jsxs("div",{className:"flex flex-col items-center justify-center h-full gap-4",children:[e.jsx("p",{className:"text-red-500",children:u}),e.jsx("button",{onClick:W,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(Ot,{size:48,className:"text-slate-300"}),e.jsx("p",{className:"text-lg font-medium",children:"知识图谱为空"}),e.jsx("p",{className:"text-sm",children:"请先通过 Bootstrap 初始化知识库,然后审核候选为 Recipe,关系将自动同步到图谱。"}),e.jsxs("button",{onClick:W,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(nt,{size:b.sm})," 刷新"]})]});const te=[...new Set(t.map(i=>i.relation))].sort();return e.jsxs("div",{className:"h-full flex flex-col",children:[e.jsxs("div",{className:"flex items-center justify-between mb-4",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(Ot,{size:b.lg,className:"text-blue-600"}),e.jsx("h2",{className:"text-lg font-bold text-slate-800",children:"知识图谱"}),l&&e.jsxs("span",{className:"text-xs text-slate-500 bg-slate-100 px-2 py-1 rounded-full",children:[Z.length," 节点 · ",l.totalEdges," 条关系"]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{onClick:()=>O(i=>Math.min(i+.2,3)),className:"p-1.5 rounded-lg bg-slate-100 hover:bg-slate-200 transition-colors",title:"放大",children:e.jsx(Ys,{size:b.sm})}),e.jsx("button",{onClick:()=>O(i=>Math.max(i-.2,.3)),className:"p-1.5 rounded-lg bg-slate-100 hover:bg-slate-200 transition-colors",title:"缩小",children:e.jsx(Zs,{size:b.sm})}),e.jsx("button",{onClick:()=>{O(1),C({x:0,y:0})},className:"p-1.5 rounded-lg bg-slate-100 hover:bg-slate-200 transition-colors",title:"重置视图",children:e.jsx(Qs,{size:b.sm})}),e.jsx("button",{onClick:W,className:"p-1.5 rounded-lg bg-slate-100 hover:bg-slate-200 transition-colors",title:"刷新",children:e.jsx(nt,{size:b.sm})})]})]}),e.jsx("div",{className:"flex flex-wrap gap-2 mb-3",children:te.map(i=>{var f;return e.jsxs("button",{onClick:()=>v(i),className:`flex items-center gap-1.5 px-2 py-1 rounded-full text-xs font-medium transition-all border ${R.has(i)?"border-transparent shadow-sm":"border-slate-200 bg-white text-slate-400 opacity-50"}`,style:R.has(i)?{backgroundColor:(Xe[i]||"#6b7280")+"18",color:Xe[i]||"#6b7280"}:{},children:[e.jsx("span",{className:"w-2.5 h-2.5 rounded-full",style:{backgroundColor:Xe[i]||"#6b7280"}}),yt[i]||i,((f=l==null?void 0:l.byRelation)==null?void 0:f[i])&&e.jsxs("span",{className:"opacity-60",children:["(",l.byRelation[i],")"]})]},i)})}),e.jsxs("div",{className:"flex-1 rounded-xl border border-slate-200 bg-white overflow-hidden relative",style:{cursor:p.current?"grabbing":"grab"},children:[e.jsxs("svg",{ref:E,width:"100%",height:"100%",viewBox:`${N.x} ${N.y} ${N.w} ${N.h}`,onMouseDown:_,onMouseMove:w,onMouseUp:D,onMouseLeave:D,style:{transform:`scale(${P}) translate(${z.x/P}px, ${z.y/P}px)`},children:[e.jsx("defs",{children:te.map(i=>e.jsx("marker",{id:K(i),viewBox:"0 0 10 8",refX:"10",refY:"4",markerWidth:"8",markerHeight:"6",orient:"auto-start-reverse",children:e.jsx("path",{d:"M0,0 L10,4 L0,8 Z",fill:Xe[i]||"#6b7280"})},i))}),q.map(i=>{const f=G.get(i.fromId),L=G.get(i.toId);if(!f||!L)return null;const U=x?Q.has(i.id):!0,ee=j===i.id,ye=x?U?1:.1:ee?1:.6,Ne=L.x-f.x,xe=L.y-f.y,fe=Math.sqrt(Ne*Ne+xe*xe)||1,y=Ne/fe*ft,F=xe/fe*ft;return e.jsxs("g",{children:[e.jsx("line",{x1:f.x+y,y1:f.y+F,x2:L.x-y,y2:L.y-F,stroke:Xe[i.relation]||"#6b7280",strokeWidth:ee?2.5:1.5,opacity:ye,markerEnd:`url(#${K(i.relation)})`,onMouseEnter:()=>M(i.id),onMouseLeave:()=>M(null),style:{cursor:"pointer",transition:"opacity 0.2s"}}),ee&&e.jsx("text",{x:(f.x+L.x)/2,y:(f.y+L.y)/2-8,textAnchor:"middle",fontSize:10,fill:Xe[i.relation]||"#6b7280",fontWeight:600,children:yt[i.relation]||i.relation})]},i.id)}),Z.map(i=>{var ee;const f=x===i.id,L=x?Q.size>0&&t.some(ye=>ye.fromId===x&&ye.toId===i.id||ye.toId===x&&ye.fromId===i.id):!1,U=x?f||L?1:.15:1;return e.jsxs("g",{onClick:ye=>{ye.stopPropagation(),h(f?null:i.id)},style:{cursor:"pointer",transition:"opacity 0.2s"},opacity:U,children:[e.jsx("circle",{cx:i.x,cy:i.y,r:ft,fill:f?"#3b82f6":"#f8fafc",stroke:f?"#2563eb":"#cbd5e1",strokeWidth:f?2.5:1.5}),e.jsx("text",{x:i.x,y:i.y+ft+14,textAnchor:"middle",fontSize:el,fill:f?"#1e40af":"#475569",fontWeight:f?600:400,children:i.label.length>20?i.label.substring(0,18)+"…":i.label}),e.jsx("text",{x:i.x,y:i.y+4,textAnchor:"middle",fontSize:9,fill:f?"#ffffff":"#64748b",fontWeight:600,children:((ee=i.label.split("/").pop())==null?void 0:ee.substring(0,4).toUpperCase())||"?"})]},i.id)})]}),x&&e.jsx("button",{className:"absolute top-2 right-2 text-xs text-slate-400 hover:text-slate-600 bg-white/80 px-2 py-1 rounded",onClick:()=>h(null),children:"取消选中"})]}),x&&e.jsxs("div",{className:"mt-3 p-4 bg-slate-50 rounded-xl border border-slate-200",children:[e.jsx("h3",{className:"font-semibold text-sm text-slate-700 mb-2",children:a[x]||x}),e.jsxs("div",{className:"grid grid-cols-2 gap-2 text-xs",children:[e.jsxs("div",{children:[e.jsx("span",{className:"text-slate-500",children:"出边(依赖):"}),e.jsxs("ul",{className:"mt-1 space-y-0.5",children:[t.filter(i=>i.fromId===x&&R.has(i.relation)).map(i=>e.jsxs("li",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"w-2 h-2 rounded-full",style:{backgroundColor:Xe[i.relation]||"#6b7280"}}),e.jsx("span",{className:"text-slate-600",children:yt[i.relation]||i.relation}),e.jsx("span",{className:"text-slate-400",children:"→"}),e.jsx("button",{className:"text-blue-600 hover:underline",onClick:()=>h(i.toId),children:a[i.toId]||i.toId.substring(0,12)})]},i.id)),t.filter(i=>i.fromId===x&&R.has(i.relation)).length===0&&e.jsx("li",{className:"text-slate-400",children:"无"})]})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-slate-500",children:"入边(被依赖):"}),e.jsxs("ul",{className:"mt-1 space-y-0.5",children:[t.filter(i=>i.toId===x&&R.has(i.relation)).map(i=>e.jsxs("li",{className:"flex items-center gap-1.5",children:[e.jsx("button",{className:"text-blue-600 hover:underline",onClick:()=>h(i.fromId),children:a[i.fromId]||i.fromId.substring(0,12)}),e.jsx("span",{className:"text-slate-400",children:"→"}),e.jsx("span",{className:"text-slate-600",children:yt[i.relation]||i.relation})]},i.id)),t.filter(i=>i.toId===x&&R.has(i.relation)).length===0&&e.jsx("li",{className:"text-slate-400",children:"无"})]})]})]})]})]})},ll=()=>{const t=n.useRef(null),s=n.useRef(!0),a=`// AutoSnippet Xcode 模拟器
87
- // 支持的指令:
88
- // // as:search <query> - 搜索代码片段
89
- // // as:create <query> - 创建代码片段
90
- // // as:audit <path> - 审计代码
91
- //
92
- // 示例:
93
- // // as:search useState hooks
94
- // // as:create custom form validation utility
95
- // // as:audit /src/components
96
- `,r=n.useRef(a),l=n.useRef(0),[o,d]=n.useState({content:a,cursorPos:0,cursorLine:0,cursorCol:0}),[c,u]=n.useState([]),[S,x]=n.useState(""),[h,j]=n.useState(!1),[M,P]=n.useState(!1),[O,z]=n.useState(!0),[C,E]=n.useState(null),[p,I]=n.useState(new Set),[W,Z]=n.useState(""),[N,G]=n.useState(null),Q=(f,L)=>{const U=f.split(`
97
- `);let ee=0,ye=0,Ne=0;for(let xe=0;xe<U.length;xe++){if(Ne+U[xe].length+1>L){ee=xe,ye=L-Ne;break}Ne+=U[xe].length+1}return{line:ee,col:ye}},R=(f,L=0)=>{r.current=f,l.current=L;const{line:U,col:ee}=Q(f,L);d({content:f,cursorPos:L,cursorLine:U,cursorCol:ee}),q(f)},V=f=>{l.current=f;const{line:L,col:U}=Q(r.current,f);d(ee=>({...ee,cursorPos:f,cursorLine:L,cursorCol:U}))};n.useEffect(()=>{s.current=!0,q(o.content),v();const f=()=>{t.current&&t.current.clientHeight};return window.addEventListener("resize",f),()=>{s.current=!1,window.removeEventListener("resize",f)}},[]);const q=(f=o.content)=>{const L=f.split(`
98
- `),U=[];L.forEach((ee,ye)=>{const Ne=ee.match(/\/\/\s*as:(search|create|audit)\s+(.+)/);Ne&&U.push({line:ye,type:Ne[1],directive:Ne[0],query:Ne[2].trim()})}),u(U)},v=async()=>{try{const L=await fetch("/api/v1/commands/files/tree");if(L.ok){const U=await L.json(),ee=U.tree||U;E(ee),ee!=null&&ee.path&&I(new Set([ee.path]));return}}catch(L){console.error("Failed to load file tree from API:",L)}E({type:"folder",name:"src",path:"/src",children:[{type:"file",name:"index.ts",path:"/src/index.ts"},{type:"folder",name:"components",path:"/src/components",children:[{type:"file",name:"Button.tsx",path:"/src/components/Button.tsx"},{type:"file",name:"Header.tsx",path:"/src/components/Header.tsx"},{type:"file",name:"Footer.tsx",path:"/src/components/Footer.tsx"}]},{type:"folder",name:"hooks",path:"/src/hooks",children:[{type:"file",name:"useAuth.ts",path:"/src/hooks/useAuth.ts"},{type:"file",name:"useFetch.ts",path:"/src/hooks/useFetch.ts"}]},{type:"folder",name:"utils",path:"/src/utils",children:[{type:"file",name:"helpers.ts",path:"/src/utils/helpers.ts"},{type:"file",name:"validators.ts",path:"/src/utils/validators.ts"}]}]})},_=async f=>{try{const L=await fetch(`/api/v1/commands/files/read?path=${encodeURIComponent(f)}`);if(!L.ok)throw new Error(`Open failed with status ${L.status}`);const U=await L.json();R(U.content||"",0),Z(U.path||f),x("")}catch(L){console.error("Open file failed:",L),x(`✗ 打开文件失败: ${L instanceof Error?L.message:"未知错误"}`)}},w=async()=>{try{await fetch("/api/v1/commands/files/save",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:W,content:o.content})})}catch(f){console.error("Save failed:",f)}},D=()=>{window.confirm("确定要清空编辑器吗?")&&R("",0)},K=async f=>{var L;j(!0),G(c.indexOf(f));try{console.log(`[Execute] 触发 ${f.type} 指令...`,{query:f.query,line:f.line});const U=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"})}),ee=await U.json();if(console.log("[Execute] 响应:",ee),!U.ok)throw new Error(ee.error||"执行失败");if(f.type==="search"&&ee.results&&ee.results.length>0){console.log(`[Execute] 搜索到 ${ee.results.length} 个结果,准备显示 NativeUI 弹窗`);const ye=ee.results.map((fe,y)=>`${y+1}. ${fe.title} (${fe.category||"uncategorized"})`),xe=await(await fetch("/api/v1/commands/execute",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({type:"list",title:`搜索结果: ${f.query}`,options:ye})})).json();if(xe.success&&((L=xe.result)==null?void 0:L.selectedIndex)>=0){const fe=ee.results[xe.result.selectedIndex];console.log(`[Execute] 用户选择了: ${fe.title}`);const y=o.content.split(`
99
- `),F=f.line+1,oe=(fe.body||`// ${fe.title}`).split(`
100
- `);y.splice(F,0,...oe);const H=y.join(`
101
- `),ce=o.content.split(`
102
- `).slice(0,F).join(`
103
- `).length+1;R(H,ce),console.log(`✓ 已插入代码片段: ${fe.title}`)}else console.log("[Execute] 用户取消了选择")}else f.type==="search"&&console.warn("[Execute] 未找到匹配的搜索结果");ee.success&&console.log(`✓ 指令已执行: ${ee.message}`)}catch(U){console.error(`✗ 错误: ${U instanceof Error?U.message:"执行失败"}`)}finally{j(!1)}},te=(f,L=60)=>{if(f.length<=L)return f;const U=f.split("/");if(U.length<=2)return f;const ee=U[U.length-1],ye=U.slice(0,2).join("/");if(ye.length+ee.length+5>L){const xe=L-ee.length-5;return`${ye.substring(0,Math.max(10,xe))}/.../${ee}`}const Ne=L-ye.length-ee.length-5;if(Ne>0&&U.length>3){let fe=U.slice(2,-1).join("/");return fe.length>Ne&&(fe="..."),`${ye}/${fe}/${ee}`}return`${ye}/.../${ee}`},i=(f,L=0)=>{if(!f)return null;if(f.type==="folder"){const U=p.has(f.path);return e.jsxs("div",{children:[e.jsxs("div",{className:"file-tree-item folder-item",onClick:()=>{const ee=new Set(p);U?ee.delete(f.path):ee.add(f.path),I(ee)},style:{paddingLeft:`${L*16}px`},children:[e.jsx(Qe,{size:b.sm,className:`folder-toggle ${U?"expanded":""}`}),e.jsx(Jt,{size:b.sm,className:"folder-icon"}),e.jsx("span",{className:"file-name",children:f.name})]}),U&&f.children&&e.jsx("div",{children:f.children.map(ee=>i(ee,L+1))})]},f.path)}else return e.jsxs("div",{className:`file-tree-item file-item ${W===f.path?"active":""}`,onClick:()=>_(f.path),style:{paddingLeft:`${L*16}px`},children:[e.jsx(aa,{size:b.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:()=>z(!O),title:"切换侧栏",children:e.jsx(ea,{size:b.md})}),e.jsxs("div",{className:"file-info",title:W,children:[e.jsx(zt,{size:b.sm}),e.jsx("span",{className:"file-name",children:te(W||"untitled.js",80)})]})]}),e.jsxs("div",{className:"toolbar-right",children:[e.jsx("button",{className:"toolbar-btn",onClick:w,title:"保存",children:e.jsx(cs,{size:b.md})}),e.jsx("button",{className:"toolbar-btn",onClick:D,title:"清空",children:e.jsx(Et,{size:b.md})}),e.jsx("button",{className:"toolbar-btn",title:"更多选项",children:e.jsx(ta,{size:b.md})})]})]}),e.jsxs("div",{className:"xcode-main",children:[O&&e.jsxs("div",{className:"xcode-sidebar",children:[e.jsxs("div",{className:"sidebar-header",children:[e.jsx(Jt,{size:b.md}),e.jsx("h3",{children:"文件浏览"})]}),e.jsx("div",{className:"file-tree",children:C&&i(C)})]}),e.jsxs("div",{className:"xcode-editor-wrapper",children:[e.jsx("div",{className:"xcode-editor",children:e.jsx(qt,{value:o.content,onChange:f=>R(f,l.current),onCursorChange:V,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(`
104
- `).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(It,{size:b.md}),e.jsx("h3",{children:"检测到的指令"}),e.jsx("span",{className:"count",children:c.length})]}),c.length===0?e.jsxs("div",{className:"empty-state",children:[e.jsx(vt,{size:32}),e.jsx("p",{children:"暂无指令"}),e.jsx("small",{children:"在代码中添加 // as:search 来创建指令"})]}):e.jsx("div",{className:"directives-list",children:c.map((f,L)=>e.jsxs("div",{className:`directive-card ${f.type} ${N===L?"active":""}`,onClick:()=>G(L),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:U=>{U.stopPropagation(),K(f)},disabled:h,children:h&&N===L?e.jsxs(e.Fragment,{children:[e.jsx(ze,{size:b.xs,className:"spin"}),"执行中..."]}):e.jsxs(e.Fragment,{children:[e.jsx(sa,{size:b.xs}),"执行"]})})]},L))})]}),S&&e.jsxs("div",{className:"result-section result",children:[e.jsxs("div",{className:"section-header",children:[e.jsx(it,{size:b.md}),e.jsx("h3",{children:"执行结果"})]}),e.jsx("div",{className:"result-content",children:e.jsx("pre",{children:S})})]})]})]}),M&&e.jsx("div",{className:"result-modal-backdrop",onClick:()=>P(!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:()=>P(!1),children:"✕"})]}),e.jsx("div",{className:"result-modal-content",children:e.jsx("pre",{children:S})}),e.jsxs("div",{className:"result-modal-footer",children:[e.jsx("button",{className:"result-modal-btn",onClick:()=>{navigator.clipboard.writeText(S)},children:"复制"}),e.jsx("button",{className:"result-modal-btn",onClick:()=>P(!1),children:"关闭"})]})]})})]})},rl={authority:0,guardUsageCount:0,humanUsageCount:0,aiUsageCount:0,lastUsedAt:null,authorityScore:0},nl=({editingRecipe:t,setEditingRecipe:s,handleSaveRecipe:a,closeRecipeEdit:r,isSavingRecipe:l=!1})=>{var C,E,p,I,W,Z;const[o,d]=n.useState("preview"),c=n.useRef(!0);n.useEffect(()=>()=>{c.current=!1},[]);const u=["View","Service","Tool","Model","Network","Storage","UI","Utility"],S=async N=>{try{if(await ie.setRecipeAuthority(t.name,N),c.current){const G=t.stats?{...t.stats,authority:N}:{...rl,authority:N};s({...t,stats:G})}}catch{}},x=N=>{const G=N.split(`
105
- `),Q={};let R=0,V=!1;for(let v=0;v<G.length;v++){const _=G[v].trim();if(_==="---"){if(!V&&v===0){V=!0;continue}else if(V){V=!1,R=v+1;break}}const w=_.match(/^([a-zA-Z0-9_-]+):\s*(.*)/);if(w)Q[w[1]]=w[2],V||(R=v+1);else if(!V&&_!==""){R=v;break}}const q=G.slice(R).join(`
106
- `).trim();return{metadata:Q,body:q}},{metadata:h,body:j}=x(t.content||""),M=N=>{const G=[],Q=[],R=te=>(N[te]||"").trim(),V=R("title"),q=R("trigger"),v=R("category"),_=R("language").toLowerCase(),w=R("summary_cn")||R("summary"),D=R("summary_en"),K=R("headers");return V||G.push("缺少 title"),(!q||!q.startsWith("@"))&&G.push("trigger 必须以 @ 开头"),(!v||!u.includes(v))&&G.push(`category 必须为以下之一:${u.join(", ")}`),(!_||_!=="swift"&&_!=="objectivec"&&_!=="markdown")&&G.push("language 必须为 swift 或 objectivec"),w||G.push("缺少 summary/summary_cn"),D||Q.push("缺少 summary_en"),K?(K.startsWith("[")?K.slice(1,-1).split(",").map(f=>f.trim().replace(/^["']|["']$/g,"")).filter(Boolean):[K.replace(/^["']|["']$/g,"")]).filter(f=>!(f.startsWith("import ")||f.startsWith("#import "))).length>0&&Q.push("headers 建议为完整 import 语句(Swift: import X / ObjC: #import <X/Y.h>)"):Q.push("缺少 headers(建议填写完整 import 语句)"),{errors:G,warnings:Q}},{errors:P,warnings:O}=M(h),z=N=>N?new Date(N).toLocaleString("zh-CN",{year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit"}):"";return e.jsx("div",{className:"fixed inset-0 bg-slate-900/50 backdrop-blur-sm z-50 flex items-center justify-center p-4",children:e.jsxs("div",{className:"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 G={rule:{label:"Rule",color:"text-red-700",bg:"bg-red-50",border:"border-red-200",icon:Ve},pattern:{label:"Pattern",color:"text-violet-700",bg:"bg-violet-50",border:"border-violet-200",icon:as},fact:{label:"Fact",color:"text-cyan-700",bg:"bg-cyan-50",border:"border-cyan-200",icon:ot}}[t.kind];if(!G)return null;const Q=G.icon;return e.jsxs("span",{className:`text-[10px] font-bold px-2 py-1 rounded uppercase flex items-center gap-1 border ${G.bg} ${G.color} ${G.border}`,children:[e.jsx(Q,{size:b.sm}),G.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:((C=t.stats)==null?void 0:C.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:((E=t.stats)==null?void 0:E.authority)??3,onChange:N=>S(parseInt(N.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:()=>d("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(Ht,{size:b.sm})," Preview"]}),e.jsxs("button",{onClick:()=>d("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(pt,{size:b.sm})," Edit"]})]}),e.jsx("button",{onClick:r,className:"p-2 hover:bg-slate-100 rounded-full",children:e.jsx(Ke,{size:b.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:N=>s({...t,name:N.target.value})})]}),(P.length>0||O.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 校验提示"}),P.length>0&&e.jsxs("div",{children:[e.jsx("div",{className:"font-semibold",children:"错误"}),e.jsx("ul",{className:"list-disc pl-5",children:P.map((N,G)=>e.jsx("li",{children:N},G))})]}),O.length>0&&e.jsxs("div",{children:[e.jsx("div",{className:"font-semibold",children:"建议"}),e.jsx("ul",{className:"list-disc pl-5",children:O.map((N,G)=>e.jsx("li",{children:N},G))})]})]}),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(qt,{value:t.content||"",onChange:N=>s({...t,content:N}),language:"markdown",height:"100%",showLineNumbers:!0})]}):e.jsxs("div",{className:"flex-1 overflow-y-auto space-y-6 scrollbar-light",children:[Object.keys(h).length>0&&e.jsxs("div",{className:"bg-slate-50 border border-slate-200 rounded-2xl p-6",children:[e.jsx("h3",{className:"text-[10px] font-bold text-slate-400 uppercase tracking-widest mb-4",children:"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(N=>h[N]).map(N=>e.jsxs("div",{className:"flex flex-col",children:[e.jsx("span",{className:"text-[10px] text-slate-400 font-bold uppercase mb-1",children:N}),e.jsx("span",{className:"text-sm text-slate-700 break-all font-medium",children:N==="updatedAt"?z(parseInt(h[N])):h[N]})]},N))}),h.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 N=JSON.parse(h.tags);return(Array.isArray(N)?N:[h.tags]).map((G,Q)=>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:G},Q))}catch{return e.jsx("span",{className:"text-sm text-slate-700",children:h.tags})}})()})]}),h.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 N=JSON.parse(h.headers);return(Array.isArray(N)?N:[h.headers]).map((G,Q)=>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:G},Q))}catch{return e.jsx("code",{className:"text-sm text-slate-700 font-mono",children:h.headers})}})()})]}),(h.summary_cn||h.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:h.summary_cn||h.summary})]}),h.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:h.summary_en})]}),(()=>{const N=new Set(["title","trigger","language","category","knowledge_type","complexity","scope","difficulty","authority","status","version","updatedAt","tags","headers","summary","summary_cn","summary_en","id"]),G=Object.entries(h).filter(([Q])=>!N.has(Q));return G.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:G.map(([Q,R])=>e.jsxs("div",{className:"flex flex-col",children:[e.jsx("span",{className:"text-[10px] text-slate-400 font-bold uppercase mb-1",children:Q}),e.jsx("span",{className:"text-sm text-slate-700 break-all font-medium",children:R})]},Q))})})})()]})]}),e.jsx("div",{className:"bg-white p-8 rounded-2xl border border-slate-100 shadow-sm min-h-[400px]",children:j?e.jsx(We,{content:j,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&&!h.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((N,G)=>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:N},G))})]}),!!(t.constraints&&((p=t.constraints.guards)!=null&&p.length||(I=t.constraints.boundaries)!=null&&I.length||(W=t.constraints.preconditions)!=null&&W.length||(Z=t.constraints.sideEffects)!=null&&Z.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((N,G)=>e.jsxs("li",{className:"flex gap-2 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-xs bg-slate-100 px-1.5 py-0.5 rounded",children:N.pattern}),N.message&&e.jsxs("span",{className:"text-xs text-slate-400",children:["— ",N.message]})]},G))})]}),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((N,G)=>e.jsxs("li",{className:"flex gap-2",children:[e.jsx("span",{className:"text-orange-400",children:"●"}),N]},G))})]}),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((N,G)=>e.jsxs("li",{className:"flex gap-2",children:[e.jsx("span",{className:"text-blue-400",children:"◆"}),N]},G))})]}),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((N,G)=>e.jsxs("li",{className:"flex gap-2",children:[e.jsx("span",{className:"text-pink-400",children:"⚡"}),N]},G))})]})]}),t.relations&&Object.entries(t.relations).some(([,N])=>Array.isArray(N)&&N.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:N,label:G,color:Q,icon:R})=>{var q;const V=(q=t.relations)==null?void 0:q[N];return!V||!Array.isArray(V)||V.length===0?null:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsxs("span",{className:`text-xs font-mono ${Q} w-16 shrink-0 pt-0.5`,children:[R," ",G]}),e.jsx("div",{className:"flex flex-wrap gap-1.5",children:V.map((v,_)=>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 v=="string"?v:v.id||v.title||JSON.stringify(v)},_))})]},N)})})]})]})})]}),e.jsxs("div",{className:"p-6 border-t border-slate-100 flex justify-end gap-3",children:[e.jsx("button",{onClick:r,disabled:l,className:"px-4 py-2 text-slate-600 font-medium disabled:opacity-50",children:"Cancel"}),e.jsxs("button",{onClick:a,disabled:l,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:[l?e.jsx(ze,{size:b.lg,className:"animate-spin"}):e.jsx(cs,{size:b.lg}),l?"保存中...":"Save Changes"]})]})]})})},il=({setShowCreateModal:t,createPath:s,setCreatePath:a,handleCreateFromPath:r,handleCreateFromClipboard:l,isExtracting:o})=>e.jsx("div",{className:"fixed inset-0 bg-slate-900/50 backdrop-blur-sm z-50 flex items-center justify-center p-4",children:e.jsxs("div",{className:"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(ss,{size:b.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:b.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(ns,{size:b.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:d=>a(d.target.value)}),e.jsx("button",{onClick:r,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(la,{size:b.sm})," Import from Clipboard"]}),e.jsxs("button",{onClick:()=>l(),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(Be,{size:b.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(At,{size:b.lg,className:"animate-spin"}),e.jsx("span",{className:"font-bold text-sm",children:"AI is thinking..."})]})]})});function ol(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 cl=({searchQ:t,insertPath:s,onClose:a})=>{const[r,l]=n.useState([]),[o,d]=n.useState(!0),[c,u]=n.useState(null),S=n.useRef(!0),x=n.useRef(null);n.useEffect(()=>(S.current=!0,x.current=new AbortController,ie.searchRecipesForModal(t||"",x.current.signal).then(j=>{S.current&&l(j.results||[])}).catch(j=>{j.name!=="AbortError"&&S.current&&l([])}).finally(()=>{S.current&&d(!1)}),()=>{S.current=!1,x.current&&x.current.abort()}),[t]);const h=async j=>{u(j.name);try{const M=ol(j.content);await ie.insertAtSearchMark({path:s,content:M}),S.current&&(alert("✅ 已插入到 "+s),a())}catch{S.current&&alert("❌ 插入失败")}finally{S.current&&u(null)}};return e.jsx("div",{className:"fixed inset-0 bg-slate-900/50 backdrop-blur-sm z-50 flex items-center justify-center p-4",children:e.jsxs("div",{className:"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(it,{size:b.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:b.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"})}):r.length===0?e.jsx("div",{className:"text-slate-500 text-center py-8",children:"未找到匹配的 Recipe"}):e.jsx("ul",{className:"space-y-2",children:r.map(j=>e.jsx("li",{children:e.jsxs("button",{type:"button",onClick:()=>h(j),disabled:c!==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:j.name}),(j.qualityScore!==void 0||j.recommendReason)&&e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[j.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:["🤖 质量: ",(j.qualityScore*100).toFixed(0),"%"]}),j.recommendReason&&e.jsx("span",{className:"text-xs text-slate-600 italic truncate max-w-xs",children:j.recommendReason})]})]}),c===j.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(os,{size:b.md})," 插入"]})]})},j.name))})})]})})};function Te(t){return t?typeof t=="string"?t:typeof t=="object"?Object.entries(t).map(([a,r])=>`${a}: ${Array.isArray(r)?r.join("; "):r}`).join(`
107
- `):String(t):""}const dl=()=>{var ct;const t=ja(),s=Na((ct=t.user)==null?void 0:ct.role),a=()=>{const m=window.location.pathname.replace(/^\//,"").split("/")[0]||"";return ca.includes(m)?m:"help"},[r,l]=n.useState(null),[o,d]=n.useState(a()),[c,u]=n.useState(""),[S,x]=n.useState(!0),[h,j]=n.useState(null),[M,P]=n.useState([]),[O,z]=n.useState(null),[C,E]=n.useState(!1),[p,I]=n.useState({current:0,total:0,status:""}),[W,Z]=n.useState([]),[N,G]=n.useState([]),[Q,R]=n.useState(null),[V,q]=n.useState("All"),[v,_]=n.useState(1),[w,D]=n.useState(12),[K,te]=n.useState(!1),[i,f]=n.useState(""),[L,U]=n.useState(!1),[ee,ye]=n.useState([]),[Ne,xe]=n.useState(""),[fe,y]=n.useState(!1),[F,Se]=n.useState(null),[oe,H]=n.useState(null),[ce,$]=n.useState(!1),X=n.useRef(null),J=n.useRef(null);n.useEffect(()=>{_(1)},[c,V]);const he=()=>{X.current&&X.current.abort(),J.current&&J.current.abort(),y(!1)},Y=(m,g)=>{d(m);const T=g!=null&&g.preserveSearch&&window.location.search?window.location.search:"";window.history.pushState({},document.title,`/${m}${T}`)},de=m=>{j(m),d("recipes");const g=new URLSearchParams(window.location.search);g.set("edit",encodeURIComponent(m.name)),window.history.pushState({},document.title,`/recipes?${g.toString()}`)},B=()=>{j(null),window.history.replaceState({},document.title,"/recipes")};n.useEffect(()=>{c===""&&Se(null)},[c]),n.useEffect(()=>{d(a())},[]),n.useEffect(()=>{if(!r)return;const m=window.location.pathname.replace(/^\//,"").split("/")[0],T=new URLSearchParams(window.location.search).get("edit");if(m==="recipes"&&T&&r.recipes)try{const A=decodeURIComponent(T),se=r.recipes.find(re=>re.name===A);se&&!h&&(d("recipes"),de(se))}catch{}},[r]),n.useEffect(()=>{ne(),ue();const m=()=>{d(a())};window.addEventListener("popstate",m);const g=new URLSearchParams(window.location.search),T=g.get("action"),A=g.get("path"),se=g.get("q")||"";T==="search"&&A?H({q:se,path:A}):T==="create"&&A&&(f(A),te(!0),g.get("autoScan")==="1"&&setTimeout(()=>Ie(A),500))},[]);const ne=async()=>{x(!0);try{const m=await ie.fetchData();if(m.candidates){const g={};Object.entries(m.candidates).forEach(([T,A])=>{const se=A.items.map(re=>{const je=re.summary_cn||re.summary||"",pe=re.summary_en&&re.summary_en!==je?re.summary_en:void 0,me=Te(re.usageGuide_cn||re.usageGuide||""),ge=re.usageGuide_en&&Te(re.usageGuide_en)!==me?Te(re.usageGuide_en):void 0;return{...re,summary_cn:je,summary_en:pe,usageGuide_cn:me,usageGuide_en:ge}});g[T]={...A,items:se}}),m.candidates=g}l(m)}catch{}finally{x(!1)}},ue=async()=>{try{const m=await ie.fetchTargets();P(m)}catch{}},we=async()=>{try{await ie.syncToXcode(),ae("已同步到 Xcode CodeSnippets")}catch{ae("同步失败",{type:"error"})}},Ce=async()=>{try{await ie.refreshProject(),ue(),ae("项目结构已刷新")}catch{ae("刷新失败",{type:"error"})}},Ie=async m=>{var g;U(!0);try{const T=await ie.extractFromPath(m);G(T.result.map(A=>{const se=A.summary_cn||A.summary||"",re=A.summary_en&&A.summary_en!==se?A.summary_en:void 0,je=Te(A.usageGuide_cn||A.usageGuide||""),pe=A.usageGuide_en&&Te(A.usageGuide_en)!==je?Te(A.usageGuide_en):void 0;return{...A,summary_cn:se,summary_en:re,usageGuide_cn:je,usageGuide_en:pe,tags:Array.isArray(A.tags)?A.tags:[],mode:"full",lang:"cn",includeHeaders:!0,category:A.category||"Utility",summary:se,usageGuide:je}})),Y("spm",{preserveSearch:!0}),te(!1),ne(),((g=T.result)==null?void 0:g.length)>0&&ae("提取完成,已加入候选池,请在 Candidates 页审核")}catch{ae("Extraction failed",{type:"error"})}finally{U(!1)}},ke=async()=>{var m;if(i){U(!0);try{const g=await ie.extractFromPath(i);G(g.result.map(T=>{const A=T.summary_cn||T.summary||"",se=T.summary_en&&T.summary_en!==A?T.summary_en:void 0,re=Te(T.usageGuide_cn||T.usageGuide||""),je=T.usageGuide_en&&Te(T.usageGuide_en)!==re?Te(T.usageGuide_en):void 0;return{...T,summary_cn:A,summary_en:se,usageGuide_cn:re,usageGuide_en:je,tags:Array.isArray(T.tags)?T.tags:[],mode:"full",lang:"cn",includeHeaders:!0,category:T.category||"Utility",summary:A,usageGuide:re}})),Y("spm"),te(!1),ne(),((m=g.result)==null?void 0:m.length)>0?ae(g.isMarked?"提取完成(精准锁定),已加入候选池":"提取完成,已加入候选池"):g.isMarked||ae("未找到标记,AI 正在分析完整文件")}catch{ae("Extraction failed",{type:"error"})}finally{U(!1)}}},Re=async m=>{var g,T,A,se;try{const re=await navigator.clipboard.readText();if(!re)return ae("剪贴板为空");ae("已收到剪贴板内容,正在调用 AI 识别..."),U(!0);const je=m||i;try{const pe=await ie.extractFromText(re,je||void 0),me=pe.summary_cn||pe.summary||"",ge=pe.summary_en&&pe.summary_en!==me?pe.summary_en:void 0,be=Te(pe.usageGuide_cn||pe.usageGuide||""),Ee=pe.usageGuide_en&&Te(pe.usageGuide_en)!==be?Te(pe.usageGuide_en):void 0,_e=pe._multipleCount;G([{...pe,summary_cn:me,summary_en:ge,usageGuide_cn:be,usageGuide_en:Ee,tags:Array.isArray(pe.tags)?pe.tags:[],mode:"full",lang:"cn",includeHeaders:!0,category:pe.category||"Utility",summary:me,usageGuide:be}]),Y("spm",{preserveSearch:!0}),te(!1),ne(),ae(_e?`已识别 ${_e} 条 Recipe,已加入候选池`:"AI 识别成功,已加入候选池")}catch(pe){const me=((T=(g=pe.response)==null?void 0:g.data)==null?void 0:T.aiError)===!0,ge=((se=(A=pe.response)==null?void 0:A.data)==null?void 0:se.error)||pe.message;me?ae(`AI 识别失败: ${ge}`,{type:"error"}):ae(`操作失败: ${ge}`,{type:"error"})}}catch{ae("剪贴板读取失败",{type:"error"})}finally{U(!1)}},tt=[{status:"正在读取 Target 源文件...",percent:15},{status:"正在发送到 AI 分析...",percent:35},{status:"正在识别可复用代码片段...",percent:55},{status:"正在生成摘要与使用指南...",percent:75},{status:"即将完成...",percent:92}],He=async m=>{var re,je,pe,me;if(C)return;X.current&&X.current.abort();const g=new AbortController;X.current=g,z(m.name),E(!0),G([]),R(null),Z([]),I({current:0,total:100,status:"正在获取待扫描文件列表..."});const T=4e3;let A=0;const se=setInterval(()=>{A=Math.min(A+1,tt.length);const ge=tt[A-1];ge&&I(be=>({...be,current:ge.percent,status:ge.status}))},T);try{const ge=await ie.getTargetFiles(m,g.signal),be=ge.files||[],Ee=ge.count??be.length;Z(be),I(Me=>({...Me,current:10,status:`正在分析 ${Ee} 个文件...`}));const _e=await ie.scanTarget(m,g.signal);clearInterval(se),I({current:100,total:100,status:"扫描完成"});const Ae=_e.recipes||[],Oe=(re=_e.scannedFiles)!=null&&re.length?_e.scannedFiles:be;if(Ae.length>0||Oe.length>0){const Me=typeof m=="string"?m:(m==null?void 0:m.name)||"unknown",Tt=Ae.map(Le=>({...Le,mode:"full",lang:"cn",includeHeaders:Le.includeHeaders!==!1,category:Le.category||"Utility",summary:Te(Le.summary_cn||Le.summary||""),usageGuide:Te(Le.usageGuide_cn||Le.usageGuide||""),tags:Array.isArray(Le.tags)?Le.tags:[],candidateTargetName:Me,scanMode:"target"}));G(Tt),Z(Oe),ne(),Ae.length>0?ae(`AI 提取了 ${Ae.length} 条结果,请在右侧审核`):_e.message?ae(`AI 扫描未返回结果: ${_e.message}`,{type:"error"}):ae("未发现可提取的代码模式",{type:"error"})}else ae("Scan failed: No source files.",{type:"error"})}catch(ge){if(clearInterval(se),Je.isCancel(ge))return;const Ee=ge.code==="ECONNABORTED"||((je=ge.message)==null?void 0:je.includes("timeout"))?"扫描超时,请尝试减少 Target 文件数量":((me=(pe=ge.response)==null?void 0:pe.data)==null?void 0:me.error)||ge.message;ae(Ee,{type:"error"})}finally{X.current===g&&(E(!1),I({current:0,total:0,status:""}),X.current=null)}},k=async()=>{var se,re,je,pe,me,ge;if(C)return;X.current&&X.current.abort();const m=new AbortController;X.current=m,Y("candidates"),E(!0),G([]),R(null),Z([]),I({current:0,total:100,status:"正在收集项目结构..."});const g=[{status:"正在扫描 SPM Target...",percent:15},{status:"正在收集源文件...",percent:30},{status:"正在构建依赖图谱...",percent:50},{status:"正在运行 Guard 审计...",percent:70},{status:"正在创建 9 维度 Candidate...",percent:85}];let T=0;const A=setInterval(()=>{T=Math.min(T+1,g.length);const be=g[T-1];be&&I(Ee=>({...Ee,current:be.percent,status:be.status}))},3e3);try{const be=await ie.bootstrap(m.signal);clearInterval(A),I({current:100,total:100,status:"冷启动完成"}),ne();const Ee=be.report||{},_e=be.bootstrapCandidates||{created:0},Ae=be.guardSummary,Oe=((se=be.targets)==null?void 0:se.length)||0,Me=((re=Ee.totals)==null?void 0:re.files)||0,Tt=((je=Ee.totals)==null?void 0:je.graphEdges)||0,Le=Ae?`, Guard: ${Ae.totalViolations} 项违规`:"",ps=be.aiEnhancement==="pending"?",AI 润色正在后台进行":"";ae(`冷启动完成: ${Oe} 个 Target, ${Me} 个文件, ${Tt} 条依赖, ${_e.created} 个维度 Candidate 已创建${Le}${ps}`)}catch(be){if(clearInterval(A),Je.isCancel(be))return;const _e=be.code==="ECONNABORTED"||((pe=be.message)==null?void 0:pe.includes("timeout"))?"冷启动超时,请检查项目文件数量":((ge=(me=be.response)==null?void 0:me.data)==null?void 0:ge.error)||be.message;ae(_e,{type:"error"})}finally{X.current===m&&(E(!1),I({current:0,total:0,status:""}),X.current=null)}},ve=async()=>{var se,re,je,pe;if(C)return;X.current&&X.current.abort();const m=new AbortController;X.current=m,Y("spm"),z("__project__"),E(!0),G([]),R(null),Z([]),I({current:0,total:100,status:"正在收集所有 Target 文件..."});const g=[{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 T=0;const A=setInterval(()=>{T=Math.min(T+1,g.length);const me=g[T-1];me&&I(ge=>({...ge,current:me.percent,status:me.status}))},15e3);try{const me=await ie.scanProject(m.signal);clearInterval(A),I({current:100,total:100,status:me.partial?"扫描部分完成(超时)":"全项目扫描完成"});const ge=me.recipes||[],be=me.scannedFiles||[];if(ge.length>0||be.length>0){const Ee=ge.map(Me=>({...Me,mode:"full",lang:"cn",includeHeaders:Me.includeHeaders!==!1,category:Me.category||"Utility",summary:Me.summary_cn||Me.summary||"",usageGuide:Me.usageGuide_cn||Me.usageGuide||"",candidateTargetName:"__project__",scanMode:"project"}));G(Ee),Z(be),R(me.guardAudit||null),ne();const _e=(se=me.guardAudit)==null?void 0:se.summary,Ae=_e?`, Guard: ${_e.totalViolations} 处违反`:"",Oe=me.partial?"(部分结果,AI 超时)":"";ae(`全项目扫描完成: ${ge.length} 条候选${Ae}${Oe}`)}else ae("全项目扫描完成,未发现可提取内容")}catch(me){if(clearInterval(A),Je.isCancel(me))return;const be=me.code==="ECONNABORTED"||((re=me.message)==null?void 0:re.includes("timeout"))?"扫描超时,请尝试减少项目文件数量或分 Target 扫描":((pe=(je=me.response)==null?void 0:je.data)==null?void 0:pe.error)||me.message;ae(be,{type:"error"})}finally{X.current===m&&(E(!1),I({current:0,total:0,status:""}),X.current=null)}},Fe=(m,g)=>{const T=[...N],A={...T[m],...g};!A.summary_cn&&A.summary&&!A.summary_en&&(A.summary_cn=A.summary),!A.usageGuide_cn&&A.usageGuide&&!A.usageGuide_en&&(A.usageGuide_cn=A.usageGuide),g.lang!==void 0&&g.summary===void 0&&(A.summary=g.lang==="cn"?A.summary_cn||A.summary:A.summary_en||A.summary),g.lang!==void 0&&g.usageGuide===void 0&&(A.usageGuide=g.lang==="cn"?A.usageGuide_cn||A.usageGuide:A.usageGuide_en||A.usageGuide),g.summary!==void 0&&g.lang===void 0&&(A.lang==="cn"?A.summary_cn=g.summary:A.summary_en=g.summary),g.usageGuide!==void 0&&g.lang===void 0&&(A.lang==="cn"?A.usageGuide_cn=g.usageGuide:A.usageGuide_en=g.usageGuide),T[m]=A,G(T)},Ue=async m=>{if(!ce){$(!0);try{const g=(m.trigger||"").split(/[,,\s]+/).map(Ae=>Ae.trim()).filter(Boolean);if(g.length===0){ae("请输入 Trigger",{type:"error"}),$(!1);return}const T=crypto.randomUUID().toUpperCase(),A=`${(m.title||"Untitled").replace(/\s+/g,"-")}.md`,se=m.summary_cn||m.summary||"",re=m.summary_en||m.summary||"",je=m.usageGuide_cn||m.usageGuide||"",pe=m.usageGuide_en||m.usageGuide||"";let me=`---
108
- id: ${m.mode==="full"?T:"preview-only"}
109
- title: ${m.title||"Untitled Recipe"}
110
- language: ${m.language||"swift"}
111
- trigger: ${g.join(", ")}
112
- category: ${m.category||"Utility"}
113
- summary: ${se}
114
- summary_cn: ${se}`;re&&re!==se&&(me+=`
115
- summary_en: ${re}`),me+=`
116
- headers: ${JSON.stringify(m.headers||[])}`,m.difficulty&&(me+=`
117
- difficulty: ${m.difficulty}`),m.authority&&(me+=`
118
- authority: ${m.authority}`),m.knowledgeType&&(me+=`
119
- knowledge_type: ${m.knowledgeType}`),m.complexity&&(me+=`
120
- complexity: ${m.complexity}`),m.scope&&(me+=`
121
- scope: ${m.scope}`),m.tags&&m.tags.length>0&&(me+=`
122
- tags: ${JSON.stringify(m.tags)}`),me+=`
123
- version: "1.0.0"
124
- updatedAt: ${Date.now()}
125
- ---`;let ge=`
126
- ## Snippet / Code Reference
127
-
128
- \`\`\`${m.language||"swift"}
129
- ${m.code||""}
130
- \`\`\`
131
-
132
- ## AI Context / Usage Guide
133
-
134
- ${je}`;pe&&pe!==je&&(ge+=`
135
-
136
- ## AI Context / Usage Guide (EN)
137
-
138
- ${pe}`),m.rationale&&(ge+=`
139
-
140
- ## Architecture Usage
141
-
142
- ${m.rationale}`),m.steps&&m.steps.length>0&&(ge+=`
143
-
144
- ## Best Practices
145
-
146
- ${m.steps.map((Ae,Oe)=>`${Oe+1}. ${Ae}`).join(`
147
- `)}`),m.preconditions&&m.preconditions.length>0&&(ge+=`
148
-
149
- ## Standards
150
-
151
- **Preconditions:**
152
- ${m.preconditions.map(Ae=>`- ${Ae}`).join(`
153
- `)}`);const be=me+ge;await ie.saveRecipe(A,be),ae(m.mode==="full"?"已保存为 Recipe(Snippet 将自动生成)":"已保存到 KB"),G(Ae=>Ae.filter(Oe=>Oe.title!==m.title));const Ee=m.candidateTargetName,_e=m.candidateId;if(Ee&&_e)try{await ie.deleteCandidate(_e)}catch{}ne()}catch(g){const T=Yt(g)??Ct(g);ae(T??"保存失败",{type:"error"})}finally{$(!1)}}},qe=async()=>{if(!(!h||ce)){$(!0);try{let m=h.content;const g=`
154
- ## AI Context / Usage Guide (EN)`,T=m.indexOf(g);if(T!==-1){const A=m.substring(T+g.length),se=A.indexOf(g);if(se!==-1){const re=A.match(/\n## /);let je=A.length;re&&re.index!==void 0&&re.index<se?(je=re.index,m=m.substring(0,T+g.length)+A.substring(0,je)):m=m.substring(0,T+g.length)+A.substring(0,se)}}await ie.saveRecipe(h.name,m),B(),ne()}catch(m){const g=Yt(m)??Ct(m);ae(g??"保存 Recipe 失败",{type:"error"})}finally{$(!1)}}},Pe=async m=>{if(window.confirm("Are you sure?"))try{await ie.deleteRecipe(m),ne()}catch(g){const T=Ct(g);ae(T??"删除失败",{type:"error"})}},Ge=async(m,g)=>{try{await ie.deleteCandidate(g),G(T=>T.filter(A=>!(A.candidateId===g&&A.candidateTargetName===m))),ne()}catch(T){throw ae("操作失败",{type:"error"}),T}},st=async m=>{if(window.confirm(`确定移除「${m}」下的全部候选?`))try{await ie.deleteAllCandidatesInTarget(m),ne(),ae(`已移除 ${m} 下的全部候选`)}catch{ae("操作失败",{type:"error"})}},at=async(m,g)=>{var T,A;try{await ie.promoteToCandidate(m,m.candidateTargetName||O||"_review"),ae("已加入 Candidate 待审核队列"),G(se=>se.filter((re,je)=>je!==g)),ne()}catch(se){ae(((A=(T=se.response)==null?void 0:T.data)==null?void 0:A.error)||"创建 Candidate 失败",{type:"error"})}},$e=async m=>{if(m.preventDefault(),!Ne.trim()||fe)return;J.current&&J.current.abort();const g=new AbortController;J.current=g;const T={role:"user",text:Ne};ye(A=>[...A,T]),xe(""),y(!0);try{const A=await ie.chat(Ne,ee.map(se=>({role:se.role,content:se.text})),g.signal);ye(se=>[...se,{role:"model",text:A.text}])}catch(A){if(Je.isCancel(A))return;ye(se=>[...se,{role:"model",text:"Error"}])}finally{J.current===g&&(J.current=null,y(!1))}},Rt=((r==null?void 0:r.recipes)||[]).filter(m=>{if(F)return F.some(je=>je.metadata.type==="recipe"&&je.metadata.name===m.name);const g=m.name||"",T=m.content||"",A=g.toLowerCase().includes(c.toLowerCase())||T.toLowerCase().includes(c.toLowerCase());if(V==="All")return A;const se=T?T.match(/category:\s*(.*)/):null,re=se?se[1].trim():"Utility";return A&&re===V}).sort((m,g)=>{var se,re,je,pe;if(F){const me=((se=F.find(be=>be.metadata.name===m.name))==null?void 0:se.similarity)||0;return(((re=F.find(be=>be.metadata.name===g.name))==null?void 0:re.similarity)||0)-me}const T=((je=m.stats)==null?void 0:je.authorityScore)??0;return(((pe=g.stats)==null?void 0:pe.authorityScore)??0)-T}),ht=M.filter(m=>m.name.toLowerCase().includes(c.toLowerCase())).sort((m,g)=>{const T=gt(m.name),A=gt(g.name);return T&&!A?1:!T&&A?-1:m.name.localeCompare(g.name)}),bt=Object.values((r==null?void 0:r.candidates)||{}).reduce((m,g)=>m+g.items.length,0),lt=o==="editor";return e.jsxs("div",{className:`flex h-screen ${lt?"bg-[#1e1e1e] text-slate-200":"bg-slate-50 text-slate-900"} overflow-hidden font-sans`,children:[e.jsx(hs,{position:"top-center",toastOptions:{duration:3e3}}),e.jsx(wa,{activeTab:o,navigateToTab:Y,handleRefreshProject:Ce,candidateCount:bt,isDarkMode:lt,currentUser:s.user!=="anonymous"?s.user:void 0,currentRole:s.role,permissionMode:s.mode,onLogout:void 0}),e.jsxs("main",{className:"flex-1 flex flex-col overflow-hidden relative",children:[e.jsx(Ca,{searchQuery:c,setSearchQuery:u,setShowCreateModal:te,handleSyncToXcode:we,aiConfig:r==null?void 0:r.aiConfig,onBeforeAiSwitch:he,onAiConfigChange:ne,isDarkMode:lt,onSemanticSearchResults:m=>{Se(m),o!=="recipes"&&Y("recipes")}}),o==="recipes"&&e.jsx(Sa,{selectedCategory:V,setSelectedCategory:q}),e.jsx("div",{className:`flex-1 overflow-y-auto ${o==="editor"?"":"p-8"}`,children:S?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"})}):o==="recipes"?e.jsx($a,{recipes:Rt,openRecipeEdit:de,handleDeleteRecipe:Pe,onRefresh:ne,currentPage:v,onPageChange:_,pageSize:w,onPageSizeChange:m=>{D(m),_(1)}}):o==="guard"?e.jsx(Za,{onRefresh:ne}):o==="candidates"?e.jsx(Ha,{data:r,isShellTarget:gt,isSilentTarget:xa,isPendingTarget:ma,handleDeleteCandidate:Ge,onEditRecipe:de,onColdStart:k,isScanning:C,onRefresh:ne,onAuditCandidate:(m,g)=>{G([{...m,mode:"full",lang:"cn",includeHeaders:!0,summary:m.summary_cn||m.summary||"",usageGuide:m.usageGuide_cn||m.usageGuide||"",candidateId:m.id,candidateTargetName:g}]),Y("spm")},onAuditAllInTarget:(m,g)=>{G(m.map(T=>({...T,mode:"full",lang:"cn",includeHeaders:!0,summary:T.summary_cn||T.summary||"",usageGuide:T.usageGuide_cn||T.usageGuide||"",candidateId:T.id,candidateTargetName:g}))),Y("spm")},handleDeleteAllInTarget:st}):o==="depgraph"?e.jsx(Ya,{}):o==="knowledgegraph"?e.jsx(al,{}):o==="spm"?e.jsx(qa,{targets:M,filteredTargets:ht,selectedTargetName:O,isScanning:C,scanProgress:p,scanFileList:W,scanResults:N,guardAudit:Q,handleScanTarget:He,handleScanProject:ve,handleUpdateScanResult:Fe,handleSaveExtracted:Ue,handlePromoteToCandidate:at,handleDeleteCandidate:Ge,onEditRecipe:de,isShellTarget:gt,recipes:(r==null?void 0:r.recipes)??[],isSavingRecipe:ce}):o==="editor"?e.jsx(ll,{}):o==="help"?e.jsx(_a,{}):e.jsx(Qa,{chatHistory:ee,userInput:Ne,setUserInput:xe,handleChat:$e,isAiThinking:fe})}),h&&e.jsx(nl,{editingRecipe:h,setEditingRecipe:j,handleSaveRecipe:qe,closeRecipeEdit:B,isSavingRecipe:ce}),K&&e.jsx(il,{setShowCreateModal:te,createPath:i,setCreatePath:f,handleCreateFromPath:ke,handleCreateFromClipboard:Re,isExtracting:L}),oe&&e.jsx(cl,{searchQ:oe.q,insertPath:oe.path,onClose:()=>{H(null),window.history.replaceState({},document.title,window.location.pathname)}})]})]})};bs.createRoot(document.getElementById("root")).render(e.jsx(gs.StrictMode,{children:e.jsx(dl,{})}));