@codragraph/cli 1.6.4 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (105) hide show
  1. package/README.md +34 -0
  2. package/dist/_shared/cgdb/schema-constants.d.ts +16 -0
  3. package/dist/_shared/cgdb/schema-constants.d.ts.map +1 -0
  4. package/dist/_shared/cgdb/schema-constants.js +67 -0
  5. package/dist/_shared/cgdb/schema-constants.js.map +1 -0
  6. package/dist/_shared/index.d.ts +2 -2
  7. package/dist/_shared/index.js +1 -1
  8. package/dist/cli/analyze.d.ts +22 -0
  9. package/dist/cli/analyze.js +109 -6
  10. package/dist/cli/compress-stats.d.ts +29 -0
  11. package/dist/cli/compress-stats.js +97 -0
  12. package/dist/cli/graphstore.d.ts +6 -2
  13. package/dist/cli/graphstore.js +45 -23
  14. package/dist/cli/index-repo.js +3 -3
  15. package/dist/cli/index.js +16 -2
  16. package/dist/cli/profile-heap.d.ts +35 -0
  17. package/dist/cli/profile-heap.js +126 -0
  18. package/dist/cli/setup.d.ts +13 -0
  19. package/dist/cli/setup.js +22 -11
  20. package/dist/cli/skill-gen.d.ts +14 -2
  21. package/dist/cli/skill-gen.js +52 -19
  22. package/dist/cli/tool.js +4 -0
  23. package/dist/cli/wiki.js +3 -3
  24. package/dist/core/augmentation/engine.js +7 -7
  25. package/dist/core/cgdb/cgdb-adapter.d.ts +176 -0
  26. package/dist/core/cgdb/cgdb-adapter.js +1320 -0
  27. package/dist/core/cgdb/content-read.d.ts +46 -0
  28. package/dist/core/cgdb/content-read.js +64 -0
  29. package/dist/core/cgdb/csv-generator.d.ts +29 -0
  30. package/dist/core/cgdb/csv-generator.js +492 -0
  31. package/dist/core/cgdb/pool-adapter.d.ts +93 -0
  32. package/dist/core/cgdb/pool-adapter.js +550 -0
  33. package/dist/core/cgdb/schema.d.ts +62 -0
  34. package/dist/core/cgdb/schema.js +502 -0
  35. package/dist/core/embeddings/embedding-pipeline.js +27 -10
  36. package/dist/core/graphstore/cgdb-row-source.d.ts +19 -0
  37. package/dist/core/graphstore/cgdb-row-source.js +141 -0
  38. package/dist/core/graphstore/index.d.ts +1 -1
  39. package/dist/core/graphstore/index.js +3 -3
  40. package/dist/core/group/bridge-db.d.ts +2 -2
  41. package/dist/core/group/bridge-db.js +123 -36
  42. package/dist/core/group/bridge-schema.d.ts +4 -4
  43. package/dist/core/group/bridge-schema.js +4 -4
  44. package/dist/core/group/cross-impact.js +3 -3
  45. package/dist/core/group/sync.js +4 -4
  46. package/dist/core/lbug/content-read.d.ts +46 -0
  47. package/dist/core/lbug/content-read.js +64 -0
  48. package/dist/core/lbug/csv-generator.d.ts +2 -6
  49. package/dist/core/lbug/csv-generator.js +45 -12
  50. package/dist/core/lbug/lbug-adapter.d.ts +4 -1
  51. package/dist/core/lbug/lbug-adapter.js +153 -21
  52. package/dist/core/lbug/schema.d.ts +7 -7
  53. package/dist/core/lbug/schema.js +18 -0
  54. package/dist/core/run-analyze.d.ts +13 -0
  55. package/dist/core/run-analyze.js +114 -27
  56. package/dist/core/search/bm25-index.d.ts +3 -3
  57. package/dist/core/search/bm25-index.js +75 -23
  58. package/dist/core/search/hybrid-search.js +2 -2
  59. package/dist/core/wiki/generator.d.ts +2 -2
  60. package/dist/core/wiki/generator.js +4 -4
  61. package/dist/core/wiki/graph-queries.d.ts +2 -2
  62. package/dist/core/wiki/graph-queries.js +5 -5
  63. package/dist/mcp/core/cgdb-adapter.d.ts +5 -0
  64. package/dist/mcp/core/cgdb-adapter.js +5 -0
  65. package/dist/mcp/core/embedder.js +1 -1
  66. package/dist/mcp/local/local-backend.d.ts +2 -2
  67. package/dist/mcp/local/local-backend.js +36 -19
  68. package/dist/mcp/server.js +3 -3
  69. package/dist/mcp/tools.js +1 -1
  70. package/dist/server/analyze-worker.js +2 -2
  71. package/dist/server/api.js +34 -33
  72. package/dist/storage/repo-manager.d.ts +42 -3
  73. package/dist/storage/repo-manager.js +23 -4
  74. package/hooks/claude/codragraph-hook.cjs +98 -5
  75. package/package.json +4 -4
  76. package/scripts/build-tree-sitter-proto.cjs +15 -3
  77. package/scripts/build.js +8 -9
  78. package/scripts/patch-tree-sitter-swift.cjs +17 -4
  79. package/skills/codragraph-api-surface.md +110 -0
  80. package/skills/codragraph-config-audit.md +146 -0
  81. package/skills/codragraph-cross-repo-impact.md +135 -0
  82. package/skills/codragraph-data-lineage.md +137 -0
  83. package/skills/codragraph-dead-code.md +119 -0
  84. package/skills/codragraph-gh-actions-debug.md +162 -0
  85. package/skills/codragraph-gh-issue-workflow.md +178 -0
  86. package/skills/codragraph-gh-pr-workflow.md +176 -0
  87. package/skills/codragraph-gh-release-workflow.md +187 -0
  88. package/skills/codragraph-git-bisect.md +176 -0
  89. package/skills/codragraph-git-force-push.md +147 -0
  90. package/skills/codragraph-git-history-rewrite.md +174 -0
  91. package/skills/codragraph-git-rebase-vs-merge.md +138 -0
  92. package/skills/codragraph-git-recovery.md +181 -0
  93. package/skills/codragraph-git-worktree.md +145 -0
  94. package/skills/codragraph-migration-tracking.md +130 -0
  95. package/skills/codragraph-notebook-context.md +136 -0
  96. package/skills/codragraph-observability-coverage.md +125 -0
  97. package/skills/codragraph-onboarding.md +129 -0
  98. package/skills/codragraph-perf-hotspots.md +132 -0
  99. package/skills/codragraph-project-switcher.md +116 -0
  100. package/skills/codragraph-security-audit.md +144 -0
  101. package/skills/codragraph-sql-tracing.md +122 -0
  102. package/skills/codragraph-supply-chain-audit.md +153 -0
  103. package/skills/codragraph-test-coverage.md +97 -0
  104. package/vendor/tree-sitter-proto/bindings/node/index.js +3 -3
  105. package/vendor/tree-sitter-proto/src/node-types.json +1 -1
