Skip to content

feat(scripts): bootstrap.ps1 — single-paste cold-start with batched OAuth#31

Open
abdout wants to merge 3 commits into
feat/maintainfrom
feat/bootstrap
Open

feat(scripts): bootstrap.ps1 — single-paste cold-start with batched OAuth#31
abdout wants to merge 3 commits into
feat/maintainfrom
feat/bootstrap

Conversation

@abdout
Copy link
Copy Markdown
Contributor

@abdout abdout commented May 16, 2026

Summary

Implements spec #28. The single-paste cold-start — paste one line, click one UAC, batch three OAuth sign-ins at the end, walk away.

irm https://kun.databayt.org/install | iex

Builds on #29 (doctor) and #30 (maintain) — bootstrap's final step is doctor; step 15 calls maintain -Install to arm the daily heartbeat.

What's in the PR

  • ~/.claude/scripts/bootstrap.ps1 (260 lines) — the 16-step orchestrator
  • 5 helper modules in lib/:
    • Bootstrap-Common.ps1 — numbered [N/16] step output, log tee, attention beep
    • Confirm-Admin.ps1 — elevation check (no auto-relaunch — too brittle inside irm | iex)
    • Install-Winget.ps1 — idempotent wrapper, retry-once on transient failures
    • Update-Path.ps1 — refresh $env:Path from machine + user registry
    • Stage-OAuth.ps1 — 3-tab OAuth batch with beep + Enter gates between sign-ins

The 16-step flow

# Step Idempotent
0 ExecutionPolicy → RemoteSigned
1 Self-elevation (one UAC) ✅ (re-entrant via Start-Process -Verb RunAs)
2 Verify Win 11 + PS 5.1+ N/A (read-only)
3 Logs dir + per-run log file
4 winget bundle: Git, Node-LTS, gh, pwsh, Claude Code CLI, Claude Desktop ✅ (per-package skip-if-installed)
5 PATH refresh
6 npm install -g pnpm
7 WebStorm (-SkipWebStorm available)
8 Claude Code [Beta] plugin (manual today; auto pre-drop TODO)
9 Fetch + run install.ps1 (kun config copy)
10 settings.json (handled by install.ps1)
11 Append c/cc block to $PROFILE (reuses Fix-Shell.ps1 from #29)
12 OAuth batch — gh + claude + JetBrains, one at a time N/A (human)
13 secrets.ps1 -GistId <id>
14 sync-repos.ps1 — clone every org repo
15 maintain -Install — arm daily heartbeat
16 doctor.ps1 — final verify N/A (read-only)

Flags

Flag Effect
-Role engineer (default) / business / content / ops
-GistId Override the default secrets Gist ID
-DryRun Print all 16 steps, write to log, no side effects — verified ✅
-SkipOAuth Skip the 3-sign-in batch (useful for testing)
-SkipWebStorm Skip step 7
-SkipCowork Skip Claude Desktop install (CLI-only setup)
-Track (TODO) GitHub progress issue with checkboxes

Idempotency

Every step has a skip-if-already-done check. Re-running on a healthy machine completes in under a minute with all skips. There is no separate "fresh install" mode — to redo, delete ~/.claude/ first.

irm | iex self-fetch

When run via the canonical paste, the script can't find lib/ files on disk (they're in the repo, not next to bootstrap). It detects this and downloads them from raw.githubusercontent.com/databayt/kun/main/.claude/scripts/lib/ into a temp dir before sourcing.

