codeforge-dev 1.7.0 → 1.8.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 (136) hide show
  1. package/.devcontainer/.env +4 -6
  2. package/.devcontainer/.env.example +29 -0
  3. package/.devcontainer/.gitignore +8 -0
  4. package/.devcontainer/.secrets.example +12 -0
  5. package/.devcontainer/CHANGELOG.md +130 -0
  6. package/.devcontainer/CLAUDE.md +56 -19
  7. package/.devcontainer/README.md +111 -56
  8. package/.devcontainer/config/{main-system-prompt.md → defaults/main-system-prompt.md} +72 -0
  9. package/.devcontainer/config/file-manifest.json +20 -0
  10. package/.devcontainer/devcontainer.json +20 -0
  11. package/.devcontainer/docs/configuration-reference.md +90 -0
  12. package/.devcontainer/docs/keybindings.md +100 -0
  13. package/.devcontainer/docs/optional-features.md +129 -0
  14. package/.devcontainer/docs/plugins.md +154 -0
  15. package/.devcontainer/docs/troubleshooting.md +128 -0
  16. package/.devcontainer/features/agent-browser/install.sh +6 -0
  17. package/.devcontainer/features/ast-grep/install.sh +6 -0
  18. package/.devcontainer/features/biome/README.md +27 -0
  19. package/.devcontainer/features/biome/install.sh +6 -0
  20. package/.devcontainer/features/ccburn/install.sh +6 -0
  21. package/.devcontainer/features/ccstatusline/devcontainer-feature.json +5 -0
  22. package/.devcontainer/features/ccstatusline/install.sh +7 -0
  23. package/.devcontainer/features/ccusage/install.sh +6 -0
  24. package/.devcontainer/features/claude-monitor/install.sh +6 -0
  25. package/.devcontainer/features/dprint/README.md +30 -0
  26. package/.devcontainer/features/dprint/devcontainer-feature.json +18 -0
  27. package/.devcontainer/features/dprint/install.sh +131 -0
  28. package/.devcontainer/features/hadolint/README.md +35 -0
  29. package/.devcontainer/features/hadolint/devcontainer-feature.json +13 -0
  30. package/.devcontainer/features/hadolint/install.sh +86 -0
  31. package/.devcontainer/features/lsp-servers/devcontainer-feature.json +5 -0
  32. package/.devcontainer/features/lsp-servers/install.sh +7 -0
  33. package/.devcontainer/features/mcp-qdrant/devcontainer-feature.json +5 -0
  34. package/.devcontainer/features/mcp-qdrant/install.sh +13 -6
  35. package/.devcontainer/features/mcp-reasoner/devcontainer-feature.json +5 -0
  36. package/.devcontainer/features/mcp-reasoner/install.sh +8 -1
  37. package/.devcontainer/features/notify-hook/devcontainer-feature.json +5 -0
  38. package/.devcontainer/features/notify-hook/install.sh +7 -0
  39. package/.devcontainer/features/ruff/README.md +26 -0
  40. package/.devcontainer/features/ruff/devcontainer-feature.json +21 -0
  41. package/.devcontainer/features/ruff/install.sh +74 -0
  42. package/.devcontainer/features/shellcheck/README.md +38 -0
  43. package/.devcontainer/features/shellcheck/devcontainer-feature.json +13 -0
  44. package/.devcontainer/features/shellcheck/install.sh +24 -0
  45. package/.devcontainer/features/shfmt/README.md +37 -0
  46. package/.devcontainer/features/shfmt/devcontainer-feature.json +13 -0
  47. package/.devcontainer/features/shfmt/install.sh +85 -0
  48. package/.devcontainer/features/splitrail/devcontainer-feature.json +5 -0
  49. package/.devcontainer/features/splitrail/install.sh +7 -0
  50. package/.devcontainer/features/tmux/install.sh +8 -0
  51. package/.devcontainer/features/tree-sitter/install.sh +6 -0
  52. package/.devcontainer/plugins/devs-marketplace/.claude-plugin/marketplace.json +3 -10
  53. package/.devcontainer/plugins/devs-marketplace/plugins/auto-formatter/.claude-plugin/plugin.json +1 -1
  54. package/.devcontainer/plugins/devs-marketplace/plugins/auto-formatter/scripts/__pycache__/format-on-stop.cpython-314.pyc +0 -0
  55. package/.devcontainer/plugins/devs-marketplace/plugins/auto-formatter/scripts/format-on-stop.py +114 -9
  56. package/.devcontainer/plugins/devs-marketplace/plugins/auto-linter/.claude-plugin/plugin.json +1 -1
  57. package/.devcontainer/plugins/devs-marketplace/plugins/auto-linter/hooks/hooks.json +4 -5
  58. package/.devcontainer/plugins/devs-marketplace/plugins/auto-linter/scripts/__pycache__/lint-file.cpython-314.pyc +0 -0
  59. package/.devcontainer/plugins/devs-marketplace/plugins/auto-linter/scripts/lint-file.py +478 -76
  60. package/.devcontainer/plugins/devs-marketplace/plugins/code-directive/.claude-plugin/plugin.json +1 -1
  61. package/.devcontainer/plugins/devs-marketplace/plugins/code-directive/AGENT-REDIRECTION.md +226 -0
  62. package/.devcontainer/plugins/devs-marketplace/plugins/code-directive/agents/architect.md +17 -0
  63. package/.devcontainer/plugins/devs-marketplace/plugins/code-directive/agents/bash-exec.md +4 -4
  64. package/.devcontainer/plugins/devs-marketplace/plugins/code-directive/agents/claude-guide.md +14 -23
  65. package/.devcontainer/plugins/devs-marketplace/plugins/code-directive/agents/debug-logs.md +2 -0
  66. package/.devcontainer/plugins/devs-marketplace/plugins/code-directive/agents/dependency-analyst.md +2 -0
  67. package/.devcontainer/plugins/devs-marketplace/plugins/code-directive/agents/doc-writer.md +13 -0
  68. package/.devcontainer/plugins/devs-marketplace/plugins/code-directive/agents/explorer.md +2 -0
  69. package/.devcontainer/plugins/devs-marketplace/plugins/code-directive/agents/generalist.md +10 -1
  70. package/.devcontainer/plugins/devs-marketplace/plugins/code-directive/agents/migrator.md +6 -0
  71. package/.devcontainer/plugins/devs-marketplace/plugins/code-directive/agents/refactorer.md +4 -0
  72. package/.devcontainer/plugins/devs-marketplace/plugins/code-directive/agents/spec-writer.md +36 -23
  73. package/.devcontainer/plugins/devs-marketplace/plugins/code-directive/agents/statusline-config.md +3 -3
  74. package/.devcontainer/plugins/devs-marketplace/plugins/code-directive/agents/test-writer.md +3 -0
  75. package/.devcontainer/plugins/devs-marketplace/plugins/code-directive/hooks/hooks.json +39 -0
  76. package/.devcontainer/plugins/devs-marketplace/plugins/code-directive/scripts/__pycache__/advisory-test-runner.cpython-314.pyc +0 -0
  77. package/.devcontainer/plugins/devs-marketplace/plugins/code-directive/scripts/__pycache__/collect-edited-files.cpython-314.pyc +0 -0
  78. package/.devcontainer/plugins/devs-marketplace/plugins/code-directive/scripts/__pycache__/commit-reminder.cpython-314.pyc +0 -0
  79. package/.devcontainer/plugins/devs-marketplace/plugins/code-directive/scripts/__pycache__/git-state-injector.cpython-314.pyc +0 -0
  80. package/.devcontainer/plugins/devs-marketplace/plugins/code-directive/scripts/__pycache__/redirect-builtin-agents.cpython-314.pyc +0 -0
  81. package/.devcontainer/plugins/devs-marketplace/plugins/code-directive/scripts/__pycache__/ticket-linker.cpython-314.pyc +0 -0
  82. package/.devcontainer/plugins/devs-marketplace/plugins/code-directive/scripts/__pycache__/todo-harvester.cpython-314.pyc +0 -0
  83. package/.devcontainer/plugins/devs-marketplace/plugins/code-directive/scripts/advisory-test-runner.py +174 -0
  84. package/.devcontainer/plugins/devs-marketplace/plugins/code-directive/scripts/collect-edited-files.py +8 -6
  85. package/.devcontainer/plugins/devs-marketplace/plugins/code-directive/scripts/commit-reminder.py +90 -0
  86. package/.devcontainer/plugins/devs-marketplace/plugins/code-directive/scripts/git-state-injector.py +114 -0
  87. package/.devcontainer/plugins/devs-marketplace/plugins/code-directive/scripts/skill-suggester.py +61 -0
  88. package/.devcontainer/plugins/devs-marketplace/plugins/code-directive/scripts/ticket-linker.py +137 -0
  89. package/.devcontainer/plugins/devs-marketplace/plugins/code-directive/scripts/todo-harvester.py +130 -0
  90. package/.devcontainer/plugins/devs-marketplace/plugins/code-directive/skills/api-design/SKILL.md +224 -0
  91. package/.devcontainer/plugins/devs-marketplace/plugins/code-directive/skills/api-design/references/error-handling.md +166 -0
  92. package/.devcontainer/plugins/devs-marketplace/plugins/code-directive/skills/api-design/references/rest-conventions.md +215 -0
  93. package/.devcontainer/plugins/devs-marketplace/plugins/code-directive/skills/ast-grep-patterns/SKILL.md +211 -0
  94. package/.devcontainer/plugins/devs-marketplace/plugins/code-directive/skills/ast-grep-patterns/references/language-patterns.md +327 -0
  95. package/.devcontainer/plugins/devs-marketplace/plugins/code-directive/skills/dependency-management/SKILL.md +134 -0
  96. package/.devcontainer/plugins/devs-marketplace/plugins/code-directive/skills/dependency-management/references/ecosystem-commands.md +264 -0
  97. package/.devcontainer/plugins/devs-marketplace/plugins/code-directive/skills/dependency-management/references/license-compliance.md +80 -0
  98. package/.devcontainer/plugins/devs-marketplace/plugins/code-directive/skills/documentation-patterns/SKILL.md +153 -0
  99. package/.devcontainer/plugins/devs-marketplace/plugins/code-directive/skills/documentation-patterns/references/api-doc-templates.md +221 -0
  100. package/.devcontainer/plugins/devs-marketplace/plugins/code-directive/skills/documentation-patterns/references/docstring-formats.md +296 -0
  101. package/.devcontainer/plugins/devs-marketplace/plugins/code-directive/skills/migration-patterns/SKILL.md +150 -0
  102. package/.devcontainer/plugins/devs-marketplace/plugins/code-directive/skills/migration-patterns/references/javascript-migrations.md +179 -0
  103. package/.devcontainer/plugins/devs-marketplace/plugins/code-directive/skills/migration-patterns/references/python-migrations.md +141 -0
  104. package/.devcontainer/plugins/devs-marketplace/plugins/code-directive/skills/specification-writing/SKILL.md +32 -0
  105. package/.devcontainer/plugins/devs-marketplace/plugins/dangerous-command-blocker/scripts/__pycache__/block-dangerous.cpython-314.pyc +0 -0
  106. package/.devcontainer/plugins/devs-marketplace/plugins/notify-hook/hooks/hooks.json +1 -1
  107. package/.devcontainer/plugins/devs-marketplace/plugins/protected-files-guard/scripts/__pycache__/guard-protected.cpython-314.pyc +0 -0
  108. package/.devcontainer/scripts/check-setup.sh +72 -0
  109. package/.devcontainer/scripts/setup-aliases.sh +43 -3
  110. package/.devcontainer/scripts/setup-auth.sh +74 -0
  111. package/.devcontainer/scripts/setup-config.sh +112 -22
  112. package/.devcontainer/scripts/setup-update-claude.sh +8 -0
  113. package/.devcontainer/scripts/setup.sh +46 -13
  114. package/README.md +23 -190
  115. package/package.json +1 -1
  116. package/setup.js +245 -71
  117. package/.devcontainer/features/claude-code/README.md +0 -498
  118. package/.devcontainer/features/claude-code/config/settings.json +0 -72
  119. package/.devcontainer/features/claude-code/config/system-prompt.md +0 -118
  120. package/.devcontainer/features/claude-code/config/world-building-sp.md +0 -1432
  121. package/.devcontainer/features/claude-code/devcontainer-feature.json +0 -42
  122. package/.devcontainer/features/claude-code/install.sh +0 -466
  123. package/.devcontainer/plugins/devs-marketplace/plugins/planning-reminder/.claude-plugin/plugin.json +0 -7
  124. package/.devcontainer/plugins/devs-marketplace/plugins/planning-reminder/hooks/hooks.json +0 -17
  125. package/.devcontainer/plugins/devs-marketplace/plugins/workflow-enhancer/.claude-plugin/plugin.json +0 -6
  126. package/.devcontainer/plugins/devs-marketplace/plugins/workflow-enhancer/config/planning-instructions.md +0 -14
  127. package/.devcontainer/plugins/devs-marketplace/plugins/workflow-enhancer/functional-conjuring-map.md +0 -989
  128. package/.devcontainer/plugins/devs-marketplace/plugins/workflow-enhancer/hooks/hooks.json +0 -33
  129. package/.devcontainer/plugins/devs-marketplace/plugins/workflow-enhancer/scripts/__pycache__/post-enhance-task.cpython-314.pyc +0 -0
  130. package/.devcontainer/plugins/devs-marketplace/plugins/workflow-enhancer/scripts/enhance-planning.py +0 -71
  131. package/.devcontainer/plugins/devs-marketplace/plugins/workflow-enhancer/scripts/enhancers/enhance-plan.sh +0 -68
  132. package/.devcontainer/plugins/devs-marketplace/plugins/workflow-enhancer/scripts/enhancers/enhance-task.sh +0 -120
  133. package/.devcontainer/plugins/devs-marketplace/plugins/workflow-enhancer/scripts/post-enhance-plan.py +0 -133
  134. package/.devcontainer/plugins/devs-marketplace/plugins/workflow-enhancer/scripts/post-enhance-task.py +0 -253
  135. /package/.devcontainer/config/{keybindings.json → defaults/keybindings.json} +0 -0
  136. /package/.devcontainer/config/{settings.json → defaults/settings.json} +0 -0
