feat(skills): unpack skill packages into standard Agent Skills directories #172

Merged
CoreRasurae merged 1 commit from feature/m1-skill-directory-unpacking into develop 2026-11-19 16:20:09 +00:00
Member

Summary

  • Add SkillDirectoryUnpacker / unpack_skill_package and a utils/unpack_skill.py CLI, the inverse of SkillDirectoryPacker (#165): write a validated Skill Package (mapping, resolved Skill, or local YAML file) back out as a standard SKILL.md + bundled resources Agent Skills directory.
  • FrontmatterRenderer emits the canonical allowed-tools spelling and the safe_mode omission rule, so unpacking a package and re-packing the result reproduces the same pkg_skl_ Package ID.
  • Writing is atomic (staging directory + os.replace): a failure during rendering or resource materialization never leaves a partial or mixed directory behind. An existing destination directory is rejected unless overwrite=True (CLI: --force).
  • cleveractors.agents now also exports SkillDirectoryUnpacker, SkillUnpackingError, UnpackedSkill, unpack_skill_package.
  • Docs: new "Unpacking a Skill Package" section in docs/guides/skill-packages.md (Python API + CLI usage).
  • Tests (Behave): features/skill_directory_unpacking.feature — full round-trip across every resource class, safe_mode rules, 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).
  • Tests (Robot): 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 real local: pipeline.

Closes #170

Validation

  • nox -s lint, nox -s format -- --check, nox -s typecheck — clean
  • nox -s unit_tests — 159 features / 3324 scenarios passed
  • nox -s coverage_report — 97.2% (>= 96.5% gate; skill_unpacker.py itself at 100%)
  • nox -s security_scan (bandit + semgrep), nox -s dead_code — 0 findings
  • nox -s complexity — informational, no new concerning grades
  • nox -s integration_tests — 382 tests passed (pabot)
  • benchmark/benchmark_regression intentionally skipped locally; CI runs them
