Skip to content

feat: enhance Figma integration with full API property coverage#251

Merged
rubenmarcus merged 15 commits intomainfrom
feat/figma-api-enhancements
Feb 26, 2026
Merged

feat: enhance Figma integration with full API property coverage#251
rubenmarcus merged 15 commits intomainfrom
feat/figma-api-enhancements

Conversation

@rubenmarcus
Copy link
Copy Markdown
Member

Summary

  • Add ~20 missing Figma REST API properties to types, parsers, and agent guidelines for significantly improved design-to-code fidelity
  • Layout: layoutSizingHorizontal/Vertical (FIXED/HUG/FILL), layoutWrap, layoutPositioning (absolute children), counterAxisSpacing, layoutAlign, min/maxWidth/Height, clipsContent, scrollBehavior, overflowDirection
  • Visual: individualStrokeWeights (per-side borders), strokeDashes, rotation, isMask, imageTransformobject-position, image filters→CSS filter(), hero section detection, icon SVG export
  • Typography: fontStyle, textTruncation + maxLines with CSS line-clamp hints, hyperlink detection
  • Effects: progressive blur detection, backdrop-filter hints
  • New parsers: font-checker (Google Fonts validation), image-collector, icon-collector (VECTOR/INSTANCE node detection + SVG export)
  • Agent guidelines: Updated with sizing, wrap, absolute positioning, overflow, sticky/fixed, borders, rotation, and image filter rules

Test plan

  • pnpm build passes
  • pnpm test:run — all 213 tests pass
  • pnpm lint — no new errors (only pre-existing warnings)
  • End-to-end: run ralph --from figma against a Figma file with auto-layout, per-side borders, images, icons, and text truncation — verify spec output includes new properties

🤖 Generated with Claude Code

rubenmarcus and others added 9 commits February 24, 2026 06:25
Wire the existing maxCost infrastructure to a new --max-cost CLI option.
When no budget is set, warn users at $2/$5/$10 thresholds to encourage
setting a limit. This is opt-in only — no default limit that could break
existing long-running loops.

Closes #211

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
When sourceType is 'figma', inject domain-specific guidelines into the
agent preamble: auto-layout to flexbox/grid mapping, color token
extraction with @theme inline, typography fidelity, constraint
conversion, responsive breakpoints, and placeholder images.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
When fetching from Figma in default 'spec' mode, also fetch design
tokens (CSS variables) and prepend them to the spec. The agent gets
ready-to-use tokens for @theme inline instead of parsing the raw tree.

Also pass all Figma CLI options through to fetchFromSource (previously
only label/status/limit/issue were passed).

Cap in-prompt spec at 15KB to reduce token waste — full spec remains
on disk in specs/ directory.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Display the model name (e.g. '3-sonnet') and cumulative cost in the
loop header subtitle line, and add the full model name to the iteration
separator. Users can now see what model is running and how much it costs
at a glance.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add 42 new tests covering:
- buildIterationContext: preamble content, Tailwind v4 guidance,
  iteration-aware trimming (full/abbreviated/minimal), plan rules,
  design quality guidelines, validation feedback, iteration log
- compressValidationFeedback: truncation, section headers, ANSI stripping
- buildTrimmedPlanContext: task info, subtasks, completion counts
- buildCommitMessage: conventional commit detection (feat/fix/docs/
  refactor/test/chore), prefix stripping (bracket and colon formats)
- buildPrBody: task URL, description truncation, execution details

Export buildCommitMessage and buildPrBody for testability.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add ~20 missing Figma REST API properties to types, parsers, and agent
guidelines for significantly improved design-to-code fidelity.

Layout: layoutSizingHorizontal/Vertical (FIXED/HUG/FILL), layoutWrap,
layoutPositioning (absolute children), counterAxisSpacing, layoutAlign,
min/maxWidth/Height, clipsContent, scrollBehavior, overflowDirection.

Visual: individualStrokeWeights (per-side borders), strokeDashes,
rotation, isMask, imageTransform→object-position, image filters→CSS
filter(), hero section detection, icon SVG export.

Typography: fontStyle, textTruncation + maxLines with CSS line-clamp
hints, hyperlink detection.

Effects: progressive blur detection, backdrop-filter hints.

New parsers: font-checker (Google Fonts validation), image-collector,
icon-collector (VECTOR/INSTANCE node detection + SVG export).

Agent guidelines updated with sizing, wrap, absolute positioning,
overflow, sticky/fixed, borders, rotation, and image filter rules.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@chatgpt-codex-connector
Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@github-actions
Copy link
Copy Markdown
Contributor

Issue Linking Reminder

This PR doesn't appear to have a linked issue. Consider linking to:

  • This repo: Closes #123
  • ralph-ideas: Closes multivmlabs/ralph-ideas#123

Using Closes, Fixes, or Resolves will auto-close the issue when this PR is merged.


If this PR doesn't need an issue, you can ignore this message.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Feb 24, 2026

⚠️ Bundle Size Analysis

Metric Value
Base 1962.84 KB
PR 2234.84 KB
Diff 271.99 KB (13.00%)
Bundle breakdown
156K	dist/auth
32K	dist/automation
4.0K	dist/cli.d.ts
4.0K	dist/cli.d.ts.map
16K	dist/cli.js
12K	dist/cli.js.map
528K	dist/commands
28K	dist/config
4.0K	dist/index.d.ts
4.0K	dist/index.d.ts.map
4.0K	dist/index.js
4.0K	dist/index.js.map
808K	dist/integrations
84K	dist/llm
804K	dist/loop
188K	dist/mcp
32K	dist/presets
92K	dist/setup
40K	dist/skills
392K	dist/sources
76K	dist/ui
124K	dist/utils
336K	dist/wizard

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps bot commented Feb 24, 2026

