Implement preflight checks and step orchestration in scripts/local-install.mjs #91
Labels
No labels
bug
chore
documentation
enhancement
feature
ready
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
david/pi-extensions-and-skills#91
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
Create
scripts/local-install.mjs(Node ESM, no third-party deps) with the run-in-order step orchestration and the complete fail-fast Step 0 preflight: every check aborts with a non-zero exit and an actionable remediation message telling the user exactly what is missing and how to fix it.Background
The
install:localscript updates and registers this repo's pi package from any git checkout. The full flow is: 0) preflight → 1)git pull→ 2)npm install→ 3) global pi registration with URL-entry dedupe → 4)/reloadreminder. This issue creates the file and implements the orchestration plus Step 0; Steps 1–4 are implemented by later steps of this plan — leave them as temporary stubs that print a "not yet implemented" message and exit non-zero, so the script fails predictably rather than silently.Depends on: #95 (Update package.json: add install:local script and register forgejo extension) — so
npm run install:localis wired; the file can also be run directly vianode scripts/local-install.mjs.Implementation Details
child_process.spawnSyncandfsfrom Node builtins only.checkPiCli,checkGitWorkTree,checkManagedClone,checkBranchMain,checkCleanTree,checkRipgrep,checkForgejoToken,checkFj) plus amain()that runs the steps in order and exits non-zero on the first failure. Helpers must be importable by the unit tests without runningmain()— guard themain()invocation (e.g. only call it whenimport.meta.urlmatches the entry-point URL).spawnSync('pi', ['--version'])succeeds → else abort: "pi CLI not found — install pi first (see https://github.com/earendil-works/pi-coding-agent)".git.excelera.net/david/pi-extensions-and-skills, acceptinghttps://,git:, andssh://URL forms → else abort: "not in a checkout of this repo —git clone https://git.excelera.net/david/pi-extensions-and-skillsfirst".~/.pi/agent/git/,.pi/git/) → else abort: "you're inside pi's managed clone — run from your own checkout".main→ else abort: "switch to main first:git checkout main".git status --porcelainoutput empty) → else abort: "commit or stash your changes:git commit/git stash".rgbinary on PATH (rg extension prereq) → else abort: "install ripgrep, e.g.sudo apt install ripgrep".FORGEJO_TOKENin env (forgejo extension prereq) → missing is warn-only: print the full remediation (generate one in Forgejo → Settings → Applications, thenexport FORGEJO_TOKEN) on stderr with a[install:local] Warning:prefix and continue — the token lives in the per-machine environment, not the checkout.fjCLI on PATH and authenticated (pr-comments extension prereq) → else abort: "install/authenticate fj:fj auth login".[install:local] Step <N> not implemented yetand exiting non-zero (replaced by later steps).Acceptance Criteria
mainbranch of this repo, the script exits non-zero and prints "switch to main first:git checkout main".main, it exits non-zero and prints "commit or stash your changes:git commit/git stash"./tmp), it exits non-zero and prints the clone remediation ("not in a checkout of this repo —git clone https://git.excelera.net/david/pi-extensions-and-skillsfirst").rgmissing from PATH, it exits non-zero and prints the ripgrep install message.FORGEJO_TOKENunset, it prints a[install:local] Warning:line on stderr naming the fix, and does NOT abort for that reason.fjmissing, it exits non-zero and prints thefj auth loginmessage.Test Plan
cd /tmp && node <repo>/scripts/local-install.mjs→ clone remediation message.git checkout -b test-branch && node scripts/local-install.mjs→ "switch to main first"; thengit checkout main.touch dirty-file && node scripts/local-install.mjs→ "commit or stash"; thenrm dirty-file.PATH=/usr/bin:/bin node scripts/local-install.mjs) → first failing tool check's message.env -u FORGEJO_TOKEN node scripts/local-install.mjson cleanmain→ warning on stderr, then reaches the Step-1 stub.Work for this issue is complete — closing.
scripts/local-install.mjsexists (Node ESM, builtins only) with the fail-fast Step 0 preflight and in-order step orchestration:main()runs preflight →git pull --ff-only→npm install→ pi registration w/ URL dedupe →/reloadreminder, aborting non-zero on first failure. Helpers are importable without runningmain()(entry-point guard).node --test scripts/local-install.test.mjspasses 99/99. Live-checked: run from a non-checkout dir → clone remediation + exit 1; dirty tree onmain→ commit/stash remediation + exit 1.rg/fj" acceptance criteria were deliberately superseded by #168 (skip/warn instead of hard-fail), documented in the file header and asserted by the current tests.