Skip to content

feat(external-skills): pin the Skills CLI and record immutable install provenance - #766

Merged
sumithr merged 33 commits into
mainfrom
feat/issue-513-pin-skills-cli
Oct 1, 2026
Merged

sumithr merged 33 commits into
mainfrom
feat/issue-513-pin-skills-cli

Conversation

@sumithr

@sumithr sumithr commented Sep 29, 2026 •

Copy link
Copy Markdown
Owner

Summary

Pins the external Skills CLI to one exact, reviewed version and records immutable provenance for every external-skill install, so the executable that runs and the bytes an agent later loads are both reproducible and verified.

The key design point, reached after review: sumo-qa clones the install source and checks out the resolved commit itself, then hands the CLI only that local checkout (npx --yes skills@1.7.0 add <absolute path> ...). The CLI never parses a URL or ref, so none of its source-form handling (which can drop or reinterpret #<ref>) can install anything other than the recorded commit.

Related issue

Closes #513

Changes

  • Pinned CLI. One command builder (build_skills_cli_command) is the only place argv is built; it refuses any non-exact pin (latest, ranges, tags), and a once-per-process --version probe must report exactly the pin before any other call. Search and install return the CLI identity used (cli: {package, version, spec}).
  • Source to commit. Sources are validated against an allow-list (owner/repo[@skill], https:///ssh:// git URLs, git@host:path, optional #ref; no credentials, query strings, .., local paths, file://). sumo-qa clones (--filter=blob:none), resolves the ref with rev-parse (tag before branch, annotated tags to their commit, full SHAs as given), checks it out detached, and refuses a checkout whose links leave it or point into .git (the CLI dereferences links when copying). Git runs non-interactively, with an allow-listed transport, and with the caller's repository-location variables (GIT_DIR and friends) dropped.
  • Provenance record. Under an OS advisory lock, each folder the install created or rewrote is recorded in .sumo-qa/external-skills.lock.json (project or home): cloned URL, requested and resolved ref, SHA-256 content digest (JSON-framed over every file and in-folder link target), agent, scope, time, installer identity. Unlistable folders, special files and links leaving the folder cannot be pinned and are refused. If the CLI fails after writing (non-zero exit, timeout, interrupt) or recording fails, the folders the install wrote are rolled back; anything that could not be removed is named rather than left to run unrecorded. Every check that can refuse the run (npx lookup, version probe, argv guard) happens before the before-snapshot, and the snapshot covers every candidate entry by lstat, so rollback never removes an entry the CLI did not write, including a user's dangling alias link.
  • Verification. execute_external_skill searches one scope at a time under that scope's lock, matches the record by the folder on disk, recomputes the digest, and checks the exact SKILL.md bytes it hands over. Any mismatch or non-commit resolved_ref blocks execution. A skill installed outside sumo-qa is reported unrecorded, not blocked (trust policy is [Epic]: Secure external skill discovery, installation, and execution #510's scope).
  • Typed errors. SkillsCLIVersionError, GitNotFoundError, SourceResolutionError, ExternalSkillProvenanceError, ExternalSkillReadError, each with an actionable hint.
  • Windows cmd.exe guard. On Windows npx is a batch file that runs through cmd.exe, which re-parses the command line after Python quotes it: %VAR% and !VAR! expand even inside quotes, and when the npx path holds a space cmd /c strips the outer quotes. build_skills_cli_command therefore refuses any argument containing " % ! ^ & | < > or a line break when npx ends in .cmd or .bat. Native npx on macOS and Linux is unaffected.
  • Windows temp-file fix. _write_atomic in src/sumo_qa/ingest.py, which the provenance lock write reuses, closes its temporary file descriptor if wrapping it fails, and never lets that close replace the original error.
  • MCP schemas. Search/install/execute outputs gain cli / provenance; installed is now always present on success (a failed locate is an error, never a null).
  • Docs. docs/TOOLS.md (pin and provenance), docs/DEVELOPMENT.md (pin upgrade checklist, smoke description), README and ARCHITECTURE one-liners, tool docstrings, regenerated tools-list snapshot.
  • Smoke. external-skills-smoke.yml now also runs a real pinned-CLI install from a local checkout (opt-in SUMO_QA_REAL_CLI_SMOKE=1, set only there) and moves to Node 24 (the package declares engines.node >= 22.20.0).

How it was verified

  • pytest: 4821 passed, 9 skipped, 1 xfailed, 100% coverage (pre-push hook on the final head 14191ea). mypy: no issues. ruff clean. Pre-push hooks, pytest and scoped mutmut, passed on push.
  • Windows CI: the five Windows pytest jobs failed on three tests on 758e544. The cause was a leaked temporary file descriptor in _write_atomic: Windows cannot unlink a file with an open handle, so cleanup failed and masked the real error. Two byte-compared test fixtures are now also written in binary so Windows newline translation no longer changes them. tests/test_ingest.py proves the descriptor is closed on both atomic-write paths and that the original error survives a descriptor that is already closed. Two platform-neutral tests now cover the checkout link walk and the busy-lock timeout, whose other tests need symlinks or fcntl and skip on Windows, so Windows CI also reaches 100% coverage. All 33 checks passed on 94ffdc0, and the scoped mutation gate passed on it.
  • The cmd.exe guard is tested against &, |, <, >, ^, %VAR%, !VAR!, a quote breakout, line breaks and a temp path under R&D Team, for .cmd, .CMD and .bat npx paths, and ordinary names and paths are shown to pass unchanged.
  • Behaviour, on the final head 14191ea: a haiku agent drove the MCP server from the branch wheel in a fresh clone of this repo. It cloned and installed anthropics/skills webapp-testing at commit 8a1541c4 (the remote HEAD) through npx --yes skills@1.7.0 add <checkout>, the record carried source, ref, digest, agent, scope, time and installer, and execute returned verified. Appending a line to the installed SKILL.md blocked execute with a digest mismatch, and setting the recorded resolved_ref to main blocked it as not a commit. Missing npx, a 30s timeout, an ENOTFOUND registry failure and a CLI reporting 9.9.9 each returned their typed error and hint, a floating latest pin was refused before any call, and a CLI that wrote the skill then exited 1 left nothing installed. using_sumo_qa and sumo_qa_load_classifications answered the same on the branch and on main.
  • Merge review: a per-file sumo-qa-reviewing-before-merge pass over every changed file found that a CLI failing after it wrote the skill left an unrecorded, executable folder, and that rollback could unlink a user's dangling alias. Both are fixed test-first here; each fix delta then passed /code-review at high effort.
  • Test-first throughout: every behaviour was red before green, including mutant checks (for example a broken retry that takes the lock but returns the stale read, and an unbounded retry) that the tests reject.
  • End-to-end with real git: install at a pinned commit while HEAD is newer, by annotated tag, by branch, through a fake npx that only accepts skills@1.7.0 and a local path.
  • Real CLI: external-skills-smoke run 36641207212 on this branch passed, proving the real skills@1.7.0 --version prints exactly the pin and find works. The new real-install smoke, run 36641839442 on 758e544, passed: the real skills@1.7.0 add <absolute path> installed a local checkout and the recorded commit and digest verified at execution. Both smokes passed again on the final head, run 36648611848, 2 passed.
  • Review: sumo-qa self-review, then adversarial passes (codex, and /code-review while codex was over its usage limit) until a pass found no correctness defects. Codex was still over that limit for the later Windows fixes, so every adversarial pass on them used the built-in /code-review fallback. Three rounds kept finding source forms where the CLI's own parser dropped #<sha>, which drove the redesign to cloning the commit ourselves (plan approved before implementing).

Known limits

  • The lock is a local record, not a signature: someone who can rewrite the lock file itself can rewrite its recorded commit and digest together. It detects changes to installed content.
  • The content digest covers file paths, bytes and in-folder link targets, not file mode, so a changed executable bit is not detected.
  • A resolved_ref swapped to another well-formed commit SHA is not detected on its own: the installed folder has no git history to compare against, and the digest is what binds the record to the bytes.
  • On Windows, when npx sits under a path containing a space, an argument that contains a space fails to run. This predates the PR and fails closed.
  • A locked execute retry can recreate .sumo-qa/ if something outside sumo-qa deletes it mid-race; this is the cost of bounding execute to two attempts.
  • On a timeout only the npx process is killed; a node child that keeps writing afterwards can leave a folder behind. An OSError or interrupt between a successful CLI exit and the post-run scan also leaves the installed folder unrecorded. Both cases report it as unrecorded, never verified.
  • After a CLI failure, rollback removes every candidate folder whose identity changed during the run, so a sibling skill folder the user edits during those seconds is removed with it.
  • The checkout link check compares paths case-sensitively, so on a case-insensitive filesystem a committed link to .GIT/... is not refused; the bytes it reaches are still pinned by the digest.

Checklist

  • PR title follows Conventional Commits
  • Tests pass locally (pytest) and lint/type checks are green (pre-commit run --all-files, python -m mypy)
  • Added or updated tests covering the change
  • Updated the relevant docs in this same PR
  • No breaking changes (or they are called out above): behaviour changes for callers of the external-skill tools. Local-path and file:// sources are no longer accepted; skill and agent names are validated; sumo_qa_install_external_skill now errors instead of returning installed: null when the installed skill cannot be located and recorded. On Windows, search queries and install paths containing " % ! ^ & | < > or a line break are refused.

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, you can upgrade your account or add credits to your account and enable them for code reviews in your settings.

sumithr added 24 commits October 1, 2026 12:31
…l provenance

Every external-skill subprocess now runs one exact Skills CLI version
(skills@1.7.0) through a single command builder that refuses any non-exact
pin, and each process checks the CLI reports that version before use.

Installs resolve the source ref to a commit with git ls-remote and hand the
CLI <source>#<sha>; the installed folder's SHA-256 digest, source, requested
and resolved ref, agent, scope, time and installer identity are recorded in
.sumo-qa/external-skills.lock.json. Execution re-verifies the record and
blocks on a digest or non-commit ref mismatch. Search and install return the
CLI identity used. New typed errors carry actionable hints.

Closes #513
… annotated tags to their commit

The locator checks .codex/skills before .agents/skills, where the pinned CLI
installs a codex project skill, so a stale copy could be recorded in place of
the install. Record every folder the install created or changed instead, and
refuse an ambiguous unchanged reinstall.

git ls-remote lists an annotated tag's commit only when the peeled name is
requested, so ask for both patterns.
…y the exact SKILL.md bytes handed over

A symlinked folder inside a skill recorded only its target, so the files
behind it could change without a digest mismatch; follow it (pruning cycles).
Execution read SKILL.md again after verifying the folder; read it once and
check those bytes against the verified walk instead.
- Validate skill and agent names so they cannot act as CLI flags (-g, --all,
  *) or paths (../x), and match lock records by the folder on disk so a case
  or path variant of a name cannot run tampered bytes as unrecorded.
- Accept only source forms the pinned CLI installs at a commit (it keeps
  '#<ref>' only for looksLikeGitSource forms), including owner/repo@skill,
  and mirror its SOURCE_ALIASES so the commit is resolved in the repository
  it clones.
- Detect the folders an install wrote by folder identity (the CLI recreates
  them every install) instead of content change, so unchanged and symlinked
  reinstalls work and an untouched copy is never vouched for; try the CLI's
  sanitized folder name first.
- Refuse links leaving the skill folder and non-regular files instead of
  following them; type every read and lock-write failure.
- Re-read and merge the lock at write time with a unique staging file, so
  concurrent installs keep each other's records.
- Verify the body against a SKILL.md entry of any case.
…checks from re-review

- Key digest entries by (kind, path) and hash a JSON encoding, so a link and
  a file named like its entry cannot collide and no name or link target can
  shift bytes between fields.
- Verify the handed-over body against the real in-folder file SKILL.md
  resolves to, so a linked SKILL.md can execute.
- Serialise lock updates with an exclusive guard file, keep the previous
  lock's permissions, and never leave a staging file behind.
- Reject credentials in source URLs, tree/blob URLs, and owner/repo.git
  shorthand; accept frontmatter-style skill names with inner spaces.
… the CLI only a local checkout

Handing the Skills CLI '<source>#<sha>' relied on its URL parser keeping the
ref, and review kept finding source forms where it drops or reinterprets it
(file://, non-.git hosts, release/raw/tree URLs, host rewrites, ?version=).
sumo-qa now clones the source, resolves the ref with rev-parse in the clone,
checks out that commit into a temporary folder and runs 'skills add <path>',
so the installed bytes come from exactly the recorded commit whatever the
source form.

Also: validate sources against a strict allow-list (no credentials, query
strings or '..'), run git non-interactively with an allow-listed transport,
hold one OS advisory lock across snapshot, CLI run and record (released if
the process dies), and write the lock through the shared atomic writer that
refuses a symlinked .sumo-qa.
… roll back unrecordable installs

- Refuse a checkout with a symlink leaving it or pointing into .git before
  the CLI runs: the CLI copies a local source by dereferencing links.
- Remove the folders an install wrote when recording it fails, and make
  execute wait on the install lock, so a sumo-qa install never runs as
  unrecorded.
- Treat a present-but-null record as malformed, not as no record.
- Clear read-only bits before removing temporary checkouts (git object
  files on Windows).
- Document that the lock is a local record, not a signature.
…iases the CLI did not replace

Execute read SKILL.md before taking the install lock, so a skill rolled back
while it waited could still be handed over. It now takes each scope's lock
(once per folder) before locating, reading and verifying.

Rollback compared folders by their dereferenced identity, so a pre-existing
alias link to a folder the CLI recreated counted as written and was deleted.
It now removes only entries whose own (lstat) identity changed.
…e's lock

Taking every scope's lock up front could lock one folder twice under two
spellings (case-insensitive filesystems) and made a project skill wait on,
or fail through, the home lock. Execute now searches project then home,
holding only the lock of the scope it is reading.
…uring an unlocked execute

With no .sumo-qa folder, execute reads without a lock. An install creates
that folder before writing a skill, so if it appears during the read the
install may be mid-way; execute now repeats the read under the lock. The
home-fallback test now also proves a recorded home skill verifies, a
tampered one is blocked, and both are read under the home lock only.
…ed read

The race test now rolls the skill back while the unlocked read is in flight,
so an implementation that takes the lock but returns the first result fails
it (checked against that mutant).
…ils because an install raced it

A surviving-skill race test showed the unlocked pass verifying against the
record a concurrent install had just written and failing closed before the
locked retry could run. An unlocked failure now also triggers the locked
retry when the lock folder appeared; the retry's own failure propagates.
The race tests now cover rollback, replaced-and-recorded, and mismatched
cases.
…te retry to one locked attempt

A skill removed between locating and reading raised a raw FileNotFoundError
that skipped the conditional retry; reads now raise ExternalSkillError and
take the same path. The retry is always locked, so an external process
recreating .sumo-qa cannot keep execute retrying.
…pt and give unreadable skills their own hint

Filesystem errors anywhere in the unlocked attempt (the SKILL.md read, the
record lookup, the digest walk) now take the conditional locked retry, and
otherwise surface as ExternalSkillReadError, chained to the OS error, with a
hint not to reinstall over a skill that is present but unreadable.
…laiming the skill is installed

ExternalSkillReadError now covers any filesystem error while locating,
locking, or reading a skill (including an unreadable file in the digest
walk), and its hint says to surface the named path and check whether the
skill still exists before reinstalling, rather than asserting it is
installed. The unlocked read-failure test also proves no lock is taken and
no .sumo-qa folder is created.
… and report rolled-back installs as such

os.walk skipped unreadable folders silently, so an install could record a
digest that did not cover part of the skill. The walk now raises, and every
filesystem error in it surfaces as ExternalSkillReadError, as do lock
failures. A failure while recording an install is re-raised, after rollback,
as a provenance error that says the install was rolled back, with the cause
chained.
…and report what it could not remove

- Rollback no longer crashes when a written folder already vanished, and
  when removal leaves folders behind it names them as unrecorded instead of
  claiming the install was rolled back.
- A permission copy (chmod) failing after the lock is written no longer
  rolls back an install whose record was saved; cleanup chmods are best
  effort.
- Lock-call failures other than 'busy' (ENOLCK, EOPNOTSUPP) surface as
  ExternalSkillReadError.
- Tests: install-time unlistable folder rolls back; the guard double raises
  the real exception type.
…errupt or crashes on a failed removal

Rollback now removes each replaced entry independently (a failed removal
cannot stop the others), treats an entry it cannot inspect as still present,
reports exactly the entries that remain, and always re-raises an interrupt
unwrapped after attempting it.
…nd never touch uninspectable entries

- An interrupted install that leaves unrecorded folders names them on
  stderr before the interrupt propagates.
- An entry lstat cannot read gets a marker equal to nothing and is reported
  without being chmodded or removed; ENOTDIR counts as absent.
- The Windows lock branch uses a sys.platform guard so mypy type-checks
  it on every platform.
…missing stderr

The notice is written straight to sys.stderr only when it exists and never
raises, so a broken pipe cannot replace the interrupt and a missing stderr
cannot divert it to stdout (the MCP protocol stream). Rollback also never
removes an entry whose identity was unknown before the install; it reports
it instead.
…ream

The broken/missing-stderr test listed monkeypatch before capsys, so on
teardown monkeypatch put back capsys's already-closed stream and, under
pytest -s, later tests writing to stderr failed. Reproduced and fixed by
fixture order.
…rom a hook

Git exports GIT_DIR, GIT_INDEX_FILE and other repository-location variables
to hooks. sumo-qa's clone/rev-parse/checkout inherited them, so run from a
hook they would act on the caller's repository instead of the fresh clone;
they are now dropped (the user's own GIT_CONFIG* settings are kept). The
end-to-end test's own git helper strips GIT_* and disables hooks like the
other git-spawning tests, since under the pre-push hook its 'git init' had
re-initialised the real repository as bare.
… local checkout

The weekly external-skills smoke only exercised 'find'. It now also installs
through the real skills@1.7.0 from a local git repository served as an
https remote, and checks the recorded commit and digest verify at execution
(opt-in via SUMO_QA_REAL_CLI_SMOKE=1, set only in that workflow). The
workflow moves to Node 24 to meet the pinned package's engines.
A failed os.fdopen left the mkstemp fd open. Windows cannot unlink an open
file, so the atomic write's cleanup raised WinError 32, left the .tmp file
behind and masked the real error. Both write paths now close the fd first.

Also write the byte-compared SKILL.md fixtures in binary so Windows newline
translation does not turn them into CRLF.
…ch file

On Windows npx resolves to npx.cmd, which CreateProcess runs through cmd.exe.
cmd.exe re-parses the command line after list2cmdline quoting, so a search
query such as x&calc could run a second command. The single argv builder now
refuses arguments carrying " % ^ & | < > or a newline when npx is a .cmd or
.bat file; a native npx still passes them through unchanged.

Also: keep the original error when fdopen already closed the fd, correct the
green smoke count to 2 passed, and show the local checkout path in the install
schema fixture's argv.
The batch-file guard refused & | < > ^ even inside an argument list2cmdline
quotes, where cmd.exe reads them literally, so every install broke for a
Windows user whose temp path holds a space and an ampersand. Those operators
are now refused only in an unquoted argument. ! joins " % and line breaks as
always refused, since delayed expansion would expand !VAR! inside quotes.
When the npx path holds a space, as the default C:\Program Files install
does, cmd /c strips the outer quotes of the command line and shifts which
spans are quoted, so an operator inside an argument list2cmdline quoted can
still run a second command. Operators are refused in every argument again;
! stays refused alongside " % and line breaks.
The only tests reaching the checkout link walk and the lock-busy timeout need
symlinks or fcntl and are skipped on Windows, so Windows CI fell short of 100%
coverage. Two platform-neutral tests cover both paths.
A Skills CLI that wrote the skill folder and then exited non-zero, timed
out, or was interrupted left that folder behind with no provenance
record, so execute_external_skill handed its bytes over as unrecorded.
The install now rolls back whatever the CLI wrote on any failure, keeps
the CLI's own typed error when nothing remains, and names any folder it
could not remove.
Run the npx lookup, version probe and argv build before the snapshot, so
a refusal never rolls back a folder the CLI did not write, and keep the
post-run scan and recording outside the CLI rollback. A failed rescan
after a CLI failure is now reported instead of silently re-raising the
CLI error.
…lls back

The before snapshot only recorded folders that already held a SKILL.md,
so an alias whose target did not exist yet looked new once the CLI wrote
the canonical folder, and rollback unlinked it. Snapshot every candidate
entry by lstat, with or without a SKILL.md.
@sumithr
sumithr force-pushed the feat/issue-513-pin-skills-cli branch from 94ffdc0 to 14191ea Compare October 1, 2026 10:49
@sumithr
sumithr merged commit 44d0c7f into main Oct 1, 2026
34 checks passed
@sumithr
sumithr deleted the feat/issue-513-pin-skills-cli branch October 1, 2026 11:07
sumithr added a commit that referenced this pull request Oct 1, 2026
🤖 I have created a release *beep* *boop*
---


##
[0.68.0](v0.67.1...v0.68.0)
(2026-10-01)


### Features

* **external-skills:** pin the Skills CLI and record immutable install
provenance ([#766](#766))
([44d0c7f](44d0c7f))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

---------

Co-authored-by: release-please[bot] <release-please[bot]@users.noreply.github.com>
sumithr added a commit that referenced this pull request Oct 1, 2026
#785)

## Summary

`run-eval.sh` decides whether a promptfoo run had provider or judge
errors by comparing a count that node prints. It printed the count as a
number, and node colours numbers when `FORCE_COLOR` is set. The coloured
count never equals `0`, so in any shell with `FORCE_COLOR` set every
clean eval run aborted with exit 3, and the ABORT line printed escape
codes. The count is now printed as a string.

## Related issue

None: found when the pre-push hook failed on
`tests/test_eval_runner_defaults.py` during PR #766 (this shell sets
`FORCE_COLOR=3`).

## Changes

- `tests/evals/promptfoo/run-eval.sh`: log the error count with
`String(...)` so it stays a plain digit.
- `tests/test_eval_runner_defaults.py`: the provider-error test runs
with `FORCE_COLOR=0` and `FORCE_COLOR=3`.

## How it was verified

- Red first: with the old script the `FORCE_COLOR=3` case failed
(`errors=\e[33m1\e[39m`), the `0` case passed.
- `FORCE_COLOR=3 node -e 'console.log(0)'` prints `\e[33m0\e[39m`, which
is the clean-run false abort; `String(0)` prints `0`.
- `tests/test_eval_runner_defaults.py`: 221 passed with `FORCE_COLOR`
unset and with `FORCE_COLOR=3`.
- Pre-push hook from a `FORCE_COLOR=3` shell: `pytest
(pre-push)...Passed`, `Required test coverage of 100% reached`, `mutmut
(pre-push, ...)...Passed`.
- `/code-review` high on the change: no high or medium findings.

## Checklist

- [x] PR title follows [Conventional
Commits](https://www.conventionalcommits.org/)
- [x] Tests pass locally (`pytest`) and lint/type checks are green
(`pre-commit run --all-files`, `python -m mypy`)
- [x] Added or updated tests covering the change
- [x] Updated the relevant docs in this same PR
- [x] No breaking changes (or they are called out above)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Task]: Pin the external Skills CLI and record immutable installation provenance

1 participant