pybao-cli 1.3.81 → 1.3.83

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 (142) hide show
  1. package/dist/REPL-HVMZDW6I.js +42 -0
  2. package/dist/{acp-4HKKXFYQ.js → acp-OWNA2GOE.js} +28 -28
  3. package/dist/{agentsValidate-Y7ESIGWC.js → agentsValidate-UC7SD3JY.js} +7 -7
  4. package/dist/{ask-BFLAH7SK.js → ask-6ESDLRIC.js} +25 -25
  5. package/dist/{autoUpdater-ZP62GDO2.js → autoUpdater-FAKGXOY4.js} +3 -3
  6. package/dist/{chunk-R56S2D3A.js → chunk-3BP3TGGN.js} +1 -1
  7. package/dist/{chunk-R56S2D3A.js.map → chunk-3BP3TGGN.js.map} +1 -1
  8. package/dist/{chunk-4YJ6DHQK.js → chunk-43ZJOQDX.js} +37 -37
  9. package/dist/{chunk-4YJ6DHQK.js.map → chunk-43ZJOQDX.js.map} +2 -2
  10. package/dist/{chunk-KZGNQII5.js → chunk-6VOYUVQU.js} +4 -4
  11. package/dist/{chunk-AED6OYMI.js → chunk-B3MDT4F6.js} +3 -3
  12. package/dist/{chunk-JEHHIOUO.js → chunk-BPZ44BIE.js} +1 -1
  13. package/dist/{chunk-IV73XFVG.js → chunk-CPOVPGCU.js} +3 -3
  14. package/dist/{chunk-LLNNHSE3.js → chunk-FH5VPA4M.js} +1 -1
  15. package/dist/{chunk-2RR4H3L6.js → chunk-FL4UY5X6.js} +9 -9
  16. package/dist/{chunk-65MNQP3U.js → chunk-FOQKIQ27.js} +3 -3
  17. package/dist/chunk-HCPU4TQ6.js +478 -0
  18. package/dist/chunk-HCPU4TQ6.js.map +7 -0
  19. package/dist/{chunk-BAGUGUP3.js → chunk-HIH43UEF.js} +2 -2
  20. package/dist/{chunk-RPQ3FFN6.js → chunk-HMCPTTVR.js} +3 -3
  21. package/dist/{chunk-TMIQYE2C.js → chunk-JGJCX75W.js} +3 -3
  22. package/dist/{chunk-Q653YYZS.js → chunk-L62UDJSU.js} +1 -1
  23. package/dist/{chunk-72RJTELO.js → chunk-MFNDDM3V.js} +1 -1
  24. package/dist/{chunk-2BT4P5FY.js → chunk-MSWBIZZC.js} +2 -2
  25. package/dist/{chunk-TE7EYQKI.js → chunk-NIKESYZF.js} +2 -2
  26. package/dist/{chunk-UUGAVZ5R.js → chunk-NNNU5K5N.js} +2 -2
  27. package/dist/{chunk-D364WNKJ.js → chunk-PBPAGOFN.js} +2 -2
  28. package/dist/{chunk-2JAKX7IR.js → chunk-SSPEL7MF.js} +3 -3
  29. package/dist/{chunk-26R2U6DS.js → chunk-SWY5TLOX.js} +123 -44
  30. package/dist/chunk-SWY5TLOX.js.map +7 -0
  31. package/dist/{chunk-PYRG5FKD.js → chunk-SYHWDS75.js} +1 -1
  32. package/dist/{chunk-BXF5H7EN.js → chunk-TNJTMN23.js} +1 -1
  33. package/dist/{chunk-5YU3ZWG6.js → chunk-WCR6QGXF.js} +4 -4
  34. package/dist/{chunk-MTSI5244.js → chunk-WU4VY7XT.js} +2 -2
  35. package/dist/{chunk-LVTQN4RG.js → chunk-XC4AJGEW.js} +1 -1
  36. package/dist/{chunk-P2VXE3TJ.js → chunk-XJDZTRBL.js} +3 -3
  37. package/dist/{chunk-5RVP5P5Y.js → chunk-ZEMFBGPE.js} +2 -2
  38. package/dist/{chunk-UGJJDTVJ.js → chunk-ZZO2YNJG.js} +1 -1
  39. package/dist/{cli-KITOXFPL.js → cli-EASV6IY7.js} +79 -79
  40. package/dist/commands-LHZ4KLGY.js +46 -0
  41. package/dist/{config-EVFJADC4.js → config-53WMBY35.js} +4 -4
  42. package/dist/{context-DZU6TVXM.js → context-GNSAANSR.js} +5 -5
  43. package/dist/{customCommands-3ZEKZS64.js → customCommands-TI7KC7QR.js} +4 -4
  44. package/dist/{env-KJ3YKVKD.js → env-7GAPXLOS.js} +2 -2
  45. package/dist/index.js +3 -3
  46. package/dist/{llm-LVHJBUBU.js → llm-24PI2Z6V.js} +26 -26
  47. package/dist/{llmLazy-E37BRRJL.js → llmLazy-JT5FOMWS.js} +1 -1
  48. package/dist/{loader-CJQYGIOX.js → loader-FVGZ4Q4O.js} +4 -4
  49. package/dist/{lspAnchor-VYW6TBK6.js → lspAnchor-2ESTEKDW.js} +4 -4
  50. package/dist/{manager-2E6RCOPM.js → manager-B7QOH5CJ.js} +4 -4
  51. package/dist/{mcp-32PUNKEE.js → mcp-DXRJFV2Z.js} +7 -7
  52. package/dist/{mentionProcessor-YQUVBGUO.js → mentionProcessor-24DFMNUM.js} +5 -5
  53. package/dist/{messages-S6XJLYHT.js → messages-44UB3QCF.js} +1 -1
  54. package/dist/{model-KERYS7VW.js → model-2MO4JM7C.js} +5 -5
  55. package/dist/{openai-LIOQRL5O.js → openai-IW2EECJN.js} +5 -5
  56. package/dist/{outputStyles-M7AT5V2E.js → outputStyles-OFVM7RO6.js} +4 -4
  57. package/dist/{pluginRuntime-RPOZH24G.js → pluginRuntime-L2ORBVPC.js} +6 -6
  58. package/dist/{pluginValidation-3PNCKYDB.js → pluginValidation-S5YXDUDC.js} +6 -6
  59. package/dist/prompts-7PXTK55Q.js +48 -0
  60. package/dist/{pybAgentSessionLoad-U343Y3XU.js → pybAgentSessionLoad-NM2FSUHI.js} +4 -4
  61. package/dist/{pybAgentSessionResume-747QQNMS.js → pybAgentSessionResume-R6DFJVOS.js} +4 -4
  62. package/dist/{pybAgentStreamJsonSession-B25HH4BN.js → pybAgentStreamJsonSession-IYC73GWN.js} +1 -1
  63. package/dist/{pybHooks-7EEKA766.js → pybHooks-BNGLUIBL.js} +4 -4
  64. package/dist/query-OLRMI42V.js +50 -0
  65. package/dist/{ripgrep-US75RUV3.js → ripgrep-QZG3RMUD.js} +5 -3
  66. package/dist/{skillMarketplace-P4P7ZUPT.js → skillMarketplace-IRUF6M5M.js} +3 -3
  67. package/dist/{state-36K5VF3G.js → state-LSDUZCQZ.js} +2 -2
  68. package/dist/{theme-7R3CIM3B.js → theme-QVGQSEFJ.js} +5 -5
  69. package/dist/{toolPermissionSettings-4YLPKZWJ.js → toolPermissionSettings-U4P7K6VA.js} +6 -6
  70. package/dist/tools-LSBTQYU4.js +51 -0
  71. package/dist/{userInput-TBU35CMG.js → userInput-EP4A6TDN.js} +27 -27
  72. package/package.json +1 -1
  73. package/dist/REPL-N4B3JZBZ.js +0 -42
  74. package/dist/chunk-26R2U6DS.js.map +0 -7
  75. package/dist/chunk-VQYBUOUL.js +0 -232
  76. package/dist/chunk-VQYBUOUL.js.map +0 -7
  77. package/dist/commands-GPZL7LEO.js +0 -46
  78. package/dist/prompts-HL3TSDJY.js +0 -48
  79. package/dist/query-LXPSR7ZB.js +0 -50
  80. package/dist/tools-3JTWQRFN.js +0 -51
  81. /package/dist/{REPL-N4B3JZBZ.js.map → REPL-HVMZDW6I.js.map} +0 -0
  82. /package/dist/{acp-4HKKXFYQ.js.map → acp-OWNA2GOE.js.map} +0 -0
  83. /package/dist/{agentsValidate-Y7ESIGWC.js.map → agentsValidate-UC7SD3JY.js.map} +0 -0
  84. /package/dist/{ask-BFLAH7SK.js.map → ask-6ESDLRIC.js.map} +0 -0
  85. /package/dist/{autoUpdater-ZP62GDO2.js.map → autoUpdater-FAKGXOY4.js.map} +0 -0
  86. /package/dist/{chunk-KZGNQII5.js.map → chunk-6VOYUVQU.js.map} +0 -0
  87. /package/dist/{chunk-AED6OYMI.js.map → chunk-B3MDT4F6.js.map} +0 -0
  88. /package/dist/{chunk-JEHHIOUO.js.map → chunk-BPZ44BIE.js.map} +0 -0
  89. /package/dist/{chunk-IV73XFVG.js.map → chunk-CPOVPGCU.js.map} +0 -0
  90. /package/dist/{chunk-LLNNHSE3.js.map → chunk-FH5VPA4M.js.map} +0 -0
  91. /package/dist/{chunk-2RR4H3L6.js.map → chunk-FL4UY5X6.js.map} +0 -0
  92. /package/dist/{chunk-65MNQP3U.js.map → chunk-FOQKIQ27.js.map} +0 -0
  93. /package/dist/{chunk-BAGUGUP3.js.map → chunk-HIH43UEF.js.map} +0 -0
  94. /package/dist/{chunk-RPQ3FFN6.js.map → chunk-HMCPTTVR.js.map} +0 -0
  95. /package/dist/{chunk-TMIQYE2C.js.map → chunk-JGJCX75W.js.map} +0 -0
  96. /package/dist/{chunk-Q653YYZS.js.map → chunk-L62UDJSU.js.map} +0 -0
  97. /package/dist/{chunk-72RJTELO.js.map → chunk-MFNDDM3V.js.map} +0 -0
  98. /package/dist/{chunk-2BT4P5FY.js.map → chunk-MSWBIZZC.js.map} +0 -0
  99. /package/dist/{chunk-TE7EYQKI.js.map → chunk-NIKESYZF.js.map} +0 -0
  100. /package/dist/{chunk-UUGAVZ5R.js.map → chunk-NNNU5K5N.js.map} +0 -0
  101. /package/dist/{chunk-D364WNKJ.js.map → chunk-PBPAGOFN.js.map} +0 -0
  102. /package/dist/{chunk-2JAKX7IR.js.map → chunk-SSPEL7MF.js.map} +0 -0
  103. /package/dist/{chunk-PYRG5FKD.js.map → chunk-SYHWDS75.js.map} +0 -0
  104. /package/dist/{chunk-BXF5H7EN.js.map → chunk-TNJTMN23.js.map} +0 -0
  105. /package/dist/{chunk-5YU3ZWG6.js.map → chunk-WCR6QGXF.js.map} +0 -0
  106. /package/dist/{chunk-MTSI5244.js.map → chunk-WU4VY7XT.js.map} +0 -0
  107. /package/dist/{chunk-LVTQN4RG.js.map → chunk-XC4AJGEW.js.map} +0 -0
  108. /package/dist/{chunk-P2VXE3TJ.js.map → chunk-XJDZTRBL.js.map} +0 -0
  109. /package/dist/{chunk-5RVP5P5Y.js.map → chunk-ZEMFBGPE.js.map} +0 -0
  110. /package/dist/{chunk-UGJJDTVJ.js.map → chunk-ZZO2YNJG.js.map} +0 -0
  111. /package/dist/{cli-KITOXFPL.js.map → cli-EASV6IY7.js.map} +0 -0
  112. /package/dist/{commands-GPZL7LEO.js.map → commands-LHZ4KLGY.js.map} +0 -0
  113. /package/dist/{config-EVFJADC4.js.map → config-53WMBY35.js.map} +0 -0
  114. /package/dist/{context-DZU6TVXM.js.map → context-GNSAANSR.js.map} +0 -0
  115. /package/dist/{customCommands-3ZEKZS64.js.map → customCommands-TI7KC7QR.js.map} +0 -0
  116. /package/dist/{env-KJ3YKVKD.js.map → env-7GAPXLOS.js.map} +0 -0
  117. /package/dist/{llm-LVHJBUBU.js.map → llm-24PI2Z6V.js.map} +0 -0
  118. /package/dist/{llmLazy-E37BRRJL.js.map → llmLazy-JT5FOMWS.js.map} +0 -0
  119. /package/dist/{loader-CJQYGIOX.js.map → loader-FVGZ4Q4O.js.map} +0 -0
  120. /package/dist/{lspAnchor-VYW6TBK6.js.map → lspAnchor-2ESTEKDW.js.map} +0 -0
  121. /package/dist/{manager-2E6RCOPM.js.map → manager-B7QOH5CJ.js.map} +0 -0
  122. /package/dist/{mcp-32PUNKEE.js.map → mcp-DXRJFV2Z.js.map} +0 -0
  123. /package/dist/{mentionProcessor-YQUVBGUO.js.map → mentionProcessor-24DFMNUM.js.map} +0 -0
  124. /package/dist/{messages-S6XJLYHT.js.map → messages-44UB3QCF.js.map} +0 -0
  125. /package/dist/{model-KERYS7VW.js.map → model-2MO4JM7C.js.map} +0 -0
  126. /package/dist/{openai-LIOQRL5O.js.map → openai-IW2EECJN.js.map} +0 -0
  127. /package/dist/{outputStyles-M7AT5V2E.js.map → outputStyles-OFVM7RO6.js.map} +0 -0
  128. /package/dist/{pluginRuntime-RPOZH24G.js.map → pluginRuntime-L2ORBVPC.js.map} +0 -0
  129. /package/dist/{pluginValidation-3PNCKYDB.js.map → pluginValidation-S5YXDUDC.js.map} +0 -0
  130. /package/dist/{prompts-HL3TSDJY.js.map → prompts-7PXTK55Q.js.map} +0 -0
  131. /package/dist/{pybAgentSessionLoad-U343Y3XU.js.map → pybAgentSessionLoad-NM2FSUHI.js.map} +0 -0
  132. /package/dist/{pybAgentSessionResume-747QQNMS.js.map → pybAgentSessionResume-R6DFJVOS.js.map} +0 -0
  133. /package/dist/{pybAgentStreamJsonSession-B25HH4BN.js.map → pybAgentStreamJsonSession-IYC73GWN.js.map} +0 -0
  134. /package/dist/{pybHooks-7EEKA766.js.map → pybHooks-BNGLUIBL.js.map} +0 -0
  135. /package/dist/{query-LXPSR7ZB.js.map → query-OLRMI42V.js.map} +0 -0
  136. /package/dist/{ripgrep-US75RUV3.js.map → ripgrep-QZG3RMUD.js.map} +0 -0
  137. /package/dist/{skillMarketplace-P4P7ZUPT.js.map → skillMarketplace-IRUF6M5M.js.map} +0 -0
  138. /package/dist/{state-36K5VF3G.js.map → state-LSDUZCQZ.js.map} +0 -0
  139. /package/dist/{theme-7R3CIM3B.js.map → theme-QVGQSEFJ.js.map} +0 -0
  140. /package/dist/{toolPermissionSettings-4YLPKZWJ.js.map → toolPermissionSettings-U4P7K6VA.js.map} +0 -0
  141. /package/dist/{tools-3JTWQRFN.js.map → tools-LSBTQYU4.js.map} +0 -0
  142. /package/dist/{userInput-TBU35CMG.js.map → userInput-EP4A6TDN.js.map} +0 -0
