Skip to content

feat(external-skills): preview, trust policy, safety lint, and rollback for external skills - #845

Merged
sumithr merged 15 commits into
mainfrom
feat/issue-520-external-skill-trust
Oct 5, 2026
Merged

sumithr merged 15 commits into
mainfrom
feat/issue-520-external-skill-trust

Conversation

@sumithr

@sumithr sumithr commented Oct 4, 2026 •

Copy link
Copy Markdown
Owner

Summary

confirmed=true recorded consent to install an external skill but never showed the exact payload, its source trust or its instruction risks, and an installed SKILL.md was handed to the host as executable guidance with no safety boundary or rollback. Now the user previews an exact immutable payload, sources are checked against a trust policy, a deterministic lint flags known dangerous shapes (critical findings block), every write is approved by the user in a prompt the server shows through MCP elicitation, the handoff marks the skill untrusted, and a single-agent install can be rolled back.

Related issue

Closes #520

Changes

  • src/sumo_qa/external_skills.py:
    • Preview (preview_external_skill): stages the pinned Skills CLI's output in a scratch folder (removed on every path) and returns commit, per-file size/sha256/executable bit, content_digest, trust tier, capabilities and lint findings; installs nothing. Links out of the checkout or into .git are refused.
    • User approval by elicitation: install, restore and remove ask the user directly through MCP form elicitation before any write. The prompt shows source, commit, digest, trust and reasons, every folder the CLI may write for the agent with what it would replace, and the lint findings (executable-file findings always listed). Payload-derived text is escaped. A decline, a dismissed prompt, a 300 s timeout or a cancelled call writes nothing. A host without form elicitation is refused with a pinned manual command the user can run themselves; there is no fallback to the agent's approval. The folder states the prompt showed are compared again under the write guard.
    • Approval-bound install: install requires approved_digest, re-stages, and refuses before writing if the digest differs or a critical finding exists, then checks every written folder against the approved digest and executable set. A failed install puts each folder back as it was (an update keeps the previous version) or removes a new one.
    • Trust policy: standard only for a trusted source pinned to a commit SHA; otherwise elevated (unlisted_source, mutable_ref) and needs elevated_trust=true. Allow/deny lists come from ~/.sumo-qa/external-skills.policy.json only; a broken policy fails closed. Source identity is normalised so a deny entry cannot be bypassed by spelling.
    • Lint (SQA-EXT-001..018, findings carry rule/severity/file/line/count/message, never the matched text): a known-shape detector, not a malware detector. Critical rules block with no override, including 018 for a file over the 1 MiB lint cap. Lines break at \r\n, \r and \n only. Every payload file is linted whatever its bytes.
    • Lock: each record carries content_digest (bytes and paths, identical on every platform) and executable_files, checked on POSIX at execute and rollback.
    • Execute: re-lints SKILL.md, verifies files against the record, and returns trust: "untrusted" with framing that forbids overriding higher-priority instructions.
    • History and rollback: up to 10 superseded records per folder; rollback_external_skill restores the previous approved version of a single-agent install or removes a first install. A skill recorded for more than one agent is refused as shared; every check re-runs under the restore's own guard.
  • src/sumo_qa/server.py, server_schemas.py, tool_registry.py: new tools sumo_qa_preview_external_skill and sumo_qa_rollback_external_skill (both in the external group), install gains approved_digest/elevated_trust, the elicitation approver, strict output models and rollback error hints.
  • skills/sumo-qa-suggesting-external-skill/SKILL.md: preview step, approval flow, untrusted framing, undo step. Docs: docs/TOOLS.md, docs/CONFIGURATION.md, docs/ARCHITECTURE.md, README.md, scenarios.

Behaviour change: install now needs approved_digest from a preview and the user's yes in the elicitation prompt; confirmed=true alone no longer installs. The bundled skill is updated in this PR.

