Skip to content

feat(updates): add npm-aware update check and opt-in cached notices - #85

Merged
abruption merged 2 commits into
mainfrom
feat/22-update-check
Oct 3, 2026
Merged

abruption merged 2 commits into
mainfrom
feat/22-update-check

Conversation

@abruption

@abruption abruption commented Oct 2, 2026 •

Copy link
Copy Markdown
Owner

Summary

Closes #22.

This adds an npm-aware session-peer update --check and opt-in cached update notices. Nothing installs or replaces files. The branch is now rebased onto main e35d1e6 (#79, #84, and #86 merged) and includes the reviewed multi-host integration contract from the review-only candidate #88.

The history has two commits on top of main:

Equivalence evidence. git diff 448be73 <this head> is byte-identical to git diff 63eec74 origin/main, which is exactly #79 (da0e06d): VALIDATION.md, src/windows.ts, and test/windows-inspection.test.ts, with 19 insertions and 7 deletions. This head therefore equals the independently reviewed candidate 448be73 plus #79, with no other changes.

Acceptance mapping

Criterion Status Implementation
Explicit update --check against npm, current/latest/channel/source, upgrade guidance, no Python/npm cross-comparison; update without --check refuses Done One GET to the npm dist-tags endpoint (3 s timeout including body, 64 KiB limit, redirects refused, no retries). --channel latest (stable only) or preview. SemVer 2.0 precedence; Python-style tags are invalid. updateCommand is given only for a positively identified owner: an npm global prefix whose own launcher targets this package (default, Homebrew, nvm, nvm-windows, fnm), a pnpm/Yarn/Bun global store whose manifest declares the package, Volta, or npx. Project, source, and unknown installs get null plus guidance. Without --check, the result is self_update_unsupported (exit 2) with no network request.
Private atomic cache, bounded single-flight refresh, opt-out, failure isolation Done npm-update.json is written 0600 via temp file + rename into a 0700 directory. Every cache write, background or explicit update --check, is serialized by one fail-closed O_EXCL token lock and only replaces an older record. Nothing takes over, moves, or deletes a foreign lock. See "Lock limits" below. --no-update-notice and SESSION_PEER_NO_UPDATE_NOTICE suppress background notices and refreshes. Notice, cache, and network errors never change results or exit codes.
Deterministic JSON, documented additive metadata, stderr text notices, no multiplied refreshes with multi-host Done See "Multi-host and failure policy" below. Verified by test/integration-multihost-updates.test.ts (POSIX).
Installation-manager ownership Done Only the private cache and lock are written. update refuses --host/--ssh-opt and is refused over the wire. Package smoke verifies that installed files are unchanged. Skills are reported read-only.
Tests Done test/updates.test.ts (16), test/integration-multihost-updates.test.ts (4), a Windows fake-SSH notice case, and the package-smoke extension.

Lock limits

  • A lock left behind by a crash, or by an I/O or release failure, blocks background refreshes until it is removed by hand. update --check reports cache: "skipped_stale_lock" in that case.
  • A failed token write after fstat removes only the just-created lock. Other I/O failures (fstat, final close) may leave it behind for manual recovery.

Multi-host and failure policy

  • Arrays. Repeated --host keeps request order and the exact element shape. No clientUpdate is added to elements, and no wrapper object is introduced.
  • Flat results. A flat result, local or a single --host, gets the additive clientUpdate, including a failed or unknown per-host result.
  • Never notified. The top-level catch path never carries it, and a --stdio-request receiver never reads or refreshes the cache or produces a notice.
  • Forged fields. A remote-supplied clientUpdate is dropped.
  • Text output. One stderr line per invocation.
  • No side effects. The advisory never changes status, exit code, submitted, consumptionConfirmed, or retryAllowed.
  • Refresh count. The notice is computed at a single call site per invocation. The evidence is indirect: registry request counts under the single-flight lock show one request for three hosts and none from receivers.

Design decisions

  • Notices are opt-in (SESSION_PEER_UPDATE_NOTICE=1), unlike Python's default-on. Agents and scripts call this CLI often, and an unrequested registry call or an extra stderr line would change its no-network default.
  • Separate cache stream. The file is npm-update.json, and Python's update.json is never read.
  • Registry override. SESSION_PEER_UPDATE_REGISTRY accepts HTTPS, or HTTP on loopback only, with no credentials.
  • Skills and capabilities. No skill notices. doctor capabilities add updateCheck:true and selfUpdate:false.

Type

  • feat
  • fix
  • docs
  • chore / refactor / test / perf

Validation

  • npm ci --ignore-scripts and npm run build
  • SESSION_PEER_PYTHON_ROOT=/path/to/pinned/reference npm test: 121 tests, 116 pass, 0 fail, 5 skipped (Windows-only tests skipped on macOS)
  • npm run test:package: pass. npm audit: 0. node scripts/check-repository.mjs: OK. Release pack/artifact: validated. test:types: clean.
  • feat(updates): add npm-aware update check and opt-in cached notices #85's own list --host audit SSH notice test passes with feat(ssh): support ordered multi-host commands and constrained connection options #84's ssh -G metadata call
  • CI (run 37091464051, including windows-native 22/24 and the release gate) and CodeQL (run 37091462700) passed on efe4bbb, based on main e35d1e6
  • Behavior changes include relevant tests; refused/unknown/queued/ACK remain distinct
  • Guides are updated in EN/KO/JA/zh-CN; README is unchanged
  • No credentials, real messages, session IDs, agent homes or local evidence in the diff

Tested environments / limitations

  • Tested locally on macOS arm64 with Node 24.16.0. CI covers macOS, Ubuntu, and Windows on Node 22 and 24.
  • Windows: windows-contract.test.ts checks an opted-in repeated --host array with no element field, one text stderr line identical to the opt-out stdout, and a flat single host carrying the field with code 0, ok:true, and sshHost. The refresh count, the failure policy, and the forged-field cases are unverified on Windows; they are covered by POSIX tests only.
  • Python's update --host remote push is not ported. There are no skill notices.

Release impact

No release or publication. This adds the update command, the additive optional clientUpdate field (opt-in), the update --check cache field, and the doctor capability flags updateCheck/selfUpdate. The package gains dist/updates.js and dist/updates.d.ts. No dependency, native, or schema-version changes.

Add `session-peer update --check`, which makes one bounded read of the npm
dist-tags (latest by default, or preview) and reports current/latest/
channel/source/status with guidance for a positively identified installation
owner. `update` without --check refuses with self_update_unsupported and never
replaces npm-owned files; update is local only (no --host/--ssh-opt, refused
over the wire).

Cached notices on list/send/doctor are opt-in (SESSION_PEER_UPDATE_NOTICE)
and honor --no-update-notice and SESSION_PEER_NO_UPDATE_NOTICE. The private
cache is written atomically, and every cache write is serialized by a
fail-closed O_EXCL token lock. One detached refresh runs per invocation with a
3 s timeout. Notices never change results or exit codes, are computed by the
client after dispatch, and are added only to flat results.

Refs #22
Drop any clientUpdate supplied by a verified remote receiver. Document that a
flat per-host result, including a failed or unknown one, may carry the
advisory, that the top-level catch path never does, and that repeated --host
arrays keep their exact element shape. Add the POSIX multi-host integration
tests (array shape, one refresh per invocation, failure policy and forged
remote fields) and a Windows fake-SSH notice case, and clear
SESSION_PEER_UPDATE_NOTICE in the test isolation preload.

Closes #22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(updates): add npm-aware version checks and opt-out update notices

1 participant