@@ -0,0 +1,174 @@
1
+ ---
2
+ name: codragraph-git-history-rewrite
3
+ description: "Use when rewriting commit history — squashing WIP commits, splitting a fat commit, removing a leaked secret, changing author info, or running git filter-repo / BFG. Covers interactive rebase, fixup/autosquash, splitting commits, and the safety rules for rewriting public history. Examples: \"squash my commits\", \"clean up history\", \"remove a leaked secret from history\", \"split this commit\", \"git filter-repo\""
4
+ ---
5
+
6
+ # History Rewriting — Safely
7
+
8
+ ## When to Use
9
+
10
+ - "Squash my last 5 WIP commits before opening a PR."
11
+ - "Split this giant commit into 3 logical ones."
12
+ - "Remove a leaked secret from history."
13
+ - "Change the author of past commits."
14
+ - "Drop a commit from the middle of the branch."
15
+
16
+ ## The cardinal rule
17
+
18
+ **Never rewrite history that's been pushed to a shared branch.** Rewriting
19
+ public history breaks every clone that pulled it. For shared branches:
20
+ make a new commit that fixes/reverts the offending one. For your own
21
+ branch (or any branch you alone work on), rewrite freely with
22
+ `--force-with-lease`.
23
+
24
+ ## Interactive rebase
25
+
26
+ ```bash
27
+ git rebase -i origin/main # rebase your branch onto main, interactively
28
+ # OR rebase the last N commits without changing the base:
29
+ git rebase -i HEAD~N
30
+ ```
31
+
32
+ You get an editor with one line per commit:
33
+
34
+ ```
35
+ pick abc1234 wip: hack on auth
36
+ pick def5678 wip: more auth
37
+ pick fed9876 fix typo
38
+ pick 012abcd add real auth flow
39
+ ```
40
+
41
+ Change `pick` to one of:
42
+
43
+ | Command | Effect |
44
+ |---|---|
45
+ | `pick` | keep the commit as-is |
46
+ | `reword` | keep the changes, edit the message |
47
+ | `edit` | pause after applying so you can `git commit --amend` or split |
48
+ | `squash` | merge into previous commit, edit combined message |
49
+ | `fixup` | merge into previous commit, drop this commit's message |
50
+ | `drop` | remove the commit entirely (its changes are gone) |
51
+ | `exec <cmd>` | run a shell command after this commit (CI-style validation per commit) |
52
+
53
+ Reorder lines to reorder commits. Save and exit; rebase replays them.
54
+
55
+ ## Fixup + autosquash workflow (the cleanest pattern)
56
+
57
+ ```bash
58
+ # While developing, instead of "wip" commits, mark fixups against a target:
59
+ git commit --fixup=<sha-of-target-commit>
60
+
61
+ # At the end, squash all fixups in one go:
62
+ git rebase -i --autosquash origin/main
63
+ # → all `fixup!` commits are auto-placed and pre-marked. Just save.
64
+ ```
65
+
66
+ This produces a clean, atomic-commit branch ready to PR — no manual
67
+ reordering needed.
68
+
69
+ ## Splitting a fat commit
70
+
71
+ ```bash
72
+ git rebase -i <commit>^ # interactive rebase starting AT the fat commit
73
+ # Mark it `edit` and save.
74
+
75
+ # Now you're paused at the fat commit. Reset to its parent, keep the changes:
76
+ git reset HEAD^
77
+
78
+ # Stage and commit each logical chunk separately:
79
+ git add <files-for-part-1>
80
+ git commit -m "first logical part"
81
+ git add <files-for-part-2>
82
+ git commit -m "second logical part"
83
+ git add -A
84
+ git commit -m "third logical part"
85
+
86
+ # Resume the rebase:
87
+ git rebase --continue
88
+ ```
89
+
90
+ ## Removing a leaked secret from history
91
+
92
+ If a secret (API key, password, .env) was committed:
93
+
94
+ 1. **Rotate the secret first.** Once it's on a public remote, treat it as
95
+ leaked — even after history scrub.
96
+ 2. **Then scrub history with `git filter-repo`** (the modern replacement
97
+ for `filter-branch`):
98
+
99
+ ```bash
100
+ # Install: pip install git-filter-repo (or pipx)
101
+
102
+ # Remove a specific file from all history:
103
+ git filter-repo --invert-paths --path path/to/leaked.env
104
+
105
+ # Or remove a string/secret from blob contents:
106
+ echo 'sk_live_abc***123==>REDACTED' > /tmp/replacements.txt
107
+ git filter-repo --replace-text /tmp/replacements.txt
108
+
109
+ # After filter-repo, the remote is forcibly out of sync. Coordinate with the
110
+ # team and force-push:
111
+ git push --force-with-lease origin --all
112
+ git push --force-with-lease origin --tags
113
+ ```
114
+
115
+ Alternative: BFG (`https://rtyley.github.io/bfg-repo-cleaner/`) is
116
+ faster for large repos but more limited.
117
+
118
+ > **Important:** GitHub caches blobs even after force-push. The blob is
119
+ > still accessible by SHA URL for ~30 days unless you contact GitHub
120
+ > Support to purge. Treat the secret as compromised.
121
+
122
+ ## Changing author info on past commits
123
+
124
+ ```bash
125
+ # Most recent commit only:
126
+ git commit --amend --author="New Name <new@email>"
127
+
128
+ # Multiple commits with filter-repo:
129
+ git filter-repo --commit-callback '
130
+ if commit.author_email == b"old@email":
131
+ commit.author_email = b"new@email"
132
+ commit.author_name = b"New Name"
133
+ '
134
+ ```
135
+
136
+ ## Why CodraGraph helps here
137
+
138
+ After any history rewrite, the structural diff against the pre-rewrite
139
+ state proves you didn't accidentally drop or alter functional code:
140
+
141
+ ```bash
142
+ # Before rewrite: snapshot the structural state
143
+ codragraph commit -m "pre-rewrite snapshot"
144
+ git rebase -i origin/main # do the rewrite
145
+ codragraph analyze # re-index after
146
+
147
+ # Confirm structural equivalence (or see exactly what differs):
148
+ codragraph diff <pre-snapshot-id> HEAD --semantic
149
+ # → Should be empty if you only rewrote messages / order.
150
+ # → If addedAPIs / removedAPIs appear, the rewrite changed semantics.
151
+ ```
152
+
153
+ ## Pitfalls
154
+
155
+ | Pitfall | What goes wrong | Avoidance |
156
+ |---|---|---|
157
+ | Rewriting shared branch | Collaborators' clones diverge | Only rewrite local-or-personal branches |
158
+ | `drop` instead of `fixup` | Lost changes silently | Verify with `codragraph diff` after the rebase |
159
+ | Editing during rebase, forgetting `--continue` | Stuck in detached state | `git rebase --continue` after each manual step |
160
+ | `git rebase --abort` after edits | Loses your edits | Stash before rebase if you have uncommitted work |
161
+ | `filter-branch` (legacy) | Slow, error-prone, deprecated | Use `git filter-repo` |
162
+ | Force-pushing after secret scrub without rotation | Secret still compromised | Rotate FIRST, scrub SECOND |
163
+
164
+ ## Checklist before any history rewrite
165
+
166
+ ```
167
+ - [ ] Branch is NOT shared (or you have explicit team coordination)
168
+ - [ ] Snapshot pre-state with `codragraph commit -m "pre-rewrite"`
169
+ - [ ] Decide: interactive rebase (small) vs filter-repo (large/secrets)
170
+ - [ ] Run the rewrite
171
+ - [ ] Re-analyze + `codragraph diff` to verify no semantic surprises
172
+ - [ ] Push with --force-with-lease
173
+ - [ ] If secrets were involved: rotate FIRST, then scrub, then push
174
+ ```
@@ -0,0 +1,138 @@
1
+ ---
2
+ name: codragraph-git-rebase-vs-merge
3
+ description: "Use when deciding between rebase, merge, squash-merge, or rebase-and-merge for integrating a branch — both for local catch-up (pulling main into a feature branch) and for landing a PR. Examples: \"should I rebase or merge\", \"how do I integrate main into my branch\", \"squash vs rebase merge\", \"clean up my branch history before PR\""
4
+ ---
5
+
6
+ # Rebase vs Merge — A Decision Guide
7
+
8
+ ## When to Use
9
+
10
+ - "How do I bring main into my feature branch?"
11
+ - "Should I squash this PR or merge it?"
12
+ - "Should I rebase before pushing?"
13
+ - "Which merge strategy do I pick on the GitHub PR button?"
14
+ - Any time you have a branch and need to combine it with another.
15
+
16
+ ## The decision rule (read this first)
17
+
18
+ | Situation | Use | Why |
19
+ |---|---|---|
20
+ | Branch is **local-only**, you want it to track main | `git pull --rebase` or `git rebase main` | Keeps your local history linear; nothing has been shared yet |
21
+ | Branch is **shared** (already pushed, others may have pulled) | `git merge main` (or `--no-rebase`) | Rebase rewrites SHAs — collaborators' clones break |
22
+ | You're about to **open a PR** and want clean history | `git rebase -i main` (interactive) | Squash WIP commits, reword messages, end with N tidy commits |
23
+ | You're **landing a PR** with one logical change | **Squash-merge** on GitHub | One commit on main, clean log, PR description becomes the body |
24
+ | You're landing a PR with multiple **already-tidy** commits | **Rebase-and-merge** on GitHub | Preserves your atomic commits; no merge bubble |
25
+ | You're landing a long-running branch that **must show as a unit** | **Merge commit** on GitHub | Preserves the branch topology — useful for release branches |
26
+
27
+ If you remember nothing else: **rebase what's only yours, merge what's already shared.**
28
+
29
+ ## Workflow: catching up a feature branch
30
+
31
+ ```bash
32
+ # Local-only branch (fast-forward integration)
33
+ git fetch origin
34
+ git rebase origin/main # replays your commits on top of main
35
+
36
+ # Already pushed branch (avoid SHA churn for collaborators)
37
+ git fetch origin
38
+ git merge origin/main # creates a merge commit — collaborators stay in sync
39
+
40
+ # OR explicitly opt into rebase even on shared branches (coordinate first!)
41
+ git rebase origin/main
42
+ git push --force-with-lease # SEE codragraph-git-force-push skill
43
+ ```
44
+
45
+ ## Workflow: cleaning up before opening a PR
46
+
47
+ ```bash
48
+ git fetch origin
49
+ git rebase -i origin/main # interactive — squash, fixup, reword
50
+
51
+ # Common interactive-rebase actions:
52
+ # pick - keep commit
53
+ # reword - change message
54
+ # squash - merge into previous, edit combined message
55
+ # fixup - merge into previous, drop this message
56
+ # drop - remove the commit entirely
57
+ ```
58
+
59
+ ## Workflow: landing a PR (GitHub UI / `gh pr merge`)
60
+
61
+ ```bash
62
+ # Squash-merge — one logical change, one commit on main:
63
+ gh pr merge --squash --delete-branch
64
+
65
+ # Rebase-and-merge — preserve your N commits as N commits on main:
66
+ gh pr merge --rebase --delete-branch
67
+
68
+ # Merge commit — preserve the branch as a unit (rare; use for releases):
69
+ gh pr merge --merge --delete-branch
70
+ ```
71
+
72
+ ## Why CodraGraph helps here
73
+
74
+ The hardest part of choosing a strategy isn't the mechanics — it's
75
+ predicting whether your branch will conflict structurally with main.
76
+ CodraGraph's `diff --semantic` tells you exactly which APIs / signatures
77
+ changed on each side, so you can see *before* the merge whether your
78
+ branch and main both touched the same callgraph regions.
79
+
80
+ ```
81
+ codragraph diff main HEAD --semantic --json | jq '.semantic'
82
+ → added APIs / removed APIs / classified modifications on YOUR branch
83
+
84
+ codragraph diff <last-shared-ancestor> main --semantic --json | jq '.semantic'
85
+ → what main has done since you forked
86
+ ```
87
+
88
+ If both diffs touch overlapping symbols, prefer **merge** (preserves both
89
+ sides as branches you can reason about) over rebase (which re-writes your
90
+ side and may produce noisy conflicts).
91
+
92
+ ## Pitfalls
93
+
94
+ | Pitfall | Symptom | Fix |
95
+ |---|---|---|
96
+ | Rebasing a shared branch | Collaborators report "diverged history", lost commits | Merge instead; don't rebase shared branches without coordination |
97
+ | Squash-merge into long-running branch | Loses individual commit context | Use rebase-and-merge for branches that need history preserved |
98
+ | `git pull` without `--rebase` flag on a feature branch | Random merge bubbles in your branch | Set `git config --global pull.rebase true` or always `pull --rebase` on feature branches |
99
+ | Rebasing ON TOP of work in progress (uncommitted) | "Your local changes would be overwritten" | `git stash` first, rebase, `git stash pop` |
100
+
101
+ ## Checklist before merging a PR
102
+
103
+ ```
104
+ - [ ] CI green (lint, tests, typecheck)
105
+ - [ ] codragraph_detect_changes({scope: "compare", base_ref: "main"}) clean
106
+ - [ ] codragraph diff main HEAD --semantic — review removed APIs
107
+ - [ ] PR description matches the (would-be-squash) commit message
108
+ - [ ] Decided strategy: squash (single change) vs rebase-and-merge (multiple atomic) vs merge (release/topology)
109
+ - [ ] gh pr merge --squash --delete-branch (or appropriate flag)
110
+ ```
111
+
112
+ ## Example: "Should I rebase or merge main into my 4-day-old branch?"
113
+
114
+ ```
115
+ 1. Check if the branch is shared:
116
+ git config branch.<your-branch>.remote
117
+ → "origin" — yes, pushed.
118
+
119
+ 2. Check who else might have it:
120
+ gh api repos/{owner}/{repo}/pulls?head={your-branch} --jq '.[].user.login'
121
+ git log origin/<your-branch>..main --oneline | head
122
+ → no co-authors observed; just you and CI.
123
+
124
+ 3. Check structural conflict potential:
125
+ codragraph diff main <your-branch> --semantic
126
+ → 2 added APIs, 1 modified signature
127
+ codragraph diff <merge-base> main --semantic
128
+ → 0 changes touching the same files
129
+ → no structural conflict expected.
130
+
131
+ 4. Decision: rebase (it's effectively local) + force-with-lease.
132
+ git fetch origin
133
+ git rebase origin/main
134
+ # Resolve any conflicts file-by-file
135
+ git push --force-with-lease
136
+
137
+ 5. If structural conflict HAD been likely → merge, not rebase.
138
+ ```
@@ -0,0 +1,181 @@
1
+ ---
2
+ name: codragraph-git-recovery
3
+ description: "Use when work appears lost — bad reset, dropped commit, blown-away stash, deleted branch, broken merge, accidental rm in tracked files. Covers reflog spelunking, stash recovery, dangling-commit revival, and what's actually unrecoverable. Examples: \"I lost my commits\", \"deleted my branch\", \"reset --hard by mistake\", \"recover work\", \"reflog\""
4
+ ---
5
+
6
+ # Lost-Work Recovery Playbook
7
+
8
+ ## When to Use
9
+
10
+ - "I ran `git reset --hard` and lost my work"
11
+ - "I deleted a branch — can I get it back?"
12
+ - "I dropped a stash by accident"
13
+ - "I rm'd a file and committed before I noticed"
14
+ - "Help, I think I lost everything."
15
+
16
+ ## The first-aid rules
17
+
18
+ 1. **STOP committing.** Every new commit pushes the lost ones further into
19
+ the reflog. Don't `git gc`, don't clone fresh.
20
+ 2. **Don't close the terminal yet.** Some recovery paths (e.g.,
21
+ `ORIG_HEAD`) live until you run another mutating command.
22
+ 3. **Reflog is your friend.** Default expiry is 90 days for reachable
23
+ commits, 30 days for unreachable. You almost always have time.
24
+ 4. **Local-only state survives EVERYTHING except** explicit `git gc
25
+ --prune=now` and disk loss. Even `reset --hard` leaves the old SHAs
26
+ in the reflog.
27
+
28
+ ## Recovery paths by symptom
29
+
30
+ ### "I ran `git reset --hard` and lost commits"
31
+
32
+ ```bash
33
+ git reflog # newest first
34
+ # → look for "HEAD@{1}: commit: <message>" — that was you, before reset
35
+ git reset --hard HEAD@{1} # OR the explicit SHA
36
+ ```
37
+
38
+ `ORIG_HEAD` is the convenience alias for "what HEAD was before the most
39
+ recent destructive operation":
40
+
41
+ ```bash
42
+ git reset --hard ORIG_HEAD # undoes the last reset / merge / rebase
43
+ ```
44
+
45
+ ### "I deleted a branch (`git branch -D`) and want it back"
46
+
47
+ ```bash
48
+ git reflog # the last entry of that branch is here
49
+ # → look for "<branch>@{N}: ..." OR walk HEAD's history to find where you were
50
+ git branch <branch> <sha> # recreates the branch at the old tip
51
+ ```
52
+
53
+ If the reflog entry for the branch is gone (rare), search dangling
54
+ commits:
55
+
56
+ ```bash
57
+ git fsck --lost-found
58
+ # → "dangling commit <sha>" lines
59
+ git show <sha> # inspect each candidate
60
+ git branch <branch> <sha> # restore the one you want
61
+ ```
62
+
63
+ ### "I dropped a stash with `stash drop` (or by accident)"
64
+
65
+ ```bash
66
+ git fsck --unreachable | grep commit
67
+ # → unreachable commits include dropped stashes
68
+ git show <sha> # confirm it's the right stash
69
+ git stash apply <sha> # apply it back (or stash branch <name> <sha>)
70
+ ```
71
+
72
+ ### "I committed a file I shouldn't have" (no remote push yet)
73
+
74
+ ```bash
75
+ git reset --soft HEAD~1 # undo the commit, keep the changes staged
76
+ git restore --staged <file> # unstage the offending file
77
+ echo "<file>" >> .gitignore
78
+ git commit -m "<original message>"
79
+ ```
80
+
81
+ If you already pushed:
82
+
83
+ ```bash
84
+ git reset --soft HEAD~1
85
+ git restore --staged <file>
86
+ echo "<file>" >> .gitignore
87
+ git commit -m "<original message>"
88
+ git push --force-with-lease # SEE codragraph-git-force-push skill
89
+ ```
90
+
91
+ If the file contained secrets, `--force-with-lease` is NOT enough —
92
+ rotate the secret first, then use `git filter-repo` or BFG to scrub
93
+ history (see codragraph-git-history-rewrite).
94
+
95
+ ### "I deleted a file with `rm` (NOT git rm) and haven't committed"
96
+
97
+ ```bash
98
+ git restore <file> # restores from index
99
+ # OR if it was never tracked, you're out of luck — check editor backups / Time Machine
100
+ ```
101
+
102
+ ### "I have a broken merge in progress"
103
+
104
+ ```bash
105
+ git merge --abort # cleanly back out
106
+ git rebase --abort # for in-progress rebase
107
+ git cherry-pick --abort # for in-progress cherry-pick
108
+ ```
109
+
110
+ If `--abort` doesn't work (rare):
111
+
112
+ ```bash
113
+ git reset --merge ORIG_HEAD
114
+ ```
115
+
116
+ ## When recovery WON'T work
117
+
118
+ | Situation | Recoverable? |
119
+ |---|---|
120
+ | Reset --hard within last 90 days (no `gc --prune=now`) | ✓ via reflog |
121
+ | Branch deleted within last 30 days | ✓ via fsck or branch reflog |
122
+ | Stash dropped within last 30 days | ✓ via fsck |
123
+ | Untracked / unstaged files deleted with `rm` | ✗ git never saw them |
124
+ | `.git/` dir deleted | ✗ catastrophic; restore from backup or remote |
125
+ | `git gc --prune=now` after the disaster | ✗ unreachable objects gone |
126
+ | Force-pushed-over commits AND local clone gone | ✗ unless GitHub Support recovers |
127
+
128
+ ## Recovery diagnostics
129
+
130
+ ```bash
131
+ # What does my reflog look like?
132
+ git reflog --all --date=iso | head -50
133
+
134
+ # What dangling commits exist?
135
+ git fsck --lost-found
136
+
137
+ # What was HEAD recently?
138
+ git reflog show HEAD --date=iso | head -10
139
+
140
+ # What was BRANCH recently?
141
+ git reflog show <branch> --date=iso | head -10
142
+
143
+ # Where did this commit live? (by sha)
144
+ git branch --contains <sha>
145
+ git tag --contains <sha>
146
+ ```
147
+
148
+ ## Why CodraGraph helps after recovery
149
+
150
+ Recovery is mechanical (reflog → reset). The real question is "did I
151
+ actually get back what I lost?" CodraGraph's diff lets you compare:
152
+
153
+ ```bash
154
+ # Compare your recovered tree to the suspected lost-work SHA:
155
+ codragraph diff <recovered-head> <reflog-candidate-sha> --semantic
156
+
157
+ # If you see addedAPIs in the candidate that aren't in your recovered HEAD,
158
+ # the recovery is incomplete — try a different reflog entry.
159
+ ```
160
+
161
+ For deleted branches with no clear "right" tip:
162
+
163
+ ```bash
164
+ git fsck --lost-found
165
+ # For each candidate dangling-commit SHA:
166
+ codragraph diff main <dangling-sha> --semantic
167
+ # Pick the one whose diff matches the work you remember doing.
168
+ ```
169
+
170
+ ## Checklist when in panic mode
171
+
172
+ ```
173
+ - [ ] STOP committing / running git gc / reinstalling
174
+ - [ ] git reflog | head -30 — see what's there
175
+ - [ ] Identify the candidate SHA for the lost work
176
+ - [ ] git show <sha> to verify it's the right thing
177
+ - [ ] git reset --hard / git branch <name> <sha> / git stash apply <sha>
178
+ - [ ] codragraph diff to verify the recovery captured the real work
179
+ - [ ] Set up git config --global core.autocrlf and longer reflog expiry
180
+ (gc.reflogExpire) for the future
181
+ ```
@@ -0,0 +1,145 @@
1
+ ---
2
+ name: codragraph-git-worktree
3
+ description: "Use when working on multiple branches in parallel without re-cloning, juggling a long-running branch alongside hotfixes, or running CI/build on one branch while editing another. Covers `git worktree` setup, conventions, and gotchas. Examples: \"work on two branches at once\", \"git worktree\", \"hotfix without losing my context\", \"avoid stash-juggling\""
4
+ ---
5
+
6
+ # Parallel Branches with `git worktree`
7
+
8
+ ## When to Use
9
+
10
+ - "I'm in the middle of something and need to do a hotfix on main."
11
+ - "I want CI to run on one branch while I edit another."
12
+ - "I have N agents working on N branches simultaneously."
13
+ - "I'm sick of `git stash` between branch switches."
14
+
15
+ ## The idea
16
+
17
+ A *worktree* is a separate working directory backed by the same git
18
+ repository. One `.git/`, many checkouts. Switching between branches no
19
+ longer requires re-running build / re-installing deps / re-warming editor
20
+ indexes — you just `cd` to a different directory.
21
+
22
+ ## Setup
23
+
24
+ ```bash
25
+ # From inside your existing repo (e.g. ~/code/myrepo):
26
+ git worktree add ../myrepo-hotfix main # check out 'main' at ../myrepo-hotfix
27
+ git worktree add ../myrepo-feat-x feat/x # check out feat/x at ../myrepo-feat-x
28
+
29
+ # List all worktrees:
30
+ git worktree list
31
+ # → /home/anit/code/myrepo abc1234 [feature/foo]
32
+ # → /home/anit/code/myrepo-hotfix def5678 [main]
33
+ # → /home/anit/code/myrepo-feat-x fed9876 [feat/x]
34
+
35
+ # Each is a real working directory. cd into it; git commands operate on its
36
+ # checked-out branch automatically.
37
+ cd ../myrepo-hotfix
38
+ git status # → on branch 'main'
39
+ ```
40
+
41
+ ## Conventions that scale
42
+
43
+ ```
44
+ ~/code/
45
+ ├── myrepo/ # main worktree (your "primary" branch's checkout)
46
+ ├── myrepo-hotfix/ # for emergency fixes off main
47
+ ├── myrepo-pr-143/ # parking a PR for review
48
+ └── myrepo-bisect/ # dedicated to long-running bisects
49
+ ```
50
+
51
+ Or co-locate inside the primary repo as siblings under `.worktrees/`:
52
+
53
+ ```bash
54
+ mkdir -p .worktrees
55
+ git worktree add .worktrees/hotfix main
56
+ echo ".worktrees/" >> .gitignore # don't index worktrees as files
57
+ ```
58
+
59
+ ## Removing worktrees
60
+
61
+ ```bash
62
+ git worktree remove ../myrepo-hotfix
63
+ # or, if the directory was already deleted manually:
64
+ git worktree prune
65
+ ```
66
+
67
+ ## Why CodraGraph helps here
68
+
69
+ Each worktree gets its own working directory but shares the `.git/`. This
70
+ matters for indexing: CodraGraph indexes `.codragraph/` in the working
71
+ directory, so each worktree gets its OWN index. That's actually useful:
72
+
73
+ ```bash
74
+ # Two worktrees, two independent CodraGraph indexes.
75
+ cd ~/code/myrepo # primary, on feature/foo
76
+ codragraph analyze # index of feature/foo
77
+
78
+ cd ~/code/myrepo-hotfix # worktree, on main
79
+ codragraph analyze # index of main
80
+
81
+ # Now you can run cross-worktree impact analysis:
82
+ codragraph_query({repo: "myrepo", query: "auth"}) # primary index
83
+ codragraph_query({repo: "myrepo-hotfix", query: "auth"}) # main's index
84
+ ```
85
+
86
+ This is especially handy for **migration tracking** (compare a
87
+ long-running migration branch's structural state to current main without
88
+ checking out and re-indexing repeatedly).
89
+
90
+ ## Pitfalls
91
+
92
+ | Pitfall | What happens | Fix |
93
+ |---|---|---|
94
+ | Same branch checked out in two worktrees | git refuses; only one worktree per branch | Use a different branch in the second worktree (or `--detach`) |
95
+ | Worktree dir deleted manually (no `worktree remove`) | git still tracks it as live | `git worktree prune` |
96
+ | Hooks / config differ across worktrees | Worktrees share `.git/` but each has its own `.git/info/` and per-worktree config | Use `git config --worktree` for per-worktree settings |
97
+ | Editor's "open repo" features confused | VS Code sometimes treats each worktree as its own repo | Open each worktree as a separate workspace; this is actually correct |
98
+ | `npm install` in every worktree | Slow, duplicated `node_modules` | Use pnpm with shared store, or yarn berry's PnP |
99
+
100
+ ## Variants
101
+
102
+ ```bash
103
+ # Detached HEAD worktree (no branch — useful for inspecting old commits):
104
+ git worktree add --detach ../myrepo-old <commit-sha>
105
+
106
+ # Lock a worktree (prevents `worktree prune` from cleaning it):
107
+ git worktree lock ../myrepo-old
108
+
109
+ # Move a worktree:
110
+ git worktree move ../myrepo-old ../myrepo-archive
111
+ ```
112
+
113
+ ## Checklist
114
+
115
+ ```
116
+ - [ ] Created worktree with a clear directory name and the right branch
117
+ - [ ] Confirmed `git worktree list` shows all expected entries
118
+ - [ ] Per-worktree CodraGraph index where relevant (codragraph analyze in each)
119
+ - [ ] Editor opened per worktree (separate workspace each)
120
+ - [ ] When done: git worktree remove <path> (or rm + git worktree prune)
121
+ ```
122
+
123
+ ## Example: "I need to ship a hotfix without losing my WIP"
124
+
125
+ ```bash
126
+ # Currently on feature/big-refactor, 8 uncommitted files, half-broken.
127
+
128
+ # 1. Create a worktree for the hotfix off main
129
+ git worktree add ../myrepo-hotfix main
130
+
131
+ # 2. cd over and do the work
132
+ cd ../myrepo-hotfix
133
+ git switch -c hotfix/null-pointer
134
+ # ... edit, test, commit ...
135
+ git push -u origin hotfix/null-pointer
136
+ gh pr create --title "..." --body "..."
137
+ gh pr merge --squash --delete-branch
138
+
139
+ # 3. Clean up the worktree
140
+ cd ../myrepo
141
+ git worktree remove ../myrepo-hotfix
142
+
143
+ # 4. Continue your refactor as if nothing happened
144
+ git status # still 8 uncommitted files, intact
145
+ ```