@@ -6,10 +6,10 @@ import {
6
6
  import {
7
7
  getSettingsFileCandidates,
8
8
  loadSettingsWithLegacyFallback
9
- } from "./chunk-LVTQN4RG.js";
9
+ } from "./chunk-XC4AJGEW.js";
10
10
  import {
11
11
  getTheme
12
- } from "./chunk-LLNNHSE3.js";
12
+ } from "./chunk-FH5VPA4M.js";
13
13
  import {
14
14
  addMcprcServerForTesting,
15
15
  getCurrentProjectConfig,
@@ -19,13 +19,13 @@ import {
19
19
  safeParseJSON,
20
20
  saveCurrentProjectConfig,
21
21
  saveGlobalConfig
22
- } from "./chunk-TMIQYE2C.js";
22
+ } from "./chunk-JGJCX75W.js";
23
23
  import {
24
24
  PRODUCT_COMMAND,
25
25
  PRODUCT_NAME,
26
26
  getCwd,
27
27
  logMCPError
28
- } from "./chunk-Q653YYZS.js";
28
+ } from "./chunk-L62UDJSU.js";
29
29
 
30
30
  // src/services/mcp/client.ts
31
31
  import { existsSync as existsSync2, readFileSync as readFileSync2 } from "fs";
@@ -8,11 +8,11 @@ import {
8
8
  } from "./chunk-BJSWTHRM.js";
