pi-mono/packages/coding-agent/src
robopipi[bot] b9e3eef6c2
fix(coding-agent): keep active tool order when the same tools are set again (#11514)
The system prompt lists tool snippets and per-tool guidelines in the
order of the active tools. When an extension called
`pi.setActiveTools()` with the same tools in a different order (for
example `[...pi.getActiveTools()].reverse()`), the "tools" and "rules"
sections came out different. pi then recorded a "System Prompt Update:
tools, rules" message even though the active tools had not changed. On
providers without mid-conversation system messages, this also rewrites
the prompt head and loses the cache.

`_applyToolLoadout` in `agent-session.ts` now treats the requested names
as a set:
- tools that stay active keep their current order;
- newly activated tools are appended at the end.

Reordering the same set therefore leaves the prompt unchanged. Adding a
tool only appends its bullet. The same rule covers tool lists changed by
`before_agent_start` handlers, since they go through the same function.

Testing:
- Added a test in `test/system-prompt-updates.test.ts`: it reverses the
active tools between two prompts and expects a single system message. It
fails without the change (a second message patches `tools` and `rules`)
and passes with it.
- `npm run check` passes.
- `./test.sh`: all coding-agent suites pass. The only failure is an
unrelated Anthropic model metadata test in `packages/ai`.

Fixes #11495

Requested by @badlogic

Co-authored-by: triagent <triagent@localhost>
2026-10-28 10:09:41 +01:00
..
bun feat(coding-agent): codemode and MCP 2026-09-29 09:12:50 +02:00
cli docs: fix provider checklist, MCP anchors, and missing commands/settings (#11338) 2026-10-23 17:02:41 +02:00
core fix(coding-agent): keep active tool order when the same tools are set again (#11514) 2026-10-28 10:09:41 +01:00
experimental feat(coding-agent): remove the experimental server stack and the client, protocol, and server packages 2026-10-12 10:41:59 +00:00
extensions fix(coding-agent): summarize union and multi-line codemode output types in tool descriptions (#11513) 2026-10-28 09:58:20 +01:00
modes fix(coding-agent): show model scope in the fullscreen header instead of the shell (#11512) 2026-10-28 09:54:06 +01:00
utils fix(coding-agent): skip fd/rg downloads on unsupported architectures 2026-10-23 19:48:59 +02:00
cli.ts fix(coding-agent): keep remote harness dependencies development-only 2026-09-05 12:45:04 +02:00
config.ts fix(coding-agent): keep codemode working after the install is updated or removed 2026-10-04 22:49:20 +02:00
index.ts fix(coding-agent): start when a configured package fails to install (#11304) 2026-10-23 12:27:45 +02:00
main.ts fix(coding-agent): report a deleted working directory instead of crashing on startup (#11511) 2026-10-28 09:51:39 +01:00
migrations.ts fix(coding-agent): update repository links to "earendil-works/pi" (#9278) 2026-09-07 14:09:39 +02:00
package-manager-cli.ts fix(coding-agent): start when a configured package fails to install (#11304) 2026-10-23 12:27:45 +02:00
rpc-entry.ts feat(coding-agent): set AI_AGENT environment variable (#7493) 2026-08-03 13:45:32 +02:00