@myagentroam/node 0.9.62 → 0.9.65

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 (161) hide show
  1. package/LICENSE +202 -0
  2. package/NOTICE +4 -0
  3. package/dist/capabilities.js +110 -2
  4. package/dist/claude-agent-sdk.js +330 -2
  5. package/dist/claude-channel.js +44 -2
  6. package/dist/codex-app-server.js +510 -2
  7. package/dist/config.js +106 -2
  8. package/dist/connector/node-connector-options.js +1 -2
  9. package/dist/connector/node-operation-router.js +22 -2
  10. package/dist/connector.js +1736 -2
  11. package/dist/control-outbound-scheduler.js +153 -2
  12. package/dist/database.js +639 -2
  13. package/dist/fake-runner.js +129 -2
  14. package/dist/git-askpass.js +12 -0
  15. package/dist/git-execution-helper.js +266 -0
  16. package/dist/health.js +3 -2
  17. package/dist/main.js +57 -2
  18. package/dist/mcp-installation-model.js +1 -2
  19. package/dist/migrations/v004.js +55 -3
  20. package/dist/migrations/v005.js +13 -3
  21. package/dist/migrations/v006.js +90 -3
  22. package/dist/migrations/v007.js +22 -3
  23. package/dist/migrations/v008.js +18 -3
  24. package/dist/migrations/v009.js +70 -4
  25. package/dist/migrations/v010.js +43 -3
  26. package/dist/migrations/v011.js +20 -3
  27. package/dist/migrations/v012.js +8 -0
  28. package/dist/native-jsonl-reader.js +186 -2
  29. package/dist/native-session-history.js +1143 -2
  30. package/dist/opencode-runtime.js +80 -2
  31. package/dist/opencode-server.js +259 -2
  32. package/dist/operational.js +122 -2
  33. package/dist/process-tree.js +18 -2
  34. package/dist/ripgrep-binary.js +31 -2
  35. package/dist/rotating-log.js +67 -2
  36. package/dist/runner/abstract-runner.js +260 -2
  37. package/dist/runner/claude/managed-run-controller.js +355 -2
  38. package/dist/runner/claude/tool-normalizer.js +120 -2
  39. package/dist/runner/claude-code-runner.js +303 -2
  40. package/dist/runner/codex/composer-image-markers.js +8 -2
  41. package/dist/runner/codex/conversation-parser.js +913 -2
  42. package/dist/runner/codex/managed-run-controller.js +494 -2
  43. package/dist/runner/codex/tool-normalizer.js +214 -2
  44. package/dist/runner/codex-runner.js +585 -2
  45. package/dist/runner/fake-test-runner.js +47 -2
  46. package/dist/runner/mar-agent/conversation-normalizer.js +644 -2
  47. package/dist/runner/mar-agent/executor-stdio-client-transport.js +139 -2
  48. package/dist/runner/mar-agent/generated-images.js +41 -2
  49. package/dist/runner/mar-agent/history-projection.js +106 -2
  50. package/dist/runner/mar-agent/hosted-conversation-runtime.js +446 -2
  51. package/dist/runner/mar-agent/managed-run-controller.js +785 -2
  52. package/dist/runner/mar-agent/mcp-client-pool.js +233 -2
  53. package/dist/runner/mar-agent/runtime-model-factory.js +326 -2
  54. package/dist/runner/mar-agent-runner.js +458 -2
  55. package/dist/runner/opencode/conversation-parser.js +221 -2
  56. package/dist/runner/opencode/managed-run-controller.js +588 -2
  57. package/dist/runner/opencode/tool-normalizer.js +80 -2
  58. package/dist/runner/opencode-runner.js +426 -2
  59. package/dist/runner/runner-registry.js +87 -2
  60. package/dist/runner-command-engine.js +71 -2
  61. package/dist/runner-profiles.js +323 -2
  62. package/dist/runner-usage.js +190 -2
  63. package/dist/runtime-command-detector.js +73 -2
  64. package/dist/runtime-model.js +1 -2
  65. package/dist/runtime-state.js +1509 -2
  66. package/dist/service/attachment-domain-state.js +7 -2
  67. package/dist/service/bubblewrap-sandbox-executor.js +543 -2
  68. package/dist/service/continuous-run-coordinator.js +425 -2
  69. package/dist/service/conversation-history-service.js +552 -2
  70. package/dist/service/conversation-hosting-capability-service.js +61 -2
  71. package/dist/service/conversation-hosting-enablement-service.js +91 -2
  72. package/dist/service/conversation-hosting-maintenance-service.js +174 -2
  73. package/dist/service/conversation-segment-service.js +162 -2
  74. package/dist/service/conversation-template-node-service.js +992 -2
  75. package/dist/service/external-session-resume-service.js +152 -2
  76. package/dist/service/fake-managed-run-service.js +60 -2
  77. package/dist/service/git-execution-service.js +418 -0
  78. package/dist/service/git-operation-service.js +57 -0
  79. package/dist/service/hosted-conversation-node-service.js +1982 -2
  80. package/dist/service/hosted-conversation-store.js +1405 -2
  81. package/dist/service/managed-runner-session-service.js +35 -2
  82. package/dist/service/mar-agent-model-transport-test-service.js +88 -2
  83. package/dist/service/mcp-installation-verifier.js +87 -2
  84. package/dist/service/mcp-node-operation-service.js +90 -2
  85. package/dist/service/mission-mcp-server.js +124 -2
  86. package/dist/service/mission-mcp-stdio.js +40 -2
  87. package/dist/service/mission-runtime.js +142 -2
  88. package/dist/service/native-session-projection-service.js +274 -2
  89. package/dist/service/native-session-watch-service.js +683 -2
  90. package/dist/service/node-connection-lifecycle-service.js +88 -2
  91. package/dist/service/node-control-channel.js +85 -2
  92. package/dist/service/node-control-message-service.js +109 -2
  93. package/dist/service/node-request-service.js +62 -2
  94. package/dist/service/node-run-event-bridge.js +88 -2
  95. package/dist/service/node-terminal-channel.js +202 -2
  96. package/dist/service/node-upgrade-coordinator.js +137 -2
  97. package/dist/service/node-workspace-coordinator.js +97 -2
  98. package/dist/service/recent-run-projection-service.js +99 -2
  99. package/dist/service/run-attachment-service.js +321 -2
  100. package/dist/service/run-domain-state.js +4 -2
  101. package/dist/service/run-event-service.js +246 -2
  102. package/dist/service/run-ownership-policy.js +22 -2
  103. package/dist/service/run-workbench-service.js +120 -2
  104. package/dist/service/runner-channel-message-service.js +20 -2
  105. package/dist/service/runner-interaction-service.js +243 -2
  106. package/dist/service/runner-service.js +69 -2
  107. package/dist/service/runtime-credential-control-service.js +95 -2
  108. package/dist/service/session-catalog-service.js +404 -2
  109. package/dist/service/session-command-service.js +125 -2
  110. package/dist/service/session-context-service.js +128 -2
  111. package/dist/service/session-domain-state.js +9 -2
  112. package/dist/service/session-identity-service.js +86 -2
  113. package/dist/service/session-lifecycle-service.js +248 -2
  114. package/dist/service/session-message-service.js +270 -2
  115. package/dist/service/session-presentation-service.js +43 -2
  116. package/dist/service/session-query-service.js +82 -2
  117. package/dist/service/session-watch-slot-coordinator.js +21 -2
  118. package/dist/service/skill-directory-service.js +238 -2
  119. package/dist/service/skill-install-service.js +434 -2
  120. package/dist/service/skill-node-operation-service.js +206 -2
  121. package/dist/service/terminal-relay-state.js +3 -2
  122. package/dist/service/terminal-service.js +90 -2
  123. package/dist/service/web-search-error.js +40 -2
  124. package/dist/service/workbench-event-service.js +21 -2
  125. package/dist/service/workbench-manifest-service.js +69 -2
  126. package/dist/service/workspace-change-service.js +290 -2
  127. package/dist/service/workspace-content-search-service.js +457 -2
  128. package/dist/service/workspace-domain-state.js +41 -2
  129. package/dist/service/workspace-file-service.js +150 -2
  130. package/dist/service/workspace-git-exclude-service.js +119 -2
  131. package/dist/service/workspace-queue-workbench-service.js +176 -2
  132. package/dist/service/workspace-service.js +92 -2
  133. package/dist/service/workspace-session-service.js +154 -2
  134. package/dist/service/workspace-upload-service.js +262 -2
  135. package/dist/service/workspace-watch-controller.js +68 -2
  136. package/dist/service/workspace-watch-service.js +170 -2
  137. package/dist/service/workspace-watch-snapshot-service.js +218 -2
  138. package/dist/service/workspace-workbench-service.js +239 -2
  139. package/dist/service.js +91 -2
  140. package/dist/storage.js +32 -2
  141. package/dist/supervisor.js +136 -2
  142. package/dist/terminal.js +496 -2
  143. package/dist/util/git-credential-client.js +32 -0
  144. package/dist/util/node-operation-data.js +9 -2
  145. package/dist/util/node-operation-parsers.js +382 -2
  146. package/dist/util/personal-instructions.js +34 -2
  147. package/dist/util/runner-error.js +70 -2
  148. package/dist/util/runner-native-session-parsers.js +510 -2
  149. package/dist/util/safe-error.js +8 -2
  150. package/dist/util/secret-environment.js +25 -2
  151. package/dist/workspace.js +1793 -2
  152. package/package.json +11 -8
  153. package/vendor/ripgrep/darwin-arm64/rg +0 -0
  154. package/vendor/ripgrep/darwin-x64/rg +0 -0
  155. package/vendor/ripgrep/manifest.json +12 -0
  156. package/README.md +0 -42
  157. package/dist/event-buffer.js +0 -2
  158. package/dist/migrations/v001.js +0 -107
  159. package/dist/migrations/v002.js +0 -2
  160. package/dist/migrations/v003.js +0 -2
  161. package/dist/service/mcp-package-installer.js +0 -2
