Skip to content

[codex] Add CLI path visibility guidance#1053

Closed
TabishB wants to merge 1 commit into
mainfrom
codex/cli-path-troubleshooting
Closed

[codex] Add CLI path visibility guidance#1053
TabishB wants to merge 1 commit into
mainfrom
codex/cli-path-troubleshooting

Conversation

@TabishB

@TabishB TabishB commented May 5, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Document the general PATH mismatch pattern for editors, agents, GUI apps, and automation in the installation guide.
  • Add postinstall detection for global installs where a detected OpenSpec CLI bin directory is not on PATH, with a troubleshooting link.
  • Prepend generated OpenSpec skills with CLI visibility guidance and update onboarding preflight to support OPENSPEC_BIN or an absolute executable path.
  • Add a patch changeset and update focused tests/parity baselines.

Why

OpenSpec can be installed correctly while still being unavailable to an agent or editor shell because that process inherits a different PATH than the user's terminal. The fix is to explain the package-manager-bin pattern generally and make generated workflows less likely to treat command not found as proof that OpenSpec is not installed.

Validation

  • pnpm lint
  • pnpm test
  • pnpm build
  • bash scripts/test-postinstall.sh
  • pnpm vitest run test/core/shared/skill-generation.test.ts test/core/templates/skill-templates-parity.test.ts
  • pnpm exec changeset status --since=origin/main

Summary by CodeRabbit

Release Notes

  • New Features

    • Installation now detects when OpenSpec CLI is missing from PATH and provides diagnostic guidance to resolve visibility issues
    • Generated workflows include CLI visibility guidance with instructions for using the OPENSPEC_BIN environment variable or absolute paths as workarounds
  • Documentation

    • Added troubleshooting section explaining why OpenSpec may work in terminal but fail in editors, agents, or automation tools due to differing PATH values

@coderabbitai

coderabbitai Bot commented May 5, 2026

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

This PR enhances OpenSpec with PATH visibility diagnostics that detect when the OpenSpec CLI bin directory is not on the system PATH (especially during global installations), generate troubleshooting guidance in the postinstall script and skill generation, and update onboard workflow templates to check CLI visibility via shell environment variables.

Changes

PATH Visibility Detection & Guidance

Layer / File(s) Summary
Documentation & Changelog
.changeset/clear-path-hints.md, docs/installation.md
Added patch changeset entry for CLI PATH mismatch reporting. New "Troubleshooting PATH Visibility" section documents why openspec --version works in terminals but fails in editors/agents, with shell commands to locate global bin directories and verify executables.
Diagnostic Logic
scripts/postinstall.js
Expanded postinstall script with PATH-visibility detection: gathers candidate CLI bin directories from npm/pnpm/bun environment variables, checks which exist but are not on current PATH, and prints multi-line hint with missing directories. Includes helpers for env parsing, PATH normalization, and executable detection via fs.access(..., X_OK).
Postinstall Testing
scripts/test-postinstall.sh
Added Test 2 scenario simulating global install with CLI bin missing from PATH by creating temporary directories, stubbing openspec executable, constraining PATH, and verifying hint output. Extended environment restoration to revert npm_config_global, npm_config_prefix, and PATH.
Skill Generation Integration
src/core/shared/skill-generation.ts
Added DEFAULT_COMPATIBILITY and OPENSPEC_CLI_VISIBILITY_GUIDANCE constants. Updated generateSkillContent to compute compatibility from templates and conditionally prepend CLI visibility guidance block to skill YAML when compatibility mentions "openspec cli".
Onboard Template Updates
src/core/templates/workflows/onboard.ts
Updated preflight section to detect CLI via OPENSPEC_BIN environment variable (default openspec), verify visibility with command -v/-x, emit CLI_NOT_ON_PATH when unavailable, and added Windows/PowerShell check examples as guidance.
Tests & Verification
test/core/shared/skill-generation.test.ts, test/core/templates/skill-templates-parity.test.ts
Extended skill generation tests to assert OpenSpec CLI visibility guidance section and OPENSPEC_BIN placeholder in generated output. Added dedicated test verifying CLI visibility prepend for skills requiring CLI. Updated baseline SHA-256 hashes in parity tests for modified templates and generated skill content.

Sequence Diagram

