Skip to content

Ship an agent skill for Psalm users - #13152

Merged
orklah merged 24 commits into
vimeo:masterfrom
roxblnfk:feat/user-facing-agent-skill
Nov 23, 2026
Merged

orklah merged 24 commits into
vimeo:masterfrom
roxblnfk:feat/user-facing-agent-skill

Conversation

@roxblnfk

@roxblnfk roxblnfk commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

Psalm now ships an agent skill (skills/psalm) that AI coding agents load when they run Psalm, fix its issues, write annotations or edit psalm.xml. It installs through llm/skills (extra.skills in composer.json), npx skills add vimeo/psalm --skill psalm, or a plain copy of the directory.

  • SKILL.md: the baseline → fix → gate workflow and the rules agents get wrong without it (narrowing instead of @var, unused code per symbol, fixing taint flows, suppressions left to the user).
  • references/: annotations, CLI, config, debugging, taint, bug reports, large cleanups, raising strictness.
  • scripts/: summary.php, explain.php, sandbox.php (uploads a minimal, anonymized repro to psalm.dev, only with the user's consent).
  • tests/AgentSkillTest.php checks that every issue type, CLI option and docs path the skill names exists.

Contributor skills in .agents/skills/ are marked internal, so npx skills add vimeo/psalm installs only psalm.

Benchmarks: #13071 (comment)

Refs #13071

resources/skills/psalm is an Agent Skill for agents that run Psalm on a
user's project: how to run it on the changed files and read the output,
how to fix issues at their source instead of suppressing them, an
annotations cheat sheet, debugging inferred types, psalter and baselines,
psalm.xml, taint findings and checking whether a result is a Psalm bug.
Three scripts summarise a JSON report, print an issue's docs offline and
check a reduced repro on psalm.dev.

extra.skills in composer.json advertises it to tools that install skills
from Composer packages. AgentSkillTest keeps the CLI options, issue types
and docs paths the skill names in sync with the code.

Refs vimeo#13071

Assisted-By: Claude Opus 5.5 <noreply@anthropic.com>
Psalm reads @api, @template, @extends, @readonly, @pure and the other
PHPDoc tags listed in the cheat sheet with the same meaning as their
@psalm- forms, and other tools read them too. The skill now writes those,
keeps the prefix for tags without a plain form, and explains that the
plain @internal is looser than @psalm-internal.

Assisted-By: Claude Opus 5.5 <noreply@anthropic.com>
SKILL.md keeps what every run needs and points to the references for
the rest: the source → sink path of taint findings and the @psalm-trace
details move to taint.md and debugging.md. The references drop rules
SKILL.md already states. The done criterion now allows the changes the
user agreed to. The skill tests count an assertion for files that name
no option or issue type, so they aren't reported as risky.

Assisted-By: Claude Opus 5.5 <noreply@anthropic.com>
…kill

references/cli.md lists the output formats by use, the cache and thread
defaults, --show-info, --stats and --find-references-to. fixing.md puts
stubs, plugins and @api before any suppression and names --alter.
taint.md adds @psalm-taint-unescape and @psalm-flow. --debug already
runs on one thread, so debugging.md drops --threads=1.

Assisted-By: Claude Opus 5.5 <noreply@anthropic.com>
Agents reported success after an edit they never rechecked, made a
library's extensible classes final, added a legacy directory to
projectFiles, and escaped every taint kind after a path check. SKILL.md
now asks for the run after the last edit, treats ClassMustBeFinal like
unused code, points to extraFiles, and says how to declare a check Psalm
can't follow; taint.md shows it for a path kept inside a directory.

Assisted-By: Claude Opus 5.5 <noreply@anthropic.com>
In the benchmark an agent piped Psalm through tail, got no output after
PHP crashed, and reported a clean run. compact prints nothing on success
too, so only the exit code tells them apart.

Assisted-By: Claude Opus 5.5 <noreply@anthropic.com>
SKILL.md starts with three steps: baseline run, fixes, and a gate run
after the last edit. references/cleanup.md covers hundreds of issues:
resolve the PHP and Psalm commands once, agree on the scope, then fix one
file per subagent, one at a time, from a fresh report each time, and
finish with an uncached full run. subagent-fix-prompt.md is the prompt
each subagent gets.

Assisted-By: Claude Opus 5.5 <noreply@anthropic.com>
Its summary of the flow let an agent split the work over parallel
subagents with its own prompts instead of following the phases.

Assisted-By: Claude Opus 5.5 <noreply@anthropic.com>
Agents with 194 issues in 26 files didn't count that as hundreds and
never opened cleanup.md.

Assisted-By: Claude Opus 5.5 <noreply@anthropic.com>
references/strictness.md goes one errorLevel at a time: check that the
current level passes, preview the next one with --error-level without
touching psalm.xml, agree on the target and the leftovers, run Psalter
with the target PHP version, fix declarations before their users, then
switch the level and gate. #[\Override] gets a rule per PHP version,
with symfony/polyfill-php83 for 8.0 to 8.2. config.md now gives 2 as the
default errorLevel, which is what Psalm uses without the attribute.

Assisted-By: Claude Opus 5.5 <noreply@anthropic.com>
The baseline step now ends on a report whose first line picks the path, so
the cleanup threshold is applied to a printed count. Phase 2 sends every
file to a subagent and says why. summary.php names info issues a filter
hid, the report path comes from PHP's temp dir, and annotations.md shows
where Psalm reads a docblock. Tests keep their assertions.

Assisted-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions

github-actions Bot commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

✅ Performance: unchanged · Issues: unchanged

Project Memory (MB) Wall (s) Issues Weighted
✅ laravel 1 690 69.1 $\color{gray}{\textsf{+1.2\%}}$ 26 056 50 823
✅ symfony 3 592 235.1 $\color{gray}{\textsf{-0.5\%}}$ 50 929 100 024
✅ doctrine-orm 391 19.3 $\color{gray}{\textsf{-1.6\%}}$ 3 536 5 606
✅ psl 628 24.4 $\color{gray}{\textsf{+1.0\%}}$ 1 337 5 262
✅ phpunit 470 14.7 $\color{gray}{\textsf{-1.1\%}}$ 1 611 1 216
✅ php-parser 231 10.9 $\color{gray}{\textsf{-1.3\%}}$ 17 168 20 611
✅ tempest 886 27.5 $\color{gray}{\textsf{+2.6\%}}$ 4 909 9 152
✅ amphp-amp 61 1.5 $\color{gray}{\textsf{-5.8\%}}$ 32 79
✅ webmozarts-assert 278 3.2 577 2 714
✅ guzzle-promises 55 1.5 161 402
✅ monolog 153 4.0 $\color{gray}{\textsf{+0.3\%}}$ 914 2 185
✅ drupal 4 738 162.3 $\color{gray}{\textsf{+1.8\%}}$ 98 405 160 595
Total 13 172 573.4 $\color{gray}{\textsf{+0.5\%}}$ 205 635 358 669
How to read this table
  • Memory: Psalm's own peak figure, threads=1. More than +5 % fails, unless the PR changes composer.json.
  • Wall: base and head run on the same runner; ±10 % is noise. Above +20 % warns, never fails. re-run: a reversed second run was taken and the faster kept.
  • Issues: head count, then $\color{red}{\textsf{+added}}$ $\color{green}{\textsf{-removed}}$ against base.
  • Weighted: issues weighted by error level (levels 1–8 as is, always-errors 10, feature-specific and purity suggestions 0). The projects' own code is pinned and their dependencies resolve identically for base and head, so a change means Psalm reports more, fewer or differently serious issues. A rise is not necessarily a regression.
  • Total: sum over the projects compared on both sides. Thresholds apply per project, not to the total.
  • Colors: $\color{red}{\textsf{red}}$ past a fail or warn threshold (or more issues), $\color{green}{\textsf{green}}$ an improvement past noise (or fewer issues), $\color{gray}{\textsf{gray}}$ noise.
  • Performance: regressed if a head run crashed or timed out or a memory or wall delta is red, else improved if one is green, else unchanged. Its icon is the check result: ❌ fail · ⚠️ warn · ✅ pass; the icon next to each project is that project's result, 💥 = not comparable: base crashed or timed out (counts as ⚠️).
  • Issues (heading): the total weighted change, increased · decreased · unchanged, followed by the issues added and removed across the projects, e.g. increased (+175 −128). If the weighted total is zero but issues were added or removed (those weighted 0 changed, or changes offset), it reads changed (+175 −128, weighted unchanged). Informational, never fails the check.

composer.json changed in this PR, so head dependencies were re-resolved; memory and time deltas are informational.

head 4290326 · base 75fa9c2 (merge-base) · workflow run

skills/ is where installers such as skills.sh look by default, so
`npx skills add vimeo/psalm` finds the skill without --full-depth.

Assisted-By: Claude Opus 5.5 <noreply@anthropic.com>
strictness.md gets a checklist for narrowing types of green code and the
inherited-@PARAM trap that turns guards into RedundantCondition. SKILL.md
covers properties a framework fills through reflection and running Psalm
on CI's PHP version; annotations.md notes that @psalm-immutable needs a
pure constructor, parameter defaults included.

Assisted-By: Claude Opus 5.5 <noreply@anthropic.com>
Drop the @var exception for framework-filled properties: it reads as a
licence for any reflection-hydrated data. The CI PHP version note moves
to cli.md, and the tightening section keeps the interface trap and the
check-type-exact pointer without a list of types agents already know.

Assisted-By: Claude Opus 5.5 <noreply@anthropic.com>
Agents already know these types; the section keeps the interface trap,
the check-type-exact pointer and the gate.

Assisted-By: Claude Opus 5.5 <noreply@anthropic.com>
Assisted-By: Claude Opus 5.5 <noreply@anthropic.com>
@roxblnfk

roxblnfk commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor Author

The latest commits (7f24835…ac302e002) add a scenario for tightening the types of code Psalm already passes. It came from tightening the annotations of spiral/temporal-bridge (list<string> → list<non-empty-string>, …).

  • strictness.md, "Tightening passing types": start from the public API, check the inferred type with @psalm-check-type-exact, and watch for the inherited @param trap. A non-empty-string on an interface's @param is inherited by every implementation without its own docblock, so its guard against '' turns into TypeDoesNotContainType (RedundantCondition for an assert()). An explicit @param string $name on the implementation keeps the guard.
  • annotations.md: @psalm-immutable needs a pure constructor, default values of its parameters included (= new Options() → ImpureMethodCall); a class-string<T> lookup narrows to T through instanceof $class, with no @var T.
  • cli.md: run Psalm on the PHP version CI uses, since a Psalm in a tool directory has its own lock file.

The trap, the purity rule and the instanceof narrowing were each checked against master with a small repro.

Benchmark on a small green library (errorLevel 1; a router interface with an implementation that rejects empty names, a service registry, value objects): "Tighten its type annotations so that Psalm checks callers more strictly, without changing what the code does."

Haiku, no skill Haiku, skill Sonnet, no skill Sonnet, skill
Runs 2 4 2 4
Runs with @psalm-suppress 1 0 1 0
Types narrowed, of 4 checked 1.5 2.75 2.5 3.25
Cost per run, $ 0.01 0.01 0.08–0.11 0.09–0.15

Every run kept the behaviour (7/7 hidden checks). Two runs narrowed the route name: Haiku without the skill suppressed the guard's TypeDoesNotContainType, Sonnet with the skill added the explicit @param string on the implementation. The registry still gets @var T in most runs: the agents read strictness.md but not the annotations.md line on instanceof. Samples are small (2–4 runs per cell).

List the defaults of the stricter psalm.xml options, including the
conditional default of findUnusedVariablesAndParams, which the
configuration docs described as plain false.

Assisted-By: Claude Opus 5.5 <noreply@anthropic.com>
@orklah

orklah commented Nov 14, 2026

Copy link
Copy Markdown
Collaborator

Thanks a lot for the idea and the work here, this is a thoughtful addition, and the AgentSkillTest guarding CLI options, issue types and docs paths is a nice touch. Sorry for the delay in getting to this.

A few points to settle before merging:

  1. sandbox.php sends code to a third party. It POSTs the user's code to https://psalm.dev/check. Please say so explicitly in SKILL.md and have the agent get the user's consent before running it, otherwise an agent could ship private code to an external service.
  2. Unrelated docs change. The docs/running_psalm/configuration.md fix for findUnusedVariablesAndParams looks correct against Config.php, but could you move it to its own PR (or at least call it out in the description)?
  3. Contributor skills. npx skills add vimeo/psalm without --skill psalm also installs the 7 skills from .agents/skills/. Could you coordinate with Keep contributor skills out of installers that read the repository #13157 (ideally land that first, or make sure the two don't conflict) so users don't get the contributor skills by accident?
  4. Maintenance. The skill is ~54 KB over 13 files and has to follow CLI options, issue docs and config semantics. The test catches names that disappear, but not semantic changes. Could you add a short note in CONTRIBUTING.md/AGENTS.md about updating skills/psalm when those change, and confirm you're happy to keep maintaining it?
  5. Description. Please trim the description a bit; the benchmark details can stay in the linked Ship a user-facing AI agent skill with the package #13071 comment.

Thanks again!

sandbox.php sends the file to psalm.dev, so the skill now runs it only
after the user agrees. AGENTS.md and CONTRIBUTING.md ask PRs that change
CLI options, issue types or config semantics to update skills/psalm.

Assisted-By: Claude Opus 5.5 <noreply@anthropic.com>
The sandbox uploads the repro to psalm.dev and the bug report makes it
public, so the repro is written as a minimal, anonymized stand-in for
the project's code rather than an excerpt of it.

Assisted-By: Claude Opus 5.5 <noreply@anthropic.com>
skills.sh skips skills whose metadata sets internal, so
`npx skills add vimeo/psalm` offers only the psalm skill. AgentSkillTest
checks that every contributor skill carries the flag and the psalm skill
does not.

Assisted-By: Claude Opus 5.5 <noreply@anthropic.com>
@roxblnfk

roxblnfk commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor Author

@orklah Thanks for the review!

  1. SKILL.md and references/bug-report.md now say that a repro leaves the machine (scripts/sandbox.php uploads it to psalm.dev, the bug report is public), so the agent writes it as a minimal, anonymized stand-in for the project's code, shows it to the user and uploads it only with their consent.
  2. The findUnusedVariablesAndParams docs fix moved to Document the conditional default of findUnusedVariablesAndParams #13750.
  3. Found a simpler way to tell installers which skills to install: skills.sh skips skills marked metadata.internal in their frontmatter, so the contributor skills in .agents/skills/ now carry internal: "true" and npx skills add vimeo/psalm offers only psalm. AgentSkillTest checks that every contributor skill has the flag and skills/psalm doesn't. Composer users weren't affected anyway: llm/skills reads only extra.skills.source, and .agents is export-ignored. So this PR no longer depends on Keep contributor skills out of installers that read the repository #13157.
  4. Added a note to AGENTS.md and CONTRIBUTING.md: a PR that changes a CLI option, an issue type or its docs, or what a psalm.xml option does also updates skills/psalm. As a follow-up, I'd propose setting things up so the skill keeps itself current: contributors' agents would get Matt Pocock's writing-for-agents skill for writing skills and AGENTS.md, so the agent that adds a feature or changes behaviour also updates skills/psalm in the same PR, with AgentSkillTest catching the names that go stale. If that sounds good, I'll open a separate PR for it as part of the rework of Keep contributor skills out of installers that read the repository #13157.
  5. Trimmed the description; the benchmark details stay in the Ship a user-facing AI agent skill with the package #13071 comment.

@orklah orklah added the release:feature The PR will be included in 'Features' section of the release notes label Nov 23, 2026
@orklah

orklah commented Nov 23, 2026

Copy link
Copy Markdown
Collaborator

Thanks @roxblnfk!

@orklah
orklah merged commit d22e4ab into vimeo:master Nov 23, 2026
73 of 74 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release:feature The PR will be included in 'Features' section of the release notes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants