Skip to content

feat: add typed TaskStarted/TaskProgress/TaskNotification message subclasses#621

Merged
qing-ant merged 1 commit intomainfrom
qing/typed-task-messages
Mar 3, 2026
Merged

feat: add typed TaskStarted/TaskProgress/TaskNotification message subclasses#621
qing-ant merged 1 commit intomainfrom
qing/typed-task-messages

Conversation

@qing-ant
Copy link
Copy Markdown
Contributor

@qing-ant qing-ant commented Mar 2, 2026

Adds typed dataclass subclasses of SystemMessage for task-related messages, matching the TypeScript SDK's SDKTaskStartedMessage/SDKTaskProgressMessage/SDKTaskNotificationMessage.

Approach

The three new classes subclass SystemMessage so existing code is unaffected:

  • isinstance(msg, SystemMessage)True for all typed task messages
  • msg.subtype and msg.data remain populated
  • case SystemMessage(): pattern matching still works
  • Unknown system subtypes still yield generic SystemMessage (not accidentally subclassed)

The parser dispatches on subtype to emit the specific subclass with typed fields; falls back to generic SystemMessage for anything else.

New types

  • TaskStartedMessage(SystemMessage)task_id, description, uuid, session_id, tool_use_id?, task_type?
  • TaskProgressMessage(SystemMessage)task_id, description, usage: TaskUsage, uuid, session_id, tool_use_id?, last_tool_name?
  • TaskNotificationMessage(SystemMessage)task_id, status: 'completed'|'failed'|'stopped', output_file, summary, uuid, session_id, tool_use_id?, usage?
  • TaskUsage TypedDict — {total_tokens, tool_uses, duration_ms}
  • Add typed TaskStartedMessage, TaskProgressMessage, TaskNotificationMessage subclasses of SystemMessage

Test plan

  • Unit: parser dispatch for all three subtypes, optional-field handling, isinstance(SystemMessage) and pattern-match backward-compat, generic fallback for unknown subtypes
  • E2E: real CLI subagent spawned — observed 1x TaskStartedMessage, 4x TaskProgressMessage, 1x TaskNotificationMessage, all fields correctly populated, init subtype correctly remained plain SystemMessage

@qing-ant qing-ant enabled auto-merge (squash) March 3, 2026 01:20
@qing-ant qing-ant requested a review from dltn March 3, 2026 03:57
@qing-ant qing-ant merged commit 9af27d7 into main Mar 3, 2026
9 checks passed
@qing-ant qing-ant deleted the qing/typed-task-messages branch March 3, 2026 18:21
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