Skip to content

Add Pi message parsing infrastructure#831

Draft
dersam wants to merge 1 commit intodersam/pi-provider-skeletonfrom
dersam/pi-provider-message-parsing
Draft

Add Pi message parsing infrastructure#831
dersam wants to merge 1 commit intodersam/pi-provider-skeletonfrom
dersam/pi-provider-message-parsing

Conversation

@dersam
Copy link
Contributor

@dersam dersam commented Mar 2, 2026

Parse Pi's streaming JSON protocol into structured message objects,
mirroring the Claude provider's message architecture.

Message types implemented:

  • SessionMessage: Initial session metadata (id, version, cwd)
  • AgentStartMessage: Agent execution has begun
  • AgentEndMessage: Agent execution complete with full conversation;
    extracts final response, model, and usage from last assistant message
  • TurnStartMessage: New request/response cycle started
  • TurnEndMessage: Turn complete with usage stats per model
  • MessageStartMessage: User or assistant message starting
  • MessageUpdateMessage: Streaming deltas (text_delta, text_start/end,
    toolcall_start/delta/end) with format() for progress display
  • MessageEndMessage: Message complete with final content and usage
  • ToolExecutionStartMessage / ToolExecutionEndMessage: Tool execution
  • UnknownMessage: Catch-all for unrecognized types

The Message base class provides a from_json/from_hash factory that
dispatches to the appropriate subclass. PiInvocation now uses the
Message classes instead of raw hash parsing.

91 new tests (119 total Pi provider tests), full suite passes (985).

Copy link
Contributor Author

dersam commented Mar 2, 2026

Warning

This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
Learn more

This stack of pull requests is managed by Graphite. Learn more about stacking.

Parse Pi's streaming JSON protocol into structured message objects,
mirroring the Claude provider's message architecture.

Message types implemented:
- SessionMessage: Initial session metadata (id, version, cwd)
- AgentStartMessage: Agent execution has begun
- AgentEndMessage: Agent execution complete with full conversation;
  extracts final response, model, and usage from last assistant message
- TurnStartMessage: New request/response cycle started
- TurnEndMessage: Turn complete with usage stats per model
- MessageStartMessage: User or assistant message starting
- MessageUpdateMessage: Streaming deltas (text_delta, text_start/end,
  toolcall_start/delta/end) with format() for progress display
- MessageEndMessage: Message complete with final content and usage
- ToolExecutionStartMessage / ToolExecutionEndMessage: Tool execution
- UnknownMessage: Catch-all for unrecognized types

The Message base class provides a from_json/from_hash factory that
dispatches to the appropriate subclass. PiInvocation now uses the
Message classes instead of raw hash parsing.

91 new tests (119 total Pi provider tests), full suite passes (985).
@dersam dersam force-pushed the dersam/pi-provider-message-parsing branch from cc37153 to ca2f382 Compare March 2, 2026 19:39
@dersam dersam force-pushed the dersam/pi-provider-skeleton branch from 07b9833 to f7587c7 Compare March 2, 2026 19:39
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.

2 participants