@rvdbreemen/adr-kit-opencode 0.52.0 → 0.52.2

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 (82) hide show
  1. package/.claude-plugin/plugin.json +29 -29
  2. package/README.md +861 -850
  3. package/bin/adr +0 -0
  4. package/bin/adr-audit +0 -0
  5. package/bin/adr-context +0 -0
  6. package/bin/adr-discover +0 -0
  7. package/bin/adr-doctor +0 -0
  8. package/bin/adr-generate-scripts +0 -0
  9. package/bin/adr-grill-signal +0 -0
  10. package/bin/adr-guardian +0 -0
  11. package/bin/adr-index +0 -0
  12. package/bin/adr-judge +0 -0
  13. package/bin/adr-judge-precommit +0 -0
  14. package/bin/adr-lint +0 -0
  15. package/bin/adr-mcp +0 -0
  16. package/bin/adr-migrate +0 -0
  17. package/bin/adr-quality +0 -0
  18. package/bin/adr-readiness +0 -0
  19. package/bin/adr-readiness-ci +0 -0
  20. package/bin/adr-related +0 -0
  21. package/bin/adr-renumber +254 -254
  22. package/bin/adr-retire +0 -0
  23. package/bin/adr-settings +0 -0
  24. package/bin/adr-status +0 -0
  25. package/bin/adr-suggest +0 -0
  26. package/bin/adr-watch +0 -0
  27. package/bin/bump-version +0 -0
  28. package/clients/workflows.json +229 -229
  29. package/hooks/__init__.py +1 -1
  30. package/hooks/adapters/__init__.py +13 -13
  31. package/hooks/adapters/claude.py +27 -27
  32. package/hooks/adapters/codex.py +26 -26
  33. package/hooks/adapters/copilot.py +11 -11
  34. package/hooks/adr-hook.py +128 -128
  35. package/hooks/adr_hook_core.py +843 -843
  36. package/hooks/adr_pr_guard.py +367 -367
  37. package/instructions/ADR-guide.md +48 -48
  38. package/instructions/adr.coding.md +82 -82
  39. package/instructions/adr.review.md +182 -182
  40. package/opencode/plugin.ts +1 -4
  41. package/package.json +5 -2
  42. package/schemas/adr-context-probes.schema.json +56 -56
  43. package/schemas/adr-enforcement.schema.json +57 -57
  44. package/schemas/adr-frontmatter.schema.json +144 -144
  45. package/schemas/adr-index.schema.json +276 -276
  46. package/schemas/adr-kit-config.schema.json +371 -371
  47. package/schemas/adr-readiness.schema.json +41 -41
  48. package/schemas/client-capabilities.schema.json +503 -503
  49. package/schemas/client-certification.schema.json +101 -101
  50. package/schemas/doctor-output.schema.json +92 -92
  51. package/skills/adr/SKILL.md +780 -780
  52. package/skills/audit/SKILL.md +103 -103
  53. package/skills/context/SKILL.md +77 -77
  54. package/skills/grill/SKILL.md +84 -84
  55. package/skills/grill/agents/openai.yaml +4 -4
  56. package/skills/guardian/SKILL.md +316 -316
  57. package/skills/init/SKILL.md +499 -499
  58. package/skills/install-hooks/SKILL.md +154 -154
  59. package/skills/judge/SKILL.md +168 -168
  60. package/skills/lint/SKILL.md +321 -321
  61. package/skills/migrate/SKILL.md +313 -313
  62. package/skills/related/SKILL.md +62 -62
  63. package/skills/retire/SKILL.md +41 -41
  64. package/skills/review/SKILL.md +167 -167
  65. package/skills/settings/SKILL.md +73 -73
  66. package/skills/setup/SKILL.md +128 -128
  67. package/skills/supersede/SKILL.md +136 -136
  68. package/skills/upgrade/SKILL.md +273 -273
  69. package/templates/adr-kit-guide.md +354 -354
  70. package/templates/adr-template.canonical.md +115 -115
  71. package/templates/adr-template.madr.md +131 -131
  72. package/templates/adr-template.md +131 -131
  73. package/templates/adr-template.nygard.md +111 -111
  74. package/templates/cc-settings/guardian-hook-entry.json +9 -9
  75. package/templates/githooks/pre-commit +1 -1
  76. package/templates/github-workflows/adr-audit.yml +58 -58
  77. package/templates/github-workflows/adr-guardian-audit.yml +133 -133
  78. package/templates/github-workflows/adr-index-check.yml +30 -30
  79. package/templates/github-workflows/adr-judge.yml +31 -31
  80. package/templates/github-workflows/adr-readiness.yml +18 -18
  81. package/templates/validate_adr_template.py +38 -38
  82. package/templates/validate_adr_template.sh +74 -74