@@ -0,0 +1,215 @@
1
+ # REST Conventions Reference
2
+
3
+ ## HTTP Method Semantics
4
+
5
+ ### GET — Read Resources
6
+
7
+ - Retrieves a resource or collection. Never modifies state.
8
+ - **Cacheable** by default. Use `Cache-Control` and `ETag` headers.
9
+ - Collection: `GET /users` → `200 OK` with array
10
+ - Single: `GET /users/123` → `200 OK` with object, or `404 Not Found`
11
+
12
+ ### POST — Create Resources
13
+
14
+ - Creates a new resource. The server assigns the ID.
15
+ - **Not idempotent** — repeating the request creates duplicate resources.
16
+ - Response: `201 Created` with `Location` header pointing to the new resource.
17
+ - Include the created resource in the response body.
18
+
19
+ ### PUT — Full Replace
20
+
21
+ - Replaces the entire resource. Client sends the complete representation.
22
+ - **Idempotent** — repeating the request produces the same state.
23
+ - If the resource doesn't exist: return `404` (don't auto-create unless designed for upsert).
24
+ - Response: `200 OK` with the updated resource.
25
+
26
+ ### PATCH — Partial Update
27
+
28
+ - Modifies specific fields without replacing the entire resource.
29
+ - Use JSON Merge Patch (`Content-Type: application/merge-patch+json`) for simplicity.
30
+ - Response: `200 OK` with the complete updated resource.
31
+ - Omitted fields remain unchanged.
32
+
33
+ ### DELETE — Remove Resources
34
+
35
+ - Removes a resource.
36
+ - **Idempotent** — deleting an already-deleted resource returns `204` or `404` (both are valid, be consistent).
37
+ - Response: `204 No Content` (no body).
38
+
39
+ ### HEAD — Headers Only
40
+
41
+ - Identical to GET but returns no body. Used for checking existence, content length, or cache validity.
42
+
43
+ ### OPTIONS — Capabilities
44
+
45
+ - Returns allowed methods and CORS headers. Response: `204 No Content` with `Allow` header.
46
+
47
+ ---
48
+
49
+ ## Status Code Reference
50
+
51
+ ### 2xx — Success
52
+
53
+ | Code | Name | When to Use |
54
+ |------|------|------------|
55
+ | `200` | OK | GET, PUT, PATCH succeeded. General success. |
56
+ | `201` | Created | POST created a resource. Include `Location` header. |
57
+ | `202` | Accepted | Request accepted for async processing. Include status URL. |
58
+ | `204` | No Content | DELETE succeeded. OPTIONS response. No body. |
59
+
60
+ ### 3xx — Redirection
61
+
62
+ | Code | Name | When to Use |
63
+ |------|------|------------|
64
+ | `301` | Moved Permanently | Resource URL changed permanently. Clients should update. |
65
+ | `302` | Found | Temporary redirect. Original URL still valid. |
66
+ | `304` | Not Modified | Cache is still valid. Response to conditional GET. |
67
+
68
+ ### 4xx — Client Errors
69
+
70
+ | Code | Name | When to Use |
71
+ |------|------|------------|
72
+ | `400` | Bad Request | Malformed syntax, invalid JSON, missing required fields. |
73
+ | `401` | Unauthorized | No credentials or invalid/expired credentials. |
74
+ | `403` | Forbidden | Valid credentials but insufficient permissions. |
75
+ | `404` | Not Found | Resource doesn't exist. |
76
+ | `405` | Method Not Allowed | HTTP method not supported for this URL. Include `Allow` header. |
77
+ | `409` | Conflict | State conflict (duplicate, version mismatch, concurrent modification). |
78
+ | `410` | Gone | Resource existed but was permanently deleted. |
79
+ | `415` | Unsupported Media Type | Content-Type not supported. |
80
+ | `422` | Unprocessable Entity | Valid syntax but semantic errors (validation failures). |
81
+ | `429` | Too Many Requests | Rate limit exceeded. Include `Retry-After` header. |
82
+
83
+ ### 5xx — Server Errors
84
+
85
+ | Code | Name | When to Use |
86
+ |------|------|------------|
87
+ | `500` | Internal Server Error | Unhandled exception. Log the error, return generic message. |
88
+ | `502` | Bad Gateway | Upstream service returned invalid response. |
89
+ | `503` | Service Unavailable | Server overloaded or in maintenance. Include `Retry-After`. |
90
+ | `504` | Gateway Timeout | Upstream service did not respond in time. |
91
+
92
+ ---
93
+
94
+ ## Resource Naming Conventions
95
+
96
+ ### Collection Patterns
97
+
98
+ ```
99
+ /users → User collection
100
+ /users/{id} → Specific user
101
+ /users/{id}/orders → Orders belonging to a user
102
+ /users/{id}/orders/{oid} → Specific order of a user
103
+ ```
104
+
105
+ ### Naming Rules
106
+
107
+ - **Plural nouns** for collections: `/users`, not `/user`
108
+ - **Lowercase with hyphens** for multi-word: `/order-items`, not `/orderItems` or `/order_items`
109
+ - **No trailing slashes**: `/users`, not `/users/`
110
+ - **No file extensions**: `/users/123`, not `/users/123.json`
111
+ - **No verbs**: `/users/{id}/activate` is acceptable as an action endpoint (RPC-style), but prefer state changes via PATCH when possible
112
+
113
+ ### Action Endpoints (RPC-Style)
114
+
115
+ When a RESTful mapping is awkward, use action sub-resources:
116
+
117
+ ```
118
+ POST /users/{id}/activate → Activate a user
119
+ POST /orders/{id}/cancel → Cancel an order
120
+ POST /emails/{id}/resend → Resend an email
121
+ ```
122
+
123
+ Action endpoints are always POST (they change state and are not idempotent).
124
+
125
+ ---
126
+
127
+ ## Query Parameter Patterns
128
+
129
+ ### Filtering
130
+
131
+ ```
132
+ GET /users?status=active
133
+ GET /users?role=admin&status=active
134
+ GET /orders?created_after=2024-01-01&created_before=2024-12-31
135
+ ```
136
+
137
+ Use `snake_case` for parameter names. Support multiple values with comma separation or repeated params:
138
+ ```
139
+ GET /users?role=admin,editor (comma-separated)
140
+ GET /users?role=admin&role=editor (repeated)
141
+ ```
142
+
143
+ ### Sorting
144
+
145
+ ```
146
+ GET /users?sort_by=created_at&sort_order=desc
147
+ GET /users?sort=-created_at,name (prefix - for descending)
148
+ ```
149
+
150
+ ### Field Selection
151
+
152
+ ```
153
+ GET /users?fields=id,name,email
154
+ GET /users/{id}?fields=id,name,email,orders
155
+ ```
156
+
157
+ Reduces payload size. Particularly valuable for mobile clients or list views.
158
+
159
+ ### Search
160
+
161
+ ```
162
+ GET /users?q=john (full-text search)
163
+ GET /users?name_contains=john (field-specific search)
164
+ ```
165
+
166
+ ---
167
+
168
+ ## Content Negotiation
169
+
170
+ ### Request Headers
171
+
172
+ ```
173
+ Content-Type: application/json → Request body format
174
+ Accept: application/json → Desired response format
175
+ Accept-Language: en-US → Preferred language
176
+ ```
177
+
178
+ ### Response Headers
179
+
180
+ ```
181
+ Content-Type: application/json; charset=utf-8
182
+ Content-Length: 1234
183
+ ETag: "abc123"
184
+ Cache-Control: max-age=3600
185
+ ```
186
+
187
+ ### Versioned Media Types
188
+
189
+ ```
190
+ Accept: application/vnd.myapi.v2+json
191
+ ```
192
+
193
+ An alternative to URL path versioning. The server reads the Accept header to determine which version to serve.
194
+
195
+ ---
196
+
197
+ ## HATEOAS (Hypermedia)
198
+
199
+ Include links to related resources and actions in responses:
200
+
201
+ ```json
202
+ {
203
+ "id": 123,
204
+ "name": "Jane Doe",
205
+ "links": {
206
+ "self": "/users/123",
207
+ "orders": "/users/123/orders",
208
+ "activate": "/users/123/activate"
209
+ }
210
+ }
211
+ ```
212
+
213
+ **When it is worth it**: Public APIs consumed by many third-party clients. The links enable discoverability without hardcoding URL patterns.
214
+
215
+ **When it is over-engineering**: Internal APIs where clients are maintained by the same team. The added payload and complexity rarely justify the benefit.
@@ -0,0 +1,211 @@
1
+ ---
2
+ name: ast-grep-patterns
3
+ description: >-
4
+ This skill should be used when the user asks to "use ast-grep",
5
+ "structural search", "syntax-aware search", "find code patterns",
6
+ "search with ast-grep", "use tree-sitter", "find function calls structurally",
7
+ or discusses ast-grep patterns, structural code search, meta-variables,
8
+ tree-sitter parsing, or syntax-aware code matching.
9
+ version: 0.1.0
10
+ ---
11
+
12
+ # AST-Grep Patterns
13
+
14
+ ## Mental Model
15
+
16
+ Text search finds **strings**. Structural search finds **code constructs**. When you need to find all calls to `fetch()` regardless of arguments, a regex like `fetch\(.*\)` matches strings inside comments, string literals, and variable names containing "fetch." ast-grep matches the actual function call in the syntax tree.
17
+
18
+ **When to use which tool:**
19
+
20
+ | Need | Tool | Why |
21
+ |------|------|-----|
22
+ | Simple text or identifier | `Grep` | Fastest for literal text matching |
23
+ | Code pattern with variable parts | `ast-grep` (`sg`) | Understands syntax, ignores comments/strings |
24
+ | Full parse tree or all symbols | `tree-sitter` | Deepest structural insight per file |
25
+ | File names by pattern | `Glob` | Path-based discovery |
26
+
27
+ **Default to Grep** for simple searches. Escalate to ast-grep when:
28
+ - The pattern has variable sub-expressions (any arguments, any name)
29
+ - You need to distinguish code from comments/strings
30
+ - The pattern spans multiple syntax elements (function with decorator, class with method)
31
+
32
+ ---
33
+
34
+ ## Meta-Variable Reference
35
+
36
+ ast-grep uses meta-variables to match parts of the syntax tree:
37
+
38
+ | Syntax | Meaning | Example |
39
+ |--------|---------|---------|
40
+ | `$NAME` | Matches exactly one AST node | `console.log($MSG)` matches `console.log("hi")` |
41
+ | `$$$ARGS` | Matches zero or more nodes (variadic) | `func($$$ARGS)` matches `func()`, `func(a)`, `func(a, b, c)` |
42
+ | `$_` | Wildcard — matches one node, not captured | `if ($_ ) { $$$BODY }` matches any if-statement |
43
+
44
+ **Key distinctions:**
45
+ - `$X` captures and can be referenced — use when you care about what matched
46
+ - `$_` is a throwaway — use when you just need "something here"
47
+ - `$$$X` is greedy — it captures everything between fixed anchors
48
+
49
+ ---
50
+
51
+ ## Tool Invocation
52
+
53
+ ### ast-grep (`sg`)
54
+
55
+ ```bash
56
+ # Basic pattern search
57
+ sg run -p 'PATTERN' -l LANGUAGE
58
+
59
+ # Search in specific directory
60
+ sg run -p 'PATTERN' -l LANGUAGE path/to/dir/
61
+
62
+ # With JSON output for parsing
63
+ sg run -p 'PATTERN' -l LANGUAGE --json
64
+ ```
65
+
66
+ **Language identifiers**: `python`, `javascript`, `typescript`, `go`, `rust`, `java`, `c`, `cpp`, `css`, `html`
67
+
68
+ ### tree-sitter
69
+
70
+ ```bash
71
+ # Extract all definitions (functions, classes, methods)
72
+ tree-sitter tags /path/to/file.py
73
+
74
+ # Parse file and show syntax tree
75
+ tree-sitter parse /path/to/file.py
76
+
77
+ # Parse and show tree for specific language
78
+ tree-sitter parse --language python /path/to/file.py
79
+ ```
80
+
81
+ ---
82
+
83
+ ## Common Cross-Language Patterns
84
+
85
+ ### Function Calls
86
+
87
+ ```bash
88
+ # Any call to a specific function
89
+ sg run -p 'fetch($$$ARGS)' -l javascript
90
+
91
+ # Method call on any object
92
+ sg run -p '$OBJ.save($$$ARGS)' -l python
93
+
94
+ # Chained method calls
95
+ sg run -p '$OBJ.filter($$$A).map($$$B)' -l javascript
96
+ ```
97
+
98
+ ### Function/Method Definitions
99
+
100
+ ```bash
101
+ # Python function
102
+ sg run -p 'def $NAME($$$PARAMS): $$$BODY' -l python
103
+
104
+ # Async Python function
105
+ sg run -p 'async def $NAME($$$PARAMS): $$$BODY' -l python
106
+
107
+ # JavaScript/TypeScript function
108
+ sg run -p 'function $NAME($$$PARAMS) { $$$BODY }' -l javascript
109
+
110
+ # Arrow function assigned to variable
111
+ sg run -p 'const $NAME = ($$$PARAMS) => $$$BODY' -l javascript
112
+ ```
113
+
114
+ ### Import Statements
115
+
116
+ ```bash
117
+ # Python imports
118
+ sg run -p 'from $MODULE import $$$NAMES' -l python
119
+ sg run -p 'import $MODULE' -l python
120
+
121
+ # JavaScript/TypeScript imports
122
+ sg run -p 'import $$$NAMES from "$MODULE"' -l javascript
123
+ sg run -p 'import { $$$NAMES } from "$MODULE"' -l typescript
124
+ ```
125
+
126
+ ### Class Definitions
127
+
128
+ ```bash
129
+ # Python class
130
+ sg run -p 'class $NAME($$$BASES): $$$BODY' -l python
131
+
132
+ # TypeScript class
133
+ sg run -p 'class $NAME { $$$BODY }' -l typescript
134
+
135
+ # Class with extends
136
+ sg run -p 'class $NAME extends $BASE { $$$BODY }' -l typescript
137
+ ```
138
+
139
+ ### Error Handling
140
+
141
+ ```bash
142
+ # Python try/except
143
+ sg run -p 'try: $$$TRY except $EXCEPTION: $$$EXCEPT' -l python
144
+
145
+ # JavaScript try/catch
146
+ sg run -p 'try { $$$TRY } catch ($ERR) { $$$CATCH }' -l javascript
147
+ ```
148
+
149
+ ### Decorators / Attributes
150
+
151
+ ```bash
152
+ # Python decorator
153
+ sg run -p '@$DECORATOR def $NAME($$$PARAMS): $$$BODY' -l python
154
+
155
+ # Specific decorator
156
+ sg run -p '@app.route($$$ARGS) def $NAME($$$PARAMS): $$$BODY' -l python
157
+
158
+ # TypeScript decorator
159
+ sg run -p '@$DECORATOR class $NAME { $$$BODY }' -l typescript
160
+ ```
161
+
162
+ ---
163
+
164
+ ## Combining Tools
165
+
166
+ Use ast-grep for structural finding, then Grep and Read for context:
167
+
168
+ 1. **Find structurally**: `sg run -p 'pattern' -l lang` → get file paths and line numbers
169
+ 2. **Filter textually**: Use `Grep` on the results to narrow by specific strings
170
+ 3. **Read context**: Use `Read` to examine surrounding code for the matches
171
+
172
+ Example workflow — find all Express route handlers that don't have error handling:
173
+
174
+ ```bash
175
+ # Step 1: Find all route handlers
176
+ sg run -p 'app.$METHOD($PATH, $$$HANDLERS)' -l javascript
177
+
178
+ # Step 2: Check which handlers lack try/catch (use Grep on matched files)
179
+ # Grep for the handler function names, then check for try/catch blocks
180
+
181
+ # Step 3: Read the full handler to confirm
182
+ ```
183
+
184
+ ---
185
+
186
+ ## tree-sitter Integration
187
+
188
+ Use `tree-sitter` when you need the full syntax tree, not just pattern matches:
189
+
190
+ - **`tree-sitter tags`** — Extracts all definitions (functions, classes, methods, variables) from a file. Use for getting a file's API surface quickly.
191
+ - **`tree-sitter parse`** — Shows the complete syntax tree. Use for debugging ast-grep patterns that don't match as expected, or for understanding unfamiliar syntax.
192
+
193
+ ---
194
+
195
+ ## Ambiguity Policy
196
+
197
+ | Ambiguity | Default |
198
+ |-----------|---------|
199
+ | **Search tool not specified** | Use Grep for simple text; ast-grep for structural patterns |
200
+ | **Language not specified** | Infer from file extensions in the search directory |
201
+ | **Pattern too broad** | Narrow by directory first, then refine the pattern |
202
+ | **No results from ast-grep** | Fall back to Grep — the pattern may not match the exact syntax tree structure |
203
+ | **Complex nested pattern** | Break into simpler patterns and combine results |
204
+
205
+ ---
206
+
207
+ ## Reference Files
208
+
209
+ | File | Contents |
210
+ |------|----------|
211
+ | [Language Patterns](references/language-patterns.md) | Complete pattern catalog for Python, TypeScript/JavaScript, Go, and Rust — function calls, class definitions, imports, async patterns, and more with exact `sg` commands |