feat: enrich --json output for AI agent consumption#96
Conversation
|
Caution Review failedPull request was closed or merged during review 📝 WalkthroughWalkthroughAdds optional Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 2✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
Add fields that AI agents need to understand and act on analysis results: - analyzedAt: ISO timestamp for tracking changes over time - fileKey: identify which Figma file was analyzed - issues: detailed list with ruleId, severity, nodeId, nodePath, message Next step: enrich message content per rule to include concrete values and fix direction so AI can act without separate fixHint field. Refs #92 https://claude.ai/code/session_017n9jQMQWFoEE3Mje7MfgXs
9726728 to
86f3c1b
Compare
Every rule message now includes: - Concrete values (hex colors, dimensions, spacing values, font details) - Fix direction after em-dash (what to do to resolve the issue) AI agents can read the message alone and understand what's wrong, where it is, and how to fix it — no separate fixHint field needed. Examples: - raw-color: "uses raw fill color #FFFFFF — bind to a color variable" - missing-size-constraint: "FILL width (currently 286px) — add minWidth" - no-auto-layout: "no auto-layout (3 children arranged vertically) — apply VERTICAL auto-layout" - inconsistent-spacing: "padding 13px not on 4pt grid — round to 12px" Refs #92 https://claude.ai/code/session_017n9jQMQWFoEE3Mje7MfgXs
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@src/core/rules/token/index.ts`:
- Line 145: The message construction uses gridBase in arithmetic (e.g.,
`"${node.name}" has padding ${padding}px not on ${gridBase}pt grid — round to
nearest ${gridBase}pt multiple (${Math.round(padding / gridBase) *
gridBase}px)`), which can produce NaN/Infinity when gridBase is zero/negative;
update the relevant rule(s) in src/core/rules/token/index.ts to validate/guard
gridBase before any division/modulo, e.g., ensure gridBase is a positive
non-zero number (or fall back to a safe default) before computing
Math.round(padding / gridBase) * gridBase and when formatting messages, and add
or reuse the Zod schema validation for the option that supplies gridBase so
downstream code (the message construction and any checks around padding,
node.name, padding, gridBase) never performs arithmetic with invalid gridBase.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro
Run ID: afc805d7-4006-4c31-b6fb-bf3be5f340db
📒 Files selected for processing (13)
src/cli/commands/analyze.tssrc/cli/commands/implement.tssrc/core/engine/scoring.test.tssrc/core/engine/scoring.tssrc/core/rules/behavior/index.tssrc/core/rules/component/index.tssrc/core/rules/component/missing-component.test.tssrc/core/rules/naming/index.tssrc/core/rules/structure/index.tssrc/core/rules/structure/no-auto-layout.test.tssrc/core/rules/token/index.tssrc/core/rules/token/raw-color.test.tssrc/mcp/server.ts
Prevent NaN/Infinity in message output when gridBase is misconfigured. https://claude.ai/code/session_017n9jQMQWFoEE3Mje7MfgXs
Summary
--json출력을 AI 에이전트가 소비할 수 있는 수준으로 고도화.추가된 필드:
analyzedAt— 분석 시점 (before/after 비교용)fileKey— 어떤 Figma 파일인지 식별issues— 개별 이슈 상세 목록 (ruleId, severity, nodeId, nodePath, message)유저 스토리: Figma 플러그인에서 JSON export → AI 에이전트가 받아서 이슈 파악 →
use_figma로 수정Before:
issuesByRule에 룰별 개수만 (어떤 노드인지, 뭐가 문제인지 모름)After: 개별 이슈마다 노드 위치 + severity + 메시지 포함 → AI가 판단 가능
Refs #92
Test plan
pnpm lint— type check passpnpm test:run— 592 tests pass (+2 new)pnpm build+npx canicode analyze fixtures/x --json— 새 필드 확인https://claude.ai/code/session_017n9jQMQWFoEE3Mje7MfgXs
Summary by CodeRabbit
New Features
Tests