From 445c3cafa0cfb52db2d65daa02d34d0e15f8434a Mon Sep 17 00:00:00 2001 From: brunosouzas-agent Date: Sun, 6 Dec 2026 07:01:35 +0000 Subject: [PATCH 1/3] spec: skills-marketplaces Co-Authored-By: Claude Sonnet 5.5 --- .../skills-marketplaces/.openspec.yaml | 1 + .../changes/skills-marketplaces/design.md | 15 ++ .../changes/skills-marketplaces/proposal.md | 54 ++++ .../specs/skill-source/spec.md | 245 ++++++++++++++++++ .../specs/skills-map-command/spec.md | 41 +++ .../specs/skills-site/spec.md | 12 + openspec/changes/skills-marketplaces/tasks.md | 23 ++ 7 files changed, 391 insertions(+) create mode 100644 openspec/changes/skills-marketplaces/.openspec.yaml create mode 100644 openspec/changes/skills-marketplaces/design.md create mode 100644 openspec/changes/skills-marketplaces/proposal.md create mode 100644 openspec/changes/skills-marketplaces/specs/skill-source/spec.md create mode 100644 openspec/changes/skills-marketplaces/specs/skills-map-command/spec.md create mode 100644 openspec/changes/skills-marketplaces/specs/skills-site/spec.md create mode 100644 openspec/changes/skills-marketplaces/tasks.md diff --git a/openspec/changes/skills-marketplaces/.openspec.yaml b/openspec/changes/skills-marketplaces/.openspec.yaml new file mode 100644 index 0000000..b4bbeb9 --- /dev/null +++ b/openspec/changes/skills-marketplaces/.openspec.yaml @@ -0,0 +1 @@ +schema: spec-driven diff --git a/openspec/changes/skills-marketplaces/design.md b/openspec/changes/skills-marketplaces/design.md new file mode 100644 index 0000000..ef61d3c --- /dev/null +++ b/openspec/changes/skills-marketplaces/design.md @@ -0,0 +1,15 @@ +## Context + +An item's identity is its `name`, used as the key by relations, the map pages, the skills metro map and the site. Marketplaces need the same plain name in two plugins. + +## Decision + +An item of a plugin has `name` = `plugin:plain` and keeps `plain`, `plugin` and `marketplace`. A loose item has `name` = `plain` and no plugin. Because `name` stays the identity everywhere, graph, metro map, pages and site keep working unchanged and show the qualified name; only places that read what an author wrote (relations, preloads, skills map file references, zone names) resolve it, through one function (`src/skills/resolve.ts`). Alternatives: a separate `id` field next to `name` (rejected: every consumer would need changing, and a missed one would key on the plain name and merge two agents). + +Page file names: `plugin--name` when both parts are valid names. Valid plain names never hold `--`, so it cannot clash with a loose item. Anything else keeps the hexadecimal form of the whole qualified name. + +Marketplace reading is in the walk, because the walk decides what is found and applies `.stackledgerignore`. The walk lists a plugin's `skills/` and `agents/` with the same code as a loose folder, below the plugin's path; ignore patterns are relative to the given folder, so `plugins/legacy/` skips a plugin. + +## Risks + +A skill whose frontmatter `name` holds `:` (only a warning today) could clash with a qualified name; the set reports the clash as "already used". diff --git a/openspec/changes/skills-marketplaces/proposal.md b/openspec/changes/skills-marketplaces/proposal.md new file mode 100644 index 0000000..ba7d519 --- /dev/null +++ b/openspec/changes/skills-marketplaces/proposal.md @@ -0,0 +1,54 @@ +## Why + +Skills are now published as Claude Code plugins in plugin marketplaces ([ADR 11](../../../docs/adr/0011-skills-are-read-from-plugin-marketplaces.md)): a Git repository with `.claude-plugin/marketplace.json` listing plugins, each with its own `skills/` and `agents/`. Checked on 2026-12-05 against a real marketplace with the 0.10.1 build: `skills validate .` finds no agents (they live in `plugins//agents/`, so ten relations fail), and passing `plugins/*/` finds the agents but `plugin:skill` names do not resolve, so the catalogue repository needs one `--skills` per plugin. Two plugins may also hold agents with the same name, and today the second is rejected. + +## What Changes + +- A given folder that holds `.claude-plugin/marketplace.json` is a marketplace root and is read as one set: every plugin the manifest lists by a local `source` (`./plugins/`) gives its `skills/` and `agents/`. A plugin with a remote `source` (an object) is skipped with a warning; nothing is fetched. +- Each skill and agent of a plugin is named `plugin:name`, and records its plugin and marketplace. Relations, an agent's `skills` and skills map file references resolve a plain name or a qualified one (precedence below); a plain name that matches two plugins' items is an error that asks for the qualified name. +- Names are unique per plugin: agents (and skills) with one name in two plugins are both kept. Each gets its own page, named `plugin--name`, on the Markdown map and on the site, and the page shows its plugin and marketplace. +- Loose skill folders behave as before, and `.stackledgerignore` applies at the top of each given folder, marketplace roots included. + +## Capabilities + +### New Capabilities + +None. + +### Modified Capabilities + +- `skill-source`: marketplace roots, plugins, qualified names and their resolution, same-named items in two plugins. +- `skills-map-command`: page file names of qualified names, the plugin and marketplace on item pages. +- `skills-site`: the plugin and marketplace on skill and agent pages. + +## Out of scope + +- Zones by marketplace, journeys, interchanges and the skills map file in the catalogue repository (`skill-journeys`, SW-347); project journeys (SW-348); named maps (SW-349); the catalogue repository's pipeline (SW-350). Nothing is drawn differently on the metro map: stations carry the qualified name. +- Fetching anything: a remote plugin is never cloned or downloaded, and what a tool has installed (`~/.claude`, a plugin cache) is never read. +- A plugin folder given directly (`plugins/`) stays a loose folder: its items have no plugin. +- Plugin manifest fields other than the plugin's name (`plugin.json` paths for custom `skills` or `agents` folders, hooks, commands, MCP servers), `metadata.pluginRoot` and `strict: false` entries that carry their own components. +- Reading skills a marketplace root holds outside its plugins. + +## Implicit requirements + +- **Errors and invalid input:** requirement. A manifest that cannot be read or parsed, a plugin with a bad name or source, a source that leaves the marketplace, a missing plugin folder and a name clash are problems on their own path; the rest of the set is still read. +- **Limits:** requirement. `marketplace.json` and `plugin.json` share the 1 MiB file limit; a manifest lists at most 500 plugins. +- **Repetition and idempotency:** requirement. The same files give the same output; a plugin folder listed twice is read once. +- **Concurrency:** n/a: one read-only process. +- **Security:** requirement. Manifests go through the secret rules like every file; a `source` is never followed outside the marketplace root (lexically or through links); remote sources are not contacted. +- **Logs and observability:** requirement. The warning for a remote plugin names it, so nothing is skipped silently; no other logging. + +## Decisions to confirm at gate 1 + +1. **A marketplace root is recognised by its manifest alone**: a given folder (not a skill folder) with a regular file `.claude-plugin/marketplace.json`. No flag; a root is read only through its plugins. Recommended: it is how Claude Code recognises one, and a loose folder never has the file. +2. **The identity of an item is `plugin:name`, with the plugin name taken from the manifest entry.** A `plugin.json` whose `name` differs is a warning. Recommended: the entry name is what `/plugin install name@marketplace` uses. +3. **Resolution of a plain name:** the declaring item's own plugin first, then an exact name (a loose item or a qualified name), then the only plugin item with that name; two or more is an error (a warning for an agent's `skills`, which a tool only skips). Recommended: it matches what an author means, and a set of loose folders resolves exactly as before. +4. **Remote plugins are a warning, never an error**, so a marketplace that mixes local and remote plugins can still pass CI. + +## Documentation + +- `docs/skills.md`: marketplaces, plugins, qualified names, resolution, remote plugins; the "Planned" note narrowed to what is still planned. +- `README.md`: one sentence in "Agent skills"; `AGENTS.md`: the implemented list. +- `docs/architecture.md`: the module map (`src/skills/marketplace.ts`, `resolve.ts`). +- `docs/roadmap.md`: the `skills-marketplaces` row delivered. +- Brain vault: the stackledger roadmap and changelog, after the merge. diff --git a/openspec/changes/skills-marketplaces/specs/skill-source/spec.md b/openspec/changes/skills-marketplaces/specs/skill-source/spec.md new file mode 100644 index 0000000..986d464 --- /dev/null +++ b/openspec/changes/skills-marketplaces/specs/skill-source/spec.md @@ -0,0 +1,245 @@ +## ADDED Requirements + +### Requirement: Marketplace root +A given folder that is not a skill folder and holds a regular file (or a link to one) at `.claude-plugin/marketplace.json` SHALL be a marketplace root. A marketplace root SHALL be read only through the plugins its manifest lists: its other folders SHALL NOT be walked, and no `agents` folder at its top SHALL be read. `.stackledgerignore` and the skills map file at its top SHALL apply as in any given folder. A folder without that file SHALL be a loose folder, read as before. + +#### Scenario: Marketplace read as one set +- **WHEN** the given folder holds `.claude-plugin/marketplace.json` listing `writing` at `./plugins/writing` and `review` at `./plugins/review`, and each holds `skills//SKILL.md` and `agents/.md` +- **THEN** the skills and agents of both plugins are in one set + +#### Scenario: Loose folder +- **WHEN** a given folder holds `skills/writer/SKILL.md` and no `.claude-plugin/marketplace.json` +- **THEN** it is read as before and `writer` has no plugin + +#### Scenario: Other folders of the root are not read +- **WHEN** a marketplace root holds `templates/skill/SKILL.md` that no plugin includes +- **THEN** it is not read and there is no problem + +#### Scenario: Ignore file +- **WHEN** the root holds `.stackledgerignore` with `plugins/legacy/` +- **THEN** the plugin at `./plugins/legacy` is not read and is counted as ignored + +### Requirement: Marketplace manifest +`marketplace.json` SHALL be a JSON object with a non-empty string `name` and an array `plugins`; each plugin SHALL be an object with `name` and `source`. A file that is too large, unreadable, not valid JSON, holding a secret, or without `name` or `plugins` SHALL be an error on that file, and the marketplace SHALL give no plugins. + +#### Scenario: Invalid manifest +- **WHEN** `marketplace.json` is not valid JSON +- **THEN** there is one error on the file, and nothing else is read from that folder + +### Requirement: Plugin entries +A plugin name SHALL be lowercase letters and digits with single hyphens between them; a name used earlier in the manifest SHALL be an error on the later entry, which is not read. An entry without a string `name`, or with no `source`, SHALL be an error on it and be skipped. At most 500 entries SHALL be read, and each later one SHALL give one error. + +#### Scenario: Too many plugins +- **WHEN** the manifest lists 501 plugins +- **THEN** the first 500 are read and the last gives one error + +#### Scenario: Duplicate plugin name +- **WHEN** two entries are named `writing` +- **THEN** there is one error on the second and its folder is not read + +#### Scenario: Plugin name not a name +- **WHEN** an entry is named `Writing Tools` +- **THEN** there is one error on it and it is skipped + +#### Scenario: Entry without a source +- **WHEN** an entry has `name` and no `source` +- **THEN** there is an error on it and the other entries are read + +### Requirement: Plugin sources +A plugin whose `source` is a string SHALL name a folder of the marketplace: it SHALL start with `./`, stay inside the marketplace root once `..` segments are resolved and links followed, and name an existing folder. A string source that does not meet this, or a missing folder, SHALL be an error on the entry. +#### Scenario: Source outside the marketplace +- **WHEN** an entry has `source` `./../elsewhere`, or a link inside `plugins/` leads outside the root +- **THEN** there is one error on the entry and nothing outside the root is read + +#### Scenario: Source without the leading ./ +- **WHEN** an entry has `source` `plugins/writing` +- **THEN** there is one error on the entry + +#### Scenario: Missing plugin folder +- **WHEN** `source` is `./plugins/gone` and there is no such folder +- **THEN** there is one error on the entry + +#### Scenario: Root as the plugin +- **WHEN** an entry has `source` `./` and the root holds `skills/writer/SKILL.md` +- **THEN** `writer` is read as a skill of that plugin + +### Requirement: Remote plugins +A plugin whose `source` is an object (a GitHub repository, a Git URL, an npm package) SHALL be skipped with one warning naming the plugin and saying it was not read; it SHALL never be fetched. A plugin folder listed by two entries SHALL be read once, for the first entry. + +#### Scenario: Remote plugin +- **WHEN** an entry has `source` `{ "source": "github", "repo": "northwind/helper" }` +- **THEN** there is one warning naming the plugin, no error, and no network call + +### Requirement: Plugin contents +A plugin SHALL give the skills found below its `skills` folder, walked like a given folder (five levels, hidden entries and `node_modules` skipped, the walk not entering a skill folder), and the `.md` files directly in its `agents` folder, checked as agent files. A missing `skills` or `agents` folder SHALL give no problem. Each item SHALL record its plugin and its marketplace's name. + +#### Scenario: Agents of a plugin +- **WHEN** `plugins/review` holds `agents/reviewer.md` with a valid agent +- **THEN** agent `review:reviewer` is in the set, with plugin `review` and the marketplace's name + +### Requirement: Plugin manifest +When a plugin holds `.claude-plugin/plugin.json` with a string `name` different from the entry's, there SHALL be one warning on `plugin.json` and the entry's name SHALL be used. A `plugin.json` that cannot be read or parsed SHALL be one warning. A plugin that gives no skill and no agent SHALL give one warning. + +#### Scenario: Name differs in plugin.json +- **WHEN** the entry is `review` and `plugins/review/.claude-plugin/plugin.json` has `name` `code-review` +- **THEN** one warning on `plugin.json`, and the items are `review:` + +#### Scenario: Empty plugin +- **WHEN** a plugin folder holds neither `skills` nor `agents` +- **THEN** there is one warning naming the plugin + +### Requirement: Qualified names +An item of a plugin SHALL be named `:`, where `` is its frontmatter `name`; an item of a loose folder SHALL keep its frontmatter `name`. Wherever this specification says "name" of an item (messages, relations, references, pages), the qualified name is meant. The frontmatter checks SHALL apply to the plain name. + +#### Scenario: Qualified name in problems +- **WHEN** a plugin's skill `writer` lists a skill that is not in the set +- **THEN** the error is on the plugin skill's `SKILL.md` and names the missing target as written + +### Requirement: Name resolution +A name written in `stackledger-skills`, `stackledger-agents`, an agent's `skills`, a skills map file reference or a zone SHALL be resolved in this order: (1) when the writer is an item of a plugin, that plugin's item with that plain name; (2) the item whose qualified name equals the text exactly, which also finds a loose item; (3) the only plugin item with that plain name. When nothing matches, the existing missing-item problem SHALL be given. + +#### Scenario: Own plugin first +- **WHEN** skills `writing:draft` and `review:draft` exist and `writing:publish` lists `draft` +- **THEN** it resolves to `writing:draft` with no problem + +#### Scenario: Plain name from outside +- **WHEN** only `writing:draft` has that plain name and a loose playbook lists `draft` +- **THEN** it resolves to `writing:draft` with no problem + +#### Scenario: Qualified name +- **WHEN** a loose playbook lists `review:draft` +- **THEN** it resolves to `review:draft`, whatever other items are named `draft` + +#### Scenario: Loose item wins over plugin items +- **WHEN** a loose skill `draft` and `writing:draft` exist and a loose playbook lists `draft` +- **THEN** it resolves to the loose skill + +### Requirement: Resolved relations +A resolved relation SHALL be stored under the qualified name, so `draft` and `writing:draft` written in one list are one relation and the repeat warning applies. + +#### Scenario: Qualified and plain name of one item +- **WHEN** a loose playbook lists `draft writing:draft` and `writing:draft` is the only `draft` +- **THEN** there is one repeat warning + +### Requirement: Ambiguous names +When step 3 of "Name resolution" finds two or more items, the name SHALL be ambiguous: one error naming every match in code-point order and asking for the qualified name, or a warning for an agent's `skills`, as a missing preload is. An ambiguous name SHALL resolve to nothing. + +#### Scenario: Ambiguous name +- **WHEN** `writing:draft` and `review:draft` exist and a loose playbook lists `draft` +- **THEN** there is one error on `metadata.stackledger-skills` naming `review:draft` and `writing:draft` and asking for the qualified name + +#### Scenario: Agent preload ambiguity +- **WHEN** an agent of no plugin has `skills: [draft]` and two plugins have `draft` +- **THEN** there is one warning with field `skills[0]` and no error + +### Requirement: Same name in two plugins +Names SHALL be unique per plugin: two skills (or two agents) of one plugin with the same name are the existing duplicate error. Items with the same plain name in different plugins SHALL all be kept, each under its qualified name. + +#### Scenario: Agents with one name in two plugins +- **WHEN** `plugins/writing/agents/reviewer.md` and `plugins/review/agents/reviewer.md` both have `name: reviewer` +- **THEN** both `writing:reviewer` and `review:reviewer` are in the set, and the summary counts two agents + +#### Scenario: Duplicate inside one plugin +- **WHEN** one plugin holds `agents/a.md` and `agents/b.md`, both `name: reviewer` +- **THEN** there is one error on the later file and one agent + +## MODIFIED Requirements + +### Requirement: Declared relations +Skills and playbooks MAY declare `stackledger-skills` and `stackledger-agents`, read as names separated by whitespace (spaces, tabs, line breaks); a blank string declares none. Each name SHALL be resolved as in "Name resolution". Each distinct name that matches no skill or playbook (for `stackledger-skills`) or no agent (for `stackledger-agents`) SHALL be one error with the field, naming it as written. + +#### Scenario: Missing skill +- **WHEN** a playbook has `stackledger-skills: writer editr` and the set has no `editr` +- **THEN** there is one error with field `metadata.stackledger-skills` naming `editr` + +#### Scenario: Missing agent +- **WHEN** a playbook has `stackledger-agents: reviewer` and the set has no agent `reviewer` +- **THEN** there is one error with field `metadata.stackledger-agents` naming `reviewer` + +#### Scenario: Names on several lines +- **WHEN** `stackledger-skills` is a YAML block holding `writer` and `editor` on two lines, both in the set +- **THEN** both relations are read and there is no problem + +### Requirement: Preloaded skills of an agent +An agent's `skills`, when present, SHALL be a YAML list of strings; otherwise it SHALL be one warning with field `skills` and no preload is read. Each listed name SHALL be resolved as in "Name resolution", the agent's own plugin first; one matching no skill or playbook SHALL be a warning with field `skills[n]`, because the tool loading the agent only skips it. + +#### Scenario: Unknown preloaded skill +- **WHEN** agent `reviewer` has `skills: [code-review, linting]` and the set has no `linting` +- **THEN** there is a warning with field `skills[1]` and no error + +#### Scenario: Skills as a string +- **WHEN** an agent has `skills: code-review` +- **THEN** there is a warning with field `skills` + +#### Scenario: Preload from the agent's plugin +- **WHEN** the agent `review:reviewer` has `skills: [checklist]` and both `review:checklist` and `writing:checklist` exist +- **THEN** it preloads `review:checklist` with no problem + +### Requirement: Unique names +A skill or playbook whose name is already used by an earlier skill or playbook of the set SHALL be an error with field `name` on the later file, naming the earlier path, and SHALL NOT join the set. The same SHALL hold for two agents. A skill and an agent MAY share a name. Two items of different plugins have different names (see "Qualified names"), so they do not clash. + +#### Scenario: Same skill name in two folders +- **WHEN** different folders `a/writer` and `b/writer` both have `name: writer`, given as `a b` +- **THEN** there is one error on `b/writer/SKILL.md` naming `a/writer/SKILL.md`, and relations use the skill under `a` + +#### Scenario: Two agents with one name +- **WHEN** `agents/review.md` and `agents/reviewer.md` both have `name: reviewer` +- **THEN** there is one error on `agents/reviewer.md` + +### Requirement: Skill references +In a skills map file, each stop and each `MapLayout` station key SHALL be `skill:`, `playbook:` or `agent:`, the kind in lower case and the name being everything after the first `:`, which SHALL be resolved as in "Name resolution" (a qualified name is `skill:plugin:name`), and SHALL name an item of that kind in the set; otherwise it SHALL be an error at it, naming it and, when an item of another kind has that name, its kind. A stop with an error is not a stop of the drawn map. A stop and a station key that resolve to one item SHALL be the same station. + +#### Scenario: Missing stop +- **WHEN** a line's second stop is `skill:editr` and the set has no `editr` +- **THEN** there is one error with field `spec.stops[1]` naming `editr` + +#### Scenario: Wrong kind +- **WHEN** a stop is `skill:release` and `release` is a playbook +- **THEN** there is an error on that stop saying `release` is a playbook, and the skills map has no station for it on that line + +#### Scenario: Kind in another case +- **WHEN** a stop is `Skill:writer` and the set has the skill `writer` +- **THEN** there is an error on that stop + +#### Scenario: Software reference +- **WHEN** a stop is `component:editor` +- **THEN** there is an error on that stop + +#### Scenario: Agent station +- **WHEN** a line stops at `agent:reviewer` and the layout places `agent:reviewer` at `[2, 0]`, and the set has the agent `reviewer` +- **THEN** there is no problem + +#### Scenario: Stop excluded by an error +- **WHEN** a line stops at `skill:editor` and `editor`'s `SKILL.md` has no frontmatter +- **THEN** there is an error on that stop, besides the error on `editor`'s file + +#### Scenario: Qualified stop +- **WHEN** a stop is `agent:review:reviewer` and the set has `review:reviewer` and `writing:reviewer` +- **THEN** there is no problem and the stop is `review:reviewer` + +#### Scenario: Ambiguous plain stop +- **WHEN** a stop is `agent:reviewer` and the set has `review:reviewer` and `writing:reviewer` +- **THEN** there is one error on that stop naming both + +#### Scenario: Plain and qualified stops of one item +- **WHEN** a line stops at `skill:draft` and then at `skill:writing:draft`, and `writing:draft` is the only `draft` +- **THEN** there is an error on the second stop saying the item is visited more than once + +### Requirement: Playbook zones +In a skills `MapLayout`, each zone of `spec.zones` (`name`, `title`, `color`, as in the catalogue) SHALL name a playbook of the set, resolved as in "Name resolution"; a name that is no playbook of the set SHALL be an error on that zone's `name`, a reference error like a missing station: the layout is still used and that zone has no member. The zone's members are the playbook and the skills, playbooks and agents its `stackledger-skills` and `stackledger-agents` name in the set. + +#### Scenario: Playbook as a zone +- **WHEN** the layout declares the zone `release` with a title and a colour, and the playbook `release` loads `writer` and `editor` and uses `reviewer` +- **THEN** there is no problem and the zone's members are `release`, `writer`, `editor` and `reviewer` + +#### Scenario: Zone that is not a playbook +- **WHEN** the layout declares the zone `writer` and `writer` is a skill +- **THEN** there is an error on that zone's `name` saying it must name a playbook, the layout's positions are still used, and the zone is not drawn + +#### Scenario: Only direct members +- **WHEN** the zone `ship` is the playbook `ship`, which loads the playbook `release`, which loads `writer` +- **THEN** the members of `ship` are `ship` and `release`, not `writer` + +#### Scenario: One skill in two zones +- **WHEN** the playbooks `release` and `review` both load `writer` and both are zones +- **THEN** `writer` is a member of both zones and there is no problem diff --git a/openspec/changes/skills-marketplaces/specs/skills-map-command/spec.md b/openspec/changes/skills-marketplaces/specs/skills-map-command/spec.md new file mode 100644 index 0000000..4307ac5 --- /dev/null +++ b/openspec/changes/skills-marketplaces/specs/skills-map-command/spec.md @@ -0,0 +1,41 @@ +## ADDED Requirements + +### Requirement: Plugin on item pages +The page of an item of a plugin SHALL show, after the kind, a line `Plugin: ` and a line `Marketplace: `; the `h1`, the diagram labels, the lists and the index SHALL use its qualified name. An item of a loose folder SHALL have neither line. Two items with one plain name in different plugins SHALL have two pages. + +#### Scenario: Agents with one name +- **WHEN** the plugins `writing` and `review` of the marketplace `northwind-skills` each hold the agent `reviewer` +- **THEN** `agents/writing--reviewer.md` and `agents/review--reviewer.md` exist, each with its own plugin line, and the index lists both + +#### Scenario: Loose skill page +- **WHEN** a skill comes from a loose folder +- **THEN** its page has no plugin or marketplace line + +## MODIFIED Requirements + +### Requirement: Page file names +A loose name SHALL be the page's file name when it matches `^[a-z0-9]+(-[a-z0-9]+)*$`, has at most 64 characters and is not a Windows device name (`con`, `prn`, `aux`, `nul`, `com0`–`com9`, `lpt0`–`lpt9`). A qualified name `:` whose two parts both match that pattern SHALL be `--` when that has at most 64 characters (a valid loose name never holds `--`, so the two forms cannot clash). Any other name SHALL be written as `_` and the lowercase hexadecimal of its UTF-8 bytes; when that has more than 64 characters, its first 52 characters, `-`, and the first 11 hexadecimal digits of the SHA-256 of those bytes. + +#### Scenario: Name with a path +- **WHEN** a skill is named `../writer` +- **THEN** its page is `skills/_2e2e2f777269746572.md` and nothing is written outside the map folder + +#### Scenario: Names that differ only in case +- **WHEN** a skill is named `Writer` and another `writer` +- **THEN** the pages are `skills/_577269746572.md` and `skills/writer.md` + +#### Scenario: Windows device name +- **WHEN** a skill is named `con` +- **THEN** its page is `skills/_636f6e.md` + +#### Scenario: Long name +- **WHEN** a skill is named with 65 `a` characters +- **THEN** its page is `skills/_616161616161616161616161616161616161616161616161616-635361c48bb.md` + +#### Scenario: Qualified name +- **WHEN** the plugin `writing` holds the skill `draft` +- **THEN** its page is `skills/writing--draft.md` + +#### Scenario: Qualified name with an invalid part +- **WHEN** the plugin `writing` holds a skill named `Draft` +- **THEN** its page is the hexadecimal form of `writing:Draft` diff --git a/openspec/changes/skills-marketplaces/specs/skills-site/spec.md b/openspec/changes/skills-marketplaces/specs/skills-site/spec.md new file mode 100644 index 0000000..d03daf1 --- /dev/null +++ b/openspec/changes/skills-marketplaces/specs/skills-site/spec.md @@ -0,0 +1,12 @@ +## ADDED Requirements + +### Requirement: Plugin on skills pages +The page of a skill, playbook or agent of a plugin SHALL show the plugin and the marketplace after the kind, and the lists and the Skills list SHALL name it by its qualified name; its URL SHALL be `/--/`, as the map's page file name says. Two agents with one plain name in different plugins SHALL have two pages. An item of a loose folder SHALL show neither. + +#### Scenario: Agents with one name +- **WHEN** the plugins `writing` and `review` each hold the agent `reviewer` +- **THEN** `/agents/writing--reviewer/` and `/agents/review--reviewer/` exist and each shows its plugin + +#### Scenario: Loose skill +- **WHEN** a skill comes from a loose folder +- **THEN** its page shows no plugin or marketplace diff --git a/openspec/changes/skills-marketplaces/tasks.md b/openspec/changes/skills-marketplaces/tasks.md new file mode 100644 index 0000000..fade37d --- /dev/null +++ b/openspec/changes/skills-marketplaces/tasks.md @@ -0,0 +1,23 @@ +## 1. Code + +- [ ] 1.1 `src/skills/resolve.ts`: the name index and the resolution order (own plugin, exact, only plugin item, ambiguous). Check: `npx vitest run test/unit/skills-resolve.test.ts` (scenarios of Name resolution). +- [ ] 1.2 `src/skills/marketplace.ts`: read and check `marketplace.json` and `plugin.json` (bounded read, secret rules, name and source rules, 500 plugins). `src/skills/walk.ts`: recognise a marketplace root at the top of a given folder, walk each plugin's `skills` and `agents` below its path with the same code and the ignore file, record plugin and marketplace on each found item, skip remote plugins with a warning. Check: `npx vitest run test/unit/skills-marketplace.test.ts`. +- [ ] 1.3 `src/skills/source.ts`: qualified names, `plain`, `plugin` and `marketplace` on skills and agents, uniqueness per plugin, resolved relations and preloads, ambiguity. `src/skills/lines.ts`, `metro.ts`: resolved references and zones. Check: `npx vitest run test/unit/skills-*.test.ts`. +- [ ] 1.4 `src/skills/graph.ts`, `mermaid.ts`: plugin and marketplace on nodes and item pages, `plugin--name` page file names. `src/site/skills-data.ts` and `site/src/components/SkillItem.astro`: plugin line on pages. Check: `npx vitest run test/unit/skills-map.test.ts test/unit/site-skills-data.test.ts`. + +## 2. Tests and documentation + +- [ ] 2.1 One test per scenario, named after it. The fixture is a fictitious marketplace, `examples/northwind-marketplace/` (two plugins, a same-named agent in both, a remote plugin), built in temporary folders for unit tests. +- [ ] 2.2 Integration and browser tests: `skills validate`, `skills map --check` and `build --skills` on the example marketplace; a site page of each same-named agent. +- [ ] 2.3 `docs/skills.md`, `README.md`, `AGENTS.md`, `docs/architecture.md` (module map) and `docs/roadmap.md` (row delivered). Check: `npx vitest run test/integration/docs.test.ts`. + +## 3. Integration + +- [ ] 3.1 Full suite. Check: `npm run build && npm test && npm run test:browser`. + +| Capability | Scenarios | Test file | +|---|---|---| +| skill-source | Marketplace root, Marketplace manifest, Plugin sources, Plugin contents, Qualified names, Same name in two plugins | test/unit/skills-marketplace.test.ts | +| skill-source | Name resolution, Declared relations, Preloaded skills, Skill references, Playbook zones | test/unit/skills-resolve.test.ts | +| skills-map-command | Plugin on item pages, Page file names | test/unit/skills-map.test.ts | +| skills-site | Plugin on skills pages | test/integration/site-skills.test.ts | From 9b54ec824bf08455315424f8cf007b39a317b618 Mon Sep 17 00:00:00 2001 From: brunosouzas-agent Date: Sun, 6 Dec 2026 07:11:29 +0000 Subject: [PATCH 2/3] feat: read Claude Code plugin marketplaces as skill sets Co-Authored-By: Claude Sonnet 5.5 --- AGENTS.md | 2 +- README.md | 4 +- docs/architecture.md | 4 +- docs/roadmap.md | 2 +- docs/skills.md | 20 +- .../.claude-plugin/marketplace.json | 9 + examples/northwind-marketplace/README.md | 7 + .../plugins/review/agents/reviewer.md | 10 + .../plugins/review/skills/checklist/SKILL.md | 8 + .../writing/.claude-plugin/plugin.json | 1 + .../plugins/writing/agents/reviewer.md | 10 + .../plugins/writing/skills/draft/SKILL.md | 8 + .../plugins/writing/skills/publish/SKILL.md | 12 + .../changes/skills-marketplaces/proposal.md | 8 +- .../specs/build-command/spec.md | 32 +++ .../specs/skill-source/spec.md | 207 ++++++++++++---- .../specs/skills-map-command/spec.md | 56 ++++- openspec/changes/skills-marketplaces/tasks.md | 25 +- site/src/components/SkillItem.astro | 5 + src/site/skills-build.ts | 6 +- src/site/skills-data.ts | 3 + src/skills/graph.ts | 9 +- src/skills/lines.ts | 36 ++- src/skills/map-command.ts | 5 + src/skills/marketplace.ts | 129 ++++++++++ src/skills/mermaid.ts | 10 +- src/skills/metro.ts | 7 +- src/skills/resolve.ts | 53 ++++ src/skills/source.ts | 85 ++++--- src/skills/walk.ts | 63 ++++- test/browser/serve.mjs | 7 +- test/browser/site-skills.spec.ts | 12 + test/integration/skills-marketplace.test.ts | 64 +++++ test/unit/skills-marketplace-map.test.ts | 43 ++++ test/unit/skills-marketplace.test.ts | 226 ++++++++++++++++++ test/unit/skills-offline.test.ts | 4 +- test/unit/skills-relations.test.ts | 2 +- test/unit/skills-resolve.test.ts | 109 +++++++++ 38 files changed, 1167 insertions(+), 136 deletions(-) create mode 100644 examples/northwind-marketplace/.claude-plugin/marketplace.json create mode 100644 examples/northwind-marketplace/README.md create mode 100644 examples/northwind-marketplace/plugins/review/agents/reviewer.md create mode 100644 examples/northwind-marketplace/plugins/review/skills/checklist/SKILL.md create mode 100644 examples/northwind-marketplace/plugins/writing/.claude-plugin/plugin.json create mode 100644 examples/northwind-marketplace/plugins/writing/agents/reviewer.md create mode 100644 examples/northwind-marketplace/plugins/writing/skills/draft/SKILL.md create mode 100644 examples/northwind-marketplace/plugins/writing/skills/publish/SKILL.md create mode 100644 openspec/changes/skills-marketplaces/specs/build-command/spec.md create mode 100644 src/skills/marketplace.ts create mode 100644 src/skills/resolve.ts create mode 100644 test/integration/skills-marketplace.test.ts create mode 100644 test/unit/skills-marketplace-map.test.ts create mode 100644 test/unit/skills-marketplace.test.ts create mode 100644 test/unit/skills-resolve.test.ts diff --git a/AGENTS.md b/AGENTS.md index ebeb4e8..5f35a42 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -10,7 +10,7 @@ Model: 2 release PR Integration branch: `main` Deliver and verify: a merge into `main` publishes nothing; release-please keeps the release pull request, Bruno merges it, and `release.yml` publishes after he approves the `npm` environment (`docs/release.md`); verify with `npm view @brunosouzas/stackledger version` -Implemented: the catalogue format and `stackledger validate` (`catalogue-model`), the SVG map engine and `stackledger map` (`metro-map-engine`), the read-only MCP server with the `full` and `staff` views (`mcp-server`), `stackledger build` with the static `full` and `staff` sites (`catalogue-site`), the licence report: `stackledger report`, the Reports page and `renewals.ics` of the `full` site (`licence-reports`), and Mac discovery: `stackledger discover`, `stackledger drift` with `--scaffold` and the `stackledger/` annotations (`mac-discovery`), and `stackledger skills validate`, which reads and checks a set of agent skills, playbooks, agents and rules (`skills-source`, code in `src/skills/`), skipping what a `.stackledgerignore` file at the top of a given folder lists (`skills-ignore`, `src/skills/ignore.ts`), and `stackledger skills map`, which writes Markdown pages with Mermaid diagrams of the set's declared relations into a folder it owns, with `--check` for pipelines (`skills-mermaid`, `src/skills/graph.ts`, `mermaid.ts`, `map-command.ts`), and the Skills section of `stackledger build` with `--skills` and `spec.skills.folders`: the skills map file `stackledger-skills.yaml` (`src/skills/lines.ts`), the skills metro map with playbook zones (`src/skills/metro.ts`), the relation diagram (`src/map/relations.ts`), the page data (`src/site/skills-data.ts`, `skills-build.ts`) and the Astro pages under `site/src/pages/{skills,skill-map,rules,playbooks,agents}/` (`skills-site`), and station labels that wrap instead of being cut, with the rule count on skills stations (`station-labels-and-rules`, `src/map/labels.ts`, `layout.ts`), and the home page at `/` with the map at `/map/`, the default title `stackledger` and `spec.site.home` (`site-home`, `site/src/pages/index.astro`, `src/site/relative.ts` for the home links' exemption), and the city backdrop of the software map: `spec.map.backdrop` and `stackledger map --backdrop`, `neutral` or `london`, its OpenStreetMap credit in the SVG and under the site's map frame (`map-backgrounds`, `src/map/backdrops/` generated by `scripts/backdrops/`, `src/map/svg.ts`, colours from the design system's `backdrop` tokens in `src/map/themes.ts`). The publishable npm package, owner-approved release workflow, catalogue repository pipeline template and protected hosting recipes (`catalogue-deployment`) are implemented. Released on npm: 0.1.0 to 0.4.0 as `stackledger` (deprecated), 0.4.1 as `@brunosouzas/stackledger` (the same code under the npm organisation's scope; the command stays `stackledger`), 0.5.0, with the identity of `@brunosouzas/design-system`, since renamed `@brunosouzas/signwright` (`design-system-identity`, `home-banner`, `design-system-pieces`, `round-bends`), 0.5.1, with maps never shown larger than drawn (`map-scale`) and the design system 0.4.0, 0.6.0, with the city backdrop of the software map (`map-backgrounds`) and the design system 0.5.3, and 0.7.0, with the script of interpreter jobs (`launchd-script`) and the helpers apps declare (`app-helpers`), and 0.8.0, with the identity v2 on design system 0.8.1 (`identity-v2`); the fictitious demo is rebuilt by hand following `docs/demo.md`. Where the identity v2 lives: Source fonts through Astro's Fonts API with the local provider (`src/site/build.ts`), its build-time font server bound to loopback (`src/site/loopback.ts`), the font CSS moved into `_astro/fonts.css` before the scan (`moveFontCss` in `src/site/relative.ts`), stackledger's accent, the outline frame, the map's `color.state.*` colours and quoted `font.sans` stack (`src/map/themes.ts`, `src/map/xml.ts`), the wordmark, the footer endorsement and the redrawn art (`scripts/site-art.mjs`). The rest of the roadmap is not implemented: say so instead of describing files that do not exist. +Implemented: the catalogue format and `stackledger validate` (`catalogue-model`), the SVG map engine and `stackledger map` (`metro-map-engine`), the read-only MCP server with the `full` and `staff` views (`mcp-server`), `stackledger build` with the static `full` and `staff` sites (`catalogue-site`), the licence report: `stackledger report`, the Reports page and `renewals.ics` of the `full` site (`licence-reports`), and Mac discovery: `stackledger discover`, `stackledger drift` with `--scaffold` and the `stackledger/` annotations (`mac-discovery`), and `stackledger skills validate`, which reads and checks a set of agent skills, playbooks, agents and rules (`skills-source`, code in `src/skills/`), skipping what a `.stackledgerignore` file at the top of a given folder lists (`skills-ignore`, `src/skills/ignore.ts`), and `stackledger skills map`, which writes Markdown pages with Mermaid diagrams of the set's declared relations into a folder it owns, with `--check` for pipelines (`skills-mermaid`, `src/skills/graph.ts`, `mermaid.ts`, `map-command.ts`), and the Skills section of `stackledger build` with `--skills` and `spec.skills.folders`: the skills map file `stackledger-skills.yaml` (`src/skills/lines.ts`), the skills metro map with playbook zones (`src/skills/metro.ts`), the relation diagram (`src/map/relations.ts`), the page data (`src/site/skills-data.ts`, `skills-build.ts`) and the Astro pages under `site/src/pages/{skills,skill-map,rules,playbooks,agents}/` (`skills-site`), and station labels that wrap instead of being cut, with the rule count on skills stations (`station-labels-and-rules`, `src/map/labels.ts`, `layout.ts`), and the home page at `/` with the map at `/map/`, the default title `stackledger` and `spec.site.home` (`site-home`, `site/src/pages/index.astro`, `src/site/relative.ts` for the home links' exemption), and the city backdrop of the software map: `spec.map.backdrop` and `stackledger map --backdrop`, `neutral` or `london`, its OpenStreetMap credit in the SVG and under the site's map frame (`map-backgrounds`, `src/map/backdrops/` generated by `scripts/backdrops/`, `src/map/svg.ts`, colours from the design system's `backdrop` tokens in `src/map/themes.ts`). The publishable npm package, owner-approved release workflow, catalogue repository pipeline template and protected hosting recipes (`catalogue-deployment`) are implemented. Released on npm: 0.1.0 to 0.4.0 as `stackledger` (deprecated), 0.4.1 as `@brunosouzas/stackledger` (the same code under the npm organisation's scope; the command stays `stackledger`), 0.5.0, with the identity of `@brunosouzas/design-system`, since renamed `@brunosouzas/signwright` (`design-system-identity`, `home-banner`, `design-system-pieces`, `round-bends`), 0.5.1, with maps never shown larger than drawn (`map-scale`) and the design system 0.4.0, 0.6.0, with the city backdrop of the software map (`map-backgrounds`) and the design system 0.5.3, and 0.7.0, with the script of interpreter jobs (`launchd-script`) and the helpers apps declare (`app-helpers`), and 0.8.0, with the identity v2 on design system 0.8.1 (`identity-v2`); the fictitious demo is rebuilt by hand following `docs/demo.md`. Where the identity v2 lives: Source fonts through Astro's Fonts API with the local provider (`src/site/build.ts`), its build-time font server bound to loopback (`src/site/loopback.ts`), the font CSS moved into `_astro/fonts.css` before the scan (`moveFontCss` in `src/site/relative.ts`), stackledger's accent, the outline frame, the map's `color.state.*` colours and quoted `font.sans` stack (`src/map/themes.ts`, `src/map/xml.ts`), the wordmark, the footer endorsement and the redrawn art (`scripts/site-art.mjs`). and reading Claude Code plugin marketplaces: a given folder with `.claude-plugin/marketplace.json` is read through its plugins, items are named `plugin:name`, plain names resolve by plugin first, remote plugins are skipped with a warning (`skills-marketplaces`, `src/skills/marketplace.ts`, `resolve.ts`, `examples/northwind-marketplace/`). The rest of the roadmap is not implemented: say so instead of describing files that do not exist. Layout: `src/` the CLI and its modules (`src/map/` map engine and diagrams, `src/site/` site data, build, publication, `src/discovery/` the Mac sources, sandboxed runner and snapshot); `site/` the Astro project shipped in the package and copied into the build's staging folder; `test/unit`, `test/integration` (vitest) and `test/browser` (Playwright); `examples/northwind/` the fictitious example catalogue and `examples/northwind-machine/` its fictitious Mac snapshot, `examples/northwind-skills/` a fictitious skill set with a skills map file. diff --git a/README.md b/README.md index aca8897..c9f8463 100644 --- a/README.md +++ b/README.md @@ -62,7 +62,7 @@ The diagram as Mermaid, and the personal and corporate modes: [docs/how-it-works 4. **The website is static.** No server, no database, nothing to patch. Why: [ADR 5](docs/adr/0005-static-site-no-server.md). 5. **It is written in TypeScript**, so the same map engine runs at build time and in the browser. Why: [ADR 9](docs/adr/0009-typescript-end-to-end.md). 6. **Agent skills are a second ledger in the same tool.** The skills, agents, playbooks and rules your AI agents use are read from their own folders, never copied into YAML. `stackledger skills validate` checks them, `stackledger skills map` draws them in the skills repository, and since 0.3.0 the site has a Skills section next to Software; linking each skill to the software it needs is planned. Why: [ADR 10](docs/adr/0010-agent-skills-are-a-second-ledger-read-from-their-folders.md). -7. **Planned: skills from plugin marketplaces and several maps.** [ADR 11](docs/adr/0011-skills-are-read-from-plugin-marketplaces.md) adds reading plugin marketplaces and skills map lines that are journeys; [ADR 12](docs/adr/0012-several-named-maps-and-stations-of-any-kind.md) adds several named maps. Neither is built; see the [roadmap](docs/roadmap.md#v21-one-site-marketplaces-journeys-and-named-maps). +7. **Skills from plugin marketplaces; journeys and several maps are planned.** A Claude Code plugin marketplace is read as one set, items named `plugin:skill` ([ADR 11](docs/adr/0011-skills-are-read-from-plugin-marketplaces.md)); skills map lines that are journeys are planned, and [ADR 12](docs/adr/0012-several-named-maps-and-stations-of-any-kind.md) adds several named maps. Those are not built; see the [roadmap](docs/roadmap.md#v21-one-site-marketplaces-journeys-and-named-maps). 8. **It looks like brunosouzas.com, with an identity of its own.** The map, the diagrams, the favicon and the site's colours come from [`@brunosouzas/signwright`](https://www.npmjs.com/package/@brunosouzas/signwright), a dependency of the published package; stackledger keeps the layout and writes every piece through its own SVG writer. On top of the family it has its own accent (a blue), its wordmark (the site title in Source Serif 4 italic), its mark (a ledger page) and the parent brand's endorsement in the footer. The fonts are the site's: Source Sans 3, Source Serif 4 and Source Code Pro, shipped in the package and delivered by Astro's Fonts API, so no font is fetched from another site. See [the map](docs/map.md#routes-and-themes) and [the site](docs/site.md). The context, the main flows and the module map are in [the architecture](docs/architecture.md). @@ -242,6 +242,8 @@ spec: `stackledger skills validate` checks agent skills (folders with a `SKILL.md`, in the [Agent Skills format](https://agentskills.io/specification)), playbooks, agents (`agents/*.md`, the Claude Code subagent format) and `rules.md` files as one set: duplicate names, a playbook naming a skill that does not exist, a rule ID defined twice, departures from the specification, and private keys or card numbers. Relations are declared inside the specification's `metadata` field, so `SKILL.md` stays valid for every tool: +Pointed at a Claude Code plugin marketplace root (a folder with `.claude-plugin/marketplace.json`), it reads every local plugin's skills and agents as one set, with items named `plugin:name`; remote plugins are skipped with a warning and nothing is fetched. See [Plugin marketplaces](docs/skills.md#plugin-marketplaces) and `examples/northwind-marketplace/`. + ```yaml metadata: stackledger-kind: playbook diff --git a/docs/architecture.md b/docs/architecture.md index 94eb9ca..8dcb6bd 100644 --- a/docs/architecture.md +++ b/docs/architecture.md @@ -100,7 +100,7 @@ Kept by hand: update it in the pull request that adds, moves or removes a module | `site/` | Astro project shipped in the package; its pages read the site data only | | `src/mcp.ts` | Read-only MCP server | | `src/discovery/`, `discover-command.ts`, `drift*.ts`, `scaffold.ts` | Read the Mac, write the snapshot, compare, draft entries | -| `src/skills/` | Read and check a skill set, its map files, Mermaid pages and the skills metro model | +| `src/skills/` | Read and check a skill set (`marketplace.ts` reads a plugin marketplace's manifest, `resolve.ts` resolves plain and `plugin:name` names), its map files, Mermaid pages and the skills metro model | | `src/errors.ts`, `control.ts`, `stdout.ts` | Shared output handling | | `src/index.ts` | Library entry | | `scripts/` | Release steps, backdrop data and the repository art | @@ -123,4 +123,4 @@ Status is in the [ADR index](adr/README.md). - [ADR 8](adr/0008-read-only-mcp-early-no-ai-in-the-core.md): a read-only MCP server and no AI model in the core. - [ADR 9](adr/0009-typescript-end-to-end.md): TypeScript end to end. - [ADR 10](adr/0010-agent-skills-are-a-second-ledger-read-from-their-folders.md): agent skills are a second ledger in the same tool. -- [ADR 11](adr/0011-skills-are-read-from-plugin-marketplaces.md), [ADR 12](adr/0012-several-named-maps-and-stations-of-any-kind.md) and [ADR 13](adr/0013-one-private-site-at-the-root.md): planned, not built; see the [roadmap](roadmap.md). +- [ADR 11](adr/0011-skills-are-read-from-plugin-marketplaces.md): plugin marketplaces are read (`skills-marketplaces`); its journeys and zones are planned. [ADR 12](adr/0012-several-named-maps-and-stations-of-any-kind.md) and [ADR 13](adr/0013-one-private-site-at-the-root.md): planned, not built; see the [roadmap](roadmap.md). diff --git a/docs/roadmap.md b/docs/roadmap.md index 5e7faa7..9ab983a 100644 --- a/docs/roadmap.md +++ b/docs/roadmap.md @@ -49,7 +49,7 @@ Decided on 2026-12-05 by [ADR 11](adr/0011-skills-are-read-from-plugin-marketpla | # | Change | Delivers | Status | |---|---|---|---| | 1 | `single-site` | One private site served at the root, with no `full`/`staff` split and no `/full/` or `/staff/` paths; whoever has access sees everything, licences included; the `staff` view stays in the code, deprecated and not built into a reachable address; old `/full/` links redirect to the root; the hosting recipes and pipeline template follow, and the Access application covering the root must allow only people who may see everything before the first deploy ([ADR 13](adr/0013-one-private-site-at-the-root.md)) | Planned (SW-345) | -| 2 | `skills-marketplaces` | Reading Claude Code plugin marketplaces (`marketplace.json`, each plugin's `skills/` and `agents/`), names as `plugin:skill`, same-named agents of two plugins both kept; loose folders keep working ([ADR 11](adr/0011-skills-are-read-from-plugin-marketplaces.md)) | Planned (SW-346) | +| 2 | `skills-marketplaces` | Reading Claude Code plugin marketplaces (`marketplace.json`, each plugin's `skills/` and `agents/`), names as `plugin:skill`, same-named agents of two plugins both kept; loose folders keep working ([ADR 11](adr/0011-skills-are-read-from-plugin-marketplaces.md)) | Delivered in [#65](https://github.com/brunosouzas/stackledger/pull/65) | | 3 | `skill-journeys` | Skills map lines are journeys (kinds of work) without playbooks as zones; zones are marketplaces, and skills outside one get a zone of their own; shared skills and agents show as interchanges; the skills map file may live in the catalogue repository | Planned (SW-347) | | 4 | `project-journeys` | A project component declares the journeys it follows (the annotation key is set by the spec); a per-project view computed from the journeys | Planned (SW-348) | | 5 | `named-maps` | Several named maps in one catalogue, and a station that may be software or a skill; `validate` must then know about skills; the first use is a map of a product family ([ADR 12](adr/0012-several-named-maps-and-stations-of-any-kind.md)) | Planned (SW-349) | diff --git a/docs/skills.md b/docs/skills.md index f7487fa..288f062 100644 --- a/docs/skills.md +++ b/docs/skills.md @@ -1,6 +1,6 @@ # Agent skills -> **Planned, not built:** [ADR 11](adr/0011-skills-are-read-from-plugin-marketplaces.md) adds reading plugin marketplaces (`plugin:skill`), skills map lines that are journeys, marketplaces as zones, and projects that declare the journeys they follow (changes `skills-marketplaces`, `skill-journeys` and `project-journeys`). This page describes what is built today: folders, with playbooks as zones. +> **Partly planned:** [ADR 11](adr/0011-skills-are-read-from-plugin-marketplaces.md) also adds skills map lines that are journeys, marketplaces as zones, and projects that declare the journeys they follow (changes `skill-journeys` and `project-journeys`); those are not built. Reading plugin marketplaces (`skills-marketplaces`) is: see [Plugin marketplaces](#plugin-marketplaces). The skills map still has playbooks as zones. `stackledger skills validate` checks a set of agent skills, playbooks, agents and rules kept in folders: what one agent would see. It reports problems in the same line format as `stackledger validate`, so a person can run it on their own folders and a team can run it in CI on every pull request. It only reads files: it writes nothing, makes no network call and fixes nothing. @@ -16,7 +16,7 @@ With no folder it checks the current folder. Several folders are read as one set - **Skills.** Any folder holding a file named exactly `SKILL.md`, in the [Agent Skills format](https://agentskills.io/specification): a YAML frontmatter between two `---` lines, with `name` and `description`. Each given folder is walked at most five levels deep, entries in code-point order; the walk does not enter a skill folder (its sub-folders are the skill's resources), and skips folders whose name starts with `.` and `node_modules`. A given folder that is itself a skill folder gives that one skill. - **Playbooks.** Skills with `stackledger-kind: playbook` in their `metadata`: a skill that orchestrates other skills and agents. -- **Agents.** Each `.md` file directly in an `agents/` folder at the top of a given folder, in the Claude Code subagent format (frontmatter with `name`, `description`, and optionally `skills`, `tools`, `model`…). A file there without frontmatter, such as a `README.md`, gets a warning and is not an agent. +- **Agents.** Each `.md` file directly in an `agents/` folder at the top of a given folder (or in a plugin's `agents/`, see [Plugin marketplaces](#plugin-marketplaces)), in the Claude Code subagent format (frontmatter with `name`, `description`, and optionally `skills`, `tools`, `model`…). A file there without frontmatter, such as a `README.md`, gets a warning and is not an agent. - **Rules.** An optional `rules.md` next to a `SKILL.md`. A rule is a line starting at column 1 with `- **ID** text`, the ID like `DOC-1`; indented `Why:` and `Check:` lines after it are its reason and check, and the nearest earlier `## ` heading is its group. Lines inside fenced code blocks are never rules. ```markdown @@ -39,6 +39,22 @@ Give the folders one agent loads together, for example a repository and the tool Point the command at folders that hold real skills. Templates, examples and deliberately broken test fixtures inside them are read like any skill unless an [ignore file](#ignore-file) skips them. +## Plugin marketplaces + +A Claude Code plugin marketplace is a Git repository (or a local folder) with `.claude-plugin/marketplace.json`, listing plugins by relative `source`; each plugin folder may hold `skills/`, `agents/` and `.claude-plugin/plugin.json`. Give the marketplace root to `skills validate`, `skills map` or `build --skills` (or list it in `spec.skills.folders`) and every plugin's skills and agents are read as one set, with no loop per plugin: + +```sh +stackledger skills validate examples/northwind-marketplace +``` + +- **How a folder is recognised.** A given folder that is not itself a skill folder and holds a regular file `.claude-plugin/marketplace.json` is a marketplace root. It is read only through its plugins; its other folders (templates, docs) are not walked. Any other folder is a loose folder, read as before, and the two kinds can be given together. +- **Local plugins.** An entry `{ "name": "writing", "source": "./plugins/writing" }` reads `plugins/writing/skills/` (walked like a given folder) and the `.md` files of `plugins/writing/agents/`. The source must start with `./` and stay inside the marketplace, links included; `./` alone makes the root the plugin. Plugin names are lowercase letters, digits and hyphens, and so is the marketplace name. Plugins are read in manifest order. A `plugin.json` whose `name` differs from the entry gives a warning; the entry's name is used. +- **Remote plugins.** An entry whose `source` is an object (GitHub repository, Git URL, npm package) is skipped with a warning that names it. stackledger makes no network call and never reads what is installed on a machine, so a marketplace that mixes local and remote plugins still passes CI; to read a remote plugin, check its repository out and give that folder. +- **Qualified names.** An item of a plugin is named `plugin:name` (`writing:draft`, `review:reviewer`) and records its plugin and marketplace; the pages, lists and diagrams show the qualified name, and the page also names the plugin and the marketplace. A loose item keeps its plain name. Names are unique per plugin, so agents (or skills) with one name in two plugins are both kept, each with its own page (`agents/writing--reviewer.md`, `/agents/writing--reviewer/`). +- **Writing a name.** In `stackledger-skills`, `stackledger-agents`, an agent's `skills`, a skills map file reference (`skill:writing:draft`) and a zone, a plain or a qualified name works. A plain name is looked up among the items of the kind the field names: first in the writer's own plugin, then an exact name (a loose item, or a qualified name), then the only plugin item with that name. When two plugins match, it is an error that lists them and asks for the qualified name (a warning in an agent's `skills`, which a tool only skips). A set of loose folders resolves exactly as before. +- **Ignore file and map file.** A `.stackledgerignore` and a `stackledger-skills.yaml` at the top of the marketplace root apply as in any given folder; patterns are relative to the root, so `plugins/legacy/` skips a plugin. Files inside a plugin have no effect. +- **Limits.** `marketplace.json` and `plugin.json` are limited to 1 MiB and go through the secret rules; a manifest lists at most 500 plugins. A marketplace with an invalid manifest gives that one error, not also "nothing found". + ## Ignore file A `.stackledgerignore` file lists, in `.gitignore` syntax, the entries the walk skips: a skipped folder is not entered, a skipped link is not followed, and a skipped skill folder or agent file is not read. diff --git a/examples/northwind-marketplace/.claude-plugin/marketplace.json b/examples/northwind-marketplace/.claude-plugin/marketplace.json new file mode 100644 index 0000000..9a18d55 --- /dev/null +++ b/examples/northwind-marketplace/.claude-plugin/marketplace.json @@ -0,0 +1,9 @@ +{ + "name": "northwind-skills", + "owner": { "name": "Northwind" }, + "plugins": [ + { "name": "writing", "source": "./plugins/writing", "description": "Fictitious writing plugin." }, + { "name": "review", "source": "./plugins/review", "description": "Fictitious review plugin." }, + { "name": "external", "source": { "source": "github", "repo": "northwind/external-plugin" }, "description": "Fictitious remote plugin; stackledger does not fetch it." } + ] +} diff --git a/examples/northwind-marketplace/README.md b/examples/northwind-marketplace/README.md new file mode 100644 index 0000000..465a5f1 --- /dev/null +++ b/examples/northwind-marketplace/README.md @@ -0,0 +1,7 @@ +# northwind-marketplace + +A fictitious Claude Code plugin marketplace for stackledger's documentation, tests and demo. Two plugins (`writing`, `review`) hold an agent with the same name, `reviewer`; a third entry has a remote source, which stackledger skips with a warning. Read it with: + +```sh +stackledger skills validate examples/northwind-marketplace +``` diff --git a/examples/northwind-marketplace/plugins/review/agents/reviewer.md b/examples/northwind-marketplace/plugins/review/agents/reviewer.md new file mode 100644 index 0000000..7193886 --- /dev/null +++ b/examples/northwind-marketplace/plugins/review/agents/reviewer.md @@ -0,0 +1,10 @@ +--- +name: reviewer +description: "Reviews a Northwind change with a clean context and reports findings." +tools: Read, Grep, Glob +model: sonnet +skills: + - checklist +--- + +You are the Northwind change reviewer. Fictitious example for stackledger. diff --git a/examples/northwind-marketplace/plugins/review/skills/checklist/SKILL.md b/examples/northwind-marketplace/plugins/review/skills/checklist/SKILL.md new file mode 100644 index 0000000..ad61b73 --- /dev/null +++ b/examples/northwind-marketplace/plugins/review/skills/checklist/SKILL.md @@ -0,0 +1,8 @@ +--- +name: checklist +description: "Checks a Northwind change against the review checklist." +--- + +# Checklist + +Fictitious example for stackledger. diff --git a/examples/northwind-marketplace/plugins/writing/.claude-plugin/plugin.json b/examples/northwind-marketplace/plugins/writing/.claude-plugin/plugin.json new file mode 100644 index 0000000..127e3d3 --- /dev/null +++ b/examples/northwind-marketplace/plugins/writing/.claude-plugin/plugin.json @@ -0,0 +1 @@ +{ "name": "writing", "description": "Fictitious writing plugin for stackledger." } diff --git a/examples/northwind-marketplace/plugins/writing/agents/reviewer.md b/examples/northwind-marketplace/plugins/writing/agents/reviewer.md new file mode 100644 index 0000000..d14904e --- /dev/null +++ b/examples/northwind-marketplace/plugins/writing/agents/reviewer.md @@ -0,0 +1,10 @@ +--- +name: reviewer +description: "Reads a Northwind draft for tone and clarity." +tools: Read, Grep, Glob +model: sonnet +skills: + - draft +--- + +You are the Northwind writing reviewer. Fictitious example for stackledger. diff --git a/examples/northwind-marketplace/plugins/writing/skills/draft/SKILL.md b/examples/northwind-marketplace/plugins/writing/skills/draft/SKILL.md new file mode 100644 index 0000000..90cad3b --- /dev/null +++ b/examples/northwind-marketplace/plugins/writing/skills/draft/SKILL.md @@ -0,0 +1,8 @@ +--- +name: draft +description: "Writes the first draft of a Northwind article." +--- + +# Draft + +Fictitious example for stackledger. diff --git a/examples/northwind-marketplace/plugins/writing/skills/publish/SKILL.md b/examples/northwind-marketplace/plugins/writing/skills/publish/SKILL.md new file mode 100644 index 0000000..6e5c6b8 --- /dev/null +++ b/examples/northwind-marketplace/plugins/writing/skills/publish/SKILL.md @@ -0,0 +1,12 @@ +--- +name: publish +description: "Publishes a Northwind article: drafts it, has it checked and reviewed." +metadata: + stackledger-kind: playbook + stackledger-skills: draft review:checklist + stackledger-agents: reviewer +--- + +# Publish + +Fictitious example for stackledger. `draft` is this plugin's skill; `review:checklist` is the qualified name of a skill of another plugin. diff --git a/openspec/changes/skills-marketplaces/proposal.md b/openspec/changes/skills-marketplaces/proposal.md index ba7d519..c5df861 100644 --- a/openspec/changes/skills-marketplaces/proposal.md +++ b/openspec/changes/skills-marketplaces/proposal.md @@ -18,13 +18,15 @@ None. ### Modified Capabilities - `skill-source`: marketplace roots, plugins, qualified names and their resolution, same-named items in two plugins. -- `skills-map-command`: page file names of qualified names, the plugin and marketplace on item pages. +- `skills-map-command`: page file names of qualified names, the plugin and marketplace on item pages, the output-folder guard for a plugin's `agents/`. +- `build-command`: the same output-folder guard. - `skills-site`: the plugin and marketplace on skill and agent pages. ## Out of scope - Zones by marketplace, journeys, interchanges and the skills map file in the catalogue repository (`skill-journeys`, SW-347); project journeys (SW-348); named maps (SW-349); the catalogue repository's pipeline (SW-350). Nothing is drawn differently on the metro map: stations carry the qualified name. -- Fetching anything: a remote plugin is never cloned or downloaded, and what a tool has installed (`~/.claude`, a plugin cache) is never read. +- Fetching anything: a remote plugin is never cloned or downloaded. stackledger never looks up what a tool has installed; a folder given explicitly is read wherever it is. +- Telling apart two marketplaces that hold a plugin with one name when given together: the identity has no marketplace part, so their items clash by name. - A plugin folder given directly (`plugins/`) stays a loose folder: its items have no plugin. - Plugin manifest fields other than the plugin's name (`plugin.json` paths for custom `skills` or `agents` folders, hooks, commands, MCP servers), `metadata.pluginRoot` and `strict: false` entries that carry their own components. - Reading skills a marketplace root holds outside its plugins. @@ -32,7 +34,7 @@ None. ## Implicit requirements - **Errors and invalid input:** requirement. A manifest that cannot be read or parsed, a plugin with a bad name or source, a source that leaves the marketplace, a missing plugin folder and a name clash are problems on their own path; the rest of the set is still read. -- **Limits:** requirement. `marketplace.json` and `plugin.json` share the 1 MiB file limit; a manifest lists at most 500 plugins. +- **Limits:** requirement. `marketplace.json` and `plugin.json` share the 1 MiB file limit; a manifest lists at most 500 plugins; names are lowercase letters, digits and hyphens. - **Repetition and idempotency:** requirement. The same files give the same output; a plugin folder listed twice is read once. - **Concurrency:** n/a: one read-only process. - **Security:** requirement. Manifests go through the secret rules like every file; a `source` is never followed outside the marketplace root (lexically or through links); remote sources are not contacted. diff --git a/openspec/changes/skills-marketplaces/specs/build-command/spec.md b/openspec/changes/skills-marketplaces/specs/build-command/spec.md new file mode 100644 index 0000000..6dc6911 --- /dev/null +++ b/openspec/changes/skills-marketplaces/specs/build-command/spec.md @@ -0,0 +1,32 @@ +## MODIFIED Requirements + +### Requirement: Output folder and the skill set +After resolving symbolic links, the output folder SHALL also be refused, with exit 2 and no change, when it is or contains a skills folder or the real path of any skill folder, agent file or file read of the set (rejected ones, ignore files and the skills map file included), or is inside such a skill folder or the folder an agent file was read from (a skills folder's top-level `agents/`, or a plugin's); a marketplace manifest counts among the files read. Elsewhere inside a skills folder it is allowed, as for `skills map`. + +#### Scenario: Output inside a skill folder +- **WHEN** `--out` is `./skills/writer/site`, `./skills/writer/SKILL.md` exists and the command has `--skills ./skills` +- **THEN** the exit code is 2 and nothing is written + +#### Scenario: Output in the agents folder +- **WHEN** `--out` is `./skills/agents/site` and the command has `--skills ./skills` +- **THEN** the exit code is 2 and nothing is written + +#### Scenario: Output contains the skills folder +- **WHEN** `--out` is `./public`, an empty folder, and the command has `--skills ./public/skills`, a folder holding skills +- **THEN** the exit code is 2 and nothing is written + +#### Scenario: Output holds a linked input +- **WHEN** an earlier build exists in `public`, and `skills/writer/rules.md` is a link to `public/full/notes.md` +- **THEN** the command with `--skills skills --out public` exits 2 and `public/full/notes.md` is unchanged + +#### Scenario: Building inside the skills repository +- **WHEN** the command runs at the top of a repository holding `catalog/` and skills as `stackledger build catalog --skills . --out public`, and `public` does not exist +- **THEN** both sites are built into `public` and the exit code is 0 + +#### Scenario: Output inside a linked skill folder +- **WHEN** `tool/writer` links to `kit/skills/writer`, the command has `--skills tool`, and `--out` is `kit/skills/writer/site` +- **THEN** the exit code is 2 and nothing is written + +#### Scenario: Output in a plugin's agents folder +- **WHEN** `--skills` is a marketplace root and `--out` is `./plugins/review/agents/site`, where `plugins/review/agents/reviewer.md` was read +- **THEN** the exit code is 2 and nothing is written diff --git a/openspec/changes/skills-marketplaces/specs/skill-source/spec.md b/openspec/changes/skills-marketplaces/specs/skill-source/spec.md index 986d464..d0945b1 100644 --- a/openspec/changes/skills-marketplaces/specs/skill-source/spec.md +++ b/openspec/changes/skills-marketplaces/specs/skill-source/spec.md @@ -1,7 +1,7 @@ ## ADDED Requirements ### Requirement: Marketplace root -A given folder that is not a skill folder and holds a regular file (or a link to one) at `.claude-plugin/marketplace.json` SHALL be a marketplace root. A marketplace root SHALL be read only through the plugins its manifest lists: its other folders SHALL NOT be walked, and no `agents` folder at its top SHALL be read. `.stackledgerignore` and the skills map file at its top SHALL apply as in any given folder. A folder without that file SHALL be a loose folder, read as before. +A given folder that is not a skill folder and holds a regular file (or a link to one) at `.claude-plugin/marketplace.json` SHALL be a marketplace root. A marketplace root SHALL be read only through the plugins its manifest lists: its other folders SHALL NOT be walked, and no `agents` folder at its top SHALL be read, except as the `agents` folder of a plugin whose source is the root. A folder without that file SHALL be a loose folder, read as before. #### Scenario: Marketplace read as one set - **WHEN** the given folder holds `.claude-plugin/marketplace.json` listing `writing` at `./plugins/writing` and `review` at `./plugins/review`, and each holds `skills//SKILL.md` and `agents/.md` @@ -15,16 +15,34 @@ A given folder that is not a skill folder and holds a regular file (or a link to - **WHEN** a marketplace root holds `templates/skill/SKILL.md` that no plugin includes - **THEN** it is not read and there is no problem +### Requirement: Marketplace root files +`.stackledgerignore` and the skills map file at the top of a marketplace root SHALL apply as in any given folder. A marketplace root that gave no item and an error (an invalid manifest, say) SHALL NOT also be reported as a folder with nothing found. + #### Scenario: Ignore file - **WHEN** the root holds `.stackledgerignore` with `plugins/legacy/` - **THEN** the plugin at `./plugins/legacy` is not read and is counted as ignored ### Requirement: Marketplace manifest -`marketplace.json` SHALL be a JSON object with a non-empty string `name` and an array `plugins`; each plugin SHALL be an object with `name` and `source`. A file that is too large, unreadable, not valid JSON, holding a secret, or without `name` or `plugins` SHALL be an error on that file, and the marketplace SHALL give no plugins. +`marketplace.json` SHALL be a JSON object with a non-empty string `name` and an array `plugins`; each plugin SHALL be an object with `name` and `source`. The file SHALL be at most 1 MiB. A file that is too large, unreadable, not valid JSON, holding a secret, or without `name` or `plugins` SHALL be an error on that file, and the marketplace SHALL give no plugins. #### Scenario: Invalid manifest - **WHEN** `marketplace.json` is not valid JSON -- **THEN** there is one error on the file, and nothing else is read from that folder +- **THEN** there is exactly one problem, an error on the file, and no item is read + +#### Scenario: Manifest over the limit +- **WHEN** `marketplace.json` is 1 MiB and 1 byte +- **THEN** there is one error on the file saying it is larger than 1 MiB + +#### Scenario: Manifest with a secret +- **WHEN** the manifest holds a payment-card number +- **THEN** there is one error on the file and the number is in no message + +### Requirement: Manifest names and positions +The marketplace `name` SHALL be lowercase letters and digits with single hyphens between them, or the manifest SHALL be an error as an unusable one. Each problem of the manifest SHALL be at its path, `1:1`, with no field, and name the plugin where one is concerned. + +#### Scenario: Marketplace name that is not a name +- **WHEN** the manifest's name is `North wind ` +- **THEN** there is one error on the file and no plugin is read ### Requirement: Plugin entries A plugin name SHALL be lowercase letters and digits with single hyphens between them; a name used earlier in the manifest SHALL be an error on the later entry, which is not read. An entry without a string `name`, or with no `source`, SHALL be an error on it and be skipped. At most 500 entries SHALL be read, and each later one SHALL give one error. @@ -46,7 +64,7 @@ A plugin name SHALL be lowercase letters and digits with single hyphens between - **THEN** there is an error on it and the other entries are read ### Requirement: Plugin sources -A plugin whose `source` is a string SHALL name a folder of the marketplace: it SHALL start with `./`, stay inside the marketplace root once `..` segments are resolved and links followed, and name an existing folder. A string source that does not meet this, or a missing folder, SHALL be an error on the entry. +A plugin whose `source` is a string SHALL name a folder of the marketplace: it SHALL start with `./`, stay inside the marketplace root once `..` segments are resolved and links followed, and name an existing folder. A string source that does not meet this, a source of another type than string or object (an array or a number, say), or a missing folder, SHALL be an error on the entry. A plugin folder listed by two entries SHALL be read once, for the first entry, with no problem. #### Scenario: Source outside the marketplace - **WHEN** an entry has `source` `./../elsewhere`, or a link inside `plugins/` leads outside the root - **THEN** there is one error on the entry and nothing outside the root is read @@ -59,26 +77,34 @@ A plugin whose `source` is a string SHALL name a folder of the marketplace: it S - **WHEN** `source` is `./plugins/gone` and there is no such folder - **THEN** there is one error on the entry +#### Scenario: Same folder twice +- **WHEN** two entries have the source `./plugins/writing` +- **THEN** its items are read once, under the first entry's name, and there is no problem + +#### Scenario: Source of another type +- **WHEN** an entry has `source` `7` or `["./plugins/writing"]` +- **THEN** there is one error on the entry + #### Scenario: Root as the plugin - **WHEN** an entry has `source` `./` and the root holds `skills/writer/SKILL.md` - **THEN** `writer` is read as a skill of that plugin ### Requirement: Remote plugins -A plugin whose `source` is an object (a GitHub repository, a Git URL, an npm package) SHALL be skipped with one warning naming the plugin and saying it was not read; it SHALL never be fetched. A plugin folder listed by two entries SHALL be read once, for the first entry. +A plugin whose `source` is an object (a GitHub repository, a Git URL, an npm package) SHALL be skipped with one warning naming the plugin and saying it was not read; it SHALL never be fetched. #### Scenario: Remote plugin - **WHEN** an entry has `source` `{ "source": "github", "repo": "northwind/helper" }` - **THEN** there is one warning naming the plugin, no error, and no network call ### Requirement: Plugin contents -A plugin SHALL give the skills found below its `skills` folder, walked like a given folder (five levels, hidden entries and `node_modules` skipped, the walk not entering a skill folder), and the `.md` files directly in its `agents` folder, checked as agent files. A missing `skills` or `agents` folder SHALL give no problem. Each item SHALL record its plugin and its marketplace's name. +A plugin SHALL give the skills found below its `skills` folder, walked like a given folder (five levels below the `skills` folder, hidden entries and `node_modules` skipped, the walk not entering a skill folder). A `.stackledgerignore` or skills map file inside a plugin SHALL have no effect, and the `.md` files directly in its `agents` folder, checked as agent files. A missing `skills` or `agents` folder SHALL give no problem. Each item SHALL record its plugin and its marketplace's name. #### Scenario: Agents of a plugin - **WHEN** `plugins/review` holds `agents/reviewer.md` with a valid agent - **THEN** agent `review:reviewer` is in the set, with plugin `review` and the marketplace's name ### Requirement: Plugin manifest -When a plugin holds `.claude-plugin/plugin.json` with a string `name` different from the entry's, there SHALL be one warning on `plugin.json` and the entry's name SHALL be used. A `plugin.json` that cannot be read or parsed SHALL be one warning. A plugin that gives no skill and no agent SHALL give one warning. +When a plugin holds `.claude-plugin/plugin.json` with a string `name` different from the entry's, there SHALL be one warning on `plugin.json` and the entry's name SHALL be used. A `plugin.json` over 1 MiB, unreadable or not valid JSON SHALL be one warning; one holding a secret SHALL be an error and the value SHALL be in no message. A plugin that gives no skill and no agent SHALL give one warning, on the plugin folder's path. #### Scenario: Name differs in plugin.json - **WHEN** the entry is `review` and `plugins/review/.claude-plugin/plugin.json` has `name` `code-review` @@ -95,8 +121,12 @@ An item of a plugin SHALL be named `:`, where `` is its fron - **WHEN** a plugin's skill `writer` lists a skill that is not in the set - **THEN** the error is on the plugin skill's `SKILL.md` and names the missing target as written +#### Scenario: Qualified name of an item in a message +- **WHEN** a plugin's `agents/a.md` and `agents/b.md` both have `name: reviewer` +- **THEN** the error on `agents/b.md` names `writing:reviewer` + ### Requirement: Name resolution -A name written in `stackledger-skills`, `stackledger-agents`, an agent's `skills`, a skills map file reference or a zone SHALL be resolved in this order: (1) when the writer is an item of a plugin, that plugin's item with that plain name; (2) the item whose qualified name equals the text exactly, which also finds a loose item; (3) the only plugin item with that plain name. When nothing matches, the existing missing-item problem SHALL be given. +A name written in `stackledger-skills`, `stackledger-agents`, an agent's `skills`, a skills map file reference or a zone SHALL be resolved only among the items of the kind it names (skills and playbooks, agents, or playbooks for a zone), in this order: (1) when the writer is an item of a plugin, that plugin's item with that plain name; (2) the item whose qualified name equals the text exactly, which also finds a loose item; (3) the only plugin item with that plain name. #### Scenario: Own plugin first - **WHEN** skills `writing:draft` and `review:draft` exist and `writing:publish` lists `draft` @@ -110,12 +140,16 @@ A name written in `stackledger-skills`, `stackledger-agents`, an agent's `skills - **WHEN** a loose playbook lists `review:draft` - **THEN** it resolves to `review:draft`, whatever other items are named `draft` +#### Scenario: Only the kind named +- **WHEN** `review:reviewer` is an agent, `writing:reviewer` is the only skill of that name, and `review:x` lists `reviewer` in `stackledger-skills` +- **THEN** it resolves to `writing:reviewer` with no problem + #### Scenario: Loose item wins over plugin items - **WHEN** a loose skill `draft` and `writing:draft` exist and a loose playbook lists `draft` - **THEN** it resolves to the loose skill ### Requirement: Resolved relations -A resolved relation SHALL be stored under the qualified name, so `draft` and `writing:draft` written in one list are one relation and the repeat warning applies. +When nothing matches, the existing missing-item problem SHALL be given. A resolved relation SHALL be stored under the qualified name, so `draft` and `writing:draft` written in one list are one relation and the repeat warning applies. #### Scenario: Qualified and plain name of one item - **WHEN** a loose playbook lists `draft writing:draft` and `writing:draft` is the only `draft` @@ -133,7 +167,7 @@ When step 3 of "Name resolution" finds two or more items, the name SHALL be ambi - **THEN** there is one warning with field `skills[0]` and no error ### Requirement: Same name in two plugins -Names SHALL be unique per plugin: two skills (or two agents) of one plugin with the same name are the existing duplicate error. Items with the same plain name in different plugins SHALL all be kept, each under its qualified name. +Names SHALL be unique per plugin: two skills (or two agents) of one plugin with the same name are the existing duplicate error. Items with the same plain name in different plugins SHALL all be kept, each under its qualified name. A plugin name is not qualified by its marketplace: two marketplaces given together that hold a plugin with one name clash on its items' names. #### Scenario: Agents with one name in two plugins - **WHEN** `plugins/writing/agents/reviewer.md` and `plugins/review/agents/reviewer.md` both have `name: reviewer` @@ -143,6 +177,21 @@ Names SHALL be unique per plugin: two skills (or two agents) of one plugin with - **WHEN** one plugin holds `agents/a.md` and `agents/b.md`, both `name: reviewer` - **THEN** there is one error on the later file and one agent +### Requirement: Qualified references +The name in a skills map file reference (everything after the kind and its `:`) SHALL be resolved as in "Name resolution", so a qualified name is written `skill:plugin:name`. A stop and a station key that resolve to one item SHALL be the same station, and a name that is ambiguous SHALL be an error at it that names every match. + +#### Scenario: Qualified stop +- **WHEN** a stop is `agent:review:reviewer` and the set has `review:reviewer` and `writing:reviewer` +- **THEN** there is no problem and the stop is `review:reviewer` + +#### Scenario: Ambiguous plain stop +- **WHEN** a stop is `agent:reviewer` and the set has `review:reviewer` and `writing:reviewer` +- **THEN** there is one error on that stop naming both + +#### Scenario: Plain and qualified stops of one item +- **WHEN** a line stops at `skill:draft` and then at `skill:writing:draft`, and `writing:draft` is the only `draft` +- **THEN** there is an error on the second stop saying the item is visited more than once + ## MODIFIED Requirements ### Requirement: Declared relations @@ -186,45 +235,6 @@ A skill or playbook whose name is already used by an earlier skill or playbook o - **WHEN** `agents/review.md` and `agents/reviewer.md` both have `name: reviewer` - **THEN** there is one error on `agents/reviewer.md` -### Requirement: Skill references -In a skills map file, each stop and each `MapLayout` station key SHALL be `skill:`, `playbook:` or `agent:`, the kind in lower case and the name being everything after the first `:`, which SHALL be resolved as in "Name resolution" (a qualified name is `skill:plugin:name`), and SHALL name an item of that kind in the set; otherwise it SHALL be an error at it, naming it and, when an item of another kind has that name, its kind. A stop with an error is not a stop of the drawn map. A stop and a station key that resolve to one item SHALL be the same station. - -#### Scenario: Missing stop -- **WHEN** a line's second stop is `skill:editr` and the set has no `editr` -- **THEN** there is one error with field `spec.stops[1]` naming `editr` - -#### Scenario: Wrong kind -- **WHEN** a stop is `skill:release` and `release` is a playbook -- **THEN** there is an error on that stop saying `release` is a playbook, and the skills map has no station for it on that line - -#### Scenario: Kind in another case -- **WHEN** a stop is `Skill:writer` and the set has the skill `writer` -- **THEN** there is an error on that stop - -#### Scenario: Software reference -- **WHEN** a stop is `component:editor` -- **THEN** there is an error on that stop - -#### Scenario: Agent station -- **WHEN** a line stops at `agent:reviewer` and the layout places `agent:reviewer` at `[2, 0]`, and the set has the agent `reviewer` -- **THEN** there is no problem - -#### Scenario: Stop excluded by an error -- **WHEN** a line stops at `skill:editor` and `editor`'s `SKILL.md` has no frontmatter -- **THEN** there is an error on that stop, besides the error on `editor`'s file - -#### Scenario: Qualified stop -- **WHEN** a stop is `agent:review:reviewer` and the set has `review:reviewer` and `writing:reviewer` -- **THEN** there is no problem and the stop is `review:reviewer` - -#### Scenario: Ambiguous plain stop -- **WHEN** a stop is `agent:reviewer` and the set has `review:reviewer` and `writing:reviewer` -- **THEN** there is one error on that stop naming both - -#### Scenario: Plain and qualified stops of one item -- **WHEN** a line stops at `skill:draft` and then at `skill:writing:draft`, and `writing:draft` is the only `draft` -- **THEN** there is an error on the second stop saying the item is visited more than once - ### Requirement: Playbook zones In a skills `MapLayout`, each zone of `spec.zones` (`name`, `title`, `color`, as in the catalogue) SHALL name a playbook of the set, resolved as in "Name resolution"; a name that is no playbook of the set SHALL be an error on that zone's `name`, a reference error like a missing station: the layout is still used and that zone has no member. The zone's members are the playbook and the skills, playbooks and agents its `stackledger-skills` and `stackledger-agents` name in the set. @@ -243,3 +253,102 @@ In a skills `MapLayout`, each zone of `spec.zones` (`name`, `title`, `color`, as #### Scenario: One skill in two zones - **WHEN** the playbooks `release` and `review` both load `writer` and both are zones - **THEN** `writer` is a member of both zones and there is no problem + +### Requirement: Finding skill folders +A folder holding a file named exactly `SKILL.md` SHALL be a skill folder. Each given folder SHALL be walked depth first, entries in code-point order of their names, at most five levels below it. An entry below the given folder named `node_modules` or starting with `.` SHALL be skipped before any other check, link or not, with no problem. The walk SHALL NOT enter a skill folder. When the given folder is itself a skill folder, it SHALL give that one skill. A given folder that is a marketplace root SHALL instead be read as "Marketplace root" says. + +#### Scenario: Grouped skills +- **WHEN** a given folder holds `skills/developer/java/SKILL.md` and `skills/developer/developer/SKILL.md` +- **THEN** both skills are read + +#### Scenario: Resources are not skills +- **WHEN** a skill folder `writer` holds `examples/draft/SKILL.md` +- **THEN** only `writer` is read + +#### Scenario: Depth limit +- **WHEN** a `SKILL.md` lies in a folder six levels below the given folder (`a/b/c/d/e/f/SKILL.md`) +- **THEN** it is not read and there is no problem, and one in a folder five levels below (`a/b/c/d/e/SKILL.md`) is read + +#### Scenario: Hidden and dependency folders +- **WHEN** a given folder holds `.git/x/SKILL.md` and `node_modules/x/SKILL.md` +- **THEN** neither is read and there is no problem + +#### Scenario: Hidden link to a skill +- **WHEN** `.cache` and `node_modules` are links to skill folders +- **THEN** neither is read and there is no problem + +#### Scenario: Given folder is a hidden tool folder +- **WHEN** the given folder is `.claude` and it holds `skills/writer/SKILL.md` +- **THEN** `writer` is read + +#### Scenario: A single skill +- **WHEN** the given folder itself holds `SKILL.md` and an `agents` folder with `helper.md` +- **THEN** that folder gives one skill and no agent + +### Requirement: Agent files +Each file ending in `.md` directly in an `agents` folder at the top of a given folder that is not a skill folder SHALL be checked as an agent, with the frontmatter rules of `SKILL.md`, except that a file with no frontmatter block SHALL get one warning and not be an agent. `name` and `description` SHALL be non-empty strings, or the file SHALL get an error. Other fields SHALL give no problem. The `agents` folder of each plugin of a marketplace root SHALL be read the same way, in place of a top-level one. + +#### Scenario: Claude Code subagent +- **WHEN** `agents/reviewer.md` has `name`, `description`, `tools` and `model` +- **THEN** agent `reviewer` is in the set with no problem + +#### Scenario: Linked agent file +- **WHEN** `agents/reviewer.md` is a link to a regular file with a valid agent +- **THEN** agent `reviewer` is read at the path `agents/reviewer.md` + +#### Scenario: Agent without a name +- **WHEN** `agents/helper.md` has a frontmatter with only `description` +- **THEN** there is an error with field `name` and no agent from that file + +#### Scenario: Notes in the agents folder +- **WHEN** `agents/README.md` has no frontmatter +- **THEN** there is one warning and no agent from that file + +#### Scenario: Nested agents folder +- **WHEN** a skill folder holds `agents/helper.md` +- **THEN** it is not read as an agent + +### Requirement: Matching paths +The walk SHALL test, right after the hidden and `node_modules` skip, each folder, symbolic link (except one to a regular file that is not an agent file), skill folder's `SKILL.md` and `.md` file directly in the top-level `agents/` folder that it meets below a given folder. A skill folder SHALL be skipped when its own path or its `SKILL.md` path matches. Other files SHALL NOT be tested or counted. A pattern for a hidden entry (such as `!.claude/`) has no effect. In a marketplace root the walk SHALL also test each plugin folder (with `/`, except a plugin whose source is the root), and, below it, the entries of its `skills` and `agents` folders as above; paths are relative to the given folder. + +#### Scenario: SKILL.md pattern +- **WHEN** the ignore file holds `fixtures/*/SKILL.md` and the folder holds `fixtures/broken/SKILL.md` +- **THEN** `broken` is not read and the ignored count is 1 + +#### Scenario: Files the walk does not use +- **WHEN** the ignore file holds `*.txt` and `README.md`, and the folder holds `README.md`, `notes.txt` and `skills/writer/SKILL.md` +- **THEN** `writer` is read and the ignored count is 0 + +#### Scenario: Linked file the walk does not use +- **WHEN** the ignore file holds `README.md` and `*.txt`, and `README.md` and `link.txt` are links to regular files +- **THEN** the ignored count is 0 and the `ignored` list is empty + +### Requirement: One read per item +A skill folder or agent file reached more than once (through a link and directly, or from two given folders) SHALL be read once, at the first path in walk order, with no problem. Walk order SHALL be the folders in argument order, each walked as in "Finding skill folders". In a marketplace root, plugins SHALL be walked in manifest order, each its `skills` folder and then its `agents` folder, entries in code-point order. An entry skipped by a pattern is not reached, so it can still be read through another given folder. Copies (separate files with the same content) are different items. + +#### Scenario: Linked copy of a repository skill +- **WHEN** folders `repo` and `tool` are given and `tool/skills/writer` links to `repo/skills/writer` +- **THEN** `writer` is read once, with the path under `repo`, and there is no duplicate-name error + +#### Scenario: Plugins in manifest order +- **WHEN** the manifest lists `review` before `writing` +- **THEN** the set lists the items of `review` first + +### Requirement: Folders with nothing found +A given folder in which no skill folder and no agent file is found, counting those already read through an earlier folder, SHALL be an error, so a wrong path fails a pipeline. Entries skipped by the ignore file SHALL NOT count as found; when any were skipped, the message SHALL say how many. Its path SHALL be the folder argument as given, or `.` when no folder is given. A marketplace root in which nothing is found SHALL be this error too, unless the marketplace itself gave an error, which then explains it. + +#### Scenario: Wrong folder +- **WHEN** the given folder holds only `README.md` +- **THEN** there is one error naming that folder + +#### Scenario: Everything already read +- **WHEN** folders `repo` and `tool` are given and `tool` holds only links to skills of `repo` +- **THEN** there is no problem about `tool` + +#### Scenario: Everything ignored +- **WHEN** the ignore file holds `*` and the folder holds `skills/writer/SKILL.md` +- **THEN** there is one error naming that folder whose message says 1 entry was skipped by `.stackledgerignore`, and the ignored count is 1 + +#### Scenario: Marketplace with only remote plugins +- **WHEN** the manifest lists only plugins with remote sources +- **THEN** there is one warning per plugin and one error naming the folder diff --git a/openspec/changes/skills-marketplaces/specs/skills-map-command/spec.md b/openspec/changes/skills-marketplaces/specs/skills-map-command/spec.md index 4307ac5..d3daef0 100644 --- a/openspec/changes/skills-marketplaces/specs/skills-map-command/spec.md +++ b/openspec/changes/skills-marketplaces/specs/skills-map-command/spec.md @@ -11,10 +11,21 @@ The page of an item of a plugin SHALL show, after the kind, a line `Plugin: :` whose two parts both match the pattern of a page file name SHALL be written `--` when that has at most 64 characters; a valid loose name never holds `--`, so the two forms cannot clash. Any other qualified name SHALL be written in the hexadecimal form of the whole name. + +#### Scenario: Qualified name +- **WHEN** the plugin `writing` holds the skill `draft` +- **THEN** its page is `skills/writing--draft.md` + +#### Scenario: Qualified name with an invalid part +- **WHEN** the plugin `writing` holds a skill named `Draft` +- **THEN** its page is the hexadecimal form of `writing:Draft` + ## MODIFIED Requirements ### Requirement: Page file names -A loose name SHALL be the page's file name when it matches `^[a-z0-9]+(-[a-z0-9]+)*$`, has at most 64 characters and is not a Windows device name (`con`, `prn`, `aux`, `nul`, `com0`–`com9`, `lpt0`–`lpt9`). A qualified name `:` whose two parts both match that pattern SHALL be `--` when that has at most 64 characters (a valid loose name never holds `--`, so the two forms cannot clash). Any other name SHALL be written as `_` and the lowercase hexadecimal of its UTF-8 bytes; when that has more than 64 characters, its first 52 characters, `-`, and the first 11 hexadecimal digits of the SHA-256 of those bytes. +A name SHALL be the page's file name when it matches `^[a-z0-9]+(-[a-z0-9]+)*$`, has at most 64 characters and is not a Windows device name (`con`, `prn`, `aux`, `nul`, `com0`–`com9`, `lpt0`–`lpt9`). A qualified name SHALL be written as "Qualified page file names" says. Any other name SHALL be written as `_` and the lowercase hexadecimal of its UTF-8 bytes; when that has more than 64 characters, its first 52 characters, `-`, and the first 11 hexadecimal digits of the SHA-256 of those bytes. #### Scenario: Name with a path - **WHEN** a skill is named `../writer` @@ -32,10 +43,41 @@ A loose name SHALL be the page's file name when it matches `^[a-z0-9]+(-[a-z0-9] - **WHEN** a skill is named with 65 `a` characters - **THEN** its page is `skills/_616161616161616161616161616161616161616161616161616-635361c48bb.md` -#### Scenario: Qualified name -- **WHEN** the plugin `writing` holds the skill `draft` -- **THEN** its page is `skills/writing--draft.md` +### Requirement: Inputs the map folder must not touch +After resolving links, the output folder SHALL be refused, with exit 2 and nothing written, when it is or contains a given folder, or the real path of any skill folder, agent file or file read (rejected ones included, the skills map file and a marketplace manifest too); is inside such a skill folder; is or is inside the folder an agent file was read from (a given folder's top-level `agents/`, or a plugin's); or has a segment below the current folder or a given folder that starts with `.` or is `openspec`. Names SHALL be compared ignoring case. -#### Scenario: Qualified name with an invalid part -- **WHEN** the plugin `writing` holds a skill named `Draft` -- **THEN** its page is the hexadecimal form of `writing:Draft` +#### Scenario: Output is the given folder +- **WHEN** the command runs as `stackledger skills map repo --out repo` +- **THEN** the exit code is 2 and nothing is written + +#### Scenario: Output holds a linked source +- **WHEN** a given folder `tool` holds `skills/writer`, a link to `repo/map/skills/writer`, and `--out` is `repo/map` +- **THEN** the exit code is 2 and nothing is removed + +#### Scenario: Output inside a skill folder +- **WHEN** `--out` is `repo/skills/writer/map` and `repo/skills/writer/SKILL.md` exists +- **THEN** the exit code is 2 + +#### Scenario: Output in the agents folder +- **WHEN** `--out` is `repo/agents` for the given folder `repo` +- **THEN** the exit code is 2 + +#### Scenario: Output in a plugin's agents folder +- **WHEN** the given folder is a marketplace root and `--out` is `plugins/review/agents/map`, where `plugins/review/agents/reviewer.md` was read +- **THEN** the exit code is 2 + +#### Scenario: Output in a tool folder +- **WHEN** `--out` is `.claude/commands/map`, `OpenSpec/specs/map`, or `../home/.claude/commands/map` with `../home/.claude` given +- **THEN** the exit code is 2 + +#### Scenario: Output holds a linked source file +- **WHEN** `repo/skills/writer/SKILL.md` is a link to `map/skills/input.md` and `--out` is `map` +- **THEN** the exit code is 2 and `map/skills/input.md` is untouched + +#### Scenario: Output holds the linked skills map file +- **WHEN** `repo/stackledger-skills.yaml` is a link to `map/skills/lines.yaml` and `--out` is `map` +- **THEN** the exit code is 2 and `map/skills/lines.yaml` is untouched + +#### Scenario: Output inside the given folder +- **WHEN** the command runs in `repo` as `stackledger skills map . --out docs/skills-map` and that folder does not exist +- **THEN** the folder is created with the marker, `.gitattributes`, the index and the pages, and the exit code is 0 diff --git a/openspec/changes/skills-marketplaces/tasks.md b/openspec/changes/skills-marketplaces/tasks.md index fade37d..897273d 100644 --- a/openspec/changes/skills-marketplaces/tasks.md +++ b/openspec/changes/skills-marketplaces/tasks.md @@ -1,23 +1,24 @@ ## 1. Code -- [ ] 1.1 `src/skills/resolve.ts`: the name index and the resolution order (own plugin, exact, only plugin item, ambiguous). Check: `npx vitest run test/unit/skills-resolve.test.ts` (scenarios of Name resolution). -- [ ] 1.2 `src/skills/marketplace.ts`: read and check `marketplace.json` and `plugin.json` (bounded read, secret rules, name and source rules, 500 plugins). `src/skills/walk.ts`: recognise a marketplace root at the top of a given folder, walk each plugin's `skills` and `agents` below its path with the same code and the ignore file, record plugin and marketplace on each found item, skip remote plugins with a warning. Check: `npx vitest run test/unit/skills-marketplace.test.ts`. -- [ ] 1.3 `src/skills/source.ts`: qualified names, `plain`, `plugin` and `marketplace` on skills and agents, uniqueness per plugin, resolved relations and preloads, ambiguity. `src/skills/lines.ts`, `metro.ts`: resolved references and zones. Check: `npx vitest run test/unit/skills-*.test.ts`. -- [ ] 1.4 `src/skills/graph.ts`, `mermaid.ts`: plugin and marketplace on nodes and item pages, `plugin--name` page file names. `src/site/skills-data.ts` and `site/src/components/SkillItem.astro`: plugin line on pages. Check: `npx vitest run test/unit/skills-map.test.ts test/unit/site-skills-data.test.ts`. +- [x] 1.1 `src/skills/resolve.ts`: the name index and the resolution order (own plugin, exact, only plugin item, ambiguous). Check: `npx vitest run test/unit/skills-resolve.test.ts` (scenarios of Name resolution). +- [x] 1.2 `src/skills/marketplace.ts`: read and check `marketplace.json` and `plugin.json` (bounded read, secret rules, name and source rules, 500 plugins). `src/skills/walk.ts`: recognise a marketplace root at the top of a given folder, walk each plugin's `skills` and `agents` below its path with the same code and the ignore file, record plugin and marketplace on each found item, skip remote plugins with a warning. Check: `npx vitest run test/unit/skills-marketplace.test.ts`. +- [x] 1.3 `src/skills/source.ts`: qualified names, `plain`, `plugin` and `marketplace` on skills and agents, uniqueness per plugin, resolved relations and preloads, ambiguity. `src/skills/lines.ts`, `metro.ts`: resolved references and zones. Check: `npx vitest run test/unit/skills-*.test.ts`. +- [x] 1.4 `src/skills/graph.ts`, `mermaid.ts`: plugin and marketplace on nodes and item pages, `plugin--name` page file names. `src/site/skills-data.ts` and `site/src/components/SkillItem.astro`: plugin line on pages. Check: `npx vitest run test/unit/skills-map.test.ts test/unit/site-skills-data.test.ts`. ## 2. Tests and documentation -- [ ] 2.1 One test per scenario, named after it. The fixture is a fictitious marketplace, `examples/northwind-marketplace/` (two plugins, a same-named agent in both, a remote plugin), built in temporary folders for unit tests. -- [ ] 2.2 Integration and browser tests: `skills validate`, `skills map --check` and `build --skills` on the example marketplace; a site page of each same-named agent. -- [ ] 2.3 `docs/skills.md`, `README.md`, `AGENTS.md`, `docs/architecture.md` (module map) and `docs/roadmap.md` (row delivered). Check: `npx vitest run test/integration/docs.test.ts`. +- [x] 2.1 One test per scenario, named after it. The fixture is a fictitious marketplace, `examples/northwind-marketplace/` (two plugins, a same-named agent in both, a remote plugin), built in temporary folders for unit tests. +- [x] 2.2 Integration and browser tests: `skills validate`, `skills map --check` and `build --skills` on the example marketplace; a site page of each same-named agent. +- [x] 2.3 `docs/skills.md`, `README.md`, `AGENTS.md`, `docs/architecture.md` (module map) and `docs/roadmap.md` (row delivered). Check: `npx vitest run test/integration/docs.test.ts`. ## 3. Integration -- [ ] 3.1 Full suite. Check: `npm run build && npm test && npm run test:browser`. +- [x] 3.1 Full suite. Check: `npm run build && npm test && npm run test:browser`. | Capability | Scenarios | Test file | |---|---|---| -| skill-source | Marketplace root, Marketplace manifest, Plugin sources, Plugin contents, Qualified names, Same name in two plugins | test/unit/skills-marketplace.test.ts | -| skill-source | Name resolution, Declared relations, Preloaded skills, Skill references, Playbook zones | test/unit/skills-resolve.test.ts | -| skills-map-command | Plugin on item pages, Page file names | test/unit/skills-map.test.ts | -| skills-site | Plugin on skills pages | test/integration/site-skills.test.ts | +| skill-source | Marketplace root, Marketplace manifest, Plugin entries, Plugin sources, Remote plugins, Plugin contents, Plugin manifest, Qualified names, Same name in two plugins, One read per item (plugin order), Folders with nothing found (marketplace) | test/unit/skills-marketplace.test.ts | +| skill-source | Name resolution, Resolved relations, Ambiguous names, Qualified references, Declared relations, Preloaded skills, Unique names, Playbook zones | test/unit/skills-resolve.test.ts | +| skills-map-command | Plugin on item pages, Qualified page file names, Page file names, Output in a plugin's agents folder | test/unit/skills-marketplace-map.test.ts, test/integration/skills-marketplace.test.ts | +| build-command | Output in a plugin's agents folder | test/integration/skills-marketplace.test.ts (the `skills map` guard; the build guard shares its code path and is checked by inspection) | +| skills-site | Plugin on skills pages | test/integration/skills-marketplace.test.ts, test/unit/skills-marketplace-map.test.ts, test/browser/site-skills.spec.ts | diff --git a/site/src/components/SkillItem.astro b/site/src/components/SkillItem.astro index 4e6ec48..7731b37 100644 --- a/site/src/components/SkillItem.astro +++ b/site/src/components/SkillItem.astro @@ -20,6 +20,11 @@ const kinds: Record = { skill: 'Skill', playbook: 'Playbook', ag