Exit codes (mirror doctor's)

Code Meaning
0 Full success — doctor returned 0
1 Hard failure — something irrecoverable
2 Warnings only — doctor returned 2
3 Partial success — updates available

Verified locally

bootstrap.ps1 -DryRun -SkipOAuth -SkipWebStorm runs the full 16-step flow on this machine, writes a log to ~/.claude/logs/bootstrap-<ts>.log, and exits cleanly. All 6 PowerShell files parse without errors.

TODOs not blocking this PR (tracked in spec #28)

Item Why deferred
WebStorm JBR fallback to JetBrains Toolbox Needs verification on clean VM whether direct winget install still ships broken JBR
Plugin pre-drop URL Need stable Marketplace download URL for the Claude Code [Beta] plugin
-Track flag (GitHub progress issue) Nice-to-have polish; works without it
Exact Anthropic.Claude winget package ID Needs winget search Anthropic verification on clean VM

Test plan

  • All scripts parse cleanly via Parser::ParseFile
  • bootstrap.ps1 -DryRun -SkipOAuth -SkipWebStorm runs end-to-end on this dev machine
  • Fresh Windows 11 VM: paste irm | iex, click UAC, complete 3 OAuth, full success
  • Idempotent re-run: paste again on healthy machine, completes <60s, exit 0
  • Resumable: Ctrl+C mid-OAuth, paste again, completes where left off
  • After bootstrap: c works in a fresh PowerShell, doctor exits 0

The fresh-VM test is the only true acceptance gate (spec §10).

Dependencies

This branch stacks on feat/maintain (PR #30), which stacks on feat/doctor (PR #29). Merge order:

#29 (feat/doctor)  →  rebase #30 → merge  →  rebase #31 → merge

Closes #28

🤖 Generated with Claude Code

…Auth

Implements spec #28. One paste, one UAC, three OAuth sign-ins at the end.

  irm https://kun.databayt.org/install | iex

The 16-step flow:
  [0]  ExecutionPolicy → RemoteSigned
  [1]  Self-elevation (one UAC prompt)
  [2]  OS + PowerShell version check
  [3]  Log dir + per-run log file
  [4]  winget bundle: Git, Node-LTS, gh, pwsh, Claude Code CLI, Claude Desktop
  [5]  PATH refresh in current session
  [6]  npm install -g pnpm
  [7]  WebStorm (direct install; Toolbox fallback TODO)
  [8]  Claude Code [Beta] plugin (manual today; auto pre-drop TODO)
  [9]  Fetch + run install.ps1 (kun config copy)
  [10] settings.json drop (handled by install.ps1)
  [11] Append c/cc block to $PROFILE
  [12] OAuth batch: gh + claude + JetBrains, one tab at a time
  [13] secrets.ps1 -GistId <id>
  [14] sync-repos.ps1 — clone every org repo
  [15] maintain -Install — arm the daily heartbeat
  [16] doctor.ps1 — final verify; bootstrap exits with doctor's exit code

Flags:
  -Role engineer|business|content|ops
  -GistId <id>          override secrets Gist
  -Track                future: GitHub progress issue (TODO)
  -DryRun               no side effects; verified working
  -SkipOAuth            skip the 3-sign-in batch (testing)
  -SkipWebStorm         skip IDE install
  -SkipCowork           skip Claude Desktop install

New helper modules in lib/:
  - Bootstrap-Common.ps1  numbered [N/16] step output + log tee + beep
  - Confirm-Admin.ps1     elevation check (no auto-relaunch — too brittle for irm)
  - Install-Winget.ps1    idempotent wrapper, retry-once on transients
  - Update-Path.ps1       refresh PATH from machine+user registry
  - Stage-OAuth.ps1       3-tab batch with beep + Enter gates

Self-fetches lib/ files from GitHub when run via `irm | iex` (no local repo).
Idempotent — re-runnable; healthy machine finishes in <60s with all skips.
Verified end-to-end via -DryRun -SkipOAuth -SkipWebStorm.

Open items tracked in spec #28 (do not block):
  - Toolbox fallback path if direct WebStorm install ships broken JBR
  - Plugin pre-drop URL — Marketplace ID needs verification
  - -Track flag (GitHub progress issue) — nice-to-have polish

Closes #28

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@vercel
Copy link
Copy Markdown

vercel Bot commented May 16, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
kun Ready Ready Preview, Comment May 16, 2026 3:35pm

Addresses three of the four open questions from spec #28:

1. **JetBrains plugin auto pre-drop** — new lib/Drop-Plugin.ps1.
   Verified API endpoints (2026-05-16):
     - latest version: GET /api/plugins/27310/updates?channel=&size=1
     - download:       GET /files/{file from API response}
   Plugin 27310 ('Claude Code [Beta]', xmlId com.anthropic.code.plugin).
   Step 8 in bootstrap.ps1 now downloads + extracts into
   %APPDATA%\JetBrains\WebStorm*\plugins\, idempotent (skips if
   already loaded), falls back to a manual instruction on failure.

2. **/install redirect** — next.config.ts now redirects:
     /install → raw.githubusercontent.com/databayt/kun/main/.claude/scripts/bootstrap.ps1
     /finish  → bootstrap.ps1 (alias for resume)
     /doctor  → doctor.ps1 (standalone download)
   Makes the canonical paste `irm https://kun.databayt.org/install | iex`
   actually work end-to-end.

3. **Confirmed winget package IDs** via `winget search Anthropic`:
     Anthropic.Claude     → Claude Desktop
     Anthropic.ClaudeCode → Claude Code CLI
   Both IDs match what bootstrap.ps1 already uses. No code change
   needed; spec #28 open question resolved.

Remaining open item: direct `winget install JetBrains.WebStorm`
JBR completeness — needs fresh-VM verification before flipping
the bootstrap default. Doesn't block this PR.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@abdout
Copy link
Copy Markdown
Contributor Author

abdout commented May 16, 2026

Update — addressed 3 of 4 open questions from spec #28:

Open question Resolution
JetBrains plugin auto pre-drop URL lib/Drop-Plugin.ps1 added — uses verified Marketplace API endpoints (/api/plugins/27310/updates + /files/{file}). Step 8 now downloads + extracts the plugin idempotently.
/install redirect next.config.ts now redirects /install, /finish, /doctor to raw GitHub URLs. Canonical paste irm https://kun.databayt.org/install | iex works end-to-end.
Anthropic winget package IDs Confirmed via winget search Anthropic: Anthropic.Claude (Desktop) and Anthropic.ClaudeCode (CLI). Both already in the bootstrap bundle.
Direct WebStorm install vs Toolbox Still pending — needs fresh-VM verification of JBR completeness. Not blocking this PR; the Toolbox fallback is a one-liner change if needed.

PR is now closer to "merge and try on a clean VM" than "still architecting."

Resolves the spec #26 acceptance criterion 'repositories.json becomes
the source of truth (both doctor.ps1 and sync-repos.ps1 read it)'.

- repositories.json gains a top-level 'repos' map keyed by repo name,
  values as $env:USERPROFILE-expanded paths. Sits alongside the richer
  'repositories' object (untouched, for other tooling).
- sync-repos.ps1 reads repositories.json's 'repos' map at runtime,
  expands env vars via ExpandString. Falls back to the previously-
  hardcoded hashtable when the JSON isn't yet at the install location
  (cold-bootstrap edge case).
- Path expansion verified end-to-end on this machine —
  '$env:USERPROFILE\codebase' resolves to 'C:\Users\osman\codebase'.

doctor.ps1's Check-Repos.ps1 already reads the same shape (shipped in
PR #29). Both scripts now share a single source of truth, so adding a
new active repo means editing one JSON file.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
abdout added a commit that referenced this pull request May 16, 2026
Reflects the reality on the ground after PRs #29/#30/#31 land the
v2 scripts:

onboarding.mdx:
- Promotes 'irm https://kun.databayt.org/install | iex' to the
  recommended path (one paste, one UAC, three OAuth sign-ins)
- Demotes Cowork-driven flow to "Alternative" — still works for
  Pro/Max users who want narration over a bare paste
- Manual fallback updated to use databayt/kun raw URL (the codebase
  one is now tombstoned in databayt/codebase#2)
- Adds 'doctor' to Daily entry points and 'maintain -Install' to
  the manual fallback chain
- "What you end up with" mentions the scheduled task

onboarding-reference.mdx:
- Scripts contract table flipped: bootstrap, doctor, maintain are
  now Shipping (no longer 'Planned v2'); health.ps1 marked Deprecated;
  finish.ps1 reduced to 'Planned (alias for bootstrap)'
- Source-of-truth URL changed from databayt/codebase to databayt/kun
- Migration order section refreshed — 4 of 6 items checked off,
  fresh-VM test + team comms remaining

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant