Implement the penpot_get_file tool (pages, objects and library assets) with unit tests #191
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#191
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 the
penpot_get_filetool: read a design file's revision, pages, page objects and library assets (colours, typographies, components) into a structured shape the agent can reason about. This is the read side that every write path checks against, and the source of therevnthe commit step tracks.Background
Depends on: #190
Confirms the file shape on Penpot 2.17, validated against a live instance:
get-filereturns library assets atdata.colors,data.typographiesanddata.components.data.pages(an ordered list of page ids) plusdata.pagesIndex(id →{ id, name, objects }), whereobjectsis the shape id → shape map.revn(revision) andvern(version). The commit step needsrevn; stale writes are accepted by the server, so the extension must track it itself.get-file-fragmentexists for cheaper targeted reads (a subset of pages/objects) — use it, or expose it, when a full file read would be wasteful for large files.A freshly created file has one page containing a
Root Frameat id00000000-0000-0000-0000-000000000000.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/<PENPOT_URL>/api/main/doc/openapi.json— authoritative parameters and response shapes forget-fileandget-file-fragmenton this instance.File/FileData/PagesListschema: whatcolors,typographies,components,pagesandpagesIndexactually contain. Pin to the Penpot tag matching the instance.objectsshape referenced bypagesIndex.docs/reference/pi-coding-agent/anddocs/reference/typebox/Type.Object/Type.Optionalfor the parameter schema;Type.Arrayfor repeated ids.Implementation Details
Create
extensions/penpot/src/tools/file.ts(and, if it grows, asrc/fileShape.tsfor the types) and register the tool insrc/index.ts.Parameters:
file_id(string, required) — the file to read.page_id(string, optional) — restrict the returned page content to one page.include_objects(boolean, optional, defaultfalse) — whether to include page object trees. Default off, because a real design file's object map is large and rarely needed in full by an agent that already knows what it wrote.summary_only(boolean, optional, defaulttrue) — return counts and names rather than full asset records.Behaviour:
get-file(orget-file-fragmentwhenpage_id/include_objectsallow a cheaper read) and normalise into a stable internal shape:{ id, name, revn, vern, pages: [{ id, name, objectCount }], colors: [{ id, name, color, opacity }], typographies: [{ id, name, ... }], components: [{ id, name, path, mainInstanceId, mainInstancePage }] }.revnandvernindetails— later steps depend on this being available and accurate.summary_onlyis false, include the asset records.objectsmap into the text channel, even wheninclude_objectsis true — emit a per-page object count and the id→name tree up to a bounded depth, and put the full structure indetailsonly if it stays within a reasonable size.file_idwith the categorisednot-foundmessage, not a crash.Acceptance Criteria
penpot_get_fileis registered and callable.revnandvernindetails.objectsmap is never dumped into the text output, regardless ofinclude_objects.page_idrestricts page content to one page; an unknownpage_idreturns a clear error.not-founderror.get-filepayload (checked in as a fixture) parse correctly, with no network access.Test Plan
Live check (requires
PENPOT_URL/PENPOT_TOKEN):penpot_get_fileon the scratch project's file and compare page names and asset names against the Penpot UI.revnmatches a subsequentget-filecall after a UI edit to the file.file_idand confirm the error is readable.pi-loop opened and merged a pull request for this issue: #224