@within-7/minto 0.1.5 → 0.1.7

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 (273) hide show
  1. package/dist/commands/agents/AgentsCommand.js +2342 -0
  2. package/dist/commands/agents/AgentsCommand.js.map +7 -0
  3. package/dist/commands/agents/constants.js +58 -0
  4. package/dist/commands/agents/constants.js.map +7 -0
  5. package/dist/commands/agents/index.js +37 -0
  6. package/dist/commands/agents/index.js.map +7 -0
  7. package/dist/commands/agents/types.js +10 -0
  8. package/dist/commands/agents/types.js.map +7 -0
  9. package/dist/commands/agents/utils/fileOperations.js +185 -0
  10. package/dist/commands/agents/utils/fileOperations.js.map +7 -0
  11. package/dist/commands/agents/utils/index.js +21 -0
  12. package/dist/commands/agents/utils/index.js.map +7 -0
  13. package/dist/commands/bug.js +2 -2
  14. package/dist/commands/bug.js.map +2 -2
  15. package/dist/commands/compact.js +5 -5
  16. package/dist/commands/compact.js.map +2 -2
  17. package/dist/commands/ctx_viz.js +55 -22
  18. package/dist/commands/ctx_viz.js.map +2 -2
  19. package/dist/commands/mcp-interactive.js +11 -11
  20. package/dist/commands/mcp-interactive.js.map +2 -2
  21. package/dist/commands/model.js +94 -32
  22. package/dist/commands/model.js.map +3 -3
  23. package/dist/commands/plugin/AddMarketplaceForm.js +49 -21
  24. package/dist/commands/plugin/AddMarketplaceForm.js.map +2 -2
  25. package/dist/commands/plugin/ConfirmDialog.js +38 -26
  26. package/dist/commands/plugin/ConfirmDialog.js.map +2 -2
  27. package/dist/commands/plugin/InstalledPluginsByMarketplace.js +24 -8
  28. package/dist/commands/plugin/InstalledPluginsByMarketplace.js.map +2 -2
  29. package/dist/commands/plugin/InstalledPluginsManager.js +3 -1
  30. package/dist/commands/plugin/InstalledPluginsManager.js.map +2 -2
  31. package/dist/commands/plugin/MainMenu.js +16 -7
  32. package/dist/commands/plugin/MainMenu.js.map +2 -2
  33. package/dist/commands/plugin/MarketplaceManager.js +84 -39
  34. package/dist/commands/plugin/MarketplaceManager.js.map +2 -2
  35. package/dist/commands/plugin/MarketplaceSelector.js +7 -3
  36. package/dist/commands/plugin/MarketplaceSelector.js.map +2 -2
  37. package/dist/commands/plugin/PlaceholderScreen.js +16 -2
  38. package/dist/commands/plugin/PlaceholderScreen.js.map +2 -2
  39. package/dist/commands/plugin/PluginBrowser.js +4 -2
  40. package/dist/commands/plugin/PluginBrowser.js.map +2 -2
  41. package/dist/commands/plugin/PluginDetailsInstall.js +12 -6
  42. package/dist/commands/plugin/PluginDetailsInstall.js.map +2 -2
  43. package/dist/commands/plugin/PluginDetailsManage.js +14 -5
  44. package/dist/commands/plugin/PluginDetailsManage.js.map +2 -2
  45. package/dist/commands/plugin/example-usage.js.map +2 -2
  46. package/dist/commands/plugin/utils.js.map +2 -2
  47. package/dist/commands/plugin.js +226 -46
  48. package/dist/commands/plugin.js.map +2 -2
  49. package/dist/commands/refreshCommands.js +6 -3
  50. package/dist/commands/refreshCommands.js.map +2 -2
  51. package/dist/commands/resume.js +2 -1
  52. package/dist/commands/resume.js.map +2 -2
  53. package/dist/commands/setup.js +19 -5
  54. package/dist/commands/setup.js.map +2 -2
  55. package/dist/commands/terminalSetup.js +2 -2
  56. package/dist/commands/terminalSetup.js.map +1 -1
  57. package/dist/commands.js +14 -30
  58. package/dist/commands.js.map +2 -2
  59. package/dist/components/AskUserQuestionDialog/AskUserQuestionDialog.js.map +2 -2
  60. package/dist/components/AskUserQuestionDialog/QuestionView.js +10 -1
  61. package/dist/components/AskUserQuestionDialog/QuestionView.js.map +2 -2
  62. package/dist/components/BackgroundTasksPanel.js +5 -1
  63. package/dist/components/BackgroundTasksPanel.js.map +2 -2
  64. package/dist/components/Config.js +17 -4
  65. package/dist/components/Config.js.map +2 -2
  66. package/dist/components/ConsoleOAuthFlow.js.map +2 -2
  67. package/dist/components/CustomSelect/select-option.js +4 -1
  68. package/dist/components/CustomSelect/select-option.js.map +2 -2
  69. package/dist/components/Help.js +6 -8
  70. package/dist/components/Help.js.map +2 -2
  71. package/dist/components/Logo.js +1 -1
  72. package/dist/components/Logo.js.map +2 -2
  73. package/dist/components/ModelListManager.js.map +2 -2
  74. package/dist/components/ModelSelector/ModelSelector.js +2030 -0
  75. package/dist/components/ModelSelector/ModelSelector.js.map +7 -0
  76. package/dist/components/ModelSelector/ScreenContainer.js +27 -0
  77. package/dist/components/ModelSelector/ScreenContainer.js.map +7 -0
  78. package/dist/components/ModelSelector/constants.js +37 -0
  79. package/dist/components/ModelSelector/constants.js.map +7 -0
  80. package/dist/components/ModelSelector/hooks/index.js +5 -0
  81. package/dist/components/ModelSelector/hooks/index.js.map +7 -0
  82. package/dist/components/ModelSelector/hooks/useEscapeNavigation.js +21 -0
  83. package/dist/components/ModelSelector/hooks/useEscapeNavigation.js.map +7 -0
  84. package/dist/components/ModelSelector/index.js +17 -0
  85. package/dist/components/ModelSelector/index.js.map +7 -0
  86. package/dist/components/ModelSelector/types.js +1 -0
  87. package/dist/components/ModelSelector/types.js.map +7 -0
  88. package/dist/components/PressEnterToContinue.js +1 -1
  89. package/dist/components/PressEnterToContinue.js.map +2 -2
  90. package/dist/components/ProjectOnboarding.js +1 -1
  91. package/dist/components/ProjectOnboarding.js.map +2 -2
  92. package/dist/components/PromptInput.js +88 -37
  93. package/dist/components/PromptInput.js.map +2 -2
  94. package/dist/components/QuitSummary.js +17 -10
  95. package/dist/components/QuitSummary.js.map +2 -2
  96. package/dist/components/SentryErrorBoundary.js.map +2 -2
  97. package/dist/components/StreamingBashOutput.js.map +2 -2
  98. package/dist/components/StructuredDiff.js.map +2 -2
  99. package/dist/components/SubagentProgress.js.map +2 -2
  100. package/dist/components/TaskCard.js.map +2 -2
  101. package/dist/components/TextInput.js.map +1 -1
  102. package/dist/components/TodoItem.js.map +1 -1
  103. package/dist/components/binary-feedback/BinaryFeedbackOption.js +1 -3
  104. package/dist/components/binary-feedback/BinaryFeedbackOption.js.map +2 -2
  105. package/dist/components/messages/AssistantLocalCommandOutputMessage.js.map +1 -1
  106. package/dist/components/messages/AssistantToolUseMessage.js +3 -1
  107. package/dist/components/messages/AssistantToolUseMessage.js.map +2 -2
  108. package/dist/components/messages/TaskProgressMessage.js.map +2 -2
  109. package/dist/components/messages/TaskToolMessage.js.map +2 -2
  110. package/dist/components/messages/UserToolResultMessage/utils.js.map +2 -2
  111. package/dist/components/permissions/FileEditPermissionRequest/FileEditToolDiff.js.map +2 -2
  112. package/dist/components/permissions/FileWritePermissionRequest/FileWriteToolDiff.js.map +2 -2
  113. package/dist/components/permissions/hooks.js.map +2 -2
  114. package/dist/constants/modelCapabilities.js +1 -1
  115. package/dist/constants/modelCapabilities.js.map +2 -2
  116. package/dist/constants/prompts.js.map +1 -1
  117. package/dist/constants/timing.js +34 -0
  118. package/dist/constants/timing.js.map +7 -0
  119. package/dist/entrypoints/cli.js +128 -33
  120. package/dist/entrypoints/cli.js.map +3 -3
  121. package/dist/entrypoints/mcp.js +13 -18
  122. package/dist/entrypoints/mcp.js.map +2 -2
  123. package/dist/hooks/useCanUseTool.js.map +2 -2
  124. package/dist/hooks/useCancelRequest.js.map +1 -1
  125. package/dist/hooks/useHistorySearch.js.map +2 -2
  126. package/dist/hooks/useLogStartupTime.js.map +2 -2
  127. package/dist/hooks/usePermissionRequestLogging.js.map +2 -2
  128. package/dist/hooks/useTextInput.js.map +1 -1
  129. package/dist/hooks/useUnifiedCompletion.js +493 -394
  130. package/dist/hooks/useUnifiedCompletion.js.map +2 -2
  131. package/dist/index.js.map +2 -2
  132. package/dist/permissions.js +4 -7
  133. package/dist/permissions.js.map +2 -2
  134. package/dist/query.js +6 -1
  135. package/dist/query.js.map +2 -2
  136. package/dist/screens/REPL.js +72 -36
  137. package/dist/screens/REPL.js.map +2 -2
  138. package/dist/screens/ResumeConversation.js +2 -1
  139. package/dist/screens/ResumeConversation.js.map +2 -2
  140. package/dist/services/adapters/base.js.map +2 -2
  141. package/dist/services/adapters/chatCompletions.js.map +2 -2
  142. package/dist/services/adapters/responsesAPI.js +3 -1
  143. package/dist/services/adapters/responsesAPI.js.map +2 -2
  144. package/dist/services/claude.js +327 -328
  145. package/dist/services/claude.js.map +2 -2
  146. package/dist/services/customCommands.js +6 -1
  147. package/dist/services/customCommands.js.map +2 -2
  148. package/dist/services/fileFreshness.js.map +2 -2
  149. package/dist/services/gpt5ConnectionTest.js +20 -7
  150. package/dist/services/gpt5ConnectionTest.js.map +2 -2
  151. package/dist/services/hookExecutor.js +6 -12
  152. package/dist/services/hookExecutor.js.map +2 -2
  153. package/dist/services/mcpClient.js +29 -2
  154. package/dist/services/mcpClient.js.map +2 -2
  155. package/dist/services/mentionProcessor.js +23 -10
  156. package/dist/services/mentionProcessor.js.map +2 -2
  157. package/dist/services/modelAdapterFactory.js.map +2 -2
  158. package/dist/services/oauth.js.map +2 -2
  159. package/dist/services/openai.js +109 -72
  160. package/dist/services/openai.js.map +3 -3
  161. package/dist/services/responseStateManager.js.map +2 -2
  162. package/dist/services/systemReminder.js.map +2 -2
  163. package/dist/tools/ArchitectTool/ArchitectTool.js +10 -9
  164. package/dist/tools/ArchitectTool/ArchitectTool.js.map +2 -2
  165. package/dist/tools/AskExpertModelTool/AskExpertModelTool.js +14 -8
  166. package/dist/tools/AskExpertModelTool/AskExpertModelTool.js.map +2 -2
  167. package/dist/tools/AskUserQuestionTool/AskUserQuestionTool.js +8 -1
  168. package/dist/tools/AskUserQuestionTool/AskUserQuestionTool.js.map +2 -2
  169. package/dist/tools/BashOutputTool/BashOutputTool.js.map +2 -2
  170. package/dist/tools/BashTool/BashTool.js.map +2 -2
  171. package/dist/tools/FileReadTool/FileReadTool.js +23 -4
  172. package/dist/tools/FileReadTool/FileReadTool.js.map +2 -2
  173. package/dist/tools/FileWriteTool/FileWriteTool.js.map +2 -2
  174. package/dist/tools/GlobTool/GlobTool.js +11 -2
  175. package/dist/tools/GlobTool/GlobTool.js.map +2 -2
  176. package/dist/tools/GrepTool/GrepTool.js +7 -5
  177. package/dist/tools/GrepTool/GrepTool.js.map +2 -2
  178. package/dist/tools/MCPTool/MCPTool.js +11 -12
  179. package/dist/tools/MCPTool/MCPTool.js.map +2 -2
  180. package/dist/tools/MultiEditTool/MultiEditTool.js +4 -1
  181. package/dist/tools/MultiEditTool/MultiEditTool.js.map +2 -2
  182. package/dist/tools/NotebookReadTool/NotebookReadTool.js +11 -5
  183. package/dist/tools/NotebookReadTool/NotebookReadTool.js.map +2 -2
  184. package/dist/tools/SkillTool/SkillTool.js +18 -6
  185. package/dist/tools/SkillTool/SkillTool.js.map +2 -2
  186. package/dist/tools/TaskTool/TaskTool.js +37 -51
  187. package/dist/tools/TaskTool/TaskTool.js.map +2 -2
  188. package/dist/tools/TaskTool/prompt.js.map +2 -2
  189. package/dist/tools/ThinkTool/ThinkTool.js +6 -1
  190. package/dist/tools/ThinkTool/ThinkTool.js.map +2 -2
  191. package/dist/tools/TodoWriteTool/TodoWriteTool.js +29 -5
  192. package/dist/tools/TodoWriteTool/TodoWriteTool.js.map +2 -2
  193. package/dist/tools/URLFetcherTool/URLFetcherTool.js +5 -2
  194. package/dist/tools/URLFetcherTool/URLFetcherTool.js.map +2 -2
  195. package/dist/tools/URLFetcherTool/cache.js +6 -3
  196. package/dist/tools/URLFetcherTool/cache.js.map +2 -2
  197. package/dist/tools/URLFetcherTool/htmlToMarkdown.js +3 -1
  198. package/dist/tools/URLFetcherTool/htmlToMarkdown.js.map +2 -2
  199. package/dist/tools/WebSearchTool/WebSearchTool.js +6 -1
  200. package/dist/tools/WebSearchTool/WebSearchTool.js.map +2 -2
  201. package/dist/tools/WebSearchTool/prompt.js.map +2 -2
  202. package/dist/tools/WebSearchTool/searchProviders.js +15 -6
  203. package/dist/tools/WebSearchTool/searchProviders.js.map +2 -2
  204. package/dist/tools.js +4 -1
  205. package/dist/tools.js.map +2 -2
  206. package/dist/types/core.js +1 -0
  207. package/dist/types/core.js.map +7 -0
  208. package/dist/types/hooks.js +1 -4
  209. package/dist/types/hooks.js.map +2 -2
  210. package/dist/types/marketplace.js +8 -2
  211. package/dist/types/marketplace.js.map +2 -2
  212. package/dist/types/plugin.js +9 -6
  213. package/dist/types/plugin.js.map +2 -2
  214. package/dist/utils/BackgroundShellManager.js +76 -10
  215. package/dist/utils/BackgroundShellManager.js.map +2 -2
  216. package/dist/utils/PersistentShell.js +7 -2
  217. package/dist/utils/PersistentShell.js.map +2 -2
  218. package/dist/utils/advancedFuzzyMatcher.js +4 -1
  219. package/dist/utils/advancedFuzzyMatcher.js.map +2 -2
  220. package/dist/utils/agentLoader.js +69 -35
  221. package/dist/utils/agentLoader.js.map +2 -2
  222. package/dist/utils/agentStorage.js.map +2 -2
  223. package/dist/utils/async.js +163 -0
  224. package/dist/utils/async.js.map +7 -0
  225. package/dist/utils/autoUpdater.js +8 -2
  226. package/dist/utils/autoUpdater.js.map +2 -2
  227. package/dist/utils/commands.js +23 -11
  228. package/dist/utils/commands.js.map +2 -2
  229. package/dist/utils/commonUnixCommands.js +3 -1
  230. package/dist/utils/commonUnixCommands.js.map +2 -2
  231. package/dist/utils/compressionMode.js.map +2 -2
  232. package/dist/utils/config.js +30 -14
  233. package/dist/utils/config.js.map +2 -2
  234. package/dist/utils/debugLogger.js.map +2 -2
  235. package/dist/utils/env.js.map +2 -2
  236. package/dist/utils/envConfig.js +82 -0
  237. package/dist/utils/envConfig.js.map +7 -0
  238. package/dist/utils/errorHandling.js +89 -0
  239. package/dist/utils/errorHandling.js.map +7 -0
  240. package/dist/utils/expertChatStorage.js.map +2 -2
  241. package/dist/utils/fuzzyMatcher.js +13 -7
  242. package/dist/utils/fuzzyMatcher.js.map +2 -2
  243. package/dist/utils/hookManager.js +14 -4
  244. package/dist/utils/hookManager.js.map +2 -2
  245. package/dist/utils/log.js.map +2 -2
  246. package/dist/utils/marketplaceManager.js +44 -9
  247. package/dist/utils/marketplaceManager.js.map +2 -2
  248. package/dist/utils/messageContextManager.js.map +1 -1
  249. package/dist/utils/messages.js +6 -3
  250. package/dist/utils/messages.js.map +2 -2
  251. package/dist/utils/model.js +3 -1
  252. package/dist/utils/model.js.map +2 -2
  253. package/dist/utils/pluginInstaller.js +3 -15
  254. package/dist/utils/pluginInstaller.js.map +2 -2
  255. package/dist/utils/pluginLoader.js +41 -13
  256. package/dist/utils/pluginLoader.js.map +2 -2
  257. package/dist/utils/pluginRegistry.js.map +2 -2
  258. package/dist/utils/pluginValidator.js +71 -49
  259. package/dist/utils/pluginValidator.js.map +2 -2
  260. package/dist/utils/ptyCompat.js.map +2 -2
  261. package/dist/utils/roundConverter.js.map +2 -2
  262. package/dist/utils/secureFile.js +43 -14
  263. package/dist/utils/secureFile.js.map +2 -2
  264. package/dist/utils/sessionState.js.map +2 -2
  265. package/dist/utils/skillLoader.js.map +2 -2
  266. package/dist/utils/teamConfig.js +7 -4
  267. package/dist/utils/teamConfig.js.map +2 -2
  268. package/dist/utils/theme.js.map +2 -2
  269. package/dist/utils/thinking.js.map +2 -2
  270. package/dist/utils/unaryLogging.js.map +2 -2
  271. package/dist/version.js +2 -2
  272. package/dist/version.js.map +1 -1
  273. package/package.json +5 -5
