autosnippet 3.3.8 → 3.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 (42) hide show
  1. package/README.md +1 -1
  2. package/config/default.json +1 -1
  3. package/dashboard/dist/assets/{index-DV8biUkH.js → index-8b1Gf3Bb.js} +4 -4
  4. package/dashboard/dist/index.html +1 -1
  5. package/dist/lib/agent/AgentRuntime.js +13 -1
  6. package/dist/lib/agent/AgentRuntimeTypes.d.ts +2 -0
  7. package/dist/lib/agent/PipelineStrategy.js +32 -2
  8. package/dist/lib/agent/context/ContextWindow.d.ts +2 -1
  9. package/dist/lib/agent/context/ContextWindow.js +18 -4
  10. package/dist/lib/agent/context/ExplorationTracker.js +6 -1
  11. package/dist/lib/agent/context/exploration/ExplorationStrategies.js +2 -1
  12. package/dist/lib/agent/core/LoopContext.d.ts +3 -0
  13. package/dist/lib/agent/core/LoopContext.js +3 -0
  14. package/dist/lib/agent/domain/EpisodicConsolidator.d.ts +5 -0
  15. package/dist/lib/agent/domain/EpisodicConsolidator.js +60 -5
  16. package/dist/lib/agent/domain/insight-analyst.d.ts +16 -0
  17. package/dist/lib/agent/domain/insight-analyst.js +38 -0
  18. package/dist/lib/agent/domain/insight-gate.js +12 -0
  19. package/dist/lib/agent/memory/MemoryConsolidator.js +17 -0
  20. package/dist/lib/bootstrap.js +6 -1
  21. package/dist/lib/cli/SetupService.js +5 -4
  22. package/dist/lib/domain/dimension/DimensionRegistry.d.ts +6 -4
  23. package/dist/lib/domain/dimension/DimensionRegistry.js +19 -23
  24. package/dist/lib/external/ai/AiProvider.d.ts +2 -0
  25. package/dist/lib/external/ai/AiProvider.js +4 -0
  26. package/dist/lib/external/ai/providers/ClaudeProvider.d.ts +1 -1
  27. package/dist/lib/external/ai/providers/ClaudeProvider.js +6 -2
  28. package/dist/lib/external/ai/providers/GoogleGeminiProvider.d.ts +1 -1
  29. package/dist/lib/external/ai/providers/GoogleGeminiProvider.js +6 -2
  30. package/dist/lib/external/ai/providers/OpenAiProvider.d.ts +1 -1
  31. package/dist/lib/external/ai/providers/OpenAiProvider.js +7 -3
  32. package/dist/lib/external/mcp/McpServer.js +19 -2
  33. package/dist/lib/external/mcp/handlers/bootstrap/MissionBriefingBuilder.js +10 -2
  34. package/dist/lib/external/mcp/handlers/bootstrap/pipeline/mock-pipeline.js +10 -29
  35. package/dist/lib/external/mcp/handlers/bootstrap/pipeline/orchestrator.js +37 -4
  36. package/dist/lib/http/routes/ai.js +2 -2
  37. package/dist/lib/infrastructure/database/DatabaseConnection.js +7 -6
  38. package/dist/lib/service/delivery/CursorDeliveryPipeline.js +15 -1
  39. package/dist/lib/shared/PathGuard.js +16 -10
  40. package/dist/lib/shared/isOwnDevRepo.d.ts +29 -4
  41. package/dist/lib/shared/isOwnDevRepo.js +64 -4
  42. package/package.json +1 -1
@@ -72,12 +72,12 @@ Skill 文档格式要求:
72
72
 
73
73
  `+t("globalChat.system.cancelled"):t("globalChat.system.cancelled"));pe&&j.current.push({role:"model",content:pe}),o(Ce=>Ce.map(F=>F.id===le?{...F,content:M}:F))}else o(pe=>pe.map(ue=>ue.id===le?{...ue,content:t("globalChat.requestFailed",{error:ke(oe)})}:ue))}finally{v.current=null}}i(!1)}},[z,l,A,D,I,W]),ae=n.useCallback(async()=>{if(!(p||!D||!g)){d(!0);try{const G=[...r].reverse().find(de=>de.role==="assistant"&&de.preview);let le=G?.preview;if(le&&G?.excludedFields?.length&&G.diff){le={...le};const de=I?Da(I):{};for(const R of G.excludedFields)R in de&&(le[R]=de[R])}await Q.refineApply(D,m,le),u(de=>new Set(de).add(D)),g.onCandidateUpdated?.(D),o(de=>[...de,{id:Dt(),role:"system",content:t("globalChat.system.changesApplied"),timestamp:Date.now()}]),re(t("globalChat.applySuccess"),{title:t("globalChat.applySuccessTitle")})}catch(G){re(ke(G),{title:t("globalChat.applyFailed"),type:"error"})}finally{d(!1)}}},[p,D,m,g]),be=n.useCallback(()=>{!g||g.currentIdx>=g.candidateIds.length-1||x(G=>G?{...G,currentIdx:G.currentIdx+1}:null)},[g]),me=n.useCallback(()=>{L.current=null,x(null),o(G=>[...G,{id:Dt(),role:"system",content:t("globalChat.system.exitedRefine"),timestamp:Date.now()}])},[]),je=n.useCallback(G=>{G.key==="Enter"&&!G.shiftKey&&(G.preventDefault(),U())},[U]);return e.jsxs("aside",{className:"w-[420px] h-full bg-[var(--bg-surface)] border-l border-[var(--border-default)] flex flex-col shrink-0",children:[e.jsxs("div",{className:"px-4 h-[var(--topbar-height)] border-b border-[var(--border-default)] flex items-center justify-between shrink-0",children:[e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsx("div",{className:"w-8 h-8 rounded-lg bg-gradient-to-br from-blue-50 to-indigo-50 border border-blue-100 flex items-center justify-center",children:A?e.jsx(Le,{className:"text-emerald-500",size:16}):e.jsx(ut,{className:"text-blue-600",size:16})}),e.jsxs("div",{children:[e.jsxs("h3",{className:"text-[13px] font-bold text-[var(--fg-primary)] flex items-center gap-2",children:[t(A?"globalChat.refineTitle":"globalChat.chatTitle"),A&&P&&e.jsxs("span",{className:"text-[10px] px-1.5 py-0.5 rounded-full bg-emerald-50 text-emerald-600 font-medium",children:[(g?.currentIdx??0)+1,"/",g?.candidateIds.length]})]}),e.jsx("p",{className:"text-[10px] text-[var(--fg-muted)] truncate max-w-[250px]",children:A?I?.title||t("globalChat.refineSubtitle"):t("globalChat.chatSubtitle")})]})]}),e.jsxs("div",{className:"flex items-center gap-1",children:[A&&e.jsx("button",{onClick:me,className:"px-2 py-1 text-[10px] font-medium text-[var(--fg-secondary)] hover:text-[var(--fg-primary)] hover:bg-[var(--bg-subtle)] rounded-md transition-colors",children:t("globalChat.exitRefine")}),!A&&r.length>0&&e.jsx("button",{onClick:()=>{L.current=null,o([]),j.current=[],c("")},className:"p-1.5 hover:bg-[var(--bg-subtle)] rounded-lg transition-colors",title:t("globalChat.newTopic"),children:e.jsx(mt,{size:16,className:"text-[var(--fg-muted)]"})}),e.jsx("button",{onClick:J,className:"p-1.5 hover:bg-[var(--bg-subtle)] rounded-lg transition-colors",title:t("globalChat.closeChat"),children:e.jsx(ze,{size:16,className:"text-[var(--fg-muted)]"})})]})]}),A&&I&&e.jsx("div",{className:"border-b border-[var(--border-default)] bg-emerald-50/30 px-4 py-2 shrink-0",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-[10px] font-bold text-emerald-700 truncate flex-1",children:I.title}),I.language&&e.jsx("span",{className:"text-[9px] px-1.5 py-0.5 rounded bg-blue-50 text-blue-600 border border-blue-100",children:I.language})]})}),e.jsxs("div",{className:"flex-1 overflow-y-auto p-4 space-y-3 min-h-0 scrollbar-light",children:[r.length===0&&!A&&e.jsxs("div",{className:"flex flex-col items-center justify-center h-full text-center py-10",children:[e.jsx("div",{className:"w-12 h-12 rounded-2xl bg-blue-50 border border-blue-100 flex items-center justify-center mb-3",children:e.jsx(ut,{className:"text-blue-500",size:20})}),e.jsx("h4",{className:"text-sm font-bold text-[var(--fg-primary)] mb-1",children:t("globalChat.emptyTitle")}),e.jsx("p",{className:"text-xs text-[var(--fg-muted)] max-w-[280px] leading-relaxed mb-3",children:t("globalChat.emptyDesc")}),e.jsx("div",{className:"flex flex-wrap gap-1.5 justify-center",children:[t("globalChat.quickPrompts.analyzeArch"),t("globalChat.quickPrompts.findDuplicates"),t("globalChat.quickPrompts.suggestOptimize")].map(G=>e.jsx("button",{onClick:()=>{k(G),B.current?.focus()},className:"text-[10px] px-2.5 py-1 rounded-md bg-[var(--bg-subtle)] text-[var(--fg-secondary)] hover:bg-blue-50 hover:text-blue-700 transition-colors",children:G},G))})]}),A&&r.length<=1&&e.jsx("div",{className:"flex flex-wrap gap-1.5 mt-2",children:[t("globalChat.refinePrompts.addExamples"),t("globalChat.refinePrompts.optimizeComments"),t("globalChat.refinePrompts.addCaveats"),t("globalChat.refinePrompts.improveSummary"),t("globalChat.refinePrompts.addPerformance")].map(G=>e.jsx("button",{onClick:()=>{k(G),B.current?.focus()},className:"text-[10px] px-2.5 py-1 rounded-md bg-emerald-50 text-emerald-700 border border-emerald-200 hover:bg-emerald-100 transition-colors",children:G},G))}),r.map(G=>e.jsx("div",{className:`flex ${G.role==="user"?"justify-end":"justify-start"}`,children:e.jsxs("div",{className:`max-w-[95%] ${G.role==="user"?"bg-blue-600 text-white rounded-2xl rounded-tr-md px-3.5 py-2":G.role==="system"?"bg-[var(--bg-subtle)] border border-[var(--border-default)] text-[var(--fg-secondary)] rounded-2xl px-3.5 py-2 w-full":"bg-[var(--bg-surface)] border border-[var(--border-default)] rounded-2xl rounded-tl-md px-3.5 py-2.5 shadow-sm w-full"}`,children:[G.role==="assistant"&&e.jsxs("div",{className:"flex items-center gap-1.5 mb-1.5",children:[e.jsx(Mt,{size:12,className:A?"text-emerald-500":"text-blue-500"}),e.jsx("span",{className:`text-[10px] font-bold ${A?"text-emerald-600":"text-blue-600"}`,children:t(A?"globalChat.assistantRefine":"globalChat.assistantChat")})]}),G.role==="assistant"&&!G.diff?e.jsx(Qt,{content:G.content,className:"text-xs text-[var(--fg-primary)]"}):e.jsx("p",{className:`text-xs leading-relaxed whitespace-pre-wrap ${G.role==="user"?"":G.role==="system"?"text-[var(--fg-secondary)]":"text-[var(--fg-primary)]"}`,children:G.content}),G.diff&&G.diff.length>0&&e.jsx(ko,{diff:G.diff,excludedFields:G.excludedFields,onToggleField:A&&!h.has(D)?le=>N(G.id,le):void 0})]})},G.id)),l&&e.jsx("div",{className:"flex justify-start",children:e.jsx("div",{className:"bg-[var(--bg-surface)] border border-[var(--border-default)] rounded-2xl rounded-tl-md px-3.5 py-2.5 shadow-sm",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Ne,{size:12,className:`animate-spin ${A?"text-emerald-500":"text-blue-500"}`}),e.jsx("span",{className:"text-xs text-[var(--fg-secondary)]",children:t(A?"globalChat.loading.analyzing":"globalChat.loading.thinking")}),v.current&&e.jsx("button",{onClick:()=>v.current?.abort(),className:"ml-1 px-1.5 py-0.5 text-[10px] font-bold text-red-500 border border-red-200 rounded hover:bg-red-50 transition-colors",children:t("globalChat.stopBtn")})]})})}),e.jsx("div",{ref:w})]}),A&&q&&!l&&(()=>{const G=[...r].reverse().find(T=>T.role==="assistant"&&T.diff&&T.diff.length>0),le=G?.diff?.length||0,de=G?.excludedFields?.length||0,R=le-de;return e.jsxs("div",{className:"px-4 py-2 border-t border-[var(--border-default)] bg-emerald-50/50 flex items-center gap-2 shrink-0",children:[e.jsxs("button",{onClick:ae,disabled:p,className:"flex items-center gap-1 px-3 py-1.5 text-[11px] font-bold text-white bg-gradient-to-r from-emerald-500 to-teal-600 hover:from-emerald-600 hover:to-teal-700 rounded-lg shadow-sm disabled:opacity-50",children:[p?e.jsx(Ne,{size:11,className:"animate-spin"}):e.jsx(ot,{size:11}),p?t("globalChat.applyingBtn"):de>0?t("globalChat.confirmApplyN",{i:R,total:le}):t("globalChat.confirmApply")]}),e.jsxs("button",{className:"flex items-center gap-1 px-2.5 py-1.5 text-[11px] font-bold text-[var(--fg-secondary)] hover:text-[var(--fg-primary)] rounded-lg hover:bg-[var(--bg-subtle)] transition-colors",children:[e.jsx($s,{size:11})," ",t("globalChat.continueAdjust")]}),P&&h.has(D)&&g.currentIdx<g.candidateIds.length-1&&e.jsxs("button",{onClick:be,className:"flex items-center gap-1 px-2.5 py-1.5 text-[11px] font-bold text-blue-600 hover:text-blue-700 rounded-lg hover:bg-blue-50 transition-colors ml-auto",children:[t("globalChat.nextItem")," ",e.jsx(Ue,{size:11})]})]})})(),A&&!q&&!l&&P&&h.has(D)&&g.currentIdx<g.candidateIds.length-1&&e.jsx("div",{className:"px-4 py-2 border-t border-[var(--border-default)] flex items-center justify-center shrink-0",children:e.jsxs("button",{onClick:be,className:"flex items-center gap-1 px-3 py-1.5 text-[11px] font-bold text-blue-600 hover:text-blue-700 rounded-lg bg-blue-50 hover:bg-blue-100 transition-colors",children:[t("globalChat.nextItem")," (",(g?.currentIdx??0)+2,"/",g?.candidateIds.length,") ",e.jsx(Ue,{size:12})]})}),e.jsxs("div",{className:"px-4 py-2.5 border-t border-[var(--border-default)] bg-[var(--bg-surface)] shrink-0",children:[e.jsxs("div",{className:"flex gap-2",children:[e.jsx("textarea",{ref:B,value:z,onChange:G=>k(G.target.value),onKeyDown:je,placeholder:t(A?"globalChat.refinePlaceholder":"globalChat.chatPlaceholder"),rows:2,className:`flex-1 px-3 py-2 text-sm border border-[var(--border-default)] rounded-xl focus:outline-none focus:ring-2 ${A?"focus:ring-emerald-200 focus:border-emerald-400":"focus:ring-blue-200 focus:border-blue-400"} resize-none placeholder:text-[var(--fg-muted)]`,disabled:l||p}),e.jsx("button",{onClick:U,disabled:!z.trim()||l||p,className:`self-stretch w-9 flex items-center justify-center rounded-xl bg-gradient-to-r ${A?"from-emerald-500 to-teal-600 hover:from-emerald-600 hover:to-teal-700":"from-blue-500 to-indigo-600 hover:from-blue-600 hover:to-indigo-700"} text-white disabled:opacity-40 disabled:cursor-not-allowed transition-all shadow-sm shrink-0`,children:e.jsx(Zs,{size:14})})]}),e.jsx("p",{className:"text-[9px] text-[var(--fg-muted)] mt-1",children:t(A?"globalChat.inputHintRefine":"globalChat.inputHintChat")})]})]})},Ao=Xa("inline-flex items-center justify-center gap-2 whitespace-nowrap font-medium transition-all cursor-pointer select-none disabled:pointer-events-none disabled:opacity-50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--accent)]/40 focus-visible:ring-offset-2 focus-visible:ring-offset-[var(--bg-root)] active:scale-[0.97]",{variants:{variant:{primary:"bg-[var(--bg-emphasis)] text-[var(--fg-on-emphasis)] hover:opacity-90 shadow-[var(--shadow-sm)]",secondary:"bg-[var(--bg-surface)] text-[var(--fg-default)] border border-[var(--border-default)] hover:bg-[var(--bg-subtle)] hover:border-[var(--border-emphasis)] shadow-[var(--shadow-sm)]",ghost:"bg-transparent text-[var(--fg-muted)] hover:bg-[var(--bg-subtle)] hover:text-[var(--fg-default)]",danger:"bg-[var(--danger)] text-white hover:opacity-90 shadow-[0_0_12px_rgba(239,68,68,0.2)]",accent:"text-white hover:opacity-90 shadow-[0_0_16px_var(--accent-glow)]"},size:{sm:"h-7 px-2.5 text-xs rounded-[var(--radius-md)]",md:"h-9 px-4 text-sm rounded-[var(--radius-md)]",lg:"h-11 px-5 text-base rounded-[var(--radius-lg)]",icon:"h-8 w-8 rounded-[var(--radius-md)]","icon-sm":"h-7 w-7 rounded-[var(--radius-sm)]"}},defaultVariants:{variant:"primary",size:"md"}}),We=n.forwardRef(({className:t,variant:s,size:a,loading:r,disabled:o,children:l,style:i,...p},d)=>{const g=s==="accent"?{background:"var(--accent-gradient)",...i}:i;return e.jsxs("button",{ref:d,className:ye(Ao({variant:s,size:a,className:t})),disabled:o||r,style:g,...p,children:[r&&e.jsxs("svg",{className:"h-4 w-4 animate-spin",xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24",children:[e.jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),e.jsx("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z"})]}),l]})});We.displayName="Button";const $r=In,Or=Tn,Do=n.forwardRef(({className:t,inset:s,children:a,...r},o)=>e.jsxs(er,{ref:o,className:ye("flex cursor-default select-none items-center rounded-[var(--radius-sm)] px-2 py-1.5 text-sm outline-none","focus:bg-[var(--bg-subtle)] data-[state=open]:bg-[var(--bg-subtle)]",s&&"pl-8",t),...r,children:[a,e.jsx(Ue,{className:"ml-auto h-4 w-4"})]}));Do.displayName=er.displayName;const Ro=n.forwardRef(({className:t,...s},a)=>e.jsx(tr,{ref:a,className:ye("z-50 min-w-[8rem] overflow-hidden rounded-[var(--radius-md)] border border-[var(--border-default)] bg-[var(--bg-surface)] p-1 text-[var(--fg-default)] shadow-[var(--shadow-lg)]","data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95","data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95","data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",t),...s}));Ro.displayName=tr.displayName;const oa=n.forwardRef(({className:t,sideOffset:s=4,...a},r)=>e.jsx(Rn,{children:e.jsx(sr,{ref:r,sideOffset:s,className:ye("z-50 min-w-[8rem] overflow-hidden rounded-[var(--radius-lg)] border border-[var(--border-default)] bg-[var(--bg-surface)] p-1 text-[var(--fg-default)] shadow-[var(--shadow-xl)]","dark:bg-[var(--bg-surface)]/95 dark:backdrop-blur-xl dark:border-[var(--glass-border)] dark:shadow-[0_16px_64px_rgba(0,0,0,0.5),0_0_1px_rgba(255,255,255,0.06)]","data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95","data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95","data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2","data-[side=bottom]:origin-top data-[side=top]:origin-bottom data-[side=left]:origin-right data-[side=right]:origin-left","data-[align=end]:data-[side=bottom]:origin-top-right data-[align=end]:data-[side=top]:origin-bottom-right","data-[align=start]:data-[side=bottom]:origin-top-left data-[align=start]:data-[side=top]:origin-bottom-left",t),...a})}));oa.displayName=sr.displayName;const kt=n.forwardRef(({className:t,inset:s,...a},r)=>e.jsx(ar,{ref:r,className:ye("relative flex cursor-default select-none items-center gap-2 rounded-[var(--radius-sm)] px-2 py-1.5 text-sm outline-none transition-colors","focus:bg-[var(--bg-subtle)] focus:text-[var(--fg-default)]","data-[disabled]:pointer-events-none data-[disabled]:opacity-50",s&&"pl-8",t),...a}));kt.displayName=ar.displayName;const Io=n.forwardRef(({className:t,children:s,checked:a,...r},o)=>e.jsxs(rr,{ref:o,className:ye("relative flex cursor-default select-none items-center rounded-[var(--radius-sm)] py-1.5 pl-8 pr-2 text-sm outline-none transition-colors","focus:bg-[var(--bg-subtle)] focus:text-[var(--fg-default)]","data-[disabled]:pointer-events-none data-[disabled]:opacity-50",t),checked:a,...r,children:[e.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:e.jsx(nr,{children:e.jsx(ot,{className:"h-4 w-4"})})}),s]}));Io.displayName=rr.displayName;const To=n.forwardRef(({className:t,children:s,...a},r)=>e.jsxs(lr,{ref:r,className:ye("relative flex cursor-default select-none items-center rounded-[var(--radius-sm)] py-1.5 pl-8 pr-2 text-sm outline-none transition-colors","focus:bg-[var(--bg-subtle)] focus:text-[var(--fg-default)]","data-[disabled]:pointer-events-none data-[disabled]:opacity-50",t),...a,children:[e.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:e.jsx(nr,{children:e.jsx(tl,{className:"h-2 w-2 fill-current"})})}),s]}));To.displayName=lr.displayName;const Hr=n.forwardRef(({className:t,inset:s,...a},r)=>e.jsx(or,{ref:r,className:ye("px-2 py-1.5 text-xs font-medium text-[var(--fg-subtle)]",s&&"pl-8",t),...a}));Hr.displayName=or.displayName;const vs=n.forwardRef(({className:t,...s},a)=>e.jsx(ir,{ref:a,className:ye("-mx-1 my-1 h-px bg-[var(--border-muted)]",t),...s}));vs.displayName=ir.displayName;function Eo(t){return t>=1e6?(t/1e6).toFixed(1)+"M":t>=1e3?(t/1e3).toFixed(1)+"k":String(t)}function Po(t,s){if(t.length<=s)return t;const a=Math.floor((s-1)/2);return t.slice(0,a)+"…"+t.slice(t.length-a)}const Mo={recipes:"sidebar.recipes",spm:"sidebar.moduleExplorer",candidates:"sidebar.candidates",knowledge:"sidebar.batchManage",guard:"sidebar.guard",panorama:"sidebar.panorama",skills:"sidebar.skills",wiki:"sidebar.repoWiki",signals:"sidebar.signals",ai:"sidebar.aiAssistant",help:"sidebar.help"},Lo=({setShowCreateModal:t,aiConfig:s,llmReady:a=!0,onOpenLlmConfig:r,onBeforeAiSwitch:o,onAiConfigChange:l,activeTab:i,onOpenCommandPalette:p,projectName:d,candidateCount:g=0,showSignalMonitor:x=!1,onToggleSignalMonitor:h})=>{const{toggle:u,isOpen:m}=Zt(),{t:c}=Ae(),[j,A]=n.useState([]),[D,I]=n.useState(!1),[P,J]=n.useState(null),w=n.useCallback(()=>{Q.getTokenUsage7Days().then(L=>J(L.summary)).catch(()=>{})},[]);n.useEffect(()=>{w();const L=Cs(),O=()=>w();return L.on("candidate-created",O),L.on("bootstrap:all-completed",O),L.on("token-usage-updated",O),()=>{L.off("candidate-created",O),L.off("bootstrap:all-completed",O),L.off("token-usage-updated",O)}},[w]);const B=async L=>{const O=s?.provider==="mock"&&L.id!=="mock";if(!(s?.provider!=="mock"&&L.id==="mock"&&!window.confirm(c("header.mockSwitchToConfirm")))){if(O&&window.confirm(c("header.mockSwitchFromConfirm")))try{const N=await Q.cleanupMockData();console.log(`Mock cleanup: ${N.deleted} entries deleted`)}catch(N){console.error("Mock cleanup failed",N)}I(!0);try{o?.(),await Q.setAiConfig(L.id,L.defaultModel),l&&l()}catch(q){console.error("AI config update failed",q)}finally{I(!1)}}},z=n.useCallback(()=>{j.length===0&&Q.getAiProviders().then(A).catch(()=>{})},[j.length]);n.useEffect(()=>{z()},[z]);const k=s?j.find(L=>L.id===s.provider)?.hasKey:void 0,E=i?c(Mo[i],{count:g}):"";return e.jsx(Mr,{children:e.jsxs("header",{className:"h-[var(--topbar-height)] flex items-center justify-between px-5 border-b border-[var(--border-muted)] glass shrink-0 gap-3 select-none z-10",children:[e.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[e.jsx("span",{className:"text-sm text-[var(--fg-subtle)] font-medium truncate max-w-[160px]",title:d||"AutoSnippet",children:d||"AutoSnippet"}),E&&e.jsxs(e.Fragment,{children:[e.jsx(Ue,{size:14,className:"text-[var(--fg-subtle)]/50 shrink-0"}),e.jsx("span",{className:"text-sm text-[var(--fg-default)] font-semibold truncate",children:E})]})]}),e.jsxs("button",{onClick:p,className:ye("flex items-center gap-2 h-8 px-3 rounded-[var(--radius-full)] border border-[var(--border-default)] bg-[var(--bg-subtle)]/60","text-sm text-[var(--fg-subtle)] hover:border-[var(--accent)]/40 hover:text-[var(--fg-muted)] hover:shadow-[0_0_12px_var(--accent-glow)] transition-all","w-64 justify-between backdrop-blur-sm"),children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(xt,{size:14}),e.jsx("span",{children:c("header.searchPlaceholder")})]}),e.jsx("kbd",{className:"hidden sm:inline-flex items-center gap-0.5 rounded-[var(--radius-sm)] border border-[var(--border-default)] bg-[var(--bg-root)]/60 px-1.5 py-0.5 text-[10px] font-mono text-[var(--fg-subtle)]",children:"⌘K"})]}),e.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[!a&&e.jsxs(We,{variant:"ghost",size:"sm",onClick:r,className:"text-[var(--warning)] animate-pulse",children:[e.jsx(Vt,{size:14}),e.jsx("span",{className:"text-xs",children:c("header.configureLlm")})]}),a&&s&&e.jsxs($r,{onOpenChange:L=>L&&z(),children:[e.jsx(Or,{asChild:!0,children:e.jsxs(We,{variant:"ghost",size:"sm",className:"gap-1.5 focus-visible:ring-0 focus-visible:ring-offset-0",children:[e.jsxs("span",{className:"relative shrink-0",children:[s.provider==="mock"?e.jsx(sl,{size:14,className:"text-amber-500"}):e.jsx(Jt,{size:14}),e.jsx("span",{className:ye("absolute -top-0.5 -right-0.5 w-[6px] h-[6px] rounded-full ring-1 ring-[var(--bg-root)]",s.provider==="mock"?"bg-amber-500":k===!1?"bg-red-400":"bg-emerald-500")})]}),e.jsx("span",{className:"text-xs",title:`${s.provider}/${s.model}`,children:Po(s.model,28)}),s.provider==="mock"&&e.jsx("span",{className:"text-[10px] px-1.5 py-0.5 rounded-full bg-amber-500/15 text-amber-500 font-medium shrink-0",children:"Mock"}),P&&P.total_tokens>0&&e.jsxs("span",{className:"flex items-center gap-0.5 ml-0.5 text-[10px] text-[var(--fg-subtle)] tabular-nums shrink-0",children:[e.jsx(Be,{size:9,className:"text-amber-500/70"}),Eo(P.total_tokens)]}),e.jsx(vt,{size:12,className:"shrink-0"})]})}),e.jsxs(oa,{align:"end",className:"w-56",children:[e.jsx(Hr,{children:c("header.switchAi")}),s.provider==="mock"&&e.jsxs("div",{className:"px-2 py-1.5 text-[11px] text-amber-500/80 bg-amber-500/5 rounded mx-1 mb-1",children:["🧪 ",c("header.mockModeHint")]}),e.jsx(vs,{}),j.length===0?e.jsx(kt,{disabled:!0,children:c("common.loading")}):j.map(L=>e.jsxs(kt,{onClick:()=>B(L),disabled:D,className:ye(s.provider===L.id&&"bg-[var(--accent-subtle)] text-[var(--accent)] font-medium",L.hasKey===!1&&"opacity-50"),children:[e.jsxs("span",{className:"flex items-center gap-2 flex-1",children:[e.jsx("span",{className:ye("inline-block w-1.5 h-1.5 rounded-full shrink-0",L.hasKey!==!1?"bg-emerald-500":"bg-[var(--fg-subtle)]")}),L.label]}),s.provider===L.id&&e.jsx("span",{className:"text-xs",children:"✓"})]},L.id)),e.jsx(vs,{}),e.jsxs(kt,{onClick:r,children:[e.jsx(Vt,{size:14}),e.jsx("span",{children:c("header.editEnvConfig")})]})]})]}),e.jsxs(wt,{children:[e.jsx(Nt,{asChild:!0,children:e.jsx(We,{variant:"ghost",size:"icon-sm",onClick:()=>t(!0),children:e.jsx(mt,{size:16})})}),e.jsx(bt,{children:c("header.newRecipe")})]}),h&&e.jsxs(wt,{children:[e.jsx(Nt,{asChild:!0,children:e.jsx(We,{variant:x?"accent":"ghost",size:"icon-sm",onClick:h,children:e.jsx(Yt,{size:16})})}),e.jsx(bt,{children:c(x?"signals.closeMonitor":"signals.openMonitor")})]}),e.jsxs(wt,{children:[e.jsx(Nt,{asChild:!0,children:e.jsx(We,{variant:m?"accent":"ghost",size:"icon-sm",onClick:u,children:e.jsx(ut,{size:16})})}),e.jsx(bt,{children:c(m?"header.closeAiChat":"header.openAiChat")})]})," "]})]})})},Fo=Mn,_o=En,Kr=n.forwardRef(({className:t,...s},a)=>e.jsx(cr,{ref:a,className:ye("fixed inset-0 z-50 bg-black/40 backdrop-blur-md","data-[state=open]:animate-in data-[state=open]:fade-in-0","data-[state=closed]:animate-out data-[state=closed]:fade-out-0",t),...s}));Kr.displayName=cr.displayName;const qr=n.forwardRef(({className:t,children:s,size:a="md",hideClose:r=!1,...o},l)=>e.jsxs(_o,{children:[e.jsx(Kr,{}),e.jsxs(dr,{ref:l,className:ye("fixed left-1/2 top-1/2 z-50 -translate-x-1/2 -translate-y-1/2","w-full rounded-[var(--radius-xl)] border border-[var(--border-default)] bg-[var(--bg-surface)] shadow-[var(--shadow-xl)]","dark:bg-[var(--bg-surface)]/95 dark:backdrop-blur-xl dark:border-[var(--glass-border)]","dark:shadow-[0_24px_80px_rgba(0,0,0,0.6),0_0_1px_rgba(255,255,255,0.08)]","data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95 data-[state=open]:slide-in-from-left-1/2 data-[state=open]:slide-in-from-top-[48%]","data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[state=closed]:slide-out-to-left-1/2 data-[state=closed]:slide-out-to-top-[48%]","duration-200",{"max-w-md":a==="sm","max-w-lg":a==="md","max-w-3xl":a==="lg","max-w-5xl":a==="xl","max-w-[calc(100vw-4rem)] max-h-[calc(100vh-4rem)]":a==="full"},t),...o,children:[s,!r&&e.jsxs(Pn,{className:"absolute right-4 top-4 rounded-[var(--radius-sm)] p-1 text-[var(--fg-subtle)] opacity-70 transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-[var(--accent)] focus:ring-offset-2",children:[e.jsx(ze,{className:"h-4 w-4"}),e.jsx("span",{className:"sr-only",children:"Close"})]})]})]}));qr.displayName=dr.displayName;const zo=n.forwardRef(({className:t,...s},a)=>e.jsx(ur,{ref:a,className:ye("text-lg font-semibold text-[var(--fg-default)]",t),...s}));zo.displayName=ur.displayName;const Bo=n.forwardRef(({className:t,...s},a)=>e.jsx(mr,{ref:a,className:ye("text-sm text-[var(--fg-muted)]",t),...s}));Bo.displayName=mr.displayName;const Ur=n.forwardRef(({className:t,...s},a)=>e.jsx(Je,{ref:a,className:ye("flex h-full w-full flex-col overflow-hidden rounded-[var(--radius-xl)] text-[var(--fg-default)]",t),...s}));Ur.displayName=Je.displayName;const Wr=n.forwardRef(({className:t,...s},a)=>e.jsxs("div",{className:"flex items-center border-b border-[var(--border-muted)] px-3",children:[e.jsx(xt,{className:"mr-2 h-4 w-4 shrink-0 text-[var(--fg-subtle)]"}),e.jsx(Je.Input,{ref:a,className:ye("flex h-12 w-full bg-transparent py-3 text-sm text-[var(--fg-default)] outline-none placeholder:text-[var(--fg-subtle)]","disabled:cursor-not-allowed disabled:opacity-50",t),...s})]}));Wr.displayName=Je.Input.displayName;const Vr=n.forwardRef(({className:t,...s},a)=>e.jsx(Je.List,{ref:a,className:ye("max-h-[300px] overflow-y-auto overflow-x-hidden p-1",t),...s}));Vr.displayName=Je.List.displayName;const Jr=n.forwardRef((t,s)=>e.jsx(Je.Empty,{ref:s,className:"py-6 text-center text-sm text-[var(--fg-subtle)]",...t}));Jr.displayName=Je.Empty.displayName;const xs=n.forwardRef(({className:t,...s},a)=>e.jsx(Je.Group,{ref:a,className:ye("overflow-hidden p-1 text-[var(--fg-default)]","[&_[cmdk-group-heading]]:px-2 [&_[cmdk-group-heading]]:py-1.5 [&_[cmdk-group-heading]]:text-xs [&_[cmdk-group-heading]]:font-medium [&_[cmdk-group-heading]]:text-[var(--fg-subtle)]",t),...s}));xs.displayName=Je.Group.displayName;const Ws=n.forwardRef(({className:t,...s},a)=>e.jsx(Je.Separator,{ref:a,className:ye("-mx-1 h-px bg-[var(--border-muted)]",t),...s}));Ws.displayName=Je.Separator.displayName;const Rt=n.forwardRef(({className:t,...s},a)=>e.jsx(Je.Item,{ref:a,className:ye("relative flex cursor-default gap-2 select-none items-center rounded-[var(--radius-md)] px-2.5 py-2 text-sm outline-none transition-colors","data-[selected=true]:bg-[var(--accent-subtle)] data-[selected=true]:text-[var(--accent)]","data-[disabled=true]:pointer-events-none data-[disabled=true]:opacity-50",t),...s}));Rt.displayName=Je.Item.displayName;function Ra({className:t,...s}){return e.jsx("span",{className:ye("ml-auto text-xs tracking-widest text-[var(--fg-subtle)]",t),...s})}const Go={recipes:al,spm:Lt,candidates:Ye,knowledge:Qs,guard:Ve,panorama:Ge,skills:qe,wiki:Qe,signals:Yt,ai:ut,help:fr},Ms={recipes:"sidebar.recipes",spm:"sidebar.moduleExplorer",candidates:"sidebar.candidates",knowledge:"sidebar.batchManage",guard:"sidebar.guard",panorama:"sidebar.panorama",skills:"sidebar.skills",wiki:"sidebar.repoWiki",signals:"sidebar.signals",ai:"sidebar.aiAssistant",help:"sidebar.help"},$o=({open:t,onOpenChange:s,navigateToTab:a,setShowCreateModal:r,onSemanticSearch:o,searchQuery:l,setSearchQuery:i,onOpenLlmConfig:p,candidateCount:d=0})=>{const{t:g}=Ae(),[x,h]=n.useState([]);n.useEffect(()=>{t&&x.length===0&&Q.fetchData().then(c=>{const j=c?.recipes||[];h(j.slice(0,5).map(A=>({name:A.name||A.title,title:A.title||A.name})))}).catch(()=>{})},[t]),n.useEffect(()=>{const c=j=>{(j.metaKey||j.ctrlKey)&&j.key==="k"&&(j.preventDefault(),s(!t))};return document.addEventListener("keydown",c),()=>document.removeEventListener("keydown",c)},[t,s]);const u=n.useCallback(c=>{c(),s(!1)},[s]),m=Object.keys(Ms);return e.jsx(Fo,{open:t,onOpenChange:s,children:e.jsx(qr,{size:"md",hideClose:!0,className:"!p-0 !top-[15vh] !translate-y-0 overflow-hidden",style:{backgroundColor:"var(--bg-root)"},children:e.jsxs(Ur,{className:"[&_[cmdk-group-heading]]:px-2 [&_[cmdk-group-heading]]:font-medium [&_[cmdk-group-heading]]:text-[var(--fg-subtle)] [&_[cmdk-item]]:px-3 [&_[cmdk-item]]:py-2.5",children:[e.jsx(Wr,{placeholder:g("commandPalette.searchPlaceholder")||"搜索知识、命令、页面...",value:l,onValueChange:i}),e.jsxs(Vr,{className:"max-h-[360px]",children:[e.jsx(Jr,{children:g("commandPalette.noResults")||"没有找到结果"}),x.length>0&&e.jsx(xs,{heading:g("commandPalette.recent")||"最近",children:x.map(c=>e.jsxs(Rt,{value:c.title,onSelect:()=>u(()=>{a("recipes"),i(c.title)}),children:[e.jsx(Qe,{className:"mr-2 h-4 w-4 text-[var(--fg-subtle)]"}),e.jsx("span",{children:c.title})]},c.name))}),e.jsx(Ws,{}),e.jsx(xs,{heading:g("commandPalette.pages")||"页面",children:m.map(c=>{const j=Go[c],A=c==="candidates"?{count:d}:void 0;return e.jsxs(Rt,{value:g(Ms[c],A),onSelect:()=>u(()=>a(c)),children:[e.jsx(j,{className:"mr-2 h-4 w-4 text-[var(--fg-subtle)]"}),e.jsx("span",{children:g(Ms[c],A)})]},c)})}),e.jsx(Ws,{}),e.jsxs(xs,{heading:g("commandPalette.commands")||"命令",children:[e.jsxs(Rt,{value:"new recipe",onSelect:()=>u(()=>r(!0)),children:[e.jsx(mt,{className:"mr-2 h-4 w-4 text-[var(--fg-subtle)]"}),e.jsx("span",{children:g("header.newRecipe")}),e.jsx(Ra,{children:"⌘N"})]}),o&&e.jsxs(Rt,{value:"semantic search",onSelect:()=>u(()=>o(l)),children:[e.jsx(rl,{className:"mr-2 h-4 w-4 text-[var(--fg-subtle)]"}),e.jsx("span",{children:g("header.semanticSearch")}),e.jsx(Ra,{children:"⌘⇧F"})]}),p&&e.jsxs(Rt,{value:"llm config",onSelect:()=>u(()=>p()),children:[e.jsx(Vt,{className:"mr-2 h-4 w-4 text-[var(--fg-subtle)]"}),e.jsx("span",{children:g("header.configureLlm")})]})]})]})]})})})},Yr="asd-drawer-wide";function Oo(){try{return localStorage.getItem(Yr)==="1"}catch{return!1}}function ia(){const[t,s]=n.useState(Oo),a=n.useCallback(()=>{s(r=>{const o=!r;try{localStorage.setItem(Yr,o?"1":"0")}catch{}return o})},[]);return{isWide:t,toggle:a}}const Ho={xs:"h-6 text-[10px] px-1.5 gap-1 rounded",sm:"h-7 text-[11px] px-2 gap-1.5 rounded-md",md:"h-9 text-sm px-3 gap-2 rounded-lg"},Ko={xs:"text-[10px] px-1.5 py-1",sm:"text-[11px] px-2 py-1.5",md:"text-sm px-3 py-2"},tt=({value:t,onChange:s,options:a,className:r,contentClassName:o,placeholder:l="—",disabled:i=!1,size:p="sm",minWidth:d,direction:g="auto",id:x,name:h})=>{const[u,m]=n.useState(!1),[c,j]=n.useState(-1),[A,D]=n.useState(!1),I=n.useRef(null),P=n.useRef(null),J=a.find(E=>E.value===t),w=n.useCallback(()=>{if(g==="up")return!0;if(g==="down"||!I.current)return!1;const E=I.current.getBoundingClientRect(),L=window.innerHeight-E.bottom,O=Math.min(a.length*28+8,248);return L<O&&E.top>O},[g,a.length]),B=n.useCallback(()=>{D(w()),m(!0),j(a.findIndex(E=>E.value===t))},[w,a,t]);n.useEffect(()=>{if(!u)return;const E=L=>{I.current?.contains(L.target)||P.current?.contains(L.target)||m(!1)};return document.addEventListener("mousedown",E),()=>document.removeEventListener("mousedown",E)},[u]);const z=n.useCallback(E=>{if(i)return;const L=a.filter(O=>!O.disabled);E.key==="Enter"||E.key===" "?(E.preventDefault(),u?c>=0&&c<L.length&&(s(L[c].value),m(!1)):B()):E.key==="Escape"?m(!1):E.key==="ArrowDown"?(E.preventDefault(),u?j(O=>Math.min(O+1,L.length-1)):B()):E.key==="ArrowUp"&&(E.preventDefault(),j(O=>Math.max(O-1,0)))},[i,u,c,a,t,s,B]);n.useEffect(()=>{if(!u||c<0||!P.current)return;P.current.querySelectorAll("[data-select-item]")[c]?.scrollIntoView({block:"nearest"})},[c,u]);const k=E=>{s(E),m(!1),I.current?.focus()};return e.jsxs("div",{className:"relative inline-block",style:d?{minWidth:d}:void 0,children:[h&&e.jsx("input",{type:"hidden",name:h,value:t}),e.jsxs("button",{ref:I,id:x,type:"button",role:"combobox","aria-expanded":u,"aria-haspopup":"listbox",disabled:i,onClick:()=>{i||(u?m(!1):B())},onKeyDown:z,className:ye("inline-flex items-center justify-between border border-[var(--border-default)] bg-[var(--bg-surface)] text-[var(--fg-default)] font-medium transition-colors","hover:border-[var(--border-emphasis)] hover:bg-[var(--bg-subtle)]","disabled:opacity-50 disabled:pointer-events-none",Ho[p],r),children:[e.jsx("span",{className:"truncate",children:J?e.jsxs(e.Fragment,{children:[J.icon&&e.jsx("span",{className:"mr-1",children:J.icon}),J.label]}):l}),e.jsx(vt,{size:p==="xs"?10:p==="sm"?12:14,className:ye("shrink-0 text-[var(--fg-muted)] transition-transform",u&&"rotate-180")})]}),u&&e.jsx("div",{ref:P,role:"listbox",className:ye("absolute z-50 min-w-full max-h-60 overflow-y-auto","rounded-[var(--radius-md)] border border-[var(--border-default)] bg-[var(--bg-surface)] shadow-[var(--shadow-lg)] p-0.5",A?"bottom-full mb-1 animate-in fade-in-0 zoom-in-95 slide-in-from-bottom-1":"top-full mt-1 animate-in fade-in-0 zoom-in-95 slide-in-from-top-1",o),children:a.map((E,L)=>{const O=E.value===t,W=L===c;return e.jsxs("div",{"data-select-item":!0,role:"option","aria-selected":O,onClick:()=>!E.disabled&&k(E.value),onMouseEnter:()=>!E.disabled&&j(L),className:ye("flex items-center justify-between cursor-pointer rounded-[var(--radius-sm)] transition-colors",Ko[p],E.disabled&&"opacity-40 pointer-events-none",W&&"bg-[var(--bg-subtle)]",O&&"text-[var(--accent)] font-semibold"),children:[e.jsxs("span",{className:"flex items-center gap-1.5 truncate",children:[E.icon&&e.jsx("span",{children:E.icon}),E.label]}),O&&e.jsx(ot,{size:p==="xs"?10:12,className:"shrink-0 text-[var(--accent)]"})]},E.value)})})]})},ca=({currentPage:t,totalPages:s,totalItems:a,pageSize:r,onPageChange:o,onPageSizeChange:l,pageSizeOptions:i=[12,24,48,96]})=>{if(s<=1&&a<=i[0])return null;const{t:p}=Ae(),d=(t-1)*r+1,g=Math.min(t*r,a),x=()=>{const h=[];if(s<=7)for(let m=1;m<=s;m++)h.push(m);else if(t<=3){for(let m=1;m<=5;m++)h.push(m);h.push("..."),h.push(s)}else if(t>=s-2){h.push(1),h.push("...");for(let m=s-5+1;m<=s;m++)h.push(m)}else{h.push(1),h.push("...");for(let m=t-1;m<=t+1;m++)h.push(m);h.push("..."),h.push(s)}return h};return e.jsxs("div",{className:"flex items-center justify-between mt-6 px-2",children:[e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx("span",{className:"text-sm text-[var(--fg-secondary)]",children:p("pagination.showing",{start:d,end:g,total:a})}),l&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-sm text-[var(--fg-secondary)]",children:p("pagination.perPage")}),e.jsx(tt,{value:String(r),onChange:h=>l(Number(h)),options:i.map(h=>({value:String(h),label:String(h)})),size:"sm"}),e.jsx("span",{className:"text-sm text-[var(--fg-secondary)]",children:p("pagination.unit")})]})]}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("button",{onClick:()=>o(1),disabled:t===1,className:"p-1.5 rounded-md hover:bg-[var(--bg-subtle)] disabled:opacity-30 disabled:cursor-not-allowed transition-colors",title:p("pagination.firstPage"),children:e.jsx(nl,{size:H.md,className:"text-[var(--fg-secondary)]"})}),e.jsx("button",{onClick:()=>o(t-1),disabled:t===1,className:"p-1.5 rounded-md hover:bg-[var(--bg-subtle)] disabled:opacity-30 disabled:cursor-not-allowed transition-colors",title:p("pagination.prevPage"),children:e.jsx(Xs,{size:H.md,className:"text-[var(--fg-secondary)]"})}),e.jsx("div",{className:"flex items-center gap-1 mx-2",children:x().map((h,u)=>typeof h=="number"?e.jsx("button",{onClick:()=>o(h),className:`min-w-[32px] h-8 px-2 rounded-md text-sm font-medium transition-colors ${t===h?"bg-blue-600 text-white":"hover:bg-[var(--bg-subtle)] text-[var(--fg-secondary)]"}`,children:h},u):e.jsx("span",{className:"px-1 text-[var(--fg-muted)]",children:h},u))}),e.jsx("button",{onClick:()=>o(t+1),disabled:t===s,className:"p-1.5 rounded-md hover:bg-[var(--bg-subtle)] disabled:opacity-30 disabled:cursor-not-allowed transition-colors",title:p("pagination.nextPage"),children:e.jsx(Ue,{size:H.md,className:"text-[var(--fg-secondary)]"})}),e.jsx("button",{onClick:()=>o(s),disabled:t===s,className:"p-1.5 rounded-md hover:bg-[var(--bg-subtle)] disabled:opacity-30 disabled:cursor-not-allowed transition-colors",title:p("pagination.lastPage"),children:e.jsx(ll,{size:H.md,className:"text-[var(--fg-secondary)]"})})]})]})},qo=it.memo(({code:t,lang:s,editorStyles:a})=>e.jsx(Ya,{language:s,style:Qa,showLineNumbers:!1,customStyle:{margin:0,padding:a.padding,fontSize:a.fontSize,lineHeight:a.lineHeight,borderRadius:"0",whiteSpace:"pre",verticalAlign:"top",display:"inline-block",minWidth:"100%",minHeight:"100%",backgroundColor:"#282c34"},codeTagProps:{style:{fontFamily:a.fontFamily,whiteSpace:"pre",verticalAlign:"top",fontSize:a.fontSize,lineHeight:a.lineHeight}},PreTag:"div",children:(()=>{const r=t;return r[r.length-1]===`
74
74
  `?r+" ":r})()})),as=19.5,Uo=it.memo(({totalLines:t,scrollTop:s,viewportHeight:a,fontSize:r,lineHeight:o,fontFamily:l})=>{const p=Math.max(0,Math.floor(s/as)-10),d=Math.ceil(a/as)+20,g=Math.min(t,p+d),x=p*as,h=Math.max(0,(t-g)*as),u=[];for(let m=p;m<g;m++)u.push(e.jsx("div",{children:m+1},m));return e.jsx("div",{style:{paddingTop:x,paddingBottom:h,fontSize:r,lineHeight:o,fontFamily:l},children:u})}),ys=({value:t,onChange:s,onCursorChange:a,language:r="javascript",height:o="400px",className:l="",placeholder:i="",rows:p,showLineNumbers:d=!0})=>{const g=n.useRef(null),x=n.useRef(null),h=n.useRef(null),u=n.useRef(null),[m,c]=n.useState(t),j=n.useRef(void 0);n.useEffect(()=>{const E=t.length>5e3?200:t.length>1e3?80:0;if(E===0){c(t);return}return j.current=setTimeout(()=>c(t),E),()=>clearTimeout(j.current)},[t]);const[A,D]=n.useState({top:0,height:400}),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?.toLowerCase()]||r?.toLowerCase()||"text",J=n.useMemo(()=>({padding:"1rem 1.25rem",fontSize:"0.8125rem",lineHeight:1.5,fontFamily:"ui-monospace, monospace",minHeight:"200px"}),[]),w=n.useCallback(E=>{const L=E.currentTarget;h.current&&(h.current.scrollTop=L.scrollTop,h.current.scrollLeft=L.scrollLeft),u.current&&(u.current.scrollTop=L.scrollTop),D({top:L.scrollTop,height:L.clientHeight})},[]),B=n.useCallback(E=>{s(E.target.value),a&&a(E.target.selectionStart||0)},[s,a]),z=n.useCallback(E=>{a&&a(E.currentTarget.selectionStart||0)},[a]),k=n.useMemo(()=>(t||"").split(`
75
- `).length,[t]);return n.useEffect(()=>{x.current&&D(E=>({...E,height:x.current.clientHeight}))},[]),e.jsxs("div",{ref:g,className:`relative overflow-hidden ${l}`,style:{height:p?"auto":o,minHeight:J.minHeight,display:"flex",borderRadius:"0",backgroundColor:"#282c34"},children:[d&&e.jsx("div",{ref:u,className:"flex-shrink-0 overflow-hidden pointer-events-none select-none",style:{width:"3.5em",backgroundColor:"#282c34",color:"#5c6370",textAlign:"right",paddingTop:"1rem",paddingRight:"0.75em",paddingBottom:"1rem",borderRadius:"0",borderRight:"1px solid #333842"},children:e.jsx(Uo,{totalLines:k,scrollTop:A.top,viewportHeight:A.height,fontSize:J.fontSize,lineHeight:J.lineHeight,fontFamily:J.fontFamily})}),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(qo,{code:m||i,lang:P,editorStyles:J})}),e.jsx("textarea",{ref:x,value:t,onChange:B,onSelect:z,onKeyUp:z,onClick:z,onScroll:w,rows:p,placeholder:i,className:"absolute inset-0 w-full h-full resize-none outline-none editor-with-dark-scrollbar",style:{padding:J.padding,lineHeight:J.lineHeight,fontSize:J.fontSize,fontFamily:J.fontFamily,caretColor:"#61afef",backgroundColor:"transparent",color:"transparent",WebkitTextFillColor:"transparent",zIndex:10,border:"none",margin:0,overflow:"auto",overflowX:"hidden",WebkitAppearance:"none",appearance:"none",boxSizing:"border-box",whiteSpace:"pre"}})]})]})},da=({badges:t,metadata:s,tags:a,maxTags:r,id:o,sourceFile:l,sourceFileLabel:i="源文件"})=>{const p=r&&a?a.slice(0,r):a;return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"px-6 py-4 border-b border-[var(--border-default)] space-y-3",children:[t.length>0&&e.jsx("div",{className:"flex flex-wrap items-center gap-1.5",children:t.map((d,g)=>{const x=d.icon;return e.jsxs("span",{className:`text-[10px] font-medium px-1.5 py-0.5 rounded border inline-flex items-center gap-1 ${d.className}`,children:[x&&e.jsx(x,{size:10}),d.label]},g)})}),(s.length>0||o||l)&&e.jsxs("div",{className:"flex flex-wrap gap-x-5 gap-y-2 text-xs",children:[s.map((d,g)=>{const x=d.icon;return e.jsxs("div",{className:`flex items-center gap-1.5${d.fullWidth?" basis-full mt-0.5":""}`,children:[e.jsx(x,{size:11,className:`${d.iconClass} shrink-0`}),e.jsx("span",{className:"text-[var(--fg-muted)]",children:d.label}),d.isCode?e.jsx("code",{className:"font-mono text-[11px] text-[var(--fg-secondary)] break-all",children:d.value}):e.jsx("span",{className:`font-medium text-[var(--fg-secondary)]${d.mono?" font-mono text-[11px]":""}`,children:d.value})]},g)}),o&&e.jsxs("div",{className:"flex items-center gap-1.5 basis-full mt-0.5",children:[e.jsx(Ys,{size:11,className:"text-[var(--fg-muted)] shrink-0"}),e.jsx("span",{className:"text-[var(--fg-muted)]",children:"ID"}),e.jsx("code",{className:"font-mono text-[11px] text-[var(--fg-secondary)] break-all",children:o})]}),l&&e.jsxs("div",{className:"flex items-center gap-1.5 basis-full",children:[e.jsx(Lt,{size:11,className:"text-[var(--fg-muted)] shrink-0"}),e.jsx("span",{className:"text-[var(--fg-muted)]",children:i}),e.jsx("code",{className:"font-mono text-[11px] text-[var(--fg-secondary)] break-all",title:l,children:l})]})]})]}),p&&p.length>0&&e.jsxs("div",{className:"px-6 py-3 border-b border-[var(--border-default)] flex flex-wrap items-center gap-1.5",children:[e.jsx(jr,{size:11,className:"text-[var(--fg-muted)] mr-0.5"}),p.map((d,g)=>e.jsx("span",{className:"text-[9px] px-2 py-0.5 rounded bg-[var(--accent-subtle)] text-[var(--accent)] border border-[var(--border-default)] font-medium",children:typeof d=="string"?d:String(d)},g))]})]})},Wo=({label:t,text:s})=>s?e.jsxs("div",{className:"px-6 py-4 border-b border-[var(--border-default)]",children:[e.jsx("label",{className:"text-[10px] font-bold text-[var(--fg-muted)] uppercase mb-1.5 block",children:t}),e.jsx("p",{className:"text-sm text-[var(--fg-secondary)] leading-relaxed",children:s})]}):null,Vo=({reasoning:t,labels:s,filterSubmitted:a=!1})=>{if(!t)return null;const r=t,o=r.whyStandard&&(!a||!/^Submitted via /i.test(r.whyStandard));return o||r.sources&&r.sources.length>0||r.confidence!=null&&r.confidence>0?e.jsxs("div",{className:"px-6 py-4 border-b border-[var(--border-default)]",children:[e.jsxs("label",{className:"text-[10px] font-bold text-[var(--fg-muted)] uppercase mb-2 block flex items-center gap-1.5",children:[e.jsx(St,{size:11,className:"text-amber-400"})," ",s.section]}),e.jsxs("div",{className:"bg-amber-50/30 border border-amber-100 rounded-xl p-4 space-y-2.5",children:[o&&e.jsx("p",{className:"text-sm text-[var(--fg-primary)] leading-relaxed",children:r.whyStandard}),r.sources&&r.sources.length>0&&e.jsxs("div",{className:"flex flex-wrap items-center gap-1.5",children:[e.jsx("span",{className:"text-[10px] text-[var(--fg-muted)] font-bold",children:s.source}),r.sources.map((i,p)=>e.jsx("code",{className:"text-[10px] px-2 py-0.5 bg-[var(--bg-surface)] border border-amber-200 rounded text-amber-700 font-mono",children:i},p))]}),r.confidence!=null&&r.confidence>0&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-[10px] text-[var(--fg-muted)] font-bold",children:s.confidence}),e.jsx("div",{className:"flex-1 max-w-[160px] h-1.5 bg-[var(--border-default)] rounded-full overflow-hidden",children:e.jsx("div",{className:"h-full bg-amber-400 rounded-full",style:{width:`${Math.round((r.confidence??0)*100)}%`}})}),e.jsxs("span",{className:"text-[10px] font-bold text-amber-600",children:[Math.round((r.confidence??0)*100),"%"]})]}),r.alternatives&&r.alternatives.length>0&&e.jsxs("div",{className:"flex flex-wrap items-center gap-1.5 pt-1",children:[e.jsx("span",{className:"text-[10px] text-[var(--fg-muted)] font-bold",children:s.alternatives}),r.alternatives.map((i,p)=>e.jsx("span",{className:"text-[10px] px-1.5 py-0.5 bg-[var(--bg-subtle)] border border-[var(--border-default)] rounded text-[var(--fg-secondary)]",children:i},p))]})]})]}):null},Jo=({quality:t,labels:s,formatFixed:a=!1})=>{if(!t?.grade||t.grade==="F")return null;const r=o=>a?o.toFixed(2):String(o);return e.jsxs("div",{className:"px-6 py-3 border-b border-[var(--border-default)]",children:[e.jsx("label",{className:"text-[10px] font-bold text-[var(--fg-muted)] uppercase mb-2 block",children:s.section}),e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx("span",{className:`text-2xl font-black ${t.grade==="A"?"text-emerald-600":t.grade==="B"?"text-blue-600":t.grade==="C"?"text-amber-600":t.grade==="D"?"text-orange-600":"text-[var(--fg-muted)]"}`,children:t.grade}),e.jsxs("div",{className:"flex-1 grid grid-cols-3 gap-2 text-xs",children:[t.completeness!=null&&t.completeness>0&&e.jsxs("div",{className:"text-center",children:[e.jsx("div",{className:"text-sm font-bold text-[var(--fg-primary)]",children:r(t.completeness)}),e.jsx("div",{className:"text-[var(--fg-muted)]",children:s.completeness})]}),t.adaptation!=null&&t.adaptation>0&&e.jsxs("div",{className:"text-center",children:[e.jsx("div",{className:"text-sm font-bold text-[var(--fg-primary)]",children:r(t.adaptation)}),e.jsx("div",{className:"text-[var(--fg-muted)]",children:s.adaptation})]}),t.documentation!=null&&t.documentation>0&&e.jsxs("div",{className:"text-center",children:[e.jsx("div",{className:"text-sm font-bold text-[var(--fg-primary)]",children:r(t.documentation)}),e.jsx("div",{className:"text-[var(--fg-muted)]",children:s.documentation})]})]})]})]})},Yo=({label:t,content:s})=>s?e.jsxs("div",{className:"px-6 py-4 border-b border-[var(--border-default)]",children:[e.jsxs("label",{className:"text-[10px] font-bold text-[var(--fg-muted)] uppercase mb-2 block flex items-center gap-1.5",children:[e.jsx(Qe,{size:11,className:"text-blue-400"})," ",t]}),e.jsx("div",{className:"bg-blue-50/30 border border-blue-100 rounded-xl p-4",children:e.jsx("div",{className:"markdown-body text-sm text-[var(--fg-primary)] leading-relaxed",children:e.jsx(Qt,{content:s})})})]}):null,Qo=({label:t,code:s,language:a})=>{if(!s)return null;const r=a==="objc"||a==="objective-c"?"objectivec":a||"text";return e.jsxs("div",{className:"px-6 py-4 border-b border-[var(--border-default)]",children:[e.jsxs("label",{className:"text-[10px] font-bold text-[var(--fg-muted)] uppercase mb-2 block flex items-center gap-1.5",children:[e.jsx(pt,{size:11,className:"text-emerald-500"})," ",t]}),e.jsx(ft,{code:s,language:r,showLineNumbers:!0})]})},Zo=({label:t,headers:s})=>!s||s.length===0?null:e.jsxs("div",{className:"px-6 py-3 border-b border-[var(--border-default)]",children:[e.jsx("label",{className:"text-[10px] font-bold text-[var(--fg-muted)] uppercase mb-2 block",children:t}),e.jsx("div",{className:"flex flex-wrap gap-1.5",children:s.map((a,r)=>e.jsx("code",{className:"px-2.5 py-1 bg-violet-50 text-violet-700 border border-violet-100 rounded-md text-[10px] font-mono font-medium",children:a},r))})]}),Xo=({label:t,text:s})=>s?e.jsxs("div",{className:"px-6 py-4 border-b border-[var(--border-default)]",children:[e.jsx("label",{className:"text-[10px] font-bold text-[var(--fg-muted)] uppercase mb-2 block",children:t}),e.jsx("div",{className:"bg-[var(--bg-subtle)] border border-[var(--border-default)] rounded-xl p-4",children:e.jsx("p",{className:"text-sm text-[var(--fg-secondary)] leading-relaxed",children:s})})]}):null,ei=({label:t,steps:s})=>!s||s.length===0?null:e.jsxs("div",{className:"px-6 py-4 border-b border-[var(--border-default)]",children:[e.jsx("label",{className:"text-[10px] font-bold text-[var(--fg-muted)] uppercase mb-2 block",children:t}),e.jsx("div",{className:"space-y-2",children:s.map((a,r)=>{if(typeof a=="string")return e.jsxs("div",{className:"bg-[var(--bg-subtle)] rounded-lg p-3 border border-[var(--border-default)] flex items-start gap-2.5",children:[e.jsx("span",{className:"text-[10px] font-bold text-blue-600 bg-blue-50 rounded-full w-5 h-5 flex items-center justify-center shrink-0 mt-0.5",children:r+1}),e.jsx("p",{className:"text-xs text-[var(--fg-primary)] leading-relaxed",children:a})]},r);const o=typeof a.title=="string"?a.title:"",l=typeof a.description=="string"?a.description:"",i=typeof a.code=="string"?a.code:"";return e.jsxs("div",{className:"bg-[var(--bg-subtle)] rounded-lg p-3 border border-[var(--border-default)]",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[e.jsx("span",{className:"text-[10px] font-bold text-blue-600 bg-blue-50 rounded-full w-5 h-5 flex items-center justify-center shrink-0",children:r+1}),o&&e.jsx("span",{className:"text-xs font-bold text-[var(--fg-primary)]",children:o})]}),l&&e.jsx("p",{className:"text-xs text-[var(--fg-secondary)] ml-7 leading-relaxed",children:l}),i&&e.jsx("pre",{className:"text-[11px] font-mono bg-slate-800 text-green-300 p-2.5 rounded-md mt-1.5 ml-7 overflow-x-auto whitespace-pre-wrap",children:i})]},r)})})]}),ti=({label:t,constraints:s})=>{if(!s)return null;const a=s,r=(a.guards?.length||0)+(a.boundaries?.length||0)+(a.preconditions?.length||0)+(a.sideEffects?.length||0);return r?e.jsxs("div",{className:"px-6 py-4 border-b border-[var(--border-default)]",children:[e.jsxs("label",{className:"text-[10px] font-bold text-[var(--fg-muted)] uppercase mb-2 block flex items-center gap-1.5",children:[e.jsx(Ve,{size:11,className:"text-amber-500"})," ",t," ",e.jsx("span",{className:"text-amber-500 font-mono",children:r})]}),e.jsxs("div",{className:"space-y-1.5 text-xs text-[var(--fg-secondary)]",children:[a.guards?.map((o,l)=>e.jsxs("div",{className:"flex gap-1.5 items-start",children:[e.jsx("span",{className:`text-xs mt-0.5 ${o.severity==="error"?"text-[var(--status-error)]":"text-[var(--status-warning)]"}`,children:"●"}),e.jsx("code",{className:"font-mono text-[10px] bg-[var(--bg-subtle)] px-1.5 py-0.5 rounded",children:o.pattern}),o.message&&e.jsxs("span",{className:"text-[10px] text-[var(--fg-muted)]",children:["— ",o.message]})]},l)),a.boundaries?.map((o,l)=>e.jsxs("div",{className:"flex gap-1.5",children:[e.jsx("span",{className:"text-[var(--status-warning)]",children:"●"}),o]},l)),a.preconditions?.map((o,l)=>e.jsxs("div",{className:"flex gap-1.5",children:[e.jsx("span",{className:"text-[var(--accent)]",children:"◆"}),o]},l)),a.sideEffects?.map((o,l)=>e.jsxs("div",{className:"flex gap-1.5",children:[e.jsx("span",{className:"text-pink-400",children:"⚡"}),o]},l))]})]}):null},si=({delivery:t,language:s})=>{if(!t)return null;const{topicHint:a,whenClause:r,doClause:o,dontClause:l,coreCode:i}=t;if(!o&&!r&&!l&&!a&&!i)return null;const p=s==="objectivec"||s==="objc"||s==="objective-c"?"objectivec":s||"text";return e.jsxs("div",{className:"px-6 py-4 border-b border-[var(--border-default)]",children:[e.jsxs("label",{className:"text-[10px] font-bold text-[var(--fg-muted)] uppercase mb-2 block flex items-center gap-1.5",children:[e.jsx(Ge,{size:11,className:"text-indigo-400"})," Cursor Delivery"]}),e.jsxs("div",{className:"bg-[var(--bg-subtle)] border border-[var(--border-default)] rounded-xl p-4 text-xs space-y-1.5",children:[a&&e.jsxs("div",{children:[e.jsx("span",{className:"text-indigo-400 font-medium",children:"Topic:"}),e.jsx("span",{className:"text-[var(--fg-primary)]",children:a})]}),r&&e.jsxs("div",{children:[e.jsx("span",{className:"text-blue-400 font-medium",children:"When:"}),e.jsx("span",{className:"text-[var(--fg-primary)]",children:r})]}),o&&e.jsxs("div",{children:[e.jsx("span",{className:"text-emerald-400 font-medium",children:"Do:"}),e.jsx("span",{className:"text-[var(--fg-primary)]",children:o})]}),l&&e.jsxs("div",{children:[e.jsx("span",{className:"text-red-400 font-medium",children:"Don't:"}),e.jsx("span",{className:"text-[var(--fg-primary)]",children:l})]}),i&&e.jsxs("div",{children:[e.jsx("span",{className:"text-purple-400 font-medium",children:"Core Code:"}),e.jsx("div",{className:"mt-1",children:e.jsx(ft,{code:i,language:p})})]})]})]})},Ee={Description:Wo,Reasoning:Vo,Quality:Jo,MarkdownSection:Yo,CodePattern:Qo,Headers:Zo,Rationale:Xo,Steps:ei,Constraints:ti,Delivery:si},ai=Xa("inline-flex items-center rounded-[var(--radius-sm)] px-2 py-0.5 text-xs font-medium leading-none whitespace-nowrap transition-all",{variants:{variant:{default:"bg-[var(--bg-subtle)] text-[var(--fg-muted)] border border-[var(--border-default)]",blue:"bg-[var(--accent-subtle)] text-[var(--accent)] border border-[var(--accent)]/15",green:"bg-[var(--success-subtle)] text-[var(--success)] border border-[var(--success)]/15",amber:"bg-[var(--warning-subtle)] text-[var(--warning)] border border-[var(--warning)]/15",red:"bg-[var(--danger-subtle)] text-[var(--danger)] border border-[var(--danger)]/15",info:"bg-[var(--info-subtle)] text-[var(--info)] border border-[var(--info)]/15",outline:"border border-[var(--border-default)] text-[var(--fg-muted)] bg-transparent",gradient:"text-white border-0"}},defaultVariants:{variant:"default"}}),Vs=n.forwardRef(({className:t,variant:s,style:a,...r},o)=>{const l=s==="gradient"?{background:"var(--accent-gradient)",...a}:a;return e.jsx("span",{ref:o,className:ye(ai({variant:s,className:t})),style:l,...r})});Vs.displayName="Badge";const ri=420,ni=({className:t="bg-black/20 backdrop-blur-[1px]"})=>e.jsx("div",{className:`absolute inset-0 ${t}`}),$e=({children:t,onClick:s,className:a="",style:r})=>{const{isOpen:o}=Zt();return e.jsx("div",{className:`fixed inset-0 overflow-hidden ${a}`,style:{right:o?ri:0,...r},onClick:s,children:t})};$e.Backdrop=ni;const li=n.forwardRef(({className:t,...s},a)=>e.jsx("div",{ref:a,className:ye("rounded-[var(--radius-lg)] border border-[var(--border-default)] bg-[var(--bg-surface)]","transition-all duration-250 ease-out","hover:border-[var(--border-emphasis)] hover:shadow-[var(--shadow-lg)] hover:-translate-y-0.5","dark:hover:shadow-[0_8px_32px_rgba(0,0,0,0.4),0_0_1px_rgba(255,255,255,0.06)]",t),...s}));li.displayName="Card";const oi=n.forwardRef(({className:t,...s},a)=>e.jsx("div",{ref:a,className:ye("flex items-center justify-between p-5 pb-0",t),...s}));oi.displayName="CardHeader";const ii=n.forwardRef(({className:t,...s},a)=>e.jsx("h3",{ref:a,className:ye("text-sm font-semibold text-[var(--fg-default)] leading-tight tracking-tight",t),...s}));ii.displayName="CardTitle";const ci=n.forwardRef(({className:t,...s},a)=>e.jsx("p",{ref:a,className:ye("text-sm text-[var(--fg-muted)] leading-relaxed",t),...s}));ci.displayName="CardDescription";const di=n.forwardRef(({className:t,...s},a)=>e.jsx("div",{ref:a,className:ye("p-5",t),...s}));di.displayName="CardContent";const ui=n.forwardRef(({className:t,...s},a)=>e.jsx("div",{ref:a,className:ye("flex items-center px-5 pb-5 pt-0",t),...s}));ui.displayName="CardFooter";const mi=n.forwardRef(({className:t,...s},a)=>e.jsx(Ln,{ref:a,className:ye("border-b border-[var(--border-muted)]",t),...s}));mi.displayName="AccordionItem";const pi=n.forwardRef(({className:t,children:s,...a},r)=>e.jsx(Fn,{className:"flex",children:e.jsxs(pr,{ref:r,className:ye("flex flex-1 items-center justify-between py-3 text-sm font-medium text-[var(--fg-default)] transition-all","hover:text-[var(--fg-default)] [&[data-state=open]>svg]:rotate-180",t),...a,children:[s,e.jsx(vt,{className:"h-4 w-4 shrink-0 text-[var(--fg-subtle)] transition-transform duration-200"})]})}));pi.displayName=pr.displayName;const xi=n.forwardRef(({className:t,children:s,...a},r)=>e.jsx(xr,{ref:r,className:"overflow-hidden text-sm data-[state=closed]:animate-accordion-up data-[state=open]:animate-accordion-down",...a,children:e.jsx("div",{className:ye("pb-4 pt-0",t),children:s})}));xi.displayName=xr.displayName;function Xe({className:t,...s}){return e.jsx("div",{className:ye("rounded-[var(--radius-md)] animate-shimmer",t),...s})}const Qr={sm:"w-[min(92vw,560px)]",md:"w-[min(92vw,700px)]","md-lg":"w-[min(92vw,800px)]",lg:"w-[min(92vw,960px)]",xl:"w-[min(92vw,1100px)]",full:"w-[min(96vw,1280px)]"};function gi({title:t,leading:s,subtitle:a,className:r,children:o}){return e.jsxs("div",{className:ye("flex items-center justify-between px-5 py-3 border-b border-[var(--border-default)] bg-[var(--bg-surface)] shrink-0",r),children:[e.jsxs("div",{className:"flex items-center flex-1 min-w-0 mr-3 gap-2",children:[s,t&&e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("h3",{className:"font-bold text-[var(--fg-primary)] text-lg leading-snug break-words",children:t}),a&&e.jsx("span",{className:"text-xs text-[var(--fg-muted)] mt-0.5 block truncate",children:a})]})]}),o&&e.jsx("div",{className:"flex items-center gap-1 shrink-0",children:o})]})}function hi({currentIndex:t,total:s,onPrev:a,onNext:r,hasPrev:o,hasNext:l}){const i=o!==void 0?!o:t<=0,p=l!==void 0?!l:t>=s-1;return e.jsxs(e.Fragment,{children:[e.jsx(We,{variant:"ghost",size:"icon-sm",onClick:a,disabled:i,children:e.jsx(Xs,{size:16})}),e.jsxs("span",{className:"text-xs text-[var(--fg-muted)] tabular-nums",children:[t+1,"/",s]}),e.jsx(We,{variant:"ghost",size:"icon-sm",onClick:r,disabled:p,children:e.jsx(Ue,{size:16})})]})}function bi({isWide:t,onToggle:s,title:a}){return e.jsx(We,{variant:"ghost",size:"icon-sm",onClick:s,title:a,children:t?e.jsx(ol,{size:16}):e.jsx(ea,{size:16})})}function fi({children:t}){return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"w-px h-5 bg-[var(--border-default)] mx-1"}),t]})}function vi({onClose:t}){return e.jsx(We,{variant:"ghost",size:"icon-sm",onClick:t,children:e.jsx(ze,{size:16})})}function yi({className:t,padded:s=!1,children:a}){return e.jsx("div",{className:ye("flex-1 overflow-y-auto",s&&"p-5 space-y-5",t),children:a})}function ji({className:t,children:s}){return e.jsx("div",{className:ye("shrink-0 border-t border-[var(--border-default)] px-5 py-3 bg-[var(--bg-surface)] flex items-center justify-between",t),children:s})}function wi({width:t,size:s="md",animationDuration:a="0.25s",className:r,children:o}){return e.jsx("div",{className:ye("relative h-full bg-[var(--bg-surface)] dark:bg-[var(--bg-surface)]/95 dark:backdrop-blur-xl shadow-2xl flex flex-col border-l border-[var(--border-default)] dark:border-[var(--glass-border)]",t||Qr[s],r),style:{animation:`slideInRight ${a} ease-out`},onClick:l=>l.stopPropagation(),children:o})}function Ie({open:t,onClose:s,size:a="md",className:r,animationDuration:o="0.25s",children:l}){return t?e.jsxs($e,{className:"z-30 flex justify-end",onClick:s,children:[e.jsx($e.Backdrop,{className:"bg-black/20 dark:bg-black/40 backdrop-blur-sm"}),e.jsx("div",{className:ye("relative h-full bg-[var(--bg-surface)] dark:bg-[var(--bg-surface)]/95 dark:backdrop-blur-xl shadow-2xl flex flex-col border-l border-[var(--border-default)] dark:border-[var(--glass-border)] dark:shadow-[0_0_80px_rgba(0,0,0,0.5)]",Qr[a],r),style:{animation:`slideInRight ${o} ease-out`},onClick:i=>i.stopPropagation(),children:l})]}):null}Ie.Header=gi;Ie.Nav=hi;Ie.WidthToggle=bi;Ie.HeaderActions=fi;Ie.CloseButton=vi;Ie.Body=yi;Ie.Footer=ji;Ie.Panel=wi;const Ls={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:St},fact:{label:"Fact",color:"text-cyan-700",bg:"bg-cyan-50",border:"border-cyan-200",icon:qe}},rs={"code-pattern":"recipes.knowledgeTypes.codePattern",architecture:"recipes.knowledgeTypes.architecture","best-practice":"recipes.knowledgeTypes.bestPractice","code-standard":"recipes.knowledgeTypes.codeStandard","call-chain":"recipes.knowledgeTypes.callChain",rule:"recipes.knowledgeTypes.rule"};function He(t){return(t.name||t.title||"Untitled").replace(/\.md$/i,"")}function Ni(t){return t.content?.pattern||""}function ki(t){const s=(t.language||"").toLowerCase();return["objectivec","objc","objective-c","obj-c"].includes(s)?"objectivec":t.language||"text"}function Zr(t){if(t==null)return!1;const s=typeof t=="string"?new Date(t).getTime():t;return!isNaN(s)&&s>9466848e5}function Ia(t){return Zr(t)?(typeof t=="string"?new Date(t):new Date(t)).toLocaleDateString("zh-CN",{year:"numeric",month:"2-digit",day:"2-digit"}):""}const Ci=({recipes:t,handleDeleteRecipe:s,onRefresh:a,idTitleMap:r,currentPage:o,onPageChange:l,pageSize:i,onPageSizeChange:p})=>{const{t:d}=Ae(),[g,x]=n.useState("newest"),[h,u]=n.useState("desc"),m=[{key:"newest",label:d("recipes.sortNewest"),defaultDir:"desc"},{key:"quality",label:d("recipes.sortQuality"),defaultDir:"desc"},{key:"usage",label:d("recipes.sortUsage"),defaultDir:"desc"},{key:"alpha",label:d("recipes.sortAlpha"),defaultDir:"asc"},{key:"category",label:d("recipes.sortCategory"),defaultDir:"asc"}],[c,j]=n.useState(1),[A,D]=n.useState(12),I=o??c,P=i??A,J=l??j,w=p?C=>p(C):C=>{D(C),j(1)},{isWide:B,toggle:z}=ia(),[k,E]=n.useState(null),[L,O]=n.useState("view"),[W,q]=n.useState({title:"",description:"",markdown:"",codePattern:"",rationale:"",tags:[],tagInput:""}),[N,v]=n.useState(!1),U=n.useRef(!0),[ae,be]=n.useState(!1),[me,je]=n.useState("related"),[G,le]=n.useState("");n.useEffect(()=>()=>{U.current=!1},[]);const de=[{key:"related",label:d("knowledgeGraph.relationAssociates"),icon:"∼"},{key:"dependsOn",label:d("knowledgeGraph.relationDependsOn"),icon:"⊕"},{key:"inherits",label:d("knowledgeGraph.relationInherits"),icon:"↑"},{key:"implements",label:d("knowledgeGraph.relationImplements"),icon:"◇"},{key:"calls",label:d("knowledgeGraph.relationCalls"),icon:"→"},{key:"dataFlow",label:d("knowledgeGraph.relationDataFlow"),icon:"⇢"},{key:"conflicts",label:d("knowledgeGraph.relationConflicts"),icon:"✕"},{key:"extends",label:d("knowledgeGraph.relationExtends"),icon:"⊃"}],R=C=>{E(C),O("view"),q({title:C.name?.replace(/\.md$/,"")||"",description:C.description||"",markdown:C.content?.markdown||"",codePattern:C.content?.pattern||"",rationale:C.content?.rationale||"",tags:C.tags||[],tagInput:""}),be(!1),le("")},T=()=>{E(null),O("view"),be(!1),le("")},X=async()=>{if(!(!k||N)){v(!0);try{const C=k.id||k.name;await Q.knowledgeUpdate(C,{title:W.title,description:W.description,tags:W.tags,content:{...k.content||{},pattern:W.codePattern,markdown:W.markdown,rationale:W.rationale}}),U.current&&(O("view"),a?.())}catch(C){re(ke(C,d("common.saveFailed")),{title:d("common.operationFailed"),type:"error"})}finally{U.current&&v(!1)}}},oe=async C=>{if(k)try{await Q.setRecipeAuthority(k.id||k.name,C),a?.()}catch(b){re(ke(b,d("common.operationFailed")),{title:d("common.operationFailed"),type:"error"})}},pe=C=>{const b=C.replace(/\.md$/i,"").toLowerCase();return t.find(_=>He(_).toLowerCase()===b)},ue=n.useMemo(()=>{const C=new Map;if(r)for(const[b,_]of Object.entries(r))C.set(b,_);for(const b of t)b.id&&C.set(b.id,He(b)),b.name&&C.set(b.name,He(b));return C},[t,r]),[M,Ce]=n.useState(!1),F=async(C,b)=>{if(!k||M)return;const _={};if(k.relations)for(const[te,ge]of Object.entries(k.relations))_[te]=[...ge];const ne=_[C]||[],$=b.replace(/\.md$/i,"");if(ne.some(te=>(typeof te=="string"?te:te.target||te.id||te.title||"").replace(/\.md$/i,"").toLowerCase()===$.toLowerCase()))return;_[C]=[...ne,$];const y=k;E({...k,relations:_}),be(!1),le(""),Ce(!0);try{await Q.updateRecipeRelations(k.id||k.name,_)}catch(te){E(y),re(ke(te,d("common.operationFailed")),{title:d("common.operationFailed"),type:"error"})}finally{Ce(!1)}},Se=async(C,b)=>{if(!k||M)return;const _={};if(k.relations)for(const[y,te]of Object.entries(k.relations))_[y]=[...te];const ne=_[C]||[];_[C]=ne.filter(y=>(typeof y=="string"?y:y.target||y.id||y.title||"").replace(/\.md$/i,"").toLowerCase()!==b.replace(/\.md$/i,"").toLowerCase()),_[C].length===0&&delete _[C];const $=k;E({...k,relations:_}),Ce(!0);try{await Q.updateRecipeRelations(k.id||k.name,_)}catch(y){E($),re(ke(y,d("common.operationFailed")),{title:d("common.operationFailed"),type:"error"})}finally{Ce(!1)}};n.useEffect(()=>{k&&!t.find(C=>He(C)===He(k))&&T()},[t,k]),n.useEffect(()=>{o==null&&j(1)},[t.length,o]);const Te=it.useMemo(()=>{if(g==="newest")return t;const C=[...t],b=h==="asc"?1:-1;return C.sort((_,ne)=>{let $=0,y=0;switch(g){case"alpha":return $=He(_).toLowerCase(),y=He(ne).toLowerCase(),b*($<y?-1:$>y?1:0);case"quality":$=_.quality?.overall??-1,y=ne.quality?.overall??-1;break;case"usage":$=(_.stats?.guardUsageCount??0)+(_.stats?.humanUsageCount??0)+(_.stats?.aiUsageCount??0),y=(ne.stats?.guardUsageCount??0)+(ne.stats?.humanUsageCount??0)+(ne.stats?.aiUsageCount??0);break;case"category":return $=(_.category||"").toLowerCase(),y=(ne.category||"").toLowerCase(),b*($<y?-1:$>y?1:0)}return b*($-y)}),C},[t,g,h]),Fe=Math.ceil(Te.length/P),Me=(I-1)*P,ee=Te.slice(Me,Me+P),ce=C=>{J(C),window.scrollTo({top:0,behavior:"smooth"})},f=k?Te.findIndex(C=>He(C)===He(k)):-1,V=()=>{f>0&&R(Te[f-1])},xe=()=>{f<Te.length-1&&R(Te[f+1])},fe=({recipe:C})=>{const b=C.kind?Ls[C.kind]:null,_=C.category||"Utility",ne=C.knowledgeType,$=[];return b&&$.push(b.label),$.push(_),ne&&rs[ne]&&$.push(d(rs[ne])),C.language&&$.push(C.language.toUpperCase()),C.trigger&&$.push(C.trigger),e.jsx("span",{className:"text-[11px] text-[var(--fg-muted)] truncate",children:$.join(" · ")})};return e.jsxs("div",{className:"relative pb-6",children:[t.length===0?e.jsxs("div",{className:"flex flex-col items-center justify-center py-24 text-center",children:[e.jsx(hr,{size:48,className:"text-[var(--fg-muted)] mb-4 opacity-40"}),e.jsx("p",{className:"font-medium text-[var(--fg-secondary)] mb-1",children:d("recipes.noResults")}),e.jsx("p",{className:"text-sm text-[var(--fg-muted)]",children:d("recipes.noContent")})]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center gap-1.5 mb-4 border-b border-[var(--border-default)] pb-3",children:[m.map(C=>{const b=g===C.key;return e.jsxs("button",{onClick:()=>{b?u(_=>_==="asc"?"desc":"asc"):(x(C.key),u(C.defaultDir)),J(1)},className:ye("px-4 py-1.5 rounded-md text-xs font-medium transition-colors flex items-center gap-1",b?"bg-[var(--accent-subtle)] text-[var(--accent)] border border-[var(--accent-emphasis)]":"text-[var(--fg-muted)] hover:bg-[var(--bg-subtle)] border border-transparent"),children:[C.label,b&&g!=="newest"&&(h==="asc"?e.jsx(il,{size:12}):e.jsx(cl,{size:12}))]},C.key)}),e.jsx("span",{className:"ml-auto text-xs text-[var(--fg-muted)]",children:d("recipes.totalCount",{count:t.length})})]}),e.jsx("div",{children:ee.map(C=>{const b=He(C),_=C.description||C.usageGuide||"",ne=k&&He(k)===b,$=C.kind?Ls[C.kind]:null;return e.jsx("div",{onClick:()=>R(C),className:ye("group relative cursor-pointer py-4 px-4 rounded-lg transition-colors hover:bg-[var(--bg-subtle)] after:absolute after:bottom-0 after:left-4 after:right-4 after:h-px after:bg-[var(--border-default)] last:after:hidden",ne&&"bg-[var(--accent-subtle)]"),children:e.jsxs("div",{className:"flex items-start justify-between gap-4",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("h3",{className:"font-semibold text-[var(--fg-primary)] text-sm break-words leading-snug truncate",children:b}),$&&e.jsx(Vs,{variant:$.label==="Rule"?"red":$.label==="Pattern"?"blue":"default",className:"text-[9px] uppercase shrink-0",children:$.label}),C.stats?.authority!=null&&C.stats.authority>=4&&e.jsxs("span",{className:"text-amber-500 text-[11px] shrink-0",children:["★ ",C.stats.authority]})]}),_&&e.jsx("p",{className:"text-xs text-[var(--fg-secondary)] line-clamp-1 leading-relaxed mb-1.5",children:_.replace(/^#+\s*/gm,"").replace(/\*\*/g,"")}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(fe,{recipe:C,compact:!0}),C.tags&&C.tags.length>0&&e.jsxs("span",{className:"text-[11px] text-[var(--fg-muted)]",children:[C.tags.slice(0,3).join(", "),C.tags.length>3&&` +${C.tags.length-3}`]})]})]}),e.jsx("div",{className:"opacity-0 group-hover:opacity-100 transition-opacity shrink-0",children:e.jsxs($r,{children:[e.jsx(Or,{asChild:!0,children:e.jsx(We,{variant:"ghost",size:"icon-sm",onClick:y=>y.stopPropagation(),children:e.jsx(dl,{size:14})})}),e.jsxs(oa,{align:"end",children:[e.jsxs(kt,{onClick:y=>{y.stopPropagation(),R(C)},children:[e.jsx(Ut,{size:14,className:"mr-2"})," ",d("common.preview")]}),e.jsxs(kt,{onClick:y=>{y.stopPropagation(),R(C),O("edit")},children:[e.jsx(It,{size:14,className:"mr-2"})," ",d("common.edit")]}),e.jsx(vs,{}),e.jsxs(kt,{className:"text-[var(--status-error)]",onClick:y=>{y.stopPropagation(),s(C.name||C.id||"")},children:[e.jsx(Ke,{size:14,className:"mr-2"})," ",d("recipes.deleteRecipe")]})]})]})})]})},C.id||b)})})]}),t.length>0&&e.jsx(ca,{currentPage:I,totalPages:Fe,totalItems:Te.length,pageSize:P,onPageChange:ce,onPageSizeChange:w}),k&&(()=>{const C=k,b=He(C),_=Ni(C),ne=ki(C),$=C.content;return e.jsxs(Ie,{open:!!k,onClose:T,size:B?"lg":"md",children:[e.jsxs(Ie.Header,{title:b,leading:e.jsx("button",{onClick:()=>{s(C.name||C.id||""),T()},title:d("recipes.deleteRecipe"),className:"p-1.5 text-[var(--fg-muted)] hover:text-red-500 rounded-md transition-colors opacity-30 hover:opacity-100 shrink-0",children:e.jsx(Ke,{size:14})}),children:[e.jsx(Ie.Nav,{currentIndex:f,total:Te.length,onPrev:V,onNext:xe}),e.jsxs(Ie.HeaderActions,{children:[e.jsxs("div",{className:"flex bg-[var(--bg-subtle)] p-0.5 rounded-lg mr-1",children:[e.jsxs("button",{onClick:()=>O("view"),className:ye("px-2.5 py-1 rounded-md text-xs font-bold transition-all flex items-center gap-1",L==="view"?"bg-[var(--bg-surface)] shadow-sm text-[var(--accent)]":"text-[var(--fg-muted)] hover:text-[var(--fg-secondary)]"),children:[e.jsx(Ut,{size:H.sm})," ",d("common.preview")]}),e.jsxs("button",{onClick:()=>{O("edit")},className:ye("px-2.5 py-1 rounded-md text-xs font-bold transition-all flex items-center gap-1",L==="edit"?"bg-[var(--bg-surface)] shadow-sm text-[var(--accent)]":"text-[var(--fg-muted)] hover:text-[var(--fg-secondary)]"),children:[e.jsx(It,{size:H.sm})," ",d("common.edit")]})]}),e.jsx(Ie.WidthToggle,{isWide:B,onToggle:z}),e.jsx(Ie.CloseButton,{onClose:T})]})]}),L==="edit"?e.jsxs(e.Fragment,{children:[e.jsxs(Ie.Body,{padded:!0,children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-[10px] font-bold text-[var(--fg-muted)] uppercase mb-1.5 block",children:d("recipes.recipeDetail")}),e.jsx("input",{type:"text",value:W.title,onChange:y=>q(te=>({...te,title:y.target.value})),className:"w-full px-3 py-2 text-sm border border-[var(--border-default)] rounded-lg bg-[var(--bg-root)] text-[var(--fg-primary)] focus:outline-none focus:ring-2 focus:ring-[var(--accent-emphasis)] focus:border-[var(--accent-emphasis)]"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-[10px] font-bold text-[var(--fg-muted)] uppercase mb-1.5 block",children:d("recipes.description")}),e.jsx("textarea",{value:W.description,onChange:y=>q(te=>({...te,description:y.target.value})),rows:2,className:"w-full px-3 py-2 text-sm border border-[var(--border-default)] rounded-lg bg-[var(--bg-root)] text-[var(--fg-primary)] focus:outline-none focus:ring-2 focus:ring-[var(--accent-emphasis)] resize-none"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-[10px] font-bold text-[var(--fg-muted)] uppercase mb-1.5 block",children:d("recipes.tags")}),e.jsx("div",{className:"flex flex-wrap gap-1.5 mb-2",children:W.tags.map((y,te)=>e.jsxs("span",{className:"inline-flex items-center gap-1 text-[10px] px-2 py-0.5 rounded bg-[var(--accent-subtle)] text-[var(--accent)] border border-[var(--border-default)] font-medium",children:[y,e.jsx("button",{onClick:()=>q(ge=>({...ge,tags:ge.tags.filter((he,De)=>De!==te)})),className:"text-[var(--fg-muted)] hover:text-[var(--status-error)]",children:e.jsx(ze,{size:10})})]},te))}),e.jsx("div",{className:"flex gap-2",children:e.jsx("input",{type:"text",value:W.tagInput,onChange:y=>q(te=>({...te,tagInput:y.target.value})),onKeyDown:y=>{y.key==="Enter"&&W.tagInput.trim()&&(y.preventDefault(),q(te=>({...te,tags:[...te.tags,te.tagInput.trim()],tagInput:""})))},placeholder:d("recipes.tags"),className:"flex-1 px-3 py-1.5 text-xs border border-[var(--border-default)] rounded-lg bg-[var(--bg-root)] text-[var(--fg-primary)] focus:outline-none focus:ring-2 focus:ring-[var(--accent-emphasis)]"})})]}),e.jsxs("div",{children:[e.jsxs("label",{className:"text-[10px] font-bold text-[var(--fg-muted)] uppercase mb-1.5 block flex items-center gap-1.5",children:[e.jsx(Qe,{size:11,className:"text-[var(--accent)]"})," ",d("recipes.markdown")]}),e.jsx("textarea",{value:W.markdown,onChange:y=>q(te=>({...te,markdown:y.target.value})),rows:4,className:"w-full px-3 py-2 text-sm border border-[var(--border-default)] rounded-lg bg-[var(--bg-root)] text-[var(--fg-primary)] focus:outline-none focus:ring-2 focus:ring-[var(--accent-emphasis)] resize-y font-mono",placeholder:d("recipes.markdown")})]}),e.jsxs("div",{children:[e.jsxs("label",{className:"text-[10px] font-bold text-[var(--fg-muted)] uppercase mb-1.5 block flex items-center gap-1.5",children:[e.jsx(At,{size:11,className:"text-[var(--status-success)]"})," ",d("recipes.code")]}),e.jsx("div",{className:"border border-[var(--border-default)] rounded-lg overflow-hidden",style:{minHeight:200},children:e.jsx(ys,{value:W.codePattern,onChange:y=>q(te=>({...te,codePattern:y})),language:ne,height:"200px",showLineNumbers:!0})})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-[10px] font-bold text-[var(--fg-muted)] uppercase mb-1.5 block",children:d("recipes.designRationale")}),e.jsx("textarea",{value:W.rationale,onChange:y=>q(te=>({...te,rationale:y.target.value})),rows:3,className:"w-full px-3 py-2 text-sm border border-[var(--border-default)] rounded-lg bg-[var(--bg-root)] text-[var(--fg-primary)] focus:outline-none focus:ring-2 focus:ring-[var(--accent-emphasis)] resize-y",placeholder:d("recipes.designRationale")})]})]}),e.jsxs(Ie.Footer,{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-xs text-[var(--fg-muted)]",children:d("recipes.qualityAuthorityScore")}),e.jsx(tt,{value:String(C.stats?.authority??3),onChange:y=>oe(parseInt(y)),options:[1,2,3,4,5].map(y=>({value:String(y),label:`${"⭐".repeat(y)} ${y}`})),size:"xs",className:"font-bold text-amber-600 bg-amber-50 border-amber-100"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(We,{variant:"ghost",onClick:()=>O("view"),disabled:N,children:d("common.cancel")}),e.jsxs(We,{variant:"primary",onClick:X,disabled:N,loading:N,children:[!N&&e.jsx(ws,{size:H.sm}),d(N?"common.saving":"common.save")]})]})]})]}):e.jsxs(Ie.Body,{children:[e.jsx(da,{badges:(()=>{const y=C.kind?Ls[C.kind]:null,te=C.category||"Utility",ge=et[te]||et.All,he=[];return y&&he.push({label:y.label,className:`${y.bg} ${y.color} ${y.border}`,icon:y.icon}),he.push({label:te,className:`font-bold uppercase ${ge?.bg||"bg-[var(--bg-subtle)]"} ${ge?.color||"text-[var(--fg-muted)]"} ${ge?.border||"border-[var(--border-default)]"}`}),C.knowledgeType&&he.push({label:rs[C.knowledgeType]?d(rs[C.knowledgeType]):C.knowledgeType,className:"bg-purple-50 text-purple-700 border-purple-200"}),C.language&&he.push({label:C.language,className:"uppercase font-bold text-[var(--fg-secondary)] bg-[var(--bg-subtle)] border-[var(--border-default)]"}),C.trigger&&he.push({label:C.trigger,className:"font-mono font-bold bg-amber-50 text-amber-700 border-amber-200"}),C.source&&C.source!=="unknown"&&he.push({label:C.source,className:"bg-[var(--bg-subtle)] text-[var(--fg-secondary)] border-[var(--border-default)]"}),he})(),metadata:(()=>{const y=[];return C.scope&&y.push({icon:Ct,iconClass:"text-teal-400",label:d("candidates.path"),value:C.scope==="universal"?d("common.all"):C.scope==="project-specific"?d("candidates.category"):C.scope}),C.complexity&&y.push({icon:Ge,iconClass:"text-orange-400",label:d("knowledge.complexity"),value:C.complexity==="advanced"?d("knowledge.complexityAdvanced"):C.complexity==="intermediate"?d("knowledge.complexityIntermediate"):C.complexity==="beginner"?d("knowledge.complexityBeginner"):C.complexity}),C.source&&C.source!=="unknown"&&y.push({icon:Ct,iconClass:"text-violet-400",label:d("recipes.sourceLabel"),value:C.source==="bootstrap-scan"?d("recipes.sourceBootstrap"):C.source==="agent"?d("recipes.sourceAiScan"):C.source}),C.updatedAt&&Zr(C.updatedAt)&&y.push({icon:Ye,iconClass:"text-[var(--fg-muted)]",label:d("candidates.updatedAt"),value:Ia(C.updatedAt)}),y})(),tags:C.tags,id:C.id,sourceFile:C.sourceFile,sourceFileLabel:d("candidates.path")}),e.jsxs("div",{className:"px-6 py-4 border-b border-[var(--border-default)]",children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(ta,{size:12,className:ye("text-purple-400",M&&"animate-spin")}),e.jsx("label",{className:"text-[10px] font-bold text-[var(--fg-muted)] uppercase",children:d("recipes.relations")}),(()=>{const y=C.relations?Object.values(C.relations).flat().length:0;return y>0?e.jsx(Vs,{variant:"blue",className:"text-[9px]",children:y}):null})()]}),e.jsx(We,{variant:ae?"secondary":"primary",size:"sm",onClick:()=>{be(!ae),le("")},children:ae?e.jsxs(e.Fragment,{children:[e.jsx(ze,{size:10})," ",d("common.cancel")]}):e.jsxs(e.Fragment,{children:[e.jsx(mt,{size:10})," ",d("recipes.editBtn")]})})]}),ae&&e.jsxs("div",{className:"mb-3 bg-[var(--bg-subtle)] border border-[var(--border-default)] rounded-lg p-3 space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(tt,{value:me,onChange:y=>je(y),options:de.map(y=>({value:y.key,label:`${y.icon} ${y.label}`})),size:"xs",className:"font-bold"}),e.jsxs("div",{className:"flex-1 relative",children:[e.jsx(xt,{size:12,className:"absolute left-2 top-1/2 -translate-y-1/2 text-[var(--fg-muted)]"}),e.jsx("input",{type:"text",placeholder:d("recipes.searchPlaceholder"),value:G,onChange:y=>le(y.target.value),className:"w-full text-xs bg-[var(--bg-root)] border border-[var(--border-default)] rounded pl-7 pr-2 py-1 outline-none text-[var(--fg-primary)]",autoFocus:!0})]})]}),G.length>0&&e.jsx("div",{className:"max-h-36 overflow-y-auto rounded border border-[var(--border-default)] bg-[var(--bg-root)] divide-y divide-[var(--border-default)]",children:(()=>{const y=t.filter(te=>He(te)===b?!1:He(te).toLowerCase().includes(G.toLowerCase())).slice(0,10);return y.length?y.map(te=>{const ge=He(te),he=C.relations&&Object.values(C.relations).flat().some(De=>(typeof De=="string"?De:De.target||De.id||De.title||"").replace(/\.md$/i,"").toLowerCase()===ge.toLowerCase());return e.jsxs("div",{className:ye("flex items-center justify-between px-3 py-1.5 text-xs",he||M?"bg-[var(--bg-subtle)] text-[var(--fg-muted)]":"hover:bg-[var(--bg-subtle)] cursor-pointer"),onClick:()=>!he&&!M&&F(me,ge),children:[e.jsx("span",{className:"font-medium truncate mr-2",children:ge}),he?e.jsx("span",{className:"text-[9px] text-[var(--fg-muted)] font-bold shrink-0",children:d("recipes.relations")}):e.jsxs("span",{className:"text-[9px] text-[var(--accent)] font-bold shrink-0",children:["+ ",d("recipes.editBtn")]})]},ge)}):e.jsx("div",{className:"text-xs text-[var(--fg-muted)] py-3 text-center",children:d("recipes.noResults")})})()})]}),C.relations&&Object.entries(C.relations).some(([,y])=>Array.isArray(y)&&y.length>0)?e.jsx("div",{className:"space-y-1.5",children:de.map(({key:y,label:te,icon:ge})=>{const he=C.relations?.[y];return!he||!Array.isArray(he)||he.length===0?null:e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsxs("span",{className:"text-[10px] font-mono text-[var(--fg-muted)] shrink-0 whitespace-nowrap pt-0.5",children:[ge," ",te]}),e.jsx("div",{className:"flex flex-wrap gap-1",children:he.map((De,se)=>{const we=typeof De=="string"?De:De.target||De.id||De.title||JSON.stringify(De),Oe=pe(we)||(ue.has(we)?pe(ue.get(we)):void 0),rt=Oe?He(Oe):ue.get(we)||we;return e.jsxs("span",{className:ye("group/rel inline-flex items-center gap-1 px-1.5 py-0.5 border rounded text-[10px] font-mono transition-colors",Oe?"bg-[var(--accent-subtle)] border-[var(--accent-emphasis)] text-[var(--accent)] cursor-pointer hover:brightness-95":"bg-[var(--bg-root)] border-[var(--border-default)] text-[var(--fg-secondary)]"),onClick:()=>Oe&&R(Oe),title:Oe?d("candidates.viewDetail"):rt,children:[rt.replace(/\.md$/i,""),e.jsx("button",{onClick:ct=>{ct.stopPropagation(),!M&&window.confirm(`${d("common.delete")}: ${rt.replace(/\.md$/i,"")}?`)&&Se(y,we)},disabled:M,className:"opacity-0 group-hover/rel:opacity-100 text-[var(--danger)] hover:text-[var(--danger)] transition-opacity ml-1 p-0.5 rounded hover:bg-[var(--danger-subtle)]",title:d("common.delete"),children:e.jsx(ze,{size:10})})]},se)})})]},y)})}):!ae&&e.jsx("div",{className:"text-xs text-[var(--fg-muted)] py-2 text-center",children:d("recipes.noContent")})]}),e.jsxs("div",{className:"px-6 py-3 border-b border-[var(--border-default)]",children:[e.jsxs("div",{className:"grid grid-cols-2 sm:grid-cols-4 gap-3",children:[e.jsxs("div",{className:"bg-[var(--bg-subtle)] rounded-xl p-3 text-center border border-[var(--border-default)]",children:[e.jsx("div",{className:"text-lg font-bold text-amber-600",children:C.stats?.authority??"—"}),e.jsx("div",{className:"text-[10px] text-[var(--fg-muted)] font-medium",children:d("recipes.qualityAuthorityScore")})]}),e.jsxs("div",{className:"bg-[var(--bg-subtle)] rounded-xl p-3 text-center border border-[var(--border-default)]",children:[e.jsx("div",{className:"text-lg font-bold text-[var(--accent)]",children:C.stats?.authorityScore!=null?C.stats.authorityScore.toFixed(1):"—"}),e.jsx("div",{className:"text-[10px] text-[var(--fg-muted)] font-medium",children:d("recipes.qualityGreat")})]}),e.jsxs("div",{className:"bg-[var(--bg-subtle)] rounded-xl p-3 text-center border border-[var(--border-default)]",children:[e.jsx("div",{className:"text-lg font-bold text-[var(--fg-primary)]",children:C.stats?C.stats.guardUsageCount+C.stats.humanUsageCount+C.stats.aiUsageCount:0}),e.jsx("div",{className:"text-[10px] text-[var(--fg-muted)] font-medium",children:d("recipes.qualitySolid")})]}),e.jsxs("div",{className:"bg-[var(--bg-subtle)] rounded-xl p-3 text-center border border-[var(--border-default)]",children:[e.jsx("div",{className:"text-sm font-bold text-[var(--fg-secondary)]",children:Ia(C.stats?.lastUsedAt)||d("recipes.noContent")}),e.jsx("div",{className:"text-[10px] text-[var(--fg-muted)] font-medium",children:d("recipes.qualityGood")})]})]}),C.stats!=null&&(C.stats.guardUsageCount>0||C.stats.humanUsageCount>0||C.stats.aiUsageCount>0)&&e.jsxs("div",{className:"flex items-center gap-4 mt-2 text-[10px] text-[var(--fg-muted)]",children:[e.jsxs("span",{children:["Guard: ",C.stats.guardUsageCount]}),e.jsxs("span",{children:["Human: ",C.stats.humanUsageCount]}),e.jsxs("span",{children:["AI: ",C.stats.aiUsageCount]})]})]}),e.jsx(Ee.Reasoning,{reasoning:C.reasoning,labels:{section:d("recipes.reasoning"),source:d("recipes.sourceColon"),confidence:d("recipes.confidenceColon"),alternatives:d("recipes.alternativesLabel")}}),e.jsx(Ee.Quality,{quality:C.quality,labels:{section:d("recipes.qualityGrade"),completeness:d("recipes.qualityCompleteness"),adaptation:d("recipes.qualityAdaptation"),documentation:d("recipes.qualityDocumentation")}}),e.jsx(Ee.Description,{label:d("recipes.description"),text:C.description}),e.jsx(Ee.MarkdownSection,{label:d("recipes.markdown"),content:$?.markdown}),e.jsx(Ee.Headers,{label:d("recipes.headers"),headers:C.headers}),e.jsx(Ee.CodePattern,{label:d("recipes.code"),code:_,language:ne}),e.jsx(Ee.Rationale,{label:d("recipes.designRationale"),text:$?.rationale}),e.jsx(Ee.Steps,{label:d("recipes.steps"),steps:$?.steps}),$?.codeChanges&&$.codeChanges.length>0&&e.jsxs("div",{className:"px-6 py-4 border-b border-[var(--border-default)]",children:[e.jsx("label",{className:"text-[10px] font-bold text-[var(--fg-muted)] uppercase mb-2 block",children:d("recipes.codeChanges")}),e.jsx("div",{className:"space-y-2",children:$.codeChanges.map((y,te)=>e.jsxs("div",{className:"border border-[var(--border-default)] rounded-lg overflow-hidden",children:[e.jsxs("div",{className:"px-3 py-1.5 bg-[var(--bg-subtle)] border-b border-[var(--border-default)] flex items-center gap-2",children:[e.jsx(pt,{size:11,className:"text-[var(--accent)]"}),e.jsx("code",{className:"text-[10px] font-mono text-[var(--fg-secondary)]",children:y.file})]}),y.explanation&&e.jsx("p",{className:"text-[11px] text-[var(--fg-muted)] px-3 py-1.5 border-b border-[var(--border-default)] bg-[var(--bg-subtle)]",children:y.explanation}),e.jsxs("div",{className:"p-2 bg-red-50/10 border-b border-[var(--border-default)]",children:[e.jsx("div",{className:"text-[9px] font-bold text-[var(--status-error)] mb-0.5 uppercase",children:"Before"}),e.jsx("pre",{className:"text-[11px] text-[var(--fg-secondary)] whitespace-pre-wrap break-words font-mono",children:y.before||d("recipes.emptyValue")})]}),e.jsxs("div",{className:"p-2 bg-emerald-50/10",children:[e.jsx("div",{className:"text-[9px] font-bold text-[var(--status-success)] mb-0.5 uppercase",children:"After"}),e.jsx("pre",{className:"text-[11px] text-[var(--fg-primary)] whitespace-pre-wrap break-words font-mono",children:y.after})]})]},te))})]}),$?.verification&&e.jsxs("div",{className:"px-6 py-4 border-b border-[var(--border-default)]",children:[e.jsx("label",{className:"text-[10px] font-bold text-[var(--fg-muted)] uppercase mb-2 block",children:d("recipes.validation")}),e.jsxs("div",{className:"bg-[var(--bg-subtle)] border border-[var(--border-default)] rounded-xl p-4 space-y-1.5",children:[$.verification.method&&e.jsxs("p",{className:"text-xs text-[var(--fg-secondary)]",children:[e.jsx("span",{className:"font-bold text-[var(--status-success)]",children:d("recipes.verificationMethod")})," ",$.verification.method]}),$.verification.expectedResult&&e.jsxs("p",{className:"text-xs text-[var(--fg-secondary)]",children:[e.jsx("span",{className:"font-bold text-[var(--status-success)]",children:d("recipes.verificationExpected")})," ",$.verification.expectedResult]}),$.verification.testCode&&e.jsx("pre",{className:"text-[11px] font-mono bg-slate-800 text-green-300 p-2.5 rounded-md overflow-x-auto whitespace-pre-wrap mt-1",children:$.verification.testCode})]})]}),e.jsx(Ee.Constraints,{label:d("recipes.constraints"),constraints:C.constraints})]})]})})()]})};function yt(t){return t>=1e6?(t/1e6).toFixed(1)+"M":t>=1e3?(t/1e3).toFixed(1)+"k":String(t)}function Si(t){const s=new Map(t.map(r=>[r.date,r])),a=[];for(let r=6;r>=0;r--){const o=new Date;o.setDate(o.getDate()-r);const l=o.toISOString().slice(0,10);a.push(s.get(l)||{date:l,input_tokens:0,output_tokens:0,total_tokens:0,call_count:0})}return a}const Ai={user:"bg-blue-500",mcp:"bg-purple-500",bootstrap:"bg-amber-500",guard:"bg-rose-500",analyst:"bg-indigo-500",producer:"bg-green-500"},Di=()=>{const{t}=Ae(),[s,a]=n.useState([]),[r,o]=n.useState([]),[l,i]=n.useState({input_tokens:0,output_tokens:0,total_tokens:0,call_count:0,avg_per_call:0}),[p,d]=n.useState(!0),[g,x]=n.useState(null);n.useEffect(()=>{let c=!1;return(async()=>{try{const j=await Q.getTokenUsage7Days();if(c)return;a(j.daily||[]),o(j.bySource||[]),i(j.summary||{input_tokens:0,output_tokens:0,total_tokens:0,call_count:0,avg_per_call:0})}catch(j){c||x(ke(j,t("tokenUsageChart.loadFailed")))}finally{c||d(!1)}})(),()=>{c=!0}},[]);const h=n.useMemo(()=>Si(s),[s]),u=n.useMemo(()=>Math.max(...h.map(c=>c.total_tokens),1),[h]);if(p)return e.jsxs("div",{className:"flex items-center justify-center py-10",children:[e.jsx("div",{className:"animate-spin rounded-full h-6 w-6 border-2 border-blue-500 border-t-transparent"}),e.jsx("span",{className:"ml-2 text-slate-500 text-sm",children:t("tokenUsageChart.loading")})]});if(g)return e.jsx("p",{className:"text-red-500 text-sm py-4 text-center",children:g});const m=l.total_tokens===0;return e.jsxs("div",{className:"space-y-5",children:[e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-3",children:[e.jsx(ns,{label:t("tokenUsageChart.totalToken"),value:yt(l.total_tokens),sub:t("tokenUsageChart.totalSub"),color:"blue"}),e.jsx(ns,{label:t("tokenUsageChart.input"),value:yt(l.input_tokens),sub:"Prompt",color:"green"}),e.jsx(ns,{label:t("tokenUsageChart.output"),value:yt(l.output_tokens),sub:"Completion",color:"purple"}),e.jsx(ns,{label:t("tokenUsageChart.calls"),value:String(l.call_count),sub:t("tokenUsageChart.avgPerCall",{avg:yt(l.avg_per_call)}),color:"amber"})]}),m?e.jsx("div",{className:"text-center py-8 text-slate-400 text-sm",children:t("tokenUsageChart.emptyState")}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{children:[e.jsx("h4",{className:"text-sm font-semibold text-slate-700 mb-3",children:t("tokenUsageChart.dailyUsage")}),e.jsx("div",{className:"flex items-end gap-1.5 h-40",children:h.map(c=>{const j=c.input_tokens/u*100,A=c.output_tokens/u*100,D=t(`tokenUsageChart.weekday${new Date(c.date+"T00:00:00").getDay()}`);return e.jsxs("div",{className:"flex-1 flex flex-col items-center gap-1 group relative",children:[e.jsxs("div",{className:"absolute -top-16 left-1/2 -translate-x-1/2 bg-slate-800 text-white text-xs rounded px-2 py-1 opacity-0 group-hover:opacity-100 transition-opacity whitespace-nowrap pointer-events-none z-10",children:[e.jsx("p",{children:c.date}),e.jsx("p",{children:t("tokenUsageChart.dailyDetail",{input:yt(c.input_tokens),output:yt(c.output_tokens)})}),e.jsx("p",{children:t("tokenUsageChart.dailyCalls",{count:String(c.call_count)})})]}),e.jsxs("div",{className:"w-full flex flex-col justify-end",style:{height:"120px"},children:[e.jsx("div",{className:"bg-green-400 rounded-t-sm w-full transition-all",style:{height:`${j}%`,minHeight:c.input_tokens>0?"2px":"0"}}),e.jsx("div",{className:"bg-purple-400 rounded-b-sm w-full transition-all",style:{height:`${A}%`,minHeight:c.output_tokens>0?"2px":"0"}})]}),e.jsx("span",{className:"text-[10px] text-slate-400",children:D})]},c.date)})}),e.jsxs("div",{className:"flex gap-4 mt-2 text-xs text-slate-500 justify-center",children:[e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx("span",{className:"w-2.5 h-2.5 rounded-sm bg-green-400 inline-block"})," ",t("tokenUsageChart.legendInput")]}),e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx("span",{className:"w-2.5 h-2.5 rounded-sm bg-purple-400 inline-block"})," ",t("tokenUsageChart.legendOutput")]})]})]}),r.length>0&&e.jsxs("div",{children:[e.jsx("h4",{className:"text-sm font-semibold text-slate-700 mb-3",children:t("tokenUsageChart.sourceDistribution")}),e.jsx("div",{className:"space-y-2",children:r.map(c=>{const j=l.total_tokens>0?c.total_tokens/l.total_tokens*100:0,A=Ai[c.source]||"bg-slate-400";return e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("span",{className:"w-20 text-xs text-slate-600 text-right truncate",children:c.source}),e.jsx("div",{className:"flex-1 bg-slate-100 rounded-full h-3 overflow-hidden",children:e.jsx("div",{className:`${A} h-full rounded-full transition-all`,style:{width:`${j}%`,minWidth:j>0?"4px":"0"}})}),e.jsx("span",{className:"w-16 text-xs text-slate-500 text-right",children:yt(c.total_tokens)}),e.jsxs("span",{className:"w-12 text-xs text-slate-400 text-right",children:[j.toFixed(0),"%"]})]},c.source)})})]})]})]})};function ns({label:t,value:s,sub:a,color:r}){const o={blue:"bg-blue-50 border-blue-200 text-blue-700",green:"bg-green-50 border-green-200 text-green-700",purple:"bg-purple-50 border-purple-200 text-purple-700",amber:"bg-amber-50 border-amber-200 text-amber-700"},l=o[r]||o.blue;return e.jsxs("div",{className:`rounded-lg border p-3 ${l}`,children:[e.jsx("p",{className:"text-xs opacity-70",children:t}),e.jsx("p",{className:"text-xl font-bold",children:s}),e.jsx("p",{className:"text-[10px] opacity-60",children:a})]})}const gt=({id:t,title:s,icon:a,isExpanded:r,onToggle:o,children:l})=>e.jsxs("section",{className:"border border-[var(--border-default)] rounded-lg overflow-hidden",children:[e.jsxs("button",{onClick:()=>o(t),className:"w-full flex items-center justify-between p-4 bg-[var(--bg-subtle)] hover:bg-[var(--bg-muted)] active:bg-[var(--bg-muted)] outline-none focus:outline-none focus-visible:outline-none transition-colors",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[a,e.jsx("h2",{className:"text-lg font-bold text-[var(--fg-primary)]",children:s})]}),r?e.jsx(vt,{size:H.lg}):e.jsx(Ue,{size:H.lg})]}),r&&e.jsx("div",{className:"p-4 bg-[var(--bg-surface)]",children:l})]}),Ri=()=>{const{t}=Ae(),[s,a]=n.useState(new Set(["quick-start"])),r=o=>{const l=new Set(s);l.has(o)?l.delete(o):l.add(o),a(l)};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.jsx("h1",{className:"text-4xl font-bold text-[var(--fg-primary)] mb-4",children:t("help.pageTitle")}),e.jsx("p",{className:"text-[var(--fg-secondary)] text-lg max-w-3xl mx-auto text-center",children:t("help.subtitle")}),e.jsx("p",{className:"text-[var(--fg-muted)] text-sm mt-2",children:t("help.techSpecs")}),e.jsxs("div",{className:"mt-6 flex gap-3 justify-center text-sm",children:[e.jsxs("a",{href:"https://github.com/GxFn/AutoSnippet",target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center gap-2 px-5 py-2.5 bg-[var(--bg-subtle)] border border-[var(--border-default)] text-[var(--fg-primary)] rounded-full hover:bg-[var(--bg-muted)] transition-colors",children:[e.jsx(ul,{size:H.sm}),t("help.viewGithub")]}),e.jsxs("a",{href:"https://docs.gaoxuefeng.com/part1/ch01-introduction.html",target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center gap-2 px-5 py-2.5 bg-blue-600 text-white rounded-full hover:bg-blue-700 transition-colors",children:[e.jsx(qe,{size:H.sm}),t("help.fullDocs"),e.jsx(wr,{size:12})]})]})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsx(gt,{id:"token-usage",title:t("help.tokenUsageLast7Days"),icon:e.jsx(Tt,{size:H.xl,className:"text-blue-600"}),isExpanded:s.has("token-usage"),onToggle:r,children:e.jsx(Di,{})}),e.jsx(gt,{id:"quick-start",title:t("help.quickStart"),icon:e.jsx(Kt,{size:H.xl,className:"text-blue-600"}),isExpanded:s.has("quick-start"),onToggle:r,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-[var(--fg-primary)] mb-2",children:t("help.step1Title")}),e.jsx("pre",{className:"bg-blue-100/70 text-blue-900 px-3 py-2 rounded text-xs overflow-x-auto whitespace-pre-wrap break-all",children:e.jsxs("code",{children:["npm install -g autosnippet",`
75
+ `).length,[t]);return n.useEffect(()=>{x.current&&D(E=>({...E,height:x.current.clientHeight}))},[]),e.jsxs("div",{ref:g,className:`relative overflow-hidden ${l}`,style:{height:p?"auto":o,minHeight:J.minHeight,display:"flex",borderRadius:"0",backgroundColor:"#282c34"},children:[d&&e.jsx("div",{ref:u,className:"flex-shrink-0 overflow-hidden pointer-events-none select-none",style:{width:"3.5em",backgroundColor:"#282c34",color:"#5c6370",textAlign:"right",paddingTop:"1rem",paddingRight:"0.75em",paddingBottom:"1rem",borderRadius:"0",borderRight:"1px solid #333842"},children:e.jsx(Uo,{totalLines:k,scrollTop:A.top,viewportHeight:A.height,fontSize:J.fontSize,lineHeight:J.lineHeight,fontFamily:J.fontFamily})}),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(qo,{code:m||i,lang:P,editorStyles:J})}),e.jsx("textarea",{ref:x,value:t,onChange:B,onSelect:z,onKeyUp:z,onClick:z,onScroll:w,rows:p,placeholder:i,className:"absolute inset-0 w-full h-full resize-none outline-none editor-with-dark-scrollbar",style:{padding:J.padding,lineHeight:J.lineHeight,fontSize:J.fontSize,fontFamily:J.fontFamily,caretColor:"#61afef",backgroundColor:"transparent",color:"transparent",WebkitTextFillColor:"transparent",zIndex:10,border:"none",margin:0,overflow:"auto",overflowX:"hidden",WebkitAppearance:"none",appearance:"none",boxSizing:"border-box",whiteSpace:"pre"}})]})]})},da=({badges:t,metadata:s,tags:a,maxTags:r,id:o,sourceFile:l,sourceFileLabel:i="源文件"})=>{const p=r&&a?a.slice(0,r):a;return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"px-6 py-4 border-b border-[var(--border-default)] space-y-3",children:[t.length>0&&e.jsx("div",{className:"flex flex-wrap items-center gap-1.5",children:t.map((d,g)=>{const x=d.icon;return e.jsxs("span",{className:`text-[10px] font-medium px-1.5 py-0.5 rounded border inline-flex items-center gap-1 ${d.className}`,children:[x&&e.jsx(x,{size:10}),d.label]},g)})}),(s.length>0||o||l)&&e.jsxs("div",{className:"flex flex-wrap gap-x-5 gap-y-2 text-xs",children:[s.map((d,g)=>{const x=d.icon;return e.jsxs("div",{className:`flex items-center gap-1.5${d.fullWidth?" basis-full mt-0.5":""}`,children:[e.jsx(x,{size:11,className:`${d.iconClass} shrink-0`}),e.jsx("span",{className:"text-[var(--fg-muted)]",children:d.label}),d.isCode?e.jsx("code",{className:"font-mono text-[11px] text-[var(--fg-secondary)] break-all",children:d.value}):e.jsx("span",{className:`font-medium text-[var(--fg-secondary)]${d.mono?" font-mono text-[11px]":""}`,children:d.value})]},g)}),o&&e.jsxs("div",{className:"flex items-center gap-1.5 basis-full mt-0.5",children:[e.jsx(Ys,{size:11,className:"text-[var(--fg-muted)] shrink-0"}),e.jsx("span",{className:"text-[var(--fg-muted)]",children:"ID"}),e.jsx("code",{className:"font-mono text-[11px] text-[var(--fg-secondary)] break-all",children:o})]}),l&&e.jsxs("div",{className:"flex items-center gap-1.5 basis-full",children:[e.jsx(Lt,{size:11,className:"text-[var(--fg-muted)] shrink-0"}),e.jsx("span",{className:"text-[var(--fg-muted)]",children:i}),e.jsx("code",{className:"font-mono text-[11px] text-[var(--fg-secondary)] break-all",title:l,children:l})]})]})]}),p&&p.length>0&&e.jsxs("div",{className:"px-6 py-3 border-b border-[var(--border-default)] flex flex-wrap items-center gap-1.5",children:[e.jsx(jr,{size:11,className:"text-[var(--fg-muted)] mr-0.5"}),p.map((d,g)=>e.jsx("span",{className:"text-[9px] px-2 py-0.5 rounded bg-[var(--accent-subtle)] text-[var(--accent)] border border-[var(--border-default)] font-medium",children:typeof d=="string"?d:String(d)},g))]})]})},Wo=({label:t,text:s})=>s?e.jsxs("div",{className:"px-6 py-4 border-b border-[var(--border-default)]",children:[e.jsx("label",{className:"text-[10px] font-bold text-[var(--fg-muted)] uppercase mb-1.5 block",children:t}),e.jsx("p",{className:"text-sm text-[var(--fg-secondary)] leading-relaxed",children:s})]}):null,Vo=({reasoning:t,labels:s,filterSubmitted:a=!1})=>{if(!t)return null;const r=t,o=r.whyStandard&&(!a||!/^Submitted via /i.test(r.whyStandard));return o||r.sources&&r.sources.length>0||r.confidence!=null&&r.confidence>0?e.jsxs("div",{className:"px-6 py-4 border-b border-[var(--border-default)]",children:[e.jsxs("label",{className:"text-[10px] font-bold text-[var(--fg-muted)] uppercase mb-2 block flex items-center gap-1.5",children:[e.jsx(St,{size:11,className:"text-amber-400"})," ",s.section]}),e.jsxs("div",{className:"bg-amber-50/30 border border-amber-100 rounded-xl p-4 space-y-2.5",children:[o&&e.jsx("p",{className:"text-sm text-[var(--fg-primary)] leading-relaxed",children:r.whyStandard}),r.sources&&r.sources.length>0&&e.jsxs("div",{className:"flex flex-wrap items-center gap-1.5",children:[e.jsx("span",{className:"text-[10px] text-[var(--fg-muted)] font-bold",children:s.source}),r.sources.map((i,p)=>e.jsx("code",{className:"text-[10px] px-2 py-0.5 bg-[var(--bg-surface)] border border-amber-200 rounded text-amber-700 font-mono",children:i},p))]}),r.confidence!=null&&r.confidence>0&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-[10px] text-[var(--fg-muted)] font-bold",children:s.confidence}),e.jsx("div",{className:"flex-1 max-w-[160px] h-1.5 bg-[var(--border-default)] rounded-full overflow-hidden",children:e.jsx("div",{className:"h-full bg-amber-400 rounded-full",style:{width:`${Math.round((r.confidence??0)*100)}%`}})}),e.jsxs("span",{className:"text-[10px] font-bold text-amber-600",children:[Math.round((r.confidence??0)*100),"%"]})]}),r.alternatives&&r.alternatives.length>0&&e.jsxs("div",{className:"flex flex-wrap items-center gap-1.5 pt-1",children:[e.jsx("span",{className:"text-[10px] text-[var(--fg-muted)] font-bold",children:s.alternatives}),r.alternatives.map((i,p)=>e.jsx("span",{className:"text-[10px] px-1.5 py-0.5 bg-[var(--bg-subtle)] border border-[var(--border-default)] rounded text-[var(--fg-secondary)]",children:i},p))]})]})]}):null},Jo=({quality:t,labels:s})=>{if(!t?.grade||t.grade==="F")return null;const a=r=>r.toFixed(2);return e.jsxs("div",{className:"px-6 py-3 border-b border-[var(--border-default)]",children:[e.jsx("label",{className:"text-[10px] font-bold text-[var(--fg-muted)] uppercase mb-2 block",children:s.section}),e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx("span",{className:`text-2xl font-black ${t.grade==="A"?"text-emerald-600":t.grade==="B"?"text-blue-600":t.grade==="C"?"text-amber-600":t.grade==="D"?"text-orange-600":"text-[var(--fg-muted)]"}`,children:t.grade}),e.jsxs("div",{className:"flex-1 grid grid-cols-3 gap-2 text-xs",children:[t.completeness!=null&&t.completeness>0&&e.jsxs("div",{className:"text-center",children:[e.jsx("div",{className:"text-sm font-bold text-[var(--fg-primary)]",children:a(t.completeness)}),e.jsx("div",{className:"text-[var(--fg-muted)]",children:s.completeness})]}),t.adaptation!=null&&t.adaptation>0&&e.jsxs("div",{className:"text-center",children:[e.jsx("div",{className:"text-sm font-bold text-[var(--fg-primary)]",children:a(t.adaptation)}),e.jsx("div",{className:"text-[var(--fg-muted)]",children:s.adaptation})]}),t.documentation!=null&&t.documentation>0&&e.jsxs("div",{className:"text-center",children:[e.jsx("div",{className:"text-sm font-bold text-[var(--fg-primary)]",children:a(t.documentation)}),e.jsx("div",{className:"text-[var(--fg-muted)]",children:s.documentation})]})]})]})]})},Yo=({label:t,content:s})=>s?e.jsxs("div",{className:"px-6 py-4 border-b border-[var(--border-default)]",children:[e.jsxs("label",{className:"text-[10px] font-bold text-[var(--fg-muted)] uppercase mb-2 block flex items-center gap-1.5",children:[e.jsx(Qe,{size:11,className:"text-blue-400"})," ",t]}),e.jsx("div",{className:"bg-blue-50/30 border border-blue-100 rounded-xl p-4",children:e.jsx("div",{className:"markdown-body text-sm text-[var(--fg-primary)] leading-relaxed",children:e.jsx(Qt,{content:s})})})]}):null,Qo=({label:t,code:s,language:a})=>{if(!s)return null;const r=a==="objc"||a==="objective-c"?"objectivec":a||"text";return e.jsxs("div",{className:"px-6 py-4 border-b border-[var(--border-default)]",children:[e.jsxs("label",{className:"text-[10px] font-bold text-[var(--fg-muted)] uppercase mb-2 block flex items-center gap-1.5",children:[e.jsx(pt,{size:11,className:"text-emerald-500"})," ",t]}),e.jsx(ft,{code:s,language:r,showLineNumbers:!0})]})},Zo=({label:t,headers:s})=>!s||s.length===0?null:e.jsxs("div",{className:"px-6 py-3 border-b border-[var(--border-default)]",children:[e.jsx("label",{className:"text-[10px] font-bold text-[var(--fg-muted)] uppercase mb-2 block",children:t}),e.jsx("div",{className:"flex flex-wrap gap-1.5",children:s.map((a,r)=>e.jsx("code",{className:"px-2.5 py-1 bg-violet-50 text-violet-700 border border-violet-100 rounded-md text-[10px] font-mono font-medium",children:a},r))})]}),Xo=({label:t,text:s})=>s?e.jsxs("div",{className:"px-6 py-4 border-b border-[var(--border-default)]",children:[e.jsx("label",{className:"text-[10px] font-bold text-[var(--fg-muted)] uppercase mb-2 block",children:t}),e.jsx("div",{className:"bg-[var(--bg-subtle)] border border-[var(--border-default)] rounded-xl p-4",children:e.jsx("p",{className:"text-sm text-[var(--fg-secondary)] leading-relaxed",children:s})})]}):null,ei=({label:t,steps:s})=>!s||s.length===0?null:e.jsxs("div",{className:"px-6 py-4 border-b border-[var(--border-default)]",children:[e.jsx("label",{className:"text-[10px] font-bold text-[var(--fg-muted)] uppercase mb-2 block",children:t}),e.jsx("div",{className:"space-y-2",children:s.map((a,r)=>{if(typeof a=="string")return e.jsxs("div",{className:"bg-[var(--bg-subtle)] rounded-lg p-3 border border-[var(--border-default)] flex items-start gap-2.5",children:[e.jsx("span",{className:"text-[10px] font-bold text-blue-600 bg-blue-50 rounded-full w-5 h-5 flex items-center justify-center shrink-0 mt-0.5",children:r+1}),e.jsx("p",{className:"text-xs text-[var(--fg-primary)] leading-relaxed",children:a})]},r);const o=typeof a.title=="string"?a.title:"",l=typeof a.description=="string"?a.description:"",i=typeof a.code=="string"?a.code:"";return e.jsxs("div",{className:"bg-[var(--bg-subtle)] rounded-lg p-3 border border-[var(--border-default)]",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[e.jsx("span",{className:"text-[10px] font-bold text-blue-600 bg-blue-50 rounded-full w-5 h-5 flex items-center justify-center shrink-0",children:r+1}),o&&e.jsx("span",{className:"text-xs font-bold text-[var(--fg-primary)]",children:o})]}),l&&e.jsx("p",{className:"text-xs text-[var(--fg-secondary)] ml-7 leading-relaxed",children:l}),i&&e.jsx("pre",{className:"text-[11px] font-mono bg-slate-800 text-green-300 p-2.5 rounded-md mt-1.5 ml-7 overflow-x-auto whitespace-pre-wrap",children:i})]},r)})})]}),ti=({label:t,constraints:s})=>{if(!s)return null;const a=s,r=(a.guards?.length||0)+(a.boundaries?.length||0)+(a.preconditions?.length||0)+(a.sideEffects?.length||0);return r?e.jsxs("div",{className:"px-6 py-4 border-b border-[var(--border-default)]",children:[e.jsxs("label",{className:"text-[10px] font-bold text-[var(--fg-muted)] uppercase mb-2 block flex items-center gap-1.5",children:[e.jsx(Ve,{size:11,className:"text-amber-500"})," ",t," ",e.jsx("span",{className:"text-amber-500 font-mono",children:r})]}),e.jsxs("div",{className:"space-y-1.5 text-xs text-[var(--fg-secondary)]",children:[a.guards?.map((o,l)=>e.jsxs("div",{className:"flex gap-1.5 items-start",children:[e.jsx("span",{className:`text-xs mt-0.5 ${o.severity==="error"?"text-[var(--status-error)]":"text-[var(--status-warning)]"}`,children:"●"}),e.jsx("code",{className:"font-mono text-[10px] bg-[var(--bg-subtle)] px-1.5 py-0.5 rounded",children:o.pattern}),o.message&&e.jsxs("span",{className:"text-[10px] text-[var(--fg-muted)]",children:["— ",o.message]})]},l)),a.boundaries?.map((o,l)=>e.jsxs("div",{className:"flex gap-1.5",children:[e.jsx("span",{className:"text-[var(--status-warning)]",children:"●"}),o]},l)),a.preconditions?.map((o,l)=>e.jsxs("div",{className:"flex gap-1.5",children:[e.jsx("span",{className:"text-[var(--accent)]",children:"◆"}),o]},l)),a.sideEffects?.map((o,l)=>e.jsxs("div",{className:"flex gap-1.5",children:[e.jsx("span",{className:"text-pink-400",children:"⚡"}),o]},l))]})]}):null},si=({delivery:t,language:s})=>{if(!t)return null;const{topicHint:a,whenClause:r,doClause:o,dontClause:l,coreCode:i}=t;if(!o&&!r&&!l&&!a&&!i)return null;const p=s==="objectivec"||s==="objc"||s==="objective-c"?"objectivec":s||"text";return e.jsxs("div",{className:"px-6 py-4 border-b border-[var(--border-default)]",children:[e.jsxs("label",{className:"text-[10px] font-bold text-[var(--fg-muted)] uppercase mb-2 block flex items-center gap-1.5",children:[e.jsx(Ge,{size:11,className:"text-indigo-400"})," Cursor Delivery"]}),e.jsxs("div",{className:"bg-[var(--bg-subtle)] border border-[var(--border-default)] rounded-xl p-4 text-xs space-y-1.5",children:[a&&e.jsxs("div",{children:[e.jsx("span",{className:"text-indigo-400 font-medium",children:"Topic:"}),e.jsx("span",{className:"text-[var(--fg-primary)]",children:a})]}),r&&e.jsxs("div",{children:[e.jsx("span",{className:"text-blue-400 font-medium",children:"When:"}),e.jsx("span",{className:"text-[var(--fg-primary)]",children:r})]}),o&&e.jsxs("div",{children:[e.jsx("span",{className:"text-emerald-400 font-medium",children:"Do:"}),e.jsx("span",{className:"text-[var(--fg-primary)]",children:o})]}),l&&e.jsxs("div",{children:[e.jsx("span",{className:"text-red-400 font-medium",children:"Don't:"}),e.jsx("span",{className:"text-[var(--fg-primary)]",children:l})]}),i&&e.jsxs("div",{children:[e.jsx("span",{className:"text-purple-400 font-medium",children:"Core Code:"}),e.jsx("div",{className:"mt-1",children:e.jsx(ft,{code:i,language:p})})]})]})]})},Ee={Description:Wo,Reasoning:Vo,Quality:Jo,MarkdownSection:Yo,CodePattern:Qo,Headers:Zo,Rationale:Xo,Steps:ei,Constraints:ti,Delivery:si},ai=Xa("inline-flex items-center rounded-[var(--radius-sm)] px-2 py-0.5 text-xs font-medium leading-none whitespace-nowrap transition-all",{variants:{variant:{default:"bg-[var(--bg-subtle)] text-[var(--fg-muted)] border border-[var(--border-default)]",blue:"bg-[var(--accent-subtle)] text-[var(--accent)] border border-[var(--accent)]/15",green:"bg-[var(--success-subtle)] text-[var(--success)] border border-[var(--success)]/15",amber:"bg-[var(--warning-subtle)] text-[var(--warning)] border border-[var(--warning)]/15",red:"bg-[var(--danger-subtle)] text-[var(--danger)] border border-[var(--danger)]/15",info:"bg-[var(--info-subtle)] text-[var(--info)] border border-[var(--info)]/15",outline:"border border-[var(--border-default)] text-[var(--fg-muted)] bg-transparent",gradient:"text-white border-0"}},defaultVariants:{variant:"default"}}),Vs=n.forwardRef(({className:t,variant:s,style:a,...r},o)=>{const l=s==="gradient"?{background:"var(--accent-gradient)",...a}:a;return e.jsx("span",{ref:o,className:ye(ai({variant:s,className:t})),style:l,...r})});Vs.displayName="Badge";const ri=420,ni=({className:t="bg-black/20 backdrop-blur-[1px]"})=>e.jsx("div",{className:`absolute inset-0 ${t}`}),$e=({children:t,onClick:s,className:a="",style:r})=>{const{isOpen:o}=Zt();return e.jsx("div",{className:`fixed inset-0 overflow-hidden ${a}`,style:{right:o?ri:0,...r},onClick:s,children:t})};$e.Backdrop=ni;const li=n.forwardRef(({className:t,...s},a)=>e.jsx("div",{ref:a,className:ye("rounded-[var(--radius-lg)] border border-[var(--border-default)] bg-[var(--bg-surface)]","transition-all duration-250 ease-out","hover:border-[var(--border-emphasis)] hover:shadow-[var(--shadow-lg)] hover:-translate-y-0.5","dark:hover:shadow-[0_8px_32px_rgba(0,0,0,0.4),0_0_1px_rgba(255,255,255,0.06)]",t),...s}));li.displayName="Card";const oi=n.forwardRef(({className:t,...s},a)=>e.jsx("div",{ref:a,className:ye("flex items-center justify-between p-5 pb-0",t),...s}));oi.displayName="CardHeader";const ii=n.forwardRef(({className:t,...s},a)=>e.jsx("h3",{ref:a,className:ye("text-sm font-semibold text-[var(--fg-default)] leading-tight tracking-tight",t),...s}));ii.displayName="CardTitle";const ci=n.forwardRef(({className:t,...s},a)=>e.jsx("p",{ref:a,className:ye("text-sm text-[var(--fg-muted)] leading-relaxed",t),...s}));ci.displayName="CardDescription";const di=n.forwardRef(({className:t,...s},a)=>e.jsx("div",{ref:a,className:ye("p-5",t),...s}));di.displayName="CardContent";const ui=n.forwardRef(({className:t,...s},a)=>e.jsx("div",{ref:a,className:ye("flex items-center px-5 pb-5 pt-0",t),...s}));ui.displayName="CardFooter";const mi=n.forwardRef(({className:t,...s},a)=>e.jsx(Ln,{ref:a,className:ye("border-b border-[var(--border-muted)]",t),...s}));mi.displayName="AccordionItem";const pi=n.forwardRef(({className:t,children:s,...a},r)=>e.jsx(Fn,{className:"flex",children:e.jsxs(pr,{ref:r,className:ye("flex flex-1 items-center justify-between py-3 text-sm font-medium text-[var(--fg-default)] transition-all","hover:text-[var(--fg-default)] [&[data-state=open]>svg]:rotate-180",t),...a,children:[s,e.jsx(vt,{className:"h-4 w-4 shrink-0 text-[var(--fg-subtle)] transition-transform duration-200"})]})}));pi.displayName=pr.displayName;const xi=n.forwardRef(({className:t,children:s,...a},r)=>e.jsx(xr,{ref:r,className:"overflow-hidden text-sm data-[state=closed]:animate-accordion-up data-[state=open]:animate-accordion-down",...a,children:e.jsx("div",{className:ye("pb-4 pt-0",t),children:s})}));xi.displayName=xr.displayName;function Xe({className:t,...s}){return e.jsx("div",{className:ye("rounded-[var(--radius-md)] animate-shimmer",t),...s})}const Qr={sm:"w-[min(92vw,560px)]",md:"w-[min(92vw,700px)]","md-lg":"w-[min(92vw,800px)]",lg:"w-[min(92vw,960px)]",xl:"w-[min(92vw,1100px)]",full:"w-[min(96vw,1280px)]"};function gi({title:t,leading:s,subtitle:a,className:r,children:o}){return e.jsxs("div",{className:ye("flex items-center justify-between px-5 py-3 border-b border-[var(--border-default)] bg-[var(--bg-surface)] shrink-0",r),children:[e.jsxs("div",{className:"flex items-center flex-1 min-w-0 mr-3 gap-2",children:[s,t&&e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("h3",{className:"font-bold text-[var(--fg-primary)] text-lg leading-snug break-words",children:t}),a&&e.jsx("span",{className:"text-xs text-[var(--fg-muted)] mt-0.5 block truncate",children:a})]})]}),o&&e.jsx("div",{className:"flex items-center gap-1 shrink-0",children:o})]})}function hi({currentIndex:t,total:s,onPrev:a,onNext:r,hasPrev:o,hasNext:l}){const i=o!==void 0?!o:t<=0,p=l!==void 0?!l:t>=s-1;return e.jsxs(e.Fragment,{children:[e.jsx(We,{variant:"ghost",size:"icon-sm",onClick:a,disabled:i,children:e.jsx(Xs,{size:16})}),e.jsxs("span",{className:"text-xs text-[var(--fg-muted)] tabular-nums",children:[t+1,"/",s]}),e.jsx(We,{variant:"ghost",size:"icon-sm",onClick:r,disabled:p,children:e.jsx(Ue,{size:16})})]})}function bi({isWide:t,onToggle:s,title:a}){return e.jsx(We,{variant:"ghost",size:"icon-sm",onClick:s,title:a,children:t?e.jsx(ol,{size:16}):e.jsx(ea,{size:16})})}function fi({children:t}){return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"w-px h-5 bg-[var(--border-default)] mx-1"}),t]})}function vi({onClose:t}){return e.jsx(We,{variant:"ghost",size:"icon-sm",onClick:t,children:e.jsx(ze,{size:16})})}function yi({className:t,padded:s=!1,children:a}){return e.jsx("div",{className:ye("flex-1 overflow-y-auto",s&&"p-5 space-y-5",t),children:a})}function ji({className:t,children:s}){return e.jsx("div",{className:ye("shrink-0 border-t border-[var(--border-default)] px-5 py-3 bg-[var(--bg-surface)] flex items-center justify-between",t),children:s})}function wi({width:t,size:s="md",animationDuration:a="0.25s",className:r,children:o}){return e.jsx("div",{className:ye("relative h-full bg-[var(--bg-surface)] dark:bg-[var(--bg-surface)]/95 dark:backdrop-blur-xl shadow-2xl flex flex-col border-l border-[var(--border-default)] dark:border-[var(--glass-border)]",t||Qr[s],r),style:{animation:`slideInRight ${a} ease-out`},onClick:l=>l.stopPropagation(),children:o})}function Ie({open:t,onClose:s,size:a="md",className:r,animationDuration:o="0.25s",children:l}){return t?e.jsxs($e,{className:"z-30 flex justify-end",onClick:s,children:[e.jsx($e.Backdrop,{className:"bg-black/20 dark:bg-black/40 backdrop-blur-sm"}),e.jsx("div",{className:ye("relative h-full bg-[var(--bg-surface)] dark:bg-[var(--bg-surface)]/95 dark:backdrop-blur-xl shadow-2xl flex flex-col border-l border-[var(--border-default)] dark:border-[var(--glass-border)] dark:shadow-[0_0_80px_rgba(0,0,0,0.5)]",Qr[a],r),style:{animation:`slideInRight ${o} ease-out`},onClick:i=>i.stopPropagation(),children:l})]}):null}Ie.Header=gi;Ie.Nav=hi;Ie.WidthToggle=bi;Ie.HeaderActions=fi;Ie.CloseButton=vi;Ie.Body=yi;Ie.Footer=ji;Ie.Panel=wi;const Ls={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:St},fact:{label:"Fact",color:"text-cyan-700",bg:"bg-cyan-50",border:"border-cyan-200",icon:qe}},rs={"code-pattern":"recipes.knowledgeTypes.codePattern",architecture:"recipes.knowledgeTypes.architecture","best-practice":"recipes.knowledgeTypes.bestPractice","code-standard":"recipes.knowledgeTypes.codeStandard","call-chain":"recipes.knowledgeTypes.callChain",rule:"recipes.knowledgeTypes.rule"};function He(t){return(t.name||t.title||"Untitled").replace(/\.md$/i,"")}function Ni(t){return t.content?.pattern||""}function ki(t){const s=(t.language||"").toLowerCase();return["objectivec","objc","objective-c","obj-c"].includes(s)?"objectivec":t.language||"text"}function Zr(t){if(t==null)return!1;const s=typeof t=="string"?new Date(t).getTime():t;return!isNaN(s)&&s>9466848e5}function Ia(t){return Zr(t)?(typeof t=="string"?new Date(t):new Date(t)).toLocaleDateString("zh-CN",{year:"numeric",month:"2-digit",day:"2-digit"}):""}const Ci=({recipes:t,handleDeleteRecipe:s,onRefresh:a,idTitleMap:r,currentPage:o,onPageChange:l,pageSize:i,onPageSizeChange:p})=>{const{t:d}=Ae(),[g,x]=n.useState("newest"),[h,u]=n.useState("desc"),m=[{key:"newest",label:d("recipes.sortNewest"),defaultDir:"desc"},{key:"quality",label:d("recipes.sortQuality"),defaultDir:"desc"},{key:"usage",label:d("recipes.sortUsage"),defaultDir:"desc"},{key:"alpha",label:d("recipes.sortAlpha"),defaultDir:"asc"},{key:"category",label:d("recipes.sortCategory"),defaultDir:"asc"}],[c,j]=n.useState(1),[A,D]=n.useState(12),I=o??c,P=i??A,J=l??j,w=p?C=>p(C):C=>{D(C),j(1)},{isWide:B,toggle:z}=ia(),[k,E]=n.useState(null),[L,O]=n.useState("view"),[W,q]=n.useState({title:"",description:"",markdown:"",codePattern:"",rationale:"",tags:[],tagInput:""}),[N,v]=n.useState(!1),U=n.useRef(!0),[ae,be]=n.useState(!1),[me,je]=n.useState("related"),[G,le]=n.useState("");n.useEffect(()=>()=>{U.current=!1},[]);const de=[{key:"related",label:d("knowledgeGraph.relationAssociates"),icon:"∼"},{key:"dependsOn",label:d("knowledgeGraph.relationDependsOn"),icon:"⊕"},{key:"inherits",label:d("knowledgeGraph.relationInherits"),icon:"↑"},{key:"implements",label:d("knowledgeGraph.relationImplements"),icon:"◇"},{key:"calls",label:d("knowledgeGraph.relationCalls"),icon:"→"},{key:"dataFlow",label:d("knowledgeGraph.relationDataFlow"),icon:"⇢"},{key:"conflicts",label:d("knowledgeGraph.relationConflicts"),icon:"✕"},{key:"extends",label:d("knowledgeGraph.relationExtends"),icon:"⊃"}],R=C=>{E(C),O("view"),q({title:C.name?.replace(/\.md$/,"")||"",description:C.description||"",markdown:C.content?.markdown||"",codePattern:C.content?.pattern||"",rationale:C.content?.rationale||"",tags:C.tags||[],tagInput:""}),be(!1),le("")},T=()=>{E(null),O("view"),be(!1),le("")},X=async()=>{if(!(!k||N)){v(!0);try{const C=k.id||k.name;await Q.knowledgeUpdate(C,{title:W.title,description:W.description,tags:W.tags,content:{...k.content||{},pattern:W.codePattern,markdown:W.markdown,rationale:W.rationale}}),U.current&&(O("view"),a?.())}catch(C){re(ke(C,d("common.saveFailed")),{title:d("common.operationFailed"),type:"error"})}finally{U.current&&v(!1)}}},oe=async C=>{if(k)try{await Q.setRecipeAuthority(k.id||k.name,C),a?.()}catch(b){re(ke(b,d("common.operationFailed")),{title:d("common.operationFailed"),type:"error"})}},pe=C=>{const b=C.replace(/\.md$/i,"").toLowerCase();return t.find(_=>He(_).toLowerCase()===b)},ue=n.useMemo(()=>{const C=new Map;if(r)for(const[b,_]of Object.entries(r))C.set(b,_);for(const b of t)b.id&&C.set(b.id,He(b)),b.name&&C.set(b.name,He(b));return C},[t,r]),[M,Ce]=n.useState(!1),F=async(C,b)=>{if(!k||M)return;const _={};if(k.relations)for(const[te,ge]of Object.entries(k.relations))_[te]=[...ge];const ne=_[C]||[],$=b.replace(/\.md$/i,"");if(ne.some(te=>(typeof te=="string"?te:te.target||te.id||te.title||"").replace(/\.md$/i,"").toLowerCase()===$.toLowerCase()))return;_[C]=[...ne,$];const y=k;E({...k,relations:_}),be(!1),le(""),Ce(!0);try{await Q.updateRecipeRelations(k.id||k.name,_)}catch(te){E(y),re(ke(te,d("common.operationFailed")),{title:d("common.operationFailed"),type:"error"})}finally{Ce(!1)}},Se=async(C,b)=>{if(!k||M)return;const _={};if(k.relations)for(const[y,te]of Object.entries(k.relations))_[y]=[...te];const ne=_[C]||[];_[C]=ne.filter(y=>(typeof y=="string"?y:y.target||y.id||y.title||"").replace(/\.md$/i,"").toLowerCase()!==b.replace(/\.md$/i,"").toLowerCase()),_[C].length===0&&delete _[C];const $=k;E({...k,relations:_}),Ce(!0);try{await Q.updateRecipeRelations(k.id||k.name,_)}catch(y){E($),re(ke(y,d("common.operationFailed")),{title:d("common.operationFailed"),type:"error"})}finally{Ce(!1)}};n.useEffect(()=>{k&&!t.find(C=>He(C)===He(k))&&T()},[t,k]),n.useEffect(()=>{o==null&&j(1)},[t.length,o]);const Te=it.useMemo(()=>{if(g==="newest")return t;const C=[...t],b=h==="asc"?1:-1;return C.sort((_,ne)=>{let $=0,y=0;switch(g){case"alpha":return $=He(_).toLowerCase(),y=He(ne).toLowerCase(),b*($<y?-1:$>y?1:0);case"quality":$=_.quality?.overall??-1,y=ne.quality?.overall??-1;break;case"usage":$=(_.stats?.guardUsageCount??0)+(_.stats?.humanUsageCount??0)+(_.stats?.aiUsageCount??0),y=(ne.stats?.guardUsageCount??0)+(ne.stats?.humanUsageCount??0)+(ne.stats?.aiUsageCount??0);break;case"category":return $=(_.category||"").toLowerCase(),y=(ne.category||"").toLowerCase(),b*($<y?-1:$>y?1:0)}return b*($-y)}),C},[t,g,h]),Fe=Math.ceil(Te.length/P),Me=(I-1)*P,ee=Te.slice(Me,Me+P),ce=C=>{J(C),window.scrollTo({top:0,behavior:"smooth"})},f=k?Te.findIndex(C=>He(C)===He(k)):-1,V=()=>{f>0&&R(Te[f-1])},xe=()=>{f<Te.length-1&&R(Te[f+1])},fe=({recipe:C})=>{const b=C.kind?Ls[C.kind]:null,_=C.category||"Utility",ne=C.knowledgeType,$=[];return b&&$.push(b.label),$.push(_),ne&&rs[ne]&&$.push(d(rs[ne])),C.language&&$.push(C.language.toUpperCase()),C.trigger&&$.push(C.trigger),e.jsx("span",{className:"text-[11px] text-[var(--fg-muted)] truncate",children:$.join(" · ")})};return e.jsxs("div",{className:"relative pb-6",children:[t.length===0?e.jsxs("div",{className:"flex flex-col items-center justify-center py-24 text-center",children:[e.jsx(hr,{size:48,className:"text-[var(--fg-muted)] mb-4 opacity-40"}),e.jsx("p",{className:"font-medium text-[var(--fg-secondary)] mb-1",children:d("recipes.noResults")}),e.jsx("p",{className:"text-sm text-[var(--fg-muted)]",children:d("recipes.noContent")})]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center gap-1.5 mb-4 border-b border-[var(--border-default)] pb-3",children:[m.map(C=>{const b=g===C.key;return e.jsxs("button",{onClick:()=>{b?u(_=>_==="asc"?"desc":"asc"):(x(C.key),u(C.defaultDir)),J(1)},className:ye("px-4 py-1.5 rounded-md text-xs font-medium transition-colors flex items-center gap-1",b?"bg-[var(--accent-subtle)] text-[var(--accent)] border border-[var(--accent-emphasis)]":"text-[var(--fg-muted)] hover:bg-[var(--bg-subtle)] border border-transparent"),children:[C.label,b&&g!=="newest"&&(h==="asc"?e.jsx(il,{size:12}):e.jsx(cl,{size:12}))]},C.key)}),e.jsx("span",{className:"ml-auto text-xs text-[var(--fg-muted)]",children:d("recipes.totalCount",{count:t.length})})]}),e.jsx("div",{children:ee.map(C=>{const b=He(C),_=C.description||C.usageGuide||"",ne=k&&He(k)===b,$=C.kind?Ls[C.kind]:null;return e.jsx("div",{onClick:()=>R(C),className:ye("group relative cursor-pointer py-4 px-4 rounded-lg transition-colors hover:bg-[var(--bg-subtle)] after:absolute after:bottom-0 after:left-4 after:right-4 after:h-px after:bg-[var(--border-default)] last:after:hidden",ne&&"bg-[var(--accent-subtle)]"),children:e.jsxs("div",{className:"flex items-start justify-between gap-4",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("h3",{className:"font-semibold text-[var(--fg-primary)] text-sm break-words leading-snug truncate",children:b}),$&&e.jsx(Vs,{variant:$.label==="Rule"?"red":$.label==="Pattern"?"blue":"default",className:"text-[9px] uppercase shrink-0",children:$.label}),C.stats?.authority!=null&&C.stats.authority>=4&&e.jsxs("span",{className:"text-amber-500 text-[11px] shrink-0",children:["★ ",C.stats.authority]})]}),_&&e.jsx("p",{className:"text-xs text-[var(--fg-secondary)] line-clamp-1 leading-relaxed mb-1.5",children:_.replace(/^#+\s*/gm,"").replace(/\*\*/g,"")}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(fe,{recipe:C,compact:!0}),C.tags&&C.tags.length>0&&e.jsxs("span",{className:"text-[11px] text-[var(--fg-muted)]",children:[C.tags.slice(0,3).join(", "),C.tags.length>3&&` +${C.tags.length-3}`]})]})]}),e.jsx("div",{className:"opacity-0 group-hover:opacity-100 transition-opacity shrink-0",children:e.jsxs($r,{children:[e.jsx(Or,{asChild:!0,children:e.jsx(We,{variant:"ghost",size:"icon-sm",onClick:y=>y.stopPropagation(),children:e.jsx(dl,{size:14})})}),e.jsxs(oa,{align:"end",children:[e.jsxs(kt,{onClick:y=>{y.stopPropagation(),R(C)},children:[e.jsx(Ut,{size:14,className:"mr-2"})," ",d("common.preview")]}),e.jsxs(kt,{onClick:y=>{y.stopPropagation(),R(C),O("edit")},children:[e.jsx(It,{size:14,className:"mr-2"})," ",d("common.edit")]}),e.jsx(vs,{}),e.jsxs(kt,{className:"text-[var(--status-error)]",onClick:y=>{y.stopPropagation(),s(C.name||C.id||"")},children:[e.jsx(Ke,{size:14,className:"mr-2"})," ",d("recipes.deleteRecipe")]})]})]})})]})},C.id||b)})})]}),t.length>0&&e.jsx(ca,{currentPage:I,totalPages:Fe,totalItems:Te.length,pageSize:P,onPageChange:ce,onPageSizeChange:w}),k&&(()=>{const C=k,b=He(C),_=Ni(C),ne=ki(C),$=C.content;return e.jsxs(Ie,{open:!!k,onClose:T,size:B?"lg":"md",children:[e.jsxs(Ie.Header,{title:b,leading:e.jsx("button",{onClick:()=>{s(C.name||C.id||""),T()},title:d("recipes.deleteRecipe"),className:"p-1.5 text-[var(--fg-muted)] hover:text-red-500 rounded-md transition-colors opacity-30 hover:opacity-100 shrink-0",children:e.jsx(Ke,{size:14})}),children:[e.jsx(Ie.Nav,{currentIndex:f,total:Te.length,onPrev:V,onNext:xe}),e.jsxs(Ie.HeaderActions,{children:[e.jsxs("div",{className:"flex bg-[var(--bg-subtle)] p-0.5 rounded-lg mr-1",children:[e.jsxs("button",{onClick:()=>O("view"),className:ye("px-2.5 py-1 rounded-md text-xs font-bold transition-all flex items-center gap-1",L==="view"?"bg-[var(--bg-surface)] shadow-sm text-[var(--accent)]":"text-[var(--fg-muted)] hover:text-[var(--fg-secondary)]"),children:[e.jsx(Ut,{size:H.sm})," ",d("common.preview")]}),e.jsxs("button",{onClick:()=>{O("edit")},className:ye("px-2.5 py-1 rounded-md text-xs font-bold transition-all flex items-center gap-1",L==="edit"?"bg-[var(--bg-surface)] shadow-sm text-[var(--accent)]":"text-[var(--fg-muted)] hover:text-[var(--fg-secondary)]"),children:[e.jsx(It,{size:H.sm})," ",d("common.edit")]})]}),e.jsx(Ie.WidthToggle,{isWide:B,onToggle:z}),e.jsx(Ie.CloseButton,{onClose:T})]})]}),L==="edit"?e.jsxs(e.Fragment,{children:[e.jsxs(Ie.Body,{padded:!0,children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-[10px] font-bold text-[var(--fg-muted)] uppercase mb-1.5 block",children:d("recipes.recipeDetail")}),e.jsx("input",{type:"text",value:W.title,onChange:y=>q(te=>({...te,title:y.target.value})),className:"w-full px-3 py-2 text-sm border border-[var(--border-default)] rounded-lg bg-[var(--bg-root)] text-[var(--fg-primary)] focus:outline-none focus:ring-2 focus:ring-[var(--accent-emphasis)] focus:border-[var(--accent-emphasis)]"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-[10px] font-bold text-[var(--fg-muted)] uppercase mb-1.5 block",children:d("recipes.description")}),e.jsx("textarea",{value:W.description,onChange:y=>q(te=>({...te,description:y.target.value})),rows:2,className:"w-full px-3 py-2 text-sm border border-[var(--border-default)] rounded-lg bg-[var(--bg-root)] text-[var(--fg-primary)] focus:outline-none focus:ring-2 focus:ring-[var(--accent-emphasis)] resize-none"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-[10px] font-bold text-[var(--fg-muted)] uppercase mb-1.5 block",children:d("recipes.tags")}),e.jsx("div",{className:"flex flex-wrap gap-1.5 mb-2",children:W.tags.map((y,te)=>e.jsxs("span",{className:"inline-flex items-center gap-1 text-[10px] px-2 py-0.5 rounded bg-[var(--accent-subtle)] text-[var(--accent)] border border-[var(--border-default)] font-medium",children:[y,e.jsx("button",{onClick:()=>q(ge=>({...ge,tags:ge.tags.filter((he,De)=>De!==te)})),className:"text-[var(--fg-muted)] hover:text-[var(--status-error)]",children:e.jsx(ze,{size:10})})]},te))}),e.jsx("div",{className:"flex gap-2",children:e.jsx("input",{type:"text",value:W.tagInput,onChange:y=>q(te=>({...te,tagInput:y.target.value})),onKeyDown:y=>{y.key==="Enter"&&W.tagInput.trim()&&(y.preventDefault(),q(te=>({...te,tags:[...te.tags,te.tagInput.trim()],tagInput:""})))},placeholder:d("recipes.tags"),className:"flex-1 px-3 py-1.5 text-xs border border-[var(--border-default)] rounded-lg bg-[var(--bg-root)] text-[var(--fg-primary)] focus:outline-none focus:ring-2 focus:ring-[var(--accent-emphasis)]"})})]}),e.jsxs("div",{children:[e.jsxs("label",{className:"text-[10px] font-bold text-[var(--fg-muted)] uppercase mb-1.5 block flex items-center gap-1.5",children:[e.jsx(Qe,{size:11,className:"text-[var(--accent)]"})," ",d("recipes.markdown")]}),e.jsx("textarea",{value:W.markdown,onChange:y=>q(te=>({...te,markdown:y.target.value})),rows:4,className:"w-full px-3 py-2 text-sm border border-[var(--border-default)] rounded-lg bg-[var(--bg-root)] text-[var(--fg-primary)] focus:outline-none focus:ring-2 focus:ring-[var(--accent-emphasis)] resize-y font-mono",placeholder:d("recipes.markdown")})]}),e.jsxs("div",{children:[e.jsxs("label",{className:"text-[10px] font-bold text-[var(--fg-muted)] uppercase mb-1.5 block flex items-center gap-1.5",children:[e.jsx(At,{size:11,className:"text-[var(--status-success)]"})," ",d("recipes.code")]}),e.jsx("div",{className:"border border-[var(--border-default)] rounded-lg overflow-hidden",style:{minHeight:200},children:e.jsx(ys,{value:W.codePattern,onChange:y=>q(te=>({...te,codePattern:y})),language:ne,height:"200px",showLineNumbers:!0})})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-[10px] font-bold text-[var(--fg-muted)] uppercase mb-1.5 block",children:d("recipes.designRationale")}),e.jsx("textarea",{value:W.rationale,onChange:y=>q(te=>({...te,rationale:y.target.value})),rows:3,className:"w-full px-3 py-2 text-sm border border-[var(--border-default)] rounded-lg bg-[var(--bg-root)] text-[var(--fg-primary)] focus:outline-none focus:ring-2 focus:ring-[var(--accent-emphasis)] resize-y",placeholder:d("recipes.designRationale")})]})]}),e.jsxs(Ie.Footer,{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-xs text-[var(--fg-muted)]",children:d("recipes.qualityAuthorityScore")}),e.jsx(tt,{value:String(C.stats?.authority??3),onChange:y=>oe(parseInt(y)),options:[1,2,3,4,5].map(y=>({value:String(y),label:`${"⭐".repeat(y)} ${y}`})),size:"xs",className:"font-bold text-amber-600 bg-amber-50 border-amber-100"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(We,{variant:"ghost",onClick:()=>O("view"),disabled:N,children:d("common.cancel")}),e.jsxs(We,{variant:"primary",onClick:X,disabled:N,loading:N,children:[!N&&e.jsx(ws,{size:H.sm}),d(N?"common.saving":"common.save")]})]})]})]}):e.jsxs(Ie.Body,{children:[e.jsx(da,{badges:(()=>{const y=C.kind?Ls[C.kind]:null,te=C.category||"Utility",ge=et[te]||et.All,he=[];return y&&he.push({label:y.label,className:`${y.bg} ${y.color} ${y.border}`,icon:y.icon}),he.push({label:te,className:`font-bold uppercase ${ge?.bg||"bg-[var(--bg-subtle)]"} ${ge?.color||"text-[var(--fg-muted)]"} ${ge?.border||"border-[var(--border-default)]"}`}),C.knowledgeType&&he.push({label:rs[C.knowledgeType]?d(rs[C.knowledgeType]):C.knowledgeType,className:"bg-purple-50 text-purple-700 border-purple-200"}),C.language&&he.push({label:C.language,className:"uppercase font-bold text-[var(--fg-secondary)] bg-[var(--bg-subtle)] border-[var(--border-default)]"}),C.trigger&&he.push({label:C.trigger,className:"font-mono font-bold bg-amber-50 text-amber-700 border-amber-200"}),C.source&&C.source!=="unknown"&&he.push({label:C.source,className:"bg-[var(--bg-subtle)] text-[var(--fg-secondary)] border-[var(--border-default)]"}),he})(),metadata:(()=>{const y=[];return C.scope&&y.push({icon:Ct,iconClass:"text-teal-400",label:d("candidates.path"),value:C.scope==="universal"?d("common.all"):C.scope==="project-specific"?d("candidates.category"):C.scope}),C.complexity&&y.push({icon:Ge,iconClass:"text-orange-400",label:d("knowledge.complexity"),value:C.complexity==="advanced"?d("knowledge.complexityAdvanced"):C.complexity==="intermediate"?d("knowledge.complexityIntermediate"):C.complexity==="beginner"?d("knowledge.complexityBeginner"):C.complexity}),C.source&&C.source!=="unknown"&&y.push({icon:Ct,iconClass:"text-violet-400",label:d("recipes.sourceLabel"),value:C.source==="bootstrap-scan"?d("recipes.sourceBootstrap"):C.source==="agent"?d("recipes.sourceAiScan"):C.source}),C.updatedAt&&Zr(C.updatedAt)&&y.push({icon:Ye,iconClass:"text-[var(--fg-muted)]",label:d("candidates.updatedAt"),value:Ia(C.updatedAt)}),y})(),tags:C.tags,id:C.id,sourceFile:C.sourceFile,sourceFileLabel:d("candidates.path")}),e.jsxs("div",{className:"px-6 py-4 border-b border-[var(--border-default)]",children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(ta,{size:12,className:ye("text-purple-400",M&&"animate-spin")}),e.jsx("label",{className:"text-[10px] font-bold text-[var(--fg-muted)] uppercase",children:d("recipes.relations")}),(()=>{const y=C.relations?Object.values(C.relations).flat().length:0;return y>0?e.jsx(Vs,{variant:"blue",className:"text-[9px]",children:y}):null})()]}),e.jsx(We,{variant:ae?"secondary":"primary",size:"sm",onClick:()=>{be(!ae),le("")},children:ae?e.jsxs(e.Fragment,{children:[e.jsx(ze,{size:10})," ",d("common.cancel")]}):e.jsxs(e.Fragment,{children:[e.jsx(mt,{size:10})," ",d("recipes.editBtn")]})})]}),ae&&e.jsxs("div",{className:"mb-3 bg-[var(--bg-subtle)] border border-[var(--border-default)] rounded-lg p-3 space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(tt,{value:me,onChange:y=>je(y),options:de.map(y=>({value:y.key,label:`${y.icon} ${y.label}`})),size:"xs",className:"font-bold"}),e.jsxs("div",{className:"flex-1 relative",children:[e.jsx(xt,{size:12,className:"absolute left-2 top-1/2 -translate-y-1/2 text-[var(--fg-muted)]"}),e.jsx("input",{type:"text",placeholder:d("recipes.searchPlaceholder"),value:G,onChange:y=>le(y.target.value),className:"w-full text-xs bg-[var(--bg-root)] border border-[var(--border-default)] rounded pl-7 pr-2 py-1 outline-none text-[var(--fg-primary)]",autoFocus:!0})]})]}),G.length>0&&e.jsx("div",{className:"max-h-36 overflow-y-auto rounded border border-[var(--border-default)] bg-[var(--bg-root)] divide-y divide-[var(--border-default)]",children:(()=>{const y=t.filter(te=>He(te)===b?!1:He(te).toLowerCase().includes(G.toLowerCase())).slice(0,10);return y.length?y.map(te=>{const ge=He(te),he=C.relations&&Object.values(C.relations).flat().some(De=>(typeof De=="string"?De:De.target||De.id||De.title||"").replace(/\.md$/i,"").toLowerCase()===ge.toLowerCase());return e.jsxs("div",{className:ye("flex items-center justify-between px-3 py-1.5 text-xs",he||M?"bg-[var(--bg-subtle)] text-[var(--fg-muted)]":"hover:bg-[var(--bg-subtle)] cursor-pointer"),onClick:()=>!he&&!M&&F(me,ge),children:[e.jsx("span",{className:"font-medium truncate mr-2",children:ge}),he?e.jsx("span",{className:"text-[9px] text-[var(--fg-muted)] font-bold shrink-0",children:d("recipes.relations")}):e.jsxs("span",{className:"text-[9px] text-[var(--accent)] font-bold shrink-0",children:["+ ",d("recipes.editBtn")]})]},ge)}):e.jsx("div",{className:"text-xs text-[var(--fg-muted)] py-3 text-center",children:d("recipes.noResults")})})()})]}),C.relations&&Object.entries(C.relations).some(([,y])=>Array.isArray(y)&&y.length>0)?e.jsx("div",{className:"space-y-1.5",children:de.map(({key:y,label:te,icon:ge})=>{const he=C.relations?.[y];return!he||!Array.isArray(he)||he.length===0?null:e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsxs("span",{className:"text-[10px] font-mono text-[var(--fg-muted)] shrink-0 whitespace-nowrap pt-0.5",children:[ge," ",te]}),e.jsx("div",{className:"flex flex-wrap gap-1",children:he.map((De,se)=>{const we=typeof De=="string"?De:De.target||De.id||De.title||JSON.stringify(De),Oe=pe(we)||(ue.has(we)?pe(ue.get(we)):void 0),rt=Oe?He(Oe):ue.get(we)||we;return e.jsxs("span",{className:ye("group/rel inline-flex items-center gap-1 px-1.5 py-0.5 border rounded text-[10px] font-mono transition-colors",Oe?"bg-[var(--accent-subtle)] border-[var(--accent-emphasis)] text-[var(--accent)] cursor-pointer hover:brightness-95":"bg-[var(--bg-root)] border-[var(--border-default)] text-[var(--fg-secondary)]"),onClick:()=>Oe&&R(Oe),title:Oe?d("candidates.viewDetail"):rt,children:[rt.replace(/\.md$/i,""),e.jsx("button",{onClick:ct=>{ct.stopPropagation(),!M&&window.confirm(`${d("common.delete")}: ${rt.replace(/\.md$/i,"")}?`)&&Se(y,we)},disabled:M,className:"opacity-0 group-hover/rel:opacity-100 text-[var(--danger)] hover:text-[var(--danger)] transition-opacity ml-1 p-0.5 rounded hover:bg-[var(--danger-subtle)]",title:d("common.delete"),children:e.jsx(ze,{size:10})})]},se)})})]},y)})}):!ae&&e.jsx("div",{className:"text-xs text-[var(--fg-muted)] py-2 text-center",children:d("recipes.noContent")})]}),e.jsxs("div",{className:"px-6 py-3 border-b border-[var(--border-default)]",children:[e.jsxs("div",{className:"grid grid-cols-2 sm:grid-cols-4 gap-3",children:[e.jsxs("div",{className:"bg-[var(--bg-subtle)] rounded-xl p-3 text-center border border-[var(--border-default)]",children:[e.jsx("div",{className:"text-lg font-bold text-amber-600",children:C.stats?.authority??"—"}),e.jsx("div",{className:"text-[10px] text-[var(--fg-muted)] font-medium",children:d("recipes.qualityAuthorityScore")})]}),e.jsxs("div",{className:"bg-[var(--bg-subtle)] rounded-xl p-3 text-center border border-[var(--border-default)]",children:[e.jsx("div",{className:"text-lg font-bold text-[var(--accent)]",children:C.stats?.authorityScore!=null?C.stats.authorityScore.toFixed(1):"—"}),e.jsx("div",{className:"text-[10px] text-[var(--fg-muted)] font-medium",children:d("recipes.qualityGreat")})]}),e.jsxs("div",{className:"bg-[var(--bg-subtle)] rounded-xl p-3 text-center border border-[var(--border-default)]",children:[e.jsx("div",{className:"text-lg font-bold text-[var(--fg-primary)]",children:C.stats?C.stats.guardUsageCount+C.stats.humanUsageCount+C.stats.aiUsageCount:0}),e.jsx("div",{className:"text-[10px] text-[var(--fg-muted)] font-medium",children:d("recipes.qualitySolid")})]}),e.jsxs("div",{className:"bg-[var(--bg-subtle)] rounded-xl p-3 text-center border border-[var(--border-default)]",children:[e.jsx("div",{className:"text-sm font-bold text-[var(--fg-secondary)]",children:Ia(C.stats?.lastUsedAt)||d("recipes.noContent")}),e.jsx("div",{className:"text-[10px] text-[var(--fg-muted)] font-medium",children:d("recipes.qualityGood")})]})]}),C.stats!=null&&(C.stats.guardUsageCount>0||C.stats.humanUsageCount>0||C.stats.aiUsageCount>0)&&e.jsxs("div",{className:"flex items-center gap-4 mt-2 text-[10px] text-[var(--fg-muted)]",children:[e.jsxs("span",{children:["Guard: ",C.stats.guardUsageCount]}),e.jsxs("span",{children:["Human: ",C.stats.humanUsageCount]}),e.jsxs("span",{children:["AI: ",C.stats.aiUsageCount]})]})]}),e.jsx(Ee.Reasoning,{reasoning:C.reasoning,labels:{section:d("recipes.reasoning"),source:d("recipes.sourceColon"),confidence:d("recipes.confidenceColon"),alternatives:d("recipes.alternativesLabel")}}),e.jsx(Ee.Quality,{quality:C.quality,labels:{section:d("recipes.qualityGrade"),completeness:d("recipes.qualityCompleteness"),adaptation:d("recipes.qualityAdaptation"),documentation:d("recipes.qualityDocumentation")}}),e.jsx(Ee.Description,{label:d("recipes.description"),text:C.description}),e.jsx(Ee.MarkdownSection,{label:d("recipes.markdown"),content:$?.markdown}),e.jsx(Ee.Headers,{label:d("recipes.headers"),headers:C.headers}),e.jsx(Ee.CodePattern,{label:d("recipes.code"),code:_,language:ne}),e.jsx(Ee.Rationale,{label:d("recipes.designRationale"),text:$?.rationale}),e.jsx(Ee.Steps,{label:d("recipes.steps"),steps:$?.steps}),$?.codeChanges&&$.codeChanges.length>0&&e.jsxs("div",{className:"px-6 py-4 border-b border-[var(--border-default)]",children:[e.jsx("label",{className:"text-[10px] font-bold text-[var(--fg-muted)] uppercase mb-2 block",children:d("recipes.codeChanges")}),e.jsx("div",{className:"space-y-2",children:$.codeChanges.map((y,te)=>e.jsxs("div",{className:"border border-[var(--border-default)] rounded-lg overflow-hidden",children:[e.jsxs("div",{className:"px-3 py-1.5 bg-[var(--bg-subtle)] border-b border-[var(--border-default)] flex items-center gap-2",children:[e.jsx(pt,{size:11,className:"text-[var(--accent)]"}),e.jsx("code",{className:"text-[10px] font-mono text-[var(--fg-secondary)]",children:y.file})]}),y.explanation&&e.jsx("p",{className:"text-[11px] text-[var(--fg-muted)] px-3 py-1.5 border-b border-[var(--border-default)] bg-[var(--bg-subtle)]",children:y.explanation}),e.jsxs("div",{className:"p-2 bg-red-50/10 border-b border-[var(--border-default)]",children:[e.jsx("div",{className:"text-[9px] font-bold text-[var(--status-error)] mb-0.5 uppercase",children:"Before"}),e.jsx("pre",{className:"text-[11px] text-[var(--fg-secondary)] whitespace-pre-wrap break-words font-mono",children:y.before||d("recipes.emptyValue")})]}),e.jsxs("div",{className:"p-2 bg-emerald-50/10",children:[e.jsx("div",{className:"text-[9px] font-bold text-[var(--status-success)] mb-0.5 uppercase",children:"After"}),e.jsx("pre",{className:"text-[11px] text-[var(--fg-primary)] whitespace-pre-wrap break-words font-mono",children:y.after})]})]},te))})]}),$?.verification&&e.jsxs("div",{className:"px-6 py-4 border-b border-[var(--border-default)]",children:[e.jsx("label",{className:"text-[10px] font-bold text-[var(--fg-muted)] uppercase mb-2 block",children:d("recipes.validation")}),e.jsxs("div",{className:"bg-[var(--bg-subtle)] border border-[var(--border-default)] rounded-xl p-4 space-y-1.5",children:[$.verification.method&&e.jsxs("p",{className:"text-xs text-[var(--fg-secondary)]",children:[e.jsx("span",{className:"font-bold text-[var(--status-success)]",children:d("recipes.verificationMethod")})," ",$.verification.method]}),$.verification.expectedResult&&e.jsxs("p",{className:"text-xs text-[var(--fg-secondary)]",children:[e.jsx("span",{className:"font-bold text-[var(--status-success)]",children:d("recipes.verificationExpected")})," ",$.verification.expectedResult]}),$.verification.testCode&&e.jsx("pre",{className:"text-[11px] font-mono bg-slate-800 text-green-300 p-2.5 rounded-md overflow-x-auto whitespace-pre-wrap mt-1",children:$.verification.testCode})]})]}),e.jsx(Ee.Constraints,{label:d("recipes.constraints"),constraints:C.constraints})]})]})})()]})};function yt(t){return t>=1e6?(t/1e6).toFixed(1)+"M":t>=1e3?(t/1e3).toFixed(1)+"k":String(t)}function Si(t){const s=new Map(t.map(r=>[r.date,r])),a=[];for(let r=6;r>=0;r--){const o=new Date;o.setDate(o.getDate()-r);const l=o.toISOString().slice(0,10);a.push(s.get(l)||{date:l,input_tokens:0,output_tokens:0,total_tokens:0,call_count:0})}return a}const Ai={user:"bg-blue-500",mcp:"bg-purple-500",bootstrap:"bg-amber-500",guard:"bg-rose-500",analyst:"bg-indigo-500",producer:"bg-green-500"},Di=()=>{const{t}=Ae(),[s,a]=n.useState([]),[r,o]=n.useState([]),[l,i]=n.useState({input_tokens:0,output_tokens:0,total_tokens:0,call_count:0,avg_per_call:0}),[p,d]=n.useState(!0),[g,x]=n.useState(null);n.useEffect(()=>{let c=!1;return(async()=>{try{const j=await Q.getTokenUsage7Days();if(c)return;a(j.daily||[]),o(j.bySource||[]),i(j.summary||{input_tokens:0,output_tokens:0,total_tokens:0,call_count:0,avg_per_call:0})}catch(j){c||x(ke(j,t("tokenUsageChart.loadFailed")))}finally{c||d(!1)}})(),()=>{c=!0}},[]);const h=n.useMemo(()=>Si(s),[s]),u=n.useMemo(()=>Math.max(...h.map(c=>c.total_tokens),1),[h]);if(p)return e.jsxs("div",{className:"flex items-center justify-center py-10",children:[e.jsx("div",{className:"animate-spin rounded-full h-6 w-6 border-2 border-blue-500 border-t-transparent"}),e.jsx("span",{className:"ml-2 text-slate-500 text-sm",children:t("tokenUsageChart.loading")})]});if(g)return e.jsx("p",{className:"text-red-500 text-sm py-4 text-center",children:g});const m=l.total_tokens===0;return e.jsxs("div",{className:"space-y-5",children:[e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-3",children:[e.jsx(ns,{label:t("tokenUsageChart.totalToken"),value:yt(l.total_tokens),sub:t("tokenUsageChart.totalSub"),color:"blue"}),e.jsx(ns,{label:t("tokenUsageChart.input"),value:yt(l.input_tokens),sub:"Prompt",color:"green"}),e.jsx(ns,{label:t("tokenUsageChart.output"),value:yt(l.output_tokens),sub:"Completion",color:"purple"}),e.jsx(ns,{label:t("tokenUsageChart.calls"),value:String(l.call_count),sub:t("tokenUsageChart.avgPerCall",{avg:yt(l.avg_per_call)}),color:"amber"})]}),m?e.jsx("div",{className:"text-center py-8 text-slate-400 text-sm",children:t("tokenUsageChart.emptyState")}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{children:[e.jsx("h4",{className:"text-sm font-semibold text-slate-700 mb-3",children:t("tokenUsageChart.dailyUsage")}),e.jsx("div",{className:"flex items-end gap-1.5 h-40",children:h.map(c=>{const j=c.input_tokens/u*100,A=c.output_tokens/u*100,D=t(`tokenUsageChart.weekday${new Date(c.date+"T00:00:00").getDay()}`);return e.jsxs("div",{className:"flex-1 flex flex-col items-center gap-1 group relative",children:[e.jsxs("div",{className:"absolute -top-16 left-1/2 -translate-x-1/2 bg-slate-800 text-white text-xs rounded px-2 py-1 opacity-0 group-hover:opacity-100 transition-opacity whitespace-nowrap pointer-events-none z-10",children:[e.jsx("p",{children:c.date}),e.jsx("p",{children:t("tokenUsageChart.dailyDetail",{input:yt(c.input_tokens),output:yt(c.output_tokens)})}),e.jsx("p",{children:t("tokenUsageChart.dailyCalls",{count:String(c.call_count)})})]}),e.jsxs("div",{className:"w-full flex flex-col justify-end",style:{height:"120px"},children:[e.jsx("div",{className:"bg-green-400 rounded-t-sm w-full transition-all",style:{height:`${j}%`,minHeight:c.input_tokens>0?"2px":"0"}}),e.jsx("div",{className:"bg-purple-400 rounded-b-sm w-full transition-all",style:{height:`${A}%`,minHeight:c.output_tokens>0?"2px":"0"}})]}),e.jsx("span",{className:"text-[10px] text-slate-400",children:D})]},c.date)})}),e.jsxs("div",{className:"flex gap-4 mt-2 text-xs text-slate-500 justify-center",children:[e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx("span",{className:"w-2.5 h-2.5 rounded-sm bg-green-400 inline-block"})," ",t("tokenUsageChart.legendInput")]}),e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx("span",{className:"w-2.5 h-2.5 rounded-sm bg-purple-400 inline-block"})," ",t("tokenUsageChart.legendOutput")]})]})]}),r.length>0&&e.jsxs("div",{children:[e.jsx("h4",{className:"text-sm font-semibold text-slate-700 mb-3",children:t("tokenUsageChart.sourceDistribution")}),e.jsx("div",{className:"space-y-2",children:r.map(c=>{const j=l.total_tokens>0?c.total_tokens/l.total_tokens*100:0,A=Ai[c.source]||"bg-slate-400";return e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("span",{className:"w-20 text-xs text-slate-600 text-right truncate",children:c.source}),e.jsx("div",{className:"flex-1 bg-slate-100 rounded-full h-3 overflow-hidden",children:e.jsx("div",{className:`${A} h-full rounded-full transition-all`,style:{width:`${j}%`,minWidth:j>0?"4px":"0"}})}),e.jsx("span",{className:"w-16 text-xs text-slate-500 text-right",children:yt(c.total_tokens)}),e.jsxs("span",{className:"w-12 text-xs text-slate-400 text-right",children:[j.toFixed(0),"%"]})]},c.source)})})]})]})]})};function ns({label:t,value:s,sub:a,color:r}){const o={blue:"bg-blue-50 border-blue-200 text-blue-700",green:"bg-green-50 border-green-200 text-green-700",purple:"bg-purple-50 border-purple-200 text-purple-700",amber:"bg-amber-50 border-amber-200 text-amber-700"},l=o[r]||o.blue;return e.jsxs("div",{className:`rounded-lg border p-3 ${l}`,children:[e.jsx("p",{className:"text-xs opacity-70",children:t}),e.jsx("p",{className:"text-xl font-bold",children:s}),e.jsx("p",{className:"text-[10px] opacity-60",children:a})]})}const gt=({id:t,title:s,icon:a,isExpanded:r,onToggle:o,children:l})=>e.jsxs("section",{className:"border border-[var(--border-default)] rounded-lg overflow-hidden",children:[e.jsxs("button",{onClick:()=>o(t),className:"w-full flex items-center justify-between p-4 bg-[var(--bg-subtle)] hover:bg-[var(--bg-muted)] active:bg-[var(--bg-muted)] outline-none focus:outline-none focus-visible:outline-none transition-colors",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[a,e.jsx("h2",{className:"text-lg font-bold text-[var(--fg-primary)]",children:s})]}),r?e.jsx(vt,{size:H.lg}):e.jsx(Ue,{size:H.lg})]}),r&&e.jsx("div",{className:"p-4 bg-[var(--bg-surface)]",children:l})]}),Ri=()=>{const{t}=Ae(),[s,a]=n.useState(new Set(["quick-start"])),r=o=>{const l=new Set(s);l.has(o)?l.delete(o):l.add(o),a(l)};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.jsx("h1",{className:"text-4xl font-bold text-[var(--fg-primary)] mb-4",children:t("help.pageTitle")}),e.jsx("p",{className:"text-[var(--fg-secondary)] text-lg max-w-3xl mx-auto text-center",children:t("help.subtitle")}),e.jsx("p",{className:"text-[var(--fg-muted)] text-sm mt-2",children:t("help.techSpecs")}),e.jsxs("div",{className:"mt-6 flex gap-3 justify-center text-sm",children:[e.jsxs("a",{href:"https://github.com/GxFn/AutoSnippet",target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center gap-2 px-5 py-2.5 bg-[var(--bg-subtle)] border border-[var(--border-default)] text-[var(--fg-primary)] rounded-full hover:bg-[var(--bg-muted)] transition-colors",children:[e.jsx(ul,{size:H.sm}),t("help.viewGithub")]}),e.jsxs("a",{href:"https://docs.gaoxuefeng.com/part1/ch01-introduction.html",target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center gap-2 px-5 py-2.5 bg-blue-600 text-white rounded-full hover:bg-blue-700 transition-colors",children:[e.jsx(qe,{size:H.sm}),t("help.fullDocs"),e.jsx(wr,{size:12})]})]})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsx(gt,{id:"token-usage",title:t("help.tokenUsageLast7Days"),icon:e.jsx(Tt,{size:H.xl,className:"text-blue-600"}),isExpanded:s.has("token-usage"),onToggle:r,children:e.jsx(Di,{})}),e.jsx(gt,{id:"quick-start",title:t("help.quickStart"),icon:e.jsx(Kt,{size:H.xl,className:"text-blue-600"}),isExpanded:s.has("quick-start"),onToggle:r,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-[var(--fg-primary)] mb-2",children:t("help.step1Title")}),e.jsx("pre",{className:"bg-blue-100/70 text-blue-900 px-3 py-2 rounded text-xs overflow-x-auto whitespace-pre-wrap break-all",children:e.jsxs("code",{children:["npm install -g autosnippet",`
76
76
  `,"cd your-project",`
77
77
  `,"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-[var(--fg-primary)] mb-2",children:t("help.step2Title")}),e.jsx("pre",{className:"bg-green-100/70 text-green-900 px-3 py-2 rounded text-xs overflow-x-auto whitespace-pre-wrap break-all",children:e.jsx("code",{children:"asd ui"})}),e.jsx("p",{className:"text-[var(--fg-secondary)] text-xs mt-2",children:t("help.step2Desc")})]}),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-[var(--fg-primary)] mb-2",children:t("help.step3Title")}),e.jsx("pre",{className:"bg-purple-100/70 text-purple-900 px-3 py-2 rounded text-xs overflow-x-auto whitespace-pre-wrap break-all",children:e.jsx("code",{children:"asd upgrade"})}),e.jsx("p",{className:"text-[var(--fg-secondary)] text-xs mt-2",children:t("help.step3Desc")})]}),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-[var(--fg-primary)] mb-2",children:t("help.step4Title")}),e.jsx("pre",{className:"bg-amber-100/70 text-amber-900 px-3 py-2 rounded text-xs overflow-x-auto whitespace-pre-wrap break-all mb-2",children:e.jsx("code",{children:"asd coldstart"})}),e.jsx("p",{className:"text-[var(--fg-secondary)] text-xs",children:t("help.step4Desc1")}),e.jsx("p",{className:"text-[var(--fg-secondary)] text-xs",children:t("help.step4Desc2")})]})]})}),e.jsxs(gt,{id:"concepts",title:t("help.coreConcepts"),icon:e.jsx(Gs,{size:H.xl,className:"text-blue-600"}),isExpanded:s.has("concepts"),onToggle:r,children:[e.jsxs("div",{className:"mb-6",children:[e.jsx("h3",{className:"text-lg font-semibold text-[var(--fg-primary)] mb-3",children:t("help.threeRoles")}),e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"min-w-full border border-[var(--border-default)] rounded-lg text-sm",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"bg-[var(--bg-subtle)]",children:[e.jsx("th",{className:"px-4 py-3 border-b text-left font-semibold",children:t("help.roleColumn")}),e.jsx("th",{className:"px-4 py-3 border-b text-left font-semibold",children:t("help.responsibilityColumn")}),e.jsx("th",{className:"px-4 py-3 border-b text-left font-semibold",children:t("help.capabilityColumn")})]})}),e.jsxs("tbody",{children:[e.jsxs("tr",{className:"hover:bg-[var(--bg-subtle)]",children:[e.jsx("td",{className:"px-4 py-3 border-b font-medium text-blue-700",children:t("help.roleDeveloper")}),e.jsx("td",{className:"px-4 py-3 border-b",children:t("help.developerResp")}),e.jsx("td",{className:"px-4 py-3 border-b text-xs",dangerouslySetInnerHTML:{__html:t("help.developerCap")}})]}),e.jsxs("tr",{className:"hover:bg-[var(--bg-subtle)]",children:[e.jsx("td",{className:"px-4 py-3 border-b font-medium text-green-700",children:t("help.roleCursorAgent")}),e.jsx("td",{className:"px-4 py-3 border-b",children:t("help.cursorAgentResp")}),e.jsx("td",{className:"px-4 py-3 border-b text-xs",dangerouslySetInnerHTML:{__html:t("help.cursorAgentCap")}})]}),e.jsxs("tr",{className:"hover:bg-[var(--bg-subtle)]",children:[e.jsx("td",{className:"px-4 py-3 font-medium text-purple-700",children:t("help.roleChatAgent")}),e.jsx("td",{className:"px-4 py-3",children:t("help.chatAgentResp")}),e.jsx("td",{className:"px-4 py-3 text-xs",dangerouslySetInnerHTML:{__html:t("help.chatAgentCap")}})]})]})]})})]}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-semibold text-[var(--fg-primary)] mb-3",children:t("help.coreComponents")}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4 [&_li]:break-words",children:[e.jsxs("div",{className:"bg-green-50 rounded-lg p-4 border border-green-200",children:[e.jsxs("h4",{className:"font-semibold text-green-900 mb-2 flex items-center gap-2",children:[e.jsx(Be,{size:H.lg}),t("help.bootstrapLabel")]}),e.jsx("p",{className:"text-green-800 text-sm mb-3",children:t("help.bootstrapDesc")}),e.jsxs("ul",{className:"text-green-700 text-xs space-y-1 list-disc list-inside",children:[e.jsx("li",{dangerouslySetInnerHTML:{__html:t("help.bootstrapBullet1")}}),e.jsx("li",{dangerouslySetInnerHTML:{__html:t("help.bootstrapBullet2")}}),e.jsx("li",{dangerouslySetInnerHTML:{__html:t("help.bootstrapBullet3")}})]})]}),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(ml,{size:H.lg}),t("help.candidatesLabel")]}),e.jsx("p",{className:"text-purple-800 text-sm mb-3",children:t("help.candidatesDesc")}),e.jsxs("ul",{className:"text-purple-700 text-xs space-y-1 list-disc list-inside",children:[e.jsx("li",{dangerouslySetInnerHTML:{__html:t("help.candidatesBullet1")}}),e.jsx("li",{dangerouslySetInnerHTML:{__html:t("help.candidatesBullet2")}}),e.jsx("li",{dangerouslySetInnerHTML:{__html:t("help.candidatesBullet3")}})]})]}),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(pt,{size:H.lg}),t("help.recipeLabel")]}),e.jsx("p",{className:"text-blue-800 text-sm mb-3",children:t("help.recipeDesc")}),e.jsxs("ul",{className:"text-blue-700 text-xs space-y-1 list-disc list-inside",children:[e.jsx("li",{dangerouslySetInnerHTML:{__html:t("help.recipeBullet1")}}),e.jsx("li",{dangerouslySetInnerHTML:{__html:t("help.recipeBullet2")}}),e.jsx("li",{dangerouslySetInnerHTML:{__html:t("help.recipeBullet3")}})]})]}),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(ga,{size:H.lg}),t("help.chatAgentLabel")]}),e.jsx("p",{className:"text-indigo-800 text-sm mb-3",children:t("help.chatAgentDesc")}),e.jsxs("ul",{className:"text-indigo-700 text-xs space-y-1 list-disc list-inside",children:[e.jsx("li",{dangerouslySetInnerHTML:{__html:t("help.chatAgentCompBullet1")}}),e.jsx("li",{dangerouslySetInnerHTML:{__html:t("help.chatAgentCompBullet2")}}),e.jsx("li",{dangerouslySetInnerHTML:{__html:t("help.chatAgentCompBullet3")}})]})]}),e.jsxs("div",{className:"bg-amber-50 rounded-lg p-4 border border-amber-200",children:[e.jsxs("h4",{className:"font-semibold text-amber-900 mb-2 flex items-center gap-2",children:[e.jsx(xt,{size:H.lg}),t("help.searchPipelineLabel")]}),e.jsx("p",{className:"text-amber-800 text-sm mb-3",children:t("help.searchPipelineDesc")}),e.jsxs("ul",{className:"text-amber-700 text-xs space-y-1 list-disc list-inside",children:[e.jsx("li",{dangerouslySetInnerHTML:{__html:t("help.searchPipelineBullet1")}}),e.jsx("li",{dangerouslySetInnerHTML:{__html:t("help.searchPipelineBullet2")}}),e.jsx("li",{dangerouslySetInnerHTML:{__html:t("help.searchPipelineBullet3")}})]})]}),e.jsxs("div",{className:"bg-cyan-50 rounded-lg p-4 border border-cyan-200",children:[e.jsxs("h4",{className:"font-semibold text-cyan-900 mb-2 flex items-center gap-2",children:[e.jsx(ha,{size:H.lg}),t("help.taskGraphLabel")]}),e.jsx("p",{className:"text-cyan-800 text-sm mb-3",children:t("help.taskGraphDesc")}),e.jsxs("ul",{className:"text-cyan-700 text-xs space-y-1 list-disc list-inside",children:[e.jsx("li",{dangerouslySetInnerHTML:{__html:t("help.taskGraphBullet1")}}),e.jsx("li",{dangerouslySetInnerHTML:{__html:t("help.taskGraphBullet2")}}),e.jsx("li",{dangerouslySetInnerHTML:{__html:t("help.taskGraphBullet3")}})]})]}),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:H.lg}),t("help.guardLabel")]}),e.jsx("p",{className:"text-rose-800 text-sm mb-3",children:t("help.guardDesc")}),e.jsxs("ul",{className:"text-rose-700 text-xs space-y-1 list-disc list-inside",children:[e.jsx("li",{dangerouslySetInnerHTML:{__html:t("help.guardCompBullet1")}}),e.jsx("li",{dangerouslySetInnerHTML:{__html:t("help.guardCompBullet2")}}),e.jsx("li",{dangerouslySetInnerHTML:{__html:t("help.guardCompBullet3")}})]})]}),e.jsxs("div",{className:"bg-teal-50 rounded-lg p-4 border border-teal-200",children:[e.jsxs("h4",{className:"font-semibold text-teal-900 mb-2 flex items-center gap-2",children:[e.jsx(ba,{size:H.lg}),t("help.ideIntegrationLabel")]}),e.jsx("p",{className:"text-teal-800 text-sm mb-3",children:t("help.ideIntegrationDesc")}),e.jsxs("ul",{className:"text-teal-700 text-xs space-y-1 list-disc list-inside",children:[e.jsx("li",{dangerouslySetInnerHTML:{__html:t("help.ideIntegrationBullet1")}}),e.jsx("li",{dangerouslySetInnerHTML:{__html:t("help.ideIntegrationBullet2")}}),e.jsx("li",{dangerouslySetInnerHTML:{__html:t("help.ideIntegrationBullet3")}})]})]}),e.jsxs("div",{className:"bg-orange-50 rounded-lg p-4 border border-orange-200",children:[e.jsxs("h4",{className:"font-semibold text-orange-900 mb-2 flex items-center gap-2",children:[e.jsx(gr,{size:H.lg}),t("help.securityLabel")]}),e.jsx("p",{className:"text-orange-800 text-sm mb-3",children:t("help.securityDesc")}),e.jsxs("ul",{className:"text-orange-700 text-xs space-y-1 list-disc list-inside",children:[e.jsx("li",{dangerouslySetInnerHTML:{__html:t("help.securityBullet1")}}),e.jsx("li",{dangerouslySetInnerHTML:{__html:t("help.securityBullet2")}}),e.jsx("li",{dangerouslySetInnerHTML:{__html:t("help.securityBullet3")}})]})]})]})]}),e.jsxs("div",{className:"mt-6 mb-6 p-4 bg-[var(--bg-subtle)] rounded-lg border border-[var(--border-default)]",children:[e.jsx("h3",{className:"text-lg font-semibold text-[var(--fg-primary)] mb-3",children:t("help.archOverviewLabel")}),e.jsxs("div",{className:"flex items-center justify-between gap-1 text-xs overflow-x-auto pb-2",children:[e.jsx("div",{className:"bg-indigo-100 text-indigo-700 px-3 py-2 rounded-lg font-medium text-center shrink-0",children:t("help.archOverviewBootstrap")}),e.jsx("span",{className:"text-[var(--fg-muted)] shrink-0",children:"→"}),e.jsx("div",{className:"bg-blue-100 text-blue-700 px-3 py-2 rounded-lg font-medium text-center shrink-0",children:t("help.archOverviewKB")}),e.jsx("span",{className:"text-[var(--fg-muted)] shrink-0",children:"→"}),e.jsx("div",{className:"bg-blue-100 text-blue-700 px-3 py-2 rounded-lg font-medium text-center shrink-0",children:t("help.archOverviewPipeline")}),e.jsx("span",{className:"text-[var(--fg-muted)] shrink-0",children:"→"}),e.jsx("div",{className:"bg-emerald-100 text-emerald-700 px-3 py-2 rounded-lg font-medium text-center shrink-0",children:t("help.archOverviewAgent")}),e.jsx("span",{className:"text-[var(--fg-muted)] shrink-0",children:"→"}),e.jsx("div",{className:"bg-amber-100 text-amber-700 px-3 py-2 rounded-lg font-medium text-center shrink-0",children:t("help.archOverviewTask")}),e.jsx("span",{className:"text-[var(--fg-muted)] shrink-0",children:"→"}),e.jsx("div",{className:"bg-emerald-100 text-emerald-700 px-3 py-2 rounded-lg font-medium text-center shrink-0",children:t("help.archOverviewOutput")})]}),e.jsxs("div",{className:"mt-2 flex items-center justify-center gap-3 text-xs",children:[e.jsxs("span",{className:"bg-rose-100 text-rose-700 px-3 py-1.5 rounded-lg font-medium",children:["↕ ",t("help.archOverviewSecurity")," ↕"]}),e.jsxs("span",{className:"bg-teal-100 text-teal-700 px-3 py-1.5 rounded-lg font-medium",children:["↕ ",t("help.archOverviewIDE")," ↕"]})]})]}),e.jsxs("div",{className:"mt-6 rounded-lg p-5 border border-[var(--border-default)] bg-[var(--bg-subtle)]",children:[e.jsx("h3",{className:"text-lg font-semibold text-[var(--fg-primary)] mb-5",children:t("help.knowledgeLoop")}),e.jsx("div",{className:"flex items-start justify-between gap-0 overflow-x-auto pb-2",children:[{step:1,color:"blue",key:"loopStep1",subKey:"loopStep1Sub"},{step:2,color:"green",key:"loopStep2",subKey:"loopStep2Sub"},{step:3,color:"purple",key:"loopStep3",subKey:"loopStep3Sub"},{step:4,color:"amber",key:"loopStep4",subKey:"loopStep4Sub"},{step:5,color:"rose",key:"loopStep5",subKey:"loopStep5Sub"}].map((o,l)=>e.jsxs(it.Fragment,{children:[e.jsxs("div",{className:"flex-1 min-w-[90px] flex flex-col items-center text-center",children:[e.jsx("div",{className:`w-11 h-11 rounded-full flex items-center justify-center font-bold text-lg text-white shadow-md mb-2.5 bg-${o.color}-500`,children:o.step}),e.jsx("p",{className:"text-[var(--fg-primary)] font-semibold text-sm leading-tight",children:t(`help.${o.key}`)}),e.jsx("p",{className:"text-[var(--fg-muted)] text-xs mt-1 font-mono",children:t(`help.${o.subKey}`)})]}),l<4&&e.jsxs("div",{className:"flex items-center pt-3 px-1 shrink-0",children:[e.jsx("div",{className:"w-6 h-px bg-[var(--border-default)]"}),e.jsx("span",{className:"text-[var(--fg-muted)] text-xs mx-0.5",children:"›"}),e.jsx("div",{className:"w-6 h-px bg-[var(--border-default)]"})]})]},o.step))}),e.jsx("div",{className:"mt-4 flex items-center justify-center",children:e.jsxs("div",{className:"flex items-center gap-2 text-xs text-[var(--fg-muted)]",children:[e.jsx("span",{className:"inline-block w-8 h-px bg-rose-400/50"}),e.jsx("span",{className:"italic",children:t("help.loopStep5")}),e.jsx("span",{children:"→"}),e.jsx("span",{className:"italic",children:t("help.loopStep1")}),e.jsx("span",{className:"inline-block w-8 h-px bg-blue-400/50"})]})})]})]}),e.jsxs(gt,{id:"agent-arch",title:t("help.agentArchTitle"),icon:e.jsx(Mt,{size:H.xl,className:"text-blue-600"}),isExpanded:s.has("agent-arch"),onToggle:r,children:[e.jsx("p",{className:"text-[var(--fg-secondary)] text-sm mb-5",children:t("help.agentArchDesc")}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-5",children:[e.jsxs("div",{className:"border border-[var(--border-default)] rounded-lg p-5 hover:shadow-lg transition-shadow",children:[e.jsxs("div",{className:"flex items-center gap-3 mb-2",children:[e.jsx("div",{className:"w-9 h-9 rounded-lg bg-indigo-100 flex items-center justify-center shrink-0",children:e.jsx(Ge,{size:H.lg,className:"text-indigo-600"})}),e.jsx("h3",{className:"font-semibold text-[var(--fg-primary)]",children:t("help.agentArchPresetTitle")})]}),e.jsx("p",{className:"text-[var(--fg-secondary)] text-xs mb-3",children:t("help.agentArchPresetDesc")}),e.jsxs("ul",{className:"text-[var(--fg-secondary)] text-sm space-y-2 list-disc list-inside",children:[e.jsx("li",{dangerouslySetInnerHTML:{__html:t("help.agentArchPresetChat")}}),e.jsx("li",{dangerouslySetInnerHTML:{__html:t("help.agentArchPresetInsight")}}),e.jsx("li",{dangerouslySetInnerHTML:{__html:t("help.agentArchPresetLark")}}),e.jsx("li",{dangerouslySetInnerHTML:{__html:t("help.agentArchPresetRemoteExec")}})]})]}),e.jsxs("div",{className:"border border-[var(--border-default)] rounded-lg p-5 hover:shadow-lg transition-shadow",children:[e.jsxs("div",{className:"flex items-center gap-3 mb-2",children:[e.jsx("div",{className:"w-9 h-9 rounded-lg bg-emerald-100 flex items-center justify-center shrink-0",children:e.jsx(Wt,{size:H.lg,className:"text-emerald-600"})}),e.jsx("h3",{className:"font-semibold text-[var(--fg-primary)]",children:t("help.agentArchStrategyTitle")})]}),e.jsx("p",{className:"text-[var(--fg-secondary)] text-xs mb-3",children:t("help.agentArchStrategyDesc")}),e.jsxs("ul",{className:"text-[var(--fg-secondary)] text-sm space-y-2 list-disc list-inside",children:[e.jsx("li",{dangerouslySetInnerHTML:{__html:t("help.agentArchStrategySingle")}}),e.jsx("li",{dangerouslySetInnerHTML:{__html:t("help.agentArchStrategyPipeline")}}),e.jsx("li",{dangerouslySetInnerHTML:{__html:t("help.agentArchStrategyFanOut")}}),e.jsx("li",{dangerouslySetInnerHTML:{__html:t("help.agentArchStrategyAdaptive")}})]})]}),e.jsxs("div",{className:"border border-[var(--border-default)] rounded-lg p-5 hover:shadow-lg transition-shadow",children:[e.jsxs("div",{className:"flex items-center gap-3 mb-2",children:[e.jsx("div",{className:"w-9 h-9 rounded-lg bg-blue-100 flex items-center justify-center shrink-0",children:e.jsx(Be,{size:H.lg,className:"text-blue-600"})}),e.jsx("h3",{className:"font-semibold text-[var(--fg-primary)]",children:t("help.agentArchCapTitle")})]}),e.jsx("p",{className:"text-[var(--fg-secondary)] text-xs mb-3",children:t("help.agentArchCapDesc")}),e.jsxs("ul",{className:"text-[var(--fg-secondary)] text-sm space-y-2 list-disc list-inside",children:[e.jsx("li",{dangerouslySetInnerHTML:{__html:t("help.agentArchCapConversation")}}),e.jsx("li",{dangerouslySetInnerHTML:{__html:t("help.agentArchCapCodeAnalysis")}}),e.jsx("li",{dangerouslySetInnerHTML:{__html:t("help.agentArchCapKnowledgeProd")}}),e.jsx("li",{dangerouslySetInnerHTML:{__html:t("help.agentArchCapScanProd")}}),e.jsx("li",{dangerouslySetInnerHTML:{__html:t("help.agentArchCapSystem")}})]})]}),e.jsxs("div",{className:"border border-[var(--border-default)] rounded-lg p-5 hover:shadow-lg transition-shadow",children:[e.jsxs("div",{className:"flex items-center gap-3 mb-2",children:[e.jsx("div",{className:"w-9 h-9 rounded-lg bg-purple-100 flex items-center justify-center shrink-0",children:e.jsx(Gs,{size:H.lg,className:"text-purple-600"})}),e.jsx("h3",{className:"font-semibold text-[var(--fg-primary)]",children:t("help.agentArchMemoryTitle")})]}),e.jsx("p",{className:"text-[var(--fg-secondary)] text-xs mb-3",children:t("help.agentArchMemoryDesc")}),e.jsxs("ul",{className:"text-[var(--fg-secondary)] text-sm space-y-2 list-disc list-inside",children:[e.jsx("li",{dangerouslySetInnerHTML:{__html:t("help.agentArchMemoryWorking")}}),e.jsx("li",{dangerouslySetInnerHTML:{__html:t("help.agentArchMemorySession")}}),e.jsx("li",{dangerouslySetInnerHTML:{__html:t("help.agentArchMemoryPersistent")}})]})]}),e.jsxs("div",{className:"border border-[var(--border-default)] rounded-lg p-5 hover:shadow-lg transition-shadow",children:[e.jsxs("div",{className:"flex items-center gap-3 mb-2",children:[e.jsx("div",{className:"w-9 h-9 rounded-lg bg-amber-100 flex items-center justify-center shrink-0",children:e.jsx(ga,{size:H.lg,className:"text-amber-600"})}),e.jsx("h3",{className:"font-semibold text-[var(--fg-primary)]",children:t("help.agentArchContextTitle")})]}),e.jsx("p",{className:"text-[var(--fg-secondary)] text-xs mb-3",children:t("help.agentArchContextDesc")}),e.jsxs("ul",{className:"text-[var(--fg-secondary)] text-sm space-y-2 list-disc list-inside",children:[e.jsx("li",{dangerouslySetInnerHTML:{__html:t("help.agentArchContextWindow")}}),e.jsx("li",{dangerouslySetInnerHTML:{__html:t("help.agentArchContextTracker")}})]})]}),e.jsxs("div",{className:"border border-[var(--border-default)] rounded-lg p-5 hover:shadow-lg transition-shadow",children:[e.jsxs("div",{className:"flex items-center gap-3 mb-2",children:[e.jsx("div",{className:"w-9 h-9 rounded-lg bg-rose-100 flex items-center justify-center shrink-0",children:e.jsx(Rs,{size:H.lg,className:"text-rose-600"})}),e.jsx("h3",{className:"font-semibold text-[var(--fg-primary)]",children:t("help.agentArchToolsTitle")})]}),e.jsx("p",{className:"text-[var(--fg-secondary)] text-xs mb-3",children:t("help.agentArchToolsDesc")}),e.jsxs("ul",{className:"text-[var(--fg-secondary)] text-sm space-y-2 list-disc list-inside",children:[e.jsx("li",{dangerouslySetInnerHTML:{__html:t("help.agentArchToolsInternal")}}),e.jsx("li",{dangerouslySetInnerHTML:{__html:t("help.agentArchToolsMcp")}})]}),e.jsxs("div",{className:"mt-3 pt-3 border-t border-[var(--border-default)]",children:[e.jsx("p",{className:"text-xs font-semibold text-[var(--fg-primary)] mb-1",children:t("help.agentArchRouterTitle")}),e.jsx("p",{className:"text-xs text-[var(--fg-secondary)]",children:t("help.agentArchRouterDesc")})]})]})]})]}),e.jsxs(gt,{id:"features",title:t("help.coreFeatures"),icon:e.jsx(Be,{size:H.xl,className:"text-blue-600"}),isExpanded:s.has("features"),onToggle:r,children:[e.jsx("p",{className:"text-[var(--fg-secondary)] text-sm mb-5",children:t("help.coreFeaturesDesc")}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-5",children:[e.jsxs("div",{className:"border border-[var(--border-default)] rounded-lg p-5 hover:shadow-lg transition-shadow",children:[e.jsxs("div",{className:"flex items-center gap-3 mb-2",children:[e.jsx("div",{className:"w-9 h-9 rounded-lg bg-blue-100 flex items-center justify-center shrink-0",children:e.jsx(Nr,{size:H.lg,className:"text-blue-600"})}),e.jsx("h3",{className:"font-semibold text-[var(--fg-primary)]",children:t("help.knowledgeBuild")})]}),e.jsx("p",{className:"text-[var(--fg-secondary)] text-xs mb-3",children:t("help.kbBuildDesc")}),e.jsxs("ul",{className:"text-[var(--fg-secondary)] text-sm space-y-2 list-disc list-inside",children:[e.jsx("li",{dangerouslySetInnerHTML:{__html:t("help.kbBuildBullet1")}}),e.jsx("li",{dangerouslySetInnerHTML:{__html:t("help.kbBuildBullet2")}}),e.jsx("li",{dangerouslySetInnerHTML:{__html:t("help.kbBuildBullet3")}}),e.jsx("li",{dangerouslySetInnerHTML:{__html:t("help.kbBuildBullet4")}})]})]}),e.jsxs("div",{className:"border border-[var(--border-default)] rounded-lg p-5 hover:shadow-lg transition-shadow",children:[e.jsxs("div",{className:"flex items-center gap-3 mb-2",children:[e.jsx("div",{className:"w-9 h-9 rounded-lg bg-emerald-100 flex items-center justify-center shrink-0",children:e.jsx(xt,{size:H.lg,className:"text-emerald-600"})}),e.jsx("h3",{className:"font-semibold text-[var(--fg-primary)]",children:t("help.semanticSearchLabel")})]}),e.jsx("p",{className:"text-[var(--fg-secondary)] text-xs mb-3",children:t("help.semSearchDescShort")}),e.jsxs("ul",{className:"text-[var(--fg-secondary)] text-sm space-y-2 list-disc list-inside",children:[e.jsx("li",{dangerouslySetInnerHTML:{__html:t("help.semSearchBullet1")}}),e.jsx("li",{dangerouslySetInnerHTML:{__html:t("help.semSearchBullet2")}}),e.jsx("li",{dangerouslySetInnerHTML:{__html:t("help.semSearchBullet3")}}),e.jsx("li",{dangerouslySetInnerHTML:{__html:t("help.semSearchBullet4")}})]})]}),e.jsxs("div",{className:"border border-[var(--border-default)] rounded-lg p-5 hover:shadow-lg transition-shadow",children:[e.jsxs("div",{className:"flex items-center gap-3 mb-2",children:[e.jsx("div",{className:"w-9 h-9 rounded-lg bg-purple-100 flex items-center justify-center shrink-0",children:e.jsx(Ve,{size:H.lg,className:"text-purple-600"})}),e.jsx("h3",{className:"font-semibold text-[var(--fg-primary)]",children:t("help.guardCompliance")})]}),e.jsx("p",{className:"text-[var(--fg-secondary)] text-xs mb-3",children:t("help.guardComplianceDesc")}),e.jsxs("ul",{className:"text-[var(--fg-secondary)] text-sm space-y-2 list-disc list-inside",children:[e.jsx("li",{dangerouslySetInnerHTML:{__html:t("help.auditFeatureBullet1")}}),e.jsx("li",{dangerouslySetInnerHTML:{__html:t("help.auditFeatureBullet2")}}),e.jsx("li",{dangerouslySetInnerHTML:{__html:t("help.auditFeatureBullet3")}}),e.jsx("li",{dangerouslySetInnerHTML:{__html:t("help.auditFeatureBullet4")}})]})]}),e.jsxs("div",{className:"border border-[var(--border-default)] rounded-lg p-5 hover:shadow-lg transition-shadow",children:[e.jsxs("div",{className:"flex items-center gap-3 mb-2",children:[e.jsx("div",{className:"w-9 h-9 rounded-lg bg-amber-100 flex items-center justify-center shrink-0",children:e.jsx(ha,{size:H.lg,className:"text-amber-600"})}),e.jsx("h3",{className:"font-semibold text-[var(--fg-primary)]",children:t("help.featureTaskGraphTitle")})]}),e.jsx("p",{className:"text-[var(--fg-secondary)] text-xs mb-3",children:t("help.featureTaskGraphDesc")}),e.jsxs("ul",{className:"text-[var(--fg-secondary)] text-sm space-y-2 list-disc list-inside",children:[e.jsx("li",{dangerouslySetInnerHTML:{__html:t("help.featureTaskGraphBullet1")}}),e.jsx("li",{dangerouslySetInnerHTML:{__html:t("help.featureTaskGraphBullet2")}}),e.jsx("li",{dangerouslySetInnerHTML:{__html:t("help.featureTaskGraphBullet3")}}),e.jsx("li",{dangerouslySetInnerHTML:{__html:t("help.featureTaskGraphBullet4")}})]})]}),e.jsxs("div",{className:"border border-[var(--border-default)] rounded-lg p-5 hover:shadow-lg transition-shadow",children:[e.jsxs("div",{className:"flex items-center gap-3 mb-2",children:[e.jsx("div",{className:"w-9 h-9 rounded-lg bg-rose-100 flex items-center justify-center shrink-0",children:e.jsx(pt,{size:H.lg,className:"text-rose-600"})}),e.jsx("h3",{className:"font-semibold text-[var(--fg-primary)]",children:t("help.wikiDocGen")})]}),e.jsx("p",{className:"text-[var(--fg-secondary)] text-xs mb-3",children:t("help.wikiDocGenDesc")}),e.jsxs("ul",{className:"text-[var(--fg-secondary)] text-sm space-y-2 list-disc list-inside",children:[e.jsx("li",{dangerouslySetInnerHTML:{__html:t("help.wikiDocBullet1")}}),e.jsx("li",{dangerouslySetInnerHTML:{__html:t("help.wikiDocBullet2")}}),e.jsx("li",{dangerouslySetInnerHTML:{__html:t("help.wikiDocBullet3")}}),e.jsx("li",{dangerouslySetInnerHTML:{__html:t("help.wikiDocBullet4")}})]})]}),e.jsxs("div",{className:"border border-[var(--border-default)] rounded-lg p-5 hover:shadow-lg transition-shadow",children:[e.jsxs("div",{className:"flex items-center gap-3 mb-2",children:[e.jsx("div",{className:"w-9 h-9 rounded-lg bg-teal-100 flex items-center justify-center shrink-0",children:e.jsx(at,{size:H.lg,className:"text-teal-600"})}),e.jsx("h3",{className:"font-semibold text-[var(--fg-primary)]",children:t("help.dataSync")})]}),e.jsx("p",{className:"text-[var(--fg-secondary)] text-xs mb-3",children:t("help.syncDescShort")}),e.jsxs("ul",{className:"text-[var(--fg-secondary)] text-sm space-y-2 list-disc list-inside",children:[e.jsx("li",{dangerouslySetInnerHTML:{__html:t("help.syncBullet1")}}),e.jsx("li",{dangerouslySetInnerHTML:{__html:t("help.syncBullet2")}}),e.jsx("li",{dangerouslySetInnerHTML:{__html:t("help.syncBullet3")}}),e.jsx("li",{dangerouslySetInnerHTML:{__html:t("help.syncBullet4")}})]})]})]})]}),e.jsxs(gt,{id:"editor-directives",title:t("help.editorDirectives"),icon:e.jsx(Rs,{size:H.xl,className:"text-blue-600"}),isExpanded:s.has("editor-directives"),onToggle:r,children:[e.jsx("p",{className:"text-[var(--fg-secondary)] text-sm mb-4",children:t("help.editorDirectivesNote")}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"bg-[var(--bg-subtle)] rounded-lg p-4 border border-[var(--border-default)]",children:[e.jsxs("h4",{className:"font-semibold text-[var(--fg-primary)] mb-2",children:[e.jsx("code",{className:"bg-slate-200 px-2 py-1 rounded",children:"// as:create"})," · ",e.jsx("code",{className:"bg-slate-200 px-2 py-1 rounded",children:"asc"})]}),e.jsx("p",{className:"text-[var(--fg-secondary)] text-sm mb-2",children:t("help.createDirective")}),e.jsxs("ul",{className:"text-[var(--fg-secondary)] text-xs space-y-1 list-disc list-inside",children:[e.jsx("li",{children:t("help.createDirBullet1")}),e.jsx("li",{dangerouslySetInnerHTML:{__html:t("help.createDirBullet2")}}),e.jsx("li",{dangerouslySetInnerHTML:{__html:t("help.createDirBullet3")}})]})]}),e.jsxs("div",{className:"bg-[var(--bg-subtle)] rounded-lg p-4 border border-[var(--border-default)]",children:[e.jsxs("h4",{className:"font-semibold text-[var(--fg-primary)] mb-2",children:[e.jsx("code",{className:"bg-slate-200 px-2 py-1 rounded",children:"// as:search"})," · ",e.jsx("code",{className:"bg-slate-200 px-2 py-1 rounded",children:"ass"})]}),e.jsx("p",{className:"text-[var(--fg-secondary)] text-sm mb-2",children:t("help.searchDirective")}),e.jsxs("ul",{className:"text-[var(--fg-secondary)] text-xs space-y-1 list-disc list-inside",children:[e.jsx("li",{children:t("help.searchDirBullet1")}),e.jsx("li",{children:t("help.searchDirBullet2")}),e.jsx("li",{children:t("help.searchDirBullet3")})]})]}),e.jsxs("div",{className:"bg-[var(--bg-subtle)] rounded-lg p-4 border border-[var(--border-default)]",children:[e.jsxs("h4",{className:"font-semibold text-[var(--fg-primary)] mb-2",children:[e.jsx("code",{className:"bg-slate-200 px-2 py-1 rounded",children:"// as:audit"})," · ",e.jsx("code",{className:"bg-slate-200 px-2 py-1 rounded",children:"asa"})]}),e.jsx("p",{className:"text-[var(--fg-secondary)] text-sm mb-2",children:t("help.auditDirective")}),e.jsxs("ul",{className:"text-[var(--fg-secondary)] text-xs space-y-1 list-disc list-inside",children:[e.jsx("li",{children:t("help.auditDirBullet1")}),e.jsx("li",{dangerouslySetInnerHTML:{__html:t("help.auditDirBullet2")}}),e.jsx("li",{dangerouslySetInnerHTML:{__html:t("help.auditDirBullet3")}})]})]}),e.jsxs("div",{className:"bg-[var(--bg-subtle)] rounded-lg p-4 border border-[var(--border-default)]",children:[e.jsxs("h4",{className:"font-semibold text-[var(--fg-primary)] 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-[var(--fg-secondary)] text-sm mb-2",children:t("help.includeDirective")}),e.jsxs("ul",{className:"text-[var(--fg-secondary)] text-xs space-y-1 list-disc list-inside",children:[e.jsx("li",{children:t("help.includeDirBullet1")}),e.jsx("li",{children:t("help.includeDirBullet2")})]})]})]})]}),e.jsxs(gt,{id:"cursor-integration",title:t("help.cursorIntegration"),icon:e.jsx(ut,{size:H.xl,className:"text-blue-600"}),isExpanded:s.has("cursor-integration"),onToggle:r,children:[e.jsxs("div",{className:"mb-5",children:[e.jsx("h3",{className:"font-semibold text-[var(--fg-primary)] mb-3",children:t("help.skills10")}),e.jsx("div",{className:"grid grid-cols-2 md:grid-cols-5 gap-2",children:[{name:"intent",descKey:"help.skillIntent"},{name:"concepts",descKey:"help.skillConcepts"},{name:"candidates",descKey:"help.skillCandidates"},{name:"recipes",descKey:"help.skillRecipes"},{name:"guard",descKey:"help.skillGuard"},{name:"structure",descKey:"help.skillStructure"},{name:"analysis",descKey:"help.skillAnalysis"},{name:"coldstart",descKey:"help.skillColdstart"},{name:"create",descKey:"help.skillCreate"},{name:"lifecycle",descKey:"help.skillLifecycle"},{name:"devdocs",descKey:"help.skillDevdocs"}].map(o=>e.jsxs("div",{className:"bg-[var(--bg-subtle)] border border-[var(--border-default)] rounded-lg px-3 py-2 text-center",children:[e.jsx("p",{className:"text-xs font-mono text-blue-600",children:o.name}),e.jsx("p",{className:"text-xs text-[var(--fg-secondary)] mt-0.5",children:t(o.descKey)})]},o.name))})]}),e.jsxs("div",{className:"mb-5",children:[e.jsx("h3",{className:"font-semibold text-[var(--fg-primary)] mb-3",children:t("help.mcp16")}),e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"min-w-full border border-[var(--border-default)] rounded-lg text-xs",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"bg-[var(--bg-subtle)]",children:[e.jsx("th",{className:"px-3 py-2 border-b text-left",children:t("help.mcpLayerHeader")}),e.jsx("th",{className:"px-3 py-2 border-b text-left",children:t("help.mcpToolHeader")}),e.jsx("th",{className:"px-3 py-2 border-b text-left",children:t("help.mcpDescHeader")})]})}),e.jsxs("tbody",{children:[e.jsx("tr",{className:"bg-blue-50/30",children:e.jsx("td",{colSpan:3,className:"px-3 py-1.5 border-b font-semibold text-blue-700 text-xs",children:t("help.mcpAgentLayerHeader")})}),e.jsxs("tr",{children:[e.jsx("td",{className:"px-3 py-2 border-b font-medium",children:"agent"}),e.jsx("td",{className:"px-3 py-2 border-b",children:e.jsx("code",{children:"health"})}),e.jsx("td",{className:"px-3 py-2 border-b",children:t("help.mcpHealthDesc")})]}),e.jsxs("tr",{children:[e.jsx("td",{className:"px-3 py-2 border-b font-medium",children:"agent"}),e.jsx("td",{className:"px-3 py-2 border-b",children:e.jsx("code",{children:"capabilities"})}),e.jsx("td",{className:"px-3 py-2 border-b",children:t("help.mcpCapabilitiesDesc")})]}),e.jsxs("tr",{children:[e.jsx("td",{className:"px-3 py-2 border-b font-medium",children:"agent"}),e.jsx("td",{className:"px-3 py-2 border-b",children:e.jsx("code",{children:"search"})}),e.jsx("td",{className:"px-3 py-2 border-b",children:t("help.mcpSearchDesc")})]}),e.jsxs("tr",{children:[e.jsx("td",{className:"px-3 py-2 border-b font-medium",children:"agent"}),e.jsx("td",{className:"px-3 py-2 border-b",children:e.jsx("code",{children:"knowledge"})}),e.jsx("td",{className:"px-3 py-2 border-b",children:t("help.mcpKnowledgeDesc")})]}),e.jsxs("tr",{children:[e.jsx("td",{className:"px-3 py-2 border-b font-medium",children:"agent"}),e.jsx("td",{className:"px-3 py-2 border-b",children:e.jsx("code",{children:"structure"})}),e.jsx("td",{className:"px-3 py-2 border-b",children:t("help.mcpStructureDesc")})]}),e.jsxs("tr",{children:[e.jsx("td",{className:"px-3 py-2 border-b font-medium",children:"agent"}),e.jsx("td",{className:"px-3 py-2 border-b",children:e.jsx("code",{children:"graph"})}),e.jsx("td",{className:"px-3 py-2 border-b",children:t("help.mcpGraphDesc")})]}),e.jsxs("tr",{children:[e.jsx("td",{className:"px-3 py-2 border-b font-medium",children:"agent"}),e.jsx("td",{className:"px-3 py-2 border-b",children:e.jsx("code",{children:"call_context"})}),e.jsx("td",{className:"px-3 py-2 border-b",children:t("help.mcpCallContextDesc")})]}),e.jsxs("tr",{children:[e.jsx("td",{className:"px-3 py-2 border-b font-medium",children:"agent"}),e.jsx("td",{className:"px-3 py-2 border-b",children:e.jsx("code",{children:"guard"})}),e.jsx("td",{className:"px-3 py-2 border-b",children:t("help.mcpGuardDesc")})]}),e.jsxs("tr",{children:[e.jsx("td",{className:"px-3 py-2 border-b font-medium",children:"agent"}),e.jsxs("td",{className:"px-3 py-2 border-b",children:[e.jsx("code",{children:"submit_knowledge"})," / ",e.jsx("code",{children:"submit_knowledge_batch"})," / ",e.jsx("code",{children:"save_document"})]}),e.jsx("td",{className:"px-3 py-2 border-b",children:t("help.mcpSubmitDesc")})]}),e.jsxs("tr",{children:[e.jsx("td",{className:"px-3 py-2 border-b font-medium",children:"agent"}),e.jsx("td",{className:"px-3 py-2 border-b",children:e.jsx("code",{children:"skill"})}),e.jsx("td",{className:"px-3 py-2 border-b",children:t("help.mcpSkillDesc")})]}),e.jsxs("tr",{children:[e.jsx("td",{className:"px-3 py-2 border-b font-medium",children:"agent"}),e.jsx("td",{className:"px-3 py-2 border-b",children:e.jsx("code",{children:"bootstrap"})}),e.jsx("td",{className:"px-3 py-2 border-b",children:t("help.mcpBootstrapDesc")})]}),e.jsxs("tr",{children:[e.jsx("td",{className:"px-3 py-2 border-b font-medium",children:"agent"}),e.jsx("td",{className:"px-3 py-2 border-b",children:e.jsx("code",{children:"dimension_complete"})}),e.jsx("td",{className:"px-3 py-2 border-b",children:t("help.mcpDimensionCompleteDesc")})]}),e.jsxs("tr",{children:[e.jsx("td",{className:"px-3 py-2 border-b font-medium",children:"agent"}),e.jsxs("td",{className:"px-3 py-2 border-b",children:[e.jsx("code",{children:"wiki_plan"})," / ",e.jsx("code",{children:"wiki_finalize"})]}),e.jsxs("td",{className:"px-3 py-2 border-b",children:[t("help.mcpWikiPlanDesc")," · ",t("help.mcpWikiFinalizeDesc")]})]}),e.jsxs("tr",{children:[e.jsx("td",{className:"px-3 py-2 border-b font-medium",children:"agent"}),e.jsx("td",{className:"px-3 py-2 border-b",children:e.jsx("code",{children:"task"})}),e.jsx("td",{className:"px-3 py-2 border-b",children:t("help.mcpTaskDesc")})]}),e.jsx("tr",{className:"bg-amber-50/30",children:e.jsx("td",{colSpan:3,className:"px-3 py-1.5 border-b font-semibold text-amber-700 text-xs",children:t("help.mcpAdminLayerHeader")})}),e.jsxs("tr",{children:[e.jsx("td",{className:"px-3 py-2 border-b font-medium",children:"admin"}),e.jsxs("td",{className:"px-3 py-2 border-b",children:[e.jsx("code",{children:"enrich_candidates"})," / ",e.jsx("code",{children:"validate_candidate"})," / ",e.jsx("code",{children:"check_duplicate"})]}),e.jsx("td",{className:"px-3 py-2 border-b",children:t("help.mcpEnrichDesc")})]}),e.jsxs("tr",{children:[e.jsx("td",{className:"px-3 py-2 font-medium",children:"admin"}),e.jsx("td",{className:"px-3 py-2",children:e.jsx("code",{children:"knowledge_lifecycle"})}),e.jsx("td",{className:"px-3 py-2",children:t("help.mcpLifecycleDesc")})]})]})]})}),e.jsx("p",{className:"text-xs text-[var(--fg-secondary)] mt-2",children:t("help.mcpWriteNote")})]}),e.jsxs("div",{children:[e.jsx("h3",{className:"font-semibold text-[var(--fg-primary)] mb-3",children:t("help.usageExamples")}),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:t("help.exampleSearchKB")}),e.jsx("p",{className:"text-blue-800 text-xs",children:t("help.exampleSearchKBDesc")})]}),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:t("help.exampleBatchScan")}),e.jsx("p",{className:"text-green-800 text-xs",children:t("help.exampleBatchScanDesc")})]}),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:t("help.exampleSubmitCode")}),e.jsx("p",{className:"text-purple-800 text-xs",children:t("help.exampleSubmitCodeDesc")})]})]})]}),e.jsxs("div",{className:"mt-5",children:[e.jsxs("h3",{className:"font-semibold text-[var(--fg-primary)] mb-3 flex items-center gap-2",children:[e.jsx(ba,{size:H.lg,className:"text-blue-600"}),t("help.vscodeExtension")]}),e.jsx("p",{className:"text-[var(--fg-secondary)] text-sm mb-3",children:t("help.vscodeExtDesc")}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-3 mb-3",children:[e.jsxs("div",{className:"bg-[var(--bg-subtle)] border border-[var(--border-default)] rounded-lg p-3",children:[e.jsx("h4",{className:"font-semibold text-[var(--fg-primary)] text-sm mb-1",children:t("help.vscodeExtTaskTool")}),e.jsx("p",{className:"text-[var(--fg-secondary)] text-xs",children:t("help.vscodeExtTaskToolDesc")})]}),e.jsxs("div",{className:"bg-[var(--bg-subtle)] border border-[var(--border-default)] rounded-lg p-3",children:[e.jsx("h4",{className:"font-semibold text-[var(--fg-primary)] text-sm mb-1",children:t("help.vscodeExtGuardDiag")}),e.jsx("p",{className:"text-[var(--fg-secondary)] text-xs",children:t("help.vscodeExtGuardDiagDesc")})]}),e.jsxs("div",{className:"bg-[var(--bg-subtle)] border border-[var(--border-default)] rounded-lg p-3",children:[e.jsx("h4",{className:"font-semibold text-[var(--fg-primary)] text-sm mb-1",children:t("help.vscodeExtCodeLens")}),e.jsx("p",{className:"text-[var(--fg-secondary)] text-xs",children:t("help.vscodeExtCodeLensDesc")})]})]}),e.jsxs("div",{className:"bg-[var(--bg-subtle)] border border-[var(--border-default)] rounded-lg p-3",children:[e.jsx("h4",{className:"font-semibold text-[var(--fg-primary)] text-sm mb-2",children:"Commands"}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-1 text-xs text-[var(--fg-secondary)]",children:[e.jsx("p",{children:t("help.vscodeExtCmd1")}),e.jsx("p",{children:t("help.vscodeExtCmd2")}),e.jsx("p",{children:t("help.vscodeExtCmd3")}),e.jsx("p",{children:t("help.vscodeExtCmd4")}),e.jsx("p",{children:t("help.vscodeExtCmd5")})]})]})]})]}),e.jsx(gt,{id:"cli-reference",title:t("help.cliReference"),icon:e.jsx(Rs,{size:H.xl,className:"text-blue-600"}),isExpanded:s.has("cli-reference"),onToggle:r,children:e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"font-semibold text-[var(--fg-primary)] mb-2",children:t("help.initAndEnv")}),e.jsxs("div",{className:"space-y-1 text-sm",children:[e.jsxs("div",{className:"flex justify-between bg-[var(--bg-subtle)] px-3 py-2 rounded",children:[e.jsx("code",{children:"asd setup"}),e.jsx("span",{className:"text-[var(--fg-secondary)] text-xs",children:t("help.cliSetupDesc")})]}),e.jsxs("div",{className:"flex justify-between bg-[var(--bg-subtle)] px-3 py-2 rounded",children:[e.jsx("code",{children:"asd status"}),e.jsx("span",{className:"text-[var(--fg-secondary)] text-xs",children:t("help.cliStatusDesc")})]}),e.jsxs("div",{className:"flex justify-between bg-[var(--bg-subtle)] px-3 py-2 rounded",children:[e.jsx("code",{children:"asd ui"}),e.jsx("span",{className:"text-[var(--fg-secondary)] text-xs",children:t("help.cliUiDesc")})]}),e.jsxs("div",{className:"flex justify-between bg-[var(--bg-subtle)] px-3 py-2 rounded",children:[e.jsx("code",{children:"asd upgrade"}),e.jsx("span",{className:"text-[var(--fg-secondary)] text-xs",children:t("help.cliUpgradeDesc")})]})]})]}),e.jsxs("div",{children:[e.jsx("h3",{className:"font-semibold text-[var(--fg-primary)] mb-2",children:t("help.kbManagement")}),e.jsxs("div",{className:"space-y-1 text-sm",children:[e.jsxs("div",{className:"flex justify-between bg-[var(--bg-subtle)] px-3 py-2 rounded",children:[e.jsx("code",{children:"asd sync"}),e.jsx("span",{className:"text-[var(--fg-secondary)] text-xs",children:t("help.cliSyncDesc")})]}),e.jsxs("div",{className:"flex justify-between bg-[var(--bg-subtle)] px-3 py-2 rounded",children:[e.jsx("code",{children:"asd ais [Target]"}),e.jsx("span",{className:"text-[var(--fg-secondary)] text-xs",children:t("help.cliAisDesc")})]}),e.jsxs("div",{className:"flex justify-between bg-[var(--bg-subtle)] px-3 py-2 rounded",children:[e.jsx("code",{children:"asd watch"}),e.jsx("span",{className:"text-[var(--fg-secondary)] text-xs",children:t("help.cliWatchDesc")})]})]})]}),e.jsxs("div",{children:[e.jsx("h3",{className:"font-semibold text-[var(--fg-primary)] mb-2",children:t("help.cliColdstartAndScan")}),e.jsxs("div",{className:"space-y-1 text-sm",children:[e.jsxs("div",{className:"flex justify-between bg-[var(--bg-subtle)] px-3 py-2 rounded",children:[e.jsx("code",{children:"asd coldstart"}),e.jsx("span",{className:"text-[var(--fg-secondary)] text-xs",children:t("help.cliColdstartDesc")})]}),e.jsxs("div",{className:"flex justify-between bg-[var(--bg-subtle)] px-3 py-2 rounded",children:[e.jsx("code",{children:"asd cursor-rules"}),e.jsx("span",{className:"text-[var(--fg-secondary)] text-xs",children:t("help.cliCursorRulesDesc")})]}),e.jsxs("div",{className:"flex justify-between bg-[var(--bg-subtle)] px-3 py-2 rounded",children:[e.jsx("code",{children:"asd mirror"}),e.jsx("span",{className:"text-[var(--fg-secondary)] text-xs",children:t("help.cliMirrorDesc")})]})]})]}),e.jsxs("div",{children:[e.jsx("h3",{className:"font-semibold text-[var(--fg-primary)] mb-2",children:t("help.searchAndAudit")}),e.jsxs("div",{className:"space-y-1 text-sm",children:[e.jsxs("div",{className:"flex justify-between bg-[var(--bg-subtle)] px-3 py-2 rounded",children:[e.jsx("code",{children:"asd search <query>"}),e.jsx("span",{className:"text-[var(--fg-secondary)] text-xs",children:t("help.cliSearchDesc")})]}),e.jsxs("div",{className:"flex justify-between bg-[var(--bg-subtle)] px-3 py-2 rounded",children:[e.jsx("code",{children:"asd guard <file>"}),e.jsx("span",{className:"text-[var(--fg-secondary)] text-xs",children:t("help.cliGuardDesc")})]}),e.jsxs("div",{className:"flex justify-between bg-[var(--bg-subtle)] px-3 py-2 rounded",children:[e.jsx("code",{children:"asd guard:ci"}),e.jsx("span",{className:"text-[var(--fg-secondary)] text-xs",children:t("help.cliGuardCiDesc")})]}),e.jsxs("div",{className:"flex justify-between bg-[var(--bg-subtle)] px-3 py-2 rounded",children:[e.jsx("code",{children:"asd guard:staged"}),e.jsx("span",{className:"text-[var(--fg-secondary)] text-xs",children:t("help.cliGuardStagedDesc")})]}),e.jsxs("div",{className:"flex justify-between bg-[var(--bg-subtle)] px-3 py-2 rounded",children:[e.jsx("code",{children:"asd server"}),e.jsx("span",{className:"text-[var(--fg-secondary)] text-xs",children:t("help.cliServerDesc")})]})]})]}),e.jsxs("div",{children:[e.jsx("h3",{className:"font-semibold text-[var(--fg-primary)] mb-2",children:t("help.cliTaskManagement")}),e.jsxs("div",{className:"space-y-1 text-sm",children:[e.jsxs("div",{className:"flex justify-between bg-[var(--bg-subtle)] px-3 py-2 rounded",children:[e.jsx("code",{children:"asd task list"}),e.jsx("span",{className:"text-[var(--fg-secondary)] text-xs",children:t("help.cliTaskListDesc")})]}),e.jsxs("div",{className:"flex justify-between bg-[var(--bg-subtle)] px-3 py-2 rounded",children:[e.jsx("code",{children:"asd task ready"}),e.jsx("span",{className:"text-[var(--fg-secondary)] text-xs",children:t("help.cliTaskReadyDesc")})]}),e.jsxs("div",{className:"flex justify-between bg-[var(--bg-subtle)] px-3 py-2 rounded",children:[e.jsx("code",{children:"asd task prime"}),e.jsx("span",{className:"text-[var(--fg-secondary)] text-xs",children:t("help.cliTaskPrimeDesc")})]}),e.jsxs("div",{className:"flex justify-between bg-[var(--bg-subtle)] px-3 py-2 rounded",children:[e.jsx("code",{children:"asd task stats"}),e.jsx("span",{className:"text-[var(--fg-secondary)] text-xs",children:t("help.cliTaskStatsDesc")})]})]})]}),e.jsxs("div",{children:[e.jsx("h3",{className:"font-semibold text-[var(--fg-primary)] mb-2",children:t("help.maintenanceUpgrade")}),e.jsxs("div",{className:"space-y-1 text-sm",children:[e.jsxs("div",{className:"flex justify-between bg-[var(--bg-subtle)] px-3 py-2 rounded",children:[e.jsx("code",{children:"asd upgrade"}),e.jsx("span",{className:"text-[var(--fg-secondary)] text-xs",children:t("help.cliUpgradeMcpDesc")})]}),e.jsxs("div",{className:"flex justify-between bg-[var(--bg-subtle)] px-3 py-2 rounded",children:[e.jsx("code",{children:"asd sync --force"}),e.jsx("span",{className:"text-[var(--fg-secondary)] text-xs",children:t("help.cliSyncForceDesc")})]}),e.jsxs("div",{className:"flex justify-between bg-[var(--bg-subtle)] px-3 py-2 rounded",children:[e.jsx("code",{children:"asd sync --dry-run"}),e.jsx("span",{className:"text-[var(--fg-secondary)] text-xs",children:t("help.cliSyncDryDesc")})]})]})]})]})})]}),e.jsx("div",{className:"mt-8 p-4 bg-blue-50 border border-blue-200 rounded-lg text-center",children:e.jsx("p",{className:"text-[var(--fg-primary)] text-sm",dangerouslySetInnerHTML:{__html:t("help.footerHint",{link:`<a href="https://github.com/GxFn/AutoSnippet" target="_blank" rel="noopener noreferrer" class="text-blue-600 hover:underline font-medium">${t("help.footerGithubReadme")}</a>`,cmd:'<code class="bg-blue-100 px-1.5 py-0.5 rounded text-xs">asd status</code>'})}})})]})};function Ii(){const[t,s]=n.useState(null);n.useEffect(()=>{const l=Cs(),i=h=>{s({status:"running",total:h.total,current:0,progress:0,refined:0,failed:0,items:h.candidateIds.map(u=>({candidateId:u,title:"",status:"pending"}))})},p=h=>{s(u=>u&&{...u,current:h.current,progress:h.progress,items:u.items.map(m=>m.candidateId===h.candidateId?{...m,title:h.title,status:"refining"}:m)})},d=h=>{s(u=>u&&{...u,current:h.current,progress:h.progress,refined:h.refinedSoFar,items:u.items.map(m=>m.candidateId===h.candidateId?{...m,title:h.title,status:"done",refined:h.refined}:m)})},g=h=>{s(u=>u&&{...u,current:h.current,progress:h.progress,failed:u.failed+1,items:u.items.map(m=>m.candidateId===h.candidateId?{...m,title:h.title,status:"failed",error:h.error}:m)})},x=h=>{s(u=>u&&{...u,status:"completed",progress:100,refined:h.refined,failed:h.failed})};return l.on("refine:started",i),l.on("refine:item-started",p),l.on("refine:item-completed",d),l.on("refine:item-failed",g),l.on("refine:completed",x),()=>{l.off("refine:started",i),l.off("refine:item-started",p),l.off("refine:item-completed",d),l.off("refine:item-failed",g),l.off("refine:completed",x)}},[]);const a=n.useCallback(()=>s(null),[]),r=t?.status==="running",o=t?.status==="completed";return{refine:t,isRefining:r,isRefineDone:o,resetRefine:a}}const Ti=({refine:t,isRefineDone:s,onDismiss:a})=>{const{t:r}=Ae(),o=n.useRef(!1);if(n.useEffect(()=>{if(s&&t&&!o.current){o.current=!0;const p=t.failed>0?r("refineProgress.doneMsgWithFail",{refined:String(t.refined),failed:String(t.failed)}):r("refineProgress.doneMsg",{refined:String(t.refined)});re(p,{title:r("refineProgress.doneTitle"),type:t.failed>0?"error":"success"})}},[s,t]),n.useEffect(()=>{t||(o.current=!1)},[t]),!t)return null;const l=t.items.find(p=>p.status==="refining"),i=t.items.filter(p=>p.status==="done"||p.status==="failed").length;return e.jsxs("div",{className:"bg-white rounded-xl border border-slate-200 shadow-sm p-4 mb-4",children:[e.jsxs("div",{className:"flex items-center justify-between mb-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:`p-1.5 rounded-lg ${s?"bg-emerald-50":"bg-blue-50"}`,children:s?e.jsx(ot,{className:"w-4 h-4 text-emerald-600"}):e.jsx(Le,{className:"w-4 h-4 text-blue-600"})}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-semibold text-slate-800",children:r(s?"refineProgress.doneTitle":"refineProgress.runningTitle")}),e.jsxs("p",{className:"text-xs text-slate-500",children:[s?t.failed>0?r("refineProgress.doneMsgWithFail",{refined:String(t.refined),failed:String(t.failed)}):r("refineProgress.doneMsg",{refined:String(t.refined)}):r("refineProgress.progressMsg",{done:String(i),total:String(t.total)}),l&&!s&&e.jsxs("span",{className:"ml-2 text-blue-600",children:[e.jsx(Ne,{className:"w-3 h-3 inline animate-spin mr-1"}),l.title||l.candidateId.slice(0,8)]})]})]})]}),s&&a&&e.jsx("button",{onClick:a,className:"text-xs px-2.5 py-1 rounded-lg bg-slate-100 hover:bg-slate-200 text-slate-600 transition-colors",children:r("refineProgress.closeBtn")})]}),e.jsx("div",{className:"w-full h-1.5 bg-slate-100 rounded-full overflow-hidden",children:e.jsx("div",{className:`h-full rounded-full transition-all duration-500 ease-out ${s?t.failed>0?"bg-amber-400":"bg-emerald-500":"bg-blue-500"}`,style:{width:`${t.progress}%`}})}),s&&t.failed>0&&e.jsxs("div",{className:"mt-2 text-xs text-red-500 flex items-center gap-1",children:[e.jsx(ze,{className:"w-3 h-3"}),t.items.filter(p=>p.status==="failed").map(p=>p.title||p.candidateId.slice(0,8)).join("、")]})]})},ls={_watch:"silentLabels.watch",_draft:"silentLabels.draft",_cli:"silentLabels.cli",_pending:"silentLabels.pending",_recipe:"silentLabels.recipe"},os={architecture:"bootstrap.dimLabels.architecture","coding-standards":"bootstrap.dimLabels.codingStandards","design-patterns":"bootstrap.dimLabels.designPatterns","error-resilience":"bootstrap.dimLabels.errorResilience","concurrency-async":"bootstrap.dimLabels.concurrencyAsync","data-event-flow":"bootstrap.dimLabels.dataEventFlow","networking-api":"bootstrap.dimLabels.networkingApi","ui-interaction":"bootstrap.dimLabels.uiInteraction","testing-quality":"bootstrap.dimLabels.testingQuality","security-auth":"bootstrap.dimLabels.securityAuth","performance-optimization":"bootstrap.dimLabels.performanceOptimization","observability-logging":"bootstrap.dimLabels.observabilityLogging","agent-guidelines":"bootstrap.dimLabels.agentGuidelines","swift-objc-idiom":"bootstrap.dimLabels.swiftObjcIdiom","ts-js-module":"bootstrap.dimLabels.tsJsModule","python-structure":"bootstrap.dimLabels.pythonStructure","jvm-annotation":"bootstrap.dimLabels.jvmAnnotation","go-module":"bootstrap.dimLabels.goModule","rust-ownership":"bootstrap.dimLabels.rustOwnership","csharp-dotnet":"bootstrap.dimLabels.csharpDotnet","react-patterns":"bootstrap.dimLabels.reactPatterns","vue-patterns":"bootstrap.dimLabels.vuePatterns","spring-patterns":"bootstrap.dimLabels.springPatterns","swiftui-patterns":"bootstrap.dimLabels.swiftuiPatterns","django-fastapi":"bootstrap.dimLabels.djangoFastapi",bootstrap:"bootstrap.dimLabels.bootstrap"};function Ei(t,s,a,r){return[...t].sort(([o],[l])=>{const i=r(o),p=r(l);if(i&&!p)return 1;if(!i&&p)return-1;const d=a(o),g=a(l);if(d&&!g)return-1;if(!d&&g)return 1;const x=s(o),h=s(l);return x&&!h?1:!x&&h?-1:o.localeCompare(l)})}function Bt(t,s){if(!t)return"";const a=typeof t=="number"?t:Number(t),r=a<1e12?a*1e3:a,o=new Date(r);if(isNaN(o.getTime())||o.getFullYear()<2e3)return"";const i=new Date().getTime()-o.getTime();if(i<0)return o.toLocaleDateString();const p=Math.floor(i/6e4);if(p<1)return s("candidates.timeJustNow");if(p<60)return s("candidates.timeMinutesAgo",{n:p});const d=Math.floor(p/60);if(d<24)return s("candidates.timeHoursAgo",{n:d});const g=Math.floor(d/24);return g<7?s("candidates.timeDaysAgo",{n:g}):o.toLocaleDateString()}function Pi(t,s=4){return t?la(t).split(`
78
78
  `).slice(0,s).join(`
79
79
  `):""}function Mi(t){return t==null?{ring:"stroke-slate-200",text:"text-[var(--fg-muted)]",bg:"bg-[var(--bg-subtle)]",labelKey:""}:t>=.8?{ring:"stroke-emerald-500",text:"text-emerald-600 dark:text-emerald-400",bg:"bg-emerald-500/10",labelKey:"candidates.confidenceHighLabel"}:t>=.6?{ring:"stroke-blue-500",text:"text-blue-600 dark:text-blue-400",bg:"bg-blue-500/10",labelKey:"candidates.confidenceMediumLabel"}:t>=.4?{ring:"stroke-amber-500",text:"text-amber-600 dark:text-amber-400",bg:"bg-amber-500/10",labelKey:"candidates.confidenceMediumLowLabel"}:{ring:"stroke-red-500",text:"text-red-600 dark:text-red-400",bg:"bg-red-500/10",labelKey:"candidates.confidenceLowLabel"}}const Ta={"bootstrap-scan":{labelKey:"candidates.sourceAiScanLabel",color:"text-violet-600 dark:text-violet-400 bg-violet-500/10 border-violet-500/20"},mcp:{labelKey:"candidates.sourceMcpLabel",color:"text-blue-600 dark:text-blue-400 bg-blue-500/10 border-blue-500/20"},manual:{labelKey:"candidates.sourceManualLabel",color:"text-emerald-600 dark:text-emerald-400 bg-emerald-500/10 border-emerald-500/20"},"file-watcher":{labelKey:"candidates.sourceFileWatcherLabel",color:"text-orange-600 dark:text-orange-400 bg-orange-500/10 border-orange-500/20"},clipboard:{labelKey:"candidates.sourceClipboardLabel",color:"text-pink-600 dark:text-pink-400 bg-pink-500/10 border-pink-500/20"},cli:{labelKey:"CLI",color:"text-[var(--fg-secondary)] bg-[var(--bg-subtle)] border-[var(--border-default)]"},agent:{labelKey:"AI Agent",color:"text-violet-600 dark:text-violet-400 bg-violet-500/10 border-violet-500/20"},submit_with_check:{labelKey:"candidates.sourceSubmitCheckLabel",color:"text-teal-600 dark:text-teal-400 bg-teal-500/10 border-teal-500/20"},"bootstrap-fallback":{labelKey:"candidates.sourceFallbackLabel",color:"text-amber-600 dark:text-amber-400 bg-amber-500/10 border-amber-500/20"}},Li=({value:t,size:s=36})=>{const a=(s-6)/2,r=2*Math.PI*a,o=t!=null?Math.max(0,Math.min(1,t)):0,l=r*(1-o),{ring:i,text:p}=Mi(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-[var(--border-default)]"}),e.jsx("circle",{cx:s/2,cy:s/2,r:a,fill:"none",strokeWidth:3,strokeLinecap:"round",className:i,strokeDasharray:r,strokeDashoffset:l,style:{transition:"stroke-dashoffset 0.5s ease"}})]}),e.jsx("span",{className:`absolute text-[9px] font-bold ${p}`,children:t!=null?`${Math.round(t*100)}`:"—"})]})},Fi=({data:t,isShellTarget:s,isSilentTarget:a=()=>!1,isPendingTarget:r=()=>!1,handleDeleteCandidate:o,handleDeleteAllInTarget:l,onAuditCandidate:i,onAuditAllInTarget:p,onEditRecipe:d,onColdStart:g,onRescan:x,isScanning:h,isBootstrapping:u,onRefresh:m})=>{const{t:c}=Ae(),[j,A]=n.useState(null),{isWide:D,toggle:I}=ia(),[P,J]=n.useState(new Set),[w]=n.useState(new Set),[B,z]=n.useState(!1),[k]=n.useState(!1),E=Zt(),{refine:L,isRefining:O,isRefineDone:W,resetRefine:q}=Ii(),[N,v]=n.useState({}),[U,ae]=n.useState(null),[be,me]=n.useState({}),[je,G]=n.useState({sort:"score-desc"}),le=t?.candidates?Object.entries(t.candidates):[],de=Ei(le,s,a,r),R=de.map(([ee])=>ee),T=!!(t?.recipes&&t.recipes.length>0),X=le.length>0,oe=T||X,pe=U&&R.includes(U)?U:R[0]??null;n.useEffect(()=>{R.length>0&&(!U||!R.includes(U))&&ae(R[0])},[R.join(","),U]);const ue=n.useMemo(()=>{if(!t?.candidates)return null;let ee=0,ce=0,f=0;for(const xe of Object.values(t.candidates))for(const fe of xe.items)ee++,ce+=fe.reasoning?.confidence??0,(fe.content?.pattern&&fe.content.pattern.trim().length>0||fe.coreCode&&fe.coreCode.trim().length>0)&&f++;const V=ee>0?ce/ee:0;return{total:ee,avgConfidence:V,withCode:f}},[t?.candidates]),M=n.useMemo(()=>{if(!pe||!t?.candidates?.[pe])return null;const ee=t.candidates[pe].items,ce=ee.length,f=ee.reduce((fe,C)=>fe+(C.reasoning?.confidence??0),0)/(ce||1),V=ee.filter(fe=>fe.content?.pattern&&fe.content.pattern.trim().length>0||fe.coreCode&&fe.coreCode.trim().length>0).length,xe=new Map;return ee.forEach(fe=>{const C=fe.source||"unknown";xe.set(C,(xe.get(C)||0)+1)}),{total:ce,avgConfidence:f,withCode:V,sources:xe}},[pe,t?.candidates]),Ce=n.useMemo(()=>{const ee=new Map;if(t?.idTitleMap)for(const[ce,f]of Object.entries(t.idTitleMap))ee.set(ce,f);if(t?.candidates)for(const ce of Object.values(t.candidates))for(const f of ce.items)f.id&&f.title&&ee.set(f.id,f.title);if(t?.recipes)for(const ce of t.recipes)ce.id&&ce.name&&ee.set(ce.id,ce.name.replace(/\.md$/i,""));return ee},[t?.idTitleMap,t?.candidates,t?.recipes]),F=n.useCallback(async ee=>{if(!P.has(ee)){J(ce=>new Set(ce).add(ee));try{const ce=await Q.enrichCandidates([ee]);ce.enriched>0?re(`${ce.results?.[0]?.filledFields?.length||0} ${c("candidates.approveSuccess")}`,{title:c("candidates.aiRefine")}):re(c("recipes.noContent"),{title:c("candidates.aiRefine"),type:"info"});try{const f=await Q.getCandidate(ee);me(V=>({...V,[ee]:f}))}catch{}}catch(ce){re(ke(ce,c("common.operationFailed")),{title:c("common.operationFailed"),type:"error"})}finally{J(ce=>{const f=new Set(ce);return f.delete(ee),f})}}},[P,m]),Se=n.useCallback(async()=>{if(B||!pe||!t?.candidates?.[pe])return;const ee=t.candidates[pe].items;if(ee.length!==0){z(!0);try{let ce=0;for(let f=0;f<ee.length;f+=20){const V=ee.slice(f,f+20).map(fe=>fe.id),xe=await Q.enrichCandidates(V);ce+=xe.enriched}re(`${ce}/${ee.length} ${c("candidates.batchDeleteDone",{count:ce})}`,{title:c("candidates.aiRefine")}),m?.()}catch(ce){re(ke(ce,c("common.operationFailed")),{title:c("common.operationFailed"),type:"error"})}finally{z(!1)}}},[B,pe,t?.candidates,m]),Te=n.useCallback(async ee=>{try{const ce=await Q.getCandidate(ee);me(f=>({...f,[ee]:ce}))}catch{}},[]),Fe=n.useCallback(()=>{if(!pe||!t?.candidates?.[pe])return;const ee=t.candidates[pe].items,ce=ee.map(f=>f.id);E.openRefine({candidateIds:ce,candidates:ee,onCandidateUpdated:Te})},[pe,t?.candidates,E,Te]),Me=n.useCallback(ee=>{if(!pe||!t?.candidates?.[pe])return;A(ee);const ce=t.candidates[pe].items;E.openRefine({candidateIds:[ee],candidates:ce,onCandidateUpdated:Te})},[pe,t?.candidates,E,Te]);return e.jsxs("div",{className:"flex-1 flex flex-col overflow-hidden",children:[e.jsxs("div",{className:"mb-4 flex flex-wrap justify-between items-center gap-3 shrink-0",children:[e.jsxs("div",{className:"flex items-center gap-3 min-w-0",children:[e.jsx("div",{className:"w-10 h-10 rounded-xl bg-blue-500/10 border border-blue-500/20 flex items-center justify-center shrink-0",children:e.jsx(hs,{className:"text-blue-600",size:20})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("h2",{className:"text-lg xl:text-xl font-bold text-[var(--fg-primary)]",children:"AI Scan Candidates"}),e.jsx("p",{className:"text-xs text-[var(--fg-muted)] mt-0.5 truncate",children:c("candidates.title")})]})]}),e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[!u&&e.jsx(e.Fragment,{children:oe?x&&X&&e.jsxs("button",{onClick:x,disabled:h,className:`flex items-center gap-1.5 px-3.5 py-2 rounded-lg text-xs font-bold transition-all ${h?"text-[var(--fg-muted)] bg-[var(--bg-subtle)] cursor-not-allowed":"text-blue-600 dark:text-blue-400 bg-blue-500/10 border border-blue-500/20 hover:bg-blue-500/20"}`,title:c("candidates.rescanTitle"),children:[h?e.jsx(Ne,{size:14,className:"animate-spin"}):e.jsx(at,{size:14}),c(h?"common.loading":"candidates.rescanBtn")]}):g&&e.jsxs("button",{onClick:g,disabled:h,className:`flex items-center gap-1.5 px-3.5 py-2 rounded-lg text-xs font-bold transition-all ${h?"text-[var(--fg-muted)] bg-[var(--bg-subtle)] cursor-not-allowed":"text-violet-600 dark:text-violet-400 bg-violet-500/10 border border-violet-500/20 hover:bg-violet-500/20"}`,title:c("candidates.coldStartTitle"),children:[h?e.jsx(Ne,{size:14,className:"animate-spin"}):e.jsx(Kt,{size:14}),c(h?"common.loading":"candidates.sourceBootstrap")]})}),M&&M.total>0&&e.jsxs("button",{onClick:Se,disabled:B||k,className:`flex items-center gap-1.5 px-3 py-2 rounded-lg text-xs font-bold transition-all ${B||k?"text-[var(--fg-muted)] bg-[var(--bg-subtle)] cursor-not-allowed":"text-amber-600 dark:text-amber-400 bg-amber-500/10 border border-amber-500/20 hover:bg-amber-500/20"}`,title:c("candidates.enrichTitle"),children:[B?e.jsx(Ne,{size:14,className:"animate-spin"}):e.jsx(us,{size:14}),c(B?"common.loading":"candidates.aiEnrich")]}),M&&M.total>0&&e.jsxs("button",{onClick:Fe,disabled:k||B||O,className:`flex items-center gap-1.5 px-3 py-2 rounded-lg text-xs font-bold transition-all ${k||B||O?"text-[var(--fg-muted)] bg-[var(--bg-subtle)] cursor-not-allowed":"text-emerald-600 dark:text-emerald-400 bg-emerald-500/10 border border-emerald-500/20 hover:bg-emerald-500/20"}`,title:c("candidates.refineTitle"),children:[k||O?e.jsx(Ne,{size:14,className:"animate-spin"}):e.jsx(Le,{size:14}),c(k||O?"common.loading":"candidates.aiRefine")]}),ue&&e.jsxs("div",{className:"flex items-center gap-2 text-xs",children:[e.jsxs("div",{className:"flex items-center gap-1.5 px-3 py-1.5 rounded-lg bg-[var(--bg-subtle)] border border-[var(--border-default)]",children:[e.jsx(Tt,{size:14,className:"text-[var(--fg-muted)]"}),e.jsx("span",{className:"text-[var(--fg-secondary)]",children:c("candidates.totalCount",{count:ue.total})})]}),e.jsxs("div",{className:"flex items-center gap-1.5 px-3 py-1.5 rounded-lg bg-emerald-500/10 border border-emerald-500/20",children:[e.jsx("span",{className:"text-emerald-500",children:c("candidates.confidence")}),e.jsxs("strong",{className:"text-emerald-700",children:[Math.round(ue.avgConfidence*100),"%"]})]})]}),!u&&g&&oe&&e.jsxs("button",{onClick:g,disabled:h,className:`ml-auto flex items-center gap-1 px-2.5 py-1.5 rounded-md text-[11px] transition-all ${h?"text-[var(--fg-muted)] cursor-not-allowed":"text-[var(--fg-muted)] hover:text-red-600 hover:bg-red-50"}`,title:c("candidates.cleanRebuildTitle"),children:[h?e.jsx(Ne,{size:12,className:"animate-spin"}):e.jsx(Ke,{size:12}),c("candidates.cleanRebuildBtn")]})]})]}),L&&e.jsx(Ti,{refine:L,isRefineDone:W,onDismiss:()=>{q(),m?.()}}),le.length>0&&e.jsx("div",{className:"shrink-0 bg-[var(--bg-surface)] border border-[var(--border-default)] rounded-xl px-3 py-2 mb-3 shadow-sm",children:e.jsx("div",{className:"flex items-center gap-1.5 flex-wrap",children:R.map(ee=>{const ce=a(ee),f=ls[ee]?c(ls[ee]):void 0,xe=t?.candidates[ee]?.items?.length??0,fe=pe===ee,C=et[ee]||et.All;return e.jsxs("button",{onClick:()=>ae(ee),className:`flex items-center gap-2 px-3 py-2 rounded-lg text-sm font-bold whitespace-nowrap transition-all border
80
- ${fe?`bg-[var(--bg-surface)] ${C?.color||"text-blue-600"} border-[var(--border-emphasis)] shadow-sm ring-1 ring-inset ring-[var(--border-emphasis)]`:"bg-[var(--bg-subtle)] text-[var(--fg-secondary)] border-[var(--border-default)] hover:border-[var(--border-emphasis)] hover:bg-[var(--bg-subtle)]"}`,children:[(()=>{const b=C?.icon||gs;return e.jsx(b,{size:H.sm,className:fe?"":"text-[var(--fg-muted)]"})})(),e.jsx("span",{children:os[ee]?c(os[ee]):ee}),ce&&f&&e.jsx("span",{className:"text-[9px] text-amber-600 dark:text-amber-400 border border-amber-200 dark:border-amber-700 px-1 rounded",children:f}),e.jsx("span",{className:`text-[10px] font-normal rounded-full px-1.5 ${fe?"bg-[var(--bg-subtle)]":"bg-[var(--bg-subtle)] text-[var(--fg-muted)]"}`,children:xe})]},ee)})})}),e.jsxs("div",{className:"flex-1 overflow-y-auto pr-1 pb-6",children:[(!t?.candidates||Object.keys(t.candidates).length===0)&&!u&&e.jsxs("div",{className:"h-72 flex flex-col items-center justify-center bg-[var(--bg-surface)] rounded-2xl border border-dashed border-[var(--border-default)] text-[var(--fg-muted)]",children:[e.jsx("div",{className:"w-16 h-16 rounded-2xl bg-[var(--bg-subtle)] flex items-center justify-center mb-4",children:e.jsx(hs,{size:32,className:"text-[var(--fg-muted)]"})}),e.jsx("p",{className:"text-sm font-medium text-[var(--fg-secondary)]",children:c("candidates.noResults")}),e.jsx("p",{className:"mt-2 text-xs max-w-sm text-center leading-relaxed text-[var(--fg-muted)]",children:c("candidates.emptyHint")}),oe?e.jsxs(e.Fragment,{children:[x&&e.jsxs("button",{onClick:x,disabled:h,className:`mt-4 flex items-center gap-2 px-5 py-2.5 rounded-xl text-sm font-bold transition-all ${h?"text-[var(--fg-muted)] bg-[var(--bg-subtle)] cursor-not-allowed":"text-blue-600 dark:text-blue-400 bg-blue-500/10 border border-blue-500/20 hover:bg-blue-500/20"}`,children:[h?e.jsx(Ne,{size:16,className:"animate-spin"}):e.jsx(at,{size:16}),c(h?"common.loading":"candidates.rescanBtn")]}),e.jsx("p",{className:"mt-3 text-[11px] text-[var(--fg-muted)]",children:c("candidates.rescanHint")})]}):e.jsxs(e.Fragment,{children:[g&&e.jsxs("button",{onClick:g,disabled:h,className:`mt-4 flex items-center gap-2 px-5 py-2.5 rounded-xl text-sm font-bold transition-all ${h?"text-[var(--fg-muted)] bg-[var(--bg-subtle)] cursor-not-allowed":"text-violet-600 dark:text-violet-400 bg-violet-500/10 border border-violet-500/20 hover:bg-violet-500/20"}`,children:[h?e.jsx(Ne,{size:16,className:"animate-spin"}):e.jsx(Kt,{size:16}),c(h?"common.loading":"candidates.sourceBootstrap")]}),e.jsx("p",{className:"mt-3 text-[11px] text-[var(--fg-muted)]",children:c("candidates.emptyHintIde")})]})]}),(!t?.candidates||Object.keys(t.candidates).length===0)&&u&&e.jsxs("div",{className:"h-72 flex flex-col items-center justify-center bg-[var(--bg-surface)] rounded-2xl border border-dashed border-violet-500/30 text-[var(--fg-muted)]",children:[e.jsx("div",{className:"w-16 h-16 rounded-2xl bg-violet-500/10 flex items-center justify-center mb-4",children:e.jsx(Ne,{size:32,className:"text-violet-400 animate-spin"})}),e.jsx("p",{className:"text-sm font-medium text-violet-400",children:c("common.loading")}),e.jsx("p",{className:"mt-2 text-xs max-w-sm text-center leading-relaxed text-[var(--fg-muted)]",children:c("candidates.scanningHint")})]}),t&&pe&&de.filter(([ee])=>ee===pe).map(([ee,ce])=>{const f=s(ee),V=a(ee),xe=ls[ee]?c(ls[ee]):c("candidates.silent"),fe=N[ee]||{page:1,pageSize:12},C=fe.page,b=fe.pageSize,_=ce.items.sort((se,we)=>je.sort==="default"?0:je.sort==="score-desc"?(we.quality?.overall??0)-(se.quality?.overall??0):je.sort==="score-asc"?(se.quality?.overall??0)-(we.quality?.overall??0):je.sort==="confidence-desc"?(we.reasoning?.confidence??0)-(se.reasoning?.confidence??0):0),ne=_.length,$=Math.ceil(ne/b),y=(C-1)*b,te=_.slice(y,y+b),ge=se=>{v(we=>({...we,[ee]:{...fe,page:se}}))},he=se=>{v(we=>({...we,[ee]:{page:1,pageSize:se}}))},De=et[ee]||et.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-[var(--bg-surface)] border border-[var(--border-default)] shadow-sm",children:[e.jsxs("div",{className:"flex items-center gap-2 flex-1 min-w-0",children:[(()=>{const se=De?.icon||gs;return e.jsx(se,{size:18,className:De?.color||"text-blue-600"})})(),e.jsx("span",{className:"text-base font-bold text-[var(--fg-primary)] truncate",children:os[ee]?c(os[ee]):ee}),V&&e.jsx("span",{className:"text-[10px] font-bold text-amber-600 dark:text-amber-400 border border-amber-500/20 bg-amber-500/10 px-1.5 py-0.5 rounded",children:xe}),f&&!V&&e.jsx("span",{className:"text-[10px] font-bold text-[var(--fg-muted)] border border-[var(--border-default)] bg-[var(--bg-subtle)] px-1.5 py-0.5 rounded",children:"SHELL"}),e.jsxs("span",{className:"text-[11px] text-[var(--fg-muted)] flex items-center gap-1",children:[e.jsx(Ye,{size:11}),c("candidates.scannedAt",{time:Bt(ce.scanTime,c)||new Date(ce.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-[var(--bg-subtle)] border border-[var(--border-default)]",children:[e.jsx(pl,{size:12,className:"text-[var(--fg-muted)]"}),e.jsx(tt,{value:je.sort,onChange:se=>G(we=>({...we,sort:se})),options:[{value:"score-desc",label:`${c("candidates.sortScore")} ↓`},{value:"score-asc",label:`${c("candidates.sortScore")} ↑`},{value:"confidence-desc",label:`${c("candidates.sortConfidence")} ↓`},{value:"default",label:c("candidates.sortDefault")}],size:"xs",className:"border-none bg-transparent"})]}),e.jsx("div",{className:"h-4 w-px bg-[var(--border-default)]"}),e.jsx("button",{onClick:()=>p(te,ee),className:"text-[11px] font-bold text-blue-600 dark:text-blue-400 hover:text-blue-700 px-2.5 py-1.5 rounded-lg hover:bg-blue-500/10 transition-colors",children:c("candidates.approveCurrentPage")})]}),e.jsx("div",{className:"h-5 w-px bg-[var(--border-default)]"}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"text-[11px] text-[var(--fg-muted)] font-medium",children:c("candidates.totalCount",{count:ne})}),ne>0&&e.jsxs("span",{className:"text-[11px] text-emerald-600 font-medium ml-1.5 pl-2 border-l border-[var(--border-default)]",children:[c("candidates.confidence")," ",Math.round(ce.items.reduce((se,we)=>se+(we.reasoning?.confidence??0),0)/ne*100),"%"]})]}),e.jsx("div",{className:"ml-auto",children:e.jsxs("button",{onClick:()=>l(ee),className:"flex items-center gap-1 px-2.5 py-1.5 rounded-md text-[11px] transition-all text-[var(--fg-muted)] hover:text-red-600 hover:bg-red-50",title:c("candidates.deleteAll"),children:[e.jsx(Ke,{size:12}),c("candidates.deleteAll")]})})]}),e.jsx("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-3 items-start",children:te.map(se=>{const we=j===se.id,Oe=se.reasoning?.confidence??null,rt=(se.quality?.overall??0)>0?se.quality?.overall??null:null,ct=Ta[se.source||""]||{labelKey:se.source||"",color:"text-[var(--fg-secondary)] bg-[var(--bg-subtle)] border-[var(--border-default)]"},Xt=et[se.category||""]||et.All||{};return e.jsxs("div",{onClick:()=>A(we?null:se.id),className:`bg-[var(--bg-surface)] rounded-xl border overflow-hidden hover:shadow-lg transition-all duration-200 flex flex-col group cursor-pointer
80
+ ${fe?`bg-[var(--bg-surface)] ${C?.color||"text-blue-600"} border-[var(--border-emphasis)] shadow-sm ring-1 ring-inset ring-[var(--border-emphasis)]`:"bg-[var(--bg-subtle)] text-[var(--fg-secondary)] border-[var(--border-default)] hover:border-[var(--border-emphasis)] hover:bg-[var(--bg-subtle)]"}`,children:[(()=>{const b=C?.icon||gs;return e.jsx(b,{size:H.sm,className:fe?"":"text-[var(--fg-muted)]"})})(),e.jsx("span",{children:os[ee]?c(os[ee]):ee}),ce&&f&&e.jsx("span",{className:"text-[9px] text-amber-600 dark:text-amber-400 border border-amber-200 dark:border-amber-700 px-1 rounded",children:f}),e.jsx("span",{className:`text-[10px] font-normal rounded-full px-1.5 ${fe?"bg-[var(--bg-subtle)]":"bg-[var(--bg-subtle)] text-[var(--fg-muted)]"}`,children:xe})]},ee)})})}),e.jsxs("div",{className:"flex-1 overflow-y-auto pr-1 pb-6",children:[(!t?.candidates||Object.keys(t.candidates).length===0)&&!u&&e.jsxs("div",{className:"h-72 flex flex-col items-center justify-center bg-[var(--bg-surface)] rounded-2xl border border-dashed border-[var(--border-default)] text-[var(--fg-muted)]",children:[e.jsx("div",{className:"w-16 h-16 rounded-2xl bg-[var(--bg-subtle)] flex items-center justify-center mb-4",children:e.jsx(hs,{size:32,className:"text-[var(--fg-muted)]"})}),e.jsx("p",{className:"text-sm font-medium text-[var(--fg-secondary)]",children:c("candidates.noResults")}),e.jsx("p",{className:"mt-2 text-xs max-w-sm text-center leading-relaxed text-[var(--fg-muted)]",children:c("candidates.emptyHint")}),oe?e.jsxs(e.Fragment,{children:[x&&e.jsxs("button",{onClick:x,disabled:h,className:`mt-4 flex items-center gap-2 px-5 py-2.5 rounded-xl text-sm font-bold transition-all ${h?"text-[var(--fg-muted)] bg-[var(--bg-subtle)] cursor-not-allowed":"text-blue-600 dark:text-blue-400 bg-blue-500/10 border border-blue-500/20 hover:bg-blue-500/20"}`,children:[h?e.jsx(Ne,{size:16,className:"animate-spin"}):e.jsx(at,{size:16}),c(h?"common.loading":"candidates.rescanBtn")]}),e.jsx("p",{className:"mt-3 text-[11px] text-[var(--fg-muted)]",children:c("candidates.rescanHint")})]}):e.jsxs(e.Fragment,{children:[g&&e.jsxs("button",{onClick:g,disabled:h,className:`mt-4 flex items-center gap-2 px-5 py-2.5 rounded-xl text-sm font-bold transition-all ${h?"text-[var(--fg-muted)] bg-[var(--bg-subtle)] cursor-not-allowed":"text-violet-600 dark:text-violet-400 bg-violet-500/10 border border-violet-500/20 hover:bg-violet-500/20"}`,children:[h?e.jsx(Ne,{size:16,className:"animate-spin"}):e.jsx(Kt,{size:16}),c(h?"common.loading":"candidates.sourceBootstrap")]}),e.jsx("p",{className:"mt-3 text-[11px] text-[var(--fg-muted)]",children:c("candidates.emptyHintIde")})]})]}),(!t?.candidates||Object.keys(t.candidates).length===0)&&u&&e.jsxs("div",{className:"h-72 flex flex-col items-center justify-center bg-[var(--bg-surface)] rounded-2xl border border-dashed border-violet-500/30 text-[var(--fg-muted)]",children:[e.jsx("div",{className:"w-16 h-16 rounded-2xl bg-violet-500/10 flex items-center justify-center mb-4",children:e.jsx(Ne,{size:32,className:"text-violet-400 animate-spin"})}),e.jsx("p",{className:"text-sm font-medium text-violet-400",children:c("common.loading")}),e.jsx("p",{className:"mt-2 text-xs text-center leading-relaxed text-[var(--fg-muted)]",children:c("candidates.scanningHint")})]}),t&&pe&&de.filter(([ee])=>ee===pe).map(([ee,ce])=>{const f=s(ee),V=a(ee),xe=ls[ee]?c(ls[ee]):c("candidates.silent"),fe=N[ee]||{page:1,pageSize:12},C=fe.page,b=fe.pageSize,_=ce.items.sort((se,we)=>je.sort==="default"?0:je.sort==="score-desc"?(we.quality?.overall??0)-(se.quality?.overall??0):je.sort==="score-asc"?(se.quality?.overall??0)-(we.quality?.overall??0):je.sort==="confidence-desc"?(we.reasoning?.confidence??0)-(se.reasoning?.confidence??0):0),ne=_.length,$=Math.ceil(ne/b),y=(C-1)*b,te=_.slice(y,y+b),ge=se=>{v(we=>({...we,[ee]:{...fe,page:se}}))},he=se=>{v(we=>({...we,[ee]:{page:1,pageSize:se}}))},De=et[ee]||et.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-[var(--bg-surface)] border border-[var(--border-default)] shadow-sm",children:[e.jsxs("div",{className:"flex items-center gap-2 flex-1 min-w-0",children:[(()=>{const se=De?.icon||gs;return e.jsx(se,{size:18,className:De?.color||"text-blue-600"})})(),e.jsx("span",{className:"text-base font-bold text-[var(--fg-primary)] truncate",children:os[ee]?c(os[ee]):ee}),V&&e.jsx("span",{className:"text-[10px] font-bold text-amber-600 dark:text-amber-400 border border-amber-500/20 bg-amber-500/10 px-1.5 py-0.5 rounded",children:xe}),f&&!V&&e.jsx("span",{className:"text-[10px] font-bold text-[var(--fg-muted)] border border-[var(--border-default)] bg-[var(--bg-subtle)] px-1.5 py-0.5 rounded",children:"SHELL"}),e.jsxs("span",{className:"text-[11px] text-[var(--fg-muted)] flex items-center gap-1",children:[e.jsx(Ye,{size:11}),c("candidates.scannedAt",{time:Bt(ce.scanTime,c)||new Date(ce.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-[var(--bg-subtle)] border border-[var(--border-default)]",children:[e.jsx(pl,{size:12,className:"text-[var(--fg-muted)]"}),e.jsx(tt,{value:je.sort,onChange:se=>G(we=>({...we,sort:se})),options:[{value:"score-desc",label:`${c("candidates.sortScore")} ↓`},{value:"score-asc",label:`${c("candidates.sortScore")} ↑`},{value:"confidence-desc",label:`${c("candidates.sortConfidence")} ↓`},{value:"default",label:c("candidates.sortDefault")}],size:"xs",className:"border-none bg-transparent"})]}),e.jsx("div",{className:"h-4 w-px bg-[var(--border-default)]"}),e.jsx("button",{onClick:()=>p(te,ee),className:"text-[11px] font-bold text-blue-600 dark:text-blue-400 hover:text-blue-700 px-2.5 py-1.5 rounded-lg hover:bg-blue-500/10 transition-colors",children:c("candidates.approveCurrentPage")})]}),e.jsx("div",{className:"h-5 w-px bg-[var(--border-default)]"}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"text-[11px] text-[var(--fg-muted)] font-medium",children:c("candidates.totalCount",{count:ne})}),ne>0&&e.jsxs("span",{className:"text-[11px] text-emerald-600 font-medium ml-1.5 pl-2 border-l border-[var(--border-default)]",children:[c("candidates.confidence")," ",Math.round(ce.items.reduce((se,we)=>se+(we.reasoning?.confidence??0),0)/ne*100),"%"]})]}),e.jsx("div",{className:"ml-auto",children:e.jsxs("button",{onClick:()=>l(ee),className:"flex items-center gap-1 px-2.5 py-1.5 rounded-md text-[11px] transition-all text-[var(--fg-muted)] hover:text-red-600 hover:bg-red-50",title:c("candidates.deleteAll"),children:[e.jsx(Ke,{size:12}),c("candidates.deleteAll")]})})]}),e.jsx("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-3 items-start",children:te.map(se=>{const we=j===se.id,Oe=se.reasoning?.confidence??null,rt=(se.quality?.overall??0)>0?se.quality?.overall??null:null,ct=Ta[se.source||""]||{labelKey:se.source||"",color:"text-[var(--fg-secondary)] bg-[var(--bg-subtle)] border-[var(--border-default)]"},Xt=et[se.category||""]||et.All||{};return e.jsxs("div",{onClick:()=>A(we?null:se.id),className:`bg-[var(--bg-surface)] rounded-xl border overflow-hidden hover:shadow-lg transition-all duration-200 flex flex-col group cursor-pointer
81
81
  ${f?"opacity-75":""}
82
82
  ${we?"ring-2 ring-blue-300 border-blue-300 shadow-md":"border-[var(--border-default)] hover:border-[var(--border-emphasis)]"}`,children:[e.jsx("div",{className:"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 bg-[var(--bg-subtle)] ${Xt?.color||"text-[var(--fg-muted)]"} border-[var(--border-default)]`,children:[(()=>{const nt=Xt?.icon||Ge;return e.jsx(nt,{size:10})})(),se.category||"general"]}),se.knowledgeType&&e.jsx("span",{className:"text-[10px] font-medium px-1.5 py-0.5 rounded bg-indigo-500/10 text-indigo-600 dark:text-indigo-400 border border-indigo-500/20",children:se.knowledgeType}),se.source&&se.source!=="unknown"&&e.jsx("span",{className:`text-[10px] font-medium px-1.5 py-0.5 rounded border ${ct.color}`,children:ct.labelKey.startsWith("candidates.")?c(ct.labelKey):ct.labelKey}),se.complexity&&e.jsx("span",{className:`text-[10px] font-medium px-1.5 py-0.5 rounded border
83
83
  ${se.complexity==="advanced"?"bg-violet-500/10 text-violet-600 dark:text-violet-400 border-violet-500/20":se.complexity==="intermediate"?"bg-sky-500/10 text-sky-600 dark:text-sky-400 border-sky-500/20":"bg-emerald-500/10 text-emerald-600 dark:text-emerald-400 border-emerald-500/20"}`,children:se.complexity==="advanced"?c("knowledge.complexityAdvanced"):se.complexity==="intermediate"?c("knowledge.complexityIntermediate"):c("knowledge.complexityBeginner")})]}),e.jsx("h3",{className:"font-bold text-sm text-[var(--fg-primary)] leading-snug mb-1 line-clamp-1",children:se.title}),e.jsx("p",{className:"text-xs text-[var(--fg-secondary)] line-clamp-2 leading-relaxed",children:se.description||""})]}),e.jsxs("div",{className:"flex flex-col items-center gap-1 shrink-0",children:[e.jsx(Li,{value:Oe}),e.jsx("span",{className:"text-[9px] text-[var(--fg-muted)] font-medium",children:c("candidates.confidence")})]})]})}),se.reasoning?.whyStandard&&!/^Submitted via /i.test(se.reasoning.whyStandard)&&e.jsx("div",{className:"px-4 py-2 bg-gradient-to-r from-indigo-500/10 to-transparent border-t border-indigo-500/10",children:e.jsxs("div",{className:"flex items-start gap-1.5",children:[e.jsx(Mt,{size:12,className:"text-indigo-400 mt-0.5 shrink-0"}),e.jsx("p",{className:"text-[11px] text-indigo-600 dark:text-indigo-400 opacity-80 line-clamp-1 leading-relaxed",children:se.reasoning.whyStandard})]})}),rt!=null&&e.jsx("div",{className:"flex flex-wrap items-center gap-1.5 px-4 py-2 border-t border-[var(--border-default)]",children:e.jsxs("span",{className:"text-[10px] font-bold px-2 py-0.5 rounded-full bg-emerald-500/10 text-emerald-600 dark:text-emerald-400 border border-emerald-500/20 flex items-center gap-1",children:[e.jsx(ht,{size:10}),c("candidates.overallScore",{score:(rt*100).toFixed(0)+"%"})]})}),se.content?.pattern&&e.jsxs("div",{className:"overflow-hidden border-t border-[var(--border-default)]/60",children:[e.jsxs("div",{className:"flex items-center justify-between px-3 py-1.5",style:{background:"#282c34"},children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(At,{size:11,className:"text-[var(--fg-secondary)]"}),e.jsx("span",{className:"text-[10px] text-[var(--fg-muted)] font-mono uppercase tracking-wide",children:se.language||"code"})]}),e.jsx("span",{className:"text-[10px] text-[var(--fg-secondary)] font-mono tabular-nums",children:c("candidates.linesCount",{count:se.content.pattern.split(`
@@ -94,7 +94,7 @@ Skill 文档格式要求:
94
94
 
95
95
  `+t("aiChat.noReplyFallback",{defaultValue:"> AI 未能生成文字回复,以上是执行过程记录。"}):"",de=G||le||t("aiChat.requestFailed",{error:"Empty response"});d.current.push({role:"model",content:de}),l(R=>R.map(T=>T.id===U?{...T,content:de}:T))}catch(be){if(fs(be)){const me=t("aiChat.cancelled");l(je=>je.map(G=>G.id===U?{...G,content:me}:G))}else l(me=>me.map(je=>je.id===U?{...je,content:t("aiChat.requestFailed",{error:ke(be)})}:je))}finally{g.current=null}p(!1)},[J,i,u,c,t,s]),q=n.useCallback(N=>{N.key==="Enter"&&!N.shiftKey&&(N.preventDefault(),W())},[W]);return e.jsxs("div",{className:"flex-1 flex h-full bg-[var(--bg-subtle)]",children:[e.jsx("div",{className:`${B?"w-10":"w-64"} shrink-0 bg-[var(--bg-surface)] border-r border-[var(--border-default)] flex flex-col transition-all duration-200`,children:B?e.jsxs("div",{className:"flex flex-col items-center py-3 gap-2",children:[e.jsx("button",{onClick:()=>z(!1),className:"p-1.5 hover:bg-[var(--bg-subtle)] rounded-lg transition-colors text-[var(--fg-muted)] hover:text-[var(--fg-secondary)]",title:t("aiChat.expandTopics"),children:e.jsx(Ue,{size:16})}),e.jsx("button",{onClick:E,className:"p-1.5 hover:bg-[var(--accent-subtle)] rounded-lg transition-colors text-blue-500",title:t("aiChat.newTopic"),children:e.jsx(mt,{size:16})})]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"px-3 py-2.5 border-b border-[var(--border-default)] flex items-center justify-between shrink-0",children:[e.jsx("span",{className:"text-xs font-bold text-[var(--fg-secondary)] uppercase tracking-wider",children:t("aiChat.topicRecords")}),e.jsxs("div",{className:"flex items-center gap-0.5",children:[e.jsx("button",{onClick:E,className:"p-1.5 hover:bg-[var(--accent-subtle)] rounded-lg transition-colors text-[var(--fg-muted)] hover:text-blue-600",title:t("aiChat.newTopic"),children:e.jsx(mt,{size:14})}),e.jsx("button",{onClick:()=>z(!0),className:"p-1.5 hover:bg-[var(--bg-subtle)] rounded-lg transition-colors text-[var(--fg-muted)] hover:text-[var(--fg-secondary)]",title:t("common.collapse"),children:e.jsx(Xs,{size:14})})]})]}),e.jsx("div",{className:"flex-1 overflow-y-auto scrollbar-light",children:h.length===0?e.jsxs("div",{className:"px-4 py-8 text-center",children:[e.jsx(ut,{size:24,className:"text-[var(--fg-muted)] mx-auto mb-2"}),e.jsx("p",{className:"text-xs text-[var(--fg-muted)]",children:t("aiChat.noHistory")}),e.jsx("p",{className:"text-[10px] text-[var(--fg-muted)] mt-1",children:t("aiChat.autoSaveHint")})]}):e.jsx("div",{className:"py-1",children:h.map(N=>{const v=N.id===u,U=N.messages.filter(ae=>ae.role==="user").length;return e.jsx("div",{onClick:()=>L(N.id),className:`group mx-1.5 mb-0.5 px-3 py-2 rounded-lg cursor-pointer transition-colors ${v?"bg-[var(--accent-subtle)] border border-blue-200":"hover:bg-[var(--bg-subtle)] border border-transparent"}`,children:e.jsxs("div",{className:"flex items-start justify-between gap-1.5",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:`text-xs font-medium truncate leading-snug ${v?"text-blue-700":"text-[var(--fg-primary)]"}`,children:N.title}),e.jsxs("div",{className:"flex items-center gap-2 mt-0.5",children:[e.jsxs("span",{className:"text-[10px] text-[var(--fg-muted)] flex items-center gap-0.5",children:[e.jsx(Ye,{size:9}),kc(N.updatedAt,t)]}),U>0&&e.jsx("span",{className:"text-[10px] text-[var(--fg-muted)]",children:t("aiChat.messageCount",{n:U})})]})]}),e.jsx("button",{onClick:ae=>O(ae,N.id),className:`p-1 rounded transition-colors shrink-0 ${v?"text-blue-400 hover:text-red-500 hover:bg-red-50":"text-transparent group-hover:text-[var(--fg-muted)] hover:!text-red-500 hover:!bg-red-50"}`,title:t("aiChat.deleteTopic"),children:e.jsx(Ke,{size:12})})]})},N.id)})})}),h.length>0&&e.jsx("div",{className:"px-3 py-2 border-t border-[var(--border-default)] shrink-0",children:e.jsx("span",{className:"text-[10px] text-[var(--fg-muted)]",children:t("aiChat.topicCount",{count:h.length})})})]})}),e.jsxs("div",{className:"flex-1 flex flex-col min-w-0",children:[e.jsxs("div",{className:"px-6 py-3 border-b border-[var(--border-default)] bg-[var(--bg-surface)] flex items-center justify-between shrink-0",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-9 h-9 rounded-xl bg-gradient-to-br from-blue-50 to-indigo-50 border border-blue-100 flex items-center justify-center",children:e.jsx(ut,{className:"text-blue-600",size:18})}),e.jsxs("div",{children:[e.jsx("h2",{className:"text-sm font-bold text-[var(--fg-primary)]",children:m?m.title:"AI Chat"}),e.jsx("p",{className:"text-[11px] text-[var(--fg-muted)]",children:t("aiChat.askAnything")})]})]}),o.length>0&&e.jsxs("button",{onClick:E,className:"flex items-center gap-1.5 px-3 py-1.5 text-xs font-medium text-[var(--fg-secondary)] hover:text-blue-600 hover:bg-[var(--accent-subtle)] rounded-lg transition-colors border border-[var(--border-default)] hover:border-blue-200",children:[e.jsx(mt,{size:14}),t("aiChat.newTopic")]})]}),e.jsx("div",{className:"flex-1 overflow-y-auto min-h-0 scrollbar-light",children:e.jsxs("div",{className:"max-w-3xl mx-auto p-6 space-y-4",children:[o.length===0&&e.jsxs("div",{className:"flex flex-col items-center justify-center py-20 text-center",children:[e.jsx("div",{className:"w-16 h-16 rounded-2xl bg-gradient-to-br from-blue-50 to-indigo-50 border border-blue-100 flex items-center justify-center mb-4",children:e.jsx(ut,{className:"text-blue-500",size:28})}),e.jsx("h3",{className:"text-base font-bold text-[var(--fg-primary)] mb-2",children:t("aiChat.startChat")}),e.jsx("p",{className:"text-sm text-[var(--fg-muted)] max-w-md leading-relaxed mb-5",children:t("aiChat.emptyDescLong")}),e.jsx("div",{className:"flex flex-wrap gap-2 justify-center",children:[{key:"analyzeArch",label:t("aiChat.quickPrompts.analyzeArch")},{key:"findDuplicates",label:t("aiChat.quickPrompts.findDuplicates")},{key:"suggestOptimize",label:t("aiChat.quickPrompts.suggestOptimize")},{key:"summarize",label:t("aiChat.quickPromptSummarize")}].map(N=>e.jsx("button",{onClick:()=>{w(N.label),P.current?.focus()},className:"text-xs px-3.5 py-2 rounded-lg bg-[var(--bg-surface)] border border-[var(--border-default)] text-[var(--fg-secondary)] hover:bg-[var(--accent-subtle)] hover:text-blue-700 hover:border-blue-200 transition-colors shadow-sm",children:N.label},N.key))})]}),o.map(N=>e.jsx("div",{className:`flex ${N.role==="user"?"justify-end":"justify-start"}`,children:e.jsxs("div",{className:`max-w-[80%] ${N.role==="user"?"bg-[var(--accent-subtle)] text-[var(--fg-primary)] rounded-2xl rounded-tr-md px-4 py-2.5":N.role==="system"?"bg-[var(--bg-subtle)] border border-[var(--border-default)] text-[var(--fg-secondary)] rounded-2xl px-4 py-2.5 w-full":"bg-[var(--bg-surface)] border border-[var(--border-default)] rounded-2xl rounded-tl-md px-4 py-3 shadow-sm w-full"}`,children:[N.role==="assistant"&&e.jsxs("div",{className:"flex items-center gap-1.5 mb-2",children:[e.jsx(Mt,{size:13,className:"text-blue-500"}),e.jsx("span",{className:"text-[11px] font-bold text-blue-600",children:t("aiChat.aiAssistant")})]}),N.role==="assistant"&&!N.diff?e.jsx(Qt,{content:N.content,className:"text-sm text-[var(--fg-primary)]"}):e.jsx("p",{className:`text-sm leading-relaxed whitespace-pre-wrap ${N.role==="user"?"":"text-[var(--fg-secondary)]"}`,children:N.content}),N.diff&&N.diff.length>0&&e.jsx("div",{className:"space-y-2 mt-2",children:N.diff.map(v=>e.jsx(Nc,{d:v},v.field))})]})},N.id)),i&&e.jsx("div",{className:"flex justify-start",children:e.jsx("div",{className:"bg-[var(--bg-surface)] border border-[var(--border-default)] rounded-2xl rounded-tl-md px-4 py-3 shadow-sm",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Ne,{size:14,className:"animate-spin text-blue-500"}),e.jsx("span",{className:"text-sm text-[var(--fg-secondary)]",children:t("aiChat.thinking")}),g.current&&e.jsx("button",{onClick:()=>g.current?.abort(),className:"ml-1 px-1.5 py-0.5 text-[10px] font-bold text-red-500 border border-red-200 rounded hover:bg-red-50 transition-colors",children:t("common.stop")})]})})}),e.jsx("div",{ref:I})]})}),e.jsx("div",{className:"border-t border-[var(--border-default)] bg-[var(--bg-surface)] shrink-0",children:e.jsxs("div",{className:"max-w-3xl mx-auto px-6 py-3",children:[e.jsxs("div",{className:"flex gap-2",children:[e.jsx("textarea",{ref:P,value:J,onChange:N=>w(N.target.value),onKeyDown:q,placeholder:t("aiChat.inputPlaceholder"),rows:2,className:"flex-1 px-4 py-2.5 text-sm border border-[var(--border-default)] rounded-xl focus:outline-none focus:ring-2 focus:ring-blue-200 focus:border-blue-400 resize-none placeholder:text-[var(--fg-muted)]",disabled:i}),e.jsx("button",{onClick:W,disabled:!J.trim()||i,className:"self-stretch w-10 flex items-center justify-center rounded-xl bg-gradient-to-r from-blue-500 to-indigo-600 hover:from-blue-600 hover:to-indigo-700 text-white disabled:opacity-40 disabled:cursor-not-allowed transition-all shadow-sm shrink-0",children:e.jsx(Zs,{size:16})})]}),e.jsx("p",{className:"text-[10px] text-[var(--fg-muted)] mt-1.5",children:t("aiChat.inputHint")})]})})]})]})};function Sc(){return e.jsxs("div",{className:"space-y-0",children:[e.jsxs("div",{className:"flex items-center gap-4 px-4 py-3 border-b border-[var(--border-default)]",children:[e.jsx(Xe,{className:"h-4 w-4 rounded-sm"}),e.jsx(Xe,{className:"h-3.5 w-[30%]"}),e.jsx(Xe,{className:"h-3.5 w-[12%]"}),e.jsx(Xe,{className:"h-3.5 w-[12%]"}),e.jsx(Xe,{className:"h-3.5 w-[15%]"}),e.jsx(Xe,{className:"h-3.5 w-6"})]}),Array.from({length:8}).map((t,s)=>e.jsxs("div",{className:"flex items-center gap-4 px-4 py-3 border-b border-[var(--border-default)]",children:[e.jsx(Xe,{className:"h-4 w-4 rounded-sm"}),e.jsx(Xe,{className:"h-3.5 w-[28%]",style:{width:`${24+s%3*8}%`}}),e.jsx(Xe,{className:"h-5 w-14 rounded-full"}),e.jsx(Xe,{className:"h-5 w-16 rounded-full"}),e.jsx(Xe,{className:"h-3.5 w-[12%]"}),e.jsx(Xe,{className:"h-5 w-5 rounded"})]},s))]})}const lt={pending:{labelKey:"lifecycle.pending",color:"text-gray-600 dark:text-gray-400",bg:"bg-gray-500/8 dark:bg-gray-500/15",border:"border-gray-300 dark:border-gray-600",hoverBorder:"hover:border-gray-400 dark:hover:border-gray-500",badgeBg:"bg-gray-500/15 dark:bg-gray-500/25",badgeColor:"text-gray-600 dark:text-gray-300",icon:Ye},staging:{labelKey:"lifecycle.staging",color:"text-blue-600 dark:text-blue-400",bg:"bg-blue-500/8 dark:bg-blue-500/15",border:"border-blue-300 dark:border-blue-600",hoverBorder:"hover:border-blue-400 dark:hover:border-blue-500",badgeBg:"bg-blue-500/15 dark:bg-blue-500/25",badgeColor:"text-blue-600 dark:text-blue-300",icon:Dr},active:{labelKey:"lifecycle.active",color:"text-green-600 dark:text-green-400",bg:"bg-green-500/8 dark:bg-green-500/15",border:"border-green-300 dark:border-green-600",hoverBorder:"hover:border-green-400 dark:hover:border-green-500",badgeBg:"bg-green-500/15 dark:bg-green-500/25",badgeColor:"text-green-600 dark:text-green-300",icon:ht},evolving:{labelKey:"lifecycle.evolving",color:"text-purple-600 dark:text-purple-400",bg:"bg-purple-500/8 dark:bg-purple-500/15",border:"border-purple-300 dark:border-purple-600",hoverBorder:"hover:border-purple-400 dark:hover:border-purple-500",badgeBg:"bg-purple-500/15 dark:bg-purple-500/25",badgeColor:"text-purple-600 dark:text-purple-300",icon:Le},decaying:{labelKey:"lifecycle.decaying",color:"text-orange-600 dark:text-orange-400",bg:"bg-orange-500/8 dark:bg-orange-500/15",border:"border-orange-300 dark:border-orange-600",hoverBorder:"hover:border-orange-400 dark:hover:border-orange-500",badgeBg:"bg-orange-500/15 dark:bg-orange-500/25",badgeColor:"text-orange-600 dark:text-orange-300",icon:qs},deprecated:{labelKey:"lifecycle.deprecated",color:"text-red-600 dark:text-red-400",bg:"bg-red-500/8 dark:bg-red-500/15",border:"border-red-300 dark:border-red-600",hoverBorder:"hover:border-red-400 dark:hover:border-red-500",badgeBg:"bg-red-500/15 dark:bg-red-500/25",badgeColor:"text-red-600 dark:text-red-300",icon:qt}},$t={rule:{labelKey:"kind.rule",color:"text-red-700",bg:"bg-red-50",border:"border-red-200",icon:Ve},pattern:{labelKey:"kind.pattern",color:"text-violet-700",bg:"bg-violet-50",border:"border-violet-200",icon:St},fact:{labelKey:"kind.fact",color:"text-cyan-700",bg:"bg-cyan-50",border:"border-cyan-200",icon:qe}},Ac={pending:[{action:"publish",labelKey:"knowledge.actionPublish",color:"text-green-700",bg:"bg-green-50 hover:bg-green-100",icon:ht},{action:"stage",labelKey:"knowledge.actionStage",color:"text-blue-700",bg:"bg-blue-50 hover:bg-blue-100",icon:Dr},{action:"deprecate",labelKey:"knowledge.actionDeprecate",color:"text-red-700",bg:"bg-red-50 hover:bg-red-100",icon:qt,needsReason:!0}],staging:[{action:"publish",labelKey:"knowledge.actionPublish",color:"text-green-700",bg:"bg-green-50 hover:bg-green-100",icon:ht},{action:"reactivate",labelKey:"knowledge.actionUnstage",color:"text-gray-700",bg:"bg-gray-50 hover:bg-gray-100",icon:$s}],active:[{action:"evolve",labelKey:"knowledge.actionEvolve",color:"text-purple-700",bg:"bg-purple-50 hover:bg-purple-100",icon:Le},{action:"decay",labelKey:"knowledge.actionDecay",color:"text-orange-700",bg:"bg-orange-50 hover:bg-orange-100",icon:qs,needsReason:!0},{action:"deprecate",labelKey:"knowledge.actionDeprecate",color:"text-red-700",bg:"bg-red-50 hover:bg-red-100",icon:qt,needsReason:!0}],evolving:[{action:"restore",labelKey:"knowledge.actionRestore",color:"text-green-700",bg:"bg-green-50 hover:bg-green-100",icon:ht},{action:"decay",labelKey:"knowledge.actionDecay",color:"text-orange-700",bg:"bg-orange-50 hover:bg-orange-100",icon:qs,needsReason:!0}],decaying:[{action:"restore",labelKey:"knowledge.actionRestore",color:"text-green-700",bg:"bg-green-50 hover:bg-green-100",icon:ht},{action:"deprecate",labelKey:"knowledge.actionDeprecate",color:"text-red-700",bg:"bg-red-50 hover:bg-red-100",icon:qt,needsReason:!0}],deprecated:[{action:"reactivate",labelKey:"knowledge.actionReactivate",color:"text-green-700",bg:"bg-green-50 hover:bg-green-100",icon:$s}]};function Ot(t,s){if(!t)return"";const a=t<1e12?t*1e3:t,r=new Date(a);if(isNaN(r.getTime())||r.getFullYear()<2e3)return"";const l=Date.now()-a;if(l<0)return r.toLocaleDateString();const i=Math.floor(l/6e4);if(i<1)return s("candidates.timeJustNow");if(i<60)return s("candidates.timeMinutesAgo",{n:i});const p=Math.floor(i/60);if(p<24)return s("candidates.timeHoursAgo",{n:p});const d=Math.floor(p/24);return d<7?s("candidates.timeDaysAgo",{n:d}):r.toLocaleDateString()}function Dc(t){return t==null?{ring:"stroke-[var(--border-default)]",text:"text-[var(--fg-muted)]",bg:"bg-[var(--bg-subtle)]",labelKey:""}:t>=.8?{ring:"stroke-emerald-500",text:"text-emerald-700",bg:"bg-emerald-50",labelKey:"candidates.confidenceHighLabel"}:t>=.6?{ring:"stroke-blue-500",text:"text-blue-700",bg:"bg-blue-50",labelKey:"candidates.confidenceMediumLabel"}:t>=.4?{ring:"stroke-amber-500",text:"text-amber-700",bg:"bg-amber-50",labelKey:"candidates.confidenceMediumLowLabel"}:{ring:"stroke-red-500",text:"text-red-700",bg:"bg-red-50",labelKey:"candidates.confidenceLowLabel"}}function Rc(t,s=4){return t?la(t).split(`
96
96
  `).slice(0,s).join(`
97
- `):""}const Oa={"bootstrap-scan":{labelKey:"knowledge.sourceBootstrap",color:"text-violet-600 bg-violet-50 border-violet-200"},mcp:{labelKey:"knowledge.sourceMcp",color:"text-blue-600 bg-blue-50 border-blue-200"},manual:{labelKey:"knowledge.sourceManual",color:"text-emerald-600 bg-emerald-50 border-emerald-200"},"file-watcher":{labelKey:"knowledge.sourceFileWatcher",color:"text-orange-600 bg-orange-50 border-orange-200"},clipboard:{labelKey:"knowledge.sourceClipboard",color:"text-pink-600 bg-pink-50 border-pink-200"},cli:{labelKey:"knowledge.sourceCli",color:"text-[var(--fg-secondary)] bg-[var(--bg-subtle)] border-[var(--border-default)]"},agent:{labelKey:"knowledge.sourceAgent",color:"text-violet-600 bg-violet-50 border-violet-200"},submit_with_check:{labelKey:"knowledge.sourceSubmitCheck",color:"text-teal-600 bg-teal-50 border-teal-200"}},Ic={"source file deleted (orphan)":"源文件已删除(孤儿条目)"};function Tc(t){return Ic[t]??t}const Ec=({onRefresh:t,idTitleMap:s})=>{const{t:a}=Ae(),r=f=>({pending:a("knowledge.lifecyclePending"),staging:a("knowledge.lifecycleStaging"),active:a("knowledge.lifecycleActive"),evolving:a("knowledge.lifecycleEvolving"),decaying:a("knowledge.lifecycleDecaying"),deprecated:a("knowledge.lifecycleDeprecated")})[f]||f,o=f=>({publish:a("knowledge.actionPublish"),stage:a("knowledge.actionStage"),deprecate:a("knowledge.actionDeprecate"),reactivate:a("knowledge.actionReactivate"),evolve:a("knowledge.actionEvolve"),decay:a("knowledge.actionDecay")})[f]||f,[l,i]=n.useState([]),[p,d]=n.useState(null),[g,x]=n.useState({}),[h,u]=n.useState(!0),[m,c]=n.useState(1),[j,A]=n.useState(12),[D,I]=n.useState(0),[P,J]=n.useState(""),[w,B]=n.useState(""),[z,k]=n.useState(""),[E,L]=n.useState(""),[O,W]=n.useState(""),{isWide:q,toggle:N}=ia(),[v,U]=n.useState(null),[ae,be]=n.useState(!1),[me,je]=n.useState(new Set),[G,le]=n.useState(!1),de=n.useRef(!0);n.useEffect(()=>(de.current=!0,()=>{de.current=!1}),[]);const R=n.useCallback(async()=>{u(!0);try{const f=await Q.knowledgeList({page:m,limit:j,lifecycle:P||void 0,kind:w||void 0,category:z||void 0,keyword:E||void 0});de.current&&(i(f.data||[]),I(f.pagination?.total||0))}catch(f){re(ke(f,a("knowledge.loadFailed")),{title:a("common.loadFailed"),type:"error"})}finally{de.current&&u(!1)}},[m,j,P,w,z,E]),T=n.useCallback(async()=>{try{const f=await Q.knowledgeStats();de.current&&d(f)}catch{}},[]),X=n.useCallback(async()=>{try{const f=await Q.getKnowledgeLifecycle();de.current&&x(f.counts||{})}catch{}},[]);n.useEffect(()=>{R()},[R]),n.useEffect(()=>{T()},[T]),n.useEffect(()=>{X()},[X]),n.useEffect(()=>{const f=setTimeout(()=>{L(O),c(1)},300);return()=>clearTimeout(f)},[O]),n.useEffect(()=>{c(1)},[P,w,z]);const oe=n.useCallback(()=>{R(),T(),X(),t?.()},[R,T,X,t]),pe=n.useMemo(()=>{const f=new Map;if(s)for(const[V,xe]of Object.entries(s))f.set(V,xe);for(const V of l)V.id&&V.title&&f.set(V.id,V.title);return f},[l,s]),ue=async(f,V,xe)=>{be(!0);try{const fe=await Q.knowledgeLifecycle(f.id,V,xe);re(`${f.title} → ${a(lt[fe.lifecycle]?.labelKey||"")||fe.lifecycle}`,{title:a("knowledge.operationSuccess")}),i(C=>C.map(b=>b.id===f.id?fe:b)),v?.id===f.id&&U(fe),T()}catch(fe){re(ke(fe,a("common.operationFailed")),{title:a("common.operationFailed"),type:"error"})}finally{de.current&&be(!1)}},M=async f=>{if(confirm(a("knowledge.deleteConfirmMsg",{title:f.title})))try{await Q.knowledgeDelete(f.id),re(a("knowledge.deleteSuccess",{title:f.title}),{title:a("common.delete")}),i(V=>V.filter(xe=>xe.id!==f.id)),v?.id===f.id&&U(null),T()}catch(V){re(ke(V,a("knowledge.deleteFailed")),{title:a("knowledge.deleteFailed"),type:"error"})}},Ce=["pending","staging"],F=async()=>{if(me.size===0)return;const f=l.filter(V=>me.has(V.id)&&Ce.includes(V.lifecycle)).map(V=>V.id);if(f.length===0){re(a("knowledge.noPublishable"),{title:a("knowledge.batchPublish"),type:"info"});return}le(!0);try{const V=await Q.knowledgeBatchPublish(f);re(a("knowledge.batchPublishResult",{success:V.successCount,fail:V.failureCount}),{title:a("knowledge.batchPublish")}),je(new Set),oe()}catch(V){re(ke(V,a("knowledge.batchPublishFailed")),{title:a("common.operationFailed"),type:"error"})}finally{le(!1)}},Se=async()=>{le(!0);try{const V=((await Q.knowledgeList({lifecycle:"pending",limit:500})).data||[]).filter(fe=>fe.autoApprovable).map(fe=>fe.id);if(V.length===0){re(a("knowledge.noAutoApprovable"),{title:a("knowledge.noPublishable")});return}const xe=await Q.knowledgeBatchPublish(V);re(a("knowledge.autoPublishResult",{count:xe.successCount}),{title:a("knowledge.batchPublishComplete")}),oe()}catch(f){re(ke(f,a("knowledge.batchPublishFailed")),{title:a("common.operationFailed"),type:"error"})}finally{le(!1)}},Te=async()=>{if(me.size===0)return;const f=l.filter(V=>me.has(V.id)&&(V.lifecycle==="active"||V.lifecycle==="evolving")).map(V=>V.id);if(f.length===0){re(a("knowledge.noDeprecatable"),{title:a("knowledge.batchDeprecate"),type:"info"});return}le(!0);try{const V=await Q.knowledgeBatchDeprecate(f);re(a("knowledge.batchDeprecateResult",{success:V.successCount,fail:V.failureCount}),{title:a("knowledge.batchDeprecate")}),je(new Set),oe()}catch(V){re(ke(V,a("knowledge.batchDeprecateFailed")),{title:a("common.operationFailed"),type:"error"})}finally{le(!1)}},Fe=async()=>{if(me.size!==0&&confirm(a("knowledge.batchDeleteConfirm",{count:me.size}))){le(!0);try{const f=await Q.knowledgeBatchDelete([...me]);re(a("knowledge.batchDeleteResult",{success:f.deletedCount,fail:f.failureCount}),{title:a("knowledge.batchDelete")}),je(new Set),oe()}catch(f){re(ke(f,a("knowledge.batchDeleteFailed")),{title:a("common.operationFailed"),type:"error"})}finally{le(!1)}}},Me=f=>{je(V=>{const xe=new Set(V);return xe.has(f)?xe.delete(f):xe.add(f),xe})},ee=()=>{me.size===l.length?je(new Set):je(new Set(l.map(f=>f.id)))},ce=(f,V)=>{const xe=prompt(a("knowledge.deprecateReasonPrompt"));xe&&ue(f,V,xe)};return e.jsxs("div",{className:"space-y-4 pb-6",children:[(()=>{const f=g;if(!Object.values(f).some(_=>_>0)&&!p)return null;const xe=_=>f[_]??p?.[_]??0,fe=({stateKey:_,onClick:ne})=>{const $=lt[_];if(!$)return null;const y=$.icon,te=xe(_),ge=P===_;return e.jsxs("button",{onClick:ne,className:`flex items-center gap-1.5 px-3 py-1.5 rounded-lg border text-xs font-medium transition-colors whitespace-nowrap ${ge?`${$.bg} ${$.border} ${$.color} shadow-sm`:`border-transparent ${$.hoverBorder} text-[var(--fg-secondary)]`}`,children:[e.jsx(y,{size:14,className:ge?"":"opacity-60"}),e.jsx("span",{children:r(_)}),e.jsx("span",{className:`ml-0.5 inline-flex items-center justify-center min-w-[20px] h-5 px-1.5 rounded text-[11px] font-bold ${$.badgeBg} ${$.badgeColor}`,children:te})]})},C=()=>e.jsx("span",{className:"text-[var(--fg-muted)] text-xs opacity-40 select-none",children:"→"}),b=_=>J(P===_?"":_);return e.jsxs("div",{className:"flex items-center gap-x-1.5 gap-y-2 flex-wrap text-[var(--fg-secondary)]",children:[e.jsx(fe,{stateKey:"pending",onClick:()=>b("pending")}),e.jsx(C,{}),e.jsx(fe,{stateKey:"staging",onClick:()=>b("staging")}),e.jsx(C,{}),e.jsx(fe,{stateKey:"active",onClick:()=>b("active")}),e.jsx(C,{}),e.jsx(fe,{stateKey:"evolving",onClick:()=>b("evolving")}),e.jsx("span",{className:"mx-1.5 h-4 border-l border-[var(--border-default)]"}),e.jsx(fe,{stateKey:"decaying",onClick:()=>b("decaying")}),e.jsx(C,{}),e.jsx(fe,{stateKey:"deprecated",onClick:()=>b("deprecated")})]})})(),e.jsxs("div",{className:"flex flex-wrap items-center gap-3",children:[e.jsxs("div",{className:"relative flex-1 min-w-[200px] max-w-md",children:[e.jsx(xt,{className:"absolute left-3 top-1/2 -translate-y-1/2 text-[var(--fg-muted)]",size:16}),e.jsx("input",{type:"text",placeholder:a("knowledge.searchPlaceholder"),value:O,onChange:f=>W(f.target.value),className:"w-full pl-9 pr-3 py-2 rounded-lg border border-[var(--border-default)] text-sm focus:outline-none focus:ring-2 focus:ring-blue-300"})]}),e.jsx("div",{className:"flex gap-1",children:Object.entries($t).map(([f,V])=>{const xe=V.icon;return e.jsxs("button",{onClick:()=>B(w===f?"":f),className:`flex items-center gap-1 px-2.5 py-1.5 rounded-md text-xs font-medium border transition-all ${w===f?`${V.bg} ${V.border} ${V.color}`:"bg-[var(--bg-surface)] border-[var(--border-default)] text-[var(--fg-secondary)] hover:bg-[var(--bg-subtle)]"}`,children:[e.jsx(xe,{size:12}),a(V.labelKey)]},f)})}),e.jsx(tt,{value:z,onChange:f=>k(f),options:[{value:"",label:a("knowledge.allCategories")},...["View","Service","Tool","Model","Network","Storage","UI","Utility"].map(f=>({value:f,label:f}))],size:"sm",className:"text-xs"}),e.jsx("button",{onClick:oe,className:"p-2 rounded-md text-[var(--fg-muted)] hover:bg-[var(--bg-subtle)]",title:a("common.refresh"),children:e.jsx(at,{size:16})}),me.size>0&&(()=>{const f=l.filter(xe=>me.has(xe.id)&&Ce.includes(xe.lifecycle)).length,V=l.filter(xe=>me.has(xe.id)&&(xe.lifecycle==="active"||xe.lifecycle==="evolving")).length;return e.jsxs("div",{className:"flex items-center gap-2 ml-auto",children:[e.jsx("span",{className:"text-xs text-[var(--fg-secondary)]",children:a("knowledge.selectedCount",{count:me.size})}),f>0&&e.jsxs("button",{onClick:F,disabled:G,className:"px-2.5 py-1 text-xs font-medium text-green-700 bg-green-50 border border-green-200 rounded-md hover:bg-green-100 disabled:opacity-50",children:[G?e.jsx(Ne,{size:12,className:"animate-spin"}):a("knowledge.batchPublish")," (",f,")"]}),V>0&&e.jsxs("button",{onClick:Te,disabled:G,className:"px-2.5 py-1 text-xs font-medium text-amber-700 bg-amber-50 border border-amber-200 rounded-md hover:bg-amber-100 disabled:opacity-50 flex items-center gap-1",children:[G?e.jsx(Ne,{size:12,className:"animate-spin"}):e.jsx(qt,{size:12}),a("knowledge.batchDeprecate")," (",V,")"]}),e.jsxs("button",{onClick:Fe,disabled:G,className:"px-2.5 py-1 text-xs font-medium text-red-700 bg-red-50 border border-red-200 rounded-md hover:bg-red-100 disabled:opacity-50 flex items-center gap-1",children:[G?e.jsx(Ne,{size:12,className:"animate-spin"}):e.jsx(Ke,{size:12}),a("knowledge.batchDelete")," (",me.size,")"]}),e.jsx("button",{onClick:()=>je(new Set),className:"p-1 text-[var(--fg-muted)] hover:text-[var(--fg-primary)]",children:e.jsx(ze,{size:14})})]})})(),me.size===0&&l.some(f=>f.lifecycle==="pending")&&e.jsxs("button",{onClick:Se,disabled:G,className:"ml-auto px-3 py-1.5 text-xs font-medium text-cyan-700 bg-cyan-50 border border-cyan-200 rounded-md hover:bg-cyan-100 disabled:opacity-50 flex items-center gap-1.5",children:[G?e.jsx(Ne,{size:12,className:"animate-spin"}):e.jsx(Be,{size:12}),a("knowledge.quickBatchPublish")]})]}),h?e.jsx(Sc,{}):l.length===0?e.jsxs("div",{className:"flex flex-col items-center justify-center py-20 text-[var(--fg-muted)]",children:[e.jsx(Qs,{size:48,className:"mb-4 opacity-30"}),e.jsx("p",{className:"text-sm",children:a("knowledge.noResults")}),(E||P||w||z)&&e.jsx("button",{onClick:()=>{W(""),J(""),B(""),k("")},className:"mt-2 text-xs text-blue-500 hover:text-blue-700",children:a("knowledge.clearFilters")})]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center gap-2 px-1",children:[e.jsx("input",{type:"checkbox",checked:me.size===l.length&&l.length>0,onChange:ee,className:"rounded border-[var(--border-default)]"}),e.jsx("span",{className:"text-xs text-[var(--fg-muted)]",children:a("knowledge.selectAll")}),e.jsx("span",{className:"text-xs text-[var(--fg-muted)] ml-auto",children:a("knowledge.totalCount",{count:D})})]}),e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4 items-start",children:l.map(f=>{const V=lt[f.lifecycle]||lt.pending,xe=$t[f.kind]||$t.pattern,fe=V.icon,C=xe.icon,b=Dc(f.reasoning?.confidence);return e.jsxs("div",{onClick:()=>U(f),className:`group bg-[var(--bg-surface)] rounded-xl border shadow-sm hover:shadow-md cursor-pointer transition-all overflow-hidden ${v?.id===f.id?"ring-2 ring-blue-300 border-blue-200":"border-[var(--border-default)]"}`,children:[e.jsxs("div",{className:"px-4 pt-3 pb-2",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1.5",children:[e.jsx("input",{type:"checkbox",checked:me.has(f.id),onChange:_=>{_.stopPropagation(),Me(f.id)},onClick:_=>_.stopPropagation(),className:"rounded border-[var(--border-default)]"}),e.jsxs("span",{className:`inline-flex items-center gap-1 px-1.5 py-0.5 rounded text-[10px] font-medium ${V.bg} ${V.color} ${V.border} border`,children:[e.jsx(fe,{size:10}),r(f.lifecycle)]}),e.jsxs("span",{className:`inline-flex items-center gap-1 px-1.5 py-0.5 rounded text-[10px] font-medium ${xe.bg} ${xe.color} ${xe.border} border`,children:[e.jsx(C,{size:10}),a(xe.labelKey)]}),f.category&&e.jsx("span",{className:"text-[10px] text-[var(--fg-muted)]",children:f.category}),e.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded ${b.bg} ${b.text}`,children:f.reasoning?.confidence!=null?`${Math.round(f.reasoning.confidence*100)}%`:"—"}),f.autoApprovable&&f.lifecycle==="pending"&&e.jsxs("span",{className:"inline-flex items-center gap-0.5 text-[10px] px-1.5 py-0.5 rounded bg-cyan-50 text-cyan-600 border border-cyan-200",children:[e.jsx(Be,{size:9}),a("knowledge.autoApprovable")]})]}),e.jsx("h3",{className:"text-sm font-bold text-[var(--fg-primary)] mb-1 break-words leading-snug",children:f.title}),(f.description||f.content?.rationale)&&e.jsx("p",{className:"text-xs text-[var(--fg-secondary)] line-clamp-2 leading-relaxed",children:f.description||f.content?.rationale||""}),f.content?.pattern&&e.jsx("pre",{className:"mt-1.5 text-[10px] text-[var(--fg-secondary)] bg-[var(--bg-subtle)] rounded p-1.5 line-clamp-3 font-mono overflow-hidden",children:Rc(f.content.pattern,3)})]}),e.jsxs("div",{className:"px-4 py-2 bg-[var(--bg-subtle)] border-t border-[var(--border-default)] flex items-center gap-2",children:[f.tags?.slice(0,3).map(_=>e.jsx("span",{className:"text-[10px] px-1.5 py-0.5 rounded bg-blue-50 text-blue-600 border border-blue-100",children:_},_)),f.tags&&f.tags.length>3&&e.jsxs("span",{className:"text-[10px] text-[var(--fg-muted)]",children:["+",f.tags.length-3]}),e.jsxs("span",{className:"text-[10px] text-[var(--fg-muted)] ml-auto",children:[f.trigger&&e.jsx("span",{className:"text-blue-400 mr-2",children:f.trigger}),f.source&&e.jsx("span",{className:"mr-2",children:f.source}),Ot(f.updatedAt,a)]})]})]},f.id)})}),e.jsx(ca,{currentPage:m,totalPages:Math.ceil(D/j),onPageChange:c,pageSize:j,onPageSizeChange:f=>{A(f),c(1)},totalItems:D})]}),v&&(()=>{const f=lt[v.lifecycle]||lt.pending,V=$t[v.kind]||$t.pattern,xe=et[v.category||""]||et.All||{},fe=v.reasoning,C=l.findIndex(y=>y.id===v.id),b=C>0,_=C<l.length-1,ne=()=>{b&&U(l[C-1])},$=()=>{_&&U(l[C+1])};return e.jsxs(Ie,{open:!!v,onClose:()=>U(null),size:q?"lg":"md",children:[e.jsxs(Ie.Header,{title:v.title,leading:e.jsx("button",{onClick:()=>{M(v),U(null)},title:a("common.delete"),className:"p-1.5 text-[var(--fg-muted)] hover:text-red-500 rounded-md transition-colors opacity-30 hover:opacity-100 shrink-0",children:e.jsx(Ke,{size:14})}),children:[e.jsx(Ie.Nav,{currentIndex:C,total:l.length,onPrev:ne,onNext:$,hasPrev:b,hasNext:_}),e.jsxs(Ie.HeaderActions,{children:[e.jsx(Ie.WidthToggle,{isWide:q,onToggle:N,title:a(q?"knowledge.narrow":"knowledge.widen")}),e.jsx(Ie.CloseButton,{onClose:()=>U(null)})]})]}),e.jsxs(Ie.Body,{children:[v.rejectionReason&&e.jsxs("div",{className:"px-6 py-3 border-b border-[var(--border-default)] bg-red-500/10",children:[e.jsx("label",{className:"text-[10px] font-bold text-red-400 uppercase mb-1.5 block",children:a("knowledge.rejectionReason")}),e.jsx("p",{className:"text-xs text-red-500 dark:text-red-400",children:Tc(v.rejectionReason)})]}),e.jsx(da,{badges:(()=>{const y=[];return y.push({label:r(v.lifecycle),className:`${f.bg} ${f.color} ${f.border}`,icon:f.icon}),y.push({label:a(V.labelKey),className:`${V.bg} ${V.color} ${V.border}`,icon:V.icon}),y.push({label:v.category||"general",className:`font-bold uppercase ${xe?.bg||"bg-[var(--bg-subtle)]"} ${xe?.color||"text-[var(--fg-muted)]"} ${xe?.border||"border-[var(--border-default)]"}`}),v.knowledgeType&&y.push({label:v.knowledgeType,className:"bg-purple-50 text-purple-700 border-purple-200"}),v.language&&y.push({label:v.language,className:"uppercase font-bold text-[var(--fg-secondary)] bg-[var(--bg-subtle)] border-[var(--border-default)]"}),v.trigger&&y.push({label:v.trigger,className:"font-mono font-bold bg-amber-50 text-amber-700 border-amber-200"}),y})(),metadata:(()=>{const y=[];return v.scope&&y.push({icon:Ct,iconClass:"text-teal-400",label:a("knowledge.scope"),value:v.scope==="universal"?a("knowledge.scopeUniversal"):v.scope==="project-specific"?a("knowledge.scopeProject"):v.scope==="module-level"?a("knowledge.scopeModule"):v.scope}),v.complexity&&y.push({icon:Ge,iconClass:"text-orange-400",label:a("knowledge.complexity"),value:v.complexity==="advanced"?a("knowledge.complexityAdvanced"):v.complexity==="intermediate"?a("knowledge.complexityIntermediate"):v.complexity==="beginner"?a("knowledge.complexityBeginner"):v.complexity}),v.source&&v.source!=="unknown"&&y.push({icon:Ct,iconClass:"text-violet-400",label:a("knowledge.source"),value:Oa[v.source||""]?a(Oa[v.source||""].labelKey):v.source||"-"}),v.createdAt&&y.push({icon:Ye,iconClass:"text-[var(--fg-muted)]",label:a("knowledge.createdAt"),value:Ot(v.createdAt,a)}),v.updatedAt&&y.push({icon:Ye,iconClass:"text-[var(--fg-muted)]",label:a("knowledge.updatedAt"),value:Ot(v.updatedAt,a)}),v.publishedAt&&y.push({icon:ht,iconClass:"text-emerald-400",label:a("knowledge.published"),value:Ot(v.publishedAt,a)}),y})(),tags:v.tags,id:v.id,sourceFile:v.sourceFile??void 0,sourceFileLabel:a("knowledge.sourceFile")}),v.relations&&Object.entries(v.relations).some(([,y])=>Array.isArray(y)&&y.length>0)&&e.jsxs("div",{className:"px-6 py-4 border-b border-[var(--border-default)]",children:[e.jsxs("div",{className:"flex items-center gap-1.5 mb-2",children:[e.jsx(ta,{size:12,className:"text-purple-400"}),e.jsx("label",{className:"text-[10px] font-bold text-[var(--fg-muted)] uppercase",children:a("knowledge.relatedKnowledge")}),(()=>{const y=Object.values(v.relations).flat().length;return y>0?e.jsx("span",{className:"text-[9px] bg-purple-100 text-purple-600 px-1.5 py-0.5 rounded-full font-bold",children:y}):null})()]}),e.jsx("div",{className:"space-y-1.5",children:Object.entries(v.relations).map(([y,te])=>!Array.isArray(te)||te.length===0?null:e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsx("span",{className:"text-[10px] font-mono text-[var(--fg-secondary)] shrink-0 whitespace-nowrap pt-0.5 uppercase",children:y}),e.jsx("div",{className:"flex flex-wrap gap-1",children:te.map((ge,he)=>{const De=ge.target||(typeof ge=="string"?ge:JSON.stringify(ge)),se=pe.get(De)||De;return e.jsx("span",{className:"inline-flex items-center gap-1 px-1.5 py-0.5 border rounded text-[10px] font-mono bg-purple-50 border-purple-200 text-purple-700",title:De,children:se},he)})})]},y))})]}),v.stats&&Object.values(v.stats).some(y=>typeof y=="number"&&y>0)||v.quality&&v.quality.overall>0?e.jsxs("div",{className:"px-6 py-3 border-b border-[var(--border-default)]",children:[e.jsxs("div",{className:"grid grid-cols-2 sm:grid-cols-4 gap-3",children:[e.jsxs("div",{className:"bg-amber-50/60 rounded-xl p-3 text-center border border-amber-100",children:[e.jsx("div",{className:"text-lg font-bold text-amber-700",children:v.stats?.authority||Math.round((v.quality?.overall||0)*5)||"—"}),e.jsx("div",{className:"text-[10px] text-amber-500 font-medium",children:a("knowledge.authorityScore")})]}),e.jsxs("div",{className:"bg-[var(--bg-subtle)] rounded-xl p-3 text-center border border-[var(--border-default)]",children:[e.jsx("div",{className:"text-lg font-bold text-[var(--fg-primary)]",children:v.stats?.guardHits??0}),e.jsx("div",{className:"text-[10px] text-[var(--fg-muted)] font-medium",children:a("knowledge.guardHits")})]}),e.jsxs("div",{className:"bg-[var(--bg-subtle)] rounded-xl p-3 text-center border border-[var(--border-default)]",children:[e.jsx("div",{className:"text-lg font-bold text-[var(--fg-primary)]",children:v.stats?.adoptions??0}),e.jsx("div",{className:"text-[10px] text-[var(--fg-muted)] font-medium",children:a("knowledge.adoptions")})]}),e.jsxs("div",{className:"bg-blue-50/60 rounded-xl p-3 text-center border border-blue-100",children:[e.jsx("div",{className:"text-lg font-bold text-blue-700",children:v.stats?.searchHits??0}),e.jsx("div",{className:"text-[10px] text-blue-500 font-medium",children:a("knowledge.searchHits")})]})]}),v.stats&&(v.stats.views>0||v.stats.applications>0)&&e.jsxs("div",{className:"flex items-center gap-4 mt-2 text-[10px] text-[var(--fg-muted)]",children:[e.jsxs("span",{children:[a("knowledge.statViews"),": ",v.stats.views]}),e.jsxs("span",{children:[a("knowledge.statApplications"),": ",v.stats.applications]})]})]}):null,e.jsx(Ee.Reasoning,{reasoning:fe,labels:{section:a("knowledge.reasoning"),source:`${a("knowledge.source")}:`,confidence:`${a("knowledge.confidence")}:`,alternatives:`${a("knowledge.alternatives")}:`},filterSubmitted:!0}),e.jsx(Ee.Quality,{quality:v.quality,labels:{section:a("knowledge.qualityGrade"),completeness:a("knowledge.qualityCompletionLabel"),adaptation:a("knowledge.qualityAdaptation"),documentation:a("knowledge.qualityDocumentation")},formatFixed:!0}),e.jsx(Ee.Description,{label:a("knowledge.summary"),text:v.description}),e.jsx(Ee.MarkdownSection,{label:a("knowledge.markdownDoc"),content:v.content?.markdown}),e.jsx(Ee.Headers,{label:a("knowledge.importHeaders"),headers:v.headers}),e.jsx(Ee.CodePattern,{label:a("knowledge.codePattern"),code:v.content?.pattern,language:v.language}),e.jsx(Ee.Delivery,{delivery:{topicHint:v.topicHint,whenClause:v.whenClause,doClause:v.doClause,dontClause:v.dontClause,coreCode:v.coreCode},language:v.language}),e.jsx(Ee.Rationale,{label:a("knowledge.designRationale"),text:v.content?.rationale}),e.jsx(Ee.Steps,{label:a("knowledge.implementSteps"),steps:v.content?.steps}),e.jsx(Ee.Constraints,{label:a("knowledge.constraintsLabel"),constraints:v.constraints}),v.aiInsight&&e.jsxs("div",{className:"px-6 py-4 border-b border-[var(--border-default)]",children:[e.jsxs("label",{className:"text-[10px] font-bold text-[var(--fg-muted)] uppercase mb-2 block flex items-center gap-1.5",children:[e.jsx(St,{size:11,className:"text-cyan-400"})," ",a("knowledge.aiInsight")]}),e.jsx("p",{className:"text-sm text-[var(--fg-secondary)] leading-relaxed",children:v.aiInsight})]}),(()=>{const y=Array.isArray(v.lifecycleHistory)?v.lifecycleHistory:(()=>{try{const te=typeof v.lifecycleHistory=="string"?JSON.parse(v.lifecycleHistory):null;return Array.isArray(te)?te:[]}catch{return[]}})();return y.length>0?e.jsxs("div",{className:"px-6 py-4 border-b border-[var(--border-default)]",children:[e.jsxs("label",{className:"text-[10px] font-bold text-[var(--fg-muted)] uppercase mb-2 block flex items-center gap-1.5",children:[e.jsx(Ye,{size:11,className:"text-[var(--fg-muted)]"})," ",a("knowledge.lifecycleHistoryLabel")]}),e.jsx("div",{className:"space-y-1",children:y.map((te,ge)=>{const he=lt[te.from]||lt.pending,De=lt[te.to]||lt.pending;return e.jsxs("div",{className:"flex items-center gap-2 text-[10px]",children:[e.jsx("span",{className:"text-[var(--fg-muted)] w-20 shrink-0",children:Ot(te.at,a)}),e.jsx("span",{className:`${he.color}`,children:r(te.from)}),e.jsx("span",{className:"text-[var(--fg-muted)]",children:"→"}),e.jsx("span",{className:`${De.color} font-medium`,children:r(te.to)}),e.jsxs("span",{className:"text-[var(--fg-muted)] ml-auto",children:["by ",te.by]})]},ge)})})]}):null})()]}),e.jsxs(Ie.Footer,{children:[e.jsx("div",{className:"flex items-center gap-2",children:e.jsxs("button",{onClick:()=>{M(v),U(null)},className:"flex items-center gap-1.5 px-3 py-2 rounded-lg text-xs font-medium text-red-500 hover:bg-red-50 border border-red-200 transition-colors",children:[e.jsx(Ke,{size:14})," ",a("common.delete")]})}),e.jsx("div",{className:"flex items-center gap-2",children:(Ac[v.lifecycle]||[]).map(y=>{const te=y.icon;return e.jsxs("button",{onClick:()=>y.needsReason?ce(v,y.action):ue(v,y.action),disabled:ae,className:`flex items-center gap-1.5 px-4 py-2 rounded-lg text-xs font-bold border transition-colors disabled:opacity-50 ${y.bg} ${y.color} border-current/20`,children:[ae?e.jsx(Ne,{size:14,className:"animate-spin"}):e.jsx(te,{size:14}),o(y.action)]},y.action)})})]})]})})()]})},is={manual:{label:"manual",color:"bg-[var(--bg-subtle)] text-[var(--fg-secondary)]",icon:vr},"user-ai":{label:"user-ai",color:"bg-violet-100 text-violet-600",icon:Le},"system-ai":{label:"system-ai",color:"bg-amber-100 text-amber-600",icon:Jt},"external-ai":{label:"external-ai",color:"bg-cyan-100 text-cyan-600",icon:aa}},Pc=({onRefresh:t,signalSuggestionCount:s=0,onSuggestionCountChange:a})=>{const{t:r}=Ae(),[o,l]=n.useState([]),[i,p]=n.useState(!0),[d,g]=n.useState(null),[x,h]=n.useState(!1),[u,m]=n.useState(!1),[c,j]=n.useState("all"),[A,D]=n.useState(!1),[I,P]=n.useState([]),[J,w]=n.useState(!1),[B,z]=n.useState(!1),[k,E]=n.useState(null),[L,O]=n.useState(!1),[W,q]=n.useState(""),[N,v]=n.useState(!1),[U,ae]=n.useState(!1),[be,me]=n.useState(!1),je=n.useCallback(async()=>{p(!0);try{const F=await Q.listSkills();l(F.skills||[])}catch(F){Wl(F)!==404&&re(ke(F,""),{title:r("skills.fetchFailed"),type:"error"}),l([])}finally{p(!1)}},[]);n.useEffect(()=>{je()},[je]);const G=async F=>{if(d?.skillName===F){g(null);return}O(!1),ae(!1),h(!0);try{const Se=await Q.loadSkill(F);g(Se)}catch{re(`"${F}" ${r("skills.loadError")}`,{title:r("skills.loadSkillFailed"),type:"error"})}finally{h(!1)}},le=()=>{d?.content&&(navigator.clipboard.writeText(d.content).catch(()=>{}),D(!0),setTimeout(()=>D(!1),2e3))},de=()=>{d&&(q(d.content),O(!0))},R=()=>{O(!1),q("")},T=async()=>{if(!(!d||!W.trim())){v(!0);try{await Q.updateSkill(d.skillName,{content:W}),re(r("skills.saveSuccess"),{title:`Skill "${d.skillName}" ${r("skills.updateSuccess")}`}),O(!1);const F=await Q.loadSkill(d.skillName);g(F)}catch(F){re(ke(F,""),{title:r("skills.updateFailed"),type:"error"})}finally{v(!1)}}},X=async()=>{if(d){me(!0);try{await Q.deleteSkill(d.skillName),re(r("skills.deleteSuccess"),{title:`Skill "${d.skillName}" ${r("skills.deleteSuccess")}`}),g(null),ae(!1),O(!1),je(),t?.()}catch(F){re(ke(F,""),{title:r("skills.deleteFailed"),type:"error"})}finally{me(!1)}}},oe=async()=>{w(!0),z(!0);try{const[F,Se]=await Promise.allSettled([Q.suggestSkills(),Q.getSignalStatus()]),Te=F.status==="fulfilled"?F.value.suggestions||[]:[],Fe=Se.status==="fulfilled"?Se.value.suggestions||[]:[],Me=new Map;for(const ce of Te)Me.set(ce.name,ce);for(const ce of Fe)Me.set(ce.name,{...Me.get(ce.name),...ce});const ee=[...Me.values()];P(ee),a?.(ee.length)}catch(F){re(ke(F,""),{title:r("skills.aiRecommendFailed"),type:"error"}),P([]),a?.(0)}finally{w(!1)}};n.useEffect(()=>{s>0&&I.length===0&&!B&&oe()},[]);const pe=async F=>{E(F.name);try{const Se=F.description||F.rationale||F.name,Te=`${r("skillsView.aiPromptPrefix")}
97
+ `):""}const Oa={"bootstrap-scan":{labelKey:"knowledge.sourceBootstrap",color:"text-violet-600 bg-violet-50 border-violet-200"},mcp:{labelKey:"knowledge.sourceMcp",color:"text-blue-600 bg-blue-50 border-blue-200"},manual:{labelKey:"knowledge.sourceManual",color:"text-emerald-600 bg-emerald-50 border-emerald-200"},"file-watcher":{labelKey:"knowledge.sourceFileWatcher",color:"text-orange-600 bg-orange-50 border-orange-200"},clipboard:{labelKey:"knowledge.sourceClipboard",color:"text-pink-600 bg-pink-50 border-pink-200"},cli:{labelKey:"knowledge.sourceCli",color:"text-[var(--fg-secondary)] bg-[var(--bg-subtle)] border-[var(--border-default)]"},agent:{labelKey:"knowledge.sourceAgent",color:"text-violet-600 bg-violet-50 border-violet-200"},submit_with_check:{labelKey:"knowledge.sourceSubmitCheck",color:"text-teal-600 bg-teal-50 border-teal-200"}},Ic={"source file deleted (orphan)":"源文件已删除(孤儿条目)"};function Tc(t){return Ic[t]??t}const Ec=({onRefresh:t,idTitleMap:s})=>{const{t:a}=Ae(),r=f=>({pending:a("knowledge.lifecyclePending"),staging:a("knowledge.lifecycleStaging"),active:a("knowledge.lifecycleActive"),evolving:a("knowledge.lifecycleEvolving"),decaying:a("knowledge.lifecycleDecaying"),deprecated:a("knowledge.lifecycleDeprecated")})[f]||f,o=f=>({publish:a("knowledge.actionPublish"),stage:a("knowledge.actionStage"),deprecate:a("knowledge.actionDeprecate"),reactivate:a("knowledge.actionReactivate"),evolve:a("knowledge.actionEvolve"),decay:a("knowledge.actionDecay")})[f]||f,[l,i]=n.useState([]),[p,d]=n.useState(null),[g,x]=n.useState({}),[h,u]=n.useState(!0),[m,c]=n.useState(1),[j,A]=n.useState(12),[D,I]=n.useState(0),[P,J]=n.useState(""),[w,B]=n.useState(""),[z,k]=n.useState(""),[E,L]=n.useState(""),[O,W]=n.useState(""),{isWide:q,toggle:N}=ia(),[v,U]=n.useState(null),[ae,be]=n.useState(!1),[me,je]=n.useState(new Set),[G,le]=n.useState(!1),de=n.useRef(!0);n.useEffect(()=>(de.current=!0,()=>{de.current=!1}),[]);const R=n.useCallback(async()=>{u(!0);try{const f=await Q.knowledgeList({page:m,limit:j,lifecycle:P||void 0,kind:w||void 0,category:z||void 0,keyword:E||void 0});de.current&&(i(f.data||[]),I(f.pagination?.total||0))}catch(f){re(ke(f,a("knowledge.loadFailed")),{title:a("common.loadFailed"),type:"error"})}finally{de.current&&u(!1)}},[m,j,P,w,z,E]),T=n.useCallback(async()=>{try{const f=await Q.knowledgeStats();de.current&&d(f)}catch{}},[]),X=n.useCallback(async()=>{try{const f=await Q.getKnowledgeLifecycle();de.current&&x(f.counts||{})}catch{}},[]);n.useEffect(()=>{R()},[R]),n.useEffect(()=>{T()},[T]),n.useEffect(()=>{X()},[X]),n.useEffect(()=>{const f=setTimeout(()=>{L(O),c(1)},300);return()=>clearTimeout(f)},[O]),n.useEffect(()=>{c(1)},[P,w,z]);const oe=n.useCallback(()=>{R(),T(),X(),t?.()},[R,T,X,t]),pe=n.useMemo(()=>{const f=new Map;if(s)for(const[V,xe]of Object.entries(s))f.set(V,xe);for(const V of l)V.id&&V.title&&f.set(V.id,V.title);return f},[l,s]),ue=async(f,V,xe)=>{be(!0);try{const fe=await Q.knowledgeLifecycle(f.id,V,xe);re(`${f.title} → ${a(lt[fe.lifecycle]?.labelKey||"")||fe.lifecycle}`,{title:a("knowledge.operationSuccess")}),i(C=>C.map(b=>b.id===f.id?fe:b)),v?.id===f.id&&U(fe),T()}catch(fe){re(ke(fe,a("common.operationFailed")),{title:a("common.operationFailed"),type:"error"})}finally{de.current&&be(!1)}},M=async f=>{if(confirm(a("knowledge.deleteConfirmMsg",{title:f.title})))try{await Q.knowledgeDelete(f.id),re(a("knowledge.deleteSuccess",{title:f.title}),{title:a("common.delete")}),i(V=>V.filter(xe=>xe.id!==f.id)),v?.id===f.id&&U(null),T()}catch(V){re(ke(V,a("knowledge.deleteFailed")),{title:a("knowledge.deleteFailed"),type:"error"})}},Ce=["pending","staging"],F=async()=>{if(me.size===0)return;const f=l.filter(V=>me.has(V.id)&&Ce.includes(V.lifecycle)).map(V=>V.id);if(f.length===0){re(a("knowledge.noPublishable"),{title:a("knowledge.batchPublish"),type:"info"});return}le(!0);try{const V=await Q.knowledgeBatchPublish(f);re(a("knowledge.batchPublishResult",{success:V.successCount,fail:V.failureCount}),{title:a("knowledge.batchPublish")}),je(new Set),oe()}catch(V){re(ke(V,a("knowledge.batchPublishFailed")),{title:a("common.operationFailed"),type:"error"})}finally{le(!1)}},Se=async()=>{le(!0);try{const V=((await Q.knowledgeList({lifecycle:"pending",limit:500})).data||[]).filter(fe=>fe.autoApprovable).map(fe=>fe.id);if(V.length===0){re(a("knowledge.noAutoApprovable"),{title:a("knowledge.noPublishable")});return}const xe=await Q.knowledgeBatchPublish(V);re(a("knowledge.autoPublishResult",{count:xe.successCount}),{title:a("knowledge.batchPublishComplete")}),oe()}catch(f){re(ke(f,a("knowledge.batchPublishFailed")),{title:a("common.operationFailed"),type:"error"})}finally{le(!1)}},Te=async()=>{if(me.size===0)return;const f=l.filter(V=>me.has(V.id)&&(V.lifecycle==="active"||V.lifecycle==="evolving")).map(V=>V.id);if(f.length===0){re(a("knowledge.noDeprecatable"),{title:a("knowledge.batchDeprecate"),type:"info"});return}le(!0);try{const V=await Q.knowledgeBatchDeprecate(f);re(a("knowledge.batchDeprecateResult",{success:V.successCount,fail:V.failureCount}),{title:a("knowledge.batchDeprecate")}),je(new Set),oe()}catch(V){re(ke(V,a("knowledge.batchDeprecateFailed")),{title:a("common.operationFailed"),type:"error"})}finally{le(!1)}},Fe=async()=>{if(me.size!==0&&confirm(a("knowledge.batchDeleteConfirm",{count:me.size}))){le(!0);try{const f=await Q.knowledgeBatchDelete([...me]);re(a("knowledge.batchDeleteResult",{success:f.deletedCount,fail:f.failureCount}),{title:a("knowledge.batchDelete")}),je(new Set),oe()}catch(f){re(ke(f,a("knowledge.batchDeleteFailed")),{title:a("common.operationFailed"),type:"error"})}finally{le(!1)}}},Me=f=>{je(V=>{const xe=new Set(V);return xe.has(f)?xe.delete(f):xe.add(f),xe})},ee=()=>{me.size===l.length?je(new Set):je(new Set(l.map(f=>f.id)))},ce=(f,V)=>{const xe=prompt(a("knowledge.deprecateReasonPrompt"));xe&&ue(f,V,xe)};return e.jsxs("div",{className:"space-y-4 pb-6",children:[(()=>{const f=g;if(!Object.values(f).some(_=>_>0)&&!p)return null;const xe=_=>f[_]??p?.[_]??0,fe=({stateKey:_,onClick:ne})=>{const $=lt[_];if(!$)return null;const y=$.icon,te=xe(_),ge=P===_;return e.jsxs("button",{onClick:ne,className:`flex items-center gap-1.5 px-3 py-1.5 rounded-lg border text-xs font-medium transition-colors whitespace-nowrap ${ge?`${$.bg} ${$.border} ${$.color} shadow-sm`:`border-transparent ${$.hoverBorder} text-[var(--fg-secondary)]`}`,children:[e.jsx(y,{size:14,className:ge?"":"opacity-60"}),e.jsx("span",{children:r(_)}),e.jsx("span",{className:`ml-0.5 inline-flex items-center justify-center min-w-[20px] h-5 px-1.5 rounded text-[11px] font-bold ${$.badgeBg} ${$.badgeColor}`,children:te})]})},C=()=>e.jsx("span",{className:"text-[var(--fg-muted)] text-xs opacity-40 select-none",children:"→"}),b=_=>J(P===_?"":_);return e.jsxs("div",{className:"flex items-center gap-x-1.5 gap-y-2 flex-wrap text-[var(--fg-secondary)]",children:[e.jsx(fe,{stateKey:"pending",onClick:()=>b("pending")}),e.jsx(C,{}),e.jsx(fe,{stateKey:"staging",onClick:()=>b("staging")}),e.jsx(C,{}),e.jsx(fe,{stateKey:"active",onClick:()=>b("active")}),e.jsx(C,{}),e.jsx(fe,{stateKey:"evolving",onClick:()=>b("evolving")}),e.jsx("span",{className:"mx-1.5 h-4 border-l border-[var(--border-default)]"}),e.jsx(fe,{stateKey:"decaying",onClick:()=>b("decaying")}),e.jsx(C,{}),e.jsx(fe,{stateKey:"deprecated",onClick:()=>b("deprecated")})]})})(),e.jsxs("div",{className:"flex flex-wrap items-center gap-3",children:[e.jsxs("div",{className:"relative flex-1 min-w-[200px] max-w-md",children:[e.jsx(xt,{className:"absolute left-3 top-1/2 -translate-y-1/2 text-[var(--fg-muted)]",size:16}),e.jsx("input",{type:"text",placeholder:a("knowledge.searchPlaceholder"),value:O,onChange:f=>W(f.target.value),className:"w-full pl-9 pr-3 py-2 rounded-lg border border-[var(--border-default)] text-sm focus:outline-none focus:ring-2 focus:ring-blue-300"})]}),e.jsx("div",{className:"flex gap-1",children:Object.entries($t).map(([f,V])=>{const xe=V.icon;return e.jsxs("button",{onClick:()=>B(w===f?"":f),className:`flex items-center gap-1 px-2.5 py-1.5 rounded-md text-xs font-medium border transition-all ${w===f?`${V.bg} ${V.border} ${V.color}`:"bg-[var(--bg-surface)] border-[var(--border-default)] text-[var(--fg-secondary)] hover:bg-[var(--bg-subtle)]"}`,children:[e.jsx(xe,{size:12}),a(V.labelKey)]},f)})}),e.jsx(tt,{value:z,onChange:f=>k(f),options:[{value:"",label:a("knowledge.allCategories")},...["View","Service","Tool","Model","Network","Storage","UI","Utility"].map(f=>({value:f,label:f}))],size:"sm",className:"text-xs"}),e.jsx("button",{onClick:oe,className:"p-2 rounded-md text-[var(--fg-muted)] hover:bg-[var(--bg-subtle)]",title:a("common.refresh"),children:e.jsx(at,{size:16})}),me.size>0&&(()=>{const f=l.filter(xe=>me.has(xe.id)&&Ce.includes(xe.lifecycle)).length,V=l.filter(xe=>me.has(xe.id)&&(xe.lifecycle==="active"||xe.lifecycle==="evolving")).length;return e.jsxs("div",{className:"flex items-center gap-2 ml-auto",children:[e.jsx("span",{className:"text-xs text-[var(--fg-secondary)]",children:a("knowledge.selectedCount",{count:me.size})}),f>0&&e.jsxs("button",{onClick:F,disabled:G,className:"px-2.5 py-1 text-xs font-medium text-green-700 bg-green-50 border border-green-200 rounded-md hover:bg-green-100 disabled:opacity-50",children:[G?e.jsx(Ne,{size:12,className:"animate-spin"}):a("knowledge.batchPublish")," (",f,")"]}),V>0&&e.jsxs("button",{onClick:Te,disabled:G,className:"px-2.5 py-1 text-xs font-medium text-amber-700 bg-amber-50 border border-amber-200 rounded-md hover:bg-amber-100 disabled:opacity-50 flex items-center gap-1",children:[G?e.jsx(Ne,{size:12,className:"animate-spin"}):e.jsx(qt,{size:12}),a("knowledge.batchDeprecate")," (",V,")"]}),e.jsxs("button",{onClick:Fe,disabled:G,className:"px-2.5 py-1 text-xs font-medium text-red-700 bg-red-50 border border-red-200 rounded-md hover:bg-red-100 disabled:opacity-50 flex items-center gap-1",children:[G?e.jsx(Ne,{size:12,className:"animate-spin"}):e.jsx(Ke,{size:12}),a("knowledge.batchDelete")," (",me.size,")"]}),e.jsx("button",{onClick:()=>je(new Set),className:"p-1 text-[var(--fg-muted)] hover:text-[var(--fg-primary)]",children:e.jsx(ze,{size:14})})]})})(),me.size===0&&l.some(f=>f.lifecycle==="pending")&&e.jsxs("button",{onClick:Se,disabled:G,className:"ml-auto px-3 py-1.5 text-xs font-medium text-cyan-700 bg-cyan-50 border border-cyan-200 rounded-md hover:bg-cyan-100 disabled:opacity-50 flex items-center gap-1.5",children:[G?e.jsx(Ne,{size:12,className:"animate-spin"}):e.jsx(Be,{size:12}),a("knowledge.quickBatchPublish")]})]}),h?e.jsx(Sc,{}):l.length===0?e.jsxs("div",{className:"flex flex-col items-center justify-center py-20 text-[var(--fg-muted)]",children:[e.jsx(Qs,{size:48,className:"mb-4 opacity-30"}),e.jsx("p",{className:"text-sm",children:a("knowledge.noResults")}),(E||P||w||z)&&e.jsx("button",{onClick:()=>{W(""),J(""),B(""),k("")},className:"mt-2 text-xs text-blue-500 hover:text-blue-700",children:a("knowledge.clearFilters")})]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center gap-2 px-1",children:[e.jsx("input",{type:"checkbox",checked:me.size===l.length&&l.length>0,onChange:ee,className:"rounded border-[var(--border-default)]"}),e.jsx("span",{className:"text-xs text-[var(--fg-muted)]",children:a("knowledge.selectAll")}),e.jsx("span",{className:"text-xs text-[var(--fg-muted)] ml-auto",children:a("knowledge.totalCount",{count:D})})]}),e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4 items-start",children:l.map(f=>{const V=lt[f.lifecycle]||lt.pending,xe=$t[f.kind]||$t.pattern,fe=V.icon,C=xe.icon,b=Dc(f.reasoning?.confidence);return e.jsxs("div",{onClick:()=>U(f),className:`group bg-[var(--bg-surface)] rounded-xl border shadow-sm hover:shadow-md cursor-pointer transition-all overflow-hidden ${v?.id===f.id?"ring-2 ring-blue-300 border-blue-200":"border-[var(--border-default)]"}`,children:[e.jsxs("div",{className:"px-4 pt-3 pb-2",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1.5",children:[e.jsx("input",{type:"checkbox",checked:me.has(f.id),onChange:_=>{_.stopPropagation(),Me(f.id)},onClick:_=>_.stopPropagation(),className:"rounded border-[var(--border-default)]"}),e.jsxs("span",{className:`inline-flex items-center gap-1 px-1.5 py-0.5 rounded text-[10px] font-medium ${V.bg} ${V.color} ${V.border} border`,children:[e.jsx(fe,{size:10}),r(f.lifecycle)]}),e.jsxs("span",{className:`inline-flex items-center gap-1 px-1.5 py-0.5 rounded text-[10px] font-medium ${xe.bg} ${xe.color} ${xe.border} border`,children:[e.jsx(C,{size:10}),a(xe.labelKey)]}),f.category&&e.jsx("span",{className:"text-[10px] text-[var(--fg-muted)]",children:f.category}),e.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded ${b.bg} ${b.text}`,children:f.reasoning?.confidence!=null?`${Math.round(f.reasoning.confidence*100)}%`:"—"}),f.autoApprovable&&f.lifecycle==="pending"&&e.jsxs("span",{className:"inline-flex items-center gap-0.5 text-[10px] px-1.5 py-0.5 rounded bg-cyan-50 text-cyan-600 border border-cyan-200",children:[e.jsx(Be,{size:9}),a("knowledge.autoApprovable")]})]}),e.jsx("h3",{className:"text-sm font-bold text-[var(--fg-primary)] mb-1 break-words leading-snug",children:f.title}),(f.description||f.content?.rationale)&&e.jsx("p",{className:"text-xs text-[var(--fg-secondary)] line-clamp-2 leading-relaxed",children:f.description||f.content?.rationale||""}),f.content?.pattern&&e.jsx("pre",{className:"mt-1.5 text-[10px] text-[var(--fg-secondary)] bg-[var(--bg-subtle)] rounded p-1.5 line-clamp-3 font-mono overflow-hidden",children:Rc(f.content.pattern,3)})]}),e.jsxs("div",{className:"px-4 py-2 bg-[var(--bg-subtle)] border-t border-[var(--border-default)] flex items-center gap-2",children:[f.tags?.slice(0,3).map(_=>e.jsx("span",{className:"text-[10px] px-1.5 py-0.5 rounded bg-blue-50 text-blue-600 border border-blue-100",children:_},_)),f.tags&&f.tags.length>3&&e.jsxs("span",{className:"text-[10px] text-[var(--fg-muted)]",children:["+",f.tags.length-3]}),e.jsxs("span",{className:"text-[10px] text-[var(--fg-muted)] ml-auto",children:[f.trigger&&e.jsx("span",{className:"text-blue-400 mr-2",children:f.trigger}),f.source&&e.jsx("span",{className:"mr-2",children:f.source}),Ot(f.updatedAt,a)]})]})]},f.id)})}),e.jsx(ca,{currentPage:m,totalPages:Math.ceil(D/j),onPageChange:c,pageSize:j,onPageSizeChange:f=>{A(f),c(1)},totalItems:D})]}),v&&(()=>{const f=lt[v.lifecycle]||lt.pending,V=$t[v.kind]||$t.pattern,xe=et[v.category||""]||et.All||{},fe=v.reasoning,C=l.findIndex(y=>y.id===v.id),b=C>0,_=C<l.length-1,ne=()=>{b&&U(l[C-1])},$=()=>{_&&U(l[C+1])};return e.jsxs(Ie,{open:!!v,onClose:()=>U(null),size:q?"lg":"md",children:[e.jsxs(Ie.Header,{title:v.title,leading:e.jsx("button",{onClick:()=>{M(v),U(null)},title:a("common.delete"),className:"p-1.5 text-[var(--fg-muted)] hover:text-red-500 rounded-md transition-colors opacity-30 hover:opacity-100 shrink-0",children:e.jsx(Ke,{size:14})}),children:[e.jsx(Ie.Nav,{currentIndex:C,total:l.length,onPrev:ne,onNext:$,hasPrev:b,hasNext:_}),e.jsxs(Ie.HeaderActions,{children:[e.jsx(Ie.WidthToggle,{isWide:q,onToggle:N,title:a(q?"knowledge.narrow":"knowledge.widen")}),e.jsx(Ie.CloseButton,{onClose:()=>U(null)})]})]}),e.jsxs(Ie.Body,{children:[v.rejectionReason&&e.jsxs("div",{className:"px-6 py-3 border-b border-[var(--border-default)] bg-red-500/10",children:[e.jsx("label",{className:"text-[10px] font-bold text-red-400 uppercase mb-1.5 block",children:a("knowledge.rejectionReason")}),e.jsx("p",{className:"text-xs text-red-500 dark:text-red-400",children:Tc(v.rejectionReason)})]}),e.jsx(da,{badges:(()=>{const y=[];return y.push({label:r(v.lifecycle),className:`${f.bg} ${f.color} ${f.border}`,icon:f.icon}),y.push({label:a(V.labelKey),className:`${V.bg} ${V.color} ${V.border}`,icon:V.icon}),y.push({label:v.category||"general",className:`font-bold uppercase ${xe?.bg||"bg-[var(--bg-subtle)]"} ${xe?.color||"text-[var(--fg-muted)]"} ${xe?.border||"border-[var(--border-default)]"}`}),v.knowledgeType&&y.push({label:v.knowledgeType,className:"bg-purple-50 text-purple-700 border-purple-200"}),v.language&&y.push({label:v.language,className:"uppercase font-bold text-[var(--fg-secondary)] bg-[var(--bg-subtle)] border-[var(--border-default)]"}),v.trigger&&y.push({label:v.trigger,className:"font-mono font-bold bg-amber-50 text-amber-700 border-amber-200"}),y})(),metadata:(()=>{const y=[];return v.scope&&y.push({icon:Ct,iconClass:"text-teal-400",label:a("knowledge.scope"),value:v.scope==="universal"?a("knowledge.scopeUniversal"):v.scope==="project-specific"?a("knowledge.scopeProject"):v.scope==="module-level"?a("knowledge.scopeModule"):v.scope}),v.complexity&&y.push({icon:Ge,iconClass:"text-orange-400",label:a("knowledge.complexity"),value:v.complexity==="advanced"?a("knowledge.complexityAdvanced"):v.complexity==="intermediate"?a("knowledge.complexityIntermediate"):v.complexity==="beginner"?a("knowledge.complexityBeginner"):v.complexity}),v.source&&v.source!=="unknown"&&y.push({icon:Ct,iconClass:"text-violet-400",label:a("knowledge.source"),value:Oa[v.source||""]?a(Oa[v.source||""].labelKey):v.source||"-"}),v.createdAt&&y.push({icon:Ye,iconClass:"text-[var(--fg-muted)]",label:a("knowledge.createdAt"),value:Ot(v.createdAt,a)}),v.updatedAt&&y.push({icon:Ye,iconClass:"text-[var(--fg-muted)]",label:a("knowledge.updatedAt"),value:Ot(v.updatedAt,a)}),v.publishedAt&&y.push({icon:ht,iconClass:"text-emerald-400",label:a("knowledge.published"),value:Ot(v.publishedAt,a)}),y})(),tags:v.tags,id:v.id,sourceFile:v.sourceFile??void 0,sourceFileLabel:a("knowledge.sourceFile")}),v.relations&&Object.entries(v.relations).some(([,y])=>Array.isArray(y)&&y.length>0)&&e.jsxs("div",{className:"px-6 py-4 border-b border-[var(--border-default)]",children:[e.jsxs("div",{className:"flex items-center gap-1.5 mb-2",children:[e.jsx(ta,{size:12,className:"text-purple-400"}),e.jsx("label",{className:"text-[10px] font-bold text-[var(--fg-muted)] uppercase",children:a("knowledge.relatedKnowledge")}),(()=>{const y=Object.values(v.relations).flat().length;return y>0?e.jsx("span",{className:"text-[9px] bg-purple-100 text-purple-600 px-1.5 py-0.5 rounded-full font-bold",children:y}):null})()]}),e.jsx("div",{className:"space-y-1.5",children:Object.entries(v.relations).map(([y,te])=>!Array.isArray(te)||te.length===0?null:e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsx("span",{className:"text-[10px] font-mono text-[var(--fg-secondary)] shrink-0 whitespace-nowrap pt-0.5 uppercase",children:y}),e.jsx("div",{className:"flex flex-wrap gap-1",children:te.map((ge,he)=>{const De=ge.target||(typeof ge=="string"?ge:JSON.stringify(ge)),se=pe.get(De)||De;return e.jsx("span",{className:"inline-flex items-center gap-1 px-1.5 py-0.5 border rounded text-[10px] font-mono bg-purple-50 border-purple-200 text-purple-700",title:De,children:se},he)})})]},y))})]}),v.stats&&Object.values(v.stats).some(y=>typeof y=="number"&&y>0)||v.quality&&v.quality.overall>0?e.jsxs("div",{className:"px-6 py-3 border-b border-[var(--border-default)]",children:[e.jsxs("div",{className:"grid grid-cols-2 sm:grid-cols-4 gap-3",children:[e.jsxs("div",{className:"bg-amber-50/60 rounded-xl p-3 text-center border border-amber-100",children:[e.jsx("div",{className:"text-lg font-bold text-amber-700",children:v.stats?.authority||Math.round((v.quality?.overall||0)*5)||"—"}),e.jsx("div",{className:"text-[10px] text-amber-500 font-medium",children:a("knowledge.authorityScore")})]}),e.jsxs("div",{className:"bg-[var(--bg-subtle)] rounded-xl p-3 text-center border border-[var(--border-default)]",children:[e.jsx("div",{className:"text-lg font-bold text-[var(--fg-primary)]",children:v.stats?.guardHits??0}),e.jsx("div",{className:"text-[10px] text-[var(--fg-muted)] font-medium",children:a("knowledge.guardHits")})]}),e.jsxs("div",{className:"bg-[var(--bg-subtle)] rounded-xl p-3 text-center border border-[var(--border-default)]",children:[e.jsx("div",{className:"text-lg font-bold text-[var(--fg-primary)]",children:v.stats?.adoptions??0}),e.jsx("div",{className:"text-[10px] text-[var(--fg-muted)] font-medium",children:a("knowledge.adoptions")})]}),e.jsxs("div",{className:"bg-blue-50/60 rounded-xl p-3 text-center border border-blue-100",children:[e.jsx("div",{className:"text-lg font-bold text-blue-700",children:v.stats?.searchHits??0}),e.jsx("div",{className:"text-[10px] text-blue-500 font-medium",children:a("knowledge.searchHits")})]})]}),v.stats&&(v.stats.views>0||v.stats.applications>0)&&e.jsxs("div",{className:"flex items-center gap-4 mt-2 text-[10px] text-[var(--fg-muted)]",children:[e.jsxs("span",{children:[a("knowledge.statViews"),": ",v.stats.views]}),e.jsxs("span",{children:[a("knowledge.statApplications"),": ",v.stats.applications]})]})]}):null,e.jsx(Ee.Reasoning,{reasoning:fe,labels:{section:a("knowledge.reasoning"),source:`${a("knowledge.source")}:`,confidence:`${a("knowledge.confidence")}:`,alternatives:`${a("knowledge.alternatives")}:`},filterSubmitted:!0}),e.jsx(Ee.Quality,{quality:v.quality,labels:{section:a("knowledge.qualityGrade"),completeness:a("knowledge.qualityCompletionLabel"),adaptation:a("knowledge.qualityAdaptation"),documentation:a("knowledge.qualityDocumentation")}}),e.jsx(Ee.Description,{label:a("knowledge.summary"),text:v.description}),e.jsx(Ee.MarkdownSection,{label:a("knowledge.markdownDoc"),content:v.content?.markdown}),e.jsx(Ee.Headers,{label:a("knowledge.importHeaders"),headers:v.headers}),e.jsx(Ee.CodePattern,{label:a("knowledge.codePattern"),code:v.content?.pattern,language:v.language}),e.jsx(Ee.Delivery,{delivery:{topicHint:v.topicHint,whenClause:v.whenClause,doClause:v.doClause,dontClause:v.dontClause,coreCode:v.coreCode},language:v.language}),e.jsx(Ee.Rationale,{label:a("knowledge.designRationale"),text:v.content?.rationale}),e.jsx(Ee.Steps,{label:a("knowledge.implementSteps"),steps:v.content?.steps}),e.jsx(Ee.Constraints,{label:a("knowledge.constraintsLabel"),constraints:v.constraints}),v.aiInsight&&e.jsxs("div",{className:"px-6 py-4 border-b border-[var(--border-default)]",children:[e.jsxs("label",{className:"text-[10px] font-bold text-[var(--fg-muted)] uppercase mb-2 block flex items-center gap-1.5",children:[e.jsx(St,{size:11,className:"text-cyan-400"})," ",a("knowledge.aiInsight")]}),e.jsx("p",{className:"text-sm text-[var(--fg-secondary)] leading-relaxed",children:v.aiInsight})]}),(()=>{const y=Array.isArray(v.lifecycleHistory)?v.lifecycleHistory:(()=>{try{const te=typeof v.lifecycleHistory=="string"?JSON.parse(v.lifecycleHistory):null;return Array.isArray(te)?te:[]}catch{return[]}})();return y.length>0?e.jsxs("div",{className:"px-6 py-4 border-b border-[var(--border-default)]",children:[e.jsxs("label",{className:"text-[10px] font-bold text-[var(--fg-muted)] uppercase mb-2 block flex items-center gap-1.5",children:[e.jsx(Ye,{size:11,className:"text-[var(--fg-muted)]"})," ",a("knowledge.lifecycleHistoryLabel")]}),e.jsx("div",{className:"space-y-1",children:y.map((te,ge)=>{const he=lt[te.from]||lt.pending,De=lt[te.to]||lt.pending;return e.jsxs("div",{className:"flex items-center gap-2 text-[10px]",children:[e.jsx("span",{className:"text-[var(--fg-muted)] w-20 shrink-0",children:Ot(te.at,a)}),e.jsx("span",{className:`${he.color}`,children:r(te.from)}),e.jsx("span",{className:"text-[var(--fg-muted)]",children:"→"}),e.jsx("span",{className:`${De.color} font-medium`,children:r(te.to)}),e.jsxs("span",{className:"text-[var(--fg-muted)] ml-auto",children:["by ",te.by]})]},ge)})})]}):null})()]}),e.jsxs(Ie.Footer,{children:[e.jsx("div",{className:"flex items-center gap-2",children:e.jsxs("button",{onClick:()=>{M(v),U(null)},className:"flex items-center gap-1.5 px-3 py-2 rounded-lg text-xs font-medium text-red-500 hover:bg-red-50 border border-red-200 transition-colors",children:[e.jsx(Ke,{size:14})," ",a("common.delete")]})}),e.jsx("div",{className:"flex items-center gap-2",children:(Ac[v.lifecycle]||[]).map(y=>{const te=y.icon;return e.jsxs("button",{onClick:()=>y.needsReason?ce(v,y.action):ue(v,y.action),disabled:ae,className:`flex items-center gap-1.5 px-4 py-2 rounded-lg text-xs font-bold border transition-colors disabled:opacity-50 ${y.bg} ${y.color} border-current/20`,children:[ae?e.jsx(Ne,{size:14,className:"animate-spin"}):e.jsx(te,{size:14}),o(y.action)]},y.action)})})]})]})})()]})},is={manual:{label:"manual",color:"bg-[var(--bg-subtle)] text-[var(--fg-secondary)]",icon:vr},"user-ai":{label:"user-ai",color:"bg-violet-100 text-violet-600",icon:Le},"system-ai":{label:"system-ai",color:"bg-amber-100 text-amber-600",icon:Jt},"external-ai":{label:"external-ai",color:"bg-cyan-100 text-cyan-600",icon:aa}},Pc=({onRefresh:t,signalSuggestionCount:s=0,onSuggestionCountChange:a})=>{const{t:r}=Ae(),[o,l]=n.useState([]),[i,p]=n.useState(!0),[d,g]=n.useState(null),[x,h]=n.useState(!1),[u,m]=n.useState(!1),[c,j]=n.useState("all"),[A,D]=n.useState(!1),[I,P]=n.useState([]),[J,w]=n.useState(!1),[B,z]=n.useState(!1),[k,E]=n.useState(null),[L,O]=n.useState(!1),[W,q]=n.useState(""),[N,v]=n.useState(!1),[U,ae]=n.useState(!1),[be,me]=n.useState(!1),je=n.useCallback(async()=>{p(!0);try{const F=await Q.listSkills();l(F.skills||[])}catch(F){Wl(F)!==404&&re(ke(F,""),{title:r("skills.fetchFailed"),type:"error"}),l([])}finally{p(!1)}},[]);n.useEffect(()=>{je()},[je]);const G=async F=>{if(d?.skillName===F){g(null);return}O(!1),ae(!1),h(!0);try{const Se=await Q.loadSkill(F);g(Se)}catch{re(`"${F}" ${r("skills.loadError")}`,{title:r("skills.loadSkillFailed"),type:"error"})}finally{h(!1)}},le=()=>{d?.content&&(navigator.clipboard.writeText(d.content).catch(()=>{}),D(!0),setTimeout(()=>D(!1),2e3))},de=()=>{d&&(q(d.content),O(!0))},R=()=>{O(!1),q("")},T=async()=>{if(!(!d||!W.trim())){v(!0);try{await Q.updateSkill(d.skillName,{content:W}),re(r("skills.saveSuccess"),{title:`Skill "${d.skillName}" ${r("skills.updateSuccess")}`}),O(!1);const F=await Q.loadSkill(d.skillName);g(F)}catch(F){re(ke(F,""),{title:r("skills.updateFailed"),type:"error"})}finally{v(!1)}}},X=async()=>{if(d){me(!0);try{await Q.deleteSkill(d.skillName),re(r("skills.deleteSuccess"),{title:`Skill "${d.skillName}" ${r("skills.deleteSuccess")}`}),g(null),ae(!1),O(!1),je(),t?.()}catch(F){re(ke(F,""),{title:r("skills.deleteFailed"),type:"error"})}finally{me(!1)}}},oe=async()=>{w(!0),z(!0);try{const[F,Se]=await Promise.allSettled([Q.suggestSkills(),Q.getSignalStatus()]),Te=F.status==="fulfilled"?F.value.suggestions||[]:[],Fe=Se.status==="fulfilled"?Se.value.suggestions||[]:[],Me=new Map;for(const ce of Te)Me.set(ce.name,ce);for(const ce of Fe)Me.set(ce.name,{...Me.get(ce.name),...ce});const ee=[...Me.values()];P(ee),a?.(ee.length)}catch(F){re(ke(F,""),{title:r("skills.aiRecommendFailed"),type:"error"}),P([]),a?.(0)}finally{w(!1)}};n.useEffect(()=>{s>0&&I.length===0&&!B&&oe()},[]);const pe=async F=>{E(F.name);try{const Se=F.description||F.rationale||F.name,Te=`${r("skillsView.aiPromptPrefix")}
98
98
 
99
99
  名称:${F.name}
100
100
  描述:${Se}
@@ -106,7 +106,7 @@ ${F.rationale||""}`;Me=Me.replace(/^\s*\{["']name["']\s*:.*\}\s*\n?/,"").trim(),
106
106
  `);for(let v=0;v<Math.min(N.length,5);v++){const U=N[v].trim();if(!(!U||U.startsWith("```"))&&U.startsWith("{")&&U.endsWith("}"))try{const ae=JSON.parse(U);if(ae.name){E=ae.name,L=ae.description||"";let be=v+1;for(;be<N.length&&!N[be].trim();)be++;O=N.slice(be).join(`
107
107
  `).trim();break}}catch{}}}if(!E){const N=/"name"\s*:\s*"([a-z][a-z0-9-]{1,62}[a-z0-9])"/,v=/"description"\s*:\s*"([^"]+)"/,U=k.match(N),ae=k.match(v);U&&(E=U[1]),ae&&(L=ae[1])}O=O.replace(/```(?:json)?\s*\n?\s*\{[^}]*"name"[^}]*\}\s*\n?\s*```/gi,"").replace(/^\s*\{[^}]*"name"[^}]*\}\s*$/gm,"").trim(),E&&x(E),L&&u(L),c(O||k.trim()),J(!0),o("manual"),re(a("skills.checkGenerated"),{title:a("skills.aiGenerated")})}catch(z){I(a("skills.aiGenFailed")+": "+ke(z,""))}finally{d(!1)}}},B=async()=>{if(!g.trim()||!h.trim()||!m.trim()){I(a("skills.fillRequired"));return}A(!0),I("");try{await Q.createSkill({name:g.trim(),description:h.trim(),content:m.trim(),createdBy:P?"user-ai":"manual"}),re(a("skills.savedToKB"),{title:`Skill "${g}" ${a("skills.createSuccess")}`}),s()}catch(z){I(a("skills.createFailed")+": "+ke(z,""))}finally{A(!1)}};return e.jsxs($e,{className:"z-40 flex items-center justify-center",children:[e.jsx($e.Backdrop,{className:"bg-black/20 dark:bg-black/40 backdrop-blur-sm"}),e.jsxs("div",{className:"relative bg-[var(--bg-surface)] rounded-2xl shadow-2xl w-[720px] max-h-[85vh] flex flex-col",children:[e.jsxs("div",{className:"flex items-center justify-between px-6 py-4 border-b border-[var(--border-default)]",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-8 h-8 bg-violet-100 rounded-lg flex items-center justify-center",children:e.jsx(Le,{size:16,className:"text-violet-600"})}),e.jsx("h3",{className:"font-bold text-lg",children:a("skills.addSkill")})]}),e.jsx("button",{onClick:t,className:"p-1.5 rounded-lg hover:bg-[var(--bg-subtle)] transition-colors",children:e.jsx(ze,{size:18,className:"text-[var(--fg-muted)]"})})]}),e.jsx("div",{className:"px-6 pt-4",children:e.jsxs("div",{className:"inline-flex items-center gap-1 p-1 bg-[var(--bg-subtle)] rounded-lg",children:[e.jsxs("button",{onClick:()=>o("ai"),className:`flex items-center gap-1.5 px-3 py-1.5 rounded-md text-xs font-medium transition-colors ${r==="ai"?"bg-[var(--bg-surface)] text-violet-700 shadow-sm":"text-[var(--fg-secondary)] hover:text-[var(--fg-primary)]"}`,children:[e.jsx(Le,{size:12}),a("skills.aiGenMode")]}),e.jsxs("button",{onClick:()=>o("manual"),className:`flex items-center gap-1.5 px-3 py-1.5 rounded-md text-xs font-medium transition-colors ${r==="manual"?"bg-[var(--bg-surface)] text-violet-700 shadow-sm":"text-[var(--fg-secondary)] hover:text-[var(--fg-primary)]"}`,children:[e.jsx(Qe,{size:12}),a("skills.manualMode")]})]})}),e.jsxs("div",{className:"flex-1 overflow-y-auto px-6 py-4 space-y-4",children:[r==="ai"?e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-[var(--fg-primary)] mb-1.5",children:a("skills.describeSkill")}),e.jsx("div",{className:"relative",children:e.jsx("textarea",{value:l,onChange:z=>i(z.target.value),placeholder:a("skillsView.placeholderDesc"),className:"w-full h-32 px-4 py-3 border border-[var(--border-default)] rounded-xl text-sm resize-none focus:outline-none focus:ring-2 focus:ring-violet-300 focus:border-violet-400",disabled:p})})]}),e.jsx("button",{onClick:w,disabled:p||!l.trim(),className:"w-full flex items-center justify-center gap-2 px-4 py-3 bg-violet-600 text-white rounded-xl hover:bg-violet-700 disabled:opacity-50 disabled:cursor-not-allowed transition-colors font-medium",children:p?e.jsxs(e.Fragment,{children:[e.jsx(Ne,{size:16,className:"animate-spin"}),a("skills.aiGeneratingContent")]}):e.jsxs(e.Fragment,{children:[e.jsx(Zs,{size:16}),a("skills.generateSkill")]})})]}):e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-1 xl:grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsxs("label",{className:"block text-sm font-medium text-[var(--fg-primary)] mb-1.5",children:[a("skills.skillName")," ",e.jsx("span",{className:"text-[var(--fg-muted)] text-xs",children:"(kebab-case)"})]}),e.jsx("input",{type:"text",value:g,onChange:z=>x(z.target.value),placeholder:"my-custom-skill",className:"w-full px-3 py-2 border border-[var(--border-default)] rounded-lg text-sm font-mono focus:outline-none focus:ring-2 focus:ring-violet-300 focus:border-violet-400"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-[var(--fg-primary)] mb-1.5",children:a("skills.skillDescription")}),e.jsx("input",{type:"text",value:h,onChange:z=>u(z.target.value),placeholder:a("skillsView.placeholderName"),className:"w-full px-3 py-2 border border-[var(--border-default)] rounded-lg text-sm focus:outline-none focus:ring-2 focus:ring-violet-300 focus:border-violet-400"})]})]}),e.jsxs("div",{children:[e.jsxs("label",{className:"block text-sm font-medium text-[var(--fg-primary)] mb-1.5",children:[a("skills.skillContent")," ",e.jsx("span",{className:"text-[var(--fg-muted)] text-xs",children:"(Markdown)"})]}),e.jsx("textarea",{value:m,onChange:z=>c(z.target.value),placeholder:a("skillsView.placeholderContent"),className:"w-full h-64 px-4 py-3 border border-[var(--border-default)] rounded-xl text-sm font-mono resize-none focus:outline-none focus:ring-2 focus:ring-violet-300 focus:border-violet-400 leading-relaxed"})]})]}),D&&e.jsxs("div",{className:"flex items-start gap-2 p-3 bg-red-50 border border-red-200 rounded-lg text-sm text-red-700",children:[e.jsx(Et,{size:16,className:"shrink-0 mt-0.5"}),e.jsx("span",{children:D})]})]}),e.jsxs("div",{className:"px-6 py-4 border-t border-[var(--border-default)] flex items-center justify-end gap-3",children:[e.jsx("button",{onClick:t,className:"px-4 py-2 text-sm text-[var(--fg-secondary)] hover:text-[var(--fg-primary)] transition-colors",children:a("common.cancel")}),r==="manual"&&e.jsx("button",{onClick:B,disabled:j||!g.trim()||!h.trim()||!m.trim(),className:"flex items-center gap-2 px-5 py-2 bg-violet-600 text-white rounded-lg hover:bg-violet-700 disabled:opacity-50 disabled:cursor-not-allowed transition-colors text-sm font-medium",children:j?e.jsxs(e.Fragment,{children:[e.jsx(Ne,{size:14,className:"animate-spin"}),a("common.saving")]}):e.jsxs(e.Fragment,{children:[e.jsx(mt,{size:14}),a("skills.addSkill")]})})]})]})]})},Ha=["architecture","swift-objc-idiom","ts-js-module","python-structure","jvm-annotation","go-module","rust-ownership","csharp-dotnet","react-patterns","vue-patterns","spring-patterns","swiftui-patterns","django-fastapi","coding-standards","design-patterns","ui-interaction","error-resilience","concurrency-async","data-event-flow","networking-api","testing-quality","security-auth","performance-optimization","observability-logging","agent-guidelines"],Lc={architecture:e.jsx(Ge,{className:"w-5 h-5"}),"coding-standards":e.jsx(qe,{className:"w-5 h-5"}),"design-patterns":e.jsx(At,{className:"w-5 h-5"}),"error-resilience":e.jsx(Le,{className:"w-5 h-5"}),"concurrency-async":e.jsx(Be,{className:"w-5 h-5"}),"data-event-flow":e.jsx(Be,{className:"w-5 h-5"}),"networking-api":e.jsx(Vt,{className:"w-5 h-5"}),"ui-interaction":e.jsx(Ge,{className:"w-5 h-5"}),"testing-quality":e.jsx(At,{className:"w-5 h-5"}),"security-auth":e.jsx(Vt,{className:"w-5 h-5"}),"performance-optimization":e.jsx(Le,{className:"w-5 h-5"}),"observability-logging":e.jsx(qe,{className:"w-5 h-5"}),"agent-guidelines":e.jsx(aa,{className:"w-5 h-5"})};function Fc(t){return Lc[t]||e.jsx(At,{className:"w-5 h-5"})}const _c=({task:t})=>{const{t:s}=Ae(),{status:a,meta:r}=t,o={skeleton:"bg-[var(--bg-subtle)] border-[var(--border-default)]",filling:"bg-blue-50 border-blue-300",completed:"bg-emerald-50 border-emerald-300",failed:"bg-red-50 border-red-300"},l={skeleton:e.jsxs("span",{className:"flex items-center gap-1 text-xs text-[var(--fg-muted)]",children:[e.jsx("div",{className:"w-2 h-2 rounded-full bg-[var(--border-emphasis)]"}),s("bootstrap.statusLabels.skeleton")]}),filling:e.jsxs("span",{className:"flex items-center gap-1 text-xs text-blue-600",children:[e.jsx(Ne,{className:"w-3 h-3 animate-spin"}),s("bootstrap.statusLabels.filling")]}),completed:e.jsxs("span",{className:"flex items-center gap-1 text-xs text-emerald-600",children:[e.jsx(ot,{className:"w-3 h-3"}),s("bootstrap.statusLabels.completed")]}),failed:e.jsxs("span",{className:"flex items-center gap-1 text-xs text-red-600",children:[e.jsx(ze,{className:"w-3 h-3"}),s("bootstrap.statusLabels.failed")]})};return e.jsxs("div",{className:`relative rounded-xl border p-4 transition-all duration-300 ${o[a]||o.skeleton}`,children:[a==="skeleton"&&e.jsx("div",{className:"absolute inset-0 rounded-xl overflow-hidden",children:e.jsx("div",{className:"animate-pulse bg-gradient-to-r from-transparent via-[var(--border-default)]/40 to-transparent h-full w-full"})}),a==="filling"&&e.jsx("div",{className:"absolute inset-0 rounded-xl overflow-hidden",children:e.jsx("div",{className:"animate-pulse bg-gradient-to-r from-transparent via-blue-200/30 to-transparent h-full w-full"})}),e.jsxs("div",{className:"relative z-10 flex items-start justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:`flex-shrink-0 p-2 rounded-lg ${a==="completed"?"bg-emerald-100 text-emerald-600":a==="filling"?"bg-blue-100 text-blue-600":a==="failed"?"bg-red-100 text-red-600":"bg-[var(--bg-subtle)] text-[var(--fg-muted)]"}`,children:Fc(t.id)}),e.jsxs("div",{children:[e.jsx("h3",{className:`font-medium text-sm ${a==="skeleton"?"text-[var(--fg-muted)]":"text-[var(--fg-primary)]"}`,children:(()=>{const i=`bootstrap.pipelineLabels.${r.dimId}`,p=s(i);return p!==i?p:r.label})()}),a==="completed"&&t.result&&e.jsx("p",{className:"text-xs text-emerald-600 mt-0.5",children:(()=>{const i=t.result,p=i.sourceCount??0,d=i.extracted??0;return i.type==="empty"?s("bootstrap.noMatch"):i.type==="skill"?i.empty?s("bootstrap.noMatch"):d>0?s("bootstrap.featuresAndCandidates",{sourceCount:p,extracted:d}):s("bootstrap.featuresOnly",{sourceCount:p}):d>0?s("bootstrap.candidatesOnly",{extracted:d}):s("bootstrap.noMatch")})()}),a==="failed"&&t.error&&e.jsx("p",{className:"text-xs text-red-500 mt-0.5 truncate max-w-[240px]",children:t.error})]})]}),e.jsx("div",{className:"flex-shrink-0",children:l[a]})]})]})},zc=[{key:"round1",labelKey:"bootstrap.reviewRounds.round1Label",descKey:"bootstrap.reviewRounds.round1Desc",icon:e.jsx(sa,{className:"w-4 h-4"})},{key:"round2",labelKey:"bootstrap.reviewRounds.round2Label",descKey:"bootstrap.reviewRounds.round2Desc",icon:e.jsx(us,{className:"w-4 h-4"})},{key:"round3",labelKey:"bootstrap.reviewRounds.round3Label",descKey:"bootstrap.reviewRounds.round3Desc",icon:e.jsx(fl,{className:"w-4 h-4"})}],Bc=({review:t})=>{const{t:s}=Ae();return t.activeRound===0?null:e.jsxs("div",{className:"mt-5 border border-purple-200 rounded-xl bg-purple-50/50 p-4",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[e.jsx(Mt,{className:"w-5 h-5 text-purple-600"}),e.jsx("h3",{className:"text-sm font-semibold text-purple-800",children:s("bootstrap.reviewPipeline")})]}),e.jsx("div",{className:"space-y-2.5",children:zc.map(({key:a,labelKey:r,descKey:o,icon:l})=>{const i=t[a],p=i.status==="running",d=i.status==="completed",g=i.status==="idle";return e.jsxs("div",{className:`flex items-center gap-3 p-2.5 rounded-lg border transition-all duration-300 ${p?"border-purple-300 bg-purple-100/60":d?"border-emerald-300 bg-emerald-50/60":"border-[var(--border-default)] bg-[var(--bg-surface)]"}`,children:[e.jsx("div",{className:`flex-shrink-0 p-1.5 rounded-md ${p?"bg-purple-200 text-purple-700":d?"bg-emerald-100 text-emerald-600":"bg-[var(--bg-subtle)] text-[var(--fg-muted)]"}`,children:l}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:`text-sm font-medium ${g?"text-[var(--fg-muted)]":"text-[var(--fg-primary)]"}`,children:s(r)}),e.jsx("span",{className:"text-xs text-[var(--fg-muted)]",children:s(o)})]}),a==="round1"&&d&&e.jsx("p",{className:"text-xs text-emerald-600 mt-0.5",children:s("bootstrap.round1Done",{kept:t.round1.kept??"?",merged:t.round1.merged??0,dropped:t.round1.dropped??0})}),a==="round2"&&p&&typeof t.round2.progress=="number"&&e.jsxs("div",{className:"mt-1.5",children:[e.jsx("div",{className:"w-full h-1.5 bg-purple-200 rounded-full overflow-hidden",children:e.jsx("div",{className:"h-full bg-purple-500 rounded-full transition-all duration-300",style:{width:`${t.round2.progress}%`}})}),e.jsx("p",{className:"text-xs text-purple-600 mt-0.5",children:s("bootstrap.round2Progress",{current:t.round2.current??0,total:t.round2.total??"?"})})]}),a==="round2"&&d&&e.jsx("p",{className:"text-xs text-emerald-600 mt-0.5",children:s("bootstrap.round2Done",{refined:t.round2.refined??"?",total:t.round2.total??"?"})}),a==="round3"&&d&&e.jsx("p",{className:"text-xs text-emerald-600 mt-0.5",children:s("bootstrap.round3Done",{afterDedup:t.round3.afterDedup??"?",relationsFound:t.round3.relationsFound??0})})]}),e.jsxs("div",{className:"flex-shrink-0",children:[p&&e.jsx(Ne,{className:"w-4 h-4 text-purple-500 animate-spin"}),d&&e.jsx(ot,{className:"w-4 h-4 text-emerald-500"})]})]},a)})})]})};function Ka(t){if(t<0)return"--";const s=Math.floor(t/1e3),a=Math.floor(s/60),r=s%60;return a===0?`${r}s`:`${a}m ${r.toString().padStart(2,"0")}s`}const Gc=({session:t,isAllDone:s,reviewState:a,onDismiss:r,onCancel:o,isCancelling:l=!1})=>{const{t:i}=Ae(),[p,d]=n.useState(Date.now());if(n.useEffect(()=>{if(!t||t.status!=="running")return;const A=setInterval(()=>d(Date.now()),1e3);return()=>clearInterval(A)},[t?.status]),!t)return null;const g=t.startedAt?p-t.startedAt:t.elapsedMs??0,x=t.completed+t.failed,h=t.total-x,u=t.elapsedMs??0,m=x>0&&u>0?Math.round(u/x*h):-1,c=t.totalToolCalls??0,j=t.status==="completed"?i("bootstrap.allCompleted"):t.status==="completed_with_errors"?i("bootstrap.completedWithErrors"):null;return e.jsxs("div",{className:"bg-[var(--bg-surface)] rounded-2xl border border-[var(--border-default)] shadow-sm p-6",children:[e.jsxs("div",{className:"flex items-center justify-between mb-5",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-lg font-semibold text-[var(--fg-primary)]",children:i("bootstrap.title")}),j&&e.jsx("p",{className:"text-sm text-[var(--fg-secondary)] mt-0.5",children:j})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[t.status==="running"&&o&&e.jsxs("button",{onClick:o,disabled:l,className:"flex items-center gap-1.5 text-sm px-3 py-1.5 rounded-lg border border-red-200 bg-red-50 hover:bg-red-100 text-red-600 transition-colors disabled:opacity-50 disabled:cursor-not-allowed",children:[l?e.jsx(Ne,{size:14,className:"animate-spin"}):e.jsx(bl,{size:14}),i("bootstrap.cancel")]}),s&&r&&e.jsx("button",{onClick:r,className:"text-sm px-3 py-1.5 rounded-lg bg-[var(--bg-subtle)] hover:bg-[var(--bg-subtle)] text-[var(--fg-secondary)] transition-colors",children:i("bootstrap.close")})]})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-4 mb-5 text-sm",children:[e.jsxs("div",{className:"flex items-center gap-1.5 text-[var(--fg-secondary)]",children:[e.jsx(Ye,{size:14,className:"text-[var(--fg-muted)]"}),e.jsxs("span",{children:[i("bootstrap.elapsed")," ",e.jsx("span",{className:"font-medium text-[var(--fg-primary)]",children:Ka(g)})]})]}),t.status==="running"&&h>0&&m>0&&e.jsxs("div",{className:"flex items-center gap-1.5 text-[var(--fg-secondary)]",children:[e.jsx(Ye,{size:14,className:"text-blue-400"}),e.jsxs("span",{children:[i("bootstrap.estimatedRemaining")," ",e.jsx("span",{className:"font-medium text-blue-600",children:Ka(m)})]})]}),e.jsxs("div",{className:"flex items-center gap-1.5 text-[var(--fg-secondary)]",children:[e.jsx(Ks,{size:14,className:"text-[var(--fg-muted)]"}),e.jsxs("span",{children:[i("bootstrap.toolCalls")," ",e.jsx("span",{className:"font-medium text-[var(--fg-primary)]",children:c})]})]}),e.jsx("div",{className:"text-[var(--fg-muted)] text-xs",children:i("bootstrap.dimensions",{done:x,total:t.total})})]}),e.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-3",children:[...t.tasks].sort((A,D)=>{const I=Ha.indexOf(A.meta?.dimId??A.id),P=Ha.indexOf(D.meta?.dimId??D.id);return(I===-1?999:I)-(P===-1?999:P)}).map(A=>e.jsx(_c,{task:A},A.id))}),a&&a.activeRound>0&&e.jsx(Bc,{review:a})]})},cs={index:{icon:qe,color:"text-blue-600",label:"overview"},architecture:{icon:Ge,color:"text-violet-600",label:"architecture"},"getting-started":{icon:pt,color:"text-emerald-600",label:"getting-started"},protocols:{icon:Le,color:"text-amber-600",label:"protocols"},components:{icon:pt,color:"text-emerald-600",label:"components"},patterns:{icon:Le,color:"text-amber-600",label:"patterns"},module:{icon:Lt,color:"text-cyan-600",label:"module"},document:{icon:Qe,color:"text-orange-600",label:"document"},_index:{icon:Ys,color:"text-[var(--fg-secondary)]",label:"index"}};function $c(t){const s=t.split("/").pop()?.replace(".md","")||"";return s==="_index"?cs._index:t.startsWith("modules/")?cs.module:t.startsWith("documents/")?cs.document:cs[s]||{icon:Qe,color:"text-[var(--fg-secondary)]",label:"doc"}}const Oc={"cursor-devdocs":{label:"Cursor Docs",color:"text-orange-700",bg:"bg-orange-50 border-orange-200"}},Hc={modules:"modules",documents:"documents"};function en(t){return t<1e3?`${t}ms`:`${(t/1e3).toFixed(1)}s`}function Kc(t){if(!t)return"";const s=new Date(t);if(isNaN(s.getTime()))return"";const r=Date.now()-s.getTime();return r<6e4?"just now":r<36e5?`${Math.floor(r/6e4)} min ago`:r<864e5?`${Math.floor(r/36e5)} hr ago`:r<6048e5?`${Math.floor(r/864e5)} d ago`:s.toLocaleDateString("zh-CN")}const qc=({task:t,wiki:s})=>{const{t:a}=Ae();return t.status==="running"?null:t.status==="error"?e.jsxs("div",{className:"bg-red-50 border border-red-200 rounded-xl p-4 mb-6 flex items-center gap-3",children:[e.jsx("div",{className:"p-1.5 bg-red-100 rounded-lg",children:e.jsx(Et,{size:H.md,className:"text-red-600"})}),e.jsxs("div",{children:[e.jsx("span",{className:"font-semibold text-red-800",children:a("wiki.genFailed")}),e.jsx("span",{className:"text-sm text-red-600 ml-3",children:t.error||a("common.operationFailed")})]})]}):s?.exists&&s.hasChanges?e.jsxs("div",{className:"bg-amber-50 border border-amber-200 rounded-xl p-4 mb-6 flex items-center gap-3",children:[e.jsx("div",{className:"p-1.5 bg-amber-100 rounded-lg",children:e.jsx(Et,{size:H.md,className:"text-amber-600"})}),e.jsx("span",{className:"text-sm text-amber-700",children:a("wiki.outOfDateHint")})]}):null};function Uc(t,s){const a=[],r=new Map(s?.map(g=>[g.path,g])||[]),o=[],l=new Map;for(const g of t){const x=g.path.split("/"),h=r.get(g.path);if(x.length===1)o.push({name:x[0],path:g.path,isDir:!1,file:g,metaInfo:h});else{const u=x[0];l.has(u)||l.set(u,[]),l.get(u).push({name:x.slice(1).join("/"),path:g.path,isDir:!1,file:g,metaInfo:h})}}const i=["index.md","architecture.md","getting-started.md","patterns.md","protocols.md","components.md"];o.sort((g,x)=>{const h=i.indexOf(g.name),u=i.indexOf(x.name);return h!==-1&&u!==-1?h-u:h!==-1?-1:u!==-1?1:g.name.localeCompare(x.name)}),a.push(...o);const p=["modules","patterns","documents"],d=[...l.entries()].sort(([g],[x])=>{const h=p.indexOf(g),u=p.indexOf(x);return h!==-1&&u!==-1?h-u:h!==-1?-1:u!==-1?1:g.localeCompare(x)});for(const[g,x]of d){const h=x.filter(u=>!u.name.startsWith("_index")).sort((u,m)=>u.name.localeCompare(m.name));a.push({name:g,path:g,isDir:!0,children:h})}return a}const Wc=({tree:t,selectedFile:s,onSelect:a,searchQuery:r})=>{const[o,l]=n.useState(new Set(["modules","documents"])),i=g=>{l(x=>{const h=new Set(x);return h.has(g)?h.delete(g):h.add(g),h})},d=(g=>{if(!r)return g;const x=r.toLowerCase();return g.filter(h=>h.isDir?h.children?.some(u=>u.name.toLowerCase().includes(x)||u.path.toLowerCase().includes(x)):h.name.toLowerCase().includes(x)||h.path.toLowerCase().includes(x))})(t);return e.jsx("div",{className:"space-y-0.5",children:d.map(g=>{if(g.isDir){const x=o.has(g.path),h=r.toLowerCase(),u=r?g.children?.filter(m=>m.name.toLowerCase().includes(h)||m.path.toLowerCase().includes(h)):g.children;return e.jsxs("div",{children:[e.jsxs("button",{onClick:()=>i(g.path),className:"w-full flex items-center gap-2 px-3 py-2 text-sm text-[var(--fg-secondary)] hover:bg-[var(--bg-subtle)] rounded-lg transition-colors",children:[x?e.jsx(vt,{size:14,className:"text-[var(--fg-muted)] flex-shrink-0"}):e.jsx(Ue,{size:14,className:"text-[var(--fg-muted)] flex-shrink-0"}),e.jsx(Lt,{size:14,className:"text-amber-500 flex-shrink-0"}),e.jsx("span",{className:"font-medium truncate",children:Hc[g.name]||g.name}),e.jsx("span",{className:"ml-auto text-xs text-[var(--fg-muted)]",children:u?.length||0})]}),x&&u&&e.jsx("div",{className:"ml-3",children:u.map(m=>e.jsx(qa,{node:m,isActive:s===m.path,onSelect:a},m.path))})]},g.path)}return e.jsx(qa,{node:g,isActive:s===g.path,onSelect:a},g.path)})})},qa=({node:t,isActive:s,onSelect:a})=>{const r=$c(t.path),o=r.icon,l=t.metaInfo?.polished,i=t.metaInfo?.source;return e.jsxs("button",{onClick:()=>a(t.path),className:`w-full flex items-center gap-2 px-3 py-2 text-sm rounded-lg transition-all ${s?"bg-blue-50 text-blue-700 border border-blue-200 shadow-sm":"text-[var(--fg-secondary)] hover:bg-[var(--bg-subtle)]"}`,children:[e.jsx(o,{size:14,className:`flex-shrink-0 ${s?"text-blue-500":r.color}`}),e.jsx("span",{className:"truncate text-left",children:t.name.replace(".md","")}),e.jsxs("span",{className:"ml-auto flex items-center gap-1 flex-shrink-0",children:[l&&e.jsx("span",{title:"AI Enhanced",children:e.jsx(Le,{size:10,className:"text-violet-400"})}),i&&e.jsx("span",{title:`Source: ${i}`,children:e.jsx(yl,{size:10,className:"text-orange-400"})})]})]})},Vc=({filePath:t,content:s,loading:a,meta:r,onBack:o})=>{const{t:l}=Ae(),[i,p]=n.useState(!1),d=r?.files?.find(u=>u.path===t),g=()=>{navigator.clipboard.writeText(s).catch(()=>{}),p(!0),setTimeout(()=>p(!1),2e3)},x=t.split("/"),h=x.map((u,m)=>({label:m===x.length-1?u.replace(".md",""):u,isLast:m===x.length-1}));return e.jsxs("div",{className:"flex flex-col h-full",children:[e.jsxs("div",{className:"flex items-center justify-between px-5 py-3 bg-[var(--bg-subtle)] border-b border-[var(--border-default)] flex-shrink-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{onClick:o,className:"p-1.5 hover:bg-[var(--bg-subtle)] rounded-lg transition-colors lg:hidden",title:l("wiki.backToList"),children:e.jsx(vl,{size:H.md})}),e.jsxs("div",{className:"flex items-center gap-1 text-sm",children:[e.jsx(qe,{size:14,className:"text-[var(--fg-muted)]"}),e.jsx("span",{className:"text-[var(--fg-muted)]",children:"wiki"}),h.map((u,m)=>e.jsxs(it.Fragment,{children:[e.jsx(Ue,{size:12,className:"text-[var(--fg-muted)]"}),e.jsx("span",{className:u.isLast?"font-medium text-[var(--fg-primary)]":"text-[var(--fg-muted)]",children:u.label})]},m))]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[d?.polished&&e.jsxs("span",{className:"flex items-center gap-1 text-xs text-violet-700 bg-violet-50 border border-violet-200 px-2 py-0.5 rounded-full",children:[e.jsx(Le,{size:10}),l("wiki.aiBadge")]}),d?.source&&(()=>{const u=Oc[d.source];return e.jsx("span",{className:`flex items-center gap-1 text-xs border px-2 py-0.5 rounded-full ${u?.bg||"bg-[var(--bg-subtle)] border-[var(--border-default)]"} ${u?.color||"text-[var(--fg-secondary)]"}`,children:u?.label||d.source})})(),e.jsxs("button",{onClick:g,className:"flex items-center gap-1 px-2.5 py-1 text-xs text-[var(--fg-secondary)] hover:text-[var(--fg-primary)] hover:bg-[var(--bg-subtle)] rounded-md transition-colors",children:[i?e.jsx(ot,{size:12,className:"text-emerald-500"}):e.jsx(Rr,{size:12}),l(i?"wiki.copySuccess":"wiki.copyBtn")]})]})]}),e.jsx("div",{className:"flex-1 overflow-auto scrollbar-light",style:{scrollbarGutter:"stable"},children:a?e.jsx("div",{className:"flex items-center justify-center py-20",children:e.jsx(Ne,{size:H.xl,className:"text-blue-500 animate-spin"})}):e.jsx("div",{className:"px-4 xl:px-6 2xl:px-8 py-6 max-w-4xl mx-auto",children:e.jsx(Qt,{content:s,className:"wiki-reader"})})})]})},Jc=()=>{const{t}=Ae();return e.jsxs("div",{className:"h-72 flex flex-col items-center justify-center bg-[var(--bg-surface)] rounded-2xl border border-dashed border-[var(--border-default)] text-[var(--fg-muted)]",children:[e.jsx("div",{className:"w-16 h-16 rounded-2xl bg-[var(--bg-subtle)] flex items-center justify-center mb-4",children:e.jsx(qe,{size:32,className:"text-[var(--fg-muted)]"})}),e.jsx("p",{className:"text-sm font-medium text-[var(--fg-secondary)]",children:t("wiki.emptyTitle")}),e.jsx("p",{className:"mt-2 text-xs max-w-sm text-center leading-relaxed text-[var(--fg-muted)]",children:t("wiki.emptyDesc")}),e.jsx("p",{className:"mt-3 text-[11px] text-[var(--fg-muted)]",children:t("wiki.emptyHint")})]})},Yc=({meta:t,onSelectFile:s,isGenerating:a,progress:r,message:o})=>{const{t:l}=Ae(),i=[{path:"index.md",label:l("wiki.quickOverview"),desc:l("wiki.quickOverviewDesc"),icon:qe,color:"bg-blue-50 text-blue-600 border-blue-200"},{path:"architecture.md",label:l("wiki.quickArch"),desc:l("wiki.quickArchDesc"),icon:Ge,color:"bg-violet-50 text-violet-600 border-violet-200"},{path:"getting-started.md",label:l("wiki.quickStart"),desc:l("wiki.quickStartDesc"),icon:pt,color:"bg-emerald-50 text-emerald-600 border-emerald-200"},{path:"protocols.md",label:l("wiki.quickProtocols"),desc:l("wiki.quickProtocolsDesc"),icon:Le,color:"bg-amber-50 text-amber-600 border-amber-200"}],p=new Set(t?.files?.map(g=>g.path||g.name)??[]),d=i.filter(g=>p.size===0||p.has(g.path));return e.jsxs("div",{className:"p-4 xl:p-6 2xl:p-8 overflow-y-auto flex-1",children:[a&&e.jsxs("div",{className:"mb-8 flex flex-col items-center",children:[e.jsxs("div",{className:"relative w-20 h-20 mb-5",children:[e.jsx("span",{className:"absolute inset-0 rounded-full bg-blue-100 animate-ping opacity-20"}),e.jsx("span",{className:"absolute inset-2 rounded-full bg-blue-50 animate-pulse"}),e.jsx("div",{className:"absolute inset-0 flex items-center justify-center",children:e.jsx(aa,{size:36,className:"text-blue-500 animate-pulse"})})]}),e.jsx("h3",{className:"text-lg font-semibold text-[var(--fg-primary)] mb-1",children:l("wiki.wikiGenerating")}),e.jsx("p",{className:"text-sm text-[var(--fg-secondary)] max-w-md text-center leading-relaxed",children:o||l("wiki.generating")}),typeof r=="number"&&e.jsxs("div",{className:"mt-4 w-48",children:[e.jsx("div",{className:"w-full bg-[var(--bg-subtle)] rounded-full h-2",children:e.jsx("div",{className:"bg-gradient-to-r from-blue-500 to-indigo-500 h-2 rounded-full transition-all duration-700 ease-out",style:{width:`${Math.max(r,3)}%`}})}),e.jsxs("p",{className:"text-xs text-center text-blue-500 mt-1.5 font-mono",children:[r,"%"]})]})]}),!a&&e.jsxs("div",{className:"text-center mb-8",children:[e.jsx("div",{className:"w-12 h-12 bg-[var(--bg-subtle)] rounded-xl flex items-center justify-center mx-auto mb-3",children:e.jsx(Qe,{size:24,className:"text-[var(--fg-muted)]"})}),e.jsx("h3",{className:"text-lg font-semibold text-[var(--fg-primary)]",children:l("wiki.selectFile")}),e.jsx("p",{className:"text-sm text-[var(--fg-secondary)] mt-1",children:l("wiki.selectPlaceholder")})]}),e.jsx("div",{className:"grid grid-cols-2 gap-3 max-w-lg mx-auto",children:d.map(g=>{const x=g.icon;return e.jsxs("button",{onClick:()=>s(g.path),className:`text-left p-4 rounded-xl border ${g.color} hover:shadow-sm transition-all group`,children:[e.jsx(x,{size:20,className:"mb-2 opacity-70 group-hover:opacity-100"}),e.jsx("div",{className:"font-medium text-sm",children:g.label}),e.jsx("div",{className:"text-xs opacity-60 mt-0.5",children:g.desc})]},g.path)})}),t&&e.jsxs("div",{className:"mt-8 text-center text-xs text-[var(--fg-muted)]",children:[t.generatedAt&&`${l("wiki.lastGenerated")}: ${new Date(t.generatedAt).toLocaleString()}`,t.duration!=null&&` · ${l("wiki.duration")} ${en(t.duration)}`,t.version&&` · v${t.version}`]})]})},Qc=()=>{const{t}=Ae(),[s,a]=n.useState({task:{status:"idle"}}),[r,o]=n.useState([]),[l,i]=n.useState(!1),[p,d]=n.useState(null),[g,x]=n.useState(""),[h,u]=n.useState(!1),[m,c]=n.useState(!0),[j,A]=n.useState(""),[D,I]=n.useState(null),P=n.useRef(null),J=n.useCallback(async()=>{try{const q=await Q.wikiStatus();return a(q),q}catch{return null}},[]),w=n.useCallback(async()=>{try{const q=await Q.wikiFiles();o(q.files||[]),i(q.exists)}catch{}},[]),B=n.useCallback(async()=>{try{const q=await Q.wikiFileContent("meta.json");q?.content&&I(JSON.parse(q.content))}catch{}},[]);n.useEffect(()=>{(async()=>(c(!0),await Promise.all([J(),w(),B()]),c(!1)))()},[J,w,B]),n.useEffect(()=>{if(s.task.status==="running"){let q=0;P.current=setInterval(async()=>{const N=await J();q++,q%3===0&&await w(),N&&N.task.status!=="running"&&(await Promise.all([w(),B()]),P.current&&clearInterval(P.current))},1500)}else P.current&&clearInterval(P.current);return()=>{P.current&&clearInterval(P.current)}},[s.task.status,J,w,B]);const z=async()=>{try{await Q.wikiUpdate(),a(q=>({...q,task:{...q.task,status:"running",progress:0,message:t("wiki.incrementalUpdating")}}))}catch(q){console.error("Wiki update failed:",q)}},k=async q=>{if(q!=="meta.json"){d(q),u(!0);try{const N=await Q.wikiFileContent(q);x(N.content)}catch{x(`# ${t("wiki.loadFailed")}
108
108
 
109
- ${t("wiki.loadFailedDesc")}`)}finally{u(!1)}}},E=()=>{d(null),x("")},L=n.useMemo(()=>r.filter(q=>q.path!=="meta.json"),[r]),O=n.useMemo(()=>Uc(L,D?.files),[L,D]);if(m)return e.jsx("div",{className:"flex items-center justify-center h-64",children:e.jsx(Ne,{size:H.xl,className:"text-blue-500 animate-spin"})});const W=!l&&L.length===0&&s.task.status!=="running";return e.jsxs("div",{className:"h-full flex flex-col overflow-hidden p-6 pt-4",children:[e.jsx(qc,{task:s.task,wiki:s.wiki}),W?e.jsx(Jc,{}):e.jsxs(e.Fragment,{children:[s.task.status==="running"&&e.jsxs("div",{className:"mb-3 flex items-center gap-3 px-4 py-2.5 bg-gradient-to-r from-blue-50 to-indigo-50 border border-blue-200/70 rounded-xl shrink-0",children:[e.jsxs("div",{className:"relative flex items-center justify-center w-6 h-6",children:[e.jsx("span",{className:"absolute inline-flex h-full w-full rounded-full bg-blue-400 opacity-30 animate-ping"}),e.jsx(Ne,{size:16,className:"text-blue-600 animate-spin relative"})]}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("span",{className:"text-sm font-medium text-blue-800",children:t("wiki.wikiGenerating")}),s.task.message&&e.jsx("span",{className:"text-xs text-blue-500 ml-2 truncate",children:s.task.message})]}),e.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0",children:[e.jsx("div",{className:"w-24 bg-blue-100 rounded-full h-1.5",children:e.jsx("div",{className:"bg-blue-500 h-1.5 rounded-full transition-all duration-700 ease-out",style:{width:`${Math.max(s.task.progress||0,3)}%`}})}),e.jsxs("span",{className:"text-xs font-mono text-blue-600 w-8 text-right",children:[s.task.progress||0,"%"]})]})]}),e.jsxs("div",{className:"flex gap-4 flex-1 min-h-0 overflow-hidden",children:[e.jsxs("div",{className:`w-64 flex-shrink-0 bg-[var(--bg-surface)] border border-[var(--border-default)] rounded-xl flex flex-col overflow-hidden ${p?"hidden lg:flex":""}`,children:[e.jsxs("div",{className:"px-3 pt-3 pb-2 border-b border-[var(--border-default)] shrink-0",children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(qe,{size:16,className:"text-blue-500"}),e.jsx("span",{className:"text-sm font-semibold text-[var(--fg-primary)]",children:"Wiki"}),D?.version&&e.jsxs("span",{className:"text-[10px] text-[var(--fg-muted)]",children:["v",D.version]})]}),e.jsxs("div",{className:"flex items-center gap-1",children:[l&&e.jsx("span",{className:"text-[10px] text-[var(--fg-muted)]",children:t("wiki.fileCount",{count:L.length})}),s.task.status!=="running"&&l&&e.jsx("button",{onClick:z,title:t("wiki.incrementalUpdate"),className:"p-1 rounded-md text-blue-500 hover:bg-blue-50 transition-colors",children:e.jsx(at,{size:13})})]})]}),e.jsxs("div",{className:"relative",children:[e.jsx(xt,{size:14,className:"absolute left-3 top-1/2 -translate-y-1/2 text-[var(--fg-muted)]"}),e.jsx("input",{type:"text",placeholder:t("wiki.searchPlaceholder"),value:j,onChange:q=>A(q.target.value),className:"w-full pl-8 pr-3 py-2 text-sm bg-[var(--bg-subtle)] border border-[var(--border-default)] rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-200 focus:border-blue-300 transition-all"})]})]}),e.jsxs("div",{className:"p-2 overflow-y-auto flex-1 min-h-0 scrollbar-light",children:[e.jsx(Wc,{tree:O,selectedFile:p,onSelect:k,searchQuery:j}),s.task.status==="running"&&e.jsxs("div",{className:"mx-2 mt-3 mb-1 flex items-center gap-2 px-3 py-2 bg-blue-50 border border-blue-100 rounded-lg",children:[e.jsx(Ne,{size:12,className:"text-blue-500 animate-spin flex-shrink-0"}),e.jsx("span",{className:"text-[11px] text-blue-600 leading-tight",children:t("wiki.generating")})]})]}),D?.generatedAt&&e.jsx("div",{className:"px-3 py-2 border-t border-[var(--border-default)] shrink-0",children:e.jsxs("div",{className:"flex items-center gap-1.5 text-[10px] text-[var(--fg-muted)]",children:[e.jsx(Ye,{size:10}),e.jsx("span",{children:Kc(D.generatedAt)}),D.duration!=null&&e.jsxs("span",{children:["· ",en(D.duration)]})]})})]}),e.jsx("div",{className:`flex-1 bg-[var(--bg-surface)] border border-[var(--border-default)] rounded-xl overflow-hidden flex flex-col min-h-0 ${p?"":"hidden lg:flex"}`,children:p?e.jsx(Vc,{filePath:p,content:g,loading:h,meta:D,onBack:E}):e.jsx(Yc,{meta:D,onSelectFile:k,isGenerating:s.task.status==="running",progress:s.task.progress,message:s.task.message})})]})]})]})},Zc={guard:"bg-red-100 text-red-700 dark:bg-red-900/30 dark:text-red-300",search:"bg-blue-100 text-blue-700 dark:bg-blue-900/30 dark:text-blue-300",forge:"bg-purple-100 text-purple-700 dark:bg-purple-900/30 dark:text-purple-300",usage:"bg-green-100 text-green-700 dark:bg-green-900/30 dark:text-green-300",lifecycle:"bg-cyan-100 text-cyan-700 dark:bg-cyan-900/30 dark:text-cyan-300",quality:"bg-amber-100 text-amber-700 dark:bg-amber-900/30 dark:text-amber-300",decay:"bg-orange-100 text-orange-700 dark:bg-orange-900/30 dark:text-orange-300",context:"bg-indigo-100 text-indigo-700 dark:bg-indigo-900/30 dark:text-indigo-300",anomaly:"bg-rose-100 text-rose-700 dark:bg-rose-900/30 dark:text-rose-300",intent:"bg-violet-100 text-violet-700 dark:bg-violet-900/30 dark:text-violet-300",exploration:"bg-teal-100 text-teal-700 dark:bg-teal-900/30 dark:text-teal-300",panorama:"bg-sky-100 text-sky-700 dark:bg-sky-900/30 dark:text-sky-300"},Xc={governance:"bg-emerald-100 text-emerald-700 dark:bg-emerald-900/30 dark:text-emerald-300",compliance:"bg-red-100 text-red-700 dark:bg-red-900/30 dark:text-red-300",metrics:"bg-blue-100 text-blue-700 dark:bg-blue-900/30 dark:text-blue-300",analysis:"bg-amber-100 text-amber-700 dark:bg-amber-900/30 dark:text-amber-300"},ed=["time1h","time6h","time24h","time7d","timeAll"],td=[36e5,216e5,864e5,6048e5,0];function tn(t){const s=new Date(t),a=r=>String(r).padStart(2,"0");return`${a(s.getMonth()+1)}-${a(s.getDate())} ${a(s.getHours())}:${a(s.getMinutes())}:${a(s.getSeconds())}`}function sn(t,s){return s[t]??"bg-gray-100 text-gray-600 dark:bg-gray-800 dark:text-gray-300"}function sd({signal:t}){const[s,a]=n.useState(!1);return e.jsxs("div",{className:"border border-[var(--border-default)] rounded-lg p-3 hover:bg-[var(--bg-muted)]/40 transition-colors cursor-pointer",onClick:()=>{a(!s)},children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[e.jsx("span",{className:`px-1.5 py-0.5 rounded text-xs font-medium ${sn(t.type,Zc)}`,children:t.type}),e.jsx("span",{className:"text-[var(--fg-default)] font-medium truncate",children:t.source}),t.target&&e.jsxs("span",{className:"text-[var(--fg-subtle)] truncate",children:["→ ",t.target]}),e.jsxs("span",{className:"ml-auto shrink-0 tabular-nums text-xs text-[var(--fg-subtle)]",children:[(t.value*100).toFixed(0),"%"]}),e.jsx("span",{className:"shrink-0 text-xs text-[var(--fg-subtle)] tabular-nums",children:tn(t.timestamp)})]}),s&&t.metadata&&(typeof t.metadata=="object"&&!Array.isArray(t.metadata)?e.jsx("div",{className:"mt-2 grid grid-cols-[auto_1fr] gap-x-3 gap-y-1 text-xs bg-[var(--bg-muted)] rounded p-2.5",children:Object.entries(t.metadata).map(([r,o])=>e.jsxs(it.Fragment,{children:[e.jsx("span",{className:"text-[var(--fg-secondary)] font-medium",children:r}),e.jsx("span",{className:"text-[var(--fg-default)] tabular-nums",children:typeof o=="object"?JSON.stringify(o):String(o)})]},r))}):e.jsx("pre",{className:"mt-2 text-xs text-[var(--fg-secondary)] bg-[var(--bg-muted)] rounded p-2.5 overflow-x-auto whitespace-pre-wrap",children:JSON.stringify(t.metadata,null,2)}))]})}function ad({report:t}){const[s,a]=n.useState(!1);return e.jsxs("div",{className:"border border-[var(--border-default)] rounded-lg p-3 hover:bg-[var(--bg-muted)]/40 transition-colors cursor-pointer",onClick:()=>{a(!s)},children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[e.jsx("span",{className:`px-1.5 py-0.5 rounded text-xs font-medium ${sn(t.category,Xc)}`,children:t.category}),e.jsx("span",{className:"text-[var(--fg-default)] font-medium truncate",children:t.type}),e.jsx("span",{className:"text-[var(--fg-subtle)] text-xs truncate",children:t.producer}),t.duration_ms!=null&&e.jsxs("span",{className:"text-xs text-[var(--fg-subtle)]",children:[t.duration_ms,"ms"]}),e.jsx("span",{className:"ml-auto shrink-0 text-xs text-[var(--fg-subtle)] tabular-nums",children:tn(t.timestamp)})]}),s&&(typeof t.data=="object"&&t.data&&!Array.isArray(t.data)?e.jsx("div",{className:"mt-2 grid grid-cols-[auto_1fr] gap-x-3 gap-y-1 text-xs bg-[var(--bg-muted)] rounded p-2.5",children:Object.entries(t.data).map(([r,o])=>e.jsxs(it.Fragment,{children:[e.jsx("span",{className:"text-[var(--fg-secondary)] font-medium",children:r}),e.jsx("span",{className:"text-[var(--fg-default)] tabular-nums",children:typeof o=="object"?JSON.stringify(o):String(o)})]},r))}):e.jsx("pre",{className:"mt-2 text-xs text-[var(--fg-secondary)] bg-[var(--bg-muted)] rounded p-2.5 overflow-x-auto whitespace-pre-wrap",children:JSON.stringify(t.data,null,2)}))]})}function Ua({label:t,value:s,max:a}){const r=a>0?Math.round(s/a*100):0;return e.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[e.jsx("span",{className:"w-24 truncate text-[var(--fg-subtle)]",children:t}),e.jsx("div",{className:"flex-1 h-2 rounded-full bg-[var(--bg-muted)] overflow-hidden",children:e.jsx("div",{className:"h-full rounded-full bg-[var(--accent)] transition-all duration-300",style:{width:`${r}%`}})}),e.jsx("span",{className:"w-12 text-right text-xs tabular-nums text-[var(--fg-subtle)]",children:s})]})}const rd=()=>{const{t}=Ae(),[s,a]=n.useState("signals"),[r,o]=n.useState(2),[l,i]=n.useState(""),[p,d]=n.useState(!1),[g,x]=n.useState(null),[h,u]=n.useState([]),[m,c]=n.useState(0),[j,A]=n.useState([]),[D,I]=n.useState(0),[P,J]=n.useState(null),w=n.useMemo(()=>{const k=td[r];return k===0?{}:{from:Date.now()-k}},[r]),B=n.useCallback(async()=>{d(!0),x(null);try{if(s==="signals"){const k=l?l.split(",").map(L=>L.trim()).filter(Boolean):void 0,E=await Q.getSignalTrace({...w,type:k,limit:100});u(E.signals),c(E.total)}else if(s==="reports"){const k=await Q.getReports({...w,limit:50});A(k.reports),I(k.total)}else{const k=await Q.getSignalStats(w);J(k)}}catch(k){x(ke(k))}finally{d(!1)}},[s,w,l]);n.useEffect(()=>{B()},[B]);const z=n.useMemo(()=>{if(!P)return 1;const k=Object.values(P.byType);return Math.max(...k,1)},[P]);return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between flex-wrap gap-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Yt,{size:20,className:"text-[var(--accent)]"}),e.jsx("h2",{className:"text-lg font-semibold text-[var(--fg-default)]",children:t("signals.title")})]}),e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[s==="signals"&&e.jsxs("div",{className:"relative",children:[e.jsx(sa,{size:13,className:"absolute left-2 top-1/2 -translate-y-1/2 text-[var(--fg-subtle)]"}),e.jsx("input",{type:"text",placeholder:t("signals.filterPlaceholder"),value:l,onChange:k=>{i(k.target.value)},className:"pl-7 pr-2 py-1.5 text-xs rounded-lg border border-[var(--border-default)] bg-[var(--bg-surface)] text-[var(--fg-default)] w-40"})]}),e.jsx("div",{className:"flex items-center gap-1",children:[["signals",e.jsx(Be,{size:13},"s"),t("signals.tabSignals")],["reports",e.jsx(Qe,{size:13},"r"),t("signals.tabReports")],["stats",e.jsx(Tt,{size:13},"st"),t("signals.tabStats")]].map(([k,E,L])=>e.jsxs("button",{type:"button",onClick:()=>{a(k)},className:`flex items-center gap-1 px-4 py-1.5 rounded-md text-xs font-medium transition-colors ${s===k?"bg-[var(--accent-subtle)] text-[var(--accent)] border border-[var(--accent-emphasis)]":"text-[var(--fg-muted)] hover:bg-[var(--bg-subtle)] border border-transparent"}`,children:[E,L]},k))}),e.jsx("div",{className:"flex items-center gap-1",children:ed.map((k,E)=>e.jsx("button",{type:"button",onClick:()=>{o(E)},className:`px-4 py-1.5 rounded-md text-xs font-medium transition-colors ${r===E?"bg-[var(--accent-subtle)] text-[var(--accent)] border border-[var(--accent-emphasis)]":"text-[var(--fg-muted)] hover:bg-[var(--bg-subtle)] border border-transparent"}`,children:t(`signals.${k}`)},k))}),e.jsxs("button",{type:"button",onClick:B,disabled:p,className:"flex items-center gap-1 px-2.5 py-1.5 text-xs rounded-lg border border-[var(--border-default)] text-[var(--fg-subtle)] hover:bg-[var(--bg-muted)] transition-colors disabled:opacity-50",children:[p?e.jsx(Ne,{size:13,className:"animate-spin"}):e.jsx(at,{size:13}),t("signals.refresh")]})]})]}),g&&e.jsxs("div",{className:"flex items-center gap-2 p-3 text-sm rounded-lg bg-red-50 text-red-700 dark:bg-red-900/20 dark:text-red-300",children:[e.jsx(st,{size:16}),g]}),p&&!h.length&&!j.length&&!P?e.jsxs("div",{className:"flex items-center justify-center py-20 text-[var(--fg-subtle)]",children:[e.jsx(Ne,{size:24,className:"animate-spin mr-2"}),t("signals.loading")]}):s==="signals"?e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{className:"text-xs text-[var(--fg-subtle)]",children:t("signals.showingSignals",{shown:h.length,total:m})}),h.length===0?e.jsxs("div",{className:"text-center py-12 text-[var(--fg-subtle)]",children:[e.jsx(js,{size:32,className:"mx-auto mb-2 opacity-40"}),e.jsx("p",{children:t("signals.noSignals")})]}):e.jsx("div",{className:"space-y-1.5",children:h.map((k,E)=>e.jsx(sd,{signal:k},`${k.timestamp}-${E}`))})]}):s==="reports"?e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{className:"text-xs text-[var(--fg-subtle)]",children:t("signals.showingReports",{shown:j.length,total:D})}),j.length===0?e.jsxs("div",{className:"text-center py-12 text-[var(--fg-subtle)]",children:[e.jsx(Qe,{size:32,className:"mx-auto mb-2 opacity-40"}),e.jsx("p",{children:t("signals.noReports")})]}):e.jsx("div",{className:"space-y-1.5",children:j.map(k=>e.jsx(ad,{report:k},k.id))})]}):e.jsx("div",{className:"space-y-6",children:P?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-3 gap-4",children:[e.jsxs("div",{className:"border border-[var(--border-default)] rounded-lg p-4",children:[e.jsx("div",{className:"text-xs text-[var(--fg-subtle)] mb-1",children:t("signals.totalSignals")}),e.jsx("div",{className:"text-2xl font-bold text-[var(--fg-default)] tabular-nums",children:P.total})]}),e.jsxs("div",{className:"border border-[var(--border-default)] rounded-lg p-4",children:[e.jsx("div",{className:"text-xs text-[var(--fg-subtle)] mb-1",children:t("signals.signalTypes")}),e.jsx("div",{className:"text-2xl font-bold text-[var(--fg-default)] tabular-nums",children:Object.keys(P.byType).length})]}),e.jsxs("div",{className:"border border-[var(--border-default)] rounded-lg p-4",children:[e.jsx("div",{className:"text-xs text-[var(--fg-subtle)] mb-1",children:t("signals.sources")}),e.jsx("div",{className:"text-2xl font-bold text-[var(--fg-default)] tabular-nums",children:Object.keys(P.bySource).length})]})]}),e.jsxs("div",{className:"border border-[var(--border-default)] rounded-lg p-4",children:[e.jsx("h3",{className:"text-sm font-medium text-[var(--fg-default)] mb-3",children:t("signals.byType")}),e.jsx("div",{className:"space-y-2",children:Object.entries(P.byType).sort((k,E)=>E[1]-k[1]).map(([k,E])=>e.jsx(Ua,{label:k,value:E,max:z},k))})]}),e.jsxs("div",{className:"border border-[var(--border-default)] rounded-lg p-4",children:[e.jsx("h3",{className:"text-sm font-medium text-[var(--fg-default)] mb-3",children:t("signals.bySource")}),e.jsx("div",{className:"space-y-2",children:Object.entries(P.bySource).sort((k,E)=>E[1]-k[1]).slice(0,15).map(([k,E])=>e.jsx(Ua,{label:k,value:E,max:z},k))})]})]}):e.jsxs("div",{className:"text-center py-12 text-[var(--fg-subtle)]",children:[e.jsx(Tt,{size:32,className:"mx-auto mb-2 opacity-40"}),e.jsx("p",{children:t("signals.noStats")})]})})]})},nd={authority:0,guardUsageCount:0,humanUsageCount:0,aiUsageCount:0,lastUsedAt:null,authorityScore:0},ld=({editingRecipe:t,setEditingRecipe:s,handleSaveRecipe:a,closeRecipeEdit:r,isSavingRecipe:o=!1})=>{const{t:l}=Ae(),[i,p]=n.useState("preview"),d=n.useRef(!0);n.useEffect(()=>()=>{d.current=!1},[]);const g=(()=>{const u=(t.language||"").toLowerCase();return["objectivec","objc","objective-c","obj-c"].includes(u)?"objectivec":t.language||"text"})(),x=async u=>{try{if(await Q.setRecipeAuthority(t.name,u),d.current){const m=t.stats?{...t.stats,authority:u}:{...nd,authority:u};s({...t,stats:m})}}catch(m){console.warn(l("recipeEditor.authorityFailed"),ke(m))}},h=u=>{if(!u)return"";const m=typeof u=="string"?new Date(u).getTime():u;return isNaN(m)?"":new Date(m).toLocaleString("zh-CN",{year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit"})};return e.jsxs($e,{className:"z-40 flex items-center justify-center p-4",children:[e.jsx($e.Backdrop,{className:"bg-black/20 dark:bg-black/40 backdrop-blur-sm"}),e.jsxs("div",{className:"relative bg-[var(--bg-surface)] w-full max-w-6xl rounded-2xl shadow-2xl flex flex-col h-[85vh]",children:[e.jsxs("div",{className:"p-6 border-b border-[var(--border-default)] 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:l("recipeEditor.title")}),t.kind&&(()=>{const m={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:St},fact:{label:"Fact",color:"text-cyan-700",bg:"bg-cyan-50",border:"border-cyan-200",icon:qe}}[t.kind];if(!m)return null;const c=m.icon;return e.jsxs("span",{className:`text-[10px] font-bold px-2 py-1 rounded uppercase flex items-center gap-1 border ${m.bg} ${m.color} ${m.border}`,children:[e.jsx(c,{size:H.sm}),m.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-[var(--bg-subtle)] text-[var(--fg-muted)] border-[var(--border-default)]":t.status==="archived"?"bg-orange-50 text-orange-600 border-orange-200":"bg-[var(--bg-subtle)] text-[var(--fg-muted)] border-[var(--border-default)]"}`,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-[var(--fg-muted)]",children:l("recipeEditor.authorityScore")}),i==="preview"?e.jsx("span",{className:"text-sm text-[var(--fg-primary)]",children:t.stats?.authority??3}):e.jsx(tt,{value:String(t.stats?.authority??3),onChange:u=>x(parseInt(u)),options:[{value:"1",label:`1 - ${l("recipeEditor.qualityLevels.basic")}`,icon:"⭐"},{value:"2",label:`2 - ${l("recipeEditor.qualityLevels.good")}`,icon:"⭐⭐"},{value:"3",label:`3 - ${l("recipeEditor.qualityLevels.solid")}`,icon:"⭐⭐⭐"},{value:"4",label:`4 - ${l("recipeEditor.qualityLevels.great")}`,icon:"⭐⭐⭐⭐"},{value:"5",label:`5 - ${l("recipeEditor.qualityLevels.excellent")}`,icon:"⭐⭐⭐⭐⭐"}],size:"xs",className:"font-bold text-amber-600 bg-amber-50 border-amber-100"})]}),e.jsxs("div",{className:"flex bg-[var(--bg-subtle)] p-1 rounded-lg mr-4",children:[e.jsxs("button",{onClick:()=>p("preview"),className:`px-4 py-1.5 rounded-md text-xs font-bold transition-all flex items-center gap-2 ${i==="preview"?"bg-[var(--bg-surface)] shadow-sm text-[var(--accent)]":"text-[var(--fg-muted)]"}`,children:[e.jsx(Ut,{size:H.sm})," ",l("recipeEditor.preview")]}),e.jsxs("button",{onClick:()=>p("edit"),className:`px-4 py-1.5 rounded-md text-xs font-bold transition-all flex items-center gap-2 ${i==="edit"?"bg-[var(--bg-surface)] shadow-sm text-[var(--accent)]":"text-[var(--fg-muted)]"}`,children:[e.jsx(It,{size:H.sm})," ",l("recipeEditor.edit")]})]}),e.jsx("button",{onClick:r,className:"p-2 hover:bg-[var(--bg-subtle)] rounded-full",children:e.jsx(ze,{size:H.lg})})]})]}),e.jsx("div",{className:"p-6 space-y-4 flex-1 flex flex-col overflow-hidden",children:e.jsx("div",{className:"flex-1 flex flex-col min-h-0",children:i==="edit"?e.jsxs("div",{className:"flex-1 overflow-y-auto space-y-5 pr-1",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-bold text-[var(--fg-muted)] uppercase mb-1",children:l("recipeEditor.path")}),e.jsx("input",{className:"w-full p-2 bg-[var(--bg-subtle)] border border-[var(--border-default)] rounded-lg text-sm",value:t.name,onChange:u=>s({...t,name:u.target.value})})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-bold text-[var(--fg-muted)] uppercase mb-1",children:l("recipeEditor.description")}),e.jsx("textarea",{className:"w-full px-3 py-2 text-sm border border-[var(--border-default)] rounded-lg focus:outline-none focus:ring-2 focus:ring-[var(--accent-emphasis)] resize-none",rows:2,value:t.description||"",onChange:u=>s({...t,description:u.target.value}),placeholder:l("recipeEditor.descPlaceholder")})]}),e.jsxs("div",{children:[e.jsxs("label",{className:"block text-xs font-bold text-[var(--fg-muted)] uppercase mb-1.5 flex items-center gap-1.5",children:[e.jsx(Qe,{size:11,className:"text-blue-400"})," ",l("recipeEditor.markdown")]}),e.jsx("div",{className:"border border-[var(--border-default)] rounded-lg overflow-hidden",style:{minHeight:180},children:e.jsx(ys,{value:t.content?.markdown||"",onChange:u=>s({...t,content:{...t.content,markdown:u}}),language:"markdown",height:"180px",showLineNumbers:!0})})]}),e.jsxs("div",{children:[e.jsxs("label",{className:"block text-xs font-bold text-[var(--fg-muted)] uppercase mb-1.5 flex items-center gap-1.5",children:[e.jsx(At,{size:11,className:"text-emerald-500"})," ",l("recipeEditor.code")]}),e.jsx("div",{className:"border border-[var(--border-default)] rounded-lg overflow-hidden",style:{minHeight:180},children:e.jsx(ys,{value:t.content?.pattern||"",onChange:u=>s({...t,content:{...t.content,pattern:u}}),language:g,height:"180px",showLineNumbers:!0})})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-bold text-[var(--fg-muted)] uppercase mb-1",children:l("recipeEditor.rationale")}),e.jsx("textarea",{className:"w-full px-3 py-2 text-sm border border-[var(--border-default)] rounded-lg focus:outline-none focus:ring-2 focus:ring-[var(--accent-emphasis)] resize-y",rows:3,value:t.content?.rationale||"",onChange:u=>s({...t,content:{...t.content,rationale:u.target.value}}),placeholder:l("recipeEditor.rationalePlaceholder")})]})]}):e.jsxs("div",{className:"flex-1 overflow-y-auto space-y-6 scrollbar-light",children:[(()=>{const u=[["trigger",t.trigger],["language",t.language],["category",t.category],["kind",t.kind],["knowledgeType",t.knowledgeType],["status",t.status],["complexity",t.complexity],["scope",t.scope],["source",t.source],["updatedAt",t.updatedAt?h(t.updatedAt):void 0]].filter(([,m])=>!!m);return u.length===0?null:e.jsxs("div",{className:"bg-[var(--bg-subtle)] border border-[var(--border-default)] rounded-2xl p-6",children:[e.jsx("h3",{className:"text-[10px] font-bold text-[var(--fg-muted)] uppercase tracking-widest mb-4",children:"Recipe Metadata"}),e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-y-4 gap-x-8",children:u.map(([m,c])=>e.jsxs("div",{className:"flex flex-col",children:[e.jsx("span",{className:"text-[10px] text-[var(--fg-muted)] font-bold uppercase mb-1",children:m}),e.jsx("span",{className:"text-sm text-[var(--fg-primary)] break-all font-medium",children:c})]},m))})]})})(),t.description&&e.jsxs("div",{className:"bg-[var(--bg-surface)] rounded-2xl border border-[var(--border-default)] p-6",children:[e.jsx("label",{className:"text-[10px] font-bold text-[var(--fg-muted)] uppercase mb-2 block",children:l("recipeEditor.description")}),e.jsx("p",{className:"text-sm text-[var(--fg-secondary)] leading-relaxed",children:t.description})]}),t.content?.markdown&&e.jsxs("div",{className:"bg-[var(--bg-surface)] rounded-2xl border border-blue-100 p-6",children:[e.jsxs("label",{className:"text-[10px] font-bold text-[var(--fg-muted)] uppercase mb-3 block flex items-center gap-1.5",children:[e.jsx(Qe,{size:11,className:"text-blue-400"})," ",l("recipeEditor.markdown")]}),e.jsx("div",{className:"bg-blue-50/30 border border-blue-100 rounded-xl p-4",children:e.jsx("div",{className:"markdown-body text-sm text-[var(--fg-primary)] leading-relaxed",children:e.jsx(Qt,{content:t.content.markdown})})})]}),t.content?.pattern&&e.jsxs("div",{className:"bg-[var(--bg-surface)] rounded-2xl border border-emerald-100 p-6",children:[e.jsxs("label",{className:"text-[10px] font-bold text-[var(--fg-muted)] uppercase mb-3 block flex items-center gap-1.5",children:[e.jsx(At,{size:11,className:"text-emerald-500"})," ",l("recipeEditor.code")]}),e.jsx(ft,{code:t.content.pattern,language:g,showLineNumbers:!0})]}),t.content?.rationale&&e.jsxs("div",{className:"bg-[var(--bg-surface)] rounded-2xl border border-[var(--border-default)] p-6",children:[e.jsx("label",{className:"text-[10px] font-bold text-[var(--fg-muted)] uppercase mb-2 block",children:l("recipeEditor.rationale")}),e.jsx("div",{className:"bg-[var(--bg-subtle)] border border-[var(--border-default)] rounded-xl p-4",children:e.jsx("p",{className:"text-sm text-[var(--fg-secondary)] leading-relaxed",children:t.content.rationale})})]}),t.content?.steps&&t.content.steps.length>0&&e.jsxs("div",{className:"bg-[var(--bg-surface)] rounded-2xl border border-[var(--border-default)] p-6",children:[e.jsx("label",{className:"text-[10px] font-bold text-[var(--fg-muted)] uppercase mb-2 block",children:l("recipeEditor.steps")}),e.jsx("div",{className:"space-y-2",children:t.content.steps.map((u,m)=>typeof u=="string"?e.jsxs("div",{className:"bg-[var(--bg-subtle)] rounded-lg p-3 border border-[var(--border-default)] flex items-start gap-2.5",children:[e.jsx("span",{className:"text-[10px] font-bold text-blue-600 bg-blue-50 rounded-full w-5 h-5 flex items-center justify-center shrink-0 mt-0.5",children:m+1}),e.jsx("p",{className:"text-xs text-[var(--fg-primary)] leading-relaxed",children:u})]},m):e.jsxs("div",{className:"bg-[var(--bg-subtle)] rounded-lg p-3 border border-[var(--border-default)]",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[e.jsx("span",{className:"text-[10px] font-bold text-blue-600 bg-blue-50 rounded-full w-5 h-5 flex items-center justify-center shrink-0",children:m+1}),u.title&&e.jsx("span",{className:"text-xs font-bold text-[var(--fg-primary)]",children:u.title})]}),u.description&&e.jsx("p",{className:"text-xs text-[var(--fg-secondary)] ml-7 leading-relaxed",children:u.description}),u.code&&e.jsx("pre",{className:"text-[11px] font-mono bg-slate-800 text-green-300 p-2.5 rounded-md mt-1.5 ml-7 overflow-x-auto whitespace-pre-wrap",children:u.code})]},m))})]}),t.content?.codeChanges&&t.content.codeChanges.length>0&&e.jsxs("div",{className:"bg-[var(--bg-surface)] rounded-2xl border border-[var(--border-default)] p-6",children:[e.jsx("label",{className:"text-[10px] font-bold text-[var(--fg-muted)] uppercase mb-2 block",children:l("recipeEditor.codeChanges")}),e.jsx("div",{className:"space-y-2",children:t.content.codeChanges.map((u,m)=>e.jsxs("div",{className:"border border-[var(--border-default)] rounded-lg overflow-hidden",children:[e.jsxs("div",{className:"px-3 py-1.5 bg-[var(--bg-subtle)] border-b border-[var(--border-default)] flex items-center gap-2",children:[e.jsx(pt,{size:11,className:"text-blue-400"}),e.jsx("code",{className:"text-[10px] font-mono text-[var(--fg-secondary)]",children:u.file})]}),u.explanation&&e.jsx("p",{className:"text-[11px] text-[var(--fg-muted)] px-3 py-1.5 border-b border-[var(--border-default)] bg-yellow-50/30",children:u.explanation}),e.jsxs("div",{className:"p-2 bg-red-50/20 border-b border-[var(--border-default)]",children:[e.jsx("div",{className:"text-[9px] font-bold text-red-400 mb-0.5 uppercase",children:"Before"}),e.jsx("pre",{className:"text-[11px] text-[var(--fg-secondary)] whitespace-pre-wrap break-words font-mono",children:u.before||l("recipes.emptyValue")})]}),e.jsxs("div",{className:"p-2 bg-emerald-50/20",children:[e.jsx("div",{className:"text-[9px] font-bold text-emerald-500 mb-0.5 uppercase",children:"After"}),e.jsx("pre",{className:"text-[11px] text-[var(--fg-primary)] whitespace-pre-wrap break-words font-mono",children:u.after})]})]},m))})]}),t.content?.verification&&e.jsxs("div",{className:"bg-[var(--bg-surface)] rounded-2xl border border-teal-100 p-6",children:[e.jsx("label",{className:"text-[10px] font-bold text-[var(--fg-muted)] uppercase mb-2 block",children:l("recipeEditor.validation")}),e.jsxs("div",{className:"bg-teal-50/50 border border-teal-100 rounded-xl p-4 space-y-1.5",children:[t.content.verification.method&&e.jsxs("p",{className:"text-xs text-[var(--fg-secondary)]",children:[e.jsx("span",{className:"font-bold text-teal-600",children:l("recipeEditor.validationMethod")})," ",t.content.verification.method]}),t.content.verification.expectedResult&&e.jsxs("p",{className:"text-xs text-[var(--fg-secondary)]",children:[e.jsx("span",{className:"font-bold text-teal-600",children:l("recipeEditor.validationExpected")})," ",t.content.verification.expectedResult]}),t.content.verification.testCode&&e.jsx("pre",{className:"text-[11px] font-mono bg-slate-800 text-green-300 p-2.5 rounded-md overflow-x-auto whitespace-pre-wrap mt-1",children:t.content.verification.testCode})]})]}),t.tags&&t.tags.length>0&&e.jsxs("div",{className:"bg-[var(--bg-subtle)] border border-[var(--border-default)] rounded-2xl p-6",children:[e.jsxs("h3",{className:"text-[10px] font-bold text-[var(--fg-muted)] uppercase tracking-widest mb-3 flex items-center gap-1.5",children:[e.jsx(jr,{size:11,className:"text-blue-400"})," ",l("recipeEditor.tags")]}),e.jsx("div",{className:"flex flex-wrap gap-1.5",children:t.tags.map((u,m)=>e.jsx("span",{className:"px-2.5 py-1 bg-blue-50 text-blue-700 border border-blue-100 rounded-full text-xs font-medium",children:u},m))})]}),!!(t.constraints&&(t.constraints.guards?.length||t.constraints.boundaries?.length||t.constraints.preconditions?.length||t.constraints.sideEffects?.length))&&e.jsxs("div",{className:"bg-[var(--bg-subtle)] border border-[var(--border-default)] rounded-2xl p-6 space-y-4",children:[e.jsxs("h3",{className:"text-[10px] font-bold text-[var(--fg-muted)] uppercase tracking-widest flex items-center gap-1.5",children:[e.jsx(Ve,{size:11,className:"text-amber-500"})," ",l("recipeEditor.constraints")]}),t.constraints.guards&&t.constraints.guards.length>0&&e.jsxs("div",{children:[e.jsx("span",{className:"text-xs font-semibold text-[var(--fg-muted)] block mb-1.5",children:l("recipeEditor.guardRules")}),e.jsx("ul",{className:"text-sm text-[var(--fg-secondary)] space-y-1",children:t.constraints.guards.map((u,m)=>e.jsxs("li",{className:"flex gap-2 items-start",children:[e.jsx("span",{className:`text-xs mt-0.5 ${u.severity==="error"?"text-red-500":"text-yellow-500"}`,children:"●"}),e.jsx("code",{className:"font-mono text-xs bg-[var(--bg-subtle)] px-1.5 py-0.5 rounded",children:u.pattern}),u.message&&e.jsxs("span",{className:"text-xs text-[var(--fg-muted)]",children:["— ",u.message]})]},m))})]}),t.constraints.boundaries&&t.constraints.boundaries.length>0&&e.jsxs("div",{children:[e.jsx("span",{className:"text-xs font-semibold text-[var(--fg-muted)] block mb-1.5",children:l("recipeEditor.boundaryConstraints")}),e.jsx("ul",{className:"text-sm text-[var(--fg-secondary)] space-y-1",children:t.constraints.boundaries.map((u,m)=>e.jsxs("li",{className:"flex gap-2",children:[e.jsx("span",{className:"text-orange-400",children:"●"}),u]},m))})]}),t.constraints.preconditions&&t.constraints.preconditions.length>0&&e.jsxs("div",{children:[e.jsx("span",{className:"text-xs font-semibold text-[var(--fg-muted)] block mb-1.5",children:l("recipeEditor.preconditions")}),e.jsx("ul",{className:"text-sm text-[var(--fg-secondary)] space-y-1",children:t.constraints.preconditions.map((u,m)=>e.jsxs("li",{className:"flex gap-2",children:[e.jsx("span",{className:"text-blue-400",children:"◆"}),u]},m))})]}),t.constraints.sideEffects&&t.constraints.sideEffects.length>0&&e.jsxs("div",{children:[e.jsx("span",{className:"text-xs font-semibold text-[var(--fg-muted)] block mb-1.5",children:l("recipeEditor.sideEffects")}),e.jsx("ul",{className:"text-sm text-[var(--fg-secondary)] space-y-1",children:t.constraints.sideEffects.map((u,m)=>e.jsxs("li",{className:"flex gap-2",children:[e.jsx("span",{className:"text-pink-400",children:"⚡"}),u]},m))})]})]}),t.relations&&Object.entries(t.relations).some(([,u])=>Array.isArray(u)&&u.length>0)&&e.jsxs("div",{className:"bg-[var(--bg-subtle)] border border-[var(--border-default)] rounded-2xl p-6",children:[e.jsx("h3",{className:"text-[10px] font-bold text-[var(--fg-muted)] uppercase tracking-widest mb-4",children:l("recipeEditor.relations")}),e.jsx("div",{className:"space-y-2",children:[{key:"inherits",label:l("recipeEditor.relationTypes.inherits"),color:"text-green-600",icon:"↑"},{key:"implements",label:l("recipeEditor.relationTypes.implements"),color:"text-blue-600",icon:"◇"},{key:"calls",label:l("recipeEditor.relationTypes.calls"),color:"text-cyan-600",icon:"→"},{key:"dependsOn",label:l("recipeEditor.relationTypes.dependsOn"),color:"text-yellow-600",icon:"⊕"},{key:"dataFlow",label:l("recipeEditor.relationTypes.dataFlow"),color:"text-purple-600",icon:"⇢"},{key:"conflicts",label:l("recipeEditor.relationTypes.conflicts"),color:"text-red-600",icon:"✕"},{key:"extends",label:l("recipeEditor.relationTypes.extends"),color:"text-teal-600",icon:"⊃"},{key:"related",label:l("recipeEditor.relationTypes.associates"),color:"text-[var(--fg-muted)]",icon:"∼"}].map(({key:u,label:m,color:c,icon:j})=>{const A=t.relations?.[u];return!A||!Array.isArray(A)||A.length===0?null:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsxs("span",{className:`text-xs font-mono ${c} shrink-0 whitespace-nowrap pt-0.5`,children:[j," ",m]}),e.jsx("div",{className:"flex flex-wrap gap-1.5",children:A.map((D,I)=>e.jsx("span",{className:"px-2 py-0.5 bg-[var(--bg-surface)] border border-[var(--border-default)] text-[var(--fg-secondary)] rounded-lg text-xs font-mono",children:typeof D=="string"?D:D.id||D.title||JSON.stringify(D)},I))})]},u)})})]}),!t.content?.markdown&&!t.content?.pattern&&!t.description&&e.jsx("div",{className:"bg-[var(--bg-surface)] p-8 rounded-2xl border border-[var(--border-default)] shadow-sm min-h-[200px] flex items-center justify-center",children:e.jsx("div",{className:"text-[var(--fg-muted)] italic",children:l("recipeEditor.noContent")})})]})})}),e.jsxs("div",{className:"p-6 border-t border-[var(--border-default)] flex justify-end gap-3",children:[e.jsx("button",{onClick:r,disabled:o,className:"px-4 py-2 text-[var(--fg-secondary)] font-medium disabled:opacity-50",children:l("recipeEditor.cancel")}),e.jsxs("button",{onClick:a,disabled:o,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:[o?e.jsx(Ne,{size:H.lg,className:"animate-spin"}):e.jsx(ws,{size:H.lg}),l(o?"recipeEditor.saving":"recipeEditor.saveChanges")]})]})]})]})},od=({setShowCreateModal:t,createPath:s,setCreatePath:a,handleCreateFromPath:r,handleCreateFromClipboard:o,isExtracting:l})=>{const{t:i}=Ae();return e.jsxs($e,{className:"z-40 flex items-center justify-center p-4",children:[e.jsx($e.Backdrop,{className:"bg-black/20 dark:bg-black/40 backdrop-blur-sm"}),e.jsxs("div",{className:"relative w-full max-w-lg rounded-2xl shadow-2xl overflow-hidden bg-[var(--bg-surface)]",children:[e.jsxs("div",{className:"p-6 border-b flex justify-between items-center bg-[var(--bg-subtle)] border-[var(--border-default)]",children:[e.jsxs("h2",{className:"text-xl font-bold flex items-center gap-2 text-[var(--fg-primary)]",children:[e.jsx(mt,{size:H.xl,className:"text-blue-600"})," ",i("createModal.title")]}),e.jsx("button",{onClick:()=>t(!1),className:"p-2 rounded-full transition-all duration-150 text-[var(--fg-muted)] hover:bg-[var(--bg-subtle)] hover:text-[var(--fg-primary)]",children:e.jsx(ze,{size:H.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 uppercase tracking-widest text-[var(--fg-muted)]",children:[e.jsx(va,{size:H.sm})," ",i("createModal.importFromPath")]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("input",{className:"flex-1 p-3 rounded-xl text-sm outline-none focus:ring-2 focus:ring-[var(--accent-emphasis)] border bg-[var(--bg-subtle)] border-[var(--border-default)] text-[var(--fg-primary)]",placeholder:i("createModal.pathPlaceholder"),value:s,onChange:p=>a(p.target.value)}),e.jsxs("button",{onClick:r,disabled:!s||l,className:"px-5 py-2 rounded-xl text-sm font-bold whitespace-nowrap disabled:opacity-40 transition-all duration-150 bg-[var(--accent)] text-white hover:opacity-90 shadow-sm",children:[e.jsx(va,{size:14,className:"inline -mt-0.5 mr-1"}),i("createModal.scanFile")]})]})]}),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-[var(--border-default)]"})}),e.jsx("div",{className:"relative flex justify-center text-xs uppercase",children:e.jsx("span",{className:"px-2 font-bold bg-[var(--bg-surface)] text-[var(--fg-muted)]",children:i("createModal.or")})})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("label",{className:"flex items-center gap-2 text-xs font-bold uppercase tracking-widest text-[var(--fg-muted)]",children:[e.jsx(jl,{size:H.sm})," ",i("createModal.importFromClipboard")]}),e.jsxs("button",{onClick:()=>o(),disabled:l,className:"w-full flex items-center justify-center gap-3 p-4 rounded-xl font-bold transition-all duration-150 border bg-[var(--accent-subtle)] text-[var(--accent)] border-[var(--accent-emphasis)]/20 hover:bg-[var(--accent-emphasis)]/10",children:[e.jsx(Be,{size:H.lg})," ",i("createModal.useClipboard")]})]})]}),l&&e.jsxs("div",{className:"bg-blue-600 text-white p-4 flex items-center justify-center gap-3 animate-pulse",children:[e.jsx(Jt,{size:H.lg,className:"animate-spin"}),e.jsx("span",{className:"font-bold text-sm",children:i("createModal.aiThinking")})]})]})]})};function id(t){if(!t)return"";if(typeof t=="object"){const o=t.code||t.pattern||t.markdown||t.snippet||t.body||"";if(o)return o}const a=(typeof t=="string"?t:JSON.stringify(t)).replace(/^---[\s\S]*?---\s*\n?/,"").trim(),r=a.match(/```[\w]*\n([\s\S]*?)```/);return r&&r[1]?r[1].trim():a.slice(0,8e3)}const cd=({searchQ:t,insertPath:s,onClose:a})=>{const{t:r}=Ae(),[o,l]=n.useState([]),[i,p]=n.useState(!0),[d,g]=n.useState(null),x=n.useRef(!0),h=n.useRef(null);n.useEffect(()=>(x.current=!0,h.current=new AbortController,Q.search(t||"",{mode:"auto",type:"recipe",signal:h.current.signal}).then(m=>{x.current&&l((m.items||[]).map(c=>({name:(c.title||c.name||"")+".md",path:"",content:c.content,qualityScore:(c.quality||{}).overall||c.qualityScore||0,recommendReason:""})))}).catch(m=>{m.name!=="AbortError"&&x.current&&l([])}).finally(()=>{x.current&&p(!1)}),()=>{x.current=!1,h.current&&h.current.abort()}),[t]);const u=async m=>{g(m.name);try{const c=id(m.content);await Q.insertAtSearchMark({path:s,content:c}),x.current&&(alert(r("searchModal.insertSuccess")+" "+s),a())}catch{x.current&&alert(r("searchModal.insertFailed"))}finally{x.current&&g(null)}};return e.jsxs($e,{className:"z-40 flex items-center justify-center p-4",children:[e.jsx($e.Backdrop,{className:"bg-black/20 dark:bg-black/40 backdrop-blur-sm"}),e.jsxs("div",{className:"relative bg-[var(--bg-surface)] 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-[var(--border-default)] flex justify-between items-center bg-[var(--bg-subtle)]",children:[e.jsxs("h2",{className:"text-xl font-bold flex items-center gap-2 text-[var(--fg-primary)]",children:[e.jsx(xt,{size:H.xl,className:"text-blue-600"})," ",r("searchModal.title")]}),e.jsx("button",{onClick:a,className:"p-2 hover:bg-[var(--bg-surface)] rounded-full transition-colors",children:e.jsx(ze,{size:H.lg})})]}),e.jsxs("div",{className:"p-4 text-sm text-[var(--fg-muted)] border-b border-[var(--border-default)]",children:[r("searchModal.keyword")," ",t||r("searchModal.keywordAll")," · ",r("searchModal.insertTo")," ",s]}),e.jsx("div",{className:"flex-1 overflow-y-auto p-4",children:i?e.jsx("div",{className:"flex items-center justify-center py-12",children:e.jsx("div",{className:"animate-spin rounded-full h-8 w-8 border-b-2 border-blue-600"})}):o.length===0?e.jsx("div",{className:"text-[var(--fg-muted)] text-center py-8",children:r("searchModal.noResults")}):e.jsx("ul",{className:"space-y-2",children:o.map(m=>e.jsx("li",{children:e.jsxs("button",{type:"button",onClick:()=>u(m),disabled:d!==null,className:"w-full flex items-center justify-between gap-3 p-4 rounded-xl border border-[var(--border-default)] hover:border-[var(--accent-emphasis)] hover:bg-[var(--accent-subtle)]/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-[var(--fg-primary)] truncate",children:m.name}),(m.qualityScore!==void 0||m.recommendReason)&&e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[m.qualityScore!==void 0&&e.jsxs("span",{className:"inline-flex items-center gap-1 px-2 py-0.5 bg-blue-100 rounded text-xs text-blue-700 font-medium",children:["🤖 ",r("searchModal.quality")," ",(m.qualityScore*100).toFixed(0),"%"]}),m.recommendReason&&e.jsx("span",{className:"text-xs text-[var(--fg-secondary)] italic truncate max-w-xs",children:m.recommendReason})]})]}),d===m.name?e.jsxs("span",{className:"text-blue-600 text-sm flex items-center gap-1",children:[e.jsx("span",{className:"animate-spin",children:"⏳"})," ",r("searchModal.inserting")]}):e.jsxs("span",{className:"text-blue-600 text-sm flex items-center gap-1",children:[e.jsx(kr,{size:H.md})," ",r("searchModal.insertBtn")]})]})},m.name))})})]})]})},Bs=[{id:"google",labelKey:"llmConfig.providers.gemini",defaultModel:"gemini-2.0-flash",keyEnv:"ASD_GOOGLE_API_KEY"},{id:"openai",labelKey:"llmConfig.providers.openai",defaultModel:"gpt-4o",keyEnv:"ASD_OPENAI_API_KEY"},{id:"deepseek",labelKey:"llmConfig.providers.deepseek",defaultModel:"deepseek-chat",keyEnv:"ASD_DEEPSEEK_API_KEY"},{id:"claude",labelKey:"llmConfig.providers.claude",defaultModel:"claude-3-5-sonnet-20240620",keyEnv:"ASD_CLAUDE_API_KEY"},{id:"ollama",labelKey:"llmConfig.providers.ollama",defaultModel:"llama3",keyEnv:""}],dd=({onClose:t,onSaved:s})=>{const{t:a}=Ae(),[r,o]=n.useState(!0),[l,i]=n.useState(!1),[p,d]=n.useState(!1),[g,x]=n.useState("google"),[h,u]=n.useState("gemini-2.0-flash"),[m,c]=n.useState(""),[j,A]=n.useState(""),[D,I]=n.useState(!1),[P,J]=n.useState({}),[w,B]=n.useState(!1);n.useEffect(()=>{z()},[]);const z=async()=>{o(!0);try{const N=await Q.getLlmEnvConfig();d(N.hasEnvFile);const v=N.vars||{};v.ASD_AI_PROVIDER&&x(v.ASD_AI_PROVIDER),v.ASD_AI_MODEL&&u(v.ASD_AI_MODEL),v.ASD_AI_PROXY&&A(v.ASD_AI_PROXY),J(v)}catch{}finally{o(!1)}},k=Bs.find(N=>N.id===g),E=k?.keyEnv||"",L=E?!!P[E]:!0,O=N=>{x(N);const v=Bs.find(U=>U.id===N);v&&u(v.defaultModel),c("")},W=async()=>{if(g){if(E&&!L&&!m.trim()){alert(a("llmConfig.apiKeyRequired"));return}i(!0),B(!1);try{await Q.saveLlmEnvConfig({provider:g,model:h||void 0,apiKey:m.trim()||void 0,proxy:j.trim()||void 0}),B(!0),setTimeout(()=>{s(),t()},800)}catch(N){alert(ke(N,a("llmConfig.saveFailed")))}finally{i(!1)}}},q=N=>!N||N.length<10?N?"••••••":"":`${N.slice(0,6)}••••${N.slice(-4)}`;return e.jsx("div",{className:"fixed inset-0 bg-black/40 flex items-center justify-center z-50",onClick:t,children:e.jsxs("div",{className:"rounded-2xl shadow-2xl w-full max-w-lg mx-4 overflow-hidden bg-[var(--bg-surface)]",onClick:N=>N.stopPropagation(),children:[e.jsxs("div",{className:"flex items-center justify-between px-6 py-4 border-b border-[var(--border-default)]",children:[e.jsx("h2",{className:"text-lg font-semibold text-[var(--fg-primary)]",children:a("llmConfig.title")}),e.jsx("button",{onClick:t,className:"p-1 rounded-lg transition-all duration-150 hover:bg-[var(--bg-subtle)] text-[var(--fg-muted)] hover:text-[var(--fg-primary)]",children:e.jsx(ze,{size:H.md})})]}),e.jsx("div",{className:"px-6 py-5 space-y-5",children:r?e.jsx("div",{className:"flex items-center justify-center py-12",children:e.jsx(Ne,{size:24,className:"animate-spin text-blue-500"})}):e.jsxs(e.Fragment,{children:[!p&&e.jsxs("div",{className:"flex items-start gap-2 p-3 bg-amber-50 border border-amber-200 rounded-lg text-sm text-amber-700",children:[e.jsx(st,{size:16,className:"mt-0.5 shrink-0"}),e.jsx("span",{children:a("llmConfig.envWarning")})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium mb-2 text-[var(--fg-primary)]",children:a("llmConfig.provider")}),e.jsx("div",{className:"grid grid-cols-2 sm:grid-cols-3 gap-2",children:Bs.map(N=>e.jsx("button",{type:"button",onClick:()=>O(N.id),className:`px-3 py-2 rounded-lg text-sm font-medium border transition-all ${g===N.id?"bg-[var(--accent-subtle)] border-[var(--accent-emphasis)] text-[var(--accent)] ring-1 ring-[var(--accent-emphasis)]/30":"bg-[var(--bg-surface)] border-[var(--border-default)] text-[var(--fg-secondary)] hover:border-[var(--border-emphasis)] hover:bg-[var(--bg-subtle)]"}`,children:a(N.labelKey)},N.id))})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium mb-1.5 text-[var(--fg-primary)]",children:a("llmConfig.model")}),e.jsx("input",{type:"text",value:h,onChange:N=>u(N.target.value),placeholder:k?.defaultModel||"",className:"w-full px-3 py-2 border rounded-lg text-sm focus:outline-none focus:ring-2 focus:ring-[var(--accent-emphasis)]/20 focus:border-[var(--accent-emphasis)] border-[var(--border-default)] bg-[var(--bg-subtle)] text-[var(--fg-primary)]"})]}),E&&e.jsxs("div",{children:[e.jsxs("label",{className:"block text-sm font-medium mb-1.5 text-[var(--fg-primary)]",children:[a("llmConfig.apiKey"),L&&e.jsxs("span",{className:"ml-2 text-xs text-green-600 font-normal",children:["(",a("llmConfig.configured")," ",q(P[E]),")"]})]}),e.jsxs("div",{className:"relative",children:[e.jsx("input",{type:D?"text":"password",value:m,onChange:N=>c(N.target.value),placeholder:a(L?"llmConfig.apiKeyPlaceholderSet":"llmConfig.apiKeyPlaceholderEmpty"),className:"w-full px-3 py-2 pr-10 border rounded-lg text-sm focus:outline-none focus:ring-2 focus:ring-[var(--accent-emphasis)]/20 focus:border-[var(--accent-emphasis)] border-[var(--border-default)] bg-[var(--bg-subtle)] text-[var(--fg-primary)]"}),e.jsx("button",{type:"button",onClick:()=>I(N=>!N),className:"absolute right-2 top-1/2 -translate-y-1/2 p-1 text-[var(--fg-muted)] hover:text-[var(--fg-secondary)]",children:D?e.jsx(wl,{size:16}):e.jsx(Ut,{size:16})})]})]}),e.jsxs("div",{children:[e.jsxs("label",{className:"block text-sm font-medium mb-1.5 text-[var(--fg-primary)]",children:[a("llmConfig.proxy")," ",e.jsx("span",{className:"text-xs font-normal text-[var(--fg-muted)]",children:a("llmConfig.optional")})]}),e.jsx("input",{type:"text",value:j,onChange:N=>A(N.target.value),placeholder:"http://127.0.0.1:7890",className:"w-full px-3 py-2 border rounded-lg text-sm focus:outline-none focus:ring-2 focus:ring-[var(--accent-emphasis)]/20 focus:border-[var(--accent-emphasis)] border-[var(--border-default)] bg-[var(--bg-subtle)] text-[var(--fg-primary)]"})]})]})}),e.jsxs("div",{className:"flex items-center justify-end gap-3 px-6 py-4 border-t border-[var(--border-default)] bg-[var(--bg-subtle)]",children:[e.jsx("button",{onClick:t,className:"px-4 py-2 text-sm font-medium transition-colors text-[var(--fg-secondary)] hover:text-[var(--fg-primary)]",children:a("llmConfig.cancel")}),e.jsxs("button",{onClick:W,disabled:l||r||w,className:`flex items-center gap-2 px-5 py-2 rounded-lg text-sm font-medium transition-all ${w?"bg-green-500 text-white":"bg-blue-600 text-white hover:bg-blue-700 shadow-sm"} disabled:opacity-60`,children:[l?e.jsx(Ne,{size:16,className:"animate-spin"}):w?e.jsx(ht,{size:16}):e.jsx(ws,{size:16}),a(w?"llmConfig.saved":"llmConfig.saveToEnv")]})]})]})})},Wa=200,ud=({open:t,onClose:s})=>{const{t:a}=Ae(),[r,o]=n.useState([]),[l,i]=n.useState(!1),[p,d]=n.useState(""),g=n.useRef(null);n.useEffect(()=>{if(!t)return;let D=!1;Q.getSignalTrace({limit:100}).then(J=>{if(D)return;const w=J.signals.map(B=>({type:B.type,source:B.source,target:B.target,value:B.value,metadata:B.metadata,timestamp:B.timestamp}));o(w)}).catch(()=>{});const I=Cs(),P=J=>{l||o(w=>{const B=[J,...w];return B.length>Wa?B.slice(0,Wa):B})};return I.on("signal:event",P),()=>{D=!0,I.off("signal:event",P)}},[t,l]);const x=p?r.filter(D=>D.type.toLowerCase().includes(p.toLowerCase())||D.source.toLowerCase().includes(p.toLowerCase())):r,h={guard:"text-red-500",search:"text-blue-500",usage:"text-green-500",lifecycle:"text-purple-500",exploration:"text-cyan-500",quality:"text-yellow-500",panorama:"text-indigo-500",decay:"text-orange-500",forge:"text-pink-500"},u={guard:"#ef4444",search:"#3b82f6",usage:"#22c55e",lifecycle:"#a855f7",decay:"#f97316"},m=["guard","search","usage","lifecycle","decay"],c=50,j=n.useMemo(()=>{const D={};for(const P of m)D[P]=0;for(const P of r)P.type in D&&D[P.type]++;const I=Math.max(1,...Object.values(D));return{counts:D,max:I}},[r]),A=n.useMemo(()=>{const D=[];for(const I of m)j.counts[I]>c&&D.push(`${I} 信号量过高 (${j.counts[I]})`);if(r.length>0){const I=r[0].timestamp;Date.now()-I>300*1e3&&D.push("超过 5 分钟未收到新信号")}else t&&D.push("尚未收到任何信号");return D},[r,j,t]);return t?e.jsxs("div",{className:"fixed right-0 top-0 h-full w-80 glass-surface border-l border-[var(--border-muted)] shadow-xl z-50 flex flex-col",children:[e.jsxs("div",{className:"flex items-center justify-between p-3 border-b border-[var(--border-muted)]",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Yt,{className:"w-4 h-4 text-[var(--accent)]"}),e.jsx("span",{className:"text-sm font-semibold text-[var(--text-primary)]",children:"Signal Monitor"}),e.jsx("span",{className:"text-xs px-1.5 py-0.5 rounded-full bg-[var(--accent)]/10 text-[var(--accent)]",children:r.length})]}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("button",{onClick:()=>i(!l),className:`p-1 rounded text-xs ${l?"text-red-500":"text-green-500"} hover:bg-[var(--bg-elevated)]`,children:l?"▶":"⏸"}),e.jsx("button",{onClick:()=>o([]),className:"p-1 rounded text-xs text-[var(--text-tertiary)] hover:bg-[var(--bg-elevated)]",children:"Clear"}),e.jsx("button",{onClick:s,className:"p-1 rounded text-[var(--text-tertiary)] hover:bg-[var(--bg-elevated)]",children:e.jsx(ze,{className:"w-4 h-4"})})]})]}),e.jsx("div",{className:"p-2 border-b border-[var(--border-muted)]",children:e.jsx("input",{type:"text",value:p,onChange:D=>d(D.target.value),placeholder:"Filter by type or source...",className:"w-full px-2 py-1 text-xs rounded bg-[var(--bg-elevated)] text-[var(--text-primary)] border border-[var(--border-muted)] focus:outline-none focus:border-[var(--accent)]"})}),e.jsx("div",{ref:g,className:"flex-1 overflow-y-auto min-h-0",children:x.length===0?e.jsxs("div",{className:"flex flex-col items-center justify-center h-32 text-[var(--text-tertiary)]",children:[e.jsx(js,{className:"w-5 h-5 mb-2 opacity-50"}),e.jsx("span",{className:"text-xs",children:"Waiting for signals..."})]}):e.jsx("div",{className:"divide-y divide-[var(--border-muted)]",children:x.map((D,I)=>e.jsxs("div",{className:"p-2 hover:bg-[var(--bg-elevated)] transition-colors",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:`text-xs font-mono font-semibold ${h[D.type]??"text-[var(--text-secondary)]"}`,children:D.type}),e.jsx("span",{className:"text-[10px] text-[var(--text-tertiary)]",children:new Date(D.timestamp).toLocaleTimeString()})]}),e.jsx("div",{className:"text-[11px] text-[var(--text-tertiary)] mt-0.5 truncate",children:D.source})]},`${D.type}-${D.timestamp}-${I}`))})}),e.jsxs("div",{className:"border-t border-[var(--border-muted)] p-3 shrink-0",children:[e.jsx("h3",{className:"text-xs font-medium text-[var(--fg-muted)] uppercase tracking-wider mb-2",children:"Signal Statistics"}),e.jsx("div",{className:"space-y-1.5",children:m.map(D=>e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-[10px] font-mono w-14 text-[var(--text-tertiary)] text-right",children:D}),e.jsx("div",{className:"flex-1 h-3 rounded-sm bg-[var(--bg-elevated)] overflow-hidden",children:e.jsx("div",{className:"h-full rounded-sm transition-all duration-300",style:{width:`${j.counts[D]/j.max*100}%`,backgroundColor:u[D]}})}),e.jsx("span",{className:"text-[10px] font-mono w-6 text-[var(--text-tertiary)] text-right",children:j.counts[D]})]},D))})]}),A.length>0&&e.jsxs("div",{className:"border-t border-[var(--border-muted)] p-3 shrink-0",children:[e.jsx("h3",{className:"text-xs font-medium text-[var(--fg-muted)] uppercase tracking-wider mb-2",children:"Anomaly Alerts"}),e.jsx("div",{className:"space-y-1",children:A.map((D,I)=>e.jsxs("div",{className:"text-[11px] text-yellow-500 bg-yellow-500/10 rounded px-2 py-1",children:["⚠️ ",D]},I))})]})]}):null};class md extends it.Component{constructor(s){super(s),this.state={hasError:!1,error:null}}static getDerivedStateFromError(s){return{hasError:!0,error:s}}render(){return this.state.hasError?e.jsxs("div",{style:{padding:40,textAlign:"center"},children:[e.jsx("h2",{style:{color:"#ef4444",marginBottom:12},children:Us.app.errorBoundary.title}),e.jsx("pre",{style:{fontSize:12,color:"#64748b",whiteSpace:"pre-wrap",maxWidth:600,margin:"0 auto"},children:this.state.error?.message}),e.jsx("button",{onClick:()=>{this.setState({hasError:!1,error:null}),window.location.reload()},style:{marginTop:16,padding:"8px 20px",background:"#3b82f6",color:"#fff",border:"none",borderRadius:8,cursor:"pointer"},children:Us.app.errorBoundary.refreshBtn})]}):this.props.children}}function Ht(t,s="ai-scan"){return{title:t.title||"",description:t.description||"",trigger:t.trigger||"",language:t.language||"",category:t.category||"",tags:t.tags||[],kind:t.kind||"",knowledgeType:t.knowledgeType||"",scope:t.scope||"",complexity:t.complexity||"",difficulty:t.difficulty||"",authority:t.authority,lifecycle:t.lifecycle||"pending",source:t.source||s,doClause:t.doClause||"",dontClause:t.dontClause||"",whenClause:t.whenClause||"",topicHint:t.topicHint||"",coreCode:t.coreCode||"",content:t.content||{},constraints:t.constraints||{},reasoning:t.reasoning||{},quality:t.quality||{},stats:t.stats||{},relations:t.relations||{},headers:t.headers||[],headerPaths:t.headerPaths,moduleName:t.moduleName,includeHeaders:t.includeHeaders,createdAt:t.createdAt,updatedAt:t.updatedAt}}const pd=()=>{const t=eo(),s=so(t.user?.role),a=ao(),{t:r}=Ae(),o=()=>{const S=window.location.pathname.replace(/^\//,"").split("/")[0]||"";return $l.includes(S)?S:"help"},[l,i]=n.useState(null),[p,d]=n.useState(o()),[g,x]=n.useState(""),[h,u]=n.useState(!1),[m,c]=n.useState(!0),[j,A]=n.useState(null),[D,I]=n.useState([]),[P,J]=n.useState([]),[w,B]=n.useState(null),[z,k]=n.useState(!1),[E,L]=n.useState({current:0,total:0,status:""}),[O,W]=n.useState([]),[q,N]=n.useState([]),[v,U]=n.useState(null),ae=n.useRef(null),be=S=>{const K=ae.current;return K?`asd:spm:${S}:${K}`:null},me=n.useCallback(S=>{N(K=>{const Y=typeof S=="function"?S(K):S;try{const ie=be("scan-results");ie&&sessionStorage.setItem(ie,JSON.stringify(Y))}catch{}return Y})},[]);n.useEffect(()=>{try{const S=be("selected-target");if(!S)return;w?sessionStorage.setItem(S,w):sessionStorage.removeItem(S)}catch{}},[w]),n.useEffect(()=>{try{const S=be("guard-audit");if(!S)return;v?sessionStorage.setItem(S,JSON.stringify(v)):sessionStorage.removeItem(S)}catch{}},[v]);const[je,G]=n.useState(1),[le,de]=n.useState(12),[R,T]=n.useState(!1),[X,oe]=n.useState(""),[pe,ue]=n.useState(!1),[M,Ce]=n.useState(null),[F,Se]=n.useState(null),[Te,Fe]=n.useState(!1),[Me,ee]=n.useState(!0),[ce,f]=n.useState(!1),[V,xe]=n.useState(0),[fe,C]=n.useState(!1),b=n.useRef(null),_=n.useRef(null);n.useEffect(()=>{G(1)},[g]),n.useEffect(()=>{if(l?.projectRoot)try{const S=`asd:custom-folder-targets:${l.projectRoot}`,K=localStorage.getItem(S);J(K?JSON.parse(K):[])}catch{J([])}},[l?.projectRoot]),n.useEffect(()=>{if(!l?.projectRoot)return;ae.current=l.projectRoot;const S=l.projectRoot;try{B(sessionStorage.getItem(`asd:spm:selected-target:${S}`)||null)}catch{B(null)}try{const K=sessionStorage.getItem(`asd:spm:scan-results:${S}`);N(K?JSON.parse(K):[])}catch{N([])}try{const K=sessionStorage.getItem(`asd:spm:guard-audit:${S}`);U(K?JSON.parse(K):null)}catch{U(null)}},[l?.projectRoot]);const ne=()=>{b.current&&b.current.abort()},[$,y]=n.useState(!1),te=async()=>{if(!$){y(!0);try{b.current&&b.current.abort(),await Q.cancelBootstrap("Cancelled by user via Dashboard")}catch{}finally{y(!1)}}};n.useEffect(()=>{let S=!1;const K=async()=>{try{const ie=await Q.getSignalStatus();if(!S){const ve=ie?.suggestions?.length||0,Re=ie?.snapshot?.lastResult?.newSuggestions||0;xe(ve||Re)}}catch{}};K();const Y=setInterval(K,300*1e3);return()=>{S=!0,clearInterval(Y)}},[]);const ge=n.useRef(null);n.useEffect(()=>{if(a.isAllDone&&a.session){if(ge.current!==a.session.id){ge.current=a.session.id;const S=a.session.failed>0?r("bootstrap.notifyPartial",{completed:a.session.completed,total:a.session.total,failed:a.session.failed}):r("bootstrap.notifySuccess",{completed:a.session.completed});re(S,{title:r("bootstrap.coldStartComplete"),type:a.session.failed>0?"error":"success"})}we()}},[a.isAllDone,a.session?.id]),n.useEffect(()=>{if(a.candidateCreatedTick>0){const S=setTimeout(()=>we(),2e3);return()=>clearTimeout(S)}},[a.candidateCreatedTick]);const he=(S,K)=>{d(S);const Y=K?.preserveSearch&&window.location.search?window.location.search:"";window.history.pushState({},document.title,`/${S}${Y}`)},De=S=>{A(S),d("recipes");const K=new URLSearchParams(window.location.search);K.set("edit",encodeURIComponent(S.name)),window.history.pushState({},document.title,`/recipes?${K.toString()}`)},se=()=>{A(null),window.history.replaceState({},document.title,"/recipes")};n.useEffect(()=>{g===""&&Ce(null)},[g]),n.useEffect(()=>{d(o())},[]),n.useEffect(()=>{if(!l)return;const S=window.location.pathname.replace(/^\//,"").split("/")[0],Y=new URLSearchParams(window.location.search).get("edit");if(S==="recipes"&&Y&&l.recipes)try{const ie=decodeURIComponent(Y),ve=l.recipes.find(Re=>Re.name===ie);ve&&!j&&(d("recipes"),De(ve))}catch{}},[l]),n.useEffect(()=>{we(),Oe(),rt();const S=()=>{d(o())};window.addEventListener("popstate",S);const K=new URLSearchParams(window.location.search),Y=K.get("action"),ie=K.get("path"),ve=K.get("q")||"";return Y==="search"&&ie?Se({q:ve,path:ie}):Y==="create"&&ie&&(oe(ie),T(!0),K.get("autoScan")==="1"&&setTimeout(()=>Xt(ie),500)),Y&&window.history.replaceState({},document.title,window.location.pathname),()=>{window.removeEventListener("popstate",S)}},[]);const we=async()=>{c(!0);try{const S=await Q.fetchData();i(S)}catch(S){re(ke(S,r("app.load.failed")),{title:r("app.load.failedTitle"),type:"error"})}finally{c(!1)}},Oe=async()=>{try{const S=await Q.fetchTargets();I(S)}catch(S){console.warn("删除候选残留失败:",ke(S))}},rt=async()=>{try{const S=await Q.getLlmEnvConfig();ee(S.llmReady)}catch{}},ct=async()=>{try{await Q.refreshProject(),Oe(),re(r("app.projectRefresh.success"),{title:r("app.projectRefresh.successTitle")})}catch{re(r("app.load.failedHint"),{title:r("app.projectRefresh.failed"),type:"error"})}},Xt=async S=>{ue(!0);try{const K=await Q.extractFromPath(S);me(K.result.map(Y=>({...Ht(Y,"extract"),mode:"full",lang:"cn"}))),he("spm"),T(!1),we(),K.result?.length>0&&re(r("app.extract.success"),{title:r("app.extract.successTitle")})}catch{re(r("app.extract.failed"),{type:"error"})}finally{ue(!1)}},nt=async()=>{if(X){ue(!0);try{const S=await Q.extractFromPath(X);me(S.result.map(K=>({...Ht(K,"extract"),mode:"full",lang:"cn"}))),he("spm"),T(!1),we(),S.result?.length>0?re(S.isMarked?r("app.extract.markerSuccess"):r("app.extract.normalSuccess"),{title:r("app.extract.successTitle")}):S.isMarked||re(r("app.extract.noMarker"),{title:r("app.extract.extracting"),type:"info"})}catch{re(r("app.extract.failed"),{type:"error"})}finally{ue(!1)}}},Ss=async S=>{try{const K=await navigator.clipboard.readText();if(!K)return re(r("app.clipboard.empty"),{title:r("app.clipboard.emptyTitle"),type:"info"});re(r("app.clipboard.analyzing"),{title:r("app.clipboard.analyzingTitle"),type:"info"}),ue(!0);const Y=S||X;try{const ie=await Q.extractFromText(K,Y||void 0),ve=ie._multipleCount;me([{...Ht(ie,"clipboard"),mode:"full",lang:"cn"}]),he("spm"),T(!1),we(),re(ve?r("app.clipboard.resultMulti",{count:ve}):r("app.extract.normalSuccess"),{title:r("app.clipboard.resultTitle")})}catch(ie){const ve=ke(ie);Vl(ie)?re(ve,{title:r("app.clipboard.aiFailed"),type:"error"}):re(ve,{title:r("common.operationFailed"),type:"error"})}}catch{re(r("app.clipboard.permissionError"),{title:r("app.clipboard.permissionTitle"),type:"error"})}finally{ue(!1)}},an={"scan:started":{percent:5,status:r("app.scan.events.initializing")},"scan:files-loaded":{percent:15,status:S=>r("app.scan.events.filesLoaded",{count:S.count||0})},"scan:reading":{percent:25,status:S=>r("app.scan.events.readingFiles",{count:S.count||0})},"scan:ai-extracting":{percent:40,status:r("app.scan.events.aiAnalyzing")},"scan:enriching":{percent:85,status:S=>r("app.scan.events.enriching",{count:S.recipeCount||0})},"scan:completed":{percent:95,status:r("app.scan.events.completing")}},rn=async S=>{if(z)return;b.current&&b.current.abort(),_.current&&(clearInterval(_.current),_.current=null);const K=new AbortController;b.current=K,B(S.name),k(!0),me([]),U(null),W([]),L({current:0,total:100,status:r("app.scan.streamInit")});try{const Y=await Q.scanTargetStream(S,Re=>{const Pe=an[Re.type];if(Pe){const _e=typeof Pe.status=="function"?Pe.status(Re):Pe.status;L({current:Pe.percent,total:100,status:_e})}Re.type==="scan:files-loaded"&&Re.files&&W(Re.files),Re.type==="scan:ai-extracting"&&(_.current&&clearInterval(_.current),_.current=setInterval(()=>{L(_e=>({..._e,current:Math.min(_e.current+1,80)}))},3e3)),(Re.type==="scan:enriching"||Re.type==="scan:completed")&&_.current&&(clearInterval(_.current),_.current=null)},K.signal);_.current&&(clearInterval(_.current),_.current=null),L({current:100,total:100,status:r("app.scan.completed")});const ie=Y.recipes||[],ve=Y.scannedFiles||[];if(ie.length>0||ve.length>0){const Re=typeof S=="string"?S:S?.name||"unknown",Pe=ie.map(_e=>({...Ht(_e,"ai-scan"),mode:"full",lang:"cn",candidateTargetName:Re,scanMode:"target"}));if(me(Pe),ve.length>0&&W(ve),we(),ie.length>0)re(r("app.scan.targetSuccess",{count:ie.length}),{title:r("app.scan.targetSuccessTitle")});else if(Y.message){const _e=Y.noAi;re(Y.message,{title:r(_e?"app.scan.aiNotConfigured":"app.scan.noResults"),type:_e?"info":"error"})}else re(r("app.scan.noResults"),{title:r("app.scan.scanComplete"),type:"info"})}else re(r("app.scan.scanFailedHint"),{title:r("app.scan.scanFailed"),type:"error"})}catch(Y){if(_.current&&(clearInterval(_.current),_.current=null),fs(Y))return;const ie=ss(Y),ve=ie?r("app.scan.timeout"):ke(Y,r("app.scan.scanError"));re(ve,{title:r(ie?"app.scan.timeoutTitle":"app.scan.scanError"),type:"error"})}finally{b.current===K&&(k(!1),L({current:0,total:0,status:""}),b.current=null)}},nn=async()=>{if(z)return;b.current&&b.current.abort();const S=new AbortController;b.current=S,he("candidates"),k(!0),me([]),U(null),W([]),L({current:0,total:100,status:r("app.coldStart.collecting")}),a.resetSession();try{const K=await Q.bootstrap(S.signal);L({current:100,total:100,status:r("app.coldStart.skeletonCreated")}),K.bootstrapSession&&a.initFromApiResponse(K.bootstrapSession),we();const Y=K.report||{},ie=K.targets?.length||0,ve=Y.totals?.files||0,Re=Y.totals?.graphEdges||0,Pe=K.guardSummary,_e=Pe?`, ${r("app.coldStart.guardSuffix",{count:Pe.totalViolations})}`:"";re(r("app.coldStart.skeletonDetail",{targets:ie,files:ve,deps:Re})+_e)}catch(K){if(Is(K))return;const ie=ss(K)?r("app.coldStart.timeout"):ke(K);re(ie,{type:"error"})}finally{b.current===S&&(k(!1),L({current:0,total:0,status:""}),b.current=null)}},ln=async()=>{if(z)return;b.current&&b.current.abort();const S=new AbortController;b.current=S,he("candidates"),k(!0),L({current:0,total:100,status:r("app.rescan.analyzing")}),a.resetSession();try{const K=await Q.rescan({reason:"dashboard-rescan"},S.signal);L({current:100,total:100,status:r("app.rescan.done")}),K.bootstrapSession&&a.initFromApiResponse(K.bootstrapSession),we();const Y=K.relevanceAudit||{},ie=K.gapAnalysis||{};re(r("app.rescan.success",{preserved:K.rescan?.preservedRecipes||0,healthy:Y.healthy||0,decayed:(Y.decay||0)+(Y.severe||0)+(Y.dead||0)})+(ie.gapDimensions>0?` ${r("app.rescan.filling",{count:ie.gapDimensions})}`:""))}catch(K){if(Is(K))return;const Y=ss(K)?r("app.rescan.timeout"):ke(K);re(Y,{type:"error"})}finally{b.current===S&&(k(!1),L({current:0,total:0,status:""}),b.current=null)}},on=async()=>{if(z)return;b.current&&b.current.abort();const S=new AbortController;b.current=S,he("spm"),B("__project__"),k(!0),me([]),U(null),W([]),L({current:0,total:100,status:r("app.fullScan.collecting")});const K=[{status:r("app.fullScan.phase5"),percent:5},{status:r("app.fullScan.phase15"),percent:15},{status:r("app.fullScan.phase25"),percent:25},{status:r("app.fullScan.phase35"),percent:35},{status:r("app.fullScan.phase45"),percent:45},{status:r("app.fullScan.phase55"),percent:55},{status:r("app.fullScan.phase65"),percent:65},{status:r("app.fullScan.phase75"),percent:75},{status:r("app.fullScan.phase85"),percent:85}];let Y=0;const ie=setInterval(()=>{Y=Math.min(Y+1,K.length);const ve=K[Y-1];ve&&L(Re=>({...Re,current:ve.percent,status:ve.status}))},15e3);try{const ve=await Q.scanProject(S.signal);clearInterval(ie),L({current:100,total:100,status:ve.partial?r("app.fullScan.partialComplete"):r("app.fullScan.completed")});const Re=ve.recipes||[],Pe=ve.scannedFiles||[];if(Re.length>0||Pe.length>0){const _e=Re.map(vn=>({...Ht(vn,"ai-scan"),mode:"full",lang:"cn",candidateTargetName:"__project__",scanMode:"project"}));me(_e),W(Pe),U(ve.guardAudit||null),we();const Ze=ve.guardAudit?.summary,es=Ze?`, ${r("app.fullScan.guardSuffix",{count:Ze.totalViolations})}`:"",Ft=ve.partial?r("app.fullScan.timeoutSuffix"):"";re(r("app.fullScan.resultDetail",{count:Re.length})+es+Ft)}else re(r("app.fullScan.noContent"))}catch(ve){if(clearInterval(ie),Is(ve))return;const Pe=ss(ve)?r("app.fullScan.timeout"):ke(ve);re(Pe,{type:"error"})}finally{b.current===S&&(k(!1),L({current:0,total:0,status:""}),b.current=null)}},cn=(S,K)=>{const Y=[...q],ie={...Y[S],...K};Y[S]=ie,me(Y)},dn=async S=>{if(!Te){Fe(!0);try{const K=(S.content?.pattern||"").trim(),Y=(()=>{if(!K)return!1;const Ze=K.split(`
109
+ ${t("wiki.loadFailedDesc")}`)}finally{u(!1)}}},E=()=>{d(null),x("")},L=n.useMemo(()=>r.filter(q=>q.path!=="meta.json"),[r]),O=n.useMemo(()=>Uc(L,D?.files),[L,D]);if(m)return e.jsx("div",{className:"flex items-center justify-center h-64",children:e.jsx(Ne,{size:H.xl,className:"text-blue-500 animate-spin"})});const W=!l&&L.length===0&&s.task.status!=="running";return e.jsxs("div",{className:"h-full flex flex-col overflow-hidden p-6 pt-4",children:[e.jsx(qc,{task:s.task,wiki:s.wiki}),W?e.jsx(Jc,{}):e.jsxs(e.Fragment,{children:[s.task.status==="running"&&e.jsxs("div",{className:"mb-3 flex items-center gap-3 px-4 py-2.5 bg-gradient-to-r from-blue-50 to-indigo-50 border border-blue-200/70 rounded-xl shrink-0",children:[e.jsxs("div",{className:"relative flex items-center justify-center w-6 h-6",children:[e.jsx("span",{className:"absolute inline-flex h-full w-full rounded-full bg-blue-400 opacity-30 animate-ping"}),e.jsx(Ne,{size:16,className:"text-blue-600 animate-spin relative"})]}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("span",{className:"text-sm font-medium text-blue-800",children:t("wiki.wikiGenerating")}),s.task.message&&e.jsx("span",{className:"text-xs text-blue-500 ml-2 truncate",children:s.task.message})]}),e.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0",children:[e.jsx("div",{className:"w-24 bg-blue-100 rounded-full h-1.5",children:e.jsx("div",{className:"bg-blue-500 h-1.5 rounded-full transition-all duration-700 ease-out",style:{width:`${Math.max(s.task.progress||0,3)}%`}})}),e.jsxs("span",{className:"text-xs font-mono text-blue-600 w-8 text-right",children:[s.task.progress||0,"%"]})]})]}),e.jsxs("div",{className:"flex gap-4 flex-1 min-h-0 overflow-hidden",children:[e.jsxs("div",{className:`w-64 flex-shrink-0 bg-[var(--bg-surface)] border border-[var(--border-default)] rounded-xl flex flex-col overflow-hidden ${p?"hidden lg:flex":""}`,children:[e.jsxs("div",{className:"px-3 pt-3 pb-2 border-b border-[var(--border-default)] shrink-0",children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(qe,{size:16,className:"text-blue-500"}),e.jsx("span",{className:"text-sm font-semibold text-[var(--fg-primary)]",children:"Wiki"}),D?.version&&e.jsxs("span",{className:"text-[10px] text-[var(--fg-muted)]",children:["v",D.version]})]}),e.jsxs("div",{className:"flex items-center gap-1",children:[l&&e.jsx("span",{className:"text-[10px] text-[var(--fg-muted)]",children:t("wiki.fileCount",{count:L.length})}),s.task.status!=="running"&&l&&e.jsx("button",{onClick:z,title:t("wiki.incrementalUpdate"),className:"p-1 rounded-md text-blue-500 hover:bg-blue-50 transition-colors",children:e.jsx(at,{size:13})})]})]}),e.jsxs("div",{className:"relative",children:[e.jsx(xt,{size:14,className:"absolute left-3 top-1/2 -translate-y-1/2 text-[var(--fg-muted)]"}),e.jsx("input",{type:"text",placeholder:t("wiki.searchPlaceholder"),value:j,onChange:q=>A(q.target.value),className:"w-full pl-8 pr-3 py-2 text-sm bg-[var(--bg-subtle)] border border-[var(--border-default)] rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-200 focus:border-blue-300 transition-all"})]})]}),e.jsxs("div",{className:"p-2 overflow-y-auto flex-1 min-h-0 scrollbar-light",children:[e.jsx(Wc,{tree:O,selectedFile:p,onSelect:k,searchQuery:j}),s.task.status==="running"&&e.jsxs("div",{className:"mx-2 mt-3 mb-1 flex items-center gap-2 px-3 py-2 bg-blue-50 border border-blue-100 rounded-lg",children:[e.jsx(Ne,{size:12,className:"text-blue-500 animate-spin flex-shrink-0"}),e.jsx("span",{className:"text-[11px] text-blue-600 leading-tight",children:t("wiki.generating")})]})]}),D?.generatedAt&&e.jsx("div",{className:"px-3 py-2 border-t border-[var(--border-default)] shrink-0",children:e.jsxs("div",{className:"flex items-center gap-1.5 text-[10px] text-[var(--fg-muted)]",children:[e.jsx(Ye,{size:10}),e.jsx("span",{children:Kc(D.generatedAt)}),D.duration!=null&&e.jsxs("span",{children:["· ",en(D.duration)]})]})})]}),e.jsx("div",{className:`flex-1 bg-[var(--bg-surface)] border border-[var(--border-default)] rounded-xl overflow-hidden flex flex-col min-h-0 ${p?"":"hidden lg:flex"}`,children:p?e.jsx(Vc,{filePath:p,content:g,loading:h,meta:D,onBack:E}):e.jsx(Yc,{meta:D,onSelectFile:k,isGenerating:s.task.status==="running",progress:s.task.progress,message:s.task.message})})]})]})]})},Zc={guard:"bg-red-100 text-red-700 dark:bg-red-900/30 dark:text-red-300",search:"bg-blue-100 text-blue-700 dark:bg-blue-900/30 dark:text-blue-300",forge:"bg-purple-100 text-purple-700 dark:bg-purple-900/30 dark:text-purple-300",usage:"bg-green-100 text-green-700 dark:bg-green-900/30 dark:text-green-300",lifecycle:"bg-cyan-100 text-cyan-700 dark:bg-cyan-900/30 dark:text-cyan-300",quality:"bg-amber-100 text-amber-700 dark:bg-amber-900/30 dark:text-amber-300",decay:"bg-orange-100 text-orange-700 dark:bg-orange-900/30 dark:text-orange-300",context:"bg-indigo-100 text-indigo-700 dark:bg-indigo-900/30 dark:text-indigo-300",anomaly:"bg-rose-100 text-rose-700 dark:bg-rose-900/30 dark:text-rose-300",intent:"bg-violet-100 text-violet-700 dark:bg-violet-900/30 dark:text-violet-300",exploration:"bg-teal-100 text-teal-700 dark:bg-teal-900/30 dark:text-teal-300",panorama:"bg-sky-100 text-sky-700 dark:bg-sky-900/30 dark:text-sky-300"},Xc={governance:"bg-emerald-100 text-emerald-700 dark:bg-emerald-900/30 dark:text-emerald-300",compliance:"bg-red-100 text-red-700 dark:bg-red-900/30 dark:text-red-300",metrics:"bg-blue-100 text-blue-700 dark:bg-blue-900/30 dark:text-blue-300",analysis:"bg-amber-100 text-amber-700 dark:bg-amber-900/30 dark:text-amber-300"},ed=["time1h","time6h","time24h","time7d","timeAll"],td=[36e5,216e5,864e5,6048e5,0];function tn(t){const s=new Date(t),a=r=>String(r).padStart(2,"0");return`${a(s.getMonth()+1)}-${a(s.getDate())} ${a(s.getHours())}:${a(s.getMinutes())}:${a(s.getSeconds())}`}function sn(t,s){return s[t]??"bg-gray-100 text-gray-600 dark:bg-gray-800 dark:text-gray-300"}function sd({signal:t}){const[s,a]=n.useState(!1);return e.jsxs("div",{className:"border border-[var(--border-default)] rounded-lg p-3 hover:bg-[var(--bg-muted)]/40 transition-colors cursor-pointer",onClick:()=>{a(!s)},children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[e.jsx("span",{className:`px-1.5 py-0.5 rounded text-xs font-medium ${sn(t.type,Zc)}`,children:t.type}),e.jsx("span",{className:"text-[var(--fg-default)] font-medium truncate",children:t.source}),t.target&&e.jsxs("span",{className:"text-[var(--fg-subtle)] truncate",children:["→ ",t.target]}),e.jsxs("span",{className:"ml-auto shrink-0 tabular-nums text-xs text-[var(--fg-subtle)]",children:[(t.value*100).toFixed(0),"%"]}),e.jsx("span",{className:"shrink-0 text-xs text-[var(--fg-subtle)] tabular-nums",children:tn(t.timestamp)})]}),s&&t.metadata&&(typeof t.metadata=="object"&&!Array.isArray(t.metadata)?e.jsx("div",{className:"mt-2 grid grid-cols-[auto_1fr] gap-x-3 gap-y-1 text-xs bg-[var(--bg-muted)] rounded p-2.5",children:Object.entries(t.metadata).map(([r,o])=>e.jsxs(it.Fragment,{children:[e.jsx("span",{className:"text-[var(--fg-secondary)] font-medium",children:r}),e.jsx("span",{className:"text-[var(--fg-default)] tabular-nums",children:typeof o=="object"?JSON.stringify(o):String(o)})]},r))}):e.jsx("pre",{className:"mt-2 text-xs text-[var(--fg-secondary)] bg-[var(--bg-muted)] rounded p-2.5 overflow-x-auto whitespace-pre-wrap",children:JSON.stringify(t.metadata,null,2)}))]})}function ad({report:t}){const[s,a]=n.useState(!1);return e.jsxs("div",{className:"border border-[var(--border-default)] rounded-lg p-3 hover:bg-[var(--bg-muted)]/40 transition-colors cursor-pointer",onClick:()=>{a(!s)},children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[e.jsx("span",{className:`px-1.5 py-0.5 rounded text-xs font-medium ${sn(t.category,Xc)}`,children:t.category}),e.jsx("span",{className:"text-[var(--fg-default)] font-medium truncate",children:t.type}),e.jsx("span",{className:"text-[var(--fg-subtle)] text-xs truncate",children:t.producer}),t.duration_ms!=null&&e.jsxs("span",{className:"text-xs text-[var(--fg-subtle)]",children:[t.duration_ms,"ms"]}),e.jsx("span",{className:"ml-auto shrink-0 text-xs text-[var(--fg-subtle)] tabular-nums",children:tn(t.timestamp)})]}),s&&(typeof t.data=="object"&&t.data&&!Array.isArray(t.data)?e.jsx("div",{className:"mt-2 grid grid-cols-[auto_1fr] gap-x-3 gap-y-1 text-xs bg-[var(--bg-muted)] rounded p-2.5",children:Object.entries(t.data).map(([r,o])=>e.jsxs(it.Fragment,{children:[e.jsx("span",{className:"text-[var(--fg-secondary)] font-medium",children:r}),e.jsx("span",{className:"text-[var(--fg-default)] tabular-nums",children:typeof o=="object"?JSON.stringify(o):String(o)})]},r))}):e.jsx("pre",{className:"mt-2 text-xs text-[var(--fg-secondary)] bg-[var(--bg-muted)] rounded p-2.5 overflow-x-auto whitespace-pre-wrap",children:JSON.stringify(t.data,null,2)}))]})}function Ua({label:t,value:s,max:a}){const r=a>0?Math.round(s/a*100):0;return e.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[e.jsx("span",{className:"w-24 truncate text-[var(--fg-subtle)]",children:t}),e.jsx("div",{className:"flex-1 h-2 rounded-full bg-[var(--bg-muted)] overflow-hidden",children:e.jsx("div",{className:"h-full rounded-full bg-[var(--accent)] transition-all duration-300",style:{width:`${r}%`}})}),e.jsx("span",{className:"w-12 text-right text-xs tabular-nums text-[var(--fg-subtle)]",children:s})]})}const rd=()=>{const{t}=Ae(),[s,a]=n.useState("signals"),[r,o]=n.useState(2),[l,i]=n.useState(""),[p,d]=n.useState(!1),[g,x]=n.useState(null),[h,u]=n.useState([]),[m,c]=n.useState(0),[j,A]=n.useState([]),[D,I]=n.useState(0),[P,J]=n.useState(null),w=n.useMemo(()=>{const k=td[r];return k===0?{}:{from:Date.now()-k}},[r]),B=n.useCallback(async()=>{d(!0),x(null);try{if(s==="signals"){const k=l?l.split(",").map(L=>L.trim()).filter(Boolean):void 0,E=await Q.getSignalTrace({...w,type:k,limit:100});u(E.signals),c(E.total)}else if(s==="reports"){const k=await Q.getReports({...w,limit:50});A(k.reports),I(k.total)}else{const k=await Q.getSignalStats(w);J(k)}}catch(k){x(ke(k))}finally{d(!1)}},[s,w,l]);n.useEffect(()=>{B()},[B]);const z=n.useMemo(()=>{if(!P)return 1;const k=Object.values(P.byType);return Math.max(...k,1)},[P]);return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between flex-wrap gap-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Yt,{size:20,className:"text-[var(--accent)]"}),e.jsx("h2",{className:"text-lg font-semibold text-[var(--fg-default)]",children:t("signals.title")})]}),e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[s==="signals"&&e.jsxs("div",{className:"relative",children:[e.jsx(sa,{size:13,className:"absolute left-2 top-1/2 -translate-y-1/2 text-[var(--fg-subtle)]"}),e.jsx("input",{type:"text",placeholder:t("signals.filterPlaceholder"),value:l,onChange:k=>{i(k.target.value)},className:"pl-7 pr-2 py-1.5 text-xs rounded-lg border border-[var(--border-default)] bg-[var(--bg-surface)] text-[var(--fg-default)] w-40"})]}),e.jsx("div",{className:"flex items-center gap-1",children:[["signals",e.jsx(Be,{size:13},"s"),t("signals.tabSignals")],["reports",e.jsx(Qe,{size:13},"r"),t("signals.tabReports")],["stats",e.jsx(Tt,{size:13},"st"),t("signals.tabStats")]].map(([k,E,L])=>e.jsxs("button",{type:"button",onClick:()=>{a(k)},className:`flex items-center gap-1 px-4 py-1.5 rounded-md text-xs font-medium transition-colors ${s===k?"bg-[var(--accent-subtle)] text-[var(--accent)] border border-[var(--accent-emphasis)]":"text-[var(--fg-muted)] hover:bg-[var(--bg-subtle)] border border-transparent"}`,children:[E,L]},k))}),e.jsx("div",{className:"flex items-center gap-1",children:ed.map((k,E)=>e.jsx("button",{type:"button",onClick:()=>{o(E)},className:`px-4 py-1.5 rounded-md text-xs font-medium transition-colors ${r===E?"bg-[var(--accent-subtle)] text-[var(--accent)] border border-[var(--accent-emphasis)]":"text-[var(--fg-muted)] hover:bg-[var(--bg-subtle)] border border-transparent"}`,children:t(`signals.${k}`)},k))}),e.jsxs("button",{type:"button",onClick:B,disabled:p,className:"flex items-center gap-1 px-2.5 py-1.5 text-xs rounded-lg border border-[var(--border-default)] text-[var(--fg-subtle)] hover:bg-[var(--bg-muted)] transition-colors disabled:opacity-50",children:[p?e.jsx(Ne,{size:13,className:"animate-spin"}):e.jsx(at,{size:13}),t("signals.refresh")]})]})]}),g&&e.jsxs("div",{className:"flex items-center gap-2 p-3 text-sm rounded-lg bg-red-50 text-red-700 dark:bg-red-900/20 dark:text-red-300",children:[e.jsx(st,{size:16}),g]}),p&&!h.length&&!j.length&&!P?e.jsxs("div",{className:"flex items-center justify-center py-20 text-[var(--fg-subtle)]",children:[e.jsx(Ne,{size:24,className:"animate-spin mr-2"}),t("signals.loading")]}):s==="signals"?e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{className:"text-xs text-[var(--fg-subtle)]",children:t("signals.showingSignals",{shown:h.length,total:m})}),h.length===0?e.jsxs("div",{className:"text-center py-12 text-[var(--fg-subtle)]",children:[e.jsx(js,{size:32,className:"mx-auto mb-2 opacity-40"}),e.jsx("p",{children:t("signals.noSignals")})]}):e.jsx("div",{className:"space-y-1.5",children:h.map((k,E)=>e.jsx(sd,{signal:k},`${k.timestamp}-${E}`))})]}):s==="reports"?e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{className:"text-xs text-[var(--fg-subtle)]",children:t("signals.showingReports",{shown:j.length,total:D})}),j.length===0?e.jsxs("div",{className:"text-center py-12 text-[var(--fg-subtle)]",children:[e.jsx(Qe,{size:32,className:"mx-auto mb-2 opacity-40"}),e.jsx("p",{children:t("signals.noReports")})]}):e.jsx("div",{className:"space-y-1.5",children:j.map(k=>e.jsx(ad,{report:k},k.id))})]}):e.jsx("div",{className:"space-y-6",children:P?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-3 gap-4",children:[e.jsxs("div",{className:"border border-[var(--border-default)] rounded-lg p-4",children:[e.jsx("div",{className:"text-xs text-[var(--fg-subtle)] mb-1",children:t("signals.totalSignals")}),e.jsx("div",{className:"text-2xl font-bold text-[var(--fg-default)] tabular-nums",children:P.total})]}),e.jsxs("div",{className:"border border-[var(--border-default)] rounded-lg p-4",children:[e.jsx("div",{className:"text-xs text-[var(--fg-subtle)] mb-1",children:t("signals.signalTypes")}),e.jsx("div",{className:"text-2xl font-bold text-[var(--fg-default)] tabular-nums",children:Object.keys(P.byType).length})]}),e.jsxs("div",{className:"border border-[var(--border-default)] rounded-lg p-4",children:[e.jsx("div",{className:"text-xs text-[var(--fg-subtle)] mb-1",children:t("signals.sources")}),e.jsx("div",{className:"text-2xl font-bold text-[var(--fg-default)] tabular-nums",children:Object.keys(P.bySource).length})]})]}),e.jsxs("div",{className:"border border-[var(--border-default)] rounded-lg p-4",children:[e.jsx("h3",{className:"text-sm font-medium text-[var(--fg-default)] mb-3",children:t("signals.byType")}),e.jsx("div",{className:"space-y-2",children:Object.entries(P.byType).sort((k,E)=>E[1]-k[1]).map(([k,E])=>e.jsx(Ua,{label:k,value:E,max:z},k))})]}),e.jsxs("div",{className:"border border-[var(--border-default)] rounded-lg p-4",children:[e.jsx("h3",{className:"text-sm font-medium text-[var(--fg-default)] mb-3",children:t("signals.bySource")}),e.jsx("div",{className:"space-y-2",children:Object.entries(P.bySource).sort((k,E)=>E[1]-k[1]).slice(0,15).map(([k,E])=>e.jsx(Ua,{label:k,value:E,max:z},k))})]})]}):e.jsxs("div",{className:"text-center py-12 text-[var(--fg-subtle)]",children:[e.jsx(Tt,{size:32,className:"mx-auto mb-2 opacity-40"}),e.jsx("p",{children:t("signals.noStats")})]})})]})},nd={authority:0,guardUsageCount:0,humanUsageCount:0,aiUsageCount:0,lastUsedAt:null,authorityScore:0},ld=({editingRecipe:t,setEditingRecipe:s,handleSaveRecipe:a,closeRecipeEdit:r,isSavingRecipe:o=!1})=>{const{t:l}=Ae(),[i,p]=n.useState("preview"),d=n.useRef(!0);n.useEffect(()=>()=>{d.current=!1},[]);const g=(()=>{const u=(t.language||"").toLowerCase();return["objectivec","objc","objective-c","obj-c"].includes(u)?"objectivec":t.language||"text"})(),x=async u=>{try{if(await Q.setRecipeAuthority(t.name,u),d.current){const m=t.stats?{...t.stats,authority:u}:{...nd,authority:u};s({...t,stats:m})}}catch(m){console.warn(l("recipeEditor.authorityFailed"),ke(m))}},h=u=>{if(!u)return"";const m=typeof u=="string"?new Date(u).getTime():u;return isNaN(m)?"":new Date(m).toLocaleString("zh-CN",{year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit"})};return e.jsxs($e,{className:"z-40 flex items-center justify-center p-4",children:[e.jsx($e.Backdrop,{className:"bg-black/20 dark:bg-black/40 backdrop-blur-sm"}),e.jsxs("div",{className:"relative bg-[var(--bg-surface)] w-full max-w-6xl rounded-2xl shadow-2xl flex flex-col h-[85vh]",children:[e.jsxs("div",{className:"p-6 border-b border-[var(--border-default)] 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:l("recipeEditor.title")}),t.kind&&(()=>{const m={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:St},fact:{label:"Fact",color:"text-cyan-700",bg:"bg-cyan-50",border:"border-cyan-200",icon:qe}}[t.kind];if(!m)return null;const c=m.icon;return e.jsxs("span",{className:`text-[10px] font-bold px-2 py-1 rounded uppercase flex items-center gap-1 border ${m.bg} ${m.color} ${m.border}`,children:[e.jsx(c,{size:H.sm}),m.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-[var(--bg-subtle)] text-[var(--fg-muted)] border-[var(--border-default)]":t.status==="archived"?"bg-orange-50 text-orange-600 border-orange-200":"bg-[var(--bg-subtle)] text-[var(--fg-muted)] border-[var(--border-default)]"}`,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-[var(--fg-muted)]",children:l("recipeEditor.authorityScore")}),i==="preview"?e.jsx("span",{className:"text-sm text-[var(--fg-primary)]",children:t.stats?.authority??3}):e.jsx(tt,{value:String(t.stats?.authority??3),onChange:u=>x(parseInt(u)),options:[{value:"1",label:`1 - ${l("recipeEditor.qualityLevels.basic")}`,icon:"⭐"},{value:"2",label:`2 - ${l("recipeEditor.qualityLevels.good")}`,icon:"⭐⭐"},{value:"3",label:`3 - ${l("recipeEditor.qualityLevels.solid")}`,icon:"⭐⭐⭐"},{value:"4",label:`4 - ${l("recipeEditor.qualityLevels.great")}`,icon:"⭐⭐⭐⭐"},{value:"5",label:`5 - ${l("recipeEditor.qualityLevels.excellent")}`,icon:"⭐⭐⭐⭐⭐"}],size:"xs",className:"font-bold text-amber-600 bg-amber-50 border-amber-100"})]}),e.jsxs("div",{className:"flex bg-[var(--bg-subtle)] p-1 rounded-lg mr-4",children:[e.jsxs("button",{onClick:()=>p("preview"),className:`px-4 py-1.5 rounded-md text-xs font-bold transition-all flex items-center gap-2 ${i==="preview"?"bg-[var(--bg-surface)] shadow-sm text-[var(--accent)]":"text-[var(--fg-muted)]"}`,children:[e.jsx(Ut,{size:H.sm})," ",l("recipeEditor.preview")]}),e.jsxs("button",{onClick:()=>p("edit"),className:`px-4 py-1.5 rounded-md text-xs font-bold transition-all flex items-center gap-2 ${i==="edit"?"bg-[var(--bg-surface)] shadow-sm text-[var(--accent)]":"text-[var(--fg-muted)]"}`,children:[e.jsx(It,{size:H.sm})," ",l("recipeEditor.edit")]})]}),e.jsx("button",{onClick:r,className:"p-2 hover:bg-[var(--bg-subtle)] rounded-full",children:e.jsx(ze,{size:H.lg})})]})]}),e.jsx("div",{className:"p-6 space-y-4 flex-1 flex flex-col overflow-hidden",children:e.jsx("div",{className:"flex-1 flex flex-col min-h-0",children:i==="edit"?e.jsxs("div",{className:"flex-1 overflow-y-auto space-y-5 pr-1",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-bold text-[var(--fg-muted)] uppercase mb-1",children:l("recipeEditor.path")}),e.jsx("input",{className:"w-full p-2 bg-[var(--bg-subtle)] border border-[var(--border-default)] rounded-lg text-sm",value:t.name,onChange:u=>s({...t,name:u.target.value})})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-bold text-[var(--fg-muted)] uppercase mb-1",children:l("recipeEditor.description")}),e.jsx("textarea",{className:"w-full px-3 py-2 text-sm border border-[var(--border-default)] rounded-lg focus:outline-none focus:ring-2 focus:ring-[var(--accent-emphasis)] resize-none",rows:2,value:t.description||"",onChange:u=>s({...t,description:u.target.value}),placeholder:l("recipeEditor.descPlaceholder")})]}),e.jsxs("div",{children:[e.jsxs("label",{className:"block text-xs font-bold text-[var(--fg-muted)] uppercase mb-1.5 flex items-center gap-1.5",children:[e.jsx(Qe,{size:11,className:"text-blue-400"})," ",l("recipeEditor.markdown")]}),e.jsx("div",{className:"border border-[var(--border-default)] rounded-lg overflow-hidden",style:{minHeight:180},children:e.jsx(ys,{value:t.content?.markdown||"",onChange:u=>s({...t,content:{...t.content,markdown:u}}),language:"markdown",height:"180px",showLineNumbers:!0})})]}),e.jsxs("div",{children:[e.jsxs("label",{className:"block text-xs font-bold text-[var(--fg-muted)] uppercase mb-1.5 flex items-center gap-1.5",children:[e.jsx(At,{size:11,className:"text-emerald-500"})," ",l("recipeEditor.code")]}),e.jsx("div",{className:"border border-[var(--border-default)] rounded-lg overflow-hidden",style:{minHeight:180},children:e.jsx(ys,{value:t.content?.pattern||"",onChange:u=>s({...t,content:{...t.content,pattern:u}}),language:g,height:"180px",showLineNumbers:!0})})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-bold text-[var(--fg-muted)] uppercase mb-1",children:l("recipeEditor.rationale")}),e.jsx("textarea",{className:"w-full px-3 py-2 text-sm border border-[var(--border-default)] rounded-lg focus:outline-none focus:ring-2 focus:ring-[var(--accent-emphasis)] resize-y",rows:3,value:t.content?.rationale||"",onChange:u=>s({...t,content:{...t.content,rationale:u.target.value}}),placeholder:l("recipeEditor.rationalePlaceholder")})]})]}):e.jsxs("div",{className:"flex-1 overflow-y-auto space-y-6 scrollbar-light",children:[(()=>{const u=[["trigger",t.trigger],["language",t.language],["category",t.category],["kind",t.kind],["knowledgeType",t.knowledgeType],["status",t.status],["complexity",t.complexity],["scope",t.scope],["source",t.source],["updatedAt",t.updatedAt?h(t.updatedAt):void 0]].filter(([,m])=>!!m);return u.length===0?null:e.jsxs("div",{className:"bg-[var(--bg-subtle)] border border-[var(--border-default)] rounded-2xl p-6",children:[e.jsx("h3",{className:"text-[10px] font-bold text-[var(--fg-muted)] uppercase tracking-widest mb-4",children:"Recipe Metadata"}),e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-y-4 gap-x-8",children:u.map(([m,c])=>e.jsxs("div",{className:"flex flex-col",children:[e.jsx("span",{className:"text-[10px] text-[var(--fg-muted)] font-bold uppercase mb-1",children:m}),e.jsx("span",{className:"text-sm text-[var(--fg-primary)] break-all font-medium",children:c})]},m))})]})})(),t.description&&e.jsxs("div",{className:"bg-[var(--bg-surface)] rounded-2xl border border-[var(--border-default)] p-6",children:[e.jsx("label",{className:"text-[10px] font-bold text-[var(--fg-muted)] uppercase mb-2 block",children:l("recipeEditor.description")}),e.jsx("p",{className:"text-sm text-[var(--fg-secondary)] leading-relaxed",children:t.description})]}),t.content?.markdown&&e.jsxs("div",{className:"bg-[var(--bg-surface)] rounded-2xl border border-blue-100 p-6",children:[e.jsxs("label",{className:"text-[10px] font-bold text-[var(--fg-muted)] uppercase mb-3 block flex items-center gap-1.5",children:[e.jsx(Qe,{size:11,className:"text-blue-400"})," ",l("recipeEditor.markdown")]}),e.jsx("div",{className:"bg-blue-50/30 border border-blue-100 rounded-xl p-4",children:e.jsx("div",{className:"markdown-body text-sm text-[var(--fg-primary)] leading-relaxed",children:e.jsx(Qt,{content:t.content.markdown})})})]}),t.content?.pattern&&e.jsxs("div",{className:"bg-[var(--bg-surface)] rounded-2xl border border-emerald-100 p-6",children:[e.jsxs("label",{className:"text-[10px] font-bold text-[var(--fg-muted)] uppercase mb-3 block flex items-center gap-1.5",children:[e.jsx(At,{size:11,className:"text-emerald-500"})," ",l("recipeEditor.code")]}),e.jsx(ft,{code:t.content.pattern,language:g,showLineNumbers:!0})]}),t.content?.rationale&&e.jsxs("div",{className:"bg-[var(--bg-surface)] rounded-2xl border border-[var(--border-default)] p-6",children:[e.jsx("label",{className:"text-[10px] font-bold text-[var(--fg-muted)] uppercase mb-2 block",children:l("recipeEditor.rationale")}),e.jsx("div",{className:"bg-[var(--bg-subtle)] border border-[var(--border-default)] rounded-xl p-4",children:e.jsx("p",{className:"text-sm text-[var(--fg-secondary)] leading-relaxed",children:t.content.rationale})})]}),t.content?.steps&&t.content.steps.length>0&&e.jsxs("div",{className:"bg-[var(--bg-surface)] rounded-2xl border border-[var(--border-default)] p-6",children:[e.jsx("label",{className:"text-[10px] font-bold text-[var(--fg-muted)] uppercase mb-2 block",children:l("recipeEditor.steps")}),e.jsx("div",{className:"space-y-2",children:t.content.steps.map((u,m)=>typeof u=="string"?e.jsxs("div",{className:"bg-[var(--bg-subtle)] rounded-lg p-3 border border-[var(--border-default)] flex items-start gap-2.5",children:[e.jsx("span",{className:"text-[10px] font-bold text-blue-600 bg-blue-50 rounded-full w-5 h-5 flex items-center justify-center shrink-0 mt-0.5",children:m+1}),e.jsx("p",{className:"text-xs text-[var(--fg-primary)] leading-relaxed",children:u})]},m):e.jsxs("div",{className:"bg-[var(--bg-subtle)] rounded-lg p-3 border border-[var(--border-default)]",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[e.jsx("span",{className:"text-[10px] font-bold text-blue-600 bg-blue-50 rounded-full w-5 h-5 flex items-center justify-center shrink-0",children:m+1}),u.title&&e.jsx("span",{className:"text-xs font-bold text-[var(--fg-primary)]",children:u.title})]}),u.description&&e.jsx("p",{className:"text-xs text-[var(--fg-secondary)] ml-7 leading-relaxed",children:u.description}),u.code&&e.jsx("pre",{className:"text-[11px] font-mono bg-slate-800 text-green-300 p-2.5 rounded-md mt-1.5 ml-7 overflow-x-auto whitespace-pre-wrap",children:u.code})]},m))})]}),t.content?.codeChanges&&t.content.codeChanges.length>0&&e.jsxs("div",{className:"bg-[var(--bg-surface)] rounded-2xl border border-[var(--border-default)] p-6",children:[e.jsx("label",{className:"text-[10px] font-bold text-[var(--fg-muted)] uppercase mb-2 block",children:l("recipeEditor.codeChanges")}),e.jsx("div",{className:"space-y-2",children:t.content.codeChanges.map((u,m)=>e.jsxs("div",{className:"border border-[var(--border-default)] rounded-lg overflow-hidden",children:[e.jsxs("div",{className:"px-3 py-1.5 bg-[var(--bg-subtle)] border-b border-[var(--border-default)] flex items-center gap-2",children:[e.jsx(pt,{size:11,className:"text-blue-400"}),e.jsx("code",{className:"text-[10px] font-mono text-[var(--fg-secondary)]",children:u.file})]}),u.explanation&&e.jsx("p",{className:"text-[11px] text-[var(--fg-muted)] px-3 py-1.5 border-b border-[var(--border-default)] bg-yellow-50/30",children:u.explanation}),e.jsxs("div",{className:"p-2 bg-red-50/20 border-b border-[var(--border-default)]",children:[e.jsx("div",{className:"text-[9px] font-bold text-red-400 mb-0.5 uppercase",children:"Before"}),e.jsx("pre",{className:"text-[11px] text-[var(--fg-secondary)] whitespace-pre-wrap break-words font-mono",children:u.before||l("recipes.emptyValue")})]}),e.jsxs("div",{className:"p-2 bg-emerald-50/20",children:[e.jsx("div",{className:"text-[9px] font-bold text-emerald-500 mb-0.5 uppercase",children:"After"}),e.jsx("pre",{className:"text-[11px] text-[var(--fg-primary)] whitespace-pre-wrap break-words font-mono",children:u.after})]})]},m))})]}),t.content?.verification&&e.jsxs("div",{className:"bg-[var(--bg-surface)] rounded-2xl border border-teal-100 p-6",children:[e.jsx("label",{className:"text-[10px] font-bold text-[var(--fg-muted)] uppercase mb-2 block",children:l("recipeEditor.validation")}),e.jsxs("div",{className:"bg-teal-50/50 border border-teal-100 rounded-xl p-4 space-y-1.5",children:[t.content.verification.method&&e.jsxs("p",{className:"text-xs text-[var(--fg-secondary)]",children:[e.jsx("span",{className:"font-bold text-teal-600",children:l("recipeEditor.validationMethod")})," ",t.content.verification.method]}),t.content.verification.expectedResult&&e.jsxs("p",{className:"text-xs text-[var(--fg-secondary)]",children:[e.jsx("span",{className:"font-bold text-teal-600",children:l("recipeEditor.validationExpected")})," ",t.content.verification.expectedResult]}),t.content.verification.testCode&&e.jsx("pre",{className:"text-[11px] font-mono bg-slate-800 text-green-300 p-2.5 rounded-md overflow-x-auto whitespace-pre-wrap mt-1",children:t.content.verification.testCode})]})]}),t.tags&&t.tags.length>0&&e.jsxs("div",{className:"bg-[var(--bg-subtle)] border border-[var(--border-default)] rounded-2xl p-6",children:[e.jsxs("h3",{className:"text-[10px] font-bold text-[var(--fg-muted)] uppercase tracking-widest mb-3 flex items-center gap-1.5",children:[e.jsx(jr,{size:11,className:"text-blue-400"})," ",l("recipeEditor.tags")]}),e.jsx("div",{className:"flex flex-wrap gap-1.5",children:t.tags.map((u,m)=>e.jsx("span",{className:"px-2.5 py-1 bg-blue-50 text-blue-700 border border-blue-100 rounded-full text-xs font-medium",children:u},m))})]}),!!(t.constraints&&(t.constraints.guards?.length||t.constraints.boundaries?.length||t.constraints.preconditions?.length||t.constraints.sideEffects?.length))&&e.jsxs("div",{className:"bg-[var(--bg-subtle)] border border-[var(--border-default)] rounded-2xl p-6 space-y-4",children:[e.jsxs("h3",{className:"text-[10px] font-bold text-[var(--fg-muted)] uppercase tracking-widest flex items-center gap-1.5",children:[e.jsx(Ve,{size:11,className:"text-amber-500"})," ",l("recipeEditor.constraints")]}),t.constraints.guards&&t.constraints.guards.length>0&&e.jsxs("div",{children:[e.jsx("span",{className:"text-xs font-semibold text-[var(--fg-muted)] block mb-1.5",children:l("recipeEditor.guardRules")}),e.jsx("ul",{className:"text-sm text-[var(--fg-secondary)] space-y-1",children:t.constraints.guards.map((u,m)=>e.jsxs("li",{className:"flex gap-2 items-start",children:[e.jsx("span",{className:`text-xs mt-0.5 ${u.severity==="error"?"text-red-500":"text-yellow-500"}`,children:"●"}),e.jsx("code",{className:"font-mono text-xs bg-[var(--bg-subtle)] px-1.5 py-0.5 rounded",children:u.pattern}),u.message&&e.jsxs("span",{className:"text-xs text-[var(--fg-muted)]",children:["— ",u.message]})]},m))})]}),t.constraints.boundaries&&t.constraints.boundaries.length>0&&e.jsxs("div",{children:[e.jsx("span",{className:"text-xs font-semibold text-[var(--fg-muted)] block mb-1.5",children:l("recipeEditor.boundaryConstraints")}),e.jsx("ul",{className:"text-sm text-[var(--fg-secondary)] space-y-1",children:t.constraints.boundaries.map((u,m)=>e.jsxs("li",{className:"flex gap-2",children:[e.jsx("span",{className:"text-orange-400",children:"●"}),u]},m))})]}),t.constraints.preconditions&&t.constraints.preconditions.length>0&&e.jsxs("div",{children:[e.jsx("span",{className:"text-xs font-semibold text-[var(--fg-muted)] block mb-1.5",children:l("recipeEditor.preconditions")}),e.jsx("ul",{className:"text-sm text-[var(--fg-secondary)] space-y-1",children:t.constraints.preconditions.map((u,m)=>e.jsxs("li",{className:"flex gap-2",children:[e.jsx("span",{className:"text-blue-400",children:"◆"}),u]},m))})]}),t.constraints.sideEffects&&t.constraints.sideEffects.length>0&&e.jsxs("div",{children:[e.jsx("span",{className:"text-xs font-semibold text-[var(--fg-muted)] block mb-1.5",children:l("recipeEditor.sideEffects")}),e.jsx("ul",{className:"text-sm text-[var(--fg-secondary)] space-y-1",children:t.constraints.sideEffects.map((u,m)=>e.jsxs("li",{className:"flex gap-2",children:[e.jsx("span",{className:"text-pink-400",children:"⚡"}),u]},m))})]})]}),t.relations&&Object.entries(t.relations).some(([,u])=>Array.isArray(u)&&u.length>0)&&e.jsxs("div",{className:"bg-[var(--bg-subtle)] border border-[var(--border-default)] rounded-2xl p-6",children:[e.jsx("h3",{className:"text-[10px] font-bold text-[var(--fg-muted)] uppercase tracking-widest mb-4",children:l("recipeEditor.relations")}),e.jsx("div",{className:"space-y-2",children:[{key:"inherits",label:l("recipeEditor.relationTypes.inherits"),color:"text-green-600",icon:"↑"},{key:"implements",label:l("recipeEditor.relationTypes.implements"),color:"text-blue-600",icon:"◇"},{key:"calls",label:l("recipeEditor.relationTypes.calls"),color:"text-cyan-600",icon:"→"},{key:"dependsOn",label:l("recipeEditor.relationTypes.dependsOn"),color:"text-yellow-600",icon:"⊕"},{key:"dataFlow",label:l("recipeEditor.relationTypes.dataFlow"),color:"text-purple-600",icon:"⇢"},{key:"conflicts",label:l("recipeEditor.relationTypes.conflicts"),color:"text-red-600",icon:"✕"},{key:"extends",label:l("recipeEditor.relationTypes.extends"),color:"text-teal-600",icon:"⊃"},{key:"related",label:l("recipeEditor.relationTypes.associates"),color:"text-[var(--fg-muted)]",icon:"∼"}].map(({key:u,label:m,color:c,icon:j})=>{const A=t.relations?.[u];return!A||!Array.isArray(A)||A.length===0?null:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsxs("span",{className:`text-xs font-mono ${c} shrink-0 whitespace-nowrap pt-0.5`,children:[j," ",m]}),e.jsx("div",{className:"flex flex-wrap gap-1.5",children:A.map((D,I)=>e.jsx("span",{className:"px-2 py-0.5 bg-[var(--bg-surface)] border border-[var(--border-default)] text-[var(--fg-secondary)] rounded-lg text-xs font-mono",children:typeof D=="string"?D:D.id||D.title||JSON.stringify(D)},I))})]},u)})})]}),!t.content?.markdown&&!t.content?.pattern&&!t.description&&e.jsx("div",{className:"bg-[var(--bg-surface)] p-8 rounded-2xl border border-[var(--border-default)] shadow-sm min-h-[200px] flex items-center justify-center",children:e.jsx("div",{className:"text-[var(--fg-muted)] italic",children:l("recipeEditor.noContent")})})]})})}),e.jsxs("div",{className:"p-6 border-t border-[var(--border-default)] flex justify-end gap-3",children:[e.jsx("button",{onClick:r,disabled:o,className:"px-4 py-2 text-[var(--fg-secondary)] font-medium disabled:opacity-50",children:l("recipeEditor.cancel")}),e.jsxs("button",{onClick:a,disabled:o,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:[o?e.jsx(Ne,{size:H.lg,className:"animate-spin"}):e.jsx(ws,{size:H.lg}),l(o?"recipeEditor.saving":"recipeEditor.saveChanges")]})]})]})]})},od=({setShowCreateModal:t,createPath:s,setCreatePath:a,handleCreateFromPath:r,handleCreateFromClipboard:o,isExtracting:l})=>{const{t:i}=Ae();return e.jsxs($e,{className:"z-40 flex items-center justify-center p-4",children:[e.jsx($e.Backdrop,{className:"bg-black/20 dark:bg-black/40 backdrop-blur-sm"}),e.jsxs("div",{className:"relative w-full max-w-lg rounded-2xl shadow-2xl overflow-hidden bg-[var(--bg-surface)]",children:[e.jsxs("div",{className:"p-6 border-b flex justify-between items-center bg-[var(--bg-subtle)] border-[var(--border-default)]",children:[e.jsxs("h2",{className:"text-xl font-bold flex items-center gap-2 text-[var(--fg-primary)]",children:[e.jsx(mt,{size:H.xl,className:"text-blue-600"})," ",i("createModal.title")]}),e.jsx("button",{onClick:()=>t(!1),className:"p-2 rounded-full transition-all duration-150 text-[var(--fg-muted)] hover:bg-[var(--bg-subtle)] hover:text-[var(--fg-primary)]",children:e.jsx(ze,{size:H.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 uppercase tracking-widest text-[var(--fg-muted)]",children:[e.jsx(va,{size:H.sm})," ",i("createModal.importFromPath")]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("input",{className:"flex-1 p-3 rounded-xl text-sm outline-none focus:ring-2 focus:ring-[var(--accent-emphasis)] border bg-[var(--bg-subtle)] border-[var(--border-default)] text-[var(--fg-primary)]",placeholder:i("createModal.pathPlaceholder"),value:s,onChange:p=>a(p.target.value)}),e.jsxs("button",{onClick:r,disabled:!s||l,className:"px-5 py-2 rounded-xl text-sm font-bold whitespace-nowrap disabled:opacity-40 transition-all duration-150 bg-[var(--accent)] text-white hover:opacity-90 shadow-sm",children:[e.jsx(va,{size:14,className:"inline -mt-0.5 mr-1"}),i("createModal.scanFile")]})]})]}),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-[var(--border-default)]"})}),e.jsx("div",{className:"relative flex justify-center text-xs uppercase",children:e.jsx("span",{className:"px-2 font-bold bg-[var(--bg-surface)] text-[var(--fg-muted)]",children:i("createModal.or")})})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("label",{className:"flex items-center gap-2 text-xs font-bold uppercase tracking-widest text-[var(--fg-muted)]",children:[e.jsx(jl,{size:H.sm})," ",i("createModal.importFromClipboard")]}),e.jsxs("button",{onClick:()=>o(),disabled:l,className:"w-full flex items-center justify-center gap-3 p-4 rounded-xl font-bold transition-all duration-150 border bg-[var(--accent-subtle)] text-[var(--accent)] border-[var(--accent-emphasis)]/20 hover:bg-[var(--accent-emphasis)]/10",children:[e.jsx(Be,{size:H.lg})," ",i("createModal.useClipboard")]})]})]}),l&&e.jsxs("div",{className:"bg-blue-600 text-white p-4 flex items-center justify-center gap-3 animate-pulse",children:[e.jsx(Jt,{size:H.lg,className:"animate-spin"}),e.jsx("span",{className:"font-bold text-sm",children:i("createModal.aiThinking")})]})]})]})};function id(t){if(!t)return"";if(typeof t=="object"){const o=t.code||t.pattern||t.markdown||t.snippet||t.body||"";if(o)return o}const a=(typeof t=="string"?t:JSON.stringify(t)).replace(/^---[\s\S]*?---\s*\n?/,"").trim(),r=a.match(/```[\w]*\n([\s\S]*?)```/);return r&&r[1]?r[1].trim():a.slice(0,8e3)}const cd=({searchQ:t,insertPath:s,onClose:a})=>{const{t:r}=Ae(),[o,l]=n.useState([]),[i,p]=n.useState(!0),[d,g]=n.useState(null),x=n.useRef(!0),h=n.useRef(null);n.useEffect(()=>(x.current=!0,h.current=new AbortController,Q.search(t||"",{mode:"auto",type:"recipe",signal:h.current.signal}).then(m=>{x.current&&l((m.items||[]).map(c=>({name:(c.title||c.name||"")+".md",path:"",content:c.content,qualityScore:(c.quality||{}).overall||c.qualityScore||0,recommendReason:""})))}).catch(m=>{m.name!=="AbortError"&&x.current&&l([])}).finally(()=>{x.current&&p(!1)}),()=>{x.current=!1,h.current&&h.current.abort()}),[t]);const u=async m=>{g(m.name);try{const c=id(m.content);await Q.insertAtSearchMark({path:s,content:c}),x.current&&(alert(r("searchModal.insertSuccess")+" "+s),a())}catch{x.current&&alert(r("searchModal.insertFailed"))}finally{x.current&&g(null)}};return e.jsxs($e,{className:"z-40 flex items-center justify-center p-4",children:[e.jsx($e.Backdrop,{className:"bg-black/20 dark:bg-black/40 backdrop-blur-sm"}),e.jsxs("div",{className:"relative bg-[var(--bg-surface)] 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-[var(--border-default)] flex justify-between items-center bg-[var(--bg-subtle)]",children:[e.jsxs("h2",{className:"text-xl font-bold flex items-center gap-2 text-[var(--fg-primary)]",children:[e.jsx(xt,{size:H.xl,className:"text-blue-600"})," ",r("searchModal.title")]}),e.jsx("button",{onClick:a,className:"p-2 hover:bg-[var(--bg-surface)] rounded-full transition-colors",children:e.jsx(ze,{size:H.lg})})]}),e.jsxs("div",{className:"p-4 text-sm text-[var(--fg-muted)] border-b border-[var(--border-default)]",children:[r("searchModal.keyword")," ",t||r("searchModal.keywordAll")," · ",r("searchModal.insertTo")," ",s]}),e.jsx("div",{className:"flex-1 overflow-y-auto p-4",children:i?e.jsx("div",{className:"flex items-center justify-center py-12",children:e.jsx("div",{className:"animate-spin rounded-full h-8 w-8 border-b-2 border-blue-600"})}):o.length===0?e.jsx("div",{className:"text-[var(--fg-muted)] text-center py-8",children:r("searchModal.noResults")}):e.jsx("ul",{className:"space-y-2",children:o.map(m=>e.jsx("li",{children:e.jsxs("button",{type:"button",onClick:()=>u(m),disabled:d!==null,className:"w-full flex items-center justify-between gap-3 p-4 rounded-xl border border-[var(--border-default)] hover:border-[var(--accent-emphasis)] hover:bg-[var(--accent-subtle)]/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-[var(--fg-primary)] truncate",children:m.name}),(m.qualityScore!==void 0||m.recommendReason)&&e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[m.qualityScore!==void 0&&e.jsxs("span",{className:"inline-flex items-center gap-1 px-2 py-0.5 bg-blue-100 rounded text-xs text-blue-700 font-medium",children:["🤖 ",r("searchModal.quality")," ",(m.qualityScore*100).toFixed(0),"%"]}),m.recommendReason&&e.jsx("span",{className:"text-xs text-[var(--fg-secondary)] italic truncate max-w-xs",children:m.recommendReason})]})]}),d===m.name?e.jsxs("span",{className:"text-blue-600 text-sm flex items-center gap-1",children:[e.jsx("span",{className:"animate-spin",children:"⏳"})," ",r("searchModal.inserting")]}):e.jsxs("span",{className:"text-blue-600 text-sm flex items-center gap-1",children:[e.jsx(kr,{size:H.md})," ",r("searchModal.insertBtn")]})]})},m.name))})})]})]})},Bs=[{id:"google",labelKey:"llmConfig.providers.gemini",defaultModel:"gemini-3-flash-preview",keyEnv:"ASD_GOOGLE_API_KEY"},{id:"openai",labelKey:"llmConfig.providers.openai",defaultModel:"gpt-5.4",keyEnv:"ASD_OPENAI_API_KEY"},{id:"deepseek",labelKey:"llmConfig.providers.deepseek",defaultModel:"deepseek-chat",keyEnv:"ASD_DEEPSEEK_API_KEY"},{id:"claude",labelKey:"llmConfig.providers.claude",defaultModel:"claude-sonnet-4-20250514",keyEnv:"ASD_CLAUDE_API_KEY"},{id:"ollama",labelKey:"llmConfig.providers.ollama",defaultModel:"llama3",keyEnv:""}],dd=({onClose:t,onSaved:s})=>{const{t:a}=Ae(),[r,o]=n.useState(!0),[l,i]=n.useState(!1),[p,d]=n.useState(!1),[g,x]=n.useState("google"),[h,u]=n.useState("gemini-3-flash-preview"),[m,c]=n.useState(""),[j,A]=n.useState(""),[D,I]=n.useState(!1),[P,J]=n.useState({}),[w,B]=n.useState(!1);n.useEffect(()=>{z()},[]);const z=async()=>{o(!0);try{const N=await Q.getLlmEnvConfig();d(N.hasEnvFile);const v=N.vars||{};v.ASD_AI_PROVIDER&&x(v.ASD_AI_PROVIDER),v.ASD_AI_MODEL&&u(v.ASD_AI_MODEL),v.ASD_AI_PROXY&&A(v.ASD_AI_PROXY),J(v)}catch{}finally{o(!1)}},k=Bs.find(N=>N.id===g),E=k?.keyEnv||"",L=E?!!P[E]:!0,O=N=>{x(N);const v=Bs.find(U=>U.id===N);v&&u(v.defaultModel),c("")},W=async()=>{if(g){if(E&&!L&&!m.trim()){alert(a("llmConfig.apiKeyRequired"));return}i(!0),B(!1);try{await Q.saveLlmEnvConfig({provider:g,model:h||void 0,apiKey:m.trim()||void 0,proxy:j.trim()||void 0}),B(!0),setTimeout(()=>{s(),t()},800)}catch(N){alert(ke(N,a("llmConfig.saveFailed")))}finally{i(!1)}}},q=N=>!N||N.length<10?N?"••••••":"":`${N.slice(0,6)}••••${N.slice(-4)}`;return e.jsx("div",{className:"fixed inset-0 bg-black/40 flex items-center justify-center z-50",onClick:t,children:e.jsxs("div",{className:"rounded-2xl shadow-2xl w-full max-w-lg mx-4 overflow-hidden bg-[var(--bg-surface)]",onClick:N=>N.stopPropagation(),children:[e.jsxs("div",{className:"flex items-center justify-between px-6 py-4 border-b border-[var(--border-default)]",children:[e.jsx("h2",{className:"text-lg font-semibold text-[var(--fg-primary)]",children:a("llmConfig.title")}),e.jsx("button",{onClick:t,className:"p-1 rounded-lg transition-all duration-150 hover:bg-[var(--bg-subtle)] text-[var(--fg-muted)] hover:text-[var(--fg-primary)]",children:e.jsx(ze,{size:H.md})})]}),e.jsx("div",{className:"px-6 py-5 space-y-5",children:r?e.jsx("div",{className:"flex items-center justify-center py-12",children:e.jsx(Ne,{size:24,className:"animate-spin text-blue-500"})}):e.jsxs(e.Fragment,{children:[!p&&e.jsxs("div",{className:"flex items-start gap-2 p-3 bg-amber-50 border border-amber-200 rounded-lg text-sm text-amber-700",children:[e.jsx(st,{size:16,className:"mt-0.5 shrink-0"}),e.jsx("span",{children:a("llmConfig.envWarning")})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium mb-2 text-[var(--fg-primary)]",children:a("llmConfig.provider")}),e.jsx("div",{className:"grid grid-cols-2 sm:grid-cols-3 gap-2",children:Bs.map(N=>e.jsx("button",{type:"button",onClick:()=>O(N.id),className:`px-3 py-2 rounded-lg text-sm font-medium border transition-all ${g===N.id?"bg-[var(--accent-subtle)] border-[var(--accent-emphasis)] text-[var(--accent)] ring-1 ring-[var(--accent-emphasis)]/30":"bg-[var(--bg-surface)] border-[var(--border-default)] text-[var(--fg-secondary)] hover:border-[var(--border-emphasis)] hover:bg-[var(--bg-subtle)]"}`,children:a(N.labelKey)},N.id))})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium mb-1.5 text-[var(--fg-primary)]",children:a("llmConfig.model")}),e.jsx("input",{type:"text",value:h,onChange:N=>u(N.target.value),placeholder:k?.defaultModel||"",className:"w-full px-3 py-2 border rounded-lg text-sm focus:outline-none focus:ring-2 focus:ring-[var(--accent-emphasis)]/20 focus:border-[var(--accent-emphasis)] border-[var(--border-default)] bg-[var(--bg-subtle)] text-[var(--fg-primary)]"})]}),E&&e.jsxs("div",{children:[e.jsxs("label",{className:"block text-sm font-medium mb-1.5 text-[var(--fg-primary)]",children:[a("llmConfig.apiKey"),L&&e.jsxs("span",{className:"ml-2 text-xs text-green-600 font-normal",children:["(",a("llmConfig.configured")," ",q(P[E]),")"]})]}),e.jsxs("div",{className:"relative",children:[e.jsx("input",{type:D?"text":"password",value:m,onChange:N=>c(N.target.value),placeholder:a(L?"llmConfig.apiKeyPlaceholderSet":"llmConfig.apiKeyPlaceholderEmpty"),className:"w-full px-3 py-2 pr-10 border rounded-lg text-sm focus:outline-none focus:ring-2 focus:ring-[var(--accent-emphasis)]/20 focus:border-[var(--accent-emphasis)] border-[var(--border-default)] bg-[var(--bg-subtle)] text-[var(--fg-primary)]"}),e.jsx("button",{type:"button",onClick:()=>I(N=>!N),className:"absolute right-2 top-1/2 -translate-y-1/2 p-1 text-[var(--fg-muted)] hover:text-[var(--fg-secondary)]",children:D?e.jsx(wl,{size:16}):e.jsx(Ut,{size:16})})]})]}),e.jsxs("div",{children:[e.jsxs("label",{className:"block text-sm font-medium mb-1.5 text-[var(--fg-primary)]",children:[a("llmConfig.proxy")," ",e.jsx("span",{className:"text-xs font-normal text-[var(--fg-muted)]",children:a("llmConfig.optional")})]}),e.jsx("input",{type:"text",value:j,onChange:N=>A(N.target.value),placeholder:"http://127.0.0.1:7890",className:"w-full px-3 py-2 border rounded-lg text-sm focus:outline-none focus:ring-2 focus:ring-[var(--accent-emphasis)]/20 focus:border-[var(--accent-emphasis)] border-[var(--border-default)] bg-[var(--bg-subtle)] text-[var(--fg-primary)]"})]})]})}),e.jsxs("div",{className:"flex items-center justify-end gap-3 px-6 py-4 border-t border-[var(--border-default)] bg-[var(--bg-subtle)]",children:[e.jsx("button",{onClick:t,className:"px-4 py-2 text-sm font-medium transition-colors text-[var(--fg-secondary)] hover:text-[var(--fg-primary)]",children:a("llmConfig.cancel")}),e.jsxs("button",{onClick:W,disabled:l||r||w,className:`flex items-center gap-2 px-5 py-2 rounded-lg text-sm font-medium transition-all ${w?"bg-green-500 text-white":"bg-blue-600 text-white hover:bg-blue-700 shadow-sm"} disabled:opacity-60`,children:[l?e.jsx(Ne,{size:16,className:"animate-spin"}):w?e.jsx(ht,{size:16}):e.jsx(ws,{size:16}),a(w?"llmConfig.saved":"llmConfig.saveToEnv")]})]})]})})},Wa=200,ud=({open:t,onClose:s})=>{const{t:a}=Ae(),[r,o]=n.useState([]),[l,i]=n.useState(!1),[p,d]=n.useState(""),g=n.useRef(null);n.useEffect(()=>{if(!t)return;let D=!1;Q.getSignalTrace({limit:100}).then(J=>{if(D)return;const w=J.signals.map(B=>({type:B.type,source:B.source,target:B.target,value:B.value,metadata:B.metadata,timestamp:B.timestamp}));o(w)}).catch(()=>{});const I=Cs(),P=J=>{l||o(w=>{const B=[J,...w];return B.length>Wa?B.slice(0,Wa):B})};return I.on("signal:event",P),()=>{D=!0,I.off("signal:event",P)}},[t,l]);const x=p?r.filter(D=>D.type.toLowerCase().includes(p.toLowerCase())||D.source.toLowerCase().includes(p.toLowerCase())):r,h={guard:"text-red-500",search:"text-blue-500",usage:"text-green-500",lifecycle:"text-purple-500",exploration:"text-cyan-500",quality:"text-yellow-500",panorama:"text-indigo-500",decay:"text-orange-500",forge:"text-pink-500"},u={guard:"#ef4444",search:"#3b82f6",usage:"#22c55e",lifecycle:"#a855f7",decay:"#f97316"},m=["guard","search","usage","lifecycle","decay"],c=50,j=n.useMemo(()=>{const D={};for(const P of m)D[P]=0;for(const P of r)P.type in D&&D[P.type]++;const I=Math.max(1,...Object.values(D));return{counts:D,max:I}},[r]),A=n.useMemo(()=>{const D=[];for(const I of m)j.counts[I]>c&&D.push(`${I} 信号量过高 (${j.counts[I]})`);if(r.length>0){const I=r[0].timestamp;Date.now()-I>300*1e3&&D.push("超过 5 分钟未收到新信号")}else t&&D.push("尚未收到任何信号");return D},[r,j,t]);return t?e.jsxs("div",{className:"fixed right-0 top-0 h-full w-80 glass-surface border-l border-[var(--border-muted)] shadow-xl z-50 flex flex-col",children:[e.jsxs("div",{className:"flex items-center justify-between p-3 border-b border-[var(--border-muted)]",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Yt,{className:"w-4 h-4 text-[var(--accent)]"}),e.jsx("span",{className:"text-sm font-semibold text-[var(--text-primary)]",children:"Signal Monitor"}),e.jsx("span",{className:"text-xs px-1.5 py-0.5 rounded-full bg-[var(--accent)]/10 text-[var(--accent)]",children:r.length})]}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("button",{onClick:()=>i(!l),className:`p-1 rounded text-xs ${l?"text-red-500":"text-green-500"} hover:bg-[var(--bg-elevated)]`,children:l?"▶":"⏸"}),e.jsx("button",{onClick:()=>o([]),className:"p-1 rounded text-xs text-[var(--text-tertiary)] hover:bg-[var(--bg-elevated)]",children:"Clear"}),e.jsx("button",{onClick:s,className:"p-1 rounded text-[var(--text-tertiary)] hover:bg-[var(--bg-elevated)]",children:e.jsx(ze,{className:"w-4 h-4"})})]})]}),e.jsx("div",{className:"p-2 border-b border-[var(--border-muted)]",children:e.jsx("input",{type:"text",value:p,onChange:D=>d(D.target.value),placeholder:"Filter by type or source...",className:"w-full px-2 py-1 text-xs rounded bg-[var(--bg-elevated)] text-[var(--text-primary)] border border-[var(--border-muted)] focus:outline-none focus:border-[var(--accent)]"})}),e.jsx("div",{ref:g,className:"flex-1 overflow-y-auto min-h-0",children:x.length===0?e.jsxs("div",{className:"flex flex-col items-center justify-center h-32 text-[var(--text-tertiary)]",children:[e.jsx(js,{className:"w-5 h-5 mb-2 opacity-50"}),e.jsx("span",{className:"text-xs",children:"Waiting for signals..."})]}):e.jsx("div",{className:"divide-y divide-[var(--border-muted)]",children:x.map((D,I)=>e.jsxs("div",{className:"p-2 hover:bg-[var(--bg-elevated)] transition-colors",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:`text-xs font-mono font-semibold ${h[D.type]??"text-[var(--text-secondary)]"}`,children:D.type}),e.jsx("span",{className:"text-[10px] text-[var(--text-tertiary)]",children:new Date(D.timestamp).toLocaleTimeString()})]}),e.jsx("div",{className:"text-[11px] text-[var(--text-tertiary)] mt-0.5 truncate",children:D.source})]},`${D.type}-${D.timestamp}-${I}`))})}),e.jsxs("div",{className:"border-t border-[var(--border-muted)] p-3 shrink-0",children:[e.jsx("h3",{className:"text-xs font-medium text-[var(--fg-muted)] uppercase tracking-wider mb-2",children:"Signal Statistics"}),e.jsx("div",{className:"space-y-1.5",children:m.map(D=>e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-[10px] font-mono w-14 text-[var(--text-tertiary)] text-right",children:D}),e.jsx("div",{className:"flex-1 h-3 rounded-sm bg-[var(--bg-elevated)] overflow-hidden",children:e.jsx("div",{className:"h-full rounded-sm transition-all duration-300",style:{width:`${j.counts[D]/j.max*100}%`,backgroundColor:u[D]}})}),e.jsx("span",{className:"text-[10px] font-mono w-6 text-[var(--text-tertiary)] text-right",children:j.counts[D]})]},D))})]}),A.length>0&&e.jsxs("div",{className:"border-t border-[var(--border-muted)] p-3 shrink-0",children:[e.jsx("h3",{className:"text-xs font-medium text-[var(--fg-muted)] uppercase tracking-wider mb-2",children:"Anomaly Alerts"}),e.jsx("div",{className:"space-y-1",children:A.map((D,I)=>e.jsxs("div",{className:"text-[11px] text-yellow-500 bg-yellow-500/10 rounded px-2 py-1",children:["⚠️ ",D]},I))})]})]}):null};class md extends it.Component{constructor(s){super(s),this.state={hasError:!1,error:null}}static getDerivedStateFromError(s){return{hasError:!0,error:s}}render(){return this.state.hasError?e.jsxs("div",{style:{padding:40,textAlign:"center"},children:[e.jsx("h2",{style:{color:"#ef4444",marginBottom:12},children:Us.app.errorBoundary.title}),e.jsx("pre",{style:{fontSize:12,color:"#64748b",whiteSpace:"pre-wrap",maxWidth:600,margin:"0 auto"},children:this.state.error?.message}),e.jsx("button",{onClick:()=>{this.setState({hasError:!1,error:null}),window.location.reload()},style:{marginTop:16,padding:"8px 20px",background:"#3b82f6",color:"#fff",border:"none",borderRadius:8,cursor:"pointer"},children:Us.app.errorBoundary.refreshBtn})]}):this.props.children}}function Ht(t,s="ai-scan"){return{title:t.title||"",description:t.description||"",trigger:t.trigger||"",language:t.language||"",category:t.category||"",tags:t.tags||[],kind:t.kind||"",knowledgeType:t.knowledgeType||"",scope:t.scope||"",complexity:t.complexity||"",difficulty:t.difficulty||"",authority:t.authority,lifecycle:t.lifecycle||"pending",source:t.source||s,doClause:t.doClause||"",dontClause:t.dontClause||"",whenClause:t.whenClause||"",topicHint:t.topicHint||"",coreCode:t.coreCode||"",content:t.content||{},constraints:t.constraints||{},reasoning:t.reasoning||{},quality:t.quality||{},stats:t.stats||{},relations:t.relations||{},headers:t.headers||[],headerPaths:t.headerPaths,moduleName:t.moduleName,includeHeaders:t.includeHeaders,createdAt:t.createdAt,updatedAt:t.updatedAt}}const pd=()=>{const t=eo(),s=so(t.user?.role),a=ao(),{t:r}=Ae(),o=()=>{const S=window.location.pathname.replace(/^\//,"").split("/")[0]||"";return $l.includes(S)?S:"help"},[l,i]=n.useState(null),[p,d]=n.useState(o()),[g,x]=n.useState(""),[h,u]=n.useState(!1),[m,c]=n.useState(!0),[j,A]=n.useState(null),[D,I]=n.useState([]),[P,J]=n.useState([]),[w,B]=n.useState(null),[z,k]=n.useState(!1),[E,L]=n.useState({current:0,total:0,status:""}),[O,W]=n.useState([]),[q,N]=n.useState([]),[v,U]=n.useState(null),ae=n.useRef(null),be=S=>{const K=ae.current;return K?`asd:spm:${S}:${K}`:null},me=n.useCallback(S=>{N(K=>{const Y=typeof S=="function"?S(K):S;try{const ie=be("scan-results");ie&&sessionStorage.setItem(ie,JSON.stringify(Y))}catch{}return Y})},[]);n.useEffect(()=>{try{const S=be("selected-target");if(!S)return;w?sessionStorage.setItem(S,w):sessionStorage.removeItem(S)}catch{}},[w]),n.useEffect(()=>{try{const S=be("guard-audit");if(!S)return;v?sessionStorage.setItem(S,JSON.stringify(v)):sessionStorage.removeItem(S)}catch{}},[v]);const[je,G]=n.useState(1),[le,de]=n.useState(12),[R,T]=n.useState(!1),[X,oe]=n.useState(""),[pe,ue]=n.useState(!1),[M,Ce]=n.useState(null),[F,Se]=n.useState(null),[Te,Fe]=n.useState(!1),[Me,ee]=n.useState(!0),[ce,f]=n.useState(!1),[V,xe]=n.useState(0),[fe,C]=n.useState(!1),b=n.useRef(null),_=n.useRef(null);n.useEffect(()=>{G(1)},[g]),n.useEffect(()=>{if(l?.projectRoot)try{const S=`asd:custom-folder-targets:${l.projectRoot}`,K=localStorage.getItem(S);J(K?JSON.parse(K):[])}catch{J([])}},[l?.projectRoot]),n.useEffect(()=>{if(!l?.projectRoot)return;ae.current=l.projectRoot;const S=l.projectRoot;try{B(sessionStorage.getItem(`asd:spm:selected-target:${S}`)||null)}catch{B(null)}try{const K=sessionStorage.getItem(`asd:spm:scan-results:${S}`);N(K?JSON.parse(K):[])}catch{N([])}try{const K=sessionStorage.getItem(`asd:spm:guard-audit:${S}`);U(K?JSON.parse(K):null)}catch{U(null)}},[l?.projectRoot]);const ne=()=>{b.current&&b.current.abort()},[$,y]=n.useState(!1),te=async()=>{if(!$){y(!0);try{b.current&&b.current.abort(),await Q.cancelBootstrap("Cancelled by user via Dashboard")}catch{}finally{y(!1)}}};n.useEffect(()=>{let S=!1;const K=async()=>{try{const ie=await Q.getSignalStatus();if(!S){const ve=ie?.suggestions?.length||0,Re=ie?.snapshot?.lastResult?.newSuggestions||0;xe(ve||Re)}}catch{}};K();const Y=setInterval(K,300*1e3);return()=>{S=!0,clearInterval(Y)}},[]);const ge=n.useRef(null);n.useEffect(()=>{if(a.isAllDone&&a.session){if(ge.current!==a.session.id){ge.current=a.session.id;const S=a.session.failed>0?r("bootstrap.notifyPartial",{completed:a.session.completed,total:a.session.total,failed:a.session.failed}):r("bootstrap.notifySuccess",{completed:a.session.completed});re(S,{title:r("bootstrap.coldStartComplete"),type:a.session.failed>0?"error":"success"})}we()}},[a.isAllDone,a.session?.id]),n.useEffect(()=>{if(a.candidateCreatedTick>0){const S=setTimeout(()=>we(),2e3);return()=>clearTimeout(S)}},[a.candidateCreatedTick]);const he=(S,K)=>{d(S);const Y=K?.preserveSearch&&window.location.search?window.location.search:"";window.history.pushState({},document.title,`/${S}${Y}`)},De=S=>{A(S),d("recipes");const K=new URLSearchParams(window.location.search);K.set("edit",encodeURIComponent(S.name)),window.history.pushState({},document.title,`/recipes?${K.toString()}`)},se=()=>{A(null),window.history.replaceState({},document.title,"/recipes")};n.useEffect(()=>{g===""&&Ce(null)},[g]),n.useEffect(()=>{d(o())},[]),n.useEffect(()=>{if(!l)return;const S=window.location.pathname.replace(/^\//,"").split("/")[0],Y=new URLSearchParams(window.location.search).get("edit");if(S==="recipes"&&Y&&l.recipes)try{const ie=decodeURIComponent(Y),ve=l.recipes.find(Re=>Re.name===ie);ve&&!j&&(d("recipes"),De(ve))}catch{}},[l]),n.useEffect(()=>{we(),Oe(),rt();const S=()=>{d(o())};window.addEventListener("popstate",S);const K=new URLSearchParams(window.location.search),Y=K.get("action"),ie=K.get("path"),ve=K.get("q")||"";return Y==="search"&&ie?Se({q:ve,path:ie}):Y==="create"&&ie&&(oe(ie),T(!0),K.get("autoScan")==="1"&&setTimeout(()=>Xt(ie),500)),Y&&window.history.replaceState({},document.title,window.location.pathname),()=>{window.removeEventListener("popstate",S)}},[]);const we=async()=>{c(!0);try{const S=await Q.fetchData();i(S)}catch(S){re(ke(S,r("app.load.failed")),{title:r("app.load.failedTitle"),type:"error"})}finally{c(!1)}},Oe=async()=>{try{const S=await Q.fetchTargets();I(S)}catch(S){console.warn("删除候选残留失败:",ke(S))}},rt=async()=>{try{const S=await Q.getLlmEnvConfig();ee(S.llmReady)}catch{}},ct=async()=>{try{await Q.refreshProject(),Oe(),re(r("app.projectRefresh.success"),{title:r("app.projectRefresh.successTitle")})}catch{re(r("app.load.failedHint"),{title:r("app.projectRefresh.failed"),type:"error"})}},Xt=async S=>{ue(!0);try{const K=await Q.extractFromPath(S);me(K.result.map(Y=>({...Ht(Y,"extract"),mode:"full",lang:"cn"}))),he("spm"),T(!1),we(),K.result?.length>0&&re(r("app.extract.success"),{title:r("app.extract.successTitle")})}catch{re(r("app.extract.failed"),{type:"error"})}finally{ue(!1)}},nt=async()=>{if(X){ue(!0);try{const S=await Q.extractFromPath(X);me(S.result.map(K=>({...Ht(K,"extract"),mode:"full",lang:"cn"}))),he("spm"),T(!1),we(),S.result?.length>0?re(S.isMarked?r("app.extract.markerSuccess"):r("app.extract.normalSuccess"),{title:r("app.extract.successTitle")}):S.isMarked||re(r("app.extract.noMarker"),{title:r("app.extract.extracting"),type:"info"})}catch{re(r("app.extract.failed"),{type:"error"})}finally{ue(!1)}}},Ss=async S=>{try{const K=await navigator.clipboard.readText();if(!K)return re(r("app.clipboard.empty"),{title:r("app.clipboard.emptyTitle"),type:"info"});re(r("app.clipboard.analyzing"),{title:r("app.clipboard.analyzingTitle"),type:"info"}),ue(!0);const Y=S||X;try{const ie=await Q.extractFromText(K,Y||void 0),ve=ie._multipleCount;me([{...Ht(ie,"clipboard"),mode:"full",lang:"cn"}]),he("spm"),T(!1),we(),re(ve?r("app.clipboard.resultMulti",{count:ve}):r("app.extract.normalSuccess"),{title:r("app.clipboard.resultTitle")})}catch(ie){const ve=ke(ie);Vl(ie)?re(ve,{title:r("app.clipboard.aiFailed"),type:"error"}):re(ve,{title:r("common.operationFailed"),type:"error"})}}catch{re(r("app.clipboard.permissionError"),{title:r("app.clipboard.permissionTitle"),type:"error"})}finally{ue(!1)}},an={"scan:started":{percent:5,status:r("app.scan.events.initializing")},"scan:files-loaded":{percent:15,status:S=>r("app.scan.events.filesLoaded",{count:S.count||0})},"scan:reading":{percent:25,status:S=>r("app.scan.events.readingFiles",{count:S.count||0})},"scan:ai-extracting":{percent:40,status:r("app.scan.events.aiAnalyzing")},"scan:enriching":{percent:85,status:S=>r("app.scan.events.enriching",{count:S.recipeCount||0})},"scan:completed":{percent:95,status:r("app.scan.events.completing")}},rn=async S=>{if(z)return;b.current&&b.current.abort(),_.current&&(clearInterval(_.current),_.current=null);const K=new AbortController;b.current=K,B(S.name),k(!0),me([]),U(null),W([]),L({current:0,total:100,status:r("app.scan.streamInit")});try{const Y=await Q.scanTargetStream(S,Re=>{const Pe=an[Re.type];if(Pe){const _e=typeof Pe.status=="function"?Pe.status(Re):Pe.status;L({current:Pe.percent,total:100,status:_e})}Re.type==="scan:files-loaded"&&Re.files&&W(Re.files),Re.type==="scan:ai-extracting"&&(_.current&&clearInterval(_.current),_.current=setInterval(()=>{L(_e=>({..._e,current:Math.min(_e.current+1,80)}))},3e3)),(Re.type==="scan:enriching"||Re.type==="scan:completed")&&_.current&&(clearInterval(_.current),_.current=null)},K.signal);_.current&&(clearInterval(_.current),_.current=null),L({current:100,total:100,status:r("app.scan.completed")});const ie=Y.recipes||[],ve=Y.scannedFiles||[];if(ie.length>0||ve.length>0){const Re=typeof S=="string"?S:S?.name||"unknown",Pe=ie.map(_e=>({...Ht(_e,"ai-scan"),mode:"full",lang:"cn",candidateTargetName:Re,scanMode:"target"}));if(me(Pe),ve.length>0&&W(ve),we(),ie.length>0)re(r("app.scan.targetSuccess",{count:ie.length}),{title:r("app.scan.targetSuccessTitle")});else if(Y.message){const _e=Y.noAi;re(Y.message,{title:r(_e?"app.scan.aiNotConfigured":"app.scan.noResults"),type:_e?"info":"error"})}else re(r("app.scan.noResults"),{title:r("app.scan.scanComplete"),type:"info"})}else re(r("app.scan.scanFailedHint"),{title:r("app.scan.scanFailed"),type:"error"})}catch(Y){if(_.current&&(clearInterval(_.current),_.current=null),fs(Y))return;const ie=ss(Y),ve=ie?r("app.scan.timeout"):ke(Y,r("app.scan.scanError"));re(ve,{title:r(ie?"app.scan.timeoutTitle":"app.scan.scanError"),type:"error"})}finally{b.current===K&&(k(!1),L({current:0,total:0,status:""}),b.current=null)}},nn=async()=>{if(z)return;b.current&&b.current.abort();const S=new AbortController;b.current=S,he("candidates"),k(!0),me([]),U(null),W([]),L({current:0,total:100,status:r("app.coldStart.collecting")}),a.resetSession();try{const K=await Q.bootstrap(S.signal);L({current:100,total:100,status:r("app.coldStart.skeletonCreated")}),K.bootstrapSession&&a.initFromApiResponse(K.bootstrapSession),we();const Y=K.report||{},ie=K.targets?.length||0,ve=Y.totals?.files||0,Re=Y.totals?.graphEdges||0,Pe=K.guardSummary,_e=Pe?`, ${r("app.coldStart.guardSuffix",{count:Pe.totalViolations})}`:"";re(r("app.coldStart.skeletonDetail",{targets:ie,files:ve,deps:Re})+_e)}catch(K){if(Is(K))return;const ie=ss(K)?r("app.coldStart.timeout"):ke(K);re(ie,{type:"error"})}finally{b.current===S&&(k(!1),L({current:0,total:0,status:""}),b.current=null)}},ln=async()=>{if(z)return;b.current&&b.current.abort();const S=new AbortController;b.current=S,he("candidates"),k(!0),L({current:0,total:100,status:r("app.rescan.analyzing")}),a.resetSession();try{const K=await Q.rescan({reason:"dashboard-rescan"},S.signal);L({current:100,total:100,status:r("app.rescan.done")}),K.bootstrapSession&&a.initFromApiResponse(K.bootstrapSession),we();const Y=K.relevanceAudit||{},ie=K.gapAnalysis||{};re(r("app.rescan.success",{preserved:K.rescan?.preservedRecipes||0,healthy:Y.healthy||0,decayed:(Y.decay||0)+(Y.severe||0)+(Y.dead||0)})+(ie.gapDimensions>0?` ${r("app.rescan.filling",{count:ie.gapDimensions})}`:""))}catch(K){if(Is(K))return;const Y=ss(K)?r("app.rescan.timeout"):ke(K);re(Y,{type:"error"})}finally{b.current===S&&(k(!1),L({current:0,total:0,status:""}),b.current=null)}},on=async()=>{if(z)return;b.current&&b.current.abort();const S=new AbortController;b.current=S,he("spm"),B("__project__"),k(!0),me([]),U(null),W([]),L({current:0,total:100,status:r("app.fullScan.collecting")});const K=[{status:r("app.fullScan.phase5"),percent:5},{status:r("app.fullScan.phase15"),percent:15},{status:r("app.fullScan.phase25"),percent:25},{status:r("app.fullScan.phase35"),percent:35},{status:r("app.fullScan.phase45"),percent:45},{status:r("app.fullScan.phase55"),percent:55},{status:r("app.fullScan.phase65"),percent:65},{status:r("app.fullScan.phase75"),percent:75},{status:r("app.fullScan.phase85"),percent:85}];let Y=0;const ie=setInterval(()=>{Y=Math.min(Y+1,K.length);const ve=K[Y-1];ve&&L(Re=>({...Re,current:ve.percent,status:ve.status}))},15e3);try{const ve=await Q.scanProject(S.signal);clearInterval(ie),L({current:100,total:100,status:ve.partial?r("app.fullScan.partialComplete"):r("app.fullScan.completed")});const Re=ve.recipes||[],Pe=ve.scannedFiles||[];if(Re.length>0||Pe.length>0){const _e=Re.map(vn=>({...Ht(vn,"ai-scan"),mode:"full",lang:"cn",candidateTargetName:"__project__",scanMode:"project"}));me(_e),W(Pe),U(ve.guardAudit||null),we();const Ze=ve.guardAudit?.summary,es=Ze?`, ${r("app.fullScan.guardSuffix",{count:Ze.totalViolations})}`:"",Ft=ve.partial?r("app.fullScan.timeoutSuffix"):"";re(r("app.fullScan.resultDetail",{count:Re.length})+es+Ft)}else re(r("app.fullScan.noContent"))}catch(ve){if(clearInterval(ie),Is(ve))return;const Pe=ss(ve)?r("app.fullScan.timeout"):ke(ve);re(Pe,{type:"error"})}finally{b.current===S&&(k(!1),L({current:0,total:0,status:""}),b.current=null)}},cn=(S,K)=>{const Y=[...q],ie={...Y[S],...K};Y[S]=ie,me(Y)},dn=async S=>{if(!Te){Fe(!0);try{const K=(S.content?.pattern||"").trim(),Y=(()=>{if(!K)return!1;const Ze=K.split(`
110
110
  `).filter(Ft=>Ft.trim());return Ze.filter(Ft=>/^\s*(#{1,6}\s|[-*>]\s|\d+\.\s)/.test(Ft)).length<=Ze.length*.3})(),ie=(S.trigger||"").split(/[,,\s]+/).map(Ze=>Ze.trim()).filter(Boolean);if(Y&&ie.length===0){re(r("app.recipe.triggerRequired"),{type:"error"}),Fe(!1);return}const ve={title:S.title||"Untitled",description:S.description||"",trigger:ie.join(", ")||"",language:S.language||"",category:S.category||"Utility",kind:S.kind||"pattern",knowledgeType:S.knowledgeType||"code-pattern",complexity:S.complexity||"intermediate",scope:S.scope||void 0,difficulty:S.difficulty||"",tags:S.tags||[],source:S.source||"ai-scan",sourceFile:S.sourceFile||"",moduleName:S.moduleName||"",doClause:S.doClause||"",dontClause:S.dontClause||"",whenClause:S.whenClause||"",topicHint:S.topicHint||"",coreCode:S.coreCode||"",content:S.content||{},reasoning:S.reasoning||{},quality:S.quality||{},constraints:S.constraints||{},relations:S.relations||{},stats:S.stats||{},headers:S.headers||[],headerPaths:S.headerPaths||[],includeHeaders:S.includeHeaders||!1},Re=await Q.knowledgeCreate(ve);if(Re?.id)try{await Q.knowledgeLifecycle(Re.id,"publish")}catch(Ze){console.warn("auto-publish after save failed:",Ze)}re(r(Y?"app.recipe.savedAsRecipe":"app.recipe.savedToKb")),me(Ze=>Ze.filter(es=>es.title!==S.title));const Pe=S.candidateTargetName,_e=S.candidateId;if(Pe&&_e)try{await Q.deleteCandidate(_e)}catch{}we()}catch(K){const Y=ka(K)??ps(K);re(Y??r("app.recipe.saveFailed"),{type:"error"})}finally{Fe(!1)}}},un=async()=>{if(!(!j||Te)){Fe(!0);try{const S=j.id||j.name?.replace(/\.md$/,""),K=typeof j.content=="string"?{pattern:j.content,markdown:"",rationale:"",steps:[],codeChanges:[],verification:null}:j.content||{};await Q.knowledgeUpdate(S,{title:j.name?.replace(/\.md$/,"")||"",description:j.description||"",content:K,tags:j.tags||[],kind:j.kind,language:j.language,category:j.category}),se(),we()}catch(S){const K=ka(S)??ps(S);re(K??r("app.recipe.saveRecipeFailed"),{type:"error"})}finally{Fe(!1)}}},mn=async S=>{if(window.confirm(r("common.areYouSure")))try{await Q.deleteRecipe(S),we()}catch(K){const Y=ps(K);re(Y??r("common.deleteFailed"),{type:"error"})}},ua=async(S,K)=>{try{await Q.deleteCandidate(K),me(Y=>Y.filter(ie=>!(ie.candidateId===K&&ie.candidateTargetName===S))),i(Y=>{if(!Y?.candidates)return Y;const ie={...Y.candidates};if(ie[S]){const ve=ie[S].items.filter(Re=>Re.id!==K);ve.length===0?delete ie[S]:ie[S]={...ie[S],items:ve}}return{...Y,candidates:ie}})}catch{re(r("common.operationFailed"),{type:"error"})}},pn=async S=>{if(window.confirm(r("app.candidate.clearConfirm",{name:S})))try{await Q.deleteAllCandidatesInTarget(S),we(),re(r("app.candidate.clearDone",{name:S}))}catch{re(r("common.operationFailed"),{type:"error"})}},xn=async(S,K)=>{try{await Q.promoteToCandidate(S,S.candidateTargetName||w||"_review"),re(r("app.candidate.pushSuccess")),me(Y=>Y.filter((ie,ve)=>ve!==K)),we()}catch(Y){re(ke(Y,r("app.candidate.pushFailed")),{type:"error"})}},gn=(l?.recipes||[]).filter(S=>{if(M)return M.some(ve=>ve.metadata.type==="recipe"&&ve.metadata.name===S.name);const K=S.name||"",Y=typeof S.content=="string"?S.content:[S.content?.pattern,S.content?.markdown].filter(Boolean).join(" ");return K.toLowerCase().includes(g.toLowerCase())||Y.toLowerCase().includes(g.toLowerCase())||(S.description||"").toLowerCase().includes(g.toLowerCase())}).sort((S,K)=>{if(M){const ve=M.find(Pe=>Pe.metadata.name===S.name)?.similarity||0;return(M.find(Pe=>Pe.metadata.name===K.name)?.similarity||0)-ve}const Y=S.stats?.authorityScore??0;return(K.stats?.authorityScore??0)-Y}),ma=it.useMemo(()=>{const S=new Set(D.map(Y=>`${Y.discovererId||""}::${Y.name}`)),K=P.filter(Y=>!S.has(`${Y.discovererId||""}::${Y.name}`));return[...D,...K]},[D,P]),hn=ma.filter(S=>S.name.toLowerCase().includes(g.toLowerCase())).sort((S,K)=>{const Y=ts(S.name),ie=ts(K.name);if(Y&&!ie)return 1;if(!Y&&ie)return-1;const ve=S.isVirtual?1:0,Re=K.isVirtual?1:0;return ve!==Re?ve-Re:S.name.localeCompare(K.name)}),bn=n.useCallback(S=>{J(K=>{if(K.some(ie=>ie.path===S.path))return K;const Y=[...K,S];return l?.projectRoot&&localStorage.setItem(`asd:custom-folder-targets:${l.projectRoot}`,JSON.stringify(Y)),Y})},[l?.projectRoot]),fn=n.useCallback(S=>{J(K=>{const Y=K.filter(ie=>ie.path!==S);return l?.projectRoot&&localStorage.setItem(`asd:custom-folder-targets:${l.projectRoot}`,JSON.stringify(Y)),Y})},[l?.projectRoot]),As=Object.values(l?.candidates||{}).reduce((S,K)=>S+K.items.length,0);return e.jsx(md,{children:e.jsx(Co,{children:e.jsxs("div",{className:"flex h-screen bg-[var(--bg-root)] text-[var(--fg-primary)] overflow-hidden font-sans ambient-bg",children:[e.jsx(_n,{position:"top-center",toastOptions:{duration:5e3,style:{background:"none",padding:0,boxShadow:"none",border:"none"}},containerStyle:{top:24}}),e.jsx(ro,{activeTab:p,navigateToTab:he,candidateCount:As,signalSuggestionCount:V,currentUser:s.user!=="anonymous"?s.user:void 0,currentRole:s.role,permissionMode:s.mode,onLogout:void 0,projectName:l?.projectName}),e.jsxs("main",{className:"flex-1 flex flex-col overflow-hidden relative",children:[e.jsx(Lo,{setShowCreateModal:T,aiConfig:l?.aiConfig,llmReady:Me,onOpenLlmConfig:()=>f(!0),onBeforeAiSwitch:ne,onAiConfigChange:we,activeTab:p,onOpenCommandPalette:()=>u(!0),projectName:l?.projectName,candidateCount:As,showSignalMonitor:fe,onToggleSignalMonitor:()=>C(S=>!S)}),e.jsx("div",{className:`flex-1 ${p==="wiki"?"overflow-hidden":"overflow-y-auto p-4 xl:p-6 2xl:p-8"}`,children:e.jsx(Nl,{mode:"wait",children:e.jsx(kl.div,{initial:{opacity:0,y:8},animate:{opacity:1,y:0,transition:{duration:.2,ease:[.4,0,.2,1]}},exit:{opacity:0,transition:{duration:.15}},className:"h-full",children:m?e.jsx("div",{className:"flex items-center justify-center h-full",children:e.jsx("div",{className:"animate-spin rounded-full h-8 w-8 border-b-2 border-[var(--accent-emphasis)]"})}):p==="recipes"?e.jsx(Ci,{recipes:gn,openRecipeEdit:De,handleDeleteRecipe:mn,onRefresh:we,idTitleMap:l?.idTitleMap,currentPage:je,onPageChange:G,pageSize:le,onPageSizeChange:S=>{de(S),G(1)}}):p==="guard"?e.jsx(Wi,{onRefresh:we}):p==="panorama"?e.jsx(pc,{}):p==="skills"?e.jsx(Pc,{onRefresh:we,signalSuggestionCount:V,onSuggestionCountChange:xe}):p==="candidates"?e.jsxs(e.Fragment,{children:[a.session&&e.jsx("div",{className:"mb-4",children:e.jsx(Gc,{session:a.session,isAllDone:a.isAllDone,reviewState:a.reviewState,onDismiss:()=>a.resetSession(),onCancel:te,isCancelling:$})}),e.jsx(Fi,{data:l,isShellTarget:ts,isSilentTarget:Hl,isPendingTarget:Kl,handleDeleteCandidate:ua,onEditRecipe:De,onColdStart:nn,onRescan:ln,isScanning:z,isBootstrapping:a.session?.status==="running",onRefresh:we,onAuditCandidate:(S,K)=>{const Y=(S.content?.pattern||"").trim(),ie=!!Y&&(()=>{const ve=Y.split(`
111
111
  `).filter(Pe=>Pe.trim());return ve.filter(Pe=>/^\s*(#{1,6}\s|[-*>]\s|\d+\.\s)/.test(Pe)).length<=ve.length*.3})();me([{...S,mode:ie?"full":"preview",lang:"cn",includeHeaders:!0,difficulty:S.difficulty||S.complexity||"intermediate",authority:S.stats?.authority||3,candidateId:S.id,candidateTargetName:K}]),he("spm")},onAuditAllInTarget:(S,K)=>{me(S.map(Y=>{const ie=(Y.content?.pattern||"").trim(),ve=!!ie&&(()=>{const Re=ie.split(`
112
112
  `).filter(_e=>_e.trim());return Re.filter(_e=>/^\s*(#{1,6}\s|[-*>]\s|\d+\.\s)/.test(_e)).length<=Re.length*.3})();return{...Y,mode:ve?"full":"preview",lang:"cn",includeHeaders:!0,difficulty:Y.difficulty||Y.complexity||"intermediate",authority:Y.stats?.authority||3,candidateId:Y.id,candidateTargetName:K}})),he("spm")},handleDeleteAllInTarget:pn})]}):p==="knowledge"?e.jsx(Ec,{onRefresh:ct,idTitleMap:l?.idTitleMap}):p==="spm"?e.jsx(Hi,{targets:ma,filteredTargets:hn,selectedTargetName:w,isScanning:z,scanProgress:E,scanFileList:O,scanResults:q,guardAudit:v,handleScanTarget:rn,handleScanProject:on,handleUpdateScanResult:cn,handleSaveExtracted:dn,handlePromoteToCandidate:xn,handleDeleteCandidate:ua,onEditRecipe:De,isShellTarget:ts,recipes:l?.recipes??[],isSavingRecipe:Te,handleRefreshProject:ct,onAddCustomFolder:bn,onRemoveCustomFolder:fn}):p==="wiki"?e.jsx(Qc,{}):p==="signals"?e.jsx(rd,{}):p==="help"?e.jsx(Ri,{}):e.jsx(Cc,{})},p)})}),j&&e.jsx(ld,{editingRecipe:j,setEditingRecipe:A,handleSaveRecipe:un,closeRecipeEdit:se,isSavingRecipe:Te}),R&&e.jsx(od,{setShowCreateModal:T,createPath:X,setCreatePath:oe,handleCreateFromPath:nt,handleCreateFromClipboard:Ss,isExtracting:pe}),F&&e.jsx(cd,{searchQ:F.q,insertPath:F.path,onClose:()=>{Se(null),window.history.replaceState({},document.title,window.location.pathname)}}),ce&&e.jsx(dd,{onClose:()=>f(!1),onSaved:()=>{rt(),we()}}),e.jsx(ud,{open:fe,onClose:()=>C(!1)})]}),e.jsx(xd,{}),e.jsx($o,{open:h,onOpenChange:u,navigateToTab:he,setShowCreateModal:T,searchQuery:g,setSearchQuery:x,onOpenLlmConfig:()=>f(!0),candidateCount:As})]})})})},xd=()=>{const{isOpen:t}=Zt();return t?e.jsx(So,{}):null};zn.createRoot(document.getElementById("root")).render(e.jsx(it.StrictMode,{children:e.jsx(Tl,{children:e.jsx(Dl,{children:e.jsx(pd,{})})})}));