sdtk-spec-kit 0.10.0 → 0.12.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/README.md +1 -1
- package/assets/manifest/toolkit-bundle.manifest.json +207 -47
- package/assets/manifest/toolkit-bundle.sha256.txt +54 -22
- package/assets/toolkit/toolkit/AGENTS.md +2 -1
- package/assets/toolkit/toolkit/SDTK_TOOLKIT.md +5 -1
- package/assets/toolkit/toolkit/runtimes/claude/CLAUDE_TEMPLATE.md +4 -0
- package/assets/toolkit/toolkit/scripts/install-claude-skills.ps1 +18 -0
- package/assets/toolkit/toolkit/scripts/install-codex-skills.ps1 +1 -0
- package/assets/toolkit/toolkit/skills/sdtk-arch/SKILL.md +2 -2
- package/assets/toolkit/toolkit/skills/sdtk-ba/SKILL.md +2 -2
- package/assets/toolkit/toolkit/skills/sdtk-customer-qa-sheet/SKILL.md +117 -0
- package/assets/toolkit/toolkit/skills/sdtk-customer-qa-sheet/references/PROFILE_TEMPLATE.md +60 -0
- package/assets/toolkit/toolkit/skills/sdtk-customer-qa-sheet/scripts/oq_sync.py +349 -0
- package/assets/toolkit/toolkit/skills/sdtk-customer-qa-sheet/scripts/test_oq_sync.py +175 -0
- package/assets/toolkit/toolkit/skills/sdtk-db-design/SKILL.md +130 -0
- package/assets/toolkit/toolkit/skills/sdtk-db-design/references/REVIEW_PROCESS.md +82 -0
- package/assets/toolkit/toolkit/skills/sdtk-pm/SKILL.md +1 -1
- package/assets/toolkit/toolkit/skills/sdtk-screen-design-xlsx/SKILL.md +104 -0
- package/assets/toolkit/toolkit/skills/sdtk-screen-design-xlsx/references/REVIEW_AND_MISTAKES.md +63 -0
- package/assets/toolkit/toolkit/skills/sdtk-screen-design-xlsx/references/SCR01.json +46 -0
- package/assets/toolkit/toolkit/skills/sdtk-screen-design-xlsx/references/SCR01.png +0 -0
- package/assets/toolkit/toolkit/skills/sdtk-screen-design-xlsx/references/SPEC_SCHEMA.md +208 -0
- package/assets/toolkit/toolkit/skills/sdtk-screen-design-xlsx/references/example_spec.yaml +115 -0
- package/assets/toolkit/toolkit/skills/sdtk-screen-design-xlsx/scripts/build_design_xlsx.py +550 -0
- package/assets/toolkit/toolkit/skills/sdtk-screen-design-xlsx/scripts/design_spec.py +305 -0
- package/assets/toolkit/toolkit/skills/sdtk-screen-design-xlsx/scripts/export_preview.py +111 -0
- package/assets/toolkit/toolkit/skills/sdtk-screen-design-xlsx/scripts/export_spec_md.py +181 -0
- package/assets/toolkit/toolkit/skills/sdtk-screen-design-xlsx/scripts/make_template.py +113 -0
- package/assets/toolkit/toolkit/skills/sdtk-screen-design-xlsx/scripts/test_screen_design.py +198 -0
- package/assets/toolkit/toolkit/skills/sdtk-screen-design-xlsx/scripts/uia_dump.py +64 -0
- package/assets/toolkit/toolkit/skills/sdtk-screen-design-xlsx/scripts/validate_spec.py +260 -0
- package/assets/toolkit/toolkit/skills/sdtk-session-handoff/SKILL.md +76 -0
- package/assets/toolkit/toolkit/skills/sdtk-session-handoff/references/HANDOFF_TEMPLATE.md +63 -0
- package/assets/toolkit/toolkit/skills/sdtk-session-handoff/references/MOVING_A_PROJECT.md +18 -0
- package/assets/toolkit/toolkit/skills/sdtk-session-handoff/scripts/dirty_files.py +133 -0
- package/assets/toolkit/toolkit/skills/sdtk-session-handoff/scripts/test_dirty_files.py +94 -0
- package/assets/toolkit/toolkit/skills/sdtk-xlsx-safe-edit/SKILL.md +4 -1
- package/assets/toolkit/toolkit/skills/sdtk-xlsx-safe-edit/scripts/test_metadata.py +76 -0
- package/assets/toolkit/toolkit/skills/sdtk-xlsx-safe-edit/scripts/xlsx_xml_edit.py +65 -1
- package/assets/toolkit/toolkit/skills/skills.catalog.yaml +96 -0
- package/assets/toolkit/toolkit/skills-claude/arch/SKILL.md +15 -2
- package/assets/toolkit/toolkit/skills-claude/ba/SKILL.md +8 -4
- package/assets/toolkit/toolkit/skills-claude/customer-qa-sheet/SKILL.md +115 -0
- package/assets/toolkit/toolkit/skills-claude/db-design/SKILL.md +128 -0
- package/assets/toolkit/toolkit/skills-claude/dev/SKILL.md +33 -2
- package/assets/toolkit/toolkit/skills-claude/dev-backend/SKILL.md +10 -0
- package/assets/toolkit/toolkit/skills-claude/dev-frontend/SKILL.md +10 -0
- package/assets/toolkit/toolkit/skills-claude/pm/SKILL.md +14 -3
- package/assets/toolkit/toolkit/skills-claude/qa/SKILL.md +40 -2
- package/assets/toolkit/toolkit/skills-claude/screen-design-xlsx/SKILL.md +101 -0
- package/assets/toolkit/toolkit/skills-claude/session-handoff/SKILL.md +74 -0
- package/assets/toolkit/toolkit/skills-claude/test-case-spec/SKILL.md +6 -0
- package/assets/toolkit/toolkit/skills-claude/xlsx-safe-edit/SKILL.md +4 -1
- package/assets/toolkit/toolkit/templates/README.md +3 -0
- package/assets/toolkit/toolkit/templates/docs/database/DATABASE_SPEC_TEMPLATE.md +14 -0
- package/assets/toolkit/toolkit/templates/screen-design-xlsx/ja-default/TEMPLATE.md +247 -0
- package/assets/toolkit/toolkit/templates/screen-design-xlsx/ja-default/template.xlsx +0 -0
- package/package.json +1 -1
- package/src/commands/help.js +7 -2
- package/src/lib/args.js +5 -2
- package/src/lib/design-handoff-provenance.js +30 -5
- package/src/lib/office-ingest.js +376 -0
- package/src/lib/requirement-analysis.js +77 -41
- package/src/lib/requirement-sources.js +259 -0
- package/src/lib/scope.js +4 -4
|
@@ -0,0 +1,305 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
"""Shared spec loading, template-set lookup, UI Automation markers, render stamps and text metrics for
|
|
3
|
+
sdtk-screen-design-xlsx.
|
|
4
|
+
|
|
5
|
+
Kept free of any Excel/pywin32 import so that validate_spec.py, export_spec_md.py and the tests run anywhere.
|
|
6
|
+
"""
|
|
7
|
+
from __future__ import annotations
|
|
8
|
+
|
|
9
|
+
import hashlib
|
|
10
|
+
import json
|
|
11
|
+
import os
|
|
12
|
+
import re
|
|
13
|
+
import sys
|
|
14
|
+
import time
|
|
15
|
+
import unicodedata
|
|
16
|
+
|
|
17
|
+
try:
|
|
18
|
+
import yaml
|
|
19
|
+
except ImportError: # pragma: no cover
|
|
20
|
+
raise SystemExit("PyYAML is required: python -m pip install pyyaml")
|
|
21
|
+
|
|
22
|
+
SKILL_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
|
23
|
+
KIND = "screen-design-xlsx"
|
|
24
|
+
DEFAULT_SET = "ja-default"
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
class SpecError(SystemExit):
|
|
28
|
+
pass
|
|
29
|
+
|
|
30
|
+
PROCESS_SHEET = "処理"
|
|
31
|
+
BLOCK_SHEETS = ("画面流れ", PROCESS_SHEET)
|
|
32
|
+
ALL_SHEETS = ("表紙", "改訂記事", "機能概要", "画面流れ", "処理")
|
|
33
|
+
|
|
34
|
+
# right-hand annotation list: text budget in full-width chars, keyed by marker column
|
|
35
|
+
ANN_BUDGET = {24: 52, 34: 38, 41: 31} # X, AH, AO
|
|
36
|
+
|
|
37
|
+
# detail-page "・" note lines start at column F and are cut off at BI. Measured:
|
|
38
|
+
# 82.5 fw renders in full, 96.5 fw is clipped mid-sentence.
|
|
39
|
+
DETAIL_NOTE_BUDGET = 84
|
|
40
|
+
BOX_LINES, BOX_CHARS = 4, 17
|
|
41
|
+
DEC_LINES, DEC_CHARS = 2, 7
|
|
42
|
+
MAX_FLOW_NODES = 6
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def force_utf8_stdio() -> None:
|
|
46
|
+
"""Make stdout/stderr able to carry Japanese on a cp932/cp1252 console.
|
|
47
|
+
|
|
48
|
+
Every message this skill prints (shape text, sheet names, block ids) is Japanese.
|
|
49
|
+
On a default Windows console `print` raises UnicodeEncodeError, which surfaces as a
|
|
50
|
+
traceback and a non-zero exit — indistinguishable from a real validation failure.
|
|
51
|
+
Call this first thing in main().
|
|
52
|
+
"""
|
|
53
|
+
for stream in (sys.stdout, sys.stderr):
|
|
54
|
+
try:
|
|
55
|
+
stream.reconfigure(encoding="utf-8", errors="replace")
|
|
56
|
+
except (AttributeError, ValueError): # already wrapped / not a TextIO
|
|
57
|
+
pass
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
def col_to_index(ref) -> int:
|
|
61
|
+
"""'AH' -> 34. Passes ints through unchanged."""
|
|
62
|
+
if isinstance(ref, int):
|
|
63
|
+
return ref
|
|
64
|
+
n = 0
|
|
65
|
+
for ch in str(ref).strip().upper():
|
|
66
|
+
if not ("A" <= ch <= "Z"):
|
|
67
|
+
raise ValueError("bad column reference: %r" % (ref,))
|
|
68
|
+
n = n * 26 + (ord(ch) - 64)
|
|
69
|
+
return n
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
def index_to_col(n: int) -> str:
|
|
73
|
+
s = ""
|
|
74
|
+
while n:
|
|
75
|
+
n, r = divmod(n - 1, 26)
|
|
76
|
+
s = chr(65 + r) + s
|
|
77
|
+
return s
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
def fw(text: str) -> float:
|
|
81
|
+
"""Width of `text` in full-width character units."""
|
|
82
|
+
return sum(1.0 if unicodedata.east_asian_width(c) in "WFA" else 0.5 for c in text)
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
# ---------------------------------------------------------------------------------------------- template sets
|
|
86
|
+
def template_set_candidates(name_or_path=None, project_root=None):
|
|
87
|
+
"""Same resolution order as the other SDTK template sets:
|
|
88
|
+
explicit folder · <project>/docs/templates/screen-design-xlsx/<set> · <toolkit>/templates/... (toolkit layout) ·
|
|
89
|
+
<skill>/references/templates/... (installed skill) · $SDTK_TEMPLATES_DIR/screen-design-xlsx/<set>."""
|
|
90
|
+
value = name_or_path or DEFAULT_SET
|
|
91
|
+
if os.path.isabs(value) or os.sep in value or "/" in value:
|
|
92
|
+
return [value if os.path.isabs(value) else os.path.join(project_root or os.getcwd(), value)]
|
|
93
|
+
out = [os.path.join(project_root or os.getcwd(), "docs", "templates", KIND, value),
|
|
94
|
+
os.path.join(SKILL_DIR, "..", "..", "templates", KIND, value),
|
|
95
|
+
os.path.join(SKILL_DIR, "references", "templates", KIND, value)]
|
|
96
|
+
if os.environ.get("SDTK_TEMPLATES_DIR"):
|
|
97
|
+
out.append(os.path.join(os.environ["SDTK_TEMPLATES_DIR"], KIND, value))
|
|
98
|
+
return [os.path.normpath(p) for p in out]
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
def resolve_template_set(name_or_path=None, project_root=None) -> str:
|
|
102
|
+
tried = template_set_candidates(name_or_path, project_root)
|
|
103
|
+
for path in tried:
|
|
104
|
+
if os.path.isfile(os.path.join(path, "TEMPLATE.md")):
|
|
105
|
+
return path
|
|
106
|
+
raise SpecError("no %s template set with a TEMPLATE.md at: %s" % (KIND, "; ".join(tried)))
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
def template_set_config(set_dir) -> dict:
|
|
110
|
+
with open(os.path.join(set_dir, "TEMPLATE.md"), encoding="utf-8") as f:
|
|
111
|
+
m = re.search(r"```json config\s*\n(.*?)```", f.read(), re.S)
|
|
112
|
+
return json.loads(m.group(1)) if m else {}
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
# ---------------------------------------------------------------------------------------------- UI Automation
|
|
116
|
+
def uia_markers(scr: dict, base: str):
|
|
117
|
+
"""Markers from a UI Automation dump instead of hand-measured fractions.
|
|
118
|
+
|
|
119
|
+
screens[].uia = {dump: <json>, markers: [{n: 1, id: <automation id>} | {n: 2, name: <element name>}],
|
|
120
|
+
anchor: center|left}
|
|
121
|
+
The dump (uia_dump.py writes it) holds the window rectangle the screenshot was taken of and the element
|
|
122
|
+
rectangles in the same screen coordinates. Returns (markers, problems)."""
|
|
123
|
+
cfg = scr.get("uia") or {}
|
|
124
|
+
path = os.path.normpath(os.path.join(base, cfg.get("dump", "")))
|
|
125
|
+
if not cfg.get("dump") or not os.path.isfile(path):
|
|
126
|
+
return [], ["uia dump not found: %s" % path]
|
|
127
|
+
with open(path, encoding="utf-8") as f:
|
|
128
|
+
dump = json.load(f)
|
|
129
|
+
left, top, right, bottom = dump["window"]["rect"]
|
|
130
|
+
inset = dump["window"].get("inset", 0)
|
|
131
|
+
left, top, right, bottom = left + inset, top + inset, right - inset, bottom - inset
|
|
132
|
+
width, height = float(right - left), float(bottom - top)
|
|
133
|
+
by_id, by_name = {}, {}
|
|
134
|
+
for el in dump.get("elements") or []:
|
|
135
|
+
if el.get("automation_id"):
|
|
136
|
+
by_id.setdefault(el["automation_id"], []).append(el)
|
|
137
|
+
if el.get("name"):
|
|
138
|
+
by_name.setdefault(el["name"], []).append(el)
|
|
139
|
+
markers, problems = [], []
|
|
140
|
+
for m in cfg.get("markers") or []:
|
|
141
|
+
key = ("id", m["id"]) if m.get("id") else ("name", m.get("name"))
|
|
142
|
+
hits = (by_id if key[0] == "id" else by_name).get(key[1]) or []
|
|
143
|
+
if len(hits) != 1:
|
|
144
|
+
problems.append("marker %s: %d elements with %s %r in the dump" % (m.get("n"), len(hits), key[0], key[1]))
|
|
145
|
+
continue
|
|
146
|
+
l, t, r, b = hits[0]["rect"]
|
|
147
|
+
x = (l + 6 - left) if cfg.get("anchor") == "left" else ((l + r) / 2.0 - left)
|
|
148
|
+
y = (t + b) / 2.0 - top
|
|
149
|
+
if not (0 <= x <= width and 0 <= y <= height):
|
|
150
|
+
problems.append("marker %s: element %r lies outside the captured window" % (m.get("n"), key[1]))
|
|
151
|
+
continue
|
|
152
|
+
markers.append({"n": m["n"], "x": round(x / width, 4), "y": round(y / height, 4)})
|
|
153
|
+
return markers, problems
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
# ---------------------------------------------------------------------------------------------- spec
|
|
157
|
+
def load_spec(path: str) -> dict:
|
|
158
|
+
with open(path, "r", encoding="utf-8") as fh:
|
|
159
|
+
spec = yaml.safe_load(fh)
|
|
160
|
+
if not isinstance(spec, dict) or "workbook" not in spec:
|
|
161
|
+
raise SpecError("%s: spec must be a mapping with a `workbook` key" % path)
|
|
162
|
+
wb = spec["workbook"]
|
|
163
|
+
wb.setdefault("block_rows", 40)
|
|
164
|
+
wb.setdefault("meta", {})
|
|
165
|
+
base = os.path.dirname(os.path.abspath(path))
|
|
166
|
+
spec["_spec_path"] = os.path.abspath(path)
|
|
167
|
+
# resolve every path in the spec relative to the spec file, not the cwd
|
|
168
|
+
wb["path"] = os.path.normpath(os.path.join(base, wb["path"]))
|
|
169
|
+
if wb.get("template"):
|
|
170
|
+
wb["template"] = os.path.normpath(os.path.join(base, wb["template"]))
|
|
171
|
+
else:
|
|
172
|
+
set_dir = resolve_template_set(wb.get("template_set"), project_root=wb.get("project_root") or os.getcwd())
|
|
173
|
+
wb["template"] = os.path.join(set_dir, template_set_config(set_dir).get("output_template", "template.xlsx"))
|
|
174
|
+
for scr in spec.get("screens") or []:
|
|
175
|
+
if scr.get("image"):
|
|
176
|
+
scr["image"] = os.path.normpath(os.path.join(base, scr["image"]))
|
|
177
|
+
if scr.get("uia"):
|
|
178
|
+
if scr.get("markers"):
|
|
179
|
+
scr.setdefault("_problems", []).append("both `markers` and `uia` given — keep one")
|
|
180
|
+
scr["markers"], problems = uia_markers(scr, base)
|
|
181
|
+
scr.setdefault("_problems", []).extend(problems)
|
|
182
|
+
return spec
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
# ---------------------------------------------------------------------------------------------- render stamps
|
|
186
|
+
def file_sha256(path: str) -> str:
|
|
187
|
+
h = hashlib.sha256()
|
|
188
|
+
with open(path, "rb") as f:
|
|
189
|
+
for chunk in iter(lambda: f.read(1 << 20), b""):
|
|
190
|
+
h.update(chunk)
|
|
191
|
+
return h.hexdigest()
|
|
192
|
+
|
|
193
|
+
|
|
194
|
+
def stamp_path(spec: dict) -> str:
|
|
195
|
+
"""The render stamp sits beside the spec: .<workbook file name>.render.json"""
|
|
196
|
+
return os.path.join(os.path.dirname(spec["_spec_path"]),
|
|
197
|
+
".%s.render.json" % os.path.basename(spec["workbook"]["path"]))
|
|
198
|
+
|
|
199
|
+
|
|
200
|
+
def workbook_state(spec: dict) -> str:
|
|
201
|
+
"""new: no workbook yet · rendered: unchanged since this skill's last render · edited: changed after it (by hand,
|
|
202
|
+
by another tool) · unknown: a workbook with no stamp (made before stamps, or by someone else) · final: the spec
|
|
203
|
+
says the person finalized it."""
|
|
204
|
+
target = spec["workbook"]["path"]
|
|
205
|
+
if spec["workbook"].get("final"):
|
|
206
|
+
return "final"
|
|
207
|
+
if not os.path.exists(target):
|
|
208
|
+
return "new"
|
|
209
|
+
sp = stamp_path(spec)
|
|
210
|
+
if not os.path.exists(sp):
|
|
211
|
+
return "unknown"
|
|
212
|
+
with open(sp, encoding="utf-8") as f:
|
|
213
|
+
stamp = json.load(f)
|
|
214
|
+
return "rendered" if stamp.get("sha256") == file_sha256(target) else "edited"
|
|
215
|
+
|
|
216
|
+
|
|
217
|
+
def write_stamp(spec: dict, sheets) -> None:
|
|
218
|
+
with open(stamp_path(spec), "w", encoding="utf-8") as f:
|
|
219
|
+
json.dump({"sha256": file_sha256(spec["workbook"]["path"]), "sheets": list(sheets),
|
|
220
|
+
"rendered_at": time.strftime("%Y-%m-%dT%H:%M:%S")}, f, ensure_ascii=False, indent=1)
|
|
221
|
+
|
|
222
|
+
|
|
223
|
+
def main_process_sheet(spec: dict) -> str:
|
|
224
|
+
"""The tab `processes:` renders to: `workbook.process_sheet`, or 処理 when the spec does not name it."""
|
|
225
|
+
return ((spec.get("workbook") or {}).get("process_sheet") or PROCESS_SHEET).strip()
|
|
226
|
+
|
|
227
|
+
|
|
228
|
+
def previous_sheet_names(spec: dict) -> dict:
|
|
229
|
+
"""{current name: former name} for process tabs renamed in the spec (`workbook.process_sheet_was`,
|
|
230
|
+
`process_sheets[].was`). The renderer renames the old tab instead of leaving it beside a new one."""
|
|
231
|
+
out = {}
|
|
232
|
+
was = (spec.get("workbook") or {}).get("process_sheet_was")
|
|
233
|
+
if was:
|
|
234
|
+
out[main_process_sheet(spec)] = was
|
|
235
|
+
for ps in spec.get("process_sheets") or []:
|
|
236
|
+
if (ps or {}).get("was"):
|
|
237
|
+
out[ps["name"]] = ps["was"]
|
|
238
|
+
return out
|
|
239
|
+
|
|
240
|
+
|
|
241
|
+
def iter_process_sheets(spec: dict):
|
|
242
|
+
"""Yield (sheet_name, blocks) for the built-in 処理 sheet and every extra one.
|
|
243
|
+
|
|
244
|
+
`processes:` renders to 処理. `process_sheets:` adds further block sheets with the same
|
|
245
|
+
layout, so a feature breakdown can live on its own tab instead of growing 処理:
|
|
246
|
+
|
|
247
|
+
process_sheets:
|
|
248
|
+
- name: "処理| 機能別詳細"
|
|
249
|
+
processes: [ ... same schema as `processes` ... ]
|
|
250
|
+
"""
|
|
251
|
+
yield main_process_sheet(spec), spec.get("processes") or []
|
|
252
|
+
for i, ps in enumerate(spec.get("process_sheets") or []):
|
|
253
|
+
name = (ps or {}).get("name")
|
|
254
|
+
if not name:
|
|
255
|
+
raise SpecError("process_sheets[%d]: `name` is required" % i)
|
|
256
|
+
if name in ALL_SHEETS:
|
|
257
|
+
raise SpecError("process_sheets[%d]: %r collides with a built-in sheet" % (i, name))
|
|
258
|
+
yield name, ps.get("processes") or []
|
|
259
|
+
|
|
260
|
+
|
|
261
|
+
def block_starts(count: int, block_rows: int, first: int = 3):
|
|
262
|
+
return [first + block_rows * i for i in range(count)]
|
|
263
|
+
|
|
264
|
+
|
|
265
|
+
def all_sheet_names(spec: dict):
|
|
266
|
+
return [n for n in ALL_SHEETS if n != PROCESS_SHEET] + [n for n, _ in iter_process_sheets(spec)]
|
|
267
|
+
|
|
268
|
+
|
|
269
|
+
def render_plan(spec: dict, sheets_arg=None, out=None, accept_hand_edits=False) -> dict:
|
|
270
|
+
"""Decide what a render may do, before Excel is touched. Raises SpecError with the reason when it may not.
|
|
271
|
+
|
|
272
|
+
- a new workbook (from the template) renders every sheet with content;
|
|
273
|
+
- an existing workbook renders only the sheets named with --sheets (rendering wipes a sheet);
|
|
274
|
+
- a workbook the spec marks `final: true` is never rendered: surgical edits via sdtk-xlsx-safe-edit final mode;
|
|
275
|
+
- a workbook changed since this skill's last render (or with no stamp) is rendered only with
|
|
276
|
+
--accept-hand-edits, after the person confirmed the named sheets hold no hand edits worth keeping;
|
|
277
|
+
- --out renders into a separate file (a preview copy) and never touches workbook.path."""
|
|
278
|
+
known = all_sheet_names(spec)
|
|
279
|
+
wanted = [s.strip() for s in sheets_arg.split(",") if s.strip()] if sheets_arg else []
|
|
280
|
+
unknown = [s for s in wanted if s not in known]
|
|
281
|
+
if unknown:
|
|
282
|
+
raise SpecError("unknown sheet(s): %s (known: %s)" % (", ".join(unknown), ", ".join(known)))
|
|
283
|
+
if out:
|
|
284
|
+
return {"target": os.path.abspath(out), "sheets": wanted or known, "from_template": True,
|
|
285
|
+
"copy_of": spec["workbook"]["path"] if os.path.exists(spec["workbook"]["path"]) else None,
|
|
286
|
+
"stamp": False}
|
|
287
|
+
state = workbook_state(spec)
|
|
288
|
+
if state == "final":
|
|
289
|
+
raise SpecError("workbook.final is set: this workbook was finalized by hand and is never re-rendered. "
|
|
290
|
+
"Apply the change surgically with sdtk-xlsx-safe-edit (final mode) and give a change table.")
|
|
291
|
+
if state == "new":
|
|
292
|
+
return {"target": spec["workbook"]["path"], "sheets": wanted or known, "from_template": True,
|
|
293
|
+
"copy_of": None, "stamp": True}
|
|
294
|
+
if not wanted:
|
|
295
|
+
raise SpecError("the workbook exists: pass --sheets with only the sheets you changed "
|
|
296
|
+
"(rendering wipes and rebuilds each named sheet)")
|
|
297
|
+
if state in ("edited", "unknown") and not accept_hand_edits:
|
|
298
|
+
why = ("it changed after the last render (hand edits?)" if state == "edited"
|
|
299
|
+
else "it has no render stamp (made before stamps or by someone else)")
|
|
300
|
+
raise SpecError("not rendering: %s. Compare the named sheets with the spec; if they hold hand edits, "
|
|
301
|
+
"carry them into the spec or edit surgically (sdtk-xlsx-safe-edit). Re-run with "
|
|
302
|
+
"--accept-hand-edits only after the person confirmed %s may be rebuilt."
|
|
303
|
+
% (why, ", ".join(wanted)))
|
|
304
|
+
return {"target": spec["workbook"]["path"], "sheets": wanted, "from_template": False, "copy_of": None,
|
|
305
|
+
"stamp": True}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
"""Export one PNG per printed page of a 画面設計書 workbook, so the pages can be reviewed
|
|
3
|
+
without opening Excel.
|
|
4
|
+
|
|
5
|
+
python export_preview.py --spec docs/screen_design/design_spec.yaml
|
|
6
|
+
python export_preview.py --spec ... --sheets 処理 --outdir docs/screen_design/_preview
|
|
7
|
+
|
|
8
|
+
Block sheets are exported per 40-row block; 画面流れ additionally exports its right-hand
|
|
9
|
+
UI item page. Requires Windows + Excel + pywin32.
|
|
10
|
+
"""
|
|
11
|
+
from __future__ import annotations
|
|
12
|
+
|
|
13
|
+
import argparse
|
|
14
|
+
import os
|
|
15
|
+
import re
|
|
16
|
+
import sys
|
|
17
|
+
import time
|
|
18
|
+
|
|
19
|
+
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
|
|
20
|
+
from design_spec import (block_starts, force_utf8_stdio, # noqa: E402
|
|
21
|
+
iter_process_sheets, load_spec)
|
|
22
|
+
|
|
23
|
+
try:
|
|
24
|
+
import win32com.client as win32
|
|
25
|
+
except ImportError: # pragma: no cover
|
|
26
|
+
raise SystemExit("pywin32 is required: python -m pip install pywin32")
|
|
27
|
+
|
|
28
|
+
SAFE = re.compile(r'[\\/:*?"<>|]+')
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def shot(ws, ref, path, attempts=3):
|
|
32
|
+
"""Range -> PNG, via a throwaway chart object.
|
|
33
|
+
|
|
34
|
+
CopyPicture/Paste go through the Windows clipboard and fail transiently when another
|
|
35
|
+
Excel instance is still shutting down, so retry rather than losing the whole run.
|
|
36
|
+
"""
|
|
37
|
+
rng = ws.Range(ref)
|
|
38
|
+
for i in range(attempts):
|
|
39
|
+
try:
|
|
40
|
+
rng.CopyPicture(1, -4147) # xlScreen, xlPicture
|
|
41
|
+
co = ws.ChartObjects().Add(10, 10, rng.Width, rng.Height)
|
|
42
|
+
co.Activate()
|
|
43
|
+
co.Chart.Paste()
|
|
44
|
+
co.Chart.Export(path, "PNG")
|
|
45
|
+
co.Delete()
|
|
46
|
+
print(path)
|
|
47
|
+
return
|
|
48
|
+
except Exception as exc:
|
|
49
|
+
if i == attempts - 1:
|
|
50
|
+
raise
|
|
51
|
+
print(" retrying %s (%s)" % (os.path.basename(path), exc))
|
|
52
|
+
time.sleep(1.5)
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
def main() -> int:
|
|
56
|
+
force_utf8_stdio()
|
|
57
|
+
ap = argparse.ArgumentParser()
|
|
58
|
+
ap.add_argument("--spec", required=True)
|
|
59
|
+
ap.add_argument("--sheets", default="", help="comma-separated; default = 画面流れ and every process sheet")
|
|
60
|
+
ap.add_argument("--outdir")
|
|
61
|
+
args = ap.parse_args()
|
|
62
|
+
|
|
63
|
+
spec = load_spec(args.spec)
|
|
64
|
+
target = spec["workbook"]["path"]
|
|
65
|
+
block_rows = spec["workbook"]["block_rows"]
|
|
66
|
+
outdir = os.path.abspath(args.outdir or
|
|
67
|
+
os.path.join(os.path.dirname(target), "_preview"))
|
|
68
|
+
os.makedirs(outdir, exist_ok=True)
|
|
69
|
+
|
|
70
|
+
proc_sheets = dict(iter_process_sheets(spec))
|
|
71
|
+
if not args.sheets:
|
|
72
|
+
args.sheets = ",".join(["画面流れ"] + list(proc_sheets))
|
|
73
|
+
|
|
74
|
+
jobs = [] # (sheet, range, filename)
|
|
75
|
+
for name in [s.strip() for s in args.sheets.split(",")]:
|
|
76
|
+
if name in proc_sheets:
|
|
77
|
+
blocks = proc_sheets[name]
|
|
78
|
+
for i, (s, blk) in enumerate(zip(block_starts(len(blocks), block_rows), blocks)):
|
|
79
|
+
label = blk.get("sub_no") or blk.get("id") or blk.get("no")
|
|
80
|
+
jobs.append((name, "A%d:BI%d" % (s, s + block_rows - 1),
|
|
81
|
+
"%s_%02d_%s.png" % (name, i + 1, label)))
|
|
82
|
+
elif name == "画面流れ":
|
|
83
|
+
for s, scr in zip(block_starts(len(spec.get("screens") or []), block_rows),
|
|
84
|
+
spec.get("screens") or []):
|
|
85
|
+
base = "%s_%s" % (scr.get("id"), scr.get("name"))
|
|
86
|
+
jobs.append((name, "A%d:BI%d" % (s, s + block_rows - 1), base + ".png"))
|
|
87
|
+
jobs.append((name, "BK%d:BW%d" % (s, s + block_rows - 1), base + "_項目.png"))
|
|
88
|
+
else:
|
|
89
|
+
jobs.append((name, "A1:BI60", name + ".png"))
|
|
90
|
+
|
|
91
|
+
if not jobs:
|
|
92
|
+
print("nothing to export")
|
|
93
|
+
return 0
|
|
94
|
+
|
|
95
|
+
xl = win32.DispatchEx("Excel.Application") # a private instance: never the person's open Excel
|
|
96
|
+
xl.Visible = True # CopyPicture needs a visible window
|
|
97
|
+
xl.DisplayAlerts = False
|
|
98
|
+
wb = xl.Workbooks.Open(target, UpdateLinks=0, ReadOnly=True)
|
|
99
|
+
try:
|
|
100
|
+
for sheet, ref, fname in jobs:
|
|
101
|
+
ws = wb.Worksheets(sheet)
|
|
102
|
+
ws.Activate()
|
|
103
|
+
shot(ws, ref, os.path.join(outdir, SAFE.sub("_", fname)))
|
|
104
|
+
finally:
|
|
105
|
+
wb.Close(False)
|
|
106
|
+
xl.Quit()
|
|
107
|
+
return 0
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
if __name__ == "__main__":
|
|
111
|
+
sys.exit(main())
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
"""Render the 処理 block sheets of a design_spec.yaml as Markdown.
|
|
3
|
+
|
|
4
|
+
The workbook is the deliverable, but nobody wants to open Excel to answer "what
|
|
5
|
+
does PRC02-2 do". This writes the same blocks as text so the chapter can never
|
|
6
|
+
drift from the spec the renderer uses: both read design_spec.yaml.
|
|
7
|
+
|
|
8
|
+
python export_spec_md.py --spec docs/screen_design/design_spec.yaml
|
|
9
|
+
python export_spec_md.py --spec <spec> --sheet 処理 # one sheet only
|
|
10
|
+
|
|
11
|
+
Writes to stdout. Flow blocks become a Mermaid diagram plus the numbered
|
|
12
|
+
explanation list that sits beside the flowchart on the printed page; detail
|
|
13
|
+
blocks become their bordered tables. Nothing is summarised or reworded — a line
|
|
14
|
+
that is wrong here is wrong in the workbook too.
|
|
15
|
+
"""
|
|
16
|
+
from __future__ import annotations
|
|
17
|
+
|
|
18
|
+
import argparse
|
|
19
|
+
import io
|
|
20
|
+
import os
|
|
21
|
+
import sys
|
|
22
|
+
|
|
23
|
+
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
|
|
24
|
+
from design_spec import force_utf8_stdio, iter_process_sheets, load_spec # noqa: E402
|
|
25
|
+
|
|
26
|
+
out: list[str] = []
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def w(line: str = "") -> None:
|
|
30
|
+
out.append(line)
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def mermaid_text(text: str) -> str:
|
|
34
|
+
"""Keep the author's line breaks in the diagram, but not the quotes that end a node."""
|
|
35
|
+
parts = [p.strip() for p in (text or "").split("\n") if p.strip()]
|
|
36
|
+
return "<br/>".join(parts).replace('"', "'")
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def flow_diagram(blk: dict) -> None:
|
|
40
|
+
"""The flowchart, in the same top-down shape the Excel page draws."""
|
|
41
|
+
w("```mermaid")
|
|
42
|
+
w("flowchart TD")
|
|
43
|
+
|
|
44
|
+
trigger = "<br/>".join(t.strip() for t in (blk.get("trigger") or []) if t.strip())
|
|
45
|
+
w(' START(["%s"])' % (trigger or "開始"))
|
|
46
|
+
|
|
47
|
+
nodes = blk.get("nodes") or []
|
|
48
|
+
ids: list[str] = []
|
|
49
|
+
for i, nd in enumerate(nodes):
|
|
50
|
+
nid = "N%d" % i
|
|
51
|
+
ids.append(nid)
|
|
52
|
+
label = "%s %s" % (nd.get("n") or "", mermaid_text(nd.get("text", "")))
|
|
53
|
+
if nd.get("type") == "decision":
|
|
54
|
+
w(' %s{"%s"}' % (nid, label.strip()))
|
|
55
|
+
else:
|
|
56
|
+
w(' %s["%s"]' % (nid, label.strip()))
|
|
57
|
+
|
|
58
|
+
br = nd.get("branch")
|
|
59
|
+
if br:
|
|
60
|
+
bid = "B%d" % i
|
|
61
|
+
w(' %s["%s %s"]' % (bid, br.get("n") or "", mermaid_text(br.get("text", ""))))
|
|
62
|
+
if br.get("terminate"):
|
|
63
|
+
w(' %s_E((("終了")))' % bid)
|
|
64
|
+
|
|
65
|
+
w(" END(((処理終了)))")
|
|
66
|
+
|
|
67
|
+
# Edges. The main column is a straight chain; a decision just labels its two
|
|
68
|
+
# exits — the branch to the side, the fall-through onward to the same next node.
|
|
69
|
+
ids.append("END")
|
|
70
|
+
w(" START --> %s" % ids[0])
|
|
71
|
+
for i, nd in enumerate(nodes):
|
|
72
|
+
nid, nxt = ids[i], ids[i + 1]
|
|
73
|
+
if nd.get("type") == "decision" and nd.get("else_label"):
|
|
74
|
+
w(' %s -- "%s" --> %s' % (nid, nd["else_label"], nxt))
|
|
75
|
+
else:
|
|
76
|
+
w(" %s --> %s" % (nid, nxt))
|
|
77
|
+
br = nd.get("branch")
|
|
78
|
+
if br:
|
|
79
|
+
bid = "B%d" % i
|
|
80
|
+
w(' %s -- "%s" --> %s' % (nid, br.get("label") or "はい", bid))
|
|
81
|
+
w(" %s --> %s" % (bid, "%s_E" % bid if br.get("terminate") else nxt))
|
|
82
|
+
if not nodes:
|
|
83
|
+
w(" START --> END")
|
|
84
|
+
w("```")
|
|
85
|
+
w()
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
def flow_block(blk: dict) -> None:
|
|
89
|
+
w("### %s — %s" % (blk.get("id"), blk.get("summary") or ""))
|
|
90
|
+
w()
|
|
91
|
+
w("| | |")
|
|
92
|
+
w("|---|---|")
|
|
93
|
+
w("| 画面名 | %s |" % (blk.get("screen") or "—"))
|
|
94
|
+
w("| きっかけ | %s |" % (" ".join(blk.get("trigger") or []) or "—"))
|
|
95
|
+
w()
|
|
96
|
+
|
|
97
|
+
flow_diagram(blk)
|
|
98
|
+
|
|
99
|
+
subs = [(nd.get("n"), nd["sub"]) for nd in (blk.get("nodes") or []) if nd.get("sub")]
|
|
100
|
+
if subs:
|
|
101
|
+
w("> 詳細処理: " + " · ".join("%s → `%s`" % (n or "", s) for n, s in subs))
|
|
102
|
+
w()
|
|
103
|
+
|
|
104
|
+
notes = blk.get("notes") or []
|
|
105
|
+
if notes:
|
|
106
|
+
w("| № | 説明 |")
|
|
107
|
+
w("|---|---|")
|
|
108
|
+
for note in notes:
|
|
109
|
+
body = " ".join(ln.strip() for ln in (note.get("lines") or []) if ln.strip())
|
|
110
|
+
w("| %s | %s |" % (note.get("mark") or "", body.replace("|", "\\|")))
|
|
111
|
+
w()
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
def detail_block(blk: dict) -> None:
|
|
115
|
+
w("### %s — %s" % (blk.get("sub_no"), blk.get("sub_name") or ""))
|
|
116
|
+
w()
|
|
117
|
+
w("`%s`(%s)の詳細処理" % (blk.get("id"), blk.get("summary") or ""))
|
|
118
|
+
w()
|
|
119
|
+
for sec in blk.get("sections") or []:
|
|
120
|
+
w("**%s**" % (sec.get("head") or ""))
|
|
121
|
+
w()
|
|
122
|
+
cols = sec.get("columns") or []
|
|
123
|
+
rows = sec.get("rows") or []
|
|
124
|
+
if cols:
|
|
125
|
+
w("| " + " | ".join(str(c.get("title") or "") for c in cols) + " |")
|
|
126
|
+
w("|" + "|".join("---" for _ in cols) + "|")
|
|
127
|
+
for row in rows:
|
|
128
|
+
w("| " + " | ".join(str(cell).replace("|", "\\|") for cell in row) + " |")
|
|
129
|
+
w()
|
|
130
|
+
for line in sec.get("notes") or []:
|
|
131
|
+
w("- %s" % line.strip().lstrip("・"))
|
|
132
|
+
if sec.get("notes"):
|
|
133
|
+
w()
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
def sheet(name: str, blocks: list[dict], level: int) -> None:
|
|
137
|
+
w("%s シート `%s` の内容" % ("#" * level, name))
|
|
138
|
+
w()
|
|
139
|
+
w("> design_spec.yaml から export_spec_md.py で自動生成。**手で編集しない** — spec を直して再生成する"
|
|
140
|
+
"(次の Excel レンダリングと食い違うため)。")
|
|
141
|
+
w()
|
|
142
|
+
flows = sum(1 for b in blocks if b.get("kind") == "flow")
|
|
143
|
+
w("%d ブロック: フローチャート %d、詳細ページ %d。" % (len(blocks), flows, len(blocks) - flows))
|
|
144
|
+
w()
|
|
145
|
+
for blk in blocks:
|
|
146
|
+
if blk.get("kind") == "flow":
|
|
147
|
+
flow_block(blk)
|
|
148
|
+
else:
|
|
149
|
+
detail_block(blk)
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
def main() -> int:
|
|
153
|
+
force_utf8_stdio()
|
|
154
|
+
ap = argparse.ArgumentParser()
|
|
155
|
+
ap.add_argument("--spec", required=True)
|
|
156
|
+
ap.add_argument("--sheet", help="only this block sheet; default = all of them")
|
|
157
|
+
ap.add_argument("--level", type=int, default=2, help="heading level for the sheet title")
|
|
158
|
+
args = ap.parse_args()
|
|
159
|
+
|
|
160
|
+
spec = load_spec(args.spec)
|
|
161
|
+
|
|
162
|
+
sheets: list[tuple[str, list]] = [(n, b) for n, b in iter_process_sheets(spec) if b]
|
|
163
|
+
|
|
164
|
+
if args.sheet:
|
|
165
|
+
sheets = [s for s in sheets if s[0] == args.sheet]
|
|
166
|
+
if not sheets:
|
|
167
|
+
print("no such block sheet: %s" % args.sheet, file=sys.stderr)
|
|
168
|
+
return 1
|
|
169
|
+
|
|
170
|
+
for i, (name, blocks) in enumerate(sheets):
|
|
171
|
+
if i:
|
|
172
|
+
w("---")
|
|
173
|
+
w()
|
|
174
|
+
sheet(name, blocks, args.level)
|
|
175
|
+
|
|
176
|
+
io.TextIOWrapper(sys.stdout.buffer, encoding="utf-8", newline="\n").write("\n".join(out) + "\n")
|
|
177
|
+
return 0
|
|
178
|
+
|
|
179
|
+
|
|
180
|
+
if __name__ == "__main__":
|
|
181
|
+
sys.exit(main())
|