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).
This commit is contained in:
bchanot committed 2026-11-13 17:27:25 +01:00
1 parent 9ee3fdad23
commit 6433e4d32a
4 files changed
+25 -11

No files matched your search

+3 -3
View File
@@ -186,7 +186,7 @@ async function boot($: Engine, on: On, o: Opts = {}): Promise<World> {
} }
w.runs.push([...e.argv]) w.runs.push([...e.argv])
if (w.proc === 'throw') throw new Error('spawn failed') 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<never>(() => undefined)
const done = w.proc === 'exit2' const done = w.proc === 'exit2'
? { exitCode: 2, stdout: '' } : { exitCode: 0, stdout: w.proc.stdout } ? { exitCode: 2, stdout: '' } : { exitCode: 0, stdout: w.proc.stdout }
return { value: { ...done, stderr: '', isStdoutTruncated: false, return { value: { ...done, stderr: '', isStdoutTruncated: false,
@@ -197,7 +197,7 @@ async function boot($: Engine, on: On, o: Opts = {}): Promise<World> {
w.asks.push({ model: x.model, prompt: x.prompt, effort: x.effort, w.asks.push({ model: x.model, prompt: x.prompt, effort: x.effort,
maxTokens: x.maxTokens, timeoutMs: x.timeoutMs }) maxTokens: x.maxTokens, timeoutMs: x.timeoutMs })
if (w.model === 'throw') throw new Error('api down') 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<never>(() => undefined)
const usage = { input_tokens: 0, output_tokens: 0 } const usage = { input_tokens: 0, output_tokens: 0 }
const done = w.model === 'unanswered' const done = w.model === 'unanswered'
? { isAnswered: false, reason: 'api-error', status: 500, ? { isAnswered: false, reason: 'api-error', status: 500,
@@ -2802,7 +2802,7 @@ const fakeApi = (w: World): Api => ({
w.asks.push(a) w.asks.push(a)
return { isAnswered: true, text: (w.model as { text: string }).text } 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 }, ui: { log: () => undefined },
}) as unknown as Api }) as unknown as Api
+5 -2
View File
@@ -5,7 +5,9 @@
// through unchanged: the mod may never break a tool call or a prompt. // 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 // It also recalls: registry entries on a qualifying prompt and a known-error
// line on a Bash failure, both switchable with "recall": false. // 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 type Api = EngineInterface
@@ -1586,7 +1588,8 @@ function registerBash(on: On, st: State): void {
await captureMilestones($, st, at, e, out as BashOut) await captureMilestones($, st, at, e, out as BashOut)
const line = await knownContext($, st, at, e, f) const line = await knownContext($, st, at, e, f)
if (line === '') return out if (line === '') return out
return { ...out, context: [...(out.context ?? []), line] } return { ...out, context: [...(out.context ?? []), line] } as
ToolCallResult<'Bash'>
}).catch(($, e, next) => { }).catch(($, e, next) => {
warnOnce(st, $, 'Bash', next.error.kind) warnOnce(st, $, 'Bash', next.error.kind)
return next(e) return next(e)
+14 -5
View File
@@ -8,6 +8,12 @@ const SONNET = 'claude-sonnet-5-5'
const HAIKU = 'claude-haiku-5-5' const HAIKU = 'claude-haiku-5-5'
type Rec = Record<string, unknown> type Rec = Record<string, unknown>
// 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 } type Asked = { text: string; options: string[]; header: string }
const HOME = '/home/t' 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 // the probe of the model main runs on: every model answers unless a test says not
on('model.complete', async (_$, e) => { on('model.complete', async (_$, e) => {
world.completions.push(e.model) 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) installWorld(on, world)
if (tokens !== null) usageOf(on, tokens) if (tokens !== null) usageOf(on, tokens)
@@ -1198,6 +1204,7 @@ function recordLogs(on: On): string[] {
} catch { } catch {
// nothing implements ui.log below the recorder in the kit // nothing implements ui.log below the recorder in the kit
} }
return undefined as never
}) })
return lines return lines
} }
@@ -1380,7 +1387,7 @@ async function effortAfterSkill($: Engine, on: On, skill: string) {
await $.agent.spawn(spawnOf('feater')) await $.agent.spawn(spawnOf('feater'))
await loadSkill($, skill, 'a1') await loadSkill($, skill, 'a1')
await runStep($, { ...highStep('a1'), model: SONNET }) 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) => { 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({ $.prompt.submit({
text, text,
wait: true, wait: true,
origin: { kind }, origin: { kind } as never,
turnId: 'u1', turnId: 'u1',
}) })
@@ -1614,7 +1621,7 @@ test('idle fallback: a mid-turn composer prompt promotes the allowance', async (
await $.prompt.submit({ await $.prompt.submit({
text: 'hello', text: 'hello',
wait: false, wait: false,
origin: { kind: 'channel' }, origin: { kind: 'channel' } as never,
}) })
await queued($, 'composer', 'hello') await queued($, 'composer', 'hello')
await endTurn($) await endTurn($)
@@ -1644,6 +1651,7 @@ function recordToasts(on: On): string[] {
} catch { } catch {
// nothing implements ui.toast below the recorder in the kit // nothing implements ui.toast below the recorder in the kit
} }
return undefined as never
}) })
return lines return lines
} }
@@ -4595,7 +4603,7 @@ const skillWorld = (): World => newWorld({ edit: f => {
/** The name a line shows after `marker`, up to the closing char. */ /** The name a line shows after `marker`, up to the closing char. */
const nameAfter = (line: string, marker: string, end: string): string => 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 ( test('logs: a hostile skill name is cleaned in the main line', async (
$, on) => { $, on) => {
@@ -4668,6 +4676,7 @@ function recordStatus(on: On): string[] {
} catch { } catch {
// nothing implements ui.status below the recorder in the kit // nothing implements ui.status below the recorder in the kit
} }
return undefined as never
}) })
return lines return lines
} }
+3 -1
View File
@@ -4656,7 +4656,9 @@ function registerSpawn(on: On, st: State): void {
const started = await next(wanted === undefined const started = await next(wanted === undefined
? e ? e
: { ...e, model: wanted }) : { ...e, model: wanted })
afterSpawn($, st, { e, started, route, wanted }) if (started.deny === undefined) {
afterSpawn($, st, { e, started, route, wanted })
}
return started return started
} finally { } finally {
st.spawning = Math.max(0, st.spawning - 1) st.spawning = Math.max(0, st.spawning - 1)