@codragraph/cli 1.6.3 → 2.0.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 (89) hide show
  1. package/README.md +50 -16
  2. package/dist/cli/ai-context.js +2 -2
  3. package/dist/cli/analyze.d.ts +22 -0
  4. package/dist/cli/analyze.js +111 -8
  5. package/dist/cli/compress-stats.d.ts +29 -0
  6. package/dist/cli/compress-stats.js +97 -0
  7. package/dist/cli/graphstore.d.ts +6 -2
  8. package/dist/cli/graphstore.js +24 -2
  9. package/dist/cli/index.js +17 -6
  10. package/dist/cli/profile-heap.d.ts +35 -0
  11. package/dist/cli/profile-heap.js +126 -0
  12. package/dist/cli/setup.d.ts +13 -0
  13. package/dist/cli/setup.js +75 -29
  14. package/dist/cli/skill-gen.d.ts +14 -2
  15. package/dist/cli/skill-gen.js +53 -20
  16. package/dist/cli/tool.js +4 -0
  17. package/dist/config/ignore-service.js +1 -1
  18. package/dist/core/embeddings/embedding-pipeline.js +24 -7
  19. package/dist/core/group/bridge-db.js +111 -24
  20. package/dist/core/group/extractors/grpc-patterns/proto.js +1 -12
  21. package/dist/core/ingestion/call-processor.js +2 -2
  22. package/dist/core/ingestion/cobol/cobol-preprocessor.js +1 -1
  23. package/dist/core/ingestion/cobol/jcl-parser.d.ts +1 -1
  24. package/dist/core/ingestion/cobol/jcl-parser.js +1 -1
  25. package/dist/core/ingestion/cobol-processor.d.ts +1 -1
  26. package/dist/core/ingestion/cobol-processor.js +1 -1
  27. package/dist/core/ingestion/heritage-extractors/generic.js +1 -1
  28. package/dist/core/ingestion/heritage-processor.js +1 -1
  29. package/dist/core/ingestion/import-processor.js +1 -1
  30. package/dist/core/ingestion/mro-processor.js +1 -1
  31. package/dist/core/ingestion/parsing-processor.js +1 -1
  32. package/dist/core/ingestion/type-extractors/c-cpp.js +1 -1
  33. package/dist/core/ingestion/type-extractors/python.js +1 -1
  34. package/dist/core/ingestion/type-extractors/shared.js +0 -3
  35. package/dist/core/lbug/content-read.d.ts +46 -0
  36. package/dist/core/lbug/content-read.js +64 -0
  37. package/dist/core/lbug/csv-generator.d.ts +2 -6
  38. package/dist/core/lbug/csv-generator.js +45 -12
  39. package/dist/core/lbug/lbug-adapter.d.ts +4 -1
  40. package/dist/core/lbug/lbug-adapter.js +157 -25
  41. package/dist/core/lbug/pool-adapter.js +51 -44
  42. package/dist/core/lbug/schema.d.ts +7 -7
  43. package/dist/core/lbug/schema.js +18 -0
  44. package/dist/core/run-analyze.d.ts +13 -0
  45. package/dist/core/run-analyze.js +91 -4
  46. package/dist/core/search/bm25-index.js +153 -12
  47. package/dist/core/wiki/generator.js +4 -4
  48. package/dist/mcp/local/local-backend.js +22 -5
  49. package/dist/mcp/resources.js +2 -3
  50. package/dist/server/api.js +4 -3
  51. package/dist/storage/repo-manager.d.ts +39 -0
  52. package/dist/storage/repo-manager.js +19 -0
  53. package/hooks/claude/codragraph-hook.cjs +108 -5
  54. package/hooks/claude/pre-tool-use.sh +6 -1
  55. package/package.json +4 -4
  56. package/scripts/build-tree-sitter-proto.cjs +15 -3
  57. package/scripts/patch-tree-sitter-swift.cjs +17 -4
  58. package/skills/codragraph-api-surface.md +110 -0
  59. package/skills/codragraph-cli.md +5 -5
  60. package/skills/codragraph-config-audit.md +146 -0
  61. package/skills/codragraph-cross-repo-impact.md +135 -0
  62. package/skills/codragraph-data-lineage.md +137 -0
  63. package/skills/codragraph-dead-code.md +119 -0
  64. package/skills/codragraph-debugging.md +1 -1
  65. package/skills/codragraph-exploring.md +1 -1
  66. package/skills/codragraph-gh-actions-debug.md +162 -0
  67. package/skills/codragraph-gh-issue-workflow.md +178 -0
  68. package/skills/codragraph-gh-pr-workflow.md +176 -0
  69. package/skills/codragraph-gh-release-workflow.md +187 -0
  70. package/skills/codragraph-git-bisect.md +176 -0
  71. package/skills/codragraph-git-force-push.md +147 -0
  72. package/skills/codragraph-git-history-rewrite.md +174 -0
  73. package/skills/codragraph-git-rebase-vs-merge.md +138 -0
  74. package/skills/codragraph-git-recovery.md +181 -0
  75. package/skills/codragraph-git-worktree.md +145 -0
  76. package/skills/codragraph-guide.md +1 -1
  77. package/skills/codragraph-impact-analysis.md +1 -1
  78. package/skills/codragraph-migration-tracking.md +130 -0
  79. package/skills/codragraph-notebook-context.md +136 -0
  80. package/skills/codragraph-observability-coverage.md +125 -0
  81. package/skills/codragraph-onboarding.md +129 -0
  82. package/skills/codragraph-perf-hotspots.md +132 -0
  83. package/skills/codragraph-pr-review.md +1 -1
  84. package/skills/codragraph-project-switcher.md +116 -0
  85. package/skills/codragraph-refactoring.md +1 -1
  86. package/skills/codragraph-security-audit.md +144 -0
  87. package/skills/codragraph-sql-tracing.md +122 -0
  88. package/skills/codragraph-supply-chain-audit.md +153 -0
  89. package/skills/codragraph-test-coverage.md +97 -0
