different-ai/openwork · error · InterpreterRuntimeError

Expected '${key}' to be a boolean.

Error message

Expected '${key}' to be a boolean.

What it means

getBoolean is an internal AST accessor in the CodeMode interpreter that extracts an AST node property and asserts it is a boolean. It throws InterpreterRuntimeError when a node field that the interpreter expects to be `true`/`false` (e.g. a literal's `value`, a declaration's flag fields) has any other type, meaning the AST shape differs from what the evaluator assumes. This indicates either a malformed/synthetic AST node was fed to the interpreter or an internal bug in how a node was constructed.

Source

Thrown at packages/codemode/src/interpreter/model.ts:180

  }
  return value as AstNode
}

export const getArray = (node: AstNode, key: string): Array<unknown> => {
  const value = node[key]
  if (!Array.isArray(value)) throw new InterpreterRuntimeError(`Expected '${key}' to be an array.`, node)
  return value
}

export const getString = (node: AstNode, key: string): string => {
  const value = node[key]
  if (typeof value !== "string") throw new InterpreterRuntimeError(`Expected '${key}' to be a string.`, node)
  return value
}

export const getBoolean = (node: AstNode, key: string): boolean => {
  const value = node[key]
  if (typeof value !== "boolean") throw new InterpreterRuntimeError(`Expected '${key}' to be a boolean.`, node)
  return value
}

export const getOptionalNode = (node: AstNode, key: string): AstNode | undefined => {
  const value = node[key]
  if (value === undefined || value === null) return undefined
  return asNode(value, key)
}

export const getNode = (node: AstNode, key: string): AstNode => asNode(node[key], key)

export const sourceLocation = (node: AstNode): { readonly line: number; readonly column: number } => ({
  line: Math.max(1, (node.loc?.start.line ?? 2) - 1),
  column: Math.max(1, (node.loc?.start.column ?? 4) - 3),
})

export const formatLocation = (node?: AstNode): string => {
  if (!node?.loc) return ""

View on GitHub (pinned to 2b7df46e8a)

Solutions

  1. Update packages/codemode to a matching version so the transpiler output and interpreter AST accessors agree.
  2. Check the node reported in the error: log node[key] and confirm the field actually holds a boolean.
  3. If constructing AST by hand, set the field to a real boolean (true/false) rather than a string like "true".
  4. File/report an interpreter bug if the input script is plain valid TypeScript that should never hit this path.

Example fix

// before (synthetic node)
const node = { type: "BooleanLiteral", value: "true" }
// after
const node = { type: "BooleanLiteral", value: true }
Defensive patterns

Strategy: try-catch

Validate before calling

// Before running, sanity-check that scripts you feed in are plain TS that transpiles cleanly:
import ts from "typescript"
const { diagnostics } = ts.transpileModule(script, { compilerOptions: { module: ts.ModuleKind.ESNext, target: ts.ScriptTarget.ESNext } })
if (diagnostics?.length) throw new Error("Script does not transpile cleanly")

Type guard

const isBoolean = (v: unknown): v is boolean => typeof v === "boolean"

Try / catch

try {
  await program(script)
} catch (e) {
  if (e instanceof Error && e.message.includes("to be a boolean")) {
    // internal AST shape mismatch: report script + interpreter version, don't retry blindly
  } else throw e
}

Prevention

When it happens

Trigger: Calling program()/run with TypeScript that transpiles to an AST where a node property read via getBoolean (e.g. a BooleanLiteral's value) is not a boolean — typically when custom/transpiled AST is injected, or an interpreter bug after an AST producer version change.

Common situations: Running scripts through a mismatched typescript transpile target/AST shape, manually constructing AST nodes, or a codemode package version where AST fields were renamed so old field values are undefined.

Related errors


AI-assisted analysis of different-ai/openwork@2b7df46e8a (2026-09-01). Data as JSON: /api/errors/b8c6084613543e10. Report an issue: GitHub.