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: CHANGELOG.md
+5Lines changed: 5 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,6 +4,11 @@ Changes to Calva Backseat Driver
4
4
5
5
## [Unreleased]
6
6
7
+
-[Replace four structural editing tools with single batch `clojure_edit_files` tool](https://github.com/BetterThanTomorrow/calva-backseat-driver/issues/58)
8
+
- Supports replace, insert, append, and create operations in one call
Copy file name to clipboardExpand all lines: assets/instructions/editing-clojure-files.instructions.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,5 +1,5 @@
1
1
---
2
-
description: 'Structural editing rules for Clojure files — read these instructions when creating or modifying Clojure files regardless of dialect or runtime and when using structural editing tools (clojure_create_file, replace_top_level_form, insert_top_level_form, clojure_append_code, clojure_balance_brackets)'
2
+
description: 'Structural editing rules for Clojure files — read these instructions when creating or modifying Clojure files regardless of dialect or runtime and when using structural editing tools (clojure_edit_files, clojure_balance_brackets)'
Copy file name to clipboardExpand all lines: assets/skills/backseat-driver/SKILL.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
---
2
2
name: backseat-driver
3
-
description: 'Effective use of the Backseat Driver extension and its tools for Clojure interactive programming. Use when: working in Clojure (including all dialects and runtimes) project, be it reading, planning, developing, or evaluating code in the REPL, looking up function documentation or ClojureDocs examples, choosing REPL sessions, editing Clojure files structurally, checking REPL output, planning implementations, reviewing code, or developing solutions incrementally. Whenever you consider any of these tools: clojure_evaluate_code, clojure_load_file, clojuredocs_info, clojure_list_sessions, clojure_symbol_info, clojure_repl_output_log, replace_top_level_form, insert_top_level_form, clojure_append_code, clojure_create_file, clojure_balance_brackets. Also use this skill when PLANNING or DISCUSSING Clojure development approaches — not only at the moment of REPL evaluation.'
3
+
description: 'Effective use of the Backseat Driver extension and its tools for Clojure interactive programming. Use when: working in Clojure (including all dialects and runtimes) project, be it reading, planning, developing, or evaluating code in the REPL, looking up function documentation or ClojureDocs examples, choosing REPL sessions, editing Clojure files structurally, checking REPL output, planning implementations, reviewing code, or developing solutions incrementally. Whenever you consider any of these tools: clojure_evaluate_code, clojure_load_file, clojuredocs_info, clojure_list_sessions, clojure_symbol_info, clojure_repl_output_log, clojure_edit_files, clojure_balance_brackets. Also use this skill when PLANNING or DISCUSSING Clojure development approaches — not only at the moment of REPL evaluation.'
Copy file name to clipboardExpand all lines: assets/skills/editing-clojure-files/SKILL.md
+57-51Lines changed: 57 additions & 51 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
---
2
2
name: editing-clojure-files
3
-
description: 'Structural editing of Clojure files using Backseat Driver tools. Use when: creating/adding/inserting/replacing/deleting top-level forms, fixing bracket balance, resolving indentation issues, planning multi-edit sequences, recovering from failed edits, or working with Rich Comment Forms in Clojure files, regardless of dialect or runtime. Use whenever you consider any of these tools: clojure_create_file, clojure_append_code, insert_top_level_form, replace_top_level_form, clojure_balance_brackets. Use when editing Clojure and unsure which tool to pick. Use this skill when PLANNING or DISCUSSING Clojure file edits — not only at the moment of editing.'
3
+
description: 'Structural editing of Clojure files using Backseat Driver tools. Use when: creating/adding/inserting/replacing/deleting top-level forms, fixing bracket balance, resolving indentation issues, planning multi-edit sequences, recovering from failed edits, or working with Rich Comment Forms in Clojure files, regardless of dialect or runtime. Use whenever you consider any of these tools: clojure_edit_files, clojure_balance_brackets. Use when editing Clojure and unsure which tool to pick. Use this skill when PLANNING or DISCUSSING Clojure file edits — not only at the moment of editing.'
4
4
---
5
5
6
6
# Editing Clojure Files
@@ -23,40 +23,58 @@ Smaller, simpler forms mean less code to get right in a single edit, fewer inden
23
23
24
24
When a function you need to modify is already long or deeply nested, improve its structure first, then make the requested change. Structural edits on bloated forms are error-prone.
25
25
26
-
## Tool Selection
26
+
## The Tool: `clojure_edit_files`
27
27
28
+
One tool handles all structural editing operations. It accepts a batch of edits, validates them up front, groups by file, sorts for safe application order, and applies them sequentially.
29
+
30
+
### Edit Types
31
+
32
+
| Type | Purpose | Required fields |
33
+
|------|---------|-----------------|
34
+
|`create`| Create a new file with content |`filePath`, `content`|
35
+
|`append`| Append forms to end of file |`filePath`, `code`|
36
+
|`replace`| Replace an existing top-level form |`filePath`, `line`, `targetLineText`, `newForm`|
37
+
|`insert`| Insert a form before an existing form |`filePath`, `line`, `targetLineText`, `newForm`|
38
+
39
+
### Constraints
40
+
41
+
- At most one `create` per file per call
42
+
- At most one `append` per file per call
43
+
- All edits are schema-validated before any are applied — one invalid edit blocks the entire batch
44
+
- Within a file: creates run first, then replace/insert (highest line first), then appends
When brackets are broken, structural top-level edits are not possible. Use `clojure_balance_brackets` to analyse the breakage, then fall back to regular text editing tools if needed. If repeated attempts fail, escalate to the human via the #askQuestions tool.
67
+
### When Brackets Are Broken
68
+
69
+
Structural top-level edits are not possible when brackets are unbalanced. Use `clojure_balance_brackets` to analyse the breakage, then fall back to regular text editing tools if needed. If repeated attempts fail, escalate to the human via the #askQuestions tool.
70
+
71
+
### Line Comments
72
+
73
+
Structural tools operate on forms, not line comments (`;`). Use built-in text editing tools for line comments.
56
74
57
75
## Targeting Forms
58
76
59
-
The `replace_top_level_form` and `insert_top_level_form` tools locate forms using two parameters: `line` (1-based line number) and `targetLineText` (the exact first line of the target form). Accuracy here is critical.
77
+
The `replace` and `insert` edit types locate forms using two parameters: `line` (1-based line number) and `targetLineText` (the exact first line of the target form). Accuracy here is critical.
60
78
61
79
Read the file immediately before editing to get accurate line numbers and exact text.
62
80
@@ -102,27 +120,20 @@ Definitions must precede their call sites in the file. When edits would create a
102
120
103
121
## Edit Process
104
122
105
-
Verification is mandatory after every edit:
123
+
Verification is mandatory after every batch:
106
124
107
125
1.**Check problems first** — review current diagnostics; fix existing compilation problems before introducing new edits
108
-
2.**Edit the file** — use the structural tool with REPL-verified code
109
-
3.**Check diagnostics** — read post-edit linting info; act on unexpected problems before the next edit
126
+
2.**Batch edits** — assemble all edits for the call with REPL-verified code
127
+
3.**Check diagnostics** — read post-edit diagnostics from the response; act on unexpected problems before the next batch
110
128
4.**Reload** — `clojure_load_file` to load the file, or `(require 'the.namespace :reload)` to confirm the file loads cleanly
111
129
112
130
In a hot-reload environment, the REPL output log shows compile errors and warnings immediately after the edit. Read and act on them before proceeding.
113
131
114
-
## Multiple Edits: Bottom-to-Top
115
-
116
-
Always edit from highest line number to lowest. Each edit shifts line numbers below it — working bottom-up keeps planned numbers accurate.
132
+
## Multiple Edits Are Automatic
117
133
118
-
1. Read the file — identify all edit targets with line numbers
119
-
2. Sort edits by line number, **descending**
120
-
3. Apply each edit (highest line first)
121
-
4. Read the file afterward to verify final state
134
+
The tool automatically sorts edits within each file for safe application order (highest line number first for replace/insert). You do not need to manually sort — just provide all edits in a single call and the tool handles ordering.
122
135
123
-
Example: editing forms at lines 10, 25, 40 → edit order: 40 → 25 → 10.
124
-
125
-
Expect temporary linter warnings about undefined symbols during a multi-edit sequence — they resolve once the full sequence completes.
136
+
Expect temporary linter warnings about undefined symbols during a multi-edit sequence — they resolve once the full batch completes.
126
137
127
138
## Error Recovery
128
139
@@ -140,17 +151,13 @@ Target line text not found. Expected: '(defn wrong-function [x]' near line 23
140
151
```
141
152
Fix: Use `grep_search` scoped to the file to find the target text's current line number — cheaper than reading the whole file. Plain text mode for exact matches; in regex mode, escape parens as `\(`.
142
153
143
-
### Comment Targeting
154
+
### Partial Batch Failure
144
155
145
-
Structural tools operate on forms, not line comments:
146
-
```
147
-
Target line text cannot start with a comment (;). You can only target forms/sexpressions.
148
-
```
149
-
Fix: Use `replace_string_in_file` or equivalent text tool for line comments.
156
+
The tool continues on failure within a file. The response shows which edits succeeded and which failed. For failed edits, re-read the file, get updated line numbers, and retry in a new batch.
150
157
151
158
### Scan Window Miss
152
159
153
-
The text exists but outside the ±2 window — most commonly because previous edits shifted line numbers. Search the file for the target text to get its current line number.
160
+
The text exists but outside the ±2 window — most commonly because a prior edit in the same batch shifted line numbers beyond the ±2 tolerance. Re-read the file and retry with updated targeting.
154
161
155
162
## Extensibility
156
163
@@ -160,9 +167,8 @@ When this skill is loaded, also load any corresponding `clojure-coding` or `cloj
160
167
161
168
## Invariants
162
169
163
-
- Clojure file edits use structural tools; line comments use text editing tools
164
-
- New `.clj`/`.cljs`/`.cljc`/`.bb` files are created with `clojure_create_file`
165
-
- Multi-edit sequences proceed bottom-to-top (highest line number first)
170
+
- Clojure file edits use `clojure_edit_files`; line comments use text editing tools
171
+
- New `.clj`/`.cljs`/`.cljc`/`.bb` files are created with `clojure_edit_files` type `create`
166
172
- Indentation is verified before every structural edit — Parinfer depends on it
167
173
- Post-edit diagnostics are read and acted on before proceeding
168
174
-`targetLineText` is always the exact first line of the target form
0 commit comments