Skip to content

Add Zod runtime validation for agent output and IPC payloads#115

Merged
gregpriday merged 2 commits intomainfrom
feature/issue-80-zod-validation
Nov 29, 2025
Merged

Add Zod runtime validation for agent output and IPC payloads#115
gregpriday merged 2 commits intomainfrom
feature/issue-80-zod-validation

Conversation

@gregpriday
Copy link
Copy Markdown
Collaborator

Summary

Implements runtime validation using Zod schemas to protect against malformed data at system boundaries (agent events, IPC payloads, and AI responses).

Closes #80

Changes Made

  • Added electron/schemas/ module with comprehensive Zod schemas for:
    • Agent events (agent.ts): spawned, state-changed, output, completed, failed, killed
    • IPC payloads (ipc.ts): terminal operations, dev server controls, CopyTree integration
    • External data (external.ts): package.json, AI responses, git output
  • Implemented validation in PtyManager for all agent event emissions
  • Added validation to IPC handlers for terminal spawn/resize, dev server operations, and CopyTree generation/injection
  • Enhanced AI response parsing with Zod validation and safe fallbacks
  • Fixed agent:output bypass that could emit invalid payloads to transcript consumers
  • Filtered undefined environment variables before PTY spawn to prevent node-pty errors
  • Enforced non-empty strings in AgentOutputSchema and AgentFailedSchema
  • Added safe color defaults for invalid AI-generated project identities
  • Re-validated AI response fallbacks to prevent constraint bypass

Test Plan

  • ✅ TypeScript type checking passes
  • ✅ ESLint checks pass
  • ✅ Prettier formatting applied
  • ✅ All schemas compile correctly
  • ✅ Validation errors are properly logged

- Add consistent blank lines between sections for better visual separation
- Improve markdown structure in AGENTS.md, CLAUDE.md, and GEMINI.md
- Enhance readability of bulleted lists and headings
- Standardize section spacing across all documentation files
- Add electron/schemas/ module with agent.ts, ipc.ts, external.ts
- Validate agent events in PtyManager (spawned, state-changed, output, completed, failed, killed)
- Validate IPC handlers for terminal spawn/resize, dev server ops, CopyTree generation/injection
- Add Zod validation to AI response parsing in worktree.ts and identity.ts
- Fix agent:output bypass by dropping invalid payloads instead of emitting
- Filter undefined env values before spawning PTY to prevent node-pty errors
- Add fallback validation for AI responses with safe defaults for invalid colors
- Require non-empty strings in AgentOutputSchema and AgentFailedSchema
- Export SimplifiedProjectIdentitySchema for consistent imports
@gregpriday gregpriday merged commit ad0e01a into main Nov 29, 2025
@gregpriday gregpriday deleted the feature/issue-80-zod-validation branch November 29, 2025 09: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.

Add Zod runtime validation for agent output and IPC payloads

1 participant