@neuralnomads/codenomad-dev 0.20.0-dev-20260917-aa51cbb9 → 0.20.0-dev-20260918-a311de98

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 (223) hide show
  1. package/dist/api-types.js.map +1 -1
  2. package/dist/events/bus.js +2 -0
  3. package/dist/events/bus.js.map +1 -1
  4. package/dist/filesystem/__tests__/browser.test.js +10 -10
  5. package/dist/filesystem/__tests__/browser.test.js.map +1 -1
  6. package/dist/filesystem/__tests__/responsiveness.test.js +79 -0
  7. package/dist/filesystem/__tests__/responsiveness.test.js.map +1 -0
  8. package/dist/filesystem/__tests__/search-cache.test.js +48 -9
  9. package/dist/filesystem/__tests__/search-cache.test.js.map +1 -1
  10. package/dist/filesystem/__tests__/search.test.js +8 -8
  11. package/dist/filesystem/__tests__/search.test.js.map +1 -1
  12. package/dist/filesystem/__tests__/write-order.test.js +64 -0
  13. package/dist/filesystem/__tests__/write-order.test.js.map +1 -0
  14. package/dist/filesystem/browser.js +44 -46
  15. package/dist/filesystem/browser.js.map +1 -1
  16. package/dist/filesystem/file-access.js +19 -0
  17. package/dist/filesystem/file-access.js.map +1 -0
  18. package/dist/filesystem/search-cache.js +35 -9
  19. package/dist/filesystem/search-cache.js.map +1 -1
  20. package/dist/filesystem/search.js +9 -8
  21. package/dist/filesystem/search.js.map +1 -1
  22. package/dist/index.js +28 -18
  23. package/dist/index.js.map +1 -1
  24. package/dist/opencode/automation/desktop-plugin.js +69 -0
  25. package/dist/opencode/automation/desktop-plugin.js.map +1 -0
  26. package/dist/opencode/automation/desktop-plugin.test.js +155 -0
  27. package/dist/opencode/automation/desktop-plugin.test.js.map +1 -0
  28. package/dist/opencode/automation-plugin.js +90 -24
  29. package/dist/opencode/automation-plugin.js.map +1 -1
  30. package/dist/opencode/automation-plugin.test.js +14 -1
  31. package/dist/opencode/automation-plugin.test.js.map +1 -1
  32. package/dist/opencode/compatibility/contract-fixture.js +13 -1
  33. package/dist/opencode/compatibility/contract-fixture.js.map +1 -1
  34. package/dist/opencode/compatibility/location.js +13 -0
  35. package/dist/opencode/compatibility/location.js.map +1 -1
  36. package/dist/opencode/compatibility/location.test.js +44 -0
  37. package/dist/opencode/compatibility/location.test.js.map +1 -1
  38. package/dist/opencode/compatibility/runtime.js.map +1 -1
  39. package/dist/opencode/compatibility/transport.js +3 -0
  40. package/dist/opencode/compatibility/transport.js.map +1 -1
  41. package/dist/opencode/compatibility/transport.test.js +40 -0
  42. package/dist/opencode/compatibility/transport.test.js.map +1 -1
  43. package/dist/opencode/desktop-plugin-installation.js +103 -0
  44. package/dist/opencode/desktop-plugin-installation.js.map +1 -0
  45. package/dist/opencode/desktop-plugin-lifecycle.js +117 -0
  46. package/dist/opencode/desktop-plugin-lifecycle.js.map +1 -0
  47. package/dist/opencode/desktop-plugin-lifecycle.test.js +180 -0
  48. package/dist/opencode/desktop-plugin-lifecycle.test.js.map +1 -0
  49. package/dist/opencode/desktop-plugin-paths.js +30 -0
  50. package/dist/opencode/desktop-plugin-paths.js.map +1 -0
  51. package/dist/opencode/desktop-plugin-paths.test.js +46 -0
  52. package/dist/opencode/desktop-plugin-paths.test.js.map +1 -0
  53. package/dist/opencode/desktop-plugin-presence.js +42 -0
  54. package/dist/opencode/desktop-plugin-presence.js.map +1 -0
  55. package/dist/opencode/pruning-installation.js +3 -63
  56. package/dist/opencode/pruning-installation.js.map +1 -1
  57. package/dist/opencode/pruning-lifecycle.js +3 -64
  58. package/dist/opencode/pruning-lifecycle.js.map +1 -1
  59. package/dist/opencode/session-pruning/presence.js +1 -41
  60. package/dist/opencode/session-pruning/presence.js.map +1 -1
  61. package/dist/permissions/opencode-yolo-metadata.js +3 -1
  62. package/dist/permissions/opencode-yolo-metadata.js.map +1 -1
  63. package/dist/permissions/opencode-yolo-metadata.test.js +2 -2
  64. package/dist/permissions/opencode-yolo-metadata.test.js.map +1 -1
  65. package/dist/plugins/automation/plugin.mjs +504 -0
  66. package/dist/plugins/session-pruning/plugin.mjs +1 -1
  67. package/dist/server/routes/automation-plugin.js +31 -4
  68. package/dist/server/routes/automation-plugin.js.map +1 -1
  69. package/dist/server/routes/automation-plugin.test.js +46 -0
  70. package/dist/server/routes/automation-plugin.test.js.map +1 -1
  71. package/dist/server/routes/filesystem.js +3 -3
  72. package/dist/server/routes/filesystem.js.map +1 -1
  73. package/dist/server/routes/workspaces.js +13 -7
  74. package/dist/server/routes/workspaces.js.map +1 -1
  75. package/dist/server/routes/workspaces.test.js +31 -0
  76. package/dist/server/routes/workspaces.test.js.map +1 -1
  77. package/dist/server/routes/worktrees.js +232 -41
  78. package/dist/server/routes/worktrees.js.map +1 -1
  79. package/dist/server/routes/worktrees.test.js +113 -40
  80. package/dist/server/routes/worktrees.test.js.map +1 -1
  81. package/dist/workspaces/__tests__/git-worktrees.test.js +2 -2
  82. package/dist/workspaces/__tests__/git-worktrees.test.js.map +1 -1
  83. package/dist/workspaces/__tests__/native-worktree-fixture.js +22 -0
  84. package/dist/workspaces/__tests__/native-worktree-fixture.js.map +1 -0
  85. package/dist/workspaces/git-status.test.js +24 -1
  86. package/dist/workspaces/git-status.test.js.map +1 -1
  87. package/dist/workspaces/git-worktrees.js +37 -204
  88. package/dist/workspaces/git-worktrees.js.map +1 -1
  89. package/dist/workspaces/host-opencode-service.test.js +58 -1
  90. package/dist/workspaces/host-opencode-service.test.js.map +1 -1
  91. package/dist/workspaces/instance-events.js +5 -0
  92. package/dist/workspaces/instance-events.js.map +1 -1
  93. package/dist/workspaces/instance-events.test.js +36 -1
  94. package/dist/workspaces/instance-events.test.js.map +1 -1
  95. package/dist/workspaces/manager.js +124 -14
  96. package/dist/workspaces/manager.js.map +1 -1
  97. package/dist/workspaces/manager.test.js +25 -0
  98. package/dist/workspaces/manager.test.js.map +1 -1
  99. package/dist/workspaces/native-service-start.js +13 -0
  100. package/dist/workspaces/native-service-start.js.map +1 -0
  101. package/dist/workspaces/native-service-start.test.js +65 -0
  102. package/dist/workspaces/native-service-start.test.js.map +1 -0
  103. package/dist/workspaces/native-worktrees.js +140 -0
  104. package/dist/workspaces/native-worktrees.js.map +1 -0
  105. package/dist/workspaces/opencode-cli-service.js +10 -2
  106. package/dist/workspaces/opencode-cli-service.js.map +1 -1
  107. package/dist/workspaces/opencode-service.js +24 -2
  108. package/dist/workspaces/opencode-service.js.map +1 -1
  109. package/dist/workspaces/opencode-service.test.js +62 -0
  110. package/dist/workspaces/opencode-service.test.js.map +1 -1
  111. package/dist/workspaces/project-session-families.js +376 -0
  112. package/dist/workspaces/project-session-families.js.map +1 -0
  113. package/dist/workspaces/project-session-families.test.js +341 -0
  114. package/dist/workspaces/project-session-families.test.js.map +1 -0
  115. package/dist/workspaces/worktree-directory.js +36 -18
  116. package/dist/workspaces/worktree-directory.js.map +1 -1
  117. package/dist/workspaces/worktree-directory.test.js +123 -5
  118. package/dist/workspaces/worktree-directory.test.js.map +1 -1
  119. package/dist/workspaces/worktree-inventory.js +79 -0
  120. package/dist/workspaces/worktree-inventory.js.map +1 -0
  121. package/dist/workspaces/worktree-inventory.test.js +156 -0
  122. package/dist/workspaces/worktree-inventory.test.js.map +1 -0
  123. package/dist/workspaces/worktree-map.js +2 -5
  124. package/dist/workspaces/worktree-map.js.map +1 -1
  125. package/dist/workspaces/wsl-opencode-service.test.js +16 -2
  126. package/dist/workspaces/wsl-opencode-service.test.js.map +1 -1
  127. package/package.json +4 -3
  128. package/public/assets/App-I9uNKt0K.js +54 -0
  129. package/public/assets/App-I9uNKt0K.js.map +1 -0
  130. package/public/assets/{FilesTab-DY3Vr-3r.js → FilesTab-_xb_Aq0c.js} +3 -3
  131. package/public/assets/{FilesTab-DY3Vr-3r.js.map → FilesTab-_xb_Aq0c.js.map} +1 -1
  132. package/public/assets/{GitChangesTab-BD6CJngE.js → GitChangesTab-Cz0RckYn.js} +3 -3
  133. package/public/assets/{GitChangesTab-BD6CJngE.js.map → GitChangesTab-Cz0RckYn.js.map} +1 -1
  134. package/public/assets/{SplitFilePanel-BdY6d_6m.js → SplitFilePanel-DVkVS5C0.js} +2 -2
  135. package/public/assets/{SplitFilePanel-BdY6d_6m.js.map → SplitFilePanel-DVkVS5C0.js.map} +1 -1
  136. package/public/assets/{StatusTab-C-_2yaPa.js → StatusTab-DU1H4ngp.js} +2 -2
  137. package/public/assets/{StatusTab-C-_2yaPa.js.map → StatusTab-DU1H4ngp.js.map} +1 -1
  138. package/public/assets/{align-justify-DI8VTZ4G.js → align-justify-Czy9hp3K.js} +2 -2
  139. package/public/assets/{align-justify-DI8VTZ4G.js.map → align-justify-Czy9hp3K.js.map} +1 -1
  140. package/public/assets/{bundle-full-D_M65Eb_.js → bundle-full-CMakdq_6.js} +2 -2
  141. package/public/assets/{bundle-full-D_M65Eb_.js.map → bundle-full-CMakdq_6.js.map} +1 -1
  142. package/public/assets/{client-state-CWCzCOz6.js → client-state-DGbupmmR.js} +2 -2
  143. package/public/assets/{client-state-CWCzCOz6.js.map → client-state-DGbupmmR.js.map} +1 -1
  144. package/public/assets/{diff-viewer-CGPsYEr3.js → diff-viewer-CSOlh3i1.js} +2 -2
  145. package/public/assets/{diff-viewer-CGPsYEr3.js.map → diff-viewer-CSOlh3i1.js.map} +1 -1
  146. package/public/assets/index-B0BLbbT3.js +2 -0
  147. package/public/assets/{index-BxRFHpJd.js.map → index-B0BLbbT3.js.map} +1 -1
  148. package/public/assets/index-B52s_Dh2.js +2 -0
  149. package/public/assets/index-B52s_Dh2.js.map +1 -0
  150. package/public/assets/index-B8W9is7z.js +2 -0
  151. package/public/assets/index-B8W9is7z.js.map +1 -0
  152. package/public/assets/index-Bn8a8ymh.js +2 -0
  153. package/public/assets/index-Bn8a8ymh.js.map +1 -0
  154. package/public/assets/index-CWaDoBhJ.js +2 -0
  155. package/public/assets/index-CWaDoBhJ.js.map +1 -0
  156. package/public/assets/{index-MeFffHqb.css → index-CXEtEGDL.css} +1 -1
  157. package/public/assets/index-CbuT2QEY.js +2 -0
  158. package/public/assets/index-CbuT2QEY.js.map +1 -0
  159. package/public/assets/{index-Ddjkirek.js → index-Cq5Hfa6i.js} +2 -2
  160. package/public/assets/{index-Ddjkirek.js.map → index-Cq5Hfa6i.js.map} +1 -1
  161. package/public/assets/index-D03eJbIp.js +2 -0
  162. package/public/assets/index-D03eJbIp.js.map +1 -0
  163. package/public/assets/index-DDK0Fk7j.js +2 -0
  164. package/public/assets/index-DDK0Fk7j.js.map +1 -0
  165. package/public/assets/index-DftCJdT3.js +2 -0
  166. package/public/assets/index-DftCJdT3.js.map +1 -0
  167. package/public/assets/index-_N9V2vB3.js +3 -0
  168. package/public/assets/index-_N9V2vB3.js.map +1 -0
  169. package/public/assets/index-zo6cKyNQ.js +2 -0
  170. package/public/assets/index-zo6cKyNQ.js.map +1 -0
  171. package/public/assets/{loading-Gqh6NPUr.js → loading-B2-6L7aO.js} +2 -2
  172. package/public/assets/{loading-Gqh6NPUr.js.map → loading-B2-6L7aO.js.map} +1 -1
  173. package/public/assets/main-pZWMgVoG.js +42 -0
  174. package/public/assets/main-pZWMgVoG.js.map +1 -0
  175. package/public/assets/{markdown-BWnjyvnX.js → markdown-CH9bocix.js} +4 -4
  176. package/public/assets/{markdown-BWnjyvnX.js.map → markdown-CH9bocix.js.map} +1 -1
  177. package/public/assets/monaco-viewer-Bv1s0h2m.js +27 -0
  178. package/public/assets/monaco-viewer-Bv1s0h2m.js.map +1 -0
  179. package/public/assets/{startup-state-settings-card-C4E2Itop.js → startup-state-settings-card-mmovljyz.js} +2 -2
  180. package/public/assets/{startup-state-settings-card-C4E2Itop.js.map → startup-state-settings-card-mmovljyz.js.map} +1 -1
  181. package/public/assets/{terminal-square-C3wutdV0.js → terminal-square-U8R46SS0.js} +2 -2
  182. package/public/assets/{terminal-square-C3wutdV0.js.map → terminal-square-U8R46SS0.js.map} +1 -1
  183. package/public/assets/tool-call-AnfwOPww.js +60 -0
  184. package/public/assets/tool-call-AnfwOPww.js.map +1 -0
  185. package/public/assets/unified-picker-DtvQUEiv.js +2 -0
  186. package/public/assets/unified-picker-DtvQUEiv.js.map +1 -0
  187. package/public/assets/{wrap-text-CkBxzt04.js → wrap-text-Bh1AU9Re.js} +2 -2
  188. package/public/assets/{wrap-text-CkBxzt04.js.map → wrap-text-Bh1AU9Re.js.map} +1 -1
  189. package/public/index.html +4 -4
  190. package/public/loading.html +4 -4
  191. package/public/sw.js +1 -1
  192. package/public/sw.js.map +1 -1
  193. package/public/assets/App-BROhwPo9.js +0 -54
  194. package/public/assets/App-BROhwPo9.js.map +0 -1
  195. package/public/assets/index-B8-lAqjr.js +0 -2
  196. package/public/assets/index-B8-lAqjr.js.map +0 -1
  197. package/public/assets/index-BeUewQym.js +0 -2
  198. package/public/assets/index-BeUewQym.js.map +0 -1
  199. package/public/assets/index-BxRFHpJd.js +0 -2
  200. package/public/assets/index-Bzv1kU-S.js +0 -2
  201. package/public/assets/index-Bzv1kU-S.js.map +0 -1
  202. package/public/assets/index-C9tI4CRG.js +0 -2
  203. package/public/assets/index-C9tI4CRG.js.map +0 -1
  204. package/public/assets/index-CGYHFZ6F.js +0 -2
  205. package/public/assets/index-CGYHFZ6F.js.map +0 -1
  206. package/public/assets/index-CMEAjBFp.js +0 -2
  207. package/public/assets/index-CMEAjBFp.js.map +0 -1
  208. package/public/assets/index-Cazypvyc.js +0 -2
  209. package/public/assets/index-Cazypvyc.js.map +0 -1
  210. package/public/assets/index-CwqzofWP.js +0 -2
  211. package/public/assets/index-CwqzofWP.js.map +0 -1
  212. package/public/assets/index-Da9yOa6q.js +0 -2
  213. package/public/assets/index-Da9yOa6q.js.map +0 -1
  214. package/public/assets/index-HHgvEOAH.js +0 -3
  215. package/public/assets/index-HHgvEOAH.js.map +0 -1
  216. package/public/assets/main-Cbx7KdTr.js +0 -38
  217. package/public/assets/main-Cbx7KdTr.js.map +0 -1
  218. package/public/assets/monaco-viewer-BEJIiZWL.js +0 -27
  219. package/public/assets/monaco-viewer-BEJIiZWL.js.map +0 -1
  220. package/public/assets/tool-call-DNsAQ_m4.js +0 -60
  221. package/public/assets/tool-call-DNsAQ_m4.js.map +0 -1
  222. package/public/assets/unified-picker-tB7y17Qz.js +0 -2
  223. package/public/assets/unified-picker-tB7y17Qz.js.map +0 -1
@@ -1,2 +1,2 @@
1
- import{e as ct}from"./git-diff-vendor-ChbWBukG.js";import{a as mt,b as lt,m as Ie,i as $t}from"./index-HHgvEOAH.js";import{h as _e}from"./monaco-viewer-BEJIiZWL.js";const be=["codenomad-client-snapshot-v1","codenomad-client-restore-enabled-v1"],ht={isPrimary:!1,restoreEnabled:!1,snapshot:null},Pe=_e("actions"),K=(()=>{const t=new Uint8Array(32);return globalThis.crypto.getRandomValues(t),Array.from(t,e=>e.toString(16).padStart(2,"0")).join("")})();let F=!1;const Ht=()=>window.electronAPI;function ft(t,e,n={}){if(mt())return t(Ht());if(lt())return $t(e,{accessToken:K,...n})}async function Oe(){if(!Ie())return!1;try{const t=await ft(e=>{var n;return(n=e==null?void 0:e.claimClientStateAccess)==null?void 0:n.call(e,K)},"client_state_claim_access");F=lt()||t===!0}catch(t){F=!1,Pe.warn("Client state native access claim failed",t)}return F}async function Ee(){if(mt()||lt()){if(!await Oe())return ht;const t=await ft(n=>{var r;return(r=n==null?void 0:n.loadClientState)==null?void 0:r.call(n,K)},"client_state_load")??ht;if(!mt())return t;const e=Ht();return{...t,partitionProtocolVersion:t.partitionProtocolVersion===1&&typeof(e==null?void 0:e.commitClientStatePartitions)=="function"&&typeof e.loadClientStatePartition=="function"?1:void 0}}try{for(const t of be)window.localStorage.removeItem(t)}catch{}return ht}async function dt(t,e,n={}){return F?await ft(r=>r&&t(r),e,n)??!1:!1}const ve=t=>dt(e=>{var n;return(n=e.saveClientState)==null?void 0:n.call(e,K,t)},"client_state_save",{snapshot:t}),Te=t=>dt(e=>{var n;return(n=e.commitClientStatePartitions)==null?void 0:n.call(e,K,t)},"client_state_commit_partitions",{payload:t}),Ne=async t=>F?await ft(e=>{var n;return(n=e==null?void 0:e.loadClientStatePartition)==null?void 0:n.call(e,K,t)},"client_state_load_partition",{key:t})??null:null,zt=t=>dt(e=>{var n;return(n=e.setClientStateRestoreEnabled)==null?void 0:n.call(e,K,t)},"client_state_set_restore_enabled",{enabled:t}),je=()=>dt(t=>{var e;return(e=t.clearClientState)==null?void 0:e.call(t,K)},"client_state_clear");function Gt(t,e={}){return!lt()||!F?Promise.resolve():$t(t,{accessToken:K,...e})}const Mn=t=>Gt("client_state_navigation_flushed",{generation:t}),xn=t=>Gt("client_state_renderer_flushed",{generation:t}),Wt=512,St=1024,wt=4096,Jt=256,H=t=>typeof t=="object"&&t!==null&&!Array.isArray(t),Ce=t=>t!=="__proto__"&&t!=="constructor"&&t!=="prototype";function x(t,e,n=!1){if(!(typeof t!="string"||t.length>e)&&!(!n&&t.trim().length===0))return t}function Zt(t){let e="";for(let n=0;n<t.length;n+=32768)e+=String.fromCharCode(...t.subarray(n,n+32768));return btoa(e)}const qt=t=>Uint8Array.from(atob(t),e=>e.charCodeAt(0));function Re(t){if(typeof t!="string"||t.length%4!==0||!/^[A-Za-z0-9+/]*={0,2}$/.test(t))return!1;try{return qt(t),!0}catch{return!1}}const Qt=t=>{var e;return typeof t=="string"?(e=t.match(/^data:[^;,]+;base64,([A-Za-z0-9+/]*={0,2})$/))==null?void 0:e[1]:void 0};function Me(t,e){const n=Qt(e)??t,r=n instanceof Uint8Array?Zt(n):n;return Re(r)?r:void 0}function Xt(t){if(!(!H(t)||!Number.isSafeInteger(t.line)||Number(t.line)<0)&&!(!Number.isSafeInteger(t.char)||Number(t.char)<0))return{line:Number(t.line),char:Number(t.char)}}function xe(t,e){if(!H(t))return;if(t.type==="text")return typeof t.value=="string"?{type:"text",value:t.value}:void 0;if(t.type==="agent"){const o=x(t.name,St);return o===void 0?void 0:{type:"agent",name:o}}const n=x(t.path,wt);if(t.type==="file"){const o=x(t.mime,Jt);if(n===void 0||o===void 0)return;const l=Qt(e)??t.data,h=Me(t.data,e);return l!==void 0&&h===void 0?void 0:h===void 0?{type:"file",path:n,mime:o}:{type:"file",path:n,mime:o,data:h}}if(t.type!=="symbol"||!H(t.range))return;const r=x(t.name,St),i=Xt(t.range.start),s=Xt(t.range.end);if(!(n===void 0||r===void 0||!Number.isSafeInteger(t.kind)||!i||!s))return{type:"symbol",path:n,name:r,kind:Number(t.kind),range:{start:i,end:s}}}function Ke(t){if(!H(t)||!["file","text","symbol","agent"].includes(String(t.type)))return;const e=x(t.id,Wt),n=x(t.display,St),r=x(t.filename,wt),i=x(t.mediaType,Jt),s=xe(t.source,t.url),o=typeof t.url=="string"&&!t.url.startsWith("data:")?t.url:"",l=x(o,wt,!0);if(!(!e||!n||!r||!i||!s||s.type!==t.type||l===void 0))return{id:e,type:t.type,display:n,url:l,filename:r,mediaType:i,source:s}}function jt(t,e,n=[]){if(!H(t))return null;const r=Object.create(null),i=[...new Set(n)],s=new Set(i),o=[...i.flatMap(l=>Object.prototype.hasOwnProperty.call(t,l)?[[l,t[l]]]:[]),...Object.entries(t).filter(([l])=>!s.has(l))];for(const[l,h]of o){if(!Ce(l)||!l||l.length>Wt||!Array.isArray(h))continue;const w=[];for(const S of h){const u=Ke(S);u&&w.push(u)}w.length&&(r[l]=w)}return{attachments:r,drafts:{...e}}}function Kn(t,e,n=[]){const r=jt(e,t,n);if(!r||Object.entries(e).some(([i,s])=>{var o;return s.length!==(((o=r.attachments[i])==null?void 0:o.length)??0)}))throw new Error("Draft attachments could not be persisted safely");return r}function Ln(t){let e,n=t.url;if(t.source.type==="file")try{const r=t.source.data===void 0?void 0:qt(t.source.data);e={type:"file",path:t.source.path,mime:t.source.mime,data:r},!n&&t.source.data&&(n=`data:${t.source.mime};base64,${t.source.data}`)}catch{return null}else e=t.source,t.source.type==="text"&&!n&&(n=`data:text/plain;base64,${Zt(new TextEncoder().encode(t.source.value))}`);return{...t,url:n,source:e}}const te=32,Le=64,ke=24,ze=96,Xe=256,Be=256,De=256,ee=256,At=4096,tt=512,Ve=4096,ne=32*1024,Ye=1024,Ue=96*1024,Fe=256,Bt=1024,$e="__no_session_draft__";function re(){return{remaining:Ue,scrollSnapshotsRemaining:Fe}}const k=t=>typeof t=="object"&&t!==null&&!Array.isArray(t),oe=t=>t!=="__proto__"&&t!=="constructor"&&t!=="prototype";function N(t,e,n,r=!1){if(!(typeof t!="string"||t.length>e||t.length>n.remaining)&&!(!r&&t.trim().length===0))return n.remaining-=t.length,t}const X=(t,e,n)=>typeof t=="number"&&Number.isFinite(t)&&t>=e&&t<=n?t:void 0;function et(t,e,n,r,i=()=>!0,s=()=>{},o=[]){if(!k(t))return null;const l=Object.create(null);let h=0;const w=[...new Set(o)],S=new Set(w),u=[...w.flatMap(p=>Object.prototype.hasOwnProperty.call(t,p)?[[p,t[p]]]:[]),...Object.entries(t).filter(([p])=>!S.has(p))];for(const[p,j]of u){if(h>=e)break;if(!oe(p)||!i(j))continue;const b=N(p,ee,n),f=r(j);b===void 0||f===void 0||(l[b]=f,h+=1,s())}return l}function ie(t,e,n,r,i=[]){return et(t,e,r,s=>N(s,n,r,!0),void 0,void 0,i)}function He(t,e){if(!k(t))return;const n=X(t.scrollTop,0,1e9),r=X(t.updatedAt,0,Number.MAX_SAFE_INTEGER);if(n===void 0||r===void 0||typeof t.atBottom!="boolean")return;const i={scrollTop:n,atBottom:t.atBottom,updatedAt:r},s=X(t.scrollRatio,0,1),o=X(t.maxScrollTop,0,1e9),l=X(t.anchorOffset,-1e6,1e6),h=t.anchorKey===void 0?void 0:N(t.anchorKey,Ye,e);s!==void 0&&(i.scrollRatio=s),o!==void 0&&(i.maxScrollTop=o),h!==void 0&&(i.anchorKey=h),l!==void 0&&(i.anchorOffset=l),(t.followModeType==="following"||t.followModeType==="escaped")&&(i.followModeType=t.followModeType),typeof t.windowIsLatest=="boolean"&&(i.windowIsLatest=t.windowIsLatest);const w=t.windowCursor===void 0?void 0:N(t.windowCursor,Bt,e);if(w!==void 0&&(i.windowCursor=w),Array.isArray(t.newerCursors)){const S=[];for(const u of t.newerCursors.slice(-32)){if(u===null||u===""){S.push(null);continue}const p=N(u,Bt,e);p!==void 0&&S.push(p)}S.length>0&&(i.newerCursors=S)}return i}function Ge(t,e){if(!Array.isArray(t))return null;const n=[],r=new Set;for(const i of t.slice(0,De)){if(typeof i!="string"||r.has(i))continue;const s=N(i,tt,e);s!==void 0&&(r.add(s),n.push(s))}return n}function We(t,e,n,r){const i=e.priorityDrafts,s=Object.fromEntries(Object.entries(t.drafts??{}).filter(([a])=>!Object.prototype.hasOwnProperty.call(i,a))),o=ie(s,Math.max(0,ke-Object.keys(i).length),ne,n),l=o?{...i,...o}:null,h=Math.min(ze,n.scrollSnapshotsRemaining),w=et(t.scrollSnapshots??{},h,n,a=>He(a,n),void 0,()=>{n.scrollSnapshotsRemaining-=1}),S=et(t.unseenIdleSince??{},Xe,n,a=>X(a,0,Number.MAX_SAFE_INTEGER)),u=et(t.generationRecovery??{},Be,n,a=>a,a=>a==="working"||a==="interrupted"),p=t.expandedSessionIds===void 0?void 0:Ge(t.expandedSessionIds,n);if(!l||!w||!S||!u||p===null)return null;const j=Object.fromEntries(Object.entries(t.attachments??{}).filter(([a])=>!e.prioritySessionIds.includes(a))),b=jt(j,l);if(!b)return null;const f={kind:"workspace",folder:e.folder,drafts:b.drafts,attachments:{...e.priorityAttachments,...b.attachments},scrollSnapshots:w,unseenIdleSince:S,generationRecovery:u};p!==void 0&&(f.expandedSessionIds=p),Number.isInteger(t.occurrence)&&Number(t.occurrence)>=0&&Number(t.occurrence)<te&&(f.occurrence=Number(t.occurrence));const y=t.projectName===void 0?void 0:N(t.projectName,At,n),c=t.binaryPath===void 0?void 0:N(t.binaryPath,At,n);return y!==void 0&&(f.projectName=y),c!==void 0&&(f.binaryPath=c),e.activeParentSessionId!==void 0&&(f.activeParentSessionId=e.activeParentSessionId),e.activeSessionId!==void 0&&(f.activeSessionId=e.activeSessionId),f}function Je(t,e){if(!k(t))return null;const n=t.kind??t.type;if(n==="sidecar"){const l=N(t.sidecarId,tt,e);return l===void 0?null:{kind:n,sidecarId:l}}if(n!=="workspace"&&n!=="instance"||!["drafts","attachments","scrollSnapshots","unseenIdleSince","generationRecovery"].every(l=>k(t[l]??{})))return null;const r=N(t.folder,At,e);if(r===void 0)return null;const i=t.activeParentSessionId===void 0?void 0:N(t.activeParentSessionId,tt,e),s=t.activeSessionId===void 0?void 0:N(t.activeSessionId,tt,e),o=[s,$e].filter(l=>!!l);return{kind:"workspace",value:t,folder:r,activeParentSessionId:i,activeSessionId:s,prioritySessionIds:o,priorityDrafts:Object.create(null),priorityAttachments:Object.create(null)}}function Ze(t,e){const n=t.value.drafts??{};if(!k(n))return;for(const o of t.prioritySessionIds){if(!oe(o)||!Object.prototype.hasOwnProperty.call(n,o))continue;const l=e.remaining,h=N(o,ee,e),w=N(n[o],ne,e,!0);if(h===void 0||w===void 0){e.remaining=l;continue}t.priorityDrafts[h]=w}const r=t.value.attachments??{};if(!k(r))return;const i=Object.fromEntries(t.prioritySessionIds.filter(o=>Object.prototype.hasOwnProperty.call(r,o)).map(o=>[o,r[o]])),s=jt(i,t.priorityDrafts,t.prioritySessionIds);s&&(t.priorityDrafts=s.drafts,t.priorityAttachments=s.attachments)}function gt(t){return se(t,re())}function se(t,e){if(!k(t)||!Array.isArray(t.tabs)||!Number.isInteger(t.activeTabIndex))return null;const n=Number(t.activeTabIndex),r=t.tabs.slice(0,te),i=new Map,s=new Map,o=f=>{const y=Je(r[f],e);y&&i.set(f,y)},l=(f,y)=>{const c=i.get(f);if(!c)return;const a=c.kind==="sidecar"?c:We(c.value,c,e);a&&s.set(f,a)};r.forEach((f,y)=>o(y));const h=[n,...r.map((f,y)=>y).filter(f=>f!==n)];for(const f of h){const y=i.get(f);(y==null?void 0:y.kind)==="workspace"&&Ze(y,e)}r[n]!==void 0&&l(n),r.forEach((f,y)=>{y!==n&&l(y)});const S=r.flatMap((f,y)=>{const c=i.get(y);return c?[{originalIndex:y,identity:c}]:[]}).flatMap(({originalIndex:f})=>{const y=s.get(f);return y?[{originalIndex:f,tab:y}]:[]});if(t.tabs.length&&!S.length)return null;const u=S.map(({tab:f})=>f),p=S.findIndex(({originalIndex:f})=>f===n),j=S.findIndex(({originalIndex:f})=>f>n),b=u.length?p>=0?p:j>=0?j:u.length-1:-1;return{tabs:u,activeTabIndex:b,...t.homeActive===!0?{homeActive:!0}:{}}}function Ct(t){if(!k(t)||t.version!==void 0&&t.version!==1||!Number.isSafeInteger(t.revision)||Number(t.revision)<0)return null;const e=X(t.savedAt,0,Number.MAX_SAFE_INTEGER);if(e===void 0)return null;const n=re(),r=t.session===null?null:se(t.session,n);if(t.session!==null&&!r)return null;const i=ie(t.layout,Le,Ve,n);return i?{version:1,revision:Number(t.revision),savedAt:e,layout:i,session:r}:null}const G=1024*1024,It=1024*1024,qe=4096,Dt=256*1024*1024,Qe=512,_t=768*1024,ae=256,ce=_t*ae,B=/^[0-9a-f]{64}$/,tn=["layout","partitionKeys","revision","savedAt","sessionPartition","version"],en=new Set(["__proto__","constructor","prototype"]),z=new TextEncoder,C=t=>typeof t=="object"&&t!==null&&!Array.isArray(t),I=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),q=t=>typeof t=="string"&&t.length>0&&t.length<=Qe&&t.trim().length>0&&!en.has(t);function le(t){return Array.isArray(t)&&t.every((e,n)=>typeof e=="string"&&B.test(e)&&(n===0||t[n-1]<e))}function M(t,e,n=[]){const r=new Set([...e,...n]);return e.every(i=>I(t,i))&&Object.keys(t).every(i=>r.has(i))}function bt(t){return Array.isArray(t)?t.map(bt):C(t)?Object.fromEntries(Object.keys(t).sort().map(e=>[e,bt(t[e])])):t}function W(t){const e=JSON.stringify(bt(t));if(e===void 0)throw new TypeError("Client state partition must be JSON-serializable");return e}function Pt(t,e){try{return W(t)===W(e)}catch{return!1}}async function Rt(t){const e=await crypto.subtle.digest("SHA-256",z.encode(t));return Array.from(new Uint8Array(e),n=>n.toString(16).padStart(2,"0")).join("")}function nn(t){let e="";for(let n=0;n<t.length;n+=32768)e+=String.fromCharCode(...t.subarray(n,n+32768));return btoa(e)}const rn=t=>Uint8Array.from(atob(t),e=>e.charCodeAt(0)),Ot=t=>typeof t=="string"&&t.length%4===0&&/^[A-Za-z0-9+/]*={0,2}$/.test(t);async function Vt(t,e){if(!Ot(t)||t.length>ce)throw new Error("Client state attachment exceeds the 192 MiB encoded blob limit");const n=[];for(let r=0,i=0;r<t.length||r===0;r+=_t,i+=1)n.push(await e({format:2,index:i,data:t.slice(r,r+_t)}));return n}async function on(t,e){return Promise.all(t.map(async n=>{let r;return n.source.type==="file"?(r={type:"file",path:n.source.path,mime:n.source.mime},n.source.data!==void 0&&(r.dataPartitions=await Vt(n.source.data,e))):n.source.type==="text"?r={type:"text",valuePartitions:await Vt(nn(z.encode(n.source.value)),e)}:r=n.source,{...n,source:r}}))}async function Et(t){const e=Object.create(null),n=async o=>{const l=W(o);if(z.encode(l).byteLength>G)throw new Error("Client state partition exceeds the native size limit");const h=await Rt(l);return e[h]=l,h},r=t===null?null:{tabs:await Promise.all(t.tabs.map(async o=>{if(o.kind==="sidecar")return{kind:o.kind,sidecarId:o.sidecarId};const l=new Set([...Object.keys(o.drafts),...Object.keys(o.attachments),...Object.keys(o.scrollSnapshots),...Object.keys(o.unseenIdleSince),...Object.keys(o.generationRecovery)]),h=Object.create(null);for(const u of[...l].sort()){const p={format:2};I(o.drafts,u)&&(p.draft=o.drafts[u]),I(o.attachments,u)&&(p.attachments=await on(o.attachments[u],n)),I(o.scrollSnapshots,u)&&(p.scrollSnapshot=o.scrollSnapshots[u]),I(o.unseenIdleSince,u)&&(p.unseenIdleSince=o.unseenIdleSince[u]),I(o.generationRecovery,u)&&(p.generationRecovery=o.generationRecovery[u]);const j=await n(p),b=(p.attachments??[]).flatMap(f=>{if(!C(f)||!C(f.source))return[];const y=f.source.dataPartitions??f.source.valuePartitions;return Array.isArray(y)?y.filter(c=>typeof c=="string"):[]});h[u]={documentPartition:j,partitionKeys:[...new Set([j,...b])].sort()}}const w={format:2,sessions:h};o.activeParentSessionId!==void 0&&(w.activeParentSessionId=o.activeParentSessionId),o.activeSessionId!==void 0&&(w.activeSessionId=o.activeSessionId),o.expandedSessionIds!==void 0&&(w.expandedSessionIds=o.expandedSessionIds);const S={kind:o.kind,folder:o.folder,workspacePartition:await n(w)};return o.occurrence!==void 0&&(S.occurrence=o.occurrence),o.projectName!==void 0&&(S.projectName=o.projectName),o.binaryPath!==void 0&&(S.binaryPath=o.binaryPath),S})),activeTabIndex:t.activeTabIndex,...t.homeActive!==void 0?{homeActive:t.homeActive}:{}},i=await n({format:2,session:r}),s=Object.keys(e).sort();return{sessionPartition:i,partitionKeys:s,partitions:Object.fromEntries(s.map(o=>[o,e[o]]))}}async function sn(t){const e=await Et(t.session);return{root:{version:2,revision:t.revision,savedAt:t.savedAt,layout:t.layout,sessionPartition:e.sessionPartition,partitionKeys:e.partitionKeys},partitions:e.partitions,partitionKeys:e.partitionKeys}}function an(t){if(t.partitionKeys.length>qe)return!1;const e=JSON.stringify(t.root);if(e.length>It)return!1;let n=z.encode(e).byteLength;if(n>It)return!1;for(const r in t.partitions){if(!I(t.partitions,r))continue;const i=t.partitions[r];if(i.length>G||i.length>Dt-n)return!1;const s=z.encode(i).byteLength;if(s>G||s>Dt-n)return!1;n+=s}return!0}function cn(t){if(!C(t)||t.version!==2||typeof t.sessionPartition!="string"||!B.test(t.sessionPartition)||!le(t.partitionKeys)||!t.partitionKeys.includes(t.sessionPartition)||Object.keys(t).sort().join("\0")!==tn.join("\0"))return null;let e;try{e=JSON.stringify(t)}catch{return null}if(z.encode(e).byteLength>It)return null;const n=Ct({...t,version:1,session:null});return!n||!Pt(t,{version:2,revision:n.revision,savedAt:n.savedAt,layout:n.layout,sessionPartition:t.sessionPartition,partitionKeys:t.partitionKeys})?null:{root:n,partitionKey:t.sessionPartition,partitionKeys:t.partitionKeys}}function fe(t){try{return{value:JSON.parse(t)}}catch{return null}}async function ln(t,e,n,r,i){var y;if(!M(t,["format","session"])||W(t)!==r.get(e))return;if(t.session===null){const c=await Et(null);return Yt(c,e,n,r)?null:void 0}if(!C(t.session)||!M(t.session,["tabs","activeTabIndex"],["homeActive"])||!Array.isArray(t.session.tabs))return;const s=async c=>{if(typeof c!="string"||!B.test(c))return null;let a=r.get(c);if(a===void 0){if(a=await i(c)??void 0,a===void 0||z.encode(a).byteLength>G||await Rt(a)!==c)return null;r.set(c,a)}const A=fe(a);return A&&C(A.value)&&W(A.value)===a?A.value:null},o=(c,a)=>{const A=[...new Set(c)].sort();return A.length===a.length&&A.every((v,P)=>v===a[P])},l=async(c,a,A)=>{if(!Array.isArray(c)||!c.length||c.length>ae||!c.every(d=>typeof d=="string"&&B.test(d))||new Set(c).size!==c.length)return null;const v=[];let P=0;for(const[d,m]of c.entries()){if(!a.has(m))return null;A.add(m);const T=await s(m);if(!T||!Ot(T.data))return null;if(T.format===1){if(!M(T,["format","data"]))return null}else if(T.format===2){if(!M(T,["format","index","data"])||T.index!==d)return null}else return null;if(T.data.length>ce-P)return null;P+=T.data.length,v.push(T.data)}const g=v.join("");return Ot(g)?g:null},h=async(c,a,A)=>{if(!Array.isArray(c))return null;const v=[];for(const P of c){if(!C(P)||!M(P,["id","type","display","url","filename","mediaType","source"])||!C(P.source))return null;const g=P.source;if(g.type==="file"){if(!M(g,["type","path","mime"],["dataPartitions"]))return null;if(I(g,"dataPartitions")){const d=await l(g.dataPartitions,a,A);if(d===null)return null;v.push({...P,source:{type:g.type,path:g.path,mime:g.mime,data:d}})}else v.push(P);continue}if(g.type==="text"){if(!M(g,["type","valuePartitions"]))return null;const d=await l(g.valuePartitions,a,A);if(d===null)return null;try{const m=new TextDecoder("utf-8",{fatal:!0}).decode(rn(d));v.push({...P,source:{type:g.type,value:m}})}catch{return null}continue}v.push(P)}return v},w=[],S=new Set([e]);let u=!1,p=!1;for(const c of t.session.tabs){if(!C(c))return;if(c.kind==="sidecar"){if(!M(c,["kind","sidecarId"]))return;w.push({kind:c.kind,sidecarId:c.sidecarId});continue}if(c.kind!=="workspace"||!M(c,["kind","folder","workspacePartition"],["occurrence","projectName","binaryPath"])||typeof c.workspacePartition!="string"||!B.test(c.workspacePartition))return;S.add(c.workspacePartition);const a=await s(c.workspacePartition);if(!a||a.format!==1&&a.format!==2||!M(a,["format","sessions"],["activeParentSessionId","activeSessionId","expandedSessionIds"])||!C(a.sessions)||(p||(p=a.format===1),!Object.keys(a.sessions).every(q)||I(a,"activeParentSessionId")&&!q(a.activeParentSessionId)||I(a,"activeSessionId")&&!q(a.activeSessionId)||I(a,"expandedSessionIds")&&(!Array.isArray(a.expandedSessionIds)||!a.expandedSessionIds.every(q))))return;const A={kind:c.kind,folder:c.folder,drafts:Object.create(null),attachments:Object.create(null),scrollSnapshots:Object.create(null),unseenIdleSince:Object.create(null),generationRecovery:Object.create(null)};for(const d of["occurrence","projectName","binaryPath"])I(c,d)&&(A[d]=c[d]);for(const d of["activeParentSessionId","activeSessionId","expandedSessionIds"])I(a,d)&&(A[d]=a[d]);const v=[];for(const[d,m]of Object.entries(a.sessions)){if(a.format===1){if(typeof m!="string"||!B.test(m))return;v.push({sessionId:d,documentKey:m,partitionKeys:[m]}),S.add(m);continue}if(!C(m)||!M(m,["documentPartition","partitionKeys"])||typeof m.documentPartition!="string"||!B.test(m.documentPartition)||!le(m.partitionKeys)||!m.partitionKeys.includes(m.documentPartition))return;v.push({sessionId:d,documentKey:m.documentPartition,partitionKeys:m.partitionKeys}),m.partitionKeys.forEach(T=>S.add(T))}const P=typeof a.activeSessionId=="string"?a.activeSessionId:void 0;v.sort((d,m)=>d.sessionId===P?-1:m.sessionId===P?1:d.sessionId.localeCompare(m.sessionId));const g=new Set;for(const{sessionId:d,documentKey:m,partitionKeys:T}of v){const R=await s(m),Ae=new Set(T),Kt=new Set([m]);if(!(R&&(R.format===1||R.format===2)&&M(R,["format"],["draft","attachments","scrollSnapshot","unseenIdleSince","generationRecovery"])&&Object.keys(R).length>1)){u=!0,g.add(d);continue}const pt=I(R,"attachments")?R.format===1?R.attachments:await h(R.attachments,Ae,Kt):void 0;if(I(R,"attachments")&&pt===null||!o(Kt,T)){u=!0,g.add(d);continue}const L={kind:"workspace",folder:"/",drafts:Object.create(null),attachments:Object.create(null),scrollSnapshots:Object.create(null),unseenIdleSince:Object.create(null),generationRecovery:Object.create(null)},Lt=[["draft","drafts"],["scrollSnapshot","scrollSnapshots"],["unseenIdleSince","unseenIdleSince"],["generationRecovery","generationRecovery"]];for(const[Y,ge]of Lt)I(R,Y)&&(L[ge][d]=R[Y]);pt!==void 0&&(L.attachments[d]=pt);const kt=(y=gt({tabs:[L],activeTabIndex:0}))==null?void 0:y.tabs[0];if(!kt||!Pt(L,kt)){u=!0,g.add(d);continue}for(const[,Y]of Lt)I(L[Y],d)&&(A[Y][d]=L[Y][d]);I(L.attachments,d)&&(A.attachments[d]=L.attachments[d])}g.has(String(A.activeSessionId))&&delete A.activeSessionId,g.has(String(A.activeParentSessionId))&&delete A.activeParentSessionId,Array.isArray(A.expandedSessionIds)&&(A.expandedSessionIds=A.expandedSessionIds.filter(d=>!g.has(String(d)))),w.push(A)}if(!o(S,n))return;const j={tabs:w,activeTabIndex:t.session.activeTabIndex,...I(t.session,"homeActive")?{homeActive:t.session.homeActive}:{}},b=gt(j);if(!b||!Pt(j,b))return;if(u||p)return b;const f=await Et(b);return Yt(f,e,n,r)?b:void 0}function Yt(t,e,n,r){return t.sessionPartition!==e||t.partitionKeys.length!==n.length||!t.partitionKeys.every((i,s)=>i===n[s])||t.partitionKeys.length!==r.size?!1:t.partitionKeys.every(i=>r.get(i)===t.partitions[i])}async function fn(t,e,n){const r=cn(t);if(!r||e!==1)return null;try{const i=await n(r.partitionKey);if(i===null||z.encode(i).byteLength>G||await Rt(i)!==r.partitionKey)return null;const s=fe(i);if(!s)return null;if(C(s.value)&&s.value.format===2){const o=new Map([[r.partitionKey,i]]),l=await ln(s.value,r.partitionKey,r.partitionKeys,o,n);return l===void 0?null:{...r.root,session:l}}return null}catch{return null}}const dn=t=>C(t)&&t.version===2,un=250,yn=3,pn=1024*1024,hn=64,mn=256,Mt=4096,Sn="opencode-session-",wn=new Set(["__proto__","constructor","prototype"]),[V,it]=ct(!0),[$,nt]=ct(!1),[An,gn]=ct(!1),[de,vt]=ct(null);let Tt=!1,Q=null,E=Object.create(null),ue=0,O=!1,_=!1,rt=null,D=Promise.resolve(),Ut=Promise.resolve(),J,ye;const U=new Set;function ut(t,e){try{return e(window.localStorage)}catch{return t}}function pe(t){return t.length>0&&t.length<=mn&&!wn.has(t)}const Ft=t=>ut(null,e=>{const n=e.getItem(t);return n!==null&&n.length<=Mt?n:null}),Nt=(t,e)=>ut(void 0,n=>n.setItem(t,e));function he(t){const e=new Set(Object.keys(E));for(let n=0;n<t.length;n+=1){const r=t.key(n);r!=null&&r.startsWith(Sn)&&e.add(r)}return[...e]}const st=t=>Object.prototype.hasOwnProperty.call(E,t),at=()=>Object.keys(E).length>=hn;function In(){return ut(!1,t=>{const e=Object.keys(E).length;for(const n of he(t)){if(st(n))continue;if(at())break;const r=t.getItem(n);r===null||r.length>Mt||(E[n]=r)}return Object.keys(E).length!==e})}function xt(){return Tt&&V()&&$()&&!_}const yt=()=>{rt!==null&&clearTimeout(rt),rt=null};function me(){if(yt(),!O||!xt())return D;const t={version:1,revision:++ue,savedAt:Date.now(),layout:{...E},session:de()},e=Ct(t);if(!e)return Promise.reject(new Error("Client snapshot normalization failed"));E={...e.layout},O=!1;const n=D.then(async()=>{try{const r=ye===1?await sn(e):null;if(r&&!an(r))throw new Error("Client snapshot exceeds the native partition count or size limits");if(!r&&new TextEncoder().encode(JSON.stringify(e)).byteLength>pn)throw new Error("Client snapshot exceeds the V1 1 MiB limit and partition persistence is unavailable");if(!(r?await Te({protocolVersion:1,snapshot:r.root,partitions:r.partitions,partitionKeys:r.partitionKeys}):await ve(e)))throw it(!1),new Error("Native client state save was rejected");J=void 0}catch(r){throw O=!0,J=r,r}});return D=n.catch(()=>{}),n}function Z(){O=!0,xt()&&(yt(),rt=setTimeout(()=>void me().catch(t=>console.warn("[client-state] failed to save client snapshot",t)),un))}function ot(t=null,e=!1){E=t?{...t.layout}:Object.create(null),e&&(ue=(t==null?void 0:t.revision)??0),gn(t!==null),vt((t==null?void 0:t.session)??null)}async function Se(t,e,n=!1){const r=_;let i=O;_="transaction",U.clear(),yt(),O=!1;try{if(await D,i||(i=O),O=!1,!await t())throw n&&it(!1),new Error(e);ut(void 0,s=>{for(const o of he(s))s.removeItem(o)}),ot(),U.clear(),_="snapshot"}catch(s){i||(i=O);for(const o of U)Nt(o,E[o]);throw U.clear(),_=r,O=i,O&&Z(),s}}function we(t){const e=Ut.then(t);return Ut=e.catch(()=>{}),e}function _n(t){const e=t===null?null:gt(t);if(!(t!==null&&e===null)){if(_==="transaction"){vt(e),O=!0;return}_||!V()||!$()||(vt(e),Z())}}function bn(t){if(!pe(t))return null;if(!V())return Ft(t);if(!$()||_)return null;if(st(t))return E[t]??null;const e=Ft(t);return e===null||at()||(E[t]=e,Z()),e}function Pn(t,e){if(!(!pe(t)||e.length>Mt)){if(!V())return Nt(t,e);if(_==="transaction"){if(!st(t)&&at())return;O||(O=E[t]!==e),E[t]=e,U.add(t);return}!$()||_||!st(t)&&at()||(Nt(t,e),E[t]!==e&&(E[t]=e,Z()))}}async function On(){yt();let t=J;for(let e=0;e<yn;e+=1){for(;;){const n=D;if(await n,n===D)break}if(!O){if(t!==void 0)throw t;return}if(!xt()){const n=J??t;if(n!==void 0)throw n;return}try{await me(),t=void 0}catch(n){t=n}}if(await D,!!O)throw t??new Error("Client state remained dirty after the final flush attempt")}async function En(){await we(async()=>{if(!V())throw new Error("Client state is not owned by this window");await Se(je,"Native client state clear was rejected",!0)})}async function vn(t){await we(async()=>{if(!(t===$()&&(!t||_===!1))){if(!V())throw new Error("Client state is not owned by this window");if(t){if(!await zt(!0))throw new Error("Native restore preference update was rejected");_=!1,nt(!0);return}nt(!1);try{await Se(()=>zt(!1),"Native restore preference update was rejected")}catch(e){throw nt(!0),e}}})}function Tn(){return Q||(Q=(async()=>{try{const t=await Ee();if(ye=t.partitionProtocolVersion,it(t.isPrimary),nt(t.restoreEnabled),ot(null,!0),O=!1,J=void 0,_=!1,U.clear(),Tt=!0,!t.isPrimary||!t.restoreEnabled)return;let e;if(dn(t.snapshot)){_="snapshot";try{e=await fn(t.snapshot,t.partitionProtocolVersion,Ne)}catch(n){e=null,console.warn("[client-state] failed to load client snapshot partition",n)}e&&(_=!1)}else e=Ct(t.snapshot),_=t.snapshot!==null&&e===null?"snapshot":!1;ot(e,!0),!_&&In()&&Z()}catch(t){Tt=!0,it(!1),ot(),console.warn("[client-state] failed to initialize client state",t)}})(),Q)}const kn=Object.freeze(Object.defineProperty({__proto__:null,clearRestoredClientState:En,clientStateIsPrimary:V,flushClientState:On,initializeClientState:Tn,loadedClientSnapshotExists:An,loadedRestorableSession:de,readClientLayoutValue:bn,restorePreviousStateEnabled:$,setRestorePreviousStateEnabled:vn,updateRestorableSession:_n,writeClientLayoutValue:Pn},Symbol.toStringTag,{value:"Module"}));export{$ as a,xn as b,V as c,Mn as d,vn as e,On as f,En as g,Ln as h,kn as i,de as l,bn as r,Kn as s,_n as u,Pn as w};
2
- //# sourceMappingURL=client-state-CWCzCOz6.js.map
1
+ import{e as ct}from"./git-diff-vendor-ChbWBukG.js";import{a as mt,b as lt,m as Ie,i as $t}from"./index-_N9V2vB3.js";import{h as _e}from"./monaco-viewer-Bv1s0h2m.js";const be=["codenomad-client-snapshot-v1","codenomad-client-restore-enabled-v1"],ht={isPrimary:!1,restoreEnabled:!1,snapshot:null},Pe=_e("actions"),K=(()=>{const t=new Uint8Array(32);return globalThis.crypto.getRandomValues(t),Array.from(t,e=>e.toString(16).padStart(2,"0")).join("")})();let F=!1;const Ht=()=>window.electronAPI;function ft(t,e,n={}){if(mt())return t(Ht());if(lt())return $t(e,{accessToken:K,...n})}async function Oe(){if(!Ie())return!1;try{const t=await ft(e=>{var n;return(n=e==null?void 0:e.claimClientStateAccess)==null?void 0:n.call(e,K)},"client_state_claim_access");F=lt()||t===!0}catch(t){F=!1,Pe.warn("Client state native access claim failed",t)}return F}async function Ee(){if(mt()||lt()){if(!await Oe())return ht;const t=await ft(n=>{var r;return(r=n==null?void 0:n.loadClientState)==null?void 0:r.call(n,K)},"client_state_load")??ht;if(!mt())return t;const e=Ht();return{...t,partitionProtocolVersion:t.partitionProtocolVersion===1&&typeof(e==null?void 0:e.commitClientStatePartitions)=="function"&&typeof e.loadClientStatePartition=="function"?1:void 0}}try{for(const t of be)window.localStorage.removeItem(t)}catch{}return ht}async function dt(t,e,n={}){return F?await ft(r=>r&&t(r),e,n)??!1:!1}const ve=t=>dt(e=>{var n;return(n=e.saveClientState)==null?void 0:n.call(e,K,t)},"client_state_save",{snapshot:t}),Te=t=>dt(e=>{var n;return(n=e.commitClientStatePartitions)==null?void 0:n.call(e,K,t)},"client_state_commit_partitions",{payload:t}),Ne=async t=>F?await ft(e=>{var n;return(n=e==null?void 0:e.loadClientStatePartition)==null?void 0:n.call(e,K,t)},"client_state_load_partition",{key:t})??null:null,zt=t=>dt(e=>{var n;return(n=e.setClientStateRestoreEnabled)==null?void 0:n.call(e,K,t)},"client_state_set_restore_enabled",{enabled:t}),je=()=>dt(t=>{var e;return(e=t.clearClientState)==null?void 0:e.call(t,K)},"client_state_clear");function Gt(t,e={}){return!lt()||!F?Promise.resolve():$t(t,{accessToken:K,...e})}const Mn=t=>Gt("client_state_navigation_flushed",{generation:t}),xn=t=>Gt("client_state_renderer_flushed",{generation:t}),Wt=512,St=1024,wt=4096,Jt=256,H=t=>typeof t=="object"&&t!==null&&!Array.isArray(t),Ce=t=>t!=="__proto__"&&t!=="constructor"&&t!=="prototype";function x(t,e,n=!1){if(!(typeof t!="string"||t.length>e)&&!(!n&&t.trim().length===0))return t}function Zt(t){let e="";for(let n=0;n<t.length;n+=32768)e+=String.fromCharCode(...t.subarray(n,n+32768));return btoa(e)}const qt=t=>Uint8Array.from(atob(t),e=>e.charCodeAt(0));function Re(t){if(typeof t!="string"||t.length%4!==0||!/^[A-Za-z0-9+/]*={0,2}$/.test(t))return!1;try{return qt(t),!0}catch{return!1}}const Qt=t=>{var e;return typeof t=="string"?(e=t.match(/^data:[^;,]+;base64,([A-Za-z0-9+/]*={0,2})$/))==null?void 0:e[1]:void 0};function Me(t,e){const n=Qt(e)??t,r=n instanceof Uint8Array?Zt(n):n;return Re(r)?r:void 0}function Xt(t){if(!(!H(t)||!Number.isSafeInteger(t.line)||Number(t.line)<0)&&!(!Number.isSafeInteger(t.char)||Number(t.char)<0))return{line:Number(t.line),char:Number(t.char)}}function xe(t,e){if(!H(t))return;if(t.type==="text")return typeof t.value=="string"?{type:"text",value:t.value}:void 0;if(t.type==="agent"){const o=x(t.name,St);return o===void 0?void 0:{type:"agent",name:o}}const n=x(t.path,wt);if(t.type==="file"){const o=x(t.mime,Jt);if(n===void 0||o===void 0)return;const l=Qt(e)??t.data,h=Me(t.data,e);return l!==void 0&&h===void 0?void 0:h===void 0?{type:"file",path:n,mime:o}:{type:"file",path:n,mime:o,data:h}}if(t.type!=="symbol"||!H(t.range))return;const r=x(t.name,St),i=Xt(t.range.start),s=Xt(t.range.end);if(!(n===void 0||r===void 0||!Number.isSafeInteger(t.kind)||!i||!s))return{type:"symbol",path:n,name:r,kind:Number(t.kind),range:{start:i,end:s}}}function Ke(t){if(!H(t)||!["file","text","symbol","agent"].includes(String(t.type)))return;const e=x(t.id,Wt),n=x(t.display,St),r=x(t.filename,wt),i=x(t.mediaType,Jt),s=xe(t.source,t.url),o=typeof t.url=="string"&&!t.url.startsWith("data:")?t.url:"",l=x(o,wt,!0);if(!(!e||!n||!r||!i||!s||s.type!==t.type||l===void 0))return{id:e,type:t.type,display:n,url:l,filename:r,mediaType:i,source:s}}function jt(t,e,n=[]){if(!H(t))return null;const r=Object.create(null),i=[...new Set(n)],s=new Set(i),o=[...i.flatMap(l=>Object.prototype.hasOwnProperty.call(t,l)?[[l,t[l]]]:[]),...Object.entries(t).filter(([l])=>!s.has(l))];for(const[l,h]of o){if(!Ce(l)||!l||l.length>Wt||!Array.isArray(h))continue;const w=[];for(const S of h){const u=Ke(S);u&&w.push(u)}w.length&&(r[l]=w)}return{attachments:r,drafts:{...e}}}function Kn(t,e,n=[]){const r=jt(e,t,n);if(!r||Object.entries(e).some(([i,s])=>{var o;return s.length!==(((o=r.attachments[i])==null?void 0:o.length)??0)}))throw new Error("Draft attachments could not be persisted safely");return r}function Ln(t){let e,n=t.url;if(t.source.type==="file")try{const r=t.source.data===void 0?void 0:qt(t.source.data);e={type:"file",path:t.source.path,mime:t.source.mime,data:r},!n&&t.source.data&&(n=`data:${t.source.mime};base64,${t.source.data}`)}catch{return null}else e=t.source,t.source.type==="text"&&!n&&(n=`data:text/plain;base64,${Zt(new TextEncoder().encode(t.source.value))}`);return{...t,url:n,source:e}}const te=32,Le=64,ke=24,ze=96,Xe=256,Be=256,De=256,ee=256,At=4096,tt=512,Ve=4096,ne=32*1024,Ye=1024,Ue=96*1024,Fe=256,Bt=1024,$e="__no_session_draft__";function re(){return{remaining:Ue,scrollSnapshotsRemaining:Fe}}const k=t=>typeof t=="object"&&t!==null&&!Array.isArray(t),oe=t=>t!=="__proto__"&&t!=="constructor"&&t!=="prototype";function N(t,e,n,r=!1){if(!(typeof t!="string"||t.length>e||t.length>n.remaining)&&!(!r&&t.trim().length===0))return n.remaining-=t.length,t}const X=(t,e,n)=>typeof t=="number"&&Number.isFinite(t)&&t>=e&&t<=n?t:void 0;function et(t,e,n,r,i=()=>!0,s=()=>{},o=[]){if(!k(t))return null;const l=Object.create(null);let h=0;const w=[...new Set(o)],S=new Set(w),u=[...w.flatMap(p=>Object.prototype.hasOwnProperty.call(t,p)?[[p,t[p]]]:[]),...Object.entries(t).filter(([p])=>!S.has(p))];for(const[p,j]of u){if(h>=e)break;if(!oe(p)||!i(j))continue;const b=N(p,ee,n),f=r(j);b===void 0||f===void 0||(l[b]=f,h+=1,s())}return l}function ie(t,e,n,r,i=[]){return et(t,e,r,s=>N(s,n,r,!0),void 0,void 0,i)}function He(t,e){if(!k(t))return;const n=X(t.scrollTop,0,1e9),r=X(t.updatedAt,0,Number.MAX_SAFE_INTEGER);if(n===void 0||r===void 0||typeof t.atBottom!="boolean")return;const i={scrollTop:n,atBottom:t.atBottom,updatedAt:r},s=X(t.scrollRatio,0,1),o=X(t.maxScrollTop,0,1e9),l=X(t.anchorOffset,-1e6,1e6),h=t.anchorKey===void 0?void 0:N(t.anchorKey,Ye,e);s!==void 0&&(i.scrollRatio=s),o!==void 0&&(i.maxScrollTop=o),h!==void 0&&(i.anchorKey=h),l!==void 0&&(i.anchorOffset=l),(t.followModeType==="following"||t.followModeType==="escaped")&&(i.followModeType=t.followModeType),typeof t.windowIsLatest=="boolean"&&(i.windowIsLatest=t.windowIsLatest);const w=t.windowCursor===void 0?void 0:N(t.windowCursor,Bt,e);if(w!==void 0&&(i.windowCursor=w),Array.isArray(t.newerCursors)){const S=[];for(const u of t.newerCursors.slice(-32)){if(u===null||u===""){S.push(null);continue}const p=N(u,Bt,e);p!==void 0&&S.push(p)}S.length>0&&(i.newerCursors=S)}return i}function Ge(t,e){if(!Array.isArray(t))return null;const n=[],r=new Set;for(const i of t.slice(0,De)){if(typeof i!="string"||r.has(i))continue;const s=N(i,tt,e);s!==void 0&&(r.add(s),n.push(s))}return n}function We(t,e,n,r){const i=e.priorityDrafts,s=Object.fromEntries(Object.entries(t.drafts??{}).filter(([a])=>!Object.prototype.hasOwnProperty.call(i,a))),o=ie(s,Math.max(0,ke-Object.keys(i).length),ne,n),l=o?{...i,...o}:null,h=Math.min(ze,n.scrollSnapshotsRemaining),w=et(t.scrollSnapshots??{},h,n,a=>He(a,n),void 0,()=>{n.scrollSnapshotsRemaining-=1}),S=et(t.unseenIdleSince??{},Xe,n,a=>X(a,0,Number.MAX_SAFE_INTEGER)),u=et(t.generationRecovery??{},Be,n,a=>a,a=>a==="working"||a==="interrupted"),p=t.expandedSessionIds===void 0?void 0:Ge(t.expandedSessionIds,n);if(!l||!w||!S||!u||p===null)return null;const j=Object.fromEntries(Object.entries(t.attachments??{}).filter(([a])=>!e.prioritySessionIds.includes(a))),b=jt(j,l);if(!b)return null;const f={kind:"workspace",folder:e.folder,drafts:b.drafts,attachments:{...e.priorityAttachments,...b.attachments},scrollSnapshots:w,unseenIdleSince:S,generationRecovery:u};p!==void 0&&(f.expandedSessionIds=p),Number.isInteger(t.occurrence)&&Number(t.occurrence)>=0&&Number(t.occurrence)<te&&(f.occurrence=Number(t.occurrence));const y=t.projectName===void 0?void 0:N(t.projectName,At,n),c=t.binaryPath===void 0?void 0:N(t.binaryPath,At,n);return y!==void 0&&(f.projectName=y),c!==void 0&&(f.binaryPath=c),e.activeParentSessionId!==void 0&&(f.activeParentSessionId=e.activeParentSessionId),e.activeSessionId!==void 0&&(f.activeSessionId=e.activeSessionId),f}function Je(t,e){if(!k(t))return null;const n=t.kind??t.type;if(n==="sidecar"){const l=N(t.sidecarId,tt,e);return l===void 0?null:{kind:n,sidecarId:l}}if(n!=="workspace"&&n!=="instance"||!["drafts","attachments","scrollSnapshots","unseenIdleSince","generationRecovery"].every(l=>k(t[l]??{})))return null;const r=N(t.folder,At,e);if(r===void 0)return null;const i=t.activeParentSessionId===void 0?void 0:N(t.activeParentSessionId,tt,e),s=t.activeSessionId===void 0?void 0:N(t.activeSessionId,tt,e),o=[s,$e].filter(l=>!!l);return{kind:"workspace",value:t,folder:r,activeParentSessionId:i,activeSessionId:s,prioritySessionIds:o,priorityDrafts:Object.create(null),priorityAttachments:Object.create(null)}}function Ze(t,e){const n=t.value.drafts??{};if(!k(n))return;for(const o of t.prioritySessionIds){if(!oe(o)||!Object.prototype.hasOwnProperty.call(n,o))continue;const l=e.remaining,h=N(o,ee,e),w=N(n[o],ne,e,!0);if(h===void 0||w===void 0){e.remaining=l;continue}t.priorityDrafts[h]=w}const r=t.value.attachments??{};if(!k(r))return;const i=Object.fromEntries(t.prioritySessionIds.filter(o=>Object.prototype.hasOwnProperty.call(r,o)).map(o=>[o,r[o]])),s=jt(i,t.priorityDrafts,t.prioritySessionIds);s&&(t.priorityDrafts=s.drafts,t.priorityAttachments=s.attachments)}function gt(t){return se(t,re())}function se(t,e){if(!k(t)||!Array.isArray(t.tabs)||!Number.isInteger(t.activeTabIndex))return null;const n=Number(t.activeTabIndex),r=t.tabs.slice(0,te),i=new Map,s=new Map,o=f=>{const y=Je(r[f],e);y&&i.set(f,y)},l=(f,y)=>{const c=i.get(f);if(!c)return;const a=c.kind==="sidecar"?c:We(c.value,c,e);a&&s.set(f,a)};r.forEach((f,y)=>o(y));const h=[n,...r.map((f,y)=>y).filter(f=>f!==n)];for(const f of h){const y=i.get(f);(y==null?void 0:y.kind)==="workspace"&&Ze(y,e)}r[n]!==void 0&&l(n),r.forEach((f,y)=>{y!==n&&l(y)});const S=r.flatMap((f,y)=>{const c=i.get(y);return c?[{originalIndex:y,identity:c}]:[]}).flatMap(({originalIndex:f})=>{const y=s.get(f);return y?[{originalIndex:f,tab:y}]:[]});if(t.tabs.length&&!S.length)return null;const u=S.map(({tab:f})=>f),p=S.findIndex(({originalIndex:f})=>f===n),j=S.findIndex(({originalIndex:f})=>f>n),b=u.length?p>=0?p:j>=0?j:u.length-1:-1;return{tabs:u,activeTabIndex:b,...t.homeActive===!0?{homeActive:!0}:{}}}function Ct(t){if(!k(t)||t.version!==void 0&&t.version!==1||!Number.isSafeInteger(t.revision)||Number(t.revision)<0)return null;const e=X(t.savedAt,0,Number.MAX_SAFE_INTEGER);if(e===void 0)return null;const n=re(),r=t.session===null?null:se(t.session,n);if(t.session!==null&&!r)return null;const i=ie(t.layout,Le,Ve,n);return i?{version:1,revision:Number(t.revision),savedAt:e,layout:i,session:r}:null}const G=1024*1024,It=1024*1024,qe=4096,Dt=256*1024*1024,Qe=512,_t=768*1024,ae=256,ce=_t*ae,B=/^[0-9a-f]{64}$/,tn=["layout","partitionKeys","revision","savedAt","sessionPartition","version"],en=new Set(["__proto__","constructor","prototype"]),z=new TextEncoder,C=t=>typeof t=="object"&&t!==null&&!Array.isArray(t),I=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),q=t=>typeof t=="string"&&t.length>0&&t.length<=Qe&&t.trim().length>0&&!en.has(t);function le(t){return Array.isArray(t)&&t.every((e,n)=>typeof e=="string"&&B.test(e)&&(n===0||t[n-1]<e))}function M(t,e,n=[]){const r=new Set([...e,...n]);return e.every(i=>I(t,i))&&Object.keys(t).every(i=>r.has(i))}function bt(t){return Array.isArray(t)?t.map(bt):C(t)?Object.fromEntries(Object.keys(t).sort().map(e=>[e,bt(t[e])])):t}function W(t){const e=JSON.stringify(bt(t));if(e===void 0)throw new TypeError("Client state partition must be JSON-serializable");return e}function Pt(t,e){try{return W(t)===W(e)}catch{return!1}}async function Rt(t){const e=await crypto.subtle.digest("SHA-256",z.encode(t));return Array.from(new Uint8Array(e),n=>n.toString(16).padStart(2,"0")).join("")}function nn(t){let e="";for(let n=0;n<t.length;n+=32768)e+=String.fromCharCode(...t.subarray(n,n+32768));return btoa(e)}const rn=t=>Uint8Array.from(atob(t),e=>e.charCodeAt(0)),Ot=t=>typeof t=="string"&&t.length%4===0&&/^[A-Za-z0-9+/]*={0,2}$/.test(t);async function Vt(t,e){if(!Ot(t)||t.length>ce)throw new Error("Client state attachment exceeds the 192 MiB encoded blob limit");const n=[];for(let r=0,i=0;r<t.length||r===0;r+=_t,i+=1)n.push(await e({format:2,index:i,data:t.slice(r,r+_t)}));return n}async function on(t,e){return Promise.all(t.map(async n=>{let r;return n.source.type==="file"?(r={type:"file",path:n.source.path,mime:n.source.mime},n.source.data!==void 0&&(r.dataPartitions=await Vt(n.source.data,e))):n.source.type==="text"?r={type:"text",valuePartitions:await Vt(nn(z.encode(n.source.value)),e)}:r=n.source,{...n,source:r}}))}async function Et(t){const e=Object.create(null),n=async o=>{const l=W(o);if(z.encode(l).byteLength>G)throw new Error("Client state partition exceeds the native size limit");const h=await Rt(l);return e[h]=l,h},r=t===null?null:{tabs:await Promise.all(t.tabs.map(async o=>{if(o.kind==="sidecar")return{kind:o.kind,sidecarId:o.sidecarId};const l=new Set([...Object.keys(o.drafts),...Object.keys(o.attachments),...Object.keys(o.scrollSnapshots),...Object.keys(o.unseenIdleSince),...Object.keys(o.generationRecovery)]),h=Object.create(null);for(const u of[...l].sort()){const p={format:2};I(o.drafts,u)&&(p.draft=o.drafts[u]),I(o.attachments,u)&&(p.attachments=await on(o.attachments[u],n)),I(o.scrollSnapshots,u)&&(p.scrollSnapshot=o.scrollSnapshots[u]),I(o.unseenIdleSince,u)&&(p.unseenIdleSince=o.unseenIdleSince[u]),I(o.generationRecovery,u)&&(p.generationRecovery=o.generationRecovery[u]);const j=await n(p),b=(p.attachments??[]).flatMap(f=>{if(!C(f)||!C(f.source))return[];const y=f.source.dataPartitions??f.source.valuePartitions;return Array.isArray(y)?y.filter(c=>typeof c=="string"):[]});h[u]={documentPartition:j,partitionKeys:[...new Set([j,...b])].sort()}}const w={format:2,sessions:h};o.activeParentSessionId!==void 0&&(w.activeParentSessionId=o.activeParentSessionId),o.activeSessionId!==void 0&&(w.activeSessionId=o.activeSessionId),o.expandedSessionIds!==void 0&&(w.expandedSessionIds=o.expandedSessionIds);const S={kind:o.kind,folder:o.folder,workspacePartition:await n(w)};return o.occurrence!==void 0&&(S.occurrence=o.occurrence),o.projectName!==void 0&&(S.projectName=o.projectName),o.binaryPath!==void 0&&(S.binaryPath=o.binaryPath),S})),activeTabIndex:t.activeTabIndex,...t.homeActive!==void 0?{homeActive:t.homeActive}:{}},i=await n({format:2,session:r}),s=Object.keys(e).sort();return{sessionPartition:i,partitionKeys:s,partitions:Object.fromEntries(s.map(o=>[o,e[o]]))}}async function sn(t){const e=await Et(t.session);return{root:{version:2,revision:t.revision,savedAt:t.savedAt,layout:t.layout,sessionPartition:e.sessionPartition,partitionKeys:e.partitionKeys},partitions:e.partitions,partitionKeys:e.partitionKeys}}function an(t){if(t.partitionKeys.length>qe)return!1;const e=JSON.stringify(t.root);if(e.length>It)return!1;let n=z.encode(e).byteLength;if(n>It)return!1;for(const r in t.partitions){if(!I(t.partitions,r))continue;const i=t.partitions[r];if(i.length>G||i.length>Dt-n)return!1;const s=z.encode(i).byteLength;if(s>G||s>Dt-n)return!1;n+=s}return!0}function cn(t){if(!C(t)||t.version!==2||typeof t.sessionPartition!="string"||!B.test(t.sessionPartition)||!le(t.partitionKeys)||!t.partitionKeys.includes(t.sessionPartition)||Object.keys(t).sort().join("\0")!==tn.join("\0"))return null;let e;try{e=JSON.stringify(t)}catch{return null}if(z.encode(e).byteLength>It)return null;const n=Ct({...t,version:1,session:null});return!n||!Pt(t,{version:2,revision:n.revision,savedAt:n.savedAt,layout:n.layout,sessionPartition:t.sessionPartition,partitionKeys:t.partitionKeys})?null:{root:n,partitionKey:t.sessionPartition,partitionKeys:t.partitionKeys}}function fe(t){try{return{value:JSON.parse(t)}}catch{return null}}async function ln(t,e,n,r,i){var y;if(!M(t,["format","session"])||W(t)!==r.get(e))return;if(t.session===null){const c=await Et(null);return Yt(c,e,n,r)?null:void 0}if(!C(t.session)||!M(t.session,["tabs","activeTabIndex"],["homeActive"])||!Array.isArray(t.session.tabs))return;const s=async c=>{if(typeof c!="string"||!B.test(c))return null;let a=r.get(c);if(a===void 0){if(a=await i(c)??void 0,a===void 0||z.encode(a).byteLength>G||await Rt(a)!==c)return null;r.set(c,a)}const A=fe(a);return A&&C(A.value)&&W(A.value)===a?A.value:null},o=(c,a)=>{const A=[...new Set(c)].sort();return A.length===a.length&&A.every((v,P)=>v===a[P])},l=async(c,a,A)=>{if(!Array.isArray(c)||!c.length||c.length>ae||!c.every(d=>typeof d=="string"&&B.test(d))||new Set(c).size!==c.length)return null;const v=[];let P=0;for(const[d,m]of c.entries()){if(!a.has(m))return null;A.add(m);const T=await s(m);if(!T||!Ot(T.data))return null;if(T.format===1){if(!M(T,["format","data"]))return null}else if(T.format===2){if(!M(T,["format","index","data"])||T.index!==d)return null}else return null;if(T.data.length>ce-P)return null;P+=T.data.length,v.push(T.data)}const g=v.join("");return Ot(g)?g:null},h=async(c,a,A)=>{if(!Array.isArray(c))return null;const v=[];for(const P of c){if(!C(P)||!M(P,["id","type","display","url","filename","mediaType","source"])||!C(P.source))return null;const g=P.source;if(g.type==="file"){if(!M(g,["type","path","mime"],["dataPartitions"]))return null;if(I(g,"dataPartitions")){const d=await l(g.dataPartitions,a,A);if(d===null)return null;v.push({...P,source:{type:g.type,path:g.path,mime:g.mime,data:d}})}else v.push(P);continue}if(g.type==="text"){if(!M(g,["type","valuePartitions"]))return null;const d=await l(g.valuePartitions,a,A);if(d===null)return null;try{const m=new TextDecoder("utf-8",{fatal:!0}).decode(rn(d));v.push({...P,source:{type:g.type,value:m}})}catch{return null}continue}v.push(P)}return v},w=[],S=new Set([e]);let u=!1,p=!1;for(const c of t.session.tabs){if(!C(c))return;if(c.kind==="sidecar"){if(!M(c,["kind","sidecarId"]))return;w.push({kind:c.kind,sidecarId:c.sidecarId});continue}if(c.kind!=="workspace"||!M(c,["kind","folder","workspacePartition"],["occurrence","projectName","binaryPath"])||typeof c.workspacePartition!="string"||!B.test(c.workspacePartition))return;S.add(c.workspacePartition);const a=await s(c.workspacePartition);if(!a||a.format!==1&&a.format!==2||!M(a,["format","sessions"],["activeParentSessionId","activeSessionId","expandedSessionIds"])||!C(a.sessions)||(p||(p=a.format===1),!Object.keys(a.sessions).every(q)||I(a,"activeParentSessionId")&&!q(a.activeParentSessionId)||I(a,"activeSessionId")&&!q(a.activeSessionId)||I(a,"expandedSessionIds")&&(!Array.isArray(a.expandedSessionIds)||!a.expandedSessionIds.every(q))))return;const A={kind:c.kind,folder:c.folder,drafts:Object.create(null),attachments:Object.create(null),scrollSnapshots:Object.create(null),unseenIdleSince:Object.create(null),generationRecovery:Object.create(null)};for(const d of["occurrence","projectName","binaryPath"])I(c,d)&&(A[d]=c[d]);for(const d of["activeParentSessionId","activeSessionId","expandedSessionIds"])I(a,d)&&(A[d]=a[d]);const v=[];for(const[d,m]of Object.entries(a.sessions)){if(a.format===1){if(typeof m!="string"||!B.test(m))return;v.push({sessionId:d,documentKey:m,partitionKeys:[m]}),S.add(m);continue}if(!C(m)||!M(m,["documentPartition","partitionKeys"])||typeof m.documentPartition!="string"||!B.test(m.documentPartition)||!le(m.partitionKeys)||!m.partitionKeys.includes(m.documentPartition))return;v.push({sessionId:d,documentKey:m.documentPartition,partitionKeys:m.partitionKeys}),m.partitionKeys.forEach(T=>S.add(T))}const P=typeof a.activeSessionId=="string"?a.activeSessionId:void 0;v.sort((d,m)=>d.sessionId===P?-1:m.sessionId===P?1:d.sessionId.localeCompare(m.sessionId));const g=new Set;for(const{sessionId:d,documentKey:m,partitionKeys:T}of v){const R=await s(m),Ae=new Set(T),Kt=new Set([m]);if(!(R&&(R.format===1||R.format===2)&&M(R,["format"],["draft","attachments","scrollSnapshot","unseenIdleSince","generationRecovery"])&&Object.keys(R).length>1)){u=!0,g.add(d);continue}const pt=I(R,"attachments")?R.format===1?R.attachments:await h(R.attachments,Ae,Kt):void 0;if(I(R,"attachments")&&pt===null||!o(Kt,T)){u=!0,g.add(d);continue}const L={kind:"workspace",folder:"/",drafts:Object.create(null),attachments:Object.create(null),scrollSnapshots:Object.create(null),unseenIdleSince:Object.create(null),generationRecovery:Object.create(null)},Lt=[["draft","drafts"],["scrollSnapshot","scrollSnapshots"],["unseenIdleSince","unseenIdleSince"],["generationRecovery","generationRecovery"]];for(const[Y,ge]of Lt)I(R,Y)&&(L[ge][d]=R[Y]);pt!==void 0&&(L.attachments[d]=pt);const kt=(y=gt({tabs:[L],activeTabIndex:0}))==null?void 0:y.tabs[0];if(!kt||!Pt(L,kt)){u=!0,g.add(d);continue}for(const[,Y]of Lt)I(L[Y],d)&&(A[Y][d]=L[Y][d]);I(L.attachments,d)&&(A.attachments[d]=L.attachments[d])}g.has(String(A.activeSessionId))&&delete A.activeSessionId,g.has(String(A.activeParentSessionId))&&delete A.activeParentSessionId,Array.isArray(A.expandedSessionIds)&&(A.expandedSessionIds=A.expandedSessionIds.filter(d=>!g.has(String(d)))),w.push(A)}if(!o(S,n))return;const j={tabs:w,activeTabIndex:t.session.activeTabIndex,...I(t.session,"homeActive")?{homeActive:t.session.homeActive}:{}},b=gt(j);if(!b||!Pt(j,b))return;if(u||p)return b;const f=await Et(b);return Yt(f,e,n,r)?b:void 0}function Yt(t,e,n,r){return t.sessionPartition!==e||t.partitionKeys.length!==n.length||!t.partitionKeys.every((i,s)=>i===n[s])||t.partitionKeys.length!==r.size?!1:t.partitionKeys.every(i=>r.get(i)===t.partitions[i])}async function fn(t,e,n){const r=cn(t);if(!r||e!==1)return null;try{const i=await n(r.partitionKey);if(i===null||z.encode(i).byteLength>G||await Rt(i)!==r.partitionKey)return null;const s=fe(i);if(!s)return null;if(C(s.value)&&s.value.format===2){const o=new Map([[r.partitionKey,i]]),l=await ln(s.value,r.partitionKey,r.partitionKeys,o,n);return l===void 0?null:{...r.root,session:l}}return null}catch{return null}}const dn=t=>C(t)&&t.version===2,un=250,yn=3,pn=1024*1024,hn=64,mn=256,Mt=4096,Sn="opencode-session-",wn=new Set(["__proto__","constructor","prototype"]),[V,it]=ct(!0),[$,nt]=ct(!1),[An,gn]=ct(!1),[de,vt]=ct(null);let Tt=!1,Q=null,E=Object.create(null),ue=0,O=!1,_=!1,rt=null,D=Promise.resolve(),Ut=Promise.resolve(),J,ye;const U=new Set;function ut(t,e){try{return e(window.localStorage)}catch{return t}}function pe(t){return t.length>0&&t.length<=mn&&!wn.has(t)}const Ft=t=>ut(null,e=>{const n=e.getItem(t);return n!==null&&n.length<=Mt?n:null}),Nt=(t,e)=>ut(void 0,n=>n.setItem(t,e));function he(t){const e=new Set(Object.keys(E));for(let n=0;n<t.length;n+=1){const r=t.key(n);r!=null&&r.startsWith(Sn)&&e.add(r)}return[...e]}const st=t=>Object.prototype.hasOwnProperty.call(E,t),at=()=>Object.keys(E).length>=hn;function In(){return ut(!1,t=>{const e=Object.keys(E).length;for(const n of he(t)){if(st(n))continue;if(at())break;const r=t.getItem(n);r===null||r.length>Mt||(E[n]=r)}return Object.keys(E).length!==e})}function xt(){return Tt&&V()&&$()&&!_}const yt=()=>{rt!==null&&clearTimeout(rt),rt=null};function me(){if(yt(),!O||!xt())return D;const t={version:1,revision:++ue,savedAt:Date.now(),layout:{...E},session:de()},e=Ct(t);if(!e)return Promise.reject(new Error("Client snapshot normalization failed"));E={...e.layout},O=!1;const n=D.then(async()=>{try{const r=ye===1?await sn(e):null;if(r&&!an(r))throw new Error("Client snapshot exceeds the native partition count or size limits");if(!r&&new TextEncoder().encode(JSON.stringify(e)).byteLength>pn)throw new Error("Client snapshot exceeds the V1 1 MiB limit and partition persistence is unavailable");if(!(r?await Te({protocolVersion:1,snapshot:r.root,partitions:r.partitions,partitionKeys:r.partitionKeys}):await ve(e)))throw it(!1),new Error("Native client state save was rejected");J=void 0}catch(r){throw O=!0,J=r,r}});return D=n.catch(()=>{}),n}function Z(){O=!0,xt()&&(yt(),rt=setTimeout(()=>void me().catch(t=>console.warn("[client-state] failed to save client snapshot",t)),un))}function ot(t=null,e=!1){E=t?{...t.layout}:Object.create(null),e&&(ue=(t==null?void 0:t.revision)??0),gn(t!==null),vt((t==null?void 0:t.session)??null)}async function Se(t,e,n=!1){const r=_;let i=O;_="transaction",U.clear(),yt(),O=!1;try{if(await D,i||(i=O),O=!1,!await t())throw n&&it(!1),new Error(e);ut(void 0,s=>{for(const o of he(s))s.removeItem(o)}),ot(),U.clear(),_="snapshot"}catch(s){i||(i=O);for(const o of U)Nt(o,E[o]);throw U.clear(),_=r,O=i,O&&Z(),s}}function we(t){const e=Ut.then(t);return Ut=e.catch(()=>{}),e}function _n(t){const e=t===null?null:gt(t);if(!(t!==null&&e===null)){if(_==="transaction"){vt(e),O=!0;return}_||!V()||!$()||(vt(e),Z())}}function bn(t){if(!pe(t))return null;if(!V())return Ft(t);if(!$()||_)return null;if(st(t))return E[t]??null;const e=Ft(t);return e===null||at()||(E[t]=e,Z()),e}function Pn(t,e){if(!(!pe(t)||e.length>Mt)){if(!V())return Nt(t,e);if(_==="transaction"){if(!st(t)&&at())return;O||(O=E[t]!==e),E[t]=e,U.add(t);return}!$()||_||!st(t)&&at()||(Nt(t,e),E[t]!==e&&(E[t]=e,Z()))}}async function On(){yt();let t=J;for(let e=0;e<yn;e+=1){for(;;){const n=D;if(await n,n===D)break}if(!O){if(t!==void 0)throw t;return}if(!xt()){const n=J??t;if(n!==void 0)throw n;return}try{await me(),t=void 0}catch(n){t=n}}if(await D,!!O)throw t??new Error("Client state remained dirty after the final flush attempt")}async function En(){await we(async()=>{if(!V())throw new Error("Client state is not owned by this window");await Se(je,"Native client state clear was rejected",!0)})}async function vn(t){await we(async()=>{if(!(t===$()&&(!t||_===!1))){if(!V())throw new Error("Client state is not owned by this window");if(t){if(!await zt(!0))throw new Error("Native restore preference update was rejected");_=!1,nt(!0);return}nt(!1);try{await Se(()=>zt(!1),"Native restore preference update was rejected")}catch(e){throw nt(!0),e}}})}function Tn(){return Q||(Q=(async()=>{try{const t=await Ee();if(ye=t.partitionProtocolVersion,it(t.isPrimary),nt(t.restoreEnabled),ot(null,!0),O=!1,J=void 0,_=!1,U.clear(),Tt=!0,!t.isPrimary||!t.restoreEnabled)return;let e;if(dn(t.snapshot)){_="snapshot";try{e=await fn(t.snapshot,t.partitionProtocolVersion,Ne)}catch(n){e=null,console.warn("[client-state] failed to load client snapshot partition",n)}e&&(_=!1)}else e=Ct(t.snapshot),_=t.snapshot!==null&&e===null?"snapshot":!1;ot(e,!0),!_&&In()&&Z()}catch(t){Tt=!0,it(!1),ot(),console.warn("[client-state] failed to initialize client state",t)}})(),Q)}const kn=Object.freeze(Object.defineProperty({__proto__:null,clearRestoredClientState:En,clientStateIsPrimary:V,flushClientState:On,initializeClientState:Tn,loadedClientSnapshotExists:An,loadedRestorableSession:de,readClientLayoutValue:bn,restorePreviousStateEnabled:$,setRestorePreviousStateEnabled:vn,updateRestorableSession:_n,writeClientLayoutValue:Pn},Symbol.toStringTag,{value:"Module"}));export{$ as a,xn as b,V as c,Mn as d,vn as e,On as f,En as g,Ln as h,kn as i,de as l,bn as r,Kn as s,_n as u,Pn as w};
2
+ //# sourceMappingURL=client-state-DGbupmmR.js.map