package/dist/workspace.js CHANGED
@@ -1,2 +1,1793 @@
1
- /* mar-release-protected */
2
- const _0x5af3e3=_0xd6ca;(function(_0x11fe99,_0x34ca8a){const _0x4b3518=_0xd6ca,_0x5a1d10=_0x11fe99();while(!![]){try{const _0x38eb22=parseInt(_0x4b3518(0x213))/(0x2*0x12f8+0x5*0x73d+0x2510*-0x2)+parseInt(_0x4b3518(0x19a))/(0x1a95*-0x1+0x1858+-0x23f*-0x1)*(-parseInt(_0x4b3518(0x20c))/(0x111b+0xa*-0x2bf+0x52f*0x2))+-parseInt(_0x4b3518(0x27a))/(0x1*-0x6c9+0x12b5+-0xbe8)+parseInt(_0x4b3518(0x1f9))/(0x371*-0x1+0x2*-0x259+0x828)+-parseInt(_0x4b3518(0x24b))/(-0x13*0x97+-0x26a8+0x31e3)+-parseInt(_0x4b3518(0x260))/(0x29*-0x41+-0x21d8+0x2c48)*(parseInt(_0x4b3518(0x21a))/(-0x1b6c+0xb51*0x1+0x1023))+parseInt(_0x4b3518(0x2a2))/(0x16d5+-0x1879+0x3*0x8f);if(_0x38eb22===_0x34ca8a)break;else _0x5a1d10['push'](_0x5a1d10['shift']());}catch(_0x2d17ee){_0x5a1d10['push'](_0x5a1d10['shift']());}}}(_0x585a,0x275ec+-0xdd5f*-0x15+-0x6ac6b));import{createHash,randomUUID}from'node:crypto';import{lstat,mkdir,opendir,open,readdir,readFile,realpath,rename,rm,stat,unlink,writeFile}from'node:fs/promises';import{homedir,platform as _0x315274}from'node:os';import{basename,dirname,isAbsolute,posix,relative,resolve,sep,win32}from'node:path';import{spawn}from'node:child_process';import{minimatch}from'minimatch';import{terminateProcessTree}from'./process-tree.js';const GIT_TIMEOUT_MS=-0x89f*-0x2+-0x21e*0x5+-0xce0*-0x1,GIT_STATUS_TIMEOUT_MS=0x8452+-0xe68e+-0x4*-0x35db,GIT_HISTORY_TIMEOUT_MS=0x4cb*0x6+-0x145f*0x5+0x1*0x83b1,GIT_OUTPUT_LIMIT=(0x1bdf+-0x1c*0x53+-0x10cb)*(-0x20d+0x580+0x1*0x8d),GIT_LARGE_OUTPUT_LIMIT=(-0x845*0x3+-0x24aa*-0x1+-0xbd3)*(-0x1057+0x53f+-0x18*-0xa1)*(-0x264f+0x209+0x2*0x1423),FILE_READ_LIMIT=(0x1fda+-0x14*-0x9d+-0x2a1e)*(-0x2*-0xc7+0x65*-0x37+0x1825),DIRECTORY_PAGE_LIMIT=0xfb8+-0x5f*0xf+-0x95f*0x1,DIRECTORY_PICKER_LIMIT=-0x2f*-0xa9+-0x25cd+0x78e,SEARCH_RESULT_LIMIT=-0x67+-0x12*-0x49+0x3f3*-0x1,GIT_WORKTREE_LIST_LIMIT=0xdcb+0x21c2+-0x2f0d,FILE_INDEX_IDLE_TTL_MS=(0x1*0x9b5+0x23f5+-0x2d6e*0x1)*(-0x202d+-0x2d4*-0x8+0x9c9*0x1)*(-0x1*0x79d+-0x1d50*0x1+0x28d5),FILE_INDEX_FRESHNESS_TTL_MS=-0xd531+-0x23*0x25+0x14f70,FILE_INDEX_ENTRY_LIMIT=0x53*0x2f+-0x3*-0x98ec+0x58f*-0xf,FILE_INDEX_METADATA_CONCURRENCY=-0x945*0x3+-0x1*-0x104b+0xba4,DEFAULT_QUICK_OPEN_EXCLUDES=[_0x5af3e3(0x1b6),_0x5af3e3(0x25f),_0x5af3e3(0x23e),_0x5af3e3(0x28f),_0x5af3e3(0x2b7),_0x5af3e3(0x27b),_0x5af3e3(0x194),_0x5af3e3(0x229),_0x5af3e3(0x25a),_0x5af3e3(0x277),_0x5af3e3(0x22a),_0x5af3e3(0x1db),_0x5af3e3(0x25c),_0x5af3e3(0x287),_0x5af3e3(0x19d),_0x5af3e3(0x224),_0x5af3e3(0x21d),_0x5af3e3(0x238),_0x5af3e3(0x1ae),_0x5af3e3(0x203),_0x5af3e3(0x1aa),_0x5af3e3(0x19f),_0x5af3e3(0x243),_0x5af3e3(0x2ac),_0x5af3e3(0x1c0)],REF_PATTERN=/^(?!-)(?!.*\.\.)(?!.*@\{)[A-Za-z0-9][A-Za-z0-9._/-]{0,254}$/;export async function createWorkspaceDirectory(_0x2422fd,_0x530c13,_0x82e710){const _0x4819d1=_0x5af3e3,_0x3ec3a5=_0x530c13[_0x4819d1(0x28d)]();if(_0x3ec3a5[_0x4819d1(0x1c9)]===0x1c4d+0x1*0x7e+-0x5b*0x51||_0x3ec3a5[_0x4819d1(0x1c9)]>-0x26ea+-0x17*-0xa9+0x18ba||_0x3ec3a5==='.'||_0x3ec3a5==='..'||_0x3ec3a5[_0x4819d1(0x201)]('/')||_0x3ec3a5[_0x4819d1(0x201)]('\x5c')||_0x3ec3a5[_0x4819d1(0x201)]('\x00'))throw new Error(_0x4819d1(0x283));const _0x57e833=await Promise[_0x4819d1(0x2b2)](_0x82e710[_0x4819d1(0x1cc)](_0x187cca=>realpath(_0x187cca))),_0x181099=await realpath(_0x2422fd)[_0x4819d1(0x263)](()=>{const _0x109e80=_0x4819d1;throw new Error(_0x109e80(0x299));}),_0x126702=await stat(_0x181099)[_0x4819d1(0x263)](()=>undefined);if(_0x126702?.[_0x4819d1(0x29d)]()!==!![]||!isWithinAllowedRoot(_0x181099,_0x57e833))throw new Error(_0x4819d1(0x299));const _0x1fe366=resolve(_0x181099,_0x3ec3a5);if(dirname(_0x1fe366)!==_0x181099||!isWithinAllowedRoot(_0x1fe366,_0x57e833))throw new Error(_0x4819d1(0x283));try{await mkdir(_0x1fe366);}catch(_0x19a99e){if(_0x19a99e[_0x4819d1(0x1e1)]===_0x4819d1(0x1ac))throw new Error(_0x4819d1(0x233));throw _0x19a99e;}return _0x1fe366;}export class WorkspaceFileIndex{[_0x5af3e3(0x252)];[_0x5af3e3(0x199)];[_0x5af3e3(0x1d2)]=[];[_0x5af3e3(0x1c2)]=![];[_0x5af3e3(0x26b)];[_0x5af3e3(0x1c3)];[_0x5af3e3(0x1bd)]=!![];[_0x5af3e3(0x19e)];[_0x5af3e3(0x2af)]=0x1a*0x169+-0x13*-0x1b1+0x13*-0x39f;[_0x5af3e3(0x1be)]=0xcbb+-0xa29+-0x292;constructor(_0x53adf7,_0x45b137={}){const _0x3dc349=_0x5af3e3;this[_0x3dc349(0x252)]=_0x53adf7,this[_0x3dc349(0x199)]=_0x45b137;}async[_0x5af3e3(0x293)](){const _0x14442f=_0x5af3e3;return await this[_0x14442f(0x1d1)](),this[_0x14442f(0x27f)](),{'entries':this[_0x14442f(0x1d2)][_0x14442f(0x2a4)](_0x49bf30=>_0x49bf30[_0x14442f(0x1b1)]===_0x14442f(0x285)),'truncated':this[_0x14442f(0x1c2)]};}[_0x5af3e3(0x242)](){const _0x42ce99=_0x5af3e3;if(this[_0x42ce99(0x19e)]!==undefined)clearTimeout(this[_0x42ce99(0x19e)]);this[_0x42ce99(0x19e)]=undefined,this[_0x42ce99(0x1d2)]=[],this[_0x42ce99(0x1c2)]=![],this[_0x42ce99(0x1bd)]=!![],this[_0x42ce99(0x2af)]=0x1c47+0x1*-0x33+0x1*-0x1c14,this[_0x42ce99(0x1be)]=0x8*0x4cf+-0x5*0x1a1+0x1*-0x1e53;}async[_0x5af3e3(0x291)](_0x51f73e,_0x4300a9,_0x6fc7b=SEARCH_RESULT_LIMIT,_0x42a345=![]){const _0xa71be=_0x5af3e3;if(_0x51f73e[_0xa71be(0x28d)]()[_0xa71be(0x1c9)]===-0x4*-0x6d7+-0x1d8e+0x232||_0x51f73e[_0xa71be(0x1c9)]>-0x4bd*-0x5+-0x192d+0x27c||!Number[_0xa71be(0x20b)](_0x6fc7b)||_0x6fc7b<-0x1b*-0xf7+0x15b4+-0x5f8*0x8||_0x6fc7b>SEARCH_RESULT_LIMIT)throw new Error(_0xa71be(0x2ab));await this[_0xa71be(0x1d1)](),this[_0xa71be(0x27f)]();const _0x4ab745=decodeSearchCursor(_0x4300a9,_0x51f73e),_0x117b38=_0x4ab745===undefined?undefined:this[_0xa71be(0x1d2)][_0xa71be(0x1d4)](_0x46c1f2=>_0x46c1f2[_0xa71be(0x266)]===_0x4ab745&&(_0x42a345||_0x46c1f2[_0xa71be(0x1b1)]===_0xa71be(0x285))),_0x238cec=_0x117b38===undefined?-(0x18+-0x12e6+0xf*0x141):fuzzyPathScore(_0x117b38[_0xa71be(0x266)],_0x51f73e),_0x10981=_0x117b38===undefined||_0x238cec<0x1a0c+-0x484+0x2b1*-0x8?undefined:{'entry':_0x117b38,'score':_0x238cec},_0x50f27a=new RankedCandidateHeap(_0x6fc7b+(-0x5e8+0x18db+-0x12f2));for(const _0x6da541 of this[_0xa71be(0x1d2)]){if(!_0x42a345&&_0x6da541[_0xa71be(0x1b1)]!==_0xa71be(0x285))continue;const _0x512d5c=fuzzyPathScore(_0x6da541[_0xa71be(0x266)],_0x51f73e);if(_0x512d5c<0x531+-0x1*0x15b9+-0x844*-0x2)continue;const _0x577942={'entry':_0x6da541,'score':_0x512d5c};if(_0x10981!==undefined&&compareRankedCandidate(_0x577942,_0x10981)<=-0x6b*0xb+0xd3f+-0x8a6)continue;_0x50f27a[_0xa71be(0x1a8)](_0x577942);}const _0x5c1b54=_0x50f27a[_0xa71be(0x2b9)](),_0x6e79ae=_0x5c1b54[_0xa71be(0x288)](-0xcf9+-0x617+0x3d0*0x5,_0x6fc7b)[_0xa71be(0x1cc)](_0x46c5c4=>_0x46c5c4[_0xa71be(0x1d7)]),_0x627c8f=_0x5c1b54[_0x6fc7b]?.[_0xa71be(0x1d7)][_0xa71be(0x266)];return{'entries':_0x6e79ae,'nextCursor':_0x627c8f===undefined?null:encodeSearchCursor(_0x51f73e,_0x6e79ae['at'](-(0x8*-0xca+0xe*0x136+0xaa3*-0x1))?.[_0xa71be(0x266)]??_0x4ab745??''),'truncated':_0x627c8f!==undefined||this[_0xa71be(0x1c2)]};}async[_0x5af3e3(0x1d1)](){const _0x3f2b9a=_0x5af3e3;if(!this[_0x3f2b9a(0x1bd)]&&this[_0x3f2b9a(0x26b)]!==undefined){if(Date[_0x3f2b9a(0x1d0)]()-this[_0x3f2b9a(0x1be)]>=(this[_0x3f2b9a(0x199)][_0x3f2b9a(0x268)]??FILE_INDEX_FRESHNESS_TTL_MS))this[_0x3f2b9a(0x1d3)]();return;}this[_0x3f2b9a(0x1c3)]===undefined&&(this[_0x3f2b9a(0x1c3)]=this[_0x3f2b9a(0x1c7)]()[_0x3f2b9a(0x19b)](()=>{const _0x24c1c8=_0x3f2b9a;this[_0x24c1c8(0x1c3)]=undefined;})),await this[_0x3f2b9a(0x1c3)];}[_0x5af3e3(0x27f)](){const _0x54b949=_0x5af3e3;if(this[_0x54b949(0x19e)]!==undefined)clearTimeout(this[_0x54b949(0x19e)]);this[_0x54b949(0x19e)]=setTimeout(()=>this[_0x54b949(0x242)](),this[_0x54b949(0x199)][_0x54b949(0x187)]??FILE_INDEX_IDLE_TTL_MS),this[_0x54b949(0x19e)][_0x54b949(0x221)]();}async[_0x5af3e3(0x1c7)](){const _0x5c20e8=_0x5af3e3,_0x26e1ac=await resolveRegisteredWorkspaceRoot(this[_0x5c20e8(0x252)]),_0x4a8874=[...DEFAULT_QUICK_OPEN_EXCLUDES,...await workspaceExcludePatterns(_0x26e1ac)],_0xbe329e=[],_0x2e0949=this[_0x5c20e8(0x199)][_0x5c20e8(0x271)]??FILE_INDEX_ENTRY_LIMIT;let _0x42cb84=![];const _0x20ba4d=['.'];let _0x362023=0x7*0x155+0xf4e*0x2+-0x27ef;while(_0x362023<_0x20ba4d[_0x5c20e8(0x1c9)]&&!_0x42cb84){const _0x589a8e=_0x20ba4d[_0x362023];_0x362023+=-0x266d+-0x202f+0x469d;const _0x3295a6=await resolveWorkspaceEntryFromCanonicalRoot(_0x26e1ac,_0x589a8e,!![])[_0x5c20e8(0x263)](()=>undefined);if(_0x3295a6===undefined)continue;const _0x1d495a=await opendir(_0x3295a6)[_0x5c20e8(0x263)](()=>undefined);if(_0x1d495a===undefined)continue;let _0x371299=[];const _0x5e1951=async()=>{const _0x304edb=_0x5c20e8,_0x1ff681=await Promise[_0x304edb(0x2b2)](_0x371299);_0x371299=[];for(const _0x5d5a68 of _0x1ff681){if(_0x5d5a68===undefined)continue;if(_0x5d5a68[_0x304edb(0x266)]===_0x304edb(0x255)||_0x5d5a68[_0x304edb(0x266)][_0x304edb(0x1bf)](_0x304edb(0x1de))||isExcluded(_0x5d5a68[_0x304edb(0x266)],_0x4a8874))continue;if(_0x5d5a68[_0x304edb(0x1b1)]===_0x304edb(0x26a))_0x20ba4d[_0x304edb(0x1bb)](_0x5d5a68[_0x304edb(0x266)]);_0xbe329e[_0x304edb(0x1bb)](_0x5d5a68);if(_0xbe329e[_0x304edb(0x1c9)]>=_0x2e0949){_0x42cb84=!![];break;}}};for await(const _0x1158b9 of _0x1d495a){const _0x31190a=_0x589a8e==='.'?_0x1158b9[_0x5c20e8(0x28e)]:posix[_0x5c20e8(0x1a1)](_0x589a8e[_0x5c20e8(0x231)]('\x5c','/'),_0x1158b9[_0x5c20e8(0x28e)]);if(_0x31190a===_0x5c20e8(0x255)||_0x31190a[_0x5c20e8(0x1bf)](_0x5c20e8(0x1de))||isExcluded(_0x31190a,_0x4a8874))continue;_0x371299[_0x5c20e8(0x1bb)](inspectWorkspaceIndexEntry(_0x26e1ac,_0x31190a,_0x1158b9[_0x5c20e8(0x28e)]));if(_0x371299[_0x5c20e8(0x1c9)]>=FILE_INDEX_METADATA_CONCURRENCY)await _0x5e1951();if(_0x42cb84)break;}if(!_0x42cb84&&_0x371299[_0x5c20e8(0x1c9)]>0x96e+-0x11b7*-0x1+-0x1b25)await _0x5e1951();}this[_0x5c20e8(0x26b)]=_0x26e1ac,this[_0x5c20e8(0x1d2)]=_0xbe329e,this[_0x5c20e8(0x1c2)]=_0x42cb84,this[_0x5c20e8(0x1bd)]=![],this[_0x5c20e8(0x2af)]=Date[_0x5c20e8(0x1d0)](),this[_0x5c20e8(0x1be)]=this[_0x5c20e8(0x2af)];}[_0x5af3e3(0x1d3)](){const _0x4f6128=_0x5af3e3;if(this[_0x4f6128(0x1c3)]!==undefined)return;this[_0x4f6128(0x1be)]=Date[_0x4f6128(0x1d0)](),this[_0x4f6128(0x1c3)]=this[_0x4f6128(0x1c7)]()[_0x4f6128(0x263)](()=>undefined)[_0x4f6128(0x19b)](()=>{const _0x35c0a8=_0x4f6128;this[_0x35c0a8(0x1c3)]=undefined;});}}async function workspaceExcludePatterns(_0x10ac28){const _0x56580f=_0x5af3e3,_0xf9a0b6=resolve(_0x10ac28,_0x56580f(0x2b4)),_0x5b87f1=await readFile(_0xf9a0b6,_0x56580f(0x250))[_0x56580f(0x1f2)](JSON[_0x56580f(0x182)])[_0x56580f(0x263)](()=>undefined);if(typeof _0x5b87f1!==_0x56580f(0x196)||_0x5b87f1===null)return[];return[_0x56580f(0x1e9),_0x56580f(0x1cb)][_0x56580f(0x25b)](_0x4f9f50=>{const _0x434c04=_0x56580f,_0xd8ad9f=_0x5b87f1[_0x4f9f50];return typeof _0xd8ad9f===_0x434c04(0x196)&&_0xd8ad9f!==null?Object[_0x434c04(0x1d2)](_0xd8ad9f)[_0x434c04(0x25b)](([_0x3982d2,_0x464de7])=>_0x464de7===!![]?[_0x3982d2]:[]):[];});}function isExcluded(_0x337f2a,_0x24c90b){const _0x31d007=_0x5af3e3;return _0x24c90b[_0x31d007(0x1f1)](_0x4b7c29=>minimatch(_0x337f2a,_0x4b7c29,{'dot':!![],'nocase':_0x315274()!==_0x31d007(0x2b5)})||minimatch(_0x337f2a+'/',_0x4b7c29,{'dot':!![],'nocase':_0x315274()!==_0x31d007(0x2b5)}));}function compareRankedCandidate(_0x347073,_0x269a2d){const _0x34cc17=_0x5af3e3;return _0x269a2d[_0x34cc17(0x251)]-_0x347073[_0x34cc17(0x251)]||_0x347073[_0x34cc17(0x1d7)][_0x34cc17(0x266)][_0x34cc17(0x24d)](_0x269a2d[_0x34cc17(0x1d7)][_0x34cc17(0x266)]);}class RankedCandidateHeap{[_0x5af3e3(0x192)];[_0x5af3e3(0x1af)]=[];constructor(_0x2fcc7d){const _0x42e772=_0x5af3e3;this[_0x42e772(0x192)]=_0x2fcc7d;}[_0x5af3e3(0x1a8)](_0x1a562c){const _0xed1b26=_0x5af3e3;if(this[_0xed1b26(0x1af)][_0xed1b26(0x1c9)]<this[_0xed1b26(0x192)]){this[_0xed1b26(0x1af)][_0xed1b26(0x1bb)](_0x1a562c),this[_0xed1b26(0x296)](this[_0xed1b26(0x1af)][_0xed1b26(0x1c9)]-(0xae8+-0x19d3*0x1+-0x4*-0x3bb));return;}if(compareRankedCandidate(_0x1a562c,this[_0xed1b26(0x1af)][-0x1b5f+-0x939*-0x1+-0x1226*-0x1])>=-0x8e9*0x2+0x2299*0x1+-0x10c7)return;this[_0xed1b26(0x1af)][-0x2156+-0x27*0x1d+0x25c1]=_0x1a562c,this[_0xed1b26(0x1b7)](0x4dc*0x1+0xe66+0x1342*-0x1);}[_0x5af3e3(0x2b9)](){const _0x225955=_0x5af3e3;return[...this[_0x225955(0x1af)]][_0x225955(0x272)](compareRankedCandidate);}[_0x5af3e3(0x296)](_0x17eb98){const _0x597969=_0x5af3e3;let _0x3c1baa=_0x17eb98;while(_0x3c1baa>-0x816*-0x2+0x10f+-0x113b){const _0x2426ee=Math[_0x597969(0x222)]((_0x3c1baa-(0x1eb6+0x1d98+-0x3c4d))/(0x23*0xfb+0x79*0x31+-0x6*0x994));if(compareRankedCandidate(this[_0x597969(0x1af)][_0x3c1baa],this[_0x597969(0x1af)][_0x2426ee])<=0xee9+0x13ed+0xd*-0x2ae)break;[this[_0x597969(0x1af)][_0x3c1baa],this[_0x597969(0x1af)][_0x2426ee]]=[this[_0x597969(0x1af)][_0x2426ee],this[_0x597969(0x1af)][_0x3c1baa]],_0x3c1baa=_0x2426ee;}}[_0x5af3e3(0x1b7)](_0xb85fbc){const _0xf99ce9=_0x5af3e3;let _0x17a274=_0xb85fbc;while(!![]){const _0x31ec46=_0x17a274*(-0x1ac5+0x1*-0x889+0x2350)+(0x1ddb+-0x1*0x732+-0x16a8);if(_0x31ec46>=this[_0xf99ce9(0x1af)][_0xf99ce9(0x1c9)])return;const _0x3bd68b=_0x31ec46+(-0xcd+-0x1*0x55b+0x629),_0x336b01=_0x3bd68b<this[_0xf99ce9(0x1af)][_0xf99ce9(0x1c9)]&&compareRankedCandidate(this[_0xf99ce9(0x1af)][_0x3bd68b],this[_0xf99ce9(0x1af)][_0x31ec46])>-0x2*0x1046+0x25e8+-0x55c?_0x3bd68b:_0x31ec46;if(compareRankedCandidate(this[_0xf99ce9(0x1af)][_0x336b01],this[_0xf99ce9(0x1af)][_0x17a274])<=0x26e6+0x1cfd+0x43e3*-0x1)return;[this[_0xf99ce9(0x1af)][_0x17a274],this[_0xf99ce9(0x1af)][_0x336b01]]=[this[_0xf99ce9(0x1af)][_0x336b01],this[_0xf99ce9(0x1af)][_0x17a274]],_0x17a274=_0x336b01;}}}function fuzzyPathScore(_0x34aec6,_0x417b6a){const _0x5e5b1d=_0x5af3e3,_0x37fddb=_0x34aec6[_0x5e5b1d(0x2a3)](),_0x1f145e=_0x417b6a[_0x5e5b1d(0x28d)]()[_0x5e5b1d(0x2a3)]();let _0x1d1620=0x982*-0x1+0x98*-0x23+-0x1*-0x1e4a,_0x38a47f=-0x78b+-0xebf+0x76e*0x3,_0x3d02c7=-(-0x1*-0xd69+-0x1b*0x17+0x1*-0xafa);for(const _0x27a57f of _0x1f145e){const _0x3a42b9=_0x37fddb[_0x5e5b1d(0x215)](_0x27a57f,_0x1d1620);if(_0x3a42b9===-(0xb27*0x2+-0x1d2+-0x147b))return-(0xc33+-0x25a8+0x1976);_0x38a47f+=_0x3a42b9===_0x3d02c7+(0xfe7+-0x661*0x6+-0x2cc*-0x8)?-0xb1*-0x37+-0x4d*-0x45+-0x54*0xb3:-0xc1*0x1+0x19b2+0x26*-0xa8;if(_0x3a42b9===-0x1248+-0x1*0xaf6+-0x18a*-0x13||_0x5e5b1d(0x228)[_0x5e5b1d(0x201)](_0x37fddb[_0x3a42b9-(0xf8b*0x2+-0x19f*0xd+-0x15*0x7a)]??''))_0x38a47f+=0x14b6+-0x68*-0x52+0x1aff*-0x2;_0x3d02c7=_0x3a42b9,_0x1d1620=_0x3a42b9+(0xee+-0x6ce+0x5*0x12d);}const _0x2a1dc4=_0x34aec6[_0x5e5b1d(0x288)](_0x34aec6[_0x5e5b1d(0x1c5)]('/')+(-0x1*-0xdcd+-0x6b*0x5b+0x1*0x183d))[_0x5e5b1d(0x2a3)]();if(_0x2a1dc4[_0x5e5b1d(0x201)](_0x1f145e))_0x38a47f+=-0x2*0x83e+0x744*-0x2+0x1f2c;else{if(_0x37fddb[_0x5e5b1d(0x201)](_0x1f145e))_0x38a47f+=-0x3e*0x89+0x187*0x2+-0x30*-0xa1;}return _0x38a47f-_0x34aec6[_0x5e5b1d(0x1c9)]/(0x15*-0x169+-0x1*0x1b09+0x3c8e);}export async function listWorkspaceDirectories(_0x428c14,_0x114008,_0xb2c869=homedir()){const _0x136e61=_0x5af3e3,_0x13cda6=await realpath(_0xb2c869),_0x2e9f22=await Promise[_0x136e61(0x2b2)](_0x114008[_0x136e61(0x1cc)](_0x5011a2=>realpath(_0x5011a2))),_0x55e557=[...new Set([_0x13cda6,..._0x2e9f22])],_0x273838=_0x428c14===undefined?_0x2e9f22[-0x7*0x13d+0x11a3+-0x8f8]??_0x13cda6:await realpath(_0x428c14),_0x267944=await stat(_0x273838);if(!_0x267944[_0x136e61(0x29d)]()||!isWithinAllowedRoot(_0x273838,_0x55e557))throw new Error(_0x136e61(0x299));const _0xf9b4d1=await readdir(_0x273838,{'withFileTypes':!![]}),_0x13c1c4=[];for(const _0x1d1668 of _0xf9b4d1[_0x136e61(0x272)]((_0x472058,_0x1944be)=>_0x472058[_0x136e61(0x28e)][_0x136e61(0x24d)](_0x1944be[_0x136e61(0x28e)]))){if(!_0x1d1668[_0x136e61(0x29d)]()&&!_0x1d1668[_0x136e61(0x1b2)]())continue;const _0x14079b=await realpath(resolve(_0x273838,_0x1d1668[_0x136e61(0x28e)]))[_0x136e61(0x263)](()=>undefined);if(_0x14079b===undefined||!isWithinAllowedRoot(_0x14079b,_0x55e557))continue;const _0x34c031=await stat(_0x14079b)[_0x136e61(0x263)](()=>undefined);if(_0x34c031===undefined||!_0x34c031[_0x136e61(0x29d)]())continue;_0x13c1c4[_0x136e61(0x1bb)]({'path':_0x14079b,'name':_0x1d1668[_0x136e61(0x28e)],'selectable':isWithinAllowedRoot(_0x14079b,_0x2e9f22)});if(_0x13c1c4[_0x136e61(0x1c9)]>DIRECTORY_PICKER_LIMIT)break;}const _0x4b74f0=dirname(_0x273838);return{'homePath':_0x13cda6,'currentPath':_0x273838,'parentPath':_0x4b74f0===_0x273838||!isWithinAllowedRoot(_0x4b74f0,_0x55e557)?null:_0x4b74f0,'browseRoots':_0x2e9f22,'selectable':isWithinAllowedRoot(_0x273838,_0x2e9f22),'entries':_0x13c1c4[_0x136e61(0x288)](-0x510+-0x2413+0x2923*0x1,DIRECTORY_PICKER_LIMIT),'truncated':_0x13c1c4[_0x136e61(0x1c9)]>DIRECTORY_PICKER_LIMIT};}export async function listWorkspaceFiles(_0x163c08,_0x4a5cf1='.',_0x3ac3d7,_0x3d3d7d=DIRECTORY_PAGE_LIMIT){const _0xaed95c=_0x5af3e3;if(!Number[_0xaed95c(0x20b)](_0x3d3d7d)||_0x3d3d7d<-0x8*0x3fa+0x20*0x10f+-0x20f||_0x3d3d7d>DIRECTORY_PAGE_LIMIT)throw new Error(_0xaed95c(0x1c1));const _0x275fd6=await resolveRegisteredWorkspaceRoot(_0x163c08),_0x3b2bb4=await resolveWorkspaceEntryFromCanonicalRoot(_0x275fd6,_0x4a5cf1,!![]),_0x3d3b7d=await readdir(_0x3b2bb4,{'withFileTypes':!![]}),_0x1f0b45=decodeDirectoryCursor(_0x3ac3d7,_0x4a5cf1),_0x394548=_0x3d3b7d[_0xaed95c(0x2a4)](_0x3af06d=>_0x3af06d[_0xaed95c(0x28e)]!==_0xaed95c(0x255)&&!isWorkspaceUploadTemporaryName(_0x3af06d[_0xaed95c(0x28e)]))[_0xaed95c(0x1cc)](_0x445eb8=>_0x445eb8[_0xaed95c(0x28e)])[_0xaed95c(0x272)]((_0x4e28a7,_0x11a676)=>_0x4e28a7[_0xaed95c(0x24d)](_0x11a676)),_0x305d1d=_0x1f0b45===undefined?-0x1ad7*-0x1+0xf8c+0xe21*-0x3:_0x394548[_0xaed95c(0x22d)](_0x4358ed=>_0x4358ed>_0x1f0b45);if(_0x1f0b45!==undefined&&_0x305d1d===-(0x63*0x29+0x3f2+-0x13cc))return{'entries':[],'nextCursor':null,'truncated':![]};const _0x2a61bd=_0x394548[_0xaed95c(0x288)](_0x305d1d,_0x305d1d+_0x3d3d7d),_0x4bb36b=[];for(const _0x17497e of _0x2a61bd){const _0x94465a=await resolveWorkspaceEntry(_0x275fd6,relative(_0x275fd6,resolve(_0x3b2bb4,_0x17497e)),![])[_0xaed95c(0x263)](_0x3163de=>{if(isSkippableWorkspaceEntryError(_0x3163de))return undefined;throw _0x3163de;});if(_0x94465a===undefined)continue;const _0x5abaac=await lstat(_0x94465a)[_0xaed95c(0x263)](_0x1017f7=>{const _0x52cfbb=_0xaed95c;if(_0x1017f7[_0x52cfbb(0x1e1)]===_0x52cfbb(0x281))return undefined;throw _0x1017f7;});if(_0x5abaac===undefined||!_0x5abaac[_0xaed95c(0x1d9)]()&&!_0x5abaac[_0xaed95c(0x29d)]())continue;_0x4bb36b[_0xaed95c(0x1bb)]({'path':relative(_0x275fd6,_0x94465a)[_0xaed95c(0x23b)](sep)[_0xaed95c(0x1a1)]('/'),'name':_0x17497e,'kind':_0x5abaac[_0xaed95c(0x29d)]()?_0xaed95c(0x26a):_0xaed95c(0x285),'size':_0x5abaac[_0xaed95c(0x1d9)]()?_0x5abaac[_0xaed95c(0x2ae)]:null,'modifiedAt':_0x5abaac[_0xaed95c(0x1cd)]});}const _0x5631a2=_0x394548[_0x305d1d+_0x2a61bd[_0xaed95c(0x1c9)]];return{'entries':_0x4bb36b,'nextCursor':_0x5631a2===undefined||_0x2a61bd[_0xaed95c(0x1c9)]===-0x1*-0x23ad+-0x9*0xf6+0x11*-0x197?null:encodeDirectoryCursor(_0x4a5cf1,_0x2a61bd[_0x2a61bd[_0xaed95c(0x1c9)]-(0x1785+-0x2301+0xb7d)]),'truncated':_0x5631a2!==undefined};}export async function mutateWorkspaceFile(_0x3c650f,_0x2c3e78){const _0x420cdc=_0x5af3e3,_0x19e211=await resolveRegisteredWorkspaceRoot(_0x3c650f);if(_0x2c3e78[_0x420cdc(0x1ba)]===_0x420cdc(0x1fb)||_0x2c3e78[_0x420cdc(0x1ba)]===_0x420cdc(0x1e4)){const _0x198045=await resolveNewWorkspaceEntry(_0x19e211,_0x2c3e78[_0x420cdc(0x266)]);if(_0x2c3e78[_0x420cdc(0x1ba)]===_0x420cdc(0x1fb))await writeFile(_0x198045,'',{'flag':'wx'});else await mkdir(_0x198045);return{'path':workspaceRelativePath(_0x19e211,_0x198045)};}await assertWorkspaceMutationPathHasNoSymlinks(_0x19e211,_0x2c3e78[_0x420cdc(0x266)]);const _0x4304ce=await resolveWorkspaceEntryMetadata(_0x19e211,_0x2c3e78[_0x420cdc(0x266)]);if(workspaceRelativePath(_0x19e211,_0x4304ce[_0x420cdc(0x266)])==='.')throw new Error(_0x420cdc(0x27e));if(_0x2c3e78[_0x420cdc(0x1ba)]===_0x420cdc(0x28c))return await rm(_0x4304ce[_0x420cdc(0x266)],{'recursive':_0x4304ce[_0x420cdc(0x1f0)][_0x420cdc(0x29d)](),'force':![]}),{'deleted':!![]};const _0x526b2b=await resolveNewWorkspaceEntry(_0x19e211,_0x2c3e78[_0x420cdc(0x1e7)]);if(_0x4304ce[_0x420cdc(0x1f0)][_0x420cdc(0x29d)]()){const _0x1ebfea=relative(_0x4304ce[_0x420cdc(0x266)],_0x526b2b);if(_0x1ebfea===''||!isAbsolute(_0x1ebfea)&&_0x1ebfea!=='..'&&!_0x1ebfea[_0x420cdc(0x1bf)]('..'+sep))throw new Error(_0x420cdc(0x183));}return await rename(_0x4304ce[_0x420cdc(0x266)],_0x526b2b),{'path':workspaceRelativePath(_0x19e211,_0x526b2b)};}async function resolveNewWorkspaceEntry(_0x235e76,_0x1b5752){const _0x4ef1f8=_0x5af3e3,_0x426665=_0x1b5752[_0x4ef1f8(0x231)]('\x5c','/'),_0xbc9c7a=_0x426665[_0x4ef1f8(0x23b)]('/'),_0x545a47=_0xbc9c7a['at'](-(0x5*0x54c+0x1744+-0x587*0x9));if(_0x1b5752[_0x4ef1f8(0x201)]('\x00')||_0x426665[_0x4ef1f8(0x1bf)]('/')||isAbsolute(_0x1b5752)||win32[_0x4ef1f8(0x29f)](_0x426665)||_0x545a47===undefined||_0x545a47[_0x4ef1f8(0x1c9)]===0x2*-0x305+-0x1f58+0x2562||_0xbc9c7a[_0x4ef1f8(0x1f1)](invalidWorkspaceMutationSegment))throw new Error(_0x4ef1f8(0x1ad));const _0x1fcd0c=_0xbc9c7a[_0x4ef1f8(0x1c9)]===0x24f5+0xb1b+-0x300f?'.':_0xbc9c7a[_0x4ef1f8(0x288)](0x677*-0x1+0xe4+0x593*0x1,-(-0x1419+0x2cd+0x114d))[_0x4ef1f8(0x1a1)]('/');await assertWorkspaceMutationPathHasNoSymlinks(_0x235e76,_0x1fcd0c);const _0x2e4ca7=await resolveWorkspaceEntryFromCanonicalRoot(_0x235e76,_0x1fcd0c,!![]),_0x3b9790=resolve(_0x2e4ca7,_0x545a47);try{await lstat(_0x3b9790);throw new Error(_0x4ef1f8(0x202));}catch(_0x2f7ce6){if(_0x2f7ce6[_0x4ef1f8(0x1e1)]!==_0x4ef1f8(0x281))throw _0x2f7ce6;}return _0x3b9790;}async function assertWorkspaceMutationPathHasNoSymlinks(_0x51a321,_0x5ac14d){const _0x26323d=_0x5af3e3,_0x1ce2d0=_0x5ac14d[_0x26323d(0x231)]('\x5c','/');if(_0x1ce2d0==='.')return;const _0x218f4e=_0x1ce2d0[_0x26323d(0x23b)]('/');if(_0x5ac14d[_0x26323d(0x201)]('\x00')||_0x1ce2d0[_0x26323d(0x1bf)]('/')||isAbsolute(_0x5ac14d)||win32[_0x26323d(0x29f)](_0x1ce2d0)||_0x218f4e[_0x26323d(0x1f1)](invalidWorkspaceMutationSegment))throw new Error(_0x26323d(0x1ad));let _0x5b78f4=_0x51a321;for(const _0x2ddc2c of _0x218f4e){_0x5b78f4=resolve(_0x5b78f4,_0x2ddc2c);const _0x23fbfe=await lstat(_0x5b78f4)[_0x26323d(0x263)](_0x5a0e2e=>{const _0x2367f1=_0x26323d;if(_0x5a0e2e[_0x2367f1(0x1e1)]===_0x2367f1(0x281))throw new Error(_0x2367f1(0x1c4));throw _0x5a0e2e;});if(_0x23fbfe[_0x26323d(0x1b2)]())throw new Error(_0x26323d(0x1ad));}}function invalidWorkspaceMutationSegment(_0x3e25bd){const _0x352fb5=_0x5af3e3;if(_0x3e25bd[_0x352fb5(0x1c9)]===-0x1e8+-0x2*-0x442+-0x69c||_0x3e25bd==='.'||_0x3e25bd==='..'||_0x3e25bd===_0x352fb5(0x255))return!![];if(_0x315274()!==_0x352fb5(0x227))return![];const _0x78a4e2=_0x3e25bd[_0x352fb5(0x18c)](/[. ]+$/u,'')[_0x352fb5(0x20a)]();return/[<>:"|?*]/u[_0x352fb5(0x1e6)](_0x3e25bd)||/^(?:CON|PRN|AUX|NUL|COM[1-9]|LPT[1-9])(?:\..*)?$/u[_0x352fb5(0x1e6)](_0x78a4e2);}function workspaceRelativePath(_0x1e1ce7,_0x355f61){const _0x25d30e=_0x5af3e3,_0x100953=relative(_0x1e1ce7,_0x355f61)[_0x25d30e(0x23b)](sep)[_0x25d30e(0x1a1)]('/');return _0x100953[_0x25d30e(0x1c9)]===0x3*-0xa5d+0x1063+0xeb4?'.':_0x100953;}function isSkippableWorkspaceEntryError(_0x2b6cd9){const _0x50e4c0=_0x5af3e3;return _0x2b6cd9 instanceof Error&&(_0x2b6cd9[_0x50e4c0(0x214)]===_0x50e4c0(0x1ad)||_0x2b6cd9[_0x50e4c0(0x214)]===_0x50e4c0(0x1c4)||_0x2b6cd9[_0x50e4c0(0x214)]===_0x50e4c0(0x1e3));}export async function preflightWorkspaceUpload(_0x149384,_0x3b4517,_0x4413bd){const _0x15dcd8=_0x5af3e3;if(_0x4413bd[_0x15dcd8(0x1c9)]===0x24*0x24+0x1*-0x138a+0x6d*0x22||_0x4413bd==='.'||_0x4413bd==='..'||_0x4413bd[_0x15dcd8(0x201)]('\x00')||_0x4413bd[_0x15dcd8(0x201)]('/')||_0x4413bd[_0x15dcd8(0x201)]('\x5c')||isWorkspaceUploadTemporaryName(_0x4413bd))return{'path':'','absolutePath':'','status':_0x15dcd8(0x2b6)};const _0x1e8550=await resolveRegisteredWorkspaceRoot(_0x149384),_0x8ab5de=await resolveWorkspaceEntry(_0x1e8550,_0x3b4517,!![]),_0x500102=resolve(_0x8ab5de,_0x4413bd);if(dirname(_0x500102)!==_0x8ab5de)throw new Error(_0x15dcd8(0x1ad));const _0xeb01d4=relative(_0x1e8550,_0x500102)[_0x15dcd8(0x23b)](sep)[_0x15dcd8(0x1a1)]('/'),_0x483ddf=await lstat(_0x500102)[_0x15dcd8(0x263)](_0x41a43a=>{const _0x73eff4=_0x15dcd8;if(_0x41a43a[_0x73eff4(0x1e1)]===_0x73eff4(0x281))return undefined;throw _0x41a43a;});if(_0x483ddf===undefined)return{'path':_0xeb01d4,'absolutePath':_0x500102,'status':_0x15dcd8(0x1fe)};if(_0x483ddf[_0x15dcd8(0x1b2)]())throw new Error(_0x15dcd8(0x1ad));if(_0x483ddf[_0x15dcd8(0x1d9)]())return{'path':_0xeb01d4,'absolutePath':_0x500102,'status':_0x15dcd8(0x1fa)};return{'path':_0xeb01d4,'absolutePath':_0x500102,'status':_0x15dcd8(0x1ee)};}export function workspaceUploadTemporaryName(_0x9dcb1c){const _0x5a63ee=_0x5af3e3;return _0x5a63ee(0x278)+_0x9dcb1c+_0x5a63ee(0x26f);}function isWorkspaceUploadTemporaryName(_0x3e0b2f){const _0x49272b=_0x5af3e3;return/^\.mar-upload-[0-9a-f-]{36}\.part$/iu[_0x49272b(0x1e6)](_0x3e0b2f)||/^\.mar-edit-[0-9a-f-]{36}\.part$/iu[_0x49272b(0x1e6)](_0x3e0b2f);}export async function readWorkspaceTextFile(_0x16f5e0,_0x2cc02f,_0x5e9b38=0xb*-0x2a8+-0x1720+0x3458,_0x3c7214=FILE_READ_LIMIT){const _0x13e5ba=_0x5af3e3;if(!Number[_0x13e5ba(0x20b)](_0x5e9b38)||_0x5e9b38<0x69b+0x276+0xd3*-0xb||!Number[_0x13e5ba(0x20b)](_0x3c7214)||_0x3c7214<0xa25*-0x1+-0xb0f+0x1535||_0x3c7214>FILE_READ_LIMIT)throw new Error(_0x13e5ba(0x1b9));const _0x1e29f9=await resolveRegisteredWorkspaceRoot(_0x16f5e0),_0x22fe72=await resolveWorkspaceEntry(_0x1e29f9,_0x2cc02f,![]),_0x5bd931=await lstat(_0x22fe72);if(!_0x5bd931[_0x13e5ba(0x1d9)]())throw new Error(_0x13e5ba(0x1e3));if(_0x5bd931[_0x13e5ba(0x2ae)]>FILE_READ_LIMIT*(0x101a+0xca+-0x10d4))throw new Error(_0x13e5ba(0x188));const _0x39a44c=await readFile(_0x22fe72),_0x184099=createHash(_0x13e5ba(0x29e))[_0x13e5ba(0x253)](_0x39a44c)[_0x13e5ba(0x27c)](_0x13e5ba(0x284)),_0x4878fe=_0x39a44c[_0x13e5ba(0x201)](-0x22aa+-0x826*-0x4+0x212)||!isValidUtf8(_0x39a44c);if(_0x4878fe){const _0x3e8f74=Math[_0x13e5ba(0x25d)](_0x39a44c[_0x13e5ba(0x1c9)],_0x5e9b38+_0x3c7214),_0x279b1e=_0x39a44c[_0x13e5ba(0x273)](_0x5e9b38,_0x3e8f74);return{'path':relative(_0x1e29f9,_0x22fe72)[_0x13e5ba(0x23b)](sep)[_0x13e5ba(0x1a1)]('/'),'encoding':_0x13e5ba(0x24e),'size':_0x39a44c[_0x13e5ba(0x1c9)],'content':_0x279b1e[_0x13e5ba(0x230)](_0x13e5ba(0x24e)),'truncated':_0x3e8f74<_0x39a44c[_0x13e5ba(0x1c9)],'nextOffset':_0x3e8f74<_0x39a44c[_0x13e5ba(0x1c9)]?_0x3e8f74:null,'revision':_0x184099};}if(_0x5e9b38>-0x1935*0x1+-0xe*-0x1e7+-0x16d&&_0x5e9b38<_0x39a44c[_0x13e5ba(0x1c9)]&&isUtf8ContinuationByte(_0x39a44c[_0x5e9b38]))throw new Error(_0x13e5ba(0x1b9));let _0x18792e=Math[_0x13e5ba(0x25d)](_0x39a44c[_0x13e5ba(0x1c9)],_0x5e9b38+_0x3c7214);if(_0x18792e<_0x39a44c[_0x13e5ba(0x1c9)]&&isUtf8ContinuationByte(_0x39a44c[_0x18792e])){while(_0x18792e>_0x5e9b38&&isUtf8ContinuationByte(_0x39a44c[_0x18792e]))_0x18792e-=-0x181e+0x18c1+0x1*-0xa2;if(_0x18792e===_0x5e9b38){_0x18792e+=0xf7f+0xf1e+-0x4*0x7a7;while(_0x18792e<_0x39a44c[_0x13e5ba(0x1c9)]&&isUtf8ContinuationByte(_0x39a44c[_0x18792e]))_0x18792e+=0x250c+-0x658+-0x1d*0x10f;}}const _0x1f7e7f=_0x39a44c[_0x13e5ba(0x273)](_0x5e9b38,_0x18792e),_0x32e0ca=new TextDecoder(_0x13e5ba(0x1d5),{'fatal':!![]})[_0x13e5ba(0x217)](_0x1f7e7f),_0x39d381=_0x18792e<_0x39a44c[_0x13e5ba(0x1c9)]?_0x18792e:null;return{'path':relative(_0x1e29f9,_0x22fe72)[_0x13e5ba(0x23b)](sep)[_0x13e5ba(0x1a1)]('/'),'encoding':_0x13e5ba(0x1d5),'size':_0x39a44c[_0x13e5ba(0x1c9)],'content':_0x32e0ca,'truncated':_0x39d381!==null,'nextOffset':_0x39d381,'revision':_0x184099};}export async function writeWorkspaceTextFile(_0x1a7a9c,_0x331fcd,_0x57f277,_0x1a9523){const _0x5b161e=_0x5af3e3;if(!/^[0-9a-f]{64}$/u[_0x5b161e(0x1e6)](_0x1a9523))throw new Error(_0x5b161e(0x244));const _0x22b615=Buffer[_0x5b161e(0x27d)](_0x57f277,_0x5b161e(0x250));if(_0x22b615[_0x5b161e(0x1c9)]>FILE_READ_LIMIT*(0x18fe+0x1*-0x18d+-0x299*0x9))throw new Error(_0x5b161e(0x188));if(_0x22b615[_0x5b161e(0x201)](0x24cb+-0x1e26+-0x6a5))throw new Error(_0x5b161e(0x23d));const _0x87a9f=await resolveRegisteredWorkspaceRoot(_0x1a7a9c);await assertWorkspaceMutationPathHasNoSymlinks(_0x87a9f,_0x331fcd);const _0x5145fa=await resolveWorkspaceEntry(_0x87a9f,_0x331fcd,![]),_0x3fd370=await lstat(_0x5145fa);if(!_0x3fd370[_0x5b161e(0x1d9)]())throw new Error(_0x5b161e(0x1e3));const _0x4a7887=await readFile(_0x5145fa);if(_0x4a7887[_0x5b161e(0x201)](-0x25a8+0x1*-0x22ca+0xb*0x696)||!isValidUtf8(_0x4a7887))throw new Error(_0x5b161e(0x23d));const _0x35ed0d=createHash(_0x5b161e(0x29e))[_0x5b161e(0x253)](_0x4a7887)[_0x5b161e(0x27c)](_0x5b161e(0x284));if(_0x35ed0d!==_0x1a9523)throw new Error(_0x5b161e(0x286));const _0x19365d=createHash(_0x5b161e(0x29e))[_0x5b161e(0x253)](_0x22b615)[_0x5b161e(0x27c)](_0x5b161e(0x284)),_0x114d76=resolve(dirname(_0x5145fa),_0x5b161e(0x200)+randomUUID()+_0x5b161e(0x26f));try{await writeFile(_0x114d76,_0x22b615,{'flag':'wx','mode':_0x3fd370[_0x5b161e(0x29c)]}),await rename(_0x114d76,_0x5145fa);}finally{await rm(_0x114d76,{'force':!![]})[_0x5b161e(0x263)](()=>undefined);}return{'path':workspaceRelativePath(_0x87a9f,_0x5145fa),'revision':_0x19365d,'size':_0x22b615[_0x5b161e(0x1c9)]};}export async function readWorkspaceFileContentRange(_0x2a6551,_0x56c925,_0x29e24f=0xb9e*0x2+0x11*0x5e+-0x1d7a,_0x246980=FILE_READ_LIMIT){const _0x1e3f92=_0x5af3e3;if(!Number[_0x1e3f92(0x20b)](_0x29e24f)||_0x29e24f<0x577*0x4+-0x2034+0xa58||!Number[_0x1e3f92(0x20b)](_0x246980)||_0x246980<-0x1*0x1cf2+-0x171*-0x17+-0x434||_0x246980>FILE_READ_LIMIT)throw new Error(_0x1e3f92(0x1b9));const _0x4e5984=await resolveRegisteredWorkspaceRoot(_0x2a6551),_0x506fc1=await resolveWorkspaceEntry(_0x4e5984,_0x56c925,![]),_0xa6673a=await lstat(_0x506fc1);if(!_0xa6673a[_0x1e3f92(0x1d9)]())throw new Error(_0x1e3f92(0x1e3));if(_0x29e24f>_0xa6673a[_0x1e3f92(0x2ae)])throw new Error(_0x1e3f92(0x1b9));const _0x27fa52=Math[_0x1e3f92(0x25d)](_0x246980,_0xa6673a[_0x1e3f92(0x2ae)]-_0x29e24f),_0x149e09=Buffer[_0x1e3f92(0x211)](_0x27fa52),_0x26ff06=await open(_0x506fc1,'r');try{const {bytesRead:_0x4c65f3}=await _0x26ff06[_0x1e3f92(0x20f)](_0x149e09,-0x1*0x871+0xd2+0x1*0x79f,_0x27fa52,_0x29e24f),_0x3c6cbc=_0x29e24f+_0x4c65f3;return{'path':relative(_0x4e5984,_0x506fc1)[_0x1e3f92(0x23b)](sep)[_0x1e3f92(0x1a1)]('/'),'size':_0xa6673a[_0x1e3f92(0x2ae)],'offset':_0x29e24f,'contentBase64':_0x149e09[_0x1e3f92(0x273)](-0x2479+-0x1912+-0xc4f*-0x5,_0x4c65f3)[_0x1e3f92(0x230)](_0x1e3f92(0x24e)),'nextOffset':_0x3c6cbc<_0xa6673a[_0x1e3f92(0x2ae)]?_0x3c6cbc:null};}finally{await _0x26ff06[_0x1e3f92(0x28b)]();}}function _0x585a(){const _0x13ceab=['Chj1BMfIBguG','ls1UBY1LEhqTzgLMzG','AwDUB3jL','BgLZDa','BwvYz2uTyMfZzq','nda2ody5mhH4weftCW','Bg9JA2vKia','Bg9JywXLq29TCgfYzq','yMfZzty0','y2f0lwzPBgu','DxrMoa','C2nVCMu','D29YA3nWywnLuM9VDa','DxbKyxrL','A2LSBa','lMDPDa','AgfZvxjS','BgLTAxq','ls1WB3jJzwXHAw4','revmrvrfra','kIOVzgLZDc8QkG','zMXHDe1HCa','kIOVDgvZDc9YDw5ZlYOQ','BwLU','ls11BNrYywnRzwqTzMLSzxm9ywXS','kIOVBM9Kzv9TB2r1BgvZlYOQ','n1zUq3LuAq','r0Lux1jfrL9jtLzbteLe','B3v0Chv0','y2f0y2G','ls1UBY10zxH0y29UDG','tufqueve','Cgf0Aa','ls10B3bVlw9YzgvY','zNjLC2HUzxnZvhrStxm','r0Lux1DpuKTtuefdrq','reLsrunut1jz','CM9VDa','Bwf4','zxzLCNK','CMvMCW','lNbHCNq','CMv2lxbHCNnL','zw50CNLmAw1PDa','C29YDa','C3vIyxjYyxK','ls1ICMfUy2G','ls1MB3jTyxq9','ls1ZAg93lxrVCgXLDMvS','kIOVyNvPBgqVkIO','lM1HCI11CgXVywqT','ls1PCY1HBMnLC3rVCG','nZeWntyWmgfjzhfJCG','kIOVlMnHy2HLlYOQ','zgLNzxn0','zNjVBq','rKLmrv9st09ux01vvefusu9ox0LovKfmsuq','Dg91y2G','lMDPDg1VzhvSzxm','ru5pru5u','ls1UDwXS','v09ss1nqqunfx0rjuKvdve9swv9oqu1fx0LovKfmsuq','Agv4','rKLmrq','rKLmrv9xuKLurv9dt05gteLdva','kIOVlM5LEhqVkIO','C2XPy2u','ls1TyxGTy291BNq9','xNn1yM1VzhvSzvWUlIPClIHWyxrOFhvYBcKK','y2XVC2u','revmrvrf','DhjPBq','BMfTzq','kIOVlNbUCg0VkIO','r0Lux1nvqK1prfvmrv9esvndt1zfuLLFvfjvtKnbveve','C2vHCMnO','zxHLyW','y29UDgvUDenHBMrPzgf0zxm','qureruq','v09ss1nqqunfx0rfvKLdrv9qqvrix1jfsKvdveve','yNvIyMXLvxa','ls1VDgHLCNm','C3LTyM9SAwmTCMvM','v09ss1nqqunfx0rjuKvdve9swv9ot1rFquXmt1Dfra','C3rHDhvZ','C3rKzxjY','Bw9Kzq','AxneAxjLy3rVCNK','C2HHmJu2','AxnbyNnVBhv0zq','r0Lux0Hju1rpuLLFuKvgx0LovKfmsuq','AgfZAa','mJiYodiWodnts0vZque','Dg9mB2nHBgvmB3DLCKnHC2u','zMLSDgvY','C3rYAw5NAwz5','ls1ZAg93lxn1CgvYChjVAMvJDc13B3jRAw5NlxrYzwu','iYmG','CMvZDg9Yzq','D29YA3rYzwuG','vfLqrv9dsefor0ve','rKLmrv9trufsq0HFteLnsvrFrvHdruveruq','kIOVlNzLBNyVkIO','oIHSAxrLCMfSkq','C2L6zq','CMvMCMvZAgvKqxq','D29YA3rYzwu','ls1Uyw1Llxn0yxr1CW','ywXS','uKvnt1rf','lNzZy29Kzs9Zzxr0Aw5NCY5QC29U','BgLUDxG','su5wquXjrf9oqu1f','kIOVlNLHCM4VkIO','l2rLDI9UDwXS','C29YDgvK','y3vYC29Y','CMvMCY9OzwfKCW','zgLMzG','CxvLCNK','CgfYC2u','rKLmrv9nt1zfx0rfu0nftKrbtLrFsu5wquXjra','q09qsuve','C2HPzNq','z2v0','AwrSzvr0Be1Z','rKLmrv9ut09Ftefsr0u','te9dquW','y29Uy2f0','ls1YB290','CMvWBgfJzq','v09ss1nqqunfx05pvf9bteXpv0ve','tuLtu0LorW','CMvMCY9Yzw1VDgvZ','CgXHDgzVCM0','ls1Yzw1VDgvZ','y2fWywnPDhK','sevbra','kIOVlNbHCMnLBc1JywnOzs8QkG','C3rYAw5N','B2jQzwn0','pZ8G','yMLUyxj5','BgLTAxrZ','ndi3mdeYwKHQu3zR','zMLUywXSEq','C2HVDW','kIOVlM51EhqVkIO','zxHWAxj5vgLTzxi','kIOVDMvUzg9YlYOQ','ls1KyxrLlw9YzgvY','AM9PBG','ls12zxjPzNK','ls1ICMfUy2HLCW','Bg9N','zgLMzI10CMvL','r0Lux1jfue9tsvrpuLLFsu5wquXjra','ls1UBY1JB21TAxqTAwq','ywrK','C3rKB3v0','kIOVB2jQlYOQ','yNjHBMnOia','ruvysvnu','rKLmrv9qqvrix0vtq0fqrq','kIOVlMDYywrSzs8QkG','DMfSDwvZ','ls1NAxqTy29TBw9UlwrPCG','A2LUza','AxntEw1IB2XPy0XPBMS','C2v0','yMfYzq','CgLK','kIOVlMDPDc8QkG','C2LUA0rVD24','z2L0','rKLmrv9squ5hrv9jtLzbteLe','ywn0Aw9U','ChvZAa','uKvoqu1fra','C3rHBgu','CMvMCMvZAef0DgvTChrLzef0','C3rHCNrZv2L0Aa','kIOVDMvUDI8QkG','reLsrunut1jzx0nvuLnpuL9jtLzbteLe','Dhj1BMnHDgvK','Bg9HzgLUzW','rKLmrv9ot1rFrK9vtKq','BgfZDeLUzgv4t2y','CgLWzq','CMvIDwLSza','Bg9JA2vK','BgvUz3rO','u1rbr0ve','C2vHCMnOlMv4y2X1zgu','BwfW','BxrPBwvnCW','qMLUyxj5igzPBgvZia','B3v0Chv0tgLTAxq','BM93','zw5ZDxjLtg9HzgvK','zw50CMLLCW','CMvMCMvZAeLUqMfJA2DYB3vUza','zMLUza','DxrMltG','vu5uuKfds0ve','zw50CNK','ls1NzxqTCMvNzxHW','AxngAwXL','ls1MB3jTyxq9juGLEdaWjvaLEdaWjwfUjxGWmcvHzsv4mdaLy3qLEdaWjxm','kIOVy292zxjHz2uVkIO','B25Jzq','v09ss1nqqunfx1bmqvrgt1jnx1vou1vque9sveve','lMDPDc8','yNL0zuXLBMD0Aa','r0Lux0Hju1rpuLLFteLnsvrFsu5wquXjra','y29Kzq','CMvMCY9Yzw1VDgvZlW','rKLmrv9ot1rFuKvhvuXbuG','q1jfqvrfx0rjuKvdve9swq','tu9esuzjruq','DgvZDa','zgvZDgLUyxrPB24','zgLZCgXHEu5HBwu','zMLSzxmUzxHJBhvKzq','CMvMCY9OzwfKCY8','su5wquXjra','ls1MAwXL','AgfZ','rvHju1rtx0rjuKvdve9swq','r0Lux0Hju1rpuLLFq1vsu09sx0LovKfmsuq','Bwv0ywrHDge','C29Tzq','DgHLBG','zM9YlwvHy2GTCMvM','r0Lux0Hju1rpuLLFq09ntuLux0LovKfmsuq','r0Lux1DpuKTuuKvfx0Xju1rFsu5wquXjra','igj5DgvZpq','v09ss1nqqunfx1bbveHFsu5wquXjra','ls1ZB3vYy2u9sevbra','mZy3mtuYnxnOEMf1tG','rvHju1rtx0zjteu','q1jfqvrfx0zjteu','zMLUz2vYChjPBNq','zgf0yq','uKvbrfK','BM9YBwfSAxPL','lM1HCI1LzgL0lq','Aw5JBhvKzxm','rKLmrv9btfjfqurzx0vysvnuuW','kIOVyMLUlYOQ','lI4U','CMvHze9UBhK','yMfZzty0DxjS','ls1UBY1PBMrLEa','ls1MAxjZDc1WyxjLBNq','ls1ZDgfNzq','Dg9vChbLCKnHC2u','AxntywzLsw50zwDLCG','m2PzrwXLBa','v09ss1nqqunfx1bbveHFtK9ux0fcu09mvvrf','ls1Pz25VCMuTC3vIBw9KDwXLCZ1KAxj0Eq','CMvHza','ls1MB3jTyxq9jsHYzwzUyw1LksuWosuOCMvMBMfTztPZAg9YDcKLmdKLkg9IAMvJDg5HBwuPjta5jsHirufeksuWosuOC3LTCMvMkq','ywXSB2nvBNnHzMu','B2zMC2v0','mte5mZq4nfncug9gsa','BwvZC2fNzq','Aw5KzxHpzG','y29UzMLN','zgvJB2rL','CMvSyxrPDMu','ls1ZAg9YDa','nJu3mJq3mKv2vK5kuW','ls1LEgnSDwrLlxn0yw5KyxjK','BhmTzMLSzxm','kIOVlMfUz3vSyxiVkIO','ls1XDwLLDa','zxjYB3i','zgv0ywnOzwq','Dw5Yzwy','zMXVB3i','sevbrca','kIOVlNn2zwX0zs1RAxqVkIO','rKLmrv9ot1rFreLsrunut1jz','Dg9mB3DLCKnHC2u','D2LUmZi','lY5Flq','kIOVlNr1CMjVlYOQ','kIOVB3v0lYOQ','AxnjBNrLz2vY','ls13B3jRDhjLzq','zMLUzeLUzgv4','u0Lhs0Lmta','Chj1BMfIBgu','Dg9tDhjPBMC','CMvWBgfJzufSBa','yMXVyG','v09ss1nqqunfx0rjuKvdve9swv9fweLtvfm','ls1ZDgfNzwq','vu5tvefhruq','Dgv4Da','r0Lux0niqu5hrv9srvnut1jfx1voqvzbsuXbqKXf','kIOVDgfYz2v0lYOQ','ls1ZA2LWpq','r0Lux0nptu1btKrFrKfjteve','C3bSAxq','ls1WB3jJzwXHAw49DJe','rKLmrv9ot1rFvevyva','kIOVyM93zxjFy29TCg9Uzw50CY8QkG','DgLTzw91De1Z','yMLUyxj5igrPzMyGC2HHmJu2pq','y2HHBMDLCW','zgLZCg9Zzq','kIOVx19WEwnHy2HLx18VkIO','rKLmrv9srvzju0LptL9jtLzbteLe','Aw52ywXPza'];_0x585a=function(){return _0x13ceab;};return _0x585a();}export async function readAllowedFileContentRange(_0x344d4f,_0x4a4388,_0x4e1346=0x65f*-0x5+0x2*-0x371+-0x2f*-0xd3,_0x34ddf9=FILE_READ_LIMIT){const _0x13aacd=_0x5af3e3;if(!Number[_0x13aacd(0x20b)](_0x4e1346)||_0x4e1346<-0x199*0x16+0x47*-0x6b+-0xcf7*-0x5||!Number[_0x13aacd(0x20b)](_0x34ddf9)||_0x34ddf9<0x629+0x2400+-0x1514*0x2||_0x34ddf9>FILE_READ_LIMIT)throw new Error(_0x13aacd(0x1b9));const {file:_0xa9d9a9,metadata:_0x5bb4f1}=await resolveAllowedFile(_0x344d4f,_0x4a4388);if(_0x4e1346>_0x5bb4f1[_0x13aacd(0x2ae)])throw new Error(_0x13aacd(0x1b9));const _0x41d19d=Math[_0x13aacd(0x25d)](_0x34ddf9,_0x5bb4f1[_0x13aacd(0x2ae)]-_0x4e1346),_0x4e8051=Buffer[_0x13aacd(0x211)](_0x41d19d),_0x53c47b=await open(_0xa9d9a9,'r');try{const {bytesRead:_0xfb04bc}=await _0x53c47b[_0x13aacd(0x20f)](_0x4e8051,-0x16da+0x826+0xeb4,_0x41d19d,_0x4e1346),_0x290d1b=_0x4e1346+_0xfb04bc;return{'path':_0xa9d9a9,'size':_0x5bb4f1[_0x13aacd(0x2ae)],'offset':_0x4e1346,'contentBase64':_0x4e8051[_0x13aacd(0x273)](0xdd*-0x7+-0xb*-0x21a+-0x1113,_0xfb04bc)[_0x13aacd(0x230)](_0x13aacd(0x24e)),'nextOffset':_0x290d1b<_0x5bb4f1[_0x13aacd(0x2ae)]?_0x290d1b:null};}finally{await _0x53c47b[_0x13aacd(0x28b)]();}}export async function readAllowedTextFile(_0x14cd9d,_0x316b10,_0xb63005=0x1*-0x2537+0x211a*0x1+0x9*0x75,_0x2a1602=FILE_READ_LIMIT){const _0x4e994f=_0x5af3e3,{file:_0x53d353,metadata:_0x11174}=await resolveAllowedFile(_0x14cd9d,_0x316b10);if(_0x11174[_0x4e994f(0x2ae)]>FILE_READ_LIMIT*(0x2*-0x767+-0x1b05+0x29e3))throw new Error(_0x4e994f(0x188));if(!Number[_0x4e994f(0x20b)](_0xb63005)||_0xb63005<0xad2+0x185*-0x17+0x1821*0x1||!Number[_0x4e994f(0x20b)](_0x2a1602)||_0x2a1602<0xdfd+0x1*0x1fc2+-0x2*0x16df||_0x2a1602>FILE_READ_LIMIT)throw new Error(_0x4e994f(0x1b9));const _0x4c4ca2=await readFile(_0x53d353),_0x488fd0=_0x4c4ca2[_0x4e994f(0x201)](-0x757+-0x6f8+0x4c5*0x3)||!isValidUtf8(_0x4c4ca2),_0x5a3761=Math[_0x4e994f(0x25d)](_0x4c4ca2[_0x4e994f(0x1c9)],_0xb63005+_0x2a1602);if(_0x488fd0){const _0x19c90a=_0x4c4ca2[_0x4e994f(0x273)](_0xb63005,_0x5a3761);return{'path':_0x53d353,'encoding':_0x4e994f(0x24e),'size':_0x4c4ca2[_0x4e994f(0x1c9)],'content':_0x19c90a[_0x4e994f(0x230)](_0x4e994f(0x24e)),'truncated':_0x5a3761<_0x4c4ca2[_0x4e994f(0x1c9)],'nextOffset':_0x5a3761<_0x4c4ca2[_0x4e994f(0x1c9)]?_0x5a3761:null};}if(_0xb63005>0x40*0x7f+-0x4b7+-0x1b09&&_0xb63005<_0x4c4ca2[_0x4e994f(0x1c9)]&&isUtf8ContinuationByte(_0x4c4ca2[_0xb63005]))throw new Error(_0x4e994f(0x1b9));let _0x35bc47=_0x5a3761;if(_0x35bc47<_0x4c4ca2[_0x4e994f(0x1c9)]&&isUtf8ContinuationByte(_0x4c4ca2[_0x35bc47])){while(_0x35bc47>_0xb63005&&isUtf8ContinuationByte(_0x4c4ca2[_0x35bc47]))_0x35bc47-=0x160e+-0x13e*0x17+0x685;if(_0x35bc47===_0xb63005){_0x35bc47+=0x1633*0x1+0x25c4+-0x2*0x1dfb;while(_0x35bc47<_0x4c4ca2[_0x4e994f(0x1c9)]&&isUtf8ContinuationByte(_0x4c4ca2[_0x35bc47]))_0x35bc47+=-0x134e+0xd6*-0xd+-0x135*-0x19;}}const _0x48fcea=_0x35bc47<_0x4c4ca2[_0x4e994f(0x1c9)]?_0x35bc47:null;return{'path':_0x53d353,'encoding':_0x4e994f(0x1d5),'size':_0x4c4ca2[_0x4e994f(0x1c9)],'content':new TextDecoder(_0x4e994f(0x1d5),{'fatal':!![]})[_0x4e994f(0x217)](_0x4c4ca2[_0x4e994f(0x273)](_0xb63005,_0x35bc47)),'truncated':_0x48fcea!==null,'nextOffset':_0x48fcea};}export function normalizeFilePreviewPath(_0x119f51){const _0x4677de=_0x5af3e3;if(!/^sandbox:/iu[_0x4677de(0x1e6)](_0x119f51))return _0x119f51;let _0x532987;try{_0x532987=decodeURIComponent(_0x119f51[_0x4677de(0x288)](_0x119f51[_0x4677de(0x215)](':')+(-0x1ca*0x1+0x1bf+0xc)));}catch{throw new Error(_0x4677de(0x1ad));}const _0xec6ae4=_0x532987[_0x4677de(0x18c)](/^\/([a-z]:[\\/])/iu,'$1');if(_0xec6ae4[_0x4677de(0x1c9)]===-0x1823+-0x5*0x3f3+0x2be2||/^[\\/]{2,}[?.](?:[\\/]|$)/u[_0x4677de(0x1e6)](_0x532987)||!isAbsolute(_0xec6ae4)&&!win32[_0x4677de(0x29f)](_0xec6ae4)||_0xec6ae4[_0x4677de(0x201)]('\x00')||_0xec6ae4[_0x4677de(0x201)]('?')||_0xec6ae4[_0x4677de(0x201)]('#'))throw new Error(_0x4677de(0x1ad));return _0xec6ae4;}async function resolveAllowedFile(_0x59877a,_0x4eb388){const _0x36f51e=_0x5af3e3;if(!isAbsolute(_0x59877a))throw new Error(_0x36f51e(0x1ad));const _0x3cf380=await realpath(_0x59877a)[_0x36f51e(0x263)](_0xdb8135=>{const _0x50be98=_0x36f51e;if(_0xdb8135[_0x50be98(0x1e1)]===_0x50be98(0x281))throw new Error(_0x50be98(0x1c4));throw _0xdb8135;}),_0x4e9c0d=await Promise[_0x36f51e(0x2b2)](_0x4eb388[_0x36f51e(0x1cc)](_0x4d45da=>realpath(_0x4d45da)));if(!isWithinAllowedRoot(_0x3cf380,_0x4e9c0d))throw new Error(_0x36f51e(0x1ad));const _0x3bd523=await lstat(_0x3cf380);if(!_0x3bd523[_0x36f51e(0x1d9)]())throw new Error(_0x36f51e(0x1e3));return{'file':_0x3cf380,'metadata':_0x3bd523};}function isValidUtf8(_0x4b5f6e){const _0x105768=_0x5af3e3;try{return new TextDecoder(_0x105768(0x1d5),{'fatal':!![]})[_0x105768(0x217)](_0x4b5f6e),!![];}catch{return![];}}function isUtf8ContinuationByte(_0x424417){return(_0x424417&0x68e+0x93*0x13+-0xb*0x185)===0x16*-0x1af+0x12b3+0x12d7;}export async function searchWorkspaceFiles(_0x407aac,_0x3e70d6,_0x1dcfa3,_0x3effd9=SEARCH_RESULT_LIMIT,_0x2a16a4=![]){const _0x2ec0ac=_0x5af3e3,_0x239887=new WorkspaceFileIndex(_0x407aac);try{return await _0x239887[_0x2ec0ac(0x291)](_0x3e70d6,_0x1dcfa3,_0x3effd9,_0x2a16a4);}finally{_0x239887[_0x2ec0ac(0x242)]();}}async function resolveRegisteredWorkspaceRoot(_0x23c8df){const _0x499feb=_0x5af3e3,_0x507bee=await realpath(_0x23c8df);if(normalizeWorkspacePath(_0x507bee)!==normalizeWorkspacePath(_0x23c8df))throw new Error(_0x499feb(0x18d));return _0x507bee;}async function resolveWorkspaceEntry(_0x40bd4b,_0x88860a,_0x5b6c27){const _0x365b2d=await resolveRegisteredWorkspaceRoot(_0x40bd4b);return resolveWorkspaceEntryFromCanonicalRoot(_0x365b2d,_0x88860a,_0x5b6c27);}async function resolveWorkspaceEntryFromCanonicalRoot(_0xaaa625,_0x23eaa4,_0x12ee32){const _0x4da135=_0x5af3e3,_0x12a97c=await resolveWorkspaceEntryMetadata(_0xaaa625,_0x23eaa4);if(_0x12ee32?!_0x12a97c[_0x4da135(0x1f0)][_0x4da135(0x29d)]():!_0x12a97c[_0x4da135(0x1f0)][_0x4da135(0x1d9)]()&&!_0x12a97c[_0x4da135(0x1f0)][_0x4da135(0x29d)]())throw new Error(_0x12ee32?_0x4da135(0x225):_0x4da135(0x1e3));return _0x12a97c[_0x4da135(0x266)];}async function resolveWorkspaceEntryMetadata(_0x2d583b,_0x57cdff){const _0xcbb02e=_0x5af3e3;if(_0x57cdff[_0xcbb02e(0x201)]('\x00')||_0x57cdff[_0xcbb02e(0x1c9)]===-0x1d7a+0x35*-0xac+-0x1*-0x4116||_0x57cdff[_0xcbb02e(0x1bf)]('/')||_0x57cdff[_0xcbb02e(0x1bf)]('\x5c'))throw new Error(_0xcbb02e(0x1ad));const _0x150bbf=_0x57cdff[_0xcbb02e(0x231)]('\x5c','/');if(_0x150bbf[_0xcbb02e(0x23b)]('/')[_0xcbb02e(0x1f1)](_0x534686=>_0x534686==='..'||_0x534686===_0xcbb02e(0x255)))throw new Error(_0xcbb02e(0x1ad));let _0x439970;try{_0x439970=await realpath(resolve(_0x2d583b,_0x150bbf));}catch(_0x5ed097){if(_0x5ed097[_0xcbb02e(0x1e1)]===_0xcbb02e(0x281))throw new Error(_0xcbb02e(0x1c4));throw _0x5ed097;}const _0x57c66c=relative(_0x2d583b,_0x439970);if(isAbsolute(_0x57c66c)||_0x57c66c[_0xcbb02e(0x1bf)]('..')||_0x57c66c==='..'||_0x57c66c[_0xcbb02e(0x1bf)]('..'+sep))throw new Error(_0xcbb02e(0x1ad));const _0x1e96a1=await lstat(_0x439970);return{'path':_0x439970,'metadata':_0x1e96a1};}async function inspectWorkspaceIndexEntry(_0x126e34,_0x130b96,_0xcbedf5){const _0x3cefbe=_0x5af3e3;try{const _0x56a606=await resolveWorkspaceEntryMetadata(_0x126e34,_0x130b96);if(!_0x56a606[_0x3cefbe(0x1f0)][_0x3cefbe(0x1d9)]()&&!_0x56a606[_0x3cefbe(0x1f0)][_0x3cefbe(0x29d)]())return undefined;const _0x439b81=relative(_0x126e34,_0x56a606[_0x3cefbe(0x266)])[_0x3cefbe(0x23b)](sep)[_0x3cefbe(0x1a1)]('/');return _0x56a606[_0x3cefbe(0x1f0)][_0x3cefbe(0x29d)]()?{'path':_0x439b81,'name':_0xcbedf5,'kind':_0x3cefbe(0x26a),'size':null,'modifiedAt':_0x56a606[_0x3cefbe(0x1f0)][_0x3cefbe(0x1cd)]}:{'path':_0x439b81,'name':_0xcbedf5,'kind':_0x3cefbe(0x285),'size':_0x56a606[_0x3cefbe(0x1f0)][_0x3cefbe(0x2ae)],'modifiedAt':_0x56a606[_0x3cefbe(0x1f0)][_0x3cefbe(0x1cd)]};}catch{return undefined;}}function encodeDirectoryCursor(_0x1cb2f5,_0x3b73bc){const _0x468bf7=_0x5af3e3;return Buffer[_0x468bf7(0x27d)](JSON[_0x468bf7(0x2a5)]({'path':_0x1cb2f5,'name':_0x3b73bc}))[_0x468bf7(0x230)](_0x468bf7(0x206));}function decodeDirectoryCursor(_0x2cc5d2,_0x85dcdb){const _0x565ff7=_0x5af3e3;if(_0x2cc5d2===undefined)return undefined;try{const _0x367699=JSON[_0x565ff7(0x182)](Buffer[_0x565ff7(0x27d)](_0x2cc5d2,_0x565ff7(0x206))[_0x565ff7(0x230)](_0x565ff7(0x250)));if(typeof _0x367699!==_0x565ff7(0x196)||_0x367699===null||_0x367699[_0x565ff7(0x266)]!==_0x85dcdb||typeof _0x367699[_0x565ff7(0x28e)]!==_0x565ff7(0x195))throw new Error();return _0x367699[_0x565ff7(0x28e)];}catch{throw new Error(_0x565ff7(0x1c1));}}function encodeSearchCursor(_0x4a3796,_0x3f5ed1){const _0x2a202c=_0x5af3e3;return Buffer[_0x2a202c(0x27d)](JSON[_0x2a202c(0x2a5)]({'query':_0x4a3796,'path':_0x3f5ed1}))[_0x2a202c(0x230)](_0x2a202c(0x206));}function decodeSearchCursor(_0x3c8efa,_0x3696b5){const _0x4a828a=_0x5af3e3;if(_0x3c8efa===undefined)return undefined;try{const _0x2113a8=JSON[_0x4a828a(0x182)](Buffer[_0x4a828a(0x27d)](_0x3c8efa,_0x4a828a(0x206))[_0x4a828a(0x230)](_0x4a828a(0x250)));if(typeof _0x2113a8!==_0x4a828a(0x196)||_0x2113a8===null||_0x2113a8[_0x4a828a(0x181)]!==_0x3696b5||typeof _0x2113a8[_0x4a828a(0x266)]!==_0x4a828a(0x195))throw new Error();return _0x2113a8[_0x4a828a(0x266)];}catch{throw new Error(_0x4a828a(0x1c1));}}export function normalizeWorkspacePath(_0x27d57f,_0x20d07a=_0x315274()){const _0x5da579=_0x5af3e3;if(_0x27d57f[_0x5da579(0x1c9)]===-0x538*-0x4+0x1862+-0x2d42||_0x27d57f[_0x5da579(0x201)]('\u0000'))throw new Error(_0x5da579(0x1f7));if(_0x20d07a===_0x5da579(0x227)){if(/^\\\\[?.]/[_0x5da579(0x1e6)](_0x27d57f))throw new Error(_0x5da579(0x295));const _0x5c4114=win32[_0x5da579(0x1ff)](_0x27d57f[_0x5da579(0x231)]('/','\x5c'));if(!win32[_0x5da579(0x29f)](_0x5c4114))throw new Error(_0x5da579(0x20d));return _0x5c4114[_0x5da579(0x18c)](/\\+$/,'')[_0x5da579(0x226)]();}if(_0x20d07a!==_0x5da579(0x2b5))throw new Error(_0x5da579(0x1dd));const _0x1c3bb6=posix[_0x5da579(0x1ff)](_0x27d57f);if(!posix[_0x5da579(0x29f)](_0x1c3bb6))throw new Error(_0x5da579(0x20d));return _0x1c3bb6==='/'?_0x1c3bb6:_0x1c3bb6[_0x5da579(0x18c)](/\/+$/,'');}export function isWithinAllowedRoot(_0x1f0e69,_0x41db36,_0x1acda1=_0x315274()){const _0x5e32f3=_0x5af3e3,_0x3daf1b=normalizeWorkspacePath(_0x1f0e69,_0x1acda1),_0x1c4c8c=_0x1acda1===_0x5e32f3(0x227)?win32:posix;return _0x41db36[_0x5e32f3(0x1f1)](_0x341f3f=>{const _0x1c06cd=_0x5e32f3,_0x1a7560=normalizeWorkspacePath(_0x341f3f,_0x1acda1),_0x1ff454=_0x1c4c8c[_0x1c06cd(0x218)](_0x1a7560,_0x3daf1b);return _0x1ff454===''||!_0x1ff454[_0x1c06cd(0x1bf)]('..')&&!_0x1c4c8c[_0x1c06cd(0x29f)](_0x1ff454);});}export async function inspectWorkspace(_0x4d459b,_0x3c90bc){const _0x421985=_0x5af3e3,_0x3e616c=await realpath(_0x4d459b),_0x1242fe=await Promise[_0x421985(0x2b2)](_0x3c90bc[_0x421985(0x1cc)](_0xc1e79a=>realpath(_0xc1e79a))),_0x18caa1=await stat(_0x3e616c);if(!_0x18caa1[_0x421985(0x29d)]()||!isWithinAllowedRoot(_0x3e616c,_0x1242fe))throw new Error(_0x421985(0x18d));try{const _0x2fcda3=await readGitSummary(_0x3e616c);return{'path':_0x3e616c,'kind':_0x421985(0x269),'gitSummary':_0x2fcda3};}catch(_0x2bc041){if(_0x2bc041 instanceof GitCommandError&&_0x2bc041[_0x421985(0x1e1)]===-0x17*-0x1af+-0x8b+0x6a*-0x5b||isGitUnavailable(_0x2bc041))return{'path':_0x3e616c,'kind':_0x421985(0x26a)};throw _0x2bc041;}}export async function readGitSummary(_0x4ea886){const _0x19a48=_0x5af3e3,_0x35cfc4=(await runReadOnlyGit(_0x4ea886,[_0x19a48(0x270),_0x19a48(0x1b0)]))[_0x19a48(0x236)][_0x19a48(0x28d)](),_0x2e78e5=await runReadOnlyGitAllowFailure(_0x4ea886,[_0x19a48(0x270),_0x19a48(0x1a2),_0x19a48(0x193)]),_0x3baee8=await runReadOnlyGitAllowFailure(_0x4ea886,[_0x19a48(0x298),_0x19a48(0x21e),_0x19a48(0x219),_0x19a48(0x193)]),_0x337321={'timeoutMs':GIT_STATUS_TIMEOUT_MS,'outputLimit':GIT_LARGE_OUTPUT_LIMIT},_0x15dd98=await runReadOnlyGit(_0x4ea886,[_0x19a48(0x29a),_0x19a48(0x23c)],_0x337321);return{'commonDir':_0x35cfc4,'head':_0x2e78e5[_0x19a48(0x1e1)]===0x106*-0x18+0x278+-0x8*-0x2c3?_0x2e78e5[_0x19a48(0x236)][_0x19a48(0x28d)]():'','branch':_0x3baee8[_0x19a48(0x1e1)]===0x322+-0x100*0x8+-0x2*-0x26f?_0x3baee8[_0x19a48(0x236)][_0x19a48(0x28d)]():null,'dirty':_0x15dd98[_0x19a48(0x262)][_0x19a48(0x1c9)]>0x176d*0x1+0x3*-0x1ac+-0x1269,'snapshot':summarizeText(_0x15dd98[_0x19a48(0x236)])};}export function assertSafeGitRef(_0x47090d){const _0x372f95=_0x5af3e3;if(!REF_PATTERN[_0x372f95(0x1e6)](_0x47090d))throw new Error(_0x372f95(0x261));}export async function readRestrictedDiff(_0xd1f871,_0x2a0c9d,_0x376f4b){const _0x42fbb1=_0x5af3e3;assertSafeGitRef(_0x2a0c9d),assertSafeGitRef(_0x376f4b);const _0x127521=await runReadOnlyGit(_0xd1f871,[_0x42fbb1(0x2bc),_0x42fbb1(0x247),_0x42fbb1(0x264),_0x2a0c9d,_0x376f4b]),_0x1c19cf=_0x127521[_0x42fbb1(0x262)][_0x42fbb1(0x201)](0x31b+0x24fc+0x21*-0x137)||_0x127521[_0x42fbb1(0x236)][_0x42fbb1(0x201)](_0x42fbb1(0x1ce));if(_0x1c19cf)return{'binary':!![],'summary':_0x42fbb1(0x240)+createHash(_0x42fbb1(0x29e))[_0x42fbb1(0x253)](_0x127521[_0x42fbb1(0x262)])[_0x42fbb1(0x27c)](_0x42fbb1(0x284))+_0x42fbb1(0x1f6)+_0x127521[_0x42fbb1(0x262)][_0x42fbb1(0x1c9)],'truncated':_0x127521[_0x42fbb1(0x1c2)]};return{'binary':![],'text':_0x127521[_0x42fbb1(0x236)],'truncated':_0x127521[_0x42fbb1(0x1c2)]};}function currentBranchFromStatusHeader(_0x4ce75e){const _0x3605b9=_0x5af3e3,_0x19bb65=_0x4ce75e[_0x3605b9(0x288)](-0x1fa4+0x1a*0x15+0x1d85);if(_0x19bb65[_0x3605b9(0x1bf)](_0x3605b9(0x223)))return null;const _0x43e765=/^(?:No commits yet on|Initial commit on) (.+)$/[_0x3605b9(0x292)](_0x19bb65);if(_0x43e765!==null)return _0x43e765[0x3e*-0x79+0x1278+0xad7]??null;return _0x19bb65[_0x3605b9(0x23b)](_0x3605b9(0x204))[0x2213+-0x1f*0xcc+-0x1*0x95f]?.[_0x3605b9(0x23b)]('\x20')[0x570+-0x12*-0x31+-0x8e2]??null;}export async function listGitWorktrees(_0x94645b){const _0x135862=_0x5af3e3,_0x6f7ba4={'timeoutMs':GIT_STATUS_TIMEOUT_MS,'outputLimit':GIT_LARGE_OUTPUT_LIMIT},_0x2dabbb=await runReadOnlyGitAllowFailure(_0x94645b,[_0x135862(0x2b0),_0x135862(0x249),_0x135862(0x258),'-z'],_0x6f7ba4);if(_0x2dabbb[_0x135862(0x1e1)]===-0x122a*-0x1+-0x19c2+0x798)return parseGitWorktreeList(_0x94645b,_0x2dabbb,!![]);if(!canRetryGitWorktreeListWithoutNullOutput(_0x2dabbb))throw new GitCommandError(_0x2dabbb[_0x135862(0x1e1)],_0x2dabbb[_0x135862(0x29b)]);const _0x3512df=await runReadOnlyGit(_0x94645b,[_0x135862(0x2b0),_0x135862(0x249),_0x135862(0x258)],_0x6f7ba4);return parseGitWorktreeList(_0x94645b,_0x3512df,![]);}async function parseGitWorktreeList(_0x5af1c2,_0x26f165,_0x3c2e6a){const _0x4249a9=_0x5af3e3,_0xe68d5f=normalizeWorkspacePath(await realpath(_0x5af1c2)),_0x50c9dc=[];let _0x1ba5dd=_0x26f165[_0x4249a9(0x1c2)];const _0x20dcbd=_0x3c2e6a?_0x26f165[_0x4249a9(0x236)][_0x4249a9(0x23b)]('\x00\x00'):_0x26f165[_0x4249a9(0x236)][_0x4249a9(0x23b)](/\r?\n\r?\n/);for(const _0x44be55 of _0x20dcbd){if(_0x44be55[_0x4249a9(0x1c9)]===-0xa04*0x1+0x459*0x5+-0xbb9*0x1)continue;if(_0x50c9dc[_0x4249a9(0x1c9)]>=GIT_WORKTREE_LIST_LIMIT){_0x1ba5dd=!![];break;}const _0x32a80e=(_0x3c2e6a?_0x44be55[_0x4249a9(0x23b)]('\x00'):_0x44be55[_0x4249a9(0x23b)](/\r?\n/))[_0x4249a9(0x2a4)](_0x4a1a46=>_0x4a1a46[_0x4249a9(0x1c9)]>-0x21ad+-0x254e+0x2a1*0x1b);if(!_0x3c2e6a&&_0x32a80e[_0x4249a9(0x1f1)](_0x28b6af=>!(_0x28b6af[_0x4249a9(0x1bf)](_0x4249a9(0x2a9))||_0x28b6af[_0x4249a9(0x1bf)](_0x4249a9(0x223))||_0x28b6af[_0x4249a9(0x1bf)](_0x4249a9(0x1ab))||_0x28b6af===_0x4249a9(0x1b4)||_0x28b6af===_0x4249a9(0x220)||_0x28b6af===_0x4249a9(0x1c8)||_0x28b6af[_0x4249a9(0x1bf)](_0x4249a9(0x24c))||_0x28b6af===_0x4249a9(0x22f)||_0x28b6af[_0x4249a9(0x1bf)](_0x4249a9(0x246)))))throw new Error(_0x4249a9(0x1f5));if(_0x32a80e[_0x4249a9(0x1f1)](_0x4b27b5=>_0x4b27b5===_0x4249a9(0x1b4)))continue;const _0x1d9b36=_0x32a80e[_0x4249a9(0x1d4)](_0x4c1ce8=>_0x4c1ce8[_0x4249a9(0x1bf)](_0x4249a9(0x2a9))),_0x2a27b0=_0x32a80e[_0x4249a9(0x1d4)](_0x5d833f=>_0x5d833f[_0x4249a9(0x1bf)](_0x4249a9(0x223))),_0x3e38d9=_0x1d9b36?.[_0x4249a9(0x288)](_0x4249a9(0x2a9)[_0x4249a9(0x1c9)]),_0x51189b=_0x2a27b0?.[_0x4249a9(0x288)](_0x4249a9(0x223)[_0x4249a9(0x1c9)]);if(_0x3e38d9===undefined||_0x3e38d9[_0x4249a9(0x1c9)]===0x538+0x886+-0xdbe||_0x51189b===undefined||!/^[0-9a-f]{40,64}$/u[_0x4249a9(0x1e6)](_0x51189b)){if(_0x26f165[_0x4249a9(0x1c2)]){_0x1ba5dd=!![];continue;}throw new Error(_0x4249a9(0x1f5));}const _0x786002=_0x32a80e[_0x4249a9(0x1d4)](_0x48c057=>_0x48c057[_0x4249a9(0x1bf)](_0x4249a9(0x1ab))),_0x24c939=_0x786002?.[_0x4249a9(0x288)](_0x4249a9(0x1ab)[_0x4249a9(0x1c9)]),_0x36cf73=_0x24c939===undefined?null:_0x24c939[_0x4249a9(0x1bf)](_0x4249a9(0x1ea))?_0x24c939[_0x4249a9(0x288)](_0x4249a9(0x1ea)[_0x4249a9(0x1c9)]):_0x24c939,_0x5eb14d=(basename(_0x3e38d9)[_0x4249a9(0x28d)]()||_0x36cf73||_0x51189b[_0x4249a9(0x288)](0x1079*-0x1+-0x8fd+0x1976,-0x2*0x7a5+0x24cd*-0x1+0x9*0x5cb))[_0x4249a9(0x288)](-0x20f5+0x102*0x8+0x18e5,-0x1699+-0x1*-0x93d+0x1*0xf5c);_0x50c9dc[_0x4249a9(0x1bb)]({'path':_0x3e38d9,'directoryName':_0x5eb14d,'branch':_0x36cf73,'head':_0x51189b,'current':normalizeWorkspacePath(_0x3e38d9)===_0xe68d5f,'locked':_0x32a80e[_0x4249a9(0x1f1)](_0x42be78=>_0x42be78===_0x4249a9(0x1c8)||_0x42be78[_0x4249a9(0x1bf)](_0x4249a9(0x24c))),'prunable':_0x32a80e[_0x4249a9(0x1f1)](_0x3ab707=>_0x3ab707===_0x4249a9(0x22f)||_0x3ab707[_0x4249a9(0x1bf)](_0x4249a9(0x246)))});}return{'entries':_0x50c9dc,'truncated':_0x1ba5dd};}export async function readCurrentChangesSummary(_0x5d4d57,_0x36e9ef=![]){const _0xb59366=_0x5af3e3,_0x1126d6=[_0xb59366(0x29a),_0xb59366(0x23c),'-z',_0xb59366(0x274),_0xb59366(0x25e)],_0x501760={'timeoutMs':GIT_STATUS_TIMEOUT_MS,'outputLimit':GIT_LARGE_OUTPUT_LIMIT},_0x1c7859=await runReadOnlyGit(_0x5d4d57,_0x1126d6,_0x501760)[_0xb59366(0x263)](_0x5b71b5=>{const _0x1a7264=_0xb59366;if(!_0x36e9ef||!(_0x5b71b5 instanceof GitCommandError))throw _0x5b71b5;return runReadOnlyGit(_0x5d4d57,[..._0x1126d6,_0x1a7264(0x20e)],_0x501760);}),_0x482e1e=_0x1c7859[_0xb59366(0x236)][_0xb59366(0x23b)]('\x00'),_0x44d713=_0x482e1e[_0xb59366(0x185)]()??'',_0x6481c7=[];for(let _0x181737=0x1b*0x18+0x223*-0x1+-0x65*0x1;_0x181737<_0x482e1e[_0xb59366(0x1c9)];_0x181737+=-0xc7a+-0x43*0x49+0x1f96){const _0x12dc14=_0x482e1e[_0x181737];if(_0x12dc14[_0xb59366(0x1c9)]<0xecd+-0xddc*-0x1+-0x1ca5)continue;const _0x5dc45a=_0x12dc14[-0x17ee+0x1540+0x2ae],_0x4eb3b6=_0x12dc14[0x2188+-0x29*0x7f+0x698*-0x2],_0x157182=_0x12dc14[_0xb59366(0x288)](-0x1*0x19ff+-0x116a+0x2b6c*0x1);if(_0x5dc45a==='?'&&_0x4eb3b6==='?'){_0x6481c7[_0xb59366(0x1bb)]({'path':_0x157182,'state':_0xb59366(0x1d6),'change':_0xb59366(0x294)});continue;}_0x5dc45a!=='\x20'&&_0x6481c7[_0xb59366(0x1bb)]({'path':_0x157182,'state':_0xb59366(0x1ca),'change':gitChange(_0x5dc45a)});_0x4eb3b6!=='\x20'&&_0x6481c7[_0xb59366(0x1bb)]({'path':_0x157182,'state':_0xb59366(0x235),'change':gitChange(_0x4eb3b6)});if(_0x5dc45a==='R'||_0x5dc45a==='C'||_0x4eb3b6==='R'||_0x4eb3b6==='C')_0x181737+=0x8b4+0x17*-0x1c+-0x62f;}return{'branch':_0x44d713[_0xb59366(0x1bf)](_0xb59366(0x2a7))?currentBranchFromStatusHeader(_0x44d713):null,'changes':_0x6481c7};}export async function listGitSubmodules(_0x40e2f0){const _0x4e1265=_0x5af3e3,_0x52ea3f=await runReadOnlyGit(_0x40e2f0,[_0x4e1265(0x21c),_0x4e1265(0x209),'-z'],{'timeoutMs':GIT_STATUS_TIMEOUT_MS,'outputLimit':GIT_LARGE_OUTPUT_LIMIT});if(_0x52ea3f[_0x4e1265(0x1c2)])throw new Error(_0x4e1265(0x290));const _0x41b3d2=[...new Set(_0x52ea3f[_0x4e1265(0x236)][_0x4e1265(0x23b)]('\x00')[_0x4e1265(0x25b)](_0x1253b5=>{const _0x4fc82d=_0x4e1265,_0x41b476=/^160000 [0-9a-f]+ [0-3]\t([\s\S]+)$/[_0x4fc82d(0x292)](_0x1253b5);return _0x41b476?.[-0x2e+0x5*-0x6da+-0x3*-0xb7b]===undefined?[]:[_0x41b476[-0x65b*0x4+-0x1422+-0x2d8f*-0x1]];}))][_0x4e1265(0x272)]((_0x130671,_0x1ef2e8)=>_0x130671[_0x4e1265(0x24d)](_0x1ef2e8));if(_0x41b3d2[_0x4e1265(0x1c9)]===0x6*-0xb7+0xe*-0xa9+0xd88)return[];const _0x27d9ce=(_0x439698,_0x98187f)=>_0x41b3d2[_0x4e1265(0x1cc)](_0x504e00=>({'path':_0x504e00,'mapping':_0x439698,..._0x98187f===undefined?{}:{'gitExitCode':_0x98187f}}));try{const _0x5d078b=await lstat(resolve(_0x40e2f0,_0x4e1265(0x280)));if(!_0x5d078b[_0x4e1265(0x1d9)]()||_0x5d078b[_0x4e1265(0x1b2)]())return _0x27d9ce(_0x4e1265(0x1eb));}catch(_0x5d45bf){return _0x27d9ce(_0x5d45bf[_0x4e1265(0x1e1)]===_0x4e1265(0x281)?_0x4e1265(0x18e):_0x4e1265(0x1eb));}const _0x222a8b=await runReadOnlyGitAllowFailure(_0x40e2f0,[_0x4e1265(0x216),_0x4e1265(0x282),_0x4e1265(0x1ec),_0x4e1265(0x280),_0x4e1265(0x1d8),_0x4e1265(0x28a)],{'outputLimit':GIT_LARGE_OUTPUT_LIMIT});if(_0x222a8b[_0x4e1265(0x1c2)]||_0x222a8b[_0x4e1265(0x1e1)]!==-0x21c6+-0x2*-0x61+-0x1082*-0x2&&_0x222a8b[_0x4e1265(0x1e1)]!==0x1*-0x7f7+0x2419*0x1+0x1*-0x1c21)return _0x27d9ce(_0x4e1265(0x1eb),_0x222a8b[_0x4e1265(0x1e1)]);const _0x3727d3=new Map();for(const _0x3b6502 of _0x222a8b[_0x4e1265(0x236)][_0x4e1265(0x23b)]('\x00')){const _0x2ea48b=_0x3b6502[_0x4e1265(0x215)]('\x0a');if(_0x2ea48b<0xcfb*-0x1+0x778+0x11*0x53)continue;const _0x537656=_0x3b6502[_0x4e1265(0x288)](-0x4f+-0x719*-0x3+-0x14fc,_0x2ea48b),_0x302a5d=_0x3b6502[_0x4e1265(0x288)](_0x2ea48b+(-0xaa4+0x46f+0x636)),_0x3fa89c=/^submodule\.(.*)\.(path|url)$/[_0x4e1265(0x292)](_0x537656);if(_0x3fa89c?.[-0x591+-0x61*0x4+-0x2*-0x38b]===undefined)continue;const _0x5817c2=_0x3727d3[_0x4e1265(0x186)](_0x3fa89c[-0x3c1+0xd90+-0xa*0xfb])??{};if(_0x3fa89c[0x108*-0x25+0x1712+0xf18]===_0x4e1265(0x266))_0x5817c2[_0x4e1265(0x266)]=_0x302a5d;else _0x5817c2[_0x4e1265(0x256)]=_0x302a5d[_0x4e1265(0x28d)]()[_0x4e1265(0x1c9)]>-0x1d2+0xff0+-0xd*0x116;_0x3727d3[_0x4e1265(0x1b3)](_0x3fa89c[0x772+-0xa*0x36e+-0x19*-0x113],_0x5817c2);}const _0x38c32e=new Set([..._0x3727d3[_0x4e1265(0x1af)]()][_0x4e1265(0x25b)](_0x5e8e8e=>_0x5e8e8e[_0x4e1265(0x266)]!==undefined&&_0x5e8e8e[_0x4e1265(0x256)]?[_0x5e8e8e[_0x4e1265(0x266)]]:[]));return _0x41b3d2[_0x4e1265(0x1cc)](_0x396acd=>({'path':_0x396acd,'mapping':_0x38c32e[_0x4e1265(0x1ed)](_0x396acd)?_0x4e1265(0x265):_0x4e1265(0x18e)}));}export async function resolveGitRepository(_0x5e4cb3,_0x52aa22,_0x479e59){const _0x2c8313=_0x5af3e3,_0x1e37f1=await realpath(_0x5e4cb3);if(_0x52aa22[_0x2c8313(0x1c9)]===-0xf9*-0x17+0x1421*0x1+-0x2a80)return _0x1e37f1;if(_0x52aa22[_0x2c8313(0x201)]('\x00')||_0x52aa22[_0x2c8313(0x1bf)]('/')||_0x52aa22[_0x2c8313(0x1bf)]('\x5c')||_0x52aa22[_0x2c8313(0x23b)]('/')[_0x2c8313(0x1f1)](_0x28f245=>_0x28f245[_0x2c8313(0x1c9)]===0x15f+0x1*-0xde5+-0x7*-0x1ca||_0x28f245==='.'||_0x28f245==='..'))throw new Error(_0x2c8313(0x1a6));try{const _0x707ece=resolve(_0x1e37f1,_0x52aa22),_0x1dab39=await realpath(_0x707ece);if(normalizeWorkspacePath(_0x707ece)!==normalizeWorkspacePath(_0x1dab39)||!isWithinAllowedRoot(_0x1dab39,[_0x1e37f1]))throw new Error(_0x2c8313(0x245));if(_0x479e59!==undefined){if(!_0x479e59[_0x2c8313(0x201)](_0x52aa22))throw new Error(_0x2c8313(0x245));return _0x1dab39;}return await assertGitSuperprojectChain(_0x1e37f1,_0x1dab39),_0x1dab39;}catch{throw new Error(_0x2c8313(0x1a6));}}export async function resolveGitRepositoryTarget(_0x2ac78e,_0x34d4f1,_0x19a82b,_0x506a2b){const _0x2a5a4b=_0x5af3e3;if(_0x19a82b===undefined)return resolveGitRepository(_0x2ac78e,_0x34d4f1,_0x506a2b);if(_0x34d4f1[_0x2a5a4b(0x1c9)]!==-0x22a0+-0x1*0x21d3+-0x213*-0x21||_0x19a82b[_0x2a5a4b(0x1c9)]===-0x1*-0x25cf+-0x1ce*-0xf+-0x11*0x3d1||_0x19a82b[_0x2a5a4b(0x1c9)]>0x1*-0x254e+-0x1d0e+0x525c||_0x19a82b[_0x2a5a4b(0x201)]('\x00'))throw new Error(_0x2a5a4b(0x1a6));const _0x4c1777=normalizeWorkspacePath(_0x19a82b),_0x49c11c=await listGitWorktrees(_0x2ac78e),_0x38af2b=_0x49c11c[_0x2a5a4b(0x1d2)][_0x2a5a4b(0x1d4)](_0x199d35=>normalizeWorkspacePath(_0x199d35[_0x2a5a4b(0x266)])===_0x4c1777);if(_0x38af2b===undefined||_0x38af2b[_0x2a5a4b(0x22f)])throw new Error(_0x2a5a4b(0x1a6));try{return await realpath(_0x38af2b[_0x2a5a4b(0x266)]);}catch{throw new Error(_0x2a5a4b(0x1a6));}}function _0xd6ca(_0x408586,_0x58e472){_0x408586=_0x408586-(-0xb3*-0x1f+0x12*-0x49+-0xf0a);const _0x258d3a=_0x585a();let _0x29116e=_0x258d3a[_0x408586];if(_0xd6ca['UKmHDG']===undefined){var _0x137ed5=function(_0x365991){const _0x3417bf='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/=';let _0x267b3a='',_0x38e532='';for(let _0x52b492=0x2*-0xc11+0xab8+-0xca*-0x11,_0x86aabf,_0x4b4d4d,_0x1078bd=-0x936*-0x1+-0x1c78*0x1+0x1342;_0x4b4d4d=_0x365991['charAt'](_0x1078bd++);~_0x4b4d4d&&(_0x86aabf=_0x52b492%(-0x1d75+-0x51d*-0x7+0x329*-0x2)?_0x86aabf*(0x4*0x79f+-0x5*0x691+0x299)+_0x4b4d4d:_0x4b4d4d,_0x52b492++%(0x2048+-0x114a+-0x4fe*0x3))?_0x267b3a+=String['fromCharCode'](-0x93*0x24+0x1c1*0x5+0xce6&_0x86aabf>>(-(0x9a7+-0x240e+-0x1a69*-0x1)*_0x52b492&-0x21ee+0x1947+-0x8ad*-0x1)):0x109*-0x4+-0x67*-0x43+-0x3b*0x63){_0x4b4d4d=_0x3417bf['indexOf'](_0x4b4d4d);}for(let _0x43d5ff=-0x1445+-0x2*-0xc7+0x63d*0x3,_0xf32c6b=_0x267b3a['length'];_0x43d5ff<_0xf32c6b;_0x43d5ff++){_0x38e532+='%'+('00'+_0x267b3a['charCodeAt'](_0x43d5ff)['toString'](-0xbbc+0xfb8+-0x1f6*0x2))['slice'](-(-0xa67*-0x1+-0x19*0x10c+0xfc7));}return decodeURIComponent(_0x38e532);};_0xd6ca['RdYmne']=_0x137ed5,_0xd6ca['uYchDQ']={},_0xd6ca['UKmHDG']=!![];}const _0x3b88cd=_0x258d3a[-0x6*0x70+-0x1*0x67+0x9b*0x5];_0xd6ca['lhohpv']!==_0x3b88cd&&(_0xd6ca['uYchDQ']={},_0xd6ca['lhohpv']=_0x3b88cd);const _0x5b932c=_0xd6ca['uYchDQ'][_0x408586];return _0x5b932c===undefined?(_0x29116e=_0xd6ca['RdYmne'](_0x29116e),_0xd6ca['uYchDQ'][_0x408586]=_0x29116e):_0x29116e=_0x5b932c,_0x29116e;}async function assertGitSuperprojectChain(_0x21eaec,_0x19b852){const _0x23bd92=_0x5af3e3,_0x497a2b=normalizeWorkspacePath(_0x21eaec);let _0x42c8d5=_0x19b852;const _0x1d07ca=new Set();for(let _0x2d77a5=-0x25f0+-0x2*0xc7a+0x3ee4;_0x2d77a5<0x18eb+0x13a5+-0x1628*0x2;_0x2d77a5+=-0x1*-0x8ef+-0xcd7*0x1+-0x4d*-0xd){const _0x18a842=normalizeWorkspacePath(_0x42c8d5);if(_0x18a842===_0x497a2b)return;if(_0x1d07ca[_0x23bd92(0x1ed)](_0x18a842))throw new Error(_0x23bd92(0x245));_0x1d07ca[_0x23bd92(0x1a8)](_0x18a842);const _0x509bd5=await runReadOnlyGit(_0x42c8d5,[_0x23bd92(0x270),_0x23bd92(0x276),_0x23bd92(0x2a6)]),[_0x363eaf,_0x2954bc]=_0x509bd5[_0x23bd92(0x236)][_0x23bd92(0x23b)](/\r?\n/);if(_0x363eaf===undefined||_0x2954bc===undefined||_0x2954bc[_0x23bd92(0x1c9)]===-0x1efe+0x919*0x1+0x15e5)throw new Error(_0x23bd92(0x245));const _0x188d19=await realpath(_0x363eaf),_0x530e0e=await realpath(_0x2954bc);if(normalizeWorkspacePath(_0x188d19)!==_0x18a842||normalizeWorkspacePath(_0x530e0e)===_0x18a842||!isWithinAllowedRoot(_0x530e0e,[_0x21eaec])||!isWithinAllowedRoot(_0x42c8d5,[_0x530e0e]))throw new Error(_0x23bd92(0x245));_0x42c8d5=_0x530e0e;}throw new Error(_0x23bd92(0x245));}export async function listGitHistoryRefs(_0x4d03ff){const _0x360fb2=_0x5af3e3,_0x1020f6=await runReadOnlyGit(_0x4d03ff,[_0x360fb2(0x1f3),_0x360fb2(0x210),_0x360fb2(0x2bb),_0x360fb2(0x18f)],{'timeoutMs':GIT_HISTORY_TIMEOUT_MS,'outputLimit':GIT_LARGE_OUTPUT_LIMIT});return _0x1020f6[_0x360fb2(0x236)][_0x360fb2(0x23b)](/\r?\n/)[_0x360fb2(0x25b)](_0x20470f=>{const _0x182315=_0x360fb2,[_0x3b3030,_0x1fcec7,_0x3256db,_0x190a9c,_0x471c60]=_0x20470f[_0x182315(0x23b)]('\x09');if(_0x3b3030===undefined||_0x1fcec7===undefined||_0x3256db===undefined||_0x471c60===undefined||_0x471c60[_0x182315(0x1c9)]>0xa4a+-0xe62+-0x83*-0x8||!/^[0-9a-f]{40,64}$/[_0x182315(0x1e6)](_0x3256db))return[];const _0x5ef375=_0x3b3030[_0x182315(0x1bf)](_0x182315(0x1ea))?_0x182315(0x189):_0x3b3030[_0x182315(0x1bf)](_0x182315(0x1e2))?_0x182315(0x2b3):undefined;return _0x5ef375===undefined?[]:[{'name':_0x3b3030,'displayName':_0x1fcec7,'kind':_0x5ef375,'hash':_0x3256db,'current':_0x190a9c==='*'}];})[_0x360fb2(0x272)]((_0x41e51b,_0x157ddd)=>_0x41e51b[_0x360fb2(0x1b1)][_0x360fb2(0x24d)](_0x157ddd[_0x360fb2(0x1b1)])||_0x41e51b[_0x360fb2(0x1e8)][_0x360fb2(0x24d)](_0x157ddd[_0x360fb2(0x1e8)]));}function selectedHistoryRefs(_0xd48114,_0x50d870){const _0x486467=_0x5af3e3;if(_0x50d870===undefined||_0x50d870[_0x486467(0x1c9)]===0x1a*0x2f+0x2*-0x802+-0x2*-0x59f)return _0xd48114;const _0x689489=[...new Set(_0x50d870)],_0x207910=_0x689489[_0x486467(0x1cc)](_0x16c5d2=>_0xd48114[_0x486467(0x1d4)](_0x1c450b=>_0x1c450b[_0x486467(0x28e)]===_0x16c5d2));if(_0x207910[_0x486467(0x1f1)](_0x246367=>_0x246367===undefined))throw new Error(_0x486467(0x2a0));return _0x207910;}function historyCursor(_0x29f639,_0x2a89d3){const _0x343b09=_0x5af3e3;return Buffer[_0x343b09(0x27d)](JSON[_0x343b09(0x2a5)]({'offset':_0x29f639,'fingerprint':_0x2a89d3}))[_0x343b09(0x230)](_0x343b09(0x206));}function parseHistoryCursor(_0x41aa9d,_0x3f6a51){const _0x14eeda=_0x5af3e3;if(_0x41aa9d===undefined)return-0x26*0xb3+0x1*-0x1582+0x1*0x3014;try{const _0x329288=JSON[_0x14eeda(0x182)](Buffer[_0x14eeda(0x27d)](_0x41aa9d,_0x14eeda(0x206))[_0x14eeda(0x230)](_0x14eeda(0x250)));if(!Number[_0x14eeda(0x22b)](_0x329288[_0x14eeda(0x212)])||_0x329288[_0x14eeda(0x212)]<-0x61d*0x3+-0x129e+0x24f5||_0x329288[_0x14eeda(0x1fc)]!==_0x3f6a51)throw new Error(_0x14eeda(0x245));return _0x329288[_0x14eeda(0x212)];}catch{throw new Error(_0x14eeda(0x1ef));}}export async function readGitHistory(_0x5603be,_0x845efa){const _0x182b0e=_0x5af3e3,_0x5c09d6=await listGitHistoryRefs(_0x5603be),_0x42c9e7=selectedHistoryRefs(_0x5c09d6,_0x845efa[_0x182b0e(0x26e)]);if(_0x42c9e7[_0x182b0e(0x1c9)]===0xcd6+-0x9f*-0x25+-0x23d1*0x1)return{'commits':[],'nextCursor':null};const _0x16fca0=_0x845efa[_0x182b0e(0x257)]??-0x3c9*-0x3+0x3*-0x845+0x6d3*0x2;if(!Number[_0x182b0e(0x22b)](_0x16fca0)||_0x16fca0<0x10d*-0x15+-0x351+0x1963||_0x16fca0>0x133a*-0x2+0xf9*0x10+0x1748*0x1)throw new Error(_0x182b0e(0x1e0));const _0x1a4a8e=_0x42c9e7[_0x182b0e(0x1cc)](_0x20258c=>_0x20258c[_0x182b0e(0x28e)])[_0x182b0e(0x272)](),_0x34886e=_0x845efa[_0x182b0e(0x26e)]===undefined||_0x845efa[_0x182b0e(0x26e)][_0x182b0e(0x1c9)]===-0x1762+-0x150f+0x2c71||_0x42c9e7[_0x182b0e(0x1c9)]===_0x5c09d6[_0x182b0e(0x1c9)]&&_0x42c9e7[_0x182b0e(0x26d)](_0x5a0a0e=>_0x5c09d6[_0x182b0e(0x1f1)](_0x309e91=>_0x309e91[_0x182b0e(0x28e)]===_0x5a0a0e[_0x182b0e(0x28e)])),_0x21c7d3=_0x34886e?[_0x182b0e(0x1a3),_0x182b0e(0x191)]:_0x1a4a8e,_0x122c5c=createHash(_0x182b0e(0x29e))[_0x182b0e(0x253)](_0x42c9e7[_0x182b0e(0x1cc)](_0x2fdf55=>_0x2fdf55[_0x182b0e(0x28e)]+'\x00'+_0x2fdf55[_0x182b0e(0x2a1)])[_0x182b0e(0x272)]()[_0x182b0e(0x1a1)]('\x00'))[_0x182b0e(0x27c)](_0x182b0e(0x284)),_0x42062b=parseHistoryCursor(_0x845efa[_0x182b0e(0x2ba)],_0x122c5c),_0x46332d=await runReadOnlyGit(_0x5603be,[_0x182b0e(0x1a4),_0x182b0e(0x267),_0x182b0e(0x1a0),_0x182b0e(0x239)+_0x42062b,_0x182b0e(0x289)+(_0x16fca0+(0xea3*0x1+-0x3*-0x884+0x8b*-0x4a)),'-z',_0x182b0e(0x1da),..._0x21c7d3,'--'],{'timeoutMs':GIT_HISTORY_TIMEOUT_MS}),_0x4643ba=new Map();for(const _0x4b2916 of _0x5c09d6){const _0x3aae0c=_0x4643ba[_0x182b0e(0x186)](_0x4b2916[_0x182b0e(0x2a1)])??[];_0x3aae0c[_0x182b0e(0x1bb)](_0x4b2916[_0x182b0e(0x1e8)]),_0x4643ba[_0x182b0e(0x1b3)](_0x4b2916[_0x182b0e(0x2a1)],_0x3aae0c);}const _0x3cd7d8=_0x46332d[_0x182b0e(0x236)][_0x182b0e(0x23b)]('\x00'),_0x1fa0da=[];for(let _0x55ed7b=-0x11f0+-0x184*0xb+0x229c;_0x55ed7b+(0x2c2*0x1+-0x6*0xa3+0x1*0x115)<_0x3cd7d8[_0x182b0e(0x1c9)];_0x55ed7b+=0x5da+-0x23e2+0x1e0e){const [_0x44cf85,_0x42229a='',_0xaa2e3b='',_0x2c4f72='',_0x1e3dd4='0',_0x37ac4a='']=_0x3cd7d8[_0x182b0e(0x288)](_0x55ed7b,_0x55ed7b+(0x39*0x90+-0x2f*0xcb+0x53b*0x1));if(_0x44cf85===undefined||!/^[0-9a-f]{40,64}$/[_0x182b0e(0x1e6)](_0x44cf85))continue;_0x1fa0da[_0x182b0e(0x1bb)]({'hash':_0x44cf85,'parents':_0x42229a[_0x182b0e(0x1c9)]===0x9*0x293+-0xee1+-0x84a?[]:_0x42229a[_0x182b0e(0x23b)]('\x20'),'authorName':_0xaa2e3b,'authorEmail':_0x2c4f72,'committedAt':Number(_0x1e3dd4)*(0x2*0x734+-0x89c+-0x1e4),'subject':_0x37ac4a,'refs':_0x4643ba[_0x182b0e(0x186)](_0x44cf85)??[]});}const _0x555b14=_0x1fa0da[_0x182b0e(0x1c9)]>_0x16fca0;return{'commits':_0x1fa0da[_0x182b0e(0x288)](0xa57+0x2661+-0x30b8*0x1,_0x16fca0),'nextCursor':_0x555b14?historyCursor(_0x42062b+_0x16fca0,_0x122c5c):null};}async function assertHistoryCommitReachable(_0x38abd0,_0x320b40,_0xa197f9){const _0x895450=_0x5af3e3;if(!/^[0-9a-f]{40,64}$/[_0x895450(0x1e6)](_0x320b40))throw new Error(_0x895450(0x1f4));const _0x1fa89c=selectedHistoryRefs(await listGitHistoryRefs(_0x38abd0),_0xa197f9);for(const _0x1d3d8e of _0x1fa89c){const _0x2b38a2=await runReadOnlyGitAllowFailure(_0x38abd0,[_0x895450(0x24a),_0x895450(0x279),_0x320b40,_0x1d3d8e[_0x895450(0x28e)]]);if(_0x2b38a2[_0x895450(0x1e1)]===-0x416*0x1+0x2281+-0x1e6b)return;}throw new Error(_0x895450(0x1f4));}export async function readGitHistoryFiles(_0x26258b,_0xe6c67c,_0x53ae3c){const _0x3f67e5=_0x5af3e3;await assertHistoryCommitReachable(_0x26258b,_0xe6c67c,_0x53ae3c);const _0x4c0bdc=await runReadOnlyGit(_0x26258b,[_0x3f67e5(0x1a5),_0x3f67e5(0x18b),_0x3f67e5(0x208),_0x3f67e5(0x1a7),'-r','-z','-M','-C',_0x3f67e5(0x2b1),_0xe6c67c],{'timeoutMs':GIT_STATUS_TIMEOUT_MS,'outputLimit':GIT_LARGE_OUTPUT_LIMIT}),_0x55386c=_0x4c0bdc[_0x3f67e5(0x236)][_0x3f67e5(0x23b)]('\x00'),_0x3484da=[];for(let _0x1a09c0=0x28c*0x4+-0x7*0x15d+0x1*-0xa5;_0x1a09c0<_0x55386c[_0x3f67e5(0x1c9)];_0x1a09c0+=-0x1801*0x1+0x1*-0x2605+0x3e07){const _0x24ab1b=_0x55386c[_0x1a09c0];if(_0x24ab1b===undefined||_0x24ab1b[_0x3f67e5(0x1c9)]===-0x11f*-0xd+-0x8*0x137+-0x4db)continue;const _0x586b1b=_0x24ab1b[-0x4a*0x26+-0x606+0x1102]??'M';if(_0x586b1b==='R'||_0x586b1b==='C'){const _0x55e0af=_0x55386c[_0x1a09c0+(-0x80f*0x2+-0xd00+0x1d1f)],_0x635658=_0x55386c[_0x1a09c0+(0x55e+-0x738+-0x11*-0x1c)];if(_0x55e0af!==undefined&&_0x635658!==undefined)_0x3484da[_0x3f67e5(0x1bb)]({'path':_0x635658,'previousPath':_0x55e0af,'change':gitChange(_0x586b1b)});_0x1a09c0+=-0x1b67*-0x1+0x257b*-0x1+0xa16;}else{const _0x551e88=_0x55386c[_0x1a09c0+(0xcf9+-0x4*0x4ca+0x630)];if(_0x551e88!==undefined)_0x3484da[_0x3f67e5(0x1bb)]({'path':_0x551e88,'change':gitChange(_0x586b1b)});_0x1a09c0+=0x1c6d+-0x7*-0x1c6+0x146b*-0x2;}}return _0x3484da;}export async function readGitHistoryFileDiff(_0xa68a3a,_0x93eca8,_0x89398f,_0x411f14,_0x278686){const _0x335360=_0x5af3e3;await assertHistoryCommitReachable(_0xa68a3a,_0x93eca8,_0x411f14);const _0x286722=safeGitWorkspacePath(_0x89398f),_0x3347f8=_0x278686===undefined?undefined:safeGitWorkspacePath(_0x278686),_0x4588a0=await runReadOnlyGit(_0xa68a3a,[_0x335360(0x19c),_0x335360(0x275),_0x335360(0x208),_0x335360(0x247),_0x335360(0x264),_0x93eca8,'--',_0x335360(0x2ad)+_0x286722,..._0x3347f8===undefined||_0x3347f8===_0x286722?[]:[_0x335360(0x2ad)+_0x3347f8]]),_0x66c3f6=_0x4588a0[_0x335360(0x262)][_0x335360(0x201)](-0x1d3f*0x1+0x2*-0xddb+0x38f5)||_0x4588a0[_0x335360(0x236)][_0x335360(0x201)](_0x335360(0x1ce));if(_0x66c3f6)return{'binary':!![],'summary':_0x335360(0x240)+createHash(_0x335360(0x29e))[_0x335360(0x253)](_0x4588a0[_0x335360(0x262)])[_0x335360(0x27c)](_0x335360(0x284))+_0x335360(0x1f6)+_0x4588a0[_0x335360(0x262)][_0x335360(0x1c9)],'truncated':_0x4588a0[_0x335360(0x1c2)]};return{'binary':![],'text':_0x4588a0[_0x335360(0x236)],'truncated':_0x4588a0[_0x335360(0x1c2)]};}export async function readGitHistoryFileContentRange(_0x5b1fcd,_0x4ea9bc,_0x13335b,_0x32aa0b,_0x3960ce,_0x537daf){const _0x152b51=_0x5af3e3;if(!Number[_0x152b51(0x20b)](_0x32aa0b)||_0x32aa0b<-0x3e3*0x9+0x649*0x5+0xd*0x46||!Number[_0x152b51(0x20b)](_0x3960ce)||_0x3960ce<-0x5*0x35f+0xb94+0x548||_0x3960ce>(0x8b6+-0x4*0x6ec+0x130e)*(-0x1d*-0xf6+-0x3d2*-0x1+-0x1bb0)*(-0x805+-0x1ae9+0x26ee)||_0x32aa0b+_0x3960ce>(-0x2*-0x776+0x1f91*0x1+-0x2e69)*(0x9*0x407+0xb9b+-0x2bda)*(0x863+-0xba0+-0x11*-0x6d))throw new Error(_0x152b51(0x1b9));await assertHistoryCommitReachable(_0x5b1fcd,_0x4ea9bc,_0x537daf);const _0x4859da=safeGitWorkspacePath(_0x13335b),_0x42c3fc=_0x4ea9bc+':'+_0x4859da,_0x29e68f=await runReadOnlyGit(_0x5b1fcd,[_0x152b51(0x24f),'-s',_0x42c3fc]),_0x5399fe=Number(_0x29e68f[_0x152b51(0x236)][_0x152b51(0x28d)]());if(!Number[_0x152b51(0x20b)](_0x5399fe)||_0x5399fe<0x1*-0x161+-0x18c2+0x1a23||_0x32aa0b>_0x5399fe)throw new Error(_0x152b51(0x1b9));if(_0x32aa0b===_0x5399fe)return{'path':_0x4859da,'size':_0x5399fe,'offset':_0x32aa0b,'contentBase64':'','nextOffset':null};const _0x5a6017=await runReadOnlyGitAllowFailure(_0x5b1fcd,[_0x152b51(0x24f),_0x152b51(0x232),_0x42c3fc],{'outputLimit':_0x32aa0b+_0x3960ce,'timeoutMs':GIT_HISTORY_TIMEOUT_MS});if(_0x5a6017[_0x152b51(0x1e1)]!==-0xf4*-0x4+0x1*0x557+0x3*-0x30d)throw new GitCommandError(_0x5a6017[_0x152b51(0x1e1)],_0x5a6017[_0x152b51(0x29b)]);const _0x463c1b=_0x5a6017[_0x152b51(0x262)][_0x152b51(0x273)](_0x32aa0b,Math[_0x152b51(0x25d)](_0x5399fe,_0x32aa0b+_0x3960ce)),_0x3b0547=_0x32aa0b+_0x463c1b[_0x152b51(0x1c9)];return{'path':_0x4859da,'size':_0x5399fe,'offset':_0x32aa0b,'contentBase64':_0x463c1b[_0x152b51(0x230)](_0x152b51(0x24e)),'nextOffset':_0x3b0547<_0x5399fe?_0x3b0547:null};}export async function readCurrentChanges(_0x16a457){const _0x478bc9=_0x5af3e3;return(await readCurrentChangesSummary(_0x16a457))[_0x478bc9(0x241)];}export async function readCurrentChangeDiff(_0x413ea3,_0xb4a14f){const _0x4566cd=_0x5af3e3,_0x2d3b88=safeGitWorkspacePath(_0xb4a14f);await assertCurrentChangePathAccessible(_0x413ea3,_0x2d3b88);const _0x199a4f=await readCurrentChangeGitDiff(_0x413ea3,_0x2d3b88),_0x3bb5e3=await readWorkingTreeText(_0x413ea3,_0x2d3b88),_0x146328=_0x199a4f[_0x4566cd(0x262)][_0x4566cd(0x201)](-0x58d*0x7+-0x249a+-0x8d*-0x89)||_0x199a4f[_0x4566cd(0x236)][_0x4566cd(0x201)](_0x4566cd(0x1ce))||_0x3bb5e3?.[_0x4566cd(0x198)]===!![];if(_0x146328)return{'binary':!![],'summary':_0x4566cd(0x240)+createHash(_0x4566cd(0x29e))[_0x4566cd(0x253)](_0x199a4f[_0x4566cd(0x262)])[_0x4566cd(0x27c)](_0x4566cd(0x284))+_0x4566cd(0x1f6)+_0x199a4f[_0x4566cd(0x262)][_0x4566cd(0x1c9)],'truncated':_0x199a4f[_0x4566cd(0x1c2)]||_0x3bb5e3?.[_0x4566cd(0x1c2)]===!![]};return{'binary':![],'text':_0x199a4f[_0x4566cd(0x236)],'truncated':_0x199a4f[_0x4566cd(0x1c2)]||_0x3bb5e3?.[_0x4566cd(0x1c2)]===!![],'afterText':_0x3bb5e3?.[_0x4566cd(0x236)]??'',..._0x3bb5e3===undefined?{}:{'afterTruncated':_0x3bb5e3[_0x4566cd(0x1c2)]}};}async function readCurrentChangeGitDiff(_0x35a631,_0x376649){const _0x2d618b=_0x5af3e3,_0x40adbf=await runReadOnlyGit(_0x35a631,[_0x2d618b(0x21c),_0x2d618b(0x297),_0x2d618b(0x21b),'-z','--',_0x2d618b(0x2ad)+_0x376649]);if(_0x40adbf[_0x2d618b(0x236)][_0x2d618b(0x23b)]('\x00')[_0x2d618b(0x201)](_0x376649)){const _0x334e66=await runReadOnlyGitAllowFailure(_0x35a631,[_0x2d618b(0x2bc),_0x2d618b(0x207),_0x2d618b(0x247),_0x2d618b(0x264),'--',_0x2d618b(0x2b8),_0x376649]);if(_0x334e66[_0x2d618b(0x1e1)]!==0x2070+0xe*0x14d+-0x32a6&&_0x334e66[_0x2d618b(0x1e1)]!==0x7*0x2fb+0x20e5+0x1a1*-0x21)throw new GitCommandError(_0x334e66[_0x2d618b(0x1e1)],_0x334e66[_0x2d618b(0x29b)]);return _0x334e66;}return runReadOnlyGit(_0x35a631,[_0x2d618b(0x2bc),_0x2d618b(0x247),_0x2d618b(0x264),_0x2d618b(0x193),'--',_0x2d618b(0x2ad)+_0x376649]);}export async function isWorkspaceChangeVisible(_0x10b441,_0x4cd85f){const _0x1cc875=_0x5af3e3;try{return await assertCurrentChangePathAccessible(_0x10b441,safeGitWorkspacePath(_0x4cd85f)),!![];}catch(_0x1c852e){if(_0x1c852e instanceof Error&&(_0x1c852e[_0x1cc875(0x214)]===_0x1cc875(0x1ad)||_0x1c852e[_0x1cc875(0x214)]===_0x1cc875(0x1c4)||_0x1c852e[_0x1cc875(0x214)]===_0x1cc875(0x1e3)))return![];throw _0x1c852e;}}async function assertCurrentChangePathAccessible(_0x3221db,_0x12895b){const _0x19be52=_0x5af3e3,_0x48df83=await realpath(_0x3221db),_0x3b232c=resolve(_0x48df83,_0x12895b),_0x346505=await lstat(_0x3b232c)[_0x19be52(0x263)](_0x5bb14c=>{const _0x22442c=_0x19be52;if(_0x5bb14c[_0x22442c(0x1e1)]===_0x22442c(0x281))return undefined;throw _0x5bb14c;});if(_0x346505===undefined)return;await resolveWorkspaceEntry(_0x48df83,_0x12895b,![]);}async function readWorkingTreeText(_0x4e8068,_0xd9e00b){const _0x5b545c=_0x5af3e3,_0x308664=await realpath(_0x4e8068);let _0x48060d;try{_0x48060d=await resolveWorkspaceEntry(_0x308664,_0xd9e00b,![]);}catch(_0x252471){if(_0x252471 instanceof Error&&_0x252471[_0x5b545c(0x214)]===_0x5b545c(0x1c4))return undefined;throw _0x252471;}const _0x3230d7=await lstat(_0x48060d);if(!_0x3230d7[_0x5b545c(0x1d9)]())return undefined;const _0x56dc48=await readFile(_0x48060d);return diffTextFromBuffer(_0x56dc48,_0x56dc48[_0x5b545c(0x1c9)]>GIT_OUTPUT_LIMIT);}function diffTextFromBuffer(_0xbfa1a3,_0x4c51df){const _0x479ac3=_0x5af3e3;if(_0xbfa1a3[_0x479ac3(0x201)](0x121*0x13+0xfe1+0x1*-0x2554)||!isValidUtf8(_0xbfa1a3))return{'binary':!![],'truncated':_0x4c51df};let _0x86a4fd=Math[_0x479ac3(0x25d)](_0xbfa1a3[_0x479ac3(0x1c9)],GIT_OUTPUT_LIMIT);while(_0x86a4fd>-0x1*-0xc2f+0x1b2e+-0x275d*0x1&&_0x86a4fd<_0xbfa1a3[_0x479ac3(0x1c9)]&&isUtf8ContinuationByte(_0xbfa1a3[_0x86a4fd]))_0x86a4fd-=-0x1969+0x774+0x11f6;return{'binary':![],'text':_0xbfa1a3[_0x479ac3(0x273)](-0x1*0x23c9+-0x5*0x5f9+0x41a6,_0x86a4fd)[_0x479ac3(0x230)](_0x479ac3(0x250)),'truncated':_0x4c51df};}export async function restoreCurrentChange(_0x372a5e,_0x5b6b34,_0x462751){const _0xef657=_0x5af3e3,_0x347d7d=safeGitWorkspacePath(_0x5b6b34),_0x29be26=_0xef657(0x2ad)+_0x347d7d;if(_0x462751===_0xef657(0x1d6)){const _0x396a4f=await runReadOnlyGit(_0x372a5e,[_0xef657(0x29a),_0xef657(0x23c),'-z',_0xef657(0x25e),'--',_0x29be26]);if(!_0x396a4f[_0xef657(0x236)][_0xef657(0x23b)]('\x00')[_0xef657(0x1f1)](_0x8e9f7b=>_0x8e9f7b[_0xef657(0x1bf)](_0xef657(0x197))&&_0x8e9f7b[_0xef657(0x288)](-0x266+0x2238+-0x1fcf*0x1)===_0x347d7d))throw new Error(_0xef657(0x237));const _0x288215=await realpath(_0x372a5e),_0x1b7c1b=resolve(_0x288215,_0x347d7d),_0x3f8cc7=await lstat(_0x1b7c1b);if(!_0x3f8cc7[_0xef657(0x1d9)]()||_0x3f8cc7[_0xef657(0x1b2)]())throw new Error(_0xef657(0x237));await unlink(_0x1b7c1b);return;}if(_0x462751===_0xef657(0x235)){await runGit(_0x372a5e,[_0xef657(0x2a8),_0xef657(0x22c),'--',_0x29be26]);return;}await runGit(_0x372a5e,[_0xef657(0x2a8),_0xef657(0x1f8),_0xef657(0x234),_0xef657(0x22c),'--',_0x29be26]);}function safeGitWorkspacePath(_0x51837f){const _0x3b22e2=_0x5af3e3;if(_0x51837f[_0x3b22e2(0x1c9)]===-0x361*-0x2+0x729*0x1+-0xdeb||_0x51837f[_0x3b22e2(0x201)]('\x00')||_0x51837f[_0x3b22e2(0x1bf)]('/')||_0x51837f[_0x3b22e2(0x1bf)]('\x5c'))throw new Error(_0x3b22e2(0x1ad));const _0x372a27=_0x51837f[_0x3b22e2(0x231)]('\x5c','/');if(_0x372a27[_0x3b22e2(0x23b)]('/')[_0x3b22e2(0x1f1)](_0x563363=>_0x563363===''||_0x563363==='..'||_0x563363===_0x3b22e2(0x255)))throw new Error(_0x3b22e2(0x1ad));return _0x372a27;}function gitChange(_0x79b508){const _0x5ab68c=_0x5af3e3;if(_0x79b508==='A')return _0x5ab68c(0x294);if(_0x79b508==='D')return _0x5ab68c(0x259);if(_0x79b508==='R')return _0x5ab68c(0x1bc);if(_0x79b508==='C')return _0x5ab68c(0x184);if(_0x79b508==='T')return _0x5ab68c(0x2aa);return _0x5ab68c(0x1e5);}export class GitCommandError extends Error{[_0x5af3e3(0x1e1)];[_0x5af3e3(0x29b)];constructor(_0x3522c0,_0x38dcec){const _0x27ac5e=_0x5af3e3;super(_0x27ac5e(0x23a)),this[_0x27ac5e(0x1e1)]=_0x3522c0,this[_0x27ac5e(0x29b)]=_0x38dcec;}}async function runReadOnlyGit(_0x3d8727,_0x3d6e6a,_0x5b81fb={}){return runGit(_0x3d8727,_0x3d6e6a,{..._0x5b81fb,'readOnly':!![]});}async function runReadOnlyGitAllowFailure(_0xc6efa3,_0xe6f52c,_0x53b734={}){return runGitAllowFailure(_0xc6efa3,_0xe6f52c,{..._0x53b734,'readOnly':!![]});}async function runGit(_0x3b7ec6,_0xb71a37,_0x770783={}){const _0x542693=_0x5af3e3,_0x400445=await runGitAllowFailure(_0x3b7ec6,_0xb71a37,_0x770783);if(_0x400445[_0x542693(0x1e1)]!==0x3e+-0x210a+0x20cc)throw new GitCommandError(_0x400445[_0x542693(0x1e1)],_0x400445[_0x542693(0x29b)]);return _0x400445;}async function runGitAllowFailure(_0x102faf,_0x50fcc5,_0x123a86={}){return new Promise((_0x3fdd21,_0x4778b9)=>{const _0x2fba73=_0xd6ca,_0x2b35f3=_0x123a86[_0x2fba73(0x1cf)]??GIT_OUTPUT_LIMIT,_0x587cf3=spawn(_0x2fba73(0x1b8),[..._0x50fcc5],{'cwd':_0x102faf,'shell':![],'windowsHide':!![],'stdio':[_0x2fba73(0x248),_0x2fba73(0x1c6),_0x2fba73(0x1c6)],..._0x123a86[_0x2fba73(0x205)]===!![]?{'env':{...process.env,'GIT_OPTIONAL_LOCKS':'0'}}:{}}),_0x24549e=[],_0x5d45c2=[];let _0x2f7623=-0xf42+0x1c1e+-0xcdc*0x1,_0x4820b0=-0x2c0*0xa+0x197*0x2+0x1852,_0x18bf33=![];const _0x119f81=setTimeout(()=>{const _0x80ceda=_0x2fba73;if(process[_0x80ceda(0x190)]===_0x80ceda(0x227)){const _0x1be62a=_0x587cf3[_0x80ceda(0x1b5)];if(_0x1be62a===undefined){_0x587cf3[_0x80ceda(0x254)](_0x80ceda(0x22e));return;}void terminateProcessTree({'pid':_0x1be62a,'kill':_0x17ecd9=>_0x587cf3[_0x80ceda(0x254)](_0x17ecd9)},_0x80ceda(0x227))[_0x80ceda(0x263)](()=>{const _0x52127d=_0x80ceda;try{_0x587cf3[_0x52127d(0x254)](_0x52127d(0x22e));}catch{}});return;}_0x587cf3[_0x80ceda(0x254)](_0x80ceda(0x22e));},_0x123a86[_0x2fba73(0x23f)]??GIT_TIMEOUT_MS);_0x587cf3[_0x2fba73(0x1a9)]['on'](_0x2fba73(0x1fd),_0x538b26=>{const _0x3db38f=_0x2fba73,_0x5d73c3=Math[_0x3db38f(0x26c)](0x1*-0x1517+-0x7c*0x47+0x377b,_0x2b35f3-_0x2f7623);if(_0x5d73c3>-0x2c*-0x74+-0x250+-0xbc*0x18){const _0x49743d=_0x538b26[_0x3db38f(0x273)](0x133*-0x5+0x1ed0+-0x1*0x18d1,_0x5d73c3);_0x24549e[_0x3db38f(0x1bb)](_0x49743d),_0x2f7623+=_0x49743d[_0x3db38f(0x1c9)];}_0x18bf33||=_0x538b26[_0x3db38f(0x1c9)]>_0x5d73c3;}),_0x587cf3[_0x2fba73(0x29b)]['on'](_0x2fba73(0x1fd),_0x1fb534=>{const _0x38cc76=_0x2fba73,_0x2f2f02=Math[_0x38cc76(0x26c)](0x6*-0x1+-0x173*-0x4+-0x5c6,-0x22a3+0x1*0x1e79+0x2*0xa15-_0x4820b0);if(_0x2f2f02===0x547+-0x39*0x45+0x2*0x50b)return;const _0x4116e8=_0x1fb534[_0x38cc76(0x273)](-0x1591+-0x49c+0x1a2d,_0x2f2f02);_0x5d45c2[_0x38cc76(0x1bb)](_0x4116e8),_0x4820b0+=_0x4116e8[_0x38cc76(0x1c9)];}),_0x587cf3[_0x2fba73(0x1dc)](_0x2fba73(0x21f),_0x38e4fd=>{clearTimeout(_0x119f81),_0x4778b9(_0x38e4fd);}),_0x587cf3[_0x2fba73(0x1dc)](_0x2fba73(0x28b),_0x59a282=>{const _0x1afb97=_0x2fba73;clearTimeout(_0x119f81);const _0x370fa5=Buffer[_0x1afb97(0x18a)](_0x24549e);_0x3fdd21({'code':_0x59a282??-0x199e+-0x3*0xb82+0x3c25*0x1,'output':_0x370fa5,'text':_0x370fa5[_0x1afb97(0x230)](_0x1afb97(0x250)),'stderr':Buffer[_0x1afb97(0x18a)](_0x5d45c2)[_0x1afb97(0x230)](_0x1afb97(0x250)),'truncated':_0x18bf33});});});}function canRetryGitWorktreeListWithoutNullOutput(_0x49f355){const _0x4eec36=_0x5af3e3;return _0x49f355[_0x4eec36(0x1e1)]===-0x111b+-0x2*0x1294+0x36c4||/(?:unknown|unrecognized|invalid)\s+(?:option|switch).*['"`]?-?z\b/iu[_0x4eec36(0x1e6)](_0x49f355[_0x4eec36(0x29b)]);}function isGitUnavailable(_0x23d554){const _0x19b84b=_0x5af3e3;return _0x23d554 instanceof Error&&_0x19b84b(0x1e1)in _0x23d554&&_0x23d554[_0x19b84b(0x1e1)]===_0x19b84b(0x281);}function summarizeText(_0x25401c){const _0x3bb275=_0x5af3e3;return JSON[_0x3bb275(0x2a5)]({'sha256':createHash(_0x3bb275(0x29e))[_0x3bb275(0x253)](_0x25401c)[_0x3bb275(0x27c)](_0x3bb275(0x284)),'bytes':Buffer[_0x3bb275(0x1df)](_0x25401c)});}
1
+ import { createHash, randomUUID } from 'node:crypto';
2
+ import { lstat, mkdir, opendir, open, readdir, readFile, realpath, rename, rm, stat, unlink, writeFile } from 'node:fs/promises';
3
+ import { homedir, platform as hostPlatform } from 'node:os';
4
+ import { basename, dirname, isAbsolute, posix, relative, resolve, sep, win32 } from 'node:path';
5
+ import { spawn } from 'node:child_process';
6
+ import { minimatch } from 'minimatch';
7
+ import { terminateProcessTree } from './process-tree.js';
8
+ import { gitOperationEnvironment } from './service/git-operation-service.js';
9
+ const GIT_TIMEOUT_MS = 5_000;
10
+ const GIT_STATUS_TIMEOUT_MS = 30_000;
11
+ const GIT_HISTORY_TIMEOUT_MS = 15_000;
12
+ const GIT_OUTPUT_LIMIT = 512 * 1024;
13
+ const GIT_LARGE_OUTPUT_LIMIT = 8 * 1024 * 1024;
14
+ const FILE_READ_LIMIT = 512 * 1024;
15
+ const DIRECTORY_PAGE_LIMIT = 200;
16
+ const DIRECTORY_PICKER_LIMIT = 200;
17
+ const SEARCH_RESULT_LIMIT = 200;
18
+ const GIT_WORKTREE_LIST_LIMIT = 128;
19
+ const FILE_INDEX_IDLE_TTL_MS = 60 * 60 * 1_000;
20
+ const FILE_INDEX_FRESHNESS_TTL_MS = 30_000;
21
+ const FILE_INDEX_ENTRY_LIMIT = 100_000;
22
+ const FILE_INDEX_METADATA_CONCURRENCY = 32;
23
+ const DEFAULT_QUICK_OPEN_EXCLUDES = [
24
+ '**/.git/**',
25
+ '**/node_modules/**',
26
+ '**/bower_components/**',
27
+ '**/.pnpm/**',
28
+ '**/.yarn/**',
29
+ '**/.cache/**',
30
+ '**/.parcel-cache/**',
31
+ '**/.turbo/**',
32
+ '**/dist/**',
33
+ '**/build/**',
34
+ '**/out/**',
35
+ '**/coverage/**',
36
+ '**/test/runs/**',
37
+ '**/.next/**',
38
+ '**/.nuxt/**',
39
+ '**/.svelte-kit/**',
40
+ '**/.angular/**',
41
+ '**/target/**',
42
+ '**/.gradle/**',
43
+ '**/bin/**',
44
+ '**/obj/**',
45
+ '**/vendor/**',
46
+ '**/__pycache__/**',
47
+ '**/.venv/**',
48
+ '**/venv/**'
49
+ ];
50
+ const REF_PATTERN = /^(?!-)(?!.*\.\.)(?!.*@\{)[A-Za-z0-9][A-Za-z0-9._/-]{0,254}$/;
51
+ export async function createWorkspaceDirectory(parentPath, directoryName, allowedRoots) {
52
+ const name = directoryName.trim();
53
+ if (name.length === 0 ||
54
+ name.length > 255 ||
55
+ name === '.' ||
56
+ name === '..' ||
57
+ name.includes('/') ||
58
+ name.includes('\\') ||
59
+ name.includes('\0'))
60
+ throw new Error('WORKSPACE_DIRECTORY_NAME_INVALID');
61
+ const roots = await Promise.all(allowedRoots.map((root) => realpath(root)));
62
+ const parent = await realpath(parentPath).catch(() => {
63
+ throw new Error('WORKSPACE_DIRECTORY_NOT_ALLOWED');
64
+ });
65
+ const metadata = await stat(parent).catch(() => undefined);
66
+ if (metadata?.isDirectory() !== true || !isWithinAllowedRoot(parent, roots))
67
+ throw new Error('WORKSPACE_DIRECTORY_NOT_ALLOWED');
68
+ const target = resolve(parent, name);
69
+ if (dirname(target) !== parent || !isWithinAllowedRoot(target, roots))
70
+ throw new Error('WORKSPACE_DIRECTORY_NAME_INVALID');
71
+ try {
72
+ await mkdir(target);
73
+ }
74
+ catch (error) {
75
+ if (error.code === 'EEXIST')
76
+ throw new Error('WORKSPACE_DIRECTORY_EXISTS');
77
+ throw error;
78
+ }
79
+ return target;
80
+ }
81
+ /** A per-workspace, process-local index for the Quick Open file picker. */
82
+ export class WorkspaceFileIndex {
83
+ workspaceRoot;
84
+ limits;
85
+ entries = [];
86
+ truncated = false;
87
+ root;
88
+ loading;
89
+ stale = true;
90
+ expiryTimer;
91
+ refreshedAt = 0;
92
+ refreshAttemptedAt = 0;
93
+ constructor(workspaceRoot, limits = {}) {
94
+ this.workspaceRoot = workspaceRoot;
95
+ this.limits = limits;
96
+ }
97
+ async contentCandidates() {
98
+ await this.ensureLoaded();
99
+ this.touch();
100
+ return {
101
+ entries: this.entries.filter((entry) => entry.kind === 'FILE'),
102
+ truncated: this.truncated
103
+ };
104
+ }
105
+ dispose() {
106
+ if (this.expiryTimer !== undefined)
107
+ clearTimeout(this.expiryTimer);
108
+ this.expiryTimer = undefined;
109
+ this.entries = [];
110
+ this.truncated = false;
111
+ this.stale = true;
112
+ this.refreshedAt = 0;
113
+ this.refreshAttemptedAt = 0;
114
+ }
115
+ async search(query, cursor, limit = SEARCH_RESULT_LIMIT, includeDirectories = false) {
116
+ if (query.trim().length === 0 ||
117
+ query.length > 256 ||
118
+ !Number.isSafeInteger(limit) ||
119
+ limit < 1 ||
120
+ limit > SEARCH_RESULT_LIMIT)
121
+ throw new Error('FILE_SEARCH_LIMIT_EXCEEDED');
122
+ await this.ensureLoaded();
123
+ this.touch();
124
+ const after = decodeSearchCursor(cursor, query);
125
+ const afterEntry = after === undefined
126
+ ? undefined
127
+ : this.entries.find((entry) => entry.path === after && (includeDirectories || entry.kind === 'FILE'));
128
+ const afterScore = afterEntry === undefined ? -1 : fuzzyPathScore(afterEntry.path, query);
129
+ const afterCandidate = afterEntry === undefined || afterScore < 0
130
+ ? undefined
131
+ : { entry: afterEntry, score: afterScore };
132
+ const ranked = new RankedCandidateHeap(limit + 1);
133
+ for (const entry of this.entries) {
134
+ if (!includeDirectories && entry.kind !== 'FILE')
135
+ continue;
136
+ const score = fuzzyPathScore(entry.path, query);
137
+ if (score < 0)
138
+ continue;
139
+ const candidate = { entry, score };
140
+ if (afterCandidate !== undefined && compareRankedCandidate(candidate, afterCandidate) <= 0)
141
+ continue;
142
+ ranked.add(candidate);
143
+ }
144
+ const candidates = ranked.sorted();
145
+ const page = candidates.slice(0, limit).map((candidate) => candidate.entry);
146
+ const next = candidates[limit]?.entry.path;
147
+ return {
148
+ entries: page,
149
+ nextCursor: next === undefined ? null : encodeSearchCursor(query, page.at(-1)?.path ?? after ?? ''),
150
+ truncated: next !== undefined || this.truncated
151
+ };
152
+ }
153
+ async ensureLoaded() {
154
+ if (!this.stale && this.root !== undefined) {
155
+ if (Date.now() - this.refreshAttemptedAt >=
156
+ (this.limits.freshnessTtlMs ?? FILE_INDEX_FRESHNESS_TTL_MS))
157
+ this.refreshInBackground();
158
+ return;
159
+ }
160
+ if (this.loading === undefined) {
161
+ this.loading = this.rebuild().finally(() => {
162
+ this.loading = undefined;
163
+ });
164
+ }
165
+ await this.loading;
166
+ }
167
+ touch() {
168
+ if (this.expiryTimer !== undefined)
169
+ clearTimeout(this.expiryTimer);
170
+ this.expiryTimer = setTimeout(() => this.dispose(), this.limits.idleTtlMs ?? FILE_INDEX_IDLE_TTL_MS);
171
+ this.expiryTimer.unref();
172
+ }
173
+ async rebuild() {
174
+ const root = await resolveRegisteredWorkspaceRoot(this.workspaceRoot);
175
+ const excludes = [...DEFAULT_QUICK_OPEN_EXCLUDES, ...(await workspaceExcludePatterns(root))];
176
+ const indexed = [];
177
+ const entryLimit = this.limits.entryLimit ?? FILE_INDEX_ENTRY_LIMIT;
178
+ let truncated = false;
179
+ const directories = ['.'];
180
+ let directoryCursor = 0;
181
+ while (directoryCursor < directories.length && !truncated) {
182
+ const relativeDirectory = directories[directoryCursor];
183
+ directoryCursor += 1;
184
+ const directory = await resolveWorkspaceEntryFromCanonicalRoot(root, relativeDirectory, true).catch(() => undefined);
185
+ if (directory === undefined)
186
+ continue;
187
+ const stream = await opendir(directory).catch(() => undefined);
188
+ if (stream === undefined)
189
+ continue;
190
+ let pending = [];
191
+ const appendPending = async () => {
192
+ const resolvedEntries = await Promise.all(pending);
193
+ pending = [];
194
+ for (const entry of resolvedEntries) {
195
+ if (entry === undefined)
196
+ continue;
197
+ if (entry.path === '.git' ||
198
+ entry.path.startsWith('.git/') ||
199
+ isExcluded(entry.path, excludes))
200
+ continue;
201
+ if (entry.kind === 'DIRECTORY')
202
+ directories.push(entry.path);
203
+ indexed.push(entry);
204
+ if (indexed.length >= entryLimit) {
205
+ truncated = true;
206
+ break;
207
+ }
208
+ }
209
+ };
210
+ for await (const child of stream) {
211
+ const candidatePath = relativeDirectory === '.'
212
+ ? child.name
213
+ : posix.join(relativeDirectory.replaceAll('\\', '/'), child.name);
214
+ if (candidatePath === '.git' ||
215
+ candidatePath.startsWith('.git/') ||
216
+ isExcluded(candidatePath, excludes))
217
+ continue;
218
+ pending.push(inspectWorkspaceIndexEntry(root, candidatePath, child.name));
219
+ if (pending.length >= FILE_INDEX_METADATA_CONCURRENCY)
220
+ await appendPending();
221
+ if (truncated)
222
+ break;
223
+ }
224
+ if (!truncated && pending.length > 0)
225
+ await appendPending();
226
+ }
227
+ this.root = root;
228
+ this.entries = indexed;
229
+ this.truncated = truncated;
230
+ this.stale = false;
231
+ this.refreshedAt = Date.now();
232
+ this.refreshAttemptedAt = this.refreshedAt;
233
+ }
234
+ refreshInBackground() {
235
+ if (this.loading !== undefined)
236
+ return;
237
+ this.refreshAttemptedAt = Date.now();
238
+ this.loading = this.rebuild()
239
+ .catch(() => undefined)
240
+ .finally(() => {
241
+ this.loading = undefined;
242
+ });
243
+ }
244
+ }
245
+ async function workspaceExcludePatterns(root) {
246
+ const settingsPath = resolve(root, '.vscode/settings.json');
247
+ const settings = (await readFile(settingsPath, 'utf8')
248
+ .then(JSON.parse)
249
+ .catch(() => undefined));
250
+ if (typeof settings !== 'object' || settings === null)
251
+ return [];
252
+ return ['files.exclude', 'search.exclude'].flatMap((key) => {
253
+ const value = settings[key];
254
+ return typeof value === 'object' && value !== null
255
+ ? Object.entries(value).flatMap(([pattern, enabled]) => (enabled === true ? [pattern] : []))
256
+ : [];
257
+ });
258
+ }
259
+ function isExcluded(path, patterns) {
260
+ return patterns.some((pattern) => minimatch(path, pattern, { dot: true, nocase: hostPlatform() !== 'linux' }) ||
261
+ minimatch(`${path}/`, pattern, { dot: true, nocase: hostPlatform() !== 'linux' }));
262
+ }
263
+ function compareRankedCandidate(left, right) {
264
+ return right.score - left.score || left.entry.path.localeCompare(right.entry.path);
265
+ }
266
+ /** Keeps only the best page-sized candidate set, with the current worst item at the root. */
267
+ class RankedCandidateHeap {
268
+ capacity;
269
+ values = [];
270
+ constructor(capacity) {
271
+ this.capacity = capacity;
272
+ }
273
+ add(candidate) {
274
+ if (this.values.length < this.capacity) {
275
+ this.values.push(candidate);
276
+ this.bubbleUp(this.values.length - 1);
277
+ return;
278
+ }
279
+ if (compareRankedCandidate(candidate, this.values[0]) >= 0)
280
+ return;
281
+ this.values[0] = candidate;
282
+ this.sinkDown(0);
283
+ }
284
+ sorted() {
285
+ return [...this.values].sort(compareRankedCandidate);
286
+ }
287
+ bubbleUp(start) {
288
+ let index = start;
289
+ while (index > 0) {
290
+ const parent = Math.floor((index - 1) / 2);
291
+ if (compareRankedCandidate(this.values[index], this.values[parent]) <= 0)
292
+ break;
293
+ [this.values[index], this.values[parent]] = [
294
+ this.values[parent],
295
+ this.values[index]
296
+ ];
297
+ index = parent;
298
+ }
299
+ }
300
+ sinkDown(start) {
301
+ let index = start;
302
+ while (true) {
303
+ const left = index * 2 + 1;
304
+ if (left >= this.values.length)
305
+ return;
306
+ const right = left + 1;
307
+ const worse = right < this.values.length &&
308
+ compareRankedCandidate(this.values[right], this.values[left]) > 0
309
+ ? right
310
+ : left;
311
+ if (compareRankedCandidate(this.values[worse], this.values[index]) <= 0)
312
+ return;
313
+ [this.values[index], this.values[worse]] = [
314
+ this.values[worse],
315
+ this.values[index]
316
+ ];
317
+ index = worse;
318
+ }
319
+ }
320
+ }
321
+ function fuzzyPathScore(path, query) {
322
+ const source = path.toLocaleLowerCase();
323
+ const needle = query.trim().toLocaleLowerCase();
324
+ let cursor = 0;
325
+ let score = 0;
326
+ let previous = -2;
327
+ for (const character of needle) {
328
+ const index = source.indexOf(character, cursor);
329
+ if (index === -1)
330
+ return -1;
331
+ score += index === previous + 1 ? 12 : 1;
332
+ if (index === 0 || '/._-'.includes(source[index - 1] ?? ''))
333
+ score += 8;
334
+ previous = index;
335
+ cursor = index + 1;
336
+ }
337
+ const name = path.slice(path.lastIndexOf('/') + 1).toLocaleLowerCase();
338
+ if (name.includes(needle))
339
+ score += 40;
340
+ else if (source.includes(needle))
341
+ score += 16;
342
+ return score - path.length / 1_000;
343
+ }
344
+ /**
345
+ * Lists directory names only for the Workspace picker. Browsing begins at the
346
+ * first allowed root when configured, while the Node account home remains a
347
+ * browse boundary and terminal default.
348
+ */
349
+ export async function listWorkspaceDirectories(requestedPath, allowedRoots, homePath = homedir()) {
350
+ const home = await realpath(homePath);
351
+ const roots = await Promise.all(allowedRoots.map((root) => realpath(root)));
352
+ const browseRoots = [...new Set([home, ...roots])];
353
+ const requested = requestedPath === undefined ? (roots[0] ?? home) : await realpath(requestedPath);
354
+ const directory = await stat(requested);
355
+ if (!directory.isDirectory() || !isWithinAllowedRoot(requested, browseRoots))
356
+ throw new Error('WORKSPACE_DIRECTORY_NOT_ALLOWED');
357
+ const children = await readdir(requested, { withFileTypes: true });
358
+ const entries = [];
359
+ for (const child of children.sort((left, right) => left.name.localeCompare(right.name))) {
360
+ if (!child.isDirectory() && !child.isSymbolicLink())
361
+ continue;
362
+ const path = await realpath(resolve(requested, child.name)).catch(() => undefined);
363
+ if (path === undefined || !isWithinAllowedRoot(path, browseRoots))
364
+ continue;
365
+ const metadata = await stat(path).catch(() => undefined);
366
+ if (metadata === undefined || !metadata.isDirectory())
367
+ continue;
368
+ entries.push({ path, name: child.name, selectable: isWithinAllowedRoot(path, roots) });
369
+ if (entries.length > DIRECTORY_PICKER_LIMIT)
370
+ break;
371
+ }
372
+ const parent = dirname(requested);
373
+ return {
374
+ homePath: home,
375
+ currentPath: requested,
376
+ parentPath: parent === requested || !isWithinAllowedRoot(parent, browseRoots) ? null : parent,
377
+ browseRoots: roots,
378
+ selectable: isWithinAllowedRoot(requested, roots),
379
+ entries: entries.slice(0, DIRECTORY_PICKER_LIMIT),
380
+ truncated: entries.length > DIRECTORY_PICKER_LIMIT
381
+ };
382
+ }
383
+ export async function listWorkspaceFiles(workspaceRoot, requestedPath = '.', cursor, limit = DIRECTORY_PAGE_LIMIT) {
384
+ if (!Number.isSafeInteger(limit) || limit < 1 || limit > DIRECTORY_PAGE_LIMIT)
385
+ throw new Error('DIRECTORY_CURSOR_INVALID');
386
+ const root = await resolveRegisteredWorkspaceRoot(workspaceRoot);
387
+ const directory = await resolveWorkspaceEntryFromCanonicalRoot(root, requestedPath, true);
388
+ const entries = await readdir(directory, { withFileTypes: true });
389
+ const cursorValue = decodeDirectoryCursor(cursor, requestedPath);
390
+ const names = entries
391
+ .filter((entry) => entry.name !== '.git' && !isWorkspaceUploadTemporaryName(entry.name))
392
+ .map((entry) => entry.name)
393
+ .sort((left, right) => left.localeCompare(right));
394
+ const start = cursorValue === undefined ? 0 : names.findIndex((name) => name > cursorValue);
395
+ if (cursorValue !== undefined && start === -1)
396
+ return { entries: [], nextCursor: null, truncated: false };
397
+ const pageNames = names.slice(start, start + limit);
398
+ const output = [];
399
+ for (const name of pageNames) {
400
+ const child = await resolveWorkspaceEntry(root, relative(root, resolve(directory, name)), false).catch((error) => {
401
+ if (isSkippableWorkspaceEntryError(error))
402
+ return undefined;
403
+ throw error;
404
+ });
405
+ if (child === undefined)
406
+ continue;
407
+ const metadata = await lstat(child).catch((error) => {
408
+ if (error.code === 'ENOENT')
409
+ return undefined;
410
+ throw error;
411
+ });
412
+ if (metadata === undefined || (!metadata.isFile() && !metadata.isDirectory()))
413
+ continue;
414
+ output.push({
415
+ path: relative(root, child).split(sep).join('/'),
416
+ name,
417
+ kind: metadata.isDirectory() ? 'DIRECTORY' : 'FILE',
418
+ size: metadata.isFile() ? metadata.size : null,
419
+ modifiedAt: metadata.mtimeMs
420
+ });
421
+ }
422
+ const nextName = names[start + pageNames.length];
423
+ return {
424
+ entries: output,
425
+ nextCursor: nextName === undefined || pageNames.length === 0
426
+ ? null
427
+ : encodeDirectoryCursor(requestedPath, pageNames[pageNames.length - 1]),
428
+ truncated: nextName !== undefined
429
+ };
430
+ }
431
+ export async function mutateWorkspaceFile(workspaceRoot, mutation) {
432
+ const root = await resolveRegisteredWorkspaceRoot(workspaceRoot);
433
+ if (mutation.action === 'CREATE_FILE' || mutation.action === 'CREATE_DIRECTORY') {
434
+ const target = await resolveNewWorkspaceEntry(root, mutation.path);
435
+ if (mutation.action === 'CREATE_FILE')
436
+ await writeFile(target, '', { flag: 'wx' });
437
+ else
438
+ await mkdir(target);
439
+ return { path: workspaceRelativePath(root, target) };
440
+ }
441
+ await assertWorkspaceMutationPathHasNoSymlinks(root, mutation.path);
442
+ const source = await resolveWorkspaceEntryMetadata(root, mutation.path);
443
+ if (workspaceRelativePath(root, source.path) === '.')
444
+ throw new Error('FILE_ROOT_MUTATION_INVALID');
445
+ if (mutation.action === 'DELETE') {
446
+ await rm(source.path, { recursive: source.metadata.isDirectory(), force: false });
447
+ return { deleted: true };
448
+ }
449
+ const destination = await resolveNewWorkspaceEntry(root, mutation.destination);
450
+ if (source.metadata.isDirectory()) {
451
+ const destinationFromSource = relative(source.path, destination);
452
+ if (destinationFromSource === '' ||
453
+ (!isAbsolute(destinationFromSource) &&
454
+ destinationFromSource !== '..' &&
455
+ !destinationFromSource.startsWith(`..${sep}`)))
456
+ throw new Error('FILE_MOVE_DESCENDANT_INVALID');
457
+ }
458
+ await rename(source.path, destination);
459
+ return { path: workspaceRelativePath(root, destination) };
460
+ }
461
+ async function resolveNewWorkspaceEntry(root, requestedPath) {
462
+ const normalized = requestedPath.replaceAll('\\', '/');
463
+ const segments = normalized.split('/');
464
+ const name = segments.at(-1);
465
+ if (requestedPath.includes('\0') ||
466
+ normalized.startsWith('/') ||
467
+ isAbsolute(requestedPath) ||
468
+ win32.isAbsolute(normalized) ||
469
+ name === undefined ||
470
+ name.length === 0 ||
471
+ segments.some(invalidWorkspaceMutationSegment))
472
+ throw new Error('FILE_PATH_ESCAPE');
473
+ const parentPath = segments.length === 1 ? '.' : segments.slice(0, -1).join('/');
474
+ await assertWorkspaceMutationPathHasNoSymlinks(root, parentPath);
475
+ const parent = await resolveWorkspaceEntryFromCanonicalRoot(root, parentPath, true);
476
+ const target = resolve(parent, name);
477
+ try {
478
+ await lstat(target);
479
+ throw new Error('FILE_ALREADY_EXISTS');
480
+ }
481
+ catch (error) {
482
+ if (error.code !== 'ENOENT')
483
+ throw error;
484
+ }
485
+ return target;
486
+ }
487
+ async function assertWorkspaceMutationPathHasNoSymlinks(root, requestedPath) {
488
+ const normalized = requestedPath.replaceAll('\\', '/');
489
+ if (normalized === '.')
490
+ return;
491
+ const segments = normalized.split('/');
492
+ if (requestedPath.includes('\0') ||
493
+ normalized.startsWith('/') ||
494
+ isAbsolute(requestedPath) ||
495
+ win32.isAbsolute(normalized) ||
496
+ segments.some(invalidWorkspaceMutationSegment))
497
+ throw new Error('FILE_PATH_ESCAPE');
498
+ let candidate = root;
499
+ for (const segment of segments) {
500
+ candidate = resolve(candidate, segment);
501
+ const metadata = await lstat(candidate).catch((error) => {
502
+ if (error.code === 'ENOENT')
503
+ throw new Error('FILE_NOT_FOUND');
504
+ throw error;
505
+ });
506
+ if (metadata.isSymbolicLink())
507
+ throw new Error('FILE_PATH_ESCAPE');
508
+ }
509
+ }
510
+ function invalidWorkspaceMutationSegment(segment) {
511
+ if (segment.length === 0 || segment === '.' || segment === '..' || segment === '.git')
512
+ return true;
513
+ if (hostPlatform() !== 'win32')
514
+ return false;
515
+ const normalized = segment.replace(/[. ]+$/u, '').toUpperCase();
516
+ return (/[<>:"|?*]/u.test(segment) ||
517
+ /^(?:CON|PRN|AUX|NUL|COM[1-9]|LPT[1-9])(?:\..*)?$/u.test(normalized));
518
+ }
519
+ function workspaceRelativePath(root, path) {
520
+ const value = relative(root, path).split(sep).join('/');
521
+ return value.length === 0 ? '.' : value;
522
+ }
523
+ function isSkippableWorkspaceEntryError(error) {
524
+ return (error instanceof Error &&
525
+ (error.message === 'FILE_PATH_ESCAPE' ||
526
+ error.message === 'FILE_NOT_FOUND' ||
527
+ error.message === 'FILE_NOT_REGULAR'));
528
+ }
529
+ /** Validates an upload destination without following an existing target symlink. */
530
+ export async function preflightWorkspaceUpload(workspaceRoot, requestedDirectory, name) {
531
+ if (name.length === 0 ||
532
+ name === '.' ||
533
+ name === '..' ||
534
+ name.includes('\0') ||
535
+ name.includes('/') ||
536
+ name.includes('\\') ||
537
+ isWorkspaceUploadTemporaryName(name)) {
538
+ return { path: '', absolutePath: '', status: 'INVALID_NAME' };
539
+ }
540
+ const root = await resolveRegisteredWorkspaceRoot(workspaceRoot);
541
+ const directory = await resolveWorkspaceEntry(root, requestedDirectory, true);
542
+ const absolutePath = resolve(directory, name);
543
+ if (dirname(absolutePath) !== directory)
544
+ throw new Error('FILE_PATH_ESCAPE');
545
+ const relativePath = relative(root, absolutePath).split(sep).join('/');
546
+ const metadata = await lstat(absolutePath).catch((error) => {
547
+ if (error.code === 'ENOENT')
548
+ return undefined;
549
+ throw error;
550
+ });
551
+ if (metadata === undefined)
552
+ return { path: relativePath, absolutePath, status: 'READY' };
553
+ if (metadata.isSymbolicLink())
554
+ throw new Error('FILE_PATH_ESCAPE');
555
+ if (metadata.isFile())
556
+ return { path: relativePath, absolutePath, status: 'EXISTS_FILE' };
557
+ return { path: relativePath, absolutePath, status: 'EXISTS_DIRECTORY' };
558
+ }
559
+ export function workspaceUploadTemporaryName(uploadId) {
560
+ return `.mar-upload-${uploadId}.part`;
561
+ }
562
+ function isWorkspaceUploadTemporaryName(name) {
563
+ return (/^\.mar-upload-[0-9a-f-]{36}\.part$/iu.test(name) ||
564
+ /^\.mar-edit-[0-9a-f-]{36}\.part$/iu.test(name));
565
+ }
566
+ export async function readWorkspaceTextFile(workspaceRoot, requestedPath, offset = 0, limit = FILE_READ_LIMIT) {
567
+ if (!Number.isSafeInteger(offset) ||
568
+ offset < 0 ||
569
+ !Number.isSafeInteger(limit) ||
570
+ limit < 1 ||
571
+ limit > FILE_READ_LIMIT)
572
+ throw new Error('FILE_RANGE_INVALID');
573
+ const root = await resolveRegisteredWorkspaceRoot(workspaceRoot);
574
+ const file = await resolveWorkspaceEntry(root, requestedPath, false);
575
+ const metadata = await lstat(file);
576
+ if (!metadata.isFile())
577
+ throw new Error('FILE_NOT_REGULAR');
578
+ if (metadata.size > FILE_READ_LIMIT * 16)
579
+ throw new Error('FILE_TOO_LARGE');
580
+ const source = await readFile(file);
581
+ const revision = createHash('sha256').update(source).digest('hex');
582
+ const binary = source.includes(0) || !isValidUtf8(source);
583
+ if (binary) {
584
+ const end = Math.min(source.length, offset + limit);
585
+ const slice = source.subarray(offset, end);
586
+ return {
587
+ path: relative(root, file).split(sep).join('/'),
588
+ encoding: 'base64',
589
+ size: source.length,
590
+ content: slice.toString('base64'),
591
+ truncated: end < source.length,
592
+ nextOffset: end < source.length ? end : null,
593
+ revision
594
+ };
595
+ }
596
+ if (offset > 0 && offset < source.length && isUtf8ContinuationByte(source[offset]))
597
+ throw new Error('FILE_RANGE_INVALID');
598
+ let end = Math.min(source.length, offset + limit);
599
+ if (end < source.length && isUtf8ContinuationByte(source[end])) {
600
+ while (end > offset && isUtf8ContinuationByte(source[end]))
601
+ end -= 1;
602
+ if (end === offset) {
603
+ end += 1;
604
+ while (end < source.length && isUtf8ContinuationByte(source[end]))
605
+ end += 1;
606
+ }
607
+ }
608
+ const slice = source.subarray(offset, end);
609
+ const content = new TextDecoder('utf-8', { fatal: true }).decode(slice);
610
+ const nextOffset = end < source.length ? end : null;
611
+ return {
612
+ path: relative(root, file).split(sep).join('/'),
613
+ encoding: 'utf-8',
614
+ size: source.length,
615
+ content,
616
+ truncated: nextOffset !== null,
617
+ nextOffset,
618
+ revision
619
+ };
620
+ }
621
+ export async function writeWorkspaceTextFile(workspaceRoot, requestedPath, content, expectedRevision) {
622
+ if (!/^[0-9a-f]{64}$/u.test(expectedRevision))
623
+ throw new Error('FILE_REVISION_INVALID');
624
+ const source = Buffer.from(content, 'utf8');
625
+ if (source.length > FILE_READ_LIMIT * 16)
626
+ throw new Error('FILE_TOO_LARGE');
627
+ if (source.includes(0))
628
+ throw new Error('FILE_NOT_TEXT');
629
+ const root = await resolveRegisteredWorkspaceRoot(workspaceRoot);
630
+ await assertWorkspaceMutationPathHasNoSymlinks(root, requestedPath);
631
+ const file = await resolveWorkspaceEntry(root, requestedPath, false);
632
+ const metadata = await lstat(file);
633
+ if (!metadata.isFile())
634
+ throw new Error('FILE_NOT_REGULAR');
635
+ const current = await readFile(file);
636
+ if (current.includes(0) || !isValidUtf8(current))
637
+ throw new Error('FILE_NOT_TEXT');
638
+ const currentRevision = createHash('sha256').update(current).digest('hex');
639
+ if (currentRevision !== expectedRevision)
640
+ throw new Error('FILE_WRITE_CONFLICT');
641
+ const revision = createHash('sha256').update(source).digest('hex');
642
+ const staging = resolve(dirname(file), `.mar-edit-${randomUUID()}.part`);
643
+ try {
644
+ await writeFile(staging, source, { flag: 'wx', mode: metadata.mode });
645
+ await rename(staging, file);
646
+ }
647
+ finally {
648
+ await rm(staging, { force: true }).catch(() => undefined);
649
+ }
650
+ return { path: workspaceRelativePath(root, file), revision, size: source.length };
651
+ }
652
+ export async function readWorkspaceFileContentRange(workspaceRoot, requestedPath, offset = 0, limit = FILE_READ_LIMIT) {
653
+ if (!Number.isSafeInteger(offset) ||
654
+ offset < 0 ||
655
+ !Number.isSafeInteger(limit) ||
656
+ limit < 1 ||
657
+ limit > FILE_READ_LIMIT)
658
+ throw new Error('FILE_RANGE_INVALID');
659
+ const root = await resolveRegisteredWorkspaceRoot(workspaceRoot);
660
+ const file = await resolveWorkspaceEntry(root, requestedPath, false);
661
+ const metadata = await lstat(file);
662
+ if (!metadata.isFile())
663
+ throw new Error('FILE_NOT_REGULAR');
664
+ if (offset > metadata.size)
665
+ throw new Error('FILE_RANGE_INVALID');
666
+ const length = Math.min(limit, metadata.size - offset);
667
+ const source = Buffer.allocUnsafe(length);
668
+ const handle = await open(file, 'r');
669
+ try {
670
+ const { bytesRead } = await handle.read(source, 0, length, offset);
671
+ const end = offset + bytesRead;
672
+ return {
673
+ path: relative(root, file).split(sep).join('/'),
674
+ size: metadata.size,
675
+ offset,
676
+ contentBase64: source.subarray(0, bytesRead).toString('base64'),
677
+ nextOffset: end < metadata.size ? end : null
678
+ };
679
+ }
680
+ finally {
681
+ await handle.close();
682
+ }
683
+ }
684
+ /** Reads one absolute file range only when the resolved target remains within a preview root. */
685
+ export async function readAllowedFileContentRange(requestedPath, allowedRoots, offset = 0, limit = FILE_READ_LIMIT) {
686
+ if (!Number.isSafeInteger(offset) ||
687
+ offset < 0 ||
688
+ !Number.isSafeInteger(limit) ||
689
+ limit < 1 ||
690
+ limit > FILE_READ_LIMIT)
691
+ throw new Error('FILE_RANGE_INVALID');
692
+ const { file, metadata } = await resolveAllowedFile(requestedPath, allowedRoots);
693
+ if (offset > metadata.size)
694
+ throw new Error('FILE_RANGE_INVALID');
695
+ const length = Math.min(limit, metadata.size - offset);
696
+ const source = Buffer.allocUnsafe(length);
697
+ const handle = await open(file, 'r');
698
+ try {
699
+ const { bytesRead } = await handle.read(source, 0, length, offset);
700
+ const end = offset + bytesRead;
701
+ return {
702
+ path: file,
703
+ size: metadata.size,
704
+ offset,
705
+ contentBase64: source.subarray(0, bytesRead).toString('base64'),
706
+ nextOffset: end < metadata.size ? end : null
707
+ };
708
+ }
709
+ finally {
710
+ await handle.close();
711
+ }
712
+ }
713
+ /** Reads one absolute file only when the resolved target remains within a preview root. */
714
+ export async function readAllowedTextFile(requestedPath, allowedRoots, offset = 0, limit = FILE_READ_LIMIT) {
715
+ const { file, metadata } = await resolveAllowedFile(requestedPath, allowedRoots);
716
+ if (metadata.size > FILE_READ_LIMIT * 16)
717
+ throw new Error('FILE_TOO_LARGE');
718
+ if (!Number.isSafeInteger(offset) ||
719
+ offset < 0 ||
720
+ !Number.isSafeInteger(limit) ||
721
+ limit < 1 ||
722
+ limit > FILE_READ_LIMIT)
723
+ throw new Error('FILE_RANGE_INVALID');
724
+ const source = await readFile(file);
725
+ const binary = source.includes(0) || !isValidUtf8(source);
726
+ const end = Math.min(source.length, offset + limit);
727
+ if (binary) {
728
+ const slice = source.subarray(offset, end);
729
+ return {
730
+ path: file,
731
+ encoding: 'base64',
732
+ size: source.length,
733
+ content: slice.toString('base64'),
734
+ truncated: end < source.length,
735
+ nextOffset: end < source.length ? end : null
736
+ };
737
+ }
738
+ if (offset > 0 && offset < source.length && isUtf8ContinuationByte(source[offset]))
739
+ throw new Error('FILE_RANGE_INVALID');
740
+ let textEnd = end;
741
+ if (textEnd < source.length && isUtf8ContinuationByte(source[textEnd])) {
742
+ while (textEnd > offset && isUtf8ContinuationByte(source[textEnd]))
743
+ textEnd -= 1;
744
+ if (textEnd === offset) {
745
+ textEnd += 1;
746
+ while (textEnd < source.length && isUtf8ContinuationByte(source[textEnd]))
747
+ textEnd += 1;
748
+ }
749
+ }
750
+ const nextOffset = textEnd < source.length ? textEnd : null;
751
+ return {
752
+ path: file,
753
+ encoding: 'utf-8',
754
+ size: source.length,
755
+ content: new TextDecoder('utf-8', { fatal: true }).decode(source.subarray(offset, textEnd)),
756
+ truncated: nextOffset !== null,
757
+ nextOffset
758
+ };
759
+ }
760
+ export function normalizeFilePreviewPath(requestedPath) {
761
+ if (!/^sandbox:/iu.test(requestedPath))
762
+ return requestedPath;
763
+ let decoded;
764
+ try {
765
+ decoded = decodeURIComponent(requestedPath.slice(requestedPath.indexOf(':') + 1));
766
+ }
767
+ catch {
768
+ throw new Error('FILE_PATH_ESCAPE');
769
+ }
770
+ const normalized = decoded.replace(/^\/([a-z]:[\\/])/iu, '$1');
771
+ if (normalized.length === 0 ||
772
+ /^[\\/]{2,}[?.](?:[\\/]|$)/u.test(decoded) ||
773
+ (!isAbsolute(normalized) && !win32.isAbsolute(normalized)) ||
774
+ normalized.includes('\0') ||
775
+ normalized.includes('?') ||
776
+ normalized.includes('#'))
777
+ throw new Error('FILE_PATH_ESCAPE');
778
+ return normalized;
779
+ }
780
+ async function resolveAllowedFile(requestedPath, allowedRoots) {
781
+ if (!isAbsolute(requestedPath))
782
+ throw new Error('FILE_PATH_ESCAPE');
783
+ const file = await realpath(requestedPath).catch((error) => {
784
+ if (error.code === 'ENOENT')
785
+ throw new Error('FILE_NOT_FOUND');
786
+ throw error;
787
+ });
788
+ const roots = await Promise.all(allowedRoots.map((root) => realpath(root)));
789
+ if (!isWithinAllowedRoot(file, roots))
790
+ throw new Error('FILE_PATH_ESCAPE');
791
+ const metadata = await lstat(file);
792
+ if (!metadata.isFile())
793
+ throw new Error('FILE_NOT_REGULAR');
794
+ return { file, metadata };
795
+ }
796
+ function isValidUtf8(source) {
797
+ try {
798
+ new TextDecoder('utf-8', { fatal: true }).decode(source);
799
+ return true;
800
+ }
801
+ catch {
802
+ return false;
803
+ }
804
+ }
805
+ function isUtf8ContinuationByte(value) {
806
+ return (value & 0b1100_0000) === 0b1000_0000;
807
+ }
808
+ /** Searches file names only, so an exploratory request cannot exfiltrate file contents. */
809
+ export async function searchWorkspaceFiles(workspaceRoot, query, cursor, limit = SEARCH_RESULT_LIMIT, includeDirectories = false) {
810
+ const index = new WorkspaceFileIndex(workspaceRoot);
811
+ try {
812
+ return await index.search(query, cursor, limit, includeDirectories);
813
+ }
814
+ finally {
815
+ index.dispose();
816
+ }
817
+ }
818
+ async function resolveRegisteredWorkspaceRoot(workspaceRoot) {
819
+ const root = await realpath(workspaceRoot);
820
+ if (normalizeWorkspacePath(root) !== normalizeWorkspacePath(workspaceRoot))
821
+ throw new Error('WORKSPACE_NOT_ALLOWED');
822
+ return root;
823
+ }
824
+ async function resolveWorkspaceEntry(workspaceRoot, requestedPath, directory) {
825
+ const root = await resolveRegisteredWorkspaceRoot(workspaceRoot);
826
+ return resolveWorkspaceEntryFromCanonicalRoot(root, requestedPath, directory);
827
+ }
828
+ async function resolveWorkspaceEntryFromCanonicalRoot(root, requestedPath, directory) {
829
+ const entry = await resolveWorkspaceEntryMetadata(root, requestedPath);
830
+ if (directory
831
+ ? !entry.metadata.isDirectory()
832
+ : !entry.metadata.isFile() && !entry.metadata.isDirectory())
833
+ throw new Error(directory ? 'FILE_NOT_DIRECTORY' : 'FILE_NOT_REGULAR');
834
+ return entry.path;
835
+ }
836
+ async function resolveWorkspaceEntryMetadata(root, requestedPath) {
837
+ if (requestedPath.includes('\0') ||
838
+ requestedPath.length === 0 ||
839
+ requestedPath.startsWith('/') ||
840
+ requestedPath.startsWith('\\'))
841
+ throw new Error('FILE_PATH_ESCAPE');
842
+ const normalized = requestedPath.replaceAll('\\', '/');
843
+ if (normalized.split('/').some((segment) => segment === '..' || segment === '.git'))
844
+ throw new Error('FILE_PATH_ESCAPE');
845
+ let candidate;
846
+ try {
847
+ candidate = await realpath(resolve(root, normalized));
848
+ }
849
+ catch (error) {
850
+ if (error.code === 'ENOENT')
851
+ throw new Error('FILE_NOT_FOUND');
852
+ throw error;
853
+ }
854
+ const pathToCandidate = relative(root, candidate);
855
+ if (isAbsolute(pathToCandidate) ||
856
+ pathToCandidate.startsWith('..') ||
857
+ pathToCandidate === '..' ||
858
+ pathToCandidate.startsWith(`..${sep}`))
859
+ throw new Error('FILE_PATH_ESCAPE');
860
+ const metadata = await lstat(candidate);
861
+ return { path: candidate, metadata };
862
+ }
863
+ async function inspectWorkspaceIndexEntry(root, requestedPath, name) {
864
+ try {
865
+ const entry = await resolveWorkspaceEntryMetadata(root, requestedPath);
866
+ if (!entry.metadata.isFile() && !entry.metadata.isDirectory())
867
+ return undefined;
868
+ const safePath = relative(root, entry.path).split(sep).join('/');
869
+ return entry.metadata.isDirectory()
870
+ ? {
871
+ path: safePath,
872
+ name,
873
+ kind: 'DIRECTORY',
874
+ size: null,
875
+ modifiedAt: entry.metadata.mtimeMs
876
+ }
877
+ : {
878
+ path: safePath,
879
+ name,
880
+ kind: 'FILE',
881
+ size: entry.metadata.size,
882
+ modifiedAt: entry.metadata.mtimeMs
883
+ };
884
+ }
885
+ catch {
886
+ return undefined;
887
+ }
888
+ }
889
+ function encodeDirectoryCursor(path, name) {
890
+ return Buffer.from(JSON.stringify({ path, name })).toString('base64url');
891
+ }
892
+ function decodeDirectoryCursor(cursor, expectedPath) {
893
+ if (cursor === undefined)
894
+ return undefined;
895
+ try {
896
+ const value = JSON.parse(Buffer.from(cursor, 'base64url').toString('utf8'));
897
+ if (typeof value !== 'object' ||
898
+ value === null ||
899
+ value.path !== expectedPath ||
900
+ typeof value.name !== 'string')
901
+ throw new Error();
902
+ return value.name;
903
+ }
904
+ catch {
905
+ throw new Error('DIRECTORY_CURSOR_INVALID');
906
+ }
907
+ }
908
+ function encodeSearchCursor(query, path) {
909
+ return Buffer.from(JSON.stringify({ query, path })).toString('base64url');
910
+ }
911
+ function decodeSearchCursor(cursor, expectedQuery) {
912
+ if (cursor === undefined)
913
+ return undefined;
914
+ try {
915
+ const value = JSON.parse(Buffer.from(cursor, 'base64url').toString('utf8'));
916
+ if (typeof value !== 'object' ||
917
+ value === null ||
918
+ value.query !== expectedQuery ||
919
+ typeof value.path !== 'string')
920
+ throw new Error();
921
+ return value.path;
922
+ }
923
+ catch {
924
+ throw new Error('DIRECTORY_CURSOR_INVALID');
925
+ }
926
+ }
927
+ export function normalizeWorkspacePath(input, platform = hostPlatform()) {
928
+ if (input.length === 0 || input.includes('\u0000')) {
929
+ throw new Error('WORKSPACE_PATH_INVALID');
930
+ }
931
+ if (platform === 'win32') {
932
+ // Device paths bypass normal Win32 resolution and must never be accepted.
933
+ if (/^\\\\[?.]/.test(input)) {
934
+ throw new Error('WORKSPACE_DEVICE_PATH_REJECTED');
935
+ }
936
+ const normalized = win32.normalize(input.replaceAll('/', '\\'));
937
+ if (!win32.isAbsolute(normalized)) {
938
+ throw new Error('WORKSPACE_PATH_NOT_ABSOLUTE');
939
+ }
940
+ return normalized.replace(/\\+$/, '').toLowerCase();
941
+ }
942
+ if (platform !== 'linux' && platform !== 'darwin') {
943
+ throw new Error('WORKSPACE_PLATFORM_UNSUPPORTED');
944
+ }
945
+ const normalized = posix.normalize(input);
946
+ if (!posix.isAbsolute(normalized)) {
947
+ throw new Error('WORKSPACE_PATH_NOT_ABSOLUTE');
948
+ }
949
+ return normalized === '/' ? normalized : normalized.replace(/\/+$/, '');
950
+ }
951
+ export function isWithinAllowedRoot(target, roots, platform = hostPlatform()) {
952
+ const normalizedTarget = normalizeWorkspacePath(target, platform);
953
+ const pathApi = platform === 'win32' ? win32 : posix;
954
+ return roots.some((root) => {
955
+ const normalizedRoot = normalizeWorkspacePath(root, platform);
956
+ const relative = pathApi.relative(normalizedRoot, normalizedTarget);
957
+ return relative === '' || (!relative.startsWith('..') && !pathApi.isAbsolute(relative));
958
+ });
959
+ }
960
+ /** Resolving both candidate and roots rejects Linux symlinks which point outside a root. */
961
+ export async function inspectWorkspace(requestedPath, allowedRoots) {
962
+ const resolvedPath = await realpath(requestedPath);
963
+ const resolvedRoots = await Promise.all(allowedRoots.map((root) => realpath(root)));
964
+ const directory = await stat(resolvedPath);
965
+ if (!directory.isDirectory() || !isWithinAllowedRoot(resolvedPath, resolvedRoots)) {
966
+ throw new Error('WORKSPACE_NOT_ALLOWED');
967
+ }
968
+ try {
969
+ const summary = await readGitSummary(resolvedPath);
970
+ return { path: resolvedPath, kind: 'GIT_WORKSPACE', gitSummary: summary };
971
+ }
972
+ catch (error) {
973
+ if ((error instanceof GitCommandError && error.code === 128) || isGitUnavailable(error)) {
974
+ return { path: resolvedPath, kind: 'DIRECTORY' };
975
+ }
976
+ throw error;
977
+ }
978
+ }
979
+ export async function readGitSummary(workspacePath) {
980
+ const commonDir = (await runReadOnlyGit(workspacePath, ['rev-parse', '--git-common-dir'])).text.trim();
981
+ const headResult = await runReadOnlyGitAllowFailure(workspacePath, [
982
+ 'rev-parse',
983
+ '--verify',
984
+ 'HEAD'
985
+ ]);
986
+ const branchResult = await runReadOnlyGitAllowFailure(workspacePath, [
987
+ 'symbolic-ref',
988
+ '--quiet',
989
+ '--short',
990
+ 'HEAD'
991
+ ]);
992
+ const statusOptions = {
993
+ timeoutMs: GIT_STATUS_TIMEOUT_MS,
994
+ outputLimit: GIT_LARGE_OUTPUT_LIMIT
995
+ };
996
+ const status = await runReadOnlyGit(workspacePath, ['status', '--porcelain=v1'], statusOptions);
997
+ return {
998
+ commonDir,
999
+ head: headResult.code === 0 ? headResult.text.trim() : '',
1000
+ branch: branchResult.code === 0 ? branchResult.text.trim() : null,
1001
+ dirty: status.output.length > 0,
1002
+ snapshot: summarizeText(status.text)
1003
+ };
1004
+ }
1005
+ export function assertSafeGitRef(ref) {
1006
+ if (!REF_PATTERN.test(ref)) {
1007
+ throw new Error('GIT_REF_INVALID');
1008
+ }
1009
+ }
1010
+ export async function readRestrictedDiff(workspacePath, fromRef, toRef) {
1011
+ assertSafeGitRef(fromRef);
1012
+ assertSafeGitRef(toRef);
1013
+ const result = await runReadOnlyGit(workspacePath, [
1014
+ 'diff',
1015
+ '--no-ext-diff',
1016
+ '--no-textconv',
1017
+ fromRef,
1018
+ toRef
1019
+ ]);
1020
+ const binary = result.output.includes(0) || result.text.includes('Binary files ');
1021
+ if (binary) {
1022
+ return {
1023
+ binary: true,
1024
+ summary: `binary diff sha256=${createHash('sha256').update(result.output).digest('hex')} bytes=${result.output.length}`,
1025
+ truncated: result.truncated
1026
+ };
1027
+ }
1028
+ return { binary: false, text: result.text, truncated: result.truncated };
1029
+ }
1030
+ function currentBranchFromStatusHeader(header) {
1031
+ const value = header.slice(3);
1032
+ if (value.startsWith('HEAD '))
1033
+ return null;
1034
+ const unborn = /^(?:No commits yet on|Initial commit on) (.+)$/.exec(value);
1035
+ if (unborn !== null)
1036
+ return unborn[1] ?? null;
1037
+ return value.split('...')[0]?.split(' ')[0] ?? null;
1038
+ }
1039
+ export async function listGitWorktrees(workspacePath) {
1040
+ const options = {
1041
+ timeoutMs: GIT_STATUS_TIMEOUT_MS,
1042
+ outputLimit: GIT_LARGE_OUTPUT_LIMIT
1043
+ };
1044
+ const nulDelimited = await runReadOnlyGitAllowFailure(workspacePath, ['worktree', 'list', '--porcelain', '-z'], options);
1045
+ if (nulDelimited.code === 0)
1046
+ return parseGitWorktreeList(workspacePath, nulDelimited, true);
1047
+ if (!canRetryGitWorktreeListWithoutNullOutput(nulDelimited))
1048
+ throw new GitCommandError(nulDelimited.code, nulDelimited.stderr);
1049
+ const lineDelimited = await runReadOnlyGit(workspacePath, ['worktree', 'list', '--porcelain'], options);
1050
+ return parseGitWorktreeList(workspacePath, lineDelimited, false);
1051
+ }
1052
+ async function parseGitWorktreeList(workspacePath, result, nulDelimited) {
1053
+ const currentPath = normalizeWorkspacePath(await realpath(workspacePath));
1054
+ const entries = [];
1055
+ let truncated = result.truncated;
1056
+ const groups = nulDelimited ? result.text.split('\0\0') : result.text.split(/\r?\n\r?\n/);
1057
+ for (const group of groups) {
1058
+ if (group.length === 0)
1059
+ continue;
1060
+ if (entries.length >= GIT_WORKTREE_LIST_LIMIT) {
1061
+ truncated = true;
1062
+ break;
1063
+ }
1064
+ const fields = (nulDelimited ? group.split('\0') : group.split(/\r?\n/)).filter((field) => field.length > 0);
1065
+ if (!nulDelimited &&
1066
+ fields.some((field) => !(field.startsWith('worktree ') ||
1067
+ field.startsWith('HEAD ') ||
1068
+ field.startsWith('branch ') ||
1069
+ field === 'bare' ||
1070
+ field === 'detached' ||
1071
+ field === 'locked' ||
1072
+ field.startsWith('locked ') ||
1073
+ field === 'prunable' ||
1074
+ field.startsWith('prunable ')))) {
1075
+ throw new Error('GIT_WORKTREE_LIST_INVALID');
1076
+ }
1077
+ if (fields.some((field) => field === 'bare'))
1078
+ continue;
1079
+ const pathField = fields.find((field) => field.startsWith('worktree '));
1080
+ const headField = fields.find((field) => field.startsWith('HEAD '));
1081
+ const path = pathField?.slice('worktree '.length);
1082
+ const head = headField?.slice('HEAD '.length);
1083
+ if (path === undefined ||
1084
+ path.length === 0 ||
1085
+ head === undefined ||
1086
+ !/^[0-9a-f]{40,64}$/u.test(head)) {
1087
+ if (result.truncated) {
1088
+ truncated = true;
1089
+ continue;
1090
+ }
1091
+ throw new Error('GIT_WORKTREE_LIST_INVALID');
1092
+ }
1093
+ const branchField = fields.find((field) => field.startsWith('branch '));
1094
+ const branchRef = branchField?.slice('branch '.length);
1095
+ const branch = branchRef === undefined
1096
+ ? null
1097
+ : branchRef.startsWith('refs/heads/')
1098
+ ? branchRef.slice('refs/heads/'.length)
1099
+ : branchRef;
1100
+ const directoryName = (basename(path).trim() || branch || head.slice(0, 12)).slice(0, 512);
1101
+ entries.push({
1102
+ path,
1103
+ directoryName,
1104
+ branch,
1105
+ head,
1106
+ current: normalizeWorkspacePath(path) === currentPath,
1107
+ locked: fields.some((field) => field === 'locked' || field.startsWith('locked ')),
1108
+ prunable: fields.some((field) => field === 'prunable' || field.startsWith('prunable '))
1109
+ });
1110
+ }
1111
+ return { entries, truncated };
1112
+ }
1113
+ export async function readCurrentChangesSummary(workspacePath, isolateSubmoduleFailures = false) {
1114
+ const args = ['status', '--porcelain=v1', '-z', '--branch', '--untracked-files=all'];
1115
+ const options = { timeoutMs: GIT_STATUS_TIMEOUT_MS, outputLimit: GIT_LARGE_OUTPUT_LIMIT };
1116
+ const result = await runReadOnlyGit(workspacePath, args, options).catch((error) => {
1117
+ if (!isolateSubmoduleFailures || !(error instanceof GitCommandError))
1118
+ throw error;
1119
+ // Validate root facts independently when descending into a damaged child fails.
1120
+ // A second failure remains a repository failure, never an empty success.
1121
+ return runReadOnlyGit(workspacePath, [...args, '--ignore-submodules=dirty'], options);
1122
+ });
1123
+ const records = result.text.split('\0');
1124
+ const header = records.shift() ?? '';
1125
+ const output = [];
1126
+ for (let index = 0; index < records.length; index += 1) {
1127
+ const record = records[index];
1128
+ if (record.length < 4)
1129
+ continue;
1130
+ const indexState = record[0];
1131
+ const worktreeState = record[1];
1132
+ const path = record.slice(3);
1133
+ if (indexState === '?' && worktreeState === '?') {
1134
+ output.push({ path, state: 'UNTRACKED', change: 'ADDED' });
1135
+ continue;
1136
+ }
1137
+ if (indexState !== ' ') {
1138
+ output.push({ path, state: 'STAGED', change: gitChange(indexState) });
1139
+ }
1140
+ if (worktreeState !== ' ') {
1141
+ output.push({ path, state: 'UNSTAGED', change: gitChange(worktreeState) });
1142
+ }
1143
+ // Porcelain v1 -z emits a second NUL-delimited source path for rename
1144
+ // and copy records. It is metadata for the same entry, never another
1145
+ // status record.
1146
+ if (indexState === 'R' || indexState === 'C' || worktreeState === 'R' || worktreeState === 'C')
1147
+ index += 1;
1148
+ }
1149
+ return {
1150
+ branch: header.startsWith('## ') ? currentBranchFromStatusHeader(header) : null,
1151
+ changes: output
1152
+ };
1153
+ }
1154
+ export async function listGitSubmodules(workspacePath) {
1155
+ const result = await runReadOnlyGit(workspacePath, ['ls-files', '--stage', '-z'], {
1156
+ timeoutMs: GIT_STATUS_TIMEOUT_MS,
1157
+ outputLimit: GIT_LARGE_OUTPUT_LIMIT
1158
+ });
1159
+ if (result.truncated)
1160
+ throw new Error('GIT_SUBMODULE_DISCOVERY_TRUNCATED');
1161
+ const paths = [
1162
+ ...new Set(result.text.split('\0').flatMap((record) => {
1163
+ const match = /^160000 [0-9a-f]+ [0-3]\t([\s\S]+)$/.exec(record);
1164
+ return match?.[1] === undefined ? [] : [match[1]];
1165
+ }))
1166
+ ].sort((left, right) => left.localeCompare(right));
1167
+ if (paths.length === 0)
1168
+ return [];
1169
+ const unavailable = (mapping, gitExitCode) => paths.map((path) => ({ path, mapping, ...(gitExitCode === undefined ? {} : { gitExitCode }) }));
1170
+ try {
1171
+ const modulesFile = await lstat(resolve(workspacePath, '.gitmodules'));
1172
+ if (!modulesFile.isFile() || modulesFile.isSymbolicLink())
1173
+ return unavailable('INVALID');
1174
+ }
1175
+ catch (error) {
1176
+ return unavailable(error.code === 'ENOENT' ? 'MISSING' : 'INVALID');
1177
+ }
1178
+ const mappings = await runReadOnlyGitAllowFailure(workspacePath, ['config', '--null', '--file', '.gitmodules', '--get-regexp', '^submodule\\..*\\.(path|url)$'], { outputLimit: GIT_LARGE_OUTPUT_LIMIT });
1179
+ if (mappings.truncated || (mappings.code !== 0 && mappings.code !== 1))
1180
+ return unavailable('INVALID', mappings.code);
1181
+ const byName = new Map();
1182
+ for (const entry of mappings.text.split('\0')) {
1183
+ const separator = entry.indexOf('\n');
1184
+ if (separator < 0)
1185
+ continue;
1186
+ const key = entry.slice(0, separator);
1187
+ const value = entry.slice(separator + 1);
1188
+ const match = /^submodule\.(.*)\.(path|url)$/.exec(key);
1189
+ if (match?.[1] === undefined)
1190
+ continue;
1191
+ const mapping = byName.get(match[1]) ?? {};
1192
+ if (match[2] === 'path')
1193
+ mapping.path = value;
1194
+ else
1195
+ mapping.hasUrl = value.trim().length > 0;
1196
+ byName.set(match[1], mapping);
1197
+ }
1198
+ const mappedPaths = new Set([...byName.values()].flatMap((mapping) => mapping.path !== undefined && mapping.hasUrl ? [mapping.path] : []));
1199
+ return paths.map((path) => ({ path, mapping: mappedPaths.has(path) ? 'MAPPED' : 'MISSING' }));
1200
+ }
1201
+ export async function resolveGitRepository(workspacePath, repositoryPath, initializedSubmodulePaths) {
1202
+ const root = await realpath(workspacePath);
1203
+ if (repositoryPath.length === 0)
1204
+ return root;
1205
+ if (repositoryPath.includes('\0') ||
1206
+ repositoryPath.startsWith('/') ||
1207
+ repositoryPath.startsWith('\\') ||
1208
+ repositoryPath
1209
+ .split('/')
1210
+ .some((segment) => segment.length === 0 || segment === '.' || segment === '..'))
1211
+ throw new Error('GIT_REPOSITORY_INVALID');
1212
+ try {
1213
+ const requestedRepository = resolve(root, repositoryPath);
1214
+ const repository = await realpath(requestedRepository);
1215
+ if (normalizeWorkspacePath(requestedRepository) !== normalizeWorkspacePath(repository) ||
1216
+ !isWithinAllowedRoot(repository, [root]))
1217
+ throw new Error('invalid');
1218
+ if (initializedSubmodulePaths !== undefined) {
1219
+ if (!initializedSubmodulePaths.includes(repositoryPath))
1220
+ throw new Error('invalid');
1221
+ return repository;
1222
+ }
1223
+ await assertGitSuperprojectChain(root, repository);
1224
+ return repository;
1225
+ }
1226
+ catch {
1227
+ throw new Error('GIT_REPOSITORY_INVALID');
1228
+ }
1229
+ }
1230
+ export async function resolveGitRepositoryTarget(workspacePath, repositoryPath, worktreePath, initializedSubmodulePaths) {
1231
+ if (worktreePath === undefined)
1232
+ return resolveGitRepository(workspacePath, repositoryPath, initializedSubmodulePaths);
1233
+ if (repositoryPath.length !== 0 ||
1234
+ worktreePath.length === 0 ||
1235
+ worktreePath.length > 4096 ||
1236
+ worktreePath.includes('\0'))
1237
+ throw new Error('GIT_REPOSITORY_INVALID');
1238
+ const requestedKey = normalizeWorkspacePath(worktreePath);
1239
+ const worktrees = await listGitWorktrees(workspacePath);
1240
+ const matched = worktrees.entries.find((entry) => normalizeWorkspacePath(entry.path) === requestedKey);
1241
+ if (matched === undefined || matched.prunable)
1242
+ throw new Error('GIT_REPOSITORY_INVALID');
1243
+ try {
1244
+ return await realpath(matched.path);
1245
+ }
1246
+ catch {
1247
+ throw new Error('GIT_REPOSITORY_INVALID');
1248
+ }
1249
+ }
1250
+ async function assertGitSuperprojectChain(root, repository) {
1251
+ const rootKey = normalizeWorkspacePath(root);
1252
+ let current = repository;
1253
+ const visited = new Set();
1254
+ for (let depth = 0; depth < 64; depth += 1) {
1255
+ const currentKey = normalizeWorkspacePath(current);
1256
+ if (currentKey === rootKey)
1257
+ return;
1258
+ if (visited.has(currentKey))
1259
+ throw new Error('invalid');
1260
+ visited.add(currentKey);
1261
+ const result = await runReadOnlyGit(current, [
1262
+ 'rev-parse',
1263
+ '--show-toplevel',
1264
+ '--show-superproject-working-tree'
1265
+ ]);
1266
+ const [topLevel, superproject] = result.text.split(/\r?\n/);
1267
+ if (topLevel === undefined || superproject === undefined || superproject.length === 0)
1268
+ throw new Error('invalid');
1269
+ const resolvedTopLevel = await realpath(topLevel);
1270
+ const resolvedSuperproject = await realpath(superproject);
1271
+ if (normalizeWorkspacePath(resolvedTopLevel) !== currentKey ||
1272
+ normalizeWorkspacePath(resolvedSuperproject) === currentKey ||
1273
+ !isWithinAllowedRoot(resolvedSuperproject, [root]) ||
1274
+ !isWithinAllowedRoot(current, [resolvedSuperproject]))
1275
+ throw new Error('invalid');
1276
+ current = resolvedSuperproject;
1277
+ }
1278
+ throw new Error('invalid');
1279
+ }
1280
+ export async function listGitHistoryRefs(repository) {
1281
+ const result = await runReadOnlyGit(repository, [
1282
+ 'for-each-ref',
1283
+ '--format=%(refname)%09%(refname:short)%09%(objectname)%09%(HEAD)%09%(symref)',
1284
+ 'refs/heads',
1285
+ 'refs/remotes'
1286
+ ], {
1287
+ timeoutMs: GIT_HISTORY_TIMEOUT_MS,
1288
+ outputLimit: GIT_LARGE_OUTPUT_LIMIT
1289
+ });
1290
+ return result.text
1291
+ .split(/\r?\n/)
1292
+ .flatMap((line) => {
1293
+ const [name, displayName, hash, head, symref] = line.split('\t');
1294
+ if (name === undefined ||
1295
+ displayName === undefined ||
1296
+ hash === undefined ||
1297
+ symref === undefined ||
1298
+ symref.length > 0 ||
1299
+ !/^[0-9a-f]{40,64}$/.test(hash))
1300
+ return [];
1301
+ const kind = name.startsWith('refs/heads/')
1302
+ ? 'LOCAL'
1303
+ : name.startsWith('refs/remotes/')
1304
+ ? 'REMOTE'
1305
+ : undefined;
1306
+ return kind === undefined ? [] : [{ name, displayName, kind, hash, current: head === '*' }];
1307
+ })
1308
+ .sort((left, right) => left.kind.localeCompare(right.kind) || left.displayName.localeCompare(right.displayName));
1309
+ }
1310
+ function selectedHistoryRefs(available, requested) {
1311
+ if (requested === undefined || requested.length === 0)
1312
+ return available;
1313
+ const unique = [...new Set(requested)];
1314
+ const selected = unique.map((name) => available.find((entry) => entry.name === name));
1315
+ if (selected.some((entry) => entry === undefined))
1316
+ throw new Error('GIT_HISTORY_REF_INVALID');
1317
+ return selected;
1318
+ }
1319
+ function historyCursor(offset, fingerprint) {
1320
+ return Buffer.from(JSON.stringify({ offset, fingerprint })).toString('base64url');
1321
+ }
1322
+ function parseHistoryCursor(value, fingerprint) {
1323
+ if (value === undefined)
1324
+ return 0;
1325
+ try {
1326
+ const parsed = JSON.parse(Buffer.from(value, 'base64url').toString('utf8'));
1327
+ if (!Number.isInteger(parsed.offset) ||
1328
+ parsed.offset < 0 ||
1329
+ parsed.fingerprint !== fingerprint)
1330
+ throw new Error('invalid');
1331
+ return parsed.offset;
1332
+ }
1333
+ catch {
1334
+ throw new Error('GIT_HISTORY_CURSOR_INVALID');
1335
+ }
1336
+ }
1337
+ export async function readGitHistory(repository, input) {
1338
+ const available = await listGitHistoryRefs(repository);
1339
+ const selected = selectedHistoryRefs(available, input.refs);
1340
+ if (selected.length === 0)
1341
+ return { commits: [], nextCursor: null };
1342
+ const limit = input.limit ?? 50;
1343
+ if (!Number.isInteger(limit) || limit < 1 || limit > 100)
1344
+ throw new Error('GIT_HISTORY_LIMIT_INVALID');
1345
+ const names = selected.map((entry) => entry.name).sort();
1346
+ const allBranchesSelected = input.refs === undefined ||
1347
+ input.refs.length === 0 ||
1348
+ (selected.length === available.length &&
1349
+ selected.every((entry) => available.some((candidate) => candidate.name === entry.name)));
1350
+ const revisionArguments = allBranchesSelected ? ['--branches', '--remotes'] : names;
1351
+ // Bind the offset cursor to the exact branch tips. Advancing a branch invalidates
1352
+ // the cursor instead of silently skipping or duplicating commits between pages.
1353
+ const fingerprint = createHash('sha256')
1354
+ .update(selected
1355
+ .map((entry) => `${entry.name}\0${entry.hash}`)
1356
+ .sort()
1357
+ .join('\0'))
1358
+ .digest('hex');
1359
+ const offset = parseHistoryCursor(input.cursor, fingerprint);
1360
+ const result = await runReadOnlyGit(repository, [
1361
+ 'log',
1362
+ '--topo-order',
1363
+ '--date-order',
1364
+ `--skip=${offset}`,
1365
+ `--max-count=${limit + 1}`,
1366
+ '-z',
1367
+ '--format=%H%x00%P%x00%an%x00%ae%x00%ct%x00%s',
1368
+ ...revisionArguments,
1369
+ '--'
1370
+ ], { timeoutMs: GIT_HISTORY_TIMEOUT_MS });
1371
+ const refsByHash = new Map();
1372
+ for (const entry of available) {
1373
+ const refs = refsByHash.get(entry.hash) ?? [];
1374
+ refs.push(entry.displayName);
1375
+ refsByHash.set(entry.hash, refs);
1376
+ }
1377
+ const fields = result.text.split('\0');
1378
+ const commits = [];
1379
+ for (let index = 0; index + 5 < fields.length; index += 6) {
1380
+ const [hash, parents = '', authorName = '', authorEmail = '', committedAt = '0', subject = ''] = fields.slice(index, index + 6);
1381
+ if (hash === undefined || !/^[0-9a-f]{40,64}$/.test(hash))
1382
+ continue;
1383
+ commits.push({
1384
+ hash,
1385
+ parents: parents.length === 0 ? [] : parents.split(' '),
1386
+ authorName,
1387
+ authorEmail,
1388
+ committedAt: Number(committedAt) * 1000,
1389
+ subject,
1390
+ refs: refsByHash.get(hash) ?? []
1391
+ });
1392
+ }
1393
+ const hasMore = commits.length > limit;
1394
+ return {
1395
+ commits: commits.slice(0, limit),
1396
+ nextCursor: hasMore ? historyCursor(offset + limit, fingerprint) : null
1397
+ };
1398
+ }
1399
+ async function assertHistoryCommitReachable(repository, commit, refs) {
1400
+ if (!/^[0-9a-f]{40,64}$/.test(commit))
1401
+ throw new Error('GIT_HISTORY_COMMIT_INVALID');
1402
+ const selected = selectedHistoryRefs(await listGitHistoryRefs(repository), refs);
1403
+ for (const ref of selected) {
1404
+ const result = await runReadOnlyGitAllowFailure(repository, [
1405
+ 'merge-base',
1406
+ '--is-ancestor',
1407
+ commit,
1408
+ ref.name
1409
+ ]);
1410
+ if (result.code === 0)
1411
+ return;
1412
+ }
1413
+ throw new Error('GIT_HISTORY_COMMIT_INVALID');
1414
+ }
1415
+ export async function readGitHistoryFiles(repository, commit, refs) {
1416
+ await assertHistoryCommitReachable(repository, commit, refs);
1417
+ const result = await runReadOnlyGit(repository, [
1418
+ 'diff-tree',
1419
+ '--root',
1420
+ '--first-parent',
1421
+ '--no-commit-id',
1422
+ '-r',
1423
+ '-z',
1424
+ '-M',
1425
+ '-C',
1426
+ '--name-status',
1427
+ commit
1428
+ ], {
1429
+ timeoutMs: GIT_STATUS_TIMEOUT_MS,
1430
+ outputLimit: GIT_LARGE_OUTPUT_LIMIT
1431
+ });
1432
+ const records = result.text.split('\0');
1433
+ const files = [];
1434
+ for (let index = 0; index < records.length; index += 1) {
1435
+ const status = records[index];
1436
+ if (status === undefined || status.length === 0)
1437
+ continue;
1438
+ const code = status[0] ?? 'M';
1439
+ if (code === 'R' || code === 'C') {
1440
+ const previousPath = records[index + 1];
1441
+ const path = records[index + 2];
1442
+ if (previousPath !== undefined && path !== undefined)
1443
+ files.push({ path, previousPath, change: gitChange(code) });
1444
+ index += 2;
1445
+ }
1446
+ else {
1447
+ const path = records[index + 1];
1448
+ if (path !== undefined)
1449
+ files.push({ path, change: gitChange(code) });
1450
+ index += 1;
1451
+ }
1452
+ }
1453
+ return files;
1454
+ }
1455
+ export async function readGitHistoryFileDiff(repository, commit, requestedPath, refs, requestedPreviousPath) {
1456
+ await assertHistoryCommitReachable(repository, commit, refs);
1457
+ const path = safeGitWorkspacePath(requestedPath);
1458
+ const previousPath = requestedPreviousPath === undefined ? undefined : safeGitWorkspacePath(requestedPreviousPath);
1459
+ const result = await runReadOnlyGit(repository, [
1460
+ 'show',
1461
+ '--format=',
1462
+ '--first-parent',
1463
+ '--no-ext-diff',
1464
+ '--no-textconv',
1465
+ commit,
1466
+ '--',
1467
+ `:(literal)${path}`,
1468
+ ...(previousPath === undefined || previousPath === path ? [] : [`:(literal)${previousPath}`])
1469
+ ]);
1470
+ const binary = result.output.includes(0) || result.text.includes('Binary files ');
1471
+ if (binary) {
1472
+ return {
1473
+ binary: true,
1474
+ summary: `binary diff sha256=${createHash('sha256').update(result.output).digest('hex')} bytes=${result.output.length}`,
1475
+ truncated: result.truncated
1476
+ };
1477
+ }
1478
+ return { binary: false, text: result.text, truncated: result.truncated };
1479
+ }
1480
+ export async function readGitHistoryFileContentRange(repository, commit, requestedPath, offset, limit, refs) {
1481
+ if (!Number.isSafeInteger(offset) ||
1482
+ offset < 0 ||
1483
+ !Number.isSafeInteger(limit) ||
1484
+ limit < 1 ||
1485
+ limit > 20 * 1024 * 1024 ||
1486
+ offset + limit > 20 * 1024 * 1024)
1487
+ throw new Error('FILE_RANGE_INVALID');
1488
+ await assertHistoryCommitReachable(repository, commit, refs);
1489
+ const path = safeGitWorkspacePath(requestedPath);
1490
+ const object = `${commit}:${path}`;
1491
+ const sizeResult = await runReadOnlyGit(repository, ['cat-file', '-s', object]);
1492
+ const size = Number(sizeResult.text.trim());
1493
+ if (!Number.isSafeInteger(size) || size < 0 || offset > size)
1494
+ throw new Error('FILE_RANGE_INVALID');
1495
+ if (offset === size)
1496
+ return { path, size, offset, contentBase64: '', nextOffset: null };
1497
+ const result = await runReadOnlyGitAllowFailure(repository, ['cat-file', 'blob', object], {
1498
+ outputLimit: offset + limit,
1499
+ timeoutMs: GIT_HISTORY_TIMEOUT_MS
1500
+ });
1501
+ if (result.code !== 0)
1502
+ throw new GitCommandError(result.code, result.stderr);
1503
+ const content = result.output.subarray(offset, Math.min(size, offset + limit));
1504
+ const nextOffset = offset + content.length;
1505
+ return {
1506
+ path,
1507
+ size,
1508
+ offset,
1509
+ contentBase64: content.toString('base64'),
1510
+ nextOffset: nextOffset < size ? nextOffset : null
1511
+ };
1512
+ }
1513
+ export async function readCurrentChanges(workspacePath) {
1514
+ return (await readCurrentChangesSummary(workspacePath)).changes;
1515
+ }
1516
+ export async function readCurrentChangeDiff(workspacePath, requestedPath) {
1517
+ const path = safeGitWorkspacePath(requestedPath);
1518
+ await assertCurrentChangePathAccessible(workspacePath, path);
1519
+ const result = await readCurrentChangeGitDiff(workspacePath, path);
1520
+ const after = await readWorkingTreeText(workspacePath, path);
1521
+ const binary = result.output.includes(0) || result.text.includes('Binary files ') || after?.binary === true;
1522
+ if (binary) {
1523
+ return {
1524
+ binary: true,
1525
+ summary: `binary diff sha256=${createHash('sha256').update(result.output).digest('hex')} bytes=${result.output.length}`,
1526
+ truncated: result.truncated || after?.truncated === true
1527
+ };
1528
+ }
1529
+ return {
1530
+ binary: false,
1531
+ text: result.text,
1532
+ truncated: result.truncated || after?.truncated === true,
1533
+ afterText: after?.text ?? '',
1534
+ ...(after === undefined ? {} : { afterTruncated: after.truncated })
1535
+ };
1536
+ }
1537
+ async function readCurrentChangeGitDiff(workspacePath, path) {
1538
+ const untracked = await runReadOnlyGit(workspacePath, [
1539
+ 'ls-files',
1540
+ '--others',
1541
+ '--exclude-standard',
1542
+ '-z',
1543
+ '--',
1544
+ `:(literal)${path}`
1545
+ ]);
1546
+ if (untracked.text.split('\0').includes(path)) {
1547
+ const result = await runReadOnlyGitAllowFailure(workspacePath, [
1548
+ 'diff',
1549
+ '--no-index',
1550
+ '--no-ext-diff',
1551
+ '--no-textconv',
1552
+ '--',
1553
+ '/dev/null',
1554
+ path
1555
+ ]);
1556
+ if (result.code !== 0 && result.code !== 1)
1557
+ throw new GitCommandError(result.code, result.stderr);
1558
+ return result;
1559
+ }
1560
+ return runReadOnlyGit(workspacePath, [
1561
+ 'diff',
1562
+ '--no-ext-diff',
1563
+ '--no-textconv',
1564
+ 'HEAD',
1565
+ '--',
1566
+ `:(literal)${path}`
1567
+ ]);
1568
+ }
1569
+ /** Current Changes must not expose an external link. */
1570
+ export async function isWorkspaceChangeVisible(workspacePath, requestedPath) {
1571
+ try {
1572
+ await assertCurrentChangePathAccessible(workspacePath, safeGitWorkspacePath(requestedPath));
1573
+ return true;
1574
+ }
1575
+ catch (error) {
1576
+ if (error instanceof Error &&
1577
+ (error.message === 'FILE_PATH_ESCAPE' ||
1578
+ error.message === 'FILE_NOT_FOUND' ||
1579
+ error.message === 'FILE_NOT_REGULAR'))
1580
+ return false;
1581
+ throw error;
1582
+ }
1583
+ }
1584
+ async function assertCurrentChangePathAccessible(workspacePath, path) {
1585
+ const root = await realpath(workspacePath);
1586
+ const candidate = resolve(root, path);
1587
+ const metadata = await lstat(candidate).catch((error) => {
1588
+ if (error.code === 'ENOENT')
1589
+ return undefined;
1590
+ throw error;
1591
+ });
1592
+ if (metadata === undefined)
1593
+ return;
1594
+ await resolveWorkspaceEntry(root, path, false);
1595
+ }
1596
+ async function readWorkingTreeText(workspacePath, path) {
1597
+ const root = await realpath(workspacePath);
1598
+ let file;
1599
+ try {
1600
+ file = await resolveWorkspaceEntry(root, path, false);
1601
+ }
1602
+ catch (error) {
1603
+ if (error instanceof Error && error.message === 'FILE_NOT_FOUND')
1604
+ return undefined;
1605
+ throw error;
1606
+ }
1607
+ const metadata = await lstat(file);
1608
+ if (!metadata.isFile())
1609
+ return undefined;
1610
+ const source = await readFile(file);
1611
+ return diffTextFromBuffer(source, source.length > GIT_OUTPUT_LIMIT);
1612
+ }
1613
+ function diffTextFromBuffer(source, truncated) {
1614
+ if (source.includes(0) || !isValidUtf8(source))
1615
+ return { binary: true, truncated };
1616
+ let end = Math.min(source.length, GIT_OUTPUT_LIMIT);
1617
+ while (end > 0 && end < source.length && isUtf8ContinuationByte(source[end]))
1618
+ end -= 1;
1619
+ return { binary: false, text: source.subarray(0, end).toString('utf8'), truncated };
1620
+ }
1621
+ export async function restoreCurrentChange(workspacePath, requestedPath, state) {
1622
+ const path = safeGitWorkspacePath(requestedPath);
1623
+ const pathspec = `:(literal)${path}`;
1624
+ if (state === 'UNTRACKED') {
1625
+ const status = await runReadOnlyGit(workspacePath, [
1626
+ 'status',
1627
+ '--porcelain=v1',
1628
+ '-z',
1629
+ '--untracked-files=all',
1630
+ '--',
1631
+ pathspec
1632
+ ]);
1633
+ if (!status.text
1634
+ .split('\0')
1635
+ .some((record) => record.startsWith('?? ') && record.slice(3) === path))
1636
+ throw new Error('GIT_CHANGE_RESTORE_UNAVAILABLE');
1637
+ const root = await realpath(workspacePath);
1638
+ const file = resolve(root, path);
1639
+ const metadata = await lstat(file);
1640
+ if (!metadata.isFile() || metadata.isSymbolicLink())
1641
+ throw new Error('GIT_CHANGE_RESTORE_UNAVAILABLE');
1642
+ await unlink(file);
1643
+ return;
1644
+ }
1645
+ if (state === 'UNSTAGED') {
1646
+ await runGit(workspacePath, ['restore', '--worktree', '--', pathspec]);
1647
+ return;
1648
+ }
1649
+ await runGit(workspacePath, [
1650
+ 'restore',
1651
+ '--source=HEAD',
1652
+ '--staged',
1653
+ '--worktree',
1654
+ '--',
1655
+ pathspec
1656
+ ]);
1657
+ }
1658
+ function safeGitWorkspacePath(requestedPath) {
1659
+ if (requestedPath.length === 0 ||
1660
+ requestedPath.includes('\0') ||
1661
+ requestedPath.startsWith('/') ||
1662
+ requestedPath.startsWith('\\'))
1663
+ throw new Error('FILE_PATH_ESCAPE');
1664
+ const normalized = requestedPath.replaceAll('\\', '/');
1665
+ if (normalized
1666
+ .split('/')
1667
+ .some((segment) => segment === '' || segment === '..' || segment === '.git'))
1668
+ throw new Error('FILE_PATH_ESCAPE');
1669
+ return normalized;
1670
+ }
1671
+ function gitChange(status) {
1672
+ if (status === 'A')
1673
+ return 'ADDED';
1674
+ if (status === 'D')
1675
+ return 'DELETED';
1676
+ if (status === 'R')
1677
+ return 'RENAMED';
1678
+ if (status === 'C')
1679
+ return 'COPIED';
1680
+ if (status === 'T')
1681
+ return 'TYPE_CHANGED';
1682
+ return 'MODIFIED';
1683
+ }
1684
+ export class GitCommandError extends Error {
1685
+ code;
1686
+ stderr;
1687
+ constructor(code, stderr) {
1688
+ super('GIT_COMMAND_FAILED');
1689
+ this.code = code;
1690
+ this.stderr = stderr;
1691
+ }
1692
+ }
1693
+ async function runReadOnlyGit(workspacePath, args, options = {}) {
1694
+ return runGit(workspacePath, args, { ...options, readOnly: true });
1695
+ }
1696
+ async function runReadOnlyGitAllowFailure(workspacePath, args, options = {}) {
1697
+ return runGitAllowFailure(workspacePath, args, { ...options, readOnly: true });
1698
+ }
1699
+ async function runGit(workspacePath, args, options = {}) {
1700
+ const result = await runGitAllowFailure(workspacePath, args, options);
1701
+ if (result.code !== 0) {
1702
+ throw new GitCommandError(result.code, result.stderr);
1703
+ }
1704
+ return result;
1705
+ }
1706
+ async function runGitAllowFailure(workspacePath, args, options = {}) {
1707
+ return new Promise((resolve, reject) => {
1708
+ const outputLimit = options.outputLimit ?? GIT_OUTPUT_LIMIT;
1709
+ const child = spawn('git', [...args], {
1710
+ cwd: workspacePath,
1711
+ shell: false,
1712
+ windowsHide: true,
1713
+ stdio: ['ignore', 'pipe', 'pipe'],
1714
+ env: {
1715
+ ...process.env,
1716
+ ...gitOperationEnvironment.getStore(),
1717
+ ...(options.readOnly === true ? { GIT_OPTIONAL_LOCKS: '0' } : {})
1718
+ }
1719
+ });
1720
+ const chunks = [];
1721
+ const errors = [];
1722
+ let size = 0;
1723
+ let errorSize = 0;
1724
+ let truncated = false;
1725
+ const timer = setTimeout(() => {
1726
+ if (process.platform === 'win32') {
1727
+ const pid = child.pid;
1728
+ if (pid === undefined) {
1729
+ child.kill('SIGKILL');
1730
+ return;
1731
+ }
1732
+ void terminateProcessTree({
1733
+ pid,
1734
+ kill: (signal) => child.kill(signal)
1735
+ }, 'win32').catch(() => {
1736
+ try {
1737
+ child.kill('SIGKILL');
1738
+ }
1739
+ catch {
1740
+ // The process may have exited while taskkill was starting.
1741
+ }
1742
+ });
1743
+ return;
1744
+ }
1745
+ child.kill('SIGKILL');
1746
+ }, options.timeoutMs ?? GIT_TIMEOUT_MS);
1747
+ child.stdout.on('data', (chunk) => {
1748
+ const remaining = Math.max(0, outputLimit - size);
1749
+ if (remaining > 0) {
1750
+ const retained = chunk.subarray(0, remaining);
1751
+ chunks.push(retained);
1752
+ size += retained.length;
1753
+ }
1754
+ truncated ||= chunk.length > remaining;
1755
+ });
1756
+ child.stderr.on('data', (chunk) => {
1757
+ const remaining = Math.max(0, 4096 - errorSize);
1758
+ if (remaining === 0)
1759
+ return;
1760
+ const retained = chunk.subarray(0, remaining);
1761
+ errors.push(retained);
1762
+ errorSize += retained.length;
1763
+ });
1764
+ child.once('error', (error) => {
1765
+ clearTimeout(timer);
1766
+ reject(error);
1767
+ });
1768
+ child.once('close', (code) => {
1769
+ clearTimeout(timer);
1770
+ const output = Buffer.concat(chunks);
1771
+ resolve({
1772
+ code: code ?? 1,
1773
+ output,
1774
+ text: output.toString('utf8'),
1775
+ stderr: Buffer.concat(errors).toString('utf8'),
1776
+ truncated
1777
+ });
1778
+ });
1779
+ });
1780
+ }
1781
+ function canRetryGitWorktreeListWithoutNullOutput(result) {
1782
+ return (result.code === 129 ||
1783
+ /(?:unknown|unrecognized|invalid)\s+(?:option|switch).*['"`]?-?z\b/iu.test(result.stderr));
1784
+ }
1785
+ function isGitUnavailable(error) {
1786
+ return (error instanceof Error && 'code' in error && error.code === 'ENOENT');
1787
+ }
1788
+ function summarizeText(value) {
1789
+ return JSON.stringify({
1790
+ sha256: createHash('sha256').update(value).digest('hex'),
1791
+ bytes: Buffer.byteLength(value)
1792
+ });
1793
+ }