Drift from the issue text (recorded on #520): #513 already provided digest verification; rollback of a first install stands in for a separate uninstall tool; the bounded per-folder history is the install history; the policy file is read from home only; approval moved from the agent's [y/N] to server-side elicitation.

How it was verified

  • Pre-push full suite on the final head: 6223 passed, 8 skipped, 1 xfailed, 100% coverage; mypy, ruff and format clean. Windows CI covers the platform-conditional paths.
  • Real-surface behaviour ledger (every behaviour in [Task]: Add external skill preview, trust policy, safety linting, and rollback #520), driven through the real sumo-qa server over stdio with an MCP client answering the elicitation prompt (accept, decline, no callback) and the real pinned skills@1.7.0, on a fresh clone and a temp HOME; the real ~/.claude/skills, ~/.agents, ~/.codex and ~/.sumo-qa unchanged before and after. Covered: install gate and prompt contents, elevated trust, lint findings (including an over-cap file, a vertical-tab-split pipe and CR-only line endings), critical block with zero prompts, edited-content and changed-executable refusal at execute, untrusted handoff, rollback restore and remove (including a symlinked ~/.claude), lock contents, and a headless haiku claude -p agent unable to install without the user.
  • existing flow: using_sumo_qa, check_external_skill_installed and search_external_skills return identical output on this branch and on main through the same agent.
  • Evals (haiku candidate, Claude judge): skill-suggesting-external-skill.yaml 1/1 and the conversion config 10/10; no eval input changed since, so the results are reused.
  • Mutation gate: strict gate passed with 0 survivors.
  • Review: sumo-qa per-file review and /code-review high on the whole diff, then on each fix delta (13 rounds); the last three rounds were limited to regressions against main, writes without a user yes, unmet acceptance criteria and false docs.

Known limitations

  • Claude Code 2.1.289 opens with the 2026-07-28 protocol (server/discover). On that protocol the server cannot send an elicitation prompt, so every install through sumo-qa from that host is refused with the manual command. Safe (nothing is written without a yes), but the in-chat approval does not appear there. The 2026 InputRequiredResult flow is not supported.
  • A global claude-code install with CLAUDE_CONFIG_DIR outside ~/.claude fails after the CLI writes, and one pointing at another tracked root is not backed up before an update (both pre-existing on main): [Bug]: global claude-code external skill install fails and leaves an unrecorded folder when CLAUDE_CONFIG_DIR is set #847.
  • An executable bit set after the preview is shown to the user as SQA-EXT-010 in the install prompt, not refused.
  • Lint limits (documented): homoglyphs, base64-to-shell, | fish, a pipe after a bare carriage return (a shell reads \r as an ordinary character, the lint reads it as a line break, as on main), two-step download-then-run and other spellings outside the listed shapes. The preview, the user's approval and the untrusted handoff are the primary controls.
  • Rollback of a skill installed for more than one agent is refused; remove or reinstall it by hand.
  • The suggesting-external-skill SKILL.md, its eval quote and SCENARIOS.md carry em-dashes on lines this PR rewrote; scripts/check_no_em_dashes.py does not scan skills/.

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)

…ck for external skills

Installing an external skill now takes a previewed, user-approved payload:

- sumo_qa_preview_external_skill stages the resolved commit through the
  pinned Skills CLI into a scratch folder and returns its files (size,
  SHA-256, executable bit), content_digest, source trust tier, detected
  capabilities, and safety-lint findings. It installs nothing.
- sumo_qa_install_external_skill requires approved_digest (the preview's
  content_digest) and refuses a payload that no longer matches it, so an
  upstream change after the preview writes nothing. A mutable ref or a
  source outside the trust policy needs elevated_trust; a denied source is
  rejected. The trust policy is read from ~/.sumo-qa only.
- A deterministic lint with stable rule ids (SQA-EXT-001..013) flags
  instruction override, concealment, piped remote code, credential files,
  writes outside the project, and destructive deletes as critical, which
  block install and handoff with no override; lower severities are
  disclosed. Findings never carry the matched text.
- Execution lints SKILL.md again and marks the body untrusted, framed so it
  cannot override system, developer, user, or sumo-qa instructions.
- A reinstall keeps the superseded record in a bounded per-folder history.
  sumo_qa_rollback_external_skill restores the previous approved version
  from its recorded commit and digest, or removes a first install.

The suggesting-external-skill skill gains the preview step and a separate
payload-approval gate; docs cover the flow and the trust policy file.

Refs #520
…keep critical lint to dangerous shapes

Trust policy: every spelling of a repository (case, scheme, user, port,
www., trailing slash, .git) now maps to one identity on both sides, so
denied_sources cannot be bypassed by respelling; entries naming a #ref or
@skill fail closed.

Rollback: acts only on <root>/<name> lock keys (a repo-shipped lock with a
.. or absolute key is refused), needs an agent when several agents' installs
match, refuses to delete a first install whose folder no longer holds the
recorded digest, re-checks trust for the version it restores
(elevated_trust parameter, threaded through the server tool), refuses a
history record for another skill, and reinstates the original record. Errors
carry rollback-specific hints.

Lock: history must be lists of records with the fields rollback reads; a
reinstall of the same digest pushes no history.

Lint: critical rules match the dangerous instruction itself and skip a
negated one; mentions of credential files, shell profiles, and a role
reassignment are high (SQA-EXT-014..016), disclosed and non-blocking.

SKILL.md: a preview isError offers the next candidate. tools/list snapshot
regenerated for the rollback parameters.
…pe rollback to the named skill

Critical lint rules no longer exempt a negated command shape: any
download-execute, private-key read or send, shell-profile write, or
destructive rm anywhere on a line blocks. Only an instruction override
directly preceded by "do not", "don't" or "never" is skipped, and every
match position is checked. The download-execute, key and profile rules
also catch interpreter pipes, sh -c/eval of a download, irm then iex,
include/attach/share of a key, and quoted or braced $HOME targets.

Rollback acts only on records of the named skill, refuses a folder the
user edited or another agent's link points into, keys a restored record
to the folder written with the restore's own trust and time, and
requires a path on every history record. A restore that fails after the
CLI ran and a broken trust policy file get their own error types and
accurate hints.
…ollback to its own agent's folders

Rollback: a removal no longer counts this install's own links as targets,
so agents sharing a canonical copy can each unlink their own link; a
restore through a link into a folder recorded for another agent is
refused; a restore pops only the history entries it brought back and
records the installer CLI that wrote the folder; the restore guard uses
the same sanitised-folder test as rollback path selection.

Lint: command rules read logical lines (joined at a trailing \, |, &&
or ||) and instruction rules read markdown paragraphs; each joined line
is linted up to 4000 characters, with SQA-EXT-017 disclosing a longer
one; verb-led rules start at the first verb so a line stays linear.
SQA-EXT-002 gets the directly-negated exemption. One batch of known
variants of 003 to 006 now blocks. Docs say plainly the lint is a
deterministic known-shape matcher, not a malware detector.
… text and keep rollback reachable

Instruction rules (SQA-EXT-001, 002) now match the whole file with each
line's markdown markers stripped and every whitespace run collapsed, so no
soft wrap in a paragraph, blockquote, list, table, fence or heading splits a
phrase; a negation exempts a match only on the verb's own line. The
paragraph, block-boundary and fence-state logic is removed. Command rules
keep logical lines, physical lines and windows.

Rollback restores the newest history record of the rolled-back agent and
treats a folder with none as a first install, so an agent switch on a shared
folder no longer deadlocks. The circular refusal appears only when the other
install is blocked too. SQA-EXT-005 reads each whitespace run once.
…backslash-wrapped instructions

Rollback acts on one agent's install of the named skill (the agent given, or
the single one recorded) and refuses a shared install before anything
changes: a folder whose record or history names another agent, a folder
linked with another agent's recorded folder (to, into, or through), or
several recorded agents with no agent given. The chain, circle and subfolder
link handling, the agent-filtered history pick and the cross-agent history
drop are removed. A restore pops the history entry matching its digest,
agent and resolved ref.

