From 6433e4d32a5db33a52984936efde2cb90cf759d0 Mon Sep 17 00:00:00 2001 From: bchanot Date: Fri, 13 Nov 2026 17:27:25 +0100 Subject: [PATCH] fix(mods): type narrowings for plugin validate --strict (BLK-049) Claude Code 2.1.323 type-checks mods in validate --strict: three TS2339 in the memory kit, the Bash hook return type, thirteen sites in the model-router kit and the agent.spawn deny arm. Type-only or behaviour-equivalent changes; kits 288/640 unchanged; guards stay fail-open (BDR-136). --- mods/memory/hooks/register.test.ts | 6 +++--- mods/memory/hooks/register.ts | 7 +++++-- mods/model-router/hooks/register.test.ts | 19 ++++++++++++++----- mods/model-router/hooks/register.ts | 4 +++- 4 files changed, 25 insertions(+), 11 deletions(-) diff --git a/mods/memory/hooks/register.test.ts b/mods/memory/hooks/register.test.ts index 9486647..44dd41e 100644 --- a/mods/memory/hooks/register.test.ts +++ b/mods/memory/hooks/register.test.ts @@ -186,7 +186,7 @@ async function boot($: Engine, on: On, o: Opts = {}): Promise { } w.runs.push([...e.argv]) if (w.proc === 'throw') throw new Error('spawn failed') - if (w.proc === 'hang') await new Promise(() => undefined) + if (w.proc === 'hang') return await new Promise(() => undefined) const done = w.proc === 'exit2' ? { exitCode: 2, stdout: '' } : { exitCode: 0, stdout: w.proc.stdout } return { value: { ...done, stderr: '', isStdoutTruncated: false, @@ -197,7 +197,7 @@ async function boot($: Engine, on: On, o: Opts = {}): Promise { w.asks.push({ model: x.model, prompt: x.prompt, effort: x.effort, maxTokens: x.maxTokens, timeoutMs: x.timeoutMs }) if (w.model === 'throw') throw new Error('api down') - if (w.model === 'hang') await new Promise(() => undefined) + if (w.model === 'hang') return await new Promise(() => undefined) const usage = { input_tokens: 0, output_tokens: 0 } const done = w.model === 'unanswered' ? { isAnswered: false, reason: 'api-error', status: 500, @@ -2802,7 +2802,7 @@ const fakeApi = (w: World): Api => ({ w.asks.push(a) return { isAnswered: true, text: (w.model as { text: string }).text } } }, - store: storeApi(w).store, + store: (storeApi(w) as unknown as { store: unknown }).store, ui: { log: () => undefined }, }) as unknown as Api diff --git a/mods/memory/hooks/register.ts b/mods/memory/hooks/register.ts index 9972068..49c1caa 100644 --- a/mods/memory/hooks/register.ts +++ b/mods/memory/hooks/register.ts @@ -5,7 +5,9 @@ // through unchanged: the mod may never break a tool call or a prompt. // It also recalls: registry entries on a qualifying prompt and a known-error // line on a Bash failure, both switchable with "recall": false. -import type { EngineInterface, On, Register } from 'claude-code' +import type { + EngineInterface, On, Register, ToolCallResult, +} from 'claude-code' type Api = EngineInterface @@ -1586,7 +1588,8 @@ function registerBash(on: On, st: State): void { await captureMilestones($, st, at, e, out as BashOut) const line = await knownContext($, st, at, e, f) if (line === '') return out - return { ...out, context: [...(out.context ?? []), line] } + return { ...out, context: [...(out.context ?? []), line] } as + ToolCallResult<'Bash'> }).catch(($, e, next) => { warnOnce(st, $, 'Bash', next.error.kind) return next(e) diff --git a/mods/model-router/hooks/register.test.ts b/mods/model-router/hooks/register.test.ts index 7a7e560..ccd6c9f 100644 --- a/mods/model-router/hooks/register.test.ts +++ b/mods/model-router/hooks/register.test.ts @@ -8,6 +8,12 @@ const SONNET = 'claude-sonnet-5-5' const HAIKU = 'claude-haiku-5-5' type Rec = Record + +// the kit's type lib has neither the timers nor ES2024 strings: types only +declare function setTimeout(fn: (...a: never[]) => void, ms: number): unknown +declare global { + interface String { isWellFormed(): boolean } +} type Asked = { text: string; options: string[]; header: string } const HOME = '/home/t' @@ -309,7 +315,7 @@ async function boot( // the probe of the model main runs on: every model answers unless a test says not on('model.complete', async (_$, e) => { world.completions.push(e.model) - return { value: (await world.complete(e.model)) as string } + return { value: (await world.complete(e.model)) as string } as never }) installWorld(on, world) if (tokens !== null) usageOf(on, tokens) @@ -1198,6 +1204,7 @@ function recordLogs(on: On): string[] { } catch { // nothing implements ui.log below the recorder in the kit } + return undefined as never }) return lines } @@ -1380,7 +1387,7 @@ async function effortAfterSkill($: Engine, on: On, skill: string) { await $.agent.spawn(spawnOf('feater')) await loadSkill($, skill, 'a1') await runStep($, { ...highStep('a1'), model: SONNET }) - return rig.seen[rig.seen.length - 1].effort + return rig.seen[rig.seen.length - 1]!.effort } test('agent skill: an unrowed one leaves the loop effort', async ($, on) => { @@ -1595,7 +1602,7 @@ const queued = ($: Engine, kind: string, text: string) => $.prompt.submit({ text, wait: true, - origin: { kind }, + origin: { kind } as never, turnId: 'u1', }) @@ -1614,7 +1621,7 @@ test('idle fallback: a mid-turn composer prompt promotes the allowance', async ( await $.prompt.submit({ text: 'hello', wait: false, - origin: { kind: 'channel' }, + origin: { kind: 'channel' } as never, }) await queued($, 'composer', 'hello') await endTurn($) @@ -1644,6 +1651,7 @@ function recordToasts(on: On): string[] { } catch { // nothing implements ui.toast below the recorder in the kit } + return undefined as never }) return lines } @@ -4595,7 +4603,7 @@ const skillWorld = (): World => newWorld({ edit: f => { /** The name a line shows after `marker`, up to the closing char. */ const nameAfter = (line: string, marker: string, end: string): string => - line.slice(line.indexOf(marker) + marker.length).split(end)[0] + line.slice(line.indexOf(marker) + marker.length).split(end)[0]! test('logs: a hostile skill name is cleaned in the main line', async ( $, on) => { @@ -4668,6 +4676,7 @@ function recordStatus(on: On): string[] { } catch { // nothing implements ui.status below the recorder in the kit } + return undefined as never }) return lines } diff --git a/mods/model-router/hooks/register.ts b/mods/model-router/hooks/register.ts index 448b13e..51869f9 100644 --- a/mods/model-router/hooks/register.ts +++ b/mods/model-router/hooks/register.ts @@ -4656,7 +4656,9 @@ function registerSpawn(on: On, st: State): void { const started = await next(wanted === undefined ? e : { ...e, model: wanted }) - afterSpawn($, st, { e, started, route, wanted }) + if (started.deny === undefined) { + afterSpawn($, st, { e, started, route, wanted }) + } return started } finally { st.spawning = Math.max(0, st.spawning - 1)