9
9
  import {
10
10
  loadSettingsWithLegacyFallback
11
- } from "./chunk-LVTQN4RG.js";
11
+ } from "./chunk-XC4AJGEW.js";
12
12
  import {
13
13
  getCwd,
14
14
  logError
15
- } from "./chunk-Q653YYZS.js";
15
+ } from "./chunk-L62UDJSU.js";
16
16
 
17
17
  // src/utils/session/pybHooks.ts
18
18
  import { spawn } from "child_process";
@@ -496,7 +496,7 @@ async function runPromptHook(args) {
496
496
  fallbackTimeoutMs: args.fallbackTimeoutMs
497
497
  });
498
498
  try {
499
- const { queryQuick } = await import("./llmLazy-E37BRRJL.js");
499
+ const { queryQuick } = await import("./llmLazy-JT5FOMWS.js");
500
500
  const systemPrompt = [
501
501
  "You are executing a Pyb prompt hook.",
502
502
  "Return a single JSON object only (no markdown, no prose).",
@@ -448,7 +448,7 @@ function getLastAssistantMessageId(messages) {
448
448
 
449
449
  // src/utils/messages/index.ts
450
450
  async function processUserInput(input, mode, setToolJSX, context, pastedImages) {
451
- const impl = await import("./userInput-TBU35CMG.js");
451
+ const impl = await import("./userInput-EP4A6TDN.js");
452
452
  return impl.processUserInput(input, mode, setToolJSX, context, pastedImages);
453
453
  }
454
454
 
@@ -4,18 +4,18 @@ import {
4
4
  getSettingsFileCandidates,
5
5
  loadSettingsWithLegacyFallback,
6
6
  saveSettingsToPrimaryAndSyncLegacy
7
- } from "./chunk-LVTQN4RG.js";
7
+ } from "./chunk-XC4AJGEW.js";
8
8
  import {
9
9
  createDefaultToolPermissionContext,
10
10
  isPersistableToolPermissionDestination
11
11
  } from "./chunk-UNNVICVU.js";
12
12
  import {
13
13
  getCurrentProjectConfig
14
- } from "./chunk-TMIQYE2C.js";
14
+ } from "./chunk-JGJCX75W.js";
15
15
  import {
16
16
  getCwd,
17
17
  logError
18
- } from "./chunk-Q653YYZS.js";
18
+ } from "./chunk-L62UDJSU.js";
19
19
 
