Skip to content

fix(installer): cache-layout detection, tree-sitter dep, worker:status docs#2061

Closed
thedotmack wants to merge 2 commits intomainfrom
bugfix/installer-bugs
Closed

fix(installer): cache-layout detection, tree-sitter dep, worker:status docs#2061
thedotmack wants to merge 2 commits intomainfrom
bugfix/installer-bugs

Conversation

@thedotmack
Copy link
Copy Markdown
Owner

Summary

Test plan

  • Verify BranchManager provides helpful error for cache installs (path containing /cache/thedotmack/claude-mem/)
  • Verify update endpoint returns user-friendly error instead of crashing on cache-only installs
  • Verify switch endpoint returns user-friendly error instead of crashing on cache-only installs
  • Verify tree-sitter is in runtime dependencies in package.json
  • Verify documentation points to npx claude-mem commands instead of npm run worker:*

Closes #1928, closes #1929, closes #1930, closes #1931

🤖 Generated with Claude Code

…s docs

- Fix #1928: Detect cache-layout installs in BranchManager.getBranchInfo()
  and provide helpful error message instead of generic "not a git repository"
- Fix #1929: Guard update/switch endpoints in SettingsRoutes against missing
  marketplace directory to prevent crashes on cache-only installs
- Fix #1930: Add tree-sitter runtime to dependencies (was only in
  devDependencies via grammar packages) for Windows compatibility
- Fix #1931: Replace npm run worker:* commands in troubleshooting docs and
  openclaw SKILL.md with npx claude-mem equivalents that work from any
  directory without requiring a local package.json

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

coderabbitai Bot commented Apr 18, 2026

Warning

Rate limit exceeded

@thedotmack has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 5 minutes and 6 seconds before requesting another review.

Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 5 minutes and 6 seconds.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 4441b35b-1ed1-46e6-b281-ea55c2804f00

📥 Commits

Reviewing files that changed from the base of the PR and between c4bc8cd and 131518f.

📒 Files selected for processing (1)
  • src/services/worker/BranchManager.ts

Walkthrough

This pull request updates the installer to handle Claude Code cache-based installation layouts. Documentation was migrated from npm run worker:* to npx claude-mem commands. The tree-sitter runtime dependency was added to resolve missing grammar parser failures. BranchManager and SettingsRoutes were enhanced with cache-layout detection to provide targeted error messages instead of opaque git errors.

Changes

Cohort / File(s) Summary
Documentation CLI Updates
docs/public/troubleshooting.mdx, openclaw/SKILL.md
Replaced all npm run worker:* commands (status/logs/restart/start/stop) with npx claude-mem equivalents across troubleshooting sections and health-check workflows.
Dependency Addition
package.json
Added tree-sitter@^0.25.0 as a runtime dependency to resolve missing grammar parser for smart-explore skill.
Cache Layout Detection
src/services/worker/BranchManager.ts
Introduced isCacheLayoutInstall() check to detect cache-based installations; getBranchInfo() now returns tailored error messages for cache layouts; pullUpdates() propagates cache-specific error instead of generic git failure.
Preflight Installation Checks
src/services/worker/http/routes/SettingsRoutes.ts
Added MARKETPLACE_ROOT existence checks in /api/branch/switch and /api/branch/update handlers to detect and reject cache-only installations before attempting git operations.

Sequence Diagram

sequenceDiagram
    actor User as User
    participant PluginUI as Plugin UI
    participant Routes as SettingsRoutes
    participant BranchMgr as BranchManager
    participant FS as Filesystem

    User->>PluginUI: Click "Update now"
    PluginUI->>Routes: POST /api/branch/update
    Routes->>FS: Check MARKETPLACE_ROOT exists
    alt Cache-only install
        FS-->>Routes: Not found
        Routes-->>PluginUI: Error: cache-only installation
        PluginUI-->>User: Update unavailable (use npx claude-mem install)
    else Git-cloned install
        FS-->>Routes: Exists
        Routes->>BranchMgr: getBranchInfo()
        BranchMgr->>FS: Check .git directory
        alt Cache layout detected
            FS-->>BranchMgr: No .git found
            BranchMgr-->>Routes: Error with cache-layout guidance
        else Standard git layout
            FS-->>BranchMgr: .git exists
            BranchMgr-->>Routes: Branch info
            Routes->>BranchMgr: pullUpdates()
            BranchMgr-->>Routes: Success
        end
    end
Loading

Estimated Code Review Effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

🐰 A rabbit in caches and repos does dwell,
With npx commands and trees with good spell,
Cache layouts now known from git clones apart,
Smart errors guide users to play their own part!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main changes: cache-layout detection, tree-sitter dependency, and worker:status docs updates.
Description check ✅ Passed The description clearly relates to the changeset by explaining fixes for cache-layout detection, marketplace directory handling, tree-sitter dependency, and documentation updates.
Linked Issues check ✅ Passed The PR addresses all four linked issues: #1928 (cache-layout detection in BranchManager), #1929 (graceful handling of missing marketplace directory), #1930 (tree-sitter runtime dependency), and #1931 (documentation update from npm run worker:* to npx claude-mem).
Out of Scope Changes check ✅ Passed All changes are in scope: BranchManager improvements, SettingsRoutes checks, tree-sitter dependency, and documentation updates directly address the four linked issues without introducing unrelated modifications.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch bugfix/installer-bugs

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

@claude
Copy link
Copy Markdown

claude Bot commented Apr 18, 2026

Code Review

Overall: Clean, focused bug fix PR. Four well-scoped fixes addressing real user pain points. Ready to merge with minor notes below.


Overview

This PR fixes 4 issues:


Code Quality

BranchManager.ts — Solid approach.

  • isCacheLayoutInstall() is clean, pure, well-named, and handles Windows path normalization (replace(/\\/g, '/')) correctly.
  • The info.error || 'Cannot pull updates: not a git repository' fallback in pullUpdates() is a nice improvement — it preserves the contextual error from getBranchInfo() rather than discarding it.

SettingsRoutes.ts — Good guard placement.

  • The existsSync(MARKETPLACE_ROOT) check is correctly placed before the allowedBranches validation in both handlers, preventing crashes before any branch logic runs.
  • Reuses the shared MARKETPLACE_ROOT constant rather than constructing the path inline. ✓

Docs — Mechanical but complete. All npm run worker:* occurrences appear to be updated consistently.


Potential Issues

1. Cache path detection is fragile (minor)

return normalizedPath.includes('/cache/thedotmack/claude-mem');

This hardcodes the cache path structure. If Claude Code changes its cache directory layout (e.g., /caches/ vs /cache/, or a version-stamped subdirectory), this silently falls through to the generic "not a git repository" error. Consider exporting a CACHE_PLUGIN_PATH constant from paths.ts similar to MARKETPLACE_ROOT, so the detection uses the same canonical path that's used elsewhere.

2. Hardcoded allowed branches includes a feature branch

const allowedBranches = ['main', 'beta/7.0', 'feature/bun-executable'];

This existed before the PR, but feature/bun-executable looks like it shouldn't be user-facing. Low risk since it only gatekeeps a switch operation, but worth cleaning up.

3. Troubleshooting table still references cd to marketplace dir
In openclaw/SKILL.md, the troubleshooting table still has:

cd ~/.claude/plugins/marketplaces/thedotmack && npx claude-mem status

For cache-only installs, this cd would fail. Since npx claude-mem is intended to work from any directory, this could just be npx claude-mem status without the cd.


No Test Coverage

The test plan is manual only. isCacheLayoutInstall() is a pure function that would be easy to unit test with a few path patterns (standard git install, cache install, Windows-style paths). Not a blocker, but worth adding.


Security / Performance

No concerns. The existsSync guards are I/O-cheap for these infrequent HTTP endpoints. No user input is introduced unsanitized.


Summary: Approve with optional follow-ups on the cache path detection robustness and cleaning up feature/bun-executable from the allowed branches list. The core fixes are correct and the docs updates are thorough.

🤖 Generated with Claude Code

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented Apr 18, 2026

Greptile Summary

This PR fixes four issues: cache-layout install detection in BranchManager, graceful handling of missing marketplace directories in the update/switch HTTP endpoints, adding tree-sitter as a runtime dependency for Windows, and replacing npm run worker:* docs commands with npx claude-mem equivalents.

Confidence Score: 4/5

Safe to merge with the caveat that the cache-layout error message improvement (#1928) is a no-op due to the wrong path being checked.

Four of the five changes are straightforward and correct. The only functional issue is that isCacheLayoutInstall() checks a path that will never contain the cache substring, so #1928's user-facing improvement never activates. The other three fixes (#1929, #1930, #1931) work correctly and are low-risk.

src/services/worker/BranchManager.ts — isCacheLayoutInstall() needs to check getPackageRoot() instead of INSTALLED_PLUGIN_PATH.

Important Files Changed

Filename Overview
src/services/worker/BranchManager.ts Adds cache-layout detection, but isCacheLayoutInstall() checks MARKETPLACE_ROOT (a fixed computed path that never contains the cache substring) rather than getPackageRoot(), so the improved error message is dead code.
src/services/worker/http/routes/SettingsRoutes.ts Correctly guards both switch and update endpoints with existsSync(MARKETPLACE_ROOT) before proceeding with git operations, preventing crashes on cache-only installs.
package.json Adds tree-sitter ^0.25.0 to runtime dependencies for Windows grammar-package compatibility.
docs/public/troubleshooting.mdx All npm run worker:* references replaced with npx claude-mem equivalents that work from any directory.
openclaw/SKILL.md Same npm run worker:*npx claude-mem documentation fix applied to the SKILL.md file.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[GET /api/branch/status] --> B[getBranchInfo]
    B --> C{existsSync .git?}
    C -- No --> D{isCacheLayoutInstall?}
    D -- "Always false\n(checks wrong path)" --> E[Generic error:\nnot a git repository]
    D -- true --> F[Cache-layout error:\nuse npx claude-mem install]
    C -- Yes --> G[Return branch info]

    H[POST /api/branch/switch] --> I{existsSync MARKETPLACE_ROOT?}
    I -- No --> J[Return: cache-only install error]
    I -- Yes --> K{Valid branch?}
    K -- No --> L[400 Bad Request]
    K -- Yes --> M[switchBranch]

    N[POST /api/branch/update] --> O{existsSync MARKETPLACE_ROOT?}
    O -- No --> P[Return: cache-only install error]
    O -- Yes --> Q[pullUpdates]
Loading

Fix All in Claude Code

Reviews (1): Last reviewed commit: "fix(installer): cache-layout detection, ..." | Re-trigger Greptile

Comment on lines +107 to 113
*/
function isCacheLayoutInstall(): boolean {
const normalizedPath = INSTALLED_PLUGIN_PATH.replace(/\\/g, '/');
return normalizedPath.includes('/cache/thedotmack/claude-mem');
}

/**
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.

P1 isCacheLayoutInstall() always returns false

INSTALLED_PLUGIN_PATH is an alias for MARKETPLACE_ROOT, which is always computed as join(CLAUDE_CONFIG_DIR, 'plugins', 'marketplaces', 'thedotmack'). With the default CLAUDE_CONFIG_DIR of ~/.claude, the resulting path is ~/.claude/plugins/marketplaces/thedotmack — which never contains the substring /cache/thedotmack/claude-mem. The helpful "cache layout" error message will therefore never be shown; users will always see the generic fallback.

The detection should target the running package root (where this code actually executes) rather than the fixed installation target path. Checking getPackageRoot() would reflect whether the process was launched from a cache directory:

function isCacheLayoutInstall(): boolean {
  const normalizedPath = getPackageRoot().replace(/\\/g, '/');
  return normalizedPath.includes('/cache/thedotmack/claude-mem');
}

Fix in Claude Code

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

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 the current code and only fix it if needed.

Inline comments:
In `@src/services/worker/BranchManager.ts`:
- Around line 104-111: isCacheLayoutInstall currently checks
INSTALLED_PLUGIN_PATH (set to MARKETPLACE_ROOT) which will never match cache
installs; change the detection to inspect the actual module execution path
(e.g., derive the current file's directory from import.meta.url or __dirname at
runtime) instead of MARKETPLACE_ROOT. Update isCacheLayoutInstall to compute a
normalized runtime path (using fileURLToPath(import.meta.url) or equivalent),
then check that normalized path for the cache-layout substring (e.g.,
'/cache/thedotmack/claude-mem'); alternatively, check both INSTALLED_PLUGIN_PATH
and the runtime module path to preserve behavior across environments. Ensure
references remain to isCacheLayoutInstall, INSTALLED_PLUGIN_PATH and
MARKETPLACE_ROOT so reviewers can find the change.
🪄 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: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: dae4fbdd-9cc1-4c7e-8e9a-c05ff514caaa

📥 Commits

Reviewing files that changed from the base of the PR and between beea789 and c4bc8cd.

📒 Files selected for processing (5)
  • docs/public/troubleshooting.mdx
  • openclaw/SKILL.md
  • package.json
  • src/services/worker/BranchManager.ts
  • src/services/worker/http/routes/SettingsRoutes.ts

Comment thread src/services/worker/BranchManager.ts
INSTALLED_PLUGIN_PATH is an alias for MARKETPLACE_ROOT which always
resolves to ~/.claude/plugins/marketplaces/thedotmack — it never
contains '/cache/', so isCacheLayoutInstall() always returned false.

Now checks the actual runtime module path (__dirname or import.meta.url)
instead of the static MARKETPLACE_ROOT constant.

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

claude Bot commented Apr 18, 2026

Code Review

Overview

This PR fixes four related issues around cache-layout installs, Windows tree-sitter compatibility, and stale documentation. The changes are focused, non-breaking, and address real user-facing pain points. No concerns blocking merge — a few notes below.


src/services/worker/BranchManager.ts

Good:

  • The JSDoc on isCacheLayoutInstall() is justified — the explanation that INSTALLED_PLUGIN_PATH/MARKETPLACE_ROOT is a fixed alias and won't contain /cache/ is genuinely non-obvious and worth documenting.
  • The typeof __dirname !== 'undefined' guard correctly handles both CJS and ESM module contexts in the compiled output.
  • Reusing info.error in pullUpdates() (line ~290) instead of repeating a hardcoded message is a clean improvement.

Suggestions:

  1. Path heuristic fragilitynormalizedRuntimePath.includes('/cache/thedotmack/claude-mem/') is a string match against the hardcoded org/repo name. If the plugin is ever renamed or the org changes, this silently stops working. Consider extracting the path fragment to a named constant so it's easy to locate and update:

    const CACHE_LAYOUT_PATH_MARKER = '/cache/thedotmack/claude-mem/';
  2. Windows path edge caseruntimeDir.replace(/\\/g, '/') normalizes backslashes before the .includes() check, which is correct. Worth a brief inline note since it's a subtle correctness detail that the next reader might question.


src/services/worker/http/routes/SettingsRoutes.ts

Good:

Suggestion:

  1. Duplicated guard — The identical existsSync(MARKETPLACE_ROOT) block appears in both handleSwitchBranch and handleUpdateBranch. A small private helper would keep this DRY and make future changes (e.g., changing the error message) a single edit:
    private requiresMarketplaceDir(res: Response): boolean {
      if (!existsSync(MARKETPLACE_ROOT)) {
        res.json({ success: false, error: 'Marketplace directory not found...' });
        return false;
      }
      return true;
    }
    Not a blocker, but worth noting since both handlers are already using the wrapHandler pattern.

package.json

  1. tree-sitter version^0.25.0 is added to runtime dependencies. Two questions worth confirming before merge:
    • Was it previously in devDependencies (and therefore omitted from installs)? If so, this is the right fix.
    • Is ^0.25.0 compatible with the grammar packages already in use? The tree-sitter native addon has a strict ABI contract with grammar packages — a major-minor mismatch causes runtime crashes. Worth verifying the grammar packages in the project are aligned with this version.

Documentation (troubleshooting.mdx, openclaw/SKILL.md)

Good:

  • All 30+ replacements of npm run worker:*npx claude-mem are consistent and correct.
  • The npx claude-mem form works from any directory, which is a genuine UX improvement for users who aren't in the repo root.

Minor nit:

  1. In openclaw/SKILL.md troubleshooting table (line ~421), the cd ~/.claude/plugins/marketplaces/thedotmack && prefix is still present before the updated npx claude-mem status command. Since npx claude-mem works from any directory, the cd prefix is now unnecessary and slightly misleading:
    - | Worker started from Claude Code install but not responding | Check `cd ~/.claude/plugins/marketplaces/thedotmack && npx claude-mem status`. May need `npx claude-mem restart`. |
    + | Worker started from Claude Code install but not responding | Check `npx claude-mem status`. May need `npx claude-mem restart`. |

Summary

Area Verdict
Cache layout detection logic ✅ Correct, minor naming suggestion
Crash prevention on cache-only installs ✅ Solid early-return guards
Duplicate guard blocks ⚠️ Minor — consider a private helper
tree-sitter runtime dep ⚠️ Verify ABI compatibility with grammar packages
Doc/skill command updates ✅ Consistent, stale cd prefix in one table cell

Overall this is a solid set of defensive fixes. The cache-layout detection and crash prevention are the most impactful changes and look correct.

🤖 Generated with Claude Code

@thedotmack
Copy link
Copy Markdown
Owner Author

Closing to start fresh from main — will redo fixes isolated in Docker container.

@thedotmack thedotmack closed this Apr 20, 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

1 participant