@rvdbreemen/adr-kit-opencode 0.52.0
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.
- package/.claude-plugin/plugin.json +29 -0
- package/LICENSE +21 -0
- package/README.md +850 -0
- package/bin/adr +1552 -0
- package/bin/adr-audit +454 -0
- package/bin/adr-context +584 -0
- package/bin/adr-discover +546 -0
- package/bin/adr-doctor +166 -0
- package/bin/adr-generate-scripts +421 -0
- package/bin/adr-grill-signal +131 -0
- package/bin/adr-guardian +1263 -0
- package/bin/adr-index +199 -0
- package/bin/adr-judge +2832 -0
- package/bin/adr-judge-precommit +87 -0
- package/bin/adr-lint +2087 -0
- package/bin/adr-mcp +1093 -0
- package/bin/adr-migrate +644 -0
- package/bin/adr-quality +275 -0
- package/bin/adr-readiness +211 -0
- package/bin/adr-readiness-ci +111 -0
- package/bin/adr-related +401 -0
- package/bin/adr-renumber +254 -0
- package/bin/adr-retire +467 -0
- package/bin/adr-settings +399 -0
- package/bin/adr-status +797 -0
- package/bin/adr-suggest +803 -0
- package/bin/adr-watch +674 -0
- package/bin/adr_catalog.py +536 -0
- package/bin/adr_config.py +280 -0
- package/bin/adr_doctor_checks.py +407 -0
- package/bin/adr_doctor_core.py +342 -0
- package/bin/adr_doctor_models.py +186 -0
- package/bin/adr_doctor_probes.py +216 -0
- package/bin/adr_format.py +786 -0
- package/bin/adr_grill_signal.py +123 -0
- package/bin/adr_guardian_queue.py +218 -0
- package/bin/adr_history_scan.py +278 -0
- package/bin/adr_index_core.py +443 -0
- package/bin/adr_llm.py +333 -0
- package/bin/adr_llm_judge_migration.py +314 -0
- package/bin/adr_quality_core.py +674 -0
- package/bin/adr_query.py +678 -0
- package/bin/adr_readiness.py +442 -0
- package/bin/adr_readiness_ci.py +123 -0
- package/bin/adr_regex.py +165 -0
- package/bin/adr_regex_worker.py +30 -0
- package/bin/adr_retrieval_health.py +385 -0
- package/bin/adr_schema.py +448 -0
- package/bin/adr_state.py +172 -0
- package/bin/bump-version +71 -0
- package/clients/workflows.json +229 -0
- package/hooks/__init__.py +1 -0
- package/hooks/adapters/__init__.py +13 -0
- package/hooks/adapters/claude.py +27 -0
- package/hooks/adapters/codex.py +26 -0
- package/hooks/adapters/copilot.py +11 -0
- package/hooks/adr-hook.py +128 -0
- package/hooks/adr_hook_core.py +843 -0
- package/hooks/adr_pr_guard.py +367 -0
- package/instructions/ADR-guide.md +48 -0
- package/instructions/adr.coding.md +82 -0
- package/instructions/adr.review.md +182 -0
- package/opencode/plugin.ts +451 -0
- package/package.json +41 -0
- package/schemas/adr-context-probes.schema.json +56 -0
- package/schemas/adr-enforcement.schema.json +57 -0
- package/schemas/adr-frontmatter.schema.json +144 -0
- package/schemas/adr-index.schema.json +276 -0
- package/schemas/adr-kit-config.schema.json +371 -0
- package/schemas/adr-readiness.schema.json +41 -0
- package/schemas/client-capabilities.schema.json +503 -0
- package/schemas/client-certification.schema.json +101 -0
- package/schemas/doctor-output.schema.json +92 -0
- package/schemas/marketplace.json.schema.json +70 -0
- package/schemas/plugin.json.schema.json +67 -0
- package/scripts/adr_settings.py +239 -0
- package/scripts/benchmark-adr-grilling.py +323 -0
- package/scripts/benchmark-client-generation.py +178 -0
- package/scripts/build-client-adapters.py +139 -0
- package/scripts/bump-version.py +304 -0
- package/scripts/check-branch-sync.py +243 -0
- package/scripts/check-release-version.py +81 -0
- package/scripts/client_certification.py +153 -0
- package/scripts/client_evidence.py +280 -0
- package/scripts/client_generation.py +288 -0
- package/scripts/client_generation_artifacts.py +351 -0
- package/scripts/client_generation_model.py +173 -0
- package/scripts/client_generation_state.py +260 -0
- package/scripts/client_support_matrix.py +360 -0
- package/scripts/install-agent-envs.py +300 -0
- package/scripts/probe-client-events.py +183 -0
- package/scripts/project_setup.py +379 -0
- package/scripts/refresh-otgw-corpus.py +219 -0
- package/scripts/settings.py +81 -0
- package/scripts/setup-project.py +205 -0
- package/scripts/sync-agent-plugins.py +17 -0
- package/scripts/version_sites.py +377 -0
- package/skills/adr/SKILL.md +780 -0
- package/skills/audit/SKILL.md +103 -0
- package/skills/context/SKILL.md +77 -0
- package/skills/grill/SKILL.md +84 -0
- package/skills/grill/agents/openai.yaml +4 -0
- package/skills/guardian/SKILL.md +316 -0
- package/skills/init/SKILL.md +499 -0
- package/skills/install-hooks/SKILL.md +154 -0
- package/skills/judge/SKILL.md +168 -0
- package/skills/lint/SKILL.md +321 -0
- package/skills/migrate/SKILL.md +313 -0
- package/skills/related/SKILL.md +62 -0
- package/skills/retire/SKILL.md +41 -0
- package/skills/review/SKILL.md +167 -0
- package/skills/settings/SKILL.md +73 -0
- package/skills/setup/SKILL.md +128 -0
- package/skills/supersede/SKILL.md +136 -0
- package/skills/upgrade/SKILL.md +273 -0
- package/templates/adr-kit-guide.md +354 -0
- package/templates/adr-template.canonical.md +115 -0
- package/templates/adr-template.madr.md +131 -0
- package/templates/adr-template.md +131 -0
- package/templates/adr-template.nygard.md +111 -0
- package/templates/cc-settings/guardian-hook-entry.json +9 -0
- package/templates/githooks/pre-commit +337 -0
- package/templates/github-workflows/adr-audit.yml +58 -0
- package/templates/github-workflows/adr-guardian-audit.yml +133 -0
- package/templates/github-workflows/adr-index-check.yml +30 -0
- package/templates/github-workflows/adr-judge.yml +31 -0
- package/templates/github-workflows/adr-readiness.yml +18 -0
- package/templates/validate_adr_template.py +38 -0
- package/templates/validate_adr_template.sh +74 -0
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""Refresh the frozen OTGW-firmware ADR compatibility corpus.
|
|
3
|
+
|
|
4
|
+
Only numbered ADR Markdown files and the source repository license are copied.
|
|
5
|
+
The adjacent checkout is never needed by the tests themselves.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
import argparse
|
|
11
|
+
import hashlib
|
|
12
|
+
import json
|
|
13
|
+
import re
|
|
14
|
+
import shutil
|
|
15
|
+
import subprocess
|
|
16
|
+
import sys
|
|
17
|
+
from collections import Counter
|
|
18
|
+
from datetime import date
|
|
19
|
+
from pathlib import Path
|
|
20
|
+
from typing import Dict, List
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
ROOT = Path(__file__).resolve().parent.parent
|
|
24
|
+
TARGET = ROOT / "tests" / "testsets" / "otgw-firmware"
|
|
25
|
+
ADR_NAME_RE = re.compile(r"^ADR-\d{3,4}-.*\.md$", re.IGNORECASE)
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def _git(source: Path, *args: str) -> str:
|
|
29
|
+
result = subprocess.run(
|
|
30
|
+
["git", "-C", str(source), *args],
|
|
31
|
+
capture_output=True,
|
|
32
|
+
text=True,
|
|
33
|
+
encoding="utf-8",
|
|
34
|
+
errors="replace",
|
|
35
|
+
check=False,
|
|
36
|
+
)
|
|
37
|
+
if result.returncode != 0:
|
|
38
|
+
raise RuntimeError(result.stderr.strip() or "git command failed")
|
|
39
|
+
return result.stdout.strip()
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def _json_command(*args: str) -> tuple[int, Dict]:
|
|
43
|
+
result = subprocess.run(
|
|
44
|
+
[sys.executable, *args],
|
|
45
|
+
capture_output=True,
|
|
46
|
+
text=True,
|
|
47
|
+
encoding="utf-8",
|
|
48
|
+
errors="replace",
|
|
49
|
+
check=False,
|
|
50
|
+
cwd=str(ROOT),
|
|
51
|
+
)
|
|
52
|
+
try:
|
|
53
|
+
payload = json.loads(result.stdout)
|
|
54
|
+
except json.JSONDecodeError as exc:
|
|
55
|
+
raise RuntimeError(
|
|
56
|
+
f"command produced invalid JSON: {' '.join(args)}\n{result.stderr}"
|
|
57
|
+
) from exc
|
|
58
|
+
return result.returncode, payload
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
def _sha256(path: Path) -> str:
|
|
62
|
+
digest = hashlib.sha256()
|
|
63
|
+
with path.open("rb") as handle:
|
|
64
|
+
for chunk in iter(lambda: handle.read(1024 * 1024), b""):
|
|
65
|
+
digest.update(chunk)
|
|
66
|
+
return digest.hexdigest()
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
def _numbered_adr_changes(source: Path) -> List[str]:
|
|
70
|
+
status = _git(source, "status", "--porcelain", "--", "docs/adr")
|
|
71
|
+
changes: List[str] = []
|
|
72
|
+
for line in status.splitlines():
|
|
73
|
+
normalized = line.replace("\\", "/")
|
|
74
|
+
name = normalized.rsplit("/", 1)[-1].strip('"')
|
|
75
|
+
if ADR_NAME_RE.match(name):
|
|
76
|
+
changes.append(line)
|
|
77
|
+
return changes
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
def refresh(source: Path) -> Dict:
|
|
81
|
+
source = source.resolve()
|
|
82
|
+
source_adrs = source / "docs" / "adr"
|
|
83
|
+
source_license = source / "LICENSE"
|
|
84
|
+
if not source_adrs.is_dir() or not source_license.is_file():
|
|
85
|
+
raise RuntimeError(
|
|
86
|
+
f"{source} is not an OTGW-firmware checkout with docs/adr and LICENSE"
|
|
87
|
+
)
|
|
88
|
+
|
|
89
|
+
dirty_adrs = _numbered_adr_changes(source)
|
|
90
|
+
if dirty_adrs:
|
|
91
|
+
raise RuntimeError(
|
|
92
|
+
"refusing to snapshot modified/untracked numbered ADRs:\n"
|
|
93
|
+
+ "\n".join(dirty_adrs)
|
|
94
|
+
)
|
|
95
|
+
|
|
96
|
+
source_files = sorted(
|
|
97
|
+
(
|
|
98
|
+
path
|
|
99
|
+
for path in source_adrs.iterdir()
|
|
100
|
+
if path.is_file() and ADR_NAME_RE.match(path.name)
|
|
101
|
+
),
|
|
102
|
+
key=lambda path: path.name.casefold(),
|
|
103
|
+
)
|
|
104
|
+
if not source_files:
|
|
105
|
+
raise RuntimeError(f"no numbered ADR files found in {source_adrs}")
|
|
106
|
+
|
|
107
|
+
target_adrs = TARGET / "adrs"
|
|
108
|
+
target_adrs.mkdir(parents=True, exist_ok=True)
|
|
109
|
+
expected_names = {path.name for path in source_files}
|
|
110
|
+
for stale in target_adrs.iterdir():
|
|
111
|
+
if stale.is_file() and ADR_NAME_RE.match(stale.name):
|
|
112
|
+
if stale.name not in expected_names:
|
|
113
|
+
stale.unlink()
|
|
114
|
+
for source_file in source_files:
|
|
115
|
+
shutil.copyfile(source_file, target_adrs / source_file.name)
|
|
116
|
+
shutil.copyfile(source_license, TARGET / "LICENSE")
|
|
117
|
+
|
|
118
|
+
plan_code, plan = _json_command(
|
|
119
|
+
str(ROOT / "bin" / "adr-migrate"),
|
|
120
|
+
"--plan",
|
|
121
|
+
"--format",
|
|
122
|
+
"json",
|
|
123
|
+
str(target_adrs),
|
|
124
|
+
)
|
|
125
|
+
if plan_code != 0:
|
|
126
|
+
raise RuntimeError("migration planner failed for the copied corpus")
|
|
127
|
+
dry_run_code, dry_run = _json_command(
|
|
128
|
+
str(ROOT / "bin" / "adr-migrate"),
|
|
129
|
+
"--dry-run",
|
|
130
|
+
"--format",
|
|
131
|
+
"json",
|
|
132
|
+
str(target_adrs),
|
|
133
|
+
)
|
|
134
|
+
|
|
135
|
+
file_entries = [
|
|
136
|
+
{
|
|
137
|
+
"path": f"adrs/{path.name}",
|
|
138
|
+
"bytes": path.stat().st_size,
|
|
139
|
+
"sha256": _sha256(path),
|
|
140
|
+
}
|
|
141
|
+
for path in sorted(target_adrs.iterdir(), key=lambda item: item.name.casefold())
|
|
142
|
+
if path.is_file() and ADR_NAME_RE.match(path.name)
|
|
143
|
+
]
|
|
144
|
+
format_counts = Counter(
|
|
145
|
+
item["detected_format"] for item in plan.get("files", [])
|
|
146
|
+
)
|
|
147
|
+
action_counts = Counter(item["action"] for item in plan.get("files", []))
|
|
148
|
+
|
|
149
|
+
manifest = {
|
|
150
|
+
"schema_version": 1,
|
|
151
|
+
"corpus": "otgw-firmware-adrs",
|
|
152
|
+
"captured_on": date.today().isoformat(),
|
|
153
|
+
"license": "GPL-3.0-only",
|
|
154
|
+
"source": {
|
|
155
|
+
"repository_url": _git(source, "remote", "get-url", "origin"),
|
|
156
|
+
"revision": _git(source, "rev-parse", "HEAD"),
|
|
157
|
+
"adr_tree_revision": _git(
|
|
158
|
+
source,
|
|
159
|
+
"log",
|
|
160
|
+
"-1",
|
|
161
|
+
"--format=%H",
|
|
162
|
+
"--",
|
|
163
|
+
"docs/adr",
|
|
164
|
+
),
|
|
165
|
+
"path": "docs/adr",
|
|
166
|
+
"numbered_adrs_clean": True,
|
|
167
|
+
},
|
|
168
|
+
"baseline": {
|
|
169
|
+
"file_count": len(file_entries),
|
|
170
|
+
"total_bytes": sum(item["bytes"] for item in file_entries),
|
|
171
|
+
"migration_plan": {
|
|
172
|
+
"format_counts": dict(sorted(format_counts.items())),
|
|
173
|
+
"action_counts": dict(sorted(action_counts.items())),
|
|
174
|
+
"deterministic": plan["summary"]["deterministic"],
|
|
175
|
+
"guided": plan["summary"]["guided"],
|
|
176
|
+
"notices": plan["summary"]["notices"],
|
|
177
|
+
},
|
|
178
|
+
"metadata_dry_run": {
|
|
179
|
+
"exit_code": dry_run_code,
|
|
180
|
+
"changed": dry_run["summary"]["changed"],
|
|
181
|
+
"failed": dry_run["summary"]["failed"],
|
|
182
|
+
},
|
|
183
|
+
},
|
|
184
|
+
"files": file_entries,
|
|
185
|
+
}
|
|
186
|
+
(TARGET / "manifest.json").write_text(
|
|
187
|
+
json.dumps(manifest, indent=2, ensure_ascii=False) + "\n",
|
|
188
|
+
encoding="utf-8",
|
|
189
|
+
)
|
|
190
|
+
return manifest
|
|
191
|
+
|
|
192
|
+
|
|
193
|
+
def main() -> int:
|
|
194
|
+
parser = argparse.ArgumentParser(
|
|
195
|
+
description="Refresh the frozen OTGW-firmware ADR test corpus."
|
|
196
|
+
)
|
|
197
|
+
parser.add_argument(
|
|
198
|
+
"--source",
|
|
199
|
+
default=str(ROOT.parent / "OTGW-firmware"),
|
|
200
|
+
help="Path to the OTGW-firmware checkout (default: ../OTGW-firmware).",
|
|
201
|
+
)
|
|
202
|
+
args = parser.parse_args()
|
|
203
|
+
try:
|
|
204
|
+
manifest = refresh(Path(args.source))
|
|
205
|
+
except RuntimeError as exc:
|
|
206
|
+
print(f"refresh-otgw-corpus: {exc}", file=sys.stderr)
|
|
207
|
+
return 2
|
|
208
|
+
baseline = manifest["baseline"]
|
|
209
|
+
print(
|
|
210
|
+
"refreshed OTGW ADR corpus: "
|
|
211
|
+
f"{baseline['file_count']} files, "
|
|
212
|
+
f"{baseline['total_bytes']} bytes, "
|
|
213
|
+
f"revision {manifest['source']['revision']}"
|
|
214
|
+
)
|
|
215
|
+
return 0
|
|
216
|
+
|
|
217
|
+
|
|
218
|
+
if __name__ == "__main__":
|
|
219
|
+
raise SystemExit(main())
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""CLI for ADR Kit global defaults and per-project overrides."""
|
|
3
|
+
|
|
4
|
+
from __future__ import annotations
|
|
5
|
+
|
|
6
|
+
import argparse
|
|
7
|
+
import json
|
|
8
|
+
import sys
|
|
9
|
+
from pathlib import Path
|
|
10
|
+
|
|
11
|
+
from adr_settings import (
|
|
12
|
+
SettingsError,
|
|
13
|
+
parse_cli_value,
|
|
14
|
+
resolve_settings,
|
|
15
|
+
write_setting,
|
|
16
|
+
)
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def _parser() -> argparse.ArgumentParser:
|
|
20
|
+
parser = argparse.ArgumentParser(prog="adr-kit:settings")
|
|
21
|
+
parser.add_argument("--project-root", type=Path, default=Path.cwd())
|
|
22
|
+
parser.add_argument("--global-settings", type=Path)
|
|
23
|
+
parser.add_argument("--format", choices=("human", "json"), default="human")
|
|
24
|
+
subparsers = parser.add_subparsers(dest="command")
|
|
25
|
+
subparsers.add_parser("show")
|
|
26
|
+
setter = subparsers.add_parser("set")
|
|
27
|
+
setter.add_argument("key")
|
|
28
|
+
setter.add_argument("value")
|
|
29
|
+
setter.add_argument("--scope", choices=("global", "project"), default="project")
|
|
30
|
+
unsetter = subparsers.add_parser("unset")
|
|
31
|
+
unsetter.add_argument("key")
|
|
32
|
+
unsetter.add_argument(
|
|
33
|
+
"--scope", choices=("global", "project"), default="project"
|
|
34
|
+
)
|
|
35
|
+
return parser
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def _render_human(payload: dict) -> str:
|
|
39
|
+
lines = ["ADR Kit effective settings:"]
|
|
40
|
+
for entry in payload["entries"]:
|
|
41
|
+
value = json.dumps(entry["value"], ensure_ascii=False)
|
|
42
|
+
lines.append(f" {entry['key']} = {value} ({entry['source']})")
|
|
43
|
+
return "\n".join(lines)
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def main(argv: list[str] | None = None) -> int:
|
|
47
|
+
args = _parser().parse_args(argv)
|
|
48
|
+
command = args.command or "show"
|
|
49
|
+
root = args.project_root.resolve()
|
|
50
|
+
try:
|
|
51
|
+
if command == "set":
|
|
52
|
+
write_setting(
|
|
53
|
+
root,
|
|
54
|
+
args.scope,
|
|
55
|
+
args.key,
|
|
56
|
+
parse_cli_value(args.value),
|
|
57
|
+
global_path=args.global_settings,
|
|
58
|
+
)
|
|
59
|
+
elif command == "unset":
|
|
60
|
+
write_setting(
|
|
61
|
+
root,
|
|
62
|
+
args.scope,
|
|
63
|
+
args.key,
|
|
64
|
+
unset=True,
|
|
65
|
+
global_path=args.global_settings,
|
|
66
|
+
)
|
|
67
|
+
resolved = resolve_settings(root, global_path=args.global_settings)
|
|
68
|
+
except SettingsError as exc:
|
|
69
|
+
print(f"adr-kit:settings: {exc}", file=sys.stderr)
|
|
70
|
+
return 2
|
|
71
|
+
|
|
72
|
+
payload = dict(resolved)
|
|
73
|
+
if args.format == "json":
|
|
74
|
+
print(json.dumps(payload, indent=2, sort_keys=True))
|
|
75
|
+
else:
|
|
76
|
+
print(_render_human(payload))
|
|
77
|
+
return 0
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
if __name__ == "__main__":
|
|
81
|
+
raise SystemExit(main())
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""Install ADR Kit's generated guide, managed pointers, and pre-commit gate."""
|
|
3
|
+
|
|
4
|
+
from __future__ import annotations
|
|
5
|
+
|
|
6
|
+
import argparse
|
|
7
|
+
import json
|
|
8
|
+
import sys
|
|
9
|
+
from pathlib import Path
|
|
10
|
+
|
|
11
|
+
def _use_utf8_output() -> None:
|
|
12
|
+
"""Print the diff as UTF-8, whatever the console claims to be.
|
|
13
|
+
|
|
14
|
+
A dry run against this repository crashed with `UnicodeEncodeError` on
|
|
15
|
+
U+2192 in the rendered diff, after four change lines had already been
|
|
16
|
+
printed -- so the user saw a traceback where the summary belonged and could
|
|
17
|
+
reasonably conclude the run had half-applied. On Windows the default console
|
|
18
|
+
encoding is cp1252, and instruction text legitimately contains arrows, dashes
|
|
19
|
+
and quotation marks it cannot represent.
|
|
20
|
+
|
|
21
|
+
`errors="replace"` on stderr rather than a hard failure: a diagnostic line
|
|
22
|
+
losing one glyph is better than a diagnostic line raising.
|
|
23
|
+
"""
|
|
24
|
+
for stream, kwargs in (
|
|
25
|
+
(sys.stdout, {"encoding": "utf-8"}),
|
|
26
|
+
(sys.stderr, {"encoding": "utf-8", "errors": "replace"}),
|
|
27
|
+
):
|
|
28
|
+
if hasattr(stream, "reconfigure"):
|
|
29
|
+
try:
|
|
30
|
+
stream.reconfigure(**kwargs)
|
|
31
|
+
except (ValueError, OSError):
|
|
32
|
+
# A detached or non-seekable stream; the default encoding stays.
|
|
33
|
+
pass
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
_use_utf8_output()
|
|
37
|
+
|
|
38
|
+
from adr_settings import SettingsError, resolve_settings
|
|
39
|
+
from project_setup import (
|
|
40
|
+
SetupError,
|
|
41
|
+
apply_changes,
|
|
42
|
+
collect_changes,
|
|
43
|
+
render_diff,
|
|
44
|
+
)
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
CLIENT_ALIASES = {
|
|
48
|
+
"claude-code-cli": "claude",
|
|
49
|
+
"codex-cli": "codex",
|
|
50
|
+
"github-copilot-cli": "copilot",
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def _parser() -> argparse.ArgumentParser:
|
|
55
|
+
parser = argparse.ArgumentParser(prog="adr-kit:setup")
|
|
56
|
+
parser.add_argument(
|
|
57
|
+
"workspace",
|
|
58
|
+
nargs="?",
|
|
59
|
+
type=Path,
|
|
60
|
+
default=None,
|
|
61
|
+
help="Project to set up. Equivalent to --project-root; accepted "
|
|
62
|
+
"positionally because that is the form the setup skills documented.",
|
|
63
|
+
)
|
|
64
|
+
parser.add_argument("--project-root", type=Path, default=None)
|
|
65
|
+
parser.add_argument(
|
|
66
|
+
"--plugin-root",
|
|
67
|
+
type=Path,
|
|
68
|
+
default=Path(__file__).resolve().parents[1],
|
|
69
|
+
)
|
|
70
|
+
parser.add_argument(
|
|
71
|
+
"--clients",
|
|
72
|
+
default=None,
|
|
73
|
+
help="Comma-separated selected native clients: claude, codex, copilot. "
|
|
74
|
+
"Full client ids such as codex-cli are accepted and normalised.",
|
|
75
|
+
)
|
|
76
|
+
parser.add_argument(
|
|
77
|
+
"--client",
|
|
78
|
+
default=None,
|
|
79
|
+
help="Alias for --clients, singular. Accepts a short name or a full "
|
|
80
|
+
"client id.",
|
|
81
|
+
)
|
|
82
|
+
parser.add_argument("--global-settings", type=Path)
|
|
83
|
+
parser.add_argument("--dry-run", action="store_true")
|
|
84
|
+
parser.add_argument(
|
|
85
|
+
"--no-pre-commit", action="store_true",
|
|
86
|
+
help="Leave .githooks/pre-commit exactly as it is: do not install one, "
|
|
87
|
+
"and do not remove one. Use this on a project that manages its git "
|
|
88
|
+
"hooks another way.",
|
|
89
|
+
)
|
|
90
|
+
parser.add_argument(
|
|
91
|
+
"--remove-pre-commit", action="store_true",
|
|
92
|
+
help="Remove adr-kit's pre-commit hook. Only ever removes a hook this "
|
|
93
|
+
"kit wrote; a foreign hook is left alone.",
|
|
94
|
+
)
|
|
95
|
+
parser.add_argument("--format", choices=("human", "json"), default="human")
|
|
96
|
+
return parser
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
def _selected_clients(raw: str | None) -> list[str]:
|
|
100
|
+
"""Normalise whatever the caller wrote into the short names settings use.
|
|
101
|
+
|
|
102
|
+
Both spellings reach this command from real callers: the settings surface
|
|
103
|
+
and this script's own default use `claude`/`codex`/`copilot`, while every
|
|
104
|
+
skill and workflow that names a client elsewhere uses the full ids from
|
|
105
|
+
`clients/capabilities.json`. Accepting one and failing on the other with a
|
|
106
|
+
`KeyError` -- which is what shipped -- means the documented invocation dies
|
|
107
|
+
on a dictionary lookup after argparse has already accepted it.
|
|
108
|
+
"""
|
|
109
|
+
if raw is None:
|
|
110
|
+
raw = "claude,codex,copilot"
|
|
111
|
+
selected = []
|
|
112
|
+
for item in raw.split(","):
|
|
113
|
+
name = item.strip()
|
|
114
|
+
if not name:
|
|
115
|
+
continue
|
|
116
|
+
name = CLIENT_ALIASES.get(name, name)
|
|
117
|
+
if name not in ("claude", "codex", "copilot"):
|
|
118
|
+
raise SystemExit(
|
|
119
|
+
f"adr-kit:setup: unknown client {item.strip()!r}; expected one "
|
|
120
|
+
f"of claude, codex, copilot (or the full ids "
|
|
121
|
+
f"{', '.join(sorted(CLIENT_ALIASES))})"
|
|
122
|
+
)
|
|
123
|
+
if name not in selected:
|
|
124
|
+
selected.append(name)
|
|
125
|
+
return selected
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
def main(argv: list[str] | None = None) -> int:
|
|
129
|
+
args = _parser().parse_args(argv)
|
|
130
|
+
if args.client and args.clients:
|
|
131
|
+
raise SystemExit(
|
|
132
|
+
"adr-kit:setup: pass --client or --clients, not both; they mean "
|
|
133
|
+
"the same thing"
|
|
134
|
+
)
|
|
135
|
+
if args.workspace and args.project_root and args.workspace != args.project_root:
|
|
136
|
+
raise SystemExit(
|
|
137
|
+
"adr-kit:setup: the positional workspace and --project-root "
|
|
138
|
+
"disagree; pass one"
|
|
139
|
+
)
|
|
140
|
+
root = (args.project_root or args.workspace or Path.cwd()).resolve()
|
|
141
|
+
clients = _selected_clients(args.client or args.clients)
|
|
142
|
+
try:
|
|
143
|
+
effective = resolve_settings(root, global_path=args.global_settings)
|
|
144
|
+
clients = [
|
|
145
|
+
client
|
|
146
|
+
for client in clients
|
|
147
|
+
if effective["values"]["clients"][client]["enabled"] is not False
|
|
148
|
+
]
|
|
149
|
+
# Three states, not two. `--no-pre-commit` used to mean "remove the
|
|
150
|
+
# hook", which is a destructive act behind a name that promises a
|
|
151
|
+
# non-act: a project using husky or a hand-written hook lost it to a
|
|
152
|
+
# flag that reads as "leave things alone". Skipping is now expressible
|
|
153
|
+
# and is what that name does; removal has its own name.
|
|
154
|
+
if args.no_pre_commit and args.remove_pre_commit:
|
|
155
|
+
raise SystemExit(
|
|
156
|
+
"adr-kit:setup: --no-pre-commit leaves the hook alone and "
|
|
157
|
+
"--remove-pre-commit deletes it; pass one"
|
|
158
|
+
)
|
|
159
|
+
pre_commit = (
|
|
160
|
+
effective["values"]["pre_commit"]["enabled"]
|
|
161
|
+
and not args.remove_pre_commit
|
|
162
|
+
)
|
|
163
|
+
changes, configure_hooks_path = collect_changes(
|
|
164
|
+
root,
|
|
165
|
+
args.plugin_root.resolve(),
|
|
166
|
+
clients,
|
|
167
|
+
pre_commit_enabled=pre_commit,
|
|
168
|
+
touch_pre_commit=not args.no_pre_commit,
|
|
169
|
+
)
|
|
170
|
+
diff = render_diff(changes, root)
|
|
171
|
+
if not args.dry_run:
|
|
172
|
+
apply_changes(
|
|
173
|
+
root,
|
|
174
|
+
changes,
|
|
175
|
+
configure_hooks_path=configure_hooks_path,
|
|
176
|
+
)
|
|
177
|
+
except (KeyError, SettingsError, SetupError) as exc:
|
|
178
|
+
print(f"adr-kit:setup: {exc}", file=sys.stderr)
|
|
179
|
+
return 2
|
|
180
|
+
|
|
181
|
+
payload = {
|
|
182
|
+
"dry_run": args.dry_run,
|
|
183
|
+
"clients": clients,
|
|
184
|
+
"pre_commit_enabled": pre_commit,
|
|
185
|
+
"configure_hooks_path": configure_hooks_path,
|
|
186
|
+
"changes": [
|
|
187
|
+
{"path": str(change.path.relative_to(root)), "action": change.action}
|
|
188
|
+
for change in changes
|
|
189
|
+
],
|
|
190
|
+
"diff": diff,
|
|
191
|
+
}
|
|
192
|
+
if args.format == "json":
|
|
193
|
+
print(json.dumps(payload, indent=2, sort_keys=True))
|
|
194
|
+
else:
|
|
195
|
+
for change in payload["changes"]:
|
|
196
|
+
print(f"{change['action']}: {change['path']}")
|
|
197
|
+
if not payload["changes"]:
|
|
198
|
+
print("ADR Kit project setup is already current.")
|
|
199
|
+
if args.dry_run and diff:
|
|
200
|
+
print(diff, end="" if diff.endswith("\n") else "\n")
|
|
201
|
+
return 0
|
|
202
|
+
|
|
203
|
+
|
|
204
|
+
if __name__ == "__main__":
|
|
205
|
+
raise SystemExit(main())
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""Compatibility entrypoint for the bounded client artifact generator."""
|
|
3
|
+
|
|
4
|
+
from __future__ import annotations
|
|
5
|
+
|
|
6
|
+
import runpy
|
|
7
|
+
from pathlib import Path
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def comparison_bytes(path: Path) -> bytes:
|
|
11
|
+
"""Normalize checkout EOLs for compatibility with existing callers."""
|
|
12
|
+
return path.read_bytes().replace(b"\r\n", b"\n")
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
if __name__ == "__main__":
|
|
16
|
+
target = Path(__file__).with_name("build-client-adapters.py")
|
|
17
|
+
runpy.run_path(str(target), run_name="__main__")
|