## Summary - Add `SkillDirectoryUnpacker` / `unpack_skill_package` and a `utils/unpack_skill.py` CLI, the inverse of `SkillDirectoryPacker` (#165): write a validated Skill Package (mapping, resolved `Skill`, or local YAML file) back out as a standard `SKILL.md` + bundled resources Agent Skills directory. - `FrontmatterRenderer` emits the canonical `allowed-tools` spelling and the `safe_mode` omission rule, so unpacking a package and re-packing the result reproduces the same `pkg_skl_` Package ID. - Writing is atomic (staging directory + `os.replace`): a failure during rendering or resource materialization never leaves a partial or mixed directory behind. An existing destination directory is rejected unless `overwrite=True` (CLI: `--force`). - `cleveractors.agents` now also exports `SkillDirectoryUnpacker`, `SkillUnpackingError`, `UnpackedSkill`, `unpack_skill_package`. - Docs: new "Unpacking a Skill Package" section in `docs/guides/skill-packages.md` (Python API + CLI usage). - Tests (Behave): `features/skill_directory_unpacking.feature` — full round-trip across every resource class, `safe_mode` rules, 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). - Tests (Robot): `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 real `local:` pipeline. Closes #170 ## Validation - `nox -s lint`, `nox -s format -- --check`, `nox -s typecheck` — clean - `nox -s unit_tests` — 159 features / 3324 scenarios passed - `nox -s coverage_report` — 97.2% (>= 96.5% gate; `skill_unpacker.py` itself at 100%) - `nox -s security_scan` (bandit + semgrep), `nox -s dead_code` — 0 findings - `nox -s complexity` — informational, no new concerning grades - `nox -s integration_tests` — 382 tests passed (pabot) - `benchmark`/`benchmark_regression` intentionally skipped locally; CI runs them
feat(skills): unpack skill packages into standard Agent Skills directories
Some checks failed
CI / lint (pull_request) Successful in 42s
CI / typecheck (pull_request) Successful in 1m10s
CI / security (pull_request) Successful in 59s
CI / quality (pull_request) Successful in 42s
CI / build (pull_request) Successful in 2m7s
CI / integration_tests (pull_request) Successful in 3m31s
CI / unit_tests (pull_request) Successful in 5m47s
CI / coverage (pull_request) Successful in 5m25s
CI / status-check (pull_request) Successful in 1s
CI / benchmark (pull_request) Failing after 26m38s
28dec11799
Add SkillDirectoryUnpacker / unpack_skill_package and a utils/unpack_skill.py
CLI, the inverse of the existing SkillDirectoryPacker (issue #165): given a
validated Skill Package — a mapping, a resolved Skill, or a local YAML file —
write a standard SKILL.md plus its bundled resources back out as a real
Agent Skills directory, so a package can be inspected, edited with familiar
tooling, and republished.

The renderer uses the canonical allowed-tools spelling and the safe_mode
omission rule so an unpacked-then-repacked package reproduces the same
pkg_skl_ Package ID. Writing is atomic via a staging directory swapped in
with os.replace, so a failure during rendering or resource materialization
never leaves a partial or mixed directory behind. An existing destination
directory is rejected unless overwrite=True (CLI: --force) is given.

Behave scenarios cover the full round-trip (every resource class, safe_mode
rules, determinism), destination collision, and every input-validation and
I/O failure path. A new Robot scenario unpacks a packed skill, re-packs it,
and loads the result end to end through the real local: pipeline.

ISSUES CLOSED: #170
CoreRasurae added this to the v2.1.0 milestone 2026-11-19 09:56:59 +00:00
hurui200320 left a comment

PR Review: !172 (Ticket #170)

Verdict: Approve

Single atomic commit, first line matches the issue Metadata Commit Message exactly, branch matches feature/m1-skill-directory-unpacking, no merge commits, targets develop. All quality gates verified locally: lint, typecheck, unit_tests (all scenarios pass), coverage_report (97.2%, threshold 96.5%; skill_unpacker.py at 100%), and the affected robot/agent_skills.robot suite (13/13, including the new unpack → re-pack → load scenario). The implementation faithfully mirrors the packer (canonical allowed-tools spelling, safe_mode omission rule, atomic staging + os.replace), the CLI conventions match utils/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

  1. Package ID round-trip breaks for packages with an explicit empty metadata: {} or resources: {} — src/cleveractors/agents/skill_unpacker.py:87 (if skill.metadata:) and src/cleveractors/agents/skill_unpacker.py:276-278 (_write_resources writes nothing for an empty dict).
    Reproduced: a package whose canonical form includes metadata: {} packs to pkg_skl_b3e8788…; unpack → re-pack yields pkg_skl_71acc55… (IDs differ). Same for resources: {} (pkg_skl_af85eb0… vs pkg_skl_28949a1…). The packer preserves an explicitly-present empty mapping (so it is a legal, ID-distinct canonical form), but the Skill value object collapses "absent" and "explicit empty" to {}, so FrontmatterRenderer (if skill.metadata:) and the resources loop cannot distinguish them. This contradicts the invariant stated in the PR description, in docs/guides/skill-packages.md ("Unpacking an already-canonical package and packing the result again reproduces the same pkg_skl_ Package ID"), and in ticket #170's acceptance criteria. The existing Behave determinism scenario only uses non-empty metadata/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.

  2. A NUL byte in a resource path bypasses the "same path-safety rules as packing" and escapes as a raw ValueError instead of SkillUnpackingError — src/cleveractors/agents/skill_unpacker.py:139-145 (ResourceMaterializer.materialize) and src/cleveractors/agents/skill_schema.py:353-360.
    Reproduced: unpack({... "resources": {"bad\u0000path.txt": ...} ...}, dest) passes SkillValidator (the schema validates paths but, unlike the packer's _validate_resource_path, does not reject \x00), then Path.mkdir raises ValueError: embedded null byte, which is not an OSError and 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 catching SkillUnpackingError (as utils/unpack_skill.py:75 does) would miss this and get a confusing traceback.
    Recommendation: reject \x00 in resource paths — ideally in SkillValidator._validate_resources (bringing it to parity with the packer), or defensively in ResourceMaterializer.materialize with the same "invalid resource path" message.

Nits

  1. Non-atomic overwrite window — src/cleveractors/agents/skill_unpacker.py:253-265 (_write_atomically): when overwrite=True, the existing directory is shutil.rmtree'd before os.replace, so a crash between the two loses the old directory; and with overwrite=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").
  2. CLI scenarios don't assert the skill name in stderr — 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 assert pkg_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.
  3. Leaked staging directories on hard crash — src/cleveractors/agents/skill_unpacker.py:254: a SIGKILL between mkdtemp and os.replace leaves 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-tools spelling, safe_mode omission 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.replace design 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 real local: pipeline. skill_unpacker.py is 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.

## PR Review: !172 (Ticket #170) ### Verdict: Approve Single atomic commit, first line matches the issue Metadata `Commit Message` exactly, branch matches `feature/m1-skill-directory-unpacking`, no merge commits, targets `develop`. All quality gates verified locally: `lint`, `typecheck`, `unit_tests` (all scenarios pass), `coverage_report` (97.2%, threshold 96.5%; `skill_unpacker.py` at 100%), and the affected `robot/agent_skills.robot` suite (13/13, including the new unpack → re-pack → load scenario). The implementation faithfully mirrors the packer (canonical `allowed-tools` spelling, `safe_mode` omission rule, atomic staging + `os.replace`), the CLI conventions match `utils/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 1. **Package ID round-trip breaks for packages with an explicit empty `metadata: {}` or `resources: {}`** — `src/cleveractors/agents/skill_unpacker.py:87` (`if skill.metadata:`) and `src/cleveractors/agents/skill_unpacker.py:276-278` (`_write_resources` writes nothing for an empty dict). Reproduced: a package whose canonical form includes `metadata: {}` packs to `pkg_skl_b3e8788…`; unpack → re-pack yields `pkg_skl_71acc55…` (IDs differ). Same for `resources: {}` (`pkg_skl_af85eb0…` vs `pkg_skl_28949a1…`). The packer preserves an explicitly-present empty mapping (so it is a legal, ID-distinct canonical form), but the `Skill` value object collapses "absent" and "explicit empty" to `{}`, so `FrontmatterRenderer` (`if skill.metadata:`) and the resources loop cannot distinguish them. This contradicts the invariant stated in the PR description, in `docs/guides/skill-packages.md` ("Unpacking an already-canonical package and packing the result again reproduces the same `pkg_skl_` Package ID"), and in ticket #170's acceptance criteria. The existing Behave determinism scenario only uses non-empty `metadata`/`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. 2. **A NUL byte in a resource path bypasses the "same path-safety rules as packing" and escapes as a raw `ValueError` instead of `SkillUnpackingError`** — `src/cleveractors/agents/skill_unpacker.py:139-145` (`ResourceMaterializer.materialize`) and `src/cleveractors/agents/skill_schema.py:353-360`. Reproduced: `unpack({... "resources": {"bad\u0000path.txt": ...} ...}, dest)` passes `SkillValidator` (the schema validates paths but, unlike the packer's `_validate_resource_path`, does not reject `\x00`), then `Path.mkdir` raises `ValueError: embedded null byte`, which is not an `OSError` and 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 catching `SkillUnpackingError` (as `utils/unpack_skill.py:75` does) would miss this and get a confusing traceback. Recommendation: reject `\x00` in resource paths — ideally in `SkillValidator._validate_resources` (bringing it to parity with the packer), or defensively in `ResourceMaterializer.materialize` with the same "invalid resource path" message. ### Nits 1. **Non-atomic overwrite window** — `src/cleveractors/agents/skill_unpacker.py:253-265` (`_write_atomically`): when `overwrite=True`, the existing directory is `shutil.rmtree`'d before `os.replace`, so a crash between the two loses the old directory; and with `overwrite=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"). 2. **CLI scenarios don't assert the skill name in stderr** — `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 assert `pkg_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. 3. **Leaked staging directories on hard crash** — `src/cleveractors/agents/skill_unpacker.py:254`: a `SIGKILL` between `mkdtemp` and `os.replace` leaves 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-tools` spelling, `safe_mode` omission 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.replace` design 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 real `local:` pipeline. `skill_unpacker.py` is 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.
CoreRasurae force-pushed feature/m1-skill-directory-unpacking from 28dec11799
Some checks failed
CI / lint (pull_request) Successful in 42s
CI / typecheck (pull_request) Successful in 1m10s
CI / security (pull_request) Successful in 59s
CI / quality (pull_request) Successful in 42s
CI / build (pull_request) Successful in 2m7s
CI / integration_tests (pull_request) Successful in 3m31s
CI / unit_tests (pull_request) Successful in 5m47s
CI / coverage (pull_request) Successful in 5m25s
CI / status-check (pull_request) Successful in 1s
CI / benchmark (pull_request) Failing after 26m38s
to 4a839eb347
Some checks failed
CI / lint (pull_request) Successful in 1m12s
CI / typecheck (pull_request) Successful in 1m19s
CI / security (pull_request) Successful in 1m42s
CI / quality (pull_request) Successful in 1m35s
CI / build (pull_request) Successful in 2m30s
CI / integration_tests (pull_request) Successful in 4m33s
CI / unit_tests (pull_request) Successful in 6m35s
CI / coverage (pull_request) Successful in 7m17s
CI / status-check (pull_request) Successful in 4s
CI / benchmark (pull_request) Failing after 32m26s
CI / lint (push) Successful in 1m17s
CI / typecheck (push) Successful in 1m52s
CI / security (push) Successful in 1m52s
CI / build (push) Successful in 1m39s
CI / quality (push) Successful in 2m4s
CI / integration_tests (push) Successful in 3m41s
CI / unit_tests (push) Successful in 6m4s
CI / coverage (push) Failing after 10m46s
CI / benchmark (push) Failing after 21m39s
CI / status-check (push) Has been cancelled
2026-11-19 15:16:17 +00:00
Compare
Author
Member

Response 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 in docs/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 to develop yet, 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_metadata normalizes both "key absent" and "key present with {}" to Skill.metadata == {}, so the information needed to tell them apart was gone by the time FrontmatterRenderer ran. Since the packer builds its fields dict directly from the raw frontmatter dict ("metadata" in frontmatter, not a truthiness check — see SkillDirectoryPacker._schema_fields), an explicit metadata: {} written by a human in SKILL.md is preserved going directory → package today. The unpacker going the other way was the asymmetric half.

Fix: SkillDirectoryUnpacker._resolve_skill now returns (Skill, metadata_explicit: bool). For a dict or YAML-file input, metadata_explicit is "metadata" in <raw mapping>, computed before validation collapses it. This flows through _write_atomically → _write_skill_md → FrontmatterRenderer.render(skill, metadata_explicit=...), which now emits metadata: {} when skill.metadata or metadata_explicit. New scenario: "An explicit empty metadata mapping is preserved through a round trip" (unpacks the mapping, not a bypassed Skill object, 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 bare Skill object (not a mapping/YAML file) cannot benefit from this, because a Skill value 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 the resources key when _collect_resources() is non-empty (if resources: content["resources"] = resources). The packer itself never emits an explicit resources: {} — that can only appear in a hand-authored mapping that bypasses our own packer entirely.
  • Unpacking a package with zero resources therefore writes a directory with zero extra files. Re-packing that directory walks the filesystem and finds zero files, so it omits resources again — correctly reproducing what our own tooling would always produce, but not round-tripping a hand-crafted resources: {} that never came from the packer in the first place.
  • There is no filesystem-level way to represent "resources key present but empty" distinctly from "resources key absent" without inventing a marker file or directory convention that ADR-2034/the Agent Skills spec does not define. Doing that would be adding an out-of-spec extension to work around a case the packer's own (pre-existing, already-shipped in #165) design decision makes unreachable via the packer→unpacker pipeline anyway.

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.md now states the determinism guarantee holds for packages produced by this project's own packer, and explicitly calls out that a hand-authored resources: {} 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_resources checks for a leading slash, backslash, and ./.. segments, but not \x00, while the packer's _validate_resource_path does. ResourceMaterializer.materialize now checks _NUL_BYTE in resource.path first and raises SkillUnpackingError("invalid resource path ...: must not contain a NUL byte") before any filesystem call, instead of letting a raw ValueError escape from Path.mkdir.

I fixed this locally in skill_unpacker.py rather than in the shared SkillValidator._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.md now distinguishes: staging SKILL.md + resources in a hidden sibling directory is what prevents a partial/mixed directory on a rendering or materialization failure; replacing an existing overwrite=True destination 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 — clean
  • nox -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 findings
  • nox -s integration_tests — 382/382 (Robot/pabot), including the unpack → re-pack → load scenario
  • nox -s e2e_tests — 1/1, real LLM calls, no mocks
  • benchmark/benchmark_regression intentionally skipped locally; CI runs them

Amended 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.

## Response 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 in `docs/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 to `develop` yet, 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_metadata` normalizes both "key absent" and "key present with `{}`" to `Skill.metadata == {}`, so the information needed to tell them apart was gone by the time `FrontmatterRenderer` ran. Since the *packer* builds its `fields` dict directly from the raw frontmatter dict (`"metadata" in frontmatter`, not a truthiness check — see `SkillDirectoryPacker._schema_fields`), an explicit `metadata: {}` written by a human in `SKILL.md` **is** preserved going directory → package today. The unpacker going the other way was the asymmetric half. Fix: `SkillDirectoryUnpacker._resolve_skill` now returns `(Skill, metadata_explicit: bool)`. For a `dict` or YAML-file input, `metadata_explicit` is `"metadata" in <raw mapping>`, computed before validation collapses it. This flows through `_write_atomically` → `_write_skill_md` → `FrontmatterRenderer.render(skill, metadata_explicit=...)`, which now emits `metadata: {}` when `skill.metadata or metadata_explicit`. New scenario: *"An explicit empty metadata mapping is preserved through a round trip"* (unpacks the **mapping**, not a bypassed `Skill` object, 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 bare `Skill` object (not a mapping/YAML file) cannot benefit from this, because a `Skill` value 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 the `resources` key when `_collect_resources()` is non-empty (`if resources: content["resources"] = resources`). The packer itself **never** emits an explicit `resources: {}` — that can only appear in a hand-authored mapping that bypasses our own packer entirely. - Unpacking a package with zero resources therefore writes a directory with zero extra files. Re-packing that directory walks the filesystem and finds zero files, so it omits `resources` again — correctly reproducing what *our own tooling* would always produce, but not round-tripping a hand-crafted `resources: {}` that never came from the packer in the first place. - There is no filesystem-level way to represent "resources key present but empty" distinctly from "resources key absent" without inventing a marker file or directory convention that ADR-2034/the Agent Skills spec does not define. Doing that would be adding an out-of-spec extension to work around a case the packer's own (pre-existing, already-shipped in #165) design decision makes unreachable via the packer→unpacker pipeline anyway. 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.md` now states the determinism guarantee holds for packages produced by this project's own packer, and explicitly calls out that a hand-authored `resources: {}` 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_resources` checks for a leading slash, backslash, and `.`/`..` segments, but not `\x00`, while the packer's `_validate_resource_path` does. `ResourceMaterializer.materialize` now checks `_NUL_BYTE in resource.path` first and raises `SkillUnpackingError("invalid resource path ...: must not contain a NUL byte")` before any filesystem call, instead of letting a raw `ValueError` escape from `Path.mkdir`. I fixed this locally in `skill_unpacker.py` rather than in the shared `SkillValidator._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.md` now distinguishes: staging `SKILL.md` + resources in a hidden sibling directory is what prevents a partial/mixed directory on a *rendering or materialization* failure; replacing an *existing* `overwrite=True` destination 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` — clean - `nox -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 findings - `nox -s integration_tests` — 382/382 (Robot/pabot), including the unpack → re-pack → load scenario - `nox -s e2e_tests` — 1/1, real LLM calls, no mocks - `benchmark`/`benchmark_regression` intentionally skipped locally; CI runs them Amended 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.
CoreRasurae deleted branch feature/m1-skill-directory-unpacking 2026-11-19 16:20:10 +00:00
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
cleveragents/cleveractors-core!172
No description provided.