Repository navigation
fix: keep self-update off npm link checkouts, and report hook injection only on change (#871) - #874
Merged
Merged
Conversation
… with the registry package When the running CLI is not under node_modules (an npm link checkout), resolveInstallPrefix returns null and doUpdate ran a prefix-less npm install -g. That lands in npm's default global prefix, where npm link put its symlink, so the next hook run swapped the checkout for the published package. Skip the install and say how to update instead.
…file changes These injectors rewrote their file and logged success on every pull, so an up-to-date pull listed them as injected while Claude and Codex, which already compare before writing, printed nothing. Use writeIfChanged and log at debug level when the file is current.
… the skip in debug.log Review follow-ups: resolve the install target before the prompt policy so nobody confirms an update that is then skipped; persist the skip warning because hooks discard stderr; word it for every null target, not only a link; tell the user to pull before rebuilding; pass --registry in the suggested install command.
…hing changes Both are reached by the pull reconcile and still logged success on every run. OpenClaw now writes its two files with writeIfChanged; Hermes also reports whether its config.yaml entry and allowlist were written.
Adversarial review follow-up: the Stop hook discards stderr, so the vendored-layout refusal left no trace while the linked-checkout refusal next to it is persisted.
The PR description includes sufficient unit, lint, build, and representative real-CLI verification. |
jeff-r2026
approved these changes
Sep 29, 2026
Walternater
pushed a commit
to Walternater/teamai-cli
that referenced
this pull request
Nov 2, 2026
…on only on change (Tencent#871) (Tencent#874) * fix(update): leave an npm link checkout alone instead of replacing it with the registry package When the running CLI is not under node_modules (an npm link checkout), resolveInstallPrefix returns null and doUpdate ran a prefix-less npm install -g. That lands in npm's default global prefix, where npm link put its symlink, so the next hook run swapped the checkout for the published package. Skip the install and say how to update instead. * fix(hooks): report OMP, OpenCode and Pi hook injection only when the file changes These injectors rewrote their file and logged success on every pull, so an up-to-date pull listed them as injected while Claude and Codex, which already compare before writing, printed nothing. Use writeIfChanged and log at debug level when the file is current. * fix(update): refuse an unsupported install before prompting, and keep the skip in debug.log Review follow-ups: resolve the install target before the prompt policy so nobody confirms an update that is then skipped; persist the skip warning because hooks discard stderr; word it for every null target, not only a link; tell the user to pull before rebuilding; pass --registry in the suggested install command. * fix(hooks): report Hermes and OpenClaw hook injection only when something changes Both are reached by the pull reconcile and still logged success on every run. OpenClaw now writes its two files with writeIfChanged; Hermes also reports whether its config.yaml entry and allowlist were written. * fix(update): persist the vendored-install skip to debug.log too Adversarial review follow-up: the Stop hook discards stderr, so the vendored-layout refusal left no trace while the linked-checkout refusal next to it is persisted.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes the two bugs in #871.
1. Self-update no longer replaces an
npm linkcheckout. When the running CLI is outsidenode_modules,resolveInstallPrefix()returns null.doUpdatethen rannpm install -gwithout--prefix, which lands in npm's default global prefix, wherenpm linkput its symlink. Now it refuses the install before prompting:Both refusals also go to
debug.log, because the hook commands send stderr to/dev/null. Before, the vendored one left no trace when a hook hit it.2.
pullreports a hook injection only when a file changed. The adapters insrc/hooks.tsalready compare before writing. The file-based injectors rewrote their files and logged✔ Injected …on every pull. They now use the existingwriteIfChangedhelper and log at debug level when nothing changed:Type of Change
Test Plan
npx tsc --noEmitpassesnpm run lintpasses (0 warnings)npx vitest runpasses: 337 files, 5252 passed, 1 skippedNew tests, each red before its fix:
The existing
doUpdatetests ran through the null-target path, because the suite runs from this checkout. They now pointfileURLToPathat a real<tmp>/lib/node_modules/teamai-clilayout.Real CLI after
npm run build(macOS, Node 24.21.0; the globalteamaiis the published v0.25.0 copy that replaced my link):Before: where
npm linkhad put a symlink,$(npm root -g)/teamai-cliwas a directory withpackage.json0.25.0 and the mtime of a hook run. The Stop hook printed the old/teamai-share-learningshint.After:
node dist/index.js updatefrom this worktree:The global install's
shasumis the same before and after, and~/.teamai/debug.loghas the[WARN] Self-update skippedline.Before:
teamai pullwith the published v0.25.0 on an up-to-date sandbox (isolatedHOME, local bare git team repo,~/.ompand~/.config/opencodepresent):After: the same sandbox, this build. The first pull prints the Claude
Updated, OMP and OpenCodeInjectedlines. The second prints only:pull --verboseshows[debug] teamai OMP hook already up-to-date …and the same line for OpenCode, next to the existing Claude line.Not run: Hermes, OpenClaw and Pi under the real CLI, because they are not installed here. Their unit tests use real files in tmp dirs.
Related Issues
Closes #871
Notes for Reviewers
Door: two-way. No data or config format changes. Reverting restores the old install and logging behavior.
Blast Radius: narrow.
prefixFromEntryPathcannot attribute. Before, it installed into npm's default global prefix. Anyone who relied on that is on an unusual layout, and they now get the warning with the exact command to run instead.updatePolicy: prompt, the vendored-layout refusal now comes before the question instead of after the user answers yes. It is also persisted todebug.log, so a vendored install on a Stop hook adds a WARN line per run, the same as a linked checkout.upsertHermesHookandaddHermesAllowlistnow returnPromise<boolean>. Their other caller (applyHermesAgentHook) ignores the value.ensureDirseparately, becausewriteIfChangedcreates the parent directory itself.Both bugs ship in one PR because #871 reports them together. The commits keep them apart: update, hooks, one review follow-up for each, and the vendored
persistfrom an adversarial review pass (verdict approve, that one low finding).