Skip to content

Commit 497029b

Browse files
Add AI skills that automate rebase rules processes
Signed-off-by: Roman Nikitenko <rnikiten@redhat.com> Assisted-by: Cursor AI
1 parent 2023b00 commit 497029b

10 files changed

Lines changed: 1657 additions & 130 deletions

File tree

.claude/skills/add-rebase-rules/SKILL.md

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,39 @@ Important:
5656
- File path: `.rebase/replace/<original-path>.json`
5757
- Format: JSON array of objects with `from` and `by`.
5858
- Add one rule per changed hunk, using stable and unique snippets.
59-
- Prefer the smallest safe snippet that is unlikely to change accidentally.
59+
- **Ensure `from` appears exactly once in the upstream file.** Both sed and perl handlers replace **all** occurrences — if `from` matches multiple places, all will be replaced, which is almost always wrong. Extend the snippet with more surrounding context to make it unique.
60+
- Prefer the smallest safe snippet that is unlikely to change accidentally, but large enough to be unique in the file.
6061
- If replacement is multiline, encode using escaped newlines/tabs in JSON consistently with existing files.
6162
- For multiline `from` snippets, start at the first non-whitespace token (avoid anchoring on leading indentation only).
6263
- Prefer replacing the whole logical block (`if (...) { ... }`) rather than only an inner line fragment, so closing braces remain structurally correct.
64+
- **Encode special characters correctly** for the handler used in `rebase.sh`. See the encoding tables below.
65+
66+
### Sed encoding (`apply_changes`)
67+
68+
Values go through: JSON parse → `jq -r``escape_litteral` → sed.
69+
70+
| Character in target | `from` encoding | `by` encoding |
71+
|---------------------|----------------|---------------|
72+
| Newline | `\\\n` | `\\\n` |
73+
| Tab | `\\\t` | `\\\t` |
74+
| `&` | literal | `\\&` |
75+
| `*` | `\\*` | literal |
76+
| `$`, `[`, `]` | literal (`escape_litteral` handles) | literal |
77+
| `"` | `\\\"` | `\\\"` |
78+
79+
**Common pitfall — `&` in sed `by` values:** In sed replacement strings, `&` means "the entire matched text". Writing `&&` in a `by` value produces the matched `from` text repeated twice instead of a literal `&&`. Always escape as `\\&\\&`. This applies to any `&` in `by`, not just `&&`.
80+
81+
### Perl encoding (`apply_changes_multi_line` / `apply_multi_line_replace`)
82+
83+
Values go through: JSON parse → `jq -r` → env var → perl `\Q\E` (from) / literal (by).
84+
85+
| Character in target | `from` encoding | `by` encoding |
86+
|---------------------|----------------|---------------|
87+
| Newline | `\n` | `\n` |
88+
| Tab | `\t` | `\t` |
89+
| Any special char | literal | literal |
90+
91+
**Prefer multiline (perl) for new rules** — simpler encoding, handles all cases, no `&` pitfall.
6392

6493
5. Update `rebase.sh` conflict routing
6594
- Ensure each file that now has a new rebasing rule is routable in `resolve_conflicts`.
@@ -89,13 +118,24 @@ Important:
89118
- For each changed `.rebase/replace/**/*.json`, verify every `from` exists in the upstream file content before finishing.
90119
- Example: `git show <upstream-ref>:<path-without-code-prefix>` and compare with the `from` snippet.
91120
- `path-without-code-prefix` means the same file path but without the leading `code/` (because `upstream-code` stores VS Code sources at repo root).
121+
- Verify each `from` appears **exactly once** in the upstream file. If it matches multiple times, the rule will silently replace all of them. Extend the `from` snippet with more context until it is unique.
92122
- Dry-run the generated rule using the same replacement path as `rebase.sh` (Perl-based multiline replace), not a language-native `.replace(...)`.
93123
- Include at least one test case where `from`/`by` contains `$` (for example template literals like `${key}`) and confirm replacement still succeeds.
94124
- Re-check exclusions:
95125
- no rules for `code/extensions/che-*`
96126
- no rules for `package-lock.json`
97127
- Ensure every changed rule file is actually referenced by logic in `rebase.sh` when required.
98128

129+
8. Verify completeness — no uncovered Che-specific changes
130+
- For each file that was updated or created in `.rebase/replace/`, simulate the **full** rule application:
131+
1. Start with the upstream file at `CURRENT_UPSTREAM_VERSION`.
132+
2. Apply **all** rule entries from the JSON (not just the newly added ones) plus any custom inline replacements from `rebase.sh`.
133+
3. Diff the result against the che-code working tree file.
134+
- If the diff is empty → all Che changes are covered. Good.
135+
- If there is a remaining diff → there are Che-specific changes in the working tree that are **not covered** by any rule. These changes would be silently lost during rebase.
136+
- If the uncovered changes are from the same commit being processed, add additional rule entries for them.
137+
- If the uncovered changes are pre-existing (from earlier commits), report them to the user as a warning: "Pre-existing Che-specific changes at lines X-Y have no rebase rule and would be lost during rebase."
138+
99139
## Decision notes
100140

101141
- Goal is to protect Che-specific behavior during upstream subtree rebases while keeping deltas in upstream files minimal.

0 commit comments

Comments
 (0)