Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions .cursor/rules/codebase-memory.mdc
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
---
description: Codebase Memory graph-first repository intelligence policy
globs: **/*

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🔴 Critical | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

ruby <<'RUBY'
require "yaml"
text = File.read(".cursor/rules/codebase-memory.mdc")
frontmatter = text[/\A---\n(.*?)\n---/m, 1]
abort "missing front matter" unless frontmatter
YAML.safe_load(frontmatter)
puts "valid"
RUBY

Repository: barisbagirlar-web/SectorCalc

Length of output: 625


Quote the globs pattern.

globs: **/* is invalid YAML because plain scalars cannot begin with the * alias indicator, and Cursor may fail to load this rule. Use globs: "**/*" instead.

🤖 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 @.cursor/rules/codebase-memory.mdc at line 3, Quote the glob pattern in the
frontmatter by updating the globs configuration from an unquoted **/* value to a
quoted "**/*" value, preserving the existing pattern while ensuring valid YAML
parsing.

alwaysApply: true
---
# Codebase Memory MCP Policy

Codebase Memory is an advisory repository-intelligence layer. Source code, schemas, tests, DECISIONS.md, AGENTS.md, and existing project rules remain authoritative.

## Mandatory workflow

For architecture discovery, dependency tracing, blast-radius analysis, or any change that can affect multiple files:

1. Use Codebase Memory first when the MCP server is available.
2. Establish current architecture with `get_architecture` when the session lacks fresh repository context.
3. Locate symbols and relationships with `search_graph` and `trace_path` instead of broad repeated file reads.
4. Before editing, determine the affected surface and read the actual source files that will be changed.
5. Never treat graph output as authorization to violate `.cursorrules`, `DECISIONS.md`, `AGENTS.md`, sealed boundaries, or user scope.
6. After editing, run `detect_changes` to inspect blast radius when Codebase Memory is available.
7. Run the repository's existing verification gates from `AGENTS.md` and `.cursorrules`. Graph analysis never replaces schema validation, tests, checks, builds, or language validation.

## Failure behavior

- If the graph is missing, stale, degraded, or lacks coverage for a relevant path, fall back to direct source search/read and continue safely.
- Dynamic behavior not represented in the graph must be verified from source and tests.
- A clean graph result means only that no relationship was recorded; it is not proof that no dependency exists.
- Never modify code solely from graph summaries without reading the target implementation.

## Persistence

- `auto_index=true` is recommended.
- `auto_watch=true` is recommended.
- Do not commit `.codebase-memory/graph.db.zst` or any generated graph artifact unless the user explicitly requests a team-shared graph snapshot.

## Invariant

SOURCE + PROJECT RULES + TESTS = SSOT.
CODEBASE MEMORY = DERIVED NAVIGATION AND IMPACT INTELLIGENCE ONLY.
25 changes: 25 additions & 0 deletions scripts/setup-codebase-memory.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
$ErrorActionPreference = 'Stop'

$repoRoot = (git rev-parse --show-toplevel).Trim()
if (-not $repoRoot) { throw 'Unable to resolve repository root.' }

