history-trim 0.1.2. The whitespace step trimmed trailing spaces with /[ \t]+$/gm, which takes quadratic time on a long run of spaces followed by a word: 1.2 s at 40,000 spaces on Node 22. A one-pass scan replaces it. It runs after the blank-line fold, as before, and trims before every line end that `$` sees under /m (\n, \r, U+2028, U+2029 and the end of the text). The output is the same as main's. Four cases.json regressions are added: CRLF, whitespace-only lines, U+2028, and a long run of spaces before a word. What was run at 0ad27d87, merged with origin/main: - `bun test packages/history-trim` (27 pass) and `bun scripts/check.mjs` (ok), on WSL Ubuntu 24.04 and on Windows 11, each with a fresh HOME (and USERPROFILE on Windows). - main's onRequest against the PR's, on 500,000 random strings over space, tab, \n, \r, U+2028, U+2029, U+0085, \v, \f, U+00A0, U+3000, U+FEFF, U+2000 and U+200A: 0 differ, on Node 22 and Bun. - Timing at 40,000 spaces + "a": main 1,223 ms, PR 0.28 ms; 1,000,000 spaces: 7 ms (Node 22, mote). - Broken by hand: treating only LF as a line end turns the CRLF and U+2028 cases red. Trimming before the fold turns the whitespace-only-lines case red.
18 lines
879 B
JSON
18 lines
879 B
JSON
{
|
|
"name": "@magpie-community/middleware-history-trim",
|
|
"version": "0.1.2",
|
|
"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"],
|
|
"keywords": ["magpie", "magpie-middleware", "compression", "context", "history", "tokens", "llm-gateway"],
|
|
"license": "MIT",
|
|
"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,
|
|
"compressToolResults": true,
|
|
"preserveSystemPrompt": false
|
|
}
|
|
}
|
|
} |