Compare commits

...
Author SHA1 Message Date
Defame1297andClaude Opus 5.5 e6d680a4c5 fix(kyberforge): apply the #273 review to the apm 0.39.3 refresh
- apm-workflow and apm-orchestrate always pass --project to uv run,
  because uv run outside the project silently runs the PATH apm. The
  agent now checks that the reported version equals the pin, or is
  0.39.2 or later where nothing pins it, not only that it exits 0.
- A pin is a quoted apm-cli or apm_cli requirement plus a uv.lock,
  matching the SessionStart hook, in apm-install, uv-pin.md and
  apm-workflow.
- uv-pin.md spells the hook's exact invocation and its environment
  check, and says scripts always pass --project.
- instructions-author and its research note: a Claude rule leaves
  .claude/rules/ only when compile actually wrote it into AGENTS.md;
  install-then-compile dedups it.
- prompt-author: Kiro strips every key with a warning, not silently.
- Record the 0.39.3 executables findings in approvals-and-executables.md
  and the output-profile and type-routing facts in cli-reference.md, and
  cite those digests.
- forge's routing table notes that Kiro gets the body only.

Refs: #273

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_014uGZTNugst7K9Bd2FTR4Mi
2026-12-02 12:35:19 +00:00
Defame1297andClaude Opus 5.5 c68b67301a chore(release): bump kyberforge to 2.3.1 and delivery to 0.8.1
Patch bumps for the apm 0.39.3 refresh of their skills and docs. The
root executables.allow keys follow at full identity, the catalog moves to
0.9.2, and the marketplace is re-packed. Refresh the root apm.yml grant
comment's quote of the gate-disabled message to the 0.39.3 wording; the
rest of that comment was re-checked on 0.39.3 and holds.

Refs: #273

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_014uGZTNugst7K9Bd2FTR4Mi
2026-12-02 11:59:17 +00:00
Defame1297andClaude Opus 5.5 aaada85e26 docs(plugins): describe full-identity hook grants on apm 0.39
The kyberforge and delivery hook docs still described apm 0.28.0: a bare
kyberforge#<version> or delivery key matching, and "parked pending
approval" printed for a granted package. On 0.39.3 a bare key parks the
hook and deploys nothing with exit 0, the full
<host>/<owner>/<repo>/<path> identity is required, and the #<version>
suffix is still ignored when matching. Re-run the copilot and codex hook
placement on 0.39.3: with codex in targets, apm now creates .codex/
itself.

Refs: #273

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_014uGZTNugst7K9Bd2FTR4Mi
2026-12-02 11:59:17 +00:00
Defame1297andClaude Opus 5.5 0fb106b731 fix(kyberforge): run the repo-pinned apm from apm-workflow
apm-workflow spelled every command as bare apm, which in a repo that pins
apm with uv runs whatever is on PATH, possibly an apm that refuses the
repo's lockfile. Add a step that checks for the pin and runs
uv run --frozen apm there, and the PATH apm otherwise. apm-orchestrate's
version check now probes the same apm.

Bring the references level with apm 0.39.3: the Copilot marketplace
output profile, get_effective_type() still ignoring the declared type,
plain apm audit's exit codes, the uv form of the CI example, and audit
--ci needing an apm at least as new as the lock's writer. Bump
metadata.version to 1.0.4.

Refs: #273

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_014uGZTNugst7K9Bd2FTR4Mi
2026-12-02 11:59:17 +00:00
Defame1297andClaude Opus 5.5 b81af32425 feat(kyberforge): document the per-repo uv pin of apm in apm-install
Add a dispatch on where apm comes from: a repo that pins apm with uv, a
repo that wants the pin, or a global install. The new uv-pin reference
covers the pyproject.toml dev group, the committed uv.lock, running as
uv run --frozen apm, the one-time online sync, upgrading the pin, and why
uvx and uv tool are not used. It closes with a worked example of one
pinned and one unpinned repo.

Raise the pip floor to Python 3.11, which apm requires since 0.36.0, add
the package-manager installs, and note the 0.39.2 minimum for v4 locks.
Bump metadata.version to 1.0.2.

Refs: #273

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_014uGZTNugst7K9Bd2FTR4Mi
2026-12-02 11:59:17 +00:00
Defame1297andClaude Opus 5.5 5f9c805522 fix(kyberforge): bring prompt-author level with apm 0.39.3
apm 0.39 keeps Claude Code command keys such as disable-model-invocation
on the claude target and still drops them on cursor, opencode, windsurf
and grok-build. It withholds hooks, names dropped keys only under
--verbose, deploys a body-only prompt to Kiro, fails install on a
hand-edited deployed command, and writes nothing when a prompt carries a
critical hidden character.

Update the Gotchas, the frontmatter contract, the compatibility line, the
template and every reference. Re-cite forge's prompt-routing table on the
0.39.3 run. Bump prompt-author to 0.1.1 and forge to 1.0.6.

Refs: #273

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_014uGZTNugst7K9Bd2FTR4Mi
2026-12-02 11:59:17 +00:00
Defame1297andClaude Opus 5.5 598f88b536 fix(kyberforge): bring instructions-author level with apm 0.39.3
The skill still described apm 0.28.0. On 0.39.3 an unquoted applyTo fails
install and deploys nothing, the Claude compile writes AGENTS.md behind a
CLAUDE.md that only imports it, dedup is per instruction, unscoped rules
retire from .claude/rules/ once AGENTS.md carries them, and install skips
a hand-authored rule rather than overwriting it.

Update the Gotchas, the compatibility line and the target-mapping, schema,
verify, improve and create references, the template comment, the tests
README and the bats header. Bump metadata.version to 0.1.1.

Refs: #273

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_014uGZTNugst7K9Bd2FTR4Mi
2026-12-02 11:59:17 +00:00
Defame1297andClaude Opus 5.5 bb84e4ac13 docs(kyberforge): record the apm 0.39.3 re-run of the primitive experiments
Re-run the 0.28.0 instruction, prompt and executable-grant experiments on
the repo-pinned apm 0.39.3 in throwaway packages, and record what changed
in instructions-gotchas.md and prompt-gotchas.md. Register the run as the
apm-cli-0-39-3-experiments source so the skills refreshed under #273 can
cite it.

Refs: #273

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_014uGZTNugst7K9Bd2FTR4Mi
2026-12-02 11:59:17 +00:00
Defame1297andClaude Opus 5.5 c2ba7f01bf fix(apm): regenerate apm.lock.yaml from a fresh apm 0.39.3 install
The lock committed in e87bd67 was written by `apm update` over an
apm_modules/ that apm 0.28.0 had populated. The 22 pinned third-party
dependencies (fluxcd gitops skills and mattpocock skills) were reused
from that cache, so the lock lacked their carried_licenses and LICENSE
deployment records. A fresh install writes them, which left the
committed lock out of step with every new checkout and failed
apm-pack-check-clean there on a content-hash mismatch.

Regenerated with `uv run --frozen apm install` after moving apm_modules/
aside: +331/-1, only carried_licenses for those 22 dependencies, their 22
LICENSE deployment records, and generated_at. A second fresh install into
another empty apm_modules/ left the lock byte-identical. Still the
sanctioned lock rewrite (ADR-0034); no tracked .claude/ file changed.

Refs: #271

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_014uGZTNugst7K9Bd2FTR4Mi
2026-12-02 11:27:04 +00:00
Defame1297andClaude Opus 5.5 126831e96f fix(scripts): expand APM_CMD bash-3.2-safely in apm-pack-check-clean
The helper now seeds APM_CMD empty, and a bare "${APM_CMD[@]}" on an
array that can be empty fails under `set -u` on bash 3.2. The bash-4
construct scan in tests/test-vale-wrap.sh caught it at pre-push. Use the
guarded expansion that run_apm already uses.

Refs: #271

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_014uGZTNugst7K9Bd2FTR4Mi
2026-12-02 10:29:51 +00:00
Defame1297andClaude Opus 5.5 b0977d4073 feat(scripts): fail the push on a parked executable in apm.lock.yaml
apm records each dependency's executables decision as `exec_status:` in
the lock. A gated_* value means the trust gate parked that package's
hooks, bin or MCP servers. Root `apm audit --ci` still passes in that
state, so a wrong key would leave the SessionStart hook or the delivery
guard uninstalled with every gate green (spike #269, section 7.3).

check-executables-allow-sync now scans the lock's dependencies and fails
on any gated_* entry, naming its identity and status, with a Why/Fix
block that starts from `apm approve --list`. It runs even when no plugin
here ships executables. The test covers deployed, two gated_* values
under both readers, the no-plugin case, and that neither the next
dependency nor the deployments: section is misreported. gates.md and the
hook description note it.

Refs: #271

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_014uGZTNugst7K9Bd2FTR4Mi
2026-12-02 10:12:06 +00:00
Defame1297andClaude Opus 5.5 045e43f0f8 fix(scripts): describe allow-sync keys as <identity>#<version>
A comment and the name-mismatch message still described the bare
<name>#<version> key. Both now say <identity>#<version>, and that the
directory name is what finds the identity, through the root dependency
entry's `path: plugins/<dir>`.

Refs: #271

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_014uGZTNugst7K9Bd2FTR4Mi
2026-12-02 10:11:41 +00:00
Defame1297andClaude Opus 5.5 5089856c0d fix(scripts): anchor the apm version check to its CLI banner
Match `CLI version X.Y.Z`, the banner apm prints, instead of any
`version X.Y.Z`, so other version-like text on stdout is not taken for
apm's version. Fail clearly when APM holds only whitespace, instead of
running an empty command.

The seam B test now pins both properties. The fake uv also writes a
banner-shaped `uv CLI version 0.0.1` to stderr, so a parser reading the
merged stream fails it (23 failures with the round-1 bug restored). A
stub that prints `version 0.40.0` before a 0.28.0 banner must still fail.
The git-env test's stub prints the real banner.

Refs: #271

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_014uGZTNugst7K9Bd2FTR4Mi
2026-12-02 10:11:28 +00:00
Defame1297andClaude Opus 5.5 0696ce31e7 test(kyberforge): keep the real-apm probe off the network
The probe moves HOME to an empty dir, which also moved uv's cache and its
managed Pythons, leaving uv cold. Pin UV_CACHE_DIR and
UV_PYTHON_INSTALL_DIR to the real ones resolved beforehand, and set
UV_OFFLINE so the probe runs the synced pin and never fetches. Verified
under `unshare -rn`.

Refs: #271

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_014uGZTNugst7K9Bd2FTR4Mi
2026-12-02 09:47:45 +00:00
Defame1297andClaude Opus 5.5 dca0b5823b fix(scripts): refuse a dependency URL with a port in the allow-sync gate
How apm 0.39 writes a port into a package identity is unverified, so a
key derived from a git: URL with a port could be wrong while looking
right. The gate now fails clearly on one, naming `apm approve --list` as
the way to read the real identity. The script and gates.md record that
only an https URL on a lowercase host was checked against apm.

The test drops its GNU-only `sed -i` for a python3 rewrite, and covers
ssh:// and https URLs with a port under both readers.

Refs: #271

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_014uGZTNugst7K9Bd2FTR4Mi
2026-12-02 09:47:38 +00:00
Defame1297andClaude Opus 5.5 615d3dd881 fix(scripts): parse the apm version from stdout and its banner only
require_apm_version merged stderr into the --version output and took the
first X.Y.Z. When `uv run --frozen` syncs first, uv prints
`Using CPython 3.14.6` on stderr, so the check parsed 3.14.6 and passed
whatever apm reported. It now reads stdout only, matches apm's
`version X.Y.Z` banner, and shows the captured stderr only on failure.

The fake uv in the seam B test now writes that line to stderr, so the
regression stays pinned. Resolve the repo root with CDPATH cleared.

Refs: #271

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_014uGZTNugst7K9Bd2FTR4Mi
2026-12-02 09:47:30 +00:00
Defame1297andClaude Opus 5.5 a48f0fdf5b docs: document the uv-pinned apm setup and full-identity allow keys
README: uv replaces the global apm as a prerequisite, setup starts with
`uv sync --frozen`, and the offline note names both one-time steps.
gates.md: the apm hooks run through scripts/lib/apm.sh with plain
--frozen (and why the gates, unlike the SessionStart hook, keep the
sync), and check-executables-allow-sync expects the full package
identity apm 0.39 matches on.

Refs: #271

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_014uGZTNugst7K9Bd2FTR4Mi
2026-12-02 08:47:53 +00:00
Defame1297andClaude Opus 5.5 e87bd67c1f chore(apm): regenerate apm.lock.yaml with the pinned apm 0.39.3
Written by `uv run --frozen apm update --yes` on apm 0.39.3: lockfile
version 4, apm_version 0.39.3, and every dependency resolved to main at
feef6d8, which records kyberforge 2.3.0 from #270. This is the one
sanctioned exception to discarding lock churn on a feature branch
(ADR-0034, ADR-0019).

With the full-identity approvals both hooks stay deployed (exec_status
deployed). .claude/settings.json and .claude/apm-hooks.json keep the
PreToolUse guard and SessionStart entries; their only change is
kyberforge 2.3.0's hook timeout, 380 to 400. No apm-owned file was edited
by hand.

Refs: #271

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_014uGZTNugst7K9Bd2FTR4Mi
2026-12-02 08:47:43 +00:00
Defame1297andClaude Opus 5.5 5842be70cc test(kyberforge): run the instructions-author bats suite on the pinned apm
need_apm now runs apm through scripts/lib/apm.sh, so the suite exercises
the repo-pinned 0.39.3 and never a PATH apm. In this repo a missing uv or
an apm below 0.39.2 fails rather than skips, so run-tests.sh --strict
cannot pass without running these tests. Outside the repo it still falls
back to PATH apm and skips without one.

Three assertions pinned 0.28.0 behaviour and are updated to 0.39.3's:
compile --target claude writes a CLAUDE.md that imports AGENTS.md, an
unquoted applyTo fails install closed and deploys nothing, and compile
warns when applyTo matches no file. The skill's own text still describes
the 0.28.0 behaviour; that is left for a skill update.

Refs: #271

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_014uGZTNugst7K9Bd2FTR4Mi
2026-12-02 08:47:35 +00:00
Defame1297andClaude Opus 5.5 7291b46271 feat(scripts): run the apm gates through the uv-pinned apm
Add scripts/lib/apm.sh, the one place the repo spells its apm command:
`uv run --project <repo root> --frozen apm`. --project comes from the
helper's own location, so it names the repo root even when apm runs inside
plugins/<name>/. Sourcing it keeps the git-env scrub (#204), and
require_apm_version fails with a clear message, naming `uv sync --frozen`,
when the resolved apm is below 0.39.2, unreadable, or uv is missing. APM
overrides the command, as ADR-0034 provides.

apm-audit-ci.sh and apm-pack-check-clean.sh use it. The audit script's
matching logic is unchanged; only its verified-against note now records
0.39.3.

tests/test-apm-gate-invocation.sh is seam B: a fake uv and a stub apm
first on a PATH without the real ones. It proves the command shape,
--project from a plugin directory, the scrub, and the version floor.
test-apm-hooks-git-env.sh reaches its stub through a fake uv, and the
real-apm probe in test-apm-current-hook.sh now runs the pinned apm.

Refs: #271

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_014uGZTNugst7K9Bd2FTR4Mi
2026-12-02 08:47:12 +00:00
Defame1297andClaude Opus 5.5 d15688ee99 build: pin apm-cli 0.39.3 per repo with uv
Add a root pyproject.toml with no build system, uv package mode off,
Python 3.11 or later, and a dev dependency group pinning apm-cli==0.39.3,
as ADR-0034 decides. Commit the uv.lock that hashes apm-cli and its
transitive dependencies, and ignore uv's .venv/.

Refs: #271

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_014uGZTNugst7K9Bd2FTR4Mi
2026-12-02 08:47:06 +00:00
Defame1297andClaude Opus 5.5 e1a99a7291 fix(apm): key executables.allow on the full 0.39 package identity
apm 0.39.3 matches executable grants on the package identity
<host>/<owner>/<repo>/<path>. The bare kyberforge#<version> and
delivery#<version> keys that 0.28.0 matched no longer match, so the first
0.39 install parks both hooks and rewrites .claude/settings.json without
them, while root apm audit --ci stays green (spike #269, on #268).

Rename both keys to git.rkdr.net/Mortis/Holocron/plugins/<name>#<version>
with type-level grants, as `apm approve --list` names them on 0.39.3. Keep
the version suffix convention; apm strips it before matching. Do not use
`apm approve`, which would content-pin, strip the block's comments and
park the hook on every script edit.

check-executables-allow-sync now derives each expected key from root
apm.yml's git + path dependency entry for the plugin, fails a bare key with
a message saying why, and fails a shipping plugin with no such entry. Both
readers carry the change, and the test covers URL and path spellings.

Refs: #271

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_014uGZTNugst7K9Bd2FTR4Mi
2026-12-02 08:46:38 +00:00
Defame1297 feef6d8307 Merge pull request 'feat(kyberforge): SessionStart hook resolves the repo-pinned apm (#270)' (#274) from feat/270-hook-resolves-pinned-apm into main
Reviewed-on: #274
2026-12-02 08:14:05 +00:00
Defame1297andClaude Opus 5.5 45d740eef1 fix(kyberforge): pick the timeout binary first and tidy review-round-2 points
Review round 2 of #270, all non-blocking.

- Resolve `timeout`/`gtimeout` before choosing apm, so a machine with
  neither stays silent on every path, the uv not-synced notice included.
- The uv-path unreadable-version notice also offers `uv sync --frozen`.
- Tests: a `timeout` shim replaces the real binary in the whitelisted PATH
  (and backs `gtimeout`), so the suite runs on macOS without coreutils; add
  a PATH-route case where `apm --version` exits 1, and a no-timeout case on
  the uv path; fix two stale comments.
- ADR-0034: contract item 1 now spells out `--frozen --no-sync --offline`
  and the missing-environment short-circuit; amendment dated 2026-12-02.
- ADR-0019: the 2026-12-02 amendment moves below the 2026-09-16 one.
- docs/hooks.md: rewrap an over-long line.

Refs: #270

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_014uGZTNugst7K9Bd2FTR4Mi
2026-12-02 00:51:25 +00:00
Defame1297andClaude Opus 5.5 367cc1c259 fix(kyberforge): bound the SessionStart hook portably and sharpen its notices
Review round 1 of #270.

- Resolve `timeout`, else `gtimeout`, once after choosing apm, and call it
  through "$to" at all three sites. Stock macOS has neither `timeout` nor a
  GNU coreutils default, so the `--version` call failed there and every
  session printed a false too-old notice. With neither binary the hook exits
  0 silently. The budget test now parses `"$to" N` too.
- Check that the project environment ($UV_PROJECT_ENVIRONMENT, else
  <root>/.venv) exists before taking the uv path. If it is missing, print a
  fixed not-synced notice and never call uv, because `uv run --no-sync`
  would create an empty .venv in the consumer repo.
- Separate "version too old" from "version unreadable or timed out", with a
  fixed literal for each on each path, so a timeout no longer blames an
  unsynced environment.
- Raise the hooks.json timeout from 380 to 400 for the 375s script budget,
  refresh the outdated-timing comment, and note the budget in ADR-0019.
- Tests: no timeout binary, gtimeout only, missing and relocated project
  environment, a failing `uv run`, `--offline` required on every uv call,
  and the hostile-output notice compared to its exact literal.
- ADR-0034: until the #271 cutover, this repo prints the too-old notice and
  auto-refresh is paused.

Refs: #270

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_014uGZTNugst7K9Bd2FTR4Mi
2026-12-02 00:25:14 +00:00
Defame1297andClaude Opus 5.5 1fb8cc797b feat(kyberforge): resolve the repo-pinned apm in the SessionStart hook
The hook now picks one apm and uses it for both the outdated check and the
update (ADR-0034): `uv run --project <root> --frozen --no-sync --offline apm`
when the project pins apm-cli (a quoted apm-cli requirement in pyproject.toml
plus a uv.lock) and uv is on PATH, else the PATH apm, else it exits silently.
uv is only ever called as `uv run`; `--no-sync` keeps a plain run from syncing
the environment, and `--offline` keeps uv off the network.

Before the outdated check it reads `--version`. Below 0.39.2, or when the
version cannot be read, it prints a fixed notice naming the chosen binary and
skips the check, since an older apm refuses a lockfile v4 and would report it
as up to date. All advice strings are fixed literals that name the chosen
binary; no command output is interpolated.

Tests use seam A: a fake uv first on a whitelisted PATH logs every call and
reaches the pinned fake apm only through `uv run`. They cover pin plus uv, pin
without uv, pin without uv.lock, no pin, no apm, too-old and boundary
versions, stale and current output on both paths, and hostile output.
ADR-0034 is amended to record that seam.

Impact: kyberforge 2.2.1 -> 2.3.0, catalog 0.9.0 -> 0.9.1.

Refs: #270

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_014uGZTNugst7K9Bd2FTR4Mi
2026-12-02 00:05:03 +00:00
Defame1297 0ad15c80bc Merge pull request 'docs(adr): pin apm per repo with uv (#265)' (#267) from docs/plan-pin-apm-per-repo into main
Reviewed-on: #267
2026-12-01 22:40:31 +00:00
Defame1297andClaude Opus 5.5 5ca2056046 docs(research): refresh apm reference set to 0.39.3 (#265)
Add lockfile-and-compatibility, approvals-and-executables and
migration-0-28-to-0-39 topics; update installation, cli-reference, the
prompt, hooks and instructions topics for 0.39.x behaviour; label the
remaining 0.28.0 observations by version. Sources: the v0.39.3 source,
CHANGELOG and docs; Context7 was unavailable.

Refs #265

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_014uGZTNugst7K9Bd2FTR4Mi
2026-12-01 21:46:06 +00:00
Defame1297andClaude Opus 5.5 a0997cbcf7 docs(adr): pin apm per repo with uv (ADR-0034)
Record that apm is pinned per repo with uv (minimum 0.39.2, pinned
0.39.3), shipped hook-first, with the consumer hook fallback contract.
Add forward notes on ADR-0019 and ADR-0033 for their 0.28.0 claims,
pending re-verification on 0.39.3.

Refs #265, #245

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_014uGZTNugst7K9Bd2FTR4Mi
2026-12-01 21:14:27 +00:00
Defame1297 e17237a9e2 Merge pull request 'docs(readme): document consumer pinning with the object form (#235, #236)' (#259) from docs/consumer-pinning-readme into main
Reviewed-on: #259
Reviewed-by: Defame1297 <[email protected]>
2026-12-01 20:08:16 +00:00
Defame1297andClaude Opus 5.5 389b5cc425 docs(readme): document consumer pinning with the object form
Expand README "For external consumers" with how to pin a plugin at
<plugin>-v<x.y.z> using apm's object form, why the shorthand form fails
on this host, and that Renovate updates are planned but untested
(ADR-0033 consequence 3). Point the ref: line in the bin, core, git and
kyberforge READMEs at that section.

Refs #235, #236

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_014uGZTNugst7K9Bd2FTR4Mi
2026-11-29 19:54:37 +00:00
Defame1297 276fd1f099 Merge pull request 'docs(adr): amend ADR-0033 for object-form pins (#235, #236)' (#258) from docs/adr-0033-consumer-pin-amendment into main
Reviewed-on: #258
Reviewed-by: Defame1297 <[email protected]>
2026-11-29 19:20:59 +00:00
Defame1297andClaude Opus 5.5 b4a452b690 docs(adr): amend ADR-0033 — withdraw apm-manager packageRule
Renovate's apm manager reads only the shorthand form, which apm cannot
install for a Gitea subpath, so the overridePackageName rule cannot work.
Record the object-form consumer pin and the planned, untested customManagers
route. The tag shape decision is unchanged.

Refs #235, #236

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_014uGZTNugst7K9Bd2FTR4Mi
2026-11-29 18:51:20 +00:00
Defame1297 0abe97270b Merge pull request 'chore(apm): lock plan 0.5.0' (#257) from chore/lock-plan-0.5.0 into main
Reviewed-on: #257
2026-11-29 18:32:21 +00:00
Defame1297andClaude Opus 5.5 1e1c2c1ce2 chore(apm): lock plan 0.5.0
Refresh the lock after #256: write-docs is now deployed from plan, not bin.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_014uGZTNugst7K9Bd2FTR4Mi
2026-11-29 18:12:28 +00:00
75 changed files with 5875 additions and 408 deletions

No files matched your search

+3 -3
View File
@@ -1,7 +1,7 @@
{
"name": "holocron",
"description": "AI development skills for Claude Code, and for GitHub Copilot through apm — factory, design, implement, review, and cross-cutting workflows.",
"version": "0.9.0",
"version": "0.9.2",
"owner": {
"name": "Mortis",
"url": "https://git.rkdr.net/Mortis/"
@@ -10,7 +10,7 @@
{
"name": "kyberforge",
"description": "Skills and agents for creating, maintaining, and managing an apm plugin marketplace for Claude Code and GitHub Copilot.",
"version": "2.2.1",
"version": "2.3.1",
"category": "Developer Tools",
"source": "./plugins/kyberforge"
},
@@ -59,7 +59,7 @@
{
"name": "delivery",
"description": "Agents and skills for taking a change from spec to a verified merge through tracker-gated stages.",
"version": "0.8.0",
"version": "0.8.1",
"category": "Developer Tools",
"source": "./plugins/delivery"
},
+1 -1
View File
@@ -20,7 +20,7 @@
{
"type": "command",
"command": "\"${CLAUDE_PROJECT_DIR}/.claude/hooks/kyberforge/.apm/hooks/check-apm-current.sh\"",
"timeout": 380
"timeout": 400
}
],
"_apm_source": "Mortis/Holocron/plugins/kyberforge"
+1 -1
View File
@@ -20,7 +20,7 @@
{
"type": "command",
"command": "\"${CLAUDE_PROJECT_DIR}/.claude/hooks/kyberforge/.apm/hooks/check-apm-current.sh\"",
"timeout": 380
"timeout": 400
}
]
}
+4
View File
@@ -66,3 +66,7 @@ build/
# apm copies the whole hooks directory, so a stray cache would deploy with it.
__pycache__/
*.pyc
# uv's project environment for the repo-pinned apm (ADR-0034). Created by
# `uv sync --frozen` from the committed uv.lock; machine-local, never content.
.venv/
+1 -1
View File
@@ -71,7 +71,7 @@ repos:
- id: check-executables-allow-sync
name: Check executables allow keys sync
description: Verify root apm.yml's executables.allow carries a "<name>#<version>" key matching the apm.yml version of every plugin that ships executables (plugins/<name>/.apm/hooks/ or bin/), reporting every out-of-sync package in one run. apm's grant is version-blind, so a stale key still deploys; this is a record-keeping gate that fails a version bump made without the matching key edit, keeping each key an accurate record of what was approved (see ADR-0019's 2026-09-19 correction and docs/spec/gates.md)
description: Verify root apm.yml's executables.allow carries a "<host>/<owner>/<repo>/plugins/<name>#<version>" key -- the full package identity apm 0.39 matches on, derived from root apm.yml's git+path dependency entry for the plugin, plus the plugin's apm.yml version -- for every plugin that ships executables (plugins/<name>/.apm/hooks/ or bin/), reporting every out-of-sync package in one run. A bare "<name>#<version>" key fails, because apm 0.39 parks the hooks under it while root `apm audit --ci` stays green (spike #269). The version half is version-blind to apm, so a stale version still deploys; that half is a record-keeping gate that fails a version bump made without the matching key edit (see ADR-0019's 2026-09-19 correction and docs/spec/gates.md). It also fails when apm.lock.yaml records any gated_* exec_status, a parked executable that root `apm audit --ci` lets through
entry: bash scripts/check-executables-allow-sync.sh
language: system
stages: [pre-push]
+43 -7
View File
@@ -36,7 +36,7 @@ Install all of these before setting up. Each one is a hard dependency of a git h
| Tool | Why | Install |
| --- | --- | --- |
| `apm` CLI | Two pre-push hooks shell out to it (`apm-audit-ci` and `apm-pack-check-clean`) | The `apm-install` skill, or `curl -sSL https://aka.ms/apm-unix \| sh`. Verify with `apm --version` |
| `uv` | Runs this repo's pinned apm. The root `pyproject.toml` pins `apm-cli==0.39.3` and `uv.lock` locks it (ADR-0034); the `apm-audit-ci` and `apm-pack-check-clean` pre-push hooks run it as `uv run --frozen apm` through `scripts/lib/apm.sh`, and fail below apm 0.39.2 | https://docs.astral.sh/uv/getting-started/installation/. A global `apm` is not needed and not used: a bare `apm` here may be an older one that refuses the v4 `apm.lock.yaml` |
| `python3` + PyYAML | Required by `scripts/skill-size-check.sh` (the `skill-size-check` pre-commit hook) and `scripts/check-skill-version-bump.sh` (the `check-skill-version-bump` pre-push hook), which both parse YAML frontmatter | `python3` is usually present — pre-commit is itself a Python application. `pip install pyyaml` if the hook reports PyYAML missing |
| `vale` | Required by the `vale-audit-prefilter-skill` / `-agent` pre-commit hooks, and by the `test-vale-wrap.sh` suite that `run-tests --strict` runs at pre-push | `brew install vale` (macOS), `snap install vale` (Linux), `choco install vale` (Windows), or https://vale.sh/docs/vale-cli/installation/ |
| `claude` CLI | Required by the `validate-marketplace` pre-push hook | Claude Code |
@@ -51,14 +51,19 @@ Two notes worth reading before you skip one:
Run these in order, from the repo root.
```bash
# 1. Deploy this repo's own skills and agents
apm install
# 1. Install the pinned apm into .venv/ (gitignored)
uv sync --frozen
# 2. Install the git hooks — all three stages
# 2. Deploy this repo's own skills and agents
uv run --frozen apm install
# 3. Install the git hooks — all three stages
pre-commit install -t pre-commit -t commit-msg -t pre-push
```
**`apm install`** deploys the plugins root `apm.yml` lists into `.claude/skills/` and `.claude/agents/`. Both are gitignored install output, *not* authoring source — `plugins/<name>/.apm/` remains the only place to edit. It needs the network and materializes `apm_modules/` (which stays gitignored).
**`uv sync --frozen`** installs the apm that `uv.lock` pins into `.venv/`. Every apm command in this repo runs as `uv run --frozen apm ...`.
**`apm install`** deploys the plugins root `apm.yml` lists into `.claude/skills/` and `.claude/agents/`. Both are gitignored install output, *not* authoring source — `plugins/<name>/.apm/` remains the only place to edit. Both steps need the network once, and `apm install` materializes `apm_modules/` (which stays gitignored).
**Git hooks** must be wired for **all three stages**. This repo's `.pre-commit-config.yaml` has no `default_install_hook_types`, so a plain `pre-commit install` silently skips `commit-msg` (Conventional Commits) and `pre-push` (the full gate) — the `-t` flags above are not optional. The `pc-run` skill handles this and the troubleshooting around it, if you would rather not remember the flags.
@@ -92,7 +97,7 @@ pre-commit run --hook-stage pre-push --all-files
See [`docs/spec/gates.md`](docs/spec/gates.md) for what each hook enforces and why.
**Offline?** No pre-push hook needs the network **once `apm install` has populated `apm_modules/`**. Root `apm.yml`'s marketplace has no remote package entries (the last one, `mattpocock-skills`, was removed), so `apm-pack-check-clean` resolves everything from local sources, and `apm-audit-ci`'s install-replay is cache-only against a populated install. On a **fresh clone** there is no cache: `apm-audit-ci`'s `deployed-files-present` fails outright, and its `drift` and `config-consistency` checks clone from the holocron remote. The offline guarantee is a property of a populated `apm_modules/`, not of the hook set — run `apm install` once on a new checkout and it holds from then on.
**Offline?** No pre-push hook needs the network **once `uv sync --frozen` and `apm install` have each run once** (ADR-0034). Root `apm.yml`'s marketplace has no remote package entries (the last one, `mattpocock-skills`, was removed), so `apm-pack-check-clean` resolves everything from local sources, and `apm-audit-ci`'s install-replay is cache-only against a populated install. On a **fresh clone** there is no cache: `apm-audit-ci`'s `deployed-files-present` fails outright, and its `drift` and `config-consistency` checks clone from the holocron remote. The offline guarantee is a property of a populated `apm_modules/`, not of the hook set — run `uv sync --frozen` and `uv run --frozen apm install` once on a new checkout and it holds from then on.
## Editing plugin content
@@ -111,7 +116,38 @@ An agent may run all four steps, but it runs step 4 only after the maintainer ex
## For external consumers
Consume the packages through apm, the way this repo does — declare them as `dependencies.apm` git+path entries against the holocron remote and run `apm install`. apm is the only supported install path.
Consume the packages through apm, the way this repo does. apm is the only supported install path.
### Pinning a plugin to a release
Each plugin is released as a git tag `<plugin>-v<x.y.z>`, for example `git-v1.3.9`
([ADR-0033](docs/adr/0033-plugin-releases-are-tagged-plugin-v-version.md)). Pin one with apm's
object form, keys in this order (the planned Renovate rule matches only this order):
```yaml
dependencies:
apm:
- git: https://git.rkdr.net/Mortis/Holocron.git
path: plugins/git
ref: git-v1.3.9
```
Then run `apm install`. Without `ref:`, the entry tracks the default branch. To list a plugin's
releases, run `git ls-remote --tags https://git.rkdr.net/Mortis/Holocron.git '<plugin>-v*'`;
`apm outdated` also reports newer `<plugin>-v<x.y.z>` tags.
### Do not use the shorthand form
The shorthand `git.rkdr.net/Mortis/Holocron/plugins/<name>#<plugin>-v<x.y.z>` does not work on this
host. apm reads `plugins/<name>` as part of the repository path, so a real install tries to clone
`.../Holocron/plugins/<name>.git` and fails with "Not found". `apm install --dry-run` does not catch
this. Use the object form.
### Automated updates
Renovate's `apm` manager cannot update these pins: it reads only the shorthand form and drops
object-form entries. A Renovate regex manager on the `ref:` line is planned but untested, so bump
`ref:` by hand until a verified rule is published here. See ADR-0033 consequence 3.
## Where to go next
+1114 -67
View File
File diff suppressed because it is too large. Load diff
+25 -18
View File
@@ -1,5 +1,5 @@
name: holocron
version: 0.9.0
version: 0.9.2
description: AI development skills for Claude Code, and for GitHub Copilot through apm — factory, design, implement, review, and cross-cutting workflows.
license: MIT
@@ -55,29 +55,36 @@ dependencies:
# Turns apm's executable-trust gate ON. Without this block the gate is disabled
# and every hook, bin and MCP primitive a dependency ships deploys silently —
# verified: `apm approve --list` reports "Executable-trust gate disabled -- all
# executables deploy" until an `executables:` block exists.
# verified on 0.39.3: `apm approve --list` reports "Executable-trust gate
# disabled -- executables need no approval" until an `executables:` block
# exists.
#
# Keys are the FULL package identity apm 0.39 matches on,
# <host>/<owner>/<repo>/<path>#<version>, as `apm approve --list` prints it.
# The bare `kyberforge#<version>` form 0.28 accepted no longer matches: under
# 0.39.3 it parks both hooks, writes `.claude/settings.json` back to `{}`, and
# root `apm audit --ci` still passes (spike #269, on #268). The `#<version>`
# suffix is stripped before matching, so the grant is version-blind and a
# plugin bump alone does not park the hook; the suffix is a repo convention
# that `scripts/check-executables-allow-sync.sh`, a pre-push hook, holds level
# with each plugin's apm.yml `version:`.
#
# The grants are type-level (`hooks: true`), not content-pinned. Every install
# warns that they are not pinned to content; that is accepted, because a
# content pin parks the hook on every edit to its scripts until someone re-runs
# `apm approve`. Do not run `apm approve` here: it rewrites this block, adds
# content pins and strips these comments.
#
# kyberforge ships the SessionStart hook that keeps this install level with the
# remote (ADR-0019). The `#2.0.0` suffix below is cosmetic as far as apm is
# concerned: grants are version-BLIND in apm 0.28.0. `_map_grants`
# (apm_cli/security/executables.py) matches the exact key, the version-blind
# name, or any stored key sharing that name, and `materialize_exec_map` also
# stores the version-blind name — so approving `kyberforge` covers
# `kyberforge#2.0.0` and vice-versa, and a kyberforge version bump does NOT
# make this entry stop matching or stop the hook deploying. Do not delete the
# suffix anyway: `scripts/check-executables-allow-sync.sh` is a repo-authored
# pre-push hook that asserts this key carries the version in
# plugins/kyberforge/apm.yml, so a bump here is a repo convention to keep, not
# an apm mechanic.
# remote (ADR-0019).
executables:
allow:
kyberforge#2.2.1:
git.rkdr.net/Mortis/Holocron/plugins/kyberforge#2.3.1:
hooks: true
bin: true
# delivery ships the guard hook (ADR-0032 enforcement layer 2). Same
# version-in-key convention as above, kept by the same sync check.
delivery#0.8.0:
# full-identity, version-in-key convention as above, kept by the same check.
git.rkdr.net/Mortis/Holocron/plugins/delivery#0.8.1:
hooks: true
marketplace:
@@ -86,7 +93,7 @@ marketplace:
# top-level apm.yml description:/version: above are NOT inherited into the
# compiled output despite being used elsewhere (e.g. by `apm audit`).
description: AI development skills for Claude Code, and for GitHub Copilot through apm — factory, design, implement, review, and cross-cutting workflows.
version: 0.9.0
version: 0.9.2
owner:
name: Mortis
url: https://git.rkdr.net/Mortis/
@@ -7,6 +7,11 @@ and nothing detects it.
**Status: accepted (2026-08-14).**
*Amended 2026-12-01 (holocron#265): the hook resolves apm through the contract in ADR-0034 (a
repo-pinned `uv run --frozen` apm, else `PATH` apm, else exit 0) instead of a bare `command -v apm`.
The "0.28.0" claims below (the correction near line 80, the `apm outdated` prose at about line 143,
and the sidecar reproduction at about line 217) are pending re-verification on 0.39.3 under #265.*
## Context
The pre-existing answer was `scripts/git-hooks/post-push`, which pulled the marketplace clone and
@@ -139,6 +144,11 @@ value to be larger — so changing either side without the other fails the suite
> Re-measured: ~24–26 s for the same six-behind refresh, warm, on a LAN remote — well inside the
> 380 s above.
> **Amendment (2026-12-02, holocron#270) — the budget is now 375 s and the host timeout 400 s.** The
> hook also reads `apm --version` under a 15 s bound before the outdated check (ADR-0034), and calls
> `timeout` or `gtimeout` through a variable, which the budget test parses too. The current numbers
> and their breakdown live in `plugins/kyberforge/docs/hooks.md`.
**Reading a human-readable CLI for a control decision cost a silent failure, again.** `apm outdated`
has no `--json` or other machine-readable flag (confirmed against 0.28.0), so the hook must match
its prose. The first attempt matched `outdated dependencies found` — plural only. apm emits
@@ -2,6 +2,10 @@
**Status: accepted (2026-11-27).**
*Amended 2026-12-01 (holocron#265): the 0.28.0 claims in this ADR (the `apm outdated` tag-pattern
check in Context and the apm behaviour in consequence 3) are pending re-verification on 0.39.3 under
#265, once apm is pinned per repo (ADR-0034). The Decision is unchanged.*
## Context
Issue #223. Consumers that pin a holocron package need a git tag per package version. Two consumers
@@ -9,6 +13,9 @@ are known, and both read the same tag shape:
- **Renovate's `apm` manager** (≥ 44.153.0) looks up a dependency on a `plugins/<name>` subpath
through the `git-tags` datasource. It considers only tags of the form `<prefix>-v<x.y.z>`.
*Amended 2026-11-29 (holocron#235, #236): this is wrong for Holocron consumers. The manager reads
only the shorthand form, which apm cannot install for a Gitea subpath, so it does not serve them
today. See consequence 3.*
- **`apm outdated`** matches the tag pattern `{name}-v{version}`. This was verified with apm 0.28.0
against a synthetic repo, and `apm_cli/marketplace/tag_pattern.py` lists `{name}-v{version}`
among its patterns.
@@ -159,20 +166,29 @@ cuts the same tags on the same commits.
**2. The root catalogue's version is not tagged per plugin.** Only the `plugins/<name>/apm.yml`
versions get `<plugin>-v*` tags. The marketplace catalogue's own version is out of scope.
**3. Renovate consumers on this Gitea need an `overridePackageName` rule until upstream fixes
it.** On hosts other than GitHub and GitLab, Renovate's apm manager does not strip `/plugins/<name>`
from the package URL (`lib/modules/manager/apm/extract.ts`, `resolveRepoPath`), so its `git-tags`
lookup targets a repo that does not exist. A consumer-side `packageRules` entry along these lines
rewrites it. **It is untested.**
**3. Consumers pin with the object form; the `apm` manager does not update them.** *Amended
2026-11-29 (holocron#235, #236); this replaces the original consequence 3, an `overridePackageName`
`packageRules` entry, which is withdrawn.* It was untested and cannot work, for any form:
```json
{
"matchManagers": ["apm"],
"matchDatasources": ["git-tags"],
"matchPackageNames": ["/\\/plugins\\/[^/]+$/"],
"overridePackageName": "{{{replace '/plugins/[^/]+$' '' packageName}}}"
}
```
- On a generic git host such as this Gitea, apm (0.28.0, and still on `main` at 0.39.1) cannot
resolve a plugin subdirectory from the shorthand form. `<host>/Mortis/Holocron/plugins/<name>#ref`
folds `plugins/<name>` into the repo path, and an install clones `.../plugins/<name>.git` and
fails with "Not found". The separate `rstrip(".git")` parse bug (0.28.0) is already fixed upstream
(microsoft/apm#3715, PR #3767).
- The object form (`git:` + `path:` + `ref:`) is the only working way to pin a Holocron plugin.
Consumers set `ref: <plugin>-v<x.y.z>`.
- Renovate's `apm` manager (schema `apm: LooseArray(z.string())`) extracts only shorthand strings and
silently drops object-form entries. No `apm.yml` entry is both installable by apm and updatable by
that manager for a Gitea subpath, so no `packageRules` entry can fix it.
The planned route is a Renovate `customManagers` regex manager on the object-form `ref:` line: the
`git-tags` datasource, a `currentValue` capturing only the version after `<plugin>-v`, an
`extractVersion` scoped to that plugin's own prefix, and automerge off. **This is planned and
untested, and no snippet is given.** The verified rule goes in a later amendment, after a live
consumer proof. Two upstream reports are to be filed: an apm issue for generic-host subpath folding,
and a Renovate Discussion for object-form extraction.
The Decision, the tag shape `<plugin>-v<version>`, is unchanged by this amendment.
**4. For a maintainer, Gitea's `create_tag` is an equivalent way to cut a tag**, provided
`git cat-file -t <tag>` reports `tag` after fetching. That confirms it is annotated; the script
@@ -0,0 +1,97 @@
# apm is pinned per repo with uv
**Status: accepted (2026-12-01).**
*Amended 2026-12-02 (holocron#270): the hook's test seam is a `PATH` stub of `uv`, not an `APM`
environment override. `tests/test-apm-current-hook.sh` puts a fake `uv` first on a `PATH` that
excludes the machine's real `uv` and `apm`. The fake records every invocation and reaches the pinned
fake apm only through `uv run`, so the shipped hook carries no test-only override. The `APM` variable
under Invocation still applies to repo scripts, not to the hook. The hook also passes `--no-sync` and
`--offline` to `uv run`. A plain `uv run --frozen` syncs the environment before running, which is the
uv sync and the network access this contract forbids.*
## Context
Issue #265. apm is installed once per machine with pipx, at 0.28.0, and every repo and the
`SessionStart` hook (ADR-0019) call whatever `apm` is on `PATH`. Three things now fail against that:
- **Lockfile format.** apm 0.37 and later write lockfile v4, and apm 0.36.1 and earlier refuse it. A
lock written by 0.39.2 is in turn refused by 0.37.0 through 0.39.1.
- **Command keys.** apm 0.39.0 and later keep Claude command keys such as `disable-model-invocation`
(#245). Earlier versions drop them, so a deployed command silently loses the setting.
- **Machine-global drift.** One shared binary means every checkout's behaviour depends on what was
last installed on that machine. apm has no minimum-version field in `apm.yml`, and upstream's advice
is to pin a minimum in CI. This repo has no CI (ADR-0024), so the pin has to live in the repo.
## Decision
**Each repo pins its own apm with uv. This repo needs apm 0.39.2 or later and is pinned to 0.39.3.**
- **Pin.** The root `pyproject.toml` has no build system, sets `[tool.uv] package = false` and
`requires-python = ">=3.11"`, and declares `[dependency-groups] dev = ["apm-cli==0.39.3"]`. A
committed `uv.lock` fixes the transitive dependencies. `.venv/` is gitignored.
- **Invocation.** Repo scripts run apm as `uv run --project <repo root> --frozen apm`. An `APM`
environment variable overrides the command, as a seam for tests.
- **Minimum version, 0.39.2.** It is the lowest version that reads and writes lockfile v4 and is
read back by later versions, and it is at or above 0.39.0, which keeps the Claude command keys.
Inside this repo the `==` pin enforces it. Where apm comes from `PATH` (a consumer repo that does
not pin), an explicit version check enforces it.
- **uv only pins apm itself.** ADR-0024 stands: apm is the only supported install path for plugin
content. uv installs the tool, never plugins, skills or agents.
- **Hook first.** The kyberforge `SessionStart` hook change ships first, with a kyberforge version
bump and its release tag (ADR-0033). The cutover (the v4 lock, `pyproject.toml`, `uv.lock`, the
scripts and their tests) follows as one PR. The order matters because the deployed hook comes from
the `main` commit that `apm.lock.yaml` records. If the v4 lock landed first, the old hook would run
`PATH` apm 0.28.0, which refuses the lock, and staleness detection would be lost with no error.
The cost of this order: between the hook landing and the cutover, this repo has no pin, so the hook
runs `PATH` apm 0.28.0 and prints the fixed too-old notice at every session start. Auto-refresh
is paused here until the #271 cutover adds the pin.
- **The cutover PR commits a lock rewrite (v1 to v4) on purpose.** It is the one sanctioned exception
to the rule that `apm.lock.yaml` churn is discarded on feature branches (ADR-0019).
- **Consumer hook contract.** The shipped hook (`check-apm-current.sh`) resolves apm in this order:
1. `uv run --frozen --no-sync --offline`, when the project pins `apm-cli` (a quoted `apm-cli`
requirement in `pyproject.toml` plus a `uv.lock`) and uv exists. If the project environment
(`$UV_PROJECT_ENVIRONMENT`, else `<root>/.venv`) does not exist, the hook prints a fixed "not
synced, run `uv sync --frozen`" notice and never calls uv, because even `--no-sync` creates an
empty `.venv`.
2. `apm` on `PATH`.
3. Neither: exit 0. So does a machine with no `timeout` or `gtimeout`, on every path.
It never triggers a uv sync, and on a cold cache it must not touch the network inside the
`SessionStart` timeout. It never reports "up to date" when it ran on an apm older than 0.39.2. Its
advice strings are fixed and name the chosen binary, with no interpolation of command output.
- **Global apm 0.28.0 stays.** It stays installed and on `PATH`, because ansible still uses it
(Defame1297/ansible-homelab-mono#1078). It is not upgraded. Whichever of that issue and
Mortis/Kamino#499 lands last uninstalls it: the last mover deletes.
- **New setup step.** The offline pre-push guarantee of ADR-0019 now needs `uv sync --frozen` once
and `apm install` once per checkout. The first apm 0.39 install also needs the network, to record
commit verdicts.
## Considered options
**Global pipx apm, as today (rejected).** It is the drift described above, and it cannot enforce a
minimum version.
**Upgrade the global apm (rejected).** It would fix this repo and break ansible, which still depends
on 0.28.0 behaviour, and it would leave the next repo with the same shared-binary problem.
**`uvx` (rejected).** It has no lock, so apm's transitive dependencies float between runs and the
pin only covers the top-level package.
**`uv tool install` (rejected).** It is machine-global state, the same drift as pipx under a
different name.
## Consequences
1. **A bare `apm` instruction fails closed.** Any leftover `apm` call in this repo that resolves to
the global 0.28.0 refuses the v4 lock instead of rewriting it. That is the intended failure, but it
will surprise whoever hits it; the fix is the `uv run` form.
2. **The network is needed on first sync.** A fresh checkout needs it for `uv sync --frozen` and again
for the first `apm install`. After both, the offline guarantee holds.
3. **uv becomes a prerequisite** of working in this repo. A consumer without uv falls back to `PATH`
apm and the version check.
4. **Re-verification is pending.** ADR-0019 and ADR-0033 state facts verified against apm 0.28.0.
They are re-checked on 0.39.3 under #265, and each carries a note saying so.
Related: ADR-0019, ADR-0024, ADR-0033; #245, #265; Defame1297/ansible-homelab-mono#1078;
Mortis/Kamino#499.
+43 -6
View File
@@ -1164,8 +1164,18 @@ Verified: a malformed dependency entry passes
`apm pack --check-versions --check-clean --dry-run` and fails `apm audit --ci` in that package's
directory. Costs ~0.5s per package.
**apm runs with git's repo-locating env scrubbed.** Both apm hooks source
`scripts/lib/clean-git-env.sh` before calling `apm`, which unsets `GIT_DIR`, `GIT_WORK_TREE`,
**Both apm hooks run the repo-pinned apm.** They source `scripts/lib/apm.sh`, the one place the
invocation is spelled: `uv run --project <repo root> --frozen apm` (ADR-0034). `--project` comes
from the helper's own location, so it names the repo root even when apm runs inside
`plugins/<name>/`. Each hook first checks the resolved apm's version and fails, naming
`uv sync --frozen` as the fix, below 0.39.2. The gates keep plain `--frozen`, without the
SessionStart hook's `--no-sync --offline`: once `uv sync --frozen` has run, the sync it implies is a
no-op that needs no network, and after a pull that moves the pin it brings `.venv/` to the new pin
instead of letting a gate certify the tree with a stale apm. `tests/test-apm-gate-invocation.sh`
pins the command, the `--project` root, the scrub and the version floor with a fake `uv`.
**apm runs with git's repo-locating env scrubbed.** Sourcing `scripts/lib/apm.sh` also sources
`scripts/lib/clean-git-env.sh` before anything calls `apm`, which unsets `GIT_DIR`, `GIT_WORK_TREE`,
`GIT_INDEX_FILE`, `GIT_OBJECT_DIRECTORY`, `GIT_COMMON_DIR`, `GIT_PREFIX` and
`GIT_IMPLICIT_WORK_TREE`. It deliberately keeps the config-passing vars (`GIT_CONFIG_PARAMETERS`,
`GIT_CONFIG_COUNT`), because they carry `git -c` overrides apm's remote clones may need. The reason: `git push` from a **linked worktree** exports an
@@ -1256,6 +1266,33 @@ among them, which is the state ADR-0026 rules out rather than a second scan wort
### `check-executables-allow-sync`
**Keys are full package identities (apm 0.39, #271).** apm 0.39.3 matches a grant on the package
identity `<host>/<owner>/<repo>/<path>`, as `apm approve --list` prints it, e.g.
`git.rkdr.net/Mortis/Holocron/plugins/kyberforge`. The bare `kyberforge#<version>` key that 0.28.0
matched no longer matches: the first 0.39 install parks the hooks, rewrites `.claude/settings.json`
without them, and root `apm audit --ci` still passes (spike #269, on #268). So the gate now derives
each expected key from root `apm.yml`'s own `git:` + `path:` dependency entry for the plugin (URL
without scheme, user or `.git`, then the path), appends `#<version>`, and fails a bare key with a
message saying why. A shipping plugin with no such entry fails, since no key can be derived, and so
does one whose `git:` URL names a port, because how apm writes a port into the identity is
unverified. Only an https URL on a lowercase host was checked against `apm approve --list`; the
scp-like and `ssh://` forms follow the same rule unchecked, and the host's case is kept as written. The
`#<version>` suffix is still stripped before apm matches, so the grant stays version-blind and the
version half stays a repo-level record. The grants are type-level (`hooks: true`), not
content-pinned: `apm approve` would pin content, strip the block's comments, and park the hook on
every script edit until someone approves again.
**It also fails on a parked executable in `apm.lock.yaml`** (spike #269, section 7.3). apm records
each dependency's executables decision as `exec_status:` in the lock, `deployed` or a `gated_*`
value such as `gated_pending_approval`. Root `apm audit --ci` passes with executables parked,
because `exec-status-current` only checks that the lock agrees with the gate. So the gate scans the
lock's `dependencies:` and fails on any `gated_*` entry, naming its identity and status, with
`apm approve --list` as the first step of the fix. It runs even when no plugin here ships
executables, since a third-party dependency can be parked too. A missing lock is left to
`apm-audit-ci`'s `lockfile-exists`. It is a line scan of the shape apm writes, not a YAML parse.
The rest of this section describes the 0.28.0 matching that the version-blind behaviour comes from.
apm gates a package's `hooks/` and `bin/` on root `apm.yml`'s `executables.allow`
(`apm_cli/security/executables.py`). `is_package_approved` is itself an exact dictionary lookup, but
it is never called with a single key: `install/exec_gate.py` builds a candidate list that includes
@@ -1276,10 +1313,10 @@ It covers every plugin that ships executables, not one named package. The script
`plugins/*/` and treats a plugin as shipping executables when `plugins/<name>/.apm/hooks/` or
`plugins/<name>/bin/` exists — kyberforge ships both, delivery ships a guard hook. For each one it
reads `name:` and `version:` from `plugins/<name>/apm.yml` and asserts root `apm.yml` carries the
`<name>#<version>` key under `executables.allow`. Keys use the package name, so a `name:` that
differs from the directory name fails rather than being guessed at. Every failing package is
reported in one run, each with its own Why/Fix block; a stale `<name>#<other-version>` key is quoted
back as "found instead". It also fails on a shipping plugin with no `apm.yml`, a missing `version:`,
`<identity>#<version>` key under `executables.allow`. The `name:` must equal the directory name, so
one that differs fails rather than being guessed at. Every failing package is
reported in one run, each with its own Why/Fix block; a stale `<identity>#<other-version>` key, or a
bare `<name>#...` key, is quoted back as "found instead". It also fails on a shipping plugin with no `apm.yml`, a missing `version:`,
a missing root `apm.yml`, or no `executables.allow` mapping. A repo with no executable-shipping
plugin at all is the one no-op, and a plugin with neither directory needs no key.
+1 -1
View File
@@ -19,7 +19,7 @@ Then:
apm install
```
The entry above is unpinned and tracks the remote's default branch — add `ref: <tag>` to pin a release. Registering the catalogue instead (`apm marketplace add https://git.rkdr.net/Mortis/Holocron.git --name holocron`) gets you the `bin@holocron` short name, but writes to `~/.apm/marketplaces.json` at user scope; the git+path object needs nothing beyond the manifest.
The entry above is unpinned and tracks the remote's default branch. To pin a release, add `ref: bin-v<x.y.z>` after `path:`; see [Pinning a plugin to a release](../../README.md#pinning-a-plugin-to-a-release). Registering the catalogue instead (`apm marketplace add https://git.rkdr.net/Mortis/Holocron.git --name holocron`) gets you the `bin@holocron` short name, but writes to `~/.apm/marketplaces.json` at user scope; the git+path object needs nothing beyond the manifest.
**Native plugin installs do not work.** This package ships no per-plugin manifest and no flat content directories, so a host that installs it natively gets zero skills — and Claude Code raises no error while doing it (ADR-0024).
+1 -1
View File
@@ -19,7 +19,7 @@ Then:
apm install
```
The entry above is unpinned and tracks the remote's default branch — add `ref: <tag>` to pin a release. Registering the catalogue instead (`apm marketplace add https://git.rkdr.net/Mortis/Holocron.git --name holocron`) gets you the `core@holocron` short name, but writes to `~/.apm/marketplaces.json` at user scope; the git+path object needs nothing beyond the manifest.
The entry above is unpinned and tracks the remote's default branch. To pin a release, add `ref: core-v<x.y.z>` after `path:`; see [Pinning a plugin to a release](../../README.md#pinning-a-plugin-to-a-release). Registering the catalogue instead (`apm marketplace add https://git.rkdr.net/Mortis/Holocron.git --name holocron`) gets you the `core@holocron` short name, but writes to `~/.apm/marketplaces.json` at user scope; the git+path object needs nothing beyond the manifest.
**Native plugin installs do not work.** This package ships no per-plugin manifest and no flat content directories, so a host that installs it natively gets zero skills — and Claude Code raises no error while doing it (ADR-0024).
+1 -1
View File
@@ -1,5 +1,5 @@
name: delivery
version: 0.8.0
version: 0.8.1
description: Agents and skills for taking a change from spec to a verified merge through tracker-gated stages.
author:
name: Mortis
+10 -6
View File
@@ -152,7 +152,7 @@ The script tells runtimes apart by where apm deployed it:
|---|---|---|
| `.claude/hooks/` | Claude Code | Output is `hookSpecificOutput.permissionDecision`. `onFailure: block` makes a crash or timeout block the call (Claude Code ≥ 2.1.295). Verified live on 2.1.326. |
| `.github/hooks/scripts/` | Copilot CLI | Output is top-level `permissionDecision` plus a reason. A non-zero exit denies, but a **timeout lets the call through**. The TUI auto-approves `ask` (ADR-0032 accepted risk). apm writes the entry in Claude's nested shape with `command`/`timeout`, and Copilot's docs accept both keys but don't document the nested group, so it is **unverified** until a Copilot account exists. |
| `.codex/hooks/` | Codex | `ask` is unsupported, so the guard denies with exit 2 and the reason on stderr. apm deploys only if `.codex/` already exists, and Codex skips project hooks until a human trusts them. Codex resolves the relative command from the session cwd, so a session started in a subdirectory may not find the script. |
| `.codex/hooks/` | Codex | `ask` is unsupported, so the guard denies with exit 2 and the reason on stderr. apm deploys it when the consuming project targets `codex`; with `codex` in `targets:`, apm 0.39.3 creates `.codex/` itself. Codex skips project hooks until a human trusts them. Codex resolves the relative command from the session cwd, so a session started in a subdirectory may not find the script. |
| anywhere else | unknown | Treated like Codex: odd jobs are denied, with exit 2. The payload's shape (`toolName` or `tool_name`) picks only how the payload is read, never the runtime. |
## What a consuming repo needs
@@ -160,18 +160,22 @@ The script tells runtimes apart by where apm deployed it:
- `python3` on PATH. The script uses the standard library only. Without python3 the hook cannot
start, which blocks every tool call on Claude Code and Copilot. That's deliberate.
- An `executables.allow` grant for the package in the repo's `apm.yml`, when that repo turns on apm's
executable-trust gate:
executable-trust gate. On apm 0.39 the key is the package's full identity, as
`apm approve --list` prints it:
```yaml
executables:
allow:
delivery:
git.rkdr.net/Mortis/Holocron/plugins/delivery:
hooks: true
```
apm 0.28.0 prints "parked pending approval" even when the grant matches (holocron#208). Check that
the hook actually deployed by looking for `guard.py` under `.claude/hooks/delivery/` and the
`PreToolUse` entry in `.claude/settings.json`. Don't rely on the install exit code.
A bare `delivery` key, which apm 0.28.0 matched, no longer does: under 0.39.3 the hook is parked
("parked pending approval"), nothing deploys, and install still exits 0. A `#<version>` suffix on
the key is ignored when matching. Check that the hook actually deployed by looking for `guard.py`
under `.claude/hooks/delivery/` and the `PreToolUse` entry in `.claude/settings.json`. Don't rely
on the install exit code. apm 0.28.0 also printed "parked pending approval" when the grant matched
(holocron#208); 0.39.3 does not.
- Host hardening is documented, not shipped (ADR-0032 layer 3). Examples are Claude permission
deny rules, sandbox `denyRead` on the vault password file, and managed settings with
`allowManagedHooksOnly` so the guard cannot be switched off.
+1 -1
View File
@@ -19,7 +19,7 @@ Then:
apm install
```
The entry above is unpinned and tracks the remote's default branch — add `ref: <tag>` to pin a release. Registering the catalogue instead (`apm marketplace add https://git.rkdr.net/Mortis/Holocron.git --name holocron`) gets you the `git@holocron` short name, but writes to `~/.apm/marketplaces.json` at user scope; the git+path object needs nothing beyond the manifest.
The entry above is unpinned and tracks the remote's default branch. To pin a release, add `ref: git-v<x.y.z>` after `path:`; see [Pinning a plugin to a release](../../README.md#pinning-a-plugin-to-a-release). Registering the catalogue instead (`apm marketplace add https://git.rkdr.net/Mortis/Holocron.git --name holocron`) gets you the `git@holocron` short name, but writes to `~/.apm/marketplaces.json` at user scope; the git+path object needs nothing beyond the manifest.
**Native plugin installs do not work.** This package ships no per-plugin manifest and no flat content directories, so a host that installs it natively gets zero skills and zero agents — and Claude Code raises no error while doing it (ADR-0024).
@@ -13,7 +13,7 @@ You are the orchestrator for apm package/marketplace operations. Your one job is
You resolve the package root once per dispatched operation (the directory containing that package's `apm.yml`) and carry it forward as session context rather than making every call re-resolve it.
**Scope:** this orchestrator routes `apm-workflow`'s five concerns only — configure/scaffold, marketplace, install, compile/pack/publish, audit. It does not route `apm-install` (binary install, agent-runtime setup) — that's a one-time machine bootstrap, not a per-package, fan-out-able operation, and has no orchestrator counterpart. Confirm `apm --version` succeeds before dispatching any operation; if it fails, tell the caller to run `apm-install` first rather than attempting recovery here.
**Scope:** this orchestrator routes `apm-workflow`'s five concerns only — configure/scaffold, marketplace, install, compile/pack/publish, audit. It does not route `apm-install` (binary install, agent-runtime setup) — that's a one-time machine bootstrap, not a per-package, fan-out-able operation, and has no orchestrator counterpart. Confirm the repo's apm reports a usable version before dispatching any operation: `uv run --project <repo root> --frozen apm --version` in a repo that pins apm with uv, `apm --version` otherwise (`apm-workflow` Step 2 says how to tell). Always pass `--project`: `uv run` outside the project silently falls back to the `PATH` apm. Exit 0 is not enough. The version must equal the repo's pin, or be 0.39.2 or later where nothing pins it, because an older apm refuses a v4 lockfile. If the check fails, tell the caller to run `apm-install` first rather than attempting recovery here.
## Hard rules
@@ -43,7 +43,7 @@ These are non-negotiable regardless of `confirm` or any skill-local override:
1. Validate the request structure and check if `operation` is known
2. Check the request against the Hard rules above (publish confirmation, marketplace-add direction, `type:` delegation, audit-vs-audit-ci, registries precondition) — refuse outright on violation, independent of `confirm`
3. If `operation` is `publish`: require `confirm: true`, dispatch `--dry-run -v` first regardless, surface that output, else fail with structured "requires explicit confirmation" error
4. Verify `apm --version` succeeds; if not, fail with a diagnostic pointing to `apm-install`
4. Verify the repo's apm version (pinned: `uv run --project <repo root> --frozen apm --version`, which must equal the pin; otherwise `apm --version`, which must be 0.39.2 or later); if not, fail with a diagnostic pointing to `apm-install`
5. Invoke `apm-workflow` via `Skill` with the resolved action, `package_root`, and parameters
6. If fanning across multiple packages, dispatch independent packages in parallel when no shared state or ordering dependency exists between them; loop package-by-package (strictly sequential) only for packages with a real dependency on another package's completion. Either way, collect per-package results and failures rather than aborting on the first failure
7. Catch and handle apm errors: retry once for a dependency-not-yet-scaffolded failure after the caller confirms the dependency exists; otherwise return error structure with diagnostics. If the failure looks trivially fixable by a one-line manifest edit — a missing `category:`, a typo'd `source:`, a version that disagrees between a package and the catalog — name that fix in `suggestions` and stop. Do not apply it yourself and do not self-dispatch an `edit-config` to apply it
@@ -24,26 +24,49 @@ project_dir="${CLAUDE_PROJECT_DIR:-$PWD}"
# No lockfile means nothing was installed through apm here — e.g. a host that
# installed this plugin natively. Say nothing and cost nothing.
[[ -f "$project_dir/apm.lock.yaml" ]] || exit 0
command -v apm > /dev/null 2>&1 || exit 0
# Every apm call below must see the same directory the guard just checked —
# `apm outdated` and `apm update` both resolve the lockfile from the cwd.
cd "$project_dir" || exit 0
# Every apm call below is bounded, and stock macOS ships no `timeout`; Homebrew
# coreutils installs it as `gtimeout`. Without either, nothing can be bounded,
# so the hook stays silent on every path rather than risk holding the session
# open — or misreporting an apm whose version it could not read. It is chosen
# before the apm, so no notice is printed either. The budget test in
# tests/test-apm-current-hook.sh sums every `"$to" N` and `timeout N` here.
if command -v timeout > /dev/null 2>&1; then
to=timeout
elif command -v gtimeout > /dev/null 2>&1; then
to=gtimeout
else
exit 0
fi
# `apm outdated` exits 0 whether or not anything is stale, so the answer has to
# come from its output. ~0.7s against six remote refs; a hung remote must not
# hold the session open.
# Choose the apm once, and use it for every call below (ADR-0034):
# 1. the repo's own pin, run as `uv run`, when the project pins apm-cli AND
# uv is on PATH;
# 2. otherwise the `apm` on PATH;
# 3. otherwise nothing: exit silently.
#
# There is no --json/machine-readable flag on `apm outdated` (verified against
# apm 0.28.0), so the phrase match is forced rather than chosen. Note the
# singular: apm prints "1 outdated dependency found" when exactly one package is
# behind, so matching only "dependencies" would silently miss a one-package
# drift. tests/test-apm-current-hook.sh pins both spellings against the real apm.
outdated_output="$(timeout 60 apm outdated 2>&1)" || exit 0
grep -qE 'outdated dependenc(y|ies) found' <<< "$outdated_output" || exit 0
stale_count="$(grep -oE '[0-9]+ outdated dependenc(y|ies) found' <<< "$outdated_output" | grep -oE '^[0-9]+' || true)"
[[ "$stale_count" =~ ^[0-9]+$ ]] || stale_count="some"
# "Pins apm-cli" means a pyproject.toml whose text carries a quoted apm-cli
# requirement (`"apm-cli==0.39.3"`, `'apm_cli>=0.39'`, ...) AND a uv.lock next
# to it. It is a text match, not a TOML parse: the hook must not depend on a
# Python being on PATH, and a quoted `apm-cli` requirement string has no other
# plausible meaning in a pyproject.toml. The uv.lock is required because
# `--frozen` runs from the lock and has nothing to run without one; a pin with
# no lock falls through to PATH apm and its version check.
#
# uv is only ever invoked as `uv run`, and with `--no-sync`: a plain `uv run`
# syncs the environment first, which installs packages and can reach the
# network, and a SessionStart hook must do neither. `--offline` closes the
# remaining gap (uv fetching a Python). Even `--no-sync` creates an empty
# .venv when none exists, so a project environment that is missing altogether
# (`$UV_PROJECT_ENVIRONMENT`, else <root>/.venv) gets a fixed "not synced"
# notice and uv is never called. One that exists but was never synced has no
# apm of its own, so `uv run` falls through to whatever apm is on PATH, and the
# version check below catches an old one and tells the reader to sync.
#
# apm_label names the chosen binary in advice text. It selects between fixed
# literals and is never built from command output. apm_cmd is never seeded
# empty: every branch below either sets it or exits, which keeps its expansions
# safe under `set -u` on bash 3.2 (tests/test-vale-wrap.sh scans for this).
# Only ever emit fixed text plus a digit-checked count — never interpolate
# command output into the JSON, which would need escaping this cannot do safely.
@@ -51,6 +74,83 @@ emit() {
printf '{"hookSpecificOutput":{"hookEventName":"SessionStart","reloadSkills":%s,"additionalContext":"%s"}}\n' "$1" "$2"
}
apm_label=""
if [[ -f "$project_dir/pyproject.toml" && -f "$project_dir/uv.lock" ]] \
&& grep -qiE "[\"']apm[-_.]cli[^a-z0-9_.-]" "$project_dir/pyproject.toml" 2> /dev/null \
&& command -v uv > /dev/null 2>&1; then
uv_env="${UV_PROJECT_ENVIRONMENT:-$project_dir/.venv}"
[[ "$uv_env" == /* ]] || uv_env="$project_dir/$uv_env"
if [[ ! -d "$uv_env" ]]; then
emit false "This project pins apm with uv but its environment has not been synced, so the apm install was not checked for staleness. Run: uv sync --frozen"
exit 0
fi
apm_cmd=(uv run --project "$project_dir" --frozen --no-sync --offline apm)
apm_label="uv"
elif command -v apm > /dev/null 2>&1; then
apm_cmd=(apm)
apm_label="path"
else
exit 0
fi
# Every apm call below must see the same directory the guard just checked —
# `apm outdated` and `apm update` both resolve the lockfile from the cwd.
cd "$project_dir" || exit 0
# apm older than 0.39.2 refuses a lockfile v4 and would then report it as up to
# date, so its `outdated` verdict is worthless (ADR-0034). Below the minimum, or
# when the version cannot be read at all, say so in a fixed line and skip the
# check: a silent pass here is exactly the false "up to date" to avoid. Only the
# first dotted triple is taken, and only its digits are compared.
#
# Returns 0 when new enough, 1 when the version was read and is too old, and 2
# when it could not be read (the call failed or timed out, or printed no
# version), so the notice can say which.
version_ok() {
local version_output version
version_output="$("$to" 15 "${apm_cmd[@]}" --version 2> /dev/null)" || return 2
version="$(grep -oE '[0-9]+\.[0-9]+\.[0-9]+' <<< "$version_output" | head -n 1)"
[[ "$version" =~ ^([0-9]+)\.([0-9]+)\.([0-9]+)$ ]] || return 2
local -a have=("${BASH_REMATCH[1]}" "${BASH_REMATCH[2]}" "${BASH_REMATCH[3]}") need=(0 39 2)
local i
for i in 0 1 2; do
((10#${have[i]} > need[i])) && return 0
((10#${have[i]} < need[i])) && return 1
done
return 0
}
version_ok
version_status=$?
if [[ $version_status -ne 0 ]]; then
if [[ "$apm_label" == "uv" && $version_status -eq 1 ]]; then
emit false "\`uv run apm\` is older than apm 0.39.2, so the apm install was not checked for staleness (older apm refuses lockfile v4 and would report it as up to date). The project environment is probably not synced to its pin. Run: uv sync --frozen"
elif [[ "$apm_label" == "uv" ]]; then
emit false "Could not read the version of \`uv run apm\` (it failed or timed out), so the apm install was not checked for staleness. Check that this works: uv run apm --version, or run: uv sync --frozen"
elif [[ $version_status -eq 1 ]]; then
emit false "\`apm\` on PATH is older than apm 0.39.2, so the apm install was not checked for staleness (older apm refuses lockfile v4 and would report it as up to date). Upgrade the apm on PATH to 0.39.2 or later, or pin apm-cli in this project with uv."
else
emit false "Could not read the version of \`apm\` on PATH (it failed or timed out), so the apm install was not checked for staleness. Check that this works: apm --version"
fi
exit 0
fi
# `apm outdated` exits 0 whether or not anything is stale, so the answer has to
# come from its output. Measured ~0.7s against six remote refs on apm 0.28.0
# from PATH, and ~3.6s through `uv run` on 0.39.3; a hung remote must not hold
# the session open.
#
# There is no --json/machine-readable flag on `apm outdated` (verified against
# apm 0.28.0 and 0.39.3), so the phrase match is forced rather than chosen. Note the
# singular: apm prints "1 outdated dependency found" when exactly one package is
# behind, so matching only "dependencies" would silently miss a one-package
# drift. tests/test-apm-current-hook.sh pins both spellings against the real apm.
outdated_output="$("$to" 60 "${apm_cmd[@]}" outdated 2>&1)" || exit 0
grep -qE 'outdated dependenc(y|ies) found' <<< "$outdated_output" || exit 0
stale_count="$(grep -oE '[0-9]+ outdated dependenc(y|ies) found' <<< "$outdated_output" | grep -oE '^[0-9]+' || true)"
[[ "$stale_count" =~ ^[0-9]+$ ]] || stale_count="some"
# What to do with the rewritten lock depends on the branch (ADR-0019): on the
# default branch it is a real update to commit or discard; on a feature branch it
# is churn unrelated to the branch and should be discarded. The branch name only
@@ -73,14 +173,21 @@ if [[ -n "$current_branch" && -n "$default_branch" ]]; then
if [[ "$current_branch" == "$default_branch" ]]; then
lock_advice="this is the default branch, so commit it or discard it deliberately."
else
lock_advice="this is a feature branch, so discard it: git checkout -- apm.lock.yaml && apm install"
if [[ "$apm_label" == "uv" ]]; then
lock_advice="this is a feature branch, so discard it: git checkout -- apm.lock.yaml && uv run apm install"
else
lock_advice="this is a feature branch, so discard it: git checkout -- apm.lock.yaml && apm install"
fi
fi
fi
if timeout 300 apm update --yes > /dev/null 2>&1; then
manual_update="apm update --yes"
[[ "$apm_label" == "uv" ]] && manual_update="uv run apm update --yes"
if "$to" 300 "${apm_cmd[@]}" update --yes > /dev/null 2>&1; then
emit true "apm install was ${stale_count} package(s) behind the remote default branch and has been refreshed automatically; skills and agents were redeployed and re-scanned. apm.lock.yaml has been rewritten and is now a modified file in the working tree - ${lock_advice}"
else
emit false "apm install is ${stale_count} package(s) behind the remote default branch and the automatic refresh failed. Deployed skills and agents may be stale. Run: apm update --yes"
emit false "apm install is ${stale_count} package(s) behind the remote default branch and the automatic refresh failed. Deployed skills and agents may be stale. Run: ${manual_update}"
fi
exit 0
+1 -1
View File
@@ -5,7 +5,7 @@
"hooks": [
{
"command": "${CLAUDE_PLUGIN_ROOT}/.apm/hooks/check-apm-current.sh",
"timeout": 380,
"timeout": 400,
"type": "command"
}
],
@@ -6,20 +6,33 @@ description: >
authoring, publishing, auditing, or dependency installation for an apm
package -> `apm-workflow`.
metadata:
version: "1.0.1"
version: "1.0.2"
category: apm
source_keys:
- context7-microsoft-apm
- apm-v0-39-3-docs
- apm-cli-0-39-3-uv-experiments
---
## Gotchas
- apm never executes an agent itself — it only installs and manages the runtimes that do. Installing apm alone leaves the user with a package manager and no working agent CLI, so Step 2 is required whenever the user actually wants one; skip it only when they explicitly want the package manager alone.
- apm never executes an agent itself — it only installs and manages the runtimes that do. Installing apm alone leaves the user with a package manager and no working agent CLI, so Step 3 is required whenever the user actually wants one; skip it only when they explicitly want the package manager alone.
- `apm runtime setup copilot` needs Node.js v22+ and npm v10+ already on `PATH`; apm will not install them for you.
- In a repo that pins apm with uv, the `PATH` apm is not the repo's apm and may refuse its lockfile. Never upgrade the global apm to fix one repo: other repos may depend on its version.
## Step 1 — Install the apm CLI
## Step 1 — Choose where apm comes from
If `apm --version` already answers and the user is not pinning or upgrading, skip to Step 2.
| Condition | Method | Where |
|---|---|---|
| The repo pins apm: `pyproject.toml` has a quoted `apm-cli` or `apm_cli` requirement, beside a `uv.lock` | Per-repo pin. Use or upgrade it, never the global apm | `references/uv-pin.md` |
| The user wants apm fixed per repo, and uv is available | Per-repo pin. Set it up | `references/uv-pin.md` |
| Anything else: a machine-wide apm, a CI image, no uv | Global install | Step 2 |
Unsure which row applies: read the worked example closing `references/uv-pin.md`.
## Step 2 — Install the global apm CLI
If `apm --version` already answers and the user is not pinning or upgrading, skip to Step 3.
Default:
@@ -29,16 +42,17 @@ curl -sSL https://aka.ms/apm-unix | sh
Escape hatches — combine as needed:
- **Pin a version** — append `@vX.Y.Z` to the piped script's arguments: `curl -sSL https://aka.ms/apm-unix | sh -s -- @v1.2.3`.
- **Pin a version** — append `@vX.Y.Z` to the piped script's arguments: `curl -sSL https://aka.ms/apm-unix | sh -s -- @v1.2.3`. Pick 0.39.2 or later for a repo whose `apm.lock.yaml` an apm 0.39.2 or later wrote; older versions refuse it.
- **Custom install directory** — set `APM_INSTALL_DIR` on the piped script's command: `curl -sSL https://aka.ms/apm-unix | APM_INSTALL_DIR=$HOME/.local/bin sh`.
- **Air-gapped mirror / GitHub Enterprise** — an air-gapped host cannot reach `aka.ms` at all, so get `install.sh` onto the box and run it from disk instead of piping. Point it at the mirror with `APM_RELEASE_BASE_URL` and pin `VERSION`: `APM_RELEASE_BASE_URL=https://mirror.corp/apm VERSION=v1.2.3 sh install.sh`; add `APM_RELEASE_METADATA_URL` instead if you leave `VERSION` unset. `GITHUB_URL` is the GitHub Enterprise host, not a release mirror. All four are ordinary environment variables that also work through the pipe — running from disk is a network constraint, not a script one.
- **pip** — `pip install apm-cli` requires Python 3.10+. Not on an externally-managed (PEP 668) Python such as Debian or Ubuntu, where it hard-fails with `error: externally-managed-environment`; use pipx below. The quick-install script has no Python prerequisite, so prefer it unless the environment is pip-first.
- **Air-gapped mirror / GitHub Enterprise** — an air-gapped host cannot reach `aka.ms` at all, so get `install.sh` onto the box and run it from disk instead of piping. Point it at the mirror with `APM_RELEASE_BASE_URL` and pin `VERSION`: `APM_RELEASE_BASE_URL=https://mirror.corp/apm VERSION=v1.2.3 sh install.sh`; add `APM_RELEASE_METADATA_URL` instead if you leave `VERSION` unset. `GITHUB_URL` is the GitHub Enterprise host, not a release mirror.
- **pip** — `pip install apm-cli` requires Python 3.11+ (since apm 0.36.0), and so does every other Python-based install. Not on an externally-managed (PEP 668) Python such as Debian or Ubuntu, where it hard-fails with `error: externally-managed-environment`; use pipx below. The quick-install script has no Python prerequisite, so prefer it unless the environment is pip-first.
- **pipx** — `pipx install apm-cli` on those PEP 668 environments. Same PyPI package, but pipx builds an isolated venv and exposes `apm` on `PATH`.
- **Package managers** — `brew install apm`, `winget install --id Microsoft.APM --exact --source winget` or `scoop install apm`. The apm docs give no way to pin a version through them.
- **Manual** — download the platform archive from the GitHub releases page, extract, and place the binary on `PATH`.
Verify with `apm --version`.
## Step 2 — Install or manage an agent runtime
## Step 3 — Install or manage an agent runtime
Default:
@@ -46,7 +60,7 @@ Default:
apm runtime setup copilot
```
Other targets: `apm runtime setup codex`, `apm runtime setup gemini`, `apm runtime setup llm`.
Other targets: `apm runtime setup codex`, `apm runtime setup gemini`, `apm runtime setup llm`. In a repo that pins apm, spell each of these as `uv run --project <repo root> --frozen apm runtime …`.
- `apm runtime list` — show installed runtimes.
- `apm runtime status` — show which runtime `apm run` will pick by default.
@@ -15,3 +15,27 @@
- **Research doc:** plugins/kyberforge/docs/research/docs/microsoft-apm/sources.md
- **Contributing files:** (none)
- **Status:** `referenced`
## apm-v0-39-3-docs
- **URL:** https://github.com/microsoft/apm/tree/v0.39.3/docs/src/content/docs
- **Description:** The apm docs source at tag v0.39.3: the installation page (install methods, the Python 3.11 floor, version pinning, the package-manager installs) and the lockfile compatibility pages (which apm reads which lock, the minimum-version advice, `apm audit --ci` refusing unknown lock fields).
- **Research doc:** plugins/kyberforge/docs/research/docs/microsoft-apm/sources.md (digest: plugins/kyberforge/docs/research/docs/microsoft-apm/installation.md)
- **Contributing files:** SKILL.md, references/uv-pin.md
- **Status:** `extracted`
## apm-cli-0-39-3-uv-experiments
- **URL:** https://pypi.org/project/apm-cli/0.39.3/
- **Description:** Throwaway uv 0.11.24 projects pinning apm-cli 0.39.3: the `[tool.uv] package = false` form, `uv run --frozen --offline` with a warm and a cold cache, and `uvx --offline` against a cache warmed by `uv add`. Grounds the per-repo pin, its offline behaviour and the rejection of uvx and `uv tool`.
- **Research doc:** plugins/kyberforge/docs/research/docs/microsoft-apm/sources.md (digest: plugins/kyberforge/docs/research/docs/microsoft-apm/installation.md)
- **Contributing files:** SKILL.md, references/uv-pin.md
- **Status:** `extracted`
## pypi-apm-cli
- **URL:** https://pypi.org/pypi/apm-cli/json
- **Description:** PyPI metadata for apm-cli: `requires_python >=3.11` and the runtime dependencies the uv lock pins.
- **Research doc:** plugins/kyberforge/docs/research/docs/microsoft-apm/sources.md (digest: plugins/kyberforge/docs/research/docs/microsoft-apm/installation.md)
- **Contributing files:** references/uv-pin.md
- **Status:** `extracted`
@@ -0,0 +1,99 @@
---
source_keys:
- apm-cli-0-39-3-uv-experiments
- apm-v0-39-3-docs
- pypi-apm-cli
---
# Pinning apm per repo with uv
Reached from `SKILL.md` Step 1. apm has no `apm.yml` field for a minimum apm version, and upstream
advises pinning apm outside the manifest. A uv pin gives every checkout of the repo the same apm
and the same transitive dependencies, whatever is installed globally. apm's docs do not describe
this method. It was tested with uv 0.11.24 and apm-cli 0.39.3.
## Set up the pin
1. Add this `pyproject.toml` at the repo root:
```toml
[project]
name = "<repo>-tooling"
version = "0.0.0"
requires-python = ">=3.11"
dependencies = []
[tool.uv]
package = false
[dependency-groups]
dev = ["apm-cli==0.39.3"]
```
- There is no `[build-system]`, and `package = false` keeps uv from ever building the project,
so uv installs only the `dev` group. `uv sync` installs that group by default.
- `>=3.11` is apm-cli's own floor.
- Pin with `==`. Choose 0.39.2 or later. Older versions refuse a lockfile that 0.39.2 or later
rewrote.
- If the repo already has a `pyproject.toml` for a real Python project, add `apm-cli==<version>`
to a dependency group there. Do not add `package = false` to a project that builds.
2. Run `uv lock`. Commit `pyproject.toml` and `uv.lock`, and gitignore `.venv/`. The lock hashes
apm-cli and every transitive dependency.
3. On each checkout, run `uv sync --frozen` once. The first sync on a machine needs the network,
because a cold uv cache cannot download wheels offline.
4. Run `uv run --project . --frozen apm install` from the repo root. The first install with apm 0.39 or later also needs the
network once, to record commit verdicts.
5. Check the version with `uv run --project . --frozen apm --version`.
## Run it
- Spell every apm command in the repo as `uv run --project <repo root> --frozen apm <args>`. `--frozen` runs from
`uv.lock` as committed and never re-resolves it. It still syncs the environment to the lock
first. After the one-time sync that costs nothing, and when a pull moves the pin it brings the
environment up to the new version.
- Scripts always pass `--project <repo root>`. Without it, `uv run` from a directory outside the repo finds no project and silently runs the `PATH` apm. The same happens under a nested `pyproject.toml`.
- Offline, `uv run --project <repo root> --frozen --offline apm …` works once the uv cache is warm, even with no
`.venv`. With a cold cache it fails.
- A hook with a short timeout must never sync. kyberforge's SessionStart hook runs
`uv run --project <root> --frozen --no-sync --offline apm`, after checking that
`${UV_PROJECT_ENVIRONMENT:-<root>/.venv}` exists, because even `--no-sync` creates an empty one.
## Upgrade the pin
Change the `==` version, then run `uv lock` and `uv sync --frozen`, and commit both files. Then
follow apm's own upgrade notes for the versions crossed. Every machine and CI job that runs
`apm install` or `apm audit --ci` on the repo's lockfile needs an apm at least as new as the one
that last wrote it. `apm audit --ci` fails on lockfile fields it does not know.
## Why not uvx or `uv tool`
- **`uvx apm-cli@<version>`** pins only apm-cli. Its transitive dependencies float between runs and
nothing is locked. A cache warmed by `uv add` also did not satisfy `uvx --offline`.
- **`uv tool install apm-cli`** is machine-global, the same drift as a global pipx install under
another name.
uv installs the apm tool and nothing else. Packages, skills and agents still come from
`apm install`.
## Worked example: one pinned repo, one unpinned
**Repo A pins apm.** The user asks to install the repo's apm dependencies. The root
`pyproject.toml` has `dev = ["apm-cli==0.39.3"]`, and `uv.lock` sits beside it.
1. Detect the pin: a quoted `apm-cli` or `apm_cli` requirement in `pyproject.toml`, and a `uv.lock` beside it:
`grep -Eq "[\"']apm[-_]cli" pyproject.toml && test -f uv.lock`.
2. Run `uv sync --frozen`, the first time on this checkout.
3. Run `uv run --project . --frozen apm --version`. It prints 0.39.3.
4. Run `uv run --project . --frozen apm install`.
Wrong moves: a bare `apm install`, because the `PATH` apm may be 0.28.0, which refuses the v4 lock.
`pipx upgrade apm-cli`, because that changes every repo on the machine. `uvx apm-cli@0.39.3
install`, because its dependencies are unlocked.
**Repo B does not pin apm.** It has no `pyproject.toml` naming `apm-cli`, or no `uv.lock`.
1. Run `apm --version`. If nothing answers, install apm globally (`SKILL.md` Step 2).
2. If apm is older than the repo's lock needs (0.39.2 or later for a lock 0.39.2 or later wrote),
upgrade the global apm, or propose a per-repo pin. Do not add the pin unasked: it is a repo
change the user should approve.
3. Run `apm install`.
@@ -5,16 +5,18 @@ description: >
the dependencies it declares, or an apm marketplace — even when the user does
not say "apm". Not the apm binary or an agent runtime -> `apm-install`.
metadata:
version: "1.0.3"
version: "1.0.4"
category: apm
source_keys:
- context7-microsoft-apm
- apm-cli-0-39-3-uv-experiments
---
## Gotchas
- MCP server secrets in `apm.yml` (headers, env vars) must use `${VAR}` indirection, never literal values, so they resolve at install or runtime and are never committed.
- `apm experimental enable registries` must run before a `registries:` block or `registry.*` config takes effect anywhere — configure, install or publish. Without it, declaring one silently does nothing: no error, no warning.
- `uv run` outside the uv project silently runs the `PATH` apm instead: from outside the repo it reported 0.28.0 where the repo pinned 0.39.3. Hence `--project` in Step 2.
- `apm.yml`'s `type:` selects which primitives are processed and is never checked against what `.apm/` holds, so `apm install` and `apm compile` can exit 0 having shipped none of the ones you expected. Set it to cover every primitive the package ships, and confirm the deployed output, not the exit code. Mechanics: `references/configure.md`.
## Step 1 — Dispatch
@@ -29,6 +31,15 @@ metadata:
Read the reference file matching the resolved flow — it carries that flow's own traps, and names a sibling file wherever one flow genuinely depends on another's detail.
## Step 2 — Execute
## Step 2 — Choose the apm command
Follow the matched reference file's instructions. Report back which `apm` command(s) were run (or drafted, if the user asked for a plan rather than execution) and their outcome.
The references spell every command as bare `apm`. Before running one, check whether the repo pins apm: a `pyproject.toml` at the repo root carrying a quoted `apm-cli` or `apm_cli` requirement, with a `uv.lock` beside it.
- **Pinned:** run each command as `uv run --project <repo root> --frozen apm <args>`. Run `uv sync --frozen` once per checkout first; the first sync needs the network. A bare `apm` there runs whatever is on `PATH`, which may be older than the repo's pin and refuse its lockfile.
- **Not pinned:** use the `apm` on `PATH`. If it is missing, or refuses the repo's lockfile as too new, hand off to `apm-install`.
Installing apm, or adding or moving the pin, belongs to `apm-install`.
## Step 3 — Execute
Follow the matched reference file's instructions. Report back which `apm` command(s) were run (or drafted, if the user asked for a plan rather than execution), spelled as invoked, and their outcome.
@@ -4,6 +4,9 @@ source_keys:
- context7-microsoft-apm
- context7-websites-code-claude
- claude-code-plugins-docs
- apm-v0-39-3-source
- apm-v0-39-3-docs
- apm-cli-0-39-3-uv-experiments
---
## `apm audit`
@@ -14,7 +17,7 @@ apm audit --ci # CI gate: lockfile consistency + drift replay + pol
apm audit --file <path> # standalone: scan an arbitrary file
```
Exit code `0` on success, `1` on any violation — composes as a normal CI gate step. It does not replace general lint/test/security-scan CI steps, it sits alongside them.
`apm audit --ci` exits `0` when every check passes and `1` when any fails, so it composes as a normal CI gate step. Plain `apm audit` exits `0` when clean, `1` on a critical finding and `2` on warnings only. It does not replace general lint/test/security-scan CI steps, it sits alongside them.
## Policy checks
@@ -46,6 +49,10 @@ jobs:
`-f sarif --output <file>` emits SARIF for GitHub Code Scanning's inline PR annotations.
In a repo that pins apm with uv, replace the `pip install` step with `uv sync --frozen` and run each apm step as `uv run --project . --frozen apm …` from the checkout root, so CI runs the repo's own apm.
The apm that runs `apm audit --ci` must be at least as new as the newest apm that wrote `apm.lock.yaml`: it fails on lockfile fields it does not know, where plain `apm audit` only warns.
## Frozen installs
`apm install --frozen` fails instead of silently re-resolving if the lockfile is out of date — the CI equivalent of `npm ci` vs `npm install`. Use in any CI job that must not be allowed to drift the lockfile.
@@ -2,6 +2,7 @@
topic: compile
source_keys:
- context7-microsoft-apm
- apm-cli-0-39-3-experiments
---
## Compile
@@ -12,7 +13,7 @@ apm compile --clean # zero-write sanity check; use for skill/agent-o
apm compile --clean --dry-run # pure preview, no writes
```
Compiles `.apm/instructions/` + `.apm/agents/*.agent.md` primitives into consumer-side context files (AGENTS.md/CLAUDE.md CONTEXT files) for the deployment target, per the `compilation:` block in `apm.yml`. This is the consumer/deployment side — it is NOT the producer of `plugin.json`/`marketplace.json`; that's `apm pack`'s job (below). Run `apm compile` after any change to `.apm/instructions/`/`.apm/agents/` content or to `compilation:`/`targets:` in `apm.yml`. To author an instructions file, use `instructions-author` — it covers which fields each target drops. `apm compile` never reads `.apm/prompts/`; to author a prompt file, use `prompt-author` — verification there is a throwaway `apm install`.
Compiles `.apm/instructions/` + `.apm/agents/*.agent.md` primitives into consumer-side context files (AGENTS.md/CLAUDE.md CONTEXT files) for the deployment target, per the `compilation:` block in `apm.yml`. For the `claude` target, apm 0.38 and later write the instructions into `AGENTS.md` and a `CLAUDE.md` that only imports it (`@AGENTS.md`). This is the consumer/deployment side — it is NOT the producer of `plugin.json`/`marketplace.json`; that's `apm pack`'s job (below). Run `apm compile` after any change to `.apm/instructions/`/`.apm/agents/` content or to `compilation:`/`targets:` in `apm.yml`. To author an instructions file, use `instructions-author` — it covers which fields each target drops. `apm compile` never reads `.apm/prompts/`; to author a prompt file, use `prompt-author` — verification there is a throwaway `apm install`.
## Pack
@@ -63,5 +64,5 @@ Executes a named script defined under `scripts:` in `apm.yml`, with `--param` su
## Gotchas
- Plain `apm compile` HARD-FAILS with exit 1 and `No instruction files found in .apm/ directory` on any package that has skills/agents but no `.apm/instructions/` content — the common case for a skill-only or skill+agent package. Use `apm compile --clean` as the zero-write sanity-check substitute: it sets `allow_empty=True` internally and exits 0 cleanly with zero writes; add `--dry-run` for a pure preview. `compile` ≠ `pack` — see above.
- Plain `apm compile` HARD-FAILS with exit 1 and `No instruction files found in .apm/ directory` (re-run on apm 0.39.3) on any package that has skills/agents but no `.apm/instructions/` content — the common case for a skill-only or skill+agent package. Use `apm compile --clean` as the zero-write sanity-check substitute: it sets `allow_empty=True` internally and exits 0 cleanly with zero writes; add `--dry-run` for a pure preview. `compile` ≠ `pack` — see above.
- `claude plugin validate --strict` auto-scans every `.md` file directly under a compiled plugin's `agents/` directory and treats it as an agent definition requiring frontmatter, independent of any manifest declaration (an empirically observed Claude Code platform behavior, not an `apm` mechanic). A non-agent `.md` file (notes, provenance record, README) that ends up under `.apm/agents/` in the source tree will still fail validation once compiled to the `claude` target. Keep such files outside `.apm/agents/` (e.g. at the package root), regardless of what `apm.yml` declares.
@@ -2,6 +2,7 @@
topic: configure
source_keys:
- context7-microsoft-apm
- apm-v0-39-3-source
---
## Scaffolding a new package
@@ -90,6 +91,6 @@ apm config set registry.corp-main.default true
## Gotchas
- `apm.yml`'s `type:` field validates nothing about `.apm/`. It selects processing: `instructions` compiles to AGENTS.md only, `skill` installs a native skill only, `prompts` emits commands only, `hybrid` does both (see `apm_cli/models/validation.py`, `PackageContentType`). apm checks only that the value parses to one of those four strings; no check anywhere compares it against the primitives actually on disk, and no mismatch diagnostic exists. A package declaring `type: instructions` while shipping `.apm/skills/` therefore raises no error — the mismatch resolves silently, either by omitting that primitive from the install/compile output or, in apm 0.28.0 where `get_effective_type()` routes off the on-disk layout and never reads the declared field, by ignoring the declared value outright. Both directions are silent: `apm install` and `apm compile` can exit 0 having shipped none of the primitives you expected. Set `type:` to cover every primitive the package ships, and confirm the deployed output rather than the exit code.
- `apm.yml`'s `type:` field validates nothing about `.apm/`. It selects processing: `instructions` compiles to AGENTS.md only, `skill` installs a native skill only, `prompts` emits commands only, `hybrid` does both (see `apm_cli/models/validation.py`, `PackageContentType`). apm checks only that the value parses to one of those four strings; no check anywhere compares it against the primitives actually on disk, and no mismatch diagnostic exists. A package declaring `type: instructions` while shipping `.apm/skills/` therefore raises no error — the mismatch resolves silently, either by omitting that primitive from the install/compile output or, in apm 0.28.0 and still in 0.39.3, where `get_effective_type()` routes off the detected package layout and never reads the declared field, by ignoring the declared value outright. Both directions are silent: `apm install` and `apm compile` can exit 0 having shipped none of the primitives you expected. Set `type:` to cover every primitive the package ships, and confirm the deployed output rather than the exit code.
- `apm experimental enable registries` must run before any `registry.*` config takes effect. Declaring a `registries:` block or running `apm config set registry.*` without it silently does nothing — no error, no warning.
- `apm plugin init <name>` run with a positional name argument, from inside a directory already named `<name>`, creates a wrongly-nested `<name>/<name>/` subdirectory — it treats the positional arg as "create a new project directory named X," not "confirm the current directory is X." Fix: omit the positional argument entirely when already cd'd into the target package directory — run `apm plugin init --yes --target claude,copilot` instead.
@@ -5,6 +5,7 @@ source_keys:
- context7-websites-code-claude
- claude-code-plugins-docs
- apm-github-repo
- apm-v0-39-3-source
---
## Building a marketplace from a producer repo
@@ -114,6 +115,6 @@ hook.
## Gotchas
- `apm marketplace add` and `apm marketplace package add` point in opposite directions and are easy to conflate: `add` registers someone else's catalog for you to *consume*; `package add` registers a package by remote reference (`owner/repo`, host URL, or full URL) into a marketplace you are *building*. `package add` does not accept a local path — register a local package by hand-editing `marketplace.packages[]`, as above.
- Only `claude` and `codex` marketplace output profiles exist in apm 0.28.0 — confirmed via source (`apm_cli/marketplace/output_profiles.py`: `MARKETPLACE_OUTPUTS = {claude: ..., codex: ...}`, nothing else). There is no native Copilot marketplace output; `apm pack` will not generate one. A repo needing a Copilot-consumable marketplace manifest must maintain it separately by other means.
- The marketplace output profiles depend on the apm version. apm 0.39.3 has three, `claude` (`.claude-plugin/marketplace.json`), `codex` (`.agents/plugins/marketplace.json`) and `copilot` (`.github/plugin/marketplace.json`), confirmed in `apm_cli/marketplace/output_profiles.py`. apm 0.28.0 had only `claude` and `codex`, so an older apm cannot emit a Copilot marketplace manifest. Add the output under `marketplace.outputs` only once every apm that packs the repo has it.
- A package/plugin `name` compiling to the `claude` target must avoid Claude Code's reserved name prefixes/values — `anthropic-*`, `claude-*`, `agent-skills`, `official-claude-plugins` — otherwise the compiled `.claude-plugin/marketplace.json` is rejected by Claude Code's validator. This is a Claude Code platform constraint, independent of how the manifest gets authored.
- Removing a package from `marketplace.packages[]` in `apm.yml` and re-packing changes the public/consumed catalog. Confirm with the user in conversation before removing the entry and running `apm pack` — this is a normal `apm.yml` edit (not a distinct apm-orchestrate operation with its own gate), so the confirmation is conversational, the same as any other consequential manifest edit.
@@ -11,7 +11,7 @@
## apm-github-repo
- **URL:** https://github.com/microsoft/apm
- **Description:** APM's own Python source (`src/apm_cli/`), read directly for schema and compile-mapping ground truth where Context7's doc snippets were thin. Backs the marketplace output-profile claim (`apm_cli/marketplace/output_profiles.py` — only `claude` and `codex` profiles exist, so there is no native Copilot marketplace output) and the `apm pack --check-clean`/`--check-versions` semantics.
- **Description:** APM's own Python source (`src/apm_cli/`), read directly for schema and compile-mapping ground truth where Context7's doc snippets were thin. Backs the `apm pack --check-clean`/`--check-versions` semantics, and the 0.28.0 marketplace output profiles (`claude` and `codex` only).
- **Research doc:** plugins/kyberforge/docs/research/docs/microsoft-apm/sources.md
- **Contributing files:** references/marketplace.md
- **Status:** `extracted`
@@ -39,3 +39,35 @@
- **Research doc:** plugins/kyberforge/docs/research/docs/claude-code-plugins/sources.md
- **Contributing files:** (none)
- **Status:** `referenced`
## apm-v0-39-3-source
- **URL:** https://github.com/microsoft/apm/tree/v0.39.3/src/apm_cli
- **Description:** apm source at tag v0.39.3, read from the pinned install: the three marketplace output profiles in `marketplace/output_profiles.py`, `get_effective_type()` in `integration/skill_package_routing.py` still routing off the detected package layout, and the `apm audit` exit codes.
- **Research doc:** plugins/kyberforge/docs/research/docs/microsoft-apm/sources.md (digest: plugins/kyberforge/docs/research/docs/microsoft-apm/cli-reference.md)
- **Contributing files:** references/marketplace.md, references/configure.md, references/audit.md
- **Status:** `extracted`
## apm-v0-39-3-docs
- **URL:** https://github.com/microsoft/apm/tree/v0.39.3/docs/src/content/docs
- **Description:** apm docs at tag v0.39.3: `apm audit --ci` refusing lockfile fields it does not know, so the auditing apm must be at least as new as the lock's writer.
- **Research doc:** plugins/kyberforge/docs/research/docs/microsoft-apm/sources.md (digest: plugins/kyberforge/docs/research/docs/microsoft-apm/lockfile-and-compatibility.md)
- **Contributing files:** references/audit.md
- **Status:** `extracted`
## apm-cli-0-39-3-uv-experiments
- **URL:** https://pypi.org/project/apm-cli/0.39.3/
- **Description:** Throwaway uv projects pinning apm-cli 0.39.3. Grounds the pinned invocation `uv run --project <repo root> --frozen apm` in `SKILL.md` Step 2 and in the CI note, and the need for one online `uv sync --frozen` per machine.
- **Research doc:** plugins/kyberforge/docs/research/docs/microsoft-apm/sources.md (digest: plugins/kyberforge/docs/research/docs/microsoft-apm/installation.md)
- **Contributing files:** SKILL.md, references/audit.md
- **Status:** `extracted`
## apm-cli-0-39-3-experiments
- **URL:** https://pypi.org/project/apm-cli/0.39.3/
- **Description:** The repo-pinned apm-cli 0.39.3 run in throwaway packages outside the repo (holocron#273): the Claude compile writing a `CLAUDE.md` that imports `AGENTS.md`, and a skills-only package's plain compile still exiting 1 while `--clean` exits 0.
- **Research doc:** plugins/kyberforge/docs/research/docs/microsoft-apm/sources.md (digest: plugins/kyberforge/docs/research/docs/microsoft-apm/instructions-gotchas.md)
- **Contributing files:** references/compile.md
- **Status:** `extracted`
@@ -6,7 +6,7 @@ description: >
skill -> `skill-author`. Not a named agent -> `agent-author`. Not a named
plugin -> `apm-workflow`.
metadata:
version: "1.0.5"
version: "1.0.6"
category: factory
source_keys:
- claude-code-subagents-docs
@@ -4,7 +4,7 @@ source_keys:
- context7-websites-code-claude
- claude-code-memory-docs
- apm-docs-author-prompts
- apm-cli-0-28-0-prompt-experiments
- apm-cli-0-39-3-experiments
- claude-code-slash-commands
---
@@ -37,7 +37,7 @@ place only where its single-file, multi-target shape is the point.
| The content is | Route |
|---|---|
| A single-file command that should also reach Copilot, Cursor, Gemini or OpenCode | Prompt file (`prompt-author`) |
| A single-file command that should also reach Copilot, Cursor, Gemini or OpenCode (Kiro gets the body only) | Prompt file (`prompt-author`) |
| A command that needs `references/` or `scripts/`, or that other skills or the model must be able to call | Skill (`skill-author`), declared hand-invoked |
| A Claude-only command with no such need | Skill (`skill-author`), because the vendor steers new commands there |
@@ -32,11 +32,11 @@
- **Contributing files:** references/author-routes.md
- **Status:** `extracted`
## apm-cli-0-28-0-prompt-experiments
## apm-cli-0-39-3-experiments
- **URL:** https://pypi.org/project/apm-cli/0.28.0/
- **Research doc:** plugins/kyberforge/docs/research/docs/microsoft-apm/sources.md (digest: plugins/kyberforge/docs/research/docs/microsoft-apm/prompt-target-mapping.md)
- **Description:** The installed apm-cli 0.28.0 exercised in throwaway packages. Grounds the same table: which targets receive a prompt file.
- **URL:** https://pypi.org/project/apm-cli/0.39.3/
- **Research doc:** plugins/kyberforge/docs/research/docs/microsoft-apm/sources.md (digest: plugins/kyberforge/docs/research/docs/microsoft-apm/prompt-gotchas.md)
- **Description:** The repo-pinned apm-cli 0.39.3 run in throwaway packages (holocron#273), re-running the 0.28.0 prompt experiments. Grounds the same table: Copilot, Cursor, Gemini and OpenCode each receive a prompt file as a command. Kiro now receives the body only, and Codex and Antigravity still receive nothing.
- **Contributing files:** references/author-routes.md
- **Status:** `extracted`
@@ -5,21 +5,23 @@ description: >
(`.apm/instructions/*.instructions.md`). Not read-only review ->
`factory-audit`. Not skills -> `skill-author`. Not agents -> `agent-author`.
Not AGENTS.md -> `agentsmd-author`.
compatibility: Requires the apm CLI; behaviour verified against apm 0.28.0.
compatibility: Requires the apm CLI, 0.39.2 or later; behaviour verified against apm 0.39.3.
allowed-tools: Bash Read Write Edit
metadata:
version: "0.1.0"
version: "0.1.1"
category: factory
source_keys:
- apm-docs-site
- apm-cli-0-28-0-experiments
- apm-cli-0-39-3-experiments
- apm-v0-39-3-source
- claude-code-memory-docs
---
## Gotchas
- Claude Code drops `description`; only Copilot, grok-build and Cursor keep it. Write a body that explains itself.
- Quote every `applyTo`. An unquoted `**/*.py` fails to parse, compile skips the file, and `apm install` still deploys it with no `paths:`, so it loads in every session. Install prints the parse warning once and exits 0.
- Quote every `applyTo`. An unquoted `**/*.py` is a YAML alias error: `apm install` exits 1 and deploys nothing, while `apm compile` drops the file and still exits 0.
- On Claude a rule leaves `.claude/rules/` only once a compile has actually written it into `AGENTS.md`, which `CLAUDE.md` imports. Install-then-compile dedups it, so it stays. Where a rule loads from is in `references/target-mapping.md`.
## Step 1 — Dispatch
@@ -40,7 +42,7 @@ Gates on every file, whichever flow wrote it:
- **One topic per file.** Two topics are two files.
- **Scope.** Omit `applyTo` only for a rule that must load in every session, and tell the user it then costs context at every launch.
- **Source.** Flat in `.apm/instructions/`, named `<stem>.instructions.md`. Anything nested or misnamed is ignored or never installed.
- **Stem.** It becomes the deployed filename, and install overwrites a hand-authored rule of the same name on most targets without a prompt. Check for a collision before choosing it.
- **Stem.** It becomes the deployed filename. Install skips a hand-authored file at that path and deploys nothing there, and `--force` overwrites it. Check for a collision before choosing it.
- **Body.** Concrete, checkable bullets, paths in backticks, nothing assuming another file is loaded, under 200 lines. If unsure the content is a rule rather than a procedure or something to enforce, read `references/content.md`.
If a field, glob or location is in question, read `references/schema.md`. If the question is which target keeps which field, or what compile does, read `references/target-mapping.md`.
@@ -2,8 +2,8 @@
# Delete these comments once filled in; Copilot receives this file verbatim.
description: "FILL IN: one line on what this rule covers. Only Copilot, grok-build and Cursor keep it."
applyTo: "FILL IN: quoted glob, e.g. **/*.py"
# applyTo is always quoted: an unquoted ** is a YAML alias error and the rule
# deploys unscoped. Several globs: "**/*.css,**/*.scss". Delete the line only
# applyTo is always quoted: an unquoted ** is a YAML alias error and apm
# install fails. Several globs: "**/*.css,**/*.scss". Delete the line only
# for a rule that must load in every session.
---
# FILL IN: one topic per file
@@ -1,7 +1,7 @@
---
source_keys:
- apm-docs-site
- apm-cli-0-28-0-experiments
- apm-cli-0-39-3-experiments
---
# Creating a new instructions file
@@ -18,7 +18,7 @@ Confirm, and ask the user for anything missing:
## Step 1 — Check the stem
Install overwrites a hand-authored file at `.claude/rules/<stem>.md`, `.cursor/rules/<stem>.mdc`, `.windsurf/rules/<stem>.md`, `.kiro/steering/<stem>.md` and `.agents/rules/<stem>.md` without a prompt. List those paths in the consuming project and choose another stem on any hit.
Install skips a hand-authored file at a deployed path, such as `.claude/rules/<stem>.md` or `.github/instructions/<stem>.instructions.md`, so the new rule never deploys there; `--force` would overwrite the hand-authored one. For each target in `targets:`, list its path from `references/target-mapping.md` in the consuming project and choose another stem on any hit.
## Step 2 — Scaffold
@@ -1,7 +1,7 @@
---
source_keys:
- apm-docs-site
- apm-cli-0-28-0-experiments
- apm-cli-0-39-3-experiments
---
# Improving an existing instructions file
@@ -16,13 +16,16 @@ Read the file whole. Signals are grill output, audit findings, inline feedback,
| Symptom | Cause | Fix |
|---|---|---|
| A scoped rule loads in every Claude session | `applyTo` is unquoted or malformed, so install deployed no `paths:` | Quote it, then confirm with `references/verify.md` |
| Compile warns "Failed to parse" | Broken frontmatter YAML | Repair the YAML; do not delete the field |
| The rule is in `CLAUDE.md` but not `.claude/rules/` | The file is nested under `.apm/instructions/` | Move it up to the flat directory |
| Install exits 1 with "Rejected frontmatter", or compile warns "Failed to parse" | Broken frontmatter YAML, most often an unquoted `applyTo` | Repair or quote it; do not delete the field |
| A rule meant to be scoped loads in every Claude session | `applyTo` is missing, or apm 0.28.0 installed it unquoted with no `paths:` | Add or quote it, then confirm with `references/verify.md` |
| The rule is in `AGENTS.md` but not `.claude/rules/`, and it is scoped to file types | The file is nested under `.apm/instructions/` | Move it up to the flat directory |
| An unscoped rule left `.claude/rules/` | apm moved it into `AGENTS.md`, which `CLAUDE.md` imports | Expected; confirm `CLAUDE.md` holds `@AGENTS.md` |
| Compile warns "applyTo ... matched no files" | The glob matches nothing in this project | Fix the glob, or confirm the files do not exist yet |
| The rule appears nowhere | The name lacks `.instructions.md` | Rename it |
| Claude ignores guidance written in `description` | Claude Code drops `description` | Move the substance into the body |
| A hand-written rule vanished after install | The stem collided with a deployed name | Restore it from version control and rename the source stem |
| The same rule reaches the agent twice | Cursor, Windsurf, Kiro and Grok get both a native file and an `AGENTS.md` copy | State it to the user; it is apm behaviour, not a defect in the file |
| The rule did not deploy and install printed "files skipped -- local files exist" | The stem collides with a hand-written file at the deployed path | Rename the source stem. `--force` would overwrite the hand-written file |
| A hand-written rule vanished after install | `--force`, or apm 0.28.0, overwrote it | Restore it from version control and rename the source stem |
| The same rule reaches the agent twice | When compile also writes `AGENTS.md` for a target with no dedup, Cursor, Windsurf, Kiro and Grok get both a native file and an `AGENTS.md` copy | State it to the user; it is apm behaviour, not a defect in the file |
Cases not in the table: read `references/target-mapping.md`.
@@ -2,20 +2,20 @@
source_keys:
- apm-docs-site
- apm-github-repo
- apm-cli-0-28-0-experiments
- apm-cli-0-39-3-experiments
- claude-code-memory-docs
---
# The instructions source file
Verified against apm 0.28.0. Reached from `SKILL.md` Step 2 when a frontmatter field, a glob or the file's location is in question.
Verified against apm 0.39.3. Reached from `SKILL.md` Step 2 when a frontmatter field, a glob or the file's location is in question.
## Location and name
`.apm/instructions/<name>.instructions.md`, flat. The double extension is the discovery key and the stem is the primitive's name; there is no `name` field.
- A plain `.md` in that directory is ignored by both `apm compile` and `apm install`.
- A file in a subdirectory is folded into compiled root files by compile but never deployed by install, so it reaches `CLAUDE.md` and `AGENTS.md` and no native rules directory.
- A file in a subdirectory is folded into compiled root files by compile but never deployed by install, so it reaches `AGENTS.md` and no native rules directory.
- The stem becomes the deployed filename: `<stem>.md`, `<stem>.mdc`, or `<stem>.instructions.md`, by target.
## Frontmatter
@@ -32,7 +32,7 @@ Only `description` and `applyTo` carry meaning. `author` and `version` are parse
- A YAML sequence is joined into the same comma form.
- Brace alternation is never split: `"**/*.{css,scss},**/*.py"` is two patterns.
- A literal comma in a pattern is `\,`; a literal backslash is `\\`.
- Always quote the value. An unquoted `**/*.py` is a YAML alias error; see `SKILL.md` Gotchas for what apm then does.
- Always quote the value. An unquoted `**/*.py` is a YAML alias error, and install then fails; see `SKILL.md` Gotchas.
## Body
@@ -43,8 +43,8 @@ Plain markdown. Official guidance: bullets over prose, one topic per file (`pyth
`Instruction.validate()` yields three findings, all demoted to warnings: missing `description`, missing `applyTo` ("will apply globally") and empty content. A broken relative link in the body is a fourth, also non-fatal.
- A real `apm compile` prints them. `apm compile --validate` prints none of them and exits 0 even for a file with all three problems; it exits 1 only when the package has no instructions at all.
- `apm install` prints none.
- `apm install` prints none, and deploys such a file.
- `apm audit --ci` checks lockfile, deployed-file presence, content hash and hidden Unicode, not instruction content.
- A file whose frontmatter does not parse is skipped by compile ("Failed to parse") but still deployed by install.
- A file whose frontmatter does not parse is skipped by compile ("Failed to parse", exit 0) and fails install: `apm install` exits 1 with "Rejected frontmatter in <file>" and commits nothing.
No standalone instructions validator exists, so enforcement is this skill's checks and `references/verify.md`.
@@ -2,6 +2,8 @@
source_keys:
- apm-docs-site
- apm-github-repo
- apm-cli-0-39-3-experiments
- apm-v0-39-3-source
- apm-cli-0-28-0-experiments
- claude-code-memory-docs
- github-copilot-custom-instructions-docs
@@ -26,12 +28,28 @@ source_keys:
- **Contributing files:** references/schema.md
- **Status:** `extracted`
## apm-cli-0-39-3-experiments
- **URL:** https://pypi.org/project/apm-cli/0.39.3/
- **Research doc:** plugins/kyberforge/docs/research/docs/microsoft-apm/sources.md (digest: plugins/kyberforge/docs/research/docs/microsoft-apm/instructions-gotchas.md)
- **Description:** The repo-pinned apm-cli 0.39.3 run in throwaway packages (holocron#273): unquoted and broken frontmatter failing install, the Claude compile writing a `CLAUDE.md` that imports `AGENTS.md`, per-instruction dedup, an unscoped rule's retirement from `.claude/rules/`, hand-authored collisions skipped, stale cleanup, per-target transforms, validation severity and discovery asymmetry. The bats suite in `tests/` re-runs four of these on every push.
- **Contributing files:** SKILL.md, references/schema.md, references/target-mapping.md, references/verify.md, references/create.md, references/improve.md
- **Status:** `extracted`
## apm-v0-39-3-source
- **URL:** https://github.com/microsoft/apm/tree/v0.39.3/src/apm_cli
- **Research doc:** plugins/kyberforge/docs/research/docs/microsoft-apm/sources.md (digest: plugins/kyberforge/docs/research/docs/microsoft-apm/instructions-target-mapping.md)
- **Description:** apm source at tag v0.39.3: which Claude instruction scopes route to `AGENTS.md`, and the blockers that keep every instruction in `.claude/rules/` (a hand-authored `CLAUDE.md` without the import, a hand-authored `AGENTS.md` without managed-section markers, a symlinked `AGENTS.md`).
- **Contributing files:** SKILL.md, references/target-mapping.md
- **Status:** `extracted`
## apm-cli-0-28-0-experiments
- **URL:** https://pypi.org/project/apm-cli/0.28.0/
- **Research doc:** plugins/kyberforge/docs/research/docs/microsoft-apm/sources.md (digest: plugins/kyberforge/docs/research/docs/microsoft-apm/instructions-gotchas.md)
- **Description:** The installed apm-cli 0.28.0 package plus throwaway install, compile and audit experiments confirming validation severity, unquoted-glob handling, discovery asymmetry, dedup and overwrite behaviour.
- **Contributing files:** SKILL.md, references/schema.md, references/target-mapping.md, references/verify.md, references/create.md, references/improve.md
- **Description:** The installed apm-cli 0.28.0 package plus throwaway install, compile and audit experiments. Superseded by `apm-cli-0-39-3-experiments` wherever the two were both run; still the only source for the user-scope deploy rule and the 0.28.0 behaviours the skill names as history.
- **Contributing files:** references/target-mapping.md
- **Status:** `extracted`
## claude-code-memory-docs
@@ -1,5 +1,7 @@
---
source_keys:
- apm-cli-0-39-3-experiments
- apm-v0-39-3-source
- apm-cli-0-28-0-experiments
- apm-docs-site
- claude-code-memory-docs
@@ -9,11 +11,11 @@ source_keys:
# What each target receives
Verified against apm 0.28.0 and throwaway installs. Reached from `SKILL.md` Step 2 when the question is which target keeps which field. Source-file syntax is in `references/schema.md`.
Verified against apm 0.39.3 in throwaway installs, except where a line says otherwise. Reached from `SKILL.md` Step 2 when the question is which target keeps which field. Source-file syntax is in `references/schema.md`.
## Two output paths
`apm install` writes one native file per instruction into each target's rules directory. `apm compile` writes root context files that concatenate instruction bodies, grouped by `applyTo`. Treat install as the primary path for Claude Code and Copilot, and compile as the path for targets with no native instructions directory.
`apm install` writes one native file per instruction into each target's rules directory. `apm compile` writes root context files that concatenate instruction bodies, grouped by `applyTo`. Treat install as the primary path for Copilot and the other rule-directory targets, and compile as the path for targets with no native instructions directory. Claude uses both; see below.
## Install: deployed path and transform
@@ -21,14 +23,23 @@ Verified against apm 0.28.0 and throwaway installs. Reached from `SKILL.md` Step
|---|---|---|
| copilot | `.github/instructions/<n>.instructions.md` | Verbatim copy |
| claude | `.claude/rules/<n>.md` | `applyTo` becomes a `paths:` list; `description` dropped; no frontmatter at all without `applyTo` |
| cursor | `.cursor/rules/<n>.mdc` | `applyTo` becomes `globs`; `description` kept; no `alwaysApply` written |
| cursor | `.cursor/rules/<n>.mdc` | `applyTo` becomes `globs`, one comma-separated string even for several patterns; `description` kept; no `alwaysApply` written |
| windsurf | `.windsurf/rules/<n>.md` | `trigger: glob` plus `globs`, or `trigger: always_on`; `description` dropped |
| kiro | `.kiro/steering/<n>.md` | `inclusion: fileMatch` plus `fileMatchPattern`, or `inclusion: always`; `description` dropped |
| antigravity | `.agents/rules/<n>.md` | `trigger: glob` plus `globs`, or no frontmatter; `description` dropped |
| antigravity | `.agents/rules/<n>.md` | `trigger: glob` plus `globs`, or `trigger: always_on`; `description` dropped |
| grok-build | `.grok/rules/<n>.instructions.md` | Verbatim copy |
| codex, gemini, opencode and the rest | none | Reach instructions only through compile |
Cursor, Windsurf and Antigravity do not deploy at user scope; Kiro and the rest do.
At user scope Cursor, Windsurf and Antigravity do not deploy, and Kiro and the rest do. That is from the 0.28.0 source and was not re-run.
## Claude: `.claude/rules/` or `AGENTS.md`
apm 0.38 and later split Claude's instructions between the two.
- Install deploys each instruction to `.claude/rules/`, unless a compiled `AGENTS.md` already carries it.
- Compile writes the bodies into `AGENTS.md` and a `CLAUDE.md` that holds only `@AGENTS.md`, leaving out any instruction already in `.claude/rules/`.
- A rule moves out of `.claude/rules/` only when compile actually wrote it into `AGENTS.md`: compile ran before install, `--force-instructions` was passed, or the compile also served a target with no dedup. The next install then deletes the `.claude/rules/` copy ("Retired ... AGENTS.md now carries it"). Install-then-compile dedups every deployed rule, so they all stay in `.claude/rules/`, and compile-then-install never deploys the unscoped rule there. The source also routes a rule scoped to `**`, `**/*` or exactly one literal `dir/**` this way. File-type globs such as `**/*.py`, wildcard directories and lists stay in `.claude/rules/`.
- From the source, not run: these keep every instruction in `.claude/rules/`, with a warning: a hand-authored root `CLAUDE.md` without an `@AGENTS.md` import; a hand-authored root `AGENTS.md` without `compilation.agents_md.mode: managed_section` and one pair of `<!-- apm:start -->`/`<!-- apm:end -->` markers; a symlinked `AGENTS.md`. Compile never overwrites a hand-authored root file. User scope never routes to `AGENTS.md`.
## Field survival
@@ -42,22 +53,23 @@ For Claude Code the body's first line or heading is the only descriptive text th
## Ownership and overwrite
- Claude, Cursor, Windsurf, Kiro and Antigravity treat each deployed file as apm-owned: install replaces a hand-authored file at the same path without a prompt. Copilot and grok-build skip an unmanaged file ("local files exist, not managed by APM") until `apm install --force`.
- Removing or renaming a source makes the next install delete the file it deployed for Claude, Copilot, Cursor, Windsurf and Kiro. Antigravity and grok-build leave the old file behind in 0.28.0, so delete it by hand.
- Every rule target skips a hand-authored file at a deployed path: install prints "files skipped -- local files exist, not managed by APM", deploys nothing there and exits 0. `apm install --force` overwrites the hand-authored file. apm 0.28.0 overwrote it silently on Claude, Cursor, Windsurf, Kiro and Antigravity.
- Removing or renaming a source makes the next install delete the file it deployed, on every rule target.
## Compile
- `--target claude` writes `CLAUDE.md`; Gemini writes `GEMINI.md` and `AGENTS.md`; every other target writes `AGENTS.md`.
- Compile skips instructions already deployed natively, for Claude, Copilot and Antigravity only, and the skip is all-or-nothing: if any instruction has a same-stem file in `.claude/rules/`, compile omits every instruction from `CLAUDE.md`, including a new one never deployed. With rules populated, `--target claude` exits 0, prints "produced no output files" and writes nothing. `--force-instructions` (alias `--no-dedup`) overrides.
- Cursor, Windsurf, Kiro and Grok have no dedup: compile writes `AGENTS.md` that repeats rules the tool already loads natively. Codex, Gemini and OpenCode get no native file, so the compiled root file is their only copy.
- A package with no instruction primitives (skills only) makes plain `apm compile` exit 1 with "No instruction files found"; `apm compile --clean` exits 0.
- `--target claude` writes `AGENTS.md` plus a `CLAUDE.md` that imports it. Gemini writes `GEMINI.md`, which also imports `AGENTS.md`. Every other target writes `AGENTS.md`.
- For a Claude-only compile, an instruction already deployed to `.claude/rules/` is left out of `AGENTS.md`, one instruction at a time. A nested or newly added one is still compiled. When every instruction is deployed, compile exits 0 and writes no `CLAUDE.md`. `--force-instructions` (alias `--no-dedup`) includes them all.
- A compile that also serves a target with no dedup, such as codex, writes every instruction into `AGENTS.md`. Cursor, Windsurf, Kiro and Grok then get each rule twice: natively and through `AGENTS.md`.
- Compile warns "applyTo for '<n>' matched no files" when a pattern matches nothing in the project, and places that instruction at the root.
- A package with skills but no instruction primitives makes plain `apm compile` exit 1 with "No instruction files found"; `apm compile --clean` exits 0.
## Native format facts
- Claude Code reads `.claude/rules/**/*.md` recursively. `paths` is the only field it reads, as a list or a comma-separated string; other fields are ignored. A rule without `paths` loads at every launch. Frontmatter that fails to parse is ignored and the rule loads without `paths`.
- Claude Code reads `.claude/rules/**/*.md` recursively. `paths` is the only field it reads, as a list or a comma-separated string; other fields are ignored. A rule without `paths` loads at every launch. Frontmatter that fails to parse is ignored and the rule loads without `paths`. Claude Code reads `AGENTS.md` only while no `CLAUDE.md` exists or `CLAUDE.md` imports it.
- Copilot path-specific files need `applyTo` as a quoted comma-joined string; `excludeAgent` is the only other documented key. Repository-wide instructions are the separate `.github/copilot-instructions.md`.
- Cursor ignores a plain `.md` in `.cursor/rules`. A rule with only a `description` is "Apply Intelligently", not always-on.
## Unverified
Cursor's handling of a YAML-list `globs`, Copilot's handling of unknown frontmatter keys, and runtime behaviour on Windsurf, Kiro and Antigravity. Say so rather than asserting any of them.
Copilot's handling of unknown frontmatter keys, and runtime behaviour on Windsurf, Kiro and Antigravity. Say so rather than asserting any of them.
@@ -1,11 +1,11 @@
---
source_keys:
- apm-cli-0-28-0-experiments
- apm-cli-0-39-3-experiments
---
# Verifying a file in a throwaway package
Reached from `SKILL.md` Step 3. Run step 2 outside the repo: `apm install` writes `apm_modules/`, `apm.lock.yaml` and a rules directory, and install overwrites hand-authored rule files without warning.
Reached from `SKILL.md` Step 3. Run step 2 outside the repo: `apm install` writes `apm_modules/`, `apm.lock.yaml` and a rules directory. In a repo that pins apm with uv, spell each `apm` below as `uv run --project <repo root> --frozen apm`, so the check runs the repo's apm and not the one on `PATH`.
1. From the package root, a real compile. `--validate` hides the missing-`description`, missing-`applyTo` and empty-body warnings and exits 0 whenever the package has an instruction, so it verifies nothing:
@@ -25,8 +25,8 @@ Reached from `SKILL.md` Step 3. Run step 2 outside the repo: `apm install` write
(cd "$d" && apm install && cat .claude/rules/<name>.md)
```
3. The deployed file must open with `paths:` listing the intended globs. No frontmatter block at all means `applyTo` was missing or did not parse: the rule would load in every session.
3. Install must exit 0. Exit 1 with "Rejected frontmatter" means the YAML did not parse, usually an unquoted `applyTo`. The deployed file must open with `paths:` listing the intended globs. No frontmatter block at all means `applyTo` was missing: the rule loads in every session.
4. Once rules sit in `.claude/rules/`, `apm compile --target claude` writes no `CLAUDE.md` and still exits 0, so an exit-code check proves nothing. To inspect the compiled root file, pass `--force-instructions`.
4. Once every rule sits in `.claude/rules/`, `apm compile --target claude` writes no `CLAUDE.md` and still exits 0, so an exit-code check proves nothing. To inspect the compiled `AGENTS.md`, pass `--force-instructions`. The `CLAUDE.md` it writes holds only `@AGENTS.md`.
Delete the directory afterwards. Report only what was observed; Cursor's list-form `globs` and the Windsurf, Kiro and Antigravity runtimes stay unverified.
Delete the directory afterwards. Report only what was observed; the Windsurf, Kiro and Antigravity runtimes stay unverified.
@@ -1,12 +1,12 @@
# tests/
- **`new-instructions.bats`** — covers `scripts/new-instructions.sh` (name validation, package walk-up, no-package refusal, no-op on an existing file, template placeholders) and the apm behaviour the skill's gotchas rest on, run against throwaway packages: a filled scaffold compiles into `CLAUDE.md` and installs into `.claude/rules/` with `description` dropped, compile writes nothing once rules are installed, an unquoted `applyTo` installs unscoped, and `--validate` hides the warnings a real compile prints.
- **`new-instructions.bats`** — covers `scripts/new-instructions.sh` (name validation, package walk-up, no-package refusal, no-op on an existing file, template placeholders) and the apm behaviour the skill's gotchas rest on, run against throwaway packages: a filled scaffold compiles into `AGENTS.md` behind a `CLAUDE.md` that imports it, and installs into `.claude/rules/` with `description` dropped; compile writes nothing once rules are installed; an unquoted `applyTo` fails install and deploys nothing; and `--validate` hides the warnings a real compile prints.
## Dependencies
The test file loads `bats-support` and `bats-assert` from the repo root's `tests/test_helper/`, and runs on the repo's bats submodule at `tests/bats/`. The first `bash tests/run-bats.sh` initialises the submodules.
The apm tests need the `apm` CLI on `PATH` and skip when it is absent. They assert apm 0.28.0 behaviour, so a failure after an apm upgrade is a finding about the skill's gotchas, not a flaky test.
In this repo the apm tests run the repo-pinned apm (`uv run --frozen apm`, through `scripts/lib/apm.sh`) and fail when it is unavailable; run `uv sync --frozen` first. Outside this repo they use the `apm` on `PATH` and skip when it is absent. They assert apm 0.39.3 behaviour, so a failure after an apm upgrade is a finding about the skill's gotchas, not a flaky test.
From the repo root:
@@ -28,7 +28,21 @@ fill() {
"$1"
}
# In this repo apm is the one pinned in pyproject.toml/uv.lock, run through
# scripts/lib/apm.sh as `uv run --project <repo root> --frozen apm` (ADR-0034),
# so these tests exercise 0.39.3 and never whatever apm is on PATH. The pin is
# a declared dependency here, so a missing uv or an apm below the helper's
# minimum FAILS rather than skips: a skip would let `run-tests.sh --strict` go
# green without running these tests. Outside this repo (no helper) the PATH
# apm is used, and its absence still skips.
need_apm() {
if [[ -f "$REPO_ROOT/scripts/lib/apm.sh" ]]; then
# shellcheck source=/dev/null
source "$REPO_ROOT/scripts/lib/apm.sh"
require_apm_version || fail "the repo-pinned apm is unavailable; run 'uv sync --frozen' at $REPO_ROOT"
apm() { run_apm "$@"; }
return 0
fi
command -v apm >/dev/null 2>&1 || skip "apm CLI not installed"
}
@@ -173,10 +187,14 @@ need_apm() {
}
# ---------------------------------------------------------------------------
# apm behaviour the skill's gotchas rest on (verified against apm 0.28.0)
# apm behaviour the skill's gotchas rest on. Verified against apm 0.28.0, then
# re-pinned to the repo's 0.39.3 (#271), where three behaviours changed: compile
# --target claude writes a CLAUDE.md that imports AGENTS.md, an unquoted applyTo
# fails install closed, and compile warns when applyTo matches no file. The
# skill's text was brought level with 0.39.3 under #273.
# ---------------------------------------------------------------------------
@test "filled scaffold compiles for the Claude target into CLAUDE.md without the description" {
@test "filled scaffold compiles for the Claude target: CLAUDE.md imports AGENTS.md, which drops the description" {
need_apm
make_package
bash "$SCRIPT" my-rule "$ROOT"
@@ -185,9 +203,11 @@ need_apm() {
run apm compile --target claude
assert_success
assert [ -f "$ROOT/CLAUDE.md" ]
run grep -F 'Use type hints.' "$ROOT/CLAUDE.md"
run grep -Fx '@AGENTS.md' "$ROOT/CLAUDE.md"
assert_success
run grep -F 'Python style rules' "$ROOT/CLAUDE.md"
run grep -F 'Use type hints.' "$ROOT/AGENTS.md"
assert_success
run grep -F 'Python style rules' "$ROOT/AGENTS.md"
assert_failure
}
@@ -221,17 +241,16 @@ need_apm() {
assert [ ! -f "$ROOT/CLAUDE.md" ]
}
@test "an unquoted applyTo still installs, as a rule with no paths:" {
@test "an unquoted applyTo fails install closed and deploys no rule" {
need_apm
make_package
mkdir -p "$ROOT/.apm/instructions"
printf -- '---\ndescription: x\napplyTo: **/*.py\n---\n# T\n\n- a\n' > "$ROOT/.apm/instructions/bad.instructions.md"
cd "$ROOT"
run apm install
assert_success
assert [ -f "$ROOT/.claude/rules/bad.md" ]
run grep -F 'paths:' "$ROOT/.claude/rules/bad.md"
assert_failure
assert_output --partial "Rejected frontmatter in bad.instructions.md"
assert [ ! -f "$ROOT/.claude/rules/bad.md" ]
}
@test "compile --validate exits 0 and hides the warnings a real compile prints" {
@@ -259,5 +278,8 @@ need_apm() {
assert_success
assert_output --partial "dry-run"
refute_output --partial "Failed to parse"
refute_output --partial "Warning"
# 0.39 warns when applyTo matches no file, which an empty package always
# does; any other warning is a parse or validation finding.
run grep -F "Warning" <<< "$(grep -vF "matched no files" <<< "$output")"
assert_failure
}
@@ -5,23 +5,24 @@ description: >
(`.apm/prompts/*.prompt.md`). Not read-only review -> `factory-audit`.
Not skills -> `skill-author`. Not agents -> `agent-author`. Not
instructions -> `instructions-author`.
compatibility: Requires the apm CLI; behaviour verified against apm 0.28.0.
compatibility: Requires the apm CLI, 0.39.2 or later; behaviour verified against apm 0.39.3.
allowed-tools: Bash Read Write Edit
metadata:
version: "0.1.0"
version: "0.1.1"
category: factory
source_keys:
- apm-docs-author-prompts
- apm-docs-llms-full
- apm-docs-producer-ramp
- apm-github-repo
- apm-cli-0-28-0-prompt-experiments
- apm-cli-0-39-3-experiments
- apm-v0-39-3-source
---
## Gotchas
- `apm compile` never reads prompt files, and `--validate` ignores them even when malformed. A prompt file is verified only by a throwaway `apm install`.
- Unsupported frontmatter keys are dropped, loudly on the Claude family and silently on Gemini, which keeps only `description`. Codex, Kiro and Antigravity deploy nothing and print nothing.
- Unsupported frontmatter keys are dropped quietly: the Claude family names them only under `apm install --verbose`, and Gemini keeps only `description` and says nothing. Kiro strips every key, with a warning naming them. Codex and Antigravity deploy nothing and print nothing.
- `input:` descriptions are discarded: only the names survive, as `arguments:`. Duplicate names are not caught.
## Step 1 — Dispatch
@@ -42,7 +43,7 @@ Gates on every file, whichever flow wrote it:
- **Source.** A single file named `<stem>.prompt.md` in `.apm/prompts/`, flat. Anything nested, uppercase or named plain `.md` is silently ignored.
- **Stem.** Kebab-case. It becomes the deployed command name, and apm skips a hand-written file of the same name unless `--force` is passed. Check for a collision before choosing it.
- **Frontmatter.** `description`, plus `input`, `allowed-tools`, `model` or `argument-hint` only when needed. No other keys: they are dropped, and `source_keys` would warn on every install.
- **Frontmatter.** `description`, plus `input`, `allowed-tools`, `model` or `argument-hint` only when needed. A Claude Code command key such as `disable-model-invocation` survives on the `claude` target only, from apm 0.39.0, and is dropped on every other target; add one only when the command needs it on Claude. Never `hooks`: apm withholds it. No other keys, `source_keys` included: they are dropped.
- **Arguments.** Declare `input:` names and use `${input:name}` in the body, or use a literal `$ARGUMENTS`, never both.
- **Body.** Written as an instruction to the model, self-contained, and clear about what it produces. If unsure the content is a prompt file rather than a skill, a rule or something to enforce, read `references/content.md`.
@@ -11,6 +11,8 @@ input:
# allowed-tools: Bash(git status:*) Read
# model: FILL IN
# argument-hint: "<target>" # synthesised from input: when omitted
# Claude only (apm 0.39+), dropped on every other target:
# disable-model-invocation: true
---
FILL IN: an instruction to the model, written so it works with nothing else loaded.
@@ -1,7 +1,7 @@
---
source_keys:
- apm-docs-author-prompts
- apm-cli-0-28-0-prompt-experiments
- apm-cli-0-39-3-experiments
---
# Creating a new prompt file
@@ -1,7 +1,7 @@
---
source_keys:
- apm-docs-author-prompts
- apm-cli-0-28-0-prompt-experiments
- apm-cli-0-39-3-experiments
---
# Improving an existing prompt file
@@ -18,15 +18,20 @@ Read the file whole. Apply the signals that triggered this flow (`SKILL.md` Step
|---|---|---|
| The command does not exist after install | The file is nested, uppercase (`.PROMPT.md`) or a bare `.md`, so discovery ignored it | Move it flat into `.apm/prompts/` and name it `<stem>.prompt.md` |
| The command is missing and install warned "malformed or over-budget YAML frontmatter" | Broken frontmatter, so Claude and Gemini skipped the file | Repair the YAML |
| Install warned "frontmatter keys not supported … dropped" | The file carries keys the Claude family does not keep | Remove them, or accept that only Copilot keeps them |
| `apm install --verbose` reported "frontmatter keys not supported … dropped" | The file carries keys that target does not keep | Remove them, or accept that only Copilot keeps them |
| `disable-model-invocation` or another Claude Code command key is missing from `.claude/commands/` | The apm that installed it is older than 0.39, which dropped those keys | Install with apm 0.39.2 or later |
| A Claude Code command key is missing from the Cursor or OpenCode command | Only the `claude` target keeps those keys | State it to the user; it is apm behaviour |
| Install warned "frontmatter hooks withheld" | The file sets `hooks`, which apm does not deploy on commands | Remove it, or move the hook into a hook package |
| An argument is missing from `arguments:` | The name failed `[A-Za-z][A-Za-z0-9_-]{0,63}` and install warned `input: rejected` | Rename it |
| An argument appears twice | Duplicate names are not caught | Remove the duplicate |
| `arguments:` lists `name` and `description` | An `input:` item had `name:` and `description:` keys, and each key became an argument | Use plain names, or one `{name: description}` pair per item |
| The body shows `$ARGUMENTS` or `$0` next to named arguments | `input:` and a literal placeholder were both written | Use one style |
| The Gemini command ignores `model` or `allowed-tools` | Gemini keeps only `description` and the body, silently | State it to the user; it is apm behaviour |
| Nothing deployed for Codex, Kiro or Antigravity | Those targets have no prompt surface | State it to the user |
| Nothing deployed for Codex or Antigravity | Those targets have no prompt surface | State it to the user |
| The Kiro prompt has no frontmatter | Kiro's prompt surface keeps the body only | State it to the user |
| Install exited 1 with "Kept … modified since APM deployed it" | A deployed command was edited by hand | Move it aside, or export the edit with `apm export-patch`, then reinstall |
| A hand-written command was not replaced | apm skips unmanaged files | Rename the stem, or use `apm install --force` knowingly |
| Install failed with exit 1 and a security error | Tag characters or a bidi override in the file; the Claude-family command is withheld even with `--force`, while the Copilot copy and Gemini TOML may still be written | Remove the hidden characters |
| Install failed with exit 1 and a security error | Tag characters or a bidi override in the file. Nothing is written; with `--force` the Copilot copy and Gemini TOML are, but the Claude-family command is still withheld | Remove the hidden characters |
Cases not in the table: read `references/target-mapping.md`.
@@ -2,12 +2,14 @@
source_keys:
- apm-docs-author-prompts
- apm-github-repo
- apm-v0-39-3-source
- apm-cli-0-39-3-experiments
- apm-cli-0-28-0-prompt-experiments
---
# The prompt source file
Verified against apm 0.28.0. Reached from `SKILL.md` Step 2 when a field, a placeholder or the file's location is in question.
Verified against apm 0.39.3, except the root-file and odd-name rules under "Location and name", last run on 0.28.0. Reached from `SKILL.md` Step 2 when a field, a placeholder or the file's location is in question.
## Location and name
@@ -31,9 +33,16 @@ No closed schema; apm passes or drops keys per target.
| `model` | Model override |
| `argument-hint` (alias `argumentHint`) | Hint text; synthesised as `<a> <b>` from `input` when omitted |
### Claude Code command keys
From apm 0.39.0 the `claude` target keeps Claude Code's own command keys: `when_to_use`, `disable-model-invocation`, `user-invocable`, `disallowed-tools`, `effort`, `context`, `agent`, `background` and `shell`. Every other target that gets a command file (cursor, opencode, windsurf, grok-build) drops them, and Gemini and Kiro drop them with the rest. apm 0.28.0 dropped them on Claude too, so a command relying on one needs apm 0.39.2 or later wherever it is installed.
- An authored `arguments:` is kept on Claude only when the file has no `input:` key at all.
- `hooks` is withheld: the command deploys without it, and install warns `frontmatter hooks withheld`.
Input names must match `[A-Za-z][A-Za-z0-9_-]{0,63}`. An invalid name is dropped with a warning and the install still succeeds; duplicates are neither removed nor warned about.
The Copilot App workflow keys `interval`, `schedule_hour` and `schedule_day` mark a prompt file as a scheduled workflow that the command integrator skips. Do not use them in a plain prompt file. The VS Code keys `agent`, `tools` and `name` survive on Copilot only.
The Copilot App workflow keys `interval`, `schedule_hour` and `schedule_day` mark a prompt file as a scheduled workflow that the command integrator skips. Do not use them in a plain prompt file. The VS Code keys `tools` and `name` survive on Copilot only. `agent` also survives on Claude, as a Claude Code command key with its own meaning there.
## Body placeholders
@@ -4,6 +4,8 @@ source_keys:
- apm-docs-llms-full
- apm-docs-producer-ramp
- apm-github-repo
- apm-v0-39-3-source
- apm-cli-0-39-3-experiments
- apm-cli-0-28-0-prompt-experiments
---
@@ -41,10 +43,26 @@ source_keys:
- **Contributing files:** SKILL.md, references/schema.md
- **Status:** `extracted`
## apm-v0-39-3-source
- **URL:** https://github.com/microsoft/apm/tree/v0.39.3/src/apm_cli
- **Research doc:** plugins/kyberforge/docs/research/docs/microsoft-apm/sources.md (digest: plugins/kyberforge/docs/research/docs/microsoft-apm/prompt-primitive-schema.md)
- **Description:** apm source at tag v0.39.3: the Claude-native command keys kept only on the `claude` target (`_CLAUDE_NATIVE_COMMAND_KEYS`), the `arguments` rule, and `hooks` being withheld.
- **Contributing files:** SKILL.md, references/schema.md, references/target-mapping.md
- **Status:** `extracted`
## apm-cli-0-39-3-experiments
- **URL:** https://pypi.org/project/apm-cli/0.39.3/
- **Research doc:** plugins/kyberforge/docs/research/docs/microsoft-apm/sources.md (digest: plugins/kyberforge/docs/research/docs/microsoft-apm/prompt-gotchas.md)
- **Description:** The repo-pinned apm-cli 0.39.3 run in throwaway packages (holocron#273): Claude-native keys on claude versus cursor and opencode, the `--verbose` dropped-keys line, `hooks` withheld, per-target output including Kiro, malformed YAML, input names, collisions, hand-edited deployed files, hidden-character scanning, and compile ignoring prompts.
- **Contributing files:** SKILL.md, references/create.md, references/improve.md, references/schema.md, references/target-mapping.md, references/verify.md
- **Status:** `extracted`
## apm-cli-0-28-0-prompt-experiments
- **URL:** https://pypi.org/project/apm-cli/0.28.0/
- **Research doc:** plugins/kyberforge/docs/research/docs/microsoft-apm/sources.md (digest: plugins/kyberforge/docs/research/docs/microsoft-apm/prompt-gotchas.md)
- **Description:** The installed apm-cli 0.28.0 exercised in throwaway packages: discovery, manifest type, compile on prompts-only packages, per-target output and warnings, input-name and YAML edge cases, collisions, cleanup, hidden-Unicode scanning and packing.
- **Contributing files:** SKILL.md, references/create.md, references/improve.md, references/schema.md, references/target-mapping.md, references/verify.md
- **Description:** The installed apm-cli 0.28.0 exercised in throwaway packages. Superseded by `apm-cli-0-39-3-experiments` wherever both were run; still the only source for root-level discovery, odd filenames, user-scope paths, packing, and BOM, NBSP and bidi scanning.
- **Contributing files:** references/schema.md, references/target-mapping.md
- **Status:** `extracted`
@@ -2,12 +2,14 @@
source_keys:
- apm-docs-author-prompts
- apm-docs-llms-full
- apm-cli-0-39-3-experiments
- apm-v0-39-3-source
- apm-cli-0-28-0-prompt-experiments
---
# What each target receives
Verified against apm 0.28.0 in throwaway installs; runtime behaviour in the receiving tools was not tested. Reached from `SKILL.md` Step 2. Source syntax is in `references/schema.md`.
Verified against apm 0.39.3 in throwaway installs, except the user-scope paths and packing, last run on 0.28.0. Runtime behaviour in the receiving tools was not tested. Reached from `SKILL.md` Step 2. Source syntax is in `references/schema.md`.
## Install is the only path
@@ -20,7 +22,8 @@ Verified against apm 0.28.0 in throwaway installs; runtime behaviour in the rece
| cursor, opencode, grok-build | `.cursor/commands/`, `.opencode/commands/`, `.grok/commands/` `<n>.md` | Same transform as claude |
| windsurf | `.windsurf/workflows/<n>.md` | Same transform |
| gemini | `.gemini/commands/<n>.toml` | `description` and `prompt` only, silently |
| codex, kiro, antigravity, agent-skills | none | Exit 0, no warning |
| kiro | `.kiro/prompts/<n>.md` | Body only; every frontmatter key stripped, with a warning naming them |
| codex, antigravity, agent-skills | none | Exit 0, no warning |
At user scope (`apm install -g`) claude, gemini and cursor deploy to their home commands directories and Copilot to `~/.copilot/prompts/`. The experimental targets (hermes, openclaw, copilot-cowork, grok-cloud, copilot-app) need a flag and are untested.
@@ -33,9 +36,11 @@ At user scope (`apm install -g`) claude, gemini and cursor deploy to their home
| `allowed-tools` | kept (ignored by Copilot) | kept | dropped silently |
| `model` | kept | kept | dropped silently |
| `argument-hint` | kept | kept or synthesised | dropped silently |
| any other key | kept | dropped, with a warning naming the keys | dropped silently |
| Claude Code command keys (`disable-model-invocation` and the rest, `references/schema.md`) | kept | kept on `claude` only; dropped on cursor, opencode, windsurf and grok-build | dropped silently |
| `hooks` | kept | withheld on `claude`, with a warning; dropped elsewhere | dropped silently |
| any other key | kept | dropped; named only under `apm install --verbose` | dropped silently |
The Claude command file holds only `allowed-tools`, `argument-hint`, `arguments`, `description` and `model`, sorted, with no trailing newline.
The Claude command file holds the shared keys (`allowed-tools`, `argument-hint`, `arguments`, `description`, `model`) plus any Claude Code command keys, sorted. Cursor's and the other Claude-family files hold the shared keys only.
## Body placeholders by target
@@ -49,13 +54,14 @@ Claude Code natively supports `$ARGUMENTS`, zero-based `$N` and named `$name` fr
## Ownership and cleanup
- A hand-written file at a deployed path is skipped ("not managed by APM", exit 0); `--force` overwrites. Editing a deployed file and reinstalling silently overwrites it.
- Removing a prompt file from the package and reinstalling deletes the deployed files. A hand-edited one is kept with a "delete manually" message.
- Zero-width characters, BOM and NBSP warn and the file deploys to every target. Tag characters and bidi overrides are critical: install exits 1 and the Claude-family command is withheld, but the Copilot byte copy and Gemini TOML may still be written. `--force` makes the exit code 0 and changes nothing else.
- A hand-written file at a deployed path is skipped ("not managed by APM", exit 0); `--force` overwrites.
- A deployed file edited by hand blocks the next install that would change it: install exits 1 with "Kept ... it was modified since APM deployed it" and commits nothing. Move the file aside, or export the edit with `apm export-patch`.
- Removing a prompt file from the package and reinstalling deletes the deployed files. A hand-edited one is kept, with a warning.
- A zero-width space warns and the file deploys to every target. A tag character is critical: install exits 1 and writes nothing on any target. `--force` exits 0 and writes the Copilot copy and Gemini TOML, but still withholds the Claude-family command. BOM, NBSP and bidi overrides were last tested on 0.28.0, as warning, warning and critical.
## Packing
`apm pack --format plugin` copies `.apm/prompts/x.prompt.md` to `commands/x.md` unchanged and skips root-level prompts. Installing that bundle copies files verbatim, so `input:` survives untransformed and Copilot receives `.github/commands/`.
Last run on 0.28.0. `apm pack --format plugin` copies `.apm/prompts/x.prompt.md` to `commands/x.md` unchanged and skips root-level prompts. Installing that bundle copies files verbatim, so `input:` survives untransformed and Copilot receives `.github/commands/`.
## Unverified
@@ -1,11 +1,11 @@
---
source_keys:
- apm-cli-0-28-0-prompt-experiments
- apm-cli-0-39-3-experiments
---
# Verifying a file in a throwaway package
Reached from `SKILL.md` Step 3. `apm compile` and `apm compile --validate` never read prompts, so they verify nothing. Install is the only check. Run it outside the repo: `apm install` writes `apm_modules/`, `apm.lock.yaml` and a commands directory.
Reached from `SKILL.md` Step 3. `apm compile` and `apm compile --validate` never read prompts, so they verify nothing. Install is the only check. Run it outside the repo: `apm install` writes `apm_modules/`, `apm.lock.yaml` and a commands directory. In a repo that pins apm with uv, spell each `apm` below as `uv run --project <repo root> --frozen apm`, so the check runs the repo's apm and not the one on `PATH`.
1. Deploy the prompt where nothing else can be overwritten:
@@ -14,12 +14,12 @@ Reached from `SKILL.md` Step 3. `apm compile` and `apm compile --validate` never
printf 'name: scratch\nversion: 0.1.0\ntype: prompts\ntargets:\n - claude\n' > "$d/apm.yml"
mkdir -p "$d/.apm/prompts" "$d/.claude"
cp <package-root>/.apm/prompts/<name>.prompt.md "$d/.apm/prompts/"
(cd "$d" && apm install && cat .claude/commands/<name>.md)
(cd "$d" && apm install --verbose && cat .claude/commands/<name>.md)
```
2. Read every warning install prints. A line starting "frontmatter keys not supported … dropped" lists keys that did not survive; "input: rejected" names an invalid argument; "Skipped command … malformed" means the file did not parse and no command exists.
2. Read every warning and info line install prints. `--verbose` is what makes apm name dropped keys: a line "frontmatter keys not supported … dropped" lists keys that did not survive, and "frontmatter hooks withheld" means `hooks` was removed; "input: rejected" names an invalid argument; "Skipped command … malformed" means the file did not parse and no command exists.
3. The deployed file must contain `description` and, if `input:` was written, an `arguments:` list matching it. Body placeholders should read `$name`, not `${input:name}`. A missing file means the install skipped it.
3. The deployed file must contain `description`, every Claude Code command key the source set, such as `disable-model-invocation`, and, if `input:` was written, an `arguments:` list matching it. A missing command key means the apm that ran is older than 0.39. Body placeholders should read `$name`, not `${input:name}`. A missing file means the install skipped it.
4. For another target, add it to `targets:` and `cat` its deployed path from `references/target-mapping.md`. Gemini prints no warning for what it drops, so read its `.toml`.
+1 -1
View File
@@ -19,7 +19,7 @@ Then:
apm install
```
The entry above is unpinned and tracks the remote's default branch — add `ref: <tag>` to pin a release. Registering the catalogue instead (`apm marketplace add https://git.rkdr.net/Mortis/Holocron.git --name holocron`) gets you the `kyberforge@holocron` short name, but writes to `~/.apm/marketplaces.json` at user scope; the git+path object needs nothing beyond the manifest.
The entry above is unpinned and tracks the remote's default branch. To pin a release, add `ref: kyberforge-v<x.y.z>` after `path:`; see [Pinning a plugin to a release](../../README.md#pinning-a-plugin-to-a-release). Registering the catalogue instead (`apm marketplace add https://git.rkdr.net/Mortis/Holocron.git --name holocron`) gets you the `kyberforge@holocron` short name, but writes to `~/.apm/marketplaces.json` at user scope; the git+path object needs nothing beyond the manifest.
**Native plugin installs do not work.** This package ships no per-plugin manifest and no flat content directories, so a host that installs it natively gets zero skills, agents and hooks — and Claude Code raises no error while doing it (ADR-0024).
+1 -1
View File
@@ -1,5 +1,5 @@
name: kyberforge
version: 2.2.1
version: 2.3.1
description: Skills and agents for creating, maintaining, and managing an apm plugin marketplace for Claude Code and GitHub Copilot.
author:
name: Mortis
+55 -15
View File
@@ -70,15 +70,21 @@ tracked in a `.claude/apm-hooks.json` sidecar, so an uninstall removes them with
hand-authored hooks. Both `.claude/hooks/` and the sidecar are gitignored install output.
Note that apm's **executable-trust gate is off** unless the consuming project's `apm.yml` has an
`executables:` block — without one, package hooks deploy with no prompt. The grant is
**version-blind**: apm also matches an allow key such as `kyberforge#<version>` by its bare package
name, so a version bump on one side does not stop the hook deploying (verified against apm 0.28.0;
the correction is recorded in ADR-0019 and `docs/spec/gates.md`). This repo still keeps each key at
`<name>#<version>` as a record of which version was reviewed, and `check-executables-allow-sync` is
the pre-push gate that holds every plugin shipping `.apm/hooks/` or `bin/` to that.
`executables:` block — without one, package hooks deploy with no prompt. An allow key must be the
package's **full identity**, `<host>/<owner>/<repo>/<path>`, as `apm approve --list` prints it, for
example `git.rkdr.net/Mortis/Holocron/plugins/kyberforge`. apm 0.39 no longer matches the bare
`kyberforge#<version>` form that 0.28.0 accepted: under 0.39.3 that key parks the hook ("parked
pending approval"), deploys nothing and exits 0 (spike #269, re-run under #273). The grant is still
**version-blind**: apm strips a `#<version>` suffix before matching, so a key at one version admits
any other, and a version bump on one side does not stop the hook deploying. This repo keeps each key
at `<identity>#<version>` as a record of which version was reviewed, and
`check-executables-allow-sync` is the pre-push gate that holds every plugin shipping `.apm/hooks/` or
`bin/` to that.
apm 0.28.0 prints "parked pending approval" for a granted package even when it deploys the hook
(holocron#208). Check for the deployed script and settings entry, not the warning.
A matching type-level grant (`hooks: true`) deploys the hook, and every install then warns that the
approval is "not pinned to content". apm 0.28.0 printed "parked pending approval" even for a granted
package (holocron#208); 0.39.3 prints it only when the hook really was not deployed. Either way, check
for the deployed script and settings entry, not the exit code.
## The SessionStart hook
@@ -87,6 +93,39 @@ and if anything is behind, runs `apm update --yes` and returns `reloadSkills: tr
session picks up the redeployed content. Rationale, measurements, and the failure modes are in
ADR-0019.
**Which apm it runs.** The hook picks one apm and uses it for every call (ADR-0034):
1. `uv run --project <root> --frozen --no-sync --offline apm`, when the project pins apm and `uv` is
on `PATH`. A pin is a `pyproject.toml` carrying a quoted `apm-cli` requirement plus a `uv.lock`
beside it. It is matched as text so the hook needs no Python.
2. Otherwise the `apm` on `PATH`.
3. Otherwise nothing: it exits 0 silently.
uv is only ever called as `uv run`, with `--no-sync`, so the hook never installs into the environment
and never reaches the network through uv. Even `--no-sync` creates an empty `.venv` when none exists,
so before taking the uv path the hook checks that the project environment exists. That is
`$UV_PROJECT_ENVIRONMENT` when set, else `<root>/.venv`. If it is missing, the hook prints a fixed
"not synced, run `uv sync --frozen`" notice and never calls uv. An environment that exists but was
never synced has no apm of its own. `uv run` then falls through to the `PATH` apm, and the version
check below catches an old one.
**It needs `timeout` or `gtimeout`.** Every apm call is bounded. Stock macOS ships no `timeout`, and
Homebrew coreutils installs it as `gtimeout`, so the hook uses whichever exists. With neither, it
exits 0 silently on every path, before choosing an apm, rather than run an unbounded call.
**apm older than 0.39.2 is not trusted.** Before the outdated check the hook reads `--version`. If the
chosen apm is older than 0.39.2, or its version cannot be read, the hook prints a fixed notice that
names the chosen binary and skips the check. The reason is that an older apm refuses a lockfile v4 and
would then report the install as up to date. "Too old" and "could not read the version" are separate
notices. On the uv path, too old says to run `uv sync --frozen`, and unreadable (the call failed or
timed out) says to check `uv run apm --version` or to run `uv sync --frozen`. On the `PATH` path, too old says to upgrade or pin
apm, and unreadable says to check `apm --version`.
**Advice text is fixed.** Every notice is a literal string, and the only variable part is a
digit-checked package count. The commands it names follow the chosen binary: `uv run apm install` or
`apm install`, and `uv run apm update --yes` or `apm update --yes`. No command output is ever
interpolated.
**Where it looks for the lockfile.** The hook resolves a project directory as `${CLAUDE_PROJECT_DIR}`
when the host exports it (Claude Code does, for SessionStart hooks) and the current directory
otherwise, then exits silently unless that directory holds an `apm.lock.yaml` — which is what makes
@@ -97,14 +136,14 @@ Keep the cwd fallback: a host that sets no `CLAUDE_PROJECT_DIR` must still get i
behaviour, not an unset-variable error.
**The `timeout` in `hooks.json` must exceed the script's own budget.** The script spends at most
`timeout 60 apm outdated` plus `timeout 300 apm update`; the hook entry declares `timeout: 380`, the
sum plus a buffer. Set it lower and a slow remote gets the hook SIGKILLed mid-`apm update`, leaving a
partially redeployed `.claude/skills/` and emitting no notice — precisely the silent failure the hook
exists to prevent. `tests/test-apm-current-hook.sh` pins the relationship (host timeout > sum of the
15s on `apm --version`, 60s on `apm outdated` and 300s on `apm update`, 375s in all. The hook entry
declares `timeout: 400`, the sum plus a buffer. Set it lower and a slow remote gets the hook
SIGKILLed mid-`apm update`, leaving a partially redeployed `.claude/skills/` and emitting no notice —
precisely the silent failure the hook exists to prevent. `tests/test-apm-current-hook.sh` pins the relationship (host timeout > sum of the
script's internal timeouts) rather than the literal, so raising either side alone fails the suite.
**Staleness is detected by matching apm's summary line, and both spellings count.** `apm outdated`
has no `--json` or otherwise machine-readable output (verified against apm 0.28.0), so the hook
has no `--json` or otherwise machine-readable output (verified against apm 0.28.0 and 0.39.3), so the hook
greps its text. apm prints `1 outdated dependency found` in the singular when exactly one package is
behind and `N outdated dependencies found` otherwise; matching only the plural silently misses a
one-package drift. Because a mocked `apm` would keep a reworded release invisible, the test suite
@@ -116,14 +155,15 @@ hook.
An earlier version of this section said Copilot loads no hooks from an apm package, because nothing
pointed Copilot at a hooks file and apm wrote only a Claude-shaped definition. That no longer holds:
apm 0.28.0 shapes and deploys hooks per target itself, with no `plugin.json` pointer involved.
apm shapes and deploys hooks per target itself, with no `plugin.json` pointer involved. The table
below was observed on 0.28.0 and re-run on 0.39.3 (holocron#273).
Sources: `docs/research/infra-packages/enforcement-hooks.md` on the `research/enforcement-hooks`
branch, and the [delivery guard hook](https://git.rkdr.net/Mortis/Holocron/issues/190) work.
| Target | Where apm writes the hook | Status |
|---|---|---|
| `copilot` | One file per hook, `.github/hooks/<pkg>-<name>.json`, with the script under `.github/hooks/scripts/<pkg>/.apm/hooks/`. Event names are renamed to camelCase and `version: 1` is added. | **Unverified.** Entries keep Claude's nested matcher group with `command`/`timeout`. Copilot's docs accept `command`/`timeout` as aliases for `bash`/`powershell`, but don't document the nested group, so whether Copilot CLI runs the hook is untested until a Copilot account exists. |
| `codex` | Merged into `.codex/hooks.json`, with the script under `.codex/hooks/<pkg>/.apm/hooks/`. Claude's event names and shape are kept. | apm skips the target unless `.codex/` already exists, and Codex runs project hooks only after a human trusts them. |
| `codex` | Merged into `.codex/hooks.json`, with the script under `.codex/hooks/<pkg>/.apm/hooks/` and ownership in `.codex/apm-hooks.json`. Claude's event names and shape are kept. | With `codex` in `targets:`, apm 0.39.3 creates `.codex/` and deploys; whether it skips an auto-detected codex target with no `.codex/` was not re-run. Codex runs project hooks only after a human trusts them. |
Only enabled targets get a hook: this repo's root `apm.yml` targets `claude` alone, so nothing lands
in `.github/hooks/` or `.codex/` here. VS Code's Copilot reads both `.github/hooks/` and
@@ -0,0 +1,96 @@
---
topic: approvals-and-executables
source_keys:
- apm-v0-39-3-source
- apm-v0-39-3-changelog
- apm-v0-39-3-docs
- apm-cli-0-39-3-experiments
---
How apm 0.39.3 decides whether a package's executables may be deployed. Executables means hooks, MCP servers, `bin`, LSP servers, canvas extensions and native plugins. This also covers what `apm approve` writes and which `apm audit --ci` checks enforce it. Read from the v0.39.3 source, CHANGELOG and docs, and not run. Claims are marked **source** or **doc**.
## The gate and its opt-in
- **Source:** the executables gate is on when the project `apm.yml` has an `executables:` block (even `{}`) or the deprecated `allowExecutables:` block. **Doc:** a non-empty `executables:` block in org policy also turns it on.
- **Doc:** without an opt-in, executables deploy unconditionally. The first project approval prompts that it turns the gate on. A `--user` approval never turns it on.
- **Source:** `allowExecutables:` is still read as an alias of `executables.allow`, warned once per run, and migrated on the next approve or deny write.
## Store shape
`apm approve` writes the project `apm.yml` under `executables: {allow, deny}` by default. `--user` writes `$APM_HOME/config.json` instead.
```yaml
executables:
allow:
acme/agent-kit:
hooks: { .apm/hooks/lint-on-save.json: sha256:<64 hex> }
mcp: { kit-docs: sha256:<64 hex> }
acme/tools: { bin: true }
deny:
evil/pkg: { hooks: true, mcp: true, bin: true, canvas: true, lsp: true }
```
- **Source:** each package key is a version-blind identity, such as `owner/repo`, `./pkgs/x` or `local:pkgs/leaf`.
- **Source:** values by type:
- `hooks` and `mcp` are maps of `item: sha256:<64 hex>`. The item is the package-relative hook file path, or the MCP server name.
- `bin`, `lsp` and `canvas` are `true`.
- A native plugin gets a single `plugin: sha256:<hex>`.
- **Source:** deny entries stay booleans.
- **Source:** malformed pins are rejected. A pinned item set to `true`, or a short digest, fails with `expected 'sha256:<64 hex>'`.
## Grants are version-blind
- **Source:** an ordinary grant key has its `#version` suffix stripped before matching. So `owner/repo#1.2.0` matches any installed version of `owner/repo`, and `apm approve` folds such keys into the bare identity. This was already true in 0.28.0.
- **Source:** the one exception is content-bound local-bundle keys of the form `name#version@sha256:<digest>`, which match only exactly.
## Type-level versus content-pinned grants
- **Source/doc:** type-level `hooks: true` and `mcp: true` still deploy any content. Each install warns once: `N executable approval(s) not pinned to content: <pkg> (<type>) ... Upstream changes deploy without review.`
- **Source/doc:** `mcp: true` never admits a transitive MCP server.
- **Source/doc:** re-running `apm approve <pkg>` converts a type-level grant to pins.
- **Source:** a pinned item whose bytes change is parked as `definition-changed` and not deployed. A project pin decides alone; a user pin applies only when the project has none for that item.
- **Source (0.38.0, #4688):** a hook pin covers everything the hook deploys:
- the hook JSON;
- every script it references;
- every file the hook-bundle copier deploys from those script roots, such as helpers and nested `package.json`;
- the Node module type.
It does not cover code the hook downloads at run time. Pins written before 0.38 show as changed once, so re-run `apm approve <pkg>`.
- **Source:** pinned approvals need apm 0.37 or later on every machine. The first pinned approval prints `Teammates need APM 0.37 or later to read pinned approvals.`, and older clients reject the item form and fail closed.
- **Doc (0.39.3):** re-run `apm approve <package>` after reinstalling a package.
## Transitive MCP servers
- **Source:** `--trust-transitive-mcp` still exists in 0.39.3 as a per-run install flag that is never saved. **Doc:** it never overrides a deny or a mismatched pin.
- **Doc (0.37.0, #3918):** the durable replacement is `apm approve <pkg>`, with `apm.yml` committed.
- **Doc (0.39.0):** a server trusted in 0.38 only via the flag is parked and removed on the first plain 0.39 install. Approve it to keep it.
## Audit checks that enforce approvals (doc)
| Check | Fails when |
|---|---|
| `config-consistency` | The lock admits an MCP server that `apm.yml` does not approve: `admitted in apm.lock.yaml but not approved in apm.yml (<reason>); run 'apm approve <pkg>' and re-run 'apm install'`. Admission is re-evaluated from `apm.yml` and org policy only, never from the lock or the user store. |
| `hook-approval-pins` | A recorded deployed hook file no longer matches its pin; or an unrecorded file sits at a withheld package's hook path; or a merged-config entry matches such a package's hook with no ownership record. |
| `exec-status-current` | A recorded `exec_status` differs from the current gate decision. Claude `settings.json` hooks are included. Not evaluated under `--no-policy`. |
| `local-bundle-hooks` | A local-bundle hook entry was edited or is unrecorded. Needs the `.claude/apm-hooks.json` record. |
`apm install --frozen` fails on the same pin mismatches.
## `apm approve` and `apm deny`
- **Doc:** flags are `--pending`, `--all`, `--recommended`, `--list`, `--user`/`-g`.
- **Doc:** it exits 1 when:
- a requested package is not installed or is refused;
- the first-approval prompt is declined;
- a blocking org policy applies;
- installed files differ from `apm.lock.yaml`.
- **Source:** `apm deny [PACKAGES] --user/-g` writes deny entries.
## Observed on 0.39.3 (holocron#273)
Run with the repo-pinned apm 0.39.3 in a throwaway project, with a local `./pkg` dependency shipping one SessionStart hook.
- **No `executables:` block.** `apm approve --list` prints `Executable-trust gate disabled -- executables need no approval (org policy still applies)`, and the hook deploys (`hooks[+:gate-disabled]`).
- **Bare-name grant.** An allow key `pkg#1.0.0`, which is not the package identity `./pkg`, parks the hook: install prints `1 package(s) have executable primitives parked pending approval; install completed without deploying them`, deletes the previously deployed script, writes no `.claude/settings.json` entry and exits 0. `apm approve --list` shows `hooks[x:default-deny]`.
- **`#version` is ignored.** An allow key `./pkg#9.9.9` admits the installed `./pkg` at 1.0.0: the hook deploys and install exits 0.
- In this repo, the full-identity type-level grants deploy both hooks, and every install warns `executable approvals are not pinned to content`.
@@ -2,35 +2,151 @@
topic: cli-reference
source_keys:
- context7-microsoft-apm
- apm-v0-39-3-source
- apm-v0-39-3-docs
---
The command surface as of apm 0.39.3, read from source (`cli.py` and `commands/`) and the reference docs. Version-specific changes are summarized in `migration-0-28-to-0-39.md`.
## Command list (0.39.3, source)
`approve`, `audit`, `auth`, `cache`, `compile`, `config`, `deny`, `deps`, `doctor`, `experimental`, `export-patch`, `find`, `init`, `install`, `lifecycle`, `list`, `lock`, `marketplace`, `mcp`, `outdated`, `pack`, `plugin`, `policy`, `preview`, `prune`, `publish`, `run`, `runtime`, `search`, `self-update`, `targets`, `uninstall`, `unpack`, `update`, `view`.
There are also two hidden entries: `discover` (use the documented `apm init --discover` form) and `info`, an alias of `view`.
## Install
```bash
apm install [PACKAGE_REF...] [OPTIONS]
```
With no arguments, resolves and installs everything declared in `apm.yml` against `apm.lock.yaml`. Explicit `PACKAGE_REF` arguments (e.g. `acme/internal-tools#^1.0.0`) install and add that dependency. `apm install --update` re-resolves and accepts new upstream content even when it doesn't match the recorded lockfile hash (see troubleshooting). `apm install --target agent-skills` generates a vendor-neutral output directory for IDE-agnostic tool support instead of a harness-specific one.
- With no arguments, apm installs everything declared in `apm.yml` against `apm.lock.yaml`.
- Naming a `PACKAGE_REF` installs that package and adds it as a dependency.
- `--update` re-resolves the dependencies and accepts new upstream content.
- `--target agent-skills` produces a vendor-neutral output directory.
Frozen-install behaviour is in `lockfile-and-compatibility.md`.
Options (doc):
| Group | Options |
|---|---|
| Resolution and lockfile | `--update`, `--frozen/--no-frozen`, `--refresh`, `--accept-ref-change` |
| Run control | `--dry-run`, `--force`, `-v`, `--dev` |
| Scope and targets | `--root DIR`, `-t/--target`, `--runtime`, `--exclude`, `--only apm\|mcp`, `-g/--global`, `--legacy-skill-paths` |
| Policy and security | `--policy SOURCE`, `--no-policy`, `--audit off\|warn\|block`, `--no-audit` |
| Trust | `--trust-transitive-mcp`, `--trust-bin/--no-trust-bin` |
| Network and transport | `--allow-insecure`, `--allow-insecure-host`, `--parallel-downloads N`, `--ssh`, `--https`, `--allow-protocol-fallback`, `--auth-first` |
| Skill selection | `--skill`, `--as` |
| MCP | `--mcp`, `--transport`, `--url`, `--env`, `--header`, `--mcp-version`, `--registry` |
Exit codes (doc):
| Code | Meaning |
|---|---|
| 0 | Success or preview |
| 1 | Install failure. This includes frozen violations, and any reported error even with `--force`. |
| 2 | Usage error: no target detectable, `--ssh` with `--https`, `--frozen` with `--update`, or `--root` with `--global`. |
## Update and outdated
```bash
apm update [PACKAGES] [--yes] [--dry-run] [--verbose] [--global] [--force] [--target ...]
apm outdated [-g] [-v] [-j N]
```
**`apm update`** (source):
- `--check` is deprecated (doc). Use `--dry-run`, or `self-update --check` instead.
- Run outside an `apm.yml` project, bare `apm update` forwards to `self-update` with a warning (doc).
- `apm deps update` is deprecated in favour of `apm update`.
**`apm outdated`** (source):
- Options are `--global`, `--verbose` and `--parallel-checks/-j N` (default 4; 0 means sequential).
- There is no `--json` and no package filter.
- **Output:** a "Dependency Status" table with columns Package, Current, Wanted (only when registry rows exist), Latest, Status and Source.
- The summary line is `<N> outdated dependency found` or `<N> outdated dependencies found`, or `Some dependencies could not be checked`.
- Statuses in code are `up-to-date`, `outdated`, `unknown`, `origin-conflict`, `access-denied` and `not-comparable`.
- With `-v`, the table adds the newer tags.
- **Exit codes:** 1 on `origin-conflict` or `access-denied` (source); the docs also give 1 for no lockfile in scope. Outdated or unknown rows still exit 0.
- Local and Artifactory dependencies are skipped, and the command is read-only.
## Audit
```bash
apm audit # scan deployed files for hidden Unicode
apm audit --ci # CI gate: lockfile consistency, approvals, drift replay, policy
apm audit --file <path> # scan an arbitrary file
apm audit --ci -f json -o r.json
```
- **Options:** `--file`, `--strip`, `--dry-run`, `--no-drift`, `-v`, `--ci`, `--policy`, `--no-policy`, `--no-cache`, `--no-fail-fast`, `-f/--format text|json|sarif|markdown`, `-o/--output PATH`.
- When `-o` is given without `-f`, the format is inferred from the file extension.
- `markdown` is not allowed with `--ci`.
- **Exit codes in content-scan mode** (source docstring): 0 clean, 1 critical, 2 warnings only. The docs add 3 for configuration or infrastructure errors.
- **Exit codes in `--ci` mode:** 0 when every check passes, 1 when any fails.
- **Text output in `--ci` mode** (source):
- On success: `All <M> check(s) passed`.
- On failure: `<N> of <M> check(s) failed`, with each failure as `<check>: <message>` followed by detail lines.
- M varies with which checks apply; the list is in `migration-0-28-to-0-39.md`.
- **Lockfile message** (source): when `apm.yml` declares dependencies but there is no lock, the detail reads `apm.yml declares dependencies but apm.lock.yaml is absent`.
- Fail-fast is the default.
See `testing-and-validation.md` for CI wiring.
## Approve, deny and export-patch
```bash
apm approve [PACKAGES] [--pending|--all|--recommended|--list] [--user|-g]
apm deny [PACKAGES] [--user|-g]
apm export-patch [--out DIR] [--dry-run] [-v]
```
- Approvals are covered in `approvals-and-executables.md`.
- **`export-patch` (doc):**
- It writes one `patches/<pkg>@<ref>.patch` per package, ready for `git apply`, covering only files that were deployed verbatim.
- It needs a lockfile and a populated `apm_modules/`, and it runs cache-only.
- It exits 0 on success, including when there is nothing to export. It exits 1 on a missing manifest or lock, a cold cache, or an invalid `--out`.
## Compile
```bash
apm compile
apm compile [-t TARGET|--all] [--root DIR] [-o PATH] [--clean] [--validate] [--dry-run] [--watch] [-g]
```
Generates per-target output (Claude, Copilot, etc.) from the vendor-neutral `.apm/` primitive source tree, per the `compilation:` block in `apm.yml`.
- `apm compile` generates root context files (`AGENTS.md`, `CLAUDE.md`, `GEMINI.md`) from instructions.
- Other options: `--single-agents`, `--chatmode`, `--no-links`, `--with-constitution/--no-constitution`, `--local-only`, `--force-instructions` (alias `--no-dedup`) and `--legacy-skill-paths`.
- It exits 1 when org policy blocks a recorded package.
- A hand-authored root `CLAUDE.md` or `AGENTS.md` is never overwritten (source). For the 0.38/0.39 Claude layout, see `instructions-target-mapping.md`.
## Pack
```bash
apm pack --dry-run # resolve and print; do not write
apm pack --offline # cached refs only
apm pack --include-prerelease # allow pre-release tags
apm pack -v # per-entry resolution detail
apm pack --marketplace=claude --json # JSON output for CI pipelines
apm pack --dry-run # resolve and print; do not write
apm pack --check-versions --check-clean --dry-run
apm pack --format plugin # Claude Code plugin bundle (alias)
apm pack --marketplace=claude --json
```
Bundles a producer package into a distributable artifact.
- **Options (source):**
- `--claude-plugin`
- `--format plugin|agent-plugin|claude|claude-plugin|apm`. With no flag the default is `claude-plugin`. `plugin` is an alias for the Claude Code plugin bundle.
- `--target/-t`, which is deprecated and informational only.
- `--archive` (default `.zip`) with `--archive-format zip|tar.gz`.
- `-o`, `--dry-run`, `--force`, `-v`, `--offline`, `--include-prerelease`.
- `--check-versions`, `--check-clean`, `--strict-metadata`.
- `-m/--marketplace`, `--marketplace-path FORMAT=PATH`, `--json`, `--legacy-skill-paths`.
- **Exit codes (source):**
| Code | Meaning |
|---|---|
| 0 | Success |
| 1 | Build or runtime error |
| 2 | Usage error |
| 3 | `--check-versions` misalignment |
| 4 | `--check-clean` drift |
| 5 | `--strict-metadata` failure |
- `--check-clean` is read-only.
## Publish
@@ -39,17 +155,17 @@ apm publish --package acme/my-skill --dry-run -v
apm publish --package acme/my-skill
```
Publishes a producer package (root containing `apm.yml`, `.apm/`, and optionally a `registries:` block) to a registry. Always dry-run with `-v` first to see resolution detail before publishing for real.
`apm publish` sends a producer package to a registry. Always dry-run with `-v` first.
## Runtime management
```bash
apm runtime setup copilot # install with APM defaults
apm runtime setup codex --version 0.20.0 # pinned version
apm runtime setup llm --vanilla # skip APM-managed config
apm runtime list # what's installed
apm runtime status # which runtime `apm run` will pick
apm runtime remove gemini -y # uninstall without prompting
apm runtime setup copilot
apm runtime setup codex --version 0.20.0
apm runtime setup llm --vanilla
apm runtime list
apm runtime status
apm runtime remove gemini -y
```
## Run
@@ -58,42 +174,38 @@ apm runtime remove gemini -y # uninstall without prompting
apm run <script> [--param key=value]
```
Executes a named script defined under `scripts:` in `apm.yml`, with `--param` substituting values into the script's parameters (used, for example, when the script wraps a Gemini CLI invocation).
`apm run` executes a named script from `scripts:` in `apm.yml`. It is experimental.
## Audit (validation)
```bash
apm audit # local: scan deployed files for hidden Unicode
apm audit --ci # CI gate: lockfile consistency + drift replay + policy
apm audit --file <path> # standalone: scan an arbitrary file
```
See `testing-and-validation.md` for CI wiring and exit-code behavior.
## Marketplace
```bash
apm marketplace init # add the marketplace: block to apm.yml
apm marketplace check # validate every listed package ref resolves
apm marketplace package add <path> --name <n> # register a local package into the marketplace
apm marketplace add <source> [--name <n>] # register a marketplace as a consumer (see marketplace-and-registries.md for source forms)
```
## Plugin scaffolding
## Marketplace and plugin scaffolding
```bash
apm marketplace init
apm marketplace check
apm marketplace package add <path> --name <n>
apm marketplace add <source> [--name <n>]
apm plugin init <name> --yes
```
Scaffolds a new package's `apm.yml` + `.apm/` skeleton in the current directory.
- Marketplace subcommands (source): `add`, `list`, `browse`, `update`, `remove`, `validate`, `init`, `migrate`, `check`, `audit`, `outdated`, and `package add|set|remove`.
- `plugin` has only `init`.
- `apm init --plugin` and `apm init --marketplace` were removed in 0.37 and exit 2.
## Config
```bash
apm config set <key> <value>
apm config get <key>
apm config list
apm config unset <key>
apm experimental enable registries # required before registry.* config takes effect
apm experimental enable registries
```
Used for workstation-level settings such as private registry URLs/tokens (see `marketplace-and-registries.md`).
## Marketplace outputs and package-type routing (source, re-read under holocron#273)
- `apm_cli/marketplace/output_profiles.py` registers three marketplace output profiles in `MARKETPLACE_OUTPUTS`:
- `claude`, writing `.claude-plugin/marketplace.json`;
- `codex`, writing `.agents/plugins/marketplace.json`, which requires a `category` on every package;
- `copilot`, writing `.github/plugin/marketplace.json`.
apm 0.28.0 had only `claude` and `codex`.
- `get_effective_type()` in `apm_cli/integration/skill_package_routing.py` derives the content type from the detected package type: a Claude skill, hybrid, skill bundle or marketplace plugin routes as a skill, and everything else as instructions. It never reads the `type:` declared in `apm.yml`, as in 0.28.0.
@@ -3,6 +3,9 @@ topic: hooks-primitive-schema
source_keys:
- context7-microsoft-apm
- apm-github-repo
- apm-v0-39-3-source
- apm-v0-39-3-changelog
- apm-v0-39-3-docs
---
## File location, naming, and format — confirmed `.json`, not assumed
@@ -57,3 +60,25 @@ Differences from the Claude/source shape: flat arrays (no nested matcher-group w
- **Dropping a target from `apm.yml`'s `targets:` list does not auto-clean its merged hook entries** unless `apm install`/reconcile logic explicitly walks the complement set (`reconcile_dropped_targets`) — a real, documented gap the code works around rather than a design guarantee; relying on "just remove the target and hooks disappear" is not safe without a fresh `apm install`.
- **Event-casing mismatches are warnings, not errors** — a hook authored with the wrong casing for a target and no applicable rename mapping will silently not fire at runtime; APM only logs a warning at install time, it does not block the install or refuse to deploy the file.
- **No dedicated `Hook`/`HookPrimitive` validation dataclass** exists comparable to `Instruction.validate()` — validation is distributed across `_validate_copilot_payload` (Copilot-shape-specific) and general JSON-parseability checks, not a single primitive-level contract. This mirrors the same "no independent validation model" gap already documented for the agent primitive.
## Changes through 0.39.3 (source, CHANGELOG and docs; not run)
The sections above were written against 0.28.0. The merge into `.claude/settings.json` is still the mechanism in 0.39.3. The following changed:
- **Filename routing is gone (0.36.0, #3613).** Filenames such as `*-<target>-hooks.json` and `hooks-<target>.json` no longer send a hook to one target only, so every hook file reaches every targeted harness.
- To limit a hook to Claude, ship it in a package whose `apm.yml` sets `targets: [claude]`, or narrow the dependency with object-form `targets:`.
- If dropping the routing would hand a target a file the old name kept from it, install fails for that package and names the file.
- **Event names.** `SessionStart` and `sessionStart` both map to `SessionStart` for Claude. Copilot events that have a Claude equivalent are written to `.claude/settings.json` under the Claude name. For Copilot, `SessionStart` becomes `sessionStart`.
- **Where ownership is recorded.** apm marks its entries with `_apm_source` while it works. On write, it moves those markers into a sidecar, `.claude/apm-hooks.json`, so `settings.json` itself carries no apm markers. On reinstall the markers are read back from the sidecar.
- **Edited entries are kept (0.38.1, 0.39.0).**
- When a user edits a deployed entry, apm keeps the edited copy and writes the deployed entry beside it, with a warning. A byte-identical user copy does not count as an edit.
- Install exits 1 when an edited hook file or script blocks new content.
- Uninstall refuses when a package's entry was edited or its sidecar record is missing.
- **Ordering.** Entries merge in full-install order. Do not rely on order across packages. Your own entries never move.
- **Approval.** When the executables gate is on, a hook deploys only under a grant: type-level `hooks: true`, or a per-file content pin. A pin covers the hook JSON and every file deployed with it. See `approvals-and-executables.md`.
- **Command safety (0.39.0, #5600).** Only hook commands that stay inside the package and use no shell expansion are deployed. Shell expansion means `$(...)`, backticks, `eval`, here-docs and subshells.
- **Settings-file lifecycle.**
- A `.claude/settings.json` that apm created is deleted once its last entry leaves.
- An emptied one that apm has no creation record for is kept, with a warning.
- A hook config that is not valid JSON is never rewritten. A merge into it exits 1; a cleanup-only run warns and exits 0.
- **Audit.** These checks cover merged Claude hook entries: `hook-approval-pins`, `exec-status-current`, `local-bundle-hooks`, `content-integrity` and `drift`. `drift` compares only apm-owned entries. `apm install --frozen` also fails when an apm-managed merged entry was edited.
@@ -2,32 +2,85 @@
topic: installation
source_keys:
- context7-microsoft-apm
- apm-v0-39-3-docs
- apm-v0-39-3-source
- pypi-apm-cli
- apm-cli-0-39-3-uv-experiments
---
## Quick install (recommended)
## Install methods (0.39.3 docs)
A one-line install script auto-detects the platform, downloads the latest binary, and configures the system `PATH`:
- Quick install script. It auto-detects the platform, downloads the release binary and configures `PATH`:
```bash
curl -sSL https://aka.ms/apm-unix | sh
```bash
curl -sSL https://aka.ms/apm-unix | sh
```
On Windows use `irm https://aka.ms/apm-windows | iex`.
- Homebrew: `brew install apm`, from the core formula. The old `microsoft/apm` tap is migrated.
- WinGet: `winget install --id Microsoft.APM --exact --source winget`.
- Scoop: `scoop install apm`.
- pip: `python3 -m pip install apm-cli`. Since 0.36.0 this needs Python 3.11 or later, and the same floor applies to any Python-based install.
- Manual binary: download the release archive and put the binary on `PATH`. Prebuilt binaries cover macOS, Linux and Windows on x86_64 and ARM64.
The installation doc mentions neither pipx nor uv. If no prebuilt binary fits, the installer script falls back to `pip install --user apm-cli`.
`apm self-update` upgrades a script install. The installer refuses to overwrite a copy owned by Homebrew or pip.
The docs give glibc 2.28 as the Linux minimum for the binary, but the 0.32.0 installer notes say 2.38. This conflict is unresolved; use pip if in doubt.
## Package facts (PyPI and source)
- The package is `apm-cli`, and its console entry point is `apm = apm_cli.entrypoint:main`. It needs Python 3.11 or later.
- 0.39.3 was released 2026-12-01 as a wheel and an sdist, and 0.39.2 on 2026-11-30. Neither is yanked.
- Runtime dependencies:
- click, colorama, pyyaml, requests, truststore
- python-frontmatter, llm, llm-github-models
- toml, tomlkit, rich, rich-click
- watchdog, GitPython, ruamel.yaml, filelock
- websockets (below 17)
A full resolve came to about 63 packages.
## Pinning a version
- Script: `curl -sSL https://aka.ms/apm-unix | sh -s -- @v1.2.3`, or set `VERSION=v1.2.3`. On Windows, set `$env:VERSION` before the `irm` line.
- pip: `pip install apm-cli==0.39.3`.
- GitHub Action: `microsoft/apm-action@v1` with `setup-only: 'true'` and `apm-version: '<version>'`.
- The docs give no pinning method for Homebrew, WinGet or Scoop.
- Upstream advice: pin a **minimum** apm in CI rather than an exact one. Choose a release that reads your lockfile format, which means 0.39.2 or later for v4 locks rewritten by 0.39.2. apm has no manifest field that enforces a minimum. See `lockfile-and-compatibility.md`.
## Per-project pin with uv (tested, not upstream-documented)
apm's docs do not cover this. It was tested with uv 0.11.24 in a throwaway project outside any repo.
```toml
[project]
name = "<project>"
version = "0.0.0"
requires-python = ">=3.11"
dependencies = []
[tool.uv]
package = false
[dependency-groups]
dev = ["apm-cli==0.39.3"]
```
On Windows, the installer adds both the current directory and the bin directory to `PATH`, so it works from native shells, Git Bash, and process APIs alike.
## Customizing the install
- **Pin a specific version**: append `@vX.Y.Z` to the piped script arguments, e.g. `curl -sSL https://aka.ms/apm-unix | sh -s -- @v1.2.3`.
- **Custom install directory**: set `APM_INSTALL_DIR` on the piped script's command, e.g. `curl -sSL https://aka.ms/apm-unix | APM_INSTALL_DIR=$HOME/.local/bin sh`.
- **Air-gapped / GitHub Enterprise mirror**: set `GITHUB_URL` and `VERSION` env vars against a local `install.sh`, e.g. `GITHUB_URL=https://github.corp.com VERSION=v1.2.3 sh install.sh`.
## Alternative install methods
- **pip**: `pip install apm-cli` — requires Python 3.10 or higher.
- **Manual binary**: download the platform-specific archive from the GitHub releases page, extract it, move the binary to a permanent directory, and add that directory to `PATH`.
- With no `[build-system]`, uv installs only the dependencies and never builds the project. `package = false` keeps it that way even if a build system is added later. `uv sync` installs the `dev` group by default.
- `uv run apm --version` reported 0.39.3. The committed `uv.lock` hashes apm-cli and every transitive dependency.
- **Offline behaviour:**
- `uv run --frozen --offline apm ...` worked once the uv cache was warm, even with no `.venv`.
- It failed with an empty cache, because wheels cannot be downloaded offline.
- So the first sync on a machine needs the network.
- **Rejected alternatives:**
- `uvx apm-cli@<v>` pins only apm-cli: transitive dependencies float and nothing is locked. A cache warmed by `uv add` also did not satisfy `uvx --offline`.
- `uv tool install` is machine-global, the same drift problem as pipx.
## Installing agent runtimes
APM itself doesn't execute agents, but it can install and manage the runtimes that do, via `apm runtime setup <name>`:
apm does not run agents itself, but it can install and manage the runtimes that do:
```bash
apm runtime setup copilot # recommended default
@@ -36,4 +89,4 @@ apm runtime setup gemini
apm runtime setup llm
```
Installing GitHub Copilot CLI through APM pulls it from the public npm registry and requires Node.js v22+ and npm v10+; no authentication is needed for the install step itself. Use `apm runtime list` to see which runtimes are currently installed and which one `apm run` will pick by default.
Installing the GitHub Copilot CLI through apm pulls it from the public npm registry. It needs Node.js 22 or later and npm 10 or later. `apm runtime list` shows which runtimes are installed and which one `apm run` picks.
@@ -6,9 +6,11 @@ source_keys:
- claude-code-memory-docs
- cursor-rules-docs
- github-copilot-custom-instructions-docs
- apm-v0-39-3-changelog
- apm-cli-0-39-3-experiments
---
Surprising behaviours and source contradictions for the instructions primitive. "Verified" means observed with the installed apm 0.28.0 in a throwaway directory outside the repo. Everything else is stated as sourced or inferred.
Surprising behaviours and source contradictions for the instructions primitive. The section "Re-run on 0.39.3" at the end records what changed when the experiments were repeated on the repo-pinned apm 0.39.3; where it disagrees with an earlier section, it wins. "Verified" means observed with the installed apm 0.28.0 in a throwaway directory outside the repo. Everything else is stated as sourced or inferred.
## Verified failure modes
@@ -78,7 +80,7 @@ An earlier version of this topic's schema file described missing `description` a
- Runtime behaviour of Windsurf, Kiro and Antigravity on the emitted frontmatter; no downstream docs were fetched.
- Windsurf user-scope global rules.
- The Context7 step was unavailable (invalid API key), so the registry carries no fresh Context7 pull. Doc pages were summarised by a smaller model before reaching this file and can be lossy.
- Apm versions other than 0.28.0 were not tested.
- Apm versions other than 0.28.0 were not tested. 0.38.0 and 0.39.0 changed the Claude layout, moving `**`- and directory-scoped rules into `AGENTS.md` once compiled. The `.claude/rules/` items above may therefore not hold on 0.39.x. See `instructions-target-mapping.md`, "Claude layout in 0.38 and later", and `migration-0-28-to-0-39.md`.
## What belongs in an instruction body
@@ -90,3 +92,17 @@ From the Claude Code memory docs (`claude-code-memory-docs`): instructions reach
- Something that must happen at a fixed point (before every commit) or must be blocked is a hook or a `permissions.deny` entry, never an instruction: "Settings rules are enforced by the client regardless of what Claude decides to do. CLAUDE.md instructions shape Claude's behavior but are not a hard enforcement layer."
- Two instructions that contradict each other make Claude pick one arbitrarily, across user and project files and across rules.
- Under 200 lines per file; one topic per file.
## Re-run on 0.39.3 (holocron#273)
Observed with the repo-pinned apm 0.39.3 in throwaway packages outside the repo.
- **Unquoted or broken frontmatter fails install.** `applyTo: **/*.py` unquoted, or `description: [broken`, makes `apm install` exit 1 with `Rejected frontmatter in <file>` and deploy nothing. No transaction change is committed. Compile still prints `Failed to parse`, skips the file and exits 0; `--validate` counts it out. The silent widening above no longer happens on install.
- **Claude compile layout.** `apm compile --target claude` writes `AGENTS.md` with the instruction bodies and a `CLAUDE.md` that holds only `@AGENTS.md` under the generated header. Compile also warns `applyTo for '<name>' matched no files` when a pattern matches nothing in the project.
- **Dedup is per instruction.** Compile omits only the instructions already deployed to `.claude/rules/`. A nested or newly added instruction still reaches `AGENTS.md`, and when every instruction is deployed no `CLAUDE.md` is written. `--force-instructions` puts all of them in. When the compile also serves a target with no dedup (codex), `AGENTS.md` carries every instruction.
- **Unscoped rules move to `AGENTS.md` only when compile wrote them there.** Install deploys an unscoped rule to `.claude/rules/<n>.md` with no frontmatter, and a later compile dedups it, so it stays. It moves only when compile actually wrote it into `AGENTS.md`: compile before install, `--force-instructions`, or a no-dedup target in the same compile. The next install then deletes that file and prints `Retired .claude/rules/<n>.md: AGENTS.md now carries it for Claude Code`. A `**/*.py` rule stays in `.claude/rules/`.
- **Hand-authored collisions are skipped on Claude too.** A hand-written `.claude/rules/<n>.md` or `.github/instructions/<n>.instructions.md` is kept, with `files skipped -- local files exist, not managed by APM`, exit 0. `apm install --force` overwrites it. The 0.28.0 silent overwrite on Claude is gone.
- **Stale cleanup covers every rule target.** Renaming a source deletes the old file on antigravity, claude, copilot, cursor, grok-build, kiro and windsurf.
- **Per-target transforms.** Unchanged from 0.28.0 except: Cursor writes several patterns as one comma-separated `globs:` string, not a list; Antigravity writes `trigger: always_on` for an unscoped rule.
- **Empty package.** With no `.apm/` content, plain compile exits 1 with `No APM content found to compile`. With skills but no instructions it is still `No instruction files found in .apm/ directory`, exit 1. `--clean` exits 0 in both.
- **Unchanged:** `--validate` hides the warnings a real compile prints; a nested file is compiled but never deployed; `description` is dropped on Claude.
@@ -6,10 +6,27 @@ source_keys:
- claude-code-memory-docs
- github-copilot-custom-instructions-docs
- cursor-rules-docs
- apm-v0-39-3-source
- apm-v0-39-3-changelog
- apm-v0-39-3-docs
---
What each target receives from an instruction file, at install time (native per-file deploy) and at compile time (folded into a root context file). Verified against apm 0.28.0 source and throwaway installs unless marked otherwise. Field syntax of the source file is in `instructions-primitive-schema.md`.
## Claude layout in 0.38 and later (source and CHANGELOG; not run)
The install table below is the 0.28.0 behaviour, where every Claude instruction went to `.claude/rules/`. Two later releases changed that.
- **0.38.0:** Claude instructions scoped to `**`, unscoped, scoped to `**/*`, or scoped to exactly one literal `dir/**` glob move into `AGENTS.md`, which `CLAUDE.md` imports. Run `apm install` and then `apm compile`. Any other glob stays a path-scoped rule in `.claude/rules/`, including file-type globs, wildcard directories and lists.
- **0.39.0 (#5394):** install-only projects keep the 0.37 `.claude/rules/` layout. A routed instruction is dropped from `.claude/rules/` only once a compiled `AGENTS.md` that Claude loads already carries its exact scope and body. Until then, install keeps the rule and asks for `apm compile`.
- **Blockers.** These keep every instruction in `.claude/rules/`, with a warning:
- a hand-authored root `CLAUDE.md` without an `@AGENTS.md` (or `@./AGENTS.md`) import;
- a hand-authored root `AGENTS.md` without `compilation.agents_md.mode: managed_section` and a single pair of `<!-- apm:start -->`/`<!-- apm:end -->` markers;
- a symlinked root `AGENTS.md`.
- **Hand-authored files are protected.** A root `AGENTS.md`, `CLAUDE.md` or `GEMINI.md` without the apm-generated marker near the top is never overwritten. `--clean` never deletes an unmarked `CLAUDE.md`, and a compile with no primitives writes nothing. The one opt-in exception is `managed_section` mode, which writes only between the markers. If the user's `CLAUDE.md` already imports `@AGENTS.md`, compile leaves it untouched.
- **Scope limits.** User scope (`-g`) and a home-rooted project never route to `AGENTS.md`.
- **Claude Code version.** The source notes that Claude Code 2.1.277 and later read `AGENTS.md` natively, but only while no `CLAUDE.md` exists or the `CLAUDE.md` imports `@AGENTS.md`.
## Two separate output paths
`apm install` writes native files, one per instruction, into each target's own rules directory. `apm compile` writes root context files (`CLAUDE.md`, `AGENTS.md`, `GEMINI.md`) that concatenate instruction bodies. The two overlap, which is why compile has a dedup rule (below). A skill author should treat install as the primary path for Claude Code and Copilot, and compile as the path for targets that have no native instructions directory.
@@ -80,4 +97,4 @@ Keys: `target`, `strategy` (`distributed` or `single-file`), `single_file`, `out
### Relevant compile flags
`--validate` (parse only; see schema file for why it is a weak check), `--dry-run`, `--clean` (removes orphaned generated files, never hand-authored ones), `--target`, `--all`, `--root`, `-g`, `--local-only`, `--single-agents`, `--no-links`, `--with-constitution`, `--force-instructions`. Documented exit codes: 0 success, 1 error, 2 conflicting flags. A compile with no instruction primitives at all exits 0 in 0.28.0.
`--validate` (parse only; see schema file for why it is a weak check), `--dry-run`, `--clean` (removes orphaned generated files, never hand-authored ones), `--target`, `--all`, `--root`, `-g`, `--local-only`, `--single-agents`, `--no-links`, `--with-constitution`, `--force-instructions`. Documented exit codes: 0 success, 1 error, 2 conflicting flags. A compile with no instruction primitives at all exits 0 in 0.28.0. In 0.39.3 it also exits 1 when org policy blocks a recorded package.
@@ -0,0 +1,97 @@
---
topic: lockfile-and-compatibility
source_keys:
- apm-v0-39-3-source
- apm-v0-39-3-changelog
- apm-v0-39-3-docs
---
Lockfile format, cross-version compatibility, frozen installs and ref resolution as of apm 0.39.3. Read from the v0.39.3 source, its CHANGELOG and its docs. Nothing here was run against a real project. Each claim is marked **source** (read in code) or **doc** (docs or CHANGELOG only).
## Lockfile versions
- **Source:** the supported versions are `"1"` to `"4"`. Anything else is refused before any file changes, with `Unsupported lockfile version '<v>'; supported versions: 1, 2, 3, 4` plus a `apm self-update` hint.
- **Doc:** the bump depends on content:
- `"4"` when any package records a `content_hash`;
- else `"3"` when a root `replacements` table exists;
- else `"2"` for registry or semver evidence;
- else `"1"`.
- **Doc:** v4 adds no fields. It only changes how `content_hash` is computed. Each file, in sorted path order, contributes its path, a NUL byte and the SHA-256 of its raw bytes; v1-v3 keep the older stream. **Source:** both digests exist and are selected per lock version.
- **Doc:** 0.37+ verifies a v1-v3 lock as written:
- A writable `apm install` promotes the lock to `"4"` once every package re-hashes from verified bytes.
- `apm install --frozen`, `apm audit` and other read-only commands never promote or rewrite it.
- **Doc:** a lockfile with invalid YAML, a non-mapping root or malformed rows fails closed.
- **Doc (0.39.0):** the lock is parsed with libyaml, so a hand-edited lockfile with nonstandard YAML may now be rejected. Regenerate it with `apm install`.
## Which apm reads which lock
| Lock | Refused by | Read by |
|---|---|---|
| v1-v3 written by 0.28.0 | nothing current | 0.37+ reads as written; a writable install promotes to v4 |
| v4 written by 0.37.0-0.39.1 | 0.36.1 and older | 0.37.0+ |
| v4 rewritten by 0.39.2+ | 0.36.1 and older, and 0.37.0-0.39.1 (they refuse any lock from a newer apm) | 0.39.2+ |
Practical rule: once a lock written by 0.39.2 or later is committed, every machine that runs install or audit on it needs 0.39.2 or later. Upgrade CI and update bots first.
## The 0.39.2 compatibility promise (doc, warning text confirmed in source)
From 0.39.2, the `lockfile_version` decides compatibility, not `apm_version`.
- A lock written by a newer apm in a format this apm reads runs normally. The only difference is one `[!]` line on stderr per process: `apm.lock.yaml was written by APM <x>, newer than this APM <y>. Its format (lockfile_version 4) is supported, so APM continues and keeps fields it does not know.`
- Unknown fields survive a rewrite, with exceptions:
- A dependency row's unknown fields are dropped when its commit, hash, version, `content_hash` or `source_digest` changed.
- A deployment row's unknown fields are dropped when its `content_hash` or owner changed.
- Top-level unknown fields are dropped when any dependency changed.
- `x-*` top-level keys are always kept.
- Refused with exit 1 before any change:
- an unsupported `lockfile_version`;
- an unknown deployment `kind`;
- an unknown value in a known enum field (`exec_status`, `host_type`);
- a duplicated `apm_version` or `lockfile_version` key.
- No-op runs leave the lockfile byte-identical, and apm never switches its own version.
- Read support for a new format ships at least eight weeks before any release writes it.
**`apm audit --ci` is stricter than install.** It fails with exit 1 when the lock records fields this apm does not know (other than `x-` keys): `'apm audit --ci' cannot certify apm.lock.yaml: it was written by APM <x>, newer than this APM <y>, and it records fields this APM does not know: <names>. Nothing was changed.` In JSON or SARIF output this is a failed check named `lockfile-fields-certifiable`. Plain `apm audit` only warns. Consequence: the apm that runs `audit --ci` must be at least as new as the newest apm that writes the lock.
## Minimum-version advice (doc)
apm has no manifest field for a required or minimum apm version. The upstream advice is to "pin a minimum APM in CI, not an exact one". The minimum should be a release that reads the lock format: 0.39.2 or later in the docs' own example. Version pinning therefore lives outside `apm.yml`, in whatever installs apm.
## `apm install --frozen`
- **Doc:** requires `apm.lock.yaml`, replays its pins, and never writes the lock (since 0.34.0).
- **Doc:** in CI (env `CI` set to anything but empty, `0` or `false`), `apm install` with a committed lock behaves like `--frozen` (0.37.0). `--no-frozen` opts out, and is the recommended form for update bots.
- **Doc:** mutually exclusive with `--update`, positional package additions and `--mcp`. Passing `--frozen --update` is a usage error (exit 2).
- **Doc:** fails (exit 1) before the pipeline on:
- a missing lock (a no-op when nothing is declared);
- a direct dependency missing from the lock;
- changed refs or commit pins;
- a host, provider or transport mismatch;
- MCP declaration mismatches;
- an MCP server the lock admits but `apm.yml` does not approve;
- hook approval pin mismatches.
- **Doc:** hash enforcement:
- Since 0.36.0, every deployed file is compared with its locked hash, and since 0.37.0 this happens before anything deploys. A mismatch exits 1.
- Since 0.39.x, it also fails when an apm-managed entry inside a merged hook config, such as `.claude/settings.json`, was edited.
- Recovery: restore or delete the edited file or entry, run `apm install` without `--frozen`, and commit. To keep edits made to a dependency's files, export them first with `apm export-patch`.
- **Doc:** after the pipeline, `--frozen` also checks for unrecorded files, missing files, a stale executables decision, and hash drift. `generated_at` and `apm_version` are excluded from the comparison.
## Exact dependency refs (0.39.0, #4970)
- **Source:** a dependency `ref` resolves only to `refs/heads/<ref>` or `refs/tags/<ref>`, or to itself when spelled out in full under one of those. There is no tail match and no fallback, so a ref that only partly matches a branch or tag name is refused.
- When a ref names both a branch and a tag, the error says it is ambiguous; spell it as `refs/heads/<name>` or `refs/tags/<name>`.
- When it names neither: `it is not a branch or tag of the origin`.
- An abbreviated SHA the host cannot expand is refused. Use the full 40 characters.
- **Source:** a pinned commit, whether a `#sha` ref or a locked commit, is admitted only if an origin branch or tag reaches it. A commit reachable only from a PR or a fork is refused.
- The fast path is a branch or tag tip, found with one `ls-remote`. Otherwise apm does a commits-only fetch of heads and tags.
- The verdict is cached in local state, never in the lockfile, so later replays work offline.
- **Source/doc:** the first install of a pinned commit needs the network. Offline, it fails closed with `the first install of a pinned commit needs network access once`.
- **Source:** Artifactory routes are exempt and resolve by name.
## Commit verdicts after an upgrade (0.39.0, #5173)
**Source:** reachability verdicts live in a new cache namespace (`verified-v2`), and verdicts recorded by earlier builds are never read. After upgrading, run each install online once before relying on offline or locked replays.
## Helper tools resolve from PATH (0.39.0)
**Doc:** apm's helper tools (`git`, `az`, `npm` and others) and the setup scripts it runs resolve programs only from PATH entries outside the project. This does not affect your own scripts.
@@ -0,0 +1,88 @@
---
topic: migration-0-28-to-0-39
source_keys:
- apm-v0-39-3-changelog
- apm-v0-39-3-source
- apm-v0-39-3-docs
---
This page lists the breaking and behaviour-changing items between apm 0.28.0, the version the rest of this reference set was first verified on, and 0.39.3. Use it to decide which "verified on 0.28.0" claims elsewhere need re-checking. Every item comes from the CHANGELOG, with source confirmation where it says **source**. None of it was run against a real project.
## Versions and runtime
- **0.36.0:** pip, pipx and uv installs need Python 3.11 or later. Standalone binaries are unaffected.
- **0.37.0:** the lockfile moves to format v4. 0.36.1 and older refuse it. See `lockfile-and-compatibility.md`.
- **0.39.2:** 0.37.0-0.39.1 refuse a lock that 0.39.2 rewrites. From 0.39.2, a lock written by a newer apm in a supported format only warns. 0.39.2 is therefore the practical minimum.
## Manifest and targets
- **0.29.0:** a plugin's `skills` declaration exclusively controls which skills deploy. `"skills": []` deploys none, and removing the key keeps conventional `skills/` discovery.
- **0.31.0:** a non-dry-run `apm install` exits 1 when Agent Plugins v1 target exclusion leaves no package deployed.
- **0.32.0:** `apm install` rejects bare `.` or `..` aliases and unsafe symlink destinations.
- **0.37.0:**
- The `vscode` target is deprecated in favour of `copilot`.
- The singular `target:` key is replaced by `targets:`, and `compilation.target` is ignored. Both still work, with warnings.
- Copilot project MCP servers move to a root `.mcp.json`.
- The `auto-integrate` config key is removed.
- With `default_host:` set, shorthand dependencies resolve against it.
- **Source:** `KNOWN_TARGETS` has 17 keys: agent-skills, antigravity, claude, codex, copilot, copilot-app, copilot-cowork, cursor, gemini, grok-bot, grok-build, grok-cloud, hermes, kiro, openclaw, opencode and windsurf. `vscode` is not among them.
- **0.39.0 (#4970):** a dependency `ref` must exactly name an origin branch or tag, and pinned commits must be reachable from one. See `lockfile-and-compatibility.md`.
## Install, lockfile and audit
- **0.34.0:** `apm install --frozen` no longer writes the lock.
- **0.36.0 (#3654):** `--frozen` verifies every deployed file against its locked hash. Before reinstalling, export your edits with `apm export-patch`.
- **0.37.0:**
- In CI, `apm install` with a committed lock verifies like `--frozen`. Use `--no-frozen` to opt out.
- `--frozen` fails before deploying on any edited deployed file.
- **0.38.0:** a failed or interrupted install restores every file it wrote. Install refuses managed files that lack deployment evidence.
- **0.39.0:**
- The lock is parsed with libyaml.
- Reachability verdicts are recorded anew, so run one online install after upgrading.
- Helper tools resolve only from PATH entries outside the project.
- **0.39.2:** `apm audit --ci` fails on lock fields this apm does not know.
- **0.39.3:** outside CI, the first `apm install --frozen` after an `apm install` takes a verified fast path.
- **Audit checks:** the baseline set has grown, so the total behind `N of M check(s) failed` is not fixed (**source**).
- Baseline: `manifest-parse`, `manifest-missing`, `lockfile-exists`, `ref-consistency`, `deployment-ledger-owners`, `deployed-files-present`, `exec-status-current`, `no-orphaned-packages`, `lockfile-targets-current`, `skill-subset-consistency`, `config-consistency`, `native-mcp-ownership`.
- Conditional: `native-mcp-drift` and `kept-mcp-entries`.
- Always on: `content-integrity`, `local-bundle-hooks`, `hook-approval-pins`, `includes-consent` (advisory), and `drift`.
## Executables and approvals
- **0.37.0 (#3918):** `apm audit --ci` fails MCP servers the lock admits but `apm.yml` does not approve. Use `apm approve <pkg>` instead of `--trust-transitive-mcp`.
- **0.37.0:** approvals can be pinned to content. Older clients reject pinned approvals.
- **0.38.0 (#4688):** a hook pin covers every file deployed with the hook. Re-approve hook packages once.
- **0.38.1:** `apm audit --ci` fails on merged hook entries that match a denied or unapproved package's hook and have no ownership evidence.
- **Ordinary grants stay version-blind (source).** A `hooks: true` grant keyed `pkg#1.2.3` still matches any version. See `approvals-and-executables.md`.
## Hooks
- **0.36.0 (#3613):** hook filenames no longer route hooks to targets, so every hook file reaches every targeted harness. To limit a hook to one target, declare `targets:` in the package `apm.yml`, or narrow the dependency with object-form `targets:`. When the old routing kept a target from a file, install fails for that package and names the file.
- **0.36.0:** Copilot hook events that have a Claude equivalent are written to `.claude/settings.json` under the Claude name.
- **0.38.1 and 0.39.0:**
- Edited hook entries and scripts are kept. Install exits 1 when an edited one blocks new content.
- A `.claude/settings.json` that apm created is deleted when its last entry leaves. One that apm did not create is kept, with a warning.
- Hooks merge in full-install order.
- **0.39.0 (#5600):** only hook commands that stay inside the package and use no shell expansion are deployed. Shell expansion means `$(...)`, backticks, `eval`, here-docs and subshells.
## Prompts and commands
- **0.39.0 (#4910 and others):** on the Claude target, apm keeps Claude Code command keys:
- `when_to_use`, `disable-model-invocation`, `user-invocable`, `disallowed-tools`, `effort`;
- `context`, `agent`, `background`, `shell`.
`hooks` is still withheld, with a warning. In 0.28.0 only `description`, `allowed-tools`, `model`, `argument-hint` and `input` survived. See `prompt-primitive-schema.md`.
- **0.39.0:** the dropped-keys message is shown only with `--verbose`. It is an info message, not a warning.
## Instructions and root context files
- **0.38.0:** Claude instructions scoped to `**` or to a directory move from `.claude/rules/` into `AGENTS.md`, which `CLAUDE.md` imports. A hand-authored `CLAUDE.md` needs `@AGENTS.md`.
- **0.39.0 (#5394):** install-only projects keep the 0.37 `.claude/rules/` layout. A hand-authored root `CLAUDE.md` without the import, or a hand-authored `AGENTS.md` without managed-section markers, keeps every instruction in `.claude/rules/`, with a warning. See `instructions-target-mapping.md`.
## CLI
- **0.36.0:** `apm export-patch` is added.
- **0.37.0:** `apm init --plugin` and `apm init --marketplace` exit 2. Use `apm plugin init` or `apm marketplace init` instead.
- **0.37.0:** approvals are pinned to content, and `apm approve` and `apm deny` manage them.
- **`apm outdated`:** still has no `--json`. Its summary line `<N> outdated dependency/dependencies found` is unchanged in source. Its columns are Package, Current, Wanted (registry rows only), Latest, Status and Source.
- **`apm audit`:** supports `-f text|json|sarif|markdown` and `-o PATH`. JSON is the stable machine format. `markdown` is not allowed with `--ci`.
@@ -7,11 +7,14 @@ source_keys:
- apm-docs-cli-run
- apm-docs-cli-compile
- apm-cli-0-28-0-prompt-experiments
- apm-v0-39-3-source
- apm-v0-39-3-changelog
- apm-cli-0-39-3-experiments
---
## What this covers
Constraints that surprise a prompt author. Items are marked **observed** when they were reproduced on the installed apm 0.28.0 in a throwaway project with local-path packages, and **doc** when they come only from the published docs. Where an observation disagrees with a doc statement, the observation wins and the disagreement is noted. Claude Code, Cursor and Gemini runtime behaviour on the emitted files was not tested.
Constraints that surprise a prompt author. **Version note:** every **observed** item below was observed on apm 0.28.0 and has not been re-run on 0.39.x. The changes known from the 0.39.3 source and CHANGELOG are listed under "Changed in 0.39.x" at the end. Items are marked **observed** when they were reproduced on the installed apm 0.28.0 in a throwaway project with local-path packages, and **doc** when they come only from the published docs. Where an observation disagrees with a doc statement, the observation wins and the disagreement is noted. Claude Code, Cursor and Gemini runtime behaviour on the emitted files was not tested.
## Discovery
@@ -72,3 +75,27 @@ Parameters are interpolated into any `.prompt.md` the script references and are
## Not tested
The experimental targets (hermes, openclaw, copilot-cowork, grok-cloud, copilot-app), because enabling them writes global config. Claude Code, Cursor and Gemini runtime handling of the emitted files.
## Changed in 0.39.x (from source and CHANGELOG, not observed)
- On the `claude` target the Claude-native command keys are kept rather than dropped:
- `when_to_use`, `disable-model-invocation`, `user-invocable`, `disallowed-tools`, `effort`;
- `context`, `agent`, `background`, `shell`.
So the 0.28.0 drop list above (which named `agent`) no longer holds for Claude. Cursor, OpenCode, Windsurf and grok-build still drop these keys. See `prompt-primitive-schema.md`.
- The dropped-keys message is an info line shown only with `--verbose`, so a default install no longer reports dropped keys at all.
- Frontmatter `hooks` on a command is withheld with a warning.
- A non-string frontmatter key (for example `1:`) skips that one command with a warning, and the other commands still install.
- Hidden-Unicode, collision and stale-cleanup behaviour were not re-checked. 0.38 and 0.39 changed how edited deployed files are kept (see `migration-0-28-to-0-39.md`), so the "hand-edited file is silently overwritten" item above is likely stale.
## Re-run on 0.39.3 (holocron#273)
Observed with the repo-pinned apm 0.39.3 in throwaway packages outside the repo. Where this disagrees with the sections above, it wins.
- **Claude-native keys.** `disable-model-invocation`, `when_to_use`, `user-invocable` and `effort` reached `.claude/commands/<n>.md`. Cursor and OpenCode dropped them. `author` and `mcp` were dropped everywhere but Copilot.
- **Dropped-keys message.** Printed only with `--verbose`, as an info line naming the dropped keys and the target's supported set. A default install says nothing about them.
- **`hooks`** in a prompt's frontmatter is withheld on Claude with a `frontmatter hooks withheld` warning, and the command still deploys.
- **Kiro now receives prompts**, at `.kiro/prompts/<n>.md` with every frontmatter key stripped and a warning naming them. Codex, Antigravity and agent-skills still deploy nothing, silently.
- **Hand-edited deployed files.** Editing `.claude/commands/<n>.md` and reinstalling after a source change makes install exit 1 with `Kept ... it was modified since APM deployed it`, and nothing is committed. Removing the source keeps the edited file with a warning and cleans the others.
- **Hidden characters.** A tag character makes install exit 1 with nothing written on any target. `--force` exits 0 and writes the Copilot copy and Gemini TOML, but still withholds the Claude command. A zero-width space warns and deploys.
- **Unchanged:** compile ignores prompts; `--validate` counts none; malformed YAML skips the command with a warning; an invalid input name is rejected with a warning and duplicates pass; a hand-written file at a deployed path is skipped until `--force`; `input:` becomes `arguments:`; Gemini keeps `description` and the body, and prepends `Arguments: {{args}}` to a body using `$0`.
@@ -5,9 +5,26 @@ source_keys:
- apm-github-repo
- apm-docs-author-prompts
- apm-docs-llms-full
- apm-v0-39-3-source
- apm-v0-39-3-changelog
---
Per-target output, key survival and the doc inconsistencies are in `prompt-target-mapping.md` and `prompt-gotchas.md`. The published "Author a prompt" page lists five preserved keys: `description`, `input`, `allowed-tools`, `model`, `argument-hint`. Where the section below says four keys are preserved, read that as four plus `input`, which is consumed into `arguments:` on Claude. Both the page and the installed 0.28.0 source agree on this set.
Per-target output, key survival and the doc inconsistencies are in `prompt-target-mapping.md` and `prompt-gotchas.md`.
**Version note.** This file was first verified on apm 0.28.0. The Claude key set changed in 0.39.0; the section "Claude command keys in 0.39.x" below is the current behaviour, read from the v0.39.3 source. In 0.28.0 the shared set was five keys: `description`, `input`, `allowed-tools`, `model`, `argument-hint`, where `input` is consumed into `arguments:` on Claude. Every other key was dropped on every Claude-family target.
## Claude command keys in 0.39.x
- **Shared keys, kept on every Claude-family target:** `description`, `allowed-tools` (alias `allowedTools`), `model`, `argument-hint` (alias `argumentHint`), `input`.
- **Claude-native keys, kept only when the target is `claude`:**
- `when_to_use`, `disable-model-invocation`, `user-invocable`, `disallowed-tools`, `effort`;
- `context`, `agent`, `background`, `shell`.
Cursor, OpenCode, Windsurf and the other targets that reuse the command transformer still drop them.
- **`arguments`:** an authored `arguments` is kept verbatim only on Claude, and only when the file has no `input` key at all. An `input` key always wins, even when it is empty or every name in it was rejected.
- **`hooks`:** withheld on purpose. The command is deployed without its hooks, and install warns `frontmatter hooks withheld`. apm does not yet run command hooks through its executable-approval gate.
- **Other keys:** still dropped. The dropped-keys message is now an info line shown only with `--verbose`, no longer an always-on warning.
- **Consequence:** a prompt with `disable-model-invocation: true` deploys with that key to `.claude/commands/<name>.md` on 0.39.0 and later. 0.28.0 silently stripped it.
## File location, naming, and frontmatter
@@ -33,7 +50,7 @@ There is no single closed frontmatter schema — APM's P1 "no invented primitive
**Claude Code target — real reconstruction into a slash command, with field-dropping.** There is no `prompts:` key at all in Claude's `TargetProfile.primitives` dict; instead prompts route through the shared `CommandIntegrator`, which transforms `.prompt.md` → Claude custom slash command markdown. `CommandIntegrator._transform_prompt_to_command()`:
- Strips the `.prompt.md` suffix from the filename to derive `command_name`.
- Builds an entirely new frontmatter object containing **only** these preserved keys: `description`, `allowed-tools` (accepts `allowedTools` alias), `model`, `argument-hint` (accepts `argumentHint` alias).
- Builds an entirely new frontmatter object containing **only** the preserved keys. In 0.28.0 these were `description`, `allowed-tools` (alias `allowedTools`), `model` and `argument-hint` (alias `argumentHint`). From 0.39.0 the `claude` target also keeps the Claude-native keys listed above.
- Maps APM's `input:` list to Claude's `arguments:` list, and synthesizes `argument-hint` from it if not already set.
- Rewrites body placeholders `${input:name}` / `${{input:name}}` to Claude's native `$name` syntax via regex substitution.
- Computes `dropped_keys = source_frontmatter_keys - preserved_keys` and surfaces it as an install-time diagnostic warning — so `author`, `mcp`, `parameters`, and any other non-listed key are silently dropped from the compiled output but *not* silently dropped from the user's awareness (a warning fires).
@@ -44,7 +61,7 @@ There is no single closed frontmatter schema — APM's P1 "no invented primitive
| Target | Output path | Transform |
|---|---|---|
| Copilot CLI | `.github/prompts/<name>.prompt.md` | Verbatim byte copy (links resolved) |
| Claude Code | `.claude/commands/<name>.md` | Reconstructed: only `description`/`allowed-tools`/`model`/`argument-hint`/`arguments` survive; `input:` → `arguments:`; `${input:x}` → `$x` |
| Claude Code | `.claude/commands/<name>.md` | Reconstructed. In 0.28.0 only `description`/`allowed-tools`/`model`/`argument-hint`/`arguments` survive; from 0.39.0 the Claude-native keys survive too. `input:` → `arguments:`; `${input:x}` → `$x` |
Invocation surface differs correspondingly: Copilot exposes it via the prompts picker UI (select by name); Claude exposes it as `/<name> <args>` (same pattern Cursor, OpenCode, Gemini CLI, and Windsurf's workflows menu use for their own compiled copies).
@@ -52,6 +69,6 @@ Invocation surface differs correspondingly: Copilot exposes it via the prompts p
- **Input-name validation is real, not just documentation.** `_extract_input_names()` enforces `[A-Za-z][\w-]{0,63}` on every name pulled from `input:`; anything that fails is dropped from `arguments:` and reported as a warning listing up to 5 rejected names (`input: rejected N invalid name(s) ... `). A malformed `input:` entry does not fail the install — it silently loses that one argument.
- **Filename-derived identity is security-checked.** `integrate_commands_for_target` calls `validate_path_segments(base_name, context="command filename")` specifically to reject a package shipping a `.prompt.md` file with a manipulated relative name (e.g. `../../evil.prompt.md`) that would otherwise escape the target commands directory.
- **The dropped-key warning is the only signal a Claude-only author gets** that Cursor-specific frontmatter (`author`, `mcp`, `parameters`) never reached the deployed file — there is no error, no hard failure, and no config flag to preserve those keys for Claude; the shared transformer's preserved-key list is fixed in code (`_PRESERVED_COMMAND_KEYS`), not configurable per package.
- **The dropped-key message is the only signal a Claude-only author gets** that Cursor-specific frontmatter (`author`, `mcp`, `parameters`) never reached the deployed file. There is no error, no hard failure, and no config flag to preserve those keys. The preserved-key lists are fixed in code (`_PRESERVED_COMMAND_KEYS`, and `_CLAUDE_NATIVE_COMMAND_KEYS` from 0.39.0); a package cannot configure them. From 0.39.0 the message appears only with `--verbose`.
- **No dedicated `Prompt`/`PromptPrimitive` validation class exists** in `apm_cli/models/validation.py` or `apm_cli/primitives/models.py` — same gap pattern documented for the agent primitive. `apm.yml`'s `type: prompts` package-content-type ("Commands/prompts only, no instructions or skills") is validated at the package-type-detection level, not the individual-prompt level.
- Slash commands and prompts share one source directory and one glob (`.apm/prompts/*.prompt.md`) — there is no separate `.apm/commands/` primitive; "command" is purely a per-target compiled *name* for the same source file, not a distinct authoring primitive.
@@ -6,12 +6,15 @@ source_keys:
- apm-docs-producer-ramp
- apm-github-repo
- apm-cli-0-28-0-prompt-experiments
- apm-v0-39-3-source
---
## Scope and confidence
This file maps one `.apm/prompts/<name>.prompt.md` source to what each apm target receives. The paths and transforms below were **observed** on apm 0.28.0 using local-path packages in a throwaway project, and cross-checked against the published docs and the installer source. Where docs and observation disagree, the observation is used and `prompt-gotchas.md` records the disagreement. Runtime behaviour in the receiving tools was not tested.
**Version note:** the output paths below are unchanged in the 0.39.3 source. What changed is which frontmatter keys the `claude` row keeps. From 0.39.0 it keeps the Claude-native command keys, `disable-model-invocation` among them. See `prompt-primitive-schema.md`.
## Output per target
| Target | Output path | Form |
@@ -92,3 +92,73 @@ Note: `releasing.md`'s `--check-clean`/`--check-versions` scope, `apm pack` exit
- **Description:** The installed apm-cli 0.28.0 exercised with local-path throwaway packages in a scratchpad outside the repo: root-level and nested prompt discovery, manifest `type:` values, compile on prompts-only packages, per-target install output and dropped-key warnings, input-name and YAML edge cases, collision, stale-cleanup and hand-edit behaviour, hidden-Unicode scanning and audit, and `apm pack --format plugin`. Source files `command_integrator.py`, `prompt_integrator.py` and `plugin_exporter.py` were read to cross-check. Experimental targets and `apm run` were not exercised.
- **Contributing files:** prompt-target-mapping.md, prompt-gotchas.md
- **Status:** `extracted`
## apm-v0-39-3-source
- **URL:** https://github.com/microsoft/apm/tree/v0.39.3/src/apm_cli
- **Description:** apm source at tag v0.39.3. Read from a local clone that `git describe` confirmed as v0.39.3, covering:
- **lockfile and audit:** lockfile versions and hashing, the compatibility warning and `audit --ci` certification, `exact_branch_or_tag_sha`, commit reachability, libyaml loading, the audit baseline checks and output strings, and `apm outdated` options and output;
- **approvals:** executables grants and pins, trust, and the hook fingerprint;
- **integrators:** hook, command, agent and skill;
- **instructions:** `claude_agents_md` and root-context protection;
- **CLI:** the command table, init, pack, update, approve and export-patch;
- **package metadata:** `pyproject.toml`.
- **Contributing files:** lockfile-and-compatibility.md, approvals-and-executables.md, migration-0-28-to-0-39.md, cli-reference.md, installation.md, prompt-primitive-schema.md, prompt-gotchas.md, prompt-target-mapping.md, hooks-primitive-schema.md, instructions-target-mapping.md
- **Status:** `extracted`
## apm-v0-39-3-changelog
- **URL:** https://github.com/microsoft/apm/blob/v0.39.3/CHANGELOG.md
- **Description:** CHANGELOG entries from 0.29.0 to 0.39.3. They cover breaking changes and upgrade notes on lockfile v4, the 0.39.2 lock refusal, `--frozen` hashes, exact refs, commit verdicts, approvals and hook pins, hook filename routing, the Claude command keys, the AGENTS.md instruction layout, targets and CLI removals.
- **Contributing files:** lockfile-and-compatibility.md, approvals-and-executables.md, migration-0-28-to-0-39.md, prompt-primitive-schema.md, prompt-gotchas.md, hooks-primitive-schema.md, instructions-target-mapping.md, instructions-gotchas.md
- **Status:** `extracted`
## apm-v0-39-3-docs
- **URL:** https://github.com/microsoft/apm/tree/v0.39.3/docs/src/content/docs
- **Description:** the docs source behind https://microsoft.github.io/apm/, read at tag v0.39.3 from the same clone. Pages used:
- **reference:** lockfile-spec, compatibility and baseline-checks;
- **CLI reference:** install, audit, outdated, approve, export-patch, compile, pack, marketplace and uninstall;
- **consumer:** run-in-ci and update-and-refresh;
- **producer:** write-primitives;
- **getting started:** installation;
- **spec:** the OpenAPM spec.
The published installation page was also fetched, and it matched.
- **Contributing files:** lockfile-and-compatibility.md, approvals-and-executables.md, migration-0-28-to-0-39.md, cli-reference.md, installation.md, hooks-primitive-schema.md, instructions-target-mapping.md
- **Status:** `extracted`
## pypi-apm-cli
- **URL:** https://pypi.org/pypi/apm-cli/json
- **Description:** PyPI metadata for apm-cli: the 0.39.2 and 0.39.3 release dates, wheel and sdist availability, yank status, `requires_python >=3.11` and `requires_dist`.
- **Contributing files:** installation.md
- **Status:** `extracted`
## apm-cli-0-39-3-uv-experiments
- **URL:** https://pypi.org/project/apm-cli/0.39.3/
- **Description:** throwaway uv projects built in a scratchpad outside any repo with uv 0.11.24. They tested:
- `uv add --dev apm-cli==0.39.3` and `uv run apm --version`;
- the `[tool.uv] package = false` form;
- `uv run --frozen --offline` with a warm cache and with a cold cache;
- `uvx --offline` against a cache warmed by `uv add`.
- **Contributing files:** installation.md
- **Status:** `extracted`
## apm-cli-0-39-3-experiments
- **URL:** https://pypi.org/project/apm-cli/0.39.3/
- **Description:** The repo-pinned apm-cli 0.39.3 (`uv run --frozen apm`) run in throwaway packages in a scratchpad outside the repo, under holocron#273. It re-ran the 0.28.0 instruction and prompt experiments:
- **instructions:** the Claude compile layout, per-instruction dedup, an unscoped rule's retirement from `.claude/rules/`, unquoted and broken frontmatter on install and compile, hand-authored collisions, stale cleanup, the per-target transforms for ten targets, and the empty-package compile;
- **prompts:** Claude-native key survival on claude versus cursor and opencode, the `--verbose` dropped-keys message, `hooks` withholding, malformed YAML, input names, collisions, hand-edited deployed files, the Kiro prompt surface and hidden-character scanning;
- **executables:** a bare-name grant parking a hook, a full-identity grant with a different `#version` deploying it, and the gate-disabled message.
- **Contributing files:** instructions-gotchas.md, prompt-gotchas.md, approvals-and-executables.md
- **Status:** `extracted`
## context7-microsoft-apm-0-39-3
- **URL:** context7:/microsoft/apm
- **Description:** a Context7 query for apm 0.39.3 made during this refresh. It returned "Invalid API key", so no Context7 content informs the 0.39.3 material.
- **Contributing files:** none
- **Status:** `no content extracted`
+16
View File
@@ -0,0 +1,16 @@
# Pins this repo's apm with uv (ADR-0034). Not a Python package: there is no
# build system, and uv only installs the dev group below. Run apm as
# `uv run --frozen apm ...`; the repo's gate scripts spell that once in
# scripts/lib/apm.sh. uv pins the apm tool only, never plugin content
# (ADR-0024).
[project]
name = "holocron-tooling"
version = "0.0.0"
requires-python = ">=3.11"
dependencies = []
[tool.uv]
package = false
[dependency-groups]
dev = ["apm-cli==0.39.3"]
+15 -8
View File
@@ -28,7 +28,9 @@
# and additionally litters it with an apm_modules/ tree
#
# So this hook waives exactly one failure: a plugin package whose ONLY failing
# check is `lockfile-exists`. Verified against apm 0.28.0.
# check is `lockfile-exists`. Verified against apm 0.28.0, and re-verified
# against 0.39.3 (spike #269, on #268): both matched strings below are unchanged,
# and no other check fails in any plugin directory.
#
# WHAT IS DELIBERATELY NOT WAIVED
#
@@ -55,12 +57,17 @@
set -uo pipefail
# Scrub git's repo-locating env before apm runs: pushed from a linked worktree,
# the hook inherits an absolute GIT_DIR, and apm's drift replay runs `git init`
# / `git checkout` in a temp dir with it -- flipping core.bare=true and moving
# the worktree's HEAD (issue #204). See the helper for the full account.
# shellcheck source=scripts/lib/clean-git-env.sh
source "$(dirname "${BASH_SOURCE[0]}")/lib/clean-git-env.sh"
# apm is the repo-pinned one, run through scripts/lib/apm.sh as
# `uv run --project <repo root> --frozen apm` (ADR-0034). Sourcing the helper
# also scrubs git's repo-locating env before apm runs: pushed from a linked
# worktree, the hook inherits an absolute GIT_DIR, and apm's drift replay runs
# `git init` / `git checkout` in a temp dir with it -- flipping core.bare=true
# and moving the worktree's HEAD (issue #204). See clean-git-env.sh for the
# full account.
# shellcheck source=scripts/lib/apm.sh
source "$(dirname "${BASH_SOURCE[0]}")/lib/apm.sh"
require_apm_version || exit 1
readonly WAIVED_CHECK='declares dependencies but apm.lock.yaml is absent'
readonly SOLE_FAILURE='1 of 1 check(s) failed'
@@ -68,7 +75,7 @@ readonly SOLE_FAILURE='1 of 1 check(s) failed'
status=0
for manifest_dir in . plugins/*/; do
output="$(cd "$manifest_dir" && apm audit --ci 2>&1)"
output="$(cd "$manifest_dir" && run_apm audit --ci 2>&1)"
exit_code=$?
if [ "$exit_code" -eq 0 ]; then
+9 -5
View File
@@ -1,12 +1,16 @@
#!/usr/bin/env bash
# apm-pack-check-clean pre-push hook: `apm pack --check-versions --check-clean
# --dry-run`, run with git's repo-locating env scrubbed first. A script rather
# than a bare `apm ...` entry only so it can source that scrub -- see
# --dry-run`, run through scripts/lib/apm.sh. That helper runs the repo-pinned
# apm as `uv run --project <repo root> --frozen apm` (ADR-0034), fails clearly
# below the minimum version, and scrubs git's repo-locating env first -- see
# scripts/lib/clean-git-env.sh and issue #204, and docs/spec/gates.md,
# "apm-audit-ci", the "apm runs with git's repo-locating env scrubbed" paragraph.
set -euo pipefail
# shellcheck source=scripts/lib/clean-git-env.sh
source "$(dirname "${BASH_SOURCE[0]}")/lib/clean-git-env.sh"
# shellcheck source=scripts/lib/apm.sh
source "$(dirname "${BASH_SOURCE[0]}")/lib/apm.sh"
exec apm pack --check-versions --check-clean --dry-run
require_apm_version || exit 1
# The guarded expansion keeps bash 3.2 happy under `set -u`: the helper seeds
# APM_CMD empty, and require_apm_version has already refused an empty one.
exec ${APM_CMD[@]+"${APM_CMD[@]}"} pack --check-versions --check-clean --dry-run
+241 -35
View File
@@ -1,22 +1,37 @@
#!/usr/bin/env bash
set -euo pipefail
# Fails the push when root apm.yml's executables.allow stops naming the actual
# version of every plugin that ships executables. A plugin ships executables
# when plugins/<name>/.apm/hooks/ or plugins/<name>/bin/ exists; each one needs
# a '<name>#<version>' key, where <name> and <version> come from its own
# apm.yml (and <name> must equal the directory name, since keys use the
# package name). Every failing package is reported in one run.
# Fails the push when root apm.yml's executables.allow stops naming the full
# identity and actual version of every plugin that ships executables. A plugin
# ships executables when plugins/<name>/.apm/hooks/ or plugins/<name>/bin/
# exists; each one needs a '<identity>#<version>' key:
#
# The grant itself is version-blind — apm matches the version-less name
# alongside '<package>#<version>' (exec_gate.py builds the candidate list,
# _map_grants matches it) — so a stale key keeps granting the package's hooks/
# and bin/ and deployment does not break. What this gate buys is repo-level,
# not apm-level: a version bump without the matching key edit fails this
# repo's own pre-push, so each key stays an accurate record of what was
# approved. See ADR-0019's 2026-09-19 correction and docs/spec/gates.md,
# "check-executables-allow-sync"; nothing else in the pre-push gate compares
# these files.
# * <identity> is the package identity apm 0.39 matches grants on,
# <host>/<owner>/<repo>/<path>, e.g. git.rkdr.net/Mortis/Holocron/plugins/kyberforge.
# It is derived from root apm.yml's own `git:` + `path:` dependency entry
# for plugins/<name>, the same fields apm builds it from: the URL loses its
# scheme, any user@ and a trailing .git, and the path is appended. Verified
# against `apm approve --list` on apm 0.39.3 for a git+path entry on a
# self-hosted host. A plugin with no such entry fails, because no key can be
# derived for it.
# * <version> comes from plugins/<name>/apm.yml (whose name: must equal the
# directory name).
#
# Every failing package is reported in one run.
#
# Under apm 0.28 a bare '<name>#<version>' key matched. Under 0.39.3 it does
# not: the hooks are parked, .claude/settings.json is rewritten without them,
# and root `apm audit --ci` still passes (spike #269, on #268). So a bare key is
# now a real deployment failure that nothing else catches, and this gate names
# it as one.
#
# The '#<version>' suffix is stripped before apm matches, so the grant is
# version-blind and a stale version keeps granting the package's hooks/ and
# bin/. What the version half buys is repo-level, not apm-level: a version bump
# without the matching key edit fails this repo's own pre-push, so each key
# stays an accurate record of what was approved. See ADR-0019's 2026-09-19
# correction and docs/spec/gates.md, "check-executables-allow-sync"; nothing
# else in the pre-push gate compares these files.
#
# Run from repo root or pass REPO_ROOT as arg.
@@ -49,13 +64,64 @@ for plugin_dir in "$REPO_ROOT"/plugins/*/; do
done
shopt -u nullglob
# Only a repo with no executable-shipping plugin at all is a legitimate no-op —
# there is no version to pin and no hook to deploy.
if [[ ${#PLUGINS[@]} -eq 0 ]]; then
exit 0
FAILED=0
# ---------------------------------------------------------------------------
# Parked executables in the lock (spike #269, on #268, section 7.3)
# ---------------------------------------------------------------------------
# apm records each dependency's executables decision as `exec_status:` in
# apm.lock.yaml: `deployed`, or a `gated_*` value (for example
# `gated_pending_approval`) when the trust gate parked its hooks, bin or MCP
# servers. Root `apm audit --ci` passes in that state, because its
# exec-status-current check only asserts the lock agrees with the gate. So a
# wrong key, or a content-pinned hook whose script changed, would leave the
# SessionStart hook or the delivery guard silently uninstalled with every
# other gate green. This fails the push instead. Runs whether or not any
# plugin here ships executables: a third-party dependency can be parked too.
# A missing lock is not this check's concern (apm-audit-ci's lockfile-exists).
#
# A line scan, not a YAML parse: apm writes the lock with libyaml in one fixed
# shape, with `- repo_url:` opening each dependency and its fields at 2 spaces.
LOCKFILE="$REPO_ROOT/apm.lock.yaml"
if [[ -f "$LOCKFILE" ]]; then
GATED="$(awk '
/^[^ -]/ { in_deps = ($0 ~ /^dependencies:/); next }
!in_deps { next }
/^- / { host = ""; repo = ""; vpath = "" }
{
line = $0
sub(/^- /, " ", line)
if (line !~ /^ [a-z_]+: /) next
key = line; sub(/^ /, "", key); sub(/: .*/, "", key)
val = line; sub(/^ [a-z_]+: /, "", val); gsub(/["\047]/, "", val)
if (key == "host") host = val
else if (key == "repo_url") repo = val
else if (key == "virtual_path") vpath = val
else if (key == "exec_status" && val ~ /^gated_/) {
id = (host != "" ? host "/" : "") repo (vpath != "" ? "/" vpath : "")
printf "%s: %s\n", id, val
}
}
' "$LOCKFILE")"
if [[ -n "$GATED" ]]; then
echo "FAIL: apm.lock.yaml records executables apm did not deploy:" >&2
while IFS= read -r line; do echo " $line" >&2; done <<< "$GATED"
echo " Why: a gated_* exec_status means the trust gate parked that package's hooks, bin or" >&2
echo " MCP servers: no executables.allow key matches it, or a content pin no longer" >&2
echo " does. Root 'apm audit --ci' still passes in that state (spike #269), so without" >&2
echo " this check a parked SessionStart hook or guard goes unnoticed." >&2
echo " Fix: run 'uv run --frozen apm approve --list' to see why each is parked, correct its" >&2
echo " executables.allow key in root apm.yml, then 'uv run --frozen apm install' and" >&2
echo " commit the rewritten apm.lock.yaml." >&2
FAILED=1
fi
fi
FAILED=0
# Only a repo with no executable-shipping plugin at all is a legitimate no-op
# for the key checks below — there is no version to pin and no hook to deploy.
if [[ ${#PLUGINS[@]} -eq 0 ]]; then
exit "$FAILED"
fi
# "hooks/ and bin/", "hooks/" or "bin/" — what the plugin actually ships, so a
# message never claims a package has a bin/ it does not.
@@ -110,6 +176,8 @@ fi
# e<TAB><plugin dir><TAB><message> zero or more — the plugin's facts are unusable
# a<TAB>present|absent exactly once — is executables.allow a mapping?
# k<TAB><allow key> zero or more
# d<TAB><path><TAB><git url> zero or more — a root dependencies.apm entry
# carrying both git: and path:
#
# python3 + PyYAML is preferred where importable; the fallback below is not a
# YAML parser, it recognises only the shapes these manifests use. PyYAML stays
@@ -167,6 +235,14 @@ if isinstance(allow, dict):
print("k\t%s" % key)
else:
print("a\tabsent")
dependencies = root.get("dependencies")
apm_deps = dependencies.get("apm") if isinstance(dependencies, dict) else None
for entry in apm_deps if isinstance(apm_deps, list) else []:
if isinstance(entry, dict):
git, path = entry.get("git"), entry.get("path")
if isinstance(git, str) and isinstance(path, str):
print("d\t%s\t%s" % (path, git))
PY
}
@@ -193,6 +269,16 @@ top_level_scalar() {
read_facts_bash() {
local line allow_state="absent" in_executables=0 in_allow=0 key plugin manifest
local in_deps=0 in_apm_deps=0 dep_git="" dep_path=""
# Emits the dependency entry collected so far, if it carried both fields.
flush_dep() {
if [[ -n "$dep_git" && -n "$dep_path" ]]; then
printf 'd\t%s\t%s\n' "$dep_path" "$dep_git"
fi
dep_git=""
dep_path=""
}
for plugin in ${READABLE[@]+"${READABLE[@]}"}; do
manifest="$REPO_ROOT/plugins/$plugin/apm.yml"
@@ -208,12 +294,38 @@ read_facts_bash() {
# A top-level key (column 0) closes whatever block was open. Checked before
# anything else so `marketplace:` after `executables:` cannot leak keys in.
if [[ "$line" != [[:space:]]* ]]; then
if [[ "$line" == executables:* ]]; then
in_executables=1
else
in_executables=0
fi
flush_dep
in_executables=0
in_deps=0
case "$line" in
executables:*) in_executables=1 ;;
dependencies:*) in_deps=1 ;;
esac
in_allow=0
in_apm_deps=0
continue
fi
# dependencies: -> apm: -> a list of `- git: ...` / ` path: ...` items at
# 4-space indent, fields at 6 (or on the dash line itself).
if [[ $in_deps -eq 1 ]]; then
if [[ "$line" =~ ^\ \ [^[:space:]#] ]]; then
flush_dep
in_apm_deps=0
[[ "$line" =~ ^\ \ apm: ]] && in_apm_deps=1
continue
fi
[[ $in_apm_deps -eq 1 ]] || continue
if [[ "$line" =~ ^\ \ \ \ -\ * ]]; then
flush_dep
line=" ${line#*- }"
fi
if [[ "$line" =~ ^\ \ \ \ \ \ (git|path):(.*)$ ]]; then
if [[ "${BASH_REMATCH[1]}" == git ]]; then
dep_git="$(unquote "${BASH_REMATCH[2]}")"
else
dep_path="$(unquote "${BASH_REMATCH[2]}")"
fi
fi
continue
fi
[[ $in_executables -eq 1 ]] || continue
@@ -236,6 +348,7 @@ read_facts_bash() {
printf 'k\t%s\n' "$key"
fi
done < "$ROOT_MANIFEST"
flush_dep
printf 'a\t%s\n' "$allow_state"
}
@@ -263,11 +376,69 @@ fact() {
ALLOW_STATE="$(printf '%s\n' "$FACTS" | sed -n 's/^a\t//p')"
ALLOW_KEYS="$(printf '%s\n' "$FACTS" | sed -n 's/^k\t//p')"
# Strips one leading ./ and any trailing / from a dependency path.
norm_path() {
local path="${1#./}"
printf '%s' "${path%/}"
}
# dep_url <plugin dir> — the git: URL of root apm.yml's git+path dependency
# entry for plugins/<plugin dir>; empty when it has none.
dep_url() {
local want="plugins/$1" tag path url
while IFS=$'\t' read -r tag path url; do
[[ "$tag" == d && "$(norm_path "$path")" == "$want" ]] || continue
printf '%s' "$url"
return
done <<< "$FACTS"
}
# url_has_port <url> — true when a scheme URL names a port (host:port).
url_has_port() {
local rest
[[ "$1" == *://* ]] || return 1
rest="${1#*://}"
rest="${rest%%/*}"
rest="${rest#*@}"
[[ "$rest" == *:* ]]
}
# identity <plugin dir> — <host>/<owner>/<repo>/<path> from that entry; empty
# when there is none.
#
# Verified against apm 0.39.3 (`apm approve --list`) for an https URL on a
# lowercase host only. The scp-like (user@host:owner/repo) and ssh:// forms are
# derived by the same rule but were not checked against apm, and the host's
# case is kept as written, also unchecked. A URL with a port is refused before
# this runs (see the per-package checks): where apm puts a port in the
# identity is unknown, so a derived key could be wrong while looking right.
identity() {
local want="plugins/$1" url
url="$(dep_url "$1")"
[[ -n "$url" ]] || return 0
if [[ "$url" == *://* ]]; then
url="${url#*://}"
elif [[ "$url" == *:* ]]; then
url="${url/://}" # scp-like user@host:owner/repo
fi
url="${url#*@}"
url="${url%/}"
url="${url%.git}"
printf '%s/%s' "$url" "$want"
}
# expected_key <plugin dir> — '<identity>#<version>'.
expected_key() {
printf '%s#%s' "$(identity "$1")" "$(fact v "$1")"
}
# ---------------------------------------------------------------------------
# Per-package checks
# ---------------------------------------------------------------------------
# EXPECTED: plugin dir names whose manifest is usable; the key each needs is
# '<dir>#<version>' because a usable manifest's name: equals its dir name.
# '<identity>#<version>'. The dir name is what finds the identity: it is
# matched against the `path: plugins/<dir>` of a root dependency entry, which
# is why a usable manifest's name: must equal it.
EXPECTED=()
for plugin in ${READABLE[@]+"${READABLE[@]}"}; do
error="$(fact e "$plugin")"
@@ -285,8 +456,9 @@ for plugin in ${READABLE[@]+"${READABLE[@]}"}; do
if [[ "$name" != "$plugin" ]]; then
echo "FAIL: plugins/$plugin/apm.yml declares name: '${name}', which does not match its directory '$plugin'." >&2
echo " Why: executables.allow keys use the package name; with the two disagreeing this gate" >&2
echo " cannot tell which '<name>#<version>' key root apm.yml should carry." >&2
echo " Why: the '<identity>#<version>' key is found through the directory name, which this gate" >&2
echo " matches against root apm.yml's 'path: plugins/<dir>' entry; with name: disagreeing" >&2
echo " it cannot tell which package the key should be for." >&2
echo " Fix: make plugins/$plugin/apm.yml's name: equal '$plugin', or rename the directory (read by $READER)." >&2
FAILED=1
continue
@@ -294,20 +466,42 @@ for plugin in ${READABLE[@]+"${READABLE[@]}"}; do
if [[ -z "$version" ]]; then
echo "FAIL: plugins/$plugin/apm.yml declares no version:, so no allow key can be checked against it." >&2
echo " Why: the executables.allow key is '<package>#<version>'; with no version there is" >&2
echo " Why: the executables.allow key is '<identity>#<version>'; with no version there is" >&2
echo " nothing for root apm.yml's key to stay in sync with." >&2
echo " Fix: give plugins/$plugin/apm.yml a top-level version: (read by $READER)." >&2
FAILED=1
continue
fi
if [[ -z "$(identity "$plugin")" ]]; then
echo "FAIL: root apm.yml has no dependencies.apm entry with git: and path: plugins/$plugin, so the" >&2
echo " identity apm approves $plugin's $(ships "$plugin") under cannot be derived." >&2
echo " Why: apm 0.39 matches executables.allow on the full identity <host>/<owner>/<repo>/<path>," >&2
echo " built from that entry; this gate builds the expected key from the same fields." >&2
echo " Fix: declare plugins/$plugin in root apm.yml as a '- git: <url>' / 'path: plugins/$plugin'" >&2
echo " dependency (read by $READER)." >&2
FAILED=1
continue
fi
if url_has_port "$(dep_url "$plugin")"; then
echo "FAIL: root apm.yml's dependency entry for plugins/$plugin uses a git: URL with a port," >&2
echo " '$(dep_url "$plugin")', so its executables.allow key cannot be derived reliably." >&2
echo " Why: this gate derives the full package identity apm 0.39 approves under from that URL," >&2
echo " and how apm writes a port into the identity was never verified." >&2
echo " Fix: use the URL without a port if the host allows it; otherwise read the identity from" >&2
echo " 'uv run --frozen apm approve --list' and extend this check to match it." >&2
FAILED=1
continue
fi
EXPECTED+=("$plugin")
done
if [[ ${#EXPECTED[@]} -gt 0 && "$ALLOW_STATE" != "present" ]]; then
summary=""
for plugin in ${EXPECTED[@]+"${EXPECTED[@]}"}; do
summary+="${summary:+, }$plugin#$(fact v "$plugin")"
summary+="${summary:+, }$(expected_key "$plugin")"
done
echo "FAIL: root apm.yml has no executables.allow mapping, but these packages ship executables: $summary." >&2
echo " Why: without an allow entry apm refuses to deploy a package's hooks/ and bin/ — for" >&2
@@ -317,7 +511,7 @@ if [[ ${#EXPECTED[@]} -gt 0 && "$ALLOW_STATE" != "present" ]]; then
echo " executables:" >&2
echo " allow:" >&2
for plugin in ${EXPECTED[@]+"${EXPECTED[@]}"}; do
echo " $plugin#$(fact v "$plugin"):" >&2
echo " $(expected_key "$plugin"):" >&2
if [[ -d "$REPO_ROOT/plugins/$plugin/.apm/hooks" ]]; then echo " hooks: true" >&2; fi
if [[ -d "$REPO_ROOT/plugins/$plugin/bin" ]]; then echo " bin: true" >&2; fi
done
@@ -325,18 +519,30 @@ if [[ ${#EXPECTED[@]} -gt 0 && "$ALLOW_STATE" != "present" ]]; then
fi
for plugin in ${EXPECTED[@]+"${EXPECTED[@]}"}; do
expected_key="$plugin#$(fact v "$plugin")"
expected_key="$(expected_key "$plugin")"
if grep -qxF -- "$expected_key" <<< "$ALLOW_KEYS"; then
continue
fi
# Keys for the right identity at another version, and bare '<name>#...' keys,
# which apm 0.28 matched and 0.39 does not.
stale_keys=()
bare_keys=()
while IFS= read -r key; do
if [[ -n "$key" && "$key" == "$plugin#"* ]]; then stale_keys+=("$key"); fi
[[ -n "$key" ]] || continue
if [[ "$key" == "$(identity "$plugin")#"* ]]; then stale_keys+=("$key"); fi
if [[ "$key" == "$plugin" || "$key" == "$plugin#"* ]]; then bare_keys+=("$key"); fi
done <<< "$ALLOW_KEYS"
echo "FAIL: root apm.yml's executables.allow has no '$expected_key' key, but that is $plugin's version." >&2
if [[ ${#stale_keys[@]} -gt 0 ]]; then
echo "FAIL: root apm.yml's executables.allow has no '$expected_key' key, but that is $plugin's identity and version." >&2
if [[ ${#bare_keys[@]} -gt 0 ]]; then
echo " Found instead:" >&2
printf ' %s\n' ${bare_keys[@]+"${bare_keys[@]}"} ${stale_keys[@]+"${stale_keys[@]}"} >&2
echo " Why: apm 0.39 matches grants on the full package identity. A bare '$plugin#...' key" >&2
echo " matches nothing, so $plugin's $(ships "$plugin") are parked, .claude/settings.json" >&2
echo " loses its entries, and root 'apm audit --ci' still passes (spike #269, on #268)." >&2
echo " Fix: rename the key in root apm.yml to '$expected_key:'." >&2
elif [[ ${#stale_keys[@]} -gt 0 ]]; then
echo " Found instead:" >&2
printf ' %s\n' ${stale_keys[@]+"${stale_keys[@]}"} >&2
echo " Why: nothing is broken right now — apm's grant is version-blind, so a key naming another" >&2
+110
View File
@@ -0,0 +1,110 @@
#!/usr/bin/env bash
# The one place this repo spells how its scripts run apm (ADR-0034).
#
# Source it, call `require_apm_version || exit 1` once, then run apm as
# `run_apm <args>`. Sourcing also applies scripts/lib/clean-git-env.sh, so every
# gate that reaches apm through this helper runs it with git's repo-locating env
# scrubbed (issue #204).
#
# THE COMMAND
#
# uv run --project <repo root> --frozen apm
#
# * The pin is the dev group in the root pyproject.toml, locked by uv.lock. A
# bare `apm` would be whatever is on PATH, which on this machine is the global
# pipx 0.28.0 that refuses the v4 apm.lock.yaml (ADR-0034, consequence 1).
# * --project is the repo root, derived from this file's own location, never
# from the cwd. apm-audit-ci.sh runs apm from inside each plugins/<name>/, and
# uv's project discovery would otherwise start there. --project does not
# change the cwd, so apm still reads the manifest of the directory it runs in.
# * --frozen runs from uv.lock as committed and never re-resolves it. It does
# still sync the environment to that lock before running, and that is
# deliberate for gates, unlike the SessionStart hook, which adds --no-sync
# --offline (ADR-0034's 2026-12-02 amendment). A gate runs after the one-time
# `uv sync --frozen`, where that sync is a no-op that needs no network; and if
# the pin moves (a pull that bumps apm-cli), the sync brings the environment
# to the new pin instead of letting the gate certify the tree with a stale
# apm. The hook cannot afford that sync inside its timeout; a push gate can.
#
# APM overrides the command, as a seam for tests (ADR-0034, "Invocation"). It is
# split on whitespace, so it can name a stub or a full command line. The
# minimum-version check applies to it too, and an APM that holds only
# whitespace fails that check rather than silently running the default.
#
# Not meant to be executed directly.
# shellcheck source=scripts/lib/clean-git-env.sh
source "$(dirname "${BASH_SOURCE[0]}")/clean-git-env.sh"
APM_REPO_ROOT="$(CDPATH='' cd -- "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
# 0.39.2 is the lowest apm that reads and writes lockfile v4 in a form later
# versions accept, and it is above 0.39.0, which keeps Claude command keys such
# as disable-model-invocation (ADR-0034, "Minimum version").
APM_MIN_VERSION="0.39.2"
APM_CMD=()
if [[ -n "${APM:-}" ]]; then
read -r -a APM_CMD <<<"$APM"
else
APM_CMD=(uv run --project "$APM_REPO_ROOT" --frozen apm)
fi
run_apm() {
${APM_CMD[@]+"${APM_CMD[@]}"} "$@"
}
# Fails, with a message naming the fix, when the apm this helper resolves is
# missing, unreadable, or below APM_MIN_VERSION. Returns 0 when it is new enough.
require_apm_version() {
local output version stderr_file
if [[ ${#APM_CMD[@]} -eq 0 ]]; then
echo "FAIL: APM is set but holds only whitespace, so there is no apm command to run." >&2
echo " Fix: unset APM to run the repo-pinned apm, or set it to a command." >&2
return 1
fi
if [[ -z "${APM:-}" ]] && ! command -v uv >/dev/null 2>&1; then
echo "FAIL: uv is not on PATH, and this repo runs apm as 'uv run --frozen apm' (ADR-0034)." >&2
echo " Fix: install uv, then run 'uv sync --frozen' at the repo root." >&2
return 1
fi
# stdout only. uv writes its own lines to stderr when `uv run` syncs first
# (`Using CPython 3.14.6`, `Installed 62 packages`), and a merged stream
# would hand the parser uv's numbers instead of apm's. stderr is kept aside
# and shown only when the check fails.
stderr_file="$(mktemp)"
if ! output="$(run_apm --version 2>"$stderr_file")"; then
cat "$stderr_file" >&2
printf '%s\n' "$output" >&2
rm -f "$stderr_file"
echo "FAIL: could not run '${APM_CMD[*]} --version', so the apm version is unknown." >&2
echo " Fix: run 'uv sync --frozen' at the repo root, then retry." >&2
return 1
fi
# Anchored to apm's banner, `Agent Package Manager (APM) CLI version X.Y.Z`,
# so no other version-like text on stdout can be taken for apm's version.
version="$(grep -oE 'CLI version [0-9]+\.[0-9]+\.[0-9]+' <<<"$output" | head -n 1 || true)"
version="${version#CLI version }"
if [[ ! "$version" =~ ^([0-9]+)\.([0-9]+)\.([0-9]+)$ ]]; then
cat "$stderr_file" >&2
rm -f "$stderr_file"
echo "FAIL: '${APM_CMD[*]} --version' printed no 'CLI version X.Y.Z' banner, so the apm version is unknown." >&2
echo " Fix: run 'uv sync --frozen' at the repo root, then retry." >&2
return 1
fi
rm -f "$stderr_file"
local -a have=("${BASH_REMATCH[1]}" "${BASH_REMATCH[2]}" "${BASH_REMATCH[3]}")
local -a need
IFS=. read -r -a need <<<"$APM_MIN_VERSION"
local i
for i in 0 1 2; do
((10#${have[i]} > 10#${need[i]})) && return 0
if ((10#${have[i]} < 10#${need[i]})); then
echo "FAIL: apm $version is below $APM_MIN_VERSION, the minimum this repo needs (ADR-0034)." >&2
echo " Why: apm before 0.39.2 cannot read this repo's lockfile v4 apm.lock.yaml in a form" >&2
echo " later versions accept, and before 0.39.0 it drops Claude command keys." >&2
echo " Fix: run 'uv sync --frozen' at the repo root so '${APM_CMD[*]}' resolves the pinned apm." >&2
return 1
fi
done
return 0
}
+453 -13
View File
@@ -2,9 +2,11 @@
# Tests for plugins/kyberforge/.apm/hooks/check-apm-current.sh — the SessionStart
# hook that keeps an apm-consumed install level with its remote.
#
# `apm` is mocked throughout: the hook's contract is "read `apm outdated`, decide,
# emit SessionStart JSON", and that is testable without a network or a real
# install.
# `apm` and `uv` are mocked throughout (seam A: fake binaries first on PATH,
# asserting on exit code and stdout, plus the fakes' own call logs): the hook's
# contract is "pick the apm, read `apm outdated`, decide, emit SessionStart
# JSON", and that is testable without a network or a real install. The real
# apm appears once, at the end, to pin the phrase the hook greps for.
set -euo pipefail
REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
@@ -31,12 +33,15 @@ GIT_CEILING_DIRECTORIES="$(dirname "$WORK")"
# `apm update`. Sentinel files record whether update was actually invoked and
# which directory the calls ran in — the hook must run them against the same
# directory its lockfile guard checked, not the session's cwd.
# `apm --version` answers 0.39.3 unless $3 says otherwise: the hook skips the
# outdated check on anything older than 0.39.2 (ADR-0034).
make_apm() {
local outdated_line="$1" update_exit="$2"
local outdated_line="$1" update_exit="$2" version="${3:-0.39.3}"
cat > "$FAKE_BIN/apm" << EOF
#!/usr/bin/env bash
pwd > "$WORK/apm-cwd"
case "\$1" in
--version) echo "Agent Package Manager (APM) CLI version $version"; exit 0 ;;
outdated) echo "$outdated_line"; exit 0 ;;
update) touch "$WORK/update-was-called"; exit $update_exit ;;
esac
@@ -291,6 +296,414 @@ out="$(run_hook_in "$ELSEWHERE" "$ELSEWHERE")"; rc=$?
&& pass "does not run apm update when there is no lockfile anywhere" \
|| fail "must not touch a project that does not use apm"
# ---------------------------------------------------------------------------
echo ""
echo "--- which apm: repo-pinned uv, else PATH, else nothing (ADR-0034) ---"
# ---------------------------------------------------------------------------
# Seam A: every binary the hook may call is a fake first on a PATH that holds
# nothing else of interest. The machine's real uv and apm must not leak into
# these cases — a real uv would make "pin but no uv" untestable — so PATH is
# built from a whitelist of the system tools the hook and the fakes need.
TOOLS="$(mktemp -d)"
UV_BIN="$(mktemp -d)"
PIN_BIN="$(mktemp -d)"
PATH_APM_BIN="$(mktemp -d)"
PINNED="$(mktemp -d)"
trap 'rm -rf "$FAKE_BIN" "$WORK" "$TOOLS" "$UV_BIN" "$PIN_BIN" "$PATH_APM_BIN" "$PINNED" "${PROBE:-}"' EXIT
for tool in bash grep git cat touch head; do
src="$(command -v "$tool" || true)"
[[ -n "$src" ]] && ln -s "$src" "$TOOLS/$tool"
done
# A fake `timeout` that drops its duration and runs the command unbounded, so
# the suite does not need coreutils (stock macOS has no `timeout`). The real
# bound is the hook's business; these cases only need it to resolve one.
TIMEOUT_SHIM="$TOOLS/timeout"
printf '#!/usr/bin/env bash\nshift\nexec "$@"\n' > "$TIMEOUT_SHIM"
chmod +x "$TIMEOUT_SHIM"
# A fake apm at $1 that records, under $2, which phases ran. $3 is the
# `apm outdated` line, $4 the `apm update` exit code, $5 the version string.
make_fake_apm() {
local bin_dir="$1" tag="$2" outdated_line="$3" update_exit="$4" version="$5"
cat > "$bin_dir/apm" << EOF
#!/usr/bin/env bash
echo "\$*" >> "$WORK/$tag-calls"
case "\$1" in
--version) printf '%s\n' "$version"; exit 0 ;;
outdated) cat "$WORK/$tag-outdated.txt"; exit 0 ;;
update) exit $update_exit ;;
esac
exit 0
EOF
printf '%s\n' "$outdated_line" > "$WORK/$tag-outdated.txt"
chmod +x "$bin_dir/apm"
}
# The fake uv logs every invocation verbatim and only knows `run`: anything
# else exits 2. For `run` it skips uv's own options up to the `apm` argument
# and execs the pinned fake apm, which is NOT on PATH — so the pinned apm is
# reachable only through `uv run`.
cat > "$UV_BIN/uv" << EOF
#!/usr/bin/env bash
printf '%s\n' "\$*" >> "$WORK/uv-calls"
[[ "\${1:-}" == run ]] || exit 2
[[ -f "$WORK/uv-run-fails" ]] && exit 1
shift
while [[ \$# -gt 0 && "\$1" != apm ]]; do
case "\$1" in --project) shift 2 ;; *) shift ;; esac
done
[[ "\${1:-}" == apm ]] || exit 2
shift
exec "$PIN_BIN/apm" "\$@"
EOF
chmod +x "$UV_BIN/uv"
# The pin: a pyproject.toml naming apm-cli plus a uv.lock, as ADR-0034 lays out.
cat > "$PINNED/pyproject.toml" << 'EOF'
[project]
name = "consumer"
version = "0"
requires-python = ">=3.11"
[tool.uv]
package = false
[dependency-groups]
dev = ["apm-cli==0.39.3"]
EOF
touch "$PINNED/uv.lock" "$PINNED/apm.lock.yaml"
# A synced project environment. Without one the hook must not call uv at all.
mkdir -p "$PINNED/.venv"
STALE="[!] 4 outdated dependencies found"
CURRENT="[*] All dependencies are up-to-date"
V_NEW="Agent Package Manager (APM) CLI version 0.39.3"
reset_calls() { rm -f "$WORK"/uv-calls "$WORK"/pin-calls "$WORK"/path-calls; }
calls_of() { cat "$WORK/$1-calls" 2>/dev/null || true; }
# $1: space-separated PATH components drawn from uv, apm. Always ends in TOOLS.
run_pinned() {
local p="" part
for part in $1; do
case "$part" in
uv) p+="$UV_BIN:" ;;
apm) p+="$PATH_APM_BIN:" ;;
esac
done
(cd "$PINNED" && env -u CLAUDE_PROJECT_DIR -u UV_PROJECT_ENVIRONMENT PATH="${p}${RUN_TOOLS:-$TOOLS}" bash "$HOOK" 2>/dev/null)
}
ctx_of() { json_field additionalContext <<< "$1" 2>/dev/null || true; }
# Every recorded uv call must be `uv run` against the project, frozen, and with
# syncing off: a SessionStart hook must never install into the environment.
assert_uv_calls_run_only() {
local label="$1" n=0 bad=0 line
while IFS= read -r line; do
[[ -n "$line" ]] || continue
n=$((n + 1))
[[ "$line" == "run "* ]] || bad=1
[[ " $line " == *" sync "* ]] && bad=1
[[ " $line " == *" --frozen "* && " $line " == *" --no-sync "* && " $line " == *" --offline "* ]] || bad=1
[[ " $line " == *" --project $PINNED "* ]] || bad=1
done < <(calls_of uv)
if [[ $n -eq 0 ]]; then
fail "$label: expected uv to be called at least once, it was not"
elif [[ $bad -eq 0 ]]; then
pass "$label: all $n uv call(s) are \`uv run --project <root> --frozen --no-sync --offline\`, none is a sync"
else
fail "$label: uv was called with something other than a frozen no-sync \`run\`: $(tr '\n' '|' <<< "$(calls_of uv)")"
fi
}
# --- pin plus uv: uses `uv run`, for both the check and the update ---
make_fake_apm "$PIN_BIN" pin "$STALE" 1 "$V_NEW"
make_fake_apm "$PATH_APM_BIN" path "$STALE" 1 "$V_NEW"
reset_calls
out="$(run_pinned "uv apm")"; rc=$?
[[ $rc -eq 0 ]] && pass "pin + uv: exits 0" || fail "pin + uv: exit $rc"
grep -q "^outdated" <<< "$(calls_of pin)" && grep -q "^update" <<< "$(calls_of pin)" \
&& pass "pin + uv: runs the outdated check and the update through \`uv run\`" \
|| fail "pin + uv: the pinned apm should see outdated and update, saw: $(calls_of pin | tr '\n' '|')"
[[ -z "$(calls_of path)" ]] && pass "pin + uv: never touches the PATH apm" \
|| fail "pin + uv: PATH apm was called: $(calls_of path | tr '\n' '|')"
grep -qF "Run: uv run apm update --yes" <<< "$(ctx_of "$out")" \
&& pass "pin + uv: the failed-refresh advice names \`uv run apm\`" \
|| fail "pin + uv: advice should name uv run apm: $(ctx_of "$out")"
assert_uv_calls_run_only "pin + uv, stale"
# --- stale and current on the uv path ---
make_fake_apm "$PIN_BIN" pin "$STALE" 0 "$V_NEW"
reset_calls
out="$(run_pinned "uv")"
[[ "$(json_field reloadSkills <<< "$out" 2>/dev/null)" == "True" ]] \
&& grep -q "4 package" <<< "$(ctx_of "$out")" \
&& pass "uv path, stale: refreshes and reports the count" \
|| fail "uv path, stale: expected a successful-refresh notice, got: $out"
assert_uv_calls_run_only "uv path, stale"
make_fake_apm "$PIN_BIN" pin "$CURRENT" 0 "$V_NEW"
reset_calls
out="$(run_pinned "uv")"; rc=$?
[[ $rc -eq 0 && -z "$out" ]] && pass "uv path, current: silent, exit 0" \
|| fail "uv path, current: expected silence, got rc=$rc: $out"
grep -q "^update" <<< "$(calls_of pin)" && fail "uv path, current: must not update" \
|| pass "uv path, current: does not update"
assert_uv_calls_run_only "uv path, current"
# A feature branch's discard advice names the binary that will reinstall.
git -C "$PINNED" init -q -b main
git -C "$PINNED" -c user.email=[email protected] -c user.name=probe commit -q --allow-empty -m init
git -C "$PINNED" update-ref refs/remotes/origin/main HEAD
git -C "$PINNED" symbolic-ref refs/remotes/origin/HEAD refs/remotes/origin/main
git -C "$PINNED" checkout -q -b feature/y
make_fake_apm "$PIN_BIN" pin "$STALE" 0 "$V_NEW"
reset_calls
out="$(run_pinned "uv")"
grep -qF "git checkout -- apm.lock.yaml && uv run apm install" <<< "$(ctx_of "$out")" \
&& pass "uv path, feature branch: the discard advice names \`uv run apm install\`" \
|| fail "uv path, feature branch: advice should name uv run apm install: $(ctx_of "$out")"
rm -rf "$PINNED/.git"
# --- pinned apm too old (an unsynced env falls through to an old apm) ---
make_fake_apm "$PIN_BIN" pin "$CURRENT" 0 "Agent Package Manager (APM) CLI version 0.28.0"
reset_calls
out="$(run_pinned "uv")"; rc=$?
[[ $rc -eq 0 ]] && pass "uv path, apm 0.28.0: exits 0" || fail "uv path, apm 0.28.0: exit $rc"
grep -q "^outdated" <<< "$(calls_of pin)" && fail "uv path, apm 0.28.0: ran the outdated check on a too-old apm" \
|| pass "uv path, apm 0.28.0: runs no outdated check"
grep -qF "\`uv run apm\` is older than apm 0.39.2" <<< "$(ctx_of "$out")" \
&& grep -qF "Run: uv sync --frozen" <<< "$(ctx_of "$out")" \
&& pass "uv path, apm 0.28.0: prints the fixed too-old line naming \`uv run apm\`" \
|| fail "uv path, apm 0.28.0: expected the uv too-old line, got: $out"
assert_uv_calls_run_only "uv path, too old"
# --- pin but no uv: falls back to the PATH apm ---
make_fake_apm "$PIN_BIN" pin "$STALE" 0 "$V_NEW"
make_fake_apm "$PATH_APM_BIN" path "$STALE" 1 "$V_NEW"
reset_calls
out="$(run_pinned "apm")"; rc=$?
[[ $rc -eq 0 ]] && pass "pin, no uv: exits 0" || fail "pin, no uv: exit $rc"
grep -q "^outdated" <<< "$(calls_of path)" && grep -q "^update" <<< "$(calls_of path)" \
&& pass "pin, no uv: falls back to the PATH apm for the check and the update" \
|| fail "pin, no uv: PATH apm should run, saw: $(calls_of path | tr '\n' '|')"
[[ -z "$(calls_of pin)" ]] && pass "pin, no uv: the pinned apm is not reached" \
|| fail "pin, no uv: pinned apm ran without uv"
ctx="$(ctx_of "$out")"
grep -qF "Run: apm update --yes" <<< "$ctx" && ! grep -qF "uv run" <<< "$ctx" \
&& pass "pin, no uv: advice names the bare \`apm\`, not \`uv run apm\`" \
|| fail "pin, no uv: advice should name apm only: $ctx"
# --- pin declared but no uv.lock: `--frozen` has nothing to run from ---
rm -f "$PINNED/uv.lock"
reset_calls
out="$(run_pinned "uv apm")"
[[ -z "$(calls_of uv)" ]] && grep -q "^outdated" <<< "$(calls_of path)" \
&& pass "pin without uv.lock: does not call uv, uses the PATH apm" \
|| fail "pin without uv.lock: expected PATH apm only, uv saw: $(calls_of uv | tr '\n' '|')"
touch "$PINNED/uv.lock"
# --- no pin, with a PATH apm: uv on PATH is ignored ---
mv "$PINNED/pyproject.toml" "$PINNED/pyproject.toml.off"
make_fake_apm "$PATH_APM_BIN" path "$STALE" 0 "$V_NEW"
reset_calls
out="$(run_pinned "uv apm")"
[[ -z "$(calls_of uv)" ]] && pass "no pin: never calls uv even when it is on PATH" \
|| fail "no pin: uv was called: $(calls_of uv | tr '\n' '|')"
grep -q "^update" <<< "$(calls_of path)" && [[ "$(json_field reloadSkills <<< "$out" 2>/dev/null)" == "True" ]] \
&& pass "no pin, PATH path, stale: refreshes through the PATH apm" \
|| fail "no pin, PATH path, stale: expected a refresh via PATH apm, got: $out"
make_fake_apm "$PATH_APM_BIN" path "$CURRENT" 0 "$V_NEW"
reset_calls
out="$(run_pinned "uv apm")"; rc=$?
[[ $rc -eq 0 && -z "$out" ]] && ! grep -q "^update" <<< "$(calls_of path)" \
&& pass "no pin, PATH path, current: silent, no update" \
|| fail "no pin, PATH path, current: expected silence, got rc=$rc: $out"
# A pyproject.toml that does not mention apm-cli is not a pin.
printf '[project]\nname = "other"\ndependencies = ["apm-client-lib>=1"]\n' > "$PINNED/pyproject.toml"
make_fake_apm "$PATH_APM_BIN" path "$CURRENT" 0 "$V_NEW"
reset_calls
run_pinned "uv apm" > /dev/null
[[ -z "$(calls_of uv)" ]] && pass "a pyproject.toml without apm-cli is not read as a pin" \
|| fail "apm-client-lib was mistaken for an apm-cli pin"
rm -f "$PINNED/pyproject.toml"
mv "$PINNED/pyproject.toml.off" "$PINNED/pyproject.toml"
# --- no apm at all (the pin is present, uv and apm are not): silent, exit 0 ---
reset_calls
out="$(run_pinned "")"; rc=$?
[[ $rc -eq 0 && -z "$out" ]] && pass "no uv, no apm: silent, exit 0" \
|| fail "no uv, no apm: expected silence, got rc=$rc: $out"
# --- PATH apm below 0.39.2: fixed too-old line, no outdated check ---
for v in 0.28.0 0.39.1 "no version here"; do
make_fake_apm "$PATH_APM_BIN" path "$STALE" 0 "Agent Package Manager (APM) CLI version $v"
want="\`apm\` on PATH is older than apm 0.39.2"
if [[ "$v" == "no version here" ]]; then
make_fake_apm "$PATH_APM_BIN" path "$STALE" 0 "$v"
want="Could not read the version of \`apm\` on PATH"
fi
reset_calls
out="$(run_pinned "apm")"; rc=$?
ctx="$(ctx_of "$out")"
if [[ $rc -eq 0 ]] && ! grep -qE "^(outdated|update)" <<< "$(calls_of path)" \
&& grep -qF "$want" <<< "$ctx" \
&& [[ "$(json_field reloadSkills <<< "$out" 2>/dev/null)" == "False" ]]; then
pass "PATH apm reporting '$v': fixed notice ($want), no outdated check, no update"
else
fail "PATH apm reporting '$v': expected the too-old line and no outdated call; rc=$rc calls=$(calls_of path | tr '\n' '|') out=$out"
fi
done
grep -qF "uv run" <<< "$ctx" && fail "PATH too-old line must not name uv run: $ctx" \
|| pass "PATH too-old line names the bare apm only"
# The boundary is inclusive: 0.39.2 is new enough, and so is a later minor.
for v in 0.39.2 0.40.0 1.0.0; do
make_fake_apm "$PATH_APM_BIN" path "$STALE" 0 "Agent Package Manager (APM) CLI version $v"
reset_calls
run_pinned "apm" > /dev/null
grep -q "^outdated" <<< "$(calls_of path)" \
&& pass "PATH apm $v: new enough, runs the outdated check" \
|| fail "PATH apm $v: should be accepted as new enough"
done
# --- pin and uv, but no project environment: never call uv ---
# `uv run --no-sync` would create an empty .venv in the consumer's repo.
rm -rf "$PINNED/.venv"
make_fake_apm "$PIN_BIN" pin "$STALE" 0 "$V_NEW"
make_fake_apm "$PATH_APM_BIN" path "$STALE" 0 "$V_NEW"
reset_calls
out="$(run_pinned "uv apm")"; rc=$?
[[ $rc -eq 0 ]] && grep -qF "its environment has not been synced" <<< "$(ctx_of "$out")" \
&& grep -qF "Run: uv sync --frozen" <<< "$(ctx_of "$out")" \
&& pass "pin + uv, no .venv: prints the fixed not-synced notice" \
|| fail "pin + uv, no .venv: expected the not-synced notice, got rc=$rc: $out"
[[ -z "$(calls_of uv)" && -z "$(calls_of path)" ]] \
&& pass "pin + uv, no .venv: calls neither uv nor the PATH apm" \
|| fail "pin + uv, no .venv: uv saw '$(calls_of uv | tr '\n' '|')', PATH apm saw '$(calls_of path | tr '\n' '|')'"
[[ ! -e "$PINNED/.venv" ]] && pass "pin + uv, no .venv: creates no .venv" \
|| fail "pin + uv, no .venv: a .venv appeared in the project"
# UV_PROJECT_ENVIRONMENT relocates the environment; an existing one there counts.
ALT_ENV="$WORK/alt-env"
mkdir -p "$ALT_ENV"
reset_calls
out="$(cd "$PINNED" && env -u CLAUDE_PROJECT_DIR UV_PROJECT_ENVIRONMENT="$ALT_ENV" PATH="$UV_BIN:$TOOLS" bash "$HOOK" 2>/dev/null)"
grep -q "^outdated" <<< "$(calls_of pin)" \
&& pass "UV_PROJECT_ENVIRONMENT pointing at an existing env: takes the uv path" \
|| fail "UV_PROJECT_ENVIRONMENT should satisfy the environment check, got: $out"
reset_calls
out="$(cd "$PINNED" && env -u CLAUDE_PROJECT_DIR UV_PROJECT_ENVIRONMENT="$WORK/no-such-env" PATH="$UV_BIN:$TOOLS" bash "$HOOK" 2>/dev/null)"
[[ -z "$(calls_of uv)" ]] && grep -qF "has not been synced" <<< "$(ctx_of "$out")" \
&& pass "UV_PROJECT_ENVIRONMENT pointing at nothing: not-synced notice, no uv call" \
|| fail "UV_PROJECT_ENVIRONMENT pointing at nothing should not call uv, got: $out"
mkdir -p "$PINNED/.venv"
# --- pin and uv, but `uv run` itself fails ---
for how in "uv run exits non-zero" "no pinned apm to exec"; do
make_fake_apm "$PIN_BIN" pin "$STALE" 0 "$V_NEW"
if [[ "$how" == "uv run exits non-zero" ]]; then touch "$WORK/uv-run-fails"; else rm -f "$PIN_BIN/apm"; fi
reset_calls
out="$(run_pinned "uv")"; rc=$?
ctx="$(ctx_of "$out")"
[[ $rc -eq 0 ]] && grep -qF "Could not read the version of \`uv run apm\` (it failed or timed out)" <<< "$ctx" \
&& grep -qF "or run: uv sync --frozen" <<< "$ctx" \
&& ! grep -qF "not synced" <<< "$ctx" \
&& pass "pin + uv, $how: exits 0 with the fixed unreadable-version notice, not the not-synced one" \
|| fail "pin + uv, $how: expected the unreadable-version notice, got rc=$rc: $out"
assert_uv_calls_run_only "pin + uv, $how"
rm -f "$WORK/uv-run-fails"
done
# --- no timeout binary: nothing can be bounded, so stay silent ---
NO_TO="$WORK/tools-no-timeout"
G_TO="$WORK/tools-gtimeout"
mkdir -p "$NO_TO" "$G_TO"
for tool in bash grep git cat touch head; do
[[ -e "$TOOLS/$tool" ]] && ln -s "$(readlink "$TOOLS/$tool")" "$NO_TO/$tool" && ln -s "$(readlink "$TOOLS/$tool")" "$G_TO/$tool"
done
ln -s "$TIMEOUT_SHIM" "$G_TO/gtimeout"
make_fake_apm "$PATH_APM_BIN" path "$STALE" 0 "$V_NEW"
reset_calls
out="$(RUN_TOOLS="$NO_TO" run_pinned "apm")"; rc=$?
[[ $rc -eq 0 && -z "$out" && -z "$(calls_of path)" ]] \
&& pass "no timeout or gtimeout on PATH: silent, exit 0, apm not called" \
|| fail "no timeout binary: expected silence and no apm call, got rc=$rc calls=$(calls_of path | tr '\n' '|') out=$out"
# Chosen before the apm, so the uv path stays silent too: a pin with uv and no
# project environment would otherwise print its not-synced notice.
rm -rf "$PINNED/.venv"
reset_calls
out="$(RUN_TOOLS="$NO_TO" run_pinned "uv apm")"; rc=$?
[[ $rc -eq 0 && -z "$out" && -z "$(calls_of uv)" ]] \
&& pass "no timeout or gtimeout, pin + uv without .venv: still silent, uv not called" \
|| fail "no timeout binary on the uv path: expected silence, got rc=$rc out=$out"
mkdir -p "$PINNED/.venv"
reset_calls
out="$(RUN_TOOLS="$G_TO" run_pinned "apm")"
grep -q "^update" <<< "$(calls_of path)" && [[ "$(json_field reloadSkills <<< "$out" 2>/dev/null)" == "True" ]] \
&& pass "only gtimeout on PATH (Homebrew coreutils on macOS): uses it and refreshes" \
|| fail "gtimeout should stand in for timeout, got calls=$(calls_of path | tr '\n' '|') out=$out"
# --- PATH apm whose `--version` exits non-zero: unreadable, not too old ---
make_fake_apm "$PATH_APM_BIN" path "$STALE" 0 "$V_NEW"
cat > "$PATH_APM_BIN/apm" << EOF
#!/usr/bin/env bash
echo "\$*" >> "$WORK/path-calls"
case "\$1" in
--version) echo "$V_NEW"; exit 1 ;;
outdated) cat "$WORK/path-outdated.txt"; exit 0 ;;
esac
exit 0
EOF
reset_calls
mv "$PINNED/pyproject.toml" "$PINNED/pyproject.toml.off"
out="$(run_pinned "apm")"; rc=$?
ctx="$(ctx_of "$out")"
[[ $rc -eq 0 ]] && grep -qF "Could not read the version of \`apm\` on PATH (it failed or timed out)" <<< "$ctx" \
&& ! grep -qF "older than" <<< "$ctx" && ! grep -q "^outdated" <<< "$(calls_of path)" \
&& pass "PATH apm --version exits 1: unreadable-version notice, no outdated check" \
|| fail "PATH apm --version exits 1: expected the unreadable notice, got rc=$rc calls=$(calls_of path | tr '\n' '|') out=$out"
mv "$PINNED/pyproject.toml.off" "$PINNED/pyproject.toml"
# --- hostile command output never reaches the advice text ---
# Every advice string is a fixed literal; only a digit-checked count is
# spliced in. Output stuffed with ANSI escapes, command substitutions,
# backticks, separators and quotes must leave no trace in what is emitted.
HOSTILE=$'\e[31m[!] 7 outdated dependencies found\e[0m $(touch '"$WORK"'/pwned) `touch '"$WORK"'/pwned2`; rm -rf / ; "}]}\\ \x01'
for route in uv apm; do
if [[ "$route" == uv ]]; then
make_fake_apm "$PIN_BIN" pin "$HOSTILE" 1 "$V_NEW"$'\n\e[0m$(id) `id`;'
else
mv "$PINNED/pyproject.toml" "$PINNED/pyproject.toml.off"
make_fake_apm "$PATH_APM_BIN" path "$HOSTILE" 1 "$V_NEW"$'\n\e[0m$(id) `id`;'
fi
reset_calls
out="$(run_pinned "$route")"; rc=$?
ctx="$(ctx_of "$out")"
if [[ $rc -eq 0 ]] && echo "$out" | python3 -m json.tool > /dev/null 2>&1 && [[ -n "$ctx" ]]; then
pass "hostile output via $route: still exits 0 with valid JSON"
else
fail "hostile output via $route: rc=$rc, output not valid JSON: $(cat -v <<< "$out")"
fi
leaked=""
for needle in $'\e' '$(' 'pwned' 'rm -rf' '\\' $'\x01' '}]}' 'id`'; do
grep -qF -- "$needle" <<< "$out" && leaked+="[$needle]"
done
[[ -z "$leaked" ]] && pass "hostile output via $route: none of it reaches the emitted text" \
|| fail "hostile output via $route: leaked $(cat -v <<< "$leaked") into: $(cat -v <<< "$out")"
[[ ! -e "$WORK/pwned" && ! -e "$WORK/pwned2" ]] && pass "hostile output via $route: nothing in it was executed" \
|| fail "hostile output via $route: a substitution in apm's output was executed"
expected="apm install is 7 package(s) behind the remote default branch and the automatic refresh failed. Deployed skills and agents may be stale. Run: apm update --yes"
[[ "$route" == uv ]] && expected="${expected%apm update --yes}uv run apm update --yes"
[[ "$ctx" == "$expected" ]] \
&& pass "hostile output via $route: the notice is exactly the fixed literal plus the digit-checked count" \
|| fail "hostile output via $route: notice differs from the fixed literal: $(cat -v <<< "$ctx")"
[[ -f "$PINNED/pyproject.toml.off" ]] && mv "$PINNED/pyproject.toml.off" "$PINNED/pyproject.toml"
done
# ---------------------------------------------------------------------------
echo ""
echo "--- hooks.json wiring ---"
@@ -317,7 +730,8 @@ matcher="$(python3 -c 'import json,sys; d=json.load(open(sys.argv[1])); print(d[
# literal, so raising either internal `timeout` without raising the host budget
# fails here instead of reintroducing the gap quietly.
#
# Every `timeout N` in the script counts, comments included: a stray "timeout
# Every `timeout N` or `"$to" N` in the script counts (the hook resolves
# `timeout` or `gtimeout` into $to), comments included: a stray "timeout
# 300" in prose only makes this stricter, which is the safe direction.
script_budget=0
timeout_count=0
@@ -325,12 +739,12 @@ while read -r n; do
[[ -n "$n" ]] || continue
script_budget=$((script_budget + n))
timeout_count=$((timeout_count + 1))
done < <(grep -oE '\btimeout [0-9]+\b' "$HOOK" | grep -oE '[0-9]+')
done < <(grep -oE '(\btimeout|"\$to") [0-9]+\b' "$HOOK" | grep -oE '[0-9]+$')
hook_timeout="$(python3 -c 'import json,sys; d=json.load(open(sys.argv[1])); print(d["hooks"]["SessionStart"][0]["hooks"][0]["timeout"])' "$HOOKS_JSON")"
if [[ $timeout_count -eq 0 ]]; then
fail "found no 'timeout N' in $HOOK — the budget assertion below would be vacuous"
fail "found no 'timeout N' or '\"\$to\" N' in $HOOK — the budget assertion below would be vacuous"
else
pass "parsed $timeout_count internal timeout(s) totalling ${script_budget}s from the hook script"
[[ $hook_timeout -gt $script_budget ]] \
@@ -345,8 +759,8 @@ echo "--- the greped phrase, against the real apm ---"
# Everything above mocks `apm`, so an apm release that reworded its summary line
# would revert this hook to its pre-fix behaviour with a fully green suite.
# `apm outdated` has no --json/machine-readable flag (verified against 0.28.0),
# so the phrase match cannot be replaced — it can only be pinned.
# `apm outdated` has no --json/machine-readable flag (verified against 0.28.0
# and 0.39.3), so the phrase match cannot be replaced — it can only be pinned.
#
# The probe stages a genuinely outdated dependency with no network: a local git
# repo stands in for the upstream, reached through `url.<path>.insteadOf`
@@ -359,13 +773,30 @@ echo "--- the greped phrase, against the real apm ---"
# The genuine output is then replayed into the real hook through the mock, so
# what is asserted is the hook's own matching logic against real apm text —
# no pattern is duplicated here to drift out of sync.
#
# "The real apm" is this repo's pinned one, run through scripts/lib/apm.sh as
# `uv run --project <repo root> --frozen apm` (ADR-0034), never whatever apm is
# on PATH: that may be an older global install whose wording is not what this
# repo ships against. Sourced in a subshell so the helper's git-env scrub and
# its functions stay out of this suite's shell. The probe is skipped only when
# that apm cannot be run at all (no uv, or `uv sync --frozen` never ran).
probe_apm() {
(
# shellcheck source=scripts/lib/apm.sh
source "$REPO_ROOT/scripts/lib/apm.sh"
run_apm "$@"
)
}
SKIP_REASON=""
if ! command -v apm > /dev/null 2>&1 || ! command -v git > /dev/null 2>&1; then
SKIP_REASON="SKIP: apm and git are both required to verify the hook's phrase match against real \`apm outdated\` output — everything above ran, this axis did not"
if ! command -v git > /dev/null 2>&1 \
|| ! ( source "$REPO_ROOT/scripts/lib/apm.sh" && require_apm_version ) > /dev/null 2>&1; then
SKIP_REASON="SKIP: git and the repo-pinned apm (uv sync --frozen) are both required to verify the hook's phrase match against real \`apm outdated\` output — everything above ran, this axis did not"
echo " $SKIP_REASON"
else
PROBE="$(mktemp -d)"
trap 'rm -rf "$FAKE_BIN" "$WORK" "$PROBE"' EXIT
UV_REAL_CACHE="${UV_CACHE_DIR:-$(uv cache dir 2> /dev/null || true)}"
UV_REAL_PYTHONS="${UV_PYTHON_INSTALL_DIR:-$(uv python dir 2> /dev/null || true)}"
trap 'rm -rf "$FAKE_BIN" "$WORK" "$TOOLS" "$UV_BIN" "$PIN_BIN" "$PATH_APM_BIN" "$PINNED" "$PROBE"' EXIT
UPSTREAM="$PROBE/upstream.git"
git init -q "$UPSTREAM"
@@ -407,13 +838,21 @@ else
done
echo "deployments: []"
} > "$PROBE/consumer/apm.lock.yaml"
# env cannot run a shell function, so probe_apm is re-declared in a child bash.
# HOME moves to an empty dir, so uv's cache and its managed Pythons (both
# under HOME by default) are pinned to the real ones resolved before the
# move, and UV_OFFLINE forbids any fetch: the probe runs the already-synced
# pin and never needs the network.
(
cd "$PROBE/consumer" &&
env HOME="$PROBE/home" \
UV_CACHE_DIR="$UV_REAL_CACHE" \
UV_PYTHON_INSTALL_DIR="$UV_REAL_PYTHONS" \
UV_OFFLINE=1 \
GIT_CONFIG_GLOBAL="$PROBE/gitconfig" \
GIT_CONFIG_NOSYSTEM=1 \
GIT_TERMINAL_PROMPT=0 \
apm outdated 2>&1
bash -c "$(declare -f probe_apm); REPO_ROOT=\"\$1\"; probe_apm outdated" _ "$REPO_ROOT" 2>&1
)
}
@@ -431,6 +870,7 @@ else
#!/usr/bin/env bash
pwd > "$WORK/apm-cwd"
case "\$1" in
--version) echo "Agent Package Manager (APM) CLI version 0.39.3"; exit 0 ;;
outdated) cat "$PROBE/genuine-$want.txt"; exit 0 ;;
update) touch "$WORK/update-was-called"; exit 0 ;;
esac
+234
View File
@@ -0,0 +1,234 @@
#!/usr/bin/env bash
# Tests how the apm pre-push gates invoke apm (ADR-0034, issue #271).
#
# Seam B: a fake `uv` and a stub `apm` sit first on a PATH that excludes the
# machine's real uv and any global apm. The fake uv records its cwd, its argv
# and the GIT_DIR it inherited, accepts only the `run --project <root> --frozen
# apm ...` shape, and hands the rest to the stub. The stub answers --version
# with $STUB_APM_VERSION and records every other call. Nothing here runs a real
# apm or touches the repo this suite lives in.
#
# It proves, for both scripts/apm-audit-ci.sh and scripts/apm-pack-check-clean.sh:
# * the command is `uv run --project <repo root> --frozen apm`, and --project
# names the repo root even when apm runs from a plugin directory;
# * git's repo-locating env is still scrubbed before apm runs (issue #204);
# * an apm below 0.39.2 fails with a clear message before any gate work runs.
set -euo pipefail
REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
AUDIT="$REPO_ROOT/scripts/apm-audit-ci.sh"
PACK="$REPO_ROOT/scripts/apm-pack-check-clean.sh"
PASS=0
FAIL=0
pass() { echo " PASS: $1"; PASS=$((PASS + 1)); }
fail() { echo " FAIL: $1"; FAIL=$((FAIL + 1)); }
# The test must never inherit an override or the caller's repo.
unset APM GIT_DIR GIT_WORK_TREE GIT_INDEX_FILE GIT_OBJECT_DIRECTORY GIT_COMMON_DIR
TMP="$(mktemp -d)"
trap 'rm -rf "$TMP"' EXIT
BIN="$TMP/bin"
mkdir -p "$BIN"
UV_LOG="$TMP/uv.log"
APM_LOG="$TMP/apm.log"
cat > "$BIN/uv" << EOF
#!/usr/bin/env bash
{
printf 'cwd=%s\n' "\$PWD"
printf 'git_dir=%s\n' "\${GIT_DIR-<unset>}"
printf 'git_work_tree=%s\n' "\${GIT_WORK_TREE-<unset>}"
printf 'argv=%s\n' "\$*"
} >> "$UV_LOG"
if [[ "\${1:-}" != run || "\${2:-}" != --project || "\${4:-}" != --frozen || "\${5:-}" != apm ]]; then
echo "fake uv: unexpected argv: \$*" >&2
exit 97
fi
shift 5
# What a real \`uv run --frozen\` prints on stderr when it syncs first, plus a
# decoy shaped exactly like apm's banner. The version check must parse apm's
# stdout only: a parser reading the merged stream takes 0.0.1 from the decoy
# and fails a current apm (review rounds 1 and 2 of #271).
echo "Using CPython 3.14.6" >&2
echo "uv CLI version 0.0.1" >&2
exec "$BIN/apm" "\$@"
EOF
cat > "$BIN/apm" << EOF
#!/usr/bin/env bash
if [[ "\${1:-}" == --version ]]; then
printf '%s\n' "\${STUB_APM_OUTPUT:-Agent Package Manager (APM) CLI version \${STUB_APM_VERSION:-0.39.3}}"
exit 0
fi
printf 'cwd=%s args=%s\n' "\$PWD" "\$*" >> "$APM_LOG"
exit 0
EOF
chmod +x "$BIN/uv" "$BIN/apm"
# A PATH with the fakes first and only system directories after them: no
# /usr/local/bin (the real uv) and no ~/.local/bin (the global pipx apm).
FAKE_PATH="$BIN:/usr/bin:/bin"
NO_UV_PATH="/usr/bin:/bin"
for tool in uv apm; do
if PATH="$NO_UV_PATH" command -v "$tool" > /dev/null 2>&1; then
echo "SKIP: a real $tool is on $NO_UV_PATH, so the fake cannot be isolated"
exit 77
fi
done
# A fixture tree for apm-audit-ci.sh's per-manifest loop: a root and one
# plugin package. The script iterates `. plugins/*/` relative to its cwd.
FIXTURE="$TMP/fixture"
mkdir -p "$FIXTURE/plugins/demo"
reset_logs() { : > "$UV_LOG"; : > "$APM_LOG"; }
# run_gate <cwd> <script> [VAR=value ...] — sets RC and OUT (stdout+stderr).
RC=0
OUT=""
run_gate() {
local cwd="$1" script="$2"
shift 2
RC=0
OUT="$(cd "$cwd" && env PATH="$FAKE_PATH" "$@" bash "$script" 2>&1)" || RC=$?
}
# Every uv call names the repo root as --project and uses --frozen.
check_project_root() {
local label="$1" n bad
n="$(grep -c '^argv=' "$UV_LOG" || true)"
if [[ "$n" -eq 0 ]]; then
fail "$label: uv was never called"
return
fi
bad="$(grep '^argv=' "$UV_LOG" | grep -vF "argv=run --project $REPO_ROOT --frozen apm " || true)"
if [[ -z "$bad" ]]; then
pass "$label: all $n uv call(s) are 'run --project <repo root> --frozen apm'"
else
fail "$label: uv called with another shape: $bad"
fi
}
echo "--- apm-pack-check-clean: the command, run from a plugin directory ---"
reset_logs
run_gate "$REPO_ROOT/plugins/kyberforge" "$PACK"
[[ $RC -eq 0 ]] && pass "exits 0 when the pinned apm passes" || fail "exited $RC: $OUT"
check_project_root "apm-pack-check-clean from plugins/kyberforge"
grep -qxF "cwd=$REPO_ROOT/plugins/kyberforge args=pack --check-versions --check-clean --dry-run" "$APM_LOG" \
&& pass "runs 'pack --check-versions --check-clean --dry-run' in the caller's cwd" \
|| fail "unexpected apm calls: $(cat "$APM_LOG")"
echo ""
echo "--- apm-audit-ci: --project stays the repo root inside each plugin dir ---"
reset_logs
run_gate "$FIXTURE" "$AUDIT"
[[ $RC -eq 0 ]] && pass "exits 0 when every audit passes" || fail "exited $RC: $OUT"
check_project_root "apm-audit-ci"
grep -qxF "cwd=$FIXTURE/plugins/demo args=audit --ci" "$APM_LOG" \
&& pass "audits plugins/demo from inside that directory" \
|| fail "no audit ran in plugins/demo: $(cat "$APM_LOG")"
grep -qxF "cwd=$FIXTURE args=audit --ci" "$APM_LOG" \
&& pass "audits the root manifest" || fail "no root audit: $(cat "$APM_LOG")"
echo ""
echo "--- the git-env scrub still applies ---"
for pair in "apm-audit-ci:$AUDIT" "apm-pack-check-clean:$PACK"; do
label="${pair%%:*}"
script="${pair#*:}"
reset_logs
run_gate "$FIXTURE" "$script" GIT_DIR="$TMP/elsewhere/.git" GIT_WORK_TREE="$TMP/elsewhere"
[[ $RC -eq 0 ]] || fail "$label: exited $RC with GIT_DIR exported: $OUT"
if grep -q '^git_dir=' "$UV_LOG" && ! grep -q '^git_dir=[^<]' "$UV_LOG" \
&& ! grep -q '^git_work_tree=[^<]' "$UV_LOG"; then
pass "$label: uv (and so apm) saw no GIT_DIR or GIT_WORK_TREE"
else
fail "$label: git env leaked: $(grep '^git_' "$UV_LOG" | sort -u | tr '\n' ' ')"
fi
done
echo ""
echo "--- the minimum-version check ---"
for pair in "apm-audit-ci:$AUDIT" "apm-pack-check-clean:$PACK"; do
label="${pair%%:*}"
script="${pair#*:}"
for old in 0.39.1 0.28.0; do
reset_logs
run_gate "$FIXTURE" "$script" STUB_APM_VERSION="$old"
[[ $RC -ne 0 ]] && pass "$label: fails on apm $old" || fail "$label: apm $old must fail"
grep -qF "apm $old is below 0.39.2" <<< "$OUT" && grep -qF "uv sync --frozen" <<< "$OUT" \
&& pass "$label: says $old is below 0.39.2 and names the fix" \
|| fail "$label: unclear message for $old: $OUT"
[[ ! -s "$APM_LOG" ]] && pass "$label: ran no gate work on apm $old" \
|| fail "$label: ran apm past the version check: $(cat "$APM_LOG")"
done
for ok in 0.39.2 0.39.10 1.0.0; do
reset_logs
run_gate "$FIXTURE" "$script" STUB_APM_VERSION="$ok"
[[ $RC -eq 0 ]] && pass "$label: accepts apm $ok" || fail "$label: apm $ok must pass: $OUT"
done
reset_logs
run_gate "$FIXTURE" "$script" STUB_APM_OUTPUT="apm, version unknown"
[[ $RC -ne 0 ]] && grep -qF "printed no 'CLI version X.Y.Z' banner" <<< "$OUT" \
&& pass "$label: fails when the version cannot be read" \
|| fail "$label: an unreadable version must fail clearly (rc=$RC): $OUT"
done
echo ""
echo "--- the version is read from apm's stdout banner, nothing else ---"
# The fake uv writes a banner-shaped `uv CLI version 0.0.1` to stderr on every
# call, so these fail if stderr reaches the parser.
reset_logs
run_gate "$FIXTURE" "$PACK" STUB_APM_VERSION=0.39.3
[[ $RC -eq 0 ]] && pass "stdout only: apm 0.39.3 passes despite a 0.0.1 decoy on uv's stderr" \
|| fail "stdout only: 0.39.3 must pass, the stderr decoy was parsed: $OUT"
reset_logs
run_gate "$FIXTURE" "$PACK" STUB_APM_VERSION=0.28.0
[[ $RC -ne 0 ]] && grep -qF "apm 0.28.0 is below 0.39.2" <<< "$OUT" \
&& pass "stdout only: apm 0.28.0 still fails" || fail "stdout only: 0.28.0 must fail: $OUT"
# Other version-like text on stdout, before the banner, is not the version.
reset_logs
run_gate "$FIXTURE" "$PACK" \
STUB_APM_OUTPUT=$'reads lockfile version 0.40.0\nAgent Package Manager (APM) CLI version 0.28.0'
[[ $RC -ne 0 ]] && grep -qF "apm 0.28.0 is below 0.39.2" <<< "$OUT" \
&& pass "banner anchor: a 'version 0.40.0' line before the banner does not rescue 0.28.0" \
|| fail "banner anchor: the decoy line was taken for the version (rc=$RC): $OUT"
reset_logs
run_gate "$FIXTURE" "$PACK" \
STUB_APM_OUTPUT=$'reads lockfile version 0.40.0\nAgent Package Manager (APM) CLI version 0.39.3'
[[ $RC -eq 0 ]] && pass "banner anchor: the banner's 0.39.3 is the version read" \
|| fail "banner anchor: 0.39.3 behind a decoy line must pass (rc=$RC): $OUT"
echo ""
echo "--- no uv, and the APM override ---"
RC=0
OUT="$(cd "$FIXTURE" && env PATH="$NO_UV_PATH" bash "$PACK" 2>&1)" || RC=$?
[[ $RC -ne 0 ]] && grep -qF "uv is not on PATH" <<< "$OUT" \
&& pass "fails clearly when uv is missing" || fail "missing uv must fail clearly (rc=$RC): $OUT"
reset_logs
RC=0
OUT="$(cd "$FIXTURE" && env PATH="$NO_UV_PATH" APM="$BIN/apm" bash "$PACK" 2>&1)" || RC=$?
[[ $RC -eq 0 && ! -s "$UV_LOG" ]] && grep -qF "args=pack" "$APM_LOG" \
&& pass "APM overrides the command and bypasses uv" \
|| fail "APM override not honoured (rc=$RC): $OUT"
RC=0
OUT="$(cd "$FIXTURE" && env PATH="$FAKE_PATH" APM=" " bash "$PACK" 2>&1)" || RC=$?
[[ $RC -ne 0 ]] && grep -qF "holds only whitespace" <<< "$OUT" \
&& pass "a whitespace-only APM fails clearly" \
|| fail "a whitespace-only APM must fail clearly (rc=$RC): $OUT"
reset_logs
RC=0
OUT="$(cd "$FIXTURE" && env PATH="$NO_UV_PATH" APM="$BIN/apm" STUB_APM_VERSION=0.28.0 bash "$PACK" 2>&1)" || RC=$?
[[ $RC -ne 0 ]] && grep -qF "below 0.39.2" <<< "$OUT" \
&& pass "the version check applies to an APM override too" \
|| fail "an old apm via APM must fail (rc=$RC): $OUT"
echo ""
echo "Results: $PASS passed, $FAIL failed"
[[ "$FAIL" -eq 0 ]]
+18 -2
View File
@@ -13,10 +13,15 @@
# and `git checkout` inside a fresh `mktemp -d` -- and each hook script is run
# from a linked worktree of a throwaway repo with GIT_DIR exported the way git
# exports it. Nothing here touches the repo this suite lives in.
#
# The hooks run apm as `uv run --project <repo root> --frozen apm` (ADR-0034,
# scripts/lib/apm.sh), so a fake `uv` sits beside the stub and hands everything
# after `apm` to it. tests/test-apm-gate-invocation.sh pins that command shape;
# this suite only needs the call to land on the stub.
set -euo pipefail
# This suite builds its own repos; it must never inherit the caller's.
unset GIT_DIR GIT_WORK_TREE GIT_INDEX_FILE GIT_OBJECT_DIRECTORY GIT_COMMON_DIR
unset APM GIT_DIR GIT_WORK_TREE GIT_INDEX_FILE GIT_OBJECT_DIRECTORY GIT_COMMON_DIR
export GIT_CONFIG_GLOBAL=/dev/null GIT_CONFIG_NOSYSTEM=1
REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
@@ -34,7 +39,8 @@ g() { git -c user.name=fixture -c [email protected] "$@"; }
# Builds <dir>/main (two commits on `main`) and <dir>/wt, a linked worktree on
# branch `feature`, with a plugins/demo/ package dir so the audit script's
# per-package loop has something to iterate. Also writes <dir>/bin/apm, the stub.
# per-package loop has something to iterate. Also writes <dir>/bin/apm, the stub,
# and <dir>/bin/uv, the fake that reaches it.
make_fixture() {
local dir="$1"
mkdir -p "$dir/bin"
@@ -51,8 +57,18 @@ make_fixture() {
local locked
locked="$(g -C "$dir/main" rev-parse HEAD~1)"
cat > "$dir/bin/uv" <<EOF
#!/usr/bin/env bash
[[ "\${1:-}" == run && "\${5:-}" == apm ]] || { echo "fake uv: unexpected argv: \$*" >&2; exit 97; }
shift 5
exec "$dir/bin/apm" "\$@"
EOF
chmod +x "$dir/bin/uv"
# --version answers above the gates' 0.39.2 floor and records nothing.
cat > "$dir/bin/apm" <<EOF
#!/usr/bin/env bash
if [[ "\${1:-}" == --version ]]; then echo "Agent Package Manager (APM) CLI version 0.39.3"; exit 0; fi
printf '%s\n' "\${GIT_DIR-<unset>}" >> "$dir/apm-saw-git-dir"
tmp="\$(mktemp -d)"
( cd "\$tmp" && git init -q . >/dev/null 2>&1; git checkout -q --detach $locked >/dev/null 2>&1 ) || true
+177 -8
View File
@@ -46,12 +46,18 @@ make_fixture() {
echo "description: fixture"
} > "$dir/plugins/kyberforge/apm.yml"
# Both plugins are declared the way the real root apm.yml declares them, as
# git + path entries: the gate derives each key's identity from these.
{
echo "name: ai-development"
echo "version: 0.0.1"
echo "dependencies:"
echo " apm:"
echo " - name: kyberforge"
echo " - git: https://git.example.invalid/Owner/Repo.git"
echo " path: plugins/kyberforge"
echo " - git: https://git.example.invalid/Owner/Repo.git"
echo " path: plugins/delivery"
echo " mcp: []"
[[ -n "$executables_block" ]] && printf '%s\n' "$executables_block"
# A top-level key after the block: the fallback reader must stop collecting
# allow keys here rather than reading on into the next section.
@@ -74,40 +80,50 @@ add_plugin() {
} > "$dir/apm.yml"
}
# The identity apm 0.39 matches on: <host>/<owner>/<repo>/<path>.
ID=git.example.invalid/Owner/Repo/plugins
MATCHING_BLOCK='executables:
allow:
kyberforge#1.5.0:
git.example.invalid/Owner/Repo/plugins/kyberforge#1.5.0:
hooks: true
bin: true'
STALE_BLOCK='executables:
allow:
kyberforge#1.4.0:
git.example.invalid/Owner/Repo/plugins/kyberforge#1.4.0:
hooks: true
bin: true'
TWO_MATCHING_BLOCK='executables:
allow:
kyberforge#1.5.0:
git.example.invalid/Owner/Repo/plugins/kyberforge#1.5.0:
hooks: true
bin: true
# delivery ships a guard hook; an indented comment must not read as a key.
delivery#0.1.0:
git.example.invalid/Owner/Repo/plugins/delivery#0.1.0:
hooks: true'
TWO_STALE_BLOCK='executables:
allow:
kyberforge#1.4.0:
git.example.invalid/Owner/Repo/plugins/kyberforge#1.4.0:
hooks: true
bin: true
delivery#0.0.9:
git.example.invalid/Owner/Repo/plugins/delivery#0.0.9:
hooks: true'
OTHER_PACKAGE_BLOCK='executables:
allow:
git#1.0.0:
git.example.invalid/Owner/Repo/plugins/git#1.0.0:
hooks: true'
# The bare '<name>#<version>' form apm 0.28 matched and 0.39 does not.
BARE_BLOCK='executables:
allow:
kyberforge#1.5.0:
hooks: true
bin: true'
# run_gate <fixture> — echoes combined output, sets GATE_RC.
GATE_RC=0
run_gate() {
@@ -281,6 +297,39 @@ run_gate "$F"
[[ $GATE_RC -ne 0 ]] && pass "refuses an unquoted 2-component version" \
|| fail "a float version must fail rather than be compared in reader-invented form"
# ---------------------------------------------------------------------------
echo ""
echo "--- the key is the full package identity apm 0.39 matches on ---"
# ---------------------------------------------------------------------------
# The 0.28-era bare key: apm 0.39.3 parks the hooks under it while root
# `apm audit --ci` stays green (spike #269), so this gate is what catches it.
F="$(make_fixture "version: 1.5.0" "$BARE_BLOCK")"
run_gate "$F"
[[ $GATE_RC -ne 0 ]] && pass "fails on a bare '<name>#<version>' key" \
|| fail "a bare key no longer matches under apm 0.39 and must fail"
OUT="$(bash "$SCRIPT" "$F" 2>&1 || true)"
grep -qF "$ID/kyberforge#1.5.0" <<< "$OUT" && pass "names the full-identity key to use" \
|| fail "the failure must state the full-identity key, got: $OUT"
grep -qF "full package identity" <<< "$OUT" && pass "says why a bare key no longer matches" \
|| fail "the failure must explain the bare key, got: $OUT"
# No git+path dependency entry for the plugin means no identity to derive.
F="$(make_fixture "version: 1.5.0" "$MATCHING_BLOCK")"
# python3, not `sed -i`, whose in-place syntax differs between GNU and BSD sed.
python3 - "$F/apm.yml" << 'PY2'
import sys
path = sys.argv[1]
lines = open(path).read().splitlines(keepends=True)
open(path, "w").write("".join(l for l in lines if "path: plugins/kyberforge" not in l))
PY2
run_gate "$F"
[[ $GATE_RC -ne 0 ]] && pass "fails when root apm.yml has no git+path entry for the plugin" \
|| fail "with no dependency entry the identity cannot be derived; must fail"
OUT="$(bash "$SCRIPT" "$F" 2>&1 || true)"
grep -qF "cannot be derived" <<< "$OUT" && pass "says the identity cannot be derived" \
|| fail "the failure must say why, got: $OUT"
# ---------------------------------------------------------------------------
echo ""
echo "--- the fallback reader agrees with the PyYAML reader ---"
@@ -338,6 +387,126 @@ run_fallback "$F"
run_fallback "$REPO_ROOT"
[[ $GATE_RC -eq 0 ]] && pass "fallback passes the real repo" || fail "fallback disagrees with PyYAML on the real repo"
# Dependency entry shapes that name the same identity: no .git suffix, path
# first, quoted values, ./ prefix and trailing slash, and an scp-like URL. Each
# must pass under both readers.
identity_variant() {
local label="$1" entry="$2" f
f="$(make_fixture "version: 1.5.0" "$MATCHING_BLOCK")"
python3 - "$f/apm.yml" "$entry" << 'PY2'
import sys
path, entry = sys.argv[1], sys.argv[2]
text = open(path).read()
old = " - git: https://git.example.invalid/Owner/Repo.git\n path: plugins/kyberforge\n"
assert old in text
open(path, "w").write(text.replace(old, entry + "\n"))
PY2
run_gate "$f"
[[ $GATE_RC -eq 0 ]] && pass "PyYAML reader derives the identity: $label" \
|| fail "PyYAML reader: $label should pass, got: $(bash "$SCRIPT" "$f" 2>&1 | head -2 || true)"
run_fallback "$f"
[[ $GATE_RC -eq 0 ]] && pass "fallback reader derives the identity: $label" \
|| fail "fallback reader: $label should pass"
}
identity_variant "no .git suffix" " - git: https://git.example.invalid/Owner/Repo
path: plugins/kyberforge"
identity_variant "path before git" " - path: plugins/kyberforge
git: https://git.example.invalid/Owner/Repo.git"
identity_variant "quoted values, ./ and trailing /" " - git: \"https://git.example.invalid/Owner/Repo.git\"
path: './plugins/kyberforge/'"
identity_variant "scp-like URL" " - git: [email protected]:Owner/Repo.git
path: plugins/kyberforge"
F="$(make_fixture "version: 1.5.0" "$BARE_BLOCK")"
run_fallback "$F"
[[ $GATE_RC -ne 0 ]] && pass "fallback fails a bare key" || fail "fallback missed a bare key"
# A URL with a port: where apm puts the port in the identity is unverified, so
# the gate refuses to derive a key rather than derive a plausible wrong one.
for port_url in "ssh://[email protected]:2222/Owner/Repo.git" "https://git.example.invalid:8443/Owner/Repo.git"; do
F="$(make_fixture "version: 1.5.0" "$MATCHING_BLOCK")"
python3 - "$F/apm.yml" "$port_url" << 'PY2'
import sys
path, url = sys.argv[1], sys.argv[2]
text = open(path).read()
old = " - git: https://git.example.invalid/Owner/Repo.git\n path: plugins/kyberforge\n"
assert old in text
open(path, "w").write(text.replace(old, " - git: %s\n path: plugins/kyberforge\n" % url))
PY2
OUT="$(bash "$SCRIPT" "$F" 2>&1)" && rc=0 || rc=$?
[[ $rc -ne 0 ]] && grep -qF "URL with a port" <<< "$OUT" \
&& pass "refuses a git: URL with a port: $port_url" \
|| fail "a URL with a port must fail clearly ($port_url), got rc=$rc: $OUT"
run_fallback "$F"
[[ $GATE_RC -ne 0 ]] && pass "fallback refuses a git: URL with a port: $port_url" \
|| fail "fallback must refuse a URL with a port ($port_url)"
done
# ---------------------------------------------------------------------------
echo ""
echo "--- a parked executable recorded in apm.lock.yaml fails ---"
# ---------------------------------------------------------------------------
# write_lock <fixture> <kyberforge exec_status> — a lock in the shape apm 0.39.3
# writes: `- repo_url:` opens each dependency, fields at 2 spaces, host after
# repo_url, exec_status last, then a top-level deployments: section.
write_lock() {
{
echo "lockfile_version: '4'"
echo "apm_version: 0.39.3"
echo "dependencies:"
echo "- repo_url: Owner/Repo"
echo " name: kyberforge"
echo " host: git.example.invalid"
echo " virtual_path: plugins/kyberforge"
echo " deployed_files:"
echo " - .claude/hooks/kyberforge/x.sh"
echo " exec_status: $2"
echo "- repo_url: Owner/Repo"
echo " name: docs"
echo " host: git.example.invalid"
echo " virtual_path: plugins/docs"
echo "deployments:"
echo "- exec_status: gated_pending_approval"
} > "$1/apm.lock.yaml"
}
F="$(make_fixture "version: 1.5.0" "$MATCHING_BLOCK")"
write_lock "$F" deployed
run_gate "$F"
[[ $GATE_RC -eq 0 ]] && pass "passes a lock whose executables are deployed" \
|| fail "exec_status: deployed must pass, got: $(bash "$SCRIPT" "$F" 2>&1 | head -3 || true)"
F="$(make_fixture "version: 1.5.0" "$MATCHING_BLOCK")"
write_lock "$F" gated_pending_approval
run_gate "$F"
[[ $GATE_RC -ne 0 ]] && pass "fails a lock that records gated_pending_approval" \
|| fail "a parked executable in the lock must fail the push"
OUT="$(bash "$SCRIPT" "$F" 2>&1 || true)"
grep -qF "git.example.invalid/Owner/Repo/plugins/kyberforge: gated_pending_approval" <<< "$OUT" \
&& pass "names the parked package by identity and its status" \
|| fail "the failure must name the package and status, got: $OUT"
grep -q "Why:" <<< "$OUT" && grep -qF "apm approve --list" <<< "$OUT" \
&& pass "carries Why: and a Fix: naming apm approve --list" || fail "message must carry Why/Fix: $OUT"
grep -qF "plugins/docs" <<< "$OUT" && fail "a dependency with no exec_status must not be reported" \
|| pass "reports only the gated dependency, not the next one or the deployments: section"
F="$(make_fixture "version: 1.5.0" "$MATCHING_BLOCK")"
write_lock "$F" gated_definition_changed
run_fallback "$F"
[[ $GATE_RC -ne 0 ]] && pass "fails any gated_* status, without PyYAML too" \
|| fail "gated_definition_changed must fail under the fallback reader"
# A third-party dependency can be parked in a repo whose own plugins ship no
# executables, so the check runs before the no-plugin no-op.
F="$(mktemp -d "$RUN_TMP/fx.XXXXXX")"
echo "name: someone-else" > "$F/apm.yml"
write_lock "$F" gated_pending_approval
run_gate "$F"
[[ $GATE_RC -ne 0 ]] && pass "fails a parked executable even with no executable-shipping plugin" \
|| fail "the lock check must run before the no-plugin no-op"
# ---------------------------------------------------------------------------
echo ""
echo "--- wired into the pre-push gate ---"
Generated
+1951
View File
File diff suppressed because it is too large. Load diff