Skills · {kinds[page.kind]}

{page.name}

+ { + page.plugin !== undefined && ( +

Plugin {page.plugin} · Marketplace {page.marketplace}

+ ) + }

{page.description}

diff --git a/src/site/skills-build.ts b/src/site/skills-build.ts index 0dca492..76ad8a6 100644 --- a/src/site/skills-build.ts +++ b/src/site/skills-build.ts @@ -14,7 +14,7 @@ * Configured folders are read with the catalogue folder as the current folder, so problems and messages * show the paths as written in the Settings; pages show only paths below each folder. */ -import { join, relative, resolve, sep } from 'node:path'; +import { dirname, join, relative, resolve, sep } from 'node:path'; import { withoutControls } from '../control.js'; import { CommandStop } from '../errors.js'; import type { MapGeometry } from '../map/layout.js'; @@ -79,6 +79,10 @@ export function refuseSkillsOutput(target: string, skills: SkillsInUse, ops: FsO const first = within(target, folder) ? relative(folder, target).split(sep)[0] : undefined; if (within(target, agents) || first?.toLowerCase() === AGENTS_FOLDER) throw new Error('Output folder must not be the agents folder of a skills folder or inside it'); } + // The folder of each agent file too: a plugin's `agents/` is not the top level of a skills folder. + for (const agent of skills.set.agents) { + if (within(target, dirname(agent.files[0]!.real))) throw new Error('Output folder must not be the agents folder of a skills folder or inside it'); + } for (const found of skills.set.found) { if (within(found, target)) throw new Error(`Output folder must not hold a skill folder, agent file or file of the skill set: ${found}`); if (within(target, found)) throw new Error(`Output folder must not be inside a skill folder of the set: ${found}`); diff --git a/src/site/skills-data.ts b/src/site/skills-data.ts index 8dddc7d..9ef4da5 100644 --- a/src/site/skills-data.ts +++ b/src/site/skills-data.ts @@ -29,6 +29,8 @@ export interface LineChip { ref: string; slug: string; title: string; badge: str export interface RuleRow { id: string; group: string; text: string; why: string; check: string } export interface SkillItemPage extends ItemLink { file: string; description: string; + /** The plugin and marketplace of an item of a plugin (skill-source, Qualified names); absent for a loose item. */ + plugin?: string; marketplace?: string; /** Absent when a side has more than MAX_SIDE_ITEMS relations; `relationCount` says how many there are. */ diagram?: Themed; relationCount: number; broughtInBy: RelationLink[]; bringsIn: RelationLink[]; reachedThrough: ItemLink[]; @@ -86,6 +88,7 @@ export function buildSkillsData(set: SkillSet): { data: SkillsData; geometry: Ma const rules = 'rules' in source ? source.rules : []; return { ...link(node), file: pageFileName(node.name), description: descriptionLine(node.description), + ...(source.plugin === undefined ? {} : { plugin: cleanText(source.plugin), marketplace: cleanText(source.marketplace ?? '') }), ...(near ? { diagram: themed(theme => renderRelations(near, theme)) } : {}), relationCount: left.length + right.length, broughtInBy: left.map(edge => ({ ...link(edge.from), relation: edge.kind })), bringsIn: right.map(edge => ({ ...link(edge.to), relation: edge.kind })), diff --git a/src/skills/graph.ts b/src/skills/graph.ts index 1b509b8..96b90a2 100644 --- a/src/skills/graph.ts +++ b/src/skills/graph.ts @@ -29,6 +29,9 @@ export interface MapNode { /** Rule IDs in file order (skills and playbooks; none for agents). */ rules: string[]; files: SourceFile[]; + /** The plugin and marketplace of an item of a plugin (skill-source, Qualified names); absent otherwise. */ + plugin?: string; + marketplace?: string; } export interface MapEdge { from: MapNode; kind: RelationKind; to: MapNode } export interface SkillGraph { @@ -60,11 +63,13 @@ export function buildGraph(set: Pick): SkillGraph const skillsByName = new Map(), agentsByName = new Map(); for (const skill of set.skills) { const node: MapNode = { key: keyOf(skill.kind, skill.name), kind: skill.kind, name: skill.name, description: skill.description, - rules: skill.rules.map(rule => rule.id), files: skill.files }; + rules: skill.rules.map(rule => rule.id), files: skill.files, + ...(skill.plugin === undefined ? {} : { plugin: skill.plugin, marketplace: skill.marketplace ?? '' }) }; nodes.push(node); skillsByName.set(skill.name, node); } for (const agent of set.agents) { - const node: MapNode = { key: keyOf('agent', agent.name), kind: 'agent', name: agent.name, description: agent.description, rules: [], files: agent.files }; + const node: MapNode = { key: keyOf('agent', agent.name), kind: 'agent', name: agent.name, description: agent.description, rules: [], files: agent.files, + ...(agent.plugin === undefined ? {} : { plugin: agent.plugin, marketplace: agent.marketplace ?? '' }) }; nodes.push(node); agentsByName.set(agent.name, node); } const edges: MapEdge[] = []; diff --git a/src/skills/lines.ts b/src/skills/lines.ts index 57825f6..5ce8bda 100644 --- a/src/skills/lines.ts +++ b/src/skills/lines.ts @@ -18,6 +18,7 @@ import { lineSchema, layoutSchema, name as nameSchema, type Line, type MapLayout import { scanSecrets } from '../secrets.js'; import { schemaProblems } from '../validate.js'; import { readBounded } from './read.js'; +import { ambiguousMessage, indexNames, resolveName } from './resolve.js'; export type ItemKind = 'skill' | 'playbook' | 'agent'; export const ITEM_KINDS: readonly ItemKind[] = ['skill', 'playbook', 'agent']; @@ -26,8 +27,13 @@ export interface SkillsMap { lines: Line[]; layout?: MapLayout; } -/** What the checks need to know about the set: each item name and its kind. */ -export type ItemKinds = Map; +/** What the checks need to know about one item of the set: its name (qualified for a plugin item), plain name, plugin and kind. */ +export interface SetItem { name: string; plain: string; plugin?: string; kind: ItemKind } +/** The items of a set, split into the namespaces a reference names: skills and playbooks, and agents. */ +export interface SetIndex { skills: ReturnType>; agents: ReturnType> } +export function indexItems(items: readonly SetItem[]): SetIndex { + return { skills: indexNames(items.filter(item => item.kind !== 'agent')), agents: indexNames(items.filter(item => item.kind === 'agent')) }; +} const API_VERSION = 'stackledger/v1alpha1'; interface Document { source: Source; kind: 'Line' | 'MapLayout'; name: string; served?: Line | MapLayout } @@ -46,7 +52,7 @@ export function splitReference(value: string): { kind: ItemKind; name: string } } /** Read the map files in folder order and check them against the set's items. */ -export async function readSkillsMap(files: { path: string; absolute: string }[], items: ItemKinds, problems: Problem[]): Promise { +export async function readSkillsMap(files: { path: string; absolute: string }[], items: readonly SetItem[], problems: Problem[]): Promise { const sources: Source[] = []; for (const file of files) { const read = await readBounded(file.absolute, file.path, { bytes: MAX_FILE_BYTES, tooLarge: 'File exceeds 1 MiB', unreadable: 'File cannot be read' }); @@ -58,7 +64,7 @@ export async function readSkillsMap(files: { path: string; absolute: string }[], } /** The catalogue's document checks for Line and MapLayout, then the cross-document checks. */ -export function checkSkillsMap(sources: Source[], items: ItemKinds, problems: Problem[]): SkillsMap { +export function checkSkillsMap(sources: Source[], items: readonly SetItem[], problems: Problem[]): SkillsMap { const documents: Document[] = []; // A file with a secret gives no line and no layout, and its values never reach another message. const secretFiles = new Set(); @@ -96,7 +102,8 @@ export function checkSkillsMap(sources: Source[], items: ItemKinds, problems: Pr }; } -function crossCheck(unique: Document[], items: ItemKinds, problems: Problem[]): void { +function crossCheck(unique: Document[], items: readonly SetItem[], problems: Problem[]): void { + const setIndex = indexItems(items); const add = (document: Document, path: FieldPath, message: string, severity: Problem['severity'] = 'error', key = false) => { problems.push(problem(document.source, path, message, severity, key)); }; @@ -104,9 +111,12 @@ function crossCheck(unique: Document[], items: ItemKinds, problems: Problem[]): function target(document: Document, value: string, path: FieldPath, key = false): string | undefined { const ref = splitReference(value); if (!ref) { add(document, path, 'Reference must be skill:, playbook: or agent:', 'error', key); return; } - const kinds = items.get(ref.name) ?? []; - if (kinds.includes(ref.kind)) return `${ref.kind}:${ref.name}`; - const other = kinds.find(kind => kind !== ref.kind); + const own = ref.kind === 'agent' ? setIndex.agents : setIndex.skills, others = ref.kind === 'agent' ? setIndex.skills : setIndex.agents; + const hit = resolveName(own, ref.name); + if (hit && 'ambiguous' in hit) { add(document, path, ambiguousMessage(ref.kind, ref.name, hit.ambiguous), 'error', key); return; } + if (hit && hit.item.kind === ref.kind) return `${ref.kind}:${hit.item.name}`; + const found = hit ? hit.item : (() => { const other = resolveName(others, ref.name); return other && 'item' in other ? other.item : undefined; })(); + const other = found?.kind; add(document, path, other ? `No ${ref.kind} named ${ref.name}; ${ref.name} is ${other === 'agent' ? 'an' : 'a'} ${other}` : `No ${ref.kind} named ${ref.name} in the set`, 'error', key); return undefined; } @@ -156,7 +166,9 @@ function crossCheck(unique: Document[], items: ItemKinds, problems: Problem[]): const path: FieldPath = ['spec', 'zones', index, 'name']; if (zones.has(value)) { add(layout, path, 'Duplicate zone name'); return; } zones.add(value); - if (!(items.get(value) ?? []).includes('playbook')) add(layout, path, `Zone must name a playbook of the set; ${value} is not one`); + const hit = resolveName(setIndex.skills, value); + if (hit && 'ambiguous' in hit) add(layout, path, ambiguousMessage('Playbook', value, hit.ambiguous)); + else if (!hit || hit.item.kind !== 'playbook') add(layout, path, `Zone must name a playbook of the set; ${value} is not one`); }); } for (const [ref, stop] of firstStops) if (!stations.has(ref)) add(stop.document, stop.path, 'No position; the map will place this item', 'warning'); @@ -167,10 +179,12 @@ function crossCheck(unique: Document[], items: ItemKinds, problems: Problem[]): * then what its `stackledger-skills` and `stackledger-agents` name in the set, as written. Only direct * relations: a playbook that loads another would otherwise take that one's whole zone. Empty when the * name is no playbook of the set. */ -export function zoneMembers(set: { skills: { name: string; kind: 'skill' | 'playbook'; skills: string[]; agents: string[] }[]; agents: { name: string }[] }, zone: string): string[] { - const playbook = set.skills.find(item => item.kind === 'playbook' && item.name === zone); +export function zoneMembers(set: { skills: { name: string; plain?: string; plugin?: string; kind: 'skill' | 'playbook'; skills: string[]; agents: string[] }[]; agents: { name: string; plain?: string; plugin?: string }[] }, zone: string): string[] { + const hit = resolveName(indexNames(set.skills), zone); + const playbook = hit && 'item' in hit && hit.item.kind === 'playbook' ? hit.item : undefined; if (!playbook) return []; const members = [`playbook:${playbook.name}`]; + // The relations of a playbook already hold the names they resolved to (src/skills/source.ts). for (const name of playbook.skills) { const item = set.skills.find(candidate => candidate.name === name); if (item) members.push(`${item.kind}:${item.name}`); diff --git a/src/skills/map-command.ts b/src/skills/map-command.ts index 1a31bb8..7acc61b 100644 --- a/src/skills/map-command.ts +++ b/src/skills/map-command.ts @@ -171,6 +171,11 @@ function checkOutput(out: string, given: string[], set: SkillSet, current: strin // The given folder's own name counts: with `~/.claude` given, `~/.claude/commands/map` is in a tool folder. if (segments) toolFolder([basename(folder), ...segments].filter(Boolean)); } + // The folder of each agent file too: a plugin's `agents/` is not the top level of a given folder. + for (const agent of set.agents) { + const holder = dirname(agent.files[0]!.real); + if (within(target, holder)) throw new Error('Output folder must not be the agents folder of a given folder or inside it'); + } for (const found of set.found) { if (within(found, target)) throw new Error(`Output folder must not hold a skill folder or agent file of the set, or a file the set was read from: ${found}`); if (within(target, found)) throw new Error(`Output folder must not be inside a skill folder of the set: ${found}`); diff --git a/src/skills/marketplace.ts b/src/skills/marketplace.ts new file mode 100644 index 0000000..1157bd8 --- /dev/null +++ b/src/skills/marketplace.ts @@ -0,0 +1,129 @@ +/** Read a Claude Code plugin marketplace (skill-source spec: Marketplace root, Marketplace manifest, + * Plugin entries, Plugin sources, Remote plugins, Plugin manifest). Used by src/skills/walk.ts, which + * decides what a given folder is and then walks each plugin's `skills` and `agents` folders. Only + * reads files and stats folders: nothing is written, nothing is fetched. + * + * Why this shape: + * - A marketplace is recognised by its manifest alone (`.claude-plugin/marketplace.json`, a regular + * file); a plugin's identity is the name of its manifest entry, the one `/plugin install` uses. + * - A plugin `source` is read only as a folder of the marketplace: it starts with `./`, and its real path + * (links resolved) stays inside the marketplace's real path, so a fork's pull request cannot point the + * read at another folder. An object source is a remote plugin: it gets a warning and is never contacted. + * - Every problem is on a path and never throws; one bad entry never stops the others. + */ +import { realpath, stat } from 'node:fs/promises'; +import { isAbsolute, join, relative, resolve, sep } from 'node:path'; +import { fileProblem, MAX_FILE_BYTES, type Problem } from '../source.js'; +import { readBounded, secretProblems } from './read.js'; + +export const MARKETPLACE_FOLDER = '.claude-plugin'; +export const MARKETPLACE_FILE = 'marketplace.json'; +export const PLUGIN_FILE = 'plugin.json'; +/** At most this many plugin entries of one manifest are read. */ +export const MAX_PLUGINS = 500; +const NAME = /^[a-z0-9]+(-[a-z0-9]+)*$/; + +export interface PluginEntry { + name: string; + /** Absolute path of the plugin folder, lexically below the marketplace root. */ + absolute: string; + /** Path below the marketplace root, `/`-separated; empty when the root is the plugin. */ + relative: string; +} +export interface Marketplace { + /** The manifest's name; absent when the manifest could not be used. */ + name?: string; + plugins: PluginEntry[]; + problems: Problem[]; +} + +const object = (value: unknown): Record | undefined => + value !== null && typeof value === 'object' && !Array.isArray(value) ? value as Record : undefined; +function join2(prefix: string, relativePath: string): string { + if (!prefix) return relativePath; + return prefix.endsWith('/') ? prefix + relativePath : `${prefix}/${relativePath}`; +} +/** Every string of a decoded JSON value, keys included. */ +function* strings(value: unknown): Generator { + if (typeof value === 'string') yield value; + else if (Array.isArray(value)) for (const child of value) yield* strings(child); + else if (value !== null && typeof value === 'object') for (const [key, child] of Object.entries(value)) { yield key; yield* strings(child); } +} +const insideRoot = (root: string, path: string): boolean => { + const found = relative(root, path); + return found === '' || (found !== '..' && !found.startsWith(`..${sep}`) && !isAbsolute(found)); +}; +const readJson = (absolute: string, path: string) => + readBounded(absolute, path, { bytes: MAX_FILE_BYTES, tooLarge: 'File is larger than 1 MiB; not read', unreadable: 'File cannot be read' }); + +/** Read `/.claude-plugin/marketplace.json`; `prefix` is how the given folder is displayed. */ +export async function readMarketplace(root: string, prefix: string): Promise { + const path = join2(prefix, `${MARKETPLACE_FOLDER}/${MARKETPLACE_FILE}`); + const result: Marketplace = { plugins: [], problems: [] }; + const fail = (message: string) => { result.problems.push(fileProblem(path, message)); return result; }; + const read = await readJson(join(root, MARKETPLACE_FOLDER, MARKETPLACE_FILE), path); + if ('problem' in read) { result.problems.push(read.problem); return result; } + let parsed: unknown; + try { parsed = JSON.parse(read.text.replace(/^/, '')); } catch { return fail('Marketplace manifest is not valid JSON'); } + const secrets = secretProblems(path, [read.text, ...strings(parsed)]); + if (secrets.length) { result.problems.push(...secrets); return result; } + const manifest = object(parsed); + if (!manifest) return fail('Marketplace manifest must be a JSON object'); + if (typeof manifest.name !== 'string' || !manifest.name) return fail('Marketplace manifest needs a name'); + if (!NAME.test(manifest.name)) return fail('Marketplace name must be lowercase letters and digits with hyphens between them'); + if (!Array.isArray(manifest.plugins)) return fail('Marketplace manifest needs a plugins list'); + result.name = manifest.name; + let realRoot: string; + try { realRoot = await realpath(root); } catch { realRoot = resolve(root); } + const names = new Set(), folders = new Set(); + const entries = manifest.plugins as unknown[]; + for (const [index, value] of entries.entries()) { + const where = `Plugin ${index + 1}`; + if (index >= MAX_PLUGINS) { result.problems.push(fileProblem(path, `${where} is over the limit of ${MAX_PLUGINS} plugins; not read`)); continue; } + const entry = object(value); + if (!entry || typeof entry.name !== 'string' || !entry.name) { result.problems.push(fileProblem(path, `${where} needs a name; not read`)); continue; } + const name = entry.name; + if (!NAME.test(name)) { result.problems.push(fileProblem(path, 'Plugin name must be lowercase letters and digits with hyphens between them; not read')); continue; } + if (names.has(name)) { result.problems.push(fileProblem(path, `Plugin ${name} is listed more than once; the later entry is not read`)); continue; } + names.add(name); + const source = entry.source; + if (source === undefined) { result.problems.push(fileProblem(path, `Plugin ${name} has no source; not read`)); continue; } + if (object(source)) { + result.problems.push(fileProblem(path, `Plugin ${name} has a remote source; not read (stackledger makes no network call)`, 'warning')); + continue; + } + if (typeof source !== 'string' || !source.startsWith('./')) { + result.problems.push(fileProblem(path, `Plugin ${name} source must be a folder of the marketplace that starts with ./; not read`)); continue; + } + const absolute = resolve(root, source); + if (!insideRoot(resolve(root), absolute)) { result.problems.push(fileProblem(path, `Plugin ${name} source is outside the marketplace; not read`)); continue; } + let real: string; + try { + real = await realpath(absolute); + if (!(await stat(absolute)).isDirectory()) throw new Error('not a folder'); + } catch { result.problems.push(fileProblem(path, `Plugin ${name} source folder was not found; not read`)); continue; } + if (!insideRoot(realRoot, real)) { result.problems.push(fileProblem(path, `Plugin ${name} source is outside the marketplace; not read`)); continue; } + if (folders.has(real)) continue; + folders.add(real); + result.plugins.push({ name, absolute, relative: relative(resolve(root), absolute).split(sep).filter(Boolean).join('/') }); + } + return result; +} + +/** The warnings about a plugin's own `plugin.json`: unreadable, not JSON, or a name unlike the entry's. */ +export async function checkPluginManifest(plugin: PluginEntry, prefix: string): Promise { + const file = join(plugin.absolute, MARKETPLACE_FOLDER, PLUGIN_FILE); + try { if (!(await stat(file)).isFile()) return []; } catch { return []; } + const path = join2(prefix, plugin.relative ? `${plugin.relative}/${MARKETPLACE_FOLDER}/${PLUGIN_FILE}` : `${MARKETPLACE_FOLDER}/${PLUGIN_FILE}`); + const read = await readJson(file, path); + if ('problem' in read) return [{ ...read.problem, severity: 'warning' }]; + let parsed: unknown; + try { parsed = JSON.parse(read.text.replace(/^/, '')); } catch { return [fileProblem(path, 'Plugin manifest is not valid JSON', 'warning')]; } + const secrets = secretProblems(path, [read.text, ...strings(parsed)]); + if (secrets.length) return secrets; + const name = object(parsed)?.name; + if (typeof name === 'string' && name !== plugin.name) { + return [fileProblem(path, `Plugin manifest name differs from the marketplace entry ${plugin.name}; the entry's name is used`, 'warning')]; + } + return []; +} diff --git a/src/skills/mermaid.ts b/src/skills/mermaid.ts index 6b65559..072ccfc 100644 --- a/src/skills/mermaid.ts +++ b/src/skills/mermaid.ts @@ -8,7 +8,8 @@ * * Why the text is handled this way: names, descriptions, rule IDs and folder names come from files a * fork's pull request can change, and Git hosts render the pages. - * - Page file names are lowercase ASCII (a valid Agent Skills name, or `_` and hexadecimal UTF-8), so + * - Page file names are lowercase ASCII (a valid Agent Skills name, `plugin--name` for an item of a plugin, + * or `_` and hexadecimal UTF-8), so * no name can climb out of the map folder, clash on a case-insensitive file system or be refused by * Windows. * - Node IDs are derived from the file name (`s_writer`), never numbered, so adding one item changes @@ -68,6 +69,12 @@ const ARROWS = 'An arrow goes from what brings an item in to what it brings in: /** The page file name of an item, without `.md`. */ export function pageFileName(name: string): string { + // A qualified name `plugin:name` is `plugin--name` when both parts are valid names; a valid name never holds `--`. + const colon = name.indexOf(':'); + if (colon > 0) { + const joined = `${name.slice(0, colon)}--${name.slice(colon + 1)}`; + if (joined.length <= MAX_FILE_NAME && VALID_NAME.test(name.slice(0, colon)) && VALID_NAME.test(name.slice(colon + 1))) return joined; + } if (name.length <= MAX_FILE_NAME && VALID_NAME.test(name) && !WINDOWS_DEVICE.test(name)) return name; const bytes = Buffer.from(name, 'utf8'); const hexadecimal = `_${bytes.toString('hex')}`; @@ -207,6 +214,7 @@ function itemPage(graph: SkillGraph, node: MapNode, paths: MapPaths): string { `# ${markdownText(node.name)}`, NOTICE, `Kind: ${node.kind}`, + ...(node.plugin === undefined ? [] : [`Plugin: ${markdownText(node.plugin)}\n\nMarketplace: ${markdownText(node.marketplace ?? '')}`]), description || 'No description.', legend(true), oneHop(graph, node), diff --git a/src/skills/metro.ts b/src/skills/metro.ts index 4bc2c5f..a04eaf9 100644 --- a/src/skills/metro.ts +++ b/src/skills/metro.ts @@ -14,6 +14,7 @@ import { compareText } from '../identity.js'; import type { MapLine, MapModel, MapStation, MapZone, Point } from '../map/model.js'; import { splitReference, zoneMembers, type ItemKind } from './lines.js'; import { pageFileName } from './mermaid.js'; +import { indexNames, resolveName } from './resolve.js'; import type { SkillSet } from './source.js'; /** Control characters (C0, DEL, C1) and format characters (zero-width, bidirectional, tag characters). */ @@ -36,10 +37,14 @@ export function buildSkillsMapModel(set: Pick(); for (const skill of set.skills) items.set(`${skill.kind}:${skill.name}`, { kind: skill.kind, name: skill.name, rules: skill.rules.length }); for (const agent of set.agents) items.set(`agent:${agent.name}`, { kind: 'agent', name: agent.name, rules: 0 }); + type Named = { name: string; plain?: string; plugin?: string; kind: ItemKind }; + const skillIndex = indexNames(set.skills), agentIndex = indexNames(set.agents.map(agent => ({ ...agent, kind: 'agent' as const }))); /** The station reference of a map-file key, or undefined when it names no item of its kind. */ const resolve = (value: string): string | undefined => { const ref = splitReference(value); - const item = ref ? items.get(`${ref.kind}:${ref.name}`) : undefined; + // An ambiguous name was an error at its file and names no item here. + const hit = ref ? resolveName(ref.kind === 'agent' ? agentIndex : skillIndex, ref.name) : undefined; + const item = hit && 'item' in hit && hit.item.kind === ref!.kind ? items.get(`${ref!.kind}:${hit.item.name}`) : undefined; return item ? stationRef(item.kind, item.name) : undefined; }; const lines: MapLine[] = [...set.map.lines].sort(compareLines).map(line => ({ diff --git a/src/skills/resolve.ts b/src/skills/resolve.ts new file mode 100644 index 0000000..71fb4a4 --- /dev/null +++ b/src/skills/resolve.ts @@ -0,0 +1,53 @@ +/** Resolve the names an author writes to the items of a skill set (skill-source spec: Name resolution, + * Resolved relations, Ambiguous names). Used by src/skills/source.ts (relations, preloads), + * src/skills/lines.ts and src/skills/metro.ts (skills map file references and zones). Pure: no I/O. + * + * An item's `name` is its identity: `plugin:plain` for an item of a plugin, the plain name for a loose + * one. A name written in a file resolves, in this order: + * 1. when the writer belongs to a plugin, that plugin's item with that plain name; + * 2. the item whose name equals the text exactly (a loose item, or a qualified name); + * 3. the only plugin item with that plain name; two or more is ambiguous and resolves to nothing. + * So a set of loose folders resolves exactly as it did before plugins were read. + */ +import { compareText } from '../identity.js'; + +/** What resolution needs of an item; `plain` defaults to `name` for items that predate plugins. */ +export interface Resolvable { name: string; plain?: string; plugin?: string } +export type Resolution = { item: T } | { ambiguous: T[] } | undefined; + +export interface NameIndex { + exact: Map; + /** Items of plugins by plain name, in the order given. */ + byPlain: Map; +} + +/** The index of the items of one namespace (skills and playbooks, or agents). The first item with a name wins. */ +export function indexNames(items: readonly T[]): NameIndex { + const exact = new Map(), byPlain = new Map(); + for (const item of items) { + if (!exact.has(item.name)) exact.set(item.name, item); + if (item.plugin === undefined) continue; + const plain = item.plain ?? item.name; + byPlain.set(plain, [...(byPlain.get(plain) ?? []), item]); + } + return { exact, byPlain }; +} + +/** The item a written name means, as seen from an item of `from` (a plugin name), or what it is ambiguous between. */ +export function resolveName(index: NameIndex, written: string, from?: string): Resolution { + if (from !== undefined) { + const own = index.exact.get(`${from}:${written}`); + if (own) return { item: own }; + } + const exact = index.exact.get(written); + if (exact) return { item: exact }; + const matches = index.byPlain.get(written) ?? []; + if (matches.length === 1) return { item: matches[0]! }; + if (matches.length > 1) return { ambiguous: [...matches].sort((one, two) => compareText(one.name, two.name)) }; + return undefined; +} + +/** The message of an ambiguous name, naming every match. */ +export function ambiguousMessage(noun: string, written: string, matches: readonly Resolvable[]): string { + return `${noun} ${written} is ambiguous: it matches ${matches.map(item => item.name).join(', ')}; use the qualified name`; +} diff --git a/src/skills/source.ts b/src/skills/source.ts index 5dd0f81..00603df 100644 --- a/src/skills/source.ts +++ b/src/skills/source.ts @@ -33,7 +33,8 @@ import { readBounded, secretProblems } from './read.js'; import { AGENTS_KEY, SKILLS_KEY, at, checkAgentFields, checkNameAndDescription, checkSkillFields, readFrontmatter, relationNames, type Frontmatter, type SkillKind } from './frontmatter.js'; import { parseRules, type Rule } from './rules.js'; -import { readSkillsMap, type ItemKind, type SkillsMap } from './lines.js'; +import { readSkillsMap, type SetItem, type SkillsMap } from './lines.js'; +import { ambiguousMessage, indexNames, resolveName } from './resolve.js'; import { RULES_FILE, SKILL_FILE, walkSkillFolders, type FoundAgent, type FoundSkill, type WalkOptions } from './walk.js'; /** A file an item was read from. */ @@ -46,7 +47,13 @@ export interface SourceFile { real: string; } export interface Skill { + /** The item's identity: `plugin:plain` for an item of a plugin, the plain name for a loose one. */ name: string; + /** The `name` of the SKILL.md frontmatter. */ + plain: string; + /** The plugin and marketplace it was found in; absent for a loose folder. */ + plugin?: string; + marketplace?: string; kind: SkillKind; /** Display path of the SKILL.md. */ path: string; @@ -55,20 +62,24 @@ export interface Skill { given: string; /** Its SKILL.md, then the rules.md read for it. */ files: SourceFile[]; - /** Declared relations, in the order written, repeats removed. */ + /** Declared relations resolved to the targets' names (one that matches nothing stays as written), in the order written, repeats removed. */ skills: string[]; agents: string[]; rules: Rule[]; } export interface Agent { + /** As `Skill.name`. */ name: string; + plain: string; + plugin?: string; + marketplace?: string; path: string; description: string; /** Absolute path of the given folder the agent file was found in. */ given: string; /** The agent file. */ files: SourceFile[]; - /** Preloaded skills, as listed. */ + /** Preloaded skills, resolved to their names (a name that matches no skill stays as written). */ preloads: string[]; } export interface SkillsSummary { skills: number; playbooks: number; agents: number; rules: number; ignored: number; errors: number; warnings: number } @@ -89,8 +100,8 @@ export interface SkillSet { /** The error of a given folder in which nothing was found (`skills map` refuses to change the map then). */ export const NOTHING_FOUND = 'No skill folder or agent file found in this folder'; -interface SkillCandidate { found: FoundSkill; frontmatter: Frontmatter; kind: SkillKind } -interface AgentCandidate { found: FoundAgent; frontmatter: Frontmatter; preloads: string[] } +interface SkillCandidate { found: FoundSkill; frontmatter: Frontmatter; kind: SkillKind; name: string; plain: string } +interface AgentCandidate { found: FoundAgent; frontmatter: Frontmatter; preloads: string[]; name: string; plain: string } /** A file's display path inside a skill folder; a folder of `/` (or ending in `/`) adds no second separator. */ function displayJoin(folder: string, file: string): string { @@ -148,13 +159,18 @@ async function sourceFile(path: string, absolute: string, below: string): Promis const belowJoin = (relative: string, file: string) => relative ? `${relative}/${file}` : file; const hasError = (problems: Problem[]) => problems.some(problem => problem.severity === 'error'); const distinct = (names: string[]) => [...new Set(names)]; +/** The first entry for each key, in order. */ +function distinctBy(entries: T[], key: (entry: T) => string): T[] { + const seen = new Set(); + return entries.filter(entry => { const k = key(entry); if (seen.has(k)) return false; seen.add(k); return true; }); +} /** Read the given folders (none: the current folder) as one skill set. */ export async function readSkillSet(folders: string[], options: WalkOptions = {}): Promise { const walked = await walkSkillFolders(folders, options); const problems: Problem[] = [...walked.problems]; for (const folder of walked.folders) { - if (folder.found) continue; + if (folder.found || folder.explained) continue; // Skipped entries are not found, so a pattern that hides everything fails; the message says it was the ignore file. const skipped = folder.ignored === 1 ? '; 1 entry was skipped by ' + IGNORE_FILE : folder.ignored ? `; ${folder.ignored} entries were skipped by ${IGNORE_FILE}` : ''; @@ -175,7 +191,9 @@ export async function readSkillSet(folders: string[], options: WalkOptions = {}) const identity = checkNameAndDescription(frontmatter); problems.push(...identity); if (hasError(identity)) continue; - const name = frontmatter.value.name as string; + const plain = frontmatter.value.name as string; + // An item of a plugin is named plugin:plain; two plugins may hold one plain name (skill-source, Qualified names). + const name = found.plugin === undefined ? plain : `${found.plugin}:${plain}`; const paths = found.type === 'skill' ? skillPaths : agentPaths; if (found.type === 'skill') { const fields = checkSkillFields(frontmatter, found.folderName); @@ -184,58 +202,64 @@ export async function readSkillSet(folders: string[], options: WalkOptions = {}) const earlier = paths.get(name); if (earlier !== undefined) { problems.push(at(frontmatter, ['name'], `Name ${name} is already used by ${earlier}`)); continue; } paths.set(name, path); - skillCandidates.push({ found, frontmatter, kind: fields.kind }); + skillCandidates.push({ found, frontmatter, kind: fields.kind, name, plain }); } else { const fields = checkAgentFields(frontmatter); problems.push(...fields.problems); const earlier = paths.get(name); if (earlier !== undefined) { problems.push(at(frontmatter, ['name'], `Name ${name} is already used by ${earlier}`)); continue; } paths.set(name, path); - agentCandidates.push({ found, frontmatter, preloads: fields.preloads }); + agentCandidates.push({ found, frontmatter, preloads: fields.preloads, name, plain }); } } // Phase 3: the set is fixed; check what each item declares against it, without removing anything. + // A written name resolves as src/skills/resolve.ts says: the writer's own plugin first. + const skillIndex = indexNames(skillCandidates.map(candidate => ({ name: candidate.name, plain: candidate.plain, ...(candidate.found.plugin === undefined ? {} : { plugin: candidate.found.plugin }) }))); + const agentIndex = indexNames(agentCandidates.map(candidate => ({ name: candidate.name, plain: candidate.plain, ...(candidate.found.plugin === undefined ? {} : { plugin: candidate.found.plugin }) }))); const skills: Skill[] = [], agents: Agent[] = []; const ruleOwners = new Map(); + const owned = (found: FoundSkill | FoundAgent) => found.plugin === undefined ? {} : { plugin: found.plugin, marketplace: found.marketplace ?? '' }; for (const candidate of skillCandidates) { - const { frontmatter, found } = candidate; - const name = frontmatter.value.name as string; + const { frontmatter, found, name, plain } = candidate; const files = [await sourceFile(frontmatter.path, join(found.absolute, SKILL_FILE), belowJoin(found.relative, SKILL_FILE))]; - const skill: Skill = { name, kind: candidate.kind, path: frontmatter.path, description: frontmatter.value.description as string, + const skill: Skill = { name, plain, ...owned(found), kind: candidate.kind, path: frontmatter.path, description: frontmatter.value.description as string, given: found.given, files, skills: [], agents: [], rules: [] }; - for (const [key, known, noun] of [[SKILLS_KEY, skillPaths, 'Skill'], [AGENTS_KEY, agentPaths, 'Agent']] as const) { + for (const [key, index, noun] of [[SKILLS_KEY, skillIndex, 'Skill'], [AGENTS_KEY, agentIndex, 'Agent']] as const) { const declared = (frontmatter.value.metadata as Record | undefined)?.[key]; if (typeof declared !== 'string') continue; - const names = relationNames(declared); - for (const missing of distinct(names.filter(target => !known.has(target)))) { - problems.push(at(frontmatter, ['metadata', key], `${noun} ${missing} is not in the set`)); + // Each written name becomes the name it resolves to; one that matches nothing stays as written. + const resolved = relationNames(declared).map(written => ({ written, hit: resolveName(index, written, found.plugin) })); + const targets = resolved.map(({ written, hit }) => hit && 'item' in hit ? hit.item.name : written); + for (const { written, hit } of distinctBy(resolved, entry => entry.written)) { + if (hit && 'item' in hit) continue; + problems.push(at(frontmatter, ['metadata', key], hit ? ambiguousMessage(noun, written, hit.ambiguous) : `${noun} ${written} is not in the set`)); } - for (const repeated of distinct(names.filter((target, index) => names.indexOf(target) !== index))) { + for (const repeated of distinct(targets.filter((target, position) => targets.indexOf(target) !== position))) { problems.push(at(frontmatter, ['metadata', key], `${repeated} is listed more than once`, 'warning')); } - if (key === SKILLS_KEY && names.includes(name)) problems.push(at(frontmatter, ['metadata', key], `${name} lists itself`, 'warning')); - skill[key === SKILLS_KEY ? 'skills' : 'agents'] = distinct(names); + if (key === SKILLS_KEY && targets.includes(name)) problems.push(at(frontmatter, ['metadata', key], `${name} lists itself`, 'warning')); + skill[key === SKILLS_KEY ? 'skills' : 'agents'] = distinct(targets); } if (found.hasRules) skill.rules = await readRules(found, name, ruleOwners, problems, files); skills.push(skill); } for (const candidate of agentCandidates) { - const { frontmatter, found } = candidate; - candidate.preloads.forEach((preload, index) => { - if (!skillPaths.has(preload)) problems.push(at(frontmatter, ['skills', index], `Skill ${preload} is not in the set; the tool skips it`, 'warning')); + const { frontmatter, found, name, plain } = candidate; + const preloads = candidate.preloads.map((preload, index) => { + const hit = resolveName(skillIndex, preload, found.plugin); + if (hit && 'item' in hit) return hit.item.name; + problems.push(at(frontmatter, ['skills', index], hit ? `${ambiguousMessage('Skill', preload, hit.ambiguous)}; the tool skips it` : `Skill ${preload} is not in the set; the tool skips it`, 'warning')); + return preload; }); - agents.push({ name: frontmatter.value.name as string, path: frontmatter.path, description: frontmatter.value.description as string, - given: found.given, files: [await sourceFile(found.path, found.absolute, found.relative)], preloads: candidate.preloads }); + agents.push({ name, plain, ...owned(found), path: frontmatter.path, description: frontmatter.value.description as string, + given: found.given, files: [await sourceFile(found.path, found.absolute, found.relative)], preloads }); } // The map files are checked against the fixed set; their problems never remove an item. - const kinds = new Map(); - for (const item of [...skills, ...agents]) { - const kind: ItemKind = 'kind' in item ? item.kind : 'agent'; - kinds.set(item.name, [...(kinds.get(item.name) ?? []), kind]); - } - const map = await readSkillsMap(walked.mapFiles, kinds, problems); + const items: SetItem[] = [...skills, ...agents].map(item => ({ name: item.name, plain: item.plain, kind: 'kind' in item ? item.kind : 'agent', + ...(item.plugin === undefined ? {} : { plugin: item.plugin }) })); + const map = await readSkillsMap(walked.mapFiles, items, problems); sortProblems(problems); // Every skill folder and agent file, and every SKILL.md and rules.md in a skill folder, by real path: // a file can be a link into the map folder, which cleaning would delete (rejected items included). @@ -248,6 +272,7 @@ export async function readSkillSet(folders: string[], options: WalkOptions = {}) } // An ignore file can be a link into the map folder too; cleaning would delete its target. for (const file of walked.ignoreFiles) foundPaths.add(await realOrAbsolute(file)); + for (const file of walked.marketplaceFiles) foundPaths.add(await realOrAbsolute(file)); // A map file too (skill-source, One read per map file). for (const file of walked.mapFiles) foundPaths.add(await realOrAbsolute(file.absolute)); const count = (severity: Problem['severity']) => problems.filter(problem => problem.severity === severity).length; diff --git a/src/skills/walk.ts b/src/skills/walk.ts index 9fba088..5783d4e 100644 --- a/src/skills/walk.ts +++ b/src/skills/walk.ts @@ -29,6 +29,7 @@ import { lstat, readdir, stat } from 'node:fs/promises'; import { basename, join, resolve } from 'node:path'; import { compareText } from '../identity.js'; import { fileProblem, SKILLS_MAP_FILE, type Problem } from '../source.js'; +import { checkPluginManifest, MARKETPLACE_FILE, MARKETPLACE_FOLDER, readMarketplace } from './marketplace.js'; import { createMatcher, IGNORE_FILE, ignores, readIgnoreFile, type Matcher } from './ignore.js'; /** How many folder levels below a given folder are looked at: `a/b/c/d/e/SKILL.md` is read, `a/b/c/d/e/f/SKILL.md` is not. */ @@ -60,6 +61,9 @@ export interface FoundSkill { relative: string; /** Whether the folder holds an entry named exactly `rules.md`. */ hasRules: boolean; + /** The plugin and marketplace it was found in; absent in a loose folder. */ + plugin?: string; + marketplace?: string; } export interface FoundAgent { type: 'agent'; @@ -70,6 +74,8 @@ export interface FoundAgent { given: string; /** Path of the agent file below its given folder, `/`-separated (`agents/.md`). */ relative: string; + plugin?: string; + marketplace?: string; } export type Found = FoundSkill | FoundAgent; export interface Walked { @@ -80,9 +86,11 @@ export interface Walked { ignored: string[]; /** Per given folder, in argument order: its display name, how many items were found in it, counting * those already found through an earlier folder, and how many entries its ignore file skipped. */ - folders: { path: string; found: number; ignored: number }[]; + folders: { path: string; found: number; ignored: number; explained: boolean }[]; /** Absolute paths of the `.stackledgerignore` files read (a link included), in argument order. */ ignoreFiles: string[]; + /** Absolute paths of the marketplace manifests read, in argument order. */ + marketplaceFiles: string[]; /** The skills map files at the top of the given folders, each target once, in argument order. */ mapFiles: { path: string; absolute: string }[]; } @@ -115,7 +123,7 @@ function hidden(name: string): boolean { export async function walkSkillFolders(folders: string[], options: WalkOptions = {}): Promise { const cwd = options.cwd ?? process.cwd(); const list = options.list ?? listFolder; - const walked: Walked = { items: [], problems: [], ignored: [], folders: [], ignoreFiles: [], mapFiles: [] }; + const walked: Walked = { items: [], problems: [], ignored: [], folders: [], ignoreFiles: [], mapFiles: [], marketplaceFiles: [] }; const seenMapFiles = new Set(); const seenItems = new Set(); const seenProblems = new Set(); @@ -124,8 +132,13 @@ export async function walkSkillFolders(folders: string[], options: WalkOptions = // The ignore file of the given folder being walked (none: nothing is skipped), and how many entries it skipped. let matcher: Matcher | undefined; let skipped = 0; + // Whether the marketplace being walked gave an error: a folder with nothing found is then already explained. + let explained = false; // The absolute path of the given folder being walked, recorded on each item it gives. let given = ''; + // The plugin being walked, recorded on each item it gives, and the folder its agent files are in. + let owner: { plugin: string; marketplace: string } | undefined; + let agentsAt = AGENTS_FOLDER; function problemOnce(key: string, problem: Problem): void { if (seenProblems.has(key)) return; @@ -150,11 +163,11 @@ export async function walkSkillFolders(folders: string[], options: WalkOptions = } async function addSkill(absolute: string, folder: string, folderName: string, names: string[], relative: string): Promise { const key = await itemKey(absolute, folder || '.'); - if (key) addItem(`skill:${key}`, { type: 'skill', folder, folderName, absolute, given, relative, hasRules: names.includes(RULES_FILE) }); + if (key) addItem(`skill:${key}`, { type: 'skill', folder, folderName, absolute, given, relative, hasRules: names.includes(RULES_FILE), ...(owner ? { plugin: owner.plugin, marketplace: owner.marketplace } : {}) }); } async function addAgent(absolute: string, path: string, relative: string): Promise { const key = await itemKey(absolute, path); - if (key) addItem(`agent:${key}`, { type: 'agent', path, absolute, given, relative }); + if (key) addItem(`agent:${key}`, { type: 'agent', path, absolute, given, relative, ...(owner ? { plugin: owner.plugin, marketplace: owner.marketplace } : {}) }); } async function holdsSkill(absolute: string, names: string[]): Promise { return names.includes(SKILL_FILE) && await isRegularFile(join(absolute, SKILL_FILE)); @@ -171,7 +184,7 @@ export async function walkSkillFolders(folders: string[], options: WalkOptions = /** Walk the entries of a listed folder that is not a skill folder, `depth` levels below the given folder. */ async function walkEntries(absolute: string, relative: string, depth: number, names: string[], prefix: string): Promise { if (depth >= MAX_DEPTH) return; - const agents = depth === 1 && relative === AGENTS_FOLDER; + const agents = depth === 1 && relative === agentsAt; for (const name of [...names].sort(compareText)) { // Hidden entries and dependencies are skipped before any other check, links included. if (hidden(name)) continue; @@ -227,6 +240,38 @@ export async function walkSkillFolders(folders: string[], options: WalkOptions = } } + /** Walk a marketplace root through the plugins its manifest lists: each plugin's `skills` and `agents`. */ + async function walkMarketplace(root: string, prefix: string): Promise { + const market = await readMarketplace(root, prefix); + walked.marketplaceFiles.push(join(root, MARKETPLACE_FOLDER, MARKETPLACE_FILE)); + for (const problem of market.problems) { problemOnce(`market:${problem.path}:${problem.message}`, problem); if (problem.severity === 'error') explained = true; } + for (const plugin of market.plugins) { + const display = plugin.relative ? below(prefix, plugin.relative) : prefix || '.'; + if (plugin.relative) { + const key = await itemKey(plugin.absolute, display); + if (!key) continue; + if (skip(`${plugin.relative}/`, key, display)) continue; + } + for (const problem of await checkPluginManifest(plugin, prefix)) problemOnce(`plugin:${problem.path}:${problem.message}`, problem); + owner = { plugin: plugin.name, marketplace: market.name ?? '' }; + const before = found; + const inPlugin = (name: string) => plugin.relative ? `${plugin.relative}/${name}` : name; + for (const [folder, depth] of [['skills', 0], ['agents', 1]] as const) { + const absolute = join(plugin.absolute, folder); + let info; + try { info = await stat(absolute); } catch { continue; } + if (!info.isDirectory()) continue; + const names = await listOrProblem(absolute, below(prefix, inPlugin(folder)), `plugin:${absolute}`, 'Folder cannot be read'); + if (!names) continue; + agentsAt = inPlugin('agents'); + await walkEntries(absolute, inPlugin(folder), depth, names, prefix); + } + agentsAt = AGENTS_FOLDER; + owner = undefined; + if (found === before) problemOnce(`plugin-empty:${plugin.absolute}`, fileProblem(display, `Plugin ${plugin.name} holds no skill and no agent`, 'warning')); + } + } + for (const argument of folders.length ? folders : [undefined]) { const prefix = argument === undefined ? '' : trimSeparators(argument); // How the given folder itself is named in problems and failures. @@ -240,7 +285,7 @@ export async function walkSkillFolders(folders: string[], options: WalkOptions = if (!info.isDirectory()) throw new SkillsFolderError(`Skills path is not a folder: ${self}`); let names; try { names = await list(absolute); } catch { throw new SkillsFolderError(`Skills folder cannot be read: ${self}`); } - found = 0; skipped = 0; matcher = undefined; given = absolute; + found = 0; skipped = 0; explained = false; matcher = undefined; given = absolute; // A given folder that is a skill folder gives that one skill, and no agents; its ignore file has no effect. if (await holdsSkill(absolute, names)) await addSkill(absolute, prefix, basename(absolute), names, ''); else { @@ -258,9 +303,11 @@ export async function walkSkillFolders(folders: string[], options: WalkOptions = try { key = identity(await stat(mapAbsolute, { bigint: true })); } catch { /* reported when read */ } if (!seenMapFiles.has(key)) { seenMapFiles.add(key); walked.mapFiles.push({ path: below(prefix, SKILLS_MAP_FILE), absolute: mapAbsolute }); } } - await walkEntries(absolute, '', 0, names, prefix); + // A folder with a marketplace manifest is read through its plugins only; any other folder is walked. + if (names.includes(MARKETPLACE_FOLDER) && await isRegularFile(join(absolute, MARKETPLACE_FOLDER, MARKETPLACE_FILE))) await walkMarketplace(absolute, prefix); + else await walkEntries(absolute, '', 0, names, prefix); } - walked.folders.push({ path: self, found, ignored: skipped }); + walked.folders.push({ path: self, found, ignored: skipped, explained }); } return walked; } diff --git a/test/browser/serve.mjs b/test/browser/serve.mjs index ba3cf87..4237cf5 100644 --- a/test/browser/serve.mjs +++ b/test/browser/serve.mjs @@ -49,8 +49,13 @@ write(join(extra, 'catalogue', 'stackledger.yaml'), doc('Settings', 'settings', write(join(extra, 'kit', 'notes', 'SKILL.md'), '---\nname: notes\ndescription: Takes Northwind notes.\n---\n'); write(join(extra, 'kit', 'summary', 'SKILL.md'), '---\nname: summary\ndescription: Summarises Northwind notes.\n---\n'); write(join(extra, 'kit', 'stackledger-skills.yaml'), doc('Line', 'notes', ' color: "#E4002B"\n stops: ["skill:notes", "skill:summary"]\n')); +// A marketplace of two plugins holding an agent with one name (skills-site, Plugin on skills pages), a second skills folder of the small site. +write(join(extra, 'market', '.claude-plugin', 'marketplace.json'), JSON.stringify({ name: 'northwind-skills', plugins: [{ name: 'writing', source: './plugins/writing' }, { name: 'review', source: './plugins/review' }] })); +for (const plugin of ['writing', 'review']) { + write(join(extra, 'market', 'plugins', plugin, 'agents', 'reviewer.md'), `---\nname: reviewer\ndescription: Reviews Northwind work for the ${plugin} plugin.\n---\n`); +} execFileSync(process.execPath, [join(root, 'dist', 'cli.js'), 'build', join(extra, 'catalogue'), '--out', join(extra, 'out'), '--date', '2027-06-01', - '--skills', join(extra, 'kit')], { stdio: 'inherit' }); + '--skills', join(extra, 'kit'), '--skills', join(extra, 'market')], { stdio: 'inherit' }); /** `_headers` lines under `/*` as [name, value] pairs. */ const headers = readFileSync(join(out, '_headers'), 'utf8').split('\n').slice(1).filter(Boolean) diff --git a/test/browser/site-skills.spec.ts b/test/browser/site-skills.spec.ts index 98d9fd4..142fdf8 100644 --- a/test/browser/site-skills.spec.ts +++ b/test/browser/site-skills.spec.ts @@ -32,6 +32,18 @@ test('Pages work under the policy', async ({ page }) => { expect(problems).toEqual([]); }); +test('Agents with one name in two plugins', async ({ page }) => { + for (const plugin of ['writing', 'review']) { + await page.goto(`/extra/agents/${plugin}--reviewer/`); + await expect(page.locator('h1')).toHaveText(`${plugin}:reviewer`); + await expect(page.locator('[data-plugin]')).toContainText(`Plugin ${plugin}`); + await expect(page.locator('[data-plugin]')).toContainText('Marketplace northwind-skills'); + } + await page.goto('/extra/skills/'); + await expect(page.getByRole('link', { name: 'writing:reviewer' })).toBeVisible(); + await expect(page.getByRole('link', { name: 'review:reviewer' })).toBeVisible(); +}); + test.describe('Skills list', () => { test.beforeEach(async ({ page }) => { await page.goto('/full/skills/'); }); test('Search', async ({ page }) => { diff --git a/test/integration/skills-marketplace.test.ts b/test/integration/skills-marketplace.test.ts new file mode 100644 index 0000000..3ab5e93 --- /dev/null +++ b/test/integration/skills-marketplace.test.ts @@ -0,0 +1,64 @@ +/** A marketplace root through the built CLI (skill-source: Marketplace root; skills-map-command: Plugin on + * item pages, Qualified page file names, Inputs the map folder must not touch; build-command: Output + * folder and the skill set; skills-site: Plugin on skills pages). Run npm run build && npm test. + * Uses examples/northwind-marketplace, a fictitious marketplace. + */ +import { afterAll, expect, test } from 'vitest'; +import { existsSync, mkdtempSync, readFileSync, realpathSync, rmSync } from 'node:fs'; +import { tmpdir } from 'node:os'; +import { join } from 'node:path'; +import { run } from './helpers.js'; +import { skillSet } from '../skills-helpers.js'; +import { agent, skill } from '../skills-helpers.js'; + +const MARKET = 'examples/northwind-marketplace'; +const temp = realpathSync(mkdtempSync(join(tmpdir(), 'stackledger-marketplace-'))); +afterAll(() => rmSync(temp, { recursive: true, force: true })); + +test('Marketplace read as one set', () => { + const result = run(['skills', 'validate', MARKET]); + expect(result.status).toBe(0); + expect(result.stdout).toContain('Plugin external has a remote source; not read'); + expect(result.stdout).toContain('skills: 2, playbooks: 1, agents: 2, rules: 0, ignored: 0, errors: 0, warnings: 1'); +}); + +test('Agents with one name in two plugins get two pages', () => { + const out = join(temp, 'map'); + const result = run(['skills', 'map', MARKET, '--out', out]); + expect(result.status).toBe(0); + for (const plugin of ['writing', 'review']) { + const page = readFileSync(join(out, 'agents', `${plugin}--reviewer.md`), 'utf8'); + expect(page).toContain(`# ${plugin}:reviewer`); + expect(page).toContain(`Plugin: ${plugin}`); + expect(page).toContain('Marketplace: northwind-skills'); + } + expect(run(['skills', 'map', MARKET, '--out', out, '--check']).status).toBe(0); +}); + +test('Loose skill page has no plugin line', () => { + const root = skillSet({ 'skills/writer/SKILL.md': skill('writer') }); + const out = join(root, 'map'); + expect(run(['skills', 'map', 'skills', '--out', out], root).status).toBe(0); + expect(readFileSync(join(out, 'skills', 'writer.md'), 'utf8')).not.toContain('Plugin:'); +}); + +test('Output in a plugin\'s agents folder', () => { + const root = skillSet({ '.claude-plugin/marketplace.json': '{"name":"northwind","plugins":[{"name":"review","source":"./plugins/review"}]}', + 'plugins/review/agents/reviewer.md': agent('reviewer'), 'plugins/review/skills/checklist/SKILL.md': skill('checklist') }); + const result = run(['skills', 'map', '.', '--out', 'plugins/review/agents/map'], root); + expect(result.status).toBe(2); + expect(existsSync(join(root, 'plugins/review/agents/map'))).toBe(false); +}); + +test('Site pages of the same-named agents', () => { + const out = join(temp, 'site'); + const result = run(['build', 'examples/northwind', '--out', out, '--date', '2027-06-01', '--skills', MARKET]); + expect(result.status).toBe(0); + for (const view of ['full', 'staff']) { + for (const plugin of ['writing', 'review']) { + const file = join(out, view, 'agents', `${plugin}--reviewer`, 'index.html'); + expect(existsSync(file)).toBe(true); + expect(readFileSync(file, 'utf8')).toContain('data-plugin'); + } + } +}, 240_000); diff --git a/test/unit/skills-marketplace-map.test.ts b/test/unit/skills-marketplace-map.test.ts new file mode 100644 index 0000000..ae919a3 --- /dev/null +++ b/test/unit/skills-marketplace-map.test.ts @@ -0,0 +1,43 @@ +/** Page file names and pages of plugin items (skills-map-command spec: Qualified page file names, Plugin + * on item pages; skills-site: Plugin on skills pages). Run npm test. + */ +import { test, expect } from 'vitest'; +import { readSkillSet } from '../../src/skills/source.js'; +import { buildGraph } from '../../src/skills/graph.js'; +import { pageFileName, pagePath } from '../../src/skills/mermaid.js'; +import { buildSkillsData } from '../../src/site/skills-data.js'; +import { agent, skill, skillSet } from '../skills-helpers.js'; + +test('Qualified name', () => { + expect(pageFileName('writing:draft')).toBe('writing--draft'); + expect(pagePath({ kind: 'agent', name: 'review:reviewer' })).toBe('agents/review--reviewer.md'); +}); +test('Qualified name with an invalid part', () => { + expect(pageFileName('writing:Draft')).toBe(`_${Buffer.from('writing:Draft').toString('hex')}`); +}); +test('A qualified name over 64 characters keeps to the hexadecimal form', () => { + expect(pageFileName(`${'a'.repeat(40)}:${'b'.repeat(40)}`).length).toBeLessThanOrEqual(64); + expect(pageFileName(`${'a'.repeat(40)}:${'b'.repeat(40)}`).startsWith('_')).toBe(true); +}); +test('A qualified form never equals a loose name', () => { + expect(pageFileName('a:b')).not.toBe(pageFileName('a-b')); +}); + +const files = { '.claude-plugin/marketplace.json': '{"name":"northwind","plugins":[{"name":"writing","source":"./plugins/writing"},{"name":"review","source":"./plugins/review"}]}', + 'plugins/writing/agents/reviewer.md': agent('reviewer'), 'plugins/review/agents/reviewer.md': agent('reviewer'), 'plugins/review/skills/draft/SKILL.md': skill('draft') }; + +test('Plugin on the graph and the site data', async () => { + const set = await readSkillSet([], { cwd: skillSet(files) }); + const graph = buildGraph(set); + expect(graph.nodes.map(node => [node.name, node.plugin, node.marketplace])).toEqual([ + ['review:draft', 'review', 'northwind'], ['review:reviewer', 'review', 'northwind'], ['writing:reviewer', 'writing', 'northwind']]); + const { data } = buildSkillsData(set); + const pages = data.items.filter(item => item.kind === 'agent'); + expect(pages.map(item => [item.file, item.plugin, item.marketplace])).toEqual([ + ['review--reviewer', 'review', 'northwind'], ['writing--reviewer', 'writing', 'northwind']]); +}); +test('Loose item has no plugin', async () => { + const set = await readSkillSet([], { cwd: skillSet({ 'skills/writer/SKILL.md': skill('writer') }) }); + expect(buildGraph(set).nodes[0]).not.toHaveProperty('plugin'); + expect(buildSkillsData(set).data.items[0]).not.toHaveProperty('plugin'); +}); diff --git a/test/unit/skills-marketplace.test.ts b/test/unit/skills-marketplace.test.ts new file mode 100644 index 0000000..322a8f6 --- /dev/null +++ b/test/unit/skills-marketplace.test.ts @@ -0,0 +1,226 @@ +/** Marketplace roots, plugins and qualified names (skill-source spec: Marketplace root, Marketplace + * manifest, Plugin entries, Plugin sources, Remote plugins, Plugin contents, Plugin manifest, + * Qualified names, Same name in two plugins). Run npm test. Fixtures are fictitious Northwind + * marketplaces in temporary folders (test/skills-helpers.ts). + */ +import { test, expect } from 'vitest'; +import { join } from 'node:path'; +import { readSkillSet } from '../../src/skills/source.js'; +import { agent, link, playbook, skill, skillSet } from '../skills-helpers.js'; + +const manifest = (plugins: unknown[], name: unknown = 'northwind') => JSON.stringify({ name, plugins }); +const entry = (name: string, source: unknown = `./plugins/${name}`) => ({ name, source }); +const MANIFEST = '.claude-plugin/marketplace.json'; +const read = (root: string, folders: string[] = []) => readSkillSet(folders, { cwd: root }); +const names = (set: { skills: { name: string }[] }) => set.skills.map(item => item.name); +const agentNames = (set: { agents: { name: string }[] }) => set.agents.map(item => item.name); + +const TWO_PLUGINS = { + [MANIFEST]: manifest([entry('writing'), entry('review')]), + 'plugins/writing/skills/draft/SKILL.md': skill('draft'), + 'plugins/writing/agents/reviewer.md': agent('reviewer'), + 'plugins/review/skills/checklist/SKILL.md': skill('checklist'), + 'plugins/review/agents/reviewer.md': agent('reviewer'), +}; + +test('Marketplace read as one set', async () => { + const set = await read(skillSet(TWO_PLUGINS)); + expect(set.problems).toEqual([]); + expect(names(set)).toEqual(['writing:draft', 'review:checklist']); + expect(agentNames(set)).toEqual(['writing:reviewer', 'review:reviewer']); + expect(set.skills[0]).toMatchObject({ plain: 'draft', plugin: 'writing', marketplace: 'northwind' }); + expect(set.summary).toMatchObject({ skills: 2, agents: 2, errors: 0 }); +}); + +test('Loose folder', async () => { + const set = await read(skillSet({ 'skills/writer/SKILL.md': skill('writer') })); + expect(set.skills[0]).toMatchObject({ name: 'writer', plain: 'writer' }); + expect(set.skills[0]!.plugin).toBeUndefined(); + expect(set.problems).toEqual([]); +}); + +test('Other folders of the root are not read', async () => { + const set = await read(skillSet({ ...TWO_PLUGINS, 'templates/skill/SKILL.md': skill('template'), 'agents/stray.md': agent('stray') })); + expect(names(set)).toEqual(['writing:draft', 'review:checklist']); + expect(agentNames(set)).not.toContain('stray'); + expect(set.problems).toEqual([]); +}); + +test('Ignore file', async () => { + const set = await read(skillSet({ ...TWO_PLUGINS, '.stackledgerignore': 'plugins/review/\n' })); + expect(names(set)).toEqual(['writing:draft']); + expect(set.ignored).toEqual(['plugins/review']); + expect(set.summary.ignored).toBe(1); +}); + +test('Marketplace given by path keeps display paths', async () => { + const root = skillSet({ 'market/.claude-plugin/marketplace.json': manifest([entry('writing', './plugins/writing')]), 'market/plugins/writing/skills/draft/SKILL.md': skill('draft') }); + const set = await read(root, ['market']); + expect(set.skills[0]!.path).toBe('market/plugins/writing/skills/draft/SKILL.md'); + expect(set.skills[0]!.files[0]!.below).toBe('plugins/writing/skills/draft/SKILL.md'); +}); + +test('Invalid manifest', async () => { + const set = await read(skillSet({ [MANIFEST]: '{ not json', 'plugins/writing/skills/draft/SKILL.md': skill('draft') })); + expect(set.problems.map(p => [p.path, p.message])).toEqual([[MANIFEST, 'Marketplace manifest is not valid JSON']]); + expect(set.skills).toEqual([]); +}); + +test.each([ + ['not an object', '[]', 'Marketplace manifest must be a JSON object'], + ['no name', '{"plugins":[]}', 'Marketplace manifest needs a name'], + ['no plugins list', '{"name":"n"}', 'Marketplace manifest needs a plugins list'], +])('Manifest %s', async (_label, text, message) => { + const set = await read(skillSet({ [MANIFEST]: text })); + expect(set.problems.map(p => p.message)).toContain(message); +}); + +test('Marketplace name that is not a name', async () => { + const set = await read(skillSet({ [MANIFEST]: manifest([entry('writing')], 'North wind '), 'plugins/writing/skills/draft/SKILL.md': skill('draft') })); + expect(set.problems.map(p => p.message)).toEqual(['Marketplace name must be lowercase letters and digits with hyphens between them']); +}); + +test('All plugins remote', async () => { + const set = await read(skillSet({ [MANIFEST]: manifest([entry('external', { source: 'github', repo: 'northwind/external' })]) })); + expect(set.problems.map(p => [p.severity, p.path])).toEqual([['error', '.'], ['warning', MANIFEST]]); +}); + +test('Source of another type', async () => { + const set = await read(skillSet({ ...TWO_PLUGINS, [MANIFEST]: manifest([entry('writing', ['./plugins/writing']), entry('review', 7)]) })); + expect(set.problems.filter(p => p.severity === 'error').length).toBeGreaterThanOrEqual(2); + expect(set.skills).toEqual([]); +}); + +test('Plugin walk order is the manifest order', async () => { + const set = await read(skillSet({ ...TWO_PLUGINS, [MANIFEST]: manifest([entry('review'), entry('writing')]) })); + expect(names(set)).toEqual(['review:checklist', 'writing:draft']); +}); + +test('Manifest with a secret', async () => { + const set = await read(skillSet({ [MANIFEST]: manifest([entry('writing')], '4111111111111111'), 'plugins/writing/skills/draft/SKILL.md': skill('draft') })); + expect(set.problems.some(p => p.severity === 'error' && p.path === MANIFEST)).toBe(true); + expect(JSON.stringify(set.problems)).not.toContain('4111111111111111'); +}); + +test('Duplicate plugin name', async () => { + const set = await read(skillSet({ ...TWO_PLUGINS, [MANIFEST]: manifest([entry('writing'), entry('writing', './plugins/review')]) })); + expect(set.problems.map(p => p.message)).toContain('Plugin writing is listed more than once; the later entry is not read'); + expect(names(set)).toEqual(['writing:draft']); +}); + +test('Plugin name not a name', async () => { + const set = await read(skillSet({ ...TWO_PLUGINS, [MANIFEST]: manifest([entry('Writing Tools', './plugins/writing')]) })); + expect(set.problems.filter(p => p.severity === 'error')).toHaveLength(1); + expect(set.skills).toEqual([]); +}); + +test('Entry without a source', async () => { + const set = await read(skillSet({ ...TWO_PLUGINS, [MANIFEST]: manifest([{ name: 'writing' }, entry('review')]) })); + expect(set.problems.map(p => p.message)).toContain('Plugin writing has no source; not read'); + expect(names(set)).toEqual(['review:checklist']); +}); + +test('Too many plugins', async () => { + const plugins = Array.from({ length: 501 }, (_, index) => entry(`p${index}`, './plugins/review')); + const set = await read(skillSet({ ...TWO_PLUGINS, [MANIFEST]: manifest(plugins) })); + expect(set.problems.filter(p => p.message.includes('over the limit'))).toHaveLength(1); +}); + +test('Remote plugin', async () => { + const set = await read(skillSet({ ...TWO_PLUGINS, [MANIFEST]: manifest([entry('writing'), entry('external', { source: 'github', repo: 'northwind/external' })]) })); + const warnings = set.problems.filter(p => p.severity === 'warning'); + expect(warnings.map(p => p.message)).toEqual(['Plugin external has a remote source; not read (stackledger makes no network call)']); + expect(set.summary.errors).toBe(0); + expect(names(set)).toEqual(['writing:draft']); +}); + +test('Source outside the marketplace', async () => { + const root = skillSet({ 'market/.claude-plugin/marketplace.json': manifest([entry('escape', './../elsewhere')]), 'elsewhere/skills/x/SKILL.md': skill('x') }); + const set = await read(root, ['market']); + expect(set.problems.map(p => p.message)).toContain('Plugin escape source is outside the marketplace; not read'); + expect(set.skills).toEqual([]); +}); + +test('Source through a link that leaves the root', async () => { + const root = skillSet({ 'market/.claude-plugin/marketplace.json': manifest([entry('escape', './plugins/escape')]), 'elsewhere/skills/x/SKILL.md': skill('x'), + 'market/plugins/escape': link('elsewhere') }); + const set = await read(root, ['market']); + expect(set.problems.map(p => p.message)).toContain('Plugin escape source is outside the marketplace; not read'); + expect(set.skills).toEqual([]); +}); + +test('Source without the leading ./', async () => { + const set = await read(skillSet({ ...TWO_PLUGINS, [MANIFEST]: manifest([entry('writing', 'plugins/writing')]) })); + expect(set.problems.filter(p => p.severity === 'error')).toHaveLength(1); + expect(set.skills).toEqual([]); +}); + +test('Missing plugin folder', async () => { + const set = await read(skillSet({ ...TWO_PLUGINS, [MANIFEST]: manifest([entry('gone'), entry('review')]) })); + expect(set.problems.map(p => p.message)).toContain('Plugin gone source folder was not found; not read'); + expect(names(set)).toEqual(['review:checklist']); +}); + +test('Root as the plugin', async () => { + const set = await read(skillSet({ [MANIFEST]: manifest([entry('solo', './')]), 'skills/writer/SKILL.md': skill('writer'), 'agents/helper.md': agent('helper') })); + expect(set.problems).toEqual([]); + expect(names(set)).toEqual(['solo:writer']); + expect(agentNames(set)).toEqual(['solo:helper']); +}); + +test('Plugin listed twice is read once', async () => { + const set = await read(skillSet({ ...TWO_PLUGINS, [MANIFEST]: manifest([entry('writing'), entry('again', './plugins/writing')]) })); + expect(names(set)).toEqual(['writing:draft']); +}); + +test('Agents of a plugin', async () => { + const set = await read(skillSet(TWO_PLUGINS)); + expect(set.agents.find(item => item.name === 'review:reviewer')).toMatchObject({ plugin: 'review', marketplace: 'northwind', plain: 'reviewer' }); +}); + +test('Grouped skills in a plugin', async () => { + const set = await read(skillSet({ [MANIFEST]: manifest([entry('dev')]), 'plugins/dev/skills/java/spec/SKILL.md': skill('spec') })); + expect(names(set)).toEqual(['dev:spec']); +}); + +test('Name differs in plugin.json', async () => { + const set = await read(skillSet({ ...TWO_PLUGINS, 'plugins/review/.claude-plugin/plugin.json': '{"name":"code-review"}' })); + const warnings = set.problems.filter(p => p.severity === 'warning'); + expect(warnings).toHaveLength(1); + expect(warnings[0]!.path).toBe('plugins/review/.claude-plugin/plugin.json'); + expect(names(set)).toContain('review:checklist'); +}); + +test('Plugin.json that is not JSON', async () => { + const set = await read(skillSet({ ...TWO_PLUGINS, 'plugins/review/.claude-plugin/plugin.json': 'nope' })); + expect(set.problems.map(p => [p.severity, p.message])).toEqual([['warning', 'Plugin manifest is not valid JSON']]); +}); + +test('Empty plugin', async () => { + const set = await read(skillSet({ ...TWO_PLUGINS, 'plugins/review/skills/checklist/SKILL.md': '', [MANIFEST]: manifest([entry('writing'), entry('hollow', './plugins/hollow')]), 'plugins/hollow/README.md': 'x' })); + expect(set.problems.map(p => p.message)).toContain('Plugin hollow holds no skill and no agent'); +}); + +test('Qualified name in problems', async () => { + const set = await read(skillSet({ [MANIFEST]: manifest([entry('writing')]), 'plugins/writing/skills/publish/SKILL.md': playbook('publish', 'ghost') })); + expect(set.problems).toMatchObject([{ path: 'plugins/writing/skills/publish/SKILL.md', severity: 'error', message: 'Skill ghost is not in the set' }]); +}); + +test('Same name in two plugins', async () => { + const set = await read(skillSet(TWO_PLUGINS)); + expect(agentNames(set)).toEqual(['writing:reviewer', 'review:reviewer']); + expect(set.summary.agents).toBe(2); +}); + +test('Duplicate inside one plugin', async () => { + const set = await read(skillSet({ [MANIFEST]: manifest([entry('writing')]), 'plugins/writing/agents/a.md': agent('reviewer'), 'plugins/writing/agents/b.md': agent('reviewer') })); + expect(agentNames(set)).toEqual(['writing:reviewer']); + expect(set.problems).toMatchObject([{ path: 'plugins/writing/agents/b.md', severity: 'error', message: 'Name writing:reviewer is already used by plugins/writing/agents/a.md' }]); +}); + +test('Read-only and listing order do not matter', async () => { + const root = skillSet(TWO_PLUGINS); + const reversed = await readSkillSet(['.'], { cwd: root, list: async path => (await (await import('node:fs/promises')).readdir(path)).reverse() }); + expect(names(reversed)).toEqual(names(await read(root))); + expect(join(root)).toBe(root); +}); diff --git a/test/unit/skills-offline.test.ts b/test/unit/skills-offline.test.ts index 12bece3..75bc996 100644 --- a/test/unit/skills-offline.test.ts +++ b/test/unit/skills-offline.test.ts @@ -14,8 +14,8 @@ const IMPORT = /\b(?:import|export)\b[^'";]*?\bfrom\s*['"]([^'"]+)['"]|\bimport\ test('Network not used', () => { const start = readdirSync(join(src, 'skills')).filter(name => name.endsWith('.ts')).map(name => join(src, 'skills', name)); - expect(start.map(file => relative(src, file)).sort()).toEqual(['skills/command.ts', 'skills/frontmatter.ts', 'skills/graph.ts', 'skills/ignore.ts', 'skills/lines.ts', 'skills/map-command.ts', 'skills/mermaid.ts', 'skills/metro.ts', - 'skills/read.ts', 'skills/rules.ts', 'skills/source.ts', 'skills/walk.ts']); + expect(start.map(file => relative(src, file)).sort()).toEqual(['skills/command.ts', 'skills/frontmatter.ts', 'skills/graph.ts', 'skills/ignore.ts', 'skills/lines.ts', 'skills/map-command.ts', 'skills/marketplace.ts', 'skills/mermaid.ts', 'skills/metro.ts', + 'skills/read.ts', 'skills/resolve.ts', 'skills/rules.ts', 'skills/source.ts', 'skills/walk.ts']); const seen = new Set(), queue = [...start], findings: string[] = []; while (queue.length) { const file = queue.pop()!; diff --git a/test/unit/skills-relations.test.ts b/test/unit/skills-relations.test.ts index 6fc0e41..4446a1c 100644 --- a/test/unit/skills-relations.test.ts +++ b/test/unit/skills-relations.test.ts @@ -77,7 +77,7 @@ test('Claude Code subagent', async () => { expect(set.problems).toEqual([]); // The description, given folder and source file are kept for stackledger skills map. const real = realpathSync(join(root, 'agents/reviewer.md')); - expect(set.agents).toEqual([{ name: 'reviewer', path: 'agents/reviewer.md', description: 'Northwind reviewer agent.', given: root, + expect(set.agents).toEqual([{ name: 'reviewer', plain: 'reviewer', path: 'agents/reviewer.md', description: 'Northwind reviewer agent.', given: root, files: [{ path: 'agents/reviewer.md', below: 'agents/reviewer.md', real }], preloads: [] }]); expect(set.found).toEqual([real]); }); diff --git a/test/unit/skills-resolve.test.ts b/test/unit/skills-resolve.test.ts new file mode 100644 index 0000000..0fb5a9e --- /dev/null +++ b/test/unit/skills-resolve.test.ts @@ -0,0 +1,109 @@ +/** Name resolution across plugins (skill-source spec: Name resolution, Resolved relations, Ambiguous + * names, Declared relations, Preloaded skills of an agent, Skill references, Playbook zones). Run npm test. + * Fixtures are fictitious Northwind marketplaces in temporary folders. + */ +import { test, expect } from 'vitest'; +import { readSkillSet } from '../../src/skills/source.js'; +import { zoneMembers } from '../../src/skills/lines.js'; +import { buildSkillsMapModel } from '../../src/skills/metro.js'; +import { agent, playbook, skill, skillSet } from '../skills-helpers.js'; + +const MANIFEST = '.claude-plugin/marketplace.json'; +const market = (...plugins: string[]) => JSON.stringify({ name: 'northwind', plugins: plugins.map(name => ({ name, source: `./plugins/${name}` })) }); +const read = (files: Record) => readSkillSet([], { cwd: skillSet(files) }); +const LINE = (name: string, stops: string[]) => `apiVersion: stackledger/v1alpha1\nkind: Line\nmetadata:\n name: ${name}\nspec:\n color: "#E40026"\n stops: [${stops.map(stop => JSON.stringify(stop)).join(', ')}]\n`; +const errors = (set: { problems: { severity: string }[] }) => set.problems.filter(p => p.severity === 'error'); +const BOTH = { [MANIFEST]: market('writing', 'review'), 'plugins/writing/skills/draft/SKILL.md': skill('draft'), 'plugins/review/skills/draft/SKILL.md': skill('draft') }; +const messages = (set: { problems: { message: string }[] }) => set.problems.map(p => p.message); + +test('Own plugin first', async () => { + const set = await read({ ...BOTH, 'plugins/writing/skills/publish/SKILL.md': playbook('publish', 'draft') }); + expect(set.problems).toEqual([]); + expect(set.skills.find(s => s.name === 'writing:publish')!.skills).toEqual(['writing:draft']); +}); + +test('Plain name from outside', async () => { + const set = await read({ [MANIFEST]: market('writing'), 'plugins/writing/skills/draft/SKILL.md': skill('draft'), 'tools/release/SKILL.md': playbook('release', 'draft') }); + // The marketplace root is the given folder, so a loose folder is a second given folder. + const both = await readSkillSet(['.', 'tools'], { cwd: skillSet({ [MANIFEST]: market('writing'), 'plugins/writing/skills/draft/SKILL.md': skill('draft'), 'tools/release/SKILL.md': playbook('release', 'draft') }) }); + expect(both.skills.find(s => s.name === 'release')!.skills).toEqual(['writing:draft']); + expect(both.problems).toEqual([]); + expect(set.skills.map(s => s.name)).toEqual(['writing:draft']); +}); + +test('Qualified name', async () => { + const set = await readSkillSet(['.', 'tools'], { cwd: skillSet({ ...BOTH, 'tools/release/SKILL.md': playbook('release', 'review:draft') }) }); + expect(set.skills.find(s => s.name === 'release')!.skills).toEqual(['review:draft']); + expect(set.problems).toEqual([]); +}); + +test('Loose item wins over plugin items', async () => { + const set = await readSkillSet(['.', 'tools'], { cwd: skillSet({ [MANIFEST]: market('writing'), 'plugins/writing/skills/draft/SKILL.md': skill('draft'), 'tools/draft/SKILL.md': skill('draft'), 'tools/release/SKILL.md': playbook('release', 'draft') }) }); + expect(set.skills.find(s => s.name === 'release')!.skills).toEqual(['draft']); +}); + +test('Ambiguous name', async () => { + const set = await readSkillSet(['.', 'tools'], { cwd: skillSet({ ...BOTH, 'tools/release/SKILL.md': playbook('release', 'draft') }) }); + expect(set.problems).toMatchObject([{ path: 'tools/release/SKILL.md', severity: 'error', field: 'metadata.stackledger-skills', + message: 'Skill draft is ambiguous: it matches review:draft, writing:draft; use the qualified name' }]); +}); + +test('Agent preload ambiguity', async () => { + const set = await readSkillSet(['.', 'tools'], { cwd: skillSet({ ...BOTH, 'tools/agents/helper.md': agent('helper', 'skills:\n - draft\n') }) }); + expect(set.problems).toMatchObject([{ severity: 'warning', field: 'skills[0]' }]); + expect(set.summary.errors).toBe(0); + expect(set.agents[0]!.preloads).toEqual(['draft']); +}); + +test('Preload from the agent\'s plugin', async () => { + const set = await read({ ...BOTH, 'plugins/review/agents/reviewer.md': agent('reviewer', 'skills:\n - draft\n') }); + expect(set.problems).toEqual([]); + expect(set.agents[0]!.preloads).toEqual(['review:draft']); +}); + +test('Qualified and plain name of one item', async () => { + const set = await readSkillSet(['.', 'tools'], { cwd: skillSet({ [MANIFEST]: market('writing'), 'plugins/writing/skills/draft/SKILL.md': skill('draft'), 'tools/release/SKILL.md': playbook('release', 'draft writing:draft') }) }); + expect(set.problems).toMatchObject([{ severity: 'warning', message: 'writing:draft is listed more than once' }]); + expect(set.skills.find(s => s.name === 'release')!.skills).toEqual(['writing:draft']); +}); + +test('Missing name next to a qualified one', async () => { + const set = await read({ ...BOTH, 'plugins/writing/skills/publish/SKILL.md': playbook('publish', 'nope review:draft') }); + expect(messages(set)).toEqual(['Skill nope is not in the set']); +}); + +test('Playbook listing itself by its plain name', async () => { + const set = await read({ [MANIFEST]: market('writing'), 'plugins/writing/skills/publish/SKILL.md': playbook('publish', 'publish') }); + expect(messages(set)).toEqual(['writing:publish lists itself']); +}); + +test('Qualified stop', async () => { + const set = await read({ ...BOTH, 'stackledger-skills.yaml': LINE('ship', ['skill:writing:draft', 'skill:review:draft']) }); + expect(errors(set)).toEqual([]); + expect(set.map.lines).toHaveLength(1); + expect(buildSkillsMapModel(set).lines[0]!.stops).toEqual(['skill:writing--draft', 'skill:review--draft']); +}); + +test('Ambiguous plain stop', async () => { + const set = await read({ ...BOTH, 'stackledger-skills.yaml': LINE('ship', ['skill:draft', 'skill:writing:draft']) }); + expect(errors(set)).toMatchObject([{ field: 'spec.stops[0]', severity: 'error', message: 'skill draft is ambiguous: it matches review:draft, writing:draft; use the qualified name' }]); +}); + +test('Plain and qualified stops of one item', async () => { + const set = await read({ [MANIFEST]: market('writing'), 'plugins/writing/skills/draft/SKILL.md': skill('draft'), 'plugins/writing/skills/edit/SKILL.md': skill('edit'), + 'stackledger-skills.yaml': LINE('ship', ['skill:draft', 'skill:edit', 'skill:writing:draft']) }); + expect(errors(set)).toMatchObject([{ field: 'spec.stops[2]', message: 'Item is visited more than once' }]); +}); + +test('Wrong kind of a plugin item', async () => { + const set = await read({ [MANIFEST]: market('writing'), 'plugins/writing/skills/publish/SKILL.md': playbook('publish'), 'stackledger-skills.yaml': LINE('ship', ['skill:publish']) }); + expect(messages(set)).toContain('No skill named publish; publish is a playbook'); +}); + +test('Zone by a plain name', async () => { + const files = { [MANIFEST]: market('writing'), 'plugins/writing/skills/draft/SKILL.md': skill('draft'), 'plugins/writing/skills/publish/SKILL.md': playbook('publish', 'draft') }; + const set = await read(files); + expect(zoneMembers(set, 'publish')).toEqual(['playbook:writing:publish', 'skill:writing:draft']); + expect(zoneMembers(set, 'writing:publish')).toEqual(['playbook:writing:publish', 'skill:writing:draft']); + expect(zoneMembers(set, 'draft')).toEqual([]); +}); From 4d8212b0f06d6b94222f9a65454a339ada575f28 Mon Sep 17 00:00:00 2001 From: brunosouzas-agent Date: Sun, 6 Dec 2026 07:21:12 +0000 Subject: [PATCH 3/3] fix: review findings; archive skills-marketplaces Co-Authored-By: Claude Sonnet 5.5 --- AGENTS.md | 4 +- README.md | 4 +- docs/skills.md | 5 +- .../.openspec.yaml | 0 .../2026-12-06-skills-marketplaces}/design.md | 0 .../proposal.md | 0 .../specs/build-command/spec.md | 0 .../specs/skill-source/spec.md | 0 .../specs/skills-map-command/spec.md | 0 .../specs/skills-site/spec.md | 0 .../2026-12-06-skills-marketplaces}/tasks.md | 0 openspec/specs/build-command/spec.md | 7 + openspec/specs/skill-source/spec.md | 222 +++++++++++++++++- openspec/specs/skills-map-command/spec.md | 35 ++- openspec/specs/skills-site/spec.md | 11 + src/site/skills-build.ts | 5 +- src/skills/lines.ts | 9 +- src/skills/map-command.ts | 4 +- src/skills/marketplace.ts | 4 +- src/skills/metro.ts | 2 +- src/skills/walk.ts | 12 +- test/integration/skills-marketplace.test.ts | 17 +- test/unit/skills-marketplace.test.ts | 48 +++- test/unit/skills-resolve.test.ts | 15 +- 24 files changed, 375 insertions(+), 29 deletions(-) rename openspec/changes/{skills-marketplaces => archive/2026-12-06-skills-marketplaces}/.openspec.yaml (100%) rename openspec/changes/{skills-marketplaces => archive/2026-12-06-skills-marketplaces}/design.md (100%) rename openspec/changes/{skills-marketplaces => archive/2026-12-06-skills-marketplaces}/proposal.md (100%) rename openspec/changes/{skills-marketplaces => archive/2026-12-06-skills-marketplaces}/specs/build-command/spec.md (100%) rename openspec/changes/{skills-marketplaces => archive/2026-12-06-skills-marketplaces}/specs/skill-source/spec.md (100%) rename openspec/changes/{skills-marketplaces => archive/2026-12-06-skills-marketplaces}/specs/skills-map-command/spec.md (100%) rename openspec/changes/{skills-marketplaces => archive/2026-12-06-skills-marketplaces}/specs/skills-site/spec.md (100%) rename openspec/changes/{skills-marketplaces => archive/2026-12-06-skills-marketplaces}/tasks.md (100%) diff --git a/AGENTS.md b/AGENTS.md index 5f35a42..7ab2f6a 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -10,9 +10,9 @@ Model: 2 release PR Integration branch: `main` Deliver and verify: a merge into `main` publishes nothing; release-please keeps the release pull request, Bruno merges it, and `release.yml` publishes after he approves the `npm` environment (`docs/release.md`); verify with `npm view @brunosouzas/stackledger version` -Implemented: the catalogue format and `stackledger validate` (`catalogue-model`), the SVG map engine and `stackledger map` (`metro-map-engine`), the read-only MCP server with the `full` and `staff` views (`mcp-server`), `stackledger build` with the static `full` and `staff` sites (`catalogue-site`), the licence report: `stackledger report`, the Reports page and `renewals.ics` of the `full` site (`licence-reports`), and Mac discovery: `stackledger discover`, `stackledger drift` with `--scaffold` and the `stackledger/` annotations (`mac-discovery`), and `stackledger skills validate`, which reads and checks a set of agent skills, playbooks, agents and rules (`skills-source`, code in `src/skills/`), skipping what a `.stackledgerignore` file at the top of a given folder lists (`skills-ignore`, `src/skills/ignore.ts`), and `stackledger skills map`, which writes Markdown pages with Mermaid diagrams of the set's declared relations into a folder it owns, with `--check` for pipelines (`skills-mermaid`, `src/skills/graph.ts`, `mermaid.ts`, `map-command.ts`), and the Skills section of `stackledger build` with `--skills` and `spec.skills.folders`: the skills map file `stackledger-skills.yaml` (`src/skills/lines.ts`), the skills metro map with playbook zones (`src/skills/metro.ts`), the relation diagram (`src/map/relations.ts`), the page data (`src/site/skills-data.ts`, `skills-build.ts`) and the Astro pages under `site/src/pages/{skills,skill-map,rules,playbooks,agents}/` (`skills-site`), and station labels that wrap instead of being cut, with the rule count on skills stations (`station-labels-and-rules`, `src/map/labels.ts`, `layout.ts`), and the home page at `/` with the map at `/map/`, the default title `stackledger` and `spec.site.home` (`site-home`, `site/src/pages/index.astro`, `src/site/relative.ts` for the home links' exemption), and the city backdrop of the software map: `spec.map.backdrop` and `stackledger map --backdrop`, `neutral` or `london`, its OpenStreetMap credit in the SVG and under the site's map frame (`map-backgrounds`, `src/map/backdrops/` generated by `scripts/backdrops/`, `src/map/svg.ts`, colours from the design system's `backdrop` tokens in `src/map/themes.ts`). The publishable npm package, owner-approved release workflow, catalogue repository pipeline template and protected hosting recipes (`catalogue-deployment`) are implemented. Released on npm: 0.1.0 to 0.4.0 as `stackledger` (deprecated), 0.4.1 as `@brunosouzas/stackledger` (the same code under the npm organisation's scope; the command stays `stackledger`), 0.5.0, with the identity of `@brunosouzas/design-system`, since renamed `@brunosouzas/signwright` (`design-system-identity`, `home-banner`, `design-system-pieces`, `round-bends`), 0.5.1, with maps never shown larger than drawn (`map-scale`) and the design system 0.4.0, 0.6.0, with the city backdrop of the software map (`map-backgrounds`) and the design system 0.5.3, and 0.7.0, with the script of interpreter jobs (`launchd-script`) and the helpers apps declare (`app-helpers`), and 0.8.0, with the identity v2 on design system 0.8.1 (`identity-v2`); the fictitious demo is rebuilt by hand following `docs/demo.md`. Where the identity v2 lives: Source fonts through Astro's Fonts API with the local provider (`src/site/build.ts`), its build-time font server bound to loopback (`src/site/loopback.ts`), the font CSS moved into `_astro/fonts.css` before the scan (`moveFontCss` in `src/site/relative.ts`), stackledger's accent, the outline frame, the map's `color.state.*` colours and quoted `font.sans` stack (`src/map/themes.ts`, `src/map/xml.ts`), the wordmark, the footer endorsement and the redrawn art (`scripts/site-art.mjs`). and reading Claude Code plugin marketplaces: a given folder with `.claude-plugin/marketplace.json` is read through its plugins, items are named `plugin:name`, plain names resolve by plugin first, remote plugins are skipped with a warning (`skills-marketplaces`, `src/skills/marketplace.ts`, `resolve.ts`, `examples/northwind-marketplace/`). The rest of the roadmap is not implemented: say so instead of describing files that do not exist. +Implemented: the catalogue format and `stackledger validate` (`catalogue-model`), the SVG map engine and `stackledger map` (`metro-map-engine`), the read-only MCP server with the `full` and `staff` views (`mcp-server`), `stackledger build` with the static `full` and `staff` sites (`catalogue-site`), the licence report: `stackledger report`, the Reports page and `renewals.ics` of the `full` site (`licence-reports`), and Mac discovery: `stackledger discover`, `stackledger drift` with `--scaffold` and the `stackledger/` annotations (`mac-discovery`), and `stackledger skills validate`, which reads and checks a set of agent skills, playbooks, agents and rules (`skills-source`, code in `src/skills/`), skipping what a `.stackledgerignore` file at the top of a given folder lists (`skills-ignore`, `src/skills/ignore.ts`), and `stackledger skills map`, which writes Markdown pages with Mermaid diagrams of the set's declared relations into a folder it owns, with `--check` for pipelines (`skills-mermaid`, `src/skills/graph.ts`, `mermaid.ts`, `map-command.ts`), and the Skills section of `stackledger build` with `--skills` and `spec.skills.folders`: the skills map file `stackledger-skills.yaml` (`src/skills/lines.ts`), the skills metro map with playbook zones (`src/skills/metro.ts`), the relation diagram (`src/map/relations.ts`), the page data (`src/site/skills-data.ts`, `skills-build.ts`) and the Astro pages under `site/src/pages/{skills,skill-map,rules,playbooks,agents}/` (`skills-site`), and reading Claude Code plugin marketplaces: a given folder with `.claude-plugin/marketplace.json` is read through its plugins, items are named `plugin:name`, plain names resolve by plugin first, remote plugins are skipped with a warning (`skills-marketplaces`, `src/skills/marketplace.ts`, `resolve.ts`, `examples/northwind-marketplace/`), and station labels that wrap instead of being cut, with the rule count on skills stations (`station-labels-and-rules`, `src/map/labels.ts`, `layout.ts`), and the home page at `/` with the map at `/map/`, the default title `stackledger` and `spec.site.home` (`site-home`, `site/src/pages/index.astro`, `src/site/relative.ts` for the home links' exemption), and the city backdrop of the software map: `spec.map.backdrop` and `stackledger map --backdrop`, `neutral` or `london`, its OpenStreetMap credit in the SVG and under the site's map frame (`map-backgrounds`, `src/map/backdrops/` generated by `scripts/backdrops/`, `src/map/svg.ts`, colours from the design system's `backdrop` tokens in `src/map/themes.ts`). The publishable npm package, owner-approved release workflow, catalogue repository pipeline template and protected hosting recipes (`catalogue-deployment`) are implemented. Released on npm: 0.1.0 to 0.4.0 as `stackledger` (deprecated), 0.4.1 as `@brunosouzas/stackledger` (the same code under the npm organisation's scope; the command stays `stackledger`), 0.5.0, with the identity of `@brunosouzas/design-system`, since renamed `@brunosouzas/signwright` (`design-system-identity`, `home-banner`, `design-system-pieces`, `round-bends`), 0.5.1, with maps never shown larger than drawn (`map-scale`) and the design system 0.4.0, 0.6.0, with the city backdrop of the software map (`map-backgrounds`) and the design system 0.5.3, and 0.7.0, with the script of interpreter jobs (`launchd-script`) and the helpers apps declare (`app-helpers`), and 0.8.0, with the identity v2 on design system 0.8.1 (`identity-v2`).; the fictitious demo is rebuilt by hand following `docs/demo.md`. Where the identity v2 lives: Source fonts through Astro's Fonts API with the local provider (`src/site/build.ts`), its build-time font server bound to loopback (`src/site/loopback.ts`), the font CSS moved into `_astro/fonts.css` before the scan (`moveFontCss` in `src/site/relative.ts`), stackledger's accent, the outline frame, the map's `color.state.*` colours and quoted `font.sans` stack (`src/map/themes.ts`, `src/map/xml.ts`), the wordmark, the footer endorsement and the redrawn art (`scripts/site-art.mjs`). The rest of the roadmap is not implemented: say so instead of describing files that do not exist. -Layout: `src/` the CLI and its modules (`src/map/` map engine and diagrams, `src/site/` site data, build, publication, `src/discovery/` the Mac sources, sandboxed runner and snapshot); `site/` the Astro project shipped in the package and copied into the build's staging folder; `test/unit`, `test/integration` (vitest) and `test/browser` (Playwright); `examples/northwind/` the fictitious example catalogue and `examples/northwind-machine/` its fictitious Mac snapshot, `examples/northwind-skills/` a fictitious skill set with a skills map file. +Layout: `src/` the CLI and its modules (`src/map/` map engine and diagrams, `src/site/` site data, build, publication, `src/discovery/` the Mac sources, sandboxed runner and snapshot); `site/` the Astro project shipped in the package and copied into the build's staging folder; `test/unit`, `test/integration` (vitest) and `test/browser` (Playwright); `examples/northwind/` the fictitious example catalogue and `examples/northwind-machine/` its fictitious Mac snapshot, `examples/northwind-skills/` a fictitious skill set with a skills map file and `examples/northwind-marketplace/` a fictitious plugin marketplace. - Build: `npm run build` - Test: `npm test` (vitest; build first for CLI integration tests) diff --git a/README.md b/README.md index c9f8463..4a384c7 100644 --- a/README.md +++ b/README.md @@ -242,8 +242,6 @@ spec: `stackledger skills validate` checks agent skills (folders with a `SKILL.md`, in the [Agent Skills format](https://agentskills.io/specification)), playbooks, agents (`agents/*.md`, the Claude Code subagent format) and `rules.md` files as one set: duplicate names, a playbook naming a skill that does not exist, a rule ID defined twice, departures from the specification, and private keys or card numbers. Relations are declared inside the specification's `metadata` field, so `SKILL.md` stays valid for every tool: -Pointed at a Claude Code plugin marketplace root (a folder with `.claude-plugin/marketplace.json`), it reads every local plugin's skills and agents as one set, with items named `plugin:name`; remote plugins are skipped with a warning and nothing is fetched. See [Plugin marketplaces](docs/skills.md#plugin-marketplaces) and `examples/northwind-marketplace/`. - ```yaml metadata: stackledger-kind: playbook @@ -253,6 +251,8 @@ metadata: `stackledger-kind` is `skill` (the default) or `playbook`; the other two keys hold names separated by spaces. Give the folders one agent loads together, and check each tool folder on its own. A `.stackledgerignore` file at the top of a given folder skips templates, examples and test fixtures with `.gitignore` patterns, and the output counts and lists what it skipped. `stackledger skills map` writes the set's declared relations as Markdown pages with Mermaid diagrams into the repository, for offline reading and pull-request diffs, and `--check` fails a pipeline when they are out of date. The format, every check, the map and a CI example: [docs/skills.md](docs/skills.md). With `--skills` or `spec.skills.folders`, `stackledger build` also publishes the set on the site ([Skills on the site](#skills-on-the-site)). +Pointed at a Claude Code plugin marketplace root (a folder with `.claude-plugin/marketplace.json`), it reads every local plugin's skills and agents as one set, with items named `plugin:name`; remote plugins are skipped with a warning and nothing is fetched. See [Plugin marketplaces](docs/skills.md#plugin-marketplaces) and `examples/northwind-marketplace/`. + ## How this project is built stackledger follows spec-driven development: diff --git a/docs/skills.md b/docs/skills.md index 288f062..96555ad 100644 --- a/docs/skills.md +++ b/docs/skills.md @@ -53,6 +53,7 @@ stackledger skills validate examples/northwind-marketplace - **Qualified names.** An item of a plugin is named `plugin:name` (`writing:draft`, `review:reviewer`) and records its plugin and marketplace; the pages, lists and diagrams show the qualified name, and the page also names the plugin and the marketplace. A loose item keeps its plain name. Names are unique per plugin, so agents (or skills) with one name in two plugins are both kept, each with its own page (`agents/writing--reviewer.md`, `/agents/writing--reviewer/`). - **Writing a name.** In `stackledger-skills`, `stackledger-agents`, an agent's `skills`, a skills map file reference (`skill:writing:draft`) and a zone, a plain or a qualified name works. A plain name is looked up among the items of the kind the field names: first in the writer's own plugin, then an exact name (a loose item, or a qualified name), then the only plugin item with that name. When two plugins match, it is an error that lists them and asks for the qualified name (a warning in an agent's `skills`, which a tool only skips). A set of loose folders resolves exactly as before. - **Ignore file and map file.** A `.stackledgerignore` and a `stackledger-skills.yaml` at the top of the marketplace root apply as in any given folder; patterns are relative to the root, so `plugins/legacy/` skips a plugin. Files inside a plugin have no effect. +- **Links.** A plugin's `skills/` or `agents/` that is a link must lead inside the marketplace, like a `source`; otherwise it gets a warning and is not read. - **Limits.** `marketplace.json` and `plugin.json` are limited to 1 MiB and go through the secret rules; a manifest lists at most 500 plugins. A marketplace with an invalid manifest gives that one error, not also "nothing found". ## Ignore file @@ -72,7 +73,7 @@ examples/* **Syntax.** Each line means what it means to Git, as implemented by the [`ignore`](https://www.npmjs.com/package/ignore) package (version 7.0.13): blank lines and `#` comments, `\#` and `\!` for a literal first character, trailing spaces dropped, `!` to re-include (the last matching line wins), a leading or middle `/` to anchor a pattern to the given folder, a trailing `/` for folders only, and the wildcards `*`, `?`, `[...]` and `**`. A folder that is skipped is not entered, so nothing below it can be re-included, as with Git. Matching is case-sensitive on every platform and compares names as stored, without Unicode normalisation. Line endings may be LF or CRLF, and a byte-order mark is dropped. A line Git cannot match (such as `a[`) matches nothing and gives no problem. -**What is tested.** Paths are relative to the given folder, separated by `/`. The walk tests only the entries that can add to the set: each folder (with a trailing `/`), each symbolic link (always without `/`, whatever it points to, as Git does: `shared/` does not skip a link named `shared`, `shared` does), each skill folder's `SKILL.md` (so `fixtures/*/SKILL.md` skips those skills, but not a linked skill, whose inside Git does not look at), and each `.md` file directly in the top-level `agents/` folder. Other files, and links to them, are never tested or counted, and files inside a skill folder other than `SKILL.md`, `rules.md` included, are never skipped (a skill is read whole or not at all). Mind that `*.md` matches every `SKILL.md`, so it hides every skill, as it would hide those files from Git; to hide READMEs write `/README.md` or `**/README.md`. Hidden entries and `node_modules` are skipped before the ignore file is looked at, so a pattern such as `!.claude/` has no effect. +**What is tested.** Paths are relative to the given folder, separated by `/`. The walk tests only the entries that can add to the set: each folder (with a trailing `/`), each symbolic link (always without `/`, whatever it points to, as Git does: `shared/` does not skip a link named `shared`, `shared` does), each skill folder's `SKILL.md` (so `fixtures/*/SKILL.md` skips those skills, but not a linked skill, whose inside Git does not look at), and each `.md` file directly in the top-level `agents/` folder. In a [marketplace root](#plugin-marketplaces) it also tests each plugin folder (with `/`) and the same entries inside the plugin's `skills/` and `agents/`. Other files, and links to them, are never tested or counted, and files inside a skill folder other than `SKILL.md`, `rules.md` included, are never skipped (a skill is read whole or not at all). Mind that `*.md` matches every `SKILL.md`, so it hides every skill, as it would hide those files from Git; to hide READMEs write `/README.md` or `**/README.md`. Hidden entries and `node_modules` are skipped before the ignore file is looked at, so a pattern such as `!.claude/` has no effect. **The `ignored` count and list.** The counts line gives `ignored`, the number of entries the ignore files skipped: each entry once per run (a folder given twice counts once), a skipped folder as one whatever it holds (`fixtures/` counts one, `fixtures/*` counts each entry below it). Hidden entries and `node_modules` are not counted. The JSON output lists the skipped paths, so you can see what a pattern hid. A given folder where everything was skipped still fails with "No skill folder or agent file found", and the message says how many entries `.stackledgerignore` skipped. @@ -233,7 +234,7 @@ stackledger owns, in the output folder, the marker, `.gitattributes`, `README.md Before writing anything, the command refuses (exit 2) an output folder that: - is, or holds, a given folder, or a skill folder, agent file, `SKILL.md`, `rules.md` or `.stackledgerignore` the set was read from, also through a link and also a rejected one (cleaning the map would delete it); -- is inside a skill folder of the set, or is or is inside the top-level `agents/` of a given folder, in any case (`AGENTS`), as its `README.md` would be read as an agent; +- is inside a skill folder of the set, or is or is inside the folder an agent file was read from (the top-level `agents/` of a given folder, or a plugin's `agents/`), in any case (`AGENTS`), as its `README.md` would be read as an agent; - has a folder starting with `.` or named `openspec` (in any case) on its path below the current folder, or from a given folder that holds it down, the given folder's own name included (tool folders such as `.claude/commands` load Markdown as instructions: with `~/.claude` given, `~/.claude/commands/map` is refused); - exists, is not empty and has no valid marker, or whose marker, `.gitattributes`, `README.md` or kind folders are symbolic links. diff --git a/openspec/changes/skills-marketplaces/.openspec.yaml b/openspec/changes/archive/2026-12-06-skills-marketplaces/.openspec.yaml similarity index 100% rename from openspec/changes/skills-marketplaces/.openspec.yaml rename to openspec/changes/archive/2026-12-06-skills-marketplaces/.openspec.yaml diff --git a/openspec/changes/skills-marketplaces/design.md b/openspec/changes/archive/2026-12-06-skills-marketplaces/design.md similarity index 100% rename from openspec/changes/skills-marketplaces/design.md rename to openspec/changes/archive/2026-12-06-skills-marketplaces/design.md diff --git a/openspec/changes/skills-marketplaces/proposal.md b/openspec/changes/archive/2026-12-06-skills-marketplaces/proposal.md similarity index 100% rename from openspec/changes/skills-marketplaces/proposal.md rename to openspec/changes/archive/2026-12-06-skills-marketplaces/proposal.md diff --git a/openspec/changes/skills-marketplaces/specs/build-command/spec.md b/openspec/changes/archive/2026-12-06-skills-marketplaces/specs/build-command/spec.md similarity index 100% rename from openspec/changes/skills-marketplaces/specs/build-command/spec.md rename to openspec/changes/archive/2026-12-06-skills-marketplaces/specs/build-command/spec.md diff --git a/openspec/changes/skills-marketplaces/specs/skill-source/spec.md b/openspec/changes/archive/2026-12-06-skills-marketplaces/specs/skill-source/spec.md similarity index 100% rename from openspec/changes/skills-marketplaces/specs/skill-source/spec.md rename to openspec/changes/archive/2026-12-06-skills-marketplaces/specs/skill-source/spec.md diff --git a/openspec/changes/skills-marketplaces/specs/skills-map-command/spec.md b/openspec/changes/archive/2026-12-06-skills-marketplaces/specs/skills-map-command/spec.md similarity index 100% rename from openspec/changes/skills-marketplaces/specs/skills-map-command/spec.md rename to openspec/changes/archive/2026-12-06-skills-marketplaces/specs/skills-map-command/spec.md diff --git a/openspec/changes/skills-marketplaces/specs/skills-site/spec.md b/openspec/changes/archive/2026-12-06-skills-marketplaces/specs/skills-site/spec.md similarity index 100% rename from openspec/changes/skills-marketplaces/specs/skills-site/spec.md rename to openspec/changes/archive/2026-12-06-skills-marketplaces/specs/skills-site/spec.md diff --git a/openspec/changes/skills-marketplaces/tasks.md b/openspec/changes/archive/2026-12-06-skills-marketplaces/tasks.md similarity index 100% rename from openspec/changes/skills-marketplaces/tasks.md rename to openspec/changes/archive/2026-12-06-skills-marketplaces/tasks.md diff --git a/openspec/specs/build-command/spec.md b/openspec/specs/build-command/spec.md index 342d131..e2b2871 100644 --- a/openspec/specs/build-command/spec.md +++ b/openspec/specs/build-command/spec.md @@ -283,3 +283,10 @@ Both sites for a catalogue of 300 items and 20 lines, with a skill set of 200 sk #### Scenario: Large catalogue and skill set - **WHEN** a generated catalogue of 300 items and 20 lines is built with a generated skill set of that size - **THEN** the command finishes within 150 seconds + +### Requirement: Plugin agents folders in the output check +The output folder SHALL also be refused, with exit 2 and no change, when it is or is inside the folder an agent file was read from (the folder it was found in, not that of a link's target), a plugin's `agents/` included. + +#### Scenario: Output in a plugin's agents folder +- **WHEN** `--skills` is a marketplace root and `--out` is `./plugins/review/agents/site`, where `plugins/review/agents/reviewer.md` was read +- **THEN** the exit code is 2 and nothing is written diff --git a/openspec/specs/skill-source/spec.md b/openspec/specs/skill-source/spec.md index 88feaa5..f4447eb 100644 --- a/openspec/specs/skill-source/spec.md +++ b/openspec/specs/skill-source/spec.md @@ -221,7 +221,7 @@ Keys in `metadata` starting with `stackledger-` in any letter case SHALL be only - **THEN** there is an error with field `metadata.stackledger-skills` saying it must be names separated by spaces ### Requirement: Declared relations -Skills and playbooks MAY declare `stackledger-skills` and `stackledger-agents`, read as names separated by whitespace (spaces, tabs, line breaks); a blank string declares none. Each distinct name not in the set as a skill or playbook (for `stackledger-skills`) or as an agent (for `stackledger-agents`) SHALL be one error with the field, naming it. +Skills and playbooks MAY declare `stackledger-skills` and `stackledger-agents`, read as names separated by whitespace (spaces, tabs, line breaks); a blank string declares none. Each name SHALL be resolved as in "Name resolution". Each distinct name that matches no skill or playbook (for `stackledger-skills`) or no agent (for `stackledger-agents`) SHALL be one error with the field, naming it as written. #### Scenario: Missing skill - **WHEN** a playbook has `stackledger-skills: writer editr` and the set has no `editr` @@ -270,7 +270,7 @@ Each file ending in `.md` directly in an `agents` folder at the top of a given f - **THEN** it is not read as an agent ### Requirement: Preloaded skills of an agent -An agent's `skills`, when present, SHALL be a YAML list of strings; otherwise it SHALL be one warning with field `skills` and no preload is read. Each listed name not in the set as a skill or playbook SHALL be a warning with field `skills[n]`, because the tool loading the agent only skips it. +An agent's `skills`, when present, SHALL be a YAML list of strings; otherwise it SHALL be one warning with field `skills` and no preload is read. Each listed name SHALL be resolved as in "Name resolution", the agent's own plugin first; one matching no skill or playbook SHALL be a warning with field `skills[n]`, because the tool loading the agent only skips it. #### Scenario: Unknown preloaded skill - **WHEN** agent `reviewer` has `skills: [code-review, linting]` and the set has no `linting` @@ -280,8 +280,12 @@ An agent's `skills`, when present, SHALL be a YAML list of strings; otherwise it - **WHEN** an agent has `skills: code-review` - **THEN** there is a warning with field `skills` +#### Scenario: Preload from the agent's plugin +- **WHEN** the agent `review:reviewer` has `skills: [checklist]` and both `review:checklist` and `writing:checklist` exist +- **THEN** it preloads `review:checklist` with no problem + ### Requirement: Unique names -A skill or playbook whose `name` is already used by an earlier skill or playbook of the set SHALL be an error with field `name` on the later file, naming the earlier path, and SHALL NOT join the set. The same SHALL hold for two agents. A skill and an agent MAY share a name. +A skill or playbook whose name is already used by an earlier skill or playbook of the set SHALL be an error with field `name` on the later file, naming the earlier path, and SHALL NOT join the set. The same SHALL hold for two agents. A skill and an agent MAY share a name. Two items of different plugins have different names (see "Qualified names"), so they do not clash. #### Scenario: Same skill name in two folders - **WHEN** different folders `a/writer` and `b/writer` both have `name: writer`, given as `a b` @@ -639,7 +643,7 @@ In a skills map file, each stop and each `MapLayout` station key SHALL be `skill - **THEN** there is an error on that stop, besides the error on `editor`'s file ### Requirement: Playbook zones -In a skills `MapLayout`, each zone of `spec.zones` (`name`, `title`, `color`, as in the catalogue) SHALL name a playbook of the set by its exact name; a name that is no playbook of the set SHALL be an error on that zone's `name`, a reference error like a missing station: the layout is still used and that zone has no member. The zone's members are the playbook and the skills, playbooks and agents its `stackledger-skills` and `stackledger-agents` name in the set. +In a skills `MapLayout`, each zone of `spec.zones` (`name`, `title`, `color`, as in the catalogue) SHALL name a playbook of the set, resolved as in "Name resolution"; a name that is no playbook of the set SHALL be an error on that zone's `name`, a reference error like a missing station: the layout is still used and that zone has no member. The zone's members are the playbook and the skills, playbooks and agents its `stackledger-skills` and `stackledger-agents` name in the set. #### Scenario: Playbook as a zone - **WHEN** the layout declares the zone `release` with a title and a colour, and the playbook `release` loads `writer` and `editor` and uses `reviewer` @@ -667,3 +671,213 @@ The skills map files of several given folders SHALL be read, in folder order, as #### Scenario: One line name in two files - **WHEN** both map files hold a line named `publish` - **THEN** there is an error on the line in `tool`'s file + +### Requirement: Marketplace root +A given folder that is not a skill folder and holds a regular file (or a link to one) at `.claude-plugin/marketplace.json` SHALL be a marketplace root. A marketplace root SHALL be read only through the plugins its manifest lists: its other folders SHALL NOT be walked, and no `agents` folder at its top SHALL be read, except as the `agents` folder of a plugin whose source is the root. A folder without that file SHALL be a loose folder, read as before. + +#### Scenario: Marketplace read as one set +- **WHEN** the given folder holds `.claude-plugin/marketplace.json` listing `writing` at `./plugins/writing` and `review` at `./plugins/review`, and each holds `skills//SKILL.md` and `agents/.md` +- **THEN** the skills and agents of both plugins are in one set + +#### Scenario: Loose folder +- **WHEN** a given folder holds `skills/writer/SKILL.md` and no `.claude-plugin/marketplace.json` +- **THEN** it is read as before and `writer` has no plugin + +#### Scenario: Other folders of the root are not read +- **WHEN** a marketplace root holds `templates/skill/SKILL.md` that no plugin includes +- **THEN** it is not read and there is no problem + +### Requirement: Marketplace root files +`.stackledgerignore` and the skills map file at the top of a marketplace root SHALL apply as in any given folder. A marketplace root that gave no item and an error (an invalid manifest, say) SHALL NOT also be reported as a folder with nothing found. + +#### Scenario: Ignore file +- **WHEN** the root holds `.stackledgerignore` with `plugins/legacy/` +- **THEN** the plugin at `./plugins/legacy` is not read and is counted as ignored + +### Requirement: Marketplace manifest +`marketplace.json` SHALL be a JSON object with a non-empty string `name` and an array `plugins`; each plugin SHALL be an object with `name` and `source`. The file SHALL be at most 1 MiB. A file that is too large, unreadable, not valid JSON, holding a secret, or without `name` or `plugins` SHALL be an error on that file, and the marketplace SHALL give no plugins. + +#### Scenario: Invalid manifest +- **WHEN** `marketplace.json` is not valid JSON +- **THEN** there is exactly one problem, an error on the file, and no item is read + +#### Scenario: Manifest over the limit +- **WHEN** `marketplace.json` is 1 MiB and 1 byte +- **THEN** there is one error on the file saying it is larger than 1 MiB + +#### Scenario: Manifest with a secret +- **WHEN** the manifest holds a payment-card number +- **THEN** there is one error on the file and the number is in no message + +### Requirement: Manifest names and positions +The marketplace `name` SHALL be lowercase letters and digits with single hyphens between them, or the manifest SHALL be an error as an unusable one. Each problem of the manifest SHALL be at its path, `1:1`, with no field, and name the plugin where one is concerned. + +#### Scenario: Marketplace name that is not a name +- **WHEN** the manifest's name is `North wind ` +- **THEN** there is one error on the file and no plugin is read + +### Requirement: Plugin entries +A plugin name SHALL be lowercase letters and digits with single hyphens between them; a name used earlier in the manifest SHALL be an error on the later entry, which is not read. An entry without a string `name`, or with no `source`, SHALL be an error on it and be skipped. At most 500 entries SHALL be read, and each later one SHALL give one error. + +#### Scenario: Too many plugins +- **WHEN** the manifest lists 501 plugins +- **THEN** the first 500 are read and the last gives one error + +#### Scenario: Duplicate plugin name +- **WHEN** two entries are named `writing` +- **THEN** there is one error on the second and its folder is not read + +#### Scenario: Plugin name not a name +- **WHEN** an entry is named `Writing Tools` +- **THEN** there is one error on it and it is skipped + +#### Scenario: Entry without a source +- **WHEN** an entry has `name` and no `source` +- **THEN** there is an error on it and the other entries are read + +### Requirement: Plugin sources +A plugin whose `source` is a string SHALL name a folder of the marketplace: it SHALL start with `./`, stay inside the marketplace root once `..` segments are resolved and links followed, and name an existing folder. A string source that does not meet this, a source of another type than string or object (an array or a number, say), or a missing folder, SHALL be an error on the entry. A plugin folder listed by two entries SHALL be read once, for the first entry, with no problem. +#### Scenario: Source outside the marketplace +- **WHEN** an entry has `source` `./../elsewhere`, or a link inside `plugins/` leads outside the root +- **THEN** there is one error on the entry and nothing outside the root is read + +#### Scenario: Source without the leading ./ +- **WHEN** an entry has `source` `plugins/writing` +- **THEN** there is one error on the entry + +#### Scenario: Missing plugin folder +- **WHEN** `source` is `./plugins/gone` and there is no such folder +- **THEN** there is one error on the entry + +#### Scenario: Same folder twice +- **WHEN** two entries have the source `./plugins/writing` +- **THEN** its items are read once, under the first entry's name, and there is no problem + +#### Scenario: Source of another type +- **WHEN** an entry has `source` `7` or `["./plugins/writing"]` +- **THEN** there is one error on the entry + +#### Scenario: Root as the plugin +- **WHEN** an entry has `source` `./` and the root holds `skills/writer/SKILL.md` +- **THEN** `writer` is read as a skill of that plugin + +### Requirement: Remote plugins +A plugin whose `source` is an object (a GitHub repository, a Git URL, an npm package) SHALL be skipped with one warning naming the plugin and saying it was not read; it SHALL never be fetched. + +#### Scenario: Remote plugin +- **WHEN** an entry has `source` `{ "source": "github", "repo": "northwind/helper" }` +- **THEN** there is one warning naming the plugin, no error, and no network call + +### Requirement: Plugin contents +A plugin SHALL give the skills found below its `skills` folder, walked like a given folder (five levels below the `skills` folder, hidden entries and `node_modules` skipped, the walk not entering a skill folder). A `.stackledgerignore` or skills map file inside a plugin SHALL have no effect, and the `.md` files directly in its `agents` folder, checked as agent files. A missing `skills` or `agents` folder SHALL give no problem. Each item SHALL record its plugin and its marketplace's name. + +#### Scenario: Agents of a plugin +- **WHEN** `plugins/review` holds `agents/reviewer.md` with a valid agent +- **THEN** agent `review:reviewer` is in the set, with plugin `review` and the marketplace's name + +### Requirement: Plugin manifest +When a plugin holds `.claude-plugin/plugin.json` with a string `name` different from the entry's, there SHALL be one warning on `plugin.json` and the entry's name SHALL be used. A `plugin.json` over 1 MiB, unreadable or not valid JSON SHALL be one warning; one holding a secret SHALL be an error and the value SHALL be in no message. A plugin that gives no skill and no agent SHALL give one warning, on the plugin folder's path. + +#### Scenario: Name differs in plugin.json +- **WHEN** the entry is `review` and `plugins/review/.claude-plugin/plugin.json` has `name` `code-review` +- **THEN** one warning on `plugin.json`, and the items are `review:` + +#### Scenario: Empty plugin +- **WHEN** a plugin folder holds neither `skills` nor `agents` +- **THEN** there is one warning naming the plugin + +### Requirement: Qualified names +An item of a plugin SHALL be named `:`, where `` is its frontmatter `name`; an item of a loose folder SHALL keep its frontmatter `name`. Wherever this specification says "name" of an item (messages, relations, references, pages), the qualified name is meant. The frontmatter checks SHALL apply to the plain name. + +#### Scenario: Qualified name in problems +- **WHEN** a plugin's skill `writer` lists a skill that is not in the set +- **THEN** the error is on the plugin skill's `SKILL.md` and names the missing target as written + +#### Scenario: Qualified name of an item in a message +- **WHEN** a plugin's `agents/a.md` and `agents/b.md` both have `name: reviewer` +- **THEN** the error on `agents/b.md` names `writing:reviewer` + +### Requirement: Name resolution +A name written in `stackledger-skills`, `stackledger-agents`, an agent's `skills`, a skills map file reference or a zone SHALL be resolved only among the items of the kind it names (skills and playbooks, agents, or playbooks for a zone), in this order: (1) when the writer is an item of a plugin, that plugin's item with that plain name; (2) the item whose qualified name equals the text exactly, which also finds a loose item; (3) the only plugin item with that plain name. + +#### Scenario: Own plugin first +- **WHEN** skills `writing:draft` and `review:draft` exist and `writing:publish` lists `draft` +- **THEN** it resolves to `writing:draft` with no problem + +#### Scenario: Plain name from outside +- **WHEN** only `writing:draft` has that plain name and a loose playbook lists `draft` +- **THEN** it resolves to `writing:draft` with no problem + +#### Scenario: Qualified name +- **WHEN** a loose playbook lists `review:draft` +- **THEN** it resolves to `review:draft`, whatever other items are named `draft` + +#### Scenario: Only the kind named +- **WHEN** `review:reviewer` is an agent, `writing:reviewer` is the only skill of that name, and `review:x` lists `reviewer` in `stackledger-skills` +- **THEN** it resolves to `writing:reviewer` with no problem + +#### Scenario: Loose item wins over plugin items +- **WHEN** a loose skill `draft` and `writing:draft` exist and a loose playbook lists `draft` +- **THEN** it resolves to the loose skill + +### Requirement: Resolved relations +When nothing matches, the existing missing-item problem SHALL be given. A resolved relation SHALL be stored under the qualified name, so `draft` and `writing:draft` written in one list are one relation and the repeat warning applies. + +#### Scenario: Qualified and plain name of one item +- **WHEN** a loose playbook lists `draft writing:draft` and `writing:draft` is the only `draft` +- **THEN** there is one repeat warning + +### Requirement: Ambiguous names +When step 3 of "Name resolution" finds two or more items, the name SHALL be ambiguous: one error naming every match in code-point order and asking for the qualified name, or a warning for an agent's `skills`, as a missing preload is. An ambiguous name SHALL resolve to nothing. + +#### Scenario: Ambiguous name +- **WHEN** `writing:draft` and `review:draft` exist and a loose playbook lists `draft` +- **THEN** there is one error on `metadata.stackledger-skills` naming `review:draft` and `writing:draft` and asking for the qualified name + +#### Scenario: Agent preload ambiguity +- **WHEN** an agent of no plugin has `skills: [draft]` and two plugins have `draft` +- **THEN** there is one warning with field `skills[0]` and no error + +### Requirement: Same name in two plugins +Names SHALL be unique per plugin: two skills (or two agents) of one plugin with the same name are the existing duplicate error. Items with the same plain name in different plugins SHALL all be kept, each under its qualified name. A plugin name is not qualified by its marketplace: two marketplaces given together that hold a plugin with one name clash on its items' names. + +#### Scenario: Agents with one name in two plugins +- **WHEN** `plugins/writing/agents/reviewer.md` and `plugins/review/agents/reviewer.md` both have `name: reviewer` +- **THEN** both `writing:reviewer` and `review:reviewer` are in the set, and the summary counts two agents + +#### Scenario: Duplicate inside one plugin +- **WHEN** one plugin holds `agents/a.md` and `agents/b.md`, both `name: reviewer` +- **THEN** there is one error on the later file and one agent + +### Requirement: Qualified references +The name in a skills map file reference (everything after the kind and its `:`) SHALL be resolved as in "Name resolution", so a qualified name is written `skill:plugin:name`. A stop and a station key that resolve to one item SHALL be the same station, and a name that is ambiguous SHALL be an error at it that names every match. + +#### Scenario: Qualified stop +- **WHEN** a stop is `agent:review:reviewer` and the set has `review:reviewer` and `writing:reviewer` +- **THEN** there is no problem and the stop is `review:reviewer` + +#### Scenario: Ambiguous plain stop +- **WHEN** a stop is `agent:reviewer` and the set has `review:reviewer` and `writing:reviewer` +- **THEN** there is one error on that stop naming both + +#### Scenario: Plain and qualified stops of one item +- **WHEN** a line stops at `skill:draft` and then at `skill:writing:draft`, and `writing:draft` is the only `draft` +- **THEN** there is an error on the second stop saying the item is visited more than once + +### Requirement: Marketplace walk +A marketplace root SHALL replace the walk of "Finding skill folders" and the top-level `agents` folder of "Agent files": each plugin's `skills` folder is walked, and the `.md` files of its `agents` folder are agent files. Plugins SHALL be walked in manifest order, `skills` then `agents`, entries in code-point order ("One read per item"). + +#### Scenario: Plugins in manifest order +- **WHEN** the manifest lists `review` before `writing` +- **THEN** the set lists the items of `review` first + +### Requirement: Marketplace ignore and empty roots +"Matching paths" SHALL also test each plugin folder (with `/`, except one whose source is the root) and the entries below it, with paths relative to the given folder. A marketplace root in which nothing is found SHALL be the "Folders with nothing found" error, unless the marketplace itself gave an error that explains it. + +#### Scenario: Plugin folder skipped by pattern +- **WHEN** the ignore file holds `plugins/legacy/` +- **THEN** that plugin's items are not read and the ignored count is 1 + +#### Scenario: Marketplace with only remote plugins +- **WHEN** the manifest lists only plugins with remote sources +- **THEN** there is one warning per plugin and one error naming the folder diff --git a/openspec/specs/skills-map-command/spec.md b/openspec/specs/skills-map-command/spec.md index 27ec161..f4978db 100644 --- a/openspec/specs/skills-map-command/spec.md +++ b/openspec/specs/skills-map-command/spec.md @@ -120,7 +120,7 @@ The device and inode of the output folder and of each kind folder, or their abse - **THEN** it is replaced by rename and the exit code is 0 ### Requirement: Page file names -A name SHALL be the page's file name when it matches `^[a-z0-9]+(-[a-z0-9]+)*$`, has at most 64 characters and is not a Windows device name (`con`, `prn`, `aux`, `nul`, `com0`–`com9`, `lpt0`–`lpt9`). Any other name SHALL be written as `_` and the lowercase hexadecimal of its UTF-8 bytes; when that has more than 64 characters, its first 52 characters, `-`, and the first 11 hexadecimal digits of the SHA-256 of those bytes. +A name SHALL be the page's file name when it matches `^[a-z0-9]+(-[a-z0-9]+)*$`, has at most 64 characters and is not a Windows device name (`con`, `prn`, `aux`, `nul`, `com0`–`com9`, `lpt0`–`lpt9`). A qualified name SHALL be written as "Qualified page file names" says. Any other name SHALL be written as `_` and the lowercase hexadecimal of its UTF-8 bytes; when that has more than 64 characters, its first 52 characters, `-`, and the first 11 hexadecimal digits of the SHA-256 of those bytes. #### Scenario: Name with a path - **WHEN** a skill is named `../writer` @@ -315,3 +315,36 @@ Without `--check`, the command SHALL exit 0 when the map was written; 1 when a g #### Scenario: Wrong folder does not empty the map - **WHEN** a marked map exists and the command is given a folder with nothing found in it - **THEN** the exit code is 1 and no page is removed + +### Requirement: Plugin on item pages +The page of an item of a plugin SHALL show, after the kind, a line `Plugin: ` and a line `Marketplace: `; the `h1`, the diagram labels, the lists and the index SHALL use its qualified name. An item of a loose folder SHALL have neither line. Two items with one plain name in different plugins SHALL have two pages. + +#### Scenario: Agents with one name +- **WHEN** the plugins `writing` and `review` of the marketplace `northwind-skills` each hold the agent `reviewer` +- **THEN** `agents/writing--reviewer.md` and `agents/review--reviewer.md` exist, each with its own plugin line, and the index lists both + +#### Scenario: Loose skill page +- **WHEN** a skill comes from a loose folder +- **THEN** its page has no plugin or marketplace line + +### Requirement: Qualified page file names +A qualified name `:` whose two parts both match the pattern of a page file name SHALL be written `--` when that has at most 64 characters; a valid loose name never holds `--`, so the two forms cannot clash. Any other qualified name SHALL be written in the hexadecimal form of the whole name. + +#### Scenario: Qualified name +- **WHEN** the plugin `writing` holds the skill `draft` +- **THEN** its page is `skills/writing--draft.md` + +#### Scenario: Qualified name with an invalid part +- **WHEN** the plugin `writing` holds a skill named `Draft` +- **THEN** its page is the hexadecimal form of `writing:Draft` + +### Requirement: Plugin agents folders +The output folder SHALL also be refused, with exit 2 and nothing written, when it is or is inside the folder an agent file was read from (the folder it was found in, not that of a link's target), a plugin's `agents/` included, or when it holds a marketplace manifest that was read. + +#### Scenario: Output in a plugin's agents folder +- **WHEN** the given folder is a marketplace root and `--out` is `plugins/review/agents/map`, where `plugins/review/agents/reviewer.md` was read +- **THEN** the exit code is 2 + +#### Scenario: Linked agent file +- **WHEN** `agents/reviewer.md` links to `reviewer-agent.md` at the top of the given folder and `--out` is `docs/skills-map` +- **THEN** the exit code is 0 diff --git a/openspec/specs/skills-site/spec.md b/openspec/specs/skills-site/spec.md index 4aca6db..9309f34 100644 --- a/openspec/specs/skills-site/spec.md +++ b/openspec/specs/skills-site/spec.md @@ -275,3 +275,14 @@ On a relation diagram, skills SHALL be `nodeBlock` boxes with radius 6, playbook - **GIVEN** JavaScript is disabled and a 1360-pixel-wide window - **WHEN** the reader opens `/full/skill-map/` - **THEN** the whole map is shown, as wide as its viewBox (within 1 pixel) + +### Requirement: Plugin on skills pages +The page of a skill, playbook or agent of a plugin SHALL show the plugin and the marketplace after the kind, and the lists and the Skills list SHALL name it by its qualified name; its URL SHALL be `/--/`, as the map's page file name says. Two agents with one plain name in different plugins SHALL have two pages. An item of a loose folder SHALL show neither. + +#### Scenario: Agents with one name +- **WHEN** the plugins `writing` and `review` each hold the agent `reviewer` +- **THEN** `/agents/writing--reviewer/` and `/agents/review--reviewer/` exist and each shows its plugin + +#### Scenario: Loose skill +- **WHEN** a skill comes from a loose folder +- **THEN** its page shows no plugin or marketplace diff --git a/src/site/skills-build.ts b/src/site/skills-build.ts index 76ad8a6..8c57c59 100644 --- a/src/site/skills-build.ts +++ b/src/site/skills-build.ts @@ -81,7 +81,10 @@ export function refuseSkillsOutput(target: string, skills: SkillsInUse, ops: FsO } // The folder of each agent file too: a plugin's `agents/` is not the top level of a skills folder. for (const agent of skills.set.agents) { - if (within(target, dirname(agent.files[0]!.real))) throw new Error('Output folder must not be the agents folder of a skills folder or inside it'); + // The folder the agent file was found in, not the folder of a link's target. + let holder = dirname(join(agent.given, agent.files[0]!.below)); + try { holder = ops.realpath(holder); } catch { /* the plain path is checked */ } + if (within(target, holder)) throw new Error('Output folder must not be the agents folder of a skills folder or inside it'); } for (const found of skills.set.found) { if (within(found, target)) throw new Error(`Output folder must not hold a skill folder, agent file or file of the skill set: ${found}`); diff --git a/src/skills/lines.ts b/src/skills/lines.ts index 5ce8bda..29f8a74 100644 --- a/src/skills/lines.ts +++ b/src/skills/lines.ts @@ -156,7 +156,8 @@ function crossCheck(unique: Document[], items: readonly SetItem[], problems: Pro const earlier = positions.get(cell); if (earlier) add(layout, path, `Position already used by ${earlier}`, 'error', true); else positions.set(cell, key); - stations.set(ref, { document: layout, path }); + if (stations.has(ref)) add(layout, path, `Item is already placed by ${stations.get(ref)!.path.join('.')}`, 'error', true); + stations.set(ref, stations.get(ref) ?? { document: layout, path }); } } const zones = new Set(); @@ -164,9 +165,11 @@ function crossCheck(unique: Document[], items: readonly SetItem[], problems: Pro const value = object(zone).name; if (typeof value !== 'string') return; const path: FieldPath = ['spec', 'zones', index, 'name']; - if (zones.has(value)) { add(layout, path, 'Duplicate zone name'); return; } - zones.add(value); const hit = resolveName(setIndex.skills, value); + // Two spellings of one playbook are one zone. + const identity = hit && 'item' in hit ? hit.item.name : value; + if (zones.has(identity)) { add(layout, path, 'Duplicate zone name'); return; } + zones.add(identity); if (hit && 'ambiguous' in hit) add(layout, path, ambiguousMessage('Playbook', value, hit.ambiguous)); else if (!hit || hit.item.kind !== 'playbook') add(layout, path, `Zone must name a playbook of the set; ${value} is not one`); }); diff --git a/src/skills/map-command.ts b/src/skills/map-command.ts index 7acc61b..a721251 100644 --- a/src/skills/map-command.ts +++ b/src/skills/map-command.ts @@ -173,7 +173,9 @@ function checkOutput(out: string, given: string[], set: SkillSet, current: strin } // The folder of each agent file too: a plugin's `agents/` is not the top level of a given folder. for (const agent of set.agents) { - const holder = dirname(agent.files[0]!.real); + // The folder the agent file was found in, not the folder of a link's target. + let holder = dirname(join(agent.given, agent.files[0]!.below)); + try { holder = ops.realpath(holder); } catch { /* the plain path is checked */ } if (within(target, holder)) throw new Error('Output folder must not be the agents folder of a given folder or inside it'); } for (const found of set.found) { diff --git a/src/skills/marketplace.ts b/src/skills/marketplace.ts index 1157bd8..89e4521 100644 --- a/src/skills/marketplace.ts +++ b/src/skills/marketplace.ts @@ -49,7 +49,7 @@ function* strings(value: unknown): Generator { else if (Array.isArray(value)) for (const child of value) yield* strings(child); else if (value !== null && typeof value === 'object') for (const [key, child] of Object.entries(value)) { yield key; yield* strings(child); } } -const insideRoot = (root: string, path: string): boolean => { +export const insideRoot = (root: string, path: string): boolean => { const found = relative(root, path); return found === '' || (found !== '..' && !found.startsWith(`..${sep}`) && !isAbsolute(found)); }; @@ -83,7 +83,7 @@ export async function readMarketplace(root: string, prefix: string): Promise earlier.name === key)) continue; zones.push({ name: key, title: cleanText(zone.title) || cleanText(zone.name) || key, color: zone.color }); for (const member of members) { diff --git a/src/skills/walk.ts b/src/skills/walk.ts index 5783d4e..becede3 100644 --- a/src/skills/walk.ts +++ b/src/skills/walk.ts @@ -29,7 +29,8 @@ import { lstat, readdir, stat } from 'node:fs/promises'; import { basename, join, resolve } from 'node:path'; import { compareText } from '../identity.js'; import { fileProblem, SKILLS_MAP_FILE, type Problem } from '../source.js'; -import { checkPluginManifest, MARKETPLACE_FILE, MARKETPLACE_FOLDER, readMarketplace } from './marketplace.js'; +import { realpath } from 'node:fs/promises'; +import { checkPluginManifest, insideRoot, MARKETPLACE_FILE, MARKETPLACE_FOLDER, readMarketplace } from './marketplace.js'; import { createMatcher, IGNORE_FILE, ignores, readIgnoreFile, type Matcher } from './ignore.js'; /** How many folder levels below a given folder are looked at: `a/b/c/d/e/SKILL.md` is read, `a/b/c/d/e/f/SKILL.md` is not. */ @@ -243,6 +244,8 @@ export async function walkSkillFolders(folders: string[], options: WalkOptions = /** Walk a marketplace root through the plugins its manifest lists: each plugin's `skills` and `agents`. */ async function walkMarketplace(root: string, prefix: string): Promise { const market = await readMarketplace(root, prefix); + let realRoot = root; + try { realRoot = await realpath(root); } catch { /* the root was listed a moment ago; keep its path */ } walked.marketplaceFiles.push(join(root, MARKETPLACE_FOLDER, MARKETPLACE_FILE)); for (const problem of market.problems) { problemOnce(`market:${problem.path}:${problem.message}`, problem); if (problem.severity === 'error') explained = true; } for (const plugin of market.plugins) { @@ -261,6 +264,13 @@ export async function walkSkillFolders(folders: string[], options: WalkOptions = let info; try { info = await stat(absolute); } catch { continue; } if (!info.isDirectory()) continue; + // A link to a folder must stay inside the marketplace, as a plugin's source must. + let real = absolute; + try { real = await realpath(absolute); } catch { continue; } + if (!insideRoot(realRoot, real)) { + problemOnce(`plugin-link:${absolute}`, fileProblem(below(prefix, inPlugin(folder)), `Plugin ${plugin.name} ${folder} folder leaves the marketplace; not read`, 'warning')); + continue; + } const names = await listOrProblem(absolute, below(prefix, inPlugin(folder)), `plugin:${absolute}`, 'Folder cannot be read'); if (!names) continue; agentsAt = inPlugin('agents'); diff --git a/test/integration/skills-marketplace.test.ts b/test/integration/skills-marketplace.test.ts index 3ab5e93..8a02c5b 100644 --- a/test/integration/skills-marketplace.test.ts +++ b/test/integration/skills-marketplace.test.ts @@ -9,7 +9,7 @@ import { tmpdir } from 'node:os'; import { join } from 'node:path'; import { run } from './helpers.js'; import { skillSet } from '../skills-helpers.js'; -import { agent, skill } from '../skills-helpers.js'; +import { agent, link, skill } from '../skills-helpers.js'; const MARKET = 'examples/northwind-marketplace'; const temp = realpathSync(mkdtempSync(join(tmpdir(), 'stackledger-marketplace-'))); @@ -62,3 +62,18 @@ test('Site pages of the same-named agents', () => { } } }, 240_000); + +test('A linked agent file does not block an output folder', () => { + const root = skillSet({ 'repo/skills/writer/SKILL.md': skill('writer'), 'repo/reviewer-agent.md': agent('reviewer'), 'repo/agents/reviewer.md': link('repo/reviewer-agent.md') }); + const result = run(['skills', 'map', '.', '--out', 'docs/skills-map'], join(root, 'repo')); + expect(result.stderr).not.toContain('agents folder'); + expect(result.status).toBe(0); +}); + +test('Build output in a plugin\'s agents folder', () => { + const root = skillSet({ '.claude-plugin/marketplace.json': '{"name":"northwind","plugins":[{"name":"review","source":"./plugins/review"}]}', + 'plugins/review/agents/reviewer.md': agent('reviewer'), 'plugins/review/skills/checklist/SKILL.md': skill('checklist') }); + const result = run(['build', join(process.cwd(), 'examples/northwind'), '--out', 'plugins/review/agents/site', '--date', '2027-06-01', '--skills', '.'], root); + expect(result.status).toBe(2); + expect(existsSync(join(root, 'plugins/review/agents/site'))).toBe(false); +}); diff --git a/test/unit/skills-marketplace.test.ts b/test/unit/skills-marketplace.test.ts index 322a8f6..3472ed3 100644 --- a/test/unit/skills-marketplace.test.ts +++ b/test/unit/skills-marketplace.test.ts @@ -4,7 +4,6 @@ * marketplaces in temporary folders (test/skills-helpers.ts). */ import { test, expect } from 'vitest'; -import { join } from 'node:path'; import { readSkillSet } from '../../src/skills/source.js'; import { agent, link, playbook, skill, skillSet } from '../skills-helpers.js'; @@ -87,7 +86,7 @@ test('All plugins remote', async () => { test('Source of another type', async () => { const set = await read(skillSet({ ...TWO_PLUGINS, [MANIFEST]: manifest([entry('writing', ['./plugins/writing']), entry('review', 7)]) })); - expect(set.problems.filter(p => p.severity === 'error').length).toBeGreaterThanOrEqual(2); + expect(set.problems.filter(p => p.severity === 'error')).toHaveLength(2); expect(set.skills).toEqual([]); }); @@ -98,7 +97,7 @@ test('Plugin walk order is the manifest order', async () => { test('Manifest with a secret', async () => { const set = await read(skillSet({ [MANIFEST]: manifest([entry('writing')], '4111111111111111'), 'plugins/writing/skills/draft/SKILL.md': skill('draft') })); - expect(set.problems.some(p => p.severity === 'error' && p.path === MANIFEST)).toBe(true); + expect(set.problems.filter(p => p.severity === 'error' && p.path === MANIFEST)).toHaveLength(1); expect(JSON.stringify(set.problems)).not.toContain('4111111111111111'); }); @@ -121,9 +120,12 @@ test('Entry without a source', async () => { }); test('Too many plugins', async () => { - const plugins = Array.from({ length: 501 }, (_, index) => entry(`p${index}`, './plugins/review')); - const set = await read(skillSet({ ...TWO_PLUGINS, [MANIFEST]: manifest(plugins) })); + const files: Record = { ...TWO_PLUGINS }; + const plugins = Array.from({ length: 501 }, (_, index) => { files[`plugins/p${index}/skills/s/SKILL.md`] = skill('s'); return entry(`p${index}`); }); + const set = await read(skillSet({ ...files, [MANIFEST]: manifest(plugins) })); expect(set.problems.filter(p => p.message.includes('over the limit'))).toHaveLength(1); + expect(set.skills).toHaveLength(500); + expect(names(set)).not.toContain('p500:s'); }); test('Remote plugin', async () => { @@ -171,6 +173,7 @@ test('Root as the plugin', async () => { test('Plugin listed twice is read once', async () => { const set = await read(skillSet({ ...TWO_PLUGINS, [MANIFEST]: manifest([entry('writing'), entry('again', './plugins/writing')]) })); expect(names(set)).toEqual(['writing:draft']); + expect(set.problems).toEqual([]); }); test('Agents of a plugin', async () => { @@ -222,5 +225,38 @@ test('Read-only and listing order do not matter', async () => { const root = skillSet(TWO_PLUGINS); const reversed = await readSkillSet(['.'], { cwd: root, list: async path => (await (await import('node:fs/promises')).readdir(path)).reverse() }); expect(names(reversed)).toEqual(names(await read(root))); - expect(join(root)).toBe(root); +}); + +test('Two plugin names that are not names give two errors', async () => { + const set = await read(skillSet({ ...TWO_PLUGINS, [MANIFEST]: manifest([entry('Bad One', './plugins/writing'), entry('Bad Two', './plugins/review')]) })); + expect(set.problems.filter(p => p.severity === 'error')).toHaveLength(2); +}); + +test('Manifest over the limit', async () => { + const set = await read(skillSet({ [MANIFEST]: ' '.repeat(1024 * 1024 + 1) })); + expect(set.problems.map(p => [p.path, p.message])).toEqual([[MANIFEST, 'File is larger than 1 MiB; not read']]); +}); + +test('Plugin.json over the limit and with a secret', async () => { + const big = await read(skillSet({ ...TWO_PLUGINS, 'plugins/review/.claude-plugin/plugin.json': ' '.repeat(1024 * 1024 + 1) })); + expect(big.problems.map(p => p.severity)).toEqual(['warning']); + const secret = await read(skillSet({ ...TWO_PLUGINS, 'plugins/review/.claude-plugin/plugin.json': '{"name":"review","description":"4111111111111111"}' })); + expect(secret.problems.map(p => p.severity)).toEqual(['error']); + expect(JSON.stringify(secret.problems)).not.toContain('4111111111111111'); +}); + +test('Ignore file and map file inside a plugin have no effect', async () => { + const set = await read(skillSet({ ...TWO_PLUGINS, 'plugins/review/.stackledgerignore': '*\n', 'plugins/review/stackledger-skills.yaml': 'not: a map\n' })); + expect(names(set)).toEqual(['writing:draft', 'review:checklist']); + expect(set.problems).toEqual([]); +}); + +test('A plugin skills folder that links outside the marketplace is not read', async () => { + const root = skillSet({ 'market/.claude-plugin/marketplace.json': manifest([entry('w')]), 'market/plugins/w/skills': link('outside/skills'), 'market/plugins/w/agents': link('outside/agents'), + 'outside/skills/leaked/SKILL.md': skill('leaked'), 'outside/agents/spy.md': agent('spy') }); + const set = await read(root, ['market']); + expect(set.skills).toEqual([]); expect(set.agents).toEqual([]); + const messages = set.problems.map(p => p.message); + expect(messages).toContain('Plugin w skills folder leaves the marketplace; not read'); + expect(messages).toContain('Plugin w agents folder leaves the marketplace; not read'); }); diff --git a/test/unit/skills-resolve.test.ts b/test/unit/skills-resolve.test.ts index 0fb5a9e..112f901 100644 --- a/test/unit/skills-resolve.test.ts +++ b/test/unit/skills-resolve.test.ts @@ -23,12 +23,10 @@ test('Own plugin first', async () => { }); test('Plain name from outside', async () => { - const set = await read({ [MANIFEST]: market('writing'), 'plugins/writing/skills/draft/SKILL.md': skill('draft'), 'tools/release/SKILL.md': playbook('release', 'draft') }); // The marketplace root is the given folder, so a loose folder is a second given folder. const both = await readSkillSet(['.', 'tools'], { cwd: skillSet({ [MANIFEST]: market('writing'), 'plugins/writing/skills/draft/SKILL.md': skill('draft'), 'tools/release/SKILL.md': playbook('release', 'draft') }) }); expect(both.skills.find(s => s.name === 'release')!.skills).toEqual(['writing:draft']); expect(both.problems).toEqual([]); - expect(set.skills.map(s => s.name)).toEqual(['writing:draft']); }); test('Qualified name', async () => { @@ -107,3 +105,16 @@ test('Zone by a plain name', async () => { expect(zoneMembers(set, 'writing:publish')).toEqual(['playbook:writing:publish', 'skill:writing:draft']); expect(zoneMembers(set, 'draft')).toEqual([]); }); + +test('Only the kind named', async () => { + const set = await read({ [MANIFEST]: market('review', 'writing'), 'plugins/review/agents/reviewer.md': agent('reviewer'), 'plugins/review/skills/x/SKILL.md': playbook('x', 'reviewer'), + 'plugins/writing/skills/reviewer/SKILL.md': skill('reviewer') }); + expect(set.problems).toEqual([]); + expect(set.skills.find(s => s.name === 'review:x')!.skills).toEqual(['writing:reviewer']); +}); + +test('Item placed twice under two spellings', async () => { + const layout = (stations: string[]) => `apiVersion: stackledger/v1alpha1\nkind: MapLayout\nmetadata:\n name: skills\nspec:\n stations:\n${stations.map((s, i) => ` ${JSON.stringify(s)}: [${i * 2}, 0]\n`).join('')}`; + const set = await read({ [MANIFEST]: market('writing'), 'plugins/writing/skills/draft/SKILL.md': skill('draft'), 'stackledger-skills.yaml': layout(['skill:draft', 'skill:writing:draft']) }); + expect(errors(set)).toMatchObject([{ message: expect.stringContaining('already placed') }]); +});