Skip to content

fix(claude): keep documented command frontmatter on .claude/commands (#3067) - #4910

Merged
Daniel Meppiel (danielmeppiel) merged 10 commits into
mainfrom
cloud-3067-claude-command-frontmatter
Nov 23, 2026
Merged

Daniel Meppiel (danielmeppiel) merged 10 commits into
mainfrom
cloud-3067-claude-command-frontmatter

Conversation

@danielmeppiel

@danielmeppiel Daniel Meppiel (danielmeppiel) commented Nov 23, 2026 •

Copy link
Copy Markdown
Collaborator

Description

Supersedes #3748 by Abhishek Acharya (@abhishekacharya200) (credited via Co-authored-by on both commits). The fork branch could not be updated from here (the merge with main touches workflow files), so the contributor's commit is cherry-picked onto main and the review is folded on top.

On the claude target, .claude/commands/*.md now keeps the frontmatter Claude Code documents for command files: when_to_use, disable-model-invocation, user-invocable, disallowed-tools, effort, context, agent, background, shell, and an authored arguments when there is no input:. Inline hooks stay withheld with a warning (tracked in #3227). name and paths are still dropped. Cursor/Grok output is unchanged.

Changes on top of #3748:

  • Conflict with [BUG] First install of the sample package prints warnings about a dropped mode: key #4182: unsupported dropped keys stay a verbose info note; the withheld-hooks notice stays a [!] warning because the command behaves differently.
  • Copilot review fold: an authored input: (empty, whitespace-only or fully rejected) still wins over arguments.
  • Copilot review fold: the "Mapped input -> command arguments" note uses the explicit mapping result, so an authored arguments: [issue, 7] or arguments: 7 is no longer joined (TypeError) or reported as mapped.
  • Merge fix: the adopt check (install overwrites user-edited managed files when no deployment receipt exists #4360) now renders with the target name, so a reinstalled Claude command carrying native keys is adopted instead of reported as a user-file collision.
  • Copilot review fold: the withheld-hooks warning also fires when an existing command is retained (adopted or receipted-unchanged), so a source that only gains hooks: is never kept silently; a retained command with malformed frontmatter reports a per-file warning instead of aborting the run.
  • Docs moved with main's redesign: producer/write-primitives.md; apm-guide package-authoring.md updated.

Issue and approved scope

Issue: Fixes #3067

Human scope-approval comment: #3067 (comment) (hook split: #3067 (comment))

Does this PR complete the issue, or what remains? It completes the non-hook metadata repair. Inline hooks remain withheld and are tracked in #3227.

Supersedes #3748.

Type of change

  • Bug fix
  • New feature
  • Documentation
  • Maintenance / refactor

Testing

  • Tested locally
  • All existing tests pass
  • Added tests for new functionality (if applicable)

Red-first: TestClaudeNativeCommandFrontmatter has 3 tests failing on main (native keys, authored arguments, hooks warning) and 6 failing on the #3748 head (input precedence x3, non-string arguments x2, adopt on reinstall), plus 3 retain-path tests (hooks warning x2, malformed frontmatter) that fail without the last fold; all 15 pass here.

  • uv run --extra dev pytest -q tests/unit/integration/test_command_integrator.py tests/integration/test_command_integrator_hermetic.py -- 130 passed
  • uv run --extra dev pytest -q tests/integration/test_architecture_owner_rule_mutations.py -- 1306 passed
  • uv run --extra dev pytest -q tests/quality -- 665 passed
  • 29 test files touching CommandIntegrator / .claude/commands -- 974 passed, 3 failed (test_local_single_file_matrix.py::test_failed_source_preserves_owned_output[unreadable-*]; environmental: run as root, chmod 0 is not enforced; also fails for agents/instructions this PR does not touch)
  • Lint mirror: ruff check, ruff format --check (ruff 0.15.12), pylint R0801, scripts/lint-auth-signals.sh, check_complexity_ratchet.py --base-ref origin/main, python -m tests.quality.taxonomy --changed, lint_architecture_boundaries.py --root . -- all pass
  • changelog_fragments.py check and check-unreleased --base-ref origin/main -- pass

Changelog

  • One fragment per section, changelog.d/<pr>.<section>.md, holding
    one line: user-visible effect first, 25 words or fewer, ending with
    (#PR); breaking changes only under upgrade notes; no Highlights; no
    new lines under ## [Unreleased]. See changelog.d/README.md and
    .github/instructions/changelog.instructions.md.
  • N/A -- internal-only change (CI, tests, refactor).

Spec conformance (OpenAPM v0.1)

  • N/A -- this PR does not change OpenAPM-observable behaviour.

apm-spec-waiver: Claude-target command frontmatter rendering only; no OpenAPM requirement changes.

…3067)

Claude Code documents that command files accept the skill frontmatter except name and paths, but the command transform kept only description, allowed-tools, model, argument-hint and input. On the claude target it now also keeps when_to_use, disable-model-invocation, user-invocable, disallowed-tools, effort, context, agent, background, shell, and an authored arguments when there is no input. Inline hooks stay withheld with their own warning until they go through executable consent. Cursor and Grok output is unchanged.

Cherry-picked from 9db3413 (#3748, by @abhishekacharya200) onto main;
the dropped-key notice follows #4182 (verbose info), and the deleted
author-primitives doc pages are ported in the next commit.

Co-authored-by: abhishekacharya200 <[email protected]>
Co-authored-by: copilot-swe-agent[bot] <[email protected]>
- An authored input (even empty, whitespace or fully rejected) now wins
  over arguments, as documented.
- The input -> arguments note uses the explicit mapping result, so an
  authored arguments is never joined (no TypeError on non-string items)
  or reported as mapped.
- The adopt check renders with the target name, so a Claude command
  carrying native keys is adopted on reinstall instead of colliding.
- Port docs to producer/write-primitives.md; add changelog.d fragment.

Co-authored-by: abhishekacharya200 <[email protected]>
Co-authored-by: copilot-swe-agent[bot] <[email protected]>
@danielmeppiel Daniel Meppiel (danielmeppiel) added this to the 0.38.0 milestone Nov 23, 2026
Copilot AI balanced review requested due to automatic review settings November 23, 2026 04:23
Co-authored-by: abhishekacharya200 <[email protected]>
Co-authored-by: copilot-swe-agent[bot] <[email protected]>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

The changelog fragment’s incorrect trailing PR number blocks validation and release assembly, while the missing hook-adoption warning and stale mutation-test anchor remain unresolved.

3 open issues
What changed in this PR

Repairs Claude command metadata preservation for #3067, superseding #3748 while leaving inline-hook consent support to #3227.

Changes:

  • Preserves additional Claude-native frontmatter and authored arguments when input is absent; Cursor and Grok behavior stays unchanged.
  • Makes adoption rendering target-aware and distinguishes withheld-hook warnings from verbose dropped-key notices.
  • Adds regression coverage, authoring documentation, and a changelog fragment.
File Description
tests/​unit/​integration/​test_command_integrator.py Adds metadata, input-precedence, warning, and adoption regression tests.
src/​apm_cli/​integration/​command_integrator.py Implements Claude-specific preservation, diagnostics, and target-aware adoption.
packages/​apm-guide/​.apm/​skills/​apm-usage/​package-authoring.md Documents preserved fields and the inline-hook limitation.
docs/​src/​content/​docs/​producer/​write-primitives.md Updates command frontmatter and diagnostic guidance.
changelog.d/​4910.fixed.md Records the user-visible repair and contributor credit.

Review effort: Balanced

Comment thread changelog.d/4910.fixed.md Resolved
- An adopted Claude command (identical bytes already on disk) now repeats
  the withheld-hooks warning instead of keeping it silently.
- Update the render-then-adopt mutation anchor for the target-aware call.
- Shorten the changelog fragment to the 25-word limit.

Co-authored-by: abhishekacharya200 <[email protected]>
Co-authored-by: copilot-swe-agent[bot] <[email protected]>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔵 Needs a closer look

A receipt-backed skip bypasses the withheld-hooks warning when a command gains only hooks, silently retaining the hook-free command and leaving that path without regression coverage.

No open issues 🎉

1 previously missed issue

In code that hasn't changed since last review

Medium severity Warn when matching receipts skip commands with withheld hooks

src/​apm_cli/​integration/​command_integrator.py:705

If an installed command's source gains only hooks:, its rendered bytes stay unchanged, and a matching deployment receipt makes BaseIntegrator._check_adopt_or_skip() return (True, False) (base_integrator.py:855-857). This bypasses the warning helper, silently retaining the hook-free command. Distinguish identical retained output from collision and planning skips through the base integrator, emit the withheld-hooks warning for that outcome too, and add a receipt-backed regression.

3 resolved since last review

Review effort: Balanced

A receipted-unchanged skip also bypassed integrate_command(), so a
source that only gained hooks: kept the hook-free command silently.
Warn whenever the existing command is retained (the base integrator
tracks it in target_paths); collision skips and planning stay quiet.

apm-spec-waiver: Claude-target command frontmatter rendering only; no OpenAPM requirement changes.

Co-authored-by: abhishekacharya200 <[email protected]>
Co-authored-by: copilot-swe-agent[bot] <[email protected]>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔵 Needs a closer look

Malformed frontmatter can trigger an uncaught YAML error during command adoption, aborting remaining integrations instead of reporting a per-file diagnostic and continuing.

No open issues 🎉

1 previously missed issue

In code that hasn't changed since last review

Medium severity Catch YAML errors during source frontmatter reparsing

src/​apm_cli/​integration/​command_integrator.py:368

If an existing command contains the same malformed frontmatter as its source, _rendered_command() returns None and the adoption check can retain it by comparing raw bytes. This helper then reparses the source outside the per-file YAML error handler, aborting the remaining command integrations. Catch yaml.YAMLError here and report a per-file diagnostic so processing can continue.

Review effort: Balanced

#3067)

A command kept by a raw-bytes match with malformed frontmatter reparsed
the source outside the per-file YAML handler; catch it and warn.

apm-spec-waiver: Claude-target command frontmatter rendering only; no OpenAPM requirement changes.

Co-authored-by: abhishekacharya200 <[email protected]>
Co-authored-by: copilot-swe-agent[bot] <[email protected]>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔵 Needs a closer look

Human assessment is needed because an unpublished finding shows that rereading an adopted non-UTF-8 command can raise UnicodeDecodeError and halt processing of the remaining commands.

No open issues 🎉

Review effort: Balanced

apm-spec-waiver: Claude-target command frontmatter rendering only; no OpenAPM requirement changes.

Co-authored-by: abhishekacharya200 <[email protected]>
Co-authored-by: copilot-swe-agent[bot] <[email protected]>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔵 Needs a closer look

Human assessment is needed because retained commands with non-string frontmatter keys can still trigger an uncaught TypeError that aborts the batch.

No open issues 🎉

Review effort: Balanced

Copy link
Copy Markdown
Collaborator Author

Copilot's last note (non-string frontmatter keys raise TypeError in the dropped-key sort) is pre-existing on main's write path, not introduced here; tracked in 4922 -> #4922. Head frozen at cc9454b.

#3067)

Only core/remediation.py formats lines starting with "Kept "
(test_remediation_block_proofs); reword the per-file warning.

apm-spec-waiver: Claude-target command frontmatter rendering only; no OpenAPM requirement changes.

Co-authored-by: abhishekacharya200 <[email protected]>
Co-authored-by: copilot-swe-agent[bot] <[email protected]>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔵 Needs a closer look

Human assessment is needed because retained-command handling can incorrectly claim preserved hooks were removed and allow malformed metadata to abort the remaining batch.

No open issues 🎉

Review effort: Balanced

Copy link
Copy Markdown
Collaborator Author

Final Copilot round at 14b959c has no open threads. Its two notes are edge cases outside the fold criteria and are tracked as follow-ups: the retained-warning wording for kept user files that already have hooks (4930), and non-string frontmatter keys (#4922, already on main). CI is green except the inherited deployment_ledger.py file-length Lint red (fixed by #4878). Integration run 45118148868 passed. Head frozen.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

The warning inaccurately implies retained user-edited commands lack hooks; it should say APM omits hooks from rendered output and leaves retained files unchanged.

1 open issue

Review effort: Balanced

Keep main's #4922 non-string-key handling (key=str sort, per-file skip)
alongside the Claude-native preserved set; both test classes kept.

Co-authored-by: Copilot App <[email protected]>
Co-authored-by: copilot-swe-agent[bot] <[email protected]>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues block approval of the Claude command-frontmatter preservation change.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

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.

[BUG] Claude command transform drops frontmatter keys Claude Code supports on commands

2 participants