From ebdd4fd24722966607d64ededbbf8b491b899638 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=C3=B1j=C5=AB=E1=B9=A3aka?= <153098568+manjughosa@users.noreply.github.com> Date: Wed, 4 Nov 2026 19:08:41 +0800 Subject: [PATCH] history-trim 0.1.1: declare compressToolResults and preserveSystemPrompt, two regression cases (manjughosa, #681) Declares history-trim's existing compressToolResults (true) and preserveSystemPrompt (false) options in the package manifest, matching what history-trim.middleware.js does when they are absent, and adds two regression cases: a long surrogate-only tool result in the turn being sent stays whole, and a repeated message is dropped even when its keys are in a different order. No middleware runtime change. Version 0.1.0 -> 0.1.1 so the new manifest is packed onto dist. Run at the reviewed head 06c179d (and merged onto main d9a6c45), on mote: - bun test packages/history-trim: 23 pass, 0 fail - bun scripts/check.mjs: exit 0; bun test scripts/: 0 fail Broken by hand: turning off the `index >= currentTurnStart` guard in cutToolResults fails the new surrogate case (and "the turn being sent is never cut"); dropping .sort() in canonical() fails the key-order case. Not tried: a real request through a magpie gateway with the middleware on. --- packages/history-trim/cases.json | 56 ++++++++++++++++++++++++++++++ packages/history-trim/package.json | 8 +++-- 2 files changed, 62 insertions(+), 2 deletions(-) diff --git a/packages/history-trim/cases.json b/packages/history-trim/cases.json index 1b80762..2d1ac5e 100644 --- a/packages/history-trim/cases.json +++ b/packages/history-trim/cases.json @@ -778,5 +778,61 @@ } ] } + }, + { + "name": "a long surrogate-only tool result in the turn being sent stays whole", + "options": { + "maxToolLength": 256 + }, + "request": { + "model": "m", + "messages": [ + { + "role": "user", + "content": "go" + }, + { + "role": "assistant", + "content": "reading" + }, + { + "role": "tool", + "content": "😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀" + } + ] + } + }, + { + "name": "a repeated message goes even when its keys are ordered differently", + "request": { + "model": "m", + "messages": [ + { + "role": "user", + "content": "same" + }, + { + "content": "same", + "role": "user" + }, + { + "role": "assistant", + "content": "ok" + } + ] + }, + "expect_request": { + "model": "m", + "messages": [ + { + "role": "user", + "content": "same" + }, + { + "role": "assistant", + "content": "ok" + } + ] + } } ] diff --git a/packages/history-trim/package.json b/packages/history-trim/package.json index 7a67da4..5ae0c22 100644 --- a/packages/history-trim/package.json +++ b/packages/history-trim/package.json @@ -1,6 +1,6 @@ { "name": "@magpie-community/middleware-history-trim", - "version": "0.1.0", + "version": "0.1.1", "description": "Send a request's history smaller: blank-line runs folded, a system prompt written twice and a message repeated right after itself dropped, a past tool result longer than maxToolLength cut, as magpie gateway middleware", "type": "module", "files": ["history-trim.middleware.js", "README.md", "LICENSE", "PROVENANCE.json"], @@ -9,6 +9,10 @@ "repository": { "type": "git", "url": "git+https://github.com/magpie-community/plugins.git", "directory": "packages/history-trim" }, "magpie": { "middleware": "./history-trim.middleware.js", - "options": { "maxToolLength": 2000 } + "options": { + "maxToolLength": 2000, + "compressToolResults": true, + "preserveSystemPrompt": false + } } } \ No newline at end of file