sequenceDiagram
    actor User
    participant NPM Install
    participant Postinstall Script
    participant Skill Generator
    participant Shell
    participant User Shell

    User->>NPM Install: npm install -g `@fission-ai/openspec`
    NPM Install->>Postinstall Script: Trigger postinstall hook
    Postinstall Script->>Postinstall Script: Detect if global install
    Postinstall Script->>Postinstall Script: Gather npm/pnpm/bun bin directories
    Postinstall Script->>Postinstall Script: Check if bin dirs exist<br/>and are missing from PATH
    Postinstall Script->>User: Print PATH visibility hint<br/>(if missing dirs detected)
    
    Note over Skill Generator,User Shell: Later: During skill generation
    Skill Generator->>Skill Generator: Check if compatibility<br/>mentions "openspec cli"
    Skill Generator->>Skill Generator: Prepend CLI visibility<br/>guidance to YAML
    Skill Generator->>User: Generated skill with<br/>PATH troubleshooting
    
    User->>User Shell: Execute generated skill
    User Shell->>Shell: Check OPENSPEC_BIN<br/>or openspec via command -v
    Shell-->>User Shell: CLI visibility status
    User Shell->>User: Print CLI_NOT_ON_PATH<br/>if not found
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~50 minutes

Possibly related PRs

  • Fission-AI/OpenSpec#637: Modifies onboarding preflight checks to detect the OpenSpec CLI with explicit version/visibility checks.
  • Fission-AI/OpenSpec#574: Introduces skill/template generation and onboarding workflow files that this PR builds upon.
  • Fission-AI/OpenSpec#892: Directly modifies the same onboarding workflow template and updates related parity test hashes.

Suggested reviewers

  • alfred-openspec

Poem

🐰 A bunny hops through install,
Finding CLI bins tucked away in PATH's great hall,
"Fear not!" squeaks the hint, "we shall guide,
With visibility checks and nowhere to hide!" 🛤️✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 12.50% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely summarizes the main change: adding CLI path visibility guidance across documentation, postinstall scripts, and generated skills.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/cli-path-troubleshooting

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
scripts/test-postinstall.sh (1)

29-47: ⚡ Quick win

Add an assertion for the expected PATH hint output.

Line 29 introduces a new scenario, but it currently does not verify that the hint text is actually emitted. That makes this test a smoke run instead of a regression check.

Suggested test hardening
 TMP_PREFIX="$(mktemp -d)"
 TMP_HOME="$(mktemp -d)"
 mkdir -p "$TMP_PREFIX/bin"
 printf '#!/bin/sh\nexit 0\n' > "$TMP_PREFIX/bin/openspec"
 chmod +x "$TMP_PREFIX/bin/openspec"
 unset CI
 unset OPENSPEC_NO_COMPLETIONS
 export npm_config_global=true
 export npm_config_prefix="$TMP_PREFIX"