The instruction rules drop a line's trailing continuation backslash before
joining, so a backslash-wrapped override or hiding instruction is critical
again. The pathological-input timing test runs through lint_skill_file.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: bbb42f24e8

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/sumo_qa/external_skills.py Resolved
Comment thread src/sumo_qa/external_skills.py Resolved
…y write

An agent could copy a preview's content_digest into approved_digest and
install with no user involved. Install, restore and removal now take an
injected approver; the server supplies one that elicits a yes/no from the
user showing source, commit, digest, trust tier and reasons, and every
finding. A decline or cancel writes nothing, and a host that did not
declare elicitation (or whose prompt fails) is refused with the manual
npx command; there is no agent-only fallback. Removal re-checks its plan
after the user answers instead of holding the lock while asking.

Also in this change:
- lock records carry the set of agents per folder (legacy agent read as
  a one-agent set); a reinstall merges it and rollback refuses a shared
  folder
- rollback refuses a folder any unrecorded link under the skill roots
  reaches
- the lock merge refuses a malformed current record before it reaches
  history, and a restore keeps a replaced record that had no history entry
- SQA-EXT-003 iex and SQA-EXT-006 rm patterns no longer backtrack
  polynomially on whitespace or repeated --rm flags
- source identity maps ssh.github.com to github.com and drops port and
  www. only on GitHub