20
20
  // src/utils/permissions/toolPermissionSettings.ts
21
21
  function uniqueStrings(value) {
@@ -2,7 +2,7 @@ import { createRequire as __pybCreateRequire } from "node:module";
2
2
  const require = __pybCreateRequire(import.meta.url);
3
3
  import {
4
4
  getGlobalConfig
5
- } from "./chunk-TMIQYE2C.js";
5
+ } from "./chunk-JGJCX75W.js";
6
6
 
7
7
  // src/utils/theme/index.ts
8
8
  var lightTheme = {
@@ -5,11 +5,11 @@ import {
5
5
  getCLISyspromptPrefix,
6
6
  getReasoningEffort,
7
7
  models_default
8
- } from "./chunk-4YJ6DHQK.js";
8
+ } from "./chunk-43ZJOQDX.js";
9
9
  import {
10
10
  getCompletionWithProfile,
11
11
  getGPT5CompletionWithProfile
12
- } from "./chunk-MTSI5244.js";
12
+ } from "./chunk-WU4VY7XT.js";
13
13
  import {
14
14
  API_ERROR_MESSAGE_PREFIX,
15
15
  CREDIT_BALANCE_TOO_LOW_ERROR_MESSAGE,
@@ -18,7 +18,7 @@ import {
18
18
  PROMPT_TOO_LONG_ERROR_MESSAGE,
19
19
  createAssistantAPIErrorMessage,
20
20
  normalizeContentFromAPI
21
- } from "./chunk-JEHHIOUO.js";
21
+ } from "./chunk-BPZ44BIE.js";
22
22
  import {
23
23
  processResponsesStream
24
24
  } from "./chunk-OMELVAJD.js";
