Commit Graph
5 Commits
Author SHA1 Message Date
webkubor 2598c5355a fovea 0.2.5: Gemini support, harness blocks are not the user's words, legacy function role (#763)
Gemini requests (`contents`) are now thinned: thought parts, parts carrying a
thoughtSignature and functionCall parts stay as sent; a functionResponse keeps
its id, name and keys while the long strings inside it are cut; old images
become a note; document and video inlineData stay. saccade "auto" strips
<system-reminder> blocks before judging the topic, and a user message that is
only harness blocks is not the newest question. leadingUserEnd counts
custom_tool_call / computer_call / local_shell_call (and outputs) as answers.
Chat's legacy role "function" messages are thinned like role "tool".
page/measure.js carries the same change (diff of the two files is only the
export line).

What was run at 38385b82 (merged onto main 15f4fa80), on mote (macOS, Bun 1.4.2):
- bun test packages/fovea: 57 pass, 0 fail; bun scripts/check.mjs fovea: ok.
- fovea main vs 0.2.5 through magpie's own moejs middleware runner
  (internal/middleware Begin/Request, a throwaway test, not committed):
  - Gemini body, 41 turns, 849,212 -> 360,846 bytes (main: unchanged).
    Every thought part, thoughtSignature text part and functionCall is
    byte-identical; functionResponse ids/names kept, nested strings cut;
    image/png -> note, application/pdf untouched; the task turn and the
    recent window unchanged; no middleware failures.
  - Gemini, 401 turns, 8.5 MB, default options: 3.4 ms in onRequest
    (limit 250 ms).
  - Claude Code shape with <system-reminder> on every tool_result turn,
    saccade auto: a follow-up collapses nothing (main and 0.2.5); a real
    topic change with a reminder attached collapses 57 old items on 0.2.5,
    none on main.
  - Chat role "function": 81,491 -> 25,035 bytes (main: unchanged).
  - Responses whose first answer is custom_tool_call: 81,736 -> 25,240
    (main: unchanged).
- No new network access or I/O in the diff.

Not tried: a real Gemini account through a live gateway.
2026-11-05 21:27:14 +08:00
yetone 549e41d89e fovea 0.2.4: a state marker counts only at the head of an assistant's text (#756)
state_marker was found by its text anywhere: any item's string content
or any part's text. A Chat tool result or a user message that read a
file or log containing the marker stayed whole on every turn, and lifted
the task message's protection. carriesState now takes the marker only
where the agent writes its state block: an assistant message (Chat,
Anthropic, or a Responses message item) whose string content, or a
text/output_text part, starts with the marker. Tool results, user text,
nested tool_result parts, function_call_output and a marker in the
middle of a text count for nothing. page/measure.js rebuilt (build.mjs's
transform), README option row and CHANGELOG updated. Ships the 8e4105dd
docs fix too.

Run on mote (Bun 1.4.2, temp HOME), at bf959aa60e plus this change:
- bun test packages/fovea: 45 pass, 0 fail (10 new tests).
- bun test (whole repo): 5932 pass, 19 skip, 0 fail. bun scripts/check.mjs ok.
- Old code (origin/main's middleware) with the new tests: 6 fail -
  Chat tool result (string and text part), user string, user text block,
  mid-text assistant, Responses user input_text. The Anthropic
  tool_result (string, nested part) and function_call_output cases pass
  on the old code too: it read only top-level content/text, so those
  were not forgeable; the tests keep them that way.
- Broken by hand: role/type check removed, 4 fail; startsWith replaced
  by includes, 1 fail (mid-text).

Not tried: a live gateway request, magpie's moejs run of cases.json.
Users who put the marker somewhere other than the start of an assistant
text lose the exemption; fovea is not on npm and the option is off by
default.
2026-11-05 15:23:47 +08:00
yetone 8e4105dd3d fovea: docs say a cut result is kept by the length guard, not the marker
#755 removed cut()'s "[fovea:" sniff, but the file header (and its copy
in page/measure.js) and the README still said content carrying the
marker is left alone, and the README still counted 31 tests. Comment
and README only; no code or version change.