- text lint skips binary assets and reads each payload file once
- hints name the preview, approved_digest and the user prompt
- the fake Skills CLI writes bytes, so Windows digests match
…capes, and harden the approval prompt

- Lint every payload file: decode with replacement, read NUL as whitespace,
  and disclose bytes past the 1 MiB cap as SQA-EXT-017 instead of skipping a
  file with a NUL byte or invalid UTF-8.
- Drop each scheme's default port from a source's identity, so
  gitlab.com:443 or :22 no longer escapes a deny or trust entry.
- Refuse a rollback when a skill root or its parent is linked onto the
  folder, when a folder under the roots cannot be listed, or on a link loop
  (a typed error, not RuntimeError).
- Pin the manual fallback command to the reviewed commit: clone, check out
  the commit, and hand the pinned CLI that checkout.
- Escape payload and lock values in the approval prompt, cap the findings
  list, and name the folders the install may write with what each replaces.
- Ask only through form elicitation on a request that can reach the client;
  an unanswered prompt (300 s) or a cancelled call is a decline, and the SDK
  gets its cancellation back.
- A lock record whose agent is not in its agents is unreadable.
- Grant the real-CLI smoke test the user's approval it now needs.
… recheck targets under the write guard, and name every folder the CLI writes

- A payload file over the 1 MiB lint cap is the critical finding
  SQA-EXT-018, which blocks install and handoff; SQA-EXT-017 keeps only
  the long-line disclosure at its own line.
- Lines break at \n only (a CRLF line's \r dropped), so \v, \f, \x85,
  U+2028 and the like no longer split one shell command.
- A link on a rolled-back folder's own path (.claude -> ~/dotfiles/claude)
  no longer refuses the rollback; any other spelling that reaches the
  folder still does.
- The folders the approval prompt showed are compared again under the
  write guard; a change made while the prompt was open writes nothing.
- A global claude-code install lists $CLAUDE_CONFIG_DIR/skills/<name>,
  where skills@1.7.0 writes it, as a folder sumo-qa does not track.
- The content digest pins each file's executable bit (none on Windows).
- A failed update puts back each folder the CLI rewrote, so the folder
  matches the lock record that stays.
- A decline caused by concurrent.futures.CancelledError hands the
  cancellation back, as for asyncio.CancelledError.
…ead bare carriage returns as line breaks, and back up only this agent's folders

The content digest hashes paths and bytes only again, so a lock recorded on
any platform or by an earlier release verifies. Each record lists its
executable files apart (executable_files); execution, rollback and the
install's check of the folders it wrote compare them on POSIX, and the
approval prompt always lists every executable-file finding.

A bare carriage return now ends a lint line. The install backs up only the
folders the CLI writes for this agent, and a backed-up folder link is
recreated as a folder link on Windows.
…n Windows, and list higher findings before executable files in the prompt
…y rollback, and state the approval prompt as it is
@sumithr

sumithr commented Oct 5, 2026

Copy link
Copy Markdown
Owner Author

Finish evidence for head 5e24c81

Verdict: merge-ready. All 8 acceptance criteria of #520 are met, CI is green, the mutation gate passed, and 0 review threads are unresolved.

Acceptance criteria (#520)

# Criterion Met Evidence
1 Install cannot proceed until the exact payload is previewed and confirmed yes Install requires approved_digest, re-stages, and asks the user through MCP elicitation. Real server: no digest or a wrong one is refused before any prompt; a decline writes nothing; an accept installs.
2 Mutable or arbitrary sources need elevated trust yes #main gives mutable_ref, an unlisted source gives unlisted_source; both are refused without elevated_trust, with 0 prompts.
3 Lint findings structured by severity with stable rule ids yes SQA-EXT-001..018, each with rule/severity/file/line/count/message, never the matched text.
4 Critical violations block yes ExternalSkillPolicyError with 0 prompts, even with elevated_trust=true and a client answering accept (download-and-run, NUL byte, vertical-tab split, over-cap file).
5 Execution verifies files against the approved digest yes An edited SKILL.md gives a digest mismatch, and chmod -x on a recorded executable gives an executable-files mismatch; both are refused.
6 Handoff untrusted, cannot override instructions yes trust: "untrusted" plus the framing prompt.
7 Rollback restores the previous version or removes a first install yes Restore and remove are each refused on decline and done on accept, including under a symlinked ~/.claude. A failed update keeps the previous version.
8 Audit history holds no secrets or unbounded content yes 13 documented record keys, history capped at 10. The canary and content grep is 0 over both locks and all wire logs.

Behaviour ledger (real surface)

4.7: 9 of 9 rows filled, all met.

  • real_repo: a fresh clone of this repo at the head, a real skill source repo, and temp HOMEs. The real ~/.claude/skills, ~/.agents, ~/.codex and ~/.sumo-qa were unchanged before and after.

  • real_surface:

    • Rows 1 to 8: a wheel built from the head, the real sumo-qa server over stdio, an MCP client answering the elicitation prompt (accept, decline, no callback), and the real pinned skills@1.7.0.
    • Row 9: a headless haiku claude -p --strict-mcp-config agent could not install without the user. On protocol 2026-07-28 the host is refused with the manual command; on 2025-11-25 it sends the prompt, the host cancels, and nothing is written.
  • existing_flow: using_sumo_qa, check_external_skill_installed and search_external_skills give identical output on this branch and on main, through the same agent.

  • evals: eval-reuse-check.py says REUSABLE for both configs (1/1 and 10/10), with inputs unchanged since those runs.

  • Observed on: rows 2 to 7 and 9 on 234bd82, rows 1 and 8 on 97b39bd. The commits after them change only:

    • the finding order in the prompt when there are more than 20 findings;
    • executable_files: null on Windows;
    • docs wording;
    • an early refusal for a rollback with no lock file.

    None of these changes what the rows observed.

Review

  • Per-file sumo-qa review (reviewing-before-merge, full post-change content against base): server.py, server_schemas.py, tool_registry.py, the skill, the tests and the other docs were SAFE. Two blockers were found and fixed in 5e24c81:
    • docs/TOOLS.md described the prompt order wrongly;
    • a rollback with no lock file created .sumo-qa/ before the user's yes.
  • /code-review high: run on the whole diff, then on each fix delta, 13 rounds in total. The final rounds were limited to regressions against main, writes without a user yes, unmet ACs and false docs.
  • Rounds 10 to 13 fixed:
    • two regressions introduced by round 9;
    • a check that compared folders before the prompt but not again under the write guard;
    • prompt completeness;
    • a platform-independent digest;
    • a failed update now keeps the previous version;
    • bare-CR line breaks;
    • backup scope;
    • Windows directory links;
    • Windows-written records.
  • Review threads: 2, both from the codex connector, both replied to and resolved.

Gates

  • Pre-push full suite: 6223 passed, 8 skipped, 1 xfailed, 100% coverage. mypy, ruff and format clean.
  • CI: 30/30 checks passed on 5e24c81 (Linux, macOS, Windows).
  • Mutation gate: strict gate passed, 0 survivors (run 37291987477).

Known limitations (in the PR body)

@sumithr
sumithr merged commit d1a8f73 into main Oct 5, 2026
31 checks passed
@sumithr
sumithr deleted the feat/issue-520-external-skill-trust branch October 5, 2026 09:58
sumithr added a commit that referenced this pull request Oct 5, 2026
🤖 I have created a release *beep* *boop*
---


##
[0.75.0](v0.74.0...v0.75.0)
(2026-10-05)


### Features

* **external-skills:** preview, trust policy, safety lint, and rollback
for external skills
([#845](#845))
([d1a8f73](d1a8f73))

---
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 5, 2026
…arameter (Refs #802)

Rebased onto main, the full profile's tools/list measured 12,161 estimated tokens against main's 12,100 budget: main's external-skill tools (#845) left 5 tokens of headroom and the catalogues= parameter adds 66. The core budget is unchanged.
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]: Add external skill preview, trust policy, safety linting, and rollback

1 participant