feat(skills): unpack skill packages into standard Agent Skills directories #172
No reviewers
Labels
No labels
auto/blocked-by-deps
auto/ci-timeout
auto/claimed-implementer
auto/claimed-merge
auto/claimed-reviewer
auto/driver-down
auto/invariant-violation
auto/last-attempt-tier-0
auto/last-attempt-tier-1
auto/last-attempt-tier-2
auto/last-attempt-tier-min
Automation Tracking
auto/needs-conflict-resolution
auto/needs-implementer
auto/postmortem
auto/ready-to-merge
auto/restart-throttled
auto/revert
auto/sentinel
auto/stale-inactivity
auto/unstable
Blocked
Bounty
$100
Bounty
$1000
Bounty
$10000
Bounty
$20
Bounty
$2000
Bounty
$250
Bounty
$50
Bounty
$500
Bounty
$5000
Bounty
$750
MoSCoW
Could have
MoSCoW
Must have
MoSCoW
Should have
Needs Feedback
Points
1
Points
13
Points
2
Points
21
Points
3
Points
34
Points
5
Points
55
Points
8
Points
88
Priority
Backlog
Priority
CI Blocker
Priority
Critical
Priority
High
Priority
Low
Priority
Medium
Signed-off: Owner
Signed-off: Scrum Master
Signed-off: Tech Lead
Spike
State
Completed
State
Duplicate
State
In Progress
State
In Review
State
Paused
State
Unverified
State
Verified
State
Wont Do
Type
Automation
Type
Bug
Type
Discussion
Type
Documentation
Type
Epic
Type
Feature
Type
Legendary
Type
Refactor
Type
Support
Type
Task
Type
Testing
No project
No assignees
2 participants
Notifications
Due date
No due date set.
Blocks
#170 feat(skills): unpack skill packages into standard Agent Skills directories
cleveragents/cleveractors-core
Reference
cleveragents/cleveractors-core!172
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "feature/m1-skill-directory-unpacking"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
SkillDirectoryUnpacker/unpack_skill_packageand autils/unpack_skill.pyCLI, the inverse ofSkillDirectoryPacker(#165): write a validated Skill Package (mapping, resolvedSkill, or local YAML file) back out as a standardSKILL.md+ bundled resources Agent Skills directory.FrontmatterRendereremits the canonicalallowed-toolsspelling and thesafe_modeomission rule, so unpacking a package and re-packing the result reproduces the samepkg_skl_Package ID.os.replace): a failure during rendering or resource materialization never leaves a partial or mixed directory behind. An existing destination directory is rejected unlessoverwrite=True(CLI:--force).cleveractors.agentsnow also exportsSkillDirectoryUnpacker,SkillUnpackingError,UnpackedSkill,unpack_skill_package.docs/guides/skill-packages.md(Python API + CLI usage).features/skill_directory_unpacking.feature— full round-trip across every resource class,safe_moderules, determinism (unpack → repack reproduces the same Package ID), destination collision/overwrite, and every input-validation and I/O failure path (invalid base64, invalid resource path, missing fields, non-mapping YAML, unreadable/unwritable files, symlink escape, non-path inputs).robot/agent_skills.robot— "Unpacked Skill Directory Is Re-Packed And Loaded" unpacks a packed skill, re-packs it, and loads the result end to end through the reallocal:pipeline.Closes #170
Validation
nox -s lint,nox -s format -- --check,nox -s typecheck— cleannox -s unit_tests— 159 features / 3324 scenarios passednox -s coverage_report— 97.2% (>= 96.5% gate;skill_unpacker.pyitself at 100%)nox -s security_scan(bandit + semgrep),nox -s dead_code— 0 findingsnox -s complexity— informational, no new concerning gradesnox -s integration_tests— 382 tests passed (pabot)benchmark/benchmark_regressionintentionally skipped locally; CI runs themPR Review: !172 (Ticket #170)
Verdict: Approve
Single atomic commit, first line matches the issue Metadata
Commit Messageexactly, branch matchesfeature/m1-skill-directory-unpacking, no merge commits, targetsdevelop. All quality gates verified locally:lint,typecheck,unit_tests(all scenarios pass),coverage_report(97.2%, threshold 96.5%;skill_unpacker.pyat 100%), and the affectedrobot/agent_skills.robotsuite (13/13, including the new unpack → re-pack → load scenario). The implementation faithfully mirrors the packer (canonicalallowed-toolsspelling,safe_modeomission rule, atomic staging +os.replace), the CLI conventions matchutils/pack_skill.py, and Behave/Robot coverage is thorough — every resource class, both encodings, all documented failure paths, symlink escape, and end-to-end determinism are exercised with real filesystems and no mocks in the unpacking path.Two minor issues were found and experimentally reproduced (details below); neither blocks merge in my view, but the determinism claim in the docs should either be fixed or scoped.
Critical Issues
None.
Major Issues
None.
Minor Issues
Package ID round-trip breaks for packages with an explicit empty
metadata: {}orresources: {}—src/cleveractors/agents/skill_unpacker.py:87(if skill.metadata:) andsrc/cleveractors/agents/skill_unpacker.py:276-278(_write_resourceswrites nothing for an empty dict).Reproduced: a package whose canonical form includes
metadata: {}packs topkg_skl_b3e8788…; unpack → re-pack yieldspkg_skl_71acc55…(IDs differ). Same forresources: {}(pkg_skl_af85eb0…vspkg_skl_28949a1…). The packer preserves an explicitly-present empty mapping (so it is a legal, ID-distinct canonical form), but theSkillvalue object collapses "absent" and "explicit empty" to{}, soFrontmatterRenderer(if skill.metadata:) and the resources loop cannot distinguish them. This contradicts the invariant stated in the PR description, indocs/guides/skill-packages.md("Unpacking an already-canonical package and packing the result again reproduces the samepkg_skl_Package ID"), and in ticket #170's acceptance criteria. The existing Behave determinism scenario only uses non-emptymetadata/resources, so it does not catch this.Recommendation: either (a) track "field was present in the source mapping" through validation so the renderer can emit
metadata: {}when (and only when) the source mapping declared it, or (b) scope the determinism claim in the docs/PR to packages whose canonical form has no explicit empty mappings, and note the limitation. Option (a) is the correct fix for the stated invariant.A NUL byte in a resource path bypasses the "same path-safety rules as packing" and escapes as a raw
ValueErrorinstead ofSkillUnpackingError—src/cleveractors/agents/skill_unpacker.py:139-145(ResourceMaterializer.materialize) andsrc/cleveractors/agents/skill_schema.py:353-360.Reproduced:
unpack({... "resources": {"bad\u0000path.txt": ...} ...}, dest)passesSkillValidator(the schema validates paths but, unlike the packer's_validate_resource_path, does not reject\x00), thenPath.mkdirraisesValueError: embedded null byte, which is not anOSErrorand therefore not wrapped. Ticket #170 requires "Apply the same path-safety rules as packing" and "fail clearly for … invalid resource paths"; the packer rejects\x00, the unpacker does not. The CLI is unaffected (the YAML parser rejects NUL first — verified clean exit code 2), but API callers catchingSkillUnpackingError(asutils/unpack_skill.py:75does) would miss this and get a confusing traceback.Recommendation: reject
\x00in resource paths — ideally inSkillValidator._validate_resources(bringing it to parity with the packer), or defensively inResourceMaterializer.materializewith the same "invalid resource path" message.Nits
src/cleveractors/agents/skill_unpacker.py:253-265(_write_atomically): whenoverwrite=True, the existing directory isshutil.rmtree'd beforeos.replace, so a crash between the two loses the old directory; and withoverwrite=False, a destination created concurrently between the existence check and the swap is silently replaced. POSIX cannot atomically swap non-empty directories, so this is a reasonable pragmatic choice — but the "atomic" wording in the PR description/docs could be qualified ("atomic for rendering/materialization failures; replacement of an existing directory is delete-then-rename").features/skill_directory_unpacking.feature:97-102: ticket #170's acceptance criterion says the CLI scenario proves the command "reports the Package ID/skill name on standard error"; the scenarios assertpkg_skl_and the output layout but never the name, even though the CLI prints it (utils/unpack_skill.py:80). One extra assertion would close the gap.src/cleveractors/agents/skill_unpacker.py:254: aSIGKILLbetweenmkdtempandos.replaceleaves a hidden.{skill.name}-<rand>directory in the destination parent that no later run cleans up. Standard trade-off for staging-dir swaps; fine to leave as is.Summary
A well-executed inverse of the packer: the orchestration/collaborator structure mirrors
skill_packer.py, the canonical frontmatter rules (allowed-toolsspelling,safe_modeomission per ADR-2034 D-9) match the spec §16.1/§16.2, path-safety and base64 validation are enforced before any bytes are written, and the staging-dir +os.replacedesign prevents partial output on rendering/materialization failures. Tests are genuine: real filesystem, real validator/canonicalizer, no mocks in the unpacking path, deterministic CLI exit codes, and an end-to-end Robot scenario that unpacks, re-packs (asserting the same Package ID), and loads through the reallocal:pipeline.skill_unpacker.pyis at 100% line coverage and the global gate holds at 97.2%. The two minor issues above are both edge cases (explicit empty mappings; NUL-byte paths via the mapping API) — worth a follow-up, not a blocker.28dec117994a839eb347Response to review (hurui200320, 2026-11-19T11:38:38Z)
Thank you for the detailed review and the reproductions. Below is a point-by-point response: what was changed, what was deliberately left as-is, and the reasoning for each, checked against ADR-2034 (
docs/adr/ADR-2034-skill-package-support.md), the Skill Package Schema indocs/actor-registry-standard.md§16, and issue #170's acceptance criteria. Applied in an amended commit (single commit, force-pushed — issue #170 has not merged todevelopyet, so this is still the one feature commit, not a fix on top of a shipped change).Minor Issue 1 — Package ID round-trip for explicit empty
metadata: {}/resources: {}metadata: {}— fixed. Confirmed this was a real bug:SkillValidator._validate_metadatanormalizes both "key absent" and "key present with{}" toSkill.metadata == {}, so the information needed to tell them apart was gone by the timeFrontmatterRendererran. Since the packer builds itsfieldsdict directly from the raw frontmatter dict ("metadata" in frontmatter, not a truthiness check — seeSkillDirectoryPacker._schema_fields), an explicitmetadata: {}written by a human inSKILL.mdis preserved going directory → package today. The unpacker going the other way was the asymmetric half.Fix:
SkillDirectoryUnpacker._resolve_skillnow returns(Skill, metadata_explicit: bool). For adictor YAML-file input,metadata_explicitis"metadata" in <raw mapping>, computed before validation collapses it. This flows through_write_atomically→_write_skill_md→FrontmatterRenderer.render(skill, metadata_explicit=...), which now emitsmetadata: {}whenskill.metadata or metadata_explicit. New scenario: "An explicit empty metadata mapping is preserved through a round trip" (unpacks the mapping, not a bypassedSkillobject, so the presence-tracking path is actually exercised — asserts both the rendered frontmatter and Package ID equality after re-packing).Known residual gap, stated explicitly in the updated docstring: a caller that hands
unpack()a bareSkillobject (not a mapping/YAML file) cannot benefit from this, because aSkillvalue object carries no raw-mapping presence information at all — there's nothing to detect. That's inherent to the input type, not a bug in the fix.resources: {}— not fixed, documented instead. I verified this is not just unimplemented but structurally unreachable to fix while staying inside the Agent Skills directory model ADR-2034 defines:SkillDirectoryPacker.pack()only ever adds theresourceskey when_collect_resources()is non-empty (if resources: content["resources"] = resources). The packer itself never emits an explicitresources: {}— that can only appear in a hand-authored mapping that bypasses our own packer entirely.resourcesagain — correctly reproducing what our own tooling would always produce, but not round-tripping a hand-craftedresources: {}that never came from the packer in the first place.Given "do not go against the specification" and "the packer never produces this" together, I scoped the documentation instead of attempting a code fix:
docs/guides/skill-packages.mdnow states the determinism guarantee holds for packages produced by this project's own packer, and explicitly calls out that a hand-authoredresources: {}is the one case that can't round-trip, with the reasoning above. Happy to revisit with a dedicated ADR amendment if an out-of-band "explicit empty" marker is ever wanted — that felt like a bigger, separate design decision than this ticket's scope.Minor Issue 2 — NUL byte in a resource path
Fixed. Reproduced the same gap you found:
SkillValidator._validate_resourceschecks for a leading slash, backslash, and./..segments, but not\x00, while the packer's_validate_resource_pathdoes.ResourceMaterializer.materializenow checks_NUL_BYTE in resource.pathfirst and raisesSkillUnpackingError("invalid resource path ...: must not contain a NUL byte")before any filesystem call, instead of letting a rawValueErrorescape fromPath.mkdir.I fixed this locally in
skill_unpacker.pyrather than in the sharedSkillValidator._validate_resources(your alternative (1)) deliberately: that validator is shared by the packer's own validation step,SkillLoader, and tool-dispatch resource resolution — none of which are in scope for issue #170, and I didn't want a drive-by change to shared validation logic as a side effect of fixing the unpacker. If you'd prefer parity enforced at the schema level instead, I'd treat that as its own follow-up ticket since it touches more call sites than this one. New scenario: "A resource path containing a NUL byte is rejected with a clear error" (via the mapping input path, same reproduction method you used).Nit 1 — "atomic" wording
Addressed (docs only, no code change). You're right that POSIX can't atomically replace a non-empty directory.
docs/guides/skill-packages.mdnow distinguishes: stagingSKILL.md+ resources in a hidden sibling directory is what prevents a partial/mixed directory on a rendering or materialization failure; replacing an existingoverwrite=Truedestination is delete-then-os.replace, not a single atomic syscall, and a crash in that narrow window can still lose the previous directory's contents. No code change — this was a correctness-of-wording issue, not a correctness-of-behavior issue, and the behavior itself matches what was already intended.Nit 2 — CLI scenario doesn't assert the skill name
Fixed. Added
And the unpacking CLI standard error should contain "cli-unpack-skill"to the round-trip CLI scenario, so it now asserts both the Package ID and the skill name are present in stderr, matching issue #170's acceptance criterion verbatim ("reports the Package ID/skill name on standard error").Nit 3 — Leaked staging directory on a hard crash
Not changed, per your own framing of it as an acceptable trade-off for staging-dir swaps rather than a request for a fix. Agreed — didn't touch it.
Verification (full gate re-run after the changes above)
nox -s lint,nox -s format -- --check,nox -s typecheck— cleannox -s unit_tests -- features/skill_directory_unpacking.feature— 32/32 scenarios (30 existing + 2 new)nox -s unit_tests(full suite) — 3326/3326 scenarios, 0 failed (up from 3324 before this round)nox -s coverage_report -- features/skill_directory_unpacking.feature(scoped to this feature, per our own coverage-delta process rather than re-running the whole suite's coverage for a localized change) —skill_unpacker.py: 212/212 lines, 100%nox -s security_scan,nox -s dead_code— 0 findingsnox -s integration_tests— 382/382 (Robot/pabot), including the unpack → re-pack → load scenarionox -s e2e_tests— 1/1, real LLM calls, no mocksbenchmark/benchmark_regressionintentionally skipped locally; CI runs themAmended into the single existing commit and force-pushed (no squash — there was only ever one commit on this branch). I have not approved this PR myself; leaving that to you given your review is now marked stale by Forgejo after the force-push.