Revision: 1 Last modified: 2026-12-04T17:48:16Z
The §11.4.80 CodeGraph regular-update automation: checks the locally-installed @colbymchenry/codegraph version
against npm's latest, and if a newer one exists, installs it globally (no sudo — §9/§12).
Run it when: you want the CodeGraph CLI itself current. It changes a global npm package, not any index.
The anti-bluff rule that defines this script (§11.4.107 / §11.4.201): "update succeeded" is proved by observing the
new version via codegraph --version, not by npm install's exit code. A successful npm exit followed by an
unchanged version means the update did not take, and that is exit 1, not 0.
How this differs from its two siblings — the confusion to settle first:
| Script | Changes | Touches an index? |
|---|---|---|
codegraph_update.sh (this) |
the global npm package @colbymchenry/codegraph |
no |
codegraph_sync.sh |
the index of a consuming project (codegraph sync . + validate) |
yes — one project |
codegraph_update_and_resync.sh |
pull + index + commit + push for the current project, via the single writer entry | yes — through codegraph_safe.sh |
codegraph_update.sh answers "is the tool current?"; codegraph_sync.sh answers "is this project's index current?";
codegraph_update_and_resync.sh is the operator's one-shot that does pull/index/commit/push.
npmonPATH. Absent → exit2withERROR: npm not on PATH. Install Node.js 18+ first.codegraphornpxonPATH. Neither → exit2.- A user-writable npm prefix. The script never uses
sudo; if the prefix is not writable,npm install -gfails and the script says so explicitly ("verify npm prefix is user-writable (no sudo per §9/§12)") and exits2. - Network access to the npm registry for
npm view @colbymchenry/codegraph version. Unreachable → exit2. - Write access to
docs/codegraph/Status.mdunder the constitution root (it is created withmkdir -pif missing). - No env vars are read.
# Check and, if needed, update; appends the outcome to the audit trail
bash <constitution>/scripts/codegraph_update.sh
# A no-op run (already at latest) looks like this
$ bash scripts/codegraph_update.sh
Current codegraph version: 1.2.3
Latest on npm: 1.2.3
Already at latest — no update needed.
# A real update looks like this
$ bash scripts/codegraph_update.sh
Current codegraph version: 1.2.3
Latest on npm: 1.2.4
Updating @colbymchenry/codegraph from 1.2.3 → 1.2.4...
Update successful — codegraph is now 1.2.4.Verify afterwards, independently of the script's own word:
codegraph --versionThere is no --help and no flags at all — the script takes no arguments and ignores any you pass.
| Code | Meaning |
|---|---|
0 |
Already at latest, or successfully updated (the new version was observed) |
1 |
Update attempted but the new version did not take — the caught bluff |
2 |
Environment problem: npm/node missing, neither codegraph nor npx found, npm registry unreachable, or npm install -g failed |
Note 1 is specifically not "npm failed" — an npm failure is 2. Exit 1 means npm claimed success and the
version disagrees, which is the event this script exists to catch.
codegraphnot installed butnpxpresent.current_versionstays empty; the script printsCurrent codegraph version: <not-installed>and treats any npm latest as an update.- Registry unreachable →
npm viewyields empty → explicit error and exit2. It does not fall through to an update guess. npm install -gsucceeds but the version is unchanged. This is the classic case: a differentcodegraphearlier onPATH, a prefix that did not take, a cached shim. The script printsBLUFF: npm install succeeded but codegraph --version still reports '<v>' (expected '<latest>')and exits1.- The version string is only as good as
codegraph --version's first line. The script takeshead -1; if that command fails it recordsunknown, which can never equallatest, so the run reports a bluff. That is the fail-closed direction. docs/codegraph/Status.mdis appended to on every path, including the no-op and the failure — the audit trail records checks, not only changes. Its directory is created when missing.- No lock. Two concurrent runs can interleave their appends and both attempt the install; the file is append-only so nothing is corrupted, but the entries may interleave.
set -uo pipefailwithout-e, deliberately: the script inspects statuses itself and must reach its own reporting and audit-append steps rather than dying at the first non-zero.
- Resolve
SCRIPT_DIR,CONST_ROOT($SCRIPT_DIR/..), the audit document pathdocs/codegraph/Status.md, and a UTC timestamp. mkdir -pthe audit document's directory.- Require
npm; requirecodegraphornpx. - Capture
current_versionfromcodegraph --version(first line), empty when not installed. - Capture
latest_versionfromnpm view @colbymchenry/codegraph version; empty → exit2. - Print both. Equal → append a no-op section to the audit trail and exit
0. npm install -g "@colbymchenry/codegraph@${latest_version}"; failure → exit2.- Re-read
codegraph --versionasnew_version. new_version != latest_version→ append a "codegraph update FAILED (§107 bluff caught)" section and exit1.- Otherwise append a "codegraph updated" section (before / after / npm command) and exit
0.
scripts/codegraph_sync.sh— syncs and validates a consuming project's index; run it after this one.docs/scripts/codegraph_sync.md.scripts/codegraph_update_and_resync.sh— pull + index + commit + push for the current project through the single writer entry.docs/scripts/codegraph_update_and_resync.md.scripts/codegraph/codegraph_safe.sh— the §11.4.78(7)/§11.4.80(5) single writer entry;codegraph init/index/syncmust go through it, never stockcodegraph.scripts/codegraph/codegraph_guard.sh,scripts/codegraph/codegraph_scope_guard.py— the index guards.docs/codegraph/Status.md— the audit trail this script appends to.docs/scripts/codegraph_safe.md,docs/scripts/codegraph_guard.md,docs/scripts/index_watch.md.- §11.4.80 (CodeGraph automation), §11.4.107 / §11.4.201 (the observed-version proof), §9/§12 (never
sudo).
2026-12-04 — bash -n clean; the script was not executed in this pass, because a run installs a global npm package
and contacts the network. The contract above is transcribed from the source:
$ bash -n scripts/codegraph_update.sh && echo PARSE-OK
PARSE-OK
$ grep -n 'exit [0-9]' scripts/codegraph_update.shA reader with network access can verify on their own host with bash scripts/codegraph_update.sh; the no-op path
(already at latest) is the safe first run and appends one section to docs/codegraph/Status.md.