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
This commit is contained in:
Defame1297andClaude Opus 5.5 committed 2026-12-02 00:05:03 +00:00
1 parent 0ad15c80bc
commit 1fb8cc797b
7 files changed
+436 -33

No files matched your search

+26 -3
View File
@@ -87,6 +87,29 @@ 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. An environment that 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.
**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 one 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. The notice says `uv sync --frozen` on the uv path, and
says to upgrade or pin apm on the `PATH` path.
**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 +120,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
15s on `apm --version`, 60s on `apm outdated` and 300s on `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
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