Skip to content

refactor(pocket-pi): typecheck the pi-full harness against pi's real API - #6

Merged
doodlewind merged 1 commit into
mainfrom
feat/type-harness-against-pi
Jul 22, 2026
Merged

refactor(pocket-pi): typecheck the pi-full harness against pi's real API#6
doodlewind merged 1 commit into
mainfrom
feat/type-harness-against-pi

Conversation

@doodlewind

Copy link
Copy Markdown
Contributor

The one type-safety investment worth making (from the discussion on #4): the session harness read globalThis.PiFull as any, so its createAgentSession/ModelRuntime/SessionManager/session calls weren't validated against pi's real types. A pi bump that changed those signatures would only surface in a runtime test.

Now entry.ts exports PiFullApi (the real, pi-typed PiFull object) and the harness scripts cast globalThis.PiFull to it — so tsc checks the harness against pi's actual API. A signature-changing bump now fails the typecheck at build time.

Turning it on immediately paid off. It flagged:

  • a dead event.type === "error" branch in the driver — pi has no "error" event; errors arrive as an assistant message with stopReason: "error" (already handled). Removed.
  • test-probe messages that don't match pi's Message shape, and reads of fields not on the public message union — deliberate loose test usages, now explicit casts instead of silent any.

Scope is exactly the harness (the code with real integration logic); the runtime polyfills stay transpile-only, as discussed. Runtime behavior unchanged — full suite green (incl. real gpt-5.6 turn); tsc + clippy clean.

🤖 Generated with Claude Code

The session harness read globalThis.PiFull as `any`, so its createAgentSession/
ModelRuntime/SessionManager/session calls weren't validated against pi's actual
types — a pi bump that changed those signatures would only blow up in a runtime
test. Now entry.ts exports `PiFullApi` (= the real, pi-typed PiFull object) and
the harness scripts cast globalThis.PiFull to it, so tsc checks them against pi's
API. A signature-changing bump now fails the typecheck at build time.

Turning it on immediately paid off — the typecheck flagged:
- a dead `event.type === "error"` branch in the driver: pi has no "error" event;
  errors arrive as an assistant message with stopReason "error" (already handled).
  Removed it.
- test-probe messages that don't match pi's Message shape, and reads of message
  fields not on the public union — deliberate loose test usages, now explicit
  casts rather than silent `any`.

Runtime behavior unchanged: full suite green (23 + 8 ignored, incl. real gpt-5.6
turn "pocket pi lives"); tsc + clippy clean.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@doodlewind
doodlewind merged commit bb3d366 into main Jul 22, 2026
1 check passed
@doodlewind
doodlewind deleted the feat/type-harness-against-pi branch July 22, 2026 06:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant