Skip to content

fix(cli): add path-only project pruning#647

Open
Maicololiveras wants to merge 1 commit into
Gentleman-Programming:mainfrom
Maicololiveras:fix/prune-path-named-projects
Open

fix(cli): add path-only project pruning#647
Maicololiveras wants to merge 1 commit into
Gentleman-Programming:mainfrom
Maicololiveras:fix/prune-path-named-projects

Conversation

@Maicololiveras

@Maicololiveras Maicololiveras commented Jul 21, 2026

Copy link
Copy Markdown

🔗 Linked Issue

Closes #283


🏷️ PR Type

  • type:bug: Bug fix
  • type:feature: New feature
  • type:docs: Documentation only
  • type:refactor: Code refactoring (no behavior change)
  • type:chore: Maintenance, dependencies, tooling
  • type:breaking-change: Breaking change

📝 Summary

  • Add projects prune --paths-only for cleaning up legacy projects whose names are filesystem paths.
  • Restrict cleanup to zero-observation path-named projects while preserving legitimate empty projects.

📂 Changes

File Change
cmd/engram/main.go Add the --paths-only flag, path-name detection, candidate filtering, and focused empty-state output.
cmd/engram/prune_paths_test.go Cover path detection, dry-run filtering, deletion, and preservation of legitimate projects.

🧪 Test Plan

  • Focused unit tests pass locally: go test ./cmd/engram -run "Test(IsPathLikeProjectName|CmdProjectsPrunePathsOnly)" -count=1
  • Full unit suite: go test ./... (not rerun; this Windows host has a known unrelated package-suite failure and timeout)
  • E2E tests: go test -tags e2e ./internal/server/... (not required for this CLI-only prune change)
  • Scoped diff verified against main: only cmd/engram/main.go and cmd/engram/prune_paths_test.go

🤖 Automated Checks

These run automatically and all must pass before merge:

Check What it verifies Status
Check Issue Reference PR body contains Closes #N / Fixes #N / Resolves #N Pending
Check Issue Has status:approved Linked issue has status:approved label Pending
Check PR Has type: Label* PR has exactly one type:* label Pending
Unit Tests go test ./... passes Pending
E2E Tests go test -tags e2e ./internal/server/... passes Pending

✅ Contributor Checklist

  • I linked an approved issue above (Closes #283)
  • I added exactly one type:* label to this PR (requires maintainer permission)
  • I ran unit tests locally: go test ./...
  • I ran e2e tests locally: go test -tags e2e ./internal/server/...
  • Docs updated (not required for this focused cleanup flag)
  • Commits follow conventional commits format
  • No Co-Authored-By trailers in commits

💬 Notes for Reviewers

This PR is issue #283 bug 2 and is the second independent slice of the cleanup. The grouping safeguard remains in #445.

Chain Context

Both slices target main and can merge independently.

main
├── #445: grouping safeguard (bug 4)
└── 📍 #647: path-only pruning (bug 2)

Start state: legacy path-named projects require broad pruning that also selects legitimate empty projects.

End state: --paths-only selects only zero-observation projects whose names contain filesystem separators.

Prior dependency: none. This slice is independent from #445.

Out of scope: consolidation grouping and project write-boundary behavior.

@coderabbitai

coderabbitai Bot commented Jul 21, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The projects prune command adds --paths-only, recognizing path-like names containing / or \ and restricting pruning to empty matching projects. Tests cover detection, dry-run output, and selective deletion.

Changes

Path-only project pruning

Layer / File(s) Summary
Prune filtering and CLI support
cmd/engram/main.go
Adds --paths-only, detects path-like project names, filters empty-project candidates, and updates usage and no-candidate messages.
Pruning behavior validation
cmd/engram/prune_paths_test.go
Tests path-name detection, dry-run output, and deletion of only path-named projects without observations.

Estimated code review effort: 2 (Simple) | ~10 minutes

Suggested labels: type:bug

Suggested reviewers: gentleman-programming

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The PR implements the safe cleanup flow requested in #283 by filtering and deleting only zero-observation path-named projects.
Out of Scope Changes check ✅ Passed The changes stay focused on path-only pruning, related CLI messaging, and tests, with no obvious unrelated additions.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the main change: adding path-only project pruning in the CLI.
✨ 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 `@cmd/engram/prune_paths_test.go`:
- Line 129: Add a test in the prune-paths test suite covering the --paths-only
flow when filtering produces zero candidates. Assert that the command follows
the no-candidate branch and emits “No path-named projects to prune.”, while
preserving existing happy-path and mixed-project coverage.
🪄 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: 2c034e52-44fc-4794-ad1a-9050b827f70f

📥 Commits

Reviewing files that changed from the base of the PR and between 763a6ba and c47daa1.

📒 Files selected for processing (2)
  • cmd/engram/main.go
  • cmd/engram/prune_paths_test.go

if !has("realproject") {
t.Fatalf("project with observations must remain: %v", names)
}
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Add test coverage for the "no candidates" edge case.

As per path instructions, we must verify coverage of error paths and edge cases. The current test suite effectively covers the happy path and mixed-project scenarios, but it lacks a test for the alternate path where the --paths-only filter results in zero candidates (which triggers the "No path-named projects to prune." message added to main.go).

Please consider adding a test like the one below to ensure this edge case is fully covered.

🧪 Proposed test addition
 }