if (-not (Get-Command codebase-memory-mcp -ErrorAction SilentlyContinue)) {
$installer = Join-Path $env:TEMP ("cbm-install-{0}.ps1" -f [guid]::NewGuid().ToString('N'))
try {
Invoke-WebRequest -Uri 'https://raw.githubusercontent.com/DeusData/codebase-memory-mcp/main/install.ps1' -OutFile $installer
Unblock-File $installer -ErrorAction SilentlyContinue
& powershell -NoProfile -ExecutionPolicy Bypass -File $installer
Comment on lines +9 to +11

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔒 Security & Privacy | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

printf 'Repository files matching setup scripts:\n'
fd -a 'setup-codebase-memory\.(ps1|sh)$' . || true

printf '\nscripts/setup-codebase-memory.ps1:\n'
if [ -f scripts/setup-codebase-memory.ps1 ]; then
  cat -n scripts/setup-codebase-memory.ps1
fi

printf '\nscripts/setup-codebase-memory.sh:\n'
if [ -f scripts/setup-codebase-memory.sh ]; then
  cat -n scripts/setup-codebase-memory.sh
fi

printf '\nAny related README/security/codebase-memory docs:\n'
rg -n --hidden --glob '!*.lock' --glob '!node_modules/**' --glob '!dist/**' --glob '!build/**' \
  'codebase-memory|install\.ps1|install\.sh|setup-codebase-memory|raw\.githubusercontent\.com/DeusData' . || true

Repository: barisbagirlar-web/SectorCalc

Length of output: 4333


Pin and verify the upstream installer in both bootstrap scripts.

Both scripts execute code downloaded from main (install.ps1/install.sh) before running it, so a compromised or modified upstream branch would execute arbitrary bootstrapping code. Pin the installer source to an immutable reviewed tag/release or commit, and check its digest/attestation before invoking PowerShell or Bash.

📍 Affects 2 files
  • scripts/setup-codebase-memory.ps1#L9-L11 (this comment)
  • scripts/setup-codebase-memory.sh#L9-L12
🤖 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/setup-codebase-memory.ps1` around lines 9 - 11, The bootstrap scripts
execute unpinned upstream installers without integrity verification. In
scripts/setup-codebase-memory.ps1 lines 9-11 and
scripts/setup-codebase-memory.sh lines 9-12, change the installer URLs from the
mutable main branch to the same immutable reviewed tag, release, or commit,
verify each downloaded installer against its reviewed digest or attestation, and
invoke PowerShell or Bash only after verification succeeds.

}
finally {
Remove-Item $installer -Force -ErrorAction SilentlyContinue
}
}

codebase-memory-mcp config set auto_index true
Comment on lines +6 to +18

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== repository files =="
git ls-files | rg 'scripts/setup-codebase-memory\.(ps1|sh)$|scripts/|README|AGENTS|CODEBASE|DECISIONS' || true

echo
echo "== setup script snippets =="
for f in scripts/setup-codebase-memory.ps1 scripts/setup-codebase-memory.sh; do
  if [ -f "$f" ]; then
    echo "--- $f ---"
    nl -ba "$f" | sed -n '1,120p'
  fi
done

echo
echo "== references to codebase-memory-mcp =="
rg -n "codebase-memory-mcp|INSTALLER|PATH|\\\$env:PATH|export PATH|\\.local/bin|mcp" . --glob '!node_modules/**' --glob '!dist/**' --glob '!build/**' || true

Repository: barisbagirlar-web/SectorCalc

Length of output: 851


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== setup script snippets =="
for f in scripts/setup-codebase-memory.ps1 scripts/setup-codebase-memory.sh; do
  if [ -f "$f" ]; then
    echo "--- $f ---"
    awk '{printf "%6d  %s\n", NR, $0}' "$f" | sed -n '1,120p'
  else
    echo "missing $f"
  fi
done

echo
echo "== references to codebase-memory-mcp and path/install vars =="
grep -RInEi "codebase-memory-mcp|INSTALLER|PATH|\\\$env:PATH|export PATH|\\.local/bin|mcp" . --exclude-dir=node_modules --exclude-dir=dist --exclude-dir=build || true

echo
echo "== inspect install scripts from upstream (read-only) =="
python3 - <<'PY'
import urllib.request
urls = [
    ("https://raw.githubusercontent.com/DeusData/codebase-memory-mcp/main/install.ps1", "scripts/setup-codebase-memory.ps1"),
    ("https://raw.githubusercontent.com/DeusData/codebase-memory-mcp/main/install.sh", "scripts/setup-codebase-memory.sh"),
]
for url, context in urls:
    print(f"--- upstream {context} depends on {url} ---")
    try:
        with urllib.request.urlopen(url, timeout=20) as r:
            text = r.read().decode("utf-8", "replace")
        for i, line in enumerate(text.splitlines(), 1):
            if any(s in line.lower() for s in ["bin", "programfiles", "appdata", "local", "path", "cp", "copy", "chmod", "codebase-memory-mcp"]):
                print(f"{i}: {line}")
    except Exception as e:
        print(f"ERROR: {e}")
PY

Repository: barisbagirlar-web/SectorCalc

Length of output: 50384


🌐 Web query:

github DeusData codebase-memory-mcp install.ps1 install.sh install directory PATH bin

💡 Result:

DeusData codebase-memory-mcp is a high-performance, single-binary Model Context Protocol (MCP) server that indexes codebases into a persistent knowledge graph [1][2]. Installation is handled via platform-specific scripts provided in the GitHub repository [1][3]. Installation Scripts and Directories: - macOS and Linux: Uses install.sh, which defaults to installing the binary in $HOME/.local/bin [4][5]. You can specify a custom installation directory using the --dir flag (e.g., curl -fsSL... | bash -s -- --dir /custom/path) [4][5]. - Windows: Uses install.ps1, which typically installs to $env:LOCALAPPDATA\Programs\codebase-memory-mcp [6]. PATH Configuration: After installation, the installer checks if the target directory is in your system PATH [4][6][5]. If it is not, the installer will typically warn you and provide the command to add it to your shell configuration (e.g., ~/.bashrc, ~/.zshrc, or the Windows User PATH environment variable) [4][6][5][7]. Usage: Once installed, you can configure your AI coding agents by running the following command in your terminal [8]: codebase-memory-mcp install For further configuration or to install the UI variant (with graph visualization), refer to the official repository documentation [2][4].

Citations:


🏁 Script executed:

#!/bin/bash
set -euo pipefail

python3 - <<'PY'
import urllib.request

urls = [
    "https://raw.githubusercontent.com/DeusData/codebase-memory-mcp/main/install.ps1",
    "https://raw.githubusercontent.com/DeusData/codebase-memory-mcp/main/install.sh",
]
for url in urls:
    print(f"--- {url} ---")
    with urllib.request.urlopen(url, timeout=20) as r:
        text = r.read().decode("utf-8", "replace").splitlines()
    for i, line in enumerate(text, 1):
        if any(s in line for for s in [
            "localappdata", "program files", ".local", "local/bin", "PATH", "path", "Copy",
            "cp", "chmod", "exec", "codebase-memory-mcp", "Destination", "targetDir",
            "Programs", "bin", "warn", "message"
        ]):
            print(f"{i:03d}: {line}")
PY

Repository: barisbagirlar-web/SectorCalc

Length of output: 285


🏁 Script executed:

#!/bin/bash
set -euo pipefail

python3 - <<'PY'
import urllib.request

urls = [
    "https://raw.githubusercontent.com/DeusData/codebase-memory-mcp/main/install.ps1",
    "https://raw.githubusercontent.com/DeusData/codebase-memory-mcp/main/install.sh",
]
for url in urls:
    print(f"--- {url} ---")
    with urllib.request.urlopen(url, timeout=20) as r:
        text = r.read().decode("utf-8", "replace").splitlines()
    for i, line in enumerate(text, 1):
        if any(s in line for s in [
            "localappdata", "program files", ".local", "local/bin", "PATH", "path", "Copy",
            "cp", "chmod", "exec", "codebase-memory-mcp", "Destination", "targetDir",
            "Programs", "bin", "warn", "message"
        ]):
            print(f"{i:03d}: {line}")
PY

Repository: barisbagirlar-web/SectorCalc

Length of output: 2848


🌐 Web query:

raw.githubusercontent.com DeusData codebase-memory-mcp install.ps1 PowerShell -NoProfile -ExecutionPolicy Bypass Destination

💡 Result:

The file at https://raw.githubusercontent.com/DeusData/codebase-memory-mcp/main/install.ps1 is the official PowerShell installation script for the codebase-memory-mcp project, a high-performance code intelligence engine for AI coding agents [1][2][3]. The script is designed to automate the download, installation, and configuration of the codebase-memory-mcp binary on Windows systems [1][3]. When executing this script in PowerShell, users may encounter Windows script execution policy restrictions [2][4]. To address this, the project documentation provides the following guidance for bypassing these restrictions: 1. Setting the execution policy for the current process: Run the command Set-ExecutionPolicy -Scope Process Bypass before executing the script [2][4]. 2. Invoking the script with a bypass flag: Alternatively, you can run the script using the following command [2][4]: PowerShell -ExecutionPolicy Bypass -File.\install.ps1 Additionally, because files downloaded from the internet may be blocked by Windows (Mark-of-the-Web), the project recommends unblocking the script before execution using the command Unblock-File .\install.ps1 [2][4]. The official installation procedure provided by the repository is: 1. Download the script: Invoke-WebRequest -Uri https://raw.githubusercontent.com/DeusData/codebase-memory-mcp/main/install.ps1 -OutFile install.ps1 [2][4]. 2. Unblock the file: Unblock-File .\install.ps1 [2][4]. 3. Execute the script: .\install.ps1 (with the execution policy bypassed if necessary) [2][4].

Citations:


🌐 Web query:

site:github.com/DeusData/codebase-memory-mcp install.ps1 Destination $env:LOCALAPPDATA

💡 Result:

The command install.ps1 Destination $env:LOCALAPPDATA is not a standard or built-in PowerShell command. It appears to be a pattern associated with specific custom installers, most notably the codebase-memory-mcp project [1][2][3]. In the context of that project, the install.ps1 script is used to install binaries to a user-local directory [1]. While the script typically defaults to $env:LOCALAPPDATA\Programs\codebase-memory-mcp [1], some installers allow users to specify a custom installation directory using command-line arguments [2][3]. If you are trying to use a script and need to specify a destination, check if the script supports a parameter like -Destination or a similar flag [3]. You can typically inspect a PowerShell script to see which parameters it accepts by opening it in a text editor or by running the following command in PowerShell: Get-Help.\install.ps1 -Detailed If you are writing your own script and want to install to a folder within $env:LOCALAPPDATA, you can use the following approach in your PowerShell script: $InstallDir = Join-Path $env:LOCALAPPDATA "YourAppFolder" if (!(Test-Path $InstallDir)) { New-Item -ItemType Directory -Path $InstallDir -Force | Out-Null } # Proceed with copying your files to $InstallDir Always be cautious when running scripts downloaded from the internet [2][3]. It is recommended to inspect the code first (e.g., using notepad install.ps1) and unblock the file using Unblock-File.\install.ps1 if necessary [2][3].

Citations:


🏁 Script executed:

#!/bin/bash
set -euo pipefail

curl --fail --silent --show-error --location -o /tmp/cbm-install.ps1 'https://raw.githubusercontent.com/DeusData/codebase-memory-mcp/main/install.ps1'
echo "--- install.ps1 PATH / install-dir lines ---"
grep -InEi '\.(path|prepend|environmentvariable|LOCALAPPDATA|Programs|Destination|InstallDir|PATH|path)' /tmp/cbm-install.ps1 | sed -n '1,120p' || true
wc -l /tmp/cbm-install.ps1

curl --fail --silent --show-error --location -o /tmp/cbm-install.sh 'https://raw.githubusercontent.com/DeusData/codebase-memory-mcp/main/install.sh'
echo "--- install.sh PATH / install-dir lines ---"
grep -InEi '\.(path|prepend|export|export PATH|\.local/bin|DIRECTORY|DIR|local|bin|chmod|codebase-memory-mcp)' /tmp/cbm-install.sh | sed -n '1,160p' || true
wc -l /tmp/cbm-install.sh

echo "--- full install.ps1 size-safe line numbers relevant ---"
awk '/Dest|LOCALAPPDATA|Programs|PATH|path|Copy|Unblock|Write|Message/ { printf "%d: %s\n", NR, $0 }' /tmp/cbm-install.ps1

echo "--- full install.sh size-safe line numbers relevant ---"
awk '/Dest|local|bin|export PATH|PATH|cp|chmod|codebase-memory-mcp|Write|Message|InstallDir/ { printf "%d: %s\n", NR, $0 }' /tmp/cbm-install.sh

Repository: barisbagirlar-web/SectorCalc

Length of output: 5008


Make the installed executable available before the first CLI call.

The installers only print a PATH warning/instruction; the setup scripts then immediately call codebase-memory-mcp. Resolve the installer-provided executable path, or prepend the default install directory before those CLI invocations:

  • scripts/setup-codebase-memory.ps1: use the Windows install path (e.g., $env:LOCALAPPDATA\Programs\codebase-memory-mcp\codebase-memory-mcp) before calling it.
  • scripts/setup-codebase-memory.sh: use "$HOME/.local/bin/codebase-memory-mcp" or update the active PATH.
📍 Affects 2 files
  • scripts/setup-codebase-memory.ps1#L6-L18 (this comment)
  • scripts/setup-codebase-memory.sh#L6-L18
🤖 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/setup-codebase-memory.ps1` around lines 6 - 18, The setup scripts
must make the installer-provided executable available before their first CLI
invocation. In scripts/setup-codebase-memory.ps1, resolve or prepend the Windows
default install path
($env:LOCALAPPDATA\Programs\codebase-memory-mcp\codebase-memory-mcp) before
codebase-memory-mcp config set; in scripts/setup-codebase-memory.sh, resolve or
prepend $HOME/.local/bin/codebase-memory-mcp before its corresponding CLI calls.

codebase-memory-mcp config set auto_watch true
codebase-memory-mcp config set auto_index_limit 50000
codebase-memory-mcp cli --progress index_repository --repo-path $repoRoot

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "Repo files matching setup-codebase-memory:"
fd -a 'setup-codebase-memory\.(ps1|sh)$' . || true

echo
echo "Contents of setup scripts:"
for f in $(fd 'setup-codebase-memory\.(ps1|sh)$' .); do
  echo "--- $f ---"
  nl -ba "$f" | sed -n '1,80p'
done

echo
echo "Search for codebase-memory-mcp usage and repo_path arguments:"
rg -n "codebase-memory-mcp|repo_path|--repo-path|index_repository|convertto-json|JSON|read_text_file" -S .

Repository: barisbagirlar-web/SectorCalc

Length of output: 427


🌐 Web query:

DeusData codebase-memory-mcp README index_repository repo_path CLI

💡 Result:

codebase-memory-mcp is a high-performance, open-source Model Context Protocol (MCP) server that indexes codebases into a persistent knowledge graph to assist AI coding agents [1][2]. It is designed as a structural analysis backend that provides fast, token-efficient querying of code elements like functions, classes, and call chains, rather than functioning as an LLM itself [2][3]. The index_repository tool is the primary method for adding a codebase to the server's knowledge graph [4]. It can be invoked via the Command Line Interface (CLI) or through an integrated MCP client [4][5]. Using the CLI To index a repository via the CLI, you use the index_repository tool command, passing a JSON string that specifies the repo_path [4][5]. Basic usage example: codebase-memory-mcp cli index_repository '{"repo_path": "/path/to/your/repository"}' [4][5] Important Configuration and Troubleshooting 1. Path Requirements: You must provide the absolute path to the repository [4][6]. 2. Windows Specifics: Windows users may encounter issues with JSON quoting or path parsing. If you receive a "repo_path is required" error despite specifying the path, it is often due to shell-specific JSON escaping [6][7]. - Recommended fix: Use double quotes to escape internal quotes, for example: codebase-memory-mcp cli index_repository "{"repo_path": "C:/Users/name/projects/repo"}" [6][7] - Alternatively, ensure forward slashes are used in the path [6]. 3. Security: You can optionally set the CBM_ALLOWED_ROOT environment variable to restrict the index_repository tool to specific directories, which is useful in untrusted or multi-tenant environments [4]. For a complete list of tools, configuration options, and language support, refer to the official README at the DeusData/codebase-memory-mcp GitHub repository [1][8].

Citations:


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "Setup script contents:"
for f in scripts/setup-codebase-memory.ps1 scripts/setup-codebase-memory.sh; do
  echo "--- $f ---"
  awk '{printf "%5d\t%s\n", NR, $0}' "$f" | sed -n '1,120p'
done

echo
echo "Repository references to codebase-memory-mcp CLI usage:"
rg -n "codebase-memory-mcp|index_repository|repo_path|--repo-path|ConvertTo-Json|repo-path" -S .

Repository: barisbagirlar-web/SectorCalc

Length of output: 3995


Use the documented JSON argument contract for indexing.

cli index_repository expects a JSON string with {"repo_path": "...}, so both setup scripts should replace --repo-path "$REPO_ROOT" with that JSON-payload form instead.

📍 Affects 2 files
  • scripts/setup-codebase-memory.ps1#L21-L21 (this comment)
  • scripts/setup-codebase-memory.sh#L18-L18
🤖 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/setup-codebase-memory.ps1` at line 21, The indexing commands use the
wrong argument contract. In scripts/setup-codebase-memory.ps1 at line 21 and
scripts/setup-codebase-memory.sh at line 18, update the cli index_repository
invocation to pass a JSON payload containing the repository path, replacing the
separate --repo-path argument while preserving the existing repository-root
values.

codebase-memory-mcp cli list_projects
Comment on lines +18 to +22

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

printf 'Files matching setup-codebase-memory.ps1:\n'
fd -a 'setup-codebase-memory\.ps1$' . || true

printf '\nTarget file contents with line numbers:\n'
if [ -f scripts/setup-codebase-memory.ps1 ]; then
  cat -n scripts/setup-codebase-memory.ps1
fi

printf '\nSearch for LASTEXITCODE handling or wrappers:\n'
rg -n "LASTEXITCODE|Check-Executable|ExecutableExists|codebase-memory-mcp|Set-StrictMode|trap|throws|Exception" scripts setup-codebase-memory.ps1 . --glob '!**/.git/**' --glob '!**/node_modules/**' || true

printf '\nPowerShell availability and native error behavior probe (if pwsh available):\n'
if command -v pwsh >/dev/null 2>&1; then
  pwsh -NoProfile -Command '
    $ErrorActionPreference = "Stop"
    $ErrorActionPreference | Out-String
    try {
      echo "foo" ; exit 7
      "after native nonzero"
    } catch {
      "catch executed"
    }
    "LASTEXITCODE=$LASTEXITCODE"
  '
else
  echo "pwsh not available"
fi

Repository: barisbagirlar-web/SectorCalc

Length of output: 14306


🌐 Web query:

Microsoft Learn PowerShell about ErrorHandling LASTEXITCODE native programs nonzero exit code ErrorActionPreference Stop

💡 Result:

In PowerShell, native programs do not participate in the standard PowerShell error system by default; they report failure via a non-zero exit code, which is stored in the automatic variable $LASTEXITCODE [1][2]. Traditionally, developers had to manually check this variable after every command execution [3][4]. However, starting in PowerShell 7.3 (and stabilized in 7.4), you can leverage the $PSNativeCommandUseErrorActionPreference feature to integrate native program failures into PowerShell's standard error handling [1][2]. How to use ErrorActionPreference Stop with native commands: 1. Enable the preference variable: Set $PSNativeCommandUseErrorActionPreference = $true [1][5]. 2. Configure error handling: Set $ErrorActionPreference = 'Stop' [1][5]. 3. Wrap in try/catch: When these two variables are set, a non-zero exit code from a native command will emit a NativeCommandExitException [1][2]. Because $ErrorActionPreference is set to 'Stop', this non-terminating error is promoted to a script-terminating error, allowing it to be caught by a try/catch block [1][5][2]. Example: $PSNativeCommandUseErrorActionPreference = $true $ErrorActionPreference = 'Stop' try { # If the command returns a non-zero exit code, it will now throw an exception &amp; my-native-command.exe } catch { Write-Host "Caught error: $($_.Exception.Message)" } Key Considerations: - Legacy behavior: In older versions of PowerShell (pre-7.3) or when $PSNativeCommandUseErrorActionPreference is $false, native commands will not trigger PowerShell errors, and you must check $LASTEXITCODE manually [1][4][2]. - $?: Regardless of the version, PowerShell sets the $? automatic variable to $true if the exit code is 0 and $false if it is non-zero, providing a quick way to check success without relying on error exceptions [6][7][3]. - Scope: You can scope these preference variables to a specific script block or function to avoid affecting the global session state [8].

Citations:


Check native command exit codes explicitly.

$ErrorActionPreference = 'Stop' only stops PowerShell errors by default; native codebase-memory-mcp failures remain in $LASTEXITCODE, and the script can continue through remaining commands before printing the success message. Add a $LASTEXITCODE check, check $?, or enable PowerShell 7.3+ native-error handling before these calls.

🤖 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/setup-codebase-memory.ps1` around lines 18 - 22, Update the setup
command sequence in setup-codebase-memory.ps1 to explicitly detect failures from
each native codebase-memory-mcp invocation using $LASTEXITCODE, $?, or supported
PowerShell native-error handling. Stop execution immediately on failure so
subsequent commands and the success message are not reached.


Write-Output 'Codebase Memory is installed and this repository is indexed.'
Write-Output 'Restart Cursor so the MCP server and managed agent configuration are loaded.'
23 changes: 23 additions & 0 deletions scripts/setup-codebase-memory.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/usr/bin/env bash
set -euo pipefail

REPO_ROOT="$(git rev-parse --show-toplevel)"

if ! command -v codebase-memory-mcp >/dev/null 2>&1; then
INSTALLER="$(mktemp)"
trap 'rm -f "$INSTALLER"' EXIT
curl --fail --silent --show-error --location --proto '=https' --tlsv1.2 \
https://raw.githubusercontent.com/DeusData/codebase-memory-mcp/main/install.sh \
--output "$INSTALLER"
bash "$INSTALLER"
fi

codebase-memory-mcp config set auto_index true
codebase-memory-mcp config set auto_watch true
codebase-memory-mcp config set auto_index_limit 50000
codebase-memory-mcp cli --progress index_repository --repo-path "$REPO_ROOT"
codebase-memory-mcp cli list_projects

printf '%s\n' \
'Codebase Memory is installed and this repository is indexed.' \
'Restart Cursor so the MCP server and managed agent configuration are loaded.'
Loading