@qwen-code/qwen-code 0.13.0-preview.4 → 0.13.0-preview.6

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 (2) hide show
  1. package/cli.js +201 -105
  2. package/package.json +2 -2
package/cli.js CHANGED
@@ -171203,7 +171203,7 @@ __export(geminiContentGenerator_exports, {
171203
171203
  createGeminiContentGenerator: () => createGeminiContentGenerator
171204
171204
  });
171205
171205
  function createGeminiContentGenerator(config2, gcConfig) {
171206
- const version2 = "0.13.0-preview.4";
171206
+ const version2 = "0.13.0-preview.6";
171207
171207
  const userAgent2 = config2.userAgent || `QwenCode/${version2} (${process.platform}; ${process.arch})`;
171208
171208
  const baseHeaders = {
171209
171209
  "User-Agent": userAgent2
@@ -174648,7 +174648,7 @@ var init_chatCompressionService = __esm({
174648
174648
  static {
174649
174649
  __name(this, "ChatCompressionService");
174650
174650
  }
174651
- async compress(chat, promptId, force, model, config2, hasFailedCompressionAttempt) {
174651
+ async compress(chat, promptId, force, model, config2, hasFailedCompressionAttempt, signal) {
174652
174652
  const curatedHistory = chat.getHistory(true);
174653
174653
  const threshold = config2.getChatCompression()?.contextPercentageThreshold ?? COMPRESSION_TOKEN_THRESHOLD;
174654
174654
  if (curatedHistory.length === 0 || threshold <= 0 || hasFailedCompressionAttempt && !force) {
@@ -174679,7 +174679,7 @@ var init_chatCompressionService = __esm({
174679
174679
  if (hookSystem) {
174680
174680
  const trigger = force ? PreCompactTrigger.Manual : PreCompactTrigger.Auto;
174681
174681
  try {
174682
- await hookSystem.firePreCompactEvent(trigger, "");
174682
+ await hookSystem.firePreCompactEvent(trigger, "", signal);
174683
174683
  } catch (err2) {
174684
174684
  config2.getDebugLogger().warn(`PreCompact hook failed: ${err2}`);
174685
174685
  }
@@ -174778,7 +174778,8 @@ var init_chatCompressionService = __esm({
174778
174778
  } else {
174779
174779
  uiTelemetryService.setLastPromptTokenCount(newTokenCount);
174780
174780
  try {
174781
- await config2.getHookSystem()?.fireSessionStartEvent(SessionStartSource.Compact, model ?? "");
174781
+ const permissionMode = String(config2.getApprovalMode());
174782
+ await config2.getHookSystem()?.fireSessionStartEvent(SessionStartSource.Compact, model ?? "", permissionMode, void 0, signal);
174782
174783
  } catch (err2) {
174783
174784
  config2.getDebugLogger().warn(`SessionStart hook failed: ${err2}`);
174784
174785
  }
@@ -175075,7 +175076,7 @@ var init_types7 = __esm({
175075
175076
  function generateToolUseId() {
175076
175077
  return `toolu_${Date.now()}_${Math.random().toString(36).substring(2, 11)}`;
175077
175078
  }
175078
- async function firePreToolUseHook(messageBus, toolName, toolInput, toolUseId, permissionMode) {
175079
+ async function firePreToolUseHook(messageBus, toolName, toolInput, toolUseId, permissionMode, signal) {
175079
175080
  if (!messageBus) {
175080
175081
  return { shouldProceed: true };
175081
175082
  }
@@ -175088,7 +175089,8 @@ async function firePreToolUseHook(messageBus, toolName, toolInput, toolUseId, pe
175088
175089
  tool_name: toolName,
175089
175090
  tool_input: toolInput,
175090
175091
  tool_use_id: toolUseId
175091
- }
175092
+ },
175093
+ signal
175092
175094
  }, MessageBusType.HOOK_EXECUTION_RESPONSE);
175093
175095
  if (!response.success || !response.output) {
175094
175096
  return { shouldProceed: true };
@@ -175125,7 +175127,7 @@ async function firePreToolUseHook(messageBus, toolName, toolInput, toolUseId, pe
175125
175127
  return { shouldProceed: true };
175126
175128
  }
175127
175129
  }
175128
- async function firePostToolUseHook(messageBus, toolName, toolInput, toolResponse, toolUseId, permissionMode) {
175130
+ async function firePostToolUseHook(messageBus, toolName, toolInput, toolResponse, toolUseId, permissionMode, signal) {
175129
175131
  if (!messageBus) {
175130
175132
  return { shouldStop: false };
175131
175133
  }
@@ -175139,7 +175141,8 @@ async function firePostToolUseHook(messageBus, toolName, toolInput, toolResponse
175139
175141
  tool_input: toolInput,
175140
175142
  tool_response: toolResponse,
175141
175143
  tool_use_id: toolUseId
175142
- }
175144
+ },
175145
+ signal
175143
175146
  }, MessageBusType.HOOK_EXECUTION_RESPONSE);
175144
175147
  if (!response.success || !response.output) {
175145
175148
  return { shouldStop: false };
@@ -175161,7 +175164,7 @@ async function firePostToolUseHook(messageBus, toolName, toolInput, toolResponse
175161
175164
  return { shouldStop: false };
175162
175165
  }
175163
175166
  }
175164
- async function firePostToolUseFailureHook(messageBus, toolUseId, toolName, toolInput, errorMessage, isInterrupt, permissionMode) {
175167
+ async function firePostToolUseFailureHook(messageBus, toolUseId, toolName, toolInput, errorMessage, isInterrupt, permissionMode, signal) {
175165
175168
  if (!messageBus) {
175166
175169
  return {};
175167
175170
  }
@@ -175176,7 +175179,8 @@ async function firePostToolUseFailureHook(messageBus, toolUseId, toolName, toolI
175176
175179
  tool_input: toolInput,
175177
175180
  error: errorMessage,
175178
175181
  is_interrupt: isInterrupt
175179
- }
175182
+ },
175183
+ signal
175180
175184
  }, MessageBusType.HOOK_EXECUTION_RESPONSE);
175181
175185
  if (!response.success || !response.output) {
175182
175186
  return {};
@@ -175191,7 +175195,7 @@ async function firePostToolUseFailureHook(messageBus, toolUseId, toolName, toolI
175191
175195
  return {};
175192
175196
  }
175193
175197
  }
175194
- async function fireNotificationHook(messageBus, message, notificationType, title) {
175198
+ async function fireNotificationHook(messageBus, message, notificationType, title, signal) {
175195
175199
  if (!messageBus) {
175196
175200
  return {};
175197
175201
  }
@@ -175203,7 +175207,8 @@ async function fireNotificationHook(messageBus, message, notificationType, title
175203
175207
  message,
175204
175208
  notification_type: notificationType,
175205
175209
  title
175206
- }
175210
+ },
175211
+ signal
175207
175212
  }, MessageBusType.HOOK_EXECUTION_RESPONSE);
175208
175213
  if (!response.success || !response.output) {
175209
175214
  return {};
@@ -175218,7 +175223,7 @@ async function fireNotificationHook(messageBus, message, notificationType, title
175218
175223
  return {};
175219
175224
  }
175220
175225
  }
175221
- async function firePermissionRequestHook(messageBus, toolName, toolInput, permissionMode, permissionSuggestions) {
175226
+ async function firePermissionRequestHook(messageBus, toolName, toolInput, permissionMode, permissionSuggestions, signal) {
175222
175227
  if (!messageBus) {
175223
175228
  return { hasDecision: false };
175224
175229
  }
@@ -175231,7 +175236,8 @@ async function firePermissionRequestHook(messageBus, toolName, toolInput, permis
175231
175236
  tool_input: toolInput,
175232
175237
  permission_mode: permissionMode,
175233
175238
  permission_suggestions: permissionSuggestions
175234
- }
175239
+ },
175240
+ signal
175235
175241
  }, MessageBusType.HOOK_EXECUTION_RESPONSE);
175236
175242
  if (!response.success || !response.output) {
175237
175243
  return { hasDecision: false };
@@ -190439,7 +190445,7 @@ assistant: "I'm going to use the ${ToolNames.AGENT} tool to launch the greeting-
190439
190445
  const agentType = this.params.subagent_type;
190440
190446
  if (hookSystem) {
190441
190447
  try {
190442
- const startHookOutput = await hookSystem.fireSubagentStartEvent(agentId, agentType, PermissionMode.Default);
190448
+ const startHookOutput = await hookSystem.fireSubagentStartEvent(agentId, agentType, PermissionMode.Default, signal);
190443
190449
  const additionalContext = startHookOutput?.getAdditionalContext();
190444
190450
  if (additionalContext) {
190445
190451
  contextState.set("hook_context", additionalContext);
@@ -190463,7 +190469,7 @@ assistant: "I'm going to use the ${ToolNames.AGENT} tool to launch the greeting-
190463
190469
  break;
190464
190470
  }
190465
190471
  try {
190466
- const stopHookOutput = await hookSystem.fireSubagentStopEvent(agentId, agentType, transcriptPath, subagent.getFinalText(), stopHookActive, PermissionMode.Default);
190472
+ const stopHookOutput = await hookSystem.fireSubagentStopEvent(agentId, agentType, transcriptPath, subagent.getFinalText(), stopHookActive, PermissionMode.Default, signal);
190467
190473
  const typedStopOutput = stopHookOutput;
190468
190474
  if (typedStopOutput?.isBlockingDecision() || typedStopOutput?.shouldStopExecution()) {
190469
190475
  const continueReason = typedStopOutput.getEffectiveReason();
@@ -195982,7 +195988,7 @@ var init_client2 = __esm({
195982
195988
  if (!boundedTurns) {
195983
195989
  return new Turn(this.getChat(), prompt_id);
195984
195990
  }
195985
- const compressed = await this.tryCompressChat(prompt_id, false);
195991
+ const compressed = await this.tryCompressChat(prompt_id, false, signal);
195986
195992
  if (compressed.compressionStatus === CompressionStatus.COMPRESSED) {
195987
195993
  yield { type: GeminiEventType.ChatCompressed, value: compressed };
195988
195994
  }
@@ -196070,7 +196076,7 @@ var init_client2 = __esm({
196070
196076
  return turn;
196071
196077
  }
196072
196078
  }
196073
- if (hooksEnabled && messageBus && !turn.pendingToolCalls.length) {
196079
+ if (hooksEnabled && messageBus && !turn.pendingToolCalls.length && signal && !signal.aborted) {
196074
196080
  const history2 = this.getHistory();
196075
196081
  const lastModelMessage = history2.filter((msg) => msg.role === "model").pop();
196076
196082
  const responseText = lastModelMessage?.parts?.filter((p2) => "text" in p2).map((p2) => p2.text).join("") || "[no response text]";
@@ -196080,16 +196086,23 @@ var init_client2 = __esm({
196080
196086
  input: {
196081
196087
  stop_hook_active: true,
196082
196088
  last_assistant_message: responseText
196083
- }
196089
+ },
196090
+ signal
196084
196091
  }, MessageBusType.HOOK_EXECUTION_RESPONSE);
196092
+ if (signal.aborted) {
196093
+ return turn;
196094
+ }
196085
196095
  const hookOutput = response.output ? createHookOutput("Stop", response.output) : void 0;
196086
196096
  const stopOutput = hookOutput;
196097
+ if (stopOutput?.systemMessage) {
196098
+ yield {
196099
+ type: GeminiEventType.HookSystemMessage,
196100
+ value: stopOutput.systemMessage
196101
+ };
196102
+ }
196087
196103
  if (stopOutput?.isBlockingDecision() || stopOutput?.shouldStopExecution()) {
196088
- if (stopOutput.systemMessage) {
196089
- yield {
196090
- type: GeminiEventType.HookSystemMessage,
196091
- value: stopOutput.systemMessage
196092
- };
196104
+ if (signal.aborted) {
196105
+ return turn;
196093
196106
  }
196094
196107
  const continueReason = stopOutput.getEffectiveReason();
196095
196108
  const continueRequest = [{ text: continueReason }];
@@ -196151,9 +196164,9 @@ var init_client2 = __esm({
196151
196164
  throw new Error(`Failed to generate content with model ${currentAttemptModel}: ${getErrorMessage(error40)}`);
196152
196165
  }
196153
196166
  }
196154
- async tryCompressChat(prompt_id, force = false) {
196167
+ async tryCompressChat(prompt_id, force = false, signal) {
196155
196168
  const compressionService = new ChatCompressionService();
196156
- const { newHistory, info: info2 } = await compressionService.compress(this.getChat(), prompt_id, force, this.config.getModel(), this.config, this.hasFailedCompressionAttempt);
196169
+ const { newHistory, info: info2 } = await compressionService.compress(this.getChat(), prompt_id, force, this.config.getModel(), this.config, this.hasFailedCompressionAttempt, signal);
196157
196170
  if (info2.compressionStatus === CompressionStatus.COMPRESSED) {
196158
196171
  if (newHistory) {
196159
196172
  const chatRecordingService = this.config.getChatRecordingService();
@@ -264533,11 +264546,25 @@ var init_hookRunner = __esm({
264533
264546
  }
264534
264547
  /**
264535
264548
  * Execute a single hook
264549
+ * @param hookConfig Hook configuration
264550
+ * @param eventName Event name
264551
+ * @param input Hook input
264552
+ * @param signal Optional AbortSignal to cancel hook execution
264536
264553
  */
264537
- async executeHook(hookConfig, eventName, input) {
264554
+ async executeHook(hookConfig, eventName, input, signal) {
264538
264555
  const startTime = Date.now();
264556
+ if (signal?.aborted) {
264557
+ const hookId = hookConfig.name || hookConfig.command || "unknown";
264558
+ return {
264559
+ hookConfig,
264560
+ eventName,
264561
+ success: false,
264562
+ error: new Error(`Hook execution cancelled (aborted): ${hookId}`),
264563
+ duration: 0
264564
+ };
264565
+ }
264539
264566
  try {
264540
- return await this.executeCommandHook(hookConfig, eventName, input, startTime);
264567
+ return await this.executeCommandHook(hookConfig, eventName, input, startTime, signal);
264541
264568
  } catch (error40) {
264542
264569
  const duration3 = Date.now() - startTime;
264543
264570
  const hookId = hookConfig.name || hookConfig.command || "unknown";
@@ -264554,11 +264581,12 @@ var init_hookRunner = __esm({
264554
264581
  }
264555
264582
  /**
264556
264583
  * Execute multiple hooks in parallel
264584
+ * @param signal Optional AbortSignal to cancel hook execution
264557
264585
  */
264558
- async executeHooksParallel(hookConfigs, eventName, input, onHookStart, onHookEnd) {
264586
+ async executeHooksParallel(hookConfigs, eventName, input, onHookStart, onHookEnd, signal) {
264559
264587
  const promises8 = hookConfigs.map(async (config2, index) => {
264560
264588
  onHookStart?.(config2, index);
264561
- const result = await this.executeHook(config2, eventName, input);
264589
+ const result = await this.executeHook(config2, eventName, input, signal);
264562
264590
  onHookEnd?.(config2, result);
264563
264591
  return result;
264564
264592
  });
@@ -264566,14 +264594,18 @@ var init_hookRunner = __esm({
264566
264594
  }
264567
264595
  /**
264568
264596
  * Execute multiple hooks sequentially
264597
+ * @param signal Optional AbortSignal to cancel hook execution
264569
264598
  */
264570
- async executeHooksSequential(hookConfigs, eventName, input, onHookStart, onHookEnd) {
264599
+ async executeHooksSequential(hookConfigs, eventName, input, onHookStart, onHookEnd, signal) {
264571
264600
  const results = [];
264572
264601
  let currentInput = input;
264573
264602
  for (let i4 = 0; i4 < hookConfigs.length; i4++) {
264603
+ if (signal?.aborted) {
264604
+ break;
264605
+ }
264574
264606
  const config2 = hookConfigs[i4];
264575
264607
  onHookStart?.(config2, i4);
264576
- const result = await this.executeHook(config2, eventName, currentInput);
264608
+ const result = await this.executeHook(config2, eventName, currentInput, signal);
264577
264609
  onHookEnd?.(config2, result);
264578
264610
  results.push(result);
264579
264611
  if (result.success && result.output) {
@@ -264616,8 +264648,13 @@ var init_hookRunner = __esm({
264616
264648
  }
264617
264649
  /**
264618
264650
  * Execute a command hook
264651
+ * @param hookConfig Hook configuration
264652
+ * @param eventName Event name
264653
+ * @param input Hook input
264654
+ * @param startTime Start time for duration calculation
264655
+ * @param signal Optional AbortSignal to cancel hook execution
264619
264656
  */
264620
- async executeCommandHook(hookConfig, eventName, input, startTime) {
264657
+ async executeCommandHook(hookConfig, eventName, input, startTime, signal) {
264621
264658
  const timeout2 = hookConfig.timeout ?? DEFAULT_HOOK_TIMEOUT;
264622
264659
  return new Promise((resolve35) => {
264623
264660
  if (!hookConfig.command) {
@@ -264635,6 +264672,7 @@ var init_hookRunner = __esm({
264635
264672
  let stdout2 = "";
264636
264673
  let stderr = "";
264637
264674
  let timedOut = false;
264675
+ let aborted2 = false;
264638
264676
  const shellConfig = getShellConfiguration();
264639
264677
  const command2 = this.expandCommand(hookConfig.command, input, shellConfig.shell);
264640
264678
  const env6 = {
@@ -264652,15 +264690,28 @@ var init_hookRunner = __esm({
264652
264690
  stdio: ["pipe", "pipe", "pipe"],
264653
264691
  shell: false
264654
264692
  });
264693
+ const killChild = /* @__PURE__ */ __name(() => {
264694
+ if (!child.killed) {
264695
+ child.kill("SIGTERM");
264696
+ setTimeout(() => {
264697
+ if (!child.killed) {
264698
+ child.kill("SIGKILL");
264699
+ }
264700
+ }, 2e3);
264701
+ }
264702
+ }, "killChild");
264655
264703
  const timeoutHandle = setTimeout(() => {
264656
264704
  timedOut = true;
264657
- child.kill("SIGTERM");
264658
- setTimeout(() => {
264659
- if (!child.killed) {
264660
- child.kill("SIGKILL");
264661
- }
264662
- }, 5e3);
264705
+ killChild();
264663
264706
  }, timeout2);
264707
+ const abortHandler = /* @__PURE__ */ __name(() => {
264708
+ aborted2 = true;
264709
+ clearTimeout(timeoutHandle);
264710
+ killChild();
264711
+ }, "abortHandler");
264712
+ if (signal) {
264713
+ signal.addEventListener("abort", abortHandler);
264714
+ }
264664
264715
  if (child.stdin) {
264665
264716
  child.stdin.on("error", (err2) => {
264666
264717
  if (err2.code !== "EPIPE") {
@@ -264696,7 +264747,22 @@ var init_hookRunner = __esm({
264696
264747
  });
264697
264748
  child.on("close", (exitCode) => {
264698
264749
  clearTimeout(timeoutHandle);
264750
+ if (signal) {
264751
+ signal.removeEventListener("abort", abortHandler);
264752
+ }
264699
264753
  const duration3 = Date.now() - startTime;
264754
+ if (aborted2) {
264755
+ resolve35({
264756
+ hookConfig,
264757
+ eventName,
264758
+ success: false,
264759
+ error: new Error("Hook execution cancelled (aborted)"),
264760
+ stdout: stdout2,
264761
+ stderr,
264762
+ duration: duration3
264763
+ });
264764
+ return;
264765
+ }
264700
264766
  if (timedOut) {
264701
264767
  resolve35({
264702
264768
  hookConfig,
@@ -265231,30 +265297,30 @@ var init_hookEventHandler = __esm({
265231
265297
  * Fire a UserPromptSubmit event
265232
265298
  * Called by handleHookExecutionRequest - executes hooks directly
265233
265299
  */
265234
- async fireUserPromptSubmitEvent(prompt) {
265300
+ async fireUserPromptSubmitEvent(prompt, signal) {
265235
265301
  const input = {
265236
265302
  ...this.createBaseInput(HookEventName.UserPromptSubmit),
265237
265303
  prompt
265238
265304
  };
265239
- return this.executeHooks(HookEventName.UserPromptSubmit, input);
265305
+ return this.executeHooks(HookEventName.UserPromptSubmit, input, void 0, signal);
265240
265306
  }
265241
265307
  /**
265242
265308
  * Fire a Stop event
265243
265309
  * Called by handleHookExecutionRequest - executes hooks directly
265244
265310
  */
265245
- async fireStopEvent(stopHookActive = false, lastAssistantMessage = "") {
265311
+ async fireStopEvent(stopHookActive = false, lastAssistantMessage = "", signal) {
265246
265312
  const input = {
265247
265313
  ...this.createBaseInput(HookEventName.Stop),
265248
265314
  stop_hook_active: stopHookActive,
265249
265315
  last_assistant_message: lastAssistantMessage
265250
265316
  };
265251
- return this.executeHooks(HookEventName.Stop, input);
265317
+ return this.executeHooks(HookEventName.Stop, input, void 0, signal);
265252
265318
  }
265253
265319
  /**
265254
265320
  * Fire a SessionStart event
265255
265321
  * Called when a new session starts or resumes
265256
265322
  */
265257
- async fireSessionStartEvent(source2, model, permissionMode, agentType) {
265323
+ async fireSessionStartEvent(source2, model, permissionMode, agentType, signal) {
265258
265324
  const input = {
265259
265325
  ...this.createBaseInput(HookEventName.SessionStart),
265260
265326
  permission_mode: permissionMode ?? PermissionMode.Default,
@@ -265264,26 +265330,26 @@ var init_hookEventHandler = __esm({
265264
265330
  };
265265
265331
  return this.executeHooks(HookEventName.SessionStart, input, {
265266
265332
  trigger: source2
265267
- });
265333
+ }, signal);
265268
265334
  }
265269
265335
  /**
265270
265336
  * Fire a SessionEnd event
265271
265337
  * Called when a session ends
265272
265338
  */
265273
- async fireSessionEndEvent(reason) {
265339
+ async fireSessionEndEvent(reason, signal) {
265274
265340
  const input = {
265275
265341
  ...this.createBaseInput(HookEventName.SessionEnd),
265276
265342
  reason
265277
265343
  };
265278
265344
  return this.executeHooks(HookEventName.SessionEnd, input, {
265279
265345
  trigger: reason
265280
- });
265346
+ }, signal);
265281
265347
  }
265282
265348
  /**
265283
265349
  * Fire a PreToolUse event
265284
265350
  * Called before tool execution begins
265285
265351
  */
265286
- async firePreToolUseEvent(toolName, toolInput, toolUseId, permissionMode) {
265352
+ async firePreToolUseEvent(toolName, toolInput, toolUseId, permissionMode, signal) {
265287
265353
  const input = {
265288
265354
  ...this.createBaseInput(HookEventName.PreToolUse),
265289
265355
  permission_mode: permissionMode,
@@ -265293,13 +265359,13 @@ var init_hookEventHandler = __esm({
265293
265359
  };
265294
265360
  return this.executeHooks(HookEventName.PreToolUse, input, {
265295
265361
  toolName
265296
- });
265362
+ }, signal);
265297
265363
  }
265298
265364
  /**
265299
265365
  * Fire a PostToolUse event
265300
265366
  * Called after successful tool execution
265301
265367
  */
265302
- async firePostToolUseEvent(toolName, toolInput, toolResponse, toolUseId, permissionMode) {
265368
+ async firePostToolUseEvent(toolName, toolInput, toolResponse, toolUseId, permissionMode, signal) {
265303
265369
  const input = {
265304
265370
  ...this.createBaseInput(HookEventName.PostToolUse),
265305
265371
  permission_mode: permissionMode,
@@ -265310,13 +265376,13 @@ var init_hookEventHandler = __esm({
265310
265376
  };
265311
265377
  return this.executeHooks(HookEventName.PostToolUse, input, {
265312
265378
  toolName
265313
- });
265379
+ }, signal);
265314
265380
  }
265315
265381
  /**
265316
265382
  * Fire a PostToolUseFailure event
265317
265383
  * Called when tool execution fails
265318
265384
  */
265319
- async firePostToolUseFailureEvent(toolUseId, toolName, toolInput, errorMessage, isInterrupt, permissionMode) {
265385
+ async firePostToolUseFailureEvent(toolUseId, toolName, toolInput, errorMessage, isInterrupt, permissionMode, signal) {
265320
265386
  const input = {
265321
265387
  ...this.createBaseInput(HookEventName.PostToolUseFailure),
265322
265388
  permission_mode: permissionMode ?? PermissionMode.Default,
@@ -265328,13 +265394,13 @@ var init_hookEventHandler = __esm({
265328
265394
  };
265329
265395
  return this.executeHooks(HookEventName.PostToolUseFailure, input, {
265330
265396
  toolName
265331
- });
265397
+ }, signal);
265332
265398
  }
265333
265399
  /**
265334
265400
  * Fire a PreCompact event
265335
265401
  * Called before conversation compaction begins
265336
265402
  */
265337
- async firePreCompactEvent(trigger, customInstructions = "") {
265403
+ async firePreCompactEvent(trigger, customInstructions = "", signal) {
265338
265404
  const input = {
265339
265405
  ...this.createBaseInput(HookEventName.PreCompact),
265340
265406
  trigger,
@@ -265342,12 +265408,12 @@ var init_hookEventHandler = __esm({
265342
265408
  };
265343
265409
  return this.executeHooks(HookEventName.PreCompact, input, {
265344
265410
  trigger
265345
- });
265411
+ }, signal);
265346
265412
  }
265347
265413
  /**
265348
265414
  * Fire a Notification event
265349
265415
  */
265350
- async fireNotificationEvent(message, notificationType, title) {
265416
+ async fireNotificationEvent(message, notificationType, title, signal) {
265351
265417
  const input = {
265352
265418
  ...this.createBaseInput(HookEventName.Notification),
265353
265419
  message,
@@ -265356,13 +265422,13 @@ var init_hookEventHandler = __esm({
265356
265422
  };
265357
265423
  return this.executeHooks(HookEventName.Notification, input, {
265358
265424
  notificationType
265359
- });
265425
+ }, signal);
265360
265426
  }
265361
265427
  /**
265362
265428
  * Fire a PermissionRequest event
265363
265429
  * Called when a permission dialog is about to be shown to the user
265364
265430
  */
265365
- async firePermissionRequestEvent(toolName, toolInput, permissionMode, permissionSuggestions) {
265431
+ async firePermissionRequestEvent(toolName, toolInput, permissionMode, permissionSuggestions, signal) {
265366
265432
  const input = {
265367
265433
  ...this.createBaseInput(HookEventName.PermissionRequest),
265368
265434
  permission_mode: permissionMode,
@@ -265372,13 +265438,13 @@ var init_hookEventHandler = __esm({
265372
265438
  };
265373
265439
  return this.executeHooks(HookEventName.PermissionRequest, input, {
265374
265440
  toolName
265375
- });
265441
+ }, signal);
265376
265442
  }
265377
265443
  /**
265378
265444
  * Fire a SubagentStart event
265379
265445
  * Called when a subagent is spawned via the Agent tool
265380
265446
  */
265381
- async fireSubagentStartEvent(agentId, agentType, permissionMode) {
265447
+ async fireSubagentStartEvent(agentId, agentType, permissionMode, signal) {
265382
265448
  const input = {
265383
265449
  ...this.createBaseInput(HookEventName.SubagentStart),
265384
265450
  permission_mode: permissionMode,
@@ -265387,13 +265453,13 @@ var init_hookEventHandler = __esm({
265387
265453
  };
265388
265454
  return this.executeHooks(HookEventName.SubagentStart, input, {
265389
265455
  agentType: String(agentType)
265390
- });
265456
+ }, signal);
265391
265457
  }
265392
265458
  /**
265393
265459
  * Fire a SubagentStop event
265394
265460
  * Called when a subagent has finished responding
265395
265461
  */
265396
- async fireSubagentStopEvent(agentId, agentType, agentTranscriptPath, lastAssistantMessage, stopHookActive, permissionMode) {
265462
+ async fireSubagentStopEvent(agentId, agentType, agentTranscriptPath, lastAssistantMessage, stopHookActive, permissionMode, signal) {
265397
265463
  const input = {
265398
265464
  ...this.createBaseInput(HookEventName.SubagentStop),
265399
265465
  permission_mode: permissionMode,
@@ -265405,13 +265471,13 @@ var init_hookEventHandler = __esm({
265405
265471
  };
265406
265472
  return this.executeHooks(HookEventName.SubagentStop, input, {
265407
265473
  agentType: String(agentType)
265408
- });
265474
+ }, signal);
265409
265475
  }
265410
265476
  /**
265411
265477
  * Execute hooks for a specific event (direct execution without MessageBus)
265412
265478
  * Used as fallback when MessageBus is not available
265413
265479
  */
265414
- async executeHooks(eventName, input, context2) {
265480
+ async executeHooks(eventName, input, context2, signal) {
265415
265481
  try {
265416
265482
  const plan = this.hookPlanner.createExecutionPlan(eventName, context2);
265417
265483
  if (!plan || plan.hookConfigs.length === 0) {
@@ -265426,7 +265492,7 @@ var init_hookEventHandler = __esm({
265426
265492
  }, "onHookStart");
265427
265493
  const onHookEnd = /* @__PURE__ */ __name((_config, _result) => {
265428
265494
  }, "onHookEnd");
265429
- const results = plan.sequential ? await this.hookRunner.executeHooksSequential(plan.hookConfigs, eventName, input, onHookStart, onHookEnd) : await this.hookRunner.executeHooksParallel(plan.hookConfigs, eventName, input, onHookStart, onHookEnd);
265495
+ const results = plan.sequential ? await this.hookRunner.executeHooksSequential(plan.hookConfigs, eventName, input, onHookStart, onHookEnd, signal) : await this.hookRunner.executeHooksParallel(plan.hookConfigs, eventName, input, onHookStart, onHookEnd, signal);
265430
265496
  const aggregated = this.hookAggregator.aggregateResults(results, eventName);
265431
265497
  this.processCommonHookOutputFields(aggregated);
265432
265498
  return aggregated;
@@ -265534,76 +265600,76 @@ var init_hookSystem = __esm({
265534
265600
  getAllHooks() {
265535
265601
  return this.hookRegistry.getAllHooks();
265536
265602
  }
265537
- async fireUserPromptSubmitEvent(prompt) {
265538
- const result = await this.hookEventHandler.fireUserPromptSubmitEvent(prompt);
265603
+ async fireUserPromptSubmitEvent(prompt, signal) {
265604
+ const result = await this.hookEventHandler.fireUserPromptSubmitEvent(prompt, signal);
265539
265605
  return result.finalOutput ? createHookOutput("UserPromptSubmit", result.finalOutput) : void 0;
265540
265606
  }
265541
- async fireStopEvent(stopHookActive = false, lastAssistantMessage = "") {
265542
- const result = await this.hookEventHandler.fireStopEvent(stopHookActive, lastAssistantMessage);
265607
+ async fireStopEvent(stopHookActive = false, lastAssistantMessage = "", signal) {
265608
+ const result = await this.hookEventHandler.fireStopEvent(stopHookActive, lastAssistantMessage, signal);
265543
265609
  return result.finalOutput ? createHookOutput("Stop", result.finalOutput) : void 0;
265544
265610
  }
265545
- async fireSessionStartEvent(source2, model, permissionMode, agentType) {
265546
- const result = await this.hookEventHandler.fireSessionStartEvent(source2, model, permissionMode, agentType);
265611
+ async fireSessionStartEvent(source2, model, permissionMode, agentType, signal) {
265612
+ const result = await this.hookEventHandler.fireSessionStartEvent(source2, model, permissionMode, agentType, signal);
265547
265613
  return result.finalOutput ? createHookOutput("SessionStart", result.finalOutput) : void 0;
265548
265614
  }
265549
- async fireSessionEndEvent(reason) {
265550
- const result = await this.hookEventHandler.fireSessionEndEvent(reason);
265615
+ async fireSessionEndEvent(reason, signal) {
265616
+ const result = await this.hookEventHandler.fireSessionEndEvent(reason, signal);
265551
265617
  return result.finalOutput ? createHookOutput("SessionEnd", result.finalOutput) : void 0;
265552
265618
  }
265553
265619
  /**
265554
265620
  * Fire a PreToolUse event - called before tool execution
265555
265621
  */
265556
- async firePreToolUseEvent(toolName, toolInput, toolUseId, permissionMode) {
265557
- const result = await this.hookEventHandler.firePreToolUseEvent(toolName, toolInput, toolUseId, permissionMode);
265622
+ async firePreToolUseEvent(toolName, toolInput, toolUseId, permissionMode, signal) {
265623
+ const result = await this.hookEventHandler.firePreToolUseEvent(toolName, toolInput, toolUseId, permissionMode, signal);
265558
265624
  return result.finalOutput ? createHookOutput("PreToolUse", result.finalOutput) : void 0;
265559
265625
  }
265560
265626
  /**
265561
265627
  * Fire a PostToolUse event - called after successful tool execution
265562
265628
  */
265563
- async firePostToolUseEvent(toolName, toolInput, toolResponse, toolUseId, permissionMode) {
265564
- const result = await this.hookEventHandler.firePostToolUseEvent(toolName, toolInput, toolResponse, toolUseId, permissionMode);
265629
+ async firePostToolUseEvent(toolName, toolInput, toolResponse, toolUseId, permissionMode, signal) {
265630
+ const result = await this.hookEventHandler.firePostToolUseEvent(toolName, toolInput, toolResponse, toolUseId, permissionMode, signal);
265565
265631
  return result.finalOutput ? createHookOutput("PostToolUse", result.finalOutput) : void 0;
265566
265632
  }
265567
265633
  /**
265568
265634
  * Fire a PostToolUseFailure event - called when tool execution fails
265569
265635
  */
265570
- async firePostToolUseFailureEvent(toolUseId, toolName, toolInput, errorMessage, isInterrupt, permissionMode) {
265571
- const result = await this.hookEventHandler.firePostToolUseFailureEvent(toolUseId, toolName, toolInput, errorMessage, isInterrupt, permissionMode);
265636
+ async firePostToolUseFailureEvent(toolUseId, toolName, toolInput, errorMessage, isInterrupt, permissionMode, signal) {
265637
+ const result = await this.hookEventHandler.firePostToolUseFailureEvent(toolUseId, toolName, toolInput, errorMessage, isInterrupt, permissionMode, signal);
265572
265638
  return result.finalOutput ? createHookOutput("PostToolUseFailure", result.finalOutput) : void 0;
265573
265639
  }
265574
265640
  /**
265575
265641
  * Fire a PreCompact event - called before conversation compaction
265576
265642
  */
265577
- async firePreCompactEvent(trigger, customInstructions = "") {
265578
- const result = await this.hookEventHandler.firePreCompactEvent(trigger, customInstructions);
265643
+ async firePreCompactEvent(trigger, customInstructions = "", signal) {
265644
+ const result = await this.hookEventHandler.firePreCompactEvent(trigger, customInstructions, signal);
265579
265645
  return result.finalOutput ? createHookOutput("PreCompact", result.finalOutput) : void 0;
265580
265646
  }
265581
265647
  /**
265582
265648
  * Fire a Notification event
265583
265649
  */
265584
- async fireNotificationEvent(message, notificationType, title) {
265585
- const result = await this.hookEventHandler.fireNotificationEvent(message, notificationType, title);
265650
+ async fireNotificationEvent(message, notificationType, title, signal) {
265651
+ const result = await this.hookEventHandler.fireNotificationEvent(message, notificationType, title, signal);
265586
265652
  return result.finalOutput ? createHookOutput("Notification", result.finalOutput) : void 0;
265587
265653
  }
265588
265654
  /**
265589
265655
  * Fire a SubagentStart event - called when a subagent is spawned
265590
265656
  */
265591
- async fireSubagentStartEvent(agentId, agentType, permissionMode) {
265592
- const result = await this.hookEventHandler.fireSubagentStartEvent(agentId, agentType, permissionMode);
265657
+ async fireSubagentStartEvent(agentId, agentType, permissionMode, signal) {
265658
+ const result = await this.hookEventHandler.fireSubagentStartEvent(agentId, agentType, permissionMode, signal);
265593
265659
  return result.finalOutput ? createHookOutput("SubagentStart", result.finalOutput) : void 0;
265594
265660
  }
265595
265661
  /**
265596
265662
  * Fire a SubagentStop event - called when a subagent finishes
265597
265663
  */
265598
- async fireSubagentStopEvent(agentId, agentType, agentTranscriptPath, lastAssistantMessage, stopHookActive, permissionMode) {
265599
- const result = await this.hookEventHandler.fireSubagentStopEvent(agentId, agentType, agentTranscriptPath, lastAssistantMessage, stopHookActive, permissionMode);
265664
+ async fireSubagentStopEvent(agentId, agentType, agentTranscriptPath, lastAssistantMessage, stopHookActive, permissionMode, signal) {
265665
+ const result = await this.hookEventHandler.fireSubagentStopEvent(agentId, agentType, agentTranscriptPath, lastAssistantMessage, stopHookActive, permissionMode, signal);
265600
265666
  return result.finalOutput ? createHookOutput("SubagentStop", result.finalOutput) : void 0;
265601
265667
  }
265602
265668
  /**
265603
265669
  * Fire a PermissionRequest event
265604
265670
  */
265605
- async firePermissionRequestEvent(toolName, toolInput, permissionMode, permissionSuggestions) {
265606
- const result = await this.hookEventHandler.firePermissionRequestEvent(toolName, toolInput, permissionMode, permissionSuggestions);
265671
+ async firePermissionRequestEvent(toolName, toolInput, permissionMode, permissionSuggestions, signal) {
265672
+ const result = await this.hookEventHandler.firePermissionRequestEvent(toolName, toolInput, permissionMode, permissionSuggestions, signal);
265607
265673
  return result.finalOutput ? createHookOutput("PermissionRequest", result.finalOutput) : void 0;
265608
265674
  }
265609
265675
  };
@@ -265694,9 +265760,13 @@ var init_message_bus = __esm({
265694
265760
  * This enables synchronous-style communication over the async MessageBus
265695
265761
  * The correlation ID is generated internally and added to the request
265696
265762
  */
265697
- async request(request4, responseType, timeoutMs = 6e4) {
265763
+ async request(request4, responseType, timeoutMs = 6e4, signal) {
265698
265764
  const correlationId = randomUUID5();
265699
265765
  return new Promise((resolve35, reject) => {
265766
+ if (signal?.aborted) {
265767
+ reject(new Error("Request aborted"));
265768
+ return;
265769
+ }
265700
265770
  const timeoutId = setTimeout(() => {
265701
265771
  cleanup();
265702
265772
  reject(new Error(`Request timed out waiting for ${responseType}`));
@@ -265704,7 +265774,17 @@ var init_message_bus = __esm({
265704
265774
  const cleanup = /* @__PURE__ */ __name(() => {
265705
265775
  clearTimeout(timeoutId);
265706
265776
  this.unsubscribe(responseType, responseHandler);
265777
+ if (signal) {
265778
+ signal.removeEventListener("abort", abortHandler);
265779
+ }
265707
265780
  }, "cleanup");
265781
+ const abortHandler = /* @__PURE__ */ __name(() => {
265782
+ cleanup();
265783
+ reject(new Error("Request aborted"));
265784
+ }, "abortHandler");
265785
+ if (signal) {
265786
+ signal.addEventListener("abort", abortHandler);
265787
+ }
265708
265788
  const responseHandler = /* @__PURE__ */ __name((response) => {
265709
265789
  if ("correlationId" in response && response.correlationId === correlationId) {
265710
265790
  cleanup();
@@ -269236,36 +269316,46 @@ var init_config3 = __esm({
269236
269316
  });
269237
269317
  return;
269238
269318
  }
269319
+ if (request4.signal?.aborted) {
269320
+ this.messageBus?.publish({
269321
+ type: MessageBusType.HOOK_EXECUTION_RESPONSE,
269322
+ correlationId: request4.correlationId,
269323
+ success: false,
269324
+ error: new Error("Hook execution cancelled (aborted)")
269325
+ });
269326
+ return;
269327
+ }
269239
269328
  let result;
269240
269329
  const input = request4.input || {};
269330
+ const signal = request4.signal;
269241
269331
  switch (request4.eventName) {
269242
269332
  case "UserPromptSubmit":
269243
- result = await hookSystem.fireUserPromptSubmitEvent(input["prompt"] || "");
269333
+ result = await hookSystem.fireUserPromptSubmitEvent(input["prompt"] || "", signal);
269244
269334
  break;
269245
269335
  case "Stop":
269246
- result = await hookSystem.fireStopEvent(input["stop_hook_active"] || false, input["last_assistant_message"] || "");
269336
+ result = await hookSystem.fireStopEvent(input["stop_hook_active"] || false, input["last_assistant_message"] || "", signal);
269247
269337
  break;
269248
269338
  case "PreToolUse": {
269249
- result = await hookSystem.firePreToolUseEvent(input["tool_name"] || "", input["tool_input"] || {}, input["tool_use_id"] || "", input["permission_mode"] ?? PermissionMode.Default);
269339
+ result = await hookSystem.firePreToolUseEvent(input["tool_name"] || "", input["tool_input"] || {}, input["tool_use_id"] || "", input["permission_mode"] ?? PermissionMode.Default, signal);
269250
269340
  break;
269251
269341
  }
269252
269342
  case "PostToolUse":
269253
- result = await hookSystem.firePostToolUseEvent(input["tool_name"] || "", input["tool_input"] || {}, input["tool_response"] || {}, input["tool_use_id"] || "", input["permission_mode"] || "default");
269343
+ result = await hookSystem.firePostToolUseEvent(input["tool_name"] || "", input["tool_input"] || {}, input["tool_response"] || {}, input["tool_use_id"] || "", input["permission_mode"] || "default", signal);
269254
269344
  break;
269255
269345
  case "PostToolUseFailure":
269256
- result = await hookSystem.firePostToolUseFailureEvent(input["tool_use_id"] || "", input["tool_name"] || "", input["tool_input"] || {}, input["error"] || "", input["is_interrupt"], input["permission_mode"] || "default");
269346
+ result = await hookSystem.firePostToolUseFailureEvent(input["tool_use_id"] || "", input["tool_name"] || "", input["tool_input"] || {}, input["error"] || "", input["is_interrupt"], input["permission_mode"] || "default", signal);
269257
269347
  break;
269258
269348
  case "Notification":
269259
- result = await hookSystem.fireNotificationEvent(input["message"] || "", input["notification_type"] || "permission_prompt", input["title"] || void 0);
269349
+ result = await hookSystem.fireNotificationEvent(input["message"] || "", input["notification_type"] || "permission_prompt", input["title"] || void 0, signal);
269260
269350
  break;
269261
269351
  case "PermissionRequest":
269262
- result = await hookSystem.firePermissionRequestEvent(input["tool_name"] || "", input["tool_input"] || {}, input["permission_mode"] || PermissionMode.Default, input["permission_suggestions"] || void 0);
269352
+ result = await hookSystem.firePermissionRequestEvent(input["tool_name"] || "", input["tool_input"] || {}, input["permission_mode"] || PermissionMode.Default, input["permission_suggestions"] || void 0, signal);
269263
269353
  break;
269264
269354
  case "SubagentStart":
269265
- result = await hookSystem.fireSubagentStartEvent(input["agent_id"] || "", input["agent_type"] || "", input["permission_mode"] || PermissionMode.Default);
269355
+ result = await hookSystem.fireSubagentStartEvent(input["agent_id"] || "", input["agent_type"] || "", input["permission_mode"] || PermissionMode.Default, signal);
269266
269356
  break;
269267
269357
  case "SubagentStop":
269268
- result = await hookSystem.fireSubagentStopEvent(input["agent_id"] || "", input["agent_type"] || "", input["agent_transcript_path"] || "", input["last_assistant_message"] || "", input["stop_hook_active"] || false, input["permission_mode"] || PermissionMode.Default);
269358
+ result = await hookSystem.fireSubagentStopEvent(input["agent_id"] || "", input["agent_type"] || "", input["agent_transcript_path"] || "", input["last_assistant_message"] || "", input["stop_hook_active"] || false, input["permission_mode"] || PermissionMode.Default, signal);
269269
269359
  break;
269270
269360
  default:
269271
269361
  this.debugLogger.warn(`Unknown hook event: ${request4.eventName}`);
@@ -405793,7 +405883,7 @@ __name(getPackageJson, "getPackageJson");
405793
405883
  // packages/cli/src/utils/version.ts
405794
405884
  async function getCliVersion() {
405795
405885
  const pkgJson = await getPackageJson();
405796
- return "0.13.0-preview.4";
405886
+ return "0.13.0-preview.6";
405797
405887
  }
405798
405888
  __name(getCliVersion, "getCliVersion");
405799
405889
 
@@ -413423,7 +413513,7 @@ var formatDuration = /* @__PURE__ */ __name((milliseconds) => {
413423
413513
 
413424
413514
  // packages/cli/src/generated/git-commit.ts
413425
413515
  init_esbuild_shims();
413426
- var GIT_COMMIT_INFO = "49cf030d1";
413516
+ var GIT_COMMIT_INFO = "dc4760129";
413427
413517
 
413428
413518
  // packages/cli/src/utils/systemInfo.ts
413429
413519
  async function getNpmVersion() {
@@ -414441,7 +414531,8 @@ var clearCommand = {
414441
414531
  try {
414442
414532
  await config2.getHookSystem()?.fireSessionStartEvent(
414443
414533
  SessionStartSource.Clear,
414444
- config2.getModel() ?? ""
414534
+ config2.getModel() ?? "",
414535
+ String(config2.getApprovalMode())
414445
414536
  );
414446
414537
  } catch (err2) {
414447
414538
  config2.getDebugLogger().warn(`SessionStart hook failed: ${err2}`);
@@ -464004,7 +464095,8 @@ function useResumeCommand(options2) {
464004
464095
  try {
464005
464096
  await config2.getHookSystem()?.fireSessionStartEvent(
464006
464097
  SessionStartSource.Resume,
464007
- config2.getModel() ?? ""
464098
+ config2.getModel() ?? "",
464099
+ String(config2.getApprovalMode())
464008
464100
  );
464009
464101
  } catch (err2) {
464010
464102
  config2.getDebugLogger().warn(`SessionStart hook failed: ${err2}`);
@@ -471791,7 +471883,11 @@ var AppContainer = /* @__PURE__ */ __name((props) => {
471791
471883
  const sessionStartSource = resumedSessionData ? SessionStartSource.Resume : SessionStartSource.Startup;
471792
471884
  const hookSystem = config2.getHookSystem();
471793
471885
  if (hookSystem) {
471794
- hookSystem.fireSessionStartEvent(sessionStartSource, config2.getModel() ?? "").then(() => {
471886
+ hookSystem.fireSessionStartEvent(
471887
+ sessionStartSource,
471888
+ config2.getModel() ?? "",
471889
+ String(config2.getApprovalMode())
471890
+ ).then(() => {
471795
471891
  debugLogger145.debug("SessionStart event completed successfully");
471796
471892
  }).catch((err2) => {
471797
471893
  debugLogger145.warn(`SessionStart hook failed: ${err2}`);
@@ -476793,7 +476889,7 @@ var QwenAgent = class {
476793
476889
  async initialize(args2) {
476794
476890
  this.clientCapabilities = args2.clientCapabilities;
476795
476891
  const authMethods = buildAuthMethods();
476796
- const version2 = "0.13.0-preview.4";
476892
+ const version2 = "0.13.0-preview.6";
476797
476893
  return {
476798
476894
  protocolVersion: PROTOCOL_VERSION,
476799
476895
  agentInfo: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@qwen-code/qwen-code",
3
- "version": "0.13.0-preview.4",
3
+ "version": "0.13.0-preview.6",
4
4
  "description": "Qwen Code - AI-powered coding assistant",
5
5
  "repository": {
6
6
  "type": "git",
@@ -21,7 +21,7 @@
21
21
  "bundled"
22
22
  ],
23
23
  "config": {
24
- "sandboxImageUri": "ghcr.io/qwenlm/qwen-code:0.13.0-preview.4"
24
+ "sandboxImageUri": "ghcr.io/qwenlm/qwen-code:0.13.0-preview.6"
25
25
  },
26
26
  "dependencies": {},
27
27
  "optionalDependencies": {