Greptile Summary

This PR significantly enhances Figma integration by adding ~20 missing REST API properties for improved design-to-code fidelity. The changes span layout properties (sizing modes, wrap, absolute positioning, overflow), visual properties (per-side borders, rotation, masks, image transforms), typography enhancements (font style, text truncation), and new utility parsers for font validation, image collection, and icon extraction.

Key additions:

  • Layout: layoutSizingHorizontal/Vertical, layoutWrap, layoutPositioning, counterAxisSpacing, layoutAlign, size constraints, clipsContent, scrollBehavior, overflowDirection
  • Visual: individualStrokeWeights, strokeDashes, rotation, isMask, imageTransform, filters
  • Typography: fontStyle, textTruncation, maxLines, hyperlink detection
  • New parsers: font-checker (Google Fonts validation), image-collector, icon-collector with SVG export
  • Agent guidelines: Comprehensive Figma-to-code instructions for layout, colors, typography, images, and CSS implementation
  • CLI: Added --max-cost budget control option
  • Tests: 235 new test cases for context-builder and task-executor

Issues found:

  • Division by zero risk in imageTransformToObjectPosition when transform scale values equal exactly 1.0

Confidence Score: 4/5

  • Safe to merge after fixing the division by zero issue in imageTransformToObjectPosition
  • Comprehensive feature addition with extensive test coverage (213 tests passing). One critical division by zero bug found in image transform calculation. All other code is well-structured with proper error handling.
  • Pay close attention to src/integrations/figma/parsers/design-spec.ts - fix the division by zero bug before merging

Important Files Changed

Filename Overview
src/integrations/figma/types.ts Added ~20 new Figma API properties for layout, visual effects, typography, and image handling - comprehensive type coverage
src/integrations/figma/parsers/design-spec.ts Major parser enhancements with layout sizing, borders, rotation, image transforms - includes division by zero risk in imageTransformToObjectPosition
src/integrations/figma/source.ts Integrated new parsers (font-checker, icon-collector, image-collector) with API calls and error handling
src/commands/run.ts Enhanced with Figma asset downloads (images, icons, screenshots), font warnings, and spec size capping - robust error handling
src/loop/context-builder.ts Added comprehensive Figma-specific agent guidelines covering layout, typography, images, and CSS implementation

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[Figma Source Integration] --> B[Fetch Figma File API]
    B --> C[Parse Document Nodes]
    C --> D[Font Checker]
    C --> E[Image Collector]
    C --> F[Icon Collector]
    D --> G[Check Google Fonts]
    G --> H[Build Font Substitutions]
    E --> I[Fetch Image Fill URLs]
    I --> J[Download Images]
    F --> K[Export Icons as SVG]
    K --> L[Download SVG Files]
    C --> M[Design Spec Parser]
    H --> M
    I --> M
    K --> M
    M --> N[Generate Markdown Spec]
    N --> O[Context Builder]
    O --> P[Add Figma-Specific Guidelines]
    P --> Q[AI Coding Loop]
    J --> R[public/images/]
    L --> S[public/images/icons/]
Loading

Last reviewed commit: ed8854e

Copy link
Copy Markdown
Contributor

@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.

15 files reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

rubenmarcus and others added 4 commits February 25, 2026 17:11
… and sequential patterns

- Text/content elements always get higher z-index than visual layers (universal stacking rule)
- Classify image semantic importance: person images are CRITICAL priority, never hidden at any breakpoint
- Detect sequential/numbered patterns (01, 02, 03) in sibling elements, preserve exact design order
- Add Universal Stacking & Layout Rules section to generated implementation plans
- Add image-optimizer utility and plan-generator for Figma integration

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Keep PR branch's enhanced Figma features: plan budget tracking,
expanded agent guidelines, font substitutions, image downloads,
and spec size caps.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Replace magic 0.99 threshold with epsilon-based comparison
(1e-4) to eliminate the gap where values in [0.99, 1.0) could
cause division by near-zero or inconsistent behavior.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add sanitizeAssetFilename(), isValidFigmaCdnUrl(), and
sanitizeSvgContent() utilities. Apply to all four Figma
asset download locations in run.ts to prevent path traversal,
SSRF, and SVG XSS attacks.

Addresses GitHub Advanced Security review comments.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Feb 25, 2026

🔗 Docs Preview

Preview URL: https://feat-figma-api-enhancements.ralph-starter-docs.pages.dev

This preview was deployed from the latest commit on this PR.

- Rewrite sanitizeSvgContent with iterative stripping for nested/malformed tags
- Add PNG magic byte validation (isValidPngBuffer) for all image downloads
- Remove existsSync checks before mkdirSync (TOCTOU race conditions)
- Remove unused existsSync import from source.ts
- Update pnpm-lock.yaml for sharp optional dependency

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Rewrite sanitizeSvgContent with substring-based parser instead of
  regex to satisfy CodeQL js/bad-tag-filter and
  js/incomplete-multi-character-sanitization rules
- Fix TOCTOU race in readCache using fd-based stat+read (openSync/fstatSync)
- Fix TOCTOU race in image-optimizer using readFileSync buffer instead
  of separate statSync + sharp(filePath) calls

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@rubenmarcus rubenmarcus merged commit aff3c88 into main Feb 26, 2026
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants