-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdev
More file actions
executable file
·214 lines (187 loc) · 7.35 KB
/
Copy pathdev
File metadata and controls
executable file
·214 lines (187 loc) · 7.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
#!/usr/bin/env python3
"""Stable contributor commands for Deixic Code."""
from __future__ import annotations
import argparse
import json
import os
from pathlib import Path
import shutil
import subprocess
import sys
MAESTRO_ROOT = Path(__file__).resolve().parent
MONO_ROOT = (
MAESTRO_ROOT.parents[1]
if MAESTRO_ROOT.parent.name == "products"
else MAESTRO_ROOT
)
WORKBENCH = MAESTRO_ROOT / "scripts/dev/ui-workbench.py"
def cargo_preview(*args: str, stdin: bytes | None = None) -> int:
command = [
"cargo",
"run",
"--quiet",
"--locked",
"-p",
"maestro-ui-preview",
"--",
*args,
]
return subprocess.run(command, cwd=MAESTRO_ROOT, input=stdin).returncode
def cargo_onboarding(mode: str, body: bytes) -> int:
command = [
"cargo",
"run",
"--quiet",
"--locked",
"-p",
"maestro-tui",
"--example",
"onboarding-preview",
"--",
mode,
]
return subprocess.run(command, cwd=MAESTRO_ROOT, input=body).returncode
def read_receipt(path: str) -> tuple[bytes, str]:
receipt = Path(path)
if receipt.stat().st_size > 1_048_576:
raise ValueError("receipt exceeds 1048576 bytes")
body = receipt.read_bytes()
value = json.loads(body)
if not isinstance(value, dict) or not isinstance(value.get("schema"), str):
raise ValueError("receipt must be a versioned wire envelope")
return body, value["schema"]
def changed_review_filter() -> list[str]:
if MONO_ROOT == MAESTRO_ROOT or not (MONO_ROOT / ".git").exists():
return []
base = subprocess.run(
["git", "merge-base", "origin/main", "HEAD"],
cwd=MONO_ROOT,
capture_output=True,
text=True,
check=True,
).stdout.strip()
paths = subprocess.run(
["git", "diff", "--name-only", base, "HEAD", "--", "products/maestro"],
cwd=MONO_ROOT,
capture_output=True,
text=True,
check=True,
).stdout.splitlines()
visual = [path for path in paths if "/packages/ui-preview-rs/" in path]
if visual and len(visual) == len(paths):
return ["--components-only", "--adapter", "shared-menu"]
return []
def doctor(as_json: bool) -> int:
tools = {name: shutil.which(name) for name in ("cargo", "python3", "rustfmt")}
required_paths = [
MAESTRO_ROOT / "Cargo.toml",
MAESTRO_ROOT / "packages/ui-preview-rs/Cargo.toml",
WORKBENCH,
]
missing = [str(path) for path in required_paths if not path.is_file()]
ready = tools["cargo"] is not None and tools["python3"] is not None and not missing
report = {
"status": "ready" if ready else "blocked",
"maestro_root": str(MAESTRO_ROOT),
"repository_root": str(MONO_ROOT),
"layout": "mono" if MONO_ROOT != MAESTRO_ROOT else "public",
"tools": tools,
"missing": missing,
}
if as_json:
print(json.dumps(report, indent=2, sort_keys=True))
else:
print(f"Maestro UI development: {report['status']}")
print(f"Layout: {report['layout']} ({MAESTRO_ROOT})")
for name, path in tools.items():
print(f"{name}: {path or 'missing'}")
for path in missing:
print(f"missing: {path}")
return 0 if ready else 2
def build_parser() -> argparse.ArgumentParser:
parser = argparse.ArgumentParser(prog="./dev", description=__doc__)
top = parser.add_subparsers(dest="area", required=True)
ui = top.add_parser("ui", help="design, inspect, replay, and review native UI stories")
commands = ui.add_subparsers(dest="command")
commands.add_parser("list", help="list registered stories and cases")
new = commands.add_parser("new", help="plan or create an adapter-owned story")
new.add_argument("story")
new.add_argument("--adapter", default="shared-menu")
new.add_argument("--check", action="store_true")
check = commands.add_parser("check", help="render one story and evaluate its contract")
check.add_argument("story")
check.add_argument("--require-contract", action="store_true")
inspect = commands.add_parser("inspect", help="show owner, source, cases, and exact commands")
inspect.add_argument("story")
inspect.add_argument("--json", action="store_true", help="reserved; output is always JSON")
replay = commands.add_parser("replay", help="replay a portable menu or theme receipt")
replay.add_argument("receipt")
migrate = commands.add_parser("migrate", help="migrate a versioned recipe, replay, or contract")
migrate.add_argument("receipt")
migrate.add_argument("--check", action="store_true")
review = commands.add_parser("review", help="open the live production-renderer workbench")
review.add_argument("--story")
review.add_argument("--adapter")
review.add_argument("--components-only", action="store_true")
review.add_argument("--changed", action="store_true")
review.add_argument("--port", type=int, default=8770)
doctor_parser = commands.add_parser("doctor", help="check the local UI toolchain and layout")
doctor_parser.add_argument("--json", action="store_true")
return parser
def main(argv: list[str] | None = None) -> int:
parser = build_parser()
args = parser.parse_args(argv)
if args.area != "ui":
parser.error("unknown development area")
command = args.command or "review"
if command == "list":
return cargo_preview("--list")
if command == "new":
tail = ["studio", "new", "--adapter", args.adapter, args.story]
if args.check:
tail.append("--check")
return cargo_preview(*tail)
if command == "check":
tail = ["studio", "verify", args.story]
if args.require_contract:
tail.append("--require-contract")
return cargo_preview(*tail)
if command == "inspect":
return cargo_preview("studio", "inspect", args.story)
if command == "migrate":
tail = ["studio", "migrate", args.receipt]
if args.check:
tail.append("--check")
return cargo_preview(*tail)
if command == "replay":
try:
body, schema = read_receipt(args.receipt)
except (OSError, ValueError, json.JSONDecodeError) as error:
print(error, file=sys.stderr)
return 2
if schema == "maestro.ui.menu-recipe":
return cargo_onboarding("--studio-stdin", body)
if schema == "maestro.ui.theme-replay":
return cargo_onboarding("--replay-stdin", body)
print(f"unsupported replay schema: {schema}", file=sys.stderr)
return 2
if command == "doctor":
return doctor(args.json)
if command == "review":
port = getattr(args, "port", 8770)
story = getattr(args, "story", None)
adapter = getattr(args, "adapter", None)
tail = [sys.executable, str(WORKBENCH), "--port", str(port)]
if getattr(args, "changed", False):
tail.extend(changed_review_filter())
elif getattr(args, "components_only", False):
tail.append("--components-only")
if story:
tail.extend(["--story", story])
if adapter:
tail.extend(["--adapter", adapter])
return subprocess.run(tail, cwd=MAESTRO_ROOT).returncode
parser.error(f"unknown ui command: {command}")
return 2
if __name__ == "__main__":
raise SystemExit(main())