Lines 9-49javascript
9 * Two layers, both baked in here:
10 * • Layer 1 — client compare: fetch our own `latest` dist-tag from the npm registry
11 * and compare to the running version. Answers "is there something newer?"
12 * • Layer 2 — server policy: an authed command that talks to the MCP can hand us a
13 * `{ minSupported, recommended, message }` policy (via recordServerPolicy). Answers
14 * "is this version still SUPPORTED?" — a decision only the server can make. Because
15 * the client just renders whatever policy it was last handed, we can raise a hard
16 * floor years from now and even today's build will honor it. That render-what-the-
17 * server-says hook is the part that must exist now; the policy stays editable forever.
19 * Contract (like activity-log / token-store):
20 * • NEVER throws and NEVER blocks a command. The nudge is drawn from the LAST cached
21 * result (instant, no network on the hot path); the registry refresh happens in a
22 * DETACHED, unref'd child so it can't add latency or hold the process open.
23 * • Cached in `~/.tot/update-check.json`; refreshed at most once per CHECK_INTERVAL_MS.
24 * • Suppressed when stderr isn't a TTY, in CI, or when TOT_NO_UPDATE_CHECK /
25 * NO_UPDATE_NOTIFIER is set. `TOT_HOME` overrides the home dir (tests).
27import { readFileSync, writeFileSync, mkdirSync, renameSync, chmodSync } from "node:fs";
28import { homedir } from "node:os";
29import { join, dirname } from "node:path";
30import { spawn } from "node:child_process";
31import { fileURLToPath } from "node:url";
HighChild Process
Package source references child process execution.
src/update-check.mjsView on unpkg · L29 33/** Refresh the registry check at most this often. */
34export const CHECK_INTERVAL_MS = 24 * 60 * 60 * 1000; // 24h
36const PKG = "@tokenoftrust/cli";
37const DEFAULT_NPM_REGISTRY = "https://registry.npmjs.org";
38const FETCH_TIMEOUT_MS = 3000;
40/** Absolute path to the update-check cache for this environment. */
41export function updateCachePath(env = process.env) {
42 const home = env.TOT_HOME || homedir();
HighSame File Env Network Execution
A single source file combines environment access, network access, and code or shell execution; review context before blocking.
src/update-check.mjsView on unpkg · L29 43 return join(home, ".tot", "update-check.json");
46function readCache(env) {
48 return JSON.parse(readFileSync(updateCachePath(env), "utf8"));