@@ -0,0 +1,135 @@
1
+ ---
2
+ name: codragraph-cross-repo-impact
3
+ description: "Use when assessing the blast radius of a change that crosses repository boundaries — a shared library used by multiple services, a contract / protobuf / OpenAPI schema consumed by N consumers, a microservices change. Examples: \"what services consume X\", \"cross-repo blast radius\", \"will this break the consumers\", \"who depends on this contract\""
4
+ ---
5
+
6
+ # Cross-Repo Impact Analysis with CodraGraph
7
+
8
+ ## When to Use
9
+
10
+ - "What other repos consume `<symbol>` from this one?"
11
+ - "If I change this gRPC method / OpenAPI route / protobuf message, what breaks?"
12
+ - "Cross-repo blast radius for `<change>`"
13
+ - Microservices architecture: assessing a contract change
14
+ - Shared-library author: deciding if a function is safe to remove
15
+
16
+ ## Why CodraGraph helps here
17
+
18
+ CodraGraph's **groups** (sets of related repos sharing a `group.yaml`)
19
+ maintain a Contract Registry — provider/consumer rows for every cross-repo
20
+ reference (gRPC service / method, OpenAPI route, protobuf message). The
21
+ group-mode `impact` walks both the local call graph AND the contract
22
+ bridges, so a single call returns the blast radius across every member
23
+ repo. You don't need to re-run impact in each consumer separately.
24
+
25
+ ## Workflow
26
+
27
+ ```
28
+ 1. Identify the group:
29
+ codragraph_group_list({})
30
+ → list of groups + their member repos
31
+
32
+ 2. Confirm the symbol exists in the producer repo:
33
+ codragraph_context({repo: "<producerRepo>", name: "<symbol>"})
34
+
35
+ 3. Run group-mode impact:
36
+ codragraph_impact({repo: "@<group>", target: "<symbol>", direction: "upstream"})
37
+ → d=1 callers spanning every group member
38
+ (in-repo callers + contract-bridge consumers)
39
+
40
+ 4. Inspect the Contract Registry to see provider/consumer rows directly:
41
+ READ codragraph://group/<groupName>/contracts
42
+ → list of contracts touching the symbol or its API
43
+
44
+ 5. Check group-status / staleness:
45
+ READ codragraph://group/<groupName>/status
46
+ → which member repos haven't been re-indexed recently
47
+ (stale members produce stale impact results)
48
+
49
+ 6. Surface the worst-case consumer:
50
+ any consumer not updated since the schema change = potential breakage
51
+ ```
52
+
53
+ > If any member repo's index is stale, group-mode impact may underreport.
54
+ > Re-analyze stale members before relying on the results.
55
+
56
+ ## Checklist
57
+
58
+ ```
59
+ - [ ] group_list to confirm the group exists and the producer is a member
60
+ - [ ] context on the symbol in the producer repo
61
+ - [ ] Group-mode impact upstream
62
+ - [ ] Inspect Contract Registry for provider/consumer rows
63
+ - [ ] Check group/status for stale members; re-analyze if needed
64
+ - [ ] List affected consumer repos by impact depth
65
+ - [ ] Recommend coordinated PRs across consumers (if breaking)
66
+ ```
67
+
68
+ ## When to Use Which Tool
69
+
70
+ | Question | Tool |
71
+ | --- | --- |
72
+ | "Which repos are in my group?" | `group_list` |
73
+ | "What contracts cross between member A and member B?" | Contract Registry resource |
74
+ | "If I change this provider method, what breaks?" | Group-mode `impact` |
75
+ | "Are all consumers up to date with the latest provider commit?" | `group/<name>/status` resource |
76
+ | "What's the structural diff between last release and now in repo X?" | Per-repo `diff --semantic` |
77
+
78
+ ## Example: "Will renaming `getUserProfile` break my microservices?"
79
+
80
+ ```
81
+ 1. codragraph_group_list({})
82
+ → group "platform": [user-service, web-app, mobile-bff, admin-portal]
83
+
84
+ 2. codragraph_context({repo: "user-service", name: "getUserProfile"})
85
+ → exported gRPC method in user.proto, defined in user-service
86
+
87
+ 3. codragraph_impact({repo: "@platform", target: "getUserProfile", direction: "upstream"})
88
+ → d=1 callers (across the group):
89
+ - web-app/src/api/userClient.ts (CALLS via grpc-web)
90
+ - mobile-bff/internal/user.go (CALLS via grpc.NewClient)
91
+ - admin-portal/src/services/users.tsx (CALLS via grpc-web)
92
+ → 3 consumer repos depend on this method by exact name.
93
+
94
+ 4. READ codragraph://group/platform/contracts
95
+ → user.UserService.getUserProfile: provider=user-service,
96
+ consumers=[web-app, mobile-bff, admin-portal]
97
+
98
+ 5. READ codragraph://group/platform/status
99
+ → web-app last indexed 2 hours ago ✓
100
+ → mobile-bff last indexed 3 days ago ⚠ (might miss recent callers)
101
+ → admin-portal last indexed 1 month ago ⚠⚠ (re-analyze first!)
102
+
103
+ 6. Recommendation:
104
+ - HIGH-RISK rename. 3 consumer repos must change in lockstep.
105
+ - Re-index admin-portal before trusting the d=1 list.
106
+ - Coordinated PR sequence:
107
+ 1. Add new method (getUserProfileV2) in user-service
108
+ 2. Migrate web-app, mobile-bff, admin-portal to V2
109
+ 3. Remove getUserProfile in user-service after all consumers ship
110
+ - Alternative: keep both, deprecate old, drop in next major.
111
+ ```
112
+
113
+ ## Output Format
114
+
115
+ ```markdown
116
+ ## Cross-Repo Impact: `<symbol>` in `<producer-repo>` (group `@<group>`)
117
+
118
+ ### Consumers (d=1)
119
+ | Repo | Caller | Path | Notes |
120
+ | --- | --- | --- | --- |
121
+ | web-app | userClient.ts | grpc-web | active |
122
+ | mobile-bff | internal/user.go | grpc native | active |
123
+ | admin-portal | services/users.tsx | grpc-web | last indexed 1mo ago ⚠ |
124
+
125
+ ### Contracts touching this symbol
126
+ - `user.UserService.getUserProfile` (provider: user-service)
127
+
128
+ ### Staleness
129
+ Re-analyze `admin-portal` before trusting these results.
130
+
131
+ ### Recommended migration sequence
132
+ 1. Add `getUserProfileV2` alongside the old method
133
+ 2. Migrate consumers to V2 (separate PRs per repo)
134
+ 3. Remove old method after all consumers ship
135
+ ```
@@ -0,0 +1,137 @@
1
+ ---
2
+ name: codragraph-data-lineage
3
+ description: "Use when tracing data flow through an ETL pipeline, finding where a column or table is read/written, mapping data dependencies in a notebook-heavy or data-engineering project. Examples: \"where does this data come from\", \"trace this column\", \"data lineage for X\", \"who reads from this table\", \"what's downstream of this query\""
4
+ ---
5
+
6
+ # Data Lineage with CodraGraph
7
+
8
+ ## When to Use
9
+
10
+ - "Where does the `user_events` table get written?"
11
+ - "Trace the data flow that produces `daily_revenue.csv`"
12
+ - "What's downstream of this Snowflake query?"
13
+ - "Which notebook cells transform this DataFrame?"
14
+ - Auditing a data pipeline before changing a schema
15
+ - Understanding an unfamiliar ETL project
16
+
17
+ ## Why CodraGraph helps here
18
+
19
+ Data pipelines often look like a graph of small functions: `extract_*`,
20
+ `transform_*`, `load_*`, `enrich_*`. Their connections are *function calls*
21
+ plus *string-literal table names* and *file paths*. CodraGraph already
22
+ captures the call graph; combining it with `query` over identifier strings
23
+ gives you data lineage at the *symbol* level, regardless of whether your
24
+ pipeline is in vanilla Python, Airflow, dbt, Pandas, PySpark, or Notebooks.
25
+
26
+ ## Workflow
27
+
28
+ ```
29
+ 1. codragraph_query({query: "<table_or_column_name>"})
30
+ → find every symbol that mentions the data identifier
31
+
32
+ 2. For each candidate symbol:
33
+ codragraph_context({name: "<symbol>"})
34
+ → see callers (who triggers this read/write) and callees (what it depends on)
35
+
36
+ 3. Walk the producer side (downstream → upstream):
37
+ codragraph_impact({target: "<load function>", direction: "upstream"})
38
+ → trace back to where the data originates
39
+
40
+ 4. Walk the consumer side (upstream → downstream):
41
+ codragraph_impact({target: "<extract function>", direction: "downstream"})
42
+ → trace forward to every transform / sink that depends on it
43
+
44
+ 5. READ codragraph://repo/{name}/process/<pipeline-flow>
45
+ → the canonical step-by-step flow if CodraGraph detected this as a process
46
+
47
+ 6. Build the lineage diagram: source → transform stages → sink
48
+ ```
49
+
50
+ > CodraGraph is graph-aware, not SQL-aware: it sees a string literal that
51
+ > *looks* like a table name, but doesn't parse SQL semantics. For mature SQL
52
+ > lineage tooling (column-level resolution), pair with `codragraph-sql-tracing`
53
+ > skill and a SQL parser like sqlglot.
54
+
55
+ ## Checklist
56
+
57
+ ```
58
+ - [ ] query for the table/column/file identifier
59
+ - [ ] context on each candidate to map producers vs consumers
60
+ - [ ] impact upstream on the load/sink function
61
+ - [ ] impact downstream on the extract/source function
62
+ - [ ] Cross-reference with processes for canonical pipeline flows
63
+ - [ ] Render the lineage as: source → transform_1 → transform_2 → sink
64
+ ```
65
+
66
+ ## Identifier Patterns to Search
67
+
68
+ | Layer | Search hints |
69
+ | --- | --- |
70
+ | File-based source | filename, path fragments (`raw_events.parquet`) |
71
+ | Database table | bare table name + `FROM table_name` |
72
+ | Column / field | column name in conjunction with the table name |
73
+ | API endpoint | URL path or function name (`fetchUserEvents`) |
74
+ | Event topic / queue | topic name (`user.signup.v2`) |
75
+
76
+ ## Example: "Where does daily_revenue.csv come from?"
77
+
78
+ ```
79
+ 1. codragraph_query({query: "daily_revenue"})
80
+ → 4 symbols:
81
+ - write_daily_revenue (src/etl/daily.py)
82
+ - read_daily_revenue (src/dashboards/finance.py)
83
+ - DailyRevenueRow (src/schemas/types.py)
84
+ - daily_revenue_dag (airflow/dags/finance_etl.py)
85
+
86
+ 2. codragraph_context({name: "write_daily_revenue"})
87
+ → callers: daily_revenue_dag (Airflow task)
88
+ → callees: aggregate_orders, attach_currency_rates, format_csv_row
89
+
90
+ 3. codragraph_impact({target: "aggregate_orders", direction: "upstream"})
91
+ → reads from: orders_raw, returns_raw (both tables)
92
+
93
+ 4. codragraph_impact({target: "read_daily_revenue", direction: "downstream"})
94
+ → consumed by: finance_dashboard.render(), revenue_alerts.check()
95
+
96
+ 5. READ codragraph://repo/CodraGraph/process/DailyRevenueETL
97
+ → 6 steps:
98
+ fetch_orders → fetch_returns → aggregate_orders →
99
+ attach_currency_rates → format_csv_row → write_daily_revenue
100
+
101
+ Lineage:
102
+ orders_raw, returns_raw (DB tables)
103
+
104
+ fetch_orders + fetch_returns (extract)
105
+
106
+ aggregate_orders → attach_currency_rates → format_csv_row (transform)
107
+
108
+ daily_revenue.csv (sink)
109
+
110
+ finance_dashboard, revenue_alerts (consumers)
111
+ ```
112
+
113
+ ## Output Format
114
+
115
+ ```markdown
116
+ ## Data Lineage: <data-asset>
117
+
118
+ ### Sources
119
+ - `orders_raw` (DB)
120
+ - `returns_raw` (DB)
121
+
122
+ ### Pipeline (DailyRevenueETL flow, 6 steps)
123
+ 1. `fetch_orders` — reads `orders_raw`
124
+ 2. `fetch_returns` — reads `returns_raw`
125
+ 3. `aggregate_orders` — joins, sums by day
126
+ 4. `attach_currency_rates` — enriches with FX
127
+ 5. `format_csv_row` — schema-conforming serialization
128
+ 6. `write_daily_revenue` — writes `daily_revenue.csv`
129
+
130
+ ### Consumers
131
+ - `finance_dashboard` (renders chart)
132
+ - `revenue_alerts` (threshold checks)
133
+
134
+ ### Risk if `<schema/source>` changes
135
+ - 6 transform stages depend on it
136
+ - 2 consumers depend on the output schema
137
+ ```
@@ -0,0 +1,119 @@
1
+ ---
2
+ name: codragraph-dead-code
3
+ description: "Use when the user wants to find unused code, orphan functions/classes, dead code, or symbols safe to delete. Examples: \"what's unused\", \"find dead code\", \"can I delete this function\", \"orphan symbols\", \"clean up unused exports\""
4
+ ---
5
+
6
+ # Dead Code Detection with CodraGraph
7
+
8
+ ## When to Use
9
+
10
+ - "What's unused in this codebase?"
11
+ - "Find dead code / orphan functions / unused exports"
12
+ - "Can I safely delete `<symbol>`?"
13
+ - Periodic cleanup before a release
14
+ - Identifying candidates for the next refactor
15
+
16
+ ## Why CodraGraph helps here
17
+
18
+ Linters can find unreachable code in *one file*. CodraGraph walks the
19
+ *whole-repo* call graph, including dynamic dispatch, framework entry
20
+ points, and exports — so it can tell you a symbol is genuinely unreachable
21
+ rather than just "the linter couldn't see the caller."
22
+
23
+ The trick is to combine three signals:
24
+
25
+ 1. **No incoming references** — `cypher` query for symbols with zero
26
+ `<-[:CALLS|REFERENCES]-` edges.
27
+ 2. **Not exported** — internal-only symbols are stronger candidates than
28
+ `isExported = true` ones (which may be public API).
29
+ 3. **Not in any process** — execution flows are the canonical "this is
30
+ used" signal; symbols outside every process are extra suspect.
31
+
32
+ ## Workflow
33
+
34
+ ```
35
+ 1. codragraph_cypher({query: `
36
+ MATCH (n)
37
+ WHERE NOT (n)<-[:CALLS|REFERENCES]-()
38
+ AND NOT (n.isExported = true)
39
+ RETURN n.id, n.name, labels(n)[0] AS label, n.filePath
40
+ LIMIT 200
41
+ `})
42
+ → list of orphan candidates
43
+
44
+ 2. For each candidate:
45
+ codragraph_context({name: "<candidate>"})
46
+ → confirm: 0 callers, 0 callees that matter, not in any process
47
+
48
+ 3. Cross-check against processes:
49
+ READ codragraph://repo/{name}/processes
50
+ → if the symbol appears in ANY process, it's not actually dead
51
+
52
+ 4. For exported orphans (potentially public API):
53
+ codragraph_impact({target: "<symbol>", direction: "upstream"})
54
+ → if d=1 has external callers (in another indexed repo group), keep it
55
+
56
+ 5. Group by file/cluster, prioritize by file size of dead code
57
+ ```
58
+
59
+ > If "Index is stale" → run `npx @codragraph/cli analyze` first. Stale
60
+ > indexes produce false-positive dead-code reports because new callers
61
+ > aren't visible.
62
+
63
+ ## Checklist
64
+
65
+ ```
66
+ - [ ] Cypher query for orphan symbols (no incoming edges, not exported)
67
+ - [ ] context check on each candidate (confirm 0 callers)
68
+ - [ ] Cross-reference with processes (symbols in flows are not dead)
69
+ - [ ] For exported orphans, impact across groups (cross-repo callers?)
70
+ - [ ] Group findings by file → suggest which files can lose the most code
71
+ - [ ] Flag any candidate that's a framework convention (e.g., default export
72
+ of a Next.js page route) — those LOOK orphan but aren't
73
+ ```
74
+
75
+ ## Pitfalls
76
+
77
+ | Pitfall | What to do |
78
+ | --- | --- |
79
+ | Framework conventions (Next.js pages, Astro routes, Django URLs) | Check `isEntryPoint` on the node — these often score high |
80
+ | Test-only symbols | Filter `filePath CONTAINS '/test'` separately |
81
+ | Re-exported symbols | A re-export creates `REFERENCES` edges; a true orphan has none |
82
+ | Dynamic dispatch (factories, plugin systems) | Cross-check with `query` for the registration string |
83
+
84
+ ## Example: "Clean up unused code in src/utils/"
85
+
86
+ ```
87
+ 1. codragraph_cypher({
88
+ query: `MATCH (n) WHERE n.filePath STARTS WITH 'src/utils/'
89
+ AND NOT (n)<-[:CALLS|REFERENCES]-()
90
+ AND NOT (n.isExported = true)
91
+ RETURN n.id, n.name, n.filePath`
92
+ })
93
+ → 7 candidates
94
+
95
+ 2. codragraph_context({name: "formatLegacyDate"})
96
+ → 0 callers, 0 callees, not in any process. Truly dead.
97
+
98
+ 3. codragraph_context({name: "DEBUG_TIMER"})
99
+ → 0 callers but called dynamically via process.env injection.
100
+ → Keep it.
101
+
102
+ 4. Final: 6 of 7 candidates safe to delete. Total: 142 LoC across 4 files.
103
+ ```
104
+
105
+ ## Output Format
106
+
107
+ ```markdown
108
+ ## Dead Code Audit: <scope>
109
+
110
+ ### High-confidence (0 callers, 0 callees, not in any process)
111
+ - `formatLegacyDate` — `src/utils/date.ts:42` (12 LoC)
112
+ - ...
113
+
114
+ ### Possibly dead (verify dynamic dispatch first)
115
+ - `DEBUG_TIMER` — used via env-driven hook?
116
+
117
+ ### Total cleanup potential
118
+ N functions, M LoC, X files.
119
+ ```
@@ -22,7 +22,7 @@ description: "Use when the user is debugging a bug, tracing an error, or asking
22
22
  4. codragraph_cypher({query: "MATCH path..."}) → Custom traces if needed
