@geraldmaron/construct 1.0.7 → 1.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +20 -17
- package/bin/construct +1199 -69
- package/commands/work/optimize-prompts.md +1 -1
- package/db/schema/007_tags.sql +30 -0
- package/db/schema/008_skill_usage.sql +24 -0
- package/db/schema/009_scheduler.sql +14 -0
- package/examples/internal/roles/architect/bad/clever-plan-without-contracts.md +1 -1
- package/examples/internal/roles/architect/golden/explicit-tradeoff-before-plan.md +1 -1
- package/examples/internal/roles/engineer/bad/speculative-abstraction.md +1 -1
- package/examples/internal/roles/engineer/golden/read-before-write.md +1 -1
- package/examples/internal/roles/qa/bad/coverage-theater.md +1 -1
- package/examples/internal/roles/qa/golden/regression-gate.md +1 -1
- package/examples/seed-observations/decisions.md +1 -1
- package/lib/audit-skills.mjs +3 -3
- package/lib/auto-docs.mjs +2 -2
- package/lib/cli-commands.mjs +276 -122
- package/lib/comment-lint.mjs +5 -1
- package/lib/completions.mjs +1 -1
- package/lib/config/schema.mjs +15 -1
- package/lib/contracts/validate.mjs +65 -17
- package/lib/distill.mjs +22 -4
- package/lib/doc-stamp.mjs +48 -0
- package/lib/doctor/watchers/consistency.mjs +62 -12
- package/lib/document-extract.mjs +221 -28
- package/lib/document-ingest.mjs +2 -0
- package/lib/embed/inbox.mjs +48 -3
- package/lib/embed/role-framing.mjs +3 -3
- package/lib/env-config.mjs +9 -3
- package/lib/extractors/calendar.mjs +173 -0
- package/lib/extractors/shared/drop-info.mjs +22 -0
- package/lib/extractors/transcript.mjs +0 -0
- package/lib/gates-audit.mjs +8 -2
- package/lib/git-hooks/prepare-commit-msg +1 -1
- package/lib/headhunt.mjs +2 -2
- package/lib/hooks/agent-tracker.mjs +6 -11
- package/lib/hooks/guard-bash.mjs +35 -14
- package/lib/hooks/mcp-audit.mjs +12 -0
- package/lib/hooks/pre-compact.mjs +92 -5
- package/lib/hooks/pre-push-gate.mjs +41 -8
- package/lib/hooks/registry-sync.mjs +2 -2
- package/lib/hooks/stop-notify.mjs +7 -6
- package/lib/host-capabilities.mjs +10 -1
- package/lib/hygiene/scan.mjs +141 -0
- package/lib/init-unified.mjs +18 -0
- package/lib/install/stage-project.mjs +4 -4
- package/lib/intake/classify.mjs +222 -55
- package/lib/intake/filesystem-queue.mjs +25 -5
- package/lib/intake/postgres-queue.mjs +45 -3
- package/lib/intake/prepare.mjs +3 -0
- package/lib/intake/quarantine.mjs +205 -0
- package/lib/knowledge/postgres-search.mjs +132 -0
- package/lib/knowledge/search.mjs +14 -4
- package/lib/mcp/server.mjs +9 -3
- package/lib/mcp/tools/skills.mjs +32 -11
- package/lib/mcp/tools/workflow.mjs +1 -1
- package/lib/migrations/index.mjs +1 -1
- package/lib/model-registry.mjs +1 -1
- package/lib/opencode-runtime-plugin.mjs +1 -1
- package/lib/orchestration-policy.mjs +4 -4
- package/lib/overrides/resolver.mjs +3 -3
- package/lib/parity.mjs +4 -4
- package/lib/policy/engine.mjs +2 -2
- package/lib/profiles/lifecycle.mjs +1 -1
- package/lib/prompt-metadata.mjs +4 -4
- package/lib/providers/circuit-breaker.mjs +14 -0
- package/lib/providers/contract.mjs +67 -3
- package/lib/providers/creds.mjs +219 -0
- package/lib/providers/scaffold.mjs +107 -0
- package/lib/role-preload.mjs +5 -0
- package/lib/roles/catalog.mjs +1 -1
- package/lib/roles/manifest.mjs +2 -2
- package/lib/scheduler/index.mjs +112 -0
- package/lib/scheduler/solo.mjs +183 -0
- package/lib/server/index.mjs +7 -1
- package/lib/server/insights.mjs +14 -12
- package/lib/server/langfuse-login.mjs +58 -0
- package/lib/server/static/assets/index-ab25c707.js +1 -1
- package/lib/{agent-contracts-enforce.mjs → specialist-contracts-enforce.mjs} +4 -4
- package/lib/{agent-contracts.mjs → specialist-contracts.mjs} +9 -8
- package/lib/{agents → specialists}/postconditions.mjs +3 -3
- package/lib/{agents → specialists}/schema.mjs +6 -6
- package/lib/status.mjs +13 -11
- package/lib/storage/backup.mjs +2 -2
- package/lib/tags/lifecycle.mjs +278 -0
- package/lib/tags/vocabulary.mjs +140 -0
- package/lib/telemetry/otel-tracer.mjs +184 -0
- package/lib/telemetry/skill-calls.mjs +73 -12
- package/lib/uninstall/uninstall.mjs +1 -1
- package/lib/update.mjs +1 -1
- package/lib/validator.mjs +57 -56
- package/lib/workflows/instantiate.mjs +320 -0
- package/package.json +13 -3
- package/personas/construct.md +2 -2
- package/platforms/claude/CLAUDE.md +1 -1
- package/rules/common/no-fabrication.md +1 -1
- package/scripts/{sync-agents.mjs → sync-specialists.mjs} +126 -54
- package/skills/ai/prompt-optimizer.md +3 -3
- package/skills/exploration/dependency-graph-reading.md +98 -0
- package/skills/exploration/tracer-bullet-method.md +71 -0
- package/skills/exploration/unknown-codebase-onboarding.md +91 -0
- package/skills/operating/change-management.md +91 -0
- package/skills/operating/incident-response.md +75 -0
- package/skills/operating/oncall-rotation.md +95 -0
- package/skills/operating/orchestration-reference.md +2 -2
- package/skills/strategy/competitive-landscape.md +75 -0
- package/skills/strategy/market-research-methods.md +87 -0
- package/skills/strategy/narrative-arc.md +77 -0
- package/skills/strategy/pricing-positioning.md +94 -0
- package/{agents → specialists}/contracts.schema.json +1 -1
- package/specialists/policy-inventory.json +160 -0
- package/{agents → specialists}/prompts/cx-accessibility.md +1 -1
- package/{agents → specialists}/prompts/cx-ai-engineer.md +1 -1
- package/{agents → specialists}/prompts/cx-architect.md +1 -1
- package/{agents → specialists}/prompts/cx-business-strategist.md +1 -1
- package/{agents → specialists}/prompts/cx-data-analyst.md +1 -1
- package/{agents → specialists}/prompts/cx-data-engineer.md +1 -1
- package/{agents → specialists}/prompts/cx-debugger.md +1 -1
- package/{agents → specialists}/prompts/cx-designer.md +1 -1
- package/{agents → specialists}/prompts/cx-devil-advocate.md +1 -1
- package/{agents → specialists}/prompts/cx-docs-keeper.md +2 -2
- package/{agents → specialists}/prompts/cx-engineer.md +2 -2
- package/{agents → specialists}/prompts/cx-evaluator.md +1 -1
- package/{agents → specialists}/prompts/cx-explorer.md +1 -1
- package/{agents → specialists}/prompts/cx-legal-compliance.md +1 -1
- package/{agents → specialists}/prompts/cx-operations.md +1 -1
- package/{agents → specialists}/prompts/cx-orchestrator.md +2 -2
- package/{agents → specialists}/prompts/cx-platform-engineer.md +1 -1
- package/{agents → specialists}/prompts/cx-product-manager.md +1 -1
- package/{agents → specialists}/prompts/cx-qa.md +1 -1
- package/{agents → specialists}/prompts/cx-rd-lead.md +1 -1
- package/{agents → specialists}/prompts/cx-release-manager.md +1 -1
- package/{agents → specialists}/prompts/cx-researcher.md +1 -1
- package/{agents → specialists}/prompts/cx-reviewer.md +2 -2
- package/{agents → specialists}/prompts/cx-security.md +1 -1
- package/{agents → specialists}/prompts/cx-sre.md +2 -2
- package/{agents → specialists}/prompts/cx-test-automation.md +1 -1
- package/{agents → specialists}/prompts/cx-trace-reviewer.md +3 -3
- package/{agents → specialists}/prompts/cx-ux-researcher.md +1 -1
- package/{agents → specialists}/registry.json +651 -423
- package/{agents → specialists}/role-manifests.json +8 -8
- package/templates/provider-scaffold/health.test.mjs +30 -0
- package/templates/provider-scaffold/index.mjs +48 -0
- package/templates/workflows/cross-team-handoff.yml +85 -0
- package/templates/workflows/engineering-onboarding.yml +77 -0
- package/templates/workflows/new-feature.yml +53 -0
- /package/{agents → specialists}/contracts.json +0 -0
- /package/{agents → specialists}/teams.json +0 -0
|
@@ -64,7 +64,7 @@ Error generating stack: `+a.message+`
|
|
|
64
64
|
* LICENSE.md file in the root directory of this source tree.
|
|
65
65
|
*
|
|
66
66
|
* @license MIT
|
|
67
|
-
*/function Al(){return Al=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},Al.apply(this,arguments)}function Rp(e,t){if(e==null)return{};var n={},r=Object.keys(e),l,a;for(a=0;a<r.length;a++)l=r[a],!(t.indexOf(l)>=0)&&(n[l]=e[l]);return n}function lg(e){return!!(e.metaKey||e.altKey||e.ctrlKey||e.shiftKey)}function ag(e,t){return e.button===0&&(!t||t==="_self")&&!lg(e)}const ig=["onClick","relative","reloadDocument","replace","state","target","to","preventScrollReset","viewTransition"],sg=["aria-current","caseSensitive","className","end","style","to","viewTransition","children"],og="6";try{window.__reactRouterVersion=og}catch{}const cg=m.createContext({isTransitioning:!1}),ug="startTransition",Jc=tf[ug];function dg(e){let{basename:t,children:n,future:r,window:l}=e,a=m.useRef();a.current==null&&(a.current=mh({window:l,v5Compat:!0}));let s=a.current,[o,c]=m.useState({action:s.action,location:s.location}),{v7_startTransition:p}=r||{},f=m.useCallback(x=>{p&&Jc?Jc(()=>c(x)):c(x)},[c,p]);return m.useLayoutEffect(()=>s.listen(f),[s,f]),m.useEffect(()=>tg(r),[r]),m.createElement(ng,{basename:t,children:n,location:o.location,navigationType:o.action,navigator:s,future:r})}const pg=typeof window<"u"&&typeof window.document<"u"&&typeof window.document.createElement<"u",fg=/^(?:[a-z][a-z0-9+.-]*:|\/\/)/i,mg=m.forwardRef(function(t,n){let{onClick:r,relative:l,reloadDocument:a,replace:s,state:o,target:c,to:p,preventScrollReset:f,viewTransition:x}=t,v=Rp(t,ig),{basename:y}=m.useContext(Ht),w,b=!1;if(typeof p=="string"&&fg.test(p)&&(w=p,pg))try{let h=new URL(window.location.href),N=p.startsWith("//")?new URL(h.protocol+p):new URL(p),S=Dn(N.pathname,y);N.origin===h.origin&&S!=null?p=S+N.search+N.hash:b=!0}catch{}let C=Ah(p,{relative:l}),g=xg(p,{replace:s,state:o,target:c,preventScrollReset:f,relative:l,viewTransition:x});function d(h){r&&r(h),h.defaultPrevented||g(h)}return m.createElement("a",Al({},v,{href:w||C,onClick:b||a?r:d,ref:n,target:c}))}),hg=m.forwardRef(function(t,n){let{"aria-current":r="page",caseSensitive:l=!1,className:a="",end:s=!1,style:o,to:c,viewTransition:p,children:f}=t,x=Rp(t,sg),v=ia(c,{relative:x.relative}),y=Mr(),w=m.useContext(Sp),{navigator:b,basename:C}=m.useContext(Ht),g=w!=null&&vg(v)&&p===!0,d=b.encodeLocation?b.encodeLocation(v).pathname:v.pathname,h=y.pathname,N=w&&w.navigation&&w.navigation.location?w.navigation.location.pathname:null;l||(h=h.toLowerCase(),N=N?N.toLowerCase():null,d=d.toLowerCase()),N&&C&&(N=Dn(N,C)||N);const S=d!=="/"&&d.endsWith("/")?d.length-1:d.length;let L=h===d||!s&&h.startsWith(d)&&h.charAt(S)==="/",R=N!=null&&(N===d||!s&&N.startsWith(d)&&N.charAt(d.length)==="/"),k={isActive:L,isPending:R,isTransitioning:g},A=L?r:void 0,j;typeof a=="function"?j=a(k):j=[a,L?"active":null,R?"pending":null,g?"transitioning":null].filter(Boolean).join(" ");let D=typeof o=="function"?o(k):o;return m.createElement(mg,Al({},x,{"aria-current":A,className:j,ref:n,style:D,to:c,viewTransition:p}),typeof f=="function"?f(k):f)});var $i;(function(e){e.UseScrollRestoration="useScrollRestoration",e.UseSubmit="useSubmit",e.UseSubmitFetcher="useSubmitFetcher",e.UseFetcher="useFetcher",e.useViewTransitionState="useViewTransitionState"})($i||($i={}));var Gc;(function(e){e.UseFetcher="useFetcher",e.UseFetchers="useFetchers",e.UseScrollRestoration="useScrollRestoration"})(Gc||(Gc={}));function gg(e){let t=m.useContext(la);return t||se(!1),t}function xg(e,t){let{target:n,replace:r,state:l,preventScrollReset:a,relative:s,viewTransition:o}=t===void 0?{}:t,c=Pp(),p=Mr(),f=ia(e,{relative:s});return m.useCallback(x=>{if(ag(x,n)){x.preventDefault();let v=r!==void 0?r:jl(p)===jl(f);c(e,{replace:v,state:l,preventScrollReset:a,relative:s,viewTransition:o})}},[p,c,f,r,l,n,e,a,s,o])}function vg(e,t){t===void 0&&(t={});let n=m.useContext(cg);n==null&&se(!1);let{basename:r}=gg($i.useViewTransitionState),l=ia(e,{relative:t.relative});if(!n.isTransitioning)return!1;let a=Dn(n.currentLocation.pathname,r)||n.currentLocation.pathname,s=Dn(n.nextLocation.pathname,r)||n.nextLocation.pathname;return zl(l.pathname,s)!=null||zl(l.pathname,a)!=null}const Op="/api";function yg(){for(const e of document.cookie.split(";")){const[t,...n]=e.trim().split("=");if(t==="cx_csrf")return n.join("=")}return null}async function Z(e){const t=await fetch(`${Op}${e}`);if(!t.ok)throw new Error(`GET ${e}: ${t.status}`);return t.json()}async function Nt(e,t){return sa(e,t,"POST")}async function sa(e,t,n){const r={"Content-Type":"application/json"},l=yg();l&&(r["x-construct-csrf"]=l);const a=await fetch(`${Op}${e}`,{method:n,headers:r,body:JSON.stringify(t)});if(!a.ok){const s=await a.json().catch(()=>({}));throw new Error(s.error||`${n} ${e}: ${a.status}`)}return a.json()}const Fn=()=>Z("/status"),Ng=()=>Z("/auth/status"),Os=()=>Z("/registry"),wg=()=>Z("/approvals"),bg=()=>Z("/snapshots"),kg=()=>Z("/artifacts"),Sg=()=>Z("/mode"),Cg=()=>Z("/alias"),Mp=()=>Z("/insights"),Eg=()=>Z("/project-config"),Yc=e=>Z(`/overrides/${e}`),Xc=(e,t)=>Z(`/overrides/${e}/${t}`),Zc=(e,t)=>Z(`/overrides/${e}/${t}?action=backups`),Pg=(e,t,n)=>sa(`/overrides/${e}/${t}`,{content:n},"PUT"),_g=(e,t,n)=>sa(`/overrides/${e}/${t}?action=restore`,{backupFilename:n},"POST"),Lg=e=>sa("/project-config",e,"PUT"),Tg=()=>Z("/knowledge/trends"),Rg=()=>Z("/knowledge/index"),Og=e=>Nt("/knowledge/ask",{question:e}),Mg=()=>Z("/terraform/files"),Ig=()=>Z("/models/providers"),Dg=e=>Z(`/models/pricing?ids=${encodeURIComponent(e.filter(Boolean).join(","))}`),$g=()=>Nt("/models/free/apply",{}),jg=()=>Z("/intake/config"),zg=e=>Z(`/fs/browse${e?`?path=${encodeURIComponent(e)}`:""}`),Fg=e=>Nt("/intake/config",e),qc=()=>Z("/providers/credentials"),Ag=()=>Z("/providers/config-path"),eu=()=>Z("/providers/credentials/custom"),Ug=e=>Nt("/providers/credentials/custom",{action:"save",...e}),Bg=e=>Nt("/providers/credentials/custom",{action:"delete",provider:e}),Vg=()=>Z("/providers/credentials/op-status"),Wg=(e,t)=>Nt("/providers/credentials/op-pull",{envVar:e,opRef:t}),Hg=()=>Z("/providers/billing"),Qg=(e,t)=>Nt("/providers/billing",{provider:e,billingMode:t}),Kg=(e,t,n)=>Nt("/registry/models",{tier:e,primary:t,fallback:n}),tu=(e,t)=>Nt("/providers/credentials",{envVar:e,value:t}),Jg=()=>Z("/beads");function Ve({children:e,text:t}){return i("span",{title:t,className:"cursor-help inline-flex items-center gap-1 underline decoration-dotted decoration-text-dim underline-offset-2","aria-label":t,children:e})}function $a(e){switch(e){case"healthy":case"ok":case"configured":return"pip pip-healthy";case"degraded":case"warning":return"pip pip-degraded";case"down":case"unavailable":case"error":case"not-configured":return"pip pip-down";default:return"pip"}}function ja(e){switch(e){case"healthy":case"ok":case"configured":return"✓";case"degraded":case"warning":return"!";case"down":case"unavailable":case"error":case"not-configured":return"✕";default:return"·"}}function Gg({trend:e}){var r;if(!e||e.state!=="ok"||!((r=e.series)!=null&&r.length))return i("p",{className:"text-xs text-text-dim",children:(e==null?void 0:e.state)==="misconfigured"?e.message:(e==null?void 0:e.state)==="empty"?"No telemetry traces in the last 7 days.":"Cost trend unavailable."});const t=Math.max(...e.series.map(l=>l.costUsd),1e-4),n=e.series;return u("div",{children:[i("div",{className:"flex items-end gap-1.5 h-32",children:n.map(l=>{const a=t>0?l.costUsd/t*100:0;return i("div",{className:"flex-1 flex flex-col items-center justify-end h-full",title:`${l.day}: $${l.costUsd.toFixed(4)} · ${l.traces} traces${l.errors?` · ${l.errors} errors`:""}`,children:i("div",{style:{width:"100%",height:`${Math.max(2,a)}%`,background:l.errors>0?"var(--status-degraded)":"var(--aurora-gradient)",borderRadius:"4px 4px 0 0",opacity:l.traces===0?.25:1}})},l.day)})}),i("div",{className:"flex justify-between text-[10px] text-text-dim mt-2 font-mono",children:n.map(l=>i("span",{className:"flex-1 text-center",children:l.day.slice(-5)},l.day))})]})}function Yg({ratio:e,dangerOver:t=1,warnOver:n=.8}){const r=Math.max(0,Math.min(2,e));return i("div",{className:"h-1.5 w-full bg-bg-muted rounded mt-2",children:i("div",{className:"h-full rounded transition-all",style:{width:`${Math.min(100,r*100)}%`,background:r>t?"var(--status-down)":r>n?"var(--status-degraded)":"var(--aurora-gradient)"}})})}function Xg(){var j,D,O,H,B,fe,$e,Le,M,F,U,K,G,P,z,V,T,E,Y,Ir,An,me,Ye,wt,Is,Ds,$s,js,zs,Fs,As,Us,Bs,Vs,Ws,Hs,Qs,Ks,Js,Gs,Ys,Xs,Zs,qs,eo,to,no,ro,lo,ao,io,so,oo,co,uo,po,fo,mo,ho,go,xo,vo,yo,No,wo,bo,ko,So,Co,Eo,Po,_o,Lo,To,Ro,Oo;const[e,t]=m.useState(null),[n,r]=m.useState(null),[l,a]=m.useState(null),[s,o]=m.useState(null),[c,p]=m.useState(!0),[f,x]=m.useState(null);if(m.useEffect(()=>{const I=()=>Promise.all([Fn().then(t).catch(()=>{}),Ng().then(r).catch(()=>{}),Mp().then(a).catch(()=>{}),Os().then(o).catch(()=>{})]).catch(lt=>x((lt==null?void 0:lt.message)||"Failed to fetch status")).finally(()=>p(!1));I();const ce=window.setInterval(I,1e4),ne=()=>{document.visibilityState==="visible"&&I()};return document.addEventListener("visibilitychange",ne),window.addEventListener("focus",ne),()=>{window.clearInterval(ce),document.removeEventListener("visibilitychange",ne),window.removeEventListener("focus",ne)}},[]),c)return i("p",{className:"text-text-dim text-sm",children:"Loading system snapshot…"});if(f)return u("section",{className:"card max-w-2xl",children:[i("h1",{className:"text-lg font-semibold mb-2",children:"Mission Control unavailable"}),i("p",{className:"text-text-muted text-sm mb-4",children:f}),u("p",{className:"text-text-dim text-xs",children:["Try ",i("code",{className:"px-1 py-0.5 bg-bg-muted rounded",children:"construct doctor"})," to identify the cause."]})]});if(!e)return null;const v=((D=(j=e.system)==null?void 0:j.overall)==null?void 0:D.status)||"unknown",y=((H=(O=l==null?void 0:l.beads)==null?void 0:O.byStatus)==null?void 0:H.open)||0,w=((fe=(B=l==null?void 0:l.beads)==null?void 0:B.byStatus)==null?void 0:fe.in_progress)||0;((Le=($e=l==null?void 0:l.cost)==null?void 0:$e.budget)==null?void 0:Le.todayActualUsd)??((F=(M=l==null?void 0:l.cost)==null?void 0:M.budget)==null||F.todayUsd),((K=(U=l==null?void 0:l.cost)==null?void 0:U.budget)==null?void 0:K.todayMeteredEquivalentUsd)??((P=(G=l==null?void 0:l.cost)==null?void 0:G.budget)==null||P.todayUsd),(V=(z=l==null?void 0:l.cost)==null?void 0:z.budget)==null||V.capUsd,(E=(T=l==null?void 0:l.cost)==null?void 0:T.budget)==null||E.usageRatio;const b=((Y=l==null?void 0:l.cost)==null?void 0:Y.billingMode)||"subscription";(Ir=l==null?void 0:l.cost)!=null&&Ir.billingSource;const C=((An=l==null?void 0:l.cost)==null?void 0:An.providerBilling)||{};Object.keys(C).length>0&&Object.values(C).every(I=>(I==null?void 0:I.billingMode)==="subscription");const d=((me=l==null?void 0:l.resources)==null?void 0:me.totalCxUsageRatio)??0,h=(((Ye=l==null?void 0:l.resources)==null?void 0:Ye.totalCxBytes)??0)/1024/1024,N=(((wt=l==null?void 0:l.resources)==null?void 0:wt.totalCxCap)??0)/1024/1024,S=((Is=e.system)==null?void 0:Is.services)??[],L=S.filter(I=>I.status==="healthy").length,R=["reasoning","standard","fast"].map(I=>{var ce,ne;return(ne=(ce=s==null?void 0:s.models)==null?void 0:ce[I])==null?void 0:ne.primary}).filter(I=>typeof I=="string"&&I.length>0),k=[{key:"model",label:`Pick a model per tier (${R.length} of 3 set)`,done:R.length===3,href:"#/models",hint:"Construct ships with no default — choose reasoning / standard / fast. Auto-pick from free OpenRouter models is one click away."},{key:"provider",label:"Configure at least one provider",done:((l==null?void 0:l.providers)??[]).some(I=>I.state==="configured"),href:"#/providers",hint:"Set an API key (Anthropic / OpenAI / OpenRouter / Ollama) so the picked models can run."}],A=k.filter(I=>!I.done);return u("div",{className:"max-w-7xl space-y-6",children:[u("header",{children:[i("p",{className:"text-text-dim text-xs uppercase tracking-wider mb-1",children:"Page"}),i("h1",{className:"text-2xl sm:text-3xl font-semibold tracking-tight",children:"Mission Control"}),u("p",{className:"text-text-muted text-sm mt-1",children:["Live system snapshot · refreshes every 10s · ",e.version??"—",e.lastSync&&u(Ce,{children:[" · last sync ",new Date(e.lastSync).toLocaleTimeString()]})]})]}),A.length>0&&u("section",{className:"card border border-amber-300 bg-amber-50/40","aria-labelledby":"getting-started-heading",children:[u("h2",{id:"getting-started-heading",className:"text-xs uppercase tracking-wider text-text-dim mb-3",children:["Getting started — ",k.filter(I=>I.done).length," of ",k.length," complete"]}),i("ul",{className:"space-y-2",children:k.map(I=>u("li",{className:"flex items-start gap-3 text-sm",children:[i("span",{"aria-hidden":"true",className:I.done?"text-green-700":"text-amber-700",children:I.done?"✓":"○"}),u("div",{className:"flex-1 min-w-0",children:[u("div",{className:"flex flex-wrap items-baseline gap-x-2 gap-y-0.5",children:[i("span",{className:I.done?"line-through text-text-dim":"font-medium",children:I.label}),!I.done&&i("a",{href:I.href,className:"text-xs underline hover:no-underline text-indigo-700",children:"Fix here →"})]}),i("p",{className:"text-xs text-text-dim",children:I.hint})]})]},I.key))})]}),u("section",{className:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-4","aria-labelledby":"hero-heading",children:[i("h2",{id:"hero-heading",className:"sr-only",children:"Primary signals"}),u("article",{className:"card",children:[i("p",{className:"text-xs uppercase tracking-wider text-text-dim mb-3",children:i(Ve,{text:"Count of running local services (Dashboard, Memory, OpenCode) that are responding to health probes.",children:"System health"})}),i("div",{className:"flex items-baseline gap-3",children:u("span",{className:$a(v),style:{fontSize:"0.9rem"},children:[i("span",{"aria-hidden":"true",children:ja(v)}),v]})}),u("p",{className:"text-3xl font-semibold mt-3",children:[L,u("span",{className:"text-base text-text-dim font-normal",children:["/",S.length]})]}),i("p",{className:"text-xs text-text-muted mt-1",children:"core surfaces reachable"}),(($s=(Ds=e.system)==null?void 0:Ds.overall)==null?void 0:$s.summary)&&i("p",{className:"text-xs text-text-dim mt-2",children:e.system.overall.summary})]}),u("article",{className:"card",children:[i("p",{className:"text-xs uppercase tracking-wider text-text-dim mb-3",children:i(Ve,{text:"Total LLM token usage across all agent sessions. 'Billed' includes cache reads (96.4%) at ~10% cost — the raw number looks large but the actual compute is modest. Provider total is the raw tokens sent to the API before cache discounts.",children:"Token usage"})}),u("p",{className:"text-3xl font-semibold",children:[(((js=l==null?void 0:l.sessionUsage)==null?void 0:js.billedTotalTokens)??0)>1e6?(l.sessionUsage.billedTotalTokens/1e6).toFixed(0)+"M":(l.sessionUsage.billedTotalTokens??0).toLocaleString(),i("span",{className:"text-xs text-text-dim font-normal ml-1",children:"billed"})]}),u("p",{className:"text-xs text-text-muted mt-1",children:[((zs=l==null?void 0:l.sessionUsage)==null?void 0:zs.interactions)??0," interactions ·"," ",(((Fs=l==null?void 0:l.sessionUsage)==null?void 0:Fs.providerTotalTokens)??0).toLocaleString()," raw"]}),u("p",{className:"text-xs text-text-dim mt-2",children:[(((As=l==null?void 0:l.sessionUsage)==null?void 0:As.cacheReadInputTokens)??0).toLocaleString()," cache rd ·"," ",(((Us=l==null?void 0:l.sessionUsage)==null?void 0:Us.cacheCreationInputTokens)??0).toLocaleString()," cache wr ·"," ",(((Bs=l==null?void 0:l.sessionUsage)==null?void 0:Bs.outputTokens)??0).toLocaleString()," out"]})]}),u("article",{className:"card",children:[i("p",{className:"text-xs uppercase tracking-wider text-text-dim mb-3",children:i(Ve,{text:"Share of input tokens served from prompt cache. Higher is better — cache reads reduce latency and increase throughput. The billed total includes cache at a fraction of the cost.",children:"Cache efficiency"})}),u("p",{className:"text-3xl font-semibold",style:{color:"var(--status-healthy)"},children:[Math.round((((Hs=(Ws=(Vs=l==null?void 0:l.cost)==null?void 0:Vs.windows)==null?void 0:Ws.last7d)==null?void 0:Hs.cacheHitRate)??((Qs=l==null?void 0:l.sessionUsage)==null?void 0:Qs.cacheHitRate)??0)*100),i("span",{className:"text-xs text-text-dim font-normal ml-1",children:"% hit"})]}),u("p",{className:"text-xs text-text-muted mt-1",children:[((Js=(Ks=l==null?void 0:l.sessionUsage)==null?void 0:Ks.cacheReadInputTokens)==null?void 0:Js.toLocaleString())??0," tokens served from cache"]}),i("p",{className:"text-xs text-text-dim mt-2",children:(((Gs=l==null?void 0:l.sessionUsage)==null?void 0:Gs.cacheReadInputTokens)??0)>0?u(Ce,{children:[(l.sessionUsage.cacheReadInputTokens/(l.sessionUsage.billedTotalTokens||1)*100).toFixed(1),"% of all tokens ·"," ",(l.sessionUsage.cacheCreationInputTokens/(l.sessionUsage.billedTotalTokens||1)*100).toFixed(1),"% write overhead"]}):"No cache data yet."})]}),u("article",{className:"card",children:[i("p",{className:"text-xs uppercase tracking-wider text-text-dim mb-3",children:i(Ve,{text:"Beads (issues) currently open, in progress, or closed in the project's bd tracker. P0–P3 are priority tiers; lower is more urgent.",children:"Active work"})}),u("p",{className:"text-3xl font-semibold",children:[y,i("span",{className:"text-base text-text-dim font-normal ml-1",children:"open"})]}),u("p",{className:"text-xs text-text-muted mt-1",children:[w," in progress · ",((Xs=(Ys=l==null?void 0:l.beads)==null?void 0:Ys.byStatus)==null?void 0:Xs.closed)??0," closed"]}),i("div",{className:"flex gap-2 mt-3 text-xs",children:["P0","P1","P2","P3"].map(I=>{var ne,lt;const ce=((lt=(ne=l==null?void 0:l.beads)==null?void 0:ne.byPriority)==null?void 0:lt[I])??0;return ce?u("span",{className:"px-1.5 py-0.5 rounded bg-bg-muted font-mono",title:`Priority ${I.slice(1)}: ${ce} issues. P0=critical, P1=high, P2=medium, P3=low.`,children:[I,":",ce]},I):null})})]})]}),u("section",{className:"grid grid-cols-1 lg:grid-cols-3 gap-4",children:[u("article",{className:"card lg:col-span-2","aria-labelledby":"cost-trend-heading",children:[u("header",{className:"flex items-baseline justify-between mb-3",children:[i("h2",{id:"cost-trend-heading",className:"text-xs uppercase tracking-wider text-text-dim",children:i(Ve,{text:"Daily LLM spend over the last 7 days, pulled from telemetry traces in this project. Bars turn amber on days with at least one errored trace. Empty / dim bars mean no traces that day.",children:"Cost trend (7d)"})}),i("span",{className:"text-xs text-text-dim",children:((Zs=l==null?void 0:l.costTrend)==null?void 0:Zs.state)==="ok"?`${l.costTrend.sampleSize} traces · ${l.costTrend.withCost} priced`:null})]}),i(Gg,{trend:l==null?void 0:l.costTrend})]}),u("article",{className:"card","aria-labelledby":"services-strip-heading",children:[i("h2",{id:"services-strip-heading",className:"text-xs uppercase tracking-wider text-text-dim mb-3",children:"Services"}),S.length===0?u("p",{className:"text-xs text-text-muted",children:["No services reported. Run ",i("code",{className:"px-1 py-0.5 bg-bg-muted rounded",children:"construct up"}),"."]}):i("ul",{className:"space-y-2",children:S.map((I,ce)=>u("li",{className:"flex items-center justify-between gap-3 text-sm",children:[u("div",{className:"min-w-0",children:[i("div",{className:"font-medium truncate",children:I.name}),I.note&&i("div",{className:"text-xs text-text-dim truncate",children:I.note})]}),u("div",{className:"flex items-center gap-2 flex-shrink-0",children:[u("span",{className:$a(I.status),children:[i("span",{"aria-hidden":"true",children:ja(I.status)}),I.status]}),I.url&&i("a",{href:I.url,target:"_blank",rel:"noreferrer",className:"text-xs text-text-dim hover:text-text","aria-label":`open ${I.name}`,children:"↗"})]})]},ce))})]})]}),u("section",{"aria-labelledby":"token-efficiency-heading",className:"grid grid-cols-1 lg:grid-cols-3 gap-4",children:[i("h2",{id:"token-efficiency-heading",className:"sr-only",children:"Token efficiency"}),u("article",{className:"card",children:[i("p",{className:"text-xs uppercase tracking-wider text-text-dim mb-2",children:i(Ve,{text:"How much of your token throughput is served from Anthropic's prompt cache. Cache reads count toward your billed total at ~10% of the cost of fresh input. Higher is better — means your system prompts and context are being reused efficiently.",children:"Cache efficiency (7d)"})}),u("p",{className:"text-2xl font-semibold",style:{color:"var(--status-healthy)"},children:[Math.round((((to=(eo=(qs=l==null?void 0:l.cost)==null?void 0:qs.windows)==null?void 0:eo.last7d)==null?void 0:to.cacheHitRate)??0)*100),i("span",{className:"text-xs text-text-dim font-normal ml-1",children:"% cache hit"})]}),(((ro=(no=l==null?void 0:l.cost)==null?void 0:no.tokenMix)==null?void 0:ro.cacheRead)??0)>0&&u("p",{className:"text-xs text-text-muted mt-1",children:[(l.cost.tokenMix.cacheRead/1e6).toFixed(1),"M cached input · ",(l.cost.tokenMix.cacheCreation/1e6).toFixed(2),"M write overhead"]}),!(((ao=(lo=l==null?void 0:l.cost)==null?void 0:lo.tokenMix)==null?void 0:ao.cacheRead)??0)>0&&i("p",{className:"text-xs text-text-muted mt-1",children:"No token usage yet."})]}),u("article",{className:"card lg:col-span-2",children:[i("p",{className:"text-xs uppercase tracking-wider text-text-dim mb-3",children:i(Ve,{text:"Stacked bar of token usage over the last 7 days. Cache-read = served from prompt cache (cheap). Cache-write = first-time-stored to cache (slight premium). Input = uncached input. Output = generated tokens. Reasoning = extended-thinking tokens (priced like output).",children:"Token mix (7d)"})}),((so=(io=l==null?void 0:l.cost)==null?void 0:io.tokenMix)==null?void 0:so.total)>0?u(Ce,{children:[i("div",{className:"flex h-3 rounded overflow-hidden border border-border",children:(()=>{const I=l.cost.tokenMix;return[{key:"cacheRead",label:"Cache read",value:I.cacheRead,color:"var(--aurora-cyan)"},{key:"cacheCreation",label:"Cache write",value:I.cacheCreation,color:"var(--aurora-violet)"},{key:"input",label:"Input",value:I.input,color:"var(--aurora-mint)"},{key:"output",label:"Output",value:I.output,color:"var(--aurora-pink)"},{key:"reasoning",label:"Reasoning",value:I.reasoning,color:"var(--ink-500)"}].filter(ne=>ne.value>0).map(ne=>i("div",{style:{width:`${ne.value/I.total*100}%`,background:ne.color},title:`${ne.label}: ${ne.value.toLocaleString()} (${(ne.value/I.total*100).toFixed(1)}%)`},ne.key))})()}),i("div",{className:"grid grid-cols-2 md:grid-cols-5 gap-3 mt-3 text-xs",children:["cacheRead","cacheCreation","input","output","reasoning"].map(I=>{const ce=l.cost.tokenMix;if(!ce[I])return null;const ne={cacheRead:"var(--aurora-cyan)",cacheCreation:"var(--aurora-violet)",input:"var(--aurora-mint)",output:"var(--aurora-pink)",reasoning:"var(--ink-500)"},lt={cacheRead:"Cache read",cacheCreation:"Cache write",input:"Input",output:"Output",reasoning:"Reasoning"};return u("div",{className:"flex items-start gap-2",children:[i("span",{className:"w-2 h-2 rounded-full mt-1 flex-shrink-0",style:{background:ne[I]},"aria-hidden":"true"}),u("div",{className:"min-w-0",children:[i("div",{className:"text-text-dim text-[10px] uppercase tracking-wider",children:lt[I]}),i("div",{className:"font-mono",children:ce[I].toLocaleString()}),u("div",{className:"text-text-dim text-[10px]",children:[(ce[I]/ce.total*100).toFixed(1),"%"]})]})]},I)})})]}):i("p",{className:"text-xs text-text-muted",children:"No token usage yet."})]})]}),u("section",{"aria-labelledby":"obs-heading",children:[i("h2",{id:"obs-heading",className:"text-xs uppercase tracking-wider text-text-dim mb-3",children:i(Ve,{text:"LLM behavior metrics from telemetry traces. Each card answers a different question about how the agent is performing.",children:"Observability (last 7d)"})}),i("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-5 gap-4",children:u("article",{className:"card",children:[i("p",{className:"text-xs uppercase tracking-wider text-text-dim mb-2",children:i(Ve,{text:"Recall@5: of the documents that *should* have been retrieved for each fixture query, what share appeared in the top 5 returned results. 100% = the right doc is always in the top 5. MRR is mean reciprocal rank — 1.0 means the right doc is always first. Run `construct evals retrieval` to refresh.",children:"Retrieval recall@5"})}),((oo=l==null?void 0:l.retrievalEval)==null?void 0:oo.state)==="ok"?u(Ce,{children:[u("p",{className:"text-xl font-semibold",children:[((l.retrievalEval.recallAt5??0)*100).toFixed(0),i("span",{className:"text-xs text-text-dim font-normal ml-1",children:"%"})]}),u("p",{className:"text-xs text-text-muted mt-1",children:["MRR ",(l.retrievalEval.mrr??0).toFixed(2)," · p95 ",Math.round(l.retrievalEval.p95LatencyMs||0),"ms"]}),u("p",{className:"text-xs text-text-dim mt-2",children:[l.retrievalEval.queryCount," queries · ",new Date(l.retrievalEval.ranAt).toLocaleDateString()]}),((co=l.retrievalEval.history)==null?void 0:co.length)>1&&i("svg",{viewBox:"0 0 60 16",className:"w-full h-4 mt-2",preserveAspectRatio:"none","aria-label":"recall@5 history",children:(()=>{const I=l.retrievalEval.history,ce=I.map((ne,lt)=>{const $p=lt/Math.max(1,I.length-1)*60,jp=16-Number(ne.recallAt5??0)*16;return`${$p.toFixed(1)},${jp.toFixed(1)}`}).join(" ");return i("polyline",{points:ce,fill:"none",stroke:"var(--aurora-cyan)",strokeWidth:"1.2"})})()})]}):u("p",{className:"text-xs text-text-muted",children:["Run ",i("code",{className:"bg-bg-muted px-1 rounded",children:"construct evals retrieval"})]})]})})]}),u("section",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-4","aria-labelledby":"secondary-heading",children:[i("h2",{id:"secondary-heading",className:"sr-only",children:"Resources and queues"}),u("article",{className:"card",children:[i("p",{className:"text-xs uppercase tracking-wider text-text-dim mb-2",children:".cx/ disk"}),u("p",{className:"text-xl font-semibold",children:[h.toFixed(1),i("span",{className:"text-xs text-text-dim font-normal ml-1",children:"MB"})]}),u("p",{className:"text-xs text-text-muted",children:["/ ",N.toFixed(0),"MB cap"]}),i(Yg,{ratio:d})]}),u("article",{className:"card",children:[i("p",{className:"text-xs uppercase tracking-wider text-text-dim mb-2",children:"Handoffs"}),((uo=l==null?void 0:l.handoffs)==null?void 0:uo.state)==="ok"?u(Ce,{children:[i("p",{className:"text-xl font-semibold",children:l.handoffs.total}),u("p",{className:"text-xs text-text-muted",children:["oldest ",(po=l.handoffs.oldestAgeDays)==null?void 0:po.toFixed(0),"d / ",l.handoffs.maxDays,"d"]}),l.handoffs.pastRetentionCount>0&&u("p",{className:"text-xs mt-2",style:{color:"var(--status-degraded)"},children:[l.handoffs.pastRetentionCount," past retention"]})]}):i("p",{className:"text-xs text-text-muted",children:"empty"})]}),u("article",{className:"card",children:[i("p",{className:"text-xs uppercase tracking-wider text-text-dim mb-2",children:i(Ve,{text:"R&D intake pipeline: files dropped in .cx/inbox/ are auto-ingested, triaged, and queued. Processed = marked done via `construct intake done`. Skipped = intentionally bypassed. Customer-linked = items auto-matched to customer profiles via name/domain detection.",children:"Intake queue"})}),((fo=l==null?void 0:l.intake)==null?void 0:fo.state)==="ok"?u(Ce,{children:[i("p",{className:"text-xl font-semibold",children:l.intake.pending}),i("p",{className:"text-xs text-text-muted",children:"pending"}),u("p",{className:"text-xs text-text-dim mt-1",children:["processed ",l.intake.processed," · skipped ",l.intake.skipped]}),l.intake.customerLinked>0&&u("p",{className:"text-xs text-cyan-700 mt-1",children:[l.intake.customerLinked," customer-linked"]})]}):u("p",{className:"text-xs text-text-muted",children:["empty · drop a file in ",i("code",{className:"bg-bg-muted px-1 rounded",children:".cx/inbox/"})]})]}),u("article",{className:"card",children:[i("p",{className:"text-xs uppercase tracking-wider text-text-dim mb-2",children:"Vector index"}),((mo=l==null?void 0:l.vector)==null?void 0:mo.state)==="ok"?u(Ce,{children:[i("p",{className:"text-xl font-semibold",children:((ho=l.vector.records)==null?void 0:ho.toLocaleString())??"—"}),u("p",{className:"text-xs text-text-muted",children:["records · ",(l.vector.bytes/1024).toFixed(1),"KB"]}),l.vector.model&&i("p",{className:"text-xs text-text-dim mt-1 font-mono truncate",children:l.vector.model})]}):i("p",{className:"text-xs text-text-muted",children:((go=l==null?void 0:l.vector)==null?void 0:go.message)||"No index yet. Run `construct ingest`."})]}),u("article",{className:"card",children:[i("p",{className:"text-xs uppercase tracking-wider text-text-dim mb-2",children:i(Ve,{text:"Artifact recommendations generated by the docs-lifecycle daemon job based on intake signal patterns, doc gaps, and snapshot analysis. P0 = urgent, P3 = nice-to-have. Run `construct recommendations list` for details.",children:"Recommendations"})}),((xo=l==null?void 0:l.recommendations)==null?void 0:xo.state)==="ok"&&l.recommendations.active>0?u(Ce,{children:[i("p",{className:"text-xl font-semibold",children:l.recommendations.active}),i("p",{className:"text-xs text-text-muted",children:"active"}),l.recommendations.byPriority&&Object.keys(l.recommendations.byPriority).length>0&&i("div",{className:"flex gap-2 mt-2 text-xs",children:Object.entries(l.recommendations.byPriority).map(([I,ce])=>u("span",{className:`px-1.5 py-0.5 rounded font-mono ${I==="P0"?"bg-red-100 text-red-800":I==="P1"?"bg-amber-100 text-amber-800":"bg-bg-muted text-text-dim"}`,children:[I,": ",ce]},I))}),u("p",{className:"text-xs text-text-dim mt-1",children:[l.recommendations.dismissed," dismissed · ",l.recommendations.total," total"]})]}):i("p",{className:"text-xs text-text-muted",children:((vo=l==null?void 0:l.recommendations)==null?void 0:vo.state)==="empty"?"No active recommendations.":"Loading…"})]})]}),u("section",{className:"card","aria-labelledby":"providers-heading",children:[u("header",{className:"flex items-baseline justify-between mb-3",children:[i("h2",{id:"providers-heading",className:"text-xs uppercase tracking-wider text-text-dim",children:"Model providers"}),i("a",{href:"#/providers",className:"text-xs text-text-dim hover:text-text",children:"manage ↗"})]}),i("div",{className:"grid grid-cols-2 md:grid-cols-4 lg:grid-cols-7 gap-3",children:((l==null?void 0:l.providers)??[]).map(I=>u("div",{className:"flex items-center gap-2 text-sm",children:[i("span",{className:$a(I.state),children:i("span",{"aria-hidden":"true",children:ja(I.state)})}),i("span",{className:"truncate",children:I.displayName})]},I.id))})]}),((yo=l==null?void 0:l.integrations)==null?void 0:yo.state)==="ok"&&u("section",{className:"card","aria-labelledby":"integrations-heading",children:[u("header",{className:"flex items-baseline justify-between mb-3",children:[i("h2",{id:"integrations-heading",className:"text-xs uppercase tracking-wider text-text-dim",children:i(Ve,{text:"External system integrations for intake packets. GitHub Issues uses gh CLI or GITHUB_TOKEN. Jira and Confluence need env vars in ~/.construct/config.env. Auth resolution checks process.env, .env files, config.env, shell rc files, and 1Password op:// refs.",children:"Integrations"})}),i("a",{href:"#/intake",className:"text-xs text-text-dim hover:text-text",children:"configure ↗"})]}),u("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-4 text-sm",children:[u("div",{className:"flex items-start gap-2",children:[i("span",{"aria-hidden":"true",className:((No=l.integrations.details)==null?void 0:No.github)!=="not configured"?"text-green-700":"text-text-dim",children:((wo=l.integrations.details)==null?void 0:wo.github)!=="not configured"?"✓":"○"}),u("div",{children:[i("p",{className:"font-medium",children:"GitHub Issues"}),i("p",{className:"text-xs text-text-muted",children:((bo=l.integrations.details)==null?void 0:bo.github)||"not configured"}),i("p",{className:"text-xs text-text-dim",children:"Creates issues from intake via gh CLI or API"})]})]}),u("div",{className:"flex items-start gap-2",children:[i("span",{"aria-hidden":"true",className:((ko=l.integrations.details)==null?void 0:ko.jira)!=="not configured"?"text-green-700":"text-text-dim",children:((So=l.integrations.details)==null?void 0:So.jira)!=="not configured"?"✓":"○"}),u("div",{children:[i("p",{className:"font-medium",children:"Jira"}),i("p",{className:"text-xs text-text-muted",children:((Co=l.integrations.details)==null?void 0:Co.jira)||"not configured"}),i("p",{className:"text-xs text-text-dim",children:"Set JIRA_HOST + JIRA_USER + JIRA_API_TOKEN + JIRA_PROJECT"})]})]}),u("div",{className:"flex items-start gap-2",children:[i("span",{"aria-hidden":"true",className:((Eo=l.integrations.details)==null?void 0:Eo.confluence)!=="not configured"?"text-green-700":"text-text-dim",children:((Po=l.integrations.details)==null?void 0:Po.confluence)!=="not configured"?"✓":"○"}),u("div",{children:[i("p",{className:"font-medium",children:"Confluence"}),i("p",{className:"text-xs text-text-muted",children:((_o=l.integrations.details)==null?void 0:_o.confluence)||"not configured"}),i("p",{className:"text-xs text-text-dim",children:"Set CONFLUENCE_HOST + USER + API_TOKEN + SPACE"})]})]})]}),i("p",{className:"text-xs text-text-dim mt-3",children:"Auth chain: env → ~/.env → ~/.construct/config.env → shell rc → 1Password op://. GitHub also checks gh CLI."})]}),u("section",{className:"card","aria-labelledby":"auth-heading",children:[i("h2",{id:"auth-heading",className:"text-xs uppercase tracking-wider text-text-dim mb-3",children:"Authentication"}),u("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-4 text-sm",children:[u("div",{children:[i("p",{className:"text-text-dim text-xs mb-1",children:"Mode"}),i("p",{children:((Lo=n==null?void 0:n.auth)==null?void 0:Lo.mode)??"token"})]}),u("div",{children:[i("p",{className:"text-text-dim text-xs mb-1",children:"Providers"}),i("p",{children:(Ro=(To=n==null?void 0:n.auth)==null?void 0:To.providers)!=null&&Ro.length?n.auth.providers.join(", "):"none"})]}),u("div",{children:[i("p",{className:"text-text-dim text-xs mb-1",children:"Token"}),i("p",{children:(Oo=n==null?void 0:n.auth)!=null&&Oo.tokenConfigured?"configured":"not configured"})]})]})]})]})}const Zg="/api";function qg(){const[e,t]=m.useState(null),[n,r]=m.useState(!0),[l,a]=m.useState(null),[s,o]=m.useState("plan");if(m.useEffect(()=>{fetch(`${Zg}/workflow`).then(f=>f.json()).then(f=>t(f)).catch(f=>a(f.message)).finally(()=>r(!1))},[]),n)return i("div",{className:"text-center py-20 text-gray-600",children:"Loading..."});if(l)return i("div",{className:"text-center py-20 text-red-500",children:l});if(!e)return i("div",{className:"text-center py-20 text-gray-600",children:"No workflow data available."});const c=e.taskStatusCounts??{},p=e.workflowState;return u("div",{children:[u("div",{className:"flex items-center justify-between mb-6",children:[i("h1",{className:"text-2xl font-bold",children:"Workflow"}),i("div",{className:"flex gap-1 bg-gray-100 rounded-lg p-1",children:["plan","tasks","phases"].map(f=>i("button",{onClick:()=>o(f),className:`px-3 py-1.5 text-sm font-medium rounded-md transition-colors ${s===f?"bg-white text-gray-900 shadow-sm":"text-gray-500 hover:text-gray-700"}`,children:f.charAt(0).toUpperCase()+f.slice(1)},f))})]}),i("div",{className:"grid grid-cols-2 md:grid-cols-5 gap-3 mb-6",children:[{label:"Pending",value:c.todo??0,color:"bg-gray-100 text-gray-700"},{label:"In Progress",value:c.inProgress??0,color:"bg-blue-100 text-blue-700"},{label:"Blocked",value:c.blocked??0,color:"bg-red-100 text-red-700"},{label:"Done",value:c.done??0,color:"bg-green-100 text-green-700"},{label:"Skipped",value:c.skipped??0,color:"bg-gray-100 text-gray-700"}].map(f=>u("div",{className:"bg-white border border-gray-200 rounded-xl p-4 text-center",children:[i("p",{className:"text-2xl font-bold",children:f.value}),i("p",{className:`text-xs font-medium mt-0.5 inline-block px-2 py-0.5 rounded-full ${f.color}`,children:f.label})]},f.label))}),s==="plan"&&u("div",{className:"bg-white border border-gray-200 rounded-xl p-6",children:[u("div",{className:"flex items-center justify-between mb-4",children:[i("p",{className:"text-sm font-semibold text-gray-500 uppercase tracking-wide",children:"Plan"}),e.hasPlan&&i("span",{className:"text-xs text-gray-600 font-mono",children:"plan.md"})]}),e.hasPlan?i("pre",{className:"text-sm text-gray-700 whitespace-pre-wrap font-sans leading-relaxed",children:e.planSummary||"No summary"}):i("p",{className:"text-gray-600",children:"No plan.md found."})]}),s==="tasks"&&p&&u("div",{className:"bg-white border border-gray-200 rounded-xl overflow-hidden",children:[i("div",{className:"px-6 py-3 border-b border-gray-100",children:u("p",{className:"text-sm font-semibold text-gray-500 uppercase tracking-wide",children:[e.taskCount," Tasks"]})}),(p.tasks??[]).length===0?i("div",{className:"p-6 text-center text-gray-600",children:"No tasks defined."}):i("div",{className:"divide-y divide-gray-50",children:(p.tasks??[]).map((f,x)=>{var y;const v=f.status==="done"?"bg-green-100 text-green-700":f.status==="in-progress"?"bg-blue-100 text-blue-700":(y=f.status)!=null&&y.startsWith("blocked")?"bg-red-100 text-red-700":(f.status==="skipped","bg-gray-100 text-gray-700");return u("div",{className:"px-6 py-4",children:[u("div",{className:"flex items-center justify-between mb-1",children:[i("p",{className:"font-medium text-sm",children:f.title||f.key||`Task ${x+1}`}),i("span",{className:`text-xs font-medium px-2 py-0.5 rounded-full ${v}`,children:f.status||"todo"})]}),f.phase&&i("p",{className:"text-xs text-gray-600 font-mono",children:f.phase})]},x)})})]}),s==="phases"&&p&&i("div",{className:"grid grid-cols-1 gap-3",children:Object.entries(p.phases??{}).map(([f,x])=>{const v=x.status==="done"?"bg-green-100 text-green-700":x.status==="in-progress"?"bg-blue-100 text-blue-700":"bg-gray-100 text-gray-700",y=f===p.phase;return u("div",{className:`bg-white border rounded-xl p-5 ${y?"border-indigo-300 ring-1 ring-indigo-100":"border-gray-200"}`,children:[u("div",{className:"flex items-center justify-between mb-2",children:[u("div",{className:"flex items-center gap-2",children:[i("p",{className:"font-semibold capitalize",children:f}),y&&i("span",{className:"text-xs text-indigo-600 font-medium",children:"current"})]}),i("span",{className:`text-xs font-medium px-2 py-0.5 rounded-full ${v}`,children:x.status||"todo"})]}),x.summary&&i("p",{className:"text-sm text-gray-500",children:x.summary})]},f)})})]})}function ex(){const[e,t]=m.useState([]),[n,r]=m.useState(!0),l=()=>wg().then(a=>t(a.items??[])).catch(()=>{}).finally(()=>r(!1));return m.useEffect(()=>{l()},[]),n?i("div",{className:"text-center py-20 text-gray-600",children:"Loading..."}):e.length?u("div",{children:[i("h1",{className:"text-2xl font-bold mb-6",children:"Approval Queue"}),i("div",{className:"grid grid-cols-1 gap-4",children:e.map((a,s)=>u("div",{className:"bg-white border border-gray-200 rounded-xl p-6",children:[i("p",{className:"text-xs text-gray-600 font-mono mb-1",children:a.id}),i("p",{className:"text-gray-700 mb-4",children:a.description||a.action||JSON.stringify(a)}),i("div",{className:"flex gap-3",children:i("span",{className:"bg-gray-100 text-gray-600 text-xs px-2 py-1 rounded-full",children:a.pattern??"standard"})})]},s))})]}):i("div",{className:"text-center py-20 text-gray-600",children:"No pending approvals."})}function tx(){const[e,t]=m.useState([]),[n,r]=m.useState(!0);return m.useEffect(()=>{bg().then(l=>t(l.snapshots??[])).catch(()=>{}).finally(()=>r(!1))},[]),n?i("div",{className:"text-center py-20 text-gray-600",children:"Loading..."}):e.length?u("div",{children:[i("h1",{className:"text-2xl font-bold mb-6",children:"Snapshots"}),i("div",{className:"grid grid-cols-1 gap-4",children:e.map((l,a)=>u("div",{className:"bg-white border border-gray-200 rounded-xl p-6",children:[u("div",{className:"flex items-center justify-between mb-3",children:[i("span",{className:"text-sm text-gray-500",children:l.capturedAt?new Date(l.capturedAt).toLocaleString():"—"}),l.providers&&i("span",{className:"text-xs text-gray-600",children:l.providers.join(", ")})]}),i("p",{className:"text-sm text-gray-700 whitespace-pre-wrap",children:l.summary??JSON.stringify(l).slice(0,300)})]},a))})]}):i("div",{className:"text-center py-20 text-gray-600",children:"No snapshots recorded yet."})}function nx(){const[e,t]=m.useState([]),[n,r]=m.useState([]),[l,a]=m.useState(!0);return m.useEffect(()=>{Fn().then(s=>{t(s.personas??[]),r(s.specialists??[])}).catch(()=>{}).finally(()=>a(!1))},[]),l?i("div",{className:"text-center py-20 text-gray-600",children:"Loading..."}):u("div",{children:[i("h1",{className:"text-2xl font-bold mb-6",children:"Agents"}),e.length>0&&u("div",{className:"mb-8",children:[i("h2",{className:"text-sm font-semibold text-gray-500 uppercase tracking-wide mb-3",children:"Entry Points"}),i("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:e.map((s,o)=>u("div",{className:"bg-white border border-gray-200 rounded-xl p-5",children:[i("p",{className:"font-semibold",children:s.name}),i("p",{className:"text-sm text-gray-500 mb-2",children:s.role}),i("p",{className:"text-sm text-gray-600",children:s.description})]},o))})]}),n.length>0&&u("div",{children:[i("h2",{className:"text-sm font-semibold text-gray-500 uppercase tracking-wide mb-3",children:"Specialists"}),i("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:n.map((s,o)=>u("div",{className:"bg-white border border-gray-200 rounded-xl p-5",children:[i("p",{className:"font-semibold",children:s.name}),i("p",{className:"text-sm text-gray-600",children:s.description})]},o))})]}),e.length===0&&n.length===0&&i("div",{className:"text-center py-20 text-gray-600",children:"No agents found."})]})}function rx(){const[e,t]=m.useState([]),[n,r]=m.useState(!0);return m.useEffect(()=>{Fn().then(l=>t(l.skills??[])).catch(()=>{}).finally(()=>r(!1))},[]),n?i("div",{className:"text-center py-20 text-gray-600",children:"Loading..."}):u("div",{children:[i("h1",{className:"text-2xl font-bold mb-6",children:"Skills"}),e.length===0?i("div",{className:"text-center py-20 text-gray-600",children:"No skills found."}):i("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:e.map((l,a)=>u("div",{className:"bg-white border border-gray-200 rounded-xl p-5",children:[i("p",{className:"font-semibold capitalize mb-2",children:l.category}),i("div",{className:"flex flex-wrap gap-1.5",children:(l.files??[]).map((s,o)=>i("span",{className:"bg-gray-100 text-gray-600 text-xs px-2 py-0.5 rounded-full",children:s.replace(/\.(md|mjs)$/,"").replace(/-/g," ")},o))})]},a))})]})}function oa({category:e,title:t,intro:n}){const[r,l]=m.useState([]),[a,s]=m.useState(null),[o,c]=m.useState(""),[p,f]=m.useState(""),[x,v]=m.useState("original"),[y,w]=m.useState([]),[b,C]=m.useState(null),[g,d]=m.useState(!1),[h,N]=m.useState(null),[S,L]=m.useState("");m.useEffect(()=>{Yc(e).then(D=>l(D.items)).catch(D=>C(D.message))},[e]),m.useEffect(()=>{a&&(C(null),N(null),Xc(e,a).then(D=>{c(D.content),f(D.content),v(D.source)}).catch(D=>C(D.message)),Zc(e,a).then(D=>w(D.backups)).catch(()=>w([])))},[a,e]);const R=o!==p,k=r.filter(D=>!S||D.name.toLowerCase().includes(S.toLowerCase()));async function A(){if(a){d(!0),C(null),N(null);try{const D=await Pg(e,a,o);N(`Saved (${D.wrote} bytes${D.backupPath?", backup created":""})`),f(o);const O=await Yc(e);l(O.items);const H=await Zc(e,a);w(H.backups)}catch(D){C(D.message)}finally{d(!1)}}}async function j(D){if(a){d(!0),C(null);try{await _g(e,a,D);const O=await Xc(e,a);c(O.content),f(O.content),N(`Restored from ${D}`)}catch(O){C(O.message)}finally{d(!1)}}}return u("div",{className:"max-w-6xl space-y-6",children:[u("header",{children:[i("p",{className:"text-text-dim text-xs uppercase tracking-wider mb-1",children:"Page"}),i("h1",{className:"text-3xl font-semibold tracking-tight",children:t}),i("p",{className:"text-text-muted text-sm mt-2",children:n})]}),b&&i("div",{className:"card",style:{borderColor:"var(--status-down)"},children:i("p",{className:"text-sm",children:b})}),u("div",{className:"grid grid-cols-1 lg:grid-cols-[260px_1fr] gap-6",children:[u("aside",{className:"space-y-3",children:[i("input",{type:"text",placeholder:"Filter…",value:S,onChange:D=>L(D.target.value),className:"w-full px-3 py-2 border border-border rounded bg-surface text-sm"}),u("ul",{className:"space-y-1 max-h-[60vh] overflow-y-auto",children:[k.map(D=>i("li",{children:u("button",{type:"button",onClick:()=>s(D.name),className:["w-full text-left px-3 py-1.5 rounded text-sm transition-colors flex items-center justify-between gap-2",a===D.name?"bg-bg-muted border-l-2 border-aurora-cyan":"hover:bg-bg-muted"].join(" "),children:[i("span",{className:"font-mono text-xs truncate",children:D.name}),D.hasOverride&&i("span",{className:"pip pip-healthy text-[10px]",children:"edited"})]})},D.name)),k.length===0&&i("li",{className:"text-xs text-text-dim px-3 py-2",children:"No items match."})]})]}),u("section",{className:"space-y-4",children:[!a&&i("div",{className:"card",children:i("p",{className:"text-sm text-text-muted",children:"Select an item on the left to view or edit."})}),a&&u(Ce,{children:[u("div",{className:"flex items-center justify-between flex-wrap gap-2",children:[u("div",{children:[i("h2",{className:"text-lg font-semibold font-mono",children:a}),u("p",{className:"text-xs text-text-dim mt-0.5",children:["source: ",i("span",{className:"font-mono",children:x})]})]}),u("div",{className:"flex items-center gap-2",children:[i("button",{type:"button",disabled:!R||g,onClick:A,className:"btn btn-primary disabled:opacity-50 disabled:cursor-not-allowed text-sm",children:g?"Saving…":"Save"}),i("button",{type:"button",disabled:!R||g,onClick:()=>c(p),className:"btn disabled:opacity-50 disabled:cursor-not-allowed text-sm",children:"Discard"})]})]}),h&&i("div",{className:"card text-sm",style:{borderColor:"var(--status-healthy)"},children:h}),i("textarea",{value:o,onChange:D=>c(D.target.value),className:"w-full h-[55vh] p-3 border border-border rounded bg-surface font-mono text-xs leading-relaxed",spellCheck:!1}),y.length>0&&u("section",{className:"card",children:[u("h3",{className:"text-sm uppercase tracking-wider text-text-dim mb-3",children:["Backups (",y.length,")"]}),i("ul",{className:"space-y-2",children:y.map(D=>u("li",{className:"flex items-center justify-between gap-3 text-xs",children:[i("div",{className:"flex-1 font-mono truncate",children:D.filename}),u("div",{className:"text-text-dim whitespace-nowrap",children:[D.size,"B · ",new Date(D.mtimeMs).toLocaleString()]}),i("button",{type:"button",onClick:()=>j(D.filename),className:"btn text-xs",disabled:g,children:"Restore"})]},D.filename))})]})]})]})]})]})}function lx(){return i(oa,{category:"personas",title:"Personas",intro:"Edit Construct personas. Originals live in personas/; edits land at .cx/personas/, with prior content snapshotted to .cx/backups/personas/."})}function ax(){return i(oa,{category:"agents",title:"Agent prompts",intro:"Edit specialist agent prompts (cx-architect, cx-engineer, cx-product-manager, …). Originals in agents/prompts/; overrides at .cx/agents/, backups at .cx/backups/agents/."})}function ix(){return i(oa,{category:"skills",title:"Skills",intro:"Edit skill guidance. Originals live in skills/; edits land at .cx/skills/, with prior content snapshotted to .cx/backups/skills/. Custom skills go in .cx/skills/custom/."})}function sx(){return i(oa,{category:"rules",title:"Rules",intro:"Edit shared rules. Originals live in rules/; edits land at .cx/rules/, with prior content snapshotted to .cx/backups/rules/."})}function ox(){const[e,t]=m.useState([]),[n,r]=m.useState(0),[l,a]=m.useState(null),[s,o]=m.useState(!0);return m.useEffect(()=>{fetch("/api/audit?limit=200").then(c=>c.json()).then(c=>{c.error?a(c.error):(t(c.entries),r(c.total))}).catch(c=>a(c.message)).finally(()=>o(!1))},[]),u("div",{className:"max-w-5xl space-y-6",children:[u("header",{children:[i("p",{className:"text-text-dim text-xs uppercase tracking-wider mb-1",children:"Page"}),i("h1",{className:"text-3xl font-semibold tracking-tight",children:"Audit log"}),u("p",{className:"text-text-muted text-sm mt-2",children:["Every config / persona / skill / rules edit appends a line to ",i("code",{className:"px-1 py-0.5 bg-bg-muted rounded",children:".cx/audit.jsonl"}),". Newest first."]})]}),l&&i("div",{className:"card",style:{borderColor:"var(--status-down)"},children:i("p",{className:"text-sm",children:l})}),s&&!l&&i("p",{className:"text-sm text-text-dim",children:"Loading audit entries…"}),!s&&e.length===0&&!l&&u("section",{className:"card",children:[i("h2",{className:"text-lg font-semibold mb-2",children:"No audit entries yet"}),u("p",{className:"text-sm text-text-muted",children:["The log is created on first config or override edit. Try saving a change in ",i("code",{className:"px-1 py-0.5 bg-bg-muted rounded",children:"/config"})," or ",i("code",{className:"px-1 py-0.5 bg-bg-muted rounded",children:"/personas"}),"."]})]}),e.length>0&&u("section",{className:"card",children:[u("p",{className:"text-xs text-text-dim mb-3",children:["Showing ",e.length," of ",n," entries"]}),u("table",{className:"w-full text-sm",children:[i("thead",{className:"text-xs uppercase tracking-wider text-text-dim",children:u("tr",{children:[i("th",{className:"text-left font-normal pb-3 pr-4 whitespace-nowrap",children:"When"}),i("th",{className:"text-left font-normal pb-3 pr-4",children:"Action"}),i("th",{className:"text-left font-normal pb-3 pr-4",children:"Detail"})]})}),i("tbody",{children:e.map((c,p)=>u("tr",{className:"border-t border-border align-top",children:[i("td",{className:"py-2 pr-4 text-xs text-text-dim whitespace-nowrap font-mono",children:new Date(c.ts).toLocaleString()}),i("td",{className:"py-2 pr-4 font-mono text-xs",children:c.action}),u("td",{className:"py-2 pr-4 text-xs text-text-muted",children:[c.keys&&u("div",{children:["keys: ",c.keys.join(", ")]}),c.bytes!=null&&u("div",{children:["bytes: ",c.bytes]}),c.backupPath&&u("div",{children:["backup: ",i("span",{className:"font-mono",children:c.backupPath.split("/").slice(-3).join("/")})]}),c.path&&u("div",{className:"text-text-dim",children:["path: ",c.path.split("/").slice(-2).join("/")]})]})]},p))})]})]})]})}function cx(e){return e==="healthy"?"pip pip-healthy":e==="needs_attention"?"pip pip-degraded":e==="failing"||e==="broken"?"pip pip-down":"pip"}function ux(){const[e,t]=m.useState([]),[n,r]=m.useState(0),[l,a]=m.useState(!0),[s,o]=m.useState(null),[c,p]=m.useState(!0),[f,x]=m.useState(null),[v,y]=m.useState(""),[w,b]=m.useState(!1),[C,g]=m.useState(null);m.useEffect(()=>{fetch("/api/performance/reviews").then(h=>h.json()).then(h=>{h.error?o(h.error):(t(h.reviews||[]),r(h.mockFiltered||0),a(h.generatorImplemented!==!1))}).catch(h=>o(h.message)).finally(()=>p(!1))},[]);async function d(h){b(!0);try{const N=await fetch("/api/performance/feedback",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({agent:h,text:v})}),S=await N.json();if(!N.ok)throw new Error(S.error||`HTTP ${N.status}`);g(`Feedback saved to .cx/feedback/${S.filename}`),y(""),x(null)}catch(N){g(`Error: ${N.message}`)}finally{b(!1)}}return u("div",{className:"max-w-5xl space-y-6",children:[u("header",{children:[i("p",{className:"text-text-dim text-xs uppercase tracking-wider mb-1",children:"Page"}),i("h1",{className:"text-3xl font-semibold tracking-tight",children:"Performance reviews"}),u("p",{className:"text-text-muted text-sm mt-2",children:["Auto-generated end-of-session summaries from ",i("code",{className:"px-1 py-0.5 bg-bg-muted rounded",children:"~/.cx/performance-reviews/"}),". Each agent carries invocations + avg-score + trend + status. Add feedback to seed proposed prompt updates."]})]}),s&&i("div",{className:"card",style:{borderColor:"var(--status-down)"},children:i("p",{className:"text-sm",children:s})}),C&&i("div",{className:"card",style:{borderColor:"var(--status-healthy)"},children:i("p",{className:"text-sm",children:C})}),c&&i("p",{className:"text-sm text-text-dim",children:"Loading reviews…"}),!c&&e.length===0&&!s&&u("section",{className:"card",children:[i("h2",{className:"text-lg font-semibold mb-2",children:"No performance reviews yet"}),u("p",{className:"text-sm text-text-muted",children:["Run ",i("code",{className:"px-1 py-0.5 bg-bg-muted rounded",children:"construct review run"})," to generate the first review from your cost ledger + telemetry generations. The Stop hook also runs this every 24 hours automatically once the hooks are installed."]}),n>0&&u("p",{className:"text-xs text-text-dim mt-3",children:["Filtered out ",n," mock fixture file",n===1?"":"s"," (",i("code",{className:"px-1 py-0.5 bg-bg-muted rounded",children:"test-*-mock.json"}),") in ",i("code",{className:"px-1 py-0.5 bg-bg-muted rounded",children:"~/.cx/performance-reviews/"})," — those are test seeds, not real reviews."]})]}),e.map(h=>{var N;return u("section",{className:"card space-y-4",children:[u("header",{className:"flex items-start justify-between flex-wrap gap-3",children:[u("div",{children:[u("h2",{className:"text-lg font-semibold",children:["Review ",new Date(h.generated).toLocaleDateString()]}),u("p",{className:"text-xs text-text-dim mt-1",children:["Period: ",h.period.days," days · ",new Date(h.period.from).toLocaleDateString()," → ",new Date(h.period.to).toLocaleDateString()]})]}),i("div",{className:"text-xs text-text-dim font-mono",children:h.filename})]}),u("table",{className:"w-full text-sm",children:[i("thead",{className:"text-xs uppercase tracking-wider text-text-dim",children:u("tr",{children:[i("th",{className:"text-left font-normal pb-2",children:"Agent"}),i("th",{className:"text-right font-normal pb-2",children:"Invocations"}),i("th",{className:"text-right font-normal pb-2",children:"Avg score"}),i("th",{className:"text-right font-normal pb-2",children:"Fail rate"}),i("th",{className:"text-left font-normal pb-2 pl-3",children:"Trend"}),i("th",{className:"text-left font-normal pb-2 pl-3",children:"Status"}),i("th",{className:"text-right font-normal pb-2"})]})}),i("tbody",{children:(N=h.agentStats)==null?void 0:N.map(S=>{var L;return u(Ce,{children:[u("tr",{className:"border-t border-border align-top",children:[i("td",{className:"py-2 font-mono text-xs",children:S.name}),i("td",{className:"py-2 text-right",children:S.invocations}),i("td",{className:"py-2 text-right",children:(L=S.avgScore)==null?void 0:L.toFixed(2)}),u("td",{className:"py-2 text-right",children:[Math.round((S.failureRate||0)*100),"%"]}),i("td",{className:"py-2 pl-3 text-xs",children:S.trend}),i("td",{className:"py-2 pl-3",children:u("span",{className:cx(S.status),children:[i("span",{"aria-hidden":"true",children:S.status==="healthy"?"✓":S.status==="needs_attention"?"!":"✕"}),S.status]})}),i("td",{className:"py-2 text-right",children:i("button",{type:"button",onClick:()=>{x(S.name),y("")},className:"btn text-xs",children:"Feedback"})})]},S.name),f===S.name&&i("tr",{className:"bg-bg-muted",children:u("td",{colSpan:7,className:"p-3",children:[u("label",{className:"block text-xs uppercase tracking-wider text-text-dim mb-2",children:["Feedback for ",S.name]}),i("textarea",{value:v,onChange:R=>y(R.target.value),rows:4,placeholder:"Describe what should change about this agent's behavior. The feedback seeds proposed prompt updates.",className:"w-full p-2 border border-border rounded bg-surface text-sm"}),u("div",{className:"flex items-center gap-2 mt-2",children:[i("button",{type:"button",onClick:()=>d(S.name),disabled:!v.trim()||w,className:"btn btn-primary text-xs disabled:opacity-50",children:w?"Saving…":"Save feedback"}),i("button",{type:"button",onClick:()=>{x(null),y("")},className:"btn text-xs",children:"Cancel"})]})]})},`${S.name}-feedback`)]})})})]})]},h.filename)})]})}function dx({items:e}){const[t,n]=m.useState(!1),[r,l]=m.useState(""),[a,s]=m.useState(0),o=m.useRef(null),c=Pp();if(m.useEffect(()=>{function v(y){if((y.metaKey||y.ctrlKey)&&y.key.toLowerCase()==="k"){y.preventDefault(),n(w=>!w),l(""),s(0);return}y.key==="Escape"&&t&&(y.preventDefault(),n(!1))}return window.addEventListener("keydown",v),()=>window.removeEventListener("keydown",v)},[t]),m.useEffect(()=>{t&&setTimeout(()=>{var v;return(v=o.current)==null?void 0:v.focus()},10)},[t]),!t)return null;const p=e.filter(v=>!r||v.label.toLowerCase().includes(r.toLowerCase())),f=Math.min(a,Math.max(0,p.length-1));function x(v){if(v.key==="ArrowDown"){v.preventDefault(),s(y=>Math.min(p.length-1,y+1));return}if(v.key==="ArrowUp"){v.preventDefault(),s(y=>Math.max(0,y-1));return}if(v.key==="Enter"){v.preventDefault();const y=p[f];y&&(c(y.path),n(!1))}}return i("div",{role:"dialog","aria-modal":"true","aria-label":"Command palette",onClick:()=>n(!1),style:{position:"fixed",inset:0,background:"rgba(0, 0, 0, 0.4)",zIndex:100,display:"flex",alignItems:"flex-start",justifyContent:"center",paddingTop:"15vh"},children:u("div",{onClick:v=>v.stopPropagation(),className:"card",style:{width:"90%",maxWidth:"560px",padding:0,background:"var(--surface)",borderColor:"var(--border)"},children:[i("input",{ref:o,type:"text",value:r,placeholder:"Jump to page…",onChange:v=>{l(v.target.value),s(0)},onKeyDown:x,className:"w-full p-4 bg-surface text-text border-b border-border focus:outline-none",style:{fontSize:"1rem"}}),u("ul",{className:"max-h-96 overflow-y-auto",role:"listbox",children:[p.length===0&&i("li",{className:"px-4 py-3 text-sm text-text-dim",children:"No matches."}),p.map((v,y)=>u("li",{role:"option","aria-selected":y===f,className:"px-4 py-2.5 text-sm cursor-pointer flex items-center justify-between",style:y===f?{background:"var(--bg-muted)",borderLeft:"2px solid var(--aurora-cyan)"}:{},onMouseEnter:()=>s(y),onClick:()=>{c(v.path),n(!1)},children:[i("span",{children:v.label}),i("span",{className:"text-xs text-text-dim font-mono",children:v.path})]},v.path))]}),u("div",{className:"px-4 py-2 text-xs text-text-dim border-t border-border flex items-center gap-3",children:[i("span",{children:"↑↓ navigate"}),i("span",{children:"↵ open"}),i("span",{children:"esc close"})]})]})})}function px(){const[e,t]=m.useState([]),[n,r]=m.useState([]),[l,a]=m.useState(!0);return m.useEffect(()=>{Fn().then(s=>{t(s.cliCommands??[]),r(s.commands??[])}).catch(()=>{}).finally(()=>a(!1))},[]),l?i("div",{className:"text-center py-20 text-gray-600",children:"Loading..."}):u("div",{children:[i("h1",{className:"text-2xl font-bold mb-6",children:"Commands"}),e.length>0&&u("div",{className:"mb-8",children:[i("h2",{className:"text-sm font-semibold text-gray-500 uppercase tracking-wide mb-3",children:"CLI"}),i("div",{className:"grid grid-cols-1 gap-2",children:e.map((s,o)=>u("div",{className:"bg-white border border-gray-200 rounded-lg px-4 py-3",children:[u("p",{className:"font-mono text-sm font-medium",children:["construct ",s.name]}),i("p",{className:"text-sm text-gray-500",children:s.description})]},o))})]}),n.length>0&&u("div",{children:[i("h2",{className:"text-sm font-semibold text-gray-500 uppercase tracking-wide mb-3",children:"Slash"}),i("div",{className:"grid grid-cols-1 gap-4",children:n.map((s,o)=>u("div",{className:"bg-white border border-gray-200 rounded-xl p-5",children:[i("p",{className:"font-semibold mb-2",children:s.domain}),i("div",{className:"flex flex-wrap gap-2",children:(s.commands??[]).map((c,p)=>i("span",{className:"bg-gray-100 text-gray-700 text-xs px-2 py-1 rounded-full font-mono",children:c.slash},p))})]},o))})]}),e.length===0&&n.length===0&&i("div",{className:"text-center py-20 text-gray-600",children:"No commands found."})]})}function fx(){const[e,t]=m.useState([]),[n,r]=m.useState(!0);if(m.useEffect(()=>{Fn().then(a=>t(a.hooks??[])).catch(()=>{}).finally(()=>r(!1))},[]),n)return i("div",{className:"text-center py-20 text-gray-600",children:"Loading..."});const l={};for(const a of e){const s=a.phase??"Other";l[s]||(l[s]=[]),l[s].push(a)}return u("div",{children:[i("h1",{className:"text-2xl font-bold mb-6",children:"Hooks"}),e.length===0?i("div",{className:"text-center py-20 text-gray-600",children:"No hooks configured."}):Object.entries(l).map(([a,s])=>u("div",{className:"mb-6",children:[i("h2",{className:"text-sm font-semibold text-gray-500 uppercase tracking-wide mb-3",children:a}),i("div",{className:"grid grid-cols-1 gap-2",children:s.map((o,c)=>u("div",{className:"bg-white border border-gray-200 rounded-lg px-4 py-3 flex items-start gap-3",children:[i("span",{className:`w-2 h-2 rounded-full mt-1.5 flex-shrink-0 ${o.blocking?"bg-yellow-500":"bg-gray-300"}`}),u("div",{children:[i("p",{className:"text-sm text-gray-700",children:o.description}),!o.blocking&&i("p",{className:"text-xs text-gray-600 mt-0.5",children:"async"})]})]},c))})]},a))]})}function mx(){const[e,t]=m.useState({}),[n,r]=m.useState(!0);if(m.useEffect(()=>{Os().then(a=>t(a.mcpServers??{})).catch(()=>{}).finally(()=>r(!1))},[]),n)return i("div",{className:"text-center py-20 text-gray-600",children:"Loading..."});const l=Object.entries(e);return u("div",{children:[i("h1",{className:"text-2xl font-bold mb-6",children:"MCP Servers"}),l.length===0?i("div",{className:"text-center py-20 text-gray-600",children:"No MCP servers configured."}):l.map(([a,s])=>u("div",{className:"bg-white border border-gray-200 rounded-xl p-5 mb-4",children:[u("div",{className:"flex items-center justify-between mb-2",children:[i("p",{className:"font-semibold",children:a}),i("span",{className:"bg-gray-100 text-gray-600 text-xs px-2 py-0.5 rounded-full",children:s.type??"stdio"})]}),i("p",{className:"text-sm text-gray-500 mb-2",children:s.description??s.command??s.url??""}),s.command&&u("p",{className:"text-xs text-gray-600 font-mono",children:[s.command," ",Array.isArray(s.args)?s.args.join(" "):""]})]},a))]})}function hx(){const[e,t]=m.useState(null),[n,r]=m.useState(!0);return m.useEffect(()=>{Fn().then(l=>t(l.plugins??null)).catch(()=>{}).finally(()=>r(!1))},[]),n?i("div",{className:"text-center py-20 text-gray-600",children:"Loading..."}):e?u("div",{children:[i("h1",{className:"text-2xl font-bold mb-6",children:"Plugins"}),e.status&&u("p",{className:"text-sm text-gray-500 mb-4",children:["Status: ",e.status]}),e.summary&&i("p",{className:"text-sm text-gray-500 mb-4",children:e.summary}),i("div",{className:"grid grid-cols-1 gap-4",children:(e.entries??[]).map((l,a)=>u("div",{className:"bg-white border border-gray-200 rounded-xl p-5",children:[i("p",{className:"font-semibold",children:l.name}),i("p",{className:"text-sm text-gray-500 mb-2",children:l.description}),u("div",{className:"flex flex-wrap gap-2 text-xs text-gray-600",children:[i("span",{children:l.id}),u("span",{children:["v",l.version]}),l.builtIn&&i("span",{className:"bg-gray-100 px-1.5 py-0.5 rounded",children:"built-in"})]})]},a))})]}):i("div",{className:"text-center py-20 text-gray-600",children:"No plugin data."})}const za="px-2 py-0.5 text-xs font-medium rounded border border-indigo-600 bg-indigo-600 text-white hover:bg-indigo-700 transition-colors disabled:opacity-50",Zr="px-2 py-0.5 text-xs font-medium rounded border border-gray-300 bg-white text-gray-800 hover:bg-gray-100 transition-colors disabled:opacity-50",gx="px-2 py-0.5 text-xs font-medium rounded border border-red-300 bg-white text-red-700 hover:bg-red-50 transition-colors disabled:opacity-50";function xx({credentials:e,kind:t,envPath:n,onChange:r,opAvailable:l=!1}){const a=e.filter(o=>o.kind===t),s=o=>{try{navigator.clipboard.writeText(o)}catch{}};return u("div",{className:"mt-6 bg-white border border-gray-200 rounded-lg overflow-hidden",children:[u("div",{className:"px-4 py-2 border-b border-gray-200 bg-gray-50 flex items-center justify-between gap-2 flex-wrap",children:[i("p",{className:"text-xs font-semibold text-gray-700 uppercase tracking-wide",children:"Credentials"}),u("div",{className:"flex items-center gap-3",children:[l&&i("span",{className:"text-[10px] text-emerald-700 bg-emerald-50 border border-emerald-200 rounded px-1.5 py-0.5 font-medium",children:"1Password CLI detected"}),n&&i("button",{onClick:()=>s(n),className:"text-xs font-medium text-indigo-700 hover:text-indigo-900 transition-colors",children:"Copy config path"})]})]}),u("table",{className:"w-full text-sm",children:[i("thead",{className:"bg-gray-50 border-b border-gray-200",children:u("tr",{className:"text-xs uppercase tracking-wide text-gray-700",children:[i("th",{className:"text-left px-3 py-1.5 font-semibold",children:"Provider"}),i("th",{className:"text-left px-3 py-1.5 font-semibold",children:"Env var"}),i("th",{className:"text-left px-3 py-1.5 font-semibold",children:"Value"}),i("th",{className:"text-right px-3 py-1.5 font-semibold w-52",children:"Actions"})]})}),i("tbody",{className:"divide-y divide-gray-100",children:a.flatMap(o=>o.vars.map((c,p)=>i(vx,{provider:o.label,configured:o.configured,showProvider:p===0,v:c,onChange:r,opAvailable:l},`${o.provider}-${c.envVar}`)))})]})]})}function vx({provider:e,configured:t,showProvider:n,v:r,onChange:l,opAvailable:a}){const[s,o]=m.useState(!1),[c,p]=m.useState(""),[f,x]=m.useState(!1),[v,y]=m.useState(!1),[w,b]=m.useState(null),[C,g]=m.useState(!1),[d,h]=m.useState(""),[N,S]=m.useState(!1),L=()=>{o(!0),p(""),x(!1),b(null)},R=()=>{o(!1),p(""),b(null)},k=()=>{g(!0),h(""),b(null)},A=()=>{g(!1),h("")},j=async()=>{if(!d.trim()){b("Enter a 1Password reference like 'op://Development/Anthropic/credential'");return}S(!0),b(null);try{await Wg(r.envVar,d.trim()),g(!1),h(""),l()}catch(B){b(B.message||"pull from 1Password failed")}finally{S(!1)}},D=async()=>{if(!c){b("value required");return}y(!0),b(null);try{await tu(r.envVar,c),o(!1),p(""),l()}catch(B){b(B.message||"save failed")}finally{y(!1)}},O=async()=>{if(confirm(`Unset ${r.envVar}?`)){y(!0),b(null);try{await tu(r.envVar,""),l()}catch(B){b(B.message||"unset failed")}finally{y(!1)}}},H=t==="full"?"bg-green-500":t==="partial"?"bg-yellow-500":"bg-gray-400";return u(m.Fragment,{children:[u("tr",{className:"hover:bg-gray-50",children:[i("td",{className:"px-3 py-1.5",children:n&&u("div",{className:"flex items-center gap-1.5",children:[i("span",{className:`h-1.5 w-1.5 rounded-full ${H}`}),i("span",{className:"text-xs font-medium text-gray-800",children:e})]})}),i("td",{className:"px-3 py-1.5",children:i("code",{className:"text-xs font-mono text-gray-800",children:r.envVar})}),i("td",{className:"px-3 py-1.5",children:i("code",{className:`text-xs font-mono ${r.set?"text-gray-700":"text-gray-500"}`,children:r.preview??"not set"})}),u("td",{className:"px-3 py-1.5",children:[!s&&!C&&u("div",{className:"flex items-center justify-end gap-1.5 flex-wrap",children:[i("button",{onClick:L,disabled:v,className:za,children:r.set?"Update":"Set"}),a&&i("button",{onClick:k,disabled:v,className:Zr,title:"Pull this value from a 1Password vault",children:"1Password…"}),r.set&&i("button",{onClick:O,disabled:v,className:gx,children:"Clear"})]}),s&&u("div",{className:"flex items-center justify-end gap-1",children:[i("button",{onClick:D,disabled:v,className:za,children:v?"…":"Save"}),i("button",{onClick:R,disabled:v,className:Zr,children:"Cancel"})]}),C&&u("div",{className:"flex items-center justify-end gap-1",children:[i("button",{onClick:j,disabled:N,className:za,children:N?"…":"Pull"}),i("button",{onClick:A,disabled:N,className:Zr,children:"Cancel"})]})]})]}),s&&i("tr",{children:u("td",{colSpan:4,className:"px-3 pb-2 bg-gray-50",children:[u("div",{className:"flex items-center gap-2",children:[i("input",{type:f?"text":"password",value:c,onChange:B=>p(B.target.value),onKeyDown:B=>{B.key==="Enter"&&D(),B.key==="Escape"&&R()},placeholder:`new value for ${r.envVar}`,autoFocus:!0,className:"flex-1 px-2 py-1 text-xs border border-gray-300 rounded font-mono"}),i("button",{onClick:()=>x(B=>!B),className:Zr,children:f?"Hide":"Show"})]}),w&&i("p",{className:"mt-1 text-xs text-red-700",children:w})]})}),C&&i("tr",{children:u("td",{colSpan:4,className:"px-3 pb-2 bg-emerald-50/60",children:[i("div",{className:"flex items-center gap-2",children:i("input",{type:"text",value:d,onChange:B=>h(B.target.value),onKeyDown:B=>{B.key==="Enter"&&j(),B.key==="Escape"&&A()},placeholder:`op://Development/${e}/credential`,autoFocus:!0,className:"flex-1 px-2 py-1 text-xs border border-emerald-300 rounded font-mono bg-white"})}),u("p",{className:"mt-1 text-[10px] text-gray-700",children:["Runs ",i("code",{className:"bg-white px-1 rounded font-mono",children:"op read"})," on the host. The ",i("code",{className:"font-mono",children:"op://"})," reference is logged in ",i("code",{className:"font-mono",children:"~/.cx/credential-audit.jsonl"}),"; the resolved value is stored in ",i("code",{className:"font-mono",children:"~/.construct/config.env"})," (mode 0600) the same way as a manual paste."]}),w&&i("p",{className:"mt-1 text-xs text-red-700",children:w})]})})]})}function yx(e){return e==="configured"?"pip pip-healthy":"pip pip-down"}function Nx(){const[e,t]=m.useState(null),[n,r]=m.useState([]),[l,a]=m.useState([]),[s,o]=m.useState(null),[c,p]=m.useState({global:"metered",providers:{}}),[f,x]=m.useState(null),[v,y]=m.useState(null),[w,b]=m.useState(null),[C,g]=m.useState(!1),[d,h]=m.useState({provider:"",label:"",kind:"llm",envVars:[""]}),[N,S]=m.useState(!1),L=()=>qc().then(O=>r(O.credentials??[])).catch(()=>{}),R=()=>eu().then(O=>a(O.providers??[])).catch(()=>{});m.useEffect(()=>{Promise.all([Mp().then(O=>O.providers||[]).catch(O=>(y(O.message),[])),qc().then(O=>O.credentials??[]).catch(()=>[]),Ag().catch(()=>null),eu().then(O=>O.providers??[]).catch(()=>[]),Vg().catch(()=>({available:!1,signedIn:!1,accounts:[]})),Hg().catch(()=>({global:"metered",providers:{}}))]).then(([O,H,B,fe,$e,Le])=>{t(O),r(H),x(B),a(fe),o($e),p(Le)})},[]);const k=async(O,H)=>{try{const B=await Qg(O,H);p(fe=>({...fe,providers:B.providers||{}}))}catch(B){y((B==null?void 0:B.message)||"failed to save billing mode")}},A=O=>{var H,B;return((B=(H=c.providers)==null?void 0:H[O])==null?void 0:B.billingMode)||c.global||"metered"},j=async()=>{b(null),S(!0);try{await Ug({provider:d.provider.trim().toLowerCase(),label:d.label.trim(),kind:d.kind,envVars:d.envVars.map(O=>O.trim().toUpperCase()).filter(Boolean)}),await Promise.all([R(),L()]),g(!1),h({provider:"",label:"",kind:"llm",envVars:[""]})}catch(O){b((O==null?void 0:O.message)||"Failed to save")}finally{S(!1)}},D=async O=>{if(window.confirm(`Remove custom provider "${O}"? Existing env values are kept.`))try{await Bg(O),await Promise.all([R(),L()])}catch(H){b((H==null?void 0:H.message)||"Failed to delete")}};return u("div",{className:"max-w-5xl space-y-6",children:[u("header",{children:[i("p",{className:"text-text-dim text-xs uppercase tracking-wider mb-1",children:"Page"}),i("h1",{className:"text-2xl sm:text-3xl font-semibold tracking-tight",children:"Model providers"}),u("p",{className:"text-text-muted text-sm mt-2",children:["Connection state and credentials for every provider Construct can route to. Keys are stored in ",i("code",{className:"px-1 py-0.5 bg-bg-muted rounded",children:"~/.construct/config.env"})," (mode 0600) and hot-reloaded into ",i("code",{className:"px-1 py-0.5 bg-bg-muted rounded",children:"process.env"})," — no restart needed. Pick the model per tier on the ",i("a",{href:"#/models",className:"underline hover:text-text",children:"Models"})," page after the key lands."]})]}),v&&i("div",{className:"card",style:{borderColor:"var(--status-down)"},children:i("p",{className:"text-sm",children:v})}),!e&&!v&&i("p",{className:"text-sm text-text-dim",children:"Loading providers…"}),e&&e.length>0&&u("section",{className:"card overflow-x-auto",children:[u("p",{className:"text-xs text-text-muted mb-3",children:[i("strong",{children:"Billing"})," sets how each provider's spend is counted on Mission Control.",i("span",{className:"font-mono",children:" subscription"}),` = flat-rate plan (Claude Pro / GPT Plus / OpenRouter credits), excluded from "today's actual spend".`,i("span",{className:"font-mono",children:" metered"})," = pay-per-token, counted toward the daily cap. Global default: ",i("code",{className:"px-1 bg-bg-muted rounded font-mono",children:c.global}),"."]}),u("table",{className:"w-full text-sm min-w-[560px]",children:[i("thead",{className:"text-xs uppercase tracking-wider text-text-dim",children:u("tr",{children:[i("th",{className:"text-left font-normal pb-3 pr-4",children:"Provider"}),i("th",{className:"text-left font-normal pb-3 pr-4",children:"Status"}),i("th",{className:"text-left font-normal pb-3 pr-4",children:"Env var"}),i("th",{className:"text-left font-normal pb-3 pr-4",children:"Billing"}),i("th",{className:"text-right font-normal pb-3"})]})}),i("tbody",{children:e.map(O=>{var H;return u("tr",{className:"border-t border-border",children:[u("td",{className:"py-3 pr-4",children:[i("div",{className:"font-medium",children:O.displayName}),i("div",{className:"text-xs text-text-dim font-mono break-all",children:O.id})]}),i("td",{className:"py-3 pr-4",children:u("span",{className:yx(O.state),children:[i("span",{"aria-hidden":"true",children:O.configured?"✓":"✕"}),O.configured?"configured":"not configured"]})}),i("td",{className:"py-3 pr-4 font-mono text-xs break-all",children:O.envKey}),u("td",{className:"py-3 pr-4",children:[u("select",{value:A(O.id),onChange:B=>k(O.id,B.target.value),className:"px-2 py-1 text-xs border border-border rounded bg-bg","aria-label":`Billing mode for ${O.displayName}`,children:[i("option",{value:"metered",children:"metered"}),i("option",{value:"subscription",children:"subscription"}),i("option",{value:"mixed",children:"mixed"})]}),!((H=c.providers)!=null&&H[O.id])&&i("p",{className:"text-[10px] text-text-dim mt-0.5",children:"inherits global"})]}),i("td",{className:"py-3 text-right",children:i("a",{href:O.docsUrl,target:"_blank",rel:"noreferrer",className:"btn text-xs whitespace-nowrap",children:"Get key ↗"})})]},O.id)})})]})]}),(s==null?void 0:s.available)&&s.signedIn&&s.accounts&&s.accounts.length>0&&u("div",{className:"card border border-emerald-300 bg-emerald-50/40",children:[i("h2",{className:"text-xs uppercase tracking-wider text-text-dim mb-1",children:"1Password CLI"}),u("p",{className:"text-sm",children:["Signed in as ",i("code",{className:"px-1 bg-bg-muted rounded",children:s.accounts[0].email}),". Each credential row below has a ",i("strong",{children:"1Password…"})," button — paste a reference like ",i("code",{className:"px-1 bg-bg-muted rounded font-mono",children:"op://Development/Anthropic/credential"})," and Construct will resolve it on the host (via ",i("code",{className:"px-1 bg-bg-muted rounded",children:"op read"}),") and store the value the same way a manual paste does."]})]}),i(xx,{credentials:n,kind:"llm",envPath:(f==null?void 0:f.envPath)??null,onChange:L,opAvailable:!!(s!=null&&s.available&&(s!=null&&s.signedIn))}),u("section",{className:"card",children:[u("header",{className:"flex items-baseline justify-between mb-3 gap-2 flex-wrap",children:[i("h2",{className:"text-sm uppercase tracking-wider text-text-dim",children:"Custom providers"}),!C&&i("button",{onClick:()=>g(!0),className:"btn btn-primary text-xs",children:"+ Define a custom provider"})]}),u("p",{className:"text-xs text-text-muted mb-3",children:["Need a provider Construct doesn't ship a card for (xAI, Cohere, your own gateway)? Declare its env var(s) here and it'll show up in the credentials editor above. Stored in",i("code",{className:"px-1 bg-bg-muted rounded mx-1",children:"~/.construct/custom-credentials.json"}),"(mode 0600). Values still live in ",i("code",{className:"px-1 bg-bg-muted rounded",children:"~/.construct/config.env"}),"; this file is only the allowlist of names."]}),w&&i("div",{className:"mb-3 px-3 py-2 rounded bg-red-50 border border-red-200 text-red-800 text-xs",children:w}),l.length===0&&!C&&i("p",{className:"text-xs text-text-dim italic",children:"No custom providers defined."}),l.length>0&&i("ul",{className:"space-y-1 mb-3",children:l.map(O=>u("li",{className:"flex items-center justify-between gap-2 bg-bg-muted rounded px-3 py-2 text-sm",children:[u("div",{className:"min-w-0",children:[u("div",{className:"font-medium truncate",children:[O.label," ",u("span",{className:"text-text-dim text-xs font-mono",children:["(",O.provider,")"]})]}),u("div",{className:"text-xs text-text-dim font-mono break-all",children:["env: ",O.envVars.join(", ")," · kind: ",O.kind]})]}),i("button",{onClick:()=>D(O.provider),className:"text-xs text-red-700 hover:text-red-900 whitespace-nowrap",children:"Remove"})]},O.provider))}),C&&u("div",{className:"border border-border rounded p-3 space-y-3 bg-bg-muted/30",children:[u("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-3",children:[u("label",{className:"block",children:[i("span",{className:"text-xs text-text-dim block mb-1",children:"Provider id"}),i("input",{type:"text",value:d.provider,onChange:O=>h({...d,provider:O.target.value}),placeholder:"xai · cohere · my-gateway",className:"w-full px-2 py-1 text-sm font-mono border border-border rounded bg-bg"}),i("span",{className:"text-[10px] text-text-dim block mt-0.5",children:"lowercase letters, digits, hyphens"})]}),u("label",{className:"block",children:[i("span",{className:"text-xs text-text-dim block mb-1",children:"Display label"}),i("input",{type:"text",value:d.label,onChange:O=>h({...d,label:O.target.value}),placeholder:"xAI Grok · Cohere",className:"w-full px-2 py-1 text-sm border border-border rounded bg-bg"})]}),u("label",{className:"block",children:[i("span",{className:"text-xs text-text-dim block mb-1",children:"Kind"}),u("select",{value:d.kind,onChange:O=>h({...d,kind:O.target.value}),className:"w-full px-2 py-1 text-sm border border-border rounded bg-bg",children:[i("option",{value:"llm",children:"LLM provider"}),i("option",{value:"integration",children:"Integration (issue tracker / chat / docs)"})]})]})]}),u("div",{children:[i("span",{className:"text-xs text-text-dim block mb-1",children:"Env var name(s)"}),d.envVars.map((O,H)=>u("div",{className:"flex gap-2 mb-1",children:[i("input",{type:"text",value:O,onChange:B=>{const fe=[...d.envVars];fe[H]=B.target.value,h({...d,envVars:fe})},placeholder:"XAI_API_KEY",className:"flex-1 px-2 py-1 text-sm font-mono border border-border rounded bg-bg"}),i("button",{onClick:()=>h({...d,envVars:d.envVars.filter((B,fe)=>fe!==H)}),disabled:d.envVars.length===1,className:"text-xs text-red-700 hover:text-red-900 disabled:opacity-30","aria-label":"Remove this env var",children:"×"})]},H)),i("button",{onClick:()=>h({...d,envVars:[...d.envVars,""]}),className:"text-xs text-indigo-700 hover:text-indigo-900",children:"+ Add another env var"}),u("p",{className:"text-[10px] text-text-dim mt-1",children:["Must match ",i("code",{children:"/^[A-Z][A-Z0-9_]{1,63}$/"})," · reserved OS vars (PATH, HOME, …) rejected"]})]}),u("div",{className:"flex gap-2 justify-end pt-2 border-t border-border",children:[i("button",{onClick:()=>{g(!1),b(null)},className:"btn text-xs",children:"Cancel"}),i("button",{onClick:j,disabled:N,className:"btn btn-primary text-xs disabled:opacity-50",children:N?"Saving…":"Save provider"})]})]})]})]})}function Ms(){return u("div",{className:"sm:hidden mb-3 px-3 py-2 rounded border border-amber-300 bg-amber-50 text-amber-900 text-xs",children:[i("strong",{children:"Tight fit."})," This page is designed for editing on a wider screen. Status and read-only views (Mission Control · Beads · Doctor) work great here; complex forms are easier with more room."]})}const kt=["reasoning","standard","fast"];function nu(e){return e?e.source==="local"?e.label||"free · runs locally":e.input===0&&e.output===0?"free":!Number.isFinite(e.input)||!Number.isFinite(e.output)?"":`$${e.input.toFixed(2)} in · $${e.output.toFixed(2)} out /1M`:""}function wx(){var G;const[e,t]=m.useState(null),[n,r]=m.useState({reasoning:{primary:"",fallback:[]},standard:{primary:"",fallback:[]},fast:{primary:"",fallback:[]}}),[l,a]=m.useState(null),[s,o]=m.useState({}),[c,p]=m.useState(!1),[f,x]=m.useState(!0),[v,y]=m.useState(null),[w,b]=m.useState(!1),[C,g]=m.useState(null),[d,h]=m.useState(null),[N,S]=m.useState(!1);m.useEffect(()=>{Promise.all([Os().then(P=>P.models??{}).catch(()=>({})),Ig().catch(()=>null)]).then(([P,z])=>{var T,E;const V={reasoning:{primary:"",fallback:[]},standard:{primary:"",fallback:[]},fast:{primary:"",fallback:[]}};for(const Y of kt)V[Y]={primary:((T=P==null?void 0:P[Y])==null?void 0:T.primary)??"",fallback:Array.isArray((E=P==null?void 0:P[Y])==null?void 0:E.fallback)?P[Y].fallback:[]};r(V),a(JSON.parse(JSON.stringify(V))),t(z)}).finally(()=>x(!1))},[]),m.useEffect(()=>{var V;if(!e)return;const P=new Set;for(const T of kt)for(const E of((V=e.tierOptions)==null?void 0:V[T])??[])P.add(E);for(const T of kt){n[T].primary&&P.add(n[T].primary);for(const E of n[T].fallback)E&&P.add(E)}const z=Array.from(P);z.length!==0&&(p(!0),Dg(z).then(T=>o(T.pricing??{})).catch(()=>{}).finally(()=>p(!1)))},[e,n]);const L=m.useMemo(()=>{var P;return((P=e==null?void 0:e.providers)==null?void 0:P.filter(z=>z.configured))??[]},[e]),R=P=>{var z;return((z=e==null?void 0:e.tierOptions)==null?void 0:z[P])??[]},k=P=>{const z=L.flatMap(V=>V.options[P]||[]);return[...new Set(z)]},A=m.useMemo(()=>{const P={reasoning:!1,standard:!1,fast:!1};if(!l)return P;for(const z of kt)P[z]=JSON.stringify(n[z])!==JSON.stringify(l[z]);return P},[n,l]),j=P=>N?R(P):k(P),D=P=>{const z=s[P],V=nu(z);return V?`${P} — ${V}`:P},O=(P,z)=>r(V=>({...V,[P]:{...V[P],primary:z}})),H=(P,z,V)=>r(T=>({...T,[P]:{...T[P],fallback:T[P].fallback.map((E,Y)=>Y===z?V:E)}})),B=P=>r(z=>({...z,[P]:{...z[P],fallback:[...z[P].fallback,""]}})),fe=(P,z)=>r(V=>({...V,[P]:{...V[P],fallback:V[P].fallback.filter((T,E)=>E!==z)}})),$e=async P=>{if(!n[P].primary){h("Primary model required");return}y(P),h(null);try{const z=n[P].fallback.filter(Boolean);await Kg(P,n[P].primary,z),a(V=>V&&{...V,[P]:{primary:n[P].primary,fallback:z}}),r(V=>({...V,[P]:{primary:V[P].primary,fallback:z}}))}catch(z){h(z.message||"save failed")}finally{y(null)}},Le=async()=>{b(!0),h(null),g(null);try{const z=(await $g()).selections||{},V={...n};for(const E of kt)z[E]&&(V[E]={primary:z[E],fallback:n[E].fallback});r(V),a(JSON.parse(JSON.stringify(V)));const T=kt.filter(E=>z[E]).map(E=>`${E}: ${z[E]}`).join(" · ");g(T?`Saved ${T}`:"Polled OpenRouter but no free models met the per-tier context thresholds.")}catch(P){h(P.message||"Auto-pick failed. Set OPENROUTER_API_KEY in Providers, then retry.")}finally{b(!1)}},M=kt.every(P=>!n[P].primary);if(f)return i("div",{className:"text-center py-20 text-gray-600",children:"Loading..."});const F="px-2.5 py-1 text-xs font-medium rounded border border-indigo-600 bg-indigo-600 text-white hover:bg-indigo-700 transition-colors disabled:opacity-50",U="px-2.5 py-1 text-xs font-medium rounded border border-gray-300 bg-white text-gray-800 hover:bg-gray-100 transition-colors disabled:opacity-50",K=((e==null?void 0:e.providers)??[]).filter(P=>P.local);return u("div",{children:[i(Ms,{}),i("h1",{className:"text-xl font-bold mb-1",children:"Model Tiers"}),u("p",{className:"text-xs text-gray-600 mb-3",children:["Construct ships with no model selected — pick one per tier before running any LLM-backed workflow. Pricing is per million tokens (USD). Live OpenRouter numbers refresh every 5 minutes; Anthropic and OpenAI direct endpoints use the published list price.",c&&i("span",{className:"ml-2 text-indigo-600",children:"refreshing…"})]}),M&&u("div",{className:"mb-3 px-3 py-2 rounded bg-amber-50 border border-amber-300 text-amber-900 text-xs flex items-center justify-between gap-3",children:[u("div",{children:[i("p",{className:"font-semibold",children:"No models selected."}),i("p",{children:"Pick a primary for each tier below, or use auto-pick to seed all three tiers from the OpenRouter free catalog."})]}),i("button",{onClick:Le,disabled:w,className:"px-2.5 py-1 text-xs font-medium rounded border border-amber-600 bg-amber-600 text-white hover:bg-amber-700 transition-colors disabled:opacity-50 whitespace-nowrap",children:w?"Polling…":"Auto-pick free models"})]}),!M&&u("div",{className:"mb-3 flex items-center gap-3 text-xs",children:[i("button",{onClick:Le,disabled:w,className:"px-2.5 py-1 font-medium rounded border border-gray-300 bg-white text-gray-800 hover:bg-gray-100 transition-colors disabled:opacity-50",children:w?"Polling…":"Re-pick free OpenRouter models"}),i("span",{className:"text-gray-600",children:"Replaces each tier's primary with the best free OpenRouter model meeting the context threshold (32k reasoning, 16k standard, 8k fast)."})]}),C&&i("div",{className:"mb-3 px-3 py-2 rounded bg-green-50 border border-green-200 text-green-800 text-xs",children:C}),L.length>0&&u("div",{className:"mb-3 px-3 py-2 rounded bg-green-50 border border-green-200 text-xs",children:[u("p",{className:"font-semibold text-green-900 mb-1",children:["Your configured providers (",L.length,")"]}),i("ul",{className:"text-green-800 space-y-0.5 flex flex-wrap gap-x-4 gap-y-0.5",children:L.map(P=>u("li",{className:"inline-flex items-center gap-1",children:[i("span",{className:"text-green-700",children:"✓"}),i("span",{className:"font-mono",children:P.id}),u("span",{className:"text-green-700",children:["— ",P.label]})]},P.id))})]}),L.length===0&&((G=e==null?void 0:e.providers)==null?void 0:G.length)>0&&u("div",{className:"mb-3 px-3 py-2 rounded bg-amber-50 border border-amber-200 text-xs",children:[i("p",{className:"font-semibold text-amber-900 mb-1",children:"No providers configured"}),u("p",{className:"text-amber-800",children:["Add API keys on the ",i("a",{href:"#/providers",className:"underline",children:"Providers"})," page, then models from those providers will appear here."]})]}),e&&u("label",{className:"flex items-center gap-2 mb-3 text-xs text-gray-600 cursor-pointer",children:[i("input",{type:"checkbox",checked:N,onChange:P=>S(P.target.checked),className:"w-3.5 h-3.5 rounded border-gray-300"}),"Show all models (including unconfigured providers)"]}),K.length>0&&u("div",{className:"mb-3 px-3 py-2 rounded bg-indigo-50 border border-indigo-200 text-xs",children:[i("p",{className:"font-semibold text-indigo-900 mb-1",children:"Local providers available"}),i("ul",{className:"text-indigo-900 space-y-0.5",children:K.map(P=>{var z;return u("li",{children:[i("span",{className:"font-mono",children:P.id})," — ",P.label,(z=P.requiresEnv)!=null&&z.length?u(Ce,{children:[" · needs ",i("code",{className:"px-1 bg-white rounded",children:P.requiresEnv.join(", ")})]}):null]},P.id)})})]}),d&&i("div",{className:"mb-3 px-3 py-2 rounded bg-red-50 border border-red-200 text-red-800 text-xs",children:d}),i("div",{className:"bg-white border border-gray-200 rounded-lg overflow-hidden",children:kt.map((P,z)=>{const V=N?(e==null?void 0:e.providers)??[]:L,T=n[P],E=s[T.primary],Y=nu(E),Ir=V.filter(me=>(me.options[P]??[]).length>0).map(me=>({label:me.label,configured:me.configured,models:me.options[P]??[]})),An=me=>u(Ce,{children:[i("option",{value:"",children:"— select model —"}),Ir.map(Ye=>i("optgroup",{label:`${Ye.configured?"":"○ "}${Ye.label}`,children:Ye.models.map(wt=>i("option",{value:wt,children:D(wt)},wt))},Ye.label)),me&&!j(P).includes(me)&&u("option",{value:me,children:[D(me)," (current)"]})]});return u("div",{className:`px-3 py-2.5 ${z>0?"border-t border-gray-200":""}`,children:[u("div",{className:"flex items-center justify-between mb-2",children:[i("p",{className:"text-xs font-semibold text-gray-700 uppercase tracking-wide",children:P}),i("button",{onClick:()=>$e(P),disabled:!A[P]||v===P,className:A[P]?F:U,children:v===P?"Saving…":A[P]?"Save":"Saved"})]}),u("div",{className:"grid grid-cols-[80px_1fr] items-center gap-x-2 gap-y-1",children:[i("label",{className:"text-xs font-medium text-gray-700",children:"Primary"}),u("div",{children:[i("select",{value:T.primary,onChange:me=>O(P,me.target.value),className:"w-full px-2 py-1 text-xs border border-gray-300 rounded bg-white",children:An(T.primary)}),Y&&T.primary&&i("p",{className:"text-[10px] text-gray-600 mt-0.5 font-mono",children:Y})]}),i("label",{className:"text-xs font-medium text-gray-700 self-start pt-1",children:"Fallback"}),u("div",{children:[T.fallback.length===0&&i("p",{className:"text-xs text-gray-600 mb-1",children:"none"}),T.fallback.map((me,Ye)=>u("div",{className:"flex gap-1 mb-1",children:[i("select",{value:me,onChange:wt=>H(P,Ye,wt.target.value),className:"flex-1 px-2 py-1 text-xs border border-gray-300 rounded bg-white",children:An(me)}),i("button",{onClick:()=>fe(P,Ye),className:"px-2 py-0.5 text-xs font-medium rounded border border-red-300 bg-white text-red-700 hover:bg-red-50 transition-colors",children:"×"})]},Ye)),i("button",{onClick:()=>B(P),className:"text-xs font-medium text-indigo-700 hover:text-indigo-900 transition-colors",children:"+ Add fallback"})]})]})]},P)})}),u("p",{className:"mt-4 text-xs text-gray-600",children:["Need to add or rotate an API key? Manage credentials on the"," ",i("a",{href:"#/providers",className:"underline hover:no-underline text-indigo-700",children:"Providers"})," page — the single edit surface for every provider env var."]})]})}const bx=["open","in_progress","blocked","closed","deferred"],Ip={open:"Open",in_progress:"In progress",blocked:"Blocked",closed:"Closed",deferred:"Deferred"},Dp={open:"bg-gray-400",in_progress:"bg-blue-500",blocked:"bg-red-500",closed:"bg-green-500",deferred:"bg-gray-300"},kx={open:"bg-gray-100 text-gray-700",in_progress:"bg-blue-100 text-blue-800",blocked:"bg-red-100 text-red-800",closed:"bg-green-100 text-green-800",deferred:"bg-gray-100 text-gray-700"},Sx={0:"bg-red-100 text-red-800",1:"bg-orange-100 text-orange-800",2:"bg-yellow-100 text-yellow-800",3:"bg-gray-100 text-gray-700"},Cx="px-2.5 py-1 text-xs font-medium rounded border border-gray-300 bg-white text-gray-800 hover:bg-gray-100 transition-colors disabled:opacity-50",ru="px-2.5 py-1 text-xs font-medium rounded-full border transition-colors";function lu(e){const t=Date.now()-new Date(e).getTime();if(Number.isNaN(t)||t<0)return e.slice(0,10);const n=Math.floor(t/1e3);if(n<60)return`${n}s ago`;const r=Math.floor(n/60);if(r<60)return`${r}m ago`;const l=Math.floor(r/60);if(l<24)return`${l}h ago`;const a=Math.floor(l/24);return a<30?`${a}d ago`:`${Math.floor(a/30)}mo ago`}function Ex(){const[e,t]=m.useState(null),[n,r]=m.useState(!0),[l,a]=m.useState("open"),[s,o]=m.useState("all"),[c,p]=m.useState(new Set),f=()=>Jg().then(t).catch(()=>{});m.useEffect(()=>{f().finally(()=>r(!1))},[]);const x=m.useMemo(()=>{if(!e)return[];let y=e.issues;return l!=="all"&&(y=y.filter(w=>w.status===l)),s!=="all"&&(y=y.filter(w=>`P${w.priority}`===s)),[...y].sort((w,b)=>w.priority!==b.priority?w.priority-b.priority:new Date(b.updated_at).getTime()-new Date(w.updated_at).getTime())},[e,l,s]),v=y=>p(w=>{const b=new Set(w);return b.has(y)?b.delete(y):b.add(y),b});return n?i("div",{className:"text-center py-20 text-gray-600",children:"Loading..."}):e?u("div",{children:[u("div",{className:"flex items-center justify-between mb-4",children:[u("h1",{className:"text-xl font-bold",children:["Beads ",u("span",{className:"text-gray-600 font-normal text-sm",children:["— ",e.counts.total," issues"]})]}),i("button",{onClick:f,className:Cx,children:"Refresh"})]}),u("div",{className:"flex flex-wrap items-center gap-2 mb-2",children:[i("span",{className:"text-xs font-semibold text-gray-700 uppercase tracking-wide mr-1",children:"Status"}),i(qr,{label:`All (${e.counts.total})`,active:l==="all",onClick:()=>a("all")}),bx.map(y=>{const w=e.counts.byStatus[y]||0;return w===0&&y!=="open"?null:i(qr,{label:`${Ip[y]} (${w})`,active:l===y,onClick:()=>a(y),dotClass:Dp[y]},y)})]}),u("div",{className:"flex flex-wrap items-center gap-2 mb-4",children:[i("span",{className:"text-xs font-semibold text-gray-700 uppercase tracking-wide mr-1",children:"Priority"}),i(qr,{label:"All",active:s==="all",onClick:()=>o("all")}),[0,1,2,3].map(y=>{const w=`P${y}`,b=e.counts.byPriority[w]||0;return b===0?null:i(qr,{label:`${w} (${b})`,active:s===w,onClick:()=>o(w)},y)})]}),i("div",{className:"bg-white border border-gray-200 rounded-lg overflow-hidden",children:u("table",{className:"w-full text-sm",children:[i("thead",{className:"bg-gray-50 border-b border-gray-200",children:u("tr",{className:"text-xs uppercase tracking-wide text-gray-700",children:[i("th",{className:"text-left px-3 py-1.5 font-semibold w-14",children:"Pri"}),i("th",{className:"text-left px-3 py-1.5 font-semibold w-28",children:"Status"}),i("th",{className:"text-left px-3 py-1.5 font-semibold",children:"Title"}),i("th",{className:"text-left px-3 py-1.5 font-semibold w-32",children:"Owner"}),i("th",{className:"text-left px-3 py-1.5 font-semibold w-24",children:"Updated"})]})}),i("tbody",{className:"divide-y divide-gray-100",children:x.length===0?i("tr",{children:i("td",{colSpan:5,className:"px-3 py-6 text-center text-xs text-gray-600",children:"No issues match these filters."})}):x.map(y=>i(Px,{it:y,expanded:c.has(y.id),onToggle:()=>v(y.id)},y.id))})]})})]}):i("div",{className:"text-center py-20 text-gray-600",children:"No bead data."})}function qr({label:e,active:t,onClick:n,dotClass:r}){const l=t?`${ru} bg-indigo-600 border-indigo-600 text-white`:`${ru} bg-white border-gray-300 text-gray-800 hover:bg-gray-100`;return u("button",{onClick:n,className:l,children:[r&&i("span",{className:`inline-block h-1.5 w-1.5 rounded-full mr-1.5 align-middle ${r}`}),e]})}function Px({it:e,expanded:t,onToggle:n}){const r=e.owner?e.owner.split("@")[0]:"—";return u(Ce,{children:[u("tr",{className:"hover:bg-gray-50 cursor-pointer",onClick:n,children:[i("td",{className:"px-3 py-1.5",children:u("span",{className:`text-xs font-semibold px-1.5 py-0.5 rounded ${Sx[e.priority]||"bg-gray-100 text-gray-700"}`,children:["P",e.priority]})}),i("td",{className:"px-3 py-1.5",children:u("span",{className:`text-xs px-1.5 py-0.5 rounded inline-flex items-center gap-1 ${kx[e.status]||"bg-gray-100 text-gray-700"}`,children:[i("span",{className:`h-1.5 w-1.5 rounded-full ${Dp[e.status]||"bg-gray-400"}`}),Ip[e.status]||e.status]})}),i("td",{className:"px-3 py-1.5",children:u("div",{className:"flex items-center gap-2 min-w-0",children:[i("span",{className:"text-sm text-gray-900 truncate",children:e.title}),i("code",{className:"text-xs text-gray-600 font-mono flex-shrink-0",children:e.id}),e.issue_type&&i("span",{className:"text-xs px-1.5 py-0.5 rounded bg-gray-100 text-gray-700 flex-shrink-0",children:e.issue_type}),e.dependency_count>0&&u("span",{className:"text-xs text-gray-600 flex-shrink-0",children:["⟵ ",e.dependency_count]}),e.dependent_count>0&&u("span",{className:"text-xs text-gray-600 flex-shrink-0",children:["⟶ ",e.dependent_count]}),e.comment_count>0&&u("span",{className:"text-xs text-gray-600 flex-shrink-0",children:["💬 ",e.comment_count]})]})}),i("td",{className:"px-3 py-1.5",children:i("span",{className:"text-xs text-gray-700 truncate",title:e.owner||"",children:r})}),i("td",{className:"px-3 py-1.5",children:i("span",{className:"text-xs text-gray-700",title:e.updated_at,children:lu(e.updated_at)})})]}),t&&e.description&&i("tr",{className:"bg-gray-50",children:u("td",{colSpan:5,className:"px-6 py-3",children:[i("p",{className:"text-xs text-gray-700 whitespace-pre-wrap",children:e.description}),u("p",{className:"text-xs text-gray-600 mt-2",children:["Created ",lu(e.created_at)," · use ",u("code",{className:"px-1 py-0.5 bg-gray-200 rounded",children:["bd show ",e.id]})," for full details"]})]})})]})}function _x(){const[e,t]=m.useState([]),[n,r]=m.useState(!0),[l,a]=m.useState("all");m.useEffect(()=>{kg().then(o=>t(o.artifacts??[])).catch(()=>{}).finally(()=>r(!1))},[]);const s=l==="all"?e:e.filter(o=>o.type===l);return n?i("div",{className:"text-center py-20 text-gray-600",children:"Loading..."}):u("div",{children:[u("div",{className:"flex items-center justify-between mb-6",children:[i("h1",{className:"text-2xl font-bold",children:"Artifacts"}),i("div",{className:"flex gap-1 bg-gray-100 rounded-lg p-1",children:["all","prd","adr","rfc"].map(o=>i("button",{onClick:()=>a(o),className:`px-3 py-1.5 text-sm font-medium rounded-md transition-colors ${l===o?"bg-white text-gray-900 shadow-sm":"text-gray-500 hover:text-gray-700"}`,children:o.toUpperCase()},o))})]}),s.length===0?u("div",{className:"text-center py-20 text-gray-600",children:["No ",l==="all"?"":l.toUpperCase()," artifacts."]}):i("div",{className:"grid grid-cols-1 gap-3",children:s.map((o,c)=>u("div",{className:"bg-white border border-gray-200 rounded-xl p-5 flex items-start justify-between",children:[u("div",{children:[i("span",{className:"text-xs font-semibold uppercase tracking-wide text-gray-600",children:o.type}),i("p",{className:"font-semibold mt-0.5",children:o.title}),i("p",{className:"text-xs text-gray-600 font-mono mt-1",children:o.relativePath??""})]}),i("span",{className:`text-xs font-medium px-2 py-0.5 rounded-full ${o.status==="healthy"?"bg-green-100 text-green-800":o.status==="degraded"?"bg-yellow-100 text-yellow-800":o.status==="unavailable"?"bg-red-100 text-red-800":"bg-gray-100 text-gray-600"}`,children:o.status})]},c))})]})}function Lx(){var b,C;const[e,t]=m.useState("ask"),[n,r]=m.useState(""),[l,a]=m.useState(null),[s,o]=m.useState(null),[c,p]=m.useState(null),[f,x]=m.useState(!1),v=async()=>{if(n.trim()){x(!0);try{a(await Og(n))}catch{}x(!1)}},y=async()=>{x(!0);try{o(await Tg())}catch{}x(!1)},w=async()=>{x(!0);try{p(await Rg())}catch{}x(!1)};return u("div",{children:[i("h1",{className:"text-2xl font-bold mb-6",children:"Knowledge"}),i("div",{className:"flex gap-1 bg-gray-100 rounded-lg p-1 mb-6 w-fit",children:["ask","trends","index"].map(g=>i("button",{onClick:()=>{t(g),g==="trends"&&y(),g==="index"&&w()},className:`px-3 py-1.5 text-sm font-medium rounded-md transition-colors ${e===g?"bg-white text-gray-900 shadow-sm":"text-gray-500 hover:text-gray-700"}`,children:g.charAt(0).toUpperCase()+g.slice(1)},g))}),e==="ask"&&u("div",{className:"bg-white border border-gray-200 rounded-xl p-6",children:[u("div",{className:"flex gap-3 mb-4",children:[i("input",{value:n,onChange:g=>r(g.target.value),onKeyDown:g=>g.key==="Enter"&&v(),placeholder:'e.g. "what are the biggest risks?"',className:"flex-1 border border-gray-200 rounded-lg px-4 py-2 text-sm focus:outline-none focus:border-indigo-400"}),i("button",{onClick:v,disabled:f,className:"bg-gradient-to-r from-indigo-600 to-violet-600 text-white px-5 py-2 rounded-lg text-sm font-medium hover:from-indigo-700 hover:to-violet-700 transition-colors disabled:opacity-50",children:"Ask"})]}),f&&i("p",{className:"text-sm text-gray-600",children:"Thinking..."}),l&&u("div",{className:"bg-gray-50 rounded-lg p-4",children:[i("p",{className:"text-sm whitespace-pre-wrap",children:l.answer}),((b=l.sources)==null?void 0:b.length)>0&&u("div",{className:"mt-3 text-xs text-gray-600",children:[i("p",{className:"font-medium mb-1",children:"Sources:"}),l.sources.slice(0,5).map((g,d)=>u("p",{children:["[",g.source,"] ",g.title]},d))]})]})]}),e==="trends"&&s&&i("div",{className:"grid grid-cols-1 gap-4",children:((C=s.hotTopics)==null?void 0:C.length)>0&&u("div",{className:"bg-white border border-gray-200 rounded-xl p-6",children:[i("p",{className:"font-semibold mb-3",children:"Hot Topics"}),i("div",{className:"flex flex-wrap gap-2",children:s.hotTopics.map((g,d)=>i("span",{style:{fontSize:`${12+g.weightedFrequency*8}px`},className:"bg-gradient-to-r from-indigo-50 to-violet-50 text-indigo-700 px-2 py-0.5 rounded-full",children:g.term},d))})]})}),e==="index"&&c&&u("div",{className:"bg-white border border-gray-200 rounded-xl p-6",children:[u("p",{className:"font-semibold mb-2",children:["Corpus — ",c.total," total chunks"]}),i("div",{className:"space-y-1",children:Object.entries(c.sources??{}).map(([g,d],h)=>u("p",{className:"text-sm text-gray-600",children:[g,": ",d," chunks"]},h))})]})]})}function Tx({initialPath:e,onPick:t,onClose:n}){const[r,l]=m.useState(null),[a,s]=m.useState(null),[o,c]=m.useState(!0),p=f=>{c(!0),s(null),zg(f||void 0).then(x=>l(x)).catch(x=>s((x==null?void 0:x.message)||"Failed to browse filesystem")).finally(()=>c(!1))};return m.useEffect(()=>{p(e??void 0)},[e]),m.useEffect(()=>{const f=x=>{x.key==="Escape"&&n()};return window.addEventListener("keydown",f),()=>window.removeEventListener("keydown",f)},[n]),i("div",{className:"fixed inset-0 z-50 flex items-center justify-center p-4 sm:p-6 bg-black/50",role:"dialog","aria-modal":"true","aria-label":"Choose a directory",children:u("div",{className:"bg-surface border border-border rounded-lg w-full max-w-2xl max-h-[80vh] flex flex-col shadow-xl",children:[u("header",{className:"px-4 py-3 border-b border-border flex items-center justify-between gap-2",children:[i("h2",{className:"text-sm font-semibold",children:"Choose a directory"}),i("button",{onClick:n,"aria-label":"Close",className:"text-xl leading-none px-2",children:"×"})]}),u("div",{className:"px-4 py-2 border-b border-border text-xs text-text-muted flex items-center gap-2 flex-wrap",children:[i("button",{onClick:()=>(r==null?void 0:r.parent)&&p(r.parent),disabled:!(r!=null&&r.parent),className:"px-2 py-1 rounded border border-border bg-bg-muted disabled:opacity-40","aria-label":"Go up one directory",children:"↑"}),i("code",{className:"font-mono break-all flex-1 min-w-0",children:(r==null?void 0:r.path)||"…"})]}),(r==null?void 0:r.roots)&&u("div",{className:"px-4 py-2 border-b border-border text-xs flex items-center gap-2 flex-wrap",children:[i("span",{className:"text-text-dim",children:"Jump to:"}),r.roots.map(f=>i("button",{onClick:()=>p(f),className:"px-2 py-0.5 rounded border border-border bg-bg-muted hover:bg-bg-emphasis font-mono",children:f},f))]}),u("div",{className:"flex-1 overflow-y-auto px-2 py-1",children:[o&&i("p",{className:"text-xs text-text-dim px-2 py-3",children:"Loading…"}),a&&i("p",{className:"text-xs text-red-700 px-2 py-3",children:a}),!o&&!a&&r&&r.entries.length===0&&i("p",{className:"text-xs text-text-dim px-2 py-3 italic",children:"Empty directory."}),!o&&!a&&r&&r.entries.map(f=>u("button",{onClick:()=>f.type==="dir"&&p(`${r.path}/${f.name}`),disabled:f.type!=="dir",className:"w-full text-left px-2 py-1 text-sm rounded hover:bg-bg-muted disabled:opacity-50 disabled:cursor-not-allowed flex items-center gap-2",children:[i("span",{"aria-hidden":"true",className:"text-base",children:f.type==="dir"?"📁":"📄"}),i("span",{className:"font-mono truncate",children:f.name}),f.type!=="dir"&&i("span",{className:"text-[10px] text-text-dim ml-auto",children:"file"})]},f.name))]}),u("footer",{className:"px-4 py-3 border-t border-border flex items-center justify-end gap-2 flex-wrap",children:[i("button",{onClick:n,className:"btn text-xs",children:"Cancel"}),i("button",{onClick:()=>r&&t(r.path),disabled:!(r!=null&&r.path),className:"btn btn-primary text-xs disabled:opacity-50",children:"Use this directory"})]})]})})}function Rx(){const[e,t]=m.useState(null),[n,r]=m.useState([]),[l,a]=m.useState(4),[s,o]=m.useState(!0),[c,p]=m.useState(!0),[f,x]=m.useState(""),[v,y]=m.useState(!1),[w,b]=m.useState(!1),[C,g]=m.useState(null),[d,h]=m.useState(null);m.useEffect(()=>{jg().then(k=>{t(k),r(k.config.parentDirs??[]),a(k.config.maxDepth??4),o(k.config.includeProjectInbox!==!1),p(k.config.includeDocsIntake!==!1)}).catch(k=>g(k.message||"Failed to load intake config"))},[]);const N=m.useMemo(()=>((e==null?void 0:e.guidance)??[]).find(A=>A.value===l)||{value:l,label:`Custom depth (${l})`,detail:`Walks up to ${l} levels of subdirectories below each parent.`},[e,l]),S=()=>{const k=f.trim();if(k){if(n.includes(k)){x("");return}r([...n,k]),x("")}},L=k=>{r(n.filter((A,j)=>j!==k))},R=async()=>{b(!0),g(null);try{const k=await Fg({parentDirs:n,maxDepth:l,includeProjectInbox:s,includeDocsIntake:c});h(new Date().toISOString()),k!=null&&k.config&&(r(k.config.parentDirs??[]),a(k.config.maxDepth??l))}catch(k){g(k.message||"Save failed")}finally{b(!1)}};return e?u("div",{className:"max-w-3xl",children:[i(Ms,{}),i("h1",{className:"text-xl font-bold mb-1",children:"Intake"}),u("p",{className:"text-sm text-text-muted mb-4",children:["Pick the directories the inbox watcher monitors and how deep it descends. Files are ingested into ",i("code",{className:"px-1 bg-bg-muted rounded",children:".cx/knowledge/"})," and queued for triage at ",i("code",{className:"px-1 bg-bg-muted rounded",children:".cx/intake/pending/"}),"."]}),C&&i("div",{className:"mb-3 px-3 py-2 rounded bg-red-50 border border-red-200 text-red-800 text-xs",children:C}),d&&!C&&u("div",{className:"mb-3 px-3 py-2 rounded bg-green-50 border border-green-200 text-green-800 text-xs",children:["Saved at ",new Date(d).toLocaleTimeString(),". The embed daemon picks this up on its next poll cycle."]}),u("section",{className:"card mb-4",children:[i("h2",{className:"text-xs uppercase tracking-wider text-text-dim mb-2",children:"Built-in drop zones"}),i("p",{className:"text-xs text-text-muted mb-3",children:"Always-on locations relative to the project root. Disable a zone if you don't want construct to look there."}),u("label",{className:"flex items-start gap-2 mb-2 text-sm",children:[i("input",{type:"checkbox",checked:s,onChange:k=>o(k.target.checked),className:"mt-0.5"}),u("span",{children:[i("code",{className:"px-1 bg-bg-muted rounded",children:e.defaults.projectInbox}),i("span",{className:"text-text-dim",children:" — drop folder created on demand. Recommended."})]})]}),u("label",{className:"flex items-start gap-2 text-sm",children:[i("input",{type:"checkbox",checked:c,onChange:k=>p(k.target.checked),className:"mt-0.5"}),u("span",{children:[i("code",{className:"px-1 bg-bg-muted rounded",children:e.defaults.docsIntake}),u("span",{className:"text-text-dim",children:[" — picked up when the dir exists (created by ",i("code",{children:"construct docs init"}),")."]})]})]})]}),u("section",{className:"card mb-4",children:[i("h2",{className:"text-xs uppercase tracking-wider text-text-dim mb-2",children:"Parent directories"}),u("p",{className:"text-xs text-text-muted mb-3",children:["Absolute paths or relative to ",i("code",{className:"px-1 bg-bg-muted rounded",children:e.rootDir}),". The watcher scans these in addition to the built-in zones above."]}),n.length===0&&i("p",{className:"text-xs text-text-dim italic mb-3",children:"No extra directories configured."}),i("ul",{className:"mb-3 space-y-1",children:n.map((k,A)=>u("li",{className:"flex items-center justify-between bg-bg-muted rounded px-2 py-1 text-sm",children:[i("code",{className:"font-mono text-xs truncate",children:k}),i("button",{onClick:()=>L(A),className:"text-xs text-red-700 hover:text-red-900 ml-2","aria-label":`Remove ${k}`,children:"Remove"})]},`${k}-${A}`))}),u("div",{className:"flex gap-2 flex-wrap",children:[i("input",{type:"text",value:f,onChange:k=>x(k.target.value),onKeyDown:k=>k.key==="Enter"&&S(),placeholder:"/Users/you/Documents/intake or ../shared-notes",className:"flex-1 min-w-[200px] px-2 py-1 text-sm border border-border rounded bg-bg"}),i("button",{onClick:()=>y(!0),className:"btn text-xs","aria-label":"Browse for directory",children:"Browse…"}),i("button",{onClick:S,disabled:!f.trim(),className:"btn btn-primary text-xs disabled:opacity-50",children:"Add directory"})]}),u("p",{className:"text-[11px] text-text-dim mt-2",children:["Type a path manually (relative or absolute), or click ",i("strong",{children:"Browse…"})," to pick one from your filesystem. Browsing is gated to your home directory and the project root."]})]}),v&&i(Tx,{initialPath:f.trim()||null,onClose:()=>y(!1),onPick:k=>{n.includes(k)||r([...n,k]),y(!1)}}),u("section",{className:"card mb-4",children:[i("h2",{className:"text-xs uppercase tracking-wider text-text-dim mb-2",children:"Subdirectory depth"}),i("p",{className:"text-xs text-text-muted mb-3",children:"How many levels of nested subdirectories the watcher walks below each parent. Higher values are slower on large trees."}),u("div",{className:"flex items-center gap-3 mb-3",children:[i("input",{type:"range",min:0,max:e.hardMaxDepth,value:l,onChange:k=>a(Number(k.target.value)),className:"flex-1","aria-label":"Maximum subdirectory depth"}),i("span",{className:"font-mono text-sm w-8 text-right",children:l})]}),u("div",{className:"bg-bg-muted rounded px-3 py-2 text-xs",children:[i("p",{className:"font-semibold",children:N.label}),i("p",{className:"text-text-muted",children:N.detail})]}),u("details",{className:"mt-2",children:[i("summary",{className:"text-xs text-text-dim cursor-pointer hover:text-text",children:"Depth guide"}),i("ul",{className:"mt-2 space-y-1 text-xs",children:e.guidance.map(k=>u("li",{children:[i("span",{className:"font-mono mr-2",children:k.value}),i("span",{className:"font-semibold",children:k.label})," — ",i("span",{className:"text-text-muted",children:k.detail})]},k.value))})]})]}),u("div",{className:"flex gap-2 items-center",children:[i("button",{onClick:R,disabled:w,className:"btn btn-primary",children:w?"Saving…":"Save intake configuration"}),u("p",{className:"text-xs text-text-dim",children:["Backed by ",i("code",{className:"px-1 bg-bg-muted rounded",children:".cx/intake-config.json"}),"."]})]})]}):u("div",{children:[i("h1",{className:"text-xl font-bold mb-2",children:"Intake"}),C?i("p",{className:"text-sm text-red-700",children:C}):i("p",{className:"text-sm text-text-dim",children:"Loading intake configuration…"})]})}const Fa="/api";function Ox(){const[e,t]=m.useState([]),[n,r]=m.useState(null),[l,a]=m.useState(""),[s,o]=m.useState(""),[c,p]=m.useState(""),[f,x]=m.useState(!1),[v,y]=m.useState(!0),[w,b]=m.useState(!1),C=m.useRef(null);m.useEffect(()=>{Mg().then(N=>{t(N.files??[])}).catch(()=>{}).finally(()=>y(!1))},[]),m.useEffect(()=>{n?fetch(`${Fa}/terraform/file?path=${encodeURIComponent(n)}`).then(N=>N.json()).then(N=>{a(N.content??""),o(N.content??"")}).catch(()=>{}):(a(""),o(""))},[n]);const g=l!==s,d=async()=>{if(!(!n||!g)){b(!0);try{await fetch(`${Fa}/terraform/file`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:n,content:l})}),o(l)}catch{}b(!1)}},h=async N=>{var S;x(!0),p("");try{const R=(S=(await fetch(`${Fa}/terraform/run`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({subcommand:N,environment:"staging"})})).body)==null?void 0:S.getReader(),k=new TextDecoder;if(R)for(;;){const{done:A,value:j}=await R.read();if(A)break;p(D=>D+k.decode(j,{stream:!0}))}}catch(L){p(`Error: ${L.message}`)}x(!1)};return v?i("div",{className:"text-center py-20 text-gray-600",children:"Loading..."}):u("div",{className:"flex flex-col h-full",children:[i("h1",{className:"text-2xl font-bold mb-6",children:"Infrastructure"}),u("div",{className:"flex gap-6 flex-1 min-h-0",children:[u("div",{className:"w-56 flex-shrink-0 bg-white border border-gray-200 rounded-xl overflow-hidden",children:[i("div",{className:"px-4 py-3 border-b border-gray-100",children:i("p",{className:"text-sm font-semibold text-gray-500 uppercase tracking-wide",children:"Terraform Files"})}),u("div",{className:"divide-y divide-gray-50",children:[e.length===0&&i("p",{className:"px-4 py-6 text-sm text-gray-600 text-center",children:"No .tf files found."}),e.map(N=>i("button",{onClick:()=>r(N),className:`w-full text-left px-4 py-2.5 text-sm transition-colors ${n===N?"bg-gradient-to-r from-indigo-50 to-violet-50 text-indigo-700 font-medium border-r-2 border-indigo-500":"text-gray-600 hover:bg-gray-50"}`,children:N},N))]})]}),n?u("div",{className:"flex-1 flex flex-col min-w-0",children:[u("div",{className:"flex items-center justify-between mb-3",children:[u("div",{className:"flex items-center gap-2",children:[i("span",{className:"text-sm font-medium text-gray-700",children:n}),g&&i("span",{className:"text-yellow-600 text-sm font-medium",children:"● unsaved"})]}),u("div",{className:"flex gap-2",children:[i("button",{onClick:d,disabled:!g||w,className:"px-3 py-1.5 text-sm font-medium rounded-lg bg-gradient-to-r from-indigo-600 to-violet-600 text-white hover:from-indigo-700 hover:to-violet-700 transition-colors disabled:opacity-50",children:w?"Saving...":"Save"}),i("button",{onClick:()=>h("validate"),disabled:f,className:"px-3 py-1.5 text-sm font-medium rounded-lg bg-gray-100 text-gray-700 hover:bg-gray-200 transition-colors disabled:opacity-50",children:"Validate"}),i("button",{onClick:()=>h("output"),disabled:f,className:"px-3 py-1.5 text-sm font-medium rounded-lg bg-gray-100 text-gray-700 hover:bg-gray-200 transition-colors disabled:opacity-50",children:"Outputs"})]})]}),i("textarea",{value:l,onChange:N=>a(N.target.value),className:"flex-1 font-mono text-sm p-4 border border-gray-200 rounded-xl resize-none focus:outline-none focus:border-indigo-400 bg-gray-50",spellCheck:!1}),c!==""||f?u("div",{className:"mt-4",children:[u("div",{className:"flex items-center gap-2 mb-2",children:[i("p",{className:"text-sm font-semibold text-gray-500 uppercase tracking-wide",children:"Output"}),f&&i("span",{className:"text-indigo-600 text-xs animate-pulse",children:"Running..."})]}),i("pre",{ref:C,className:"bg-gray-900 text-green-400 text-xs p-4 rounded-xl overflow-auto max-h-64 font-mono leading-relaxed whitespace-pre-wrap",children:c||"Waiting..."})]}):u("div",{className:"flex gap-2 mt-4",children:[i("button",{onClick:()=>h("plan"),disabled:f,className:"px-4 py-2 text-sm font-medium rounded-lg bg-gray-900 text-white hover:bg-gray-800 transition-colors disabled:opacity-50",children:"Plan"}),i("button",{onClick:()=>h("apply"),disabled:f,className:"px-4 py-2 text-sm font-medium rounded-lg bg-gradient-to-r from-indigo-600 to-violet-600 text-white hover:from-indigo-700 hover:to-violet-700 transition-colors disabled:opacity-50",children:"Apply"})]})]}):i("div",{className:"flex-1 flex items-center justify-center text-gray-600",children:i("p",{className:"text-lg",children:"Select a Terraform file to edit"})})]})]})}const Mx=["solo","team","enterprise"],Ix=["auto","on","off"];function Dx(){var h,N,S,L,R,k,A,j,D,O,H,B,fe,$e,Le,M,F,U,K,G,P,z,V;const[e,t]=m.useState(null),[n,r]=m.useState(null),[l,a]=m.useState("default"),[s,o]=m.useState(null),[c,p]=m.useState([]),[f,x]=m.useState(!1),[v,y]=m.useState(null),[w,b]=m.useState(null);if(m.useEffect(()=>{Eg().then(T=>{t(T.config),r(JSON.parse(JSON.stringify(T.config))),a(T.source),o(T.path),p(T.errors||[])}).catch(T=>b(T.message))},[]),w)return u("section",{className:"card max-w-2xl",children:[i("h1",{className:"text-lg font-semibold mb-2",children:"Config unavailable"}),i("p",{className:"text-text-muted text-sm",children:w})]});if(!e)return i("p",{className:"text-text-dim text-sm",children:"Loading config…"});const C=JSON.stringify(e)!==JSON.stringify(n);async function g(){if(e){x(!0),y(null),p([]);try{const T=await Lg(e);y(`Saved to ${T.path}`),r(JSON.parse(JSON.stringify(e)))}catch(T){p([T.message||String(T)])}finally{x(!1)}}}function d(){n&&(t(JSON.parse(JSON.stringify(n))),y(null),p([]))}return u("div",{className:"max-w-4xl space-y-8",children:[i(Ms,{}),u("header",{children:[i("p",{className:"text-text-dim text-xs uppercase tracking-wider mb-1",children:"Page"}),i("h1",{className:"text-2xl sm:text-3xl font-semibold tracking-tight",children:"Configuration"}),u("p",{className:"text-text-muted text-sm mt-2",children:["Edits write to ",i("code",{className:"px-1 py-0.5 bg-bg-muted rounded",children:"construct.config.json"})," at the project root. Secrets stay in ",i("code",{className:"px-1 py-0.5 bg-bg-muted rounded",children:".env"}),"."]}),u("p",{className:"text-text-dim text-xs mt-2",children:["Source: ",i("span",{className:"font-mono",children:l}),s&&u(Ce,{children:[" · ",s]})]})]}),c.length>0&&u("div",{className:"card",style:{borderColor:"var(--status-down)"},children:[i("h3",{className:"font-medium mb-2",children:"Save failed"}),i("ul",{className:"text-sm text-text-muted list-disc list-inside",children:c.map((T,E)=>i("li",{children:T},E))})]}),v&&i("div",{className:"card",style:{borderColor:"var(--status-healthy)"},children:i("p",{className:"text-sm",children:v})}),u("section",{className:"card space-y-4","aria-labelledby":"general-heading",children:[i("h2",{id:"general-heading",className:"text-sm uppercase tracking-wider text-text-dim",children:"General"}),u("p",{className:"text-xs text-text-muted",children:["Alias is edited in the sidebar wordmark — click ",i("strong",{children:e.alias??"Construct"})," in the top-left to rename."]}),i(Te,{label:"Deployment mode",help:"Routes the intake queue, worker pool, and telemetry backend.",children:i("select",{value:((h=e.deployment)==null?void 0:h.mode)??"solo",onChange:T=>t(E=>({...E,deployment:{...E==null?void 0:E.deployment,mode:T.target.value}})),className:"w-full px-3 py-2 border border-border rounded bg-surface",children:Mx.map(T=>i("option",{value:T,children:T},T))})}),i(Te,{label:"MCP broker",help:"auto = team/enterprise on, solo off. on/off override.",children:i("select",{value:((N=e.deployment)==null?void 0:N.mcpBroker)??"auto",onChange:T=>t(E=>({...E,deployment:{...E==null?void 0:E.deployment,mcpBroker:T.target.value}})),className:"w-full px-3 py-2 border border-border rounded bg-surface",children:Ix.map(T=>i("option",{value:T,children:T},T))})}),i(Te,{label:"Auto-start embed daemon",help:"Session-start auto-launches the embed daemon when off.",children:u("label",{className:"inline-flex items-center gap-2",children:[i("input",{type:"checkbox",checked:!!e.autoEmbed,onChange:T=>t(E=>({...E,autoEmbed:T.target.checked}))}),i("span",{className:"text-sm",children:e.autoEmbed?"on":"off"})]})}),i(Te,{label:"Telemetry (Remote ingest)",help:"When off, R&D-loop traces stay in .cx/traces/ only.",children:u("label",{className:"inline-flex items-center gap-2",children:[i("input",{type:"checkbox",checked:((S=e.telemetry)==null?void 0:S.enabled)!==!1,onChange:T=>t(E=>({...E,telemetry:{...E==null?void 0:E.telemetry,enabled:T.target.checked}}))}),i("span",{className:"text-sm",children:((L=e.telemetry)==null?void 0:L.enabled)!==!1?"on":"off"})]})})]}),u("section",{className:"card space-y-4","aria-labelledby":"roles-heading",children:[i("h2",{id:"roles-heading",className:"text-sm uppercase tracking-wider text-text-dim",children:"Team Configuration"}),u("p",{className:"text-xs text-text-muted",children:["Set your default primary and secondary personas. The primary sets the analysis lens; the secondary provides complementary perspective. Override per-conversation with ",i("code",{className:"px-1 py-0.5 bg-bg-muted rounded",children:"@construct --primary=cx-pm --secondary=cx-arch"}),"."]}),i(Te,{label:"Primary persona",help:"Default orientation for all work. Leave null for automatic routing.",children:u("select",{value:((R=e.roleSelection)==null?void 0:R.primary)??"",onChange:T=>t(E=>({...E,roleSelection:{...E==null?void 0:E.roleSelection,primary:T.target.value||null}})),className:"w-full px-3 py-2 border border-border rounded bg-surface",children:[i("option",{value:"",children:"Automatic (context-based)"}),i("option",{value:"cx-product-manager",children:"cx-product-manager"}),i("option",{value:"cx-architect",children:"cx-architect"}),i("option",{value:"cx-engineer",children:"cx-engineer"}),i("option",{value:"cx-debugger",children:"cx-debugger"}),i("option",{value:"cx-qa",children:"cx-qa"}),i("option",{value:"cx-sre",children:"cx-sre"}),i("option",{value:"cx-platform-engineer",children:"cx-platform-engineer"}),i("option",{value:"cx-designer",children:"cx-designer"}),i("option",{value:"cx-ux-researcher",children:"cx-ux-researcher"}),i("option",{value:"cx-accessibility",children:"cx-accessibility"}),i("option",{value:"cx-researcher",children:"cx-researcher"}),i("option",{value:"cx-data-analyst",children:"cx-data-analyst"}),i("option",{value:"cx-ai-engineer",children:"cx-ai-engineer"}),i("option",{value:"cx-evaluator",children:"cx-evaluator"}),i("option",{value:"cx-trace-reviewer",children:"cx-trace-reviewer"}),i("option",{value:"cx-security",children:"cx-security"}),i("option",{value:"cx-legal-compliance",children:"cx-legal-compliance"}),i("option",{value:"cx-reviewer",children:"cx-reviewer"}),i("option",{value:"cx-devil-advocate",children:"cx-devil-advocate"}),i("option",{value:"cx-release-manager",children:"cx-release-manager"}),i("option",{value:"cx-docs-keeper",children:"cx-docs-keeper"}),i("option",{value:"cx-business-strategist",children:"cx-business-strategist"}),i("option",{value:"cx-operations",children:"cx-operations"}),i("option",{value:"cx-orchestrator",children:"cx-orchestrator"}),i("option",{value:"cx-rd-lead",children:"cx-rd-lead"})]})}),i(Te,{label:"Secondary persona",help:"Complementary perspective. Leave null for automatic routing.",children:u("select",{value:((k=e.roleSelection)==null?void 0:k.secondary)??"",onChange:T=>t(E=>({...E,roleSelection:{...E==null?void 0:E.roleSelection,secondary:T.target.value||null}})),className:"w-full px-3 py-2 border border-border rounded bg-surface",children:[i("option",{value:"",children:"Automatic (context-based)"}),i("option",{value:"cx-product-manager",children:"cx-product-manager"}),i("option",{value:"cx-architect",children:"cx-architect"}),i("option",{value:"cx-engineer",children:"cx-engineer"}),i("option",{value:"cx-debugger",children:"cx-debugger"}),i("option",{value:"cx-qa",children:"cx-qa"}),i("option",{value:"cx-sre",children:"cx-sre"}),i("option",{value:"cx-platform-engineer",children:"cx-platform-engineer"}),i("option",{value:"cx-designer",children:"cx-designer"}),i("option",{value:"cx-ux-researcher",children:"cx-ux-researcher"}),i("option",{value:"cx-accessibility",children:"cx-accessibility"}),i("option",{value:"cx-researcher",children:"cx-researcher"}),i("option",{value:"cx-data-analyst",children:"cx-data-analyst"}),i("option",{value:"cx-ai-engineer",children:"cx-ai-engineer"}),i("option",{value:"cx-evaluator",children:"cx-evaluator"}),i("option",{value:"cx-trace-reviewer",children:"cx-trace-reviewer"}),i("option",{value:"cx-security",children:"cx-security"}),i("option",{value:"cx-legal-compliance",children:"cx-legal-compliance"}),i("option",{value:"cx-reviewer",children:"cx-reviewer"}),i("option",{value:"cx-devil-advocate",children:"cx-devil-advocate"}),i("option",{value:"cx-release-manager",children:"cx-release-manager"}),i("option",{value:"cx-docs-keeper",children:"cx-docs-keeper"}),i("option",{value:"cx-business-strategist",children:"cx-business-strategist"}),i("option",{value:"cx-operations",children:"cx-operations"}),i("option",{value:"cx-orchestrator",children:"cx-orchestrator"}),i("option",{value:"cx-rd-lead",children:"cx-rd-lead"})]})}),i(Te,{label:"Per-conversation override",help:"Allow CLI overrides with --primary and --secondary flags.",children:u("label",{className:"inline-flex items-center gap-2",children:[i("input",{type:"checkbox",checked:((A=e.roleSelection)==null?void 0:A.perConversationOverride)!==!1,onChange:T=>t(E=>({...E,roleSelection:{...E==null?void 0:E.roleSelection,perConversationOverride:T.target.checked}}))}),i("span",{className:"text-sm",children:((j=e.roleSelection)==null?void 0:j.perConversationOverride)!==!1?"enabled":"disabled"})]})})]}),u("section",{className:"card space-y-2","aria-labelledby":"models-heading",children:[i("h2",{id:"models-heading",className:"text-sm uppercase tracking-wider text-text-dim",children:"Models"}),u("p",{className:"text-xs text-text-muted",children:["Model tiers are configured on the ",i("a",{href:"#/models",className:"underline hover:no-underline",children:"Models page"}),". That page is the single source of truth — selections persist to ",i("code",{className:"px-1 bg-bg-muted rounded",children:"agents/registry.json"})," and stay there. Env vars ",i("code",{className:"px-1 bg-bg-muted rounded",children:"CX_MODEL_REASONING|STANDARD|FAST"})," still override at runtime for CI and ops; they are not editable from the dashboard."]})]}),u("section",{className:"card space-y-4","aria-labelledby":"resources-heading",children:[i("h2",{id:"resources-heading",className:"text-sm uppercase tracking-wider text-text-dim",children:"Resource limits"}),i(Te,{label:".cx/ total cap (MB)",help:"Hard cap on the .cx/ tree. Defaults to 2GB.",children:i("input",{type:"number",min:"100",step:"100",value:((O=(D=e.resources)==null?void 0:D.disk)==null?void 0:O.totalCxMaxMb)??2e3,onChange:T=>t(E=>{var Y;return{...E,resources:{...E==null?void 0:E.resources,disk:{...(Y=E==null?void 0:E.resources)==null?void 0:Y.disk,totalCxMaxMb:Number(T.target.value)}}}}),className:"w-full px-3 py-2 border border-border rounded bg-surface"})}),i(Te,{label:"Trace retention (days)",help:"JSONL traces in .cx/traces/ rotate past this age.",children:i("input",{type:"number",min:"1",value:((B=(H=e.resources)==null?void 0:H.disk)==null?void 0:B.tracesMaxDays)??30,onChange:T=>t(E=>{var Y;return{...E,resources:{...E==null?void 0:E.resources,disk:{...(Y=E==null?void 0:E.resources)==null?void 0:Y.disk,tracesMaxDays:Number(T.target.value)}}}}),className:"w-full px-3 py-2 border border-border rounded bg-surface"})}),i(Te,{label:"Backup retention (days)",help:"Persona/skill/rules edit backups in .cx/backups/.",children:i("input",{type:"number",min:"1",value:(($e=(fe=e.resources)==null?void 0:fe.disk)==null?void 0:$e.backupsMaxDays)??60,onChange:T=>t(E=>{var Y;return{...E,resources:{...E==null?void 0:E.resources,disk:{...(Y=E==null?void 0:E.resources)==null?void 0:Y.disk,backupsMaxDays:Number(T.target.value)}}}}),className:"w-full px-3 py-2 border border-border rounded bg-surface"})})]}),u("section",{className:"card space-y-4","aria-labelledby":"costs-heading",children:[i("h2",{id:"costs-heading",className:"text-sm uppercase tracking-wider text-text-dim",children:"Cost ceilings"}),i(Te,{label:"Billing mode",help:"metered = pay-per-token API (numbers = real bill). subscription = Claude Pro / Max / Team / Enterprise flat-rate (numbers below become metered-equivalent only). mixed = some of both.",children:u("select",{value:((Le=e.costs)==null?void 0:Le.billingMode)??"metered",onChange:T=>t(E=>({...E,costs:{...E==null?void 0:E.costs,billingMode:T.target.value}})),className:"w-full px-3 py-2 border border-border rounded bg-surface",children:[i("option",{value:"metered",children:"metered (API key, pay-per-token)"}),i("option",{value:"subscription",children:"subscription (Claude Pro / Max / Team)"}),i("option",{value:"mixed",children:"mixed (both)"})]})}),i(Te,{label:"Daily total cap (USD)",help:"Hard-stop when enforce is on. Has no meaning under pure subscription billing — the cap applies only to metered API calls.",children:i("input",{type:"number",min:"0",step:"0.5",value:((U=(F=(M=e.costs)==null?void 0:M.budgets)==null?void 0:F.total)==null?void 0:U.dailyUsd)??50,onChange:T=>t(E=>{var Y;return{...E,costs:{...E==null?void 0:E.costs,budgets:{...(Y=E==null?void 0:E.costs)==null?void 0:Y.budgets,total:{dailyUsd:Number(T.target.value)}}}}}),className:"w-full px-3 py-2 border border-border rounded bg-surface"})}),i(Te,{label:"Per-persona default cap (USD)",help:"Applies to any persona without a specific entry.",children:i("input",{type:"number",min:"0",step:"0.5",value:((P=(G=(K=e.costs)==null?void 0:K.budgets)==null?void 0:G.default)==null?void 0:P.dailyUsd)??10,onChange:T=>t(E=>{var Y;return{...E,costs:{...E==null?void 0:E.costs,budgets:{...(Y=E==null?void 0:E.costs)==null?void 0:Y.budgets,default:{dailyUsd:Number(T.target.value)}}}}}),className:"w-full px-3 py-2 border border-border rounded bg-surface"})}),i(Te,{label:"Enforce",help:"When on, calls exceeding the cap return PolicyDenied. When off, advisory only.",children:u("label",{className:"inline-flex items-center gap-2",children:[i("input",{type:"checkbox",checked:!!((z=e.costs)!=null&&z.enforce),onChange:T=>t(E=>({...E,costs:{...E==null?void 0:E.costs,enforce:T.target.checked}}))}),i("span",{className:"text-sm",children:(V=e.costs)!=null&&V.enforce?"on":"off"})]})})]}),C&&u("section",{className:"card","aria-labelledby":"diff-heading",children:[i("h3",{id:"diff-heading",className:"text-sm uppercase tracking-wider text-text-dim mb-2",children:"Pending changes"}),i("pre",{className:"text-xs bg-bg-muted p-3 rounded overflow-auto max-h-64 font-mono",children:$x(n,e)})]}),u("div",{className:"flex items-center gap-3",children:[i("button",{type:"button",disabled:!C||f,onClick:g,className:"btn btn-primary disabled:opacity-50 disabled:cursor-not-allowed",children:f?"Saving…":"Save changes"}),i("button",{type:"button",disabled:!C||f,onClick:d,className:"btn disabled:opacity-50 disabled:cursor-not-allowed",children:"Discard"}),!C&&i("span",{className:"text-xs text-text-dim",children:"No changes pending."})]})]})}function Te({label:e,help:t,children:n}){return u("div",{className:"space-y-1",children:[i("label",{className:"block text-sm font-medium",children:e}),t&&i("p",{className:"text-xs text-text-dim",children:t}),n]})}function $x(e,t){const n=[],r=JSON.stringify(e??{},null,2).split(`
|
|
67
|
+
*/function Al(){return Al=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},Al.apply(this,arguments)}function Rp(e,t){if(e==null)return{};var n={},r=Object.keys(e),l,a;for(a=0;a<r.length;a++)l=r[a],!(t.indexOf(l)>=0)&&(n[l]=e[l]);return n}function lg(e){return!!(e.metaKey||e.altKey||e.ctrlKey||e.shiftKey)}function ag(e,t){return e.button===0&&(!t||t==="_self")&&!lg(e)}const ig=["onClick","relative","reloadDocument","replace","state","target","to","preventScrollReset","viewTransition"],sg=["aria-current","caseSensitive","className","end","style","to","viewTransition","children"],og="6";try{window.__reactRouterVersion=og}catch{}const cg=m.createContext({isTransitioning:!1}),ug="startTransition",Jc=tf[ug];function dg(e){let{basename:t,children:n,future:r,window:l}=e,a=m.useRef();a.current==null&&(a.current=mh({window:l,v5Compat:!0}));let s=a.current,[o,c]=m.useState({action:s.action,location:s.location}),{v7_startTransition:p}=r||{},f=m.useCallback(x=>{p&&Jc?Jc(()=>c(x)):c(x)},[c,p]);return m.useLayoutEffect(()=>s.listen(f),[s,f]),m.useEffect(()=>tg(r),[r]),m.createElement(ng,{basename:t,children:n,location:o.location,navigationType:o.action,navigator:s,future:r})}const pg=typeof window<"u"&&typeof window.document<"u"&&typeof window.document.createElement<"u",fg=/^(?:[a-z][a-z0-9+.-]*:|\/\/)/i,mg=m.forwardRef(function(t,n){let{onClick:r,relative:l,reloadDocument:a,replace:s,state:o,target:c,to:p,preventScrollReset:f,viewTransition:x}=t,v=Rp(t,ig),{basename:y}=m.useContext(Ht),w,b=!1;if(typeof p=="string"&&fg.test(p)&&(w=p,pg))try{let h=new URL(window.location.href),N=p.startsWith("//")?new URL(h.protocol+p):new URL(p),S=Dn(N.pathname,y);N.origin===h.origin&&S!=null?p=S+N.search+N.hash:b=!0}catch{}let C=Ah(p,{relative:l}),g=xg(p,{replace:s,state:o,target:c,preventScrollReset:f,relative:l,viewTransition:x});function d(h){r&&r(h),h.defaultPrevented||g(h)}return m.createElement("a",Al({},v,{href:w||C,onClick:b||a?r:d,ref:n,target:c}))}),hg=m.forwardRef(function(t,n){let{"aria-current":r="page",caseSensitive:l=!1,className:a="",end:s=!1,style:o,to:c,viewTransition:p,children:f}=t,x=Rp(t,sg),v=ia(c,{relative:x.relative}),y=Mr(),w=m.useContext(Sp),{navigator:b,basename:C}=m.useContext(Ht),g=w!=null&&vg(v)&&p===!0,d=b.encodeLocation?b.encodeLocation(v).pathname:v.pathname,h=y.pathname,N=w&&w.navigation&&w.navigation.location?w.navigation.location.pathname:null;l||(h=h.toLowerCase(),N=N?N.toLowerCase():null,d=d.toLowerCase()),N&&C&&(N=Dn(N,C)||N);const S=d!=="/"&&d.endsWith("/")?d.length-1:d.length;let L=h===d||!s&&h.startsWith(d)&&h.charAt(S)==="/",R=N!=null&&(N===d||!s&&N.startsWith(d)&&N.charAt(d.length)==="/"),k={isActive:L,isPending:R,isTransitioning:g},A=L?r:void 0,j;typeof a=="function"?j=a(k):j=[a,L?"active":null,R?"pending":null,g?"transitioning":null].filter(Boolean).join(" ");let D=typeof o=="function"?o(k):o;return m.createElement(mg,Al({},x,{"aria-current":A,className:j,ref:n,style:D,to:c,viewTransition:p}),typeof f=="function"?f(k):f)});var $i;(function(e){e.UseScrollRestoration="useScrollRestoration",e.UseSubmit="useSubmit",e.UseSubmitFetcher="useSubmitFetcher",e.UseFetcher="useFetcher",e.useViewTransitionState="useViewTransitionState"})($i||($i={}));var Gc;(function(e){e.UseFetcher="useFetcher",e.UseFetchers="useFetchers",e.UseScrollRestoration="useScrollRestoration"})(Gc||(Gc={}));function gg(e){let t=m.useContext(la);return t||se(!1),t}function xg(e,t){let{target:n,replace:r,state:l,preventScrollReset:a,relative:s,viewTransition:o}=t===void 0?{}:t,c=Pp(),p=Mr(),f=ia(e,{relative:s});return m.useCallback(x=>{if(ag(x,n)){x.preventDefault();let v=r!==void 0?r:jl(p)===jl(f);c(e,{replace:v,state:l,preventScrollReset:a,relative:s,viewTransition:o})}},[p,c,f,r,l,n,e,a,s,o])}function vg(e,t){t===void 0&&(t={});let n=m.useContext(cg);n==null&&se(!1);let{basename:r}=gg($i.useViewTransitionState),l=ia(e,{relative:t.relative});if(!n.isTransitioning)return!1;let a=Dn(n.currentLocation.pathname,r)||n.currentLocation.pathname,s=Dn(n.nextLocation.pathname,r)||n.nextLocation.pathname;return zl(l.pathname,s)!=null||zl(l.pathname,a)!=null}const Op="/api";function yg(){for(const e of document.cookie.split(";")){const[t,...n]=e.trim().split("=");if(t==="cx_csrf")return n.join("=")}return null}async function Z(e){const t=await fetch(`${Op}${e}`);if(!t.ok)throw new Error(`GET ${e}: ${t.status}`);return t.json()}async function Nt(e,t){return sa(e,t,"POST")}async function sa(e,t,n){const r={"Content-Type":"application/json"},l=yg();l&&(r["x-construct-csrf"]=l);const a=await fetch(`${Op}${e}`,{method:n,headers:r,body:JSON.stringify(t)});if(!a.ok){const s=await a.json().catch(()=>({}));throw new Error(s.error||`${n} ${e}: ${a.status}`)}return a.json()}const Fn=()=>Z("/status"),Ng=()=>Z("/auth/status"),Os=()=>Z("/registry"),wg=()=>Z("/approvals"),bg=()=>Z("/snapshots"),kg=()=>Z("/artifacts"),Sg=()=>Z("/mode"),Cg=()=>Z("/alias"),Mp=()=>Z("/insights"),Eg=()=>Z("/project-config"),Yc=e=>Z(`/overrides/${e}`),Xc=(e,t)=>Z(`/overrides/${e}/${t}`),Zc=(e,t)=>Z(`/overrides/${e}/${t}?action=backups`),Pg=(e,t,n)=>sa(`/overrides/${e}/${t}`,{content:n},"PUT"),_g=(e,t,n)=>sa(`/overrides/${e}/${t}?action=restore`,{backupFilename:n},"POST"),Lg=e=>sa("/project-config",e,"PUT"),Tg=()=>Z("/knowledge/trends"),Rg=()=>Z("/knowledge/index"),Og=e=>Nt("/knowledge/ask",{question:e}),Mg=()=>Z("/terraform/files"),Ig=()=>Z("/models/providers"),Dg=e=>Z(`/models/pricing?ids=${encodeURIComponent(e.filter(Boolean).join(","))}`),$g=()=>Nt("/models/free/apply",{}),jg=()=>Z("/intake/config"),zg=e=>Z(`/fs/browse${e?`?path=${encodeURIComponent(e)}`:""}`),Fg=e=>Nt("/intake/config",e),qc=()=>Z("/providers/credentials"),Ag=()=>Z("/providers/config-path"),eu=()=>Z("/providers/credentials/custom"),Ug=e=>Nt("/providers/credentials/custom",{action:"save",...e}),Bg=e=>Nt("/providers/credentials/custom",{action:"delete",provider:e}),Vg=()=>Z("/providers/credentials/op-status"),Wg=(e,t)=>Nt("/providers/credentials/op-pull",{envVar:e,opRef:t}),Hg=()=>Z("/providers/billing"),Qg=(e,t)=>Nt("/providers/billing",{provider:e,billingMode:t}),Kg=(e,t,n)=>Nt("/registry/models",{tier:e,primary:t,fallback:n}),tu=(e,t)=>Nt("/providers/credentials",{envVar:e,value:t}),Jg=()=>Z("/beads");function Ve({children:e,text:t}){return i("span",{title:t,className:"cursor-help inline-flex items-center gap-1 underline decoration-dotted decoration-text-dim underline-offset-2","aria-label":t,children:e})}function $a(e){switch(e){case"healthy":case"ok":case"configured":return"pip pip-healthy";case"degraded":case"warning":return"pip pip-degraded";case"down":case"unavailable":case"error":case"not-configured":return"pip pip-down";default:return"pip"}}function ja(e){switch(e){case"healthy":case"ok":case"configured":return"✓";case"degraded":case"warning":return"!";case"down":case"unavailable":case"error":case"not-configured":return"✕";default:return"·"}}function Gg({trend:e}){var r;if(!e||e.state!=="ok"||!((r=e.series)!=null&&r.length))return i("p",{className:"text-xs text-text-dim",children:(e==null?void 0:e.state)==="misconfigured"?e.message:(e==null?void 0:e.state)==="empty"?"No telemetry traces in the last 7 days.":"Cost trend unavailable."});const t=Math.max(...e.series.map(l=>l.costUsd),1e-4),n=e.series;return u("div",{children:[i("div",{className:"flex items-end gap-1.5 h-32",children:n.map(l=>{const a=t>0?l.costUsd/t*100:0;return i("div",{className:"flex-1 flex flex-col items-center justify-end h-full",title:`${l.day}: $${l.costUsd.toFixed(4)} · ${l.traces} traces${l.errors?` · ${l.errors} errors`:""}`,children:i("div",{style:{width:"100%",height:`${Math.max(2,a)}%`,background:l.errors>0?"var(--status-degraded)":"var(--aurora-gradient)",borderRadius:"4px 4px 0 0",opacity:l.traces===0?.25:1}})},l.day)})}),i("div",{className:"flex justify-between text-[10px] text-text-dim mt-2 font-mono",children:n.map(l=>i("span",{className:"flex-1 text-center",children:l.day.slice(-5)},l.day))})]})}function Yg({ratio:e,dangerOver:t=1,warnOver:n=.8}){const r=Math.max(0,Math.min(2,e));return i("div",{className:"h-1.5 w-full bg-bg-muted rounded mt-2",children:i("div",{className:"h-full rounded transition-all",style:{width:`${Math.min(100,r*100)}%`,background:r>t?"var(--status-down)":r>n?"var(--status-degraded)":"var(--aurora-gradient)"}})})}function Xg(){var j,D,O,H,B,fe,$e,Le,M,F,U,K,G,P,z,V,T,E,Y,Ir,An,me,Ye,wt,Is,Ds,$s,js,zs,Fs,As,Us,Bs,Vs,Ws,Hs,Qs,Ks,Js,Gs,Ys,Xs,Zs,qs,eo,to,no,ro,lo,ao,io,so,oo,co,uo,po,fo,mo,ho,go,xo,vo,yo,No,wo,bo,ko,So,Co,Eo,Po,_o,Lo,To,Ro,Oo;const[e,t]=m.useState(null),[n,r]=m.useState(null),[l,a]=m.useState(null),[s,o]=m.useState(null),[c,p]=m.useState(!0),[f,x]=m.useState(null);if(m.useEffect(()=>{const I=()=>Promise.all([Fn().then(t).catch(()=>{}),Ng().then(r).catch(()=>{}),Mp().then(a).catch(()=>{}),Os().then(o).catch(()=>{})]).catch(lt=>x((lt==null?void 0:lt.message)||"Failed to fetch status")).finally(()=>p(!1));I();const ce=window.setInterval(I,1e4),ne=()=>{document.visibilityState==="visible"&&I()};return document.addEventListener("visibilitychange",ne),window.addEventListener("focus",ne),()=>{window.clearInterval(ce),document.removeEventListener("visibilitychange",ne),window.removeEventListener("focus",ne)}},[]),c)return i("p",{className:"text-text-dim text-sm",children:"Loading system snapshot…"});if(f)return u("section",{className:"card max-w-2xl",children:[i("h1",{className:"text-lg font-semibold mb-2",children:"Mission Control unavailable"}),i("p",{className:"text-text-muted text-sm mb-4",children:f}),u("p",{className:"text-text-dim text-xs",children:["Try ",i("code",{className:"px-1 py-0.5 bg-bg-muted rounded",children:"construct doctor"})," to identify the cause."]})]});if(!e)return null;const v=((D=(j=e.system)==null?void 0:j.overall)==null?void 0:D.status)||"unknown",y=((H=(O=l==null?void 0:l.beads)==null?void 0:O.byStatus)==null?void 0:H.open)||0,w=((fe=(B=l==null?void 0:l.beads)==null?void 0:B.byStatus)==null?void 0:fe.in_progress)||0;((Le=($e=l==null?void 0:l.cost)==null?void 0:$e.budget)==null?void 0:Le.todayActualUsd)??((F=(M=l==null?void 0:l.cost)==null?void 0:M.budget)==null||F.todayUsd),((K=(U=l==null?void 0:l.cost)==null?void 0:U.budget)==null?void 0:K.todayMeteredEquivalentUsd)??((P=(G=l==null?void 0:l.cost)==null?void 0:G.budget)==null||P.todayUsd),(V=(z=l==null?void 0:l.cost)==null?void 0:z.budget)==null||V.capUsd,(E=(T=l==null?void 0:l.cost)==null?void 0:T.budget)==null||E.usageRatio;const b=((Y=l==null?void 0:l.cost)==null?void 0:Y.billingMode)||"subscription";(Ir=l==null?void 0:l.cost)!=null&&Ir.billingSource;const C=((An=l==null?void 0:l.cost)==null?void 0:An.providerBilling)||{};Object.keys(C).length>0&&Object.values(C).every(I=>(I==null?void 0:I.billingMode)==="subscription");const d=((me=l==null?void 0:l.resources)==null?void 0:me.totalCxUsageRatio)??0,h=(((Ye=l==null?void 0:l.resources)==null?void 0:Ye.totalCxBytes)??0)/1024/1024,N=(((wt=l==null?void 0:l.resources)==null?void 0:wt.totalCxCap)??0)/1024/1024,S=((Is=e.system)==null?void 0:Is.services)??[],L=S.filter(I=>I.status==="healthy").length,R=["reasoning","standard","fast"].map(I=>{var ce,ne;return(ne=(ce=s==null?void 0:s.models)==null?void 0:ce[I])==null?void 0:ne.primary}).filter(I=>typeof I=="string"&&I.length>0),k=[{key:"model",label:`Pick a model per tier (${R.length} of 3 set)`,done:R.length===3,href:"#/models",hint:"Construct ships with no default — choose reasoning / standard / fast. Auto-pick from free OpenRouter models is one click away."},{key:"provider",label:"Configure at least one provider",done:((l==null?void 0:l.providers)??[]).some(I=>I.state==="configured"),href:"#/providers",hint:"Set an API key (Anthropic / OpenAI / OpenRouter / Ollama) so the picked models can run."}],A=k.filter(I=>!I.done);return u("div",{className:"max-w-7xl space-y-6",children:[u("header",{children:[i("p",{className:"text-text-dim text-xs uppercase tracking-wider mb-1",children:"Page"}),i("h1",{className:"text-2xl sm:text-3xl font-semibold tracking-tight",children:"Mission Control"}),u("p",{className:"text-text-muted text-sm mt-1",children:["Live system snapshot · refreshes every 10s · ",e.version??"—",e.lastSync&&u(Ce,{children:[" · last sync ",new Date(e.lastSync).toLocaleTimeString()]})]})]}),A.length>0&&u("section",{className:"card border border-amber-300 bg-amber-50/40","aria-labelledby":"getting-started-heading",children:[u("h2",{id:"getting-started-heading",className:"text-xs uppercase tracking-wider text-text-dim mb-3",children:["Getting started — ",k.filter(I=>I.done).length," of ",k.length," complete"]}),i("ul",{className:"space-y-2",children:k.map(I=>u("li",{className:"flex items-start gap-3 text-sm",children:[i("span",{"aria-hidden":"true",className:I.done?"text-green-700":"text-amber-700",children:I.done?"✓":"○"}),u("div",{className:"flex-1 min-w-0",children:[u("div",{className:"flex flex-wrap items-baseline gap-x-2 gap-y-0.5",children:[i("span",{className:I.done?"line-through text-text-dim":"font-medium",children:I.label}),!I.done&&i("a",{href:I.href,className:"text-xs underline hover:no-underline text-indigo-700",children:"Fix here →"})]}),i("p",{className:"text-xs text-text-dim",children:I.hint})]})]},I.key))})]}),u("section",{className:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-4","aria-labelledby":"hero-heading",children:[i("h2",{id:"hero-heading",className:"sr-only",children:"Primary signals"}),u("article",{className:"card",children:[i("p",{className:"text-xs uppercase tracking-wider text-text-dim mb-3",children:i(Ve,{text:"Count of running local services (Dashboard, Memory, OpenCode) that are responding to health probes.",children:"System health"})}),i("div",{className:"flex items-baseline gap-3",children:u("span",{className:$a(v),style:{fontSize:"0.9rem"},children:[i("span",{"aria-hidden":"true",children:ja(v)}),v]})}),u("p",{className:"text-3xl font-semibold mt-3",children:[L,u("span",{className:"text-base text-text-dim font-normal",children:["/",S.length]})]}),i("p",{className:"text-xs text-text-muted mt-1",children:"core surfaces reachable"}),(($s=(Ds=e.system)==null?void 0:Ds.overall)==null?void 0:$s.summary)&&i("p",{className:"text-xs text-text-dim mt-2",children:e.system.overall.summary})]}),u("article",{className:"card",children:[i("p",{className:"text-xs uppercase tracking-wider text-text-dim mb-3",children:i(Ve,{text:"Total LLM token usage across all agent sessions. 'Billed' includes cache reads (96.4%) at ~10% cost — the raw number looks large but the actual compute is modest. Provider total is the raw tokens sent to the API before cache discounts.",children:"Token usage"})}),u("p",{className:"text-3xl font-semibold",children:[(((js=l==null?void 0:l.sessionUsage)==null?void 0:js.billedTotalTokens)??0)>1e6?(l.sessionUsage.billedTotalTokens/1e6).toFixed(0)+"M":(l.sessionUsage.billedTotalTokens??0).toLocaleString(),i("span",{className:"text-xs text-text-dim font-normal ml-1",children:"billed"})]}),u("p",{className:"text-xs text-text-muted mt-1",children:[((zs=l==null?void 0:l.sessionUsage)==null?void 0:zs.interactions)??0," interactions ·"," ",(((Fs=l==null?void 0:l.sessionUsage)==null?void 0:Fs.providerTotalTokens)??0).toLocaleString()," raw"]}),u("p",{className:"text-xs text-text-dim mt-2",children:[(((As=l==null?void 0:l.sessionUsage)==null?void 0:As.cacheReadInputTokens)??0).toLocaleString()," cache rd ·"," ",(((Us=l==null?void 0:l.sessionUsage)==null?void 0:Us.cacheCreationInputTokens)??0).toLocaleString()," cache wr ·"," ",(((Bs=l==null?void 0:l.sessionUsage)==null?void 0:Bs.outputTokens)??0).toLocaleString()," out"]})]}),u("article",{className:"card",children:[i("p",{className:"text-xs uppercase tracking-wider text-text-dim mb-3",children:i(Ve,{text:"Share of input tokens served from prompt cache. Higher is better — cache reads reduce latency and increase throughput. The billed total includes cache at a fraction of the cost.",children:"Cache efficiency"})}),u("p",{className:"text-3xl font-semibold",style:{color:"var(--status-healthy)"},children:[Math.round((((Hs=(Ws=(Vs=l==null?void 0:l.cost)==null?void 0:Vs.windows)==null?void 0:Ws.last7d)==null?void 0:Hs.cacheHitRate)??((Qs=l==null?void 0:l.sessionUsage)==null?void 0:Qs.cacheHitRate)??0)*100),i("span",{className:"text-xs text-text-dim font-normal ml-1",children:"% hit"})]}),u("p",{className:"text-xs text-text-muted mt-1",children:[((Js=(Ks=l==null?void 0:l.sessionUsage)==null?void 0:Ks.cacheReadInputTokens)==null?void 0:Js.toLocaleString())??0," tokens served from cache"]}),i("p",{className:"text-xs text-text-dim mt-2",children:(((Gs=l==null?void 0:l.sessionUsage)==null?void 0:Gs.cacheReadInputTokens)??0)>0?u(Ce,{children:[(l.sessionUsage.cacheReadInputTokens/(l.sessionUsage.billedTotalTokens||1)*100).toFixed(1),"% of all tokens ·"," ",(l.sessionUsage.cacheCreationInputTokens/(l.sessionUsage.billedTotalTokens||1)*100).toFixed(1),"% write overhead"]}):"No cache data yet."})]}),u("article",{className:"card",children:[i("p",{className:"text-xs uppercase tracking-wider text-text-dim mb-3",children:i(Ve,{text:"Beads (issues) currently open, in progress, or closed in the project's bd tracker. P0–P3 are priority tiers; lower is more urgent.",children:"Active work"})}),u("p",{className:"text-3xl font-semibold",children:[y,i("span",{className:"text-base text-text-dim font-normal ml-1",children:"open"})]}),u("p",{className:"text-xs text-text-muted mt-1",children:[w," in progress · ",((Xs=(Ys=l==null?void 0:l.beads)==null?void 0:Ys.byStatus)==null?void 0:Xs.closed)??0," closed"]}),i("div",{className:"flex gap-2 mt-3 text-xs",children:["P0","P1","P2","P3"].map(I=>{var ne,lt;const ce=((lt=(ne=l==null?void 0:l.beads)==null?void 0:ne.byPriority)==null?void 0:lt[I])??0;return ce?u("span",{className:"px-1.5 py-0.5 rounded bg-bg-muted font-mono",title:`Priority ${I.slice(1)}: ${ce} issues. P0=critical, P1=high, P2=medium, P3=low.`,children:[I,":",ce]},I):null})})]})]}),u("section",{className:"grid grid-cols-1 lg:grid-cols-3 gap-4",children:[u("article",{className:"card lg:col-span-2","aria-labelledby":"cost-trend-heading",children:[u("header",{className:"flex items-baseline justify-between mb-3",children:[i("h2",{id:"cost-trend-heading",className:"text-xs uppercase tracking-wider text-text-dim",children:i(Ve,{text:"Daily LLM spend over the last 7 days, pulled from telemetry traces in this project. Bars turn amber on days with at least one errored trace. Empty / dim bars mean no traces that day.",children:"Cost trend (7d)"})}),i("span",{className:"text-xs text-text-dim",children:((Zs=l==null?void 0:l.costTrend)==null?void 0:Zs.state)==="ok"?`${l.costTrend.sampleSize} traces · ${l.costTrend.withCost} priced`:null})]}),i(Gg,{trend:l==null?void 0:l.costTrend})]}),u("article",{className:"card","aria-labelledby":"services-strip-heading",children:[i("h2",{id:"services-strip-heading",className:"text-xs uppercase tracking-wider text-text-dim mb-3",children:"Services"}),S.length===0?u("p",{className:"text-xs text-text-muted",children:["No services reported. Run ",i("code",{className:"px-1 py-0.5 bg-bg-muted rounded",children:"construct up"}),"."]}):i("ul",{className:"space-y-2",children:S.map((I,ce)=>u("li",{className:"flex items-center justify-between gap-3 text-sm",children:[u("div",{className:"min-w-0",children:[i("div",{className:"font-medium truncate",children:I.name}),I.note&&i("div",{className:"text-xs text-text-dim truncate",children:I.note})]}),u("div",{className:"flex items-center gap-2 flex-shrink-0",children:[u("span",{className:$a(I.status),children:[i("span",{"aria-hidden":"true",children:ja(I.status)}),I.status]}),I.url&&i("a",{href:I.url,target:"_blank",rel:"noreferrer",className:"text-xs text-text-dim hover:text-text","aria-label":`open ${I.name}`,children:"↗"})]})]},ce))})]})]}),u("section",{"aria-labelledby":"token-efficiency-heading",className:"grid grid-cols-1 lg:grid-cols-3 gap-4",children:[i("h2",{id:"token-efficiency-heading",className:"sr-only",children:"Token efficiency"}),u("article",{className:"card",children:[i("p",{className:"text-xs uppercase tracking-wider text-text-dim mb-2",children:i(Ve,{text:"How much of your token throughput is served from Anthropic's prompt cache. Cache reads count toward your billed total at ~10% of the cost of fresh input. Higher is better — means your system prompts and context are being reused efficiently.",children:"Cache efficiency (7d)"})}),u("p",{className:"text-2xl font-semibold",style:{color:"var(--status-healthy)"},children:[Math.round((((to=(eo=(qs=l==null?void 0:l.cost)==null?void 0:qs.windows)==null?void 0:eo.last7d)==null?void 0:to.cacheHitRate)??0)*100),i("span",{className:"text-xs text-text-dim font-normal ml-1",children:"% cache hit"})]}),(((ro=(no=l==null?void 0:l.cost)==null?void 0:no.tokenMix)==null?void 0:ro.cacheRead)??0)>0&&u("p",{className:"text-xs text-text-muted mt-1",children:[(l.cost.tokenMix.cacheRead/1e6).toFixed(1),"M cached input · ",(l.cost.tokenMix.cacheCreation/1e6).toFixed(2),"M write overhead"]}),!(((ao=(lo=l==null?void 0:l.cost)==null?void 0:lo.tokenMix)==null?void 0:ao.cacheRead)??0)>0&&i("p",{className:"text-xs text-text-muted mt-1",children:"No token usage yet."})]}),u("article",{className:"card lg:col-span-2",children:[i("p",{className:"text-xs uppercase tracking-wider text-text-dim mb-3",children:i(Ve,{text:"Stacked bar of token usage over the last 7 days. Cache-read = served from prompt cache (cheap). Cache-write = first-time-stored to cache (slight premium). Input = uncached input. Output = generated tokens. Reasoning = extended-thinking tokens (priced like output).",children:"Token mix (7d)"})}),((so=(io=l==null?void 0:l.cost)==null?void 0:io.tokenMix)==null?void 0:so.total)>0?u(Ce,{children:[i("div",{className:"flex h-3 rounded overflow-hidden border border-border",children:(()=>{const I=l.cost.tokenMix;return[{key:"cacheRead",label:"Cache read",value:I.cacheRead,color:"var(--aurora-cyan)"},{key:"cacheCreation",label:"Cache write",value:I.cacheCreation,color:"var(--aurora-violet)"},{key:"input",label:"Input",value:I.input,color:"var(--aurora-mint)"},{key:"output",label:"Output",value:I.output,color:"var(--aurora-pink)"},{key:"reasoning",label:"Reasoning",value:I.reasoning,color:"var(--ink-500)"}].filter(ne=>ne.value>0).map(ne=>i("div",{style:{width:`${ne.value/I.total*100}%`,background:ne.color},title:`${ne.label}: ${ne.value.toLocaleString()} (${(ne.value/I.total*100).toFixed(1)}%)`},ne.key))})()}),i("div",{className:"grid grid-cols-2 md:grid-cols-5 gap-3 mt-3 text-xs",children:["cacheRead","cacheCreation","input","output","reasoning"].map(I=>{const ce=l.cost.tokenMix;if(!ce[I])return null;const ne={cacheRead:"var(--aurora-cyan)",cacheCreation:"var(--aurora-violet)",input:"var(--aurora-mint)",output:"var(--aurora-pink)",reasoning:"var(--ink-500)"},lt={cacheRead:"Cache read",cacheCreation:"Cache write",input:"Input",output:"Output",reasoning:"Reasoning"};return u("div",{className:"flex items-start gap-2",children:[i("span",{className:"w-2 h-2 rounded-full mt-1 flex-shrink-0",style:{background:ne[I]},"aria-hidden":"true"}),u("div",{className:"min-w-0",children:[i("div",{className:"text-text-dim text-[10px] uppercase tracking-wider",children:lt[I]}),i("div",{className:"font-mono",children:ce[I].toLocaleString()}),u("div",{className:"text-text-dim text-[10px]",children:[(ce[I]/ce.total*100).toFixed(1),"%"]})]})]},I)})})]}):i("p",{className:"text-xs text-text-muted",children:"No token usage yet."})]})]}),u("section",{"aria-labelledby":"obs-heading",children:[i("h2",{id:"obs-heading",className:"text-xs uppercase tracking-wider text-text-dim mb-3",children:i(Ve,{text:"LLM behavior metrics from telemetry traces. Each card answers a different question about how the agent is performing.",children:"Observability (last 7d)"})}),i("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-5 gap-4",children:u("article",{className:"card",children:[i("p",{className:"text-xs uppercase tracking-wider text-text-dim mb-2",children:i(Ve,{text:"Recall@5: of the documents that *should* have been retrieved for each fixture query, what share appeared in the top 5 returned results. 100% = the right doc is always in the top 5. MRR is mean reciprocal rank — 1.0 means the right doc is always first. Run `construct evals retrieval` to refresh.",children:"Retrieval recall@5"})}),((oo=l==null?void 0:l.retrievalEval)==null?void 0:oo.state)==="ok"?u(Ce,{children:[u("p",{className:"text-xl font-semibold",children:[((l.retrievalEval.recallAt5??0)*100).toFixed(0),i("span",{className:"text-xs text-text-dim font-normal ml-1",children:"%"})]}),u("p",{className:"text-xs text-text-muted mt-1",children:["MRR ",(l.retrievalEval.mrr??0).toFixed(2)," · p95 ",Math.round(l.retrievalEval.p95LatencyMs||0),"ms"]}),u("p",{className:"text-xs text-text-dim mt-2",children:[l.retrievalEval.queryCount," queries · ",new Date(l.retrievalEval.ranAt).toLocaleDateString()]}),((co=l.retrievalEval.history)==null?void 0:co.length)>1&&i("svg",{viewBox:"0 0 60 16",className:"w-full h-4 mt-2",preserveAspectRatio:"none","aria-label":"recall@5 history",children:(()=>{const I=l.retrievalEval.history,ce=I.map((ne,lt)=>{const $p=lt/Math.max(1,I.length-1)*60,jp=16-Number(ne.recallAt5??0)*16;return`${$p.toFixed(1)},${jp.toFixed(1)}`}).join(" ");return i("polyline",{points:ce,fill:"none",stroke:"var(--aurora-cyan)",strokeWidth:"1.2"})})()})]}):u("p",{className:"text-xs text-text-muted",children:["Run ",i("code",{className:"bg-bg-muted px-1 rounded",children:"construct evals retrieval"})]})]})})]}),u("section",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-4","aria-labelledby":"secondary-heading",children:[i("h2",{id:"secondary-heading",className:"sr-only",children:"Resources and queues"}),u("article",{className:"card",children:[i("p",{className:"text-xs uppercase tracking-wider text-text-dim mb-2",children:".cx/ disk"}),u("p",{className:"text-xl font-semibold",children:[h.toFixed(1),i("span",{className:"text-xs text-text-dim font-normal ml-1",children:"MB"})]}),u("p",{className:"text-xs text-text-muted",children:["/ ",N.toFixed(0),"MB cap"]}),i(Yg,{ratio:d})]}),u("article",{className:"card",children:[i("p",{className:"text-xs uppercase tracking-wider text-text-dim mb-2",children:"Handoffs"}),((uo=l==null?void 0:l.handoffs)==null?void 0:uo.state)==="ok"?u(Ce,{children:[i("p",{className:"text-xl font-semibold",children:l.handoffs.total}),u("p",{className:"text-xs text-text-muted",children:["oldest ",(po=l.handoffs.oldestAgeDays)==null?void 0:po.toFixed(0),"d / ",l.handoffs.maxDays,"d"]}),l.handoffs.pastRetentionCount>0&&u("p",{className:"text-xs mt-2",style:{color:"var(--status-degraded)"},children:[l.handoffs.pastRetentionCount," past retention"]})]}):i("p",{className:"text-xs text-text-muted",children:"empty"})]}),u("article",{className:"card",children:[i("p",{className:"text-xs uppercase tracking-wider text-text-dim mb-2",children:i(Ve,{text:"R&D intake pipeline: files dropped in .cx/inbox/ are auto-ingested, triaged, and queued. Processed = marked done via `construct intake done`. Skipped = intentionally bypassed. Customer-linked = items auto-matched to customer profiles via name/domain detection.",children:"Intake queue"})}),((fo=l==null?void 0:l.intake)==null?void 0:fo.state)==="ok"?u(Ce,{children:[i("p",{className:"text-xl font-semibold",children:l.intake.pending}),i("p",{className:"text-xs text-text-muted",children:"pending"}),u("p",{className:"text-xs text-text-dim mt-1",children:["processed ",l.intake.processed," · skipped ",l.intake.skipped]}),l.intake.customerLinked>0&&u("p",{className:"text-xs text-cyan-700 mt-1",children:[l.intake.customerLinked," customer-linked"]})]}):u("p",{className:"text-xs text-text-muted",children:["empty · drop a file in ",i("code",{className:"bg-bg-muted px-1 rounded",children:".cx/inbox/"})]})]}),u("article",{className:"card",children:[i("p",{className:"text-xs uppercase tracking-wider text-text-dim mb-2",children:"Vector index"}),((mo=l==null?void 0:l.vector)==null?void 0:mo.state)==="ok"?u(Ce,{children:[i("p",{className:"text-xl font-semibold",children:((ho=l.vector.records)==null?void 0:ho.toLocaleString())??"—"}),u("p",{className:"text-xs text-text-muted",children:["records · ",(l.vector.bytes/1024).toFixed(1),"KB"]}),l.vector.model&&i("p",{className:"text-xs text-text-dim mt-1 font-mono truncate",children:l.vector.model})]}):i("p",{className:"text-xs text-text-muted",children:((go=l==null?void 0:l.vector)==null?void 0:go.message)||"No index yet. Run `construct ingest`."})]}),u("article",{className:"card",children:[i("p",{className:"text-xs uppercase tracking-wider text-text-dim mb-2",children:i(Ve,{text:"Artifact recommendations generated by the docs-lifecycle daemon job based on intake signal patterns, doc gaps, and snapshot analysis. P0 = urgent, P3 = nice-to-have. Run `construct recommendations list` for details.",children:"Recommendations"})}),((xo=l==null?void 0:l.recommendations)==null?void 0:xo.state)==="ok"&&l.recommendations.active>0?u(Ce,{children:[i("p",{className:"text-xl font-semibold",children:l.recommendations.active}),i("p",{className:"text-xs text-text-muted",children:"active"}),l.recommendations.byPriority&&Object.keys(l.recommendations.byPriority).length>0&&i("div",{className:"flex gap-2 mt-2 text-xs",children:Object.entries(l.recommendations.byPriority).map(([I,ce])=>u("span",{className:`px-1.5 py-0.5 rounded font-mono ${I==="P0"?"bg-red-100 text-red-800":I==="P1"?"bg-amber-100 text-amber-800":"bg-bg-muted text-text-dim"}`,children:[I,": ",ce]},I))}),u("p",{className:"text-xs text-text-dim mt-1",children:[l.recommendations.dismissed," dismissed · ",l.recommendations.total," total"]})]}):i("p",{className:"text-xs text-text-muted",children:((vo=l==null?void 0:l.recommendations)==null?void 0:vo.state)==="empty"?"No active recommendations.":"Loading…"})]})]}),u("section",{className:"card","aria-labelledby":"providers-heading",children:[u("header",{className:"flex items-baseline justify-between mb-3",children:[i("h2",{id:"providers-heading",className:"text-xs uppercase tracking-wider text-text-dim",children:"Model providers"}),i("a",{href:"#/providers",className:"text-xs text-text-dim hover:text-text",children:"manage ↗"})]}),i("div",{className:"grid grid-cols-2 md:grid-cols-4 lg:grid-cols-7 gap-3",children:((l==null?void 0:l.providers)??[]).map(I=>u("div",{className:"flex items-center gap-2 text-sm",children:[i("span",{className:$a(I.state),children:i("span",{"aria-hidden":"true",children:ja(I.state)})}),i("span",{className:"truncate",children:I.displayName})]},I.id))})]}),((yo=l==null?void 0:l.integrations)==null?void 0:yo.state)==="ok"&&u("section",{className:"card","aria-labelledby":"integrations-heading",children:[u("header",{className:"flex items-baseline justify-between mb-3",children:[i("h2",{id:"integrations-heading",className:"text-xs uppercase tracking-wider text-text-dim",children:i(Ve,{text:"External system integrations for intake packets. GitHub Issues uses gh CLI or GITHUB_TOKEN. Jira and Confluence need env vars in ~/.construct/config.env. Auth resolution checks process.env, .env files, config.env, shell rc files, and 1Password op:// refs.",children:"Integrations"})}),i("a",{href:"#/intake",className:"text-xs text-text-dim hover:text-text",children:"configure ↗"})]}),u("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-4 text-sm",children:[u("div",{className:"flex items-start gap-2",children:[i("span",{"aria-hidden":"true",className:((No=l.integrations.details)==null?void 0:No.github)!=="not configured"?"text-green-700":"text-text-dim",children:((wo=l.integrations.details)==null?void 0:wo.github)!=="not configured"?"✓":"○"}),u("div",{children:[i("p",{className:"font-medium",children:"GitHub Issues"}),i("p",{className:"text-xs text-text-muted",children:((bo=l.integrations.details)==null?void 0:bo.github)||"not configured"}),i("p",{className:"text-xs text-text-dim",children:"Creates issues from intake via gh CLI or API"})]})]}),u("div",{className:"flex items-start gap-2",children:[i("span",{"aria-hidden":"true",className:((ko=l.integrations.details)==null?void 0:ko.jira)!=="not configured"?"text-green-700":"text-text-dim",children:((So=l.integrations.details)==null?void 0:So.jira)!=="not configured"?"✓":"○"}),u("div",{children:[i("p",{className:"font-medium",children:"Jira"}),i("p",{className:"text-xs text-text-muted",children:((Co=l.integrations.details)==null?void 0:Co.jira)||"not configured"}),i("p",{className:"text-xs text-text-dim",children:"Set JIRA_HOST + JIRA_USER + JIRA_API_TOKEN + JIRA_PROJECT"})]})]}),u("div",{className:"flex items-start gap-2",children:[i("span",{"aria-hidden":"true",className:((Eo=l.integrations.details)==null?void 0:Eo.confluence)!=="not configured"?"text-green-700":"text-text-dim",children:((Po=l.integrations.details)==null?void 0:Po.confluence)!=="not configured"?"✓":"○"}),u("div",{children:[i("p",{className:"font-medium",children:"Confluence"}),i("p",{className:"text-xs text-text-muted",children:((_o=l.integrations.details)==null?void 0:_o.confluence)||"not configured"}),i("p",{className:"text-xs text-text-dim",children:"Set CONFLUENCE_HOST + USER + API_TOKEN + SPACE"})]})]})]}),i("p",{className:"text-xs text-text-dim mt-3",children:"Auth chain: env → ~/.env → ~/.construct/config.env → shell rc → 1Password op://. GitHub also checks gh CLI."})]}),u("section",{className:"card","aria-labelledby":"auth-heading",children:[i("h2",{id:"auth-heading",className:"text-xs uppercase tracking-wider text-text-dim mb-3",children:"Authentication"}),u("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-4 text-sm",children:[u("div",{children:[i("p",{className:"text-text-dim text-xs mb-1",children:"Mode"}),i("p",{children:((Lo=n==null?void 0:n.auth)==null?void 0:Lo.mode)??"token"})]}),u("div",{children:[i("p",{className:"text-text-dim text-xs mb-1",children:"Providers"}),i("p",{children:(Ro=(To=n==null?void 0:n.auth)==null?void 0:To.providers)!=null&&Ro.length?n.auth.providers.join(", "):"none"})]}),u("div",{children:[i("p",{className:"text-text-dim text-xs mb-1",children:"Token"}),i("p",{children:(Oo=n==null?void 0:n.auth)!=null&&Oo.tokenConfigured?"configured":"not configured"})]})]})]})]})}const Zg="/api";function qg(){const[e,t]=m.useState(null),[n,r]=m.useState(!0),[l,a]=m.useState(null),[s,o]=m.useState("plan");if(m.useEffect(()=>{fetch(`${Zg}/workflow`).then(f=>f.json()).then(f=>t(f)).catch(f=>a(f.message)).finally(()=>r(!1))},[]),n)return i("div",{className:"text-center py-20 text-gray-600",children:"Loading..."});if(l)return i("div",{className:"text-center py-20 text-red-500",children:l});if(!e)return i("div",{className:"text-center py-20 text-gray-600",children:"No workflow data available."});const c=e.taskStatusCounts??{},p=e.workflowState;return u("div",{children:[u("div",{className:"flex items-center justify-between mb-6",children:[i("h1",{className:"text-2xl font-bold",children:"Workflow"}),i("div",{className:"flex gap-1 bg-gray-100 rounded-lg p-1",children:["plan","tasks","phases"].map(f=>i("button",{onClick:()=>o(f),className:`px-3 py-1.5 text-sm font-medium rounded-md transition-colors ${s===f?"bg-white text-gray-900 shadow-sm":"text-gray-500 hover:text-gray-700"}`,children:f.charAt(0).toUpperCase()+f.slice(1)},f))})]}),i("div",{className:"grid grid-cols-2 md:grid-cols-5 gap-3 mb-6",children:[{label:"Pending",value:c.todo??0,color:"bg-gray-100 text-gray-700"},{label:"In Progress",value:c.inProgress??0,color:"bg-blue-100 text-blue-700"},{label:"Blocked",value:c.blocked??0,color:"bg-red-100 text-red-700"},{label:"Done",value:c.done??0,color:"bg-green-100 text-green-700"},{label:"Skipped",value:c.skipped??0,color:"bg-gray-100 text-gray-700"}].map(f=>u("div",{className:"bg-white border border-gray-200 rounded-xl p-4 text-center",children:[i("p",{className:"text-2xl font-bold",children:f.value}),i("p",{className:`text-xs font-medium mt-0.5 inline-block px-2 py-0.5 rounded-full ${f.color}`,children:f.label})]},f.label))}),s==="plan"&&u("div",{className:"bg-white border border-gray-200 rounded-xl p-6",children:[u("div",{className:"flex items-center justify-between mb-4",children:[i("p",{className:"text-sm font-semibold text-gray-500 uppercase tracking-wide",children:"Plan"}),e.hasPlan&&i("span",{className:"text-xs text-gray-600 font-mono",children:"plan.md"})]}),e.hasPlan?i("pre",{className:"text-sm text-gray-700 whitespace-pre-wrap font-sans leading-relaxed",children:e.planSummary||"No summary"}):i("p",{className:"text-gray-600",children:"No plan.md found."})]}),s==="tasks"&&p&&u("div",{className:"bg-white border border-gray-200 rounded-xl overflow-hidden",children:[i("div",{className:"px-6 py-3 border-b border-gray-100",children:u("p",{className:"text-sm font-semibold text-gray-500 uppercase tracking-wide",children:[e.taskCount," Tasks"]})}),(p.tasks??[]).length===0?i("div",{className:"p-6 text-center text-gray-600",children:"No tasks defined."}):i("div",{className:"divide-y divide-gray-50",children:(p.tasks??[]).map((f,x)=>{var y;const v=f.status==="done"?"bg-green-100 text-green-700":f.status==="in-progress"?"bg-blue-100 text-blue-700":(y=f.status)!=null&&y.startsWith("blocked")?"bg-red-100 text-red-700":(f.status==="skipped","bg-gray-100 text-gray-700");return u("div",{className:"px-6 py-4",children:[u("div",{className:"flex items-center justify-between mb-1",children:[i("p",{className:"font-medium text-sm",children:f.title||f.key||`Task ${x+1}`}),i("span",{className:`text-xs font-medium px-2 py-0.5 rounded-full ${v}`,children:f.status||"todo"})]}),f.phase&&i("p",{className:"text-xs text-gray-600 font-mono",children:f.phase})]},x)})})]}),s==="phases"&&p&&i("div",{className:"grid grid-cols-1 gap-3",children:Object.entries(p.phases??{}).map(([f,x])=>{const v=x.status==="done"?"bg-green-100 text-green-700":x.status==="in-progress"?"bg-blue-100 text-blue-700":"bg-gray-100 text-gray-700",y=f===p.phase;return u("div",{className:`bg-white border rounded-xl p-5 ${y?"border-indigo-300 ring-1 ring-indigo-100":"border-gray-200"}`,children:[u("div",{className:"flex items-center justify-between mb-2",children:[u("div",{className:"flex items-center gap-2",children:[i("p",{className:"font-semibold capitalize",children:f}),y&&i("span",{className:"text-xs text-indigo-600 font-medium",children:"current"})]}),i("span",{className:`text-xs font-medium px-2 py-0.5 rounded-full ${v}`,children:x.status||"todo"})]}),x.summary&&i("p",{className:"text-sm text-gray-500",children:x.summary})]},f)})})]})}function ex(){const[e,t]=m.useState([]),[n,r]=m.useState(!0),l=()=>wg().then(a=>t(a.items??[])).catch(()=>{}).finally(()=>r(!1));return m.useEffect(()=>{l()},[]),n?i("div",{className:"text-center py-20 text-gray-600",children:"Loading..."}):e.length?u("div",{children:[i("h1",{className:"text-2xl font-bold mb-6",children:"Approval Queue"}),i("div",{className:"grid grid-cols-1 gap-4",children:e.map((a,s)=>u("div",{className:"bg-white border border-gray-200 rounded-xl p-6",children:[i("p",{className:"text-xs text-gray-600 font-mono mb-1",children:a.id}),i("p",{className:"text-gray-700 mb-4",children:a.description||a.action||JSON.stringify(a)}),i("div",{className:"flex gap-3",children:i("span",{className:"bg-gray-100 text-gray-600 text-xs px-2 py-1 rounded-full",children:a.pattern??"standard"})})]},s))})]}):i("div",{className:"text-center py-20 text-gray-600",children:"No pending approvals."})}function tx(){const[e,t]=m.useState([]),[n,r]=m.useState(!0);return m.useEffect(()=>{bg().then(l=>t(l.snapshots??[])).catch(()=>{}).finally(()=>r(!1))},[]),n?i("div",{className:"text-center py-20 text-gray-600",children:"Loading..."}):e.length?u("div",{children:[i("h1",{className:"text-2xl font-bold mb-6",children:"Snapshots"}),i("div",{className:"grid grid-cols-1 gap-4",children:e.map((l,a)=>u("div",{className:"bg-white border border-gray-200 rounded-xl p-6",children:[u("div",{className:"flex items-center justify-between mb-3",children:[i("span",{className:"text-sm text-gray-500",children:l.capturedAt?new Date(l.capturedAt).toLocaleString():"—"}),l.providers&&i("span",{className:"text-xs text-gray-600",children:l.providers.join(", ")})]}),i("p",{className:"text-sm text-gray-700 whitespace-pre-wrap",children:l.summary??JSON.stringify(l).slice(0,300)})]},a))})]}):i("div",{className:"text-center py-20 text-gray-600",children:"No snapshots recorded yet."})}function nx(){const[e,t]=m.useState([]),[n,r]=m.useState([]),[l,a]=m.useState(!0);return m.useEffect(()=>{Fn().then(s=>{t(s.personas??[]),r(s.specialists??[])}).catch(()=>{}).finally(()=>a(!1))},[]),l?i("div",{className:"text-center py-20 text-gray-600",children:"Loading..."}):u("div",{children:[i("h1",{className:"text-2xl font-bold mb-6",children:"Agents"}),e.length>0&&u("div",{className:"mb-8",children:[i("h2",{className:"text-sm font-semibold text-gray-500 uppercase tracking-wide mb-3",children:"Entry Points"}),i("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:e.map((s,o)=>u("div",{className:"bg-white border border-gray-200 rounded-xl p-5",children:[i("p",{className:"font-semibold",children:s.name}),i("p",{className:"text-sm text-gray-500 mb-2",children:s.role}),i("p",{className:"text-sm text-gray-600",children:s.description})]},o))})]}),n.length>0&&u("div",{children:[i("h2",{className:"text-sm font-semibold text-gray-500 uppercase tracking-wide mb-3",children:"Specialists"}),i("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:n.map((s,o)=>u("div",{className:"bg-white border border-gray-200 rounded-xl p-5",children:[i("p",{className:"font-semibold",children:s.name}),i("p",{className:"text-sm text-gray-600",children:s.description})]},o))})]}),e.length===0&&n.length===0&&i("div",{className:"text-center py-20 text-gray-600",children:"No agents found."})]})}function rx(){const[e,t]=m.useState([]),[n,r]=m.useState(!0);return m.useEffect(()=>{Fn().then(l=>t(l.skills??[])).catch(()=>{}).finally(()=>r(!1))},[]),n?i("div",{className:"text-center py-20 text-gray-600",children:"Loading..."}):u("div",{children:[i("h1",{className:"text-2xl font-bold mb-6",children:"Skills"}),e.length===0?i("div",{className:"text-center py-20 text-gray-600",children:"No skills found."}):i("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:e.map((l,a)=>u("div",{className:"bg-white border border-gray-200 rounded-xl p-5",children:[i("p",{className:"font-semibold capitalize mb-2",children:l.category}),i("div",{className:"flex flex-wrap gap-1.5",children:(l.files??[]).map((s,o)=>i("span",{className:"bg-gray-100 text-gray-600 text-xs px-2 py-0.5 rounded-full",children:s.replace(/\.(md|mjs)$/,"").replace(/-/g," ")},o))})]},a))})]})}function oa({category:e,title:t,intro:n}){const[r,l]=m.useState([]),[a,s]=m.useState(null),[o,c]=m.useState(""),[p,f]=m.useState(""),[x,v]=m.useState("original"),[y,w]=m.useState([]),[b,C]=m.useState(null),[g,d]=m.useState(!1),[h,N]=m.useState(null),[S,L]=m.useState("");m.useEffect(()=>{Yc(e).then(D=>l(D.items)).catch(D=>C(D.message))},[e]),m.useEffect(()=>{a&&(C(null),N(null),Xc(e,a).then(D=>{c(D.content),f(D.content),v(D.source)}).catch(D=>C(D.message)),Zc(e,a).then(D=>w(D.backups)).catch(()=>w([])))},[a,e]);const R=o!==p,k=r.filter(D=>!S||D.name.toLowerCase().includes(S.toLowerCase()));async function A(){if(a){d(!0),C(null),N(null);try{const D=await Pg(e,a,o);N(`Saved (${D.wrote} bytes${D.backupPath?", backup created":""})`),f(o);const O=await Yc(e);l(O.items);const H=await Zc(e,a);w(H.backups)}catch(D){C(D.message)}finally{d(!1)}}}async function j(D){if(a){d(!0),C(null);try{await _g(e,a,D);const O=await Xc(e,a);c(O.content),f(O.content),N(`Restored from ${D}`)}catch(O){C(O.message)}finally{d(!1)}}}return u("div",{className:"max-w-6xl space-y-6",children:[u("header",{children:[i("p",{className:"text-text-dim text-xs uppercase tracking-wider mb-1",children:"Page"}),i("h1",{className:"text-3xl font-semibold tracking-tight",children:t}),i("p",{className:"text-text-muted text-sm mt-2",children:n})]}),b&&i("div",{className:"card",style:{borderColor:"var(--status-down)"},children:i("p",{className:"text-sm",children:b})}),u("div",{className:"grid grid-cols-1 lg:grid-cols-[260px_1fr] gap-6",children:[u("aside",{className:"space-y-3",children:[i("input",{type:"text",placeholder:"Filter…",value:S,onChange:D=>L(D.target.value),className:"w-full px-3 py-2 border border-border rounded bg-surface text-sm"}),u("ul",{className:"space-y-1 max-h-[60vh] overflow-y-auto",children:[k.map(D=>i("li",{children:u("button",{type:"button",onClick:()=>s(D.name),className:["w-full text-left px-3 py-1.5 rounded text-sm transition-colors flex items-center justify-between gap-2",a===D.name?"bg-bg-muted border-l-2 border-aurora-cyan":"hover:bg-bg-muted"].join(" "),children:[i("span",{className:"font-mono text-xs truncate",children:D.name}),D.hasOverride&&i("span",{className:"pip pip-healthy text-[10px]",children:"edited"})]})},D.name)),k.length===0&&i("li",{className:"text-xs text-text-dim px-3 py-2",children:"No items match."})]})]}),u("section",{className:"space-y-4",children:[!a&&i("div",{className:"card",children:i("p",{className:"text-sm text-text-muted",children:"Select an item on the left to view or edit."})}),a&&u(Ce,{children:[u("div",{className:"flex items-center justify-between flex-wrap gap-2",children:[u("div",{children:[i("h2",{className:"text-lg font-semibold font-mono",children:a}),u("p",{className:"text-xs text-text-dim mt-0.5",children:["source: ",i("span",{className:"font-mono",children:x})]})]}),u("div",{className:"flex items-center gap-2",children:[i("button",{type:"button",disabled:!R||g,onClick:A,className:"btn btn-primary disabled:opacity-50 disabled:cursor-not-allowed text-sm",children:g?"Saving…":"Save"}),i("button",{type:"button",disabled:!R||g,onClick:()=>c(p),className:"btn disabled:opacity-50 disabled:cursor-not-allowed text-sm",children:"Discard"})]})]}),h&&i("div",{className:"card text-sm",style:{borderColor:"var(--status-healthy)"},children:h}),i("textarea",{value:o,onChange:D=>c(D.target.value),className:"w-full h-[55vh] p-3 border border-border rounded bg-surface font-mono text-xs leading-relaxed",spellCheck:!1}),y.length>0&&u("section",{className:"card",children:[u("h3",{className:"text-sm uppercase tracking-wider text-text-dim mb-3",children:["Backups (",y.length,")"]}),i("ul",{className:"space-y-2",children:y.map(D=>u("li",{className:"flex items-center justify-between gap-3 text-xs",children:[i("div",{className:"flex-1 font-mono truncate",children:D.filename}),u("div",{className:"text-text-dim whitespace-nowrap",children:[D.size,"B · ",new Date(D.mtimeMs).toLocaleString()]}),i("button",{type:"button",onClick:()=>j(D.filename),className:"btn text-xs",disabled:g,children:"Restore"})]},D.filename))})]})]})]})]})]})}function lx(){return i(oa,{category:"personas",title:"Personas",intro:"Edit Construct personas. Originals live in personas/; edits land at .cx/personas/, with prior content snapshotted to .cx/backups/personas/."})}function ax(){return i(oa,{category:"agents",title:"Agent prompts",intro:"Edit specialist agent prompts (cx-architect, cx-engineer, cx-product-manager, …). Originals in specialists/prompts/; overrides at .cx/agents/, backups at .cx/backups/agents/."})}function ix(){return i(oa,{category:"skills",title:"Skills",intro:"Edit skill guidance. Originals live in skills/; edits land at .cx/skills/, with prior content snapshotted to .cx/backups/skills/. Custom skills go in .cx/skills/custom/."})}function sx(){return i(oa,{category:"rules",title:"Rules",intro:"Edit shared rules. Originals live in rules/; edits land at .cx/rules/, with prior content snapshotted to .cx/backups/rules/."})}function ox(){const[e,t]=m.useState([]),[n,r]=m.useState(0),[l,a]=m.useState(null),[s,o]=m.useState(!0);return m.useEffect(()=>{fetch("/api/audit?limit=200").then(c=>c.json()).then(c=>{c.error?a(c.error):(t(c.entries),r(c.total))}).catch(c=>a(c.message)).finally(()=>o(!1))},[]),u("div",{className:"max-w-5xl space-y-6",children:[u("header",{children:[i("p",{className:"text-text-dim text-xs uppercase tracking-wider mb-1",children:"Page"}),i("h1",{className:"text-3xl font-semibold tracking-tight",children:"Audit log"}),u("p",{className:"text-text-muted text-sm mt-2",children:["Every config / persona / skill / rules edit appends a line to ",i("code",{className:"px-1 py-0.5 bg-bg-muted rounded",children:".cx/audit.jsonl"}),". Newest first."]})]}),l&&i("div",{className:"card",style:{borderColor:"var(--status-down)"},children:i("p",{className:"text-sm",children:l})}),s&&!l&&i("p",{className:"text-sm text-text-dim",children:"Loading audit entries…"}),!s&&e.length===0&&!l&&u("section",{className:"card",children:[i("h2",{className:"text-lg font-semibold mb-2",children:"No audit entries yet"}),u("p",{className:"text-sm text-text-muted",children:["The log is created on first config or override edit. Try saving a change in ",i("code",{className:"px-1 py-0.5 bg-bg-muted rounded",children:"/config"})," or ",i("code",{className:"px-1 py-0.5 bg-bg-muted rounded",children:"/personas"}),"."]})]}),e.length>0&&u("section",{className:"card",children:[u("p",{className:"text-xs text-text-dim mb-3",children:["Showing ",e.length," of ",n," entries"]}),u("table",{className:"w-full text-sm",children:[i("thead",{className:"text-xs uppercase tracking-wider text-text-dim",children:u("tr",{children:[i("th",{className:"text-left font-normal pb-3 pr-4 whitespace-nowrap",children:"When"}),i("th",{className:"text-left font-normal pb-3 pr-4",children:"Action"}),i("th",{className:"text-left font-normal pb-3 pr-4",children:"Detail"})]})}),i("tbody",{children:e.map((c,p)=>u("tr",{className:"border-t border-border align-top",children:[i("td",{className:"py-2 pr-4 text-xs text-text-dim whitespace-nowrap font-mono",children:new Date(c.ts).toLocaleString()}),i("td",{className:"py-2 pr-4 font-mono text-xs",children:c.action}),u("td",{className:"py-2 pr-4 text-xs text-text-muted",children:[c.keys&&u("div",{children:["keys: ",c.keys.join(", ")]}),c.bytes!=null&&u("div",{children:["bytes: ",c.bytes]}),c.backupPath&&u("div",{children:["backup: ",i("span",{className:"font-mono",children:c.backupPath.split("/").slice(-3).join("/")})]}),c.path&&u("div",{className:"text-text-dim",children:["path: ",c.path.split("/").slice(-2).join("/")]})]})]},p))})]})]})]})}function cx(e){return e==="healthy"?"pip pip-healthy":e==="needs_attention"?"pip pip-degraded":e==="failing"||e==="broken"?"pip pip-down":"pip"}function ux(){const[e,t]=m.useState([]),[n,r]=m.useState(0),[l,a]=m.useState(!0),[s,o]=m.useState(null),[c,p]=m.useState(!0),[f,x]=m.useState(null),[v,y]=m.useState(""),[w,b]=m.useState(!1),[C,g]=m.useState(null);m.useEffect(()=>{fetch("/api/performance/reviews").then(h=>h.json()).then(h=>{h.error?o(h.error):(t(h.reviews||[]),r(h.mockFiltered||0),a(h.generatorImplemented!==!1))}).catch(h=>o(h.message)).finally(()=>p(!1))},[]);async function d(h){b(!0);try{const N=await fetch("/api/performance/feedback",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({agent:h,text:v})}),S=await N.json();if(!N.ok)throw new Error(S.error||`HTTP ${N.status}`);g(`Feedback saved to .cx/feedback/${S.filename}`),y(""),x(null)}catch(N){g(`Error: ${N.message}`)}finally{b(!1)}}return u("div",{className:"max-w-5xl space-y-6",children:[u("header",{children:[i("p",{className:"text-text-dim text-xs uppercase tracking-wider mb-1",children:"Page"}),i("h1",{className:"text-3xl font-semibold tracking-tight",children:"Performance reviews"}),u("p",{className:"text-text-muted text-sm mt-2",children:["Auto-generated end-of-session summaries from ",i("code",{className:"px-1 py-0.5 bg-bg-muted rounded",children:"~/.cx/performance-reviews/"}),". Each agent carries invocations + avg-score + trend + status. Add feedback to seed proposed prompt updates."]})]}),s&&i("div",{className:"card",style:{borderColor:"var(--status-down)"},children:i("p",{className:"text-sm",children:s})}),C&&i("div",{className:"card",style:{borderColor:"var(--status-healthy)"},children:i("p",{className:"text-sm",children:C})}),c&&i("p",{className:"text-sm text-text-dim",children:"Loading reviews…"}),!c&&e.length===0&&!s&&u("section",{className:"card",children:[i("h2",{className:"text-lg font-semibold mb-2",children:"No performance reviews yet"}),u("p",{className:"text-sm text-text-muted",children:["Run ",i("code",{className:"px-1 py-0.5 bg-bg-muted rounded",children:"construct review run"})," to generate the first review from your cost ledger + telemetry generations. The Stop hook also runs this every 24 hours automatically once the hooks are installed."]}),n>0&&u("p",{className:"text-xs text-text-dim mt-3",children:["Filtered out ",n," mock fixture file",n===1?"":"s"," (",i("code",{className:"px-1 py-0.5 bg-bg-muted rounded",children:"test-*-mock.json"}),") in ",i("code",{className:"px-1 py-0.5 bg-bg-muted rounded",children:"~/.cx/performance-reviews/"})," — those are test seeds, not real reviews."]})]}),e.map(h=>{var N;return u("section",{className:"card space-y-4",children:[u("header",{className:"flex items-start justify-between flex-wrap gap-3",children:[u("div",{children:[u("h2",{className:"text-lg font-semibold",children:["Review ",new Date(h.generated).toLocaleDateString()]}),u("p",{className:"text-xs text-text-dim mt-1",children:["Period: ",h.period.days," days · ",new Date(h.period.from).toLocaleDateString()," → ",new Date(h.period.to).toLocaleDateString()]})]}),i("div",{className:"text-xs text-text-dim font-mono",children:h.filename})]}),u("table",{className:"w-full text-sm",children:[i("thead",{className:"text-xs uppercase tracking-wider text-text-dim",children:u("tr",{children:[i("th",{className:"text-left font-normal pb-2",children:"Agent"}),i("th",{className:"text-right font-normal pb-2",children:"Invocations"}),i("th",{className:"text-right font-normal pb-2",children:"Avg score"}),i("th",{className:"text-right font-normal pb-2",children:"Fail rate"}),i("th",{className:"text-left font-normal pb-2 pl-3",children:"Trend"}),i("th",{className:"text-left font-normal pb-2 pl-3",children:"Status"}),i("th",{className:"text-right font-normal pb-2"})]})}),i("tbody",{children:(N=h.agentStats)==null?void 0:N.map(S=>{var L;return u(Ce,{children:[u("tr",{className:"border-t border-border align-top",children:[i("td",{className:"py-2 font-mono text-xs",children:S.name}),i("td",{className:"py-2 text-right",children:S.invocations}),i("td",{className:"py-2 text-right",children:(L=S.avgScore)==null?void 0:L.toFixed(2)}),u("td",{className:"py-2 text-right",children:[Math.round((S.failureRate||0)*100),"%"]}),i("td",{className:"py-2 pl-3 text-xs",children:S.trend}),i("td",{className:"py-2 pl-3",children:u("span",{className:cx(S.status),children:[i("span",{"aria-hidden":"true",children:S.status==="healthy"?"✓":S.status==="needs_attention"?"!":"✕"}),S.status]})}),i("td",{className:"py-2 text-right",children:i("button",{type:"button",onClick:()=>{x(S.name),y("")},className:"btn text-xs",children:"Feedback"})})]},S.name),f===S.name&&i("tr",{className:"bg-bg-muted",children:u("td",{colSpan:7,className:"p-3",children:[u("label",{className:"block text-xs uppercase tracking-wider text-text-dim mb-2",children:["Feedback for ",S.name]}),i("textarea",{value:v,onChange:R=>y(R.target.value),rows:4,placeholder:"Describe what should change about this agent's behavior. The feedback seeds proposed prompt updates.",className:"w-full p-2 border border-border rounded bg-surface text-sm"}),u("div",{className:"flex items-center gap-2 mt-2",children:[i("button",{type:"button",onClick:()=>d(S.name),disabled:!v.trim()||w,className:"btn btn-primary text-xs disabled:opacity-50",children:w?"Saving…":"Save feedback"}),i("button",{type:"button",onClick:()=>{x(null),y("")},className:"btn text-xs",children:"Cancel"})]})]})},`${S.name}-feedback`)]})})})]})]},h.filename)})]})}function dx({items:e}){const[t,n]=m.useState(!1),[r,l]=m.useState(""),[a,s]=m.useState(0),o=m.useRef(null),c=Pp();if(m.useEffect(()=>{function v(y){if((y.metaKey||y.ctrlKey)&&y.key.toLowerCase()==="k"){y.preventDefault(),n(w=>!w),l(""),s(0);return}y.key==="Escape"&&t&&(y.preventDefault(),n(!1))}return window.addEventListener("keydown",v),()=>window.removeEventListener("keydown",v)},[t]),m.useEffect(()=>{t&&setTimeout(()=>{var v;return(v=o.current)==null?void 0:v.focus()},10)},[t]),!t)return null;const p=e.filter(v=>!r||v.label.toLowerCase().includes(r.toLowerCase())),f=Math.min(a,Math.max(0,p.length-1));function x(v){if(v.key==="ArrowDown"){v.preventDefault(),s(y=>Math.min(p.length-1,y+1));return}if(v.key==="ArrowUp"){v.preventDefault(),s(y=>Math.max(0,y-1));return}if(v.key==="Enter"){v.preventDefault();const y=p[f];y&&(c(y.path),n(!1))}}return i("div",{role:"dialog","aria-modal":"true","aria-label":"Command palette",onClick:()=>n(!1),style:{position:"fixed",inset:0,background:"rgba(0, 0, 0, 0.4)",zIndex:100,display:"flex",alignItems:"flex-start",justifyContent:"center",paddingTop:"15vh"},children:u("div",{onClick:v=>v.stopPropagation(),className:"card",style:{width:"90%",maxWidth:"560px",padding:0,background:"var(--surface)",borderColor:"var(--border)"},children:[i("input",{ref:o,type:"text",value:r,placeholder:"Jump to page…",onChange:v=>{l(v.target.value),s(0)},onKeyDown:x,className:"w-full p-4 bg-surface text-text border-b border-border focus:outline-none",style:{fontSize:"1rem"}}),u("ul",{className:"max-h-96 overflow-y-auto",role:"listbox",children:[p.length===0&&i("li",{className:"px-4 py-3 text-sm text-text-dim",children:"No matches."}),p.map((v,y)=>u("li",{role:"option","aria-selected":y===f,className:"px-4 py-2.5 text-sm cursor-pointer flex items-center justify-between",style:y===f?{background:"var(--bg-muted)",borderLeft:"2px solid var(--aurora-cyan)"}:{},onMouseEnter:()=>s(y),onClick:()=>{c(v.path),n(!1)},children:[i("span",{children:v.label}),i("span",{className:"text-xs text-text-dim font-mono",children:v.path})]},v.path))]}),u("div",{className:"px-4 py-2 text-xs text-text-dim border-t border-border flex items-center gap-3",children:[i("span",{children:"↑↓ navigate"}),i("span",{children:"↵ open"}),i("span",{children:"esc close"})]})]})})}function px(){const[e,t]=m.useState([]),[n,r]=m.useState([]),[l,a]=m.useState(!0);return m.useEffect(()=>{Fn().then(s=>{t(s.cliCommands??[]),r(s.commands??[])}).catch(()=>{}).finally(()=>a(!1))},[]),l?i("div",{className:"text-center py-20 text-gray-600",children:"Loading..."}):u("div",{children:[i("h1",{className:"text-2xl font-bold mb-6",children:"Commands"}),e.length>0&&u("div",{className:"mb-8",children:[i("h2",{className:"text-sm font-semibold text-gray-500 uppercase tracking-wide mb-3",children:"CLI"}),i("div",{className:"grid grid-cols-1 gap-2",children:e.map((s,o)=>u("div",{className:"bg-white border border-gray-200 rounded-lg px-4 py-3",children:[u("p",{className:"font-mono text-sm font-medium",children:["construct ",s.name]}),i("p",{className:"text-sm text-gray-500",children:s.description})]},o))})]}),n.length>0&&u("div",{children:[i("h2",{className:"text-sm font-semibold text-gray-500 uppercase tracking-wide mb-3",children:"Slash"}),i("div",{className:"grid grid-cols-1 gap-4",children:n.map((s,o)=>u("div",{className:"bg-white border border-gray-200 rounded-xl p-5",children:[i("p",{className:"font-semibold mb-2",children:s.domain}),i("div",{className:"flex flex-wrap gap-2",children:(s.commands??[]).map((c,p)=>i("span",{className:"bg-gray-100 text-gray-700 text-xs px-2 py-1 rounded-full font-mono",children:c.slash},p))})]},o))})]}),e.length===0&&n.length===0&&i("div",{className:"text-center py-20 text-gray-600",children:"No commands found."})]})}function fx(){const[e,t]=m.useState([]),[n,r]=m.useState(!0);if(m.useEffect(()=>{Fn().then(a=>t(a.hooks??[])).catch(()=>{}).finally(()=>r(!1))},[]),n)return i("div",{className:"text-center py-20 text-gray-600",children:"Loading..."});const l={};for(const a of e){const s=a.phase??"Other";l[s]||(l[s]=[]),l[s].push(a)}return u("div",{children:[i("h1",{className:"text-2xl font-bold mb-6",children:"Hooks"}),e.length===0?i("div",{className:"text-center py-20 text-gray-600",children:"No hooks configured."}):Object.entries(l).map(([a,s])=>u("div",{className:"mb-6",children:[i("h2",{className:"text-sm font-semibold text-gray-500 uppercase tracking-wide mb-3",children:a}),i("div",{className:"grid grid-cols-1 gap-2",children:s.map((o,c)=>u("div",{className:"bg-white border border-gray-200 rounded-lg px-4 py-3 flex items-start gap-3",children:[i("span",{className:`w-2 h-2 rounded-full mt-1.5 flex-shrink-0 ${o.blocking?"bg-yellow-500":"bg-gray-300"}`}),u("div",{children:[i("p",{className:"text-sm text-gray-700",children:o.description}),!o.blocking&&i("p",{className:"text-xs text-gray-600 mt-0.5",children:"async"})]})]},c))})]},a))]})}function mx(){const[e,t]=m.useState({}),[n,r]=m.useState(!0);if(m.useEffect(()=>{Os().then(a=>t(a.mcpServers??{})).catch(()=>{}).finally(()=>r(!1))},[]),n)return i("div",{className:"text-center py-20 text-gray-600",children:"Loading..."});const l=Object.entries(e);return u("div",{children:[i("h1",{className:"text-2xl font-bold mb-6",children:"MCP Servers"}),l.length===0?i("div",{className:"text-center py-20 text-gray-600",children:"No MCP servers configured."}):l.map(([a,s])=>u("div",{className:"bg-white border border-gray-200 rounded-xl p-5 mb-4",children:[u("div",{className:"flex items-center justify-between mb-2",children:[i("p",{className:"font-semibold",children:a}),i("span",{className:"bg-gray-100 text-gray-600 text-xs px-2 py-0.5 rounded-full",children:s.type??"stdio"})]}),i("p",{className:"text-sm text-gray-500 mb-2",children:s.description??s.command??s.url??""}),s.command&&u("p",{className:"text-xs text-gray-600 font-mono",children:[s.command," ",Array.isArray(s.args)?s.args.join(" "):""]})]},a))]})}function hx(){const[e,t]=m.useState(null),[n,r]=m.useState(!0);return m.useEffect(()=>{Fn().then(l=>t(l.plugins??null)).catch(()=>{}).finally(()=>r(!1))},[]),n?i("div",{className:"text-center py-20 text-gray-600",children:"Loading..."}):e?u("div",{children:[i("h1",{className:"text-2xl font-bold mb-6",children:"Plugins"}),e.status&&u("p",{className:"text-sm text-gray-500 mb-4",children:["Status: ",e.status]}),e.summary&&i("p",{className:"text-sm text-gray-500 mb-4",children:e.summary}),i("div",{className:"grid grid-cols-1 gap-4",children:(e.entries??[]).map((l,a)=>u("div",{className:"bg-white border border-gray-200 rounded-xl p-5",children:[i("p",{className:"font-semibold",children:l.name}),i("p",{className:"text-sm text-gray-500 mb-2",children:l.description}),u("div",{className:"flex flex-wrap gap-2 text-xs text-gray-600",children:[i("span",{children:l.id}),u("span",{children:["v",l.version]}),l.builtIn&&i("span",{className:"bg-gray-100 px-1.5 py-0.5 rounded",children:"built-in"})]})]},a))})]}):i("div",{className:"text-center py-20 text-gray-600",children:"No plugin data."})}const za="px-2 py-0.5 text-xs font-medium rounded border border-indigo-600 bg-indigo-600 text-white hover:bg-indigo-700 transition-colors disabled:opacity-50",Zr="px-2 py-0.5 text-xs font-medium rounded border border-gray-300 bg-white text-gray-800 hover:bg-gray-100 transition-colors disabled:opacity-50",gx="px-2 py-0.5 text-xs font-medium rounded border border-red-300 bg-white text-red-700 hover:bg-red-50 transition-colors disabled:opacity-50";function xx({credentials:e,kind:t,envPath:n,onChange:r,opAvailable:l=!1}){const a=e.filter(o=>o.kind===t),s=o=>{try{navigator.clipboard.writeText(o)}catch{}};return u("div",{className:"mt-6 bg-white border border-gray-200 rounded-lg overflow-hidden",children:[u("div",{className:"px-4 py-2 border-b border-gray-200 bg-gray-50 flex items-center justify-between gap-2 flex-wrap",children:[i("p",{className:"text-xs font-semibold text-gray-700 uppercase tracking-wide",children:"Credentials"}),u("div",{className:"flex items-center gap-3",children:[l&&i("span",{className:"text-[10px] text-emerald-700 bg-emerald-50 border border-emerald-200 rounded px-1.5 py-0.5 font-medium",children:"1Password CLI detected"}),n&&i("button",{onClick:()=>s(n),className:"text-xs font-medium text-indigo-700 hover:text-indigo-900 transition-colors",children:"Copy config path"})]})]}),u("table",{className:"w-full text-sm",children:[i("thead",{className:"bg-gray-50 border-b border-gray-200",children:u("tr",{className:"text-xs uppercase tracking-wide text-gray-700",children:[i("th",{className:"text-left px-3 py-1.5 font-semibold",children:"Provider"}),i("th",{className:"text-left px-3 py-1.5 font-semibold",children:"Env var"}),i("th",{className:"text-left px-3 py-1.5 font-semibold",children:"Value"}),i("th",{className:"text-right px-3 py-1.5 font-semibold w-52",children:"Actions"})]})}),i("tbody",{className:"divide-y divide-gray-100",children:a.flatMap(o=>o.vars.map((c,p)=>i(vx,{provider:o.label,configured:o.configured,showProvider:p===0,v:c,onChange:r,opAvailable:l},`${o.provider}-${c.envVar}`)))})]})]})}function vx({provider:e,configured:t,showProvider:n,v:r,onChange:l,opAvailable:a}){const[s,o]=m.useState(!1),[c,p]=m.useState(""),[f,x]=m.useState(!1),[v,y]=m.useState(!1),[w,b]=m.useState(null),[C,g]=m.useState(!1),[d,h]=m.useState(""),[N,S]=m.useState(!1),L=()=>{o(!0),p(""),x(!1),b(null)},R=()=>{o(!1),p(""),b(null)},k=()=>{g(!0),h(""),b(null)},A=()=>{g(!1),h("")},j=async()=>{if(!d.trim()){b("Enter a 1Password reference like 'op://Development/Anthropic/credential'");return}S(!0),b(null);try{await Wg(r.envVar,d.trim()),g(!1),h(""),l()}catch(B){b(B.message||"pull from 1Password failed")}finally{S(!1)}},D=async()=>{if(!c){b("value required");return}y(!0),b(null);try{await tu(r.envVar,c),o(!1),p(""),l()}catch(B){b(B.message||"save failed")}finally{y(!1)}},O=async()=>{if(confirm(`Unset ${r.envVar}?`)){y(!0),b(null);try{await tu(r.envVar,""),l()}catch(B){b(B.message||"unset failed")}finally{y(!1)}}},H=t==="full"?"bg-green-500":t==="partial"?"bg-yellow-500":"bg-gray-400";return u(m.Fragment,{children:[u("tr",{className:"hover:bg-gray-50",children:[i("td",{className:"px-3 py-1.5",children:n&&u("div",{className:"flex items-center gap-1.5",children:[i("span",{className:`h-1.5 w-1.5 rounded-full ${H}`}),i("span",{className:"text-xs font-medium text-gray-800",children:e})]})}),i("td",{className:"px-3 py-1.5",children:i("code",{className:"text-xs font-mono text-gray-800",children:r.envVar})}),i("td",{className:"px-3 py-1.5",children:i("code",{className:`text-xs font-mono ${r.set?"text-gray-700":"text-gray-500"}`,children:r.preview??"not set"})}),u("td",{className:"px-3 py-1.5",children:[!s&&!C&&u("div",{className:"flex items-center justify-end gap-1.5 flex-wrap",children:[i("button",{onClick:L,disabled:v,className:za,children:r.set?"Update":"Set"}),a&&i("button",{onClick:k,disabled:v,className:Zr,title:"Pull this value from a 1Password vault",children:"1Password…"}),r.set&&i("button",{onClick:O,disabled:v,className:gx,children:"Clear"})]}),s&&u("div",{className:"flex items-center justify-end gap-1",children:[i("button",{onClick:D,disabled:v,className:za,children:v?"…":"Save"}),i("button",{onClick:R,disabled:v,className:Zr,children:"Cancel"})]}),C&&u("div",{className:"flex items-center justify-end gap-1",children:[i("button",{onClick:j,disabled:N,className:za,children:N?"…":"Pull"}),i("button",{onClick:A,disabled:N,className:Zr,children:"Cancel"})]})]})]}),s&&i("tr",{children:u("td",{colSpan:4,className:"px-3 pb-2 bg-gray-50",children:[u("div",{className:"flex items-center gap-2",children:[i("input",{type:f?"text":"password",value:c,onChange:B=>p(B.target.value),onKeyDown:B=>{B.key==="Enter"&&D(),B.key==="Escape"&&R()},placeholder:`new value for ${r.envVar}`,autoFocus:!0,className:"flex-1 px-2 py-1 text-xs border border-gray-300 rounded font-mono"}),i("button",{onClick:()=>x(B=>!B),className:Zr,children:f?"Hide":"Show"})]}),w&&i("p",{className:"mt-1 text-xs text-red-700",children:w})]})}),C&&i("tr",{children:u("td",{colSpan:4,className:"px-3 pb-2 bg-emerald-50/60",children:[i("div",{className:"flex items-center gap-2",children:i("input",{type:"text",value:d,onChange:B=>h(B.target.value),onKeyDown:B=>{B.key==="Enter"&&j(),B.key==="Escape"&&A()},placeholder:`op://Development/${e}/credential`,autoFocus:!0,className:"flex-1 px-2 py-1 text-xs border border-emerald-300 rounded font-mono bg-white"})}),u("p",{className:"mt-1 text-[10px] text-gray-700",children:["Runs ",i("code",{className:"bg-white px-1 rounded font-mono",children:"op read"})," on the host. The ",i("code",{className:"font-mono",children:"op://"})," reference is logged in ",i("code",{className:"font-mono",children:"~/.cx/credential-audit.jsonl"}),"; the resolved value is stored in ",i("code",{className:"font-mono",children:"~/.construct/config.env"})," (mode 0600) the same way as a manual paste."]}),w&&i("p",{className:"mt-1 text-xs text-red-700",children:w})]})})]})}function yx(e){return e==="configured"?"pip pip-healthy":"pip pip-down"}function Nx(){const[e,t]=m.useState(null),[n,r]=m.useState([]),[l,a]=m.useState([]),[s,o]=m.useState(null),[c,p]=m.useState({global:"metered",providers:{}}),[f,x]=m.useState(null),[v,y]=m.useState(null),[w,b]=m.useState(null),[C,g]=m.useState(!1),[d,h]=m.useState({provider:"",label:"",kind:"llm",envVars:[""]}),[N,S]=m.useState(!1),L=()=>qc().then(O=>r(O.credentials??[])).catch(()=>{}),R=()=>eu().then(O=>a(O.providers??[])).catch(()=>{});m.useEffect(()=>{Promise.all([Mp().then(O=>O.providers||[]).catch(O=>(y(O.message),[])),qc().then(O=>O.credentials??[]).catch(()=>[]),Ag().catch(()=>null),eu().then(O=>O.providers??[]).catch(()=>[]),Vg().catch(()=>({available:!1,signedIn:!1,accounts:[]})),Hg().catch(()=>({global:"metered",providers:{}}))]).then(([O,H,B,fe,$e,Le])=>{t(O),r(H),x(B),a(fe),o($e),p(Le)})},[]);const k=async(O,H)=>{try{const B=await Qg(O,H);p(fe=>({...fe,providers:B.providers||{}}))}catch(B){y((B==null?void 0:B.message)||"failed to save billing mode")}},A=O=>{var H,B;return((B=(H=c.providers)==null?void 0:H[O])==null?void 0:B.billingMode)||c.global||"metered"},j=async()=>{b(null),S(!0);try{await Ug({provider:d.provider.trim().toLowerCase(),label:d.label.trim(),kind:d.kind,envVars:d.envVars.map(O=>O.trim().toUpperCase()).filter(Boolean)}),await Promise.all([R(),L()]),g(!1),h({provider:"",label:"",kind:"llm",envVars:[""]})}catch(O){b((O==null?void 0:O.message)||"Failed to save")}finally{S(!1)}},D=async O=>{if(window.confirm(`Remove custom provider "${O}"? Existing env values are kept.`))try{await Bg(O),await Promise.all([R(),L()])}catch(H){b((H==null?void 0:H.message)||"Failed to delete")}};return u("div",{className:"max-w-5xl space-y-6",children:[u("header",{children:[i("p",{className:"text-text-dim text-xs uppercase tracking-wider mb-1",children:"Page"}),i("h1",{className:"text-2xl sm:text-3xl font-semibold tracking-tight",children:"Model providers"}),u("p",{className:"text-text-muted text-sm mt-2",children:["Connection state and credentials for every provider Construct can route to. Keys are stored in ",i("code",{className:"px-1 py-0.5 bg-bg-muted rounded",children:"~/.construct/config.env"})," (mode 0600) and hot-reloaded into ",i("code",{className:"px-1 py-0.5 bg-bg-muted rounded",children:"process.env"})," — no restart needed. Pick the model per tier on the ",i("a",{href:"#/models",className:"underline hover:text-text",children:"Models"})," page after the key lands."]})]}),v&&i("div",{className:"card",style:{borderColor:"var(--status-down)"},children:i("p",{className:"text-sm",children:v})}),!e&&!v&&i("p",{className:"text-sm text-text-dim",children:"Loading providers…"}),e&&e.length>0&&u("section",{className:"card overflow-x-auto",children:[u("p",{className:"text-xs text-text-muted mb-3",children:[i("strong",{children:"Billing"})," sets how each provider's spend is counted on Mission Control.",i("span",{className:"font-mono",children:" subscription"}),` = flat-rate plan (Claude Pro / GPT Plus / OpenRouter credits), excluded from "today's actual spend".`,i("span",{className:"font-mono",children:" metered"})," = pay-per-token, counted toward the daily cap. Global default: ",i("code",{className:"px-1 bg-bg-muted rounded font-mono",children:c.global}),"."]}),u("table",{className:"w-full text-sm min-w-[560px]",children:[i("thead",{className:"text-xs uppercase tracking-wider text-text-dim",children:u("tr",{children:[i("th",{className:"text-left font-normal pb-3 pr-4",children:"Provider"}),i("th",{className:"text-left font-normal pb-3 pr-4",children:"Status"}),i("th",{className:"text-left font-normal pb-3 pr-4",children:"Env var"}),i("th",{className:"text-left font-normal pb-3 pr-4",children:"Billing"}),i("th",{className:"text-right font-normal pb-3"})]})}),i("tbody",{children:e.map(O=>{var H;return u("tr",{className:"border-t border-border",children:[u("td",{className:"py-3 pr-4",children:[i("div",{className:"font-medium",children:O.displayName}),i("div",{className:"text-xs text-text-dim font-mono break-all",children:O.id})]}),i("td",{className:"py-3 pr-4",children:u("span",{className:yx(O.state),children:[i("span",{"aria-hidden":"true",children:O.configured?"✓":"✕"}),O.configured?"configured":"not configured"]})}),i("td",{className:"py-3 pr-4 font-mono text-xs break-all",children:O.envKey}),u("td",{className:"py-3 pr-4",children:[u("select",{value:A(O.id),onChange:B=>k(O.id,B.target.value),className:"px-2 py-1 text-xs border border-border rounded bg-bg","aria-label":`Billing mode for ${O.displayName}`,children:[i("option",{value:"metered",children:"metered"}),i("option",{value:"subscription",children:"subscription"}),i("option",{value:"mixed",children:"mixed"})]}),!((H=c.providers)!=null&&H[O.id])&&i("p",{className:"text-[10px] text-text-dim mt-0.5",children:"inherits global"})]}),i("td",{className:"py-3 text-right",children:i("a",{href:O.docsUrl,target:"_blank",rel:"noreferrer",className:"btn text-xs whitespace-nowrap",children:"Get key ↗"})})]},O.id)})})]})]}),(s==null?void 0:s.available)&&s.signedIn&&s.accounts&&s.accounts.length>0&&u("div",{className:"card border border-emerald-300 bg-emerald-50/40",children:[i("h2",{className:"text-xs uppercase tracking-wider text-text-dim mb-1",children:"1Password CLI"}),u("p",{className:"text-sm",children:["Signed in as ",i("code",{className:"px-1 bg-bg-muted rounded",children:s.accounts[0].email}),". Each credential row below has a ",i("strong",{children:"1Password…"})," button — paste a reference like ",i("code",{className:"px-1 bg-bg-muted rounded font-mono",children:"op://Development/Anthropic/credential"})," and Construct will resolve it on the host (via ",i("code",{className:"px-1 bg-bg-muted rounded",children:"op read"}),") and store the value the same way a manual paste does."]})]}),i(xx,{credentials:n,kind:"llm",envPath:(f==null?void 0:f.envPath)??null,onChange:L,opAvailable:!!(s!=null&&s.available&&(s!=null&&s.signedIn))}),u("section",{className:"card",children:[u("header",{className:"flex items-baseline justify-between mb-3 gap-2 flex-wrap",children:[i("h2",{className:"text-sm uppercase tracking-wider text-text-dim",children:"Custom providers"}),!C&&i("button",{onClick:()=>g(!0),className:"btn btn-primary text-xs",children:"+ Define a custom provider"})]}),u("p",{className:"text-xs text-text-muted mb-3",children:["Need a provider Construct doesn't ship a card for (xAI, Cohere, your own gateway)? Declare its env var(s) here and it'll show up in the credentials editor above. Stored in",i("code",{className:"px-1 bg-bg-muted rounded mx-1",children:"~/.construct/custom-credentials.json"}),"(mode 0600). Values still live in ",i("code",{className:"px-1 bg-bg-muted rounded",children:"~/.construct/config.env"}),"; this file is only the allowlist of names."]}),w&&i("div",{className:"mb-3 px-3 py-2 rounded bg-red-50 border border-red-200 text-red-800 text-xs",children:w}),l.length===0&&!C&&i("p",{className:"text-xs text-text-dim italic",children:"No custom providers defined."}),l.length>0&&i("ul",{className:"space-y-1 mb-3",children:l.map(O=>u("li",{className:"flex items-center justify-between gap-2 bg-bg-muted rounded px-3 py-2 text-sm",children:[u("div",{className:"min-w-0",children:[u("div",{className:"font-medium truncate",children:[O.label," ",u("span",{className:"text-text-dim text-xs font-mono",children:["(",O.provider,")"]})]}),u("div",{className:"text-xs text-text-dim font-mono break-all",children:["env: ",O.envVars.join(", ")," · kind: ",O.kind]})]}),i("button",{onClick:()=>D(O.provider),className:"text-xs text-red-700 hover:text-red-900 whitespace-nowrap",children:"Remove"})]},O.provider))}),C&&u("div",{className:"border border-border rounded p-3 space-y-3 bg-bg-muted/30",children:[u("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-3",children:[u("label",{className:"block",children:[i("span",{className:"text-xs text-text-dim block mb-1",children:"Provider id"}),i("input",{type:"text",value:d.provider,onChange:O=>h({...d,provider:O.target.value}),placeholder:"xai · cohere · my-gateway",className:"w-full px-2 py-1 text-sm font-mono border border-border rounded bg-bg"}),i("span",{className:"text-[10px] text-text-dim block mt-0.5",children:"lowercase letters, digits, hyphens"})]}),u("label",{className:"block",children:[i("span",{className:"text-xs text-text-dim block mb-1",children:"Display label"}),i("input",{type:"text",value:d.label,onChange:O=>h({...d,label:O.target.value}),placeholder:"xAI Grok · Cohere",className:"w-full px-2 py-1 text-sm border border-border rounded bg-bg"})]}),u("label",{className:"block",children:[i("span",{className:"text-xs text-text-dim block mb-1",children:"Kind"}),u("select",{value:d.kind,onChange:O=>h({...d,kind:O.target.value}),className:"w-full px-2 py-1 text-sm border border-border rounded bg-bg",children:[i("option",{value:"llm",children:"LLM provider"}),i("option",{value:"integration",children:"Integration (issue tracker / chat / docs)"})]})]})]}),u("div",{children:[i("span",{className:"text-xs text-text-dim block mb-1",children:"Env var name(s)"}),d.envVars.map((O,H)=>u("div",{className:"flex gap-2 mb-1",children:[i("input",{type:"text",value:O,onChange:B=>{const fe=[...d.envVars];fe[H]=B.target.value,h({...d,envVars:fe})},placeholder:"XAI_API_KEY",className:"flex-1 px-2 py-1 text-sm font-mono border border-border rounded bg-bg"}),i("button",{onClick:()=>h({...d,envVars:d.envVars.filter((B,fe)=>fe!==H)}),disabled:d.envVars.length===1,className:"text-xs text-red-700 hover:text-red-900 disabled:opacity-30","aria-label":"Remove this env var",children:"×"})]},H)),i("button",{onClick:()=>h({...d,envVars:[...d.envVars,""]}),className:"text-xs text-indigo-700 hover:text-indigo-900",children:"+ Add another env var"}),u("p",{className:"text-[10px] text-text-dim mt-1",children:["Must match ",i("code",{children:"/^[A-Z][A-Z0-9_]{1,63}$/"})," · reserved OS vars (PATH, HOME, …) rejected"]})]}),u("div",{className:"flex gap-2 justify-end pt-2 border-t border-border",children:[i("button",{onClick:()=>{g(!1),b(null)},className:"btn text-xs",children:"Cancel"}),i("button",{onClick:j,disabled:N,className:"btn btn-primary text-xs disabled:opacity-50",children:N?"Saving…":"Save provider"})]})]})]})]})}function Ms(){return u("div",{className:"sm:hidden mb-3 px-3 py-2 rounded border border-amber-300 bg-amber-50 text-amber-900 text-xs",children:[i("strong",{children:"Tight fit."})," This page is designed for editing on a wider screen. Status and read-only views (Mission Control · Beads · Doctor) work great here; complex forms are easier with more room."]})}const kt=["reasoning","standard","fast"];function nu(e){return e?e.source==="local"?e.label||"free · runs locally":e.input===0&&e.output===0?"free":!Number.isFinite(e.input)||!Number.isFinite(e.output)?"":`$${e.input.toFixed(2)} in · $${e.output.toFixed(2)} out /1M`:""}function wx(){var G;const[e,t]=m.useState(null),[n,r]=m.useState({reasoning:{primary:"",fallback:[]},standard:{primary:"",fallback:[]},fast:{primary:"",fallback:[]}}),[l,a]=m.useState(null),[s,o]=m.useState({}),[c,p]=m.useState(!1),[f,x]=m.useState(!0),[v,y]=m.useState(null),[w,b]=m.useState(!1),[C,g]=m.useState(null),[d,h]=m.useState(null),[N,S]=m.useState(!1);m.useEffect(()=>{Promise.all([Os().then(P=>P.models??{}).catch(()=>({})),Ig().catch(()=>null)]).then(([P,z])=>{var T,E;const V={reasoning:{primary:"",fallback:[]},standard:{primary:"",fallback:[]},fast:{primary:"",fallback:[]}};for(const Y of kt)V[Y]={primary:((T=P==null?void 0:P[Y])==null?void 0:T.primary)??"",fallback:Array.isArray((E=P==null?void 0:P[Y])==null?void 0:E.fallback)?P[Y].fallback:[]};r(V),a(JSON.parse(JSON.stringify(V))),t(z)}).finally(()=>x(!1))},[]),m.useEffect(()=>{var V;if(!e)return;const P=new Set;for(const T of kt)for(const E of((V=e.tierOptions)==null?void 0:V[T])??[])P.add(E);for(const T of kt){n[T].primary&&P.add(n[T].primary);for(const E of n[T].fallback)E&&P.add(E)}const z=Array.from(P);z.length!==0&&(p(!0),Dg(z).then(T=>o(T.pricing??{})).catch(()=>{}).finally(()=>p(!1)))},[e,n]);const L=m.useMemo(()=>{var P;return((P=e==null?void 0:e.providers)==null?void 0:P.filter(z=>z.configured))??[]},[e]),R=P=>{var z;return((z=e==null?void 0:e.tierOptions)==null?void 0:z[P])??[]},k=P=>{const z=L.flatMap(V=>V.options[P]||[]);return[...new Set(z)]},A=m.useMemo(()=>{const P={reasoning:!1,standard:!1,fast:!1};if(!l)return P;for(const z of kt)P[z]=JSON.stringify(n[z])!==JSON.stringify(l[z]);return P},[n,l]),j=P=>N?R(P):k(P),D=P=>{const z=s[P],V=nu(z);return V?`${P} — ${V}`:P},O=(P,z)=>r(V=>({...V,[P]:{...V[P],primary:z}})),H=(P,z,V)=>r(T=>({...T,[P]:{...T[P],fallback:T[P].fallback.map((E,Y)=>Y===z?V:E)}})),B=P=>r(z=>({...z,[P]:{...z[P],fallback:[...z[P].fallback,""]}})),fe=(P,z)=>r(V=>({...V,[P]:{...V[P],fallback:V[P].fallback.filter((T,E)=>E!==z)}})),$e=async P=>{if(!n[P].primary){h("Primary model required");return}y(P),h(null);try{const z=n[P].fallback.filter(Boolean);await Kg(P,n[P].primary,z),a(V=>V&&{...V,[P]:{primary:n[P].primary,fallback:z}}),r(V=>({...V,[P]:{primary:V[P].primary,fallback:z}}))}catch(z){h(z.message||"save failed")}finally{y(null)}},Le=async()=>{b(!0),h(null),g(null);try{const z=(await $g()).selections||{},V={...n};for(const E of kt)z[E]&&(V[E]={primary:z[E],fallback:n[E].fallback});r(V),a(JSON.parse(JSON.stringify(V)));const T=kt.filter(E=>z[E]).map(E=>`${E}: ${z[E]}`).join(" · ");g(T?`Saved ${T}`:"Polled OpenRouter but no free models met the per-tier context thresholds.")}catch(P){h(P.message||"Auto-pick failed. Set OPENROUTER_API_KEY in Providers, then retry.")}finally{b(!1)}},M=kt.every(P=>!n[P].primary);if(f)return i("div",{className:"text-center py-20 text-gray-600",children:"Loading..."});const F="px-2.5 py-1 text-xs font-medium rounded border border-indigo-600 bg-indigo-600 text-white hover:bg-indigo-700 transition-colors disabled:opacity-50",U="px-2.5 py-1 text-xs font-medium rounded border border-gray-300 bg-white text-gray-800 hover:bg-gray-100 transition-colors disabled:opacity-50",K=((e==null?void 0:e.providers)??[]).filter(P=>P.local);return u("div",{children:[i(Ms,{}),i("h1",{className:"text-xl font-bold mb-1",children:"Model Tiers"}),u("p",{className:"text-xs text-gray-600 mb-3",children:["Construct ships with no model selected — pick one per tier before running any LLM-backed workflow. Pricing is per million tokens (USD). Live OpenRouter numbers refresh every 5 minutes; Anthropic and OpenAI direct endpoints use the published list price.",c&&i("span",{className:"ml-2 text-indigo-600",children:"refreshing…"})]}),M&&u("div",{className:"mb-3 px-3 py-2 rounded bg-amber-50 border border-amber-300 text-amber-900 text-xs flex items-center justify-between gap-3",children:[u("div",{children:[i("p",{className:"font-semibold",children:"No models selected."}),i("p",{children:"Pick a primary for each tier below, or use auto-pick to seed all three tiers from the OpenRouter free catalog."})]}),i("button",{onClick:Le,disabled:w,className:"px-2.5 py-1 text-xs font-medium rounded border border-amber-600 bg-amber-600 text-white hover:bg-amber-700 transition-colors disabled:opacity-50 whitespace-nowrap",children:w?"Polling…":"Auto-pick free models"})]}),!M&&u("div",{className:"mb-3 flex items-center gap-3 text-xs",children:[i("button",{onClick:Le,disabled:w,className:"px-2.5 py-1 font-medium rounded border border-gray-300 bg-white text-gray-800 hover:bg-gray-100 transition-colors disabled:opacity-50",children:w?"Polling…":"Re-pick free OpenRouter models"}),i("span",{className:"text-gray-600",children:"Replaces each tier's primary with the best free OpenRouter model meeting the context threshold (32k reasoning, 16k standard, 8k fast)."})]}),C&&i("div",{className:"mb-3 px-3 py-2 rounded bg-green-50 border border-green-200 text-green-800 text-xs",children:C}),L.length>0&&u("div",{className:"mb-3 px-3 py-2 rounded bg-green-50 border border-green-200 text-xs",children:[u("p",{className:"font-semibold text-green-900 mb-1",children:["Your configured providers (",L.length,")"]}),i("ul",{className:"text-green-800 space-y-0.5 flex flex-wrap gap-x-4 gap-y-0.5",children:L.map(P=>u("li",{className:"inline-flex items-center gap-1",children:[i("span",{className:"text-green-700",children:"✓"}),i("span",{className:"font-mono",children:P.id}),u("span",{className:"text-green-700",children:["— ",P.label]})]},P.id))})]}),L.length===0&&((G=e==null?void 0:e.providers)==null?void 0:G.length)>0&&u("div",{className:"mb-3 px-3 py-2 rounded bg-amber-50 border border-amber-200 text-xs",children:[i("p",{className:"font-semibold text-amber-900 mb-1",children:"No providers configured"}),u("p",{className:"text-amber-800",children:["Add API keys on the ",i("a",{href:"#/providers",className:"underline",children:"Providers"})," page, then models from those providers will appear here."]})]}),e&&u("label",{className:"flex items-center gap-2 mb-3 text-xs text-gray-600 cursor-pointer",children:[i("input",{type:"checkbox",checked:N,onChange:P=>S(P.target.checked),className:"w-3.5 h-3.5 rounded border-gray-300"}),"Show all models (including unconfigured providers)"]}),K.length>0&&u("div",{className:"mb-3 px-3 py-2 rounded bg-indigo-50 border border-indigo-200 text-xs",children:[i("p",{className:"font-semibold text-indigo-900 mb-1",children:"Local providers available"}),i("ul",{className:"text-indigo-900 space-y-0.5",children:K.map(P=>{var z;return u("li",{children:[i("span",{className:"font-mono",children:P.id})," — ",P.label,(z=P.requiresEnv)!=null&&z.length?u(Ce,{children:[" · needs ",i("code",{className:"px-1 bg-white rounded",children:P.requiresEnv.join(", ")})]}):null]},P.id)})})]}),d&&i("div",{className:"mb-3 px-3 py-2 rounded bg-red-50 border border-red-200 text-red-800 text-xs",children:d}),i("div",{className:"bg-white border border-gray-200 rounded-lg overflow-hidden",children:kt.map((P,z)=>{const V=N?(e==null?void 0:e.providers)??[]:L,T=n[P],E=s[T.primary],Y=nu(E),Ir=V.filter(me=>(me.options[P]??[]).length>0).map(me=>({label:me.label,configured:me.configured,models:me.options[P]??[]})),An=me=>u(Ce,{children:[i("option",{value:"",children:"— select model —"}),Ir.map(Ye=>i("optgroup",{label:`${Ye.configured?"":"○ "}${Ye.label}`,children:Ye.models.map(wt=>i("option",{value:wt,children:D(wt)},wt))},Ye.label)),me&&!j(P).includes(me)&&u("option",{value:me,children:[D(me)," (current)"]})]});return u("div",{className:`px-3 py-2.5 ${z>0?"border-t border-gray-200":""}`,children:[u("div",{className:"flex items-center justify-between mb-2",children:[i("p",{className:"text-xs font-semibold text-gray-700 uppercase tracking-wide",children:P}),i("button",{onClick:()=>$e(P),disabled:!A[P]||v===P,className:A[P]?F:U,children:v===P?"Saving…":A[P]?"Save":"Saved"})]}),u("div",{className:"grid grid-cols-[80px_1fr] items-center gap-x-2 gap-y-1",children:[i("label",{className:"text-xs font-medium text-gray-700",children:"Primary"}),u("div",{children:[i("select",{value:T.primary,onChange:me=>O(P,me.target.value),className:"w-full px-2 py-1 text-xs border border-gray-300 rounded bg-white",children:An(T.primary)}),Y&&T.primary&&i("p",{className:"text-[10px] text-gray-600 mt-0.5 font-mono",children:Y})]}),i("label",{className:"text-xs font-medium text-gray-700 self-start pt-1",children:"Fallback"}),u("div",{children:[T.fallback.length===0&&i("p",{className:"text-xs text-gray-600 mb-1",children:"none"}),T.fallback.map((me,Ye)=>u("div",{className:"flex gap-1 mb-1",children:[i("select",{value:me,onChange:wt=>H(P,Ye,wt.target.value),className:"flex-1 px-2 py-1 text-xs border border-gray-300 rounded bg-white",children:An(me)}),i("button",{onClick:()=>fe(P,Ye),className:"px-2 py-0.5 text-xs font-medium rounded border border-red-300 bg-white text-red-700 hover:bg-red-50 transition-colors",children:"×"})]},Ye)),i("button",{onClick:()=>B(P),className:"text-xs font-medium text-indigo-700 hover:text-indigo-900 transition-colors",children:"+ Add fallback"})]})]})]},P)})}),u("p",{className:"mt-4 text-xs text-gray-600",children:["Need to add or rotate an API key? Manage credentials on the"," ",i("a",{href:"#/providers",className:"underline hover:no-underline text-indigo-700",children:"Providers"})," page — the single edit surface for every provider env var."]})]})}const bx=["open","in_progress","blocked","closed","deferred"],Ip={open:"Open",in_progress:"In progress",blocked:"Blocked",closed:"Closed",deferred:"Deferred"},Dp={open:"bg-gray-400",in_progress:"bg-blue-500",blocked:"bg-red-500",closed:"bg-green-500",deferred:"bg-gray-300"},kx={open:"bg-gray-100 text-gray-700",in_progress:"bg-blue-100 text-blue-800",blocked:"bg-red-100 text-red-800",closed:"bg-green-100 text-green-800",deferred:"bg-gray-100 text-gray-700"},Sx={0:"bg-red-100 text-red-800",1:"bg-orange-100 text-orange-800",2:"bg-yellow-100 text-yellow-800",3:"bg-gray-100 text-gray-700"},Cx="px-2.5 py-1 text-xs font-medium rounded border border-gray-300 bg-white text-gray-800 hover:bg-gray-100 transition-colors disabled:opacity-50",ru="px-2.5 py-1 text-xs font-medium rounded-full border transition-colors";function lu(e){const t=Date.now()-new Date(e).getTime();if(Number.isNaN(t)||t<0)return e.slice(0,10);const n=Math.floor(t/1e3);if(n<60)return`${n}s ago`;const r=Math.floor(n/60);if(r<60)return`${r}m ago`;const l=Math.floor(r/60);if(l<24)return`${l}h ago`;const a=Math.floor(l/24);return a<30?`${a}d ago`:`${Math.floor(a/30)}mo ago`}function Ex(){const[e,t]=m.useState(null),[n,r]=m.useState(!0),[l,a]=m.useState("open"),[s,o]=m.useState("all"),[c,p]=m.useState(new Set),f=()=>Jg().then(t).catch(()=>{});m.useEffect(()=>{f().finally(()=>r(!1))},[]);const x=m.useMemo(()=>{if(!e)return[];let y=e.issues;return l!=="all"&&(y=y.filter(w=>w.status===l)),s!=="all"&&(y=y.filter(w=>`P${w.priority}`===s)),[...y].sort((w,b)=>w.priority!==b.priority?w.priority-b.priority:new Date(b.updated_at).getTime()-new Date(w.updated_at).getTime())},[e,l,s]),v=y=>p(w=>{const b=new Set(w);return b.has(y)?b.delete(y):b.add(y),b});return n?i("div",{className:"text-center py-20 text-gray-600",children:"Loading..."}):e?u("div",{children:[u("div",{className:"flex items-center justify-between mb-4",children:[u("h1",{className:"text-xl font-bold",children:["Beads ",u("span",{className:"text-gray-600 font-normal text-sm",children:["— ",e.counts.total," issues"]})]}),i("button",{onClick:f,className:Cx,children:"Refresh"})]}),u("div",{className:"flex flex-wrap items-center gap-2 mb-2",children:[i("span",{className:"text-xs font-semibold text-gray-700 uppercase tracking-wide mr-1",children:"Status"}),i(qr,{label:`All (${e.counts.total})`,active:l==="all",onClick:()=>a("all")}),bx.map(y=>{const w=e.counts.byStatus[y]||0;return w===0&&y!=="open"?null:i(qr,{label:`${Ip[y]} (${w})`,active:l===y,onClick:()=>a(y),dotClass:Dp[y]},y)})]}),u("div",{className:"flex flex-wrap items-center gap-2 mb-4",children:[i("span",{className:"text-xs font-semibold text-gray-700 uppercase tracking-wide mr-1",children:"Priority"}),i(qr,{label:"All",active:s==="all",onClick:()=>o("all")}),[0,1,2,3].map(y=>{const w=`P${y}`,b=e.counts.byPriority[w]||0;return b===0?null:i(qr,{label:`${w} (${b})`,active:s===w,onClick:()=>o(w)},y)})]}),i("div",{className:"bg-white border border-gray-200 rounded-lg overflow-hidden",children:u("table",{className:"w-full text-sm",children:[i("thead",{className:"bg-gray-50 border-b border-gray-200",children:u("tr",{className:"text-xs uppercase tracking-wide text-gray-700",children:[i("th",{className:"text-left px-3 py-1.5 font-semibold w-14",children:"Pri"}),i("th",{className:"text-left px-3 py-1.5 font-semibold w-28",children:"Status"}),i("th",{className:"text-left px-3 py-1.5 font-semibold",children:"Title"}),i("th",{className:"text-left px-3 py-1.5 font-semibold w-32",children:"Owner"}),i("th",{className:"text-left px-3 py-1.5 font-semibold w-24",children:"Updated"})]})}),i("tbody",{className:"divide-y divide-gray-100",children:x.length===0?i("tr",{children:i("td",{colSpan:5,className:"px-3 py-6 text-center text-xs text-gray-600",children:"No issues match these filters."})}):x.map(y=>i(Px,{it:y,expanded:c.has(y.id),onToggle:()=>v(y.id)},y.id))})]})})]}):i("div",{className:"text-center py-20 text-gray-600",children:"No bead data."})}function qr({label:e,active:t,onClick:n,dotClass:r}){const l=t?`${ru} bg-indigo-600 border-indigo-600 text-white`:`${ru} bg-white border-gray-300 text-gray-800 hover:bg-gray-100`;return u("button",{onClick:n,className:l,children:[r&&i("span",{className:`inline-block h-1.5 w-1.5 rounded-full mr-1.5 align-middle ${r}`}),e]})}function Px({it:e,expanded:t,onToggle:n}){const r=e.owner?e.owner.split("@")[0]:"—";return u(Ce,{children:[u("tr",{className:"hover:bg-gray-50 cursor-pointer",onClick:n,children:[i("td",{className:"px-3 py-1.5",children:u("span",{className:`text-xs font-semibold px-1.5 py-0.5 rounded ${Sx[e.priority]||"bg-gray-100 text-gray-700"}`,children:["P",e.priority]})}),i("td",{className:"px-3 py-1.5",children:u("span",{className:`text-xs px-1.5 py-0.5 rounded inline-flex items-center gap-1 ${kx[e.status]||"bg-gray-100 text-gray-700"}`,children:[i("span",{className:`h-1.5 w-1.5 rounded-full ${Dp[e.status]||"bg-gray-400"}`}),Ip[e.status]||e.status]})}),i("td",{className:"px-3 py-1.5",children:u("div",{className:"flex items-center gap-2 min-w-0",children:[i("span",{className:"text-sm text-gray-900 truncate",children:e.title}),i("code",{className:"text-xs text-gray-600 font-mono flex-shrink-0",children:e.id}),e.issue_type&&i("span",{className:"text-xs px-1.5 py-0.5 rounded bg-gray-100 text-gray-700 flex-shrink-0",children:e.issue_type}),e.dependency_count>0&&u("span",{className:"text-xs text-gray-600 flex-shrink-0",children:["⟵ ",e.dependency_count]}),e.dependent_count>0&&u("span",{className:"text-xs text-gray-600 flex-shrink-0",children:["⟶ ",e.dependent_count]}),e.comment_count>0&&u("span",{className:"text-xs text-gray-600 flex-shrink-0",children:["💬 ",e.comment_count]})]})}),i("td",{className:"px-3 py-1.5",children:i("span",{className:"text-xs text-gray-700 truncate",title:e.owner||"",children:r})}),i("td",{className:"px-3 py-1.5",children:i("span",{className:"text-xs text-gray-700",title:e.updated_at,children:lu(e.updated_at)})})]}),t&&e.description&&i("tr",{className:"bg-gray-50",children:u("td",{colSpan:5,className:"px-6 py-3",children:[i("p",{className:"text-xs text-gray-700 whitespace-pre-wrap",children:e.description}),u("p",{className:"text-xs text-gray-600 mt-2",children:["Created ",lu(e.created_at)," · use ",u("code",{className:"px-1 py-0.5 bg-gray-200 rounded",children:["bd show ",e.id]})," for full details"]})]})})]})}function _x(){const[e,t]=m.useState([]),[n,r]=m.useState(!0),[l,a]=m.useState("all");m.useEffect(()=>{kg().then(o=>t(o.artifacts??[])).catch(()=>{}).finally(()=>r(!1))},[]);const s=l==="all"?e:e.filter(o=>o.type===l);return n?i("div",{className:"text-center py-20 text-gray-600",children:"Loading..."}):u("div",{children:[u("div",{className:"flex items-center justify-between mb-6",children:[i("h1",{className:"text-2xl font-bold",children:"Artifacts"}),i("div",{className:"flex gap-1 bg-gray-100 rounded-lg p-1",children:["all","prd","adr","rfc"].map(o=>i("button",{onClick:()=>a(o),className:`px-3 py-1.5 text-sm font-medium rounded-md transition-colors ${l===o?"bg-white text-gray-900 shadow-sm":"text-gray-500 hover:text-gray-700"}`,children:o.toUpperCase()},o))})]}),s.length===0?u("div",{className:"text-center py-20 text-gray-600",children:["No ",l==="all"?"":l.toUpperCase()," artifacts."]}):i("div",{className:"grid grid-cols-1 gap-3",children:s.map((o,c)=>u("div",{className:"bg-white border border-gray-200 rounded-xl p-5 flex items-start justify-between",children:[u("div",{children:[i("span",{className:"text-xs font-semibold uppercase tracking-wide text-gray-600",children:o.type}),i("p",{className:"font-semibold mt-0.5",children:o.title}),i("p",{className:"text-xs text-gray-600 font-mono mt-1",children:o.relativePath??""})]}),i("span",{className:`text-xs font-medium px-2 py-0.5 rounded-full ${o.status==="healthy"?"bg-green-100 text-green-800":o.status==="degraded"?"bg-yellow-100 text-yellow-800":o.status==="unavailable"?"bg-red-100 text-red-800":"bg-gray-100 text-gray-600"}`,children:o.status})]},c))})]})}function Lx(){var b,C;const[e,t]=m.useState("ask"),[n,r]=m.useState(""),[l,a]=m.useState(null),[s,o]=m.useState(null),[c,p]=m.useState(null),[f,x]=m.useState(!1),v=async()=>{if(n.trim()){x(!0);try{a(await Og(n))}catch{}x(!1)}},y=async()=>{x(!0);try{o(await Tg())}catch{}x(!1)},w=async()=>{x(!0);try{p(await Rg())}catch{}x(!1)};return u("div",{children:[i("h1",{className:"text-2xl font-bold mb-6",children:"Knowledge"}),i("div",{className:"flex gap-1 bg-gray-100 rounded-lg p-1 mb-6 w-fit",children:["ask","trends","index"].map(g=>i("button",{onClick:()=>{t(g),g==="trends"&&y(),g==="index"&&w()},className:`px-3 py-1.5 text-sm font-medium rounded-md transition-colors ${e===g?"bg-white text-gray-900 shadow-sm":"text-gray-500 hover:text-gray-700"}`,children:g.charAt(0).toUpperCase()+g.slice(1)},g))}),e==="ask"&&u("div",{className:"bg-white border border-gray-200 rounded-xl p-6",children:[u("div",{className:"flex gap-3 mb-4",children:[i("input",{value:n,onChange:g=>r(g.target.value),onKeyDown:g=>g.key==="Enter"&&v(),placeholder:'e.g. "what are the biggest risks?"',className:"flex-1 border border-gray-200 rounded-lg px-4 py-2 text-sm focus:outline-none focus:border-indigo-400"}),i("button",{onClick:v,disabled:f,className:"bg-gradient-to-r from-indigo-600 to-violet-600 text-white px-5 py-2 rounded-lg text-sm font-medium hover:from-indigo-700 hover:to-violet-700 transition-colors disabled:opacity-50",children:"Ask"})]}),f&&i("p",{className:"text-sm text-gray-600",children:"Thinking..."}),l&&u("div",{className:"bg-gray-50 rounded-lg p-4",children:[i("p",{className:"text-sm whitespace-pre-wrap",children:l.answer}),((b=l.sources)==null?void 0:b.length)>0&&u("div",{className:"mt-3 text-xs text-gray-600",children:[i("p",{className:"font-medium mb-1",children:"Sources:"}),l.sources.slice(0,5).map((g,d)=>u("p",{children:["[",g.source,"] ",g.title]},d))]})]})]}),e==="trends"&&s&&i("div",{className:"grid grid-cols-1 gap-4",children:((C=s.hotTopics)==null?void 0:C.length)>0&&u("div",{className:"bg-white border border-gray-200 rounded-xl p-6",children:[i("p",{className:"font-semibold mb-3",children:"Hot Topics"}),i("div",{className:"flex flex-wrap gap-2",children:s.hotTopics.map((g,d)=>i("span",{style:{fontSize:`${12+g.weightedFrequency*8}px`},className:"bg-gradient-to-r from-indigo-50 to-violet-50 text-indigo-700 px-2 py-0.5 rounded-full",children:g.term},d))})]})}),e==="index"&&c&&u("div",{className:"bg-white border border-gray-200 rounded-xl p-6",children:[u("p",{className:"font-semibold mb-2",children:["Corpus — ",c.total," total chunks"]}),i("div",{className:"space-y-1",children:Object.entries(c.sources??{}).map(([g,d],h)=>u("p",{className:"text-sm text-gray-600",children:[g,": ",d," chunks"]},h))})]})]})}function Tx({initialPath:e,onPick:t,onClose:n}){const[r,l]=m.useState(null),[a,s]=m.useState(null),[o,c]=m.useState(!0),p=f=>{c(!0),s(null),zg(f||void 0).then(x=>l(x)).catch(x=>s((x==null?void 0:x.message)||"Failed to browse filesystem")).finally(()=>c(!1))};return m.useEffect(()=>{p(e??void 0)},[e]),m.useEffect(()=>{const f=x=>{x.key==="Escape"&&n()};return window.addEventListener("keydown",f),()=>window.removeEventListener("keydown",f)},[n]),i("div",{className:"fixed inset-0 z-50 flex items-center justify-center p-4 sm:p-6 bg-black/50",role:"dialog","aria-modal":"true","aria-label":"Choose a directory",children:u("div",{className:"bg-surface border border-border rounded-lg w-full max-w-2xl max-h-[80vh] flex flex-col shadow-xl",children:[u("header",{className:"px-4 py-3 border-b border-border flex items-center justify-between gap-2",children:[i("h2",{className:"text-sm font-semibold",children:"Choose a directory"}),i("button",{onClick:n,"aria-label":"Close",className:"text-xl leading-none px-2",children:"×"})]}),u("div",{className:"px-4 py-2 border-b border-border text-xs text-text-muted flex items-center gap-2 flex-wrap",children:[i("button",{onClick:()=>(r==null?void 0:r.parent)&&p(r.parent),disabled:!(r!=null&&r.parent),className:"px-2 py-1 rounded border border-border bg-bg-muted disabled:opacity-40","aria-label":"Go up one directory",children:"↑"}),i("code",{className:"font-mono break-all flex-1 min-w-0",children:(r==null?void 0:r.path)||"…"})]}),(r==null?void 0:r.roots)&&u("div",{className:"px-4 py-2 border-b border-border text-xs flex items-center gap-2 flex-wrap",children:[i("span",{className:"text-text-dim",children:"Jump to:"}),r.roots.map(f=>i("button",{onClick:()=>p(f),className:"px-2 py-0.5 rounded border border-border bg-bg-muted hover:bg-bg-emphasis font-mono",children:f},f))]}),u("div",{className:"flex-1 overflow-y-auto px-2 py-1",children:[o&&i("p",{className:"text-xs text-text-dim px-2 py-3",children:"Loading…"}),a&&i("p",{className:"text-xs text-red-700 px-2 py-3",children:a}),!o&&!a&&r&&r.entries.length===0&&i("p",{className:"text-xs text-text-dim px-2 py-3 italic",children:"Empty directory."}),!o&&!a&&r&&r.entries.map(f=>u("button",{onClick:()=>f.type==="dir"&&p(`${r.path}/${f.name}`),disabled:f.type!=="dir",className:"w-full text-left px-2 py-1 text-sm rounded hover:bg-bg-muted disabled:opacity-50 disabled:cursor-not-allowed flex items-center gap-2",children:[i("span",{"aria-hidden":"true",className:"text-base",children:f.type==="dir"?"📁":"📄"}),i("span",{className:"font-mono truncate",children:f.name}),f.type!=="dir"&&i("span",{className:"text-[10px] text-text-dim ml-auto",children:"file"})]},f.name))]}),u("footer",{className:"px-4 py-3 border-t border-border flex items-center justify-end gap-2 flex-wrap",children:[i("button",{onClick:n,className:"btn text-xs",children:"Cancel"}),i("button",{onClick:()=>r&&t(r.path),disabled:!(r!=null&&r.path),className:"btn btn-primary text-xs disabled:opacity-50",children:"Use this directory"})]})]})})}function Rx(){const[e,t]=m.useState(null),[n,r]=m.useState([]),[l,a]=m.useState(4),[s,o]=m.useState(!0),[c,p]=m.useState(!0),[f,x]=m.useState(""),[v,y]=m.useState(!1),[w,b]=m.useState(!1),[C,g]=m.useState(null),[d,h]=m.useState(null);m.useEffect(()=>{jg().then(k=>{t(k),r(k.config.parentDirs??[]),a(k.config.maxDepth??4),o(k.config.includeProjectInbox!==!1),p(k.config.includeDocsIntake!==!1)}).catch(k=>g(k.message||"Failed to load intake config"))},[]);const N=m.useMemo(()=>((e==null?void 0:e.guidance)??[]).find(A=>A.value===l)||{value:l,label:`Custom depth (${l})`,detail:`Walks up to ${l} levels of subdirectories below each parent.`},[e,l]),S=()=>{const k=f.trim();if(k){if(n.includes(k)){x("");return}r([...n,k]),x("")}},L=k=>{r(n.filter((A,j)=>j!==k))},R=async()=>{b(!0),g(null);try{const k=await Fg({parentDirs:n,maxDepth:l,includeProjectInbox:s,includeDocsIntake:c});h(new Date().toISOString()),k!=null&&k.config&&(r(k.config.parentDirs??[]),a(k.config.maxDepth??l))}catch(k){g(k.message||"Save failed")}finally{b(!1)}};return e?u("div",{className:"max-w-3xl",children:[i(Ms,{}),i("h1",{className:"text-xl font-bold mb-1",children:"Intake"}),u("p",{className:"text-sm text-text-muted mb-4",children:["Pick the directories the inbox watcher monitors and how deep it descends. Files are ingested into ",i("code",{className:"px-1 bg-bg-muted rounded",children:".cx/knowledge/"})," and queued for triage at ",i("code",{className:"px-1 bg-bg-muted rounded",children:".cx/intake/pending/"}),"."]}),C&&i("div",{className:"mb-3 px-3 py-2 rounded bg-red-50 border border-red-200 text-red-800 text-xs",children:C}),d&&!C&&u("div",{className:"mb-3 px-3 py-2 rounded bg-green-50 border border-green-200 text-green-800 text-xs",children:["Saved at ",new Date(d).toLocaleTimeString(),". The embed daemon picks this up on its next poll cycle."]}),u("section",{className:"card mb-4",children:[i("h2",{className:"text-xs uppercase tracking-wider text-text-dim mb-2",children:"Built-in drop zones"}),i("p",{className:"text-xs text-text-muted mb-3",children:"Always-on locations relative to the project root. Disable a zone if you don't want construct to look there."}),u("label",{className:"flex items-start gap-2 mb-2 text-sm",children:[i("input",{type:"checkbox",checked:s,onChange:k=>o(k.target.checked),className:"mt-0.5"}),u("span",{children:[i("code",{className:"px-1 bg-bg-muted rounded",children:e.defaults.projectInbox}),i("span",{className:"text-text-dim",children:" — drop folder created on demand. Recommended."})]})]}),u("label",{className:"flex items-start gap-2 text-sm",children:[i("input",{type:"checkbox",checked:c,onChange:k=>p(k.target.checked),className:"mt-0.5"}),u("span",{children:[i("code",{className:"px-1 bg-bg-muted rounded",children:e.defaults.docsIntake}),u("span",{className:"text-text-dim",children:[" — picked up when the dir exists (created by ",i("code",{children:"construct docs init"}),")."]})]})]})]}),u("section",{className:"card mb-4",children:[i("h2",{className:"text-xs uppercase tracking-wider text-text-dim mb-2",children:"Parent directories"}),u("p",{className:"text-xs text-text-muted mb-3",children:["Absolute paths or relative to ",i("code",{className:"px-1 bg-bg-muted rounded",children:e.rootDir}),". The watcher scans these in addition to the built-in zones above."]}),n.length===0&&i("p",{className:"text-xs text-text-dim italic mb-3",children:"No extra directories configured."}),i("ul",{className:"mb-3 space-y-1",children:n.map((k,A)=>u("li",{className:"flex items-center justify-between bg-bg-muted rounded px-2 py-1 text-sm",children:[i("code",{className:"font-mono text-xs truncate",children:k}),i("button",{onClick:()=>L(A),className:"text-xs text-red-700 hover:text-red-900 ml-2","aria-label":`Remove ${k}`,children:"Remove"})]},`${k}-${A}`))}),u("div",{className:"flex gap-2 flex-wrap",children:[i("input",{type:"text",value:f,onChange:k=>x(k.target.value),onKeyDown:k=>k.key==="Enter"&&S(),placeholder:"/Users/you/Documents/intake or ../shared-notes",className:"flex-1 min-w-[200px] px-2 py-1 text-sm border border-border rounded bg-bg"}),i("button",{onClick:()=>y(!0),className:"btn text-xs","aria-label":"Browse for directory",children:"Browse…"}),i("button",{onClick:S,disabled:!f.trim(),className:"btn btn-primary text-xs disabled:opacity-50",children:"Add directory"})]}),u("p",{className:"text-[11px] text-text-dim mt-2",children:["Type a path manually (relative or absolute), or click ",i("strong",{children:"Browse…"})," to pick one from your filesystem. Browsing is gated to your home directory and the project root."]})]}),v&&i(Tx,{initialPath:f.trim()||null,onClose:()=>y(!1),onPick:k=>{n.includes(k)||r([...n,k]),y(!1)}}),u("section",{className:"card mb-4",children:[i("h2",{className:"text-xs uppercase tracking-wider text-text-dim mb-2",children:"Subdirectory depth"}),i("p",{className:"text-xs text-text-muted mb-3",children:"How many levels of nested subdirectories the watcher walks below each parent. Higher values are slower on large trees."}),u("div",{className:"flex items-center gap-3 mb-3",children:[i("input",{type:"range",min:0,max:e.hardMaxDepth,value:l,onChange:k=>a(Number(k.target.value)),className:"flex-1","aria-label":"Maximum subdirectory depth"}),i("span",{className:"font-mono text-sm w-8 text-right",children:l})]}),u("div",{className:"bg-bg-muted rounded px-3 py-2 text-xs",children:[i("p",{className:"font-semibold",children:N.label}),i("p",{className:"text-text-muted",children:N.detail})]}),u("details",{className:"mt-2",children:[i("summary",{className:"text-xs text-text-dim cursor-pointer hover:text-text",children:"Depth guide"}),i("ul",{className:"mt-2 space-y-1 text-xs",children:e.guidance.map(k=>u("li",{children:[i("span",{className:"font-mono mr-2",children:k.value}),i("span",{className:"font-semibold",children:k.label})," — ",i("span",{className:"text-text-muted",children:k.detail})]},k.value))})]})]}),u("div",{className:"flex gap-2 items-center",children:[i("button",{onClick:R,disabled:w,className:"btn btn-primary",children:w?"Saving…":"Save intake configuration"}),u("p",{className:"text-xs text-text-dim",children:["Backed by ",i("code",{className:"px-1 bg-bg-muted rounded",children:".cx/intake-config.json"}),"."]})]})]}):u("div",{children:[i("h1",{className:"text-xl font-bold mb-2",children:"Intake"}),C?i("p",{className:"text-sm text-red-700",children:C}):i("p",{className:"text-sm text-text-dim",children:"Loading intake configuration…"})]})}const Fa="/api";function Ox(){const[e,t]=m.useState([]),[n,r]=m.useState(null),[l,a]=m.useState(""),[s,o]=m.useState(""),[c,p]=m.useState(""),[f,x]=m.useState(!1),[v,y]=m.useState(!0),[w,b]=m.useState(!1),C=m.useRef(null);m.useEffect(()=>{Mg().then(N=>{t(N.files??[])}).catch(()=>{}).finally(()=>y(!1))},[]),m.useEffect(()=>{n?fetch(`${Fa}/terraform/file?path=${encodeURIComponent(n)}`).then(N=>N.json()).then(N=>{a(N.content??""),o(N.content??"")}).catch(()=>{}):(a(""),o(""))},[n]);const g=l!==s,d=async()=>{if(!(!n||!g)){b(!0);try{await fetch(`${Fa}/terraform/file`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:n,content:l})}),o(l)}catch{}b(!1)}},h=async N=>{var S;x(!0),p("");try{const R=(S=(await fetch(`${Fa}/terraform/run`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({subcommand:N,environment:"staging"})})).body)==null?void 0:S.getReader(),k=new TextDecoder;if(R)for(;;){const{done:A,value:j}=await R.read();if(A)break;p(D=>D+k.decode(j,{stream:!0}))}}catch(L){p(`Error: ${L.message}`)}x(!1)};return v?i("div",{className:"text-center py-20 text-gray-600",children:"Loading..."}):u("div",{className:"flex flex-col h-full",children:[i("h1",{className:"text-2xl font-bold mb-6",children:"Infrastructure"}),u("div",{className:"flex gap-6 flex-1 min-h-0",children:[u("div",{className:"w-56 flex-shrink-0 bg-white border border-gray-200 rounded-xl overflow-hidden",children:[i("div",{className:"px-4 py-3 border-b border-gray-100",children:i("p",{className:"text-sm font-semibold text-gray-500 uppercase tracking-wide",children:"Terraform Files"})}),u("div",{className:"divide-y divide-gray-50",children:[e.length===0&&i("p",{className:"px-4 py-6 text-sm text-gray-600 text-center",children:"No .tf files found."}),e.map(N=>i("button",{onClick:()=>r(N),className:`w-full text-left px-4 py-2.5 text-sm transition-colors ${n===N?"bg-gradient-to-r from-indigo-50 to-violet-50 text-indigo-700 font-medium border-r-2 border-indigo-500":"text-gray-600 hover:bg-gray-50"}`,children:N},N))]})]}),n?u("div",{className:"flex-1 flex flex-col min-w-0",children:[u("div",{className:"flex items-center justify-between mb-3",children:[u("div",{className:"flex items-center gap-2",children:[i("span",{className:"text-sm font-medium text-gray-700",children:n}),g&&i("span",{className:"text-yellow-600 text-sm font-medium",children:"● unsaved"})]}),u("div",{className:"flex gap-2",children:[i("button",{onClick:d,disabled:!g||w,className:"px-3 py-1.5 text-sm font-medium rounded-lg bg-gradient-to-r from-indigo-600 to-violet-600 text-white hover:from-indigo-700 hover:to-violet-700 transition-colors disabled:opacity-50",children:w?"Saving...":"Save"}),i("button",{onClick:()=>h("validate"),disabled:f,className:"px-3 py-1.5 text-sm font-medium rounded-lg bg-gray-100 text-gray-700 hover:bg-gray-200 transition-colors disabled:opacity-50",children:"Validate"}),i("button",{onClick:()=>h("output"),disabled:f,className:"px-3 py-1.5 text-sm font-medium rounded-lg bg-gray-100 text-gray-700 hover:bg-gray-200 transition-colors disabled:opacity-50",children:"Outputs"})]})]}),i("textarea",{value:l,onChange:N=>a(N.target.value),className:"flex-1 font-mono text-sm p-4 border border-gray-200 rounded-xl resize-none focus:outline-none focus:border-indigo-400 bg-gray-50",spellCheck:!1}),c!==""||f?u("div",{className:"mt-4",children:[u("div",{className:"flex items-center gap-2 mb-2",children:[i("p",{className:"text-sm font-semibold text-gray-500 uppercase tracking-wide",children:"Output"}),f&&i("span",{className:"text-indigo-600 text-xs animate-pulse",children:"Running..."})]}),i("pre",{ref:C,className:"bg-gray-900 text-green-400 text-xs p-4 rounded-xl overflow-auto max-h-64 font-mono leading-relaxed whitespace-pre-wrap",children:c||"Waiting..."})]}):u("div",{className:"flex gap-2 mt-4",children:[i("button",{onClick:()=>h("plan"),disabled:f,className:"px-4 py-2 text-sm font-medium rounded-lg bg-gray-900 text-white hover:bg-gray-800 transition-colors disabled:opacity-50",children:"Plan"}),i("button",{onClick:()=>h("apply"),disabled:f,className:"px-4 py-2 text-sm font-medium rounded-lg bg-gradient-to-r from-indigo-600 to-violet-600 text-white hover:from-indigo-700 hover:to-violet-700 transition-colors disabled:opacity-50",children:"Apply"})]})]}):i("div",{className:"flex-1 flex items-center justify-center text-gray-600",children:i("p",{className:"text-lg",children:"Select a Terraform file to edit"})})]})]})}const Mx=["solo","team","enterprise"],Ix=["auto","on","off"];function Dx(){var h,N,S,L,R,k,A,j,D,O,H,B,fe,$e,Le,M,F,U,K,G,P,z,V;const[e,t]=m.useState(null),[n,r]=m.useState(null),[l,a]=m.useState("default"),[s,o]=m.useState(null),[c,p]=m.useState([]),[f,x]=m.useState(!1),[v,y]=m.useState(null),[w,b]=m.useState(null);if(m.useEffect(()=>{Eg().then(T=>{t(T.config),r(JSON.parse(JSON.stringify(T.config))),a(T.source),o(T.path),p(T.errors||[])}).catch(T=>b(T.message))},[]),w)return u("section",{className:"card max-w-2xl",children:[i("h1",{className:"text-lg font-semibold mb-2",children:"Config unavailable"}),i("p",{className:"text-text-muted text-sm",children:w})]});if(!e)return i("p",{className:"text-text-dim text-sm",children:"Loading config…"});const C=JSON.stringify(e)!==JSON.stringify(n);async function g(){if(e){x(!0),y(null),p([]);try{const T=await Lg(e);y(`Saved to ${T.path}`),r(JSON.parse(JSON.stringify(e)))}catch(T){p([T.message||String(T)])}finally{x(!1)}}}function d(){n&&(t(JSON.parse(JSON.stringify(n))),y(null),p([]))}return u("div",{className:"max-w-4xl space-y-8",children:[i(Ms,{}),u("header",{children:[i("p",{className:"text-text-dim text-xs uppercase tracking-wider mb-1",children:"Page"}),i("h1",{className:"text-2xl sm:text-3xl font-semibold tracking-tight",children:"Configuration"}),u("p",{className:"text-text-muted text-sm mt-2",children:["Edits write to ",i("code",{className:"px-1 py-0.5 bg-bg-muted rounded",children:"construct.config.json"})," at the project root. Secrets stay in ",i("code",{className:"px-1 py-0.5 bg-bg-muted rounded",children:".env"}),"."]}),u("p",{className:"text-text-dim text-xs mt-2",children:["Source: ",i("span",{className:"font-mono",children:l}),s&&u(Ce,{children:[" · ",s]})]})]}),c.length>0&&u("div",{className:"card",style:{borderColor:"var(--status-down)"},children:[i("h3",{className:"font-medium mb-2",children:"Save failed"}),i("ul",{className:"text-sm text-text-muted list-disc list-inside",children:c.map((T,E)=>i("li",{children:T},E))})]}),v&&i("div",{className:"card",style:{borderColor:"var(--status-healthy)"},children:i("p",{className:"text-sm",children:v})}),u("section",{className:"card space-y-4","aria-labelledby":"general-heading",children:[i("h2",{id:"general-heading",className:"text-sm uppercase tracking-wider text-text-dim",children:"General"}),u("p",{className:"text-xs text-text-muted",children:["Alias is edited in the sidebar wordmark — click ",i("strong",{children:e.alias??"Construct"})," in the top-left to rename."]}),i(Te,{label:"Deployment mode",help:"Routes the intake queue, worker pool, and telemetry backend.",children:i("select",{value:((h=e.deployment)==null?void 0:h.mode)??"solo",onChange:T=>t(E=>({...E,deployment:{...E==null?void 0:E.deployment,mode:T.target.value}})),className:"w-full px-3 py-2 border border-border rounded bg-surface",children:Mx.map(T=>i("option",{value:T,children:T},T))})}),i(Te,{label:"MCP broker",help:"auto = team/enterprise on, solo off. on/off override.",children:i("select",{value:((N=e.deployment)==null?void 0:N.mcpBroker)??"auto",onChange:T=>t(E=>({...E,deployment:{...E==null?void 0:E.deployment,mcpBroker:T.target.value}})),className:"w-full px-3 py-2 border border-border rounded bg-surface",children:Ix.map(T=>i("option",{value:T,children:T},T))})}),i(Te,{label:"Auto-start embed daemon",help:"Session-start auto-launches the embed daemon when off.",children:u("label",{className:"inline-flex items-center gap-2",children:[i("input",{type:"checkbox",checked:!!e.autoEmbed,onChange:T=>t(E=>({...E,autoEmbed:T.target.checked}))}),i("span",{className:"text-sm",children:e.autoEmbed?"on":"off"})]})}),i(Te,{label:"Telemetry (Remote ingest)",help:"When off, R&D-loop traces stay in .cx/traces/ only.",children:u("label",{className:"inline-flex items-center gap-2",children:[i("input",{type:"checkbox",checked:((S=e.telemetry)==null?void 0:S.enabled)!==!1,onChange:T=>t(E=>({...E,telemetry:{...E==null?void 0:E.telemetry,enabled:T.target.checked}}))}),i("span",{className:"text-sm",children:((L=e.telemetry)==null?void 0:L.enabled)!==!1?"on":"off"})]})})]}),u("section",{className:"card space-y-4","aria-labelledby":"roles-heading",children:[i("h2",{id:"roles-heading",className:"text-sm uppercase tracking-wider text-text-dim",children:"Team Configuration"}),u("p",{className:"text-xs text-text-muted",children:["Set your default primary and secondary personas. The primary sets the analysis lens; the secondary provides complementary perspective. Override per-conversation with ",i("code",{className:"px-1 py-0.5 bg-bg-muted rounded",children:"@construct --primary=cx-pm --secondary=cx-arch"}),"."]}),i(Te,{label:"Primary persona",help:"Default orientation for all work. Leave null for automatic routing.",children:u("select",{value:((R=e.roleSelection)==null?void 0:R.primary)??"",onChange:T=>t(E=>({...E,roleSelection:{...E==null?void 0:E.roleSelection,primary:T.target.value||null}})),className:"w-full px-3 py-2 border border-border rounded bg-surface",children:[i("option",{value:"",children:"Automatic (context-based)"}),i("option",{value:"cx-product-manager",children:"cx-product-manager"}),i("option",{value:"cx-architect",children:"cx-architect"}),i("option",{value:"cx-engineer",children:"cx-engineer"}),i("option",{value:"cx-debugger",children:"cx-debugger"}),i("option",{value:"cx-qa",children:"cx-qa"}),i("option",{value:"cx-sre",children:"cx-sre"}),i("option",{value:"cx-platform-engineer",children:"cx-platform-engineer"}),i("option",{value:"cx-designer",children:"cx-designer"}),i("option",{value:"cx-ux-researcher",children:"cx-ux-researcher"}),i("option",{value:"cx-accessibility",children:"cx-accessibility"}),i("option",{value:"cx-researcher",children:"cx-researcher"}),i("option",{value:"cx-data-analyst",children:"cx-data-analyst"}),i("option",{value:"cx-ai-engineer",children:"cx-ai-engineer"}),i("option",{value:"cx-evaluator",children:"cx-evaluator"}),i("option",{value:"cx-trace-reviewer",children:"cx-trace-reviewer"}),i("option",{value:"cx-security",children:"cx-security"}),i("option",{value:"cx-legal-compliance",children:"cx-legal-compliance"}),i("option",{value:"cx-reviewer",children:"cx-reviewer"}),i("option",{value:"cx-devil-advocate",children:"cx-devil-advocate"}),i("option",{value:"cx-release-manager",children:"cx-release-manager"}),i("option",{value:"cx-docs-keeper",children:"cx-docs-keeper"}),i("option",{value:"cx-business-strategist",children:"cx-business-strategist"}),i("option",{value:"cx-operations",children:"cx-operations"}),i("option",{value:"cx-orchestrator",children:"cx-orchestrator"}),i("option",{value:"cx-rd-lead",children:"cx-rd-lead"})]})}),i(Te,{label:"Secondary persona",help:"Complementary perspective. Leave null for automatic routing.",children:u("select",{value:((k=e.roleSelection)==null?void 0:k.secondary)??"",onChange:T=>t(E=>({...E,roleSelection:{...E==null?void 0:E.roleSelection,secondary:T.target.value||null}})),className:"w-full px-3 py-2 border border-border rounded bg-surface",children:[i("option",{value:"",children:"Automatic (context-based)"}),i("option",{value:"cx-product-manager",children:"cx-product-manager"}),i("option",{value:"cx-architect",children:"cx-architect"}),i("option",{value:"cx-engineer",children:"cx-engineer"}),i("option",{value:"cx-debugger",children:"cx-debugger"}),i("option",{value:"cx-qa",children:"cx-qa"}),i("option",{value:"cx-sre",children:"cx-sre"}),i("option",{value:"cx-platform-engineer",children:"cx-platform-engineer"}),i("option",{value:"cx-designer",children:"cx-designer"}),i("option",{value:"cx-ux-researcher",children:"cx-ux-researcher"}),i("option",{value:"cx-accessibility",children:"cx-accessibility"}),i("option",{value:"cx-researcher",children:"cx-researcher"}),i("option",{value:"cx-data-analyst",children:"cx-data-analyst"}),i("option",{value:"cx-ai-engineer",children:"cx-ai-engineer"}),i("option",{value:"cx-evaluator",children:"cx-evaluator"}),i("option",{value:"cx-trace-reviewer",children:"cx-trace-reviewer"}),i("option",{value:"cx-security",children:"cx-security"}),i("option",{value:"cx-legal-compliance",children:"cx-legal-compliance"}),i("option",{value:"cx-reviewer",children:"cx-reviewer"}),i("option",{value:"cx-devil-advocate",children:"cx-devil-advocate"}),i("option",{value:"cx-release-manager",children:"cx-release-manager"}),i("option",{value:"cx-docs-keeper",children:"cx-docs-keeper"}),i("option",{value:"cx-business-strategist",children:"cx-business-strategist"}),i("option",{value:"cx-operations",children:"cx-operations"}),i("option",{value:"cx-orchestrator",children:"cx-orchestrator"}),i("option",{value:"cx-rd-lead",children:"cx-rd-lead"})]})}),i(Te,{label:"Per-conversation override",help:"Allow CLI overrides with --primary and --secondary flags.",children:u("label",{className:"inline-flex items-center gap-2",children:[i("input",{type:"checkbox",checked:((A=e.roleSelection)==null?void 0:A.perConversationOverride)!==!1,onChange:T=>t(E=>({...E,roleSelection:{...E==null?void 0:E.roleSelection,perConversationOverride:T.target.checked}}))}),i("span",{className:"text-sm",children:((j=e.roleSelection)==null?void 0:j.perConversationOverride)!==!1?"enabled":"disabled"})]})})]}),u("section",{className:"card space-y-2","aria-labelledby":"models-heading",children:[i("h2",{id:"models-heading",className:"text-sm uppercase tracking-wider text-text-dim",children:"Models"}),u("p",{className:"text-xs text-text-muted",children:["Model tiers are configured on the ",i("a",{href:"#/models",className:"underline hover:no-underline",children:"Models page"}),". That page is the single source of truth — selections persist to ",i("code",{className:"px-1 bg-bg-muted rounded",children:"specialists/registry.json"})," and stay there. Env vars ",i("code",{className:"px-1 bg-bg-muted rounded",children:"CX_MODEL_REASONING|STANDARD|FAST"})," still override at runtime for CI and ops; they are not editable from the dashboard."]})]}),u("section",{className:"card space-y-4","aria-labelledby":"resources-heading",children:[i("h2",{id:"resources-heading",className:"text-sm uppercase tracking-wider text-text-dim",children:"Resource limits"}),i(Te,{label:".cx/ total cap (MB)",help:"Hard cap on the .cx/ tree. Defaults to 2GB.",children:i("input",{type:"number",min:"100",step:"100",value:((O=(D=e.resources)==null?void 0:D.disk)==null?void 0:O.totalCxMaxMb)??2e3,onChange:T=>t(E=>{var Y;return{...E,resources:{...E==null?void 0:E.resources,disk:{...(Y=E==null?void 0:E.resources)==null?void 0:Y.disk,totalCxMaxMb:Number(T.target.value)}}}}),className:"w-full px-3 py-2 border border-border rounded bg-surface"})}),i(Te,{label:"Trace retention (days)",help:"JSONL traces in .cx/traces/ rotate past this age.",children:i("input",{type:"number",min:"1",value:((B=(H=e.resources)==null?void 0:H.disk)==null?void 0:B.tracesMaxDays)??30,onChange:T=>t(E=>{var Y;return{...E,resources:{...E==null?void 0:E.resources,disk:{...(Y=E==null?void 0:E.resources)==null?void 0:Y.disk,tracesMaxDays:Number(T.target.value)}}}}),className:"w-full px-3 py-2 border border-border rounded bg-surface"})}),i(Te,{label:"Backup retention (days)",help:"Persona/skill/rules edit backups in .cx/backups/.",children:i("input",{type:"number",min:"1",value:(($e=(fe=e.resources)==null?void 0:fe.disk)==null?void 0:$e.backupsMaxDays)??60,onChange:T=>t(E=>{var Y;return{...E,resources:{...E==null?void 0:E.resources,disk:{...(Y=E==null?void 0:E.resources)==null?void 0:Y.disk,backupsMaxDays:Number(T.target.value)}}}}),className:"w-full px-3 py-2 border border-border rounded bg-surface"})})]}),u("section",{className:"card space-y-4","aria-labelledby":"costs-heading",children:[i("h2",{id:"costs-heading",className:"text-sm uppercase tracking-wider text-text-dim",children:"Cost ceilings"}),i(Te,{label:"Billing mode",help:"metered = pay-per-token API (numbers = real bill). subscription = Claude Pro / Max / Team / Enterprise flat-rate (numbers below become metered-equivalent only). mixed = some of both.",children:u("select",{value:((Le=e.costs)==null?void 0:Le.billingMode)??"metered",onChange:T=>t(E=>({...E,costs:{...E==null?void 0:E.costs,billingMode:T.target.value}})),className:"w-full px-3 py-2 border border-border rounded bg-surface",children:[i("option",{value:"metered",children:"metered (API key, pay-per-token)"}),i("option",{value:"subscription",children:"subscription (Claude Pro / Max / Team)"}),i("option",{value:"mixed",children:"mixed (both)"})]})}),i(Te,{label:"Daily total cap (USD)",help:"Hard-stop when enforce is on. Has no meaning under pure subscription billing — the cap applies only to metered API calls.",children:i("input",{type:"number",min:"0",step:"0.5",value:((U=(F=(M=e.costs)==null?void 0:M.budgets)==null?void 0:F.total)==null?void 0:U.dailyUsd)??50,onChange:T=>t(E=>{var Y;return{...E,costs:{...E==null?void 0:E.costs,budgets:{...(Y=E==null?void 0:E.costs)==null?void 0:Y.budgets,total:{dailyUsd:Number(T.target.value)}}}}}),className:"w-full px-3 py-2 border border-border rounded bg-surface"})}),i(Te,{label:"Per-persona default cap (USD)",help:"Applies to any persona without a specific entry.",children:i("input",{type:"number",min:"0",step:"0.5",value:((P=(G=(K=e.costs)==null?void 0:K.budgets)==null?void 0:G.default)==null?void 0:P.dailyUsd)??10,onChange:T=>t(E=>{var Y;return{...E,costs:{...E==null?void 0:E.costs,budgets:{...(Y=E==null?void 0:E.costs)==null?void 0:Y.budgets,default:{dailyUsd:Number(T.target.value)}}}}}),className:"w-full px-3 py-2 border border-border rounded bg-surface"})}),i(Te,{label:"Enforce",help:"When on, calls exceeding the cap return PolicyDenied. When off, advisory only.",children:u("label",{className:"inline-flex items-center gap-2",children:[i("input",{type:"checkbox",checked:!!((z=e.costs)!=null&&z.enforce),onChange:T=>t(E=>({...E,costs:{...E==null?void 0:E.costs,enforce:T.target.checked}}))}),i("span",{className:"text-sm",children:(V=e.costs)!=null&&V.enforce?"on":"off"})]})})]}),C&&u("section",{className:"card","aria-labelledby":"diff-heading",children:[i("h3",{id:"diff-heading",className:"text-sm uppercase tracking-wider text-text-dim mb-2",children:"Pending changes"}),i("pre",{className:"text-xs bg-bg-muted p-3 rounded overflow-auto max-h-64 font-mono",children:$x(n,e)})]}),u("div",{className:"flex items-center gap-3",children:[i("button",{type:"button",disabled:!C||f,onClick:g,className:"btn btn-primary disabled:opacity-50 disabled:cursor-not-allowed",children:f?"Saving…":"Save changes"}),i("button",{type:"button",disabled:!C||f,onClick:d,className:"btn disabled:opacity-50 disabled:cursor-not-allowed",children:"Discard"}),!C&&i("span",{className:"text-xs text-text-dim",children:"No changes pending."})]})]})}function Te({label:e,help:t,children:n}){return u("div",{className:"space-y-1",children:[i("label",{className:"block text-sm font-medium",children:e}),t&&i("p",{className:"text-xs text-text-dim",children:t}),n]})}function $x(e,t){const n=[],r=JSON.stringify(e??{},null,2).split(`
|
|
68
68
|
`),l=JSON.stringify(t??{},null,2).split(`
|
|
69
69
|
`),a=Math.max(r.length,l.length);for(let s=0;s<a;s++){if(r[s]===l[s]){n.push(` ${l[s]??""}`);continue}r[s]!==void 0&&n.push(`- ${r[s]}`),l[s]!==void 0&&n.push(`+ ${l[s]}`)}return n.join(`
|
|
70
70
|
`)}const jx="/api",au=3e4;function Aa(e){return e?new Date(e).toISOString().replace("T"," ").slice(0,19):"—"}function el(e){if(!e)return"";const t=Math.floor((Date.now()-e)/1e3);return t<60?`${t}s ago`:t<3600?`${Math.floor(t/60)}m ago`:t<86400?`${Math.floor(t/3600)}h ago`:`${Math.floor(t/86400)}d ago`}function zx(){var s;const[e,t]=m.useState(null),[n,r]=m.useState(null);if(m.useEffect(()=>{let o=!1;const c=async()=>{try{const f=await fetch(`${jx}/doctor?limit=100`);if(!f.ok)throw new Error(`HTTP ${f.status}`);const x=await f.json();o||(t(x),r(null))}catch(f){o||r(String(f))}};c();const p=setInterval(c,au);return()=>{o=!0,clearInterval(p)}},[]),n&&!e)return u("div",{className:"p-6",children:[i("h1",{className:"text-2xl font-semibold mb-2",children:"Doctor"}),u("p",{className:"text-red-600",children:["Failed to load /api/doctor: ",n]})]});if(!e)return u("div",{className:"p-6",children:[i("h1",{className:"text-2xl font-semibold mb-2",children:"Doctor"}),i("p",{className:"text-gray-600",children:"Loading…"})]});const l=e.cost.total.cap>0?e.cost.total.spent/e.cost.total.cap*100:0,a=Object.entries(e.cost.byPersona).sort((o,c)=>c[1].spent-o[1].spent);return u("div",{className:"p-6 space-y-6",children:[u("div",{className:"flex items-center justify-between",children:[i("h1",{className:"text-2xl font-semibold",children:"Doctor"}),u("span",{className:"text-xs text-gray-500",children:["Auto-refreshes every ",au/1e3,"s"]})]}),u("section",{className:"rounded-lg border border-gray-200 p-4 bg-white",children:[i("h2",{className:"text-sm font-semibold text-gray-700 mb-3",children:"L0 daemon"}),e.daemon?u("div",{className:"space-y-1 text-sm",children:[u("div",{children:[i("span",{className:"text-gray-500",children:"Status:"})," ",i("span",{className:"text-green-600 font-medium",children:"running"})]}),u("div",{children:[i("span",{className:"text-gray-500",children:"PID:"})," ",e.daemon.pid]}),u("div",{children:[i("span",{className:"text-gray-500",children:"Started:"})," ",Aa(e.daemon.startedAt)," (",el(e.daemon.startedAt),")"]}),u("div",{children:[i("span",{className:"text-gray-500",children:"Last state write:"})," ",Aa(e.daemon.updatedAt)," (",el(e.daemon.updatedAt),")"]}),u("div",{children:[i("span",{className:"text-gray-500",children:"Watchers:"})," ",((s=e.daemon.watchers)==null?void 0:s.join(", "))||"—"]})]}):u("p",{className:"text-sm text-gray-600",children:["Doctor not running. Start with ",i("code",{className:"px-1 py-0.5 bg-gray-100 rounded",children:"construct up"}),"."]})]}),u("section",{className:"rounded-lg border border-gray-200 p-4 bg-white",children:[u("h2",{className:"text-sm font-semibold text-gray-700 mb-3",children:["Cost — ",e.cost.dayKey]}),u("div",{className:"mb-3",children:[u("div",{className:"flex justify-between text-sm mb-1",children:[u("span",{children:["Total: $",e.cost.total.spent.toFixed(4)," / $",e.cost.total.cap.toFixed(2)]}),u("span",{className:"text-gray-500",children:[e.cost.total.invocations," invocations"]})]}),i("div",{className:"h-2 bg-gray-100 rounded overflow-hidden",children:i("div",{className:`h-full ${l>=80?"bg-red-500":l>=50?"bg-yellow-500":"bg-emerald-500"}`,style:{width:`${Math.min(100,l)}%`}})})]}),a.length>0?u("table",{className:"w-full text-sm",children:[i("thead",{children:u("tr",{className:"text-left text-gray-500 border-b border-gray-100",children:[i("th",{className:"py-1 pr-4",children:"Persona"}),i("th",{className:"py-1 pr-4",children:"Spent"}),i("th",{className:"py-1 pr-4",children:"Cap"}),i("th",{className:"py-1",children:"Invocations"})]})}),i("tbody",{children:a.map(([o,c])=>u("tr",{className:"border-b border-gray-50",children:[u("td",{className:"py-1 pr-4 font-mono",children:["cx-",o]}),u("td",{className:"py-1 pr-4",children:["$",c.spent.toFixed(4)]}),u("td",{className:"py-1 pr-4 text-gray-500",children:["$",c.cap.toFixed(2)]}),i("td",{className:"py-1",children:c.invocations})]},o))})]}):i("p",{className:"text-sm text-gray-500",children:"No per-persona spend recorded today."})]}),u("section",{className:"rounded-lg border border-gray-200 p-4 bg-white",children:[u("h2",{className:"text-sm font-semibold text-gray-700 mb-3",children:["Approval requests (",e.approvals.length,")"]}),e.approvals.length===0?i("p",{className:"text-sm text-gray-500",children:"No pending approval requests."}):i("ul",{className:"space-y-2 text-sm",children:e.approvals.map(o=>u("li",{className:"flex items-start gap-3",children:[i("span",{className:"text-xs text-gray-600 font-mono whitespace-nowrap mt-0.5",children:el(o.ts)}),i("span",{className:"text-xs px-1.5 py-0.5 bg-amber-50 text-amber-800 rounded font-medium",children:o.cxId}),i("span",{className:"text-xs text-gray-500",children:o.action}),i("span",{className:"font-mono text-xs break-all flex-1",children:o.target})]},`${o.ts}-${o.target}`))})]}),u("section",{className:"rounded-lg border border-gray-200 p-4 bg-white",children:[u("h2",{className:"text-sm font-semibold text-gray-700 mb-3",children:["Pending role invocations (",e.pendingRoleInvocations.length,")"]}),e.pendingRoleInvocations.length===0?i("p",{className:"text-sm text-gray-500",children:"No pending invocations queued."}):i("ul",{className:"space-y-2 text-sm",children:e.pendingRoleInvocations.map(o=>u("li",{className:"flex items-start gap-3",children:[i("span",{className:"text-xs text-gray-600 font-mono whitespace-nowrap mt-0.5",children:el(o.ts)}),i("span",{className:"text-xs px-1.5 py-0.5 bg-violet-50 text-violet-800 rounded font-medium",children:o.cxId}),i("span",{className:"text-xs text-gray-500 whitespace-nowrap",children:o.bdIssueId||"—"}),i("span",{className:"text-xs text-gray-500 whitespace-nowrap",children:o.eventType}),i("span",{className:"flex-1 text-gray-700",children:o.summary||""})]},`${o.ts}-${o.bdIssueId}`))})]}),u("section",{className:"rounded-lg border border-gray-200 p-4 bg-white",children:[u("h2",{className:"text-sm font-semibold text-gray-700 mb-3",children:["Recent audit (",e.audit.length,")"]}),e.audit.length===0?i("p",{className:"text-sm text-gray-500",children:"No audit entries yet."}):i("div",{className:"max-h-96 overflow-y-auto",children:u("table",{className:"w-full text-xs font-mono",children:[i("thead",{children:u("tr",{className:"text-left text-gray-500 border-b border-gray-100 sticky top-0 bg-white",children:[i("th",{className:"py-1 pr-3",children:"Time"}),i("th",{className:"py-1 pr-3",children:"Watcher"}),i("th",{className:"py-1 pr-3",children:"Kind"}),i("th",{className:"py-1 pr-3",children:"Action"}),i("th",{className:"py-1",children:"Summary"})]})}),i("tbody",{children:e.audit.map((o,c)=>u("tr",{className:"border-b border-gray-50",children:[i("td",{className:"py-1 pr-3 text-gray-500 whitespace-nowrap",children:Aa(o.ts)}),i("td",{className:"py-1 pr-3",children:o.watcher}),i("td",{className:"py-1 pr-3 text-gray-500",children:o.kind}),i("td",{className:"py-1 pr-3 text-gray-700",children:o.action||""}),i("td",{className:"py-1 text-gray-700",children:o.summary||""})]},`${o.ts}-${c}`))})]})})]}),u("p",{className:"text-xs text-gray-600",children:["Onboarded personas (",e.onboardedPersonas.length,"/28): ",e.onboardedPersonas.map(o=>`cx-${o}`).join(", ")]})]})}function Fx(){const[e,t]=m.useState("init"),[n,r]=m.useState(null),[l,a]=m.useState("Construct"),[s,o]=m.useState(()=>{const d=typeof window<"u"?localStorage.getItem("cx-theme"):null;return d==="light"||d==="dark"||d==="auto"?d:"auto"}),[c,p]=m.useState(!0),[f,x]=m.useState(!1);if(m.useEffect(()=>{if(!(typeof document>"u")){s==="auto"?document.documentElement.removeAttribute("data-theme"):document.documentElement.setAttribute("data-theme",s);try{localStorage.setItem("cx-theme",s)}catch{}}},[s]),m.useEffect(()=>{Promise.all([Sg().then(d=>{t(d.mode),r(d.instanceId||null)}).catch(()=>{t("init"),r(null)}),Cg().then(d=>{d!=null&&d.value&&a(d.value)}).catch(()=>{})]).finally(()=>p(!1))},[]),c)return i("div",{className:"flex min-h-screen items-center justify-center bg-bg text-text",children:i("div",{className:"text-aurora text-sm tracking-wide",children:"Loading…"})});const v=[{heading:"Overview",items:[{path:"/",label:"Mission Control",element:i(Xg,{})},{path:"/beads",label:"Beads",element:i(Ex,{})},{path:"/workflow",label:"Workflow",element:i(qg,{})},{path:"/approvals",label:"Approvals",element:i(ex,{})}]},{heading:"Authoring",items:[{path:"/personas",label:"Personas",element:i(lx,{})},{path:"/agents-edit",label:"Agent prompts",element:i(ax,{})},{path:"/skills",label:"Skills",element:i(ix,{})},{path:"/rules",label:"Rules",element:i(sx,{})}]},{heading:"Operations",items:[{path:"/doctor",label:"Doctor",element:i(zx,{})},{path:"/performance",label:"Performance",element:i(ux,{})},{path:"/snapshots",label:"Snapshots",element:i(tx,{})},{path:"/intake",label:"Intake",element:i(Rx,{})}]},{heading:"Models & integrations",items:[{path:"/providers",label:"Providers",element:i(Nx,{})},{path:"/models",label:"Models",element:i(wx,{})},{path:"/mcp",label:"MCP servers",element:i(mx,{})}]},{heading:"System",items:[{path:"/config",label:"Configuration",element:i(Dx,{})},{path:"/audit",label:"Audit log",element:i(ox,{})}]}],y=v.flatMap(d=>d.items),w=e==="embed"||e==="live"?[{path:"/agents",label:"Agents",element:i(nx,{})},{path:"/skills-browse",label:"Skills (browse)",element:i(rx,{})},{path:"/commands",label:"Commands",element:i(px,{})},{path:"/hooks",label:"Hooks",element:i(fx,{})},{path:"/plugins",label:"Plugins",element:i(hx,{})},{path:"/artifacts",label:"Artifacts",element:i(_x,{})},{path:"/knowledge",label:"Knowledge",element:i(Lx,{})},{path:"/infrastructure",label:"Infrastructure",element:i(Ox,{})}]:[],b=[...y,...w],C=()=>x(!1),g=u(Ce,{children:[i(Ax,{alias:l,setAlias:a,mode:e}),n&&i("div",{className:"px-5 py-2 text-xs text-text-dim border-b border-border truncate",children:n}),i("nav",{className:"flex-1 mt-3 px-3 space-y-3 overflow-y-auto","aria-label":"Primary navigation",children:v.map(d=>u("div",{children:[i("p",{className:"px-3 mt-2 mb-1 text-[10px] uppercase tracking-wider text-text-dim font-medium",children:d.heading}),i("div",{className:"space-y-0.5",children:d.items.map(({path:h,label:N})=>i(hg,{to:h,end:h==="/",onClick:C,className:({isActive:S})=>["block px-3 py-1.5 rounded-md text-sm transition-colors",S?"bg-bg-muted text-text border-l-2 border-aurora-cyan font-medium":"text-text-muted hover:text-text hover:bg-bg-muted"].join(" "),children:N},h))})]},d.heading))}),i("div",{className:"hairline-aurora","aria-hidden":"true"}),u("div",{className:"px-5 py-3 text-xs text-text-dim space-y-2",children:[u("div",{className:"flex items-center justify-between gap-2",children:[i("span",{children:"Theme"}),u("select",{value:s,onChange:d=>o(d.target.value),"aria-label":"Theme",className:"bg-bg-muted border border-border rounded px-2 py-1 text-xs",children:[i("option",{value:"auto",children:"auto"}),i("option",{value:"light",children:"light"}),i("option",{value:"dark",children:"dark"})]})]}),u("div",{className:"hidden lg:block",children:[i("span",{className:"text-text-dim",children:"Press "}),i("kbd",{className:"px-1.5 py-0.5 bg-bg-muted rounded font-mono text-[10px]",children:"⌘K"}),i("span",{className:"text-text-dim",children:" to jump"})]}),i("a",{href:"https://construct.dev/docs",target:"_blank",rel:"noreferrer",className:"block hover:text-text",children:"Documentation ↗"})]})]});return u(dg,{children:[i("a",{href:"#main",className:"sr-only focus:not-sr-only focus:fixed focus:top-2 focus:left-2 focus:px-3 focus:py-2 focus:bg-surface focus:border focus:border-border focus:rounded-md focus:z-50",children:"Skip to main content"}),u("div",{className:"flex flex-col lg:flex-row min-h-screen bg-bg text-text",children:[u("header",{className:"lg:hidden sticky top-0 z-30 flex items-center justify-between px-4 py-3 border-b border-border bg-surface",children:[i("button",{type:"button",onClick:()=>x(!0),"aria-label":"Open navigation",className:"px-2 py-1 rounded border border-border text-sm",children:"☰"}),i("span",{className:"text-aurora text-lg truncate ml-3",children:l}),e!=="init"&&i("span",{className:"ml-auto pip pip-healthy","aria-label":`mode: ${e}`,children:e})]}),i("aside",{"aria-label":"Primary",className:["border-r border-border flex flex-col bg-surface","lg:w-64 lg:relative lg:translate-x-0","fixed inset-y-0 left-0 z-40 w-72 transition-transform duration-150 ease-out",f?"translate-x-0":"-translate-x-full lg:translate-x-0"].join(" "),children:g}),f&&i("button",{type:"button","aria-label":"Close navigation",onClick:C,className:"lg:hidden fixed inset-0 z-30 bg-black/40"}),i("main",{id:"main",className:"flex-1 overflow-y-auto p-4 sm:p-6 lg:p-8",children:i(rg,{children:b.map(({path:d,element:h})=>i(Tp,{path:d,element:h},d))})})]}),i(dx,{items:b.map(d=>({path:d.path,label:d.label}))})]})}function Ax({alias:e,setAlias:t,mode:n}){const[r,l]=m.useState(!1),[a,s]=m.useState(e),[o,c]=m.useState(!1),[p,f]=m.useState(null);m.useEffect(()=>{s(e)},[e]);async function x(){if(!a.trim()){f("alias cannot be empty");return}c(!0),f(null);try{const y={...(await fetch("/api/project-config").then(C=>C.json())).config||{},alias:a.trim()},w=await fetch("/api/project-config",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(y)}),b=await w.json();if(!w.ok)throw new Error(b.error||"save failed");t(a.trim()),l(!1)}catch(v){f(v.message)}finally{c(!1)}}return r?u("div",{className:"px-3 py-3 border-b border-border space-y-2",children:[i("label",{className:"block text-[10px] uppercase tracking-wider text-text-dim",children:"Alias"}),i("input",{value:a,onChange:v=>s(v.target.value),autoFocus:!0,onKeyDown:v=>{v.key==="Enter"&&x(),v.key==="Escape"&&l(!1)},className:"w-full px-2 py-1.5 bg-bg border border-border rounded text-sm"}),p&&i("p",{className:"text-xs",style:{color:"var(--status-down)"},children:p}),u("div",{className:"flex gap-2",children:[i("button",{type:"button",onClick:x,disabled:o||a===e,className:"btn btn-primary text-xs flex-1 disabled:opacity-50",children:o?"Saving…":"Save"}),i("button",{type:"button",onClick:()=>{l(!1),s(e)},className:"btn text-xs",children:"Cancel"})]})]}):u("div",{className:"flex h-16 items-center px-5 border-b border-border",children:[i("button",{type:"button",onClick:()=>l(!0),className:"text-xl text-aurora truncate text-left","aria-label":`Edit alias (current: ${e})`,title:"Click to rename",children:e}),n!=="init"&&i("span",{className:"ml-3 pip pip-healthy","aria-label":`mode: ${n}`,children:n})]})}Ua.createRoot(document.getElementById("root")).render(i(gu.StrictMode,{children:i(Fx,{})}));
|