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
Copy file name to clipboardExpand all lines: .github/instructions/ai.instructions.md
+21-5Lines changed: 21 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,11 +2,26 @@
2
2
applyTo: adapters/ai/**/*.sh
3
3
---
4
4
5
-
# AI Instructions
5
+
# AI Adapter Instructions
6
6
7
-
## Adding Features
7
+
## When to Use a File vs Registry
8
8
9
-
### New AI Tool Adapter (`adapters/ai/<name>.sh`)
9
+
Most AI tools are defined as **registry entries** in `lib/adapters.sh` — no adapter file needed.
10
+
Only create an adapter file in `adapters/ai/` for tools that need **custom behavior** beyond the standard builder (see `claude.sh` or `cursor.sh` for examples).
11
+
12
+
## Adding a Standard AI Tool (Registry)
13
+
14
+
Add a line to `_AI_REGISTRY` in `lib/adapters.sh`:
15
+
16
+
```
17
+
yourname|yourcmd|ToolName not found. Install with: ...|Extra info;More info
18
+
```
19
+
20
+
Format: `name|cmd|err_msg|info_lines` (info lines are semicolon-separated)
21
+
22
+
## Adding a Custom AI Tool (File Override)
23
+
24
+
Create `adapters/ai/<name>.sh` implementing:
10
25
11
26
```bash
12
27
#!/usr/bin/env bash
@@ -27,7 +42,9 @@ ai_start() {
27
42
}
28
43
```
29
44
30
-
**Also update**: Same as editor adapters (README, completions, help text)
45
+
File-based adapters take precedence over registry entries of the same name.
46
+
47
+
**Also update**: README, completions (bash/zsh/fish), help text in `lib/commands/help.sh`
31
48
32
49
## Contract & Guidelines
33
50
@@ -38,5 +55,4 @@ ai_start() {
38
55
- Accept extra args after `--`: preserve ordering (`ai_start` receives already-shifted args).
39
56
- Prefer fast startup; heavy initialization belongs in hooks (`postCreate`), not adapters.
40
57
- When adding adapter: update `cmd_help`, README tool list, and completions (bash/zsh/fish).
Copy file name to clipboardExpand all lines: .github/instructions/editor.instructions.md
+24-6Lines changed: 24 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,11 +2,28 @@
2
2
applyTo: adapters/editor/**/*.sh
3
3
---
4
4
5
-
# Editor Instructions
5
+
# Editor Adapter Instructions
6
6
7
-
## Adding Features
7
+
## When to Use a File vs Registry
8
8
9
-
### New Editor Adapter (`adapters/editor/<name>.sh`)
9
+
Most editors are defined as **registry entries** in `lib/adapters.sh` — no adapter file needed.
10
+
Only create an adapter file in `adapters/editor/` for editors that need **custom behavior** beyond what the standard/terminal builders provide (see `nano.sh` for an example).
11
+
12
+
## Adding a Standard Editor (Registry)
13
+
14
+
Add a line to `_EDITOR_REGISTRY` in `lib/adapters.sh`:
15
+
16
+
```
17
+
yourname|yourcmd|standard|EditorName not found. Install from https://...|flags
18
+
```
19
+
20
+
Format: `name|cmd|type|err_msg|flags`
21
+
-`type`: `standard` (GUI app) or `terminal` (runs in terminal)
-**User-facing docs**: Always reference `git gtr`, never `./bin/gtr`
14
14
15
-
## CRITICAL: No Automated Tests
15
+
## Testing
16
16
17
-
This project has **no test suite**. All testing is manual. After any change, run the relevant smoke tests:
17
+
This project uses **BATS tests** for core functions and **manual smoke tests** for end-to-end workflows. CI runs ShellCheck + BATS automatically on PRs (`.github/workflows/lint.yml`).
18
+
19
+
1. Run automated tests: `bats tests/`
20
+
2. Run a single test file: `bats tests/config.bats`
21
+
3. Run a single test by name: `bats tests/config.bats --filter "cfg_map_to_file_key"`
22
+
4. Run relevant manual smoke tests:
18
23
19
24
```bash
20
25
./bin/gtr new test-feature # Create worktree
@@ -25,7 +30,9 @@ This project has **no test suite**. All testing is manual. After any change, run
25
30
./bin/gtr rm test-feature # Clean up
26
31
```
27
32
28
-
For exhaustive testing (hooks, copy patterns, adapters, `--force`, `--from-current`, etc.), see the full checklist in CONTRIBUTING.md or `.github/instructions/testing.instructions.md`.
33
+
For exhaustive manual testing (hooks, copy patterns, adapters, `--force`, `--from-current`, etc.), see the full checklist in CONTRIBUTING.md or `.github/instructions/testing.instructions.md`.
34
+
35
+
**Test files**: `adapters`, `config`, `copy_safety`, `integration_lifecycle`, `parse_args`, `provider`, `resolve_base_dir`, `sanitize_branch_name` (all in `tests/`). Shared fixtures in `tests/test_helper.bash`.
29
36
30
37
**Tip**: Use a disposable repo for testing to avoid polluting your working tree:
|`lib/commands/*.sh`| One file per subcommand: `cmd_create`, `cmd_remove`, etc. (16 files) |
66
+
67
+
Libraries are sourced in the order listed above (ui → args → config → ... → launch → commands/\*.sh glob).
54
68
55
69
### Adapters
56
70
57
-
Editor adapters in `adapters/editor/` and AI adapters in `adapters/ai/` are dynamically sourced via `load_editor_adapter()` and `load_ai_adapter()` in `bin/gtr`.
71
+
Most adapters are defined declaratively in the **adapter registry** (`lib/adapters.sh`) using pipe-delimited entries. Custom adapters that need special logic remain as override files in `adapters/editor/` and `adapters/ai/`.
2. Add case entry in `main()` dispatcher (around line 71)
111
-
3. Add help text in `cmd_help()`
123
+
1.Create `lib/commands/<name>.sh` with `cmd_<name>()` function
124
+
2. Add case entry in `main()` dispatcher in `bin/gtr`
125
+
3. Add help text in `lib/commands/help.sh`
112
126
4. Update all three completion files: `completions/gtr.bash`, `completions/_git-gtr`, `completions/git-gtr.fish`
113
127
5. Update README.md
114
128
115
129
### Adding an Adapter
116
130
117
-
Create `adapters/{editor,ai}/<name>.sh` implementing the two required functions (see existing adapters for patterns). Then update: help text in `cmd_help()` and `load_*_adapter()`, all three completions, README.md.
131
+
**Standard adapters** (just a command name + error message): Add an entry to `_EDITOR_REGISTRY` or `_AI_REGISTRY` in `lib/adapters.sh`. Then update: help text in `lib/commands/help.sh`, all three completions, README.md.
132
+
133
+
**Custom adapters** (special logic needed): Create `adapters/{editor,ai}/<name>.sh` implementing the two required functions (see `adapters/ai/claude.sh` for an example). File-based adapters take priority over registry entries.
118
134
119
135
### Updating the Version
120
136
@@ -128,6 +144,17 @@ When adding commands or flags, update all three files:
128
144
-`completions/_git-gtr` (Zsh)
129
145
-`completions/git-gtr.fish` (Fish)
130
146
147
+
## Critical Gotcha: `set -e`
148
+
149
+
`bin/gtr` runs with `set -e`. Any unguarded non-zero return silently exits the entire script. When calling functions that may `return 1`, guard with `|| true`:
150
+
151
+
```bash
152
+
result=$(my_func)||true# Prevents silent exit
153
+
if my_func;then ...;fi# Also safe (if guards the return)
154
+
```
155
+
156
+
This is the most common source of subtle bugs in this codebase.
0 commit comments