diff --git a/docs/DEVELOPMENT.md b/docs/DEVELOPMENT.md index ae8be45..3b81901 100644 --- a/docs/DEVELOPMENT.md +++ b/docs/DEVELOPMENT.md @@ -244,10 +244,12 @@ grep -c 'bypass:' /tmp/opencode-jev.log # requests handed to the LLM untouched | `bypass: jev choice X listed but missing from payload — ...` | Name passed the criteria list but matched no payload entry (format mismatch edge case). | Full tool list. | | `bypass: jev unavailable (see preceding 'jev ...' error line) — ...` | The round-trip failed; the **preceding** error line names why. | Full tool list. | -Error/context lines that precede a `bypass: jev unavailable`: +Error/context lines that precede a `bypass: jev unavailable`, plus the +`note:` line (which can precede **any** tagged line, `apply:` included): | Line | Meaning | | --- | --- | +| `note: N tools exceed criteria cap 254 — first 254 offered to jev` | Payload has more than 254 function tools; the excess is invisible to Jev's choice (a pick among the kept tools still trims correctly). Operator awareness only — behavior unchanged. | | `jev http 500` (or any non-401/403 status) | Transient provider failure — plugin keeps trying next request. | | `jev http 401 (invalid key, routing disabled)` | **Latched off.** Auth failed; all later requests bypass silently with zero jev round-trips and **no further log lines**. Fix the key and restart OpenCode. | | `jev answer malformed` | Jev's JSON didn't parse into `{choice, confidence}`. | diff --git a/src/index.ts b/src/index.ts index b97f5fc..18886e0 100644 --- a/src/index.ts +++ b/src/index.ts @@ -339,6 +339,10 @@ async function askJev( state: string, names: string[], ): Promise { + if (names.length > MAX_CRITERIA - 1) + log( + `note: ${names.length} tools exceed criteria cap ${MAX_CRITERIA - 1} — first ${MAX_CRITERIA - 1} offered to jev`, + ); const criteria: Record = { respond_to_user: "Task is complete, or clarification from user is required", }; diff --git a/test/index.test.ts b/test/index.test.ts index d46b888..b51621f 100644 --- a/test/index.test.ts +++ b/test/index.test.ts @@ -564,3 +564,26 @@ test("22. bogus config timeoutMs (0 / non-numeric): default used, routes normall assert.equal(calls.length, 1); } }); + +test("23. 260 tools: criteria truncated to first 254 + note logged, trim still applies", async () => { + const { calls, holder } = await setupPlugin(undefined, () => + jevResponse(choice("tool_0", 0.99)), + ); + assert.ok(holder.captured); + const payload = anthropicPayload(); + payload.tools = Array.from({ length: 260 }, (_, i) => ({ + name: `tool_${i}`, + input_schema: {}, + })); + const event = jsonEvent(ANTHROPIC_URL, payload); + await holder.captured!(event); + const jevBody = JSON.parse(calls[0].init.body); + const criteria = jevBody.questions.next_tool.criteria; + // 254 kept tools + the reserved respond_to_user slot; tool_254..259 invisible. + assert.equal(Object.keys(criteria).length, 255); // MAX_CRITERIA: 254 tools + respond_to_user + assert.ok("tool_253" in criteria); + assert.ok(!("tool_254" in criteria)); + const logText = readFileSync(process.env.JEV_DEBUG_FILE!, "utf8"); + assert.match(logText, /\[jev\] note: 260 tools exceed criteria cap 254/); + assert.match(logText, /\[jev\] apply: tools trimmed to tool_0/); +});