Run on mote (Bun 1.4.2, temp HOME): bun test packages/fovea, 35 pass,
0 fail, including the measure.js freshness test.
2026-11-05 15:13:35 +08:00
Howie 1e9f14248e fovea 0.2.3: a forged marker no longer exempts old content from cutting (#755)
cut() skipped any text containing "[fovea:" as already cut. That string
can come from a tool result, a file read or a user message, so such a
block stayed whole forever. The sniff is removed; the existing
head + tail + 80 length guard keeps a cut result from being cut again,
since the marker adds at most 44 chars plus the count's digits.
cut() is the one place the cut marker was read, and every route goes through
it: Chat role:"tool" (string and text parts), Anthropic tool_result
(string and nested text parts) and text blocks, Responses
function_call_output / custom_tool_call_output and message parts, and
user/assistant text. Saccade mode compares against the exact NOTE line
only, so it was not affected.

Reviewed head c41cae5cb43770158173369f18acda4e572fdc9e (evanmaranzano),
run on mote (Bun 1.4.2, HOME a temp dir):
- bun test packages/fovea: 35 pass, 0 fail, 128 expects.
- bun scripts/check.mjs: ok.
- A review-only property check, 12000 requests over Chat, Anthropic and
  Responses shapes (string and nested-part tool results, text blocks),
  random head/tail options and lengths, a forged "[fovea: ...]" at a
  random offset, emoji at the end: 0 second-pass differences, 0 forged
  blocks over the bound left whole.
- Broken by hand: putting the includes("[fovea:") line back in
  fovea.middleware.js and page/measure.js turns the new case and the new
  test red (33 pass, 2 fail) and the property check reports 38492
  forged blocks left whole.

Not changed here: state_marker (opt-in, default "") is still found in any
item's text, a Chat tool result's included: #756. Not tried:
magpie's moejs run of cases.json, and a live gateway request.
2026-11-05 15:12:57 +08:00
webkubor d4eeba4493 fovea 0.2.2: a new middleware, old history to head and tail on a cache-stable boundary (webkubor, #640)
A new gateway middleware, @magpie-community/middleware-fovea 0.2.2 (webkubor, #640): old tool output and text in a long history are cut to head and tail, with the boundary only on multiples of `cut_step` (24) so the cut prefix stays byte-identical between turns and the prompt cache holds. The leading user items before the first answer (Codex's AGENTS.md, environment_context and the task; Claude Code's first message) stay whole. `saccade` ("off" by default) drops the old context on a new topic, judged against that same task. Old images become a text note that keeps their `cache_control`. Ships an evidence page (Plugins > Fovea evidence) that computes a paste-in A/B in the frame, with no network.

What was run, at the reviewed head b9883cf206814fdc01950a00d413a36856de4e11, on mote (macOS, Bun 1.4.2, sandbox HOME):
- `bun test packages/fovea`: 33 pass, 0 fail. The two new Codex saccade cases fail with 0357f1c's middleware (and pass at the head).
- `bun scripts/check.mjs fovea` and `bun scripts/check.mjs`: pass. `page/measure.js` is byte-identical to a fresh `bun build.mjs`.
- `npm pack --dry-run`: 18 files, 131.8 kB unpacked; no brand/, no live-benchmark.mjs.
- The head merged onto origin/main 82b254f2 (registry.json auto-merged): `bun scripts/check.mjs` passes and `HOME=$(mktemp -d) bun test` (the whole repo, as pr.yml runs it): 5477 pass, 0 fail.
- A probe calling onRequest turn after turn. Codex-shaped Responses (instructions, developer permissions item, AGENTS.md, environment_context, the task as input_text, then reasoning with encrypted_content, function_call and function_call_output, 60 turns) and Claude Code-shaped Messages (system with cache_control, a first message with system-reminder, task and an image with cache_control, then thinking + signature, text, tool_use and a 6400-char tool_result with emoji, 70 turns). `instructions`, `system`, `tools`, every reasoning, function_call and assistant item, ids, counts and the cache_control count are unchanged; the four leading Codex items reach upstream byte-identical; no lone surrogate. The shared prefix breaks once per cut_step (Codex 6 of 60 turns, Messages 5 of 70; 0 without fovea), with `saccade: "auto"` too. With auto, a same-task follow-up on Codex ("scheduler retry timing assertion still fails in internal/sched, fix it") and on Messages collapses nothing; a new topic collapses from that turn on (one extra prefix break). Bodies went 16.1 MB to 9.4 MB (Codex) and 26.1 MB to 13.9 MB (Messages) over the run.
- Text the middleware adds upstream is only `[fovea: N chars of old tool output omitted]` and `[fovea: prior topic not carried]`: neither names magpie, a vendor or a limit. Codex's instructions are never touched.

Not tried: a live vendor request with real cache-hit numbers (the evidence is the byte-level prefix). pr.yml's runs were waiting on approval for a first-time contributor, so the CI record is the merged-tree run above. A new topic that shares a common word such as "the" with the task stays below the 0.08 overlap bar only when it has enough words; with saccade off by default that is a tuning note, not a blocker. @magpie-community/middleware-fovea is new to npm, so its first version needs an owner (trusted publishing can't create a package); magpie serves it from the dist branch meanwhile.
2026-11-04 16:56:37 +08:00