+
+// TestCmdProjectsPrunePathsOnlyNoCandidates verifies that when no path-named projects exist,
+// it exits gracefully with the correct message.
+func TestCmdProjectsPrunePathsOnlyNoCandidates(t *testing.T) {
+	cfg := testConfig(t)
+
+	// Only legitimate empty project, no garbage.
+	mustSeedSession(t, cfg, "s-legit", "legit-empty")
+
+	withArgs(t, "engram", "projects", "prune", "--paths-only")
+	stdout, stderr := captureOutput(t, func() { cmdProjectsPrune(cfg) })
+
+	if stderr != "" {
+		t.Fatalf("expected no stderr, got: %q", stderr)
+	}
+	if !strings.Contains(stdout, "No path-named projects to prune.") {
+		t.Fatalf("expected no candidates message, got: %q", stdout)
+	}
+}
📝 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
}
}
// TestCmdProjectsPrunePathsOnlyNoCandidates verifies that when no path-named projects exist,
// it exits gracefully with the correct message.
func TestCmdProjectsPrunePathsOnlyNoCandidates(t *testing.T) {
cfg := testConfig(t)
// Only legitimate empty project, no garbage.
mustSeedSession(t, cfg, "s-legit", "legit-empty")
withArgs(t, "engram", "projects", "prune", "--paths-only")
stdout, stderr := captureOutput(t, func() { cmdProjectsPrune(cfg) })
if stderr != "" {
t.Fatalf("expected no stderr, got: %q", stderr)
}
if !strings.Contains(stdout, "No path-named projects to prune.") {
t.Fatalf("expected no candidates message, got: %q", stdout)
}
}
🤖 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 `@cmd/engram/prune_paths_test.go` at line 129, Add a test in the prune-paths
test suite covering the --paths-only flow when filtering produces zero
candidates. Assert that the command follows the no-candidate branch and emits
“No path-named projects to prune.”, while preserving existing happy-path and
mixed-project coverage.

Source: Path instructions

@j0k3r-dev-rgl j0k3r-dev-rgl 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.

Thanks for keeping this cleanup slice focused. Before merging, please add regression coverage for the destructive edge cases:

  • A path-named project with only soft-deleted observations, which still retain foreign-key references to its sessions. Verify that PruneProject handles the failure safely and that the CLI does not report a successful prune when deletion did not complete.
  • --paths-only when no candidates match, asserting the No path-named projects to prune. branch.

These cases matter because this command deletes persisted data, so we need to prove both the safety boundary and the user-visible result. After updating the PR, please rerun the full CI checks and we can review it again.

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.

MCP server fails on multi-repo cwd + 3 related bugs (ambiguity, path-as-name, case-sensitivity, unsafe consolidate)

2 participants