package/bin/adr CHANGED
File without changes
package/bin/adr-audit CHANGED
File without changes
package/bin/adr-context CHANGED
File without changes
package/bin/adr-discover CHANGED
File without changes
package/bin/adr-doctor CHANGED
File without changes
File without changes
File without changes
package/bin/adr-guardian CHANGED
File without changes
package/bin/adr-index CHANGED
File without changes
package/bin/adr-judge CHANGED
File without changes
File without changes
package/bin/adr-lint CHANGED
File without changes
package/bin/adr-mcp CHANGED
File without changes
package/bin/adr-migrate CHANGED
File without changes
package/bin/adr-quality CHANGED
File without changes
package/bin/adr-readiness CHANGED
File without changes
File without changes
package/bin/adr-related CHANGED
File without changes
package/bin/adr-renumber CHANGED
@@ -1,254 +1,254 @@
1
- #!/usr/bin/env python3
2
- """adr-renumber: safely renumber one ADR and update all cross-references.
3
-
4
- Built for the merge-collision workflow: two parallel branches both claim
5
- ADR-043, CI fails on the duplicate-number check in adr-lint, and one of the
6
- two files must move to a free number. This tool renames the file, rewrites
7
- the heading, and updates every whole-token reference to the old id across
8
- all ADRs in the directory: Related Decisions entries, "Superseded by" and
9
- "Amended by" status strings, Status History mentions, and plain ADR-NNN
10
- references.
11
-
12
- Safety properties:
13
- - Dry-run by default: prints the full plan (file rename plus every rewrite
14
- with file:line) and changes nothing. --apply executes the plan.
15
- - Whole-token matching only: renumbering ADR-043 never touches ADR-0430.
16
- - Refuses (exit 2) when the target number is already taken or the source
17
- does not exist.
18
- - All regexes are linear: no nested or lazy quantifiers (see the
19
- 0.19.1/0.19.2 ReDoS history in CHANGELOG.md).
20
-
21
- Exit codes:
22
- 0 success (plan printed, or --apply completed)
23
- 2 input error (source missing, target taken, ambiguous source, bad id)
24
-
25
- Usage:
26
- adr-renumber ADR-043 # dry-run, target = next free number
27
- adr-renumber ADR-043 --to ADR-051 # dry-run with explicit target
28
- adr-renumber ADR-043 --to ADR-051 --apply # execute
29
- adr-renumber docs/adr/ADR-043-foo.md --to ADR-051 # disambiguate duplicates
30
- adr-renumber ADR-043 --adr-dir docs/decisions
31
-
32
- Deterministic, stdlib-only, Python 3.10+.
33
- """
34
-
35
- from __future__ import annotations
36
-
37
- import argparse
38
- import re
39
- import sys
40
- from pathlib import Path
41
- from typing import Dict, List, Optional, Tuple
42
-
43
- ADR_FILENAME_RE = re.compile(r"(?i)^ADR-(\d{1,4})-")
44
- ADR_ID_RE = re.compile(r"(?i)^ADR-(\d{1,4})$")
45
-
46
-
47
- class RenumberError(Exception):
48
- """Raised on input errors; maps to exit code 2."""
49
-
50
-
51
- def parse_adr_id(raw: str) -> int:
52
- """Return the integer number of an ADR-NNN id, or raise RenumberError."""
53
- m = ADR_ID_RE.match(raw.strip())
54
- if not m:
55
- raise RenumberError(f"{raw!r} does not match ADR-NNN (e.g. ADR-043)")
56
- return int(m.group(1))
57
-
58
-
59
- def discover_adrs(adr_dir: Path) -> List[Path]:
60
- """Return sorted ADR markdown files in adr_dir (non-recursive)."""
61
- if not adr_dir.is_dir():
62
- raise RenumberError(f"ADR directory not found: {adr_dir}")
63
- return sorted(
64
- (p for p in adr_dir.glob("*.md") if ADR_FILENAME_RE.match(p.name)),
65
- key=lambda p: p.name.lower(),
66
- )
67
-
68
-
69
- def numbers_in_use(files: List[Path]) -> Dict[int, List[Path]]:
70
- """Map ADR number -> list of files carrying that number."""
71
- grouped: Dict[int, List[Path]] = {}
72
- for fp in files:
73
- m = ADR_FILENAME_RE.match(fp.name)
74
- if m:
75
- grouped.setdefault(int(m.group(1)), []).append(fp)
76
- return grouped
77
-
78
-
79
- def next_free_number(in_use: Dict[int, List[Path]]) -> int:
80
- """Return max(used) + 1. Gaps are not reused: a gap usually means a
81
- retired or reserved number, and reusing it would resurrect stale
82
- references."""
83
- return (max(in_use) + 1) if in_use else 1
84
-
85
-
86
- def token_pattern(num: int) -> "re.Pattern[str]":
87
- """Whole-token pattern for every common spelling of an ADR id.
88
-
89
- Matches ADR-43, ADR-043, ADR-0043 (whichever spellings differ), but
90
- never ADR-0430: a digit may not follow the number. \\b before 'ADR'
91
- rejects mid-word hits. Pure alternation of literals: linear time.
92
- """
93
- spellings = sorted({str(num), f"{num:03d}", f"{num:04d}"}, key=len, reverse=True)
94
- alt = "|".join(spellings)
95
- return re.compile(rf"\bADR-(?:{alt})(?!\d)")
96
-
97
-
98
- def renamed_filename(name: str, new_num: int) -> str:
99
- """Replace the leading ADR-NNN- of a filename with the new number."""
100
- m = ADR_FILENAME_RE.match(name)
101
- if not m:
102
- raise RenumberError(f"{name!r} is not an ADR filename (ADR-NNN-...)")
103
- return f"ADR-{new_num:03d}-" + name[m.end():]
104
-
105
-
106
- def find_source(source_arg: str, adr_dir: Path, files: List[Path]) -> Tuple[Path, int]:
107
- """Resolve the source argument (ADR-NNN id or file path) to one file."""
108
- candidate = Path(source_arg)
109
- if candidate.suffix.lower() == ".md":
110
- if not candidate.is_file():
111
- candidate = adr_dir / candidate.name
112
- if not candidate.is_file():
113
- raise RenumberError(f"source file not found: {source_arg}")
114
- m = ADR_FILENAME_RE.match(candidate.name)
115
- if not m:
116
- raise RenumberError(
117
- f"{candidate.name!r} is not an ADR filename (ADR-NNN-...)"
118
- )
119
- return candidate, int(m.group(1))
120
-
121
- num = parse_adr_id(source_arg)
122
- matches = [
123
- fp for fp in files
124
- if (m := ADR_FILENAME_RE.match(fp.name)) and int(m.group(1)) == num
125
- ]
126
- if not matches:
127
- raise RenumberError(f"no ADR with number {num:03d} found in {adr_dir}")
128
- if len(matches) > 1:
129
- names = ", ".join(fp.name for fp in matches)
130
- raise RenumberError(
131
- f"ADR-{num:03d} is ambiguous ({names}); "
132
- f"pass the file path of the one to renumber"
133
- )
134
- return matches[0], num
135
-
136
-
137
- def build_plan(
138
- files: List[Path], source: Path, old_num: int, new_num: int
139
- ) -> List[Tuple[Path, int, str, str]]:
140
- """Return rewrite entries: (file, 1-based line, old line, new line)."""
141
- pat = token_pattern(old_num)
142
- new_id = f"ADR-{new_num:03d}"
143
- plan: List[Tuple[Path, int, str, str]] = []
144
- for fp in files:
145
- text = fp.read_text(encoding="utf-8", errors="replace")
146
- for lineno, line in enumerate(text.splitlines(), start=1):
147
- new_line, n = pat.subn(new_id, line)
148
- if n:
149
- plan.append((fp, lineno, line, new_line))
150
- return plan
151
-
152
-
153
- def apply_plan(
154
- files: List[Path], source: Path, old_num: int, new_num: int
155
- ) -> Path:
156
- """Rewrite references in every file, then rename the source. Returns the
157
- new source path."""
158
- pat = token_pattern(old_num)
159
- new_id = f"ADR-{new_num:03d}"
160
- for fp in files:
161
- text = fp.read_text(encoding="utf-8")
162
- new_text, n = pat.subn(new_id, text)
163
- if n:
164
- fp.write_text(new_text, encoding="utf-8")
165
- new_path = source.with_name(renamed_filename(source.name, new_num))
166
- source.rename(new_path)
167
- return new_path
168
-
169
-
170
- def main(argv: Optional[List[str]] = None) -> int:
171
- parser = argparse.ArgumentParser(
172
- prog="adr-renumber",
173
- description=(
174
- "Renumber one ADR and update all cross-references. "
175
- "Dry-run by default; pass --apply to execute."
176
- ),
177
- )
178
- parser.add_argument(
179
- "source",
180
- help="ADR id (ADR-043) or file path of the ADR to renumber",
181
- )
182
- parser.add_argument(
183
- "--to", metavar="ADR-NNN", default=None,
184
- help="Target id (default: next free number, max in use + 1)",
185
- )
186
- parser.add_argument(
187
- "--adr-dir", metavar="DIR", default="docs/adr",
188
- help="ADR directory (default: docs/adr)",
189
- )
190
- parser.add_argument(
191
- "--apply", action="store_true",
192
- help="Execute the plan (default is dry-run)",
193
- )
194
- parser.add_argument(
195
- "--version", action="version", version="adr-renumber 0.1.0",
196
- )
197
- args = parser.parse_args(argv)
198
-
199
- try:
200
- adr_dir = Path(args.adr_dir)
201
- files = discover_adrs(adr_dir)
202
- source, old_num = find_source(args.source, adr_dir, files)
203
- in_use = numbers_in_use(files)
204
-
205
- if args.to is not None:
206
- new_num = parse_adr_id(args.to)
207
- else:
208
- new_num = next_free_number(in_use)
209
-
210
- if new_num == old_num:
211
- raise RenumberError(
212
- f"target ADR-{new_num:03d} equals the source number"
213
- )
214
- if new_num in in_use:
215
- taken_by = ", ".join(fp.name for fp in in_use[new_num])
216
- raise RenumberError(
217
- f"target ADR-{new_num:03d} is already taken by {taken_by}"
218
- )
219
- except RenumberError as e:
220
- print(f"adr-renumber: {e}", file=sys.stderr)
221
- return 2
222
-
223
- old_id = f"ADR-{old_num:03d}"
224
- new_id = f"ADR-{new_num:03d}"
225
- new_name = renamed_filename(source.name, new_num)
226
-
227
- print(f"Plan: renumber {old_id} -> {new_id}")
228
- print(f" rename: {source} -> {source.with_name(new_name)}")
229
- if len(in_use.get(old_num, [])) > 1:
230
- others = ", ".join(
231
- fp.name for fp in in_use[old_num] if fp != source
232
- )
233
- print(
234
- f" warning: {old_id} is duplicated (also: {others}); "
235
- f"rewritten references may belong to either file. Review the plan."
236
- )
237
-
238
- plan = build_plan(files, source, old_num, new_num)
239
- for fp, lineno, old_line, new_line in plan:
240
- print(f" {fp}:{lineno}: {old_line.strip()}")
241
- print(f" -> {new_line.strip()}")
242
- print(f" {len(plan)} line(s) to rewrite across {len(files)} ADR file(s).")
243
-
244
- if not args.apply:
245
- print("Dry run: no changes made. Re-run with --apply to execute.")
246
- return 0
247
-
248
- new_path = apply_plan(files, source, old_num, new_num)
249
- print(f"Applied: {len(plan)} line(s) rewritten; renamed to {new_path}")
250
- return 0
251
-
252
-
253
- if __name__ == "__main__":
254
- sys.exit(main())
1
+ #!/usr/bin/env python3
2
+ """adr-renumber: safely renumber one ADR and update all cross-references.
3
+
4
+ Built for the merge-collision workflow: two parallel branches both claim
5
+ ADR-043, CI fails on the duplicate-number check in adr-lint, and one of the
6
+ two files must move to a free number. This tool renames the file, rewrites
7
+ the heading, and updates every whole-token reference to the old id across
8
+ all ADRs in the directory: Related Decisions entries, "Superseded by" and
9
+ "Amended by" status strings, Status History mentions, and plain ADR-NNN
10
+ references.
11
+
12
+ Safety properties:
13
+ - Dry-run by default: prints the full plan (file rename plus every rewrite
14
+ with file:line) and changes nothing. --apply executes the plan.
15
+ - Whole-token matching only: renumbering ADR-043 never touches ADR-0430.
16
+ - Refuses (exit 2) when the target number is already taken or the source
17
+ does not exist.
18
+ - All regexes are linear: no nested or lazy quantifiers (see the
19
+ 0.19.1/0.19.2 ReDoS history in CHANGELOG.md).
20
+
21
+ Exit codes:
22
+ 0 success (plan printed, or --apply completed)
23
+ 2 input error (source missing, target taken, ambiguous source, bad id)
24
+
25
+ Usage:
26
+ adr-renumber ADR-043 # dry-run, target = next free number
27
+ adr-renumber ADR-043 --to ADR-051 # dry-run with explicit target
28
+ adr-renumber ADR-043 --to ADR-051 --apply # execute
29
+ adr-renumber docs/adr/ADR-043-foo.md --to ADR-051 # disambiguate duplicates
30
+ adr-renumber ADR-043 --adr-dir docs/decisions
31
+
32
+ Deterministic, stdlib-only, Python 3.10+.
33
+ """
34
+
35
+ from __future__ import annotations
36
+
37
+ import argparse
38
+ import re
39
+ import sys
40
+ from pathlib import Path
41
+ from typing import Dict, List, Optional, Tuple
42
+
43
+ ADR_FILENAME_RE = re.compile(r"(?i)^ADR-(\d{1,4})-")
44
+ ADR_ID_RE = re.compile(r"(?i)^ADR-(\d{1,4})$")
45
+
46
+
47
+ class RenumberError(Exception):
48
+ """Raised on input errors; maps to exit code 2."""
49
+
50
+
51
+ def parse_adr_id(raw: str) -> int:
52
+ """Return the integer number of an ADR-NNN id, or raise RenumberError."""
53
+ m = ADR_ID_RE.match(raw.strip())
54
+ if not m:
55
+ raise RenumberError(f"{raw!r} does not match ADR-NNN (e.g. ADR-043)")
56
+ return int(m.group(1))
57
+
58
+
59
+ def discover_adrs(adr_dir: Path) -> List[Path]:
60
+ """Return sorted ADR markdown files in adr_dir (non-recursive)."""
61
+ if not adr_dir.is_dir():
62
+ raise RenumberError(f"ADR directory not found: {adr_dir}")
63
+ return sorted(
64
+ (p for p in adr_dir.glob("*.md") if ADR_FILENAME_RE.match(p.name)),
65
+ key=lambda p: p.name.lower(),
66
+ )
67
+
68
+
69
+ def numbers_in_use(files: List[Path]) -> Dict[int, List[Path]]:
70
+ """Map ADR number -> list of files carrying that number."""
71
+ grouped: Dict[int, List[Path]] = {}
72
+ for fp in files:
73
+ m = ADR_FILENAME_RE.match(fp.name)
74
+ if m:
75
+ grouped.setdefault(int(m.group(1)), []).append(fp)
76
+ return grouped
77
+
78
+
79
+ def next_free_number(in_use: Dict[int, List[Path]]) -> int:
80
+ """Return max(used) + 1. Gaps are not reused: a gap usually means a
81
+ retired or reserved number, and reusing it would resurrect stale
82
+ references."""
83
+ return (max(in_use) + 1) if in_use else 1
84
+
85
+
86
+ def token_pattern(num: int) -> "re.Pattern[str]":
87
+ """Whole-token pattern for every common spelling of an ADR id.
88
+
89
+ Matches ADR-43, ADR-043, ADR-0043 (whichever spellings differ), but
90
+ never ADR-0430: a digit may not follow the number. \\b before 'ADR'
91
+ rejects mid-word hits. Pure alternation of literals: linear time.
92
+ """
93
+ spellings = sorted({str(num), f"{num:03d}", f"{num:04d}"}, key=len, reverse=True)
94
+ alt = "|".join(spellings)
95
+ return re.compile(rf"\bADR-(?:{alt})(?!\d)")
96
+
97
+
98
+ def renamed_filename(name: str, new_num: int) -> str:
99
+ """Replace the leading ADR-NNN- of a filename with the new number."""
100
+ m = ADR_FILENAME_RE.match(name)
101
+ if not m:
102
+ raise RenumberError(f"{name!r} is not an ADR filename (ADR-NNN-...)")
103
+ return f"ADR-{new_num:03d}-" + name[m.end():]
104
+
105
+
106
+ def find_source(source_arg: str, adr_dir: Path, files: List[Path]) -> Tuple[Path, int]:
107
+ """Resolve the source argument (ADR-NNN id or file path) to one file."""
108
+ candidate = Path(source_arg)
109
+ if candidate.suffix.lower() == ".md":
110
+ if not candidate.is_file():
111
+ candidate = adr_dir / candidate.name
112
+ if not candidate.is_file():
113
+ raise RenumberError(f"source file not found: {source_arg}")
114
+ m = ADR_FILENAME_RE.match(candidate.name)
115
+ if not m:
116
+ raise RenumberError(
117
+ f"{candidate.name!r} is not an ADR filename (ADR-NNN-...)"
118
+ )
119
+ return candidate, int(m.group(1))
120
+
121
+ num = parse_adr_id(source_arg)
122
+ matches = [
123
+ fp for fp in files
124
+ if (m := ADR_FILENAME_RE.match(fp.name)) and int(m.group(1)) == num
125
+ ]
126
+ if not matches:
127
+ raise RenumberError(f"no ADR with number {num:03d} found in {adr_dir}")
128
+ if len(matches) > 1:
129
+ names = ", ".join(fp.name for fp in matches)
130
+ raise RenumberError(
131
+ f"ADR-{num:03d} is ambiguous ({names}); "
132
+ f"pass the file path of the one to renumber"
133
+ )
134
+ return matches[0], num
135
+
136
+
137
+ def build_plan(
138
+ files: List[Path], source: Path, old_num: int, new_num: int
139
+ ) -> List[Tuple[Path, int, str, str]]:
140
+ """Return rewrite entries: (file, 1-based line, old line, new line)."""
141
+ pat = token_pattern(old_num)
142
+ new_id = f"ADR-{new_num:03d}"
143
+ plan: List[Tuple[Path, int, str, str]] = []
144
+ for fp in files:
145
+ text = fp.read_text(encoding="utf-8", errors="replace")
146
+ for lineno, line in enumerate(text.splitlines(), start=1):
147
+ new_line, n = pat.subn(new_id, line)
148
+ if n:
149
+ plan.append((fp, lineno, line, new_line))
150
+ return plan
151
+
152
+
153
+ def apply_plan(
154
+ files: List[Path], source: Path, old_num: int, new_num: int
155
+ ) -> Path:
156
+ """Rewrite references in every file, then rename the source. Returns the
157
+ new source path."""
158
+ pat = token_pattern(old_num)
159
+ new_id = f"ADR-{new_num:03d}"
160
+ for fp in files:
161
+ text = fp.read_text(encoding="utf-8")
162
+ new_text, n = pat.subn(new_id, text)
163
+ if n:
164
+ fp.write_text(new_text, encoding="utf-8")
165
+ new_path = source.with_name(renamed_filename(source.name, new_num))
166
+ source.rename(new_path)
167
+ return new_path
168
+
169
+
170
+ def main(argv: Optional[List[str]] = None) -> int:
171
+ parser = argparse.ArgumentParser(
172
+ prog="adr-renumber",
173
+ description=(
174
+ "Renumber one ADR and update all cross-references. "
175
+ "Dry-run by default; pass --apply to execute."
176
+ ),
177
+ )
178
+ parser.add_argument(
179
+ "source",
180
+ help="ADR id (ADR-043) or file path of the ADR to renumber",
181
+ )
182
+ parser.add_argument(
183
+ "--to", metavar="ADR-NNN", default=None,
184
+ help="Target id (default: next free number, max in use + 1)",
185
+ )
186
+ parser.add_argument(
187
+ "--adr-dir", metavar="DIR", default="docs/adr",
188
+ help="ADR directory (default: docs/adr)",
189
+ )
190
+ parser.add_argument(
191
+ "--apply", action="store_true",
192
+ help="Execute the plan (default is dry-run)",
193
+ )
194
+ parser.add_argument(
195
+ "--version", action="version", version="adr-renumber 0.1.0",
196
+ )
197
+ args = parser.parse_args(argv)
198
+
199
+ try:
200
+ adr_dir = Path(args.adr_dir)
201
+ files = discover_adrs(adr_dir)
202
+ source, old_num = find_source(args.source, adr_dir, files)
203
+ in_use = numbers_in_use(files)
204
+
205
+ if args.to is not None:
206
+ new_num = parse_adr_id(args.to)
207
+ else:
208
+ new_num = next_free_number(in_use)
209
+
210
+ if new_num == old_num:
211
+ raise RenumberError(
212
+ f"target ADR-{new_num:03d} equals the source number"
213
+ )
214
+ if new_num in in_use:
215
+ taken_by = ", ".join(fp.name for fp in in_use[new_num])
216
+ raise RenumberError(
217
+ f"target ADR-{new_num:03d} is already taken by {taken_by}"
218
+ )
219
+ except RenumberError as e:
220
+ print(f"adr-renumber: {e}", file=sys.stderr)
221
+ return 2
222
+
223
+ old_id = f"ADR-{old_num:03d}"
224
+ new_id = f"ADR-{new_num:03d}"
225
+ new_name = renamed_filename(source.name, new_num)
226
+
227
+ print(f"Plan: renumber {old_id} -> {new_id}")
228
+ print(f" rename: {source} -> {source.with_name(new_name)}")
229
+ if len(in_use.get(old_num, [])) > 1:
230
+ others = ", ".join(
231
+ fp.name for fp in in_use[old_num] if fp != source
232
+ )
233
+ print(
234
+ f" warning: {old_id} is duplicated (also: {others}); "
235
+ f"rewritten references may belong to either file. Review the plan."
236
+ )
237
+
238
+ plan = build_plan(files, source, old_num, new_num)
239
+ for fp, lineno, old_line, new_line in plan:
240
+ print(f" {fp}:{lineno}: {old_line.strip()}")
241
+ print(f" -> {new_line.strip()}")
242
+ print(f" {len(plan)} line(s) to rewrite across {len(files)} ADR file(s).")
243
+
244
+ if not args.apply:
245
+ print("Dry run: no changes made. Re-run with --apply to execute.")
246
+ return 0
247
+
248
+ new_path = apply_plan(files, source, old_num, new_num)
249
+ print(f"Applied: {len(plan)} line(s) rewritten; renamed to {new_path}")
250
+ return 0
251
+
252
+
253
+ if __name__ == "__main__":
254
+ sys.exit(main())
package/bin/adr-retire CHANGED
File without changes
package/bin/adr-settings CHANGED
File without changes
package/bin/adr-status CHANGED
File without changes
package/bin/adr-suggest CHANGED
File without changes
package/bin/adr-watch CHANGED
File without changes
package/bin/bump-version CHANGED
File without changes