@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,176 @@
1
+ ---
2
+ name: codragraph-gh-pr-workflow
3
+ description: "Use for any pull-request workflow via GitHub CLI — create draft, convert ready, request review, address comments, check CI, merge with the right strategy, manage stacked PRs. Examples: \"open a PR\", \"draft PR\", \"merge this PR\", \"check PR status\", \"address review comments\", \"stacked PRs\""
4
+ ---
5
+
6
+ # Pull Request Workflow with `gh`
7
+
8
+ ## When to Use
9
+
10
+ - "Open a PR for this branch."
11
+ - "Convert this draft to ready-for-review."
12
+ - "Check the status of my PRs."
13
+ - "Merge PR #N — which strategy should I use?"
14
+ - "Address review comments and push fixes."
15
+ - "I have stacked PRs — how do I manage them?"
16
+
17
+ ## Lifecycle commands
18
+
19
+ ### Open
20
+
21
+ ```bash
22
+ # After pushing your branch:
23
+ gh pr create --title "feat: …" --body "…" --reviewer @teammate
24
+ gh pr create --draft # ship as draft
25
+ gh pr create --fill # use the most recent commit message
26
+ gh pr create --base main --head my-branch # explicit base/head
27
+
28
+ # Multi-line body (HEREDOC) — preferred for real PRs:
29
+ gh pr create --title "feat: X" --body "$(cat <<'EOF'
30
+ ## Summary
31
+ - Bullet 1
32
+ - Bullet 2
33
+
34
+ ## Test plan
35
+ - [ ] Unit
36
+ - [ ] Integration
37
+ - [ ] Manual repro of the bug
38
+ EOF
39
+ )"
40
+ ```
41
+
42
+ ### Inspect
43
+
44
+ ```bash
45
+ gh pr list # PRs in this repo (yours by default)
46
+ gh pr list --state all --author "@me" # all your PRs ever
47
+ gh pr status # PRs needing attention (created by you, requesting your review)
48
+ gh pr view <N> # one PR's metadata
49
+ gh pr view <N> --comments # include review comments
50
+ gh pr diff <N> # raw diff
51
+ gh pr checks <N> # CI status per check
52
+ ```
53
+
54
+ ### Update
55
+
56
+ ```bash
57
+ # Push fixes to the same branch:
58
+ git push # PR auto-updates
59
+
60
+ # Convert draft <-> ready:
61
+ gh pr ready <N> # draft → ready-for-review
62
+ gh pr ready --undo <N> # ready → draft
63
+
64
+ # Edit metadata:
65
+ gh pr edit <N> --title "…" --add-reviewer @teammate --add-label "bug"
66
+ ```
67
+
68
+ ### Address review comments
69
+
70
+ ```bash
71
+ # Pull the conversation:
72
+ gh pr view <N> --comments
73
+
74
+ # Push your fixes (same branch):
75
+ git add <files> && git commit -m "address review: <topic>"
76
+ git push
77
+
78
+ # Mark conversations resolved (UI only, no CLI flag) or reply:
79
+ gh pr comment <N> --body "fixed in <new-sha>"
80
+ ```
81
+
82
+ ### Merge
83
+
84
+ | Strategy | When | gh command |
85
+ |---|---|---|
86
+ | **Squash** | One logical change, want one commit on main | `gh pr merge <N> --squash --delete-branch` |
87
+ | **Rebase** | Multiple already-tidy commits, no merge bubble | `gh pr merge <N> --rebase --delete-branch` |
88
+ | **Merge commit** | Long-running release branch, preserve topology | `gh pr merge <N> --merge --delete-branch` |
89
+ | **Auto-merge** | Merge as soon as CI green + reviews approved | `gh pr merge <N> --auto --squash --delete-branch` |
90
+
91
+ See `codragraph-git-rebase-vs-merge` for the decision rule. Default to
92
+ **squash** for typical feature PRs.
93
+
94
+ ### Close / reopen
95
+
96
+ ```bash
97
+ gh pr close <N> --comment "superseded by #<other>"
98
+ gh pr reopen <N>
99
+ ```
100
+
101
+ ## Stacked PR pattern (`gh pr` with branches that depend on each other)
102
+
103
+ When PR #2 depends on PR #1's branch, point #2's base at #1's branch:
104
+
105
+ ```bash
106
+ git switch feat/step-1
107
+ gh pr create --base main --title "feat: step 1"
108
+
109
+ git switch -c feat/step-2 feat/step-1
110
+ # … edit …
111
+ git push -u origin feat/step-2
112
+ gh pr create --base feat/step-1 --title "feat: step 2 (depends on #N)"
113
+
114
+ # When step-1 merges, automatically retarget step-2 to main:
115
+ gh pr edit <step-2-pr> --base main
116
+ ```
117
+
118
+ ## Why CodraGraph helps here
119
+
120
+ The PR review GitHub Action (codragraph-pr-review) ALREADY automates the
121
+ diff-comment side. As an author, you should ALSO run impact locally
122
+ before requesting review — it catches the "I forgot to update a caller"
123
+ class of problem that a reviewer is most likely to flag:
124
+
125
+ ```bash
126
+ codragraph_detect_changes({scope: "compare", base_ref: "main"})
127
+ # → list of changed symbols + affected execution flows
128
+
129
+ # For each non-trivial changed symbol:
130
+ codragraph_impact({target: "<symbol>", direction: "upstream"})
131
+ # → d=1 callers. Are they all updated in the PR?
132
+ ```
133
+
134
+ If d=1 callers exist OUTSIDE your PR diff, that's the breakage waiting
135
+ to happen. Either update them or document the migration path before
136
+ review.
137
+
138
+ ## Author checklist before requesting review
139
+
140
+ ```
141
+ - [ ] Branch rebased onto main (or merged main in, if shared)
142
+ - [ ] CI green: gh pr checks <N>
143
+ - [ ] codragraph_detect_changes — confirm scope is what you intended
144
+ - [ ] codragraph_impact on each public symbol you changed — d=1 callers updated
145
+ - [ ] PR title is conventional (feat: / fix: / docs: / etc.)
146
+ - [ ] PR body has Summary + Test plan
147
+ - [ ] Reviewers and labels set
148
+ - [ ] gh pr ready <N> if it was draft
149
+ ```
150
+
151
+ ## Reviewer checklist (if you're reviewing)
152
+
153
+ ```
154
+ - [ ] Pull the diff: gh pr diff <N> | less
155
+ - [ ] Use codragraph-pr-review skill: detect_changes + impact + context
156
+ - [ ] Run tests locally: gh pr checkout <N> && npm test
157
+ - [ ] Approve / request-changes / comment via gh pr review <N>
158
+ ```
159
+
160
+ ```bash
161
+ gh pr review <N> --approve --body "LGTM. Verified the impact graph clean."
162
+ gh pr review <N> --request-changes --body "…"
163
+ gh pr review <N> --comment --body "…"
164
+
165
+ # Inline comments require the GitHub UI (gh CLI doesn't support them yet).
166
+ ```
167
+
168
+ ## Pitfalls
169
+
170
+ | Pitfall | Symptom | Fix |
171
+ |---|---|---|
172
+ | Created PR from main | "There isn't anything to compare" | Push to a feature branch first |
173
+ | Wrong base | PR shows commits from main | `gh pr edit <N> --base <correct-base>` |
174
+ | Squash-merged a stacked PR's parent | Child PR shows 0 commits | `git rebase main` on child, force-push |
175
+ | `gh pr merge --auto` without branch protection | Merges immediately, not on green | Configure branch-protection rules first |
176
+ | Closing instead of merging | Commits don't land on main | `gh pr merge` not `gh pr close` |
@@ -0,0 +1,187 @@
1
+ ---
2
+ name: codragraph-gh-release-workflow
3
+ description: "Use for the release workflow — semver bump, tag, generate release notes, attach assets, draft vs published, prerelease tagging, and propagating to npm. Examples: \"cut a release\", \"create a GitHub release\", \"draft release notes\", \"upload binaries to release\", \"prerelease v2 alpha\""
4
+ ---
5
+
6
+ # Release Workflow with `gh`
7
+
8
+ ## When to Use
9
+
10
+ - "Cut a 1.7.0 release."
11
+ - "Draft release notes from commits."
12
+ - "Attach the built binaries to the release."
13
+ - "Mark this as a prerelease (alpha / beta / RC)."
14
+ - "Re-publish notes after I edited them."
15
+
16
+ ## Pre-release checklist (do these BEFORE `gh release create`)
17
+
18
+ ```
19
+ - [ ] Branch is main / release/x.y, fully synced
20
+ - [ ] CHANGELOG.md updated (or ready to be auto-generated)
21
+ - [ ] Version bumped in package.json / Cargo.toml / pyproject.toml
22
+ - [ ] All commits since last tag intentional (no leftover wip)
23
+ - [ ] CI green on the release commit (gh pr checks <N>)
24
+ - [ ] codragraph diff <last-tag> HEAD --semantic — review removed APIs
25
+ (any removed public API = SemVer major; document loudly in notes)
26
+ ```
27
+
28
+ ## Cutting the release
29
+
30
+ ```bash
31
+ # 1. Bump + commit version
32
+ npm version 1.7.0 --no-git-tag-version # or pnpm version, or manual edit
33
+ git add package.json package-lock.json
34
+ git commit -m "chore(release): 1.7.0"
35
+ git push origin main
36
+
37
+ # 2. Tag (annotated, signed if you have GPG):
38
+ git tag -a v1.7.0 -m "Release 1.7.0" # annotated
39
+ git tag -s v1.7.0 -m "Release 1.7.0" # signed (requires GPG setup)
40
+ git push origin v1.7.0
41
+
42
+ # 3. Create GitHub release. Auto-generate notes from commits since the previous tag:
43
+ gh release create v1.7.0 --generate-notes
44
+ ```
45
+
46
+ `--generate-notes` uses `.github/release.yml` (if present) for category
47
+ filtering, or falls back to a flat list of commit titles.
48
+
49
+ ## Custom notes
50
+
51
+ ```bash
52
+ # Notes from a file:
53
+ gh release create v1.7.0 --notes-file RELEASE_NOTES.md
54
+
55
+ # Inline (HEREDOC, the right way):
56
+ gh release create v1.7.0 --notes "$(cat <<'EOF'
57
+ ## What's new
58
+ - npx zero-install entry — no more 3-step setup
59
+ - PR review GitHub Action (deterministic + LLM modes)
60
+ - 17 built-in workflow skills
61
+
62
+ ## Breaking
63
+ - None.
64
+
65
+ ## Upgrade
66
+ \`\`\`
67
+ npm i -g @codragraph/cli@1.7.0
68
+ \`\`\`
69
+ EOF
70
+ )"
71
+
72
+ # Edit notes after publishing:
73
+ gh release edit v1.7.0 --notes-file new-notes.md
74
+ ```
75
+
76
+ ## Attach assets
77
+
78
+ ```bash
79
+ # After creating the release, upload binaries / source bundles:
80
+ gh release upload v1.7.0 dist/cli-linux-x64.tar.gz dist/cli-darwin-arm64.tar.gz
81
+
82
+ # Or in one shot at create time:
83
+ gh release create v1.7.0 dist/*.tar.gz dist/*.zip --generate-notes
84
+ ```
85
+
86
+ ## Draft vs published vs prerelease
87
+
88
+ ```bash
89
+ # Draft (visible only to maintainers, not yet announced):
90
+ gh release create v1.7.0 --draft --generate-notes
91
+
92
+ # Promote draft → published:
93
+ gh release edit v1.7.0 --draft=false
94
+
95
+ # Prerelease (alpha / beta / RC — semver string ends with -alpha.N etc.):
96
+ gh release create v2.0.0-alpha.1 --prerelease --generate-notes
97
+
98
+ # Mark an existing release as latest (otherwise GitHub picks by semver):
99
+ gh release edit v1.7.0 --latest
100
+ ```
101
+
102
+ ## Re-publish a release after editing
103
+
104
+ ```bash
105
+ # View existing release:
106
+ gh release view v1.7.0
107
+
108
+ # Edit notes:
109
+ gh release edit v1.7.0 --notes-file fixed-notes.md
110
+
111
+ # Upload missing asset:
112
+ gh release upload v1.7.0 dist/cli-windows-x64.zip
113
+ ```
114
+
115
+ ## Coordinating with npm publish
116
+
117
+ For a TypeScript / Node package, the GitHub release and the npm publish
118
+ are TWO separate events:
119
+
120
+ ```bash
121
+ # Order: tag → npm publish → GH release (so the release links a version
122
+ # users can `npm install`).
123
+
124
+ git tag v1.7.0 && git push origin v1.7.0
125
+ npm publish --access public # for scoped packages
126
+ gh release create v1.7.0 --generate-notes
127
+ ```
128
+
129
+ You can automate this in a workflow that triggers on `push` of a `v*` tag:
130
+
131
+ ```yaml
132
+ on:
133
+ push:
134
+ tags: ['v*']
135
+ jobs:
136
+ release:
137
+ runs-on: ubuntu-latest
138
+ steps:
139
+ - uses: actions/checkout@v4
140
+ - uses: actions/setup-node@v4
141
+ with:
142
+ node-version: '20'
143
+ registry-url: 'https://registry.npmjs.org'
144
+ - run: npm ci && npm run build
145
+ - run: npm publish --access public
146
+ env:
147
+ NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
148
+ - uses: softprops/action-gh-release@v2
149
+ with:
150
+ generate_release_notes: true
151
+ ```
152
+
153
+ ## Why CodraGraph helps here
154
+
155
+ The structural diff between two tags is the most honest changelog you'll
156
+ ever produce — it's derived from the graph, not from commit messages
157
+ that lie:
158
+
159
+ ```bash
160
+ codragraph diff v1.6.4 v1.7.0 --semantic --json > /tmp/diff.json
161
+
162
+ # What changed:
163
+ jq '.semantic.addedAPIs | length, .semantic.removedAPIs | length, .semantic.classifiedModifications | length' /tmp/diff.json
164
+
165
+ # Generate a structured "API changes" section for the release notes:
166
+ jq -r '
167
+ "### Added APIs\n" +
168
+ ([.semantic.addedAPIs[] | "- `" + (.name // .id) + "`"] | join("\n")) +
169
+ "\n\n### Removed APIs (BREAKING)\n" +
170
+ ([.semantic.removedAPIs[] | "- `" + (.name // .id) + "`"] | join("\n"))
171
+ ' /tmp/diff.json
172
+ ```
173
+
174
+ Removed APIs = SemVer major. Modified signatures with parameter-count
175
+ changes = SemVer major. Use this to keep your bump honest.
176
+
177
+ ## Pitfalls
178
+
179
+ | Pitfall | Symptom | Fix |
180
+ |---|---|---|
181
+ | Forgot to push the tag | GH release creation fails | `git push origin v1.7.0` |
182
+ | `npm publish` before the tag | Tag not on the published commit | publish AFTER pushing the tag |
183
+ | Removed an API but bumped only minor | Breaking change in non-major release | Always run `codragraph diff <prev> HEAD --semantic` and bump major if removedAPIs is non-empty |
184
+ | `--generate-notes` produces noise | All commit messages flat-listed | Add `.github/release.yml` to categorize by labels / paths |
185
+ | Wrong release marked `latest` | Older release stays as latest | `gh release edit <new-version> --latest` |
186
+ | Released a prerelease as stable | Users on `latest` channel get unstable code | Always `--prerelease` for alpha / beta / RC |
187
+ ```
@@ -0,0 +1,176 @@
1
+ ---
2
+ name: codragraph-git-bisect
3
+ description: "Use when hunting a regression — narrowing down which commit introduced a bug across N commits using binary search. Covers manual bisect, automated bisect with a test script, and how to combine bisect with CodraGraph context to understand the bad commit. Examples: \"find which commit broke X\", \"git bisect\", \"regression hunt\", \"automated bisect\""
4
+ ---
5
+
6
+ # Regression Hunting with `git bisect`
7
+
8
+ ## When to Use
9
+
10
+ - "Tests pass at commit A but fail at commit B — which commit broke it?"
11
+ - "Performance regressed somewhere in the last 200 commits."
12
+ - "Find the commit that introduced this bug."
13
+ - "Automate a bisect with my test suite."
14
+
15
+ ## The principle
16
+
17
+ Bisect performs binary search over the commit graph. Given a
18
+ known-good commit (`good`) and a known-bad commit (`bad`), it picks the
19
+ midpoint, you mark it, and it halves the search space until exactly one
20
+ commit is identified. Log₂(N) tests instead of N.
21
+
22
+ ## Manual workflow
23
+
24
+ ```bash
25
+ # Start
26
+ git bisect start
27
+ git bisect bad <known-bad> # often HEAD or a commit/tag
28
+ git bisect good <known-good> # something older that worked
29
+
30
+ # Now git checks out the midpoint. Test it.
31
+ # Mark each midpoint:
32
+ git bisect bad # if the bug IS present
33
+ git bisect good # if the bug is NOT present
34
+ git bisect skip # if the commit can't be tested
35
+ # (won't compile, broken in some other way)
36
+
37
+ # Bisect narrows down. Repeat marking until git announces:
38
+ # → "<sha> is the first bad commit"
39
+
40
+ # Done — back to your starting state:
41
+ git bisect reset
42
+ ```
43
+
44
+ ## Automated workflow
45
+
46
+ If you have a script that exits 0 on good and non-zero on bad, you can
47
+ fully automate:
48
+
49
+ ```bash
50
+ git bisect start HEAD <known-good>
51
+ git bisect run ./scripts/repro-bug.sh
52
+ # → bisect runs the script at each midpoint; marks good/bad automatically;
53
+ # announces the first bad commit when done
54
+ ```
55
+
56
+ The script's exit codes:
57
+
58
+ ```
59
+ exit 0 → mark as good
60
+ exit 1..124, → mark as bad
61
+ 126..127
62
+ exit 125 → mark as skip (can't test this commit)
63
+ exit 128+ → abort the bisect
64
+ ```
65
+
66
+ ## Test-script template
67
+
68
+ ```bash
69
+ #!/usr/bin/env bash
70
+ # scripts/repro-bug.sh — bisect-aware reproduction script
71
+ set -e
72
+
73
+ # 1. If this commit can't even build, skip it (don't say bad).
74
+ npm install --silent --no-audit > /dev/null 2>&1 || exit 125
75
+ npm run build > /dev/null 2>&1 || exit 125
76
+
77
+ # 2. Run the targeted test that demonstrates the bug.
78
+ if npx vitest run path/to/regression.test.ts --reporter=basic > /dev/null 2>&1; then
79
+ exit 0 # good
80
+ else
81
+ exit 1 # bad
82
+ fi
83
+ ```
84
+
85
+ ## Why CodraGraph helps here
86
+
87
+ Once bisect names the first bad commit, the next question is *why*
88
+ that commit broke things. CodraGraph's `diff --semantic` and `context`
89
+ tell you exactly what changed, structurally:
90
+
91
+ ```bash
92
+ git bisect log # see the bisection that found it
93
+ BAD=$(git bisect log | grep "first bad commit" | awk '{print $1}')
94
+
95
+ # What changed structurally between good and bad?
96
+ codragraph diff "$BAD"^ "$BAD" --semantic
97
+ # → addedAPIs / removedAPIs / classifiedModifications
98
+
99
+ # Get full context on the modified symbols
100
+ codragraph_context({name: "<symbol from the diff>"})
101
+ ```
102
+
103
+ This turns "commit X is bad" into "commit X removed/modified Y, which
104
+ broke flow Z." That's the actionable answer.
105
+
106
+ ## Bisect across non-linear history
107
+
108
+ If your history has merges, bisect handles them but the midpoints are
109
+ weird (commits from sibling branches). Two helpful flags:
110
+
111
+ ```bash
112
+ git bisect start --first-parent HEAD <known-good>
113
+ # → only follows the first-parent path (main line of merges).
114
+ # Useful when feature-branch commits aren't worth testing individually.
115
+
116
+ git bisect start --no-checkout HEAD <known-good>
117
+ # → don't checkout each midpoint; instead just sets BISECT_HEAD ref.
118
+ # Use when checkout is expensive (huge repo, slow build).
119
+ ```
120
+
121
+ ## Pitfalls
122
+
123
+ | Pitfall | What happens | Fix |
124
+ |---|---|---|
125
+ | Forgot to `bisect reset` after finishing | Stuck in detached state, future `git pull` weird | `git bisect reset` returns you to your branch |
126
+ | Test depends on uncommitted state | Bisect finds noise, not the real bug | Stash before bisecting; ensure script is self-contained |
127
+ | Build broken in middle of range | Every middle commit looks "bad" | Use `git bisect skip` or exit-code 125 in the auto script |
128
+ | Submodules not in sync | Wrong code being tested | Add `git submodule update --init --recursive` to the script |
129
+ | Found a "bad commit" that's a merge | Probably a transient issue or skip-worthy | Inspect the merge: `git show --first-parent <merge>` |
130
+
131
+ ## Checklist
132
+
133
+ ```
134
+ - [ ] Identified a clear known-good and known-bad commit
135
+ - [ ] Have a deterministic, single-command reproduction
136
+ - [ ] Repro is fast enough (<2 min ideally; bisect runs ~log₂(N) times)
137
+ - [ ] Build can complete on every commit in the range (or skip script handles it)
138
+ - [ ] Use `git bisect run <script>` for full automation
139
+ - [ ] After hit: codragraph diff <bad>^ <bad> --semantic to understand WHY
140
+ - [ ] git bisect reset before resuming work
141
+ ```
142
+
143
+ ## Example: "Tests started failing in the last 3 weeks"
144
+
145
+ ```bash
146
+ # 1. Confirm endpoints
147
+ git checkout main && npx vitest run path/to/regression.test.ts
148
+ # → fails
149
+
150
+ git checkout v1.5.3 # known-good 3 weeks ago
151
+ npx vitest run path/to/regression.test.ts
152
+ # → passes
153
+
154
+ # 2. Automate
155
+ git bisect start main v1.5.3
156
+ cat > /tmp/repro.sh <<'EOF'
157
+ #!/usr/bin/env bash
158
+ set -e
159
+ npm install --silent || exit 125
160
+ npx vitest run path/to/regression.test.ts --reporter=basic > /dev/null 2>&1
161
+ EOF
162
+ chmod +x /tmp/repro.sh
163
+ git bisect run /tmp/repro.sh
164
+ # → "abc1234 is the first bad commit"
165
+
166
+ # 3. Understand the bad commit
167
+ codragraph diff abc1234^ abc1234 --semantic
168
+ # → modified validateUser (parameter count 3→4)
169
+
170
+ codragraph_context({name: "validateUser"})
171
+ # → caller `loginFlow` still passes 3 args — that's the regression
172
+
173
+ # 4. Reset and fix
174
+ git bisect reset
175
+ # Patch the caller; tests pass; ship.
176
+ ```
@@ -0,0 +1,147 @@
1
+ ---
2
+ name: codragraph-git-force-push
3
+ description: "Use when the user is about to force-push, recovering after someone else force-pushed, or asking whether it's safe. Covers --force vs --force-with-lease, recovery from a bad force-push, and the rules for shared vs personal branches. Examples: \"force push\", \"is force push safe\", \"someone overwrote my work\", \"git push rejected\", \"--force-with-lease\""
4
+ ---
5
+
6
+ # Force Push — When, How, and Recovery
7
+
8
+ ## When to Use
9
+
10
+ - "Can I force push to this branch?"
11
+ - "Git is rejecting my push, is force the answer?"
12
+ - "Someone force-pushed and lost my commits — help."
13
+ - "What's the difference between --force and --force-with-lease?"
14
+
15
+ ## The rules
16
+
17
+ 1. **Never `--force` on a shared branch** without coordinating. You will
18
+ silently overwrite collaborators' commits. Their reflogs save them; their
19
+ patience does not.
20
+ 2. **Always prefer `--force-with-lease`** over `--force`. It refuses the
21
+ push if the remote has commits you haven't seen — i.e. someone pushed
22
+ while you were rebasing.
23
+ 3. **Never force on `main` / `master` / `release/*`** unless you're recovering
24
+ from a documented incident with explicit sign-off. Branch protection
25
+ should make this impossible; if it's possible, fix the protection rule.
26
+ 4. **Force-pushing your OWN feature branch** after a rebase is normal and
27
+ expected. Just use `--force-with-lease`.
28
+
29
+ ## Decision tree
30
+
31
+ ```
32
+ Is the branch protected on the remote?
33
+ ├─ yes → STOP. Don't force. Open a PR or get an admin to lift protection
34
+ │ for a documented operation.
35
+ └─ no → Is anyone else committing to this branch?
36
+ ├─ yes → STOP. Coordinate. They'll lose work if you force.
37
+ └─ no → Have you fetched the latest remote tip?
38
+ ├─ no → git fetch first, then `git push --force-with-lease`
39
+ └─ yes → `git push --force-with-lease` is safe.
40
+ ```
41
+
42
+ ## --force vs --force-with-lease
43
+
44
+ ```bash
45
+ # DANGEROUS: overwrites whatever is on the remote, no matter what.
46
+ git push --force
47
+
48
+ # SAFER: only succeeds if the remote tip matches what you last fetched.
49
+ # If anyone pushed in the meantime, this aborts.
50
+ git push --force-with-lease
51
+
52
+ # EVEN SAFER: explicitly require the remote SHA to be what you expect.
53
+ git push --force-with-lease=<branch>:<expected-sha>
54
+ ```
55
+
56
+ > Make `--force-with-lease` your default by aliasing:
57
+ > `git config --global alias.fwl 'push --force-with-lease'`
58
+
59
+ ## Recovery: someone force-pushed and lost your work
60
+
61
+ Your local clone has the original commits in its reflog. You haven't lost
62
+ anything as long as you haven't run `git gc --prune=now` AND your reflog
63
+ is still intact (default 90-day expiry).
64
+
65
+ ```bash
66
+ # 1. Find the lost commit on YOUR machine
67
+ git reflog show <branch>
68
+ # → look for "<branch>@{N}: ... before force push" or your last commit
69
+
70
+ # 2. Inspect it
71
+ git show <sha>
72
+ git log <sha> --oneline -20
73
+
74
+ # 3a. If they overwrote with rubbish: reset your branch to your old tip
75
+ # (this re-creates the divergence; coordinate before re-pushing)
76
+ git checkout <branch>
77
+ git reset --hard <sha-from-reflog>
78
+
79
+ # 3b. If they had legitimate changes you also want to keep: cherry-pick
80
+ # YOUR lost commits onto their version
81
+ git checkout <branch>
82
+ git pull # accept their version
83
+ git cherry-pick <your-lost-sha-1> <your-lost-sha-2> ...
84
+
85
+ # 4. Push back (with --force-with-lease to avoid the same problem)
86
+ git push --force-with-lease
87
+ ```
88
+
89
+ If the only copy of the lost commits was on the remote (no local clone),
90
+ the recovery options are:
91
+
92
+ - GitHub: contact GitHub Support — they retain dangling commits for ~30 days.
93
+ - Self-hosted GitLab/Gitea: server-side reflog (if enabled) or a backup.
94
+
95
+ ## Recovery: I force-pushed something I shouldn't have
96
+
97
+ If you JUST did it and have a terminal where the previous local state still
98
+ exists:
99
+
100
+ ```bash
101
+ git reflog # find the previous tip
102
+ git reset --hard <previous-sha>
103
+ git push --force-with-lease # restore the remote
104
+ ```
105
+
106
+ If you've already moved on locally:
107
+
108
+ ```bash
109
+ git fetch origin
110
+ git reflog show origin/<branch>
111
+ # → look for the line BEFORE the force push you just did
112
+ git reset --hard <recovered-sha>
113
+ git push --force-with-lease
114
+ ```
115
+
116
+ ## Why CodraGraph helps here
117
+
118
+ After a force-push (yours or theirs), `codragraph diff` against the
119
+ recovered SHA tells you EXACTLY what structural changes were undone or
120
+ reapplied — so you can verify nothing important got lost in the
121
+ recovery:
122
+
123
+ ```bash
124
+ codragraph diff <recovered-sha> HEAD --semantic
125
+ # If addedAPIs / removedAPIs reveals work that should still be present,
126
+ # the recovery is incomplete — go back to the reflog and pick more.
127
+ ```
128
+
129
+ ## Checklist (before any --force / --force-with-lease)
130
+
131
+ ```
132
+ - [ ] Branch is NOT protected on the remote
133
+ - [ ] Branch is NOT main / master / release/*
134
+ - [ ] You're the only one committing to it (git log <branch> | grep -c Author)
135
+ - [ ] You've git-fetched recently (so --force-with-lease has fresh info)
136
+ - [ ] Using --force-with-lease, NEVER bare --force
137
+ - [ ] If recovering: verified the recovered SHA via codragraph diff
138
+ ```
139
+
140
+ ## Pitfalls
141
+
142
+ | Pitfall | What goes wrong | Avoidance |
143
+ |---|---|---|
144
+ | `git push -f` on shared branch | collaborators' commits silently gone | --force-with-lease + check `git log <branch>` for other authors first |
145
+ | `--force-with-lease` after `git fetch` | lease check passes against the freshly-fetched tip — no protection | run lease BEFORE the fetch, or specify the expected SHA explicitly |
146
+ | Force-push during CI run | CI race conditions, half-deployed states | wait for CI to finish, then force |
147
+ | Forgetting reflog can save you | panic | reflogs default to 90 days; check `git reflog` before destroying anything |