diff --git a/docs/DEVELOPMENT.md b/docs/DEVELOPMENT.md index 3348147..e7a5771 100644 --- a/docs/DEVELOPMENT.md +++ b/docs/DEVELOPMENT.md @@ -260,7 +260,7 @@ rebuild threw; the consumed original is passed through as the last resort). Silent paths (no log line by design, request simply untouched): non-POST / non-target URLs, non-primary `event.kind` (title, compaction), -payloads with no usable tools, and everything after the 401 latch. If the +payloads with no usable tools, payloads whose single function tool is the only entry in `tools`, and everything after the 401 latch. If the log goes quiet mid-session, check for a latch line first. ### Verify trimming actually happened diff --git a/src/index.ts b/src/index.ts index 9552b2d..54b91c3 100644 --- a/src/index.ts +++ b/src/index.ts @@ -390,7 +390,13 @@ async function routePayload( payload: Record, ): Promise { const names = toolNames(payload.tools as unknown[]); - if (names.length === 0) return false; + // No usable candidate, or a lone candidate with nothing else in the payload: + // trimming can only reproduce the original tools array, so there is no + // decision for Jev and the round-trip would be pure added latency. + // (A built-in alongside the lone tool still counts — trimming drops it.) + if (names.length === 0 || (names.length === 1 && (payload.tools as unknown[]).length === 1)) { + return false; + } // Invalid key latched earlier: skip the round-trip, zero added latency. if (jevAuthFailed) return false; // A thrown round-trip (fetch network error, timeout abort, non-JSON body) diff --git a/test/index.test.ts b/test/index.test.ts index 6fcd468..b0e507c 100644 --- a/test/index.test.ts +++ b/test/index.test.ts @@ -503,3 +503,16 @@ test("19. body read fails (stream errors mid-read): original returned, no jev ca const logText = readFileSync(process.env.JEV_DEBUG_FILE!, "utf8"); assert.match(logText, /\[jev\] bypass: body read failed/); }); + +test("20. single function tool: passthrough, no fetch", async () => { + const { calls, holder } = await setupPlugin(); + assert.ok(holder.captured); + const payload = { + ...anthropicPayload(), + tools: [{ name: "read", input_schema: {} }], + }; + const event = jsonEvent(ANTHROPIC_URL, payload); + await holder.captured!(event); + assert.deepEqual(await bodyJson(event), payload); + assert.equal(calls.length, 0); // nothing for jev to decide, no round-trip +});