@frumu/tandem-panel 0.5.4 → 0.5.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (56) hide show
  1. package/bin/setup.js +1 -0
  2. package/dist/assets/AutomationsPage-BGqpmilp.js +946 -0
  3. package/dist/assets/BugMonitorPage-BVzdj9y-.js +4 -0
  4. package/dist/assets/ChannelsPage-B-InJ4Yh.js +1 -0
  5. package/dist/assets/ChatInterfacePanel-BrMo4cXg.js +1 -0
  6. package/dist/assets/ChatPage-Bc-BfOG1.js +1 -0
  7. package/dist/assets/CodingWorkflowsPage-xgfwLRlt.js +8 -0
  8. package/dist/assets/ControlPanelDialogs-yFfCht3Y.js +1 -0
  9. package/dist/assets/DashboardPage-CrA1itFc.js +1 -0
  10. package/dist/assets/ExperimentsPage-Bkg1_6rw.js +84 -0
  11. package/dist/assets/FilesPage-DChyHlO_.js +1 -0
  12. package/dist/assets/IntentPlannerPage-Dti1h8Tm.js +5 -0
  13. package/dist/assets/LazyJson-vfWw7G9F.js +1 -0
  14. package/dist/assets/MarketplacePage-90fAVNGg.js +1 -0
  15. package/dist/assets/McpToolAllowlistEditor-BzQ64HrZ.js +1 -0
  16. package/dist/assets/MemoryImportDialog-DSpS1JF5.js +1 -0
  17. package/dist/assets/MemoryPage-DRRLgoc0.js +1 -0
  18. package/dist/assets/OrchestratorPage-CYU-ESPI.js +3 -0
  19. package/dist/assets/PacksPage-dRmjjdKD.js +3 -0
  20. package/dist/assets/PlannerDiagnosticsPanel-C1uIuRIx.js +1 -0
  21. package/dist/assets/ProviderModelSelector-BdtOpkJR.js +1 -0
  22. package/dist/assets/RunsPage-DEy8vbRT.js +1 -0
  23. package/dist/assets/SettingsPage-CwH_FzOs.js +5 -0
  24. package/dist/assets/TaskBoard-CCY_Qy5S.js +1 -0
  25. package/dist/assets/TeamsPage-Dn81V0EB.js +4472 -0
  26. package/dist/assets/TimezoneField-B5i---lF.js +1 -0
  27. package/dist/assets/WorkflowStudioPage-yFhlA4KV.js +1854 -0
  28. package/dist/assets/WorkflowsPage-vmaKHFox.js +2 -0
  29. package/dist/assets/chatPageHelpers-Dmb4waDk.js +1 -0
  30. package/dist/assets/explorerHandoff-BPKxMR82.js +1 -0
  31. package/dist/assets/format-DyX5imzJ.js +1 -0
  32. package/dist/assets/fullcalendar-Bn75j0xM.js +1 -0
  33. package/dist/assets/index-C8Bjo7hU.css +1 -0
  34. package/dist/assets/index-TvymvGva.js +3 -0
  35. package/dist/assets/messages-uD0aB_MZ.js +3 -0
  36. package/dist/assets/motion-B3ZE8SGR.js +9 -0
  37. package/dist/assets/plannerShared-Dx7-Sxpc.js +1 -0
  38. package/dist/assets/preact-vendor-DaCG_P2o.js +1 -0
  39. package/dist/assets/react-query-BIbNygEJ.js +1 -0
  40. package/dist/assets/sse-B4A2m-Nk.js +2 -0
  41. package/dist/assets/useEngineStream-Diqri33l.js +1 -0
  42. package/dist/assets/vendor-DSaYtO9f.js +156 -0
  43. package/dist/assets/workflowStability-C8USyGOY.js +2 -0
  44. package/dist/index.html +8 -7
  45. package/lib/automations/workflow-list.js +147 -0
  46. package/lib/setup/control-panel-preferences.js +4 -0
  47. package/package.json +3 -3
  48. package/server/routes/capabilities.js +1 -0
  49. package/server/routes/knowledgebase.js +7 -1
  50. package/dist/assets/index-BL-9rGEh.css +0 -1
  51. package/dist/assets/index-DhoScTZK.js +0 -7379
  52. package/dist/assets/motion-CBnf8hfk.js +0 -9
  53. package/dist/assets/preact-vendor-B239Onrg.js +0 -1
  54. package/dist/assets/react-query-_hsOQSt5.js +0 -1
  55. package/dist/assets/vendor-DZYPF2Pz.js +0 -156
  56. /package/dist/assets/{markdown-Dd89TVib.js → markdown-Dwwtq3bu.js} +0 -0
