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
This commit is contained in:
Defame1297andClaude Opus 5.5 committed 2026-12-02 00:51:25 +00:00
1 parent 367cc1c259
commit 45d740eef1
5 files changed
+74 -31

No files matched your search

@@ -25,6 +25,20 @@ project_dir="${CLAUDE_PROJECT_DIR:-$PWD}"
# installed this plugin natively. Say nothing and cost nothing.
[[ -f "$project_dir/apm.lock.yaml" ]] || 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
# 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;
@@ -53,6 +67,7 @@ project_dir="${CLAUDE_PROJECT_DIR:-$PWD}"
# 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.
emit() {
@@ -78,19 +93,6 @@ else
exit 0
fi
# 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 rather than risk holding the session open — or
# misreporting an apm whose version it could not read. 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
# 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
@@ -124,7 +126,7 @@ 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"
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