Skip to content

Commit 76d3f2e

Browse files
authored
Streamline first-time setup with recommended defaults (#660)
* Streamline first-time setup with recommended defaults * Preserve safe account-wide setup defaults * Make installer setup best-effort and terminal-safe * Report setup outcomes without hiding the cursor * Keep setup modes behind the terminal gate * Align setup guidance with account and terminal behavior * Validate setup accounts and PowerShell terminals * Reject invalid setup args and clarify Omarchy status
1 parent 6147193 commit 76d3f2e

26 files changed

Lines changed: 1869 additions & 236 deletions

‎.surface‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12802,6 +12802,7 @@ FLAG basecamp setup --account type=string
1280212802
FLAG basecamp setup --agent type=bool
1280312803
FLAG basecamp setup --cache-dir type=string
1280412804
FLAG basecamp setup --count type=bool
12805+
FLAG basecamp setup --customize type=bool
1280512806
FLAG basecamp setup --help type=bool
1280612807
FLAG basecamp setup --hints type=bool
1280712808
FLAG basecamp setup --ids-only type=bool
@@ -12810,6 +12811,7 @@ FLAG basecamp setup --jq type=string
1281012811
FLAG basecamp setup --json type=bool
1281112812
FLAG basecamp setup --markdown type=bool
1281212813
FLAG basecamp setup --md type=bool
12814+
FLAG basecamp setup --minimal type=bool
1281312815
FLAG basecamp setup --no-hints type=bool
1281412816
FLAG basecamp setup --no-stats type=bool
1281512817
FLAG basecamp setup --profile type=string

‎README.md‎

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ irm https://raw.githubusercontent.com/basecamp/basecamp-cli/main/scripts/install
2323

2424
On Windows 11 with Smart App Control, see [Troubleshooting](#windows-smart-app-control-and-smartscreen) if the install is blocked.
2525

26-
That's it. You now have full access to Basecamp from your terminal.
26+
On an interactive terminal, the installer opens Basecamp setup: approve OAuth in your browser and the CLI uses the account granted by OAuth, otherwise preserves an existing account or selects the first available. It saves that account globally, clears the global project default, and connects every detected coding agent. Directory-specific and environment project settings continue to apply. Use `basecamp setup --customize` to choose those settings instead.
2727

2828
<details>
2929
<summary>Other installation methods</summary>
@@ -69,6 +69,11 @@ nix profile install github:basecamp/basecamp-cli
6969
go install github.com/basecamp/basecamp-cli/cmd/basecamp@latest
7070
```
7171

72+
**mise:**
73+
```bash
74+
mise use --global github:basecamp/basecamp-cli@latest
75+
```
76+
7277
**GitHub Release:** download from [Releases](https://github.com/basecamp/basecamp-cli/releases).
7378

7479
</details>
@@ -83,7 +88,7 @@ What happens depends on how the CLI was installed:
8388

8489
- **Installer script / tarball** (a binary under your home directory, e.g. `~/bin` or `~/.local/bin`): upgrades in place. The CLI downloads the release for your platform, verifies its Sigstore signature (the keyless `checksums.txt.bundle` published by the release pipeline, identity-pinned to the release workflow and tag) and SHA-256 checksum, swaps the executable transactionally, and confirms the installed binary reports the new version. On failure the previous binary is restored; in the worst case — restoration itself fails mid-swap — the error names the preserved backup file next to the binary so you can put it back by hand.
8590
- **Homebrew / Scoop**: delegates to `brew upgrade --cask` / `scoop update`, then verifies the manager-installed binary actually reports the new version.
86-
- **System packages** (apt/dnf/apk, AUR, Nix) and **`go install` builds**: never touched. `basecamp upgrade` exits nonzero with upgrade guidance for that install method (the exact command where it can be known, e.g. `go install`; otherwise which package manager to use).
91+
- **System packages** (apt/dnf/apk, AUR, Nix), **mise**, and **`go install` builds**: never touched. `basecamp upgrade` exits nonzero with upgrade guidance for that install method (the exact command where it can be known, e.g. mise or `go install`; otherwise which package manager to use).
8792

8893
`basecamp upgrade` exits 0 only when there is no update, or the update was applied *and confirmed*. Every other outcome is a structured failure (`"ok": false` in JSON) with one of these codes:
8994

@@ -96,6 +101,20 @@ What happens depends on how the CLI was installed:
96101

97102
The install scripts verify release signatures when `cosign` is available: cosign v3 verifies the published bundle format as-is, v2.6+ is driven with `--new-bundle-format=true`, and older versions skip signature verification with a warning (SHA-256 checksums are always verified).
98103

104+
## First-time setup
105+
106+
The first interactive `basecamp` run applies the recommended setup automatically after browser approval:
107+
108+
- Account granted by OAuth, otherwise the existing configured account or first available account, saved globally
109+
- No global default project; directory-specific and environment project settings continue to apply
110+
- Every detected Claude Code or Codex integration
111+
112+
Run the same setup directly with `basecamp setup`. To choose the account, default project, config scope, and agent integrations, run:
113+
114+
```bash
115+
basecamp setup --customize
116+
```
117+
99118
## Usage
100119

101120
```bash

‎e2e/installer.bats‎

Lines changed: 171 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
setup() {
1010
# The installer contract keys off these; a leaked value would skew results.
11-
unset BASECAMP_SKIP_SETUP BASECAMP_SETUP_AGENT
11+
unset BASECAMP_SKIP_SETUP BASECAMP_NONINTERACTIVE BASECAMP_SETUP_AGENT
1212

1313
INSTALL_SH="${BATS_TEST_DIRNAME}/../scripts/install.sh"
1414
INSTALL_PS1="${BATS_TEST_DIRNAME}/../scripts/install.ps1"
@@ -95,6 +95,68 @@ run_post_install_setup() {
9595
[[ "$output" != *"BASH_SOURCE[0]: unbound variable"* ]]
9696
}
9797

98+
@test "install.sh gives piped first-time setup the controlling terminal" {
99+
run grep -F 'run_first_time_setup "$BIN_DIR/$binary_name" </dev/tty' "$INSTALL_SH"
100+
[[ "$status" -eq 0 ]]
101+
run grep -F '[[ -t 1 ]] && [[ -t 2 ]] && { : </dev/tty; } 2>/dev/null' "$INSTALL_SH"
102+
[[ "$status" -eq 0 ]]
103+
}
104+
105+
@test "install.sh matches the CLI non-interactive truthy values" {
106+
run bash -c "
107+
set -euo pipefail
108+
source '$INSTALL_SH'
109+
for value in 1 true TRUE True; do
110+
env_value_is_true \"\$value\" || exit 1
111+
done
112+
for value in 0 false FALSE yes ''; do
113+
if env_value_is_true \"\$value\"; then exit 1; fi
114+
done
115+
"
116+
[[ "$status" -eq 0 ]]
117+
}
118+
119+
@test "install.sh rejects a present but unusable controlling terminal" {
120+
[[ "$(uname -s)" == "Linux" ]] || skip "setsid reproduction requires Linux"
121+
command -v setsid >/dev/null 2>&1 || skip "setsid is required"
122+
command -v script >/dev/null 2>&1 || skip "script is required"
123+
124+
cat > "$STUB_DIR/tty-probe" <<EOF
125+
#!/usr/bin/env bash
126+
source '$INSTALL_SH'
127+
if can_run_first_time_setup; then
128+
echo SETUP_CAN_RUN
129+
else
130+
echo SETUP_CANNOT_RUN
131+
fi
132+
EOF
133+
chmod +x "$STUB_DIR/tty-probe"
134+
135+
run script -qec "setsid -f -w '$STUB_DIR/tty-probe'" /dev/null
136+
[[ "$status" -eq 0 ]]
137+
[[ "$output" == *"SETUP_CANNOT_RUN"* ]]
138+
[[ "$output" != *"SETUP_CAN_RUN"* ]]
139+
}
140+
141+
@test "install.sh keeps installation successful when first-time setup fails" {
142+
cat > "$STUB_DIR/setup-fails" <<'EOF'
143+
#!/usr/bin/env bash
144+
exit 23
145+
EOF
146+
chmod +x "$STUB_DIR/setup-fails"
147+
148+
run bash -c "
149+
set -euo pipefail
150+
source '$INSTALL_SH'
151+
run_first_time_setup '$STUB_DIR/setup-fails'
152+
echo install-survived
153+
"
154+
[[ "$status" -eq 0 ]]
155+
[[ "$output" == *"First-time setup did not finish"* ]]
156+
[[ "$output" == *"basecamp setup"* ]]
157+
[[ "$output" == *"install-survived"* ]]
158+
}
159+
98160
@test "new binary: post_install_setup dispatches to 'setup agents', never 'setup claude'" {
99161
run_post_install_setup
100162
[[ "$status" -eq 0 ]]
@@ -218,6 +280,114 @@ run_post_install_setup() {
218280
[[ "$output" == *"nk=1 skill install"* ]]
219281
}
220282

283+
@test "install.ps1 honors non-interactive values and tolerates setup failure" {
284+
if ! command -v pwsh >/dev/null 2>&1; then
285+
if [[ -n "${CI:-}" ]]; then
286+
echo "pwsh is required in CI for install.ps1 setup coverage" >&2
287+
return 1
288+
fi
289+
skip "pwsh not installed"
290+
fi
291+
292+
cat > "$STUB_DIR/ps-setup-fails" <<'EOF'
293+
#!/usr/bin/env bash
294+
exit 23
295+
EOF
296+
chmod +x "$STUB_DIR/ps-setup-fails"
297+
298+
cat > "$STUB_DIR/first-time-driver.ps1" <<'EOF'
299+
$ErrorActionPreference = 'Stop'
300+
$tokens = $null; $parseErrors = $null
301+
$ast = [System.Management.Automation.Language.Parser]::ParseFile($env:INSTALL_PS1_PATH, [ref]$tokens, [ref]$parseErrors)
302+
if ($parseErrors.Count -gt 0) { throw "install.ps1 parse errors: $($parseErrors -join '; ')" }
303+
foreach ($name in @('Test-TruthyEnvironmentValue', 'Invoke-FirstTimeSetup')) {
304+
$fn = $ast.Find({ param($n) $n -is [System.Management.Automation.Language.FunctionDefinitionAst] -and $n.Name -eq $name }, $true)
305+
if (-not $fn) { throw "$name not found in install.ps1" }
306+
. ([scriptblock]::Create($fn.Extent.Text))
307+
}
308+
function Warn([string]$Message) { $script:WarningMessage = $Message }
309+
foreach ($value in @('1', 'true', 'TRUE', 'True')) {
310+
if (-not (Test-TruthyEnvironmentValue $value)) { throw "truthy value rejected: $value" }
311+
}
312+
foreach ($value in @('0', 'false', 'yes', '')) {
313+
if (Test-TruthyEnvironmentValue $value) { throw "falsey value accepted: $value" }
314+
}
315+
Invoke-FirstTimeSetup $env:PS_SETUP_STUB
316+
"WARN:$script:WarningMessage"
317+
'install-survived'
318+
EOF
319+
320+
run bash -c "
321+
set -euo pipefail
322+
export INSTALL_PS1_PATH='$INSTALL_PS1' PS_SETUP_STUB='$STUB_DIR/ps-setup-fails'
323+
pwsh -NoProfile -File '$STUB_DIR/first-time-driver.ps1'
324+
"
325+
[[ "$status" -eq 0 ]]
326+
[[ "$output" == *"WARN:First-time setup did not finish"* ]]
327+
[[ "$output" == *"install-survived"* ]]
328+
grep -qF 'Test-TruthyEnvironmentValue $env:BASECAMP_NONINTERACTIVE' "$INSTALL_PS1"
329+
}
330+
331+
@test "install.ps1 first-time setup preserves terminal streams and visible output" {
332+
[[ "$(uname -s)" == "Linux" ]] || skip "PTY stream reproduction requires Linux"
333+
command -v pwsh >/dev/null 2>&1 || skip "pwsh not installed"
334+
command -v script >/dev/null 2>&1 || skip "script is required"
335+
336+
PS_TTY_LOG="$STUB_DIR/ps-setup-tty.log"
337+
cat > "$STUB_DIR/ps-setup-probe" <<'EOF'
338+
#!/usr/bin/env bash
339+
stdin=redirected
340+
stdout=redirected
341+
stderr=redirected
342+
[[ -t 0 ]] && stdin=tty
343+
[[ -t 1 ]] && stdout=tty
344+
[[ -t 2 ]] && stderr=tty
345+
printf 'stdin=%s stdout=%s stderr=%s\n' "$stdin" "$stdout" "$stderr" > "$PS_TTY_LOG"
346+
echo SETUP_OUTPUT_VISIBLE
347+
EOF
348+
chmod +x "$STUB_DIR/ps-setup-probe"
349+
350+
cat > "$STUB_DIR/ps-first-time-tty-driver.ps1" <<'EOF'
351+
$ErrorActionPreference = 'Stop'
352+
$tokens = $null; $parseErrors = $null
353+
$ast = [System.Management.Automation.Language.Parser]::ParseFile($env:INSTALL_PS1_PATH, [ref]$tokens, [ref]$parseErrors)
354+
if ($parseErrors.Count -gt 0) { throw "install.ps1 parse errors: $($parseErrors -join '; ')" }
355+
foreach ($name in @('Warn', 'Invoke-FirstTimeSetup')) {
356+
$fn = $ast.Find({ param($n) $n -is [System.Management.Automation.Language.FunctionDefinitionAst] -and $n.Name -eq $name }, $true)
357+
if (-not $fn) { throw "$name not found in install.ps1" }
358+
. ([scriptblock]::Create($fn.Extent.Text))
359+
}
360+
Invoke-FirstTimeSetup $env:PS_SETUP_STUB
361+
EOF
362+
363+
run script -qec "INSTALL_PS1_PATH='$INSTALL_PS1' PS_SETUP_STUB='$STUB_DIR/ps-setup-probe' PS_TTY_LOG='$PS_TTY_LOG' pwsh -NoProfile -File '$STUB_DIR/ps-first-time-tty-driver.ps1'" /dev/null
364+
[[ "$status" -eq 0 ]]
365+
[[ "$output" == *"SETUP_OUTPUT_VISIBLE"* ]]
366+
[[ "$(cat "$PS_TTY_LOG")" == "stdin=tty stdout=tty stderr=tty" ]]
367+
run grep -F '[void](Invoke-FirstTimeSetup' "$INSTALL_PS1"
368+
[[ "$status" -ne 0 ]]
369+
}
370+
371+
@test "install.ps1 treats redirected stderr as non-interactive" {
372+
[[ "$(uname -s)" == "Linux" ]] || skip "PTY stream reproduction requires Linux"
373+
command -v pwsh >/dev/null 2>&1 || skip "pwsh not installed"
374+
command -v script >/dev/null 2>&1 || skip "script is required"
375+
376+
cat > "$STUB_DIR/ps-interactive-driver.ps1" <<'EOF'
377+
$tokens = $null; $parseErrors = $null
378+
$ast = [System.Management.Automation.Language.Parser]::ParseFile($env:INSTALL_PS1_PATH, [ref]$tokens, [ref]$parseErrors)
379+
if ($parseErrors.Count -gt 0) { throw "install.ps1 parse errors: $($parseErrors -join '; ')" }
380+
$fn = $ast.Find({ param($n) $n -is [System.Management.Automation.Language.FunctionDefinitionAst] -and $n.Name -eq 'Test-InteractiveSession' }, $true)
381+
if (-not $fn) { throw 'Test-InteractiveSession not found in install.ps1' }
382+
. ([scriptblock]::Create($fn.Extent.Text))
383+
"INTERACTIVE:$(Test-InteractiveSession)"
384+
EOF
385+
386+
run script -qec "INSTALL_PS1_PATH='$INSTALL_PS1' pwsh -NoProfile -File '$STUB_DIR/ps-interactive-driver.ps1' 2>'$STUB_DIR/ps-stderr.log'" /dev/null
387+
[[ "$status" -eq 0 ]]
388+
[[ "$output" == *"INTERACTIVE:False"* ]]
389+
}
390+
221391
# The Windows canary can never prove the ps1 belt — Credential Manager works
222392
# headlessly with or without it — so pin the behavior here. The function under
223393
# test is extracted from install.ps1's AST and evaluated alone: Main never

‎e2e/setup.bats‎

Lines changed: 41 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
#!/usr/bin/env bats
2-
# setup.bats - `basecamp setup` refuses to prompt when nothing can answer it.
2+
# setup.bats - `basecamp setup` refuses when first-time setup cannot run safely.
33
#
4-
# The wizard is prompts end to end, and huh runs them as a bubbletea program.
5-
# Redirecting stdin does not make that program fail: bubbletea sees a
6-
# non-terminal stdin and opens /dev/tty instead, so the prompt waits on the real
7-
# terminal — `basecamp setup --json < /dev/null` hung forever.
4+
# Recommended setup opens browser OAuth, while `--customize` also uses huh
5+
# prompts. Redirecting stdin does not make a bubbletea prompt fail: it can open
6+
# /dev/tty instead and wait on the real terminal. The setup gate keeps both
7+
# modes out of contexts that cannot complete them.
88
#
99
# Every case runs under a timeout, and the timeout is the assertion: exit 124 is
1010
# the bug reproducing. A unit test with a fake reader cannot catch this, because
@@ -68,6 +68,42 @@ assert_refused() {
6868
assert_refused
6969
}
7070

71+
@test "setup --customize refuses under --json with redirected stdin" {
72+
create_credentials
73+
create_global_config '{"account_id": 99999}'
74+
75+
run_guarded "basecamp setup --customize --json < /dev/null"
76+
assert_refused
77+
}
78+
79+
@test "setup --minimal refuses under --json with redirected stdin" {
80+
create_credentials
81+
create_global_config '{"account_id": 99999}'
82+
83+
run_guarded "basecamp setup --minimal --json < /dev/null"
84+
assert_refused
85+
}
86+
87+
@test "setup --project gives non-interactive config guidance" {
88+
create_credentials
89+
create_global_config '{"account_id": 99999}'
90+
91+
run_guarded "basecamp setup --project 123 --json < /dev/null"
92+
assert_not_timed_out
93+
assert_failure
94+
assert_json_value '.code' 'usage'
95+
assert_json_value '.hint | contains("basecamp config set project_id <id>")' 'true'
96+
assert_json_value '.hint | contains("--customize")' 'false'
97+
}
98+
99+
@test "setup rejects an unknown subcommand before onboarding" {
100+
run_guarded "basecamp setup codxe --json < /dev/null"
101+
assert_not_timed_out
102+
assert_failure
103+
assert_json_value '.error | contains("unknown command")' 'true'
104+
assert_json_value '.error | contains("interactive terminal")' 'false'
105+
}
106+
71107
@test "setup without --json and stdin closed refuses instead of hanging" {
72108
create_credentials
73109
create_global_config '{"account_id": 99999}'

0 commit comments

Comments
 (0)