Skip to content

fix(community-tool): resolve installed CodeGraph binary path#1068

Open
skiveldev wants to merge 2 commits into
Gentleman-Programming:mainfrom
skiveldev:fix/codegraph-install-path-resolution
Open

fix(community-tool): resolve installed CodeGraph binary path#1068
skiveldev wants to merge 2 commits into
Gentleman-Programming:mainfrom
skiveldev:fix/codegraph-install-path-resolution

Conversation

@skiveldev

@skiveldev skiveldev commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Summary

  • resolves the installed CodeGraph executable from npm/pnpm global bin when codegraph is not yet in PATH
  • runs codegraph install --yes through the resolved executable path while keeping PATH status honest
  • surfaces follow-up/manual guidance when setup succeeds but direct codegraph usage still requires PATH refresh

Context

Closes #1003.

This is intentionally narrower than #1059, which focuses on version-aware upgrade/reconcile behavior. This PR only fixes the post-install executable resolution path for environments where npm/pnpm global bin is not available to the non-interactive Gentle AI process.

Tests

  • go test ./internal/components/communitytool
  • go test ./internal/cli -run CommunityTool
  • git diff --check

Summary by CodeRabbit

  • New Features

    • Enhanced CodeGraph installer to auto-detect whether npm or pnpm is available, install globally accordingly, and then resolve the codegraph CLI by checking PATH and common global-bin locations (OS-aware).
  • Bug Fixes

    • Improved handling when CodeGraph is present but the CLI isn’t yet on PATH, including clearer follow-up/manual guidance.
    • Improved install status validation for detected agents configuration.
    • Better error reporting now surfaces the exact command that failed.
  • Tests

    • Expanded coverage for setup-command resolution, global-bin detection, OS-specific candidate paths, and end-to-end install behaviors.

@coderabbitai

coderabbitai Bot commented Jul 9, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The CodeGraph install flow now detects the package manager, runs the matching global install command, resolves a setup command from PATH or global-bin candidates, and rechecks status after setup. Validation was split into a dedicated helper, and tests cover PATH fallback and OS-specific global-bin behavior.

Changes

CodeGraph install and setup resolution

Layer / File(s) Summary
Setup command and global-bin resolution helpers
internal/components/communitytool/tool.go
Adds imports, a codeGraphNpmGlobalBin hook, npm global-bin resolution, and CodeGraph executable candidate generation used by setup command resolution.
InstallWithHome flow rewrite and validation
internal/components/communitytool/tool.go
Rewrites the install branch to run the package-manager install command, resolve and run a setup command via PATH or global-bin candidates, re-detect status, conditionally emit follow-up instructions, and delegate validation through the detected-agents helper.
Tests for setup resolution and install behavior
internal/components/communitytool/tool_test.go
Extends stubs and adds tests for setup-command resolution, executable candidate generation, npm global-bin OS mapping, and install behavior when the resolved binary is still missing from PATH.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Sequence Diagram(s)

sequenceDiagram
  participant InstallWithHome
  participant PackageManager
  participant Runner
  participant Detector

  InstallWithHome->>PackageManager: detect package manager
  InstallWithHome->>Runner: run global install command
  InstallWithHome->>Detector: resolveCodeGraphSetupCommand
  Detector-->>InstallWithHome: setup command (PATH or global-bin candidate)
  InstallWithHome->>Runner: run setup command
  InstallWithHome->>Detector: re-detect status
  InstallWithHome->>InstallWithHome: validateCodeGraphDetectedAgentsConfigured
Loading

Possibly related issues

  • Gentle-Programming/gentle-ai#984: Changes the same CodeGraph community-tool install/reconcile flow in internal/components/communitytool/tool.go.

Possibly related PRs

Suggested labels: type:bug

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% 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 states the main change: resolving the installed CodeGraph binary path.
Linked Issues check ✅ Passed The changes address #1003 by resolving CodeGraph via npm/pnpm global bin when PATH lookup fails.
Out of Scope Changes check ✅ Passed The pnpm support, status refactor, and tests all support the install-path resolution fix.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 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 `@internal/components/communitytool/tool.go`:
- Around line 173-184: The branch in tool.go that handles unavailable CLI status
should be simplified to avoid re-checking the same `after.CLI !=
AvailabilityAvailable && setupCommand[0] != "codegraph"` condition and the
redundant `len(after.FollowUps) > 0` guard. In `DetectStatus`/the setup flow,
capture the PATH guidance string once when you append it to `after.FollowUps`,
then reuse that stored message for `result.ManualActions` instead of re-fetching
`after.FollowUps[len(after.FollowUps)-1]`. This keeps
`validateCodeGraphDetectedAgentsConfigured` and the manual actions logic stable
even if more follow-ups are added later.
🪄 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: Repository UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: e361fc80-a395-4b25-9195-ca9ef1bcbc00

