Implement the penpot_list_library tool with name-to-id resolution and unit tests #192
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#192
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_list_librarytool: return a file's design-system inventory — colours, typographies and components — as resolved name → id lookups, including duplicate-name detection. This is the lookup table the composition primitives use to turncolour: "flip7-gold"ortypography: "h2"into the asset ids that make a shape's fill or text linked to the library rather than hard-coded.Background
Depends on: #191
penpot_get_filealready returns the raw asset records. This tool is the semantic projection of them: the agent works with names, the extension resolves ids. The testable core is the resolution logic, not the HTTP call.Confirmed on Penpot 2.17: assets live at
data.colors,data.typographiesanddata.componentson the file; each record hasidandname. Components additionally carrypathandmainInstanceId/mainInstancePage, which the instancing primitive (a later milestone) needs.Two real-world wrinkles this tool must handle rather than hide:
flip7-gold. Resolution must refuse to guess: report the ambiguity with both ids and let the caller disambiguate.get-file-libraries/link-file-to-librarygovern that relationship and are built and validated in the library import/export milestone. Here, treat linked-library discovery as best-effort and optional: if a listing can be obtained, show it in a clearly separated section, but never let it fail the tool or appear in the acceptance criteria.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— confirmget-file(assets) andget-file-libraries/has-file-libraries(linked libraries) parameters on this instance.colors,typographies,componentscollections on the file.docs/reference/pi-coding-agent/anddocs/reference/typebox/Implementation Details
Create
extensions/penpot/src/tools/library.tsplus a pure resolution module —extensions/penpot/src/resolve.ts— and register the tool insrc/index.ts.Pure resolution (
src/resolve.ts) — the unit-tested corebuildIndex(assets: {id, name}[])→Map<name, Asset[]>.resolveAsset(assets, name)→{ ok: true, asset } | { ok: false, reason: "missing" | "ambiguous", candidates?: Asset[] }.{ caseInsensitive: true }used by the tool'sfuzzyparameter when the caller asks for it. Keep both behaviours tested.Tool (
penpot_list_library)Parameters:
file_id(string, required).library_file_ids(array of strings, optional) — extra library files whose assets should be merged in, labelled by source file id (explicit rather than implicit, so behaviour never depends on unpublished linking state).include_components(boolean, optional, defaulttrue) — whether to list components.Behaviour:
get-file, asset fields only — do not fetch page objects).name → id, alphabetical, with duplicates marked and a banner warning listing every ambiguous name.detailscarries the structured index:{ fileId, colors: {...}, typographies: {...}, components: {...}, ambiguousNames: [...] }.library_file_ids: fetch each named file's assets and merge under a per-source heading; a failure for one library file is reported, not fatal.Acceptance Criteria
penpot_list_libraryis registered and callable.name → id, alphabetically.resolveAssetreturns{ ok: false, reason: "missing" }with a bounded list of available names for an unknown name.resolveAssetreturns{ ok: false, reason: "ambiguous" }with every candidate id when a name occurs more than once; it never picks one silently.details.ambiguousNames.library_file_idsmerges the named files' assets, labelled by source; a failure for one file does not fail the tool.include_components: falseomits the components section.resolveAsset/buildIndexare green with no network access.Test Plan
Live check (requires
PENPOT_URL/PENPOT_TOKEN):penpot_list_libraryon the scratch file and confirm the names/ids match the Penpot UI's Assets panel.pi-loop opened and merged a pull request for this issue: #225