Skip to content

Latest commit

 

History

History
136 lines (105 loc) · 7.11 KB

codegraph_update.md

File metadata and controls

136 lines (105 loc) · 7.11 KB

codegraph_update.sh

Revision: 1 Last modified: 2026-12-04T17:48:16Z

Overview

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.

Prerequisites

  • npm on PATH. Absent → exit 2 with ERROR: npm not on PATH. Install Node.js 18+ first.
  • codegraph or npx on PATH. Neither → exit 2.
  • A user-writable npm prefix. The script never uses sudo; if the prefix is not writable, npm install -g fails and the script says so explicitly ("verify npm prefix is user-writable (no sudo per §9/§12)") and exits 2.
  • Network access to the npm registry for npm view @colbymchenry/codegraph version. Unreachable → exit 2.
  • Write access to docs/codegraph/Status.md under the constitution root (it is created with mkdir -p if missing).
  • No env vars are read.

Usage examples

# 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 --version

There is no --help and no flags at all — the script takes no arguments and ignores any you pass.

Exit codes

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.

Edge cases

  • codegraph not installed but npx present. current_version stays empty; the script prints Current codegraph version: <not-installed> and treats any npm latest as an update.
  • Registry unreachable → npm view yields empty → explicit error and exit 2. It does not fall through to an update guess.
  • npm install -g succeeds but the version is unchanged. This is the classic case: a different codegraph earlier on PATH, a prefix that did not take, a cached shim. The script prints BLUFF: npm install succeeded but codegraph --version still reports '<v>' (expected '<latest>') and exits 1.
  • The version string is only as good as codegraph --version's first line. The script takes head -1; if that command fails it records unknown, which can never equal latest, so the run reports a bluff. That is the fail-closed direction.
  • docs/codegraph/Status.md is 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 pipefail without -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.

Internal behaviour

  1. Resolve SCRIPT_DIR, CONST_ROOT ($SCRIPT_DIR/..), the audit document path docs/codegraph/Status.md, and a UTC timestamp.
  2. mkdir -p the audit document's directory.
  3. Require npm; require codegraph or npx.
  4. Capture current_version from codegraph --version (first line), empty when not installed.
  5. Capture latest_version from npm view @colbymchenry/codegraph version; empty → exit 2.
  6. Print both. Equal → append a no-op section to the audit trail and exit 0.
  7. npm install -g "@colbymchenry/codegraph@${latest_version}"; failure → exit 2.
  8. Re-read codegraph --version as new_version.
  9. new_version != latest_version → append a "codegraph update FAILED (§107 bluff caught)" section and exit 1.
  10. Otherwise append a "codegraph updated" section (before / after / npm command) and exit 0.

Related scripts

  • 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/ sync must go through it, never stock codegraph.
  • 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).

Last verified

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.sh

A 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.