agent-dealer 1.2.16 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -61,4 +61,4 @@ Please change the parent <Route path="${H}"> to <Route path="${H==="/"?"*":`${H}
61
61
  `).map(m=>m.trim()).filter(m=>m.length>0);return{head:u,commands:f}}function Yw(n){const s=Vy(n).head.replace(/\s+/g," ").trim(),u=s.match(/^(.+?[.!?])(\s|$)/);return(u?u[1]:s).trim()}const Vw=/(?:~|\/(?:[^/\s\\:"'*?<>|][^/\s\\:"'*?<>|]*))+(?:\/[^/\s\\:"'*?<>|]+)*/g;function Zw(n){const l=[],s=new Set,u=f=>{const m=f.trim().replace(/[.,;:!?)"'\]]+$/,"");m.length<2||s.has(m)||(s.add(m),l.push(m))};for(const f of[n.reason,n.question])for(const m of f.matchAll(Vw)){const x=m[0];/^\/\d+(\.\d+)*$/.test(x)||!x.includes("/")&&!x.startsWith("~")||u(x)}const d=Du(n);return typeof(d==null?void 0:d.worktreePath)=="string"&&d.worktreePath&&u(d.worktreePath),l}function kx(n){return n.length>12?n.slice(0,12):n}function Gw(n){const l=[],s=Du(n);if(s&&typeof s.localSha=="string"&&typeof s.remoteSha=="string"){const d=typeof s.branch=="string"?s.branch:"the branch",f=typeof s.ahead=="number"?` (+${s.ahead})`:"",m=typeof s.behind=="number"?` (+${s.behind})`:"";l.push(`Push: local ${s.localSha}${f} · origin/${d} ${s.remoteSha}${m}`),typeof s.observedRemoteSha=="string"&&s.observedRemoteSha!==s.remoteSha&&l.push(`Remote moved: origin/${d} is now at ${s.observedRemoteSha}`),typeof s.lastLeaseError=="string"&&s.lastLeaseError&&l.push(`Last lease attempt: ${s.lastLeaseError}`)}const u=Yy(n);return u&&l.push(`Continuation: resumes as ${u}`),l}function Qw(n){return n==="close"||n==="reject"||n==="abort"}function nl(n){return n.length===0?null:n.some(l=>l.choice==="push_with_lease")?"push_with_lease":(n.find(l=>!Qw(l.choice))??n[0]).choice}function Xw(n){if(n.actionType!=="policy_escalation")return"other";if(Bw(n))return"merge-failure";const l=Du(n);if((l==null?void 0:l.relationship)==="diverged")return"diverged-push";if(l&&(l.relationship==="behind"||typeof l.localSha=="string"))return"unpushed";const s=`${n.reason}
62
62
  ${n.question}`;return Hw.test(s)?"unpushed":Yy(n)==="reviewer"?"reviewer-retry":$w.test(s)?"dirty-worktree":zw(n)||/already used by worktree/i.test(s)||/worktree/i.test(s)&&/Recovery:/.test(s)?"worktree-conflict":"ordinary-escalation"}const Iw="Resume safely";function Zy(n){const l=Xw(n),s=Uw(n),{commands:u}=Vy(n.reason),d=Zw(n),f=Gw(n),m=(()=>{const y=Mu(n.evidenceJson);return y==null?null:JSON.stringify(y,null,2)})(),x={question:n.question,reason:n.reason,commands:u,paths:d,factLines:f,evidencePretty:m};switch(l){case"diverged-push":{const y=Du(n),v=y&&typeof y.branch=="string"&&typeof y.localSha=="string"&&typeof y.remoteSha=="string"?` (origin/${y.branch}: local ${kx(y.localSha)} against remote ${kx(y.remoteSha)})`:"";return{kind:l,title:"Publish these finished commits with a pinned lease?",context:`Your branch diverged from the remote — confirm the pinned commits${v} under Details, then choose Push with lease.`,safeResume:!1,displayOptions:s,primaryChoice:nl(s),details:x}}case"unpushed":return{kind:l,title:"The push was rejected — how should we proceed?",context:"Your commits are saved; resuming continues development without discarding them.",safeResume:!1,displayOptions:s,primaryChoice:nl(s),details:x};case"worktree-conflict":return{kind:l,title:"A saved worktree still holds this branch — how should we proceed?",context:"Your work is preserved; check the worktree path and recovery steps under Details before choosing.",safeResume:!1,displayOptions:s,primaryChoice:nl(s),details:x};case"dirty-worktree":return{kind:l,title:"Uncommitted changes were preserved — how should we proceed?",context:"Nothing was discarded; review the saved changes under Details before choosing.",safeResume:!1,displayOptions:s,primaryChoice:nl(s),details:x};case"merge-failure":return{kind:l,title:"The merge failed after approval — retry it?",context:"The work is already approved; retrying the merge publishes the same commits without a new developer round.",safeResume:!1,displayOptions:s,primaryChoice:nl(s),details:x};case"reviewer-retry":return{kind:l,title:"The review attempt failed — retry it?",context:"Nothing is wrong with the code itself; retrying re-queues the reviewer at the same pinned commit.",safeResume:!0,displayOptions:s,primaryChoice:nl(s),details:x};case"ordinary-escalation":{const y=Yw(n.reason),v=!qw.test(`${n.reason}
63
63
  ${n.question}`),w=v?s.map(j=>j.choice==="resume"&&j.label==="Resume development"?{...j,label:Iw}:j):s;return{kind:l,title:"Development is parked — resume or close?",context:y?`${y} Choose ${v?"Resume safely":"Resume"} to continue, or Close to stop.`:null,safeResume:v,displayOptions:w,primaryChoice:nl(w),details:x}}case"other":default:return{kind:"other",title:n.question,context:null,safeResume:!1,displayOptions:s,primaryChoice:nl(s),details:x}}}const Kw=he(["blocking","non_blocking"]),Jw=he(["open","resolved","recurring","superseded"]);z({id:p().uuid(),issueId:p().uuid(),fingerprint:p(),severity:Kw,title:p(),rationale:p(),evidenceRef:p().nullable(),file:p().nullable(),line:A().int().nullable(),status:Jw,firstRound:A().int().min(1),lastRound:A().int().min(1)});z({id:p().uuid(),issueId:p().uuid(),workerSessionId:p().uuid(),role:he(["developer","reviewer","legacy"]),runtime:p().nullable(),tokensIn:A().int().nullable(),tokensOut:A().int().nullable(),costUsd:A().nullable(),durationMs:A().int().nullable(),ts:p(),model:p().nullable().optional()});const Fw=z({available:ka(!0)}),Ww=z({available:ka(!1),until:p(),reason:p()});Ry("available",[Fw,Ww]);const af=he(["supported_protocol","observed_event","experimental_api","unavailable"]),Uu=he(["unsupported","missing","expired","unparsable","stale"]),Pw=he(["five_hour","weekly"]),e2=z({message:p().min(1),consecutiveFailures:A().int().positive(),firstFailureAt:p(),lastFailureAt:p()}),t2=z({windowKey:p().min(1),providerBucket:p().min(1),durationMinutes:A().int().positive().nullable(),displayLabel:p().min(1),usedValue:A().nullable(),usedUnit:p().nullable(),remainingPercent:A().min(0).max(100).nullable(),resetAt:p().nullable(),observedAt:p(),freshUntil:p().nullable(),expiresAt:p().nullable(),source:af,unavailableReason:Uu.nullable(),unavailableDetail:e2.nullable().optional(),criticalRole:Pw.nullable()}),a2=z({runtime:Yt,windows:ae(t2),unavailableReason:Uu.nullable()});z({runtimes:ae(a2),generatedAt:p()});z({configured:Oe(),cycleStart:p().nullable(),cycleEnd:p().nullable(),spendValue:A().nullable(),spendUnit:p().nullable(),hardLimitValue:A().nullable(),hardLimitUnit:p().nullable(),memberCount:A().nullable(),memberLimitOverrideCount:A().nullable(),usagePeriodStart:p().nullable(),usagePeriodEnd:p().nullable(),usageSpendValue:A().nullable(),usageSpendUnit:p().nullable(),source:af,unavailableReason:Uu.nullable(),observedAt:p().nullable(),generatedAt:p()});z({enabled:Oe(),configured:Oe(),cycleLabel:p().nullable(),cycleStart:p().nullable(),cycleEnd:p().nullable(),usageValue:A().nullable(),usageUnit:p().nullable(),remainingPercent:A().min(0).max(100).nullable(),source:af,unavailableReason:Uu.nullable(),observedAt:p().nullable(),generatedAt:p()});function Gy(n,l=Date.now()){if(n.remainingPercent===null||n.source==="unavailable"||n.unavailableReason!==null)return!1;if(n.resetAt!==null){const s=Date.parse(n.resetAt);if(!Number.isFinite(s)||s<=l)return!1}if(n.freshUntil!==null){const s=Date.parse(n.freshUntil);if(!Number.isFinite(s)||s<=l)return!1}if(n.expiresAt!==null){const s=Date.parse(n.expiresAt);if(!Number.isFinite(s)||s<=l)return!1}if(n.observedAt){const s=Date.parse(n.observedAt);if(!Number.isFinite(s)||s>l+6e4)return!1}return!0}const n2=he(["queued","admitted","removed"]),l2=z({id:p().uuid(),issueId:p().uuid(),position:A().int(),enqueuedAt:p(),state:n2,waitReason:p().nullable(),waitReasonAt:p().nullable()});l2.extend({title:p().optional(),issueStatus:p().optional()});z({issueId:p().uuid()});const i2=Q1([ka("top"),ka("bottom"),z({before:p().uuid()}).strict(),z({after:p().uuid()}).strict()]);z({to:i2});const s2=2;z({maxActiveIssues:A().int().min(1).max(s2)});z({active:A().int().min(0),waiting:A().int().min(0),limit:A().int().min(0),maxActiveIssues:A().int().min(1),ceiling:A().int().min(0),options:ae(A().int().min(1)),overCap:Oe()});const ia=he(["exact","inferred","unavailable"]),zu=z({quality:ia,reasons:ae(p())}),Qy=he(["queue_wait","coordinator_setup","agent_process","coordinator_validation_publish","coordinator_work"]),Us=z({phase:Qy,startMs:A().int().nullable(),endMs:A().int().nullable(),durationMs:A().int().nullable(),quality:ia,reasons:ae(p()),sessionId:p().nullable(),startCursor:A().int().nullable(),endCursor:A().int().nullable()}),r2=zu.extend({phase:Qy,durationMs:A().int().nullable(),rawCount:A().int(),known:A().int(),total:A().int()}),Xy=z({kind:he(["admission_dependency_wait","runtime_health_preflight","unexplained_silence","human_wait"]),startMs:A().int().nullable(),endMs:A().int().nullable(),durationMs:A().int().nullable(),quality:ia,reasons:ae(p()),category:p().nullable(),sessionId:p().nullable()}),Jt=zu.extend({value:A().nullable(),known:A().int(),total:A().int()}),Wa=zu.extend({p50:A().nullable(),p95:A().nullable(),n:A().int()}),u2=z({sessionId:p(),role:p(),runtime:p().nullable(),model:p().nullable(),status:p(),round:A().int(),publishOnly:Oe(),setup:Us,agentProcess:Us,validationPublish:Us,spawnEnvelopeMs:A().int().nullable(),spawnEnvelopeQuality:ia,spawnEnvelopeReasons:ae(p()),failureCauses:ae(Ld),reuseKinds:ae(ef).optional(),silence:ae(Xy),silenceQuality:ia,silenceReasons:ae(p()),tokensIn:A().int().nullable(),tokensOut:A().int().nullable(),costUsd:A().nullable(),usageDurationMs:A().int().nullable(),usageQuality:ia,usageReasons:ae(p())}),o2=z({kind:p().nullable(),observedSha:p().nullable(),msSinceWorkflowStart:A().int().nullable(),quality:ia,reasons:ae(p())}),c2=z({attempts:A().int(),retries:A().int(),cold:A().int(),reused:A().int(),unknown:A().int(),publishOnly:A().int(),reuseRate:A().nullable(),preservedKinds:ae(ef).optional(),quality:ia,reasons:ae(p())}),d2=z({rounds:A().int(),verdicts:A().int(),changeRequests:A().int(),changeRequestRate:A().nullable(),quality:ia,reasons:ae(p())});z({issueId:p(),elapsed:Us,rawIntervals:ae(Us),unionedDurations:ae(r2),exclusiveTotalMs:A().int().nullable(),exclusiveTotalQuality:ia,exclusiveTotalReasons:ae(p()),nested:ae(Xy),attempts:ae(u2),primaryFailure:Ld.nullable(),primaryFailureQuality:ia,primaryFailureReasons:ae(p()),consequenceCauses:ae(Ld),waste:z({failedAttempts:A().int(),publishOnlyAttempts:A().int(),runtimeMs:Jt,tokensIn:Jt,tokensOut:Jt,costUsd:Jt}),firstCheckpoint:o2,retry:c2,reviewer:d2,humanWaitMs:A().int().nullable(),humanWaitQuality:ia,humanWaitReasons:ae(p()),interventionCount:A().int(),coverage:z({duration:Jt,tokens:Jt,cost:Jt})});z({from:p().nullable().default(null),to:p().nullable().default(null),role:p().nullable().default(null),runtime:p().nullable().default(null),model:p().nullable().default(null),status:p().nullable().default(null),repo:p().nullable().default(null),limit:A().int().min(1).max(200).default(50),offset:A().int().min(0).default(0)});const rd=zu.extend({numerator:A().int(),denominator:A().int(),rate:A().nullable()}),ud=z({key:p(),attempts:A().int(),successes:A().int(),successRate:A().nullable(),retries:A().int(),retryRate:A().nullable(),wallTimeMs:Wa});z({window:z({from:p(),to:p(),defaultApplied:Oe()}),pagination:z({limit:A().int(),offset:A().int(),totalIssues:A().int()}),issueIds:ae(p()),phaseWallTime:qs(p(),Wa),attemptSuccess:rd,issueSuccess:rd,primaryFailures:ae(z({code:p(),count:A().int(),rate:A().nullable()})),primaryFailureDenominator:A().int(),waste:z({failedAttempts:A().int(),runtimeMs:Jt,tokensIn:Jt,tokensOut:Jt,costUsd:Jt}),checkpointLatencyMs:Wa,retryReuse:rd,reviewer:z({rounds:A().int(),verdicts:A().int(),changeRequests:A().int(),changeRequestRate:A().nullable(),quality:ia,reasons:ae(p())}),humanInterventions:z({totalActions:A().int(),issuesWithIntervention:A().int(),humanWaitMs:Wa}),byRole:ae(ud),byRuntime:ae(ud),byModel:ae(ud),coverage:z({duration:Jt,tokens:Jt,cost:Jt})});const f2=100,Iy=25,Ky=5,h2=he(["developer","reviewer","legacy"]),m2=he(["authentication_configuration","provider_capacity_rate_limit","agent_cli_crash","tool_test_timeout","muse_no_progress","coordinator_crash","validation_failure","publish_git_failure","agent_deck_unavailable","host_sleep_liveness","unknown"]),p2=he(["task","infrastructure","unknown"]);z({from:p().optional(),to:p().optional(),repo:p().optional(),role:h2.optional(),runtime:p().optional(),model:p().optional(),status:p().optional(),page:jx.number().int().min(1).default(1),limit:jx.number().int().min(1).max(f2).default(Iy)});const Jy=he(["exact","inferred","unavailable"]),Sa=z({sum:A().nullable(),known:A().int().min(0),total:A().int().min(0),quality:Jy,reasons:ae(p())}),od=z({key:p(),issues:A().int().min(0),attempts:A().int().min(0),issueSuccess:A().nullable(),issueSuccessDenominator:A().int().min(0),attemptSuccess:A().nullable(),attemptSuccessDenominator:A().int().min(0),sessionWallMs:Wa,spawnEnvelopeMs:Wa,retryRate:A().nullable(),tokensIn:Sa,tokensOut:Sa,costUsd:Sa,durationMs:Sa,failedDurationMs:Sa,failedTokensIn:Sa,failedTokensOut:Sa,failedCostUsd:Sa}),x2=z({code:m2,domain:p2,count:A().int().min(0),share:A().nullable(),issueIds:ae(p()),issueTotal:A().int().min(0)}),y2=z({id:p(),title:p(),status:p(),repo:p(),attempts:A().int().min(0),updatedAt:p()}),v2=z({window:z({from:p(),to:p()}),filters:z({repo:p().nullable(),role:p().nullable(),runtime:p().nullable(),model:p().nullable(),status:ae(p())}),summary:z({issues:A().int().min(0),closedIssues:A().int().min(0),issueSuccess:A().nullable(),attempts:A().int().min(0),terminalAttempts:A().int().min(0),attemptSuccess:A().nullable(),retryRate:A().nullable(),retryExtraAttempts:A().int().min(0),reuseRate:A().nullable(),reuseDenominator:A().int().min(0),humanWaitMs:A().int().min(0),humanWaitQuality:Jy,interventions:A().int().min(0),avgReviewerRounds:A().nullable(),reviewedIssues:A().int().min(0),changeRequestRate:A().nullable(),sessionWallMs:Wa,spawnEnvelopeMs:Wa,checkpointMs:Wa,phaseWallMs:ae(z({phase:p(),stat:Wa})),failedDurationMs:Sa,failedTokensIn:Sa,failedTokensOut:Sa,failedCostUsd:Sa}),byRole:ae(od),byRuntime:ae(od),byModel:ae(od),failures:ae(x2),issues:ae(y2),pagination:z({page:A().int().min(1),limit:A().int().min(1),total:A().int().min(0),totalPages:A().int().min(0)}),meta:z({generatedAt:p(),partial:Oe(),partialReasons:ae(p())})});function Fy(n){const l=new URLSearchParams;for(const[s,u]of Object.entries(n)){if(u==null)continue;const d=String(u).trim();d&&(s==="page"&&d==="1"||s==="limit"&&d===String(Iy)||l.set(s,d))}return l.sort(),l.toString()}function ll(n,l){return n.sum===null||n.known===0?"Unavailable":n.known<n.total?`${l(n.sum)} (${n.known}/${n.total} known)`:l(n.sum)}function Wy(n){return n<Ky?`n=${n} (sparse)`:`n=${n}`}function Md(n){return n<Ky}function Ax(n,l){if(n.n===0||n.p50===null&&n.p95===null)return"Unavailable";const s=u=>u===null?"–":l(u);return`P50 ${s(n.p50)} · P95 ${s(n.p95)} (${Wy(n.n)})`}function Ls(n){return`$${n.toFixed(2)}`}function Je(n){return n.toLocaleString("en-US")}function g2(n){if(!Number.isFinite(n))return Je(n);const l=Math.abs(n);if(l<1e3)return Je(n);const s=u=>u>=100?String(Math.round(u)):u.toFixed(1).replace(/\.0$/,"");return l<1e6?`${s(n/1e3)}K`:`${s(n/1e6)}M`}function Kt(n){if(n<1e3)return`${Math.round(n)} ms`;const l=n/1e3;if(l<60)return`${l.toFixed(1)} s`;const s=Math.floor(l/60),u=Math.round(l%60);return s<60?`${s}m ${u}s`:`${Math.floor(s/60)}h ${s%60}m`}function Bu(n){return n===null||!Number.isFinite(n)?"Unavailable":`${(n*100).toFixed(1)}%`}const b2=he(["queued","plan_pending","plan_approved","running","review","done","failed","cancelled"]),Py=he(["code","communication","email","research","content","other"]),w2=he(["task_snapshot","draft_plan","approved_plan","plan_triage","plan_answers","acceptance_criteria","transcript","stream_trace","usage","agent_session","execution_result","diff","pr","email_draft","slack_draft","service_draft","document","research_brief","deliverable","feedback","playbook_patch","playbook_use_receipt","deck_feedback_signal","reflect_status","linear_sync","send_receipt","result_qa"]),qu=he(["plan","execute","reflect","qa"]),ev=he(["retry","approve"]);z({patchId:p(),playbookId:p().optional(),playbookTitle:p().optional(),rationale:p().optional(),status:ka("proposed"),trigger:ev,dashboardUrl:p().optional()});z({status:he(["pending","completed","failed","skipped"]),trigger:ev,error:p().optional()});const S2=z({type:he(["system","human","context","thinking","assistant","tool","rate_limit","result"]),text:p(),toolName:p().optional()});z({phase:qu,runtime:Yt,entries:ae(S2)});const j2=z({phase:qu,runtime:Yt,totalCostUsd:A().optional(),inputTokens:A().optional(),outputTokens:A().optional(),cacheReadTokens:A().optional(),cacheWriteTokens:A().optional(),durationMs:A().optional(),model:p().optional(),numTurns:A().optional(),maxTurns:A().optional(),maxBudgetUsd:A().optional()}),N2=z({label:p(),usage:j2,maxTurns:A().optional(),maxBudgetUsd:A().optional()});z({lines:ae(N2),total:z({totalCostUsd:A(),inputTokens:A(),outputTokens:A(),durationMs:A(),numTurns:A()})});z({phase:qu,runtime:Yt,sessionId:p()});z({phase:qu,exitCode:A(),resultText:p().optional(),isError:Oe().optional(),blocker:z({summary:p().optional()}).optional()});z({path:p(),title:p(),markdown:p()});z({markdown:p(),sessionId:p().optional()});const _2=he(["manual","linear"]);z({id:p(),title:p(),description:p().optional(),url:p().optional()});const _n=z({id:p().uuid(),source:_2,externalId:p().nullable(),externalLabel:p().nullable(),taskCategory:Py,title:p(),description:p().nullable(),repo:p().nullable(),artifactWorkspace:p().nullable(),agentId:p().uuid().nullable(),agentName:p().nullable(),deckId:p().nullable(),deckName:p().nullable(),playbookId:p().nullable(),runtime:Yt.nullable(),planModel:p().nullable(),executeModel:p().nullable(),status:b2,lineageId:p().uuid().nullable(),acceptanceCriteria:p().nullable(),approvalGatesJson:p().nullable(),budgetJson:p().nullable(),createdAt:p(),updatedAt:p()});z({id:p().uuid(),runId:p().uuid(),kind:w2,contentJson:p().nullable(),blobPath:p().nullable(),author:he(["human","agent","system"]),createdAt:p()});z({id:p().uuid(),runId:p().uuid(),type:p(),payloadJson:p().nullable(),ts:p()});z({title:p().min(1),description:p().optional(),taskCategory:Py.default("other"),repo:p().optional(),artifactWorkspace:p().optional(),acceptanceCriteria:p().optional(),status:he(["queued","plan_pending","plan_approved"]).default("plan_pending"),agentId:p().uuid(),planModel:p().nullable().optional(),executeModel:p().nullable().optional(),budget:Dy.optional()});z({runtime:Yt,deckId:p().uuid().optional(),playbookId:p().optional(),planModel:p().nullable().optional(),executeModel:p().nullable().optional(),budget:Dy.optional()});z({planMarkdown:p(),approve:Oe().default(!1),planModel:p().nullable().optional(),executeModel:p().nullable().optional(),planBudget:$a.nullable().optional(),executeBudget:$a.nullable().optional()});z({runtime:Yt.optional(),deckId:p().uuid().optional(),playbookId:p().optional(),executeModel:p().nullable().optional(),executeBudget:$a.nullable().optional()});z({feedback:p().min(1),planModel:p().nullable().optional(),executeModel:p().nullable().optional(),executeBudget:$a.nullable().optional()});z({outboundBody:p().min(1).max(4e3).optional()});const k2=z({id:p(),identifier:p(),title:p(),description:p().optional(),url:p(),state:p().optional(),labels:ae(p()).optional(),teamId:p().optional(),branchName:p().optional(),repoResolution:W1.optional(),attachments:ae(My).optional()});z({stateFilter:ae(p()),teamId:p().nullable(),assigneeMe:Oe(),syncEnabled:Oe()});const Dd=z({stateFilter:ae(p().min(1)).min(1),teamId:p().nullable(),assigneeMe:Oe()});Dd.extend({persisted:Dd,envOverrides:z({stateFilter:Oe(),teamId:Oe()})});Dd.partial();const A2=z({id:p(),name:p(),key:p().optional()}),E2=z({name:p(),type:p().optional(),teamId:p().optional()});z({teams:ae(A2),workflowStates:ae(E2),viewer:z({id:p(),name:p(),email:p().optional()}).nullable()});z({candidates:ae(k2),hasMore:Oe()});z({host:p(),port:A().int().min(1).max(65535),envOverride:Oe()});const C2=he(["UNAUTHORIZED","DECK_UNAVAILABLE"]);z({connected:Oe(),apiUrl:p(),mcpUrl:p(),deckCount:A().optional(),envOverride:Oe(),error:p().optional(),deckAccessError:C2.optional(),deckAccessErrorMessage:p().optional()});z({agentId:p().uuid().optional(),autoAgent:Oe().optional(),planModel:p().nullable().optional()}).refine(n=>n.agentId!==void 0||n.autoAgent===!0,{message:"Provide agentId or autoAgent: true"});z({planModel:p().nullable().optional(),planBudget:$a.nullable().optional(),feedback:p().optional(),editedMarkdown:p().optional()});const R2=z({id:p(),label:p()});z({runtime:Yt,models:ae(R2),source:he(["live","fallback"])});z({planReviewCount:A(),resultReviewCount:A(),maxConcurrent:A(),planningActiveRuns:ae(_n),planningQueuedRuns:ae(_n),runningRuns:ae(_n),waitingExecution:ae(_n),resultReviewRuns:ae(_n),recentDone:ae(_n),awaitingPlanReview:ae(_n),awaitingAnswerRuns:ae(_n),openQuestionCounts:qs(p(),A()),pendingSendCounts:qs(p(),A()),sentRunIds:ae(p()).optional(),autoApprovedRunIds:ae(p()),runs:ae(_n),agentDeckOnline:Oe(),agents:ae(By),agentIssueCount:A()});const tv=new Map,cd=new Map;function Ud(n){return tv.get(n)??null}function T2(n,l){l.models.length!==0&&tv.set(n,l)}function O2(n,l){const s=Ud(n);if(s)return Promise.resolve(s);const u=cd.get(n);if(u)return u;const d=l().then(f=>(T2(n,f),f)).finally(()=>cd.delete(n));return cd.set(n,d),d}const be="";async function Ge(n){const l=await n.text();try{const s=JSON.parse(l),u=s.error??s.message;if(typeof u=="string"&&u.trim())return u.replace(/^Error:\s*/i,"")}catch{}return l}async function L2(){const n=await fetch(`${be}/api/intake/linear`);if(!n.ok)throw new Error(await n.text());const l=await n.json();return{candidates:l.candidates??[],hasMore:!!l.hasMore}}async function M2(n){const l=await fetch(`${be}/api/intake/linear/lookup?q=${encodeURIComponent(n)}`),s=await l.json().catch(()=>({}));if(!l.ok)throw new Error(s.error??`Lookup failed (${l.status})`);if(!s.candidate)throw new Error("Linear issue not found");return s.candidate}async function D2(){const n=await fetch(`${be}/api/intake/linear/config`);if(!n.ok)throw new Error(await Ge(n));return n.json()}async function U2(n){const l=await fetch(`${be}/api/intake/linear/config`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify(n)});if(!l.ok)throw new Error(await Ge(l));return l.json()}async function z2(){const n=await fetch(`${be}/api/intake/linear/metadata`);if(!n.ok)throw new Error(await Ge(n));return n.json()}async function B2(){const n=await fetch(`${be}/api/settings/repository-mappings`);if(!n.ok)throw new Error(await Ge(n));return(await n.json()).mappings??[]}async function q2(n){const l=await fetch(`${be}/api/settings/repository-mappings`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({mappings:n})});if(!l.ok)throw new Error(await Ge(l));return(await l.json()).mappings??[]}async function H2(){const n=await fetch(`${be}/api/agents`);if(!n.ok)throw new Error("Failed to fetch agents");return n.json()}async function $2(n){const l=await fetch(`${be}/api/agents`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(n)});if(!l.ok)throw new Error(await l.text());return l.json()}async function Y2(n,l){const s=await fetch(`${be}/api/agents/${n}`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify(l)});if(!s.ok)throw new Error(await s.text());return s.json()}async function V2(n){const l=await fetch(`${be}/api/agents/${n}`,{method:"DELETE"});if(!l.ok)throw new Error(await l.text())}async function Z2(n,l){return O2(n,async()=>{const u=await fetch(`${be}/api/runtimes/${n}/models`);if(!u.ok)throw new Error(await u.text());return u.json()})}async function av(){const n=await fetch(`${be}/api/runtime-capacity`);if(!n.ok)throw new Error(await n.text());return n.json()}async function nv(){const n=await fetch(`${be}/api/agent-deck/status`);if(!n.ok)throw new Error(await n.text());return n.json()}async function G2(){const n=await fetch(`${be}/api/host-power`);if(!n.ok)throw new Error(await n.text());return n.json()}async function Q2(){try{const n=await fetch(`${be}/api/agent-deck/decks`),l=await n.json().catch(()=>null);return n.ok?{ok:!0,decks:(l==null?void 0:l.data)??[]}:{ok:!1,code:l==null?void 0:l.code,message:(l==null?void 0:l.error)??`Agent Deck error (${n.status})`}}catch(n){return{ok:!1,message:n instanceof Error?n.message:String(n)}}}async function Ex(n){const l=new URLSearchParams,s=n.map(f=>f.trim()).filter(Boolean);s.length>0&&l.set("status",s.join(",")),l.set("page","1"),l.set("limit","1"),l.sort();const u=await fetch(`${be}/api/issues?${l.toString()}`);if(!u.ok)throw new Error(await Ge(u));const d=await u.json();return typeof d.total=="number"?d.total:0}async function X2(n){var u,d,f;const l=new URLSearchParams;(u=n.q)!=null&&u.trim()&&l.set("q",n.q.trim()),(d=n.status)!=null&&d.trim()&&l.set("status",n.status.trim()),(f=n.repo)!=null&&f.trim()&&l.set("repo",n.repo.trim()),n.needsAttention&&l.set("needsAttention","1"),l.set("page",String(n.page&&n.page>1?Math.floor(n.page):1)),l.sort();const s=await fetch(`${be}/api/issues?${l.toString()}`);if(!s.ok)throw new Error(await Ge(s));return s.json()}async function I2(){const n=await fetch(`${be}/api/issues/recent-repos`);if(!n.ok)throw new Error(await Ge(n));return(await n.json()).repos??[]}async function lv(n){const l=await fetch(`${be}/api/issues/${n}`);if(!l.ok)throw new Error(await Ge(l));return l.json()}async function K2(n){const l=await fetch(`${be}/api/issues/${n}/execution-analysis`);if(!l.ok)throw new Error(await Ge(l));return l.json()}async function J2(n){const l=await fetch(`${be}/api/issues/${n}/evidence`);if(!l.ok)throw new Error(await Ge(l));return l.json()}async function F2(n,l){const s=await fetch(`${be}/api/issues/${n}/artifacts/${l}/trace`);if(!s.ok)throw new Error(await Ge(s));return s.json()}async function W2(n){const l=await fetch(`${be}/api/issues`,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify(n)});if(!l.ok)throw new Error(await Ge(l));return l.json()}async function fu(n,l){const s=await fetch(`${be}/api/issues/${n}`,{method:"PATCH",headers:{"content-type":"application/json"},body:JSON.stringify(l)});if(!s.ok)throw new Error(await Ge(s));return s.json()}async function P2(n){const l=await fetch(`${be}/api/issues/${n}/reload-source`,{method:"POST"});if(!l.ok)throw new Error(await Ge(l));return l.json()}async function iv(n){const l=await fetch(`${be}/api/issues/${n}/start`,{method:"POST"});if(!l.ok)throw new Error(await Ge(l));return l.json()}async function sv(n){const l=await fetch(`${be}/api/issues/${n}/execute`,{method:"POST"});if(!l.ok)throw new Error(await Ge(l));return l.json()}async function eS(n,l="web"){const s=await fetch(`${be}/api/issues/${n}/abort`,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({resolvedBy:l})});if(!s.ok)throw new Error(await Ge(s));return s.json()}async function tS(n){const l=await fetch(`${be}/api/issues/${n}/park`,{method:"POST"});if(!l.ok)throw new Error(await Ge(l));return l.json()}async function aS(n,l="web"){const s=await fetch(`${be}/api/issues/${n}/close`,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({closedBy:l})});if(!s.ok)throw new Error(await Ge(s));return s.json()}async function nS(n){const l=await fetch(`${be}/api/issues/${n}`,{method:"DELETE"});if(!l.ok)throw new Error(await Ge(l));return l.json()}async function lS(n){const l=await fetch(`${be}/api/queue`,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({issueId:n})});if(!l.ok)throw new Error(await Ge(l));return l.json()}async function rv(n){const l=await fetch(`${be}/api/queue/${n}`,{method:"DELETE"});if(!l.ok)throw new Error(await Ge(l));return l.json()}async function nu(n,l){const s=await fetch(`${be}/api/queue/${n}/move`,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({to:l})});if(!s.ok)throw new Error(await Ge(s));return s.json()}async function dd(){const n=await fetch(`${be}/api/queue`);if(!n.ok)throw new Error(await Ge(n));return n.json()}async function iS(){const n=await fetch(`${be}/api/queue/status`);if(!n.ok)throw new Error(await Ge(n));return n.json()}async function sS(n){const l=await fetch(`${be}/api/queue/settings`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({maxActiveIssues:n})});if(!l.ok)throw new Error(await Ge(l));return l.json()}async function rS(n,l){const s=await fetch(`${be}/api/issues/${n}/guidance`,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({markdown:l})});if(!s.ok)throw new Error(await Ge(s));return s.json()}async function uS(n){const l=Fy(n),s=await fetch(`${be}/api/execution-report${l?`?${l}`:""}`);if(!s.ok)throw new Error(await Ge(s));const u=await s.json(),d=v2.safeParse(u);if(!d.success)throw new Error(`Unexpected report shape: ${d.error.message}`);return d.data}async function oS(){const n=await fetch(`${be}/api/human-actions`);if(!n.ok)throw new Error(await Ge(n));return n.json()}async function uv(n,l,s,u){const d=await fetch(`${be}/api/human-actions/${n}/resolve`,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify(u!=null&&u.trim()?{resolvedBy:l,choice:s,note:u.trim()}:{resolvedBy:l,choice:s})});if(!d.ok)throw new Error(await Ge(d));return d.json()}function cS(n){return n||zy}function dS({runtime:n,label:l,value:s,onChange:u,defaultModelId:d,disabled:f,compact:m}){const x=Ud(n),[y,v]=b.useState((x==null?void 0:x.models)??[]),[w,j]=b.useState((x==null?void 0:x.source)??"fallback"),[D,X]=b.useState(!x);b.useEffect(()=>{const L=Ud(n);if(L){v(L.models),j(L.source),X(!1);return}X(!0),Z2(n).then(H=>{v(H.models),j(H.source)}).catch(()=>v([])).finally(()=>X(!1))},[n]);const E=b.useMemo(()=>{var L,H;if(n==="cursor_local"){const F=cS(d);return((L=y.find(P=>P.id===F))==null?void 0:L.label)??"Auto (subscription pool)"}return d?((H=y.find(F=>F.id===d))==null?void 0:H.label)??d:"runtime default"},[n,d,y]),$=n==="cursor_local"?D?"Loading models…":`Agent default (${E})`:D?"Loading models…":`Default (${E})`;return r.jsxs("label",{className:"block space-y-1",children:[r.jsx("span",{className:"text-xs text-[#A8C4C0] uppercase",children:l}),r.jsxs("select",{className:"field text-sm",disabled:f||D,value:s,onChange:L=>u(L.target.value),children:[r.jsx("option",{value:"",children:$}),y.map(L=>r.jsx("option",{value:L.id,children:L.label},L.id))]}),n==="cursor_local"&&!D&&!m&&r.jsx("p",{className:"text-xs text-white/40",children:"Auto and Composer use your Cursor subscription pool. Other models draw API credits."}),w==="fallback"&&y.length>0&&!D&&n==="cursor_local"&&!m&&r.jsx("p",{className:"text-xs text-white/40",children:"Run cursor-agent login to load the full model list."})]})}function Cx(n){const l={};return n.allowWorktreeWrite||(l.worktreeWrite=!1),Object.keys(l).length?l:null}function fS(n){let l={};try{n!=null&&n.trim()&&(l=JSON.parse(n))}catch{l={}}return{allowWorktreeWrite:l.worktreeWrite!==!1}}function Rx({value:n,onChange:l,agentDeckOnline:s,disabled:u}){const[d,f]=b.useState([]),[m,x]=b.useState(null);b.useEffect(()=>{Q2().then(w=>{w.ok?(f(w.decks),x(null)):(f([]),x(w.message))})},[]);const y=w=>l({...n,...w}),v=n.runtime==="codex_local"||n.runtime==="claude_code";return r.jsxs("div",{className:"space-y-2",children:[r.jsx("div",{className:"font-ui-display text-base uppercase tracking-wide text-[#92E4DD]",children:"Agent"}),r.jsx("label",{className:"text-xs text-[#A8C4C0] uppercase",children:"Runtime (required)"}),r.jsxs("select",{className:"field",disabled:u,value:n.runtime,onChange:w=>{const j=w.target.value;y({runtime:j,defaultModel:j==="cursor_local"?zy:j==="muse_code"?iw:"",defaultEffort:j==="cursor_local"||j==="muse_code"?"":n.defaultEffort})},children:[r.jsx("option",{value:"claude_code",children:"Claude Code (claude -p)"}),r.jsx("option",{value:"cursor_local",children:"Cursor local (cursor-agent -p)"}),r.jsx("option",{value:"codex_local",children:"Codex local (codex exec)"}),r.jsx("option",{value:"muse_code",children:"Muse Code (muse exec) — developer only, trial"})]}),r.jsx("label",{className:"text-xs text-[#A8C4C0] uppercase",children:"Agent Deck (required)"}),r.jsxs("select",{className:"field",disabled:u||!s||!!m,value:n.deckId,onChange:w=>y({deckId:w.target.value}),required:!0,children:[r.jsx("option",{value:"",disabled:!!n.deckId,children:s?m?"Agent Deck error — see below":"Select a deck…":"Agent Deck offline"}),d.map(w=>r.jsxs("option",{value:w.id,children:["◆ ",w.name]},w.id))]}),s&&m&&r.jsx("p",{className:"text-xs text-amber-300/90",children:m}),r.jsxs("div",{className:"pt-2 mt-2 border-t border-white/10 space-y-2",children:[r.jsx("div",{className:"font-ui-display text-xs uppercase tracking-wide text-white/40",children:"Issue-centric session defaults"}),r.jsxs("label",{className:"block space-y-1",children:[r.jsx("span",{className:"text-xs text-[#A8C4C0] uppercase",children:"Purpose (optional)"}),r.jsx("input",{className:"field text-sm",placeholder:"e.g. backend refactors on the payments service",disabled:u,value:n.purpose,onChange:w=>y({purpose:w.target.value})})]}),r.jsxs("div",{className:`grid gap-2 ${v?"grid-cols-2":"grid-cols-1"}`,children:[r.jsx(dS,{runtime:n.runtime,label:"Default model",value:n.defaultModel,onChange:w=>y({defaultModel:w}),disabled:u,compact:!0}),v&&r.jsxs("label",{className:"space-y-1",children:[r.jsx("span",{className:"text-xs text-[#A8C4C0] uppercase",children:"Reasoning effort"}),r.jsxs("select",{className:"field text-sm",disabled:u,value:n.defaultEffort,onChange:w=>y({defaultEffort:w.target.value}),children:[r.jsx("option",{value:"",children:"Runtime default"}),r.jsx("option",{value:"low",children:"Low"}),r.jsx("option",{value:"medium",children:"Medium"}),r.jsx("option",{value:"high",children:"High"})]})]})]}),n.runtime==="muse_code"&&r.jsx("p",{className:"text-xs text-white/40",children:"Developer role only — keep a Claude or Codex agent as the reviewer. The developer session receives the selected deck above. Contributor-tier content may be used for product improvement; use it on non-sensitive tickets."}),n.runtime==="cursor_local"&&r.jsx("p",{className:"text-xs text-white/40",children:"Cursor has no separate effort flag — put effort in the model id if needed (e.g. parameterized `[effort=high]`)."}),r.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[r.jsxs("label",{className:"space-y-1",children:[r.jsx("span",{className:"text-xs text-[#A8C4C0] uppercase",children:"Max turns"}),r.jsx("input",{className:"field text-sm",type:"number",min:1,placeholder:"none",disabled:u,value:n.defaultBudget.maxTurns,onChange:w=>y({defaultBudget:{...n.defaultBudget,maxTurns:w.target.value}})})]}),r.jsxs("label",{className:"space-y-1",children:[r.jsx("span",{className:"text-xs text-[#A8C4C0] uppercase",children:"Max $ / session"}),r.jsx("input",{className:"field text-sm",type:"number",min:0,step:"0.1",placeholder:"none",disabled:u,value:n.defaultBudget.maxBudgetUsd,onChange:w=>y({defaultBudget:{...n.defaultBudget,maxBudgetUsd:w.target.value}})})]})]}),r.jsxs("div",{className:"space-y-1",children:[r.jsx("span",{className:"text-xs text-[#A8C4C0] uppercase",children:"Developer capabilities"}),r.jsx("div",{className:"flex flex-wrap gap-x-4 gap-y-1 text-sm text-white/70",children:r.jsxs("label",{className:"flex items-center gap-1.5",children:[r.jsx("input",{type:"checkbox",disabled:u,checked:n.allowWorktreeWrite,onChange:w=>y({allowWorktreeWrite:w.target.checked})}),"Write files"]})}),r.jsx("p",{className:"text-xs text-white/40",children:"Unchecking runs the developer read-only (no Write/Edit/Bash grant), same as a reviewer. There is no separate push / open-PR toggle — a session with file-write access can already push and open PRs, and no mechanism here can restrict just that without also removing write access."})]})]})]})}function Aa(n){return n==="claude_code"?"Claude":n==="cursor_local"?"Cursor":n==="codex_local"?"Codex":n==="muse_code"?"Muse Code":"No agent"}function hS(){return{maxTurns:"",maxBudgetUsd:""}}function Tx(n){const l=n.maxTurns.trim()?Number(n.maxTurns):null,s=n.maxBudgetUsd.trim()?Number(n.maxBudgetUsd):null;return l==null&&s==null||l!=null&&(!Number.isFinite(l)||l<=0)||s!=null&&(!Number.isFinite(s)||s<=0)?null:{maxTurns:l,maxBudgetUsd:s}}function mS(n){const l=du(n);return{maxTurns:(l==null?void 0:l.maxTurns)!=null?String(l.maxTurns):"",maxBudgetUsd:(l==null?void 0:l.maxBudgetUsd)!=null?String(l.maxBudgetUsd):""}}function Ts({children:n,className:l="",title:s}){return r.jsx("span",{title:s,className:`inline-flex items-center gap-1 rounded px-2 py-0.5 text-xs font-medium uppercase tracking-wide border ${l}`,children:n})}function lu(n,l){const s=n.find(d=>d.runtime===l);if(!s)return{ok:!1,detail:"no agent"};const u=s.issues.find(d=>d.code==="cli_missing"||d.code==="runtime_auth"||d.code==="runtime_unknown"||d.code==="runtime_capability"||d.code==="cursor_keychain");return u?{ok:!1,detail:u.message}:{ok:!0,detail:"CLI ready"}}function pS(n){const l=n.flatMap(s=>s.issues).find(s=>s.code==="github_cli_missing"||s.code==="github_auth"||s.code==="github_unreachable");return l?{ok:!1,detail:l.message}:n.length===0?{ok:!1,detail:"no agent"}:{ok:!0,detail:"gh ready"}}function Ei({ok:n}){return r.jsx("span",{className:`inline-block w-1.5 h-1.5 rounded-full shrink-0 ${n?"bg-emerald-400":"bg-amber-400"}`,"aria-hidden":!0})}function xS({agents:n,agentDeckOnline:l}){const[s,u]=b.useState(null);b.useEffect(()=>{nv().then(w=>u(w.mcpUrl)).catch(()=>u(null))},[l]);const d=lu(n,"claude_code"),f=lu(n,"cursor_local"),m=lu(n,"codex_local"),x=n.some(w=>w.runtime==="muse_code")?lu(n,"muse_code"):null,y=pS(n),v=n.flatMap(w=>w.issues).find(w=>w.code==="mcp_not_registered");return r.jsxs("div",{className:"flex flex-wrap items-center justify-end gap-x-4 gap-y-1.5 text-xs text-white/45",children:[r.jsx("span",{className:"uppercase tracking-wider text-white/30",children:"Connections"}),r.jsxs("span",{className:"inline-flex items-center gap-1.5",title:d.detail,children:[r.jsx(Ei,{ok:d.ok}),r.jsx("span",{className:d.ok?"text-white/55":"text-amber-200/90",children:"Claude"})]}),r.jsxs("span",{className:"inline-flex items-center gap-1.5",title:f.detail,children:[r.jsx(Ei,{ok:f.ok}),r.jsx("span",{className:f.ok?"text-white/55":"text-amber-200/90",children:"Cursor"})]}),r.jsxs("span",{className:"inline-flex items-center gap-1.5",title:m.detail,children:[r.jsx(Ei,{ok:m.ok}),r.jsx("span",{className:m.ok?"text-white/55":"text-amber-200/90",children:"Codex"})]}),x&&r.jsxs("span",{className:"inline-flex items-center gap-1.5",title:x.detail,children:[r.jsx(Ei,{ok:x.ok}),r.jsx("span",{className:x.ok?"text-white/55":"text-amber-200/90",children:"Muse Code"})]}),r.jsxs("span",{className:"inline-flex items-center gap-1.5",title:y.detail,children:[r.jsx(Ei,{ok:y.ok}),r.jsx("span",{className:y.ok?"text-white/55":"text-amber-200/90",children:"GitHub"})]}),r.jsxs("span",{className:"inline-flex items-center gap-1.5",title:(v==null?void 0:v.message)??(s?`MCP ${s}`:"Agent Deck optional"),children:[r.jsx(Ei,{ok:l&&!v}),r.jsxs("span",{className:l&&!v?"text-[#92E4DD]/80":v?"text-amber-200/90":"text-white/35",children:["Agent Deck MCP",l?v?" (setup needed)":"":" (optional)"]})]})]})}function ov(n){return n<10?"critical":n<30?"warning":"normal"}function cv(n){const l=n.unavailableDetail;if(!l)return null;const s=l.consecutiveFailures,u=new Date(l.firstFailureAt).toLocaleString();return`unavailable: ${l.message} (${s} consecutive failed refresh${s===1?"":"es"} since ${u})`}const nf={unsupported:"not reported by provider",missing:"no data yet",expired:"expired",unparsable:"provider data unparsable",stale:"stale"},yS={critical:"font-bold text-red-400",warning:"text-yellow-400",normal:"font-medium"},vS=new Set(["claude_code","codex_local","muse_code"]),gS="billing_cycle",bS="1M",wS="5H",SS="1W";function Ox(n,l,s,u){if(n!==null)return dv(n,l,null);const d=s??"missing";return{key:u,label:l,kind:"unknown",reason:d,title:`${l}: N/A (${nf[d]})`}}function dv(n,l,s){if(n.unavailableReason===null&&n.remainingPercent!==null){const d=n.remainingPercent,f=n.resetAt?`, resets ${new Date(n.resetAt).toLocaleString()}`:"",m=s?`, ${s}`:"";return{key:n.windowKey,label:l,kind:"known",remaining:Math.round(d),rawRemaining:d,title:`${l}: ${Math.round(d)}% remaining${m}${f}`}}const u=n.unavailableReason??"missing";return{key:n.windowKey,label:l,kind:"unknown",reason:u,title:`${l}: N/A (${cv(n)??nf[u]})`}}function jS(n){if(n.runtime==="cursor_local"){const l=n.windows.find(s=>s.windowKey===gS)??null;return l===null?[]:[dv(l,bS,"current billing cycle")]}if(vS.has(n.runtime)){const l=n.windows.find(u=>u.criticalRole==="five_hour")??null,s=n.windows.find(u=>u.criticalRole==="weekly")??null;return[Ox(l,wS,n.unavailableReason,"missing-5H"),Ox(s,SS,n.unavailableReason,"missing-1W")]}return[]}function NS({row:n}){const l=n.kind==="known";return r.jsxs("span",{"data-testid":`capacity-window-${n.key}`,"data-reason":n.kind==="unknown"?n.reason:void 0,title:n.title,className:`inline-flex items-center gap-1 rounded border px-1.5 py-0.5 whitespace-nowrap ${l?"border-white/15 bg-white/5 text-white/70":"border-white/10 bg-transparent text-white/35"}`,children:[r.jsx("span",{className:"text-white/40",children:n.label}),n.kind==="known"?(()=>{const s=ov(n.rawRemaining);return r.jsxs("span",{"data-severity":s,className:yS[s],children:[n.remaining,"%"]})})():r.jsx("span",{children:"N/A"})]})}function _S({data:n}){return n.runtimes.length===0?null:r.jsxs("div",{"data-testid":"runtime-capacity-strip",className:"flex flex-wrap items-center gap-x-4 gap-y-1.5 text-xs",children:[r.jsx("span",{className:"uppercase tracking-wider text-white/30",children:"Runtime capacity"}),n.runtimes.map(l=>{const s=jS(l);return r.jsxs("span",{"data-testid":`capacity-entry-${l.runtime}`,className:"inline-flex min-w-0 flex-wrap items-center gap-1.5",children:[r.jsx("span",{className:"shrink-0 whitespace-nowrap font-medium text-white/55",children:Aa(l.runtime)}),s.length===0?r.jsx("span",{"data-testid":`capacity-entry-${l.runtime}-na`,"data-reason":l.unavailableReason??"missing",title:`N/A (${nf[l.unavailableReason??"missing"]})`,className:"whitespace-nowrap text-white/35",children:"N/A"}):s.map(u=>r.jsx(NS,{row:u},u.key))]},l.runtime)})]})}function kS({refreshTick:n}){const[l,s]=b.useState(null);return b.useEffect(()=>{let u=!1;return av().then(d=>{u||s(d)}).catch(()=>{u||s(null)}),()=>{u=!0}},[n]),l?r.jsx(_S,{data:l}):null}const AS="agent-dealer:host-power-sleep-notice-dismissed:";function fv(n){return`${AS}${n}`}function Lx(n){if(typeof localStorage>"u")return!1;try{return localStorage.getItem(fv(n))==="1"}catch{return!1}}function ES(n){if(!(typeof localStorage>"u"))try{localStorage.setItem(fv(n),"1")}catch{}}function CS({status:n}){const[l,s]=b.useState(()=>Lx(n.serverInstanceId));b.useEffect(()=>{s(Lx(n.serverInstanceId))},[n.serverInstanceId]);const u=n.sleepTimerNotice,d=!!u&&!l,f=()=>{ES(n.serverInstanceId),s(!0)};return r.jsxs("div",{className:"space-y-2","data-testid":"host-power-status",children:[r.jsx("p",{className:"text-xs text-white/45 font-mono","data-testid":"host-power-hold-line",children:n.holdStatusLine}),d&&u&&r.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-2 rounded border border-amber-400/25 bg-amber-500/10 px-3 py-2 text-xs text-amber-100/90","data-testid":"host-power-sleep-notice",role:"status",children:[r.jsx("p",{className:"min-w-0 flex-1 leading-relaxed font-mono",children:u.message}),r.jsx("button",{type:"button",onClick:f,className:"shrink-0 text-amber-100/70 hover:text-amber-50 underline-offset-2 hover:underline","data-testid":"host-power-sleep-notice-dismiss",children:"Dismiss"})]})]})}function RS({status:n,pollMs:l=5e3}){const[s,u]=b.useState(n??null);return b.useEffect(()=>{if(n!==void 0){u(n);return}let d=!1;const f=()=>{G2().then(x=>{d||u(x)}).catch(()=>{d||u(null)})};f();const m=setInterval(f,l);return()=>{d=!0,clearInterval(m)}},[n,l]),s?r.jsx(CS,{status:s}):null}const TS="data:image/svg+xml,%3csvg%20viewBox='0%200%20248%20248'%20fill='none'%20xmlns='http://www.w3.org/2000/svg'%20aria-hidden='true'%3e%3cpath%20d='M52.4285%20162.873L98.7844%20136.879L99.5485%20134.602L98.7844%20133.334H96.4921L88.7237%20132.862L62.2346%20132.153L39.3113%20131.207L17.0249%20130.026L11.4214%20128.844L6.2%20121.873L6.7094%20118.447L11.4214%20115.257L18.171%20115.847L33.0711%20116.911L55.485%20118.447L71.6586%20119.392L95.728%20121.873H99.5485L100.058%20120.337L98.7844%20119.392L97.7656%20118.447L74.5877%20102.732L49.4995%2086.1905L36.3823%2076.62L29.3779%2071.7757L25.8121%2067.2858L24.2839%2057.3608L30.6515%2050.2716L39.3113%2050.8623L41.4763%2051.4531L50.2636%2058.1879L68.9842%2072.7209L93.4357%2090.6804L97.0015%2093.6343L98.4374%2092.6652L98.6571%2091.9801L97.0015%2089.2625L83.757%2065.2772L69.621%2040.8192L63.2534%2030.6579L61.5978%2024.632C60.9565%2022.1032%2060.579%2020.0111%2060.579%2017.4246L67.8381%207.49965L71.9133%206.19995L81.7193%207.49965L85.7946%2011.0443L91.9074%2024.9865L101.714%2046.8451L116.996%2076.62L121.453%2085.4816L123.873%2093.6343L124.764%2096.1155H126.292V94.6976L127.566%2077.9197L129.858%2057.3608L132.15%2030.8942L132.915%2023.4505L136.608%2014.4708L143.994%209.62643L149.725%2012.344L154.437%2019.0788L153.8%2023.4505L150.998%2041.6463L145.522%2070.1215L141.957%2089.2625H143.994L146.414%2086.7813L156.093%2074.0206L172.266%2053.698L179.398%2045.6635L187.803%2036.802L193.152%2032.5484H203.34L210.726%2043.6549L207.415%2055.1159L196.972%2068.3492L188.312%2079.5739L175.896%2096.2095L168.191%20109.585L168.882%20110.689L170.738%20110.53L198.755%20104.504L213.91%20101.787L231.994%2098.7149L240.144%20102.496L241.036%20106.395L237.852%20114.311L218.495%20119.037L195.826%20123.645L162.07%20131.592L161.696%20131.893L162.137%20132.547L177.36%20133.925L183.855%20134.279H199.774L229.447%20136.524L237.215%20141.605L241.8%20147.867L241.036%20152.711L229.065%20158.737L213.019%20154.956L175.45%20145.977L162.587%20142.787H160.805V143.85L171.502%20154.366L191.242%20172.089L215.82%20195.011L217.094%20200.682L213.91%20205.172L210.599%20204.699L188.949%20188.394L180.544%20181.069L161.696%20165.118H160.422V166.772L164.752%20173.152L187.803%20207.771L188.949%20218.405L187.294%20221.832L181.308%20223.959L174.813%20222.777L161.187%20203.754L147.305%20182.486L136.098%20163.345L134.745%20164.2L128.075%20235.42L125.019%20239.082L117.887%20241.8L111.902%20237.31L108.718%20229.984L111.902%20215.452L115.722%20196.547L118.779%20181.541L121.58%20162.873L123.291%20156.636L123.14%20156.219L121.773%20156.449L107.699%20175.752L86.304%20204.699L69.3663%20222.777L65.291%20224.431L58.2867%20220.768L58.9235%20214.27L62.8713%20208.48L86.304%20178.705L100.44%20160.155L109.551%20149.507L109.462%20147.967L108.959%20147.924L46.6977%20188.512L35.6182%20189.93L30.7788%20185.44L31.4156%20178.115L33.7079%20175.752L52.4285%20162.873Z'%20fill='%23D97757'/%3e%3c/svg%3e",OS="/assets/codex-YZSpL-SB.png",LS="data:image/svg+xml,%3csvg%20viewBox='0%200%2024%2024'%20fill='none'%20xmlns='http://www.w3.org/2000/svg'%20aria-hidden='true'%3e%3cpath%20fill='%23EDEDED'%20d='M11.503.131%201.891%205.678a.84.84%200%200%200-.42.726v11.188c0%20.3.162.575.42.724l9.609%205.55a1%201%200%200%200%20.998%200l9.61-5.55a.84.84%200%200%200%20.42-.724V6.404a.84.84%200%200%200-.42-.726L12.497.131a1.01%201.01%200%200%200-.996%200M2.657%206.338h18.55c.263%200%20.43.287.297.515L12.23%2022.918c-.062.107-.229.064-.229-.06V12.335a.59.59%200%200%200-.295-.51l-9.11-5.257c-.109-.063-.064-.23.061-.23'/%3e%3c/svg%3e",MS="/assets/muse-CtdcC6ve.svg";function Hu({src:n,className:l}){return r.jsx("span",{className:`inline-flex items-center justify-center rounded-lg bg-white/[0.04] ${l??"h-8 w-8"}`,children:r.jsx("img",{src:n,alt:"",className:"h-[70%] w-[70%] object-contain",draggable:!1})})}function DS({className:n="h-8 w-8"}){return r.jsx(Hu,{src:TS,className:n})}function US({className:n="h-8 w-8"}){return r.jsx(Hu,{src:LS,className:n})}function zS({className:n="h-8 w-8"}){return r.jsxs("svg",{viewBox:"0 0 32 32",fill:"none",xmlns:"http://www.w3.org/2000/svg",className:n,"aria-hidden":!0,children:[r.jsx("rect",{width:"32",height:"32",rx:"8",fill:"white",fillOpacity:"0.06"}),r.jsx("circle",{cx:"16",cy:"13",r:"4.5",stroke:"#92E4DD",strokeWidth:"1.75"}),r.jsx("path",{d:"M8.5 24.5c1.2-3.5 3.8-5.5 7.5-5.5s6.3 2 7.5 5.5",stroke:"#92E4DD",strokeWidth:"1.75",strokeLinecap:"round"})]})}function BS({className:n="h-8 w-8"}){return r.jsx(Hu,{src:OS,className:n})}function qS({className:n="h-8 w-8"}){return r.jsx(Hu,{src:MS,className:n})}function hv({runtime:n,className:l="h-8 w-8 shrink-0"}){return n==="claude_code"?r.jsx(DS,{className:l}):n==="cursor_local"?r.jsx(US,{className:l}):n==="codex_local"?r.jsx(BS,{className:l}):n==="muse_code"?r.jsx(qS,{className:l}):r.jsx(zS,{className:l})}const iu=()=>({runtime:"claude_code",deckId:"",purpose:"",defaultModel:"",defaultEffort:"",defaultBudget:hS(),allowWorktreeWrite:!0});function HS({agents:n,agentDeckOnline:l,onRefresh:s}){const[u,d]=b.useState(!1),[f,m]=b.useState(""),[x,y]=b.useState(iu()),[v,w]=b.useState(!1),[j,D]=b.useState(null),[X,E]=b.useState(""),[$,L]=b.useState(iu()),H=async I=>{if(I.preventDefault(),!(!f.trim()||!x.deckId)){w(!0);try{const ye={name:f.trim(),runtime:x.runtime,deckId:x.deckId,defaultModel:x.defaultModel.trim()||null,defaultEffort:x.defaultEffort||null,defaultBudget:Tx(x.defaultBudget),purpose:x.purpose.trim()||null,permissionPolicy:Cx(x)};await $2(ye),m(""),y(iu()),d(!1),s()}catch(ye){alert(String(ye))}finally{w(!1)}}},F=I=>{D(I.id),E(I.name),L({runtime:I.runtime,deckId:I.deckId??"",purpose:I.purpose??"",defaultModel:Nx(I)??"",defaultEffort:I.defaultEffort??"",defaultBudget:mS(uw(I)),...fS(I.permissionPolicyJson)})},P=()=>{D(null),L(iu())},ne=async I=>{if(!(!X.trim()||!$.deckId)){w(!0);try{const ye={name:X.trim(),runtime:$.runtime,deckId:$.deckId,defaultModel:$.defaultModel.trim()||null,defaultEffort:$.defaultEffort||null,defaultBudget:Tx($.defaultBudget),purpose:$.purpose.trim()||null,permissionPolicy:Cx($)};await Y2(I.id,ye),P(),s()}catch(ye){alert(String(ye))}finally{w(!1)}}},V=async I=>{if(confirm(`Delete agent "${I.name}"?`)){w(!0);try{await V2(I.id),s()}catch(ye){alert(String(ye))}finally{w(!1)}}},Ne=n.filter(I=>!I.healthy).length;return r.jsxs("div",{className:"flex-1 overflow-y-auto px-6 py-4 max-w-6xl mx-auto w-full",children:[r.jsxs("div",{className:"mb-6 flex flex-col sm:flex-row sm:items-start sm:justify-between gap-4",children:[r.jsxs("div",{className:"min-w-0",children:[r.jsx("h1",{className:"heading-page",children:"Agents"}),r.jsx("p",{className:"text-sm text-white/50 mt-1",children:"Saved execution profiles — pick one when creating an issue instead of configuring each task"}),r.jsxs("p",{className:"text-sm text-white/45 mt-2",children:[n.length," agent",n.length===1?"":"s",Ne>0&&r.jsxs("span",{className:"text-red-400 ml-2",children:["· ",Ne," need",Ne===1?"s":""," attention"]})]})]}),r.jsx(xS,{agents:n,agentDeckOnline:l})]}),r.jsxs("div",{className:"mb-4 overflow-x-auto space-y-2",children:[r.jsx(kS,{}),r.jsx(RS,{})]}),r.jsx("div",{className:"space-y-3 mb-6",children:n.map(I=>{const ye=Nx(I);return r.jsxs("div",{className:"panel flex flex-col sm:flex-row sm:items-start gap-3 justify-between",children:[r.jsxs("div",{className:"flex gap-3 min-w-0 flex-1",children:[r.jsx(hv,{runtime:I.runtime}),r.jsxs("div",{className:"space-y-2 min-w-0 flex-1",children:[r.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[r.jsx("span",{className:"text-lg font-semibold text-[#E8F6F4]",children:I.name}),!I.healthy&&r.jsx(Ts,{className:"bg-red-500/15 text-red-300 border-red-400/30 normal-case",children:"Needs fix"})]}),r.jsxs("div",{className:"flex flex-wrap gap-1.5",children:[r.jsx(Ts,{className:"bg-white/5 text-white/55 border-white/15 normal-case",children:Aa(I.runtime)}),I.deckName?r.jsxs(Ts,{className:"bg-[#92E4DD]/10 text-[#92E4DD] border-[#92E4DD]/25 normal-case",children:["◆ ",I.deckName]}):r.jsx(Ts,{className:"bg-white/5 text-white/40 border-white/10 normal-case",children:"No deck"}),ye&&r.jsx(Ts,{className:"bg-white/5 text-white/50 border-white/10 normal-case truncate max-w-[10rem]",title:ye,children:ye})]}),j===I.id&&r.jsxs("div",{className:"space-y-3 pt-2 border-t border-white/10",children:[r.jsxs("label",{className:"block space-y-1",children:[r.jsx("span",{className:"text-xs text-[#A8C4C0] uppercase",children:"Name"}),r.jsx("input",{className:"field text-sm",value:X,onChange:Me=>E(Me.target.value)})]}),r.jsx(Rx,{value:$,onChange:L,agentDeckOnline:l}),r.jsxs("div",{className:"flex gap-2 pt-1",children:[r.jsx("button",{type:"button",disabled:v||!X.trim()||!$.deckId,onClick:()=>ne(I),className:"btn-gold text-sm px-3 py-1.5",children:"Save"}),r.jsx("button",{type:"button",onClick:P,className:"btn-ghost text-sm px-3 py-1.5",children:"Cancel"})]})]}),I.issues.length>0&&r.jsx("ul",{className:"text-sm text-red-300/90 space-y-1",children:I.issues.map((Me,bt)=>r.jsxs("li",{children:["· ",Me.message]},bt))})]})]}),r.jsxs("div",{className:"flex gap-2 shrink-0",children:[j!==I.id&&r.jsx("button",{type:"button",disabled:v,onClick:()=>F(I),className:"btn-ghost text-sm px-3 py-1.5",children:"Edit"}),r.jsx("button",{type:"button",disabled:v,onClick:()=>V(I),className:"btn-ghost text-sm px-3 py-1.5",children:"Delete"})]})]},I.id)})}),u?r.jsxs("form",{onSubmit:H,className:"panel space-y-3",children:[r.jsx("h2",{className:"heading-panel",children:"New Agent"}),r.jsxs("label",{className:"block space-y-1",children:[r.jsx("span",{className:"text-xs text-[#A8C4C0] uppercase",children:"Name"}),r.jsx("input",{className:"field",placeholder:"e.g. Claude · Work",value:f,onChange:I=>m(I.target.value)})]}),r.jsx(Rx,{value:x,onChange:y,agentDeckOnline:l}),r.jsxs("div",{className:"flex gap-2",children:[r.jsx("button",{type:"submit",disabled:v||!f.trim()||!x.deckId,className:"btn-gold px-4 py-2",children:v?"Saving…":"Create agent"}),r.jsx("button",{type:"button",onClick:()=>d(!1),className:"btn-ghost px-4 py-2",children:"Cancel"})]})]}):r.jsx("button",{type:"button",onClick:()=>d(!0),className:"btn-gold px-4 py-2",children:"Add agent"})]})}function $S(n){try{return Wd(n).identity}catch{return null}}function YS(n,l){return n!=="linear"||!l?null:l.repoResolution??Ly(l.labels)}function VS(n,l){if(!l)return n;const s=l.repoResolution??Ly(l.labels);return s.status==="resolved"&&s.repository?s.repository:n}function ZS(n,l){var u;const s=YS(n,l);if(!s)return null;if(s.status==="conflict")return`Conflicting repo: labels (${(s.labels??[]).join(", ")}) — kept the current repository. Fix the labels in Linear or type a repository below.`;if(s.status==="invalid"){const d=((u=s.labels)==null?void 0:u[0])??"repo:",f=s.error?` — ${s.error}`:"";return`Invalid repository label ${d}${f}. Kept the current repository — fix the label in Linear or type a repository below.`}return null}function Mx(n){return n.title.trim().length>0&&$S(n.repo)!=null&&n.developerAgentId.length>0&&n.reviewerAgentId.length>0}function GS(n,l,s){const u=s?n.find(d=>d.id===s):void 0;return u&&!l.some(d=>d.id===u.id)?[u,...l]:[...l]}function QS(n,l){return{candidates:[l,...n.filter(s=>s.id!==l.id)],selectedId:l.id}}const fd=["ready","developing","reviewing","repairing","final_review","needs_human","done","closed"],XS={q:"",status:"",repo:"",needsAttention:!1};function lf(n){return n.startsWith("?")?n.slice(1):n}function Dx(n){var s,u,d;const l=new URLSearchParams(lf(n));return{q:((s=l.get("q"))==null?void 0:s.trim())??"",status:((u=l.get("status"))==null?void 0:u.trim())??"",repo:((d=l.get("repo"))==null?void 0:d.trim())??"",needsAttention:l.get("needsAttention")==="1"||l.get("needsAttention")==="true"}}function IS(n){const l=new URLSearchParams(lf(n)),s=y=>{var w;const v=(w=l.get(y))==null?void 0:w.trim();return v||void 0},u={},d=s("q");d!==void 0&&(u.q=d);const f=s("status");f!==void 0&&(u.status=f);const m=s("repo");m!==void 0&&(u.repo=m),(l.get("needsAttention")==="1"||l.get("needsAttention")==="true")&&(u.needsAttention=!0);const x=Number(l.get("page"));return Number.isInteger(x)&&x>=1&&(u.page=x),u}function KS(n){var s,u,d;const l=new URLSearchParams;return(s=n.q)!=null&&s.trim()&&l.set("q",n.q.trim()),(u=n.status)!=null&&u.trim()&&l.set("status",n.status.trim()),(d=n.repo)!=null&&d.trim()&&l.set("repo",n.repo.trim()),n.needsAttention&&l.set("needsAttention","1"),n.page!==void 0&&Number.isInteger(n.page)&&n.page>1&&l.set("page",String(n.page)),l.sort(),l.toString()}function JS(n){const l={};return n.q.trim()&&(l.q=n.q.trim()),n.status.trim()&&(l.status=n.status.trim()),n.repo.trim()&&(l.repo=n.repo.trim()),n.needsAttention&&(l.needsAttention=!0),l}function FS(n,l){const s=new URLSearchParams(lf(n));return l<=1?s.delete("page"):s.set("page",String(Math.floor(l))),s.sort(),s.toString()}function Ux(n){if(n.total===0)return"No issues match these filters";const l=(n.page-1)*n.limit+1,s=Math.min(n.total,n.page*n.limit);return`Showing ${l}–${s} of ${n.total} issues`}function zx(n){return n.totalPages<=1?"":`Page ${n.page} of ${n.totalPages}`}function Bx(n){return!!(n.q||n.status||n.repo||n.needsAttention)}const WS={ready:"bg-white/10 text-white/70 border-white/20",developing:"bg-cyber-violet/20 text-cyber-violet-light border-cyber-violet/40",reviewing:"bg-cyber-gold/20 text-[#E8DC7A] border-cyber-gold/40",repairing:"bg-cyber-violet/25 text-cyber-violet-light border-cyber-violet/50",final_review:"bg-amber-500/20 text-amber-300 border-amber-400/40",needs_human:"bg-red-500/20 text-red-300 border-red-400/40",done:"bg-cyber-teal/20 text-cyber-teal border-cyber-teal/40",closed:"bg-white/5 text-white/40 border-white/10"},PS={ready:"Ready",developing:"Developing",reviewing:"Reviewing",repairing:"Repairing",final_review:"Final review",needs_human:"Needs human",done:"Done",closed:"Closed"};function mv({status:n}){return r.jsx("span",{className:`text-xs leading-none px-2 py-1 rounded border tabular-nums ${WS[n]}`,children:PS[n]})}const pv="agent-dealer:first-issue-dismissed:v1";function ej(n){return n.healthy}function tj(n){return n.healthy&&n.runtime!=="muse_code"}function aj(n){const l=n.some(ej),s=n.some(tj);return l&&s?"new-issue":"agents"}function nj(n){return n.historyTotal===0&&!n.filtersActive&&!n.dismissed}function xv(){try{return typeof localStorage>"u"?null:localStorage}catch{return null}}function lj(n=xv()){try{return(n==null?void 0:n.getItem(pv))==="1"}catch{return!1}}function ij(n=xv()){try{n==null||n.setItem(pv,"1")}catch{}}function sj({agents:n,onStartIssue:l,onDismiss:s}){const u=aj(n);return r.jsx("section",{"aria-label":"Create your first issue","data-testid":"first-issue-strip",className:"mb-4 rounded border border-[#C4B643]/40 bg-[#C4B643]/5 px-4 py-3",children:r.jsxs("div",{className:"flex items-start gap-3",children:[r.jsxs("div",{className:"flex-1 min-w-0",children:[r.jsx("p",{className:"font-ui-display text-sm font-medium text-white/90",children:"Create your first issue"}),r.jsx("p",{className:"mt-1 text-sm text-white/60",children:"Connect a developer and a reviewer agent, pick a GitHub repository, then create the issue. Capacity status in the header is informational — it never blocks creating an issue."}),r.jsxs("div",{className:"mt-2 flex flex-wrap items-center gap-2",children:[u==="agents"?r.jsx(sa,{to:"/agents","data-testid":"first-issue-primary",className:"btn-gold px-4 py-2 text-sm",children:"Configure agents"}):r.jsx("button",{type:"button","data-testid":"first-issue-primary",className:"btn-gold px-4 py-2 text-sm",onClick:l,children:"New issue"}),u==="agents"&&r.jsx("span",{className:"text-xs text-white/40",children:"then pick a repository and create the issue"})]})]}),r.jsx("button",{type:"button","aria-label":"Dismiss first-issue guide",title:"Dismiss",onClick:s,className:"shrink-0 rounded px-2 py-1 text-sm text-white/40 hover:text-white focus-visible:outline focus-visible:outline-2 focus-visible:outline-cyber-teal/45",children:"✕"})]})})}function yv({value:n,onChange:l,recentRepos:s=[],id:u}){return r.jsxs("div",{className:"space-y-1",children:[s.length>0&&r.jsxs("select",{className:"w-full bg-black/30 border border-white/10 rounded px-3 py-2 text-sm",value:s.includes(n)?n:"",onChange:d=>{d.target.value&&l(d.target.value)},"aria-label":"Recent repositories",children:[r.jsx("option",{value:"",children:"Recent repositories…"}),s.map(d=>r.jsx("option",{value:d,children:d},d))]}),r.jsx("input",{id:u,className:"w-full bg-black/30 border border-white/10 rounded px-3 py-2 text-sm",placeholder:"GitHub URL or owner/repo",value:n,onChange:d=>l(d.target.value)})]})}function rj(){return{label:"",repository:""}}function uj(n){const l=new Set;for(const s of n){const u=s.label.trim();if(!u)return"Labels must not be empty";if(u.length>100)return`Label "${u}" must be 1–100 characters`;const d=u.toLowerCase();if(l.has(d))return`Duplicate label "${u}"`;if(l.add(d),!s.repository.trim())return`Repository for "${u}" must not be empty`}return n.length>100?"At most 100 mappings are allowed":null}function oj({recentRepos:n=[],initialMappings:l,loadMappings:s=B2,saveMappings:u=q2,onClose:d}){const[f,m]=b.useState(l??[]),[x,y]=b.useState(l!==void 0),[v,w]=b.useState(null),[j,D]=b.useState(null),[X,E]=b.useState(!1);b.useEffect(()=>{if(l!==void 0)return;let H=!0;return s().then(F=>{H&&(m(F),y(!0))}).catch(F=>{H&&(w(String(F)),y(!0))}),()=>{H=!1}},[l,s]);const $=(H,F)=>{m(P=>P.map((ne,V)=>V===H?{...ne,...F}:ne))},L=async()=>{w(null),D(null);const H=uj(f);if(H){w(H);return}E(!0);try{const F=await u(f.map(P=>({label:P.label.trim(),repository:P.repository})));m(F),D(F.length===0?"Mappings cleared":`Saved ${F.length} mapping${F.length===1?"":"s"}`)}catch(F){w(String(F))}finally{E(!1)}};return r.jsxs("div",{className:"rounded border border-white/10 bg-black/20 px-3 py-2 space-y-2","aria-label":"Repository mappings",children:[r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsx("p",{className:"text-xs text-white/60",children:"Repository mappings"}),d&&r.jsx("button",{type:"button",className:"text-xs text-white/50 hover:text-white",onClick:d,children:"Close"})]}),x?f.length===0?r.jsx("p",{className:"text-xs text-white/40",children:"No mappings yet — add one to prefill the Repository field from a Linear label."}):f.map((H,F)=>r.jsxs("div",{className:"flex gap-2 items-start","data-testid":"mapping-row",children:[r.jsx("input",{className:"w-40 shrink-0 bg-black/30 border border-white/10 rounded px-2 py-1.5 text-sm",placeholder:"Linear label","aria-label":`Linear label for mapping ${F+1}`,value:H.label,onChange:P=>$(F,{label:P.target.value})}),r.jsx("div",{className:"flex-1 min-w-0",children:r.jsx(yv,{value:H.repository,onChange:P=>$(F,{repository:P}),recentRepos:n})}),r.jsx("button",{type:"button",className:"shrink-0 text-xs text-white/50 hover:text-white px-1 py-1.5",onClick:()=>m(P=>P.filter((ne,V)=>V!==F)),children:"Remove"})]},F)):r.jsx("p",{className:"text-xs text-white/40",children:"Loading…"}),v&&r.jsx("p",{className:"text-xs text-red-300","data-testid":"mappings-error",children:v}),j&&r.jsx("p",{className:"text-xs text-teal-200/80",children:j}),r.jsxs("div",{className:"flex gap-2",children:[r.jsx("button",{type:"button",className:"text-xs px-2 py-1 rounded border border-white/15 text-white/70 hover:text-white",onClick:()=>m(H=>[...H,rj()]),children:"Add mapping"}),r.jsx("button",{type:"button",className:"text-xs px-2 py-1 rounded border border-teal/40 text-teal disabled:opacity-50",disabled:X||!x,onClick:()=>void L(),children:X?"Saving…":"Save changes"})]})]})}const cj=["Backlog","Todo","In Progress","In Review"];function hd(n,l){const s=l?n.filter(f=>f.teamId===l):n,u=new Set,d=[];for(const f of s){const m=f.name.toLowerCase();u.has(m)||(u.add(m),d.push(f.name))}return d}function qx(n,l){return l.length===0?[...n]:n.filter(s=>l.some(u=>u.toLowerCase()===s.toLowerCase()))}function dj(n,l){return n!==null&&!l}function fj({initialConfig:n,initialMetadata:l,loadConfig:s=D2,loadMetadata:u=z2,saveConfig:d=U2,onSaved:f,onClose:m}){var se;const[x,y]=b.useState(n===void 0?null:n),[v,w]=b.useState(l===void 0?null:l),[j,D]=b.useState((n==null?void 0:n.persisted.teamId)??""),[X,E]=b.useState((n==null?void 0:n.persisted.assigneeMe)??!1),[$,L]=b.useState((n==null?void 0:n.persisted.stateFilter)??[...cj]),[H,F]=b.useState(n!==void 0),[P,ne]=b.useState(l!==void 0),[V,Ne]=b.useState(n===null?"Could not load saved Linear intake filters":null),[I,ye]=b.useState(l===null?"Could not load Linear teams and statuses":null),[Me,bt]=b.useState(null),[At,rt]=b.useState(!1),[yt,lt]=b.useState(null);b.useEffect(()=>{if(n!==void 0)return;let B=!0;return s().then(ce=>{B&&(y(ce),D(ce.persisted.teamId??""),E(ce.persisted.assigneeMe),L(ce.persisted.stateFilter),Ne(null),F(!0))}).catch(ce=>{B&&(y(null),Ne(String(ce)),F(!0))}),()=>{B=!1}},[n,s]),b.useEffect(()=>{if(l!==void 0)return;let B=!0;return u().then(ce=>{B&&(w(ce),ye(null),ne(!0))}).catch(ce=>{B&&(w(null),ye(String(ce)),ne(!0))}),()=>{B=!1}},[l,u]),b.useEffect(()=>{if(!v)return;const B=hd(v.workflowStates,j||null);L(ce=>qx(ce,B))},[v,j]);const Qe=b.useMemo(()=>hd((v==null?void 0:v.workflowStates)??[],j||null),[v,j]),U=Qe.length>0?Qe:$,J=!!(x!=null&&x.envOverrides.teamId),re=!!(x!=null&&x.envOverrides.stateFilter),Ae=J||re,Le=H&&P,N=dj(x,At),Y=B=>{L(ce=>ce.some(De=>De.toLowerCase()===B.toLowerCase())?ce.filter(De=>De.toLowerCase()!==B.toLowerCase()):[...ce,B])},W=async()=>{if(lt(null),bt(null),!x){lt("Saved filters are unavailable — reload before saving");return}if($.length===0){lt("Select at least one workflow status");return}rt(!0);try{const B=hd((v==null?void 0:v.workflowStates)??[],j.trim()||null),ce=qx($,B);if(ce.length===0){lt("Select at least one workflow status"),rt(!1);return}const Xe=await d({stateFilter:ce,teamId:j.trim()||null,assigneeMe:X});y(Xe),D(Xe.persisted.teamId??""),E(Xe.persisted.assigneeMe),L(Xe.persisted.stateFilter),bt(Xe.envOverrides.stateFilter||Xe.envOverrides.teamId?"Saved locally — env still overrides the disabled controls":"Saved"),f==null||f()}catch(B){lt(String(B))}finally{rt(!1)}},te=V||I||yt;return r.jsxs("div",{className:"rounded border border-white/10 bg-black/20 px-3 py-2 space-y-2","aria-label":"Linear intake filters",children:[r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsx("p",{className:"text-xs text-white/60",children:"Linear intake filters"}),m&&r.jsx("button",{type:"button",className:"text-xs text-white/50 hover:text-white",onClick:m,children:"Close"})]}),Le?r.jsxs(r.Fragment,{children:[Ae&&r.jsxs("p",{className:"text-xs text-amber-200/90 rounded bg-amber-500/10 border border-amber-400/20 px-2 py-1.5","data-testid":"linear-filter-env-notice",children:[J&&re?r.jsxs(r.Fragment,{children:[r.jsx("code",{className:"text-amber-100/90",children:"LINEAR_TEAM_ID"})," and"," ",r.jsx("code",{className:"text-amber-100/90",children:"LINEAR_STATE_FILTER"})," override saved Team and Status."]}):J?r.jsxs(r.Fragment,{children:[r.jsx("code",{className:"text-amber-100/90",children:"LINEAR_TEAM_ID"})," overrides saved Team."]}):r.jsxs(r.Fragment,{children:[r.jsx("code",{className:"text-amber-100/90",children:"LINEAR_STATE_FILTER"})," overrides saved Status."]})," ","Remove the env var to use the value below."]}),r.jsxs("label",{className:"block space-y-1",children:[r.jsx("span",{className:"text-xs text-white/50",children:"Team"}),r.jsxs("select",{className:"w-full bg-black/30 border border-white/10 rounded px-2 py-1.5 text-sm disabled:opacity-50","aria-label":"Team",value:j,disabled:J||!x,onChange:B=>D(B.target.value),children:[r.jsx("option",{value:"",children:"All teams"}),((v==null?void 0:v.teams)??[]).map(B=>r.jsxs("option",{value:B.id,children:[B.name,B.key?` (${B.key})`:""]},B.id))]})]}),r.jsxs("fieldset",{className:"space-y-1",disabled:!x,children:[r.jsx("legend",{className:"text-xs text-white/50",children:"Assignee"}),r.jsxs("label",{className:"flex items-center gap-2 text-sm text-white/80 cursor-pointer",children:[r.jsx("input",{type:"radio",name:"linear-assignee",checked:!X,onChange:()=>E(!1),className:"accent-[#C4B643]"}),"Anyone"]}),r.jsxs("label",{className:"flex items-center gap-2 text-sm text-white/80 cursor-pointer",children:[r.jsx("input",{type:"radio",name:"linear-assignee",checked:X,onChange:()=>E(!0),className:"accent-[#C4B643]"}),"Assigned to me",(se=v==null?void 0:v.viewer)!=null&&se.name?r.jsxs("span",{className:"text-xs text-white/40",children:["(",v.viewer.name,")"]}):null]})]}),r.jsxs("fieldset",{className:"space-y-1",disabled:re||!x,children:[r.jsx("legend",{className:"text-xs text-white/50",children:"Status"}),U.length===0?r.jsx("p",{className:"text-xs text-white/40",children:"No workflow statuses available."}):r.jsx("div",{className:"max-h-40 overflow-y-auto space-y-1","data-testid":"linear-status-list",children:U.map(B=>{const ce=$.some(Xe=>Xe.toLowerCase()===B.toLowerCase());return r.jsxs("label",{className:"flex items-center gap-2 text-sm text-white/80 cursor-pointer",children:[r.jsx("input",{type:"checkbox",checked:ce,disabled:re||!x,onChange:()=>Y(B),className:"accent-[#C4B643]","aria-label":`Status ${B}`}),B]},B)})})]}),te&&r.jsx("p",{className:"text-xs text-red-300","data-testid":"linear-filters-error",children:te}),Me&&r.jsx("p",{className:"text-xs text-teal-200/80","data-testid":"linear-filters-notice",children:Me}),r.jsx("div",{className:"flex gap-2",children:r.jsx("button",{type:"button",className:"text-xs px-2 py-1 rounded border border-teal/40 text-teal disabled:opacity-50",disabled:!N,"data-testid":"linear-filters-save",onClick:()=>void W(),children:At?"Saving…":"Save"})})]}):r.jsx("p",{className:"text-xs text-white/40",children:"Loading…"})]})}function vv(n){return n.issues.some(l=>l.code==="usage_capped")}function gv(n){return[...n].sort((l,s)=>Number(s.healthy)-Number(l.healthy))}function rl(n){var u;const l=`${n.name} · ${Aa(n.runtime)}`,s=[];if(!n.healthy){const d=((u=n.issues[0])==null?void 0:u.message)??"unhealthy";s.push(`NEEDS FIX: ${d}`)}return vv(n)&&s.push("USAGE CAPPED"),s.length>0?`${l} — ${s.join(" · ")}`:l}function Nu(n){var l;return n?n.healthy?vv(n)?"Usage capped — admission will refuse until the cap lifts":null:((l=n.issues[0])==null?void 0:l.message)??"Agent is unhealthy":null}function bv({agents:n,initialDeveloperId:l,initialReviewerId:s,busy:u,onSave:d,onCancel:f,variant:m="queued",notice:x=null}){var P,ne;const[y,v]=b.useState(l??""),[w,j]=b.useState(s??""),D=gv(n),X=n.find(V=>V.id===y),E=n.find(V=>V.id===w),$=Nu(X),L=Nu(E),H=y===(l??"")&&w===(s??""),F=m==="parked"?"Save via the issue PATCH contract — keeps the worktree and branch, records the change on the timeline; resume continues with the new agents":"Save via the issue PATCH contract — keeps queue position and rechecks the wait reason";return r.jsxs("div",{className:"p-3 rounded border border-white/10 bg-panel-elevated/60 space-y-2",children:[r.jsx("p",{className:"text-xs text-white/50",children:m==="parked"?r.jsx(r.Fragment,{children:"Swap the developer and/or reviewer to another profile — the worktree, branch and review rounds are kept, the change is recorded on the timeline, and a resume continues with the new agents."}):r.jsx(r.Fragment,{children:"Reassign agents — queue position is kept, the wait reason is rechecked, and the change is recorded on the timeline."})}),r.jsxs("label",{className:"block space-y-1",children:[r.jsx("span",{className:"text-xs text-white/45 uppercase tracking-wide",children:"Developer"}),r.jsxs("select",{className:"w-full bg-black/30 border border-white/10 rounded px-3 py-2 text-sm",value:y,disabled:u,title:X?`${X.name} · ${Aa(X.runtime)}${X.healthy?" · healthy":` · ${((P=X.issues[0])==null?void 0:P.message)??"unhealthy"}`}`:"Pick a developer agent",onChange:V=>v(V.target.value),children:[r.jsx("option",{value:"",children:"Developer agent…"}),D.map(V=>r.jsx("option",{value:V.id,title:rl(V),children:(V.healthy?"● ":"○ ")+rl(V)},V.id))]}),$&&r.jsx("span",{className:"text-xs text-amber-200/80 block",children:$})]}),r.jsxs("label",{className:"block space-y-1",children:[r.jsx("span",{className:"text-xs text-white/45 uppercase tracking-wide",children:"Reviewer"}),r.jsxs("select",{className:"w-full bg-black/30 border border-white/10 rounded px-3 py-2 text-sm",value:w,disabled:u,title:E?`${E.name} · ${Aa(E.runtime)}${E.healthy?" · healthy":` · ${((ne=E.issues[0])==null?void 0:ne.message)??"unhealthy"}`}`:"Pick a reviewer agent",onChange:V=>j(V.target.value),children:[r.jsx("option",{value:"",children:"Reviewer agent…"}),D.map(V=>V.runtime==="muse_code"?r.jsx("option",{value:V.id,disabled:!0,title:"Muse Code cannot be a reviewer (developer role only)",children:`○ ${V.name} · ${Aa(V.runtime)} — reviewer not supported`},V.id):r.jsx("option",{value:V.id,title:rl(V),children:(V.healthy?"● ":"○ ")+rl(V)},V.id))]}),L&&r.jsx("span",{className:"text-xs text-amber-200/80 block",children:L})]}),r.jsxs("div",{className:"flex flex-wrap gap-2",children:[r.jsx("button",{type:"button",className:"btn-gold px-4 py-1.5 text-sm disabled:opacity-50",disabled:u||!y||!w||H,title:F,onClick:()=>d(y,w),children:"Save agents"}),r.jsx("button",{type:"button",className:"px-4 py-1.5 text-sm text-white/60 hover:text-white disabled:opacity-50",disabled:u,title:m==="parked"?"Reset the selectors to the issue's current agents":void 0,onClick:()=>{if(m==="parked"){v(l??""),j(s??""),f==null||f();return}f==null||f()},children:"Cancel"})]}),x&&r.jsx("p",{className:"text-xs text-emerald-200/90",children:x})]})}function _u({className:n="w-3.5 h-3.5"}){return r.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:n,"aria-hidden":!0,children:r.jsx("path",{fillRule:"evenodd",d:"M8.982 1.566a1.13 1.13 0 0 0-1.964 0L.165 13.233c-.457.778.091 1.767.982 1.767h13.706c.891 0 1.439-.99.982-1.767L8.982 1.566zM8 5.697a.75.75 0 0 1 .75.75v3.5a.75.75 0 0 1-1.5 0v-3.5A.75.75 0 0 1 8 5.697zm0 7.75a1 1 0 1 0 0-2 1 1 0 0 0 0 2z"})})}const hj={final_review:"Final review",attempts_exhausted:"Attempts exhausted",policy_escalation:"Policy escalation",product_scope_decision:"Product scope decision",deck_interaction_required:"Agent Deck interaction required",reflection_interaction_required:"Reflection interaction required",outbound_delivery_interaction_required:"Outbound delivery interaction required",muse_capability:"Muse capability",operator_verification:"Operator verification"};function mj(n){return hj[n]??n}function pj(n){if(!n)return null;try{return JSON.parse(n)}catch{return null}}function xj(n){const l=pj(n.responseOptionsJson);return Array.isArray(l)?l.filter(s=>typeof(s==null?void 0:s.choice)=="string"&&typeof(s==null?void 0:s.label)=="string"):[]}function yj(n){return n==="close"||n==="reject"||n==="abort"}function vj({options:n,disabled:l,onChoose:s}){return n.length===0?null:r.jsx("div",{className:"flex flex-wrap gap-2",children:n.map(u=>r.jsx("button",{type:"button",className:`${yj(u.choice)?"btn-ghost-danger":"btn-gold"} px-3 py-1 text-xs disabled:opacity-50`,disabled:l,onClick:()=>s(u.choice),children:u.label},u.choice))})}function zs({action:n,linkTo:l,onChoose:s,disabled:u,children:d,hideChoicesHint:f}){const m=Zy(n),x=l?r.jsx(sa,{to:l,className:"text-sm text-white/85 hover:text-white hover:underline",children:m.title}):r.jsx("span",{className:"text-sm text-white/85",children:m.title});return r.jsxs("div",{className:"space-y-1.5",children:[r.jsxs("div",{className:"flex items-baseline justify-between gap-2",children:[r.jsx("span",{className:"text-xs uppercase tracking-wide text-red-300/80",children:mj(n.actionType)}),r.jsx("span",{className:"text-xs text-white/35 shrink-0",children:new Date(n.requestedAt).toLocaleString()})]}),r.jsx("div",{children:x}),m.context&&r.jsx("p",{className:"text-xs text-white/55",children:m.context}),s?m.displayOptions.length>0?r.jsx(vj,{options:m.displayOptions,disabled:u,onChoose:s}):r.jsxs("p",{className:"text-xs text-amber-200/80",children:["This item declares no response options — resolve it from the CLI (",r.jsx("code",{children:"agent-dealer action"}),")."]}):!f&&m.displayOptions.length>0&&r.jsxs("p",{className:"text-xs text-white/50",children:["To decide: ",m.displayOptions.map(y=>y.label).join(" · ")]}),d,r.jsxs("details",{children:[r.jsx("summary",{className:"text-xs text-white/45 cursor-pointer hover:text-white/70",children:"Details"}),r.jsxs("div",{className:"mt-1.5 space-y-1.5 rounded border border-white/10 bg-black/20 px-3 py-2",children:[r.jsx("p",{className:"text-xs text-white/60 whitespace-pre-wrap",children:m.details.question}),m.details.question!==m.details.reason&&r.jsx("p",{className:"text-xs text-white/60 whitespace-pre-wrap",children:m.details.reason}),m.details.factLines.map(y=>r.jsx("p",{className:"text-xs text-white/60",children:y},y)),m.details.paths.length>0&&r.jsxs("div",{className:"text-xs text-white/60",children:[r.jsx("p",{className:"text-white/40",children:"Saved paths:"}),m.details.paths.map(y=>r.jsx("p",{className:"font-mono break-all",children:y},y))]}),m.details.commands.length>0&&r.jsxs("div",{className:"text-xs text-white/60",children:[r.jsx("p",{className:"text-white/40",children:"Recovery commands:"}),r.jsx("pre",{className:"font-mono whitespace-pre-wrap break-all",children:m.details.commands.join(`
64
- `)})]}),m.details.evidencePretty&&r.jsxs("div",{className:"text-xs text-white/60",children:[r.jsx("p",{className:"text-white/40",children:"Evidence:"}),r.jsx("pre",{className:"font-mono whitespace-pre-wrap break-all",children:m.details.evidencePretty})]})]})]})]})}function gj({actions:n,busyActionId:l,onResolve:s}){const[u,d]=b.useState({});return n.length===0?null:r.jsxs("div",{className:"mb-4 rounded border border-red-400/30 bg-red-500/10",children:[r.jsxs("div",{className:"px-4 py-2 flex items-center gap-2 border-b border-red-400/20",children:[r.jsx(_u,{className:"w-4 h-4 shrink-0 text-red-300"}),r.jsxs("span",{className:"font-ui-display text-sm font-medium text-red-200",children:[n.length," ",n.length===1?"item needs":"items need"," your attention"]})]}),r.jsx("div",{className:"divide-y divide-white/5",children:n.map(f=>{if(f.issueId)return r.jsx("div",{className:"px-4 py-3 hover:bg-white/5 transition-colors",children:r.jsx(zs,{action:f,linkTo:`/issues/${f.issueId}`})},f.id);const m=f.actionType==="operator_verification",x=u[f.id]??"";return r.jsx("div",{className:"px-4 py-3",children:r.jsx(zs,{action:f,disabled:l===f.id||m&&!x.trim(),onChoose:y=>s(f.id,y,m?x:void 0),children:m&&r.jsx("textarea",{className:"w-full bg-black/30 border border-white/10 rounded px-3 py-2 text-sm text-white/85 placeholder:text-white/30",rows:2,placeholder:"Result note (required) — paste the probe output, waiver reason, or repair note",value:x,disabled:l===f.id,onChange:y=>d(v=>({...v,[f.id]:y.target.value}))})})},f.id)})})]})}const bj="web";function wj(n){if(typeof n!="object"||n===null)return null;const l=n.deletedNotice;return typeof l=="string"&&l.length>0?l:null}function Sj(n){const l=Date.now()-new Date(n).getTime(),s=Math.floor(l/6e4);if(s<1)return"just now";if(s<60)return`${s}m ago`;const u=Math.floor(s/60);return u<24?`${u}h ago`:`${Math.floor(u/24)}d ago`}function jj({agents:n,humanActions:l,onHumanActionsChanged:s}){const[u,d]=b.useState(null),[f,m]=b.useState(null),[x,y]=Ny(),v=x.toString(),w=IS(v),j=b.useRef(w);j.current=w;const[D,X]=b.useState(()=>Dx(v)),[E,$]=b.useState(!1),L=Bx(w),[H,F]=b.useState(!1),[P,ne]=b.useState(!1),[V,Ne]=b.useState(!1),[I,ye]=b.useState("manual"),[Me,bt]=b.useState([]),[At,rt]=b.useState(!1),[yt,lt]=b.useState(""),Qe=b.useRef(yt);Qe.current=yt;const[U,J]=b.useState(""),[re,Ae]=b.useState(!1),[Le,N]=b.useState([]),[Y,W]=b.useState(""),[te,se]=b.useState(""),[B,ce]=b.useState("main"),[Xe,De]=b.useState(""),[Bt,Ta]=b.useState(""),[ua,Va]=b.useState(""),[qe,Za]=b.useState(""),[dt,wt]=b.useState(!0),[Rn,Ye]=b.useState(null),Ga=Ca(),oa=wj(Ga.state),[tn,ol]=b.useState(!1),[ut,ca]=b.useState([]),[Ue,cl]=b.useState(null),[qt,$l]=b.useState(!1),[dl,Yl]=b.useState(null),[fl,Oa]=b.useState(()=>lj()),[tt,Ut]=b.useState(null),[ft,Ft]=b.useState(null),at=Me.find(C=>C.id===yt)??null,Vl=I==="linear"&&at!=null,an=ZS(I,at),nn=Mx({title:Y,repo:te,developerAgentId:ua,reviewerAgentId:qe}),Qa=C=>{X2(C).then(d).catch(de=>Ye(String(de)))},La=()=>{Ex([...fd]).then(Yl).catch(()=>{})},Tn=()=>{ij(),Oa(!0)},ln=nj({historyTotal:dl,filtersActive:L,dismissed:fl}),Tt=()=>{Qa(j.current),dd().then(ca).catch(()=>{}),iS().then(cl).catch(()=>{}),La()},hl=async C=>{$l(!0),Ye(null);try{const de=await sS(C);cl(de),Tt()}catch(de){Ye(String(de))}finally{$l(!1)}},ml=async C=>{Ft(C),Ye(null);try{const de=await lv(C);Ut({issueId:C,developerAgentId:de.issue.developerAgentId,reviewerAgentId:de.issue.reviewerAgentId})}catch(de){Ye(String(de))}finally{Ft(null)}},sn=async(C,de)=>{if(tt){Ft(tt.issueId);try{await fu(tt.issueId,{developerAgentId:C,reviewerAgentId:de}),Ut(null),Tt()}catch(nt){Ut(null),Ye(String(nt)),Tt()}finally{Ft(null)}}},Bi=async C=>{Ft(C),Ye(null);try{await iv(C),Tt()}catch(de){Ye(String(de))}finally{Ft(null)}},Zl=async C=>{Ft(C),Ye(null);try{await sv(C),Tt()}catch(de){Ye(String(de)),Tt()}finally{Ft(null)}},On=C=>{const de=KS(JS(C));y(de?Object.fromEntries(new URLSearchParams(de)):{})},pl=()=>{X(XS),y({})},Ln=C=>{const de=FS(v,C);y(de?Object.fromEntries(new URLSearchParams(de)):{})},Ma=C=>X(de=>({...de,...C})),G=async(C,de,nt)=>{m(C),Ye(null);try{await uv(C,bj,de,nt),s(),Tt()}catch(da){Ye(String(da))}finally{m(null)}};b.useEffect(()=>{X(Dx(v))},[v]),b.useEffect(()=>{Qa(j.current),dd().then(ca).catch(()=>{}),Ex([...fd]).then(Yl).catch(()=>{});const C=setInterval(()=>{Qa(j.current),dd().then(ca).catch(()=>{})},5e3);return()=>clearInterval(C)},[v]);const je=()=>{L2().then(C=>{rt(C.hasMore),bt(de=>GS(de,C.candidates,Qe.current))}).catch(C=>Ye(`Linear inbox: ${String(C)}`))};b.useEffect(()=>{H&&(I2().then(N).catch(()=>N([])),I==="linear"&&je())},[H,I]),b.useEffect(()=>{at&&(W(`${at.identifier}: ${at.title}`),De(at.description??""),Ta(""),se(C=>VS(C,at)))},[at]);const ze=()=>{W(""),se(""),De(""),Ta(""),lt(""),J(""),wt(!0),ce("main")},Ve=C=>{bt(de=>QS(de,C).candidates),lt(C.id),J(C.identifier)},ht=async()=>{const C=U.trim();if(!C){Ye("Paste a Linear id (e.g. NOT-103) or issue URL");return}Ae(!0),Ye(null);try{const de=await M2(C);Ve(de)}catch(de){Ye(`Linear lookup: ${String(de)}`)}finally{Ae(!1)}},mt=async()=>{if(!Mx({title:Y,repo:te,developerAgentId:ua,reviewerAgentId:qe})){Ye("Title, GitHub repository, developer, and reviewer are required");return}try{await W2({title:Y.trim(),repo:te.trim(),baseBranch:B.trim()||"main",description:Xe.trim()||void 0,acceptanceCriteria:Bt.trim()||void 0,developerAgentId:ua,reviewerAgentId:qe,maxReviewRounds:3,maxInfraAttempts:3,autoMerge:dt,source:I==="linear"&&at?"linear":"manual",externalId:at==null?void 0:at.id,externalLabel:at==null?void 0:at.identifier,externalUrl:at==null?void 0:at.url,linearAttachments:at==null?void 0:at.attachments}),F(!1),ze(),Tt()}catch(C){Ye(String(C))}};return r.jsxs("div",{className:"flex-1 min-h-0 px-6 py-4 w-full overflow-y-auto",children:[r.jsxs("div",{className:"flex items-center justify-between mb-4",children:[r.jsx("h2",{className:"font-ui-display text-lg font-semibold text-white/90",children:"Issues"}),r.jsx("button",{type:"button",className:"btn-gold px-4",onClick:()=>F(C=>!C),children:"New issue"})]}),Rn&&r.jsx("p",{className:"text-sm text-red-300 mb-3",children:Rn}),oa&&!tn&&r.jsxs("div",{className:"mb-3 p-3 rounded border border-white/15 bg-white/[0.04] flex items-start justify-between gap-3",children:[r.jsx("p",{className:"text-sm text-white/85",children:oa}),r.jsx("button",{type:"button",className:"font-ui-display shrink-0 text-xs text-white/50 hover:text-white",onClick:()=>ol(!0),children:"Dismiss"})]}),ln&&r.jsx(sj,{agents:n,onStartIssue:()=>F(!0),onDismiss:Tn}),H&&r.jsxs("div",{className:"mb-4 p-4 rounded border border-white/10 bg-panel-elevated/60 space-y-2",children:[r.jsxs("p",{className:"text-xs text-white/50",children:["Workflow:"," ",r.jsxs("span",{className:"text-white/75",children:["developer → reviewer → ",dt?"auto-merge on approve":"final human review"]}),"."]}),r.jsxs("div",{className:"flex gap-2 text-sm",children:[r.jsx("button",{type:"button",className:`font-ui-display px-3 py-1 rounded border ${I==="manual"?"border-teal/50 text-teal":"border-white/10 text-white/50"}`,onClick:()=>{ye("manual"),lt("")},children:"Manual"}),r.jsx("button",{type:"button",className:`font-ui-display px-3 py-1 rounded border ${I==="linear"?"border-teal/50 text-teal":"border-white/10 text-white/50"}`,onClick:()=>ye("linear"),children:"From Linear"})]}),I==="linear"&&r.jsxs("div",{className:"space-y-2",children:[r.jsxs("div",{className:"flex gap-2",children:[r.jsx("input",{className:"flex-1 bg-black/30 border border-white/10 rounded px-3 py-2 text-sm",placeholder:"NOT-103 or Linear URL",value:U,onChange:C=>J(C.target.value),onKeyDown:C=>{C.key==="Enter"&&(C.preventDefault(),ht())}}),r.jsx("button",{type:"button",className:"font-ui-display px-3 py-2 rounded border border-teal/40 text-teal text-sm disabled:opacity-50",disabled:re||!U.trim(),onClick:()=>void ht(),children:re?"…":"Lookup"})]}),r.jsxs("div",{className:"space-y-1",children:[r.jsxs("div",{className:"flex items-center gap-1.5",children:[r.jsx("span",{className:"text-xs text-white/50",children:"Or pick from open inbox…"}),r.jsx("button",{type:"button","aria-label":"Configure Linear intake filters",title:"Configure Linear intake filters","aria-expanded":V,onClick:()=>Ne(C=>!C),className:"text-white/40 hover:text-white shrink-0 rounded focus-visible:outline focus-visible:outline-2 focus-visible:outline-cyber-teal/45",children:r.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 16 16",fill:"none","aria-hidden":"true",children:[r.jsx("path",{d:"M8 5.2a2.8 2.8 0 1 0 0 5.6 2.8 2.8 0 0 0 0-5.6Z",stroke:"currentColor",strokeWidth:"1.3"}),r.jsx("path",{d:"M8 1.5v1.7M8 12.8v1.7M1.5 8h1.7M12.8 8h1.7M3.4 3.4l1.2 1.2M11.4 11.4l1.2 1.2M12.6 3.4l-1.2 1.2M4.6 11.4l-1.2 1.2",stroke:"currentColor",strokeWidth:"1.3",strokeLinecap:"round"})]})})]}),r.jsxs("select",{className:"w-full bg-black/30 border border-white/10 rounded px-3 py-2 text-sm","aria-label":"Or pick from open inbox",value:yt,onChange:C=>{const de=C.target.value;lt(de);const nt=Me.find(da=>da.id===de);nt&&J(nt.identifier)},children:[r.jsx("option",{value:"",children:"Select an issue…"}),Me.map(C=>r.jsxs("option",{value:C.id,children:[C.identifier,": ",C.title]},C.id))]}),V&&r.jsx(fj,{onClose:()=>Ne(!1),onSaved:je}),At&&r.jsx("p",{className:"text-xs text-white/40","data-testid":"linear-candidates-has-more",children:"Showing the 50 most recently updated matches. Use exact ID/URL lookup above for another issue."})]})]}),r.jsx("input",{className:"w-full bg-black/30 border border-white/10 rounded px-3 py-2 text-sm disabled:opacity-60",placeholder:"Title",value:Y,disabled:Vl,onChange:C=>W(C.target.value)}),r.jsx("textarea",{className:"w-full bg-black/30 border border-white/10 rounded px-3 py-2 text-sm disabled:opacity-60",rows:3,placeholder:"Problem statement / description",value:Xe,disabled:Vl,onChange:C=>De(C.target.value)}),r.jsx("textarea",{className:"w-full bg-black/30 border border-white/10 rounded px-3 py-2 text-sm",rows:3,placeholder:"Acceptance criteria (derived from the ticket when left empty)",value:Bt,onChange:C=>Ta(C.target.value)}),r.jsxs("div",{className:"flex gap-2 items-stretch",children:[r.jsxs("div",{className:"flex-1 space-y-1 min-w-0",children:[r.jsxs("div",{className:"flex items-center gap-1.5",children:[r.jsx("span",{className:"text-xs text-white/50",children:"Repository"}),r.jsx("button",{type:"button","aria-label":"Configure repository mappings",title:"Configure repository mappings","aria-expanded":P,onClick:()=>ne(C=>!C),className:"text-white/40 hover:text-white shrink-0 rounded focus-visible:outline focus-visible:outline-2 focus-visible:outline-cyber-teal/45",children:r.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 16 16",fill:"none","aria-hidden":"true",children:[r.jsx("path",{d:"M8 5.2a2.8 2.8 0 1 0 0 5.6 2.8 2.8 0 0 0 0-5.6Z",stroke:"currentColor",strokeWidth:"1.3"}),r.jsx("path",{d:"M8 1.5v1.7M8 12.8v1.7M1.5 8h1.7M12.8 8h1.7M3.4 3.4l1.2 1.2M11.4 11.4l1.2 1.2M12.6 3.4l-1.2 1.2M4.6 11.4l-1.2 1.2",stroke:"currentColor",strokeWidth:"1.3",strokeLinecap:"round"})]})})]}),r.jsx(yv,{value:te,onChange:se,recentRepos:Le}),P&&r.jsx(oj,{recentRepos:Le,onClose:()=>ne(!1)}),an&&r.jsx("p",{className:"text-xs text-amber-200/80","data-testid":"repo-label-warning",children:an})]}),r.jsx("input",{className:"w-32 bg-black/30 border border-white/10 rounded px-3 py-2 text-sm",placeholder:"Base (seed)",title:"Seed only — managed GitHub clones use the remote default at first checkout",value:B,onChange:C=>ce(C.target.value)})]}),r.jsxs("select",{className:"w-full bg-black/30 border border-white/10 rounded px-3 py-2 text-sm",value:ua,onChange:C=>Va(C.target.value),children:[r.jsx("option",{value:"",children:"Developer agent…"}),n.map(C=>r.jsx("option",{value:C.id,children:C.name},C.id))]}),r.jsxs("select",{className:"w-full bg-black/30 border border-white/10 rounded px-3 py-2 text-sm",value:qe,onChange:C=>Za(C.target.value),children:[r.jsx("option",{value:"",children:"Reviewer agent…"}),n.map(C=>r.jsx("option",{value:C.id,children:C.name},C.id))]}),r.jsxs("label",{className:"flex items-center gap-2 text-sm text-white/70 cursor-pointer",children:[r.jsx("input",{type:"checkbox",checked:dt,onChange:C=>wt(C.target.checked),className:"accent-[#C4B643]"}),"Auto-merge when reviewer approves (skip final human review)"]}),r.jsxs("div",{className:"flex gap-2",children:[r.jsx("button",{type:"button",className:"btn-gold px-4 disabled:opacity-40",disabled:!nn,title:nn?void 0:"Title, GitHub repository, developer, and reviewer are required",onClick:mt,children:I==="linear"?"Kick from Linear":"Create"}),r.jsx("button",{type:"button",className:"font-ui-display px-4 py-2 text-sm text-white/60 hover:text-white",onClick:()=>{F(!1),ze()},children:"Cancel"})]})]}),ut.length>0?r.jsxs("div",{className:"mb-4 rounded border border-cyber-teal/25 bg-cyber-teal/5",children:[r.jsxs("div",{className:"px-4 py-2 border-b border-cyber-teal/20 flex items-center justify-between gap-3",children:[r.jsx("span",{className:"font-ui-display text-sm font-medium text-cyber-teal",children:"Admission queue"}),r.jsx("span",{className:"flex items-center gap-2 text-xs text-white/40",children:Ue?r.jsxs(r.Fragment,{children:[r.jsxs("span",{children:[Ue.active," active · ",Ue.waiting," waiting · limit"," ",Ue.limit,Ue.overCap?" · over capacity":""]}),Ue.options.length>0?r.jsxs("label",{className:"flex items-center gap-1",children:[r.jsx("span",{className:"text-white/35",children:"limit"}),r.jsx("select",{className:"bg-black/30 border border-white/10 rounded px-1.5 py-0.5 text-xs text-white/80 disabled:opacity-50",value:Ue.options.includes(Ue.maxActiveIssues)?Ue.maxActiveIssues:Ue.limit,disabled:qt,title:Ue.ceiling<2?`Capped by the worker/spawn ceiling (${Ue.ceiling})`:"How many issues may execute in parallel (max one per repository)",onChange:C=>void hl(Number(C.target.value)),children:Ue.options.map(C=>r.jsx("option",{value:C,children:C},C))})]}):r.jsxs("span",{title:`Capped by the worker/spawn ceiling (${Ue.ceiling})`,children:["max ",Ue.ceiling]})]}):r.jsxs("span",{children:[ut.length," waiting · sequential"]})})]}),r.jsx("div",{className:"divide-y divide-white/5",children:ut.map((C,de)=>r.jsxs("div",{children:[r.jsxs("div",{className:"px-4 py-2 flex items-start gap-3",children:[r.jsx("span",{className:"text-xs text-white/35 w-5 shrink-0 pt-0.5",children:C.position}),r.jsxs(sa,{to:`/issues/${C.issueId}`,className:"flex-1 min-w-0 text-left hover:text-cyber-teal",children:[r.jsx("span",{className:"text-sm text-white/85 truncate block",children:C.title??C.issueId.slice(0,8)}),C.waitReason?r.jsx("span",{className:"text-xs text-amber-200/80 block mt-0.5",children:C.waitReason}):r.jsxs("span",{className:"text-xs text-white/35 block mt-0.5",children:[C.issueStatus??"queued"," · next up"]})]}),r.jsxs("div",{className:"flex items-center gap-2 shrink-0 flex-wrap justify-end",children:[r.jsx("button",{type:"button",className:"font-ui-display text-xs text-white/40 hover:text-cyber-teal disabled:opacity-30",disabled:ft===C.issueId,title:"Change the developer/reviewer agents — keeps queue position and rechecks the wait reason",onClick:()=>void ml(C.issueId),children:"Edit"}),r.jsx("button",{type:"button",className:"font-ui-display text-xs text-white/40 hover:text-cyber-teal disabled:opacity-30",disabled:ft===C.issueId,title:"Run next — move to the front of the admission queue; runs now if a slot is free, otherwise waits first with a reason",onClick:()=>void Bi(C.issueId),children:"Run next"}),r.jsx("button",{type:"button",className:"font-ui-display text-xs text-white/40 hover:text-cyber-teal disabled:opacity-30",disabled:ft===C.issueId,title:"Execute now — start immediately, skipping queue order; refuses (changing nothing) when capacity, readiness, blockers, or agent health prevents it",onClick:()=>void Zl(C.issueId),children:"Execute now"}),r.jsx("button",{type:"button",className:"font-ui-display text-xs text-white/40 hover:text-cyber-teal disabled:opacity-30",disabled:de===0,title:"Move to top",onClick:()=>{nu(C.issueId,"top").then(Tt).catch(nt=>Ye(String(nt)))},children:"Top"}),r.jsx("button",{type:"button",className:"font-ui-display text-xs text-white/40 hover:text-cyber-teal disabled:opacity-30",disabled:de===0,title:"Move up",onClick:()=>{const nt=ut[de-1];nt&&nu(C.issueId,{before:nt.issueId}).then(Tt).catch(da=>Ye(String(da)))},children:"↑"}),r.jsx("button",{type:"button",className:"font-ui-display text-xs text-white/40 hover:text-cyber-teal disabled:opacity-30",disabled:de===ut.length-1,title:"Move down",onClick:()=>{const nt=ut[de+1];nt&&nu(C.issueId,{after:nt.issueId}).then(Tt).catch(da=>Ye(String(da)))},children:"↓"}),r.jsx("button",{type:"button",className:"font-ui-display text-xs text-white/40 hover:text-cyber-teal disabled:opacity-30",disabled:de===ut.length-1,title:"Move to bottom",onClick:()=>{nu(C.issueId,"bottom").then(Tt).catch(nt=>Ye(String(nt)))},children:"Bottom"}),r.jsx("button",{type:"button",className:"font-ui-display text-xs text-white/40 hover:text-white",onClick:()=>{rv(C.issueId).then(Tt).catch(nt=>Ye(String(nt)))},children:"Remove"})]})]}),(tt==null?void 0:tt.issueId)===C.issueId&&r.jsx("div",{className:"px-4 pb-3 pl-12",children:r.jsx(bv,{agents:n,initialDeveloperId:tt.developerAgentId,initialReviewerId:tt.reviewerAgentId,busy:ft===C.issueId,onSave:(nt,da)=>void sn(nt,da),onCancel:()=>Ut(null)})})]},C.id))})]}):Ue?r.jsxs("p",{"data-testid":"admission-idle-status",className:"mb-4 text-xs text-white/35 tabular-nums",children:["Admission: ",Ue.active," active · ",Ue.waiting," waiting · limit"," ",Ue.limit,Ue.overCap?" · over capacity":"",Ue.options.length>0&&r.jsxs("label",{className:"ml-2 inline-flex items-center gap-1",children:[r.jsx("span",{children:"limit"}),r.jsx("select",{className:"bg-black/30 border border-white/10 rounded px-1.5 py-0.5 text-xs text-white/60 disabled:opacity-50",value:Ue.options.includes(Ue.maxActiveIssues)?Ue.maxActiveIssues:Ue.limit,disabled:qt,title:Ue.ceiling<2?`Capped by the worker/spawn ceiling (${Ue.ceiling})`:"How many issues may execute in parallel (max one per repository)",onChange:C=>void hl(Number(C.target.value)),children:Ue.options.map(C=>r.jsx("option",{value:C,children:C},C))})]})]}):null,r.jsx(gj,{actions:l,busyActionId:f,onResolve:(C,de,nt)=>void G(C,de,nt)}),r.jsxs("div",{className:"mb-4 rounded border border-white/10 bg-panel-elevated/60",children:[r.jsxs("button",{type:"button","aria-expanded":E,"aria-controls":"issues-filter-form",onClick:()=>$(C=>!C),className:"w-full flex items-center gap-2 px-4 py-2.5 text-sm text-white/70 hover:text-white",children:[r.jsx("span",{"aria-hidden":"true",className:"text-xs text-white/40 w-3 shrink-0",children:E?"▾":"▸"}),r.jsx("span",{className:"font-ui-display",children:E?"Hide filters":"Show filters"}),L&&r.jsx("span",{"data-testid":"filters-active-indicator",title:"The issue list is filtered",className:"text-xs px-2 py-0.5 rounded-full border border-[#C4B643]/50 text-[#C4B643]",children:"Filtered"})]}),E&&r.jsx("form",{id:"issues-filter-form","aria-label":"Issues filters",className:"px-4 pb-4",onSubmit:C=>{C.preventDefault(),On(D)},children:r.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-3",children:[r.jsxs("label",{className:"block text-sm",children:[r.jsx("span",{className:"block text-xs text-white/50 mb-1",children:"Search"}),r.jsx("input",{type:"text",placeholder:"Title or label (e.g. NOT-175)",className:"w-full bg-black/30 border border-white/10 rounded px-3 py-2",value:D.q,onChange:C=>Ma({q:C.target.value})})]}),r.jsxs("label",{className:"block text-sm",children:[r.jsx("span",{className:"block text-xs text-white/50 mb-1",children:"Status"}),r.jsxs("select",{className:"w-full bg-black/30 border border-white/10 rounded px-3 py-2",value:D.status,onChange:C=>Ma({status:C.target.value}),children:[r.jsx("option",{value:"",children:"All statuses"}),fd.map(C=>r.jsx("option",{value:C,children:C},C))]})]}),r.jsxs("label",{className:"block text-sm",children:[r.jsx("span",{className:"block text-xs text-white/50 mb-1",children:"Repository"}),r.jsx("input",{type:"text",placeholder:"github.com/owner/repo",title:"Exact repository identity",className:"w-full bg-black/30 border border-white/10 rounded px-3 py-2",value:D.repo,onChange:C=>Ma({repo:C.target.value})})]}),r.jsx("div",{className:"flex items-end gap-2",children:r.jsxs("label",{className:"flex items-center gap-2 text-sm text-white/70 cursor-pointer pb-2",children:[r.jsx("input",{type:"checkbox",checked:D.needsAttention,onChange:C=>Ma({needsAttention:C.target.checked}),className:"accent-[#C4B643]"}),"Needs attention"]})}),r.jsxs("div",{className:"flex items-end gap-2 sm:col-span-2 lg:col-span-4",children:[r.jsx("button",{type:"submit",className:"btn-gold px-4",children:"Apply"}),r.jsx("button",{type:"button",className:"px-4 py-2 text-sm text-white/60 hover:text-white",onClick:pl,children:"Reset"})]})]})})]}),u===null?r.jsx("p",{className:"text-white/50 text-sm",children:"Loading…"}):u.total===0&&!Bx(w)?r.jsx("p",{className:"text-white/45 text-sm",children:"No issues yet — create one to get started."}):u.total===0?r.jsxs("div",{className:"rounded border border-white/10 bg-panel-elevated/40 px-4 py-3",children:[r.jsx("p",{className:"text-white/45 text-sm",children:Ux(u)}),r.jsx("button",{type:"button",className:"mt-2 px-3 py-1.5 text-sm rounded border border-white/15 text-white/70 hover:text-white",onClick:pl,children:"Reset filters"})]}):r.jsxs("div",{children:[r.jsx("div",{className:"flex justify-end mb-2",children:r.jsxs("p",{className:"text-xs text-white/40 tabular-nums",children:[Ux(u),zx(u)?` · ${zx(u)}`:""]})}),r.jsx("div",{className:"space-y-2",children:u.issues.map(C=>{const de=ut.find(nt=>nt.issueId===C.id);return r.jsxs(sa,{to:`/issues/${C.id}`,className:"w-full text-left flex items-center gap-3 px-4 py-3 rounded border border-white/10 bg-panel-elevated/40 hover:bg-panel-elevated/70 transition-colors",children:[C.hasOpenHumanAction&&r.jsx(_u,{className:"w-4 h-4 shrink-0 text-red-400"}),r.jsxs("div",{className:"flex-1 min-w-0",children:[r.jsx("p",{className:"text-sm font-medium text-white/90 truncate",children:C.title}),de!=null&&de.waitReason?r.jsx("p",{className:"text-xs text-amber-200/80 truncate",title:de.waitReason,children:de.waitReason}):C.currentIntent&&r.jsx("p",{className:"text-xs text-white/50 truncate",children:C.currentIntent})]}),r.jsx("span",{className:"text-xs text-white/40 capitalize shrink-0",children:C.currentOwner}),de&&r.jsxs("span",{className:"text-xs px-2 py-0.5 rounded border border-cyber-teal/40 text-cyber-teal shrink-0",title:de.waitReason??"Next up for admission",children:["Queued #",de.position]}),r.jsx(mv,{status:C.status}),r.jsx("span",{className:"text-xs text-white/35 shrink-0 w-16 text-right",children:Sj(C.updatedAt)})]},C.id)})}),u.totalPages>1&&r.jsxs("nav",{"aria-label":"Issues pages",className:"mt-3 flex items-center gap-2",children:[r.jsx("button",{type:"button",className:"px-3 py-1.5 text-sm rounded border border-white/15 text-white/70 hover:text-white disabled:opacity-40",disabled:u.page<=1,onClick:()=>Ln(u.page-1),children:"Previous"}),r.jsxs("span",{className:"text-xs text-white/45 tabular-nums",children:["Page ",u.page," of ",u.totalPages]}),r.jsx("button",{type:"button",className:"px-3 py-1.5 text-sm rounded border border-white/15 text-white/70 hover:text-white disabled:opacity-40",disabled:u.page>=u.totalPages,onClick:()=>Ln(u.page+1),children:"Next"})]})]})]})}const Nj=["developer","reviewer","legacy"],Hx=["claude_code","cursor_local","codex_local"],_j=["ready","developing","reviewing","repairing","final_review","needs_human","done","closed"];function Ri(n,l){return n.n===0||n.p50===null&&n.p95===null?{available:!1,p50Text:null,p95Text:null,sampleText:"n=0",sampleTitle:"No observations in this cohort",sparse:!0}:{available:!0,p50Text:n.p50===null?null:l(n.p50),p95Text:n.p95===null?null:l(n.p95),sampleText:Wy(n.n),sampleTitle:`Sample size ${n.n}${Md(n.n)?" — fewer than 5 observations, compare with care":""}`,sparse:Md(n.n)}}function ja(n,l,s){if(n.sum===null||n.known===0)return{available:!1,valueText:"N/A",exactText:null,noteText:null,noteTitle:null,incomplete:n.known<n.total};const u=l(n.sum),d=s!=null&&s.compact?g2(n.sum):u,f=n.known<n.total;return{available:!0,valueText:d,exactText:s!=null&&s.compact?u:null,noteText:f?`${Je(n.known)}/${Je(n.total)} known`:null,noteTitle:f?"Partial sample — missing provider metadata is excluded, never zero":null,incomplete:f}}function Hs(n,l,s){return n===null||l===0?{available:!1,valueText:"N/A",evidenceCounts:null,evidenceNoun:null,title:`No ${s} in this cohort`}:{available:!0,valueText:Bu(n),evidenceCounts:`${Je(Math.round(n*l))}/${Je(l)}`,evidenceNoun:s,title:`Exact share over ${l} ${s}`}}function $x(n,l,s){const u=Hs(n,l,s);return u.available?{text:`${u.valueText} (${u.evidenceCounts} ${u.evidenceNoun})`,title:u.title}:{text:u.valueText,title:u.title}}function md(n){const l=$x(n.issueSuccess,n.issueSuccessDenominator,"closed"),s=$x(n.attemptSuccess,n.attemptSuccessDenominator,"terminal attempts");return{key:n.key,issuesText:Je(n.issues),attemptsText:Je(n.attempts),issueSuccessText:l.text,issueSuccessTitle:l.title,attemptSuccessText:s.text,attemptSuccessTitle:s.title,issueSuccessDisplay:Hs(n.issueSuccess,n.issueSuccessDenominator,"closed"),attemptSuccessDisplay:Hs(n.attemptSuccess,n.attemptSuccessDenominator,"terminal attempts"),wallText:Ax(n.sessionWallMs,Kt),envelopeText:Ax(n.spawnEnvelopeMs,Kt),retryText:n.retryRate===null?"N/A":Bu(n.retryRate),retryTitle:"Extra attempts after a terminal attempt in the same issue/role/round ÷ attempts",tokensInText:ll(n.tokensIn,Je),tokensOutText:ll(n.tokensOut,Je),costText:ll(n.costUsd,Ls),costIncomplete:n.costUsd.known<n.costUsd.total,durationText:ll(n.durationMs,Kt),failedCostText:ll(n.failedCostUsd,Ls),failedTokensText:`${ll(n.failedTokensIn,Je)} in · ${ll(n.failedTokensOut,Je)} out`,failedDurationText:ll(n.failedDurationMs,Kt),wall:Ri(n.sessionWallMs,Kt),envelope:Ri(n.spawnEnvelopeMs,Kt),tokensIn:ja(n.tokensIn,Je,{compact:!0}),tokensOut:ja(n.tokensOut,Je,{compact:!0}),cost:ja(n.costUsd,Ls),duration:ja(n.durationMs,Kt),failedCost:ja(n.failedCostUsd,Ls),failedTokensIn:ja(n.failedTokensIn,Je,{compact:!0}),failedTokensOut:ja(n.failedTokensOut,Je,{compact:!0}),failedDuration:ja(n.failedDurationMs,Kt),failedIncomplete:n.failedCostUsd.known<n.failedCostUsd.total||n.failedTokensIn.known<n.failedTokensIn.total||n.failedTokensOut.known<n.failedTokensOut.total||n.failedDurationMs.known<n.failedDurationMs.total,sparse:n.attempts>0&&Md(n.attempts)}}function kj(n,l){const s=n.code==="unknown";return{code:n.code,domain:n.domain,countText:Je(n.count),shareText:n.share===null?"N/A":Bu(n.share),shareTitle:l>0?`${Je(n.count)} of ${Je(l)} issues with a failed attempt`:"No issues with a failed attempt in scope",isUnknown:s,blurb:s?"Ambiguous evidence — not promoted to a specific cause.":`Primary cause · ${n.domain} domain`,displayCode:s?"Cause not recorded":n.code,displayNote:s?"Needs more evidence":`Primary cause · ${n.domain} domain`,issueIds:n.issueIds,hiddenIssueCount:Math.max(0,n.issueTotal-n.issueIds.length)}}function Aj(n){const l=n.reduce((s,u)=>s+u.count,0);return n.map(s=>kj(s,l))}function Ej(n){return`/issues/${n}`}function Yx(n,l){if(n!=null&&n.trim()&&/^\d{4}-\d{2}-\d{2}$/.test(n.trim()))return l?`${n.trim()}T23:59:59.999Z`:`${n.trim()}T00:00:00.000Z`}function Vx(n){if(!n)return"";const l=n.match(/^(\d{4}-\d{2}-\d{2})/);return l?l[1]:""}function Zx(n){const l=new URLSearchParams(n.startsWith("?")?n.slice(1):n),s=u=>{var d;return((d=l.get(u))==null?void 0:d.trim())??""};return{fromDate:Vx(s("from")),toDate:Vx(s("to")),repo:s("repo"),role:s("role"),runtime:s("runtime"),model:s("model"),status:s("status")}}function Cj(n){const l=new URLSearchParams(n.startsWith("?")?n.slice(1):n),s=d=>{var m;const f=(m=l.get(d))==null?void 0:m.trim();return f||void 0},u={};for(const d of["from","to","repo","role","runtime","model","status"]){const f=s(d);f!==void 0&&(u[d]=f)}return u}function Rj(n,l,s){const u=new URLSearchParams(n.startsWith("?")?n.slice(1):n);u.set(l,s),u.delete("page"),u.delete("limit"),u.sort();const d=u.toString();return`/reports/execution${d?`?${d}`:""}`}function Tj(n){return{from:Yx(n.fromDate,!1),to:Yx(n.toDate,!0),repo:n.repo.trim()||void 0,role:n.role||void 0,runtime:n.runtime.trim()||void 0,model:n.model.trim()||void 0,status:n.status.trim()||void 0}}function pd(n){return n===null?"N/A":Bu(n)}function Ba({label:n,value:l,valueTitle:s,note:u}){return r.jsxs("div",{className:"rounded border border-white/10 bg-panel-elevated/60 px-4 py-3",children:[r.jsx("p",{className:"font-ui-display text-xs uppercase tracking-wide text-white/40",children:n}),r.jsx("div",{className:"mt-1 font-mono text-lg font-semibold text-white/90 tabular-nums",title:s,children:l}),u&&r.jsx("div",{className:"mt-0.5 font-ui-display text-xs text-white/40",children:u})]})}function ku({display:n,compact:l}){if(!n.available)return r.jsx("span",{className:"font-mono text-white/45",title:n.title,children:"N/A"});const s=l?"font-mono text-sm font-medium text-white/85 tabular-nums leading-tight whitespace-nowrap":"font-mono text-base sm:text-lg font-semibold text-white/90 tabular-nums leading-tight whitespace-nowrap";return r.jsxs("span",{className:"inline-flex flex-wrap items-baseline gap-x-2",title:n.title,children:[r.jsx("span",{className:s,"aria-label":n.title,children:n.valueText}),r.jsxs("span",{className:"font-ui-display min-w-0 break-words text-xs text-white/40",children:["(",r.jsx("span",{className:"font-mono tabular-nums",children:n.evidenceCounts})," ",n.evidenceNoun,")"]})]})}function Ms({display:n,compact:l}){if(!n.available)return r.jsx("span",{className:"font-mono text-white/45",children:"N/A"});const s=l?"font-ui-display text-[11px] uppercase tracking-wide text-white/40":"font-ui-display text-xs uppercase tracking-wide text-white/40",u=l?"font-mono text-sm font-medium text-white/85 tabular-nums":"font-mono text-base font-semibold text-white/90 tabular-nums";return r.jsxs("span",{className:"inline-flex flex-wrap items-baseline gap-x-3 gap-y-0.5",children:[r.jsxs("span",{className:"inline-flex items-baseline gap-x-1.5",children:[r.jsx("span",{className:s,children:"P50"}),r.jsx("span",{className:u,children:n.p50Text??"N/A"})]}),r.jsxs("span",{className:"inline-flex items-baseline gap-x-1.5",children:[r.jsx("span",{className:s,children:"P95"}),r.jsx("span",{className:u,children:n.p95Text??"N/A"})]}),r.jsx("span",{className:"font-ui-display text-xs text-white/40",title:n.sampleTitle,children:n.sampleText})]})}function Na({display:n,compact:l}){if(!n.available)return r.jsx("span",{className:"font-mono text-white/45",children:"N/A"});const s=n.exactText??n.valueText,u=l?"font-mono text-sm font-medium text-white/85 tabular-nums":"font-mono text-base font-semibold text-white/90 tabular-nums";return r.jsxs("span",{className:"inline-flex flex-wrap items-baseline gap-x-2",children:[r.jsx("span",{className:u,title:s,"aria-label":s,children:n.valueText}),n.noteText&&r.jsx("span",{className:"font-ui-display text-xs text-white/40",title:n.noteTitle??void 0,children:n.noteText})]})}function xd({caption:n,dimension:l,rows:s,cohortLink:u}){return s.length===0?r.jsxs("div",{className:"rounded border border-white/10 bg-panel-elevated/60 px-4 py-3",children:[r.jsx("h4",{className:"font-ui-display text-sm font-medium text-white/80",children:n}),r.jsx("p",{className:"font-ui-display mt-1 text-sm text-white/45",children:"No attempts in this dimension for these filters."})]}):r.jsx("div",{className:"rounded border border-white/10 bg-panel-elevated/60 overflow-x-auto",children:r.jsxs("table",{className:"w-full min-w-[1440px] text-sm",children:[r.jsxs("caption",{className:"sr-only",children:[n," — sorted by name, never by cost"]}),r.jsx("thead",{children:r.jsxs("tr",{className:"font-ui-display text-left text-xs uppercase tracking-wide text-white/40 border-b border-white/10",children:[r.jsx("th",{scope:"col",className:"px-4 py-2 font-medium",children:n}),r.jsx("th",{scope:"col",className:"px-3 py-2 font-medium",children:"Issues"}),r.jsx("th",{scope:"col",className:"px-3 py-2 font-medium",children:"Attempts"}),r.jsx("th",{scope:"col",className:"px-3 py-2 font-medium",children:"Issue success"}),r.jsx("th",{scope:"col",className:"px-3 py-2 font-medium",children:"Attempt success"}),r.jsx("th",{scope:"col",className:"px-3 py-2 font-medium",children:"Session wall P50/P95"}),r.jsx("th",{scope:"col",className:"px-3 py-2 font-medium",children:"Retry rate"}),r.jsx("th",{scope:"col",className:"px-3 py-2 font-medium",children:"Tokens in"}),r.jsx("th",{scope:"col",className:"px-3 py-2 font-medium",children:"Tokens out"}),r.jsx("th",{scope:"col",className:"px-3 py-2 font-medium",children:"Cost"}),r.jsx("th",{scope:"col",className:"px-3 py-2 font-medium",children:"Duration"}),r.jsx("th",{scope:"col",className:"px-3 py-2 font-medium",children:"Failed cost"}),r.jsx("th",{scope:"col",className:"px-3 py-2 font-medium",children:"Failed tokens"}),r.jsx("th",{scope:"col",className:"px-3 py-2 font-medium",children:"Failed runtime"})]})}),r.jsx("tbody",{className:"divide-y divide-white/5",children:s.map(d=>r.jsxs("tr",{className:"tabular-nums",children:[r.jsxs("th",{scope:"row",className:"px-4 py-2 text-left font-mono font-medium text-white/85",children:[u?r.jsx(sa,{to:u(l,d.key),className:"text-cyber-teal hover:underline focus-visible:outline focus-visible:outline-2 focus-visible:outline-cyber-teal/45",title:`Filter the report to ${l} ${d.key}`,children:d.key}):d.key,d.sparse&&r.jsx("span",{className:"font-ui-display ml-2 text-xs font-normal text-amber-200/80",title:"Fewer than 5 attempts — compare with care",children:"sparse"})]}),r.jsx("td",{className:"px-3 py-2 font-mono text-white/75",children:d.issuesText}),r.jsx("td",{className:"px-3 py-2 font-mono text-white/75",children:d.attemptsText}),r.jsx("td",{className:"px-3 py-2 text-white/75",title:d.issueSuccessTitle,children:r.jsx(ku,{display:d.issueSuccessDisplay,compact:!0})}),r.jsx("td",{className:"px-3 py-2 text-white/75",title:d.attemptSuccessTitle,children:r.jsx(ku,{display:d.attemptSuccessDisplay,compact:!0})}),r.jsx("td",{className:"px-3 py-2 text-white/75",children:r.jsx(Ms,{display:d.wall,compact:!0})}),r.jsx("td",{className:"px-3 py-2 font-mono text-white/75",title:d.retryTitle,children:d.retryText}),r.jsx("td",{className:"px-3 py-2 text-white/75",children:r.jsx(Na,{display:d.tokensIn,compact:!0})}),r.jsx("td",{className:"px-3 py-2 text-white/75",children:r.jsx(Na,{display:d.tokensOut,compact:!0})}),r.jsx("td",{className:"px-3 py-2 text-white/75",children:r.jsx(Na,{display:d.cost,compact:!0})}),r.jsx("td",{className:"px-3 py-2 text-white/75",children:r.jsx(Na,{display:d.duration,compact:!0})}),r.jsx("td",{className:"px-3 py-2 text-white/75",children:r.jsx(Na,{display:d.failedCost,compact:!0})}),r.jsx("td",{className:"px-3 py-2 text-white/75",children:r.jsxs("span",{className:"inline-flex flex-wrap items-baseline gap-x-1.5",children:[r.jsx(Na,{display:d.failedTokensIn,compact:!0}),r.jsx("span",{className:"font-ui-display text-xs text-white/40",children:"in"}),r.jsx("span",{className:"font-ui-display text-xs text-white/40",children:"·"}),r.jsx(Na,{display:d.failedTokensOut,compact:!0}),r.jsx("span",{className:"font-ui-display text-xs text-white/40",children:"out"})]})}),r.jsx("td",{className:"px-3 py-2 text-white/75",children:r.jsx(Na,{display:d.failedDuration,compact:!0})})]},d.key))})]})})}const Oj={fromDate:"",toDate:"",repo:"",role:"",runtime:"",model:"",status:""};function Lj({loading:n,error:l,report:s,onRetry:u,cohortLink:d}){const f=(s==null?void 0:s.summary)??null,m=b.useMemo(()=>s?Aj(s.failures):[],[s]),x=b.useMemo(()=>s?s.failures.reduce((y,v)=>y+v.count,0):0,[s]);return r.jsxs("div",{"aria-live":"polite",children:[n&&r.jsx("p",{role:"status",className:"text-sm text-white/50",children:"Loading execution report…"}),!n&&l&&r.jsxs("div",{className:"rounded border border-red-400/30 bg-red-500/10 px-4 py-3",role:"alert",children:[r.jsxs("p",{className:"font-ui-display text-sm text-red-200",children:["Couldn’t load the execution report: ",l]}),r.jsx("button",{type:"button",className:"font-ui-display mt-2 px-3 py-1.5 text-sm rounded border border-red-300/40 text-red-100 hover:bg-red-500/20",onClick:u,children:"Retry"})]}),!n&&!l&&s&&f&&r.jsxs("div",{className:"space-y-6",children:[s.meta.partial&&r.jsxs("div",{className:"rounded border border-amber-300/30 bg-amber-400/10 px-4 py-3",children:[r.jsx("p",{className:"font-ui-display text-sm text-amber-100 font-medium",children:"Partial metadata"}),r.jsx("ul",{className:"font-ui-display mt-1 list-disc list-inside text-sm text-amber-100/80",children:s.meta.partialReasons.map(y=>r.jsx("li",{children:y},y))})]}),f.issues===0?r.jsx("p",{className:"font-ui-display text-sm text-white/45",children:"No issues match these filters in this window. Widen the date range or clear filters."}):r.jsxs(r.Fragment,{children:[r.jsx("section",{"aria-label":"Summary",children:r.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 xl:grid-cols-4 gap-3",children:[r.jsx(Ba,{label:"Issue success",value:r.jsx(ku,{display:Hs(f.issueSuccess,f.closedIssues,"closed")}),valueTitle:`done / (done + closed), denominator ${f.closedIssues}`,note:`${Je(f.issues)} issues · ${Je(f.closedIssues)} closed`}),r.jsx(Ba,{label:"Attempt success",value:r.jsx(ku,{display:Hs(f.attemptSuccess,f.terminalAttempts,"terminal")}),valueTitle:`done sessions / terminal sessions, denominator ${f.terminalAttempts}`,note:`${Je(f.attempts)} attempts · ${Je(f.terminalAttempts)} terminal`}),r.jsx(Ba,{label:"Retry rate",value:pd(f.retryRate),valueTitle:`${f.retryExtraAttempts} extra attempts after a terminal attempt in the same issue/role/round ÷ ${f.attempts} attempts`,note:`Reuse rate ${pd(f.reuseRate)} over ${Je(f.reuseDenominator)} reviewer sessions with input SHA`}),r.jsx(Ba,{label:"Human wait",value:Kt(f.humanWaitMs),note:`${Je(f.interventions)} interventions`}),r.jsx(Ba,{label:"Session wall P50/P95",value:r.jsx(Ms,{display:Ri(f.sessionWallMs,Kt)}),note:"Session bookkeeping proxy — never CLI runtime"}),r.jsx(Ba,{label:"Spawn envelope P50/P95",value:r.jsx(Ms,{display:Ri(f.spawnEnvelopeMs,Kt)}),note:"Coordinator-measured; includes slot wait + post-exit work"}),r.jsx(Ba,{label:"Checkpoint latency P50/P95",value:r.jsx(Ms,{display:Ri(f.checkpointMs,Kt)}),note:"Session start → first heartbeat"}),r.jsx(Ba,{label:"Reviewer rounds (avg)",value:f.avgReviewerRounds===null?"N/A":f.avgReviewerRounds.toFixed(1),note:`Change-request rate ${pd(f.changeRequestRate)} over ${Je(f.reviewedIssues)} reviewed`})]})}),r.jsxs("section",{"aria-label":"Failed-attempt waste",children:[r.jsx("h3",{className:"font-ui-display text-sm font-medium text-white/80 mb-2",children:"Failed-attempt waste (known values only)"}),r.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-3 gap-3",children:[r.jsx(Ba,{label:"Failed cost",value:r.jsx(Na,{display:ja(f.failedCostUsd,Ls)})}),r.jsx(Ba,{label:"Failed tokens",value:r.jsxs("span",{className:"inline-flex flex-wrap items-baseline gap-x-2",children:[r.jsx(Na,{display:ja(f.failedTokensIn,Je,{compact:!0})}),r.jsx("span",{className:"font-ui-display text-xs font-normal text-white/40",children:"in"}),r.jsx("span",{className:"font-ui-display text-xs font-normal text-white/40",children:"·"}),r.jsx(Na,{display:ja(f.failedTokensOut,Je,{compact:!0})}),r.jsx("span",{className:"font-ui-display text-xs font-normal text-white/40",children:"out"})]})}),r.jsx(Ba,{label:"Failed runtime",value:r.jsx(Na,{display:ja(f.failedDurationMs,Kt)})})]})]}),r.jsxs("section",{"aria-label":"Phase wall time",children:[r.jsx("h3",{className:"font-ui-display text-sm font-medium text-white/80 mb-2",children:"Phase wall time"}),r.jsx("p",{className:"font-ui-display text-xs text-white/40 mb-2",children:"Composed from the execution-analysis read model over the same issues: exact when agent start/complete events are recorded, inferred usage-envelope backfill otherwise. Rows without evidence read N/A — never a guess. See per-row reasons."}),r.jsx("div",{className:"rounded border border-white/10 bg-panel-elevated/60 overflow-x-auto",children:r.jsxs("table",{className:"w-full min-w-[560px] text-sm",children:[r.jsx("caption",{className:"sr-only",children:"Exclusive phase wall times. Boundaries without defensible evidence are N/A."}),r.jsx("thead",{children:r.jsxs("tr",{className:"font-ui-display text-left text-xs uppercase tracking-wide text-white/40 border-b border-white/10",children:[r.jsx("th",{scope:"col",className:"px-4 py-2 font-medium",children:"Phase"}),r.jsx("th",{scope:"col",className:"px-3 py-2 font-medium",children:"P50 / P95"}),r.jsx("th",{scope:"col",className:"px-3 py-2 font-medium",children:"Why"})]})}),r.jsx("tbody",{className:"divide-y divide-white/5",children:f.phaseWallMs.map(y=>r.jsxs("tr",{className:"tabular-nums",children:[r.jsx("th",{scope:"row",className:"px-4 py-2 text-left font-mono font-medium text-white/85",children:y.phase}),r.jsx("td",{className:"px-3 py-2 text-white/75",children:r.jsx(Ms,{display:Ri(y.stat,Kt),compact:!0})}),r.jsx("td",{className:"font-ui-display px-3 py-2 text-xs text-white/45",children:y.stat.reasons.join(", ")})]},y.phase))})]})})]}),r.jsxs("section",{"aria-label":"Comparisons",className:"space-y-4",children:[r.jsxs("h3",{className:"font-ui-display text-sm font-medium text-white/80",children:["Comparisons ",r.jsx("span",{className:"font-normal text-white/40",children:"— sorted by name, never by cost"})]}),r.jsx(xd,{caption:"By role",dimension:"role",rows:s.byRole.map(md),cohortLink:d}),r.jsx(xd,{caption:"By runtime",dimension:"runtime",rows:s.byRuntime.map(md),cohortLink:d}),r.jsx(xd,{caption:"By model",dimension:"model",rows:s.byModel.map(md),cohortLink:d})]}),r.jsxs("section",{"aria-label":"Why attempts failed",children:[r.jsx("h3",{className:"font-ui-display text-sm font-medium text-white/80 mb-2",children:"Why attempts failed"}),r.jsxs("p",{className:"font-ui-display text-xs text-white/40 mb-2",children:["Each issue with a failed attempt is counted once using its primary actionable cause, and may later have recovered. Share is over"," ",Je(x)," failed ",x===1?"issue":"issues"," in scope."]}),m.length===0?r.jsx("p",{className:"font-ui-display text-sm text-white/45",children:"No failed attempts in this window."}):r.jsx("div",{className:"rounded border border-white/10 bg-panel-elevated/60 overflow-x-auto",children:r.jsxs("table",{className:"w-full min-w-[560px] text-sm",children:[r.jsx("caption",{className:"sr-only",children:"Why attempts failed: each issue counted once by primary cause. Cause not recorded is its own bucket and is never promoted."}),r.jsx("thead",{children:r.jsxs("tr",{className:"font-ui-display text-left text-xs uppercase tracking-wide text-white/40 border-b border-white/10",children:[r.jsx("th",{scope:"col",className:"px-4 py-2 font-medium",children:"Failure"}),r.jsx("th",{scope:"col",className:"px-3 py-2 font-medium",children:"Domain"}),r.jsx("th",{scope:"col",className:"px-3 py-2 font-medium",children:"Issues"}),r.jsx("th",{scope:"col",className:"px-3 py-2 font-medium",children:"Share"}),r.jsx("th",{scope:"col",className:"px-3 py-2 font-medium",children:"Example issues"})]})}),r.jsx("tbody",{className:"divide-y divide-white/5",children:m.map(y=>r.jsxs("tr",{className:y.isUnknown?"bg-amber-400/5 tabular-nums":"tabular-nums",children:[r.jsxs("th",{scope:"row",className:"px-4 py-2 text-left text-white/85",children:[r.jsx("span",{className:"font-ui-display block font-medium",title:y.code,children:y.displayCode}),r.jsx("span",{className:`font-ui-display block text-xs font-normal ${y.isUnknown?"text-amber-200/90":"text-white/40"}`,children:y.displayNote})]}),r.jsx("td",{className:"px-3 py-2 font-mono text-white/75",children:y.domain}),r.jsx("td",{className:"px-3 py-2 font-mono text-white/75",children:y.countText}),r.jsx("td",{className:"px-3 py-2 font-mono text-white/75",title:y.shareTitle,children:y.shareText}),r.jsx("td",{className:"px-3 py-2",children:r.jsxs("span",{className:"flex flex-wrap gap-x-3 gap-y-1",children:[y.issueIds.map(v=>r.jsx(sa,{to:Ej(v),className:"text-cyber-teal hover:underline font-mono text-xs",children:v.slice(0,8)},v)),y.hiddenIssueCount>0&&r.jsxs("span",{className:"font-ui-display text-xs text-white/40",children:["+",y.hiddenIssueCount," more"]})]})})]},y.code))})]})})]})]})]})]})}function Mj(){const[n,l]=Ny(),s=n.toString(),u=b.useMemo(()=>Cj(s),[s]),[d,f]=b.useState(()=>Zx(s)),[m,x]=b.useState(null),[y,v]=b.useState(!0),[w,j]=b.useState(null),[D,X]=b.useState(0);b.useEffect(()=>{f(Zx(s))},[s]),b.useEffect(()=>{let L=!1;return v(!0),j(null),uS(u).then(H=>{L||(x(H),v(!1))}).catch(H=>{L||(j(H instanceof Error?H.message:String(H)),v(!1))}),()=>{L=!0}},[s,D]);const E=L=>{const H=Fy(Tj(L));l(H?Object.fromEntries(new URLSearchParams(H)):{})},$=L=>f(H=>({...H,...L}));return r.jsxs("div",{className:"flex-1 min-h-0 px-6 py-4 w-full overflow-y-auto",children:[r.jsxs("div",{className:"flex flex-wrap items-baseline justify-between gap-2 mb-1",children:[r.jsx("h2",{className:"font-ui-display text-lg font-semibold text-white/90",children:"Execution report"}),m&&r.jsxs("p",{className:"font-ui-display text-xs text-white/40",children:["Window ",new Date(m.window.from).toLocaleDateString()," –"," ",new Date(m.window.to).toLocaleDateString()," · generated"," ",new Date(m.meta.generatedAt).toLocaleTimeString()]})]}),r.jsx("p",{className:"font-ui-display text-sm text-white/50 mb-4",children:"Reliability, latency, retry waste, and metadata coverage by role, runtime, and model. Missing cost/token data reads as N/A — never as zero."}),r.jsx("form",{"aria-label":"Report filters",className:"mb-4 p-4 rounded border border-white/10 bg-panel-elevated/60",onSubmit:L=>{L.preventDefault(),E(d)},children:r.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-3",children:[r.jsxs("label",{className:"block text-sm",children:[r.jsx("span",{className:"font-ui-display block text-xs text-white/50 mb-1",children:"From"}),r.jsx("input",{type:"date",className:"w-full bg-black/30 border border-white/10 rounded px-3 py-2",value:d.fromDate,onChange:L=>$({fromDate:L.target.value})})]}),r.jsxs("label",{className:"block text-sm",children:[r.jsx("span",{className:"font-ui-display block text-xs text-white/50 mb-1",children:"To"}),r.jsx("input",{type:"date",className:"w-full bg-black/30 border border-white/10 rounded px-3 py-2",value:d.toDate,onChange:L=>$({toDate:L.target.value})})]}),r.jsxs("label",{className:"block text-sm",children:[r.jsx("span",{className:"font-ui-display block text-xs text-white/50 mb-1",children:"Repository"}),r.jsx("input",{type:"text",placeholder:"github.com/owner/repo",className:"w-full bg-black/30 border border-white/10 rounded px-3 py-2",value:d.repo,onChange:L=>$({repo:L.target.value})})]}),r.jsxs("label",{className:"block text-sm",children:[r.jsx("span",{className:"font-ui-display block text-xs text-white/50 mb-1",children:"Role"}),r.jsxs("select",{className:"w-full bg-black/30 border border-white/10 rounded px-3 py-2",value:d.role,onChange:L=>$({role:L.target.value}),children:[r.jsx("option",{value:"",children:"All roles"}),Nj.map(L=>r.jsx("option",{value:L,children:L},L))]})]}),r.jsxs("label",{className:"block text-sm",children:[r.jsx("span",{className:"font-ui-display block text-xs text-white/50 mb-1",children:"Runtime"}),r.jsxs("select",{className:"w-full bg-black/30 border border-white/10 rounded px-3 py-2",value:d.runtime,onChange:L=>{$({runtime:L.target.value})},children:[r.jsx("option",{value:"",children:"All runtimes"}),Hx.map(L=>r.jsx("option",{value:L,children:L},L)),r.jsx("option",{value:"unknown",children:"unknown (missing metadata)"}),d.runtime&&!Hx.includes(d.runtime)&&r.jsxs("option",{value:d.runtime,children:[d.runtime," (from URL)"]})]})]}),r.jsxs("label",{className:"block text-sm",children:[r.jsx("span",{className:"font-ui-display block text-xs text-white/50 mb-1",children:"Model"}),r.jsx("input",{type:"text",placeholder:"Any model",className:"w-full bg-black/30 border border-white/10 rounded px-3 py-2",value:d.model,onChange:L=>$({model:L.target.value})})]}),r.jsxs("label",{className:"block text-sm",children:[r.jsx("span",{className:"font-ui-display block text-xs text-white/50 mb-1",children:"Issue status"}),r.jsxs("select",{className:"w-full bg-black/30 border border-white/10 rounded px-3 py-2",value:d.status,onChange:L=>$({status:L.target.value}),children:[r.jsx("option",{value:"",children:"All statuses"}),_j.map(L=>r.jsx("option",{value:L,children:L},L))]})]}),r.jsxs("div",{className:"flex items-end gap-2",children:[r.jsx("button",{type:"submit",className:"btn-gold px-4",children:"Apply"}),r.jsx("button",{type:"button",className:"font-ui-display px-4 py-2 text-sm text-white/60 hover:text-white",onClick:()=>{f(Oj),l({})},children:"Reset"})]})]})}),r.jsx(Lj,{loading:y,error:w,report:m,onRetry:()=>X(L=>L+1),cohortLink:(L,H)=>Rj(s,L,H)})]})}function Gx(n,l){var d;if(!n)return"Not assigned";const s=l.find(f=>f.id===n);if(!s)return"Unavailable — profile removed";const u=`${s.name} · ${Aa(s.runtime)}`;return s.healthy?u:`${u} (unhealthy: ${((d=s.issues[0])==null?void 0:d.message)??"needs attention"})`}function Qx(n,l){var u;if(!n)return;const s=l.find(d=>d.id===n);return s?`${s.name} · ${Aa(s.runtime)}${s.healthy?" · healthy":` · ${((u=s.issues[0])==null?void 0:u.message)??"unhealthy"}`}`:`Configured profile ${n} is not on record (deleted?)`}function Dj({agents:n,initialRepo:l,initialDeveloperId:s,initialReviewerId:u,busy:d,onSave:f,onCancel:m}){var P,ne;const[x,y]=b.useState(l),[v,w]=b.useState(s??""),[j,D]=b.useState(u??""),X=gv(n),E=n.find(V=>V.id===v),$=n.find(V=>V.id===j),L=Nu(E),H=Nu($),F=x.trim()===l&&v===(s??"")&&j===(u??"");return r.jsxs("div",{className:"p-3 rounded border border-white/10 bg-panel-elevated/60 space-y-2",children:[r.jsx("p",{className:"text-xs text-white/50",children:"Edit configuration — repository, developer, and reviewer save together. Queue position is kept, readiness and the wait reason are rechecked, and the change is recorded on the timeline."}),r.jsxs("label",{className:"block space-y-1",children:[r.jsx("span",{className:"text-xs text-white/45 uppercase tracking-wide",children:"Repository"}),r.jsx("input",{className:"w-full bg-black/30 border border-white/10 rounded px-3 py-2 text-sm",value:x,disabled:d,placeholder:"GitHub URL or owner/repo",title:"GitHub URL or owner/repo — normalized to github.com/owner/repo, same validation as issue creation",onChange:V=>y(V.target.value)})]}),r.jsxs("label",{className:"block space-y-1",children:[r.jsx("span",{className:"text-xs text-white/45 uppercase tracking-wide",children:"Developer"}),r.jsxs("select",{className:"w-full bg-black/30 border border-white/10 rounded px-3 py-2 text-sm",value:v,disabled:d,title:E?`${E.name} · ${Aa(E.runtime)}${E.healthy?" · healthy":` · ${((P=E.issues[0])==null?void 0:P.message)??"unhealthy"}`}`:"Pick a developer agent",onChange:V=>w(V.target.value),children:[r.jsx("option",{value:"",children:"Developer agent…"}),X.map(V=>r.jsx("option",{value:V.id,title:rl(V),children:(V.healthy?"● ":"○ ")+rl(V)},V.id))]}),L&&r.jsx("span",{className:"text-xs text-amber-200/80 block",children:L})]}),r.jsxs("label",{className:"block space-y-1",children:[r.jsx("span",{className:"text-xs text-white/45 uppercase tracking-wide",children:"Reviewer"}),r.jsxs("select",{className:"w-full bg-black/30 border border-white/10 rounded px-3 py-2 text-sm",value:j,disabled:d,title:$?`${$.name} · ${Aa($.runtime)}${$.healthy?" · healthy":` · ${((ne=$.issues[0])==null?void 0:ne.message)??"unhealthy"}`}`:"Pick a reviewer agent",onChange:V=>D(V.target.value),children:[r.jsx("option",{value:"",children:"Reviewer agent…"}),X.map(V=>V.runtime==="muse_code"?r.jsx("option",{value:V.id,disabled:!0,title:"Muse Code cannot be a reviewer (developer role only)",children:`○ ${V.name} · ${Aa(V.runtime)} — reviewer not supported`},V.id):r.jsx("option",{value:V.id,title:rl(V),children:(V.healthy?"● ":"○ ")+rl(V)},V.id))]}),H&&r.jsx("span",{className:"text-xs text-amber-200/80 block",children:H})]}),r.jsxs("div",{className:"flex gap-2",children:[r.jsx("button",{type:"button",className:"btn-gold px-4 py-1.5 text-sm disabled:opacity-50",disabled:d||!x.trim()||!v||!j||F,title:"Save via the issue PATCH contract — keeps queue position, rechecks readiness and the wait reason",onClick:()=>f(x.trim(),v,j),children:"Save configuration"}),r.jsx("button",{type:"button",className:"px-4 py-1.5 text-sm text-white/60 hover:text-white disabled:opacity-50",disabled:d,onClick:m,children:"Cancel"})]})]})}function Uj({issue:n,agents:l,canEdit:s,editing:u,busy:d,onBeginEdit:f,onSave:m,onCancel:x}){return r.jsxs("div",{className:"mb-4 p-3 rounded border border-white/10 bg-white/[0.03] space-y-1.5",children:[r.jsx("p",{className:"text-xs text-white/45 uppercase tracking-wide",children:"Configuration"}),r.jsxs("p",{className:"text-sm text-white/85",title:`Exact repository identity: ${n.repo}`,children:[r.jsx("span",{className:"text-white/45",children:"Repository "}),n.repo]}),r.jsxs("p",{className:"text-sm text-white/85",title:Qx(n.developerAgentId,l),children:[r.jsx("span",{className:"text-white/45",children:"Developer "}),Gx(n.developerAgentId,l)]}),r.jsxs("p",{className:"text-sm text-white/85",title:Qx(n.reviewerAgentId,l),children:[r.jsx("span",{className:"text-white/45",children:"Reviewer "}),Gx(n.reviewerAgentId,l)]}),s&&!u&&r.jsx("button",{type:"button",className:"text-xs text-cyber-teal hover:underline disabled:opacity-50",disabled:d,onClick:f,children:"Edit configuration"}),s&&u&&r.jsx(Dj,{agents:l,initialRepo:n.repo,initialDeveloperId:n.developerAgentId,initialReviewerId:n.reviewerAgentId,busy:d,onSave:m,onCancel:x})]})}function zj({contract:n}){return r.jsxs("section",{"aria-label":"Execution contract",className:"mb-4 p-3 rounded border border-white/10 bg-white/[0.03] space-y-2",children:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("p",{className:"text-xs text-white/45 uppercase tracking-wide",children:"Execution contract"}),r.jsx("span",{className:"text-[11px] px-1.5 py-0.5 rounded border border-cyber-teal/40 text-cyber-teal",children:n.version}),r.jsx("span",{className:"text-[11px] px-1.5 py-0.5 rounded border border-white/15 text-white/70",children:n.executionMode})]}),r.jsxs("div",{className:"text-sm text-white/85 space-y-1.5",children:[r.jsxs("p",{children:[r.jsx("span",{className:"text-white/45",children:"Exit predicate: "}),n.exitPredicate]}),r.jsxs("p",{children:[r.jsx("span",{className:"text-white/45",children:"One-PR stopping point: "}),n.onePrStoppingPoint]}),r.jsxs("div",{children:[r.jsx("p",{className:"text-white/45",children:"Non-goals:"}),r.jsx("ul",{className:"list-disc pl-5 text-white/75",children:n.nonGoals.map(l=>r.jsx("li",{children:l},l))})]}),r.jsxs("div",{children:[r.jsx("p",{className:"text-white/45",children:"Acceptance criteria:"}),r.jsx("ul",{className:"space-y-1",children:n.acceptanceCriteria.map(l=>r.jsxs("li",{children:[r.jsxs("p",{className:"text-white/80",children:["☐ ",l.text]}),l.evidence&&r.jsxs("p",{className:"pl-5 text-xs text-white/55",children:["Evidence: ",l.evidence]})]},l.text))})]})]}),r.jsx("p",{className:"text-[11px] text-white/35",children:"Compiled from the ticket description — edit the description to change it."})]})}function Bj(n){return n===void 0?"unknown size":`${n.toLocaleString("en-US")} bytes`}function qj({attachments:n}){if(!(n!=null&&n.length))return null;const l=n.filter(u=>u.kind==="file"),s=n.filter(u=>u.kind==="link");return r.jsxs("div",{className:"mb-4 p-3 rounded border border-white/10 bg-white/[0.03] space-y-1","data-testid":"source-attachments",children:[r.jsx("p",{className:"text-xs text-white/45 font-medium uppercase tracking-wide",children:"Source attachments"}),l.map(u=>r.jsxs("p",{className:"text-sm text-white/85","data-testid":"source-attachment-file",children:[r.jsx("span",{className:"text-cyber-teal",children:"file"})," ",u.safeFileName??u.title,r.jsxs("span",{className:"text-white/45",children:[" ","· ",Bj(u.sizeBytes),u.sha256?` · sha256:${u.sha256.slice(0,16)}…`:"",u.contentType?` · ${u.contentType}`:""]})]},u.linearAttachmentId)),s.map(u=>r.jsxs("p",{className:"text-sm text-white/85","data-testid":"source-attachment-link",children:[r.jsx("span",{className:"text-amber-300",children:"link"})," ",u.title,r.jsxs("span",{className:"text-white/45",children:[" ","· ",u.url,u.subtitle?` · ${u.subtitle}`:""]})]},u.linearAttachmentId)),r.jsx("p",{className:"text-xs text-white/40",children:"Files are Dealer-stored snapshots — the Builder reads local bytes, never the expiring Linear URL. Links are metadata only, never downloaded. Files uploaded only inside Linear comments are not imported."})]})}function su(n){return n==="developer"?"Developer":n==="reviewer"?"Reviewer":"Worker"}const yd={"issue.created":()=>"Issue created","issue.reassigned":()=>"Configuration updated","issue.source_reloaded":()=>"Task text reloaded from Linear","workflow.started":()=>"Workflow started","worker.started":n=>`${su(n.actorType)} started${n.round?` (round ${n.round})`:""}`,"worker.completed":n=>`${su(n.actorType)} finished${n.round?` (round ${n.round})`:""}`,"worker.failed":n=>`${su(n.actorType)} failed${n.round?` (round ${n.round})`:""}`,"worker.deferred":n=>{var l;return((l=Ti(n.payloadJson))==null?void 0:l.outcome)==="deck_unavailable"?`Waiting for Agent Deck${n.round?` (round ${n.round})`:""}`:`${su(n.actorType)} deferred${n.round?` (round ${n.round})`:""}`},"worktree.ready":()=>"Worktree ready","worktree.deps_ready":()=>"Dependencies ready","deck.connected":()=>"Deck connected","brief.resolved":()=>"Brief resolved","base.probe":n=>{var s;const l=(s=Ti(n.payloadJson))==null?void 0:s.result;return l==="conflict"?"Base conflict found before publish":l==="skipped"?"Base conflict probe skipped":l==="deferred"?"Base conflict probe waiting on base fetch":l==="failed"?"Base conflict probe failed; not published":"Base conflict probe clean"},"branch.pushed":()=>"Branch pushed","checks.started":()=>"Checks started","pull_request.opened":()=>"Developer opened the PR","pull_request.updated":()=>"Developer updated the PR","checks.completed":()=>"Checks completed","review.submitted":()=>"Reviewer submitted a review","repair.started":n=>`Repair round ${n.round??"?"} started`,"guidance.added":()=>"Guidance added","task_snapshot.refreshed":()=>"Task snapshot refreshed","human_action.requested":()=>"Human action requested","human_action.resolved":()=>"Human action resolved","final_review.requested":()=>"Final review requested","issue.completed":()=>"Issue completed","issue.closed":()=>"Issue closed"};function Ti(n){if(!n)return null;try{return JSON.parse(n)}catch{return null}}const Hj={approved:"text-cyber-teal",changes_requested:"text-amber-300",escalated:"text-red-300"};function $j({e:n}){var l;if(n.type==="pull_request.opened"||n.type==="pull_request.updated"){const s=Ti(n.payloadJson);return n.artifactRef?r.jsxs("a",{href:n.artifactRef,target:"_blank",rel:"noreferrer",className:"text-sm text-cyber-teal hover:underline",children:["PR ",s!=null&&s.prNumber?`#${s.prNumber}`:""," ",s!=null&&s.branch?`(${s.branch})`:""]}):null}if(n.type==="review.submitted"){const s=Ti(n.payloadJson);return s?r.jsxs("span",{className:"text-sm",children:[r.jsx("span",{className:Hj[s.verdict]??"text-white/70",children:s.verdict.replace("_"," ")}),(l=s.findings)!=null&&l.length?` · ${s.findings.length} finding(s)`:""]}):null}if(n.type==="guidance.added"){const s=Ti(n.payloadJson);return s!=null&&s.markdown?r.jsxs("span",{className:"text-sm text-white/55 italic",children:["— ",s.markdown]}):null}if(n.type==="worker.started"||n.type==="worker.completed"||n.type==="worker.failed"||n.type==="worker.deferred"||n.type==="worktree.ready"||n.type==="deck.connected"||n.type==="brief.resolved"||n.type==="branch.pushed"||n.type==="checks.started"||n.type==="checks.completed"){const s=Ti(n.payloadJson);if(!s)return null;const u=[];return s.runtime&&u.push(s.runtime),s.model&&u.push(s.model),s.sessionId&&u.push(s.sessionId.slice(0,8)),s.worktreePath&&u.push(s.worktreePath),s.resolution&&u.push(s.resolution),s.branch&&u.push(s.branch),s.commitsAhead!=null&&u.push(`${s.commitsAhead} ahead`),s.snapshot&&u.push(s.snapshot),(n.type==="worker.deferred"||n.type==="worker.failed")&&(s.reason&&u.push(s.reason),n.type==="worker.deferred"&&s.until&&u.push(`until ${new Date(s.until).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"})}`)),u.length===0?null:r.jsxs("span",{className:"text-xs text-white/40",children:["· ",u.join(" · ")]})}return null}function Yj(n){var l;return((l=yd[n.type])==null?void 0:l.call(yd,n))??n.type}const Xx={human:"You",system:"System",developer:"Developer",reviewer:"Reviewer"},Vj={human:"bg-cyber-teal/15 text-cyber-teal",system:"bg-white/10 text-white/50",developer:"bg-cyber-violet/20 text-cyber-violet-light",reviewer:"bg-[#C4B643]/25 text-[#E8DC7A]"};function Zj(n){return n.actorRef?`${Xx[n.actorType]} · ${n.actorRef}`:Xx[n.actorType]}function Gj({events:n}){return n.length===0?r.jsx("p",{className:"text-white/40 text-sm",children:"No activity yet."}):r.jsx("div",{className:"space-y-1",children:n.map(l=>r.jsxs("div",{className:"flex items-baseline gap-3 py-1.5 border-b border-white/5 last:border-0",children:[r.jsx("span",{className:"text-xs text-white/35 w-20 shrink-0 tabular-nums",children:new Date(l.ts).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"})}),r.jsx("span",{className:`text-[11px] leading-none px-1.5 py-0.5 rounded shrink-0 ${Vj[l.actorType]}`,children:Zj(l)}),r.jsx("span",{className:"text-sm text-white/80",children:Yj(l)}),r.jsx($j,{e:l})]},l.id))})}function qa(n){if(n==null||!Number.isFinite(n))return null;if(n<1e3)return"<1s";const l=Math.round(n/1e3);if(l<60)return`${l}s`;const s=Math.floor(l/60);if(s<60){const f=l%60;return f===0?`${s}m`:`${s}m ${f}s`}const u=Math.floor(s/60),d=s%60;return d===0?`${u}h`:`${u}h ${d}m`}function Ix(n){return n==null||!Number.isFinite(n)?null:`${Math.round(n).toLocaleString("en-US")} tokens`}function Qj(n){return n==null||!Number.isFinite(n)?null:`$${n.toFixed(2)}`}const Xj={queue_wait:"Queue / admission wait",coordinator_setup:"Setup",agent_process:"Agent process",coordinator_validation_publish:"Validation / publish",coordinator_work:"Coordinator work"},Kx={model_provider_wait:"Silent · waiting on model provider",tool_or_subprocess_in_flight:"Silent · tool/subprocess in flight",host_suspended:"Silent · host suspended",no_structured_output:"Silent · no structured output yet",unknown:"Silent · unknown cause"},zd={worktree:"worktree",commit:"commit",verification_receipt:"verification receipt",publish_only:"publish-only result"},Ij=new Set(["failed","timed_out","error"]);function sf(n){return n.replace(/_/g," ")}function $s(n,l){const s=`Evidence quality: ${n}`;return l.length>0?`${s} — ${l.join(", ")}`:s}function _a({quality:n,reasons:l}){return r.jsxs("span",{className:`text-[11px] tabular-nums ${n==="exact"?"text-white/60":n==="inferred"?"text-amber-300/90":"text-white/60 italic"}`,title:$s(n,l),children:["· ",n,l.length>0&&r.jsxs("span",{className:"sr-only",children:[" (",l.join(", "),")"]})]})}function sl({reasons:n}){const l=n.length>0?n.join(", "):"no reason recorded";return r.jsxs("span",{className:"text-white/45 italic",title:`Unavailable — ${l}`,children:["Unavailable",r.jsxs("span",{className:"text-[11px]",children:[" — ",l]})]})}function ru({covered:n,format:l,unit:s}){if(n.value==null)return r.jsx(sl,{reasons:n.reasons});const u=n.known<n.total;return r.jsxs("span",{title:`${$s(n.quality,n.reasons)} · known ${n.known} of ${n.total} ${s}`,children:[l(n.value),r.jsx(_a,{quality:n.quality,reasons:n.reasons}),u&&r.jsxs("span",{className:"text-[11px] text-white/60",title:`Known for ${n.known} of ${n.total} ${s}`,children:[" ","(known ",n.known," of ",n.total,")"]})]})}function Jx({cause:n,primary:l}){return r.jsxs("div",{className:l?"p-2.5 rounded border border-red-400/30 bg-red-500/10 space-y-1":"p-2 rounded border border-white/10 bg-white/[0.02] space-y-1",children:[r.jsxs("p",{className:l?"text-sm font-medium text-red-200":"text-xs text-white/60",children:[l?"First failure: ":"Consequence: ",sf(n.code)]}),r.jsx("p",{className:l?"text-sm text-white/85 whitespace-pre-wrap break-words":"text-xs text-white/55 whitespace-pre-wrap break-words",children:n.rawReason}),r.jsxs("p",{className:"text-[11px] text-white/60",title:$s(n.quality==="exact"?"exact":"inferred",[`evidence: ${n.evidenceSource}`,`confidence: ${n.confidence}`]),children:[n.domain," · ",n.confidence," confidence · via ",n.evidenceSource.replace(/_/g," ")," · ",n.quality,n.occurredAt?` · ${new Date(n.occurredAt).toLocaleString()}`:""]})]})}function Kj({interval:n}){const l=Kx[n.category??"unknown"]??Kx.unknown,s=qa(n.durationMs),u=n.category==="host_suspended";return r.jsxs("li",{className:`flex flex-wrap items-baseline gap-x-2 gap-y-0.5 py-1 border-b border-white/5 last:border-0 ${u?"text-amber-200/90":"text-white/70"}`,children:[r.jsx("span",{className:`text-xs px-1.5 py-0.5 rounded border shrink-0 ${u?"border-amber-400/40 bg-amber-500/10":"border-white/15 bg-white/5"}`,title:u?"Overlapping durable host-sleep evidence split this gap — the host was suspended, not the agent.":"Observational gap with no new structured activity — not a diagnosis of what the agent was doing.",children:l}),r.jsx("span",{className:"text-xs tabular-nums",children:s??r.jsx(sl,{reasons:n.reasons})}),r.jsx(_a,{quality:n.quality,reasons:n.reasons})]})}function Jj({attempt:n}){const l=n.reuseKinds;return l===void 0?r.jsx("span",{className:"ml-2 text-[11px] px-1.5 py-0.5 rounded border border-white/15 bg-white/5 text-white/60 italic",title:"Reuse unknown for this retry — no reuse evidence recorded.",children:"reuse unknown"}):l.length===0?r.jsx("span",{className:"ml-2 text-[11px] px-1.5 py-0.5 rounded border border-white/15 bg-white/5 text-white/60",title:"Cold retry — no prior worktree, commit, or verification was reused.",children:"cold retry"}):r.jsx(r.Fragment,{children:l.map(s=>r.jsxs("span",{className:"ml-2 text-[11px] px-1.5 py-0.5 rounded border border-cyber-teal/40 bg-cyber-teal/10 text-cyber-teal",title:`This retry preserved the prior ${zd[s]??s} instead of starting cold.`,children:["reused ",zd[s]??s]},s))})}function Fj({attempt:n,isRetry:l}){const s=qa(n.setup.durationMs),u=qa(n.agentProcess.durationMs),d=qa(n.validationPublish.durationMs),f=l&&n.role==="developer";return r.jsxs("li",{className:"py-1.5 border-b border-white/5 last:border-0 space-y-0.5",children:[r.jsxs("p",{className:"text-sm text-white/85",children:[r.jsx("span",{className:"capitalize",children:n.role}),r.jsxs("span",{className:"text-white/45",children:[n.runtime?` · ${n.runtime}`:"",n.model?` · ${n.model}`:"",` · round ${n.round} · ${n.status}`]}),n.publishOnly&&r.jsx("span",{className:"ml-2 text-[11px] px-1.5 py-0.5 rounded border border-cyber-violet/40 bg-cyber-violet/10 text-cyber-violet-light",title:"Publish-only attempt: no agent process ran — the coordinator published prior work.",children:"publish-only"}),f&&!n.publishOnly&&r.jsx(Jj,{attempt:n})]}),r.jsxs("p",{className:"text-xs text-white/50 tabular-nums",children:[r.jsxs("span",{title:s?void 0:`Setup unavailable — ${n.setup.reasons.join(", ")||"no reason recorded"}`,children:["Setup ",s??r.jsxs("span",{className:"italic",children:["Unavailable — ",n.setup.reasons.join(", ")||"no reason recorded"]})]}),r.jsx(_a,{quality:n.setup.quality,reasons:n.setup.reasons})," · ",r.jsxs("span",{title:u?void 0:`Agent process unavailable — ${n.agentProcess.reasons.join(", ")||"no reason recorded"}`,children:["Agent ",u??r.jsxs("span",{className:"italic",children:["Unavailable — ",n.agentProcess.reasons.join(", ")||"no reason recorded"]})]}),r.jsx(_a,{quality:n.agentProcess.quality,reasons:n.agentProcess.reasons})," · ",r.jsxs("span",{title:d?void 0:`Validation/publish unavailable — ${n.validationPublish.reasons.join(", ")||"no reason recorded"}`,children:["Validation/publish ",d??r.jsxs("span",{className:"italic",children:["Unavailable — ",n.validationPublish.reasons.join(", ")||"no reason recorded"]})]}),r.jsx(_a,{quality:n.validationPublish.quality,reasons:n.validationPublish.reasons})]}),n.failureCauses.length>0&&r.jsxs("p",{className:"text-[11px] text-white/60",children:["Failures: ",n.failureCauses.map(m=>sf(m.code)).join(", ")]})]})}function Wj({analysis:n}){const l=qa(n.elapsed.durationMs),s=qa(n.exclusiveTotalMs),u=qa(n.firstCheckpoint.msSinceWorkflowStart),d=n.nested.filter(E=>E.kind!=="unexplained_silence"),f=n.attempts.flatMap(E=>E.silence),m=n.attempts.length>0&&n.attempts.every(E=>E.silence.length===0&&E.silenceQuality==="unavailable"),x=n.attempts.filter(E=>E.silence.length===0&&E.silenceQuality==="unavailable"),y=n.waste.failedAttempts>0||n.waste.publishOnlyAttempts>0||n.attempts.some(E=>E.failureCauses.length>0||Ij.has(E.status)),v=qa(n.humanWaitMs),w=n.retry.reuseRate==null?null:`${Math.round(n.retry.reuseRate*100)}% reused`,D=(n.retry.preservedKinds??[]).map(E=>zd[E]??E),X=n.waste.failedAttempts>0||n.waste.publishOnlyAttempts>0;return r.jsxs("div",{className:"space-y-3",children:[r.jsxs("div",{children:[r.jsxs("p",{className:"text-sm text-white/85 tabular-nums",children:["Elapsed ",l??r.jsx(sl,{reasons:n.elapsed.reasons}),r.jsx(_a,{quality:n.elapsed.quality,reasons:n.elapsed.reasons})]}),r.jsxs("p",{className:"text-xs text-white/45 tabular-nums",title:"Unioned top-level phases with overlaps removed (human wait excluded). Nested waits below explain phases — they are never added to this total.",children:["Exclusive phase total ",s??r.jsx(sl,{reasons:n.exclusiveTotalReasons}),r.jsx(_a,{quality:n.exclusiveTotalQuality,reasons:n.exclusiveTotalReasons}),r.jsx("span",{children:" · overlaps unioned, not summed"})]})]}),r.jsxs("div",{children:[r.jsx("h4",{className:"text-xs text-white/45 uppercase tracking-wide mb-1",children:"Phase breakdown"}),r.jsx("ul",{children:n.unionedDurations.map(E=>{const $=qa(E.durationMs);return r.jsxs("li",{className:"flex flex-wrap items-baseline gap-x-2 py-0.5 text-sm",children:[r.jsx("span",{className:"text-white/70 w-36 shrink-0",children:Xj[E.phase]??E.phase}),r.jsx("span",{className:"text-white/85 tabular-nums",children:$??r.jsx(sl,{reasons:E.reasons})}),r.jsx(_a,{quality:E.quality,reasons:E.reasons}),E.known<E.total&&r.jsxs("span",{className:"text-[11px] text-white/60",children:["(known ",E.known," of ",E.total,")"]})]},E.phase)})}),r.jsxs("p",{className:"text-xs text-white/45 tabular-nums mt-1",children:["Human wait ",v??r.jsx(sl,{reasons:n.humanWaitReasons}),r.jsx(_a,{quality:n.humanWaitQuality,reasons:n.humanWaitReasons}),r.jsx("span",{title:"Human wait is tracked separately — it never adds to the phase total.",children:" · never additive"})]}),d.length>0&&r.jsx("ul",{className:"mt-1",children:d.map((E,$)=>r.jsxs("li",{className:"text-xs text-white/50 tabular-nums",children:[r.jsxs("span",{title:"Nested drill-down: explains its parent phase, never adds to the total.",children:["↳ ",E.kind==="human_wait"?"Human wait":E.category??E.kind]})," ",qa(E.durationMs)??r.jsx(sl,{reasons:E.reasons}),r.jsx(_a,{quality:E.quality,reasons:E.reasons})]},$))})]}),r.jsxs("div",{children:[r.jsxs("h4",{className:"text-xs text-white/45 uppercase tracking-wide mb-1",children:["Attempts (",n.attempts.length,")"]}),n.attempts.length===0?r.jsx("p",{className:"text-xs text-white/45 italic",children:"No attempts recorded yet."}):r.jsx("ul",{children:n.attempts.map((E,$)=>r.jsx(Fj,{attempt:E,isRetry:$>0},E.sessionId))})]}),r.jsxs("div",{children:[r.jsx("h4",{className:"text-xs text-white/45 uppercase tracking-wide mb-1",children:"Failure"}),n.primaryFailure?r.jsxs("div",{className:"space-y-1.5",children:[r.jsx(Jx,{cause:n.primaryFailure,primary:!0}),n.consequenceCauses.length>0&&r.jsx("div",{className:"space-y-1 opacity-80",children:n.consequenceCauses.map((E,$)=>r.jsx(Jx,{cause:E,primary:!1},`${E.code}-${$}`))})]}):y?r.jsxs("p",{className:"text-sm text-white/60 italic",title:$s("unavailable",n.primaryFailureReasons),children:["Unknown — ",n.primaryFailureReasons.join(", ")||"no failure evidence recorded"]}):r.jsx("p",{className:"text-sm text-white/45",children:"No failure recorded."})]}),r.jsxs("div",{children:[r.jsxs("h4",{className:"text-xs text-white/45 uppercase tracking-wide mb-1",children:["Retry waste (",n.waste.failedAttempts," failed attempt",n.waste.failedAttempts===1?"":"s",")"]}),X?r.jsxs("p",{className:"text-sm text-white/85 flex flex-wrap gap-x-3 gap-y-0.5 tabular-nums",children:[r.jsxs("span",{title:"Failed-attempt agent-process time over known values only",children:["Runtime ",r.jsx(ru,{covered:n.waste.runtimeMs,format:E=>qa(Math.round(E))??"?",unit:"attempts"})]}),r.jsxs("span",{title:"Failed-attempt input tokens over known values only",children:["In ",r.jsx(ru,{covered:n.waste.tokensIn,format:E=>Ix(E)??"?",unit:"attempts"})]}),r.jsxs("span",{title:"Failed-attempt output tokens over known values only",children:["Out ",r.jsx(ru,{covered:n.waste.tokensOut,format:E=>Ix(E)??"?",unit:"attempts"})]}),r.jsxs("span",{title:"Failed-attempt known cost over known values only",children:["Cost ",r.jsx(ru,{covered:n.waste.costUsd,format:E=>Qj(E)??"?",unit:"attempts"})]})]}):r.jsx("p",{className:"text-sm text-white/45",children:"No failed attempts — no retry waste."})]}),r.jsxs("div",{children:[r.jsx("h4",{className:"text-xs text-white/45 uppercase tracking-wide mb-1",children:"First checkpoint"}),n.firstCheckpoint.msSinceWorkflowStart==null&&n.firstCheckpoint.kind==null?r.jsxs("p",{className:"text-sm text-white/60 italic",title:$s(n.firstCheckpoint.quality,n.firstCheckpoint.reasons),children:["Unavailable — ",n.firstCheckpoint.reasons.join(", ")||"no checkpoint recorded"]}):r.jsxs("p",{className:"text-sm text-white/85 tabular-nums",children:[n.firstCheckpoint.kind?sf(n.firstCheckpoint.kind):"Checkpoint",n.firstCheckpoint.observedSha?` · ${n.firstCheckpoint.observedSha.slice(0,12)}`:"",u?` · ${u} after workflow start`:"",r.jsx(_a,{quality:n.firstCheckpoint.quality,reasons:n.firstCheckpoint.reasons})]})]}),r.jsxs("div",{children:[r.jsx("h4",{className:"text-xs text-white/45 uppercase tracking-wide mb-1",children:"Retry reuse"}),r.jsxs("div",{className:"flex flex-wrap gap-1.5",role:"group","aria-label":"Retry reuse summary",children:[r.jsxs("span",{className:"text-[11px] px-1.5 py-0.5 rounded border border-cyber-teal/40 bg-cyber-teal/10 text-cyber-teal",title:"Retries that preserved prior work — a reused worktree, commit, or verification receipt.",children:["Reused ",n.retry.reused]}),r.jsxs("span",{className:"text-[11px] px-1.5 py-0.5 rounded border border-white/15 bg-white/5 text-white/60",title:"Retries that started cold — no prior worktree, commit, or verification was reused.",children:["Cold ",n.retry.cold]}),n.retry.unknown>0&&r.jsxs("span",{className:"text-[11px] px-1.5 py-0.5 rounded border border-white/15 bg-white/5 text-white/60 italic",title:`Unknown reuse for ${n.retry.unknown} retr${n.retry.unknown===1?"y":"ies"} — ${n.retry.reasons.join(", ")||"no reuse evidence"}.`,children:["Unknown ",n.retry.unknown]}),n.retry.publishOnly>0&&r.jsxs("span",{className:"text-[11px] px-1.5 py-0.5 rounded border border-cyber-violet/40 bg-cyber-violet/10 text-cyber-violet-light",title:"Publish-only retries ran no agent process — the coordinator published already-verified work.",children:["Publish-only ",n.retry.publishOnly]}),r.jsxs("span",{className:"text-[11px] text-white/60 tabular-nums self-center",children:[n.retry.retries===0?"No retries":w??r.jsx(sl,{reasons:n.retry.reasons}),r.jsx(_a,{quality:n.retry.quality,reasons:n.retry.reasons})]})]}),r.jsx("p",{className:"text-[11px] text-white/60 mt-0.5",children:n.retry.retries===0?"No retries — nothing to preserve.":D.length>0?`Preserved: ${D.join(", ")}.`:n.retry.unknown>0?`Preservation unknown for ${n.retry.unknown} retr${n.retry.unknown===1?"y":"ies"} — no reuse evidence.`:"No prior work preserved — every retry started cold."})]}),r.jsxs("div",{children:[r.jsx("h4",{className:"text-xs text-white/45 uppercase tracking-wide mb-1",children:"Silence"}),r.jsx("p",{className:"text-[11px] text-white/60 mb-1",children:"Silence is observational — gaps with no new structured activity. It describes what was observed, never a diagnosis."}),f.length===0?m?r.jsx("p",{className:"text-sm text-white/60 italic",children:"Unknown — silence cannot be derived without agent-process bounds."}):r.jsx("p",{className:"text-sm text-white/45",children:"No silence observed."}):r.jsxs(r.Fragment,{children:[r.jsx("ul",{"aria-label":"Observed silence intervals",children:f.map((E,$)=>r.jsx(Kj,{interval:E},$))}),x.length>0&&r.jsx("ul",{"aria-label":"Attempts with unknown silence",className:"mt-1",children:x.map(E=>r.jsxs("li",{className:"text-[11px] text-white/60 italic py-0.5",children:["Silence unknown for attempt ",E.sessionId.length>12?`${E.sessionId.slice(0,8)}…`:E.sessionId," —"," ",E.silenceReasons.join(", ")||"no silence evidence recorded"]},E.sessionId))})]})]})]})}function Pj({issueId:n}){const[l,s]=b.useState(null),[u,d]=b.useState(null),[f,m]=b.useState(!0);return b.useEffect(()=>{s(null),d(null),m(!0);let x=!1;return K2(n).then(y=>{x||(s(y),m(!1))}).catch(y=>{x||(/not found/i.test(String(y))?(s(null),d(null)):d(String(y).replace(/^Error:\s*/i,"")),m(!1))}),()=>{x=!0}},[n]),r.jsxs("section",{"aria-labelledby":"execution-analysis-heading",className:"mb-4 p-3 rounded border border-white/10 bg-white/[0.03]",children:[r.jsx("h3",{id:"execution-analysis-heading",className:"font-ui-display text-sm font-medium text-white/85 mb-2",children:"Execution analysis"}),f&&r.jsx("p",{className:"text-xs text-white/40",children:"Loading execution analysis…"}),!f&&u&&r.jsx("p",{className:"text-xs text-red-300",children:u}),!f&&!u&&!l&&r.jsx("p",{className:"text-xs text-white/45",children:"No execution analysis yet — start the workflow to see where time goes."}),!f&&!u&&l&&r.jsx(Wj,{analysis:l})]})}const eN="web";function tN(n){try{const l=JSON.parse(n);return typeof l.text=="string"?l.text:JSON.stringify(l,null,2)}catch{return n}}function vd(n){const l=Math.floor(n/6e4);return l<60?`${l}m`:`${Math.floor(l/60)}h ${l%60}m`}function aN(n){if(!n)return"no heartbeat yet";const l=Math.max(0,Math.floor((Date.now()-new Date(n).getTime())/1e3));return l<5?"just now":l<60?`${l}s ago`:`${Math.floor(l/60)}m ago`}function Ds(n){if(!n)return null;const l=n.split(/[/\\]/).filter(Boolean);return l.length<=2?n:l.slice(-2).join("/")}function gd(n){var l;return[n.branch,n.tipLabel,(l=n.worktree)!=null&&l.path?Ds(n.worktree.path):null].filter(Boolean).join(" · ")}function bd(n){var l;return[n.restartRisk?"restart risk":null,(l=n.worktree)!=null&&l.preserved?"dirty worktree preserved":null].filter(Boolean).map(s=>` · ${s}`).join("")}function wd(n){var l;return!!(n.restartRisk||(l=n.worktree)!=null&&l.preserved)}function nN(n,l){return!n||!l?!1:n===l?!0:n.includes(l)}function lN({busy:n,onConfirm:l,onCancel:s}){return r.jsxs("div",{className:"mt-2 p-3 rounded border border-red-400/30 bg-red-500/10 space-y-2",children:[r.jsx("p",{className:"text-sm text-white/90 font-medium",children:"Close this issue?"}),r.jsx("p",{className:"text-sm text-white/70",children:"It will not execute. Any queue entry will be removed. History is retained and can be found as closed work — filter the Issues list by status closed or open this page directly."}),r.jsxs("div",{className:"flex gap-2",children:[r.jsx("button",{type:"button",className:"px-4 py-1.5 text-sm rounded border border-red-400/50 text-red-200 hover:bg-red-500/20 disabled:opacity-50",disabled:n,onClick:l,children:"Close issue"}),r.jsx("button",{type:"button",className:"font-ui-display px-4 py-1.5 text-sm text-white/60 hover:text-white",onClick:s,children:"Keep issue"})]})]})}function iN(n){return n.externalLabel??n.id}function sN(n,l){return n===l}function rN({expectedToken:n,externalLabel:l,busy:s,onConfirm:u,onCancel:d}){const[f,m]=b.useState(""),x=sN(f,n);return r.jsxs("div",{className:"mt-2 p-3 rounded border border-red-400/30 bg-red-500/10 space-y-2",children:[r.jsx("p",{className:"text-sm text-white/90 font-medium",children:"Delete this issue from Dealer?"}),r.jsxs("p",{className:"text-sm text-white/70",children:["This permanently deletes the Dealer-local issue — its history, evidence, and files cannot be recovered.",l?` The Linear ticket ${l} will not be deleted.`:" There is no linked Linear ticket to affect."]}),r.jsxs("label",{className:"block text-xs text-white/60",children:["Type ",r.jsx("span",{className:"font-mono text-white/85",children:n})," to confirm",r.jsx("input",{className:"mt-1 block w-full bg-black/30 border border-white/10 rounded px-3 py-1.5 text-sm text-white/90 font-mono",value:f,onChange:y=>m(y.target.value),placeholder:n,autoComplete:"off"})]}),r.jsxs("div",{className:"flex gap-2",children:[r.jsx("button",{type:"button",className:"px-4 py-1.5 text-sm rounded border border-red-400/50 text-red-200 hover:bg-red-500/20 disabled:opacity-50",disabled:s||!x,onClick:u,children:"Delete from Dealer"}),r.jsx("button",{type:"button",className:"font-ui-display px-4 py-1.5 text-sm text-white/60 hover:text-white",onClick:d,children:"Keep issue"})]})]})}function uN(n){const l=n.externalLabel??n.issueId,s=n.residualPaths.length>0?` ${n.residualPaths.length} Dealer-owned file(s) could not be removed: ${n.residualPaths.join(", ")}`:"";return n.externalLabel?`Issue ${l} deleted from Dealer. The Linear ticket was not deleted.${s}`:`Issue ${l} permanently deleted from Dealer.${s}`}async function oN(n,l,s){try{const u=await s.removeIssue(n),d=uN({issueId:n,externalLabel:l.externalLabel,residualPaths:u.residualPaths});return s.closeConfirmation(),s.onHumanActionsChanged(),s.navigateToIssues(d),"deleted"}catch(u){return s.closeConfirmation(),s.reportError(u),s.refresh(),"refused"}}const cN="Agents updated. Resume to continue with the new agents.";function dN(n,l,s,u){const d={};return s!==(n??"")&&(d.developerAgentId=s),u!==(l??"")&&(d.reviewerAgentId=u),d}function fN(n){const l=n.humanActions.find(s=>s.status==="open");if(l)return Zy(l).title;switch(n.issue.currentOwner){case"developer":return"Waiting on the developer";case"reviewer":return"Waiting on the reviewer";case"human":return"Waiting on you";default:return n.issue.status==="done"||n.issue.status==="closed"?"Complete":"Idle"}}function hN({issueId:n,detail:l,agents:s,onHumanActionsChanged:u,refresh:d,onError:f}){var Ma;const[m,x]=b.useState(null),[y,v]=b.useState({}),[w,j]=b.useState(""),[D,X]=b.useState(!1),[E,$]=b.useState(""),[L,H]=b.useState(""),[F,P]=b.useState(""),[ne,V]=b.useState(!1),[Ne,I]=b.useState(null),[ye,Me]=b.useState(!1),[bt,At]=b.useState(null),[rt,yt]=b.useState(!1),[lt,Qe]=b.useState(!1),U=Ru(),[J,re]=b.useState(!1),[Ae,Le]=b.useState(null),[N,Y]=b.useState({}),[W,te]=b.useState({}),se=G=>f(String(G)),{issue:B,timeline:ce,humanActions:Xe,usageSummary:De,readiness:Bt,humanWaitMs:Ta,interventionCount:ua,latestWorkflowInstance:Va,activeWorkerSession:qe,liveProgress:Za,latestSessionFailure:dt,branchTipStatus:wt,queued:Rn,queueEntry:Ye,capWait:Ga}=l,oa=s.find(G=>G.id===B.developerAgentId),tn=oa&&!oa.healthy,ol=((Ma=oa==null?void 0:oa.issues[0])==null?void 0:Ma.message)??"Developer agent is unhealthy",ut=Va?new Date(Va.completedAt??Date.now()).getTime()-new Date(Va.startedAt).getTime():0,ca=Xe.filter(G=>G.status==="open"),Ue=B.status==="needs_human"&&ca.some(G=>G.actionType==="attempts_exhausted"||G.actionType==="policy_escalation"),cl=Bt.ok===!1||ca.some(G=>G.actionType==="product_scope_decision"),qt=Va!=null&&Va.completedAt===null,$l=B.status==="ready"&&!qt,dl=cl||$l,Yl=(qe==null?void 0:qe.status)==="running",fl=B.source==="linear"&&B.status==="ready"&&!qt&&!Yl,Oa=B.status==="ready"&&!qt,tt=(B.status==="ready"||B.status==="done"||B.status==="closed")&&!qt,Ut=B.status==="ready"&&!qt,ft=qe&&qe.status==="running"&&(B.status==="developing"||B.status==="reviewing"||B.status==="repairing"),Ft=!!dt&&!ft,at=async()=>{w.trim()&&(await rS(n,w),j(""),d())},Vl=()=>{$(B.title),H(B.description??""),P(B.acceptanceCriteria??""),X(!0)},an=async()=>{V(!0),f(null);try{await fu(n,{title:E.trim()||void 0,description:L.trim()||null,acceptanceCriteria:F.trim()||null}),X(!1),d()}catch(G){se(G)}finally{V(!1)}},nn=async()=>{V(!0),f(null);try{await P2(n),re(!1),d()}catch(G){re(!1),se(G),d()}finally{V(!1)}},Qa=async()=>{V(!0),f(null);try{const G=await iv(n);I(G.state==="admitted"?null:`Queued at position ${G.position}${G.waitReason?` — ${G.waitReason}`:""}`),d()}catch(G){se(G)}finally{V(!1)}},La=async()=>{V(!0),f(null);try{await lS(n),d()}catch(G){se(G)}finally{V(!1)}},Tn=async()=>{V(!0),f(null);try{await sv(n),I(null),Me(!1),d()}catch(G){se(G),d()}finally{V(!1)}},ln=async(G,je,ze)=>{V(!0),f(null);try{await fu(n,{repo:G,developerAgentId:je,reviewerAgentId:ze}),Me(!1),d()}catch(Ve){Me(!1),se(Ve),d()}finally{V(!1)}},Tt=async(G,je)=>{V(!0),f(null);try{await fu(n,dN(B.developerAgentId,B.reviewerAgentId,G,je)),At(cN),d()}catch(ze){se(ze),d()}finally{V(!1)}},hl=async()=>{V(!0),f(null);try{await tS(n),u(),d()}catch(G){se(G)}finally{V(!1)}},ml=async()=>{V(!0),f(null);try{await rv(n),d()}catch(G){se(G)}finally{V(!1)}},sn=async()=>{V(!0),f(null);try{await aS(n),yt(!1),Le("Issue closed — it will not execute. History is retained and can be found as closed work."),d()}catch(G){se(G)}finally{V(!1)}},Bi=async()=>{V(!0),f(null);try{await oN(n,{externalLabel:B.externalLabel},{removeIssue:nS,navigateToIssues:G=>U("/issues",{state:{deletedNotice:G}}),onHumanActionsChanged:u,closeConfirmation:()=>Qe(!1),reportError:G=>se(G),refresh:d})}finally{V(!1)}},Zl=async()=>{if(confirm("Abort this workflow? The current worker will stop and the issue will close. History and evidence are kept.")){V(!0),f(null);try{await eS(n),d()}catch(G){se(G)}finally{V(!1)}}},On=async(G,je,ze)=>{V(!0),f(null);try{await uv(G,eN,je,ze),u(),d()}catch(Ve){se(Ve)}finally{V(!1)}},pl=()=>{m||J2(n).then(x).catch(G=>se(G))},Ln=G=>{y[G]||(v(je=>({...je,[G]:{content:"",loading:!0}})),F2(n,G).then(je=>v(ze=>({...ze,[G]:{content:je.content,loading:!1}}))).catch(je=>v(ze=>({...ze,[G]:{content:"",loading:!1,error:String(je)}}))))};return r.jsx("div",{className:"flex-1 min-h-0 overflow-y-auto px-6 py-4",children:r.jsxs("div",{className:"max-w-3xl",children:[r.jsx(sa,{to:"/issues",className:"font-ui-display inline-block text-sm text-white/50 hover:text-white mb-3",children:"← Issues"}),r.jsxs("div",{className:"flex items-start justify-between gap-4 mb-4",children:[r.jsxs("div",{children:[r.jsx("h2",{className:"text-lg font-semibold text-white/90",children:B.title}),r.jsxs("p",{className:"text-xs text-white/45 mt-1",children:["Owner: ",r.jsx("span",{className:"capitalize",children:B.currentOwner}),B.currentIntent?` · ${B.currentIntent}`:""]}),r.jsxs("div",{className:"flex flex-wrap gap-3 mt-2 text-xs text-white/40",children:[B.prUrl&&r.jsxs("a",{href:B.prUrl,target:"_blank",rel:"noreferrer",className:"text-cyber-teal hover:underline",children:["PR #",B.prNumber]}),B.externalUrl&&r.jsx("a",{href:B.externalUrl,target:"_blank",rel:"noreferrer",className:"text-cyber-teal hover:underline",children:B.externalLabel??"External link"}),r.jsxs("span",{children:["Round ",B.currentRound,"/",B.maxReviewRounds]}),r.jsxs("span",{children:["Infra attempts ",B.infraAttempts,"/",B.maxInfraAttempts]}),r.jsxs("span",{title:"Wall-clock time from workflow start to completion (or now)",children:[vd(ut)," elapsed"]}),r.jsxs("span",{title:`${De.totalTokensIn} in / ${De.totalTokensOut} out tokens`,children:["$",De.totalCostUsd.toFixed(2)]}),Ta>0&&r.jsxs("span",{title:"Time spent waiting on a human, excluding autonomous processing",children:[vd(Ta)," human wait"]}),ua>0&&r.jsxs("span",{children:[ua," intervention",ua===1?"":"s"]})]})]}),r.jsx(mv,{status:B.status})]}),Ae&&r.jsx("div",{className:"mb-4 p-3 rounded border border-white/15 bg-white/[0.04]",children:r.jsx("p",{className:"text-sm text-white/85",children:Ae})}),r.jsx(Uj,{issue:B,agents:s,canEdit:Ut,editing:ye,busy:ne,onBeginEdit:()=>Me(!0),onSave:(G,je,ze)=>void ln(G,je,ze),onCancel:()=>Me(!1)}),B.executionContract&&r.jsx(zj,{contract:B.executionContract}),r.jsx(qj,{attachments:l.sourceAttachments}),r.jsxs("div",{className:"mb-4 p-3 rounded border border-white/10 bg-panel-elevated/40 flex items-start justify-between gap-3",children:[r.jsxs("div",{children:[r.jsx("p",{className:"text-xs text-white/45",children:"Next"}),r.jsx("p",{className:"text-sm text-white/85",children:fN(l)})]}),qt&&r.jsx("button",{type:"button",className:"btn-ghost-danger px-3 py-1.5 text-xs shrink-0 disabled:cursor-not-allowed disabled:opacity-60",disabled:ne,onClick:Zl,children:"Abort workflow"})]}),Ye&&r.jsxs("div",{className:"mb-4 p-3 rounded border border-cyber-teal/30 bg-cyber-teal/5",children:[r.jsxs("p",{className:"text-xs text-cyber-teal font-medium uppercase tracking-wide",children:["Queued · position ",Ye.position]}),r.jsx("p",{className:"text-sm text-white/80 mt-0.5",children:Ye.waitReason??"Next up — starts as soon as the coordinator ticks"})]}),Ga&&r.jsxs("div",{className:"mb-4 p-3 rounded border border-amber-400/30 bg-amber-500/10 flex flex-wrap items-start justify-between gap-3",children:[r.jsxs("div",{className:"min-w-0 flex-1",children:[r.jsx("p",{className:"text-xs text-amber-300 font-medium uppercase tracking-wide",children:Ga.kind==="usage_capped"?"Waiting on usage cap":"Waiting on Agent Deck"}),r.jsx("p",{className:"text-sm text-white/80 mt-0.5 break-words",children:Ga.reason}),r.jsxs("p",{className:"text-xs text-white/45 mt-0.5",children:["Wait until ",new Date(Ga.until).toLocaleString()]})]}),r.jsx("button",{type:"button",className:"btn-gold px-3 py-1.5 text-xs shrink-0 disabled:opacity-50",disabled:ne,title:"Park this issue for a human — cancels the wait without touching the worktree; a resume continues with whichever agents are then set",onClick:hl,children:"Park for human"})]}),ft&&qe&&r.jsxs("div",{className:"mb-4 p-3 rounded border border-cyber-teal/35 bg-cyber-teal/5 space-y-1.5",children:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("span",{className:"inline-block w-1.5 h-1.5 rounded-full bg-cyber-teal animate-pulse","aria-hidden":!0}),r.jsx("p",{className:"text-xs text-cyber-teal font-medium uppercase tracking-wide",children:"Running now"})]}),r.jsxs("p",{className:"text-sm text-white/90",children:[r.jsx("span",{className:"capitalize",children:qe.role}),qe.runtime?` · ${qe.runtime}`:"",qe.model?` · ${qe.model}`:"",` · round ${qe.round}`]}),r.jsxs("p",{className:"text-sm text-[#C4B643] truncate",title:Za??B.currentIntent??"session started",children:["Last progress: ",Za??B.currentIntent??"session started"]}),wt&&r.jsxs("p",{className:`text-xs ${wd(wt)?"text-amber-300":"text-white/55"}`,title:gd(wt),children:["Branch tip: ",wt.tipLabel,bd(wt)]}),Za&&B.currentIntent&&!/session running/i.test(B.currentIntent)&&!nN(B.currentIntent,Za)&&r.jsx("p",{className:"text-xs text-white/45 truncate",title:B.currentIntent,children:B.currentIntent}),r.jsxs("p",{className:"text-xs text-white/45",children:["Heartbeat ",aN(qe.heartbeatAt),Ds(qe.worktreePath)?` · ${Ds(qe.worktreePath)}`:""]}),qe.logPath&&r.jsxs("p",{className:"text-xs text-white/40 font-mono break-all",title:qe.logPath,children:["Log: ",Ds(qe.logPath)??qe.logPath]})]}),Ft&&dt&&r.jsxs("div",{className:"mb-4 p-3 rounded border border-red-400/30 bg-red-500/10 space-y-1.5",children:[r.jsx("p",{className:"text-xs text-red-300 font-medium uppercase tracking-wide",children:"Latest session failure"}),r.jsx("p",{className:"text-sm text-white/90 whitespace-pre-wrap break-words",children:dt.reason}),r.jsxs("p",{className:"text-xs text-white/45",children:[dt.role?r.jsx("span",{className:"capitalize",children:dt.role}):"Worker",dt.outcome?` · ${dt.outcome}`:"",` · ${new Date(dt.when).toLocaleString()}`,` · infra ${dt.infraAttempts}/${dt.maxInfraAttempts}`]}),wt&&r.jsxs("p",{className:`text-xs ${wd(wt)?"text-amber-300":"text-white/55"}`,title:gd(wt),children:["Branch tip: ",wt.tipLabel,bd(wt)]}),dt.logPath&&r.jsxs("p",{className:"text-xs text-white/40 font-mono break-all",title:dt.logPath,children:["Log: ",Ds(dt.logPath)??dt.logPath]})]}),wt&&!ft&&!Ft&&r.jsxs("div",{className:"mb-4 p-3 rounded border border-white/10 bg-white/[0.03] space-y-1",children:[r.jsx("p",{className:"text-xs text-white/45 uppercase tracking-wide",children:"Branch tip"}),r.jsxs("p",{className:`text-sm ${wd(wt)?"text-amber-300":"text-white/80"}`,title:gd(wt),children:[wt.tipLabel,bd(wt)]})]}),!Bt.ok&&!ca.some(G=>G.actionType==="product_scope_decision")&&r.jsx("div",{className:"mb-4 p-3 rounded border border-amber-400/30 bg-amber-500/10",children:r.jsxs("p",{className:"text-xs text-amber-300 font-medium",children:["Not startable yet — missing: ",Bt.missing.join(", ")]})}),ca.length>0&&r.jsxs("div",{className:"mb-4 p-3 rounded border border-red-400/30 bg-red-500/10 space-y-2",children:[r.jsx("p",{className:"text-xs text-red-300 font-medium",children:"Human action needed"}),ca.map(G=>{const je=G.actionType==="product_scope_decision";if(G.actionType==="operator_verification"){const ze=xj(G),Ve=W[G.id]??"",ht=Ve.trim().length>0;return r.jsx(zs,{action:G,hideChoicesHint:!0,children:r.jsxs("div",{className:"space-y-1",children:[r.jsx("textarea",{className:"w-full bg-black/30 border border-white/10 rounded px-3 py-2 text-sm text-white/85 placeholder:text-white/30",rows:2,placeholder:"Result note (required) — paste the probe output, waiver reason, or repair note",value:Ve,disabled:ne,onChange:mt=>te(C=>({...C,[G.id]:mt.target.value}))}),r.jsx("div",{className:"flex flex-wrap gap-2",children:ze.map(mt=>r.jsx("button",{type:"button",className:"btn-gold px-3 py-1 text-xs disabled:opacity-50",disabled:ne||!ht,title:ht?void 0:"Enter the result note first — the server requires it",onClick:()=>On(G.id,mt.choice,Ve),children:mt.label},mt.choice))})]})},G.id)}return je?r.jsx(zs,{action:G,hideChoicesHint:!0,children:Bt.ok&&r.jsxs("div",{className:"space-y-1",children:[r.jsx("textarea",{className:"w-full bg-black/30 border border-white/10 rounded px-3 py-2 text-sm text-white/85 placeholder:text-white/30",rows:2,placeholder:"Decision note (optional) — shown to the next developer round",value:N[G.id]??"",disabled:ne,onChange:ze=>Y(Ve=>({...Ve,[G.id]:ze.target.value}))}),r.jsx("button",{type:"button",className:"btn-gold px-3 py-1 text-xs",disabled:ne,onClick:()=>On(G.id,"resume",N[G.id]),children:"Resume"})]})},G.id):r.jsx(zs,{action:G,disabled:ne,onChoose:ze=>On(G.id,ze)},G.id)})]}),Ue&&r.jsx("div",{className:"mb-4",children:r.jsx(bv,{variant:"parked",agents:s,initialDeveloperId:B.developerAgentId,initialReviewerId:B.reviewerAgentId,busy:ne,notice:bt,onSave:(G,je)=>void Tt(G,je)},`${B.developerAgentId??""}:${B.reviewerAgentId??""}`)}),(dl||fl)&&!D&&!J&&r.jsxs("div",{className:"mb-4 flex flex-wrap items-center gap-x-4 gap-y-1",children:[dl&&r.jsx("button",{type:"button",className:"font-ui-display text-xs text-cyber-teal hover:underline",onClick:Vl,children:"Edit title / description / acceptance criteria"}),fl&&r.jsx("button",{type:"button",className:"font-ui-display text-xs text-cyber-teal hover:underline",title:"Pull the latest title, description, and acceptance criteria from the linked Linear ticket — local edits will be replaced",onClick:()=>re(!0),children:"Reload from Linear"})]}),fl&&J&&!D&&r.jsxs("div",{className:"mb-4 p-3 rounded border border-cyber-teal/30 bg-cyber-teal/5 space-y-2",children:[r.jsxs("p",{className:"text-sm text-white/90 font-medium",children:["Reload the latest task text from Linear",B.externalLabel?` ${B.externalLabel}`:"","?"]}),r.jsx("p",{className:"text-sm text-white/70",children:"This replaces the local title, description, and acceptance criteria with the latest ticket text. Local edits will be lost. Repository, agents, and queue position are unchanged, and nothing is written back to Linear."}),r.jsxs("div",{className:"flex gap-2",children:[r.jsx("button",{type:"button",className:"btn-gold px-4 py-1.5 text-sm disabled:opacity-50",disabled:ne,onClick:nn,children:"Reload from Linear"}),r.jsx("button",{type:"button",className:"font-ui-display px-4 py-1.5 text-sm text-white/60 hover:text-white",onClick:()=>re(!1),children:"Cancel"})]})]}),D&&r.jsxs("div",{className:"mb-4 p-3 rounded border border-white/10 bg-panel-elevated/60 space-y-2",children:[r.jsx("input",{className:"w-full bg-black/30 border border-white/10 rounded px-3 py-2 text-sm",value:E,onChange:G=>$(G.target.value),placeholder:"Title"}),r.jsx("textarea",{className:"w-full bg-black/30 border border-white/10 rounded px-3 py-2 text-sm",rows:2,value:L,onChange:G=>H(G.target.value),placeholder:"Description"}),r.jsx("textarea",{className:"w-full bg-black/30 border border-white/10 rounded px-3 py-2 text-sm",rows:2,value:F,onChange:G=>P(G.target.value),placeholder:"Acceptance criteria"}),r.jsxs("div",{className:"flex gap-2",children:[r.jsx("button",{type:"button",className:"btn-gold px-4 py-1.5 text-sm",disabled:ne,onClick:an,children:"Save"}),r.jsx("button",{type:"button",className:"font-ui-display px-4 py-1.5 text-sm text-white/60 hover:text-white",onClick:()=>X(!1),children:"Cancel"})]})]}),(B.status==="ready"||B.status==="needs_human"&&ca.length===0)&&r.jsxs("div",{className:"mb-4 space-y-2",children:[tn&&r.jsxs("p",{className:"text-sm text-amber-200/90",children:["Fix before Start: ",ol]}),Ne&&r.jsx("p",{className:"text-sm text-amber-200/90",children:Ne}),r.jsxs("div",{className:"flex flex-wrap gap-2",children:[r.jsx("button",{type:"button",className:"btn-gold px-4 py-2 disabled:opacity-50",disabled:!Bt.ok||ne||!!tn,title:tn?ol:"Run next — move to the front of the admission queue; runs now if a slot is free, otherwise waits first with a reason",onClick:Qa,children:"Run next"}),r.jsx("button",{type:"button",className:"px-4 py-2 text-sm border border-cyber-teal/40 rounded text-cyber-teal hover:bg-cyber-teal/10 disabled:opacity-50",disabled:!Bt.ok||ne||!!tn,title:tn?ol:"Execute now — start immediately, skipping queue order; refuses (changing nothing) when capacity, readiness, blockers, or agent health prevents it",onClick:Tn,children:"Execute now"}),Rn?r.jsx("button",{type:"button",className:"font-ui-display px-4 py-2 text-sm border border-white/15 rounded text-white/60 hover:text-white disabled:opacity-50",disabled:ne,onClick:ml,children:"Remove from queue"}):r.jsx("button",{type:"button",className:"font-ui-display px-4 py-2 text-sm border border-white/15 rounded text-white/80 hover:border-cyber-teal/50 hover:text-cyber-teal disabled:opacity-50",disabled:ne||qt,title:"Add to queue — append to the end of the admission queue; does not start anything now",onClick:La,children:"Add to queue"})]}),Rn&&Ut&&!ye&&r.jsx("p",{className:"text-xs text-white/40",children:"Queued — edit repository / agents from the Configuration section above; position is kept."})]}),r.jsx(Pj,{issueId:n}),r.jsx("div",{className:"border-t border-white/10 pt-3",children:r.jsx(Gj,{events:ce})}),r.jsxs("div",{className:"mt-4 flex gap-2",children:[r.jsx("input",{className:"flex-1 bg-black/30 border border-white/10 rounded px-3 py-2 text-sm",placeholder:"Guide this issue…",value:w,onChange:G=>j(G.target.value),onKeyDown:G=>G.key==="Enter"&&at()}),r.jsx("button",{type:"button",className:"btn-gold px-4",onClick:at,children:"Send"})]}),(Oa||tt)&&r.jsxs("details",{className:"mt-6",children:[r.jsx("summary",{className:"text-xs text-white/45 cursor-pointer hover:text-white/70",children:"More actions"}),r.jsxs("div",{className:"mt-2 space-y-2",children:[r.jsxs("p",{className:"text-xs text-white/45",children:[Oa?"Remove from queue means do not run yet — the issue stays ready and can run later. Close issue means this work is no longer needed — it will never execute, but history is kept.":"This work is finished — there is nothing left to close or abort.",tt?" Delete from Dealer permanently removes the local issue, its history, and its files.":""]}),Oa&&(rt?r.jsx(lN,{busy:ne,onConfirm:()=>void sn(),onCancel:()=>yt(!1)}):r.jsx("button",{type:"button",className:"font-ui-display text-xs text-white/50 hover:text-red-300 underline underline-offset-2 disabled:opacity-50",disabled:ne,title:"Retire this issue without running it — removes any queue entry, keeps history as closed work",onClick:()=>yt(!0),children:"Close issue"})),tt&&(lt?r.jsx(rN,{expectedToken:iN(B),externalLabel:B.externalLabel,busy:ne,onConfirm:()=>void Bi(),onCancel:()=>Qe(!1)}):r.jsx("button",{type:"button",className:"font-ui-display text-xs text-white/50 hover:text-red-300 underline underline-offset-2 disabled:opacity-50",disabled:ne,title:"Permanently delete the Dealer-local issue, its history, and its files — the Linear ticket is not deleted",onClick:()=>Qe(!0),children:"Delete from Dealer"}))]})]}),r.jsxs("details",{className:"mt-6",onToggle:G=>G.currentTarget.open&&pl(),children:[r.jsx("summary",{className:"text-xs text-white/45 cursor-pointer hover:text-white/70",children:"Evidence & raw trace"}),m?r.jsxs("div",{className:"mt-2 space-y-3 text-xs text-white/60",children:[r.jsxs("div",{children:[r.jsx("p",{className:"text-white/45 mb-1",children:"Worker sessions"}),m.workerSessions.map(G=>{const je=m.usageEvents.filter(mt=>mt.workerSessionId===G.id),ze=je.reduce((mt,C)=>mt+(C.costUsd??0),0),Ve=je.reduce((mt,C)=>mt+(C.tokensIn??0),0),ht=je.reduce((mt,C)=>mt+(C.tokensOut??0),0);return r.jsxs("p",{children:[G.role," round ",G.round," · ",G.status,G.startedAt&&G.completedAt?` · ${vd(new Date(G.completedAt).getTime()-new Date(G.startedAt).getTime())}`:"",je.length>0?` · $${ze.toFixed(3)} · ${Ve}→${ht} tok`:""]},G.id)}),m.workerSessions.length===0&&r.jsx("p",{className:"text-white/35",children:"None yet."})]}),r.jsxs("div",{children:[r.jsx("p",{className:"text-white/45 mb-1",children:"Artifacts"}),m.artifacts.map(G=>{const je=y[G.id];return r.jsxs("details",{className:"mb-1.5",onToggle:ze=>ze.currentTarget.open&&G.blobPath&&Ln(G.id),children:[r.jsxs("summary",{className:"cursor-pointer hover:text-white/80",children:[G.kind," · ",new Date(G.createdAt).toLocaleString()]}),r.jsxs("div",{className:"mt-1 pl-3 border-l border-white/10 space-y-1",children:[G.contentJson&&r.jsx("pre",{className:"whitespace-pre-wrap break-words text-white/55",children:tN(G.contentJson)}),G.blobPath&&r.jsxs("div",{children:[r.jsxs("p",{className:"text-white/40",children:["Raw trace: ",G.blobPath]}),(je==null?void 0:je.loading)&&r.jsx("p",{className:"text-white/35",children:"Loading trace…"}),(je==null?void 0:je.error)&&r.jsx("p",{className:"text-red-300/80",children:je.error}),je&&!je.loading&&!je.error&&r.jsx("pre",{className:"mt-1 max-h-64 overflow-y-auto whitespace-pre-wrap break-words text-white/50 bg-black/20 rounded p-2",children:je.content||"(empty)"})]}),!G.contentJson&&!G.blobPath&&r.jsx("p",{className:"text-white/35",children:"No content recorded."})]})]},G.id)}),m.artifacts.length===0&&r.jsx("p",{className:"text-white/35",children:"None yet."})]})]}):r.jsx("p",{className:"text-xs text-white/40 mt-2",children:"Loading…"})]})]})})}function mN({issueId:n,agents:l,onHumanActionsChanged:s}){const[u,d]=b.useState(null),[f,m]=b.useState(null),[x,y]=b.useState(!1),v=()=>lv(n).then(w=>{d(w),m(null),y(!1)}).catch(w=>{const j=String(w).replace(/^Error:\s*/i,"").trim();/^not found$/i.test(j)?(y(!0),m(null),d(null)):(m(j),y(!1))});return b.useEffect(()=>{d(null),m(null),y(!1),v();const w=setInterval(v,4e3);return()=>clearInterval(w)},[n]),x?r.jsx("div",{className:"flex-1 min-h-0 overflow-y-auto px-6 py-10",children:r.jsxs("div",{className:"max-w-md space-y-3",children:[r.jsx("h2",{className:"text-lg font-semibold text-white/90",children:"Issue not found"}),r.jsx("p",{className:"text-sm text-white/55",children:"No issue exists for this ID — it may have been deleted, or the link is wrong."}),r.jsx(sa,{to:"/issues",className:"font-ui-display inline-block text-sm text-cyber-teal hover:underline",children:"← Back to Issues"})]})}):f?r.jsxs("div",{className:"flex-1 min-h-0 overflow-y-auto px-6 py-6 space-y-3",children:[r.jsx("p",{className:"text-red-300 text-sm",children:f}),r.jsx(sa,{to:"/issues",className:"font-ui-display inline-block text-sm text-cyber-teal hover:underline",children:"← Back to Issues"})]}):u?r.jsx(hN,{issueId:n,detail:u,agents:l,onHumanActionsChanged:s,refresh:v,onError:w=>m(w)},n):r.jsx("div",{className:"p-6 text-white/50 text-sm",children:"Loading…"})}function pN(){return r.jsx("div",{className:"flex-1 min-h-0 overflow-y-auto px-6 py-10",children:r.jsxs("div",{className:"max-w-md space-y-3",children:[r.jsx("h2",{className:"font-ui-display text-lg font-semibold text-white/90",children:"Page not found"}),r.jsx("p",{className:"text-sm text-white/55",children:"That URL is not a destination in Agent Dealer."}),r.jsx(sa,{to:"/issues",className:"font-ui-display inline-block text-sm text-cyber-teal hover:underline",children:"← Back to Issues"})]})})}function xN(){return r.jsxs("div",{className:"fixed inset-0 pointer-events-none z-0 overflow-hidden","aria-hidden":!0,children:[r.jsx("div",{className:"absolute top-16 left-12",children:r.jsx("div",{className:"ambient-orb ambient-orb-a w-[26rem] h-[26rem] rounded-full bg-cyan-500/10 blur-3xl"})}),r.jsx("div",{className:"absolute bottom-20 right-12",children:r.jsx("div",{className:"ambient-orb ambient-orb-b w-[26rem] h-[26rem] rounded-full bg-pink-500/10 blur-3xl"})}),r.jsx("div",{className:"absolute top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2",children:r.jsx("div",{className:"ambient-orb ambient-orb-c w-[22rem] h-[22rem] rounded-full bg-blue-500/[0.07] blur-3xl"})})]})}function yN({className:n="w-5 h-5"}){return r.jsxs("svg",{viewBox:"0 0 20 20",fill:"currentColor",className:n,"aria-hidden":!0,children:[r.jsx("circle",{cx:"6.75",cy:"6.25",r:"3.25"}),r.jsx("circle",{cx:"13.5",cy:"6.75",r:"2.85",opacity:"0.85"}),r.jsx("path",{d:"M1.75 16v-1.1c0-2.35 1.928-4.25 4.3-4.25 1.16 0 2.21.456 3 1.2.79-.744 1.84-1.2 3-1.2 2.372 0 4.3 1.9 4.3 4.25V16H1.75z"})]})}const vN="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAJYAAACWCAYAAAA8AXHiAAAN5UlEQVR4AeydXagdVxmGF7loIKSpN/WHttqKktpAvWkVoRctp4gRtf4QbxRrREEb0wtRGkRovLCmKC1Y641CFGpBCtpIsVfHRvAm5KpIrMGfCCJUa8GmTWl6k+5nznlPvzOZ2Xtmz5o1a/Z8Ie/+vjU/a6351nPe/Xv22bFr185LLq9BbAZ2BP/nFeihAg5WD0X1LkNwsJyCXirgYPVSVu/UwXIGeqmAg9VLWTPsNPGUHKzEBZ/KcA7WVFY68XU6WIkLPpXhHKyprHTi63SwEhc89nDv37cndpdR+nOwopQxfScA9dDRfQGRM4O1ew+Fd3/wVtLB5WANtgTLDQxEwITI6eXoDz8dHvjrmbB2+J6ZDrFpcDlYgy9BswkAETAhcnvWnlfOBsS2G2aOlYNrOVisRsYCImBC5HVTveb5327tWjs8vGs5WFvLkVcCRMCEyO3szu/ea5tFjmMhGjm4loPFSmQkIAImRG6nBlDPvedbAZHbfeQ5uZaDxYpkICACJkRupwREwIR+c3w9fPu9+8LRb/7aHlLkOBaiMbRrOViswoACImBC5HYqVUCt/+jR4pBnz5wPqGiYm1xcy8F6c1GSZkAETIjcDj4PKHvcL574l20WuRyLxpCu5WCxAgkFRMCEyO3QTYHSOTgWUlvx2gyeITpYWo2eIxABEyK3w7UFyp5b5Vr27nAo13Kw7Cr1kAMRMCFyO0QXoNQPjoXUVhzatRwsrUTkCETAhMht9zGAsv3l6FoOll2hCDkQARMit13GBkp941hIbcUhXcvB0ip0jEAETIjcdtcXUHaM3Fwra7Bs4XLNgQiYELmdZwqgNB6OhdRWHMq1HCytQMsIRMCEyO3pKYGy4+bkWg6WXZkGORABEyK3pwwFlOaAYyG1FYdwLQdL1V8QgQiYELk93AJ16dyt4R2PXxNueXm/PSRZnotrOVgLlhyIgAmR28MtULw5/NID58LuP11ZHHLj9bcFVDQS3uBYqDxkatdysMorsNkGImBC5Jubi1AGik8b8ObwiWeOFft1c9cdR5QmjTm4loNVWnIgAiZEbnfXAaVj/vLPPwakNo6F1E4VcSxUHi+la7UDqzzTFWsDE2oLlC2Du9ZGNRysjTrU3sqliOdOnQ7c5dUePNuBY6FZWvzHsVDRSHiDY6HykKlcy8EylT91+l2mtZHy+SZEq+knBdy1gn+jH8DgKPcdfCp85AOPh4uv3symbbIfQ2nyGzA4FlIn9I/UThVxLFQeL4VrTdqxWGyAQhQfGF564XOk24RjITa6a1GFxZokWGWgHjz+sYC4C3vtws0r5Vp1CPTtWpMCqw4onIoFIKJVcC2e2fIMF3FtVjwRQdpW4cLatXScBFiLgLLVS+lad3/2urD+xIcCENg5dMnpC5gQue2Lx49/3/Odyt9LbPLY0fa1KF9psNoApULhWKhP1xJQXzhwbTHs3QeuK2KXGyACJkRu++IB/DeOngl/OPnxcOncLXbXVh7btVYSrGWA2qrwLDk7ewW9j8daV139y/Dhj34vCKjZUMV/QEBFo+UN5wETIrenCyigIseNr/jPznDFf3faw7bymK61UmB1BUoVfnLzPb9YrvX8ha+Fd960P1x19WMa4rLY1rWACJgQue0QiIAJkWsfToyu3HyjXNsVY7rWSoAVCygVmHji5LHQ1bXKd3n0WyfgQHX7tZ1jgAmRazsRiIAJkbOtrFSuNWqw+gBKC9HVtVj08l0effNsjO9gINK2muda9AdMiNyeB0TAhMjtvnKOY6G+XWuUYPUJlF2ILq718u69oQoe+mf7v9/+CdJtAhhkN9IGJkRu9wERMCFyu29ensK1RgVWKqC0KMu4Ft+m95XHfh6+PFMVPLyCj4ALaSxFuRYQARMi134iEAETImdbG+FYqE/XGgVYqYGyi9TGtQQUD4Lpg0VH5FZ677EKPCACJkRuz6MvYELkdl/bvG/XyhqsIYHSQrVxLQHFx2t+9vkvhp/OVPVpThwL4VhIYyn2CZTGwLFQX66VJVg5AKUFIDZ1LY4VUP84dZpm8R1WVe4i1+KxWHFgxQ3n4U6IvOKQTpv6dK2swMoNKK1aU9fS8eVY51rv+9sPggArnwNIfQGlsXAs1IdrZQFWrkBpAYi4FndbiLaVhaPq1WsgQfYccu4OiUOqL9caFKwxAKVFx7V4O+SFHQc2NplbAEFs4nEWzwzJrZ7983nbrM0Bl9e5fvz0rtpjYu7AsVBs1xoErDEBZRcR1+JNXBbfbievcy0eiPMMr+rFUs6T6BOgfvfi7eGhr34/6DGa9vcZ+3CtpGCNFSgtahvX+tSX7iz+zg1QAZf6KMcyUDyTTAkV88GxUEzXSgLW2IGi+NIi19rzytnAg/Kv779w2eesgAjRF9E61BBAMQ8ptmv1CtYqAaUFWORaQAVcOp4oiACJF0WJussbGijmh3AsFMu1egFrFYGi+NI819IxRAsUOdt4dshjqFyAYk5STNeKCtaqA6UFmOdaHANEuBIiZ5t9NT71YyjGbyIcC8VwrShg5QFUk9LFO6bKtYAImBC5Riu/Gq/tOcZYrtUJrCkCJRisawERMCFyHTPGiGOhrq61FFhTBsrCgms99/vXKn/rxR5X9Wq83Z9bHsO1WoHlQG1HANd6+MHPBB4/ofVHfrL9gM1W3avxm7uzCzgW6uJajcByoOavPc/wEN9EA2BVR0/NteaC5UBVITJ/2/ojj1YeMDXXqgTLgapko9FGXkpw1yp9jVFkoBotxCoeNCXXqlu/wrEsUOQ82+HbV3gAV3eib6+vwKRc695DlYUowGIPQBHR3utvI7g6VGAqrrV2+J7KKhVg4UxIRwAZUttj+wpM3bUKsCgbL4oRpaG+o1zjr0KcsmttgYVjIS0ojoXU9ti+AlN2rS2wKJu7FlWIq0m41qxk5cda28DCsdDsuOI/joWKht8sVYGputY2sKicuxZViKsputZlYOFYSKXFsZDaHttXYIqudRlYlM1diyrE1dRcqxIsHAuptDgWUttj+wpMzbUqwaJs7lpUIa6m5Fq1YOFYSKXFsZDaHttXIJ1rtZ9b2zMwHr5yoOobmPl0Ry1YDMTJRMlfjVcllo+r4lqvv+1iePHO/4XX33pxqxgApV8cmQsWjoV0Jo6F1PbYvgJjdy2+8ETfXCioLFBcH1WZCxYHuGtRhbgao2tZoPg0LBWpAortaCFYOBbiYIRjIXLXchXgp5pFqTp77XD155uqjk2xrS1QmtNCsDjQXYsqxFXurrUsUKpSI7BwLKSTcCyktsf2FcjVtboCpUo0AouD3bWowtKqPDEn14oFlC60MVg4FtKJOBZS22P7CuTgWrGBUhUag8UJ7lpUIa6Gcq2+gFJ1WoGFYyGdjGMhtT22r0Bq1+obKFWgFVic5K5FFeIqhWulAkqVaQ0WjoXUAY6F1PbYvgJ9ulZqoHT1rcHiRHctqhBXsV1rKKBUlaXAwrGQOsGxkNpjiLnNMZZrDQ2U6roUWJzsrkUV4qqLa+UClCqyNFg4FlJHOBZS22P7CizjWrkBpateGiw6cNeiCnHV1LVyBUrV6AQWjoXUGY6F1PbYvgKLXCt3oHTFncCiE3ctqhBX81yLvzXd5PNQcWfUvrfOYOFYSEPjWEhtj+0rMM+16I3PcukjwBzLttzUGSwuKIpr0ZFrqwJVrjUGoHQBUcDCsZA6xbGQ2h7bVYDaHbjp/qDfgBkTULrSKGDRmbsWVegmgLrv4FMB0RNf7537XR7zrFI0sHAspEEoElLbY30FqBMwIY7i+1/R0796OOlfWmXsWIoGFhNy16IKzVUHlP0Bbd5bXkdGBYuCIF0ihUNqe9yoADXBnRBbcCdka8f2MSsqWBTCXYsqVGsKQOnK54ClQ9pFfuqQzqKYSO0pRq4fd0JcP+6EbJ3YvkqKDhbFcdeiCiFMEaiNKy/9yRNt7Br5SUTqhwIjtVc9cq24E+JacSdka8L2VVYvjkXBpuhaDhQrv6HewOKnE20Ms3G3QOHVXqXIdeFOiOvCnZC9frZPSb2BRRFX3bUcKFa5Wr2CxU8s0tAsBFJ7rJFrwJ0Q14A7IXutbB+L+phnr2Ax4VVyLQeKFW2m3sHipxhpOiwOUnsMkfniToj54k7IXhfbXW9WoHewGGqsruVAsXrLKQlY/GQjTZEFQ2rnFpkb7oSYG+6E7DWw3VVfgSRgMfwYXOuTdxwJx7/7/63PQwETcqBYwXZKBhaLgzQ9XAGpPWQUUHfdfiQwR2BC5EPOa8xjJwOLIpVd68Ybhv3b09kCRbFGrqRg4QBINcMhlKeMDlT/1U4KFpdTdi0Wme0pxFg8hgJoAOfuDpGnGH9KYyQHi0VEKjKLrLyv6ED1Vdn6fpODxVRSuZYDRbWH0SBg4VhIlxzbtSxQJ04eCwfvf0vwuzxVO00cBCwurQ/XqgLqyWeOMZwrcQUGAwvHQrreLq7VP1CapcemFRgMLCbY1bUcKKqYpwYFC8dCKk1T13KgVLF846BgUZY2ruVAUbFxaHCwcCykclW5lgOl6ownDg4WpapzLQeK6oxTWYCFYyGVENfSWy96HcpfNlB1xhGzAItSlV1rAVCc4sq4AtmAhWMhBypjWlpMLRuwmDNvu/hdHpUYv7ICa/zl9CtQBRwsVcJj1Ao4WFHL6Z2pAg6WKuExagWigRV1Vt7Z6CvgYI1+CfO8AAcrz3UZ/awcrNEvYZ4X4GDluS6jn5WDNfolzPMCHKw81yXjWTWb2hsAAAD//0DhVxwAAAAGSURBVAMA8NLI/5AoLlwAAAAASUVORK5CYII=";function gN({className:n="",size:l=36}){return r.jsx("img",{src:vN,alt:"",width:l,height:l,className:`shrink-0 object-contain ${n}`,"aria-hidden":!0,draggable:!1})}const Au={unsupported:"not reported by provider",missing:"no data yet",expired:"expired",unparsable:"provider data unparsable",stale:"stale"},Fx="5H",Wx="1W",bN=new Set(["claude_code","codex_local","muse_code"]),wN="billing_cycle",SN="1M",jN=new Set(Yt.options),NN={critical:"font-medium text-red-300",warning:"font-medium text-yellow-300",normal:"font-medium text-white/75"};function _N(n){return{fiveHour:n.find(l=>l.criticalRole==="five_hour")??null,weekly:n.find(l=>l.criticalRole==="weekly")??null}}function wv(n,l,s){if(n.unavailableReason!==null)return n.unavailableReason;if(n.remainingPercent===null||n.source==="unavailable")return s??"missing";if(n.resetAt!==null){const u=Date.parse(n.resetAt);if(!Number.isFinite(u)||u<=l)return"expired"}if(n.freshUntil!==null){const u=Date.parse(n.freshUntil);if(!Number.isFinite(u)||u<=l)return"stale"}if(n.expiresAt!==null){const u=Date.parse(n.expiresAt);if(!Number.isFinite(u)||u<=l)return"expired"}if(n.observedAt){const u=Date.parse(n.observedAt);if(!Number.isFinite(u)||u>l+6e4)return"stale"}return s??"missing"}function Px(n,l,s,u,d=null){if(Gy(n,l)){const m=Math.round(n.remainingPercent??0),x=n.resetAt?`, resets ${new Date(n.resetAt).toLocaleString()}`:"",y=d?`, ${d}`:"";return`${u}: ${m}% available (${100-m}% used${y}${x})`}const f=cv(n);return f!==null?`${u}: N/A (${f})`:`${u}: N/A (${Au[wv(n,l,s)]})`}function Bd(n,l,s,u,d,f=null){if(Gy(n,s)){const x=n.remainingPercent??0;return{key:n.windowKey,label:d,kind:"known",remaining:Math.round(x),rawRemaining:x,detail:Px(n,s,l.unavailableReason,d,f),isCritical:u}}const m=wv(n,s,l.unavailableReason);return{key:n.windowKey,label:d,kind:"unknown",reason:m,detail:Px(n,s,l.unavailableReason,d,f),isCritical:u}}function ey(n,l){const s=l.unavailableReason??"missing";return{key:`missing:${n}`,label:n,kind:"unknown",reason:s,detail:`${n}: N/A (${Au[s]})`,isCritical:!0}}function kN(n,l,s){return Bd(n,l,s,!0,SN,"current billing cycle")}function AN(n,l=Date.now()){return n.runtimes.map(s=>{const u=Aa(s.runtime),d=s.runtime;if(s.runtime==="cursor_local"){const f=s.windows.find(x=>x.windowKey===wN)??null;if(f===null)return{runtime:u,runtimeKey:d,windows:[],exhausted:!1,detail:`N/A (${Au[s.unavailableReason??"missing"]})`};const m=kN(f,s,l);return{runtime:u,runtimeKey:d,windows:[m],exhausted:m.kind==="known"&&m.rawRemaining===0,detail:m.detail}}if(bN.has(s.runtime)){const{fiveHour:f,weekly:m}=_N(s.windows),x=f!==null?Bd(f,s,l,!0,Fx):ey(Fx,s),y=m!==null?Bd(m,s,l,!0,Wx):ey(Wx,s),v=[x,y],w=v.some(D=>D.kind==="known"&&D.rawRemaining===0),j=v.map(D=>D.detail).join("; ");return{runtime:u,runtimeKey:d,windows:v,exhausted:w,detail:j}}return{runtime:u,runtimeKey:d,windows:[],exhausted:!1,detail:`N/A (${Au[s.unavailableReason??"missing"]})`}})}function ty(n){return n.exhausted?`${n.runtime} exhausted — a capacity window is at 0%: ${n.detail}`:`${n.runtime}: ${n.detail}`}function EN({state:n,nowMs:l}){if(n.status==="loading")return r.jsxs("span",{"data-testid":"topbar-capacity","data-status":"loading",title:"Agent capacity is loading",className:"inline-flex min-w-0 max-w-full flex-wrap items-center gap-x-2 gap-y-1 whitespace-nowrap text-xs text-white/40",children:[r.jsx("span",{className:"uppercase tracking-wider text-white/30",children:"Capacity"}),r.jsx("span",{"aria-live":"polite",children:"loading…"})]});if(n.status==="unavailable")return r.jsxs("span",{"data-testid":"topbar-capacity","data-status":"unavailable",title:"Agent capacity is unavailable — the capacity read failed",className:"inline-flex min-w-0 max-w-full flex-wrap items-center gap-x-2 gap-y-1 whitespace-nowrap text-xs text-white/40",children:[r.jsx("span",{className:"uppercase tracking-wider text-white/30",children:"Capacity"}),r.jsx("span",{children:"unavailable"})]});const s=AN(n.data,l),u=s.length===0||s.every(d=>!d.windows.some(f=>f.kind==="known"));return r.jsxs("span",{"data-testid":"topbar-capacity","data-status":u?"unknown":"ready",title:s.length===0?"Agent capacity: no runtime accounts reported":s.map(ty).join(" · "),className:"inline-flex min-w-0 max-w-full flex-wrap items-center gap-x-3 gap-y-1 text-xs",children:[r.jsx("span",{className:"uppercase tracking-wider text-white/30",children:"Capacity"}),s.length===0?r.jsx("span",{className:"whitespace-nowrap text-white/35",children:"N/A"}):s.map(d=>{const f=d.windows.some(m=>m.kind==="known");return r.jsxs("span",{"data-testid":`topbar-capacity-${d.runtime}`,"data-known":f?"true":"false","data-exhausted":d.exhausted?"true":"false",title:ty(d),role:"group","aria-label":`${jN.has(d.runtimeKey)?d.runtime:"Unknown runtime"} capacity`,className:d.exhausted?"inline-flex items-center gap-1.5 whitespace-nowrap rounded border border-red-400/40 bg-red-500/10 px-1.5 py-0.5":"inline-flex items-center gap-1.5 whitespace-nowrap",children:[r.jsx(hv,{runtime:d.runtimeKey,className:"h-4 w-4 shrink-0"}),d.windows.length===0?r.jsx("span",{className:"text-white/35",children:"N/A"}):r.jsx("span",{className:"inline-flex flex-col leading-tight",children:d.windows.map(m=>r.jsxs("span",{"data-window":m.label,"data-window-known":m.kind==="known"?"true":"false",className:"inline-flex items-center gap-1 whitespace-nowrap tabular-nums",children:[r.jsx("span",{className:"text-white/40",children:m.label}),m.kind==="known"?(()=>{const x=ov(m.rawRemaining);return r.jsxs("span",{"data-severity":x,className:NN[x],children:[m.remaining,"%"]})})():r.jsx("span",{className:"text-white/35",children:"N/A"})]},m.key))})]},d.runtime)})]})}const ay=5e3;function Sd({isActive:n}){return`font-ui-display px-3 py-2 text-base rounded ${n?"bg-cyber-teal/20 text-cyber-teal":"text-white/60 hover:text-white"}`}function CN({agents:n,onHumanActionsChanged:l}){const{issueId:s}=kb();return s?r.jsx(mN,{issueId:s,agents:n,onHumanActionsChanged:l},s):r.jsx(wy,{to:"/issues",replace:!0})}function RN({openHumanActionCount:n,agentCount:l,agentIssueCount:s,capacity:u={status:"loading"}}){return r.jsxs("header",{className:"px-6 py-3 border-b border-white/10 flex flex-wrap gap-4 items-center justify-between glass-header shrink-0",children:[r.jsxs("div",{className:"flex items-center gap-6",children:[r.jsxs(sa,{to:"/issues",className:"flex items-center gap-3 text-left rounded hover:opacity-90 transition-opacity focus-visible:outline focus-visible:outline-2 focus-visible:outline-cyber-teal/45","aria-label":"AgentDealer — go to Issues",title:"AgentDealer — go to Issues",children:[r.jsx(gN,{size:40}),r.jsx("h1",{className:"font-mono text-xl font-bold sm:text-2xl",style:{background:"linear-gradient(to right, #C4B643, #D4C760)",WebkitBackgroundClip:"text",WebkitTextFillColor:"transparent",backgroundClip:"text"},children:"AgentDealer"})]}),r.jsxs("nav",{className:"flex gap-1",children:[r.jsxs(cu,{to:"/issues",className:Sd,children:["Issues",n>0&&r.jsxs("span",{className:"ml-1.5 inline-flex items-center gap-0.5 font-mono text-xs leading-none bg-red-500/20 text-red-300 px-1.5 py-0.5 rounded tabular-nums border border-red-400/30 align-middle",title:`${n} open human action${n===1?"":"s"}`,children:[r.jsx(_u,{className:"w-3 h-3 shrink-0"}),n]})]}),r.jsx(cu,{to:"/reports/execution",className:Sd,children:"Reports"})]})]}),r.jsxs("div",{className:"flex flex-wrap items-center gap-x-4 gap-y-2 min-w-0",children:[r.jsx(EN,{state:u}),r.jsxs(cu,{to:"/agents",className:({isActive:d})=>`${Sd({isActive:d})} inline-flex items-center gap-1.5 transition-colors`,"aria-label":"Agents",title:"Agents",children:[r.jsx(yN,{className:"w-6 h-6 shrink-0"}),r.jsx("span",{children:"Agents"}),l>0&&r.jsx("span",{className:"font-mono text-xs leading-none bg-white/10 text-white/55 px-1.5 py-0.5 rounded tabular-nums border border-white/10",title:`${l} configured agent${l===1?"":"s"}`,children:l}),s>0&&r.jsxs("span",{className:"inline-flex items-center gap-0.5 font-mono text-xs leading-none bg-red-500/20 text-red-300 px-1.5 py-0.5 rounded tabular-nums border border-red-400/30",title:`${s} need${s===1?"s":""} attention`,children:[r.jsx(_u,{className:"w-3 h-3 shrink-0"}),s]})]})]})]})}function TN(){const[n,l]=b.useState([]),[s,u]=b.useState(0),[d,f]=b.useState(!1),[m,x]=b.useState([]),[y,v]=b.useState({status:"loading"}),w=b.useCallback(()=>{H2().then(({agents:E,issueCount:$})=>{l(E),u($)}).catch(console.error),nv().then(E=>f(E.connected)).catch(()=>f(!1)),av().then(E=>v({status:"ready",data:E})).catch(()=>v({status:"unavailable"}))},[]),j=b.useCallback(()=>oS().then(x).catch(()=>{}),[]);b.useEffect(()=>{w();const E=setInterval(w,ay);return()=>clearInterval(E)},[w]),b.useEffect(()=>{j();const E=setInterval(()=>void j(),ay);return()=>clearInterval(E)},[j]);const D=m.length,X=n.length;return r.jsxs(r.Fragment,{children:[r.jsx(xN,{}),r.jsxs("div",{className:"relative z-10 min-h-screen flex flex-col",children:[r.jsx(RN,{openHumanActionCount:D,agentCount:X,agentIssueCount:s,capacity:y}),r.jsx("main",{className:"flex-1 flex overflow-hidden",children:r.jsxs($b,{children:[r.jsx(Ll,{path:"/",element:r.jsx(wy,{to:"/issues",replace:!0})}),r.jsx(Ll,{path:"/issues",element:r.jsx(jj,{agents:n,humanActions:m,onHumanActionsChanged:j})}),r.jsx(Ll,{path:"/issues/:issueId",element:r.jsx(CN,{agents:n,onHumanActionsChanged:j})}),r.jsx(Ll,{path:"/agents",element:r.jsx(HS,{agents:n,agentDeckOnline:d,onRefresh:w})}),r.jsx(Ll,{path:"/reports/execution",element:r.jsx(Mj,{})}),r.jsx(Ll,{path:"*",element:r.jsx(pN,{})})]})})]})]})}function ON(){return typeof document>"u"?Promise.resolve():document.fonts.load('13px "Monaco"').then(()=>{}).catch(()=>{})}ON();H0.createRoot(document.getElementById("root")).render(r.jsx(b.StrictMode,{children:r.jsx(f1,{children:r.jsx(TN,{})})}));
64
+ `)})]}),m.details.evidencePretty&&r.jsxs("div",{className:"text-xs text-white/60",children:[r.jsx("p",{className:"text-white/40",children:"Evidence:"}),r.jsx("pre",{className:"font-mono whitespace-pre-wrap break-all",children:m.details.evidencePretty})]})]})]})]})}function gj({actions:n,busyActionId:l,onResolve:s}){const[u,d]=b.useState({});return n.length===0?null:r.jsxs("div",{className:"mb-4 rounded border border-red-400/30 bg-red-500/10",children:[r.jsxs("div",{className:"px-4 py-2 flex items-center gap-2 border-b border-red-400/20",children:[r.jsx(_u,{className:"w-4 h-4 shrink-0 text-red-300"}),r.jsxs("span",{className:"font-ui-display text-sm font-medium text-red-200",children:[n.length," ",n.length===1?"item needs":"items need"," your attention"]})]}),r.jsx("div",{className:"divide-y divide-white/5",children:n.map(f=>{if(f.issueId)return r.jsx("div",{className:"px-4 py-3 hover:bg-white/5 transition-colors",children:r.jsx(zs,{action:f,linkTo:`/issues/${f.issueId}`})},f.id);const m=f.actionType==="operator_verification",x=u[f.id]??"";return r.jsx("div",{className:"px-4 py-3",children:r.jsx(zs,{action:f,disabled:l===f.id||m&&!x.trim(),onChoose:y=>s(f.id,y,m?x:void 0),children:m&&r.jsx("textarea",{className:"w-full bg-black/30 border border-white/10 rounded px-3 py-2 text-sm text-white/85 placeholder:text-white/30",rows:2,placeholder:"Result note (required) — paste the probe output, waiver reason, or repair note",value:x,disabled:l===f.id,onChange:y=>d(v=>({...v,[f.id]:y.target.value}))})})},f.id)})})]})}const bj="web";function wj(n){if(typeof n!="object"||n===null)return null;const l=n.deletedNotice;return typeof l=="string"&&l.length>0?l:null}function Sj(n){const l=Date.now()-new Date(n).getTime(),s=Math.floor(l/6e4);if(s<1)return"just now";if(s<60)return`${s}m ago`;const u=Math.floor(s/60);return u<24?`${u}h ago`:`${Math.floor(u/24)}d ago`}function jj({agents:n,humanActions:l,onHumanActionsChanged:s}){const[u,d]=b.useState(null),[f,m]=b.useState(null),[x,y]=Ny(),v=x.toString(),w=IS(v),j=b.useRef(w);j.current=w;const[D,X]=b.useState(()=>Dx(v)),[E,$]=b.useState(!1),L=Bx(w),[H,F]=b.useState(!1),[P,ne]=b.useState(!1),[V,Ne]=b.useState(!1),[I,ye]=b.useState("manual"),[Me,bt]=b.useState([]),[At,rt]=b.useState(!1),[yt,lt]=b.useState(""),Qe=b.useRef(yt);Qe.current=yt;const[U,J]=b.useState(""),[re,Ae]=b.useState(!1),[Le,N]=b.useState([]),[Y,W]=b.useState(""),[te,se]=b.useState(""),[B,ce]=b.useState("main"),[Xe,De]=b.useState(""),[Bt,Ta]=b.useState(""),[ua,Va]=b.useState(""),[qe,Za]=b.useState(""),[dt,wt]=b.useState(!0),[Rn,Ye]=b.useState(null),Ga=Ca(),oa=wj(Ga.state),[tn,ol]=b.useState(!1),[ut,ca]=b.useState([]),[Ue,cl]=b.useState(null),[qt,$l]=b.useState(!1),[dl,Yl]=b.useState(null),[fl,Oa]=b.useState(()=>lj()),[tt,Ut]=b.useState(null),[ft,Ft]=b.useState(null),at=Me.find(C=>C.id===yt)??null,Vl=I==="linear"&&at!=null,an=ZS(I,at),nn=Mx({title:Y,repo:te,developerAgentId:ua,reviewerAgentId:qe}),Qa=C=>{X2(C).then(d).catch(de=>Ye(String(de)))},La=()=>{Ex([...fd]).then(Yl).catch(()=>{})},Tn=()=>{ij(),Oa(!0)},ln=nj({historyTotal:dl,filtersActive:L,dismissed:fl}),Tt=()=>{Qa(j.current),dd().then(ca).catch(()=>{}),iS().then(cl).catch(()=>{}),La()},hl=async C=>{$l(!0),Ye(null);try{const de=await sS(C);cl(de),Tt()}catch(de){Ye(String(de))}finally{$l(!1)}},ml=async C=>{Ft(C),Ye(null);try{const de=await lv(C);Ut({issueId:C,developerAgentId:de.issue.developerAgentId,reviewerAgentId:de.issue.reviewerAgentId})}catch(de){Ye(String(de))}finally{Ft(null)}},sn=async(C,de)=>{if(tt){Ft(tt.issueId);try{await fu(tt.issueId,{developerAgentId:C,reviewerAgentId:de}),Ut(null),Tt()}catch(nt){Ut(null),Ye(String(nt)),Tt()}finally{Ft(null)}}},Bi=async C=>{Ft(C),Ye(null);try{await iv(C),Tt()}catch(de){Ye(String(de))}finally{Ft(null)}},Zl=async C=>{Ft(C),Ye(null);try{await sv(C),Tt()}catch(de){Ye(String(de)),Tt()}finally{Ft(null)}},On=C=>{const de=KS(JS(C));y(de?Object.fromEntries(new URLSearchParams(de)):{})},pl=()=>{X(XS),y({})},Ln=C=>{const de=FS(v,C);y(de?Object.fromEntries(new URLSearchParams(de)):{})},Ma=C=>X(de=>({...de,...C})),G=async(C,de,nt)=>{m(C),Ye(null);try{await uv(C,bj,de,nt),s(),Tt()}catch(da){Ye(String(da))}finally{m(null)}};b.useEffect(()=>{X(Dx(v))},[v]),b.useEffect(()=>{Qa(j.current),dd().then(ca).catch(()=>{}),Ex([...fd]).then(Yl).catch(()=>{});const C=setInterval(()=>{Qa(j.current),dd().then(ca).catch(()=>{})},5e3);return()=>clearInterval(C)},[v]);const je=()=>{L2().then(C=>{rt(C.hasMore),bt(de=>GS(de,C.candidates,Qe.current))}).catch(C=>Ye(`Linear inbox: ${String(C)}`))};b.useEffect(()=>{H&&(I2().then(N).catch(()=>N([])),I==="linear"&&je())},[H,I]),b.useEffect(()=>{at&&(W(`${at.identifier}: ${at.title}`),De(at.description??""),Ta(""),se(C=>VS(C,at)))},[at]);const ze=()=>{W(""),se(""),De(""),Ta(""),lt(""),J(""),wt(!0),ce("main")},Ve=C=>{bt(de=>QS(de,C).candidates),lt(C.id),J(C.identifier)},ht=async()=>{const C=U.trim();if(!C){Ye("Paste a Linear id (e.g. NOT-103) or issue URL");return}Ae(!0),Ye(null);try{const de=await M2(C);Ve(de)}catch(de){Ye(`Linear lookup: ${String(de)}`)}finally{Ae(!1)}},mt=async()=>{if(!Mx({title:Y,repo:te,developerAgentId:ua,reviewerAgentId:qe})){Ye("Title, GitHub repository, developer, and reviewer are required");return}try{await W2({title:Y.trim(),repo:te.trim(),baseBranch:B.trim()||"main",description:Xe.trim()||void 0,acceptanceCriteria:Bt.trim()||void 0,developerAgentId:ua,reviewerAgentId:qe,maxReviewRounds:3,maxInfraAttempts:3,autoMerge:dt,source:I==="linear"&&at?"linear":"manual",externalId:at==null?void 0:at.id,externalLabel:at==null?void 0:at.identifier,externalUrl:at==null?void 0:at.url,linearAttachments:at==null?void 0:at.attachments}),F(!1),ze(),Tt()}catch(C){Ye(String(C))}};return r.jsxs("div",{className:"flex-1 min-h-0 px-6 py-4 w-full overflow-y-auto",children:[r.jsxs("div",{className:"flex items-center justify-between mb-4",children:[r.jsx("h2",{className:"font-ui-display text-lg font-semibold text-white/90",children:"Issues"}),r.jsx("button",{type:"button",className:"btn-gold px-4",onClick:()=>F(C=>!C),children:"New issue"})]}),Rn&&r.jsx("p",{className:"text-sm text-red-300 mb-3",children:Rn}),oa&&!tn&&r.jsxs("div",{className:"mb-3 p-3 rounded border border-white/15 bg-white/[0.04] flex items-start justify-between gap-3",children:[r.jsx("p",{className:"text-sm text-white/85",children:oa}),r.jsx("button",{type:"button",className:"font-ui-display shrink-0 text-xs text-white/50 hover:text-white",onClick:()=>ol(!0),children:"Dismiss"})]}),ln&&r.jsx(sj,{agents:n,onStartIssue:()=>F(!0),onDismiss:Tn}),H&&r.jsxs("div",{className:"mb-4 p-4 rounded border border-white/10 bg-panel-elevated/60 space-y-2",children:[r.jsxs("p",{className:"text-xs text-white/50",children:["Workflow:"," ",r.jsxs("span",{className:"text-white/75",children:["developer → reviewer → ",dt?"auto-merge on approve":"final human review"]}),"."]}),r.jsxs("div",{className:"flex gap-2 text-sm",children:[r.jsx("button",{type:"button",className:`font-ui-display px-3 py-1 rounded border ${I==="manual"?"border-teal/50 text-teal":"border-white/10 text-white/50"}`,onClick:()=>{ye("manual"),lt("")},children:"Manual"}),r.jsx("button",{type:"button",className:`font-ui-display px-3 py-1 rounded border ${I==="linear"?"border-teal/50 text-teal":"border-white/10 text-white/50"}`,onClick:()=>ye("linear"),children:"From Linear"})]}),I==="linear"&&r.jsxs("div",{className:"space-y-2",children:[r.jsxs("div",{className:"flex gap-2",children:[r.jsx("input",{className:"flex-1 bg-black/30 border border-white/10 rounded px-3 py-2 text-sm",placeholder:"NOT-103 or Linear URL",value:U,onChange:C=>J(C.target.value),onKeyDown:C=>{C.key==="Enter"&&(C.preventDefault(),ht())}}),r.jsx("button",{type:"button",className:"font-ui-display px-3 py-2 rounded border border-teal/40 text-teal text-sm disabled:opacity-50",disabled:re||!U.trim(),onClick:()=>void ht(),children:re?"…":"Lookup"})]}),r.jsxs("div",{className:"space-y-1",children:[r.jsxs("div",{className:"flex items-center gap-1.5",children:[r.jsx("span",{className:"text-xs text-white/50",children:"Or pick from open inbox…"}),r.jsx("button",{type:"button","aria-label":"Configure Linear intake filters",title:"Configure Linear intake filters","aria-expanded":V,onClick:()=>Ne(C=>!C),className:"text-white/40 hover:text-white shrink-0 rounded focus-visible:outline focus-visible:outline-2 focus-visible:outline-cyber-teal/45",children:r.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 16 16",fill:"none","aria-hidden":"true",children:[r.jsx("path",{d:"M8 5.2a2.8 2.8 0 1 0 0 5.6 2.8 2.8 0 0 0 0-5.6Z",stroke:"currentColor",strokeWidth:"1.3"}),r.jsx("path",{d:"M8 1.5v1.7M8 12.8v1.7M1.5 8h1.7M12.8 8h1.7M3.4 3.4l1.2 1.2M11.4 11.4l1.2 1.2M12.6 3.4l-1.2 1.2M4.6 11.4l-1.2 1.2",stroke:"currentColor",strokeWidth:"1.3",strokeLinecap:"round"})]})})]}),r.jsxs("select",{className:"w-full bg-black/30 border border-white/10 rounded px-3 py-2 text-sm","aria-label":"Or pick from open inbox",value:yt,onChange:C=>{const de=C.target.value;lt(de);const nt=Me.find(da=>da.id===de);nt&&J(nt.identifier)},children:[r.jsx("option",{value:"",children:"Select an issue…"}),Me.map(C=>r.jsxs("option",{value:C.id,children:[C.identifier,": ",C.title]},C.id))]}),V&&r.jsx(fj,{onClose:()=>Ne(!1),onSaved:je}),At&&r.jsx("p",{className:"text-xs text-white/40","data-testid":"linear-candidates-has-more",children:"Showing the 50 most recently updated matches. Use exact ID/URL lookup above for another issue."})]})]}),r.jsx("input",{className:"w-full bg-black/30 border border-white/10 rounded px-3 py-2 text-sm disabled:opacity-60",placeholder:"Title",value:Y,disabled:Vl,onChange:C=>W(C.target.value)}),r.jsx("textarea",{className:"w-full bg-black/30 border border-white/10 rounded px-3 py-2 text-sm disabled:opacity-60",rows:3,placeholder:"Problem statement / description",value:Xe,disabled:Vl,onChange:C=>De(C.target.value)}),r.jsx("textarea",{className:"w-full bg-black/30 border border-white/10 rounded px-3 py-2 text-sm",rows:3,placeholder:"Acceptance criteria (derived from the ticket when left empty)",value:Bt,onChange:C=>Ta(C.target.value)}),r.jsxs("div",{className:"flex gap-2 items-stretch",children:[r.jsxs("div",{className:"flex-1 space-y-1 min-w-0",children:[r.jsxs("div",{className:"flex items-center gap-1.5",children:[r.jsx("span",{className:"text-xs text-white/50",children:"Repository"}),r.jsx("button",{type:"button","aria-label":"Configure repository mappings",title:"Configure repository mappings","aria-expanded":P,onClick:()=>ne(C=>!C),className:"text-white/40 hover:text-white shrink-0 rounded focus-visible:outline focus-visible:outline-2 focus-visible:outline-cyber-teal/45",children:r.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 16 16",fill:"none","aria-hidden":"true",children:[r.jsx("path",{d:"M8 5.2a2.8 2.8 0 1 0 0 5.6 2.8 2.8 0 0 0 0-5.6Z",stroke:"currentColor",strokeWidth:"1.3"}),r.jsx("path",{d:"M8 1.5v1.7M8 12.8v1.7M1.5 8h1.7M12.8 8h1.7M3.4 3.4l1.2 1.2M11.4 11.4l1.2 1.2M12.6 3.4l-1.2 1.2M4.6 11.4l-1.2 1.2",stroke:"currentColor",strokeWidth:"1.3",strokeLinecap:"round"})]})})]}),r.jsx(yv,{value:te,onChange:se,recentRepos:Le}),P&&r.jsx(oj,{recentRepos:Le,onClose:()=>ne(!1)}),an&&r.jsx("p",{className:"text-xs text-amber-200/80","data-testid":"repo-label-warning",children:an})]}),r.jsx("input",{className:"w-32 bg-black/30 border border-white/10 rounded px-3 py-2 text-sm",placeholder:"Base (seed)",title:"Seed only — managed GitHub clones use the remote default at first checkout",value:B,onChange:C=>ce(C.target.value)})]}),r.jsxs("select",{className:"w-full bg-black/30 border border-white/10 rounded px-3 py-2 text-sm",value:ua,onChange:C=>Va(C.target.value),children:[r.jsx("option",{value:"",children:"Developer agent…"}),n.map(C=>r.jsx("option",{value:C.id,children:C.name},C.id))]}),r.jsxs("select",{className:"w-full bg-black/30 border border-white/10 rounded px-3 py-2 text-sm",value:qe,onChange:C=>Za(C.target.value),children:[r.jsx("option",{value:"",children:"Reviewer agent…"}),n.map(C=>r.jsx("option",{value:C.id,children:C.name},C.id))]}),r.jsxs("label",{className:"flex items-center gap-2 text-sm text-white/70 cursor-pointer",children:[r.jsx("input",{type:"checkbox",checked:dt,onChange:C=>wt(C.target.checked),className:"accent-[#C4B643]"}),"Auto-merge when reviewer approves (skip final human review)"]}),r.jsxs("div",{className:"flex gap-2",children:[r.jsx("button",{type:"button",className:"btn-gold px-4 disabled:opacity-40",disabled:!nn,title:nn?void 0:"Title, GitHub repository, developer, and reviewer are required",onClick:mt,children:I==="linear"?"Kick from Linear":"Create"}),r.jsx("button",{type:"button",className:"font-ui-display px-4 py-2 text-sm text-white/60 hover:text-white",onClick:()=>{F(!1),ze()},children:"Cancel"})]})]}),ut.length>0?r.jsxs("div",{className:"mb-4 rounded border border-cyber-teal/25 bg-cyber-teal/5",children:[r.jsxs("div",{className:"px-4 py-2 border-b border-cyber-teal/20 flex items-center justify-between gap-3",children:[r.jsx("span",{className:"font-ui-display text-sm font-medium text-cyber-teal",children:"Admission queue"}),r.jsx("span",{className:"flex items-center gap-2 text-xs text-white/40",children:Ue?r.jsxs(r.Fragment,{children:[r.jsxs("span",{children:[Ue.active," active · ",Ue.waiting," waiting · limit"," ",Ue.limit,Ue.overCap?" · over capacity":""]}),Ue.options.length>0?r.jsxs("label",{className:"flex items-center gap-1",children:[r.jsx("span",{className:"text-white/35",children:"limit"}),r.jsx("select",{className:"bg-black/30 border border-white/10 rounded px-1.5 py-0.5 text-xs text-white/80 disabled:opacity-50",value:Ue.options.includes(Ue.maxActiveIssues)?Ue.maxActiveIssues:Ue.limit,disabled:qt,title:Ue.ceiling<2?`Capped by the worker/spawn ceiling (${Ue.ceiling})`:"How many issues may execute in parallel (same-repository issues may run together)",onChange:C=>void hl(Number(C.target.value)),children:Ue.options.map(C=>r.jsx("option",{value:C,children:C},C))})]}):r.jsxs("span",{title:`Capped by the worker/spawn ceiling (${Ue.ceiling})`,children:["max ",Ue.ceiling]})]}):r.jsxs("span",{children:[ut.length," waiting · sequential"]})})]}),r.jsx("div",{className:"divide-y divide-white/5",children:ut.map((C,de)=>r.jsxs("div",{children:[r.jsxs("div",{className:"px-4 py-2 flex items-start gap-3",children:[r.jsx("span",{className:"text-xs text-white/35 w-5 shrink-0 pt-0.5",children:C.position}),r.jsxs(sa,{to:`/issues/${C.issueId}`,className:"flex-1 min-w-0 text-left hover:text-cyber-teal",children:[r.jsx("span",{className:"text-sm text-white/85 truncate block",children:C.title??C.issueId.slice(0,8)}),C.waitReason?r.jsx("span",{className:"text-xs text-amber-200/80 block mt-0.5",children:C.waitReason}):r.jsxs("span",{className:"text-xs text-white/35 block mt-0.5",children:[C.issueStatus??"queued"," · next up"]})]}),r.jsxs("div",{className:"flex items-center gap-2 shrink-0 flex-wrap justify-end",children:[r.jsx("button",{type:"button",className:"font-ui-display text-xs text-white/40 hover:text-cyber-teal disabled:opacity-30",disabled:ft===C.issueId,title:"Change the developer/reviewer agents — keeps queue position and rechecks the wait reason",onClick:()=>void ml(C.issueId),children:"Edit"}),r.jsx("button",{type:"button",className:"font-ui-display text-xs text-white/40 hover:text-cyber-teal disabled:opacity-30",disabled:ft===C.issueId,title:"Run next — move to the front of the admission queue; runs now if a slot is free, otherwise waits first with a reason",onClick:()=>void Bi(C.issueId),children:"Run next"}),r.jsx("button",{type:"button",className:"font-ui-display text-xs text-white/40 hover:text-cyber-teal disabled:opacity-30",disabled:ft===C.issueId,title:"Execute now — start immediately, skipping queue order; refuses (changing nothing) when capacity, readiness, blockers, or agent health prevents it",onClick:()=>void Zl(C.issueId),children:"Execute now"}),r.jsx("button",{type:"button",className:"font-ui-display text-xs text-white/40 hover:text-cyber-teal disabled:opacity-30",disabled:de===0,title:"Move to top",onClick:()=>{nu(C.issueId,"top").then(Tt).catch(nt=>Ye(String(nt)))},children:"Top"}),r.jsx("button",{type:"button",className:"font-ui-display text-xs text-white/40 hover:text-cyber-teal disabled:opacity-30",disabled:de===0,title:"Move up",onClick:()=>{const nt=ut[de-1];nt&&nu(C.issueId,{before:nt.issueId}).then(Tt).catch(da=>Ye(String(da)))},children:"↑"}),r.jsx("button",{type:"button",className:"font-ui-display text-xs text-white/40 hover:text-cyber-teal disabled:opacity-30",disabled:de===ut.length-1,title:"Move down",onClick:()=>{const nt=ut[de+1];nt&&nu(C.issueId,{after:nt.issueId}).then(Tt).catch(da=>Ye(String(da)))},children:"↓"}),r.jsx("button",{type:"button",className:"font-ui-display text-xs text-white/40 hover:text-cyber-teal disabled:opacity-30",disabled:de===ut.length-1,title:"Move to bottom",onClick:()=>{nu(C.issueId,"bottom").then(Tt).catch(nt=>Ye(String(nt)))},children:"Bottom"}),r.jsx("button",{type:"button",className:"font-ui-display text-xs text-white/40 hover:text-white",onClick:()=>{rv(C.issueId).then(Tt).catch(nt=>Ye(String(nt)))},children:"Remove"})]})]}),(tt==null?void 0:tt.issueId)===C.issueId&&r.jsx("div",{className:"px-4 pb-3 pl-12",children:r.jsx(bv,{agents:n,initialDeveloperId:tt.developerAgentId,initialReviewerId:tt.reviewerAgentId,busy:ft===C.issueId,onSave:(nt,da)=>void sn(nt,da),onCancel:()=>Ut(null)})})]},C.id))})]}):Ue?r.jsxs("p",{"data-testid":"admission-idle-status",className:"mb-4 text-xs text-white/35 tabular-nums",children:["Admission: ",Ue.active," active · ",Ue.waiting," waiting · limit"," ",Ue.limit,Ue.overCap?" · over capacity":"",Ue.options.length>0&&r.jsxs("label",{className:"ml-2 inline-flex items-center gap-1",children:[r.jsx("span",{children:"limit"}),r.jsx("select",{className:"bg-black/30 border border-white/10 rounded px-1.5 py-0.5 text-xs text-white/60 disabled:opacity-50",value:Ue.options.includes(Ue.maxActiveIssues)?Ue.maxActiveIssues:Ue.limit,disabled:qt,title:Ue.ceiling<2?`Capped by the worker/spawn ceiling (${Ue.ceiling})`:"How many issues may execute in parallel (same-repository issues may run together)",onChange:C=>void hl(Number(C.target.value)),children:Ue.options.map(C=>r.jsx("option",{value:C,children:C},C))})]})]}):null,r.jsx(gj,{actions:l,busyActionId:f,onResolve:(C,de,nt)=>void G(C,de,nt)}),r.jsxs("div",{className:"mb-4 rounded border border-white/10 bg-panel-elevated/60",children:[r.jsxs("button",{type:"button","aria-expanded":E,"aria-controls":"issues-filter-form",onClick:()=>$(C=>!C),className:"w-full flex items-center gap-2 px-4 py-2.5 text-sm text-white/70 hover:text-white",children:[r.jsx("span",{"aria-hidden":"true",className:"text-xs text-white/40 w-3 shrink-0",children:E?"▾":"▸"}),r.jsx("span",{className:"font-ui-display",children:E?"Hide filters":"Show filters"}),L&&r.jsx("span",{"data-testid":"filters-active-indicator",title:"The issue list is filtered",className:"text-xs px-2 py-0.5 rounded-full border border-[#C4B643]/50 text-[#C4B643]",children:"Filtered"})]}),E&&r.jsx("form",{id:"issues-filter-form","aria-label":"Issues filters",className:"px-4 pb-4",onSubmit:C=>{C.preventDefault(),On(D)},children:r.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-3",children:[r.jsxs("label",{className:"block text-sm",children:[r.jsx("span",{className:"block text-xs text-white/50 mb-1",children:"Search"}),r.jsx("input",{type:"text",placeholder:"Title or label (e.g. NOT-175)",className:"w-full bg-black/30 border border-white/10 rounded px-3 py-2",value:D.q,onChange:C=>Ma({q:C.target.value})})]}),r.jsxs("label",{className:"block text-sm",children:[r.jsx("span",{className:"block text-xs text-white/50 mb-1",children:"Status"}),r.jsxs("select",{className:"w-full bg-black/30 border border-white/10 rounded px-3 py-2",value:D.status,onChange:C=>Ma({status:C.target.value}),children:[r.jsx("option",{value:"",children:"All statuses"}),fd.map(C=>r.jsx("option",{value:C,children:C},C))]})]}),r.jsxs("label",{className:"block text-sm",children:[r.jsx("span",{className:"block text-xs text-white/50 mb-1",children:"Repository"}),r.jsx("input",{type:"text",placeholder:"github.com/owner/repo",title:"Exact repository identity",className:"w-full bg-black/30 border border-white/10 rounded px-3 py-2",value:D.repo,onChange:C=>Ma({repo:C.target.value})})]}),r.jsx("div",{className:"flex items-end gap-2",children:r.jsxs("label",{className:"flex items-center gap-2 text-sm text-white/70 cursor-pointer pb-2",children:[r.jsx("input",{type:"checkbox",checked:D.needsAttention,onChange:C=>Ma({needsAttention:C.target.checked}),className:"accent-[#C4B643]"}),"Needs attention"]})}),r.jsxs("div",{className:"flex items-end gap-2 sm:col-span-2 lg:col-span-4",children:[r.jsx("button",{type:"submit",className:"btn-gold px-4",children:"Apply"}),r.jsx("button",{type:"button",className:"px-4 py-2 text-sm text-white/60 hover:text-white",onClick:pl,children:"Reset"})]})]})})]}),u===null?r.jsx("p",{className:"text-white/50 text-sm",children:"Loading…"}):u.total===0&&!Bx(w)?r.jsx("p",{className:"text-white/45 text-sm",children:"No issues yet — create one to get started."}):u.total===0?r.jsxs("div",{className:"rounded border border-white/10 bg-panel-elevated/40 px-4 py-3",children:[r.jsx("p",{className:"text-white/45 text-sm",children:Ux(u)}),r.jsx("button",{type:"button",className:"mt-2 px-3 py-1.5 text-sm rounded border border-white/15 text-white/70 hover:text-white",onClick:pl,children:"Reset filters"})]}):r.jsxs("div",{children:[r.jsx("div",{className:"flex justify-end mb-2",children:r.jsxs("p",{className:"text-xs text-white/40 tabular-nums",children:[Ux(u),zx(u)?` · ${zx(u)}`:""]})}),r.jsx("div",{className:"space-y-2",children:u.issues.map(C=>{const de=ut.find(nt=>nt.issueId===C.id);return r.jsxs(sa,{to:`/issues/${C.id}`,className:"w-full text-left flex items-center gap-3 px-4 py-3 rounded border border-white/10 bg-panel-elevated/40 hover:bg-panel-elevated/70 transition-colors",children:[C.hasOpenHumanAction&&r.jsx(_u,{className:"w-4 h-4 shrink-0 text-red-400"}),r.jsxs("div",{className:"flex-1 min-w-0",children:[r.jsx("p",{className:"text-sm font-medium text-white/90 truncate",children:C.title}),de!=null&&de.waitReason?r.jsx("p",{className:"text-xs text-amber-200/80 truncate",title:de.waitReason,children:de.waitReason}):C.currentIntent&&r.jsx("p",{className:"text-xs text-white/50 truncate",children:C.currentIntent})]}),r.jsx("span",{className:"text-xs text-white/40 capitalize shrink-0",children:C.currentOwner}),de&&r.jsxs("span",{className:"text-xs px-2 py-0.5 rounded border border-cyber-teal/40 text-cyber-teal shrink-0",title:de.waitReason??"Next up for admission",children:["Queued #",de.position]}),r.jsx(mv,{status:C.status}),r.jsx("span",{className:"text-xs text-white/35 shrink-0 w-16 text-right",children:Sj(C.updatedAt)})]},C.id)})}),u.totalPages>1&&r.jsxs("nav",{"aria-label":"Issues pages",className:"mt-3 flex items-center gap-2",children:[r.jsx("button",{type:"button",className:"px-3 py-1.5 text-sm rounded border border-white/15 text-white/70 hover:text-white disabled:opacity-40",disabled:u.page<=1,onClick:()=>Ln(u.page-1),children:"Previous"}),r.jsxs("span",{className:"text-xs text-white/45 tabular-nums",children:["Page ",u.page," of ",u.totalPages]}),r.jsx("button",{type:"button",className:"px-3 py-1.5 text-sm rounded border border-white/15 text-white/70 hover:text-white disabled:opacity-40",disabled:u.page>=u.totalPages,onClick:()=>Ln(u.page+1),children:"Next"})]})]})]})}const Nj=["developer","reviewer","legacy"],Hx=["claude_code","cursor_local","codex_local"],_j=["ready","developing","reviewing","repairing","final_review","needs_human","done","closed"];function Ri(n,l){return n.n===0||n.p50===null&&n.p95===null?{available:!1,p50Text:null,p95Text:null,sampleText:"n=0",sampleTitle:"No observations in this cohort",sparse:!0}:{available:!0,p50Text:n.p50===null?null:l(n.p50),p95Text:n.p95===null?null:l(n.p95),sampleText:Wy(n.n),sampleTitle:`Sample size ${n.n}${Md(n.n)?" — fewer than 5 observations, compare with care":""}`,sparse:Md(n.n)}}function ja(n,l,s){if(n.sum===null||n.known===0)return{available:!1,valueText:"N/A",exactText:null,noteText:null,noteTitle:null,incomplete:n.known<n.total};const u=l(n.sum),d=s!=null&&s.compact?g2(n.sum):u,f=n.known<n.total;return{available:!0,valueText:d,exactText:s!=null&&s.compact?u:null,noteText:f?`${Je(n.known)}/${Je(n.total)} known`:null,noteTitle:f?"Partial sample — missing provider metadata is excluded, never zero":null,incomplete:f}}function Hs(n,l,s){return n===null||l===0?{available:!1,valueText:"N/A",evidenceCounts:null,evidenceNoun:null,title:`No ${s} in this cohort`}:{available:!0,valueText:Bu(n),evidenceCounts:`${Je(Math.round(n*l))}/${Je(l)}`,evidenceNoun:s,title:`Exact share over ${l} ${s}`}}function $x(n,l,s){const u=Hs(n,l,s);return u.available?{text:`${u.valueText} (${u.evidenceCounts} ${u.evidenceNoun})`,title:u.title}:{text:u.valueText,title:u.title}}function md(n){const l=$x(n.issueSuccess,n.issueSuccessDenominator,"closed"),s=$x(n.attemptSuccess,n.attemptSuccessDenominator,"terminal attempts");return{key:n.key,issuesText:Je(n.issues),attemptsText:Je(n.attempts),issueSuccessText:l.text,issueSuccessTitle:l.title,attemptSuccessText:s.text,attemptSuccessTitle:s.title,issueSuccessDisplay:Hs(n.issueSuccess,n.issueSuccessDenominator,"closed"),attemptSuccessDisplay:Hs(n.attemptSuccess,n.attemptSuccessDenominator,"terminal attempts"),wallText:Ax(n.sessionWallMs,Kt),envelopeText:Ax(n.spawnEnvelopeMs,Kt),retryText:n.retryRate===null?"N/A":Bu(n.retryRate),retryTitle:"Extra attempts after a terminal attempt in the same issue/role/round ÷ attempts",tokensInText:ll(n.tokensIn,Je),tokensOutText:ll(n.tokensOut,Je),costText:ll(n.costUsd,Ls),costIncomplete:n.costUsd.known<n.costUsd.total,durationText:ll(n.durationMs,Kt),failedCostText:ll(n.failedCostUsd,Ls),failedTokensText:`${ll(n.failedTokensIn,Je)} in · ${ll(n.failedTokensOut,Je)} out`,failedDurationText:ll(n.failedDurationMs,Kt),wall:Ri(n.sessionWallMs,Kt),envelope:Ri(n.spawnEnvelopeMs,Kt),tokensIn:ja(n.tokensIn,Je,{compact:!0}),tokensOut:ja(n.tokensOut,Je,{compact:!0}),cost:ja(n.costUsd,Ls),duration:ja(n.durationMs,Kt),failedCost:ja(n.failedCostUsd,Ls),failedTokensIn:ja(n.failedTokensIn,Je,{compact:!0}),failedTokensOut:ja(n.failedTokensOut,Je,{compact:!0}),failedDuration:ja(n.failedDurationMs,Kt),failedIncomplete:n.failedCostUsd.known<n.failedCostUsd.total||n.failedTokensIn.known<n.failedTokensIn.total||n.failedTokensOut.known<n.failedTokensOut.total||n.failedDurationMs.known<n.failedDurationMs.total,sparse:n.attempts>0&&Md(n.attempts)}}function kj(n,l){const s=n.code==="unknown";return{code:n.code,domain:n.domain,countText:Je(n.count),shareText:n.share===null?"N/A":Bu(n.share),shareTitle:l>0?`${Je(n.count)} of ${Je(l)} issues with a failed attempt`:"No issues with a failed attempt in scope",isUnknown:s,blurb:s?"Ambiguous evidence — not promoted to a specific cause.":`Primary cause · ${n.domain} domain`,displayCode:s?"Cause not recorded":n.code,displayNote:s?"Needs more evidence":`Primary cause · ${n.domain} domain`,issueIds:n.issueIds,hiddenIssueCount:Math.max(0,n.issueTotal-n.issueIds.length)}}function Aj(n){const l=n.reduce((s,u)=>s+u.count,0);return n.map(s=>kj(s,l))}function Ej(n){return`/issues/${n}`}function Yx(n,l){if(n!=null&&n.trim()&&/^\d{4}-\d{2}-\d{2}$/.test(n.trim()))return l?`${n.trim()}T23:59:59.999Z`:`${n.trim()}T00:00:00.000Z`}function Vx(n){if(!n)return"";const l=n.match(/^(\d{4}-\d{2}-\d{2})/);return l?l[1]:""}function Zx(n){const l=new URLSearchParams(n.startsWith("?")?n.slice(1):n),s=u=>{var d;return((d=l.get(u))==null?void 0:d.trim())??""};return{fromDate:Vx(s("from")),toDate:Vx(s("to")),repo:s("repo"),role:s("role"),runtime:s("runtime"),model:s("model"),status:s("status")}}function Cj(n){const l=new URLSearchParams(n.startsWith("?")?n.slice(1):n),s=d=>{var m;const f=(m=l.get(d))==null?void 0:m.trim();return f||void 0},u={};for(const d of["from","to","repo","role","runtime","model","status"]){const f=s(d);f!==void 0&&(u[d]=f)}return u}function Rj(n,l,s){const u=new URLSearchParams(n.startsWith("?")?n.slice(1):n);u.set(l,s),u.delete("page"),u.delete("limit"),u.sort();const d=u.toString();return`/reports/execution${d?`?${d}`:""}`}function Tj(n){return{from:Yx(n.fromDate,!1),to:Yx(n.toDate,!0),repo:n.repo.trim()||void 0,role:n.role||void 0,runtime:n.runtime.trim()||void 0,model:n.model.trim()||void 0,status:n.status.trim()||void 0}}function pd(n){return n===null?"N/A":Bu(n)}function Ba({label:n,value:l,valueTitle:s,note:u}){return r.jsxs("div",{className:"rounded border border-white/10 bg-panel-elevated/60 px-4 py-3",children:[r.jsx("p",{className:"font-ui-display text-xs uppercase tracking-wide text-white/40",children:n}),r.jsx("div",{className:"mt-1 font-mono text-lg font-semibold text-white/90 tabular-nums",title:s,children:l}),u&&r.jsx("div",{className:"mt-0.5 font-ui-display text-xs text-white/40",children:u})]})}function ku({display:n,compact:l}){if(!n.available)return r.jsx("span",{className:"font-mono text-white/45",title:n.title,children:"N/A"});const s=l?"font-mono text-sm font-medium text-white/85 tabular-nums leading-tight whitespace-nowrap":"font-mono text-base sm:text-lg font-semibold text-white/90 tabular-nums leading-tight whitespace-nowrap";return r.jsxs("span",{className:"inline-flex flex-wrap items-baseline gap-x-2",title:n.title,children:[r.jsx("span",{className:s,"aria-label":n.title,children:n.valueText}),r.jsxs("span",{className:"font-ui-display min-w-0 break-words text-xs text-white/40",children:["(",r.jsx("span",{className:"font-mono tabular-nums",children:n.evidenceCounts})," ",n.evidenceNoun,")"]})]})}function Ms({display:n,compact:l}){if(!n.available)return r.jsx("span",{className:"font-mono text-white/45",children:"N/A"});const s=l?"font-ui-display text-[11px] uppercase tracking-wide text-white/40":"font-ui-display text-xs uppercase tracking-wide text-white/40",u=l?"font-mono text-sm font-medium text-white/85 tabular-nums":"font-mono text-base font-semibold text-white/90 tabular-nums";return r.jsxs("span",{className:"inline-flex flex-wrap items-baseline gap-x-3 gap-y-0.5",children:[r.jsxs("span",{className:"inline-flex items-baseline gap-x-1.5",children:[r.jsx("span",{className:s,children:"P50"}),r.jsx("span",{className:u,children:n.p50Text??"N/A"})]}),r.jsxs("span",{className:"inline-flex items-baseline gap-x-1.5",children:[r.jsx("span",{className:s,children:"P95"}),r.jsx("span",{className:u,children:n.p95Text??"N/A"})]}),r.jsx("span",{className:"font-ui-display text-xs text-white/40",title:n.sampleTitle,children:n.sampleText})]})}function Na({display:n,compact:l}){if(!n.available)return r.jsx("span",{className:"font-mono text-white/45",children:"N/A"});const s=n.exactText??n.valueText,u=l?"font-mono text-sm font-medium text-white/85 tabular-nums":"font-mono text-base font-semibold text-white/90 tabular-nums";return r.jsxs("span",{className:"inline-flex flex-wrap items-baseline gap-x-2",children:[r.jsx("span",{className:u,title:s,"aria-label":s,children:n.valueText}),n.noteText&&r.jsx("span",{className:"font-ui-display text-xs text-white/40",title:n.noteTitle??void 0,children:n.noteText})]})}function xd({caption:n,dimension:l,rows:s,cohortLink:u}){return s.length===0?r.jsxs("div",{className:"rounded border border-white/10 bg-panel-elevated/60 px-4 py-3",children:[r.jsx("h4",{className:"font-ui-display text-sm font-medium text-white/80",children:n}),r.jsx("p",{className:"font-ui-display mt-1 text-sm text-white/45",children:"No attempts in this dimension for these filters."})]}):r.jsx("div",{className:"rounded border border-white/10 bg-panel-elevated/60 overflow-x-auto",children:r.jsxs("table",{className:"w-full min-w-[1440px] text-sm",children:[r.jsxs("caption",{className:"sr-only",children:[n," — sorted by name, never by cost"]}),r.jsx("thead",{children:r.jsxs("tr",{className:"font-ui-display text-left text-xs uppercase tracking-wide text-white/40 border-b border-white/10",children:[r.jsx("th",{scope:"col",className:"px-4 py-2 font-medium",children:n}),r.jsx("th",{scope:"col",className:"px-3 py-2 font-medium",children:"Issues"}),r.jsx("th",{scope:"col",className:"px-3 py-2 font-medium",children:"Attempts"}),r.jsx("th",{scope:"col",className:"px-3 py-2 font-medium",children:"Issue success"}),r.jsx("th",{scope:"col",className:"px-3 py-2 font-medium",children:"Attempt success"}),r.jsx("th",{scope:"col",className:"px-3 py-2 font-medium",children:"Session wall P50/P95"}),r.jsx("th",{scope:"col",className:"px-3 py-2 font-medium",children:"Retry rate"}),r.jsx("th",{scope:"col",className:"px-3 py-2 font-medium",children:"Tokens in"}),r.jsx("th",{scope:"col",className:"px-3 py-2 font-medium",children:"Tokens out"}),r.jsx("th",{scope:"col",className:"px-3 py-2 font-medium",children:"Cost"}),r.jsx("th",{scope:"col",className:"px-3 py-2 font-medium",children:"Duration"}),r.jsx("th",{scope:"col",className:"px-3 py-2 font-medium",children:"Failed cost"}),r.jsx("th",{scope:"col",className:"px-3 py-2 font-medium",children:"Failed tokens"}),r.jsx("th",{scope:"col",className:"px-3 py-2 font-medium",children:"Failed runtime"})]})}),r.jsx("tbody",{className:"divide-y divide-white/5",children:s.map(d=>r.jsxs("tr",{className:"tabular-nums",children:[r.jsxs("th",{scope:"row",className:"px-4 py-2 text-left font-mono font-medium text-white/85",children:[u?r.jsx(sa,{to:u(l,d.key),className:"text-cyber-teal hover:underline focus-visible:outline focus-visible:outline-2 focus-visible:outline-cyber-teal/45",title:`Filter the report to ${l} ${d.key}`,children:d.key}):d.key,d.sparse&&r.jsx("span",{className:"font-ui-display ml-2 text-xs font-normal text-amber-200/80",title:"Fewer than 5 attempts — compare with care",children:"sparse"})]}),r.jsx("td",{className:"px-3 py-2 font-mono text-white/75",children:d.issuesText}),r.jsx("td",{className:"px-3 py-2 font-mono text-white/75",children:d.attemptsText}),r.jsx("td",{className:"px-3 py-2 text-white/75",title:d.issueSuccessTitle,children:r.jsx(ku,{display:d.issueSuccessDisplay,compact:!0})}),r.jsx("td",{className:"px-3 py-2 text-white/75",title:d.attemptSuccessTitle,children:r.jsx(ku,{display:d.attemptSuccessDisplay,compact:!0})}),r.jsx("td",{className:"px-3 py-2 text-white/75",children:r.jsx(Ms,{display:d.wall,compact:!0})}),r.jsx("td",{className:"px-3 py-2 font-mono text-white/75",title:d.retryTitle,children:d.retryText}),r.jsx("td",{className:"px-3 py-2 text-white/75",children:r.jsx(Na,{display:d.tokensIn,compact:!0})}),r.jsx("td",{className:"px-3 py-2 text-white/75",children:r.jsx(Na,{display:d.tokensOut,compact:!0})}),r.jsx("td",{className:"px-3 py-2 text-white/75",children:r.jsx(Na,{display:d.cost,compact:!0})}),r.jsx("td",{className:"px-3 py-2 text-white/75",children:r.jsx(Na,{display:d.duration,compact:!0})}),r.jsx("td",{className:"px-3 py-2 text-white/75",children:r.jsx(Na,{display:d.failedCost,compact:!0})}),r.jsx("td",{className:"px-3 py-2 text-white/75",children:r.jsxs("span",{className:"inline-flex flex-wrap items-baseline gap-x-1.5",children:[r.jsx(Na,{display:d.failedTokensIn,compact:!0}),r.jsx("span",{className:"font-ui-display text-xs text-white/40",children:"in"}),r.jsx("span",{className:"font-ui-display text-xs text-white/40",children:"·"}),r.jsx(Na,{display:d.failedTokensOut,compact:!0}),r.jsx("span",{className:"font-ui-display text-xs text-white/40",children:"out"})]})}),r.jsx("td",{className:"px-3 py-2 text-white/75",children:r.jsx(Na,{display:d.failedDuration,compact:!0})})]},d.key))})]})})}const Oj={fromDate:"",toDate:"",repo:"",role:"",runtime:"",model:"",status:""};function Lj({loading:n,error:l,report:s,onRetry:u,cohortLink:d}){const f=(s==null?void 0:s.summary)??null,m=b.useMemo(()=>s?Aj(s.failures):[],[s]),x=b.useMemo(()=>s?s.failures.reduce((y,v)=>y+v.count,0):0,[s]);return r.jsxs("div",{"aria-live":"polite",children:[n&&r.jsx("p",{role:"status",className:"text-sm text-white/50",children:"Loading execution report…"}),!n&&l&&r.jsxs("div",{className:"rounded border border-red-400/30 bg-red-500/10 px-4 py-3",role:"alert",children:[r.jsxs("p",{className:"font-ui-display text-sm text-red-200",children:["Couldn’t load the execution report: ",l]}),r.jsx("button",{type:"button",className:"font-ui-display mt-2 px-3 py-1.5 text-sm rounded border border-red-300/40 text-red-100 hover:bg-red-500/20",onClick:u,children:"Retry"})]}),!n&&!l&&s&&f&&r.jsxs("div",{className:"space-y-6",children:[s.meta.partial&&r.jsxs("div",{className:"rounded border border-amber-300/30 bg-amber-400/10 px-4 py-3",children:[r.jsx("p",{className:"font-ui-display text-sm text-amber-100 font-medium",children:"Partial metadata"}),r.jsx("ul",{className:"font-ui-display mt-1 list-disc list-inside text-sm text-amber-100/80",children:s.meta.partialReasons.map(y=>r.jsx("li",{children:y},y))})]}),f.issues===0?r.jsx("p",{className:"font-ui-display text-sm text-white/45",children:"No issues match these filters in this window. Widen the date range or clear filters."}):r.jsxs(r.Fragment,{children:[r.jsx("section",{"aria-label":"Summary",children:r.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 xl:grid-cols-4 gap-3",children:[r.jsx(Ba,{label:"Issue success",value:r.jsx(ku,{display:Hs(f.issueSuccess,f.closedIssues,"closed")}),valueTitle:`done / (done + closed), denominator ${f.closedIssues}`,note:`${Je(f.issues)} issues · ${Je(f.closedIssues)} closed`}),r.jsx(Ba,{label:"Attempt success",value:r.jsx(ku,{display:Hs(f.attemptSuccess,f.terminalAttempts,"terminal")}),valueTitle:`done sessions / terminal sessions, denominator ${f.terminalAttempts}`,note:`${Je(f.attempts)} attempts · ${Je(f.terminalAttempts)} terminal`}),r.jsx(Ba,{label:"Retry rate",value:pd(f.retryRate),valueTitle:`${f.retryExtraAttempts} extra attempts after a terminal attempt in the same issue/role/round ÷ ${f.attempts} attempts`,note:`Reuse rate ${pd(f.reuseRate)} over ${Je(f.reuseDenominator)} reviewer sessions with input SHA`}),r.jsx(Ba,{label:"Human wait",value:Kt(f.humanWaitMs),note:`${Je(f.interventions)} interventions`}),r.jsx(Ba,{label:"Session wall P50/P95",value:r.jsx(Ms,{display:Ri(f.sessionWallMs,Kt)}),note:"Session bookkeeping proxy — never CLI runtime"}),r.jsx(Ba,{label:"Spawn envelope P50/P95",value:r.jsx(Ms,{display:Ri(f.spawnEnvelopeMs,Kt)}),note:"Coordinator-measured; includes slot wait + post-exit work"}),r.jsx(Ba,{label:"Checkpoint latency P50/P95",value:r.jsx(Ms,{display:Ri(f.checkpointMs,Kt)}),note:"Session start → first heartbeat"}),r.jsx(Ba,{label:"Reviewer rounds (avg)",value:f.avgReviewerRounds===null?"N/A":f.avgReviewerRounds.toFixed(1),note:`Change-request rate ${pd(f.changeRequestRate)} over ${Je(f.reviewedIssues)} reviewed`})]})}),r.jsxs("section",{"aria-label":"Failed-attempt waste",children:[r.jsx("h3",{className:"font-ui-display text-sm font-medium text-white/80 mb-2",children:"Failed-attempt waste (known values only)"}),r.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-3 gap-3",children:[r.jsx(Ba,{label:"Failed cost",value:r.jsx(Na,{display:ja(f.failedCostUsd,Ls)})}),r.jsx(Ba,{label:"Failed tokens",value:r.jsxs("span",{className:"inline-flex flex-wrap items-baseline gap-x-2",children:[r.jsx(Na,{display:ja(f.failedTokensIn,Je,{compact:!0})}),r.jsx("span",{className:"font-ui-display text-xs font-normal text-white/40",children:"in"}),r.jsx("span",{className:"font-ui-display text-xs font-normal text-white/40",children:"·"}),r.jsx(Na,{display:ja(f.failedTokensOut,Je,{compact:!0})}),r.jsx("span",{className:"font-ui-display text-xs font-normal text-white/40",children:"out"})]})}),r.jsx(Ba,{label:"Failed runtime",value:r.jsx(Na,{display:ja(f.failedDurationMs,Kt)})})]})]}),r.jsxs("section",{"aria-label":"Phase wall time",children:[r.jsx("h3",{className:"font-ui-display text-sm font-medium text-white/80 mb-2",children:"Phase wall time"}),r.jsx("p",{className:"font-ui-display text-xs text-white/40 mb-2",children:"Composed from the execution-analysis read model over the same issues: exact when agent start/complete events are recorded, inferred usage-envelope backfill otherwise. Rows without evidence read N/A — never a guess. See per-row reasons."}),r.jsx("div",{className:"rounded border border-white/10 bg-panel-elevated/60 overflow-x-auto",children:r.jsxs("table",{className:"w-full min-w-[560px] text-sm",children:[r.jsx("caption",{className:"sr-only",children:"Exclusive phase wall times. Boundaries without defensible evidence are N/A."}),r.jsx("thead",{children:r.jsxs("tr",{className:"font-ui-display text-left text-xs uppercase tracking-wide text-white/40 border-b border-white/10",children:[r.jsx("th",{scope:"col",className:"px-4 py-2 font-medium",children:"Phase"}),r.jsx("th",{scope:"col",className:"px-3 py-2 font-medium",children:"P50 / P95"}),r.jsx("th",{scope:"col",className:"px-3 py-2 font-medium",children:"Why"})]})}),r.jsx("tbody",{className:"divide-y divide-white/5",children:f.phaseWallMs.map(y=>r.jsxs("tr",{className:"tabular-nums",children:[r.jsx("th",{scope:"row",className:"px-4 py-2 text-left font-mono font-medium text-white/85",children:y.phase}),r.jsx("td",{className:"px-3 py-2 text-white/75",children:r.jsx(Ms,{display:Ri(y.stat,Kt),compact:!0})}),r.jsx("td",{className:"font-ui-display px-3 py-2 text-xs text-white/45",children:y.stat.reasons.join(", ")})]},y.phase))})]})})]}),r.jsxs("section",{"aria-label":"Comparisons",className:"space-y-4",children:[r.jsxs("h3",{className:"font-ui-display text-sm font-medium text-white/80",children:["Comparisons ",r.jsx("span",{className:"font-normal text-white/40",children:"— sorted by name, never by cost"})]}),r.jsx(xd,{caption:"By role",dimension:"role",rows:s.byRole.map(md),cohortLink:d}),r.jsx(xd,{caption:"By runtime",dimension:"runtime",rows:s.byRuntime.map(md),cohortLink:d}),r.jsx(xd,{caption:"By model",dimension:"model",rows:s.byModel.map(md),cohortLink:d})]}),r.jsxs("section",{"aria-label":"Why attempts failed",children:[r.jsx("h3",{className:"font-ui-display text-sm font-medium text-white/80 mb-2",children:"Why attempts failed"}),r.jsxs("p",{className:"font-ui-display text-xs text-white/40 mb-2",children:["Each issue with a failed attempt is counted once using its primary actionable cause, and may later have recovered. Share is over"," ",Je(x)," failed ",x===1?"issue":"issues"," in scope."]}),m.length===0?r.jsx("p",{className:"font-ui-display text-sm text-white/45",children:"No failed attempts in this window."}):r.jsx("div",{className:"rounded border border-white/10 bg-panel-elevated/60 overflow-x-auto",children:r.jsxs("table",{className:"w-full min-w-[560px] text-sm",children:[r.jsx("caption",{className:"sr-only",children:"Why attempts failed: each issue counted once by primary cause. Cause not recorded is its own bucket and is never promoted."}),r.jsx("thead",{children:r.jsxs("tr",{className:"font-ui-display text-left text-xs uppercase tracking-wide text-white/40 border-b border-white/10",children:[r.jsx("th",{scope:"col",className:"px-4 py-2 font-medium",children:"Failure"}),r.jsx("th",{scope:"col",className:"px-3 py-2 font-medium",children:"Domain"}),r.jsx("th",{scope:"col",className:"px-3 py-2 font-medium",children:"Issues"}),r.jsx("th",{scope:"col",className:"px-3 py-2 font-medium",children:"Share"}),r.jsx("th",{scope:"col",className:"px-3 py-2 font-medium",children:"Example issues"})]})}),r.jsx("tbody",{className:"divide-y divide-white/5",children:m.map(y=>r.jsxs("tr",{className:y.isUnknown?"bg-amber-400/5 tabular-nums":"tabular-nums",children:[r.jsxs("th",{scope:"row",className:"px-4 py-2 text-left text-white/85",children:[r.jsx("span",{className:"font-ui-display block font-medium",title:y.code,children:y.displayCode}),r.jsx("span",{className:`font-ui-display block text-xs font-normal ${y.isUnknown?"text-amber-200/90":"text-white/40"}`,children:y.displayNote})]}),r.jsx("td",{className:"px-3 py-2 font-mono text-white/75",children:y.domain}),r.jsx("td",{className:"px-3 py-2 font-mono text-white/75",children:y.countText}),r.jsx("td",{className:"px-3 py-2 font-mono text-white/75",title:y.shareTitle,children:y.shareText}),r.jsx("td",{className:"px-3 py-2",children:r.jsxs("span",{className:"flex flex-wrap gap-x-3 gap-y-1",children:[y.issueIds.map(v=>r.jsx(sa,{to:Ej(v),className:"text-cyber-teal hover:underline font-mono text-xs",children:v.slice(0,8)},v)),y.hiddenIssueCount>0&&r.jsxs("span",{className:"font-ui-display text-xs text-white/40",children:["+",y.hiddenIssueCount," more"]})]})})]},y.code))})]})})]})]})]})]})}function Mj(){const[n,l]=Ny(),s=n.toString(),u=b.useMemo(()=>Cj(s),[s]),[d,f]=b.useState(()=>Zx(s)),[m,x]=b.useState(null),[y,v]=b.useState(!0),[w,j]=b.useState(null),[D,X]=b.useState(0);b.useEffect(()=>{f(Zx(s))},[s]),b.useEffect(()=>{let L=!1;return v(!0),j(null),uS(u).then(H=>{L||(x(H),v(!1))}).catch(H=>{L||(j(H instanceof Error?H.message:String(H)),v(!1))}),()=>{L=!0}},[s,D]);const E=L=>{const H=Fy(Tj(L));l(H?Object.fromEntries(new URLSearchParams(H)):{})},$=L=>f(H=>({...H,...L}));return r.jsxs("div",{className:"flex-1 min-h-0 px-6 py-4 w-full overflow-y-auto",children:[r.jsxs("div",{className:"flex flex-wrap items-baseline justify-between gap-2 mb-1",children:[r.jsx("h2",{className:"font-ui-display text-lg font-semibold text-white/90",children:"Execution report"}),m&&r.jsxs("p",{className:"font-ui-display text-xs text-white/40",children:["Window ",new Date(m.window.from).toLocaleDateString()," –"," ",new Date(m.window.to).toLocaleDateString()," · generated"," ",new Date(m.meta.generatedAt).toLocaleTimeString()]})]}),r.jsx("p",{className:"font-ui-display text-sm text-white/50 mb-4",children:"Reliability, latency, retry waste, and metadata coverage by role, runtime, and model. Missing cost/token data reads as N/A — never as zero."}),r.jsx("form",{"aria-label":"Report filters",className:"mb-4 p-4 rounded border border-white/10 bg-panel-elevated/60",onSubmit:L=>{L.preventDefault(),E(d)},children:r.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-3",children:[r.jsxs("label",{className:"block text-sm",children:[r.jsx("span",{className:"font-ui-display block text-xs text-white/50 mb-1",children:"From"}),r.jsx("input",{type:"date",className:"w-full bg-black/30 border border-white/10 rounded px-3 py-2",value:d.fromDate,onChange:L=>$({fromDate:L.target.value})})]}),r.jsxs("label",{className:"block text-sm",children:[r.jsx("span",{className:"font-ui-display block text-xs text-white/50 mb-1",children:"To"}),r.jsx("input",{type:"date",className:"w-full bg-black/30 border border-white/10 rounded px-3 py-2",value:d.toDate,onChange:L=>$({toDate:L.target.value})})]}),r.jsxs("label",{className:"block text-sm",children:[r.jsx("span",{className:"font-ui-display block text-xs text-white/50 mb-1",children:"Repository"}),r.jsx("input",{type:"text",placeholder:"github.com/owner/repo",className:"w-full bg-black/30 border border-white/10 rounded px-3 py-2",value:d.repo,onChange:L=>$({repo:L.target.value})})]}),r.jsxs("label",{className:"block text-sm",children:[r.jsx("span",{className:"font-ui-display block text-xs text-white/50 mb-1",children:"Role"}),r.jsxs("select",{className:"w-full bg-black/30 border border-white/10 rounded px-3 py-2",value:d.role,onChange:L=>$({role:L.target.value}),children:[r.jsx("option",{value:"",children:"All roles"}),Nj.map(L=>r.jsx("option",{value:L,children:L},L))]})]}),r.jsxs("label",{className:"block text-sm",children:[r.jsx("span",{className:"font-ui-display block text-xs text-white/50 mb-1",children:"Runtime"}),r.jsxs("select",{className:"w-full bg-black/30 border border-white/10 rounded px-3 py-2",value:d.runtime,onChange:L=>{$({runtime:L.target.value})},children:[r.jsx("option",{value:"",children:"All runtimes"}),Hx.map(L=>r.jsx("option",{value:L,children:L},L)),r.jsx("option",{value:"unknown",children:"unknown (missing metadata)"}),d.runtime&&!Hx.includes(d.runtime)&&r.jsxs("option",{value:d.runtime,children:[d.runtime," (from URL)"]})]})]}),r.jsxs("label",{className:"block text-sm",children:[r.jsx("span",{className:"font-ui-display block text-xs text-white/50 mb-1",children:"Model"}),r.jsx("input",{type:"text",placeholder:"Any model",className:"w-full bg-black/30 border border-white/10 rounded px-3 py-2",value:d.model,onChange:L=>$({model:L.target.value})})]}),r.jsxs("label",{className:"block text-sm",children:[r.jsx("span",{className:"font-ui-display block text-xs text-white/50 mb-1",children:"Issue status"}),r.jsxs("select",{className:"w-full bg-black/30 border border-white/10 rounded px-3 py-2",value:d.status,onChange:L=>$({status:L.target.value}),children:[r.jsx("option",{value:"",children:"All statuses"}),_j.map(L=>r.jsx("option",{value:L,children:L},L))]})]}),r.jsxs("div",{className:"flex items-end gap-2",children:[r.jsx("button",{type:"submit",className:"btn-gold px-4",children:"Apply"}),r.jsx("button",{type:"button",className:"font-ui-display px-4 py-2 text-sm text-white/60 hover:text-white",onClick:()=>{f(Oj),l({})},children:"Reset"})]})]})}),r.jsx(Lj,{loading:y,error:w,report:m,onRetry:()=>X(L=>L+1),cohortLink:(L,H)=>Rj(s,L,H)})]})}function Gx(n,l){var d;if(!n)return"Not assigned";const s=l.find(f=>f.id===n);if(!s)return"Unavailable — profile removed";const u=`${s.name} · ${Aa(s.runtime)}`;return s.healthy?u:`${u} (unhealthy: ${((d=s.issues[0])==null?void 0:d.message)??"needs attention"})`}function Qx(n,l){var u;if(!n)return;const s=l.find(d=>d.id===n);return s?`${s.name} · ${Aa(s.runtime)}${s.healthy?" · healthy":` · ${((u=s.issues[0])==null?void 0:u.message)??"unhealthy"}`}`:`Configured profile ${n} is not on record (deleted?)`}function Dj({agents:n,initialRepo:l,initialDeveloperId:s,initialReviewerId:u,busy:d,onSave:f,onCancel:m}){var P,ne;const[x,y]=b.useState(l),[v,w]=b.useState(s??""),[j,D]=b.useState(u??""),X=gv(n),E=n.find(V=>V.id===v),$=n.find(V=>V.id===j),L=Nu(E),H=Nu($),F=x.trim()===l&&v===(s??"")&&j===(u??"");return r.jsxs("div",{className:"p-3 rounded border border-white/10 bg-panel-elevated/60 space-y-2",children:[r.jsx("p",{className:"text-xs text-white/50",children:"Edit configuration — repository, developer, and reviewer save together. Queue position is kept, readiness and the wait reason are rechecked, and the change is recorded on the timeline."}),r.jsxs("label",{className:"block space-y-1",children:[r.jsx("span",{className:"text-xs text-white/45 uppercase tracking-wide",children:"Repository"}),r.jsx("input",{className:"w-full bg-black/30 border border-white/10 rounded px-3 py-2 text-sm",value:x,disabled:d,placeholder:"GitHub URL or owner/repo",title:"GitHub URL or owner/repo — normalized to github.com/owner/repo, same validation as issue creation",onChange:V=>y(V.target.value)})]}),r.jsxs("label",{className:"block space-y-1",children:[r.jsx("span",{className:"text-xs text-white/45 uppercase tracking-wide",children:"Developer"}),r.jsxs("select",{className:"w-full bg-black/30 border border-white/10 rounded px-3 py-2 text-sm",value:v,disabled:d,title:E?`${E.name} · ${Aa(E.runtime)}${E.healthy?" · healthy":` · ${((P=E.issues[0])==null?void 0:P.message)??"unhealthy"}`}`:"Pick a developer agent",onChange:V=>w(V.target.value),children:[r.jsx("option",{value:"",children:"Developer agent…"}),X.map(V=>r.jsx("option",{value:V.id,title:rl(V),children:(V.healthy?"● ":"○ ")+rl(V)},V.id))]}),L&&r.jsx("span",{className:"text-xs text-amber-200/80 block",children:L})]}),r.jsxs("label",{className:"block space-y-1",children:[r.jsx("span",{className:"text-xs text-white/45 uppercase tracking-wide",children:"Reviewer"}),r.jsxs("select",{className:"w-full bg-black/30 border border-white/10 rounded px-3 py-2 text-sm",value:j,disabled:d,title:$?`${$.name} · ${Aa($.runtime)}${$.healthy?" · healthy":` · ${((ne=$.issues[0])==null?void 0:ne.message)??"unhealthy"}`}`:"Pick a reviewer agent",onChange:V=>D(V.target.value),children:[r.jsx("option",{value:"",children:"Reviewer agent…"}),X.map(V=>V.runtime==="muse_code"?r.jsx("option",{value:V.id,disabled:!0,title:"Muse Code cannot be a reviewer (developer role only)",children:`○ ${V.name} · ${Aa(V.runtime)} — reviewer not supported`},V.id):r.jsx("option",{value:V.id,title:rl(V),children:(V.healthy?"● ":"○ ")+rl(V)},V.id))]}),H&&r.jsx("span",{className:"text-xs text-amber-200/80 block",children:H})]}),r.jsxs("div",{className:"flex gap-2",children:[r.jsx("button",{type:"button",className:"btn-gold px-4 py-1.5 text-sm disabled:opacity-50",disabled:d||!x.trim()||!v||!j||F,title:"Save via the issue PATCH contract — keeps queue position, rechecks readiness and the wait reason",onClick:()=>f(x.trim(),v,j),children:"Save configuration"}),r.jsx("button",{type:"button",className:"px-4 py-1.5 text-sm text-white/60 hover:text-white disabled:opacity-50",disabled:d,onClick:m,children:"Cancel"})]})]})}function Uj({issue:n,agents:l,canEdit:s,editing:u,busy:d,onBeginEdit:f,onSave:m,onCancel:x}){return r.jsxs("div",{className:"mb-4 p-3 rounded border border-white/10 bg-white/[0.03] space-y-1.5",children:[r.jsx("p",{className:"text-xs text-white/45 uppercase tracking-wide",children:"Configuration"}),r.jsxs("p",{className:"text-sm text-white/85",title:`Exact repository identity: ${n.repo}`,children:[r.jsx("span",{className:"text-white/45",children:"Repository "}),n.repo]}),r.jsxs("p",{className:"text-sm text-white/85",title:Qx(n.developerAgentId,l),children:[r.jsx("span",{className:"text-white/45",children:"Developer "}),Gx(n.developerAgentId,l)]}),r.jsxs("p",{className:"text-sm text-white/85",title:Qx(n.reviewerAgentId,l),children:[r.jsx("span",{className:"text-white/45",children:"Reviewer "}),Gx(n.reviewerAgentId,l)]}),s&&!u&&r.jsx("button",{type:"button",className:"text-xs text-cyber-teal hover:underline disabled:opacity-50",disabled:d,onClick:f,children:"Edit configuration"}),s&&u&&r.jsx(Dj,{agents:l,initialRepo:n.repo,initialDeveloperId:n.developerAgentId,initialReviewerId:n.reviewerAgentId,busy:d,onSave:m,onCancel:x})]})}function zj({contract:n}){return r.jsxs("section",{"aria-label":"Execution contract",className:"mb-4 p-3 rounded border border-white/10 bg-white/[0.03] space-y-2",children:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("p",{className:"text-xs text-white/45 uppercase tracking-wide",children:"Execution contract"}),r.jsx("span",{className:"text-[11px] px-1.5 py-0.5 rounded border border-cyber-teal/40 text-cyber-teal",children:n.version}),r.jsx("span",{className:"text-[11px] px-1.5 py-0.5 rounded border border-white/15 text-white/70",children:n.executionMode})]}),r.jsxs("div",{className:"text-sm text-white/85 space-y-1.5",children:[r.jsxs("p",{children:[r.jsx("span",{className:"text-white/45",children:"Exit predicate: "}),n.exitPredicate]}),r.jsxs("p",{children:[r.jsx("span",{className:"text-white/45",children:"One-PR stopping point: "}),n.onePrStoppingPoint]}),r.jsxs("div",{children:[r.jsx("p",{className:"text-white/45",children:"Non-goals:"}),r.jsx("ul",{className:"list-disc pl-5 text-white/75",children:n.nonGoals.map(l=>r.jsx("li",{children:l},l))})]}),r.jsxs("div",{children:[r.jsx("p",{className:"text-white/45",children:"Acceptance criteria:"}),r.jsx("ul",{className:"space-y-1",children:n.acceptanceCriteria.map(l=>r.jsxs("li",{children:[r.jsxs("p",{className:"text-white/80",children:["☐ ",l.text]}),l.evidence&&r.jsxs("p",{className:"pl-5 text-xs text-white/55",children:["Evidence: ",l.evidence]})]},l.text))})]})]}),r.jsx("p",{className:"text-[11px] text-white/35",children:"Compiled from the ticket description — edit the description to change it."})]})}function Bj(n){return n===void 0?"unknown size":`${n.toLocaleString("en-US")} bytes`}function qj({attachments:n}){if(!(n!=null&&n.length))return null;const l=n.filter(u=>u.kind==="file"),s=n.filter(u=>u.kind==="link");return r.jsxs("div",{className:"mb-4 p-3 rounded border border-white/10 bg-white/[0.03] space-y-1","data-testid":"source-attachments",children:[r.jsx("p",{className:"text-xs text-white/45 font-medium uppercase tracking-wide",children:"Source attachments"}),l.map(u=>r.jsxs("p",{className:"text-sm text-white/85","data-testid":"source-attachment-file",children:[r.jsx("span",{className:"text-cyber-teal",children:"file"})," ",u.safeFileName??u.title,r.jsxs("span",{className:"text-white/45",children:[" ","· ",Bj(u.sizeBytes),u.sha256?` · sha256:${u.sha256.slice(0,16)}…`:"",u.contentType?` · ${u.contentType}`:""]})]},u.linearAttachmentId)),s.map(u=>r.jsxs("p",{className:"text-sm text-white/85","data-testid":"source-attachment-link",children:[r.jsx("span",{className:"text-amber-300",children:"link"})," ",u.title,r.jsxs("span",{className:"text-white/45",children:[" ","· ",u.url,u.subtitle?` · ${u.subtitle}`:""]})]},u.linearAttachmentId)),r.jsx("p",{className:"text-xs text-white/40",children:"Files are Dealer-stored snapshots — the Builder reads local bytes, never the expiring Linear URL. Links are metadata only, never downloaded. Files uploaded only inside Linear comments are not imported."})]})}function su(n){return n==="developer"?"Developer":n==="reviewer"?"Reviewer":"Worker"}const yd={"issue.created":()=>"Issue created","issue.reassigned":()=>"Configuration updated","issue.source_reloaded":()=>"Task text reloaded from Linear","workflow.started":()=>"Workflow started","worker.started":n=>`${su(n.actorType)} started${n.round?` (round ${n.round})`:""}`,"worker.completed":n=>`${su(n.actorType)} finished${n.round?` (round ${n.round})`:""}`,"worker.failed":n=>`${su(n.actorType)} failed${n.round?` (round ${n.round})`:""}`,"worker.deferred":n=>{var l;return((l=Ti(n.payloadJson))==null?void 0:l.outcome)==="deck_unavailable"?`Waiting for Agent Deck${n.round?` (round ${n.round})`:""}`:`${su(n.actorType)} deferred${n.round?` (round ${n.round})`:""}`},"worktree.ready":()=>"Worktree ready","worktree.deps_ready":()=>"Dependencies ready","deck.connected":()=>"Deck connected","brief.resolved":()=>"Brief resolved","base.probe":n=>{var s;const l=(s=Ti(n.payloadJson))==null?void 0:s.result;return l==="conflict"?"Base conflict found before publish":l==="skipped"?"Base conflict probe skipped":l==="deferred"?"Base conflict probe waiting on base fetch":l==="failed"?"Base conflict probe failed; not published":"Base conflict probe clean"},"branch.pushed":()=>"Branch pushed","checks.started":()=>"Checks started","pull_request.opened":()=>"Developer opened the PR","pull_request.updated":()=>"Developer updated the PR","checks.completed":()=>"Checks completed","review.submitted":()=>"Reviewer submitted a review","repair.started":n=>`Repair round ${n.round??"?"} started`,"guidance.added":()=>"Guidance added","task_snapshot.refreshed":()=>"Task snapshot refreshed","human_action.requested":()=>"Human action requested","human_action.resolved":()=>"Human action resolved","final_review.requested":()=>"Final review requested","issue.completed":()=>"Issue completed","issue.closed":()=>"Issue closed"};function Ti(n){if(!n)return null;try{return JSON.parse(n)}catch{return null}}const Hj={approved:"text-cyber-teal",changes_requested:"text-amber-300",escalated:"text-red-300"};function $j({e:n}){var l;if(n.type==="pull_request.opened"||n.type==="pull_request.updated"){const s=Ti(n.payloadJson);return n.artifactRef?r.jsxs("a",{href:n.artifactRef,target:"_blank",rel:"noreferrer",className:"text-sm text-cyber-teal hover:underline",children:["PR ",s!=null&&s.prNumber?`#${s.prNumber}`:""," ",s!=null&&s.branch?`(${s.branch})`:""]}):null}if(n.type==="review.submitted"){const s=Ti(n.payloadJson);return s?r.jsxs("span",{className:"text-sm",children:[r.jsx("span",{className:Hj[s.verdict]??"text-white/70",children:s.verdict.replace("_"," ")}),(l=s.findings)!=null&&l.length?` · ${s.findings.length} finding(s)`:""]}):null}if(n.type==="guidance.added"){const s=Ti(n.payloadJson);return s!=null&&s.markdown?r.jsxs("span",{className:"text-sm text-white/55 italic",children:["— ",s.markdown]}):null}if(n.type==="worker.started"||n.type==="worker.completed"||n.type==="worker.failed"||n.type==="worker.deferred"||n.type==="worktree.ready"||n.type==="deck.connected"||n.type==="brief.resolved"||n.type==="branch.pushed"||n.type==="checks.started"||n.type==="checks.completed"){const s=Ti(n.payloadJson);if(!s)return null;const u=[];return s.runtime&&u.push(s.runtime),s.model&&u.push(s.model),s.sessionId&&u.push(s.sessionId.slice(0,8)),s.worktreePath&&u.push(s.worktreePath),s.resolution&&u.push(s.resolution),s.branch&&u.push(s.branch),s.commitsAhead!=null&&u.push(`${s.commitsAhead} ahead`),s.snapshot&&u.push(s.snapshot),(n.type==="worker.deferred"||n.type==="worker.failed")&&(s.reason&&u.push(s.reason),n.type==="worker.deferred"&&s.until&&u.push(`until ${new Date(s.until).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"})}`)),u.length===0?null:r.jsxs("span",{className:"text-xs text-white/40",children:["· ",u.join(" · ")]})}return null}function Yj(n){var l;return((l=yd[n.type])==null?void 0:l.call(yd,n))??n.type}const Xx={human:"You",system:"System",developer:"Developer",reviewer:"Reviewer"},Vj={human:"bg-cyber-teal/15 text-cyber-teal",system:"bg-white/10 text-white/50",developer:"bg-cyber-violet/20 text-cyber-violet-light",reviewer:"bg-[#C4B643]/25 text-[#E8DC7A]"};function Zj(n){return n.actorRef?`${Xx[n.actorType]} · ${n.actorRef}`:Xx[n.actorType]}function Gj({events:n}){return n.length===0?r.jsx("p",{className:"text-white/40 text-sm",children:"No activity yet."}):r.jsx("div",{className:"space-y-1",children:n.map(l=>r.jsxs("div",{className:"flex items-baseline gap-3 py-1.5 border-b border-white/5 last:border-0",children:[r.jsx("span",{className:"text-xs text-white/35 w-20 shrink-0 tabular-nums",children:new Date(l.ts).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"})}),r.jsx("span",{className:`text-[11px] leading-none px-1.5 py-0.5 rounded shrink-0 ${Vj[l.actorType]}`,children:Zj(l)}),r.jsx("span",{className:"text-sm text-white/80",children:Yj(l)}),r.jsx($j,{e:l})]},l.id))})}function qa(n){if(n==null||!Number.isFinite(n))return null;if(n<1e3)return"<1s";const l=Math.round(n/1e3);if(l<60)return`${l}s`;const s=Math.floor(l/60);if(s<60){const f=l%60;return f===0?`${s}m`:`${s}m ${f}s`}const u=Math.floor(s/60),d=s%60;return d===0?`${u}h`:`${u}h ${d}m`}function Ix(n){return n==null||!Number.isFinite(n)?null:`${Math.round(n).toLocaleString("en-US")} tokens`}function Qj(n){return n==null||!Number.isFinite(n)?null:`$${n.toFixed(2)}`}const Xj={queue_wait:"Queue / admission wait",coordinator_setup:"Setup",agent_process:"Agent process",coordinator_validation_publish:"Validation / publish",coordinator_work:"Coordinator work"},Kx={model_provider_wait:"Silent · waiting on model provider",tool_or_subprocess_in_flight:"Silent · tool/subprocess in flight",host_suspended:"Silent · host suspended",no_structured_output:"Silent · no structured output yet",unknown:"Silent · unknown cause"},zd={worktree:"worktree",commit:"commit",verification_receipt:"verification receipt",publish_only:"publish-only result"},Ij=new Set(["failed","timed_out","error"]);function sf(n){return n.replace(/_/g," ")}function $s(n,l){const s=`Evidence quality: ${n}`;return l.length>0?`${s} — ${l.join(", ")}`:s}function _a({quality:n,reasons:l}){return r.jsxs("span",{className:`text-[11px] tabular-nums ${n==="exact"?"text-white/60":n==="inferred"?"text-amber-300/90":"text-white/60 italic"}`,title:$s(n,l),children:["· ",n,l.length>0&&r.jsxs("span",{className:"sr-only",children:[" (",l.join(", "),")"]})]})}function sl({reasons:n}){const l=n.length>0?n.join(", "):"no reason recorded";return r.jsxs("span",{className:"text-white/45 italic",title:`Unavailable — ${l}`,children:["Unavailable",r.jsxs("span",{className:"text-[11px]",children:[" — ",l]})]})}function ru({covered:n,format:l,unit:s}){if(n.value==null)return r.jsx(sl,{reasons:n.reasons});const u=n.known<n.total;return r.jsxs("span",{title:`${$s(n.quality,n.reasons)} · known ${n.known} of ${n.total} ${s}`,children:[l(n.value),r.jsx(_a,{quality:n.quality,reasons:n.reasons}),u&&r.jsxs("span",{className:"text-[11px] text-white/60",title:`Known for ${n.known} of ${n.total} ${s}`,children:[" ","(known ",n.known," of ",n.total,")"]})]})}function Jx({cause:n,primary:l}){return r.jsxs("div",{className:l?"p-2.5 rounded border border-red-400/30 bg-red-500/10 space-y-1":"p-2 rounded border border-white/10 bg-white/[0.02] space-y-1",children:[r.jsxs("p",{className:l?"text-sm font-medium text-red-200":"text-xs text-white/60",children:[l?"First failure: ":"Consequence: ",sf(n.code)]}),r.jsx("p",{className:l?"text-sm text-white/85 whitespace-pre-wrap break-words":"text-xs text-white/55 whitespace-pre-wrap break-words",children:n.rawReason}),r.jsxs("p",{className:"text-[11px] text-white/60",title:$s(n.quality==="exact"?"exact":"inferred",[`evidence: ${n.evidenceSource}`,`confidence: ${n.confidence}`]),children:[n.domain," · ",n.confidence," confidence · via ",n.evidenceSource.replace(/_/g," ")," · ",n.quality,n.occurredAt?` · ${new Date(n.occurredAt).toLocaleString()}`:""]})]})}function Kj({interval:n}){const l=Kx[n.category??"unknown"]??Kx.unknown,s=qa(n.durationMs),u=n.category==="host_suspended";return r.jsxs("li",{className:`flex flex-wrap items-baseline gap-x-2 gap-y-0.5 py-1 border-b border-white/5 last:border-0 ${u?"text-amber-200/90":"text-white/70"}`,children:[r.jsx("span",{className:`text-xs px-1.5 py-0.5 rounded border shrink-0 ${u?"border-amber-400/40 bg-amber-500/10":"border-white/15 bg-white/5"}`,title:u?"Overlapping durable host-sleep evidence split this gap — the host was suspended, not the agent.":"Observational gap with no new structured activity — not a diagnosis of what the agent was doing.",children:l}),r.jsx("span",{className:"text-xs tabular-nums",children:s??r.jsx(sl,{reasons:n.reasons})}),r.jsx(_a,{quality:n.quality,reasons:n.reasons})]})}function Jj({attempt:n}){const l=n.reuseKinds;return l===void 0?r.jsx("span",{className:"ml-2 text-[11px] px-1.5 py-0.5 rounded border border-white/15 bg-white/5 text-white/60 italic",title:"Reuse unknown for this retry — no reuse evidence recorded.",children:"reuse unknown"}):l.length===0?r.jsx("span",{className:"ml-2 text-[11px] px-1.5 py-0.5 rounded border border-white/15 bg-white/5 text-white/60",title:"Cold retry — no prior worktree, commit, or verification was reused.",children:"cold retry"}):r.jsx(r.Fragment,{children:l.map(s=>r.jsxs("span",{className:"ml-2 text-[11px] px-1.5 py-0.5 rounded border border-cyber-teal/40 bg-cyber-teal/10 text-cyber-teal",title:`This retry preserved the prior ${zd[s]??s} instead of starting cold.`,children:["reused ",zd[s]??s]},s))})}function Fj({attempt:n,isRetry:l}){const s=qa(n.setup.durationMs),u=qa(n.agentProcess.durationMs),d=qa(n.validationPublish.durationMs),f=l&&n.role==="developer";return r.jsxs("li",{className:"py-1.5 border-b border-white/5 last:border-0 space-y-0.5",children:[r.jsxs("p",{className:"text-sm text-white/85",children:[r.jsx("span",{className:"capitalize",children:n.role}),r.jsxs("span",{className:"text-white/45",children:[n.runtime?` · ${n.runtime}`:"",n.model?` · ${n.model}`:"",` · round ${n.round} · ${n.status}`]}),n.publishOnly&&r.jsx("span",{className:"ml-2 text-[11px] px-1.5 py-0.5 rounded border border-cyber-violet/40 bg-cyber-violet/10 text-cyber-violet-light",title:"Publish-only attempt: no agent process ran — the coordinator published prior work.",children:"publish-only"}),f&&!n.publishOnly&&r.jsx(Jj,{attempt:n})]}),r.jsxs("p",{className:"text-xs text-white/50 tabular-nums",children:[r.jsxs("span",{title:s?void 0:`Setup unavailable — ${n.setup.reasons.join(", ")||"no reason recorded"}`,children:["Setup ",s??r.jsxs("span",{className:"italic",children:["Unavailable — ",n.setup.reasons.join(", ")||"no reason recorded"]})]}),r.jsx(_a,{quality:n.setup.quality,reasons:n.setup.reasons})," · ",r.jsxs("span",{title:u?void 0:`Agent process unavailable — ${n.agentProcess.reasons.join(", ")||"no reason recorded"}`,children:["Agent ",u??r.jsxs("span",{className:"italic",children:["Unavailable — ",n.agentProcess.reasons.join(", ")||"no reason recorded"]})]}),r.jsx(_a,{quality:n.agentProcess.quality,reasons:n.agentProcess.reasons})," · ",r.jsxs("span",{title:d?void 0:`Validation/publish unavailable — ${n.validationPublish.reasons.join(", ")||"no reason recorded"}`,children:["Validation/publish ",d??r.jsxs("span",{className:"italic",children:["Unavailable — ",n.validationPublish.reasons.join(", ")||"no reason recorded"]})]}),r.jsx(_a,{quality:n.validationPublish.quality,reasons:n.validationPublish.reasons})]}),n.failureCauses.length>0&&r.jsxs("p",{className:"text-[11px] text-white/60",children:["Failures: ",n.failureCauses.map(m=>sf(m.code)).join(", ")]})]})}function Wj({analysis:n}){const l=qa(n.elapsed.durationMs),s=qa(n.exclusiveTotalMs),u=qa(n.firstCheckpoint.msSinceWorkflowStart),d=n.nested.filter(E=>E.kind!=="unexplained_silence"),f=n.attempts.flatMap(E=>E.silence),m=n.attempts.length>0&&n.attempts.every(E=>E.silence.length===0&&E.silenceQuality==="unavailable"),x=n.attempts.filter(E=>E.silence.length===0&&E.silenceQuality==="unavailable"),y=n.waste.failedAttempts>0||n.waste.publishOnlyAttempts>0||n.attempts.some(E=>E.failureCauses.length>0||Ij.has(E.status)),v=qa(n.humanWaitMs),w=n.retry.reuseRate==null?null:`${Math.round(n.retry.reuseRate*100)}% reused`,D=(n.retry.preservedKinds??[]).map(E=>zd[E]??E),X=n.waste.failedAttempts>0||n.waste.publishOnlyAttempts>0;return r.jsxs("div",{className:"space-y-3",children:[r.jsxs("div",{children:[r.jsxs("p",{className:"text-sm text-white/85 tabular-nums",children:["Elapsed ",l??r.jsx(sl,{reasons:n.elapsed.reasons}),r.jsx(_a,{quality:n.elapsed.quality,reasons:n.elapsed.reasons})]}),r.jsxs("p",{className:"text-xs text-white/45 tabular-nums",title:"Unioned top-level phases with overlaps removed (human wait excluded). Nested waits below explain phases — they are never added to this total.",children:["Exclusive phase total ",s??r.jsx(sl,{reasons:n.exclusiveTotalReasons}),r.jsx(_a,{quality:n.exclusiveTotalQuality,reasons:n.exclusiveTotalReasons}),r.jsx("span",{children:" · overlaps unioned, not summed"})]})]}),r.jsxs("div",{children:[r.jsx("h4",{className:"text-xs text-white/45 uppercase tracking-wide mb-1",children:"Phase breakdown"}),r.jsx("ul",{children:n.unionedDurations.map(E=>{const $=qa(E.durationMs);return r.jsxs("li",{className:"flex flex-wrap items-baseline gap-x-2 py-0.5 text-sm",children:[r.jsx("span",{className:"text-white/70 w-36 shrink-0",children:Xj[E.phase]??E.phase}),r.jsx("span",{className:"text-white/85 tabular-nums",children:$??r.jsx(sl,{reasons:E.reasons})}),r.jsx(_a,{quality:E.quality,reasons:E.reasons}),E.known<E.total&&r.jsxs("span",{className:"text-[11px] text-white/60",children:["(known ",E.known," of ",E.total,")"]})]},E.phase)})}),r.jsxs("p",{className:"text-xs text-white/45 tabular-nums mt-1",children:["Human wait ",v??r.jsx(sl,{reasons:n.humanWaitReasons}),r.jsx(_a,{quality:n.humanWaitQuality,reasons:n.humanWaitReasons}),r.jsx("span",{title:"Human wait is tracked separately — it never adds to the phase total.",children:" · never additive"})]}),d.length>0&&r.jsx("ul",{className:"mt-1",children:d.map((E,$)=>r.jsxs("li",{className:"text-xs text-white/50 tabular-nums",children:[r.jsxs("span",{title:"Nested drill-down: explains its parent phase, never adds to the total.",children:["↳ ",E.kind==="human_wait"?"Human wait":E.category??E.kind]})," ",qa(E.durationMs)??r.jsx(sl,{reasons:E.reasons}),r.jsx(_a,{quality:E.quality,reasons:E.reasons})]},$))})]}),r.jsxs("div",{children:[r.jsxs("h4",{className:"text-xs text-white/45 uppercase tracking-wide mb-1",children:["Attempts (",n.attempts.length,")"]}),n.attempts.length===0?r.jsx("p",{className:"text-xs text-white/45 italic",children:"No attempts recorded yet."}):r.jsx("ul",{children:n.attempts.map((E,$)=>r.jsx(Fj,{attempt:E,isRetry:$>0},E.sessionId))})]}),r.jsxs("div",{children:[r.jsx("h4",{className:"text-xs text-white/45 uppercase tracking-wide mb-1",children:"Failure"}),n.primaryFailure?r.jsxs("div",{className:"space-y-1.5",children:[r.jsx(Jx,{cause:n.primaryFailure,primary:!0}),n.consequenceCauses.length>0&&r.jsx("div",{className:"space-y-1 opacity-80",children:n.consequenceCauses.map((E,$)=>r.jsx(Jx,{cause:E,primary:!1},`${E.code}-${$}`))})]}):y?r.jsxs("p",{className:"text-sm text-white/60 italic",title:$s("unavailable",n.primaryFailureReasons),children:["Unknown — ",n.primaryFailureReasons.join(", ")||"no failure evidence recorded"]}):r.jsx("p",{className:"text-sm text-white/45",children:"No failure recorded."})]}),r.jsxs("div",{children:[r.jsxs("h4",{className:"text-xs text-white/45 uppercase tracking-wide mb-1",children:["Retry waste (",n.waste.failedAttempts," failed attempt",n.waste.failedAttempts===1?"":"s",")"]}),X?r.jsxs("p",{className:"text-sm text-white/85 flex flex-wrap gap-x-3 gap-y-0.5 tabular-nums",children:[r.jsxs("span",{title:"Failed-attempt agent-process time over known values only",children:["Runtime ",r.jsx(ru,{covered:n.waste.runtimeMs,format:E=>qa(Math.round(E))??"?",unit:"attempts"})]}),r.jsxs("span",{title:"Failed-attempt input tokens over known values only",children:["In ",r.jsx(ru,{covered:n.waste.tokensIn,format:E=>Ix(E)??"?",unit:"attempts"})]}),r.jsxs("span",{title:"Failed-attempt output tokens over known values only",children:["Out ",r.jsx(ru,{covered:n.waste.tokensOut,format:E=>Ix(E)??"?",unit:"attempts"})]}),r.jsxs("span",{title:"Failed-attempt known cost over known values only",children:["Cost ",r.jsx(ru,{covered:n.waste.costUsd,format:E=>Qj(E)??"?",unit:"attempts"})]})]}):r.jsx("p",{className:"text-sm text-white/45",children:"No failed attempts — no retry waste."})]}),r.jsxs("div",{children:[r.jsx("h4",{className:"text-xs text-white/45 uppercase tracking-wide mb-1",children:"First checkpoint"}),n.firstCheckpoint.msSinceWorkflowStart==null&&n.firstCheckpoint.kind==null?r.jsxs("p",{className:"text-sm text-white/60 italic",title:$s(n.firstCheckpoint.quality,n.firstCheckpoint.reasons),children:["Unavailable — ",n.firstCheckpoint.reasons.join(", ")||"no checkpoint recorded"]}):r.jsxs("p",{className:"text-sm text-white/85 tabular-nums",children:[n.firstCheckpoint.kind?sf(n.firstCheckpoint.kind):"Checkpoint",n.firstCheckpoint.observedSha?` · ${n.firstCheckpoint.observedSha.slice(0,12)}`:"",u?` · ${u} after workflow start`:"",r.jsx(_a,{quality:n.firstCheckpoint.quality,reasons:n.firstCheckpoint.reasons})]})]}),r.jsxs("div",{children:[r.jsx("h4",{className:"text-xs text-white/45 uppercase tracking-wide mb-1",children:"Retry reuse"}),r.jsxs("div",{className:"flex flex-wrap gap-1.5",role:"group","aria-label":"Retry reuse summary",children:[r.jsxs("span",{className:"text-[11px] px-1.5 py-0.5 rounded border border-cyber-teal/40 bg-cyber-teal/10 text-cyber-teal",title:"Retries that preserved prior work — a reused worktree, commit, or verification receipt.",children:["Reused ",n.retry.reused]}),r.jsxs("span",{className:"text-[11px] px-1.5 py-0.5 rounded border border-white/15 bg-white/5 text-white/60",title:"Retries that started cold — no prior worktree, commit, or verification was reused.",children:["Cold ",n.retry.cold]}),n.retry.unknown>0&&r.jsxs("span",{className:"text-[11px] px-1.5 py-0.5 rounded border border-white/15 bg-white/5 text-white/60 italic",title:`Unknown reuse for ${n.retry.unknown} retr${n.retry.unknown===1?"y":"ies"} — ${n.retry.reasons.join(", ")||"no reuse evidence"}.`,children:["Unknown ",n.retry.unknown]}),n.retry.publishOnly>0&&r.jsxs("span",{className:"text-[11px] px-1.5 py-0.5 rounded border border-cyber-violet/40 bg-cyber-violet/10 text-cyber-violet-light",title:"Publish-only retries ran no agent process — the coordinator published already-verified work.",children:["Publish-only ",n.retry.publishOnly]}),r.jsxs("span",{className:"text-[11px] text-white/60 tabular-nums self-center",children:[n.retry.retries===0?"No retries":w??r.jsx(sl,{reasons:n.retry.reasons}),r.jsx(_a,{quality:n.retry.quality,reasons:n.retry.reasons})]})]}),r.jsx("p",{className:"text-[11px] text-white/60 mt-0.5",children:n.retry.retries===0?"No retries — nothing to preserve.":D.length>0?`Preserved: ${D.join(", ")}.`:n.retry.unknown>0?`Preservation unknown for ${n.retry.unknown} retr${n.retry.unknown===1?"y":"ies"} — no reuse evidence.`:"No prior work preserved — every retry started cold."})]}),r.jsxs("div",{children:[r.jsx("h4",{className:"text-xs text-white/45 uppercase tracking-wide mb-1",children:"Silence"}),r.jsx("p",{className:"text-[11px] text-white/60 mb-1",children:"Silence is observational — gaps with no new structured activity. It describes what was observed, never a diagnosis."}),f.length===0?m?r.jsx("p",{className:"text-sm text-white/60 italic",children:"Unknown — silence cannot be derived without agent-process bounds."}):r.jsx("p",{className:"text-sm text-white/45",children:"No silence observed."}):r.jsxs(r.Fragment,{children:[r.jsx("ul",{"aria-label":"Observed silence intervals",children:f.map((E,$)=>r.jsx(Kj,{interval:E},$))}),x.length>0&&r.jsx("ul",{"aria-label":"Attempts with unknown silence",className:"mt-1",children:x.map(E=>r.jsxs("li",{className:"text-[11px] text-white/60 italic py-0.5",children:["Silence unknown for attempt ",E.sessionId.length>12?`${E.sessionId.slice(0,8)}…`:E.sessionId," —"," ",E.silenceReasons.join(", ")||"no silence evidence recorded"]},E.sessionId))})]})]})]})}function Pj({issueId:n}){const[l,s]=b.useState(null),[u,d]=b.useState(null),[f,m]=b.useState(!0);return b.useEffect(()=>{s(null),d(null),m(!0);let x=!1;return K2(n).then(y=>{x||(s(y),m(!1))}).catch(y=>{x||(/not found/i.test(String(y))?(s(null),d(null)):d(String(y).replace(/^Error:\s*/i,"")),m(!1))}),()=>{x=!0}},[n]),r.jsxs("section",{"aria-labelledby":"execution-analysis-heading",className:"mb-4 p-3 rounded border border-white/10 bg-white/[0.03]",children:[r.jsx("h3",{id:"execution-analysis-heading",className:"font-ui-display text-sm font-medium text-white/85 mb-2",children:"Execution analysis"}),f&&r.jsx("p",{className:"text-xs text-white/40",children:"Loading execution analysis…"}),!f&&u&&r.jsx("p",{className:"text-xs text-red-300",children:u}),!f&&!u&&!l&&r.jsx("p",{className:"text-xs text-white/45",children:"No execution analysis yet — start the workflow to see where time goes."}),!f&&!u&&l&&r.jsx(Wj,{analysis:l})]})}const eN="web";function tN(n){try{const l=JSON.parse(n);return typeof l.text=="string"?l.text:JSON.stringify(l,null,2)}catch{return n}}function vd(n){const l=Math.floor(n/6e4);return l<60?`${l}m`:`${Math.floor(l/60)}h ${l%60}m`}function aN(n){if(!n)return"no heartbeat yet";const l=Math.max(0,Math.floor((Date.now()-new Date(n).getTime())/1e3));return l<5?"just now":l<60?`${l}s ago`:`${Math.floor(l/60)}m ago`}function Ds(n){if(!n)return null;const l=n.split(/[/\\]/).filter(Boolean);return l.length<=2?n:l.slice(-2).join("/")}function gd(n){var l;return[n.branch,n.tipLabel,(l=n.worktree)!=null&&l.path?Ds(n.worktree.path):null].filter(Boolean).join(" · ")}function bd(n){var l;return[n.restartRisk?"restart risk":null,(l=n.worktree)!=null&&l.preserved?"dirty worktree preserved":null].filter(Boolean).map(s=>` · ${s}`).join("")}function wd(n){var l;return!!(n.restartRisk||(l=n.worktree)!=null&&l.preserved)}function nN(n,l){return!n||!l?!1:n===l?!0:n.includes(l)}function lN({busy:n,onConfirm:l,onCancel:s}){return r.jsxs("div",{className:"mt-2 p-3 rounded border border-red-400/30 bg-red-500/10 space-y-2",children:[r.jsx("p",{className:"text-sm text-white/90 font-medium",children:"Close this issue?"}),r.jsx("p",{className:"text-sm text-white/70",children:"It will not execute. Any queue entry will be removed. History is retained and can be found as closed work — filter the Issues list by status closed or open this page directly."}),r.jsxs("div",{className:"flex gap-2",children:[r.jsx("button",{type:"button",className:"px-4 py-1.5 text-sm rounded border border-red-400/50 text-red-200 hover:bg-red-500/20 disabled:opacity-50",disabled:n,onClick:l,children:"Close issue"}),r.jsx("button",{type:"button",className:"font-ui-display px-4 py-1.5 text-sm text-white/60 hover:text-white",onClick:s,children:"Keep issue"})]})]})}function iN(n){return n.externalLabel??n.id}function sN(n,l){return n===l}function rN({expectedToken:n,externalLabel:l,busy:s,onConfirm:u,onCancel:d}){const[f,m]=b.useState(""),x=sN(f,n);return r.jsxs("div",{className:"mt-2 p-3 rounded border border-red-400/30 bg-red-500/10 space-y-2",children:[r.jsx("p",{className:"text-sm text-white/90 font-medium",children:"Delete this issue from Dealer?"}),r.jsxs("p",{className:"text-sm text-white/70",children:["This permanently deletes the Dealer-local issue — its history, evidence, and files cannot be recovered.",l?` The Linear ticket ${l} will not be deleted.`:" There is no linked Linear ticket to affect."]}),r.jsxs("label",{className:"block text-xs text-white/60",children:["Type ",r.jsx("span",{className:"font-mono text-white/85",children:n})," to confirm",r.jsx("input",{className:"mt-1 block w-full bg-black/30 border border-white/10 rounded px-3 py-1.5 text-sm text-white/90 font-mono",value:f,onChange:y=>m(y.target.value),placeholder:n,autoComplete:"off"})]}),r.jsxs("div",{className:"flex gap-2",children:[r.jsx("button",{type:"button",className:"px-4 py-1.5 text-sm rounded border border-red-400/50 text-red-200 hover:bg-red-500/20 disabled:opacity-50",disabled:s||!x,onClick:u,children:"Delete from Dealer"}),r.jsx("button",{type:"button",className:"font-ui-display px-4 py-1.5 text-sm text-white/60 hover:text-white",onClick:d,children:"Keep issue"})]})]})}function uN(n){const l=n.externalLabel??n.issueId,s=n.residualPaths.length>0?` ${n.residualPaths.length} Dealer-owned file(s) could not be removed: ${n.residualPaths.join(", ")}`:"";return n.externalLabel?`Issue ${l} deleted from Dealer. The Linear ticket was not deleted.${s}`:`Issue ${l} permanently deleted from Dealer.${s}`}async function oN(n,l,s){try{const u=await s.removeIssue(n),d=uN({issueId:n,externalLabel:l.externalLabel,residualPaths:u.residualPaths});return s.closeConfirmation(),s.onHumanActionsChanged(),s.navigateToIssues(d),"deleted"}catch(u){return s.closeConfirmation(),s.reportError(u),s.refresh(),"refused"}}const cN="Agents updated. Resume to continue with the new agents.";function dN(n,l,s,u){const d={};return s!==(n??"")&&(d.developerAgentId=s),u!==(l??"")&&(d.reviewerAgentId=u),d}function fN(n){const l=n.humanActions.find(s=>s.status==="open");if(l)return Zy(l).title;switch(n.issue.currentOwner){case"developer":return"Waiting on the developer";case"reviewer":return"Waiting on the reviewer";case"human":return"Waiting on you";default:return n.issue.status==="done"||n.issue.status==="closed"?"Complete":"Idle"}}function hN({issueId:n,detail:l,agents:s,onHumanActionsChanged:u,refresh:d,onError:f}){var Ma;const[m,x]=b.useState(null),[y,v]=b.useState({}),[w,j]=b.useState(""),[D,X]=b.useState(!1),[E,$]=b.useState(""),[L,H]=b.useState(""),[F,P]=b.useState(""),[ne,V]=b.useState(!1),[Ne,I]=b.useState(null),[ye,Me]=b.useState(!1),[bt,At]=b.useState(null),[rt,yt]=b.useState(!1),[lt,Qe]=b.useState(!1),U=Ru(),[J,re]=b.useState(!1),[Ae,Le]=b.useState(null),[N,Y]=b.useState({}),[W,te]=b.useState({}),se=G=>f(String(G)),{issue:B,timeline:ce,humanActions:Xe,usageSummary:De,readiness:Bt,humanWaitMs:Ta,interventionCount:ua,latestWorkflowInstance:Va,activeWorkerSession:qe,liveProgress:Za,latestSessionFailure:dt,branchTipStatus:wt,queued:Rn,queueEntry:Ye,capWait:Ga}=l,oa=s.find(G=>G.id===B.developerAgentId),tn=oa&&!oa.healthy,ol=((Ma=oa==null?void 0:oa.issues[0])==null?void 0:Ma.message)??"Developer agent is unhealthy",ut=Va?new Date(Va.completedAt??Date.now()).getTime()-new Date(Va.startedAt).getTime():0,ca=Xe.filter(G=>G.status==="open"),Ue=B.status==="needs_human"&&ca.some(G=>G.actionType==="attempts_exhausted"||G.actionType==="policy_escalation"),cl=Bt.ok===!1||ca.some(G=>G.actionType==="product_scope_decision"),qt=Va!=null&&Va.completedAt===null,$l=B.status==="ready"&&!qt,dl=cl||$l,Yl=(qe==null?void 0:qe.status)==="running",fl=B.source==="linear"&&B.status==="ready"&&!qt&&!Yl,Oa=B.status==="ready"&&!qt,tt=(B.status==="ready"||B.status==="done"||B.status==="closed")&&!qt,Ut=B.status==="ready"&&!qt,ft=qe&&qe.status==="running"&&(B.status==="developing"||B.status==="reviewing"||B.status==="repairing"),Ft=!!dt&&!ft,at=async()=>{w.trim()&&(await rS(n,w),j(""),d())},Vl=()=>{$(B.title),H(B.description??""),P(B.acceptanceCriteria??""),X(!0)},an=async()=>{V(!0),f(null);try{await fu(n,{title:E.trim()||void 0,description:L.trim()||null,acceptanceCriteria:F.trim()||null}),X(!1),d()}catch(G){se(G)}finally{V(!1)}},nn=async()=>{V(!0),f(null);try{await P2(n),re(!1),d()}catch(G){re(!1),se(G),d()}finally{V(!1)}},Qa=async()=>{V(!0),f(null);try{const G=await iv(n);I(G.state==="admitted"?null:`Queued at position ${G.position}${G.waitReason?` — ${G.waitReason}`:""}`),d()}catch(G){se(G)}finally{V(!1)}},La=async()=>{V(!0),f(null);try{await lS(n),d()}catch(G){se(G)}finally{V(!1)}},Tn=async()=>{V(!0),f(null);try{await sv(n),I(null),Me(!1),d()}catch(G){se(G),d()}finally{V(!1)}},ln=async(G,je,ze)=>{V(!0),f(null);try{await fu(n,{repo:G,developerAgentId:je,reviewerAgentId:ze}),Me(!1),d()}catch(Ve){Me(!1),se(Ve),d()}finally{V(!1)}},Tt=async(G,je)=>{V(!0),f(null);try{await fu(n,dN(B.developerAgentId,B.reviewerAgentId,G,je)),At(cN),d()}catch(ze){se(ze),d()}finally{V(!1)}},hl=async()=>{V(!0),f(null);try{await tS(n),u(),d()}catch(G){se(G)}finally{V(!1)}},ml=async()=>{V(!0),f(null);try{await rv(n),d()}catch(G){se(G)}finally{V(!1)}},sn=async()=>{V(!0),f(null);try{await aS(n),yt(!1),Le("Issue closed — it will not execute. History is retained and can be found as closed work."),d()}catch(G){se(G)}finally{V(!1)}},Bi=async()=>{V(!0),f(null);try{await oN(n,{externalLabel:B.externalLabel},{removeIssue:nS,navigateToIssues:G=>U("/issues",{state:{deletedNotice:G}}),onHumanActionsChanged:u,closeConfirmation:()=>Qe(!1),reportError:G=>se(G),refresh:d})}finally{V(!1)}},Zl=async()=>{if(confirm("Abort this workflow? The current worker will stop and the issue will close. History and evidence are kept.")){V(!0),f(null);try{await eS(n),d()}catch(G){se(G)}finally{V(!1)}}},On=async(G,je,ze)=>{V(!0),f(null);try{await uv(G,eN,je,ze),u(),d()}catch(Ve){se(Ve)}finally{V(!1)}},pl=()=>{m||J2(n).then(x).catch(G=>se(G))},Ln=G=>{y[G]||(v(je=>({...je,[G]:{content:"",loading:!0}})),F2(n,G).then(je=>v(ze=>({...ze,[G]:{content:je.content,loading:!1}}))).catch(je=>v(ze=>({...ze,[G]:{content:"",loading:!1,error:String(je)}}))))};return r.jsx("div",{className:"flex-1 min-h-0 overflow-y-auto px-6 py-4",children:r.jsxs("div",{className:"max-w-3xl",children:[r.jsx(sa,{to:"/issues",className:"font-ui-display inline-block text-sm text-white/50 hover:text-white mb-3",children:"← Issues"}),r.jsxs("div",{className:"flex items-start justify-between gap-4 mb-4",children:[r.jsxs("div",{children:[r.jsx("h2",{className:"text-lg font-semibold text-white/90",children:B.title}),r.jsxs("p",{className:"text-xs text-white/45 mt-1",children:["Owner: ",r.jsx("span",{className:"capitalize",children:B.currentOwner}),B.currentIntent?` · ${B.currentIntent}`:""]}),r.jsxs("div",{className:"flex flex-wrap gap-3 mt-2 text-xs text-white/40",children:[B.prUrl&&r.jsxs("a",{href:B.prUrl,target:"_blank",rel:"noreferrer",className:"text-cyber-teal hover:underline",children:["PR #",B.prNumber]}),B.externalUrl&&r.jsx("a",{href:B.externalUrl,target:"_blank",rel:"noreferrer",className:"text-cyber-teal hover:underline",children:B.externalLabel??"External link"}),r.jsxs("span",{children:["Round ",B.currentRound,"/",B.maxReviewRounds]}),r.jsxs("span",{children:["Infra attempts ",B.infraAttempts,"/",B.maxInfraAttempts]}),r.jsxs("span",{title:"Wall-clock time from workflow start to completion (or now)",children:[vd(ut)," elapsed"]}),r.jsxs("span",{title:`${De.totalTokensIn} in / ${De.totalTokensOut} out tokens`,children:["$",De.totalCostUsd.toFixed(2)]}),Ta>0&&r.jsxs("span",{title:"Time spent waiting on a human, excluding autonomous processing",children:[vd(Ta)," human wait"]}),ua>0&&r.jsxs("span",{children:[ua," intervention",ua===1?"":"s"]})]})]}),r.jsx(mv,{status:B.status})]}),Ae&&r.jsx("div",{className:"mb-4 p-3 rounded border border-white/15 bg-white/[0.04]",children:r.jsx("p",{className:"text-sm text-white/85",children:Ae})}),r.jsx(Uj,{issue:B,agents:s,canEdit:Ut,editing:ye,busy:ne,onBeginEdit:()=>Me(!0),onSave:(G,je,ze)=>void ln(G,je,ze),onCancel:()=>Me(!1)}),B.executionContract&&r.jsx(zj,{contract:B.executionContract}),r.jsx(qj,{attachments:l.sourceAttachments}),r.jsxs("div",{className:"mb-4 p-3 rounded border border-white/10 bg-panel-elevated/40 flex items-start justify-between gap-3",children:[r.jsxs("div",{children:[r.jsx("p",{className:"text-xs text-white/45",children:"Next"}),r.jsx("p",{className:"text-sm text-white/85",children:fN(l)})]}),qt&&r.jsx("button",{type:"button",className:"btn-ghost-danger px-3 py-1.5 text-xs shrink-0 disabled:cursor-not-allowed disabled:opacity-60",disabled:ne,onClick:Zl,children:"Abort workflow"})]}),Ye&&r.jsxs("div",{className:"mb-4 p-3 rounded border border-cyber-teal/30 bg-cyber-teal/5",children:[r.jsxs("p",{className:"text-xs text-cyber-teal font-medium uppercase tracking-wide",children:["Queued · position ",Ye.position]}),r.jsx("p",{className:"text-sm text-white/80 mt-0.5",children:Ye.waitReason??"Next up — starts as soon as the coordinator ticks"})]}),Ga&&r.jsxs("div",{className:"mb-4 p-3 rounded border border-amber-400/30 bg-amber-500/10 flex flex-wrap items-start justify-between gap-3",children:[r.jsxs("div",{className:"min-w-0 flex-1",children:[r.jsx("p",{className:"text-xs text-amber-300 font-medium uppercase tracking-wide",children:Ga.kind==="usage_capped"?"Waiting on usage cap":"Waiting on Agent Deck"}),r.jsx("p",{className:"text-sm text-white/80 mt-0.5 break-words",children:Ga.reason}),r.jsxs("p",{className:"text-xs text-white/45 mt-0.5",children:["Wait until ",new Date(Ga.until).toLocaleString()]})]}),r.jsx("button",{type:"button",className:"btn-gold px-3 py-1.5 text-xs shrink-0 disabled:opacity-50",disabled:ne,title:"Park this issue for a human — cancels the wait without touching the worktree; a resume continues with whichever agents are then set",onClick:hl,children:"Park for human"})]}),ft&&qe&&r.jsxs("div",{className:"mb-4 p-3 rounded border border-cyber-teal/35 bg-cyber-teal/5 space-y-1.5",children:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("span",{className:"inline-block w-1.5 h-1.5 rounded-full bg-cyber-teal animate-pulse","aria-hidden":!0}),r.jsx("p",{className:"text-xs text-cyber-teal font-medium uppercase tracking-wide",children:"Running now"})]}),r.jsxs("p",{className:"text-sm text-white/90",children:[r.jsx("span",{className:"capitalize",children:qe.role}),qe.runtime?` · ${qe.runtime}`:"",qe.model?` · ${qe.model}`:"",` · round ${qe.round}`]}),r.jsxs("p",{className:"text-sm text-[#C4B643] truncate",title:Za??B.currentIntent??"session started",children:["Last progress: ",Za??B.currentIntent??"session started"]}),wt&&r.jsxs("p",{className:`text-xs ${wd(wt)?"text-amber-300":"text-white/55"}`,title:gd(wt),children:["Branch tip: ",wt.tipLabel,bd(wt)]}),Za&&B.currentIntent&&!/session running/i.test(B.currentIntent)&&!nN(B.currentIntent,Za)&&r.jsx("p",{className:"text-xs text-white/45 truncate",title:B.currentIntent,children:B.currentIntent}),r.jsxs("p",{className:"text-xs text-white/45",children:["Heartbeat ",aN(qe.heartbeatAt),Ds(qe.worktreePath)?` · ${Ds(qe.worktreePath)}`:""]}),qe.logPath&&r.jsxs("p",{className:"text-xs text-white/40 font-mono break-all",title:qe.logPath,children:["Log: ",Ds(qe.logPath)??qe.logPath]})]}),Ft&&dt&&r.jsxs("div",{className:"mb-4 p-3 rounded border border-red-400/30 bg-red-500/10 space-y-1.5",children:[r.jsx("p",{className:"text-xs text-red-300 font-medium uppercase tracking-wide",children:"Latest session failure"}),r.jsx("p",{className:"text-sm text-white/90 whitespace-pre-wrap break-words",children:dt.reason}),r.jsxs("p",{className:"text-xs text-white/45",children:[dt.role?r.jsx("span",{className:"capitalize",children:dt.role}):"Worker",dt.outcome?` · ${dt.outcome}`:"",` · ${new Date(dt.when).toLocaleString()}`,` · infra ${dt.infraAttempts}/${dt.maxInfraAttempts}`]}),wt&&r.jsxs("p",{className:`text-xs ${wd(wt)?"text-amber-300":"text-white/55"}`,title:gd(wt),children:["Branch tip: ",wt.tipLabel,bd(wt)]}),dt.logPath&&r.jsxs("p",{className:"text-xs text-white/40 font-mono break-all",title:dt.logPath,children:["Log: ",Ds(dt.logPath)??dt.logPath]})]}),wt&&!ft&&!Ft&&r.jsxs("div",{className:"mb-4 p-3 rounded border border-white/10 bg-white/[0.03] space-y-1",children:[r.jsx("p",{className:"text-xs text-white/45 uppercase tracking-wide",children:"Branch tip"}),r.jsxs("p",{className:`text-sm ${wd(wt)?"text-amber-300":"text-white/80"}`,title:gd(wt),children:[wt.tipLabel,bd(wt)]})]}),!Bt.ok&&!ca.some(G=>G.actionType==="product_scope_decision")&&r.jsx("div",{className:"mb-4 p-3 rounded border border-amber-400/30 bg-amber-500/10",children:r.jsxs("p",{className:"text-xs text-amber-300 font-medium",children:["Not startable yet — missing: ",Bt.missing.join(", ")]})}),ca.length>0&&r.jsxs("div",{className:"mb-4 p-3 rounded border border-red-400/30 bg-red-500/10 space-y-2",children:[r.jsx("p",{className:"text-xs text-red-300 font-medium",children:"Human action needed"}),ca.map(G=>{const je=G.actionType==="product_scope_decision";if(G.actionType==="operator_verification"){const ze=xj(G),Ve=W[G.id]??"",ht=Ve.trim().length>0;return r.jsx(zs,{action:G,hideChoicesHint:!0,children:r.jsxs("div",{className:"space-y-1",children:[r.jsx("textarea",{className:"w-full bg-black/30 border border-white/10 rounded px-3 py-2 text-sm text-white/85 placeholder:text-white/30",rows:2,placeholder:"Result note (required) — paste the probe output, waiver reason, or repair note",value:Ve,disabled:ne,onChange:mt=>te(C=>({...C,[G.id]:mt.target.value}))}),r.jsx("div",{className:"flex flex-wrap gap-2",children:ze.map(mt=>r.jsx("button",{type:"button",className:"btn-gold px-3 py-1 text-xs disabled:opacity-50",disabled:ne||!ht,title:ht?void 0:"Enter the result note first — the server requires it",onClick:()=>On(G.id,mt.choice,Ve),children:mt.label},mt.choice))})]})},G.id)}return je?r.jsx(zs,{action:G,hideChoicesHint:!0,children:Bt.ok&&r.jsxs("div",{className:"space-y-1",children:[r.jsx("textarea",{className:"w-full bg-black/30 border border-white/10 rounded px-3 py-2 text-sm text-white/85 placeholder:text-white/30",rows:2,placeholder:"Decision note (optional) — shown to the next developer round",value:N[G.id]??"",disabled:ne,onChange:ze=>Y(Ve=>({...Ve,[G.id]:ze.target.value}))}),r.jsx("button",{type:"button",className:"btn-gold px-3 py-1 text-xs",disabled:ne,onClick:()=>On(G.id,"resume",N[G.id]),children:"Resume"})]})},G.id):r.jsx(zs,{action:G,disabled:ne,onChoose:ze=>On(G.id,ze)},G.id)})]}),Ue&&r.jsx("div",{className:"mb-4",children:r.jsx(bv,{variant:"parked",agents:s,initialDeveloperId:B.developerAgentId,initialReviewerId:B.reviewerAgentId,busy:ne,notice:bt,onSave:(G,je)=>void Tt(G,je)},`${B.developerAgentId??""}:${B.reviewerAgentId??""}`)}),(dl||fl)&&!D&&!J&&r.jsxs("div",{className:"mb-4 flex flex-wrap items-center gap-x-4 gap-y-1",children:[dl&&r.jsx("button",{type:"button",className:"font-ui-display text-xs text-cyber-teal hover:underline",onClick:Vl,children:"Edit title / description / acceptance criteria"}),fl&&r.jsx("button",{type:"button",className:"font-ui-display text-xs text-cyber-teal hover:underline",title:"Pull the latest title, description, and acceptance criteria from the linked Linear ticket — local edits will be replaced",onClick:()=>re(!0),children:"Reload from Linear"})]}),fl&&J&&!D&&r.jsxs("div",{className:"mb-4 p-3 rounded border border-cyber-teal/30 bg-cyber-teal/5 space-y-2",children:[r.jsxs("p",{className:"text-sm text-white/90 font-medium",children:["Reload the latest task text from Linear",B.externalLabel?` ${B.externalLabel}`:"","?"]}),r.jsx("p",{className:"text-sm text-white/70",children:"This replaces the local title, description, and acceptance criteria with the latest ticket text. Local edits will be lost. Repository, agents, and queue position are unchanged, and nothing is written back to Linear."}),r.jsxs("div",{className:"flex gap-2",children:[r.jsx("button",{type:"button",className:"btn-gold px-4 py-1.5 text-sm disabled:opacity-50",disabled:ne,onClick:nn,children:"Reload from Linear"}),r.jsx("button",{type:"button",className:"font-ui-display px-4 py-1.5 text-sm text-white/60 hover:text-white",onClick:()=>re(!1),children:"Cancel"})]})]}),D&&r.jsxs("div",{className:"mb-4 p-3 rounded border border-white/10 bg-panel-elevated/60 space-y-2",children:[r.jsx("input",{className:"w-full bg-black/30 border border-white/10 rounded px-3 py-2 text-sm",value:E,onChange:G=>$(G.target.value),placeholder:"Title"}),r.jsx("textarea",{className:"w-full bg-black/30 border border-white/10 rounded px-3 py-2 text-sm",rows:2,value:L,onChange:G=>H(G.target.value),placeholder:"Description"}),r.jsx("textarea",{className:"w-full bg-black/30 border border-white/10 rounded px-3 py-2 text-sm",rows:2,value:F,onChange:G=>P(G.target.value),placeholder:"Acceptance criteria"}),r.jsxs("div",{className:"flex gap-2",children:[r.jsx("button",{type:"button",className:"btn-gold px-4 py-1.5 text-sm",disabled:ne,onClick:an,children:"Save"}),r.jsx("button",{type:"button",className:"font-ui-display px-4 py-1.5 text-sm text-white/60 hover:text-white",onClick:()=>X(!1),children:"Cancel"})]})]}),(B.status==="ready"||B.status==="needs_human"&&ca.length===0)&&r.jsxs("div",{className:"mb-4 space-y-2",children:[tn&&r.jsxs("p",{className:"text-sm text-amber-200/90",children:["Fix before Start: ",ol]}),Ne&&r.jsx("p",{className:"text-sm text-amber-200/90",children:Ne}),r.jsxs("div",{className:"flex flex-wrap gap-2",children:[r.jsx("button",{type:"button",className:"btn-gold px-4 py-2 disabled:opacity-50",disabled:!Bt.ok||ne||!!tn,title:tn?ol:"Run next — move to the front of the admission queue; runs now if a slot is free, otherwise waits first with a reason",onClick:Qa,children:"Run next"}),r.jsx("button",{type:"button",className:"px-4 py-2 text-sm border border-cyber-teal/40 rounded text-cyber-teal hover:bg-cyber-teal/10 disabled:opacity-50",disabled:!Bt.ok||ne||!!tn,title:tn?ol:"Execute now — start immediately, skipping queue order; refuses (changing nothing) when capacity, readiness, blockers, or agent health prevents it",onClick:Tn,children:"Execute now"}),Rn?r.jsx("button",{type:"button",className:"font-ui-display px-4 py-2 text-sm border border-white/15 rounded text-white/60 hover:text-white disabled:opacity-50",disabled:ne,onClick:ml,children:"Remove from queue"}):r.jsx("button",{type:"button",className:"font-ui-display px-4 py-2 text-sm border border-white/15 rounded text-white/80 hover:border-cyber-teal/50 hover:text-cyber-teal disabled:opacity-50",disabled:ne||qt,title:"Add to queue — append to the end of the admission queue; does not start anything now",onClick:La,children:"Add to queue"})]}),Rn&&Ut&&!ye&&r.jsx("p",{className:"text-xs text-white/40",children:"Queued — edit repository / agents from the Configuration section above; position is kept."})]}),r.jsx(Pj,{issueId:n}),r.jsx("div",{className:"border-t border-white/10 pt-3",children:r.jsx(Gj,{events:ce})}),r.jsxs("div",{className:"mt-4 flex gap-2",children:[r.jsx("input",{className:"flex-1 bg-black/30 border border-white/10 rounded px-3 py-2 text-sm",placeholder:"Guide this issue…",value:w,onChange:G=>j(G.target.value),onKeyDown:G=>G.key==="Enter"&&at()}),r.jsx("button",{type:"button",className:"btn-gold px-4",onClick:at,children:"Send"})]}),(Oa||tt)&&r.jsxs("details",{className:"mt-6",children:[r.jsx("summary",{className:"text-xs text-white/45 cursor-pointer hover:text-white/70",children:"More actions"}),r.jsxs("div",{className:"mt-2 space-y-2",children:[r.jsxs("p",{className:"text-xs text-white/45",children:[Oa?"Remove from queue means do not run yet — the issue stays ready and can run later. Close issue means this work is no longer needed — it will never execute, but history is kept.":"This work is finished — there is nothing left to close or abort.",tt?" Delete from Dealer permanently removes the local issue, its history, and its files.":""]}),Oa&&(rt?r.jsx(lN,{busy:ne,onConfirm:()=>void sn(),onCancel:()=>yt(!1)}):r.jsx("button",{type:"button",className:"font-ui-display text-xs text-white/50 hover:text-red-300 underline underline-offset-2 disabled:opacity-50",disabled:ne,title:"Retire this issue without running it — removes any queue entry, keeps history as closed work",onClick:()=>yt(!0),children:"Close issue"})),tt&&(lt?r.jsx(rN,{expectedToken:iN(B),externalLabel:B.externalLabel,busy:ne,onConfirm:()=>void Bi(),onCancel:()=>Qe(!1)}):r.jsx("button",{type:"button",className:"font-ui-display text-xs text-white/50 hover:text-red-300 underline underline-offset-2 disabled:opacity-50",disabled:ne,title:"Permanently delete the Dealer-local issue, its history, and its files — the Linear ticket is not deleted",onClick:()=>Qe(!0),children:"Delete from Dealer"}))]})]}),r.jsxs("details",{className:"mt-6",onToggle:G=>G.currentTarget.open&&pl(),children:[r.jsx("summary",{className:"text-xs text-white/45 cursor-pointer hover:text-white/70",children:"Evidence & raw trace"}),m?r.jsxs("div",{className:"mt-2 space-y-3 text-xs text-white/60",children:[r.jsxs("div",{children:[r.jsx("p",{className:"text-white/45 mb-1",children:"Worker sessions"}),m.workerSessions.map(G=>{const je=m.usageEvents.filter(mt=>mt.workerSessionId===G.id),ze=je.reduce((mt,C)=>mt+(C.costUsd??0),0),Ve=je.reduce((mt,C)=>mt+(C.tokensIn??0),0),ht=je.reduce((mt,C)=>mt+(C.tokensOut??0),0);return r.jsxs("p",{children:[G.role," round ",G.round," · ",G.status,G.startedAt&&G.completedAt?` · ${vd(new Date(G.completedAt).getTime()-new Date(G.startedAt).getTime())}`:"",je.length>0?` · $${ze.toFixed(3)} · ${Ve}→${ht} tok`:""]},G.id)}),m.workerSessions.length===0&&r.jsx("p",{className:"text-white/35",children:"None yet."})]}),r.jsxs("div",{children:[r.jsx("p",{className:"text-white/45 mb-1",children:"Artifacts"}),m.artifacts.map(G=>{const je=y[G.id];return r.jsxs("details",{className:"mb-1.5",onToggle:ze=>ze.currentTarget.open&&G.blobPath&&Ln(G.id),children:[r.jsxs("summary",{className:"cursor-pointer hover:text-white/80",children:[G.kind," · ",new Date(G.createdAt).toLocaleString()]}),r.jsxs("div",{className:"mt-1 pl-3 border-l border-white/10 space-y-1",children:[G.contentJson&&r.jsx("pre",{className:"whitespace-pre-wrap break-words text-white/55",children:tN(G.contentJson)}),G.blobPath&&r.jsxs("div",{children:[r.jsxs("p",{className:"text-white/40",children:["Raw trace: ",G.blobPath]}),(je==null?void 0:je.loading)&&r.jsx("p",{className:"text-white/35",children:"Loading trace…"}),(je==null?void 0:je.error)&&r.jsx("p",{className:"text-red-300/80",children:je.error}),je&&!je.loading&&!je.error&&r.jsx("pre",{className:"mt-1 max-h-64 overflow-y-auto whitespace-pre-wrap break-words text-white/50 bg-black/20 rounded p-2",children:je.content||"(empty)"})]}),!G.contentJson&&!G.blobPath&&r.jsx("p",{className:"text-white/35",children:"No content recorded."})]})]},G.id)}),m.artifacts.length===0&&r.jsx("p",{className:"text-white/35",children:"None yet."})]})]}):r.jsx("p",{className:"text-xs text-white/40 mt-2",children:"Loading…"})]})]})})}function mN({issueId:n,agents:l,onHumanActionsChanged:s}){const[u,d]=b.useState(null),[f,m]=b.useState(null),[x,y]=b.useState(!1),v=()=>lv(n).then(w=>{d(w),m(null),y(!1)}).catch(w=>{const j=String(w).replace(/^Error:\s*/i,"").trim();/^not found$/i.test(j)?(y(!0),m(null),d(null)):(m(j),y(!1))});return b.useEffect(()=>{d(null),m(null),y(!1),v();const w=setInterval(v,4e3);return()=>clearInterval(w)},[n]),x?r.jsx("div",{className:"flex-1 min-h-0 overflow-y-auto px-6 py-10",children:r.jsxs("div",{className:"max-w-md space-y-3",children:[r.jsx("h2",{className:"text-lg font-semibold text-white/90",children:"Issue not found"}),r.jsx("p",{className:"text-sm text-white/55",children:"No issue exists for this ID — it may have been deleted, or the link is wrong."}),r.jsx(sa,{to:"/issues",className:"font-ui-display inline-block text-sm text-cyber-teal hover:underline",children:"← Back to Issues"})]})}):f?r.jsxs("div",{className:"flex-1 min-h-0 overflow-y-auto px-6 py-6 space-y-3",children:[r.jsx("p",{className:"text-red-300 text-sm",children:f}),r.jsx(sa,{to:"/issues",className:"font-ui-display inline-block text-sm text-cyber-teal hover:underline",children:"← Back to Issues"})]}):u?r.jsx(hN,{issueId:n,detail:u,agents:l,onHumanActionsChanged:s,refresh:v,onError:w=>m(w)},n):r.jsx("div",{className:"p-6 text-white/50 text-sm",children:"Loading…"})}function pN(){return r.jsx("div",{className:"flex-1 min-h-0 overflow-y-auto px-6 py-10",children:r.jsxs("div",{className:"max-w-md space-y-3",children:[r.jsx("h2",{className:"font-ui-display text-lg font-semibold text-white/90",children:"Page not found"}),r.jsx("p",{className:"text-sm text-white/55",children:"That URL is not a destination in Agent Dealer."}),r.jsx(sa,{to:"/issues",className:"font-ui-display inline-block text-sm text-cyber-teal hover:underline",children:"← Back to Issues"})]})})}function xN(){return r.jsxs("div",{className:"fixed inset-0 pointer-events-none z-0 overflow-hidden","aria-hidden":!0,children:[r.jsx("div",{className:"absolute top-16 left-12",children:r.jsx("div",{className:"ambient-orb ambient-orb-a w-[26rem] h-[26rem] rounded-full bg-cyan-500/10 blur-3xl"})}),r.jsx("div",{className:"absolute bottom-20 right-12",children:r.jsx("div",{className:"ambient-orb ambient-orb-b w-[26rem] h-[26rem] rounded-full bg-pink-500/10 blur-3xl"})}),r.jsx("div",{className:"absolute top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2",children:r.jsx("div",{className:"ambient-orb ambient-orb-c w-[22rem] h-[22rem] rounded-full bg-blue-500/[0.07] blur-3xl"})})]})}function yN({className:n="w-5 h-5"}){return r.jsxs("svg",{viewBox:"0 0 20 20",fill:"currentColor",className:n,"aria-hidden":!0,children:[r.jsx("circle",{cx:"6.75",cy:"6.25",r:"3.25"}),r.jsx("circle",{cx:"13.5",cy:"6.75",r:"2.85",opacity:"0.85"}),r.jsx("path",{d:"M1.75 16v-1.1c0-2.35 1.928-4.25 4.3-4.25 1.16 0 2.21.456 3 1.2.79-.744 1.84-1.2 3-1.2 2.372 0 4.3 1.9 4.3 4.25V16H1.75z"})]})}const vN="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAJYAAACWCAYAAAA8AXHiAAAN5UlEQVR4AeydXagdVxmGF7loIKSpN/WHttqKktpAvWkVoRctp4gRtf4QbxRrREEb0wtRGkRovLCmKC1Y641CFGpBCtpIsVfHRvAm5KpIrMGfCCJUa8GmTWl6k+5nznlPvzOZ2Xtmz5o1a/Z8Ie/+vjU/a6351nPe/Xv22bFr185LLq9BbAZ2BP/nFeihAg5WD0X1LkNwsJyCXirgYPVSVu/UwXIGeqmAg9VLWTPsNPGUHKzEBZ/KcA7WVFY68XU6WIkLPpXhHKyprHTi63SwEhc89nDv37cndpdR+nOwopQxfScA9dDRfQGRM4O1ew+Fd3/wVtLB5WANtgTLDQxEwITI6eXoDz8dHvjrmbB2+J6ZDrFpcDlYgy9BswkAETAhcnvWnlfOBsS2G2aOlYNrOVisRsYCImBC5HVTveb5327tWjs8vGs5WFvLkVcCRMCEyO3szu/ea5tFjmMhGjm4loPFSmQkIAImRG6nBlDPvedbAZHbfeQ5uZaDxYpkICACJkRupwREwIR+c3w9fPu9+8LRb/7aHlLkOBaiMbRrOViswoACImBC5HYqVUCt/+jR4pBnz5wPqGiYm1xcy8F6c1GSZkAETIjcDj4PKHvcL574l20WuRyLxpCu5WCxAgkFRMCEyO3QTYHSOTgWUlvx2gyeITpYWo2eIxABEyK3w7UFyp5b5Vr27nAo13Kw7Cr1kAMRMCFyO0QXoNQPjoXUVhzatRwsrUTkCETAhMht9zGAsv3l6FoOll2hCDkQARMit13GBkp941hIbcUhXcvB0ip0jEAETIjcdtcXUHaM3Fwra7Bs4XLNgQiYELmdZwqgNB6OhdRWHMq1HCytQMsIRMCEyO3pKYGy4+bkWg6WXZkGORABEyK3pwwFlOaAYyG1FYdwLQdL1V8QgQiYELk93AJ16dyt4R2PXxNueXm/PSRZnotrOVgLlhyIgAmR28MtULw5/NID58LuP11ZHHLj9bcFVDQS3uBYqDxkatdysMorsNkGImBC5Jubi1AGik8b8ObwiWeOFft1c9cdR5QmjTm4loNVWnIgAiZEbnfXAaVj/vLPPwakNo6F1E4VcSxUHi+la7UDqzzTFWsDE2oLlC2Du9ZGNRysjTrU3sqliOdOnQ7c5dUePNuBY6FZWvzHsVDRSHiDY6HykKlcy8EylT91+l2mtZHy+SZEq+knBdy1gn+jH8DgKPcdfCp85AOPh4uv3symbbIfQ2nyGzA4FlIn9I/UThVxLFQeL4VrTdqxWGyAQhQfGF564XOk24RjITa6a1GFxZokWGWgHjz+sYC4C3vtws0r5Vp1CPTtWpMCqw4onIoFIKJVcC2e2fIMF3FtVjwRQdpW4cLatXScBFiLgLLVS+lad3/2urD+xIcCENg5dMnpC5gQue2Lx49/3/Odyt9LbPLY0fa1KF9psNoApULhWKhP1xJQXzhwbTHs3QeuK2KXGyACJkRu++IB/DeOngl/OPnxcOncLXbXVh7btVYSrGWA2qrwLDk7ewW9j8daV139y/Dhj34vCKjZUMV/QEBFo+UN5wETIrenCyigIseNr/jPznDFf3faw7bymK61UmB1BUoVfnLzPb9YrvX8ha+Fd960P1x19WMa4rLY1rWACJgQue0QiIAJkWsfToyu3HyjXNsVY7rWSoAVCygVmHji5LHQ1bXKd3n0WyfgQHX7tZ1jgAmRazsRiIAJkbOtrFSuNWqw+gBKC9HVtVj08l0effNsjO9gINK2muda9AdMiNyeB0TAhMjtvnKOY6G+XWuUYPUJlF2ILq718u69oQoe+mf7v9/+CdJtAhhkN9IGJkRu9wERMCFyu29ensK1RgVWKqC0KMu4Ft+m95XHfh6+PFMVPLyCj4ALaSxFuRYQARMi134iEAETImdbG+FYqE/XGgVYqYGyi9TGtQQUD4Lpg0VH5FZ677EKPCACJkRuz6MvYELkdl/bvG/XyhqsIYHSQrVxLQHFx2t+9vkvhp/OVPVpThwL4VhIYyn2CZTGwLFQX66VJVg5AKUFIDZ1LY4VUP84dZpm8R1WVe4i1+KxWHFgxQ3n4U6IvOKQTpv6dK2swMoNKK1aU9fS8eVY51rv+9sPggArnwNIfQGlsXAs1IdrZQFWrkBpAYi4FndbiLaVhaPq1WsgQfYccu4OiUOqL9caFKwxAKVFx7V4O+SFHQc2NplbAEFs4nEWzwzJrZ7983nbrM0Bl9e5fvz0rtpjYu7AsVBs1xoErDEBZRcR1+JNXBbfbievcy0eiPMMr+rFUs6T6BOgfvfi7eGhr34/6DGa9vcZ+3CtpGCNFSgtahvX+tSX7iz+zg1QAZf6KMcyUDyTTAkV88GxUEzXSgLW2IGi+NIi19rzytnAg/Kv779w2eesgAjRF9E61BBAMQ8ptmv1CtYqAaUFWORaQAVcOp4oiACJF0WJussbGijmh3AsFMu1egFrFYGi+NI819IxRAsUOdt4dshjqFyAYk5STNeKCtaqA6UFmOdaHANEuBIiZ5t9NT71YyjGbyIcC8VwrShg5QFUk9LFO6bKtYAImBC5Riu/Gq/tOcZYrtUJrCkCJRisawERMCFyHTPGiGOhrq61FFhTBsrCgms99/vXKn/rxR5X9Wq83Z9bHsO1WoHlQG1HANd6+MHPBB4/ofVHfrL9gM1W3avxm7uzCzgW6uJajcByoOavPc/wEN9EA2BVR0/NteaC5UBVITJ/2/ojj1YeMDXXqgTLgapko9FGXkpw1yp9jVFkoBotxCoeNCXXqlu/wrEsUOQ82+HbV3gAV3eib6+vwKRc695DlYUowGIPQBHR3utvI7g6VGAqrrV2+J7KKhVg4UxIRwAZUttj+wpM3bUKsCgbL4oRpaG+o1zjr0KcsmttgYVjIS0ojoXU9ti+AlN2rS2wKJu7FlWIq0m41qxk5cda28DCsdDsuOI/joWKht8sVYGputY2sKicuxZViKsputZlYOFYSKXFsZDaHttXYIqudRlYlM1diyrE1dRcqxIsHAuptDgWUttj+wpMzbUqwaJs7lpUIa6m5Fq1YOFYSKXFsZDaHttXIJ1rtZ9b2zMwHr5yoOobmPl0Ry1YDMTJRMlfjVcllo+r4lqvv+1iePHO/4XX33pxqxgApV8cmQsWjoV0Jo6F1PbYvgJjdy2+8ETfXCioLFBcH1WZCxYHuGtRhbgao2tZoPg0LBWpAortaCFYOBbiYIRjIXLXchXgp5pFqTp77XD155uqjk2xrS1QmtNCsDjQXYsqxFXurrUsUKpSI7BwLKSTcCyktsf2FcjVtboCpUo0AouD3bWowtKqPDEn14oFlC60MVg4FtKJOBZS22P7CuTgWrGBUhUag8UJ7lpUIa6Gcq2+gFJ1WoGFYyGdjGMhtT22r0Bq1+obKFWgFVic5K5FFeIqhWulAkqVaQ0WjoXUAY6F1PbYvgJ9ulZqoHT1rcHiRHctqhBXsV1rKKBUlaXAwrGQOsGxkNpjiLnNMZZrDQ2U6roUWJzsrkUV4qqLa+UClCqyNFg4FlJHOBZS22P7CizjWrkBpateGiw6cNeiCnHV1LVyBUrV6AQWjoXUGY6F1PbYvgKLXCt3oHTFncCiE3ctqhBX81yLvzXd5PNQcWfUvrfOYOFYSEPjWEhtj+0rMM+16I3PcukjwBzLttzUGSwuKIpr0ZFrqwJVrjUGoHQBUcDCsZA6xbGQ2h7bVYDaHbjp/qDfgBkTULrSKGDRmbsWVegmgLrv4FMB0RNf7537XR7zrFI0sHAspEEoElLbY30FqBMwIY7i+1/R0796OOlfWmXsWIoGFhNy16IKzVUHlP0Bbd5bXkdGBYuCIF0ihUNqe9yoADXBnRBbcCdka8f2MSsqWBTCXYsqVGsKQOnK54ClQ9pFfuqQzqKYSO0pRq4fd0JcP+6EbJ3YvkqKDhbFcdeiCiFMEaiNKy/9yRNt7Br5SUTqhwIjtVc9cq24E+JacSdka8L2VVYvjkXBpuhaDhQrv6HewOKnE20Ms3G3QOHVXqXIdeFOiOvCnZC9frZPSb2BRRFX3bUcKFa5Wr2CxU8s0tAsBFJ7rJFrwJ0Q14A7IXutbB+L+phnr2Ax4VVyLQeKFW2m3sHipxhpOiwOUnsMkfniToj54k7IXhfbXW9WoHewGGqsruVAsXrLKQlY/GQjTZEFQ2rnFpkb7oSYG+6E7DWw3VVfgSRgMfwYXOuTdxwJx7/7/63PQwETcqBYwXZKBhaLgzQ9XAGpPWQUUHfdfiQwR2BC5EPOa8xjJwOLIpVd68Ybhv3b09kCRbFGrqRg4QBINcMhlKeMDlT/1U4KFpdTdi0Wme0pxFg8hgJoAOfuDpGnGH9KYyQHi0VEKjKLrLyv6ED1Vdn6fpODxVRSuZYDRbWH0SBg4VhIlxzbtSxQJ04eCwfvf0vwuzxVO00cBCwurQ/XqgLqyWeOMZwrcQUGAwvHQrreLq7VP1CapcemFRgMLCbY1bUcKKqYpwYFC8dCKk1T13KgVLF846BgUZY2ruVAUbFxaHCwcCykclW5lgOl6ownDg4WpapzLQeK6oxTWYCFYyGVENfSWy96HcpfNlB1xhGzAItSlV1rAVCc4sq4AtmAhWMhBypjWlpMLRuwmDNvu/hdHpUYv7ICa/zl9CtQBRwsVcJj1Ao4WFHL6Z2pAg6WKuExagWigRV1Vt7Z6CvgYI1+CfO8AAcrz3UZ/awcrNEvYZ4X4GDluS6jn5WDNfolzPMCHKw81yXjWTWb2hsAAAD//0DhVxwAAAAGSURBVAMA8NLI/5AoLlwAAAAASUVORK5CYII=";function gN({className:n="",size:l=36}){return r.jsx("img",{src:vN,alt:"",width:l,height:l,className:`shrink-0 object-contain ${n}`,"aria-hidden":!0,draggable:!1})}const Au={unsupported:"not reported by provider",missing:"no data yet",expired:"expired",unparsable:"provider data unparsable",stale:"stale"},Fx="5H",Wx="1W",bN=new Set(["claude_code","codex_local","muse_code"]),wN="billing_cycle",SN="1M",jN=new Set(Yt.options),NN={critical:"font-medium text-red-300",warning:"font-medium text-yellow-300",normal:"font-medium text-white/75"};function _N(n){return{fiveHour:n.find(l=>l.criticalRole==="five_hour")??null,weekly:n.find(l=>l.criticalRole==="weekly")??null}}function wv(n,l,s){if(n.unavailableReason!==null)return n.unavailableReason;if(n.remainingPercent===null||n.source==="unavailable")return s??"missing";if(n.resetAt!==null){const u=Date.parse(n.resetAt);if(!Number.isFinite(u)||u<=l)return"expired"}if(n.freshUntil!==null){const u=Date.parse(n.freshUntil);if(!Number.isFinite(u)||u<=l)return"stale"}if(n.expiresAt!==null){const u=Date.parse(n.expiresAt);if(!Number.isFinite(u)||u<=l)return"expired"}if(n.observedAt){const u=Date.parse(n.observedAt);if(!Number.isFinite(u)||u>l+6e4)return"stale"}return s??"missing"}function Px(n,l,s,u,d=null){if(Gy(n,l)){const m=Math.round(n.remainingPercent??0),x=n.resetAt?`, resets ${new Date(n.resetAt).toLocaleString()}`:"",y=d?`, ${d}`:"";return`${u}: ${m}% available (${100-m}% used${y}${x})`}const f=cv(n);return f!==null?`${u}: N/A (${f})`:`${u}: N/A (${Au[wv(n,l,s)]})`}function Bd(n,l,s,u,d,f=null){if(Gy(n,s)){const x=n.remainingPercent??0;return{key:n.windowKey,label:d,kind:"known",remaining:Math.round(x),rawRemaining:x,detail:Px(n,s,l.unavailableReason,d,f),isCritical:u}}const m=wv(n,s,l.unavailableReason);return{key:n.windowKey,label:d,kind:"unknown",reason:m,detail:Px(n,s,l.unavailableReason,d,f),isCritical:u}}function ey(n,l){const s=l.unavailableReason??"missing";return{key:`missing:${n}`,label:n,kind:"unknown",reason:s,detail:`${n}: N/A (${Au[s]})`,isCritical:!0}}function kN(n,l,s){return Bd(n,l,s,!0,SN,"current billing cycle")}function AN(n,l=Date.now()){return n.runtimes.map(s=>{const u=Aa(s.runtime),d=s.runtime;if(s.runtime==="cursor_local"){const f=s.windows.find(x=>x.windowKey===wN)??null;if(f===null)return{runtime:u,runtimeKey:d,windows:[],exhausted:!1,detail:`N/A (${Au[s.unavailableReason??"missing"]})`};const m=kN(f,s,l);return{runtime:u,runtimeKey:d,windows:[m],exhausted:m.kind==="known"&&m.rawRemaining===0,detail:m.detail}}if(bN.has(s.runtime)){const{fiveHour:f,weekly:m}=_N(s.windows),x=f!==null?Bd(f,s,l,!0,Fx):ey(Fx,s),y=m!==null?Bd(m,s,l,!0,Wx):ey(Wx,s),v=[x,y],w=v.some(D=>D.kind==="known"&&D.rawRemaining===0),j=v.map(D=>D.detail).join("; ");return{runtime:u,runtimeKey:d,windows:v,exhausted:w,detail:j}}return{runtime:u,runtimeKey:d,windows:[],exhausted:!1,detail:`N/A (${Au[s.unavailableReason??"missing"]})`}})}function ty(n){return n.exhausted?`${n.runtime} exhausted — a capacity window is at 0%: ${n.detail}`:`${n.runtime}: ${n.detail}`}function EN({state:n,nowMs:l}){if(n.status==="loading")return r.jsxs("span",{"data-testid":"topbar-capacity","data-status":"loading",title:"Agent capacity is loading",className:"inline-flex min-w-0 max-w-full flex-wrap items-center gap-x-2 gap-y-1 whitespace-nowrap text-xs text-white/40",children:[r.jsx("span",{className:"uppercase tracking-wider text-white/30",children:"Capacity"}),r.jsx("span",{"aria-live":"polite",children:"loading…"})]});if(n.status==="unavailable")return r.jsxs("span",{"data-testid":"topbar-capacity","data-status":"unavailable",title:"Agent capacity is unavailable — the capacity read failed",className:"inline-flex min-w-0 max-w-full flex-wrap items-center gap-x-2 gap-y-1 whitespace-nowrap text-xs text-white/40",children:[r.jsx("span",{className:"uppercase tracking-wider text-white/30",children:"Capacity"}),r.jsx("span",{children:"unavailable"})]});const s=AN(n.data,l),u=s.length===0||s.every(d=>!d.windows.some(f=>f.kind==="known"));return r.jsxs("span",{"data-testid":"topbar-capacity","data-status":u?"unknown":"ready",title:s.length===0?"Agent capacity: no runtime accounts reported":s.map(ty).join(" · "),className:"inline-flex min-w-0 max-w-full flex-wrap items-center gap-x-3 gap-y-1 text-xs",children:[r.jsx("span",{className:"uppercase tracking-wider text-white/30",children:"Capacity"}),s.length===0?r.jsx("span",{className:"whitespace-nowrap text-white/35",children:"N/A"}):s.map(d=>{const f=d.windows.some(m=>m.kind==="known");return r.jsxs("span",{"data-testid":`topbar-capacity-${d.runtime}`,"data-known":f?"true":"false","data-exhausted":d.exhausted?"true":"false",title:ty(d),role:"group","aria-label":`${jN.has(d.runtimeKey)?d.runtime:"Unknown runtime"} capacity`,className:d.exhausted?"inline-flex items-center gap-1.5 whitespace-nowrap rounded border border-red-400/40 bg-red-500/10 px-1.5 py-0.5":"inline-flex items-center gap-1.5 whitespace-nowrap",children:[r.jsx(hv,{runtime:d.runtimeKey,className:"h-4 w-4 shrink-0"}),d.windows.length===0?r.jsx("span",{className:"text-white/35",children:"N/A"}):r.jsx("span",{className:"inline-flex flex-col leading-tight",children:d.windows.map(m=>r.jsxs("span",{"data-window":m.label,"data-window-known":m.kind==="known"?"true":"false",className:"inline-flex items-center gap-1 whitespace-nowrap tabular-nums",children:[r.jsx("span",{className:"text-white/40",children:m.label}),m.kind==="known"?(()=>{const x=ov(m.rawRemaining);return r.jsxs("span",{"data-severity":x,className:NN[x],children:[m.remaining,"%"]})})():r.jsx("span",{className:"text-white/35",children:"N/A"})]},m.key))})]},d.runtime)})]})}const ay=5e3;function Sd({isActive:n}){return`font-ui-display px-3 py-2 text-base rounded ${n?"bg-cyber-teal/20 text-cyber-teal":"text-white/60 hover:text-white"}`}function CN({agents:n,onHumanActionsChanged:l}){const{issueId:s}=kb();return s?r.jsx(mN,{issueId:s,agents:n,onHumanActionsChanged:l},s):r.jsx(wy,{to:"/issues",replace:!0})}function RN({openHumanActionCount:n,agentCount:l,agentIssueCount:s,capacity:u={status:"loading"}}){return r.jsxs("header",{className:"px-6 py-3 border-b border-white/10 flex flex-wrap gap-4 items-center justify-between glass-header shrink-0",children:[r.jsxs("div",{className:"flex items-center gap-6",children:[r.jsxs(sa,{to:"/issues",className:"flex items-center gap-3 text-left rounded hover:opacity-90 transition-opacity focus-visible:outline focus-visible:outline-2 focus-visible:outline-cyber-teal/45","aria-label":"AgentDealer — go to Issues",title:"AgentDealer — go to Issues",children:[r.jsx(gN,{size:40}),r.jsx("h1",{className:"font-mono text-xl font-bold sm:text-2xl",style:{background:"linear-gradient(to right, #C4B643, #D4C760)",WebkitBackgroundClip:"text",WebkitTextFillColor:"transparent",backgroundClip:"text"},children:"AgentDealer"})]}),r.jsxs("nav",{className:"flex gap-1",children:[r.jsxs(cu,{to:"/issues",className:Sd,children:["Issues",n>0&&r.jsxs("span",{className:"ml-1.5 inline-flex items-center gap-0.5 font-mono text-xs leading-none bg-red-500/20 text-red-300 px-1.5 py-0.5 rounded tabular-nums border border-red-400/30 align-middle",title:`${n} open human action${n===1?"":"s"}`,children:[r.jsx(_u,{className:"w-3 h-3 shrink-0"}),n]})]}),r.jsx(cu,{to:"/reports/execution",className:Sd,children:"Reports"})]})]}),r.jsxs("div",{className:"flex flex-wrap items-center gap-x-4 gap-y-2 min-w-0",children:[r.jsx(EN,{state:u}),r.jsxs(cu,{to:"/agents",className:({isActive:d})=>`${Sd({isActive:d})} inline-flex items-center gap-1.5 transition-colors`,"aria-label":"Agents",title:"Agents",children:[r.jsx(yN,{className:"w-6 h-6 shrink-0"}),r.jsx("span",{children:"Agents"}),l>0&&r.jsx("span",{className:"font-mono text-xs leading-none bg-white/10 text-white/55 px-1.5 py-0.5 rounded tabular-nums border border-white/10",title:`${l} configured agent${l===1?"":"s"}`,children:l}),s>0&&r.jsxs("span",{className:"inline-flex items-center gap-0.5 font-mono text-xs leading-none bg-red-500/20 text-red-300 px-1.5 py-0.5 rounded tabular-nums border border-red-400/30",title:`${s} need${s===1?"s":""} attention`,children:[r.jsx(_u,{className:"w-3 h-3 shrink-0"}),s]})]})]})]})}function TN(){const[n,l]=b.useState([]),[s,u]=b.useState(0),[d,f]=b.useState(!1),[m,x]=b.useState([]),[y,v]=b.useState({status:"loading"}),w=b.useCallback(()=>{H2().then(({agents:E,issueCount:$})=>{l(E),u($)}).catch(console.error),nv().then(E=>f(E.connected)).catch(()=>f(!1)),av().then(E=>v({status:"ready",data:E})).catch(()=>v({status:"unavailable"}))},[]),j=b.useCallback(()=>oS().then(x).catch(()=>{}),[]);b.useEffect(()=>{w();const E=setInterval(w,ay);return()=>clearInterval(E)},[w]),b.useEffect(()=>{j();const E=setInterval(()=>void j(),ay);return()=>clearInterval(E)},[j]);const D=m.length,X=n.length;return r.jsxs(r.Fragment,{children:[r.jsx(xN,{}),r.jsxs("div",{className:"relative z-10 min-h-screen flex flex-col",children:[r.jsx(RN,{openHumanActionCount:D,agentCount:X,agentIssueCount:s,capacity:y}),r.jsx("main",{className:"flex-1 flex overflow-hidden",children:r.jsxs($b,{children:[r.jsx(Ll,{path:"/",element:r.jsx(wy,{to:"/issues",replace:!0})}),r.jsx(Ll,{path:"/issues",element:r.jsx(jj,{agents:n,humanActions:m,onHumanActionsChanged:j})}),r.jsx(Ll,{path:"/issues/:issueId",element:r.jsx(CN,{agents:n,onHumanActionsChanged:j})}),r.jsx(Ll,{path:"/agents",element:r.jsx(HS,{agents:n,agentDeckOnline:d,onRefresh:w})}),r.jsx(Ll,{path:"/reports/execution",element:r.jsx(Mj,{})}),r.jsx(Ll,{path:"*",element:r.jsx(pN,{})})]})})]})]})}function ON(){return typeof document>"u"?Promise.resolve():document.fonts.load('13px "Monaco"').then(()=>{}).catch(()=>{})}ON();H0.createRoot(document.getElementById("root")).render(r.jsx(b.StrictMode,{children:r.jsx(f1,{children:r.jsx(TN,{})})}));