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
This commit is contained in:
1 parent
1fb8cc797b
commit
367cc1c259
6 files changed
+169
-40
No files matched your search
@@ -96,14 +96,24 @@ ADR-0019.
|
||||
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.
|
||||
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 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 one fixed notice that
|
||||
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. The notice says `uv sync --frozen` on the uv path, and
|
||||
says to upgrade or pin apm on the `PATH` path.
|
||||
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`. 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
|
||||
@@ -120,8 +130,8 @@ 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
|
||||
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
|
||||
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.
|
||||
|
||||
Reference in new issue
Block a user