You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Support bootstrap scripts in rule frontmatter (preferred over file-based) (#207)
* Initial plan
* Add support for bootstrap in frontmatter (preferred over file-based)
Co-authored-by: alexec <1142830+alexec@users.noreply.github.com>
* Update documentation for frontmatter bootstrap support
Co-authored-by: alexec <1142830+alexec@users.noreply.github.com>
* Address PR feedback: save bootstrap to temp file, improve error messages and tests
Co-authored-by: alexec <1142830+alexec@users.noreply.github.com>
* Update bootstrap examples to use shebang with space and set -eux
Co-authored-by: alexec <1142830+alexec@users.noreply.github.com>
* Add shebang and set -eux to remaining bootstrap examples
Co-authored-by: alexec <1142830+alexec@users.noreply.github.com>
---------
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: alexec <1142830+alexec@users.noreply.github.com>
Issue details are fetched by the bootstrap script.
175
+
```
176
+
177
+
Use with:
178
+
```bash
179
+
export JIRA_ISSUE_KEY="PROJ-123"
180
+
export JIRA_API_TOKEN="your-token"
181
+
182
+
coding-context -s source=jira fix-bug
183
+
```
184
+
185
+
**Note:** The bootstrap script is saved to a temporary file and executed. Include a shebang line (`#!/bin/sh` or `#!/bin/bash`) to specify the interpreter.
186
+
187
+
### File-Based Bootstrap (Legacy)
188
+
189
+
Alternatively, create a separate executable file named `<rule-name>-bootstrap`:
This is useful when rules contain template syntax that should be preserved for the AI agent to process.
826
826
827
+
#### `bootstrap` (optional)
828
+
829
+
**Type:** String (multiline)
830
+
**Purpose:** Shell script to execute before the rule is included. This is the **preferred method** for defining bootstrap scripts.
831
+
832
+
The bootstrap script runs via `sh -c`, with output sent to stderr (not included in the AI context). This allows rules to fetch dynamic data, set up environment, or prepare context before the rule content is processed.
833
+
834
+
**Example:**
835
+
```yaml
836
+
---
837
+
languages:
838
+
- go
839
+
bootstrap: |
840
+
#! /bin/sh
841
+
set -eux
842
+
echo "Fetching project dependencies..." >&2
843
+
go list -m all > /tmp/go-deps.txt
844
+
echo "Dependencies cached" >&2
845
+
---
846
+
847
+
# Go Dependency Context
848
+
849
+
Dependencies are listed in /tmp/go-deps.txt
850
+
```
851
+
852
+
**Multiple commands:**
853
+
```yaml
854
+
---
855
+
bootstrap: |
856
+
#! /bin/sh
857
+
set -eux
858
+
859
+
echo "Setting up environment..." >&2
860
+
861
+
if [ -z "$API_KEY" ]; then
862
+
echo "Warning: API_KEY not set" >&2
863
+
exit 0
864
+
fi
865
+
866
+
echo "Fetching data..." >&2
867
+
curl -s -H "Authorization: Bearer $API_KEY" \
868
+
"https://api.example.com/data" > /tmp/data.json
869
+
870
+
echo "Setup complete" >&2
871
+
---
872
+
```
873
+
874
+
**Usage:**
875
+
```bash
876
+
export API_KEY="your-api-key"
877
+
coding-context implement-feature
878
+
```
879
+
880
+
**Notes:**
881
+
- The bootstrap script is saved to a temporary executable file and run directly
882
+
- Use `#!/bin/sh` (POSIX shell) or `#!/bin/bash` (bash) as the first line to select the interpreter
883
+
- Output goes to stderr, not the assembled context
884
+
- If both frontmatter `bootstrap:` and file-based bootstrap exist, frontmatter takes precedence
885
+
- Environment variables from the parent process are available
886
+
- Exit code 0 is required for successful execution
887
+
888
+
**See also:**[Bootstrap Scripts](#bootstrap-scripts) for file-based alternative
889
+
827
890
**Other common fields:**
828
891
```yaml
829
892
---
@@ -833,6 +896,10 @@ stage: implementation
833
896
priority: high
834
897
team: backend
835
898
agent: cursor
899
+
bootstrap: |
900
+
#! /bin/sh
901
+
set -eux
902
+
echo "Running setup..." >&2
836
903
---
837
904
```
838
905
@@ -849,23 +916,54 @@ Rules are discovered in many locations. See [Search Paths Reference](./search-pa
849
916
850
917
## Bootstrap Scripts
851
918
852
-
Bootstrap scripts are executable files that run before their associated rule file is processed.
919
+
Bootstrap scripts run before their associated rule file is processed. There are two ways to define bootstrap scripts:
920
+
921
+
### Frontmatter Bootstrap (Preferred)
922
+
923
+
Define the bootstrap script directly in the rule's frontmatter using the `bootstrap:` field. This is the **preferred method** because:
0 commit comments