@kern0x1b/penstock-cli 26.10.3 → 26.10.5

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/dist/chunk-account-C8EHysMH.js +1 -0
  2. package/dist/chunk-agentFailure-piRAFLGH.js +1 -0
  3. package/dist/chunk-agentLaunch-C5Uo40vv.js +1 -0
  4. package/dist/chunk-agentServe-4O0syoYQ.js +10 -0
  5. package/dist/chunk-analyze-Brxlb4U1.js +1 -0
  6. package/dist/chunk-analyze-CUxuBgNS.js +1 -0
  7. package/dist/chunk-apply-BAMwoXG9.js +1 -0
  8. package/dist/chunk-atomicWrite-C6J1gDtO.js +1 -0
  9. package/dist/chunk-baseline-DvS2S0am.js +1 -0
  10. package/dist/chunk-bot-I4kuhjyv.js +11 -0
  11. package/dist/chunk-cacheDirectory-7sa0970e.js +1 -0
  12. package/dist/chunk-codeFactSet-DOOlbIIj.js +1 -0
  13. package/dist/chunk-codeIndex-CzENd6hG.js +1 -0
  14. package/dist/chunk-codeLinks-D-gzUjYv.js +1 -0
  15. package/dist/chunk-codeLinks-DLxEBWPi.js +1 -0
  16. package/dist/chunk-command-BR4memGJ.js +1 -0
  17. package/dist/chunk-command-BctoT00W.js +5 -0
  18. package/dist/chunk-command-Jl1msVwF.js +1 -0
  19. package/dist/chunk-commands-CeRlfHY-.js +1 -0
  20. package/dist/chunk-compose-BV9Jg348.js +4 -0
  21. package/dist/chunk-connectors-CVfz5pSg.js +1 -0
  22. package/dist/chunk-connectors-eXPldvkc.js +2 -0
  23. package/dist/chunk-context-DPJmldqg.js +1 -0
  24. package/dist/chunk-convert-B1sgT9kl.js +1 -0
  25. package/dist/chunk-deploy-C4KJK-tw.js +1 -0
  26. package/dist/chunk-deploy-DOXu2-8q.js +2 -0
  27. package/dist/chunk-diagram-BaVwLa4h.js +1 -0
  28. package/dist/chunk-diagram-CCA1-fT5.js +1 -0
  29. package/dist/chunk-diagramDefects-7UG_Iwsr.js +1 -0
  30. package/dist/chunk-diagrams-6suPQBVQ.js +1 -0
  31. package/dist/chunk-diff-BC8gZX5w.js +1 -0
  32. package/dist/chunk-diff-D1m_eKvv.js +1 -0
  33. package/dist/chunk-diffModels-DYtf3au1.js +3 -0
  34. package/dist/chunk-dispatch-CW2CJI0C.js +6 -0
  35. package/dist/chunk-docs-CY6ICsip.js +1 -0
  36. package/dist/chunk-docs-CwY3Ce9M.js +30 -0
  37. package/dist/chunk-doctor-m0mnVdDE.js +1 -0
  38. package/dist/chunk-drawing-shRfnrs9.js +8 -0
  39. package/dist/chunk-editPreview-BgH1JVOD.js +1 -0
  40. package/dist/chunk-engine-CxgdJ2wO.js +1 -0
  41. package/dist/chunk-export-9AWsr5ai.js +1 -0
  42. package/dist/chunk-export-D5kPD4Or.js +20 -0
  43. package/dist/chunk-facts-DA3Y-k9a.js +1 -0
  44. package/dist/chunk-failure-BsimkHy_.js +1 -0
  45. package/dist/chunk-features-BfRg2kR5.js +1 -0
  46. package/dist/chunk-features-BwnwB6jL.js +1 -0
  47. package/dist/chunk-folders-13vx0i0n.js +1 -0
  48. package/dist/chunk-folders-C1Nes4Ap.js +1 -0
  49. package/dist/chunk-formChecks-acRgARZ3.js +1 -0
  50. package/dist/chunk-git-BOKyPQj7.js +3 -0
  51. package/dist/chunk-help-CFhmAhz8.js +85 -0
  52. package/dist/chunk-importCommand-5SJxu2k4.js +1 -0
  53. package/dist/chunk-init-AIh_7yE0.js +227 -0
  54. package/dist/chunk-license-B_To2110.js +1 -0
  55. package/dist/chunk-license-x3oHbKe2.js +1 -0
  56. package/dist/chunk-lint-C_fAcLIg.js +1 -0
  57. package/dist/chunk-load-BVJUBU5S.js +5 -0
  58. package/dist/chunk-main-D3S4Xr__.js +1 -0
  59. package/dist/chunk-mcp-ByMCWlXC.js +76 -0
  60. package/dist/chunk-mcpLaunch-C13ViiIP.js +592 -0
  61. package/dist/chunk-migrate-CLQ-hrae.js +1 -0
  62. package/dist/chunk-migrate-CVUR1K7f.js +1 -0
  63. package/dist/chunk-moddle-AjPH0QEc.js +1 -0
  64. package/dist/chunk-moddle-Dlk0NR-u.js +1 -0
  65. package/dist/chunk-own-CX-3lIbf.js +1 -0
  66. package/dist/chunk-penstockCli-CqiOKC75.js +1 -0
  67. package/dist/chunk-placeholderLayout-B18ekWmh.js +1 -0
  68. package/dist/chunk-plural-Bq_4vgOr.js +1 -0
  69. package/dist/chunk-pr-tC3-PSNM.js +1 -0
  70. package/dist/chunk-preferencesFile-F6bAlNrk.js +1 -0
  71. package/dist/chunk-project-qT-Fk_Rz.js +1 -0
  72. package/dist/chunk-report-CDz78nCI.js +1 -0
  73. package/dist/chunk-review-BqZSohXR.js +1 -0
  74. package/dist/chunk-rules-DJlL7K_Q.js +1 -0
  75. package/dist/chunk-security-5SU-bq3A.js +18 -0
  76. package/dist/chunk-share-YSewfw3F.js +239 -0
  77. package/dist/chunk-src-BLyg_6UX.js +879 -0
  78. package/dist/chunk-stages-C-nhLoBW.js +3 -0
  79. package/dist/chunk-status-DgeSOz3A.js +1 -0
  80. package/dist/chunk-systemError-2me5k57V.js +1 -0
  81. package/dist/chunk-systemError-B-1nL94i.js +1 -0
  82. package/dist/chunk-table-CJtiXv0e.js +1 -0
  83. package/dist/chunk-taskTest-4rIxp0rL.js +2 -0
  84. package/dist/chunk-taskTest-rng12v_b.js +1 -0
  85. package/dist/chunk-templates-Bxe3J0qy.js +1 -0
  86. package/dist/chunk-testCases-CwQ-Mi7L.js +1 -0
  87. package/dist/chunk-testCases-xculyxH_.js +4 -0
  88. package/dist/chunk-tests-C-kNQNpq.js +1 -0
  89. package/dist/chunk-tests-C3XJ9LMT.js +23 -0
  90. package/dist/chunk-translator-BFUJmSkR.js +21 -0
  91. package/dist/chunk-trust-u1vZ6Yk0.js +1 -0
  92. package/dist/chunk-trust-yKw_pXRj.js +1 -0
  93. package/dist/chunk-version-CdS8_QQd.js +1 -0
  94. package/dist/chunk-workerVariables-CCLcoR0U.js +1 -0
  95. package/dist/chunk-wrapper-AJWl6ru-.js +3 -0
  96. package/dist/chunk-wrapper-Bxz1Lgp5.js +1 -0
  97. package/dist/licensing.json +1 -1
  98. package/dist/locales/de.json +9176 -0
  99. package/dist/locales/es.json +9176 -0
  100. package/dist/locales/fr.json +9176 -0
  101. package/dist/locales/ja.json +9023 -0
  102. package/dist/locales/ko.json +9023 -0
  103. package/dist/locales/pt-BR.json +9176 -0
  104. package/dist/locales/ru.json +9482 -0
  105. package/dist/locales/zh.json +9023 -0
  106. package/dist/penstock.js +1 -2102
  107. package/dist/web/assets/{AgentSettings-C-1YBic4.js → AgentSettings-C3Er_rlW.js} +1 -1
  108. package/dist/web/assets/{AgentsDialog-CSu8pyh7.js → AgentsDialog-Bo7kikb6.js} +1 -1
  109. package/dist/web/assets/BpmnCanvas-Dw5zgCN3.js +1905 -0
  110. package/dist/web/assets/BpmnDocument-CuU0biX9.js +24 -0
  111. package/dist/web/assets/{ConflictDialog-nygfF7Dn.js → ConflictDialog-GxZ-d8SK.js} +1 -1
  112. package/dist/web/assets/{DiffDocument-DUrje9io.js → DiffDocument-Bh3hFmmi.js} +1 -1
  113. package/dist/web/assets/{DmnDocument-fn7AH7P1.js → DmnDocument-C8HpJAcE.js} +9 -9
  114. package/dist/web/assets/{FormDocument-BbyRqjib.js → FormDocument-CH-4KB3x.js} +1 -1
  115. package/dist/web/assets/{FormStepView-BYRMBW0U.js → FormStepView-DraPVoAN.js} +1 -1
  116. package/dist/web/assets/GraphAwareLayoutService-C8J8YHJI.js +21 -0
  117. package/dist/web/assets/NewFileDialog-j09JqpPj.js +47 -0
  118. package/dist/web/assets/{QuickOpen-D-u9hdSt.js → QuickOpen-CeBhsCzA.js} +1 -1
  119. package/dist/web/assets/{ScriptPane-BQorfmyv.js → ScriptPane-DDikZDv6.js} +2 -2
  120. package/dist/web/assets/{ScriptRunDialog-DjBW0LRD.js → ScriptRunDialog-DdzJ0pvT.js} +1 -1
  121. package/dist/web/assets/{SettingsDialog-DvYUAKpH.js → SettingsDialog-JUc5zUR9.js} +1 -1
  122. package/dist/web/assets/{ShortcutsDialog-BQ5BYHj3.js → ShortcutsDialog-DECqWPNE.js} +1 -1
  123. package/dist/web/assets/{SourceDocument-BfHVXxuk.js → SourceDocument-X8ajUcxM.js} +1 -1
  124. package/dist/web/assets/{TextDocument-BPepqeGu.js → TextDocument-0z7qojAh.js} +1 -1
  125. package/dist/web/assets/{UnreadableFileLayer-D5B6nixz.js → UnreadableFileLayer-D3G59F4u.js} +1 -1
  126. package/dist/web/assets/{UploadDialog-BzIvQ1YS.js → UploadDialog-CiahYkTc.js} +1 -1
  127. package/dist/web/assets/apply-HqvoGwLE.js +1 -0
  128. package/dist/web/assets/{bpmnTheme-Divwrkjy.js → bpmnTheme-cOvp4qFc.js} +1 -1
  129. package/dist/web/assets/bridgeInstance-DQk-c8L1.js +850 -0
  130. package/dist/web/assets/{commands-N2yKHjf_.js → commands-nPznxvPp.js} +1 -1
  131. package/dist/web/assets/de-Dj813wjn.js +1 -0
  132. package/dist/web/assets/{dialog-DSf66Ory.js → dialog-CtGB1LHI.js} +1 -1
  133. package/dist/web/assets/{diff-DkfgVbKD.js → diff-NgYeO98t.js} +1 -1
  134. package/dist/web/assets/{documentBridge-DSWBQZRP.js → documentBridge-QW0IZ9Bq.js} +8 -8
  135. package/dist/web/assets/{documents-C4vr2KnQ.js → documents-KeXEdK1U.js} +1 -1
  136. package/dist/web/assets/{duplicate-C-AiqE1T.js → duplicate-DNPpPVse.js} +1 -1
  137. package/dist/web/assets/{engines-DG8KgTeX.js → engines-DU0BfbYM.js} +1 -1
  138. package/dist/web/assets/es-CyJDEw4H.js +1 -0
  139. package/dist/web/assets/{formChecks-B_ZFz9DR.js → formChecks-sU20kKkU.js} +1 -1
  140. package/dist/web/assets/fr-B1lqrd3d.js +1 -0
  141. package/dist/web/assets/frontend-caI7mOAL.js +1 -0
  142. package/dist/web/assets/{httpHost-Cll6HteE.js → httpHost-Dqit__mm.js} +1 -1
  143. package/dist/web/assets/{index.es-B0wi5_fv.js → index.es-BqVUpGyA.js} +1 -1
  144. package/dist/web/assets/{index.es-DQAdm_u9.js → index.es-DqkfrvWI.js} +1 -1
  145. package/dist/web/assets/{intelligence-glU4hcHy.js → intelligence-Ck_Q9upa.js} +1 -1
  146. package/dist/web/assets/ja-BUAM_DzQ.js +1 -0
  147. package/dist/web/assets/{jspdf.es.min-xdeBAA_m.js → jspdf.es.min-CM3S4IDt.js} +3 -3
  148. package/dist/web/assets/ko-7l4EjTF9.js +1 -0
  149. package/dist/web/assets/{lib-DJ1i09sd.js → lib-DAKOOgix.js} +1 -1
  150. package/dist/web/assets/{engine-BPUfS3r2.js → moddle-CGpeSs3G.js} +1 -1
  151. package/dist/web/assets/{platform-BS7bgwr3.js → platform-CkWAyNst.js} +1 -1
  152. package/dist/web/assets/preferences-nBrFGN89.js +1 -0
  153. package/dist/web/assets/pt-BR-CxxRL7kF.js +1 -0
  154. package/dist/web/assets/ru-C4gbkVXL.js +1 -0
  155. package/dist/web/assets/{run-Df8AD_as.js → run-B3YvrVeP.js} +1 -1
  156. package/dist/web/assets/{samples-chRLnLcq.js → samples-BVuIm-bu.js} +1 -1
  157. package/dist/web/assets/testCaseRuns-DYKnccnc.js +1 -0
  158. package/dist/web/assets/translator-B2N3PQBL.js +1 -0
  159. package/dist/web/assets/{ui-AICOEtWR.js → ui-3pEQJ50t.js} +1 -1
  160. package/dist/web/assets/{useTrace-B3gDUL0X.js → useTrace-BAXnn0Bt.js} +1 -1
  161. package/dist/web/assets/{web-BtxFF0jJ.js → web-B2zkonPE.js} +8 -8
  162. package/dist/web/assets/zh-DIYPlVjz.js +1 -0
  163. package/dist/web/index.html +20 -20
  164. package/package.json +4 -1
  165. package/dist/web/assets/BpmnCanvas-DnBLxMNQ.js +0 -1905
  166. package/dist/web/assets/BpmnDocument-BPpyqTzJ.js +0 -24
  167. package/dist/web/assets/GraphAwareLayoutService-BiLVDmB7.js +0 -21
  168. package/dist/web/assets/NewFileDialog-Ce_cTeOv.js +0 -34
  169. package/dist/web/assets/apply-B0vauBJn.js +0 -1
  170. package/dist/web/assets/bridgeInstance-D0bzpNGz.js +0 -600
  171. package/dist/web/assets/de-izeWpfua.js +0 -1
  172. package/dist/web/assets/es-CRMYEYWD.js +0 -1
  173. package/dist/web/assets/fr-8pTyPyAI.js +0 -1
  174. package/dist/web/assets/frontend-BLfXy4OQ.js +0 -1
  175. package/dist/web/assets/ja-I1fjeFMy.js +0 -1
  176. package/dist/web/assets/ko-CFd9C-RA.js +0 -1
  177. package/dist/web/assets/preferences-C_EXTz45.js +0 -1
  178. package/dist/web/assets/pt-BR-Dl_APu95.js +0 -1
  179. package/dist/web/assets/ru-_vhcOTod.js +0 -1
  180. package/dist/web/assets/testCaseRuns-DLEqANBi.js +0 -1
  181. package/dist/web/assets/translator-CS9eR0My.js +0 -1
  182. package/dist/web/assets/zh-Do_q1RZ2.js +0 -1
