qwen-code/packages
zhangxy-zju b842f27c99
fix(cli): inject plan/subagent/arena system reminders in ACP (#1151) (#3479)
* fix(cli): inject plan/subagent/arena system reminders in ACP (#1151)

The ACP Session sends user messages via chat.sendMessageStream() directly,
bypassing GeminiClient.sendMessageStream() where the CLI/TUI path injects
its per-turn system reminders. As a result:

- Plan mode is silently inert in ACP: the model never sees the reminder
  that tells it to avoid edits and call exit_plan_mode, so it tries to
  run edit tools and triggers the plan-mode block-check only as a fallback.
- User-level subagents registered in the workspace are invisible to the
  model for the same reason.
- Arena sessions started via the ACP path lose their session-dir context.

Mirror the subagent / plan / arena branches from client.ts:848-878 in a
new private helper #buildInitialSystemReminders, and prepend its output
to the initial user-query message in #executePrompt as well as the cron
path in #executeCronPrompt. The helper intentionally skips the managed
auto-memory reminder — that one needs the GeminiClient prefetch pipeline
and will be tackled as part of broader middleware alignment.

Tests cover plan-mode on/off and non-builtin subagent filtering on the
first-turn message fed into chat.sendMessageStream.

* test(acp): add ensureTool + getSubagentManager to default mockConfig

The system-reminder fix added an unconditional
`config.getToolRegistry().ensureTool(ToolNames.AGENT)` call inside
`#buildInitialSystemReminders`, which now runs on every
`session.prompt()` and every cron fire. The new system-reminder tests
stub `ensureTool` via their own `stubEmptySubagents` helper, but the
default `mockToolRegistry` at the top of the file still only carries
`getTool`. As a result all 13 pre-existing tests that exercise
`session.prompt()` blow up with
`TypeError: this.config.getToolRegistry(...).ensureTool is not a function`,
and the cascaded `StopFailure` assertion fails because the test never
reaches the assertion point.

Move both `ensureTool` (on the tool registry) and `getSubagentManager`
(on the config) into the default beforeEach mocks so every test that
calls `session.prompt()` can traverse `#buildInitialSystemReminders`
without the caller having to know about it. Defaulting
`listSubagents` to an empty array is the harmless zero case — tests
that care about subagent reminders already override it.

The existing `stubEmptySubagents` helper still works unchanged (its
explicit overrides take precedence over the defaults), so the new
system-reminder tests in this PR keep expressing intent locally.

* test(acp): update afterEach cast to match new mockToolRegistry type

The previous commit added `ensureTool` to the `mockToolRegistry`
declaration but left the `afterEach` reset casting to the old
`{ getTool: ReturnType<typeof vi.fn> }` shape, which TS 5 now rejects
under strict mode:

  error TS2741: Property 'ensureTool' is missing in type
  '{ getTool: Mock<Procedure>; }' but required in type
  '{ getTool: Mock<Procedure>; ensureTool: Mock<Procedure>; }'.

Use `typeof mockToolRegistry` so the cast tracks the declaration
automatically and future additions don't need a second edit.

* test(acp): add getApprovalMode to default mockConfig

The previous commits wired `#buildInitialSystemReminders` into every
`session.prompt()` entry, which also reads `this.config.getApprovalMode()`
to decide whether to prepend the plan-mode reminder. The default
`mockConfig` never provided `getApprovalMode`, so the five pre-existing
prompt-level tests that don't set it locally (passes resolved paths,
runtime output dir context, UserPromptSubmit/Stop/StopFailure hooks)
crash with `TypeError: this.config.getApprovalMode is not a function`
on every platform + node version.

Default to `ApprovalMode.DEFAULT` so tests that don't care about
approval mode still traverse the helper. The ~10 tests that exercise
plan/yolo/auto-edit already reassign `mockConfig.getApprovalMode`
locally, and the reassignment wins over the default.
2026-04-22 14:46:33 +08:00
..
channels fix(weixin): check full 4-byte PNG magic signature (#2970) 2026-04-18 09:32:58 +08:00
cli fix(cli): inject plan/subagent/arena system reminders in ACP (#1151) (#3479) 2026-04-22 14:46:33 +08:00
core feat(session): add rename, delete, and auto-title generation for session (#3093) 2026-04-22 11:48:01 +08:00
sdk-java Fix typo in class name (#2189) 2026-04-18 11:59:36 +08:00
sdk-typescript fix(sdk): settle pending next() promise in Stream.return() to prevent hangs (#2981) 2026-04-18 09:46:56 +08:00
vscode-ide-companion feat(cli): cap inline shell output with configurable line limit (#3508) 2026-04-22 14:37:13 +08:00
web-templates fix: display (#2766) 2026-04-19 15:25:29 +08:00
webui feat(session): add rename, delete, and auto-title generation for session (#3093) 2026-04-22 11:48:01 +08:00
zed-extension chore(zed-extension): update package version to 0.10.0 2026-02-06 14:26:01 +08:00