Implement asset-reference resolution plus penpot_add_rect and penpot_add_text #199
Labels
No labels
bug
chore
documentation
enhancement
feature
ready
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
david/pi-extensions-and-skills#199
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
Implement library-asset resolution for shape arguments and the two leaf composition primitives,
penpot_add_rectandpenpot_add_text. Shapes must reference library assets by id (fillColorRefId/fillColorRefFile,typographyRefId/typographyRefFile) so editing one asset restyles every screen that uses it — the whole point of a design system.Background
Depends on: #198
The agent works in names (
fill: "flip7-gold",typography: "h2"); the extension resolves them from the library index built inpenpot_list_libraryand sets the reference fields. The agent never handles raw ids or hex values for linked styling.Confirmed on 2.17:
{ fillColor, fillOpacity, fillColorRefId, fillColorRefFile }and reads back correctly.fillColorRefFile; an asset from a linked library file carries that file's id (relevant from the library-import milestone onwards — support the field now, don't hard-code the current file).contentis a nested tree:root → paragraph-set → paragraph → spans, where each span carriestext,fillsand font fields (fontFamily,fontId,fontVariantId,fontSize,fontWeight,fontStyle,lineHeight,letterSpacing,textTransform). The agent should never author this tree by hand — the tool takes a plain string and builds it.add-objchange wrapper as frames, withparentIdpointing at the containing frame; the server maintains the parent'sshapesarray.Documentation Required
A separate process downloads these into the listed folders before this issue is implemented. Check the folders for the actual reference material before starting.
docs/reference/penpot-api/fillColorRefId/fillColorRefFile.root → paragraph-set → paragraph → spancontent tree and its required fields.typographyRefId/typographyRefFilereference fields.<PENPOT_URL>/api/main/doc/openapi.json—update-file/add-objon this instance.docs/reference/pi-coding-agent/anddocs/reference/typebox/details.Implementation Details
src/shapes.tsadditions (pure, unit-tested)fillFrom({ hex, opacity, refId, refFile })→ a fill record, withfillColorRefId/fillColorRefFileomitted (not null) when there is no reference.textContent({ text, typography, font, fills })→ the fullroot → paragraph-set → paragraph → spanstree for a single-paragraph string, with each span populated withtext,fillsand every font field. Build the tree — never accept it from the caller.resolveStyleArg(arg)→ parses the dual-form arguments:"#2BA8A2"(literal hex) or{ ref: "flip7-gold" }/"colour:flip7-gold"-style selector (library reference). Keep the parser small, documented and covered by tests.src/tools/rect.ts—penpot_add_rectParameters:
file_id(required),name,x,y,width,height,parent_id(required — the frame it belongs to),page_id(optional),fill(hex or library reference),stroke_color/stroke_width(optional),corner_radius(optional; supports the pill radius = half the shorter side), and child-layout hints where relevant (layout_item_h_sizing/layout_item_v_sizing/layout_item_absolute/layout_item_margin) so rects behave correctly inside an auto-layout frame.add-objchange and return the shape id indetails.src/tools/text.ts—penpot_add_textParameters:
file_id(required),text(the plain string),name,x,y,width/height(optional; text can size to content),parent_id,page_id,typography(library reference name, optional),font_size/font_weight/line_height/letter_spacing/text_transform/color(used when no typography is named), plus the same child-layout hints.typographynames a library asset, settypographyRefId/typographyRefFileand mirror the typography's font fields into the span (confirmed working on 2.17). When it does not, build the style from the individual parameters.Both tools: no HTTP write, no
update-file; the changeset accumulates andpenpot_commitapplies.Acceptance Criteria
fillColorRefIdandfillColorRefFile(using the asset's owning file id, not a hard-coded current file).refId/refFilekeys at all (notnull).root → paragraph-set → paragraph → spanstree with all font fields present per span.typographysets the typography reference fields and mirrors the asset's font fields into the span.corner_radiussupports a pill radius and rejects negatives.layoutItem*form (fill/fix/auto), never the UI word "hug".update-filecall in either tool.Test Plan
Live validation (requires
PENPOT_URL/PENPOT_TOKEN, scratch file with library assets from the earlier milestone):pi-loop opened and merged a pull request for this issue: #232