commandmate 0.32.1 → 0.33.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (182) hide show
  1. package/.next/BUILD_ID +1 -1
  2. package/.next/app-build-manifest.json +166 -166
  3. package/.next/app-path-routes-manifest.json +36 -36
  4. package/.next/build-manifest.json +2 -2
  5. package/.next/prerender-manifest.json +9 -9
  6. package/.next/required-server-files.json +1 -1
  7. package/.next/server/app/_not-found/page_client-reference-manifest.js +1 -1
  8. package/.next/server/app/api/agents/update/route_client-reference-manifest.js +1 -1
  9. package/.next/server/app/api/agents/versions/route_client-reference-manifest.js +1 -1
  10. package/.next/server/app/api/app/update/route_client-reference-manifest.js +1 -1
  11. package/.next/server/app/api/app/update-check/route_client-reference-manifest.js +1 -1
  12. package/.next/server/app/api/assistant/conversation/route_client-reference-manifest.js +1 -1
  13. package/.next/server/app/api/assistant/current-output/route_client-reference-manifest.js +1 -1
  14. package/.next/server/app/api/assistant/messages/route_client-reference-manifest.js +1 -1
  15. package/.next/server/app/api/assistant/session/route_client-reference-manifest.js +1 -1
  16. package/.next/server/app/api/assistant/start/route_client-reference-manifest.js +1 -1
  17. package/.next/server/app/api/assistant/terminal/route_client-reference-manifest.js +1 -1
  18. package/.next/server/app/api/assistant/tools/route_client-reference-manifest.js +1 -1
  19. package/.next/server/app/api/auth/login/route_client-reference-manifest.js +1 -1
  20. package/.next/server/app/api/auth/logout/route_client-reference-manifest.js +1 -1
  21. package/.next/server/app/api/auth/status/route_client-reference-manifest.js +1 -1
  22. package/.next/server/app/api/capabilities/route_client-reference-manifest.js +1 -1
  23. package/.next/server/app/api/daily-summary/route_client-reference-manifest.js +1 -1
  24. package/.next/server/app/api/daily-summary/status/route_client-reference-manifest.js +1 -1
  25. package/.next/server/app/api/external-apps/[id]/health/route_client-reference-manifest.js +1 -1
  26. package/.next/server/app/api/external-apps/[id]/route_client-reference-manifest.js +1 -1
  27. package/.next/server/app/api/external-apps/route_client-reference-manifest.js +1 -1
  28. package/.next/server/app/api/fs/browse/route_client-reference-manifest.js +1 -1
  29. package/.next/server/app/api/fs/recent-paths/route_client-reference-manifest.js +1 -1
  30. package/.next/server/app/api/hooks/agent-event/route_client-reference-manifest.js +1 -1
  31. package/.next/server/app/api/hooks/claude-done/route_client-reference-manifest.js +1 -1
  32. package/.next/server/app/api/hooks/permission-request/route_client-reference-manifest.js +1 -1
  33. package/.next/server/app/api/metrics/vibe/route_client-reference-manifest.js +1 -1
  34. package/.next/server/app/api/ollama/models/route_client-reference-manifest.js +1 -1
  35. package/.next/server/app/api/push/escalation/route_client-reference-manifest.js +1 -1
  36. package/.next/server/app/api/push/subscriptions/route_client-reference-manifest.js +1 -1
  37. package/.next/server/app/api/push/vapid/route_client-reference-manifest.js +1 -1
  38. package/.next/server/app/api/relays/[relayId]/cancel/route_client-reference-manifest.js +1 -1
  39. package/.next/server/app/api/relays/route_client-reference-manifest.js +1 -1
  40. package/.next/server/app/api/remote/pair/route_client-reference-manifest.js +1 -1
  41. package/.next/server/app/api/repositories/[id]/route_client-reference-manifest.js +1 -1
  42. package/.next/server/app/api/repositories/[id]/todos/[todoId]/route_client-reference-manifest.js +1 -1
  43. package/.next/server/app/api/repositories/[id]/todos/route_client-reference-manifest.js +1 -1
  44. package/.next/server/app/api/repositories/clone/[jobId]/route_client-reference-manifest.js +1 -1
  45. package/.next/server/app/api/repositories/clone/route_client-reference-manifest.js +1 -1
  46. package/.next/server/app/api/repositories/excluded/route_client-reference-manifest.js +1 -1
  47. package/.next/server/app/api/repositories/restore/route_client-reference-manifest.js +1 -1
  48. package/.next/server/app/api/repositories/route_client-reference-manifest.js +1 -1
  49. package/.next/server/app/api/repositories/scan/route_client-reference-manifest.js +1 -1
  50. package/.next/server/app/api/repositories/sync/route_client-reference-manifest.js +1 -1
  51. package/.next/server/app/api/repositories/validate-path/route_client-reference-manifest.js +1 -1
  52. package/.next/server/app/api/settings/default-agents/route_client-reference-manifest.js +1 -1
  53. package/.next/server/app/api/settings/default-surface-mode/route_client-reference-manifest.js +1 -1
  54. package/.next/server/app/api/sidebar/group-order/route_client-reference-manifest.js +1 -1
  55. package/.next/server/app/api/skills/[id]/route_client-reference-manifest.js +1 -1
  56. package/.next/server/app/api/skills/installations/route_client-reference-manifest.js +1 -1
  57. package/.next/server/app/api/skills/operations/route_client-reference-manifest.js +1 -1
  58. package/.next/server/app/api/skills/reindex/route_client-reference-manifest.js +1 -1
  59. package/.next/server/app/api/skills/route_client-reference-manifest.js +1 -1
  60. package/.next/server/app/api/slash-commands/route_client-reference-manifest.js +1 -1
  61. package/.next/server/app/api/tasks/[taskId]/cancel/route_client-reference-manifest.js +1 -1
  62. package/.next/server/app/api/tasks/[taskId]/route_client-reference-manifest.js +1 -1
  63. package/.next/server/app/api/templates/[id]/route_client-reference-manifest.js +1 -1
  64. package/.next/server/app/api/templates/route_client-reference-manifest.js +1 -1
  65. package/.next/server/app/api/todos/route_client-reference-manifest.js +1 -1
  66. package/.next/server/app/api/verification/runs/[runId]/route_client-reference-manifest.js +1 -1
  67. package/.next/server/app/api/verification/runs/route_client-reference-manifest.js +1 -1
  68. package/.next/server/app/api/worktrees/[id]/auto-yes/route_client-reference-manifest.js +1 -1
  69. package/.next/server/app/api/worktrees/[id]/capture/route_client-reference-manifest.js +1 -1
  70. package/.next/server/app/api/worktrees/[id]/clear-composer/route_client-reference-manifest.js +1 -1
  71. package/.next/server/app/api/worktrees/[id]/cli-reference/route_client-reference-manifest.js +1 -1
  72. package/.next/server/app/api/worktrees/[id]/cli-tool/route_client-reference-manifest.js +1 -1
  73. package/.next/server/app/api/worktrees/[id]/cmate/schedules/route_client-reference-manifest.js +1 -1
  74. package/.next/server/app/api/worktrees/[id]/current-output/route_client-reference-manifest.js +1 -1
  75. package/.next/server/app/api/worktrees/[id]/env/route_client-reference-manifest.js +1 -1
  76. package/.next/server/app/api/worktrees/[id]/execution-logs/[logId]/route_client-reference-manifest.js +1 -1
  77. package/.next/server/app/api/worktrees/[id]/execution-logs/route_client-reference-manifest.js +1 -1
  78. package/.next/server/app/api/worktrees/[id]/files/[...path]/route_client-reference-manifest.js +1 -1
  79. package/.next/server/app/api/worktrees/[id]/git/branch/create/route_client-reference-manifest.js +1 -1
  80. package/.next/server/app/api/worktrees/[id]/git/branch/delete/route_client-reference-manifest.js +1 -1
  81. package/.next/server/app/api/worktrees/[id]/git/branches/route_client-reference-manifest.js +1 -1
  82. package/.next/server/app/api/worktrees/[id]/git/checkout/route_client-reference-manifest.js +1 -1
  83. package/.next/server/app/api/worktrees/[id]/git/commit/route_client-reference-manifest.js +1 -1
  84. package/.next/server/app/api/worktrees/[id]/git/diff/route_client-reference-manifest.js +1 -1
  85. package/.next/server/app/api/worktrees/[id]/git/fetch/route_client-reference-manifest.js +1 -1
  86. package/.next/server/app/api/worktrees/[id]/git/log/route_client-reference-manifest.js +1 -1
  87. package/.next/server/app/api/worktrees/[id]/git/pull/route_client-reference-manifest.js +1 -1
  88. package/.next/server/app/api/worktrees/[id]/git/push/route_client-reference-manifest.js +1 -1
  89. package/.next/server/app/api/worktrees/[id]/git/reset/route_client-reference-manifest.js +1 -1
  90. package/.next/server/app/api/worktrees/[id]/git/revert/route_client-reference-manifest.js +1 -1
  91. package/.next/server/app/api/worktrees/[id]/git/show/[commitHash]/route_client-reference-manifest.js +1 -1
  92. package/.next/server/app/api/worktrees/[id]/git/stage/route_client-reference-manifest.js +1 -1
  93. package/.next/server/app/api/worktrees/[id]/git/staged/route_client-reference-manifest.js +1 -1
  94. package/.next/server/app/api/worktrees/[id]/git/stash/[index]/route_client-reference-manifest.js +1 -1
  95. package/.next/server/app/api/worktrees/[id]/git/stash/apply/route_client-reference-manifest.js +1 -1
  96. package/.next/server/app/api/worktrees/[id]/git/stash/pop/route_client-reference-manifest.js +1 -1
  97. package/.next/server/app/api/worktrees/[id]/git/stash/push/route_client-reference-manifest.js +1 -1
  98. package/.next/server/app/api/worktrees/[id]/git/stash/route_client-reference-manifest.js +1 -1
  99. package/.next/server/app/api/worktrees/[id]/git/status/route_client-reference-manifest.js +1 -1
  100. package/.next/server/app/api/worktrees/[id]/git/unstage/route_client-reference-manifest.js +1 -1
  101. package/.next/server/app/api/worktrees/[id]/git/working-diff/route_client-reference-manifest.js +1 -1
  102. package/.next/server/app/api/worktrees/[id]/instances/opencode/route_client-reference-manifest.js +1 -1
  103. package/.next/server/app/api/worktrees/[id]/interrupt/route_client-reference-manifest.js +1 -1
  104. package/.next/server/app/api/worktrees/[id]/kill-session/route_client-reference-manifest.js +1 -1
  105. package/.next/server/app/api/worktrees/[id]/logs/[filename]/route_client-reference-manifest.js +1 -1
  106. package/.next/server/app/api/worktrees/[id]/logs/route_client-reference-manifest.js +1 -1
  107. package/.next/server/app/api/worktrees/[id]/marp-render/route_client-reference-manifest.js +1 -1
  108. package/.next/server/app/api/worktrees/[id]/memos/[memoId]/route_client-reference-manifest.js +1 -1
  109. package/.next/server/app/api/worktrees/[id]/memos/route_client-reference-manifest.js +1 -1
  110. package/.next/server/app/api/worktrees/[id]/messages/route_client-reference-manifest.js +1 -1
  111. package/.next/server/app/api/worktrees/[id]/opencode/diff/route_client-reference-manifest.js +1 -1
  112. package/.next/server/app/api/worktrees/[id]/opencode/session/route_client-reference-manifest.js +1 -1
  113. package/.next/server/app/api/worktrees/[id]/opencode/share/route_client-reference-manifest.js +1 -1
  114. package/.next/server/app/api/worktrees/[id]/prompt-response/route_client-reference-manifest.js +1 -1
  115. package/.next/server/app/api/worktrees/[id]/resolve-target/route_client-reference-manifest.js +1 -1
  116. package/.next/server/app/api/worktrees/[id]/respond/route_client-reference-manifest.js +1 -1
  117. package/.next/server/app/api/worktrees/[id]/route_client-reference-manifest.js +1 -1
  118. package/.next/server/app/api/worktrees/[id]/schedules/[scheduleId]/route_client-reference-manifest.js +1 -1
  119. package/.next/server/app/api/worktrees/[id]/schedules/active/route_client-reference-manifest.js +1 -1
  120. package/.next/server/app/api/worktrees/[id]/schedules/route_client-reference-manifest.js +1 -1
  121. package/.next/server/app/api/worktrees/[id]/search/route_client-reference-manifest.js +1 -1
  122. package/.next/server/app/api/worktrees/[id]/send/route_client-reference-manifest.js +1 -1
  123. package/.next/server/app/api/worktrees/[id]/skills/[skillId]/git-workflow/route_client-reference-manifest.js +1 -1
  124. package/.next/server/app/api/worktrees/[id]/skills/[skillId]/install/route_client-reference-manifest.js +1 -1
  125. package/.next/server/app/api/worktrees/[id]/skills/[skillId]/plan/route_client-reference-manifest.js +1 -1
  126. package/.next/server/app/api/worktrees/[id]/skills/[skillId]/uninstall/route_client-reference-manifest.js +1 -1
  127. package/.next/server/app/api/worktrees/[id]/skills/[skillId]/uninstall-plan/route_client-reference-manifest.js +1 -1
  128. package/.next/server/app/api/worktrees/[id]/skills/[skillId]/update/route_client-reference-manifest.js +1 -1
  129. package/.next/server/app/api/worktrees/[id]/skills/[skillId]/update-plan/route_client-reference-manifest.js +1 -1
  130. package/.next/server/app/api/worktrees/[id]/skills/route_client-reference-manifest.js +1 -1
  131. package/.next/server/app/api/worktrees/[id]/slash-commands/route_client-reference-manifest.js +1 -1
  132. package/.next/server/app/api/worktrees/[id]/special-keys/route_client-reference-manifest.js +1 -1
  133. package/.next/server/app/api/worktrees/[id]/tasks/route_client-reference-manifest.js +1 -1
  134. package/.next/server/app/api/worktrees/[id]/terminal/route_client-reference-manifest.js +1 -1
  135. package/.next/server/app/api/worktrees/[id]/timers/history/route_client-reference-manifest.js +1 -1
  136. package/.next/server/app/api/worktrees/[id]/timers/route_client-reference-manifest.js +1 -1
  137. package/.next/server/app/api/worktrees/[id]/todos/[todoId]/route_client-reference-manifest.js +1 -1
  138. package/.next/server/app/api/worktrees/[id]/todos/route_client-reference-manifest.js +1 -1
  139. package/.next/server/app/api/worktrees/[id]/tree/[...path]/route_client-reference-manifest.js +1 -1
  140. package/.next/server/app/api/worktrees/[id]/tree/route_client-reference-manifest.js +1 -1
  141. package/.next/server/app/api/worktrees/[id]/upload/[...path]/route_client-reference-manifest.js +1 -1
  142. package/.next/server/app/api/worktrees/[id]/verify/config/route_client-reference-manifest.js +1 -1
  143. package/.next/server/app/api/worktrees/[id]/verify/route_client-reference-manifest.js +1 -1
  144. package/.next/server/app/api/worktrees/[id]/verify/runs/[runId]/cancel/route_client-reference-manifest.js +1 -1
  145. package/.next/server/app/api/worktrees/[id]/verify/runs/[runId]/route_client-reference-manifest.js +1 -1
  146. package/.next/server/app/api/worktrees/[id]/verify/runs/route_client-reference-manifest.js +1 -1
  147. package/.next/server/app/api/worktrees/[id]/viewed/route_client-reference-manifest.js +1 -1
  148. package/.next/server/app/api/worktrees/apply-default-agents/route_client-reference-manifest.js +1 -1
  149. package/.next/server/app/api/worktrees/route_client-reference-manifest.js +1 -1
  150. package/.next/server/app/chat/page_client-reference-manifest.js +1 -1
  151. package/.next/server/app/login/page_client-reference-manifest.js +1 -1
  152. package/.next/server/app/manifest.webmanifest/route_client-reference-manifest.js +1 -1
  153. package/.next/server/app/more/page_client-reference-manifest.js +1 -1
  154. package/.next/server/app/offline/page_client-reference-manifest.js +1 -1
  155. package/.next/server/app/page_client-reference-manifest.js +1 -1
  156. package/.next/server/app/proxy/[...path]/route_client-reference-manifest.js +1 -1
  157. package/.next/server/app/repositories/page_client-reference-manifest.js +1 -1
  158. package/.next/server/app/review/page_client-reference-manifest.js +1 -1
  159. package/.next/server/app/sessions/page_client-reference-manifest.js +1 -1
  160. package/.next/server/app/skills/[skillId]/page_client-reference-manifest.js +1 -1
  161. package/.next/server/app/skills/installed/page_client-reference-manifest.js +1 -1
  162. package/.next/server/app/skills/page_client-reference-manifest.js +1 -1
  163. package/.next/server/app/worktrees/[id]/files/[...path]/page_client-reference-manifest.js +1 -1
  164. package/.next/server/app/worktrees/[id]/page.js +11 -11
  165. package/.next/server/app/worktrees/[id]/page_client-reference-manifest.js +1 -1
  166. package/.next/server/app/worktrees/[id]/terminal/page_client-reference-manifest.js +1 -1
  167. package/.next/server/app-paths-manifest.json +36 -36
  168. package/.next/server/chunks/6838.js +1 -1
  169. package/.next/server/chunks/8918.js +4 -4
  170. package/.next/server/middleware-manifest.json +5 -5
  171. package/.next/server/pages/500.html +1 -1
  172. package/.next/server/server-reference-manifest.json +1 -1
  173. package/.next/static/chunks/{4718-9d63107c612a065d.js → 4718-d97f52cd932dc1ee.js} +1 -1
  174. package/.next/static/chunks/app/worktrees/[id]/page-18a7d9374bd8c218.js +1 -0
  175. package/.next/static/css/{96d94a4ba771efc3.css → fb455b4e308adbaa.css} +1 -1
  176. package/.next/trace +13 -13
  177. package/dist/server/src/lib/hooks/sources/codex/transcript.js +88 -6
  178. package/dist/server/src/lib/hooks/sources/turn-body.js +3 -1
  179. package/package.json +1 -1
  180. package/.next/static/chunks/app/worktrees/[id]/page-3d82a9355d5612d9.js +0 -1
  181. /package/.next/static/{Lno4w_zWXdGdlfXg06Vp8 → eVkZd6vpcQwyJIlbymCUg}/_buildManifest.js +0 -0
  182. /package/.next/static/{Lno4w_zWXdGdlfXg06Vp8 → eVkZd6vpcQwyJIlbymCUg}/_ssgManifest.js +0 -0
@@ -1,9 +1,9 @@
1
- "use strict";exports.id=8918,exports.ids=[8918],exports.modules={18201:(a,b,c)=>{c.d(b,{Ce:()=>g,pk:()=>e});let d=(0,c(72626).h)("lib/history/user-turn-recorder");function e(a){return a.replace(/\r\n?/g,"\n").split("\n").map(a=>a.replace(/[ \t ]+$/u,"")).join("\n").trim()}function f(a){return{worktreeId:a.worktreeId,cliToolId:a.cliToolId,instanceId:a.instanceId??a.cliToolId}}async function g(a,b,h,i,j={}){let k=a.instanceId??a.cliToolId,l=e(h);if(0===b.length||0===l.length)return{outcome:"skipped",messageId:null,timestampMs:null};try{let[{getDbInstance:g},m,{broadcastMessage:n}]=await Promise.all([Promise.resolve().then(c.bind(c,88807)),Promise.resolve().then(c.bind(c,52660)),Promise.all([c.e(1503),c.e(4299),c.e(6838),c.e(1719),c.e(2119),c.e(2445),c.e(595)]).then(c.bind(c,49640))]),o=g(),p=m.findMessageByRequestId(o,a.worktreeId,b);if(p)return{outcome:"already-recorded",messageId:p.id,timestampMs:p.timestamp.getTime()};let q=i>0?i:Date.now(),r=function(a,b,c,g,h,i,j,k){var l,m,n;let o=Math.min(j-12e4,k.adoptionFromMs??1/0),p=(l=a.findUnkeyedUserMessages(b,{worktreeId:c.worktreeId,cliToolId:c.cliToolId,instanceId:g,fromMs:o,toMs:j+12e4,includeRelayDelivered:!0}),m=i,n=j,l.filter(a=>e(a.content)===m).sort((a,b)=>Math.abs(a.timestamp.getTime()-n)-Math.abs(b.timestamp.getTime()-n)));for(let e of p)if(!e.requestId&&a.setMessageRequestId(b,e.id,h))return d.info("user-turn-adopted",{...f(c),requestId:h,messageId:e.id,driftMs:e.timestamp.getTime()-j}),{outcome:"adopted",messageId:e.id,timestampMs:e.timestamp.getTime()};let q=p.find(a=>a.requestId);return q?(d.info("user-turn-already-relayed",{...f(c),requestId:h,messageId:q.id,relayRequestId:q.requestId??null,driftMs:q.timestamp.getTime()-j}),{outcome:"already-recorded",messageId:q.id,timestampMs:q.timestamp.getTime()}):null}(m,o,a,k,b,l,q,j);if(r)return r;let s=m.createMessage(o,{worktreeId:a.worktreeId,role:"user",content:h,messageType:"normal",timestamp:new Date(q),cliToolId:a.cliToolId,instanceId:k,requestId:b});return n("message",{worktreeId:a.worktreeId,message:s}),d.info("user-turn-recorded",{...f(a),requestId:b,contentLength:h.length}),{outcome:"inserted",messageId:s.id,timestampMs:q}}catch(c){return d.error("user-turn-record-failed",{...f(a),requestId:b,error:c instanceof Error?c.message:String(c)}),{outcome:"failed",messageId:null,timestampMs:null}}}},28918:(a,b,c)=>{c.r(b),c.d(b,{captureStructuredHistoryTurn:()=>aS,hasStructuredHistoryTranscript:()=>aT,isPullTranscriptHistory:()=>aQ,isStructuredHistoryWriterLive:()=>aR,resetStructuredHistoryCaptureQueue:()=>aN});var d=c(72626),e=c(53163),f=c(79696),g=c(79748),h=c(21820),i=c(33873),j=c(24455);let k=(0,d.h)("lib/history/transcript-tail");async function l(a){let b;try{b=await (0,g.open)(a,"r");let{size:c}=await b.stat(),d=Math.max(0,c-4194304),e=c-d;if(e<=0)return"";let f=Buffer.alloc(e),{bytesRead:h}=await b.read(f,0,e,d),i=f.subarray(0,h).toString("utf8");if(0===d)return i;let j=i.indexOf("\n");return -1===j?"":i.slice(j+1)}catch(b){return k.warn("transcript-tail-read-failed",{path:a,error:b instanceof Error?b.message:String(b)}),null}finally{await b?.close().catch(()=>{})}}var m=c(18201),n=c(86594),o=c(57510),p=c(27128);let q=["sessions"],r=".jsonl",s="\n\n_(truncated)_";function t(a){return a.replace(/\s+/g," ").trim()}function u(a){return a.length<=200?a:`${a.slice(0,199)}…`}let v=new Set(["ContextCompaction"]),w={CommandExecution:"exec",FileChange:"edit",McpToolCall:"mcp",ImageView:"view",Extension:"extension"},x=(0,d.h)("lib/hooks/sources/codex/history"),y=/^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$/,z=globalThis.__codexTranscriptSessions??=new Map,A=globalThis.__codexTranscriptPaths??=new Map;async function B(a){let b=(0,j.v7)(a.worktreeId,a.cliToolId,a.instanceId);try{let{getLastAgentEvent:d}=await Promise.resolve().then(c.bind(c,48083)),e=d(a.worktreeId,a.cliToolId,a.instanceId)?.sessionId;if("string"==typeof e&&e.length>0)return z.set(b,e),e}catch(b){x.debug("codex-transcript-session-lookup-failed",{worktreeId:a.worktreeId,instanceId:a.instanceId??a.cliToolId,error:b instanceof Error?b.message:String(b)})}return z.get(b)??null}function C(a=process.env){let b=a.CODEX_HOME;return"string"==typeof b&&b.length>0?b:(0,i.join)((0,h.homedir)(),".codex")}function D(a){return(0,i.join)(a,...q)}async function E(a,b,c=4){return y.test(b)?F(D(a),b,c):null}async function F(a,b,c){let d;if(c<=0)return null;try{d=await (0,g.readdir)(a,{withFileTypes:!0})}catch{return null}let e=[];for(let c of d){if(c.isFile()){var f;if(f=c.name,f.startsWith("rollout-")&&f.endsWith(`-${b}${r}`))return(0,i.join)(a,c.name);continue}c.isDirectory()&&e.push(c.name)}for(let d of(e.sort((a,b)=>a<b?1:a>b?-1:0),e)){let e=await F((0,i.join)(a,d),b,c-1);if(e)return e}return null}async function G(a,b={}){let c=a.instanceId??a.cliToolId;try{let d=b.codexHome??C(),e=await B(a);if(!e)return x.debug("codex-transcript-unavailable",{worktreeId:a.worktreeId,instanceId:c,reason:"no-session-pointer"}),!1;let f=await J(d,e);if(!f)return x.debug("codex-transcript-unavailable",{worktreeId:a.worktreeId,instanceId:c,sessionId:e,reason:"no-file"}),!1;let g=await l(f);if(null===g)return!1;let h=function(a){let b=[],c=0;for(let d of a.split("\n")){let a;if(0===d.trim().length)continue;try{a=JSON.parse(d)}catch{c+=1;continue}let e=function(a){if(!(0,o.Qd)(a))return null;let b=(0,o.O2)(a,"type");if(!b)return null;let c=(0,o.Qd)(a.payload)?a.payload:null,d=c?(0,o.O2)(c,"type"):null,e=(0,o.O2)(a,"timestamp"),f=e?Date.parse(e):NaN;return{type:b,payloadType:d,turnId:c?(0,o.O2)(c,"turn_id"):null,sessionId:c?(0,o.O2)(c,"session_id")??(0,o.O2)(c,"thread_id"):null,timestampMs:Number.isFinite(f)?f:null,item:c&&"item_completed"===d?function(a){var b,c;if(!(0,o.Qd)(a))return null;let d=(0,o.O2)(a,"type");return d?{type:d,id:(0,o.O2)(a,"id"),text:(b=d,c=a,"UserMessage"===b||"AgentMessage"===b?function(a){if(!Array.isArray(a))return null;let b="";for(let c of a){if(!(0,o.Qd)(c))continue;let a=(0,o.O2)(c,"text");a&&(b+=a)}return b.length>0?b:null}(c.content):"Reasoning"===b?function(a){if(!Array.isArray(a))return null;let b=a.filter(a=>"string"==typeof a&&""!==a);return b.length>0?b.join("\n\n"):null}(c.summary_text):null),phase:(0,o.O2)(a,"phase"),detail:function(a,b){if("CommandExecution"===a){let a=function(a){if(!Array.isArray(a))return null;let b=[];for(let c of a){if(!(0,o.Qd)(c))continue;let a=(0,o.O2)(c,"cmd");a&&b.push(a)}return b.length>0?b.join(" ; "):null}(b.parsed_cmd);if(a)return u(t(a));let c=function(a){if(!Array.isArray(a))return null;let b=a.filter(a=>"string"==typeof a);return b.length>0?b.join(" "):null}(b.command);return c?u(t(c)):null}if("FileChange"===a){let a=b.changes;if(!(0,o.Qd)(a))return null;let c=Object.keys(a);return c.length>0?u(c.join(", ")):null}if("McpToolCall"===a){let a=(0,o.O2)(b,"server"),c=(0,o.O2)(b,"tool");return a||c?u([a,c].filter(Boolean).join(".")):null}if("ImageView"===a){let a=(0,o.O2)(b,"path");return a?u(a):null}if("Extension"===a){let a=(0,o.O2)(b,"query")??(0,o.O2)(b,"action");return a?u(t(a)):null}return null}(d,a)}:null}(c.item):null}}(a);e?b.push(e):c+=1}return{records:b,malformedLines:c}}(g),i=function(a,b){let c=new Map,d=0,e=0,f=null;for(let g of a){if("session_meta"===g.type&&g.sessionId&&(f=g.sessionId),"response_item"===g.type){d+=1;continue}let a=g.turnId;if(!a){e+=1;continue}let h=c.get(a);if(h||(h={sessionId:g.sessionId??f??b,turnId:a,startedAt:g.timestampMs??0,prompts:[],items:[],started:!1,closed:!1,overflowed:!1},c.set(a,h)),"task_started"===g.payloadType){h.started=!0;continue}if("task_complete"===g.payloadType){h.closed=!0;continue}let i=g.item;if(i){if("UserMessage"===i.type){i.id&&i.text&&h.prompts.push({itemId:i.id,text:i.text,timestampMs:g.timestampMs??h.startedAt});continue}if(h.items.length>=2048){h.overflowed=!0;continue}h.items.push(i)}}return{turns:[...c.values()],duplicateStreamRecords:d,turnlessRecords:e}}(h.records,e);if(0===i.turns.length)return x.info("codex-transcript-no-turn",{worktreeId:a.worktreeId,instanceId:c,path:f,records:h.records.length,malformedLines:h.malformedLines,duplicateStreamRecords:i.duplicateStreamRecords}),!1;h.malformedLines>0&&x.info("codex-transcript-partial-read",{worktreeId:a.worktreeId,instanceId:c,path:f,malformedLines:h.malformedLines,turnlessRecords:i.turnlessRecords,duplicateStreamRecords:i.duplicateStreamRecords});let j=await I(a,i.turns);if(0===j.turns.length)return x.debug("codex-transcript-turns-already-saved",{worktreeId:a.worktreeId,instanceId:c,turnsInWindow:i.turns.length}),!0;j.turns.length>1&&x.info("codex-transcript-backfilling-turns",{worktreeId:a.worktreeId,instanceId:c,path:f,pendingTurns:j.turns.length,turnsInWindow:i.turns.length,anchored:j.anchored});let k=[];for(let b=0;b<j.turns.length;b+=1){let c=0===b?j.previousStartedAt:j.turns[b-1].startedAt;k.push(await L(a,j.turns[b],c))}let m={path:f,firstRecordAt:function(a){for(let b of a)if(null!==b.timestampMs)return b.timestampMs;return null}(h.records),turnlessRecords:i.turnlessRecords,malformedLines:h.malformedLines},n=function(a){let b=new Map;for(let c of a){if("response_item"===c.type)continue;let a=c.turnId;a&&null!==c.timestampMs&&c.timestampMs>(b.get(a)??0)&&b.set(a,c.timestampMs)}return b}(h.records),q=!1;for(let b=0;b<j.turns.length;b+=1){let c=j.turns[b];q=await M(a,c,function(a){let b=[],c=new Set,d=0,e=0;for(let f of a.items){if("AgentMessage"===f.type){let a=f.text?.trim()??"";if(0===a.length)continue;b.push({kind:"prose",text:a}),d+=1;continue}if("Reasoning"===f.type){let a=f.text?.trim()??"";if(0===a.length)continue;b.push({kind:"aside",text:function(a){let b=a.trim().split("\n").map(a=>a.length>0?`> ${a}`:">").join("\n");return`> **Thinking**
1
+ "use strict";exports.id=8918,exports.ids=[8918],exports.modules={18201:(a,b,c)=>{c.d(b,{Ce:()=>g,pk:()=>e});let d=(0,c(72626).h)("lib/history/user-turn-recorder");function e(a){return a.replace(/\r\n?/g,"\n").split("\n").map(a=>a.replace(/[ \t ]+$/u,"")).join("\n").trim()}function f(a){return{worktreeId:a.worktreeId,cliToolId:a.cliToolId,instanceId:a.instanceId??a.cliToolId}}async function g(a,b,h,i,j={}){let k=a.instanceId??a.cliToolId,l=e(h);if(0===b.length||0===l.length)return{outcome:"skipped",messageId:null,timestampMs:null};try{let[{getDbInstance:g},m,{broadcastMessage:n}]=await Promise.all([Promise.resolve().then(c.bind(c,88807)),Promise.resolve().then(c.bind(c,52660)),Promise.all([c.e(1503),c.e(4299),c.e(6838),c.e(1719),c.e(2119),c.e(2445),c.e(595)]).then(c.bind(c,49640))]),o=g(),p=m.findMessageByRequestId(o,a.worktreeId,b);if(p)return{outcome:"already-recorded",messageId:p.id,timestampMs:p.timestamp.getTime()};let q=i>0?i:Date.now(),r=function(a,b,c,g,h,i,j,k){var l,m,n;let o=Math.min(j-12e4,k.adoptionFromMs??1/0),p=(l=a.findUnkeyedUserMessages(b,{worktreeId:c.worktreeId,cliToolId:c.cliToolId,instanceId:g,fromMs:o,toMs:j+12e4,includeRelayDelivered:!0}),m=i,n=j,l.filter(a=>e(a.content)===m).sort((a,b)=>Math.abs(a.timestamp.getTime()-n)-Math.abs(b.timestamp.getTime()-n)));for(let e of p)if(!e.requestId&&a.setMessageRequestId(b,e.id,h))return d.info("user-turn-adopted",{...f(c),requestId:h,messageId:e.id,driftMs:e.timestamp.getTime()-j}),{outcome:"adopted",messageId:e.id,timestampMs:e.timestamp.getTime()};let q=p.find(a=>a.requestId);return q?(d.info("user-turn-already-relayed",{...f(c),requestId:h,messageId:q.id,relayRequestId:q.requestId??null,driftMs:q.timestamp.getTime()-j}),{outcome:"already-recorded",messageId:q.id,timestampMs:q.timestamp.getTime()}):null}(m,o,a,k,b,l,q,j);if(r)return r;let s=m.createMessage(o,{worktreeId:a.worktreeId,role:"user",content:h,messageType:"normal",timestamp:new Date(q),cliToolId:a.cliToolId,instanceId:k,requestId:b});return n("message",{worktreeId:a.worktreeId,message:s}),d.info("user-turn-recorded",{...f(a),requestId:b,contentLength:h.length}),{outcome:"inserted",messageId:s.id,timestampMs:q}}catch(c){return d.error("user-turn-record-failed",{...f(a),requestId:b,error:c instanceof Error?c.message:String(c)}),{outcome:"failed",messageId:null,timestampMs:null}}}},28918:(a,b,c)=>{c.r(b),c.d(b,{captureStructuredHistoryTurn:()=>aT,hasStructuredHistoryTranscript:()=>aU,isPullTranscriptHistory:()=>aR,isStructuredHistoryWriterLive:()=>aS,resetStructuredHistoryCaptureQueue:()=>aO});var d=c(72626),e=c(53163),f=c(79696),g=c(79748),h=c(21820),i=c(33873),j=c(24455);let k=(0,d.h)("lib/history/transcript-tail");async function l(a){let b;try{b=await (0,g.open)(a,"r");let{size:c}=await b.stat(),d=Math.max(0,c-4194304),e=c-d;if(e<=0)return"";let f=Buffer.alloc(e),{bytesRead:h}=await b.read(f,0,e,d),i=f.subarray(0,h).toString("utf8");if(0===d)return i;let j=i.indexOf("\n");return -1===j?"":i.slice(j+1)}catch(b){return k.warn("transcript-tail-read-failed",{path:a,error:b instanceof Error?b.message:String(b)}),null}finally{await b?.close().catch(()=>{})}}var m=c(18201),n=c(86594),o=c(57510),p=c(27128);let q=["sessions"],r=".jsonl",s="\n\n_(truncated)_";function t(a){return a.replace(/\s+/g," ").trim()}function u(a){return a.length<=200?a:`${a.slice(0,199)}…`}let v=new Set(["ContextCompaction"]),w={CommandExecution:"exec",FileChange:"edit",McpToolCall:"mcp",ImageView:"view",Extension:"extension"};function x(a){return a.text?.trim()??""}let y=(0,d.h)("lib/hooks/sources/codex/history"),z=/^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$/,A=globalThis.__codexTranscriptSessions??=new Map,B=globalThis.__codexTranscriptPaths??=new Map;async function C(a){let b=(0,j.v7)(a.worktreeId,a.cliToolId,a.instanceId);try{let{getLastAgentEvent:d}=await Promise.resolve().then(c.bind(c,48083)),e=d(a.worktreeId,a.cliToolId,a.instanceId)?.sessionId;if("string"==typeof e&&e.length>0)return A.set(b,e),e}catch(b){y.debug("codex-transcript-session-lookup-failed",{worktreeId:a.worktreeId,instanceId:a.instanceId??a.cliToolId,error:b instanceof Error?b.message:String(b)})}return A.get(b)??null}function D(a=process.env){let b=a.CODEX_HOME;return"string"==typeof b&&b.length>0?b:(0,i.join)((0,h.homedir)(),".codex")}function E(a){return(0,i.join)(a,...q)}async function F(a,b,c=4){return z.test(b)?G(E(a),b,c):null}async function G(a,b,c){let d;if(c<=0)return null;try{d=await (0,g.readdir)(a,{withFileTypes:!0})}catch{return null}let e=[];for(let c of d){if(c.isFile()){var f;if(f=c.name,f.startsWith("rollout-")&&f.endsWith(`-${b}${r}`))return(0,i.join)(a,c.name);continue}c.isDirectory()&&e.push(c.name)}for(let d of(e.sort((a,b)=>a<b?1:a>b?-1:0),e)){let e=await G((0,i.join)(a,d),b,c-1);if(e)return e}return null}async function H(a,b={}){let c=a.instanceId??a.cliToolId;try{let d=b.codexHome??D(),e=await C(a);if(!e)return y.debug("codex-transcript-unavailable",{worktreeId:a.worktreeId,instanceId:c,reason:"no-session-pointer"}),!1;let f=await K(d,e);if(!f)return y.debug("codex-transcript-unavailable",{worktreeId:a.worktreeId,instanceId:c,sessionId:e,reason:"no-file"}),!1;let g=await l(f);if(null===g)return!1;let h=function(a){let b=[],c=0;for(let d of a.split("\n")){let a;if(0===d.trim().length)continue;try{a=JSON.parse(d)}catch{c+=1;continue}let e=function(a){if(!(0,o.Qd)(a))return null;let b=(0,o.O2)(a,"type");if(!b)return null;let c=(0,o.Qd)(a.payload)?a.payload:null,d=c?(0,o.O2)(c,"type"):null,e=(0,o.O2)(a,"timestamp"),f=e?Date.parse(e):NaN;return{type:b,payloadType:d,turnId:c?(0,o.O2)(c,"turn_id"):null,sessionId:c?(0,o.O2)(c,"session_id")??(0,o.O2)(c,"thread_id"):null,timestampMs:Number.isFinite(f)?f:null,item:c&&"item_completed"===d?function(a){var b,c;if(!(0,o.Qd)(a))return null;let d=(0,o.O2)(a,"type");return d?{type:d,id:(0,o.O2)(a,"id"),text:(b=d,c=a,"UserMessage"===b||"AgentMessage"===b?function(a){if(!Array.isArray(a))return null;let b="";for(let c of a){if(!(0,o.Qd)(c))continue;let a=(0,o.O2)(c,"text");a&&(b+=a)}return b.length>0?b:null}(c.content):"Reasoning"===b?function(a){if(!Array.isArray(a))return null;let b=a.filter(a=>"string"==typeof a&&""!==a);return b.length>0?b.join("\n\n"):null}(c.summary_text):null),phase:(0,o.O2)(a,"phase"),detail:function(a,b){if("CommandExecution"===a){let a=function(a){if(!Array.isArray(a))return null;let b=[];for(let c of a){if(!(0,o.Qd)(c))continue;let a=(0,o.O2)(c,"cmd");a&&b.push(a)}return b.length>0?b.join(" ; "):null}(b.parsed_cmd);if(a)return u(t(a));let c=function(a){if(!Array.isArray(a))return null;let b=a.filter(a=>"string"==typeof a);return b.length>0?b.join(" "):null}(b.command);return c?u(t(c)):null}if("FileChange"===a){let a=b.changes;if(!(0,o.Qd)(a))return null;let c=Object.keys(a);return c.length>0?u(c.join(", ")):null}if("McpToolCall"===a){let a=(0,o.O2)(b,"server"),c=(0,o.O2)(b,"tool");return a||c?u([a,c].filter(Boolean).join(".")):null}if("ImageView"===a){let a=(0,o.O2)(b,"path");return a?u(a):null}if("Extension"===a){let a=(0,o.O2)(b,"query")??(0,o.O2)(b,"action");return a?u(t(a)):null}return null}(d,a)}:null}(c.item):null}}(a);e?b.push(e):c+=1}return{records:b,malformedLines:c}}(g),i=function(a,b){let c=new Map,d=0,e=0,f=null;for(let g of a){if("session_meta"===g.type&&g.sessionId&&(f=g.sessionId),"response_item"===g.type){d+=1;continue}let a=g.turnId;if(!a){e+=1;continue}let h=c.get(a);if(h||(h={sessionId:g.sessionId??f??b,turnId:a,startedAt:g.timestampMs??0,prompts:[],items:[],started:!1,closed:!1,overflowed:!1},c.set(a,h)),"task_started"===g.payloadType){h.started=!0;continue}if("task_complete"===g.payloadType){h.closed=!0;continue}let i=g.item;if(i){if("UserMessage"===i.type){i.id&&i.text&&h.prompts.push({itemId:i.id,text:i.text,timestampMs:g.timestampMs??h.startedAt});continue}if(h.items.length>=2048){h.overflowed=!0;continue}h.items.push(i)}}return{turns:[...c.values()],duplicateStreamRecords:d,turnlessRecords:e}}(h.records,e);if(0===i.turns.length)return y.info("codex-transcript-no-turn",{worktreeId:a.worktreeId,instanceId:c,path:f,records:h.records.length,malformedLines:h.malformedLines,duplicateStreamRecords:i.duplicateStreamRecords}),!1;h.malformedLines>0&&y.info("codex-transcript-partial-read",{worktreeId:a.worktreeId,instanceId:c,path:f,malformedLines:h.malformedLines,turnlessRecords:i.turnlessRecords,duplicateStreamRecords:i.duplicateStreamRecords});let j=await J(a,i.turns);if(0===j.turns.length)return y.debug("codex-transcript-turns-already-saved",{worktreeId:a.worktreeId,instanceId:c,turnsInWindow:i.turns.length}),!0;j.turns.length>1&&y.info("codex-transcript-backfilling-turns",{worktreeId:a.worktreeId,instanceId:c,path:f,pendingTurns:j.turns.length,turnsInWindow:i.turns.length,anchored:j.anchored});let k=[];for(let b=0;b<j.turns.length;b+=1){let c=0===b?j.previousStartedAt:j.turns[b-1].startedAt;k.push(await M(a,j.turns[b],c))}let m={path:f,firstRecordAt:function(a){for(let b of a)if(null!==b.timestampMs)return b.timestampMs;return null}(h.records),turnlessRecords:i.turnlessRecords,malformedLines:h.malformedLines},n=function(a){let b=new Map;for(let c of a){if("response_item"===c.type)continue;let a=c.turnId;a&&null!==c.timestampMs&&c.timestampMs>(b.get(a)??0)&&b.set(a,c.timestampMs)}return b}(h.records),q=!1;for(let b=0;b<j.turns.length;b+=1){let c=j.turns[b];q=await N(a,c,function(a){let b=[],c=new Set,d=0,e=0,f=a.items.some(a=>"AgentMessage"===a.type&&"final_answer"===a.phase&&x(a).length>0);for(let g of a.items){if("AgentMessage"===g.type){let a=x(g);if(0===a.length)continue;let c=f&&"commentary"===g.phase;b.push({kind:c?"reasoning":"prose",text:a}),d+=1;continue}if("Reasoning"===g.type){let a=g.text?.trim()??"";if(0===a.length)continue;b.push({kind:"aside",text:function(a){let b=a.trim().split("\n").map(a=>a.length>0?`> ${a}`:">").join("\n");return`> **Thinking**
2
2
  >
3
- ${b}`}(a)});continue}if(f.type in w){b.push({kind:"tool",text:function(a){let b=w[a.type]??a.type;return a.detail?`- \`${b}\` — ${a.detail}`:`- \`${b}\``}(f)}),e+=1;continue}v.has(f.type)||c.add(f.type)}let f=(0,p.t3)(b).body;return!a.started&&f.length>0&&(f="_(head truncated)_\n\n"+f),f.length>2e5&&(f=f.slice(0,2e5-s.length)+s),{sessionId:a.sessionId,turnId:a.turnId,body:f,headless:!a.started,textBlocks:d,toolBlocks:e,unknownBlockTypes:[...c]}}(c),function(a,b,c=0,d=null){let e=null===b.timestampMs?a.startedAt:Math.max(a.startedAt,b.timestampMs+1);return Math.max(e,Math.min(c,null===d?1/0:d-1))}(c,k[b],n.get(c.turnId)??0,function(a,b,c){let d=a[c+1];return d?b[c+1]?.timestampMs??d.startedAt:null}(j.turns,k,b)),m)}return q}catch(b){return x.error("codex-transcript-capture-failed",{worktreeId:a.worktreeId,instanceId:c,error:b instanceof Error?b.message:String(b)}),!1}}async function H(a,b={}){try{let c=await B(a);if(!c)return null;return await J(b.codexHome??C(),c)}catch{return null}}async function I(a,b){let[{getDbInstance:d},{findMessageByRequestId:e}]=await Promise.all([Promise.resolve().then(c.bind(c,88807)),Promise.resolve().then(c.bind(c,56791))]),f=d();for(let c=b.length-1;c>=0;c-=1){let d=(0,n.ZS)(b[c].turnId);if(e(f,a.worktreeId,d))return{turns:b.slice(c+1),previousStartedAt:b[c].startedAt,anchored:!0}}return{turns:b.slice(-1),previousStartedAt:b.length>1?b[b.length-2].startedAt:0,anchored:!1}}async function J(a,b){let c=`${a}\0${b}`,d=A.get(c);if(d&&await K(d))return d;d&&A.delete(c);let e=await E(a,b);if(!e)return null;let f=function(a,b){if(!b.endsWith(r)||b.includes("\0"))return null;let c=(0,i.resolve)(D(a)),d=(0,i.resolve)(b);return d===c||d.startsWith(c+i.sep)?d:null}(a,e);return f?(A.set(c,f),f):null}async function K(a){try{return(await (0,g.stat)(a)).isFile()}catch{return!1}}async function L(a,b,c=0){let d=a.instanceId??a.cliToolId,e={outcome:"skipped",messageId:null,timestampMs:null},f=c>0?{adoptionFromMs:c}:{};for(let c of b.prompts){let g=await (0,m.Ce)(a,(0,n.Ac)(c.itemId),c.text,c.timestampMs,f);if("failed"===g.outcome){x.warn("codex-transcript-user-turn-failed",{worktreeId:a.worktreeId,instanceId:d,sessionId:b.sessionId,turnId:b.turnId,promptItemId:c.itemId});continue}e=g}return e}async function M(a,b,d,e,f){let g=a.instanceId??a.cliToolId;if(!b.closed)return x.info("codex-transcript-turn-open",{worktreeId:a.worktreeId,instanceId:g,sessionId:d.sessionId,turnId:d.turnId,items:b.items.length}),!1;if(0===d.body.length)return x.info("codex-transcript-turn-empty",{worktreeId:a.worktreeId,instanceId:g,sessionId:d.sessionId,turnId:d.turnId}),!1;d.unknownBlockTypes.length>0&&x.info("codex-transcript-unknown-items",{worktreeId:a.worktreeId,instanceId:g,sessionId:d.sessionId,turnId:d.turnId,itemTypes:d.unknownBlockTypes}),b.overflowed&&x.info("codex-transcript-turn-overflowed",{worktreeId:a.worktreeId,instanceId:g,sessionId:d.sessionId,turnId:d.turnId});let h=(0,n.ZS)(d.turnId),[{getDbInstance:i},{createMessage:j,findMessageByRequestId:k},{broadcastMessage:l}]=await Promise.all([Promise.resolve().then(c.bind(c,88807)),Promise.resolve().then(c.bind(c,56791)),Promise.all([c.e(1503),c.e(4299),c.e(6838),c.e(1719),c.e(2119),c.e(2445),c.e(595)]).then(c.bind(c,49640))]),m=i();if(k(m,a.worktreeId,h))return x.debug("codex-transcript-turn-already-saved",{worktreeId:a.worktreeId,instanceId:g,requestId:h}),!0;d.headless&&x.info("codex-transcript-turn-headless",{worktreeId:a.worktreeId,instanceId:g,sessionId:d.sessionId,turnId:d.turnId,path:f.path,windowBytes:4194304,windowFirstRecordAt:f.firstRecordAt,turnlessRecords:f.turnlessRecords,malformedLines:f.malformedLines,promptsInWindow:b.prompts.length,itemsInWindow:b.items.length});let o=j(m,{worktreeId:a.worktreeId,role:"assistant",content:d.body,messageType:"normal",timestamp:new Date(e>0?e:Date.now()),cliToolId:a.cliToolId,instanceId:g,requestId:h});return l("message",{worktreeId:a.worktreeId,message:o}),x.info("codex-transcript-turn-saved",{worktreeId:a.worktreeId,instanceId:g,sessionId:d.sessionId,requestId:h,path:f.path,bodyLength:d.body.length,textBlocks:d.textBlocks,toolBlocks:d.toolBlocks,prompts:b.prompts.length}),!0}let N=[".system_generated","logs","transcript_full.jsonl"],O="\n\n_(truncated)_",P="MODEL",Q="PLANNER_RESPONSE",R=new Set(["RUN_COMMAND","VIEW_FILE","LIST_DIRECTORY","GREP_SEARCH","SEARCH_WEB","CODE_ACTION","GENERATE_IMAGE","GENERIC"]),S=new Set(["CHECKPOINT","CONVERSATION_HISTORY","SYSTEM_MESSAGE","EPHEMERAL_MESSAGE","ERROR_MESSAGE"]),T=(0,d.h)("lib/hooks/sources/antigravity/history"),U=[".gemini","antigravity-cli"],V=/^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$/,W=globalThis.__antigravityTranscriptConversations??=new Map;async function X(a){let b=(0,j.v7)(a.worktreeId,a.cliToolId,a.instanceId);try{let{getLastAgentEvent:d}=await Promise.resolve().then(c.bind(c,48083)),e=d(a.worktreeId,a.cliToolId,a.instanceId)?.sessionId;if("string"==typeof e&&e.length>0)return W.set(b,e),e}catch(b){T.debug("antigravity-transcript-conversation-lookup-failed",{worktreeId:a.worktreeId,instanceId:a.instanceId??a.cliToolId,error:b instanceof Error?b.message:String(b)})}return W.get(b)??null}function Y(a=(0,h.homedir)()){return(0,i.join)(a,...U)}function Z(a){return(0,i.join)(a,"brain")}async function $(a,b={}){let c=a.instanceId??a.cliToolId;try{let d=b.antigravityHome??Y(),e=await X(a);if(!e)return T.debug("antigravity-transcript-unavailable",{worktreeId:a.worktreeId,instanceId:c,reason:"no-conversation-pointer"}),!1;let f=await ab(d,e);if(!f)return T.debug("antigravity-transcript-unavailable",{worktreeId:a.worktreeId,instanceId:c,conversationId:e,reason:"no-file"}),!1;let g=await l(f);if(null===g)return!1;let h=function(a){let b=[],c=0;for(let d of a.split("\n")){let a;if(0===d.trim().length)continue;try{a=JSON.parse(d)}catch{c+=1;continue}let e=function(a){if(!(0,o.Qd)(a))return null;let b=a.step_index;if("number"!=typeof b||!Number.isInteger(b)||b<0)return null;let c=(0,o.O2)(a,"source"),d=(0,o.O2)(a,"type");if(!c||!d)return null;let e=(0,o.O2)(a,"created_at"),f=e?Date.parse(e):NaN,g=[];if(Array.isArray(a.tool_calls))for(let b of a.tool_calls){let a=function(a){var b;if(!(0,o.Qd)(a))return null;let c=(0,o.O2)(a,"name");if(!c)return null;let d=(0,o.Qd)(a.args)?a.args:null,e=d?(0,o.O2)(d,"toolAction")??(0,o.O2)(d,"toolSummary"):null;return{name:c,detail:e?(b=e.replace(/\s+/g," ").trim()).length<=200?b:`${b.slice(0,199)}…`:null}}(b);a&&g.push(a)}return{stepIndex:b,source:c,type:d,status:(0,o.O2)(a,"status"),timestampMs:Number.isFinite(f)?f:null,content:(0,o.O2)(a,"content"),thinking:(0,o.O2)(a,"thinking"),toolCalls:g}}(a);e?b.push(e):c+=1}return{records:b,malformedLines:c}}(g),i=function(a,b){let c=[],d=0;for(let g of a){var e,f;if(e=g,"USER_EXPLICIT"===e.source&&"USER_INPUT"===e.type){let a=g.content?function(a){let b=a.indexOf("<USER_REQUEST>");if(-1===b)return null;let c=b+14,d=a.indexOf("</USER_REQUEST>",c);if(-1===d)return null;let e=a.slice(c,d).trim();return e.length>0?e:null}(g.content):null,d=g.timestampMs??0;c.push({conversationId:b,stepIndex:g.stepIndex,startedAt:d,prompt:a?{stepIndex:g.stepIndex,text:a,timestampMs:g.timestampMs??d}:null,records:[],closed:!1,superseded:!1,overflowed:!1});continue}let a=c.at(-1);if(!a){d+=1;continue}if(g.source===P&&(a.closed=(f=g).source===P&&f.type===Q&&!(f.toolCalls.length>0)&&(f.content??"").trim().length>0),a.records.length>=2048){a.overflowed=!0;continue}a.records.push(g)}for(let a=0;a<c.length-1;a+=1)c[a].superseded=!0;return{turns:c,preludeRecords:d}}(h.records,e);if(0===i.turns.length)return T.info("antigravity-transcript-no-turn",{worktreeId:a.worktreeId,instanceId:c,path:f,records:h.records.length,malformedLines:h.malformedLines,preludeRecords:i.preludeRecords}),!1;h.malformedLines>0&&T.info("antigravity-transcript-partial-read",{worktreeId:a.worktreeId,instanceId:c,path:f,malformedLines:h.malformedLines,preludeRecords:i.preludeRecords});let j=await aa(a,i.turns);if(0===j.turns.length)return T.debug("antigravity-transcript-turns-already-saved",{worktreeId:a.worktreeId,instanceId:c,turnsInWindow:i.turns.length}),!0;j.turns.length>1&&T.info("antigravity-transcript-backfilling-turns",{worktreeId:a.worktreeId,instanceId:c,path:f,pendingTurns:j.turns.length,turnsInWindow:i.turns.length,anchored:j.anchored});let k=[];for(let b=0;b<j.turns.length;b+=1){let c=0===b?j.previousStartedAt:j.turns[b-1].startedAt;k.push(await ad(a,j.turns[b],c))}let m=!1;for(let b=0;b<j.turns.length;b+=1){let c=j.turns[b];m=await ae(a,c,function(a){let b=[],c=new Set,d=0,e=0;for(let f of a.records){if(f.source===P&&f.type===Q){let a=f.thinking?.trim()??"";a.length>0&&b.push({kind:"aside",text:function(a){let b=a.trim().split("\n").map(a=>a.length>0?`> ${a}`:">").join("\n");return`> **Thinking**
3
+ ${b}`}(a)});continue}if(g.type in w){b.push({kind:"tool",text:function(a){let b=w[a.type]??a.type;return a.detail?`- \`${b}\` — ${a.detail}`:`- \`${b}\``}(g)}),e+=1;continue}v.has(g.type)||c.add(g.type)}let g=(0,p.t3)(b).body;return!a.started&&g.length>0&&(g="_(head truncated)_\n\n"+g),g.length>2e5&&(g=g.slice(0,2e5-s.length)+s),{sessionId:a.sessionId,turnId:a.turnId,body:g,headless:!a.started,textBlocks:d,toolBlocks:e,unknownBlockTypes:[...c]}}(c),function(a,b,c=0,d=null){let e=null===b.timestampMs?a.startedAt:Math.max(a.startedAt,b.timestampMs+1);return Math.max(e,Math.min(c,null===d?1/0:d-1))}(c,k[b],n.get(c.turnId)??0,function(a,b,c){let d=a[c+1];return d?b[c+1]?.timestampMs??d.startedAt:null}(j.turns,k,b)),m)}return q}catch(b){return y.error("codex-transcript-capture-failed",{worktreeId:a.worktreeId,instanceId:c,error:b instanceof Error?b.message:String(b)}),!1}}async function I(a,b={}){try{let c=await C(a);if(!c)return null;return await K(b.codexHome??D(),c)}catch{return null}}async function J(a,b){let[{getDbInstance:d},{findMessageByRequestId:e}]=await Promise.all([Promise.resolve().then(c.bind(c,88807)),Promise.resolve().then(c.bind(c,56791))]),f=d();for(let c=b.length-1;c>=0;c-=1){let d=(0,n.ZS)(b[c].turnId);if(e(f,a.worktreeId,d))return{turns:b.slice(c+1),previousStartedAt:b[c].startedAt,anchored:!0}}return{turns:b.slice(-1),previousStartedAt:b.length>1?b[b.length-2].startedAt:0,anchored:!1}}async function K(a,b){let c=`${a}\0${b}`,d=B.get(c);if(d&&await L(d))return d;d&&B.delete(c);let e=await F(a,b);if(!e)return null;let f=function(a,b){if(!b.endsWith(r)||b.includes("\0"))return null;let c=(0,i.resolve)(E(a)),d=(0,i.resolve)(b);return d===c||d.startsWith(c+i.sep)?d:null}(a,e);return f?(B.set(c,f),f):null}async function L(a){try{return(await (0,g.stat)(a)).isFile()}catch{return!1}}async function M(a,b,c=0){let d=a.instanceId??a.cliToolId,e={outcome:"skipped",messageId:null,timestampMs:null},f=c>0?{adoptionFromMs:c}:{};for(let c of b.prompts){let g=await (0,m.Ce)(a,(0,n.Ac)(c.itemId),c.text,c.timestampMs,f);if("failed"===g.outcome){y.warn("codex-transcript-user-turn-failed",{worktreeId:a.worktreeId,instanceId:d,sessionId:b.sessionId,turnId:b.turnId,promptItemId:c.itemId});continue}e=g}return e}async function N(a,b,d,e,f){let g=a.instanceId??a.cliToolId;if(!b.closed)return y.info("codex-transcript-turn-open",{worktreeId:a.worktreeId,instanceId:g,sessionId:d.sessionId,turnId:d.turnId,items:b.items.length}),!1;if(0===d.body.length)return y.info("codex-transcript-turn-empty",{worktreeId:a.worktreeId,instanceId:g,sessionId:d.sessionId,turnId:d.turnId}),!1;d.unknownBlockTypes.length>0&&y.info("codex-transcript-unknown-items",{worktreeId:a.worktreeId,instanceId:g,sessionId:d.sessionId,turnId:d.turnId,itemTypes:d.unknownBlockTypes}),b.overflowed&&y.info("codex-transcript-turn-overflowed",{worktreeId:a.worktreeId,instanceId:g,sessionId:d.sessionId,turnId:d.turnId});let h=(0,n.ZS)(d.turnId),[{getDbInstance:i},{createMessage:j,findMessageByRequestId:k},{broadcastMessage:l}]=await Promise.all([Promise.resolve().then(c.bind(c,88807)),Promise.resolve().then(c.bind(c,56791)),Promise.all([c.e(1503),c.e(4299),c.e(6838),c.e(1719),c.e(2119),c.e(2445),c.e(595)]).then(c.bind(c,49640))]),m=i();if(k(m,a.worktreeId,h))return y.debug("codex-transcript-turn-already-saved",{worktreeId:a.worktreeId,instanceId:g,requestId:h}),!0;d.headless&&y.info("codex-transcript-turn-headless",{worktreeId:a.worktreeId,instanceId:g,sessionId:d.sessionId,turnId:d.turnId,path:f.path,windowBytes:4194304,windowFirstRecordAt:f.firstRecordAt,turnlessRecords:f.turnlessRecords,malformedLines:f.malformedLines,promptsInWindow:b.prompts.length,itemsInWindow:b.items.length});let o=j(m,{worktreeId:a.worktreeId,role:"assistant",content:d.body,messageType:"normal",timestamp:new Date(e>0?e:Date.now()),cliToolId:a.cliToolId,instanceId:g,requestId:h});return l("message",{worktreeId:a.worktreeId,message:o}),y.info("codex-transcript-turn-saved",{worktreeId:a.worktreeId,instanceId:g,sessionId:d.sessionId,requestId:h,path:f.path,bodyLength:d.body.length,textBlocks:d.textBlocks,toolBlocks:d.toolBlocks,prompts:b.prompts.length}),!0}let O=[".system_generated","logs","transcript_full.jsonl"],P="\n\n_(truncated)_",Q="MODEL",R="PLANNER_RESPONSE",S=new Set(["RUN_COMMAND","VIEW_FILE","LIST_DIRECTORY","GREP_SEARCH","SEARCH_WEB","CODE_ACTION","GENERATE_IMAGE","GENERIC"]),T=new Set(["CHECKPOINT","CONVERSATION_HISTORY","SYSTEM_MESSAGE","EPHEMERAL_MESSAGE","ERROR_MESSAGE"]),U=(0,d.h)("lib/hooks/sources/antigravity/history"),V=[".gemini","antigravity-cli"],W=/^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$/,X=globalThis.__antigravityTranscriptConversations??=new Map;async function Y(a){let b=(0,j.v7)(a.worktreeId,a.cliToolId,a.instanceId);try{let{getLastAgentEvent:d}=await Promise.resolve().then(c.bind(c,48083)),e=d(a.worktreeId,a.cliToolId,a.instanceId)?.sessionId;if("string"==typeof e&&e.length>0)return X.set(b,e),e}catch(b){U.debug("antigravity-transcript-conversation-lookup-failed",{worktreeId:a.worktreeId,instanceId:a.instanceId??a.cliToolId,error:b instanceof Error?b.message:String(b)})}return X.get(b)??null}function Z(a=(0,h.homedir)()){return(0,i.join)(a,...V)}function $(a){return(0,i.join)(a,"brain")}async function _(a,b={}){let c=a.instanceId??a.cliToolId;try{let d=b.antigravityHome??Z(),e=await Y(a);if(!e)return U.debug("antigravity-transcript-unavailable",{worktreeId:a.worktreeId,instanceId:c,reason:"no-conversation-pointer"}),!1;let f=await ac(d,e);if(!f)return U.debug("antigravity-transcript-unavailable",{worktreeId:a.worktreeId,instanceId:c,conversationId:e,reason:"no-file"}),!1;let g=await l(f);if(null===g)return!1;let h=function(a){let b=[],c=0;for(let d of a.split("\n")){let a;if(0===d.trim().length)continue;try{a=JSON.parse(d)}catch{c+=1;continue}let e=function(a){if(!(0,o.Qd)(a))return null;let b=a.step_index;if("number"!=typeof b||!Number.isInteger(b)||b<0)return null;let c=(0,o.O2)(a,"source"),d=(0,o.O2)(a,"type");if(!c||!d)return null;let e=(0,o.O2)(a,"created_at"),f=e?Date.parse(e):NaN,g=[];if(Array.isArray(a.tool_calls))for(let b of a.tool_calls){let a=function(a){var b;if(!(0,o.Qd)(a))return null;let c=(0,o.O2)(a,"name");if(!c)return null;let d=(0,o.Qd)(a.args)?a.args:null,e=d?(0,o.O2)(d,"toolAction")??(0,o.O2)(d,"toolSummary"):null;return{name:c,detail:e?(b=e.replace(/\s+/g," ").trim()).length<=200?b:`${b.slice(0,199)}…`:null}}(b);a&&g.push(a)}return{stepIndex:b,source:c,type:d,status:(0,o.O2)(a,"status"),timestampMs:Number.isFinite(f)?f:null,content:(0,o.O2)(a,"content"),thinking:(0,o.O2)(a,"thinking"),toolCalls:g}}(a);e?b.push(e):c+=1}return{records:b,malformedLines:c}}(g),i=function(a,b){let c=[],d=0;for(let g of a){var e,f;if(e=g,"USER_EXPLICIT"===e.source&&"USER_INPUT"===e.type){let a=g.content?function(a){let b=a.indexOf("<USER_REQUEST>");if(-1===b)return null;let c=b+14,d=a.indexOf("</USER_REQUEST>",c);if(-1===d)return null;let e=a.slice(c,d).trim();return e.length>0?e:null}(g.content):null,d=g.timestampMs??0;c.push({conversationId:b,stepIndex:g.stepIndex,startedAt:d,prompt:a?{stepIndex:g.stepIndex,text:a,timestampMs:g.timestampMs??d}:null,records:[],closed:!1,superseded:!1,overflowed:!1});continue}let a=c.at(-1);if(!a){d+=1;continue}if(g.source===Q&&(a.closed=(f=g).source===Q&&f.type===R&&!(f.toolCalls.length>0)&&(f.content??"").trim().length>0),a.records.length>=2048){a.overflowed=!0;continue}a.records.push(g)}for(let a=0;a<c.length-1;a+=1)c[a].superseded=!0;return{turns:c,preludeRecords:d}}(h.records,e);if(0===i.turns.length)return U.info("antigravity-transcript-no-turn",{worktreeId:a.worktreeId,instanceId:c,path:f,records:h.records.length,malformedLines:h.malformedLines,preludeRecords:i.preludeRecords}),!1;h.malformedLines>0&&U.info("antigravity-transcript-partial-read",{worktreeId:a.worktreeId,instanceId:c,path:f,malformedLines:h.malformedLines,preludeRecords:i.preludeRecords});let j=await ab(a,i.turns);if(0===j.turns.length)return U.debug("antigravity-transcript-turns-already-saved",{worktreeId:a.worktreeId,instanceId:c,turnsInWindow:i.turns.length}),!0;j.turns.length>1&&U.info("antigravity-transcript-backfilling-turns",{worktreeId:a.worktreeId,instanceId:c,path:f,pendingTurns:j.turns.length,turnsInWindow:i.turns.length,anchored:j.anchored});let k=[];for(let b=0;b<j.turns.length;b+=1){let c=0===b?j.previousStartedAt:j.turns[b-1].startedAt;k.push(await ae(a,j.turns[b],c))}let m=!1;for(let b=0;b<j.turns.length;b+=1){let c=j.turns[b];m=await af(a,c,function(a){let b=[],c=new Set,d=0,e=0;for(let f of a.records){if(f.source===Q&&f.type===R){let a=f.thinking?.trim()??"";a.length>0&&b.push({kind:"aside",text:function(a){let b=a.trim().split("\n").map(a=>a.length>0?`> ${a}`:">").join("\n");return`> **Thinking**
4
4
  >
5
- ${b}`}(a)});let c=f.content?.trim()??"";for(let a of(c.length>0&&(b.push({kind:"prose",text:c}),d+=1),f.toolCalls))b.push({kind:"tool",text:a.detail?`- \`${a.name}\` — ${a.detail}`:`- \`${a.name}\``}),e+=1;continue}if(f.source===P){R.has(f.type)||c.add(f.type);continue}S.has(f.type)||c.add(f.type)}let f=(0,p.t3)(b).body;return f.length>2e5&&(f=f.slice(0,2e5-O.length)+O),{conversationId:a.conversationId,stepIndex:a.stepIndex,body:f,textBlocks:d,toolBlocks:e,unknownRecordTypes:[...c]}}(c),function(a,b,c=0,d=null){let e=null===b.timestampMs?a.startedAt:Math.max(a.startedAt,b.timestampMs+1);return Math.max(e,Math.min(c,null===d?1/0:d-1))}(c,k[b],function(a){let b=0;for(let c of a.records)null!==c.timestampMs&&c.timestampMs>b&&(b=c.timestampMs);return b}(c),function(a,b,c){let d=a[c+1];return d?b[c+1]?.timestampMs??d.startedAt:null}(j.turns,k,b)),f)}return m}catch(b){return T.error("antigravity-transcript-capture-failed",{worktreeId:a.worktreeId,instanceId:c,error:b instanceof Error?b.message:String(b)}),!1}}async function _(a,b={}){try{let c=await X(a);if(!c)return null;return await ab(b.antigravityHome??Y(),c)}catch{return null}}async function aa(a,b){let[{getDbInstance:d},{findMessageByRequestId:e}]=await Promise.all([Promise.resolve().then(c.bind(c,88807)),Promise.resolve().then(c.bind(c,56791))]),f=d();for(let c=b.length-1;c>=0;c-=1){let d=b[c],g=(0,n.O1)(d.conversationId,d.stepIndex);if(e(f,a.worktreeId,g))return{turns:b.slice(c+1),previousStartedAt:d.startedAt,anchored:!0}}return{turns:b.slice(-1),previousStartedAt:b.length>1?b[b.length-2].startedAt:0,anchored:!1}}async function ab(a,b){let c=V.test(b)?(0,i.join)(Z(a),b,...N):null;if(!c)return null;let d=function(a,b){if(!b.endsWith(".jsonl")||b.includes("\0"))return null;let c=(0,i.resolve)(Z(a)),d=(0,i.resolve)(b);return d===c||d.startsWith(c+i.sep)?d:null}(a,c);return d&&await ac(d)?d:null}async function ac(a){try{return(await (0,g.stat)(a)).isFile()}catch{return!1}}async function ad(a,b,c=0){let d={outcome:"skipped",messageId:null,timestampMs:null},e=b.prompt;if(!e)return d;let f=await (0,m.Ce)(a,(0,n.jN)(b.conversationId,e.stepIndex),e.text,e.timestampMs,c>0?{adoptionFromMs:c}:{});return"failed"===f.outcome?(T.warn("antigravity-transcript-user-turn-failed",{worktreeId:a.worktreeId,instanceId:a.instanceId??a.cliToolId,conversationId:b.conversationId,stepIndex:e.stepIndex}),d):f}async function ae(a,b,d,e,f){let g=a.instanceId??a.cliToolId;if(!(b.closed||b.superseded))return T.info("antigravity-transcript-turn-open",{worktreeId:a.worktreeId,instanceId:g,conversationId:d.conversationId,stepIndex:d.stepIndex,records:b.records.length,textBlocks:d.textBlocks,toolBlocks:d.toolBlocks}),!1;if(0===d.body.length)return T.info("antigravity-transcript-turn-empty",{worktreeId:a.worktreeId,instanceId:g,conversationId:d.conversationId,stepIndex:d.stepIndex,records:b.records.length}),!1;d.unknownRecordTypes.length>0&&T.info("antigravity-transcript-unknown-records",{worktreeId:a.worktreeId,instanceId:g,conversationId:d.conversationId,stepIndex:d.stepIndex,recordTypes:d.unknownRecordTypes}),b.overflowed&&T.info("antigravity-transcript-turn-overflowed",{worktreeId:a.worktreeId,instanceId:g,conversationId:d.conversationId,stepIndex:d.stepIndex});let h=(0,n.O1)(d.conversationId,d.stepIndex),[{getDbInstance:i},{createMessage:j,findMessageByRequestId:k},{broadcastMessage:l}]=await Promise.all([Promise.resolve().then(c.bind(c,88807)),Promise.resolve().then(c.bind(c,56791)),Promise.all([c.e(1503),c.e(4299),c.e(6838),c.e(1719),c.e(2119),c.e(2445),c.e(595)]).then(c.bind(c,49640))]),m=i();if(k(m,a.worktreeId,h))return T.debug("antigravity-transcript-turn-already-saved",{worktreeId:a.worktreeId,instanceId:g,requestId:h}),!0;let o=j(m,{worktreeId:a.worktreeId,role:"assistant",content:d.body,messageType:"normal",timestamp:new Date(e>0?e:Date.now()),cliToolId:a.cliToolId,instanceId:g,requestId:h});return l("message",{worktreeId:a.worktreeId,message:o}),T.info("antigravity-transcript-turn-saved",{worktreeId:a.worktreeId,instanceId:g,conversationId:d.conversationId,requestId:h,path:f,bodyLength:d.body.length,textBlocks:d.textBlocks,toolBlocks:d.toolBlocks}),!0}let af=[".commandcode","projects"],ag=".jsonl",ah="message",ai="\n\n_(truncated)_",aj=["command","file_path","path","pattern","query","url","description"];function ak(a){return!(a.type!==ah||"user"!==a.role||a.isMeta||!a.id||a.blocks.some(a=>"tool_result"===a.type))&&a.text.trim().length>0}function al(a){return a.closed||a.superseded}let am=new Set(["tool_result"]);function an(a){let b=[],c=new Set,d=0,e=0;for(let f of a.blocks){if("text"===f.type){let a=f.text?.trim()??"";if(0===a.length)continue;b.push({kind:"prose",text:a}),d+=1;continue}if("thinking"===f.type){let a=f.text?.trim()??"";if(0===a.length)continue;b.push({kind:"aside",text:function(a){let b=a.trim().split("\n").map(a=>a.length>0?`> ${a}`:">").join("\n");return`> **Thinking**
5
+ ${b}`}(a)});let c=f.content?.trim()??"";for(let a of(c.length>0&&(b.push({kind:"prose",text:c}),d+=1),f.toolCalls))b.push({kind:"tool",text:a.detail?`- \`${a.name}\` — ${a.detail}`:`- \`${a.name}\``}),e+=1;continue}if(f.source===Q){S.has(f.type)||c.add(f.type);continue}T.has(f.type)||c.add(f.type)}let f=(0,p.t3)(b).body;return f.length>2e5&&(f=f.slice(0,2e5-P.length)+P),{conversationId:a.conversationId,stepIndex:a.stepIndex,body:f,textBlocks:d,toolBlocks:e,unknownRecordTypes:[...c]}}(c),function(a,b,c=0,d=null){let e=null===b.timestampMs?a.startedAt:Math.max(a.startedAt,b.timestampMs+1);return Math.max(e,Math.min(c,null===d?1/0:d-1))}(c,k[b],function(a){let b=0;for(let c of a.records)null!==c.timestampMs&&c.timestampMs>b&&(b=c.timestampMs);return b}(c),function(a,b,c){let d=a[c+1];return d?b[c+1]?.timestampMs??d.startedAt:null}(j.turns,k,b)),f)}return m}catch(b){return U.error("antigravity-transcript-capture-failed",{worktreeId:a.worktreeId,instanceId:c,error:b instanceof Error?b.message:String(b)}),!1}}async function aa(a,b={}){try{let c=await Y(a);if(!c)return null;return await ac(b.antigravityHome??Z(),c)}catch{return null}}async function ab(a,b){let[{getDbInstance:d},{findMessageByRequestId:e}]=await Promise.all([Promise.resolve().then(c.bind(c,88807)),Promise.resolve().then(c.bind(c,56791))]),f=d();for(let c=b.length-1;c>=0;c-=1){let d=b[c],g=(0,n.O1)(d.conversationId,d.stepIndex);if(e(f,a.worktreeId,g))return{turns:b.slice(c+1),previousStartedAt:d.startedAt,anchored:!0}}return{turns:b.slice(-1),previousStartedAt:b.length>1?b[b.length-2].startedAt:0,anchored:!1}}async function ac(a,b){let c=W.test(b)?(0,i.join)($(a),b,...O):null;if(!c)return null;let d=function(a,b){if(!b.endsWith(".jsonl")||b.includes("\0"))return null;let c=(0,i.resolve)($(a)),d=(0,i.resolve)(b);return d===c||d.startsWith(c+i.sep)?d:null}(a,c);return d&&await ad(d)?d:null}async function ad(a){try{return(await (0,g.stat)(a)).isFile()}catch{return!1}}async function ae(a,b,c=0){let d={outcome:"skipped",messageId:null,timestampMs:null},e=b.prompt;if(!e)return d;let f=await (0,m.Ce)(a,(0,n.jN)(b.conversationId,e.stepIndex),e.text,e.timestampMs,c>0?{adoptionFromMs:c}:{});return"failed"===f.outcome?(U.warn("antigravity-transcript-user-turn-failed",{worktreeId:a.worktreeId,instanceId:a.instanceId??a.cliToolId,conversationId:b.conversationId,stepIndex:e.stepIndex}),d):f}async function af(a,b,d,e,f){let g=a.instanceId??a.cliToolId;if(!(b.closed||b.superseded))return U.info("antigravity-transcript-turn-open",{worktreeId:a.worktreeId,instanceId:g,conversationId:d.conversationId,stepIndex:d.stepIndex,records:b.records.length,textBlocks:d.textBlocks,toolBlocks:d.toolBlocks}),!1;if(0===d.body.length)return U.info("antigravity-transcript-turn-empty",{worktreeId:a.worktreeId,instanceId:g,conversationId:d.conversationId,stepIndex:d.stepIndex,records:b.records.length}),!1;d.unknownRecordTypes.length>0&&U.info("antigravity-transcript-unknown-records",{worktreeId:a.worktreeId,instanceId:g,conversationId:d.conversationId,stepIndex:d.stepIndex,recordTypes:d.unknownRecordTypes}),b.overflowed&&U.info("antigravity-transcript-turn-overflowed",{worktreeId:a.worktreeId,instanceId:g,conversationId:d.conversationId,stepIndex:d.stepIndex});let h=(0,n.O1)(d.conversationId,d.stepIndex),[{getDbInstance:i},{createMessage:j,findMessageByRequestId:k},{broadcastMessage:l}]=await Promise.all([Promise.resolve().then(c.bind(c,88807)),Promise.resolve().then(c.bind(c,56791)),Promise.all([c.e(1503),c.e(4299),c.e(6838),c.e(1719),c.e(2119),c.e(2445),c.e(595)]).then(c.bind(c,49640))]),m=i();if(k(m,a.worktreeId,h))return U.debug("antigravity-transcript-turn-already-saved",{worktreeId:a.worktreeId,instanceId:g,requestId:h}),!0;let o=j(m,{worktreeId:a.worktreeId,role:"assistant",content:d.body,messageType:"normal",timestamp:new Date(e>0?e:Date.now()),cliToolId:a.cliToolId,instanceId:g,requestId:h});return l("message",{worktreeId:a.worktreeId,message:o}),U.info("antigravity-transcript-turn-saved",{worktreeId:a.worktreeId,instanceId:g,conversationId:d.conversationId,requestId:h,path:f,bodyLength:d.body.length,textBlocks:d.textBlocks,toolBlocks:d.toolBlocks}),!0}let ag=[".commandcode","projects"],ah=".jsonl",ai="message",aj="\n\n_(truncated)_",ak=["command","file_path","path","pattern","query","url","description"];function al(a){return!(a.type!==ai||"user"!==a.role||a.isMeta||!a.id||a.blocks.some(a=>"tool_result"===a.type))&&a.text.trim().length>0}function am(a){return a.closed||a.superseded}let an=new Set(["tool_result"]);function ao(a){let b=[],c=new Set,d=0,e=0;for(let f of a.blocks){if("text"===f.type){let a=f.text?.trim()??"";if(0===a.length)continue;b.push({kind:"prose",text:a}),d+=1;continue}if("thinking"===f.type){let a=f.text?.trim()??"";if(0===a.length)continue;b.push({kind:"aside",text:function(a){let b=a.trim().split("\n").map(a=>a.length>0?`> ${a}`:">").join("\n");return`> **Thinking**
6
6
  >
7
- ${b}`}(a)});continue}if("tool_use"===f.type){b.push({kind:"tool",text:function(a){let b=a.toolName??"tool";return a.toolDetail?`- \`${b}\` — ${a.toolDetail}`:`- \`${b}\``}(f)}),e+=1;continue}am.has(f.type)||c.add(f.type)}let f=(0,p.t3)(b).body;return f.length>2e5&&(f=f.slice(0,2e5-ai.length)+ai),{sessionId:a.sessionId,promptId:a.promptId,body:f,textBlocks:d,toolBlocks:e,unknownBlockTypes:[...c]}}let ao=(0,d.h)("lib/hooks/sources/command-code/history"),ap=/^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$/,aq=globalThis.__commandCodeTranscriptSessions??=new Map,ar=globalThis.__commandCodeTranscriptPaths??=new Map;async function as(a){let b=(0,j.v7)(a.worktreeId,a.cliToolId,a.instanceId);try{let{getLastAgentEvent:d}=await Promise.resolve().then(c.bind(c,48083)),e=d(a.worktreeId,a.cliToolId,a.instanceId)?.sessionId;if("string"==typeof e&&e.length>0)return aq.set(b,e),e}catch(b){ao.debug("command-code-transcript-session-lookup-failed",{worktreeId:a.worktreeId,instanceId:a.instanceId??a.cliToolId,error:b instanceof Error?b.message:String(b)})}return aq.get(b)??null}function at(a){return(0,i.join)(a,...af)}async function au(a,b){let c;if(!ap.test(b))return null;let d=at(a);try{c=await (0,g.readdir)(d,{withFileTypes:!0})}catch{return null}let e=[];for(let a of c){if(!a.isDirectory())continue;let b=0;try{b=(await (0,g.stat)((0,i.join)(d,a.name))).mtimeMs}catch{}e.push({name:a.name,modifiedAt:b})}e.sort((a,b)=>b.modifiedAt-a.modifiedAt);let f=`${b}${ag}`;for(let a of e){let b=(0,i.join)(d,a.name,f);if(await az(b))return b}return null}async function av(a,b){let c=a.instanceId??a.cliToolId;try{let d=b.commandCodeHome??(0,h.homedir)(),e=await as(a),f=await ay(d,b,e);if(!f)return ao.debug("command-code-transcript-unavailable",{worktreeId:a.worktreeId,instanceId:c,sessionId:e,reason:e?"no-file":"no-session-pointer"}),!1;let g=await l(f);if(null===g)return!1;let i=function(a){let b=[],c=0,d=null,e=null,f=null;for(let g of a.split("\n")){let a;if(0===g.trim().length)continue;try{a=JSON.parse(g)}catch{c+=1;continue}let h=function(a){if(!(0,o.Qd)(a))return null;let b=(0,o.O2)(a,"type");if(!b)return null;let c="session"===b,d=(0,o.Qd)(a.message)?a.message:null,e=d&&(0,o.Qd)(d.meta)?d.meta:null,f=d?.content,g=[],h="";if("string"==typeof f)h=f;else if(Array.isArray(f))for(let a of f){let b=function(a){if(!(0,o.Qd)(a))return null;let b=(0,o.O2)(a,"type");if(!b)return null;if("tool_use"===b)return{type:b,text:null,toolName:(0,o.O2)(a,"name"),toolDetail:function(a){if(!(0,o.Qd)(a))return null;for(let c of aj){let d=(0,o.O2)(a,c);if(d){var b;return(b=d.replace(/\s+/g," ").trim()).length<=200?b:`${b.slice(0,199)}…`}}return null}(a.input)};let c="text"===b?(0,o.O2)(a,"text")??"":"thinking"===b?(0,o.O2)(a,"thinking")??"":null;return{type:b,text:c,toolName:null,toolDetail:null}}(a);b&&(g.push(b),"text"===b.type&&b.text&&(h+=b.text))}let i=(0,o.O2)(a,"timestamp"),j=i?Date.parse(i):NaN,k=e&&"number"==typeof e.createdAt?e.createdAt:null;return{type:b,id:c?null:(0,o.O2)(a,"id"),parentId:(0,o.O2)(a,"parentId"),role:d?(0,o.O2)(d,"role"):null,sessionId:c?(0,o.O2)(a,"id"):null,cwd:c?(0,o.O2)(a,"cwd"):null,parentSession:c?(0,o.O2)(a,"parentSession"):null,source:e?(0,o.O2)(e,"source"):null,isMeta:e?.isMeta===!0,isSummary:e?.isSummary===!0,isAutomated:e?.isAutomated===!0,timestampMs:null!==k&&Number.isFinite(k)?k:Number.isFinite(j)?j:null,blocks:g,text:h}}(a);if(!h){c+=1;continue}b.push(h),h.sessionId&&(d=h.sessionId,e=h.cwd,f=h.parentSession)}return{records:b,malformedLines:c,sessionId:d,cwd:e,parentSession:f}}(g),j=function(a,b){let c=[],d=new Set,e=null,f=0,g=0,h=0,i=b;for(let b of a){if(b.sessionId){i=b.sessionId;continue}if(b.type!==ah){h+=1,b.id&&d.add(b.id);continue}if(null===b.parentId||d.has(b.parentId)||(g+=1),b.id&&d.add(b.id),ak(b)){e=function(a,b){return{sessionId:b,promptId:a.id,startedAt:a.timestampMs??0,promptText:a.text,promptIsOperatorInput:!!ak(a)&&!a.isSummary&&!a.isAutomated&&"user"===a.source,blocks:[],assistantRecords:0,closed:!1,superseded:!1,overflowed:!1}}(b,i),c.push(e);continue}if("assistant"===b.role){if(!e){f+=1;continue}for(let a of(e.assistantRecords+=1,e.closed=!(b.type!==ah||"assistant"!==b.role||b.blocks.some(a=>"tool_use"===a.type))&&b.blocks.some(a=>"text"===a.type&&(a.text??"").trim().length>0),b.blocks)){if(e.blocks.length>=2048){e.overflowed=!0;break}e.blocks.push(a)}}}for(let a=0;a<c.length-1;a+=1)c[a].superseded=!0;return{turns:c,orphanedAssistantRecords:f,unresolvedParentRecords:g,nonMessageRecords:h}}(i.records,i.sessionId??e??"");if(0===j.turns.length)return ao.info("command-code-transcript-no-turn",{worktreeId:a.worktreeId,instanceId:c,path:f,records:i.records.length,malformedLines:i.malformedLines,orphanedAssistantRecords:j.orphanedAssistantRecords}),!1;(i.malformedLines>0||j.orphanedAssistantRecords>0||null!==i.parentSession)&&ao.info("command-code-transcript-partial-read",{worktreeId:a.worktreeId,instanceId:c,path:f,malformedLines:i.malformedLines,orphanedAssistantRecords:j.orphanedAssistantRecords,unresolvedParentRecords:j.unresolvedParentRecords,nonMessageRecords:j.nonMessageRecords,parentSession:i.parentSession});let k=await aw(a,j.turns);if(await aD(a,j.turns.slice(0,j.turns.length-k.turns.length).slice(-aB),f),0===k.turns.length)return ao.debug("command-code-transcript-turns-already-saved",{worktreeId:a.worktreeId,instanceId:c,turnsInWindow:j.turns.length}),!0;k.turns.length>1&&ao.info("command-code-transcript-backfilling-turns",{worktreeId:a.worktreeId,instanceId:c,path:f,pendingTurns:k.turns.length,turnsInWindow:j.turns.length,anchored:k.anchored});let m=[];for(let b=0;b<k.turns.length;b+=1){let c=0===b?k.previousStartedAt:k.turns[b-1].startedAt;m.push(await aA(a,k.turns[b],c))}let n=function(a){let b=new Map,c=null;for(let d of a)if(!d.sessionId&&d.type===ah){if(ak(d)){c=d.id;continue}"assistant"===d.role&&null!==c&&null!==d.timestampMs&&d.timestampMs>(b.get(c)??0)&&b.set(c,d.timestampMs)}return b}(i.records),p=!1;for(let b=0;b<k.turns.length;b+=1){let c=k.turns[b];p=await aE(a,c,an(c),function(a,b,c=0,d=null){let e=null===b.timestampMs?a.startedAt:Math.max(a.startedAt,b.timestampMs+1);return Math.max(e,Math.min(c,null===d?1/0:d-1))}(c,m[b],n.get(c.promptId)??0,function(a,b,c){let d=a[c+1];return d?b[c+1]?.timestampMs??d.startedAt:null}(k.turns,m,b)),f)}return p}catch(b){return ao.error("command-code-transcript-capture-failed",{worktreeId:a.worktreeId,instanceId:c,error:b instanceof Error?b.message:String(b)}),!1}}async function aw(a,b){let[{getDbInstance:d},{findMessageByRequestId:e}]=await Promise.all([Promise.resolve().then(c.bind(c,88807)),Promise.resolve().then(c.bind(c,56791))]),f=d();for(let c=b.length-1;c>=0;c-=1){let d=(0,n.sT)(b[c].promptId);if(e(f,a.worktreeId,d))return{turns:b.slice(c+1),previousStartedAt:b[c].startedAt,anchored:!0}}return{turns:b.slice(-1),previousStartedAt:b.length>1?b[b.length-2].startedAt:0,anchored:!1}}async function ax(a,b){try{let c=b.commandCodeHome??(0,h.homedir)();return await ay(c,b,await as(a))}catch{return null}}async function ay(a,b,c){let d=b.transcriptPathHint;if("string"==typeof d&&d.length>0){let b=function(a,b){if(!b.endsWith(ag)||b.includes("\0"))return null;let c=(0,i.resolve)(at(a)),d=(0,i.resolve)(b);return d===c||d.startsWith(c+i.sep)?d:null}(a,d);if(b&&await az(b))return b}if(!c)return null;let e=`${a}\0${c}`,f=ar.get(e);if(f&&await az(f))return f;let g=await au(a,c);return g?ar.set(e,g):ar.delete(e),g}async function az(a){try{return(await (0,g.stat)(a)).isFile()}catch{return!1}}async function aA(a,b,c=0){let d=a.instanceId??a.cliToolId;if(!b.promptIsOperatorInput)return ao.debug("command-code-transcript-user-turn-skipped",{worktreeId:a.worktreeId,instanceId:d,promptId:b.promptId,reason:"not-operator-input"}),{outcome:"skipped",messageId:null,timestampMs:null};let e=await (0,m.Ce)(a,(0,n.TW)(b.promptId),b.promptText,b.startedAt,c>0?{adoptionFromMs:c}:{});return"failed"===e.outcome&&ao.warn("command-code-transcript-user-turn-failed",{worktreeId:a.worktreeId,instanceId:d,sessionId:b.sessionId,promptId:b.promptId}),e}let aB=3;async function aC(a,b,d,e){let f=a.instanceId??a.cliToolId,g=b.content.length;if(d.body.length<=g)return!1;let[{getDbInstance:h},{updateMessageContent:i},{broadcastMessage:j}]=await Promise.all([Promise.resolve().then(c.bind(c,88807)),Promise.resolve().then(c.bind(c,56791)),Promise.all([c.e(1503),c.e(4299),c.e(6838),c.e(1719),c.e(2119),c.e(2445),c.e(595)]).then(c.bind(c,49640))]);return i(h(),b.id,d.body),j("message_updated",{worktreeId:a.worktreeId,message:{...b,content:d.body}}),ao.info("command-code-transcript-turn-updated",{worktreeId:a.worktreeId,instanceId:f,sessionId:d.sessionId,requestId:b.requestId,path:e,previousLength:g,bodyLength:d.body.length,textBlocks:d.textBlocks,toolBlocks:d.toolBlocks}),!0}async function aD(a,b,d){if(0===b.length)return 0;let[{getDbInstance:e},{findMessageByRequestId:f}]=await Promise.all([Promise.resolve().then(c.bind(c,88807)),Promise.resolve().then(c.bind(c,56791))]),g=e(),h=0;for(let c of b){if(!al(c))continue;let b=f(g,a.worktreeId,(0,n.sT)(c.promptId));b&&await aC(a,b,an(c),d)&&(h+=1)}return h}async function aE(a,b,d,e,f){let g=a.instanceId??a.cliToolId;if(!al(b))return ao.info("command-code-transcript-turn-open",{worktreeId:a.worktreeId,instanceId:g,sessionId:d.sessionId,promptId:d.promptId,assistantRecords:b.assistantRecords,textBlocks:d.textBlocks,toolBlocks:d.toolBlocks}),!1;if(0===d.body.length)return ao.info("command-code-transcript-turn-empty",{worktreeId:a.worktreeId,instanceId:g,sessionId:d.sessionId,promptId:d.promptId}),!1;d.unknownBlockTypes.length>0&&ao.info("command-code-transcript-unknown-blocks",{worktreeId:a.worktreeId,instanceId:g,sessionId:d.sessionId,blockTypes:d.unknownBlockTypes});let h=(0,n.sT)(d.promptId),[{getDbInstance:i},{createMessage:j,findMessageByRequestId:k},{broadcastMessage:l}]=await Promise.all([Promise.resolve().then(c.bind(c,88807)),Promise.resolve().then(c.bind(c,56791)),Promise.all([c.e(1503),c.e(4299),c.e(6838),c.e(1719),c.e(2119),c.e(2445),c.e(595)]).then(c.bind(c,49640))]),m=i(),o=k(m,a.worktreeId,h);if(o)return ao.debug("command-code-transcript-turn-already-saved",{worktreeId:a.worktreeId,instanceId:g,requestId:h}),await aC(a,o,d,f),!0;let p=j(m,{worktreeId:a.worktreeId,role:"assistant",content:d.body,messageType:"normal",timestamp:new Date(e>0?e:Date.now()),cliToolId:a.cliToolId,instanceId:g,requestId:h});return l("message",{worktreeId:a.worktreeId,message:p}),ao.info("command-code-transcript-turn-saved",{worktreeId:a.worktreeId,instanceId:g,sessionId:d.sessionId,requestId:h,path:f,bodyLength:d.body.length,textBlocks:d.textBlocks,toolBlocks:d.toolBlocks}),!0}var aF=c(70997),aG=c(2734),aH=c(76835),aI=c(28862),aJ=c(129),aK=c(43925);let aL=(0,d.h)("lib/polling/structured-history-gate"),aM=globalThis.__structuredHistoryCaptureQueue??=new Map;function aN(){aM.clear()}let aO={[aF.v]:{capture:(a,b)=>(0,f.K$)(a,b),locate:(a,b)=>(0,f.Oi)(a,b)},[aG.c]:{capture:(a,b)=>G(a,b),locate:(a,b)=>H(a,b)},[aH.F]:{capture:(a,b)=>$(a,b),locate:(a,b)=>_(a,b)},[aI.k]:{capture:(a,b)=>av(a,b),locate:(a,b)=>ax(a,b)}};function aP(a){try{return(0,aJ.VM)(a).capabilities.transcriptHistory??null}catch(b){return aL.warn("structured-history-capability-unavailable",{cliToolId:a,error:b instanceof Error?b.message:String(b)}),null}}function aQ(a){return"pull"===aP(a)}function aR(a,b,c){if("push"!==aP(b))return!1;try{return(0,e.f4)({worktreeId:a,cliToolId:b,instanceId:c??b})}catch(d){return aL.warn("structured-history-gate-unavailable",{worktreeId:a,cliToolId:b,instanceId:c??b,error:d instanceof Error?d.message:String(d)}),!1}}async function aS(a,b,c,d){if(!aQ(b))return!1;let e=aO[b];if(!e)return aL.warn("structured-history-reader-missing",{worktreeId:a,cliToolId:b,instanceId:c??b}),!1;let f=c??b;return function(a,b){let c=(aM.get(a)??Promise.resolve()).then(b,b),d=c.then(()=>void 0,()=>void 0);return aM.set(a,d),d.then(()=>{aM.get(a)===d&&aM.delete(a)}),c}(`${a}\u0000${b}\u0000${f}`,async()=>{try{let c=await e.capture({worktreeId:a,cliToolId:b,instanceId:f},d);return c&&(0,aK.vQ)(a,b,f,!0),c}catch(c){return aL.warn("structured-history-capture-unavailable",{worktreeId:a,cliToolId:b,instanceId:f,error:c instanceof Error?c.message:String(c)}),!1}})}async function aT(a,b,c,d){let e=aQ(b)?aO[b]:void 0;if(!e)return!1;try{let f=await e.locate({worktreeId:a,cliToolId:b,instanceId:c??b},d);return null!==f}catch(d){return aL.warn("structured-history-locate-unavailable",{worktreeId:a,cliToolId:b,instanceId:c??b,error:d instanceof Error?d.message:String(d)}),!1}}},79696:(a,b,c)=>{c.d(b,{K$:()=>G,readClaudeTurnProgress:()=>J,Oi:()=>I});var d=c(79748),e=c(21820),f=c(33873),g=c(24455),h=c(18201),i=c(72626),j=c(86594),k=c(57510),l=c(27128);let m=[".claude","projects"],n="\n\n_(truncated)_",o=["<local-command-caveat>","<local-command-stdout>","<command-name>"],p="<command-message>",q=/<command-name>([\s\S]*?)<\/command-name>/,r=/<command-args>([\s\S]*?)<\/command-args>/;function s(a){let b=a.trim();if(!b.startsWith(p))return null;let c=q.exec(b)?.[1].trim()??"";if(0===c.length)return null;let d=r.exec(b)?.[1].trim()??"";return 0===d.length?c:`${c} ${d}`}let t=["command","file_path","notebook_path","path","pattern","query","url","description"];function u(a){let b=[],c=0;for(let d of a.split("\n")){let a;if(0===d.trim().length)continue;try{a=JSON.parse(d)}catch{c+=1;continue}let e=function(a){if(!(0,k.Qd)(a))return null;let b=(0,k.O2)(a,"type");if(!b)return null;let c=(0,k.Qd)(a.message)?a.message:null,d=c?.content,e=[],f="";if("string"==typeof d)f=d;else if(Array.isArray(d))for(let a of d){let b=function(a){if(!(0,k.Qd)(a))return null;let b=(0,k.O2)(a,"type");if(!b)return null;if("tool_use"===b)return{type:b,text:null,toolName:(0,k.O2)(a,"name"),toolDetail:function(a){if(!(0,k.Qd)(a))return null;for(let c of t){let d=(0,k.O2)(a,c);if(d){var b;return(b=d.replace(/\s+/g," ").trim()).length<=200?b:`${b.slice(0,199)}…`}}return null}(a.input)};let c="text"===b?(0,k.O2)(a,"text")??"":"thinking"===b?(0,k.O2)(a,"thinking")??"":null;return{type:b,text:c,toolName:null,toolDetail:null}}(a);b&&(e.push(b),b.text&&(f+=b.text))}let g=(0,k.O2)(a,"timestamp"),h=g?Date.parse(g):NaN,i=(0,k.Qd)(a.origin)?a.origin:null;return{type:b,uuid:(0,k.O2)(a,"uuid"),sessionId:(0,k.O2)(a,"sessionId")??(0,k.O2)(a,"session_id"),cwd:(0,k.O2)(a,"cwd"),isSidechain:!0===a.isSidechain,isMeta:!0===a.isMeta,originKind:i?(0,k.O2)(i,"kind"):null,promptSource:(0,k.O2)(a,"promptSource"),isCompactSummary:!0===a.isCompactSummary,isInterruption:null!==(0,k.O2)(a,"interruptedMessageId"),timestampMs:Number.isFinite(h)?h:null,stopReason:c?(0,k.O2)(c,"stop_reason"):null,blocks:e,text:f}}(a);e?b.push(e):c+=1}return{records:b,malformedLines:c}}function v(a){if("user"!==a.type||a.isMeta||!a.uuid||a.blocks.some(a=>"tool_result"===a.type))return!1;let b=a.text.trim();return 0!==b.length&&(b.startsWith(p)?null!==s(b):!o.some(a=>b.startsWith(a)))}let w=["typed","queued"];function x(a){return!!a.closed||!!a.superseded||!a.stopReasonObserved}function y(a,b){let c=[],d=null,e=0,f=0;for(let g of a){if(g.isSidechain){f+=1;continue}if(v(g)){d=function(a,b){return{sessionId:a.sessionId??b,promptUuid:a.uuid,startedAt:a.timestampMs??0,promptText:s(a.text)??a.text,promptIsOperatorInput:!!v(a)&&!a.isCompactSummary&&!a.isInterruption&&(null!==a.originKind?"human"===a.originKind:null!==a.promptSource&&w.includes(a.promptSource)),blocks:[],assistantRecords:0,closed:!1,superseded:!1,stopReasonObserved:!1,overflowed:!1}}(g,b),c.push(d);continue}if("assistant"===g.type){if(!d){e+=1;continue}for(let a of(d.assistantRecords+=1,d.closed="assistant"===g.type&&"end_turn"===g.stopReason&&g.blocks.some(a=>"text"===a.type&&(a.text??"").trim().length>0),null!==g.stopReason&&(d.stopReasonObserved=!0),g.blocks)){if(d.blocks.length>=2048){d.overflowed=!0;break}d.blocks.push(a)}}}for(let a=0;a<c.length-1;a+=1)c[a].superseded=!0;return{turns:c,orphanedAssistantRecords:e,sidechainRecords:f}}let z=new Set(["tool_result"]);function A(a){let b=[],c=new Set,d=0,e=0;for(let f of a.blocks){if("text"===f.type){let a=f.text?.trim()??"";if(0===a.length)continue;b.push({kind:"prose",text:a}),d+=1;continue}if("thinking"===f.type){let a=f.text?.trim()??"";if(0===a.length)continue;b.push({kind:"aside",text:function(a){let b=a.trim().split("\n").map(a=>a.length>0?`> ${a}`:">").join("\n");return`> **Thinking**
7
+ ${b}`}(a)});continue}if("tool_use"===f.type){b.push({kind:"tool",text:function(a){let b=a.toolName??"tool";return a.toolDetail?`- \`${b}\` — ${a.toolDetail}`:`- \`${b}\``}(f)}),e+=1;continue}an.has(f.type)||c.add(f.type)}let f=(0,p.t3)(b).body;return f.length>2e5&&(f=f.slice(0,2e5-aj.length)+aj),{sessionId:a.sessionId,promptId:a.promptId,body:f,textBlocks:d,toolBlocks:e,unknownBlockTypes:[...c]}}let ap=(0,d.h)("lib/hooks/sources/command-code/history"),aq=/^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$/,ar=globalThis.__commandCodeTranscriptSessions??=new Map,as=globalThis.__commandCodeTranscriptPaths??=new Map;async function at(a){let b=(0,j.v7)(a.worktreeId,a.cliToolId,a.instanceId);try{let{getLastAgentEvent:d}=await Promise.resolve().then(c.bind(c,48083)),e=d(a.worktreeId,a.cliToolId,a.instanceId)?.sessionId;if("string"==typeof e&&e.length>0)return ar.set(b,e),e}catch(b){ap.debug("command-code-transcript-session-lookup-failed",{worktreeId:a.worktreeId,instanceId:a.instanceId??a.cliToolId,error:b instanceof Error?b.message:String(b)})}return ar.get(b)??null}function au(a){return(0,i.join)(a,...ag)}async function av(a,b){let c;if(!aq.test(b))return null;let d=au(a);try{c=await (0,g.readdir)(d,{withFileTypes:!0})}catch{return null}let e=[];for(let a of c){if(!a.isDirectory())continue;let b=0;try{b=(await (0,g.stat)((0,i.join)(d,a.name))).mtimeMs}catch{}e.push({name:a.name,modifiedAt:b})}e.sort((a,b)=>b.modifiedAt-a.modifiedAt);let f=`${b}${ah}`;for(let a of e){let b=(0,i.join)(d,a.name,f);if(await aA(b))return b}return null}async function aw(a,b){let c=a.instanceId??a.cliToolId;try{let d=b.commandCodeHome??(0,h.homedir)(),e=await at(a),f=await az(d,b,e);if(!f)return ap.debug("command-code-transcript-unavailable",{worktreeId:a.worktreeId,instanceId:c,sessionId:e,reason:e?"no-file":"no-session-pointer"}),!1;let g=await l(f);if(null===g)return!1;let i=function(a){let b=[],c=0,d=null,e=null,f=null;for(let g of a.split("\n")){let a;if(0===g.trim().length)continue;try{a=JSON.parse(g)}catch{c+=1;continue}let h=function(a){if(!(0,o.Qd)(a))return null;let b=(0,o.O2)(a,"type");if(!b)return null;let c="session"===b,d=(0,o.Qd)(a.message)?a.message:null,e=d&&(0,o.Qd)(d.meta)?d.meta:null,f=d?.content,g=[],h="";if("string"==typeof f)h=f;else if(Array.isArray(f))for(let a of f){let b=function(a){if(!(0,o.Qd)(a))return null;let b=(0,o.O2)(a,"type");if(!b)return null;if("tool_use"===b)return{type:b,text:null,toolName:(0,o.O2)(a,"name"),toolDetail:function(a){if(!(0,o.Qd)(a))return null;for(let c of ak){let d=(0,o.O2)(a,c);if(d){var b;return(b=d.replace(/\s+/g," ").trim()).length<=200?b:`${b.slice(0,199)}…`}}return null}(a.input)};let c="text"===b?(0,o.O2)(a,"text")??"":"thinking"===b?(0,o.O2)(a,"thinking")??"":null;return{type:b,text:c,toolName:null,toolDetail:null}}(a);b&&(g.push(b),"text"===b.type&&b.text&&(h+=b.text))}let i=(0,o.O2)(a,"timestamp"),j=i?Date.parse(i):NaN,k=e&&"number"==typeof e.createdAt?e.createdAt:null;return{type:b,id:c?null:(0,o.O2)(a,"id"),parentId:(0,o.O2)(a,"parentId"),role:d?(0,o.O2)(d,"role"):null,sessionId:c?(0,o.O2)(a,"id"):null,cwd:c?(0,o.O2)(a,"cwd"):null,parentSession:c?(0,o.O2)(a,"parentSession"):null,source:e?(0,o.O2)(e,"source"):null,isMeta:e?.isMeta===!0,isSummary:e?.isSummary===!0,isAutomated:e?.isAutomated===!0,timestampMs:null!==k&&Number.isFinite(k)?k:Number.isFinite(j)?j:null,blocks:g,text:h}}(a);if(!h){c+=1;continue}b.push(h),h.sessionId&&(d=h.sessionId,e=h.cwd,f=h.parentSession)}return{records:b,malformedLines:c,sessionId:d,cwd:e,parentSession:f}}(g),j=function(a,b){let c=[],d=new Set,e=null,f=0,g=0,h=0,i=b;for(let b of a){if(b.sessionId){i=b.sessionId;continue}if(b.type!==ai){h+=1,b.id&&d.add(b.id);continue}if(null===b.parentId||d.has(b.parentId)||(g+=1),b.id&&d.add(b.id),al(b)){e=function(a,b){return{sessionId:b,promptId:a.id,startedAt:a.timestampMs??0,promptText:a.text,promptIsOperatorInput:!!al(a)&&!a.isSummary&&!a.isAutomated&&"user"===a.source,blocks:[],assistantRecords:0,closed:!1,superseded:!1,overflowed:!1}}(b,i),c.push(e);continue}if("assistant"===b.role){if(!e){f+=1;continue}for(let a of(e.assistantRecords+=1,e.closed=!(b.type!==ai||"assistant"!==b.role||b.blocks.some(a=>"tool_use"===a.type))&&b.blocks.some(a=>"text"===a.type&&(a.text??"").trim().length>0),b.blocks)){if(e.blocks.length>=2048){e.overflowed=!0;break}e.blocks.push(a)}}}for(let a=0;a<c.length-1;a+=1)c[a].superseded=!0;return{turns:c,orphanedAssistantRecords:f,unresolvedParentRecords:g,nonMessageRecords:h}}(i.records,i.sessionId??e??"");if(0===j.turns.length)return ap.info("command-code-transcript-no-turn",{worktreeId:a.worktreeId,instanceId:c,path:f,records:i.records.length,malformedLines:i.malformedLines,orphanedAssistantRecords:j.orphanedAssistantRecords}),!1;(i.malformedLines>0||j.orphanedAssistantRecords>0||null!==i.parentSession)&&ap.info("command-code-transcript-partial-read",{worktreeId:a.worktreeId,instanceId:c,path:f,malformedLines:i.malformedLines,orphanedAssistantRecords:j.orphanedAssistantRecords,unresolvedParentRecords:j.unresolvedParentRecords,nonMessageRecords:j.nonMessageRecords,parentSession:i.parentSession});let k=await ax(a,j.turns);if(await aE(a,j.turns.slice(0,j.turns.length-k.turns.length).slice(-aC),f),0===k.turns.length)return ap.debug("command-code-transcript-turns-already-saved",{worktreeId:a.worktreeId,instanceId:c,turnsInWindow:j.turns.length}),!0;k.turns.length>1&&ap.info("command-code-transcript-backfilling-turns",{worktreeId:a.worktreeId,instanceId:c,path:f,pendingTurns:k.turns.length,turnsInWindow:j.turns.length,anchored:k.anchored});let m=[];for(let b=0;b<k.turns.length;b+=1){let c=0===b?k.previousStartedAt:k.turns[b-1].startedAt;m.push(await aB(a,k.turns[b],c))}let n=function(a){let b=new Map,c=null;for(let d of a)if(!d.sessionId&&d.type===ai){if(al(d)){c=d.id;continue}"assistant"===d.role&&null!==c&&null!==d.timestampMs&&d.timestampMs>(b.get(c)??0)&&b.set(c,d.timestampMs)}return b}(i.records),p=!1;for(let b=0;b<k.turns.length;b+=1){let c=k.turns[b];p=await aF(a,c,ao(c),function(a,b,c=0,d=null){let e=null===b.timestampMs?a.startedAt:Math.max(a.startedAt,b.timestampMs+1);return Math.max(e,Math.min(c,null===d?1/0:d-1))}(c,m[b],n.get(c.promptId)??0,function(a,b,c){let d=a[c+1];return d?b[c+1]?.timestampMs??d.startedAt:null}(k.turns,m,b)),f)}return p}catch(b){return ap.error("command-code-transcript-capture-failed",{worktreeId:a.worktreeId,instanceId:c,error:b instanceof Error?b.message:String(b)}),!1}}async function ax(a,b){let[{getDbInstance:d},{findMessageByRequestId:e}]=await Promise.all([Promise.resolve().then(c.bind(c,88807)),Promise.resolve().then(c.bind(c,56791))]),f=d();for(let c=b.length-1;c>=0;c-=1){let d=(0,n.sT)(b[c].promptId);if(e(f,a.worktreeId,d))return{turns:b.slice(c+1),previousStartedAt:b[c].startedAt,anchored:!0}}return{turns:b.slice(-1),previousStartedAt:b.length>1?b[b.length-2].startedAt:0,anchored:!1}}async function ay(a,b){try{let c=b.commandCodeHome??(0,h.homedir)();return await az(c,b,await at(a))}catch{return null}}async function az(a,b,c){let d=b.transcriptPathHint;if("string"==typeof d&&d.length>0){let b=function(a,b){if(!b.endsWith(ah)||b.includes("\0"))return null;let c=(0,i.resolve)(au(a)),d=(0,i.resolve)(b);return d===c||d.startsWith(c+i.sep)?d:null}(a,d);if(b&&await aA(b))return b}if(!c)return null;let e=`${a}\0${c}`,f=as.get(e);if(f&&await aA(f))return f;let g=await av(a,c);return g?as.set(e,g):as.delete(e),g}async function aA(a){try{return(await (0,g.stat)(a)).isFile()}catch{return!1}}async function aB(a,b,c=0){let d=a.instanceId??a.cliToolId;if(!b.promptIsOperatorInput)return ap.debug("command-code-transcript-user-turn-skipped",{worktreeId:a.worktreeId,instanceId:d,promptId:b.promptId,reason:"not-operator-input"}),{outcome:"skipped",messageId:null,timestampMs:null};let e=await (0,m.Ce)(a,(0,n.TW)(b.promptId),b.promptText,b.startedAt,c>0?{adoptionFromMs:c}:{});return"failed"===e.outcome&&ap.warn("command-code-transcript-user-turn-failed",{worktreeId:a.worktreeId,instanceId:d,sessionId:b.sessionId,promptId:b.promptId}),e}let aC=3;async function aD(a,b,d,e){let f=a.instanceId??a.cliToolId,g=b.content.length;if(d.body.length<=g)return!1;let[{getDbInstance:h},{updateMessageContent:i},{broadcastMessage:j}]=await Promise.all([Promise.resolve().then(c.bind(c,88807)),Promise.resolve().then(c.bind(c,56791)),Promise.all([c.e(1503),c.e(4299),c.e(6838),c.e(1719),c.e(2119),c.e(2445),c.e(595)]).then(c.bind(c,49640))]);return i(h(),b.id,d.body),j("message_updated",{worktreeId:a.worktreeId,message:{...b,content:d.body}}),ap.info("command-code-transcript-turn-updated",{worktreeId:a.worktreeId,instanceId:f,sessionId:d.sessionId,requestId:b.requestId,path:e,previousLength:g,bodyLength:d.body.length,textBlocks:d.textBlocks,toolBlocks:d.toolBlocks}),!0}async function aE(a,b,d){if(0===b.length)return 0;let[{getDbInstance:e},{findMessageByRequestId:f}]=await Promise.all([Promise.resolve().then(c.bind(c,88807)),Promise.resolve().then(c.bind(c,56791))]),g=e(),h=0;for(let c of b){if(!am(c))continue;let b=f(g,a.worktreeId,(0,n.sT)(c.promptId));b&&await aD(a,b,ao(c),d)&&(h+=1)}return h}async function aF(a,b,d,e,f){let g=a.instanceId??a.cliToolId;if(!am(b))return ap.info("command-code-transcript-turn-open",{worktreeId:a.worktreeId,instanceId:g,sessionId:d.sessionId,promptId:d.promptId,assistantRecords:b.assistantRecords,textBlocks:d.textBlocks,toolBlocks:d.toolBlocks}),!1;if(0===d.body.length)return ap.info("command-code-transcript-turn-empty",{worktreeId:a.worktreeId,instanceId:g,sessionId:d.sessionId,promptId:d.promptId}),!1;d.unknownBlockTypes.length>0&&ap.info("command-code-transcript-unknown-blocks",{worktreeId:a.worktreeId,instanceId:g,sessionId:d.sessionId,blockTypes:d.unknownBlockTypes});let h=(0,n.sT)(d.promptId),[{getDbInstance:i},{createMessage:j,findMessageByRequestId:k},{broadcastMessage:l}]=await Promise.all([Promise.resolve().then(c.bind(c,88807)),Promise.resolve().then(c.bind(c,56791)),Promise.all([c.e(1503),c.e(4299),c.e(6838),c.e(1719),c.e(2119),c.e(2445),c.e(595)]).then(c.bind(c,49640))]),m=i(),o=k(m,a.worktreeId,h);if(o)return ap.debug("command-code-transcript-turn-already-saved",{worktreeId:a.worktreeId,instanceId:g,requestId:h}),await aD(a,o,d,f),!0;let p=j(m,{worktreeId:a.worktreeId,role:"assistant",content:d.body,messageType:"normal",timestamp:new Date(e>0?e:Date.now()),cliToolId:a.cliToolId,instanceId:g,requestId:h});return l("message",{worktreeId:a.worktreeId,message:p}),ap.info("command-code-transcript-turn-saved",{worktreeId:a.worktreeId,instanceId:g,sessionId:d.sessionId,requestId:h,path:f,bodyLength:d.body.length,textBlocks:d.textBlocks,toolBlocks:d.toolBlocks}),!0}var aG=c(70997),aH=c(2734),aI=c(76835),aJ=c(28862),aK=c(129),aL=c(43925);let aM=(0,d.h)("lib/polling/structured-history-gate"),aN=globalThis.__structuredHistoryCaptureQueue??=new Map;function aO(){aN.clear()}let aP={[aG.v]:{capture:(a,b)=>(0,f.K$)(a,b),locate:(a,b)=>(0,f.Oi)(a,b)},[aH.c]:{capture:(a,b)=>H(a,b),locate:(a,b)=>I(a,b)},[aI.F]:{capture:(a,b)=>_(a,b),locate:(a,b)=>aa(a,b)},[aJ.k]:{capture:(a,b)=>aw(a,b),locate:(a,b)=>ay(a,b)}};function aQ(a){try{return(0,aK.VM)(a).capabilities.transcriptHistory??null}catch(b){return aM.warn("structured-history-capability-unavailable",{cliToolId:a,error:b instanceof Error?b.message:String(b)}),null}}function aR(a){return"pull"===aQ(a)}function aS(a,b,c){if("push"!==aQ(b))return!1;try{return(0,e.f4)({worktreeId:a,cliToolId:b,instanceId:c??b})}catch(d){return aM.warn("structured-history-gate-unavailable",{worktreeId:a,cliToolId:b,instanceId:c??b,error:d instanceof Error?d.message:String(d)}),!1}}async function aT(a,b,c,d){if(!aR(b))return!1;let e=aP[b];if(!e)return aM.warn("structured-history-reader-missing",{worktreeId:a,cliToolId:b,instanceId:c??b}),!1;let f=c??b;return function(a,b){let c=(aN.get(a)??Promise.resolve()).then(b,b),d=c.then(()=>void 0,()=>void 0);return aN.set(a,d),d.then(()=>{aN.get(a)===d&&aN.delete(a)}),c}(`${a}\u0000${b}\u0000${f}`,async()=>{try{let c=await e.capture({worktreeId:a,cliToolId:b,instanceId:f},d);return c&&(0,aL.vQ)(a,b,f,!0),c}catch(c){return aM.warn("structured-history-capture-unavailable",{worktreeId:a,cliToolId:b,instanceId:f,error:c instanceof Error?c.message:String(c)}),!1}})}async function aU(a,b,c,d){let e=aR(b)?aP[b]:void 0;if(!e)return!1;try{let f=await e.locate({worktreeId:a,cliToolId:b,instanceId:c??b},d);return null!==f}catch(d){return aM.warn("structured-history-locate-unavailable",{worktreeId:a,cliToolId:b,instanceId:c??b,error:d instanceof Error?d.message:String(d)}),!1}}},79696:(a,b,c)=>{c.d(b,{K$:()=>G,readClaudeTurnProgress:()=>J,Oi:()=>I});var d=c(79748),e=c(21820),f=c(33873),g=c(24455),h=c(18201),i=c(72626),j=c(86594),k=c(57510),l=c(27128);let m=[".claude","projects"],n="\n\n_(truncated)_",o=["<local-command-caveat>","<local-command-stdout>","<command-name>"],p="<command-message>",q=/<command-name>([\s\S]*?)<\/command-name>/,r=/<command-args>([\s\S]*?)<\/command-args>/;function s(a){let b=a.trim();if(!b.startsWith(p))return null;let c=q.exec(b)?.[1].trim()??"";if(0===c.length)return null;let d=r.exec(b)?.[1].trim()??"";return 0===d.length?c:`${c} ${d}`}let t=["command","file_path","notebook_path","path","pattern","query","url","description"];function u(a){let b=[],c=0;for(let d of a.split("\n")){let a;if(0===d.trim().length)continue;try{a=JSON.parse(d)}catch{c+=1;continue}let e=function(a){if(!(0,k.Qd)(a))return null;let b=(0,k.O2)(a,"type");if(!b)return null;let c=(0,k.Qd)(a.message)?a.message:null,d=c?.content,e=[],f="";if("string"==typeof d)f=d;else if(Array.isArray(d))for(let a of d){let b=function(a){if(!(0,k.Qd)(a))return null;let b=(0,k.O2)(a,"type");if(!b)return null;if("tool_use"===b)return{type:b,text:null,toolName:(0,k.O2)(a,"name"),toolDetail:function(a){if(!(0,k.Qd)(a))return null;for(let c of t){let d=(0,k.O2)(a,c);if(d){var b;return(b=d.replace(/\s+/g," ").trim()).length<=200?b:`${b.slice(0,199)}…`}}return null}(a.input)};let c="text"===b?(0,k.O2)(a,"text")??"":"thinking"===b?(0,k.O2)(a,"thinking")??"":null;return{type:b,text:c,toolName:null,toolDetail:null}}(a);b&&(e.push(b),b.text&&(f+=b.text))}let g=(0,k.O2)(a,"timestamp"),h=g?Date.parse(g):NaN,i=(0,k.Qd)(a.origin)?a.origin:null;return{type:b,uuid:(0,k.O2)(a,"uuid"),sessionId:(0,k.O2)(a,"sessionId")??(0,k.O2)(a,"session_id"),cwd:(0,k.O2)(a,"cwd"),isSidechain:!0===a.isSidechain,isMeta:!0===a.isMeta,originKind:i?(0,k.O2)(i,"kind"):null,promptSource:(0,k.O2)(a,"promptSource"),isCompactSummary:!0===a.isCompactSummary,isInterruption:null!==(0,k.O2)(a,"interruptedMessageId"),timestampMs:Number.isFinite(h)?h:null,stopReason:c?(0,k.O2)(c,"stop_reason"):null,blocks:e,text:f}}(a);e?b.push(e):c+=1}return{records:b,malformedLines:c}}function v(a){if("user"!==a.type||a.isMeta||!a.uuid||a.blocks.some(a=>"tool_result"===a.type))return!1;let b=a.text.trim();return 0!==b.length&&(b.startsWith(p)?null!==s(b):!o.some(a=>b.startsWith(a)))}let w=["typed","queued"];function x(a){return!!a.closed||!!a.superseded||!a.stopReasonObserved}function y(a,b){let c=[],d=null,e=0,f=0;for(let g of a){if(g.isSidechain){f+=1;continue}if(v(g)){d=function(a,b){return{sessionId:a.sessionId??b,promptUuid:a.uuid,startedAt:a.timestampMs??0,promptText:s(a.text)??a.text,promptIsOperatorInput:!!v(a)&&!a.isCompactSummary&&!a.isInterruption&&(null!==a.originKind?"human"===a.originKind:null!==a.promptSource&&w.includes(a.promptSource)),blocks:[],assistantRecords:0,closed:!1,superseded:!1,stopReasonObserved:!1,overflowed:!1}}(g,b),c.push(d);continue}if("assistant"===g.type){if(!d){e+=1;continue}for(let a of(d.assistantRecords+=1,d.closed="assistant"===g.type&&"end_turn"===g.stopReason&&g.blocks.some(a=>"text"===a.type&&(a.text??"").trim().length>0),null!==g.stopReason&&(d.stopReasonObserved=!0),g.blocks)){if(d.blocks.length>=2048){d.overflowed=!0;break}d.blocks.push(a)}}}for(let a=0;a<c.length-1;a+=1)c[a].superseded=!0;return{turns:c,orphanedAssistantRecords:e,sidechainRecords:f}}let z=new Set(["tool_result"]);function A(a){let b=[],c=new Set,d=0,e=0;for(let f of a.blocks){if("text"===f.type){let a=f.text?.trim()??"";if(0===a.length)continue;b.push({kind:"prose",text:a}),d+=1;continue}if("thinking"===f.type){let a=f.text?.trim()??"";if(0===a.length)continue;b.push({kind:"aside",text:function(a){let b=a.trim().split("\n").map(a=>a.length>0?`> ${a}`:">").join("\n");return`> **Thinking**
8
8
  >
9
9
  ${b}`}(a)});continue}if("tool_use"===f.type){b.push({kind:"tool",text:function(a){let b=a.toolName??"tool";return a.toolDetail?`- \`${b}\` — ${a.toolDetail}`:`- \`${b}\``}(f)}),e+=1;continue}z.has(f.type)||c.add(f.type)}let f=(0,l.t3)(b).body;return f.length>2e5&&(f=f.slice(0,2e5-n.length)+n),{sessionId:a.sessionId,promptUuid:a.promptUuid,body:f,textBlocks:d,toolBlocks:e,unknownBlockTypes:[...c]}}let B=(0,i.h)("lib/hooks/sources/claude/history"),C=".jsonl",D=globalThis.__claudeTranscriptSessions??=new Map;async function E(a){let b=(0,g.v7)(a.worktreeId,a.cliToolId,a.instanceId);try{let{getLastAgentEvent:d}=await Promise.resolve().then(c.bind(c,48083)),e=d(a.worktreeId,a.cliToolId,a.instanceId)?.sessionId;if("string"==typeof e&&e.length>0)return D.set(b,e),e}catch(b){B.debug("claude-transcript-session-lookup-failed",{worktreeId:a.worktreeId,instanceId:a.instanceId??a.cliToolId,error:b instanceof Error?b.message:String(b)})}return D.get(b)??null}function F(a){return(0,f.join)(a,...m)}async function G(a,b){let c=a.instanceId??a.cliToolId;try{let d=b.homeDir??(0,e.homedir)();if("string"!=typeof b.worktreePath||0===b.worktreePath.length)return!1;let f=await E(a),g=await L(d,b,f);if(!g)return B.debug("claude-transcript-unavailable",{worktreeId:a.worktreeId,instanceId:c,sessionId:f,reason:f?"no-file":"no-session-pointer"}),!1;let h=await N(g);if(null===h)return!1;let i=u(h),j=y(i.records,f??"");if(0===j.turns.length)return B.info("claude-transcript-no-turn",{worktreeId:a.worktreeId,instanceId:c,path:g,records:i.records.length,malformedLines:i.malformedLines,orphanedAssistantRecords:j.orphanedAssistantRecords}),!1;(i.malformedLines>0||j.orphanedAssistantRecords>0)&&B.info("claude-transcript-partial-read",{worktreeId:a.worktreeId,instanceId:c,path:g,malformedLines:i.malformedLines,orphanedAssistantRecords:j.orphanedAssistantRecords,sidechainRecords:j.sidechainRecords});let k=await H(a,j.turns);if(await Q(a,j.turns.slice(0,j.turns.length-k.turns.length).slice(-O),g),0===k.turns.length)return B.debug("claude-transcript-turns-already-saved",{worktreeId:a.worktreeId,instanceId:c,turnsInWindow:j.turns.length}),!0;k.turns.length>1&&B.info("claude-transcript-backfilling-turns",{worktreeId:a.worktreeId,instanceId:c,path:g,pendingTurns:k.turns.length,turnsInWindow:j.turns.length,anchored:k.anchored});let l=[];for(let b=0;b<k.turns.length;b+=1){let c=0===b?k.previousStartedAt:k.turns[b-1].startedAt;l.push(await K(a,k.turns[b],c))}let m=function(a){let b=new Map,c=null;for(let d of a)if(!d.isSidechain){if(v(d)){c=d.uuid;continue}"assistant"===d.type&&null!==c&&null!==d.timestampMs&&d.timestampMs>(b.get(c)??0)&&b.set(c,d.timestampMs)}return b}(i.records),n=!1;for(let b=0;b<k.turns.length;b+=1){let c=k.turns[b];n=await R(a,c,A(c),function(a,b,c=0,d=null){let e=null===b.timestampMs?a.startedAt:Math.max(a.startedAt,b.timestampMs+1);return Math.max(e,Math.min(c,null===d?1/0:d-1))}(c,l[b],m.get(c.promptUuid)??0,function(a,b,c){let d=a[c+1];return d?b[c+1]?.timestampMs??d.startedAt:null}(k.turns,l,b)),g)}return n}catch(b){return B.error("claude-transcript-capture-failed",{worktreeId:a.worktreeId,instanceId:c,error:b instanceof Error?b.message:String(b)}),!1}}async function H(a,b){let[{getDbInstance:d},{findMessageByRequestId:e}]=await Promise.all([Promise.resolve().then(c.bind(c,88807)),Promise.resolve().then(c.bind(c,56791))]),f=d();for(let c=b.length-1;c>=0;c-=1){let d=(0,j.qe)(b[c].promptUuid);if(e(f,a.worktreeId,d))return{turns:b.slice(c+1),previousStartedAt:b[c].startedAt,anchored:!0}}return{turns:b.slice(-1),previousStartedAt:b.length>1?b[b.length-2].startedAt:0,anchored:!1}}async function I(a,b){try{let c=b.homeDir??(0,e.homedir)();if("string"!=typeof b.worktreePath||0===b.worktreePath.length)return null;return await L(c,b,await E(a))}catch{return null}}async function J(a,b){let c=a.instanceId??a.cliToolId;try{var d;let f=b.homeDir??(0,e.homedir)();if("string"!=typeof b.worktreePath||0===b.worktreePath.length)return null;let g=await E(a),h=await L(f,b,g);if(!h)return null;let i=await N(h);if(null===i)return null;let k=u(i),l=y(k.records,g??""),m=l.turns.at(-1);if(m){let a=A(m);if(0===a.body.length)return null;return{turnKey:(0,j.qe)(a.promptUuid),body:a.body,partial:!1}}if(0===l.orphanedAssistantRecords)return null;let n=function(a,b){let c=[],d=0,e=!1;for(let b of a){if(v(b))break;if(!b.isSidechain&&"assistant"===b.type)for(let a of(d+=1,b.blocks)){if(c.length>=2048){e=!0;break}c.push(a)}}return{sessionId:b,promptUuid:`partial:${b}`,startedAt:0,promptText:"",promptIsOperatorInput:!1,blocks:c,assistantRecords:d,closed:!1,superseded:!1,stopReasonObserved:!1,overflowed:e}}(k.records,g??""),o=A(n);if(0===o.body.length)return null;return B.info("claude-transcript-progress-headless",{worktreeId:a.worktreeId,instanceId:c,path:h,orphanedAssistantRecords:l.orphanedAssistantRecords,malformedLines:k.malformedLines}),{turnKey:(d=g??"",(0,j.qe)(`partial:${d}`)),body:o.body,partial:!0}}catch(b){return B.debug("claude-transcript-progress-failed",{worktreeId:a.worktreeId,instanceId:c,error:b instanceof Error?b.message:String(b)}),null}}async function K(a,b,c=0){let d=a.instanceId??a.cliToolId;if(!b.promptIsOperatorInput)return B.debug("claude-transcript-user-turn-skipped",{worktreeId:a.worktreeId,instanceId:d,promptUuid:b.promptUuid,reason:"not-operator-input"}),{outcome:"skipped",messageId:null,timestampMs:null};let e=await (0,h.Ce)(a,(0,j.H_)(b.promptUuid),b.promptText,b.startedAt,c>0?{adoptionFromMs:c}:{});return"failed"===e.outcome&&B.warn("claude-transcript-user-turn-failed",{worktreeId:a.worktreeId,instanceId:d,sessionId:b.sessionId,promptUuid:b.promptUuid}),e}async function L(a,b,c){if(c){var d,e,g;let h=(d=a,e=b.worktreePath,g=c,(0,f.join)(F(d),e.replace(/[^a-zA-Z0-9]/g,"-"),`${g}${C}`));if(await M(h))return h}let h=b.transcriptPathHint;if("string"==typeof h&&h.length>0){let b=function(a,b){if(!b.endsWith(C)||b.includes("\0"))return null;let c=(0,f.resolve)(F(a)),d=(0,f.resolve)(b);return d===c||d.startsWith(c+f.sep)?d:null}(a,h);if(b&&await M(b))return b}return null}async function M(a){try{return(await (0,d.stat)(a)).isFile()}catch{return!1}}async function N(a){let b;try{b=await (0,d.open)(a,"r");let{size:c}=await b.stat(),e=Math.max(0,c-4194304),f=c-e;if(f<=0)return"";let g=Buffer.alloc(f),{bytesRead:h}=await b.read(g,0,f,e),i=g.subarray(0,h).toString("utf8");if(0===e)return i;let j=i.indexOf("\n");return -1===j?"":i.slice(j+1)}catch(b){return B.warn("claude-transcript-read-failed",{path:a,error:b instanceof Error?b.message:String(b)}),null}finally{await b?.close().catch(()=>{})}}let O=3;async function P(a,b,d,e){let f=a.instanceId??a.cliToolId,g=b.content.length;if(d.body.length<=g)return!1;let[{getDbInstance:h},{updateMessageContent:i},{broadcastMessage:j}]=await Promise.all([Promise.resolve().then(c.bind(c,88807)),Promise.resolve().then(c.bind(c,56791)),Promise.all([c.e(1503),c.e(4299),c.e(6838),c.e(1719),c.e(2119),c.e(2445),c.e(595)]).then(c.bind(c,49640))]);return i(h(),b.id,d.body),j("message_updated",{worktreeId:a.worktreeId,message:{...b,content:d.body}}),B.info("claude-transcript-turn-updated",{worktreeId:a.worktreeId,instanceId:f,sessionId:d.sessionId,requestId:b.requestId,path:e,previousLength:g,bodyLength:d.body.length,textBlocks:d.textBlocks,toolBlocks:d.toolBlocks}),!0}async function Q(a,b,d){if(0===b.length)return 0;let[{getDbInstance:e},{findMessageByRequestId:f}]=await Promise.all([Promise.resolve().then(c.bind(c,88807)),Promise.resolve().then(c.bind(c,56791))]),g=e(),h=0;for(let c of b){if(!x(c))continue;let b=f(g,a.worktreeId,(0,j.qe)(c.promptUuid));b&&await P(a,b,A(c),d)&&(h+=1)}return h}async function R(a,b,d,e,f){let g=a.instanceId??a.cliToolId;if(!x(b))return B.info("claude-transcript-turn-open",{worktreeId:a.worktreeId,instanceId:g,sessionId:d.sessionId,promptUuid:d.promptUuid,assistantRecords:b.assistantRecords,textBlocks:d.textBlocks,toolBlocks:d.toolBlocks}),!1;if(0===d.body.length)return B.info("claude-transcript-turn-empty",{worktreeId:a.worktreeId,instanceId:g,sessionId:d.sessionId,promptUuid:d.promptUuid}),!1;d.unknownBlockTypes.length>0&&B.info("claude-transcript-unknown-blocks",{worktreeId:a.worktreeId,instanceId:g,sessionId:d.sessionId,blockTypes:d.unknownBlockTypes});let h=(0,j.qe)(d.promptUuid),[{getDbInstance:i},{createMessage:k,findMessageByRequestId:l},{broadcastMessage:m}]=await Promise.all([Promise.resolve().then(c.bind(c,88807)),Promise.resolve().then(c.bind(c,56791)),Promise.all([c.e(1503),c.e(4299),c.e(6838),c.e(1719),c.e(2119),c.e(2445),c.e(595)]).then(c.bind(c,49640))]),n=i(),o=l(n,a.worktreeId,h);if(o)return B.debug("claude-transcript-turn-already-saved",{worktreeId:a.worktreeId,instanceId:g,requestId:h}),await P(a,o,d,f),!0;let p=k(n,{worktreeId:a.worktreeId,role:"assistant",content:d.body,messageType:"normal",timestamp:new Date(e>0?e:Date.now()),cliToolId:a.cliToolId,instanceId:g,requestId:h});return m("message",{worktreeId:a.worktreeId,message:p}),B.info("claude-transcript-turn-saved",{worktreeId:a.worktreeId,instanceId:g,sessionId:d.sessionId,requestId:h,path:f,bodyLength:d.body.length,textBlocks:d.textBlocks,toolBlocks:d.toolBlocks}),!0}}};