📥 Commits

Reviewing files that changed from the base of the PR and between 61bcfc4 and 6e361d7.

📒 Files selected for processing (2)
  • internal/components/communitytool/tool.go
  • internal/components/communitytool/tool_test.go

Comment thread internal/components/communitytool/tool.go

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
internal/components/communitytool/tool.go (2)

169-169: 🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win

Add a backup/restore path before writing user config
InjectCodeGraphGuidanceIfSelected mutates files under homeDir via filemerge.WriteFileAtomic, but there’s no snapshot/restore path around that change. Atomic replacement avoids partial writes; it doesn’t preserve the previous config for rollback.

🤖 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 `@internal/components/communitytool/tool.go` at line 169, Wrap the
configuration update in a backup/restore flow around
InjectCodeGraphGuidanceIfSelected in tool.go so the user’s existing config under
homeDir can be restored if the write fails or the injection is only partially
applied. Before calling InjectCodeGraphGuidanceIfSelected, snapshot the affected
config state; on error, restore the snapshot and surface the failure. Keep the
change localized to the code path that calls InjectCodeGraphGuidanceIfSelected
and the WriteFileAtomic-backed mutation logic.

Source: Path instructions


152-186: 🩺 Stability & Availability | 🟠 Major | 🏗️ Heavy lift

Make CodeGraph setup converge instead of reinstalling on every run

The reconcile gate still depends on LookPath("codegraph"), so a package-manager install that leaves the global bin off PATH is always treated as “missing.” That makes npm/pnpm add -g … and the setup command rerun on every invocation instead of becoming a no-op after the first successful setup.

The guidance write also mutates user config without a backup/restore path; add one before overwriting prompt files.

🤖 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 `@internal/components/communitytool/tool.go` around lines 152 - 186, The
CodeGraph reconcile flow is still keying off direct availability of `codegraph`,
so a successful package-manager install/setup can be retriggered forever when
the global bin is not on PATH. Update the detection/reconcile logic in
`detectCodeGraphPackageManager`, `codeGraphPackageInstallCommand`,
`resolveCodeGraphSetupCommand`, and the `DetectStatus`/`pathFollowUp` handling
so a previously completed setup is recognized as converged and treated as a
no-op on later runs. Also add a backup/restore path around
`InjectCodeGraphGuidanceIfSelected` before any prompt/config files are
overwritten, so user config is preserved if the write needs to be reverted.

Source: Path instructions

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

Outside diff comments:
In `@internal/components/communitytool/tool.go`:
- Line 169: Wrap the configuration update in a backup/restore flow around
InjectCodeGraphGuidanceIfSelected in tool.go so the user’s existing config under
homeDir can be restored if the write fails or the injection is only partially
applied. Before calling InjectCodeGraphGuidanceIfSelected, snapshot the affected
config state; on error, restore the snapshot and surface the failure. Keep the
change localized to the code path that calls InjectCodeGraphGuidanceIfSelected
and the WriteFileAtomic-backed mutation logic.
- Around line 152-186: The CodeGraph reconcile flow is still keying off direct
availability of `codegraph`, so a successful package-manager install/setup can
be retriggered forever when the global bin is not on PATH. Update the
detection/reconcile logic in `detectCodeGraphPackageManager`,
`codeGraphPackageInstallCommand`, `resolveCodeGraphSetupCommand`, and the
`DetectStatus`/`pathFollowUp` handling so a previously completed setup is
recognized as converged and treated as a no-op on later runs. Also add a
backup/restore path around `InjectCodeGraphGuidanceIfSelected` before any
prompt/config files are overwritten, so user config is preserved if the write
needs to be reverted.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 2aeb4608-fb0a-4dbc-a5cc-6735bafd2bd9

📥 Commits

Reviewing files that changed from the base of the PR and between 6e361d7 and e458950.

📒 Files selected for processing (1)
  • internal/components/communitytool/tool.go

@skiveldev

Copy link
Copy Markdown
Contributor Author

Thanks for the review. The remaining GitHub check is only the required �0type:*�0 label. This PR is a bug fix for #1003, so �0type:bug�0 should be the right label when a maintainer has a chance to add it.

On the two new CodeRabbit outside-diff notes: I agree they point at useful follow-up hardening, but I’d keep them out of this PR for scope. The backup/restore path is broader config-write safety work, and the repeated-reconcile/no-op behavior overlaps with the existing CodeGraph reconcile work being discussed separately. This PR stays focused on resolving the installed CodeGraph binary path after global npm/pnpm install.

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.

FAILED: community-tool:codegraph — install

1 participant