From 268810d19482b2327f57709edad9a4dba4aaea0f Mon Sep 17 00:00:00 2001 From: Patrick Ribbsaeter Date: Mon, 20 Jul 2026 09:55:24 +0200 Subject: [PATCH] fix: disable tools for generation-only queries (#26) Co-authored-by: Patrick <233187023+patrickswedish@users.noreply.github.com> --- package.json | 1 + src/llm.ts | 21 ++++++++++++++------- tests/llm.test.ts | 16 ++++++++++++++++ 3 files changed, 31 insertions(+), 7 deletions(-) create mode 100644 tests/llm.test.ts diff --git a/package.json b/package.json index 1844b80..d695fbe 100644 --- a/package.json +++ b/package.json @@ -17,6 +17,7 @@ ], "scripts": { "build": "tsc", + "test": "node --import tsx --test tests/*.test.ts", "typecheck": "tsc --noEmit && tsc --noEmit -p tsconfig.bench.json", "prepublishOnly": "npm run build", "dev": "tsx src/cli.ts", diff --git a/src/llm.ts b/src/llm.ts index 27c9289..6a277b3 100644 --- a/src/llm.ts +++ b/src/llm.ts @@ -14,18 +14,25 @@ export type LLMOptions = { userPrompt: string; }; +export function buildQueryOptions(opts: LLMOptions) { + return { + model: opts.model, + systemPrompt: { + type: "preset" as const, + preset: "claude_code" as const, + append: opts.systemPrompt, + }, + // No tools — divergence is pure generation. Tools = convergence pressure. + tools: [] as string[], + }; +} + export async function callLLM(opts: LLMOptions): Promise { const chunks: string[] = []; const iter = query({ prompt: opts.userPrompt, - options: { - model: opts.model, - systemPrompt: { type: "preset", preset: "claude_code", append: opts.systemPrompt }, - // No tools — divergence is pure generation. Tools = convergence pressure. - allowedTools: [], - permissionMode: "bypassPermissions", - }, + options: buildQueryOptions(opts), }); for await (const message of iter) { diff --git a/tests/llm.test.ts b/tests/llm.test.ts new file mode 100644 index 0000000..8f52311 --- /dev/null +++ b/tests/llm.test.ts @@ -0,0 +1,16 @@ +import assert from "node:assert/strict"; +import test from "node:test"; + +import { buildQueryOptions } from "../src/llm.ts"; + +test("generation-only queries disable all built-in tools", () => { + const options = buildQueryOptions({ + model: "claude-sonnet-4-5", + systemPrompt: "Think divergently.", + userPrompt: "Generate ideas.", + }); + + assert.deepEqual(options.tools, []); + assert.equal("allowedTools" in options, false); + assert.equal("permissionMode" in options, false); +}); -- 2.55.0.windows.3