@@ -17,11 +17,11 @@
17
17
  "wasm": [],
18
18
  "assets": [],
19
19
  "env": {
20
- "__NEXT_BUILD_ID": "Lno4w_zWXdGdlfXg06Vp8",
21
- "NEXT_SERVER_ACTIONS_ENCRYPTION_KEY": "WrICbw/JIL1IJHbjjJ3S0yh+UCF7FXhmsQ7+G4tyShI=",
22
- "__NEXT_PREVIEW_MODE_ID": "675ab822642ae958e837cf5674c7d1a4",
23
- "__NEXT_PREVIEW_MODE_SIGNING_KEY": "b8e074d6136dc208b6a56d68f51e61109577d9b2b87c14decc10723cf9d5940b",
24
- "__NEXT_PREVIEW_MODE_ENCRYPTION_KEY": "bf353a99f22beca7d776a3747d82c5f656c3ef8cde93066df05bdd0202d9ef5a"
20
+ "__NEXT_BUILD_ID": "eVkZd6vpcQwyJIlbymCUg",
21
+ "NEXT_SERVER_ACTIONS_ENCRYPTION_KEY": "oOp/+36q5UyMZK16pQqy3tvw/4eA6ofuTQWY/sjU0zA=",
22
+ "__NEXT_PREVIEW_MODE_ID": "d9dc8992181ca3a908efb203bd8d8777",
23
+ "__NEXT_PREVIEW_MODE_SIGNING_KEY": "e589d4ce2ef128a40297d7bec10c1ca354aceb916ca6bacb80cfe3f6205d5a69",
24
+ "__NEXT_PREVIEW_MODE_ENCRYPTION_KEY": "aab303b798a99b35037d8257e7ed9d316b0230b67a045ad1784785d668730054"
25
25
  }
