import{c as K,aa as ce,ab as re,u as se,b as ae,r as h,j as e,a3 as ue,e as S,L as v,C as ne,U as le,ac as he,V as F,X as T,T as V,D as I,M as R,g as z,ad as xe,ae as me,q as ie}from"./index-BlXLlXRH.js";import{L as ge}from"./lightbulb-BryzQBuC.js";import{C as O}from"./code-xml-BqvtzCbM.js";import{S as te}from"./send-DEYq34ms.js";import{L as pe}from"./layers-Dpkgl66T.js";import{R as be}from"./rotate-ccw-sJC9w4gD.js";/** * @license lucide-react v0.460.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. */const fe=K("ArrowDown",[["path",{d:"M12 5v14",key:"s699le"}],["path",{d:"m19 12-7 7-7-7",key:"1idqje"}]]);/** * @license lucide-react v0.460.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. */const je=K("ArrowUp",[["path",{d:"m5 12 7-7 7 7",key:"hav0vg"}],["path",{d:"M12 19V5",key:"x0mq9r"}]]);/** * @license lucide-react v0.460.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. */const Ne=K("ClipboardCheck",[["rect",{width:"8",height:"4",x:"8",y:"2",rx:"1",ry:"1",key:"tgr4d6"}],["path",{d:"M16 4h2a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2V6a2 2 0 0 1 2-2h2",key:"116196"}],["path",{d:"m9 14 2 2 4-4",key:"df797q"}]]);/** * @license lucide-react v0.460.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. */const ke=K("FileDiff",[["path",{d:"M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z",key:"1rqfz7"}],["path",{d:"M9 10h6",key:"9gxzsh"}],["path",{d:"M12 13V7",key:"h0r20n"}],["path",{d:"M9 17h6",key:"r8uit2"}]]);/** * @license lucide-react v0.460.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. */const we=K("GitBranch",[["line",{x1:"6",x2:"6",y1:"3",y2:"15",key:"17qcm7"}],["circle",{cx:"18",cy:"6",r:"3",key:"1h7g24"}],["circle",{cx:"6",cy:"18",r:"3",key:"fqmcym"}],["path",{d:"M18 9a9 9 0 0 1-9 9",key:"n2h4wq"}]]);/** * @license lucide-react v0.460.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. */const de=K("Hammer",[["path",{d:"m15 12-8.373 8.373a1 1 0 1 1-3-3L12 9",key:"eefl8a"}],["path",{d:"m18 15 4-4",key:"16gjal"}],["path",{d:"m21.5 11.5-1.914-1.914A2 2 0 0 1 19 8.172V7l-2.26-2.26a6 6 0 0 0-4.202-1.756L9 2.96l.92.82A6.18 6.18 0 0 1 12 8.4V10l2 2h1.172a2 2 0 0 1 1.414.586L18.5 14.5",key:"b7pghm"}]]);/** * @license lucide-react v0.460.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. */const ye=K("Square",[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}]]),ve={wartung:"Werkstatt",orchestrator:"Orchestrator",doku:"Doku",feature:"Feature"},De={laeuft:{label:"wird eingespielt …",cls:"text-sky-300 border-sky-500/40 bg-sky-500/10",spin:!0},rollback:{label:"Rollback läuft …",cls:"text-amber-300 border-amber-500/40 bg-amber-500/10",spin:!0},eingespielt:{label:"eingespielt ✓",cls:"text-emerald-300 border-emerald-500/40 bg-emerald-500/10"},fehlgeschlagen:{label:"fehlgeschlagen",cls:"text-red-300 border-red-500/40 bg-red-500/10"},zurueckgerollt:{label:"zurückgerollt",cls:"text-amber-300 border-amber-500/40 bg-amber-500/10"},kritisch:{label:"KRITISCH — Box prüfen",cls:"text-red-200 border-red-500/60 bg-red-500/20"},abgelehnt:{label:"abgelehnt",cls:"text-muted-foreground border-border/60 bg-background/30"}};function q(t){return t?new Date(t*1e3).toLocaleString("de-DE",{day:"2-digit",month:"2-digit",hour:"2-digit",minute:"2-digit"}):"—"}function Me(){const{data:t,isLoading:a,refetch:c,isFetching:p}=ce(),{data:u}=re(),D=se(),{showAlert:f,showConfirm:j,dialogElement:o}=ae(),[N,A]=h.useState({}),s=()=>D.invalidateQueries({queryKey:ie.auftragsbuch});async function l(m,k,E,L){A(g=>({...g,[m]:!0}));try{await z(k,{method:"POST",body:JSON.stringify(E)}),L&&f("Erledigt",L),s()}catch(g){f("Das hat nicht geklappt",String((g==null?void 0:g.message)||g))}finally{A(g=>({...g,[m]:!1}))}}const b=(t==null?void 0:t.items)??[],x=(t==null?void 0:t.skill_kandidaten)??[],B=u!=null&&u.available?u.items.filter(m=>m.status==="blocked").length:0,C=b.length===0&&x.length===0&&B===0;return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"bg-gradient-to-r from-foreground via-foreground to-primary bg-clip-text font-space text-2xl font-bold tracking-tight text-transparent",children:"Auftragsbuch"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Was die Box gebaut oder sich ausgedacht hat — du entscheidest. Annehmen spielt es mit Fangnetz ein (Health-Check, automatischer Rollback)."})]}),e.jsxs("button",{onClick:()=>c(),className:"flex h-9 items-center gap-1.5 rounded-lg border border-border/60 bg-card/45 px-3 text-xs font-semibold text-muted-foreground hover:text-foreground hover:border-primary/40 transition-all cursor-pointer",children:[e.jsx(ue,{className:S("h-3.5 w-3.5",p&&"animate-spin")})," Aktualisieren"]})]}),t&&!t.available&&e.jsx("div",{className:"rounded-2xl border border-amber-500/30 bg-amber-500/5 p-4 text-xs text-amber-300",children:"Das Auftragsbuch lebt auf der Box (liest die Gitea-Branches dort). Im lokalen Dev-Modus ist hier nichts zu sehen."}),a&&e.jsxs("div",{className:"flex items-center gap-2 rounded-2xl border border-border/60 bg-card/30 p-6 text-xs text-muted-foreground",children:[e.jsx(v,{className:"h-4 w-4 animate-spin"})," Vorschläge werden geladen …"]}),(t==null?void 0:t.available)&&C&&e.jsxs("div",{className:"flex items-center gap-3 rounded-2xl border border-emerald-500/25 bg-emerald-500/5 p-5",children:[e.jsx(ne,{className:"h-5 w-5 shrink-0 text-emerald-400"}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-semibold text-foreground",children:"Nichts zu entscheiden"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Keine offenen Vorschläge. Werkstatt, Orchestrator und Traum melden sich hier, sobald es etwas gibt."})]})]}),e.jsx(Se,{}),b.length>0&&e.jsxs("section",{className:"space-y-3",children:[e.jsxs(G,{icon:we,children:["Patch-Vorschläge (",b.length,")"]}),b.map(m=>e.jsx(ze,{item:m,busy:N,onAct:l,showConfirm:j},`${m.repo??"mc2"}:${m.branch}`))]}),x.length>0&&e.jsxs("section",{className:"space-y-3",children:[e.jsxs(G,{icon:le,children:["Skill-Kandidaten aus dem Traum (",x.length,")"]}),x.map(m=>e.jsx(Ke,{k:m,busy:N,onAct:l,showConfirm:j},m.file))]}),o]})}function G({icon:t,children:a}){return e.jsxs("p",{className:"flex items-center gap-1.5 text-[11px] font-semibold uppercase tracking-wider text-muted-foreground/60",children:[e.jsx(t,{className:"h-3.5 w-3.5"})," ",a]})}const Ae={triage:{label:"wird ausgearbeitet …",cls:"text-violet-300 border-violet-500/40 bg-violet-500/10",spin:!0},todo:{label:"wartet",cls:"text-muted-foreground border-border/60 bg-background/30"},scheduled:{label:"geplant",cls:"text-muted-foreground border-border/60 bg-background/30"},ready:{label:"gleich dran",cls:"text-sky-300/80 border-sky-500/30 bg-sky-500/5"},running:{label:"in Arbeit …",cls:"text-sky-300 border-sky-500/40 bg-sky-500/10",spin:!0},review:{label:"im Review",cls:"text-amber-300 border-amber-500/40 bg-amber-500/10"},blocked:{label:"hängt — braucht dich",cls:"text-red-300 border-red-500/40 bg-red-500/10"},done:{label:"fertig ✓",cls:"text-emerald-300 border-emerald-500/40 bg-emerald-500/10"}},Ce={needs_input:"Die Box hat eine Frage:",capability:"Die Box kam hier nicht weiter:",transient:"Die Aufgabe hakt:"};function Se(){var Z,U;const{data:t,isLoading:a}=re(),c=se(),{showAlert:p,showConfirm:u,dialogElement:D}=ae(),[f,j]=h.useState(""),[o,N]=h.useState("box"),[A,s]=h.useState(!1),[l,b]=h.useState({}),[x,B]=h.useState(null),[C,m]=h.useState({}),k=(t==null?void 0:t.items)??[],E=()=>c.invalidateQueries({queryKey:ie.ideen}),L=x!==null&&(((Z=t==null?void 0:t.items.find(r=>r.id===x))==null?void 0:Z.status)==="triage"||((U=t==null?void 0:t.items.find(r=>r.id===x))==null?void 0:U.status)==="running"),g=he(x??"",L);async function W(){const r=f.trim();if(!(r.length<3||A)){s(!0);try{const n=r.length>160?r.slice(0,157)+"…":r;await z("/api/ideen",{method:"POST",body:JSON.stringify({titel:n,notiz:r.length>160?r:"",welt:o})}),j(""),E()}catch(n){p("Das hat nicht geklappt",String((n==null?void 0:n.message)||n))}finally{s(!1)}}}async function d(r){b(n=>({...n,[r]:!0}));try{await z("/api/ideen/archivieren",{method:"POST",body:JSON.stringify({id:r})}),E()}catch(n){p("Das hat nicht geklappt",String((n==null?void 0:n.message)||n))}finally{b(n=>({...n,[r]:!1}))}}async function w(r,n,i,P){b(y=>({...y,[r+n]:!0}));try{await z(i,{method:"POST",body:JSON.stringify(P)}),E()}catch(y){p("Das hat nicht geklappt",String((y==null?void 0:y.message)||y))}finally{b(y=>({...y,[r+n]:!1}))}}async function H(r){const n=(C[r]||"").trim();if(!(n.length<1||l["ans:"+r])){b(i=>({...i,["ans:"+r]:!0}));try{await z("/api/ideen/antwort",{method:"POST",body:JSON.stringify({id:r,antwort:n})}),m(i=>({...i,[r]:""})),E()}catch(i){p("Das hat nicht geklappt",String((i==null?void 0:i.message)||i))}finally{b(i=>({...i,["ans:"+r]:!1}))}}}const Q=r=>{var Y,ee;const n=Ae[r.status]??{label:r.status,cls:"text-muted-foreground border-border/60 bg-background/30"},i=x===r.id,P=r.status==="triage"||r.status==="running"||r.status==="done",y=r.status==="blocked",J=!!l["ans:"+r.id],M=r.status==="running"&&(r.puls_alter??0)>600,X=r.status==="todo"||r.status==="ready"||r.status==="scheduled";return e.jsxs("li",{className:S("flex flex-col gap-2 rounded-xl border bg-background/30 px-3 py-2",y?"border-red-500/30":M?"border-amber-500/40":"border-border/40"),children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("span",{className:S("flex shrink-0 items-center gap-1.5 rounded-lg border px-2 py-0.5 text-[10px] font-bold",n.cls),children:[n.spin&&e.jsx(v,{className:"h-3 w-3 animate-spin"}),n.label]}),M&&e.jsxs("span",{className:"flex shrink-0 items-center gap-1 rounded-lg border border-amber-500/40 bg-amber-500/10 px-2 py-0.5 text-[10px] font-bold text-amber-300",title:"Der Worker lebt, gibt aber kein Lebenszeichen mehr — vermutlich wartet er auf etwas, das nie kommt. „Neuer Versuch“ startet die Karte frisch.",children:[e.jsx(V,{className:"h-3 w-3"})," ",Math.round((r.puls_alter??0)/60)," min ohne Regung"]}),(r.prio??0)!==0&&e.jsxs("span",{className:"shrink-0 rounded bg-background/50 px-1.5 py-0.5 font-mono text-[10px] text-muted-foreground",title:"Priorität — höher kommt zuerst dran (bei gleicher Prio: Erstellzeit)",children:["P",r.prio]}),r.welt==="ide"&&e.jsxs("span",{className:"flex shrink-0 items-center gap-1 rounded-lg border border-violet-500/40 bg-violet-500/10 px-2 py-0.5 text-[10px] font-bold text-violet-300",title:"IDE-Welt: die Box bereitet nur vor (Konzept + Repo + Doku, kein Code). Gebaut wird von dir in Zed.",children:[e.jsx(O,{className:"h-3 w-3"})," IDE"]}),e.jsx("span",{className:"min-w-0 flex-1 truncate text-xs text-foreground",title:r.body||r.titel,children:r.titel}),e.jsxs("span",{className:"flex shrink-0 items-center gap-1 text-[10px] text-muted-foreground/70",children:[e.jsx(F,{className:"h-3 w-3"}),q(r.erstellt)]}),X&&e.jsxs("span",{className:"flex shrink-0 items-center",children:[e.jsx("button",{disabled:!!l["pr:"+r.id],onClick:()=>w("pr:",r.id,"/api/ideen/prio",{id:r.id,richtung:"hoch"}),title:"Vorziehen (Prio +1)",className:"rounded-md p-1 text-muted-foreground/60 transition-colors hover:text-foreground cursor-pointer disabled:opacity-50",children:e.jsx(je,{className:"h-3.5 w-3.5"})}),e.jsx("button",{disabled:!!l["pr:"+r.id],onClick:()=>w("pr:",r.id,"/api/ideen/prio",{id:r.id,richtung:"runter"}),title:"Zurückstellen (Prio −1)",className:"rounded-md p-1 text-muted-foreground/60 transition-colors hover:text-foreground cursor-pointer disabled:opacity-50",children:e.jsx(fe,{className:"h-3.5 w-3.5"})})]}),(r.status==="running"||y)&&e.jsx("button",{disabled:!!l["rt:"+r.id],onClick:()=>u("Neuer Versuch?",r.status==="running"?`Der laufende Worker von '${r.titel.slice(0,60)}' wird beendet (samt gestarteter Test-Prozesse) und die Karte frisch gestartet. Bisheriger Zwischenstand im Workspace bleibt liegen.`:`Die Karte '${r.titel.slice(0,60)}' wird entsperrt und läuft weiter, sobald ein Platz frei ist.`,()=>w("rt:",r.id,"/api/ideen/retry",{id:r.id})),title:"Neuer Versuch — Karte frisch starten",className:S("shrink-0 rounded-md p-1 transition-colors cursor-pointer disabled:opacity-50",M?"text-amber-300 hover:text-amber-200":"text-muted-foreground/60 hover:text-foreground"),children:l["rt:"+r.id]?e.jsx(v,{className:"h-3.5 w-3.5 animate-spin"}):e.jsx(be,{className:"h-3.5 w-3.5"})}),(r.status==="running"||X||r.status==="triage")&&e.jsx("button",{disabled:!!l["st:"+r.id],onClick:()=>u("Karte stoppen?",`'${r.titel.slice(0,60)}' wird angehalten${r.status==="running"?" und der laufende Worker beendet":""}. Sie bleibt als gestoppt im Board und kann jederzeit per „Neuer Versuch“ weiterlaufen.`,()=>w("st:",r.id,"/api/ideen/stopp",{id:r.id})),title:"Stoppen — Karte anhalten",className:"shrink-0 rounded-md p-1 text-muted-foreground/60 transition-colors hover:text-red-300 cursor-pointer disabled:opacity-50",children:l["st:"+r.id]?e.jsx(v,{className:"h-3.5 w-3.5 animate-spin"}):e.jsx(ye,{className:"h-3.5 w-3.5"})}),(r.status==="done"||y)&&e.jsx("button",{disabled:!!l[r.id],onClick:()=>d(r.id),title:y?"Aufgeben und aus der Liste räumen (wandert ins Kanban-Archiv)":"Aus der Liste räumen (wandert ins Kanban-Archiv)",className:"shrink-0 rounded-md p-1 text-muted-foreground/60 transition-colors hover:text-foreground cursor-pointer disabled:opacity-50",children:l[r.id]?e.jsx(v,{className:"h-3.5 w-3.5 animate-spin"}):e.jsx(T,{className:"h-3.5 w-3.5"})}),P&&e.jsx("button",{onClick:()=>B(i?null:r.id),title:r.status==="done"?"Ergebnis anzeigen":"Worker-Log anzeigen",className:"shrink-0 rounded-md p-1 text-muted-foreground/60 transition-colors hover:text-foreground cursor-pointer",children:i?e.jsx(I,{className:"h-3.5 w-3.5"}):e.jsx(R,{className:"h-3.5 w-3.5"})})]}),r.status==="running"&&r.notiz&&e.jsxs("p",{className:"-mt-1 ml-1 text-[11px] italic leading-relaxed text-sky-200/80",title:"Jüngste Zwischenmeldung des Workers (Heartbeat)",children:["„",r.notiz,"“"]}),(r.status==="todo"||r.status==="scheduled"||r.status==="ready")&&(((Y=r.wartet_auf)==null?void 0:Y.length)??0)>0&&e.jsxs("p",{className:"-mt-1 ml-1 text-[10px] text-muted-foreground/70",children:["→ wartet auf: ",r.wartet_auf.join(" · ")]}),y&&e.jsxs("div",{className:"space-y-2 border-t border-red-500/20 pt-2",children:[e.jsxs("p",{className:"flex items-start gap-1.5 text-[11px] leading-relaxed text-red-200/90",children:[e.jsx(me,{className:"mt-0.5 h-3.5 w-3.5 shrink-0 text-red-300"}),e.jsxs("span",{children:[e.jsx("b",{children:Ce[r.frage_kind||""]??"Die Aufgabe hängt und wartet auf dich:"})," ",r.frage?e.jsx("span",{className:"text-foreground/90",children:r.frage}):e.jsx("span",{className:"text-muted-foreground italic",children:"kein genauer Grund hinterlegt — antworte einfach mit einer Entscheidung, dann läuft sie weiter."})]})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("input",{value:C[r.id]||"",onChange:$=>m(oe=>({...oe,[r.id]:$.target.value})),onKeyDown:$=>{$.key==="Enter"&&H(r.id)},placeholder:"Deine Antwort — die Box macht damit weiter",maxLength:2e3,className:"h-8 min-w-0 flex-1 rounded-lg border border-border/60 bg-background/60 px-2.5 text-xs text-foreground placeholder:text-muted-foreground/50 focus:border-red-400/50 focus:outline-none"}),e.jsxs("button",{onClick:()=>H(r.id),disabled:J||(C[r.id]||"").trim().length<1,className:"flex h-8 shrink-0 items-center gap-1.5 rounded-lg border border-emerald-500/40 bg-emerald-500/10 px-3 text-[10px] font-bold uppercase tracking-wide text-emerald-300 transition-all hover:bg-emerald-500/20 cursor-pointer disabled:opacity-50",children:[J?e.jsx(v,{className:"h-3.5 w-3.5 animate-spin"}):e.jsx(te,{className:"h-3.5 w-3.5"})," Antworten & weiter"]})]})]}),i&&P&&r.status!=="done"&&e.jsx("div",{className:"ml-2 -mt-1",children:e.jsx("div",{className:"rounded-lg border border-border/50 bg-background/50 p-2",children:L&&g.isLoading?e.jsx("p",{className:"text-[10px] text-muted-foreground animate-pulse",children:"Log wird geladen …"}):g.error?e.jsx("p",{className:"text-[10px] text-red-400",children:"Log nicht ladbar"}):(ee=g.data)!=null&&ee.available&&g.data.lines.length>0?e.jsx("pre",{className:"max-h-64 overflow-auto font-mono text-[10px] leading-relaxed text-foreground/80 whitespace-pre-wrap",children:g.data.lines.join(` `)}):e.jsx("p",{className:"text-[10px] text-muted-foreground",children:"Kein Log verfügbar"})})}),i&&r.status==="done"&&e.jsx(Le,{id:r.id})]},r.id)};return t&&!t.available?null:e.jsxs("section",{className:"space-y-3",children:[e.jsxs(G,{icon:ge,children:["Ideen-Queue",t?` — ${t.offen} offen`:""]}),e.jsxs("div",{className:"mc-card p-4 space-y-3",children:[e.jsxs("div",{className:"flex gap-2",children:[e.jsx("input",{value:f,onChange:r=>j(r.target.value),onKeyDown:r=>{r.key==="Enter"&&W()},placeholder:"Neue Idee — einfach hinschreiben, die Box macht den Rest",className:"h-9 min-w-0 flex-1 rounded-lg border border-border/60 bg-background/50 px-3 text-sm text-foreground placeholder:text-muted-foreground/50 focus:border-primary/50 focus:outline-none"}),e.jsxs("button",{onClick:W,disabled:A||f.trim().length<3,className:S("flex h-9 shrink-0 items-center gap-1.5 rounded-lg border px-3 text-[11px] font-bold uppercase tracking-wide transition-all cursor-pointer disabled:opacity-50",o==="ide"?"border-violet-500/40 bg-violet-500/10 text-violet-300 hover:bg-violet-500/20":"border-primary/40 bg-primary/10 text-primary hover:bg-primary/20"),children:[A?e.jsx(v,{className:"h-3.5 w-3.5 animate-spin"}):o==="ide"?e.jsx(O,{className:"h-3.5 w-3.5"}):e.jsx(te,{className:"h-3.5 w-3.5"}),o==="ide"?"Vorbereiten":"In die Queue"]})]}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"text-[11px] text-muted-foreground/70",children:"Modus"}),e.jsxs("div",{className:"flex rounded-lg border border-border/60 p-0.5",children:[e.jsxs("button",{onClick:()=>N("box"),className:S("flex items-center gap-1 rounded px-2 py-1 text-[10px] font-bold uppercase tracking-wide transition-all cursor-pointer",o==="box"?"bg-primary/15 text-primary":"text-muted-foreground/60 hover:text-foreground"),children:[e.jsx(de,{className:"h-3 w-3"})," Box"]}),e.jsxs("button",{onClick:()=>N("ide"),className:S("flex items-center gap-1 rounded px-2 py-1 text-[10px] font-bold uppercase tracking-wide transition-all cursor-pointer",o==="ide"?"bg-violet-500/15 text-violet-300":"text-muted-foreground/60 hover:text-foreground"),children:[e.jsx(O,{className:"h-3 w-3"})," IDE"]})]})]}),e.jsx("p",{className:"text-[11px] text-muted-foreground",children:o==="ide"?e.jsxs(e.Fragment,{children:[e.jsx("b",{className:"text-violet-300/90",children:"IDE-Welt:"})," Die Box denkt das Konzept wasserdicht durch (mehrere Denk-Runden mit Kritiker), legt ein leeres Gitea-Repo an und füllt es nur mit den wichtigen Dokumenten (Konzept, Roadmap, AGENTS.md, .aiexclude) — ",e.jsx("b",{children:"kein Code"}),". Danach öffnest du das Repo in Zed und baust selbst. Das Vorbereiten dauert ein paar Minuten."]}):e.jsx(e.Fragment,{children:"Eine Queue, alle Türen: hier, per Telegram oder im Gespräch mit Lucy. Die Box arbeitet Ideen selbst aus und baut — Code-Ergebnisse erscheinen als Karte unter „Patch-Vorschläge“, nichts davon geht ohne deinen Klick live. Nur reine Doku-Bagatellen zieht die Box nachts selbst ein (mit Fangnetz und Meldung)."})}),a&&e.jsxs("p",{className:"flex items-center gap-2 text-xs text-muted-foreground",children:[e.jsx(v,{className:"h-3.5 w-3.5 animate-spin"})," Queue wird geladen …"]}),(t==null?void 0:t.fehler)&&e.jsx("p",{className:"text-xs text-amber-300",children:"Queue gerade nicht lesbar — neuer Versuch läuft."}),k.length>0&&e.jsxs("div",{className:"space-y-3",children:[((t==null?void 0:t.projekte)??[]).map(r=>e.jsx(Ee,{projekt:r,karten:k.filter(n=>n.projekt===r.key),zeile:Q},r.key)),(()=>{const r=new Set(((t==null?void 0:t.projekte)??[]).map(i=>i.key)),n=k.filter(i=>!i.projekt||!r.has(i.projekt));return n.length>0?e.jsx("ul",{className:"space-y-1.5",children:n.map(i=>Q(i))}):null})()]}),(t==null?void 0:t.available)&&!a&&k.length===0&&e.jsx("p",{className:"text-xs text-muted-foreground/70",children:"Queue ist leer — wirf der Box eine Idee zu."})]}),D]})}const _={blocked:0,running:1,review:2,ready:3,triage:4};function Ee({projekt:t,karten:a,zeile:c}){const[p,u]=h.useState(!1),[D,f]=h.useState(!1),j=a.filter(s=>_[s.status]!==void 0).sort((s,l)=>_[s.status]-_[l.status]||(s.erstellt??0)-(l.erstellt??0)),o=a.filter(s=>s.status==="todo"||s.status==="scheduled").sort((s,l)=>{var b,x;return((b=s.wartet_auf)!=null&&b.length?1:0)-((x=l.wartet_auf)!=null&&x.length?1:0)||(s.erstellt??0)-(l.erstellt??0)}),N=a.filter(s=>s.status==="done").sort((s,l)=>(l.fertig??0)-(s.fertig??0)),A=t.gesamt>0?Math.round(t.fertig/t.gesamt*100):0;return e.jsxs("div",{className:"space-y-2 rounded-xl border border-border/50 bg-background/20 p-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(pe,{className:"h-4 w-4 shrink-0 text-primary/70"}),e.jsx("p",{className:"min-w-0 flex-1 truncate text-xs font-semibold text-foreground",title:t.titel,children:t.titel}),e.jsxs("span",{className:"shrink-0 text-[10px] text-muted-foreground",children:[t.fertig," von ",t.gesamt," fertig"]})]}),e.jsx("div",{className:"h-1 overflow-hidden rounded-full bg-background/60",title:`${A}%`,children:e.jsx("div",{className:"h-1 rounded-full bg-primary/70 transition-all",style:{width:`${A}%`}})}),j.length>0&&e.jsx("ul",{className:"space-y-1.5",children:j.map(s=>c(s))}),o.length>0&&e.jsxs("div",{children:[e.jsxs("button",{onClick:()=>u(s=>!s),className:"flex items-center gap-1.5 text-[11px] font-semibold text-muted-foreground hover:text-foreground transition-colors cursor-pointer",children:[p?e.jsx(I,{className:"h-3.5 w-3.5"}):e.jsx(R,{className:"h-3.5 w-3.5"}),o.length," Karte",o.length===1?"":"n"," in der Kette — laufen automatisch der Reihe nach"]}),p&&e.jsx("ul",{className:"mt-1.5 space-y-1.5",children:o.map(s=>c(s))})]}),N.length>0&&e.jsxs("div",{children:[e.jsxs("button",{onClick:()=>f(s=>!s),className:"flex items-center gap-1.5 text-[11px] font-semibold text-emerald-300/70 hover:text-emerald-300 transition-colors cursor-pointer",children:[D?e.jsx(I,{className:"h-3.5 w-3.5"}):e.jsx(R,{className:"h-3.5 w-3.5"}),N.length," fertig"]}),D&&e.jsx("ul",{className:"mt-1.5 space-y-1.5",children:N.map(s=>c(s))})]})]})}function Le({id:t}){const[a,c]=h.useState(null),[p,u]=h.useState(!1),[D,f]=h.useState(0);h.useEffect(()=>{let o=!1;return u(!1),c(null),z(`/api/ideen/${t}/ergebnis`).then(N=>{o||c(N)}).catch(()=>{o||u(!0)}),()=>{o=!0}},[t,D]);const j=a?a.summary||a.result:"";return e.jsx("div",{className:"ml-2 -mt-1",children:e.jsxs("div",{className:"rounded-lg border border-emerald-500/25 bg-emerald-500/5 p-2.5",children:[e.jsxs("p",{className:"mb-1 flex items-center gap-1.5 text-[10px] font-bold uppercase tracking-wide text-emerald-300",children:[e.jsx(Ne,{className:"h-3 w-3"})," Ergebnis des Workers"]}),p?e.jsx("button",{type:"button",onClick:()=>f(o=>o+1),className:"text-[10px] text-red-400 underline decoration-dotted underline-offset-2 hover:text-red-300",children:"Ergebnis nicht ladbar — nochmal versuchen"}):a===null?e.jsx("p",{className:"text-[10px] text-muted-foreground animate-pulse",children:"Wird geladen …"}):j?e.jsx("p",{className:"max-h-64 overflow-y-auto whitespace-pre-wrap text-xs leading-relaxed text-foreground/85",children:j}):e.jsx("p",{className:"text-[10px] text-muted-foreground italic",children:"Der Worker hat keine Abschluss-Zusammenfassung hinterlassen (ältere Karte oder Protokollverstoß)."})]})})}function Be({item:t}){const a=t.status;if(!a)return null;const c=De[a.state];return c?e.jsxs("span",{className:S("flex items-center gap-1.5 rounded-lg border px-2 py-0.5 text-[10px] font-bold",c.cls),title:a.detail,children:[c.spin&&e.jsx(v,{className:"h-3 w-3 animate-spin"}),c.label]}):null}function ze({item:t,busy:a,onAct:c,showConfirm:p}){var L,g,W;const[u,D]=h.useState(!1),[f,j]=h.useState(null),[o,N]=h.useState(!1),[A,s]=h.useState(!1),[l,b]=h.useState(""),x=((L=t.status)==null?void 0:L.state)==="laeuft"||((g=t.status)==null?void 0:g.state)==="rollback",B=((W=t.status)==null?void 0:W.state)==="eingespielt",C=t.repo??"mc2",m=C==="lucy",k=`${C}:${t.branch}`;async function E(){const d=!u;if(D(d),d&&f===null){N(!0);try{const w=await z(`/api/auftragsbuch/diff?branch=${encodeURIComponent(t.branch)}&repo=${C}`);j(w.diff+(w.truncated?` … (gekürzt)`:""))}catch(w){j(`(Diff nicht ladbar: ${(w==null?void 0:w.message)||w})`)}finally{N(!1)}}}return e.jsxs("div",{className:"mc-card p-4 space-y-3",children:[e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("span",{className:"rounded-md border border-primary/30 bg-primary/10 px-1.5 py-0.5 text-[10px] font-bold uppercase tracking-wider text-primary",children:ve[t.kind]??t.kind}),m&&e.jsx("span",{className:"rounded-md border border-pink-500/40 bg-pink-500/10 px-1.5 py-0.5 text-[10px] font-bold uppercase tracking-wider text-pink-300",title:"Vorschlag fürs Lucy-Repo — Annehmen baut die App am PC neu und startet sie neu, wenn sie läuft.",children:"Lucy"}),e.jsx("span",{className:"font-mono text-[11px] text-muted-foreground truncate",title:t.branch,children:t.branch}),e.jsxs("span",{className:"flex items-center gap-1 text-[10px] text-muted-foreground/70",children:[e.jsx(F,{className:"h-3 w-3"}),q(t.ts)]}),e.jsx(Be,{item:t})]}),e.jsx("p",{className:"mt-1.5 text-sm font-semibold text-foreground",children:t.subject||"(ohne Titel)"}),t.body&&e.jsx("p",{className:"mt-1 whitespace-pre-wrap text-xs leading-relaxed text-muted-foreground line-clamp-6",children:t.body}),t.empfehlung&&e.jsxs("p",{className:S("mt-1.5 flex items-start gap-1.5 rounded-lg border px-2 py-1 text-[11px]",t.empfehlung.empfehlung==="ANNEHMEN"&&"border-emerald-500/30 bg-emerald-500/5 text-emerald-300",t.empfehlung.empfehlung==="ABLEHNEN"&&"border-red-500/30 bg-red-500/5 text-red-300",t.empfehlung.empfehlung==="UNKLAR"&&"border-amber-500/30 bg-amber-500/5 text-amber-300"),title:`Nächtliches Kurz-Gutachten (${t.empfehlung.richter}) — eine Meinung, kein Muss. Die Entscheidung bleibt bei dir.`,children:[e.jsx(le,{className:"mt-0.5 h-3 w-3 shrink-0"}),e.jsxs("span",{children:[e.jsxs("b",{children:["Empfehlung: ",t.empfehlung.empfehlung==="ANNEHMEN"?"Annehmen":t.empfehlung.empfehlung==="ABLEHNEN"?"Ablehnen":"Unklar","."]})," ",t.empfehlung.satz]})]})]}),!x&&!B&&e.jsxs("div",{className:"flex shrink-0 items-center gap-2",children:[!t.verwaist&&e.jsxs("button",{disabled:!!a[k],onClick:()=>p("Vorschlag annehmen?",m?`'${t.branch}' wird im Lucy-Repo auf main gemergt, dann baut dein PC die App neu (dist) und startet Lucy neu, falls sie gerade läuft. Der PC muss dafür an sein. Schlägt Build oder Start fehl, dreht die Box den Merge automatisch zurück — die laufende Lucy bleibt die alte.`:`'${t.branch}' wird auf main gemergt und live eingespielt. Die Zentrale startet dabei kurz neu. Geht der Health-Check danach rot, rollt die Box automatisch zurück.${t.frontend_ohne_build?` Achtung: Enthält Frontend-Quelltext ohne gebautes Bundle — die Oberfläche bleibt alt, bis am PC gebaut wird.`:""}`,()=>c(k,"/api/auftragsbuch/annehmen",{branch:t.branch,repo:C})),className:"flex h-9 items-center gap-1.5 rounded-lg border border-emerald-500/40 bg-emerald-500/10 px-3 text-[11px] font-bold uppercase tracking-wide text-emerald-300 transition-all hover:bg-emerald-500/20 cursor-pointer disabled:opacity-50",children:[a[k]?e.jsx(v,{className:"h-3.5 w-3.5 animate-spin"}):e.jsx(ne,{className:"h-3.5 w-3.5"})," Annehmen"]}),e.jsxs("button",{disabled:!!a["ab:"+k],onClick:()=>s(d=>!d),className:"flex h-9 items-center gap-1.5 rounded-lg border border-red-500/30 bg-red-500/5 px-3 text-[11px] font-bold uppercase tracking-wide text-red-300/90 transition-all hover:bg-red-500/15 cursor-pointer disabled:opacity-50",children:[a["ab:"+k]?e.jsx(v,{className:"h-3.5 w-3.5 animate-spin"}):e.jsx(T,{className:"h-3.5 w-3.5"})," Ablehnen"]})]})]}),A&&!x&&!B&&e.jsxs("div",{className:"space-y-2 rounded-xl border border-red-500/25 bg-red-500/5 p-3",children:[e.jsxs("p",{className:"text-[11px] text-muted-foreground",children:["Der Branch '",t.branch,"' wird auf Gitea gelöscht (die Arbeit bleibt in der Historie). Sag der Box kurz ",e.jsx("b",{children:"warum"})," — dann schlägt sie dir so etwas nicht wieder vor."]}),e.jsx("input",{value:l,onChange:d=>b(d.target.value),placeholder:"Grund (optional) — z. B. „gibt es schon“ oder „will ich nicht“",maxLength:400,className:"w-full rounded-lg border border-border/60 bg-background/60 px-2.5 py-1.5 text-xs text-foreground placeholder:text-muted-foreground/50 focus:border-red-400/50 focus:outline-none"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("button",{disabled:!!a["ab:"+k],onClick:()=>{s(!1),c("ab:"+k,"/api/auftragsbuch/ablehnen",{branch:t.branch,repo:C,grund:l.trim()})},className:"flex h-8 items-center gap-1.5 rounded-lg border border-red-500/40 bg-red-500/10 px-3 text-[11px] font-bold uppercase tracking-wide text-red-300 transition-all hover:bg-red-500/20 cursor-pointer disabled:opacity-50",children:[e.jsx(T,{className:"h-3.5 w-3.5"})," Wirklich ablehnen"]}),e.jsx("button",{onClick:()=>s(!1),className:"flex h-8 items-center rounded-lg border border-border/60 bg-background/40 px-3 text-[11px] font-semibold text-muted-foreground transition-all hover:text-foreground cursor-pointer",children:"Abbrechen"})]})]}),t.status&&(x||!B)&&t.status.detail&&e.jsx("p",{className:"text-[11px] text-muted-foreground",children:t.status.detail}),t.verwaist&&e.jsxs("p",{className:"rounded-lg border border-red-500/30 bg-red-500/5 px-2 py-1.5 text-[11px] text-red-300/90",children:[e.jsx("b",{children:"Kaputt aufgesetzt:"})," Dieser Branch hat keinen gemeinsamen Ursprung mit main (der Werkstatt-Worker hat nicht richtig geklont) — Annehmen ist technisch unmöglich, deshalb fehlt der Knopf. Am besten ",e.jsx("b",{children:"ablehnen mit Grund"}),"; die Idee kann danach frisch in die Queue."]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2 text-[11px] text-muted-foreground",children:[e.jsxs("span",{className:"rounded bg-background/40 px-1.5 py-0.5 font-mono",children:[t.ahead," Commit",t.ahead===1?"":"s"]}),t.shortstat&&e.jsx("span",{className:"rounded bg-background/40 px-1.5 py-0.5 font-mono",children:t.shortstat.trim()}),t.verwaist&&e.jsxs("span",{className:"flex items-center gap-1 rounded bg-red-500/10 px-1.5 py-0.5 text-red-300",title:"Kein gemeinsamer Vorfahre mit main — git kann diesen Branch niemals mergen.",children:[e.jsx(V,{className:"h-3 w-3"})," kein gemeinsamer Ursprung"]}),t.leer&&e.jsxs("span",{className:"flex items-center gap-1 rounded bg-amber-500/10 px-1.5 py-0.5 text-amber-300",title:"Der Diff gegen main ist leer — der Branch würde nichts verändern (Inhalt schon in main oder am Repo vorbei gearbeitet).",children:[e.jsx(V,{className:"h-3 w-3"})," Diff leer — bringt nichts"]}),t.behind>0&&!t.verwaist&&e.jsxs("span",{className:"flex items-center gap-1 rounded bg-amber-500/10 px-1.5 py-0.5 text-amber-300",title:"main ist seit diesem Vorschlag weitergelaufen — bei Konflikten versucht die Annahme automatisch einen Rebase.",children:[e.jsx(V,{className:"h-3 w-3"})," ",t.behind," hinter main"]}),t.frontend_ohne_build&&e.jsxs("span",{className:"flex items-center gap-1 rounded bg-amber-500/10 px-1.5 py-0.5 text-amber-300",title:"Die Box kann kein Frontend bauen (kein Node) — nach dem Annehmen bleibt die Oberfläche alt, bis am PC gebaut wird.",children:[e.jsx(V,{className:"h-3 w-3"})," Frontend ohne Build"]})]}),e.jsxs("div",{children:[e.jsxs("button",{onClick:E,className:"flex items-center gap-1.5 text-[11px] font-semibold text-muted-foreground hover:text-foreground transition-colors cursor-pointer",children:[u?e.jsx(I,{className:"h-3.5 w-3.5"}):e.jsx(R,{className:"h-3.5 w-3.5"}),e.jsx(ke,{className:"h-3.5 w-3.5"})," ",t.files.length," Datei",t.files.length===1?"":"en"," — Änderungen ansehen"]}),u&&e.jsxs("div",{className:"mt-2 space-y-2",children:[e.jsxs("div",{className:"flex flex-wrap gap-1.5",children:[t.files.map(d=>e.jsxs("span",{className:"rounded bg-background/40 px-1.5 py-0.5 font-mono text-[10px] text-muted-foreground",children:[e.jsx("b",{className:S(d.status.startsWith("A")&&"text-emerald-400",d.status.startsWith("D")&&"text-red-400",d.status.startsWith("M")&&"text-sky-400"),children:d.status})," ",d.path]},d.path)),t.files_truncated&&e.jsx("span",{className:"text-[10px] text-muted-foreground/60",children:"…"})]}),e.jsx("div",{className:"max-h-96 overflow-auto rounded-xl border border-border/50 bg-background/50 p-3",children:o?e.jsx("span",{className:"text-[11px] text-muted-foreground",children:"Diff wird geladen …"}):e.jsx("pre",{className:"text-[10px] leading-relaxed text-foreground/80 whitespace-pre",children:(f??"").split(` `).map((d,w)=>e.jsx("span",{className:S("block",d.startsWith("+")&&!d.startsWith("+++")&&"text-emerald-300/90 bg-emerald-500/5",d.startsWith("-")&&!d.startsWith("---")&&"text-red-300/90 bg-red-500/5",(d.startsWith("@@")||d.startsWith("diff "))&&"text-sky-300/90"),children:d||" "},w))})})]})]})]})}function Ke({k:t,busy:a,onAct:c,showConfirm:p}){const[u,D]=h.useState(!1);return e.jsxs("div",{className:"rounded-2xl border border-violet-500/25 bg-violet-500/[0.04] p-4 shadow-lg shadow-black/15 backdrop-blur-md space-y-3",children:[e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("span",{className:"rounded-md border border-violet-500/30 bg-violet-500/10 px-1.5 py-0.5 text-[10px] font-bold uppercase tracking-wider text-violet-300",children:"Traum-Idee"}),e.jsx("span",{className:"font-mono text-[11px] text-muted-foreground truncate",children:t.file}),e.jsxs("span",{className:"flex items-center gap-1 text-[10px] text-muted-foreground/70",children:[e.jsx(F,{className:"h-3 w-3"}),q(t.mtime)]})]}),e.jsx("p",{className:"mt-1.5 text-sm font-semibold text-foreground",children:t.title})]}),e.jsxs("div",{className:"flex shrink-0 items-center gap-2",children:[e.jsxs("button",{disabled:!!a["sk:"+t.file],onClick:()=>p("Werkstatt beauftragen?",`Der Kandidat '${t.title}' geht als Auftrag an die Werkstatt (Orchestrator, propose-only). Das Ergebnis erscheint später als neuer Patch-Vorschlag hier im Auftragsbuch — nichts geht ungefragt live.`,()=>c("sk:"+t.file,"/api/auftragsbuch/skill/annehmen",{file:t.file},"Die Werkstatt arbeitet. Das Ergebnis taucht als neuer Vorschlag im Auftragsbuch auf (das kann einige Minuten dauern).")),className:"flex h-9 items-center gap-1.5 rounded-lg border border-violet-500/40 bg-violet-500/10 px-3 text-[11px] font-bold uppercase tracking-wide text-violet-300 transition-all hover:bg-violet-500/20 cursor-pointer disabled:opacity-50",children:[a["sk:"+t.file]?e.jsx(v,{className:"h-3.5 w-3.5 animate-spin"}):e.jsx(de,{className:"h-3.5 w-3.5"})," Beauftragen"]}),e.jsxs("button",{disabled:!!a["skab:"+t.file],onClick:()=>p("Kandidat verwerfen?",`'${t.title}' wandert ins Archiv des Wissens-Vaults (verworfen/). Der Traum schlägt ihn nicht erneut vor.`,()=>c("skab:"+t.file,"/api/auftragsbuch/skill/ablehnen",{file:t.file})),className:"flex h-9 items-center gap-1.5 rounded-lg border border-red-500/30 bg-red-500/5 px-3 text-[11px] font-bold uppercase tracking-wide text-red-300/90 transition-all hover:bg-red-500/15 cursor-pointer disabled:opacity-50",children:[a["skab:"+t.file]?e.jsx(v,{className:"h-3.5 w-3.5 animate-spin"}):e.jsx(T,{className:"h-3.5 w-3.5"})," Verwerfen"]})]})]}),e.jsxs("button",{onClick:()=>D(f=>!f),className:"flex items-center gap-1.5 text-[11px] font-semibold text-muted-foreground hover:text-foreground transition-colors cursor-pointer",children:[u?e.jsx(I,{className:"h-3.5 w-3.5"}):e.jsx(R,{className:"h-3.5 w-3.5"}),e.jsx(xe,{className:"h-3.5 w-3.5"})," Vorschlag lesen"]}),u&&e.jsx("pre",{className:"max-h-72 overflow-auto rounded-xl border border-border/50 bg-background/50 p-3 text-[11px] leading-relaxed text-foreground/85 whitespace-pre-wrap",children:t.preview})]})}export{Me as AuftragsbuchView};