23
23
  ```
24
24
 
25
- > If "Index is stale" → run `npx codragraph analyze` in terminal.
25
+ > If "Index is stale" → run `npx @codragraph/cli analyze` in terminal.
26
26
 
27
27
  ## Checklist
28
28
 
@@ -23,7 +23,7 @@ description: "Use when the user asks how code works, wants to understand archite
23
23
  5. READ codragraph://repo/{name}/process/{name} → Trace full execution flow
24
24
  ```
25
25
 
26
- > If step 2 says "Index is stale" → run `npx codragraph analyze` in terminal.
26
+ > If step 2 says "Index is stale" → run `npx @codragraph/cli analyze` in terminal.
27
27
 
28
28
  ## Checklist
29
29
 
@@ -0,0 +1,162 @@
1
+ ---
2
+ name: codragraph-gh-actions-debug
3
+ description: "Use when a GitHub Actions workflow fails, needs to be re-run, dispatched manually, or inspected. Covers `gh run` for inspecting/rerunning runs, `gh workflow` for triggering, secrets, and the most common failure modes. Examples: \"why did CI fail\", \"rerun this workflow\", \"dispatch a workflow manually\", \"debug GitHub Action\", \"set GitHub secret\""
4
+ ---
5
+
6
+ # GitHub Actions Debugging with `gh`
7
+
8
+ ## When to Use
9
+
10
+ - "CI failed on my PR — show me why."
11
+ - "Rerun the failed jobs only."
12
+ - "Dispatch a workflow manually with custom inputs."
13
+ - "Add or rotate a secret."
14
+ - "Cancel a hung workflow run."
15
+
16
+ ## Lifecycle commands
17
+
18
+ ### List / inspect runs
19
+
20
+ ```bash
21
+ gh run list # most recent runs
22
+ gh run list --workflow ci.yml # one workflow's runs
23
+ gh run list --branch my-feature --status failure # failed runs on a branch
24
+ gh run list --json conclusion,databaseId,headBranch,name --jq '.[] | select(.conclusion=="failure")'
25
+
26
+ gh run view <run-id> # run summary + jobs
27
+ gh run view <run-id> --log # FULL logs (verbose)
28
+ gh run view <run-id> --log-failed # only the failed steps' logs
29
+ gh run view <run-id> --json jobs --jq '.jobs[] | {name, conclusion}'
30
+ ```
31
+
32
+ If you don't know the run id:
33
+
34
+ ```bash
35
+ # Most recent run on current branch:
36
+ gh run view --branch "$(git branch --show-current)"
37
+
38
+ # Most recent failed run anywhere:
39
+ gh run list --status failure --limit 1 --json databaseId --jq '.[0].databaseId'
40
+ ```
41
+
42
+ ### Re-run
43
+
44
+ ```bash
45
+ gh run rerun <run-id> # rerun the WHOLE run
46
+ gh run rerun <run-id> --failed # only the failed jobs
47
+ gh run rerun <run-id> --job <job-id> # only one specific job
48
+ gh run rerun <run-id> --debug # enable runner debug logging
49
+ ```
50
+
51
+ `--failed` is the right default for "I think the failure was flaky."
52
+
53
+ ### Cancel / delete
54
+
55
+ ```bash
56
+ gh run cancel <run-id> # cancel an in-progress run
57
+ gh run delete <run-id> # remove from history (rare)
58
+ gh run watch <run-id> # tail the run live
59
+ ```
60
+
61
+ ### Manual dispatch (workflow_dispatch)
62
+
63
+ For workflows with `on: workflow_dispatch:`:
64
+
65
+ ```bash
66
+ gh workflow list # which workflows are dispatchable
67
+ gh workflow run <workflow-name-or-id> # run on default branch
68
+ gh workflow run ci.yml --ref my-branch # run on a specific branch
69
+ gh workflow run deploy.yml --field environment=staging --field version=1.7.0
70
+ ```
71
+
72
+ Re-list runs to see the dispatched one:
73
+
74
+ ```bash
75
+ gh run list --workflow ci.yml --limit 5
76
+ ```
77
+
78
+ ### Secrets and variables
79
+
80
+ ```bash
81
+ # Repo-scope secrets:
82
+ gh secret list
83
+ gh secret set ANTHROPIC_API_KEY --body "sk-…"
84
+ gh secret set ANTHROPIC_API_KEY < ~/api-key.txt # from file
85
+ gh secret delete OLD_KEY
86
+
87
+ # Repo-scope variables (non-secret):
88
+ gh variable list
89
+ gh variable set DEPLOY_REGION --body "us-east-1"
90
+
91
+ # Environment-scope (e.g., production):
92
+ gh secret set MY_KEY --env production --body "…"
93
+ ```
94
+
95
+ ## Why CodraGraph helps here
96
+
97
+ When a workflow YAML changes break CI, treat the workflow as code: the
98
+ PR review Action's structural diff doesn't help (Actions aren't TS/Python),
99
+ but two CodraGraph patterns DO help:
100
+
101
+ 1. **Find the symbol the workflow invokes** — many workflows call into
102
+ the codebase (`npm test`, `npx my-cli`, `python scripts/foo.py`).
103
+ Trace what each step actually executes:
104
+
105
+ ```
106
+ codragraph_query({query: "<command the action runs, e.g. 'analyze repo'>"})
107
+ → which CLI handler / script the workflow ends up running
108
+ ```
109
+
110
+ 2. **After a CI break, diff against the last green run's commit** — was
111
+ it a code change or a workflow YAML change?
112
+
113
+ ```
114
+ gh run list --workflow ci.yml --status success --limit 1 --json headSha
115
+ → <last-green-sha>
116
+
117
+ codragraph diff <last-green-sha> HEAD --semantic
118
+ → if structural diff is empty, the break is in YAML / env / runner — not code
119
+ ```
120
+
121
+ ## Failure-mode triage
122
+
123
+ | Symptom | Likely cause | Where to look |
124
+ |---|---|---|
125
+ | `npm install` fails on Linux only | Native deps need apt packages | Add `apt-get install` step or use a different runner |
126
+ | Tests pass locally, fail in CI | Env diff (Node version, locale, timezone) | Compare runner env vs local; add `node-version` matrix |
127
+ | Workflow re-runs with no code change still fail | Flaky test or external service | `gh run rerun --failed --debug` and read the debug logs |
128
+ | Action can't see secret | Secret scope mismatch | `gh secret list` per env / repo / org; secrets don't leak across environments |
129
+ | Pull-request workflow can't write | Default `GITHUB_TOKEN` is read-only on PRs from forks | Switch to `pull_request_target` (with care) or PAT-based action |
130
+
131
+ ## Debugging steps that actually work
132
+
133
+ ```bash
134
+ # 1. Re-run with debug:
135
+ gh run rerun <run-id> --failed --debug
136
+
137
+ # 2. Tail the live run:
138
+ gh run watch <run-id>
139
+
140
+ # 3. Pull only the failed step's logs:
141
+ gh run view <run-id> --log-failed | less
142
+
143
+ # 4. If you need full context, download artifacts:
144
+ gh run download <run-id>
145
+ ls ./
146
+
147
+ # 5. To enable verbose runner logs without re-running, set repo secrets:
148
+ gh secret set ACTIONS_RUNNER_DEBUG --body "true"
149
+ gh secret set ACTIONS_STEP_DEBUG --body "true"
150
+ # (re-run the workflow to pick these up)
151
+ ```
152
+
153
+ ## Pitfalls
154
+
155
+ | Pitfall | Symptom | Fix |
156
+ |---|---|---|
157
+ | `--debug` doesn't show extra logs | Repo doesn't have the debug secrets set | Set `ACTIONS_STEP_DEBUG=true` repo secret |
158
+ | Workflow doesn't appear in dispatch list | Missing `on: workflow_dispatch:` | Add the trigger to the workflow YAML |
159
+ | Inputs to dispatch silently ignored | Type mismatch or missing `inputs:` block | Re-check the workflow YAML's `inputs:` schema |
160
+ | Re-run doesn't pick up your fix | Re-run uses the SAME commit; you need a NEW push for the new code | Push a fix; or use `--debug` if you want runner-level debugging only |
161
+ | Secrets leaked in logs | Used `${{ secrets.X }}` in a `run:` step that echoes | Use env: with secret values; never echo |
162
+ ```