26
26
  }
27
27
  },
@@ -1 +1 @@
1
- <!DOCTYPE html><html><head><meta charSet="utf-8" data-next-head=""/><meta name="viewport" content="width=device-width" data-next-head=""/><title data-next-head="">500: Internal Server Error</title><noscript data-n-css=""></noscript><script defer="" noModule="" src="/_next/static/chunks/polyfills-42372ed130431b0a.js"></script><script src="/_next/static/chunks/webpack-1dc9eb5ebb4fa5ff.js" defer=""></script><script src="/_next/static/chunks/framework-eaf13c96191cb608.js" defer=""></script><script src="/_next/static/chunks/main-6092074a0dc78280.js" defer=""></script><script src="/_next/static/chunks/pages/_app-4b3fb5e477a0267f.js" defer=""></script><script src="/_next/static/chunks/pages/_error-c970d8b55ace1b48.js" defer=""></script><script src="/_next/static/Lno4w_zWXdGdlfXg06Vp8/_buildManifest.js" defer=""></script><script src="/_next/static/Lno4w_zWXdGdlfXg06Vp8/_ssgManifest.js" defer=""></script></head><body><div id="__next"><div style="font-family:system-ui,&quot;Segoe UI&quot;,Roboto,Helvetica,Arial,sans-serif,&quot;Apple Color Emoji&quot;,&quot;Segoe UI Emoji&quot;;height:100vh;text-align:center;display:flex;flex-direction:column;align-items:center;justify-content:center"><div style="line-height:48px"><style>body{color:#000;background:#fff;margin:0}.next-error-h1{border-right:1px solid rgba(0,0,0,.3)}@media (prefers-color-scheme:dark){body{color:#fff;background:#000}.next-error-h1{border-right:1px solid rgba(255,255,255,.3)}}</style><h1 class="next-error-h1" style="display:inline-block;margin:0 20px 0 0;padding-right:23px;font-size:24px;font-weight:500;vertical-align:top">500</h1><div style="display:inline-block"><h2 style="font-size:14px;font-weight:400;line-height:28px">Internal Server Error<!-- -->.</h2></div></div></div></div><script id="__NEXT_DATA__" type="application/json">{"props":{"pageProps":{"statusCode":500}},"page":"/_error","query":{},"buildId":"Lno4w_zWXdGdlfXg06Vp8","nextExport":true,"isFallback":false,"gip":true,"scriptLoader":[]}</script></body></html>
1
+ <!DOCTYPE html><html><head><meta charSet="utf-8" data-next-head=""/><meta name="viewport" content="width=device-width" data-next-head=""/><title data-next-head="">500: Internal Server Error</title><noscript data-n-css=""></noscript><script defer="" noModule="" src="/_next/static/chunks/polyfills-42372ed130431b0a.js"></script><script src="/_next/static/chunks/webpack-1dc9eb5ebb4fa5ff.js" defer=""></script><script src="/_next/static/chunks/framework-eaf13c96191cb608.js" defer=""></script><script src="/_next/static/chunks/main-6092074a0dc78280.js" defer=""></script><script src="/_next/static/chunks/pages/_app-4b3fb5e477a0267f.js" defer=""></script><script src="/_next/static/chunks/pages/_error-c970d8b55ace1b48.js" defer=""></script><script src="/_next/static/eVkZd6vpcQwyJIlbymCUg/_buildManifest.js" defer=""></script><script src="/_next/static/eVkZd6vpcQwyJIlbymCUg/_ssgManifest.js" defer=""></script></head><body><div id="__next"><div style="font-family:system-ui,&quot;Segoe UI&quot;,Roboto,Helvetica,Arial,sans-serif,&quot;Apple Color Emoji&quot;,&quot;Segoe UI Emoji&quot;;height:100vh;text-align:center;display:flex;flex-direction:column;align-items:center;justify-content:center"><div style="line-height:48px"><style>body{color:#000;background:#fff;margin:0}.next-error-h1{border-right:1px solid rgba(0,0,0,.3)}@media (prefers-color-scheme:dark){body{color:#fff;background:#000}.next-error-h1{border-right:1px solid rgba(255,255,255,.3)}}</style><h1 class="next-error-h1" style="display:inline-block;margin:0 20px 0 0;padding-right:23px;font-size:24px;font-weight:500;vertical-align:top">500</h1><div style="display:inline-block"><h2 style="font-size:14px;font-weight:400;line-height:28px">Internal Server Error<!-- -->.</h2></div></div></div></div><script id="__NEXT_DATA__" type="application/json">{"props":{"pageProps":{"statusCode":500}},"page":"/_error","query":{},"buildId":"eVkZd6vpcQwyJIlbymCUg","nextExport":true,"isFallback":false,"gip":true,"scriptLoader":[]}</script></body></html>
@@ -1 +1 @@
1
- {"node":{},"edge":{},"encryptionKey":"WrICbw/JIL1IJHbjjJ3S0yh+UCF7FXhmsQ7+G4tyShI="}
1
+ {"node":{},"edge":{},"encryptionKey":"oOp/+36q5UyMZK16pQqy3tvw/4eA6ofuTQWY/sjU0zA="}
@@ -1 +1 @@
1
- "use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[4718],{2317:(e,t,r)=>{r.d(t,{V:()=>i});var n=r(12115);function o(){try{let e="__localStorage_test__";return window.localStorage.setItem(e,"test"),window.localStorage.removeItem(e),!0}catch(e){return!1}}function i(e){let{key:t,defaultValue:r,validate:i,serialize:a=JSON.stringify,deserialize:s=JSON.parse}=e,l=(0,n.useRef)(r),c=(0,n.useRef)(i),u=(0,n.useRef)(a),d=(0,n.useRef)(s);l.current=r,c.current=i,u.current=a,d.current=s;let[f,p]=(0,n.useState)(!1),[g,m]=(0,n.useState)(r),y=(0,n.useCallback)(()=>{if(!o())return l.current;try{let e=window.localStorage.getItem(t);if(null===e)return l.current;let r=d.current(e);if(c.current)return c.current(r)?r:l.current;return r}catch(e){return l.current}},[t]),h=(0,n.useCallback)(e=>{if(o())try{let r=u.current(e);window.localStorage.setItem(t,r)}catch(e){}},[t]),w=(0,n.useCallback)(e=>{m(t=>{let r="function"==typeof e?e(t):e;return h(r),r})},[h]),b=(0,n.useCallback)(()=>{if(o())try{window.localStorage.removeItem(t)}catch(e){}m(l.current)},[t]);return(0,n.useEffect)(()=>{p(o()),m(y())},[y]),{value:g,setValue:w,removeValue:b,isAvailable:f}}},7636:(e,t,r)=>{r.d(t,{BN:()=>C,EN:()=>a,LV:()=>p,PB:()=>l,Si:()=>i,UZ:()=>d,Xn:()=>b,ZC:()=>T,ZD:()=>E,_s:()=>S,fs:()=>k,j:()=>w,m3:()=>s,nO:()=>g,s6:()=>f,zD:()=>h});var n=r(38606);let o=["updatedAt","repositoryName","branchName","status","lastSent"],i=e=>o.includes(e),a=["always","collapsed","hidden"],s=e=>a.includes(e),l="collapsed",c={waiting:0,ready:1,running:2,generating:3,idle:4},u=["waiting","running","generating","ready","idle"];function d(e){let t=new Set;for(let r of e)!1===r.visible&&t.add(r.path);return t}function f(e,t){return 0===t.size?e.slice():e.filter(e=>{let r=e.repositoryPath;return!r||!t.has(r)})}function p(e){let t=function(e){let t=5381;for(let r=0;r<e.length;r++)t=(t<<5)+t+e.charCodeAt(r)|0;return Math.abs(t)}(e)%360;return"hsl(".concat(t,", ").concat(65,"%, ").concat(60,"%)")}function g(e,t){if(!e&&!t)return 0;if(!e)return 1;if(!t)return -1;let r=e instanceof Date?e.getTime():new Date(e).getTime();return(t instanceof Date?t.getTime():new Date(t).getTime())-r}function m(e){return e.cliStatus&&Object.keys(e.cliStatus).length>0?(0,n.A7)(e.cliStatus):e.status}function y(e){return"waiting"===m(e)}function h(e){let t=new Set(e.map(m));for(let e of u)if(t.has(e))return e;return"idle"}function w(e){let t=0;for(let r of e)y(r)&&t++;return t}function b(e,t,r){let n=[...e],o="status"!==t;return n.sort((e,n)=>{if(o){let t=Number(y(n))-Number(y(e));if(0!==t)return t}let i=0;switch(t){case"updatedAt":{let t=e=>e?e instanceof Date?e.getTime():new Date(e).getTime():0,r=t(e.lastActivity);i=t(n.lastActivity)-r;break}case"repositoryName":{let t=e.repositoryName.toLowerCase(),r=n.repositoryName.toLowerCase();i=t.localeCompare(r);break}case"branchName":{let t=e.name.toLowerCase(),r=n.name.toLowerCase();i=t.localeCompare(r);break}case"status":i=c[e.status]-c[n.status];break;case"lastSent":{let t=g(e.lastActivity,n.lastActivity);if(!e.lastActivity&&!n.lastActivity){i=0;break}if(!e.lastActivity)return 1;if(!n.lastActivity)return -1;i=t;break}default:i=0}return("updatedAt"===t||"lastSent"===t?"desc"===r:"asc"===r)?i:-i}),n}function S(e,t,r){let n=new Map;for(let t of e){let e=t.repositoryName;n.has(e)||n.set(e,[]),n.get(e).push(t)}return[...n.keys()].sort((e,t)=>e.toLowerCase().localeCompare(t.toLowerCase())).map(e=>({repositoryName:e,branches:b(n.get(e),t,r)}))}let v="mcbd-sidebar-group-order-cache";function E(){try{let e=localStorage.getItem(v);if(!e)return[];let t=function(e){try{let t=JSON.parse(e);if(!Array.isArray(t))return[];return t.filter(e=>"string"==typeof e).slice(0,500)}catch(e){return[]}}(e);return t.length,t}catch(e){return[]}}function T(e){try{localStorage.setItem(v,JSON.stringify(e))}catch(e){}}function C(e,t){if(0===t.length)return e.slice();let r=new Map(t.map((e,t)=>[e,t]));return e.slice().sort((e,t)=>{let n=r.has(e.repositoryName)?r.get(e.repositoryName):1/0,o=r.has(t.repositoryName)?r.get(t.repositoryName):1/0;return n===o?e.repositoryName.localeCompare(t.repositoryName):n-o})}function k(e,t){return"hidden"!==e&&("always"===e||!t)}},22592:(e,t,r)=>{r.d(t,{Ps:()=>d,W5:()=>u});var n=r(95155),o=r(12115),i=r(38218),a=r(68704);let s="data-pc-size",l={size:a.r5,setSize:()=>{},isMobile:!1,factor:a.d8[a.r5].factor,isAvailable:!1},c=(0,o.createContext)(l);function u(e){let{children:t}=e,{size:r,setSize:l,isAvailable:u}=(0,a.of)(),d=(0,i.a)();(0,o.useEffect)(()=>{if("undefined"==typeof document)return;let e=document.documentElement;return d?void e.removeAttribute(s):(e.setAttribute(s,r),()=>{e.removeAttribute(s)})},[r,d]);let f=(0,o.useMemo)(()=>({size:r,setSize:l,isMobile:d,factor:a.d8[r].factor,isAvailable:u}),[r,l,d,u]);return(0,n.jsx)(c.Provider,{value:f,children:t})}function d(){return(0,o.useContext)(c)}},24373:(e,t,r)=>{r.d(t,{Kg:()=>i,Lv:()=>a});var n=r(12115),o=r(66966);function i(e){let t=0;for(let r of e)!0===r.isWaitingForResponse&&t++;return t}function a(){let e=(0,o.rC)(),t=null==e?void 0:e.worktrees;return(0,n.useMemo)(()=>{let e=t?t.filter(e=>!0===e.isWaitingForResponse):[];return{count:e.length,worktrees:e}},[t])}r(44308)},32916:(e,t,r)=>{r.d(t,{GB:()=>u,VF:()=>d,pT:()=>f});var n=r(95155),o=r(12115),i=r(7636);let a="updatedAt",s=(0,o.createContext)(null);function l(e,t,r,n){let i=(0,o.useRef)(!0);(0,o.useEffect)(()=>{try{let t=localStorage.getItem(e);t&&n(t)}catch(e){}},[]),(0,o.useEffect)(()=>{if(i.current){i.current=!1;return}try{localStorage.setItem(e,r())}catch(e){}},[t])}function c(e,t){switch(t.type){case"TOGGLE":return{...e,isOpen:!e.isOpen};case"SET_WIDTH":return{...e,width:t.width};case"OPEN_MOBILE_DRAWER":return{...e,isMobileDrawerOpen:!0};case"CLOSE_MOBILE_DRAWER":return{...e,isMobileDrawerOpen:!1};case"SET_SORT_KEY":return{...e,sortKey:t.sortKey};case"SET_SORT_DIRECTION":return{...e,sortDirection:t.sortDirection};case"LOAD_SORT_SETTINGS":return{...e,sortKey:t.sortKey,sortDirection:t.sortDirection};case"SET_VIEW_MODE":return{...e,viewMode:t.viewMode};case"SET_OPEN":return e.isOpen===t.isOpen?e:{...e,isOpen:t.isOpen};case"SET_REPOSITORY_ORDER":return{...e,repositoryOrder:t.repositoryOrder};case"SET_REPO_TAB_BAR_MODE":return{...e,repoTabBarMode:t.repoTabBarMode};default:return e}}function u(e){let{children:t,initialOpen:r=!0,initialWidth:u=224}=e,[d,f]=(0,o.useReducer)(c,{isOpen:r,width:u,isMobileDrawerOpen:!1,sortKey:a,sortDirection:"desc",viewMode:"grouped",repositoryOrder:(0,i.ZD)(),repoTabBarMode:i.PB});l("mcbd-sidebar-sort","".concat(d.sortKey,":").concat(d.sortDirection),()=>JSON.stringify({sortKey:d.sortKey,sortDirection:d.sortDirection}),e=>{try{let t=JSON.parse(e),r=t.sortDirection,n=(0,i.Si)(t.sortKey)?t.sortKey:a;n&&("asc"===r||"desc"===r)&&f({type:"LOAD_SORT_SETTINGS",sortKey:n,sortDirection:r})}catch(e){}}),l("mcbd-sidebar-view-mode",d.viewMode,()=>d.viewMode,e=>{("grouped"===e||"flat"===e)&&f({type:"SET_VIEW_MODE",viewMode:e})}),l("mcbd-sidebar-width",d.width,()=>String(d.width),e=>{let t=Number(e);!isNaN(t)&&t>0&&f({type:"SET_WIDTH",width:288===t?224:t})}),l("mcbd-sidebar-open",d.isOpen,()=>String(d.isOpen),e=>{("true"===e||"false"===e)&&f({type:"SET_OPEN",isOpen:"true"===e})}),l("mcbd-repo-tab-bar-mode",d.repoTabBarMode,()=>d.repoTabBarMode,e=>{(0,i.m3)(e)&&f({type:"SET_REPO_TAB_BAR_MODE",repoTabBarMode:e})});let p=(0,o.useCallback)(()=>{f({type:"TOGGLE"})},[]),g=(0,o.useCallback)(e=>{f({type:"SET_WIDTH",width:e})},[]),m=(0,o.useCallback)(()=>{f({type:"OPEN_MOBILE_DRAWER"})},[]),y=(0,o.useCallback)(()=>{f({type:"CLOSE_MOBILE_DRAWER"})},[]),h=(0,o.useCallback)(e=>{f({type:"SET_SORT_KEY",sortKey:e})},[]),w=(0,o.useCallback)(e=>{f({type:"SET_SORT_DIRECTION",sortDirection:e})},[]),b=(0,o.useCallback)(e=>{f({type:"SET_VIEW_MODE",viewMode:e})},[]),S=(0,o.useCallback)(e=>{f({type:"SET_REPOSITORY_ORDER",repositoryOrder:e}),(0,i.ZC)(e)},[]),v=(0,o.useCallback)(e=>{f({type:"SET_REPO_TAB_BAR_MODE",repoTabBarMode:e})},[]),E=(0,o.useMemo)(()=>({isOpen:d.isOpen,width:d.width,isMobileDrawerOpen:d.isMobileDrawerOpen,sortKey:d.sortKey,sortDirection:d.sortDirection,toggle:p,setWidth:g,openMobileDrawer:m,closeMobileDrawer:y,setSortKey:h,setSortDirection:w,viewMode:d.viewMode,setViewMode:b,repositoryOrder:d.repositoryOrder,setRepositoryOrder:S,repoTabBarMode:d.repoTabBarMode,setRepoTabBarMode:v}),[d.isOpen,d.width,d.isMobileDrawerOpen,d.sortKey,d.sortDirection,d.viewMode,d.repositoryOrder,d.repoTabBarMode,p,g,m,y,h,w,b,S,v]);return(0,n.jsx)(s.Provider,{value:E,children:t})}function d(){let e=(0,o.useContext)(s);if(!e)throw Error("useSidebarContext must be used within a SidebarProvider");return e}function f(){return(0,o.useContext)(s)}},38218:(e,t,r)=>{r.d(t,{D:()=>i,a:()=>a});var n=r(12115);let o=n.useLayoutEffect,i=768;function a(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},{breakpoint:t=i}=e,[r,a]=(0,n.useState)(!1);return o(()=>{let e=window.matchMedia("(max-width: ".concat(t-1,"px)"));a(e.matches);let r=e=>{a(e.matches)};return e.addEventListener("change",r),()=>{e.removeEventListener("change",r)}},[t]),r}},38606:(e,t,r)=>{r.d(t,{A7:()=>c,kA:()=>i,f_:()=>f,dw:()=>u,XK:()=>p});var n=r(54014),o=r(55449);function i(e){return e?e.isWaitingForResponse?"waiting":e.isProcessing?"running":e.isRunning?"ready":"idle":"idle"}let a={start:"nextAction.start",sendMessage:"nextAction.sendMessage",approveReject:"nextAction.approveReject",replyToPrompt:"nextAction.replyToPrompt",checkStalled:"nextAction.checkStalled",running:"nextAction.running"};Object.values(a);let s="exited",l={idle:null,ready:"ready",running:"running",generating:"running",waiting:"waiting"};function c(e){if(!e)return"idle";let t=Object.values(e).filter(e=>void 0!==e);return 0===t.length?"idle":t.includes("waiting")?"waiting":t.includes("running")?"running":t.includes("generating")?"generating":t.includes("ready")?"ready":"idle"}function u(e,t,r){return e?Object.entries(e).map(e=>{var o;let[i,a]=e,s=null!=(o=null==t?void 0:t[i])?o:(0,n.f_)(i,i),l=null==r?void 0:r(i);return"".concat(s,": ").concat(null!=a?a:"idle").concat(l?" (".concat(l,")"):"")}).join(", "):""}let d=["prompt","menu","unclassified"];function f(e){var t,r,n;let o=Object.values(null!=(r=null!=(t=e.sessionStatusByInstance)?t:e.sessionStatusByCli)?r:{}).filter(e=>void 0!==e),i=!1,a=new Set;for(let e of o)e.awaitingInstruction&&(i=!0),e.waitingKind&&a.add(e.waitingKind);return{waitingKind:null!=(n=d.find(e=>a.has(e)))?n:null,awaitingInstruction:i}}function p(e){var t,r,u,d,p,g;let m=i(void 0!==e.isSessionRunning?{isRunning:null!=(t=e.isSessionRunning)&&t,isWaitingForResponse:null!=(r=e.isWaitingForResponse)&&r,isProcessing:null!=(u=e.isProcessing)&&u}:void 0),y=!!e.lastAssistantMessageAt&&(!e.lastViewedAt||new Date(e.lastAssistantMessageAt)>new Date(e.lastViewedAt)),{cliStatus:h,cliStatusLabels:w,exitedInstanceIds:b}=function(e){var t,r,a,l,c,u;let d={},f={},p=[],g=e.sessionStatusByInstance;if(!g){for(let c of null!=(t=e.selectedAgents)?t:(0,o.sA)())d[c]=i(null==(r=e.sessionStatusByCli)?void 0:r[c]),f[c]=(0,n.oo)(c),(null==(l=e.sessionStatusByCli)||null==(a=l[c])?void 0:a.sessionStatusReason)===s&&p.push(c);return{cliStatus:d,cliStatusLabels:f,exitedInstanceIds:p}}let m=e.agentInstances&&e.agentInstances.length>0?e.agentInstances:(0,n.lu)(null!=(c=e.selectedAgents)?c:(0,o.sA)()),y=new Set;for(let e of m)y.add(e.id),d[e.id]=i(g[e.id]),f[e.id]=(0,n.sw)(e),(null==(u=g[e.id])?void 0:u.sessionStatusReason)===s&&p.push(e.id);for(let[e,t]of Object.entries(g)){if(y.has(e))continue;let r=i(t);"idle"!==r&&(d[e]=r,f[e]=function(e){let t=n.XH.find(t=>e.startsWith("".concat(t,"-")));if(t){let r=e.slice(t.length+1);return"".concat((0,n.oo)(t)," ").concat(r)}return(0,n.f_)(e,e)}(e))}return{cliStatus:d,cliStatusLabels:f,exitedInstanceIds:p}}(e),S=c(h),{waitingKind:v,awaitingInstruction:E}=f(e);return{id:e.id,name:e.name,repositoryName:null!=(d=e.repositoryDisplayName)?d:e.repositoryName,status:m,hasUnread:y,lastActivity:e.updatedAt,description:e.description,cliStatus:h,cliStatusLabels:w,exitedInstanceIds:b,worktreePath:e.path,waitingKind:v,awaitingInstruction:E,nextActionKey:(p=l[S],g="waiting"===S?"approval":null,p&&"idle"!==p?"ready"===p?a.sendMessage:"waiting"===p&&"approval"===g?a.approveReject:"waiting"===p?a.replyToPrompt:(0,a.running):a.start)}}},39649:(e,t,r)=>{r.d(t,{$f:()=>d,H8:()=>u});var n=r(95155),o=r(12115),i=r(80344);let a={PROCESSING:2e3,SESSION_RUNNING:5e3,IDLE:1e4},s=(0,o.createContext)(null),l={selectedWorktreeId:null,worktrees:[],repositories:[],selectedWorktreeDetail:null,isLoading:!0,isLoadingDetail:!1,error:null};function c(e,t){switch(t.type){case"SET_WORKTREES":return{...e,worktrees:t.worktrees,isLoading:!1};case"SET_REPOSITORIES":return{...e,repositories:t.repositories};case"SELECT_WORKTREE":{var r;let n=null!=(r=e.worktrees.find(e=>e.id===t.id))?r:null;return{...e,selectedWorktreeId:t.id,selectedWorktreeDetail:null!=n?n:e.selectedWorktreeDetail,isLoadingDetail:null===n}}case"SET_WORKTREE_DETAIL":return{...e,selectedWorktreeDetail:t.detail};case"SET_LOADING":return{...e,isLoading:t.isLoading};case"SET_LOADING_DETAIL":return{...e,isLoadingDetail:t.isLoadingDetail};case"SET_ERROR":return{...e,error:t.error,isLoading:!1};default:return e}}function u(e){let{children:t,externalWorktrees:r,externalRepositories:u,externalIsLoading:d,externalError:f,externalRefresh:p}=e,g=void 0!==r,[m,y]=(0,o.useReducer)(c,l);(0,o.useEffect)(()=>{g&&r&&y({type:"SET_WORKTREES",worktrees:r})},[g,r]),(0,o.useEffect)(()=>{g&&u&&y({type:"SET_REPOSITORIES",repositories:u})},[g,u]);let h=(0,o.useCallback)(async()=>{if(!g){y({type:"SET_LOADING",isLoading:!0}),y({type:"SET_ERROR",error:null});try{var e;let t=await i.y.getAll();y({type:"SET_WORKTREES",worktrees:t.worktrees}),y({type:"SET_REPOSITORIES",repositories:null!=(e=t.repositories)?e:[]})}catch(e){y({type:"SET_ERROR",error:e instanceof Error?e.message:"Failed to fetch worktrees"})}}},[g]),w=(0,o.useCallback)(async e=>{y({type:"SELECT_WORKTREE",id:e}),y({type:"SET_ERROR",error:null});try{i.y.markAsViewed(e).catch(e=>{console.warn("[WorktreeSelectionContext] Failed to mark as viewed:",e)});let t=await i.y.getById(e);y({type:"SET_WORKTREE_DETAIL",detail:t})}catch(e){y({type:"SET_ERROR",error:e instanceof Error?e.message:"Failed to fetch worktree detail"})}finally{y({type:"SET_LOADING_DETAIL",isLoadingDetail:!1})}},[]),b=(0,o.useCallback)(async()=>{if(g&&p)return void await p();await h()},[g,p,h]);(0,o.useEffect)(()=>{g||h()},[h,g]),(0,o.useEffect)(()=>{if(g)return;let e=null,t=!0,r=async()=>{if(t)try{var n,o;let s=await i.y.getAll();y({type:"SET_WORKTREES",worktrees:s.worktrees}),y({type:"SET_REPOSITORIES",repositories:null!=(n=s.repositories)?n:[]});let l=(o=s.worktrees).some(e=>e.isProcessing||e.isWaitingForResponse)?a.PROCESSING:o.some(e=>e.isSessionRunning)?a.SESSION_RUNNING:a.IDLE;t&&(e=setTimeout(r,l))}catch(n){if(n instanceof i.hD&&401===n.status)return;console.error("[WorktreeSelectionContext] Polling error:",n),t&&(e=setTimeout(r,a.SESSION_RUNNING))}};return r(),()=>{t=!1,e&&clearTimeout(e)}},[g]);let S=g&&void 0!==d?d:m.isLoading,v=g&&f?f.message:null,E={selectedWorktreeId:m.selectedWorktreeId,worktrees:m.worktrees,repositories:m.repositories,selectedWorktreeDetail:m.selectedWorktreeDetail,isLoading:S,isLoadingDetail:m.isLoadingDetail,error:null!=v?v:m.error,selectWorktree:w,refreshWorktrees:b};return(0,n.jsx)(s.Provider,{value:E,children:t})}function d(){let e=(0,o.useContext)(s);if(!e)throw Error("useWorktreeSelection must be used within a WorktreeSelectionProvider");return e}},44308:(e,t,r)=>{r.d(t,{$h:()=>d,DR:()=>o,IH:()=>c,Iu:()=>n,Nb:()=>f,SD:()=>i,_d:()=>l,bm:()=>p,ks:()=>s,t7:()=>u,z7:()=>a});let n=7e3,o=["in_review","approval","stalled"],i="in_review",a="filter",s="/review?".concat(a,"=approval");function l(e){return e&&o.includes(e)?e:null}let c=["claude","codex","copilot","antigravity","opencode"],u=1e3,d=5,f=100,p=1e3},52703:(e,t,r)=>{r.d(t,{Oo:()=>o,ST:()=>n,T4:()=>s,dz:()=>a,rz:()=>i,zS:()=>l});let n="client_version",o="version_mismatch",i="chat_turn_progress",a="messages_invalidated",s="model_changed";function l(e){let t;try{t=JSON.parse(e)}catch(e){return null}if(!t||"object"!=typeof t)return null;let r=t;if("broadcast"===r.type){let e=r.data;return e&&"object"==typeof e?"string"!=typeof e.type?null:(void 0===e.worktreeId&&"string"==typeof r.worktreeId&&(e.worktreeId=r.worktreeId),e):null}return"string"==typeof r.type?r:null}},54014:(e,t,r)=>{r.d(t,{Ab:()=>o,NL:()=>y,O6:()=>p,XH:()=>n,f_:()=>d,hR:()=>c,lu:()=>g,n6:()=>s,oo:()=>u,pQ:()=>i,sw:()=>f,vz:()=>m});let n=["claude","codex","gemini","vibe-local","opencode","copilot","antigravity","command-code"],o=10,i=50,a=/^[a-zA-Z0-9_-]+$/;function s(e){return"string"==typeof e&&e.length>0&&e.length<=64&&a.test(e)}let l={claude:"Claude",codex:"Codex",gemini:"Gemini","vibe-local":"Vibe Local",opencode:"OpenCode",copilot:"Copilot",antigravity:"Antigravity","command-code":"Command Code"};function c(e){return n.includes(e)}function u(e){var t;return null!=(t=l[e])?t:e}function d(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"Assistant";return e&&c(e)?u(e):t}function f(e){let t=e.alias;return"string"==typeof t&&t.trim().length>0?t:u(e.cliTool)}function p(e,t,r){let n=e.find(e=>e.id===t);return n?f(n):u(r)}function g(e){return e.map((e,t)=>({id:e,cliTool:e,alias:u(e),order:t}))}let m=128,y=2097152},55449:(e,t,r)=>{r.d(t,{IK:()=>l,qD:()=>d,sA:()=>s,zk:()=>o});var n=r(63001);let o="/api/settings/default-agents",i=n.fJ,a=new Set;function s(){return i}function l(e){if(!Array.isArray(e))return!1;let t=(0,n.Lt)(e);if(!t.valid)return!1;let r=t.value;if(r.length===i.length&&r.every((e,t)=>e===i[t]))return!1;for(let e of(i=r,a))e();return!0}let c=null,u=!1;async function d(){return u?i:c||("function"!=typeof fetch?i:c=(async()=>{try{let e=await fetch(o);if(e.ok){let t=await e.json();l(null==t?void 0:t.defaultSelectedAgents),u=!0}}catch(e){}finally{c=null}return i})())}},63001:(e,t,r)=>{r.d(t,{Lt:()=>s,Wj:()=>i,eu:()=>o,fJ:()=>a});var n=r(54014);let o=2,i=6,a=["claude","codex","antigravity"];function s(e){return e.length<o||e.length>i?{valid:!1,error:"Must be ".concat(o,"-").concat(i," elements")}:e.every(e=>"string"==typeof e&&n.XH.includes(e))?new Set(e).size!==e.length?{valid:!1,error:"Duplicate tool IDs not allowed"}:{valid:!0,value:e}:{valid:!1,error:"Invalid CLI tool ID"}}},63365:(e,t,r)=>{r.d(t,{tS:()=>u,xM:()=>d,T3:()=>f});var n=r(95155),o=r(12115),i=r(52703);function a(){return"undefined"!=typeof globalThis&&"function"==typeof globalThis.WebSocket?globalThis.WebSocket:null}let s=()=>{},l={status:"disconnected",connected:!1,subscribe:s,unsubscribe:s,addListener:()=>s},c=(0,o.createContext)(null);function u(e){let{children:t,enabled:r=!0}=e,s=(0,o.useRef)(new Set),l=(0,o.useRef)(new Map),{status:u,subscribe:d,unsubscribe:f}=function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},{onEvent:t,onStatusChange:r,autoReconnect:n=!0,reconnectBaseDelay:s=1e3,reconnectMaxDelay:l=3e4,enabled:c=!0}=e,[u,d]=(0,o.useState)("disconnected"),f=(0,o.useRef)(null),p=(0,o.useRef)(null),g=(0,o.useRef)(0),m=(0,o.useRef)(new Set),y=(0,o.useRef)(!1),h=(0,o.useRef)(t);h.current=t;let w=(0,o.useRef)(r);w.current=r;let b=(0,o.useCallback)(e=>{var t;d(e),null==(t=w.current)||t.call(w,e)},[]),S=(0,o.useCallback)(()=>{null!==p.current&&(clearTimeout(p.current),p.current=null)},[]),v=(0,o.useCallback)(()=>{if(!c)return;let e=a();if(!e||f.current&&(f.current.readyState===e.OPEN||f.current.readyState===e.CONNECTING))return;S(),y.current=!1,b("connecting");let t="https:"===window.location.protocol?"wss:":"ws:",r=new e("".concat(t,"//").concat(window.location.host));f.current=r,r.onopen=()=>{g.current=0,b("connected");try{r.send(JSON.stringify({type:i.ST,version:"0.32.1"}))}catch(e){}m.current.forEach(e=>{try{r.send(JSON.stringify({type:"subscribe",worktreeId:e}))}catch(e){}})},r.onmessage=e=>{var t;let r="string"==typeof e.data?e.data:String(e.data),n=(0,i.zS)(r);n&&(null==(t=h.current)||t.call(h,n))},r.onerror=()=>{b("error")},r.onclose=()=>{var e;if(f.current=null,b("disconnected"),y.current||!n||"undefined"!=typeof document&&"hidden"===document.visibilityState)return;let t=(e=g.current,Math.min(s*2**Math.max(0,e),l));g.current+=1,p.current=setTimeout(()=>{p.current=null,v()},t)}},[c,n,s,l,b,S]),E=(0,o.useCallback)(()=>{if(S(),y.current=!0,f.current){try{f.current.close(1e3,"Client disconnect")}catch(e){}f.current=null}},[S]),T=(0,o.useCallback)(e=>{let t=f.current,r=a();if(t&&r&&t.readyState===r.OPEN)try{t.send(JSON.stringify(e))}catch(e){}},[]),C=(0,o.useCallback)(e=>{m.current.has(e)||(m.current.add(e),T({type:"subscribe",worktreeId:e}))},[T]),k=(0,o.useCallback)(e=>{m.current.has(e)&&(m.current.delete(e),T({type:"unsubscribe",worktreeId:e}))},[T]);return(0,o.useEffect)(()=>{if(c)return v(),()=>{E()}},[c,v,E]),(0,o.useEffect)(()=>{if(!c||"undefined"==typeof document)return;let e=()=>{"visible"===document.visibilityState&&(f.current||(g.current=0,v()))};return document.addEventListener("visibilitychange",e),()=>document.removeEventListener("visibilitychange",e)},[c,v]),{status:u,subscribe:C,unsubscribe:k,send:T}}({enabled:r,onEvent:(0,o.useCallback)(e=>{s.current.forEach(t=>{try{t(e)}catch(e){}})},[])}),p=(0,o.useCallback)(e=>{var t;let r=l.current,n=null!=(t=r.get(e))?t:0;r.set(e,n+1),0===n&&d(e)},[d]),g=(0,o.useCallback)(e=>{var t;let r=l.current,n=null!=(t=r.get(e))?t:0;n<=1?(r.delete(e),f(e)):r.set(e,n-1)},[f]),m=(0,o.useCallback)(e=>(s.current.add(e),()=>{s.current.delete(e)}),[]),y=(0,o.useMemo)(()=>({status:u,connected:"connected"===u,subscribe:p,unsubscribe:g,addListener:m}),[u,p,g,m]);return(0,n.jsx)(c.Provider,{value:y,children:t})}function d(){var e;return null!=(e=(0,o.useContext)(c))?e:l}function f(e){let{addListener:t}=d(),r=(0,o.useRef)(e);r.current=e,(0,o.useEffect)(()=>t(e=>r.current(e)),[t])}},65380:(e,t,r)=>{r.d(t,{H:()=>s,O:()=>a});var n=r(95155),o=r(12115);let i=(0,o.createContext)(!1);function a(e){let{children:t,authEnabled:r}=e;return(0,n.jsx)(i.Provider,{value:r,children:t})}function s(){return(0,o.useContext)(i)}},66966:(e,t,r)=>{r.d(t,{g7:()=>u,rC:()=>f,Fn:()=>d});var n=r(95155),o=r(12115),i=r(80344),a=r(63365);let s=[2e3,5e3,1e4];var l=r(39649);let c=(0,o.createContext)(null);function u(e){let{children:t}=e,{worktrees:r,repositories:u,isLoading:d,error:f,refresh:p}=function(){let[e,t]=(0,o.useState)([]),[r,n]=(0,o.useState)([]),[l,c]=(0,o.useState)(!0),[u,d]=(0,o.useState)(null),f=(0,o.useRef)(null),p=(0,o.useRef)([]),g=(0,o.useRef)(null),m=(0,o.useRef)(0),y=(0,o.useRef)(null),h=(0,o.useRef)(async()=>{}),w=(0,o.useCallback)(()=>{null!==y.current&&(clearTimeout(y.current),y.current=null)},[]),{connected:b,subscribe:S,unsubscribe:v,addListener:E}=(0,a.xM)(),T=(0,o.useRef)(b);T.current=b;let C=(0,o.useCallback)(async()=>{try{var e,r;d(null);let a=await fetch("/api/worktrees"),s=(0,i.O0)(a);if(s)throw s;if(!a.ok)throw Error("Failed to fetch worktrees: ".concat(a.status));let l=(0,i.xd)(a);if(l)throw l;let c=await a.json(),u=null!=(e=c.worktrees)?e:[],f=null!=(r=c.repositories)?r:[];(0,o.startTransition)(()=>{t(u),n(f)}),p.current=u,m.current=0,w()}catch(r){let e=r instanceof Error?r:Error(String(r));console.error("[useWorktreesCache] Failed to fetch worktrees:",e),d(e);let t=m.current;0===p.current.length&&t<s.length&&(m.current=t+1,w(),y.current=setTimeout(()=>{y.current=null,h.current()},s[t]))}finally{c(!1)}},[w]);h.current=C,(0,o.useEffect)(()=>{C()},[C]),(0,o.useEffect)(()=>w,[w]);let k=(0,o.useCallback)(()=>p.current.some(e=>!0===e.isSessionRunning),[]),O=(0,o.useCallback)(()=>{let e=k();return T.current?e?2e4:6e4:e?5e3:3e4},[k]),R=(0,o.useCallback)(()=>{null!==f.current&&(clearInterval(f.current),f.current=null),g.current=null},[]),x=(0,o.useCallback)(()=>{R();let e=O();g.current=e,f.current=setInterval(()=>{C()},e)},[O,C,R]);(0,o.useEffect)(()=>{let e=()=>{document.hidden?R():(C(),x())},t=setTimeout(()=>{x()},0);return document.addEventListener("visibilitychange",e),()=>{clearTimeout(t),R(),document.removeEventListener("visibilitychange",e)}},[C,x,R]),(0,o.useEffect)(()=>{if(p.current=e,"undefined"!=typeof document&&document.hidden||null===g.current)return;let t=O();g.current!==t&&x()},[e,b,O,x]);let N=e.map(e=>e.id).sort().join(" ");return(0,o.useEffect)(()=>{let e=N.length>0?N.split(" "):[];return e.forEach(e=>S(e)),()=>{e.forEach(e=>v(e))}},[N,S,v]),(0,o.useEffect)(()=>E(e=>{if("session_status_changed"===e.type&&"string"==typeof e.worktreeId){let i=e.worktreeId,a=e.isWaitingForResponse;if("boolean"==typeof a){var r,n;let s=null!=(r=e.instance)?r:null,l=null!=(n=e.waitingKind)?n:null;(0,o.startTransition)(()=>{t(e=>{let t=!1,r=e.map(e=>{if(e.id!==i)return e;let r=function(e,t){var r,n,o;let i,a=null!=(n=t.instance)?n:null,s=a?null==(r=e.sessionStatusByInstance)?void 0:r[a]:void 0,l=e.sessionStatusByInstance;if(a&&s&&s.isWaitingForResponse!==t.waiting&&(l={...e.sessionStatusByInstance,[a]:{...s,isWaitingForResponse:t.waiting,waitingKind:null!=(o=t.waitingKind)?o:null}}),t.waiting)i=!0;else{let e=l?Object.values(l):[];i=e.length>0&&e.some(e=>(null==e?void 0:e.isWaitingForResponse)===!0)}return l===e.sessionStatusByInstance&&i===e.isWaitingForResponse?e:{...e,sessionStatusByInstance:l,isWaitingForResponse:i}}(e,{waiting:a,instance:s,waitingKind:l});return r!==e&&(t=!0),r});return t?r:e})});return}let s=e.isRunning;if("boolean"==typeof s){if((null!=e.cliTool||null!=e.instance)&&!1===s)return void C();(0,o.startTransition)(()=>{t(e=>{let t=!1,r=e.map(e=>e.id===i&&e.isSessionRunning!==s?(t=!0,{...e,isSessionRunning:s}):e);return t?r:e})})}}else("message"===e.type||"message_updated"===e.type)&&C()}),[E,C]),{worktrees:e,repositories:r,isLoading:l,error:u,refresh:C}}(),g=(0,o.useMemo)(()=>({worktrees:r,repositories:u,isLoading:d,error:f,refresh:p}),[r,u,d,f,p]);return(0,n.jsx)(c.Provider,{value:g,children:(0,n.jsx)(l.H8,{externalWorktrees:r,externalRepositories:u,externalIsLoading:d,externalError:f,externalRefresh:p,children:t})})}function d(){let e=(0,o.useContext)(c);if(null===e)throw Error("useWorktreesCacheContext must be used within a WorktreesCacheProvider");return e}function f(){return(0,o.useContext)(c)}},68704:(e,t,r)=>{r.d(t,{Uf:()=>i,d8:()=>a,fM:()=>s,of:()=>c,r5:()=>o,rq:()=>l});var n=r(2317);let o="medium",i=["large","medium","small","xsmall"],a={large:{value:"large",rootFontSizePx:18,factor:1.125,terminalFontSize:16},medium:{value:"medium",rootFontSizePx:16,factor:1,terminalFontSize:14},small:{value:"small",rootFontSizePx:14,factor:.875,terminalFontSize:12},xsmall:{value:"xsmall",rootFontSizePx:12.5,factor:.78,terminalFontSize:11}};function s(e){return"string"==typeof e&&Object.prototype.hasOwnProperty.call(a,e)}function l(e){return a[e].terminalFontSize}function c(){let{value:e,setValue:t,isAvailable:r}=(0,n.V)({key:"mcbd-pc-display-size",defaultValue:o,validate:s});return{size:e,setSize:t,isAvailable:r}}},70628:(e,t,r)=>{r.d(t,{K:()=>s,S:()=>a});var n=r(95155),o=r(12115);let i=(0,o.createContext)({open:!1,setOpen:()=>{},toggle:()=>{}});function a(e){let{children:t}=e,[r,a]=(0,o.useState)(!1),s=(0,o.useCallback)(()=>a(e=>!e),[]),l=(0,o.useMemo)(()=>({open:r,setOpen:a,toggle:s}),[r,s]);return(0,n.jsx)(i.Provider,{value:l,children:t})}function s(){return(0,o.useContext)(i)}},77016:(e,t,r)=>{r.d(t,{W:()=>w,n:()=>b});var n=r(95155),o=r(12115),i=r(18955),a=r(52056),s=r(89559),l=r(65229),c=r(59854),u=r(63365),d=r(52703);let f=0,p=new Set;function g(){for(let e of p)e()}function m(e){return p.add(e),()=>{p.delete(e)}}function y(){return f>0}function h(){return!1}function w(){return(0,o.useSyncExternalStore)(m,y,h)}function b(){let e=(0,i.c)("common"),[t,r]=(0,o.useState)(null),[p,m]=(0,o.useState)(null),y=(0,o.useCallback)(e=>{if(e.type!==d.Oo)return;let{serverVersion:t,clientVersion:n}=e;"string"==typeof t&&"string"==typeof n&&t&&n&&t!==p&&r({serverVersion:t,clientVersion:n})},[p]);(0,u.T3)(y);let h=null!==t;(0,o.useEffect)(()=>{if(h)return f+=1,g(),()=>{f-=1,g()}},[h]);let w=(0,o.useCallback)(()=>{window.location.reload()},[]),b=(0,o.useCallback)(()=>{r(e=>(e&&m(e.serverVersion),null))},[]);return t?(0,n.jsxs)("div",{"data-testid":"version-mismatch-banner",role:"alert","aria-live":"assertive",className:"fixed top-3 left-1/2 -translate-x-1/2 flex items-start gap-3 max-w-[92vw] rounded-lg border border-warning-border bg-warning-subtle px-4 py-3 text-warning-foreground shadow-lg",style:{zIndex:c.M.TOAST},children:[(0,n.jsx)(a.A,{className:"h-5 w-5 shrink-0 mt-0.5","aria-hidden":"true"}),(0,n.jsxs)("div",{className:"flex flex-col gap-0.5 text-sm",children:[(0,n.jsx)("span",{className:"font-semibold",children:e("versionMismatch.title")}),(0,n.jsx)("span",{children:e("versionMismatch.description",{serverVersion:t.serverVersion,clientVersion:t.clientVersion})})]}),(0,n.jsxs)("button",{type:"button","data-testid":"version-mismatch-reload",onClick:w,className:"shrink-0 inline-flex items-center gap-1.5 rounded-md border border-warning-border px-3 py-1.5 text-sm font-medium hover:opacity-80 focus:outline-none focus:ring-2 focus:ring-offset-2",children:[(0,n.jsx)(s.A,{className:"h-4 w-4","aria-hidden":"true"}),e("versionMismatch.reload")]}),(0,n.jsx)("button",{type:"button","data-testid":"version-mismatch-dismiss",onClick:b,"aria-label":e("versionMismatch.dismiss"),className:"shrink-0 hover:opacity-70 focus:outline-none focus:ring-2 focus:ring-offset-2",children:(0,n.jsx)(l.A,{className:"h-4 w-4","aria-hidden":"true"})})]}):null}},80344:(e,t,r)=>{r.d(t,{$T:()=>d,GQ:()=>p,O0:()=>i,Rx:()=>c,gC:()=>u,hD:()=>n,hS:()=>f,xd:()=>a,y:()=>l});class n extends Error{constructor(e,t,r){super(e),this.status=t,this.data=r,this.name="ApiError"}}async function o(e,t,r){if(!(e.headers.get("content-type")||"").includes("application/json"))return t;try{return await e.json()}catch(e){return t}}function i(e){var t;return e.redirected&&(null!=(t=e.url)?t:"").includes("/login")?new n("Authentication required",401):null}function a(e){return e.headers?(e.headers.get("content-type")||"").includes("application/json")?null:new n("Unexpected response format",e.status):null}async function s(e,t){try{let r=new Headers(null==t?void 0:t.headers);r.set("Content-Type","application/json");let s=await fetch(e,{...t,headers:r}),l=i(s);if(l)throw l;if(!s.ok){let e=await o(s,{},"error-body");throw new n(e.error||"HTTP error ".concat(s.status),s.status,e)}let c=a(s);if(c)throw c;return s.json()}catch(e){if(e instanceof n)throw e;throw new n(e instanceof Error?e.message:"Unknown error",0,e)}}let l={getAll:async()=>s("/api/worktrees"),getById:async e=>s("/api/worktrees/".concat(e)),updateDescription:async(e,t)=>s("/api/worktrees/".concat(e),{method:"PATCH",body:JSON.stringify({description:t})}),updateLink:async(e,t)=>s("/api/worktrees/".concat(e),{method:"PATCH",body:JSON.stringify({link:t})}),toggleFavorite:async(e,t)=>s("/api/worktrees/".concat(e),{method:"PATCH",body:JSON.stringify({favorite:t})}),updateStatus:async(e,t)=>s("/api/worktrees/".concat(e),{method:"PATCH",body:JSON.stringify({status:t})}),updateCliTool:async(e,t)=>s("/api/worktrees/".concat(e),{method:"PATCH",body:JSON.stringify({cliToolId:t})}),markAsViewed:async e=>s("/api/worktrees/".concat(e,"/viewed"),{method:"PATCH"}),async getMessages(e,t,r,n){let o=new URLSearchParams;return t&&o.append("cliTool",t),r&&o.append("includeArchived","true"),"number"==typeof n&&Number.isFinite(n)&&o.append("limit",String(n)),s("/api/worktrees/".concat(e,"/messages").concat(o.toString()?"?".concat(o.toString()):""))},async sendMessage(e,t,r){var n;let o={content:t};return(null==r?void 0:r.cliToolId)&&(o.cliToolId=r.cliToolId),(null==r?void 0:r.instanceId)&&(o.instanceId=r.instanceId),(null==r?void 0:r.imagePath)&&(o.imagePath=r.imagePath),null===(n=await s("/api/worktrees/".concat(e,"/send"),{method:"POST",body:JSON.stringify(o)}))||"object"!=typeof n||n.timestamp instanceof Date?n:{...n,timestamp:new Date(n.timestamp)}},async uploadImageFile(e,t){let r=Date.now(),n="".concat(r,"-").concat(t.name),i=".commandmate/attachments",a=new FormData;a.append("file",new File([t],n,{type:t.type}));let s=await fetch("/api/worktrees/".concat(e,"/upload/").concat(i),{method:"POST",body:a});if(!s.ok){var l;let e=await o(s,{},"error-body");throw Error((null==e||null==(l=e.error)?void 0:l.message)||"Upload failed (HTTP ".concat(s.status,")"))}return{path:(await o(s,{},"response-body")).path||"".concat(i,"/").concat(n)}},getLogs:async e=>s("/api/worktrees/".concat(e,"/logs")),async getLogFile(e,t,r){let n=(null==r?void 0:r.sanitize)?"?sanitize=true":"";return s("/api/worktrees/".concat(e,"/logs/").concat(t).concat(n))},async killSession(e,t,r){let n=new URLSearchParams;t&&n.set("cliTool",t),r&&n.set("instance",r);let o=n.toString();return s("/api/worktrees/".concat(e,"/kill-session").concat(o?"?".concat(o):""),{method:"POST"})}},c={scan:async e=>s("/api/repositories/scan",{method:"POST",body:JSON.stringify({repositoryPath:e})}),sync:async()=>s("/api/repositories/sync",{method:"POST"}),delete:async e=>s("/api/repositories",{method:"DELETE",body:JSON.stringify({repositoryPath:e})}),async clone(e,t){var r;return s("/api/repositories/clone",{method:"POST",body:JSON.stringify({cloneUrl:e,fork:null!=(r=null==t?void 0:t.fork)&&r})})},getCloneStatus:async e=>s("/api/repositories/clone/".concat(e)),getExcluded:async()=>s("/api/repositories/excluded"),restore:async e=>s("/api/repositories/restore",{method:"PUT",body:JSON.stringify({repositoryPath:e})}),list:async()=>s("/api/repositories"),updateDisplayName:async(e,t)=>s("/api/repositories/".concat(encodeURIComponent(e)),{method:"PUT",body:JSON.stringify({displayName:t})}),updateVisibility:async(e,t)=>s("/api/repositories/".concat(encodeURIComponent(e)),{method:"PUT",body:JSON.stringify({visible:t})}),updateEnabled:async(e,t)=>s("/api/repositories/".concat(encodeURIComponent(e)),{method:"PUT",body:JSON.stringify({enabled:t})}),validatePath:async e=>s("/api/repositories/validate-path",{method:"POST",body:JSON.stringify({repositoryPath:e})})},u={async browse(e){let t=e?"?path=".concat(encodeURIComponent(e)):"";return s("/api/fs/browse".concat(t))},addRecentPath:async e=>s("/api/fs/recent-paths",{method:"POST",body:JSON.stringify({path:e})})},d={getAll:async e=>(await s("/api/worktrees/".concat(e,"/memos"))).memos,create:async(e,t)=>(await s("/api/worktrees/".concat(e,"/memos"),{method:"POST",body:JSON.stringify(t||{})})).memo,update:async(e,t,r)=>(await s("/api/worktrees/".concat(e,"/memos/").concat(t),{method:"PUT",body:JSON.stringify(r)})).memo,delete:async(e,t)=>s("/api/worktrees/".concat(e,"/memos/").concat(t),{method:"DELETE"}),async reorder(e,t){await s("/api/worktrees/".concat(e,"/memos"),{method:"PATCH",body:JSON.stringify({memoIds:t})})}};function f(e){return e instanceof n||e instanceof Error?e.message:"An unknown error occurred"}let p={checkForUpdate:async()=>s("/api/app/update-check",{method:"GET"}),startUpdate:async()=>s("/api/app/update",{method:"POST"}),async ping(){try{return(await fetch("/api/auth/status",{cache:"no-store"})).ok}catch(e){return!1}}}},89275:(e,t,r)=>{r.d(t,{Bo:()=>u,Hq:()=>l});var n=r(95155),o=r(12115),i=r(20063);let a={startTransition:e=>e()},s=(0,o.createContext)(null);function l(){var e;let t=(0,i.useRouter)(),{startTransition:r}=null!=(e=(0,o.useContext)(s))?e:a;return(0,o.useMemo)(()=>({push:e=>r(()=>t.push(e)),replace:e=>r(()=>t.replace(e))}),[t,r])}function c(e){let{onCommit:t}=e,r=(0,i.usePathname)(),n=(0,o.useRef)(!1);return(0,o.useEffect)(()=>{if(!n.current){n.current=!0;return}t()},[r,t]),null}function u(e){let{children:t}=e,r=(0,o.useRef)(null),i=(0,o.useCallback)(()=>{var e;null==(e=r.current)||e.call(r)},[]),a=(0,o.useCallback)(e=>{var t;t=()=>new Promise(t=>{let n=!1,o=()=>{n||(n=!0,t())};r.current=o,e(),window.setTimeout(o,500)}),"undefined"==typeof document||"function"!=typeof document.startViewTransition||"function"==typeof window.matchMedia&&window.matchMedia("(prefers-reduced-motion: reduce)").matches?t():document.startViewTransition(t)},[]),l=(0,o.useMemo)(()=>({startTransition:a}),[a]);return(0,n.jsxs)(s.Provider,{value:l,children:[(0,n.jsx)(c,{onCommit:i}),t]})}},92614:(e,t,r)=>{r.d(t,{C:()=>s,E:()=>a});var n=r(95155),o=r(12115);let i=(0,o.createContext)({open:!1,setOpen:()=>{},toggle:()=>{}});function a(e){let{children:t}=e,[r,a]=(0,o.useState)(!1),s=(0,o.useCallback)(()=>a(e=>!e),[]),l=(0,o.useMemo)(()=>({open:r,setOpen:a,toggle:s}),[r,s]);return(0,n.jsx)(i.Provider,{value:l,children:t})}function s(){return(0,o.useContext)(i)}},94442:(e,t,r)=>{r.d(t,{dj:()=>v,tE:()=>S});var n=r(95155),o=r(12115),i=r(47650),a=r(18955),s=r(42529),l=r(78874),c=r(52056),u=r(23327),d=r(65229),f=r(59854),p=r(9900),g=r(9286);function m(e){let{type:t,iconColor:r}=e,o="h-5 w-5 ".concat(r);switch(t){case"success":return(0,n.jsx)(s.A,{className:o,"data-testid":"toast-icon-success"});case"error":return(0,n.jsx)(l.A,{className:o,"data-testid":"toast-icon-error"});case"warning":return(0,n.jsx)(c.A,{className:o,"data-testid":"toast-icon-warning"});default:return(0,n.jsx)(u.A,{className:o,"data-testid":"toast-icon-info"})}}function y(e){let{id:t,message:r,type:i,onClose:s,duration:l=3e3,onClick:c}=e,u=(0,a.c)("common"),f=(0,o.useRef)(null),y=function(e){switch(e){case"success":return{bgColor:"bg-success-subtle",borderColor:"border-success-border",textColor:"text-success-foreground",iconColor:"text-success-foreground"};case"error":return{bgColor:"bg-danger-subtle",borderColor:"border-danger-border",textColor:"text-danger-foreground",iconColor:"text-danger-foreground"};case"warning":return{bgColor:"bg-warning-subtle",borderColor:"border-warning-border",textColor:"text-warning-foreground",iconColor:"text-warning-foreground"};default:return{bgColor:"bg-info-subtle",borderColor:"border-info-border",textColor:"text-info-foreground",iconColor:"text-info-foreground"}}}(i),[h,w]=(0,o.useState)(!0),{shouldRender:b,isExiting:S}=(0,g.O)(h,p.Ys),v=(0,o.useRef)(s);v.current=s,(0,o.useEffect)(()=>{b||v.current(t)},[b,t]),(0,o.useEffect)(()=>(l>0&&(f.current=setTimeout(()=>{w(!1)},l)),()=>{f.current&&clearTimeout(f.current)}),[l]);let E=(0,o.useCallback)(()=>{f.current&&clearTimeout(f.current),w(!1)},[]);return(0,n.jsxs)("div",{"data-testid":"toast-".concat(t),role:"alert",className:"\n ".concat(y.bgColor,"\n ").concat(y.borderColor,"\n ").concat(y.textColor,"\n border rounded-lg shadow-lg p-4 min-w-[300px] max-w-[400px]\n flex items-start gap-3\n ").concat(S?"animate-out fade-out-0 slide-out-to-right-full duration-200 fill-mode-forwards pointer-events-none":"animate-slide-in","\n "),children:[(0,n.jsx)(m,{type:i,iconColor:y.iconColor}),c?(0,n.jsx)("button",{type:"button","data-testid":"toast-action-button",onClick:()=>{c(),E()},className:"flex-1 text-left text-sm font-medium underline-offset-2 hover:underline focus:outline-none focus-visible:ring-2 focus-visible:ring-ring rounded-sm",children:r}):(0,n.jsx)("p",{className:"flex-1 text-sm font-medium",children:r}),(0,n.jsx)("button",{"data-testid":"toast-close-button",onClick:E,"aria-label":u("closeNotification"),className:"\n ".concat(y.textColor,"\n hover:opacity-70\n focus:outline-none focus:ring-2 focus:ring-offset-2\n transition-opacity\n "),children:(0,n.jsx)(d.A,{className:"h-4 w-4"})})]})}function h(e){let{toasts:t,onClose:r}=e,[a,s]=(0,o.useState)(!1);(0,o.useEffect)(()=>{s(!0)},[]);let l=(0,n.jsx)("div",{"data-testid":"toast-container","aria-live":"polite",className:"fixed bottom-4 right-4 flex flex-col gap-2",style:{zIndex:f.M.TOAST},children:t.map(e=>(0,n.jsx)(y,{id:e.id,message:e.message,type:e.type,onClose:r,duration:e.duration,onClick:e.onClick},e.id))});return a?(0,i.createPortal)(l,document.body):null}function w(){let[e,t]=(0,o.useState)([]),r=(0,o.useRef)(0),n=(0,o.useCallback)(function(e){let n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"info",o=arguments.length>2&&void 0!==arguments[2]?arguments[2]:3e3,i=arguments.length>3?arguments[3]:void 0,a="toast-".concat(++r.current,"-").concat(Date.now()),s={id:a,message:e,type:n,duration:o,...(null==i?void 0:i.onClick)?{onClick:i.onClick}:{}};return t(e=>[...e,s]),a},[]),i=(0,o.useCallback)(e=>{t(t=>t.filter(t=>t.id!==e))},[]),a=(0,o.useCallback)(()=>{t([])},[]);return(0,o.useMemo)(()=>({toasts:e,showToast:n,removeToast:i,clearToasts:a}),[e,n,i,a])}let b=(0,o.createContext)(null);function S(e){let{children:t}=e,r=w();return(0,n.jsxs)(b.Provider,{value:r,children:[t,(0,n.jsx)(h,{toasts:r.toasts,onClose:r.removeToast})]})}function v(){let e=(0,o.useContext)(b),t=w();return null!=e?e:t}}}]);
1
+ "use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[4718],{2317:(e,t,r)=>{r.d(t,{V:()=>i});var n=r(12115);function o(){try{let e="__localStorage_test__";return window.localStorage.setItem(e,"test"),window.localStorage.removeItem(e),!0}catch(e){return!1}}function i(e){let{key:t,defaultValue:r,validate:i,serialize:a=JSON.stringify,deserialize:s=JSON.parse}=e,l=(0,n.useRef)(r),c=(0,n.useRef)(i),u=(0,n.useRef)(a),d=(0,n.useRef)(s);l.current=r,c.current=i,u.current=a,d.current=s;let[f,p]=(0,n.useState)(!1),[g,m]=(0,n.useState)(r),y=(0,n.useCallback)(()=>{if(!o())return l.current;try{let e=window.localStorage.getItem(t);if(null===e)return l.current;let r=d.current(e);if(c.current)return c.current(r)?r:l.current;return r}catch(e){return l.current}},[t]),h=(0,n.useCallback)(e=>{if(o())try{let r=u.current(e);window.localStorage.setItem(t,r)}catch(e){}},[t]),w=(0,n.useCallback)(e=>{m(t=>{let r="function"==typeof e?e(t):e;return h(r),r})},[h]),b=(0,n.useCallback)(()=>{if(o())try{window.localStorage.removeItem(t)}catch(e){}m(l.current)},[t]);return(0,n.useEffect)(()=>{p(o()),m(y())},[y]),{value:g,setValue:w,removeValue:b,isAvailable:f}}},7636:(e,t,r)=>{r.d(t,{BN:()=>C,EN:()=>a,LV:()=>p,PB:()=>l,Si:()=>i,UZ:()=>d,Xn:()=>b,ZC:()=>T,ZD:()=>E,_s:()=>S,fs:()=>k,j:()=>w,m3:()=>s,nO:()=>g,s6:()=>f,zD:()=>h});var n=r(38606);let o=["updatedAt","repositoryName","branchName","status","lastSent"],i=e=>o.includes(e),a=["always","collapsed","hidden"],s=e=>a.includes(e),l="collapsed",c={waiting:0,ready:1,running:2,generating:3,idle:4},u=["waiting","running","generating","ready","idle"];function d(e){let t=new Set;for(let r of e)!1===r.visible&&t.add(r.path);return t}function f(e,t){return 0===t.size?e.slice():e.filter(e=>{let r=e.repositoryPath;return!r||!t.has(r)})}function p(e){let t=function(e){let t=5381;for(let r=0;r<e.length;r++)t=(t<<5)+t+e.charCodeAt(r)|0;return Math.abs(t)}(e)%360;return"hsl(".concat(t,", ").concat(65,"%, ").concat(60,"%)")}function g(e,t){if(!e&&!t)return 0;if(!e)return 1;if(!t)return -1;let r=e instanceof Date?e.getTime():new Date(e).getTime();return(t instanceof Date?t.getTime():new Date(t).getTime())-r}function m(e){return e.cliStatus&&Object.keys(e.cliStatus).length>0?(0,n.A7)(e.cliStatus):e.status}function y(e){return"waiting"===m(e)}function h(e){let t=new Set(e.map(m));for(let e of u)if(t.has(e))return e;return"idle"}function w(e){let t=0;for(let r of e)y(r)&&t++;return t}function b(e,t,r){let n=[...e],o="status"!==t;return n.sort((e,n)=>{if(o){let t=Number(y(n))-Number(y(e));if(0!==t)return t}let i=0;switch(t){case"updatedAt":{let t=e=>e?e instanceof Date?e.getTime():new Date(e).getTime():0,r=t(e.lastActivity);i=t(n.lastActivity)-r;break}case"repositoryName":{let t=e.repositoryName.toLowerCase(),r=n.repositoryName.toLowerCase();i=t.localeCompare(r);break}case"branchName":{let t=e.name.toLowerCase(),r=n.name.toLowerCase();i=t.localeCompare(r);break}case"status":i=c[e.status]-c[n.status];break;case"lastSent":{let t=g(e.lastActivity,n.lastActivity);if(!e.lastActivity&&!n.lastActivity){i=0;break}if(!e.lastActivity)return 1;if(!n.lastActivity)return -1;i=t;break}default:i=0}return("updatedAt"===t||"lastSent"===t?"desc"===r:"asc"===r)?i:-i}),n}function S(e,t,r){let n=new Map;for(let t of e){let e=t.repositoryName;n.has(e)||n.set(e,[]),n.get(e).push(t)}return[...n.keys()].sort((e,t)=>e.toLowerCase().localeCompare(t.toLowerCase())).map(e=>({repositoryName:e,branches:b(n.get(e),t,r)}))}let v="mcbd-sidebar-group-order-cache";function E(){try{let e=localStorage.getItem(v);if(!e)return[];let t=function(e){try{let t=JSON.parse(e);if(!Array.isArray(t))return[];return t.filter(e=>"string"==typeof e).slice(0,500)}catch(e){return[]}}(e);return t.length,t}catch(e){return[]}}function T(e){try{localStorage.setItem(v,JSON.stringify(e))}catch(e){}}function C(e,t){if(0===t.length)return e.slice();let r=new Map(t.map((e,t)=>[e,t]));return e.slice().sort((e,t)=>{let n=r.has(e.repositoryName)?r.get(e.repositoryName):1/0,o=r.has(t.repositoryName)?r.get(t.repositoryName):1/0;return n===o?e.repositoryName.localeCompare(t.repositoryName):n-o})}function k(e,t){return"hidden"!==e&&("always"===e||!t)}},22592:(e,t,r)=>{r.d(t,{Ps:()=>d,W5:()=>u});var n=r(95155),o=r(12115),i=r(38218),a=r(68704);let s="data-pc-size",l={size:a.r5,setSize:()=>{},isMobile:!1,factor:a.d8[a.r5].factor,isAvailable:!1},c=(0,o.createContext)(l);function u(e){let{children:t}=e,{size:r,setSize:l,isAvailable:u}=(0,a.of)(),d=(0,i.a)();(0,o.useEffect)(()=>{if("undefined"==typeof document)return;let e=document.documentElement;return d?void e.removeAttribute(s):(e.setAttribute(s,r),()=>{e.removeAttribute(s)})},[r,d]);let f=(0,o.useMemo)(()=>({size:r,setSize:l,isMobile:d,factor:a.d8[r].factor,isAvailable:u}),[r,l,d,u]);return(0,n.jsx)(c.Provider,{value:f,children:t})}function d(){return(0,o.useContext)(c)}},24373:(e,t,r)=>{r.d(t,{Kg:()=>i,Lv:()=>a});var n=r(12115),o=r(66966);function i(e){let t=0;for(let r of e)!0===r.isWaitingForResponse&&t++;return t}function a(){let e=(0,o.rC)(),t=null==e?void 0:e.worktrees;return(0,n.useMemo)(()=>{let e=t?t.filter(e=>!0===e.isWaitingForResponse):[];return{count:e.length,worktrees:e}},[t])}r(44308)},32916:(e,t,r)=>{r.d(t,{GB:()=>u,VF:()=>d,pT:()=>f});var n=r(95155),o=r(12115),i=r(7636);let a="updatedAt",s=(0,o.createContext)(null);function l(e,t,r,n){let i=(0,o.useRef)(!0);(0,o.useEffect)(()=>{try{let t=localStorage.getItem(e);t&&n(t)}catch(e){}},[]),(0,o.useEffect)(()=>{if(i.current){i.current=!1;return}try{localStorage.setItem(e,r())}catch(e){}},[t])}function c(e,t){switch(t.type){case"TOGGLE":return{...e,isOpen:!e.isOpen};case"SET_WIDTH":return{...e,width:t.width};case"OPEN_MOBILE_DRAWER":return{...e,isMobileDrawerOpen:!0};case"CLOSE_MOBILE_DRAWER":return{...e,isMobileDrawerOpen:!1};case"SET_SORT_KEY":return{...e,sortKey:t.sortKey};case"SET_SORT_DIRECTION":return{...e,sortDirection:t.sortDirection};case"LOAD_SORT_SETTINGS":return{...e,sortKey:t.sortKey,sortDirection:t.sortDirection};case"SET_VIEW_MODE":return{...e,viewMode:t.viewMode};case"SET_OPEN":return e.isOpen===t.isOpen?e:{...e,isOpen:t.isOpen};case"SET_REPOSITORY_ORDER":return{...e,repositoryOrder:t.repositoryOrder};case"SET_REPO_TAB_BAR_MODE":return{...e,repoTabBarMode:t.repoTabBarMode};default:return e}}function u(e){let{children:t,initialOpen:r=!0,initialWidth:u=224}=e,[d,f]=(0,o.useReducer)(c,{isOpen:r,width:u,isMobileDrawerOpen:!1,sortKey:a,sortDirection:"desc",viewMode:"grouped",repositoryOrder:(0,i.ZD)(),repoTabBarMode:i.PB});l("mcbd-sidebar-sort","".concat(d.sortKey,":").concat(d.sortDirection),()=>JSON.stringify({sortKey:d.sortKey,sortDirection:d.sortDirection}),e=>{try{let t=JSON.parse(e),r=t.sortDirection,n=(0,i.Si)(t.sortKey)?t.sortKey:a;n&&("asc"===r||"desc"===r)&&f({type:"LOAD_SORT_SETTINGS",sortKey:n,sortDirection:r})}catch(e){}}),l("mcbd-sidebar-view-mode",d.viewMode,()=>d.viewMode,e=>{("grouped"===e||"flat"===e)&&f({type:"SET_VIEW_MODE",viewMode:e})}),l("mcbd-sidebar-width",d.width,()=>String(d.width),e=>{let t=Number(e);!isNaN(t)&&t>0&&f({type:"SET_WIDTH",width:288===t?224:t})}),l("mcbd-sidebar-open",d.isOpen,()=>String(d.isOpen),e=>{("true"===e||"false"===e)&&f({type:"SET_OPEN",isOpen:"true"===e})}),l("mcbd-repo-tab-bar-mode",d.repoTabBarMode,()=>d.repoTabBarMode,e=>{(0,i.m3)(e)&&f({type:"SET_REPO_TAB_BAR_MODE",repoTabBarMode:e})});let p=(0,o.useCallback)(()=>{f({type:"TOGGLE"})},[]),g=(0,o.useCallback)(e=>{f({type:"SET_WIDTH",width:e})},[]),m=(0,o.useCallback)(()=>{f({type:"OPEN_MOBILE_DRAWER"})},[]),y=(0,o.useCallback)(()=>{f({type:"CLOSE_MOBILE_DRAWER"})},[]),h=(0,o.useCallback)(e=>{f({type:"SET_SORT_KEY",sortKey:e})},[]),w=(0,o.useCallback)(e=>{f({type:"SET_SORT_DIRECTION",sortDirection:e})},[]),b=(0,o.useCallback)(e=>{f({type:"SET_VIEW_MODE",viewMode:e})},[]),S=(0,o.useCallback)(e=>{f({type:"SET_REPOSITORY_ORDER",repositoryOrder:e}),(0,i.ZC)(e)},[]),v=(0,o.useCallback)(e=>{f({type:"SET_REPO_TAB_BAR_MODE",repoTabBarMode:e})},[]),E=(0,o.useMemo)(()=>({isOpen:d.isOpen,width:d.width,isMobileDrawerOpen:d.isMobileDrawerOpen,sortKey:d.sortKey,sortDirection:d.sortDirection,toggle:p,setWidth:g,openMobileDrawer:m,closeMobileDrawer:y,setSortKey:h,setSortDirection:w,viewMode:d.viewMode,setViewMode:b,repositoryOrder:d.repositoryOrder,setRepositoryOrder:S,repoTabBarMode:d.repoTabBarMode,setRepoTabBarMode:v}),[d.isOpen,d.width,d.isMobileDrawerOpen,d.sortKey,d.sortDirection,d.viewMode,d.repositoryOrder,d.repoTabBarMode,p,g,m,y,h,w,b,S,v]);return(0,n.jsx)(s.Provider,{value:E,children:t})}function d(){let e=(0,o.useContext)(s);if(!e)throw Error("useSidebarContext must be used within a SidebarProvider");return e}function f(){return(0,o.useContext)(s)}},38218:(e,t,r)=>{r.d(t,{D:()=>i,a:()=>a});var n=r(12115);let o=n.useLayoutEffect,i=768;function a(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},{breakpoint:t=i}=e,[r,a]=(0,n.useState)(!1);return o(()=>{let e=window.matchMedia("(max-width: ".concat(t-1,"px)"));a(e.matches);let r=e=>{a(e.matches)};return e.addEventListener("change",r),()=>{e.removeEventListener("change",r)}},[t]),r}},38606:(e,t,r)=>{r.d(t,{A7:()=>c,kA:()=>i,f_:()=>f,dw:()=>u,XK:()=>p});var n=r(54014),o=r(55449);function i(e){return e?e.isWaitingForResponse?"waiting":e.isProcessing?"running":e.isRunning?"ready":"idle":"idle"}let a={start:"nextAction.start",sendMessage:"nextAction.sendMessage",approveReject:"nextAction.approveReject",replyToPrompt:"nextAction.replyToPrompt",checkStalled:"nextAction.checkStalled",running:"nextAction.running"};Object.values(a);let s="exited",l={idle:null,ready:"ready",running:"running",generating:"running",waiting:"waiting"};function c(e){if(!e)return"idle";let t=Object.values(e).filter(e=>void 0!==e);return 0===t.length?"idle":t.includes("waiting")?"waiting":t.includes("running")?"running":t.includes("generating")?"generating":t.includes("ready")?"ready":"idle"}function u(e,t,r){return e?Object.entries(e).map(e=>{var o;let[i,a]=e,s=null!=(o=null==t?void 0:t[i])?o:(0,n.f_)(i,i),l=null==r?void 0:r(i);return"".concat(s,": ").concat(null!=a?a:"idle").concat(l?" (".concat(l,")"):"")}).join(", "):""}let d=["prompt","menu","unclassified"];function f(e){var t,r,n;let o=Object.values(null!=(r=null!=(t=e.sessionStatusByInstance)?t:e.sessionStatusByCli)?r:{}).filter(e=>void 0!==e),i=!1,a=new Set;for(let e of o)e.awaitingInstruction&&(i=!0),e.waitingKind&&a.add(e.waitingKind);return{waitingKind:null!=(n=d.find(e=>a.has(e)))?n:null,awaitingInstruction:i}}function p(e){var t,r,u,d,p,g;let m=i(void 0!==e.isSessionRunning?{isRunning:null!=(t=e.isSessionRunning)&&t,isWaitingForResponse:null!=(r=e.isWaitingForResponse)&&r,isProcessing:null!=(u=e.isProcessing)&&u}:void 0),y=!!e.lastAssistantMessageAt&&(!e.lastViewedAt||new Date(e.lastAssistantMessageAt)>new Date(e.lastViewedAt)),{cliStatus:h,cliStatusLabels:w,exitedInstanceIds:b}=function(e){var t,r,a,l,c,u;let d={},f={},p=[],g=e.sessionStatusByInstance;if(!g){for(let c of null!=(t=e.selectedAgents)?t:(0,o.sA)())d[c]=i(null==(r=e.sessionStatusByCli)?void 0:r[c]),f[c]=(0,n.oo)(c),(null==(l=e.sessionStatusByCli)||null==(a=l[c])?void 0:a.sessionStatusReason)===s&&p.push(c);return{cliStatus:d,cliStatusLabels:f,exitedInstanceIds:p}}let m=e.agentInstances&&e.agentInstances.length>0?e.agentInstances:(0,n.lu)(null!=(c=e.selectedAgents)?c:(0,o.sA)()),y=new Set;for(let e of m)y.add(e.id),d[e.id]=i(g[e.id]),f[e.id]=(0,n.sw)(e),(null==(u=g[e.id])?void 0:u.sessionStatusReason)===s&&p.push(e.id);for(let[e,t]of Object.entries(g)){if(y.has(e))continue;let r=i(t);"idle"!==r&&(d[e]=r,f[e]=function(e){let t=n.XH.find(t=>e.startsWith("".concat(t,"-")));if(t){let r=e.slice(t.length+1);return"".concat((0,n.oo)(t)," ").concat(r)}return(0,n.f_)(e,e)}(e))}return{cliStatus:d,cliStatusLabels:f,exitedInstanceIds:p}}(e),S=c(h),{waitingKind:v,awaitingInstruction:E}=f(e);return{id:e.id,name:e.name,repositoryName:null!=(d=e.repositoryDisplayName)?d:e.repositoryName,status:m,hasUnread:y,lastActivity:e.updatedAt,description:e.description,cliStatus:h,cliStatusLabels:w,exitedInstanceIds:b,worktreePath:e.path,waitingKind:v,awaitingInstruction:E,nextActionKey:(p=l[S],g="waiting"===S?"approval":null,p&&"idle"!==p?"ready"===p?a.sendMessage:"waiting"===p&&"approval"===g?a.approveReject:"waiting"===p?a.replyToPrompt:(0,a.running):a.start)}}},39649:(e,t,r)=>{r.d(t,{$f:()=>d,H8:()=>u});var n=r(95155),o=r(12115),i=r(80344);let a={PROCESSING:2e3,SESSION_RUNNING:5e3,IDLE:1e4},s=(0,o.createContext)(null),l={selectedWorktreeId:null,worktrees:[],repositories:[],selectedWorktreeDetail:null,isLoading:!0,isLoadingDetail:!1,error:null};function c(e,t){switch(t.type){case"SET_WORKTREES":return{...e,worktrees:t.worktrees,isLoading:!1};case"SET_REPOSITORIES":return{...e,repositories:t.repositories};case"SELECT_WORKTREE":{var r;let n=null!=(r=e.worktrees.find(e=>e.id===t.id))?r:null;return{...e,selectedWorktreeId:t.id,selectedWorktreeDetail:null!=n?n:e.selectedWorktreeDetail,isLoadingDetail:null===n}}case"SET_WORKTREE_DETAIL":return{...e,selectedWorktreeDetail:t.detail};case"SET_LOADING":return{...e,isLoading:t.isLoading};case"SET_LOADING_DETAIL":return{...e,isLoadingDetail:t.isLoadingDetail};case"SET_ERROR":return{...e,error:t.error,isLoading:!1};default:return e}}function u(e){let{children:t,externalWorktrees:r,externalRepositories:u,externalIsLoading:d,externalError:f,externalRefresh:p}=e,g=void 0!==r,[m,y]=(0,o.useReducer)(c,l);(0,o.useEffect)(()=>{g&&r&&y({type:"SET_WORKTREES",worktrees:r})},[g,r]),(0,o.useEffect)(()=>{g&&u&&y({type:"SET_REPOSITORIES",repositories:u})},[g,u]);let h=(0,o.useCallback)(async()=>{if(!g){y({type:"SET_LOADING",isLoading:!0}),y({type:"SET_ERROR",error:null});try{var e;let t=await i.y.getAll();y({type:"SET_WORKTREES",worktrees:t.worktrees}),y({type:"SET_REPOSITORIES",repositories:null!=(e=t.repositories)?e:[]})}catch(e){y({type:"SET_ERROR",error:e instanceof Error?e.message:"Failed to fetch worktrees"})}}},[g]),w=(0,o.useCallback)(async e=>{y({type:"SELECT_WORKTREE",id:e}),y({type:"SET_ERROR",error:null});try{i.y.markAsViewed(e).catch(e=>{console.warn("[WorktreeSelectionContext] Failed to mark as viewed:",e)});let t=await i.y.getById(e);y({type:"SET_WORKTREE_DETAIL",detail:t})}catch(e){y({type:"SET_ERROR",error:e instanceof Error?e.message:"Failed to fetch worktree detail"})}finally{y({type:"SET_LOADING_DETAIL",isLoadingDetail:!1})}},[]),b=(0,o.useCallback)(async()=>{if(g&&p)return void await p();await h()},[g,p,h]);(0,o.useEffect)(()=>{g||h()},[h,g]),(0,o.useEffect)(()=>{if(g)return;let e=null,t=!0,r=async()=>{if(t)try{var n,o;let s=await i.y.getAll();y({type:"SET_WORKTREES",worktrees:s.worktrees}),y({type:"SET_REPOSITORIES",repositories:null!=(n=s.repositories)?n:[]});let l=(o=s.worktrees).some(e=>e.isProcessing||e.isWaitingForResponse)?a.PROCESSING:o.some(e=>e.isSessionRunning)?a.SESSION_RUNNING:a.IDLE;t&&(e=setTimeout(r,l))}catch(n){if(n instanceof i.hD&&401===n.status)return;console.error("[WorktreeSelectionContext] Polling error:",n),t&&(e=setTimeout(r,a.SESSION_RUNNING))}};return r(),()=>{t=!1,e&&clearTimeout(e)}},[g]);let S=g&&void 0!==d?d:m.isLoading,v=g&&f?f.message:null,E={selectedWorktreeId:m.selectedWorktreeId,worktrees:m.worktrees,repositories:m.repositories,selectedWorktreeDetail:m.selectedWorktreeDetail,isLoading:S,isLoadingDetail:m.isLoadingDetail,error:null!=v?v:m.error,selectWorktree:w,refreshWorktrees:b};return(0,n.jsx)(s.Provider,{value:E,children:t})}function d(){let e=(0,o.useContext)(s);if(!e)throw Error("useWorktreeSelection must be used within a WorktreeSelectionProvider");return e}},44308:(e,t,r)=>{r.d(t,{$h:()=>d,DR:()=>o,IH:()=>c,Iu:()=>n,Nb:()=>f,SD:()=>i,_d:()=>l,bm:()=>p,ks:()=>s,t7:()=>u,z7:()=>a});let n=7e3,o=["in_review","approval","stalled"],i="in_review",a="filter",s="/review?".concat(a,"=approval");function l(e){return e&&o.includes(e)?e:null}let c=["claude","codex","copilot","antigravity","opencode"],u=1e3,d=5,f=100,p=1e3},52703:(e,t,r)=>{r.d(t,{Oo:()=>o,ST:()=>n,T4:()=>s,dz:()=>a,rz:()=>i,zS:()=>l});let n="client_version",o="version_mismatch",i="chat_turn_progress",a="messages_invalidated",s="model_changed";function l(e){let t;try{t=JSON.parse(e)}catch(e){return null}if(!t||"object"!=typeof t)return null;let r=t;if("broadcast"===r.type){let e=r.data;return e&&"object"==typeof e?"string"!=typeof e.type?null:(void 0===e.worktreeId&&"string"==typeof r.worktreeId&&(e.worktreeId=r.worktreeId),e):null}return"string"==typeof r.type?r:null}},54014:(e,t,r)=>{r.d(t,{Ab:()=>o,NL:()=>y,O6:()=>p,XH:()=>n,f_:()=>d,hR:()=>c,lu:()=>g,n6:()=>s,oo:()=>u,pQ:()=>i,sw:()=>f,vz:()=>m});let n=["claude","codex","gemini","vibe-local","opencode","copilot","antigravity","command-code"],o=10,i=50,a=/^[a-zA-Z0-9_-]+$/;function s(e){return"string"==typeof e&&e.length>0&&e.length<=64&&a.test(e)}let l={claude:"Claude",codex:"Codex",gemini:"Gemini","vibe-local":"Vibe Local",opencode:"OpenCode",copilot:"Copilot",antigravity:"Antigravity","command-code":"Command Code"};function c(e){return n.includes(e)}function u(e){var t;return null!=(t=l[e])?t:e}function d(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"Assistant";return e&&c(e)?u(e):t}function f(e){let t=e.alias;return"string"==typeof t&&t.trim().length>0?t:u(e.cliTool)}function p(e,t,r){let n=e.find(e=>e.id===t);return n?f(n):u(r)}function g(e){return e.map((e,t)=>({id:e,cliTool:e,alias:u(e),order:t}))}let m=128,y=2097152},55449:(e,t,r)=>{r.d(t,{IK:()=>l,qD:()=>d,sA:()=>s,zk:()=>o});var n=r(63001);let o="/api/settings/default-agents",i=n.fJ,a=new Set;function s(){return i}function l(e){if(!Array.isArray(e))return!1;let t=(0,n.Lt)(e);if(!t.valid)return!1;let r=t.value;if(r.length===i.length&&r.every((e,t)=>e===i[t]))return!1;for(let e of(i=r,a))e();return!0}let c=null,u=!1;async function d(){return u?i:c||("function"!=typeof fetch?i:c=(async()=>{try{let e=await fetch(o);if(e.ok){let t=await e.json();l(null==t?void 0:t.defaultSelectedAgents),u=!0}}catch(e){}finally{c=null}return i})())}},63001:(e,t,r)=>{r.d(t,{Lt:()=>s,Wj:()=>i,eu:()=>o,fJ:()=>a});var n=r(54014);let o=2,i=6,a=["claude","codex","antigravity"];function s(e){return e.length<o||e.length>i?{valid:!1,error:"Must be ".concat(o,"-").concat(i," elements")}:e.every(e=>"string"==typeof e&&n.XH.includes(e))?new Set(e).size!==e.length?{valid:!1,error:"Duplicate tool IDs not allowed"}:{valid:!0,value:e}:{valid:!1,error:"Invalid CLI tool ID"}}},63365:(e,t,r)=>{r.d(t,{tS:()=>u,xM:()=>d,T3:()=>f});var n=r(95155),o=r(12115),i=r(52703);function a(){return"undefined"!=typeof globalThis&&"function"==typeof globalThis.WebSocket?globalThis.WebSocket:null}let s=()=>{},l={status:"disconnected",connected:!1,subscribe:s,unsubscribe:s,addListener:()=>s},c=(0,o.createContext)(null);function u(e){let{children:t,enabled:r=!0}=e,s=(0,o.useRef)(new Set),l=(0,o.useRef)(new Map),{status:u,subscribe:d,unsubscribe:f}=function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},{onEvent:t,onStatusChange:r,autoReconnect:n=!0,reconnectBaseDelay:s=1e3,reconnectMaxDelay:l=3e4,enabled:c=!0}=e,[u,d]=(0,o.useState)("disconnected"),f=(0,o.useRef)(null),p=(0,o.useRef)(null),g=(0,o.useRef)(0),m=(0,o.useRef)(new Set),y=(0,o.useRef)(!1),h=(0,o.useRef)(t);h.current=t;let w=(0,o.useRef)(r);w.current=r;let b=(0,o.useCallback)(e=>{var t;d(e),null==(t=w.current)||t.call(w,e)},[]),S=(0,o.useCallback)(()=>{null!==p.current&&(clearTimeout(p.current),p.current=null)},[]),v=(0,o.useCallback)(()=>{if(!c)return;let e=a();if(!e||f.current&&(f.current.readyState===e.OPEN||f.current.readyState===e.CONNECTING))return;S(),y.current=!1,b("connecting");let t="https:"===window.location.protocol?"wss:":"ws:",r=new e("".concat(t,"//").concat(window.location.host));f.current=r,r.onopen=()=>{g.current=0,b("connected");try{r.send(JSON.stringify({type:i.ST,version:"0.33.0"}))}catch(e){}m.current.forEach(e=>{try{r.send(JSON.stringify({type:"subscribe",worktreeId:e}))}catch(e){}})},r.onmessage=e=>{var t;let r="string"==typeof e.data?e.data:String(e.data),n=(0,i.zS)(r);n&&(null==(t=h.current)||t.call(h,n))},r.onerror=()=>{b("error")},r.onclose=()=>{var e;if(f.current=null,b("disconnected"),y.current||!n||"undefined"!=typeof document&&"hidden"===document.visibilityState)return;let t=(e=g.current,Math.min(s*2**Math.max(0,e),l));g.current+=1,p.current=setTimeout(()=>{p.current=null,v()},t)}},[c,n,s,l,b,S]),E=(0,o.useCallback)(()=>{if(S(),y.current=!0,f.current){try{f.current.close(1e3,"Client disconnect")}catch(e){}f.current=null}},[S]),T=(0,o.useCallback)(e=>{let t=f.current,r=a();if(t&&r&&t.readyState===r.OPEN)try{t.send(JSON.stringify(e))}catch(e){}},[]),C=(0,o.useCallback)(e=>{m.current.has(e)||(m.current.add(e),T({type:"subscribe",worktreeId:e}))},[T]),k=(0,o.useCallback)(e=>{m.current.has(e)&&(m.current.delete(e),T({type:"unsubscribe",worktreeId:e}))},[T]);return(0,o.useEffect)(()=>{if(c)return v(),()=>{E()}},[c,v,E]),(0,o.useEffect)(()=>{if(!c||"undefined"==typeof document)return;let e=()=>{"visible"===document.visibilityState&&(f.current||(g.current=0,v()))};return document.addEventListener("visibilitychange",e),()=>document.removeEventListener("visibilitychange",e)},[c,v]),{status:u,subscribe:C,unsubscribe:k,send:T}}({enabled:r,onEvent:(0,o.useCallback)(e=>{s.current.forEach(t=>{try{t(e)}catch(e){}})},[])}),p=(0,o.useCallback)(e=>{var t;let r=l.current,n=null!=(t=r.get(e))?t:0;r.set(e,n+1),0===n&&d(e)},[d]),g=(0,o.useCallback)(e=>{var t;let r=l.current,n=null!=(t=r.get(e))?t:0;n<=1?(r.delete(e),f(e)):r.set(e,n-1)},[f]),m=(0,o.useCallback)(e=>(s.current.add(e),()=>{s.current.delete(e)}),[]),y=(0,o.useMemo)(()=>({status:u,connected:"connected"===u,subscribe:p,unsubscribe:g,addListener:m}),[u,p,g,m]);return(0,n.jsx)(c.Provider,{value:y,children:t})}function d(){var e;return null!=(e=(0,o.useContext)(c))?e:l}function f(e){let{addListener:t}=d(),r=(0,o.useRef)(e);r.current=e,(0,o.useEffect)(()=>t(e=>r.current(e)),[t])}},65380:(e,t,r)=>{r.d(t,{H:()=>s,O:()=>a});var n=r(95155),o=r(12115);let i=(0,o.createContext)(!1);function a(e){let{children:t,authEnabled:r}=e;return(0,n.jsx)(i.Provider,{value:r,children:t})}function s(){return(0,o.useContext)(i)}},66966:(e,t,r)=>{r.d(t,{g7:()=>u,rC:()=>f,Fn:()=>d});var n=r(95155),o=r(12115),i=r(80344),a=r(63365);let s=[2e3,5e3,1e4];var l=r(39649);let c=(0,o.createContext)(null);function u(e){let{children:t}=e,{worktrees:r,repositories:u,isLoading:d,error:f,refresh:p}=function(){let[e,t]=(0,o.useState)([]),[r,n]=(0,o.useState)([]),[l,c]=(0,o.useState)(!0),[u,d]=(0,o.useState)(null),f=(0,o.useRef)(null),p=(0,o.useRef)([]),g=(0,o.useRef)(null),m=(0,o.useRef)(0),y=(0,o.useRef)(null),h=(0,o.useRef)(async()=>{}),w=(0,o.useCallback)(()=>{null!==y.current&&(clearTimeout(y.current),y.current=null)},[]),{connected:b,subscribe:S,unsubscribe:v,addListener:E}=(0,a.xM)(),T=(0,o.useRef)(b);T.current=b;let C=(0,o.useCallback)(async()=>{try{var e,r;d(null);let a=await fetch("/api/worktrees"),s=(0,i.O0)(a);if(s)throw s;if(!a.ok)throw Error("Failed to fetch worktrees: ".concat(a.status));let l=(0,i.xd)(a);if(l)throw l;let c=await a.json(),u=null!=(e=c.worktrees)?e:[],f=null!=(r=c.repositories)?r:[];(0,o.startTransition)(()=>{t(u),n(f)}),p.current=u,m.current=0,w()}catch(r){let e=r instanceof Error?r:Error(String(r));console.error("[useWorktreesCache] Failed to fetch worktrees:",e),d(e);let t=m.current;0===p.current.length&&t<s.length&&(m.current=t+1,w(),y.current=setTimeout(()=>{y.current=null,h.current()},s[t]))}finally{c(!1)}},[w]);h.current=C,(0,o.useEffect)(()=>{C()},[C]),(0,o.useEffect)(()=>w,[w]);let k=(0,o.useCallback)(()=>p.current.some(e=>!0===e.isSessionRunning),[]),O=(0,o.useCallback)(()=>{let e=k();return T.current?e?2e4:6e4:e?5e3:3e4},[k]),R=(0,o.useCallback)(()=>{null!==f.current&&(clearInterval(f.current),f.current=null),g.current=null},[]),x=(0,o.useCallback)(()=>{R();let e=O();g.current=e,f.current=setInterval(()=>{C()},e)},[O,C,R]);(0,o.useEffect)(()=>{let e=()=>{document.hidden?R():(C(),x())},t=setTimeout(()=>{x()},0);return document.addEventListener("visibilitychange",e),()=>{clearTimeout(t),R(),document.removeEventListener("visibilitychange",e)}},[C,x,R]),(0,o.useEffect)(()=>{if(p.current=e,"undefined"!=typeof document&&document.hidden||null===g.current)return;let t=O();g.current!==t&&x()},[e,b,O,x]);let N=e.map(e=>e.id).sort().join(" ");return(0,o.useEffect)(()=>{let e=N.length>0?N.split(" "):[];return e.forEach(e=>S(e)),()=>{e.forEach(e=>v(e))}},[N,S,v]),(0,o.useEffect)(()=>E(e=>{if("session_status_changed"===e.type&&"string"==typeof e.worktreeId){let i=e.worktreeId,a=e.isWaitingForResponse;if("boolean"==typeof a){var r,n;let s=null!=(r=e.instance)?r:null,l=null!=(n=e.waitingKind)?n:null;(0,o.startTransition)(()=>{t(e=>{let t=!1,r=e.map(e=>{if(e.id!==i)return e;let r=function(e,t){var r,n,o;let i,a=null!=(n=t.instance)?n:null,s=a?null==(r=e.sessionStatusByInstance)?void 0:r[a]:void 0,l=e.sessionStatusByInstance;if(a&&s&&s.isWaitingForResponse!==t.waiting&&(l={...e.sessionStatusByInstance,[a]:{...s,isWaitingForResponse:t.waiting,waitingKind:null!=(o=t.waitingKind)?o:null}}),t.waiting)i=!0;else{let e=l?Object.values(l):[];i=e.length>0&&e.some(e=>(null==e?void 0:e.isWaitingForResponse)===!0)}return l===e.sessionStatusByInstance&&i===e.isWaitingForResponse?e:{...e,sessionStatusByInstance:l,isWaitingForResponse:i}}(e,{waiting:a,instance:s,waitingKind:l});return r!==e&&(t=!0),r});return t?r:e})});return}let s=e.isRunning;if("boolean"==typeof s){if((null!=e.cliTool||null!=e.instance)&&!1===s)return void C();(0,o.startTransition)(()=>{t(e=>{let t=!1,r=e.map(e=>e.id===i&&e.isSessionRunning!==s?(t=!0,{...e,isSessionRunning:s}):e);return t?r:e})})}}else("message"===e.type||"message_updated"===e.type)&&C()}),[E,C]),{worktrees:e,repositories:r,isLoading:l,error:u,refresh:C}}(),g=(0,o.useMemo)(()=>({worktrees:r,repositories:u,isLoading:d,error:f,refresh:p}),[r,u,d,f,p]);return(0,n.jsx)(c.Provider,{value:g,children:(0,n.jsx)(l.H8,{externalWorktrees:r,externalRepositories:u,externalIsLoading:d,externalError:f,externalRefresh:p,children:t})})}function d(){let e=(0,o.useContext)(c);if(null===e)throw Error("useWorktreesCacheContext must be used within a WorktreesCacheProvider");return e}function f(){return(0,o.useContext)(c)}},68704:(e,t,r)=>{r.d(t,{Uf:()=>i,d8:()=>a,fM:()=>s,of:()=>c,r5:()=>o,rq:()=>l});var n=r(2317);let o="medium",i=["large","medium","small","xsmall"],a={large:{value:"large",rootFontSizePx:18,factor:1.125,terminalFontSize:16},medium:{value:"medium",rootFontSizePx:16,factor:1,terminalFontSize:14},small:{value:"small",rootFontSizePx:14,factor:.875,terminalFontSize:12},xsmall:{value:"xsmall",rootFontSizePx:12.5,factor:.78,terminalFontSize:11}};function s(e){return"string"==typeof e&&Object.prototype.hasOwnProperty.call(a,e)}function l(e){return a[e].terminalFontSize}function c(){let{value:e,setValue:t,isAvailable:r}=(0,n.V)({key:"mcbd-pc-display-size",defaultValue:o,validate:s});return{size:e,setSize:t,isAvailable:r}}},70628:(e,t,r)=>{r.d(t,{K:()=>s,S:()=>a});var n=r(95155),o=r(12115);let i=(0,o.createContext)({open:!1,setOpen:()=>{},toggle:()=>{}});function a(e){let{children:t}=e,[r,a]=(0,o.useState)(!1),s=(0,o.useCallback)(()=>a(e=>!e),[]),l=(0,o.useMemo)(()=>({open:r,setOpen:a,toggle:s}),[r,s]);return(0,n.jsx)(i.Provider,{value:l,children:t})}function s(){return(0,o.useContext)(i)}},77016:(e,t,r)=>{r.d(t,{W:()=>w,n:()=>b});var n=r(95155),o=r(12115),i=r(18955),a=r(52056),s=r(89559),l=r(65229),c=r(59854),u=r(63365),d=r(52703);let f=0,p=new Set;function g(){for(let e of p)e()}function m(e){return p.add(e),()=>{p.delete(e)}}function y(){return f>0}function h(){return!1}function w(){return(0,o.useSyncExternalStore)(m,y,h)}function b(){let e=(0,i.c)("common"),[t,r]=(0,o.useState)(null),[p,m]=(0,o.useState)(null),y=(0,o.useCallback)(e=>{if(e.type!==d.Oo)return;let{serverVersion:t,clientVersion:n}=e;"string"==typeof t&&"string"==typeof n&&t&&n&&t!==p&&r({serverVersion:t,clientVersion:n})},[p]);(0,u.T3)(y);let h=null!==t;(0,o.useEffect)(()=>{if(h)return f+=1,g(),()=>{f-=1,g()}},[h]);let w=(0,o.useCallback)(()=>{window.location.reload()},[]),b=(0,o.useCallback)(()=>{r(e=>(e&&m(e.serverVersion),null))},[]);return t?(0,n.jsxs)("div",{"data-testid":"version-mismatch-banner",role:"alert","aria-live":"assertive",className:"fixed top-3 left-1/2 -translate-x-1/2 flex items-start gap-3 max-w-[92vw] rounded-lg border border-warning-border bg-warning-subtle px-4 py-3 text-warning-foreground shadow-lg",style:{zIndex:c.M.TOAST},children:[(0,n.jsx)(a.A,{className:"h-5 w-5 shrink-0 mt-0.5","aria-hidden":"true"}),(0,n.jsxs)("div",{className:"flex flex-col gap-0.5 text-sm",children:[(0,n.jsx)("span",{className:"font-semibold",children:e("versionMismatch.title")}),(0,n.jsx)("span",{children:e("versionMismatch.description",{serverVersion:t.serverVersion,clientVersion:t.clientVersion})})]}),(0,n.jsxs)("button",{type:"button","data-testid":"version-mismatch-reload",onClick:w,className:"shrink-0 inline-flex items-center gap-1.5 rounded-md border border-warning-border px-3 py-1.5 text-sm font-medium hover:opacity-80 focus:outline-none focus:ring-2 focus:ring-offset-2",children:[(0,n.jsx)(s.A,{className:"h-4 w-4","aria-hidden":"true"}),e("versionMismatch.reload")]}),(0,n.jsx)("button",{type:"button","data-testid":"version-mismatch-dismiss",onClick:b,"aria-label":e("versionMismatch.dismiss"),className:"shrink-0 hover:opacity-70 focus:outline-none focus:ring-2 focus:ring-offset-2",children:(0,n.jsx)(l.A,{className:"h-4 w-4","aria-hidden":"true"})})]}):null}},80344:(e,t,r)=>{r.d(t,{$T:()=>d,GQ:()=>p,O0:()=>i,Rx:()=>c,gC:()=>u,hD:()=>n,hS:()=>f,xd:()=>a,y:()=>l});class n extends Error{constructor(e,t,r){super(e),this.status=t,this.data=r,this.name="ApiError"}}async function o(e,t,r){if(!(e.headers.get("content-type")||"").includes("application/json"))return t;try{return await e.json()}catch(e){return t}}function i(e){var t;return e.redirected&&(null!=(t=e.url)?t:"").includes("/login")?new n("Authentication required",401):null}function a(e){return e.headers?(e.headers.get("content-type")||"").includes("application/json")?null:new n("Unexpected response format",e.status):null}async function s(e,t){try{let r=new Headers(null==t?void 0:t.headers);r.set("Content-Type","application/json");let s=await fetch(e,{...t,headers:r}),l=i(s);if(l)throw l;if(!s.ok){let e=await o(s,{},"error-body");throw new n(e.error||"HTTP error ".concat(s.status),s.status,e)}let c=a(s);if(c)throw c;return s.json()}catch(e){if(e instanceof n)throw e;throw new n(e instanceof Error?e.message:"Unknown error",0,e)}}let l={getAll:async()=>s("/api/worktrees"),getById:async e=>s("/api/worktrees/".concat(e)),updateDescription:async(e,t)=>s("/api/worktrees/".concat(e),{method:"PATCH",body:JSON.stringify({description:t})}),updateLink:async(e,t)=>s("/api/worktrees/".concat(e),{method:"PATCH",body:JSON.stringify({link:t})}),toggleFavorite:async(e,t)=>s("/api/worktrees/".concat(e),{method:"PATCH",body:JSON.stringify({favorite:t})}),updateStatus:async(e,t)=>s("/api/worktrees/".concat(e),{method:"PATCH",body:JSON.stringify({status:t})}),updateCliTool:async(e,t)=>s("/api/worktrees/".concat(e),{method:"PATCH",body:JSON.stringify({cliToolId:t})}),markAsViewed:async e=>s("/api/worktrees/".concat(e,"/viewed"),{method:"PATCH"}),async getMessages(e,t,r,n){let o=new URLSearchParams;return t&&o.append("cliTool",t),r&&o.append("includeArchived","true"),"number"==typeof n&&Number.isFinite(n)&&o.append("limit",String(n)),s("/api/worktrees/".concat(e,"/messages").concat(o.toString()?"?".concat(o.toString()):""))},async sendMessage(e,t,r){var n;let o={content:t};return(null==r?void 0:r.cliToolId)&&(o.cliToolId=r.cliToolId),(null==r?void 0:r.instanceId)&&(o.instanceId=r.instanceId),(null==r?void 0:r.imagePath)&&(o.imagePath=r.imagePath),null===(n=await s("/api/worktrees/".concat(e,"/send"),{method:"POST",body:JSON.stringify(o)}))||"object"!=typeof n||n.timestamp instanceof Date?n:{...n,timestamp:new Date(n.timestamp)}},async uploadImageFile(e,t){let r=Date.now(),n="".concat(r,"-").concat(t.name),i=".commandmate/attachments",a=new FormData;a.append("file",new File([t],n,{type:t.type}));let s=await fetch("/api/worktrees/".concat(e,"/upload/").concat(i),{method:"POST",body:a});if(!s.ok){var l;let e=await o(s,{},"error-body");throw Error((null==e||null==(l=e.error)?void 0:l.message)||"Upload failed (HTTP ".concat(s.status,")"))}return{path:(await o(s,{},"response-body")).path||"".concat(i,"/").concat(n)}},getLogs:async e=>s("/api/worktrees/".concat(e,"/logs")),async getLogFile(e,t,r){let n=(null==r?void 0:r.sanitize)?"?sanitize=true":"";return s("/api/worktrees/".concat(e,"/logs/").concat(t).concat(n))},async killSession(e,t,r){let n=new URLSearchParams;t&&n.set("cliTool",t),r&&n.set("instance",r);let o=n.toString();return s("/api/worktrees/".concat(e,"/kill-session").concat(o?"?".concat(o):""),{method:"POST"})}},c={scan:async e=>s("/api/repositories/scan",{method:"POST",body:JSON.stringify({repositoryPath:e})}),sync:async()=>s("/api/repositories/sync",{method:"POST"}),delete:async e=>s("/api/repositories",{method:"DELETE",body:JSON.stringify({repositoryPath:e})}),async clone(e,t){var r;return s("/api/repositories/clone",{method:"POST",body:JSON.stringify({cloneUrl:e,fork:null!=(r=null==t?void 0:t.fork)&&r})})},getCloneStatus:async e=>s("/api/repositories/clone/".concat(e)),getExcluded:async()=>s("/api/repositories/excluded"),restore:async e=>s("/api/repositories/restore",{method:"PUT",body:JSON.stringify({repositoryPath:e})}),list:async()=>s("/api/repositories"),updateDisplayName:async(e,t)=>s("/api/repositories/".concat(encodeURIComponent(e)),{method:"PUT",body:JSON.stringify({displayName:t})}),updateVisibility:async(e,t)=>s("/api/repositories/".concat(encodeURIComponent(e)),{method:"PUT",body:JSON.stringify({visible:t})}),updateEnabled:async(e,t)=>s("/api/repositories/".concat(encodeURIComponent(e)),{method:"PUT",body:JSON.stringify({enabled:t})}),validatePath:async e=>s("/api/repositories/validate-path",{method:"POST",body:JSON.stringify({repositoryPath:e})})},u={async browse(e){let t=e?"?path=".concat(encodeURIComponent(e)):"";return s("/api/fs/browse".concat(t))},addRecentPath:async e=>s("/api/fs/recent-paths",{method:"POST",body:JSON.stringify({path:e})})},d={getAll:async e=>(await s("/api/worktrees/".concat(e,"/memos"))).memos,create:async(e,t)=>(await s("/api/worktrees/".concat(e,"/memos"),{method:"POST",body:JSON.stringify(t||{})})).memo,update:async(e,t,r)=>(await s("/api/worktrees/".concat(e,"/memos/").concat(t),{method:"PUT",body:JSON.stringify(r)})).memo,delete:async(e,t)=>s("/api/worktrees/".concat(e,"/memos/").concat(t),{method:"DELETE"}),async reorder(e,t){await s("/api/worktrees/".concat(e,"/memos"),{method:"PATCH",body:JSON.stringify({memoIds:t})})}};function f(e){return e instanceof n||e instanceof Error?e.message:"An unknown error occurred"}let p={checkForUpdate:async()=>s("/api/app/update-check",{method:"GET"}),startUpdate:async()=>s("/api/app/update",{method:"POST"}),async ping(){try{return(await fetch("/api/auth/status",{cache:"no-store"})).ok}catch(e){return!1}}}},89275:(e,t,r)=>{r.d(t,{Bo:()=>u,Hq:()=>l});var n=r(95155),o=r(12115),i=r(20063);let a={startTransition:e=>e()},s=(0,o.createContext)(null);function l(){var e;let t=(0,i.useRouter)(),{startTransition:r}=null!=(e=(0,o.useContext)(s))?e:a;return(0,o.useMemo)(()=>({push:e=>r(()=>t.push(e)),replace:e=>r(()=>t.replace(e))}),[t,r])}function c(e){let{onCommit:t}=e,r=(0,i.usePathname)(),n=(0,o.useRef)(!1);return(0,o.useEffect)(()=>{if(!n.current){n.current=!0;return}t()},[r,t]),null}function u(e){let{children:t}=e,r=(0,o.useRef)(null),i=(0,o.useCallback)(()=>{var e;null==(e=r.current)||e.call(r)},[]),a=(0,o.useCallback)(e=>{var t;t=()=>new Promise(t=>{let n=!1,o=()=>{n||(n=!0,t())};r.current=o,e(),window.setTimeout(o,500)}),"undefined"==typeof document||"function"!=typeof document.startViewTransition||"function"==typeof window.matchMedia&&window.matchMedia("(prefers-reduced-motion: reduce)").matches?t():document.startViewTransition(t)},[]),l=(0,o.useMemo)(()=>({startTransition:a}),[a]);return(0,n.jsxs)(s.Provider,{value:l,children:[(0,n.jsx)(c,{onCommit:i}),t]})}},92614:(e,t,r)=>{r.d(t,{C:()=>s,E:()=>a});var n=r(95155),o=r(12115);let i=(0,o.createContext)({open:!1,setOpen:()=>{},toggle:()=>{}});function a(e){let{children:t}=e,[r,a]=(0,o.useState)(!1),s=(0,o.useCallback)(()=>a(e=>!e),[]),l=(0,o.useMemo)(()=>({open:r,setOpen:a,toggle:s}),[r,s]);return(0,n.jsx)(i.Provider,{value:l,children:t})}function s(){return(0,o.useContext)(i)}},94442:(e,t,r)=>{r.d(t,{dj:()=>v,tE:()=>S});var n=r(95155),o=r(12115),i=r(47650),a=r(18955),s=r(42529),l=r(78874),c=r(52056),u=r(23327),d=r(65229),f=r(59854),p=r(9900),g=r(9286);function m(e){let{type:t,iconColor:r}=e,o="h-5 w-5 ".concat(r);switch(t){case"success":return(0,n.jsx)(s.A,{className:o,"data-testid":"toast-icon-success"});case"error":return(0,n.jsx)(l.A,{className:o,"data-testid":"toast-icon-error"});case"warning":return(0,n.jsx)(c.A,{className:o,"data-testid":"toast-icon-warning"});default:return(0,n.jsx)(u.A,{className:o,"data-testid":"toast-icon-info"})}}function y(e){let{id:t,message:r,type:i,onClose:s,duration:l=3e3,onClick:c}=e,u=(0,a.c)("common"),f=(0,o.useRef)(null),y=function(e){switch(e){case"success":return{bgColor:"bg-success-subtle",borderColor:"border-success-border",textColor:"text-success-foreground",iconColor:"text-success-foreground"};case"error":return{bgColor:"bg-danger-subtle",borderColor:"border-danger-border",textColor:"text-danger-foreground",iconColor:"text-danger-foreground"};case"warning":return{bgColor:"bg-warning-subtle",borderColor:"border-warning-border",textColor:"text-warning-foreground",iconColor:"text-warning-foreground"};default:return{bgColor:"bg-info-subtle",borderColor:"border-info-border",textColor:"text-info-foreground",iconColor:"text-info-foreground"}}}(i),[h,w]=(0,o.useState)(!0),{shouldRender:b,isExiting:S}=(0,g.O)(h,p.Ys),v=(0,o.useRef)(s);v.current=s,(0,o.useEffect)(()=>{b||v.current(t)},[b,t]),(0,o.useEffect)(()=>(l>0&&(f.current=setTimeout(()=>{w(!1)},l)),()=>{f.current&&clearTimeout(f.current)}),[l]);let E=(0,o.useCallback)(()=>{f.current&&clearTimeout(f.current),w(!1)},[]);return(0,n.jsxs)("div",{"data-testid":"toast-".concat(t),role:"alert",className:"\n ".concat(y.bgColor,"\n ").concat(y.borderColor,"\n ").concat(y.textColor,"\n border rounded-lg shadow-lg p-4 min-w-[300px] max-w-[400px]\n flex items-start gap-3\n ").concat(S?"animate-out fade-out-0 slide-out-to-right-full duration-200 fill-mode-forwards pointer-events-none":"animate-slide-in","\n "),children:[(0,n.jsx)(m,{type:i,iconColor:y.iconColor}),c?(0,n.jsx)("button",{type:"button","data-testid":"toast-action-button",onClick:()=>{c(),E()},className:"flex-1 text-left text-sm font-medium underline-offset-2 hover:underline focus:outline-none focus-visible:ring-2 focus-visible:ring-ring rounded-sm",children:r}):(0,n.jsx)("p",{className:"flex-1 text-sm font-medium",children:r}),(0,n.jsx)("button",{"data-testid":"toast-close-button",onClick:E,"aria-label":u("closeNotification"),className:"\n ".concat(y.textColor,"\n hover:opacity-70\n focus:outline-none focus:ring-2 focus:ring-offset-2\n transition-opacity\n "),children:(0,n.jsx)(d.A,{className:"h-4 w-4"})})]})}function h(e){let{toasts:t,onClose:r}=e,[a,s]=(0,o.useState)(!1);(0,o.useEffect)(()=>{s(!0)},[]);let l=(0,n.jsx)("div",{"data-testid":"toast-container","aria-live":"polite",className:"fixed bottom-4 right-4 flex flex-col gap-2",style:{zIndex:f.M.TOAST},children:t.map(e=>(0,n.jsx)(y,{id:e.id,message:e.message,type:e.type,onClose:r,duration:e.duration,onClick:e.onClick},e.id))});return a?(0,i.createPortal)(l,document.body):null}function w(){let[e,t]=(0,o.useState)([]),r=(0,o.useRef)(0),n=(0,o.useCallback)(function(e){let n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"info",o=arguments.length>2&&void 0!==arguments[2]?arguments[2]:3e3,i=arguments.length>3?arguments[3]:void 0,a="toast-".concat(++r.current,"-").concat(Date.now()),s={id:a,message:e,type:n,duration:o,...(null==i?void 0:i.onClick)?{onClick:i.onClick}:{}};return t(e=>[...e,s]),a},[]),i=(0,o.useCallback)(e=>{t(t=>t.filter(t=>t.id!==e))},[]),a=(0,o.useCallback)(()=>{t([])},[]);return(0,o.useMemo)(()=>({toasts:e,showToast:n,removeToast:i,clearToasts:a}),[e,n,i,a])}let b=(0,o.createContext)(null);function S(e){let{children:t}=e,r=w();return(0,n.jsxs)(b.Provider,{value:r,children:[t,(0,n.jsx)(h,{toasts:r.toasts,onClose:r.removeToast})]})}function v(){let e=(0,o.useContext)(b),t=w();return null!=e?e:t}}}]);