@@ -0,0 +1,4 @@
1
+ import{C as e,g as t,h as n,v as r}from"./fullcalendar-Bn75j0xM.js";import{a as i,n as a,t as o}from"./react-query-BIbNygEJ.js";import{i as s}from"./motion-B3ZE8SGR.js";import{_ as c,a as ee,g as l,h as u,m as te,x as ne}from"./index-TvymvGva.js";import{t as re}from"./ControlPanelDialogs-yFfCht3Y.js";var ie=[10,25,50,100],d=10,f=200;function p(e,t){return!Number.isFinite(e)||e<1||!Number.isFinite(t)||t<1?1:Math.min(e,t)}function ae(e,t,n){if(!n)return`0 of 0`;let r=p(e,Math.max(1,Math.ceil(n/Math.max(1,t)))),i=Math.max(1,t);return`${(r-1)*i+1}-${Math.min(n,r*i)} of ${n}`}var oe={title:``,body:``,severity:`error`,source:`manual`,labels:`bug-monitor, runtime-failure`,confidence:`medium`,riskLevel:`medium`,expectedDestination:`bug_monitor_issue_draft`,evidenceRefs:``,relatedRunId:``,relatedWorkflowId:``,relatedFile:``,reproductionNotes:``,expectedBehavior:``,actualBehavior:``};function m(e){return e&&typeof e==`object`&&!Array.isArray(e)?e:{}}function se(e){return Array.isArray(e)?e.filter(e=>e&&typeof e==`object`):[]}function ce(e){let t=m(e);return m(t.status||t)}function h(e,t,n=``){for(let n of t){let t=e[n];if(typeof t==`string`&&t.trim())return t.trim();if(typeof t==`number`&&Number.isFinite(t))return String(t)}return n}function g(e,t){return m(e[t])}function le(e,t){for(let n of t){let t=Number(e[n]);if(Number.isFinite(t)&&t>0)return t}return null}function ue(e){let t=Number(e);if(Number.isFinite(t)&&t>0)return new Date(t).toLocaleString();if(typeof e==`string`&&e.trim()){let t=Date.parse(e);return Number.isFinite(t)?new Date(t).toLocaleString():e}return`Unavailable`}function de(e){try{return JSON.stringify(e,null,2)}catch{return String(e)}}function fe(e,t=`No body yet.`){let n=String(e||``).trim();return n?n.length>420?`${n.slice(0,420)}...`:n:t}function _(e){let t=String(e||``).toLowerCase();return[`posted`,`published`,`ok`,`ready`,`draft_ready`,`open`].includes(t)?`ok`:[`denied`,`failed`,`error`,`blocked`].some(e=>t.includes(e))?`err`:[`approval`,`pending`,`queued`,`paused`].some(e=>t.includes(e))?`warn`:t?`info`:`ghost`}function pe(e){return e?`Yes`:`No`}function v(e){return e.split(`,`).map(e=>e.trim()).filter(Boolean)}function me(e){return e.split(/\r?\n|,/).map(e=>e.trim()).filter(Boolean)}function y(e,t){return t.test(String(e.detail||``))}function b(e){return Array.isArray(e)?e.map(e=>typeof e==`string`||typeof e==`number`?String(e).trim():``).filter(Boolean):typeof e==`string`&&e.trim()?[e.trim()]:typeof e==`number`&&Number.isFinite(e)?[String(e)]:[]}function x(e,t){let n=g(e,`event_payload`),r=[];for(let i of t)r.push(...b(e[i])),r.push(...b(n[i]));return Array.from(new Set(r))}function S(e,t=120){let n=String(e||``).trim();return n?n.length>t?`${n.slice(0,t-3)}...`:n:``}function C(e,t,n){let r=g(e,`event_payload`);return h(e,t)||h(r,t)||(n&&y(e,n)?`recorded in detail`:``)}function he(e){return/^https?:\/\//i.test(e)?e:void 0}function ge(e){let t=h(e,[`github_issue_url`,`issue_url`]);if(t)return t;let n=h(e,[`repo`]),r=h(e,[`issue_number`,`matched_issue_number`]);return/^[^/\s]+\/[^/\s]+$/.test(n)&&/^\d+$/.test(r)?`https://github.com/${n}/issues/${r}`:``}function _e(e){return h(e,[`github_comment_url`,`comment_url`])}function ve(e){let t=h(e,[`issue_number`,`matched_issue_number`]);return t?`Issue #${t}`:`GitHub issue`}function ye({record:e}){let t=ge(e),n=_e(e);return!t&&!n?null:s(`div`,{className:`mt-3 flex flex-wrap gap-2`,children:[t?s(`a`,{className:`tcp-btn h-8 px-3 text-xs`,href:t,target:`_blank`,rel:`noreferrer`,children:[s(`i`,{"data-lucide":`external-link`}),ve(e)]}):null,n?s(`a`,{className:`tcp-btn h-8 px-3 text-xs`,href:n,target:`_blank`,rel:`noreferrer`,children:[s(`i`,{"data-lucide":`message-square`}),`GitHub comment`]}):null]})}function be(e){let t=[...x(e,[`evidence_refs`,`artifact_refs`,`artifactRefs`,`files_touched`,`filesTouched`]),...b(e.evidence_digest),...b(e.response_excerpt),...b(e.excerpt)];return y(e,/(^|\n)(artifact_refs|evidence_refs|files_touched|tool_result_excerpt|excerpt):/i)&&t.push(`structured evidence in detail`),Array.from(new Set(t)).filter(Boolean)}function xe(e){let t=[...x(e,[`artifact_refs`,`artifactRefs`,`evidence_refs`,`triage_artifacts`,`research_sources`,`related_failure_patterns`]),...b(e.triage_summary_artifact),...b(e.issue_draft_artifact),...b(e.duplicate_matches_artifact)];for(let n of[`triage_summary_artifact`,`issue_draft_artifact`,`duplicate_matches_artifact`]){let r=m(e[n]);t.push(...b(r.path)),t.push(...b(r.artifact_ref)),t.push(...b(r.id))}return y(e,/(^|\n)(artifact_refs|evidence_refs|research_sources|related_failure_patterns):/i)&&t.push(`structured refs in detail`),Array.from(new Set(t)).filter(Boolean)}function w(e){let t=[...x(e,[`memory_id`,`memory_ids`,`memory_ref`,`memory_refs`,`memory_pattern`,`memory_patterns`,`failure_pattern_memory`,`regression_signal_memory`,`related_failure_patterns`])];return y(e,/(^|\n)(memory|failure_pattern|regression_signal|related_failure_patterns):/i)&&t.push(`memory references in detail`),Array.from(new Set(t)).filter(Boolean)}function Se({record:e,kind:t}){let n=xe(e),r=w(e),i=ge(e),a=_e(e),o=i||a,c=m(e.coder_ready_gate),ee=m(e.quality_gate),l=h(e,[`github_status`,`proposal_status`,`issue_draft_status`])||(e.issue_body||e.issue_draft_artifact?`issue draft available`:``),te=h(e,[`approval_status`,`approval_decision`,`status`])||(t===`draft`?`awaiting review`:``),ne=h(e,[`incident_id`,`post_id`,`id`,`fingerprint`]),re=[{label:`Signal`,value:S(ne||C(e,[`event_type`,`source`],/(^|\n)(event|source):/i)),tone:ee.status?_(ee.status):`info`},{label:`Draft`,value:S(h(e,[`draft_id`])||(t===`draft`?ne:``)),tone:h(e,[`draft_id`])||t===`draft`?`info`:`ghost`},{label:`Triage`,value:S(h(e,[`triage_run_id`,`triageRunId`,`triage_context_run_id`])),tone:h(e,[`triage_run_id`,`triageRunId`,`triage_context_run_id`])?`ok`:`ghost`},{label:`Proposal`,value:S(l),tone:l?_(l):`ghost`},{label:`Coder-ready`,value:S(h(c,[`status`])||(e.coder_ready===!0?`passed`:``)),tone:e.coder_ready===!0||c.status===`passed`?`ok`:c.status?`warn`:`ghost`},{label:`Approval`,value:S(te),tone:_(te)},{label:`Published`,value:S(h(e,[`issue_number`])?ve(e):o||h(e,[`comment_id`,`github_post_id`])),tone:o||e.issue_number?`ok`:`ghost`,href:o?he(o):void 0},{label:`Artifacts`,value:S(n.slice(0,3).join(`, `)),tone:n.length?`info`:`ghost`},{label:`Memory`,value:S(r.slice(0,3).join(`, `)),tone:r.length?`info`:`ghost`}].filter(e=>e.value);return re.length?s(`div`,{className:`mt-3 rounded-md border border-sky-400/20 bg-sky-400/[0.04] p-3`,children:[s(`div`,{className:`tcp-subtle mb-2 text-xs uppercase tracking-[0.18em]`,children:`Signal lifecycle`}),s(`div`,{className:`grid gap-2 md:grid-cols-3`,children:re.map(e=>s(`div`,{className:`min-w-0 rounded border border-white/10 bg-black/10 p-2`,children:[s(`div`,{className:`mb-1 flex items-center justify-between gap-2`,children:[s(`span`,{className:`tcp-subtle text-[0.68rem] uppercase tracking-[0.14em]`,children:e.label}),s(u,{tone:e.tone||`info`,children:e.tone===`ghost`?`none`:e.tone||`info`})]}),e.href?s(`a`,{className:`break-words text-xs text-sky-200 hover:text-sky-100`,href:e.href,target:`_blank`,rel:`noreferrer`,children:e.value}):s(`div`,{className:`break-words text-xs text-white/80`,children:e.value})]},e.label))}),s(ye,{record:e})]}):null}function Ce(e){let t=m(e.quality_gate),n=Array.isArray(t.gates)?t.gates:[];if(n.length)return n.map((e,t)=>{let n=m(e);return{label:h(n,[`label`,`key`],`Gate ${t+1}`),ok:!!(n.passed??n.ok)}});g(e,`event_payload`);let r=String(e.status||``).toLowerCase(),i=C(e,[`event_type`,`event`,`signal_type`,`failure_type`,`error_kind`],/(^|\n)(event|event_type|failure_type|error_kind):/i),a=C(e,[`confidence`,`signal_confidence`,`root_cause_confidence`],/(^|\n)confidence:/i),o=C(e,[`risk_level`,`risk`],/(^|\n)risk_level:/i),s=C(e,[`expected_destination`,`github_status`,`github_issue_url`,`github_comment_url`,`issue_url`,`comment_url`],/(^|\n)expected_destination:/i),c=be(e).length>0,ee=C(e,[`source`,`component`,`event_type`],/(^|\n)(source|component|event_type):/i),l=!!e.fingerprint||!!e.duplicate_summary||Array.isArray(e.duplicate_matches),u=/progress|heartbeat|started|retrying|attempt\.started|minor_retry/.test(i)||/progress|retrying/.test(r),te=i?!u:/(failed|error|blocked|queued|draft|approval|posted|created|duplicate_suppressed)/.test(r);return[{label:`Source known`,ok:!!ee},{label:`Type classified`,ok:!!i},{label:`Confidence recorded`,ok:!!a},{label:`Dedupe/fingerprint checked`,ok:l},{label:`Evidence or artifact refs`,ok:c},{label:`Destination clear`,ok:!!s},{label:`Risk known`,ok:!!o},{label:`Not routine noise`,ok:te&&!u}]}function we({record:e}){let t=be(e),n=m(e.quality_gate),r=Array.isArray(e.duplicate_matches)?e.duplicate_matches.length:0,i=[[`Gate`,n.status?`${String(n.status)} (${Number(n.passed_count||0)}/${Number(n.total_count||0)})`:``],[`Source`,C(e,[`source`,`component`,`event_type`],/(^|\n)(source|component|event_type):/i)],[`Type`,C(e,[`event_type`,`event`,`signal_type`,`failure_type`,`error_kind`],/(^|\n)(event|event_type|failure_type|error_kind):/i)],[`Confidence`,C(e,[`confidence`,`signal_confidence`,`root_cause_confidence`],/(^|\n)confidence:/i)],[`Risk`,C(e,[`risk_level`,`risk`],/(^|\n)risk_level:/i)],[`Destination`,C(e,[`expected_destination`,`github_status`,`github_issue_url`,`github_comment_url`,`issue_url`,`comment_url`],/(^|\n)expected_destination:/i)],[`Fingerprint`,h(e,[`fingerprint`])],[`Run`,h(e,[`run_id`,`runID`])],[`Session`,h(e,[`session_id`,`sessionID`])],[`Correlation`,h(e,[`correlation_id`,`correlationID`])],[`Evidence`,t.slice(0,3).join(`, `)],[`Duplicates`,r?`${r} match${r===1?``:`es`}`:e.duplicate_summary?`summary available`:``]].filter(([,e])=>e);return i.length?s(`div`,{className:`tcp-subtle mt-3 grid gap-1 rounded-md border border-white/10 bg-white/[0.03] p-3 text-xs md:grid-cols-2`,children:i.map(([e,t])=>s(`div`,{className:`min-w-0`,children:[s(`span`,{className:`text-white/60`,children:[e,`: `]}),s(`span`,{className:`break-words text-white/80`,children:t})]},e))}):null}function Te({record:e}){let t=Ce(e),n=m(e.quality_gate),r=Array.isArray(n.gates)&&n.gates.length>0,i=t.filter(e=>e.ok).length;return s(`div`,{className:`mt-3 border-t border-white/10 pt-3`,children:[s(`div`,{className:`mb-2 flex flex-wrap items-center justify-between gap-2`,children:[s(`div`,{className:`tcp-subtle text-xs uppercase tracking-[0.18em]`,children:[`Signal quality gates`,r?``:` (heuristic)`]}),s(u,{tone:i===t.length?`ok`:i>=5?`warn`:`err`,children:[i,`/`,t.length]})]}),s(`div`,{className:`flex flex-wrap gap-1.5`,children:t.map(e=>s(u,{tone:e.ok?`ok`:`ghost`,children:[e.ok?`ok`:`missing`,` `,e.label]},e.label))})]})}function Ee(e){let t=[e.body.trim(),e.reproductionNotes.trim()?`Reproduction notes:\n${e.reproductionNotes.trim()}`:``,e.expectedBehavior.trim()?`Expected behavior:\n${e.expectedBehavior.trim()}`:``,e.actualBehavior.trim()?`Actual behavior:\n${e.actualBehavior.trim()}`:``].filter(Boolean),n=t.flatMap(e=>e.split(`
2
+ `).map(e=>e.trim()).filter(Boolean).slice(0,8));return{title:e.title.trim(),detail:t.join(`
3
+
4
+ `),source:e.source.trim()||`manual`,level:e.severity.trim()||`error`,confidence:e.confidence.trim()||void 0,risk_level:e.riskLevel.trim()||void 0,expected_destination:e.expectedDestination.trim()||void 0,evidence_refs:me(e.evidenceRefs),run_id:e.relatedRunId.trim()||void 0,file_name:e.relatedFile.trim()||void 0,component:e.relatedWorkflowId.trim()||void 0,event:e.relatedWorkflowId.trim()?`workflow_failure`:`manual_report`,excerpt:n,labels:v(e.labels),related_workflow_id:e.relatedWorkflowId.trim()||void 0,reproduction_notes:e.reproductionNotes.trim()||void 0,expected_behavior:e.expectedBehavior.trim()||void 0,actual_behavior:e.actualBehavior.trim()||void 0}}function T({label:e,value:t,tone:n=`info`}){return s(`div`,{className:`tcp-list-item min-h-[5rem]`,children:[s(`div`,{className:`tcp-subtle text-xs uppercase tracking-[0.18em]`,children:e}),s(`div`,{className:`mt-2 flex items-center justify-between gap-2`,children:[s(`div`,{className:`min-w-0 truncate text-lg font-semibold`,children:t}),s(u,{tone:n,children:String(t||`n/a`)})]})]})}function De({error:e}){let t=e instanceof Error?e.message:String(e||`Unknown error`);return s(`div`,{className:`tcp-list-item border-rose-500/40`,children:[s(`div`,{className:`font-medium text-rose-200`,children:`Request failed`}),s(`div`,{className:`tcp-subtle mt-1 break-words text-xs`,children:t})]})}function E({client:g,toast:v}){let me=i(),y=n(null),[b,x]=r(oe),[S,C]=r(null),[he,ye]=r(!1),[be,xe]=r(1),[w,Ce]=r(d),[E,Oe]=r([]),[D,ke]=r(!0),[O,Ae]=r(null),[je,Me]=r(1),[k,Ne]=r(d),[A,Pe]=r([]),[j,Fe]=r(!0),[M,Ie]=r(null),[Le,Re]=r(1),[N,ze]=r(d),[P,Be]=r([]),[F,Ve]=r(!0),[I,He]=r(null),L=async()=>{await Promise.all([me.invalidateQueries({queryKey:[`bug-monitor`,`status`]}),me.invalidateQueries({queryKey:[`bug-monitor`,`incidents`]}),me.invalidateQueries({queryKey:[`bug-monitor`,`drafts`]}),me.invalidateQueries({queryKey:[`bug-monitor`,`posts`]})])},Ue=a({queryKey:[`bug-monitor`,`status`],queryFn:()=>g.bugMonitor.getStatus(),refetchInterval:1e4}),R=a({queryKey:[`bug-monitor`,`incidents`,f],queryFn:()=>g.bugMonitor.listIncidents({limit:f})}),z=a({queryKey:[`bug-monitor`,`drafts`,f],queryFn:()=>g.bugMonitor.listDrafts({limit:f})}),B=a({queryKey:[`bug-monitor`,`posts`,f],queryFn:()=>g.bugMonitor.listPosts({limit:f})}),V=o({mutationFn:async e=>e===`recompute`?g.bugMonitor.recomputeStatus():e===`pause`?g.bugMonitor.pause():e===`resume`?g.bugMonitor.resume():g.bugMonitor.debug(),onSuccess:async(e,t)=>{t===`debug`&&C({title:`Bug Monitor Debug Payload`,value:e}),v(`ok`,t===`debug`?`Bug Monitor debug payload loaded.`:`Bug Monitor updated.`),await L()},onError:e=>v(`err`,e?.message||String(e))}),H=o({mutationFn:async e=>{let t=h(e.incident,[`incident_id`,`id`]);if(!t)throw Error(`Incident id missing.`);if(e.action===`view`)return g.bugMonitor.getIncident(t);if(e.action===`triage`){let t=h(e.incident,[`draft_id`]);if(!t)throw Error(`Incident has no draft id for triage.`);return g.bugMonitor.createTriageRun(t)}return g.bugMonitor.replayIncident(t)},onSuccess:async(e,t)=>{t.action===`view`&&C({title:`Incident ${h(t.incident,[`incident_id`,`id`],`detail`)}`,value:e}),v(`ok`,t.action===`view`?`Incident loaded.`:`Incident action queued.`),await L()},onError:e=>v(`err`,e?.message||String(e))}),U=o({mutationFn:async e=>{let t=h(e.draft,[`draft_id`,`id`]);if(!t)throw Error(`Draft id missing.`);if(e.action===`view`)return g.bugMonitor.getDraft(t);if(e.action===`approve`)return g.bugMonitor.approveDraft(t,e.reason);if(e.action===`deny`)return g.bugMonitor.denyDraft(t,e.reason);if(e.action===`triage-run`)return g.bugMonitor.createTriageRun(t);if(e.action===`triage-summary`)return g.bugMonitor.createTriageSummary(t,{suggested_title:h(e.draft,[`title`,`fingerprint`],`Runtime failure`),what_happened:h(e.draft,[`detail`,`evidence_digest`],``),notes:e.reason||`Created from the control panel.`});if(e.action===`issue-draft`)return g.bugMonitor.createIssueDraft(t,{});if(e.action===`publish`)return g.bugMonitor.publishDraft(t,{});if(e.action===`recheck`)return g.bugMonitor.recheckMatch(t,{});throw Error(`Unknown draft action: ${e.action}`)},onSuccess:async(e,t)=>{t.action===`view`&&C({title:`Draft ${h(t.draft,[`draft_id`,`id`],`detail`)}`,value:e}),v(`ok`,t.action===`view`?`Draft loaded.`:`Draft action completed.`),await L()},onError:e=>v(`err`,e?.message||String(e))}),We=o({mutationFn:async()=>{let e=Ee(b);if(!String(e.title||``).trim())throw Error(`Title is required.`);if(!String(e.detail||``).trim())throw Error(`Summary/body is required.`);return g.bugMonitor.report(e)},onSuccess:async e=>{C({title:`Manual Report Result`,value:e}),x(oe),v(`ok`,`Manual report submitted.`),await L()},onError:e=>v(`err`,e?.message||String(e))}),W=o({mutationFn:async e=>e.all?g.bugMonitor.bulkDeleteIncidents({all:!0}):g.bugMonitor.bulkDeleteIncidents({ids:e.ids}),onSuccess:async(e,t)=>{let n=Number(e?.deleted||t.ids.length||0);Oe([]),Ae(null),v(`ok`,`Deleted ${n} incident${n===1?``:`s`}.`),await L()},onError:e=>v(`err`,e?.message||String(e))}),Ge=o({mutationFn:async e=>e.all?g.bugMonitor.bulkDeleteDrafts({all:!0}):g.bugMonitor.bulkDeleteDrafts({ids:e.ids}),onSuccess:async(e,t)=>{let n=Number(e?.deleted||t.ids.length||0);Pe([]),Ie(null),v(`ok`,`Deleted ${n} draft${n===1?``:`s`}.`),await L()},onError:e=>v(`err`,e?.message||String(e))}),Ke=o({mutationFn:async e=>e.all?g.bugMonitor.bulkDeletePosts({all:!0}):g.bugMonitor.bulkDeletePosts({ids:e.ids}),onSuccess:async(e,t)=>{let n=Number(e?.deleted||t.ids.length||0);Be([]),He(null),v(`ok`,`Deleted ${n} post${n===1?``:`s`}.`),await L()},onError:e=>v(`err`,e?.message||String(e))}),qe=ce(Ue.data),Je=m(qe.config),Ye=m(qe.readiness),Xe=m(qe.runtime),G=se(m(R.data).incidents),K=se(m(z.data).drafts),q=se(m(B.data).posts),Ze=(e,t)=>h(e,[`incident_id`,`id`],`incident-${t}`),Qe=(e,t)=>h(e,[`draft_id`,`id`],`draft-${t}`),$e=(e,t)=>h(e,[`post_id`,`id`],`post-${t}`),et=Math.max(1,Math.ceil(G.length/Math.max(1,w))),J=p(be,et),tt=(J-1)*Math.max(1,w),nt=G.slice(tt,tt+w),rt=ae(J,w,G.length),it=Math.max(1,Math.ceil(K.length/Math.max(1,k))),Y=p(je,it),at=(Y-1)*Math.max(1,k),ot=K.slice(at,at+k),st=ae(Y,k,K.length),ct=Math.max(1,Math.ceil(q.length/Math.max(1,N))),X=p(Le,ct),lt=(X-1)*Math.max(1,N),ut=q.slice(lt,lt+N),dt=ae(X,N,q.length);e(()=>{be!==J&&xe(J)},[be,J]),e(()=>{je!==Y&&Me(Y)},[je,Y]),e(()=>{Le!==X&&Re(X)},[Le,X]),e(()=>{let e=new Set(G.map((e,t)=>Ze(e,t)));Oe(t=>t.filter(t=>e.has(t)))},[G]),e(()=>{let e=new Set(K.map((e,t)=>Qe(e,t)));Pe(t=>t.filter(t=>e.has(t)))},[K]),e(()=>{let e=new Set(q.map((e,t)=>$e(e,t)));Be(t=>t.filter(t=>e.has(t)))},[q]);let ft=t(()=>new Set(E),[E]),pt=t(()=>new Set(A),[A]),mt=t(()=>new Set(P),[P]),ht=e=>{e&&Oe(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e])},gt=e=>{e&&Pe(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e])},_t=e=>{e&&Be(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e])},vt=()=>{Oe(e=>{let t=new Set(e);return nt.forEach((e,n)=>t.add(Ze(e,tt+n))),Array.from(t)})},yt=()=>{Pe(e=>{let t=new Set(e);return ot.forEach((e,n)=>t.add(Qe(e,at+n))),Array.from(t)})},bt=()=>{Be(e=>{let t=new Set(e);return ut.forEach((e,n)=>t.add($e(e,lt+n))),Array.from(t)})};e(()=>{y.current&&ee(y.current)},[G.length,K.length,q.length,E.length,A.length,P.length,J,Y,X,w,k,N,D,j,F,he,!!S]);let Z=!!Je.enabled,Q=!!Xe.paused||!!Je.paused,$=!!Ye.ingest_ready,xt=!!Ye.publish_ready,St=!!Xe.monitoring_active,Ct=Number(Xe.pending_incidents||0),wt=h(Xe,[`last_runtime_error`])||h(qe,[`last_error`]),Tt=Array.isArray(qe.missing_required_capabilities)?qe.missing_required_capabilities:[],Et=t(()=>Z?Q?`Paused`:$?St&&xt?`Monitoring`:St?`Watching locally`:`Ready`:`Blocked`:`Disabled`,[Z,$,St,Q,xt]);return s(te,{className:`grid h-full min-h-0 gap-4`,children:[s(`div`,{ref:y,className:`grid h-full min-h-0 gap-4`,children:[s(ne,{title:`Bug Monitor`,subtitle:`Runtime failures, workflow failures, draft issues, and GitHub publishing.`,actions:s(`div`,{className:`flex flex-wrap items-center justify-end gap-2`,children:[s(u,{tone:Z&&$?`ok`:Z?`warn`:`ghost`,children:Et}),s(`button`,{type:`button`,className:`tcp-btn-primary h-8 px-3 text-xs`,onClick:()=>ye(!0),children:[s(`i`,{"data-lucide":`file-plus`}),`Report issue`]}),s(`button`,{type:`button`,className:`tcp-btn h-8 px-3 text-xs`,disabled:Ue.isFetching||R.isFetching||z.isFetching||B.isFetching,onClick:()=>{Promise.all([Ue.refetch(),R.refetch(),z.refetch(),B.refetch()]).then(()=>v(`ok`,`Bug Monitor refreshed.`))},children:[s(`i`,{"data-lucide":`refresh-cw`}),`Refresh`]}),s(`button`,{type:`button`,className:`tcp-btn h-8 px-3 text-xs`,disabled:V.isPending,onClick:()=>V.mutate(`recompute`),children:[s(`i`,{"data-lucide":`rotate-cw`}),`Recompute`]}),s(`button`,{type:`button`,className:`tcp-btn h-8 px-3 text-xs`,disabled:V.isPending,onClick:()=>V.mutate(Q?`resume`:`pause`),children:[s(`i`,{"data-lucide":Q?`play`:`pause`}),Q?`Resume`:`Pause`]}),s(`button`,{type:`button`,className:`tcp-btn h-8 px-3 text-xs`,disabled:V.isPending,onClick:()=>V.mutate(`debug`),children:[s(`i`,{"data-lucide":`bug-play`}),`Debug`]})]}),children:s(`div`,{className:`grid gap-4`,children:[Ue.isError?s(De,{error:Ue.error}):null,!Z||!$||wt?s(`div`,{className:`tcp-list-item`,children:[s(`div`,{className:`flex flex-wrap items-center gap-2`,children:[s(u,{tone:!Z||!$?`warn`:`err`,children:Z?$?`Runtime error`:`Readiness blocked`:`Disabled`}),Tt.length?s(`span`,{className:`tcp-subtle text-xs`,children:[`Missing: `,Tt.join(`, `)]}):null]}),wt?s(`div`,{className:`tcp-subtle mt-2 break-words text-xs`,children:wt}):null]}):null,s(`div`,{className:`grid gap-3 md:grid-cols-3 xl:grid-cols-6`,children:[s(T,{label:`enabled`,value:pe(Z),tone:Z?`ok`:`ghost`}),s(T,{label:`monitoring_active`,value:pe(St),tone:St?`ok`:`info`}),s(T,{label:`paused`,value:pe(Q),tone:Q?`warn`:`ok`}),s(T,{label:`pending_incidents`,value:Ct,tone:Ct?`warn`:`ok`}),s(T,{label:`ingest_ready`,value:pe($),tone:$?`ok`:`warn`}),s(T,{label:`publish_ready`,value:pe(xt),tone:xt?`ok`:`info`})]})]})}),s(ne,{title:`Incidents`,subtitle:`${G.length} recent incident${G.length===1?``:`s`}`,actions:s(`div`,{className:`flex flex-wrap items-center justify-end gap-2`,children:[s(u,{tone:G.length?`info`:`ghost`,children:G.length}),s(`button`,{type:`button`,className:`tcp-icon-btn`,title:D?`Expand incidents`:`Collapse incidents`,"aria-label":D?`Expand incidents`:`Collapse incidents`,onClick:()=>ke(e=>!e),children:s(`i`,{"data-lucide":D?`chevron-down`:`chevron-up`})}),s(u,{tone:`ghost`,children:rt}),s(u,{tone:E.length?`info`:`ghost`,children:[E.length,` selected`]}),s(`button`,{type:`button`,className:`tcp-icon-btn`,title:`Select all on this page`,"aria-label":`Select all on this page`,onClick:vt,disabled:!nt.length,children:s(`i`,{"data-lucide":`square-check-big`})}),s(`button`,{type:`button`,className:`tcp-icon-btn`,title:`Clear selection`,"aria-label":`Clear selection`,onClick:()=>Oe([]),disabled:!E.length,children:s(`i`,{"data-lucide":`x`})}),s(`button`,{type:`button`,className:`tcp-icon-btn border-rose-500/30 text-rose-100 hover:bg-rose-950/20 disabled:opacity-50`,title:`Delete selected incidents`,"aria-label":`Delete selected incidents`,onClick:()=>Ae({ids:E,all:!1}),disabled:!E.length||W.isPending,children:s(`i`,{"data-lucide":`trash-2`})}),s(`button`,{type:`button`,className:`tcp-icon-btn border-rose-500/30 text-rose-100 hover:bg-rose-950/20 disabled:opacity-50`,title:`Delete all incidents`,"aria-label":`Delete all incidents`,onClick:()=>Ae({ids:[],all:!0}),disabled:!G.length||W.isPending,children:s(`i`,{"data-lucide":`list-x`})}),s(`label`,{className:`flex items-center gap-2 text-[11px] uppercase tracking-wide text-slate-500`,children:[s(`span`,{children:`Per page`}),s(`select`,{className:`tcp-input h-8 min-w-[4rem] px-2 text-xs leading-none`,value:w,onChange:e=>{Ce(Number(e.target.value)||d),xe(1)},children:ie.map(e=>s(`option`,{value:e,children:e},e))})]}),s(`button`,{type:`button`,className:`tcp-icon-btn`,title:`Previous page`,"aria-label":`Previous page`,onClick:()=>xe(e=>p(e-1,et)),disabled:J<=1,children:s(`i`,{"data-lucide":`chevron-left`})}),s(`button`,{type:`button`,className:`tcp-icon-btn`,title:`Next page`,"aria-label":`Next page`,onClick:()=>xe(e=>p(e+1,et)),disabled:J>=et,children:s(`i`,{"data-lucide":`chevron-right`})})]}),children:[D?null:R.isError?s(De,{error:R.error}):null,D?null:R.isLoading?s(c,{title:`Loading incidents`,text:`Checking the reporter incident queue.`}):G.length?s(`div`,{className:`grid gap-3`,children:nt.map((e,t)=>{let n=Ze(e,tt+t),r=h(e,[`title`,`summary`,`event_type`],n),i=h(e,[`source`,`event_type`,`component`],`unknown source`),a=h(e,[`severity`,`level`]);return s(`div`,{className:`tcp-list-item`,children:[s(`div`,{className:`flex flex-wrap items-start justify-between gap-3`,children:[s(`div`,{className:`flex min-w-0 items-start gap-3`,children:[s(`label`,{className:`mt-1 flex h-6 w-6 cursor-pointer items-center justify-center rounded border border-white/15 bg-black/20 hover:border-sky-500/40`,children:s(`input`,{type:`checkbox`,className:`h-4 w-4 accent-sky-400`,checked:ft.has(n),onChange:()=>ht(n),"aria-label":`Select incident ${n}`})}),s(`div`,{className:`min-w-0`,children:[s(`div`,{className:`truncate font-medium`,children:r}),s(`div`,{className:`tcp-subtle mt-1 break-all text-xs`,children:n})]})]}),s(`div`,{className:`flex flex-wrap justify-end gap-2`,children:[a?s(u,{tone:_(a),children:a}):null,s(u,{tone:_(e.status),children:String(e.status||`unknown`)})]})]}),s(`div`,{className:`tcp-subtle mt-2 grid gap-1 text-xs md:grid-cols-2`,children:[s(`div`,{children:[`Source: `,i]}),s(`div`,{children:[`Created:`,` `,ue(le(e,[`created_at_ms`,`created_at`]))]}),s(`div`,{children:[`Updated:`,` `,ue(le(e,[`updated_at_ms`,`last_seen_at_ms`,`updated_at`]))]}),s(`div`,{children:[`Occurrences: `,Number(e.occurrence_count||0)]})]}),s(we,{record:e}),s(Se,{record:e,kind:`incident`}),e.detail?s(`div`,{className:`tcp-subtle mt-2 line-clamp-3 text-xs`,children:fe(e.detail)}):null,e.last_error?s(`div`,{className:`tcp-subtle mt-2 break-words text-xs text-rose-200`,children:String(e.last_error)}):null,s(Te,{record:e}),s(`div`,{className:`mt-3 flex flex-wrap gap-2`,children:[s(`button`,{type:`button`,className:`tcp-btn h-8 px-3 text-xs`,disabled:H.isPending,onClick:()=>H.mutate({action:`view`,incident:e}),children:[s(`i`,{"data-lucide":`file-search`}),`View`]}),s(`button`,{type:`button`,className:`tcp-btn h-8 px-3 text-xs`,disabled:H.isPending,onClick:()=>H.mutate({action:`replay`,incident:e}),children:[s(`i`,{"data-lucide":`rotate-cw`}),`Replay incident`]}),e.draft_id?s(`button`,{type:`button`,className:`tcp-btn h-8 px-3 text-xs`,disabled:H.isPending,onClick:()=>H.mutate({action:`triage`,incident:e}),children:[s(`i`,{"data-lucide":`sparkles`}),`Create triage run`]}):null,s(`button`,{type:`button`,className:`tcp-btn h-8 px-3 text-xs border-rose-500/30 text-rose-100 hover:bg-rose-950/20`,disabled:W.isPending,onClick:()=>Ae({ids:[n],all:!1}),children:[s(`i`,{"data-lucide":`trash-2`}),`Delete`]})]})]},n)})}):s(c,{title:`No incidents`,text:`No runtime or workflow failures have been captured.`})]}),s(ne,{title:`Drafts`,subtitle:`${K.length} recent draft${K.length===1?``:`s`}`,actions:s(`div`,{className:`flex flex-wrap items-center justify-end gap-2`,children:[s(u,{tone:K.length?`info`:`ghost`,children:K.length}),s(`button`,{type:`button`,className:`tcp-icon-btn`,title:j?`Expand drafts`:`Collapse drafts`,"aria-label":j?`Expand drafts`:`Collapse drafts`,onClick:()=>Fe(e=>!e),children:s(`i`,{"data-lucide":j?`chevron-down`:`chevron-up`})}),s(u,{tone:`ghost`,children:st}),s(u,{tone:A.length?`info`:`ghost`,children:[A.length,` selected`]}),s(`button`,{type:`button`,className:`tcp-icon-btn`,title:`Select all on this page`,"aria-label":`Select all on this page`,onClick:yt,disabled:!ot.length,children:s(`i`,{"data-lucide":`square-check-big`})}),s(`button`,{type:`button`,className:`tcp-icon-btn`,title:`Clear selection`,"aria-label":`Clear selection`,onClick:()=>Pe([]),disabled:!A.length,children:s(`i`,{"data-lucide":`x`})}),s(`button`,{type:`button`,className:`tcp-icon-btn border-rose-500/30 text-rose-100 hover:bg-rose-950/20 disabled:opacity-50`,title:`Delete selected drafts`,"aria-label":`Delete selected drafts`,onClick:()=>Ie({ids:A,all:!1}),disabled:!A.length||Ge.isPending,children:s(`i`,{"data-lucide":`trash-2`})}),s(`button`,{type:`button`,className:`tcp-icon-btn border-rose-500/30 text-rose-100 hover:bg-rose-950/20 disabled:opacity-50`,title:`Delete all drafts`,"aria-label":`Delete all drafts`,onClick:()=>Ie({ids:[],all:!0}),disabled:!K.length||Ge.isPending,children:s(`i`,{"data-lucide":`list-x`})}),s(`label`,{className:`flex items-center gap-2 text-[11px] uppercase tracking-wide text-slate-500`,children:[s(`span`,{children:`Per page`}),s(`select`,{className:`tcp-input h-8 min-w-[4rem] px-2 text-xs leading-none`,value:k,onChange:e=>{Ne(Number(e.target.value)||d),Me(1)},children:ie.map(e=>s(`option`,{value:e,children:e},e))})]}),s(`button`,{type:`button`,className:`tcp-icon-btn`,title:`Previous page`,"aria-label":`Previous page`,onClick:()=>Me(e=>p(e-1,it)),disabled:Y<=1,children:s(`i`,{"data-lucide":`chevron-left`})}),s(`button`,{type:`button`,className:`tcp-icon-btn`,title:`Next page`,"aria-label":`Next page`,onClick:()=>Me(e=>p(e+1,it)),disabled:Y>=it,children:s(`i`,{"data-lucide":`chevron-right`})})]}),children:[j?null:z.isError?s(De,{error:z.error}):null,j?null:z.isLoading?s(c,{title:`Loading drafts`,text:`Checking generated issue drafts.`}):K.length?s(`div`,{className:`grid gap-3`,children:ot.map((e,t)=>{let n=Qe(e,at+t),r=h(e,[`matched_issue_number`,`issue_number`]),i=ge(e),a=_e(e),o=h(e,[`confidence`,`match_confidence`]);return s(`div`,{className:`tcp-list-item`,children:[s(`div`,{className:`flex flex-wrap items-start justify-between gap-3`,children:[s(`div`,{className:`flex min-w-0 items-start gap-3`,children:[s(`label`,{className:`mt-1 flex h-6 w-6 cursor-pointer items-center justify-center rounded border border-white/15 bg-black/20 hover:border-sky-500/40`,children:s(`input`,{type:`checkbox`,className:`h-4 w-4 accent-sky-400`,checked:pt.has(n),onChange:()=>gt(n),"aria-label":`Select draft ${n}`})}),s(`div`,{className:`min-w-0`,children:[s(`div`,{className:`truncate font-medium`,children:h(e,[`title`,`fingerprint`],n)}),s(`div`,{className:`tcp-subtle mt-1 break-all text-xs`,children:n})]})]}),s(u,{tone:_(e.status),children:String(e.status||`unknown`)})]}),s(`div`,{className:`tcp-subtle mt-2 grid gap-1 text-xs md:grid-cols-3`,children:[s(`div`,{children:[`Repo: `,h(e,[`repo`],`unset`)]}),s(`div`,{children:[`Created: `,ue(le(e,[`created_at_ms`,`created_at`]))]}),s(`div`,{children:[`Match:`,` `,r?`#${r}${e.matched_issue_state?` (${e.matched_issue_state})`:``}`:`none`,o?` · ${o}`:``]})]}),s(we,{record:e}),s(Se,{record:e,kind:`draft`}),s(`div`,{className:`tcp-subtle mt-2 whitespace-pre-wrap text-xs`,children:fe(e.detail||e.evidence_digest)}),e.last_post_error?s(`div`,{className:`tcp-subtle mt-2 break-words text-xs text-rose-200`,children:String(e.last_post_error)}):null,s(Te,{record:e}),s(`div`,{className:`mt-3 flex flex-wrap gap-2`,children:[s(`button`,{type:`button`,className:`tcp-btn h-8 px-3 text-xs`,disabled:U.isPending,onClick:()=>U.mutate({action:`view`,draft:e}),children:[s(`i`,{"data-lucide":`file-search`}),`View`]}),s(`button`,{type:`button`,className:`tcp-btn h-8 px-3 text-xs`,disabled:U.isPending,onClick:()=>U.mutate({action:`approve`,draft:e,reason:window.prompt(`Approval reason`,`Approved from Bug Monitor.`)||void 0}),children:[s(`i`,{"data-lucide":`check`}),`Approve`]}),s(`button`,{type:`button`,className:`tcp-btn h-8 px-3 text-xs`,disabled:U.isPending,onClick:()=>U.mutate({action:`deny`,draft:e,reason:window.prompt(`Denial reason`,`Denied from Bug Monitor.`)||void 0}),children:[s(`i`,{"data-lucide":`x`}),`Deny`]}),s(`button`,{type:`button`,className:`tcp-btn h-8 px-3 text-xs`,disabled:U.isPending,onClick:()=>U.mutate({action:`triage-run`,draft:e}),children:[s(`i`,{"data-lucide":`sparkles`}),`Triage run`]}),s(`button`,{type:`button`,className:`tcp-btn h-8 px-3 text-xs`,disabled:U.isPending,onClick:()=>U.mutate({action:`triage-summary`,draft:e}),children:[s(`i`,{"data-lucide":`clipboard-list`}),`Triage summary`]}),s(`button`,{type:`button`,className:`tcp-btn h-8 px-3 text-xs`,disabled:U.isPending,onClick:()=>U.mutate({action:`issue-draft`,draft:e}),children:[s(`i`,{"data-lucide":`square-pen`}),`Issue draft`]}),s(`button`,{type:`button`,className:`tcp-btn h-8 px-3 text-xs`,disabled:U.isPending,onClick:()=>U.mutate({action:`publish`,draft:e}),children:[s(`i`,{"data-lucide":`bug-play`}),`Publish`]}),s(`button`,{type:`button`,className:`tcp-btn h-8 px-3 text-xs`,disabled:U.isPending,onClick:()=>U.mutate({action:`recheck`,draft:e}),children:[s(`i`,{"data-lucide":`refresh-cw`}),`Recheck match`]}),i?s(`a`,{className:`tcp-btn h-8 px-3 text-xs`,href:i,target:`_blank`,rel:`noreferrer`,children:[s(`i`,{"data-lucide":`external-link`}),ve(e)]}):null,a?s(`a`,{className:`tcp-btn h-8 px-3 text-xs`,href:a,target:`_blank`,rel:`noreferrer`,children:[s(`i`,{"data-lucide":`message-square`}),`GitHub comment`]}):null,s(`button`,{type:`button`,className:`tcp-btn h-8 px-3 text-xs border-rose-500/30 text-rose-100 hover:bg-rose-950/20`,disabled:Ge.isPending,onClick:()=>Ie({ids:[n],all:!1}),children:[s(`i`,{"data-lucide":`trash-2`}),`Delete`]})]})]},n)})}):s(c,{title:`No drafts`,text:`No generated issue drafts are waiting.`})]}),s(ne,{title:`Posts / Published Issues`,subtitle:`${q.length} recent post${q.length===1?``:`s`}`,actions:s(`div`,{className:`flex flex-wrap items-center justify-end gap-2`,children:[s(u,{tone:q.length?`info`:`ghost`,children:q.length}),s(`button`,{type:`button`,className:`tcp-icon-btn`,title:F?`Expand posts`:`Collapse posts`,"aria-label":F?`Expand posts`:`Collapse posts`,onClick:()=>Ve(e=>!e),children:s(`i`,{"data-lucide":F?`chevron-down`:`chevron-up`})}),s(u,{tone:`ghost`,children:dt}),s(u,{tone:P.length?`info`:`ghost`,children:[P.length,` selected`]}),s(`button`,{type:`button`,className:`tcp-icon-btn`,title:`Select all on this page`,"aria-label":`Select all on this page`,onClick:bt,disabled:!ut.length,children:s(`i`,{"data-lucide":`square-check-big`})}),s(`button`,{type:`button`,className:`tcp-icon-btn`,title:`Clear selection`,"aria-label":`Clear selection`,onClick:()=>Be([]),disabled:!P.length,children:s(`i`,{"data-lucide":`x`})}),s(`button`,{type:`button`,className:`tcp-icon-btn border-rose-500/30 text-rose-100 hover:bg-rose-950/20 disabled:opacity-50`,title:`Delete selected posts`,"aria-label":`Delete selected posts`,onClick:()=>He({ids:P,all:!1}),disabled:!P.length||Ke.isPending,children:s(`i`,{"data-lucide":`trash-2`})}),s(`button`,{type:`button`,className:`tcp-icon-btn border-rose-500/30 text-rose-100 hover:bg-rose-950/20 disabled:opacity-50`,title:`Delete all posts`,"aria-label":`Delete all posts`,onClick:()=>He({ids:[],all:!0}),disabled:!q.length||Ke.isPending,children:s(`i`,{"data-lucide":`list-x`})}),s(`label`,{className:`flex items-center gap-2 text-[11px] uppercase tracking-wide text-slate-500`,children:[s(`span`,{children:`Per page`}),s(`select`,{className:`tcp-input h-8 min-w-[4rem] px-2 text-xs leading-none`,value:N,onChange:e=>{ze(Number(e.target.value)||d),Re(1)},children:ie.map(e=>s(`option`,{value:e,children:e},e))})]}),s(`button`,{type:`button`,className:`tcp-icon-btn`,title:`Previous page`,"aria-label":`Previous page`,onClick:()=>Re(e=>p(e-1,ct)),disabled:X<=1,children:s(`i`,{"data-lucide":`chevron-left`})}),s(`button`,{type:`button`,className:`tcp-icon-btn`,title:`Next page`,"aria-label":`Next page`,onClick:()=>Re(e=>p(e+1,ct)),disabled:X>=ct,children:s(`i`,{"data-lucide":`chevron-right`})})]}),children:[F?null:B.isError?s(De,{error:B.error}):null,F?null:B.isLoading?s(c,{title:`Loading posts`,text:`Checking GitHub publishing attempts.`}):q.length?s(`div`,{className:`grid gap-3`,children:ut.map((e,t)=>{let n=$e(e,lt+t),r=ge(e),i=_e(e);return s(`div`,{className:`tcp-list-item`,children:[s(`div`,{className:`flex flex-wrap items-start justify-between gap-3`,children:[s(`div`,{className:`flex min-w-0 items-start gap-3`,children:[s(`label`,{className:`mt-1 flex h-6 w-6 cursor-pointer items-center justify-center rounded border border-white/15 bg-black/20 hover:border-sky-500/40`,children:s(`input`,{type:`checkbox`,className:`h-4 w-4 accent-sky-400`,checked:mt.has(n),onChange:()=>_t(n),"aria-label":`Select post ${n}`})}),s(`div`,{className:`min-w-0`,children:[s(`div`,{className:`truncate font-medium`,children:h(e,[`title`,`operation`],`GitHub post`)}),s(`div`,{className:`tcp-subtle mt-1 break-all text-xs`,children:n})]})]}),s(u,{tone:_(e.status),children:String(e.status||`unknown`)})]}),s(`div`,{className:`tcp-subtle mt-2 grid gap-1 text-xs`,children:[s(`div`,{children:[`Repo: `,h(e,[`repo`],`unset`)]}),s(`div`,{children:[`Posted:`,` `,ue(le(e,[`posted_at_ms`,`github_posted_at_ms`,`created_at_ms`,`updated_at_ms`]))]}),e.issue_number?s(`div`,{children:[`Issue: #`,String(e.issue_number)]}):null]}),s(we,{record:e}),s(Se,{record:e,kind:`post`}),e.error?s(`div`,{className:`tcp-subtle mt-2 break-words text-xs text-rose-200`,children:String(e.error)}):null,s(`div`,{className:`mt-3 flex flex-wrap gap-2`,children:[r?s(`a`,{className:`tcp-btn h-8 px-3 text-xs`,href:r,target:`_blank`,rel:`noreferrer`,children:[s(`i`,{"data-lucide":`external-link`}),ve(e)]}):null,i?s(`a`,{className:`tcp-btn h-8 px-3 text-xs`,href:i,target:`_blank`,rel:`noreferrer`,children:[s(`i`,{"data-lucide":`message-square`}),`GitHub comment`]}):null,s(`button`,{type:`button`,className:`tcp-btn h-8 px-3 text-xs border-rose-500/30 text-rose-100 hover:bg-rose-950/20`,disabled:Ke.isPending,onClick:()=>He({ids:[n],all:!1}),children:[s(`i`,{"data-lucide":`trash-2`}),`Delete`]})]})]},n)})}):s(c,{title:`No published issues`,text:`No GitHub publishing attempts have been recorded.`})]})]}),s(l,{open:!!S,title:S?.title||`Bug Monitor Detail`,onClose:()=>C(null),children:s(`pre`,{className:`tcp-code whitespace-pre-wrap break-words text-xs`,children:S?de(S.value):``})}),s(l,{open:he,title:`Report Issue`,onClose:()=>ye(!1),children:s(`form`,{className:`grid gap-3`,onSubmit:e=>{e.preventDefault(),We.mutate(void 0,{onSuccess:()=>ye(!1)})},children:[s(`p`,{className:`tcp-subtle text-xs`,children:`Manual issue intake for runtime findings.`}),s(`label`,{className:`grid gap-1`,children:[s(`span`,{className:`tcp-subtle text-xs uppercase tracking-[0.18em]`,children:`Title`}),s(`input`,{className:`tcp-input`,value:b.title,onChange:e=>x(t=>({...t,title:e.currentTarget.value})),placeholder:`Failure title`})]}),s(`label`,{className:`grid gap-1`,children:[s(`span`,{className:`tcp-subtle text-xs uppercase tracking-[0.18em]`,children:`Summary / body`}),s(`textarea`,{className:`tcp-input min-h-28 resize-y`,value:b.body,onChange:e=>x(t=>({...t,body:e.currentTarget.value})),placeholder:`What happened?`})]}),s(`div`,{className:`grid gap-3 md:grid-cols-2`,children:[s(`label`,{className:`grid gap-1`,children:[s(`span`,{className:`tcp-subtle text-xs uppercase tracking-[0.18em]`,children:`Severity`}),s(`select`,{className:`tcp-input`,value:b.severity,onChange:e=>x(t=>({...t,severity:e.currentTarget.value})),children:[s(`option`,{value:`error`,children:`Error`}),s(`option`,{value:`warn`,children:`Warning`}),s(`option`,{value:`info`,children:`Info`}),s(`option`,{value:`critical`,children:`Critical`})]})]}),s(`label`,{className:`grid gap-1`,children:[s(`span`,{className:`tcp-subtle text-xs uppercase tracking-[0.18em]`,children:`Source`}),s(`input`,{className:`tcp-input`,value:b.source,onChange:e=>x(t=>({...t,source:e.currentTarget.value})),placeholder:`manual, runtime, workflow`})]}),s(`label`,{className:`grid gap-1 md:col-span-2`,children:[s(`span`,{className:`tcp-subtle text-xs uppercase tracking-[0.18em]`,children:`Labels`}),s(`input`,{className:`tcp-input`,value:b.labels,onChange:e=>x(t=>({...t,labels:e.currentTarget.value})),placeholder:`bug-monitor, regression`})]}),s(`label`,{className:`grid gap-1`,children:[s(`span`,{className:`tcp-subtle text-xs uppercase tracking-[0.18em]`,children:`Confidence`}),s(`select`,{className:`tcp-input`,value:b.confidence,onChange:e=>x(t=>({...t,confidence:e.currentTarget.value})),children:[s(`option`,{value:`high`,children:`High`}),s(`option`,{value:`medium`,children:`Medium`}),s(`option`,{value:`low`,children:`Low`})]})]}),s(`label`,{className:`grid gap-1`,children:[s(`span`,{className:`tcp-subtle text-xs uppercase tracking-[0.18em]`,children:`Risk level`}),s(`select`,{className:`tcp-input`,value:b.riskLevel,onChange:e=>x(t=>({...t,riskLevel:e.currentTarget.value})),children:[s(`option`,{value:`low`,children:`Low`}),s(`option`,{value:`medium`,children:`Medium`}),s(`option`,{value:`high`,children:`High`})]})]}),s(`label`,{className:`grid gap-1 md:col-span-2`,children:[s(`span`,{className:`tcp-subtle text-xs uppercase tracking-[0.18em]`,children:`Expected destination`}),s(`select`,{className:`tcp-input`,value:b.expectedDestination,onChange:e=>x(t=>({...t,expectedDestination:e.currentTarget.value})),children:[s(`option`,{value:`bug_monitor_issue_draft`,children:`Bug Monitor issue draft`}),s(`option`,{value:`triage_only`,children:`Triage only`}),s(`option`,{value:`research_brief`,children:`Research brief`}),s(`option`,{value:`workflow_proposal`,children:`Workflow proposal`}),s(`option`,{value:`product_opportunity`,children:`Product opportunity`})]})]}),s(`label`,{className:`grid gap-1 md:col-span-2`,children:[s(`span`,{className:`tcp-subtle text-xs uppercase tracking-[0.18em]`,children:`Evidence refs`}),s(`textarea`,{className:`tcp-input min-h-20 resize-y`,value:b.evidenceRefs,onChange:e=>x(t=>({...t,evidenceRefs:e.currentTarget.value})),placeholder:`One artifact, log, file, URL, or context ref per line`})]}),s(`label`,{className:`grid gap-1`,children:[s(`span`,{className:`tcp-subtle text-xs uppercase tracking-[0.18em]`,children:`Related run ID`}),s(`input`,{className:`tcp-input`,value:b.relatedRunId,onChange:e=>x(t=>({...t,relatedRunId:e.currentTarget.value}))})]}),s(`label`,{className:`grid gap-1`,children:[s(`span`,{className:`tcp-subtle text-xs uppercase tracking-[0.18em]`,children:`Related workflow ID`}),s(`input`,{className:`tcp-input`,value:b.relatedWorkflowId,onChange:e=>x(t=>({...t,relatedWorkflowId:e.currentTarget.value}))})]}),s(`label`,{className:`grid gap-1 md:col-span-2`,children:[s(`span`,{className:`tcp-subtle text-xs uppercase tracking-[0.18em]`,children:`Related file / path`}),s(`input`,{className:`tcp-input`,value:b.relatedFile,onChange:e=>x(t=>({...t,relatedFile:e.currentTarget.value}))})]}),s(`label`,{className:`grid gap-1 md:col-span-2`,children:[s(`span`,{className:`tcp-subtle text-xs uppercase tracking-[0.18em]`,children:`Reproduction notes`}),s(`textarea`,{className:`tcp-input min-h-20 resize-y`,value:b.reproductionNotes,onChange:e=>x(t=>({...t,reproductionNotes:e.currentTarget.value}))})]}),s(`label`,{className:`grid gap-1`,children:[s(`span`,{className:`tcp-subtle text-xs uppercase tracking-[0.18em]`,children:`Expected behavior`}),s(`textarea`,{className:`tcp-input min-h-20 resize-y`,value:b.expectedBehavior,onChange:e=>x(t=>({...t,expectedBehavior:e.currentTarget.value}))})]}),s(`label`,{className:`grid gap-1`,children:[s(`span`,{className:`tcp-subtle text-xs uppercase tracking-[0.18em]`,children:`Actual behavior`}),s(`textarea`,{className:`tcp-input min-h-20 resize-y`,value:b.actualBehavior,onChange:e=>x(t=>({...t,actualBehavior:e.currentTarget.value}))})]})]}),s(`div`,{className:`flex flex-wrap justify-end gap-2`,children:[s(`button`,{type:`button`,className:`tcp-btn h-8 px-3 text-xs`,onClick:()=>x(oe),disabled:We.isPending,children:[s(`i`,{"data-lucide":`eraser`}),`Clear`]}),s(`button`,{type:`button`,className:`tcp-btn h-8 px-3 text-xs`,onClick:()=>ye(!1),disabled:We.isPending,children:[s(`i`,{"data-lucide":`x`}),`Cancel`]}),s(`button`,{type:`submit`,className:`tcp-btn-primary h-8 px-3 text-xs`,disabled:We.isPending,children:[s(`i`,{"data-lucide":`send`}),We.isPending?`Submitting...`:`Submit report`]})]})]})}),s(re,{open:!!O,title:O?.all?`Delete all incidents`:`Delete selected incidents`,message:s(`span`,{children:O?.all?`This will permanently remove all ${G.length} incident(s).`:`This will permanently remove ${O?.ids.length||0} selected incident(s).`}),confirmLabel:W.isPending?`Deleting...`:`Delete`,confirmIcon:`trash-2`,confirmTone:`danger`,confirmDisabled:W.isPending,onCancel:()=>Ae(null),onConfirm:()=>{O&&W.mutate({ids:O.ids,all:O.all})}}),s(re,{open:!!M,title:M?.all?`Delete all drafts`:`Delete selected drafts`,message:s(`span`,{children:M?.all?`This will permanently remove all ${K.length} draft(s).`:`This will permanently remove ${M?.ids.length||0} selected draft(s).`}),confirmLabel:Ge.isPending?`Deleting...`:`Delete`,confirmIcon:`trash-2`,confirmTone:`danger`,confirmDisabled:Ge.isPending,onCancel:()=>Ie(null),onConfirm:()=>{M&&Ge.mutate({ids:M.ids,all:M.all})}}),s(re,{open:!!I,title:I?.all?`Delete all posts`:`Delete selected posts`,message:s(`span`,{children:I?.all?`This will permanently remove all ${q.length} post(s).`:`This will permanently remove ${I?.ids.length||0} selected post(s).`}),confirmLabel:Ke.isPending?`Deleting...`:`Delete`,confirmIcon:`trash-2`,confirmTone:`danger`,confirmDisabled:Ke.isPending,onCancel:()=>He(null),onConfirm:()=>{I&&Ke.mutate({ids:I.ids,all:I.all})}})]})}export{E as BugMonitorPage};
@@ -0,0 +1 @@
1
+ import{a as e,n as t,t as n}from"./react-query-BIbNygEJ.js";import{i as r}from"./motion-B3ZE8SGR.js";import{c as i,s as a}from"./index-TvymvGva.js";function o({client:o,toast:s}){let c=e(),l=t({queryKey:[`channels`,`status`],queryFn:()=>o.channels.status().catch(()=>({})),refetchInterval:6e3}),u=t({queryKey:[`channels`,`config`],queryFn:()=>o.channels.config().catch(()=>({})),refetchInterval:15e3}),d=n({mutationFn:async e=>{let t=(u.data||{})[e];if(!t)throw Error(`No config found for ${e}`);await o.channels.put(e,t)},onSuccess:async()=>{s(`ok`,`Channel reconfigured.`),await c.invalidateQueries({queryKey:[`channels`]})},onError:e=>s(`err`,e instanceof Error?e.message:String(e))}),f=l.data&&typeof l.data==`object`?l.data:{},p=Object.entries(f);return r(`div`,{className:`grid gap-4`,children:[r(i,{title:`Chat automation drafts`,subtitle:`How Tandem turns channel messages into bounded automations`,children:r(`div`,{className:`grid gap-3 text-sm`,children:[r(`p`,{className:`tcp-subtle`,children:`When someone asks Tandem to create an automation from Discord, Telegram, Slack, or a direct chat, Tandem keeps the draft in that same conversation instead of opening the workflow editor.`}),r(`div`,{className:`grid gap-2 md:grid-cols-3`,children:[r(`div`,{className:`tcp-list-item`,children:[r(`strong`,{children:`Questions`}),r(`div`,{className:`tcp-subtle mt-1 text-xs`,children:`Tandem captures the next non-command reply from the same person in the same chat scope.`})]}),r(`div`,{className:`tcp-list-item`,children:[r(`strong`,{children:`Confirmation`}),r(`div`,{className:`tcp-subtle mt-1 text-xs`,children:`The draft is only created after a plain text confirm. Reply cancel to stop.`})]}),r(`div`,{className:`tcp-list-item`,children:[r(`strong`,{children:`Bounds`}),r(`div`,{className:`tcp-subtle mt-1 text-xs`,children:`The created automation records the source channel, sender, scope, and allowed tool policy.`})]})]})]})}),r(i,{title:`Channels`,subtitle:`Connector health and quick reconnect`,children:r(`div`,{className:`grid gap-2`,children:p.length?p.map(([e,t])=>r(`div`,{className:`tcp-list-item`,children:[r(`div`,{className:`mb-1 flex items-center justify-between gap-2`,children:[r(`strong`,{children:e}),r(`span`,{className:t?.connected?`tcp-badge-ok`:`tcp-badge-warn`,children:t?.connected?`connected`:`disconnected`})]}),r(`div`,{className:`tcp-subtle text-xs`,children:String(t?.last_error||t?.error||``)||`No recent errors.`}),r(`div`,{className:`mt-2`,children:r(`button`,{className:`tcp-btn h-7 px-2 text-xs`,onClick:()=>d.mutate(e),children:[r(`i`,{"data-lucide":`refresh-cw`}),`Reconnect`]})})]},e)):r(a,{text:`No channels configured.`})})})]})}export{o as ChannelsPage};
@@ -0,0 +1 @@
1
+ import{C as e,h as t}from"./fullcalendar-Bn75j0xM.js";import{i as n,n as r,r as i,t as a}from"./motion-B3ZE8SGR.js";import{a as o,u as s}from"./index-TvymvGva.js";function c({messages:c,emptyText:l,inputValue:u,inputPlaceholder:d,sendLabel:f,onInputChange:p,onSend:m,sendDisabled:h=!1,inputDisabled:g=!1,statusTitle:_=``,statusDetail:v=``,questionTitle:y=``,questionText:b=``,quickReplies:x=[],onQuickReply:S,questionHint:C=``,botIdentity:w,streamingText:T=``,showThinking:E=!1,thinkingText:D=`Thinking`,autoFocusKey:O,attachments:k=[],onOpenAttachment:A,onRemoveAttachment:j,onAttach:M,attachDisabled:N=!1,composerAccessory:P,className:F=``}){let I=!!a(),L=t(null),R=t(null),z=t(null),B=t(!0),V=e=>e.scrollHeight-e.scrollTop-e.clientHeight<=24;e(()=>{let e=R.current;e&&B.current&&(e.scrollTop=e.scrollHeight)},[c,T,E]),e(()=>{let e=z.current;e&&(e.style.height=`0px`,e.style.height=`${Math.min(e.scrollHeight,180)}px`)},[u]),e(()=>{if(O==null||g)return;let e=z.current;if(e){e.focus();try{let t=e.value.length;e.setSelectionRange(t,t)}catch{}}},[O,g]),e(()=>{L.current&&o(L.current)},[k,u,c,x,h,E,T]);let H=w?.botName||`Assistant`;return n(`div`,{ref:L,className:`rounded-2xl border border-white/10 bg-black/20 p-3 flex min-h-0 flex-1 flex-col ${F}`,children:[b?n(`div`,{className:`mb-3 rounded-xl border border-sky-500/40 bg-sky-950/30 p-3`,children:[n(`div`,{className:`text-xs uppercase tracking-wide text-sky-200`,children:y||`Planner question`}),n(`div`,{className:`mt-1 text-sm font-medium text-sky-100`,children:b}),x.length?n(`div`,{className:`mt-2 flex flex-wrap gap-2`,children:x.map(e=>n(`button`,{type:`button`,className:`tcp-btn text-sm`,disabled:g,onClick:()=>S?.(e),children:e.label},e.id))}):null,C?n(`div`,{className:`mt-2 text-xs text-sky-200/80`,children:C}):null]}):null,n(`div`,{ref:R,className:`chat-messages mb-2 min-h-0 min-w-0 flex-1 overflow-auto p-2 space-y-2`,onScroll:()=>{let e=R.current;e&&(B.current=V(e))},children:[c.length?n(i,{initial:!1,children:c.map(e=>{let t=e.role===`assistant`||e.role===`system`;return n(r.article,{className:`chat-msg ${t?`assistant`:`user`}`,initial:I?!1:{opacity:0,y:4},animate:I?void 0:{opacity:1,y:0},exit:I?void 0:{opacity:0,y:-4},children:[n(`div`,{className:`chat-msg-role`,children:t?n(`span`,{className:`inline-flex items-center gap-2`,children:[w?.botAvatarUrl?n(`img`,{src:w.botAvatarUrl,alt:H,className:`chat-avatar-ring h-5 w-5 object-cover`}):null,n(`span`,{children:e.displayRole||H})]}):e.displayRole||e.role}),e.markdown?n(`div`,{className:`tcp-markdown tcp-markdown-ai`,dangerouslySetInnerHTML:{__html:s(e.text||``)}}):n(`pre`,{className:`chat-msg-pre`,children:e.text||` `})]},e.id)})}):n(`div`,{className:`chat-empty-state`,children:n(`p`,{className:`chat-rail-empty`,children:l})}),E||T?n(`article`,{className:`chat-msg assistant`,children:[n(`div`,{className:`chat-msg-role`,children:n(`span`,{className:`inline-flex items-center gap-2`,children:[w?.botAvatarUrl?n(`img`,{src:w.botAvatarUrl,alt:H,className:`chat-avatar-ring h-5 w-5 object-cover`}):null,n(`span`,{children:H})]})}),E&&!T?n(`div`,{className:`tcp-thinking`,"aria-live":`polite`,children:[n(`span`,{children:D}),n(`i`,{}),n(`i`,{}),n(`i`,{})]}):null,T?n(`pre`,{className:`chat-msg-pre`,children:T}):null]}):null]}),_?n(`div`,{className:`mb-2 rounded-xl border border-sky-500/30 bg-sky-950/20 p-3 text-sm text-sky-100`,children:[n(`div`,{className:`flex items-center gap-2 font-medium`,children:[n(`span`,{className:`inline-block h-4 w-4 animate-spin rounded-full border-2 border-sky-200 border-t-transparent`,"aria-hidden":`true`}),_]}),v?n(`div`,{className:`mt-1 text-xs text-sky-200/80`,children:v}):null]}):null,n(`div`,{className:`chat-composer shrink-0`,children:[P?n(`div`,{className:`mb-2`,children:P}):null,k.length?n(`div`,{className:`chat-attach-row mb-2 flex flex-wrap items-center gap-2`,children:[n(`span`,{className:`tcp-subtle text-xs`,children:[k.length,` attached`]}),n(`div`,{className:`flex flex-wrap gap-1`,children:k.map((e,t)=>n(`span`,{className:`chat-file-pill min-w-0`,children:[n(`span`,{className:`chat-file-pill-name`,title:e.path,children:e.name||e.path}),e.size==null?null:n(`span`,{className:`chat-file-pill-size`,children:e.size<1024?`${e.size}B`:e.size<1024*1024?`${(e.size/1024).toFixed(1)}KB`:`${(e.size/1024/1024).toFixed(1)}MB`}),A?n(`button`,{type:`button`,className:`chat-file-pill-btn`,title:`Open in Files`,onClick:()=>A(t),children:n(`i`,{"data-lucide":`folder-open`})}):null,j?n(`button`,{type:`button`,className:`chat-file-pill-btn chat-file-pill-btn-danger`,title:`Remove from list`,onClick:()=>j(t),children:n(`i`,{"data-lucide":`x`})}):null]},`${e.path}-${t}`))})]}):null,n(`div`,{className:`chat-input-wrap`,children:[M?n(`button`,{type:`button`,className:`chat-icon-btn chat-icon-btn-inner`,title:`Attach files`,disabled:N,onClick:M,children:n(`i`,{"data-lucide":`paperclip`})}):null,n(`textarea`,{ref:z,rows:1,value:u,className:`tcp-input chat-input-with-clip chat-input-modern resize-none`,placeholder:d,disabled:g,onInput:e=>p(e.target.value),onKeyDown:e=>{e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),h||m())}}),n(`button`,{type:`button`,className:`chat-send-btn`,title:f,disabled:h,onClick:m,children:n(`i`,{"data-lucide":`send`})})]})]})]})}export{c as t};
@@ -0,0 +1 @@
1
+ import{C as e,g as t,h as n,v as r,x as i}from"./fullcalendar-Bn75j0xM.js";import{a}from"./react-query-BIbNygEJ.js";import{i as o,n as s,r as c,t as ee}from"./motion-B3ZE8SGR.js";import{a as l}from"./index-TvymvGva.js";import{A as u,C as te,D as ne,E as re,O as d,S as ie,T as f,_ as p,a as m,b as ae,c as oe,d as se,f as h,g as ce,h as le,i as ue,k as de,l as fe,m as pe,n as me,o as he,p as ge,r as _e,s as ve,t as ye,u as be,v as g,w as xe,x as Se,y as Ce}from"./chatPageHelpers-Dmb4waDk.js";import{r as we}from"./explorerHandoff-BPKxMR82.js";import{t as Te}from"./sse-B4A2m-Nk.js";import{t as Ee}from"./ChatInterfacePanel-BrMo4cXg.js";import{t as De}from"./messages-uD0aB_MZ.js";var _=`tcp.chat.session`;function v(e){return String(e?.id||e?.session_id||e?.sessionID||``).trim()}function y(e){let t=String(e?.title||e?.name||``).trim();if(t)return t;let n=v(e);return n?`Session ${n.slice(0,8)}`:`Session`}function b(e){return Array.isArray(e)?e:Array.isArray(e?.sessions)?e.sessions:[]}function x(e){return String(e?.title||``).trim().toLowerCase().startsWith(`__provider_test__`)}function S(e){let t=String(e?.sourceKind||e?.source_kind||``).trim().toLowerCase().replace(/-/g,`_`);return!t||t===`chat`}function Oe(e){return b(e).filter(e=>!x(e)).filter(S).map(e=>({id:v(e),title:y(e),raw:e})).filter(e=>!!e.id)}async function ke(e,t){try{let t=Oe(await e.sessions.list({pageSize:50,source:`chat`}));if(t.length>0)return t}catch{}try{return Oe(await t(`/api/engine/session?page_size=50&source=chat`,{method:`GET`}))}catch{return[]}}function Ae(){try{return localStorage.getItem(`tcp.chat.session`)||``}catch{return``}}function je(e){try{e?localStorage.setItem(_,e):localStorage.removeItem(_)}catch{}}var Me=`uploads`;function Ne(e){return e.filter(e=>e.role===`assistant`&&e.text.trim().length>0).length}function Pe(e,t,n,r){let i=r.trim();if(!i)return e;let a=e[e.length-1];return a?.role===`assistant`&&a.text.trim()===i?e:[...e,{id:`local-assistant-${t||Date.now()}`,role:`assistant`,displayRole:n||`Assistant`,text:i,markdown:!0}]}function C({client:_,api:v,toast:y,providerStatus:b,identity:x,navigate:S}){let Oe=a(),C=!!ee(),Fe=n(null),Ie=n(null),Le=n(null),Re=n(null),ze=n(null),w=n(!0),T=n(null),E=n(null),[D,Be]=r([]),[O,k]=r(!1),[A,j]=r(Ae()),[M,N]=r([]),[Ve,He]=r(!1),[P,Ue]=r(``),[F,We]=r([]),[Ge,I]=r([]),[L,Ke]=r(!1),[qe,Je]=r(``),[Ye,R]=r(!1),[Xe,Ze]=r([]),[Qe,$e]=r(new Set),[et,tt]=r([]),[nt,rt]=r(new Set),[z,it]=r([]),[at,ot]=r(new Set),[B,st]=r(he()),[ct,lt]=r(!1),[V,ut]=r([]),[H,dt]=r(ve()),[ft,pt]=r(null),[U,mt]=r(null),[ht,gt]=r(``),_t=t(()=>D.find(e=>e.id===A)?.title||`Chat`,[A,D]),vt=t(()=>new Set(H),[H]);e(()=>(w.current=!0,()=>{w.current=!1,ze.current?.abort(),T.current&&window.clearTimeout(T.current),E.current&&window.clearTimeout(E.current)}),[]),e(()=>{let e=Fe.current;e&&l(e)},[D,F,Ge,z,Xe,et,H,M,O,Ye,qe]),e(()=>{je(A)},[A]),e(()=>{let e=Ie.current;e&&(e.style.height=`0px`,e.style.height=`${Math.min(e.scrollHeight,180)}px`)},[P]),e(()=>{let e=Re.current;e&&(e.scrollTop=e.scrollHeight)},[M,qe,Ye]);let W=i(async()=>{let e=await ke(_,v);w.current&&(Be(e),j(t=>{if(t&&e.some(e=>e.id===t))return t;let n=Ae();return n&&e.some(e=>e.id===n)?n:e[0]?.id||``}))},[v,_]),yt=i(async()=>{let e=String(b.defaultProvider||``).trim(),t=String(b.defaultModel||``).trim();if(e&&t)return{providerID:e,modelID:t};try{let e=await _.providers.config(),t=String(e?.default||``).trim(),n=String(e?.providers?.[t]?.defaultModel||``).trim();if(t&&n)return{providerID:t,modelID:n}}catch{}return null},[_.providers,b.defaultModel,b.defaultProvider]),G=i(async()=>{let e=await yt(),t={title:`Chat ${new Date().toLocaleTimeString()}`};e&&(t.provider=e.providerID,t.model=e.modelID);let n=await _.sessions.create(t),r=String(n||``).trim();if(!r)throw Error(`Failed to create session.`);return j(r),await W(),r},[_.sessions,W,yt]),bt=i(e=>{let t=De(e,x.botName||`Assistant`);return N(t),t},[x.botName]),K=i(async e=>{let t=String(e||``).trim();if(!t)return N([]),[];let n=await _.sessions.messages(t).catch(()=>({messages:[]}));if(!w.current)return[];let r=bt(n),i=me(n);i.length&&Ze(e=>{let t=new Set(e.map(e=>e.id));return[...i.filter(e=>!t.has(e.id)),...e].sort((e,t)=>t.at-e.at).slice(0,80)});let a=ye(n);return a.length&&tt(e=>{let t=new Set(e.map(e=>e.id));return[...a.filter(e=>!t.has(e.id)),...e].sort((e,t)=>t.at-e.at).slice(0,80)}),r},[_.sessions,bt]),xt=i(async()=>{if(!A){N([]);return}He(!0);try{await K(A)}finally{w.current&&He(!1)}},[K,A]),St=i(()=>{Ze([]),$e(new Set)},[]),Ct=i(()=>{tt([]),rt(new Set)},[]),q=i((e,t,n=``,r={})=>{let i=String(e||``).trim();if(!i)return;let a=!0;n&&($e(e=>{if(e.has(n))return a=!1,e;let t=new Set(e);return t.add(n),t.size>1e3?new Set([n]):t}),!a)||Ze(e=>[{id:`${i}:${t}:${Date.now()}:${Math.random().toString(36).slice(2,8)}`,tool:i,status:t,at:Date.now(),...r},...e].slice(0,80))},[]),J=i((e,t,n=``)=>{let r=String(e||``).trim();if(!r||r===`server.connected`||r===`engine.lifecycle.ready`)return;let i=t&&typeof t==`object`?t:{},a=String(f({properties:i},n)||n),o=[r,a,re(i),String(i?.status||i?.state||``).trim(),String(i?.error||``).trim()].filter(Boolean).join(`:`),s=!0;rt(e=>{if(e.has(o))return s=!1,e;let t=new Set(e);return t.add(o),t.size>400?new Set([o]):t}),s&&tt(e=>[{id:`${o}:${Date.now()}`,type:r,title:ce(r),summary:le(r,i),tone:p(r,i),at:Number(i?.at||i?.createdAtMs||i?.startedAtMs||i?.finishedAtMs)||Date.now(),runId:a},...e].slice(0,80))},[]),Y=i((e,t,n=``)=>{let r=ne(t);if(!r)return;let i=re(t),a=String(f({properties:t},n)||n),o=String(e||``).toLowerCase(),s=o.includes(`fail`)||o.includes(`error`)?`failed`:o.includes(`complete`)||o.includes(`succeed`)||o.includes(`result`)||o.includes(`end`)?`completed`:toolStatusFromPayload(t);q(r,s,`${i||a||Date.now()}:${r}:${e}:${s}`,{callId:i,runId:a,source:e,summary:u(t),detail:u(t)})},[q]),wt=i(e=>{d(e?.status||``)&&it(t=>{let n=t.findIndex(t=>t.id===e.id);if(n>=0){let r=[...t];return r[n]={...r[n],...e},r}return[e,...t]})},[]),X=i(e=>{it(t=>t.filter(t=>t.id!==e))},[]),Z=i(async()=>{let e=await _.permissions.list().catch(()=>({requests:[]})),t=(Array.isArray(e?.requests)?e.requests:[]).map(e=>de(e)).filter(e=>!!e).filter(e=>oe(e.sessionId,A)).filter(e=>d(e.status));w.current&&it(t.slice(0,80))},[_.permissions,A]),Q=i(async(e,t,n=!1)=>{if(e&&!at.has(e)){ot(t=>{let n=new Set(t);return n.add(e),n});try{await _.permissions.reply(e,t),X(e),n||y(`ok`,`Permission ${t===`deny`?`denied`:`approved`} (${e}).`)}catch(e){n||y(`err`,g(e))}finally{ot(t=>{let n=new Set(t);return n.delete(e),n}),Z()}}},[_.permissions,at,Z,X,y]),Tt=i(async()=>{if(!(!B||ct||z.length===0)){lt(!0);try{for(let e of[...z])await Q(e.id,`always`,!0)}finally{w.current&&lt(!1)}}},[B,ct,z,Q]),Et=i(e=>(Array.isArray(e)?e:Array.isArray(e?.tools)?e.tools:[]).map(e=>{if(typeof e==`string`)return e;let t=e||{};return String(t.name||t.id||t.tool||``).trim()}).filter(Boolean),[]),Dt=i(async()=>{try{let e=Et(await _.listTools?.().catch(()=>null)||[]);e.length||(e=Et(await v(`/api/engine/tool`,{method:`GET`}).catch(()=>[])||[])),w.current&&ut([...new Set(e)].sort((e,t)=>e.localeCompare(t)))}catch{w.current&&ut([])}},[v,_,Et]),Ot=i(e=>new Promise((t,n)=>{let r=`${Date.now()}-${Math.random().toString(16).slice(2)}`;I(t=>[...t,{id:r,name:e.name,progress:0,error:``}]);let i=new XMLHttpRequest;i.open(`POST`,`/api/files/upload?dir=${encodeURIComponent(Me)}`),i.withCredentials=!0,i.responseType=`json`,i.setRequestHeader(`x-file-name`,encodeURIComponent(e.name)),i.upload.onprogress=e=>{if(!e.lengthComputable)return;let t=e.loaded/e.total*100;I(e=>e.map(e=>e.id===r?{...e,progress:t}:e))},i.onerror=()=>{I(e=>e.map(e=>e.id===r?{...e,error:`Network error`}:e)),window.setTimeout(()=>{I(e=>e.filter(e=>e.id!==r))},1200),n(Error(`Upload failed: ${e.name}`))},i.onload=()=>{let e=i.response||{};if(i.status<200||i.status>=300||e?.ok===!1){let t=String(e?.error||`Upload failed (${i.status})`);I(e=>e.map(e=>e.id===r?{...e,error:t}:e)),window.setTimeout(()=>{I(e=>e.filter(e=>e.id!==r))},1600),n(Error(t));return}I(e=>e.filter(e=>e.id!==r)),t(e)},i.send(e)}),[]),kt=i(async e=>{let t=[...e||[]];if(!t.length)return;let n=0;for(let e of t)try{let t=await Ot(e);We(n=>[{name:String(t?.name||e.name),path:String(t?.path||e.name),size:Number(t?.size||e.size||0),mime:e.type||_e(String(t?.name||e.name)),url:String(t?.absPath||m(t?.root,t?.path)||t?.path||e.name)},...n]),n+=1}catch(e){y(`err`,g(e))}n>0&&y(`ok`,`Uploaded ${n} file${n===1?``:`s`}.`)},[y,Ot]),At=i(async e=>{await _.sessions.delete(e),Be(t=>t.filter(t=>t.id!==e)),pt(null),y(`ok`,`Session deleted.`),A===e&&j(D.find(t=>t.id!==e)?.id||await G())},[_.sessions,G,A,D,y]),jt=i((e,t)=>{let n=String(e||``).trim();if(!n)return;let r=t>0?`\n\n${t} attachment${t===1?``:`s`}`:``;N(e=>[...e,{id:`local-user-${Date.now()}-${Math.random().toString(16).slice(2)}`,role:`user`,displayRole:`User`,text:`${n}${r}`,markdown:!1}])},[]),Mt=i(async()=>{if(L)return;let e=P.trim(),t=[...F],n=e||(t.length?`Please analyze the attached file(s).`:``);if(!n)return;try{let e=await v(`/api/engine/setup/understand`,{method:`POST`,body:JSON.stringify({surface:`control_panel_chat`,session_id:A||void 0,text:n,channel:null,trigger:{source:`direct_message`,is_direct_message:!0,was_explicitly_mentioned:!1,is_reply_to_bot:!1},scope:{kind:`direct`,id:A||`control-panel-chat`}})});if(e.intent_kind!==`workflow_planner_create`&&pe(n,e)){let t=ge(e);if(t){mt(t),Ue(``);return}}}catch{}Ue(``),Ke(!0);let r=Ne(M);jt(n,t.length);try{let e=A;if(e||=await G(),!e)throw Error(`No active session.`);let i=await yt();if(!i)throw Error(`No default provider/model configured. Set it in Settings before sending chat.`);let a=t.map(e=>({type:`file`,mime:e.mime||_e(e.name||e.path),filename:e.name||e.path||`attachment`,url:e.url||e.path}));a.push({type:`text`,text:n});let o=async()=>{let t=await fetch(`/api/engine/session/${encodeURIComponent(e)}/run`,{method:`GET`,credentials:`include`});if(!t.ok)return``;let n=await t.json().catch(()=>({}));return n?.active?.runID||n?.active?.runId||n?.active?.run_id||``},s=e=>String(e?.activeRun?.runID||e?.activeRun?.runId||e?.activeRun?.run_id||e?.active?.runID||e?.active?.runId||e?.active?.run_id||``).trim(),c=async(t=``)=>{let n=String(t||``).trim()||await o().catch(()=>``);if(!n)return!0;n&&await fetch(`/api/engine/session/${encodeURIComponent(e)}/run/${encodeURIComponent(n)}/cancel`,{method:`POST`,credentials:`include`,headers:{"content-type":`application/json`},body:JSON.stringify({})}).catch(()=>{}),await fetch(`/api/engine/session/${encodeURIComponent(e)}/cancel`,{method:`POST`,credentials:`include`,headers:{"content-type":`application/json`},body:JSON.stringify({})}).catch(()=>{});for(let e=0;e<50;e+=1){if(!await o().catch(()=>``))return!0;await new Promise(e=>window.setTimeout(e,200))}return!1},ee=async()=>fetch(`/api/engine/session/${encodeURIComponent(e)}/prompt_async?return=run`,{method:`POST`,credentials:`include`,headers:{"content-type":`application/json`},body:JSON.stringify({parts:a,model:{providerID:i.providerID,modelID:i.modelID},...H.length?{toolMode:`auto`,toolAllowlist:H}:{}})});if(!await c())throw Error(`Session has a stuck active run. Cancel it and retry.`);let l=await ee(),d=``;if(l.status===409){if(!await c(s(await l.json().catch(()=>({})))))throw Error(`Session has a stuck active run. Cancel it and retry.`);if(l=await ee(),l.ok){let e=await l.json().catch(()=>({}));d=e?.runID||e?.runId||e?.run_id||``}else if(l.status===409)throw Error(`Session is still busy with another run. Retry in a moment.`);else{let e=await l.text().catch(()=>``);throw Error(`prompt_async retry failed (${l.status}): ${e}`)}}else if(l.ok){let e=await l.json().catch(()=>({}));d=e?.runID||e?.runId||e?.run_id||``}else{let e=await l.text().catch(()=>``);throw Error(`prompt_async failed (${l.status}): ${e}`)}if(!d)throw Error(`No run ID returned from engine.`);t.length&&We([]),J(`session.run.started`,{runID:d,sessionID:e,status:`started`,message:`Prompt accepted`,startedAtMs:Date.now()},d),Je(``),R(!0);let p=new AbortController;ze.current?.abort(),ze.current=p;let m=!1,se=!1,h=``,ce=``,le=async(t,n)=>{let r=Date.now();for(;Date.now()-r<n;){let n=await o().catch(()=>t);if(await K(e),!n||n!==t)return!0;await new Promise(e=>window.setTimeout(e,350))}return!1},fe=async t=>{let n=Date.now(),i=[];for(;Date.now()-n<t;){if(i=await K(e),Ne(i)>r)return!0;await new Promise(e=>window.setTimeout(e,300))}return Ne(i)>r},pe=()=>{T.current&&window.clearTimeout(T.current),T.current=window.setTimeout(()=>{se=!0,h=`no-events-timeout`,p.abort(`no-events-timeout`)},3e4)};pe(),E.current&&window.clearTimeout(E.current),E.current=window.setTimeout(()=>{se=!0,h=`max-stream-window`,p.abort(`max-stream-window`)},18e4);try{for await(let t of _.stream(e,d,{signal:p.signal})){let n=t;if(ue(n.type)&&pe(),J(n.type,n.properties||{},d),n.type===`approval.requested`||n.type===`permission.request`||n.type===`permission.asked`){let t=de(n.properties||{});t&&oe(t.sessionId,e)?(wt(t),Tt()):Z()}if(n.type===`approval.resolved`||n.type===`permission.resolved`||n.type===`permission.replied`){let e=de(n.properties||{});e?.id&&X(e.id),Z()}let r=f(n);if(r&&r!==d)continue;let i=String(n.type||``).toLowerCase();if(!(xe.has(n.type)||te.has(n.type)||ie.has(n.type))&&i.includes(`tool`)&&Y(n.type,n.properties||{},r||d),n.type===`session.response`){let e=String(n.properties?.delta||``);if(!e)continue;m=!0,ce+=e,R(!1),Je(t=>`${t}${e}`)}if(xe.has(n.type)&&Y(n.type,n.properties||{},r||d),te.has(n.type)&&Y(n.type,n.properties||{},r||d),ie.has(n.type)&&Y(n.type,n.properties||{},r||d),n.type===`message.part.updated`){let e=n.properties?.part||{},t=String(e.type||``).trim().toLowerCase().replace(/_/g,`-`),i=ne(e)||ne(n.properties),a=re(e),o=e?.state,s=String((o&&typeof o==`object`?o.status:o)||e.status||``).trim().toLowerCase(),c=!!e.error||!!(o&&typeof o==`object`&&o.error)||s.includes(`fail`)||s.includes(`error`)||s.includes(`deny`)||s.includes(`reject`)||s.includes(`cancel`),ee=!!e.result||!!e.output||!!(o&&typeof o==`object`&&(o.output||o.result))||s.includes(`done`)||s.includes(`complete`)||s.includes(`success`);if(i&&(t===`tool`||t===`tool-invocation`)){let t=c?`failed`:ee?`completed`:`started`;q(i,t,`${a||r||d}:${i}:${t}`,{callId:a,runId:r||d,source:`message.part.updated`,summary:u(e),detail:u(e)})}i&&t===`tool-result`&&q(i,c?`failed`:`completed`,`${a||r||d}:${i}:${c?`failed`:`completed`}`,{callId:a,runId:r||d,source:`message.part.updated`,summary:u(e),detail:u(e)})}if(ae.has(n.type))throw Error(String(n.properties?.error||`Run failed.`));if((n.type===`session.updated`||n.type===`session.status`)&&String(n.properties?.status||``).toLowerCase()===`idle`||Se.has(n.type))break}}catch(e){let t=String(e?.message||e||``).toLowerCase();if(!(se||t.includes(`abort`)||t.includes(`terminated`)||t.includes(`networkerror`)))throw e}finally{T.current&&window.clearTimeout(T.current),E.current&&window.clearTimeout(E.current)}if(se){let t=await le(d,45e3);if(await K(e),!t)throw Error(`Run stream timed out and the run is still active. Check logs and retry.`)}m||R(!0);let me=await fe(m?3500:9e3);if(!m&&await o().catch(()=>``)===d)if(await le(d,3e4))me=await fe(5e3);else throw Error(`Run ${d} is still active without a final response (${h||`stream-ended`}).`);!me&&ce.trim()&&N(e=>Pe(e,d,x.botName||`Assistant`,ce)),Je(``),R(!1),await W(),await Oe.invalidateQueries({queryKey:[`chat`]}).catch(()=>{})}catch(e){let t=g(e);y(`err`,t.includes(`no-events-timeout`)||t.includes(`max-stream-window`)||t.includes(`AbortError`)||t.toLowerCase().includes(`terminated`)?`Run stream timed out before events were received. Check engine/provider logs and retry.`:t),await xt()}finally{w.current&&(Ke(!1),R(!1))}},[v,jt,Tt,_,G,x.botName,K,M,P,Oe,J,q,Y,xt,Z,W,X,yt,A,H,L,y,F,wt]);e(()=>{W(),Dt();let e=async()=>{let e=await G().catch(()=>``);e&&j(e),k(!1)};window.addEventListener(`tcp:new-chat`,e);let t=window.setInterval(()=>{W()},8e3);return()=>{window.removeEventListener(`tcp:new-chat`,e),window.clearInterval(t)}},[G,Dt,W]),e(()=>{A&&(ze.current?.abort(),k(!1),St(),Ct(),Z(),xt())},[xt,Z,Ct,St,A]),e(()=>{A||N([])},[A]),e(()=>{!A&&D.length===0&&G().catch(()=>{})},[G,A,D.length]),e(()=>{fe(B),B&&Tt()},[B,Tt]),e(()=>{be(H)},[H]),e(()=>{let e=window.setInterval(()=>{A&&Z()},2500);return()=>window.clearInterval(e)},[Z,A]),e(()=>{let e=Te(`/api/global/event`,e=>{let t=null;try{t=JSON.parse(String(e.data||`{}`))}catch{return}let n=String(t?.type||``).trim();if(!n)return;let r=t?.properties||{},i=de(r);i&&oe(i.sessionId,A)&&((n===`approval.requested`||n===`permission.request`||n===`permission.asked`)&&wt(i),(n===`approval.resolved`||n===`permission.resolved`||n===`permission.replied`)&&X(i.id)),J(n,r,f(t,`global`)),!(xe.has(n)||te.has(n)||ie.has(n))&&n.toLowerCase().includes(`tool`)&&Y(n,r,f(t,`global`)),xe.has(n)&&Y(n,r,f(t,`global`)),te.has(n)&&Y(n,r,f(t,`global`)),ie.has(n)&&Y(n,r,f(t,`global`))},{withCredentials:!0});return()=>e()},[J,Y,X,A,wt]),F.length,!Ve&&M.length;let $=P.trim(),Nt=!L&&$.length>0&&$!==ht&&/\b(workflow|workflows)\b/i.test($);return o(`div`,{ref:Fe,className:`chat-layout chat-layout-fill min-w-0 min-h-0 h-full w-full flex-1`,children:[o(s.aside,{className:`chat-sessions-panel ${O?`open`:``}`,initial:!1,animate:C?{x:O?0:`-104%`}:{x:O?0:`-104%`,transition:{duration:.18,ease:`easeOut`}},children:[o(`div`,{className:`chat-sessions-header`,children:[o(`h3`,{className:`chat-sessions-title`,children:[o(`i`,{"data-lucide":`history`}),`Sessions`]}),o(`div`,{className:`flex items-center gap-1`,children:[o(`button`,{type:`button`,className:`tcp-btn h-8 px-2.5 text-xs`,onClick:()=>{G().catch(e=>y(`err`,g(e))),k(!1)},children:[o(`i`,{"data-lucide":`plus`}),`New`]}),o(`button`,{type:`button`,className:`tcp-btn h-8 px-2.5 text-xs`,onClick:()=>void W(),children:o(`i`,{"data-lucide":`refresh-cw`})})]})]}),o(`div`,{className:`chat-session-list`,children:[o(c,{children:D.map(e=>o(s.div,{className:`chat-session-row`,initial:C?!1:{opacity:0,y:6},animate:C?void 0:{opacity:1,y:0},exit:C?void 0:{opacity:0,y:-6},children:[o(`button`,{type:`button`,className:`chat-session-btn ${e.id===A?`active`:``}`,title:e.id,onClick:()=>{j(e.id),k(!1)},children:o(`span`,{className:`block truncate`,children:e.title})}),o(`button`,{type:`button`,className:`chat-session-del`,title:`Delete session`,onClick:()=>pt({id:e.id,title:e.title}),children:o(`i`,{"data-lucide":`trash-2`})})]},e.id))}),D.length?null:o(`p`,{className:`chat-rail-empty px-1 py-2`,children:`No sessions yet.`})]})]}),o(c,{children:O?o(s.button,{type:`button`,className:`chat-scrim open`,"aria-label":`Close sessions`,initial:C?!1:{opacity:0},animate:C?void 0:{opacity:1},exit:C?void 0:{opacity:0},onClick:()=>k(!1)}):null}),o(`div`,{className:`chat-workspace min-h-0 min-w-0`,children:[o(`section`,{className:`chat-main-shell flex min-h-0 min-w-0 flex-col overflow-hidden`,children:[o(`header`,{className:`chat-main-header shrink-0`,children:[o(`button`,{type:`button`,className:`chat-icon-btn h-8 w-8`,title:`Sessions`,onClick:()=>k(e=>!e),children:o(`i`,{"data-lucide":`history`})}),o(`div`,{className:`chat-main-dot`}),o(`h3`,{className:`tcp-title chat-main-title`,children:_t}),V.length?o(`span`,{className:`chat-main-tools`,children:H.length?`${H.length} enabled`:`${V.length} tools`}):null]}),U?o(`div`,{className:`mx-3 mb-2 rounded-xl border border-amber-500/30 bg-amber-500/8 p-3`,children:[o(`div`,{className:`mb-2 flex items-start justify-between gap-3`,children:[o(`div`,{children:[o(`div`,{className:`tcp-title text-sm`,children:U.title}),o(`div`,{className:`tcp-subtle text-sm`,children:U.body})]}),o(`button`,{type:`button`,className:`tcp-btn tcp-btn-ghost`,onClick:()=>mt(null),children:`Dismiss`})]}),U.clarifier?o(`div`,{className:`mb-2 flex flex-wrap gap-2`,children:U.clarifier.options.map(e=>o(`button`,{type:`button`,className:`tcp-btn tcp-btn-ghost`,onClick:()=>{let t=e.id.startsWith(`workflow_planner_`);mt({title:e.id===`provider_setup`?`Provider setup`:e.id===`integration_setup`?`Tool connection`:t?`Workflow planning`:`Automation setup`,body:e.id===`provider_setup`?`Open Providers to configure a provider.`:e.id===`integration_setup`?`Open MCP to connect the tool you need.`:t?`Open the planner to answer the missing workflow details.`:`Open Automations to build the workflow.`,cta:e.id===`provider_setup`?`Open Providers`:e.id===`integration_setup`?`Open MCP`:t?`Open Planner`:`Open Automations`,actionType:e.id===`provider_setup`?`open_provider_setup`:e.id===`integration_setup`?`open_mcp_setup`:t?`open_planner`:`open_automations`,payload:U.payload})},children:e.label},e.id))}):null,o(`button`,{type:`button`,className:`tcp-btn`,onClick:()=>{U.actionType===`open_provider_setup`?S(`settings`):U.actionType===`open_mcp_setup`?S(`mcp`):U.actionType===`open_planner`?(h(U.payload),S(`planner`)):U.actionType===`open_automations`&&(se(U.payload),S(`automations`))},children:U.cta})]}):null,o(Ee,{messages:M.map(e=>({id:e.id,role:e.role,displayRole:e.displayRole,text:e.text,markdown:e.markdown})),emptyText:`No messages yet. Send a prompt to start.`,inputValue:P,inputPlaceholder:`Ask anything... (Enter to send, Shift+Enter newline)`,sendLabel:`Send`,onInputChange:Ue,onSend:()=>void Mt(),sendDisabled:L,inputDisabled:L,botIdentity:{botName:x.botName,botAvatarUrl:x.botAvatarUrl},streamingText:qe,showThinking:Ye,thinkingText:`Thinking`,attachments:F.map(e=>({path:e.path,name:e.path,size:e.size})),onOpenAttachment:e=>{let t=F[e];t?.path&&we(S,{path:t.path})},onRemoveAttachment:e=>We(t=>t.filter((t,n)=>n!==e)),onAttach:()=>Le.current?.click(),attachDisabled:L,statusTitle:L&&!Ye&&!qe?`Sending…`:``,composerAccessory:Nt?o(`div`,{className:`chat-planner-nudge`,role:`status`,children:[o(`button`,{type:`button`,className:`chat-planner-nudge-action`,onClick:()=>{h({prompt:$,plan_source:`control_panel_chat`,session_id:A||``}),gt($),S(`planner`)},children:[o(`i`,{"data-lucide":`workflow`}),`Open workflow planner`]}),o(`span`,{className:`chat-planner-nudge-hint`,children:`for this message`}),o(`button`,{type:`button`,className:`chat-planner-nudge-dismiss`,title:`Dismiss`,onClick:()=>gt($),children:o(`i`,{"data-lucide":`x`})})]}):null}),o(`input`,{ref:Le,type:`file`,className:`hidden`,multiple:!0,onChange:e=>{kt(e.target.files),e.target.value=``}})]}),o(`aside`,{className:`chat-right-rail hidden min-h-0 flex-col overflow-hidden xl:flex`,children:[o(`section`,{className:`chat-rail-section chat-rail-tools-section`,children:[o(`div`,{className:`mb-2 flex items-center justify-between`,children:[o(`p`,{className:`chat-rail-label`,children:`Tools`}),o(`div`,{className:`flex items-center gap-2`,children:[o(`span`,{className:`chat-rail-count`,children:H.length?`${H.length}/${V.length}`:`all`}),H.length?o(`button`,{type:`button`,className:`tcp-btn h-7 px-2 text-[11px]`,onClick:()=>dt([]),children:`All`}):null]})]}),o(`div`,{className:`chat-tools-list`,children:V.length?V.slice(0,48).map(e=>{let t=vt.has(e);return o(`button`,{type:`button`,className:`chat-tool-pill ${t?`selected`:``}`,title:t?`Remove ${e} from the next-run allowlist`:`Allow only selected tools; add ${e}`,"aria-pressed":t,onClick:()=>{dt(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),[...n].sort((e,t)=>e.localeCompare(t))})},children:[t?o(`i`,{"data-lucide":`check`}):null,e]},e)}):o(`p`,{className:`chat-rail-empty`,children:`No tools loaded.`})}),o(`p`,{className:`chat-rail-empty mt-2`,children:H.length?`Selected tools are sent as the next run's allowlist.`:`No allowlist selected; the run can use the default tool set.`})]}),o(`section`,{className:`chat-rail-section chat-rail-approvals-section`,children:[o(`div`,{className:`mb-2 flex items-center justify-between`,children:[o(`p`,{className:`chat-rail-label`,children:`Approvals`}),o(`span`,{className:`chat-rail-count`,children:z.length})]}),o(`div`,{className:`mb-2 flex items-center gap-2`,children:[o(`button`,{type:`button`,className:`tcp-btn h-7 px-2 text-[11px]`,disabled:!z.length||ct,onClick:async()=>{let e=z.map(e=>e.id).filter(Boolean);if(!e.length)return;for(let t of e)await Q(t,`once`,!0);await Z();let t=e.filter(e=>z.some(t=>String(t.id||``).trim()===e)).length;t>0?y(`warn`,`${t} request${t===1?``:`s`} still pending (likely stale/expired).`):y(`ok`,`Approved ${e.length} pending request${e.length===1?``:`s`}.`)},children:`Approve all`}),o(`label`,{className:`chat-auto-approve-label`,children:[o(`input`,{type:`checkbox`,className:`chat-auto-approve-checkbox`,checked:B,onChange:e=>st(e.target.checked)}),`Auto`]})]}),o(`div`,{className:`chat-tools-activity`,children:z.length?z.slice(0,20).map(e=>{let t=at.has(e.id),n=[e.permission,e.pattern].filter(Boolean).join(` `);return o(`article`,{className:`chat-pack-event-card`,children:[o(`div`,{className:`chat-pack-event-title truncate`,title:e.id,children:e.tool}),o(`div`,{className:`chat-pack-event-summary mt-0.5`,children:n||e.id}),o(`div`,{className:`mt-1 flex gap-1`,children:[o(`button`,{className:`tcp-btn h-6 px-1.5 text-[10px]`,disabled:t,onClick:()=>void Q(e.id,`once`),children:`Allow`}),o(`button`,{className:`tcp-btn h-6 px-1.5 text-[10px]`,disabled:t,onClick:()=>void Q(e.id,`always`),children:`Always`}),o(`button`,{className:`tcp-btn-danger h-6 px-1.5 text-[10px]`,disabled:t,onClick:()=>void Q(e.id,`deny`),children:`Deny`})]})]},e.id)}):o(`p`,{className:`chat-rail-empty`,children:`No pending approvals.`})})]}),o(`section`,{className:`chat-rail-section chat-rail-scroll-section`,children:[o(`div`,{className:`mb-2 flex items-center justify-between`,children:[o(`p`,{className:`chat-rail-label`,children:`Run Timeline`}),o(`div`,{className:`flex items-center gap-2`,children:[o(`span`,{className:`chat-rail-count`,children:et.length}),o(`button`,{type:`button`,className:`tcp-btn h-7 px-2 text-[11px]`,onClick:Ct,children:[o(`i`,{"data-lucide":`trash-2`}),`Clear`]})]})]}),o(`div`,{className:`chat-tools-activity`,children:et.length?et.slice(0,24).map(e=>o(s.article,{className:`chat-timeline-card chat-timeline-${e.tone}`,initial:C?!1:{opacity:0,y:6},animate:C?void 0:{opacity:1,y:0},children:[o(`div`,{className:`flex items-center justify-between gap-2`,children:[o(`div`,{className:`chat-pack-event-title truncate`,title:e.type,children:e.title}),o(`span`,{className:`chat-pack-event-time`,children:new Date(e.at).toLocaleTimeString()})]}),o(`div`,{className:`chat-pack-event-summary mt-0.5`,children:e.summary}),e.runId?o(`div`,{className:`chat-pack-event-summary mt-1 truncate`,title:e.runId,children:[`run: `,e.runId]}):null]},`${e.id}-${e.at}`)):o(`p`,{className:`chat-rail-empty`,children:`No run events yet.`})})]}),o(`section`,{className:`chat-rail-section chat-rail-scroll-section`,children:[o(`div`,{className:`mb-2 flex items-center justify-between`,children:[o(`p`,{className:`chat-rail-label`,children:`Tool Activity`}),o(`button`,{type:`button`,className:`tcp-btn h-7 px-2 text-[11px]`,onClick:St,children:[o(`i`,{"data-lucide":`trash-2`}),`Clear`]})]}),o(`div`,{className:`chat-tools-activity`,children:Xe.length?Xe.slice(0,24).map(e=>o(`details`,{className:`chat-tool-event ${Ce(e.status)}`,children:[o(`summary`,{children:[o(`span`,{className:`truncate`,children:e.tool}),o(`span`,{children:e.status})]}),o(`div`,{className:`chat-tool-event-body`,children:[o(`div`,{children:new Date(e.at).toLocaleTimeString()}),e.source?o(`div`,{children:[`source: `,e.source]}):null,e.callId?o(`div`,{children:[`call: `,e.callId]}):null,e.runId?o(`div`,{children:[`run: `,e.runId]}):null,e.summary?o(`pre`,{children:e.summary}):null]})]},e.id)):o(`p`,{className:`chat-rail-empty`,children:`No tool events yet.`})})]})]})]}),o(c,{children:ft?o(s.div,{className:`tcp-confirm-overlay`,initial:C?!1:{opacity:0},animate:C?void 0:{opacity:1},exit:C?void 0:{opacity:0},onClick:()=>pt(null),children:o(s.div,{className:`tcp-confirm-dialog`,initial:C?!1:{opacity:0,y:8,scale:.98},animate:C?void 0:{opacity:1,y:0,scale:1},exit:C?void 0:{opacity:0,y:6,scale:.98},onClick:e=>e.stopPropagation(),children:[o(`h3`,{className:`tcp-confirm-title`,children:`Delete session`}),o(`p`,{className:`tcp-confirm-message`,children:[`This will permanently remove `,o(`strong`,{children:ft.title}),` and all its messages.`]}),o(`div`,{className:`tcp-confirm-actions`,children:[o(`button`,{type:`button`,className:`tcp-btn`,onClick:()=>pt(null),children:[o(`i`,{"data-lucide":`x`}),`Cancel`]}),o(`button`,{type:`button`,className:`tcp-btn-danger`,onClick:()=>void At(ft.id).catch(e=>y(`err`,g(e))),children:[o(`i`,{"data-lucide":`trash-2`}),`Delete session`]})]})]})}):null})]})}export{C as ChatPage};
@@ -0,0 +1,8 @@
1
+ import{C as e,E as t,g as n,h as r,v as i,x as a}from"./fullcalendar-Bn75j0xM.js";import{a as o,n as s}from"./react-query-BIbNygEJ.js";import{i as c}from"./motion-B3ZE8SGR.js";import{a as l,g as u,h as d,m as f,s as p,t as ee,u as m,w as h,x as g}from"./index-TvymvGva.js";import{t as te}from"./ProviderModelSelector-BdtOpkJR.js";import{n as _}from"./LazyJson-vfWw7G9F.js";import{t as ne}from"./sse-B4A2m-Nk.js";import{a as v,i as re,n as y,o as b,r as ie,s as x,t as S}from"./plannerShared-Dx7-Sxpc.js";import{t as C}from"./ChatInterfacePanel-BrMo4cXg.js";import{n as w,t as ae}from"./ControlPanelDialogs-yFfCht3Y.js";import{t as oe}from"./PlannerDiagnosticsPanel-C1uIuRIx.js";function T({label:e,value:t,helper:n,tone:r=`info`}){return c(`div`,{className:`rounded-2xl border border-white/10 bg-black/20 p-4 shadow-[0_12px_36px_rgba(0,0,0,0.12)]`,children:[c(`div`,{className:`flex items-start justify-between gap-3`,children:[c(`div`,{className:`tcp-kpi-label text-sm`,children:e}),c(d,{tone:r,children:n})]}),c(`div`,{className:`mt-3 text-2xl font-semibold tracking-tight`,children:t})]})}function E(e){return String(e||`unknown`).replace(/_/g,` `).replace(/\b\w/g,e=>e.toUpperCase())}function D(e,t=`unknown`){return String(e??``).trim()||t}function O(e){return Array.isArray(e)?e.map(e=>String(e||``).trim()).filter(Boolean):[]}function k(e){let t=Number(e||0);return t?new Date(t).toLocaleString():`not refreshed yet`}function se(e){return String(e?.run_id||e?.aca_run_id||e?.id||``).trim()}function A(e){return String(e?.coder_run_id||e?.tandem_run_id||e?.coder_supervision?.coder_run_id||``).trim()}function j(e){return String(e?.coder_supervision?.tandem_status||e?.status||`unknown`).trim()}function M(e){return String(e?.coder_supervision?.tandem_phase||e?.phase||``).trim()}function ce(e){return Number(e?.coder_supervision?.last_checked_at_ms||e?.updated_at_ms||e?.started_at_ms||0)}function N(e){let t=j(e).toLowerCase();return![`completed`,`failed`,`cancelled`,`canceled`,`terminal`].includes(t)}function le({projects:e,selectedProjectSlug:n,setSelectedProjectSlug:r,selectedProject:i,acaOverview:a,projectTasksQuery:o,refreshTaskPreview:s,taskPreviewRefreshAt:l,coderRuns:u,coderRunsQuery:f,reconcileCoderRun:ee,cancelCoderRun:m,visibleRunsCount:h,activeRunsCount:te,connectedMcpServersCount:_,registeredToolsCount:ne}){let v=u.filter(N);return c(t,{children:c(`div`,{className:`grid gap-4`,children:[c(g,{title:`Project selector`,subtitle:`Choose the repository context before intake`,children:e.length?c(`div`,{className:`grid gap-3`,children:[c(`select`,{className:`tcp-input`,value:n,onChange:e=>r(e.target.value),children:[e.length?null:c(`option`,{value:``,children:`No ACA projects found`}),e.map(e=>c(`option`,{value:e.slug,children:e.slug},e.slug))]}),c(`div`,{className:`rounded-2xl border border-white/10 bg-black/20 p-4`,children:[c(`div`,{className:`text-sm font-semibold`,children:i?.slug||`No project selected`}),c(`div`,{className:`tcp-subtle mt-1 text-xs`,children:i?.repoUrl||`No repo URL stored`}),c(`div`,{className:`tcp-subtle mt-2 text-xs`,children:[`Task source: `,String(i?.taskSource?.type||`unknown`)]})]})]}):c(p,{text:`Register an ACA project to start using Coder.`})}),c(`div`,{className:`grid gap-4 md:grid-cols-2 xl:grid-cols-4`,children:[c(T,{label:`Registered projects`,value:e.length,helper:n?`Focused on ${n}`:`No project selected`,tone:e.length?`ok`:`warn`}),c(T,{label:`Coder runs`,value:u.length||h,helper:v.length||te?`${v.length||te} active`:`Idle`,tone:v.length||te?`warn`:`ok`}),c(T,{label:`Connected MCP servers`,value:_,helper:_?`GitHub available`:`MCP pending`,tone:_?`ok`:`warn`}),c(T,{label:`Registered tools`,value:ne,helper:`Engine tool surface`,tone:ne?`info`:`ghost`})]}),c(`div`,{className:`grid gap-4`,children:[c(g,{title:`Coder runs`,subtitle:`Long-running repository work supervised by ACA`,actions:c(d,{tone:v.length?`warn`:`ok`,children:v.length?`${v.length} active`:`Idle`}),children:f.isLoading?c(`div`,{className:`tcp-subtle text-sm`,children:`Loading coder runs...`}):f.isError?c(`div`,{className:`rounded-2xl border border-red-500/20 bg-red-500/10 p-4 text-sm text-red-200`,children:f.error instanceof Error?f.error.message:`Could not load coder runs.`}):u.length?c(`div`,{className:`grid gap-3`,children:u.map((e,t)=>{let r=se(e)||`coder-run-${t}`,i=A(e),a=M(e),o=String(e?.coder_supervision?.last_error||e?.error||``).trim();return c(`div`,{className:`rounded-2xl border border-white/10 bg-black/20 p-4`,children:[c(`div`,{className:`flex flex-wrap items-start justify-between gap-3`,children:[c(`div`,{className:`min-w-0`,children:[c(`div`,{className:`break-words text-sm font-semibold`,children:D(e?.task_title||e?.title,r)}),c(`div`,{className:`tcp-subtle mt-1 break-words text-xs leading-5`,children:[`ACA run `,r,i?` · Coder ${i}`:``]}),c(`div`,{className:`tcp-subtle mt-1 break-words text-xs leading-5`,children:[D(e?.repo_slug||e?.project_slug||n,`No project`),e?.repo_path?` · ${D(e.repo_path)}`:``]})]}),c(`div`,{className:`flex flex-wrap gap-2`,children:[c(d,{tone:N(e)?`info`:`ok`,children:E(j(e))}),a?c(d,{tone:`ghost`,children:E(a)}):null]})]}),c(`div`,{className:`mt-3 flex flex-wrap items-center justify-between gap-3`,children:[c(`div`,{className:`tcp-subtle text-xs`,children:[`Last checked `,k(ce(e))]}),c(`div`,{className:`flex flex-wrap gap-2`,children:[c(`button`,{type:`button`,className:`tcp-btn h-8 px-3 text-xs`,onClick:()=>ee(r),children:`Reconcile`}),c(`button`,{type:`button`,className:`tcp-btn h-8 px-3 text-xs`,onClick:()=>m(r),disabled:!N(e),children:`Cancel`})]})]}),o?c(`div`,{className:`mt-3 rounded-2xl border border-amber-500/20 bg-amber-500/10 p-3 text-xs leading-5 text-amber-100`,children:o}):null]},r)})}):c(p,{text:`No active coder runs. New repository work will appear here while it is supervised.`})}),c(g,{title:`Coder runtime snapshot`,subtitle:`Read-only ACA runtime view the agent can use before intake`,actions:c(d,{tone:a.data?`ok`:`warn`,children:a.data?`Live`:`Loading`}),children:a.isLoading?c(`div`,{className:`tcp-subtle text-sm`,children:`Loading ACA snapshot...`}):a.isError?c(`div`,{className:`rounded-2xl border border-red-500/20 bg-red-500/10 p-4 text-sm text-red-200`,children:a.error instanceof Error?a.error.message:`Could not load ACA snapshot.`}):a.data?.overview?c(`div`,{className:`grid gap-3`,children:[c(`div`,{className:`flex flex-wrap gap-2`,children:[c(d,{tone:a.data.overview.auth?.required?`ok`:`warn`,children:D(a.data.overview.auth?.mode,`bearer_api_key`)}),c(d,{tone:a.data.overview.validation?.ok?`ok`:`warn`,children:a.data.overview.validation?.ok?`Config valid`:`Needs attention`}),c(d,{tone:a.data.overview.engine?.healthy?`ok`:`warn`,children:a.data.overview.engine?.healthy?`Engine healthy`:`Engine issue`}),c(d,{tone:a.data.overview.github_mcp?.connected?`ok`:`warn`,children:a.data.overview.github_mcp?.connected?`GitHub MCP connected`:`GitHub MCP pending`})]}),c(`div`,{className:`grid gap-3 md:grid-cols-2`,children:[c(`div`,{className:`rounded-2xl border border-white/10 bg-black/20 p-4`,children:[c(`div`,{className:`text-xs uppercase tracking-[0.2em] text-slate-400`,children:`Task source`}),c(`div`,{className:`mt-1 text-sm font-semibold`,children:D(a.data.overview.task_source?.type,`unset`)}),c(`div`,{className:`tcp-subtle mt-1 text-xs`,children:a.data.overview.task_source?.owner?`${D(a.data.overview.task_source.owner)} / ${D(a.data.overview.task_source.repo)}`:D(a.data.overview.task_source?.source_name,`No source details`)}),c(`div`,{className:`tcp-subtle mt-1 text-xs`,children:[`Project `,D(a.data.overview.task_source?.project,`n/a`),a.data.overview.task_source?.item?` · Item ${D(a.data.overview.task_source.item)}`:``]})]}),c(`div`,{className:`rounded-2xl border border-white/10 bg-black/20 p-4`,children:[c(`div`,{className:`text-xs uppercase tracking-[0.2em] text-slate-400`,children:`Repository`}),c(`div`,{className:`mt-1 text-sm font-semibold`,children:D(a.data.overview.repository?.slug||a.data.overview.repository?.path,`Unbound`)}),c(`div`,{className:`tcp-subtle mt-1 text-xs`,children:a.data.overview.repository?.path?`Path ${D(a.data.overview.repository.path)}`:`Repository path unavailable`}),c(`div`,{className:`tcp-subtle mt-1 text-xs`,children:[`Branch`,` `,D(a.data.overview.repository?.default_branch,`main`),a.data.overview.repository?.remote_name?` · Remote ${D(a.data.overview.repository.remote_name,`origin`)}`:``]})]}),c(`div`,{className:`rounded-2xl border border-white/10 bg-black/20 p-4`,children:[c(`div`,{className:`text-xs uppercase tracking-[0.2em] text-slate-400`,children:`Engine and GitHub`}),c(`div`,{className:`mt-1 text-sm font-semibold`,children:[D(a.data.overview.engine?.status,`unknown`),` engine`]}),c(`div`,{className:`tcp-subtle mt-1 text-xs`,children:a.data.overview.engine?.base_url?`Engine ${D(a.data.overview.engine.base_url)}`:`Engine URL unavailable`}),c(`div`,{className:`tcp-subtle mt-1 text-xs`,children:[`GitHub MCP `,D(a.data.overview.github_mcp?.scope,`unset`),a.data.overview.github_mcp?.remote_sync?` · Sync ${D(a.data.overview.github_mcp.remote_sync)}`:``]})]}),c(`div`,{className:`rounded-2xl border border-white/10 bg-black/20 p-4`,children:[c(`div`,{className:`text-xs uppercase tracking-[0.2em] text-slate-400`,children:`Latest run`}),c(`div`,{className:`mt-1 text-sm font-semibold`,children:D(a.data.overview.latest_run?.run_id,`No run yet`)}),c(`div`,{className:`tcp-subtle mt-1 text-xs`,children:a.data.overview.latest_run?.status?`Status ${D(a.data.overview.latest_run.status)}`:`No run status`}),c(`div`,{className:`tcp-subtle mt-1 text-xs`,children:a.data.overview.latest_run?.phase?`Phase ${D(a.data.overview.latest_run.phase)}`:`No phase recorded`})]})]}),c(`div`,{className:`rounded-2xl border border-white/10 bg-black/20 p-4`,children:[c(`div`,{className:`flex flex-wrap items-center justify-between gap-3`,children:[c(`div`,{children:[c(`div`,{className:`text-sm font-semibold`,children:`Allowed next actions`}),c(`div`,{className:`tcp-subtle mt-1 text-xs`,children:`The agent should choose from these safe follow-ups.`})]}),c(d,{tone:`ghost`,children:[`Refreshed `,k(a.dataUpdatedAt)]})]}),c(`div`,{className:`mt-3 flex flex-wrap gap-2`,children:O(a.data.overview.allowed_next_actions).length?O(a.data.overview.allowed_next_actions).map(e=>c(d,{tone:`info`,children:E(e)},e)):c(`span`,{className:`tcp-subtle text-xs`,children:`No suggested actions.`})})]}),c(`details`,{className:`rounded-2xl border border-white/10 bg-black/20 p-4`,children:[c(`summary`,{className:`cursor-pointer text-sm font-semibold`,children:`Raw snapshot`}),c(`pre`,{className:`mt-3 max-h-64 overflow-auto whitespace-pre-wrap text-xs leading-6 text-slate-200`,children:JSON.stringify(a.data.overview,null,2)})]})]}):c(p,{text:`No ACA snapshot available yet.`})}),c(g,{title:`Task intake preview`,subtitle:`What ACA will try to pick up next`,children:n?o.isLoading?c(`div`,{className:`tcp-subtle text-sm`,children:`Loading task preview...`}):o.isError?c(`div`,{className:`rounded-2xl border border-red-500/20 bg-red-500/10 p-4 text-sm text-red-200`,children:o.error instanceof Error?o.error.message:`Could not load task preview.`}):o.data?.task?c(`div`,{className:`grid gap-3`,children:[c(`div`,{className:`flex flex-wrap items-center justify-between gap-3 rounded-2xl border border-white/10 bg-black/20 p-3`,children:[c(`div`,{className:`tcp-subtle text-xs`,children:[`GitHub Project intake is refreshed on demand through Tandem's GitHub MCP. It does not auto-update here so we can keep GitHub calls down.`,l?` Last refreshed ${new Date(l).toLocaleTimeString()}.`:``]}),c(`button`,{type:`button`,className:`tcp-btn tcp-btn-secondary`,onClick:s,disabled:o.isFetching,children:o.isFetching?`Refreshing...`:`Refresh from GitHub`})]}),c(`div`,{className:`rounded-2xl border border-white/10 bg-black/20 p-4`,children:[c(`div`,{className:`text-sm font-semibold`,children:String(o.data.task.title||`Untitled task`)}),c(`div`,{className:`tcp-subtle mt-1 text-xs`,children:[String(o.data.source_type||`unknown`),o.data.board_path?` · ${String(o.data.board_path)}`:``]}),c(`div`,{className:`mt-3 flex flex-wrap gap-2`,children:[c(d,{tone:o.data.eligible?`ok`:`warn`,children:o.data.eligible?`Eligible`:`Not eligible`}),c(d,{tone:`info`,children:[`ACA intake lane`,` `,E(String(o.data.task.lane||`ready`))]}),o.data.task?.source?o.data.task.source.status?c(d,{tone:`ghost`,children:[`GitHub status `,String(o.data.task.source.status)]}):c(d,{tone:`ghost`,children:`GitHub status unavailable from MCP`}):null]})]}),o.data?.board_summary?c(`div`,{className:`flex flex-wrap gap-2`,children:Object.entries(o.data.board_summary).map(([e,t])=>c(d,{tone:`ghost`,children:[e,`: `,String(t)]},e))}):null,String(o.data?.warning||``).trim()?c(`div`,{className:`rounded-2xl border border-amber-500/30 bg-amber-500/10 p-3 text-sm text-amber-100`,children:String(o.data.warning)}):null]}):c(p,{text:`No task preview available yet.`}):c(p,{text:`Select a project to preview task intake.`})})]})]})})}var P=`tcp.coding-planner.session.v1`,ue=`tcp.coding-planner.composer.v1`;function F(e){return String(e||``).trim()}function I(e,t,n=``){let r=F(t)||`default`,i=F(n);return i?`${e}:${r}:${i}`:`${e}:${r}`}function L(e){return I(P,e)}function de(e){try{return localStorage.getItem(L(e))||``}catch{return``}}function fe(e,t){try{let n=L(e),r=F(t);r?localStorage.setItem(n,r):localStorage.removeItem(n)}catch{}}function pe(e){fe(e,``)}function R(e,t){return I(ue,e,t)}function me(e,t){try{return sessionStorage.getItem(R(e,t))||``}catch{return``}}function he(e,t,n){try{let r=R(e,t),i=F(n);i?sessionStorage.setItem(r,i):sessionStorage.removeItem(r)}catch{}}function ge(e,t){he(e,t,``)}function _e({sessions:e,selectedSessionId:t,onSelectSession:n,onCreateSession:r,onRenameSession:i,onDuplicateSession:a,onDeleteSession:o,className:s=``}){return c(`section`,{className:`flex min-h-0 flex-col rounded-2xl border border-white/10 bg-black/20 p-3 ${s}`.trim(),children:[c(`div`,{className:`flex items-start justify-between gap-3`,children:[c(`div`,{className:`min-w-0`,children:[c(`div`,{className:`text-xs uppercase tracking-wide text-slate-500`,children:`Planner sessions`}),c(`div`,{className:`tcp-subtle text-xs`,children:`Draft threads only. Model work starts when you generate or revise a plan.`})]}),c(`button`,{type:`button`,className:`tcp-btn shrink-0`,onClick:r,children:[c(`i`,{"data-lucide":`plus`}),`New plan`]})]}),c(`div`,{className:`mt-3 min-h-0 flex-1 space-y-2 overflow-auto pr-1`,children:e.length?e.map(e=>c(`article`,{className:`rounded-xl border p-2 transition ${e.id===t?`border-sky-500/40 bg-sky-500/10`:`border-white/10 bg-black/10 hover:border-white/20 hover:bg-black/20`}`,children:[c(`button`,{type:`button`,className:`block w-full text-left`,onClick:()=>n(e.id),title:e.title,children:[c(`div`,{className:`flex items-start justify-between gap-2`,children:[c(`div`,{className:`min-w-0`,children:[c(`div`,{className:`truncate text-sm font-medium text-slate-100`,children:e.title||`Untitled plan`}),c(`div`,{className:`mt-1 flex flex-wrap items-center gap-2 text-[11px] text-slate-500`,children:[c(`span`,{children:e.updatedAtLabel}),e.revisionCount?c(`span`,{children:[e.revisionCount,` rev`]}):null]})]}),c(d,{tone:b(e.status),className:`shrink-0`,children:v(e.status)})]}),c(`p`,{className:`mt-2 line-clamp-2 text-xs text-slate-400`,children:e.previewText})]}),c(`div`,{className:`mt-2 flex flex-wrap gap-2`,children:[c(`button`,{type:`button`,className:`tcp-btn h-7 px-2 text-[11px]`,onClick:()=>i(e.id),title:`Rename session`,children:c(`i`,{"data-lucide":`pencil`})}),c(`button`,{type:`button`,className:`tcp-btn h-7 px-2 text-[11px]`,onClick:()=>a(e.id),title:`Duplicate session`,children:c(`i`,{"data-lucide":`copy`})}),c(`button`,{type:`button`,className:`tcp-btn h-7 px-2 text-[11px]`,onClick:()=>o(e.id),title:`Delete session`,children:c(`i`,{"data-lucide":`trash-2`})})]})]},e.id)):c(`div`,{className:`rounded-xl border border-dashed border-white/10 bg-black/10 p-3`,children:[c(`div`,{className:`text-sm text-slate-100`,children:`No planner sessions yet.`}),c(`div`,{className:`mt-1 text-xs text-slate-500`,children:`Start a new plan when you are ready to create the first draft thread.`}),c(`button`,{type:`button`,className:`tcp-btn mt-3`,onClick:r,children:[c(`i`,{"data-lucide":`plus`}),`Start new plan`]})]})})]})}function ve(e){let{rootRef:t,session:n,planner:r,status:i,provider:a,actions:o,dialogs:s}=e,{plannerSessions:l,selectedSessionId:f,sessionsOpen:ee,plannerSessionSummaries:h,activePlannerSessionSummary:_,plannerTitle:ne}=n,{goal:v,workspaceRoot:re,notes:y,plannerInput:b,plannerProvider:ie,plannerModel:x,planPreview:S,planningConversation:T,planningChangeSummary:E,plannerError:D,plannerDiagnostics:O,publishing:k,resetting:se,clarification:A,saveStatus:j,publishStatus:M,lastSavedAtMs:ce,publishedAtMs:N,publishedTasks:le,plannerChatMessages:P,plannerInputPlaceholder:ue,plannerStatusTitle:F,plannerStatusDetail:I,exportMarkdown:L,plannerFallbackReason:de,hasPlannerResponse:fe,displayTasks:pe}=r,{isGitHubProject:R,taskSourceType:me,engineHealthy:he,plannerCanUseLlm:ge,hasExplicitPlannerOverride:ve,hasBasePlannerModel:z,plannerSelectionMatchesWorkspaceDefault:ye,resolvedWorkspaceRoot:B,canPublishToGitHub:be,plannerTimedOut:xe,clarificationNeeded:Se,planIsFallbackOnly:Ce,isPlanning:V}=i,{providerOptions:we,providerStatus:Te,selectedProjectSlug:H,selectedProject:Ee,githubProjectBoardSnapshot:U,connectedMcpServers:De}=a,Oe=O?.task_budget||O?.taskBudget||O?.decomposition_observation?.task_budget||O?.decompositionObservation?.taskBudget||O?.observation?.task_budget||O?.observation?.taskBudget||null,ke=String(Oe?.status||``).trim()===`rejected`,{activatePlannerSession:Ae,createNewPlannerSession:je,renamePlannerSession:W,duplicatePlannerSession:Me,deletePlannerSession:Ne,setSessionsOpen:G,previewMutation:Pe,reviseMutation:K,resetMutation:Fe,patchActivePlannerSession:Ie,setPlannerInput:Le,setGoal:q,setWorkspaceRoot:Re,setNotes:ze,setPlannerProvider:Be,setPlannerModel:Ve,setPlannerError:He,setPlannerDiagnostics:Ue,setClarification:We,setSaveStatus:Ge,publishTasks:Ke,plannerOperatorPreferences:qe,plannerSessionTitle:Je}=o,{renameSessionDialog:Ye,deleteSessionDialog:Xe,confirmRenamePlannerSession:Ze,confirmDeletePlannerSession:Qe,setRenameSessionDialog:J,setDeleteSessionDialog:$e}=s;return c(`div`,{ref:t,className:`grid gap-4 xl:grid-cols-[320px_minmax(0,1fr)]`,children:[c(u,{open:ee,title:`Planner sessions`,onClose:()=>G(!1),children:c(_e,{sessions:h,selectedSessionId:f,onSelectSession:Ae,onCreateSession:()=>void je(),onRenameSession:e=>void W(e),onDuplicateSession:e=>void Me(e),onDeleteSession:e=>void Ne(e)})}),c(`div`,{className:`hidden min-h-0 xl:block xl:self-start xl:sticky xl:top-4`,children:c(_e,{sessions:h,selectedSessionId:f,onSelectSession:Ae,onCreateSession:()=>void je(),onRenameSession:e=>void W(e),onDuplicateSession:e=>void Me(e),onDeleteSession:e=>void Ne(e)})}),c(`div`,{className:`grid gap-4 min-w-0`,children:[c(g,{title:ne,subtitle:`Use the built-in scrum-master planner to turn a goal into reviewable implementation tasks.`,actions:c(`button`,{type:`button`,className:`tcp-btn xl:hidden`,onClick:()=>G(!0),children:[c(`i`,{"data-lucide":`history`}),`Sessions`]}),children:c(`div`,{className:`grid gap-4`,children:[c(`div`,{className:`rounded-2xl border border-emerald-500/20 bg-emerald-500/5 p-4`,children:[c(`div`,{className:`flex flex-wrap items-center gap-2`,children:[c(d,{tone:`ok`,children:`scrum-master`}),c(d,{tone:R?`info`:`warn`,children:me||`unknown task source`}),c(d,{tone:he?`ok`:`warn`,children:he?`Engine ready`:`Engine unavailable`})]}),c(`p`,{className:`tcp-subtle mt-3 text-sm`,children:`Describe the work once, let the planner break it into repo-aware tasks, then revise it with comments before publishing. GitHub Project approval creates issues and moves them into the board. Local kanban approval saves a durable export bundle.`})]}),c(`div`,{className:`grid gap-3 xl:grid-cols-2`,children:[c(`div`,{className:`rounded-2xl border border-white/10 bg-black/20 p-4 xl:col-span-2`,children:[c(`div`,{className:`mb-3 flex flex-wrap items-center justify-between gap-2`,children:[c(`div`,{children:[c(`div`,{className:`text-xs uppercase tracking-wide text-slate-500`,children:`Planner model`}),c(`div`,{className:`tcp-subtle text-xs`,children:`Leave this on workspace default to use the base provider and model, or pick an explicit planner override for richer revisions.`})]}),c(d,{tone:ge?`ok`:`warn`,children:ve?`Planner override active`:z?`Workspace default active`:`No planner model configured`})]}),c(te,{providerLabel:`Planner provider`,modelLabel:`Planner model`,draft:{provider:ie,model:x},providers:we,onChange:({provider:e,model:t})=>{Be(e),Ve(t)},inheritLabel:`Workspace default`,disabled:V}),c(`div`,{className:`mt-3 flex flex-wrap gap-2`,children:[c(`button`,{type:`button`,className:`tcp-btn`,onClick:()=>{Be(``),Ve(``)},disabled:V||!ie&&!x,children:`Use workspace default`}),c(`button`,{type:`button`,className:`tcp-btn`,onClick:()=>{Be(Te.defaultProvider||``),Ve(Te.defaultModel||``)},disabled:V||!z||ye,children:`Restore workspace model`}),c(`button`,{type:`button`,className:`tcp-btn`,onClick:()=>{He(``),Ue(null),Ge(``)},disabled:V||!D&&!O,children:`Clear diagnostics`})]}),c(`div`,{className:`mt-2 text-xs text-slate-500`,children:[`Base model:`,` `,z?`${String(Te.defaultProvider||``)} / ${String(Te.defaultModel||``)}`:`not configured`]})]}),c(`label`,{className:`grid gap-2 xl:col-span-2`,children:[c(`span`,{className:`text-xs uppercase tracking-wide text-slate-500`,children:`Workspace root`}),c(`input`,{className:`tcp-input text-sm`,value:re,onInput:e=>Re(e.target.value),placeholder:`/absolute/path/to/the/repo/checkout`,disabled:V}),B?c(`span`,{className:`tcp-subtle text-xs`,children:[`Resolved from the selected project: `,B]}):null,c(`span`,{className:`tcp-subtle text-xs`,children:`The planner uses this checkout to inspect files and glob directories for the selected project.`})]}),c(`label`,{className:`grid gap-2 xl:col-span-2`,children:c(`span`,{className:`text-xs uppercase tracking-wide text-slate-500`,children:`Planner chat`})}),c(`div`,{className:`xl:col-span-2 rounded-2xl border border-white/10 bg-black/20 p-4`,children:c(`div`,{className:`flex flex-wrap items-start justify-between gap-3`,children:[c(`div`,{className:`min-w-0`,children:[c(`div`,{className:`text-xs uppercase tracking-wide text-slate-500`,children:`Active session`}),c(`div`,{className:`truncate text-lg font-semibold text-slate-100`,children:_?.title||`Untitled plan`}),c(`div`,{className:`mt-1 flex flex-wrap gap-2 text-xs text-slate-500`,children:[c(`span`,{children:_?.projectSlug||H||`unbound`}),c(`span`,{children:`·`}),c(`span`,{children:_?.updatedAtLabel||(ce?new Date(ce).toLocaleString():`unknown`)}),c(`span`,{children:`·`}),c(`span`,{children:[_?.revisionCount||0,` rev`]})]})]}),c(`div`,{className:`flex flex-wrap items-center gap-2`,children:[c(d,{tone:_?.statusTone||`ghost`,children:_?.statusLabel||`Draft`}),c(`button`,{type:`button`,className:`tcp-btn h-8 px-2 text-xs`,onClick:()=>f?void W(f):void 0,disabled:!f||V,children:[c(`i`,{"data-lucide":`pencil`}),`Rename`]}),c(`button`,{type:`button`,className:`tcp-btn h-8 px-2 text-xs`,onClick:()=>f?void Me(f):void 0,disabled:!f||V,children:[c(`i`,{"data-lucide":`copy`}),`Duplicate`]}),c(`button`,{type:`button`,className:`tcp-btn h-8 px-2 text-xs`,onClick:()=>f?void Ne(f):void 0,disabled:!f||V,children:[c(`i`,{"data-lucide":`trash-2`}),`Delete`]}),c(`button`,{type:`button`,className:`tcp-btn h-8 px-2 text-xs xl:hidden`,onClick:()=>G(!0),children:[c(`i`,{"data-lucide":`history`}),`Sessions`]})]})]})}),fe?null:c(`div`,{className:`xl:col-span-2 rounded-2xl border border-dashed border-white/10 bg-black/10 p-4`,children:[c(`div`,{className:`text-sm font-medium text-slate-100`,children:`Start a plan with a short prompt`}),c(`div`,{className:`mt-1 text-xs text-slate-500`,children:`Use one of the prompts below, then start a new plan when you are ready to create a draft thread.`}),c(`div`,{className:`mt-3 flex flex-wrap gap-2`,children:[`Plan the implementation for this bug fix.`,`Break this feature into backend, frontend, and verification tasks.`,`Review this idea and suggest an implementation plan.`,`Refine the plan to reduce risk and unknowns.`].map(e=>c(`button`,{type:`button`,className:`tcp-btn text-sm`,onClick:()=>{Le(e)},disabled:V,children:e},e))}),c(`div`,{className:`mt-3`,children:c(`button`,{type:`button`,className:`tcp-btn-primary`,onClick:je,disabled:V,children:[c(`i`,{"data-lucide":`plus`}),`Start new plan`]})})]})]}),c(C,{messages:P,emptyText:f?`No plan yet. Use a starter prompt or describe the work.`:`No planner session selected. Start a new plan to create a draft thread.`,inputValue:b,inputPlaceholder:ue,sendLabel:S?`Send to planner`:`Generate plan`,onInputChange:Le,onSend:()=>void(S?K(b):Pe(b)),sendDisabled:V||!f||!String(b||``).trim(),inputDisabled:V||!f,statusTitle:F,statusDetail:V?I:``,questionTitle:`Planner question`,questionText:A.status===`waiting`?A.question:``,quickReplies:A.status===`waiting`?A.options:[],onQuickReply:e=>void K(e.label),questionHint:`Reply in the planner chat box below or choose a suggested answer.`,autoFocusKey:f}),c(`div`,{className:`flex flex-wrap gap-2`,children:[S?c(`button`,{type:`button`,className:`tcp-btn`,onClick:()=>void Pe(b||v),disabled:V,children:[c(`i`,{"data-lucide":`refresh-cw`}),`Regenerate plan`]}):null,c(`button`,{type:`button`,className:`tcp-btn`,onClick:()=>void Fe(),disabled:se||V,children:[c(`i`,{"data-lucide":`rotate-ccw`}),se?`Resetting…`:`Reset plan`]}),c(`button`,{type:`button`,className:`tcp-btn`,onClick:()=>{Le(``),ze(``),He(``),Ue(null),We({status:`none`}),Ge(``)},disabled:V||!b&&!y&&!D&&!O,children:[c(`i`,{"data-lucide":`eraser`}),`Clear composer and warnings`]}),c(`button`,{type:`button`,className:`tcp-btn`,onClick:()=>{Ie({title:Je({goal:v,plan:S,fallbackTime:ce||Date.now()}),workspace_root:re,goal:v,notes:y,planner_provider:ie,planner_model:x,plan_source:`coding_task_planning`,allowed_mcp_servers:De,operator_preferences:qe({plannerProvider:ie,plannerModel:x,defaultProvider:Te.defaultProvider,defaultModel:Te.defaultModel,selectedProjectSlug:H,taskSourceType:me,selectedProject:Ee,goal:v,notes:y}),current_plan_id:S?.plan_id,draft:S?{initial_plan:S,current_plan:S,plan_revision:Number(S.plan_revision||1)||1,conversation:T||{conversation_id:`wfchat-${f}`,plan_id:S.plan_id,created_at_ms:Date.now(),updated_at_ms:Date.now(),messages:[]},planner_diagnostics:O,last_success_materialization:null}:void 0,published_at_ms:N||void 0,published_tasks:le.length?le:void 0}),Ge(`Planner session synced.`)},disabled:V,children:[c(`i`,{"data-lucide":`save`}),`Sync session`]}),c(`button`,{type:`button`,className:`tcp-btn`,onClick:async()=>{try{await navigator.clipboard.writeText(L)}catch{}},disabled:V,children:[c(`i`,{"data-lucide":`copy`}),`Copy markdown`]})]}),D&&!Se?c(`div`,{className:`rounded-2xl p-3 text-sm ${xe||Se?`border border-amber-500/40 bg-amber-950/30 text-amber-100`:`border border-red-500/40 bg-red-950/30 text-red-200`}`,children:[xe?c(`div`,{className:`mb-1 text-xs uppercase tracking-wide text-amber-300`,children:`Planner timed out`}):Se?c(`div`,{className:`mb-1 text-xs uppercase tracking-wide text-amber-300`,children:`Planner question`}):null,D]}):null,O||E.length?c(oe,{plannerDiagnostics:{...O,summary:O?.summary||O?.detail||(de===`no_planner_model`?`The planner fell back because no usable planner model reached the backend for this generated plan.`:de===`clarification_needed`?`The planner needs one more answer before it can generate a richer repo-aware plan.`:``)},teachingLibrary:null,planningChangeSummary:E}):null,j||M?c(`div`,{className:`rounded-2xl border border-white/10 bg-black/20 p-3 text-sm text-slate-300`,children:[j?c(`div`,{children:j}):null,M?c(`div`,{className:`mt-1`,children:M}):null,ce?c(`div`,{className:`mt-1 text-xs text-slate-500`,children:[`Last saved `,new Date(ce).toLocaleString()]}):null]}):null]})}),fe?c(`div`,{className:`grid gap-4`,children:[c(g,{title:`Plan details`,subtitle:`Planner metadata and markdown stay visible here`,children:S?c(`div`,{className:`grid gap-3`,children:[c(`div`,{className:`grid gap-2 text-sm text-slate-300`,children:[c(`div`,{children:[c(`span`,{className:`tcp-subtle`,children:`Title:`}),` `,String(S?.title||``)||`Untitled plan`]}),c(`div`,{children:[c(`span`,{className:`tcp-subtle`,children:`Confidence:`}),` `,String(S?.confidence||``)||`unknown`]}),c(`div`,{children:[c(`span`,{className:`tcp-subtle`,children:`Plan source:`}),` `,String(S?.plan_source||S?.planSource||``)||`coding_task_planning`]})]}),typeof S?.description==`string`&&S.description.trim()?c(`div`,{className:`rounded-2xl border border-white/10 bg-black/20 p-3`,children:[c(`div`,{className:`text-xs uppercase tracking-wide text-slate-500`,children:`Planner markdown`}),c(`div`,{className:`tcp-markdown tcp-markdown-ai mt-2 text-sm`,dangerouslySetInnerHTML:{__html:m(String(S.description||``))}})]}):null,c(`div`,{className:`grid gap-2`,children:[c(`button`,{type:`button`,className:`tcp-btn-primary`,disabled:k||V||!v.trim()||!re.trim()||Se||xe||Ce||ke,onClick:()=>void Ke(),children:[c(`i`,{"data-lucide":R&&be?`badge-check`:`arrow-up-circle`}),k?`Publishing…`:R&&be?`Approve and publish to GitHub Project`:`Save local task bundle`]}),c(`div`,{className:`text-xs text-slate-500`,children:Se?`Answer the planner's question before approving or publishing tasks.`:xe?`Retry the planner revision or switch models before approving tasks.`:ke?`Regenerate the plan so Tandem can compact it into the generated 8-task budget before publishing.`:Ce?`Wait for a real task breakdown before approving or publishing tasks.`:R&&be?`This will create GitHub issues, add each issue to the selected project board, and move it into Ready when the board metadata is available.`:`Local kanban mode saves the plan locally so you can apply it to the board file or keep it as a durable draft.`})]})]}):c(p,{text:`No plan has been generated yet.`})}),c(g,{title:`Planned tasks`,subtitle:`Review the generated backlog before publishing`,children:pe.length?c(`div`,{className:`grid gap-3`,children:pe.map((e,t)=>c(`div`,{className:`rounded-2xl border border-white/10 bg-black/20 p-4`,children:[c(`div`,{className:`flex flex-wrap items-start justify-between gap-2`,children:[c(`div`,{className:`min-w-0`,children:[c(`div`,{className:`text-sm font-semibold text-slate-100`,children:e.title}),c(`div`,{className:`mt-1 text-xs text-slate-500`,children:[e.kind||`task`,e.dependsOn.length?` · depends on ${e.dependsOn.join(`, `)}`:``]})]}),c(d,{tone:`info`,children:[`Step `,t+1]})]}),c(`div`,{className:`mt-3 grid gap-2 text-sm text-slate-300`,children:[c(`div`,{children:[c(`span`,{className:`tcp-subtle`,children:`Summary:`}),` `,e.objective]}),e.outputContract?c(`div`,{children:[c(`span`,{className:`tcp-subtle`,children:`Expected result:`}),` `,e.outputContract]}):null,e.inputRefs.length?c(`div`,{className:`text-xs text-slate-500`,children:[c(`span`,{className:`tcp-subtle`,children:`Inputs:`}),` `,e.inputRefs.map(e=>`${e.alias} <- ${e.fromStepId}`).join(`, `)]}):null]})]},`${e.id}-${t}`))}):S?c(p,{text:Se?`Answer the planner's question to generate a real task breakdown.`:xe?`The last revision timed out, so the planner kept the current fallback draft.`:`The planner returned a plan, but no usable step list was available.`}):c(p,{text:`Generate a plan to see task drafts here.`})})]}):null,c(w,{open:!!Ye,title:`Rename planner session`,message:c(`span`,{children:[`Choose a new name for`,` `,c(`strong`,{children:Ye?.sessionId&&l.find(e=>e.id===Ye.sessionId)?.title||`this session`}),`.`]}),label:`Session name`,value:Ye?.value||``,placeholder:`Untitled plan`,confirmLabel:`Rename`,confirmIcon:`square-pen`,confirmDisabled:!String(Ye?.value||``).trim(),onCancel:()=>J(null),onChange:e=>J(t=>t&&{...t,value:e}),onConfirm:()=>void Ze()}),c(ae,{open:!!Xe,title:`Delete session`,message:c(`span`,{children:[`This will permanently remove`,` `,c(`strong`,{children:Xe?.title||`this session`}),` and all its messages.`]}),confirmLabel:`Delete session`,confirmIcon:`trash-2`,confirmTone:`danger`,onCancel:()=>$e(null),onConfirm:()=>void Qe()})]})]})}function z(e,t){return Array.isArray(e)?e:Array.isArray(e?.[t])?e[t]:[]}function ye(e){return(Array.isArray(e)?e:Array.isArray(e?.servers)?e.servers:e&&typeof e==`object`?Object.entries(e).map(([e,t])=>({name:e,...t})):[]).map(e=>({name:String(e?.name||``).trim(),connected:!!e?.connected,enabled:e?.enabled!==!1,transport:String(e?.transport||``).trim(),lastError:String(e?.last_error||e?.lastError||``).trim()})).filter(e=>e.name).sort((e,t)=>e.name.localeCompare(t.name))}function B(e){return(Array.isArray(e)?e:Array.isArray(e?.tools)?e.tools:[]).map(e=>typeof e==`string`?e:String(e?.namespaced_name||e?.namespacedName||e?.id||``).trim()).filter(Boolean)}function be(e){let t=Array.isArray(e)?e:e&&typeof e==`object`?Object.entries(e).map(([e,t])=>({slug:e,...t})):[],n=new Map;for(let e of t){let t=e?.task_source||e?.taskSource||{},r=String(t?.type||``).trim(),i=e?.repo||{},a=String(e?.repo_url||e?.repoUrl||i?.clone_url||i?.cloneUrl||``).trim(),o=r===`github_project`&&String(t?.owner||``).trim()&&String(t?.repo||``).trim()&&String(t?.project||``).trim()?`github:${String(t.owner).trim().toLowerCase()}/${String(t.repo).trim().toLowerCase()}#${String(t.project).trim()}`:a?`repo:${a.toLowerCase()}`:`slug:${e.slug}`,s=n.get(o);if(!s){n.set(o,e);continue}let c=s?.repo||{},l=String(s?.repo_url||s?.repoUrl||c?.clone_url||c?.cloneUrl||``).trim(),u=(s.implicit?0:10)+ +!!l;(e.implicit?0:10)+ +!!a>u&&n.set(o,e)}return Array.from(n.values()).map(e=>{let t=e?.repo||{},n=e?.task_source||e?.taskSource||{};return{slug:String(e?.slug||``).trim(),name:String(e?.name||e?.display_name||e?.displayName||e?.slug||``).trim(),repoUrl:String(e?.repo_url||e?.repoUrl||t?.clone_url||t?.cloneUrl||``).trim(),repoPath:String(t?.path||e?.repo_path||e?.repoPath||``).trim(),worktreeRoot:String(t?.worktree_root||e?.worktree_root||e?.worktreeRoot||``).trim(),defaultBranch:String(t?.default_branch||e?.default_branch||e?.defaultBranch||`main`).trim(),remoteName:String(t?.remote_name||e?.remote_name||e?.remoteName||`origin`).trim(),credentialFile:String(t?.credential_file||e?.credential_file||e?.credentialFile||``).trim(),taskSource:n,implicit:e?.implicit===!0}}).filter(e=>e.slug).sort((e,t)=>e.implicit===t.implicit?e.slug.localeCompare(t.slug):e.implicit?1:-1)}function xe(e){return{items:Array.isArray(e?.items)?e.items.map((e,t)=>({id:String(e?.id||e?.project_item_id||`item-${t}`).trim(),projectItemId:String(e?.project_item_id||e?.projectItemId||``).trim(),title:String(e?.title||`Untitled item`).trim(),statusKey:String(e?.status_key||e?.statusKey||`unknown`).trim(),statusName:String(e?.status_name||e?.statusName||`Unknown`).trim(),issueNumber:e?.issue_number||e?.issueNumber||null,issueUrl:String(e?.issue_url||e?.issueUrl||``).trim(),repoName:String(e?.repo_name||e?.repoName||``).trim(),actionable:e?.actionable===!0,selector:String(e?.project_item_id||e?.projectItemId||e?.issue_number||e?.issueNumber||e?.id||``).trim()})).filter(e=>e.id):[],source:String(e?.source||``).trim(),warning:String(e?.warning||``).trim(),isStale:e?.is_stale===!0,lastSyncedAtMs:Number(e?.last_synced_at_ms||e?.lastSyncedAtMs||0)}}function Se(e,t){return String(e?.run_id||e?.runId||e?.id||`run-${t}`).trim()}function Ce(e){return String(e?.title||e?.summary||e?.run_id||e?.runId||`Untitled run`).trim()}function V(e){let t=Number(e?.updated_at_ms||e?.created_at_ms||e?.snapshot?.updated_at_ms||e?.snapshot?.created_at_ms||0);return Number.isFinite(t)?t:0}function we(e){return String(e?.status||e?.snapshot?.status||e?.status?.run?.status||`unknown`).trim().toLowerCase()}function Te(e){return String(e?.phase?.name||e?.snapshot?.phase?.name||e?.status?.phase?.name||``).trim().toLowerCase()}function H(e){return String(e||`unknown`).replace(/_/g,` `).replace(/\b\w/g,e=>e.toUpperCase())}var Ee=1800*1e3,U=15*1e3;function De(e){return e?.is_running===!0||e?.snapshot?.is_running===!0}function Oe(e){let t=we(e);if([`completed`,`done`,`failed`,`cancelled`,`blocked`,`archived`].includes(t))return!1;if(De(e))return!0;let n=V(e);return n?Date.now()-n<Ee:!1}function ke(e,t){let n=e?.blackboard?.task||e?.snapshot?.blackboard?.task||{},r=n?.source||{},i=n?.repo||{};return String(r?.issue_url||r?.url||r?.item_url||r?.project_item_id||r?.card_id||n?.task_id||`${i?.slug||e?.project_slug||`project`}:${Ce(e)}:${t}`).trim()}function Ae(e){return String(e?.issueUrl||e?.projectItemId||e?.id||``).trim()}function je(e){return String(e||``).trim().toLowerCase().replace(/[^a-z0-9]+/g,`_`).replace(/^_+|_+$/g,``)}function W(e){let t=je(e);return t===`todos`?`TODOS`:t===`todo`?`Todo`:t.split(`_`).filter(Boolean).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(` `)}function Me(e){let t=je(e?.statusKey),n=je(e?.statusName),r=t&&t!==`unknown`?t:n;return!e?.selector||[`blocked`,`cancelled`,`closed`,`complete`,`completed`,`done`,`failed`,`in_progress`,`in_review`,`on_hold`,`stalled`].includes(r)?!1:e?.actionable===!0||[`ready`,`backlog`,`todo`,`todos`].includes(r)}function Ne(e){let t=Number(e?.status_field_id||e?.statusFieldId||0),n=e?.status_option_map||e?.statusOptionMap||{},r=new Map;Object.entries(n||{}).forEach(([e,t])=>{let n=je(e),i=String(t||``).trim();n&&i&&r.set(n,i)});let i=Array.isArray(e?.columns)?e.columns:[];for(let e of[`todos`,`todo`,`to_do`,`ready`,`backlog`]){let n=r.get(e);if(!n)continue;let a=i.find(t=>je(t?.key)===e||je(t?.name)===e);return{statusFieldId:t,optionId:n,label:String(a?.name||``).trim()||W(e)}}return{statusFieldId:t,optionId:``,label:``}}function G(e){let t=new Map;return e.forEach((e,n)=>{let r=ke(e,n),i=t.get(r);(!i||V(e)>=V(i))&&t.set(r,e)}),Array.from(t.values()).sort((e,t)=>V(t)-V(e))}function Pe(e){let t=String(e||``).trim();if(!t)return null;let n=e=>{let t=e.replace(/^\/+/,``).replace(/\.git$/i,``).split(`/`).map(e=>e.trim()).filter(Boolean);if(t.length<2)return null;let[n,r]=t;return!n||!r?null:{owner:n,repo:r,slug:`${n}/${r}`}},r=t.match(/^git@github\.com:([^/]+)\/(.+?)(?:\.git)?$/i);if(r?.[1]&&r?.[2])return n(`${r[1]}/${r[2]}`);try{let e=new URL(t);return e.hostname.toLowerCase()===`github.com`?n(e.pathname):null}catch{return n(t)}}function K(e,{prompt:t,path:n,repoRef:r,projectNumber:i}){return e===`manual`?{type:`manual`,prompt:t.trim()}:e===`kanban_board`?{type:`kanban_board`,path:n.trim()}:e===`local_backlog`?{type:`local_backlog`,path:n.trim()}:{type:`github_project`,owner:r?.owner||``,repo:r?.repo||``,project:i.trim()}}function Fe(e){let t=String(e||``).trim().replace(/\\/g,`/`);if(!t)return!0;if(t.startsWith(`/`)||/^[A-Za-z]:/.test(t))return!1;let n=t.split(`/`).filter(Boolean);return n.length>0&&!n.some(e=>e===`.`||e===`..`)}function Ie(e){try{let t=JSON.parse(String(e||`{}`));return t&&typeof t==`object`?t:null}catch{return null}}var Le=`tandem.intent-planner.codingTaskHandoff.v1`;function q(e){return String(e||``).trim()}function Re(e){let t=q(e).toLowerCase();return t.includes(`workflow_plan_not_found`)||t.includes(`workflow plan not found`)}function ze(e){let t=q(e?.taskSource?.repo);if(t)return`/workspace/repos/${t.split(`/`).pop()||t}`;let n=q(e?.repoUrl);if(!n)return``;try{let e=new URL(n).pathname.split(`/`).filter(Boolean),t=(e[e.length-1]||``).replace(/\.git$/,``);return t?`/workspace/repos/${t}`:``}catch{let e=n.match(/\/([^/]+?)(?:\.git)?(?:\?.*)?$/);return e?.[1]?`/workspace/repos/${e[1]}`:``}}function Be(e){let t=q(e.plan?.title);if(t)return t;let n=q(e.goal);return n?n.length>48?`${n.slice(0,47).trimEnd()}…`:n:e.existingTitle?e.existingTitle:`Plan ${new Date(e.fallbackTime||Date.now()).toLocaleTimeString()}`}function Ve(e){return{id:q(e?.session_id||e?.sessionId),title:q(e?.title||`Untitled plan`),updatedAtMs:Number(e?.updated_at_ms||e?.updatedAtMs||0)||0,projectSlug:q(e?.project_slug||e?.projectSlug),workspaceRoot:q(e?.workspace_root||e?.workspaceRoot),currentPlanId:q(e?.current_plan_id||e?.currentPlanId),goal:q(e?.goal||``),plannerProvider:q(e?.planner_provider||e?.plannerProvider),plannerModel:q(e?.planner_model||e?.plannerModel),publishedAtMs:Number(e?.published_at_ms||e?.publishedAtMs||0)||null,draft:e?.draft||null}}function He(e){return{id:q(e?.session_id||e?.sessionId),title:q(e?.title||`Untitled plan`),updatedAtMs:Number(e?.updated_at_ms||e?.updatedAtMs||0)||0,projectSlug:q(e?.project_slug||e?.projectSlug),workspaceRoot:q(e?.workspace_root||e?.workspaceRoot),currentPlanId:q(e?.current_plan_id||e?.currentPlanId),goal:q(e?.goal||``),plannerProvider:q(e?.planner_provider||e?.plannerProvider),plannerModel:q(e?.planner_model||e?.plannerModel),publishedAtMs:Number(e?.published_at_ms||e?.publishedAtMs||0)||null,draft:e?.draft||null}}function Ue(e,t){return x({session:{...e,...t?.session||{}},draft:t?.draft||e.draft||null,clarificationState:t?.clarification||{status:`none`}})}function We(){return{session:null,draft:null,clarification:{status:`none`},planPreview:null,planningConversation:null,planningChangeSummary:[],plannerDiagnostics:null,publishedTasks:[]}}function Ge(e){return(Array.isArray(e?.steps)?e.steps:[]).map((e,t)=>{let n=q(e?.step_id||e?.stepId||`step-${t+1}`),r=q(e?.objective),i=q(e?.kind||`task`),a=Array.isArray(e?.depends_on||e?.dependsOn)?(e?.depends_on||e?.dependsOn).map(e=>q(e)).filter(Boolean):[],o=Array.isArray(e?.input_refs||e?.inputRefs)?(e?.input_refs||e?.inputRefs).map(e=>({fromStepId:q(e?.from_step_id||e?.fromStepId),alias:q(e?.alias)})):[],s=q(e?.output_contract?.kind||e?.outputContract?.kind||``);return{id:n,title:r||`${i} ${t+1}`,objective:r||`${i} ${t+1}`,kind:i,dependsOn:a,inputRefs:o,outputContract:s}}).filter(e=>e.title||e.objective)}function Ke(e){let t=[e?.output],n=e?.metadata?.result;if(n){t.push(n);let e=n?.content;if(Array.isArray(e))for(let n of e)n&&typeof n==`object`&&(t.push(n?.text),t.push(n))}for(let e of t){if(e==null)continue;if(typeof e==`number`&&Number.isFinite(e))return Number(e);if(typeof e==`object`){let t=e,n=t.issue_number??t.issueNumber??t.number??t.issue?.number??t.data?.number;if(typeof n==`number`&&Number.isFinite(n))return Number(n);if(typeof n==`string`&&n.trim()){let e=Number.parseInt(n,10);if(Number.isFinite(e))return e}continue}let t=String(e||``).trim();if(t)try{let e=JSON.parse(t);if(e&&typeof e==`object`){let t=e.issue_number??e.issueNumber??e.number??e.data?.number;if(typeof t==`number`&&Number.isFinite(t))return Number(t);if(typeof t==`string`&&t.trim()){let e=Number.parseInt(t,10);if(Number.isFinite(e))return e}}}catch{let e=t.match(/"issue_number"\s*:\s*(\d+)/i)||t.match(/"issueNumber"\s*:\s*(\d+)/i)||t.match(/"number"\s*:\s*(\d+)/i)||t.match(/#(\d+)/);if(e){let t=Number.parseInt(e[1],10);if(Number.isFinite(t))return t}}}return null}function qe(e){let t=[e?.output],n=e?.metadata?.result;if(n){t.push(n);let e=n?.content;if(Array.isArray(e))for(let n of e)n&&typeof n==`object`&&(t.push(n?.text),t.push(n))}for(let e of t){if(e==null)continue;if(typeof e==`number`&&Number.isFinite(e))return Number(e);if(typeof e==`object`){let t=e,n=t.project_item_id??t.projectItemId??t.item_id??t.itemId??t.id;if(typeof n==`number`&&Number.isFinite(n))return Number(n);if(typeof n==`string`&&n.trim()){let e=Number.parseInt(n,10);if(Number.isFinite(e))return e}continue}let t=String(e||``).trim();if(t)try{let e=JSON.parse(t);if(e&&typeof e==`object`){let t=e.project_item_id??e.projectItemId??e.item_id??e.itemId??e.id;if(typeof t==`number`&&Number.isFinite(t))return Number(t);if(typeof t==`string`&&t.trim()){let e=Number.parseInt(t,10);if(Number.isFinite(e))return e}}}catch{let e=t.match(/"project_item_id"\s*:\s*(\d+)/i)||t.match(/"projectItemId"\s*:\s*(\d+)/i)||t.match(/"item_id"\s*:\s*(\d+)/i)||t.match(/"itemId"\s*:\s*(\d+)/i)||t.match(/"id"\s*:\s*(\d+)/i);if(e){let t=Number.parseInt(e[1],10);if(Number.isFinite(t))return t}}}return null}function Je(e,t,n,r){let i=q(e?.description),a=t.inputRefs.length?t.inputRefs.map(e=>`- ${e.alias||`ref`} <- ${e.fromStepId}`).join(`
2
+ `):`- None`,o=t.dependsOn.length?t.dependsOn.map(e=>`- ${e}`).join(`
3
+ `):`- None`,s=q(r.selectedProject?.repoUrl),c=r.selectedProject?.taskSource||{},l=r.taskSourceType===`github_project`?`GitHub Project ${q(c.owner)}/${q(c.repo)} #${q(c.project)}`:r.taskSourceType===`kanban_board`||r.taskSourceType===`local_backlog`?q(c.path)||`local task source`:`manual`;return[`# ${t.title}`,``,`## Summary`,t.objective||`Planned repository task.`,``,`## Context`,`- Project: ${r.projectSlug||`unbound`}`,`- Task source: ${l}`,`- Workspace root: ${r.workspaceRoot||`engine workspace root`}`,s?`- Repo URL: ${s}`:``,`- Planner persona: scrum-master`,`- Planner provider: ${r.plannerProvider||`workspace default`}`,`- Planner model: ${r.plannerModel||`workspace default`}`,`- Step kind: ${t.kind||`task`}`,``,`## Expected Results`,i||`Follow the goal and preserve existing behavior unless the plan says otherwise.`,``,`## Implementation Notes`,`- Depends on:\n${o}`,`- Input refs:\n${a}`,t.outputContract?`- Output contract: ${t.outputContract}`:`- Output contract: not specified`,``,`## Verification`,`- Validate the touched files in the workspace.`,`- Run the smallest relevant build or test command for the repo area.`,`- Confirm the user-visible behavior described by the plan.`,``,`## Rework Notes`,r.notes?r.notes:`None`,``,`## Planner Snapshot`,"```json",JSON.stringify({task_number:n+1,task_title:t.title,task_kind:t.kind,step_id:t.id,workspace_root:r.workspaceRoot,project_slug:r.projectSlug,planner_provider:r.plannerProvider,planner_model:r.plannerModel},null,2),"```"].filter(Boolean).join(`
4
+ `)}function Ye(e,t,n){return[`# Task Plan`,``,`- Project: ${n.projectSlug||`unbound`}`,`- Workspace root: ${n.workspaceRoot||`engine workspace root`}`,n.goal?`- Goal: ${n.goal}`:`- Goal: (none)`,`- Planner provider: ${n.plannerProvider||`workspace default`}`,`- Planner model: ${n.plannerModel||`workspace default`}`,n.notes?`- Rework notes: ${n.notes}`:``,e?.title?`- Plan title: ${e.title}`:``,``,`## Tasks`,...t.flatMap((e,t)=>[`### ${t+1}. ${e.title}`,``,e.objective||``,``,e.outputContract?`- Expected result: ${e.outputContract}`:``,e.dependsOn.length?`- Depends on: ${e.dependsOn.join(`, `)}`:``,``]),``,`## Raw Plan`,"```json",JSON.stringify(e||{},null,2),"```"].filter(Boolean).join(`
5
+ `)}function Xe(e){let t=q(e.defaultProvider),n=q(e.defaultModel),r=q(e.plannerProvider),i=q(e.plannerModel),a={};return t&&n&&(a.model_provider=t,a.model_id=n),r&&i&&(a.role_models={planner:{provider_id:r,model_id:i}}),Object.assign(a,S(e.goal)),Object.assign(a,y(e.goal)),a}function Ze({client:t,api:u,toast:d,selectedProjectSlug:f,selectedProject:p,githubProjectBoardSnapshot:ee,taskSourceType:m,workspaceRootSeed:h,connectedMcpServers:g,engineHealthy:te,providerStatus:_}){let ne=r(null),v=o(),[y,b]=i([]),[x,S]=i({}),[C,w]=i(``),[ae,oe]=i(!1),[T,E]=i(``),[D,O]=i(``),[k,se]=i(``),[A,j]=i(``),[M,ce]=i(``),[N,le]=i(``),[P,ue]=i(null),[F,I]=i(null),[L,R]=i([]),[_e,z]=i(``),[ye,B]=i(null),[be,xe]=i(!1),[Se,Ce]=i(!1),[V,we]=i(!1),[Te,H]=i(`idle`),[Ee,U]=i({status:`none`}),[De,Oe]=i(null),[ke,Ae]=i(null),[je,W]=i(``),[Me,G]=i(``),[Pe,K]=i(null),[Fe,Ie]=i(null),[Ze,Qe]=i([]),J=r(``),$e=s({queryKey:[`coding-workflows`,`control-panel-config`,f],queryFn:()=>u(`/api/control-panel/config`)}),et=s({queryKey:[`coding-workflows`,`providers`,`catalog`],queryFn:()=>t.providers.catalog().catch(()=>({all:[]})),refetchInterval:3e4}),tt=s({queryKey:[`coding-workflows`,`providers`,`config`],queryFn:()=>t.providers.config().catch(()=>({})),refetchInterval:3e4}),nt=n(()=>Ge(P),[P]),rt=String(m||``).trim()===`github_project`,it=n(()=>ie({providerCatalog:et.data,providerConfig:tt.data,defaultProvider:_.defaultProvider,defaultModel:_.defaultModel}),[_.defaultModel,_.defaultProvider,et.data,tt.data]),at=q($e.data?.config?.repository?.path||$e.data?.config?.repository?.worktree_root||``),ot=n(()=>rt?at||ze(p)||h||``:String(m||``).trim()===`kanban_board`||String(m||``).trim()===`local_backlog`?q(p?.taskSource?.path||h||``):h||``,[at,rt,p,m,h]),Y=rt&&!!q(p?.taskSource?.owner)&&!!q(p?.taskSource?.repo)&&Number.isFinite(Number(p?.taskSource?.project||0)),st=!!(q(_.defaultProvider)&&q(_.defaultModel)),ct=!!(q(M)&&q(N)),lt=q(M)===q(_.defaultProvider)&&q(N)===q(_.defaultModel),ut=st||ct,dt=Te===`generating`,ft=Te===`clarifying`,pt=Te!==`idle`,mt=q(ye?.fallback_reason||ye?.fallbackReason),ht=mt===`clarification_needed`,gt=q(Array.isArray(F?.messages)?[...F.messages].reverse().find(e=>q(e?.role).toLowerCase()===`assistant`)?.text:``),_t=/timed out before completion/i.test(q(_e))||/timed out before completion/i.test(gt),X=n(()=>re(F,!1),[F]),Z=pt?dt?`Generating task plan…`:ft?`Waiting for planner…`:`Revising task plan…`:``,vt=ft?`The planner is thinking. You'll be able to answer its question shortly.`:`The request is running against the engine now. Repo-aware planning can take a bit longer while the model inspects files and drafts the task breakdown.`,yt=P?`Send a follow-up message or revision request to the planner. (Enter to send, Shift+Enter newline)`:`Describe the outcome you want and send to planner. (Enter to send, Shift+Enter newline)`,bt=nt.length===1&&q(nt[0]?.id)===`execute_goal`&&(!!mt||/fallback draft/i.test(q(P?.description))),xt=bt?[]:nt;e(()=>{J.current=C},[C]);let St=n(()=>{let e=y.find(e=>e.id===C);if(!e)return null;let t=x[e.id];return Ue(e,{...t||{session:null,draft:null,clarification:{status:`none`},planPreview:null,planningConversation:null,planningChangeSummary:[],plannerDiagnostics:null,publishedTasks:[]},clarification:C===e.id?Ee:t?.clarification||{status:`none`}})},[Ee,x,y,C]),Ct=n(()=>y.map(e=>Ue(e,x[e.id])),[x,y]),wt=a(e=>{let t=J.current;t&&t!==e&&he(f,t,A),w(e),oe(!1)},[A,f]),Tt=a(e=>{let t=J.current;if(!t)return;let{session:n,...r}=e;S(e=>({...e,[t]:{...We(),...e[t]||{},session:n?{...e[t]?.session||{},...n||{}}:e[t]?.session||null,...r}}))},[]),Q=e=>{if(e){E(e.goal),O(e.workspaceRoot||ot||h||``),se(e.notes),ce(e.plannerProvider||_.defaultProvider||``),le(e.plannerModel||_.defaultModel||``),ue(e.plan),I(e.conversation),R(e.changeSummary||[]),z(e.plannerError||``),B(e.plannerDiagnostics||null),G(e.publishedAtMs?`Last published ${new Date(e.publishedAtMs).toLocaleString()}`:``),Ie(e.publishedAtMs||null),K(e.updatedAtMs||e.publishedAtMs||null),Qe(e.publishedTasks||[]),U({status:`none`});return}E(``),j(``),O(ot||h||``),se(``),ce(_.defaultProvider||``),le(_.defaultModel||``),ue(null),I(null),R([]),z(``),B(null),U({status:`none`}),G(``),K(null),Ie(null),Qe([]),j(``)},Et=a(e=>{if(!e)return null;let t=e?.draft||null,n=t?.current_plan||t?.currentPlan||null;return{goal:q(e?.goal||n?.title||``),workspaceRoot:q(e?.workspace_root||e?.workspaceRoot||``),notes:q(e?.notes||``),plannerProvider:q(e?.planner_provider||e?.plannerProvider||``),plannerModel:q(e?.planner_model||e?.plannerModel||``),plan:n,conversation:t?.conversation||null,changeSummary:[],plannerError:``,plannerDiagnostics:t?.planner_diagnostics||t?.plannerDiagnostics||null,publishedAtMs:Number(e?.published_at_ms||e?.publishedAtMs||0)||null,updatedAtMs:Number(e?.updated_at_ms||e?.updatedAtMs||0)||Date.now(),publishedTasks:Array.isArray(e?.published_tasks||e?.publishedTasks)?e?.published_tasks||e?.publishedTasks:[]}},[ot,_.defaultModel,_.defaultProvider,h]),Dt=a(async()=>{if(!t?.workflowPlannerSessions?.list)return[];let e=await t.workflowPlannerSessions.list({project_slug:f}),n=Array.isArray(e?.sessions)?e.sessions:[];return b(n.map(Ve).filter(e=>e.id).sort((e,t)=>t.updatedAtMs-e.updatedAtMs)),n},[t?.workflowPlannerSessions?.list,f]),$=a(async e=>{if(!t?.workflowPlannerSessions?.get||!e)return;let n=(await t.workflowPlannerSessions.get(e))?.session||null;if(!n)return;let r=Et(n);Q(r),j(me(f,e)),G(n.published_at_ms?`Last published ${new Date(n.published_at_ms).toLocaleString()}`:``),Ie(Number(n.published_at_ms||0)||null),K(Number(n.updated_at_ms||0)||null),S(t=>({...t,[e]:{session:n,draft:r,clarification:t[e]?.clarification||{status:`none`},planPreview:t[e]?.planPreview||null,planningConversation:t[e]?.planningConversation||null,planningChangeSummary:t[e]?.planningChangeSummary||[],plannerDiagnostics:t[e]?.plannerDiagnostics||null,publishedTasks:t[e]?.publishedTasks||r?.publishedTasks||[]}})),b(e=>{let t=e.filter(e=>e.id!==n.session_id);return t.unshift(He(n)),t.sort((e,t)=>t.updatedAtMs-e.updatedAtMs)})},[t?.workflowPlannerSessions?.get,Et,f]),Ot=a(async e=>{if(!(!C||!t?.workflowPlannerSessions?.patch))try{let n=e,r=(await t.workflowPlannerSessions.patch(C,n))?.session;r?.session_id&&(b(e=>{let t=e.filter(e=>e.id!==r.session_id);return t.unshift(He(r)),t.sort((e,t)=>t.updatedAtMs-e.updatedAtMs)}),S(e=>({...e,[r.session_id]:{...e[r.session_id]||{session:null,draft:null,clarification:{status:`none`},planPreview:null,planningConversation:null,planningChangeSummary:[],plannerDiagnostics:null,publishedTasks:[]},session:r,draft:n.draft?n.draft:e[r.session_id]?.draft||null,publishedTasks:Array.isArray(n.published_tasks||n.publishedTasks)?n.published_tasks||n.publishedTasks:e[r.session_id]?.publishedTasks||[]}})))}catch{}},[t?.workflowPlannerSessions?.patch,C]);e(()=>{let e=!1;return we(!0),(async()=>{try{let e=await Dt(),t=de(f),n=J.current,r=!!n&&e.some(e=>q(e?.session_id||e?.sessionId)===n),i=!!t&&e.some(e=>q(e?.session_id||e?.sessionId)===t),a=r?n:i?t:q(e[0]?.session_id||e[0]?.sessionId||``);a&&a!==n?w(a):a||(w(``),pe(f))}catch{}finally{e||we(!1)}})(),()=>{e=!0}},[t?.workflowPlannerSessions,Dt,f]),e(()=>{if(!C){Q(null),j(``);return}fe(f,C);let e=!1;return we(!0),(async()=>{try{if(await $(C),e)return}catch{e||Q(null)}finally{e||we(!1)}})(),()=>{e=!0}},[$,f,C]),e(()=>{if(!C)return;let e=!1;return we(!0),(async()=>{try{await $(C)}catch{Q(null)}finally{e||we(!1)}})(),()=>{e=!0}},[C,$,ot,h,_.defaultProvider,_.defaultModel]),e(()=>{if(!(typeof sessionStorage>`u`))try{let e=sessionStorage.getItem(Le);if(!e)return;sessionStorage.removeItem(Le);let n=JSON.parse(e);if(!t?.workflowPlannerSessions?.create)return;(async()=>{let e=(await t.workflowPlannerSessions.create({project_slug:f,title:Be({goal:n?.goal,plan:n?.plan,fallbackTime:Date.now()}),workspace_root:q(n?.workspaceRoot||n?.workspace_root||h),goal:q(n?.goal),notes:q(n?.notes),planner_provider:q(n?.plannerProvider||n?.planner_provider),planner_model:q(n?.plannerModel||n?.planner_model),plan_source:`coding_task_planning`,plan:n?.plan??null,conversation:n?.conversation??null,planner_diagnostics:n?.plannerDiagnostics??null,plan_revision:n?.plan?.plan_revision??1,last_success_materialization:n?.lastSuccessMaterialization??null,allowed_mcp_servers:Array.isArray(n?.allowedMcpServers)?n.allowedMcpServers:g,operator_preferences:n?.operatorPreferences??null}))?.session;e?.session_id&&(b(t=>[He(e),...t.filter(t=>t.id!==e.session_id)].sort((e,t)=>t.updatedAtMs-e.updatedAtMs)),w(e.session_id),Q(Et(e)),G(`Planner handoff loaded from Planner page.`))})()}catch{}},[t?.workflowPlannerSessions?.create,g,Et,f,h]),e(()=>{!D&&ot&&O(ot)},[ot,D]),e(()=>{z(``),B(null),W(``)},[M,N]),e(()=>{if(V||!C)return;let e=P||null,t=q(e?.plan_id||``),n=e&&e.plan_id?{initial_plan:e,current_plan:e,plan_revision:Number(e.plan_revision||1)||1,conversation:F||{conversation_id:`wfchat-${C}`,plan_id:e.plan_id,created_at_ms:Date.now(),updated_at_ms:Date.now(),messages:[]},planner_diagnostics:ye,last_success_materialization:null}:void 0;Ot({title:Be({goal:T,plan:e,fallbackTime:Pe||Date.now()}),workspace_root:D,goal:T,notes:k,planner_provider:M,planner_model:N,plan_source:`coding_task_planning`,allowed_mcp_servers:g,operator_preferences:Xe({plannerProvider:M,plannerModel:N,defaultProvider:_.defaultProvider,defaultModel:_.defaultModel,selectedProjectSlug:f,taskSourceType:m,selectedProject:p,goal:T,notes:k}),current_plan_id:t||void 0,draft:n,published_at_ms:Fe||void 0,published_tasks:Ze.length?Ze:void 0})},[g,T,Pe,V,k,P,ye,_e,L,F,Ze,Fe,f,C,m,N,M,Ot,D,_.defaultProvider,_.defaultModel,p]);let kt=async()=>{if(t?.workflowPlannerSessions?.create)try{J.current&&he(f,J.current,A);let e=J.current?``:A,n=(await t.workflowPlannerSessions.create({project_slug:f,title:Be({goal:``,fallbackTime:Date.now()}),workspace_root:ot||h||D||``,goal:``,notes:``,planner_provider:M,planner_model:N,plan_source:`coding_task_planning`,allowed_mcp_servers:g,operator_preferences:Xe({plannerProvider:M,plannerModel:N,defaultProvider:_.defaultProvider,defaultModel:_.defaultModel,selectedProjectSlug:f,taskSourceType:m,selectedProject:p,goal:``,notes:``})}))?.session;n?.session_id&&(b(e=>[He(n),...e.filter(e=>e.id!==n.session_id)].sort((e,t)=>t.updatedAtMs-e.updatedAtMs)),ge(f,n.session_id),wt(n.session_id),Q(Et(n)),j(e||me(f,n.session_id)),d(`ok`,`Started a new planner session.`))}catch(e){d(`err`,e instanceof Error?e.message:String(e))}},At=async e=>{let n=y.find(t=>t.id===e);!n||!t?.workflowPlannerSessions?.patch||Oe({sessionId:e,value:n.title||`Untitled plan`})},jt=async()=>{let e=De;if(!e||!t?.workflowPlannerSessions?.patch)return;let n=q(e.value);if(!n){d(`warn`,`Enter a session name.`);return}try{let r=(await t.workflowPlannerSessions.patch(e.sessionId,{title:n}))?.session;r?.session_id&&(b(e=>e.filter(e=>e.id!==r.session_id).concat(He(r)).sort((e,t)=>t.updatedAtMs-e.updatedAtMs)),S(e=>({...e,[r.session_id]:{...e[r.session_id]||{session:null,draft:null,clarification:{status:`none`},planPreview:null,planningConversation:null,planningChangeSummary:[],plannerDiagnostics:null,publishedTasks:[]},session:r}})),J.current===e.sessionId&&wt(r.session_id)),Oe(null),d(`ok`,`Planner session renamed.`)}catch(e){d(`err`,e instanceof Error?e.message:String(e))}},Mt=async e=>{let n=y.find(t=>t.id===e);if(!(!n||!t?.workflowPlannerSessions?.duplicate))try{let r=(await t.workflowPlannerSessions.duplicate(e,{title:`Copy of ${n.title||`Untitled plan`}`}))?.session;r?.session_id&&(b(e=>e.filter(e=>e.id!==r.session_id).concat(He(r)).sort((e,t)=>t.updatedAtMs-e.updatedAtMs)),ge(f,r.session_id),wt(r.session_id)),d(`ok`,`Planner session duplicated.`)}catch(e){d(`err`,e instanceof Error?e.message:String(e))}},Nt=async e=>{let t=y.find(t=>t.id===e);t&&Ae({sessionId:e,title:t.title||`Untitled plan`})},Pt=async()=>{let e=ke;if(e)try{await t.workflowPlannerSessions.delete(e.sessionId);let n=y.filter(t=>t.id!==e.sessionId);if(b(n),S(t=>{let n={...t};return delete n[e.sessionId],n}),ge(f,e.sessionId),J.current===e.sessionId){let e=n[0]?.id||``;e?wt(e):kt()}Ae(null),d(`ok`,`Planner session deleted.`)}catch(e){d(`err`,e instanceof Error?e.message:String(e))}},Ft=async e=>{let n=q(e??A??T),r=q(D);if(!n){d(`warn`,`Describe the goal you want to turn into tasks.`);return}if(!r){d(`warn`,`Workspace root is required so the planner can inspect the repo.`);return}if(!r.startsWith(`/`)){d(`warn`,`Workspace root must be an absolute path.`);return}if(!C){d(`warn`,`Start a planner session first.`);return}if(!t?.workflowPlannerSessions?.start){d(`err`,`This control panel build is missing workflow planner support.`);return}W(``),z(``),B(null),E(n);let i=`idle`;H(`generating`);try{let e=await t.workflowPlannerSessions.start(C,{prompt:[`Create a Tandem workflow plan for the repo at ${r} to implement this goal: ${n}`,`Use small ordered implementation steps.`,`Prefer step objectives that mention likely files, modules, or repo areas to inspect or change.`,`If the target or desired outcome is ambiguous, return a clarification question instead of guessing.`,q(p?.repoUrl)?`Repo URL: ${q(p?.repoUrl)}`:``,f?`Selected project: ${f}`:``,k?`User feedback / revision notes:\n${k}`:``].filter(Boolean).join(`
6
+ `),plan_source:`coding_task_planning`,workspace_root:r,allowed_mcp_servers:g,operator_preferences:Xe({plannerProvider:M,plannerModel:N,defaultProvider:_.defaultProvider,defaultModel:_.defaultModel,selectedProjectSlug:f,taskSourceType:m,selectedProject:p,goal:n,notes:k})});ue(e?.plan||null),I(e?.conversation||null),R([]),B(e?.planner_diagnostics||e?.plannerDiagnostics||null);let a=typeof e?.clarifier?.question==`string`?String(e.clarifier.question):``,o=Array.isArray(e?.clarifier?.options)?e.clarifier.options.map(e=>({id:String(e?.id||``),label:String(e?.label||``)})).filter(e=>e.id&&e.label):[];z(a),a&&o.length>0?(U({status:`waiting`,question:a,options:o}),i=`clarifying`):U({status:`none`}),K(Date.now()),Qe([]),W(`Plan synced to session.`),j(``),ge(f,C),Tt({session:e?.session||null,draft:e?.session?Et(e.session):null,clarification:a&&o.length>0?{status:`waiting`,question:a,options:o}:{status:`none`},planPreview:e?.plan||null,planningConversation:e?.conversation||null,planningChangeSummary:[],plannerDiagnostics:e?.planner_diagnostics||e?.plannerDiagnostics||null,publishedTasks:[]}),d(`ok`,typeof e?.clarifier?.question==`string`?`Planner needs clarification before it can draft richer tasks.`:`Planner generated a task draft.`)}catch(e){let t=e instanceof Error?e.message:String(e);if(Re(t)){ue(null),I(null),R([]),z(``),B(null),U({status:`none`}),d(`info`,`The previous planner session expired. Starting a fresh planning chat.`),await Ft(n);return}z(t),U({status:`none`}),W(t.includes(`Request timed out after`)?`The panel timed out before the planner finished. The engine may still be working, so wait a moment before retrying.`:``),d(`err`,t)}finally{H(i)}},It=async e=>{if(!t?.workflowPlannerSessions?.message||!C){d(`warn`,`Generate a plan first before revising it.`);return}let n=q(e??A??k);if(!n){d(`warn`,`Add a message for the planner first.`);return}W(``),z(``),B(null),se(n);let r=`idle`;H(`revising`);try{let e=await t.workflowPlannerSessions.message(C,{message:ht?n:[`Revise the workflow plan for repo ${q(D)}.`,`Goal: ${q(T)}`,f?`Selected project: ${f}`:``,`Keep the workflow valid and machine-parseable.`,`Prefer concrete repo-aware implementation steps.`,`If the request is ambiguous, return a clarification question.`,``,`Revision notes:`,n].filter(Boolean).join(`
7
+ `)});ue(e?.plan||null),I(e?.conversation||null),R(Array.isArray(e?.change_summary)?e.change_summary.map(e=>q(e)).filter(Boolean):[]),B(e?.planner_diagnostics||e?.plannerDiagnostics||null);let i=typeof e?.clarifier?.question==`string`?String(e.clarifier.question):``,a=Array.isArray(e?.clarifier?.options)?e.clarifier.options.map(e=>({id:String(e?.id||``),label:String(e?.label||``)})).filter(e=>e.id&&e.label):[];z(i),i&&a.length>0?(U({status:`waiting`,question:i,options:a}),r=`clarifying`):U({status:`none`}),K(Date.now()),Qe([]),W(`Revision synced to session.`),j(``),ge(f,C),Tt({session:e?.session||null,draft:e?.session?Et(e.session):null,clarification:i&&a.length>0?{status:`waiting`,question:i,options:a}:{status:`none`},planPreview:e?.plan||null,planningConversation:e?.conversation||null,planningChangeSummary:Array.isArray(e?.change_summary)?e.change_summary.map(e=>q(e)).filter(Boolean):[],plannerDiagnostics:e?.planner_diagnostics||e?.plannerDiagnostics||null,publishedTasks:[]}),d(`ok`,`Plan revised.`)}catch(e){let t=e instanceof Error?e.message:String(e);if(Re(t)){ue(null),I(null),R([]),z(``),B(null),U({status:`none`}),d(`info`,`The previous planner session expired. Starting a fresh planning chat.`),await Ft(n);return}z(t),U({status:`none`}),W(t.includes(`Request timed out after`)?`The panel timed out before the planner revision finished. The engine may still be working, so wait a moment before retrying.`:``),d(`err`,t)}finally{H(r)}},Lt=async()=>{if(!t?.workflowPlannerSessions?.reset||!C){E(``),j(``),se(``),ue(null),I(null),R([]),z(``),B(null),U({status:`none`}),G(``),Ie(null),K(null),W(`Draft cleared.`);return}Ce(!0);try{let e=await t.workflowPlannerSessions.reset(C);ue(e?.plan||null),I(e?.conversation||null),j(``),R([]),z(``),B(e?.planner_diagnostics||e?.plannerDiagnostics||null),Qe([]),G(``),Ie(null),W(`Plan reset.`),K(Date.now()),ge(f,C),Tt({session:e?.session?{...e.session,published_at_ms:null}:null,draft:e?.session?Et(e.session):null,clarification:{status:`none`},planPreview:e?.plan||null,planningConversation:e?.conversation||null,planningChangeSummary:[],plannerDiagnostics:e?.planner_diagnostics||e?.plannerDiagnostics||null,publishedTasks:[]}),d(`ok`,`Plan reset.`)}catch(e){let t=e instanceof Error?e.message:String(e);if(Re(t)){E(``),j(``),se(``),ue(null),I(null),R([]),z(``),B(null),U({status:`none`}),G(``),Ie(null),K(null),W(`The expired planner session was cleared locally.`),d(`info`,`The previous planner session had expired, so the local draft was reset.`);return}z(t),d(`err`,t)}finally{Ce(!1)}},Rt=async()=>{let e=nt.length?nt:T.trim()?[{id:`task-1`,title:T.trim(),objective:T.trim(),kind:`task`,dependsOn:[],inputRefs:[],outputContract:``}]:[];if(!e.length){d(`warn`,`Generate a plan before publishing tasks.`);return}xe(!0),G(``);try{if(rt&&Y){let n=p?.taskSource||{},r=q(n.owner),i=q(n.repo),a=Number(n.project),o=ee,s=Ne(o);if((!s.statusFieldId||!s.optionId)&&q(f))try{o=await u(`/api/aca/projects/${encodeURIComponent(f)}/board?refresh=true`),s=Ne(o)}catch{}let c=[];for(let n=0;n<e.length;n+=1){let o=e[n],l=Je(P,o,n,{goal:T,workspaceRoot:D,projectSlug:f,taskSourceType:m,selectedProject:p,notes:k,plannerProvider:M,plannerModel:N}),u=Ke(await t.executeTool(`mcp.github.issue_write`,{method:`create`,owner:r,repo:i,title:o.title,body:l,labels:[`tandem`,`planned-task`,`todo`]}));if(!u)throw Error(`Created GitHub issue for "${o.title}" but could not determine the issue number from the engine response.`);let d=qe(await t.executeTool(`mcp.github.projects_write`,{method:`add_project_item`,owner:r,project_number:a,item_type:`issue`,item_owner:r,item_repo:i,issue_number:u}));d&&s.statusFieldId&&s.optionId&&await t.executeTool(`mcp.github.projects_write`,{method:`update_project_item`,owner:r,project_number:a,item_id:d,updated_field:{id:s.statusFieldId,value:s.optionId}}),c.push({title:o.title,issueNumber:u,issueUrl:`https://github.com/${r}/${i}/issues/${u}`,publishedAtMs:Date.now()})}let l=Date.now();Qe(c),G(`Published ${c.length} GitHub tasks${s.label?` into ${s.label}`:``}.`),Ie(l),K(l),Tt({session:{published_at_ms:l,published_tasks:c},publishedTasks:c}),await Promise.all([v.invalidateQueries({queryKey:[`coding-workflows`,`aca-project-board`,f]}),v.invalidateQueries({queryKey:[`coding-workflows`,`aca-project-tasks`,f]}),v.invalidateQueries({queryKey:[`coding-workflows`,`aca-projects`]})]),d(`ok`,`Published ${c.length} task(s) to the GitHub Project.`)}else{let t=Ye(P,e,{goal:T,workspaceRoot:D,projectSlug:f,notes:k,plannerProvider:M,plannerModel:N}),n=Date.now();Qe(e.map(e=>({title:e.title,publishedAtMs:n}))),G(`Saved a local task bundle. Use the exported markdown to update your kanban file.`),Ie(n),K(n),Tt({session:{published_at_ms:n,published_tasks:e},publishedTasks:e.map(e=>({title:e.title,publishedAtMs:n}))}),navigator.clipboard?.writeText&&await navigator.clipboard.writeText(t),d(`ok`,`Saved a local task bundle. The plan markdown has been copied to your clipboard.`)}}catch(e){let t=e instanceof Error?e.message:String(e);G(t),d(`err`,t)}finally{xe(!1)}},zt=n(()=>Ye(P,nt,{goal:T,workspaceRoot:D,projectSlug:f,notes:k,plannerProvider:M,plannerModel:N}),[T,k,P,nt,N,M,f,D]),Bt=rt?`GitHub Project task planning`:`Local kanban task planning`,Vt=!!P||!!ye||L.length>0||Array.isArray(F?.messages)&&F.messages.length>0;return e(()=>{ne.current&&l(ne.current)},[Ee.status,xt.length,Vt,pt,_e,P,L.length,F,Ct.length,C,ae,Me,je]),c(ve,{rootRef:ne,session:{plannerSessions:y,selectedSessionId:C,sessionsOpen:ae,plannerSessionSummaries:Ct,activePlannerSessionSummary:St,plannerTitle:Bt},planner:{goal:T,workspaceRoot:D,notes:k,plannerInput:A,plannerProvider:M,plannerModel:N,planPreview:P,planningConversation:F,planningChangeSummary:L,plannerError:_e,plannerDiagnostics:ye,publishing:be,resetting:Se,clarification:Ee,saveStatus:je,publishStatus:Me,lastSavedAtMs:Pe,publishedAtMs:Fe,publishedTasks:Ze,plannerChatMessages:X,plannerInputPlaceholder:yt,plannerStatusTitle:Z,plannerStatusDetail:vt,exportMarkdown:zt,plannerFallbackReason:mt,hasPlannerResponse:Vt,displayTasks:xt},status:{isGitHubProject:rt,taskSourceType:m,engineHealthy:te,plannerCanUseLlm:ut,hasExplicitPlannerOverride:ct,hasBasePlannerModel:st,plannerSelectionMatchesWorkspaceDefault:lt,resolvedWorkspaceRoot:ot,canPublishToGitHub:Y,plannerTimedOut:_t,clarificationNeeded:ht,planIsFallbackOnly:bt,isPlanning:pt},provider:{providerOptions:it,providerStatus:_,selectedProjectSlug:f,selectedProject:p,githubProjectBoardSnapshot:ee,connectedMcpServers:g},actions:{activatePlannerSession:wt,createNewPlannerSession:kt,renamePlannerSession:At,duplicatePlannerSession:Mt,deletePlannerSession:Nt,setSessionsOpen:oe,previewMutation:Ft,reviseMutation:It,resetMutation:Lt,patchActivePlannerSession:Ot,setPlannerInput:j,setGoal:E,setWorkspaceRoot:O,setNotes:se,setPlannerProvider:ce,setPlannerModel:le,setPlannerError:z,setPlannerDiagnostics:B,setClarification:U,setSaveStatus:W,publishTasks:Rt,plannerOperatorPreferences:Xe,plannerSessionTitle:Be},dialogs:{renameSessionDialog:De,deleteSessionDialog:ke,confirmRenamePlannerSession:jt,confirmDeletePlannerSession:Pt,setRenameSessionDialog:Oe,setDeleteSessionDialog:Ae}})}function Qe({api:r,client:a,toast:l,providerStatus:u,navigate:m}){let v=o(),[re,y]=i(`overview`),[b,x]=i(``),[S,C]=i(``),[w,ae]=i(``),[oe,T]=i(``),[E,D]=i(``),[O,k]=i(``),[se,A]=i(``),[j,M]=i(``),[ce,N]=i(`main`),[P,ue]=i(`origin`),[F,I]=i(``),[L,de]=i(`github_project`),[fe,pe]=i(``),[R,me]=i(``),[he,ge]=i(``),[_e,ve]=i(``),[V,Ee]=i(``),[De,je]=i(``),[W,Ne]=i(!1),[Le,q]=i(!1),[Re,ze]=i(``),[Be,Ve]=i(``),[He,Ue]=i(null),[We,Ge]=i(null),[Ke,qe]=i(!1),[Je,Ye]=i(null),[Xe,Qe]=i(!1),[J,$e]=i(!1),[et,tt]=i([]),[nt,rt]=i({}),[it,at]=i(!1),ot=ee(),Y=ot.data?.aca_integration===!0,st=ot.data?.engine_healthy===!0,ct=ot.data?.hosted_managed===!0,lt=Y||st,ut=s({queryKey:[`coding-workflows`,`health`],queryFn:()=>r(`/api/system/health`),refetchInterval:15e3}),dt=s({queryKey:[`coding-workflows`,`aca-health`],queryFn:()=>r(`/api/aca/health`),enabled:Y}),ft=s({queryKey:[`coding-workflows`,`aca-overview`],queryFn:()=>r(`/api/aca/overview`),enabled:Y,refetchInterval:Y?3e4:!1}),pt=s({queryKey:[`coding-workflows`,`aca-projects`],queryFn:()=>r(`/api/aca/projects`),enabled:Y}),mt=s({queryKey:[`coding-workflows`,`aca-workspace-guide`],queryFn:()=>r(`/api/aca/workspace/guide`),enabled:Y}),ht=s({queryKey:[`coding-workflows`,`aca-runs`],queryFn:()=>r(`/api/aca/runs`),enabled:Y}),gt=s({queryKey:[`coding-workflows`,`coder-runs`],queryFn:()=>r(`/api/aca/operator/coder-runs`),enabled:Y,refetchInterval:Y?15e3:!1}),_t=s({queryKey:[`coding-workflows`,`aca-project-tasks`,b],queryFn:()=>r(`/api/aca/projects/${encodeURIComponent(b)}/tasks`),enabled:Y&&!!b}),X=s({queryKey:[`coding-workflows`,`aca-project-board`,b],queryFn:()=>r(`/api/aca/projects/${encodeURIComponent(b)}/board`),enabled:Y&&!!b&&be(pt.data).some(e=>e.slug===b&&String(e?.taskSource?.type||``).trim()===`github_project`),refetchInterval:Y&&b&&be(pt.data).some(e=>e.slug===b&&String(e?.taskSource?.type||``).trim()===`github_project`)?12e4:!1}),Z=s({queryKey:[`coding-workflows`,`aca-run-detail`,S],queryFn:()=>r(`/api/aca/runs/${encodeURIComponent(S)}`),enabled:Y&&!!S}),vt=s({queryKey:[`coding-workflows`,`aca-run-logs`,S],queryFn:()=>r(`/api/aca/runs/${encodeURIComponent(S)}/logs`),enabled:Y&&!!S}),yt=s({queryKey:[`coding-workflows`,`aca-run-log-tail`,S,w],queryFn:()=>r(`/api/aca/runs/${encodeURIComponent(S)}/logs/${encodeURIComponent(w)}?tail=120`),enabled:Y&&!!S&&!!w}),bt=s({queryKey:[`coding-workflows`,`mcp-servers`],queryFn:()=>a.mcp.list().catch(()=>({})),refetchInterval:lt?1e4:!1,enabled:lt}),xt=s({queryKey:[`coding-workflows`,`mcp-tools`],queryFn:()=>a.mcp.listTools().catch(()=>[]),refetchInterval:lt?15e3:!1,enabled:lt}),St=s({queryKey:[`coding-workflows`,`providers`,`catalog`],queryFn:()=>a.providers.catalog().catch(()=>({all:[]})),refetchInterval:lt?3e4:!1,enabled:lt}),Ct=s({queryKey:[`coding-workflows`,`providers`,`config`],queryFn:()=>a.providers.config().catch(()=>({})),refetchInterval:lt?3e4:!1,enabled:lt}),wt=n(()=>ye(bt.data),[bt.data]),Tt=n(()=>B(xt.data),[xt.data]),Q=n(()=>be(pt.data),[pt.data]),Et=n(()=>z(ht.data,`runs`),[ht.data]),Dt=n(()=>z(gt.data,`coder_runs`),[gt.data]),$=n(()=>xe(X.data),[X.data]),Ot=n(()=>ie({providerCatalog:St.data,providerConfig:Ct.data,defaultProvider:u.defaultProvider,defaultModel:u.defaultModel}),[u.defaultModel,u.defaultProvider,St.data,Ct.data]),kt=n(()=>Pe(O),[O]);e(()=>{Q.length&&(!b||!Q.some(e=>e.slug===b))&&x(Q[0].slug)},[Q,b]);let At=n(()=>b?Et.filter(e=>String(e?.project_slug||``).trim()===b):Et,[Et,b]),jt=n(()=>G(At),[At]),Mt=n(()=>jt.filter(Oe),[jt]);e(()=>{if(!jt.length){C(``);return}let e=Mt.map((e,t)=>Se(e,t)),t=jt.some((e,t)=>Se(e,t)===S),n=e.includes(S);if(e.length&&(!S||!n)){C(e[0]);return}(!S||!t)&&C(Se(jt[0],0))},[Mt,S,jt]);let Nt=n(()=>z(vt.data,`logs`),[vt.data]);e(()=>{if(!Nt.length){ae(``);return}(!w||!Nt.some(e=>String(e?.name||``)===w))&&ae(String(Nt[0]?.name||``))},[Nt,w]);let Pt=!!(ut.data?.engine?.ready||ut.data?.engine?.healthy),Ft=wt.some(e=>e.name.toLowerCase().includes(`github`)),It=Q.find(e=>e.slug===b)||null,Lt=It?.repo||{},Rt=String(It?.taskSource?.type||``).trim(),zt=String(ut.data?.workspaceRoot||ut.data?.workspace_root||(Rt===`kanban_board`||Rt===`local_backlog`)&&It?.taskSource?.path||``).trim(),Bt=wt.filter(e=>e.connected).map(e=>e.name),Vt=n(()=>$.items.filter(e=>et.includes(String(e.id||``))),[$.items,et]),Ht=n(()=>$.items.filter(e=>Me(e)),[$.items]),Ut=n(()=>new Set(Object.keys(nt)),[nt]),Wt=u.defaultProvider&&u.defaultModel?`ACA default (${u.defaultProvider} / ${u.defaultModel})`:`ACA default`,Gt=(e=!1)=>c(`div`,{className:`grid gap-2`,children:[c(te,{providerLabel:`ACA provider`,modelLabel:`ACA model`,draft:{provider:V,model:De},providers:Ot,onChange:({provider:e,model:t})=>{Ee(e),je(t)},inheritLabel:Wt,disabled:e}),c(`div`,{className:`tcp-subtle text-xs`,children:`Leave blank to inherit the base ACA provider and model for this run.`})]}),Kt=n(()=>new Set(Mt.map((e,t)=>ke(e,t)).map(e=>String(e||``).trim()).filter(Boolean)),[Mt]),qt=jt.find((e,t)=>Se(e,t)===S)||null,Jt=String(Z.data?.summary||``).trim(),Yt=Z.data?.blackboard||null;e(()=>{Ve(``)},[S]),e(()=>{if(!Y)return;let e=ne(`/api/aca/events`,e=>{let t=Ie(String(e?.data||``));if(!t||t.event_type===`ping`)return;ze(String(t.event_type||`event`).trim()),v.invalidateQueries({queryKey:[`coding-workflows`,`aca-runs`]}),v.invalidateQueries({queryKey:[`coding-workflows`,`coder-runs`]}),v.invalidateQueries({queryKey:[`coding-workflows`,`aca-overview`]}),v.invalidateQueries({queryKey:[`coding-workflows`,`aca-projects`]}),b&&(v.invalidateQueries({queryKey:[`coding-workflows`,`aca-project-board`,b]}),v.invalidateQueries({queryKey:[`coding-workflows`,`aca-project-tasks`,b]}));let n=String(t?.payload?.run_id||t?.payload?.event?.run_id||``).trim();S&&n&&n===S&&v.invalidateQueries({queryKey:[`coding-workflows`,`aca-run-detail`,S]})});return()=>e()},[Y,v,b,S]),e(()=>{if(!Y||!S||!qt?.is_running)return;let e=ne(`/api/aca/runs/${encodeURIComponent(S)}/events`,e=>{let t=Ie(String(e?.data||``));!t||t.event_type===`ping`||(Ve(String(t.event_type||`event`).trim()),v.invalidateQueries({queryKey:[`coding-workflows`,`aca-runs`]}),v.invalidateQueries({queryKey:[`coding-workflows`,`coder-runs`]}),v.invalidateQueries({queryKey:[`coding-workflows`,`aca-run-detail`,S]}),v.invalidateQueries({queryKey:[`coding-workflows`,`aca-run-logs`,S]}),w&&v.invalidateQueries({queryKey:[`coding-workflows`,`aca-run-log-tail`,S,w]}))});return()=>e()},[Y,v,w,qt?.is_running,S]),e(()=>{_t.data&&Ue(Date.now())},[_t.data]),e(()=>{X.data&&Ge(Number(X.data?.last_synced_at_ms||Date.now()))},[X.data]),e(()=>{tt([])},[b]),e(()=>{rt({})},[b]),e(()=>{let e=Object.entries(nt);if(!e.length)return;let t=e.map(([e,t])=>{let n=Date.now()-Number(t||0),r=Math.max(0,U-n);return window.setTimeout(()=>{rt(t=>{if(!t[e])return t;let n={...t};return delete n[e],n})},r)});return()=>{t.forEach(e=>window.clearTimeout(e))}},[nt]),e(()=>{!Object.keys(nt).length||!$.items.length||rt(e=>{let t=!1,n={...e};return $.items.forEach(e=>{let r=String(e?.id||``).trim();!r||n[r]===void 0||Kt.has(Ae(e))&&(delete n[r],t=!0)}),t?n:e})},[Kt,$.items,nt]),e(()=>{let e=new Set($.items.map(e=>String(e.id||``)));tt(t=>t.filter(t=>e.has(t)))},[$.items]);let Xt=[{id:`overview`,label:`Overview`,icon:`layout-dashboard`},{id:`board`,label:`Intake`,icon:`list-checks`},{id:`planning`,label:`Planning`,icon:`clipboard-list`},{id:`manual`,label:`Manual tasks`,icon:`code`},{id:`integrations`,label:`Integrations`,icon:`plug-zap`}];async function Zt(e){let t=String(e||``).trim();if(t)try{await r(`/api/aca/operator/coder-runs/${encodeURIComponent(t)}/reconcile`,{method:`POST`}),await v.invalidateQueries({queryKey:[`coding-workflows`,`coder-runs`]}),await v.invalidateQueries({queryKey:[`coding-workflows`,`aca-runs`]}),l(`ok`,`Reconciled coder run ${t}.`)}catch(e){l(`err`,e instanceof Error?e.message:String(e))}}async function Qt(e){let t=String(e||``).trim();if(t&&window.confirm(`Cancel coder run ${t}?`))try{await r(`/api/aca/operator/coder-runs/${encodeURIComponent(t)}/cancel`,{method:`POST`,body:JSON.stringify({reason:`cancelled from Tandem Control Panel Coder view`})}),await v.invalidateQueries({queryKey:[`coding-workflows`,`coder-runs`]}),await v.invalidateQueries({queryKey:[`coding-workflows`,`aca-runs`]}),l(`ok`,`Cancelled coder run ${t}.`)}catch(e){l(`err`,e instanceof Error?e.message:String(e))}}async function $t(){let e=Pe(O),t=oe.trim()||L===`github_project`&&e?.slug||``,n=E.trim(),i=O.trim(),a=se.trim(),o=j.trim(),s=ce.trim(),c=P.trim(),u=F.trim();if(L===`github_project`&&!e){l(`warn`,`Paste a GitHub repository URL like https://github.com/owner/repo.`);return}if(!t){l(`warn`,`Project slug is required.`);return}if(a&&!Fe(a)||o&&!Fe(o)){l(`warn`,`Repo paths must stay within the managed workspace root.`);return}let d=K(L,{prompt:fe,path:R,repoRef:e,projectNumber:he});if(d.type===`manual`&&!d.prompt){l(`warn`,`Manual task source requires a prompt.`);return}if([`kanban_board`,`local_backlog`].includes(d.type)&&!d.path){l(`warn`,`This task source requires a path.`);return}if(d.type===`github_project`&&(!d.owner||!d.repo||!d.project)){l(`warn`,`GitHub Project task sources require a repo URL and project number.`);return}Ne(!0);try{let e=new URLSearchParams({slug:t});i&&e.set(`repo_url`,i),n&&e.set(`name`,n),a&&e.set(`repo_path`,a),o&&e.set(`worktree_root`,o),s&&e.set(`default_branch`,s),c&&e.set(`remote_name`,c),u&&e.set(`credential_file`,u),await r(`/api/aca/projects?${e.toString()}`,{method:`POST`,body:JSON.stringify(d)}),await v.invalidateQueries({queryKey:[`coding-workflows`,`aca-projects`]}),await v.invalidateQueries({queryKey:[`coding-workflows`,`aca-workspace-guide`]}),x(t),T(``),D(``),k(``),A(``),M(``),N(`main`),ue(`origin`),I(``),l(`ok`,`Registered ACA project ${t}.`)}catch(e){l(`err`,e instanceof Error?e.message:String(e))}finally{Ne(!1)}}async function en(){if(!b){l(`warn`,`Select a project before triggering a run.`);return}let e={};V.trim()&&(e.ACA_PROVIDER=V.trim()),De.trim()&&(e.ACA_MODEL=De.trim()),q(!0);try{let t=new URLSearchParams({project_slug:b});_e.trim()&&t.set(`item`,_e.trim());let n=await r(`/api/aca/runs/trigger?${t.toString()}`,{method:`POST`,body:JSON.stringify(e)});await v.invalidateQueries({queryKey:[`coding-workflows`,`aca-runs`]});let i=String(n?.run_id||``).trim();i&&(C(i),y(`board`)),l(`ok`,`ACA run started${i?`: ${i}`:`.`}`)}catch(e){l(`err`,e instanceof Error?e.message:String(e))}finally{q(!1)}}function tn(e){tt(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e])}function nn(){tt($.items.filter(e=>Me(e)&&!Kt.has(Ae(e))&&!Ut.has(String(e.id||``))).map(e=>String(e.id||``)))}function rn(){tt([])}async function an(e){if(!b){l(`warn`,`Select a project before starting ACA runs.`);return}let t=e.filter(e=>Me(e)&&!Kt.has(Ae(e))&&!Ut.has(String(e.id||``))),n=t.map(e=>String(e?.selector||``).trim()).filter(Boolean);if(!n.length){l(`warn`,`Those GitHub items are already running or are not launchable from ACA intake.`);return}let i={};V.trim()&&(i.ACA_PROVIDER=V.trim()),De.trim()&&(i.ACA_MODEL=De.trim()),rt(e=>{let n={...e},r=Date.now();return t.forEach(e=>{let t=String(e?.id||``).trim();t&&(n[t]=r)}),n}),at(!0);try{let e=await r(`/api/aca/runs/trigger-batch`,{method:`POST`,body:JSON.stringify({project_slug:b,items:n,overrides:i})});await v.invalidateQueries({queryKey:[`coding-workflows`,`aca-runs`]});let t=z(e,`runs`),a=String(t?.[0]?.run_id||``).trim();a&&(C(a),y(`board`)),l(`ok`,`Started ${n.length} ACA run${n.length===1?``:`s`}.`),tt([])}catch(e){rt(e=>{let n={...e};return t.forEach(e=>{let t=String(e?.id||``).trim();t&&delete n[t]}),n}),l(`err`,e instanceof Error?e.message:String(e))}finally{at(!1)}}async function on(){if(!b){l(`warn`,`Select a project before refreshing GitHub intake.`);return}try{await _t.refetch(),Ue(Date.now()),l(`ok`,`Refreshed task intake from GitHub MCP.`)}catch(e){l(`err`,e instanceof Error?e.message:String(e))}}async function sn(){if(!b){l(`warn`,`Select a GitHub-backed project before refreshing the board.`);return}try{let e=await r(`/api/aca/projects/${encodeURIComponent(b)}/board?refresh=true`);v.setQueryData([`coding-workflows`,`aca-project-board`,b],e),Ge(Number(e?.last_synced_at_ms||Date.now())),l(`ok`,`Refreshed GitHub Project items through Tandem MCP.`)}catch(e){l(`err`,e instanceof Error?e.message:String(e))}}async function cn(){if(!b){l(`warn`,`Select a project before syncing its repository.`);return}qe(!0),Ye(null);try{let e=await r(`/api/aca/projects/${encodeURIComponent(b)}/repo/sync`,{method:`POST`});Ye(e),await v.invalidateQueries({queryKey:[`coding-workflows`,`aca-projects`]}),await v.invalidateQueries({queryKey:[`coding-workflows`,`aca-workspace-guide`]}),await v.invalidateQueries({queryKey:[`coding-workflows`,`aca-project-tasks`,b]}),l(`ok`,`Repository ready at ${String(e?.repo?.path||`managed checkout`)}.`)}catch(e){l(`err`,e instanceof Error?e.message:String(e))}finally{qe(!1)}}return Y?c(f,{className:`grid gap-4`,children:[c(g,{className:`overflow-hidden`,children:c(`div`,{className:`grid gap-5 xl:grid-cols-[minmax(0,1.3fr)_minmax(320px,0.9fr)] xl:items-start`,children:[c(`div`,{className:`min-w-0`,children:[c(`div`,{className:`tcp-page-eyebrow`,children:`Coder`}),c(`h1`,{className:`tcp-page-title`,children:`Coder project intake and run dashboard`}),c(`p`,{className:`tcp-subtle mt-2 max-w-3xl`,children:`This view talks to the ACA control plane for project registration, task preview, durable coder runs, live logs, and final handoff artifacts.`}),c(`div`,{className:`mt-3 flex flex-wrap gap-2`,children:[c(d,{tone:dt.data?.status===`healthy`?`ok`:`warn`,children:dt.data?.status===`healthy`?`ACA healthy`:`ACA checking`}),c(d,{tone:Pt?`ok`:`warn`,children:Pt?`Engine healthy`:`Engine checking`}),c(d,{tone:Ft?`ok`:`warn`,children:Ft?`GitHub MCP connected`:`GitHub MCP pending`}),c(h,{tone:Mt.length?`live`:`info`,text:`${Mt.length} active runs`}),Re?c(d,{tone:`ghost`,children:[`Live `,H(Re)]}):null]})]}),c(`div`,{className:`grid gap-3 rounded-2xl border border-white/10 bg-black/20 p-3`,children:[c(`div`,{className:`flex flex-wrap items-center justify-between gap-2`,children:[c(`div`,{className:`min-w-0`,children:[c(`div`,{className:`text-sm font-semibold text-slate-100`,children:`Repository`}),c(`div`,{className:`tcp-subtle mt-1 truncate text-xs`,children:b?String(Lt?.path||Lt?.clone_url||It?.repo_url||b):`Select a project to sync its checkout.`})]}),c(`button`,{type:`button`,className:`tcp-btn h-8 px-3 text-xs`,onClick:cn,disabled:!b||Ke,children:[c(`i`,{"data-lucide":Ke?`loader-circle`:`refresh-cw`}),Ke?`Syncing`:`Sync repo`]})]}),c(`div`,{className:`grid gap-2 text-xs`,children:[c(`div`,{className:`flex flex-wrap gap-2`,children:[c(d,{tone:Lt?.clone_url?`ok`:`ghost`,children:Lt?.clone_url?`remote git`:`local git`}),c(d,{tone:`ghost`,children:String(Lt?.default_branch||`main`)}),Je?.repo?.dirty?c(d,{tone:`warn`,children:`dirty`}):null]}),Je?.repo?.commit?c(`div`,{className:`grid gap-2`,children:[c(`div`,{className:`tcp-subtle truncate`,children:[`Ready at `,String(Je.repo.path),` ·`,` `,String(Je.repo.commit).slice(0,7)]}),c(`div`,{className:`rounded-xl border border-sky-500/20 bg-sky-500/10 p-2 text-sky-100`,children:`Bug Monitor should use this checkout as its local directory when reporting issues for this repo.`})]}):null]})]})]})}),c(`div`,{className:`tcp-settings-tabs`,children:Xt.map(e=>c(`button`,{type:`button`,className:`tcp-settings-tab tcp-settings-tab-underline ${re===e.id?`active`:``}`,onClick:()=>y(e.id),children:[c(`i`,{"data-lucide":e.icon}),e.label]},e.id))}),re===`overview`?c(le,{projects:Q,selectedProjectSlug:b,setSelectedProjectSlug:x,selectedProject:It,acaOverview:ft,projectTasksQuery:_t,refreshTaskPreview:on,taskPreviewRefreshAt:He,coderRuns:Dt,coderRunsQuery:gt,reconcileCoderRun:Zt,cancelCoderRun:Qt,visibleRunsCount:At.length,activeRunsCount:Mt.length,connectedMcpServersCount:wt.length,registeredToolsCount:Tt.length}):null,re===`board`?c(`div`,{className:`grid gap-4`,children:c(`div`,{className:`grid gap-4`,children:[c(g,{title:`GitHub Project intake`,subtitle:`GitHub items ACA can launch`,children:[c(`div`,{className:`mb-4`,children:c(`select`,{className:`tcp-input`,value:b,onChange:e=>x(e.target.value),children:[Q.length?null:c(`option`,{value:``,children:`No ACA projects found`}),Q.map(e=>c(`option`,{value:e.slug,children:e.name?`${e.name} · ${e.slug}`:e.slug},e.slug))]})}),String(It?.taskSource?.type||``).trim()===`github_project`?X.isLoading?c(`div`,{className:`tcp-subtle text-sm`,children:`Loading GitHub Project items...`}):X.isError?c(`div`,{className:`rounded-2xl border border-red-500/20 bg-red-500/10 p-4 text-sm text-red-200`,children:X.error instanceof Error?X.error.message:`Could not load the GitHub Project items.`}):c(`div`,{className:`grid gap-3`,children:[c(`div`,{className:`flex flex-wrap items-center justify-between gap-3 rounded-2xl border border-white/10 bg-black/20 p-3`,children:[c(`div`,{className:`tcp-subtle text-xs`,children:[`Items are listed by ACA launchability with direct run controls.`,We?` Last synced ${new Date(We).toLocaleTimeString()}.`:``]}),c(`div`,{className:`flex flex-wrap items-center gap-2`,children:[c(d,{tone:$.isStale?`warn`:`ok`,children:$.isStale?`Cached snapshot`:H($.source||`live`)}),c(`button`,{type:`button`,className:`tcp-btn tcp-btn-secondary`,onClick:sn,disabled:X.isFetching,children:X.isFetching?`Refreshing...`:`Refresh from GitHub`})]})]}),c(`div`,{className:`flex flex-wrap items-center justify-between gap-3 rounded-2xl border border-cyan-500/20 bg-cyan-500/10 p-3`,children:[c(`div`,{className:`tcp-subtle text-xs`,children:`Select GitHub items here to start ACA runs directly from the board. This creates one ACA run per selected item and starts them immediately.`}),c(`div`,{className:`min-w-[320px] flex-1`,children:Gt(it)}),c(`div`,{className:`flex flex-wrap gap-2`,children:[c(`button`,{type:`button`,className:`tcp-btn tcp-btn-secondary`,onClick:nn,disabled:!Ht.length||it,children:`Select actionable`}),c(`button`,{type:`button`,className:`tcp-btn tcp-btn-secondary`,onClick:rn,disabled:!et.length||it,children:`Clear selection`}),c(`button`,{type:`button`,className:`tcp-btn-primary`,onClick:()=>an(Vt),disabled:!Vt.length||it,children:it?`Starting...`:`Run selected${Vt.length?` (${Vt.length})`:``}`})]})]}),$.warning?c(`div`,{className:`rounded-2xl border border-yellow-500/20 bg-yellow-500/10 p-4 text-sm text-yellow-100`,children:$.warning}):null,$.items.length?c(`div`,{className:`grid gap-3`,children:$.items.map(e=>{let t=Me(e),n=String(e.id||``),r=t&&Kt.has(Ae(e)),i=Ut.has(n),a=r||i||it;return c(`div`,{className:`rounded-2xl border px-4 py-3 transition ${et.includes(n)?`border-cyan-400/60 bg-cyan-500/10`:`border-white/10 bg-black/20`}`,children:[c(`div`,{className:`flex flex-wrap items-start justify-between gap-3`,children:[c(`div`,{className:`flex min-w-0 flex-1 items-start gap-3`,children:[c(`input`,{type:`checkbox`,className:`mt-1 h-4 w-4 shrink-0`,checked:et.includes(n),disabled:!t||a,onChange:()=>tn(n)}),c(`div`,{className:`min-w-0`,children:[c(`div`,{className:`break-words text-sm font-semibold leading-5`,children:String(e.title||`Untitled item`)}),c(`div`,{className:`tcp-subtle mt-1 break-words text-xs leading-5`,children:[e.repoName?String(e.repoName):b,e.issueNumber?` #${String(e.issueNumber)}`:``]})]})]}),c(`div`,{className:`flex shrink-0 flex-wrap items-center gap-2`,children:[e.actionable?c(d,{tone:`ok`,children:`Actionable`}):null,c(d,{tone:`ghost`,children:H(String(e.statusName||e.statusKey||`Unknown`))}),r?c(d,{tone:`info`,children:`Run active`}):null,i&&!r?c(d,{tone:`warn`,children:`Starting`}):null]})]}),c(`div`,{className:`mt-3 flex flex-wrap gap-2 pl-7`,children:[e.issueUrl?c(`a`,{className:`tcp-btn h-8 px-3 text-xs`,href:e.issueUrl,target:`_blank`,rel:`noreferrer`,children:`Open in GitHub`}):null,c(`button`,{type:`button`,className:`tcp-btn h-8 px-3 text-xs`,onClick:()=>an([e]),disabled:!t||a,children:t?r?`Already running`:i?`Starting...`:`Run task`:`Not launchable`})]})]},n)})}):c(p,{text:`No GitHub Project items returned for this project.`})]}):c(p,{text:`The selected project is not backed by a GitHub Project task source.`})]}),c(g,{title:`ACA execution history`,subtitle:`Recent runs for the selected project`,children:jt.length?c(`div`,{className:`grid gap-2`,children:jt.map((e,t)=>{let n=Se(e,t);return c(`button`,{type:`button`,className:`rounded-2xl border px-3 py-3 text-left transition ${n===S?`border-cyan-400/60 bg-cyan-500/10`:`border-white/10 bg-black/20 hover:border-white/20`}`,onClick:()=>C(n),children:[c(`div`,{className:`flex flex-wrap items-start justify-between gap-3`,children:[c(`div`,{className:`min-w-0`,children:[c(`div`,{className:`truncate text-sm font-semibold`,children:Ce(e)}),c(`div`,{className:`tcp-subtle mt-1 text-xs`,children:[String(e?.project_slug||`unknown`),e?.branch?` · ${String(e.branch)}`:``]})]}),c(`div`,{className:`flex flex-wrap gap-2`,children:[c(d,{tone:Oe(e)?`info`:`ok`,children:H(we(e))}),Te(e)?c(d,{tone:`ghost`,children:H(Te(e))}):null]})]}),c(`div`,{className:`tcp-subtle mt-2 text-xs`,children:n})]},n)})}):c(p,{text:`No ACA runs for this project yet.`})}),c(g,{title:`Run detail`,subtitle:S?`ACA detail for ${S}`:`Select a run`,actions:c(`button`,{type:`button`,className:`tcp-btn h-8 px-3 text-xs`,onClick:()=>Qe(e=>!e),children:[c(`i`,{"data-lucide":Xe?`chevron-down`:`chevron-right`}),Xe?`Collapse`:`Expand`]}),children:Xe?S?Z.isLoading?c(`div`,{className:`tcp-subtle text-sm`,children:`Loading run detail...`}):Z.isError?c(`div`,{className:`rounded-2xl border border-red-500/20 bg-red-500/10 p-4 text-sm text-red-200`,children:Z.error instanceof Error?Z.error.message:`Could not load run detail.`}):c(`div`,{className:`grid gap-3`,children:[c(`div`,{className:`rounded-2xl border border-white/10 bg-black/20 p-4`,children:[c(`div`,{className:`flex items-start justify-between gap-3`,children:[c(`div`,{className:`min-w-0`,children:[c(`div`,{className:`text-sm font-semibold`,children:String(Z.data?.status?.task?.title||qt?.title||S)}),c(`div`,{className:`tcp-subtle mt-1 text-xs`,children:String(Z.data?.project_slug||qt?.project_slug||`unknown`)})]}),c(d,{tone:Z.data?.is_running?`info`:`ok`,children:H(String(Z.data?.status?.run?.status||qt?.status||`unknown`))})]}),c(`div`,{className:`mt-3 flex flex-wrap gap-2`,children:[Z.data?.status?.phase?.name?c(d,{tone:`info`,children:[`Phase `,H(String(Z.data.status.phase.name))]}):null,Be?c(d,{tone:`ghost`,children:[`Latest `,H(Be)]}):null,Z.data?.snapshot?.summary_available?c(d,{tone:`ok`,children:`Summary ready`}):null,Z.data?.error?c(d,{tone:`warn`,children:`Has error`}):null]})]}),Jt?c(`div`,{className:`rounded-2xl border border-white/10 bg-black/20 p-4`,children:[c(`div`,{className:`mb-2 text-sm font-semibold`,children:`Summary`}),c(`pre`,{className:`max-h-56 overflow-auto whitespace-pre-wrap text-xs leading-6 text-slate-200`,children:Jt})]}):null,c(`div`,{className:`rounded-2xl border border-white/10 bg-black/20 p-4`,children:[c(`div`,{className:`mb-2 text-sm font-semibold`,children:`Blackboard`}),c(_,{value:Yt||{},label:`Show blackboard`,preClassName:`max-h-72 overflow-auto whitespace-pre-wrap text-xs leading-6 text-slate-200`})]})]}):c(p,{text:`Select a run from the board to inspect its status, summary, and blackboard.`}):null}),c(g,{title:`Live logs`,subtitle:`Tail ACA worker and manager logs`,actions:c(`button`,{type:`button`,className:`tcp-btn h-8 px-3 text-xs`,onClick:()=>$e(e=>!e),children:[c(`i`,{"data-lucide":J?`chevron-down`:`chevron-right`}),J?`Collapse`:`Expand`]}),children:J?S?c(`div`,{className:`grid gap-3`,children:[Nt.length?c(`select`,{className:`tcp-input`,value:w,onChange:e=>ae(e.target.value),children:Nt.map(e=>c(`option`,{value:String(e?.name||``),children:String(e?.name||``)},String(e?.name||``)))}):c(`div`,{className:`tcp-subtle text-sm`,children:`No logs available yet.`}),w&&yt.data?.lines?c(`pre`,{className:`max-h-80 overflow-auto rounded-2xl border border-white/10 bg-black/30 p-4 text-xs leading-6 text-slate-200`,children:z(yt.data,`lines`).join(`
8
+ `)}):null]}):c(p,{text:`Choose a run to inspect log output.`}):null})]})}):null,re===`manual`?c(`div`,{className:`grid gap-4`,children:c(`div`,{className:`grid gap-4 xl:grid-cols-2`,children:[c(g,{title:`Register project`,subtitle:`Bind a repository, managed checkout, and task source into ACA`,children:c(`div`,{className:`grid gap-3`,children:[L===`github_project`?c(t,{children:[c(`input`,{className:`tcp-input`,placeholder:`GitHub repo URL, e.g. https://github.com/frumu-ai/tandem`,value:O,onInput:e=>k(e.target.value)}),c(`div`,{className:`rounded-2xl border border-cyan-500/20 bg-cyan-500/10 px-3 py-2 text-xs text-cyan-100`,children:kt?`Detected ${kt.owner}/${kt.repo}. ACA will use this for the GitHub Project owner/repo binding.`:`Paste a GitHub repository URL and ACA will derive the owner, repo, and default project slug.`})]}):c(`input`,{className:`tcp-input`,placeholder:`Repo URL (optional)`,value:O,onInput:e=>k(e.target.value)}),ct?c(t,{children:[c(`input`,{className:`tcp-input`,placeholder:`Managed checkout path, e.g. repos/team-alpha`,value:se,onInput:e=>A(e.target.value)}),c(`input`,{className:`tcp-input`,placeholder:`Worktree root (optional)`,value:j,onInput:e=>M(e.target.value)}),c(`div`,{className:`grid gap-3 md:grid-cols-2`,children:[c(`input`,{className:`tcp-input`,placeholder:`Default branch (optional)`,value:ce,onInput:e=>N(e.target.value)}),c(`input`,{className:`tcp-input`,placeholder:`Remote name (optional)`,value:P,onInput:e=>ue(e.target.value)})]}),c(`input`,{className:`tcp-input`,placeholder:`Token file for private repos (optional)`,value:F,onInput:e=>I(e.target.value)})]}):null,ct?c(`div`,{className:`rounded-2xl border border-lime-500/20 bg-lime-500/10 px-3 py-2 text-xs text-lime-100`,children:`Hosted installs can use these fields to register named repos and managed checkout directories without exposing an interactive shell.`}):null,c(`input`,{className:`tcp-input`,placeholder:L===`github_project`?`Project slug (optional, defaults to owner/repo)`:`Project slug`,value:oe,onInput:e=>T(e.target.value)}),c(`input`,{className:`tcp-input`,placeholder:`Project display name (optional)`,value:E,onInput:e=>D(e.target.value)}),c(`select`,{className:`tcp-input`,value:L,onChange:e=>de(e.target.value),children:[c(`option`,{value:`manual`,children:`Manual prompt`}),c(`option`,{value:`kanban_board`,children:`Kanban board`}),c(`option`,{value:`local_backlog`,children:`Local backlog`}),c(`option`,{value:`github_project`,children:`GitHub Project`})]}),L===`manual`?c(`textarea`,{className:`tcp-input min-h-[120px]`,placeholder:`Manual task prompt`,value:fe,onInput:e=>pe(e.target.value)}):null,L===`kanban_board`||L===`local_backlog`?c(`input`,{className:`tcp-input`,placeholder:`Absolute file path`,value:R,onInput:e=>me(e.target.value)}):null,L===`github_project`?c(t,{children:[c(`input`,{className:`tcp-input`,placeholder:`GitHub Project number`,value:he,onInput:e=>ge(e.target.value)}),c(`div`,{className:`tcp-subtle text-xs`,children:`Only GitHub Project board tasks are imported. Public issues that are not on this project board remain outside ACA intake.`})]}):null,c(`button`,{type:`button`,className:`tcp-btn`,disabled:W,onClick:$t,children:W?`Registering...`:`Register Project`})]})}),c(g,{title:`Trigger run`,subtitle:`Launch an ACA coding session for the selected project`,children:c(`div`,{className:`grid gap-3`,children:[c(`select`,{className:`tcp-input`,value:b,onChange:e=>x(e.target.value),children:[Q.length?null:c(`option`,{value:``,children:`No ACA projects found`}),Q.map(e=>c(`option`,{value:e.slug,children:e.slug},e.slug))]}),c(`input`,{className:`tcp-input`,placeholder:`Specific item or card id (optional)`,value:_e,onInput:e=>ve(e.target.value)}),Gt(Le),c(`button`,{type:`button`,className:`tcp-btn-primary`,disabled:Le,onClick:en,children:Le?`Starting...`:`Trigger ACA Run`})]})})]})}):null,re===`planning`?c(Ze,{client:a,api:r,toast:l,selectedProjectSlug:b,selectedProject:It,githubProjectBoardSnapshot:X.data||null,taskSourceType:Rt,workspaceRootSeed:zt,connectedMcpServers:Bt,engineHealthy:Pt,providerStatus:u}):null,re===`integrations`?c(`div`,{className:`grid gap-4 xl:grid-cols-2`,children:[c(g,{title:`ACA connection`,subtitle:`Control-plane endpoint the coding page uses`,children:c(`div`,{className:`grid gap-3`,children:[c(`div`,{className:`rounded-2xl border border-white/10 bg-black/20 p-4`,children:[c(`div`,{className:`text-sm font-semibold`,children:`Health`}),c(`div`,{className:`tcp-subtle mt-1 text-xs`,children:[dt.data?.status||`Unavailable`,dt.data?.version?` · ${String(dt.data.version)}`:``]})]}),c(`div`,{className:`rounded-2xl border border-white/10 bg-black/20 p-4`,children:[c(`div`,{className:`text-sm font-semibold`,children:`Projects`}),c(`div`,{className:`tcp-subtle mt-1 text-xs`,children:[Q.length,` registered`]})]}),c(`div`,{className:`rounded-2xl border border-white/10 bg-black/20 p-4`,children:[c(`div`,{className:`text-sm font-semibold`,children:`Runs`}),c(`div`,{className:`tcp-subtle mt-1 text-xs`,children:[Et.length,` visible through ACA`]})]})]})}),c(g,{title:`Workspace guide`,subtitle:`What the agent should inspect first`,children:mt.data?c(`div`,{className:`grid gap-3`,children:[c(`div`,{className:`rounded-2xl border border-white/10 bg-black/20 p-4`,children:[c(`div`,{className:`text-sm font-semibold`,children:`Active project`}),c(`div`,{className:`tcp-subtle mt-1 text-xs`,children:[String(mt.data?.active_project?.name||`None`).trim(),mt.data?.active_project?.repo?.path?` · ${String(mt.data.active_project.repo.path)}`:``]})]}),c(`div`,{className:`rounded-2xl border border-white/10 bg-black/20 p-4`,children:[c(`div`,{className:`text-sm font-semibold`,children:`Layout`}),c(`div`,{className:`tcp-subtle mt-1 text-xs`,children:String(mt.data?.layout?.worktree_root||`managed root`)})]}),c(`ul`,{className:`grid gap-2 text-xs text-slate-200`,children:(Array.isArray(mt.data?.instructions)?mt.data.instructions:[]).map((e,t)=>c(`li`,{className:`rounded-xl border border-white/10 bg-black/10 px-3 py-2`,children:e},`${t}-${e}`))})]}):c(p,{text:`Workspace guide unavailable yet.`})}),c(g,{title:`Connected MCP servers`,subtitle:`Engine integrations still available alongside ACA`,children:wt.length?c(`div`,{className:`grid gap-2`,children:wt.map(e=>c(`div`,{className:`flex items-center justify-between gap-3 rounded-2xl border border-white/10 bg-black/20 px-3 py-2`,children:[c(`div`,{className:`min-w-0`,children:[c(`div`,{className:`truncate text-sm font-semibold`,children:e.name}),c(`div`,{className:`tcp-subtle text-xs`,children:[e.transport||`transport pending`,e.lastError?` · ${e.lastError}`:``]})]}),c(d,{tone:e.connected?`ok`:e.enabled?`warn`:`ghost`,children:e.connected?`Connected`:e.enabled?`Configured`:`Disabled`})]},e.name))}):c(p,{text:`No MCP servers detected yet.`})})]}):null]}):c(f,{className:`grid gap-4`,children:c(g,{className:`overflow-hidden`,children:c(`div`,{className:`grid gap-5 xl:grid-cols-[minmax(0,1.3fr)_minmax(320px,0.9fr)] xl:items-start`,children:c(`div`,{className:`min-w-0`,children:[c(`div`,{className:`tcp-page-eyebrow`,children:`Coder`}),c(`h1`,{className:`tcp-page-title`,children:`Coder dashboard`}),c(`p`,{className:`tcp-subtle mt-2 max-w-3xl`,children:`ACA integration is required for Coder. Connect the ACA control plane so this workspace can load registered projects, task intake, and live run details.`}),c(`div`,{className:`mt-3 flex flex-wrap gap-2`,children:[c(d,{tone:st?`ok`:`warn`,children:st?`Engine healthy`:`Engine unavailable`}),c(d,{tone:`warn`,children:`ACA disconnected`})]}),c(`div`,{className:`mt-4 rounded-2xl border border-yellow-500/20 bg-yellow-500/10 p-4`,children:[c(`p`,{className:`text-sm text-yellow-200`,children:[c(`strong`,{children:`ACA integration required.`})," Set `ACA_BASE_URL` and make sure the control panel can authenticate to ACA with `ACA_API_TOKEN` or `ACA_API_TOKEN_FILE`."]}),c(`button`,{type:`button`,className:`tcp-btn mt-3`,onClick:()=>m(`settings`),children:`Open ACA setup`})]})]})})})})}export{Qe as CodingWorkflowsPage};
@@ -0,0 +1 @@
1
+ import{C as e,E as t,h as n}from"./fullcalendar-Bn75j0xM.js";import{i as r,n as i,r as a}from"./motion-B3ZE8SGR.js";import{a as o}from"./index-TvymvGva.js";function s(t){let r=n(null);return e(()=>{t&&r.current&&o(r.current)},[t]),r}function c({open:t,title:n,message:o,widthClassName:c=`w-[min(34rem,96vw)]`,onCancel:l,children:u,actions:d}){let f=s(t);return e(()=>{if(!t||typeof window>`u`)return;let e=e=>{e.key===`Escape`&&(e.preventDefault(),l())};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[t,l]),r(a,{children:t?r(i.div,{className:`tcp-confirm-overlay`,initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},onClick:l,children:r(i.div,{ref:f,className:`tcp-confirm-dialog ${c}`.trim(),initial:{opacity:0,y:8,scale:.98},animate:{opacity:1,y:0,scale:1},exit:{opacity:0,y:6,scale:.98},onClick:e=>e.stopPropagation(),children:[r(`h3`,{className:`tcp-confirm-title`,children:n}),o?r(`div`,{className:`tcp-confirm-message`,children:o}):null,u,d?r(`div`,{className:`tcp-confirm-actions mt-3`,children:d}):null]})}):null})}function l({open:e,title:n,message:i,confirmLabel:a=`Confirm`,cancelLabel:o=`Cancel`,confirmIcon:s=`check`,confirmTone:l=`danger`,confirmDisabled:u=!1,widthClassName:d,onCancel:f,onConfirm:p}){return r(c,{open:e,title:n,message:i,widthClassName:d,onCancel:f,actions:r(t,{children:[r(`button`,{type:`button`,className:`tcp-btn`,onClick:f,children:[r(`i`,{"data-lucide":`x`}),o]}),r(`button`,{type:`button`,className:l===`danger`?`tcp-btn-danger`:`tcp-btn-primary`,disabled:u,onClick:p,children:[r(`i`,{"data-lucide":s}),a]})]})})}function u({open:i,title:a,message:o,label:s=`Value`,value:l,placeholder:u=``,confirmLabel:d=`Save`,cancelLabel:f=`Cancel`,confirmIcon:p=`check`,confirmTone:m=`primary`,confirmDisabled:h=!1,widthClassName:g,autoFocus:_=!0,inputClassName:v=``,onCancel:y,onChange:b,onConfirm:x}){let S=n(null);return e(()=>{if(!i||!_)return;let e=S.current;e&&window.setTimeout(()=>{e.focus(),e.select()},0)},[_,i]),r(c,{open:i,title:a,message:o,widthClassName:g,onCancel:y,actions:r(t,{children:[r(`button`,{type:`button`,className:`tcp-btn`,onClick:y,children:[r(`i`,{"data-lucide":`x`}),f]}),r(`button`,{type:`button`,className:m===`danger`?`tcp-btn-danger`:`tcp-btn-primary`,disabled:h,onClick:x,children:[r(`i`,{"data-lucide":p}),d]})]}),children:r(`label`,{className:`grid gap-1 text-left`,children:[r(`span`,{className:`text-xs uppercase tracking-wide text-slate-500`,children:s}),r(`input`,{ref:S,className:`tcp-input ${v}`.trim(),value:l,placeholder:u,onChange:e=>b(e.target.value),onKeyDown:e=>{e.key!==`Enter`||h||(e.preventDefault(),x())}})]})})}export{u as n,l as t};
@@ -0,0 +1 @@
1
+ import{g as e,v as t}from"./fullcalendar-Bn75j0xM.js";import{n}from"./react-query-BIbNygEJ.js";import{i as r}from"./motion-B3ZE8SGR.js";import{S as i,T as a,g as o,h as s,m as c,s as l,w as u,x as d,y as f}from"./index-TvymvGva.js";import{n as p}from"./LazyJson-vfWw7G9F.js";import{t as m}from"./format-DyX5imzJ.js";var h=[{label:`24h`,hours:24},{label:`7d`,hours:168},{label:`30d`,hours:720}],g={missing_required_section:`Missing required section`,weak_markdown_structure:`Weak markdown structure`,missing_optional_evidence:`Missing optional evidence`,artifact_word_count_below_minimum:`Word count below minimum`,missing_nonconsumed_workspace_files:`Workspace files missing`,missing_required_artifact_path:`Missing required artifact path`,validator_kind_specific_soft_check:`Validator soft check`,repair_budget_exhausted:`Repair budget exhausted`};function _(e){return g[e]||e.replace(/_/g,` `)}function v(e){return(Number(e.accepted)||0)+(Number(e.rejected)||0)+(Number(e.re_ran_strict)||0)}function y(e){return v(e)+(Number(e.unmarked)||0)}function b(e){let t=v(e);return t===0?null:(Number(e.accepted)||0)/t}function x(e){return e===null?`—`:`${(e*100).toFixed(1)}%`}function S({client:i,automationId:a,className:o=``}){let[s,c]=t(168),l=n({queryKey:[`graduation`,`summary`,s,a||``],enabled:!!i?.automationsV2?.graduationSummary,queryFn:async()=>i?.automationsV2?.graduationSummary?i.automationsV2.graduationSummary({windowHours:s,automationId:a,limit:200}):null,refetchInterval:6e4,staleTime:3e4}),u=l.data||null,d=u?.summary||{},f=d?.by_class||{},p=e(()=>Object.entries(f).map(([e,t])=>({key:e,counts:t,total:y(t),reviewed:v(t),acceptRate:b(t)})).sort((e,t)=>t.reviewed===e.reviewed?t.total-e.total:t.reviewed-e.reviewed),[f]),m=Number(d?.total_outputs_scanned||0),g=Number(d?.total_relaxed_outputs||0),S=Number(u?.scanned_runs||0);return r(`div`,{className:`grid gap-3 ${o}`,children:[r(`div`,{className:`flex flex-wrap items-center justify-between gap-2`,children:[r(`div`,{children:[r(`div`,{className:`text-sm font-medium text-slate-100`,children:`Graduation summary`}),r(`div`,{className:`tcp-subtle text-xs`,children:[`Per-class accept rate over the last`,` `,h.find(e=>e.hours===s)?.label||`${s}h`,`.`]})]}),r(`div`,{className:`flex flex-wrap gap-1`,children:h.map(e=>r(`button`,{type:`button`,className:s===e.hours?`tcp-btn-primary`:`tcp-btn`,onClick:()=>c(e.hours),disabled:l.isFetching,children:e.label},e.hours))})]}),r(`div`,{className:`grid grid-cols-1 gap-2 sm:grid-cols-3`,children:[r(`div`,{className:`rounded-md border border-slate-800/80 bg-slate-950/30 p-2`,children:[r(`div`,{className:`tcp-subtle text-[11px]`,children:`runs scanned`}),r(`div`,{className:`mt-1 font-medium text-slate-100`,children:S})]}),r(`div`,{className:`rounded-md border border-slate-800/80 bg-slate-950/30 p-2`,children:[r(`div`,{className:`tcp-subtle text-[11px]`,children:`node outputs scanned`}),r(`div`,{className:`mt-1 font-medium text-slate-100`,children:m})]}),r(`div`,{className:`rounded-md border border-amber-700/40 bg-amber-950/20 p-2`,children:[r(`div`,{className:`tcp-subtle text-[11px]`,children:`relaxed outputs`}),r(`div`,{className:`mt-1 font-medium text-amber-200`,children:g})]})]}),l.isError?r(`div`,{className:`rounded-md border border-rose-700/40 bg-rose-950/20 p-2 text-xs text-rose-200`,children:`Failed to load graduation summary.`}):null,p.length===0?r(`div`,{className:`rounded-md border border-slate-800/80 bg-slate-950/30 p-3 text-sm text-slate-300`,children:l.isLoading?`Loading…`:m===0?`No automation runs scanned in this window.`:`No relaxed outputs in this window. Strict-only runs do not show up here.`}):r(`div`,{className:`overflow-hidden rounded-md border border-slate-800/80`,children:r(`table`,{className:`w-full text-left text-xs`,children:[r(`thead`,{className:`bg-slate-900/40 text-[11px] uppercase tracking-wide text-slate-400`,children:r(`tr`,{children:[r(`th`,{className:`px-2 py-1.5`,children:`Validator class`}),r(`th`,{className:`px-2 py-1.5 text-right`,children:`Accepted`}),r(`th`,{className:`px-2 py-1.5 text-right`,children:`Rejected`}),r(`th`,{className:`px-2 py-1.5 text-right`,children:`Re-ran Strict`}),r(`th`,{className:`px-2 py-1.5 text-right`,children:`Unmarked`}),r(`th`,{className:`px-2 py-1.5 text-right`,children:`Accept rate`})]})}),r(`tbody`,{children:p.map(e=>{let t=e.reviewed===0?r(`span`,{className:`tcp-subtle italic`,children:`insufficient signal`}):r(`span`,{className:(e.acceptRate??0)>=.8?`font-semibold text-emerald-300`:(e.acceptRate??0)<=.4?`font-semibold text-rose-300`:`font-semibold text-amber-200`,children:x(e.acceptRate)});return r(`tr`,{className:`border-t border-slate-800/60 text-slate-200`,children:[r(`td`,{className:`px-2 py-1.5`,children:[r(`div`,{className:`font-medium`,children:_(e.key)}),r(`code`,{className:`tcp-subtle text-[10px]`,children:e.key})]}),r(`td`,{className:`px-2 py-1.5 text-right`,children:e.counts.accepted||0}),r(`td`,{className:`px-2 py-1.5 text-right`,children:e.counts.rejected||0}),r(`td`,{className:`px-2 py-1.5 text-right`,children:e.counts.re_ran_strict||0}),r(`td`,{className:`px-2 py-1.5 text-right tcp-subtle`,children:e.counts.unmarked||0}),r(`td`,{className:`px-2 py-1.5 text-right`,children:t})]},e.key)})})]})})]})}function C(e,t){return Array.isArray(e)?e:Array.isArray(e?.[t])?e[t]:[]}function w(e){return String(e||``).trim().replace(/([a-z0-9])([A-Z])/g,`$1_$2`).replace(/[\s-]+/g,`_`).toLowerCase()}function T(e){return e.ready?e.defaultProvider===`openai-codex`?e.defaultProviderManagedBy===`codex-upload`?`Imported auth.json on hosted server`:e.defaultProviderManagedBy===`codex-cli`?`Mirrored from local Codex CLI`:e.defaultProviderAuthKind===`oauth`?`Codex account session active`:``:e.defaultProviderAuthKind===`oauth`?`OAuth session active`:e.defaultProviderSource===`env`?`Env-managed credentials`:e.defaultProviderSource===`persisted`?`Stored credentials`:``:``}function E(h){let{api:g,client:_,navigate:v,providerStatus:y}=h,[b,x]=t(``),[E,D]=t(`day`),O=new Set([`workflow`,`bug_monitor_triage`]),k=n({queryKey:[`dashboard`,`health`],queryFn:()=>g(`/api/system/health`),refetchInterval:15e3}),A=n({queryKey:[`dashboard`,`sessions`],queryFn:()=>_.sessions.list({pageSize:8,source:`chat`}).catch(()=>[]),refetchInterval:15e3}),j=n({queryKey:[`dashboard`,`routines`],queryFn:()=>_.routines.list().catch(()=>({routines:[]})),refetchInterval:2e4}),M=n({queryKey:[`dashboard`,`automation-v2-runs`],queryFn:()=>g(`/api/engine/automations/v2/runs?limit=200`).catch(()=>({runs:[]})),refetchInterval:15e3}),N=n({queryKey:[`dashboard`,`swarm`],queryFn:()=>g(`/api/swarm/status`).catch(()=>({status:`unknown`,activeRuns:0})),refetchInterval:6e3}),P=n({queryKey:[`dashboard`,`workflow-context-runs`],queryFn:()=>g(`/api/engine/context/runs?limit=12`).catch(()=>({runs:[]})),refetchInterval:6e3}),F=n({queryKey:[`dashboard`,`workflow-context-run`,b],enabled:!!b,queryFn:()=>g(`/api/engine/context/runs/${encodeURIComponent(b)}`).catch(()=>({run:null}))}),I=n({queryKey:[`dashboard`,`workflow-context-blackboard`,b],enabled:!!b,queryFn:()=>g(`/api/engine/context/runs/${encodeURIComponent(b)}/blackboard`).catch(()=>({blackboard:null}))}),L=C(A.data,`sessions`),R=C(j.data,`routines`),z=C(M.data,`runs`),B=C(P.data,`runs`).filter(e=>O.has(String(e?.run_type||``).trim().toLowerCase())),V=!!(k.data?.engine?.ready||k.data?.engine?.healthy),H=String(N.data?.status||`unknown`),U=[`planning`,`awaiting_approval`,`running`,`executing`].includes(H.toLowerCase()),W=z.filter(e=>[`queued`,`running`,`pausing`,`awaiting_approval`,`blocked`].includes(w(e?.status))),G=z.filter(e=>Number(e?.total_tokens||0)>0),K=z.reduce((e,t)=>({prompt:e.prompt+Number(t?.prompt_tokens||0),completion:e.completion+Number(t?.completion_tokens||0),total:e.total+Number(t?.total_tokens||0)}),{prompt:0,completion:0,total:0}),q=B.filter(e=>[`queued`,`planning`,`running`,`awaiting_approval`].includes(String(e?.status||``).trim().toLowerCase())),J=T(y),Y=e(()=>{let e=new Map,t=Date.now(),n,r,i,a;E===`day`?(n=336*60*60*1e3,r=14,i=e=>e.toISOString().slice(0,10),a=e=>{let[,t,n]=e.split(`-`);return`${t}/${n}`}):E===`week`?(n=1344*60*60*1e3,r=8,i=e=>{let t=new Date(e);return t.setDate(e.getDate()-(e.getDay()+6)%7),t.toISOString().slice(0,10)},a=e=>{let[,t,n]=e.split(`-`);return`w/${t}/${n}`}):(n=4320*60*60*1e3,r=6,i=e=>e.toISOString().slice(0,7),a=e=>{let[t,n]=e.split(`-`);return`${n}/${t.slice(2)}`});let o=t-n;for(let t of z){let n=Number(t?.created_at_ms||t?.updated_at_ms||0);if(!n||n<o)continue;let r=new Date(n),s=i(r),c=e.get(s)??{label:a(s),runs:0,tokens:0};c.runs+=1,c.tokens+=Number(t?.total_tokens||0),e.set(s,c)}let s=[...e.entries()].sort((e,t)=>e[0].localeCompare(t[0])),c=Math.max(1,...s.map(([,e])=>e.tokens));return{buckets:s.map(([,e])=>e),maxTokens:c,bucketCount:r}},[z,E]),X=e(()=>[{label:`Recent sessions`,value:L.length,tone:`info`,helper:`Latest active conversation surfaces`},{label:`Stored runs`,value:z.length,tone:`ok`,helper:`Persisted automation-v2 history`},{label:`Live runs`,value:W.length,tone:W.length?`warn`:`ghost`,helper:`Queued, running, blocked, awaiting approval`},{label:`Tracked tokens`,value:K.total,tone:K.total?`info`:`ghost`,helper:`${G.length} runs with usage`},{label:`Context runs`,value:B.length,tone:q.length?`warn`:`info`,helper:q.length?`${q.length} active`:`Workflow + triage visibility`}],[q.length,z.length,K.total,W.length,L.length,B.length,G.length]);return r(c,{className:`grid gap-4`,children:[r(d,{className:`overflow-hidden`,children:[r(`div`,{className:`grid gap-5 xl:grid-cols-[minmax(0,1.3fr)_minmax(320px,0.9fr)] xl:items-start`,children:r(`div`,{className:`min-w-0`,children:[r(`div`,{className:`tcp-page-eyebrow`,children:`Overview`}),r(`h1`,{className:`tcp-page-title`,children:`Command center`}),r(`p`,{className:`tcp-subtle mt-2 max-w-3xl`,children:`A higher-signal home screen with animated state and a clearer read on what the system is doing right now.`}),r(`div`,{className:`mt-3 flex flex-wrap gap-2`,children:[r(s,{tone:V?`ok`:`warn`,children:V?`Engine healthy`:`Engine checking`}),r(s,{tone:y.ready?`ok`:`warn`,children:y.ready?y.defaultProvider:`Provider setup required`}),J?r(s,{tone:`info`,children:J}):null,U?r(u,{tone:`live`,text:`Swarm ${H}`}):r(s,{tone:`ghost`,children:[`Swarm `,H]})]})]})}),r(`div`,{className:`mt-5`,children:[r(`div`,{className:`dashboard-kpis`,children:X.map(e=>r(`div`,{children:[r(`div`,{className:`flex items-start justify-between gap-3`,children:[r(`span`,{className:`dashboard-kpi-label`,children:e.label}),r(s,{tone:e.tone,children:e.helper})]}),r(`strong`,{children:r(f,{value:e.value,format:e.format??m})})]},e.label))}),r(`p`,{className:`tcp-subtle mt-3 text-xs`,children:`Usage totals are aggregated from stored automation-v2 run history, so they reflect real executions instead of inferred activity.`}),r(`div`,{className:`mt-4 dashboard-bars`,children:[r(`div`,{className:`dashboard-bar-row`,children:[r(`div`,{className:`dashboard-bar-meta`,children:[r(`span`,{children:`Engine readiness`}),r(`span`,{className:`dashboard-bar-count`,children:V?`100%`:`45%`})]}),r(`div`,{className:`dashboard-bar-track`,children:r(`span`,{className:`dashboard-bar-fill completed`,style:{width:V?`100%`:`45%`}})})]}),r(`div`,{className:`dashboard-bar-row`,children:[r(`div`,{className:`dashboard-bar-meta`,children:[r(`span`,{children:`Provider confidence`}),r(`span`,{className:`dashboard-bar-count`,children:y.ready?`100%`:`30%`})]}),r(`div`,{className:`dashboard-bar-track`,children:r(`span`,{className:`dashboard-bar-fill ${y.ready?`running`:`queued`}`,style:{width:y.ready?`100%`:`30%`}})})]}),r(`div`,{className:`dashboard-bar-row`,children:[r(`div`,{className:`dashboard-bar-meta`,children:[r(`span`,{children:`Automation activity`}),r(`span`,{className:`dashboard-bar-count`,children:[W.length,` live`]})]}),r(`div`,{className:`dashboard-bar-track`,children:r(`span`,{className:`dashboard-bar-fill ${W.length?`running`:`manual`}`,style:{width:`${z.length?Math.min(100,Math.max(12,W.length/z.length*100)):12}%`}})})]})]})]})]}),r(d,{children:[r(`div`,{className:`mb-3 flex flex-wrap items-center justify-between gap-2`,children:[r(`div`,{children:[r(`div`,{className:`tcp-page-eyebrow`,children:`Usage`}),r(`h2`,{className:`font-semibold`,children:`Token usage over time`})]}),r(`div`,{className:`flex gap-1`,children:[`day`,`week`,`month`].map(e=>r(`button`,{type:`button`,className:`tcp-btn h-7 px-2 text-xs capitalize ${E===e?`tcp-btn-active`:``}`,onClick:()=>D(e),children:e},e))})]}),Y.buckets.length===0?r(`p`,{className:`tcp-subtle text-xs`,children:`No token data in this window yet.`}):r(`div`,{className:`grid gap-2`,children:Y.buckets.map(e=>r(`div`,{className:`dashboard-bar-row`,children:[r(`div`,{className:`dashboard-bar-meta`,children:[r(`span`,{className:`font-mono text-xs`,children:e.label}),r(`span`,{className:`dashboard-bar-count`,children:[m(e.tokens),` tok`,` · `,r(`span`,{className:`tcp-subtle`,children:[e.runs,` run`,e.runs===1?``:`s`]})]})]}),r(`div`,{className:`dashboard-bar-track`,children:r(`span`,{className:`dashboard-bar-fill ${e.tokens>0?`running`:`manual`}`,style:{width:`${Math.max(4,e.tokens/Y.maxTokens*100)}%`}})})]},e.label))})]}),r(d,{title:`Graduation review`,subtitle:`Per-class accept rate for relaxed Guided/Lenient outputs.`,children:r(S,{client:_})}),r(i,{main:r(d,{title:`Recent sessions`,subtitle:`Latest conversations, ready to reopen.`,children:r(`div`,{className:`grid gap-2`,children:L.length?L.map(e=>r(`button`,{className:`tcp-list-item text-left`,onClick:()=>v(`chat`),children:[r(`div`,{className:`font-medium inline-flex items-center gap-2`,children:[r(`i`,{"data-lucide":`messages-square`}),String(e.title||e.id||`Session`)]}),r(`div`,{className:`tcp-subtle mt-1 text-xs`,children:String(e.id||e.session_id||``)})]},String(e.id||e.session_id||Math.random()))):r(l,{text:`Start a conversation to populate recent sessions here.`})})}),aside:r(`div`,{className:`grid gap-4`,children:[r(d,{title:`Context visibility`,subtitle:`Recent workflow and failure-triage context runs with their current projection state.`,children:[r(a,{className:`mb-3`,children:[r(s,{tone:q.length?`warn`:`info`,children:[B.length,` recent`]}),r(`button`,{className:`tcp-btn`,onClick:()=>v(`orchestrator`),children:[r(`i`,{"data-lucide":`workflow`}),`Open task board`]})]}),r(`div`,{className:`grid gap-2`,children:B.length?B.slice(0,5).map(e=>r(`button`,{className:`tcp-list-item text-left`,onClick:()=>x(String(e?.run_id||``).trim()),children:[r(`div`,{className:`mb-1 flex items-center justify-between gap-2`,children:[r(`div`,{className:`font-medium`,children:String(e?.objective||e?.run_id||`Context run`)}),r(`div`,{className:`flex flex-wrap items-center gap-2`,children:[r(s,{tone:`ghost`,children:String(e?.run_type||`context`)}),r(s,{tone:[`failed`,`cancelled`].includes(String(e?.status||``).toLowerCase())?`err`:[`running`,`queued`,`planning`].includes(String(e?.status||``).toLowerCase())?`warn`:`ok`,children:String(e?.status||`unknown`)})]})]}),r(`div`,{className:`tcp-subtle text-xs`,children:String(e?.run_id||``)}),r(`div`,{className:`tcp-subtle mt-1 text-xs`,children:[Array.isArray(e?.tasks)?e.tasks.length:0,` tasks ·`,` `,Array.isArray(e?.steps)?e.steps.length:0,` steps`]})]},String(e?.run_id||Math.random()))):r(l,{text:`Workflow and failure-triage context runs will appear here once they execute.`})})]}),r(d,{title:`Automation snapshot`,subtitle:`Schedules and run-ready routines.`,children:[r(a,{className:`mb-3`,children:[r(s,{tone:`info`,children:[R.length,` loaded`]}),r(`button`,{className:`tcp-btn`,onClick:()=>v(`automations`),children:[r(`i`,{"data-lucide":`bot`}),`Manage`]})]}),r(`div`,{className:`grid gap-2`,children:R.length?R.slice(0,4).map(e=>r(`div`,{className:`tcp-list-item`,children:[r(`div`,{className:`font-medium`,children:String(e.name||e.id||`Routine`)}),r(`div`,{className:`tcp-subtle mt-1 text-xs`,children:String(e.schedule||e.status||`manual`)})]},String(e.id||e.routine_id||Math.random()))):r(l,{text:`No routines are configured yet.`})})]}),r(d,{title:`Health notes`,subtitle:`Direct links for the next likely action.`,children:r(`div`,{className:`grid gap-2`,children:[r(`div`,{className:`tcp-list-item`,children:[r(`div`,{className:`font-medium inline-flex items-center gap-2`,children:[r(`i`,{"data-lucide":`activity`}),`Engine endpoint`]}),r(`div`,{className:`tcp-subtle mt-1 text-xs`,children:String(k.data?.engineUrl||`Unavailable`)})]}),r(`div`,{className:`tcp-list-item`,children:[r(`div`,{className:`font-medium inline-flex items-center gap-2`,children:[r(`i`,{"data-lucide":`radio`}),`Swarm`]}),r(`div`,{className:`tcp-subtle mt-1 text-xs`,children:[`Status: `,H]})]}),r(`div`,{className:`tcp-list-item`,children:[r(`div`,{className:`font-medium inline-flex items-center gap-2`,children:[r(`i`,{"data-lucide":`database`}),`Memory & runs`]}),r(`div`,{className:`mt-2 flex flex-wrap gap-2`,children:[r(`button`,{className:`tcp-btn h-8 px-3 text-xs`,onClick:()=>v(`memory`),children:`Open memory`}),r(`button`,{className:`tcp-btn h-8 px-3 text-xs`,onClick:()=>v(`runs`),children:`Open runs`})]})]})]})})]})}),r(o,{open:!!b,onClose:()=>x(``),title:b||`Workflow context run`,children:b?r(`div`,{className:`grid gap-3`,children:[r(`div`,{className:`tcp-list-item`,children:[r(`div`,{className:`mb-1 flex items-center justify-between gap-2`,children:[r(`strong`,{children:String(F.data?.run?.objective||b)}),r(s,{tone:`info`,children:String(F.data?.run?.status||`unknown`)})]}),r(`div`,{className:`tcp-subtle text-xs`,children:[`type: `,String(F.data?.run?.run_type||`workflow`)]})]}),r(`div`,{className:`tcp-list-item`,children:[r(`div`,{className:`font-medium mb-2`,children:`Projected blackboard`}),r(`div`,{className:`tcp-subtle text-xs`,children:[`tasks:`,` `,Array.isArray(I.data?.blackboard?.tasks)?I.data.blackboard.tasks.length:0,` · `,`artifacts:`,` `,Array.isArray(I.data?.blackboard?.artifacts)?I.data.blackboard.artifacts.length:0]})]}),r(p,{value:{run:F.data?.run||null,blackboard:I.data?.blackboard||null},label:`Show run + blackboard`})]}):null})]})}export{E as DashboardPage};