Skip to content

Conversation

@kdcokenny
Copy link
Collaborator

@kdcokenny kdcokenny commented Jan 13, 2026

Summary

Throw descriptive, agent-friendly errors when todowrite receives malformed input instead of silently continuing.

Problem

When LLMs pass todos as a JSON string instead of an array, the original fix silently parsed and continued. This doesn't help the agent correct its behavior.

Solution

Throw errors with the [todowrite ERROR] prefix that include:

  • What was received
  • What was expected
  • How to fix it

Follows fail fast, fail loud and the OpenCode agent-friendly error pattern.

Changes

  • src/hooks/claude-code-hooks/index.ts: Refactored todowrite string parsing to throw agent-friendly errors

Testing

Manual verification with ocx ghost:

# Valid input - creates todo
ocx ghost opencode run "Create a todo list with one item" --profile omo-dev
# ✅ Todo created successfully

# Invalid input - agent-friendly error
ocx ghost opencode run "Call todowrite with todos as '{\"id\": \"1\"}'" --profile omo-dev  
# ✅ [todowrite ERROR] Parsed JSON is not an array. Received type: object...

Closes #625

Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your free trial has ended. If you'd like to continue receiving code reviews, you can add a payment method here.

Copy link

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 issue found across 1 file

Confidence score: 4/5

  • Appending ... unconditionally in src/hooks/claude-code-hooks/index.ts can mislead the agent about true input length, so trimming logic should only add the ellipsis when the string actually exceeds 100 characters.
  • Overall change is still low risk and easy to adjust, so this PR looks safe to merge once that display detail is corrected.
  • Pay close attention to src/hooks/claude-code-hooks/index.ts - ensure ... only appears when truncation occurs.
Prompt for AI agents (all issues)

Check if these issues are valid — if so, understand the root cause of each and fix them.


<file name="src/hooks/claude-code-hooks/index.ts">

<violation number="1" location="src/hooks/claude-code-hooks/index.ts:195">
P2: Ellipsis is always appended even when string isn't truncated, which misleads the agent about the actual input. Only show `...` when the string exceeds 100 characters.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

@kdcokenny kdcokenny force-pushed the fix/todowrite-agent-friendly-errors branch from 7554d72 to 8646564 Compare January 13, 2026 03:05
@kdcokenny kdcokenny merged commit 6ea6370 into dev Jan 13, 2026
2 checks passed
@kdcokenny kdcokenny deleted the fix/todowrite-agent-friendly-errors branch January 13, 2026 03:11
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