@@ -30,11 +30,11 @@ import {
30
30
  USE_VERTEX,
31
31
  getModelManager,
32
32
  getVertexRegionForModel
33
- } from "./chunk-RPQ3FFN6.js";
33
+ } from "./chunk-HMCPTTVR.js";
34
34
  import {
35
35
  getAnthropicApiKey,
36
36
  getGlobalConfig
37
- } from "./chunk-TMIQYE2C.js";
37
+ } from "./chunk-JGJCX75W.js";
38
38
  import {
39
39
  debug,
40
40
  getCurrentRequest,
@@ -42,16 +42,16 @@ import {
42
42
  logLLMInteraction,
43
43
  logSystemPromptConstruction,
44
44
  markPhase
45
- } from "./chunk-PYRG5FKD.js";
45
+ } from "./chunk-SYHWDS75.js";
46
46
  import {
47
47
  PRODUCT_COMMAND,
48
48
  env,
49
49
  getCwd,
50
50
  logError
51
- } from "./chunk-Q653YYZS.js";
51
+ } from "./chunk-L62UDJSU.js";
52
52
  import {
53
53
  MACRO
54
- } from "./chunk-R56S2D3A.js";
54
+ } from "./chunk-3BP3TGGN.js";
55
55
  import {
56
56
  addToTotalCost
57
57
  } from "./chunk-OUXHGDLH.js";
@@ -2821,7 +2821,7 @@ async function queryOpenAI(messages, systemPrompt, maxThinkingTokens, tools, sig
2821
2821
  start = Date.now();
2822
2822
  if (adapterContext) {
2823
2823
  if (adapterContext.shouldUseResponses) {
2824
- const { callGPT5ResponsesAPI } = await import("./openai-LIOQRL5O.js");
2824
+ const { callGPT5ResponsesAPI } = await import("./openai-IW2EECJN.js");
2825
2825
  const response = await callGPT5ResponsesAPI(
2826
2826
  modelProfile,
2827
2827
  adapterContext.request,
@@ -4,10 +4,10 @@ import {
4
4
  PRODUCT_NAME,
5
5
  execFileNoThrow,
6
6
  logError
7
- } from "./chunk-Q653YYZS.js";
7
+ } from "./chunk-L62UDJSU.js";
8
8
  import {
9
9
  MACRO
10
- } from "./chunk-R56S2D3A.js";
10
+ } from "./chunk-3BP3TGGN.js";
11
11
 
12
12
  // src/utils/session/autoUpdater.ts
13
13
  async function getSemver() {
@@ -82,7 +82,7 @@ async function checkAndNotifyUpdate() {
82
82
  const [
83
83
  { isAutoUpdaterDisabled, getGlobalConfig, saveGlobalConfig },
84
84
  { env }
85
- ] = await Promise.all([import("./config-EVFJADC4.js"), import("./env-KJ3YKVKD.js")]);
85
+ ] = await Promise.all([import("./config-53WMBY35.js"), import("./env-7GAPXLOS.js")]);
86
86
  if (await isAutoUpdaterDisabled()) return;
87
87
  if (await env.getIsDocker()) return;
88
88
  if (!await env.hasInternetAccess()) return;
@@ -0,0 +1,478 @@
1
+ import { createRequire as __pybCreateRequire } from "node:module";
2
+ const require = __pybCreateRequire(import.meta.url);
3
+ import {
4
+ BunShell,
5
+ execFileNoThrow,
6
+ logError
7
+ } from "./chunk-L62UDJSU.js";
8
+
9
+ // src/utils/system/ripgrep.ts
10
+ import { findActualExecutable } from "spawn-rx";
11
+ import { memoize } from "lodash-es";
12
+ import {
13
+ chmodSync,
14
+ closeSync,
15
+ copyFileSync,
16
+ existsSync,
17
+ mkdirSync,
18
+ mkdtempSync,
19
+ openSync,
20
+ readdirSync,
21
+ rmSync,
22
+ writeFileSync
23
+ } from "node:fs";
24
+ import { execFile, spawn } from "child_process";
25
+ import debug from "debug";
26
+ import { quote } from "shell-quote";
27
+ import { basename, isAbsolute, join, relative, sep } from "path";
28
+ import envPaths from "env-paths";
29
+ import { unzipSync } from "fflate";
30
+ var d = debug("pyb:ripgrep");
31
+ var DEFAULT_RIPGREP_VERSION = "14.1.1";
32
+ var PLATFORM_CONFIG = {
33
+ "arm64-darwin": { platform: "aarch64-apple-darwin", extension: "tar.gz" },
34
+ "arm64-linux": { platform: "aarch64-unknown-linux-gnu", extension: "tar.gz" },
35
+ "x64-darwin": { platform: "x86_64-apple-darwin", extension: "tar.gz" },
36
+ "x64-linux": { platform: "x86_64-unknown-linux-musl", extension: "tar.gz" },
37
+ "x64-win32": { platform: "x86_64-pc-windows-msvc", extension: "zip" }
38
+ };
39
+ function isTruthyEnv(value) {
40
+ if (!value) return false;
41
+ return ["1", "true", "yes", "on"].includes(value.trim().toLowerCase());
42
+ }
43
+ function getRipgrepVersion() {
44
+ const override = process.env.PYB_RIPGREP_VERSION?.trim();
45
+ return override || DEFAULT_RIPGREP_VERSION;
46
+ }
47
+ function getRipgrepBinaryName() {
48
+ return process.platform === "win32" ? "rg.exe" : "rg";
49
+ }
50
+ function getPlatformConfig() {
51
+ const platformKey = `${process.arch}-${process.platform}`;
52
+ const config = PLATFORM_CONFIG[platformKey];
53
+ if (!config) {
54
+ throw new Error(`Unsupported ripgrep platform: ${platformKey}`);
55
+ }
56
+ return { platformKey, ...config };
57
+ }
58
+ function getRipgrepCacheRoot() {
59
+ const override = process.env.PYB_RIPGREP_CACHE_DIR?.trim();
60
+ if (override) return override;
61
+ const paths = envPaths("pyb");
62
+ return join(paths.cache, "ripgrep");
63
+ }
64
+ function getDownloadBaseUrl(version) {
65
+ const override = process.env.PYB_RIPGREP_DOWNLOAD_BASE_URL?.trim();
66
+ if (!override) {
67
+ return `https://github.com/BurntSushi/ripgrep/releases/download/${version}`;
68
+ }
69
+ if (override.includes("{version}")) {
70
+ return override.replace("{version}", version);
71
+ }
72
+ return `${override.replace(/\/$/, "")}/${version}`;
73
+ }
74
+ async function delay(ms) {
75
+ await new Promise((resolve) => setTimeout(resolve, ms));
76
+ }
77
+ function findFileRecursive(root, filename) {
78
+ const entries = readdirSync(root, { withFileTypes: true });
79
+ for (const entry of entries) {
80
+ const full = join(root, entry.name);
81
+ if (entry.isDirectory()) {
82
+ const found = findFileRecursive(full, filename);
83
+ if (found) return found;
84
+ } else if (entry.isFile() && entry.name === filename) {
85
+ return full;
86
+ }
87
+ }
88
+ return null;
89
+ }
90
+ async function execFileChecked(command, args, options) {
91
+ await new Promise((resolve, reject) => {
92
+ execFile(
93
+ command,
94
+ args,
95
+ { cwd: options.cwd, maxBuffer: 1e6 },
96
+ (error, _stdout, stderr) => {
97
+ if (error) {
98
+ reject(
99
+ new Error(
100
+ `${command} ${args.join(" ")} failed: ${stderr || error.message}`
101
+ )
102
+ );
103
+ } else {
104
+ resolve();
105
+ }
106
+ }
107
+ );
108
+ });
109
+ }
110
+ async function acquireLock(lockPath, readyPath) {
111
+ const start = Date.now();
112
+ while (true) {
113
+ try {
114
+ return openSync(lockPath, "wx");
115
+ } catch (error) {
116
+ if (error?.code !== "EEXIST") {
117
+ throw error;
118
+ }
119
+ if (existsSync(readyPath)) return null;
120
+ if (Date.now() - start > 2e4) {
121
+ throw new Error("Timed out waiting for ripgrep download lock");
122
+ }
123
+ await delay(100);
124
+ }
125
+ }
126
+ }
127
+ async function downloadRipgrepTo(cacheDir) {
128
+ const { platform, extension, platformKey } = getPlatformConfig();
129
+ const version = getRipgrepVersion();
130
+ const filename = `ripgrep-${version}-${platform}.${extension}`;
131
+ const url = `${getDownloadBaseUrl(version)}/${filename}`;
132
+ const response = await fetch(url);
133
+ if (!response.ok) {
134
+ throw new Error(
135
+ `Failed to download ripgrep (${response.status}): ${url}`
136
+ );
137
+ }
138
+ const buffer = new Uint8Array(await response.arrayBuffer());
139
+ const tempDir = mkdtempSync(join(cacheDir, "tmp-"));
140
+ try {
141
+ const binaryName = getRipgrepBinaryName();
142
+ const targetPath = join(cacheDir, binaryName);
143
+ if (extension === "zip") {
144
+ const files = unzipSync(buffer);
145
+ const entryName = Object.keys(files).find(
146
+ (name) => name.endsWith(binaryName)
147
+ );
148
+ if (!entryName) {
149
+ throw new Error(`ripgrep binary not found in zip: ${filename}`);
150
+ }
151
+ writeFileSync(targetPath, files[entryName]);
152
+ } else {
153
+ const archivePath = join(tempDir, filename);
154
+ const extractDir = join(tempDir, "extract");
155
+ mkdirSync(extractDir, { recursive: true });
156
+ writeFileSync(archivePath, buffer);
157
+ await execFileChecked("tar", ["-xzf", archivePath, "-C", extractDir], {
158
+ cwd: tempDir
159
+ });
160
+ const extracted = findFileRecursive(extractDir, binaryName);
161
+ if (!extracted) {
162
+ throw new Error(
163
+ `ripgrep binary not found after extraction: ${platformKey}`
164
+ );
165
+ }
166
+ copyFileSync(extracted, targetPath);
167
+ }
168
+ if (process.platform !== "win32") {
169
+ chmodSync(targetPath, 493);
170
+ }
171
+ return targetPath;
172
+ } finally {
173
+ rmSync(tempDir, { recursive: true, force: true });
174
+ }
175
+ }
176
+ async function ensureCachedRipgrep() {
177
+ const version = getRipgrepVersion();
178
+ const { platformKey } = getPlatformConfig();
179
+ const cacheRoot = getRipgrepCacheRoot();
180
+ const cacheDir = join(cacheRoot, version, platformKey);
181
+ const binaryPath = join(cacheDir, getRipgrepBinaryName());
182
+ if (existsSync(binaryPath)) return binaryPath;
183
+ mkdirSync(cacheDir, { recursive: true });
184
+ const lockPath = join(cacheDir, ".lock");
185
+ const lockFd = await acquireLock(lockPath, binaryPath);
186
+ if (!lockFd) return binaryPath;
187
+ try {
188
+ if (!existsSync(binaryPath)) {
189
+ await downloadRipgrepTo(cacheDir);
190
+ }
191
+ return binaryPath;
192
+ } finally {
193
+ try {
194
+ closeSync(lockFd);
195
+ } catch {
196
+ }
197
+ rmSync(lockPath, { force: true });
198
+ }
199
+ }
200
+ async function resolveRipgrepPathOrThrow() {
201
+ const explicit = process.env.PYB_RIPGREP_PATH;
202
+ if (explicit) {
203
+ if (!existsSync(explicit)) {
204
+ throw new Error(`PYB_RIPGREP_PATH points to a missing file: ${explicit}`);
205
+ }
206
+ return explicit;
207
+ }
208
+ const preferBundled = isTruthyEnv(process.env.USE_BUILTIN_RIPGREP);
209
+ if (!preferBundled) {
210
+ const { cmd } = findActualExecutable("rg", []);
211
+ d(`ripgrep initially resolved as: ${cmd}`);
212
+ if (cmd !== "rg") {
213
+ return cmd;
214
+ }
215
+ }
216
+ const cached = await ensureCachedRipgrep();
217
+ d("Using cached ripgrep: %s", cached);
218
+ return cached;
219
+ }
220
+ var getRipgrepPath = memoize(
221
+ async () => resolveRipgrepPathOrThrow()
222
+ );
223
+ async function ripGrepWithStatus(args, target, abortSignal, options) {
224
+ await codesignRipgrepIfNecessary();
225
+ const rg = await getRipgrepPath();
226
+ d("ripgrep called: %s %o", rg, target, args);
227
+ if (options?.sandbox?.enabled === true) {
228
+ const cmd = quote([rg, ...args, target]);
229
+ const result = await BunShell.getInstance().exec(cmd, abortSignal, 1e4, {
230
+ sandbox: options.sandbox
231
+ });
232
+ if (result.code === 1) return { files: [], status: "ok", code: 1 };
233
+ if (result.code !== 0) {
234
+ logError(`ripgrep failed with exit code ${result.code}: ${result.stderr}`);
235
+ return { files: [], status: "error", code: result.code };
236
+ }
237
+ return {
238
+ files: result.stdout.trim().split("\n").filter(Boolean),
239
+ status: "ok",
240
+ code: 0
241
+ };
242
+ }
243
+ return new Promise((resolve) => {
244
+ const bun = globalThis.Bun;
245
+ if (bun?.spawn && typeof bun.spawn === "function") {
246
+ const files2 = [];
247
+ let buffer2 = "";
248
+ let stderr2 = "";
249
+ const decoder = new TextDecoder();
250
+ const proc2 = bun.spawn([rg, ...args, target], {
251
+ stdout: "pipe",
252
+ stderr: "pipe",
253
+ signal: abortSignal
254
+ });
255
+ const readStdout = async () => {
256
+ const reader = proc2.stdout.getReader();
257
+ while (true) {
258
+ const { done, value } = await reader.read();
259
+ if (done) break;
260
+ buffer2 += decoder.decode(value, { stream: true });
261
+ const parts = buffer2.split(/\r?\n/);
262
+ buffer2 = parts.pop() ?? "";
263
+ for (const line of parts) {
264
+ if (line) files2.push(line);
265
+ }
266
+ }
267
+ reader.releaseLock();
268
+ };
269
+ const readStderr = async () => {
270
+ const reader = proc2.stderr.getReader();
271
+ while (true) {
272
+ const { done, value } = await reader.read();
273
+ if (done) break;
274
+ stderr2 += decoder.decode(value, { stream: true });
275
+ }
276
+ reader.releaseLock();
277
+ };
278
+ Promise.all([readStdout(), readStderr(), proc2.exited]).then(([_, __, exitCode]) => {
279
+ if (buffer2) files2.push(buffer2);
280
+ if (exitCode && exitCode !== 1) {
281
+ if (stderr2) {
282
+ logError(`ripgrep failed with exit code ${exitCode}: ${stderr2}`);
283
+ }
284
+ resolve({ files: [], status: "error", code: exitCode });
285
+ return;
286
+ }
287
+ resolve({ files: files2, status: "ok", code: exitCode ?? 0 });
288
+ }).catch((error) => {
289
+ d("ripgrep error: %o", error);
290
+ logError(error);
291
+ resolve({ files: [], status: "error" });
292
+ });
293
+ return;
294
+ }
295
+ const proc = spawn(rg, [...args, target], {
296
+ signal: abortSignal,
297
+ timeout: 1e4
298
+ });
299
+ const files = [];
300
+ let buffer = "";
301
+ let stderr = "";
302
+ proc.stdout?.on("data", (chunk) => {
303
+ buffer += chunk.toString();
304
+ const parts = buffer.split(/\r?\n/);
305
+ buffer = parts.pop() ?? "";
306
+ for (const line of parts) {
307
+ if (line) files.push(line);
308
+ }
309
+ });
310
+ proc.stderr?.on("data", (chunk) => {
311
+ stderr += chunk.toString();
312
+ });
313
+ proc.on("error", (error) => {
314
+ d("ripgrep error: %o", error);
315
+ logError(error);
316
+ });
317
+ proc.on("close", (code) => {
318
+ if (buffer.trim().length > 0) files.push(buffer.trim());
319
+ if (code && code !== 1) {
320
+ if (stderr) {
321
+ logError(`ripgrep failed with exit code ${code}: ${stderr}`);
322
+ }
323
+ resolve({ files: [], status: "error", code });
324
+ return;
325
+ }
326
+ resolve({
327
+ files,
328
+ status: "ok",
329
+ code: code ?? 0
330
+ });
331
+ });
332
+ });
333
+ }
334
+ async function ripGrep(args, target, abortSignal, options) {
335
+ const result = await ripGrepWithStatus(args, target, abortSignal, options);
336
+ return result.files;
337
+ }
338
+ async function listAllContentFiles(path, abortSignal, limit) {
339
+ try {
340
+ d("listAllContentFiles called: %s", path);
341
+ return (await ripGrep(["-l", ".", path], path, abortSignal)).slice(0, limit);
342
+ } catch (e) {
343
+ d("listAllContentFiles failed: %o", e);
344
+ logError(e);
345
+ return [];
346
+ }
347
+ }
348
+ var alreadyDoneSignCheck = false;
349
+ async function codesignRipgrepIfNecessary() {
350
+ if (process.platform !== "darwin" || alreadyDoneSignCheck) {
351
+ return;
352
+ }
353
+ alreadyDoneSignCheck = true;
354
+ d("checking if ripgrep is already signed");
355
+ const lines = (await execFileNoThrow(
356
+ "codesign",
357
+ ["-vv", "-d", await getRipgrepPath()],
358
+ void 0,
359
+ void 0,
360
+ false
361
+ )).stdout.split("\n");
362
+ const needsSigned = lines.find((line) => line.includes("linker-signed"));
363
+ if (!needsSigned) {
364
+ d("seems to be already signed");
365
+ return;
366
+ }
367
+ try {
368
+ d("signing ripgrep");
369
+ const signResult = await execFileNoThrow("codesign", [
370
+ "--sign",
371
+ "-",
372
+ "--force",
373
+ "--preserve-metadata=entitlements,requirements,flags,runtime",
374
+ await getRipgrepPath()
375
+ ]);
376
+ if (signResult.code !== 0) {
377
+ d("failed to sign ripgrep: %o", signResult);
378
+ logError(
379
+ `Failed to sign ripgrep: ${signResult.stdout} ${signResult.stderr}`
380
+ );
381
+ }
382
+ d("removing quarantine");
383
+ const quarantineResult = await execFileNoThrow("xattr", [
384
+ "-d",
385
+ "com.apple.quarantine",
386
+ await getRipgrepPath()
387
+ ]);
388
+ if (quarantineResult.code !== 0) {
389
+ d("failed to remove quarantine: %o", quarantineResult);
390
+ logError(
391
+ `Failed to remove quarantine: ${quarantineResult.stdout} ${quarantineResult.stderr}`
392
+ );
393
+ }
394
+ } catch (e) {
395
+ d("failed during sign: %o", e);
396
+ logError(e);
397
+ }
398
+ }
399
+ function resetRipgrepPathCacheForTests() {
400
+ ;
401
+ getRipgrepPath.cache?.clear?.();
402
+ alreadyDoneSignCheck = false;
403
+ }
404
+ function filesToTree(files, cwd, limit = 50) {
405
+ if (files.length === 0) return "";
406
+ const relFiles = files.map((f) => {
407
+ if (isAbsolute(f)) return relative(cwd, f);
408
+ return f;
409
+ });
410
+ const treeRoot = {};
411
+ for (const f of relFiles) {
412
+ const parts = f.split(sep);
413
+ let cur = treeRoot;
414
+ for (const p of parts) {
415
+ if (!cur[p]) cur[p] = {};
416
+ cur = cur[p];
417
+ }
418
+ }
419
+ const visible = /* @__PURE__ */ new Set();
420
+ const queue = [treeRoot];
421
+ visible.add(treeRoot);
422
+ let visibleCount = 0;
423
+ while (queue.length > 0) {
424
+ const node = queue.shift();
425
+ const children = Object.values(node);
426
+ for (const child of children) {
427
+ if (visibleCount < limit) {
428
+ visible.add(child);
429
+ visibleCount++;
430
+ queue.push(child);
431
+ } else {
432
+ break;
433
+ }
434
+ }
435
+ if (visibleCount >= limit) break;
436
+ }
437
+ let output = "";
438
+ function render(node, prefix, isLast, name) {
439
+ if (node !== treeRoot) {
440
+ const connector = isLast ? "\u2514\u2500\u2500 " : "\u251C\u2500\u2500 ";
441
+ output += `${prefix}${connector}${name}
442
+ `;
443
+ } else {
444
+ output += `${name}
445
+ `;
446
+ }
447
+ const childrenKeys = Object.keys(node).sort();
448
+ const visibleChildren = childrenKeys.filter((k) => visible.has(node[k]));
449
+ const hiddenCount = childrenKeys.length - visibleChildren.length;
450
+ const childPrefix = node === treeRoot ? "" : prefix + (isLast ? " " : "\u2502 ");
451
+ for (let i = 0; i < visibleChildren.length; i++) {
452
+ const key = visibleChildren[i];
453
+ const isChildLast = i === visibleChildren.length - 1 && hiddenCount === 0;
454
+ render(node[key], childPrefix, isChildLast, key);
455
+ }
456
+ if (hiddenCount > 0) {
457
+ const connector = "\u2514\u2500\u2500 ";
458
+ output += `${childPrefix}${connector}... [${hiddenCount} truncated]
459
+ `;
460
+ }
461
+ }
462
+ render(treeRoot, "", true, basename(cwd) || ".");
463
+ return output;
464
+ }
465
+ async function tree(cwd, limit = 50, abortSignal) {
466
+ const files = await ripGrep(["--files"], cwd, abortSignal);
467
+ return filesToTree(files, cwd, limit);
468
+ }
469
+
470
+ export {
471
+ getRipgrepPath,
472
+ ripGrepWithStatus,
473
+ ripGrep,
474
+ listAllContentFiles,
475
+ resetRipgrepPathCacheForTests,
476
+ filesToTree,
477
+ tree
478
+ };