TypeScript SDK command exit_code type excludes emitted null
What issue are you seeing?
A started command_execution item can contain "exit_code": null, but the TypeScript SDK declares exit_code?: number and describes it as omitted until the command exits. Code that checks for undefined therefore type-checks but can fail at runtime.
The CLI's command item serializes an Option<i32> without skipping None; its event-processor test constructs a started item with None. The SDK type excludes null.
Reproduction
With the SDK's TypeScript dependencies installed, save this as sdk/typescript/exit-repro.ts:
import type { CommandExecutionItem } from "./src/items";
function render(item: CommandExecutionItem) {
const value = item.exit_code;
return value !== undefined ? value.toFixed(0) : "running";
}
const started: CommandExecutionItem = JSON.parse(
'{"id":"item_0","type":"command_execution","command":"echo hello",' +
'"aggregated_output":"","exit_code":null,"status":"in_progress"}'
);
console.log(render(started));
npx --yes --package [email protected] tsc --noEmit --strict --skipLibCheck sdk/typescript/exit-repro.ts succeeds; running it with npx --yes tsx sdk/typescript/exit-repro.ts throws TypeError: Cannot read properties of null (reading 'toFixed').
I separately serialized the production Rust command-item definitions in an isolated harness (only the TypeScript derive was removed) and confirmed exit_code:null. I also passed that JSON through the bundled SDK's real runStreamed() using a fake CLI fixture: the started item produced the same error, while a completed item with exit_code:0 rendered successfully. This test did not execute a real command.
Expected behavior
Declare exit_code as nullable (and optional if compatibility requires it), and update its documentation and tests. Alternatively, omit the field in the CLI JSON when its value is absent.
Tested on Windows with TypeScript 5.9.2 and source commit 6bfdc75f0d9e6fae313234f694839866d7c63c39.
I confirmed the wire value with a real CLI command. Using a local mock Responses server to request echo 'Hello, world!', thread.runStreamed() emitted a started command with status: "in_progress" and exit_code: null on macOS (CLI 0.169.0-alpha.11.1).
The fork declares exit_code?: number | null and updates the streaming sample to handle both absent values and null while still displaying exit code 0. The regression checks the actual event and type-checks the expected payload against CommandExecutionItem. Fix and regression test on my fork.