wicked-crew 0.16.12 → 0.16.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -1
- package/dist/api/chat-history.d.ts +6 -0
- package/dist/api/chat-history.d.ts.map +1 -1
- package/dist/api/chat-history.js +21 -0
- package/dist/api/chat-history.js.map +1 -1
- package/dist/api/chat-proposals.d.ts +61 -6
- package/dist/api/chat-proposals.d.ts.map +1 -1
- package/dist/api/chat-proposals.js +252 -24
- package/dist/api/chat-proposals.js.map +1 -1
- package/dist/api/routes.d.ts +14 -2
- package/dist/api/routes.d.ts.map +1 -1
- package/dist/api/routes.js +119 -9
- package/dist/api/routes.js.map +1 -1
- package/dist/api/run-timing-index.d.ts +18 -0
- package/dist/api/run-timing-index.d.ts.map +1 -1
- package/dist/api/run-timing-index.js +34 -0
- package/dist/api/run-timing-index.js.map +1 -1
- package/dist/api/server.d.ts.map +1 -1
- package/dist/api/server.js +100 -1
- package/dist/api/server.js.map +1 -1
- package/dist/apps/spec.d.ts +3009 -0
- package/dist/apps/spec.d.ts.map +1 -0
- package/dist/apps/spec.js +870 -0
- package/dist/apps/spec.js.map +1 -0
- package/dist/cli/index.js +3 -3
- package/dist/cli/index.js.map +1 -1
- package/dist/core/run-boot-resume.d.ts +4 -1
- package/dist/core/run-boot-resume.d.ts.map +1 -1
- package/dist/core/run-boot-resume.js +6 -1
- package/dist/core/run-boot-resume.js.map +1 -1
- package/dist/editors/csp.d.ts +24 -4
- package/dist/editors/csp.d.ts.map +1 -1
- package/dist/editors/csp.js +35 -8
- package/dist/editors/csp.js.map +1 -1
- package/dist/editors/routes.d.ts +4 -1
- package/dist/editors/routes.d.ts.map +1 -1
- package/dist/editors/routes.js +30 -3
- package/dist/editors/routes.js.map +1 -1
- package/dist/editors/webrtc-guard.d.ts +94 -0
- package/dist/editors/webrtc-guard.d.ts.map +1 -0
- package/dist/editors/webrtc-guard.js +506 -0
- package/dist/editors/webrtc-guard.js.map +1 -0
- package/dist/interactive/bridge-pool.d.ts +11 -2
- package/dist/interactive/bridge-pool.d.ts.map +1 -1
- package/dist/interactive/bridge-pool.js +10 -1
- package/dist/interactive/bridge-pool.js.map +1 -1
- package/dist/interactive/doc-binding.d.ts +156 -0
- package/dist/interactive/doc-binding.d.ts.map +1 -0
- package/dist/interactive/doc-binding.js +277 -0
- package/dist/interactive/doc-binding.js.map +1 -0
- package/dist/interactive/doc-delete-routes.d.ts +3 -0
- package/dist/interactive/doc-delete-routes.d.ts.map +1 -1
- package/dist/interactive/doc-delete-routes.js +4 -0
- package/dist/interactive/doc-delete-routes.js.map +1 -1
- package/dist/interactive/draft-events.d.ts +89 -3
- package/dist/interactive/draft-events.d.ts.map +1 -1
- package/dist/interactive/draft-events.js +438 -27
- package/dist/interactive/draft-events.js.map +1 -1
- package/dist/interactive/edit-events.d.ts +2 -0
- package/dist/interactive/edit-events.d.ts.map +1 -1
- package/dist/interactive/edit-events.js +11 -0
- package/dist/interactive/edit-events.js.map +1 -1
- package/dist/interactive/proposal-create.d.ts +143 -0
- package/dist/interactive/proposal-create.d.ts.map +1 -0
- package/dist/interactive/proposal-create.js +318 -0
- package/dist/interactive/proposal-create.js.map +1 -0
- package/dist/interactive/proxy-routes.d.ts +60 -3
- package/dist/interactive/proxy-routes.d.ts.map +1 -1
- package/dist/interactive/proxy-routes.js +209 -3
- package/dist/interactive/proxy-routes.js.map +1 -1
- package/dist/interactive/source-packet.d.ts +126 -0
- package/dist/interactive/source-packet.d.ts.map +1 -0
- package/dist/interactive/source-packet.js +482 -0
- package/dist/interactive/source-packet.js.map +1 -0
- package/dist/studio/assets/{index-C_UIgTiy.js → index-u4O_7N-b.js} +1 -1
- package/dist/studio/editors/wicked-deck/editor.json +1 -1
- package/dist/studio/editors/wicked-deck/index.html +1 -1
- package/dist/studio/editors/wicked-doc/editor.json +1 -1
- package/dist/studio/editors/wicked-doc/index.html +1 -1
- package/dist/studio/editors/wicked-insights/editor.json +1 -1
- package/dist/studio/editors/wicked-insights/index.html +1 -1
- package/dist/studio/editors/wicked-page/editor.json +1 -1
- package/dist/studio/editors/wicked-page/index.html +1 -1
- package/dist/studio/editors/wicked-video/editor.json +1 -1
- package/dist/studio/editors/wicked-video/index.html +1 -1
- package/dist/studio/index.html +1 -1
- package/dist/studio/testid-inventory.json +1 -1
- package/endpoint-manifest.json +1 -1
- package/package.json +4 -3
|
@@ -943,7 +943,7 @@ ${n.join(`
|
|
|
943
943
|
`),l=`${String(o.length).length+1}ch`;return a.jsxs("div",{className:"flex-1 min-h-0 flex flex-col",children:[s&&a.jsx(aSe,{text:`showing first 512 KB — open externally for the full file (${Xre(r)} total)`}),a.jsx("div",{className:"flex-1 overflow-auto",children:a.jsx("pre",{className:"m-0 p-3 min-w-max",style:iSe,children:o.map((c,u)=>a.jsxs("div",{className:"flex",children:[a.jsx("span",{className:"shrink-0 text-right pr-3 select-none","aria-hidden":"true",style:{color:"var(--ink-dim)",width:l,userSelect:"none"},children:u+1}),a.jsx("span",{style:{color:URt(c)?"var(--ink-dim)":"var(--ink-body)"},children:c})]},u))})})]})}function YRt({cause:e,onClose:t}){const n=e==="no-repo"?"This run had no repository attached — nothing was produced to review.":"This run’s workdir no longer exists.",r=e==="no-repo"?"The run executed without a workdir, so there is no worktree to diff. Its captured unit transcripts are the record of what it did.":"The worktree was cleaned up after the run ended. The captured unit transcripts and evidence remain the durable record — and the run branch (wicked/<run id>) still holds the committed work; a daemon with the wave-6 diff route serves that branch here instead of this refusal (upgrade wicked-crew).",s=e==="no-repo"?"Attach a repository at launch to make future runs reviewable — for this one, review the captured transcripts on the run page.":"Review the captured transcripts on the run page, or the run branch in the repository.";return a.jsxs("div",{"data-testid":"diff-named-cause","data-cause":e,className:"m-4 rounded-lg p-4 flex flex-col gap-2 self-start",style:{background:"var(--surface-raised)",border:"1px solid var(--surface-raised)"},children:[a.jsx("p",{className:"text-xs font-semibold font-mono",style:{color:"var(--ink-muted)"},children:n}),a.jsx("p",{className:"text-xs",style:{color:"var(--ink-muted)"},children:r}),a.jsx("button",{type:"button","data-testid":"diff-cause-remediation",onClick:t,className:"self-start text-xs font-mono underline transition-opacity hover:opacity-70",style:{color:"var(--accent)",background:"none",border:"none",padding:0,cursor:"pointer"},children:s})]})}function Qre({source:e}){const t=e==="branch";return a.jsx("p",{"data-testid":"diff-baseline-note","data-source":e??"worktree",className:"wk-viewer-baseline shrink-0",children:t?"Showing the work the run committed on its branch.":"Showing uncommitted changes only; committed work is not shown here."})}function XRt({diff:e,narrowed:t,onRetry:n,onClose:r}){if(e===null||e.state==="loading")return a.jsx(lSe,{what:"the changes"});if(e.state==="timeout")return a.jsxs("div",{"data-testid":"diff-error",className:"wk-viewer-state",children:[a.jsx("p",{className:"wk-viewer-state-line",children:"Couldn't load the diff yet: it is taking longer than usual. It still shows here when it arrives."}),a.jsx("button",{type:"button","data-testid":"diff-retry",onClick:n,className:"wk-btn wk-btn--secondary wk-btn--sm",children:"Retry"})]});if(e.state==="cause")return a.jsx(YRt,{cause:e.cause,onClose:r});if(e.state==="error")return a.jsx(oSe,{message:e.message,what:"the changes"});const{diff:s,truncated:i}=e.data,o=TAe(e.data);if(s==="")return a.jsxs("div",{className:"flex-1 min-h-0 flex flex-col",children:[a.jsx(Qre,{source:o}),a.jsx("p",{"data-testid":"viewer-clean-tree",className:"wk-viewer-state wk-viewer-state-line",children:t?"No changes to this file.":o==="branch"?"This run changed no files.":"No uncommitted changes."})]});const l=WRt(s);return a.jsxs("div",{className:"flex-1 min-h-0 flex flex-col",children:[a.jsx(Qre,{source:o}),i&&a.jsx(aSe,{text:"diff truncated at 1 MB — narrow to a single file for the rest"}),a.jsx("div",{className:"flex-1 overflow-auto",children:a.jsx("pre",{className:"m-0 p-3 min-w-max",style:iSe,children:l.map((c,u)=>a.jsx("div",{"data-testid":GRt[c.kind],className:"px-1",style:KRt[c.kind],children:c.text===""?" ":c.text},u))})})]})}function QRt({model:e}){const t=e.units.filter(r=>r.filesRead.length>0),n=Mf();return a.jsxs("div",{"data-testid":"data-used",className:"flex flex-col gap-2 text-xs",children:[t.length===0?a.jsxs("p",{style:{color:"var(--ink-dim)"},"data-testid":"data-used-empty",children:["No files-read captured yet — populated from claude ",a.jsx("code",{children:"tool_use"})," blocks via"," ",a.jsx("code",{children:"dataUsed"}),"."]}):a.jsx("ul",{className:"flex flex-col gap-2",children:t.map(r=>a.jsxs("li",{"data-testid":"data-used-unit","data-ord":r.ord,children:[a.jsxs("p",{className:"font-semibold font-mono",style:{color:"var(--ink-muted)"},children:["unit #",r.ord,r.assignedCli?` · ${r.assignedCli}`:""]}),a.jsx("ul",{className:"mt-0.5 flex flex-col gap-0.5",children:r.filesRead.map(s=>a.jsx("li",{className:"truncate font-mono",style:{color:"var(--ink-muted)"},title:n(s),children:n(s)},s))})]},r.ord))}),a.jsx("p",{"data-testid":"data-used-recall-disabled",className:"rounded p-1.5 font-mono",style:{border:"1px dashed var(--surface-raised)",color:"var(--ink-dim)"},children:"memory / knowledge recall: disabled (pending core-ts binding)"})]})}function JRt({routing:e}){return e?e.method==="council"?e.seated===1?a.jsxs("p",{className:"text-xs font-mono",style:{color:"var(--ink-muted)"},"data-testid":"routing-provenance","data-seats":"1",children:[a.jsx("span",{className:"font-medium",style:{color:"var(--ink-muted)"},children:"Council:"})," ",e.winner," — single seat, no vote held"]}):a.jsxs("p",{className:"text-xs font-mono",style:{color:"var(--ink-muted)"},"data-testid":"routing-provenance",children:[a.jsx("span",{className:"font-medium",style:{color:"var(--ink-muted)"},children:"Council:"})," ",e.winner," won · ",e.agreement_pct,"% agreement · ",sSe(e)," · ",e.dissent," dissent",Jq(e)&&a.jsx("span",{style:{color:"var(--status-gate)"},children:" · quorum lost"})]}):e.method==="degraded"?a.jsxs("p",{className:"text-xs font-mono",style:{color:"var(--status-gate)"},"data-testid":"routing-provenance",children:[a.jsx("span",{className:"font-medium",children:"Degraded:"})," ",e.reason]}):e.method==="tool"?a.jsxs("p",{className:"text-xs font-mono",style:{color:"var(--ink-dim)"},"data-testid":"routing-provenance",children:[a.jsx("span",{className:"font-medium",children:"Tool:"})," direct command — no council"]}):e.method==="teamed"?a.jsxs("p",{className:"text-xs font-mono",style:{color:"var(--ink-muted)"},"data-testid":"routing-provenance","data-method":"teamed",children:[a.jsx("span",{className:"font-medium",children:"Routed:"})," ",e.winner," — team model, no council"]}):e.method==="evaluator_distinct"?a.jsxs("p",{className:"text-xs font-mono",style:{color:"var(--accent)"},"data-testid":"routing-provenance",children:[a.jsx("span",{className:"font-medium",children:"Evaluator-distinct:"})," ",e.winner," (was ",e.was,")"]}):null:null}function Jre(e){if(!e.combined){const t=[];return e.hasDeterministicFloor&&!e.deterministicPass&&t.push("deterministic floor"),e.evaluatorPass===!1&&t.push("evaluator (2nd pass)"),t.length===0&&e.agentVerdict!==null&&t.push("agent judge"),t.length>0?t.join(" + "):"governance"}return e.evaluatorPass===!0&&e.evaluatorPolicies.length>0?"evaluator (2nd pass)":e.agentVerdict!==null?"agent judge":e.hasDeterministicFloor?"deterministic floor":"ungated"}function ZRt({model:e}){const{units:t,session:n,pendingGate:r}=e,s=t.filter(c=>c.routing!==null||c.denialReason!==null||c.gateEvals.length>0),i=r!==null?r.ord+1:n.status==="executing"?n.unit_ix:null,o=(()=>{if(i===null)return!1;const c=n.human_confirm;return c==="all"?!0:c==="none"?!1:c.before===i})(),l={background:"var(--surface-rail)",border:"1px solid var(--surface-raised)",borderRadius:"6px",padding:"8px"};return a.jsx("div",{"data-testid":"decisions-ledger",className:"flex flex-col gap-2",children:s.length===0&&r===null?a.jsx("p",{className:"text-xs font-mono",style:{color:"var(--ink-dim)"},children:"No governed decisions recorded yet."}):a.jsxs("ol",{className:"flex flex-col gap-2",children:[s.map(c=>a.jsxs("li",{"data-testid":"ledger-row","data-ord":c.ord,style:l,children:[a.jsxs("div",{className:"flex items-center justify-between mb-1",children:[a.jsxs("div",{className:"flex items-center gap-1",children:[a.jsxs("span",{className:"font-semibold text-xs font-mono",style:{color:"var(--ink-high)"},children:["unit #",c.ord]}),(c.role==="creator"||c.role==="evaluator")&&a.jsx("span",{"data-testid":"role-badge",className:"text-xs font-mono px-1 rounded",style:{background:c.role==="evaluator"?"var(--accent-subtle)":"var(--status-run-dim)",color:c.role==="evaluator"?"var(--accent)":"var(--status-run)"},children:c.role==="creator"?"Creator":"Evaluator"}),c.gate!=null&&c.gate!=="auto"&&a.jsx("span",{"data-testid":"gate-badge",className:"text-xs font-mono px-1 rounded",style:{background:"var(--status-gate-dim)",color:"var(--status-gate)"},children:typeof c.gate=="string"&&c.gate==="human_confirm"||typeof c.gate=="object"&&"human_confirm"in c.gate?"HUMAN-CONFIRM":"CONDITIONAL"}),c.attempts.length>1&&a.jsxs("span",{"data-testid":"rework-badge",className:"text-xs font-mono px-1 rounded",style:{background:"var(--status-fail-dim)",color:"var(--status-fail)"},children:["×",c.attempts.length]})]}),a.jsx("span",{className:"text-xs font-mono",style:{color:"var(--ink-dim)"},children:c.resolved?c.stage:"resolving…"})]}),a.jsx(JRt,{routing:c.routing}),c.skillRef&&a.jsxs("p",{className:"text-xs font-mono",style:{color:"var(--ink-dim)"},children:["skill: ",a.jsx("span",{style:{color:"var(--ink-muted)"},children:c.skillRef})]}),c.gateEvals.map((u,d)=>a.jsxs("div",{className:"mt-1 rounded p-1.5",style:{background:"var(--surface-rail)",border:"1px solid var(--surface-raised)"},children:[a.jsxs("p",{className:"text-xs font-mono",children:[a.jsx("span",{className:"font-semibold",style:{color:u.combined?"var(--status-run)":"var(--status-fail)"},children:u.combined?"ALLOW":"DENY"}),a.jsx("span",{style:{color:"var(--ink-muted)"},children:u.combined&&Jre(u)==="ungated"&&!u.criterion?" · allowed — no policy applied":a.jsxs(a.Fragment,{children:[" · ",Jre(u),u.criterion?` · ${u.criterion}`:" · no criterion recorded"]})})]}),u.hasDeterministicFloor&&a.jsxs("p",{className:"text-xs font-mono",style:{color:"var(--ink-dim)"},children:["deterministic: ",u.deterministicPass?"pass":"fail"]}),u.agentVerdict!==null&&a.jsxs("p",{className:"text-xs font-mono",style:{color:"var(--ink-dim)"},children:["agent: ",u.agentVerdict,u.agentReasoning?` — ${u.agentReasoning}`:""]}),u.judgeSkipped!==null&&a.jsxs("p",{"data-testid":"ledger-judge-skipped",className:"text-xs font-mono",style:{color:"var(--status-gate)"},children:["judge skipped — ",u.judgeSkipped]}),u.evaluatorPass!==null&&!(u.evaluatorPass&&u.evaluatorPolicies.length===0)&&a.jsxs("p",{className:"text-xs font-mono",style:{color:"var(--ink-dim)"},children:["evaluator: ",u.evaluatorPass?"pass":"fail",u.evaluatorPolicies.length>0?` — ${u.evaluatorPolicies.join(", ")}`:""]}),u.denialReason&&a.jsxs("p",{className:"text-xs font-mono",style:{color:"var(--status-fail)"},children:["reason: ",u.denialReason]})]},d)),c.denialReason&&c.gateEvals.length===0&&a.jsxs("p",{className:"mt-1 text-xs font-mono",style:{color:"var(--status-fail)"},"data-testid":"ledger-denial",children:["denied: ",c.denialReason]})]},c.ord)),r!==null&&a.jsxs("li",{"data-testid":"ledger-pending",className:"rounded p-2 text-xs font-mono",style:{background:"var(--status-gate-dim)",border:"1px dashed var(--status-gate)",color:"var(--status-gate)"},children:[a.jsx("span",{className:"font-semibold",children:"PENDING"})," · awaiting human · before unit #",r.ord,r.prompt?` — ${r.prompt}`:""]}),i!==null&&a.jsxs("li",{"data-testid":"ledger-next",className:"rounded p-2 text-xs font-mono",style:{border:"1px dashed var(--surface-raised)",color:"var(--ink-dim)"},children:[o?"next decision point · unit #":"next unit · unit #",i,o?" (human-confirm gate)":""]})]})})}function cSe({decision:e}){const t={allow:{bg:"var(--status-run-dim)",color:"var(--status-run)"},deny:{bg:"var(--status-fail-dim)",color:"var(--status-fail)"},allow_with_conditions:{bg:"var(--status-gate-dim)",color:"var(--status-gate)"}},n={allow:"ALLOW",deny:"DENY",allow_with_conditions:"ALLOW + OBLIGATIONS"},r=t[e];return a.jsx("span",{className:"inline-flex rounded px-1.5 py-0.5 text-xs font-semibold font-mono",style:{background:r.bg,color:r.color},children:n[e]})}function eTt({claim:e}){const[t,n]=k.useState(!1),r=new Date(e.evaluated_at*1e3).toLocaleTimeString();return a.jsxs("li",{className:"rounded p-2 text-xs",style:{background:"var(--surface-rail)",border:"1px solid var(--surface-raised)"},children:[a.jsxs("div",{className:"flex items-center justify-between gap-2",children:[a.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[a.jsx(cSe,{decision:e.decision}),a.jsx("span",{className:"font-mono truncate",style:{color:"var(--ink-muted)"},children:e.phase})]}),a.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[a.jsx("span",{className:"font-mono",style:{color:"var(--ink-dim)"},children:r}),(e.criteria||e.obligations.length>0||e.policy_ids.length>0)&&a.jsx("button",{type:"button",onClick:()=>n(s=>!s),className:"text-xs",style:{color:"var(--ink-dim)"},"aria-label":t?"Collapse":"Expand",children:t?"▲":"▼"})]})]}),t&&a.jsxs("div",{className:"mt-2 flex flex-col gap-1.5 text-xs font-mono",style:{color:"var(--ink-muted)"},children:[e.criteria&&a.jsxs("p",{children:[a.jsx("span",{className:"font-semibold",style:{color:"var(--ink-muted)"},children:"criteria: "}),e.criteria]}),e.policy_ids.length>0&&a.jsxs("div",{children:[a.jsx("p",{className:"font-semibold",style:{color:"var(--ink-muted)"},children:"policies matched:"}),a.jsx("ul",{className:"list-inside list-disc pl-1",children:e.policy_ids.map(s=>a.jsx("li",{children:s},s))})]}),e.obligations.length>0&&a.jsxs("div",{children:[a.jsx("p",{className:"font-semibold",style:{color:"var(--ink-muted)"},children:"obligations:"}),a.jsx("ul",{className:"list-inside list-disc pl-1",children:e.obligations.map((s,i)=>a.jsx("li",{children:s},i))})]}),a.jsxs("p",{children:["evaluator: ",a.jsx("span",{children:e.evaluator_identity})," · ","claim: ",a.jsx("span",{children:e.claim_id})]})]})]})}function tTt({claim:e}){const[t,n]=k.useState(!1),r=new Date(e.evaluatedAt*1e3).toLocaleTimeString(),s=e.rules.length>0||e.obligations.length>0||e.policyIds.length>0;return a.jsxs("li",{"data-testid":"conformance-claim",className:"rounded p-2 text-xs",style:{background:"var(--surface-rail)",border:"1px solid var(--surface-raised)"},children:[a.jsxs("div",{className:"flex items-center justify-between gap-2",children:[a.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[a.jsx(cSe,{decision:e.decision}),e.advisory&&a.jsx("span",{className:"inline-flex rounded px-1.5 py-0.5 text-xs font-mono",style:{background:"var(--status-gate-dim)",color:"var(--status-gate)"},title:"Blocked and audited, but not unit-fatal: a boundary READ deny leaks nothing.",children:"advisory"}),a.jsx("span",{className:"font-mono truncate",style:{color:"var(--ink-muted)"},children:e.phase})]}),a.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[a.jsx("span",{className:"font-mono",style:{color:"var(--ink-dim)"},children:r}),s&&a.jsx("button",{type:"button",onClick:()=>n(i=>!i),className:"text-xs",style:{color:"var(--ink-dim)"},"aria-label":t?"Collapse":"Expand",children:t?"▲":"▼"})]})]}),e.rules.length>0&&a.jsx("ul",{className:"mt-1.5 flex flex-col gap-1",children:e.rules.map(i=>a.jsxs("li",{"data-testid":"conformance-rule-citation",className:"rounded px-1.5 py-1 text-xs font-mono",style:{background:"var(--surface-base)",border:"1px solid var(--surface-raised)",color:"var(--ink-muted)"},children:[a.jsx("span",{className:"font-semibold",children:i.ruleId}),a.jsxs("span",{style:{color:"var(--ink-dim)"},children:[" · ",i.severity," · "]}),i.statement]},`${i.ruleId}-${i.statement}`))}),t&&a.jsxs("div",{className:"mt-2 flex flex-col gap-1.5 text-xs font-mono",style:{color:"var(--ink-muted)"},children:[e.policyIds.length>0&&a.jsxs("div",{children:[a.jsx("p",{className:"font-semibold",children:"policies matched:"}),a.jsx("ul",{className:"list-inside list-disc pl-1",children:e.policyIds.map(i=>a.jsx("li",{children:i},i))})]}),e.obligations.length>0&&a.jsxs("div",{children:[a.jsx("p",{className:"font-semibold",children:"obligations (verbatim):"}),a.jsx("ul",{className:"list-inside list-disc pl-1",children:e.obligations.map((i,o)=>a.jsx("li",{children:i},o))})]}),a.jsxs("p",{children:["evaluator: ",a.jsx("span",{children:e.evaluator})," · ","claim: ",a.jsx("span",{children:e.claimId})]})]})]})}function nTt(e){const t=[];for(const n of e.units){for(const r of n.gateEvals)r.combined||t.push({ord:n.ord,source:"gate",detail:r.denialReason??r.criterion??"gate denied"});n.denialReason!==null&&!n.gateEvals.some(r=>!r.combined&&r.denialReason===n.denialReason)&&t.push({ord:n.ord,source:"unit",detail:n.denialReason});for(const r of n.hookFires)r.decision==="deny"&&t.push({ord:n.ord,source:"hook",detail:`${r.toolName} denied${r.denyingPolicy!==null?` by ${r.denyingPolicy}`:""}`})}return t}function rTt(e){const t=[];for(const n of e.units)n.governanceUnenforced!==null&&t.push({ord:n.ord,cli:n.governanceUnenforced.cli,reason:n.governanceUnenforced.reason});return t}function sTt(e,t){const n=rTt(t),r=(e==null?void 0:e.enforcement.unenforced)??[];if(n.length>0||r.length>0){const s=new Map;for(const i of r)s.set(i.ord,{ord:i.ord,cli:i.cli,reason:i.reason});for(const i of n)s.has(i.ord)||s.set(i.ord,i);return{kind:"unenforced",rows:[...s.values()].sort((i,o)=>i.ord-o.ord)}}if(e===void 0)return null;if(e.guardrailed)return{kind:"guardrailed",detail:e.summary};switch(e.enforcement.status){case"enforced":return{kind:"enforced-not-clean",detail:e.summary};case"ungoverned":return{kind:"ungoverned",detail:e.enforcement.reason};default:return{kind:"unverifiable",detail:e.enforcement.reason}}}function n_({banner:e}){if(e.kind==="unenforced")return a.jsxs("div",{"data-testid":"governance-enforcement","data-status":"unenforced",className:"rounded p-2 flex flex-col gap-1",style:{background:"var(--status-fail-dim)",border:"1px solid var(--status-fail-dim)"},children:[a.jsx("p",{className:"text-xs font-mono font-semibold",style:{color:"var(--status-fail)"},children:"UNENFORCED — governed unit(s) ran with unchecked tool calls"}),a.jsx("ul",{className:"flex flex-col gap-0.5",children:e.rows.map(r=>a.jsxs("li",{"data-testid":"governance-unenforced-unit",className:"text-xs font-mono",style:{color:"var(--ink-muted)"},children:["unit #",r.ord," · ",r.cli," — ",r.reason]},r.ord))}),a.jsx("p",{className:"text-xs font-mono",style:{color:"var(--ink-dim)"},children:"This run is not guardrailed. Phase-boundary output gating still applied."})]});const n={unenforced:{label:"",bg:"",color:""},guardrailed:{label:"GUARDRAILED",bg:"var(--status-run-dim)",color:"var(--status-run)"},"enforced-not-clean":{label:"ENFORCED — DENIALS STAND",bg:"var(--status-gate-dim)",color:"var(--status-gate)"},ungoverned:{label:"UNGOVERNED",bg:"var(--surface-rail)",color:"var(--ink-muted)"},unverifiable:{label:"UNVERIFIED",bg:"var(--status-gate-dim)",color:"var(--status-gate)"}}[e.kind];return a.jsxs("div",{"data-testid":"governance-enforcement","data-status":e.kind,className:"rounded p-2 flex flex-col gap-0.5",style:{background:n.bg,border:"1px solid var(--surface-raised)"},children:[a.jsx("p",{className:"text-xs font-mono font-semibold",style:{color:n.color},children:n.label}),a.jsx("p",{className:"text-xs font-mono",style:{color:"var(--ink-muted)"},children:e.detail})]})}function r_(){return a.jsx("p",{"data-testid":"governance-coverage-boundary",className:"text-xs font-mono",style:{color:"var(--ink-dim)"},children:"Coverage boundary: deterministic per-tool-call guardrails (gate-hook injection) exist for claude seats only. A governed unit routed to any other CLI runs with phase-boundary output-gate coverage only — advisory relative to mid-flight tool-call blocking — and is reported UNENFORCED here, never guardrailed."})}function iTt({model:e}){const t=Bn(),[n,r]=k.useState(null),[s,i]=k.useState([]),[o,l]=k.useState(!0),[c,u]=k.useState(null),d=k.useRef(0),h=k.useRef(!1);k.useEffect(()=>(h.current=!0,()=>{h.current=!1}),[]);const f=k.useCallback(async()=>{const y=++d.current,w=()=>h.current&&d.current===y;l(!0),u(null);try{let b=null;try{const x=await Oe.getRunAcceptance(e.session.id);x!==null&&typeof x=="object"&&x.conformance!==void 0&&(b=x)}catch{b=null}if(!w())return;if(r(b),b===null){const{claims:x}=await Oe.listClaims();if(!w())return;i(x.filter(S=>S.scope===e.session.id||S.scope===`wicked-agent/${e.session.id}/shared`||S.scope.startsWith(`wicked-agent/${e.session.id}/unit/`)).sort((S,_)=>S.evaluated_at-_.evaluated_at))}else i([])}catch(b){w()&&u(b instanceof Error?b.message:String(b))}finally{w()&&l(!1)}},[e.session.id]);k.useEffect(()=>{f()},[f]);const p=a.jsx("button",{type:"button",onClick:()=>void f(),className:"self-start text-xs font-mono hover:underline",style:{color:"var(--ink-dim)"},children:"Refresh"});if(o)return a.jsx("p",{className:"text-xs font-mono",style:{color:"var(--ink-dim)"},children:"Loading governance claims…"});if(c)return a.jsxs("div",{className:"flex flex-col gap-1",children:[a.jsx("p",{className:"rounded px-2 py-1 text-xs font-mono",style:{background:"var(--status-fail-dim)",color:"var(--status-fail)",border:"1px solid var(--status-fail-dim)"},children:c}),p]});const m=sTt(n==null?void 0:n.conformance,e);if(n!==null&&n.conformance!==void 0){const y=n.conformance;return a.jsxs("div",{className:"flex flex-col gap-2",children:[m!==null&&a.jsx(n_,{banner:m}),a.jsxs("p",{"data-testid":"acceptance-gate-line",className:"text-xs font-mono",style:{color:"var(--ink-muted)"},children:[a.jsxs("span",{className:"font-semibold",style:{color:n.gate.satisfied?"var(--status-run)":"var(--status-fail)"},children:["QE acceptance: ",n.gate.satisfied?"SATISFIED":"DENIED"]})," — ",t(n.gate.reason)]}),!y.claimsAvailable&&a.jsxs("p",{"data-testid":"governance-claims-unavailable",className:"rounded px-2 py-1 text-xs font-mono",style:{background:"var(--status-gate-dim)",color:"var(--status-gate)"},children:["Conformance claims unreadable",y.claimsError!==void 0?`: ${y.claimsError}`:""," — not shown as clean."]}),y.claims.length>0?a.jsxs(a.Fragment,{children:[a.jsxs("p",{className:"text-xs font-mono",style:{color:"var(--ink-dim)"},children:[y.claims.length," decision",y.claims.length!==1?"s":"",y.denials>0&&a.jsxs("span",{className:"ml-1 font-semibold",style:{color:"var(--status-fail)"},children:["· ",y.denials," denied"]}),y.advisoryDenials>0&&a.jsxs("span",{className:"ml-1",style:{color:"var(--status-gate)"},children:["· ",y.advisoryDenials," advisory"]})]}),a.jsx("ol",{className:"flex flex-col gap-1.5",children:y.claims.map(w=>a.jsx(tTt,{claim:w},w.claimId))})]}):y.claimsAvailable&&a.jsx("p",{className:"text-xs font-mono",style:{color:"var(--ink-dim)"},children:"No conformance claims scoped to this run."}),a.jsx(r_,{}),p]})}if(s.length===0){const y=nTt(e);return y.length>0?a.jsxs("div",{className:"flex flex-col gap-2",children:[m!==null&&a.jsx(n_,{banner:m}),a.jsx("p",{"data-testid":"governance-wire-empty",className:"text-xs font-mono",style:{color:"var(--ink-dim)"},children:"This panel reads the conformance store’s claims wire, which holds no claims scoped to this run."}),a.jsxs("div",{"data-testid":"governance-run-record",className:"flex flex-col gap-1.5",children:[a.jsx("p",{className:"text-xs font-mono",style:{color:"var(--ink-muted)"},children:"The run’s own decision record DOES show governance activity — the full gate record is in the Decisions panel:"}),a.jsx("ul",{className:"flex flex-col gap-1",children:y.map((w,b)=>a.jsxs("li",{"data-testid":"governance-run-decision",className:"rounded p-2 text-xs font-mono",style:{background:"var(--surface-rail)",border:"1px solid var(--surface-raised)"},children:[a.jsx("span",{className:"inline-flex rounded px-1.5 py-0.5 text-xs font-semibold font-mono mr-2",style:{background:"var(--status-fail-dim)",color:"var(--status-fail)"},children:"DENY"}),a.jsxs("span",{style:{color:"var(--ink-muted)"},children:["unit #",w.ord," · ",w.detail]})]},b))})]}),a.jsx(r_,{}),p]}):a.jsxs("div",{className:"flex flex-col gap-1",children:[m!==null&&a.jsx(n_,{banner:m}),a.jsx("p",{className:"text-xs font-mono",style:{color:"var(--ink-dim)"},children:"No governance claims recorded for this run."}),a.jsx("p",{className:"text-xs font-mono",style:{color:"var(--ink-dim)"},children:"Claims appear once wicked-core runs governance decisions for a run."}),a.jsx(r_,{}),p]})}const g=s.filter(y=>y.decision==="deny").length,v=s.filter(y=>y.decision==="allow_with_conditions").length;return a.jsxs("div",{className:"flex flex-col gap-2",children:[m!==null&&a.jsx(n_,{banner:m}),a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("p",{className:"text-xs font-mono",style:{color:"var(--ink-dim)"},children:[s.length," decision",s.length!==1?"s":"",g>0&&a.jsxs("span",{className:"ml-1 font-semibold",style:{color:"var(--status-fail)"},children:["· ",g," denied"]}),v>0&&a.jsxs("span",{className:"ml-1",style:{color:"var(--status-gate)"},children:["· ",v," with obligations"]})]}),p]}),a.jsx("ol",{className:"flex flex-col gap-1.5",children:s.map(y=>a.jsx(eTt,{claim:y},y.claim_id))}),a.jsx(r_,{})]})}const aTt=St(e=>({entries:[],seq:0,record:t=>e(n=>{const r=n.seq+1;return{seq:r,entries:[...n.entries,{...t,seq:r,ts:Date.now()}]}})})),oTt={approve:{label:"Approved",color:"var(--status-run)"},"approve-with-steer":{label:"Approved + steered",color:"var(--status-gate)"},reject:{label:"Rejected",color:"var(--status-fail)"},cancel:{label:"Cancelled run",color:"var(--ink-muted)"},reassign:{label:"Reassigned",color:"var(--status-gate)"},"request-changes":{label:"Request changes",color:"var(--status-fail)"}};function lTt({runId:e}){const t=aTt(n=>n.entries).filter(n=>n.runId===e);return t.length===0?a.jsx("p",{"data-testid":"steering-timeline",className:"text-xs font-mono",style:{color:"var(--ink-dim)"},children:"No interventions recorded this session. Operator gate actions (approve / reject / amend) appear here as they happen."}):a.jsxs("div",{className:"flex flex-col gap-2",children:[a.jsx("p",{"data-testid":"steering-scope-note",className:"text-xs font-mono",style:{color:"var(--ink-dim)"},children:"Client-recorded, this session only — daemon keeps no per-action history, cleared on reload."}),a.jsx("ol",{"data-testid":"steering-timeline",className:"flex flex-col gap-2",children:t.map(n=>{const r=oTt[n.action];return a.jsxs("li",{"data-testid":"steering-entry",className:"rounded p-2 text-xs",style:{background:"var(--surface-rail)",border:"1px solid var(--surface-raised)"},children:[a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsx("span",{className:"font-semibold font-mono",style:{color:r.color},children:r.label}),a.jsx("span",{className:"font-mono",style:{color:"var(--ink-dim)"},children:typeof n.ord=="number"?`before unit #${n.ord}`:"—"})]}),n.amend&&a.jsxs("p",{className:"mt-1 whitespace-pre-wrap rounded p-1.5 font-mono",style:{background:"var(--surface-rail)",color:"var(--ink-muted)"},children:[a.jsx("span",{className:"font-medium",style:{color:"var(--ink-high)"},children:"amended instruction:"})," ",n.amend]}),a.jsxs("p",{className:"mt-1 text-xs font-mono",style:{color:"var(--ink-dim)"},children:["effect: ",n.action==="approve-with-steer"?"steers the next unit":n.action==="approve"?"run advances":n.action==="reject"?"run rejected":n.action==="reassign"?`retry moved to ${n.cli??"another seat"}`:n.action==="request-changes"?"rewound to creator phase":"run cancelled"," ","— as recorded"]})]},n.seq)})})]})}const cTt=e=>e.slice(0,8);function Zre({label:e,runId:t,testId:n,onSelectRun:r}){const s=`${e} ${cTt(t)}`;return r===void 0?a.jsx("span",{"data-testid":n,"data-run-id":t,style:{color:"var(--accent)"},children:s}):a.jsx("button",{type:"button","data-testid":n,"data-run-id":t,onClick:()=>r(t),className:"underline transition-opacity hover:opacity-70",style:{background:"none",border:"none",padding:0,cursor:"pointer",color:"var(--accent)",font:"inherit"},title:`Open run ${t}`,children:s})}function uTt({provenance:e,retryOf:t,retriedAs:n,onSelectRun:r,testId:s}){const i=e!=null&&e.state==="known",o=t??(i&&e.retryOf!==void 0?e.retryOf:void 0);return a.jsxs("div",{"data-testid":s,className:"flex flex-wrap items-center gap-x-1.5 gap-y-0.5 text-xs",style:{color:"var(--ink-muted)"},children:[i?a.jsxs(a.Fragment,{children:[a.jsxs("span",{children:["launched by ",e.actorId]}),a.jsx("span",{className:"rounded px-1 py-px font-mono ",style:{fontSize:"var(--text-2xs)",background:"var(--surface-raised)",color:"var(--ink-muted)"},children:e.actorKind}),e.channel==="unrecorded"?a.jsx("span",{style:{color:"var(--ink-dim)"},children:"launch channel not recorded"}):a.jsxs("span",{children:["via ",e.channel]})]}):a.jsx("span",{style:{color:"var(--ink-dim)"},children:"launch not recorded"}),o!==void 0&&a.jsxs(a.Fragment,{children:[a.jsx("span",{"aria-hidden":!0,style:{color:"var(--ink-dim)"},children:"·"}),a.jsx(Zre,{label:"retry of",runId:o,testId:"lineage-retry-of",onSelectRun:r})]}),(n??[]).map(l=>a.jsxs("span",{className:"flex items-center gap-x-1.5",children:[a.jsx("span",{"aria-hidden":!0,style:{color:"var(--ink-dim)"},children:"·"}),a.jsx(Zre,{label:"retried as",runId:l,testId:"lineage-retried-as",onSelectRun:r})]},l))]})}const rx="0-19",uSe="plan_approval";function dTt(e,t,n){return e.find(r=>{const s=r.rule.trigger;return r.rule.action==="approve"&&r.rule.activeWhen==="always"&&s.kind==="gate"&&s.phase===uSe&&s.band===rx&&s.preset===n&&r.rule.scope.kind==="project"&&r.rule.scope.projectId===t})??null}function hTt(e,t){if(e.projectId===null||e.preset===null||e.band!==rx||e.highRisk===!0||e.landsDoctrine)return null;const n=dTt(t,e.projectId,e.preset);if(n!==null)return{kind:"trusted",order:n};const r=e.projectName??e.projectId,s=e.atPlanGate?" It also approves this run's open plan gate now.":"";return{kind:"offer",question:"Trust this route for low-risk runs like this",consequence:`Runs on ${r} from the ${e.preset} preset whose plan scores band ${rx} skip plan approval. The deliver gate stays manual, and every other gate still waits for you.${s}`,text:`Trust ${e.preset} runs on ${r} at band ${rx}: skip plan approval (deliver stays manual)`,rule:{scope:{kind:"project",projectId:e.projectId},trigger:{kind:"gate",phase:uSe,band:rx,preset:e.preset},action:"approve",activeWhen:"always"}}}function fTt(e,t,n){var i,o;const r=e.team_plan,s=e.project_id;return{projectId:typeof s=="string"&&s!==""&&s!=="default"?s:null,projectName:t,preset:typeof(r==null?void 0:r.preset)=="string"&&r.preset!==""?r.preset:null,band:typeof((i=r==null?void 0:r.accepted)==null?void 0:i.band)=="string"&&r.accepted.band!==""?r.accepted.band:null,highRisk:typeof((o=r==null?void 0:r.accepted)==null?void 0:o.high_risk)=="boolean"?r.accepted.high_risk:null,landsDoctrine:e.workflow_id==="steering-author",atPlanGate:n}}function pTt(e){const t=e.id,n=Gt(v=>v.gates[t]),r=typeof e.project_id=="string"?e.project_id:null,s=fn(v=>{var y;return r===null?null:((y=v.projects.find(w=>w.id===r))==null?void 0:y.name)??null}),[i,o]=k.useState(null),[l,c]=k.useState(null),[u,d]=k.useState(!1),[h,f]=k.useState(null);k.useEffect(()=>{o(null),c(null),f(null);let v=!1;return Ibe().then(({orders:y})=>{v||o(Array.isArray(y)?y:[])}).catch(()=>{v||o(null)}),()=>{v=!0}},[t]);const p=(n==null?void 0:n.gateKind)==="plan_approval"||/^\s*Approve plan rev\b/i.test((n==null?void 0:n.prompt)??""),m=k.useMemo(()=>i===null?null:hTt(fTt(e,s,p),i),[i,e,s,p]),g=k.useCallback(async()=>{if(!(m===null||m.kind!=="offer")){d(!0),f(null);try{const{order:v}=await Obe(m.text,m.rule);c(v),o(y=>[...y??[],v])}catch(v){f(v instanceof Error?v.message:String(v))}finally{d(!1)}}},[m]);return{receipt:m,made:l,busy:u,error:h,trust:g}}function mTt({session:e}){const{receipt:t,made:n,busy:r,error:s,trust:i}=pTt(e);return t===null?null:t.kind==="trusted"?a.jsxs("div",{"data-testid":n!==null?"trust-receipt-made":"trust-receipt-in-force",className:"flex gap-2 text-xs pt-1",children:[a.jsx("span",{className:"w-20 shrink-0 font-mono",style:{color:"var(--ink-dim)"},children:"trust"}),a.jsxs("span",{style:{color:"var(--ink-muted)"},children:[n!==null?"Trusted: ":"Trusted by an order: ",t.order.text]})]}):a.jsxs("div",{"data-testid":"trust-receipt",className:"flex flex-col gap-1 text-xs pt-1",children:[a.jsx("span",{"data-testid":"trust-receipt-question",className:"font-medium",style:{color:"var(--ink-high)"},children:t.question}),a.jsx("span",{"data-testid":"trust-receipt-consequence",style:{color:"var(--ink-muted)"},children:t.consequence}),a.jsx("button",{type:"button","data-testid":"trust-receipt-make",onClick:()=>void i(),disabled:r,className:"self-start rounded px-2 py-1 font-mono disabled:opacity-50",style:{background:"var(--accent)",color:"var(--accent-fg)"},children:r?"Trusting…":"Trust this route"}),s!==null&&a.jsxs("span",{"data-testid":"trust-receipt-error",style:{color:"var(--status-fail)"},children:["Not made: ",s]})]})}const gTt=[];function Ov({label:e,value:t,mono:n,title:r,testId:s}){return a.jsxs("div",{className:"flex gap-2 text-xs",...s!==void 0?{"data-testid":s}:{},children:[a.jsx("span",{className:"w-20 shrink-0 font-mono",style:{color:"var(--ink-dim)"},children:e}),a.jsx("span",{className:n?"font-mono break-all":"",style:{color:"var(--ink-muted)"},...r!==void 0?{title:r}:{},children:t})]})}function vTt(e){const t=e.replace(/\\/g,"/").split("/").filter(n=>n!=="");return t.length<=3?e:`…/${t.slice(-2).join("/")}`}function yTt({model:e,provenance:t,retriedAs:n,onSelectRun:r}){const{session:s}=e,i=qn(d=>d.byRun[s.id])??gTt,o=k.useMemo(()=>rTe(i),[i]),l=Mf(),c=Bn(),u=s.workdir!==void 0&&s.workdir!==null?l(s.workdir):null;return a.jsxs("div",{"data-testid":"what-where",className:"flex flex-col gap-1.5",children:[a.jsx(uTt,{provenance:t??null,retryOf:s.retry_of,retriedAs:n,onSelectRun:r,testId:"run-provenance"}),a.jsx(Z$e,{runId:s.id,status:s.status,session:s}),a.jsx(Ov,{label:"intent",value:c(s.problem)}),a.jsx(Ov,{label:"repo",value:s.repo_ref??"—",mono:!0}),a.jsx(Ov,{label:"worktree",value:u!==null?vTt(u):"—",mono:!0,...u!==null?{title:u}:{}}),o!==null&&a.jsx(Ov,{label:"base",value:ele(o),mono:!0,testId:"run-base",...o.note!==null?{title:c(o.note)}:{}}),a.jsx(Ov,{label:"roster",value:s.clis.length>0?s.clis.join(", "):"—",mono:!0}),a.jsx(Ov,{label:"entity",value:s.entity_mode}),a.jsx(mTt,{session:s})]})}const ns=St(()=>({catalog:"idle",entries:[],catalogError:null,presets:{},previews:{}}));function bT(){const e=ns.getState().catalog;e==="loading"||e==="ready"||e==="unsupported"||(ns.setState({catalog:"loading",catalogError:null}),no.catalog().then(t=>ns.setState({catalog:"ready",entries:Array.isArray(t.entries)?t.entries:[]}),t=>ns.setState(As(t)?{catalog:"unsupported"}:{catalog:"error",catalogError:t instanceof Error?t.message:String(t)})))}function xT(e){const t=e??"";if(ns.getState().presets[t]!==void 0)return;DM(t,"loading");const n=Nm;no.presets(e).then(r=>{n===Nm&&DM(t,Array.isArray(r.presets)?r.presets:[])},()=>{n===Nm&&DM(t,"unsupported")})}function DM(e,t){ns.setState(n=>({presets:{...n.presets,[e]:t}}))}function wTt(e,t,n){const r=e[t??""];return!Array.isArray(r)||n===""?null:r.find(s=>s.name===n)??null}function kTt(e,t){if(t!=="")for(const n of Object.values(e)){if(!Array.isArray(n))continue;const r=n.find(s=>s.name===t);if(r!==void 0&&typeof r.system=="boolean")return r.system}}function Zq(e){return JSON.stringify(e)}const iy=new Map,Uy=new Map,MM=new Map;let Nm=0;function bTt(){Nm+=1,iy.clear(),Uy.clear(),ns.setState({presets:{},previews:{}})}async function xTt(e){const t=Zq(e);let n=Uy.get(t);if(n===void 0){const o=await hSe(e);if(!(o.status==="error"&&o.timedOut===!0)||(n=Uy.get(t),n===void 0))return o}let r;const s=new Promise(o=>{r=setTimeout(()=>o({status:"error",error:STt}),jTt)}),i=await Promise.race([n,s]);return r!==void 0&&clearTimeout(r),i}const jTt=6e4,STt="the engine still hasn’t answered the preview — try again",dSe=1e4,NTt=`The engine didn’t answer in ${dSe/1e3} s — the summary below is studio’s own reading of this launch.`;function hSe(e){const t=Zq(e),n=ns.getState().previews[t];if(n!==void 0&&n.status!=="loading"&&n.status!=="error")return Promise.resolve(n);const r=iy.get(t);if(r!==void 0)return r;LM(t,{status:"loading"});const s=Nm,i=no.previewPlan(e).then(d=>({status:"ready",preview:d}),d=>As(d)?{status:"unsupported"}:{status:"error",error:d instanceof Pt?d.message:String(d)});let o;const l=new Promise(d=>{o=setTimeout(()=>d({status:"error",error:NTt,timedOut:!0}),dSe)}),c=Promise.race([i,l]).then(d=>(o!==void 0&&clearTimeout(o),iy.get(t)===c&&iy.delete(t),s===Nm&&LM(t,d),d)),u=(MM.get(t)??0)+1;return MM.set(t,u),Uy.set(t,i),i.then(d=>{var h;Uy.get(t)===i&&Uy.delete(t),s===Nm&&MM.get(t)===u&&!iy.has(t)&&((h=ns.getState().previews[t])==null?void 0:h.status)==="error"&&LM(t,d)}),iy.set(t,c),c}function LM(e,t){ns.setState(n=>({previews:{...n.previews,[e]:t}}))}const _Tt=300;function fSe(e){const t=ns(u=>u.catalog),n=ns(u=>u.entries),[r,s]=k.useState([]),[i,o]=k.useState("");k.useEffect(()=>{e&&bT()},[e]);const l=r.length>0,c=k.useMemo(()=>l?K4(r,eRe(i)):null,[l,r,i]);return{catalog:t,entries:n,picked:r,add:k.useCallback(u=>s(d=>[...d,{catalog:u}]),[]),remove:k.useCallback(u=>s(d=>d.filter((h,f)=>f!==u)),[]),clear:k.useCallback(()=>s([]),[]),replace:k.useCallback(u=>s(u.map(d=>({catalog:d}))),[]),touchText:i,setTouchText:o,composing:l,plan:c}}function pSe(e){const t=ns(p=>p.presets),n=ns(p=>p.previews),r=t[e.projectId??""]!==void 0;k.useEffect(()=>{r||xT(e.projectId)},[e.projectId,r]);const{plan:s}=e,i=s!==null?null:wTt(t,e.projectId,e.workflow.trim()),o=(i==null?void 0:i.system)===!0?null:i,l=hO(e.mode,e.confirm,e.beforeOrd,0),c=k.useMemo(()=>{const p=s??(o!==null?{steps:o.steps}:null);return p===null?null:{plan:p,...e.projectId!==null?{projectId:e.projectId}:{},...l!==void 0?{humanConfirm:l}:{},...e.repoRef!==null?{repoRef:e.repoRef}:{},...e.deliver!==null?{deliver:e.deliver}:{}}},[s,o,e.projectId,l,e.repoRef,e.deliver]),u=c===null?null:Zq(c);k.useEffect(()=>{if(c===null)return;const p=setTimeout(()=>void hSe(c),_Tt);return()=>clearTimeout(p)},[u]);const d=u===null?null:n[u]??{status:"loading"},h=d!==null&&d.status==="ready"?nRe(d.preview):null,f=k.useCallback(async()=>{const p=hO(e.mode,e.confirm,e.beforeOrd,0);if(p===void 0||!p.startsWith("before:")||c===null)return p;const m=await xTt(c);if(m.status==="error")throw new Error(`Can't place the "pause before step ${e.beforeOrd}" gate: the launch preview failed (${m.error}). Try again.`);const g=m.status==="ready"?sRe(m.preview):0;return hO(e.mode,e.confirm,e.beforeOrd,g)},[e.mode,e.confirm,e.beforeOrd,c]);return{previewBody:c,previewOf:s!==null?"plan":o!==null?"preset":null,preview:d,view:h,resolveHumanConfirm:f}}const pC={status:"idle",requestId:null,plan:null,outcome:null,error:null,retryable:!1},Tw=St(()=>({byRun:{}}));function FM(e,t){Tw.setState(n=>({byRun:{...n.byRun,[e]:t}}))}async function mSe(e,t,n){FM(e,{...pC,status:"sending",requestId:n,plan:t});try{const r=await no.editPlan(e,{plan:t,requestId:n});FM(e,{...pC,status:"done",requestId:n,plan:t,outcome:iRe(r)})}catch(r){const s=r instanceof Pt?r.status:null;FM(e,{...pC,status:"failed",requestId:n,plan:t,error:r instanceof Error?r.message:String(r),retryable:s===null||s>=500})}}function gSe(e,t){var n;return((n=Tw.getState().byRun[e])==null?void 0:n.status)==="sending"?Promise.resolve():mSe(e,t,aRe())}function CTt(e){const t=Tw.getState().byRun[e];return t===void 0||t.status!=="failed"||!t.retryable||t.plan===null||t.requestId===null?Promise.resolve():mSe(e,t.plan,t.requestId)}function vSe({model:e,touch:t=!0,emptyText:n,hide:r}){const{catalog:s,entries:i,picked:o}=e;return a.jsxs("div",{"data-testid":"phase-picker","data-catalog-state":s,className:"flex flex-col gap-2 rounded-xl px-3 py-2",style:{background:"var(--surface-rail)",border:"1px solid var(--surface-raised)"},children:[a.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[a.jsx("span",{className:"text-xs font-mono ",style:{color:"var(--ink-dim)"},children:"Phases"}),s==="loading"&&a.jsx("span",{className:"text-xs",style:{color:"var(--ink-dim)"},children:"loading the catalog…"}),s==="unsupported"&&a.jsx("span",{"data-testid":"phase-catalog-unsupported",className:"text-xs",style:{color:"var(--status-gate)"},children:"This daemon has no phase catalog. Upgrade wicked-crew to compose a plan."}),s==="error"&&a.jsx("span",{"data-testid":"phase-catalog-error",className:"text-xs",style:{color:"var(--status-fail)"},children:"Could not load the phase catalog."}),s==="ready"&&i.filter(l=>!(r??[]).includes(l.id)).map(l=>{const c=tRe(l);return a.jsxs("button",{type:"button","data-testid":"phase-option","data-catalog":l.id,title:[l.description??l.id,...c].join(" · "),onClick:()=>e.add(l.id),className:"rounded-lg px-2 py-0.5 text-xs font-mono",style:{background:"var(--surface-card)",border:"1px solid var(--surface-raised)",color:"var(--ink-high)"},children:["+ ",l.id]},l.id)})]}),a.jsx("ol",{"data-testid":"phase-selection",className:"flex items-center gap-1.5 flex-wrap text-xs font-mono",children:o.length===0?a.jsx("li",{style:{color:"var(--ink-dim)"},children:n??"No phases picked: the launch uses the workflow chosen under +."}):o.map((l,c)=>a.jsxs("li",{"data-testid":"phase-selected","data-catalog":l.catalog,className:"flex items-center gap-1 rounded-lg px-2 py-0.5",style:{background:"var(--accent-subtle)",color:"var(--ink-high)"},children:[a.jsxs("span",{style:{color:"var(--ink-dim)"},children:[c+1,"."]})," ",l.catalog,a.jsx("button",{type:"button","aria-label":`Remove ${l.catalog}`,"data-testid":"phase-remove",onClick:()=>e.remove(c),style:{color:"var(--ink-dim)"},children:"×"})]},`${l.catalog}-${c}`))}),t&&a.jsxs("label",{className:"flex flex-col gap-1 text-xs",style:{color:"var(--ink-muted)"},children:["Files this will change (optional, one per line). Leave it empty and the PA scopes the plan first.",a.jsx("textarea",{"data-testid":"plan-touch",rows:2,value:e.touchText,onChange:l=>e.setTouchText(l.target.value),placeholder:"src/auth/login.ts",className:"rounded-lg px-2 py-1 font-mono resize-y",style:{background:"var(--surface-card)",border:"1px solid var(--surface-raised)",color:"var(--ink-high)"}})]})]})}function ETt({view:e}){const t=e.session.id,n=Roe(e.session),r=fSe(n.show),s=Tw(l=>l.byRun[t])??pC;if(!n.show)return null;const i=n.editable&&r.plan!==null&&s.status!=="sending",o=s.status==="done"?s.outcome:null;return a.jsxs("div",{"data-testid":"plan-edit","data-editable":n.editable?"true":"false",className:"flex flex-col gap-2 text-xs",children:[!n.editable&&a.jsx("p",{"data-testid":"plan-edit-unavailable",style:{color:"var(--ink-muted)"},children:n.reason}),n.editable&&a.jsxs(a.Fragment,{children:[a.jsx(vSe,{model:r,touch:!1,emptyText:"Pick phases to add to this run's plan."}),a.jsx("button",{type:"button","data-testid":"plan-edit-propose",disabled:!i,onClick:()=>{r.plan!==null&&gSe(t,{steps:r.plan.steps}).then(()=>{var l;((l=Tw.getState().byRun[t])==null?void 0:l.status)==="done"&&r.clear()})},className:"self-start rounded-lg px-3 py-1 font-mono font-semibold disabled:opacity-40",style:{background:"var(--accent)",color:"var(--accent-fg)"},children:s.status==="sending"?"Proposing…":"Add to plan"})]}),(o==null?void 0:o.kind)==="applied"&&a.jsxs("div",{"data-testid":"plan-edit-result","data-kind":"applied",className:"flex flex-col gap-0.5",style:{color:"var(--ink-high)"},children:[a.jsx("span",{children:"Held for the run’s next step boundary."}),a.jsxs("span",{"data-testid":"plan-edit-band",children:["band ",o.band??"unchanged"]}),o.highRisk===!0&&a.jsx("span",{"data-testid":"plan-edit-high-risk",style:{color:"var(--status-gate)"},children:"This edit moves the run into high risk."}),a.jsx("span",{"data-testid":"plan-edit-floor-added",children:o.floorAdded.length>0?`The floor adds: ${o.floorAdded.join(", ")}.`:"The floor adds nothing."})]}),(o==null?void 0:o.kind)==="already-applied"&&a.jsx("p",{"data-testid":"plan-edit-result","data-kind":"already-applied",style:{color:"var(--ink-high)"},children:"Already applied: the engine had this edit, so nothing new was added."}),(o==null?void 0:o.kind)==="answered-gate"&&a.jsxs("p",{"data-testid":"plan-edit-result","data-kind":"answered-gate",style:{color:"var(--ink-high)"},children:["The edit answered the plan gate; the run is ",o.status,"."]}),s.status==="failed"&&a.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[a.jsx("p",{"data-testid":"plan-edit-error",style:{color:"var(--status-fail)"},children:s.error}),s.retryable&&a.jsx("button",{type:"button","data-testid":"plan-edit-retry",onClick:()=>void CTt(t),className:"rounded-lg px-2 py-0.5 font-mono",style:{background:"var(--surface-card)",border:"1px solid var(--surface-raised)",color:"var(--ink-high)"},children:"Retry the same edit"})]})]})}function eH(e,t){const n=$$e(e,t),r=Roe(e.session).show;return $Tt.filter(s=>(s.id!=="delivery"||n)&&(s.id!=="plan"||r))}function ySe({id:e,view:t,model:n,provenance:r,retriedAs:s,navigate:i,onSelectRun:o}){return e==="delivery"?a.jsx("div",{className:"px-4 py-3",style:{background:"var(--surface-base)"},children:a.jsx(yXe,{view:t,...i!==void 0?{navigate:i}:{}})}):e==="plan"?a.jsx("div",{className:"px-4 py-3",style:{background:"var(--surface-base)"},children:a.jsx(ETt,{view:t})}):n?a.jsxs("div",{className:"px-4 py-3",style:{background:"var(--surface-base)"},children:[e==="decisions"&&a.jsx(ZRt,{model:n}),e==="governance"&&a.jsx(iTt,{model:n}),e==="burn"&&a.jsx(BRt,{model:n}),e==="data"&&a.jsx(QRt,{model:n}),e==="steering"&&a.jsx(lTt,{runId:n.session.id}),e==="whatwhere"&&a.jsx(yTt,{model:n,provenance:r,retriedAs:s,...o!==void 0?{onSelectRun:o}:{}}),e==="assumptions"&&a.jsx(MRt,{model:n}),e==="files"&&a.jsx(ITt,{model:n})]}):a.jsx("div",{className:"px-4 py-3",children:a.jsx("p",{className:"text-xs font-mono",style:{color:"var(--ink-dim)"},children:"Loading…"})})}const $Tt=[{id:"whatwhere",label:"What / Where"},{id:"plan",label:"Plan"},{id:"decisions",label:"Decisions"},{id:"governance",label:"Governance"},{id:"burn",label:"Burn"},{id:"data",label:"Data"},{id:"steering",label:"Steering"},{id:"assumptions",label:"Assumptions"},{id:"files",label:"Files referenced"},{id:"delivery",label:"Delivery"}],ATt=new Set(["Write","Edit","MultiEdit","NotebookEdit"]),RTt=new Set(["DeleteFile","Remove"]);function ese(e,t){if(t===void 0||t==="")return e;const n=e.replace(/\\/g,"/"),r=t.replace(/\\/g,"/").replace(/\/+$/,"");return n===r?".":n.startsWith(`${r}/`)?n.slice(r.length+1):e}function BM({path:e,opKind:t,runId:n,root:r}){const[s,i]=k.useState(null),[o,l]=k.useState(!1),c=k.useRef(null),u=k.useRef(null);k.useEffect(()=>()=>{u.current!==null&&clearTimeout(u.current)},[]);const h=Mf()(e),f=ese(e,r)===e?h:ese(e,r),p=f.replace(/\\/g,"/").split("/"),m=p.pop()??f,g=p.length>0?`${p.join("/")}/`:"",v=t==="delete"?"−":t==="write"?"±":"~",y=t==="delete"?"var(--status-fail)":t==="write"?"var(--status-gate)":"var(--ink-dim)",w=t==="delete"?"var(--status-fail)":"var(--ink-high)";function b(C){i(C),u.current!==null&&clearTimeout(u.current),u.current=setTimeout(()=>{i(null),u.current=null},2e3)}function x(){navigator.clipboard.writeText(e).then(()=>{b("copied")}).catch(()=>{})}function S(){Oe.openPath(e,n).then(()=>b("opened")).catch(()=>{navigator.clipboard.writeText(e).catch(()=>{}),b("open-failed")})}function _(){var C;l(!1),(C=c.current)==null||C.focus()}function E(){var C;l(!1),(C=c.current)==null||C.focus(),S()}return a.jsxs("li",{title:h,className:"group flex items-start gap-1.5 min-w-0",children:[a.jsx("span",{className:"shrink-0 mt-0.5 text-xs font-mono select-none",style:{color:y},children:v}),a.jsxs("button",{type:"button",ref:c,onClick:()=>l(!0),className:"min-w-0 flex-1 leading-5 font-mono text-xs break-all text-left transition-opacity hover:opacity-70",title:`View ${h}`,style:{background:"none",border:"none",padding:0,cursor:"pointer"},children:[g&&a.jsx("span",{style:{color:"var(--ink-dim)"},children:g}),a.jsx("span",{style:{color:w},children:m}),s==="opened"&&a.jsx("span",{className:"ml-1 text-xs",style:{color:"var(--status-run)"},children:"✓ opened"}),s==="copied"&&a.jsx("span",{className:"ml-1 text-xs",style:{color:"var(--status-run)"},children:"✓ copied"}),s==="open-failed"&&a.jsx("span",{className:"ml-1 text-xs",style:{color:"var(--status-gate)"},children:"open unavailable — path copied"})]}),a.jsx("button",{type:"button",onClick:S,"aria-label":`Open externally: ${h}`,title:`Open with system default app: ${h}`,className:"shrink-0 mt-0.5 text-xs font-mono leading-5 transition-opacity hover:opacity-70 opacity-0 group-hover:opacity-100 focus:opacity-100",style:{background:"none",border:"none",padding:0,cursor:"pointer",color:"var(--ink-dim)"},children:"↗"}),a.jsx("button",{type:"button",onClick:x,"aria-label":`Copy path ${h}`,title:"Copy path",className:"shrink-0 mt-0.5 text-xs font-mono leading-5 transition-opacity hover:opacity-70 opacity-0 group-hover:opacity-100 focus:opacity-100",style:{background:"none",border:"none",padding:0,cursor:"pointer",color:"var(--ink-dim)"},children:"⧉"}),o&&a.jsx(mk,{runId:n,path:e,defaultTab:t!==void 0?"diff":"file",onClose:_,onUnsupported:E})]})}function TTt({runId:e,units:t,onOpenShell:n,live:r=null}){const s=Bn(),i=[...t].filter(c=>c.status==="done"||c.status==="rejected").sort((c,u)=>c.ord-u.ord),[o,l]=k.useState({});return k.useEffect(()=>{let c=!1;for(const u of i){const d=u.id.startsWith(`${e}:`)?u.id.slice(e.length+1):`u${u.ord}`;Oe.getUnitOutput(e,d).then(({output:h,outputUnavailable:f})=>{c||l(p=>({...p,[u.ord]:h??f??"(no transcript captured)"}))}).catch(()=>{c||l(h=>({...h,[u.ord]:"(transcript unavailable)"}))})}return()=>{c=!0}},[e,i.length]),a.jsxs("div",{"data-testid":"term-transcript",className:"flex flex-col gap-3 max-h-[60vh] overflow-y-auto",children:[r!==null&&a.jsx(QA,{runId:e,ord:r.ord,phase:r.phase}),i.map(c=>a.jsxs("div",{children:[a.jsxs("p",{className:"text-xs font-mono mb-1 ",style:{color:"var(--ink-dim)"},children:["unit #",c.ord," · ",c.stage," · ",c.status]}),a.jsx("pre",{className:"rounded-lg p-2 text-xs leading-tight whitespace-pre-wrap font-mono overflow-x-auto",style:{background:"var(--surface-base)",color:"var(--ink-body)"},children:s(o[c.ord]??"Loading…")})]},c.id)),a.jsx("div",{className:"flex items-center gap-2 pt-1",style:{borderTop:"1px solid var(--surface-raised)"},children:a.jsx("button",{type:"button","data-testid":"term-open-shell",onClick:n,className:"text-xs font-mono underline transition-opacity hover:opacity-70",style:{color:"var(--ink-muted)",background:"none",border:"none",padding:0,cursor:"pointer"},children:"Open operator shell (ungoverned) instead"})})]})}function ITt({model:e}){const t=e.session.id,n=e.session.workdir??void 0,[r,s]=k.useState(!1),[i,o]=k.useState(!1),l=k.useRef(null),c=new Set,u=new Set;for(const S of e.units)for(const _ of S.hookFires)ATt.has(_.toolName)&&c.add(S.ord),RTt.has(_.toolName)&&u.add(S.ord);const d=new Set,h=new Set,f=new Set;for(const S of e.units)for(const _ of S.filesRead)f.add(_),u.has(S.ord)?h.add(_):c.has(S.ord)&&d.add(_);for(const S of h)d.delete(S);const p=new Set;for(const S of f)!d.has(S)&&!h.has(S)&&p.add(S);const m=d.size>0||h.size>0,g=f.size>0,v=!["completed","cancelled","failed"].includes(e.session.status),y=a.jsxs(a.Fragment,{children:[a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx("button",{type:"button",ref:l,"data-testid":"files-full-diff",onClick:()=>{o(!1),s(!0)},className:"text-xs font-mono px-1.5 py-0.5 rounded transition-opacity hover:opacity-70",style:{color:"var(--accent)",background:"var(--accent-subtle)"},children:"Full diff"}),i&&a.jsx("span",{className:"text-xs font-mono",style:{color:"var(--ink-dim)"},children:"diff unavailable — this daemon predates the diff route"})]}),r&&a.jsx(mk,{runId:t,defaultTab:"diff",base:"merge-base",onClose:()=>{var S;s(!1),(S=l.current)==null||S.focus()},onUnsupported:()=>{var S;s(!1),o(!0),(S=l.current)==null||S.focus()}})]});if(!g)return a.jsxs("div",{className:"flex flex-col gap-2","data-testid":"files-empty",children:[a.jsx("p",{className:"text-xs font-mono",style:{color:"var(--ink-dim)"},children:v?"No files changed yet.":"No files recorded by the units."}),!v&&a.jsx("p",{className:"text-xs font-mono leading-snug",style:{color:"var(--ink-dim)"},children:"the units recorded no file reads — the run's changeset, if any, is on its branch: open the full diff"}),y]});const w=[...d].sort(),b=[...h].sort(),x=[...p].sort();return a.jsxs("div",{className:"flex flex-col gap-4",children:[a.jsx("p",{"data-testid":"files-scope-note",className:"text-xs font-mono leading-snug",style:{color:"var(--ink-dim)"},children:"files the agents read or wrote in the worktree — not a delivered changeset"}),y,(m||v)&&a.jsxs("div",{children:[a.jsx("p",{className:"text-xs font-mono mb-2 ",style:{color:"var(--ink-dim)"},children:"Modified / Created"}),m?a.jsxs("ul",{className:"flex flex-col gap-1",children:[w.map(S=>a.jsx(BM,{path:S,opKind:"write",runId:t,root:n},S)),b.map(S=>a.jsx(BM,{path:S,opKind:"delete",runId:t,root:n},S))]}):a.jsx("p",{className:"text-xs font-mono",style:{color:"var(--ink-dim)"},children:"No files changed yet."})]}),x.length>0&&a.jsxs("div",{children:[a.jsx("p",{className:"text-xs font-mono mb-2 ",style:{color:"var(--ink-dim)"},children:"Referenced"}),a.jsx("ul",{className:"flex flex-col gap-1",children:x.map(S=>a.jsx(BM,{path:S,runId:t,root:n},S))})]}),a.jsxs("p",{className:"text-xs font-mono",style:{color:"var(--ink-dim)"},children:[f.size," file",f.size!==1?"s":""," total"]})]})}function OTt({view:e,runs:t,onSelectRun:n,navigate:r}){const[s,i]=k.useState(!1),[o,l]=k.useState(()=>typeof window<"u"&&window.location.hash==="#governance"?"governance":"whatwhere");k.useEffect(()=>{typeof window<"u"&&window.location.hash==="#governance"&&l("governance")},[e.session.id]);const c=Aa(E=>E.byRun[e.session.id]??null);k.useEffect(()=>{Aa.getState().load(e.session.id)},[e.session.id]);const u=k.useMemo(()=>(t??[]).filter(E=>E.session.retry_of===e.session.id).map(E=>E.session.id),[t,e.session.id]),[d,h]=k.useState(!1),[f,p]=k.useState(!1),[m,g]=k.useState(!1),{session:v}=e,y=rSe(v.id,e),w=y?new Set(y.units.flatMap(E=>E.filesRead)).size:null,b=Pj(),x=k.useMemo(()=>eH(e,b),[e,b]),S=o===null||x.some(E=>E.id===o)?o:"whatwhere";function _(E){l(C=>(C===null||x.some(A=>A.id===C)?C:"whatwhere")===E?null:E)}return s?a.jsxs("div",{className:"flex flex-col items-center w-10 shrink-0 py-3 gap-2",style:{background:"var(--surface-base)",borderLeft:"1px solid var(--surface-raised)"},children:[a.jsx("button",{type:"button",onClick:()=>i(!1),className:"text-sm leading-none",style:{color:"var(--ink-dim)"},"aria-label":"Expand insights panel",children:"‹"}),a.jsx("button",{type:"button",onClick:()=>h(!0),title:"Terminal","aria-label":"Open terminal",className:"w-7 h-7 flex items-center justify-center rounded text-sm",style:{color:"var(--ink-dim)"},children:"⬛"}),a.jsx("button",{type:"button",onClick:()=>g(!0),title:"Coverage","aria-label":"Open coverage",className:"w-7 h-7 flex items-center justify-center rounded text-sm font-mono",style:{color:"var(--ink-dim)"},children:"%"})]}):a.jsxs("div",{className:"flex flex-col w-72 shrink-0 overflow-hidden",style:{background:"var(--surface-base)",borderLeft:"1px solid var(--surface-raised)"},children:[a.jsxs("div",{className:"flex items-center gap-1 px-3 py-2 border-b shrink-0",style:{background:"var(--surface-base)",borderColor:"var(--surface-raised)"},children:[a.jsxs("button",{type:"button",onClick:()=>i(!0),className:"flex items-center gap-1.5 flex-1 min-w-0 text-left","aria-label":"Collapse insights panel",children:[a.jsx("span",{className:"text-sm leading-none shrink-0",style:{color:"var(--ink-dim)"},children:"›"}),a.jsx("span",{className:"text-xs font-semibold font-mono",style:{color:"var(--ink-dim)"},children:"Insights"})]}),a.jsx("button",{type:"button",onClick:()=>h(!0),title:gl(v,e.units)!==null?"View this run's live output":e.units.some(E=>E.status==="done"||E.status==="rejected")?"View this run's transcript":"Terminal","aria-label":gl(v,e.units)!==null?"View this run's live output":e.units.some(E=>E.status==="done"||E.status==="rejected")?"View this run's transcript":"Open terminal",className:"rounded px-2 py-0.5 text-xs font-mono",style:{color:"var(--ink-muted)"},children:"Term"}),a.jsx("button",{type:"button",onClick:()=>g(!0),title:"Coverage","aria-label":"Open coverage report",className:"rounded px-2 py-0.5 text-xs font-mono",style:{color:"var(--ink-muted)"},children:"Cov"})]}),a.jsx("div",{className:"flex-1 overflow-y-auto",children:x.map(({id:E,label:C})=>a.jsxs("div",{style:{borderBottom:"1px solid var(--surface-raised)"},children:[a.jsxs("button",{type:"button","data-testid":`rail-accordion-${E}`,onClick:()=>_(E),className:"w-full flex items-center justify-between px-4 py-2.5 text-left transition-colors",style:{color:S===E?"var(--ink-high)":"var(--ink-muted)"},onMouseEnter:T=>{T.currentTarget.style.background="var(--surface-raised)"},onMouseLeave:T=>{T.currentTarget.style.background="transparent"},"aria-expanded":S===E,children:[a.jsxs("div",{className:"flex items-center gap-1.5",children:[a.jsx("span",{className:"text-xs font-medium font-mono",children:C}),E==="files"&&w!==null&&w>0&&a.jsx("span",{className:"text-xs font-mono px-1 py-0.5 rounded",style:{background:"var(--accent-subtle)",color:"var(--accent)"},children:w}),E==="delivery"&&a.jsx(gXe,{view:e})]}),a.jsx("span",{className:"text-xs",style:{color:"var(--ink-dim)"},children:S===E?"▲":"▼"})]}),S===E&&a.jsx(ySe,{id:E,view:e,model:y,provenance:c,retriedAs:u,...r!==void 0?{navigate:r}:{},...n!==void 0?{onSelectRun:n}:{}})]},E))}),d&&(()=>{const E=e.units.some(R=>R.status==="done"||R.status==="rejected"),C=gl(v,e.units),T=e.units.find(R=>R.ord===C),A=(E||C!==null)&&!f;return a.jsx(Dm,{title:A?C!==null?"This run's live output":"This run's transcript":"Operator shell",onClose:()=>{h(!1),p(!1)},children:A?a.jsx(TTt,{runId:v.id,units:e.units,onOpenShell:()=>p(!0),live:C!==null?{ord:C,phase:(T==null?void 0:T.stage)??`unit #${C}`}:null}):a.jsx(JA,{cwd:v.workdir??".",governed:!0})})})(),m&&a.jsx(Dm,{title:"Coverage report",onClose:()=>g(!1),children:a.jsx(rxe,{})})]})}function tH(e){const[t,n]=k.useState({state:"loading"});return k.useEffect(()=>{let r=!1;return n({state:"loading"}),Oe.getRunEvents(e).then(({events:s})=>{r||n({state:"ok",events:s})}).catch(s=>{r||n({state:"error",message:s instanceof Error?s.message:String(s)})}),()=>{r=!0}},[e]),t}function PTt({target:e,runId:t,run:n,navigate:r}){const s=n!==null?_s(cA(n.session.problem)??n.session.problem):"This run";return a.jsxs("div",{className:"flex flex-1 flex-col overflow-hidden","data-testid":`run-raw-${e}`,"data-run-id":t,children:[a.jsxs("header",{className:"flex items-center gap-3 px-6 py-2 shrink-0",style:{borderBottom:"1px solid var(--surface-raised)",background:"var(--surface-card)"},children:[a.jsx("button",{type:"button","data-testid":"run-raw-back",onClick:()=>jO(r),"aria-label":"Back",style:{color:"var(--ink-dim)",background:"transparent",border:"none",cursor:"pointer"},children:"←"}),a.jsxs("p",{className:"flex-1 truncate",style:{margin:0,fontSize:"var(--text-sm)",color:"var(--ink-high)"},title:s,children:[e==="events"?"Raw events":"Files"," · ",s,a.jsx(cf,{"data-testid":"tech-run-raw",parts:[NC(t),n!==null?`#${n.session.attempt+1}`:null]})]})]}),e==="events"?a.jsx(DTt,{runId:t}):a.jsx(mk,{runId:t,defaultTab:"diff",base:"merge-base",onClose:()=>jO(r),onUnsupported:()=>jO(r)})]})}function DTt({runId:e}){const t=tH(e),n={fontSize:"var(--text-xs)",fontFamily:"var(--font-mono)",margin:0};return t.state==="loading"?a.jsx("p",{className:"px-6 py-3",style:{...n,color:"var(--ink-dim)"},children:"Loading events…"}):t.state==="error"?a.jsx("div",{className:"px-6 py-3",children:a.jsx(Ft,{"data-testid":"raw-events-error",kind:"error",what:"the event trail",error:t.message})}):a.jsx("pre",{"data-testid":"raw-events","data-count":t.events.length,className:"flex-1 overflow-auto px-6 py-3",style:{...n,color:"var(--ink-body)",whiteSpace:"pre-wrap",wordBreak:"break-word"},children:JSON.stringify(t.events,null,2)})}const MTt={router:"var(--accent)","fork-worker":"var(--status-run)",module:"var(--ink-muted)"},LTt={shipped:"var(--ink-muted)",override:"var(--status-gate)","user-added":"var(--status-done)"};function wSe({kind:e}){return a.jsx("span",{"data-testid":"skills-kind-chip","data-kind":e,className:"wk-tag",style:{color:MTt[e]},children:FPe[e]})}function kSe({provenance:e}){return a.jsx("span",{"data-testid":"skills-provenance-chip","data-provenance":e,title:e==="shipped"?"shipped — every file byte-identical to the baseline":e==="override"?"overridden — a shipped skill with edited or replaced files (reset restores the baseline)":"user-added — no baseline: added through the API, or upstream dropped it while your edits were kept",className:"inline-flex shrink-0 rounded px-1.5 py-0.5 font-semibold",style:{color:LTt[e]},children:zPe[e]})}const pS="wk-tag";function FTt(){return a.jsx("span",{"data-testid":"skills-core-badge",title:"core — in the registered-reference closure (a workflow's skill_ref, or named by one of those skills); disabling or renaming it is blocked",className:pS,style:{color:"var(--accent)"},children:"core"})}const BTt="not portable — depends on the plugin root, cwd-relative scripts or sibling links; Claude-only, excluded from the snapshot's copilot view and the other CLIs' per-launch skill lists",zM="excluded from the snapshot's copilot view and the other CLIs' per-launch skill lists";function bSe(e){if(!e.detailed)return BTt;const t=e.evidence[0],n=t===void 0?"":` (first at ${t})`;return e.reach==="needs-claude"?`${$_["needs-claude"]} — ${e.reasons.join(", ")}${n}: ${k3("requires-harness:claude")}; ${zM} by design`:e.reasons.includes(fce)?`${$_["not-portable"]} — ${e.reasons.join(", ")}${n}; an authoring defect AND a harness requirement: fix the skill text; it also needs the Claude harness, so it stays ${zM} after the fix`:`${$_["not-portable"]} — ${e.reasons.join(", ")}${n}; an authoring defect: ${zM} until the skill text is fixed`}function zTt({portability:e,portable:t}){const n=Qy({portable:t,portability:e});if(n.reach==="portable")return null;const r=bSe(n),s=n.reach==="needs-claude";return a.jsx("span",{"data-testid":"skills-claude-only-badge","data-reach":n.reach,"data-contradiction":n.contradiction??void 0,className:"inline-flex shrink-0",children:a.jsx("span",{"data-testid":s?"skills-needs-claude-badge":"skills-not-portable-badge","data-reasons":n.reasons.join(" "),"data-detailed":n.detailed,role:"note","aria-label":r,title:r,className:pS,style:{color:"var(--ink-muted)"},children:$_[n.reach]})})}function WTt(){return a.jsx("span",{"data-testid":"skills-upgrade-badge",title:"upgrade available — the refreshed baseline changed a file you override; your content is kept, the new side is readable from the drawer (Baseline side)",className:pS,style:{color:"var(--status-run)"},children:"upgrade"})}function UTt(){return a.jsx("span",{"data-testid":"skills-conflict-badge",title:"refresh conflict — your edit was kept while upstream changed the same file, or upstream now ships a skill under this name at another dir; the baseline side is readable from the drawer, reset takes it",className:pS,style:{color:"var(--status-gate)"},children:"conflict"})}function qTt(){return a.jsx("span",{"data-testid":"skills-unpublished-badge",title:"unpublished — the current snapshot carries an older version of a file this skill owns (or none); Publish to hand this content to workers",className:pS,style:{color:"var(--status-run)"},children:"unpublished"})}function xSe({skill:e}){return a.jsxs("span",{className:"inline-flex flex-wrap items-center gap-1",children:[e.core&&a.jsx(FTt,{}),a.jsx(zTt,{portability:e.portability,portable:e.portable}),e.upgradeAvailable&&a.jsx(WTt,{}),e.conflict&&a.jsx(UTt,{}),e.unpublished&&a.jsx(qTt,{})]})}function jSe({name:e,enabled:t,busy:n,onToggle:r,testId:s}){return a.jsx("div",{role:"group","aria-label":e,children:a.jsx(Ls,{"data-testid":s,label:"Enabled",checked:t,disabled:n?"Wait for the current change or refresh to finish.":null,onChange:r})})}const HTt={clear:"var(--status-done)",warnings:"var(--status-gate)",blocked:"var(--status-fail)"};function KTt(e,t){const n=t.findings.length,r=n===1?"finding":"findings";return t.verdict==="blocked"?`${e} blocked — nothing was written (${n} ${r}).`:t.verdict==="warnings"?`${e} passed with ${n} ${r} to read.`:n===0?`${e} clear — no findings.`:`${e} clear (${n} ${r}).`}function GTt(e){return e.file===null?null:e.line===null?e.file:`${e.file}:${e.line}`}function K0({verb:e,result:t,testId:n}){const r=Bn(),s=HTt[t.verdict],i=t.findings.filter(l=>l.severity==="blocking").length,o=t.findings.length-i;return a.jsxs("div",{"data-testid":n,"data-verdict":t.verdict,"data-revision":t.revision,role:"status",className:"wk-card flex flex-col gap-2",children:[a.jsxs("p",{className:"flex flex-wrap items-baseline gap-2",children:[a.jsx("span",{className:"font-semibold",style:{color:s},children:KTt(e,t)}),t.findings.length>0&&a.jsxs("span",{"data-testid":"skills-findings-tally",className:"",style:{color:"var(--ink-dim)"},children:[i," blocking · ",o," ",o===1?"warning":"warnings"]}),a.jsx(ut,{text:`Catalog revision ${t.revision}`})]}),t.findings.length>0&&a.jsx("ul",{className:"flex flex-col gap-1",children:t.findings.map((l,c)=>{const u=GTt(l);return a.jsxs("li",{"data-testid":"skills-finding","data-kind":l.kind,"data-severity":l.severity,className:"flex flex-col gap-0.5",style:{color:"var(--ink-muted)"},children:[a.jsxs("span",{className:"inline-flex flex-wrap items-center gap-1.5",children:[a.jsx(ut,{text:`Check: ${l.kind}`}),a.jsx("span",{className:"",style:{color:l.severity==="blocking"?"var(--status-fail)":"var(--status-gate)"},children:l.severity}),l.skill!==null&&a.jsx("span",{"data-testid":"skills-finding-skill",className:"",style:{color:"var(--ink-dim)"},children:l.skill}),l.againstSkill!==null&&a.jsxs("span",{"data-testid":"skills-finding-against",className:"",style:{color:"var(--ink-dim)"},children:["against ",l.againstSkill,l.againstIsCore?" (core)":""]}),u!==null&&a.jsx(ut,{"data-testid":"skills-finding-location",text:u}),l.portabilityReason!=null&&a.jsx("span",{"data-testid":"skills-finding-reason","data-reason":l.portabilityReason,title:k3(l.portabilityReason),className:"rounded px-1.5",style:{color:"var(--ink-high)"},children:a.jsx(ut,{text:l.portabilityReason})})]}),l.evidence!==""&&a.jsx(ut,{"data-testid":"skills-finding-evidence",text:l.evidence}),a.jsx(ut,{text:r(l.explanation)})]},`${l.kind}-${c}`)})})]})}const VTt="Restore the original files and discard your edits. The skill keeps its current on or off setting. Publish when you are ready to share the restored files with your helpers.";function YTt({skill:e,writer:t,onClose:n,onDone:r}){const[s,i]=k.useState(""),[o,l]=k.useState(!1),[c,u]=k.useState(null),[d,h]=k.useState(null);Ai(n);const f=`Reset ${e.name}`,p=s===e.name&&!o,m=async()=>{if(p){l(!0),u(null),h(null);try{const g=await t.run(v=>o2e(e.name,v));if(g===null){n();return}if(g.verdict==="blocked"){h(g),l(!1);return}r(g)}catch(g){u(g instanceof Error?g.message:String(g)),l(!1)}}};return a.jsx("div",{className:"wk-pg-skills-scrim",children:a.jsxs("div",{"data-testid":"skills-confirm-modal",role:"dialog","aria-modal":"true","aria-label":f,className:"wk-card wk-pg-skills-modal",children:[a.jsx(Qn,{children:f}),a.jsx("p",{className:"",style:{color:"var(--ink-muted)"},children:VTt}),a.jsxs("label",{className:"flex flex-col gap-1",style:{color:"var(--ink-muted)"},children:["Type the skill name to confirm",a.jsx("input",{"data-testid":"skills-confirm-input",type:"text",value:s,onChange:g=>i(g.target.value),placeholder:e.name,spellCheck:!1,className:"wk-field"})]}),c!==null&&a.jsx(Ft,{"data-testid":"skills-confirm-error",kind:en(c),what:"the reset",error:c,onRetry:()=>void m()}),d!==null&&a.jsx(K0,{verb:"Reset skill",result:d,testId:"skills-confirm-findings"}),!p&&a.jsx("p",{className:"wk-field-note",children:o?"Wait for the reset to finish.":"Type the skill name exactly to enable Reset."}),a.jsxs("div",{className:"flex items-center justify-end gap-2",children:[a.jsx("button",{"data-testid":"skills-confirm-cancel",type:"button",onClick:n,className:"wk-btn wk-btn--quiet",children:"Cancel"}),a.jsx("button",{"data-testid":"skills-confirm",type:"button",disabled:!p,onClick:()=>void m(),className:"wk-btn wk-btn--danger",children:o?"Resetting…":"Reset skill"})]})]})})}const XTt=/^[A-Za-z0-9][A-Za-z0-9_-]*$/,QTt=`{
|
|
944
944
|
"SKILL.md": "---\\nname: my-skill\\n---\\n…"
|
|
945
945
|
}`;function SSe({mode:e,name:t,writer:n,onClose:r,onDone:s}){const[i,o]=k.useState(""),[l,c]=k.useState(""),[u,d]=k.useState(!1),[h,f]=k.useState(null),[p,m]=k.useState(null),[g,v]=k.useState(!1);Ai(r);const y=e==="add"?i.trim():t??"",w=e==="add"&&y!==""&&!XTt.test(y)?'name: letters, digits, "-" and "_" only, starting with a letter or digit':null,b=l.trim()===""?null:u2e(l),x=w??(b===null?null:b.issue),S=!u&&y!==""&&b!==null&&b.files!==null&&w===null,_=async()=>{if(!S||b===null||b.files===null)return;const T=b.files;d(!0),f(null),m(null),v(!1);try{const A=await n.run(R=>e==="add"?l2e(y,T,R):c2e(y,T,R));if(A===null){v(!0),await n.reload(),d(!1);return}if(A.verdict==="blocked"){m(A),d(!1);return}s(y,A)}catch(A){f(A instanceof Error?A.message:String(A)),d(!1)}},E=e==="add"?"Add a skill":`Replace ${t??""}`,C=e==="add"?"Add skill":"Replace files";return a.jsx("div",{className:"wk-pg-skills-scrim",children:a.jsxs("div",{"data-testid":"skills-files-modal","data-mode":e,role:"dialog","aria-modal":"true","aria-label":E,className:"wk-card wk-pg-skills-modal",children:[a.jsx(Qn,{children:E}),a.jsxs("p",{className:"",style:{color:"var(--ink-muted)"},children:[e==="add"?"Paste the new skill’s files as a JSON map of relative paths to contents, including SKILL.md.":"Replace this skill’s files with the JSON map below, including SKILL.md. Files missing from the map are removed."," ","Your changes are checked before saving. Publish to share them with your helpers."]}),e==="add"&&a.jsxs("label",{className:"flex flex-col gap-1",style:{color:"var(--ink-muted)"},children:["Skill name",a.jsx("input",{"data-testid":"skills-files-name",type:"text",value:i,onChange:T=>o(T.target.value),placeholder:"my-team-skill",spellCheck:!1,"aria-invalid":w!==null,className:"wk-field"})]}),a.jsxs("label",{className:"flex flex-col gap-1",style:{color:"var(--ink-muted)"},children:["Files map (JSON)",a.jsx("textarea",{"data-testid":"skills-files-map",value:l,onChange:T=>c(T.target.value),placeholder:QTt,spellCheck:!1,"aria-invalid":b!==null&&b.issue!==null,className:"wk-field wk-pg-skills-code"})]}),x!==null&&a.jsx("p",{"data-testid":"skills-files-issue",className:"",style:{color:"var(--status-fail)"},children:x}),h!==null&&a.jsx(Ft,{"data-testid":"skills-files-error",kind:en(h),what:"the skill files",error:h,onRetry:()=>void _()}),p!==null&&a.jsx(K0,{verb:C,result:p,testId:"skills-files-findings"}),g&&a.jsxs("p",{"data-testid":"skills-files-conflict",role:"alert",className:"rounded px-2 py-1",style:{color:"var(--ink-muted)"},children:[a.jsx("span",{className:"font-semibold",style:{color:"var(--status-gate)"},children:"The skills catalog changed under this page — nothing was written."})," ",u?"Reloading the catalog…":`Your ${e==="add"?"name and files map are":"files map is"} kept and the catalog was reloaded — ${C} again to write against the current revision.`]}),!S&&a.jsx("p",{className:"wk-field-note",children:u?"Wait for the files to finish saving.":x??"Enter a skill name and a valid files map to continue."}),a.jsxs("div",{className:"flex items-center justify-end gap-2",children:[a.jsx("button",{"data-testid":"skills-files-cancel",type:"button",onClick:r,className:"wk-btn wk-btn--quiet",children:"Cancel"}),a.jsx("button",{"data-testid":"skills-files-save",type:"button",disabled:!S,onClick:()=>void _(),className:"wk-btn wk-btn--primary",children:u?g?"Reloading…":"Writing…":C})]})]})})}const WM={skill:"Skill files",support:"Support files"};function tse(e,t){var n;return e!==null&&t.some(r=>r.path===e)?e:(n=t[0])==null?void 0:n.path}function Pv(e){return e.content??""}function JTt({skill:e,support:t,writer:n,catalogEpoch:r,busy:s,leaveTo:i,top:o=0,onClose:l,onLeave:c,onDirtyChange:u,onToggle:d,onChanged:h}){const[f,p]=k.useState("skill"),[m,g]=k.useState(null),[v,y]=k.useState(null),[w,b]=k.useState(null),[x,S]=k.useState(!1),[_,E]=k.useState(null),[C,T]=k.useState(""),[A,R]=k.useState(null),[$,I]=k.useState(null),[O,P]=k.useState(null),[W,L]=k.useState(!1),[B,F]=k.useState(null),[M,z]=k.useState(null),[q,U]=k.useState(null),[X,G]=k.useState(!1),[Q,K]=k.useState(!0),[Y,V]=k.useState(null),Z=k.useRef(0),J=k.useRef(null),te=k.useRef(""),re=k.useRef({skill:null,support:null});k.useEffect(()=>{J.current=w},[w]),k.useEffect(()=>{te.current=C},[C]);const oe=w!==null&&w.content!==null&&C!==w.content;k.useEffect(()=>(u(oe),()=>u(!1)),[oe,u]);const ve=k.useCallback(()=>{oe?G(!0):l()},[oe,l]);Ai(ve);const Te=X||i!==null,ye=()=>{G(!1),i!==null&&c(!1)},le=()=>{i!==null?c(!0):l()},Ce=k.useCallback(async()=>{y(null);try{const ie=await ZPe(e.name);return g(ie),ie}catch(ie){return g([]),y(ie instanceof Error?ie.message:String(ie)),[]}},[e.name]),ge=k.useCallback(async(ie,he)=>{const Ee=n.revision();return{...ie==="skill"?await mG(e.name,he):await gG(he),path:he,scope:ie,readAt:Ee}},[e.name,n]),me=k.useCallback(async(ie,he)=>{const Ee=++Z.current,Ue=te.current;S(!0),E(null),I(null),R(null),P(null),V(null);try{const Ye=await ge(ie,he);if(Ee!==Z.current)return;const ht=te.current;if(ht!==Ue&&ht!==""){P(he);return}re.current[ie]=he,b(Ye),T(Pv(Ye))}catch(Ye){if(Ee!==Z.current)return;b(null),E(Ye instanceof Error?Ye.message:String(Ye))}finally{Ee===Z.current&&S(!1)}},[ge]);k.useEffect(()=>{Ce()},[Ce]),k.useEffect(()=>{if(!Q||m===null)return;K(!1);const ie=tse(re.current.skill,m);ie!==void 0&&me("skill",ie)},[Q,m,me]),k.useEffect(()=>{const ie=J.current;if(ie===null)return;const he=Z.current;ge(ie.scope,ie.path).then(Ee=>{if(!(he!==Z.current||J.current!==ie)){if(Ee.content===ie.content){b(Ee),R(null);return}if(te.current===Pv(ie)){b(Ee),T(Pv(Ee)),R(null);return}R(Ee)}}).catch(Ee=>{he!==Z.current||J.current!==ie||z(`could not re-read ${ie.path} after the catalog reload — ${Ee instanceof Error?Ee.message:String(Ee)}`)})},[r,ge]);const je=f==="skill"?m:t,ce=()=>{Z.current+=1,b(null),T(""),R(null),P(null),I(null),V(null),S(!1)},se=ie=>{if(ie===f)return;p(ie),F(null),E(null);const he=ie==="skill"?m:t;if(he===null){ce(),K(!0);return}K(!1);const Ee=tse(re.current[ie],he);Ee!==void 0?me(ie,Ee):ce()},De=w===null?null:w.binary?"binary file — not editable here":w.truncated?"this file exceeds the daemon’s 512 KB read cap and is shown truncated — saving would clobber it, so it is read-only here":null,ue=w!==null&&w.readAt!==null&&A===null&&!x&&!W&&!s&&De===null&&oe&&C!==$,$e=async()=>{if(w===null||w.readAt===null||!ue)return;const ie=w,he=w.readAt,Ee=C;L(!0),z(null);try{const Ue=await n.run(Ye=>ie.scope==="skill"?s2e(e.name,ie.path,Ee,Ye):i2e(ie.path,Ee,Ye),{expectedRevision:he});if(Ue===null)return;F({verb:"Save",result:Ue}),Ue.verdict==="blocked"?I(Ee):(Z.current+=1,b({...ie,content:Ee,size:new TextEncoder().encode(Ee).byteLength,readAt:Ue.revision}),I(null),h())}catch(Ue){z(Ue instanceof Error?Ue.message:String(Ue))}finally{L(!1)}},Me=()=>{A!==null&&(Z.current+=1,b(A),T(Pv(A)),R(null),I(null))},de=()=>{A!==null&&(Z.current+=1,b(A),R(null),I(null))},ae=()=>{if(w!==null){if(A!==null){Me();return}T(Pv(w)),I(null),P(null)}},ke=()=>{z(null),d(e.name,!e.enabled).then(ie=>{ie!==null&&F({verb:e.enabled?"Disable":"Enable",result:ie})}).catch(ie=>z(ie instanceof Error?ie.message:String(ie)))},pe=(ie,he)=>{U(null),F({verb:ie,result:he}),R(null),V(null),h();const Ee=w!==null&&w.scope==="skill"?w.path:null,Ue=++Z.current;Ce().then(Ye=>{var st;if(Ue!==Z.current||f!=="skill")return;const ht=Ee!==null&&Ye.some(ct=>ct.path===Ee)?Ee:(st=Ye[0])==null?void 0:st.path;ht!==void 0?me("skill",ht):(b(null),T(""))})},xe=async()=>{if(w===null)return;if(Y!==null){V(null);return}const ie=w,he=Z.current;V("loading");try{const Ee=ie.scope==="skill"?await mG(e.name,ie.path,"baseline"):await gG(ie.path,"baseline");if(he!==Z.current||J.current!==ie)return;V({result:Ee})}catch(Ee){if(he!==Z.current||J.current!==ie)return;V({error:Ee instanceof Error?Ee.message:String(Ee)})}},Re=e.provenance!=="user-added",_e=Re||e.upstreamDir!==null,fe=s||W,Ie=oe||x,Se=Qy(e),be=M??_??v??(Y!==null&&Y!=="loading"&&"error"in Y?Y.error:null);return a.jsxs("aside",{"data-testid":"skills-drawer","data-skill":e.name,role:"complementary","aria-label":`Skill ${e.name}`,className:"wk-pg-skills-drawer",style:{top:`${o}px`},children:[a.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[a.jsx("span",{className:"font-semibold",style:{color:"var(--ink-high)"},children:e.name}),a.jsx(wSe,{kind:e.kind}),a.jsx(kSe,{provenance:e.provenance}),a.jsx(xSe,{skill:e}),a.jsx("button",{"data-testid":"skills-drawer-close",type:"button","aria-label":"Close skill",title:"Close skill",onClick:ve,className:"wk-btn wk-btn--quiet wk-btn--icon",children:"✕"})]}),be!==null&&a.jsx(Ft,{kind:en(be),what:"the skill",error:be,...M===null?{onRetry:()=>{Ce(),w!==null&&me(w.scope,w.path)}}:{}}),a.jsxs("div",{className:"flex flex-wrap items-center gap-x-3 gap-y-1",style:{color:"var(--ink-dim)"},children:[a.jsx(ut,{"data-testid":"skills-drawer-dir",text:e.dir}),e.editedAt!==null&&a.jsxs("span",{"data-testid":"skills-drawer-edited",title:e.editedAt,children:["edited ",ln(Date.parse(e.editedAt))]}),e.upstreamDir!==null&&a.jsxs("span",{"data-testid":"skills-drawer-upstream",style:{color:"var(--status-gate)"},title:"the last refresh found a name collision: upstream ships a skill under this name at another dir; Baseline side reads that directory",children:["upstream ships this name at ",e.upstreamDir]}),Se.contradiction!==null&&a.jsx("span",{"data-testid":"skills-drawer-portability-hint",role:"note",style:{color:"var(--status-gate)"},title:"the daemon's portability verdict disagrees with its portable flag; the badge and the counts follow `portable` (the admission key core reads) — worth reporting to wicked-crew",children:a.jsx(ut,{text:Se.contradiction})})]}),Se.reach!=="portable"&&a.jsxs("div",{"data-testid":"skills-drawer-portability","data-reach":Se.reach,"data-detailed":Se.detailed,className:"flex min-w-0 flex-col gap-1 rounded px-2 py-1.5",style:{color:"var(--ink-muted)"},children:[a.jsxs("span",{className:"min-w-0 break-words",children:[a.jsx("span",{className:"font-semibold",style:{color:"var(--ink-high)"},children:"Portability"})," — ",Se.reach==="needs-claude"?"Requires Claude to run.":"Edit this skill to make it available to more helpers.",a.jsx(ut,{text:bSe(Se)})]}),Se.detailed&&a.jsx("ul",{className:"flex min-w-0 flex-col gap-0.5","aria-label":"Portability reasons",children:Se.reasons.map(ie=>a.jsx("li",{"data-testid":"skills-drawer-portability-reason","data-reason":ie,className:"min-w-0 break-words",children:a.jsx(ut,{text:`${ie} — ${k3(ie)}`})},ie))}),Se.evidence.length>0&&a.jsx("ul",{"data-testid":"skills-drawer-portability-evidence","aria-label":"Portability evidence (file:line)",className:"flex min-w-0 flex-col gap-0.5",style:{color:"var(--ink-high)"},children:Se.evidence.map((ie,he)=>a.jsx("li",{"data-testid":"skills-drawer-portability-anchor",className:"min-w-0",children:a.jsx(ut,{text:ie})},`${he}:${ie}`))})]}),a.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[a.jsx("div",{className:"inline-flex items-center gap-2",children:a.jsx(jSe,{testId:"skills-drawer-toggle",name:e.name,enabled:e.enabled,busy:fe,onToggle:ke})}),a.jsx("span",{className:"flex-1"}),a.jsx("button",{"data-testid":"skills-reset-open",type:"button",disabled:fe||!Re,title:Re?"Restore every file this skill owns from the baseline (typed confirmation)":"a user-added skill has no baseline to reset to",onClick:()=>U("reset"),className:"wk-btn wk-btn--secondary",children:"Reset…"}),a.jsx("button",{"data-testid":"skills-replace-open",type:"button",disabled:fe,title:"Replace every file this skill owns from a pasted files map",onClick:()=>U("replace"),className:"wk-btn wk-btn--secondary",children:"Replace…"})]}),(!Re||fe)&&a.jsx("p",{className:"wk-field-note",children:Re?"Wait for the current change to finish.":"This added skill has no original version to restore."}),Te&&a.jsxs("div",{"data-testid":"skills-discard-prompt","data-leave-to":i??void 0,role:"alertdialog","aria-label":"Unsaved changes",className:"flex flex-wrap items-center gap-2 rounded px-3 py-2",style:{color:"var(--ink-muted)"},children:[a.jsxs("span",{children:["Unsaved edits to ",a.jsx("span",{className:"",children:w==null?void 0:w.path}),"."]}),a.jsx("span",{className:"flex-1"}),a.jsx("button",{"data-testid":"skills-keep-editing",type:"button",onClick:ye,className:"wk-btn wk-btn--quiet",children:"Keep editing"}),a.jsx("button",{"data-testid":"skills-discard",type:"button",onClick:le,className:"wk-btn wk-btn--danger",children:i!==null?a.jsxs(a.Fragment,{children:["Discard and open ",a.jsx("span",{className:"",children:i})]}):"Discard and close"})]}),a.jsxs("div",{role:"tablist","aria-label":"File trees",className:"flex items-center gap-1",children:[["skill","support"].map(ie=>a.jsx("button",{type:"button",role:"tab","data-testid":`skills-tab-${ie}`,"aria-selected":f===ie,disabled:Ie&&f!==ie,title:Ie&&f!==ie?"save or discard your edits first":WM[ie],onClick:()=>se(ie),className:"wk-tab",children:WM[ie]},ie)),f==="support"&&a.jsx("span",{"data-testid":"skills-support-note",className:"ml-2",style:{color:"var(--ink-dim)"},children:"Shared files used by your skills."})]}),Ie&&a.jsx("p",{className:"wk-field-note",children:oe?"Save or discard your edits before choosing another file or tab.":"Wait for the file to finish loading."}),a.jsxs("div",{className:"wk-pg-skills-editor-layout flex min-h-0 flex-1 gap-3",children:[a.jsx("nav",{"data-testid":"skills-file-tree","data-tab":f,"aria-label":WM[f],className:"flex w-48 shrink-0 flex-col gap-0.5 overflow-y-auto rounded p-1",children:je===null?a.jsx(nn,{"data-testid":"skills-files-loading"}):f==="skill"&&v!==null?a.jsx(ut,{"data-testid":"skills-files-error",text:v}):je.length===0?a.jsx(Zn,{"data-testid":"skills-files-empty",title:"No files"}):je.map(ie=>{var Ue;const he=w!==null&&w.scope===f&&w.path===ie.path,Ee=((Ue=ie.record)==null?void 0:Ue.conflict)===!0;return a.jsxs("button",{type:"button","data-testid":"skills-file","data-path":ie.path,"data-conflict":Ee?"true":void 0,"aria-current":he?"true":void 0,disabled:Ie,title:Ie?oe?"save or discard your edits first":"loading…":`${ie.path}${ie.size!==null?` · ${ie.size} B`:""}${Ee?" · refresh conflict: both sides changed (the effective side was kept)":""}`,onClick:()=>{F(null),me(f,ie.path)},className:"wk-btn wk-btn--secondary wk-pg-skills-file",children:[a.jsx("span",{className:"truncate",children:ie.path}),Ee&&a.jsx("span",{"aria-hidden":!0,className:"shrink-0",style:{color:"var(--status-gate)"},children:"⚑"})]},ie.path)})}),a.jsxs("div",{className:"flex min-w-0 flex-1 flex-col gap-2",children:[(x||Q)&&w===null?a.jsx(nn,{"data-testid":"skills-file-loading"}):_!==null?a.jsx(ut,{"data-testid":"skills-file-error",text:_}):w===null?a.jsx("p",{"data-testid":"skills-file-none",className:"",style:{color:"var(--ink-dim)"},children:"Pick a file to edit."}):a.jsxs(a.Fragment,{children:[a.jsxs("div",{className:"flex flex-wrap items-center gap-2",style:{color:"var(--ink-dim)"},children:[a.jsx("span",{"data-testid":"skills-file-path","data-scope":w.scope,style:{color:"var(--ink-muted)"},children:w.path}),a.jsxs("span",{"data-testid":"skills-file-size",title:"the file's full size in bytes",children:[w.size," B"]}),oe&&a.jsx("span",{"data-testid":"skills-file-dirty",style:{color:"var(--status-gate)"},children:"unsaved"}),x&&a.jsx("span",{"data-testid":"skills-file-loading",children:"loading…"}),a.jsx("span",{className:"flex-1"}),_e&&a.jsx("button",{"data-testid":"skills-baseline-open",type:"button","aria-pressed":Y!==null,disabled:x,title:Y===null?"Read the shipped copy of this file (the baseline side) — the new side of a refresh conflict, or the upstream file a name collision held back":"Hide the baseline side",onClick:()=>void xe(),className:"wk-btn wk-btn--secondary",children:Y===null?"Baseline side":"Hide baseline"})]}),De!==null&&a.jsx("p",{"data-testid":"skills-file-readonly",className:"",style:{color:"var(--status-gate)"},children:De}),O!==null&&a.jsxs("p",{"data-testid":"skills-file-stale-read","data-path":O,role:"status",className:"",style:{color:"var(--status-gate)"},children:[a.jsx("span",{className:"",children:O})," finished loading while you were typing — its content was not applied over your text. Save or discard your edits, then open it again."]}),A!==null&&a.jsxs("div",{"data-testid":"skills-file-conflict",role:"alert",className:"flex flex-wrap items-center gap-2 rounded px-3 py-2",style:{color:"var(--ink-muted)"},children:[a.jsx("span",{className:"font-semibold",children:"This file changed while you were editing."}),a.jsxs("span",{children:["Your draft is kept. Choose which version to save.",a.jsx(ut,{text:`${w.path}: ${A.size} B on the service; started from ${w.size} B, catalog revision ${w.readAt??"?"}`})]}),a.jsx("span",{className:"flex-1"}),a.jsx("button",{"data-testid":"skills-file-conflict-take",type:"button",onClick:Me,className:"wk-btn wk-btn--secondary",children:"Load the saved version (discard my edits)"}),a.jsx("button",{"data-testid":"skills-file-conflict-keep",type:"button",onClick:de,className:"wk-btn wk-btn--secondary",children:"Keep my draft — replace the saved version on Save"})]}),a.jsx("textarea",{"data-testid":"skills-editor","aria-label":`${w.path} content`,value:C,readOnly:De!==null||x,"aria-busy":x,spellCheck:!1,onChange:ie=>T(ie.target.value),className:"wk-field wk-pg-skills-code"}),Y!==null&&a.jsx("div",{"data-testid":"skills-baseline-view",className:"flex flex-col gap-1 rounded p-2",style:{color:"var(--ink-muted)"},children:Y==="loading"?a.jsx("span",{"data-testid":"skills-baseline-loading",children:"Loading the baseline side…"}):"error"in Y?a.jsx(ut,{"data-testid":"skills-baseline-error",text:Y.error}):a.jsxs(a.Fragment,{children:[a.jsxs("span",{className:"flex flex-wrap items-center gap-2",style:{color:"var(--ink-dim)"},children:[a.jsx("span",{children:"baseline side ·"}),a.jsx("span",{"data-testid":"skills-baseline-path",style:{color:"var(--ink-muted)"},title:"the plugin-relative path the daemon actually read (an upstream skill's dir for a held-back collision)",children:Y.result.path}),a.jsxs("span",{children:[Y.result.size," B"]}),Y.result.truncated&&a.jsx("span",{style:{color:"var(--status-gate)"},children:"truncated"}),Y.result.binary&&a.jsx("span",{style:{color:"var(--status-gate)"},children:"binary"}),a.jsx("span",{className:"ml-auto",children:"read-only"})]}),a.jsx("textarea",{"data-testid":"skills-baseline-content","aria-label":`${Y.result.path} baseline content`,value:Pv(Y.result),readOnly:!0,spellCheck:!1,className:"wk-field wk-pg-skills-code"})]})}),!ue&&a.jsx("p",{className:"wk-field-note",children:De??(A!==null?"Choose a version before saving.":s||W||x?"Wait for the current change or file to finish loading.":C===$&&$!==null?"Change the text to try saving again.":"Edit the file to enable Save.")}),a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx("button",{"data-testid":"skills-save",type:"button",disabled:!ue,title:A!==null?"this file changed on the daemon — load its version or keep your draft first":C===$&&$!==null?"the daemon blocked this exact content — change it to try again":"Save this file (the daemon runs its guards first)",onClick:()=>void $e(),className:"wk-btn wk-btn--primary",children:W?"Saving…":"Save"}),oe&&a.jsx("button",{"data-testid":"skills-discard-edits",type:"button",disabled:W,onClick:ae,className:"wk-btn wk-btn--quiet",children:"Discard edits"})]})]}),M!==null&&a.jsx(ut,{"data-testid":"skills-drawer-error",text:M}),B!==null&&a.jsx(K0,{verb:B.verb,result:B.result,testId:"skills-findings"})]})]}),q==="reset"&&a.jsx(YTt,{skill:e,writer:n,onClose:()=>U(null),onDone:ie=>pe("Reset",ie)}),q==="replace"&&a.jsx(SSe,{mode:"replace",name:e.name,writer:n,onClose:()=>U(null),onDone:(ie,he)=>pe("Replace",he)})]})}const ZTt=["all",...hce,"enabled","disabled","overridden","core","portable","not-portable","needs-claude"],eIt={query:"",chip:"all"};function nse(e,t){const n=t.query.trim().toLowerCase();return e.filter(r=>!(BPe(t.chip)&&r.kind!==t.chip||t.chip==="enabled"&&!r.enabled||t.chip==="disabled"&&r.enabled||t.chip==="overridden"&&r.provenance!=="override"||t.chip==="core"&&!r.core||t.chip==="portable"&&!r.portable||t.chip==="not-portable"&&Qy(r).reach!=="not-portable"||t.chip==="needs-claude"&&Qy(r).reach!=="needs-claude"||n!==""&&!r.name.toLowerCase().includes(n)&&!r.dir.toLowerCase().includes(n)))}function tIt({rows:e,facets:t,onFacets:n,selectedName:r,busyName:s,frozen:i,countsKnown:o=!0,onSelect:l,onToggle:c}){const u=nse(e,t),d=h=>nse(e,{query:t.query,chip:h}).length;return a.jsxs("section",{"data-testid":"skills-grid",className:"wk-card wk-pg-skills-catalog",children:[a.jsx(Qn,{children:"Skill catalog"}),a.jsxs("div",{"data-testid":"skills-filter","data-filter":t.chip,className:"flex min-w-0 flex-col gap-2",children:[a.jsxs("label",{className:"wk-pg-skills-search",children:[a.jsx("span",{className:"wk-field-label",children:"Search skills"}),a.jsx("input",{"data-testid":"skills-filter-search",className:"wk-field",value:t.query,placeholder:"Search by skill name or folder",onChange:h=>n({...t,query:h.target.value})})]}),a.jsx("div",{className:"wk-pg-skills-filters","aria-label":"Filter skills",children:ZTt.filter(h=>!o||d(h)>0||h===t.chip).map(h=>a.jsxs("button",{type:"button","data-testid":"skills-filter-chip","data-chip":h,"aria-pressed":t.chip===h,className:`wk-chip${t.chip===h?" wk-chip--active":""}`,"data-active":t.chip===h?"true":"false",onClick:()=>n({...t,chip:h}),children:[h==="all"?"All":h==="fork-worker"?"Worker":h==="needs-claude"?"Needs Claude":h==="not-portable"?"Not portable":h.charAt(0).toUpperCase()+h.slice(1)," ",o?d(h):null]},h))})]}),u.length===0?a.jsx(Zn,{"data-testid":"skills-grid-empty",title:e.length===0?"No skills yet":"No matching skills",body:e.length===0?"Add a skill to make it available to your helpers.":"Try another search or filter."}):a.jsx("ul",{className:"wk-pg-skills-list",children:u.map(h=>a.jsxs("li",{"data-testid":"skills-row","data-skill":h.name,"data-enabled":h.enabled,"aria-current":h.name===r?"true":void 0,"data-selected":h.name===r,"data-contradiction":Qy(h).contradiction??void 0,className:"wk-list-row wk-pg-skills-row",onClick:()=>l(h.name),children:[a.jsxs("div",{className:"min-w-0",children:[a.jsx("button",{type:"button","data-testid":"skills-row-name","aria-label":`Open ${h.name}`,className:"wk-btn wk-btn--quiet wk-pg-skills-name",onClick:f=>{f.stopPropagation(),l(h.name)},children:h.name}),a.jsxs("div",{className:"wk-list-row-meta flex flex-wrap gap-2",children:[a.jsx(wSe,{kind:h.kind}),a.jsx(kSe,{provenance:h.provenance}),a.jsx(xSe,{skill:h})]})]}),a.jsx("div",{className:"wk-list-row-actions",onClick:f=>f.stopPropagation(),children:a.jsx(jSe,{testId:"skills-toggle",name:h.name,enabled:h.enabled,busy:i||s===h.name,onToggle:()=>c(h)})})]},h.name))})]})}const UM={refresh:"Refresh baseline",analyze:"Analyze",publish:"Publish"};function nIt({navigate:e,search:t=""}){const[n,r]=k.useState(null),[s,i]=k.useState({kind:"loading"}),[o,l]=k.useState(eIt),[c,u]=k.useState(null),[d,h]=k.useState(null),[f,p]=k.useState(null),[m,g]=k.useState(null),[v,y]=k.useState(null),[w,b]=k.useState(!1),[x,S]=k.useState(null),[_,E]=k.useState(null),[C,T]=k.useState(0),[A,R]=k.useState(0),$=k.useRef(null),[I,O]=k.useState(null),[P,W]=k.useState(!1),L=k.useRef(null),[B,F]=k.useState(0);k.useLayoutEffect(()=>{const _e=()=>{var be;const Ie=L.current;if(Ie===null)return;const Se=Math.max(0,Math.round(Ie.getBoundingClientRect().bottom),Math.round(((be=Ie.closest(".wk-page-head"))==null?void 0:be.getBoundingClientRect().bottom)??0));F(ie=>ie===Se?ie:Se)};_e(),window.addEventListener("resize",_e),window.addEventListener("scroll",_e,!0);const fe=typeof ResizeObserver>"u"||L.current===null?null:new ResizeObserver(_e);return fe!==null&&L.current!==null&&fe.observe(L.current),()=>{window.removeEventListener("resize",_e),window.removeEventListener("scroll",_e,!0),fe==null||fe.disconnect()}},[]);const[M,z]=k.useState(null),q=k.useCallback(async()=>{try{const _e=await uu();O(_e.skills??null)}catch{O(null)}},[]),U=k.useCallback(async()=>{try{const _e=await GPe();return $.current=_e.revision,r(_e),E(null),i({kind:"loaded"}),T(fe=>fe+1),q(),_e}catch(_e){const fe=_e instanceof Error?_e.message:String(_e);return $.current!==null?E(kG(_e)?"the daemon no longer serves the skills catalog":fe):kG(_e)?i({kind:"unsupported"}):bG(_e)?(i({kind:"unavailable",message:xa(_e)??fe,errorKind:en(_e)}),q()):i({kind:"failed",message:fe,errorKind:en(_e)}),null}},[q]);k.useEffect(()=>{U()},[U]);const X=k.useCallback(async(_e,fe)=>{const Ie=(fe==null?void 0:fe.expectedRevision)??$.current;if(Ie===null)throw new Error("the skills catalog has not loaded — nothing to write against");R(Se=>Se+1);try{const Se=await _e(Ie);return $.current=Se.revision,Se}catch(Se){if(xG(Se))return S(xa(Se)??""),null;throw Se}finally{R(Se=>Se-1)}},[]),G=k.useCallback(async()=>{S(null),p(null),await U()},[U]),Q=k.useMemo(()=>({run:X,revision:()=>$.current,reload:G}),[X,G]),K=k.useMemo(()=>n===null?[]:XPe(n.manifest),[n]),Y=QPe(K),V=K.filter(_e=>_e.unpublished).length,Z=k.useMemo(()=>n===null?[]:e2e(n.manifest),[n]),J=k.useMemo(()=>n===null?null:n2e(n),[n]),te=k.useMemo(()=>n===null?[]:t2e(n.manifest),[n]),re=d2e(t),oe=re===null?null:K.find(_e=>_e.name===re)??null,ve=re!==null&&n!==null&&oe===null,Te=(oe==null?void 0:oe.name)??null;k.useEffect(()=>{z(null)},[Te]);const ye=_e=>{if(Te!==null&&_e!==Te&&P){z(_e);return}e(Hb(_e))},le=_e=>{const fe=M;z(null),_e&&fe!==null&&e(Hb(fe))},Ce=k.useCallback(async(_e,fe)=>{u(_e);try{const Ie=await X(Se=>a2e(_e,fe,Se));return Ie!==null&&Ie.verdict!=="blocked"&&await U(),Ie}finally{u(null)}},[X,U]),ge=_e=>{g(null),p(null),Ce(_e.name,!_e.enabled).then(fe=>{fe!==null&&(fe.verdict!=="clear"||fe.findings.length>0)&&p({verb:`${_e.enabled?"Disable":"Enable"} ${_e.name}`,result:fe})}).catch(fe=>g(fe instanceof Error?fe.message:String(fe)))},me=async _e=>{h(_e),g(null),p(null),y(null);try{let fe,Ie=null;if(_e==="analyze")fe=await wG();else if(_e==="publish"){const be=await X(ie=>yG(ie));fe=be,be!==null&&be.snapshot!==null&&(Ie=be.unchanged===!0?`Unchanged — generation ${be.snapshot.gen} is still current (${be.snapshot.skills} skills, ${be.snapshot.contentHash.slice(0,12)}); nothing was re-published.`:`Published — snapshot generation ${be.snapshot.gen} is current (${be.snapshot.skills} skills, ${be.snapshot.contentHash.slice(0,12)}); workers spawn with it from now on.`,q())}else{const be=await X(ie=>vG(ie));fe=be,be!==null&&be.verdict!=="blocked"&&(Ie=`Baseline refreshed — ${be.plugin_version} (${be.baseline.slice(0,12)}): ${be.taken.length} taken · ${be.kept.length} kept · ${be.added.length} added · ${be.removed.length} removed · ${be.conflicts.length} ${be.conflicts.length===1?"conflict":"conflicts"}. Your edits were kept; conflicts are flagged.`)}if(fe===null||(p({verb:UM[_e],result:fe}),_e==="analyze"||fe.verdict==="blocked")||await U()===null)return;y(Ie)}catch(fe){g(fe instanceof Error?fe.message:String(fe))}finally{h(null)}},[je,ce]=k.useState({busy:null,staged:null,result:null,error:null}),se=k.useCallback(async()=>{if($.current!==null)return $.current;try{const _e=await wG();return $.current=_e.revision,_e.revision}catch(_e){throw bG(_e)?new Error(`the catalog's revision could not be learned — POST /skills/analyze answered 503 too (${xa(_e)??"no detail"}), so the manifest itself is unreadable; recovery needs the daemon host (reseed the skills root), not this page`):_e}},[]),De=async _e=>{ce(fe=>({...fe,busy:_e,error:null,result:null}));try{const fe=await se();if(_e==="refresh"){const Se=await vG(fe);$.current=Se.revision,ce(be=>({...be,staged:Se.verdict==="blocked"?be.staged:Se,result:{verb:"Refresh baseline",result:Se}})),q();return}const Ie=await yG(fe);$.current=Ie.revision,ce(Se=>({...Se,result:{verb:"Publish",result:Ie}})),Ie.snapshot!==null&&(await U()!==null?(y(`Published — snapshot generation ${Ie.snapshot.gen} is current (${Ie.snapshot.skills} skills, ${Ie.snapshot.contentHash.slice(0,12)}); workers spawn with it from now on.`),p(Ie.findings.length>0?{verb:"Publish",result:Ie}:null),ce({busy:null,staged:null,result:null,error:null})):q())}catch(fe){if(xG(fe)){$.current=Zie(fe),ce(Ie=>({...Ie,error:`the catalog changed under this page (${xa(fe)??"a stale revision"}) — ${$.current!==null?`revision ${$.current} adopted from the refusal`:"the revision will be re-read"}; try again`}));return}ce(Ie=>({...Ie,error:fe instanceof Error?fe.message:String(fe)}))}finally{ce(fe=>({...fe,busy:null}))}},ue=(_e,fe)=>{b(!1),y(`Added ${_e} — publish to hand it to workers.`),p(fe.findings.length>0?{verb:`Add ${_e}`,result:fe}:null),U().then(Ie=>{Ie!==null&&e(Hb(_e))})},$e=n===null?null:VPe(n.manifest),Me=(n==null?void 0:n.current)??null,de=(n==null?void 0:n.manifest.published)??null,ae=x!==null||_!==null||A>0||d!==null,ke=ae?"Wait for the current change, or reload the catalog to continue.":null,pe=(_e,fe,Ie,Se)=>a.jsx("button",{type:"button","data-testid":fe,disabled:ae,title:Ie,onClick:()=>void me(_e),className:`wk-btn wk-btn--${Se?"primary":"secondary"}`,children:d===_e?`${UM[_e]}…`:UM[_e]}),xe=je.error??m??_??(s.kind==="failed"||s.kind==="unavailable"?s.message:null),Re=s.kind==="loaded"&&_===null&&m===null;return a.jsxs("div",{className:"wk-pg-skills-scroll",children:[a.jsxs(_a,{"data-testid":"skills-page",title:"Skills",intro:"Edit, turn off, or publish the skills your helpers can use.",actions:a.jsxs("div",{ref:L,"data-testid":"skills-header",className:"flex flex-wrap items-center gap-2",children:[s.kind==="loaded"&&a.jsxs(a.Fragment,{children:[a.jsx("button",{type:"button","data-testid":"skills-add-open",disabled:ae,onClick:()=>b(!0),className:"wk-btn wk-btn--secondary",children:"Add skill…"}),pe("analyze","skills-analyze","Check your changes before publishing",!1),pe("publish","skills-publish","Publish the skills your helpers can use",!0)]}),a.jsx("button",{type:"button","data-testid":"skills-reload",onClick:()=>void U(),className:"wk-btn wk-btn--secondary",children:"Refresh"}),s.kind==="loaded"&&a.jsx("div",{"data-testid":"skills-refresh","data-disabled":ae,children:a.jsx($s,{label:"More actions for skills",items:[{id:"refresh-baseline",label:"Refresh baseline",disabled:ke,onSelect:()=>void me("refresh")}]})}),ke!==null&&a.jsx("p",{className:"wk-field-note",children:ke})]}),children:[xe!==null&&a.jsx(Ft,{"data-testid":je.error!==null?"skills-recovery-error":m!==null?"skills-page-error":_!==null?"skills-stale":s.kind==="unavailable"?"skills-unavailable":"skills-error",kind:_!==null?"stale":s.kind==="failed"||s.kind==="unavailable"?s.errorKind:en(xe),what:"skills",error:xe,onRetry:()=>{g(null),U()}}),n!==null&&a.jsxs("div",{className:"wk-pg-skills-status",children:[a.jsxs("p",{title:de==null?void 0:de.at,children:[V>0||te.length>0?"Changes ready to publish":Me===null?"Ready to publish":(J==null?void 0:J.state)==="behind"?"Update available":(J==null?void 0:J.state)==="unknown"?"Update status unavailable":"Up to date",de!==null&&` · published ${ln(Date.parse(de.at))}`]}),a.jsx(ut,{"data-testid":"skills-root",text:[`root ${n.root}`,...$e!==null?[`baseline ${$e.plugin_version} · ${$e.source.kind} · ${$e.hash.slice(0,12)}${$e.git_sha!==null?` · ${$e.git_sha.slice(0,10)}`:""} · venv ${$e.venv} · captured ${$e.captured_at} · source ${$e.source.path}`]:[],Me===null?"never published — no snapshot":`snapshot generation ${Me.gen} is current${de!==null?` · published ${de.at} · ${de.contentHash.slice(0,12)}`:""}${V>0?` · ${V} unpublished ${V===1?"skill":"skills"}`:""} · ${Me.path}`,...I!==null?[`engine ${fG[I.state]}${I.current!==null?` · gen ${I.current.gen}`:""} · input ${I.engineInput??"unset"}`,...I.findings.map(_e=>`${_e.kind} · ${_e.severity} · ${_e.message}`)]:[]]}),$e!==null&&a.jsx("span",{hidden:!0,"data-testid":"skills-source","data-venv":$e.venv}),a.jsx("span",{hidden:!0,"data-testid":"skills-snapshot","data-generation":(Me==null?void 0:Me.gen)??"none","data-unpublished":V}),I!==null&&a.jsx("span",{hidden:!0,"data-testid":"skills-engine","data-state":I.state,children:I.findings.map((_e,fe)=>a.jsx("span",{"data-testid":"skills-engine-finding","data-kind":_e.kind,"data-severity":_e.severity},fe))})]}),s.kind==="loading"?a.jsx(nn,{"data-testid":"skills-loading"}):s.kind==="unsupported"?a.jsx(Zn,{"data-testid":"skills-unsupported",title:"Skills are unavailable in this version",body:"Update Studio’s service to manage skills here."}):s.kind==="unavailable"?a.jsxs("section",{"data-testid":"skills-recovery",className:"wk-card",children:[a.jsx(Qn,{children:"Restore skills"}),a.jsx("p",{children:"Refresh the installed skills, then publish to make them available again."}),I===null?a.jsx("p",{"data-testid":"skills-recovery-no-diagnostics",children:"Service details are unavailable. You can still try restoring skills."}):a.jsxs(a.Fragment,{children:[a.jsx("div",{"data-testid":"skills-recovery-state","data-state":I.state,children:a.jsx(ut,{text:`engine: ${I.state} — ${fG[I.state]} · input ${I.engineInput??"unset"}`})}),I.findings.map((_e,fe)=>a.jsx("div",{"data-testid":"skills-recovery-finding","data-kind":_e.kind,"data-severity":_e.severity,children:a.jsx(ut,{text:`${_e.kind} · ${_e.severity} · ${_e.message}`})},fe))]}),je.staged!==null&&a.jsxs("div",{"data-testid":"skills-recovery-staged",children:[a.jsx("p",{children:"Skills refreshed — publish to activate."}),a.jsx(ut,{text:`garden ${je.staged.plugin_version} staged · ${je.staged.baseline.slice(0,12)} · ${je.staged.conflicts.length} conflicts`})]}),a.jsxs("div",{className:"flex flex-wrap gap-2",children:[a.jsx("button",{type:"button","data-testid":"skills-recover-refresh",disabled:je.busy!==null,onClick:()=>void De("refresh"),className:"wk-btn wk-btn--secondary",children:je.busy==="refresh"?"Refreshing…":"Refresh baseline"}),a.jsx("button",{type:"button","data-testid":"skills-recover-publish",disabled:je.busy!==null,onClick:()=>void De("publish"),className:"wk-btn wk-btn--primary",children:je.busy==="publish"?"Publishing…":"Publish"})]}),je.busy!==null&&a.jsx("p",{"data-testid":"skills-recovery-busy",className:"wk-field-note",children:"Restoring skills…"}),je.result!==null&&a.jsx(K0,{verb:je.result.verb,result:je.result.result,testId:"skills-recovery-findings"})]}):s.kind==="loaded"?a.jsxs(a.Fragment,{children:[((J==null?void 0:J.state)==="behind"||te.length>0)&&a.jsxs("section",{"data-testid":"skills-behind","data-drift":(J==null?void 0:J.state)??"unknown","data-unpublished-support":te.length,className:"wk-card",children:[a.jsx(Qn,{children:"Updates for your helpers"}),a.jsx("p",{children:(J==null?void 0:J.state)==="behind"?"Refresh the installed skills, then publish to share the update with your helpers.":"Publish to share the updated support files with your helpers."}),(J==null?void 0:J.state)==="behind"&&a.jsx(ut,{"data-testid":"skills-behind-detail",text:`installed ${J.installed.source.plugin_version} · ${J.installed.source.kind} · ${J.installed.source.path} · ${J.installed.baseline??""} · baseline ${($e==null?void 0:$e.plugin_version)??"unknown"}`}),te.length>0&&a.jsx(ut,{"data-testid":"skills-behind-support",text:`${te.length} unpublished support files: ${te.map(_e=>_e.path).join(", ")}`}),a.jsxs("div",{className:"flex flex-wrap gap-2",children:[pe("refresh","skills-behind-refresh","Refresh the installed skills",(J==null?void 0:J.state)==="behind"),pe("publish","skills-behind-publish","Share updates with your helpers",(J==null?void 0:J.state)!=="behind")]}),ke!==null&&a.jsx("p",{className:"wk-field-note",children:ke})]}),(J==null?void 0:J.state)==="unknown"&&J.reason!==null&&a.jsxs("div",{"data-testid":"skills-drift-unknown",children:[a.jsx("p",{children:"The installed skills could not be compared."}),a.jsx(ut,{text:J.reason})]}),Re&&a.jsx("div",{"data-testid":"skills-kpis",children:a.jsx(fc,{items:[{label:Y.total===1?"skill":"skills",value:Y.total},{label:"enabled",value:Y.enabled},{label:"edited",value:Y.overridden},{label:"required",value:Y.core},{label:"portable",value:Y.portable}]})}),_!==null&&a.jsx("button",{"data-testid":"skills-stale-retry",type:"button",className:"wk-btn wk-btn--secondary",onClick:()=>void U(),children:"Reload catalog"}),v!==null&&a.jsxs("div",{"data-testid":"skills-note",children:[a.jsx("p",{children:"Changes saved — publish to share them with your helpers."}),a.jsx(ut,{text:v})]}),f!==null&&a.jsx(K0,{verb:f.verb,result:f.result,testId:"skills-page-findings"}),ve&&a.jsxs("p",{"data-testid":"skills-deep-link-missing",children:["No skill named ",re," in this catalog — showing every skill."]}),a.jsx(tIt,{rows:K,facets:o,onFacets:l,selectedName:(oe==null?void 0:oe.name)??null,busyName:c,frozen:ae,countsKnown:Re,onSelect:ye,onToggle:ge})]}):null]}),oe!==null&&a.jsx(JTt,{top:B,skill:oe,support:Z,writer:Q,catalogEpoch:C,busy:ae||c===oe.name,leaveTo:M,onClose:()=>e(Hb()),onLeave:le,onDirtyChange:W,onToggle:Ce,onChanged:()=>void U()},oe.name),w&&a.jsx(SSe,{mode:"add",name:null,writer:Q,onClose:()=>b(!1),onDone:ue}),x!==null&&a.jsxs("div",{"data-testid":"skills-conflict",role:"alertdialog","aria-label":"The skills catalog changed",className:"wk-card wk-pg-skills-conflict",children:[a.jsx("p",{children:"The skills catalog changed. Reload to continue; your unsaved edits are kept."}),a.jsx(ut,{text:x}),a.jsx("button",{"data-testid":"skills-conflict-reload",type:"button",onClick:()=>void G(),className:"wk-btn wk-btn--primary",children:"Reload catalog"})]})]})}const jy=40,rIt=50,rse=e=>`/repo-detail/${encodeURIComponent(e)}`,Xh=(e,t)=>`${e}\0${t}`;function NSe({projectId:e,navigate:t,selection:n,"data-testid":r="requirements-browser"}){const[s,i]=k.useState(""),[o,l]=k.useState(""),[c,u]=k.useState(0),[d,h]=k.useState(null),[f,p]=k.useState(0),m=()=>{h(null),p(I=>I+1)},g=`${e}\0${o}\0${c}`;k.useEffect(()=>{let I=!1;return cpe(e,{q:o,offset:c,limit:rIt}).then(O=>{I||h({at:g,read:O})}),()=>{I=!0}},[e,o,c,g,f]);const v=d!==null&&d.at===g?d.read:null,y=(n==null?void 0:n.max)??jy,w=n!==void 0&&n.chosen.size>=y,b=(v==null?void 0:v.state)==="ok"?v.body:null,x=(b==null?void 0:b.totals.total)??0,S=o===""?"requirements":`matching “${o}”`,_=b===null?"":`${x===0?o===""?"No requirements in this project’s repositories yet":`No requirement matches “${o}”`:b.offset>=x?`Past the last of ${x} ${S}: the list shrank, so go back a page`:`${b.offset+1}–${Math.min(b.offset+b.limit,x)} of ${x} ${S}`} · ${b.totals.ok} of ${b.totals.repos} ${b.totals.repos===1?"repository":"repositories"} read`,E=b!==null&&(b.rows.length===0||b.totals.repos===0),C=v===null||v.state!=="ok",T=E?"Attach a repository to this project first.":C?"Wait until requirements can be read.":null,A=(b==null?void 0:b.rows.filter(I=>I.state==="error").map(cw).join(`
|
|
946
|
-
`))||null,R=(v==null?void 0:v.state)==="failed"?v.why:A,$=`/repos/new?project=${encodeURIComponent(e)}`;return(v==null?void 0:v.state)==="absent"?a.jsx(Zn,{"data-testid":"requirements-absent",title:"Requirements aren’t available yet",body:"Update Studio’s service to use this view."}):a.jsxs("div",{"data-testid":r,"data-state":(v==null?void 0:v.state)??"loading",className:"wk-pg-proj-stack wk-reqs",children:[R!=null&&a.jsx(Ft,{"data-testid":"requirements-error",kind:en(R),what:"requirements",error:R,onRetry:m}),a.jsxs("form",{onSubmit:I=>{I.preventDefault(),T===null&&(u(0),l(s.trim()))},className:"wk-pg-proj-search",children:[a.jsxs("label",{className:"wk-pg-proj-field",children:["Search requirements",a.jsx("input",{"data-testid":"requirements-search",type:"search",className:"wk-field",placeholder:"Search requirements",value:s,onChange:I=>i(I.target.value),disabled:T!==null,"aria-describedby":T!==null?`${r}-search-note`:void 0})]}),a.jsx("button",{type:"submit",className:"wk-btn wk-btn--secondary",disabled:T!==null,"aria-describedby":T!==null?`${r}-search-note`:void 0,children:"Search"})]}),T!==null&&a.jsx("p",{id:`${r}-search-note`,className:"wk-field-note",children:T}),a.jsx("p",{role:"status",className:"sr-only",children:v===null?"Reading requirements…":v.state==="failed"?"The requirements could not be read.":E?"No repository in this project yet.":_}),v===null?a.jsx(nn,{"data-testid":"requirements-loading"}):E?a.jsx(Zn,{"data-testid":"requirements-empty",title:"No repository in this project yet",body:"Attach a repository to see its requirements.",action:a.jsx("a",{className:"wk-btn wk-btn--primary",href:$,onClick:I=>{I.preventDefault(),t($)},children:"Attach a repository"})}):b!==null&&a.jsxs(a.Fragment,{children:[a.jsx("p",{"data-testid":"requirements-totals",className:"wk-pg-proj-note",children:_}),x===0&&A===null&&a.jsx(Zn,{title:o===""?"No requirements yet":"No matching requirements",body:o===""?"Index the attached repositories to build their requirements maps.":"Try another search."}),[...b.rows].sort((I,O)=>+(I.state==="ok")-+(O.state==="ok")).map(I=>I.state!=="ok"?a.jsxs("div",{"data-testid":"requirements-repo-unread","data-repo":I.repo.id,"data-state":I.state,children:[a.jsxs("p",{className:"wk-pg-proj-note",children:[qz(I),I.state!=="dangling"&&a.jsxs(a.Fragment,{children:[" ",a.jsxs("a",{className:"wk-link","data-testid":"requirements-repo-open",href:rse(I.repo.id),onClick:O=>{O.preventDefault(),t(rse(I.repo.id))},children:["Open ",I.repo.name??"the repository"]})]})]}),a.jsx(ut,{text:cw(I)})]},I.repo.id):I.items.length>0?a.jsxs("div",{"data-testid":"requirements-repo","data-repo":I.repo.id,children:[a.jsxs("p",{className:"wk-pg-proj-note",children:[I.repo.name??"Unnamed repository"," · ",I.total," of ",I.corpus]}),a.jsx("ul",{className:"wk-pg-proj-list",children:I.items.map(O=>{const P=Xh(I.repo.id,O.key),W=(n==null?void 0:n.chosen.has(P))===!0;return a.jsxs("li",{"data-testid":"requirement","data-repo":I.repo.id,"data-key":O.key,className:`wk-list-row${n!==void 0?" wk-pg-proj-pick-row":""}`,children:[n!==void 0?a.jsx(Ls,{label:O.title,checked:W,disabled:!W&&w?`A draft takes at most ${y} requirements.`:null,onChange:()=>n.onToggle({repoId:I.repo.id,key:O.key,title:O.title}),"data-testid":"requirement-pick"}):a.jsx("span",{className:"wk-list-row-title",children:O.title}),a.jsxs("p",{className:"wk-list-row-meta",children:[O.reqId," · ",O.domain,O.risk&&a.jsxs(a.Fragment,{children:[" · ",a.jsx("span",{className:"wk-reqs-risk",children:"At risk"})]})]})]},O.key)})})]},I.repo.id):null),w&&a.jsxs("p",{className:"wk-field-note",children:["A draft takes at most ",y," requirements. Clear a choice to add another."]}),(x>b.limit||b.offset>0)&&a.jsxs(a.Fragment,{children:[a.jsxs("div",{className:"wk-pg-proj-actions",children:[a.jsx("button",{type:"button","data-testid":"requirements-prev",disabled:b.offset===0,onClick:()=>u(Math.max(0,b.offset-b.limit)),className:"wk-btn wk-btn--secondary",children:"Previous"}),a.jsx("button",{type:"button","data-testid":"requirements-next",disabled:b.offset+b.limit>=x,onClick:()=>u(b.offset+b.limit),className:"wk-btn wk-btn--secondary",children:"Next"})]}),(b.offset===0||b.offset+b.limit>=x)&&a.jsx("p",{className:"wk-field-note",children:b.offset===0?"You’re on the first page.":"You’re on the last page."})]})]})]})}function sIt({projectId:e,navigate:t}){var u;const n=fn(d=>d.projects);k.useEffect(()=>{fn.getState().projects.length===0&&fn.getState().load()},[]);const r=((u=n.find(d=>d.id===e))==null?void 0:u.name)??"This project",[s,i]=k.useState([]),o=k.useMemo(()=>new Map(s.map(d=>[Xh(d.repoId,d.key),d])),[s]),l=d=>i(h=>{const f=Xh(d.repoId,d.key);return h.some(p=>Xh(p.repoId,p.key)===f)?h.filter(p=>Xh(p.repoId,p.key)!==f):h.length>=jy?h:[...h,d]}),c=Cs(e);return a.jsx(_a,{"data-testid":"project-requirements-page",title:`Requirements · ${r}`,intro:"The requirements across this project’s repositories. Choose some to draft epics from them.",actions:a.jsxs(a.Fragment,{children:[a.jsxs("a",{className:"wk-btn wk-btn--quiet",href:c,onClick:d=>{d.preventDefault(),t(c)},children:["Back to ",r]}),a.jsx("button",{type:"button","data-testid":"requirements-draft",className:"wk-btn wk-btn--primary",onClick:()=>ci({workflowId:Vc,projectId:e,requirements:s,composerKey:"desk"}),children:s.length===0?"Draft epics":`Draft epics from ${s.length}`})]}),children:a.jsx("section",{className:"wk-card","aria-label":"Requirements",children:a.jsx(NSe,{projectId:e,navigate:t,selection:{chosen:o,onToggle:l}})})})}function Dv({to:e,navigate:t}){return k.useEffect(()=>{t(e,{replace:!0})},[e,t]),null}const iIt="qe-author-tests";function aIt({search:e,navigate:t}){return k.useEffect(()=>{const n=new URLSearchParams(e).get("project");t("/",{replace:!0}),ci({workflowId:iIt,projectId:n!==null&&n!==""&&n!=="default"?n:null})},[e,t]),null}const Sy={name:"Vibe — app builder",line:"Build and preview an app visually. Apps are already built by pipelines today."},oIt={"wicked-phase-report":{version:"0.14.0",html:'<!doctype html>\n<html lang="en">\n<head>\n<meta charset="utf-8">\n<!-- The bundle\'s own policy (the host frames it from a blob: URL, so no response header carries one): no network of\n any kind, no forms, no base, no workers. The same lines as crew\'s editor bundle policy (editors/csp.ts). -->\n<meta http-equiv="Content-Security-Policy" content="default-src \'none\'; script-src \'unsafe-inline\'; style-src \'unsafe-inline\'; img-src data:; font-src data:; connect-src \'none\'; form-action \'none\'; base-uri \'none\'; worker-src \'none\'; manifest-src \'none\'">\n<meta name="wicked-editor" content="wicked-phase-report">\n<meta name="wicked-editor-version" content="0.14.0">\n<title>Phase report</title>\n<style>\n /* The host\'s tokens arrive in host.hello / host.theme; these are plain fallbacks. */\n :root {\n --surface-base: #0d1117; --surface-card: #161b22; --surface-raised: #1c222b; --ink-high: #f0f3f6; --ink-body: #c9d1d9;\n --ink-muted: #8b949e; --border: #30363d; --accent: #58a6ff; --status-ok: #3fb950; --status-fail: #f85149;\n --font-sans: system-ui, sans-serif;\n }\n html, body { margin: 0; padding: 0; background: var(--surface-card); }\n /* The host caps the block\'s height: anything taller scrolls inside the frame, never clipped. */\n body { font: 13px/1.45 var(--font-sans), system-ui, sans-serif; color: var(--ink-body); overflow-x: hidden; }\n [hidden] { display: none !important; }\n button.sum {\n all: unset; box-sizing: border-box; display: flex; align-items: center; gap: 8px; width: 100%; min-height: 34px;\n padding: 6px 2px; cursor: pointer; color: var(--ink-high); font-weight: 500; border-radius: 6px;\n }\n button.sum:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }\n .sum-text { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }\n .expanded .sum-text { white-space: normal; }\n .dot { flex: 0 0 auto; width: 7px; height: 7px; border-radius: 50%; background: var(--accent); }\n .dot.wait { background: #d29922; }\n .dot.done { background: var(--status-ok); }\n .dot.bad { background: var(--status-fail); }\n .dash { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; padding: 4px 0 8px; }\n @media (max-width: 520px) { .dash { grid-template-columns: minmax(0, 1fr); } }\n /* A section of the Details panel (the host draws the heading): two tiles a row down to a narrow panel. */\n .in-panel .dash { padding-top: 0; }\n /* Two tiles a row are narrow: a list row\'s words and its time wrap instead of running past the tile\'s edge. */\n .in-panel ul.list li { flex-wrap: wrap; column-gap: 6px; }\n .in-panel ul.list li span:first-child { flex: 0 1 auto; min-width: 0; overflow-wrap: anywhere; }\n .in-panel ul.list li span:last-child { margin-left: auto; }\n @media (min-width: 300px) and (max-width: 520px) { .in-panel .dash { grid-template-columns: repeat(2, minmax(0, 1fr)); } }\n .tile { border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; background: var(--surface-raised); min-width: 0; }\n .tile.wide { grid-column: 1 / -1; }\n .label { display: block; font-size: 11px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: var(--ink-muted); margin-bottom: 4px; }\n .value { margin: 0; color: var(--ink-high); font-size: 15px; font-weight: 600; }\n .sub { margin: 2px 0 0; color: var(--ink-muted); font-size: 12px; }\n .run { margin-top: 6px; }\n .run + .run { border-top: 1px solid var(--border); padding-top: 6px; }\n .run-title { margin: 0 0 4px; font-size: 12px; color: var(--ink-body); }\n .chips { display: flex; flex-wrap: wrap; gap: 4px; }\n .chip { display: inline-flex; align-items: center; gap: 4px; padding: 1px 8px; border-radius: 999px; font-size: 12px; border: 1px solid var(--border); color: var(--ink-body); }\n .chip.ok { color: var(--status-ok); border-color: color-mix(in srgb, var(--status-ok) 45%, transparent); }\n .chip.bad { color: var(--status-fail); border-color: color-mix(in srgb, var(--status-fail) 45%, transparent); }\n .chip .re { color: var(--ink-muted); font-size: 11px; }\n ul.list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 3px; }\n ul.list li { display: flex; justify-content: space-between; gap: 10px; font-size: 12px; }\n ul.list li span:first-child { flex: 0 0 auto; }\n ul.list li span:last-child { color: var(--ink-muted); text-align: right; min-width: 0; }\n ul.list li.open span:first-child { color: var(--ink-high); font-weight: 600; }\n .gap { margin: 0 0 6px; font-size: 12px; color: var(--status-fail); }\n .rg { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin: 2px 0; font-size: 12px; color: var(--ink-muted); }\n .rg-arrow { color: var(--ink-muted); }\n .rg-chip { display: inline-flex; align-items: center; height: 18px; padding: 0 8px; border-radius: 999px; border: 1px solid var(--border); color: var(--ink-body); font-weight: 600; font-size: 11px; }\n .rg-chip.rg-high, .rg-chip.rg-highest { color: var(--status-warn, #d29922); border-color: color-mix(in srgb, var(--status-warn, #d29922) 55%, transparent); }\n /* The working document (spike 3) */\n #wd { border: 1px solid var(--border); border-radius: 10px; background: var(--surface-raised); padding: 10px 12px 12px; margin: 0 0 8px; }\n .wd-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }\n .wd-title { margin: 0; font-size: 14px; color: var(--ink-high); }\n .wd-ver { font-size: 12px; color: var(--ink-muted); }\n .wd-note { margin: 2px 0 8px; font-size: 12px; color: var(--ink-muted); }\n .wd-sec { padding: 6px 0; border-top: 1px solid var(--border); }\n .wd-sec h4 { margin: 0 0 3px; display: flex; justify-content: space-between; gap: 8px; font-size: 11px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: var(--ink-muted); }\n .wd-who { font-weight: 400; letter-spacing: 0; text-transform: none; }\n .wd-text { white-space: pre-wrap; overflow-wrap: anywhere; color: var(--ink-body); border-radius: 6px; padding: 2px 4px; margin: 0 -4px; cursor: text; min-height: 1.4em; max-height: 18em; overflow-y: auto; }\n .wd-now { margin: 0 0 4px; padding: 4px 6px; border-radius: 6px; background: var(--surface-card); white-space: pre-wrap; font-size: 12px; color: var(--ink-high); max-height: 10em; overflow-y: auto; }\n .wd-text:hover { background: var(--surface-card); }\n .wd-text:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }\n .wd-text.empty { color: var(--ink-muted); font-style: italic; }\n .wd-gen { display: block; color: var(--ink-body); }\n .wd-gen-note { margin: 2px 0 0; color: var(--ink-muted); font-size: 11px; }\n .wd-input { box-sizing: border-box; width: 100%; font: inherit; color: var(--ink-high); background: var(--surface-card); border: 1px solid var(--accent); border-radius: 6px; padding: 6px 8px; resize: vertical; }\n .wd-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-top: 6px; }\n .wd-btn { font: inherit; font-size: 12px; padding: 4px 12px; border-radius: 999px; border: 1px solid var(--border); background: transparent; color: var(--ink-body); cursor: pointer; }\n .wd-btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-fg, #fff); }\n .wd-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }\n .wd-effect { font-size: 12px; color: var(--ink-muted); }\n .wd-status { margin: 8px 0 0; font-size: 12px; color: var(--ink-body); }\n .wd-status.bad { color: var(--status-fail); }\n .wd-trail { list-style: none; margin: 8px 0 0; padding: 6px 0 0; border-top: 1px solid var(--border); display: flex; flex-direction: column; gap: 2px; font-size: 12px; color: var(--ink-muted); }\n</style>\n</head>\n<body>\n<main id="root" class="folded">\n <button type="button" class="sum" id="sum" aria-expanded="false" aria-controls="dash">\n <span class="dot" id="dot" aria-hidden="true"></span><span class="sum-text" id="sum-text">Reading the job’s events…</span>\n </button>\n <section id="dash" class="dash" hidden aria-label="Phase report"></section>\n <section id="wd" hidden aria-label="Working document"></section>\n</main>\n<script>var wickedEditor=(function(he){"use strict";const Z="wicked.editor",Ye={card:{interactive:!0,aspect:"auto",actions:[]}},Je={understand:"research",test_plan:"plan",design:"plan",architecture:"plan",build:"build",produce:"write",test:"test",domain_coverage:"test",review:"review",critique:"review",security_review:"review",walkthrough_review:"walkthrough",deliver:"deliver"};function Xe(e,t){return e==="run"?t==="operator"?"yours":"tool":Je[e]??"tool"}const Ze={research:"Research",brainstorm:"Brainstorm",plan:"Plan",build:"Build",write:"Write",test:"Test",review:"Review",walkthrough:"Walkthrough",deliver:"Deliver",yours:"Yours"};function et(e){const t=e.replace(/[-_]+/g," ").trim();return t===""?"Step":t[0].toUpperCase()+t.slice(1)}const tt={"pa-scope":"Scope",scope:"Scope",clarify:"Clarify",design:"Plan",plan:"Plan",architecture:"Plan","test-plan":"Test plan",test_plan:"Test plan",triage:"Triage",reproduce:"Reproduce",build:"Build",implement:"Build",fix:"Fix",produce:"Write","adversarial-review":"Challenge",critique:"Review",review:"Review","code-review":"Review","security-review":"Security check",security_review:"Security check",test:"Test",verify:"Check",domain_coverage:"Coverage",walkthrough:"Walkthrough",walkthrough_review:"Walkthrough",deliver:"Deliver",understand:"Research",research:"Research",recon:"Research"};function nt(e,t,a,o){const n=tt[t.toLowerCase()];return n!==void 0?n:e!=="tool"?Ze[e]:o[a]??et(t||a)}function de(e,t={}){return nt(Xe(e),e,e,t)}function st(){return{loaded:!1,seen:new Set,startedAt:null,lastAt:null,finished:null,units:new Map,gates:[],checks:[],costUsd:0,tokens:0,usageReports:0,usageByOrd:new Map,power:null,marks:[]}}const S=e=>typeof e=="string"&&e!==""?e:null,_=e=>typeof e=="number"&&Number.isFinite(e)?e:null,ot=new Set(["longer_than_estimated","tests_failing","changes_undone","rigor_jumped","spread","other"]);function ae(e,t,a,o){const n=e.pauses.at(-1);if(n===void 0||o<n.at)return;const r=n.choice==="continue"&&!n.byPerson&&t!=="continue"&&(e.checkpoints.at(-1)?.n??n.n)===n.n;n.choice!==null&&!r||(n.choice=t,n.byPerson=a,n.answeredAt=o)}function G(e){return e.power??(e.power={intake:null,rigor:null,history:[],checkpoints:[],turn:null,handoff:null,on:null,pauses:[]}),e.power}function ce(e,t){let a=e.units.get(t);return a===void 0&&(a={ord:t,step:null,seat:null,seatName:null,state:"planned",startedAt:null,finishedAt:null},e.units.set(t,a)),a}function it(e,t){let a=!1;for(const o of t){if(e.seen.has(o.id))continue;e.seen.add(o.id),a=!0,e.lastAt=Math.max(e.lastAt??0,o.at),(e.startedAt===null||o.at<e.startedAt)&&(e.startedAt=o.at);const n=o.data,r=o.ord;switch(o.topic){case"wicked.run.session.started":e.startedAt=o.at;break;case"wicked.run.session.finished":e.finished={outcome:S(n.outcome)??"completed",at:o.at},e.power!=null&&ae(e.power,n.outcome==="cancelled"?"stop":"continue",!1,o.at);break;case"wicked.run.session.resumed":e.finished!==null&&o.at>=e.finished.at&&(e.finished=null);for(const s of e.gates)s.answeredAt===null&&s.openedAt<=o.at&&(s.answeredAt=o.at);break;case"wicked.run.unit.planned":if(r!==null){const s=ce(e,r);s.step=S(n.step)??s.step}break;case"wicked.run.unit.assigned":if(r!==null){const s=ce(e,r);s.seat=S(n.seat),s.seatName=S(n.seatName)}break;case"wicked.run.unit.started":if(r!==null){e.finished!==null&&o.at>=e.finished.at&&(e.finished=null);const s=ce(e,r);s.state="running",s.startedAt??(s.startedAt=o.at),s.finishedAt=null;for(const i of e.gates)i.answeredAt===null&&i.openedAt<=o.at&&(i.answeredAt=o.at)}break;case"wicked.run.unit.finished":if(r!==null){const s=ce(e,r),i=S(n.outcome);s.state=i==="denied"?"denied":i==="failed"?"failed":"done",s.finishedAt=o.at}break;case"wicked.run.human.awaited":r!==null&&e.gates.push({ord:r,kind:S(n.kind)??"question",openedAt:o.at,answeredAt:null});break;case"wicked.run.checks.evaluated":{e.marks.push({at:o.at,ord:r,kind:"checks",outcome:n.passed===!0?"passed":"failed"});const s=Array.isArray(n.checks)?n.checks.map($=>({name:S($.name)??"check",exitCode:_($.exitCode),timedOut:$.timedOut===!0,durationMs:_($.durationMs)})):[],i=n.reusedFrom,g=$=>Array.isArray($)?$.filter(l=>typeof l=="string"):[];e.checks.push({ord:r,attempt:_(n.attempt),floor:S(n.floor),outcome:S(n.outcome),passed:n.passed===!0,checks:s,at:o.at,reusedFrom:i!=null&&typeof i=="object"?{phase:S(i.phase),ord:_(i.ord),reused:g(i.reused),fresh:g(i.fresh)}:null});break}case"wicked.run.intake.planned":{const s=G(e),i=S(n.rigor);i!==null&&(s.intake={rigor:i,score:_(n.score),at:o.at},s.rigor??(s.rigor=i)),s.on??(s.on=!0);break}case"wicked.run.rigor.rescored":{const s=G(e),i=_(n.seq),g=S(n.to);if(i===null||g===null||s.history.some($=>$.seq===i))break;s.history.push({seq:i,at:o.at,trigger:S(n.trigger)??"checkpoint",from:S(n.from),to:g,direction:S(n.direction)??"same",planned:_(n.planned),actual:_(n.actual),checkpoint:_(n.checkpoint),byKind:S(n.byKind)}),s.history.sort(($,l)=>$.seq-l.seq),s.rigor=s.history.at(-1).to,S(n.byKind)==="person"&&S(n.direction)==="up"&&ae(s,"continue_high",!0,o.at);break}case"wicked.run.checkpoint.reached":{const s=G(e),i=_(n.checkpoint);if(i===null||s.checkpoints.some(g=>g.n===i))break;if(s.checkpoints.push({n:i,at:o.at,trigger:S(n.trigger),rigor:S(n.rigor),picked:_(n.picked)??0,paused:n.paused===!0}),s.checkpoints.sort((g,$)=>g.n-$.n),n.paused===!0){const g=Array.isArray(n.pauseKinds)?n.pauseKinds.filter($=>typeof $=="string"&&ot.has($)):[];s.pauses.push({n:i,at:o.at,kinds:g,choice:null,byPerson:!1,answeredAt:null})}break}case"wicked.run.turn.started":case"wicked.run.turn.completed":{e.marks.push({at:o.at,ord:r,kind:o.topic==="wicked.run.turn.started"?"turn.started":"turn.completed",outcome:S(n.outcome)});const s=G(e),i=_(n.turn);if(i===null||s.turn!==null&&i<s.turn.n)break;o.topic==="wicked.run.turn.started"&&ae(s,"continue",!1,o.at),s.turn={n:i,seatName:S(n.seatName)??S(n.seat),running:o.topic==="wicked.run.turn.started",outcome:S(n.outcome),at:o.at};break}case"wicked.run.handoff.stepped":{const s=G(e),i=_(n.round)??1,g=S(n.step);if(g===null)break;ae(s,"continue",!1,o.at),g==="checks"&&e.marks.push({at:o.at,ord:r,kind:"handoff.checks",outcome:S(n.status)}),(s.handoff===null||i>s.handoff.round)&&(s.handoff={round:i,steps:new Map}),i===s.handoff.round&&s.handoff.steps.set(g,{status:S(n.status)??"pending",seatName:S(n.seatName)??S(n.seat),at:o.at});break}case"wicked.run.power.toggled":G(e).on=n.on===!0,n.on!==!0&&ae(G(e),"switch_phased",S(n.byKind)==="person",o.at);break;case"wicked.run.usage.reported":if(e.costUsd+=_(n.costUsd)??0,e.tokens+=(_(n.inputTokens)??0)+(_(n.outputTokens)??0),e.usageReports+=1,r!==null){const s=e.usageByOrd.get(r)??{costUsd:0,tokens:0,reports:0};s.costUsd+=_(n.costUsd)??0,s.tokens+=(_(n.inputTokens)??0)+(_(n.outputTokens)??0),s.reports+=1,e.usageByOrd.set(r,s)}break}}return a}function I(e){return e===void 0?"Step":e.step!==null?de(e.step):`Step ${e.ord}`}const at={plan_approval:"Approve the plan",escalation:"A failed check or review",deliver:"Deliver",consent:"Install consent",repeat:"Keep going?",phase_review:"Review a step",question:"A question"},rt=new Set(["plan_approval","deliver","consent"]);function Y(e){return at[e]??e.replace(/[_-]+/g," ").replace(/^./u,t=>t.toUpperCase())}function M(e){return e.finished!==null?[]:e.gates.filter(t=>t.answeredAt===null)}function Se(e){return[...e.units.keys()].sort((t,a)=>t-a)}function Ee(e){const t=[...e.units.values()].filter(o=>o.state==="running").sort((o,n)=>(n.startedAt??0)-(o.startedAt??0));if(t[0]!==void 0)return t[0];const a=M(e).at(-1);return a!==void 0?e.units.get(a.ord)??null:null}function ge(e,t){if(e===void 0)return null;const a=e.checks.length,o=e.checks.filter(s=>s.exitCode===0&&!s.timedOut).length,n=a===0?"no checks found":o===a?`${a} passed`:`${o} of ${a} passed`,r=e.reusedFrom?.phase!=null?` (reused from ${de(e.reusedFrom.phase)})`:e.reusedFrom?.ord!=null?` (reused from ${I(t.units.get(e.reusedFrom.ord))})`:"";return`checks: ${n}${r}`}const ee=(e,t,a=`${t}s`)=>`${e} ${e===1?t:a}`;function Ne(e){return e.handoff!==null?"Hand-off":e.turn!==null||e.checkpoints.length>0?"Building":"Intake"}function lt(e){const t=e.trigger==="intake"?"intake":e.trigger==="operator"||e.byKind==="person"?"raised by you":e.trigger==="plugin"?"raised by a plugin":e.trigger==="doc_edit"?"a working-document edit":e.trigger==="toggle"?"power switch":e.checkpoint!==null?`checkpoint ${e.checkpoint}`:e.trigger==="pre_handoff"?"before hand-off":e.trigger.replace(/_/g," "),a=e.trigger==="intake"?e.actual!==null?`, score ${e.actual}`:"":e.planned!==null&&e.actual!==null&&e.planned!==e.actual?`, score ${e.planned} → ${e.actual}`:"";return`${m(e.at)} ${t}${a}`}const ut={rescore:"Re-score",checks:"Checks",review:"Review",security:"Security",qe:"QE",compliance:"Compliance"},Ce=["rescore","checks","review","security","qe","compliance"];function ke(e){if(!e.loaded)return"Reading the job’s events…";if(e.power!==null&&e.finished===null&&(e.power.turn!==null||e.power.checkpoints.length>0||e.power.handoff!==null)){const r=e.power,s=[Ne(r)];r.rigor!==null&&s.push(`rigor ${r.rigor}${r.intake!==null&&r.rigor!==r.intake.rigor?" ↑":""}`),r.checkpoints.length>0&&s.push(`checkpoint ${r.checkpoints.at(-1).n}`);const i=ge(e.checks.at(-1),e);i!==null&&s.push(i);const g=M(e).length;return g>0&&s.push(`${ee(g,"decision")} open`),s.join(" · ")}const t=Se(e),a=[];if(e.finished!==null){const r=[...e.units.values()].filter(s=>s.state==="done").length;a.push(e.finished.outcome==="completed"?"Finished":e.finished.outcome==="cancelled"?"Stopped":"Failed"),t.length>0&&a.push(`${r} of ${ee(t.length,"step")} done`)}else{const r=Ee(e);if(r!==null){a.push(I(r));const s=t.indexOf(r.ord);s>=0&&a.push(`step ${s+1} of ${t.length}`)}else e.startedAt!==null?a.push(t.length>0?`Planned · ${ee(t.length,"step")}`:"Starting"):a.push("No events yet")}const o=ge(e.checks.at(-1),e);o!==null&&a.push(o);const n=M(e).length;return n>0&&a.push(`${ee(n,"decision")} open`),a.join(" · ")}function m(e){if(e===null)return"—";const t=new Date(e);return`${String(t.getHours()).padStart(2,"0")}:${String(t.getMinutes()).padStart(2,"0")}`}function te(e){const t=Math.max(0,Math.round(e/6e4));return t<60?`${t} min`:`${Math.floor(t/60)} h ${String(t%60).padStart(2,"0")} min`}function xe(e,t){const a=Se(e),o=Ee(e),n=M(e);let r;if(e.finished!==null)r={value:ke(e).split(" · ")[0]??"Finished",sub:`${ee(a.length,"step")} · ${ee(e.gates.length,"decision")} · ${m(e.startedAt)}–${m(e.finished.at)}`};else if(n.length>0){const h=n[n.length-1];r={value:`Waiting on you · ${Y(h.kind)}`,sub:`${I(e.units.get(h.ord))} · since ${m(h.openedAt)}`}}else if(o!==null){const h=a.indexOf(o.ord);r={value:`${I(o)}${h>=0?` · step ${h+1} of ${a.length}`:""}`,sub:`${o.seatName??o.seat??"A helper"} · started ${m(o.startedAt)}`}}else r={value:e.startedAt===null?"No events yet":"Starting",sub:e.startedAt===null?"The report fills in as the job runs":`Started ${m(e.startedAt)}`};const s=e.checks.slice(-3).reverse().map(h=>{const b=new Set(h.reusedFrom?.reused??[]),E=Fe(h);return{title:`${h.ord!==null?I(e.units.get(h.ord)??{step:null,ord:h.ord}):"Checks"} · ${E} · ${m(h.at)}`,chips:h.checks.map(x=>({name:x.name.replace(/_/g," "),ok:x.exitCode===0&&!x.timedOut,reused:b.has(x.name),note:x.durationMs!==null&&x.durationMs>=6e4?te(x.durationMs):x.durationMs!==null?`${Math.max(1,Math.round(x.durationMs/1e3))} s`:null})),reused:h.reusedFrom!==null?`Reused from ${h.reusedFrom.phase!==null?de(h.reusedFrom.phase):I(e.units.get(h.reusedFrom.ord??-1))}: ${h.reusedFrom.reused.join(", ")||"none"}${h.reusedFrom.fresh.length>0?` · ran again: ${h.reusedFrom.fresh.join(", ")}`:""}`:null}}),i=e.gates.filter(h=>h.answeredAt!==null),g={open:n.length,answered:i.length,items:e.gates.slice(-5).map(h=>({text:rt.has(h.kind)?Y(h.kind):`${Y(h.kind)} · ${I(e.units.get(h.ord))}`,when:h.answeredAt!==null?`answered ${m(h.answeredAt)}`:n.includes(h)?`open since ${m(h.openedAt)}`:m(h.openedAt),open:n.includes(h)}))},$=new Map;for(const h of[...e.units.values()].sort((b,E)=>b.ord-E.ord)){const b=h.seatName??h.seat;if(b===null||h.seat==="bash")continue;const E=$.get(b)??[],x=I(h);E.includes(x)||E.push(x),$.set(b,E)}const l=[...$.entries()].map(([h,b])=>({name:h,steps:b.join(", ")})),C=e.finished?.at??t,K={value:e.startedAt===null?"—":te(C-e.startedAt),sub:e.usageReports===0?"No usage reported yet":`≈ $${e.costUsd.toFixed(2)} · ${Math.round(e.tokens/1e3).toLocaleString("en-US")}k tokens`},A=e.power;let J=null,D=null;if(A!==null){const h=A.history.filter(b=>b.direction!=="same"||b.trigger==="intake");if(J=[...A.intake!==null&&!h.some(b=>b.trigger==="intake")?[{to:A.intake.rigor,arrow:"",words:`${m(A.intake.at)} intake${A.intake.score!==null?`, score ${A.intake.score}`:""}`}]:[],...h.map(b=>({to:b.to,arrow:b.trigger==="intake"?"":b.direction==="up"?"↑":b.direction==="down"?"↓":"",words:lt(b)}))],A.handoff!==null&&(D=[...A.handoff.steps.entries()].sort((b,E)=>Ce.indexOf(b[0])-Ce.indexOf(E[0])).map(([b,E])=>({name:`${ut[b]??b}${E.seatName!==null&&b!=="checks"?` · ${E.seatName}`:""}`,status:E.status}))),e.finished===null&&n.length===0&&(A.turn!==null||A.checkpoints.length>0||A.handoff!==null)){const b=Ne(A),E=A.checkpoints.at(-1);r={value:[b,E!==void 0?`checkpoint ${E.n}`:null,A.turn!==null?`turn ${A.turn.n}`:null].filter(x=>x!==null).join(" · "),sub:A.turn!==null?`${A.turn.seatName??"The orchestrator"} · orchestrator · ${A.turn.running?`turn ${A.turn.n} started ${m(A.turn.at)}`:`turn ${A.turn.n} ended ${m(A.turn.at)}`}`:A.intake!==null?`QE plan set rigor ${A.intake.rigor} at ${m(A.intake.at)}`:"Starting"}}}return{now:r,checks:s,decisions:g,helpers:l,time:K,rigor:J,handoff:D}}const dt=new Set(["intake","plan","build","checks","review","security","qe","deliver"]);function ct(e){if(e===null||typeof e!="object")return null;const t=e;if(typeof t.phase!="string"||!dt.has(t.phase)||typeof t.label!="string"||!Array.isArray(t.ords))return null;const a=t.ords.filter(o=>typeof o=="number"&&Number.isFinite(o));return{phase:t.phase,label:t.label.slice(0,40),ords:a}}function pe(e){return e===null||e.phase==="build"}function ne(e,t){return t!==null&&e.ords.includes(t)}function we(e,t){const a=t.ords.map(s=>e.units.get(s)).filter(s=>s!==void 0),o=a.reduce((s,i)=>i.startedAt!==null&&(s===null||i.startedAt<s)?i.startedAt:s,null),n=a.map(s=>s.finishedAt),r=n.length>0&&n.every(s=>s!==null)?Math.max(...n):null;return{start:o,end:r,running:a.some(s=>s.state==="running"),failed:a.some(s=>s.state==="failed"||s.state==="denied")}}function _e(e,t){const a={build:[],checks:[]},o=e.marks.filter(l=>l.ord===t||l.kind==="handoff.checks"&&l.ord===null).map(l=>l);for(const l of e.power?.pauses??[])l.answeredAt!==null&&o.push({at:l.answeredAt,ord:t,kind:"pause.answered",outcome:null});o.sort((l,C)=>l.at-C.at);let n=null,r=0,s=!1;const i=l=>{(n==="build"||n==="checks")&&a[n].push({start:r,end:l}),n=null},g=(l,C)=>{n=l,r=C};for(const l of o){if(n==="afterPause"){const C=r;n=null,l.kind==="turn.started"?g("build",C):g("checks",C)}switch(l.kind){case"turn.started":n!=="build"&&(i(l.at),g("build",l.at)),s=!1;break;case"turn.completed":l.outcome==="handoff"?(i(l.at),g("checks",l.at)):l.outcome==="paused"?s=!0:(l.outcome==="failed"||l.outcome==="cap")&&i(l.at);break;case"pause.answered":n==="build"&&s&&(i(l.at),n="afterPause",r=l.at,s=!1);break;case"checks":n===null&&g("checks",l.at),n==="checks"&&l.outcome==="passed"&&i(l.at);break;case"handoff.checks":l.outcome==="running"||l.outcome==="pending"?n!=="checks"&&(i(l.at),g("checks",l.at)):(n==="checks"||n==="build")&&i(l.at);break}}const $=n;return($==="build"||$==="checks")&&a[$].push({start:r,end:e.finished!==null?Math.max(r,e.finished.at):null}),a}function Oe(e){if(e.length===0)return null;const t=o=>o.end!==null?`${m(o.start)}–${m(o.end)}`:`since ${m(o.start)}`,a=e.slice(0,3).map(t).join(" + ");return e.length>3?`${a} + ${e.length-3} more`:a}function Re(e,t){return e.reduce((a,o)=>a+((o.end??t)-o.start),0)}const Le={checks:"checks",review:"review",security:"security",qe:"qe"};function re(e,t){if(t.phase==="build"&&e.power?.turn!=null)return e.power.turn.running?"working":e.power.handoff!==null||e.finished!==null?"handed off":"between turns";const a=t.phase==="checks"?pt(e,t):null;if(a!==null)return a;const o=Le[t.phase],n=o!==void 0?e.power?.handoff?.steps.get(o):void 0;if(n!==void 0)return n.status==="passed"?t.phase==="review"||t.phase==="security"?"approved":"passed":n.status==="failed"?t.phase==="review"?"changes asked":"failed":n.status;if(M(e).filter(i=>ne(t,i.ord)).length>0)return"waiting on you";const s=we(e,t);return s.running?"running":s.failed?"did not pass":s.end!==null?"done":s.start===null?"not started":"running"}function Fe(e){return e.outcome==="passed"||e.passed?"passed":e.outcome==="timed_out"?"timed out":e.outcome==="not_run"?"did not run":"failed"}function pt(e,t){const a=me(e,t)?.at(-1);if(a===void 0)return null;if(M(e).some(n=>ne(t,n.ord)&&n.openedAt>=a.start))return"waiting on you";const o=e.checks.filter(n=>ne(t,n.ord)&&n.at>=a.start&&(a.end===null||n.at<=a.end)).at(-1);if(o!==void 0){const n=Fe(o),r=e.power?.handoff?.steps.get("checks");return n!=="passed"&&r?.status==="passed"&&r.at>=o.at?`${n} · overridden`:n}return a.end===null?"running":null}function Pe(e,t){const a=Le[t.phase];return a!==void 0?e.power?.handoff?.steps.get(a)??null:null}function me(e,t){return t.phase!=="build"&&t.phase!=="checks"||t.ords.length!==1||e.power===null?null:_e(e,t.ords[0])[t.phase]}function Te(e,t,a={}){if(!e.loaded)return"Reading the job’s events…";const o=e.power,n=[t.label];if(t.phase==="intake")o?.intake!=null?n.push(`rigor ${o.intake.rigor}${o.intake.score!==null?` (score ${o.intake.score})`:""}`):n.push(re(e,t));else if(t.phase==="build"){const s=o?.turn?.n??0;s>0&&n.push(`${s} ${s===1?"turn":"turns"}`),(o?.checkpoints.length??0)>0&&n.push(`checkpoint ${o.checkpoints.at(-1).n}`),o?.rigor!=null&&n.push(`rigor ${o.rigor}${o.intake!==null&&o.rigor!==o.intake.rigor?" ↑":""}`),o?.turn?.running===!0&&n.push("working")}else if(t.phase==="checks"){const s=e.checks.filter(i=>ne(t,i.ord)).at(-1);n.push(ge(s,e)??re(e,t))}else{const s=t.ords.map(g=>e.units.get(g)).find(g=>g?.seatName!=null||g?.seat!=null),i=s!==void 0?s.seatName??s.seat:Pe(e,t)?.seatName??null;i!=null&&t.phase!=="deliver"&&n.push(i),n.push(re(e,t))}const r=me(e,t);if(a.times!==!1)if(r!==null){const s=Oe(r);s!==null&&n.push(s)}else{const s=we(e,t);s.start!==null&&n.push(s.end!==null?`${m(s.start)}–${m(s.end)}`:`since ${m(s.start)}`)}return n.filter(s=>s!=="").join(" · ")}function ft(e,t,a){const o=xe(e,a),n=we(e,t),r=t.phase==="build"?e.power?.turn??null:null,s=Pe(e,t),i=me(e,t),g=i!==null&&i.length>0?`${Oe(i)} · ${te(Re(i,a))}`:n.start!==null&&i===null?n.end!==null?`${m(n.start)}–${m(n.end)} · ${te(n.end-n.start)}`:`Since ${m(n.start)} · ${te(a-n.start)}`:r!==null?`${r.seatName??"The orchestrator"} · orchestrator · turn ${r.n} ${r.running?`since ${m(r.at)}`:`ended ${m(r.at)}`}`:s!==null?`${s.seatName!==null?`${s.seatName} · `:""}${s.status==="running"||s.status==="pending"?"since":"at"} ${m(s.at)}`:"Not started yet",$={value:`${t.label} · ${re(e,t)}`,sub:g},l=i!==null?_e(e,t.ords[0]).checks:null,C=c=>l!==null&&l.some(R=>c.openedAt>=R.start&&(R.end===null||c.openedAt<=R.end)),K=c=>ne(t,c.ord)&&(l===null||C(c)===(t.phase==="checks")),A=e.gates.filter(K),J=M(e).filter(K),D=A.map(c=>({at:c.openedAt,text:Y(c.kind),when:c.answeredAt!==null?`answered ${m(c.answeredAt)}`:`open since ${m(c.openedAt)}`,open:J.includes(c)})),h=t.phase==="build"&&i!==null?e.power?.pauses??[]:[];for(const c of h)D.push({at:c.at,text:`Checkpoint ${c.n} pause`,when:c.answeredAt!==null?`answered ${m(c.answeredAt)}`:`open since ${m(c.at)}`,open:c.answeredAt===null});D.sort((c,R)=>c.at-R.at);const b={open:D.filter(c=>c.open).length,answered:D.filter(c=>!c.open&&c.when.startsWith("answered")).length,items:D.slice(-5).map(({text:c,when:R,open:H})=>({text:c,when:R,open:H}))},E=e.checks.filter(c=>ne(t,c.ord)),x=o.checks.filter((c,R)=>{const H=e.checks.slice(-3).reverse()[R];return H!==void 0&&E.includes(H)}),se=t.ords.map(c=>e.units.get(c)).filter(c=>c!==void 0&&(c.seatName??c.seat)!==null&&c.seat!=="bash").map(c=>c.seatName??c.seat);se.length===0&&s?.seatName!=null&&se.push(s.seatName);const d=[...new Set(se)].map(c=>({name:c,steps:t.label}));let W=o.time;if(i!==null&&t.phase==="build"){const c=t.ords.map(U=>e.usageByOrd.get(U)).filter(U=>U!==void 0),R=c.reduce((U,X)=>U+X.costUsd,0),H=c.reduce((U,X)=>U+X.tokens,0);W={value:i.length===0?"—":te(Re(i,a)),sub:c.length===0?"No usage reported yet":`≈ $${R.toFixed(2)} · ${Math.round(H/1e3).toLocaleString("en-US")}k tokens`}}const ue=t.phase==="intake"?["now","rigor"]:t.phase==="build"?["now","rigor","decisions","time"]:t.phase==="checks"?A.length>0?["now","checks","decisions"]:["now","checks"]:t.phase==="deliver"?["now","decisions"]:["now","helpers","decisions"],V=t.phase==="intake"&&o.rigor!==null?o.rigor.slice(0,1):o.rigor;return{...o,now:$,checks:x,decisions:b,helpers:d,rigor:V,time:W,handoff:null,tiles:ue}}function ht(e,t){if(t===null){const i=e.loaded?e.finished!==null?e.finished.outcome==="completed"?"ok":"fail":M(e).length>0?"wait":"run":"none";return{text:ke(e),tone:i}}const a=Te(e,t,{times:!1}),o=`${t.label} · `,n=a.startsWith(o)?a.slice(o.length):a===t.label?"":a;if(!e.loaded)return{text:n,tone:"none"};const r=re(e,t),s=/^(working|running)$/.test(r)?"run":r==="waiting on you"?"wait":/^(passed|approved|done|handed off)$/.test(r)||/\\bpassed\\b/.test(r)?"ok":/^(failed|did not pass|changes asked)$/.test(r)||/\\bfailed\\b/.test(r)?"fail":"none";return{text:n,tone:s}}const gt=["goal","approach","decisions","constraints","questions","next"],le={goal:"Goal",approach:"Approach",decisions:"Decisions",constraints:"Constraints and steering",questions:"Open questions",next:"Next and trailing work"},qe={goal:"Saving tells the next step.",approach:"Saving tells the next step.",next:"Saving tells the next step.",constraints:"Saving tells the next step and every step after it.",decisions:"Recorded here. Not sent to a step.",questions:"Recorded here. Not sent to a step."},kt="Edits steer the next step. They can raise rigor, never lower it.";function ve(e){return e?.eventLines!==!0}const wt={claude:"Claude Code",codex:"Codex",agy:"Antigravity",antigravity:"Antigravity",pi:"Pi CLI",opencode:"OpenCode",copilot:"Copilot"};function De(e){if(e.kind==="human")return e.id==="local"?"You":e.id;if(e.kind==="plugin")return/^plugin:wicked-phase-report@/u.test(e.id)?"Phase report (plugin)":`${e.id.replace(/^plugin:/u,"").replace(/@.*$/u,"")} (plugin)`;if(e.kind==="agent"){const t=e.id.replace(/^agent:/u,"");return`${wt[t]??t} (agent)`}return"From the job’s request"}function je(e){return e.kind!=="agent"&&/^agent:/u.test(e.id)?{kind:"agent",id:e.id}:e}function mt(e,t){const a=[];for(let o=e.trail.length-1;o>=0;o-=1){const n=e.trail[o];if(!n.sections.includes(t))continue;const r=De(je(n.author));a.includes(r)||a.push(r)}return a.length>0?a.join(", "):null}const Me=e=>{const t=new Date(e);return`${String(t.getHours()).padStart(2,"0")}:${String(t.getMinutes()).padStart(2,"0")}`};function vt(e,t=()=>null){const a=e.ord!==null?t(e.ord):null;return a!==null&&a!==""?a:e.step!==null&&e.step!==""&&!e.step.includes(":")?de(e.step):e.ord!==null?`step ${e.ord}`:"a step"}function $t(e,t){return e===void 0?null:e.error!==null?`not sent: ${e.error}`:e.pickedUp!==null?`picked up at ${vt(e.pickedUp,t)} ${Me(e.pickedUp.at)}`:"waiting for the next step"}function bt(e,t=6,a){return e.trail.slice(-t).reverse().map(o=>{const n=je(o.author),r=[`v${o.version}`,De(n),o.sections.map(i=>le[i]).join(", "),Me(o.at)],s=$t(e.steers.find(i=>i.id===o.steerId),a);return s!==null?r.push(s):(n.kind==="plugin"||n.kind==="agent")&&r.push("not sent to a step"),r.join(" · ")})}const yt={longer_than_estimated:"taking much longer than estimated",tests_failing:"the tests kept failing",changes_undone:"changes were undone",rigor_jumped:"rigor jumped two levels at once",spread:"the change spread into another product",other:"it grew more complex than planned"},At={continue_high:"continue at high rigor",continue:"continue as planned",switch_phased:"switch to phased steps",stop:"stop the job"},St={checks:{failed:"the checks failed: fix them and hand off again",skipped:"the checks were skipped"},review:{failed:"the review asked for changes: make them and hand off again",skipped:"the review was skipped"},security:{failed:"the security check found problems: fix them and hand off again",skipped:"the security check was skipped"},qe:{failed:"QE acceptance did not pass: fix it and hand off again",skipped:"QE acceptance was skipped"},compliance:{failed:"the compliance check did not pass",skipped:"the compliance check was skipped"}},$e=e=>e.length>0?` (${e.map(t=>yt[t]??t).join("; ")})`:"";function We(e){const t=[],a=[],o=[];for(const s of e.gates)s.answeredAt!==null&&t.push({at:s.answeredAt,line:`${Y(s.kind)} · answered ${m(s.answeredAt)}`});const n=e.power;for(const s of n?.pauses??[])s.choice!==null&&s.answeredAt!==null?t.push({at:s.answeredAt,line:`Checkpoint ${s.n} pause${$e(s.kinds)} · ${s.byPerson?"you chose":"answered"}: ${At[s.choice]} · ${m(s.answeredAt)}`}):e.finished===null&&a.push(`Waiting on you · checkpoint ${s.n} paused${$e(s.kinds)}: split it, switch to phased steps, continue at high rigor, or stop? · since ${m(s.at)}`);for(const s of M(e))a.push(`Waiting on you · ${Y(s.kind)} · since ${m(s.openedAt)}`);if(n?.handoff!=null)for(const[s,i]of n.handoff.steps){const g=St[s];g!==void 0&&(i.status==="failed"?o.push(`After hand-off round ${n.handoff.round} · ${g.failed}`):i.status==="skipped"&&o.push(`After hand-off round ${n.handoff.round} · ${g.skipped}`))}return{decisions:t.sort((s,i)=>s.at-i.at).map(s=>s.line),questions:a,next:o}}function Et(e){const t=e.gates.map(a=>`Waiting on you · ${Y(a.kind)} · since ${m(a.openedAt)}`);for(const a of e.power?.pauses??[])t.push(`Waiting on you · checkpoint ${a.n} paused${$e(a.kinds)}: split it, switch to phased steps, continue at high rigor, or stop? · since ${m(a.at)}`);return t}function be(e,t){return e===t||e.startsWith(t)}function Nt(e,t){const a=e.split(`\n`).map(o=>o.trim());return t.filter(o=>!a.some(n=>be(n,o)))}function Ct(e,t,a,o=[],n=[]){const r=t.split(`\n`).map(l=>l.trim()).filter(l=>l!==""),s=l=>e==="next"?n.includes(l):o.includes(l),i=e==="decisions"?r:r.filter(l=>!s(l)||a.includes(l)),g=a.filter(l=>!i.some(C=>be(C,l))),$=[...i,...g];return $.join(`\n`)===r.join(`\n`)?null:$.join(`\n`)}const Ue="wicked-phase-report";function Be(){let e=null,t=!0,a=!1;const o=st();let n=null,r=!1,s="",i=null,g="reading",$=!0,l=null,C=null,K=0,A=!1,J=Promise.resolve(),D=0;const h=new Map,b=(u,p)=>{if(e===null)return Promise.resolve({ok:!1,error:{code:"unavailable",message:"not connected"}});D+=1;const v=`r${D}`;return new Promise(f=>{h.set(v,f),e?.postMessage({p:Z,v:1,type:u,id:v,payload:p}),setTimeout(()=>{h.delete(v)&&f({ok:!1,error:{code:"timeout",message:"no answer"}})},25e3)})},E=u=>document.getElementById(u),x=(u,p)=>e?.postMessage({p:Z,v:1,type:u,payload:p}),se=u=>{if(!(typeof u!="object"||u===null))for(const[p,v]of Object.entries(u))/^--[a-z0-9-]+$/.test(p)&&typeof v=="string"&&v.length<=200&&!/url\\(/i.test(v)&&document.documentElement.style.setProperty(p,v)},d=(u,p,v)=>{const f=document.createElement(u);return p!==null&&(f.className=p),v!==void 0&&(f.textContent=v),f};function W(u,p=!1){const v=d("div",p?"tile wide":"tile");return v.appendChild(d("span","label",u)),v}let ue=0;function V(){const u=Math.ceil(document.getElementById("root")?.getBoundingClientRect().height??0);u>0&&u!==ue&&(ue=u,x("ui.height",{px:u}))}function c(){const u=E("root");if(u.className=`${t?"folded":"expanded"}${r?" in-panel":""}`,E("sum").hidden=r,r&&e!==null){const f=ht(o,n),L=`${f.tone}\\0${f.text}`;L!==s&&(s=L,x("panel.summary",{text:f.text.slice(0,80),tone:f.tone}))}E("sum").setAttribute("aria-expanded",t?"false":"true"),E("sum").title=t?"Show the phase report":"Fold the phase report",E("sum-text").textContent=n!==null?Te(o,n):ke(o);const p=E("dot");p.className=`dot${o.finished!==null?o.finished.outcome==="completed"?" done":" bad":M(o).length>0?" wait":""}`;const v=E("dash");if(v.hidden=t,v.replaceChildren(),!t){const f=n!==null?ft(o,n,Date.now()):{...xe(o,Date.now()),tiles:null},L=w=>f.tiles===null||f.tiles.includes(w);a&&v.appendChild(d("p","gap tile wide","The job’s earlier events could not be read; this shows what happened since."));const k=W("Now",!0);k.append(d("p","value",f.now.value),d("p","sub",f.now.sub));const y=W("Checks",!0);f.checks.length===0&&y.appendChild(d("p","sub","No checks have run yet."));for(const w of f.checks){const N=d("div","run");N.appendChild(d("p","run-title",w.title));const q=d("div","chips");for(const ie of w.chips){const Ae=d("span",`chip ${ie.ok?"ok":"bad"}`,`${ie.name} ${ie.ok?"✓":"✗"}`);ie.reused?Ae.appendChild(d("span","re","reused")):ie.note!==null&&Ae.appendChild(d("span","re",ie.note)),q.appendChild(Ae)}N.appendChild(q),w.reused!==null&&N.appendChild(d("p","sub",w.reused)),y.appendChild(N)}const F=f.rigor!==null?W("Rigor history",f.handoff===null):null;if(F!==null&&f.rigor!==null){f.rigor.length===0&&F.appendChild(d("p","sub","Not set yet."));for(const w of f.rigor){const N=d("div","rg");w.arrow!==""&&N.appendChild(d("span","rg-arrow",w.arrow)),N.append(d("span",`rg-chip rg-${w.to}`,w.to),d("span",null,w.words)),F.appendChild(N)}}const P=f.handoff!==null?W("Hand-off"):null;if(P!==null&&f.handoff!==null){const w=d("ul","list");for(const N of f.handoff){const q=d("li",N.status==="running"||N.status==="pending"?"open":null);q.append(d("span",null,N.name),d("span",null,N.status)),w.appendChild(q)}P.appendChild(w)}const Q=W("Decisions");Q.appendChild(d("p","value",`${f.decisions.open} open · ${f.decisions.answered} answered`));const j=d("ul","list");f.decisions.items.length===0&&j.appendChild(d("li",null,"None yet"));for(const w of f.decisions.items){const N=d("li",w.open?"open":null);N.append(d("span",null,w.text),d("span",null,w.when)),j.appendChild(N)}Q.appendChild(j);const oe=W("Helpers"),B=d("ul","list");f.helpers.length===0&&B.appendChild(d("li",null,"None yet"));for(const w of f.helpers){const N=d("li",null);N.append(d("span",null,w.name),d("span",null,w.steps)),B.appendChild(N)}oe.appendChild(B);const O=W("Time and cost",!0);O.append(d("p","value",f.time.value),d("p","sub",f.time.sub));const T=[["now",k],["rigor",F],["handoff",P],["checks",y],["decisions",Q],["helpers",oe],["time",O]];v.append(...T.filter(([w,N])=>N!==null&&L(w)).map(([,w])=>w))}z(),V()}async function R(){K+=1;const u=K,p=await b("doc.read",{});u===K&&(p.ok&&p.payload!==void 0?(i=p.payload.view,g="ready",A=!1,i.doc!==null&&ye()):p.error?.code==="unsupported"||p.error?.code==="not_granted"?g="unsupported":A=!0,z(),V())}function H(u){const p=J.then(u,u);return J=p.then(()=>{},()=>{}),p}function U(u,p){u.saving||(u.saving=!0,z(),H(async()=>{const v=await b("doc.propose_edit",{base:u.base,section:u.section,text:p,origin:"typed"});if(u.saving=!1,v.ok){const f=v.payload?.version;C={text:typeof f=="number"?`Saved as version ${f}. ${qe[u.section]}`:"Nothing changed.",bad:!1},l===u&&Ve()===p?(l=null,queueMicrotask(Ge)):l===u&&typeof f=="number"&&(u.base=f)}else v.error?.code==="head_moved"?(C={text:"Someone changed the document meanwhile. Your text is kept: check the section’s new text above it, then save again.",bad:!0},u.conflict=!0):C={text:`Not saved: ${v.error?.message??"no answer"}`,bad:!0};await R(),l===u&&u.conflict&&i?.doc!=null&&(u.base=i.doc.head,(i.sections?.[u.section]??"")===u.opened&&(C={text:"Other sections changed meanwhile, not this one. Your text is kept: press Save again.",bad:!0})),z(),V()}))}let X=!1;const Ie=new Set;let fe=!1;const He=new Set;function ye(){if(!(!pe(n)||X||g!=="ready"||i?.doc==null||!o.loaded)&&ve(i)){if(l!==null){fe=!0;return}X=!0,H(async()=>{X=!1;const u=We(o);for(const p of["decisions","questions","next"]){if(l!==null){fe=!0;return}if(!ve(i))return;if(!He.has(p))for(let v=0;v<2;v+=1){if(i===null||i.doc===null||i.sections===null)return;const f=Nt(i.sections[p],u[p]),L=Ct(p,i.sections[p],u[p],Et(o),[...Ie]);if(L===null)break;const k=await b("doc.propose_edit",{base:i.doc.head,section:p,text:L,origin:"generated"});if(await R(),k.ok&&p==="next")for(const y of f)Ie.add(y);if(k.ok)break;if(k.error?.code!=="head_moved"){He.add(p);break}}}})}}function Ke(u,p){if(!pe(n)||!o.loaded||!ve(i))return[];const v=p.split(`\n`).map(f=>f.trim());return We(o)[u].filter(f=>!v.some(L=>be(L,f)))}function Ve(){const u=document.querySelector("#wd textarea");return u===null?null:u.value}function ze(u){if(l!==null&&l.section!==u&&Ve()!==l.opened){C={text:`Save or cancel ${le[l.section]} first.`,bad:!0},z();return}const p=i?.sections?.[u]??"";l={section:u,base:i?.doc?.head??-1,opened:p,saving:!1,conflict:!1},C=null,z(),V(),queueMicrotask(()=>document.querySelector("#wd textarea")?.focus())}function Qe(){l=null,C=null,z(),V(),Ge()}function Ge(){l!==null||!fe||(fe=!1,ye())}function z(){const u=E("wd");if(u.hidden=t||!pe(n)||!$,t||!pe(n)||!$)return;const p=l!==null?u.querySelector(`textarea[data-section="${l.section}"]`):null,v=p!==null&&document.activeElement===p,f=p!==null?[p.selectionStart,p.selectionEnd]:null;u.replaceChildren();const L=d("div","wd-head");if(L.append(d("h3","wd-title","Working document")),i?.doc!=null&&L.append(d("span","wd-ver",`version ${i.doc.head}`)),u.append(L,d("p","wd-note",kt)),g==="unsupported"){u.append(d("p","sub","This version of studio’s service keeps no working document."));return}if(A){const k=d("p","wd-status bad","The working document could not be read just now. "),y=d("button","wd-btn","Try again");y.type="button",y.addEventListener("click",()=>{R()}),k.append(y),u.append(k)}if(g==="reading"){u.append(d("p","sub","Reading the working document…"));return}for(const k of gt){const y=d("div","wd-sec");y.dataset.section=k;const F=d("h4",null,le[k]),P=k==="decisions"||k==="questions"||k==="next"?Ke(k,i?.sections?.[k]??""):[],Q=(i!==null?mt(i,k):null)??(P.length>0?"Phase report (plugin)":null);Q!==null&&F.append(d("span","wd-who",Q)),y.append(F);const j=i?.sections?.[k]??"",oe=k==="decisions"||k==="questions"||k==="next"?Ke(k,j):[],B=l;if(B!==null&&B.section===k){B.conflict&&j!==B.opened&&y.append(d("p","wd-now",`Now: ${j.trim()===""?"(empty)":j}`));const O=p??document.createElement("textarea");p===null&&(O.className="wd-input",O.dataset.section=k,O.value=j,O.setAttribute("aria-label",le[k]),O.maxLength=4e3,O.addEventListener("keydown",q=>{q.key==="Enter"&&(q.metaKey||q.ctrlKey)&&(q.preventDefault(),l!==null&&U(l,O.value)),q.key==="Escape"&&(q.preventDefault(),Qe())})),O.rows=Math.min(10,Math.max(3,O.value.split(`\n`).length+1));const T=d("div","wd-bar"),w=d("button","wd-btn primary",B.saving?"Saving…":"Save");w.type="button",w.disabled=B.saving,w.addEventListener("click",()=>{l!==null&&U(l,O.value)});const N=d("button","wd-btn","Cancel");N.type="button",N.addEventListener("click",Qe),T.append(w,N,d("span","wd-effect",qe[k])),y.append(O,T),p!==null&&v&&(O.focus(),f!==null&&O.setSelectionRange(f[0],f[1]))}else{const O=j.trim()===""&&oe.length===0,T=d("div",`wd-text${O?" empty":""}`,O?k==="goal"&&i?.doc==null?"Not started. Edit a section to start the working document.":"Nothing yet.":j);for(const w of oe)T.append(d("span","wd-gen",w));T.tabIndex=0,T.setAttribute("role","button"),T.setAttribute("aria-label",`Edit ${le[k]}`),T.addEventListener("click",()=>ze(k)),T.addEventListener("keydown",w=>{(w.key==="Enter"||w.key===" ")&&(w.preventDefault(),ze(k))}),y.append(T),oe.length>0&&y.append(d("p","wd-gen-note",i?.doc==null?"From the job’s events. Not saved: no working document is started yet (a person’s first edit starts it).":"From the job’s events. Not saved in the working document yet."))}u.append(y)}if(C!==null){const k=d("p",`wd-status${C.bad?" bad":""}`,C.text);k.setAttribute("role","status"),u.append(k)}if(i!==null&&i.trail.length>0){const k=d("ol","wd-trail");k.setAttribute("aria-label","Versions");for(const y of bt(i,6,F=>{const P=o.units.get(F);return P!==void 0&&P.step!==null&&!P.step.includes(":")?I(P):null}))k.append(d("li",null,y));u.append(k)}}function xt(u){const p=u.data;if(e!==null||p?.p!==Z||p.v!==1||p.type!=="host.hello"||!u.ports[0])return;const v=p.payload??{};se(v.theme);const f=v.observe??null;n=ct(f?.scope);const L=f?.panel;r=typeof L=="object"&&L!==null&&L.slot==="run.details",s="",e=u.ports[0],ue=0,e.onmessage=k=>{const y=k.data;if(y?.p!==Z||y.v!==1)return;if(typeof y.re=="string"){const P=h.get(y.re);P!==void 0&&(h.delete(y.re),P({ok:y.ok===!0,...y.payload!==void 0?{payload:y.payload}:{},...y.error!==void 0?{error:y.error}:{}}));return}const F=y.payload??{};switch(y.type){case"host.ping":y.id&&e?.postMessage({p:Z,v:1,re:y.id,ok:!0,payload:{}});break;case void 0:break;case"host.theme":se(F.theme),c();break;case"host.fold":t=F.folded===!0,c();break;case"events.batch":{F.gap==="history-unavailable"&&(a=!0);const P=Array.isArray(F.rows)?F.rows:[],Q=!o.loaded;o.loaded=!0,(it(o,P)||Q)&&c(),ye();break}case"doc.changed":R();break;case"host.teardown":e?.close(),e=null;break}},e.start(),c(),$=Array.isArray(v.grants)&&v.grants.includes("doc.read"),$?R():(g="unsupported",z())}E("sum").addEventListener("click",()=>x("ui.fold",{folded:!t})),new ResizeObserver(()=>V()).observe(document.body),setInterval(()=>{!t&&o.finished===null&&o.startedAt!==null&&c()},3e4),window.addEventListener("message",xt),c();const _t=document.querySelector(\'meta[name="wicked-editor-version"]\')?.getAttribute("content")??"0.0.0";parent.postMessage({p:Z,v:1,type:"plugin.ready",payload:{editor:Ue,version:_t,protocol:[3],surfaces:Ye}},"*")}return typeof window<"u"&&document.querySelector(`meta[name="wicked-editor"][content="${Ue}"]`)!==null&&Be(),he.start=Be,Object.defineProperty(he,Symbol.toStringTag,{value:"Module"}),he})({});\n<\/script>\n</body>\n</html>\n',sha256:"ec00e4506cef4ac8a75d78eb15348a91b5ded12261bfc64e6c46bf624489b3f2"}},lIt="wicked-phase-report",cIt="Phase report",uIt=[3],dIt="run-thread",hIt="One section per phase in a job’s Details: what is happening, checks, rigor and the working document.",fIt=[{slot:"run.details",id:"phase",title:"{phase}",instances:"per-phase",order:10,defaultOpen:"current",summary:"plugin"}],pIt={icon:"icon.svg",color:"#4f46e5",live:!0},mIt=[{topic:"wicked.run.session.*",why:"to know when the job started, resumed and ended"},{topic:"wicked.run.unit.*",why:"to show which step is running, who works on it and how far along the plan it is"},{topic:"wicked.run.human.awaited",why:"to count the decisions waiting on you"},{topic:"wicked.run.checks.evaluated",why:"to show what the checks found, and when a result was reused from an earlier step"},{topic:"wicked.run.usage.reported",why:"to add up the time and the cost"},{topic:"wicked.run.intake.planned",why:"to show the rigor the QE plan set at intake"},{topic:"wicked.run.rigor.rescored",why:"to show the rigor history: each change, what triggered it and the score"},{topic:"wicked.run.checkpoint.reached",why:"to show the checkpoints of a power-mode build"},{topic:"wicked.run.turn.*",why:"to show which orchestrator turn is running"},{topic:"wicked.run.handoff.stepped",why:"to show where the hand-off is: checks, review, QE and compliance"},{topic:"wicked.run.power.toggled",why:"to know when power mode is switched on or off"}],gIt=[{id:"doc.read",why:"to show the job's working document and who changed what"},{id:"doc.propose_edit",why:"to save what you type in it (yours, steering the next step) and to add its own lines under Decisions (labelled as the plugin's)"},{id:"steer.propose",why:"to suggest a note for the next step; nothing is sent until you press Send"}],vIt={id:lIt,title:cIt,protocol:uIt,inline:dIt,description:hIt,panels:fIt,visuals:pIt,observe:mIt,permissions:gIt},yIt=`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="24" height="24" fill="none" stroke="#fff" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><rect x="3.5" y="4" width="17" height="16" rx="2.5"/><path d="M14 4v16"/><path d="M6.5 8.5h4M6.5 12h4M6.5 15.5h2.5"/></svg>
|
|
946
|
+
`))||null,R=(v==null?void 0:v.state)==="failed"?v.why:A,$=`/repos/new?project=${encodeURIComponent(e)}`;return(v==null?void 0:v.state)==="absent"?a.jsx(Zn,{"data-testid":"requirements-absent",title:"Requirements aren’t available yet",body:"Update Studio’s service to use this view."}):a.jsxs("div",{"data-testid":r,"data-state":(v==null?void 0:v.state)??"loading",className:"wk-pg-proj-stack wk-reqs",children:[R!=null&&a.jsx(Ft,{"data-testid":"requirements-error",kind:en(R),what:"requirements",error:R,onRetry:m}),a.jsxs("form",{onSubmit:I=>{I.preventDefault(),T===null&&(u(0),l(s.trim()))},className:"wk-pg-proj-search",children:[a.jsxs("label",{className:"wk-pg-proj-field",children:["Search requirements",a.jsx("input",{"data-testid":"requirements-search",type:"search",className:"wk-field",placeholder:"Search requirements",value:s,onChange:I=>i(I.target.value),disabled:T!==null,"aria-describedby":T!==null?`${r}-search-note`:void 0})]}),a.jsx("button",{type:"submit",className:"wk-btn wk-btn--secondary",disabled:T!==null,"aria-describedby":T!==null?`${r}-search-note`:void 0,children:"Search"})]}),T!==null&&a.jsx("p",{id:`${r}-search-note`,className:"wk-field-note",children:T}),a.jsx("p",{role:"status",className:"sr-only",children:v===null?"Reading requirements…":v.state==="failed"?"The requirements could not be read.":E?"No repository in this project yet.":_}),v===null?a.jsx(nn,{"data-testid":"requirements-loading"}):E?a.jsx(Zn,{"data-testid":"requirements-empty",title:"No repository in this project yet",body:"Attach a repository to see its requirements.",action:a.jsx("a",{className:"wk-btn wk-btn--primary",href:$,onClick:I=>{I.preventDefault(),t($)},children:"Attach a repository"})}):b!==null&&a.jsxs(a.Fragment,{children:[a.jsx("p",{"data-testid":"requirements-totals",className:"wk-pg-proj-note",children:_}),x===0&&A===null&&a.jsx(Zn,{title:o===""?"No requirements yet":"No matching requirements",body:o===""?"Index the attached repositories to build their requirements maps.":"Try another search."}),[...b.rows].sort((I,O)=>+(I.state==="ok")-+(O.state==="ok")).map(I=>I.state!=="ok"?a.jsxs("div",{"data-testid":"requirements-repo-unread","data-repo":I.repo.id,"data-state":I.state,children:[a.jsxs("p",{className:"wk-pg-proj-note",children:[qz(I),I.state!=="dangling"&&a.jsxs(a.Fragment,{children:[" ",a.jsxs("a",{className:"wk-link","data-testid":"requirements-repo-open",href:rse(I.repo.id),onClick:O=>{O.preventDefault(),t(rse(I.repo.id))},children:["Open ",I.repo.name??"the repository"]})]})]}),a.jsx(ut,{text:cw(I)})]},I.repo.id):I.items.length>0?a.jsxs("div",{"data-testid":"requirements-repo","data-repo":I.repo.id,children:[a.jsxs("p",{className:"wk-pg-proj-note",children:[I.repo.name??"Unnamed repository"," · ",I.total," of ",I.corpus]}),a.jsx("ul",{className:"wk-pg-proj-list",children:I.items.map(O=>{const P=Xh(I.repo.id,O.key),W=(n==null?void 0:n.chosen.has(P))===!0;return a.jsxs("li",{"data-testid":"requirement","data-repo":I.repo.id,"data-key":O.key,className:`wk-list-row${n!==void 0?" wk-pg-proj-pick-row":""}`,children:[n!==void 0?a.jsx(Ls,{label:O.title,checked:W,disabled:!W&&w?`A draft takes at most ${y} requirements.`:null,onChange:()=>n.onToggle({repoId:I.repo.id,key:O.key,title:O.title}),"data-testid":"requirement-pick"}):a.jsx("span",{className:"wk-list-row-title",children:O.title}),a.jsxs("p",{className:"wk-list-row-meta",children:[O.reqId," · ",O.domain,O.risk&&a.jsxs(a.Fragment,{children:[" · ",a.jsx("span",{className:"wk-reqs-risk",children:"At risk"})]})]})]},O.key)})})]},I.repo.id):null),w&&a.jsxs("p",{className:"wk-field-note",children:["A draft takes at most ",y," requirements. Clear a choice to add another."]}),(x>b.limit||b.offset>0)&&a.jsxs(a.Fragment,{children:[a.jsxs("div",{className:"wk-pg-proj-actions",children:[a.jsx("button",{type:"button","data-testid":"requirements-prev",disabled:b.offset===0,onClick:()=>u(Math.max(0,b.offset-b.limit)),className:"wk-btn wk-btn--secondary",children:"Previous"}),a.jsx("button",{type:"button","data-testid":"requirements-next",disabled:b.offset+b.limit>=x,onClick:()=>u(b.offset+b.limit),className:"wk-btn wk-btn--secondary",children:"Next"})]}),(b.offset===0||b.offset+b.limit>=x)&&a.jsx("p",{className:"wk-field-note",children:b.offset===0?"You’re on the first page.":"You’re on the last page."})]})]})]})}function sIt({projectId:e,navigate:t}){var u;const n=fn(d=>d.projects);k.useEffect(()=>{fn.getState().projects.length===0&&fn.getState().load()},[]);const r=((u=n.find(d=>d.id===e))==null?void 0:u.name)??"This project",[s,i]=k.useState([]),o=k.useMemo(()=>new Map(s.map(d=>[Xh(d.repoId,d.key),d])),[s]),l=d=>i(h=>{const f=Xh(d.repoId,d.key);return h.some(p=>Xh(p.repoId,p.key)===f)?h.filter(p=>Xh(p.repoId,p.key)!==f):h.length>=jy?h:[...h,d]}),c=Cs(e);return a.jsx(_a,{"data-testid":"project-requirements-page",title:`Requirements · ${r}`,intro:"The requirements across this project’s repositories. Choose some to draft epics from them.",actions:a.jsxs(a.Fragment,{children:[a.jsxs("a",{className:"wk-btn wk-btn--quiet",href:c,onClick:d=>{d.preventDefault(),t(c)},children:["Back to ",r]}),a.jsx("button",{type:"button","data-testid":"requirements-draft",className:"wk-btn wk-btn--primary",onClick:()=>ci({workflowId:Vc,projectId:e,requirements:s,composerKey:"desk"}),children:s.length===0?"Draft epics":`Draft epics from ${s.length}`})]}),children:a.jsx("section",{className:"wk-card","aria-label":"Requirements",children:a.jsx(NSe,{projectId:e,navigate:t,selection:{chosen:o,onToggle:l}})})})}function Dv({to:e,navigate:t}){return k.useEffect(()=>{t(e,{replace:!0})},[e,t]),null}const iIt="qe-author-tests";function aIt({search:e,navigate:t}){return k.useEffect(()=>{const n=new URLSearchParams(e).get("project");t("/",{replace:!0}),ci({workflowId:iIt,projectId:n!==null&&n!==""&&n!=="default"?n:null})},[e,t]),null}const Sy={name:"Vibe — app builder",line:"Build and preview an app visually. Apps are already built by pipelines today."},oIt={"wicked-phase-report":{version:"0.14.1",html:'<!doctype html>\n<html lang="en">\n<head>\n<meta charset="utf-8">\n<!-- The bundle\'s own policy (the host frames it from a blob: URL, so no response header carries one): no network of\n any kind, no forms, no base, no workers. The same lines as crew\'s editor bundle policy (editors/csp.ts). -->\n<meta http-equiv="Content-Security-Policy" content="default-src \'none\'; script-src \'unsafe-inline\'; style-src \'unsafe-inline\'; img-src data:; font-src data:; connect-src \'none\'; form-action \'none\'; base-uri \'none\'; worker-src \'none\'; manifest-src \'none\'">\n<meta name="wicked-editor" content="wicked-phase-report">\n<meta name="wicked-editor-version" content="0.14.1">\n<title>Phase report</title>\n<style>\n /* The host\'s tokens arrive in host.hello / host.theme; these are plain fallbacks. */\n :root {\n --surface-base: #0d1117; --surface-card: #161b22; --surface-raised: #1c222b; --ink-high: #f0f3f6; --ink-body: #c9d1d9;\n --ink-muted: #8b949e; --border: #30363d; --accent: #58a6ff; --status-ok: #3fb950; --status-fail: #f85149;\n --font-sans: system-ui, sans-serif;\n }\n html, body { margin: 0; padding: 0; background: var(--surface-card); }\n /* The host caps the block\'s height: anything taller scrolls inside the frame, never clipped. */\n body { font: 13px/1.45 var(--font-sans), system-ui, sans-serif; color: var(--ink-body); overflow-x: hidden; }\n [hidden] { display: none !important; }\n button.sum {\n all: unset; box-sizing: border-box; display: flex; align-items: center; gap: 8px; width: 100%; min-height: 34px;\n padding: 6px 2px; cursor: pointer; color: var(--ink-high); font-weight: 500; border-radius: 6px;\n }\n button.sum:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }\n .sum-text { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }\n .expanded .sum-text { white-space: normal; }\n .dot { flex: 0 0 auto; width: 7px; height: 7px; border-radius: 50%; background: var(--accent); }\n .dot.wait { background: #d29922; }\n .dot.done { background: var(--status-ok); }\n .dot.bad { background: var(--status-fail); }\n .dash { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; padding: 4px 0 8px; }\n @media (max-width: 520px) { .dash { grid-template-columns: minmax(0, 1fr); } }\n /* A section of the Details panel (the host draws the heading): two tiles a row down to a narrow panel. */\n .in-panel .dash { padding-top: 0; }\n /* Two tiles a row are narrow: a list row\'s words and its time wrap instead of running past the tile\'s edge. */\n .in-panel ul.list li { flex-wrap: wrap; column-gap: 6px; }\n .in-panel ul.list li span:first-child { flex: 0 1 auto; min-width: 0; overflow-wrap: anywhere; }\n .in-panel ul.list li span:last-child { margin-left: auto; }\n @media (min-width: 300px) and (max-width: 520px) { .in-panel .dash { grid-template-columns: repeat(2, minmax(0, 1fr)); } }\n .tile { border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; background: var(--surface-raised); min-width: 0; }\n .tile.wide { grid-column: 1 / -1; }\n .label { display: block; font-size: 11px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: var(--ink-muted); margin-bottom: 4px; }\n .value { margin: 0; color: var(--ink-high); font-size: 15px; font-weight: 600; }\n .sub { margin: 2px 0 0; color: var(--ink-muted); font-size: 12px; }\n .run { margin-top: 6px; }\n .run + .run { border-top: 1px solid var(--border); padding-top: 6px; }\n .run-title { margin: 0 0 4px; font-size: 12px; color: var(--ink-body); }\n .chips { display: flex; flex-wrap: wrap; gap: 4px; }\n .chip { display: inline-flex; align-items: center; gap: 4px; padding: 1px 8px; border-radius: 999px; font-size: 12px; border: 1px solid var(--border); color: var(--ink-body); }\n .chip.ok { color: var(--status-ok); border-color: color-mix(in srgb, var(--status-ok) 45%, transparent); }\n .chip.bad { color: var(--status-fail); border-color: color-mix(in srgb, var(--status-fail) 45%, transparent); }\n .chip .re { color: var(--ink-muted); font-size: 11px; }\n ul.list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 3px; }\n ul.list li { display: flex; justify-content: space-between; gap: 10px; font-size: 12px; }\n ul.list li span:first-child { flex: 0 0 auto; }\n ul.list li span:last-child { color: var(--ink-muted); text-align: right; min-width: 0; }\n ul.list li.open span:first-child { color: var(--ink-high); font-weight: 600; }\n .gap { margin: 0 0 6px; font-size: 12px; color: var(--status-fail); }\n .rg { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin: 2px 0; font-size: 12px; color: var(--ink-muted); }\n .rg-arrow { color: var(--ink-muted); }\n .rg-chip { display: inline-flex; align-items: center; height: 18px; padding: 0 8px; border-radius: 999px; border: 1px solid var(--border); color: var(--ink-body); font-weight: 600; font-size: 11px; }\n .rg-chip.rg-high, .rg-chip.rg-highest { color: var(--status-warn, #d29922); border-color: color-mix(in srgb, var(--status-warn, #d29922) 55%, transparent); }\n /* The working document (spike 3) */\n #wd { border: 1px solid var(--border); border-radius: 10px; background: var(--surface-raised); padding: 10px 12px 12px; margin: 0 0 8px; }\n .wd-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }\n .wd-title { margin: 0; font-size: 14px; color: var(--ink-high); }\n .wd-ver { font-size: 12px; color: var(--ink-muted); }\n .wd-note { margin: 2px 0 8px; font-size: 12px; color: var(--ink-muted); }\n .wd-sec { padding: 6px 0; border-top: 1px solid var(--border); }\n .wd-sec h4 { margin: 0 0 3px; display: flex; justify-content: space-between; gap: 8px; font-size: 11px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: var(--ink-muted); }\n .wd-who { font-weight: 400; letter-spacing: 0; text-transform: none; }\n .wd-text { white-space: pre-wrap; overflow-wrap: anywhere; color: var(--ink-body); border-radius: 6px; padding: 2px 4px; margin: 0 -4px; cursor: text; min-height: 1.4em; max-height: 18em; overflow-y: auto; }\n .wd-now { margin: 0 0 4px; padding: 4px 6px; border-radius: 6px; background: var(--surface-card); white-space: pre-wrap; font-size: 12px; color: var(--ink-high); max-height: 10em; overflow-y: auto; }\n .wd-text:hover { background: var(--surface-card); }\n .wd-text:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }\n .wd-text.empty { color: var(--ink-muted); font-style: italic; }\n .wd-gen { display: block; color: var(--ink-body); }\n .wd-gen-note { margin: 2px 0 0; color: var(--ink-muted); font-size: 11px; }\n .wd-input { box-sizing: border-box; width: 100%; font: inherit; color: var(--ink-high); background: var(--surface-card); border: 1px solid var(--accent); border-radius: 6px; padding: 6px 8px; resize: vertical; }\n .wd-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-top: 6px; }\n .wd-btn { font: inherit; font-size: 12px; padding: 4px 12px; border-radius: 999px; border: 1px solid var(--border); background: transparent; color: var(--ink-body); cursor: pointer; }\n .wd-btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-fg, #fff); }\n .wd-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }\n .wd-effect { font-size: 12px; color: var(--ink-muted); }\n .wd-status { margin: 8px 0 0; font-size: 12px; color: var(--ink-body); }\n .wd-status.bad { color: var(--status-fail); }\n .wd-trail { list-style: none; margin: 8px 0 0; padding: 6px 0 0; border-top: 1px solid var(--border); display: flex; flex-direction: column; gap: 2px; font-size: 12px; color: var(--ink-muted); }\n</style>\n</head>\n<body>\n<main id="root" class="folded">\n <button type="button" class="sum" id="sum" aria-expanded="false" aria-controls="dash">\n <span class="dot" id="dot" aria-hidden="true"></span><span class="sum-text" id="sum-text">Reading the job’s events…</span>\n </button>\n <section id="dash" class="dash" hidden aria-label="Phase report"></section>\n <section id="wd" hidden aria-label="Working document"></section>\n</main>\n<script>var wickedEditor=(function(he){"use strict";const Z="wicked.editor",Ye={card:{interactive:!0,aspect:"auto",actions:[]}},Je={understand:"research",test_plan:"plan",design:"plan",architecture:"plan",build:"build",produce:"write",test:"test",domain_coverage:"test",review:"review",critique:"review",security_review:"review",walkthrough_review:"walkthrough",deliver:"deliver"};function Xe(e,t){return e==="run"?t==="operator"?"yours":"tool":Je[e]??"tool"}const Ze={research:"Research",brainstorm:"Brainstorm",plan:"Plan",build:"Build",write:"Write",test:"Test",review:"Review",walkthrough:"Walkthrough",deliver:"Deliver",yours:"Yours"};function et(e){const t=e.replace(/[-_]+/g," ").trim();return t===""?"Step":t[0].toUpperCase()+t.slice(1)}const tt={"pa-scope":"Scope",scope:"Scope",clarify:"Clarify",design:"Plan",plan:"Plan",architecture:"Plan","test-plan":"Test plan",test_plan:"Test plan",triage:"Triage",reproduce:"Reproduce",build:"Build",implement:"Build",fix:"Fix",produce:"Write","adversarial-review":"Challenge",critique:"Review",review:"Review","code-review":"Review","security-review":"Security check",security_review:"Security check",test:"Test",verify:"Check",domain_coverage:"Coverage",walkthrough:"Walkthrough",walkthrough_review:"Walkthrough",deliver:"Deliver",understand:"Research",research:"Research",recon:"Research"};function nt(e,t,a,o){const n=tt[t.toLowerCase()];return n!==void 0?n:e!=="tool"?Ze[e]:o[a]??et(t||a)}function de(e,t={}){return nt(Xe(e),e,e,t)}function st(){return{loaded:!1,seen:new Set,startedAt:null,lastAt:null,finished:null,units:new Map,gates:[],checks:[],costUsd:0,tokens:0,usageReports:0,usageByOrd:new Map,power:null,marks:[]}}const S=e=>typeof e=="string"&&e!==""?e:null,_=e=>typeof e=="number"&&Number.isFinite(e)?e:null,ot=new Set(["longer_than_estimated","tests_failing","changes_undone","rigor_jumped","spread","other"]);function ae(e,t,a,o){const n=e.pauses.at(-1);if(n===void 0||o<n.at)return;const r=n.choice==="continue"&&!n.byPerson&&t!=="continue"&&(e.checkpoints.at(-1)?.n??n.n)===n.n;n.choice!==null&&!r||(n.choice=t,n.byPerson=a,n.answeredAt=o)}function G(e){return e.power??(e.power={intake:null,rigor:null,history:[],checkpoints:[],turn:null,handoff:null,on:null,pauses:[]}),e.power}function ce(e,t){let a=e.units.get(t);return a===void 0&&(a={ord:t,step:null,seat:null,seatName:null,state:"planned",startedAt:null,finishedAt:null},e.units.set(t,a)),a}function it(e,t){let a=!1;for(const o of t){if(e.seen.has(o.id))continue;e.seen.add(o.id),a=!0,e.lastAt=Math.max(e.lastAt??0,o.at),(e.startedAt===null||o.at<e.startedAt)&&(e.startedAt=o.at);const n=o.data,r=o.ord;switch(o.topic){case"wicked.run.session.started":e.startedAt=o.at;break;case"wicked.run.session.finished":e.finished={outcome:S(n.outcome)??"completed",at:o.at},e.power!=null&&ae(e.power,n.outcome==="cancelled"?"stop":"continue",!1,o.at);break;case"wicked.run.session.resumed":e.finished!==null&&o.at>=e.finished.at&&(e.finished=null);for(const s of e.gates)s.answeredAt===null&&s.openedAt<=o.at&&(s.answeredAt=o.at);break;case"wicked.run.unit.planned":if(r!==null){const s=ce(e,r);s.step=S(n.step)??s.step}break;case"wicked.run.unit.assigned":if(r!==null){const s=ce(e,r);s.seat=S(n.seat),s.seatName=S(n.seatName)}break;case"wicked.run.unit.started":if(r!==null){e.finished!==null&&o.at>=e.finished.at&&(e.finished=null);const s=ce(e,r);s.state="running",s.startedAt??(s.startedAt=o.at),s.finishedAt=null;for(const i of e.gates)i.answeredAt===null&&i.openedAt<=o.at&&(i.answeredAt=o.at)}break;case"wicked.run.unit.finished":if(r!==null){const s=ce(e,r),i=S(n.outcome);s.state=i==="denied"?"denied":i==="failed"?"failed":"done",s.finishedAt=o.at}break;case"wicked.run.human.awaited":r!==null&&e.gates.push({ord:r,kind:S(n.kind)??"question",openedAt:o.at,answeredAt:null});break;case"wicked.run.checks.evaluated":{e.marks.push({at:o.at,ord:r,kind:"checks",outcome:n.passed===!0?"passed":"failed"});const s=Array.isArray(n.checks)?n.checks.map($=>({name:S($.name)??"check",exitCode:_($.exitCode),timedOut:$.timedOut===!0,durationMs:_($.durationMs)})):[],i=n.reusedFrom,g=$=>Array.isArray($)?$.filter(l=>typeof l=="string"):[];e.checks.push({ord:r,attempt:_(n.attempt),floor:S(n.floor),outcome:S(n.outcome),passed:n.passed===!0,checks:s,at:o.at,reusedFrom:i!=null&&typeof i=="object"?{phase:S(i.phase),ord:_(i.ord),reused:g(i.reused),fresh:g(i.fresh)}:null});break}case"wicked.run.intake.planned":{const s=G(e),i=S(n.rigor);i!==null&&(s.intake={rigor:i,score:_(n.score),at:o.at},s.rigor??(s.rigor=i)),s.on??(s.on=!0);break}case"wicked.run.rigor.rescored":{const s=G(e),i=_(n.seq),g=S(n.to);if(i===null||g===null||s.history.some($=>$.seq===i))break;s.history.push({seq:i,at:o.at,trigger:S(n.trigger)??"checkpoint",from:S(n.from),to:g,direction:S(n.direction)??"same",planned:_(n.planned),actual:_(n.actual),checkpoint:_(n.checkpoint),byKind:S(n.byKind)}),s.history.sort(($,l)=>$.seq-l.seq),s.rigor=s.history.at(-1).to,S(n.byKind)==="person"&&S(n.direction)==="up"&&ae(s,"continue_high",!0,o.at);break}case"wicked.run.checkpoint.reached":{const s=G(e),i=_(n.checkpoint);if(i===null||s.checkpoints.some(g=>g.n===i))break;if(s.checkpoints.push({n:i,at:o.at,trigger:S(n.trigger),rigor:S(n.rigor),picked:_(n.picked)??0,paused:n.paused===!0}),s.checkpoints.sort((g,$)=>g.n-$.n),n.paused===!0){const g=Array.isArray(n.pauseKinds)?n.pauseKinds.filter($=>typeof $=="string"&&ot.has($)):[];s.pauses.push({n:i,at:o.at,kinds:g,choice:null,byPerson:!1,answeredAt:null})}break}case"wicked.run.turn.started":case"wicked.run.turn.completed":{e.marks.push({at:o.at,ord:r,kind:o.topic==="wicked.run.turn.started"?"turn.started":"turn.completed",outcome:S(n.outcome)});const s=G(e),i=_(n.turn);if(i===null||s.turn!==null&&i<s.turn.n)break;o.topic==="wicked.run.turn.started"&&ae(s,"continue",!1,o.at),s.turn={n:i,seatName:S(n.seatName)??S(n.seat),running:o.topic==="wicked.run.turn.started",outcome:S(n.outcome),at:o.at};break}case"wicked.run.handoff.stepped":{const s=G(e),i=_(n.round)??1,g=S(n.step);if(g===null)break;ae(s,"continue",!1,o.at),g==="checks"&&e.marks.push({at:o.at,ord:r,kind:"handoff.checks",outcome:S(n.status)}),(s.handoff===null||i>s.handoff.round)&&(s.handoff={round:i,steps:new Map}),i===s.handoff.round&&s.handoff.steps.set(g,{status:S(n.status)??"pending",seatName:S(n.seatName)??S(n.seat),at:o.at});break}case"wicked.run.power.toggled":G(e).on=n.on===!0,n.on!==!0&&ae(G(e),"switch_phased",S(n.byKind)==="person",o.at);break;case"wicked.run.usage.reported":if(e.costUsd+=_(n.costUsd)??0,e.tokens+=(_(n.inputTokens)??0)+(_(n.outputTokens)??0),e.usageReports+=1,r!==null){const s=e.usageByOrd.get(r)??{costUsd:0,tokens:0,reports:0};s.costUsd+=_(n.costUsd)??0,s.tokens+=(_(n.inputTokens)??0)+(_(n.outputTokens)??0),s.reports+=1,e.usageByOrd.set(r,s)}break}}return a}function I(e){return e===void 0?"Step":e.step!==null?de(e.step):`Step ${e.ord}`}const at={plan_approval:"Approve the plan",escalation:"A failed check or review",deliver:"Deliver",consent:"Install consent",repeat:"Keep going?",phase_review:"Review a step",question:"A question"},rt=new Set(["plan_approval","deliver","consent"]);function Y(e){return at[e]??e.replace(/[_-]+/g," ").replace(/^./u,t=>t.toUpperCase())}function M(e){return e.finished!==null?[]:e.gates.filter(t=>t.answeredAt===null)}function Se(e){return[...e.units.keys()].sort((t,a)=>t-a)}function Ee(e){const t=[...e.units.values()].filter(o=>o.state==="running").sort((o,n)=>(n.startedAt??0)-(o.startedAt??0));if(t[0]!==void 0)return t[0];const a=M(e).at(-1);return a!==void 0?e.units.get(a.ord)??null:null}function ge(e,t){if(e===void 0)return null;const a=e.checks.length,o=e.checks.filter(s=>s.exitCode===0&&!s.timedOut).length,n=a===0?"no checks found":o===a?`${a} passed`:`${o} of ${a} passed`,r=e.reusedFrom?.phase!=null?` (reused from ${de(e.reusedFrom.phase)})`:e.reusedFrom?.ord!=null?` (reused from ${I(t.units.get(e.reusedFrom.ord))})`:"";return`checks: ${n}${r}`}const ee=(e,t,a=`${t}s`)=>`${e} ${e===1?t:a}`;function Ne(e){return e.handoff!==null?"Hand-off":e.turn!==null||e.checkpoints.length>0?"Building":"Intake"}function lt(e){const t=e.trigger==="intake"?"intake":e.trigger==="operator"||e.byKind==="person"?"raised by you":e.trigger==="plugin"?"raised by a plugin":e.trigger==="doc_edit"?"a working-document edit":e.trigger==="toggle"?"power switch":e.checkpoint!==null?`checkpoint ${e.checkpoint}`:e.trigger==="pre_handoff"?"before hand-off":e.trigger.replace(/_/g," "),a=e.trigger==="intake"?e.actual!==null?`, score ${e.actual}`:"":e.planned!==null&&e.actual!==null&&e.planned!==e.actual?`, score ${e.planned} → ${e.actual}`:"";return`${m(e.at)} ${t}${a}`}const ut={rescore:"Re-score",checks:"Checks",review:"Review",security:"Security",qe:"QE",compliance:"Compliance"},Ce=["rescore","checks","review","security","qe","compliance"];function ke(e){if(!e.loaded)return"Reading the job’s events…";if(e.power!==null&&e.finished===null&&(e.power.turn!==null||e.power.checkpoints.length>0||e.power.handoff!==null)){const r=e.power,s=[Ne(r)];r.rigor!==null&&s.push(`rigor ${r.rigor}${r.intake!==null&&r.rigor!==r.intake.rigor?" ↑":""}`),r.checkpoints.length>0&&s.push(`checkpoint ${r.checkpoints.at(-1).n}`);const i=ge(e.checks.at(-1),e);i!==null&&s.push(i);const g=M(e).length;return g>0&&s.push(`${ee(g,"decision")} open`),s.join(" · ")}const t=Se(e),a=[];if(e.finished!==null){const r=[...e.units.values()].filter(s=>s.state==="done").length;a.push(e.finished.outcome==="completed"?"Finished":e.finished.outcome==="cancelled"?"Stopped":"Failed"),t.length>0&&a.push(`${r} of ${ee(t.length,"step")} done`)}else{const r=Ee(e);if(r!==null){a.push(I(r));const s=t.indexOf(r.ord);s>=0&&a.push(`step ${s+1} of ${t.length}`)}else e.startedAt!==null?a.push(t.length>0?`Planned · ${ee(t.length,"step")}`:"Starting"):a.push("No events yet")}const o=ge(e.checks.at(-1),e);o!==null&&a.push(o);const n=M(e).length;return n>0&&a.push(`${ee(n,"decision")} open`),a.join(" · ")}function m(e){if(e===null)return"—";const t=new Date(e);return`${String(t.getHours()).padStart(2,"0")}:${String(t.getMinutes()).padStart(2,"0")}`}function te(e){const t=Math.max(0,Math.round(e/6e4));return t<60?`${t} min`:`${Math.floor(t/60)} h ${String(t%60).padStart(2,"0")} min`}function xe(e,t){const a=Se(e),o=Ee(e),n=M(e);let r;if(e.finished!==null)r={value:ke(e).split(" · ")[0]??"Finished",sub:`${ee(a.length,"step")} · ${ee(e.gates.length,"decision")} · ${m(e.startedAt)}–${m(e.finished.at)}`};else if(n.length>0){const h=n[n.length-1];r={value:`Waiting on you · ${Y(h.kind)}`,sub:`${I(e.units.get(h.ord))} · since ${m(h.openedAt)}`}}else if(o!==null){const h=a.indexOf(o.ord);r={value:`${I(o)}${h>=0?` · step ${h+1} of ${a.length}`:""}`,sub:`${o.seatName??o.seat??"A helper"} · started ${m(o.startedAt)}`}}else r={value:e.startedAt===null?"No events yet":"Starting",sub:e.startedAt===null?"The report fills in as the job runs":`Started ${m(e.startedAt)}`};const s=e.checks.slice(-3).reverse().map(h=>{const b=new Set(h.reusedFrom?.reused??[]),E=Fe(h);return{title:`${h.ord!==null?I(e.units.get(h.ord)??{step:null,ord:h.ord}):"Checks"} · ${E} · ${m(h.at)}`,chips:h.checks.map(x=>({name:x.name.replace(/_/g," "),ok:x.exitCode===0&&!x.timedOut,reused:b.has(x.name),note:x.durationMs!==null&&x.durationMs>=6e4?te(x.durationMs):x.durationMs!==null?`${Math.max(1,Math.round(x.durationMs/1e3))} s`:null})),reused:h.reusedFrom!==null?`Reused from ${h.reusedFrom.phase!==null?de(h.reusedFrom.phase):I(e.units.get(h.reusedFrom.ord??-1))}: ${h.reusedFrom.reused.join(", ")||"none"}${h.reusedFrom.fresh.length>0?` · ran again: ${h.reusedFrom.fresh.join(", ")}`:""}`:null}}),i=e.gates.filter(h=>h.answeredAt!==null),g={open:n.length,answered:i.length,items:e.gates.slice(-5).map(h=>({text:rt.has(h.kind)?Y(h.kind):`${Y(h.kind)} · ${I(e.units.get(h.ord))}`,when:h.answeredAt!==null?`answered ${m(h.answeredAt)}`:n.includes(h)?`open since ${m(h.openedAt)}`:m(h.openedAt),open:n.includes(h)}))},$=new Map;for(const h of[...e.units.values()].sort((b,E)=>b.ord-E.ord)){const b=h.seatName??h.seat;if(b===null||h.seat==="bash")continue;const E=$.get(b)??[],x=I(h);E.includes(x)||E.push(x),$.set(b,E)}const l=[...$.entries()].map(([h,b])=>({name:h,steps:b.join(", ")})),C=e.finished?.at??t,K={value:e.startedAt===null?"—":te(C-e.startedAt),sub:e.usageReports===0?"No usage reported yet":`≈ $${e.costUsd.toFixed(2)} · ${Math.round(e.tokens/1e3).toLocaleString("en-US")}k tokens`},A=e.power;let J=null,D=null;if(A!==null){const h=A.history.filter(b=>b.direction!=="same"||b.trigger==="intake");if(J=[...A.intake!==null&&!h.some(b=>b.trigger==="intake")?[{to:A.intake.rigor,arrow:"",words:`${m(A.intake.at)} intake${A.intake.score!==null?`, score ${A.intake.score}`:""}`}]:[],...h.map(b=>({to:b.to,arrow:b.trigger==="intake"?"":b.direction==="up"?"↑":b.direction==="down"?"↓":"",words:lt(b)}))],A.handoff!==null&&(D=[...A.handoff.steps.entries()].sort((b,E)=>Ce.indexOf(b[0])-Ce.indexOf(E[0])).map(([b,E])=>({name:`${ut[b]??b}${E.seatName!==null&&b!=="checks"?` · ${E.seatName}`:""}`,status:E.status}))),e.finished===null&&n.length===0&&(A.turn!==null||A.checkpoints.length>0||A.handoff!==null)){const b=Ne(A),E=A.checkpoints.at(-1);r={value:[b,E!==void 0?`checkpoint ${E.n}`:null,A.turn!==null?`turn ${A.turn.n}`:null].filter(x=>x!==null).join(" · "),sub:A.turn!==null?`${A.turn.seatName??"The orchestrator"} · orchestrator · ${A.turn.running?`turn ${A.turn.n} started ${m(A.turn.at)}`:`turn ${A.turn.n} ended ${m(A.turn.at)}`}`:A.intake!==null?`QE plan set rigor ${A.intake.rigor} at ${m(A.intake.at)}`:"Starting"}}}return{now:r,checks:s,decisions:g,helpers:l,time:K,rigor:J,handoff:D}}const dt=new Set(["intake","plan","build","checks","review","security","qe","deliver"]);function ct(e){if(e===null||typeof e!="object")return null;const t=e;if(typeof t.phase!="string"||!dt.has(t.phase)||typeof t.label!="string"||!Array.isArray(t.ords))return null;const a=t.ords.filter(o=>typeof o=="number"&&Number.isFinite(o));return{phase:t.phase,label:t.label.slice(0,40),ords:a}}function pe(e){return e===null||e.phase==="build"}function ne(e,t){return t!==null&&e.ords.includes(t)}function we(e,t){const a=t.ords.map(s=>e.units.get(s)).filter(s=>s!==void 0),o=a.reduce((s,i)=>i.startedAt!==null&&(s===null||i.startedAt<s)?i.startedAt:s,null),n=a.map(s=>s.finishedAt),r=n.length>0&&n.every(s=>s!==null)?Math.max(...n):null;return{start:o,end:r,running:a.some(s=>s.state==="running"),failed:a.some(s=>s.state==="failed"||s.state==="denied")}}function _e(e,t){const a={build:[],checks:[]},o=e.marks.filter(l=>l.ord===t||l.kind==="handoff.checks"&&l.ord===null).map(l=>l);for(const l of e.power?.pauses??[])l.answeredAt!==null&&o.push({at:l.answeredAt,ord:t,kind:"pause.answered",outcome:null});o.sort((l,C)=>l.at-C.at);let n=null,r=0,s=!1;const i=l=>{(n==="build"||n==="checks")&&a[n].push({start:r,end:l}),n=null},g=(l,C)=>{n=l,r=C};for(const l of o){if(n==="afterPause"){const C=r;n=null,l.kind==="turn.started"?g("build",C):g("checks",C)}switch(l.kind){case"turn.started":n!=="build"&&(i(l.at),g("build",l.at)),s=!1;break;case"turn.completed":l.outcome==="handoff"?(i(l.at),g("checks",l.at)):l.outcome==="paused"?s=!0:(l.outcome==="failed"||l.outcome==="cap")&&i(l.at);break;case"pause.answered":n==="build"&&s&&(i(l.at),n="afterPause",r=l.at,s=!1);break;case"checks":n===null&&g("checks",l.at),n==="checks"&&l.outcome==="passed"&&i(l.at);break;case"handoff.checks":l.outcome==="running"||l.outcome==="pending"?n!=="checks"&&(i(l.at),g("checks",l.at)):(n==="checks"||n==="build")&&i(l.at);break}}const $=n;return($==="build"||$==="checks")&&a[$].push({start:r,end:e.finished!==null?Math.max(r,e.finished.at):null}),a}function Oe(e){if(e.length===0)return null;const t=o=>o.end!==null?`${m(o.start)}–${m(o.end)}`:`since ${m(o.start)}`,a=e.slice(0,3).map(t).join(" + ");return e.length>3?`${a} + ${e.length-3} more`:a}function Re(e,t){return e.reduce((a,o)=>a+((o.end??t)-o.start),0)}const Le={checks:"checks",review:"review",security:"security",qe:"qe"};function re(e,t){if(t.phase==="build"&&e.power?.turn!=null)return e.power.turn.running?"working":e.power.handoff!==null||e.finished!==null?"handed off":"between turns";const a=t.phase==="checks"?pt(e,t):null;if(a!==null)return a;const o=Le[t.phase],n=o!==void 0?e.power?.handoff?.steps.get(o):void 0;if(n!==void 0)return n.status==="passed"?t.phase==="review"||t.phase==="security"?"approved":"passed":n.status==="failed"?t.phase==="review"?"changes asked":"failed":n.status;if(M(e).filter(i=>ne(t,i.ord)).length>0)return"waiting on you";const s=we(e,t);return s.running?"running":s.failed?"did not pass":s.end!==null?"done":s.start===null?"not started":"running"}function Fe(e){return e.outcome==="passed"||e.passed?"passed":e.outcome==="timed_out"?"timed out":e.outcome==="not_run"?"did not run":"failed"}function pt(e,t){const a=me(e,t)?.at(-1);if(a===void 0)return null;if(M(e).some(n=>ne(t,n.ord)&&n.openedAt>=a.start))return"waiting on you";const o=e.checks.filter(n=>ne(t,n.ord)&&n.at>=a.start&&(a.end===null||n.at<=a.end)).at(-1);if(o!==void 0){const n=Fe(o),r=e.power?.handoff?.steps.get("checks");return n!=="passed"&&r?.status==="passed"&&r.at>=o.at?`${n} · overridden`:n}return a.end===null?"running":null}function Pe(e,t){const a=Le[t.phase];return a!==void 0?e.power?.handoff?.steps.get(a)??null:null}function me(e,t){return t.phase!=="build"&&t.phase!=="checks"||t.ords.length!==1||e.power===null?null:_e(e,t.ords[0])[t.phase]}function Te(e,t,a={}){if(!e.loaded)return"Reading the job’s events…";const o=e.power,n=[t.label];if(t.phase==="intake")o?.intake!=null?n.push(`rigor ${o.intake.rigor}${o.intake.score!==null?` (score ${o.intake.score})`:""}`):n.push(re(e,t));else if(t.phase==="build"){const s=o?.turn?.n??0;s>0&&n.push(`${s} ${s===1?"turn":"turns"}`),(o?.checkpoints.length??0)>0&&n.push(`checkpoint ${o.checkpoints.at(-1).n}`),o?.rigor!=null&&n.push(`rigor ${o.rigor}${o.intake!==null&&o.rigor!==o.intake.rigor?" ↑":""}`),o?.turn?.running===!0&&n.push("working")}else if(t.phase==="checks"){const s=e.checks.filter(i=>ne(t,i.ord)).at(-1);n.push(ge(s,e)??re(e,t))}else{const s=t.ords.map(g=>e.units.get(g)).find(g=>g?.seatName!=null||g?.seat!=null),i=s!==void 0?s.seatName??s.seat:Pe(e,t)?.seatName??null;i!=null&&t.phase!=="deliver"&&n.push(i),n.push(re(e,t))}const r=me(e,t);if(a.times!==!1)if(r!==null){const s=Oe(r);s!==null&&n.push(s)}else{const s=we(e,t);s.start!==null&&n.push(s.end!==null?`${m(s.start)}–${m(s.end)}`:`since ${m(s.start)}`)}return n.filter(s=>s!=="").join(" · ")}function ft(e,t,a){const o=xe(e,a),n=we(e,t),r=t.phase==="build"?e.power?.turn??null:null,s=Pe(e,t),i=me(e,t),g=i!==null&&i.length>0?`${Oe(i)} · ${te(Re(i,a))}`:n.start!==null&&i===null?n.end!==null?`${m(n.start)}–${m(n.end)} · ${te(n.end-n.start)}`:`Since ${m(n.start)} · ${te(a-n.start)}`:r!==null?`${r.seatName??"The orchestrator"} · orchestrator · turn ${r.n} ${r.running?`since ${m(r.at)}`:`ended ${m(r.at)}`}`:s!==null?`${s.seatName!==null?`${s.seatName} · `:""}${s.status==="running"||s.status==="pending"?"since":"at"} ${m(s.at)}`:"Not started yet",$={value:`${t.label} · ${re(e,t)}`,sub:g},l=i!==null?_e(e,t.ords[0]).checks:null,C=c=>l!==null&&l.some(R=>c.openedAt>=R.start&&(R.end===null||c.openedAt<=R.end)),K=c=>ne(t,c.ord)&&(l===null||C(c)===(t.phase==="checks")),A=e.gates.filter(K),J=M(e).filter(K),D=A.map(c=>({at:c.openedAt,text:Y(c.kind),when:c.answeredAt!==null?`answered ${m(c.answeredAt)}`:`open since ${m(c.openedAt)}`,open:J.includes(c)})),h=t.phase==="build"&&i!==null?e.power?.pauses??[]:[];for(const c of h)D.push({at:c.at,text:`Checkpoint ${c.n} pause`,when:c.answeredAt!==null?`answered ${m(c.answeredAt)}`:`open since ${m(c.at)}`,open:c.answeredAt===null});D.sort((c,R)=>c.at-R.at);const b={open:D.filter(c=>c.open).length,answered:D.filter(c=>!c.open&&c.when.startsWith("answered")).length,items:D.slice(-5).map(({text:c,when:R,open:H})=>({text:c,when:R,open:H}))},E=e.checks.filter(c=>ne(t,c.ord)),x=o.checks.filter((c,R)=>{const H=e.checks.slice(-3).reverse()[R];return H!==void 0&&E.includes(H)}),se=t.ords.map(c=>e.units.get(c)).filter(c=>c!==void 0&&(c.seatName??c.seat)!==null&&c.seat!=="bash").map(c=>c.seatName??c.seat);se.length===0&&s?.seatName!=null&&se.push(s.seatName);const d=[...new Set(se)].map(c=>({name:c,steps:t.label}));let W=o.time;if(i!==null&&t.phase==="build"){const c=t.ords.map(U=>e.usageByOrd.get(U)).filter(U=>U!==void 0),R=c.reduce((U,X)=>U+X.costUsd,0),H=c.reduce((U,X)=>U+X.tokens,0);W={value:i.length===0?"—":te(Re(i,a)),sub:c.length===0?"No usage reported yet":`≈ $${R.toFixed(2)} · ${Math.round(H/1e3).toLocaleString("en-US")}k tokens`}}const ue=t.phase==="intake"?["now","rigor"]:t.phase==="build"?["now","rigor","decisions","time"]:t.phase==="checks"?A.length>0?["now","checks","decisions"]:["now","checks"]:t.phase==="deliver"?["now","decisions"]:["now","helpers","decisions"],V=t.phase==="intake"&&o.rigor!==null?o.rigor.slice(0,1):o.rigor;return{...o,now:$,checks:x,decisions:b,helpers:d,rigor:V,time:W,handoff:null,tiles:ue}}function ht(e,t){if(t===null){const i=e.loaded?e.finished!==null?e.finished.outcome==="completed"?"ok":"fail":M(e).length>0?"wait":"run":"none";return{text:ke(e),tone:i}}const a=Te(e,t,{times:!1}),o=`${t.label} · `,n=a.startsWith(o)?a.slice(o.length):a===t.label?"":a;if(!e.loaded)return{text:n,tone:"none"};const r=re(e,t),s=/^(working|running)$/.test(r)?"run":r==="waiting on you"?"wait":/^(passed|approved|done|handed off)$/.test(r)||/\\bpassed\\b/.test(r)?"ok":/^(failed|did not pass|changes asked)$/.test(r)||/\\bfailed\\b/.test(r)?"fail":"none";return{text:n,tone:s}}const gt=["goal","approach","decisions","constraints","questions","next"],le={goal:"Goal",approach:"Approach",decisions:"Decisions",constraints:"Constraints and steering",questions:"Open questions",next:"Next and trailing work"},qe={goal:"Saving tells the next step.",approach:"Saving tells the next step.",next:"Saving tells the next step.",constraints:"Saving tells the next step and every step after it.",decisions:"Recorded here. Not sent to a step.",questions:"Recorded here. Not sent to a step."},kt="Edits steer the next step. They can raise rigor, never lower it.";function ve(e){return e?.eventLines!==!0}const wt={claude:"Claude Code",codex:"Codex",agy:"Antigravity",antigravity:"Antigravity",pi:"Pi CLI",opencode:"OpenCode",copilot:"Copilot"};function De(e){if(e.kind==="human")return e.id==="local"?"You":e.id;if(e.kind==="plugin")return/^plugin:wicked-phase-report@/u.test(e.id)?"Phase report (plugin)":`${e.id.replace(/^plugin:/u,"").replace(/@.*$/u,"")} (plugin)`;if(e.kind==="agent"){const t=e.id.replace(/^agent:/u,"");return`${wt[t]??t} (agent)`}return"From the job’s request"}function je(e){return e.kind!=="agent"&&/^agent:/u.test(e.id)?{kind:"agent",id:e.id}:e}function mt(e,t){const a=[];for(let o=e.trail.length-1;o>=0;o-=1){const n=e.trail[o];if(!n.sections.includes(t))continue;const r=De(je(n.author));a.includes(r)||a.push(r)}return a.length>0?a.join(", "):null}const Me=e=>{const t=new Date(e);return`${String(t.getHours()).padStart(2,"0")}:${String(t.getMinutes()).padStart(2,"0")}`};function vt(e,t=()=>null){const a=e.ord!==null?t(e.ord):null;return a!==null&&a!==""?a:e.step!==null&&e.step!==""&&!e.step.includes(":")?de(e.step):e.ord!==null?`step ${e.ord}`:"a step"}function $t(e,t){return e===void 0?null:e.error!==null?`not sent: ${e.error}`:e.pickedUp!==null?`picked up at ${vt(e.pickedUp,t)} ${Me(e.pickedUp.at)}`:"waiting for the next step"}function bt(e,t=6,a){return e.trail.slice(-t).reverse().map(o=>{const n=je(o.author),r=[`v${o.version}`,De(n),o.sections.map(i=>le[i]).join(", "),Me(o.at)],s=$t(e.steers.find(i=>i.id===o.steerId),a);return s!==null?r.push(s):(n.kind==="plugin"||n.kind==="agent")&&r.push("not sent to a step"),r.join(" · ")})}const yt={longer_than_estimated:"taking much longer than estimated",tests_failing:"the tests kept failing",changes_undone:"changes were undone",rigor_jumped:"rigor jumped two levels at once",spread:"the change spread into another product",other:"it grew more complex than planned"},At={continue_high:"continue at high rigor",continue:"continue as planned",switch_phased:"switch to phased steps",stop:"stop the job"},St={checks:{failed:"the checks failed: fix them and hand off again",skipped:"the checks were skipped"},review:{failed:"the review asked for changes: make them and hand off again",skipped:"the review was skipped"},security:{failed:"the security check found problems: fix them and hand off again",skipped:"the security check was skipped"},qe:{failed:"QE acceptance did not pass: fix it and hand off again",skipped:"QE acceptance was skipped"},compliance:{failed:"the compliance check did not pass",skipped:"the compliance check was skipped"}},$e=e=>e.length>0?` (${e.map(t=>yt[t]??t).join("; ")})`:"";function We(e){const t=[],a=[],o=[];for(const s of e.gates)s.answeredAt!==null&&t.push({at:s.answeredAt,line:`${Y(s.kind)} · answered ${m(s.answeredAt)}`});const n=e.power;for(const s of n?.pauses??[])s.choice!==null&&s.answeredAt!==null?t.push({at:s.answeredAt,line:`Checkpoint ${s.n} pause${$e(s.kinds)} · ${s.byPerson?"you chose":"answered"}: ${At[s.choice]} · ${m(s.answeredAt)}`}):e.finished===null&&a.push(`Waiting on you · checkpoint ${s.n} paused${$e(s.kinds)}: split it, switch to phased steps, continue at high rigor, or stop? · since ${m(s.at)}`);for(const s of M(e))a.push(`Waiting on you · ${Y(s.kind)} · since ${m(s.openedAt)}`);if(n?.handoff!=null)for(const[s,i]of n.handoff.steps){const g=St[s];g!==void 0&&(i.status==="failed"?o.push(`After hand-off round ${n.handoff.round} · ${g.failed}`):i.status==="skipped"&&o.push(`After hand-off round ${n.handoff.round} · ${g.skipped}`))}return{decisions:t.sort((s,i)=>s.at-i.at).map(s=>s.line),questions:a,next:o}}function Et(e){const t=e.gates.map(a=>`Waiting on you · ${Y(a.kind)} · since ${m(a.openedAt)}`);for(const a of e.power?.pauses??[])t.push(`Waiting on you · checkpoint ${a.n} paused${$e(a.kinds)}: split it, switch to phased steps, continue at high rigor, or stop? · since ${m(a.at)}`);return t}function be(e,t){return e===t||e.startsWith(t)}function Nt(e,t){const a=e.split(`\n`).map(o=>o.trim());return t.filter(o=>!a.some(n=>be(n,o)))}function Ct(e,t,a,o=[],n=[]){const r=t.split(`\n`).map(l=>l.trim()).filter(l=>l!==""),s=l=>e==="next"?n.includes(l):o.includes(l),i=e==="decisions"?r:r.filter(l=>!s(l)||a.includes(l)),g=a.filter(l=>!i.some(C=>be(C,l))),$=[...i,...g];return $.join(`\n`)===r.join(`\n`)?null:$.join(`\n`)}const Ue="wicked-phase-report";function Be(){let e=null,t=!0,a=!1;const o=st();let n=null,r=!1,s="",i=null,g="reading",$=!0,l=null,C=null,K=0,A=!1,J=Promise.resolve(),D=0;const h=new Map,b=(u,p)=>{if(e===null)return Promise.resolve({ok:!1,error:{code:"unavailable",message:"not connected"}});D+=1;const v=`r${D}`;return new Promise(f=>{h.set(v,f),e?.postMessage({p:Z,v:1,type:u,id:v,payload:p}),setTimeout(()=>{h.delete(v)&&f({ok:!1,error:{code:"timeout",message:"no answer"}})},25e3)})},E=u=>document.getElementById(u),x=(u,p)=>e?.postMessage({p:Z,v:1,type:u,payload:p}),se=u=>{if(!(typeof u!="object"||u===null))for(const[p,v]of Object.entries(u))/^--[a-z0-9-]+$/.test(p)&&typeof v=="string"&&v.length<=200&&!/url\\(/i.test(v)&&document.documentElement.style.setProperty(p,v)},d=(u,p,v)=>{const f=document.createElement(u);return p!==null&&(f.className=p),v!==void 0&&(f.textContent=v),f};function W(u,p=!1){const v=d("div",p?"tile wide":"tile");return v.appendChild(d("span","label",u)),v}let ue=0;function V(){const u=Math.ceil(document.getElementById("root")?.getBoundingClientRect().height??0);u>0&&u!==ue&&(ue=u,x("ui.height",{px:u}))}function c(){const u=E("root");if(u.className=`${t?"folded":"expanded"}${r?" in-panel":""}`,E("sum").hidden=r,r&&e!==null){const f=ht(o,n),L=`${f.tone}\\0${f.text}`;L!==s&&(s=L,x("panel.summary",{text:f.text.slice(0,80),tone:f.tone}))}E("sum").setAttribute("aria-expanded",t?"false":"true"),E("sum").title=t?"Show the phase report":"Fold the phase report",E("sum-text").textContent=n!==null?Te(o,n):ke(o);const p=E("dot");p.className=`dot${o.finished!==null?o.finished.outcome==="completed"?" done":" bad":M(o).length>0?" wait":""}`;const v=E("dash");if(v.hidden=t,v.replaceChildren(),!t){const f=n!==null?ft(o,n,Date.now()):{...xe(o,Date.now()),tiles:null},L=w=>f.tiles===null||f.tiles.includes(w);a&&v.appendChild(d("p","gap tile wide","The job’s earlier events could not be read; this shows what happened since."));const k=W("Now",!0);k.append(d("p","value",f.now.value),d("p","sub",f.now.sub));const y=W("Checks",!0);f.checks.length===0&&y.appendChild(d("p","sub","No checks have run yet."));for(const w of f.checks){const N=d("div","run");N.appendChild(d("p","run-title",w.title));const q=d("div","chips");for(const ie of w.chips){const Ae=d("span",`chip ${ie.ok?"ok":"bad"}`,`${ie.name} ${ie.ok?"✓":"✗"}`);ie.reused?Ae.appendChild(d("span","re","reused")):ie.note!==null&&Ae.appendChild(d("span","re",ie.note)),q.appendChild(Ae)}N.appendChild(q),w.reused!==null&&N.appendChild(d("p","sub",w.reused)),y.appendChild(N)}const F=f.rigor!==null?W("Rigor history",f.handoff===null):null;if(F!==null&&f.rigor!==null){f.rigor.length===0&&F.appendChild(d("p","sub","Not set yet."));for(const w of f.rigor){const N=d("div","rg");w.arrow!==""&&N.appendChild(d("span","rg-arrow",w.arrow)),N.append(d("span",`rg-chip rg-${w.to}`,w.to),d("span",null,w.words)),F.appendChild(N)}}const P=f.handoff!==null?W("Hand-off"):null;if(P!==null&&f.handoff!==null){const w=d("ul","list");for(const N of f.handoff){const q=d("li",N.status==="running"||N.status==="pending"?"open":null);q.append(d("span",null,N.name),d("span",null,N.status)),w.appendChild(q)}P.appendChild(w)}const Q=W("Decisions");Q.appendChild(d("p","value",`${f.decisions.open} open · ${f.decisions.answered} answered`));const j=d("ul","list");f.decisions.items.length===0&&j.appendChild(d("li",null,"None yet"));for(const w of f.decisions.items){const N=d("li",w.open?"open":null);N.append(d("span",null,w.text),d("span",null,w.when)),j.appendChild(N)}Q.appendChild(j);const oe=W("Helpers"),B=d("ul","list");f.helpers.length===0&&B.appendChild(d("li",null,"None yet"));for(const w of f.helpers){const N=d("li",null);N.append(d("span",null,w.name),d("span",null,w.steps)),B.appendChild(N)}oe.appendChild(B);const O=W("Time and cost",!0);O.append(d("p","value",f.time.value),d("p","sub",f.time.sub));const T=[["now",k],["rigor",F],["handoff",P],["checks",y],["decisions",Q],["helpers",oe],["time",O]];v.append(...T.filter(([w,N])=>N!==null&&L(w)).map(([,w])=>w))}z(),V()}async function R(){K+=1;const u=K,p=await b("doc.read",{});u===K&&(p.ok&&p.payload!==void 0?(i=p.payload.view,g="ready",A=!1,i.doc!==null&&ye()):p.error?.code==="unsupported"||p.error?.code==="not_granted"?g="unsupported":A=!0,z(),V())}function H(u){const p=J.then(u,u);return J=p.then(()=>{},()=>{}),p}function U(u,p){u.saving||(u.saving=!0,z(),H(async()=>{const v=await b("doc.propose_edit",{base:u.base,section:u.section,text:p,origin:"typed"});if(u.saving=!1,v.ok){const f=v.payload?.version;C={text:typeof f=="number"?`Saved as version ${f}. ${qe[u.section]}`:"Nothing changed.",bad:!1},l===u&&Ve()===p?(l=null,queueMicrotask(Ge)):l===u&&typeof f=="number"&&(u.base=f)}else v.error?.code==="head_moved"?(C={text:"Someone changed the document meanwhile. Your text is kept: check the section’s new text above it, then save again.",bad:!0},u.conflict=!0):C={text:`Not saved: ${v.error?.message??"no answer"}`,bad:!0};await R(),l===u&&u.conflict&&i?.doc!=null&&(u.base=i.doc.head,(i.sections?.[u.section]??"")===u.opened&&(C={text:"Other sections changed meanwhile, not this one. Your text is kept: press Save again.",bad:!0})),z(),V()}))}let X=!1;const Ie=new Set;let fe=!1;const He=new Set;function ye(){if(!(!pe(n)||X||g!=="ready"||i?.doc==null||!o.loaded)&&ve(i)){if(l!==null){fe=!0;return}X=!0,H(async()=>{X=!1;const u=We(o);for(const p of["decisions","questions","next"]){if(l!==null){fe=!0;return}if(!ve(i))return;if(!He.has(p))for(let v=0;v<2;v+=1){if(i===null||i.doc===null||i.sections===null)return;const f=Nt(i.sections[p],u[p]),L=Ct(p,i.sections[p],u[p],Et(o),[...Ie]);if(L===null)break;const k=await b("doc.propose_edit",{base:i.doc.head,section:p,text:L,origin:"generated"});if(await R(),k.ok&&p==="next")for(const y of f)Ie.add(y);if(k.ok)break;if(k.error?.code!=="head_moved"){He.add(p);break}}}})}}function Ke(u,p){if(!pe(n)||!o.loaded||!ve(i))return[];const v=p.split(`\n`).map(f=>f.trim());return We(o)[u].filter(f=>!v.some(L=>be(L,f)))}function Ve(){const u=document.querySelector("#wd textarea");return u===null?null:u.value}function ze(u){if(l!==null&&l.section!==u&&Ve()!==l.opened){C={text:`Save or cancel ${le[l.section]} first.`,bad:!0},z();return}const p=i?.sections?.[u]??"";l={section:u,base:i?.doc?.head??-1,opened:p,saving:!1,conflict:!1},C=null,z(),V(),queueMicrotask(()=>document.querySelector("#wd textarea")?.focus())}function Qe(){l=null,C=null,z(),V(),Ge()}function Ge(){l!==null||!fe||(fe=!1,ye())}function z(){const u=E("wd");if(u.hidden=t||!pe(n)||!$,t||!pe(n)||!$)return;const p=l!==null?u.querySelector(`textarea[data-section="${l.section}"]`):null,v=p!==null&&document.activeElement===p,f=p!==null?[p.selectionStart,p.selectionEnd]:null;u.replaceChildren();const L=d("div","wd-head");if(L.append(d("h3","wd-title","Working document")),i?.doc!=null&&L.append(d("span","wd-ver",`version ${i.doc.head}`)),u.append(L,d("p","wd-note",kt)),g==="unsupported"){u.append(d("p","sub","This version of studio’s service keeps no working document."));return}if(A){const k=d("p","wd-status bad","The working document could not be read just now. "),y=d("button","wd-btn","Try again");y.type="button",y.addEventListener("click",()=>{R()}),k.append(y),u.append(k)}if(g==="reading"){u.append(d("p","sub","Reading the working document…"));return}for(const k of gt){const y=d("div","wd-sec");y.dataset.section=k;const F=d("h4",null,le[k]),P=k==="decisions"||k==="questions"||k==="next"?Ke(k,i?.sections?.[k]??""):[],Q=(i!==null?mt(i,k):null)??(P.length>0?"Phase report (plugin)":null);Q!==null&&F.append(d("span","wd-who",Q)),y.append(F);const j=i?.sections?.[k]??"",oe=k==="decisions"||k==="questions"||k==="next"?Ke(k,j):[],B=l;if(B!==null&&B.section===k){B.conflict&&j!==B.opened&&y.append(d("p","wd-now",`Now: ${j.trim()===""?"(empty)":j}`));const O=p??document.createElement("textarea");p===null&&(O.className="wd-input",O.dataset.section=k,O.value=j,O.setAttribute("aria-label",le[k]),O.maxLength=4e3,O.addEventListener("keydown",q=>{q.key==="Enter"&&(q.metaKey||q.ctrlKey)&&(q.preventDefault(),l!==null&&U(l,O.value)),q.key==="Escape"&&(q.preventDefault(),Qe())})),O.rows=Math.min(10,Math.max(3,O.value.split(`\n`).length+1));const T=d("div","wd-bar"),w=d("button","wd-btn primary",B.saving?"Saving…":"Save");w.type="button",w.disabled=B.saving,w.addEventListener("click",()=>{l!==null&&U(l,O.value)});const N=d("button","wd-btn","Cancel");N.type="button",N.addEventListener("click",Qe),T.append(w,N,d("span","wd-effect",qe[k])),y.append(O,T),p!==null&&v&&(O.focus(),f!==null&&O.setSelectionRange(f[0],f[1]))}else{const O=j.trim()===""&&oe.length===0,T=d("div",`wd-text${O?" empty":""}`,O?k==="goal"&&i?.doc==null?"Not started. Edit a section to start the working document.":"Nothing yet.":j);for(const w of oe)T.append(d("span","wd-gen",w));T.tabIndex=0,T.setAttribute("role","button"),T.setAttribute("aria-label",`Edit ${le[k]}`),T.addEventListener("click",()=>ze(k)),T.addEventListener("keydown",w=>{(w.key==="Enter"||w.key===" ")&&(w.preventDefault(),ze(k))}),y.append(T),oe.length>0&&y.append(d("p","wd-gen-note",i?.doc==null?"From the job’s events. Not saved: no working document is started yet (a person’s first edit starts it).":"From the job’s events. Not saved in the working document yet."))}u.append(y)}if(C!==null){const k=d("p",`wd-status${C.bad?" bad":""}`,C.text);k.setAttribute("role","status"),u.append(k)}if(i!==null&&i.trail.length>0){const k=d("ol","wd-trail");k.setAttribute("aria-label","Versions");for(const y of bt(i,6,F=>{const P=o.units.get(F);return P!==void 0&&P.step!==null&&!P.step.includes(":")?I(P):null}))k.append(d("li",null,y));u.append(k)}}function xt(u){const p=u.data;if(e!==null||p?.p!==Z||p.v!==1||p.type!=="host.hello"||!u.ports[0])return;const v=p.payload??{};se(v.theme);const f=v.observe??null;n=ct(f?.scope);const L=f?.panel;r=typeof L=="object"&&L!==null&&L.slot==="run.details",s="",e=u.ports[0],ue=0,e.onmessage=k=>{const y=k.data;if(y?.p!==Z||y.v!==1)return;if(typeof y.re=="string"){const P=h.get(y.re);P!==void 0&&(h.delete(y.re),P({ok:y.ok===!0,...y.payload!==void 0?{payload:y.payload}:{},...y.error!==void 0?{error:y.error}:{}}));return}const F=y.payload??{};switch(y.type){case"host.ping":y.id&&e?.postMessage({p:Z,v:1,re:y.id,ok:!0,payload:{}});break;case void 0:break;case"host.theme":se(F.theme),c();break;case"host.fold":t=F.folded===!0,c();break;case"events.batch":{F.gap==="history-unavailable"&&(a=!0);const P=Array.isArray(F.rows)?F.rows:[],Q=!o.loaded;o.loaded=!0,(it(o,P)||Q)&&c(),ye();break}case"doc.changed":R();break;case"host.teardown":e?.close(),e=null;break}},e.start(),c(),$=Array.isArray(v.grants)&&v.grants.includes("doc.read"),$?R():(g="unsupported",z())}E("sum").addEventListener("click",()=>x("ui.fold",{folded:!t})),new ResizeObserver(()=>V()).observe(document.body),setInterval(()=>{!t&&o.finished===null&&o.startedAt!==null&&c()},3e4),window.addEventListener("message",xt),c();const _t=document.querySelector(\'meta[name="wicked-editor-version"]\')?.getAttribute("content")??"0.0.0";parent.postMessage({p:Z,v:1,type:"plugin.ready",payload:{editor:Ue,version:_t,protocol:[3],surfaces:Ye}},"*")}return typeof window<"u"&&document.querySelector(`meta[name="wicked-editor"][content="${Ue}"]`)!==null&&Be(),he.start=Be,Object.defineProperty(he,Symbol.toStringTag,{value:"Module"}),he})({});\n<\/script>\n</body>\n</html>\n',sha256:"c6ac408aa72cc339bd9c7f09209ef50504869f74538befc8187db9ea00428cbe"}},lIt="wicked-phase-report",cIt="Phase report",uIt=[3],dIt="run-thread",hIt="One section per phase in a job’s Details: what is happening, checks, rigor and the working document.",fIt=[{slot:"run.details",id:"phase",title:"{phase}",instances:"per-phase",order:10,defaultOpen:"current",summary:"plugin"}],pIt={icon:"icon.svg",color:"#4f46e5",live:!0},mIt=[{topic:"wicked.run.session.*",why:"to know when the job started, resumed and ended"},{topic:"wicked.run.unit.*",why:"to show which step is running, who works on it and how far along the plan it is"},{topic:"wicked.run.human.awaited",why:"to count the decisions waiting on you"},{topic:"wicked.run.checks.evaluated",why:"to show what the checks found, and when a result was reused from an earlier step"},{topic:"wicked.run.usage.reported",why:"to add up the time and the cost"},{topic:"wicked.run.intake.planned",why:"to show the rigor the QE plan set at intake"},{topic:"wicked.run.rigor.rescored",why:"to show the rigor history: each change, what triggered it and the score"},{topic:"wicked.run.checkpoint.reached",why:"to show the checkpoints of a power-mode build"},{topic:"wicked.run.turn.*",why:"to show which orchestrator turn is running"},{topic:"wicked.run.handoff.stepped",why:"to show where the hand-off is: checks, review, QE and compliance"},{topic:"wicked.run.power.toggled",why:"to know when power mode is switched on or off"}],gIt=[{id:"doc.read",why:"to show the job's working document and who changed what"},{id:"doc.propose_edit",why:"to save what you type in it (yours, steering the next step) and to add its own lines under Decisions (labelled as the plugin's)"},{id:"steer.propose",why:"to suggest a note for the next step; nothing is sent until you press Send"}],vIt={id:lIt,title:cIt,protocol:uIt,inline:dIt,description:hIt,panels:fIt,visuals:pIt,observe:mIt,permissions:gIt},yIt=`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="24" height="24" fill="none" stroke="#fff" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><rect x="3.5" y="4" width="17" height="16" rx="2.5"/><path d="M14 4v16"/><path d="M6.5 8.5h4M6.5 12h4M6.5 15.5h2.5"/></svg>
|
|
947
947
|
`,jT={icon:null,color:null,preview:null,live:!1},wIt=/^data:image\/(?:svg\+xml|png|webp);base64,[A-Za-z0-9+/=]+$/u,kIt=/^#[0-9a-fA-F]{6}$/u,qM=(e,t)=>typeof e=="string"&&e.length<=t&&wIt.test(e)?e:null;function nH(e){if(typeof e!="object"||e===null||Array.isArray(e))return jT;const t=e,n=t.preview,r=typeof n=="object"&&n!==null&&!Array.isArray(n)?n:null,s=r!==null?qM(r.light,3e5):null,i=r!==null?qM(r.dark,3e5):null;return{icon:qM(t.icon,24e3),color:typeof t.color=="string"&&kIt.test(t.color)?t.color:null,preview:s!==null||i!==null?{light:s,dark:i}:null,live:t.live===!0}}function _Se(e){const t=new TextEncoder().encode(e.trim());let n="";for(const r of t)n+=String.fromCharCode(r);return`data:image/svg+xml;base64,${btoa(n)}`}function bIt(e,t){return e.preview===null?null:t==="dark"?e.preview.dark??e.preview.light:e.preview.light??e.preview.dark}const CSe={"wicked.run.session.started":["sessionStarted"],"wicked.run.session.resumed":["resumed"],"wicked.run.session.finished":["sessionCompleted","sessionFailed","runCancelled"],"wicked.run.unit.planned":["unitPlanned"],"wicked.run.unit.assigned":["unitDistributed"],"wicked.run.unit.started":["unitExecuting"],"wicked.run.unit.finished":["unitDone","unitDenied","stepFailed"],"wicked.run.human.awaited":["awaitingHuman"],"wicked.run.checks.evaluated":["repoChecksEvaluated"],"wicked.run.qe.decided":["qeAcceptanceDecided"],"wicked.run.usage.reported":["cliUsage"],"wicked.run.intake.planned":["powerIntakePlanned"],"wicked.run.rigor.rescored":["rigorRescored"],"wicked.run.checkpoint.reached":["powerCheckpointReached"],"wicked.run.turn.started":["powerTurnStarted"],"wicked.run.turn.completed":["powerTurnCompleted"],"wicked.run.handoff.stepped":["powerHandoffStepped"],"wicked.run.power.toggled":["powerToggled"]},xIt=/^[a-z][a-z0-9_-]{0,40}$/u;function ESe(e){if(typeof e!="string"||e.length>120)return!1;const t=e.split(".");return t[0]!=="wicked"||t.length<2?!1:t.slice(1).every((n,r,s)=>xIt.test(n)||n==="*"||n==="**"&&r===s.length-1)}function jIt(e,t){if(!ESe(e))return!1;const n=e.split("."),r=t.split(".");for(let s=0;s<n.length;s+=1){if(n[s]==="**")return r.length>s;if(s>=r.length||n[s]!=="*"&&n[s]!==r[s])return!1}return n.length===r.length}function $Se(e,t){return e.some(n=>jIt(n,t))}function SIt(e){return Object.keys(CSe).filter(t=>$Se(e,t))}function NIt(e){return[...new Set(SIt(e).flatMap(t=>CSe[t]??[]))]}const Wn=e=>typeof e=="number"&&Number.isFinite(e)?e:null,us=(e,t=40)=>typeof e=="string"&&/^[A-Za-z0-9_.:-]{1,80}$/u.test(e)?e.slice(0,t):null;function _It(e){var n;if(typeof e!="string")return null;const t=((n=e.split(/\s+[—-]\s+/u)[0])==null?void 0:n.trim())??"";return/^[a-z][a-z0-9_-]{0,40}$/u.test(t)?t:null}const CIt=new Set(["light","standard","high","highest"]),s_=e=>typeof e=="string"&&CIt.has(e)?e:null,Lb=e=>typeof e=="object"&&e!==null&&!Array.isArray(e)?e:{};function EIt(e){return Array.isArray(e)?e.slice(0,40).flatMap(t=>{if(typeof t!="object"||t===null)return[];const n=t,r=us(n.name);return r===null?[]:[{name:r,exitCode:Wn(n.exitCode),timedOut:n.timedOut===!0,durationMs:Wn(n.durationMs)}]}):[]}function $It(e){if(typeof e!="object"||e===null)return null;const t=e,n=r=>Array.isArray(r)?r.map(s=>us(s)).filter(s=>s!==null).slice(0,20):[];return{phase:us(t.phase),ord:Wn(t.ord),attempt:Wn(t.attempt),reused:n(t.reused),fresh:n(t.fresh)}}function AIt(e){const t=e.replace(/^struggling:\s*/i,""),n=[];for(const r of t.split(/;\s*/))r.trim()!==""&&(/min against an estimate of/i.test(r)?n.push("longer_than_estimated"):/failed test runs?/i.test(r)?n.push("tests_failing"):/reverts?/i.test(r)?n.push("changes_undone"):/rigor jumped/i.test(r)?n.push("rigor_jumped"):/spread into another product|spans? \d+ (products|packages)/i.test(r)?n.push("spread"):n.push("other"));return n}function RIt(e,t,n,r,s){const i=e,o=Wn(i.ord),l=Wn(i.seq),c={id:r,runId:t,seq:l,at:Wn(i.ts)??n,ord:o};switch(e.type){case"sessionStarted":return{...c,topic:"wicked.run.session.started",data:{}};case"resumed":return{...c,topic:"wicked.run.session.resumed",data:{}};case"sessionCompleted":return{...c,topic:"wicked.run.session.finished",data:{outcome:"completed"}};case"sessionFailed":return{...c,topic:"wicked.run.session.finished",data:{outcome:"failed"}};case"runCancelled":return{...c,topic:"wicked.run.session.finished",data:{outcome:"cancelled"}};case"unitPlanned":return{...c,topic:"wicked.run.unit.planned",data:{step:_It(i.description),role:us(i.role),stage:us(i.stage),gate:us(i.gate),executor:us(i.executorType)}};case"unitDistributed":{const u=us(i.cli);return{...c,topic:"wicked.run.unit.assigned",data:{seat:u,seatName:u!==null?(s==null?void 0:s(u))??null:null}}}case"unitExecuting":return{...c,topic:"wicked.run.unit.started",data:{}};case"unitDone":return{...c,topic:"wicked.run.unit.finished",data:{outcome:"done"}};case"unitDenied":return{...c,topic:"wicked.run.unit.finished",data:{outcome:"denied"}};case"stepFailed":return{...c,topic:"wicked.run.unit.finished",data:{outcome:"failed"}};case"awaitingHuman":return{...c,topic:"wicked.run.human.awaited",data:{kind:us(i.gateKind)??"question"}};case"repoChecksEvaluated":return{...c,topic:"wicked.run.checks.evaluated",data:{attempt:Wn(i.attempt),floor:us(i.floor),outcome:us(i.outcome),passed:i.passed===!0,checks:EIt(i.checks),reusedFrom:$It(i.reusedFrom),changedFiles:Array.isArray(i.changed)?i.changed.length:null}};case"qeAcceptanceDecided":{const u=typeof i.qe=="object"&&i.qe!==null?i.qe:{};return{...c,topic:"wicked.run.qe.decided",data:{status:us(u.status),score:Wn(u.score)}}}case"powerIntakePlanned":{const u=Lb(i.plan);return{...c,topic:"wicked.run.intake.planned",at:Wn(u.at)??c.at,data:{rigor:s_(u.rigor),score:Wn(u.score),band:us(u.band),highRisk:u.highRisk===!0,estimateMinutes:Wn(u.estimateMinutes),mandatoryPhases:Array.isArray(u.mandatoryPhases)?u.mandatoryPhases.length:0}}}case"rigorRescored":{const u=Lb(i.change),d=typeof u.by=="string"?u.by:"";return{...c,topic:"wicked.run.rigor.rescored",at:Wn(u.at)??c.at,data:{seq:Wn(u.seq),trigger:us(u.trigger),from:s_(u.from),to:s_(u.to),direction:us(u.direction),planned:Wn(u.planned),actual:Wn(u.actual),checkpoint:Wn(u.checkpoint),turn:Wn(u.turn),paused:u.paused===!0,byKind:d==="engine"?"engine":d.startsWith("plugin:")?"plugin":d===""?null:"person"}}}case"powerCheckpointReached":{const u=Lb(i.pause),d=Array.isArray(u.reasons)?[...new Set(u.reasons.filter(h=>typeof h=="string").flatMap(AIt))]:[];return{...c,topic:"wicked.run.checkpoint.reached",data:{checkpoint:Wn(i.checkpoint),turn:Wn(i.turn),trigger:us(i.trigger),rigor:s_(i.rigor),picked:Wn(i.picked),paused:i.paused===!0,pauseKinds:d}}}case"powerTurnStarted":case"powerTurnCompleted":{const u=us(i.cli);return{...c,topic:e.type==="powerTurnStarted"?"wicked.run.turn.started":"wicked.run.turn.completed",data:{turn:Wn(i.turn),attempt:Wn(i.attempt),seat:u,seatName:u!==null?(s==null?void 0:s(u))??null:null,outcome:us(i.outcome)}}}case"powerHandoffStepped":{const u=Lb(i.step),d=us(u.seat);return{...c,topic:"wicked.run.handoff.stepped",at:Wn(u.at)??c.at,ord:Wn(u.ord),data:{round:Wn(i.round),step:us(u.step),status:us(u.status),seat:d,seatName:d!==null?(s==null?void 0:s(d))??null:null}}}case"powerToggled":{const u=Lb(i.toggle),d=typeof u.by=="string"?u.by:"";return{...c,topic:"wicked.run.power.toggled",at:Wn(u.at)??c.at,data:{on:u.on===!0,byKind:d==="engine"?"engine":d.startsWith("plugin:")?"plugin":d===""?null:"person"}}}case"cliUsage":return{...c,topic:"wicked.run.usage.reported",data:{attempt:Wn(i.attempt),costUsd:Wn(i.costUsd),inputTokens:Wn(i.inputTokens),outputTokens:Wn(i.outputTokens)}};default:return null}}function sse(e){const t={};for(const n of Object.keys(e).sort())n==="ts"||n==="seq"||n==="daemon"||(t[n]=e[n]);return JSON.stringify(t)}const ise=200,ase=15e3;class ASe{constructor(t){bt(this,"state","idle");bt(this,"buffer",[]);bt(this,"recorded",new Map);bt(this,"unsubscribe",null);bt(this,"liveSeq",0);bt(this,"liveSince",0);bt(this,"types");bt(this,"now");this.o=t,this.types=new Set(NIt(t.granted)),this.now=t.now??Date.now}start(){if(this.state==="idle"){if(this.state="replaying",this.unsubscribe=this.o.live(t=>{this.state==="replaying"?this.buffer.push(t):this.state==="live"&&this.onLive(t)}),this.types.size===0){this.goLive([],void 0);return}this.o.history([...this.types]).then(t=>this.goLive(t,void 0),()=>this.goLive([],"history-unavailable"))}}stop(){var t;this.state="stopped",(t=this.unsubscribe)==null||t.call(this),this.unsubscribe=null,this.buffer=[]}rowOf(t,n){if(t.session!==this.o.runId||!this.types.has(t.type))return null;const r=RIt(t,this.o.runId,this.now(),n,this.o.names);return r!==null&&$Se(this.o.granted,r.topic)?r:null}goLive(t,n){if(this.state!=="replaying")return;const r=t.filter(l=>l.session===this.o.runId).slice().sort((l,c)=>(Wn(l.seq)??0)-(Wn(c.seq)??0)),s=[],i=this.now();for(const l of r){const c=Wn(l.ts);if(c===null||i-c<=ase){const h=sse(l);this.recorded.set(h,(this.recorded.get(h)??0)+1)}const u=Wn(l.seq),d=this.rowOf(l,u!==null?`s${u}`:`r${s.length}`);d!==null&&s.push(d)}s.length===0&&this.o.deliver({runId:this.o.runId,replay:!0,rows:[],...n!==void 0?{gap:n}:{}});for(let l=0;l<s.length;l+=ise)this.o.deliver({runId:this.o.runId,replay:!0,rows:s.slice(l,l+ise),...n!==void 0&&l===0?{gap:n}:{}});this.state="live",this.liveSince=this.now();const o=this.buffer;this.buffer=[];for(const l of o)this.onLive(l)}onLive(t){if(t.session!==this.o.runId||!this.types.has(t.type))return;this.recorded.size>0&&this.now()-this.liveSince>ase&&this.recorded.clear();const n=sse(t),r=this.recorded.get(n)??0;if(r>0){this.recorded.set(n,r-1);return}this.liveSeq+=1;const s=this.rowOf(t,`l${this.liveSeq}`);s!==null&&this.o.deliver({runId:this.o.runId,replay:!1,rows:[s]})}}const TIt={"wicked-phase-report":{"icon.svg":yIt}};function IIt(e){var r,s;const t=oIt[e.id];if(t===void 0||e.inline!=="run-thread")return null;const n=((r=e.visuals)==null?void 0:r.icon)!==void 0?(s=TIt[e.id])==null?void 0:s[e.visuals.icon]:void 0;return{id:e.id,title:e.title,version:t.version,protocol:e.protocol,inline:"run-thread",observe:e.observe,panels:nhe(e.panels),description:typeof e.description=="string"?e.description.slice(0,160):"",visuals:nH({...e.visuals,icon:n!==void 0?_Se(n):void 0}),granted:e.observe.map(i=>i.topic).filter(ESe),grantedBy:"built-in",firstParty:!0,html:t.html,sha256:t.sha256,permissions:(e.permissions??[]).filter(i=>sae.has(i.id))}}const G0=[IIt(vIt)].filter(e=>e!==null),OIt={"wicked.run.session.*":"when the job starts, resumes and ends","wicked.run.unit.*":"each step: planned, who works on it, started, finished","wicked.run.human.awaited":"when a decision waits on you","wicked.run.checks.evaluated":"what the checks found, and what was reused","wicked.run.usage.reported":"time, tokens and cost","wicked.run.qe.decided":"the QE acceptance decision","wicked.run.intake.planned":"the rigor the QE plan set at intake","wicked.run.rigor.rescored":"every rigor re-score: up, down or unchanged, and what triggered it","wicked.run.checkpoint.reached":"each checkpoint of a power-mode build","wicked.run.turn.*":"the orchestrator’s turns: started and finished","wicked.run.handoff.stepped":"each hand-off step: checks, review, QE and compliance","wicked.run.power.toggled":"when power mode is switched on or off"},PIt={"doc.read":"reads the job’s working document","doc.propose_edit":"saves what you type in it, and adds its own lines under Decisions as itself","steer.propose":"suggests a note for the next step (you press Send)"};function DIt(e){return PIt[e]??e}function RSe(e){return e==="wicked.**"?"everything that happens in every run":OIt[e]??e}const MIt="How studio's first-party EDITORS look on the Plugins page (program DES-LEARN §2): one line and a colour each; the icon is <id>/icon.svg. scripts/build-editors.mjs writes these into each editor's editor.json (`description`, `visuals`) for crew's registry; studio falls back to them for a crew that predates the fields. A run plugin declares its own in its manifest.json.",LIt={$doc:MIt,"wicked-insights":{description:"What the weekly review found: patterns across runs and what to change.",color:"#0f766e"},"wicked-deck":{description:"Opens decks: edit slides in place, reorder them, export PowerPoint.",color:"#c2410c"},"wicked-doc":{description:"Opens documents: write in place, compare versions, export PDF.",color:"#1d4ed8"},"wicked-page":{description:"Opens pages: point at any element and change it, at any device size.",color:"#7c3aed"},"wicked-video":{description:"Opens demo recordings: chapters, narration, trim, export.",color:"#be185d"}},FIt=`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="24" height="24" fill="none" stroke="#fff" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><rect x="3" y="4" width="18" height="12" rx="2"/><path d="M12 16v4M8.5 20h7"/><path d="M7.5 8.5h6M7.5 11.5h4"/></svg>
|
|
948
948
|
`,BIt=`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="24" height="24" fill="none" stroke="#fff" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><path d="M14 3.5H7a2 2 0 0 0-2 2v13a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2V8.5z"/><path d="M14 3.5v5h5"/><path d="M8.5 13h7M8.5 16.5h5"/></svg>
|
|
949
949
|
`,zIt=`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="24" height="24" fill="none" stroke="#fff" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><path d="M4 20h16"/><path d="M7 16.5V11M11 16.5V7M15 16.5v-4M19 16.5V5"/></svg>
|