-HOME="$TMP_HOME" PNPM_HOME="$TMP_HOME/no-pnpm" PATH="/usr/bin:/bin" "$NODE_BIN" scripts/postinstall.js
+OUTPUT="$(HOME="$TMP_HOME" PNPM_HOME="$TMP_HOME/no-pnpm" PATH="/usr/bin:/bin" "$NODE_BIN" scripts/postinstall.js)"
+echo "$OUTPUT"
+if [[ "$OUTPUT" != *"not on PATH"* ]]; then
+  echo "Expected PATH visibility hint was not printed"
+  exit 1
+fi
 rm -rf "$TMP_PREFIX"
 rm -rf "$TMP_HOME"
 unset npm_config_global
 unset npm_config_prefix
 export PATH="$ORIGINAL_PATH"
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@scripts/test-postinstall.sh` around lines 29 - 47, The new Test 2 runs the
postinstall.js scenario but doesn't assert that the PATH hint was printed;
capture the command output when invoking HOME="$TMP_HOME"
PNPM_HOME="$TMP_HOME/no-pnpm" PATH="/usr/bin:/bin" "$NODE_BIN"
scripts/postinstall.js (e.g., redirect stdout/stderr to a temp file or variable)
and add an assertion that the output contains the expected PATH hint text
emitted by scripts/postinstall.js (search for the specific hint substring your
postinstall prints, e.g., "add to your PATH" or similar) so the test fails if
the hint is missing; keep teardown (rm -rf and env unsets) unchanged.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/core/templates/workflows/onboard.ts`:
- Around line 31-33: The check combining command -v and [ -x "$OPENSPEC_CMD" ]
can yield false positives when OPENSPEC_CMD is a bare name (e.g., "openspec")
that is executable only in the current directory; change the condition to only
use -x when OPENSPEC_CMD is a path (contains a slash) and otherwise rely on
command -v. Concretely, update the if that references OPENSPEC_CMD to: if
command -v "$OPENSPEC_CMD" >/dev/null 2>&1 || { [[ "$OPENSPEC_CMD" == */* ]] &&
[ -x "$OPENSPEC_CMD" ]; }; then ... so the script emits the intended
CLI_NOT_ON_PATH when a bare command name isn't on PATH.

---

Nitpick comments:
In `@scripts/test-postinstall.sh`:
- Around line 29-47: The new Test 2 runs the postinstall.js scenario but doesn't
assert that the PATH hint was printed; capture the command output when invoking
HOME="$TMP_HOME" PNPM_HOME="$TMP_HOME/no-pnpm" PATH="/usr/bin:/bin" "$NODE_BIN"
scripts/postinstall.js (e.g., redirect stdout/stderr to a temp file or variable)
and add an assertion that the output contains the expected PATH hint text
emitted by scripts/postinstall.js (search for the specific hint substring your
postinstall prints, e.g., "add to your PATH" or similar) so the test fails if
the hint is missing; keep teardown (rm -rf and env unsets) unchanged.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: d995b2eb-3b4b-44e7-84ca-329246896758

📥 Commits

Reviewing files that changed from the base of the PR and between f510581 and 7e5054f.

📒 Files selected for processing (8)
  • .changeset/clear-path-hints.md
  • docs/installation.md
  • scripts/postinstall.js
  • scripts/test-postinstall.sh
  • src/core/shared/skill-generation.ts
  • src/core/templates/workflows/onboard.ts
  • test/core/shared/skill-generation.test.ts
  • test/core/templates/skill-templates-parity.test.ts

Comment on lines +31 to +33
OPENSPEC_CMD="\${OPENSPEC_BIN:-openspec}"
if command -v "$OPENSPEC_CMD" >/dev/null 2>&1 || [ -x "$OPENSPEC_CMD" ]; then
"$OPENSPEC_CMD" --version

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Avoid false positives from -x on bare command names.

Line 32 can incorrectly pass when openspec exists only in the current directory (not on PATH). That can cause Line 33 to fail instead of emitting CLI_NOT_ON_PATH.

Suggested fix
 OPENSPEC_CMD="${OPENSPEC_BIN:-openspec}"
-if command -v "$OPENSPEC_CMD" >/dev/null 2>&1 || [ -x "$OPENSPEC_CMD" ]; then
+if command -v "$OPENSPEC_CMD" >/dev/null 2>&1; then
+  "$OPENSPEC_CMD" --version
+elif [ "${OPENSPEC_CMD#*/}" != "$OPENSPEC_CMD" ] && [ -x "$OPENSPEC_CMD" ]; then
   "$OPENSPEC_CMD" --version
 else
   echo "CLI_NOT_ON_PATH"
 fi
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
OPENSPEC_CMD="\${OPENSPEC_BIN:-openspec}"
if command -v "$OPENSPEC_CMD" >/dev/null 2>&1 || [ -x "$OPENSPEC_CMD" ]; then
"$OPENSPEC_CMD" --version
OPENSPEC_CMD="${OPENSPEC_BIN:-openspec}"
if command -v "$OPENSPEC_CMD" >/dev/null 2>&1; then
"$OPENSPEC_CMD" --version
elif [ "${OPENSPEC_CMD#*/}" != "$OPENSPEC_CMD" ] && [ -x "$OPENSPEC_CMD" ]; then
"$OPENSPEC_CMD" --version
else
echo "CLI_NOT_ON_PATH"
fi
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/core/templates/workflows/onboard.ts` around lines 31 - 33, The check
combining command -v and [ -x "$OPENSPEC_CMD" ] can yield false positives when
OPENSPEC_CMD is a bare name (e.g., "openspec") that is executable only in the
current directory; change the condition to only use -x when OPENSPEC_CMD is a
path (contains a slash) and otherwise rely on command -v. Concretely, update the
if that references OPENSPEC_CMD to: if command -v "$OPENSPEC_CMD" >/dev/null
2>&1 || { [[ "$OPENSPEC_CMD" == */* ]] && [ -x "$OPENSPEC_CMD" ]; }; then ... so
the script emits the intended CLI_NOT_ON_PATH when a bare command name isn't on
PATH.

@TabishB TabishB closed this May 5, 2026
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