@@ -0,0 +1 @@
1
+ import{_ as e,a as t,b as n,c as r,d as i,g as a,i as o,l as s,n as c,s as l,u,v as d,y as f}from"./chunk-license-x3oHbKe2.js";import{r as p}from"./chunk-translator-BFUJmSkR.js";import{n as m}from"./chunk-features-BfRg2kR5.js";import{t as h}from"./chunk-table-CJtiXv0e.js";import{spawn as g}from"node:child_process";import{createInterface as _}from"node:readline/promises";function v(e){return e.ask?e.ask:async e=>{let t=_({input:process.stdin,output:process.stderr});try{return(await t.question(e)).trim()}finally{t.close()}}}function y(e){return e.say??(e=>process.stderr.write(`${e}\n`))}const b=/["\u0000-\u001f]/;function x(e,t=process.platform){let n;try{n=new URL(e).protocol}catch{return null}return n!==`http:`&&n!==`https:`||b.test(e)?null:t===`darwin`?{command:`open`,args:[e],verbatim:!1}:t===`win32`?{command:`cmd`,args:[`/c`,`start`,`""`,`"${e}"`],verbatim:!0}:{command:`xdg-open`,args:[e],verbatim:!1}}function S(e){let t=x(e);if(t)try{g(t.command,t.args,{stdio:`ignore`,detached:!0,windowsVerbatimArguments:t.verbatim}).unref()}catch{return}}function C(e){return e.interactive??(process.stdin.isTTY===!0&&process.stderr.isTTY===!0)}function w(){return[p(`app.cli.license.notInteractive`)]}async function T(e,t){let n=v(t),i=y(t);await f(e,t),i(p(`app.cli.license.codeOnItsWay`,{email:e}));let a=null;for(let e=0;e<3&&!a;e+=1){let e=await n(p(`app.cli.license.codeQuestion`));if(!e)return null;try{a=await r(e,t)}catch(e){if(!(e instanceof c))throw e;i(e.message)}}return a}async function E(e,t){let n=v(t),r=y(t),i=await T(e,t);if(!i)return{ok:!1,lines:[p(`app.cli.license.nothingChangedAgain`)]};let a=await s(i,t);for(;a.kind===`full`;){let e=(t.now??Date.now)();r(p(`app.cli.license.tooManyMachines`,{tier:o[a.key.tier],machines:a.activations.length}));let c=a.activations.map((t,n)=>({num:`${n+1}.`,machine:t.label,since:p(`app.cli.license.since`,{when:l(t.createdAt,e)})}));h(c,{columns:[{name:`num`,align:`right`,minWidth:2},{name:`machine`,minWidth:16},{name:`since`,minWidth:14}],headers:!1}).forEach(e=>r(` ${e}`));let u=await n(p(`app.cli.license.freeWhich`)),f=a.activations[Number(u)-1];if(!f)return{ok:!1,lines:[p(`app.cli.nothingChanged`)]};await d(a.key.key,f.id,t),a=await s(i,t)}return a.kind===`none`?{ok:!1,lines:[p(`app.cli.license.noneBought`,{email:e}),p(`app.cli.license.buyOrSignIn`)]}:{ok:!0,lines:[p(`app.cli.license.activeHere`,{tier:o[a.tier],again:a.reused?p(`app.cli.license.again`):``})]}}async function D(e,t={}){if(!C(t))return{ok:!1,lines:w()};try{let n=e[0]??await v(t)(p(`app.cli.license.emailQuestion`));return n?await E(n,t):{ok:!1,lines:[p(`app.cli.nothingChanged`)]}}catch(e){return N(e)}}async function O(t,r={}){let i=t[0]??`pro`;if(i!==`pro`&&i!==`team`)return{ok:!1,lines:[p(`app.cli.license.buyUsage`)]};if(!C(r))return{ok:!1,lines:w()};let a=y(r),s=r.wait??(e=>new Promise(t=>setTimeout(t,e)));try{let t=await u(r);if(t.source===`activation`&&t.tier===i)return{ok:!0,lines:[p(`app.cli.license.alreadyActive`,{tier:o[i]})]};let l=await n(i,void 0,r);(r.open??S)(l.url),a(p(`app.cli.license.checkoutOpen`,{tier:o[i]})),a(` ${l.url}`),a(p(`app.cli.license.waitingForPayment`));let d=(r.now??Date.now)()+36e5,f=0;for(;(r.now??Date.now)()<d;){let t;try{t=await e(l.secret,r),f=0}catch(e){if(e instanceof c||(f+=1)>5)throw e;await s(3e3);continue}if(t.status===`succeeded`){let e=t.email??await v(r)(p(`app.cli.license.paidEmailQuestion`));return a(p(`app.cli.license.paid`)),await E(e,r)}if(t.status===`failed`)return{ok:!1,lines:[p(`app.cli.license.paymentFailed`)]};if(t.status===`expired`)return{ok:!1,lines:[p(`app.cli.license.checkoutExpired`)]};await s(3e3)}return{ok:!1,lines:[p(`app.cli.license.stoppedWaiting`)]}}catch(e){return N(e)}}async function k(e={}){try{let t=await i(e);return t===`released`?{ok:!0,lines:[p(`app.cli.license.released`)]}:t===`cleared`?{ok:!0,lines:[p(`app.cli.license.cleared`)]}:{ok:!1,lines:[p(`app.cli.license.nothingToRelease`)]}}catch(e){return N(e)}}function A(e){let t=e.trialEndsAt?.slice(0,10);return e.source===`trial`&&t?{ok:!1,lines:[p(`app.cli.license.trial`,{left:/\d+ days? left/.exec(e.detail)?.[0]??p(`app.cli.license.running`),ends:t}),p(`app.cli.license.keyComesWithPurchase`),p(`app.cli.license.enterAKey`)]}:{ok:!1,lines:[p(`app.cli.license.noneOnThisMachine`,{trial:t?p(`app.cli.license.trialEnded`,{ends:t}):``}),p(`app.cli.license.orBuyOne`)]}}async function j(e,t){let n=await u(t);if(n.source!==`activation`)return A(n);if(!C(t))return{ok:!1,lines:w()};let r=e??await v(t)(p(`app.cli.license.emailQuestion`));if(!r)return{ok:!1,lines:[p(`app.cli.nothingChanged`)]};let i=await T(r,t);if(!i)return{ok:!1,lines:[p(`app.cli.license.nothingChangedAgain`)]};let s=await a(i,t);if(s.length===0)return{ok:!1,lines:[p(`app.cli.license.noneBought`,{email:r})]};let c=s.filter(e=>e.tier===`team`);return c.length===0?{ok:!1,lines:[p(`app.cli.license.teamOnly`),p(`app.cli.license.buyTeam`)]}:{ok:!0,lines:[...c.map(e=>`${o[e.tier].padEnd(5)} ${e.key}`),``,p(`app.cli.license.keepKeySecret`)]}}async function M(e,n={}){let[r,i]=e;try{switch(r){case`activate`:{if(!i)return{ok:!1,lines:[p(`app.cli.license.activateUsage`)]};await t(i,n);let e=await u(n);return{ok:!0,lines:[p(`app.cli.license.activeHerePlain`,{tier:o[e.tier]})]}}case`deactivate`:return await k(n);case`key`:return await j(i,n);case void 0:case`status`:{let e=await u(n),t=[{property:p(`app.cli.license.tierRow`),value:o[e.tier]},{property:p(`app.cli.license.statusRow`),value:e.detail}],r=h(t,{columns:[{name:`property`,header:p(`app.cli.header.property`),minWidth:10},{name:`value`,header:p(`app.cli.header.value`)}],headers:!1});if(e.tier===`free`||e.source===`trial`){r.push(``,p(`app.cli.license.buyAndSignIn`));let e=m();e&&r.push(e)}return{ok:!0,lines:r}}default:return{ok:!1,lines:[p(`app.cli.license.usage`)]}}}catch(e){return N(e)}}function N(e){return e instanceof c?{ok:!1,lines:[e.message]}:{ok:!1,lines:[p(`app.cli.license.serviceUnreachable`,{reason:e instanceof Error?e.message:String(e)})]}}export{M as licenseCommand,D as loginCommand,k as logoutCommand,O as upgradeCommand};
@@ -0,0 +1 @@
1
+ import{r as e}from"./chunk-translator-BFUJmSkR.js";const t=[/\b(?:sk|pk|rk)[-_][-_A-Za-z0-9]{12,}/g,/\b(?:xox[abprs]|ghp|gho|ghu|ghs|github_pat|glpat|AKIA|AIza)[-_A-Za-z0-9]{12,}/g,/\bnpm_[A-Za-z0-9]{20,}/g,/\bBearer\s+[A-Za-z0-9._~+/=-]{8,}/gi,/\b([A-Za-z0-9_]*(?:KEY|TOKEN|SECRET|PASSWORD|PASSWD|CREDENTIAL)[A-Za-z0-9_]*)["']?\s*[=:]\s*["']?\S+/gi,/\beyJ[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]*/g],n=[[/(:\/\/[^\s/:@]+:)[^\s/@]+@/g,`$1***@`],[/(authorization["']?\s*[:=]\s*)(?:basic|bearer)\s+\S+/gi,`$1***`]];function r(e){let r=e.replace(/[\u0000-\u0008\u000b-\u001f\u007f]+/g,` `);for(let[e,t]of n)r=r.replace(e,t);for(let e of t)r=r.replace(e,(e,t)=>typeof t==`string`&&/[=:]/.test(e)?`${t}=***`:`***`);return r}function i(e){return r(e).slice(0,200)}function a(e){return r(e).trim().slice(-200)}const o=`app.agent.exited`,s=`app.agent.installFailed`,c=`app.agent.npmMissing`,l=`app.agent.unpublished`,u=`app.agent.serviceExited`,d=`app.agent.serviceNotStarted`,f=/\bnpm (?:error|ERR!)|\b(?:ETARGET|E404|ENOTFOUND|EAI_AGAIN|ECONNREFUSED|ETIMEDOUT)\b/i,p=/\bETARGET\b|\bE404\b|No matching version found/i,m=/\bneeds Node\.js\b|\bnot recognized as an internal or external command\b|\b(?:npm|npx|node): (?:command )?not found\b|\bcommand not found: (?:npm|npx|node)\b/i,h=/* @__PURE__ */ new Set([o,s,c,l,u,d]);function g(e){return f.test(e)?s:o}function _(e){return p.test(e)?l:m.test(e)?c:f.test(e)?s:u}function v(e){return e!==0}function y(t){switch(t.kind){case`timeout`:return{key:`app.agent.timeout`,detail:``};case`spawn`:return{key:t.code===`ENOENT`?c:d,detail:a(t.message)};case`exited`:{let n=t.code===null?`signal ${t.signal??`unknown`}`:e(`app.agent.exitCode`,{code:t.code}),r=a(t.tail);return{key:_(t.tail),detail:r===``?n:`${n}: ${r}`}}}}function b(e){return h.has(e)}function x(t){return b(t.key)?e(t.key):e(t.key,{detail:t.detail})}export{y as a,x as i,v as n,i as o,g as r,l as t};
@@ -0,0 +1 @@
1
+ import{r as e}from"./chunk-translator-BFUJmSkR.js";import{H as t,Z as n,c as r,k as i,n as a,q as o,r as s}from"./chunk-mcpLaunch-C13ViiIP.js";import{r as c}from"./chunk-failure-BsimkHy_.js";import{o as l}from"./chunk-load-BVJUBU5S.js";import u from"node:path";import{constants as d,tmpdir as f}from"node:os";import{existsSync as p,mkdirSync as m,mkdtempSync as h,readFileSync as g,readdirSync as _,realpathSync as v,rmSync as y,statSync as b,writeFileSync as x}from"node:fs";import{spawn as S}from"node:child_process";import{randomBytes as C}from"node:crypto";const w=/^[a-z]+-(\d+)-[0-9a-f]{8}\.json$/;function T(e){return u.join(e,s.directory)}function E(e,t,n){let r=T(e);m(r,{recursive:!0,mode:448});let i=u.join(r,`${t}-${process.pid}-${C(4).toString(`hex`)}.json`);return x(i,n,{mode:384,flag:`wx`}),{file:i,remove:()=>y(i,{force:!0})}}function D(e){let t=T(e),n;try{n=_(t)}catch{return}for(let e of n){let n=w.exec(e);n&&!r(Number(n[1]))&&y(u.join(t,e),{force:!0})}}const O=[`claude`,`codex`,`gemini`,`opencode`],k=/^[A-Za-z0-9_-]+$/;function A(e){let t=(e.split(/[\\/]/).pop()??``).replace(/\.(exe|cmd|bat|com)$/i,``).toLowerCase();return O.find(e=>e===t)??`other`}function j(e,t,n){let r={...e.env};return typeof n.PENSTOCK_HOME==`string`&&n.PENSTOCK_HOME!==``&&(r.PENSTOCK_HOME=n.PENSTOCK_HOME),{command:e.command,args:[...e.args,`--project`,t],env:r}}function M(e){return k.test(e)?e:JSON.stringify(e)}function N(e){return`{${Object.entries(e).map(([e,t])=>`${M(e)}=${JSON.stringify(t)}`).join(`,`)}}`}function P(e){return JSON.stringify({mcpServers:{penstock:{type:`stdio`,command:e.command,args:e.args,env:e.env}}})}function F(e){let t=[`mcp_servers.penstock.command=${JSON.stringify(e.command)}`,`mcp_servers.penstock.args=${JSON.stringify(e.args)}`];return Object.keys(e.env).length>0&&t.push(`mcp_servers.penstock.env=${N(e.env)}`),t.flatMap(e=>[`-c`,e])}function I(e){if(e===void 0||e.trim()===``)return{};try{let t=JSON.parse(e);return typeof t==`object`&&t&&!Array.isArray(t)?t:{}}catch{return{}}}function L(e){return typeof e==`object`&&e&&!Array.isArray(e)?e:{}}function R(e,t){let n=I(t),r={type:`local`,command:[e.command,...e.args],enabled:!0};return Object.keys(e.env).length>0&&(r.environment=e.env),JSON.stringify({...n,mcp:{...L(n.mcp),penstock:r}})}function z(e,t){let n=I(t),r={command:e.command,args:e.args};return Object.keys(e.env).length>0&&(r.env=e.env),JSON.stringify({...n,mcpServers:{...L(n.mcpServers),penstock:r}})}function B(e){if(e!==void 0&&e!==``)try{return g(e,`utf8`)}catch{return}}function V(e,t,n,r,i,a){let o=()=>void 0;switch(e){case`claude`:{let e=E(a,`mcp`,P(t));return{args:[...i.args,...n,`--mcp-config`,e.file],env:i.env,cleanup:e.remove}}case`codex`:return{args:[...F(t),...i.args,...n],env:i.env,cleanup:o};case`opencode`:return{args:[...i.args,...n],env:{...i.env,OPENCODE_CONFIG_CONTENT:R(t,r.OPENCODE_CONFIG_CONTENT)},cleanup:o};case`gemini`:{let e=h(u.join(f(),`penstock-agent-`)),a=u.join(e,`settings.json`);return x(a,z(t,B(r.GEMINI_CLI_SYSTEM_SETTINGS_PATH)),{mode:384}),{args:[...i.args,...n],env:{...i.env,GEMINI_CLI_SYSTEM_SETTINGS_PATH:a},cleanup:()=>y(e,{recursive:!0,force:!0})}}default:return{args:[...i.args,...n],env:{...i.env,PENSTOCK_MCP_CONFIG:JSON.stringify({mcpServers:{penstock:{command:t.command,args:t.args,env:t.env}}})},cleanup:o}}}function H(n){let r=[...t().map(e=>({id:e.id,name:e.name,found:o(e.binary,n.env,n.cwd)!==null,install:e.install})),...i(n.home).map(e=>({id:e.id,name:e.name,found:o(e.command,n.env,n.cwd)!==null,install:null}))],a=Math.max(...r.map(e=>e.id.length)),s=r.map(t=>{let n=t.found?e(`app.cli.agentLaunch.installed`):t.install?e(`app.cli.agentLaunch.missing`,{install:t.install}):e(`app.cli.agentLaunch.notFound`);return` ${t.id.padEnd(a)} ${t.name}: ${n}`});return{ok:!0,lines:[e(`app.cli.agentLaunch.heading`),...s,``,e(`app.cli.agentLaunch.how`)]}}function U(...e){return{ok:!1,lines:e,code:1}}function W(t){let n=u.resolve(t);return p(n)?b(n).isDirectory()?v(n):U(e(`app.cli.web.notAFolder`,{folder:n})):U(c(n))}function G(e,t){return e===null?128+((t===null?void 0:d.signals[t])??1):e}function K(e,t,n){return new Promise(r=>{let i=S(e.command,e.args,{cwd:n,env:t,stdio:`inherit`,windowsVerbatimArguments:e.verbatim}),a=e=>()=>{i.kill(e)},o=[[`SIGTERM`,a(`SIGTERM`)],[`SIGHUP`,a(`SIGHUP`)],[`SIGINT`,()=>void 0]];for(let[e,t]of o)process.on(e,t);let s=()=>{for(let[e,t]of o)process.off(e,t)};i.once(`error`,e=>{s(),r({failure:e.message})}),i.once(`close`,(e,t)=>{s(),r({code:G(e,t)})})})}async function q(r){if(r.agent===void 0)return H(r);let s=r.agent,c=t().find(e=>e.id===s),u=c?void 0:i(r.home).find(e=>e.id===s);if(!c&&!u){let n=[...t().map(e=>e.id),...i(r.home).map(e=>e.id)].join(`, `);return U(e(`app.cli.agentLaunch.unknown`,{agent:s,list:n}))}let d=c?.name??u?.name??s,f=c?c.binary:u?.command,p=o(f,r.env,r.cwd);if(p===null)return U(c?e(`app.cli.agentLaunch.notInstalled`,{name:d,install:c.install}):e(`app.cli.agentLaunch.commandMissing`,{name:d,command:f}));let m=r.cwd,h;if(r.project!==void 0){let e=W(r.project);if(typeof e!=`string`)return e;m=e,h=e}else h=v(l(r.cwd));let g=r.mcp===void 0?a():r.mcp;if(g===null)return U(e(`app.cli.agentLaunch.noMcp`));let _=j(g,h,r.env),y=c?c.id:A(f);y===`other`&&process.stderr.write(`${e(`app.cli.agentLaunch.customNote`,{name:d})}\n`);let b;try{D(r.home),b=V(y,_,r.passthrough,r.env,{args:u?.args??[],env:u?.env??{}},r.home)}catch(t){return U(e(`app.cli.agentLaunch.cannotPrepare`,{reason:t instanceof Error?t.message:String(t)}))}let x;try{x=n({command:p,args:b.args})}catch{return b.cleanup(),U(e(`app.cli.agentLaunch.unsafeArguments`,{name:d}))}try{let t=await K(x,{...r.env,...b.env},m);return`failure`in t?U(e(`app.cli.agentLaunch.cannotStart`,{name:d,reason:t.failure})):{ok:t.code===0,lines:[],code:t.code}}finally{b.cleanup()}}function J(e){let t=e.indexOf(`--`);return t<0?[]:e.slice(t+1)}export{q as launchAgent,J as passthroughOf};
@@ -0,0 +1,10 @@
1
+ import{n as e}from"./chunk-version-CdS8_QQd.js";import{t}from"./chunk-atomicWrite-C6J1gDtO.js";import{u as n}from"./chunk-license-x3oHbKe2.js";import{r}from"./chunk-translator-BFUJmSkR.js";import{s as i,t as a}from"./chunk-features-BfRg2kR5.js";import{r as o,t as s}from"./chunk-preferencesFile-F6bAlNrk.js";import{A as c,B as l,C as u,D as ee,E as d,I as f,M as p,R as m,S as h,V as g,X as _,_ as v,a as y,b,c as x,d as te,f as S,g as C,h as w,l as ne,m as T,n as re,o as ie,p as E,r as D,s as O,t as k,u as A,v as ae,w as oe,x as j,y as se,z as ce}from"./chunk-mcpLaunch-C13ViiIP.js";import{o as M,r as le}from"./chunk-agentFailure-piRAFLGH.js";import{A as ue,C as de,D as fe,F as pe,I as me,M as he,N,O as P,P as F,S as ge,T as _e,_ as I,a as ve,b as ye,d as be,g as L,h as xe,j as Se,k as Ce,l as we,s as Te,v as Ee,w as R,y as De}from"./chunk-security-5SU-bq3A.js";import{r as Oe}from"./chunk-failure-BsimkHy_.js";import{r as ke}from"./chunk-editPreview-BgH1JVOD.js";import z from"node:path";import{mkdirSync as Ae,readFileSync as B,rmSync as V,statSync as H}from"node:fs";import{execFileSync as je,spawn as Me}from"node:child_process";import{randomBytes as Ne}from"node:crypto";import{createServer as Pe}from"node:http";import{RequestError as U}from"@agentclientprotocol/sdk";function W(e,t){return y(e,t).replace(/\.json$/,`.children.json`)}function Fe(e){return Array.isArray(e)?e.filter(e=>{let t=e;return typeof t==`object`&&!!t&&Number.isInteger(t.pid)&&(t.pid??0)>0&&typeof t.command==`string`&&t.command!==``}):[]}function G(e){try{return Fe(JSON.parse(B(e,`utf8`)))}catch{return[]}}function K(e,n){n.length===0?V(e,{force:!0}):(Ae(z.dirname(e),{recursive:!0,mode:448}),t(e,`${JSON.stringify(n)}\n`,384))}function Ie(e,t,n){let r=W(e,t);K(r,[...G(r).filter(e=>e.pid!==n.pid),n])}function Le(e,t,n){let r=W(e,t);K(r,G(r).filter(e=>e.pid!==n))}function Re(e){if(process.platform===`win32`)return null;try{return je(`ps`,[`-o`,`command=`,`-p`,String(e)],{encoding:`utf8`,stdio:[`ignore`,`pipe`,`ignore`]}).trim()}catch{return null}}async function ze(e,t){let n=W(e,t),r=G(n).filter(e=>x(e.pid)&&Re(e.pid)?.includes(e.command));V(n,{force:!0});for(let e of r)A(e.pid,`SIGTERM`);if(r.length!==0){await new Promise(e=>setTimeout(e,1e3));for(let e of r)x(e.pid)&&A(e.pid,`SIGKILL`)}}var Be=class{graceMs;holds=0;attendedAt;idleAt;constructor(e,t){this.graceMs=e,this.attendedAt=t,this.idleAt=t}hold(e){this.holds+=1,this.touch(e);let t=!0;return e=>{t&&(t=!1,--this.holds,this.touch(e))}}tick(e,t,n){let r=this.holds>0;return r&&this.touch(e),t&&(this.idleAt=e),{unattended:!r&&e-this.attendedAt>=this.graceMs,leave:n?!t:!r&&e-this.idleAt>=this.graceMs}}touch(e){this.attendedAt=e,this.idleAt=e}};const q={required:[`file`],allowed:[`file`]},Ve={required:[`file`,`element`],allowed:[`file`,`element`]},He={required:[],allowed:[`project`]},Ue={list_diagrams:He,show_diagram:q,element_context:Ve,check_diagram:q,analyze_flow:q,list_scenarios:q,check_code_links:He,search_elements:{required:[`query`],allowed:[`query`,`project`]},diff_diagrams:{required:[`file`],allowed:[`file`,`other`,`ref`]}},We=Object.keys(Ue),Ge=[`file`,`operations`,`dryRun`],Ke=/* @__PURE__ */ new Set([`edit`,`delete`,`move`]),qe=/* @__PURE__ */ new Set([`read`,`search`,`other`]),Je=/* @__PURE__ */ new Set([`allowAlways`,`rejectAlways`]);function Ye(e,t){return RegExp(`(?:^|[^a-z0-9_]|__|penstock_)${t}(?![a-z0-9_])`,`i`).test(e.title)}function Xe(e,t){return RegExp(`^\\s*(?:tool:\\s*)?(?:mcp__penstock__|penstock(?:[_/:.]|\\s*[:/]\\s*))${t}\\s*$`,`i`).test(e.title)}function Ze(e){return Ye(e,`edit_diagram`)}function Qe(e,t){let n=t=>t.every(t=>typeof e[t]==`string`&&e[t]!==``);return Object.keys(e).every(e=>t.allowed.includes(e))&&n(t.required)&&n(Object.keys(e))}function $e(e,t){if(!qe.has(e.kind)||e.diffs.length>0)return!1;let n=We.find(t=>Xe(e,t));if(n===void 0)return!1;let r=rt(t);return r!==null&&Qe(r,Ue[n])}function et(e){return Ke.has(e.kind)||e.diffs.length>0||Ze(e)}function tt(e){return{...e,options:e.options.filter(e=>!Je.has(e.kind))}}function nt(e){return e.options.find(e=>e.kind===`allow`)?.id??null}function rt(e){let t=e;if(typeof t==`string`)try{t=JSON.parse(t)}catch{return null}return typeof t==`object`&&t&&!Array.isArray(t)?t:null}function it(e,t){if(!Xe(e,`edit_diagram`)||e.diffs.length>0)return!1;let n=rt(t);return n===null||n.dryRun!==!0||!Object.keys(n).every(e=>Ge.includes(e))?!1:typeof n.file==`string`&&n.file!==``&&n.operations!==void 0}function at(e){let t=e;if(typeof t==`string`)try{t=JSON.parse(t)}catch{return null}if(typeof t!=`object`||!t)return null;let n=t;return typeof n.file!=`string`||n.file===``||n.operations===void 0?null:{file:n.file,operations:n.operations}}const ot=2e5,J=8388608,st=16777216,Y=-32602,X=-32603,Z={outcome:{outcome:`cancelled`}},ct=`app.agent.authRequired`;function lt(e,t){let n=e instanceof U?e.data:null,r=[n?.message,n?.details].find(e=>typeof e==`string`&&e.trim()!==``);return r&&!t.includes(r)?`${t}: ${r}`:t}function ut(e){if(!(e instanceof U))return``;let t=([e.data?.message,e.message].find(e=>typeof e==`string`&&e.trim()!==``)??``).split(/\r?\n/).map(e=>e.trim()).find(e=>e!==``)??``;return M(Array.from(t).slice(0,300).join(``))}function dt(e,t,n,r){if(e instanceof ue)return{key:le(e.tail),detail:e.tail===``?e.how:`${e.how}: ${e.tail}`};if(e instanceof N)return{key:`app.agent.timeout`,detail:``};if(F(e))return{key:ct,detail:ut(e),signIn:r};let i=e?.code;if(e instanceof he||i===`ENOENT`||i===`EACCES`)return{key:`app.agent.notFound`,detail:p(n,t)??``};if(e instanceof _)return{key:`app.agent.unsafe`,detail:``};let a=e instanceof Error?e.message:String(e);return{key:`app.agent.failed`,detail:M(lt(e,a))}}function ft(){return Ne(9).toString(`base64url`)}var pt=class{host;timings;store;feed;chats=/* @__PURE__ */ new Map;processes=/* @__PURE__ */ new Map;live=/* @__PURE__ */ new Set;started=/* @__PURE__ */ new Map;owners=/* @__PURE__ */ new Map;offered=/* @__PURE__ */ new Map;dirty=/* @__PURE__ */ new Map;unsaved=/* @__PURE__ */ new Set;flushTimer=null;saveTimer=null;watcher=null;asked=0;on=!0;retiring=!1;checkedAt=0;disposed=!1;constructor(e,t={}){this.host=e,this.timings={connectMs:t.connectMs??3e4,flushMs:t.flushMs??40,killMs:t.killMs??2e3,stopMs:t.stopMs??1e4,saveMs:t.saveMs??400,prefsMs:t.prefsMs??1e3,watchMs:t.watchMs??1e3,signInMs:t.signInMs??3e5},this.store=new w(e.home,e.folder);for(let e of this.store.load())this.chats.set(e.id,C.from(e));this.feed=new fe(()=>this.replay(),t.feed),this.on=this.readEnabled()}enabled(){return this.refresh(!1),this.on}refresh(e=!0){if(this.disposed)return;let t=Date.now();if(!e&&t-this.checkedAt<this.timings.prefsMs)return;this.checkedAt=t;let n=this.readEnabled();n!==this.on&&(this.on=n,n||this.shutDown(),this.publish({type:`enabled`,enabled:n}),this.publishChats())}busy(){for(let e of this.chats.values())if(e.turn!==null||e.questions.length>0||e.queue.length>0)return!0;return!1}retire(){return this.retiring=!0,this.busy()}drained(){return Promise.all([...this.live].map(e=>e.exited(this.timings.killMs*2))).then(()=>void 0)}cancelUnanswered(){for(let e of this.chats.values()){if(e.questions.length===0)continue;let t=e.transcript.notice(r(`app.agent.unanswered`));this.publish(this.entryEvent(e,t)),this.touch(e),this.halt(e)}}stopQuiet(e){let t=performance.now();for(let n of this.chats.values()){let i=n.turn;if(!i||i.stopping||n.questions.length>0||t-i.heard<e)continue;let a=n.transcript.notice(r(`app.agent.quiet`));this.publish(this.entryEvent(n,a)),this.touch(n),this.halt(n)}}catalog(){return Ce({home:this.host.home,env:this.host.env,folder:this.host.folder,version:this.host.version})}choices(){return this.installed().map(e=>({...e,options:this.cached(e.id)}))}installed(){return ee(this.host.env,this.host.home,this.host.folder)}cached(e){let t=this.offered.get(e)??pe(this.host.home,e)?.options;if(!t)return[];let n=l(this.host.home,e);return t.map(e=>{let t=j.includes(e.category)?n[e.category]:void 0;return h(t!==void 0&&u(e,t)?{...e,current:t}:e)})}list(){let e=this.enabled();return e?{chats:this.dtos(),enabled:e}:{chats:[],enabled:e}}create(e){this.requireOn(),this.requireFree();let t=this.installed();if(e!==null&&!t.some(t=>t.id===e))throw E(404,`app.agent.reason.unknownAgent`,{agent:e.slice(0,80)});let n=e??c(t,this.host.home)??g(this.host.home)??t[0]?.id??`claude`,r=new C(ft(),n,Date.now());return this.chats.set(r.id,r),this.publishChats(),r.dto()}get(e){this.requireOn();let t=this.chat(e);return this.shown(t),t.describe()}rename(e,t){this.requireOn();let n=this.chat(e),r=t.replace(/[\u0000-\u001f\u007f]+/g,` `).trim();if(r===``||Array.from(r).length>120)throw E(400,`app.agent.reason.badTitle`,{limit:120});return n.title=r,this.touch(n),this.publishChats(),n.dto()}remove(e){this.requireOn();let t=this.chat(e);this.forget(t);try{this.store.remove(e)}catch(t){console.warn(r(`app.agent.log.notKept`,{id:e,reason:t instanceof Error?t.message:String(t)}))}this.publishChats()}async prompt(e,t,n=null){this.requireOn(),this.requireFree();let r=this.chat(e),i=t.trim();if(i===``||i.length>ot)throw E(400,`app.agent.reason.badText`,{limit:ot});if(await this.requireLicence(),this.requireOn(),this.requireFree(),this.chats.get(e)!==r)throw E(404,`app.agent.reason.noSuchChat`);let a=this.contextOf(n);if(this.remember(r,this.contextFile(n)),r.turn!==null||r.queue.length>0){if(r.queue.length>=20)throw E(409,`app.agent.reason.queueFull`,{limit:20});let e={id:ft(),text:i,context:a};return r.queue.push(e),this.watch(),this.publish({type:`queue`,chatId:r.id,queue:this.queueOf(r)}),this.drainSoon(r),{queued:!0,queueId:e.id}}return this.begin(r,i,a),{queued:!1,queueId:null}}unqueue(e,t){this.requireOn();let n=this.chat(e),r=n.queue.findIndex(e=>e.id===t);if(r<0)throw E(404,`app.agent.reason.noSuchQueued`);n.queue.splice(r,1),this.publish({type:`queue`,chatId:n.id,queue:this.queueOf(n)})}stop(e){this.requireOn(),this.halt(this.chat(e))}async signIn(e){this.requireOn();let t=this.chat(e),n=t.failure;if(t.turn!==null||n?.key!==ct||n.signIn!==!0)throw E(409,`app.agent.reason.noSignIn`);if(await this.requireLicence(),this.requireOn(),this.chats.get(e)!==t)throw E(404,`app.agent.reason.noSuchChat`);try{let e=await this.processOf(t.agentId),n=e.signInMethods[0];if(n===void 0)throw E(409,`app.agent.reason.noSignIn`);await e.authenticate(n,this.timings.signInMs)}catch(e){throw e instanceof S?e:this.signInFailure(e,t.agentId)}this.chats.get(e)===t&&t.failure===n&&(t.failure=null,this.touch(t),this.publish({type:`error`,chatId:t.id,error:null}),this.publishChats())}signInFailure(e,t){return e instanceof U?E(502,`app.agent.reason.signInRefused`,{reason:ut(e)}):T(e instanceof N?504:500,dt(e,this.host.home,t,!1))}answer(e,t,n){this.requireOn();let r=this.chat(e),i=r.questions[0];if(!i||i.permission.id!==t)throw E(409,`app.agent.reason.staleQuestion`);let a=i.permission.options.find(e=>e.id===n);if(!a)throw E(409,`app.agent.reason.badOption`,{option:n.slice(0,80)});r.questions.shift(),i.grants&&a.kind===`allow`&&this.grant(r,i.permission.tool),i.resolve(n),this.publish({type:`permission`,chatId:r.id,permission:r.questions[0]?.permission??null}),this.publishChats()}next(e,t){return this.refresh(!1),this.watch(),this.feed.next(e,t)}dispose(){if(!this.disposed){this.disposed=!0,this.watcher&&clearInterval(this.watcher),this.watcher=null,this.flush(),this.saveAll();for(let e of this.chats.values()){for(let t of e.questions.splice(0))t.resolve(null);e.turn?.stopping&&clearTimeout(e.turn.stopping)}this.shutDown(),this.saveAll(),this.feed.close()}}readEnabled(){try{return new s(this.host.home).aiChat()!==`off`}catch{return!0}}requireOn(){if(!this.enabled())throw E(409,`app.agent.reason.off`)}requireFree(){if(this.retiring)throw E(409,`app.agent.retiring`)}async requireLicence(){let e={env:this.host.env},t=await n(e);if(!(this.host.licensed?await this.host.licensed():a(t,e)))throw new S(402,i(t,`ai-chat`,e).join(`
2
+ `))}chat(e){let t=this.chats.get(e);if(!t)throw E(404,`app.agent.reason.noSuchChat`);return t}forget(e){this.abandon(e),this.chats.delete(e.id),this.unsaved.delete(e),this.dirty.delete(e);for(let t of this.owners.values())e.sessionId&&t.delete(e.sessionId)}watch(){this.watcher||this.disposed||(this.watcher=setInterval(()=>this.tick(),this.timings.watchMs),this.watcher.unref())}tick(){if(!this.disposed&&(this.refresh(!1),this.on))for(let e of this.chats.values())e.queue.length>0&&e.turn===null&&this.drainSoon(e)}dtos(){return[...this.chats.values()].sort((e,t)=>t.updated-e.updated).map(e=>e.dto())}entryEvent(e,t){if(t.kind===`tool`)for(let n of t.tool.paths)this.remember(e,n);return t.kind===`tool`?{type:`tool`,chatId:e.id,tool:t.tool}:t.kind===`plan`?{type:`plan`,chatId:e.id,items:t.items}:{type:`entry`,chatId:e.id,entry:v(t)}}replay(){return[{type:`sync`},this.chatsEvent()]}chatsEvent(){let e=this.on;return{type:`chats`,chats:e?this.dtos():[],enabled:e}}publishChats(){this.flush(),this.feed.publish(this.chatsEvent())}publish(e){this.flush(),this.feed.publish(e)}queueOf(e){return e.queue.map(e=>({id:e.id,text:e.text}))}contextFile(e){if(!e||typeof e.file!=`string`||e.file===``)return null;try{return this.host.files.relative(this.host.files.resolve(e.file))}catch{return null}}remember(e,t){t!==null&&e.addFile(t)&&(this.markUnsaved(e),this.publishChats())}contextOf(e){if(!e)return null;let t=[],n=this.contextFile(e);n!==null&&t.push(r(`app.agent.contextFile`,{file:n}));let i=(e.elementIds??[]).filter(e=>typeof e==`string`&&e!==``&&e.length<=200).slice(0,50);return i.length>0&&t.push(r(`app.agent.contextElements`,{elements:i.join(`, `)})),t.length>0?t.join(`
3
+ `):null}touch(e){e.updated=Date.now(),this.markUnsaved(e)}markUnsaved(e){e.worth&&(this.unsaved.add(e),!(this.saveTimer||this.disposed)&&(this.saveTimer=setTimeout(()=>{this.saveTimer=null,this.saveAll()},this.timings.saveMs),this.saveTimer.unref()))}saveAll(){this.saveTimer&&clearTimeout(this.saveTimer),this.saveTimer=null;let e=[...this.unsaved];this.unsaved.clear();for(let t of e)this.chats.get(t.id)===t&&this.persist(t)}persist(e){try{let t=this.store.save(e.stored());e.turn===null&&t.entries.length!==e.transcript.list().length&&e.transcript.restore(t.entries)}catch(t){console.warn(r(`app.agent.log.notKept`,{id:e.id,reason:t instanceof Error?t.message:String(t)}))}}begin(e,t,n){e.turns+=1;let r={id:e.turns,cancelled:!1,stopping:null,heard:performance.now()};e.turn=r,e.failure=null,e.connecting=!0,e.grants=/* @__PURE__ */ new Map;let i=e.transcript.message(`user`,t,`user-${r.id}`);e.transcript.closeMessage(),e.title===null&&(e.title=ae(t)),this.touch(e),this.saveAll(),this.publish(this.entryEvent(e,i)),this.publishChats(),this.run(e,r,t,n)}async run(e,t,n,i){let a=null,o=`end_turn`;try{let a=await this.processOf(e.agentId);if(t.cancelled||e.turn!==t)return;let s=await this.sessionOf(e,a);if(t.cancelled||e.turn!==t)return;e.connecting=!1,this.publishChats();let c=[i,e.briefed===s?null:r(`app.agent.contextLinks`)].filter(e=>e!==null).join(`
4
+ `);e.briefed=s;let l=[{type:`text`,text:n},...c?[{type:`text`,text:c}]:[]];o=await a.prompt(s,l),await new Promise(e=>setImmediate(e))}catch(n){if(t.cancelled||e.turn!==t)return;let r=e.process,i=!(n instanceof U)&&!(n instanceof N);if(i&&r&&await r.exited(this.timings.killMs),t.cancelled||e.turn!==t)return;if(r?.killedByUs){e.process=null,this.release(r),this.stoppedBy(e,t);return}a=dt(i&&r?.exitCause?r.exitCause:n,this.host.home,e.agentId,(r?.signInMethods.length??0)>0)}this.finish(e,t,a,o)}finish(e,t,n,r){if(e.turn===t){if(this.flush(),t.stopping&&clearTimeout(t.stopping),this.settleQuestions(e),e.turn=null,e.connecting=!1,e.failure=n,e.grants=/* @__PURE__ */ new Map,n)for(let t of e.transcript.failRunning())this.publish({type:`tool`,chatId:e.id,tool:t});else if(r===`cancelled`)for(let t of e.transcript.stopRunning())this.publish({type:`tool`,chatId:e.id,tool:t});this.touch(e),this.saveAll(),n&&this.publish({type:`error`,chatId:e.id,error:n}),this.publishChats(),this.afterTurn(e)}}afterTurn(e){e.wanted.size===0||!e.process?.alive?this.drainSoon(e):this.settle(e,!1).catch(()=>void 0).finally(()=>this.drainSoon(e))}drainSoon(e){e.queue.length!==0&&setImmediate(()=>{if(this.disposed||!this.on||e.turn||this.chats.get(e.id)!==e)return;let t=e.queue.shift();t&&(this.publish({type:`queue`,chatId:e.id,queue:this.queueOf(e)}),this.begin(e,t.text,t.context))})}settleQuestions(e){if(e.questions.length!==0){for(let t of e.questions.splice(0))t.resolve(null);this.publish({type:`permission`,chatId:e.id,permission:null})}}halt(e){this.settleQuestions(e);let t=e.turn;if(!t)return;if(e.connecting){t.cancelled=!0,e.turn=null,e.connecting=!1,this.touch(e),this.saveAll(),this.publishChats(),this.drainSoon(e);return}let n=e.process;n&&e.sessionId&&n.cancel(e.sessionId),!t.stopping&&(t.stopping=setTimeout(()=>{e.turn===t&&n&&(this.othersWorking(e)?this.stoppedBy(e,t,`app.agent.stopped`):(this.release(n),n.kill(!0)))},this.timings.stopMs),t.stopping.unref())}othersWorking(e){for(let t of this.chats.values())if(t!==e&&t.agentId===e.agentId&&t.turn!==null)return!0;return!1}abandon(e){this.settleQuestions(e);let t=e.turn;t&&(t.cancelled=!0,t.stopping&&clearTimeout(t.stopping),e.turn=null,e.process&&e.sessionId&&e.process.cancel(e.sessionId))}shutDown(){for(let e of this.chats.values()){this.settleQuestions(e);let t=e.turn;if(t){t.cancelled=!0,t.stopping&&clearTimeout(t.stopping),e.turn=null,e.connecting=!1;for(let t of e.transcript.stopRunning())this.publish({type:`tool`,chatId:e.id,tool:t});e.transcript.notice(r(`app.agent.stopped`)),this.touch(e)}e.queue=[]}for(let e of[...this.live])e.kill(!0);this.processes.clear(),this.started.clear()}processOf(e){let t=this.processes.get(e);if(t)return t;let n={update:e=>this.update(e),permission:(e,t)=>this.requestPermission(e,t),read:e=>this.readText(e),write:e=>this.writeText(e),gone:(e,t,n,r)=>this.gone(e,t,n,r)},r=(async()=>{let t=f(e,this.host.env,this.host.home,this.host.folder);if(!t)throw new he;let r=await Se.launch(t,{folder:this.host.folder,env:this.host.env,version:this.host.version,connectMs:this.timings.connectMs,killMs:this.timings.killMs},n);if(this.disposed||!this.on)throw r.kill(!0),Error(`closed`);return this.live.add(r),this.started.set(e,r),this.owners.set(r,/* @__PURE__ */ new Map),r.pid!==void 0&&Ie(this.host.home,this.host.folder,{pid:r.pid,command:r.command}),r})();return this.processes.set(e,r),r.catch(()=>{this.processes.get(e)===r&&this.processes.delete(e)}),r}mcpServers(){let e=this.host.mcp;return e?[{name:`penstock`,command:e.command,args:[...e.args,`--project`,this.host.folder],env:Object.entries(e.env??{}).map(([e,t])=>({name:e,value:t}))}]:[]}async sessionOf(e,t){let n=this.owners.get(t);if(e.process=t,e.sessionId&&n?.get(e.sessionId)===e)return e.sessionId;let i=e.sessionId;if(i&&t.loadSession){e.fenced=!0,n?.set(i,e);try{let n=await t.loadSessionById(i,this.host.folder,this.mcpServers());return this.offer(e,n),await this.settle(e,!1),i}catch(e){if(n?.delete(i),F(e)||e instanceof N)throw e}finally{e.fenced=!1}}let a=await t.newSession(this.host.folder,this.mcpServers());if(e.sessionId=a.sessionId,n?.set(a.sessionId,e),this.offered.set(e.agentId,a.options),this.offer(e,a.options),await this.settle(e,!0),i!==null){let t=e.transcript.notice(r(`app.agent.newSession`));this.publish(this.entryEvent(e,t))}return g(this.host.home)!==e.agentId&&m(this.host.home,e.agentId),this.markUnsaved(e),a.sessionId}offer(e,t){(t.length!==0||e.options.length!==0)&&(e.options=t,me(this.host.home,e.agentId,t),this.publishOptions(e))}publishOptions(e){this.publish({type:`options`,chatId:e.id,options:e.shownOptions()}),this.markUnsaved(e)}desired(e,t){let n=/* @__PURE__ */ new Map,r=t?l(this.host.home,e.agentId):{};for(let t of e.options){let i=e.wanted.get(t.id)??(j.includes(t.category)?r[t.category]:void 0);i!==void 0&&i!==t.current&&u(t,i)&&n.set(t.id,i)}return n}settle(e,t){let n=e.configured.then(async()=>{let n=e.process,r=e.sessionId;if(n&&n.alive&&r)for(let i of d(e.options)){let a=this.desired(e,t).get(i.id);if(a===void 0)continue;let o=e.options.find(e=>e.id===i.id);if(o)try{await this.change(e,n,r,o,a)}catch(t){if(F(t))throw t;e.wanted.delete(i.id)}}});return e.configured=n.catch(()=>void 0),n}async change(e,t,n,r,i){let a=await t.setOption(n,r,i);e.sessionId===n&&(e.options=a===null?e.options.map(e=>e.id===r.id?{...e,current:i}:e):a.length>0?a:e.options.map(e=>e.id===r.id?{...e,current:i}:e),e.wanted.get(r.id)===i&&e.wanted.delete(r.id),me(this.host.home,e.agentId,e.options),this.publishOptions(e))}shown(e){if(e.options.length===0){let t=this.offered.get(e.agentId)??pe(this.host.home,e.agentId)?.options;if(!t)return;e.options=t.map(e=>({...e}))}if(e.sessionId===null)for(let[t,n]of this.desired(e,!0))e.wanted.set(t,n)}async setOption(e,t,n){this.requireOn();let r=this.chat(e);this.shown(r);let i=r.options.find(e=>e.id===t);if(!i)throw E(404,`app.agent.reason.noSuchOption`,{option:t.slice(0,80)});if(!u(i,n))throw E(400,`app.agent.reason.badOptionValue`,{value:n.slice(0,80)});r.wanted.set(i.id,n),j.includes(i.category)&&ce(this.host.home,r.agentId,i.category,n),this.publishOptions(r);let a=r.process,o=r.sessionId;if(!r.turn&&a?.alive&&o&&this.owners.get(a)?.get(o)===r){let e=r.configured.then(()=>this.change(r,a,o,i,n));r.configured=e.catch(()=>void 0);try{await e}catch(e){throw r.wanted.delete(i.id),this.publishOptions(r),E(502,`app.agent.reason.optionRefused`,{reason:M(e instanceof Error?e.message:String(e))})}}return r.shownOptions()}gone(e,t,n,r){this.live.delete(e),e.pid!==void 0&&Le(this.host.home,this.host.folder,e.pid);let i=this.owners.get(e);if(this.owners.delete(e),this.release(e),i)for(let a of i.values()){if(a.process!==e)continue;a.process=null;let i=a.turn;i&&(r?this.stoppedBy(a,i):this.finish(a,i,{key:le(n),detail:n===``?t:`${t}: ${n}`},`end_turn`))}}release(e){this.started.get(e.agentId)===e&&(this.started.delete(e.agentId),this.processes.delete(e.agentId))}stoppedBy(e,t,n=`app.agent.killed`){if(e.turn!==t)return;this.flush(),t.stopping&&clearTimeout(t.stopping),this.settleQuestions(e),e.turn=null,e.connecting=!1,e.failure=null;for(let t of e.transcript.stopRunning())this.publish({type:`tool`,chatId:e.id,tool:t});let i=e.transcript.notice(r(n));this.publish(this.entryEvent(e,i)),this.touch(e),this.saveAll(),this.publishChats(),this.drainSoon(e)}ownerOf(e){for(let t of this.owners.values()){let n=t.get(e);if(n)return n}return null}schedule(e,t){let n=this.dirty.get(e);n||(n=/* @__PURE__ */ new Set,this.dirty.set(e,n)),n.add(t.id),!this.flushTimer&&(this.flushTimer=setTimeout(()=>this.flush(),this.timings.flushMs),this.flushTimer.unref())}flush(){if(this.flushTimer&&clearTimeout(this.flushTimer),this.flushTimer=null,this.dirty.size===0)return;let e=[...this.dirty];this.dirty.clear();for(let[t,n]of e){for(let e of n){let n=t.transcript.find(e);n&&this.feed.publish(this.entryEvent(t,n))}this.markUnsaved(t)}}relative(e){if(!z.isAbsolute(e))return e;let t=this.host.files.relative(e);return t.startsWith(`..`)||t===``?e:t}update(e){let t=this.ownerOf(e.sessionId);if(!t||t.fenced)return;t.turn&&(t.turn.heard=performance.now());let n=e.update;switch(n.sessionUpdate){case`agent_message_chunk`:case`agent_thought_chunk`:{if(n.content.type!==`text`)return;let e=n.sessionUpdate===`agent_message_chunk`?`agent`:`thought`;this.schedule(t,t.transcript.message(e,n.content.text,n.messageId??null));return}case`tool_call`:{this.keepInput(t,n.toolCallId,n.rawInput);let e=t.transcript.upsertTool(b(n,void 0,e=>this.relative(e)));this.publish(this.entryEvent(t,e));return}case`tool_call_update`:{this.keepInput(t,n.toolCallId,n.rawInput),(n.status===`completed`||n.status===`failed`)&&t.grants.delete(n.toolCallId);let e=t.transcript.tool(n.toolCallId),r=t.transcript.upsertTool(b(n,e,e=>this.relative(e)));this.publish(this.entryEvent(t,r));return}case`config_option_update`:{let e=oe(n.configOptions,null);if(e.length===0)return;for(let n of e)t.wanted.get(n.id)===n.current&&t.wanted.delete(n.id);this.offer(t,e);return}case`current_mode_update`:if(!t.options.some(e=>e.legacy))return;t.options=t.options.map(e=>e.legacy&&u(e,n.currentModeId)?{...e,current:n.currentModeId}:e),this.publishOptions(t);return;case`plan`:{let e=t.transcript.plan(n.entries);this.publish(this.entryEvent(t,e)),this.publishChats();return}default:return}}keepInput(e,t,n){n!=null&&(e.rawInputs.set(t,n),e.rawInputs.size>40&&e.rawInputs.delete(e.rawInputs.keys().next().value))}async announced(e,t,n){let r=Date.now()+200;for(;!e.rawInputs.has(t)&&!n.aborted&&Date.now()<r;)await new Promise(e=>setTimeout(e,5))}async requestPermission(e,t){let n=this.ownerOf(e.sessionId);if(!n||n.fenced||t.aborted||!n.turn)return Z;this.asked+=1;let r=`ask:${this.asked}`,i=e.toolCall.toolCallId;if(e.toolCall.rawInput==null&&!n.rawInputs.has(i)&&await this.announced(n,i,t),t.aborted||!n.turn)return Z;let a=se(r,e.toolCall,e.options,n.transcript.tool(i),e=>this.relative(e)),o=e.toolCall.rawInput??n.rawInputs.get(i);if($e(a.tool,o)||it(a.tool,o)){let e=nt(a);if(e!==null)return{outcome:{outcome:`selected`,optionId:e}}}if(et(a.tool)&&(a=tt(a),Ze(a.tool)&&a.tool.diffs.length===0)){let r=await this.previewOf(n,e.toolCall.toolCallId,e.toolCall.rawInput);if(r&&(a={...a,tool:{...a.tool,...r}}),t.aborted||!n.turn)return Z}let s=a;return new Promise(e=>{let r={permission:s,grants:!0,resolve:t=>e(t===null?Z:{outcome:{outcome:`selected`,optionId:t}})},i=()=>{let e=n.questions.indexOf(r);e<0||(n.questions.splice(e,1),this.publish({type:`permission`,chatId:n.id,permission:n.questions[0]?.permission??null}),this.publishChats())};t.addEventListener(`abort`,()=>{i(),e(Z)}),this.ask(n,r)})}ask(e,t){let n=e.transcript.upsertTool(t.permission.tool);this.publish(this.entryEvent(e,n)),e.questions.push(t),e.questions.length===1&&(this.publish({type:`permission`,chatId:e.id,permission:t.permission}),this.publishChats())}async previewOf(e,t,n){let r=at(n??e.rawInputs.get(t));if(!r)return null;let i;try{i=this.host.files.resolve(r.file)}catch{return null}let a;try{a=await(this.host.preview??ke)(i,r.operations)}catch{return null}if(!a.ok)return null;let o=this.relative(i);return{diffs:[{path:o,oldText:a.before,newText:a.after}],paths:[o],locations:[{path:o,line:null}]}}grant(e,t){(t.kind===`edit`||t.kind===`delete`||t.kind===`move`||t.diffs.length>0)&&t.paths.length!==0&&e.grants.set(t.id,new Set(t.paths))}granted(e,t){for(let[n,r]of e.grants)if(r.delete(t))return r.size===0&&e.grants.delete(n),!0;return!1}target(e){try{return this.host.files.resolve(e)}catch(e){throw new U(Y,e instanceof Error?e.message:String(e))}}known(e){let t=this.ownerOf(e);if(!t||t.fenced)throw new U(Y,r(`app.agent.reason.notRunning`));return t}readText(e){let t=this.known(e.sessionId),n=this.target(e.path),i;try{let e=H(n);if(!e.isFile())throw new U(Y,r(`app.agent.reason.noSuchFile`));if(e.size>J)throw new U(X,r(`app.agent.reason.fileTooLarge`,{limit:J/1048576}));i=B(n,`utf8`)}catch(e){throw e instanceof U?e:new U(-32002,r(`app.agent.reason.noSuchFile`))}this.remember(t,this.relative(n));let a=Math.max(1,e.line??1);if(a===1&&(e.limit===void 0||e.limit===null))return{content:i};let o=i.split(`
5
+ `);return{content:(e.limit===void 0||e.limit===null?o.slice(a-1):o.slice(a-1,a-1+Math.max(0,e.limit))).join(`
6
+ `)}}async writeText(e){let n=this.known(e.sessionId),i=this.target(e.path),a=this.relative(i);if(Buffer.byteLength(e.content)>st)throw new U(X,r(`app.agent.reason.fileTooLarge`,{limit:st/1048576}));let o=null;try{let e=H(i);if(e.isDirectory())throw new U(Y,r(`app.agent.reason.isAFolder`));e.size<=J&&(o=B(i,`utf8`))}catch(e){if(e instanceof U)throw e}if(!this.granted(n,a)&&!await this.askToWrite(n,a,o,e.content))throw new U(X,r(`app.agent.writeRejected`,{path:a}));try{t(i,e.content)}catch(e){throw new U(X,e instanceof Error?e.message:String(e))}this.remember(n,a),this.host.changed([i]).catch(()=>void 0)}async askToWrite(e,t,n,i){this.asked+=1;let a={id:`write:${this.asked}`,title:r(`app.agent.write`,{path:t}),kind:`edit`,status:`pending`,diffs:[{path:t,oldText:n,newText:i}],paths:[t],locations:[{path:t,line:null}]},o={id:`ask:${this.asked}`,tool:a,options:[{id:`allow`,label:r(`app.agent.allow`),kind:`allow`},{id:`reject`,label:r(`app.agent.reject`),kind:`reject`}]},s=await new Promise(t=>this.ask(e,{permission:o,grants:!1,resolve:t}))===`allow`,c={...a,status:s?`done`:`failed`},l=e.transcript.upsertTool(c);return this.publish(this.entryEvent(e,l)),s}},Q=class extends Error{};const mt=/^Bearer ([\w.~+/-]{1,512}=*)$/,ht=/^[0-9a-f]{32,128}$/,gt=be(De);function _t(e){let t=e.url??``,n=`${D.ping.path}?`;if(e.method!==D.ping.method||!t.startsWith(n))return null;let r=new URLSearchParams(t.slice(n.length));return r.has(`nonce`)?r:null}function vt(e){if(e===void 0)return null;let t=mt.exec(e);return t?t[1]:null}async function yt(t){let n=t.env??process.env,r=t.home??o(n),i=t.token??Te(),a=new ye(t.folder),s=t.agent??{},c=new pt({folder:a.root,files:a,env:n,home:r,version:e(),mcp:s.mcp===void 0?re():s.mcp,licensed:s.licensed,preview:s.preview,changed:async()=>void 0},s.timings),l=/* @__PURE__ */ new Set,u=t.graceMs??D.graceMs,ee=t.quietMs??D.quietMs,d=new Be(u,performance.now()),f=(/* @__PURE__ */ new Date()).toISOString(),p=t.record??!0,m=y(r,a.root),h=null,g=!1,_=null,v=()=>void 0,b=new Promise(e=>{v=e}),x=t=>({pid:process.pid,apiVersion:D.apiVersion,cliVersion:e()??``,startedAt:f,compatible:t.get(`apiVersion`)===String(D.apiVersion),retiring:g,busy:c.busy()}),S=async(e,t,n,r,i)=>{let a=new AbortController,o=n.held?d.hold(performance.now()):null;t.once(`close`,()=>{t.writableEnded||a.abort(),o?.(performance.now())});let s=null;try{let o;if(e.method!==`GET`){let t=await xe(e,n.limit??1048576);if(t.length>0){if(!/^application\/json\b/i.test(e.headers[`content-type`]??``))throw R(415,`app.cli.web.reason.notJson`);try{o=JSON.parse(t.toString(`utf8`))}catch{throw R(400,`app.cli.web.reason.notJson`)}}}else e.resume();let l=Promise.resolve().then(()=>n.run({body:o,query:i,params:r,signal:a.signal},c));l.catch(()=>void 0);let u=n.held?await l:await Promise.race([l,new Promise((e,t)=>{s=setTimeout(()=>{a.abort(),t(R(504,`app.cli.web.reason.tookTooLong`))},_e),s.unref()})]);if(a.signal.aborted&&t.destroyed)return;I(t,200,u)}catch(e){if(e instanceof P||e instanceof P)return void t.destroy();if(t.destroyed)return;L(t,e instanceof ge?e:de(e))}finally{s&&clearTimeout(s)}},C=(e,t,n)=>n.pathname===D.ping.path?(e.method===D.ping.method?I(t,200,x(n.searchParams)):L(t,R(405,`app.cli.web.reason.methodNotAllowed`),{Allow:D.ping.method}),!0):n.pathname===D.retire.path?(e.method===D.retire.method?(g=!0,I(t,200,{retiring:g,busy:c.retire()})):L(t,R(405,`app.cli.web.reason.methodNotAllowed`),{Allow:D.retire.method}),!0):n.pathname===D.shutdown.path&&(e.method===D.shutdown.method?(I(t,200,{stopping:!0}),setImmediate(()=>void k())):L(t,R(405,`app.cli.web.reason.methodNotAllowed`),{Allow:D.shutdown.method}),!0),w=async(e,t)=>{if(Ee(t),!h||!h.allowsHost(e.headers.host))return L(t,R(403,`app.cli.web.reason.wrongHost`));if(e.headers.origin!==void 0||e.headers[`sec-fetch-site`]!==void 0)return L(t,R(403,`app.cli.web.reason.wrongOrigin`));let n=_t(e);if(n!==null){let e=n.get(`nonce`)??``;return ht.test(e)?I(t,200,{pid:process.pid,apiVersion:D.apiVersion,compatible:n.get(`apiVersion`)===String(D.apiVersion),proof:ie(i,e)}):L(t,R(400,`app.cli.web.reason.badPath`,{path:``}))}if(!we(vt(e.headers.authorization),i))return L(t,R(401,`app.cli.web.reason.noToken`),{"WWW-Authenticate":`Bearer`});let r=e.url??``;if(r.length>8192)return L(t,R(414,`app.cli.web.reason.tooLong`));if(!r.startsWith(`/`)||r.startsWith(`//`))return L(t,R(400,`app.cli.web.reason.badPath`,{path:``}));let a;try{a=new URL(r,`http://${e.headers.host}`)}catch{return L(t,R(400,`app.cli.web.reason.badPath`,{path:``}))}if(C(e,t,a))return;let o=gt(e.method??``,a.pathname);if(o.kind===`none`)return L(t,R(404,`app.cli.web.reason.noSuchOperation`));if(o.kind===`method`)return L(t,R(405,`app.cli.web.reason.methodNotAllowed`),{Allow:o.allowed.join(`, `)});await S(e,t,o.route,o.params,a.searchParams)},T=Pe({maxHeaderSize:16384,requestTimeout:6e4,headersTimeout:15e3,keepAliveTimeout:5e3},(e,t)=>{w(e,t).catch(e=>{t.headersSent?t.destroy():L(t,de(e))})});T.maxConnections=64,T.on(`connection`,e=>{l.add(e),e.once(`close`,()=>l.delete(e))}),T.on(`clientError`,(e,t)=>{t.writable?t.end(`HTTP/1.1 400 Bad Request\r
7
+ Connection: close\r
8
+ Content-Length: 0\r
9
+ \r
10
+ `):t.destroy()});try{await new Promise((e,t)=>{T.once(`error`,t),T.listen(0,`127.0.0.1`,()=>{T.off(`error`,t),e()})})}catch(e){throw c.dispose(),e}let E=T.address().port;if(h=ve(`127.0.0.1`,E),p){if(await O(r,a.root))throw await new Promise(e=>T.close(()=>e())),c.dispose(),new Q;await ze(r,a.root),te(m,{pid:process.pid,port:E,token:i,apiVersion:D.apiVersion,cliVersion:e()??``,startedAt:f})}let k=()=>(_??=(async()=>{p&&ne(m,{pid:process.pid,token:i}),c.dispose();let e=new Promise(e=>T.close(()=>e()));T.closeIdleConnections(),setTimeout(()=>{for(let e of l)e.destroy();T.closeAllConnections()},500).unref(),await c.drained(),await e})().finally(()=>v()),_),A=setInterval(()=>{if(_)return;let e=d.tick(performance.now(),c.busy(),g);e.unattended&&(c.cancelUnanswered(),c.stopQuiet(ee)),e.leave&&k()},t.checkMs??Math.min(1e3,Math.max(20,u/4)));return A.unref(),b.then(()=>clearInterval(A)),{server:T,manager:c,port:E,token:i,exited:b,close:k}}function bt(e,t){let n=Number(e[t]);return Number.isInteger(n)&&n>0?n:void 0}function $(e,t){return new Promise(n=>{let r=()=>{process.off(`SIGINT`,r),process.off(`SIGTERM`,r),e.stdin.off(`end`,r),e.stdin.off(`close`,r),e.stdin.off(`error`,r),n()};process.on(`SIGINT`,r),process.on(`SIGTERM`,r),t&&(e.stdin.on(`end`,r),e.stdin.on(`close`,r),e.stdin.on(`error`,r)),e.stdin.resume()})}function xt(e){return new Promise(t=>setTimeout(t,e))}async function St(e,t,n){let i=await O(t,e);if(i)return n.write(JSON.stringify({port:i.port,token:i.token})),{ok:!0,lines:[]};let a=k(`agent`,`serve`,`--project`,e);if(!a)return{ok:!1,lines:[r(`app.agent.notFound`)]};let o={error:null},s=Me(a.command,a.args,{detached:!0,stdio:[`ignore`,`inherit`,`inherit`],env:{...process.env,...a.env,PENSTOCK_HOME:t},windowsHide:!0});s.on(`error`,e=>{o.error=e});let c=performance.now()+D.startMs;for(;;){let i=await O(t,e);if(i)return s.unref(),n.write(JSON.stringify({port:i.port,token:i.token})),{ok:!0,lines:[]};if(o.error)return{ok:!1,lines:[r(`app.agent.failed`,{detail:o.error.message})]};if(performance.now()>=c)return s.pid!==void 0&&A(s.pid,`SIGTERM`),{ok:!1,lines:[r(`app.agent.timeout`)]};await xt(D.pollMs)}}async function Ct(e,t={stdin:process.stdin,write:e=>process.stdout.write(`${e}\n`)},n={}){if(e===void 0||e===``)return{ok:!1,lines:[r(`app.cli.agentServe.needsProject`)]};let i=z.resolve(e),a;try{a=H(i)}catch{return{ok:!1,lines:[Oe(i)]}}if(!a.isDirectory())return{ok:!1,lines:[r(`app.cli.web.notAFolder`,{folder:i})]};let s=o(process.env);if(n.detach)return St(i,s,t);let c=await O(s,i);if(c)return t.write(JSON.stringify({port:c.port,token:c.token})),await $(t,!0),{ok:!0,lines:[]};let l;try{l=await yt({folder:i,home:s,graceMs:bt(process.env,`PENSTOCK_AGENT_GRACE_MS`),quietMs:bt(process.env,`PENSTOCK_AGENT_QUIET_MS`)})}catch(e){if(e instanceof Q){let e=await O(s,i);if(e)return t.write(JSON.stringify({port:e.port,token:e.token})),await $(t,!0),{ok:!0,lines:[]}}return{ok:!1,lines:[r(`app.cli.web.cannotListen`,{reason:e instanceof Error?e.message:String(e)})]}}return t.write(JSON.stringify({port:l.port,token:l.token})),await Promise.race([$(t,!1),l.exited]),await l.close(),{ok:!0,lines:[]}}export{Ct as agentServeCommand};
@@ -0,0 +1 @@
1
+ export{i as flowFindings,o as pathsCommand,c as unreadableDmn}from"./chunk-analyze-CUxuBgNS.js";
@@ -0,0 +1 @@
1
+ import{r as e}from"./chunk-translator-BFUJmSkR.js";import{J as t,Y as n,dn as r,n as i,q as a,un as o}from"./chunk-src-BLyg_6UX.js";import{n as s}from"./chunk-moddle-Dlk0NR-u.js";import{r as c}from"./chunk-docs-CY6ICsip.js";import{s as l}from"./chunk-failure-BsimkHy_.js";import{r as u}from"./chunk-context-DPJmldqg.js";import{t as d}from"./chunk-report-CDz78nCI.js";import{t as f}from"./chunk-plural-Bq_4vgOr.js";import{t as p}from"./chunk-formChecks-acRgARZ3.js";import{readFileSync as m}from"node:fs";function h(e,t){let r=e[t];return r?.name?.replace(/\s+/g,` `).trim()||(r?.$type?n(r.$type):t)}async function g(e){return await s(`plain`).fromXML(m(e,`utf8`))}async function _(e){return t((await g(e)).rootElement)}async function v(t,n){let r=[],i=[],a=0;for(let o of t){let t;try{t=await _(o)}catch(e){a+=1,i.push({file:u(o),scenarios:[]}),r.push(l(u(o),e));continue}i.push({file:u(o),scenarios:t}),n===`md`?(r.push(`## ${u(o)}`,``),t.forEach((t,n)=>{r.push(`### ${n+1}. ${t.start} → ${t.ends.join(`, `)||e(`app.output.end`)}`,``),t.decisions.forEach(t=>r.push(`- [ ] ${t.boundary?e(`app.output.boundaryFires`,{decision:t.decision,boundary:t.boundary}):e(`app.output.decisionWay`,{decision:t.decision,way:t.way})}${t.condition?` (\`${t.condition}\`)`:``}`)),r.push(e(`app.output.runsSteps`,{steps:t.steps.join(` → `)||e(`app.output.noSteps`)}),``)})):(r.push(`${u(o)} ${f(t.length,`app.output.count.scenario`)}`),t.forEach((t,n)=>{r.push(` ${String(n+1).padStart(2)}. ${[t.start,...t.steps,...t.ends].join(` → `)}`);for(let n of t.decisions){let t=n.boundary?e(`app.output.firesOn`,{boundary:n.boundary,decision:n.decision}):e(`app.output.decisionWay`,{decision:n.decision,way:n.way});r.push(` ${t}${n.condition?e(`app.output.when`,{condition:n.condition}):``}`)}}))}return n===`json`?{ok:a===0,lines:[JSON.stringify(i,null,2)]}:{ok:a===0,lines:r}}async function y(e){let{rootElement:t,elementsById:n}=await g(e);return{problems:a(t).problems,names:e=>h(n,e)}}async function b(e){let{rootElement:t}=await r(m(e,`utf8`));return i(t)}async function x(e){try{return await r(m(e,`utf8`)),null}catch(t){if(!(t instanceof o))throw t;return{file:e,rule:`dmn`,message:t.message,severity:`error`}}}function S(e){try{let t=m(e,`utf8`).slice(0,4096);return t.trimStart().startsWith(`{`)&&t.includes(`"components"`)}catch{return!1}}function C(e){return p(JSON.parse(m(e,`utf8`)))}async function w(t){let n=(e,n,r)=>{let i=c(e,n)?.severity===`warning`;return d(e,{file:t,rule:n,message:r,severity:i?`warning`:`error`})};if(/\.dmn$/i.test(t))return(await b(t)).map(e=>n(`table`,e.kind,e.detail));if(/\.form$/i.test(t))return C(t).map(e=>n(`form`,e.kind,e.detail));let{problems:r,names:i}=await y(t);return r.map(t=>n(`flow`,t.kind,t.trace.length>0?e(`app.rules.web.detailWithPath`,{detail:t.detail,path:t.trace.map(i).join(` → `)}):t.detail))}export{S as a,x as c,w as i,C as n,v as o,b as r,_ as s,y as t};
@@ -0,0 +1 @@
1
+ import{r as e}from"./chunk-translator-BFUJmSkR.js";import{Z as t}from"./chunk-src-BLyg_6UX.js";import{a as n,o as r,r as i}from"./chunk-moddle-Dlk0NR-u.js";import{f as a,g as o,m as s,y as c}from"./chunk-engine-CxgdJ2wO.js";function l(e){return typeof e==`string`?e.split(/[^A-Za-z0-9]+/).filter(Boolean).map(e=>e[0].toUpperCase()+e.slice(1)).join(``):``}function u(e){return(e.$type??e.type??``).replace(/^[a-z0-9]+:/i,``)}function d(e){let t=e.replace(/[^A-Za-z0-9_.-]/g,`_`);return/^[A-Za-z_]/.test(t)?t:`_${t}`}function f(e,t,n){if(!n.fromName)return null;let r=l(t);return r?d((typeof n.pattern==`string`&&n.pattern?n.pattern:`{Type}_{Name}`).replace(`{Type}`,()=>u(e)).replace(`{Name}`,()=>r)):null}const p=1e6;function m(e,t){if(!t(e))return e;for(let n=2;n<p;n+=1){let r=`${e}_${n}`;if(!t(r))return r}return`${e}_${p}`}function h(e,t){let n=e?.defaults;if(typeof n!=`object`||!n||!Object.hasOwn(n,t))return{};let r=n[t];return typeof r==`object`&&r?r:{}}const g={task:{type:`bpmn:Task`},"user-task":{type:`bpmn:UserTask`},"service-task":{type:`bpmn:ServiceTask`},"script-task":{type:`bpmn:ScriptTask`},"send-task":{type:`bpmn:SendTask`},"receive-task":{type:`bpmn:ReceiveTask`},"business-rule-task":{type:`bpmn:BusinessRuleTask`},"manual-task":{type:`bpmn:ManualTask`},"call-activity":{type:`bpmn:CallActivity`},"sub-process":{type:`bpmn:SubProcess`},"end-event":{type:`bpmn:EndEvent`},"intermediate-catch-event":{type:`bpmn:IntermediateCatchEvent`},"intermediate-throw-event":{type:`bpmn:IntermediateThrowEvent`},"exclusive-gateway":{type:`bpmn:ExclusiveGateway`},"parallel-gateway":{type:`bpmn:ParallelGateway`},"inclusive-gateway":{type:`bpmn:InclusiveGateway`},"event-based-gateway":{type:`bpmn:EventBasedGateway`}},_={message:`bpmn:MessageEventDefinition`,timer:`bpmn:TimerEventDefinition`,signal:`bpmn:SignalEventDefinition`,error:`bpmn:ErrorEventDefinition`,escalation:`bpmn:EscalationEventDefinition`,conditional:`bpmn:ConditionalEventDefinition`,terminate:`bpmn:TerminateEventDefinition`},v=(e,t,n)=>({kind:t,description:`app.cli.edit.property.${e}`,on:n}),y=[`bpmn:Task`,`bpmn:UserTask`,`bpmn:ServiceTask`,`bpmn:ScriptTask`,`bpmn:SendTask`,`bpmn:ReceiveTask`,`bpmn:BusinessRuleTask`,`bpmn:ManualTask`,`bpmn:CallActivity`,`bpmn:SubProcess`],b=[`bpmn:ServiceTask`,`bpmn:SendTask`,`bpmn:BusinessRuleTask`,`bpmn:ScriptTask`],x={name:v(`name`,`string`),documentation:v(`documentation`,`string`)},S={...x,condition:v(`condition`,`string`,[`bpmn:SequenceFlow`]),class:v(`class`,`string`,b),delegateExpression:v(`delegateExpression`,`string`,b),expression:v(`expression`,`string`,b),resultVariable:v(`resultVariable`,`string`,b),topic:v(`topic`,`string`,b),asyncBefore:v(`asyncBefore`,`boolean`),asyncAfter:v(`asyncAfter`,`boolean`),assignee:v(`assignee`,`string`,[`bpmn:UserTask`]),candidateUsers:v(`candidateUsers`,`string`,[`bpmn:UserTask`]),candidateGroups:v(`candidateGroups`,`string`,[`bpmn:UserTask`]),formKey:v(`formKey`,`string`,[`bpmn:UserTask`,`bpmn:StartEvent`]),calledElement:v(`calledElement`,`string`,[`bpmn:CallActivity`]),decisionRef:v(`decisionRef`,`string`,[`bpmn:BusinessRuleTask`]),inputs:v(`inputs`,`mapping`,y),outputs:v(`outputs`,`mapping`,y)},C={...x,condition:v(`condition`,`string`,[`bpmn:SequenceFlow`]),class:v(`class`,`string`,[`bpmn:ServiceTask`,`bpmn:SendTask`,`bpmn:BusinessRuleTask`]),delegateExpression:v(`delegateExpression`,`string`,[`bpmn:ServiceTask`,`bpmn:SendTask`,`bpmn:BusinessRuleTask`]),expression:v(`expression`,`string`,[`bpmn:ServiceTask`,`bpmn:SendTask`,`bpmn:BusinessRuleTask`]),resultVariable:v(`resultVariable`,`string`,[`bpmn:ServiceTask`,`bpmn:ScriptTask`,`bpmn:BusinessRuleTask`]),async:v(`async`,`boolean`,[`bpmn:Task`,`bpmn:UserTask`,`bpmn:ServiceTask`,`bpmn:ScriptTask`,`bpmn:SendTask`,`bpmn:ReceiveTask`,`bpmn:BusinessRuleTask`,`bpmn:ManualTask`,`bpmn:CallActivity`,`bpmn:SubProcess`]),skipExpression:v(`skipExpression`,`string`,[`bpmn:Task`,`bpmn:UserTask`,`bpmn:ServiceTask`,`bpmn:ScriptTask`,`bpmn:SendTask`,`bpmn:ReceiveTask`,`bpmn:BusinessRuleTask`,`bpmn:ManualTask`]),assignee:v(`assignee`,`string`,[`bpmn:UserTask`]),candidateUsers:v(`candidateUsers`,`string`,[`bpmn:UserTask`]),candidateGroups:v(`candidateGroups`,`string`,[`bpmn:UserTask`]),formKey:v(`formKey`,`string`,[`bpmn:UserTask`,`bpmn:StartEvent`]),calledElement:v(`calledElement`,`string`,[`bpmn:CallActivity`])},w={classic:{...x,condition:v(`conditionSimple`,`string`,[`bpmn:SequenceFlow`])},"camunda-7":S,operaton:S,"cib-seven":S,flowable:C,activiti:C,"camunda-8":{...x,condition:v(`feelCondition`,`string`,[`bpmn:SequenceFlow`]),jobType:v(`jobType`,`string`,b),retries:v(`retries`,`integer`,b),assignee:v(`assignee`,`string`,[`bpmn:UserTask`]),candidateUsers:v(`candidateUsers`,`string`,[`bpmn:UserTask`]),candidateGroups:v(`candidateGroups`,`string`,[`bpmn:UserTask`]),formId:v(`formId`,`string`,[`bpmn:UserTask`]),processId:v(`processId`,`string`,[`bpmn:CallActivity`]),decisionId:v(`decisionId`,`string`,[`bpmn:BusinessRuleTask`]),inputs:v(`inputMappings`,`mapping`,y),outputs:v(`outputMappings`,`mapping`,y)}};var T=class extends Error{};function E(e,t){throw new T(`${e}: ${t}`)}function D(t,n,r){for(let i of Object.keys(t))n.includes(i)||E(r,e(`app.cli.edit.unknownField`,{key:i,allowed:n.join(`, `)}))}function O(t,n,r,i=!0){if(t!==void 0||i)return typeof t==`string`&&t.trim()||E(n,e(`app.cli.edit.mustBeAString`,{field:r})),t}function k(t,n,r){return typeof t==`number`&&Number.isFinite(t)||E(n,e(`app.cli.edit.mustBeANumber`,{field:r})),t}function A(t,n,r){(!t||typeof t!=`object`||Array.isArray(t))&&E(r,e(`app.cli.edit.propertiesMustBeAnObject`));let i=w[n],a={};for(let[o,s]of Object.entries(t)){let t=Object.hasOwn(i,o)?i[o]:void 0;t||E(r,e(`app.cli.edit.notAnEngineProperty`,{key:o,engine:n,allowed:Object.keys(i).join(`, `)})),t.kind===`string`&&typeof s!=`string`&&E(r,e(`app.cli.edit.mustBeAStringShort`,{key:o})),t.kind===`boolean`&&typeof s!=`boolean`&&E(r,e(`app.cli.edit.mustBeABoolean`,{key:o})),t.kind===`integer`&&(typeof s!=`number`||!Number.isInteger(s)||s<0)&&E(r,e(`app.cli.edit.mustBeAWholeNumber`,{key:o})),t.kind===`mapping`&&(!s||typeof s!=`object`||Array.isArray(s)||Object.values(s).some(e=>typeof e!=`string`))&&E(r,e(`app.cli.edit.mustMapNamesToStrings`,{key:o})),a[o]=s}return a}function j(e,t,n){let r=Object.hasOwn(w[e],t)?w[e][t]:void 0;return!!r&&(!r.on||r.on.includes(n))}function M(t,n){let r=Array.isArray(t)?t:[t];if(r.length===0)throw new T(e(`app.cli.edit.noOperations`));return r.map((t,r)=>{let i=e(`app.cli.edit.operationWhere`,{number:r+1});(!t||typeof t!=`object`||Array.isArray(t))&&E(i,e(`app.cli.edit.mustBeAnObject`));let a=t;switch(a.op){case`add`:return D(a,[`op`,`element`,`after`,`event`,`name`,`id`,`properties`],i),typeof a.element==`string`&&Object.hasOwn(g,a.element)||E(i,e(`app.cli.edit.elementMustBeOneOf`,{elements:Object.keys(g).join(`, `)})),a.event===void 0||typeof a.event==`string`&&Object.hasOwn(_,a.event)||E(i,e(`app.cli.edit.eventMustBeOneOf`,{events:Object.keys(_).join(`, `)})),a.event!==void 0&&!String(a.element).endsWith(`-event`)&&E(i,e(`app.cli.edit.eventOnlyForEvents`)),a.id!==void 0&&!/^[A-Za-z_][\w.-]*$/.test(String(a.id))&&E(i,e(`app.cli.edit.idMustBeValid`)),{op:`add`,element:a.element,after:O(a.after,i,`after`),event:a.event,name:O(a.name,i,`name`,!1),id:O(a.id,i,`id`,!1),properties:a.properties===void 0?void 0:A(a.properties,n,i)};case`connect`:return D(a,[`op`,`from`,`to`,`name`,`condition`],i),{op:`connect`,from:O(a.from,i,`from`),to:O(a.to,i,`to`),name:O(a.name,i,`name`,!1),condition:O(a.condition,i,`condition`,!1)};case`set`:return D(a,[`op`,`id`,`properties`],i),{op:`set`,id:O(a.id,i,`id`),properties:A(a.properties,n,i)};case`remove`:return D(a,[`op`,`id`],i),{op:`remove`,id:O(a.id,i,`id`)};case`move`:return D(a,[`op`,`id`,`dx`,`dy`],i),{op:`move`,id:O(a.id,i,`id`),dx:k(a.dx,i,`dx`),dy:k(a.dy,i,`dy`)};default:return E(i,e(`app.cli.edit.opMustBeOneOf`))}})}function N(n){let r=n?w[n]:{...w.classic,...w[`camunda-7`],...w[`camunda-8`]},i={type:`object`,additionalProperties:!1,properties:Object.fromEntries(Object.entries(r).map(([n,r])=>{let i=r.kind===`mapping`?{type:`object`,additionalProperties:{type:`string`}}:{type:r.kind},a=r.on?e(`app.cli.edit.schema.onlyOn`,{types:t(r.on.map(e=>e.replace(`bpmn:`,``)))}):``;return[n,{...i,description:`${e(r.description)}${a}`}]}))};return{$schema:`https://json-schema.org/draft/2020-12/schema`,title:n?e(`app.cli.edit.schema.titleFor`,{engine:n}):e(`app.cli.edit.schema.title`),type:`array`,minItems:1,items:{oneOf:[{type:`object`,additionalProperties:!1,required:[`op`,`element`,`after`],properties:{op:{const:`add`,description:e(`app.cli.edit.schema.add`)},element:{enum:Object.keys(g)},after:{type:`string`,description:e(`app.cli.edit.schema.after`)},event:{enum:Object.keys(_),description:e(`app.cli.edit.schema.event`)},name:{type:`string`},id:{type:`string`,description:e(`app.cli.edit.schema.newId`)},properties:i}},{type:`object`,additionalProperties:!1,required:[`op`,`from`,`to`],properties:{op:{const:`connect`,description:e(`app.cli.edit.schema.connect`)},from:{type:`string`},to:{type:`string`},name:{type:`string`},condition:{type:`string`}}},{type:`object`,additionalProperties:!1,required:[`op`,`id`,`properties`],properties:{op:{const:`set`,description:e(`app.cli.edit.schema.set`)},id:{type:`string`},properties:i}},{type:`object`,additionalProperties:!1,required:[`op`,`id`],properties:{op:{const:`remove`,description:e(`app.cli.edit.schema.remove`)},id:{type:`string`}}},{type:`object`,additionalProperties:!1,required:[`op`,`id`,`dx`,`dy`],properties:{op:{const:`move`,description:e(`app.cli.edit.schema.move`)},id:{type:`string`},dx:{type:`number`},dy:{type:`number`}}}]}}}const P={"bpmn:EndEvent":[`message`,`signal`,`error`,`escalation`,`terminate`],"bpmn:IntermediateThrowEvent":[`message`,`signal`,`escalation`],"bpmn:IntermediateCatchEvent":[`message`,`timer`,`signal`,`conditional`]},F=[`bpmn:ReceiveTask`,`bpmn:IntermediateCatchEvent`];function I(t,n){if(n&&(!(P[t]??[]).includes(n)||!Object.hasOwn(_,n)))throw new T(e(`app.patch.eventNotAllowed`,{type:u({type:t}),event:n}))}function L(t,n,r){if(t.id===n.id)throw new T(e(`app.patch.sameElement`,{id:t.id}));if(t.type===`bpmn:EndEvent`)throw new T(e(`app.cli.edit.afterEndEvent`,{id:t.id}));if(n.type===`bpmn:StartEvent`)throw new T(e(`app.patch.startEventTarget`,{id:n.id}));if(n.type===`bpmn:BoundaryEvent`)throw new T(e(`app.patch.boundaryTarget`,{id:n.id}));if(t.scope!==n.scope)throw new T(e(`app.patch.differentScopes`,{from:t.id,to:n.id}));if(t.type===`bpmn:EventBasedGateway`&&!F.includes(n.type))throw new T(e(`app.patch.eventBasedTarget`,{to:n.id}));if(r(t.id,n.id))throw new T(e(`app.patch.duplicateFlow`,{from:t.id,to:n.id}))}const ee=[0,1,-1,2,-2,3,-3,4,-4];function te(e){return e.endsWith(`Event`)?{width:36,height:36}:e.endsWith(`Gateway`)?{width:50,height:50}:e===`bpmn:SubProcess`?{width:350,height:200}:{width:100,height:80}}function ne(e,t,n=0){return e.x<t.x+t.width+n&&e.x+e.width+n>t.x&&e.y<t.y+t.height+n&&e.y+e.height+n>t.y}function R(e,t,n){if(!t||!/(Event|Gateway)$/.test(e))return;let r=Math.max(n.width,Math.min(t.length*7,120));return{x:Math.round(n.x+n.width/2-r/2),y:n.y+n.height+4,width:r,height:28}}function z(e,t){return t.x>=e.x&&t.y>=e.y&&t.x+t.width<=e.x+e.width&&t.y+t.height<=e.y+e.height}function B(e){return{x:e.x+e.width/2,y:e.y+e.height/2}}function V(e,t,n,r,i=50,a){let{width:o,height:s}=te(t),c=e.y+e.height/2,l=[];for(let t=0;t<6;t+=1)for(let n of ee)l.push({x:Math.round(e.x+e.width+i+t*(o+i)),y:Math.round(c-s/2+n*(s+i*.6)),width:o,height:s});let u=e=>!n.some(t=>ne(e,t,12)),d=e=>{let n=R(t,a,e);return u(e)&&(!n||u(n))},f=e=>!r||z(r,e);return l.find(e=>f(e)&&d(e))??l.find(d)??l[0]}function H(e,t){let n=B(e),r=B(t);if(t.x>=e.x+e.width){let i={x:e.x+e.width,y:n.y},a={x:t.x,y:r.y};if(i.y===a.y)return[i,a];let o=Math.round((i.x+a.x)/2);return[i,{x:o,y:i.y},{x:o,y:a.y},a]}let i=Math.max(e.y+e.height,t.y+t.height)+25;return[{x:n.x,y:e.y+e.height},{x:n.x,y:i},{x:r.x,y:i},{x:r.x,y:t.y+t.height}]}const U=[`class`,`delegateExpression`,`expression`,`topic`],W=[`class`,`delegateExpression`,`expression`];function G(t,n,r,i){for(let t of Object.keys(i))if(!j(n,t,r.type))throw new T(e(`app.cli.edit.doesNotApply`,{key:t,type:u(r),id:r.id}));for(let[e,a]of Object.entries(i))K(t,n,r,e,a)}function K(e,t,n,r,i){let{modeling:a,moddle:c}=e;if(r===`name`)return a.updateProperties(n,{name:i});if(r===`documentation`)return a.updateProperties(n,{documentation:[c.create(`bpmn:Documentation`,{text:i})]});if(r===`condition`)return a.updateProperties(n,{conditionExpression:c.create(`bpmn:FormalExpression`,{body:i})});if(s(t))return q(e,t,n,r,i);if(o(t))return J(e,t,n,r,i);if(t===`camunda-8`)return Y(e,n,r,i)}function q(e,t,n,r,i){let{modeling:o,moddle:s}=e,c=a(t);if(U.includes(r)){let e=Object.fromEntries([`class`,`delegateExpression`,`expression`,`topic`,`type`].map(e=>[`${c}:${e}`,void 0])),t=r===`topic`?{[`${c}:type`]:`external`,[`${c}:topic`]:i}:{[`${c}:${r}`]:i};return o.updateProperties(n,{...e,...t})}if(r===`inputs`||r===`outputs`){let t=X(e,n,`${c}:InputOutput`),a=Object.entries(i).map(([e,t])=>s.create(r===`inputs`?`${c}:InputParameter`:`${c}:OutputParameter`,{name:e,value:t}));return o.updateModdleProperties(n,t,{[r===`inputs`?`inputParameters`:`outputParameters`]:a})}return o.updateProperties(n,{[`${c}:${r}`]:i})}function J(e,t,n,r,i){let o=a(t);if(W.includes(r)){let t=Object.fromEntries([`class`,`delegateExpression`,`expression`,`type`].map(e=>[`${o}:${e}`,void 0]));return e.modeling.updateProperties(n,{...t,[`${o}:${r}`]:i})}return r===`resultVariable`?e.modeling.updateProperties(n,{[`${o}:${n.type===`bpmn:ServiceTask`?`resultVariableName`:`resultVariable`}`]:i}):e.modeling.updateProperties(n,{[`${o}:${r}`]:i})}function Y(e,t,n,r){let{modeling:i,moddle:a}=e,o=(n,r)=>{i.updateModdleProperties(t,X(e,t,n),r)};switch(n){case`jobType`:return o(`zeebe:TaskDefinition`,{type:r});case`retries`:return o(`zeebe:TaskDefinition`,{retries:String(r)});case`assignee`:case`candidateUsers`:case`candidateGroups`:return o(`zeebe:AssignmentDefinition`,{[n]:r});case`formId`:return o(`zeebe:FormDefinition`,{formId:r});case`processId`:return o(`zeebe:CalledElement`,{processId:r});case`decisionId`:return o(`zeebe:CalledDecision`,{decisionId:r});case`inputs`:case`outputs`:{let e=Object.entries(r).map(([e,t])=>a.create(n===`inputs`?`zeebe:Input`:`zeebe:Output`,{target:e,source:t}));return o(`zeebe:IoMapping`,{[n===`inputs`?`inputParameters`:`outputParameters`]:e})}}}function X(e,t,n){let{modeling:r,moddle:i}=e,a=t.businessObject.extensionElements;a||(a=i.create(`bpmn:ExtensionElements`,{values:[]}),r.updateProperties(t,{extensionElements:a}));let o=(a.values??[]).find(e=>e.$type===n);if(o)return o;let s=i.create(n);return s.$parent=a,r.updateModdleProperties(t,a,{values:[...a.values??[],s]}),s}function Z(e,t){let n={},r=e.extensionElements?.values??[],i=e=>r.find(t=>t.$type===e),c=(e,t)=>{t!=null&&t!==``&&(n[e]=t)};c(`documentation`,e.documentation?.[0]?.text),c(`condition`,e.conditionExpression?.body);let l=e.eventDefinitions?.[0]?.$type;if(l&&c(`event`,Object.entries(_).find(([,e])=>e===l)?.[0]),s(t)){let n=a(t);for(let t of Object.keys(w[`camunda-7`])){if([`inputs`,`outputs`,`name`,`documentation`,`condition`].includes(t))continue;let r=e.get(`${n}:${t}`);(typeof r!=`boolean`||Object.prototype.hasOwnProperty.call(e,t))&&c(t,r)}let r=i(`${n}:InputOutput`),o=e=>e?.length?Object.fromEntries(e.map(e=>[e.name,String(e.value??``)])):void 0;c(`inputs`,o(r?.inputParameters)),c(`outputs`,o(r?.outputParameters))}if(o(t)){let n=a(t);for(let r of Object.keys(w[t])){if([`name`,`documentation`,`condition`,`resultVariable`].includes(r))continue;let t=e.get(`${n}:${r}`);(typeof t!=`boolean`||Object.prototype.hasOwnProperty.call(e,r))&&c(r,t)}c(`resultVariable`,e.get(`${n}:resultVariableName`)??e.get(`${n}:resultVariable`))}if(t===`camunda-8`){let e=i(`zeebe:TaskDefinition`);c(`jobType`,e?.type),c(`retries`,e?.retries===void 0?void 0:Number(e.retries));let t=i(`zeebe:AssignmentDefinition`);c(`assignee`,t?.assignee),c(`candidateUsers`,t?.candidateUsers),c(`candidateGroups`,t?.candidateGroups),c(`formId`,i(`zeebe:FormDefinition`)?.formId),c(`processId`,i(`zeebe:CalledElement`)?.processId),c(`decisionId`,i(`zeebe:CalledDecision`)?.decisionId);let n=i(`zeebe:IoMapping`),r=e=>e?.length?Object.fromEntries(e.map(e=>[e.target,String(e.source??``)])):void 0;c(`inputs`,r(n?.inputParameters)),c(`outputs`,r(n?.outputParameters))}return n}const Q=`bpmn:SequenceFlow`;function re(e){let t=2166136261;for(let n=0;n<e.length;n+=1)t^=e.charCodeAt(n),t=Math.imul(t,16777619)>>>0;return t.toString(36).padStart(7,`0`).slice(-7)}function ie(e){return e.endsWith(`Gateway`)?`Gateway`:e.endsWith(`Event`)?`Event`:`Activity`}function ae(e){switch(e.op){case`add`:return[e.after];case`connect`:return[e.from,e.to];default:return[e.id]}}function oe(e){let t=/* @__PURE__ */ new Map;return e.map((e,n)=>{let r=/* @__PURE__ */ new Set;for(let n of ae(e)){let e=t.get(n);e!==void 0&&r.add(e)}return e.op===`add`&&e.id&&!t.has(e.id)&&t.set(e.id,n),[...r].sort((e,t)=>e-t)})}var $=class{nodes=/* @__PURE__ */ new Map;flows=/* @__PURE__ */ new Map;shapes=/* @__PURE__ */ new Map;edges=/* @__PURE__ */ new Map;pairs=/* @__PURE__ */ new Set;taken=/* @__PURE__ */ new Set;plane;moddle;properties;definitions;engine;conventions;gap;constructor(e,t,n,r=50){this.definitions=e,this.engine=t,this.conventions=n,this.gap=r,this.moddle=i(e),this.plane=e.diagrams?.[0]?.plane,this.properties={moddle:this.moddle,modeling:{updateProperties:(e,t)=>{for(let[n,r]of Object.entries(t))e.businessObject.set(n,r)},updateModdleProperties:(e,t,n)=>{for(let[e,r]of Object.entries(n))t.set(e,r)}}},this.index()}index(){let e=e=>{typeof e==`string`&&this.taken.add(e)},t=/* @__PURE__ */ new Set,n=[this.definitions];for(;n.length>0;){let r=n.pop();if(r&&typeof r==`object`&&!t.has(r)){if(t.add(r),Array.isArray(r))n.push(...r);else{e(r.id);for(let[e,t]of Object.entries(r))!e.startsWith(`$`)&&t&&typeof t==`object`&&n.push(t)}}}for(let e of this.definitions.rootElements??[])if(e.$type===`bpmn:Process`&&this.walk(e),e.$type===`bpmn:Collaboration`){this.nodes.set(e.id,{bo:e,kind:`root`});for(let t of e.participants??[])this.nodes.set(t.id,{bo:t,kind:`container`}),t.processRef&&this.walk(t.processRef)}for(let e of this.plane?.planeElement??[]){let t=e.bpmnElement?.id;t&&(e.$type===`bpmndi:BPMNShape`&&this.shapes.set(t,e),e.$type===`bpmndi:BPMNEdge`&&this.edges.set(t,e))}}walk(e){this.nodes.has(e.id)||this.nodes.set(e.id,{bo:e,kind:`root`});for(let t of e.laneSets?.flatMap(e=>this.lanesOf(e))??[])this.nodes.set(t.id,{bo:t,kind:`container`});for(let t of e.flowElements??[])t.$type===Q?(this.flows.set(t.id,t),this.pairs.add(`${t.sourceRef?.id}>${t.targetRef?.id}`)):t.$instanceOf(`bpmn:FlowNode`)&&(this.nodes.set(t.id,{bo:t,kind:`node`}),t.$instanceOf(`bpmn:SubProcess`)&&this.walk(t))}lanesOf(e){return(e.lanes??[]).flatMap(e=>[e,...e.childLaneSet?this.lanesOf(e.childLaneSet):[]])}has(e){return this.nodes.has(e)||this.flows.has(e)}node(t){let n=this.nodes.get(t);if(!n)throw new T(e(`app.cli.edit.noSuchElement`,{id:t}));return n}freshId(e,t){let n=e===Q?`Flow`:ie(e);for(let e=0;;e+=1){let r=`${n}_${re(e===0?t:`${t}#${e}`)}`;if(!this.taken.has(r))return r}}boundsOf(e){let t=this.shapes.get(e)?.bounds;return t?{x:t.x,y:t.y,width:t.width,height:t.height}:void 0}pointsOf(e){let t=this.edges.get(e)?.waypoint;return t?t.map(e=>({x:e.x,y:e.y})):void 0}snapshot(e){let t=this.flows.get(e),n=t??this.nodes.get(e)?.bo,r=n?.$parent;return{id:e,type:n?.$type??``,...n?.name?{name:n.name}:{},...this.boundsOf(e)?{bounds:this.boundsOf(e)}:{},...t?{waypoints:this.pointsOf(e),source:t.sourceRef?.id,target:t.targetRef?.id}:{},...r?.id&&r.$type!==`bpmn:Definitions`?{parent:r.id}:{},...n?.attachedToRef?.id?{attachedTo:n.attachedToRef.id}:{}}}scopeOf(e){return e.attachedToRef?e.attachedToRef.$parent:e.$parent}shape(e,t){let n=this.moddle.create(`dc:Bounds`,t),r={id:this.uniqueDi(e.id),bpmnElement:e,bounds:n};e.$type===`bpmn:ExclusiveGateway`&&(r.isMarkerVisible=!0),e.$type===`bpmn:SubProcess`&&(r.isExpanded=!0);let i=this.moddle.create(`bpmndi:BPMNShape`,r);this.plane.get(`planeElement`).push(i),i.$parent=this.plane,this.shapes.set(e.id,i)}uniqueDi(e){let t=m(`${e}_di`,e=>this.taken.has(e));return this.taken.add(t),t}edge(e,t){let n=this.moddle.create(`bpmndi:BPMNEdge`,{id:this.uniqueDi(e.id),bpmnElement:e,waypoint:t.map(e=>this.moddle.create(`dc:Point`,e))});this.plane.get(`planeElement`).push(n),n.$parent=this.plane,this.edges.set(e.id,n)}reroute(e){let t=this.flows.get(e),n=this.edges.get(e),r=this.boundsOf(t?.sourceRef?.id),i=this.boundsOf(t?.targetRef?.id);n&&r&&i&&n.set(`waypoint`,H(r,i).map(e=>this.moddle.create(`dc:Point`,e)))}unplane(e){for(let t of[this.shapes,this.edges]){let n=t.get(e);if(!n)continue;let r=this.plane.get(`planeElement`),i=r.indexOf(n);i>=0&&r.splice(i,1),t.delete(e)}}occupiedAround(e,t){let n=[];for(let[r,i]of this.nodes){if(i.kind!==`node`||t.has(r))continue;let a=this.boundsOf(r);if(!a||i.bo.$instanceOf(`bpmn:SubProcess`)&&z(a,e))continue;n.push(a);let o=this.labelOf(r,a,i.bo);o&&n.push(o)}return n}labelOf(e,t,n){let r=this.shapes.get(e)?.label?.bounds;return r?{x:r.x,y:r.y,width:r.width,height:r.height}:R(n.$type,n.name,t)}withinOf(e){if(e.$instanceOf(`bpmn:SubProcess`))return this.boundsOf(e.id);for(let t of this.definitions.rootElements??[]){if(t.$type!==`bpmn:Collaboration`)continue;let n=(t.participants??[]).find(t=>t.processRef===e);if(n)return this.boundsOf(n.id)}}describe(){let e=[];for(let[t,n]of this.nodes){if(n.kind===`root`)continue;let r=this.scopeOf(n.bo)?.id;e.push({id:t,type:u(n.bo),...n.bo.name?{name:n.bo.name}:{},...r?{parent:r}:{},properties:Z(n.bo,this.engine)})}for(let[t,n]of this.flows)e.push({id:t,type:u(n),...n.name?{name:n.name}:{},source:n.sourceRef?.id,target:n.targetRef?.id,properties:Z(n,this.engine)});return e.sort((e,t)=>e.id<t.id?-1:+(e.id>t.id))}snapshotAll(){return{nodes:[...this.nodes].filter(([,e])=>e.kind===`node`).map(([e])=>this.snapshot(e)),flows:[...this.flows.keys()].map(e=>this.snapshot(e))}}flowTouching(e){return[...this.flows.values()].filter(t=>t.sourceRef?.id===e||t.targetRef?.id===e).map(e=>e.id)}create(t,n,r){if(this.flows.has(t.after))throw new T(e(`app.cli.edit.isAConnection`,{id:t.after}));let i=this.node(t.after);if(i.kind!==`node`)throw new T(e(`app.cli.edit.addAfterAnElementInside`,{id:t.after,type:u(i.bo)}));if(!this.plane)throw new T(e(`app.patch.noDrawing`));let a=g[t.element].type,o=this.scopeOf(i.bo);if(I(a,t.event),t.id&&this.taken.has(t.id))throw new T(e(`app.cli.edit.idTaken`,{id:t.id}));L({id:i.bo.id,type:i.bo.$type,scope:o},{id:t.id??``,type:a,scope:o},(e,t)=>this.pairs.has(`${e}>${t}`));let s=t.id;if(!s){let e=t.name&&this.conventions.ids?f({$type:a},t.name,this.conventions.ids):null;s=e?m(e,e=>this.taken.has(e)):this.freshId(a,`${n}:${a}:${t.name??``}:${t.after}`)}this.taken.add(s);let c=this.moddle.create(a,{id:s});if(c.$parent=o,t.event){let e=this.moddle.create(_[t.event]);e.$parent=c,c.get(`eventDefinitions`).push(e)}o.get(`flowElements`).push(c),this.nodes.set(s,{bo:c,kind:`node`});for(let e of[...this.nodes.values()].filter(e=>e.kind===`container`&&e.bo.$type===`bpmn:Lane`))(e.bo.flowNodeRef??[]).includes(i.bo)&&e.bo.get(`flowNodeRef`).push(c);let l=this.boundsOf(i.bo.id);if(!l)throw new T(e(`app.patch.noDrawing`));let d=V(l,a,this.occupiedAround(l,/* @__PURE__ */ new Set([s])),this.withinOf(o),this.gap,t.name);this.shape(c,d);let p=h(this.conventions,a);Object.keys(p).length>0&&this.properties.modeling.updateProperties({businessObject:c},p),t.name&&c.set(`name`,t.name),t.properties&&G(this.properties,this.engine,{id:s,type:a,businessObject:c},t.properties);let v=this.link(i.bo,c,`${n}:flow:${i.bo.id}>${s}`);r.added.push(this.snapshot(s)),r.addedFlows.push(this.snapshot(v.id)),r.touched.push(s,v.id),r.summary=e(`app.cli.edit.added`,{type:u(c),id:s,after:i.bo.id})}link(e,t,n){let r=this.freshId(Q,n);this.taken.add(r);let i=this.moddle.create(Q,{id:r,sourceRef:e,targetRef:t}),a=this.scopeOf(e);i.$parent=a,a.get(`flowElements`).push(i),e.get(`outgoing`).push(i),t.get(`incoming`).push(i),this.flows.set(r,i),this.pairs.add(`${e.id}>${t.id}`);let o=this.boundsOf(e.id),s=this.boundsOf(t.id);return o&&s&&this.plane&&this.edge(i,H(o,s)),i}connect(t,n,r){let i=this.node(t.from),a=this.node(t.to);if(i.kind!==`node`)throw new T(e(`app.patch.notAFlowNode`,{id:t.from,type:u(i.bo)}));if(a.kind!==`node`)throw new T(e(`app.patch.notAFlowNode`,{id:t.to,type:u(a.bo)}));L({id:i.bo.id,type:i.bo.$type,scope:this.scopeOf(i.bo)},{id:a.bo.id,type:a.bo.$type,scope:this.scopeOf(a.bo)},(e,t)=>this.pairs.has(`${e}>${t}`));let o=this.link(i.bo,a.bo,`${n}:flow:${t.from}>${t.to}`);t.name&&o.set(`name`,t.name),t.condition&&G(this.properties,this.engine,{id:o.id,type:Q,businessObject:o},{condition:t.condition}),r.addedFlows.push(this.snapshot(o.id)),r.touched.push(o.id),r.summary=e(`app.cli.edit.connect`,{from:t.from,to:t.to,id:o.id})}set(t,n){let r=this.flows.get(t.id)??this.node(t.id).bo;G(this.properties,this.engine,{id:r.id,type:r.$type,businessObject:r},t.properties),n.changed.push({id:r.id,keys:Object.keys(t.properties),bounds:this.boundsOf(r.id)}),n.touched.push(r.id),n.summary=e(`app.cli.edit.set`,{keys:Object.keys(t.properties).join(`, `),id:r.id})}remove(t,n){let r=this.flows.get(t.id);if(r){this.snapshotAndDrop([r.id],n),n.summary=e(`app.cli.edit.removed`,{id:t.id});return}let i=this.node(t.id);if(i.kind===`root`)throw new T(e(`app.cli.edit.isTheRoot`,{id:t.id}));if(i.kind===`container`)throw new T(e(`app.patch.cannotRemoveContainer`,{id:t.id,type:u(i.bo)}));let a=/* @__PURE__ */ new Set([t.id]),o=[i.bo];for(;o.length>0;){let e=o.pop();for(let t of this.nodes.values())t.bo.attachedToRef===e&&!a.has(t.bo.id)&&(a.add(t.bo.id),o.push(t.bo));if(e.$instanceOf(`bpmn:SubProcess`))for(let t of e.flowElements??[])t.$type!==Q&&this.nodes.has(t.id)&&!a.has(t.id)&&(a.add(t.id),o.push(t))}let s=/* @__PURE__ */ new Set;for(let e of a)for(let t of this.flowTouching(e))s.add(t);this.snapshotAndDrop([...s,...a],n),n.summary=e(`app.cli.edit.removed`,{id:t.id})}snapshotAndDrop(e,t){let n=[...new Set(e)];for(let e of n)t.removed.push(this.snapshot(e));for(let e of n){let t=this.flows.get(e);if(t){let n=(e,t)=>{let n=e?.indexOf(t)??-1;n>=0&&e.splice(n,1)};n(t.sourceRef?.outgoing,t),n(t.targetRef?.incoming,t),n(t.$parent?.flowElements,t),t.sourceRef?.default===t&&t.sourceRef.set(`default`,void 0),this.flows.delete(e),this.pairs.delete(`${t.sourceRef?.id}>${t.targetRef?.id}`),this.unplane(e);continue}let n=this.nodes.get(e);if(!n)continue;let r=n.bo.$parent?.flowElements,i=r?.indexOf(n.bo)??-1;i>=0&&r.splice(i,1);for(let e of this.nodes.values()){let t=e.bo.flowNodeRef,r=t?.indexOf(n.bo)??-1;r>=0&&t.splice(r,1)}this.nodes.delete(e),this.unplane(e)}t.touched.push(...n)}move(t,n){if(this.flows.has(t.id))throw new T(e(`app.patch.isAFlow`,{id:t.id}));let r=this.node(t.id);if(r.kind!==`node`)throw new T(e(`app.patch.notAFlowNode`,{id:t.id,type:u(r.bo)}));if(!this.shapes.has(t.id))throw new T(e(`app.patch.noDrawing`));let i=/* @__PURE__ */ new Set([t.id]);for(let e of this.nodes.values())e.bo.attachedToRef===r.bo&&i.add(e.bo.id);if(r.bo.$instanceOf(`bpmn:SubProcess`)){let e=t=>{for(let n of t.flowElements??[])n.$type!==Q&&(i.add(n.id),n.$instanceOf(`bpmn:SubProcess`)&&e(n))};e(r.bo)}for(let e of i){let r=this.shapes.get(e)?.bounds;if(!r)continue;let i=this.boundsOf(e);r.set(`x`,i.x+t.dx),r.set(`y`,i.y+t.dy),n.moved.push({id:e,from:i,to:this.boundsOf(e)}),n.touched.push(e)}for(let e of this.flows.values()){let n=i.has(e.sourceRef?.id),r=i.has(e.targetRef?.id);if(n||r){if(n&&r){let n=this.edges.get(e.id);for(let e of n?.waypoint??[])e.set(`x`,e.x+t.dx),e.set(`y`,e.y+t.dy)}else this.reroute(e.id)}}n.summary=e(`app.cli.edit.moved`,{id:t.id,dx:t.dx,dy:t.dy})}};function se(e,t){return{index:e,operation:t,summary:``,added:[],addedFlows:[],removed:[],changed:[],moved:[],touched:[]}}function ce(t,n){let r=oe(n),i=[];return n.forEach((n,a)=>{let o=se(a,n);i.push(o);let s=r[a].find(e=>i[e].error);if(s!==void 0)o.skipped=!0,o.error=e(`app.patch.dependsOnFailed`,{number:s+1});else try{switch(n.op){case`add`:t.create(n,a,o);break;case`connect`:t.connect(n,a,o);break;case`set`:t.set(n,o);break;case`remove`:t.remove(n,o);break;case`move`:t.move(n,o)}}catch(e){if(!(e instanceof T))throw e;o.error=e.message}}),i}async function le(e,t,i){if(t.operations.length===0)return{ok:!0,xml:e,steps:[]};let a=await n(e,c(i.engine));if(!a)return{ok:!1,steps:[],failedAt:-1};let o=ce(new $(a,i.engine,i.conventions??{},i.gap),t.operations),s=o.find(e=>e.error);return s?{ok:!1,steps:o,failedAt:s.index}:{ok:!0,xml:await r(a),steps:o}}export{g as a,N as c,f as d,u as f,T as i,M as l,Z as n,_ as o,m as p,G as r,w as s,le as t,h as u};
@@ -0,0 +1 @@
1
+ import e from"node:path";import{closeSync as t,fchmodSync as n,fsyncSync as r,mkdirSync as i,openSync as a,realpathSync as o,renameSync as s,rmSync as c,statSync as l,writeFileSync as u}from"node:fs";import{randomBytes as d}from"node:crypto";const f=/* @__PURE__ */ new Set([`EPERM`,`EBUSY`,`EACCES`]);function p(e){Atomics.wait(new Int32Array(new SharedArrayBuffer(4)),0,0,e)}function m(e,t){for(let n=1;;n+=1)try{s(e,t);return}catch(e){let t=e.code;if(process.platform!==`win32`||!t||!f.has(t)||n>=6)throw e;p(20*n)}}function h(e){try{let t=o(e);return{target:t,mode:l(t).mode&4095}}catch{return{target:e,mode:void 0}}}function g(o,s,l){let{target:f,mode:p}=h(o),g=l??p;i(e.dirname(f),{recursive:!0});let _=`${f}.${process.pid}.${d(4).toString(`hex`)}.tmp`;try{let e=a(_,`w`,g);try{g!==void 0&&process.platform!==`win32`&&n(e,g),u(e,s),r(e)}finally{t(e)}m(_,f)}catch(e){throw c(_,{force:!0}),e}}export{g as t};
@@ -0,0 +1 @@
1
+ import{t as e}from"./chunk-atomicWrite-C6J1gDtO.js";import{r as t}from"./chunk-translator-BFUJmSkR.js";import{fn as n,mn as r}from"./chunk-src-BLyg_6UX.js";import i from"node:path";import{existsSync as a,readFileSync as o}from"node:fs";const s=`penstock-baseline.json`,c=`penstock-migration-baseline.json`;function l(e){return e.replace(/\\/g,`/`)}function u(e,t){return l(i.isAbsolute(t)?i.relative(e,t):t)}function d(e,t,n=!1){return`${n?l(t.file):u(e,t.file)}::${t.rule}::${t.message}`}function f(e,i){let a;try{a=JSON.parse(o(e,`utf8`))}catch(e){throw Error(t(`app.output.notValid`,{file:i,what:`JSON`,reason:r(n(e))}))}let s=a?.findings;if(!Array.isArray(s))throw Error(t(`app.output.notValid`,{file:i,what:`baseline`,reason:`it has no list of findings.`}));return s.filter(e=>typeof e?.file==`string`&&typeof e.rule==`string`&&typeof e.message==`string`)}function p(e,t,n=s){let r=i.join(e,n);if(!a(r))return{fresh:t,known:[],fixed:[]};let o=f(r,n),c=new Set(o.map(t=>d(e,t,!0))),l=new Set(t.map(t=>d(e,t)));return{fresh:t.filter(t=>!c.has(d(e,t))),known:t.filter(t=>c.has(d(e,t))),fixed:[...c].filter(e=>!l.has(e))}}function m(t,n,r=s){let a=i.join(t,r),o={generated:(/* @__PURE__ */ new Date()).toISOString(),findings:n.map(e=>({file:u(t,e.file),rule:e.rule,message:e.message})).sort((e,t)=>`${e.file}${e.rule}${e.message}`.localeCompare(`${t.file}${t.rule}${t.message}`))};return e(a,`${JSON.stringify(o,null,2)}\n`),a}export{p as n,m as r,c as t};
@@ -0,0 +1,11 @@
1
+ import{r as e}from"./chunk-translator-BFUJmSkR.js";import{o as t}from"./chunk-failure-BsimkHy_.js";import{t as n}from"./chunk-context-DPJmldqg.js";import{n as r}from"./chunk-project-qT-Fk_Rz.js";import{c as i,n as a,o,r as s,s as c,u as l}from"./chunk-git-BOKyPQj7.js";import{t as u}from"./chunk-plural-Bq_4vgOr.js";import{r as d}from"./chunk-commands-CeRlfHY-.js";import{n as f,t as p}from"./chunk-compose-BV9Jg348.js";import{r as m,t as h}from"./chunk-drawing-shRfnrs9.js";import g from"node:path";import{tmpdir as _}from"node:os";import{existsSync as v,mkdirSync as y,readFileSync as b,rmSync as x,writeFileSync as S}from"node:fs";const C=/(?:^|\s)(?:@penstock(?:\[bot\])?|\/penstock)\s*([^\n]*)/i,w=/^[A-Za-z0-9._\/ -]{1,300}\.bpmn(20\.xml)?$/;function T(e){let t=C.exec(e);if(!t)return null;let[n=``,r]=t[1].trim().split(/\s+/);switch(n.toLowerCase()){case``:case`report`:return{kind:`report`};case`check`:case`problems`:return{kind:`check`};case`diff`:case`against`:return r&&l(r)?{kind:`diff`,against:r}:{kind:`diff`};case`image`:case`picture`:case`screenshot`:return r&&w.test(r)&&!r.includes(`..`)?{kind:`image`,path:r}:{kind:`image`};default:return{kind:`help`}}}function E(){return[e(`app.cli.bot.help.intro`),``,e(`app.cli.bot.help.report`),e(`app.cli.bot.help.check`),e(`app.cli.bot.help.diff`),e(`app.cli.bot.help.image`)].join(`
2
+ `)}const D=`<!-- penstock -->`,O=/* @__PURE__ */ new Set([`OWNER`,`MEMBER`,`COLLABORATOR`]);function k(e){let t=Number(e.PENSTOCK_HTTP_TIMEOUT_MS);return Number.isFinite(t)&&t>0?t:3e4}function A(e,t){if(e)try{return new URL(e).origin===new URL(t).origin?e:void 0}catch{return}}async function j(e,t,n){let r=await fetch(t,{...n,signal:AbortSignal.timeout(k(e))});if(!r.ok)throw Error(`${n.method??`GET`} ${new URL(t).pathname}: ${r.status} ${(await r.text()).slice(0,200)}`);return r}function M(t,n,r){for(let e of n){let n=t[e];if(n)return n}throw Error(e(`app.cli.bot.${r}`,{names:n.join(` or `)}))}function N(e){return(e??``).includes(D)}function P(e){return new Blob([b(e)],{type:`image/svg+xml`})}function F(e){return/<([^>]+)>;\s*rel="next"/.exec(e.headers.get(`link`)??``)?.[1]}function I(t){let n=!!(t.GITEA_ACTIONS||t.FORGEJO_ACTIONS||t.GITHUB_SERVER_URL&&!/github\.com|ghe\.com/.test(t.GITHUB_SERVER_URL)&&t.GITHUB_API_URL?.includes(`/api/v1`)),r=t.GITHUB_API_URL??(n?`${t.GITHUB_SERVER_URL}/api/v1`:`https://api.github.com`),i=M(t,[`GITHUB_REPOSITORY`],`noRepository`),a=M(t,[`PENSTOCK_TOKEN`,`GITHUB_TOKEN`,`GITEA_TOKEN`],`noToken`),o={Authorization:n?`token ${a}`:`Bearer ${a}`,Accept:`application/json`},s=JSON.parse(b(M(t,[`GITHUB_EVENT_PATH`],`noEventPath`),`utf8`)),c=n?50:100,l=``,u=async(e,n,a)=>{let s=await j(t,`${r}/repos/${i}${n}`,{method:e,headers:{...o,...a?{"Content-Type":`application/json`}:{}},body:a?JSON.stringify(a):void 0});return s.status===204?void 0:await s.json()},d=e=>({head:e?.head?.repo?.full_name??``,base:e?.base?.repo?.full_name??``}),f=t=>e(`app.cli.bot.fromAnotherFork`,{head:t.head?e(`app.cli.bot.theFork`,{head:t.head}):e(`app.cli.bot.aForkNoLongerExists`),base:t.base});return{name:n?`gitea`:`github`,async ask(){if(t.GITHUB_EVENT_NAME===`issue_comment`){if(s.action!==`created`||!s.issue?.pull_request||s.comment?.user?.type===`Bot`||N(s.comment?.body))return null;let e=s.comment?.author_association;if(typeof e==`string`?!O.has(e):!n)return null;l=String(s.issue.number);let t=await u(`GET`,`/pulls/${l}`),r=d(t),i={number:l,base:t.base.sha,head:`refs/pull/${l}/head`,command:s.comment.body};return r.head===r.base?i:{...i,refuse:f(r)}}let e=s.pull_request;if(!e)return null;l=String(e.number);let r=d(e),i={number:l,base:e.base.sha,head:`refs/pull/${l}/head`,command:t.PENSTOCK_COMMAND};return r.head===r.base?i:{...i,refuse:f(r)}},async comments(e){let a=[],s=1,u=`${r}/repos/${i}/issues/${l}/comments?per_page=100${n?`&limit=${c}`:``}&page=${s}`;for(;u&&s<=200;){let d=await j(t,u,{headers:o}),f=await d.json();for(let t of f){let n={id:String(t.id),body:t.body??``};if(a.push(n),e(n))return a}let p=A(F(d),r);p?(s+=1,u=p):(s+=1,u=f.length<c?void 0:`${r}/repos/${i}/issues/${l}/comments?per_page=100${n?`&limit=${c}`:``}&page=${s}`)}return a},async post(e){await u(`POST`,`/issues/${l}/comments`,{body:e})},async edit(e,t){await u(`PATCH`,`/issues/comments/${e}`,{body:t})},async attach(e){if(!n)return null;let a=new FormData;return a.append(`attachment`,P(e),g.basename(e)),(await(await j(t,`${r}/repos/${i}/issues/${l}/assets?name=${encodeURIComponent(g.basename(e))}`,{method:`POST`,headers:o,body:a})).json()).browser_download_url||null},picturesLink(){if(t.GITHUB_RUN_ID)return`${t.GITHUB_SERVER_URL??`https://github.com`}/${i}/actions/runs/${t.GITHUB_RUN_ID}`}}}function L(e){let t=M(e,[`CI_API_V4_URL`],`noGitLabApi`),n={"PRIVATE-TOKEN":M(e,[`PENSTOCK_TOKEN`,`GITLAB_TOKEN`],`noGitLabToken`)},r=e.TRIGGER_PAYLOAD?JSON.parse(b(e.TRIGGER_PAYLOAD,`utf8`)):null,i=encodeURIComponent(String(r?.project?.id??M(e,[`CI_PROJECT_ID`],`noGitLabProject`))),a=``,o=async(r,a,o)=>await(await j(e,`${t}/projects/${i}${a}`,{method:r,headers:{...n,...o?{"Content-Type":`application/json`}:{}},body:o?JSON.stringify(o):void 0})).json();return{name:`gitlab`,async ask(){if(r){if(r.object_kind!==`note`||r.object_attributes?.noteable_type!==`MergeRequest`||N(r.object_attributes.note)||r.user?.bot)return null;let e=r.merge_request;return a=String(e.iid),{number:a,base:`origin/${e.target_branch}`,head:`refs/merge-requests/${a}/head`,command:r.object_attributes.note}}return e.CI_MERGE_REQUEST_IID?(a=e.CI_MERGE_REQUEST_IID,{number:a,base:e.CI_MERGE_REQUEST_DIFF_BASE_SHA??`origin/${e.CI_MERGE_REQUEST_TARGET_BRANCH_NAME}`,command:e.PENSTOCK_COMMAND}):null},async comments(r){let o=[],s=1;for(;s<=200;){let c=await j(e,`${t}/projects/${i}/merge_requests/${a}/notes?per_page=100&page=${s}`,{headers:n}),l=await c.json();for(let e of l){let t={id:String(e.id),body:e.body??``};if(o.push(t),r(t))return o}if(!c.headers.get(`x-next-page`)&&l.length<100)return o;s+=1}return o},async post(e){await o(`POST`,`/merge_requests/${a}/notes`,{body:e})},async edit(e,t){await o(`PUT`,`/merge_requests/${a}/notes/${e}`,{body:t})},async attach(r){let a=new FormData;return a.append(`file`,P(r),g.basename(r)),(await(await j(e,`${t}/projects/${i}/uploads`,{method:`POST`,headers:n,body:a})).json()).url||null},picturesLink(){return e.CI_JOB_URL?`${e.CI_JOB_URL}/artifacts/browse`:void 0}}}function R(e){let t=e.BITBUCKET_API_URL??`https://api.bitbucket.org/2.0`,n=M(e,[`BITBUCKET_REPO_FULL_NAME`],`noBitbucketRepo`),r=M(e,[`BITBUCKET_PR_ID`],`noBitbucketPr`),i={Authorization:`Bearer ${M(e,[`PENSTOCK_TOKEN`,`BITBUCKET_TOKEN`],`noBitbucketToken`)}`,"Content-Type":`application/json`},a=`${t}/repositories/${n}/pullrequests/${r}/comments`;return{name:`bitbucket`,async ask(){return{number:r,base:`origin/${M(e,[`BITBUCKET_PR_DESTINATION_BRANCH`],`noBitbucketBranch`)}`,command:e.PENSTOCK_COMMAND}},async comments(n){let r=[],o=`${a}?pagelen=100`,s=0;for(;o&&s++<200;){let a=await(await j(e,o,{headers:i})).json();for(let e of a.values){let t={id:String(e.id),body:e.content?.raw??``};if(r.push(t),n(t))return r}o=A(a.next,t)}return r},async post(t){await j(e,a,{method:`POST`,headers:i,body:JSON.stringify({content:{raw:t}})})},async edit(t,n){await j(e,`${a}/${t}`,{method:`PUT`,headers:i,body:JSON.stringify({content:{raw:n}})})},async attach(){return null},picturesLink(){let t=e.BITBUCKET_WORKSPACE;return e.BITBUCKET_BUILD_NUMBER&&t?`https://bitbucket.org/${n}/pipelines/results/${e.BITBUCKET_BUILD_NUMBER}`:void 0}}}function z(e){let t=M(e,[`SYSTEM_COLLECTIONURI`],`noAzureCollection`).replace(/\/$/,``),n=encodeURIComponent(M(e,[`SYSTEM_TEAMPROJECT`],`noAzureProject`)),r=M(e,[`BUILD_REPOSITORY_ID`],`noAzureRepository`),i=M(e,[`SYSTEM_PULLREQUEST_PULLREQUESTID`],`noAzurePullRequest`),a={Authorization:`Bearer ${M(e,[`PENSTOCK_TOKEN`,`SYSTEM_ACCESSTOKEN`],`noAzureToken`)}`},o=`${t}/${n}/_apis/git/repositories/${r}/pullRequests/${i}`,s=async(t,n,r)=>await(await j(e,n,{method:t,headers:{...a,"Content-Type":`application/json`},body:r?JSON.stringify(r):void 0})).json();return{name:`azure`,async ask(){let t=M(e,[`SYSTEM_PULLREQUEST_TARGETBRANCH`],`noAzureBranch`).replace(/^refs\/heads\//,``);return{number:i,base:`origin/${t}`,command:e.PENSTOCK_COMMAND}},async comments(e){let t=await s(`GET`,`${o}/threads?api-version=7.1`),n=[];for(let r of t.value){if(!r.comments[0])continue;let t={id:`${r.id}/${r.comments[0].id}`,body:r.comments[0].content??``};if(n.push(t),e(t))return n}return n},async post(e){await s(`POST`,`${o}/threads?api-version=7.1`,{comments:[{parentCommentId:0,content:e,commentType:1}],status:1})},async edit(e,t){let[n,r]=e.split(`/`);await s(`PATCH`,`${o}/threads/${n}/comments/${r}?api-version=7.1`,{content:t})},async attach(t){return(await(await j(e,`${o}/attachments/${encodeURIComponent(g.basename(t))}?api-version=7.1-preview.1`,{method:`POST`,headers:{...a,"Content-Type":`application/octet-stream`},body:b(t)})).json()).url||null},picturesLink(){return e.BUILD_BUILDID?`${t}/${n}/_build/results?buildId=${e.BUILD_BUILDID}&view=artifacts`:void 0}}}function B(e){return e.GITHUB_ACTIONS||e.GITEA_ACTIONS||e.FORGEJO_ACTIONS?I(e):e.GITLAB_CI?L(e):e.BITBUCKET_BUILD_NUMBER?R(e):e.TF_BUILD?z(e):null}const V=`{{penstock-pictures}}`;function H(t,n){let i=[],a=[];return{pictures:i,notes:a,async add(o,s){let c;try{let t=await h(b(o.after,`utf8`),s);c=t.svg,t.skipped.length>0&&a.push(`**${o.relative}**: ${e(`app.cli.bot.elementsNotDrawn`,{elements:u(t.skipped.length,`app.cli.bot.count.element`),ids:t.skipped.map(e=>`\`${e}\``).join(`, `)})}`)}catch(t){return a.push(e(`app.cli.bot.noPictureBecause`,{file:o.relative,reason:t instanceof Error?t.message:String(t)})),null}i.push({title:o.relative,svg:c});let l=g.join(n,`${i.length}-${r(o.relative)}.svg`);return S(l,c),t.attach(l)}}}function U(e,t){return t.length===0?e:`${e.trimEnd()}\n\n${t.map(e=>`> ${e}`).join(`
3
+ >
4
+ `)}\n`}const W=/\[([^\]]*)\]\(\{\{penstock-pictures\}\}\)/g;function G(t,n){return n?t.replace(W,`[$1](${n})`):t.includes(`](${V})`)?`${t.split(`
5
+ `).filter(e=>!e.includes(`](${V})`)).join(`
6
+ `).trimEnd()}\n\n${e(`app.cli.bot.picturesInArtifacts`)}`:t}function K(t){return`${t.split(`
7
+ `).filter(e=>!e.includes(`](${V})`)).join(`
8
+ `).trimEnd()}\n\n${e(`app.cli.report.noPictures`)}\n`}async function q(e,t,n,r){let{changed:i,removed:a}=s(e,t),o=H(n,r),c=await f({changed:i.slice(0,40),removed:a,picture:o.add,picturesLink:V});return{body:U(o.pictures.length>0?c.markdown:K(c.markdown),o.notes),pictures:o.pictures}}async function J(t,n,r,a,o){switch(n.kind){case`help`:return{body:E(),upsert:!1,pictures:[]};case`report`:return{...await q(t,r,a,o),upsert:!0};case`diff`:{if(!n.against)return{body:e(`app.cli.bot.sayWhatToCompareWith`),upsert:!1,pictures:[]};let r=i(t,n.against);if(!r)return{body:e(`app.cli.bot.couldNotFindRef`,{ref:n.against}),upsert:!1,pictures:[]};let s=await q(t,r,a,o);return{body:s.body.replace(p,``).replace(e(`app.cli.report.heading`),e(`app.cli.bot.diagramsChangedSince`,{ref:n.against})),upsert:!1,pictures:s.pictures}}case`check`:{let{changed:n}=s(t,r);if(n.length===0)return{body:e(`app.cli.bot.noDiagramChangedHere`),upsert:!1,pictures:[]};let i=(await d(n.map(e=>e.after),{format:`json`,baseline:!0,updateBaseline:!1})).reported;return i.length===0?{body:e(`app.cli.bot.cleanAgainstTheBaseline`),upsert:!1,pictures:[]}:{body:i.map(e=>`- **${g.relative(t,e.file)}** \`${e.rule}\` ${e.message}`).join(`
9
+ `),upsert:!1,pictures:[]}}case`image`:{let i=n.path?[n.path]:s(t,r).changed.map(e=>e.relative);if(i.length===0)return{body:e(`app.cli.bot.noDiagramToDraw`),upsert:!1,pictures:[]};let c=H(a,o),l=[],u=[];for(let n of i.slice(0,40)){let r=g.join(t,n);if(!v(r)){l.push(e(`app.cli.bot.notInThisChange`,{file:n}));continue}let i=await c.add({relative:n,after:r},{});i?l.push(`**${n}**\n\n![${n}](${i})`):u.push(n)}return u.length>0&&l.push(e(`app.cli.bot.drawnButNotShown`,{files:u.map(e=>`**${e}**`).join(`, `),open:e(`app.cli.bot.openThem`),link:V})),{body:U(l.join(`
10
+
11
+ `),c.notes),upsert:!1,pictures:c.pictures}}}}function Y(e){return g.join(e.PENSTOCK_BOT_DIR??e.RUNNER_TEMP??_(),`penstock-bot`)}const X=e=>e.body.includes(`<!-- penstock -->`)||e.body.includes(`<!-- penstock-report -->`);async function Z(e,t,n){let r=`${D}\n${G(t.body,n)}`;if(t.upsert){let t=(await e.comments(X)).find(X);if(t){await e.edit(t.id,r);return}}await e.post(r)}async function Q(e,n,r=process.env){try{return await $(e,n,r)}catch(e){return{ok:!1,lines:[t(e)]}}}async function $(t,r,s){let{root:l}=n(t);if(!c(l))return{ok:!1,lines:[e(`app.cli.bot.notAGitCheckout`)]};let u;try{u=B(s)}catch(e){return{ok:!1,lines:[e instanceof Error?e.message:String(e)]}}if(!u)return{ok:!1,lines:[e(`app.cli.bot.unknownCi`)]};let d=Y(s);r!==`post`&&x(d,{recursive:!0,force:!0});let f=await u.ask();if(!f)return{ok:!0,lines:[e(`app.cli.bot.nothingToAnswer`)]};if(r===`post`){let t=g.join(d,`answer.json`);return v(t)?(await Z(u,JSON.parse(b(t,`utf8`)),s.PENSTOCK_PICTURES_URL||u.picturesLink()),{ok:!0,lines:[e(`app.cli.bot.answeredOn`,{platform:u.name})]}):{ok:!0,lines:[e(`app.cli.bot.nothingDrawn`)]}}if(f.refuse){let t={body:f.refuse,upsert:!1,pictures:[]};return r===`draw`?(y(d,{recursive:!0}),S(g.join(d,`answer.json`),JSON.stringify(t)),{ok:!0,lines:[e(`app.cli.bot.refusedSaved`)]}):(await Z(u,t,void 0),{ok:!0,lines:[e(`app.cli.bot.answeredOn`,{platform:u.name})]})}let p=f.command===void 0?{kind:`report`}:T(f.command);if(!p)return{ok:!0,lines:[e(`app.cli.bot.notForPenstock`)]};if(f.head&&!o(l,f.head)&&!a(l,f.head))return{ok:!1,lines:[e(`app.cli.bot.couldNotCheckOut`,{ref:f.head})]};let h=i(l,f.base);if(!h)return{ok:!1,lines:[e(`app.cli.bot.baseNotFound`,{base:f.base})]};y(d,{recursive:!0});let _;try{_=await J(l,p,h,u,d)}catch(t){_={body:e(`app.cli.bot.couldNotDoThat`,{reason:t instanceof Error?t.message:String(t)}),upsert:!1,pictures:[]}}let C=[];if(_.pictures.length>0){let t=g.join(d,`penstock-diagrams.svg`);S(t,m(_.pictures)),C.push(e(`app.cli.bot.drew`,{file:t}))}return r===`draw`?(S(g.join(d,`answer.json`),JSON.stringify(_)),{ok:!0,lines:[...C,e(`app.cli.bot.answerSaved`)]}):(await Z(u,_,s.PENSTOCK_PICTURES_URL||u.picturesLink()),{ok:!0,lines:[...C,e(`app.cli.bot.answeredOn`,{platform:u.name})]})}export{Q as botCommand};
@@ -0,0 +1 @@
1
+ import e from"node:path";import{homedir as t}from"node:os";function n(n=process.env,r=process.platform,i=t()){return r===`darwin`?e.join(i,`Library`,`Caches`,`penstock`,`syntax`):r===`win32`?e.join(n.LOCALAPPDATA||e.join(i,`AppData`,`Local`),`penstock`,`Cache`,`syntax`):e.join(n.XDG_CACHE_HOME||e.join(i,`.cache`),`penstock`,`syntax`)}export{n as t};
@@ -0,0 +1 @@
1
+ import{_t as e,en as t,f as n,ft as r,gt as i,h as a,ht as o,m as s,p as c,r as l}from"./chunk-src-BLyg_6UX.js";import{i as u,t as d}from"./chunk-codeIndex-CzENd6hG.js";import f from"node:path";const p=/[\\/]/,m=/^[A-Za-z_][\w$]*(\.[A-Za-z_][\w$]*)*$/;function h(e,t){let n=e.split(p).map(e=>encodeURIComponent(e));return`${process.platform===`win32`?`file:///`:`file://`}${n.join(`/`)}#L${Math.max(1,t)}`}function g(e){let t=/#L(\d+)$/.exec(e)?.[1];return t?Number(t):null}function _(e){let[t]=e.split(`#`);return decodeURIComponent(t.replace(/^file:\/\//,``))}function v(e,t){return t&&m.test(t)?t:`${f.basename(e.file)}:${e.line}`}const y=/* @__PURE__ */ new Set([`JOB_TYPE`,`TOPIC`,`CLASS`,`BEAN`,`ERROR`]),b={CLASS:`CLASS`,BEAN:`CLASS`,JOB_TYPE:`METHOD`,TOPIC:`METHOD`};function x(e,t){let n=/* @__PURE__ */ new Set;return[...o(e,t),...i(e,t)].filter(e=>{let t=`${e.file}#${e.offset}`;return!n.has(t)&&(n.add(t),!0)})}function S(e,n){let r=/* @__PURE__ */ new Map;for(let i of n){let n=o(e,i);n.length>0&&r.set(t(i),n)}return r}function C(e,t,n){return x(e,t).flatMap(e=>{let i=n(e);return i?[{handle:i,label:v(e,t.kind===`CLASS`?t.value:void 0),icon:b[t.kind]??`FILE`,implements:t.kind===`VARIABLE`?e.writes===!0:y.has(t.kind),test:r(e.file)}]:[]})}function w(e,t){let n=new Map(e.map(e=>[e.path,a(e)])),r=/* @__PURE__ */ new Map;for(let e of t){let t=s(n.get(e.file)??[],e.file,e.offset);t&&r.set(`${t.path}#${t.offset}`,t)}return{workers:l(e),classes:[...r.values()],camunda7Imports:e.flatMap(e=>{let t=c(e);return t.length>0?[{path:e.path,names:t}]:[]})}}async function T(e,t,n=u()){return w(await n.factsOf(e),t)}async function E(t,n=u()){let r=await n.factsOf(t),i=w(r,[]);return{protocol:1,workers:i.workers,classes:i.classes,camunda7Imports:i.camunda7Imports,types:e(r,i.workers.flatMap(e=>(e.variables??[]).map(e=>e.type)))}}async function D(e,t){let r=await d(t.map(e=>({file:e.path,text:e.text})));return{index:r,facts:await T(t,[...S(r,await n(e)).values()].flat())}}export{h as a,C as i,E as n,g as o,D as r,_ as s,T as t};
@@ -0,0 +1 @@
1
+ import{bt as e,ut as t,yt as n}from"./chunk-src-BLyg_6UX.js";import{createRequire as r}from"node:module";import i from"node:path";import{availableParallelism as a}from"node:os";import{existsSync as o}from"node:fs";import{createHash as s,randomUUID as c}from"node:crypto";import{mkdir as ee,readFile as l,rename as te,writeFile as ne}from"node:fs/promises";import{Worker as re}from"node:worker_threads";const ie=/* @__PURE__ */ new Map([[`java`,`java`],[`kt`,`kotlin`],[`kts`,`kotlin`],[`ts`,`typescript`],[`js`,`javascript`],[`mjs`,`javascript`],[`cjs`,`javascript`],[`py`,`python`],[`go`,`go`],[`cs`,`csharp`],[`groovy`,`groovy`],[`scala`,`scala`]]);function u(e){let t=e.lastIndexOf(`.`);return t<0?null:ie.get(e.slice(t+1))??null}function ae(e,t){return i.join(e,t.slice(0,2),`${t}.json`)}function oe(e){return{async read(t){try{return JSON.parse(await l(ae(e,t),`utf8`))}catch{return null}},async write(t,n){let r=ae(e,t);try{await ee(i.dirname(r),{recursive:!0});let e=`${r}.${process.pid}.${c()}.tmp`;await ne(e,JSON.stringify(n)),await te(e,r)}catch{return}}}}const se={java:{package:`@vscode/tree-sitter-wasm`,file:`wasm/tree-sitter-java.wasm`},kotlin:{package:`@tree-sitter-grammars/tree-sitter-kotlin`,file:`tree-sitter-kotlin.wasm`},typescript:{package:`@vscode/tree-sitter-wasm`,file:`wasm/tree-sitter-typescript.wasm`},javascript:{package:`@vscode/tree-sitter-wasm`,file:`wasm/tree-sitter-javascript.wasm`},python:{package:`@vscode/tree-sitter-wasm`,file:`wasm/tree-sitter-python.wasm`},go:{package:`@vscode/tree-sitter-wasm`,file:`wasm/tree-sitter-go.wasm`},csharp:{package:`@vscode/tree-sitter-wasm`,file:`wasm/tree-sitter-c-sharp.wasm`},groovy:{package:`tree-sitter-groovy`,file:`tree-sitter-groovy.wasm`},scala:{package:`tree-sitter-scala`,file:`tree-sitter-scala.wasm`}},ce=`web-tree-sitter.wasm`;function le(e){let t=Object.fromEntries(Object.entries(se).map(([t,{file:n}])=>[t,i.join(e,i.basename(n))]));return{runtimeFile:i.join(e,ce),grammarFiles:t}}function ue(){let e=i.join(import.meta.dirname,`grammars`);if(o(i.join(e,ce)))return le(e);let t=r(import.meta.url),n=Object.fromEntries(Object.entries(se).map(([e,{package:n,file:r}])=>[e,t.resolve(`${n}/${r}`)]));return{runtimeFile:t.resolve(`web-tree-sitter/web-tree-sitter.wasm`),grammarFiles:n}}const de=/* @__PURE__ */ new Set([`string`,`string_literal`,`interpreted_string_literal`,`raw_string_literal`]),fe=/* @__PURE__ */ new Set([`array`,`array_literal`,`list`,`collection_literal`,`element_value_array_initializer`,`array_initializer`]),pe=[`"""`,`'''`,`"`,`'`,"`"],me=/* @__PURE__ */ new Set([`identifier`,`property_identifier`,`field_identifier`,`shorthand_property_identifier`]),he={attribute:`attribute`,selector_expression:`field`,member_access_expression:`name`,field_expression:`field`,member_expression:`property`},d=e=>({from:e.startIndex,to:e.endIndex}),f=(e,t)=>e.children.filter(e=>e.type===t),p=(e,t)=>e.children.find(e=>e.type===t)??null,m=(e,t)=>e.childForFieldName(t),h=e=>e?.text??null,g=e=>e.type.includes(`comment`),_=(e,t)=>t!==null&&e.type===t.type&&e.startIndex===t.startIndex&&e.endIndex===t.endIndex;function v(e){return e.type===`generic_type`||e.type===`generic_name`?e.firstNamedChild?.text??e.text:e.text}function y(e){if(e===null||!de.has(e.type))return null;let t=e.text;for(let e of pe)if(t.length>=e.length*2&&t.startsWith(e)&&t.endsWith(e))return t.slice(e.length,-e.length);return null}function ge(e){return fe.has(e.type)?e.namedChildren.flatMap(e=>y(e)??[]):null}function _e(e){let t=he[e.type];return t===void 0?null:m(e,t)?.text??null}function b(e,t){return{text:e.text,value:y(e),values:ge(e),identifier:me.has(e.type)?e.text:null,reference:_e(e),constructs:t(e),span:d(e)}}function x(e,t,n){return{...b(e,n),name:t,at:e.startIndex}}function S(e,t,n,r){let i=y(e);return{key:i??e.text,quoted:i!==null,at:e.startIndex,object:n.startIndex,value:b(t,r)}}function C(e,t,n,r){return{receiver:t.text,name:n?.text??null,key:y(r),keyAt:y(r)===null?null:r?.startIndex??null,at:e.startIndex,span:d(e)}}function w(e){return e.sort((e,t)=>e.at-t.at)}function ve(e,t){return{name:m(e,`name`)?.text??e.text.replace(/^@/,``),at:e.startIndex,arguments:t(e)}}const ye=/* @__PURE__ */ new WeakMap,be=/* @__PURE__ */ new WeakMap;function xe(e){let t=ye.get(e);if(t===void 0){t=/* @__PURE__ */ new Map;let n=[e.rootNode];for(let e=n.pop();e!==void 0;e=n.pop())for(let r of e.children)t.set(r.id,e),n.push(r);ye.set(e,t)}return t}function T(e){return xe(e.tree).get(e.id)??null}function Se(e,t){let n=be.get(e);n===void 0&&(n=/* @__PURE__ */ new Map,be.set(e,n));let r=n.get(t);return r===void 0&&(r=/* @__PURE__ */ new Map,n.set(t,r)),r}function Ce(e,t){let n=Se(e.tree,t),r=xe(e.tree),i=[],a=e;for(;a!==null&&!n.has(a.id);)i.push(a),a=r.get(a.id)??null;let o=a,s=a===null?null:n.get(a.id)??null;for(let e=i.length-1;e>=0;--e){let r=o!==null&&t.has(o.type)?o:s;n.set(i[e].id,r),o=i[e],s=r}return n.get(e.id)??null}function E(e,t){let n=Ce(e,t);return n===null?null:m(n,`name`)?.text??null}function D(e,t){return Ce(e,t)!==null}const we=/* @__PURE__ */ new Set([`method_declaration`,`local_function_statement`,`constructor_declaration`]),Te=/* @__PURE__ */ new Set([`member_access_expression`,`element_access_expression`]),Ee=/* @__PURE__ */ new Set([`object_creation_expression`,`implicit_object_creation_expression`]),De={class_declaration:`class`,record_declaration:`record`,struct_declaration:`struct`,enum_declaration:`enum`};function O(e){let t=e.type===`object_creation_expression`?m(e,`type`):null;return t===null?null:v(t)}const Oe=e=>e===null?null:b(e,O);function ke(e){return(p(e,`attribute_argument_list`)?.namedChildren??[]).map(e=>{let t=p(e,`name_equals`);return{...b(e.namedChildren.find(e=>e.type!==`name_equals`)??e,O),name:t?.namedChildren[0]?.text??null,at:e.startIndex}})}function k(e){return f(e,`attribute_list`).flatMap(e=>f(e,`attribute`).map(e=>({name:m(e,`name`)?.text??e.text,at:e.startIndex,arguments:ke(e)})))}function A(e){return f(e,`modifier`).map(e=>e.text)}function Ae(e){let t=m(e,`name`);return t===null?[]:[{kind:`field`,name:t.text,type:m(e,`type`)?.text??null,at:t.startIndex,modifiers:A(e),annotations:k(e),arity:0,tag:null}]}function je(e){let t=p(e,`variable_declaration`);if(t===null)return[];let n=m(t,`type`)?.text??null;return f(t,`variable_declarator`).flatMap(t=>{let r=m(t,`name`);return r===null?[]:[{kind:`field`,name:r.text,type:n,at:r.startIndex,modifiers:A(e),annotations:k(e),arity:0,tag:null}]})}function Me(e){return e.namedChildren.filter(e=>e.type===`parameter`).flatMap(e=>{let t=m(e,`name`);return t===null?[]:[{kind:`parameter`,name:t.text,type:m(e,`type`)?.text??null,at:t.startIndex,modifiers:[],annotations:k(e),arity:0,tag:null}]})}function Ne(e){return e.namedChildren.flatMap(e=>e.type===`property_declaration`?Ae(e):e.type===`field_declaration`?je(e):[])}function Pe(e){return(p(e,`base_list`)?.namedChildren??[]).map(e=>({name:v(e),relation:`extends`}))}function Fe(e,t){let n=m(e,`name`);if(n===null)return null;let r=m(e,`body`),i=p(e,`parameter_list`),a=[...i===null?[]:Me(i),...r===null||t===`enum`?[]:Ne(r)];return{kind:t,name:n.text,at:n.startIndex,span:d(e),modifiers:A(e),annotations:k(e),supertypes:Pe(e),generic:p(e,`type_parameter_list`)!==null,members:a,constants:t===`enum`&&r!==null?f(r,`enum_member_declaration`).map(e=>m(e,`name`)?.text??``).filter(e=>e!==``):[]}}function Ie(e){return e.descendantsOfType(Object.keys(De)).flatMap(e=>Fe(e,De[e.type])??[])}const Le=/* @__PURE__ */ new Set([`class_declaration`,`record_declaration`,`struct_declaration`]),Re={method_declaration:`method`,constructor_declaration:`constructor`};function ze(e){return(e?.namedChildren??[]).filter(e=>e.type===`parameter`).flatMap(e=>{let t=m(e,`name`);return t===null?[]:[{name:t.text,type:h(m(e,`type`)),at:t.startIndex,annotations:k(e)}]})}function Be(e){return e.descendantsOfType(Object.keys(Re)).flatMap(e=>{let t=m(e,`name`);return t===null?[]:[{kind:Re[e.type],name:t.text,at:t.startIndex,span:d(e),owner:E(e,Le),annotations:k(e),parameters:ze(m(e,`parameters`)),returnType:h(m(e,`returns`))}]})}function Ve(){return null}function He(e){return e.descendantsOfType(`variable_declaration`).filter(e=>T(e)?.type===`local_declaration_statement`&&D(e,we)).flatMap(e=>{let t=m(e,`type`);return f(e,`variable_declarator`).flatMap(e=>{let n=m(e,`name`);if(n===null)return[];let r=e.namedChildren.find(e=>!_(e,n))??null;return[{name:n.text,key:null,type:t===null||t.type===`implicit_type`?null:t.text,at:n.startIndex,initializer:Oe(r)}]})})}function Ue(e){return e.descendantsOfType(`return_statement`).map(e=>({at:e.startIndex,span:d(e),expression:Oe(e.namedChildren.find(e=>!g(e))??null)}))}function We(e){let t=T(e);return t!==null&&Te.has(t.type)&&_(e,m(t,`expression`))}function Ge(e){let t=T(e);return t===null?!1:We(e)||t.type===`invocation_expression`&&_(e,m(t,`function`))}function Ke(e){let t=m(e,`expression`);if(t===null)return[];if(e.type===`element_access_expression`)return[C(e,t,null,m(e,`subscript`)?.namedChildren[0]?.namedChildren[0]??null)];let n=m(e,`name`);return n===null?[]:[C(e,t,n,null)]}function qe(e){return w(e.descendantsOfType([...Te]).filter(e=>!Ge(e)).flatMap(Ke))}function Je(e){return w(e.descendantsOfType([...Te]).filter(We).flatMap(Ke))}function Ye(e){let t=T(e);return t!==null&&Ee.has(t.type)?t:e}function Xe(e){let t=T(e);if(t===null||t.type!==`initializer_expression`)return[];if(e.type===`initializer_expression`&&e.namedChildren.length===2){let[n,r]=e.namedChildren;return[S(n,r,Ye(t),O)]}let n=m(e,`left`),r=m(e,`right`);return e.type===`assignment_expression`&&n?.type===`identifier`&&r!==null?[S(n,r,Ye(t),O)]:[]}function Ze(e){return w(e.descendantsOfType([`initializer_expression`,`assignment_expression`]).flatMap(Xe))}function Qe(e){return(e?.namedChildren??[]).filter(e=>e.type===`argument`).map(e=>{let t=p(e,`name_colon`);return x(e.namedChildren.find(e=>e.type!==`name_colon`)??e,t?.namedChildren[0]?.text??null,O)})}function $e(e){let t=m(e,`function`);if(t===null)return null;let n=t.type===`member_access_expression`,r=n?m(t,`name`):t,i=r?.type===`generic_name`?r.firstNamedChild:r;return i==null||i.type!==`identifier`?null:{receiver:n?h(m(t,`expression`)):null,name:i.text,arguments:Qe(m(e,`arguments`)),at:i.startIndex,span:d(e),within:E(e,we)}}function et(e){return e.descendantsOfType(`invocation_expression`).flatMap(e=>$e(e)??[])}function tt(e){return e.descendantsOfType(`object_creation_expression`).flatMap(e=>{let t=m(e,`type`);return t===null?[]:[{type:v(t),arguments:Qe(m(e,`arguments`)),at:t.startIndex,span:d(e),within:E(e,we)}]})}function nt(e){return e.descendantsOfType(`using_directive`).flatMap(e=>{let t=e.namedChildren.filter(e=>e.type===`identifier`||e.type===`qualified_name`).at(-1);return t===void 0?[]:[{name:t.text,at:t.startIndex}]})}function rt(e){return e.descendantsOfType(`field_declaration`).flatMap(e=>{if(!A(e).includes(`const`))return[];let t=E(e,Le),n=p(e,`variable_declaration`);return n===null?[]:f(n,`variable_declarator`).flatMap(e=>{let n=m(e,`name`),r=y(e.namedChildren.at(-1)??null);return n===null||r===null?[]:[{name:n.text,value:r,owner:t,at:n.startIndex}]})})}const it=/* @__PURE__ */ new Set([`function_declaration`,`method_declaration`,`func_literal`]),at=/* @__PURE__ */ new Set([`selector_expression`,`index_expression`]);function ot(e){let t=e.type===`unary_expression`?e.namedChildren[0]??null:e;return t?.type===`composite_literal`?h(m(t,`type`)):null}const j=e=>e===null?null:b(e,ot);function st(e){return e===null?null:e.text.slice(1,-1)}function ct(e){return e.namedChildren.filter(e=>e.type===`field_declaration`).flatMap(e=>{let t=m(e,`type`),n=st(m(e,`tag`)),r=f(e,`field_identifier`);return r.length===0?t===null?[]:[{kind:`embedded`,name:t.text,type:t.text,at:t.startIndex,modifiers:[],annotations:[],arity:0,tag:n}]:r.map(e=>({kind:`field`,name:e.text,type:t?.text??null,at:e.startIndex,modifiers:[],annotations:[],arity:0,tag:n}))})}function lt(e){let t=m(e,`name`),n=m(e,`type`);if(t===null||n===null||n.type!==`struct_type`)return null;let r=p(n,`field_declaration_list`);return{kind:`struct`,name:t.text,at:t.startIndex,span:d(e),modifiers:[],annotations:[],supertypes:[],generic:m(e,`type_parameters`)!==null,members:r===null?[]:ct(r),constants:[]}}function ut(e){return e.descendantsOfType(`type_spec`).flatMap(e=>lt(e)??[])}function dt(e){let t=m(e,`receiver`)?.namedChildren[0]??null,n=t===null?null:m(t,`type`);return n===null?null:n.text.replace(/^\*/,``)}function ft(e){return(e?.namedChildren??[]).flatMap(e=>{if(e.type!==`parameter_declaration`&&e.type!==`variadic_parameter_declaration`)return[];let t=h(m(e,`type`));return f(e,`identifier`).map(e=>({name:e.text,type:t,at:e.startIndex,annotations:[]}))})}function pt(e){return e.descendantsOfType([`function_declaration`,`method_declaration`]).flatMap(e=>{let t=m(e,`name`);if(t===null)return[];let n=e.type===`method_declaration`;return[{kind:n?`method`:`function`,name:t.text,at:t.startIndex,span:d(e),owner:n?dt(e):null,annotations:[],parameters:ft(m(e,`parameters`)),returnType:h(m(e,`result`))}]})}function mt(e){return p(e.namedChildren.find(e=>e.type===`package_clause`)??e,`package_identifier`)?.text??null}function ht(e){let t=[];for(let n of e.descendantsOfType(`short_var_declaration`).filter(e=>D(e,it))){let e=m(n,`right`)?.namedChildren??[];m(n,`left`)?.namedChildren.forEach((n,r)=>{n.type===`identifier`&&t.push({name:n.text,key:null,type:null,at:n.startIndex,initializer:j(e[r]??null)})})}for(let n of e.descendantsOfType(`var_spec`).filter(e=>D(e,it))){let e=m(n,`value`)?.namedChildren??[],r=h(m(n,`type`));f(n,`identifier`).forEach((n,i)=>t.push({name:n.text,key:null,type:r,at:n.startIndex,initializer:j(e[i]??null)}))}return t.sort((e,t)=>e.at-t.at)}function gt(e){return e.descendantsOfType(`return_statement`).map(e=>{let t=e.namedChildren[0]??null,n=t?.type===`expression_list`?t.namedChildren.length===1?t.namedChildren[0]:null:t;return{at:e.startIndex,span:d(e),expression:j(n)}})}function _t(e){let t=T(e);return t!==null&&at.has(t.type)&&_(e,m(t,`operand`))}function vt(e){let t=T(e);return t===null?!1:_t(e)||t.type===`call_expression`&&_(e,m(t,`function`))}function yt(e){let t=m(e,`operand`);if(t===null)return[];if(e.type===`index_expression`)return[C(e,t,null,m(e,`index`))];let n=m(e,`field`);return n===null?[]:[C(e,t,n,null)]}function bt(e){return w(e.descendantsOfType([...at]).filter(e=>!vt(e)).flatMap(yt))}function xt(e){return w(e.descendantsOfType([...at]).filter(_t).flatMap(yt))}function St(e){let t=T(e)??e,n=T(t);return n?.type===`composite_literal`?n:t}function Ct(e){return e.descendantsOfType(`keyed_element`).flatMap(e=>{let t=m(e,`key`)?.namedChildren[0]??null,n=m(e,`value`)?.namedChildren[0]??null;return t===null||n===null?[]:[S(t,n,St(e),ot)]})}function wt(e){return(e?.namedChildren??[]).filter(e=>!g(e)).map(e=>x(e,null,ot))}function Tt(e){let t=m(e,`function`);if(t===null)return null;let n=t.type===`selector_expression`,r=n?m(t,`field`):t;return r===null||r.type!==`identifier`&&r.type!==`field_identifier`?null:{receiver:n?h(m(t,`operand`)):null,name:r.text,arguments:wt(m(e,`arguments`)),at:r.startIndex,span:d(e),within:E(e,it)}}function Et(e){return e.descendantsOfType(`call_expression`).flatMap(e=>Tt(e)??[])}function Dt(e){return e.descendantsOfType(`import_spec`).flatMap(e=>{let t=m(e,`path`),n=y(t);return t===null||n===null?[]:[{name:n,at:t.startIndex}]})}function Ot(e){return e.descendantsOfType(`const_spec`).flatMap(e=>{let t=m(e,`name`),n=y(m(e,`value`)?.namedChildren.at(0)??null);return t===null||n===null?[]:[{name:t.text,value:n,owner:null,at:t.startIndex}]})}const kt={class_declaration:`class`,record_declaration:`record`,enum_declaration:`enum`,interface_declaration:`interface`},At=/* @__PURE__ */ new Set([`annotation`,`marker_annotation`]);function M(e){let t=e.type===`object_creation_expression`?m(e,`type`):null;return t===null?null:v(t)}const jt=e=>e===null?null:b(e,M);function Mt(e){let t=p(e,`annotation_argument_list`);return t===null?[]:t.namedChildren.map(e=>{if(e.type!==`element_value_pair`)return x(e,null,M);let t=m(e,`value`),n=h(m(e,`key`));return t===null?x(e,n,M):{...b(t,M),name:n,at:t.startIndex}})}function N(e){return e===null?[]:e.namedChildren.filter(e=>At.has(e.type)).map(e=>ve(e,Mt))}function P(e){return e===null?[]:e.children.filter(e=>!e.isNamed).map(e=>e.type)}function Nt(e){let t=m(e,`superclass`)?.namedChildren[0],n=[...f(e,`super_interfaces`).flatMap(e=>Pt(e,`implements`)),...f(e,`extends_interfaces`).flatMap(e=>Pt(e,`extends`))];return[...t?[{name:v(t),relation:`extends`}]:[],...n]}function Pt(e,t){return(p(e,`type_list`)?.namedChildren??[]).map(e=>({name:v(e),relation:t}))}function Ft(e){let t=h(m(e,`name`));return t===null?null:{kind:`parameter`,name:t,type:h(m(e,`type`)),at:m(e,`name`)?.startIndex??e.startIndex,modifiers:P(p(e,`modifiers`)),annotations:N(p(e,`modifiers`)),arity:0,tag:null}}function It(e){let t=[];for(let n of e.namedChildren)if(n.type===`field_declaration`){let e=p(n,`modifiers`),r=h(m(n,`type`));for(let i of f(n,`variable_declarator`)){let n=m(i,`name`);n!==null&&t.push({kind:`field`,name:n.text,type:r,at:n.startIndex,modifiers:P(e),annotations:N(e),arity:0,tag:null})}}else if(n.type===`method_declaration`){let e=m(n,`name`);if(e===null)continue;let r=p(n,`modifiers`),i=m(n,`parameters`);t.push({kind:`method`,name:e.text,type:h(m(n,`type`)),at:e.startIndex,modifiers:P(r),annotations:N(r),arity:i?.namedChildren.filter(e=>e.type===`formal_parameter`||e.type===`spread_parameter`).length??0,tag:null})}return t}function Lt(e,t){let n=m(e,`name`),r=p(e,`modifiers`),i=m(e,`body`),a=t===`record`?m(e,`parameters`):null,o=[];a!==null&&o.push(...a.namedChildren.filter(e=>e.type===`formal_parameter`).flatMap(e=>Ft(e)??[])),i!==null&&o.push(...It(i));let s=i?.type===`enum_body`?i.namedChildren.filter(e=>e.type===`enum_constant`).map(e=>m(e,`name`)?.text??``):[],c=i?.type===`enum_body`?p(i,`enum_body_declarations`):null;return c!==null&&o.push(...It(c)),{kind:t,name:n?.text??``,at:n?.startIndex??e.startIndex,span:d(e),modifiers:P(r),annotations:N(r),supertypes:Nt(e),generic:m(e,`type_parameters`)!==null,members:o,constants:s.filter(e=>e!==``)}}function Rt(e){return e.descendantsOfType(Object.keys(kt)).map(e=>Lt(e,kt[e.type]))}const F=/* @__PURE__ */ new Set([`method_declaration`,`constructor_declaration`]),zt={method_declaration:`method`,constructor_declaration:`constructor`},Bt=/* @__PURE__ */ new Set([`class_declaration`,`record_declaration`,`enum_declaration`,`interface_declaration`]);function Vt(e){return(e?.namedChildren??[]).filter(e=>e.type===`formal_parameter`||e.type===`spread_parameter`).flatMap(e=>{let t=m(e,`name`)??p(e,`identifier`);return t===null?[]:[{name:t.text,type:h(m(e,`type`)),at:t.startIndex,annotations:N(p(e,`modifiers`))}]})}function Ht(e){return e.descendantsOfType([...F]).flatMap(e=>{let t=m(e,`name`);return t===null?[]:[{kind:zt[e.type],name:t.text,at:t.startIndex,span:d(e),owner:E(e,Bt),annotations:N(p(e,`modifiers`)),parameters:Vt(m(e,`parameters`)),returnType:h(m(e,`type`))}]})}function Ut(e){return e.namedChildren.find(e=>e.type===`package_declaration`)?.namedChildren.find(e=>e.type===`scoped_identifier`||e.type===`identifier`)?.text??null}function Wt(e){return e.descendantsOfType(`local_variable_declaration`).filter(e=>D(e,F)).flatMap(e=>{let t=h(m(e,`type`));return f(e,`variable_declarator`).flatMap(e=>{let n=m(e,`name`);return n===null?[]:[{name:n.text,key:null,type:t===`var`?null:t,at:n.startIndex,initializer:jt(m(e,`value`))}]})})}function Gt(e){return e.descendantsOfType(`return_statement`).map(e=>{let t=e.namedChildren.find(e=>!g(e))??null;return{at:e.startIndex,span:d(e),expression:jt(t)}})}function Kt(){return[]}function qt(){return[]}function Jt(){return[]}function Yt(e){return(e?.namedChildren??[]).filter(e=>!g(e)).map(e=>x(e,null,M))}function Xt(e,t){return{receiver:h(m(e,`object`)),name:t.text,arguments:Yt(m(e,`arguments`)),at:t.startIndex,span:d(e),within:E(e,F)}}function Zt(e){return e.descendantsOfType(`method_invocation`).flatMap(e=>{let t=m(e,`name`);return t===null?[]:[Xt(e,t)]})}function Qt(e){return e.descendantsOfType(`object_creation_expression`).flatMap(e=>{let t=m(e,`type`);return t===null?[]:[{type:v(t),arguments:Yt(m(e,`arguments`)),at:t.startIndex,span:d(e),within:E(e,F)}]})}function $t(e){return e.descendantsOfType(`import_declaration`).flatMap(e=>{let t=e.namedChildren.find(e=>e.type===`scoped_identifier`||e.type===`identifier`);return t===void 0?[]:[{name:p(e,`asterisk`)===null?t.text:`${t.text}.*`,at:t.startIndex}]})}function en(e){return e.descendantsOfType(`field_declaration`).flatMap(e=>{if(!P(p(e,`modifiers`)).includes(`final`))return[];let t=E(e,Bt);return f(e,`variable_declarator`).flatMap(e=>{let n=m(e,`name`),r=y(m(e,`value`));return n===null||r===null?[]:[{name:n.text,value:r,owner:t,at:n.startIndex}]})})}const tn=`annotation`,nn=/* @__PURE__ */ new Set([`val`,`var`]),rn=/* @__PURE__ */ new Set([`function_declaration`]),an=/* @__PURE__ */ new Set([`class_declaration`,`object_declaration`]),on=/* @__PURE__ */ new Set([`navigation_expression`,`index_expression`]);function I(e){let t=e.type===`call_expression`?e.firstNamedChild:null;return t?.type===`identifier`&&/^[A-Z]/.test(t.text)?t.text:null}const sn=e=>e===null?null:b(e,I);function cn(e){return e===null?[]:f(e,`value_argument`).map(e=>{let t=e.children.findIndex(e=>e.type===`=`);if(t>0)return x(e.children.slice(t+1).find(e=>e.isNamed)??e,e.children[t-1].text,I);let n=p(e,`value_argument_label`);return x(e.namedChildren.find(e=>e.type!==`value_argument_label`)??e,n?n.text.replace(/\s*=\s*$/,``):null,I)})}function ln(e){return cn(e.descendantsOfType(`value_arguments`)[0]??null)}function un(e){return e.descendantsOfType(`user_type`)[0]?.text??e.text.replace(/^@/,``)}function L(e){return e===null?[]:e.namedChildren.filter(e=>e.type===tn).map(e=>({name:un(e),at:e.startIndex,arguments:ln(e)}))}function R(e){return e===null?[]:e.namedChildren.filter(e=>e.type!==tn).map(e=>e.text)}function z(e){return h(p(e,`user_type`))}function dn(e){let t=p(e,`modifiers`),n=e.children.find(e=>nn.has(e.type)),r=p(e,`identifier`);return n===void 0||r===null?null:{kind:`parameter`,name:r.text,type:z(e),at:r.startIndex,modifiers:R(t),annotations:L(t),arity:0,tag:null}}function fn(e){let t=p(e,`variable_declaration`),n=t?p(t,`identifier`):null;if(t===null||n===null)return null;let r=p(e,`modifiers`);return{kind:`field`,name:n.text,type:z(t),at:n.startIndex,modifiers:R(r),annotations:L(r),arity:0,tag:null}}function pn(e){let t=m(e,`name`);if(t===null)return null;let n=p(e,`modifiers`),r=p(e,`function_value_parameters`);return{kind:`method`,name:t.text,type:z(e),at:t.startIndex,modifiers:R(n),annotations:L(n),arity:r?f(r,`parameter`).length:0,tag:null}}function mn(e){let t=p(e,`delegation_specifiers`);return t===null?[]:f(t,`delegation_specifier`).flatMap(e=>{let t=p(e,`constructor_invocation`),n=p(t||e,`user_type`);return n===null?[]:[{name:n.text,relation:t?`extends`:`implements`}]})}function hn(e){let t=p(e,`modifiers`);return f(t??e,`class_modifier`).some(e=>e.text===`enum`)?`enum`:e.children.some(e=>e.type===`interface`)?`interface`:`class`}function gn(e){let t=m(e,`name`),n=p(e,`modifiers`),r=hn(e),i=[],a=p(e,`primary_constructor`),o=a?p(a,`class_parameters`):null;for(let e of o?.namedChildren??[]){if(e.type!==`class_parameter`)continue;let t=dn(e);t&&i.push(t)}let s=p(e,`class_body`);for(let e of s?.namedChildren??[])if(e.type===`property_declaration`){let t=fn(e);t&&i.push(t)}else if(e.type===`function_declaration`){let t=pn(e);t&&i.push(t)}let c=p(e,`enum_class_body`)?.namedChildren.filter(e=>e.type===`enum_entry`).map(e=>p(e,`identifier`)?.text??``)??[];return{kind:r,name:t?.text??``,at:t?.startIndex??e.startIndex,span:d(e),modifiers:R(n),annotations:L(n),supertypes:mn(e),generic:p(e,`type_parameters`)!==null,members:i,constants:c.filter(e=>e!==``)}}function _n(e){return e.descendantsOfType([`class_declaration`,`object_declaration`]).map(gn)}function vn(e){let t=null;return(e?.namedChildren??[]).flatMap(e=>{if(e.type===`parameter_modifiers`)return t=e,[];if(e.type!==`parameter`)return[];let n=t;t=null;let r=p(e,`identifier`);return r===null?[]:[{name:r.text,type:z(e),at:r.startIndex,annotations:L(n)}]})}function yn(e){return e.descendantsOfType(`function_declaration`).flatMap(e=>{let t=m(e,`name`);if(t===null)return[];let n=E(e,an);return[{kind:n===null?`function`:`method`,name:t.text,at:t.startIndex,span:d(e),owner:n,annotations:L(p(e,`modifiers`)),parameters:vn(p(e,`function_value_parameters`)),returnType:z(e)}]})}function bn(e){let t=e.namedChildren.find(e=>e.type===`package_header`)??null;return t===null?null:h(p(t,`qualified_identifier`))}function xn(e){let t=e.children.findIndex(e=>e.type===`=`);return t<0?null:sn(e.children.slice(t+1).find(e=>e.isNamed)??null)}function Sn(e){return e.descendantsOfType(`property_declaration`).filter(e=>D(e,rn)).flatMap(e=>{let t=p(e,`variable_declaration`),n=t?p(t,`identifier`):null;return t===null||n===null?[]:[{name:n.text,key:null,type:z(t),at:n.startIndex,initializer:xn(e)}]})}function Cn(e){return e.descendantsOfType(`return_expression`).map(e=>({at:e.startIndex,span:d(e),expression:sn(e.namedChildren[0]??null)}))}function wn(e){let t=T(e);return t!==null&&on.has(t.type)&&_(e,t.firstNamedChild)}function Tn(e){let t=T(e);return t===null?!1:wn(e)||t.type===`call_expression`&&_(e,t.firstNamedChild)}function En(e){let t=e.firstNamedChild;if(t===null)return[];if(e.type===`index_expression`)return[C(e,t,null,e.namedChildren[1]??null)];let n=e.lastNamedChild;return n===null||n.type!==`identifier`?[]:[C(e,t,n,null)]}function Dn(e){return w(e.descendantsOfType([...on]).filter(e=>!Tn(e)).flatMap(En))}function On(e){return w(e.descendantsOfType([...on]).filter(wn).flatMap(En))}function kn(e){return e.descendantsOfType(`infix_expression`).flatMap(e=>{let[t,n,r]=e.namedChildren;return n?.text===`to`&&r!==void 0?[S(t,r,e,I)]:[]})}function An(e){let t=e.firstNamedChild;if(t===null)return null;let n=t.type===`navigation_expression`,r=n?t.lastNamedChild:t;return r===null||r.type!==`identifier`?null:{receiver:n?h(t.firstNamedChild):null,name:r.text,arguments:cn(p(e,`value_arguments`)),at:r.startIndex,span:d(e),within:E(e,rn)}}function jn(e){return e.descendantsOfType(`call_expression`).flatMap(e=>An(e)??[])}function Mn(e){return e.descendantsOfType(`import`).flatMap(e=>{let t=p(e,`qualified_identifier`);return t===null?[]:[{name:/\*$/.test(e.text)?`${t.text}.*`:t.text,at:t.startIndex}]})}function Nn(e){return e.descendantsOfType(`property_declaration`).flatMap(e=>{if(!R(p(e,`modifiers`)).includes(`const`))return[];let t=p(p(e,`variable_declaration`)??e,`identifier`),n=y(e.lastNamedChild);return t===null||n===null?[]:[{name:t.text,value:n,owner:E(e,an),at:t.startIndex}]})}const B=/* @__PURE__ */ new Set([`function_definition`]),Pn=/* @__PURE__ */ new Set([`class_definition`,`object_definition`,`trait_definition`]),Fn=/* @__PURE__ */ new Set([`field_expression`]);function In(e){let t=e.charAt(0);return t!==t.toLowerCase()}function V(e){let t=e.type===`call_expression`?m(e,`function`):null;return t?.type===`identifier`&&In(t.text)?t.text:null}const Ln=e=>e===null?null:b(e,V);function Rn(e){return e===null?[]:e.namedChildren.map(e=>{if(e.type===`assignment_expression`){let t=m(e,`left`),n=m(e,`right`);if(t!==null&&n!==null)return x(n,t.text,V)}return x(e,null,V)})}function H(e){let t=p(e,`modifiers`);return[...f(e,`annotation`),...t===null?[]:f(t,`annotation`)].map(e=>ve(e,e=>Rn(m(e,`arguments`)))).sort((e,t)=>e.at-t.at)}function U(e){let t=p(e,`modifiers`);return t===null?[]:t.children.filter(e=>e.type!==`annotation`).map(e=>e.text)}function zn(e){return(e?.namedChildren??[]).flatMap(e=>{if(e.type!==`parameter`)return[];let t=m(e,`name`);return t===null?[]:[{name:t.text,type:h(m(e,`type`)),at:t.startIndex,annotations:H(e)}]})}function Bn(e){if(e.type===`function_definition`){let t=m(e,`name`);return t===null?null:{kind:`method`,name:t.text,type:h(m(e,`return_type`)),at:t.startIndex,modifiers:U(e),annotations:H(e),arity:zn(m(e,`parameters`)).length,tag:null}}if(e.type!==`val_definition`&&e.type!==`var_definition`)return null;let t=m(e,`pattern`);return t===null||t.type!==`identifier`?null:{kind:`field`,name:t.text,type:h(m(e,`type`)),at:t.startIndex,modifiers:U(e),annotations:H(e),arity:0,tag:null}}function Vn(e){let t=e.children.some(e=>e.type===`case`);return(m(e,`class_parameters`)?.namedChildren??[]).flatMap(e=>{let n=m(e,`name`),r=e.children.some(e=>e.type===`val`||e.type===`var`);return n===null||!r&&!t?[]:[{kind:`field`,name:n.text,type:h(m(e,`type`)),at:n.startIndex,modifiers:[],annotations:H(e),arity:0,tag:null}]})}function Hn(e){let t=p(e,`extends_clause`);if(t===null)return[];let n=e.type===`trait_definition`?`implements`:`extends`;return t.childrenForFieldName(`type`).map((e,t)=>({name:e.text,relation:t===0?n:`implements`}))}function Un(e){return e.type===`trait_definition`?`interface`:`class`}function Wn(e){let t=m(e,`name`),n=m(e,`body`),r=[...Vn(e),...(n?.namedChildren??[]).flatMap(e=>Bn(e)??[])];return{kind:Un(e),name:t?.text??``,at:t?.startIndex??e.startIndex,span:d(e),modifiers:U(e),annotations:H(e),supertypes:Hn(e),generic:p(e,`type_parameters`)!==null,members:r,constants:[]}}function Gn(e){let t=p(e,`package_clause`);return h(t===null?null:m(t,`name`))}function Kn(e){return e.descendantsOfType([...Pn]).map(Wn)}function qn(e){return e.descendantsOfType([...B]).flatMap(e=>{let t=m(e,`name`);if(t===null)return[];let n=E(e,Pn);return[{kind:n===null?`function`:`method`,name:t.text,at:t.startIndex,span:d(e),owner:n,annotations:H(e),parameters:zn(m(e,`parameters`)),returnType:h(m(e,`return_type`))}]})}function Jn(e){return e.descendantsOfType([`val_definition`,`var_definition`]).filter(e=>D(e,B)).flatMap(e=>{let t=m(e,`pattern`);return t===null||t.type!==`identifier`?[]:[{name:t.text,key:null,type:h(m(e,`type`)),at:t.startIndex,initializer:Ln(m(e,`value`))}]})}function Yn(e){return e.descendantsOfType(`return_expression`).map(e=>({at:e.startIndex,span:d(e),expression:Ln(e.namedChildren[0]??null)}))}function Xn(e){let t=T(e);return t!==null&&Fn.has(t.type)&&_(e,m(t,`value`))}function Zn(e){let t=T(e);return t===null?!1:Xn(e)||t.type===`call_expression`&&_(e,m(t,`function`))}function Qn(e){let t=m(e,`value`),n=m(e,`field`);return t===null||n===null?[]:[C(e,t,n,null)]}function $n(e){return w(e.descendantsOfType([...Fn]).filter(e=>!Zn(e)).flatMap(Qn))}function er(e){return w(e.descendantsOfType([...Fn]).filter(Xn).flatMap(Qn))}function tr(e){return e.descendantsOfType(`infix_expression`).flatMap(e=>{let t=m(e,`left`),n=m(e,`right`);return m(e,`operator`)?.text===`->`&&t!==null&&n!==null?[S(t,n,e,V)]:[]})}function nr(e){let t=m(e,`function`);if(t===null)return null;let n=t.type===`field_expression`,r=n?m(t,`field`):t;return r===null||r.type!==`identifier`?null:{receiver:n?h(m(t,`value`)):null,name:r.text,arguments:Rn(m(e,`arguments`)),at:r.startIndex,span:d(e),within:E(e,B)}}function rr(e){return e.descendantsOfType(`call_expression`).flatMap(e=>nr(e)??[])}function ir(e){return e.descendantsOfType(`instance_expression`).flatMap(e=>{let t=e.firstNamedChild;return t===null?[]:[{type:t.text,arguments:Rn(m(e,`arguments`)),at:t.startIndex,span:d(e),within:E(e,B)}]})}function ar(e){return e.descendantsOfType(`import_declaration`).flatMap(e=>{let t=e.childrenForFieldName(`path`).filter(e=>e.isNamed).map(e=>e.text).join(`.`),n=p(e,`namespace_selectors`);return n===null?p(e,`namespace_wildcard`)===null?[{name:t,at:e.startIndex}]:[{name:`${t}.*`,at:e.startIndex}]:n.namedChildren.map(n=>({name:`${t}.${n.text}`,at:e.startIndex}))})}function or(e){return e.descendantsOfType(`val_definition`).flatMap(e=>{if(!U(e).includes(`final`))return[];let t=m(e,`pattern`),n=y(m(e,`value`));return t===null||t.type!==`identifier`||n===null?[]:[{name:t.text,value:n,owner:E(e,Pn),at:t.startIndex}]})}const sr=/* @__PURE__ */ new Set([`identifier`,`attribute`,`subscript`]),cr=/* @__PURE__ */ new Set([`function_definition`]),lr=/* @__PURE__ */ new Set([`class_definition`]),ur={attribute:`object`,subscript:`value`};function W(e){let t=e.type===`call`?m(e,`function`):null;return t?.type===`identifier`&&/^[A-Z]/.test(t.text)?t.text:null}const dr=e=>e===null?null:b(e,W);function fr(e){return(e?.namedChildren??[]).filter(e=>!g(e)).map(e=>e.type===`keyword_argument`?{...b(m(e,`value`)??e,W),name:m(e,`name`)?.text??null,at:e.startIndex}:x(e,null,W))}function pr(e){return e.type===`call`?{name:m(e,`function`)?.text??e.text,at:e.startIndex,arguments:fr(m(e,`arguments`))}:{name:e.text,at:e.startIndex,arguments:[]}}function G(e){return f(e,`decorator`).flatMap(e=>{let t=e.namedChildren[0];return t===void 0?[]:[pr(t)]})}function mr(e){return(m(e,`superclasses`)?.namedChildren??[]).flatMap(e=>{if(!sr.has(e.type)&&e.type!==`subscript`)return[];let t=e.type===`subscript`?m(e,`value`):e;return t===null?[]:[{name:t.text,relation:`extends`}]})}function K(e){return e.type===`expression_statement`?p(e,`assignment`):null}function hr(e){let t=m(e,`left`);if(t===null||t.type!==`identifier`)return[];let n=m(e,`right`),r=m(e,`type`);if(r===null&&t.text===`model_config`)return[{kind:`config`,name:t.text,type:null,at:t.startIndex,modifiers:[],annotations:[],arity:0,tag:null}];if(r===null)return[];let i=n!==null&&n.type===`call`?[pr(n)]:[];return[{kind:`field`,name:t.text,type:r.text,at:t.startIndex,modifiers:[],annotations:i,arity:0,tag:null}]}function gr(e,t){let n=m(e,`name`);return n===null?[]:e.type===`class_definition`?[{kind:`config`,name:n.text,type:null,at:n.startIndex,modifiers:[],annotations:t,arity:0,tag:null}]:e.type===`function_definition`?[{kind:`method`,name:n.text,type:m(e,`return_type`)?.text??null,at:n.startIndex,modifiers:[],annotations:t,arity:m(e,`parameters`)?.namedChildren.length??0,tag:null}]:[]}function _r(e){return e.namedChildren.flatMap(e=>{if(e.type===`decorated_definition`){let t=m(e,`definition`);return t===null?[]:gr(t,G(e))}let t=K(e);return t===null?gr(e,[]):hr(t)})}function vr(e){return e.namedChildren.flatMap(e=>{let t=K(e);if(t===null||m(t,`type`)!==null)return[];let n=m(t,`left`);return n?.type===`identifier`?[n.text]:[]})}function yr(e){let t=m(e,`name`);if(t===null)return null;let n=m(e,`body`),r=T(e)?.type===`decorated_definition`?T(e):null;return{kind:`class`,name:t.text,at:t.startIndex,span:d(e),modifiers:[],annotations:r===null?[]:G(r),supertypes:mr(e),generic:m(e,`type_parameters`)!==null,members:n===null?[]:_r(n),constants:n===null?[]:vr(n)}}function br(e){return e.descendantsOfType(`class_definition`).flatMap(e=>yr(e)??[])}function xr(e){if(e.type===`identifier`)return{name:e.text,type:null,at:e.startIndex,annotations:[]};let t=e.type===`typed_parameter`?p(e,`identifier`):m(e,`name`);return t===null?null:{name:t.text,type:h(m(e,`type`)),at:t.startIndex,annotations:[]}}function Sr(e){return e.descendantsOfType(`function_definition`).flatMap(e=>{let t=m(e,`name`);if(t===null)return[];let n=E(e,lr),r=T(e)?.type===`decorated_definition`?T(e):null;return[{kind:n===null?`function`:`method`,name:t.text,at:t.startIndex,span:d(e),owner:n,annotations:r===null?[]:G(r),parameters:(m(e,`parameters`)?.namedChildren??[]).flatMap(e=>xr(e)??[]),returnType:h(m(e,`return_type`))}]})}function Cr(){return null}function wr(e){return e.descendantsOfType(`assignment`).filter(e=>T(e)?.type===`expression_statement`&&D(e,cr)).flatMap(e=>{let t=m(e,`left`);return t===null||t.type!==`identifier`?[]:[{name:t.text,key:null,type:h(m(e,`type`)),at:t.startIndex,initializer:dr(m(e,`right`))}]})}function Tr(e){return e.descendantsOfType(`return_statement`).map(e=>({at:e.startIndex,span:d(e),expression:dr(e.namedChildren.find(e=>!g(e))??null)}))}function Er(e){let t=T(e),n=t===null?void 0:ur[t.type];return t!==null&&n!==void 0&&_(e,m(t,n))}function Dr(e){let t=T(e);return t===null?!1:Er(e)||t.type===`call`&&_(e,m(t,`function`))}function Or(e){let t=m(e,ur[e.type]);if(t===null)return[];if(e.type===`subscript`)return[C(e,t,null,m(e,`subscript`))];let n=m(e,`attribute`);return n===null?[]:[C(e,t,n,null)]}function kr(e){return w(e.descendantsOfType([`attribute`,`subscript`]).filter(e=>!Dr(e)).flatMap(Or))}function Ar(e){return w(e.descendantsOfType([`attribute`,`subscript`]).filter(Er).flatMap(Or))}function jr(e){return e.descendantsOfType(`pair`).flatMap(e=>{let t=T(e),n=m(e,`key`),r=m(e,`value`);return t===null||t.type!==`dictionary`||n===null||r===null?[]:[S(n,r,t,W)]})}function Mr(e){let t=m(e,`function`);for(;t!==null&&t.type===`call`;)t=m(t,`function`);return t}function Nr(e){let t=Mr(e);if(t===null)return null;let n=t.type===`attribute`,r=n?m(t,`attribute`):t;return r===null||r.type!==`identifier`?null:{receiver:n?h(m(t,`object`)):null,name:r.text,arguments:fr(m(e,`arguments`)),at:r.startIndex,span:d(e),within:E(e,cr)}}function Pr(e){return e.descendantsOfType(`call`).flatMap(e=>Nr(e)??[])}function Fr(e){return e.descendantsOfType([`import_statement`,`import_from_statement`]).flatMap(e=>{if(e.type===`import_from_statement`){let t=m(e,`module_name`);return t===null?[]:[{name:t.text,at:t.startIndex}]}return e.namedChildren.flatMap(e=>{let t=e.type===`aliased_import`?m(e,`name`):e;return t!==null&&(t.type===`dotted_name`||t.type===`identifier`)?[{name:t.text,at:t.startIndex}]:[]})})}function Ir(e){return e.namedChildren.flatMap(e=>{let t=K(e);if(t===null||m(t,`type`)!==null)return[];let n=m(t,`left`),r=y(m(t,`right`));return n?.type===`identifier`&&r!==null?[{name:n.text,value:r,owner:null,at:n.startIndex}]:[]})}const Lr={class_declaration:`class`,abstract_class_declaration:`class`,interface_declaration:`interface`,enum_declaration:`enum`,type_alias_declaration:`alias`},Rr=/* @__PURE__ */ new Set([`abstract`,`declare`,`get`,`override`,`private`,`protected`,`public`,`readonly`,`set`,`static`]),zr=/* @__PURE__ */ new Set([`required_parameter`,`optional_parameter`]),Br=/* @__PURE__ */ new Set([`required_parameter`,`optional_parameter`,`rest_pattern`]),Vr=/* @__PURE__ */ new Set([`public_field_definition`,`field_definition`,`property_signature`]),Hr=/* @__PURE__ */ new Set([`method_signature`,`method_definition`]),q=/* @__PURE__ */ new Set([`function_declaration`,`generator_function_declaration`,`method_definition`]),Ur=/* @__PURE__ */ new Set([...q,`arrow_function`,`function_expression`,`function`]),Wr=/* @__PURE__ */ new Set([`class_declaration`,`abstract_class_declaration`]),Gr=/* @__PURE__ */ new Set([`member_expression`,`subscript_expression`]),J=e=>e.type===`string`?e.text.slice(1,-1):e.text;function Y(e){return e.type===`new_expression`?h(m(e,`constructor`)):null}const Kr=e=>e===null?null:b(e,Y);function X(e){return e.children.filter(e=>Rr.has(e.type)||e.type===`accessibility_modifier`).map(e=>e.text)}function qr(e){return(m(e,`type`)??m(e,`return_type`))?.namedChildren[0]?.text??null}function Z(e,t,n,r=0){return{kind:e,name:J(n),type:qr(t),at:n.startIndex,modifiers:X(t),annotations:[],arity:r,tag:null}}function Jr(e){return m(e,`parameters`)?.namedChildren.filter(e=>Br.has(e.type)).length??0}function Yr(e){return(m(e,`parameters`)?.namedChildren??[]).flatMap(e=>{let t=m(e,`pattern`);return!zr.has(e.type)||t===null||X(e).length===0?[]:[Z(`parameter`,e,t)]})}function Xr(e){return e.namedChildren.flatMap(e=>{if(Vr.has(e.type)){let t=m(e,`name`)??m(e,`property`);return t===null?[]:[Z(`field`,e,t)]}if(e.type===`index_signature`){let t=m(e,`name`);return t===null?[]:[Z(`index`,e,t)]}if(Hr.has(e.type)){let t=m(e,`name`);if(t===null)return[];let n=X(e);return n.includes(`get`)||n.includes(`set`)?[Z(`accessor`,e,t)]:t.text===`constructor`?Yr(e):[Z(`method`,e,t,Jr(e))]}return[]})}function Zr(e){let t=p(e,`extends_clause`),n=t?m(t,`value`):e.namedChildren.find(e=>e.type===`identifier`||e.type===`member_expression`)??null;return n===null?[]:[{name:v(n),relation:`extends`}]}function Qr(e){let t=f(e,`extends_type_clause`).flatMap(e=>e.namedChildren.map(e=>({name:v(e),relation:`extends`}))),n=p(e,`class_heritage`);if(n===null)return t;let r=(p(n,`implements_clause`)?.namedChildren??[]).map(e=>({name:v(e),relation:`implements`}));return[...Zr(n),...r]}function $r(e){return e.namedChildren.flatMap(e=>{if(e.type===`enum_assignment`){let t=m(e,`name`);return t===null?[]:[J(t)]}return e.type===`property_identifier`||e.type===`string`?[J(e)]:[]})}function ei(e,t){let n=m(e,`name`);if(n===null)return null;let r=t===`alias`?m(e,`value`):m(e,`body`);return t===`alias`&&r?.type!==`object_type`?null:{kind:t,name:n.text,at:n.startIndex,span:d(e),modifiers:X(e),annotations:[],supertypes:Qr(e),generic:m(e,`type_parameters`)!==null,members:r===null||t===`enum`?[]:Xr(r),constants:t===`enum`&&r!==null?$r(r):[]}}function ti(e){return e.descendantsOfType(Object.keys(Lr)).flatMap(e=>ei(e,Lr[e.type])??[])}function ni(e){return(e?.namedChildren??[]).filter(e=>!g(e)).map(e=>x(e,null,Y))}function ri(e){return f(e,`decorator`).flatMap(e=>{let t=e.namedChildren[0];return t===void 0?[]:t.type===`call_expression`?[{name:h(m(t,`function`))??t.text,at:t.startIndex,arguments:ni(m(t,`arguments`))}]:[{name:t.text,at:t.startIndex,arguments:[]}]})}function ii(e){return(e?.namedChildren??[]).filter(e=>zr.has(e.type)).flatMap(e=>{let t=m(e,`pattern`);return t===null||t.type!==`identifier`?[]:[{name:t.text,type:h(m(e,`type`)?.namedChildren[0]??null),at:t.startIndex,annotations:[]}]})}function ai(e){return e.descendantsOfType([...q]).flatMap(e=>{let t=m(e,`name`);if(t===null)return[];let n=E(e,Wr),r=e.type===`method_definition`;return[{kind:t.text===`constructor`?`constructor`:r?`method`:`function`,name:t.text,at:t.startIndex,span:d(e),owner:r?n:null,annotations:ri(e),parameters:ii(m(e,`parameters`)),returnType:h(m(e,`return_type`)?.namedChildren[0]??null)}]})}function oi(){return null}function si(e){return h(m(e,`type`)?.namedChildren[0]??null)}function ci(e,t){let n=(e,n)=>({name:n.text,key:e,type:null,at:n.startIndex,initializer:t});return e.namedChildren.flatMap(e=>{if(e.type===`shorthand_property_identifier_pattern`)return[n(e.text,e)];if(e.type===`object_assignment_pattern`){let t=m(e,`left`);return t?.type===`shorthand_property_identifier_pattern`?[n(t.text,t)]:[]}if(e.type!==`pair_pattern`)return[];let t=m(e,`key`),r=m(e,`value`),i=r?.type===`assignment_pattern`?m(r,`left`):r;return t!==null&&i?.type===`identifier`?[n(J(t),i)]:[]})}function li(e){return e.descendantsOfType(`variable_declarator`).filter(e=>D(e,Ur)).flatMap(e=>{let t=m(e,`name`),n=Kr(m(e,`value`));return t===null?[]:t.type===`object_pattern`?ci(t,n):t.type===`identifier`?[{name:t.text,key:null,type:si(e),at:t.startIndex,initializer:n}]:[]})}function ui(e){return e.descendantsOfType(`return_statement`).map(e=>({at:e.startIndex,span:d(e),expression:Kr(e.namedChildren.find(e=>!g(e))??null)}))}function di(e){let t=T(e);return t!==null&&Gr.has(t.type)&&_(e,m(t,`object`))}function fi(e){let t=T(e);return t===null?!1:di(e)||t.type===`call_expression`&&_(e,m(t,`function`))}function pi(e){let t=m(e,`object`);if(t===null)return[];if(e.type!==`member_expression`)return[C(e,t,null,m(e,`index`))];let n=m(e,`property`);return n===null?[]:[C(e,t,n,null)]}function mi(e){return w(e.descendantsOfType([...Gr]).filter(e=>!fi(e)).flatMap(pi))}function hi(e){return w(e.descendantsOfType([...Gr]).filter(di).flatMap(pi))}function gi(e){return w(e.descendantsOfType([`pair`,`shorthand_property_identifier`]).flatMap(e=>{let t=T(e);if(t===null||t.type!==`object`)return[];if(e.type===`shorthand_property_identifier`)return[S(e,e,t,Y)];let n=m(e,`key`),r=m(e,`value`);return n===null||r===null?[]:[S(n,r,t,Y)]}))}function _i(e){let t=m(e,`function`);if(t===null)return null;let n=t.type===`member_expression`,r=n?m(t,`property`):t;return r===null||r.type!==`identifier`&&r.type!==`property_identifier`?null:{receiver:n?h(m(t,`object`)):null,name:r.text,arguments:ni(m(e,`arguments`)),at:r.startIndex,span:d(e),within:E(e,q)}}function vi(e){return e.descendantsOfType(`call_expression`).flatMap(e=>_i(e)??[])}const yi=e=>{let t=T(e);return t?.type===`program`||t?.type===`export_statement`&&T(t)?.type===`program`};function bi(e){return e.descendantsOfType(`new_expression`).flatMap(e=>{let t=m(e,`constructor`);return t===null?[]:[{type:t.text,arguments:ni(m(e,`arguments`)),at:t.startIndex,span:d(e),within:E(e,q)}]})}function xi(e){return e.descendantsOfType(`import_statement`).flatMap(e=>{let t=m(e,`source`),n=y(t);return t===null||n===null?[]:[{name:n,at:t.startIndex}]})}function Si(e){return e.descendantsOfType(`lexical_declaration`).flatMap(e=>p(e,`const`)===null||!yi(e)?[]:f(e,`variable_declarator`).flatMap(e=>{let t=m(e,`name`),n=y(m(e,`value`));return t===null||n===null?[]:[{name:t.text,value:n,owner:null,at:t.startIndex}]}))}const Q=()=>[],Ci={packageOf:Ut,declarations:Rt,callables:Ht,locals:Wt,returns:Gt,accesses:Kt,innerAccesses:qt,pairs:Jt,calls:Zt,constructions:Qt,imports:$t,constants:en},wi={packageOf:oi,declarations:ti,callables:ai,locals:li,returns:ui,accesses:mi,innerAccesses:hi,pairs:gi,calls:vi,constructions:bi,imports:xi,constants:Si},Ti={java:Ci,kotlin:{packageOf:bn,declarations:_n,callables:yn,locals:Sn,returns:Cn,accesses:Dn,innerAccesses:On,pairs:kn,calls:jn,constructions:Q,imports:Mn,constants:Nn},typescript:wi,javascript:wi,python:{packageOf:Cr,declarations:br,callables:Sr,locals:wr,returns:Tr,accesses:kr,innerAccesses:Ar,pairs:jr,calls:Pr,constructions:Q,imports:Fr,constants:Ir},go:{packageOf:mt,declarations:ut,callables:pt,locals:ht,returns:gt,accesses:bt,innerAccesses:xt,pairs:Ct,calls:Et,constructions:Q,imports:Dt,constants:Ot},groovy:Ci,scala:{packageOf:Gn,declarations:Kn,callables:qn,locals:Jn,returns:Yn,accesses:$n,innerAccesses:er,pairs:tr,calls:rr,constructions:ir,imports:ar,constants:or},csharp:{packageOf:Ve,declarations:Ie,callables:Be,locals:He,returns:Ue,accesses:qe,innerAccesses:Je,pairs:Ze,calls:et,constructions:tt,imports:nt,constants:rt}},Ei=/* @__PURE__ */ new Map;function Di(e,t){let n=`${e.runtimeFile}\0${e.grammarFiles[t]}`,r=Ei.get(n);return r===void 0&&(r=Promise.all([l(e.runtimeFile),l(e.grammarFiles[t])]).then(([e,t])=>s(`sha256`).update(e).update(t).digest(`hex`)),Ei.set(n,r),r.catch(()=>Ei.delete(n))),r}function Oi(t){let n=null,r=/* @__PURE__ */ new Map,i=!1,a=()=>(n??=import(`web-tree-sitter`).then(async e=>(await e.Parser.init({locateFile:()=>t.runtimeFile}),e)),n),o=e=>{let n=r.get(e);if(n)return n;let i=(async()=>{let{Language:n,Parser:r}=await a(),i=await n.load(new Uint8Array(await l(t.grammarFiles[e]))),o=new r;return o.setLanguage(i),o})();return r.set(e,i),i.catch(()=>r.delete(e)),i};return{async facts(t){if(i)throw Error(`The syntax port is disposed`);let n=u(t.path);if(n===null)throw Error(`No grammar is registered for ${t.path}`);let r=(await o(n)).parse(t.text),a=e(t.text);if(r===null)return{path:t.path,language:n,package:null,errors:[{offset:0,line:1}],lineStarts:a,declarations:[],callables:[],locals:[],returns:[],accesses:[],innerAccesses:[],pairs:[],calls:[],constructions:[],imports:[],constants:[]};try{let e=Ti[n],i=r.rootNode;return{path:t.path,language:n,package:e.packageOf(i),errors:ki(i,t.text),lineStarts:a,declarations:e.declarations(i),callables:e.callables(i),locals:e.locals(i),returns:e.returns(i),accesses:e.accesses(i),innerAccesses:e.innerAccesses(i),pairs:e.pairs(i),calls:e.calls(i),constructions:e.constructions(i),imports:e.imports(i),constants:e.constants(i)}}finally{r.delete()}},version:e=>Di(t,e),async dispose(){i=!0;let e=[...r.values()];r.clear();for(let t of e)(await t.catch(()=>null))?.delete()}}}function ki(e,t){let r=[],i=e=>{if(!(r.length>=20||!e.hasError)){if(e.isError||e.isMissing)r.push({offset:e.startIndex,line:n(t,e.startIndex)});else for(let t of e.children)i(t)}};return i(e),r}function Ai(){let e=i.join(import.meta.dirname,`syntax-worker.js`);return o(e)?{file:e,execArgv:[]}:{file:i.join(import.meta.dirname,`worker.ts`),execArgv:[`--experimental-strip-types`]}}function ji({locations:e,size:t}){let n=[],r=Ai(),i=0,a=0,o=!1,s=e=>{let t=n.indexOf(e);t>=0&&n.splice(t,1)},c=e=>(s(e),e.worker.terminate()),ee=()=>{let t=new re(r.file,{execArgv:r.execArgv,workerData:{locations:e}}),i={worker:t,waiting:/* @__PURE__ */ new Map,retired:!1};t.on(`message`,e=>{let n=i.waiting.get(e.id);n!==void 0&&(i.waiting.delete(e.id),e.recycle&&(i.retired=!0,s(i)),i.waiting.size===0&&(i.retired||a===0?c(i):t.unref()),e.error===void 0?e.facts!==void 0&&n.resolve(e.facts):n.reject(Error(e.error)))});let o=e=>{for(let t of i.waiting.values())t.reject(e);i.waiting.clear(),s(i)};return t.on(`error`,e=>o(e instanceof Error?e:Error(String(e)))),t.on(`exit`,()=>o(/* @__PURE__ */ Error(`The syntax worker stopped`))),t.unref(),n.push(i),i},l=()=>{let e=n.find(e=>e.waiting.size===0);return e===void 0?n.length<t?ee():n.reduce((e,t)=>t.waiting.size<e.waiting.size?t:e):e};return{hold(){a+=1;let e=!0;return async()=>{e&&(e=!1,--a,!(a>0)&&await Promise.all(n.filter(e=>e.waiting.size===0).map(e=>c(e))))}},live:()=>n.length,facts(e){if(o)return Promise.reject(/* @__PURE__ */ Error(`The syntax port is disposed`));let t=l(),n=i+=1;return new Promise((r,i)=>{t.waiting.set(n,{resolve:r,reject:i}),t.worker.ref(),t.worker.postMessage({id:n,source:e,recycle:e.text.length>=524288})})},version(t){return Di(e,t)},async dispose(){o=!0,await Promise.all([...n].map(e=>e.worker.terminate())),n.length=0}}}const Mi=e=>s(`sha256`).update(e).digest(`hex`);function Ni(e,t=null,n=!0){let r=/* @__PURE__ */ new Map,i=async(n,r)=>{let i=u(n.path);if(t===null||i===null)return e.facts(n);let a=s(`sha256`).update([`facts-2`,await e.version(i),n.path,r].join(`\0`)).digest(`hex`),o=await t.read(a);if(o!==null)return o;let c=await e.facts(n);return await t.write(a,c),c},a=e=>{if(!n)return i(e,Mi(e.text));let t=Mi(e.text),a=r.get(e.path);if(a!==void 0&&a.digest===t)return a.facts;let o=i(e,t);return r.set(e.path,{digest:t,facts:o}),o.catch(()=>{r.get(e.path)?.facts===o&&r.delete(e.path)}),o};return{factsOf:e=>Promise.all(e.map(a))}}function Pi(e){return Math.min(4,Math.max(1,Math.floor(e/2)))}const Fi=Pi(a());function Ii(e,t){return e>200?t:0}let $={workers:0,cacheDirectory:null,remember:!0},Li=null,Ri=null;function zi(e){$=e,Li=null,Ri?.dispose(),Ri=null}function Bi(){return Li??=Vi(),Li}function Vi(){let e=$.cacheDirectory===null?null:oe($.cacheDirectory),t=ue(),n=$.workers>0?ji({locations:t,size:$.workers}):null;Ri=n;let r={cache:Ni(Oi(t),e,$.remember),hold:null},i=n===null?null:{cache:Ni(n,e,$.remember),hold:()=>n.hold()},a=async(e,t)=>{let n=e.hold?.();try{return await t(t=>e.cache.factsOf(t))}finally{await n?.()}};return{factsOf:e=>a(i??r,t=>t(e)),pass:(e,t)=>a(i!==null&&Ii(e,$.workers)>0?i:r,t)}}async function Hi(e){let n=e.filter(e=>u(e.file)!==null);return Bi().pass(n.length,async e=>{let r=t();for(let t=0;t<n.length;t+=64){let i=n.slice(t,t+64);(await e(i.map(e=>({path:e.file,text:e.text})))).forEach((e,t)=>r.add({facts:e,text:i[t].text}))}return r.finish()})}export{u as a,Bi as i,Fi as n,zi as r,Hi as t};
@@ -0,0 +1 @@
1
+ import{r as e}from"./chunk-translator-BFUJmSkR.js";import{n as t}from"./chunk-status-DgeSOz3A.js";import{t as n}from"./chunk-table-CJtiXv0e.js";import{$t as r,an as i,mt as a,pt as o}from"./chunk-src-BLyg_6UX.js";import{t as s}from"./chunk-context-DPJmldqg.js";import{i as c,r as l}from"./chunk-folders-13vx0i0n.js";import{t as u}from"./chunk-codeIndex-CzENd6hG.js";import{t as d}from"./chunk-plural-Bq_4vgOr.js";import{t as f}from"./chunk-diagrams-6suPQBVQ.js";import p from"node:path";import{existsSync as m,readFileSync as h,readdirSync as g,statSync as _}from"node:fs";function v(e,t){let n=c(e,t),r=[],i=e=>{for(let t of g(e,{withFileTypes:!0})){if(n(),o.has(t.name)||t.name.startsWith(`.`))continue;let s=p.join(e,t.name);t.isDirectory()?l(s)&&i(s):a.test(t.name)&&r.push(s)}};return i(e),r.sort()}function y(e,t){return`${p.relative(t,e.file)}:${e.line}`}function b(t,n,i,a,o=[],s={decisions:/* @__PURE__ */ new Set,forms:/* @__PURE__ */ new Set}){let c=[];for(let a of t){let t=e=>({severity:`fail`,message:e,where:`${a.diagram} · ${a.name}`,path:a.path,elementId:a.element,value:a.value});switch(a.kind){case`jobType`:!r({kind:`JOB_TYPE`,value:a.value})&&!n.jobTypes.has(a.value)&&c.push(t(e(`app.output.noWorkerForJobType`,{value:a.value})));break;case`topic`:n.topics.has(a.value)||c.push(t(e(`app.output.noWorkerForTopic`,{value:a.value})));break;case`class`:n.classes.has(a.value)||c.push(t(e(`app.output.classNotInProject`,{value:a.value})));break;case`bean`:n.beans.has(a.value)||c.push(t(e(`app.output.noBeanNamed`,{value:a.value})));break;case`calledElement`:i.has(a.value)||c.push(t(e(`app.output.callsNoProjectProcess`,{value:a.value})));break;case`decision`:s.decisions.has(a.value)||c.push(t(e(`app.output.callsNoProjectDecision`,{value:a.value})));break;case`form`:s.forms.has(a.value)||c.push(t(e(`app.output.showsNoProjectForm`,{value:a.value})));break;case`embeddedForm`:c.push(t(e(`app.output.showsNoEmbeddedForm`,{value:a.value})))}}let l=e=>new Set(t.filter(t=>t.kind===e).map(e=>e.value)),u=/* @__PURE__ */ new Set([`io.camunda.zeebe:userTask`,...o.flatMap(e=>[...e.matchAll(/[A-Za-z_][\w-]*/g)].map(e=>e[0]))]),d=/* @__PURE__ */ new Set([...l(`jobType`),...u]),f=/* @__PURE__ */ new Set([...l(`topic`),...u]);for(let[t,r]of n.jobTypes)d.has(t)||c.push({severity:`note`,message:e(`app.output.jobTypeNoDiagramUses`,{value:t}),where:y(r[0],a),path:r[0].file,line:r[0].line,value:t});for(let[t,r]of n.topics)f.has(t)||c.push({severity:`note`,message:e(`app.output.topicNoDiagramUses`,{value:t}),where:y(r[0],a),path:r[0].file,line:r[0].line,value:t});return c}const x={JOB_TYPE:`jobType`,TOPIC:`topic`,JAVA_CLASS:`class`,BEAN:`bean`};function S(t,n){let r=e=>(t.elements.find(t=>t.id===e)?.label??e).replace(/\s+/g,` `).trim(),i=(e,t,i)=>({diagram:n.diagram,path:n.path,element:e,name:r(e),kind:t,value:i});return{references:[...t.workers.map(t=>t.listener?{diagram:n.diagram,path:n.path,element:``,name:e(`app.output.listenerName`,{value:t.listener}),kind:x[t.kind],value:t.value}:i(t.elementId,x[t.kind],t.value)),...t.calls.map(e=>i(e.elementId,`calledElement`,e.calledProcessId)),...t.decisionUses.map(e=>i(e.elementId,`decision`,e.decisionId)),...t.formUses.filter(e=>e.linked).map(e=>i(e.elementId,`form`,e.formId)),...t.formUses.filter(e=>e.embedded&&!t.embeddedForms.includes(e.formId)).map(e=>i(e.elementId,`embeddedForm`,e.formId))],processes:t.processes.map(e=>e.id),dynamic:t.dynamic}}async function C(e,t){return S(await i(e,h(e,`utf8`)),{diagram:p.relative(t,e),path:e})}async function w(e){let t={decisions:/* @__PURE__ */ new Set,forms:/* @__PURE__ */ new Set},n=f(e,[`decision`,`form`]);for(let e of n){let n=await i(e,h(e,`utf8`));n.decisions.forEach(e=>t.decisions.add(e.id)),n.formId&&t.forms.add(n.formId)}return t}function T(e){let t=e.linked;return Array.isArray(t)?t.filter(e=>typeof e==`string`&&e.trim()!==``):[]}function E(e,t){return t.map(t=>p.resolve(e,t)).filter(t=>{let n=p.relative(e,t);return(n.startsWith(`..`)||p.isAbsolute(n))&&m(t)&&_(t).isDirectory()})}async function D(r,i,a){let o=_(r).isDirectory()?r:p.dirname(r),c=s(o),l=[o,...E(c.root,T(c.values))].flatMap(e=>v(e)).map(e=>({file:e,text:h(e,`utf8`)})),f=await u(l),m=[],g=/* @__PURE__ */ new Set,x=[];for(let e of i){let t=await C(e,o);m.push(...t.references),x.push(...t.dynamic),t.processes.forEach(e=>g.add(e))}let S=b(m,f,g,o,x,await w(o)),D=S.filter(e=>e.severity===`fail`);if(a===`json`)return{ok:D.length===0,refused:!1,lines:[JSON.stringify(S,null,2)]};let O=[e(`app.output.fromDiagramsToCode`,{sources:d(l.length,`app.output.count.sourceFile`),diagrams:d(i.length,`app.output.count.diagram`),references:d(m.length,`app.output.count.reference`)}),``],k=S.map(e=>({severity:t(e.severity),content:`${e.where} ${e.message}`})),A=n(k,{columns:[{name:`severity`,header:e(`app.cli.header.severity`),minWidth:4},{name:`content`,header:e(`app.cli.header.content`)}],headers:!1});return O.push(...A),f.unresolved.length>0&&O.push(e(`app.output.unresolvedWorker`,{workers:d(f.unresolved.length,`app.output.count.worker`),where:y(f.unresolved[0],o)})),O.push(``,D.length===0?e(`app.output.everyTaskHasCode`):e(`app.output.tasksPointAtNothing`,{count:D.length})),{ok:D.length===0,refused:!1,lines:O}}export{E as a,v as c,T as i,D as n,S as o,b as r,C as s,w as t};
@@ -0,0 +1 @@
1
+ export{n as codeCommand}from"./chunk-codeLinks-D-gzUjYv.js";
@@ -0,0 +1 @@
1
+ import{n as e}from"./chunk-editPreview-BgH1JVOD.js";import{a as t,i as n,n as r,o as i}from"./chunk-command-Jl1msVwF.js";export{r as applyOperations,e as engineOf,n as operationFromWords,t as schemaCommand,i as showCommand};
@@ -0,0 +1,5 @@
1
+ import{r as e,t}from"./chunk-translator-BFUJmSkR.js";import{C as n,O as r,S as i,T as a,_ as o,a as s,c,f as l,g as u,h as d,i as f,l as p,m,n as h,o as g,p as _,r as v,s as y,t as b,u as x,v as S,w as C,x as w}from"./chunk-security-5SU-bq3A.js";import{r as T}from"./chunk-failure-BsimkHy_.js";import E from"node:path";import{createReadStream as D,existsSync as O,realpathSync as k,statSync as A}from"node:fs";import{spawn as j}from"node:child_process";import{createServer as M}from"node:http";import{pipeline as N}from"node:stream";import{isIP as P}from"node:net";function F(e){let[t,...n]=process.platform===`darwin`?[`open`,e]:process.platform===`win32`?[`rundll32`,`url.dll,FileProtocolHandler`,e]:[`xdg-open`,e];return new Promise((e,r)=>{let i=j(t,n,{stdio:`ignore`,detached:!0});i.once(`error`,r),i.once(`spawn`,()=>{i.unref(),e()})})}function I(e=process.env,t=import.meta.dirname){let n=[e.PENSTOCK_WEB_ROOT,E.join(t,`web`),E.resolve(t,`..`,`..`,`..`,`..`,`libs`,`webview`,`build`,`web`)];for(let e of n)if(e&&O(E.join(e,`index.html`)))return e;return null}function L(e){return e.replace(/&/g,`&amp;`).replace(/</g,`&lt;`).replace(/>/g,`&gt;`).replace(/"/g,`&quot;`)}function R(e){if(e.method!==`GET`&&e.method!==`HEAD`)return!1;let t=e.headers[`sec-fetch-dest`];return typeof t==`string`?t===`document`:/\btext\/html\b/i.test(e.headers.accept??``)}function z(n){let r=`app.cli.web.page.${n}`,i=n===`missing`?`<p><a href="/">${L(e(`app.cli.web.page.open`))}</a></p>`:``;return`<!doctype html><html lang="${L(t())}"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><meta name="robots" content="noindex"><title>${L(e(`${r}.title`))} - Penstock</title><style>:root{color-scheme:light dark}body{margin:0;min-height:100vh;display:flex;align-items:center;justify-content:center;background:Canvas;color:CanvasText;font:13px/1.5 "JetBrains Mono",ui-monospace,SFMono-Regular,Menlo,Consolas,monospace}main{max-width:480px;padding:24px}h1{margin:0 0 8px;font-size:1.2em;font-weight:600}p{margin:0 0 8px}.hint{opacity:.7}a{color:LinkText}</style></head><body><main><h1>${L(e(`${r}.title`))}</h1><p>${L(e(`${r}.text`))}</p><p class="hint">${L(e(`${r}.hint`))}</p>${i}</main></body></html>`}function B(e,t,n,r){if(!R(e))return u(t,n);let i=z(r);t.writeHead(n.status,{"Content-Type":`text/html; charset=utf-8`,"Content-Length":Buffer.byteLength(i),"Cache-Control":`no-store`}),t.end(e.method===`HEAD`?void 0:i)}const V={".html":`text/html; charset=utf-8`,".js":`text/javascript; charset=utf-8`,".mjs":`text/javascript; charset=utf-8`,".css":`text/css; charset=utf-8`,".json":`application/json; charset=utf-8`,".webmanifest":`application/manifest+json; charset=utf-8`,".svg":`image/svg+xml`,".png":`image/png`,".jpg":`image/jpeg`,".gif":`image/gif`,".ico":`image/x-icon`,".woff":`font/woff`,".woff2":`font/woff2`,".ttf":`font/ttf`,".map":`application/json; charset=utf-8`,".wasm":`application/wasm`,".txt":`text/plain; charset=utf-8`};var H=class{root;constructor(e){this.root=e&&A(E.join(e,`index.html`),{throwIfNoEntry:!1})?.isFile()?k(e):null}get available(){return this.root!==null}serve(e,t,n){if(e.method!==`GET`&&e.method!==`HEAD`)return u(t,C(405,`app.cli.web.reason.methodNotAllowed`),{Allow:`GET, HEAD`});if(!this.root)return this.missing(t);let r;try{r=decodeURIComponent(n)}catch{return u(t,C(400,`app.cli.web.reason.badPath`,{path:``}))}if(r.includes(`\0`)||r.includes(`\\`)||r.split(`/`).includes(`..`))return u(t,C(403,`app.cli.web.reason.outside`,{path:``}));let i=r.endsWith(`/`)?`${r}index.html`:r,a=E.join(this.root,i),o=A(a,{throwIfNoEntry:!1});if(o?.isDirectory()&&(a=E.join(a,`index.html`),o=A(a,{throwIfNoEntry:!1})),!o?.isFile())return B(e,t,C(404,`app.cli.web.reason.noSuchFile`),`missing`);let s;try{s=k(a)}catch{return B(e,t,C(404,`app.cli.web.reason.noSuchFile`),`missing`)}if(!w(s,this.root))return u(t,C(403,`app.cli.web.reason.outside`,{path:``}));let c=`"${o.size.toString(16)}-${Math.floor(o.mtimeMs).toString(16)}"`,l=E.extname(s)===`.html`;t.setHeader(`ETag`,c),t.setHeader(`Cache-Control`,l?`no-cache`:`private, max-age=3600`),e.headers[`if-none-match`]===c?(t.writeHead(304),t.end()):(t.writeHead(200,{"Content-Type":V[E.extname(s).toLowerCase()]??`application/octet-stream`,"Content-Length":o.size}),e.method===`HEAD`?t.end():N(D(s),t,()=>void 0))}missing(t){let n=`<!doctype html><meta charset="utf-8"><title>Penstock</title><p>${e(`app.cli.web.noPage`)}</p>`;t.writeHead(503,{"Content-Type":`text/html; charset=utf-8`,"Content-Length":Buffer.byteLength(n),"Cache-Control":`no-store`}),t.end(n)}};const U=/* @__PURE__ */ new Set([`GET`,`HEAD`,`POST`,`PUT`,`PATCH`,`DELETE`]),W=/^[\w.-]{1,64}$/;function G(e,t,n){return new Promise((r,i)=>{let a=t=>{e.off(`listening`,o),i(t)},o=()=>{e.off(`error`,a),r()};e.once(`error`,a),e.once(`listening`,o),e.listen(t,n)})}async function K(e,t,n,r){if(t===0)return await G(e,0,n),e.address().port;let i;for(let a=t;a<t+r&&a<=65535;a+=1)try{return await G(e,a,n),a}catch(e){i=e;let t=e.code;if(t!==`EADDRINUSE`&&t!==`EACCES`)throw e}throw i}function q(e,t){let n=new URLSearchParams(e.searchParams);n.delete(t);let r=n.toString();return`${e.pathname}${r?`?${r}`:``}`}async function J(e){let t=e.host??`127.0.0.1`,w=e.token??y(),T=new _(e),E=new H(e.webRoot??null),D=/* @__PURE__ */ new Set,O=null,k=/* @__PURE__ */ new Map,A=async(e,t)=>{S(t);let n=e.headers.host;if(!O||!O.allowsHost(n))return u(t,C(403,`app.cli.web.reason.wrongHost`));let r=e.method??``;if(!U.has(r))return u(t,C(405,`app.cli.web.reason.methodNotAllowed`),{Allow:`GET, HEAD, POST, PUT, PATCH, DELETE`});let i=e.url??``;if(i.length>8192)return u(t,C(414,`app.cli.web.reason.tooLong`));if(!i.startsWith(`/`)||i.startsWith(`//`))return u(t,C(400,`app.cli.web.reason.badPath`,{path:``}));if(!O.allowsOrigin(typeof e.headers.origin==`string`?e.headers.origin:void 0,n)||!v(e.headers))return u(t,C(403,`app.cli.web.reason.wrongOrigin`));let a;try{a=new URL(i,`http://${n}`)}catch{return u(t,C(400,`app.cli.web.reason.badPath`,{path:``}))}let o=a.pathname.startsWith(`/api/`)||a.pathname.startsWith(`/vscode/`)||a.pathname.startsWith(`/web/`);if(!o&&r===`GET`&&a.searchParams.has(`token`)){let n=a.searchParams.get(`token`),r=n===null?void 0:k.get(n);if(r!==void 0&&k.delete(n),!p(n,w)&&!(r!==void 0&&r>Date.now()))return B(e,t,C(401,`app.cli.web.reason.noToken`),`expired`);t.setHeader(`Set-Cookie`,h(w)),t.setHeader(`Cache-Control`,`no-store`),t.writeHead(303,{Location:q(a,`token`)}),t.end()}else{if(!f(e.headers,w))return o?u(t,C(401,`app.cli.web.reason.noToken`)):B(e,t,C(401,`app.cli.web.reason.noToken`),`expired`);if(!o)return E.serve(e,t,a.pathname);await j(e,t,a,r)}},j=async(e,t,s,f)=>{let p=x(f,s.pathname);if(p.kind===`none`)return u(t,C(404,`app.cli.web.reason.noSuchOperation`));if(p.kind===`method`)return u(t,C(405,`app.cli.web.reason.methodNotAllowed`),{Allow:p.allowed.join(`, `)});let{route:h,params:g}=p,_=T.context;t.setHeader(`X-Penstock-Project`,_.id);let v=new AbortController;t.once(`close`,()=>{t.writableEnded||v.abort()});let y=T.track(_,v),b=null,S=null;try{let n=l(h);if(n!==`none`){let t=e.headers[`x-penstock-project`];if(typeof t==`string`&&t!==``&&t!==_.id)throw C(409,`app.cli.web.reason.projectChanged`);if(n===`required`&&!_.open)throw C(409,`app.cli.web.reason.noProject`)}let r;if(f!==`GET`){let t=await d(e,h.limit??1048576);if(t.length>0){if(!/^application\/json\b/i.test(e.headers[`content-type`]??``))throw C(415,`app.cli.web.reason.notJson`);try{r=JSON.parse(t.toString(`utf8`))}catch{throw C(400,`app.cli.web.reason.notJson`)}}}else e.resume();h.operationId===`askEngine`&&typeof r==`object`&&r&&/^(POST|PUT|PATCH|DELETE)$/.test(String(r.method))&&(b=T.beginDeploy());let i=e.headers[`x-penstock-client`],u={body:r,query:s.searchParams,params:g,headers:e.headers,signal:v.signal,client:typeof i==`string`&&W.test(i)?i:`shared`,resource:c(e.headers),workspace:T},p=Promise.resolve().then(()=>h.run(u,_));p.catch(()=>void 0);let y=h.held?await p:await Promise.race([p,new Promise((e,t)=>{S=setTimeout(()=>{v.abort(),t(C(504,`app.cli.web.reason.tookTooLong`))},a),S.unref()})]);if(v.signal.aborted&&t.destroyed){y instanceof m&&y.body.destroy();return}if(y instanceof m){t.setHeader(`Cache-Control`,`no-store`),t.writeHead(200,y.headers),N(y.body,t,()=>void 0);return}o(t,200,y)}catch(e){if(e instanceof r)return void t.destroy();if(t.destroyed)return;u(t,e instanceof i?e:n(e))}finally{S&&clearTimeout(S),y(),b?.()}},P=M({maxHeaderSize:16384,requestTimeout:6e4,headersTimeout:15e3,keepAliveTimeout:5e3},(e,t)=>{A(e,t).catch(e=>{t.headersSent?t.destroy():u(t,n(e))})});P.maxConnections=512,P.on(`connection`,e=>{D.add(e),e.once(`close`,()=>D.delete(e))}),P.on(`clientError`,(e,t)=>{t.writable?t.end(`HTTP/1.1 400 Bad Request\r
2
+ Connection: close\r
3
+ Content-Length: 0\r
4
+ \r
5
+ `):t.destroy()});let F=e.port??8765,I;try{I=await K(P,F,t,e.portSearch??100)}catch(e){throw T.shutdown(),e}O=s(t,I);let L=g(t)?`127.0.0.1`:b(t),R=`http://${L===`0.0.0.0`?`127.0.0.1`:L}:${I}`,z=null;return{server:P,get context(){return T.context},workspace:T,token:w,host:t,port:I,requestedPort:F,url:R,entry:`${R}/?token=${w}`,launch(){let e=Date.now();for(let[t,n]of k)n<=e&&k.delete(t);let t=y();return k.set(t,e+6e4),`${R}/?token=${t}`},close(){return z??=new Promise(e=>{T.shutdown(),P.close(()=>e()),P.closeIdleConnections(),setTimeout(()=>{for(let e of D)e.destroy();P.closeAllConnections()},500).unref();for(let e of D)e.destroyed||e.setTimeout(1e3,()=>e.destroy())}),z}}}const Y=/^[A-Za-z0-9]([A-Za-z0-9.-]{0,251}[A-Za-z0-9])?$/;function X(e,t){e.write(`${t}\n`)}function Z(e){return e===void 0?8765:/^\d{1,5}$/.test(e)&&Number(e)<=65535?Number(e):null}function Q(e){if(e===void 0)return`127.0.0.1`;let t=e.replace(/^\[|\]$/g,``);return P(t)!==0||Y.test(t)?t:null}function $(t){return new Promise(n=>{let r=!1,i=()=>{r&&process.exit(130),r=!0,X(process.stderr,e(`app.cli.web.stopping`)),t.close().finally(n)};process.on(`SIGINT`,i),process.on(`SIGTERM`,i),t.server.once(`close`,()=>{process.off(`SIGINT`,i),process.off(`SIGTERM`,i),n()})})}async function ee(t,n){let r=t===void 0?void 0:E.resolve(t);if(r!==void 0){let t;try{t=A(r)}catch{return{ok:!1,lines:[T(r)]}}if(!t.isDirectory())return{ok:!1,lines:[e(`app.cli.web.notAFolder`,{folder:r})]}}let i=Z(n.port);if(i===null)return{ok:!1,lines:[e(`app.cli.web.badPort`,{value:n.port??``})]};let a=Q(n.host);if(a===null)return{ok:!1,lines:[e(`app.cli.web.badHost`,{value:n.host??``})]};let o;try{o=await J({folder:r,host:a,port:i,webRoot:I(),openLink:F,say:e=>X(process.stdout,e)})}catch(t){return t.code===`EADDRINUSE`?{ok:!1,lines:[e(`app.cli.web.noFreePort`,{from:i,to:i+99})]}:{ok:!1,lines:[e(`app.cli.web.cannotListen`,{reason:t instanceof Error?t.message:String(t)})]}}let s=$(o);return g(a)||X(process.stderr,e(`app.cli.web.exposed`,{host:a})),o.port!==i&&i!==0&&X(process.stderr,e(`app.cli.web.portTaken`,{port:i,used:o.port})),X(process.stdout,o.context.open?e(`app.cli.web.serving`,{folder:o.context.folder}):e(`app.cli.web.servingWelcome`)),X(process.stdout,` ${o.entry}`),X(process.stdout,e(`app.cli.web.pressCtrlC`)),I()===null&&X(process.stderr,e(`app.cli.web.noPageWarning`)),n.open&&F(o.launch()).catch(()=>X(process.stderr,e(`app.cli.web.browserFailed`))),await s,{ok:!0,lines:[]}}export{ee as webCommand};
@@ -0,0 +1 @@
1
+ import{t as e}from"./chunk-atomicWrite-C6J1gDtO.js";import{r as t}from"./chunk-translator-BFUJmSkR.js";import{t as n}from"./chunk-table-CJtiXv0e.js";import{c as r,d as i}from"./chunk-moddle-Dlk0NR-u.js";import{y as a}from"./chunk-engine-CxgdJ2wO.js";import{a as o,c as s,d as c,f as l,i as u,l as d,n as f,o as p,p as m,r as h,s as g,u as _}from"./chunk-apply-BAMwoXG9.js";import{r as v}from"./chunk-context-DPJmldqg.js";import{n as y,t as b}from"./chunk-editPreview-BgH1JVOD.js";import{t as x}from"./chunk-plural-Bq_4vgOr.js";import{n as S}from"./chunk-placeholderLayout-B18ekWmh.js";import{t as C}from"./chunk-diff-D1m_eKvv.js";import{n as w}from"./chunk-drawing-shRfnrs9.js";import{j as T}from"./chunk-diagramDefects-7UG_Iwsr.js";import{a as E}from"./chunk-diagram-BaVwLa4h.js";import{createRequire as D}from"node:module";import O from"node:path";import{tmpdir as k}from"node:os";import{mkdtempSync as A,readFileSync as j,rmSync as M,writeFileSync as N}from"node:fs";const P=D(import.meta.url),F={camunda:JSON.parse(j(P.resolve(`camunda-bpmn-moddle/resources/camunda.json`),`utf8`)),operaton:i,zeebe:JSON.parse(j(P.resolve(`zeebe-bpmn-moddle/resources/zeebe.json`),`utf8`)),flowable:r(`flowable`),activiti:r(`activiti`)},I=/^bpmn:(\w*Task|CallActivity|\w*Gateway|(Start|End|IntermediateCatch|IntermediateThrow)Event)$/;var L=class e{modeler;container;engine;conventions;importWarnings=0;constructor(e,t,n,r){this.modeler=e,this.container=t,this.engine=n,this.conventions=r}static async open(t,n,r={}){let{window:i}=await w(`modeler`),o=i.document.createElement(`div`);i.document.body.appendChild(o);let s=i.BpmnJS,c=a(n),l=new s({container:o,moddleExtensions:c===`plain`?{}:{[c]:F[c]}}),u=new e(l,o,n,r),d=l.get(`graphicsFactory`);d.update=()=>{};let{warnings:f}=await l.importXML(t);return u.importWarnings=f.length,u}dispose(){this.modeler.destroy(),this.container.remove()}async save(){return`${(await this.modeler.saveXML({format:!0})).xml}\n`}get registry(){return this.modeler.get(`elementRegistry`)}get modeling(){return this.modeler.get(`modeling`)}get moddle(){return this.modeler.get(`moddle`)}get properties(){return{modeling:this.modeling,moddle:this.moddle}}element(e){let n=this.registry.get(e);if(!n||n.type===`label`)throw new u(t(`app.cli.edit.noSuchElement`,{id:e}));return n}async apply(e,n){switch(e.op){case`add`:return this.add(e,n);case`connect`:return this.connect(e);case`set`:{let n=this.element(e.id);return h(this.properties,this.engine,n,e.properties),t(`app.cli.edit.set`,{keys:Object.keys(e.properties).join(`, `),id:n.id})}case`remove`:{let n=this.element(e.id);if(n.type===`bpmn:Process`||n.type===`bpmn:Collaboration`)throw new u(t(`app.cli.edit.isTheRoot`,{id:n.id}));return this.modeling.removeElements([n]),t(`app.cli.edit.removed`,{id:n.id})}case`move`:{let n=this.element(e.id);if(n.waypoints)throw new u(t(`app.cli.edit.isAConnection`,{id:n.id}));return this.modeling.moveElements([n],{x:e.dx,y:e.dy}),t(`app.cli.edit.moved`,{id:n.id,dx:e.dx,dy:e.dy})}}}add(e,n){let r=this.element(e.after);if(r.waypoints)throw new u(t(`app.cli.edit.isAConnection`,{id:r.id}));if(r.type===`bpmn:EndEvent`)throw new u(t(`app.cli.edit.afterEndEvent`,{id:r.id}));if(r.type===`bpmn:Participant`||r.type===`bpmn:Lane`)throw new u(t(`app.cli.edit.addAfterAnElementInside`,{id:r.id,type:l(r)}));let i=o[e.element].type,a=this.idFor(i,e.id,e.name),s=this.place(r,()=>this.modeler.get(`elementFactory`).createShape({type:i,businessObject:this.modeler.get(`bpmnFactory`).create(i,a?{id:a}:{}),...e.event?{eventDefinitionType:p[e.event]}:{}}),n),c=_(this.conventions,s.businessObject.$type);return Object.keys(c).length>0&&this.modeling.updateProperties(s,c),e.name&&this.modeling.updateProperties(s,{name:e.name}),e.properties&&h(this.properties,this.engine,s,e.properties),t(`app.cli.edit.added`,{type:l(s),id:s.id,after:r.id})}place(e,t,n){let r=this.modeler.get(`commandStack`),i=new Set(this.registry.getAll().map(e=>e.id)),a=this.modeler.get(`autoPlace`).append(e,t());if(!n)return a;let o=t=>{let n=Math.min(e.x,t.x)-160,r=Math.min(e.y,t.y)-160,i=Math.max(e.x+e.width,t.x+t.width)+160,a=Math.max(e.y+e.height,t.y+t.height)+160;return{x:n,y:r,width:i-n,height:a-r}},s=e=>n(E(this.modeler.getDefinitions(),this.moddle,e,i)),c=o(a),l=s(c);if(l<=0)return a;if(r.undo(),l-s(c)<=0)return r.redo(),a;let u=a.width,d=a.height,f=e.x+e.width+80+u/2,p=e.y+e.height/2,m=[];for(let e of[0,1,2,3,4])for(let t of[1,-1,2,-2,3,-3,4,-4,0])(e!==0||t!==0)&&m.push([f+e*(u+60),p+t*(d+60)]);let h=I.test(a.type)?this.registry.filter(t=>t.parent===e.parent&&!t.waypoints&&I.test(t.type)):[],g=e=>{let t={x:e[0]-u/2,y:e[1]-d/2,width:u,height:d};return h.filter(e=>T(t,e)).length},_={position:null,route:0,extra:1/0};for(let n of m){if(g(n)*1e3>=_.extra)continue;let i=o({x:n[0]-u/2,y:n[1]-d/2,width:u,height:d}),a=s(i),c=this.modeling.appendShape(e,t(),{x:n[0],y:n[1]},e.parent),l=c.incoming[0];for(let[t,o]of[null,...this.routes(e,c)].entries()){o&&this.modeling.updateWaypoints(l,o);let e=s(i)-a;if(e<=0)return c;e<_.extra&&(_={position:n,route:t,extra:e}),o&&r.undo()}r.undo()}if(!_.position)return this.modeler.get(`autoPlace`).append(e,t());let v=this.modeling.appendShape(e,t(),{x:_.position[0],y:_.position[1]},e.parent),y=_.route>0?this.routes(e,v)[_.route-1]:null;return y&&this.modeling.updateWaypoints(v.incoming[0],y),v}routes(e,t){let n={x:e.x+e.width/2,y:e.y+e.height/2},r={x:t.x+t.width/2,y:t.y+t.height/2},i=r.y>n.y,a=[{x:n.x,y:i?e.y+e.height:e.y},{x:n.x,y:r.y},{x:t.x,y:r.y}],o=[{x:e.x+e.width,y:n.y},{x:r.x,y:n.y},{x:r.x,y:i?t.y:t.y+t.height}],s=e.x+e.width,c=[{x:s,y:n.y},{x:s+20,y:n.y},{x:s+20,y:r.y},{x:t.x,y:r.y}],l=[{x:s,y:n.y},{x:t.x-20,y:n.y},{x:t.x-20,y:r.y},{x:t.x,y:r.y}];return n.y===r.y?[]:[c,a,o,l]}idFor(e,n,r){let i=e=>!!this.registry.get(e);if(n){if(i(n))throw new u(t(`app.cli.edit.idTaken`,{id:n}));return n}let a=r&&this.conventions.ids?c({$type:e},r,this.conventions.ids):null;return a?m(a,i):void 0}connect(e){let n=this.element(e.from),r=this.element(e.to),i=this.modeler.get(`bpmnRules`).canConnect(n,r);if(!i||i.type!==`bpmn:SequenceFlow`)throw new u(t(`app.cli.edit.noSequenceFlow`,{from:n.id,to:r.id}));let a=this.modeling.connect(n,r,{type:`bpmn:SequenceFlow`});return e.name&&this.modeling.updateProperties(a,{name:e.name}),e.condition&&h(this.properties,this.engine,a,{condition:e.condition}),t(`app.cli.edit.connect`,{from:n.id,to:r.id,id:a.id})}describe(){return this.registry.getAll().filter(e=>e.type!==`label`&&e.businessObject&&e.parent).map(e=>{let t=e.businessObject,n={id:e.id,type:l(e),name:t.name||void 0,parent:e.parent?.parent?e.parent.id:void 0,incoming:(e.incoming??[]).map(e=>e.id),outgoing:(e.outgoing??[]).map(e=>e.id),properties:f(t,this.engine)};return e.waypoints&&(n.source=e.source?.id,n.target=e.target?.id),n})}};const R=[`LOST-CONNECTION`,`SEMANTIC-DRIFT`,`BACKTRACK`,`CONTAINMENT`,`OVERLAP`,`EDGE-THROUGH-NODE`,`DETACHED-EDGE`,`LABEL-OVERLAP`,`DANGLING-CONNECTION`,`BOUNDARY-OFF-HOST`],z=e=>R.includes(e.slice(0,e.indexOf(`:`)));async function B(e){let t=A(O.join(k(),`penstock-edit-`));try{let n=O.join(t,`diagram.bpmn`);N(n,e);let{measureDiagram:r}=await import(`./chunk-diagram-CCA1-fT5.js`);return(await r(n,{asAuthored:!0})).defects.map(e=>`${e.kind}: ${e.detail}`)}finally{M(t,{recursive:!0,force:!0})}}async function V(e,t){let n=A(O.join(k(),`penstock-edit-`));try{return N(O.join(n,`before.bpmn`),e),N(O.join(n,`after.bpmn`),t),(await C(O.join(n,`before.bpmn`),O.join(n,`after.bpmn`),!0)).summary?.lines??[]}finally{M(n,{recursive:!0,force:!0})}}async function H(n,r,i={}){let a=j(n,`utf8`),o=y(n,a),s;try{s=d(r,o)}catch(e){return{ok:!1,applied:[],lines:[e instanceof Error?e.message:String(e),t(`app.cli.nothingWritten`)]}}let c=new Set(await B(a)),l=e=>{let t=e.filter(e=>!c.has(e));return t.filter(z).length*1e3+t.filter(e=>!z(e)).length},f=await L.open(a,o,b(n)),p=[],m;try{for(let e of s)p.push(await f.apply(e,l));m=await f.save()}catch(e){let n=e instanceof u?e.message:t(`app.cli.edit.editorRefused`,{reason:e instanceof Error?e.message:String(e)});return{ok:!1,applied:[],lines:[t(`app.cli.edit.operationFailed`,{number:p.length+1,message:n}),t(`app.cli.nothingWritten`)]}}finally{f.dispose()}let h=await L.open(m,o),g=h.importWarnings;h.dispose();let _=await L.open(a,o),S=_.importWarnings;if(_.dispose(),g>S)return{ok:!1,applied:p,lines:[t(`app.cli.edit.didNotReadBack`),t(`app.cli.nothingWritten`)]};let C=(await B(m)).filter(e=>!c.has(e)),w=C.filter(z),T=C.filter(e=>!z(e)),E=w.length>0&&!i.force;if(!i.dryRun&&!E){if(j(n,`utf8`)!==a)return{ok:!1,applied:p,lines:[t(`app.cli.edit.changedWhileEditing`),t(`app.cli.nothingWritten`)]};e(n,m)}let D=[...p,``,...(await V(a,m)).map(e=>` ${e}`),``,w.length===0?t(`app.cli.edit.nothingBroken`):t(`app.cli.edit.breaksTheDrawing`,{problems:x(w.length,`app.cli.edit.count.newProblem`)}),...w.map(e=>` ${e}`),...T.length>0?[t(`app.cli.edit.readsLessWell`,{things:x(T.length,`app.cli.edit.count.thing`)}),...T.map(e=>` ${e}`)]:[],i.dryRun?t(`app.cli.edit.dryRun`,{file:v(n)}):t(E?`app.cli.edit.wouldBreak`:`app.cli.wrote`,{file:v(n)})];return{ok:!E,applied:p,xml:m,lines:D}}async function U(e){let t=j(e,`utf8`),n=y(e,t),r=await L.open(await S(t),n);try{return{engine:n,elements:r.describe()}}finally{r.dispose()}}async function W(e,r){let{engine:i,elements:a}=await U(e);if(r)return{ok:!0,lines:[JSON.stringify({file:v(e),engine:i,elements:a},null,2)]};let o=a.map(e=>({type:e.type,id:e.id,name:e.name??``,flow:e.source&&e.target?`${e.source} -> ${e.target}`:``})),s=n(o,{columns:[{name:`type`,header:t(`app.cli.header.type`),minWidth:16},{name:`id`,header:t(`app.cli.header.id`),minWidth:14},{name:`name`,header:t(`app.cli.header.name`)},{name:`flow`,header:t(`app.cli.header.flow`)}]});return{ok:!0,lines:[`${v(e)} (${i})`,``,...s]}}function G(e){let t=j(e,`utf8`);return{ok:!0,lines:[JSON.stringify(s(y(e,t)),null,2)]}}function K(e,t,n){let r=Object.hasOwn(g[e],t)?g[e][t].kind:void 0;return r===`boolean`?n===`true`||n!==`false`&&n:r===`integer`&&/^\d+$/.test(n)?Number(n):n}function q(e,n){return e.map(e=>{let r=e.indexOf(`=`);if(r<=0)throw new u(t(`app.cli.edit.mustLookLikePairs`,{where:n,entry:e}));return[e.slice(0,r),e.slice(r+1)]})}function J(e,n){let[r,...i]=n.words,a=()=>{let t=[...i.slice(r===`set`?1:i.length),...n.options(`set`)],a=Object.fromEntries(q(t,`--set`).map(([t,n])=>[t,K(e,t,n)])),o=q(n.options(`input`),`--input`),s=q(n.options(`output`),`--output`);return o.length>0&&(a.inputs=Object.fromEntries(o)),s.length>0&&(a.outputs=Object.fromEntries(s)),Object.keys(a).length>0?a:void 0},o=e=>Object.fromEntries(Object.entries(e).filter(([,e])=>e!==void 0));switch(r){case`add`:return o({op:`add`,element:i[0],after:n.option(`after`),event:n.option(`event`),name:n.option(`name`),id:n.option(`id`),properties:a()});case`connect`:return o({op:`connect`,from:i[0],to:i[1],name:n.option(`name`),condition:n.option(`condition`)});case`set`:return{op:`set`,id:i[0],properties:a()??{}};case`remove`:return{op:`remove`,id:i[0]};default:throw new u(t(`app.cli.edit.sayWhatToDo`))}}export{G as a,J as i,H as n,W as o,U as r,R as t};
@@ -0,0 +1 @@
1
+ import{r as e}from"./chunk-translator-BFUJmSkR.js";import{n as t,t as n}from"./chunk-status-DgeSOz3A.js";import{t as r}from"./chunk-table-CJtiXv0e.js";import{Ct as i,Dt as a,Et as o,St as s,X as c,Y as l,Z as u,an as d,fn as f,mn as p,rn as m,sn as h,wt as g,xt as _}from"./chunk-src-BLyg_6UX.js";import{a as v}from"./chunk-moddle-Dlk0NR-u.js";import{i as y,t as b}from"./chunk-workerVariables-CCLcoR0U.js";import{n as x,r as S}from"./chunk-docs-CY6ICsip.js";import{a as C,n as w,r as T,s as E}from"./chunk-failure-BsimkHy_.js";import{r as D,t as O}from"./chunk-context-DPJmldqg.js";import{n as k,r as A}from"./chunk-baseline-DvS2S0am.js";import{n as j,r as M,t as N}from"./chunk-report-CDz78nCI.js";import{t as P}from"./chunk-rules-DJlL7K_Q.js";import{t as F}from"./chunk-plural-Bq_4vgOr.js";import{t as I}from"./chunk-placeholderLayout-B18ekWmh.js";import{a as L,c as R,i as z}from"./chunk-codeLinks-D-gzUjYv.js";import B from"node:path";import{tmpdir as V}from"node:os";import{mkdtempSync as H,readFileSync as U,rmSync as W}from"node:fs";async function G(){return import(`./chunk-diagram-CCA1-fT5.js`)}const K=[`drawing`,`rules`,`flow`,`variables`];function q(e){if(e===void 0)return{sections:K};let t=e.split(`,`).map(e=>e.trim()).filter(e=>e.length>0),n=[],r;for(let e of t)K.includes(e)?n.push(e):r===void 0&&(r=e);return{sections:n,unknown:r}}const J=/\.bpmn(\.xml|20\.xml)?$/i,Y=/\.form$/i;async function X(t){let n=/* @__PURE__ */ new Map,r=/* @__PURE__ */ new Map,i=/* @__PURE__ */ new Map,a=e=>{for(let t of e??[]){if(!t?.id)continue;let e=typeof t.name==`string`?t.name.trim():``;e&&n.set(t.id,e),r.set(t.id,l(String(t.$type??``))),t.sourceRef&&t.targetRef&&i.set(t.id,[t.sourceRef.id,t.targetRef.id]),a(t.flowElements)}};try{let e=await v(U(t,`utf8`));for(let t of e?.rootElements??[]){t.id&&n.set(t.id,typeof t.name==`string`&&t.name.trim()||``);for(let e of t.participants??[])e.id&&e.name&&n.set(e.id,String(e.name).trim()),a(e.processRef?.flowElements);a(t.flowElements)}}catch{return e=>e}let o=t=>n.get(t)||(r.get(t)?e(`app.rules.drawing.theElement`,{type:r.get(t)}):t);return t=>{let r=n.get(t);if(r)return r;let a=i.get(t);return a?e(`app.rules.drawing.theConnection`,{from:o(a[0]),to:o(a[1])}):o(t)}}async function ee(e){let t=U(e,`utf8`);if(!I(t)&&await v(t))return[];let{measureDiagram:n}=await G(),r=await n(e,{asAuthored:!0}),i=await X(e);return r.defects.map(t=>{let n=t.elements??[];return N(`drawing`,{file:e,rule:t.kind,message:t.detail,severity:S(`drawing`,t.kind)?.severity===`warning`?`warning`:`error`,title:c(`drawing`,t.kind),...n.length>0?{where:u(n.map(i)),elements:n}:{}})})}const Z={error:0,warning:1,note:2};function te(e){let t=e.elements??[],r=t.length>0?` (${t.join(`, `)})`:``,i=e.message.endsWith(r)&&r?e.message.slice(0,-r.length):e.message,a=e.title?`${e.title}${e.where?` - ${e.where}`:``}`:i;return[` ${n(e.severity).padEnd(7)} ${a}`,` ${` `.repeat(7)} ${e.ruleId??e.rule}${t.length>0?` ${t.join(`, `)}`:``}`]}function ne(t,n){let r=!1;try{r=U(t,`utf8`).trim()===``}catch{r=!1}let i=m(t),a=C(n);return{file:t,rule:`file-unreadable`,message:w(n)?T(t):a===null?r?e(`app.output.theFileIsEmpty`):e(`app.output.notValidFile`,{what:i,reason:p(f(n))}):`${t}: ${a}`,severity:`error`}}async function Q(e,n){let{ruleFindings:r}=await import(`./chunk-lint-C_fAcLIg.js`),{flowFindings:i,unreadableDmn:o}=await import(`./chunk-analyze-Brxlb4U1.js`),{allows:s,upsell:c}=await import(`./chunk-features-BwnwB6jL.js`),{currentLicense:l}=await import(`./chunk-license-B_To2110.js`),u=new Set(n.sections??K),d=await l(),f=n.flowAllowed??s(d),p=n.variablesAllowed??s(d),m=[],h=/* @__PURE__ */ new Map,g=[],_=[],v=0,y=!1;for(let n of e){let e=[];try{if(J.test(n)&&u.has(`drawing`)&&e.push(...await ee(n)),J.test(n)&&u.has(`rules`)&&e.push(...await r(n)),u.has(`flow`)){let t=/\.dmn$/i.test(n)?await o(n):null;t?e.push(t):f||Y.test(n)?e.push(...await i(n)):y=!0}if(J.test(n)&&u.has(`variables`)){let t=O(n).values,r=a(t);r.mode!==`off`&&p?e.push(...await ie(n,r,h)):r.mode!==`off`&&typeof t.variables?.check==`string`&&m.length===0&&await re(n,h)&&m.push(...c(d,`variable-checks`))}}catch(t){e.splice(0,e.length,ne(n,t))}let s=e.filter(e=>e.elements&&e.title),l=P(e.filter(e=>!(e.elements&&e.title)).map(e=>({...e,elements:e.elements??[]})),s.map(e=>({kind:e.rule,elements:e.elements??[]})));e.splice(0,e.length,...[...s,...l].sort((e,t)=>Z[e.severity]-Z[t.severity])),g.push(...e);let b=e.filter(e=>e.severity===`error`);if(e.length===0)_.push(`${t(`ok`).padEnd(5)} ${D(n)}`);else{b.length>0&&(v+=1),_.push(`${(b.length>0?t(`fail`):t(`note`)).padEnd(5)} ${D(n)}`);for(let t of e.slice(0,40))_.push(...te(t))}}let b=e.length>0?O(e[0]).root:process.cwd(),x=n.baseline?k(b,g):null;return{findings:g,reported:x?x.fresh:g,comparison:x,failed:v,flowSkipped:y,offer:m,lines:_,root:b}}function $(e,t){let n=O(e),r=t.get(n.root);if(r)return r;let i=[n.root,...L(n.root,z(n.values))].flatMap(e=>R(e)).map(e=>({path:e,text:U(e,`utf8`)}));return t.set(n.root,i),i}async function re(e,t){let n=U(e,`utf8`),r=await d(e,n);if(r.workers.length===0)return!1;let i=r.workers.map(e=>({kind:e.kind===`JAVA_CLASS`?`CLASS`:e.kind,value:e.value,elementId:e.elementId}));return(await b($(e,t),i)).fetches.length>0}async function ie(e,t,n){let r=U(e,`utf8`),a=await d(e,r);if(a.workers.length===0)return[];let l=await v(r),u=a.workers.map(e=>({kind:e.kind===`JAVA_CLASS`?`CLASS`:e.kind,value:e.value,elementId:e.elementId})),f=await b($(e,n),u),p=o({model:y(a,f),definitions:l,order:h(l),types:f.types??[],inputs:t.inputs,linked:new Set(f.fetches.map(e=>e.elementId)),mode:t.mode,entitled:!0});return[...p.fields.map(t=>N(`code`,{file:e,rule:`variable-field`,message:_(t),severity:`warning`,title:c(`code`,`variable-field`),where:s(t),elements:[t.elementId]})),...p.names.map(t=>N(`code`,{file:e,rule:`variable-unknown`,message:i(t.name),severity:`warning`,title:c(`code`,`variable-unknown`),where:g(),elements:[t.elementId]}))]}async function ae(t,n){let r=await Q(t,n),i=[...r.lines];if(r.offer.length>0&&n.format===`text`&&i.push(``,...r.offer),n.format===`text`&&r.findings.some(e=>e.docs)&&i.push(``,e(`app.output.everyRuleHasAPage`,{url:x})),r.flowSkipped&&n.format===`text`&&i.push(``,e(`app.output.flowAnalysisLeftOut`)),n.updateBaseline){let t=A(r.root,r.findings);return{ok:!0,lines:[e(`app.output.wroteFindings`,{file:D(t),findings:F(r.findings.length,`app.output.count.finding`)})]}}let a=r.comparison?r.reported.some(e=>e.severity===`error`):r.failed>0;if(n.format===`sarif`)return{ok:!a,refused:!1,lines:[M(r.reported,`check`)]};if(n.format===`github`)return{ok:!a,refused:!1,lines:j(r.reported)};if(n.format===`json`)return{ok:!a,refused:!1,lines:[JSON.stringify(r.reported,null,2)]};if(r.comparison){let t=[r.reported.length>0?e(`app.output.newFindings`,{count:r.reported.length}):e(`app.output.nothingNew`),e(`app.output.accepted`,{count:r.comparison.known.length}),r.comparison.fixed.length>0?e(`app.output.fixedSinceTheBaseline`,{count:r.comparison.fixed.length}):``].filter(Boolean);i.push(``,t.join(`, `)),r.comparison.fixed.length>0&&i.push(e(`app.output.runUpdateBaseline`))}return{ok:!a,refused:!1,lines:i}}async function oe(n,i){let{measureDiagram:a}=await G(),o=[],s=0,c=0,l=i?``:H(B.join(V(),`penstock-layout-`));try{for(let[r,u]of n.entries()){let n=i?u:B.join(l,`${r}.bpmn`),d,f;try{d=U(u,`utf8`),await a(u,{outPath:n}),f=U(n,`utf8`)}catch(e){c+=1,o.push({status:t(`fail`),file:D(u),details:E(D(u),e)});continue}f===d?o.push({status:t(`same`),file:D(u),details:e(`app.output.noChange`)}):(s+=1,o.push({status:t(i?`wrote`:`change`),file:D(u),details:e(i?`app.output.reflowedLayout`:`app.output.wouldReflowLayout`)}))}}finally{l&&W(l,{recursive:!0,force:!0})}let u=r(o,{columns:[{name:`status`,header:e(`app.cli.header.status`),minWidth:6},{name:`file`,header:e(`app.cli.header.file`),minWidth:24},{name:`details`,header:e(`app.cli.header.details`)}]});return!i&&s>0&&u.push(``,e(`app.output.layoutAlwaysReflows`)),{ok:c===0,refused:!1,lines:u}}export{q as a,oe as i,ae as n,Q as r,K as t};
@@ -0,0 +1,4 @@
1
+ import{r as e}from"./chunk-translator-BFUJmSkR.js";import{r as t}from"./chunk-commands-CeRlfHY-.js";import{t as n}from"./chunk-diff-D1m_eKvv.js";import r from"node:path";const i=`<!-- penstock-report -->`;function a(e){return e.map(e=>`- ${e}`).join(`
2
+ `)}async function o(o){let s=[i,e(`app.cli.report.heading`),``];if(o.changed.length===0&&o.removed.length===0)return s.push(e(`app.cli.report.nothingChanged`)),{markdown:`${s.join(`
3
+ `)}\n`,clean:!0};o.removed.length>0&&s.push(e(`app.cli.report.removed`),``,a(o.removed),``);let c=new Map(o.changed.map(e=>[e.after,e.relative])),l=(await t(o.changed.map(e=>e.after),{format:`json`,baseline:!0,updateBaseline:!1})).reported;if(s.push(e(`app.cli.report.check`),``),l.length===0)s.push(e(`app.cli.report.cleanAgainstTheBaseline`),``);else{let e=/* @__PURE__ */ new Map;for(let t of l){let n=c.get(t.file)??r.basename(t.file);e.set(n,[...e.get(n)??[],`\`${t.rule}\` ${t.message}`])}for(let[t,n]of e)s.push(`**${t}**`,``,a(n),``)}let u=/* @__PURE__ */ new Map;s.push(e(`app.cli.report.whatChanged`),``);for(let t of o.changed){if(!t.before){s.push(`**${t.relative}** - ${e(`app.cli.report.newFile`)}`,``);continue}let r=await n(t.before,t.after,!0);if(!r.ok){s.push(`**${t.relative}**`,``,a(r.lines),``);continue}let i=r.summary?.lines??[];r.summary&&u.set(t.relative,r.summary.markersAfter),s.push(`**${t.relative}**`,``,i.length>0?a(i):e(`app.cli.report.onlyTheDrawingMoved`),``)}let d=[];for(let e of o.changed){let t=await o.picture(e,u.get(e.relative)??{});t&&d.push({relative:e.relative,url:t})}if(s.push(e(`app.cli.report.howItLooks`),``),d.length===0&&o.picturesLink)s.push(e(`app.cli.report.thePicturesLink`,{link:o.picturesLink}),``);else if(d.length===0)s.push(e(`app.cli.report.noPictures`),``);else{s.push(e(`app.cli.report.outlined`),``);for(let e of d)s.push(`**${e.relative}**`,``,`![${e.relative}](${e.url})`,``)}return{markdown:`${s.join(`
4
+ `)}\n`,clean:l.length===0}}export{o as n,i as t};
@@ -0,0 +1 @@
1
+ import{f as e}from"./chunk-license-x3oHbKe2.js";import{r as t}from"./chunk-translator-BFUJmSkR.js";import{t as n}from"./chunk-table-CJtiXv0e.js";import{a as r,i,n as a,o,r as s,t as c}from"./chunk-connectors-eXPldvkc.js";import l from"node:path";import{closeSync as u,constants as d,lstatSync as f,mkdirSync as p,openSync as m,readFileSync as h,readdirSync as g,realpathSync as _,renameSync as v,rmSync as y,writeFileSync as b}from"node:fs";import x from"node:http";const S=/^[A-Za-z0-9._-]{1,128}$/,C=d.O_NOFOLLOW??0;let w=!1;function T(){if(w)return;w=!0;let e=process.env;if(!(e.HTTPS_PROXY||e.https_proxy||e.HTTP_PROXY||e.http_proxy))return;let t=x.setGlobalProxyFromEnv;typeof t==`function`&&t.call(x)}async function E(e,t){let n=e.body?.getReader();if(!n)return/* @__PURE__ */ new Uint8Array;let r=[],i=0;for(;;){let{done:e,value:a}=await n.read();if(e)break;if(i+=a.byteLength,i>t)return await n.cancel().catch(()=>void 0),null;r.push(a)}let a=new Uint8Array(i),o=0;for(let e of r)a.set(e,o),o+=e.byteLength;return a}function D(e){return{status:0,body:/* @__PURE__ */ new Uint8Array,failure:e}}function O(n,r=fetch,i=2e4){let a=l.join(n??e(process.env),`connectors`);function o(){return p(a,{recursive:!0}),_(a)}function x(e,t){return t===e||t.startsWith(e+l.sep)}function w(e){let n=e.split(`/`);if(n.length>16||n.some(e=>!S.test(e)||e===`.`||e===`..`))throw Error(t(`app.cli.connectors.notInside`,{path:e}));let r=o(),i=r;for(let a of n){i=l.join(i,a);let n=f(i,{throwIfNoEntry:!1});if(!n)break;if(n.isSymbolicLink())throw Error(t(`app.cli.connectors.linkAt`,{path:e}));if(!x(r,_(i)))throw Error(t(`app.cli.connectors.notInside`,{path:e}))}return l.join(r,...n)}function O(e){let n=o(),r=n;for(let i of l.relative(n,e).split(l.sep).filter(Boolean)){r=l.join(r,i);let e=f(r,{throwIfNoEntry:!1});if(e?.isSymbolicLink())throw Error(t(`app.cli.connectors.holdsALink`));if(!e)p(r);else if(!e.isDirectory())throw Error(t(`app.cli.connectors.fileInTheWay`))}}function k(e){return{entries:f(e,{throwIfNoEntry:!1})?.isDirectory()?g(e).sort():[]}}function A(e){let n=f(e,{throwIfNoEntry:!1});if(!n?.isFile())return{content:null};if(n.size>67108864)throw Error(t(`app.cli.connectors.tooLarge`));let r=m(e,d.O_RDONLY|C);try{return{content:h(r)}}finally{u(r)}}function j(e,n){let r=n??/* @__PURE__ */ new Uint8Array;if(r.byteLength>67108864)throw Error(t(`app.cli.connectors.contentTooLarge`));if(f(e,{throwIfNoEntry:!1})?.isDirectory())throw Error(t(`app.cli.connectors.directoryInTheWay`));O(l.dirname(e));let i=m(e,d.O_WRONLY|d.O_CREAT|d.O_TRUNC|C,420);try{b(i,r)}finally{u(i)}return{}}function M(e,n){if(!f(e,{throwIfNoEntry:!1}))throw Error(t(`app.cli.connectors.nothingToMove`));if(f(n,{throwIfNoEntry:!1}))throw Error(t(`app.cli.connectors.destinationExists`));return O(l.dirname(n)),v(e,n),{}}return{async fetch(e){if(!s(e))throw Error(t(`app.cli.connectors.notACatalogueUrl`,{url:e}));T();let n;try{n=await r(e,{redirect:`manual`,headers:{"User-Agent":`Penstock CLI`},signal:AbortSignal.timeout(i)})}catch(e){let n=e.cause?.message;return D(n??(e instanceof Error?e.message:t(`app.cli.connectors.githubUnreachable`)))}if(n.status>=300&&n.status<400)return await n.body?.cancel().catch(()=>void 0),D(t(`app.cli.connectors.redirect`));if(Number(n.headers.get(`content-length`)??0)>67108864)return await n.body?.cancel().catch(()=>void 0),D(t(`app.cli.connectors.responseTooLarge`));try{let e=await E(n,c);return e?{status:n.status,body:e}:D(t(`app.cli.connectors.responseTooLarge`))}catch(e){return D(e instanceof Error?e.message:t(`app.cli.connectors.interrupted`))}},async file(e,n,r,i){if(n===``){if(e!==`list`)throw Error(t(`app.cli.connectors.listOnly`));return k(o())}let a=w(n);switch(e){case`exists`:return{pathExists:f(a,{throwIfNoEntry:!1})!==void 0};case`read`:return A(a);case`write`:return j(a,r);case`delete`:return y(a,{recursive:!0,force:!0}),{};case`list`:return k(a);case`mkdirs`:return O(a),{};case`rename`:if(!i)throw Error(t(`app.cli.connectors.renameNeedsTarget`));return M(a,w(i));default:throw Error(t(`app.cli.connectors.unknownOperation`,{operation:String(e)}))}}}}async function k(e,s,c=O()){if(e[0]===`resolve`){if(!e[1])return{ok:!1,lines:[t(`app.cli.connectors.resolveUsage`)]};if(e[2]!==void 0&&!Number.isInteger(Number(e[2])))return{ok:!1,lines:[t(`app.cli.connectors.notAVersion`,{version:e[2]})]}}let{catalog:l,error:u,nextAttempt:d}=await a(c,{forceRefresh:s.has(`--refresh`)});if(!l)return{ok:!1,lines:[t(`app.cli.connectors.downloadFailed`,{reason:u??t(`app.cli.connectors.unknownReason`),when:d?t(`app.cli.connectors.retriedAfter`,{when:d}):``})]};let f=u?[t(`app.cli.connectors.usingOlder`,{ref:l.ref,reason:u})]:[];if(e[0]===`resolve`){let n=e[1],a=e[2]===void 0?void 0:Number(e[2]),s=a===void 0?r(l,n):o(l,n,a);if(!s){let e=a===void 0?n:t(`app.cli.connectors.idVersion`,{id:n,version:a});return{ok:!1,lines:[...f,t(`app.cli.connectors.noTemplate`,{which:e,ref:l.ref})]}}let u=await i(c,s);return u?{ok:!0,lines:[...f,JSON.stringify(u,null,2)]}:{ok:!1,lines:[...f,t(`app.cli.connectors.cacheMissing`,{id:s.id})]}}let p=[...f,t(`app.cli.connectors.summary`,{ref:l.ref,current:l.newest.length,older:l.templates.length})],m=n(l.newest,{columns:[{name:`name`,header:t(`app.cli.header.name`)},{name:`id`,header:t(`app.cli.header.id`)},{name:`version`,header:t(`app.cli.header.version`),value:e=>e.version===null?``:`v${e.version}`},{name:`elementType`,header:t(`app.cli.header.type`),value:e=>e.elementType??``},{name:`engine`,header:t(`app.cli.header.engine`),value:e=>e.engines?.camunda?`Camunda ${e.engines.camunda}`:``}]});return{ok:!0,lines:[...p,``,...m]}}export{k as connectorsCommand};
@@ -0,0 +1,2 @@
1
+ import{r as e}from"./chunk-translator-BFUJmSkR.js";const t=67108864,n=/^https:\/\/codeload\.github\.com\/camunda\/connectors\/tar\.gz\/refs\/tags\/[A-Za-z0-9_-][A-Za-z0-9._-]{0,127}$/,r=/^[A-Za-z0-9_-][A-Za-z0-9._-]{0,127}$/,i=/^[A-Za-z0-9._-]+$/,a=/^(\d+)\.(\d+)\.(\d+)$/,o=/^[A-Za-z0-9_-][A-Za-z0-9._-]{0,127}$/,s=/^[^/]+\/(connectors\/(?:[^/]+\/)+element-templates\/(?:[^/]+\/)*[^/]+\.json)$/,c=/* @__PURE__ */ new Set([`src`,`test`,`tests`,`test-resources`,`testdata`,`fixtures`]),l=/^data:image\/(?:png|jpe?g|gif|webp|svg\+xml|x-icon|vnd\.microsoft\.icon)[;,]/i,u=/^\.tmp-(.+)-(\d{13})-[a-z0-9]+$/,d=36e5,f=24*d,p=`.index.json`,m=`.state.json`,h=new TextDecoder,g=new TextEncoder;function _(e){return e===`https://api.github.com/repos/camunda/connectors/releases?per_page=100`||n.test(e)}function v(e){if(!r.test(e))throw Error(`Not a release tag: ${e}`);return`https://codeload.github.com/camunda/connectors/tar.gz/refs/tags/${e}`}function y(e){if(!Array.isArray(e))throw Error(`GitHub did not return a list of releases`);let t=null;for(let n of e){if(!n||typeof n!=`object`)continue;let{tag_name:e,draft:r,prerelease:o}=n;if(r!==!1||o!==!1||typeof e!=`string`||!i.test(e))continue;let s=a.exec(e);if(!s)continue;let c=s.slice(1).map(Number);(!t||b(c,t.parts)>0)&&(t={tag:e,parts:c})}if(!t)throw Error(`GitHub lists no final camunda/connectors release`);return t.tag}function b(e,t){for(let n=0;n<Math.max(e.length,t.length);n++){let r=(e[n]??0)-(t[n]??0);if(r!==0)return r}return 0}function x(e){let t=s.exec(e);if(!t)return null;let n=t[1];return n.split(`/`).some(e=>!o.test(e)||c.has(e.toLowerCase()))?null:n}function S(e,t){if(!e)return null;let n=Date.parse(e);return Number.isNaN(n)||n>t+6e4?null:n}function C(e){return e<=1?d:f}function w(e,t){let n=S(e.checkedAt,t),r=S(e.failedAt,t);return r!==null&&e.failures>0&&(n===null||r>=n)?t-r>=C(e.failures):n===null||t-n>=f}function T(e,t){let n=S(e.failedAt,t);return n===null||e.failures===0?null:new Date(n+C(e.failures)).toISOString()}const E={ref:null,previousRef:null,checkedAt:null,failedAt:null,failures:0,lastError:null};function D(e){return typeof e==`string`?e:null}function O(e){return typeof e==`string`&&r.test(e)?e:null}async function ee(e){try{let t=(await e.file(`read`,m)).content;if(!t)return{...E};let n=JSON.parse(h.decode(t));return{ref:O(n.ref),previousRef:O(n.previousRef),checkedAt:D(n.checkedAt),failedAt:D(n.failedAt),failures:typeof n.failures==`number`&&Number.isInteger(n.failures)&&n.failures>0?n.failures:0,lastError:D(n.lastError)}}catch{return{...E}}}async function k(e,t){await e.file(`write`,m,g.encode(JSON.stringify(t,null,2)))}function A(e){if(!e||typeof e!=`object`||Array.isArray(e))return!1;let t=e;return!(typeof t.id!=`string`||!t.id||t.id.length>256||typeof t.name!=`string`||!t.name||t.version!==void 0&&!(Number.isInteger(t.version)&&t.version>=0)||t.appliesTo!==void 0&&!(Array.isArray(t.appliesTo)&&t.appliesTo.every(e=>typeof e==`string`)))}function j(e){try{let t=JSON.parse(h.decode(e));return(Array.isArray(t)?t:[t]).filter(A)}catch{return[]}}function M(e){return(typeof e.elementType==`string`?e.elementType:e.elementType?.value)||(e.appliesTo??[]).join(`|`)}function N(e,t,n){return`${e}@${t??`_`}#${n}`}function P(e){return Array.isArray(e)?e.filter(e=>typeof e==`string`):[]}function F(e,t,n){let r=e.version??null,i=typeof e.elementType?.value==`string`?e.elementType.value:null,a={},o=e.engines,s=typeof o==`object`&&o&&!Array.isArray(o)?o:{};for(let[e,t]of Object.entries(s))typeof t==`string`&&(a[e]=t);let c=e.icon?.contents,u=e.documentationRef;return{key:N(e.id,r,M(e)),ref:n,path:t,id:e.id,version:r,name:e.name,description:typeof e.description==`string`?e.description:null,appliesTo:P(e.appliesTo),elementType:i,engines:a,category:typeof e.category?.name==`string`?e.category.name:null,keywords:[.../* @__PURE__ */ new Set([...P(e.keywords),...P(e.metadata?.keywords)])],icon:typeof c==`string`&&c.length<=262144&&l.test(c)?c:null,documentationRef:typeof u==`string`&&u.startsWith(`https://`)?u:null,deprecated:e.deprecated!==void 0&&e.deprecated!==!1,deprecatedMessage:typeof e.deprecated==`object`&&e.deprecated!==null&&typeof e.deprecated.message==`string`?e.deprecated.message:null}}function te(e){if(!e||typeof e!=`object`)return!1;let t=e;return typeof t.key==`string`&&typeof t.id==`string`&&typeof t.name==`string`&&typeof t.path==`string`&&x(`x/${t.path}`)===t.path&&Array.isArray(t.appliesTo)&&Array.isArray(t.keywords)}async function I(e,t){if(!r.test(t))return null;try{let n=(await e.file(`read`,`${t}/${p}`)).content;if(!n)return null;let r=JSON.parse(h.decode(n));if(r.format!==2||r.ref!==t||!Array.isArray(r.templates))return null;let i=r.templates.filter(te).map(e=>({...e,ref:t}));return i.length>0?i:null}catch{return null}}function L(e){let t=/* @__PURE__ */ new Map;for(let n of e){let e=`${n.id}#${M(n)}`,r=t.get(e);(!r||(r.version??-1)<(n.version??-1))&&t.set(e,n)}return[...t.values()].sort((e,t)=>e.name.localeCompare(t.name)||(e.elementType??``).localeCompare(t.elementType??``))}function R(e,t,n){return{ref:e,checkedAt:n,templates:t,newest:L(t)}}let z=/* @__PURE__ */ new WeakMap,B=/* @__PURE__ */ new WeakMap;async function V(e,t){if(!t.ref)return null;let n=z.get(e);if(n&&n.ref===t.ref)return n;let r=await I(e,t.ref);if(!r)return null;let i=R(t.ref,r,t.checkedAt);return z.set(e,i),i}function H(e){return e instanceof Error?e.message:String(e)}async function U(t,n){let r=await t.fetch(n);if(r.failure)throw Error(r.failure);if(r.status===403||r.status===429)throw Error(e(`app.connectors.githubRefused`,{status:r.status}));if(r.status!==200)throw Error(e(`app.connectors.githubAnswered`,{status:r.status}));if(r.body.byteLength>67108864)throw Error(e(`app.connectors.responseTooLarge`));return r.body}async function*W(t,n){let r=new ReadableStream({start(e){e.enqueue(t),e.close()}}).pipeThrough(new DecompressionStream(`gzip`)).getReader(),i=0;try{for(;;){let t;try{t=await r.read()}catch{throw Error(e(`app.connectors.archiveDamaged`))}if(t.done)return;if(i+=t.value.byteLength,i>n)throw Error(e(`app.connectors.archiveTooLarge`));yield t.value}}finally{await r.cancel().catch(()=>void 0)}}var G=class{chunks=[];offset=0;length=0;push(e){e.byteLength!==0&&(this.chunks.push(e),this.length+=e.byteLength)}take(e){let t=new Uint8Array(e),n=0;for(;n<e;){let r=this.chunks[0],i=r.byteLength-this.offset,a=Math.min(i,e-n);t.set(r.subarray(this.offset,this.offset+a),n),n+=a,this.consume(a,i)}return t}drop(e){let t=0;for(;t<e&&this.chunks.length>0;){let n=this.chunks[0].byteLength-this.offset,r=Math.min(n,e-t);t+=r,this.consume(r,n)}return t}consume(e,t){this.length-=e,e===t?(this.chunks.shift(),this.offset=0):this.offset+=e}};function K(e,t,n){let r=e.subarray(t,t+n),i=r.indexOf(0);return h.decode(i<0?r:r.subarray(0,i))}function q(e,t,n){let r=K(e,t,n).trim();return/^[0-7]+$/.test(r)?parseInt(r,8):NaN}function J(e){let t=0;for(let n=0;n<512;n++)t+=n>=148&&n<156?32:e[n];return q(e,148,8)===t}function Y(e){let t=null;for(let n of h.decode(e).split(`
2
+ `)){let e=/^\d+ path=(.*)$/.exec(n);e&&(t=e[1])}return t}async function*X(t,n){let r=t[Symbol.asyncIterator](),i=new G,a=()=>Error(e(`app.connectors.archiveDamaged`)),o=async e=>{for(;i.length<e;){let e=await r.next();if(e.done)return!1;i.push(e.value)}return!0},s=async e=>{let t=e;for(;t>0;){if(i.length===0&&!await o(1))throw a();t-=i.drop(t)}},c=async e=>{if(!await o(e))throw a();return i.take(e)},l=null;try{for(;;){if(!await o(512))throw a();let e=i.take(512);if(e.every(e=>e===0))return;if(!J(e))throw a();let t=q(e,124,12);if(!Number.isSafeInteger(t))throw a();let r=Math.ceil(t/512)*512,u=String.fromCharCode(e[156]);if(u===`x`||u===`L`){if(t>1048576)throw a();let e=await c(t);l=u===`x`?Y(e)??l:h.decode(e).replace(/\0.*$/s,``),await s(r-t);continue}if(u===`g`){await s(r);continue}let d=K(e,345,155),f=K(e,0,100),p=l??(d?`${d}/${f}`:f);if(l=null,(u===`0`||u===`\0`||u===`7`)&&t<=8388608&&n(p)){let e=await c(t);await s(r-t),yield{path:p,data:e}}else await s(r)}}finally{await r.return?.(void 0)}}async function Z(e,t){return(await e.file(`exists`,t)).pathExists===!0}async function ne(e,t,n){try{await e.file(`rename`,t,void 0,n);return}catch(r){if(await I(e,n)){await e.file(`delete`,t).catch(()=>void 0);return}if(!await Z(e,n))throw r}await e.file(`delete`,n),await e.file(`rename`,t,void 0,n)}async function re(t,n,r){let i=await U(t,v(n)),a=`.tmp-${n}-${r()}-${Math.random().toString(36).slice(2,10)||`x`}`;await t.file(`mkdirs`,a);try{let r=/* @__PURE__ */ new Map,o=X(W(i,536870912),e=>x(e)!==null);for await(let e of o){let i=x(e.path),o=j(e.data);if(i&&o.length!==0){await t.file(`write`,`${a}/${i}`,e.data);for(let e of o){let t=F(e,i,n);r.has(t.key)||r.set(t.key,t)}}}if(r.size===0)throw Error(e(`app.connectors.archiveHasNoTemplates`));let s=[...r.values()],c={format:2,ref:n,templates:s.map(e=>({...e,ref:void 0}))};return await t.file(`write`,`${a}/${p}`,g.encode(JSON.stringify(c))),await ne(t,a,n),s}catch(e){throw await t.file(`delete`,a).catch(()=>void 0),e}}async function ie(e,t,n){let i=(await e.file(`list`,``)).entries??[];for(let a of i){let i=u.exec(a);(a.startsWith(`.tmp-`)?!i||n-Number(i[2])>d:!a.startsWith(`.`)&&r.test(a)&&a!==t.ref&&a!==t.previousRef)&&await e.file(`delete`,a).catch(()=>void 0)}}async function ae(e,t,n){let r=await U(e,`https://api.github.com/repos/camunda/connectors/releases?per_page=100`),i;try{i=JSON.parse(h.decode(r))}catch{throw Error(`GitHub returned something that is not JSON`)}let a=y(i),o=await I(e,a)??await re(e,a,n),s=t.previousRef===a?null:t.previousRef;t.ref&&t.ref!==a&&(s=t.ref);let c={ref:a,previousRef:s,checkedAt:new Date(n()).toISOString(),failedAt:null,failures:0,lastError:null};await k(e,c),await ie(e,c,n()).catch(()=>void 0);let l=R(a,o,c.checkedAt);return z.set(e,l),l}async function oe(t,n,r){let i=await ee(t);if(!n&&!w(i,r())){let n=await V(t,i);if(n)return{catalog:n,error:null,nextAttempt:null};if(i.failures>0)return{catalog:null,error:i.lastError??e(`app.connectors.couldNotBeDownloaded`),nextAttempt:T(i,r())}}try{return{catalog:await ae(t,i,r),error:null,nextAttempt:null}}catch(e){let n={...i,failedAt:new Date(r()).toISOString(),failures:i.failures+1,lastError:H(e)};return await k(t,n).catch(()=>void 0),{catalog:await V(t,i).catch(()=>null),error:n.lastError,nextAttempt:T(n,r())}}}function se(e,t={}){let n=B.get(e);if(n)return n;let r=oe(e,t.forceRefresh===!0,t.now??Date.now).finally(()=>{B.get(e)===r&&B.delete(e)});return B.set(e,r),r}function Q(e,t){return e.length===0?null:t?e.find(e=>e.elementType===t)??e.find(e=>e.appliesTo.includes(t))??e[0]:e[0]}function ce(e,t,n,r){return Q(e.templates.filter(e=>e.id===t&&e.version===n),r)}function le(e,t,n){return Q(e.newest.filter(e=>e.id===t),n)}async function $(e,t){if(!r.test(t.ref)||x(`x/${t.path}`)!==t.path)return null;let n=(await e.file(`read`,`${t.ref}/${t.path}`)).content;return n?j(n).find(e=>N(e.id,e.version??null,M(e))===t.key)??null:null}export{le as a,$ as i,se as n,ce as o,_ as r,t};
@@ -0,0 +1 @@
1
+ import{s as e}from"./chunk-load-BVJUBU5S.js";import t from"node:path";import{existsSync as n,realpathSync as r}from"node:fs";const i=/* @__PURE__ */ new Map;function a(n){let r=t.resolve(n),a=i.get(r);if(a)return a;let o=e(r);return i.set(r,o),o}function o(e){let i=n(e)?r(e):e,a=t.relative(r(process.cwd()),i);return a&&!a.startsWith(`..`)?a:e}function s(e){return e&&typeof e==`object`&&!Array.isArray(e)?e:{}}function c(e){return typeof e==`string`&&e.trim()?e.trim():void 0}function l(e,t,n){let r=/* @__PURE__ */ new Map;for(let i of e){let e=t(i),a=r.get(e)??{key:n(i),files:[]};a.files.push(i),r.set(e,a)}return r}export{c as a,s as i,l as n,o as r,a as t};