@@ -3,9 +3,41 @@ import { EventEmitter } from "events";
3
3
  import { randomUUID } from "crypto";
4
4
  import { logError } from "./log.js";
5
5
  const MAX_OUTPUT_LINES = 1e3;
6
+ const REGEX_CACHE_SIZE = 50;
7
+ class RegExpCache {
8
+ cache = /* @__PURE__ */ new Map();
9
+ maxSize;
10
+ constructor(maxSize = REGEX_CACHE_SIZE) {
11
+ this.maxSize = maxSize;
12
+ }
13
+ get(pattern) {
14
+ const regex = this.cache.get(pattern);
15
+ if (regex) {
16
+ this.cache.delete(pattern);
17
+ this.cache.set(pattern, regex);
18
+ }
19
+ return regex;
20
+ }
21
+ set(pattern, regex) {
22
+ if (this.cache.size >= this.maxSize) {
23
+ const oldest = this.cache.keys().next().value;
24
+ if (oldest) this.cache.delete(oldest);
25
+ }
26
+ this.cache.set(pattern, regex);
27
+ }
28
+ getOrCreate(pattern) {
29
+ let regex = this.get(pattern);
30
+ if (!regex) {
31
+ regex = new RegExp(pattern);
32
+ this.set(pattern, regex);
33
+ }
34
+ return regex;
35
+ }
36
+ }
6
37
  class BackgroundShellManager extends EventEmitter {
7
38
  static instance = null;
8
39
  shells = /* @__PURE__ */ new Map();
40
+ regexCache = new RegExpCache();
9
41
  constructor() {
10
42
  super();
11
43
  }
@@ -48,7 +80,10 @@ class BackgroundShellManager extends EventEmitter {
48
80
  if (shell.stdout.length > MAX_OUTPUT_LINES) {
49
81
  const removed = shell.stdout.length - MAX_OUTPUT_LINES;
50
82
  shell.stdout = shell.stdout.slice(removed);
51
- shell.lastReadStdoutIndex = Math.max(0, shell.lastReadStdoutIndex - removed);
83
+ shell.lastReadStdoutIndex = Math.max(
84
+ 0,
85
+ shell.lastReadStdoutIndex - removed
86
+ );
52
87
  }
53
88
  this.emit("output", shellId, "stdout", lines);
54
89
  });
@@ -58,7 +93,10 @@ class BackgroundShellManager extends EventEmitter {
58
93
  if (shell.stderr.length > MAX_OUTPUT_LINES) {
59
94
  const removed = shell.stderr.length - MAX_OUTPUT_LINES;
60
95
  shell.stderr = shell.stderr.slice(removed);
61
- shell.lastReadStderrIndex = Math.max(0, shell.lastReadStderrIndex - removed);
96
+ shell.lastReadStderrIndex = Math.max(
97
+ 0,
98
+ shell.lastReadStderrIndex - removed
99
+ );
62
100
  }
63
101
  this.emit("output", shellId, "stderr", lines);
64
102
  });
@@ -67,17 +105,27 @@ class BackgroundShellManager extends EventEmitter {
67
105
  shell.exitCode = code ?? void 0;
68
106
  shell.endTime = Date.now();
69
107
  this.emit("statusChange", shellId, shell.status);
108
+ this.emitListChange();
70
109
  });
71
110
  childProcess.on("error", (error) => {
72
111
  logError(`Background shell ${shellId} error: ${error.message}`);
73
112
  shell.status = "killed";
74
113
  shell.endTime = Date.now();
75
114
  this.emit("statusChange", shellId, shell.status);
115
+ this.emitListChange();
76
116
  });
77
117
  this.shells.set(shellId, shell);
78
118
  this.emit("shellCreated", shellId);
119
+ this.emitListChange();
79
120
  return shellId;
80
121
  }
122
+ /**
123
+ * Emit a list change event with the current shell list
124
+ * Used for event-driven updates instead of polling
125
+ */
126
+ emitListChange() {
127
+ this.emit("listChange", this.list());
128
+ }
81
129
  /**
82
130
  * Get a background shell by ID
83
131
  */
