Implement the penpot_add_svg tool with svg-raw fallback and conversion reporting #210
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#210
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
penpot_add_svg: take an SVG (file path or inline string), convert it with the SVG→shapes converter, stage the resulting native shapes plussvg-rawfallbacks for anything unsupported, and report back exactly what was converted and what was not.Background
Depends on: #209
The converter produces descriptors; this step makes them real staged changes and gives the agent honest feedback. Two behaviours matter beyond the plumbing:
fillColorRefId/fillColorRefFile) rather than a literal hex. That is what keeps imported artwork editable within the design system instead of dragging in a parallel palette. Matching is by resolved hex value (case-insensitive), and ambiguity (two assets with the same hex) must be reported, not guessed.svg-rawand why. An agent that gets a silent drop produces a design that looks wrong for reasons nobody can see; an agent that gets a reason can fix the input or tell the user.svg-rawshapes are a legitimate outcome, not a failure: they keep unsupported artwork visible and editable-as-an-object, which is strictly better than losing it.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/svg-rawshape variant and what it needs (its raw content plus the standard geometry fields). Confirm the field that carries the markup on this version.content, for the convertedpathnodes.<PENPOT_URL>/api/main/doc/openapi.json—update-file/add-obj, and the exactsvg-rawpayload the server will validate.docs/reference/svg/nonesemantics being matched against library assets.docs/reference/pi-coding-agent/anddocs/reference/typebox/descriptionwording, and structureddetailsfor the conversion report.Implementation Details
Create
extensions/penpot/src/tools/svg.tsand register the tool.Parameters:
file_id(string, required).path(string, optional) — path to an.svgfile to read.svg(string, optional) — inline SVG markup. Exactly one ofpath/svgmust be provided; a runtime check with a clear error.x,y(numbers, optional, default 0) — placement offset for the root of the imported artwork.parent_id(string, optional) — the frame to place into; defaults to the page root.page_id(string, optional).scale(number, optional, default 1) — uniform scale applied at import, so an icon can be placed at a usable size.name_prefix(string, optional) — prefix for generated layer names (defaults to the file basename orsvg).Behaviour:
convertSvg) before staging anything: a parse error must leave the changeset untouched and report the offending offset/snippet.fillColorRefId/fillColorRefFile; on a duplicate-hex ambiguity, prefer the literal colour and report the ambiguity in the result. Provide alink_colorsboolean (defaulttrue) to disable matching entirely.add-objchanges for every converted shape and everysvg-rawfallback, in parent-first order, with geometry offset byx/yand scaled byscale.detailscarrying the staged shape ids, the skipped list with reasons and the report object.penpot_commitapplies everything atomically.Acceptance Criteria
path/svgis required, and giving neither or both produces a clear error.svg-rawshapes carrying the original markup.fillColorRefId/fillColorRefFile); the match is case-insensitive on hex.link_colors: falsedisables matching and leaves literal hex fills.x/yoffset andscaleare applied to every emitted shape, with geometry andselrectconsistent.path/svgid/nameattributes where present, prefixed as requested.update-filecall.Test Plan
Live validation (requires
PENPOT_URL/PENPOT_TOKEN, scratch file with library colours):path; commit.A-command path; confirm those nodes landed assvg-rawobjects (visible on the canvas) and that the tool's report lists each fallback reason.revnis unchanged.pi-loop opened and merged a pull request for this issue: #243