@@ -94,7 +142,7 @@ class BackgroundShellManager extends EventEmitter {
94
142
  let newStderr = shell.stderr.slice(shell.lastReadStderrIndex);
95
143
  if (filter) {
96
144
  try {
97
- const regex = new RegExp(filter);
145
+ const regex = this.regexCache.getOrCreate(filter);
98
146
  newStdout = newStdout.filter((line) => regex.test(line));
99
147
  newStderr = newStderr.filter((line) => regex.test(line));
100
148
  } catch (e) {
@@ -122,39 +170,55 @@ class BackgroundShellManager extends EventEmitter {
122
170
  kill(shellId) {
123
171
  const shell = this.shells.get(shellId);
124
172
  if (!shell) {
125
- console.log(`[BackgroundShellManager] Cannot kill: shell ${shellId} not found`);
173
+ console.log(
174
+ `[BackgroundShellManager] Cannot kill: shell ${shellId} not found`
175
+ );
126
176
  return false;
127
177
  }
128
178
  if (shell.status === "running") {
129
179
  try {
130
180
  const pid = shell.process.pid;
131
181
  if (!pid) {
132
- console.log(`[BackgroundShellManager] Cannot kill: shell ${shellId} has no PID`);
182
+ console.log(
183
+ `[BackgroundShellManager] Cannot kill: shell ${shellId} has no PID`
184
+ );
133
185
  return false;
134
186
  }
135
- console.log(`[BackgroundShellManager] Killing shell ${shellId} (PID: ${pid}, command: ${shell.command})`);
187
+ console.log(
188
+ `[BackgroundShellManager] Killing shell ${shellId} (PID: ${pid}, command: ${shell.command})`
189
+ );
136
190
  if (process.platform === "win32") {
137
191
  spawn("taskkill", ["/pid", pid.toString(), "/f", "/t"]);
138
192
  } else {
139
193
  try {
140
194
  process.kill(-pid, "SIGKILL");
141
- console.log(`[BackgroundShellManager] Sent SIGKILL to process group -${pid}`);
195
+ console.log(
196
+ `[BackgroundShellManager] Sent SIGKILL to process group -${pid}`
197
+ );
142
198
  } catch (e) {
143
- console.log(`[BackgroundShellManager] Process group kill failed, trying main process only`);
199
+ console.log(
200
+ `[BackgroundShellManager] Process group kill failed, trying main process only`
201
+ );
144
202
  process.kill(pid, "SIGKILL");
145
203
  }
146
204
  }
147
205
  shell.status = "killed";
148
206
  shell.endTime = Date.now();
149
207
  this.emit("statusChange", shellId, "killed");
208
+ this.emitListChange();
150
209
  return true;
151
210
  } catch (error) {
152
- console.error(`[BackgroundShellManager] Failed to kill shell ${shellId}:`, error);
211
+ console.error(
212
+ `[BackgroundShellManager] Failed to kill shell ${shellId}:`,
213
+ error
214
+ );
153
215
  logError(`Failed to kill shell ${shellId}: ${error}`);
154
216
  return false;
155
217
  }
156
218
  }
157
- console.log(`[BackgroundShellManager] Shell ${shellId} is not running (status: ${shell.status})`);
219
+ console.log(
220
+ `[BackgroundShellManager] Shell ${shellId} is not running (status: ${shell.status})`
221
+ );
158
222
  return false;
159
223
  }
160
224
  /**
@@ -178,6 +242,7 @@ class BackgroundShellManager extends EventEmitter {
178
242
  if (!shell || shell.status === "running") return false;
179
243
  this.shells.delete(shellId);
180
244
  this.emit("shellRemoved", shellId);
245
+ this.emitListChange();
181
246
  return true;
182
247
  }
183
248
  /**
@@ -194,6 +259,7 @@ class BackgroundShellManager extends EventEmitter {
194
259
  }
195
260
  if (removed > 0) {
196
261
  this.emit("cleaned", removed);
262
+ this.emitListChange();
197
263
  }
198
264
  return removed;
199
265
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/utils/BackgroundShellManager.ts"],
4
- "sourcesContent": ["import { spawn, type ChildProcess } from 'child_process'\nimport { EventEmitter } from 'events'\nimport { randomUUID } from 'crypto'\nimport { logError } from './log'\n\nexport type BackgroundShellStatus = 'running' | 'done' | 'killed'\n\nexport interface BackgroundShell {\n id: string\n command: string\n status: BackgroundShellStatus\n startTime: number\n endTime?: number\n process: ChildProcess\n stdout: string[]\n stderr: string[]\n exitCode?: number\n lastReadStdoutIndex: number\n lastReadStderrIndex: number\n}\n\nconst MAX_OUTPUT_LINES = 1000 // Keep last N lines in memory\n\nexport class BackgroundShellManager extends EventEmitter {\n private static instance: BackgroundShellManager | null = null\n private shells: Map<string, BackgroundShell> = new Map()\n\n private constructor() {\n super()\n }\n\n static getInstance(): BackgroundShellManager {\n if (!BackgroundShellManager.instance) {\n BackgroundShellManager.instance = new BackgroundShellManager()\n }\n return BackgroundShellManager.instance\n }\n\n /**\n * Create a new background shell and start executing the command\n */\n create(command: string, cwd?: string): string {\n const shellId = randomUUID().slice(0, 8)\n\n // Spawn the command in a shell\n const childProcess = spawn(command, [], {\n shell: true,\n cwd: cwd || process.cwd(),\n stdio: ['ignore', 'pipe', 'pipe'],\n detached: true, // Create a new process group for easier cleanup\n env: {\n ...process.env,\n GIT_EDITOR: 'true',\n },\n })\n\n const shell: BackgroundShell = {\n id: shellId,\n command,\n status: 'running',\n startTime: Date.now(),\n process: childProcess,\n stdout: [],\n stderr: [],\n lastReadStdoutIndex: 0,\n lastReadStderrIndex: 0,\n }\n\n // Capture stdout\n childProcess.stdout?.on('data', (data: Buffer) => {\n const lines = data.toString().split('\\n')\n shell.stdout.push(...lines)\n\n // Keep only last MAX_OUTPUT_LINES\n if (shell.stdout.length > MAX_OUTPUT_LINES) {\n const removed = shell.stdout.length - MAX_OUTPUT_LINES\n shell.stdout = shell.stdout.slice(removed)\n shell.lastReadStdoutIndex = Math.max(0, shell.lastReadStdoutIndex - removed)\n }\n\n this.emit('output', shellId, 'stdout', lines)\n })\n\n // Capture stderr\n childProcess.stderr?.on('data', (data: Buffer) => {\n const lines = data.toString().split('\\n')\n shell.stderr.push(...lines)\n\n // Keep only last MAX_OUTPUT_LINES\n if (shell.stderr.length > MAX_OUTPUT_LINES) {\n const removed = shell.stderr.length - MAX_OUTPUT_LINES\n shell.stderr = shell.stderr.slice(removed)\n shell.lastReadStderrIndex = Math.max(0, shell.lastReadStderrIndex - removed)\n }\n\n this.emit('output', shellId, 'stderr', lines)\n })\n\n // Handle process exit\n childProcess.on('exit', (code, signal) => {\n shell.status = signal ? 'killed' : 'done'\n shell.exitCode = code ?? undefined\n shell.endTime = Date.now()\n this.emit('statusChange', shellId, shell.status)\n })\n\n childProcess.on('error', (error) => {\n logError(`Background shell ${shellId} error: ${error.message}`)\n shell.status = 'killed'\n shell.endTime = Date.now()\n this.emit('statusChange', shellId, shell.status)\n })\n\n this.shells.set(shellId, shell)\n this.emit('shellCreated', shellId)\n\n return shellId\n }\n\n /**\n * Get a background shell by ID\n */\n get(shellId: string): BackgroundShell | undefined {\n return this.shells.get(shellId)\n }\n\n /**\n * Get new output since last read\n */\n getNewOutput(shellId: string, filter?: string): {\n stdout: string[]\n stderr: string[]\n } | null {\n const shell = this.shells.get(shellId)\n if (!shell) return null\n\n let newStdout = shell.stdout.slice(shell.lastReadStdoutIndex)\n let newStderr = shell.stderr.slice(shell.lastReadStderrIndex)\n\n // Apply regex filter if provided\n if (filter) {\n try {\n const regex = new RegExp(filter)\n newStdout = newStdout.filter(line => regex.test(line))\n newStderr = newStderr.filter(line => regex.test(line))\n } catch (e) {\n logError(`Invalid regex filter: ${filter}`)\n }\n }\n\n // Update read indices\n shell.lastReadStdoutIndex = shell.stdout.length\n shell.lastReadStderrIndex = shell.stderr.length\n\n return { stdout: newStdout, stderr: newStderr }\n }\n\n /**\n * Get all output (entire buffer)\n */\n getAllOutput(shellId: string): {\n stdout: string[]\n stderr: string[]\n } | null {\n const shell = this.shells.get(shellId)\n if (!shell) return null\n\n return {\n stdout: [...shell.stdout],\n stderr: [...shell.stderr],\n }\n }\n\n /**\n * Kill a background shell\n */\n kill(shellId: string): boolean {\n const shell = this.shells.get(shellId)\n if (!shell) {\n console.log(`[BackgroundShellManager] Cannot kill: shell ${shellId} not found`)\n return false\n }\n\n if (shell.status === 'running') {\n try {\n const pid = shell.process.pid\n if (!pid) {\n console.log(`[BackgroundShellManager] Cannot kill: shell ${shellId} has no PID`)\n return false\n }\n\n console.log(`[BackgroundShellManager] Killing shell ${shellId} (PID: ${pid}, command: ${shell.command})`)\n\n // Kill the process and all its children\n if (process.platform === 'win32') {\n spawn('taskkill', ['/pid', pid.toString(), '/f', '/t'])\n } else {\n // Send SIGKILL to process group (more forceful than SIGTERM)\n // The negative PID sends signal to the entire process group\n try {\n process.kill(-pid, 'SIGKILL')\n console.log(`[BackgroundShellManager] Sent SIGKILL to process group -${pid}`)\n } catch (e) {\n // If process group kill fails, try killing just the main process\n console.log(`[BackgroundShellManager] Process group kill failed, trying main process only`)\n process.kill(pid, 'SIGKILL')\n }\n }\n\n shell.status = 'killed'\n shell.endTime = Date.now()\n this.emit('statusChange', shellId, 'killed')\n return true\n } catch (error) {\n console.error(`[BackgroundShellManager] Failed to kill shell ${shellId}:`, error)\n logError(`Failed to kill shell ${shellId}: ${error}`)\n return false\n }\n }\n\n console.log(`[BackgroundShellManager] Shell ${shellId} is not running (status: ${shell.status})`)\n return false\n }\n\n /**\n * List all background shells\n */\n list(): BackgroundShell[] {\n return Array.from(this.shells.values())\n }\n\n /**\n * Get shell status\n */\n getStatus(shellId: string): BackgroundShellStatus | null {\n const shell = this.shells.get(shellId)\n return shell ? shell.status : null\n }\n\n /**\n * Remove a shell from the manager (only if done or killed)\n */\n remove(shellId: string): boolean {\n const shell = this.shells.get(shellId)\n if (!shell || shell.status === 'running') return false\n\n this.shells.delete(shellId)\n this.emit('shellRemoved', shellId)\n return true\n }\n\n /**\n * Clean up old completed/killed shells\n */\n cleanup(maxAge: number = 3600000): number {\n const now = Date.now()\n let removed = 0\n\n for (const [shellId, shell] of this.shells.entries()) {\n if (\n shell.status !== 'running' &&\n shell.endTime &&\n now - shell.endTime > maxAge\n ) {\n this.shells.delete(shellId)\n removed++\n }\n }\n\n if (removed > 0) {\n this.emit('cleaned', removed)\n }\n\n return removed\n }\n\n /**\n * Get summary of shell for display\n */\n getSummary(shellId: string): string | null {\n const shell = this.shells.get(shellId)\n if (!shell) return null\n\n const duration = shell.endTime\n ? Math.floor((shell.endTime - shell.startTime) / 1000)\n : Math.floor((Date.now() - shell.startTime) / 1000)\n\n // Get last few lines of output for preview\n const lastLines = shell.stdout.slice(-2).join(' ').slice(0, 50)\n const preview = lastLines ? ` ${lastLines}\u2026` : ''\n\n return `${shell.command}${preview}`\n }\n}\n"],
5
- "mappings": "AAAA,SAAS,aAAgC;AACzC,SAAS,oBAAoB;AAC7B,SAAS,kBAAkB;AAC3B,SAAS,gBAAgB;AAkBzB,MAAM,mBAAmB;AAElB,MAAM,+BAA+B,aAAa;AAAA,EACvD,OAAe,WAA0C;AAAA,EACjD,SAAuC,oBAAI,IAAI;AAAA,EAE/C,cAAc;AACpB,UAAM;AAAA,EACR;AAAA,EAEA,OAAO,cAAsC;AAC3C,QAAI,CAAC,uBAAuB,UAAU;AACpC,6BAAuB,WAAW,IAAI,uBAAuB;AAAA,IAC/D;AACA,WAAO,uBAAuB;AAAA,EAChC;AAAA;AAAA;AAAA;AAAA,EAKA,OAAO,SAAiB,KAAsB;AAC5C,UAAM,UAAU,WAAW,EAAE,MAAM,GAAG,CAAC;AAGvC,UAAM,eAAe,MAAM,SAAS,CAAC,GAAG;AAAA,MACtC,OAAO;AAAA,MACP,KAAK,OAAO,QAAQ,IAAI;AAAA,MACxB,OAAO,CAAC,UAAU,QAAQ,MAAM;AAAA,MAChC,UAAU;AAAA;AAAA,MACV,KAAK;AAAA,QACH,GAAG,QAAQ;AAAA,QACX,YAAY;AAAA,MACd;AAAA,IACF,CAAC;AAED,UAAM,QAAyB;AAAA,MAC7B,IAAI;AAAA,MACJ;AAAA,MACA,QAAQ;AAAA,MACR,WAAW,KAAK,IAAI;AAAA,MACpB,SAAS;AAAA,MACT,QAAQ,CAAC;AAAA,MACT,QAAQ,CAAC;AAAA,MACT,qBAAqB;AAAA,MACrB,qBAAqB;AAAA,IACvB;AAGA,iBAAa,QAAQ,GAAG,QAAQ,CAAC,SAAiB;AAChD,YAAM,QAAQ,KAAK,SAAS,EAAE,MAAM,IAAI;AACxC,YAAM,OAAO,KAAK,GAAG,KAAK;AAG1B,UAAI,MAAM,O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OAAO,QAAQ,GAAG;AACpD,UACE,MAAM,WAAW,aACjB,MAAM,WACN,MAAM,MAAM,UAAU,QACtB;AACA,aAAK,OAAO,OAAO,OAAO;AAC1B;AAAA,MACF;AAAA,IACF;AAEA,QAAI,UAAU,GAAG;AACf,WAAK,KAAK,WAAW,OAAO;AAAA,IAC9B;AAEA,WAAO;AAAA,EACT;AAAA;AAAA;AAAA;AAAA,EAKA,WAAW,SAAgC;AACzC,UAAM,QAAQ,KAAK,OAAO,IAAI,OAAO;AACrC,QAAI,CAAC,MAAO,QAAO;AAEnB,UAAM,WAAW,MAAM,UACnB,KAAK,OAAO,MAAM,UAAU,MAAM,aAAa,GAAI,IACnD,KAAK,OAAO,KAAK,IAAI,IAAI,MAAM,aAAa,GAAI;AAGpD,UAAM,YAAY,MAAM,OAAO,MAAM,EAAE,EAAE,KAAK,GAAG,EAAE,MAAM,GAAG,EAAE;AAC9D,UAAM,UAAU,YAAY,IAAI,SAAS,WAAM;AAE/C,WAAO,GAAG,MAAM,OAAO,GAAG,OAAO;AAAA,EACnC;AACF;",
4
+ "sourcesContent": ["import { spawn, type ChildProcess } from 'child_process'\nimport { EventEmitter } from 'events'\nimport { randomUUID } from 'crypto'\nimport { logError } from './log'\n\nexport type BackgroundShellStatus = 'running' | 'done' | 'killed'\n\nexport interface BackgroundShell {\n id: string\n command: string\n status: BackgroundShellStatus\n startTime: number\n endTime?: number\n process: ChildProcess\n stdout: string[]\n stderr: string[]\n exitCode?: number\n lastReadStdoutIndex: number\n lastReadStderrIndex: number\n}\n\nconst MAX_OUTPUT_LINES = 1000 // Keep last N lines in memory\nconst REGEX_CACHE_SIZE = 50 // LRU cache size for compiled regexes\n\n// Simple LRU cache for compiled RegExp objects\nclass RegExpCache {\n private cache = new Map<string, RegExp>()\n private maxSize: number\n\n constructor(maxSize: number = REGEX_CACHE_SIZE) {\n this.maxSize = maxSize\n }\n\n get(pattern: string): RegExp | undefined {\n const regex = this.cache.get(pattern)\n if (regex) {\n // Move to end (most recently used)\n this.cache.delete(pattern)\n this.cache.set(pattern, regex)\n }\n return regex\n }\n\n set(pattern: string, regex: RegExp): void {\n // Evict oldest if at capacity\n if (this.cache.size >= this.maxSize) {\n const oldest = this.cache.keys().next().value\n if (oldest) this.cache.delete(oldest)\n }\n this.cache.set(pattern, regex)\n }\n\n getOrCreate(pattern: string): RegExp {\n let regex = this.get(pattern)\n if (!regex) {\n regex = new RegExp(pattern)\n this.set(pattern, regex)\n }\n return regex\n }\n}\n\nexport class BackgroundShellManager extends EventEmitter {\n private static instance: BackgroundShellManager | null = null\n private shells: Map<string, BackgroundShell> = new Map()\n private regexCache = new RegExpCache()\n\n private constructor() {\n super()\n }\n\n static getInstance(): BackgroundShellManager {\n if (!BackgroundShellManager.instance) {\n BackgroundShellManager.instance = new BackgroundShellManager()\n }\n return BackgroundShellManager.instance\n }\n\n /**\n * Create a new background shell and start executing the command\n */\n create(command: string, cwd?: string): string {\n const shellId = randomUUID().slice(0, 8)\n\n // Spawn the command in a shell\n const childProcess = spawn(command, [], {\n shell: true,\n cwd: cwd || process.cwd(),\n stdio: ['ignore', 'pipe', 'pipe'],\n detached: true, // Create a new process group for easier cleanup\n env: {\n ...process.env,\n GIT_EDITOR: 'true',\n },\n })\n\n const shell: BackgroundShell = {\n id: shellId,\n command,\n status: 'running',\n startTime: Date.now(),\n process: childProcess,\n stdout: [],\n stderr: [],\n lastReadStdoutIndex: 0,\n lastReadStderrIndex: 0,\n }\n\n // Capture stdout\n childProcess.stdout?.on('data', (data: Buffer) => {\n const lines = data.toString().split('\\n')\n shell.stdout.push(...lines)\n\n // Keep only last MAX_OUTPUT_LINES\n if (shell.stdout.length > MAX_OUTPUT_LINES) {\n const removed = shell.stdout.length - MAX_OUTPUT_LINES\n shell.stdout = shell.stdout.slice(removed)\n shell.lastReadStdoutIndex = Math.max(\n 0,\n shell.lastReadStdoutIndex - removed,\n )\n }\n\n this.emit('output', shellId, 'stdout', lines)\n })\n\n // Capture stderr\n childProcess.stderr?.on('data', (data: Buffer) => {\n const lines = data.toString().split('\\n')\n shell.stderr.push(...lines)\n\n // Keep only last MAX_OUTPUT_LINES\n if (shell.stderr.length > MAX_OUTPUT_LINES) {\n const removed = shell.stderr.length - MAX_OUTPUT_LINES\n shell.stderr = shell.stderr.slice(removed)\n shell.lastReadStderrIndex = Math.max(\n 0,\n shell.lastReadStderrIndex - removed,\n )\n }\n\n this.emit('output', shellId, 'stderr', lines)\n })\n\n // Handle process exit\n childProcess.on('exit', (code, signal) => {\n shell.status = signal ? 'killed' : 'done'\n shell.exitCode = code ?? undefined\n shell.endTime = Date.now()\n this.emit('statusChange', shellId, shell.status)\n this.emitListChange()\n })\n\n childProcess.on('error', error => {\n logError(`Background shell ${shellId} error: ${error.message}`)\n shell.status = 'killed'\n shell.endTime = Date.now()\n this.emit('statusChange', shellId, shell.status)\n this.emitListChange()\n })\n\n this.shells.set(shellId, shell)\n this.emit('shellCreated', shellId)\n this.emitListChange()\n\n return shellId\n }\n\n /**\n * Emit a list change event with the current shell list\n * Used for event-driven updates instead of polling\n */\n private emitListChange(): void {\n this.emit('listChange', this.list())\n }\n\n /**\n * Get a background shell by ID\n */\n get(shellId: string): BackgroundShell | undefined {\n return this.shells.get(shellId)\n }\n\n /**\n * Get new output since last read\n */\n getNewOutput(\n shellId: string,\n filter?: string,\n ): {\n stdout: string[]\n stderr: string[]\n } | null {\n const shell = this.shells.get(shellId)\n if (!shell) return null\n\n let newStdout = shell.stdout.slice(shell.lastReadStdoutIndex)\n let newStderr = shell.stderr.slice(shell.lastReadStderrIndex)\n\n // Apply regex filter if provided (using cached regex)\n if (filter) {\n try {\n const regex = this.regexCache.getOrCreate(filter)\n newStdout = newStdout.filter(line => regex.test(line))\n newStderr = newStderr.filter(line => regex.test(line))\n } catch (e) {\n logError(`Invalid regex filter: ${filter}`)\n }\n }\n\n // Update read indices\n shell.lastReadStdoutIndex = shell.stdout.length\n shell.lastReadStderrIndex = shell.stderr.length\n\n return { stdout: newStdout, stderr: newStderr }\n }\n\n /**\n * Get all output (entire buffer)\n */\n getAllOutput(shellId: string): {\n stdout: string[]\n stderr: string[]\n } | null {\n const shell = this.shells.get(shellId)\n if (!shell) return null\n\n return {\n stdout: [...shell.stdout],\n stderr: [...shell.stderr],\n }\n }\n\n /**\n * Kill a background shell\n */\n kill(shellId: string): boolean {\n const shell = this.shells.get(shellId)\n if (!shell) {\n console.log(\n `[BackgroundShellManager] Cannot kill: shell ${shellId} not found`,\n )\n return false\n }\n\n if (shell.status === 'running') {\n try {\n const pid = shell.process.pid\n if (!pid) {\n console.log(\n `[BackgroundShellManager] Cannot kill: shell ${shellId} has no PID`,\n )\n return false\n }\n\n console.log(\n `[BackgroundShellManager] Killing shell ${shellId} (PID: ${pid}, command: ${shell.command})`,\n )\n\n // Kill the process and all its children\n if (process.platform === 'win32') {\n spawn('taskkill', ['/pid', pid.toString(), '/f', '/t'])\n } else {\n // Send SIGKILL to process group (more forceful than SIGTERM)\n // The negative PID sends signal to the entire process group\n try {\n process.kill(-pid, 'SIGKILL')\n console.log(\n `[BackgroundShellManager] Sent SIGKILL to process group -${pid}`,\n )\n } catch (e) {\n // If process group kill fails, try killing just the main process\n console.log(\n `[BackgroundShellManager] Process group kill failed, trying main process only`,\n )\n process.kill(pid, 'SIGKILL')\n }\n }\n\n shell.status = 'killed'\n shell.endTime = Date.now()\n this.emit('statusChange', shellId, 'killed')\n this.emitListChange()\n return true\n } catch (error) {\n console.error(\n `[BackgroundShellManager] Failed to kill shell ${shellId}:`,\n error,\n )\n logError(`Failed to kill shell ${shellId}: ${error}`)\n return false\n }\n }\n\n console.log(\n `[BackgroundShellManager] Shell ${shellId} is not running (status: ${shell.status})`,\n )\n return false\n }\n\n /**\n * List all background shells\n */\n list(): BackgroundShell[] {\n return Array.from(this.shells.values())\n }\n\n /**\n * Get shell status\n */\n getStatus(shellId: string): BackgroundShellStatus | null {\n const shell = this.shells.get(shellId)\n return shell ? shell.status : null\n }\n\n /**\n * Remove a shell from the manager (only if done or killed)\n */\n remove(shellId: string): boolean {\n const shell = this.shells.get(shellId)\n if (!shell || shell.status === 'running') return false\n\n this.shells.delete(shellId)\n this.emit('shellRemoved', shellId)\n this.emitListChange()\n return true\n }\n\n /**\n * Clean up old completed/killed shells\n */\n cleanup(maxAge: number = 3600000): number {\n const now = Date.now()\n let removed = 0\n\n for (const [shellId, shell] of this.shells.entries()) {\n if (\n shell.status !== 'running' &&\n shell.endTime &&\n now - shell.endTime > maxAge\n ) {\n this.shells.delete(shellId)\n removed++\n }\n }\n\n if (removed > 0) {\n this.emit('cleaned', removed)\n this.emitListChange()\n }\n\n return removed\n }\n\n /**\n * Get summary of shell for display\n */\n getSummary(shellId: string): string | null {\n const shell = this.shells.get(shellId)\n if (!shell) return null\n\n const duration = shell.endTime\n ? Math.floor((shell.endTime - shell.startTime) / 1000)\n : Math.floor((Date.now() - shell.startTime) / 1000)\n\n // Get last few lines of output for preview\n const lastLines = shell.stdout.slice(-2).join(' ').slice(0, 50)\n const preview = lastLines ? ` ${lastLines}\u2026` : ''\n\n return `${shell.command}${preview}`\n }\n}\n"],
5
+ "mappings": "AAAA,SAAS,aAAgC;AACzC,SAAS,oBAAoB;AAC7B,SAAS,kBAAkB;AAC3B,SAAS,gBAAgB;AAkBzB,MAAM,mBAAmB;AACzB,MAAM,mBAAmB;AAGzB,MAAM,YAAY;AAAA,EACR,QAAQ,oBAAI,IAAoB;AAAA,EAChC;AAAA,EAER,YAAY,UAAkB,kBAAkB;AAC9C,SAAK,UAAU;AAAA,EACjB;AAAA,EAEA,IAAI,SAAqC;AACvC,UAAM,QAAQ,KAAK,MAAM,IAAI,OAAO;AACpC,QAAI,OAAO;AAET,WAAK,MAAM,OAAO,OAAO;AACzB,WAAK,MAAM,IAAI,SAAS,KAAK;AAAA,IAC/B;AACA,WAAO;AAAA,EACT;AAAA,EAEA,IAAI,SAAiB,OAAqB;AAExC,QAAI,KAAK,MAAM,QAAQ,KAAK,SAAS;AACnC,YAAM,SAAS,KAAK,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AChC;AAAA;AAAA;AAAA;AAAA,EAKA,OAAO,SAA0B;AAC/B,UAAM,QAAQ,KAAK,OAAO,IAAI,OAAO;AACrC,QAAI,CAAC,SAAS,MAAM,WAAW,UAAW,QAAO;AAEjD,SAAK,OAAO,OAAO,OAAO;AAC1B,SAAK,KAAK,gBAAgB,OAAO;AACjC,SAAK,eAAe;AACpB,WAAO;AAAA,EACT;AAAA;AAAA;AAAA;AAAA,EAKA,QAAQ,SAAiB,MAAiB;AACxC,UAAM,MAAM,KAAK,IAAI;AACrB,QAAI,UAAU;AAEd,eAAW,CAAC,SAAS,KAAK,KAAK,KAAK,OAAO,QAAQ,GAAG;AACpD,UACE,MAAM,WAAW,aACjB,MAAM,WACN,MAAM,MAAM,UAAU,QACtB;AACA,aAAK,OAAO,OAAO,OAAO;AAC1B;AAAA,MACF;AAAA,IACF;AAEA,QAAI,UAAU,GAAG;AACf,WAAK,KAAK,WAAW,OAAO;AAC5B,WAAK,eAAe;AAAA,IACtB;AAEA,WAAO;AAAA,EACT;AAAA;AAAA;AAAA;AAAA,EAKA,WAAW,SAAgC;AACzC,UAAM,QAAQ,KAAK,OAAO,IAAI,OAAO;AACrC,QAAI,CAAC,MAAO,QAAO;AAEnB,UAAM,WAAW,MAAM,UACnB,KAAK,OAAO,MAAM,UAAU,MAAM,aAAa,GAAI,IACnD,KAAK,OAAO,KAAK,IAAI,IAAI,MAAM,aAAa,GAAI;AAGpD,UAAM,YAAY,MAAM,OAAO,MAAM,EAAE,EAAE,KAAK,GAAG,EAAE,MAAM,GAAG,EAAE;AAC9D,UAAM,UAAU,YAAY,IAAI,SAAS,WAAM;AAE/C,WAAO,GAAG,MAAM,OAAO,GAAG,OAAO;AAAA,EACnC;AACF;",
6
6
  "names": []
7
7
  }
@@ -118,7 +118,10 @@ function detectShell() {
118
118
  }
119
119
  }
120
120
  try {
121
- execSync('wsl.exe -e bash -lc "echo MINTO_OK"', { stdio: "ignore", timeout: 1500 });
121
+ execSync('wsl.exe -e bash -lc "echo MINTO_OK"', {
122
+ stdio: "ignore",
123
+ timeout: 1500
124
+ });
122
125
  return { bin: "wsl.exe", args: ["-e", "bash", "-l"], type: "wsl" };
123
126
  } catch {
124
127
  }
@@ -299,7 +302,9 @@ class PersistentShell {
299
302
  } else {
300
303
  commandParts.push(`pwd > ${quoteForBash(this.cwdFileBashPath)}`);
301
304
  }
302
- commandParts.push(`echo $EXEC_EXIT_CODE > ${quoteForBash(this.statusFileBashPath)}`);
305
+ commandParts.push(
306
+ `echo $EXEC_EXIT_CODE > ${quoteForBash(this.statusFileBashPath)}`
307
+ );
303
308
  this.sendToShell(commandParts.join("\n"));
304
309
  const start = Date.now();
305
310
  const checkCompletion = setInterval(() => {
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/utils/PersistentShell.ts"],
4
- "sourcesContent": ["import * as fs from 'fs'\nimport { homedir } from 'os'\nimport { existsSync } from 'fs'\nimport shellquote from 'shell-quote'\nimport { spawn, execSync, execFileSync, type ChildProcess } from 'child_process'\nimport { isAbsolute, resolve, join } from 'path'\nimport { logError } from './log'\nimport * as os from 'os'\nimport { PRODUCT_COMMAND } from '@constants/product'\n\ntype ExecResult = {\n stdout: string\n stderr: string\n code: number\n interrupted: boolean\n}\ntype QueuedCommand = {\n command: string\n abortSignal?: AbortSignal\n timeout?: number\n resolve: (result: ExecResult) => void\n reject: (error: Error) => void\n}\n\nconst TEMPFILE_PREFIX = os.tmpdir() + `/${PRODUCT_COMMAND}-`\nconst DEFAULT_TIMEOUT = 30 * 60 * 1000\nconst SIGTERM_CODE = 143 // Standard exit code for SIGTERM\nconst FILE_SUFFIXES = {\n STATUS: '-status',\n STDOUT: '-stdout',\n STDERR: '-stderr',\n CWD: '-cwd',\n}\nconst SHELL_CONFIGS: Record<string, string> = {\n '/bin/bash': '.bashrc',\n '/bin/zsh': '.zshrc',\n}\n\ntype DetectedShell = {\n bin: string\n args: string[]\n type: 'posix' | 'msys' | 'wsl'\n}\n\nfunction quoteForBash(str: string): string {\n return `'${str.replace(/'/g, \"'\\\\''\")}'`\n}\n\nfunction toBashPath(pathStr: string, type: 'posix' | 'msys' | 'wsl'): string {\n // Already POSIX absolute path\n if (pathStr.startsWith('/')) return pathStr\n if (type === 'posix') return pathStr\n\n // Normalize backslashes\n const normalized = pathStr.replace(/\\\\/g, '/').replace(/\\\\\\\\/g, '/')\n const driveMatch = /^[A-Za-z]:/.exec(normalized)\n if (driveMatch) {\n const drive = normalized[0].toLowerCase()\n const rest = normalized.slice(2)\n if (type === 'msys') {\n return `/` + drive + (rest.startsWith('/') ? rest : `/${rest}`)\n }\n // wsl\n return `/mnt/` + drive + (rest.startsWith('/') ? rest : `/${rest}`)\n }\n // Relative path: just convert slashes\n return normalized\n}\n\nfunction fileExists(p: string | undefined): p is string {\n return !!p && existsSync(p)\n}\n\n// Robust PATH splitter for Windows and POSIX\nfunction splitPathEntries(pathEnv: string, platform: NodeJS.Platform): string[] {\n if (!pathEnv) return []\n\n // POSIX: ':' is the separator\n if (platform !== 'win32') {\n return pathEnv\n .split(':')\n .map(s => s.trim().replace(/^\"|\"$/g, ''))\n .filter(Boolean)\n }\n\n // Windows: primarily ';', but some environments may use ':'\n // We must not split drive letters like 'C:\\\\' or 'D:foo\\\\bar'\n const entries: string[] = []\n let current = ''\n const pushCurrent = () => {\n const cleaned = current.trim().replace(/^\"|\"$/g, '')\n if (cleaned) entries.push(cleaned)\n current = ''\n }\n\n for (let i = 0; i < pathEnv.length; i++) {\n const ch = pathEnv[i]\n\n if (ch === ';') {\n pushCurrent()\n continue\n }\n\n if (ch === ':') {\n const segmentLength = current.length\n const firstChar = current[0]\n const isDriveLetterPrefix = segmentLength === 1 && /[A-Za-z]/.test(firstChar || '')\n // Treat ':' as separator only if it's NOT the drive letter colon\n if (!isDriveLetterPrefix) {\n pushCurrent()\n continue\n }\n }\n\n current += ch\n }\n\n // Flush the final segment\n pushCurrent()\n\n return entries\n}\n\nfunction detectShell(): DetectedShell {\n const isWin = process.platform === 'win32'\n if (!isWin) {\n const bin = process.env.SHELL || '/bin/bash'\n return { bin, args: ['-l'], type: 'posix' }\n }\n\n // 1) Respect SHELL if it points to a bash.exe that exists\n if (process.env.SHELL && /bash\\.exe$/i.test(process.env.SHELL) && existsSync(process.env.SHELL)) {\n return { bin: process.env.SHELL, args: [], type: 'msys' }\n }\n\n // 1.1) Explicit override (MINTO_BASH or KODE_BASH for backward compatibility)\n const customBash = process.env.MINTO_BASH ?? process.env.KODE_BASH\n if (customBash && existsSync(customBash)) {\n return { bin: customBash, args: [], type: 'msys' }\n }\n\n // 2) Common Git Bash/MSYS2 locations\n const programFiles = [\n process.env['ProgramFiles'],\n process.env['ProgramFiles(x86)'],\n process.env['ProgramW6432'],\n ].filter(Boolean) as string[]\n\n const localAppData = process.env['LocalAppData']\n\n const candidates: string[] = []\n for (const base of programFiles) {\n candidates.push(\n join(base, 'Git', 'bin', 'bash.exe'),\n join(base, 'Git', 'usr', 'bin', 'bash.exe'),\n )\n }\n if (localAppData) {\n candidates.push(\n join(localAppData, 'Programs', 'Git', 'bin', 'bash.exe'),\n join(localAppData, 'Programs', 'Git', 'usr', 'bin', 'bash.exe'),\n )\n }\n // MSYS2 default\n candidates.push('C:/msys64/usr/bin/bash.exe')\n\n for (const c of candidates) {\n if (existsSync(c)) {\n return { bin: c, args: [], type: 'msys' }\n }\n }\n\n // 2.1) Search in PATH for bash.exe\n const pathEnv = process.env.PATH || process.env.Path || process.env.path || ''\n const pathEntries = splitPathEntries(pathEnv, process.platform)\n for (const p of pathEntries) {\n const candidate = join(p, 'bash.exe')\n if (existsSync(candidate)) {\n return { bin: candidate, args: [], type: 'msys' }\n }\n }\n\n // 3) WSL\n try {\n // Quick probe to ensure WSL+bash exists\n execSync('wsl.exe -e bash -lc \"echo MINTO_OK\"', { stdio: 'ignore', timeout: 1500 })\n return { bin: 'wsl.exe', args: ['-e', 'bash', '-l'], type: 'wsl' }\n } catch {}\n\n // 4) Last resort: meaningful error\n const hint = [\n '\u65E0\u6CD5\u627E\u5230\u53EF\u7528\u7684 bash\u3002\u8BF7\u5B89\u88C5 Git for Windows \u6216\u542F\u7528 WSL\u3002',\n '\u63A8\u8350\u5B89\u88C5 Git: https://git-scm.com/download/win',\n '\u6216\u542F\u7528 WSL \u5E76\u5B89\u88C5 Ubuntu: https://learn.microsoft.com/windows/wsl/install',\n ].join('\\n')\n throw new Error(hint)\n}\n\nexport class PersistentShell {\n private commandQueue: QueuedCommand[] = []\n private isExecuting: boolean = false\n private shell: ChildProcess\n private isAlive: boolean = true\n private commandInterrupted: boolean = false\n private statusFile: string\n private stdoutFile: string\n private stderrFile: string\n private cwdFile: string\n private cwd: string\n private binShell: string\n private shellArgs: string[]\n private shellType: 'posix' | 'msys' | 'wsl'\n private statusFileBashPath: string\n private stdoutFileBashPath: string\n private stderrFileBashPath: string\n private cwdFileBashPath: string\n\n constructor(cwd: string) {\n const { bin, args, type } = detectShell()\n this.binShell = bin\n this.shellArgs = args\n this.shellType = type\n\n this.shell = spawn(this.binShell, this.shellArgs, {\n stdio: ['pipe', 'pipe', 'pipe'],\n cwd,\n env: {\n ...process.env,\n GIT_EDITOR: 'true',\n },\n })\n\n this.cwd = cwd\n\n this.shell.on('exit', (code, signal) => {\n if (code) {\n // TODO: It would be nice to alert the user that shell crashed\n logError(`Shell exited with code ${code} and signal ${signal}`)\n }\n for (const file of [\n this.statusFile,\n this.stdoutFile,\n this.stderrFile,\n this.cwdFile,\n ]) {\n if (fs.existsSync(file)) {\n fs.unlinkSync(file)\n }\n }\n this.isAlive = false\n })\n\n const id = Math.floor(Math.random() * 0x10000)\n .toString(16)\n .padStart(4, '0')\n\n this.statusFile = TEMPFILE_PREFIX + id + FILE_SUFFIXES.STATUS\n this.stdoutFile = TEMPFILE_PREFIX + id + FILE_SUFFIXES.STDOUT\n this.stderrFile = TEMPFILE_PREFIX + id + FILE_SUFFIXES.STDERR\n this.cwdFile = TEMPFILE_PREFIX + id + FILE_SUFFIXES.CWD\n for (const file of [this.statusFile, this.stdoutFile, this.stderrFile]) {\n fs.writeFileSync(file, '')\n }\n // Initialize CWD file with initial directory\n fs.writeFileSync(this.cwdFile, cwd)\n\n // Compute bash-visible paths for redirections\n this.statusFileBashPath = toBashPath(this.statusFile, this.shellType)\n this.stdoutFileBashPath = toBashPath(this.stdoutFile, this.shellType)\n this.stderrFileBashPath = toBashPath(this.stderrFile, this.shellType)\n this.cwdFileBashPath = toBashPath(this.cwdFile, this.shellType)\n\n // Source ~/.bashrc when available (avoid login shells on MSYS to prevent cwd resets)\n if (this.shellType === 'msys') {\n // Use non-login shell; explicitly source but keep working directory\n this.sendToShell('[ -f ~/.bashrc ] && source ~/.bashrc || true')\n // Ensure CWD file reflects current Windows path immediately on MSYS\n this.sendToShell(`pwd -W > ${quoteForBash(this.cwdFileBashPath)}`)\n } else {\n this.sendToShell('[ -f ~/.bashrc ] && source ~/.bashrc || true')\n }\n }\n\n private static instance: PersistentShell | null = null\n\n static restart() {\n if (PersistentShell.instance) {\n PersistentShell.instance.close()\n PersistentShell.instance = null\n }\n }\n\n static getInstance(): PersistentShell {\n if (!PersistentShell.instance || !PersistentShell.instance.isAlive) {\n PersistentShell.instance = new PersistentShell(process.cwd())\n }\n return PersistentShell.instance\n }\n\n killChildren() {\n const parentPid = this.shell.pid\n try {\n const childPids = execSync(`pgrep -P ${parentPid}`)\n .toString()\n .trim()\n .split('\\n')\n .filter(Boolean) // Filter out empty strings\n\n \n\n childPids.forEach(pid => {\n try {\n process.kill(Number(pid), 'SIGTERM')\n } catch (error) {\n logError(`Failed to kill process ${pid}: ${error}`)\n }\n })\n } catch {\n // pgrep returns non-zero when no processes are found - this is expected\n } finally {\n this.commandInterrupted = true\n }\n }\n\n private async processQueue() {\n /**\n * Processes commands from the queue one at a time.\n * Concurrency invariants:\n * - Only one instance runs at a time (controlled by isExecuting)\n * - Is the only caller of updateCwd() in the system\n * - Calls updateCwd() after each command completes\n * - Ensures commands execute serially via the queue\n * - Handles interruption via abortSignal by calling killChildren()\n * - Cleans up abortSignal listeners after command completion or interruption\n */\n if (this.isExecuting || this.commandQueue.length === 0) return\n\n this.isExecuting = true\n const { command, abortSignal, timeout, resolve, reject } =\n this.commandQueue.shift()!\n\n const killChildren = () => this.killChildren()\n if (abortSignal) {\n abortSignal.addEventListener('abort', killChildren)\n }\n\n try {\n const result = await this.exec_(command, timeout)\n\n // No need to update cwd - it's handled in exec_ via the CWD file\n\n resolve(result)\n } catch (error) {\n \n reject(error as Error)\n } finally {\n this.isExecuting = false\n if (abortSignal) {\n abortSignal.removeEventListener('abort', killChildren)\n }\n // Process next command in queue\n this.processQueue()\n }\n }\n\n async exec(\n command: string,\n abortSignal?: AbortSignal,\n timeout?: number,\n ): Promise<ExecResult> {\n return new Promise((resolve, reject) => {\n this.commandQueue.push({ command, abortSignal, timeout, resolve, reject })\n this.processQueue()\n })\n }\n\n private async exec_(command: string, timeout?: number): Promise<ExecResult> {\n /**\n * Direct command execution without going through the queue.\n * Concurrency invariants:\n * - Not safe for concurrent calls (uses shared files)\n * - Called only when queue is idle\n * - Relies on file-based IPC to handle shell interaction\n * - Does not modify the command queue state\n * - Tracks interruption state via commandInterrupted flag\n * - Resets interruption state at start of new command\n * - Reports interruption status in result object\n *\n * Exit Code & CWD Handling:\n * - Executes command and immediately captures its exit code into a shell variable\n * - Updates the CWD file with the working directory after capturing exit code\n * - Writes the preserved exit code to the status file as the final step\n * - This sequence eliminates race conditions between exit code capture and CWD updates\n * - The pwd() method reads the CWD file directly for current directory info\n */\n const quotedCommand = quoteForBash(command)\n\n // Check the syntax of the command\n try {\n if (this.shellType === 'wsl') {\n // On Windows WSL, avoid shell string quoting issues by using argv form\n execFileSync('wsl.exe', ['-e', 'bash', '-n', '-c', command], {\n stdio: 'ignore',\n timeout: 1000,\n })\n } else if (this.shellType === 'msys') {\n // On Windows Git Bash/MSYS, use execFileSync to bypass cmd.exe parsing\n execFileSync(this.binShell, ['-n', '-c', command], {\n stdio: 'ignore',\n timeout: 1000,\n })\n } else {\n // POSIX platforms: keep existing behavior\n execSync(`${this.binShell} -n -c ${quotedCommand}`, {\n stdio: 'ignore',\n timeout: 1000,\n })\n }\n } catch (error) {\n // If there's a syntax error, return an error with the actual exit code\n const execError = error as any\n const actualExitCode = execError?.status ?? execError?.code ?? 2 // Default to 2 (syntax error) if no code available\n const errorStr = execError?.stderr?.toString() || execError?.message || String(error || '')\n \n return Promise.resolve({\n stdout: '',\n stderr: errorStr,\n code: actualExitCode,\n interrupted: false,\n })\n }\n\n const commandTimeout = timeout || DEFAULT_TIMEOUT\n // Reset interrupted state for new command\n this.commandInterrupted = false\n return new Promise<ExecResult>(resolve => {\n // Truncate output files\n fs.writeFileSync(this.stdoutFile, '')\n fs.writeFileSync(this.stderrFile, '')\n fs.writeFileSync(this.statusFile, '')\n // Break up the command sequence for clarity using an array of commands\n const commandParts = []\n\n // 1. Execute the main command with redirections\n commandParts.push(\n `eval ${quotedCommand} < /dev/null > ${quoteForBash(this.stdoutFileBashPath)} 2> ${quoteForBash(this.stderrFileBashPath)}`,\n )\n\n // 2. Capture exit code immediately after command execution to avoid losing it\n commandParts.push(`EXEC_EXIT_CODE=$?`)\n\n // 3. Update CWD file (use Windows path on MSYS to keep Node path checks correct)\n if (this.shellType === 'msys') {\n commandParts.push(`pwd -W > ${quoteForBash(this.cwdFileBashPath)}`)\n } else {\n commandParts.push(`pwd > ${quoteForBash(this.cwdFileBashPath)}`)\n }\n\n // 4. Write the preserved exit code to status file to avoid race with pwd\n commandParts.push(`echo $EXEC_EXIT_CODE > ${quoteForBash(this.statusFileBashPath)}`)\n\n // Send the combined commands as a single operation to maintain atomicity\n this.sendToShell(commandParts.join('\\n'))\n\n // Check for command completion or timeout\n const start = Date.now()\n const checkCompletion = setInterval(() => {\n try {\n let statusFileSize = 0\n if (fs.existsSync(this.statusFile)) {\n statusFileSize = fs.statSync(this.statusFile).size\n }\n\n if (\n statusFileSize > 0 ||\n Date.now() - start > commandTimeout ||\n this.commandInterrupted\n ) {\n clearInterval(checkCompletion)\n const stdout = fs.existsSync(this.stdoutFile)\n ? fs.readFileSync(this.stdoutFile, 'utf8')\n : ''\n let stderr = fs.existsSync(this.stderrFile)\n ? fs.readFileSync(this.stderrFile, 'utf8')\n : ''\n let code: number\n if (statusFileSize) {\n code = Number(fs.readFileSync(this.statusFile, 'utf8'))\n } else {\n // Timeout occurred - kill any running processes\n this.killChildren()\n code = SIGTERM_CODE\n stderr += (stderr ? '\\n' : '') + 'Command execution timed out'\n \n }\n resolve({\n stdout,\n stderr,\n code,\n interrupted: this.commandInterrupted,\n })\n }\n } catch {\n // Ignore file system errors during polling - they are expected\n // as we check for completion before files exist\n }\n }, 10) // increasing this will introduce latency\n })\n }\n\n private sendToShell(command: string) {\n try {\n this.shell!.stdin!.write(command + '\\n')\n } catch (error) {\n const errorString =\n error instanceof Error\n ? error.message\n : String(error || 'Unknown error')\n logError(`Error in sendToShell: ${errorString}`)\n \n throw error\n }\n }\n\n pwd(): string {\n try {\n const newCwd = fs.readFileSync(this.cwdFile, 'utf8').trim()\n if (newCwd) {\n this.cwd = newCwd\n }\n } catch (error) {\n logError(`Shell pwd error ${error}`)\n }\n // Always return the cached value\n return this.cwd\n }\n\n async setCwd(cwd: string) {\n const resolved = isAbsolute(cwd) ? cwd : resolve(process.cwd(), cwd)\n if (!existsSync(resolved)) {\n throw new Error(`Path \"${resolved}\" does not exist`)\n }\n const bashPath = toBashPath(resolved, this.shellType)\n await this.exec(`cd ${quoteForBash(bashPath)}`)\n }\n\n close(): void {\n this.shell!.stdin!.end()\n this.shell.kill()\n }\n}\n"],
5
- "mappings": "AAAA,YAAY,QAAQ;AAEpB,SAAS,kBAAkB;AAE3B,SAAS,OAAO,UAAU,oBAAuC;AACjE,SAAS,YAAY,SAAS,YAAY;AAC1C,SAAS,gBAAgB;AACzB,YAAY,QAAQ;AACpB,SAAS,uBAAuB;AAgBhC,MAAM,kBAAkB,GAAG,OAAO,IAAI,IAAI,eAAe;AACzD,MAAM,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{ existsSync } from 'fs'\nimport shellquote from 'shell-quote'\nimport { spawn, execSync, execFileSync, type ChildProcess } from 'child_process'\nimport { isAbsolute, resolve, join } from 'path'\nimport { logError } from './log'\nimport * as os from 'os'\nimport { PRODUCT_COMMAND } from '@constants/product'\n\ntype ExecResult = {\n stdout: string\n stderr: string\n code: number\n interrupted: boolean\n}\ntype QueuedCommand = {\n command: string\n abortSignal?: AbortSignal\n timeout?: number\n resolve: (result: ExecResult) => void\n reject: (error: Error) => void\n}\n\nconst TEMPFILE_PREFIX = os.tmpdir() + `/${PRODUCT_COMMAND}-`\nconst DEFAULT_TIMEOUT = 30 * 60 * 1000\nconst SIGTERM_CODE = 143 // Standard exit code for SIGTERM\nconst FILE_SUFFIXES = {\n STATUS: '-status',\n STDOUT: '-stdout',\n STDERR: '-stderr',\n CWD: '-cwd',\n}\nconst SHELL_CONFIGS: Record<string, string> = {\n '/bin/bash': '.bashrc',\n '/bin/zsh': '.zshrc',\n}\n\ntype DetectedShell = {\n bin: string\n args: string[]\n type: 'posix' | 'msys' | 'wsl'\n}\n\nfunction quoteForBash(str: string): string {\n return `'${str.replace(/'/g, \"'\\\\''\")}'`\n}\n\nfunction toBashPath(pathStr: string, type: 'posix' | 'msys' | 'wsl'): string {\n // Already POSIX absolute path\n if (pathStr.startsWith('/')) return pathStr\n if (type === 'posix') return pathStr\n\n // Normalize backslashes\n const normalized = pathStr.replace(/\\\\/g, '/').replace(/\\\\\\\\/g, '/')\n const driveMatch = /^[A-Za-z]:/.exec(normalized)\n if (driveMatch) {\n const drive = normalized[0].toLowerCase()\n const rest = normalized.slice(2)\n if (type === 'msys') {\n return `/` + drive + (rest.startsWith('/') ? rest : `/${rest}`)\n }\n // wsl\n return `/mnt/` + drive + (rest.startsWith('/') ? rest : `/${rest}`)\n }\n // Relative path: just convert slashes\n return normalized\n}\n\nfunction fileExists(p: string | undefined): p is string {\n return !!p && existsSync(p)\n}\n\n// Robust PATH splitter for Windows and POSIX\nfunction splitPathEntries(\n pathEnv: string,\n platform: NodeJS.Platform,\n): string[] {\n if (!pathEnv) return []\n\n // POSIX: ':' is the separator\n if (platform !== 'win32') {\n return pathEnv\n .split(':')\n .map(s => s.trim().replace(/^\"|\"$/g, ''))\n .filter(Boolean)\n }\n\n // Windows: primarily ';', but some environments may use ':'\n // We must not split drive letters like 'C:\\\\' or 'D:foo\\\\bar'\n const entries: string[] = []\n let current = ''\n const pushCurrent = () => {\n const cleaned = current.trim().replace(/^\"|\"$/g, '')\n if (cleaned) entries.push(cleaned)\n current = ''\n }\n\n for (let i = 0; i < pathEnv.length; i++) {\n const ch = pathEnv[i]\n\n if (ch === ';') {\n pushCurrent()\n continue\n }\n\n if (ch === ':') {\n const segmentLength = current.length\n const firstChar = current[0]\n const isDriveLetterPrefix =\n segmentLength === 1 && /[A-Za-z]/.test(firstChar || '')\n // Treat ':' as separator only if it's NOT the drive letter colon\n if (!isDriveLetterPrefix) {\n pushCurrent()\n continue\n }\n }\n\n current += ch\n }\n\n // Flush the final segment\n pushCurrent()\n\n return entries\n}\n\nfunction detectShell(): DetectedShell {\n const isWin = process.platform === 'win32'\n if (!isWin) {\n const bin = process.env.SHELL || '/bin/bash'\n return { bin, args: ['-l'], type: 'posix' }\n }\n\n // 1) Respect SHELL if it points to a bash.exe that exists\n if (\n process.env.SHELL &&\n /bash\\.exe$/i.test(process.env.SHELL) &&\n existsSync(process.env.SHELL)\n ) {\n return { bin: process.env.SHELL, args: [], type: 'msys' }\n }\n\n // 1.1) Explicit override (MINTO_BASH or KODE_BASH for backward compatibility)\n const customBash = process.env.MINTO_BASH ?? process.env.KODE_BASH\n if (customBash && existsSync(customBash)) {\n return { bin: customBash, args: [], type: 'msys' }\n }\n\n // 2) Common Git Bash/MSYS2 locations\n const programFiles = [\n process.env['ProgramFiles'],\n process.env['ProgramFiles(x86)'],\n process.env['ProgramW6432'],\n ].filter(Boolean) as string[]\n\n const localAppData = process.env['LocalAppData']\n\n const candidates: string[] = []\n for (const base of programFiles) {\n candidates.push(\n join(base, 'Git', 'bin', 'bash.exe'),\n join(base, 'Git', 'usr', 'bin', 'bash.exe'),\n )\n }\n if (localAppData) {\n candidates.push(\n join(localAppData, 'Programs', 'Git', 'bin', 'bash.exe'),\n join(localAppData, 'Programs', 'Git', 'usr', 'bin', 'bash.exe'),\n )\n }\n // MSYS2 default\n candidates.push('C:/msys64/usr/bin/bash.exe')\n\n for (const c of candidates) {\n if (existsSync(c)) {\n return { bin: c, args: [], type: 'msys' }\n }\n }\n\n // 2.1) Search in PATH for bash.exe\n const pathEnv = process.env.PATH || process.env.Path || process.env.path || ''\n const pathEntries = splitPathEntries(pathEnv, process.platform)\n for (const p of pathEntries) {\n const candidate = join(p, 'bash.exe')\n if (existsSync(candidate)) {\n return { bin: candidate, args: [], type: 'msys' }\n }\n }\n\n // 3) WSL\n try {\n // Quick probe to ensure WSL+bash exists\n execSync('wsl.exe -e bash -lc \"echo MINTO_OK\"', {\n stdio: 'ignore',\n timeout: 1500,\n })\n return { bin: 'wsl.exe', args: ['-e', 'bash', '-l'], type: 'wsl' }\n } catch {}\n\n // 4) Last resort: meaningful error\n const hint = [\n '\u65E0\u6CD5\u627E\u5230\u53EF\u7528\u7684 bash\u3002\u8BF7\u5B89\u88C5 Git for Windows \u6216\u542F\u7528 WSL\u3002',\n '\u63A8\u8350\u5B89\u88C5 Git: https://git-scm.com/download/win',\n '\u6216\u542F\u7528 WSL \u5E76\u5B89\u88C5 Ubuntu: https://learn.microsoft.com/windows/wsl/install',\n ].join('\\n')\n throw new Error(hint)\n}\n\nexport class PersistentShell {\n private commandQueue: QueuedCommand[] = []\n private isExecuting: boolean = false\n private shell: ChildProcess\n private isAlive: boolean = true\n private commandInterrupted: boolean = false\n private statusFile: string\n private stdoutFile: string\n private stderrFile: string\n private cwdFile: string\n private cwd: string\n private binShell: string\n private shellArgs: string[]\n private shellType: 'posix' | 'msys' | 'wsl'\n private statusFileBashPath: string\n private stdoutFileBashPath: string\n private stderrFileBashPath: string\n private cwdFileBashPath: string\n\n constructor(cwd: string) {\n const { bin, args, type } = detectShell()\n this.binShell = bin\n this.shellArgs = args\n this.shellType = type\n\n this.shell = spawn(this.binShell, this.shellArgs, {\n stdio: ['pipe', 'pipe', 'pipe'],\n cwd,\n env: {\n ...process.env,\n GIT_EDITOR: 'true',\n },\n })\n\n this.cwd = cwd\n\n this.shell.on('exit', (code, signal) => {\n if (code) {\n // TODO: It would be nice to alert the user that shell crashed\n logError(`Shell exited with code ${code} and signal ${signal}`)\n }\n for (const file of [\n this.statusFile,\n this.stdoutFile,\n this.stderrFile,\n this.cwdFile,\n ]) {\n if (fs.existsSync(file)) {\n fs.unlinkSync(file)\n }\n }\n this.isAlive = false\n })\n\n const id = Math.floor(Math.random() * 0x10000)\n .toString(16)\n .padStart(4, '0')\n\n this.statusFile = TEMPFILE_PREFIX + id + FILE_SUFFIXES.STATUS\n this.stdoutFile = TEMPFILE_PREFIX + id + FILE_SUFFIXES.STDOUT\n this.stderrFile = TEMPFILE_PREFIX + id + FILE_SUFFIXES.STDERR\n this.cwdFile = TEMPFILE_PREFIX + id + FILE_SUFFIXES.CWD\n for (const file of [this.statusFile, this.stdoutFile, this.stderrFile]) {\n fs.writeFileSync(file, '')\n }\n // Initialize CWD file with initial directory\n fs.writeFileSync(this.cwdFile, cwd)\n\n // Compute bash-visible paths for redirections\n this.statusFileBashPath = toBashPath(this.statusFile, this.shellType)\n this.stdoutFileBashPath = toBashPath(this.stdoutFile, this.shellType)\n this.stderrFileBashPath = toBashPath(this.stderrFile, this.shellType)\n this.cwdFileBashPath = toBashPath(this.cwdFile, this.shellType)\n\n // Source ~/.bashrc when available (avoid login shells on MSYS to prevent cwd resets)\n if (this.shellType === 'msys') {\n // Use non-login shell; explicitly source but keep working directory\n this.sendToShell('[ -f ~/.bashrc ] && source ~/.bashrc || true')\n // Ensure CWD file reflects current Windows path immediately on MSYS\n this.sendToShell(`pwd -W > ${quoteForBash(this.cwdFileBashPath)}`)\n } else {\n this.sendToShell('[ -f ~/.bashrc ] && source ~/.bashrc || true')\n }\n }\n\n private static instance: PersistentShell | null = null\n\n static restart() {\n if (PersistentShell.instance) {\n PersistentShell.instance.close()\n PersistentShell.instance = null\n }\n }\n\n static getInstance(): PersistentShell {\n if (!PersistentShell.instance || !PersistentShell.instance.isAlive) {\n PersistentShell.instance = new PersistentShell(process.cwd())\n }\n return PersistentShell.instance\n }\n\n killChildren() {\n const parentPid = this.shell.pid\n try {\n const childPids = execSync(`pgrep -P ${parentPid}`)\n .toString()\n .trim()\n .split('\\n')\n .filter(Boolean) // Filter out empty strings\n\n childPids.forEach(pid => {\n try {\n process.kill(Number(pid), 'SIGTERM')\n } catch (error) {\n logError(`Failed to kill process ${pid}: ${error}`)\n }\n })\n } catch {\n // pgrep returns non-zero when no processes are found - this is expected\n } finally {\n this.commandInterrupted = true\n }\n }\n\n private async processQueue() {\n /**\n * Processes commands from the queue one at a time.\n * Concurrency invariants:\n * - Only one instance runs at a time (controlled by isExecuting)\n * - Is the only caller of updateCwd() in the system\n * - Calls updateCwd() after each command completes\n * - Ensures commands execute serially via the queue\n * - Handles interruption via abortSignal by calling killChildren()\n * - Cleans up abortSignal listeners after command completion or interruption\n */\n if (this.isExecuting || this.commandQueue.length === 0) return\n\n this.isExecuting = true\n const { command, abortSignal, timeout, resolve, reject } =\n this.commandQueue.shift()!\n\n const killChildren = () => this.killChildren()\n if (abortSignal) {\n abortSignal.addEventListener('abort', killChildren)\n }\n\n try {\n const result = await this.exec_(command, timeout)\n\n // No need to update cwd - it's handled in exec_ via the CWD file\n\n resolve(result)\n } catch (error) {\n reject(error as Error)\n } finally {\n this.isExecuting = false\n if (abortSignal) {\n abortSignal.removeEventListener('abort', killChildren)\n }\n // Process next command in queue\n this.processQueue()\n }\n }\n\n async exec(\n command: string,\n abortSignal?: AbortSignal,\n timeout?: number,\n ): Promise<ExecResult> {\n return new Promise((resolve, reject) => {\n this.commandQueue.push({ command, abortSignal, timeout, resolve, reject })\n this.processQueue()\n })\n }\n\n private async exec_(command: string, timeout?: number): Promise<ExecResult> {\n /**\n * Direct command execution without going through the queue.\n * Concurrency invariants:\n * - Not safe for concurrent calls (uses shared files)\n * - Called only when queue is idle\n * - Relies on file-based IPC to handle shell interaction\n * - Does not modify the command queue state\n * - Tracks interruption state via commandInterrupted flag\n * - Resets interruption state at start of new command\n * - Reports interruption status in result object\n *\n * Exit Code & CWD Handling:\n * - Executes command and immediately captures its exit code into a shell variable\n * - Updates the CWD file with the working directory after capturing exit code\n * - Writes the preserved exit code to the status file as the final step\n * - This sequence eliminates race conditions between exit code capture and CWD updates\n * - The pwd() method reads the CWD file directly for current directory info\n */\n const quotedCommand = quoteForBash(command)\n\n // Check the syntax of the command\n try {\n if (this.shellType === 'wsl') {\n // On Windows WSL, avoid shell string quoting issues by using argv form\n execFileSync('wsl.exe', ['-e', 'bash', '-n', '-c', command], {\n stdio: 'ignore',\n timeout: 1000,\n })\n } else if (this.shellType === 'msys') {\n // On Windows Git Bash/MSYS, use execFileSync to bypass cmd.exe parsing\n execFileSync(this.binShell, ['-n', '-c', command], {\n stdio: 'ignore',\n timeout: 1000,\n })\n } else {\n // POSIX platforms: keep existing behavior\n execSync(`${this.binShell} -n -c ${quotedCommand}`, {\n stdio: 'ignore',\n timeout: 1000,\n })\n }\n } catch (error) {\n // If there's a syntax error, return an error with the actual exit code\n const execError = error as any\n const actualExitCode = execError?.status ?? execError?.code ?? 2 // Default to 2 (syntax error) if no code available\n const errorStr =\n execError?.stderr?.toString() ||\n execError?.message ||\n String(error || '')\n\n return Promise.resolve({\n stdout: '',\n stderr: errorStr,\n code: actualExitCode,\n interrupted: false,\n })\n }\n\n const commandTimeout = timeout || DEFAULT_TIMEOUT\n // Reset interrupted state for new command\n this.commandInterrupted = false\n return new Promise<ExecResult>(resolve => {\n // Truncate output files\n fs.writeFileSync(this.stdoutFile, '')\n fs.writeFileSync(this.stderrFile, '')\n fs.writeFileSync(this.statusFile, '')\n // Break up the command sequence for clarity using an array of commands\n const commandParts = []\n\n // 1. Execute the main command with redirections\n commandParts.push(\n `eval ${quotedCommand} < /dev/null > ${quoteForBash(this.stdoutFileBashPath)} 2> ${quoteForBash(this.stderrFileBashPath)}`,\n )\n\n // 2. Capture exit code immediately after command execution to avoid losing it\n commandParts.push(`EXEC_EXIT_CODE=$?`)\n\n // 3. Update CWD file (use Windows path on MSYS to keep Node path checks correct)\n if (this.shellType === 'msys') {\n commandParts.push(`pwd -W > ${quoteForBash(this.cwdFileBashPath)}`)\n } else {\n commandParts.push(`pwd > ${quoteForBash(this.cwdFileBashPath)}`)\n }\n\n // 4. Write the preserved exit code to status file to avoid race with pwd\n commandParts.push(\n `echo $EXEC_EXIT_CODE > ${quoteForBash(this.statusFileBashPath)}`,\n )\n\n // Send the combined commands as a single operation to maintain atomicity\n this.sendToShell(commandParts.join('\\n'))\n\n // Check for command completion or timeout\n const start = Date.now()\n const checkCompletion = setInterval(() => {\n try {\n let statusFileSize = 0\n if (fs.existsSync(this.statusFile)) {\n statusFileSize = fs.statSync(this.statusFile).size\n }\n\n if (\n statusFileSize > 0 ||\n Date.now() - start > commandTimeout ||\n this.commandInterrupted\n ) {\n clearInterval(checkCompletion)\n const stdout = fs.existsSync(this.stdoutFile)\n ? fs.readFileSync(this.stdoutFile, 'utf8')\n : ''\n let stderr = fs.existsSync(this.stderrFile)\n ? fs.readFileSync(this.stderrFile, 'utf8')\n : ''\n let code: number\n if (statusFileSize) {\n code = Number(fs.readFileSync(this.statusFile, 'utf8'))\n } else {\n // Timeout occurred - kill any running processes\n this.killChildren()\n code = SIGTERM_CODE\n stderr += (stderr ? '\\n' : '') + 'Command execution timed out'\n }\n resolve({\n stdout,\n stderr,\n code,\n interrupted: this.commandInterrupted,\n })\n }\n } catch {\n // Ignore file system errors during polling - they are expected\n // as we check for completion before files exist\n }\n }, 10) // increasing this will introduce latency\n })\n }\n\n private sendToShell(command: string) {\n try {\n this.shell!.stdin!.write(command + '\\n')\n } catch (error) {\n const errorString =\n error instanceof Error\n ? error.message\n : String(error || 'Unknown error')\n logError(`Error in sendToShell: ${errorString}`)\n\n throw error\n }\n }\n\n pwd(): string {\n try {\n const newCwd = fs.readFileSync(this.cwdFile, 'utf8').trim()\n if (newCwd) {\n this.cwd = newCwd\n }\n } catch (error) {\n logError(`Shell pwd error ${error}`)\n }\n // Always return the cached value\n return this.cwd\n }\n\n async setCwd(cwd: string) {\n const resolved = isAbsolute(cwd) ? cwd : resolve(process.cwd(), cwd)\n if (!existsSync(resolved)) {\n throw new Error(`Path \"${resolved}\" does not exist`)\n }\n const bashPath = toBashPath(resolved, this.shellType)\n await this.exec(`cd ${quoteForBash(bashPath)}`)\n }\n\n close(): void {\n this.shell!.stdin!.end()\n this.shell.kill()\n }\n}\n"],
5
+ "mappings": "AAAA,YAAY,QAAQ;AAEpB,SAAS,kBAAkB;AAE3B,SAAS,OAAO,UAAU,oBAAuC;AACjE,SAAS,YAAY,SAAS,YAAY;AAC1C,SAAS,gBAAgB;AACzB,YAAY,QAAQ;AACpB,SAAS,uBAAuB;AAgBhC,MAAM,kBAAkB,GAAG,OAAO,IAAI,IAAI,eAAe;AACzD,MAAM,kBAAkB,KAAK,KAAK;AAClC,MAAM,eAAe;AACrB,MAAM,gBAAgB;AAAA,EACpB,QAAQ;AAAA,EACR,QAAQ;AAAA,EACR,QAAQ;AAAA,EACR,KAAK;AACP;AACA,MAAM,gBAAwC;AAAA,EAC5C,aAAa;AAAA,EACb,YAAY;AACd;AAQA,SAAS,aAAa,KAAqB;AACzC,SAAO,IAAI,IAAI,QAAQ,MAAM,OAAO,CAAC;AACvC;AAEA,SAAS,WAAW,SAAiB,MAAwC;AAE3E,MAAI,QAAQ,WAAW,GAAG,EAAG,QAAO;AACpC,MAAI,SAAS,QAAS,QAAO;AAG7B,QAAM,aAAa,QAAQ,QAAQ,OAAO,GAAG,EAAE,QAAQ,SAAS,GAAG;AACnE,QAAM,aAAa,aAAa,KAAK,UAAU;AAC/C,MAAI,YAAY;AACd,UAAM,QAAQ,WAAW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AM;AAAA,IACR;AAAA,EACF;AAAA,EAEA,MAAc;AACZ,QAAI;AACF,YAAM,SAAS,GAAG,aAAa,KAAK,SAAS,MAAM,EAAE,KAAK;AAC1D,UAAI,QAAQ;AACV,aAAK,MAAM;AAAA,MACb;AAAA,IACF,SAAS,OAAO;AACd,eAAS,mBAAmB,KAAK,EAAE;AAAA,IACrC;AAEA,WAAO,KAAK;AAAA,EACd;AAAA,EAEA,MAAM,OAAO,KAAa;AACxB,UAAM,WAAW,WAAW,GAAG,IAAI,MAAM,QAAQ,QAAQ,IAAI,GAAG,GAAG;AACnE,QAAI,CAAC,WAAW,QAAQ,GAAG;AACzB,YAAM,IAAI,MAAM,SAAS,QAAQ,kBAAkB;AAAA,IACrD;AACA,UAAM,WAAW,WAAW,UAAU,KAAK,SAAS;AACpD,UAAM,KAAK,KAAK,MAAM,aAAa,QAAQ,CAAC,EAAE;AAAA,EAChD;AAAA,EAEA,QAAc;AACZ,SAAK,MAAO,MAAO,IAAI;AACvB,SAAK,MAAM,KAAK;AAAA,EAClB;AACF;",
6
6
  "names": ["resolve"]
7
7
  }
@@ -178,7 +178,10 @@ class AdvancedFuzzyMatcher {
178
178
  const index = cleanText.indexOf(cleanPattern);
179
179
  if (index !== -1) {
180
180
  const positionPenalty = index * 5;
181
- return { score: Math.max(50, 100 - positionPenalty), algorithm: "fuzzy-contains" };
181
+ return {
182
+ score: Math.max(50, 100 - positionPenalty),
183
+ algorithm: "fuzzy-contains"
184
+ };
182
185
  }
183
186
  return { score: 0, algorithm: "fuzzy-segment" };
184
187
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/utils/advancedFuzzyMatcher.ts"],
4
- "sourcesContent": ["/**\n * Advanced Fuzzy Matching Algorithm\n * \n * Inspired by:\n * - Chinese Pinyin input methods (Sogou, Baidu)\n * - IDE intelligent completion (VSCode, IntelliJ)\n * - Terminal fuzzy finders (fzf, peco)\n * \n * Key features:\n * - Hyphen-aware matching (dao \u2192 dao-qi-harmony)\n * - Numeric suffix matching (py3 \u2192 python3)\n * - Abbreviation matching (dq \u2192 dao-qi)\n * - Subsequence matching\n * - Word boundary bonus\n */\n\nexport interface MatchResult {\n score: number\n matched: boolean\n algorithm: string\n}\n\nexport class AdvancedFuzzyMatcher {\n /**\n * Main matching function - combines multiple algorithms\n */\n match(candidate: string, query: string): MatchResult {\n // Normalize inputs\n const text = candidate.toLowerCase()\n const pattern = query.toLowerCase()\n \n // Quick exact match - give HUGE score for exact matches\n if (text === pattern) {\n return { score: 10000, matched: true, algorithm: 'exact' }\n }\n \n // Try all algorithms and combine scores\n const algorithms = [\n this.exactPrefixMatch(text, pattern),\n this.hyphenAwareMatch(text, pattern),\n this.wordBoundaryMatch(text, pattern),\n this.abbreviationMatch(text, pattern),\n this.numericSuffixMatch(text, pattern),\n this.subsequenceMatch(text, pattern),\n this.fuzzySegmentMatch(text, pattern),\n ]\n \n // Get best score\n let bestScore = 0\n let bestAlgorithm = 'none'\n \n for (const result of algorithms) {\n if (result.score > bestScore) {\n bestScore = result.score\n bestAlgorithm = result.algorithm\n }\n }\n \n return {\n score: bestScore,\n matched: bestScore > 10,\n algorithm: bestAlgorithm\n }\n }\n \n /**\n * Exact prefix matching\n */\n private exactPrefixMatch(text: string, pattern: string): { score: number; algorithm: string } {\n if (text.startsWith(pattern)) {\n const coverage = pattern.length / text.length\n // Higher base score for prefix matches to prioritize them\n return { score: 1000 + coverage * 500, algorithm: 'prefix' }\n }\n return { score: 0, algorithm: 'prefix' }\n }\n \n /**\n * Hyphen-aware matching (dao \u2192 dao-qi-harmony-designer)\n * Treats hyphens as optional word boundaries\n */\n private hyphenAwareMatch(text: string, pattern: string): { score: number; algorithm: string } {\n // Split by hyphens and try to match\n const words = text.split('-')\n \n // Check if pattern matches the beginning of hyphenated words\n if (words[0].startsWith(pattern)) {\n const coverage = pattern.length / words[0].length\n return { score: 300 + coverage * 100, algorithm: 'hyphen-prefix' }\n }\n \n // Check if pattern matches concatenated words (ignoring hyphens)\n const concatenated = words.join('')\n if (concatenated.startsWith(pattern)) {\n const coverage = pattern.length / concatenated.length\n return { score: 250 + coverage * 100, algorithm: 'hyphen-concat' }\n }\n \n // Check if pattern matches any word start\n for (let i = 0; i < words.length; i++) {\n if (words[i].startsWith(pattern)) {\n return { score: 200 - i * 10, algorithm: 'hyphen-word' }\n }\n }\n \n return { score: 0, algorithm: 'hyphen' }\n }\n \n /**\n * Word boundary matching (dq \u2192 dao-qi)\n * Matches characters at word boundaries\n */\n private wordBoundaryMatch(text: string, pattern: string): { score: number; algorithm: string } {\n const words = text.split(/[-_\\s]+/)\n let patternIdx = 0\n let score = 0\n let matched = false\n \n for (const word of words) {\n if (patternIdx >= pattern.length) break\n \n if (word[0] === pattern[patternIdx]) {\n score += 50 // Bonus for word boundary match\n patternIdx++\n matched = true\n \n // Try to match more characters in this word\n for (let i = 1; i < word.length && patternIdx < pattern.length; i++) {\n if (word[i] === pattern[patternIdx]) {\n score += 20\n patternIdx++\n }\n }\n }\n }\n \n if (matched && patternIdx === pattern.length) {\n return { score, algorithm: 'word-boundary' }\n }\n \n return { score: 0, algorithm: 'word-boundary' }\n }\n \n /**\n * Abbreviation matching (nde \u2192 node, daoqi \u2192 dao-qi)\n */\n private abbreviationMatch(text: string, pattern: string): { score: number; algorithm: string } {\n let textIdx = 0\n let patternIdx = 0\n let score = 0\n let lastMatchIdx = -1\n \n while (patternIdx < pattern.length && textIdx < text.length) {\n if (text[textIdx] === pattern[patternIdx]) {\n // Calculate position score\n const gap = lastMatchIdx === -1 ? 0 : textIdx - lastMatchIdx - 1\n \n if (textIdx === 0) {\n score += 50 // First character match\n } else if (lastMatchIdx >= 0 && gap === 0) {\n score += 30 // Consecutive match\n } else if (text[textIdx - 1] === '-' || text[textIdx - 1] === '_') {\n score += 40 // Word boundary match\n } else {\n score += Math.max(5, 20 - gap * 2) // Distance penalty\n }\n \n lastMatchIdx = textIdx\n patternIdx++\n }\n textIdx++\n }\n \n if (patternIdx === pattern.length) {\n // Bonus for compact matches\n const spread = lastMatchIdx / pattern.length\n if (spread <= 3) score += 50\n else if (spread <= 5) score += 30\n \n return { score, algorithm: 'abbreviation' }\n }\n \n return { score: 0, algorithm: 'abbreviation' }\n }\n \n /**\n * Numeric suffix matching (py3 \u2192 python3, np18 \u2192 node18)\n */\n private numericSuffixMatch(text: string, pattern: string): { score: number; algorithm: string } {\n // Check if pattern has numeric suffix\n const patternMatch = pattern.match(/^(.+?)(\\d+)$/)\n if (!patternMatch) return { score: 0, algorithm: 'numeric' }\n \n const [, prefix, suffix] = patternMatch\n \n // Check if text ends with same number\n if (!text.endsWith(suffix)) return { score: 0, algorithm: 'numeric' }\n \n // Check if prefix matches start of text\n const textWithoutSuffix = text.slice(0, -suffix.length)\n if (textWithoutSuffix.startsWith(prefix)) {\n const coverage = prefix.length / textWithoutSuffix.length\n return { score: 200 + coverage * 100, algorithm: 'numeric-suffix' }\n }\n \n // Check abbreviation match for prefix\n const abbrevResult = this.abbreviationMatch(textWithoutSuffix, prefix)\n if (abbrevResult.score > 0) {\n return { score: abbrevResult.score + 50, algorithm: 'numeric-abbrev' }\n }\n \n return { score: 0, algorithm: 'numeric' }\n }\n \n /**\n * Subsequence matching - characters appear in order\n */\n private subsequenceMatch(text: string, pattern: string): { score: number; algorithm: string } {\n let textIdx = 0\n let patternIdx = 0\n let score = 0\n \n while (patternIdx < pattern.length && textIdx < text.length) {\n if (text[textIdx] === pattern[patternIdx]) {\n score += 10\n patternIdx++\n }\n textIdx++\n }\n \n if (patternIdx === pattern.length) {\n // Penalty for spread\n const spread = textIdx / pattern.length\n score = Math.max(10, score - spread * 5)\n return { score, algorithm: 'subsequence' }\n }\n \n return { score: 0, algorithm: 'subsequence' }\n }\n \n /**\n * Fuzzy segment matching (dao \u2192 dao-qi-harmony)\n * Matches segments flexibly\n */\n private fuzzySegmentMatch(text: string, pattern: string): { score: number; algorithm: string } {\n // Remove hyphens and underscores for matching\n const cleanText = text.replace(/[-_]/g, '')\n const cleanPattern = pattern.replace(/[-_]/g, '')\n \n // Check if clean pattern is a prefix of clean text\n if (cleanText.startsWith(cleanPattern)) {\n const coverage = cleanPattern.length / cleanText.length\n return { score: 150 + coverage * 100, algorithm: 'fuzzy-segment' }\n }\n \n // Check if pattern appears anywhere in clean text\n const index = cleanText.indexOf(cleanPattern)\n if (index !== -1) {\n const positionPenalty = index * 5\n return { score: Math.max(50, 100 - positionPenalty), algorithm: 'fuzzy-contains' }\n }\n \n return { score: 0, algorithm: 'fuzzy-segment' }\n }\n}\n\n// Export singleton instance and helper functions\nexport const advancedMatcher = new AdvancedFuzzyMatcher()\n\nexport function matchAdvanced(candidate: string, query: string): MatchResult {\n return advancedMatcher.match(candidate, query)\n}\n\nexport function matchManyAdvanced(\n candidates: string[], \n query: string,\n minScore: number = 10\n): Array<{ candidate: string; score: number; algorithm: string }> {\n return candidates\n .map(candidate => {\n const result = advancedMatcher.match(candidate, query)\n return {\n candidate,\n score: result.score,\n algorithm: result.algorithm\n }\n })\n .filter(item => item.score >= minScore)\n .sort((a, b) => b.score - a.score)\n}"],
5
- "mappings": "AAsBO,MAAM,qBAAqB;AAAA;AAAA;AAAA;AAAA,EAIhC,MAAM,WAAmB,OAA4B;AAEnD,UAAM,OAAO,UAAU,YAAY;AACnC,UAAM,UAAU,MAAM,YAAY;AAGlC,QAAI,SAAS,SAAS;AACpB,aAAO,EAAE,OAAO,KAAO,SAAS,MAAM,WAAW,QAAQ;AAAA,IAC3D;AAGA,UAAM,aAAa;AAAA,MACjB,KAAK,iBAAiB,MAAM,OAAO;AAAA,MACnC,KAAK,iBAAiB,MAAM,OAAO;AAAA,MACnC,KAAK,kBAAkB,MAAM,OAAO;AAAA,MACpC,KAAK,kBAAkB,MAAM,OAAO;AAAA,MACpC,KAAK,mBAAmB,MAAM,OAAO;AAAA,MACrC,KAAK,iBAAiB,MAAM,OAAO;AAAA,MACnC,KAAK,kBAAkB,MAAM,OAAO;AAAA,IACtC;AAGA,QAAI,YAA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C3C;AAEA,WAAO,EAAE,OAAO,GAAG,WAAW,cAAc;AAAA,EAC9C;AAAA;AAAA;AAAA;AAAA;AAAA,EAMQ,kBAAkB,MAAc,SAAuD;AAE7F,UAAM,YAAY,KAAK,QAAQ,SAAS,EAAE;AAC1C,UAAM,eAAe,QAAQ,QAAQ,SAAS,EAAE;AAGhD,QAAI,UAAU,WAAW,YAAY,GAAG;AACtC,YAAM,WAAW,aAAa,SAAS,UAAU;AACjD,aAAO,EAAE,OAAO,MAAM,WAAW,KAAK,WAAW,gBAAgB;AAAA,IACnE;AAGA,UAAM,QAAQ,UAAU,QAAQ,YAAY;AAC5C,QAAI,UAAU,IAAI;AAChB,YAAM,kBAAkB,QAAQ;AAChC,aAAO,EAAE,OAAO,KAAK,IAAI,IAAI,MAAM,eAAe,GAAG,WAAW,iBAAiB;AAAA,IACnF;AAEA,WAAO,EAAE,OAAO,GAAG,WAAW,gBAAgB;AAAA,EAChD;AACF;AAGO,MAAM,kBAAkB,IAAI,qBAAqB;AAEjD,SAAS,cAAc,WAAmB,OAA4B;AAC3E,SAAO,gBAAgB,MAAM,WAAW,KAAK;AAC/C;AAEO,SAAS,kBACd,YACA,OACA,WAAmB,IAC6C;AAChE,SAAO,WACJ,IAAI,eAAa;AAChB,UAAM,SAAS,gBAAgB,MAAM,WAAW,KAAK;AACrD,WAAO;AAAA,MACL;AAAA,MACA,OAAO,OAAO;AAAA,MACd,WAAW,OAAO;AAAA,IACpB;AAAA,EACF,CAAC,EACA,OAAO,UAAQ,KAAK,SAAS,QAAQ,EACrC,KAAK,CAAC,GAAG,MAAM,EAAE,QAAQ,EAAE,KAAK;AACrC;",
4
+ "sourcesContent": ["/**\n * Advanced Fuzzy Matching Algorithm\n *\n * Inspired by:\n * - Chinese Pinyin input methods (Sogou, Baidu)\n * - IDE intelligent completion (VSCode, IntelliJ)\n * - Terminal fuzzy finders (fzf, peco)\n *\n * Key features:\n * - Hyphen-aware matching (dao \u2192 dao-qi-harmony)\n * - Numeric suffix matching (py3 \u2192 python3)\n * - Abbreviation matching (dq \u2192 dao-qi)\n * - Subsequence matching\n * - Word boundary bonus\n */\n\nexport interface MatchResult {\n score: number\n matched: boolean\n algorithm: string\n}\n\nexport class AdvancedFuzzyMatcher {\n /**\n * Main matching function - combines multiple algorithms\n */\n match(candidate: string, query: string): MatchResult {\n // Normalize inputs\n const text = candidate.toLowerCase()\n const pattern = query.toLowerCase()\n\n // Quick exact match - give HUGE score for exact matches\n if (text === pattern) {\n return { score: 10000, matched: true, algorithm: 'exact' }\n }\n\n // Try all algorithms and combine scores\n const algorithms = [\n this.exactPrefixMatch(text, pattern),\n this.hyphenAwareMatch(text, pattern),\n this.wordBoundaryMatch(text, pattern),\n this.abbreviationMatch(text, pattern),\n this.numericSuffixMatch(text, pattern),\n this.subsequenceMatch(text, pattern),\n this.fuzzySegmentMatch(text, pattern),\n ]\n\n // Get best score\n let bestScore = 0\n let bestAlgorithm = 'none'\n\n for (const result of algorithms) {\n if (result.score > bestScore) {\n bestScore = result.score\n bestAlgorithm = result.algorithm\n }\n }\n\n return {\n score: bestScore,\n matched: bestScore > 10,\n algorithm: bestAlgorithm,\n }\n }\n\n /**\n * Exact prefix matching\n */\n private exactPrefixMatch(\n text: string,\n pattern: string,\n ): { score: number; algorithm: string } {\n if (text.startsWith(pattern)) {\n const coverage = pattern.length / text.length\n // Higher base score for prefix matches to prioritize them\n return { score: 1000 + coverage * 500, algorithm: 'prefix' }\n }\n return { score: 0, algorithm: 'prefix' }\n }\n\n /**\n * Hyphen-aware matching (dao \u2192 dao-qi-harmony-designer)\n * Treats hyphens as optional word boundaries\n */\n private hyphenAwareMatch(\n text: string,\n pattern: string,\n ): { score: number; algorithm: string } {\n // Split by hyphens and try to match\n const words = text.split('-')\n\n // Check if pattern matches the beginning of hyphenated words\n if (words[0].startsWith(pattern)) {\n const coverage = pattern.length / words[0].length\n return { score: 300 + coverage * 100, algorithm: 'hyphen-prefix' }\n }\n\n // Check if pattern matches concatenated words (ignoring hyphens)\n const concatenated = words.join('')\n if (concatenated.startsWith(pattern)) {\n const coverage = pattern.length / concatenated.length\n return { score: 250 + coverage * 100, algorithm: 'hyphen-concat' }\n }\n\n // Check if pattern matches any word start\n for (let i = 0; i < words.length; i++) {\n if (words[i].startsWith(pattern)) {\n return { score: 200 - i * 10, algorithm: 'hyphen-word' }\n }\n }\n\n return { score: 0, algorithm: 'hyphen' }\n }\n\n /**\n * Word boundary matching (dq \u2192 dao-qi)\n * Matches characters at word boundaries\n */\n private wordBoundaryMatch(\n text: string,\n pattern: string,\n ): { score: number; algorithm: string } {\n const words = text.split(/[-_\\s]+/)\n let patternIdx = 0\n let score = 0\n let matched = false\n\n for (const word of words) {\n if (patternIdx >= pattern.length) break\n\n if (word[0] === pattern[patternIdx]) {\n score += 50 // Bonus for word boundary match\n patternIdx++\n matched = true\n\n // Try to match more characters in this word\n for (let i = 1; i < word.length && patternIdx < pattern.length; i++) {\n if (word[i] === pattern[patternIdx]) {\n score += 20\n patternIdx++\n }\n }\n }\n }\n\n if (matched && patternIdx === pattern.length) {\n return { score, algorithm: 'word-boundary' }\n }\n\n return { score: 0, algorithm: 'word-boundary' }\n }\n\n /**\n * Abbreviation matching (nde \u2192 node, daoqi \u2192 dao-qi)\n */\n private abbreviationMatch(\n text: string,\n pattern: string,\n ): { score: number; algorithm: string } {\n let textIdx = 0\n let patternIdx = 0\n let score = 0\n let lastMatchIdx = -1\n\n while (patternIdx < pattern.length && textIdx < text.length) {\n if (text[textIdx] === pattern[patternIdx]) {\n // Calculate position score\n const gap = lastMatchIdx === -1 ? 0 : textIdx - lastMatchIdx - 1\n\n if (textIdx === 0) {\n score += 50 // First character match\n } else if (lastMatchIdx >= 0 && gap === 0) {\n score += 30 // Consecutive match\n } else if (text[textIdx - 1] === '-' || text[textIdx - 1] === '_') {\n score += 40 // Word boundary match\n } else {\n score += Math.max(5, 20 - gap * 2) // Distance penalty\n }\n\n lastMatchIdx = textIdx\n patternIdx++\n }\n textIdx++\n }\n\n if (patternIdx === pattern.length) {\n // Bonus for compact matches\n const spread = lastMatchIdx / pattern.length\n if (spread <= 3) score += 50\n else if (spread <= 5) score += 30\n\n return { score, algorithm: 'abbreviation' }\n }\n\n return { score: 0, algorithm: 'abbreviation' }\n }\n\n /**\n * Numeric suffix matching (py3 \u2192 python3, np18 \u2192 node18)\n */\n private numericSuffixMatch(\n text: string,\n pattern: string,\n ): { score: number; algorithm: string } {\n // Check if pattern has numeric suffix\n const patternMatch = pattern.match(/^(.+?)(\\d+)$/)\n if (!patternMatch) return { score: 0, algorithm: 'numeric' }\n\n const [, prefix, suffix] = patternMatch\n\n // Check if text ends with same number\n if (!text.endsWith(suffix)) return { score: 0, algorithm: 'numeric' }\n\n // Check if prefix matches start of text\n const textWithoutSuffix = text.slice(0, -suffix.length)\n if (textWithoutSuffix.startsWith(prefix)) {\n const coverage = prefix.length / textWithoutSuffix.length\n return { score: 200 + coverage * 100, algorithm: 'numeric-suffix' }\n }\n\n // Check abbreviation match for prefix\n const abbrevResult = this.abbreviationMatch(textWithoutSuffix, prefix)\n if (abbrevResult.score > 0) {\n return { score: abbrevResult.score + 50, algorithm: 'numeric-abbrev' }\n }\n\n return { score: 0, algorithm: 'numeric' }\n }\n\n /**\n * Subsequence matching - characters appear in order\n */\n private subsequenceMatch(\n text: string,\n pattern: string,\n ): { score: number; algorithm: string } {\n let textIdx = 0\n let patternIdx = 0\n let score = 0\n\n while (patternIdx < pattern.length && textIdx < text.length) {\n if (text[textIdx] === pattern[patternIdx]) {\n score += 10\n patternIdx++\n }\n textIdx++\n }\n\n if (patternIdx === pattern.length) {\n // Penalty for spread\n const spread = textIdx / pattern.length\n score = Math.max(10, score - spread * 5)\n return { score, algorithm: 'subsequence' }\n }\n\n return { score: 0, algorithm: 'subsequence' }\n }\n\n /**\n * Fuzzy segment matching (dao \u2192 dao-qi-harmony)\n * Matches segments flexibly\n */\n private fuzzySegmentMatch(\n text: string,\n pattern: string,\n ): { score: number; algorithm: string } {\n // Remove hyphens and underscores for matching\n const cleanText = text.replace(/[-_]/g, '')\n const cleanPattern = pattern.replace(/[-_]/g, '')\n\n // Check if clean pattern is a prefix of clean text\n if (cleanText.startsWith(cleanPattern)) {\n const coverage = cleanPattern.length / cleanText.length\n return { score: 150 + coverage * 100, algorithm: 'fuzzy-segment' }\n }\n\n // Check if pattern appears anywhere in clean text\n const index = cleanText.indexOf(cleanPattern)\n if (index !== -1) {\n const positionPenalty = index * 5\n return {\n score: Math.max(50, 100 - positionPenalty),\n algorithm: 'fuzzy-contains',\n }\n }\n\n return { score: 0, algorithm: 'fuzzy-segment' }\n }\n}\n\n// Export singleton instance and helper functions\nexport const advancedMatcher = new AdvancedFuzzyMatcher()\n\nexport function matchAdvanced(candidate: string, query: string): MatchResult {\n return advancedMatcher.match(candidate, query)\n}\n\nexport function matchManyAdvanced(\n candidates: string[],\n query: string,\n minScore: number = 10,\n): Array<{ candidate: string; score: number; algorithm: string }> {\n return candidates\n .map(candidate => {\n const result = advancedMatcher.match(candidate, query)\n return {\n candidate,\n score: result.score,\n algorithm: result.algorithm,\n }\n })\n .filter(item => item.score >= minScore)\n .sort((a, b) => b.score - a.score)\n}\n"],
5
+ "mappings": "AAsBO,MAAM,qBAAqB;AAAA;AAAA;AAAA;AAAA,EAIhC,MAAM,WAAmB,OAA4B;AAEnD,UAAM,OAAO,UAAU,YAAY;AACnC,UAAM,UAAU,MAAM,YAAY;AAGlC,QAAI,SAAS,SAAS;AACpB,aAAO,EAAE,OAAO,KAAO,SAAS,MAAM,WAAW,QAAQ;AAAA,IAC3D;AAGA,UAAM,aAAa;AAAA,MACjB,KAAK,iBAAiB,MAAM,OAAO;AAAA,MACnC,KAAK,iBAAiB,MAAM,OAAO;AAAA,MACnC,KAAK,kBAAkB,MAAM,OAAO;AAAA,MACpC,KAAK,kBAAkB,MAAM,OAAO;AAAA,MACpC,KAAK,mBAAmB,MAAM,OAAO;AAAA,MACrC,KAAK,iBAAiB,MAAM,OAAO;AAAA,MACnC,KAA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