sdtk-spec-kit 0.9.2 → 0.11.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.
Files changed (88) hide show
  1. package/README.md +1 -1
  2. package/assets/manifest/toolkit-bundle.manifest.json +370 -35
  3. package/assets/manifest/toolkit-bundle.sha256.txt +84 -17
  4. package/assets/toolkit/toolkit/AGENTS.md +2 -1
  5. package/assets/toolkit/toolkit/SDTK_TOOLKIT.md +11 -3
  6. package/assets/toolkit/toolkit/runtimes/claude/CLAUDE_TEMPLATE.md +7 -0
  7. package/assets/toolkit/toolkit/scripts/install-claude-skills.ps1 +46 -0
  8. package/assets/toolkit/toolkit/scripts/install-codex-skills.ps1 +19 -0
  9. package/assets/toolkit/toolkit/skills/sdtk-arch/SKILL.md +1 -1
  10. package/assets/toolkit/toolkit/skills/sdtk-ba/SKILL.md +1 -1
  11. package/assets/toolkit/toolkit/skills/sdtk-customer-qa-sheet/SKILL.md +117 -0
  12. package/assets/toolkit/toolkit/skills/sdtk-customer-qa-sheet/references/PROFILE_TEMPLATE.md +60 -0
  13. package/assets/toolkit/toolkit/skills/sdtk-customer-qa-sheet/scripts/oq_sync.py +349 -0
  14. package/assets/toolkit/toolkit/skills/sdtk-customer-qa-sheet/scripts/test_oq_sync.py +175 -0
  15. package/assets/toolkit/toolkit/skills/sdtk-db-design/SKILL.md +130 -0
  16. package/assets/toolkit/toolkit/skills/sdtk-db-design/references/REVIEW_PROCESS.md +82 -0
  17. package/assets/toolkit/toolkit/skills/sdtk-orchestrator/SKILL.md +2 -0
  18. package/assets/toolkit/toolkit/skills/sdtk-qa/SKILL.md +1 -1
  19. package/assets/toolkit/toolkit/skills/sdtk-screen-design-xlsx/SKILL.md +104 -0
  20. package/assets/toolkit/toolkit/skills/sdtk-screen-design-xlsx/references/REVIEW_AND_MISTAKES.md +63 -0
  21. package/assets/toolkit/toolkit/skills/sdtk-screen-design-xlsx/references/SCR01.json +46 -0
  22. package/assets/toolkit/toolkit/skills/sdtk-screen-design-xlsx/references/SCR01.png +0 -0
  23. package/assets/toolkit/toolkit/skills/sdtk-screen-design-xlsx/references/SPEC_SCHEMA.md +208 -0
  24. package/assets/toolkit/toolkit/skills/sdtk-screen-design-xlsx/references/example_spec.yaml +115 -0
  25. package/assets/toolkit/toolkit/skills/sdtk-screen-design-xlsx/scripts/build_design_xlsx.py +550 -0
  26. package/assets/toolkit/toolkit/skills/sdtk-screen-design-xlsx/scripts/design_spec.py +305 -0
  27. package/assets/toolkit/toolkit/skills/sdtk-screen-design-xlsx/scripts/export_preview.py +111 -0
  28. package/assets/toolkit/toolkit/skills/sdtk-screen-design-xlsx/scripts/export_spec_md.py +181 -0
  29. package/assets/toolkit/toolkit/skills/sdtk-screen-design-xlsx/scripts/make_template.py +113 -0
  30. package/assets/toolkit/toolkit/skills/sdtk-screen-design-xlsx/scripts/test_screen_design.py +198 -0
  31. package/assets/toolkit/toolkit/skills/sdtk-screen-design-xlsx/scripts/uia_dump.py +64 -0
  32. package/assets/toolkit/toolkit/skills/sdtk-screen-design-xlsx/scripts/validate_spec.py +260 -0
  33. package/assets/toolkit/toolkit/skills/sdtk-session-handoff/SKILL.md +76 -0
  34. package/assets/toolkit/toolkit/skills/sdtk-session-handoff/references/HANDOFF_TEMPLATE.md +63 -0
  35. package/assets/toolkit/toolkit/skills/sdtk-session-handoff/references/MOVING_A_PROJECT.md +18 -0
  36. package/assets/toolkit/toolkit/skills/sdtk-session-handoff/scripts/dirty_files.py +133 -0
  37. package/assets/toolkit/toolkit/skills/sdtk-session-handoff/scripts/test_dirty_files.py +94 -0
  38. package/assets/toolkit/toolkit/skills/sdtk-smoke-test-spec/SKILL.md +69 -0
  39. package/assets/toolkit/toolkit/skills/sdtk-smoke-test-spec/scripts/test_validate_smoke_test.py +58 -0
  40. package/assets/toolkit/toolkit/skills/sdtk-smoke-test-spec/scripts/validate_smoke_test.py +152 -0
  41. package/assets/toolkit/toolkit/skills/sdtk-test-case-xlsx/SKILL.md +297 -0
  42. package/assets/toolkit/toolkit/skills/sdtk-test-case-xlsx/prompts/agent_brief_template.md +59 -0
  43. package/assets/toolkit/toolkit/skills/sdtk-test-case-xlsx/scripts/check_coverage.py +50 -0
  44. package/assets/toolkit/toolkit/skills/sdtk-test-case-xlsx/scripts/extract_sources.py +224 -0
  45. package/assets/toolkit/toolkit/skills/sdtk-test-case-xlsx/scripts/merge_parts.py +78 -0
  46. package/assets/toolkit/toolkit/skills/sdtk-test-case-xlsx/scripts/render_testcase.py +421 -0
  47. package/assets/toolkit/toolkit/skills/sdtk-test-case-xlsx/scripts/template_set.py +57 -0
  48. package/assets/toolkit/toolkit/skills/sdtk-test-case-xlsx/scripts/test_write_results.py +89 -0
  49. package/assets/toolkit/toolkit/skills/sdtk-test-case-xlsx/scripts/write_results.py +126 -0
  50. package/assets/toolkit/toolkit/skills/sdtk-xlsx-safe-edit/SKILL.md +149 -0
  51. package/assets/toolkit/toolkit/skills/sdtk-xlsx-safe-edit/scripts/pictures.py +68 -0
  52. package/assets/toolkit/toolkit/skills/sdtk-xlsx-safe-edit/scripts/test_metadata.py +76 -0
  53. package/assets/toolkit/toolkit/skills/sdtk-xlsx-safe-edit/scripts/test_pictures.py +55 -0
  54. package/assets/toolkit/toolkit/skills/sdtk-xlsx-safe-edit/scripts/xlsafe.py +137 -0
  55. package/assets/toolkit/toolkit/skills/sdtk-xlsx-safe-edit/scripts/xlsx_xml_edit.py +217 -0
  56. package/assets/toolkit/toolkit/skills/skills.catalog.yaml +172 -0
  57. package/assets/toolkit/toolkit/skills-claude/arch/SKILL.md +1 -1
  58. package/assets/toolkit/toolkit/skills-claude/ba/SKILL.md +1 -1
  59. package/assets/toolkit/toolkit/skills-claude/customer-qa-sheet/SKILL.md +115 -0
  60. package/assets/toolkit/toolkit/skills-claude/db-design/SKILL.md +128 -0
  61. package/assets/toolkit/toolkit/skills-claude/orchestrator/SKILL.md +1 -1
  62. package/assets/toolkit/toolkit/skills-claude/qa/SKILL.md +1 -1
  63. package/assets/toolkit/toolkit/skills-claude/screen-design-xlsx/SKILL.md +101 -0
  64. package/assets/toolkit/toolkit/skills-claude/session-handoff/SKILL.md +74 -0
  65. package/assets/toolkit/toolkit/skills-claude/smoke-test-spec/SKILL.md +66 -0
  66. package/assets/toolkit/toolkit/skills-claude/test-case-xlsx/SKILL.md +294 -0
  67. package/assets/toolkit/toolkit/skills-claude/xlsx-safe-edit/SKILL.md +146 -0
  68. package/assets/toolkit/toolkit/templates/README.md +11 -1
  69. package/assets/toolkit/toolkit/templates/docs/database/DATABASE_SPEC_TEMPLATE.md +14 -0
  70. package/assets/toolkit/toolkit/templates/screen-design-xlsx/ja-default/TEMPLATE.md +247 -0
  71. package/assets/toolkit/toolkit/templates/screen-design-xlsx/ja-default/template.xlsx +0 -0
  72. package/assets/toolkit/toolkit/templates/smoke-test/PROFILE_TEMPLATE.md +36 -0
  73. package/assets/toolkit/toolkit/templates/smoke-test/vi-default/AUTHORING_RULES.md +32 -0
  74. package/assets/toolkit/toolkit/templates/smoke-test/vi-default/SMOKE_TEST_TEMPLATE.md +147 -0
  75. package/assets/toolkit/toolkit/templates/smoke-test/vi-default/TEMPLATE.md +25 -0
  76. package/assets/toolkit/toolkit/templates/test-case-xlsx/PROFILE_TEMPLATE.md +78 -0
  77. package/assets/toolkit/toolkit/templates/test-case-xlsx/ja-default/TEMPLATE.md +28 -0
  78. package/assets/toolkit/toolkit/templates/test-case-xlsx/ja-default/viewpoints/README.md +73 -0
  79. package/assets/toolkit/toolkit/templates/test-case-xlsx/ja-default/viewpoints/_template.xlsx +0 -0
  80. package/assets/toolkit/toolkit/templates/test-case-xlsx/ja-default/viewpoints/common/common.xlsx +0 -0
  81. package/assets/toolkit/toolkit/templates/test-case-xlsx/ja-default/viewpoints/platform/mobile_app.xlsx +0 -0
  82. package/assets/toolkit/toolkit/templates/test-case-xlsx/ja-default/viewpoints/platform/smartphone_web.xlsx +0 -0
  83. package/assets/toolkit/toolkit/templates/test-case-xlsx/ja-default/viewpoints/platform/web.xlsx +0 -0
  84. package/assets/toolkit/toolkit/templates/test-case-xlsx/ja-default/viewpoints/platform/windows_app.xlsx +0 -0
  85. package/assets/toolkit/toolkit/templates/test-case-xlsx/ja-default//343/203/206/343/202/271/343/203/210/344/273/225/346/247/230/346/233/270/344/275/234/346/210/220/343/203/253/343/203/274/343/203/253.md +514 -0
  86. package/assets/toolkit/toolkit/templates/test-case-xlsx/ja-default//343/203/206/343/202/271/343/203/210/344/273/225/346/247/230/346/233/270/351/233/233/345/236/213.xlsx +0 -0
  87. package/package.json +1 -1
  88. package/src/lib/scope.js +6 -4
@@ -0,0 +1,550 @@
1
+ # -*- coding: utf-8 -*-
2
+ """Render a design_spec.yaml into a 画面設計書 .xlsx via Excel COM.
3
+
4
+ python build_design_xlsx.py --spec docs/screen_design/design_spec.yaml
5
+ python build_design_xlsx.py --spec ... --sheets 処理
6
+ python build_design_xlsx.py --spec ... --out /tmp/preview.xlsx
7
+
8
+ Requires Windows + desktop Excel + pywin32. openpyxl cannot be used to save these
9
+ workbooks: it drops every drawing on every sheet it does not rewrite.
10
+
11
+ Rendering a sheet WIPES and rebuilds it: on an existing workbook --sheets is required, a workbook marked
12
+ `final` is never rendered, and one changed since the last render (render stamp beside the spec) needs
13
+ --accept-hand-edits after the person confirmed. Preflight and backup come from sdtk-xlsx-safe-edit. Rows 3..(2+block_rows) of each block sheet are treated as the
14
+ in-file block template and are stamped down the sheet; keep them clean.
15
+ """
16
+ from __future__ import annotations
17
+
18
+ import argparse
19
+ import os
20
+ import shutil
21
+ import sys
22
+
23
+ sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
24
+ from design_spec import (PROCESS_SHEET, block_starts, # noqa: E402
25
+ col_to_index, force_utf8_stdio, iter_process_sheets, load_spec,
26
+ main_process_sheet, previous_sheet_names, render_plan, write_stamp)
27
+
28
+ win32 = None # imported in main(), after the render plan passed
29
+
30
+ # ---- Excel / Office enums (raw values; the COM constants module is unreliable) -----
31
+ msoRect, msoOval, msoDecision = 1, 9, 63
32
+ msoConnStraight, msoConnElbow = 1, 2
33
+ msoTrue, msoFalse = -1, 0
34
+ xlMove = 2
35
+ xlContinuous, xlThin = 1, 2
36
+ xlPageBreakManual = -4135
37
+ HEADER_FILL = 0xD9D9D9
38
+
39
+ # ---- flowchart geometry, in points (see the template set TEMPLATE.md §4) ----------
40
+ BOX_W, BOX_H = 146.25, 42.75
41
+ DEC_W, DEC_H = 104.0, 54.0
42
+ STA_W, STA_H = 24.75, 28.50
43
+ END_W, END_H = 25.50, 28.50
44
+ MAIN_COL = 4 # column D
45
+ NODE_PITCH = 5 # rows between nodes
46
+ BODY_PT = 8 # block-body font size
47
+ MARKER_PT = 15.0 # 画面流れ overlay marker diameter
48
+ GRID_COLS = 76 # A..BX — the styled part of the grid
49
+
50
+
51
+ # =====================================================================================
52
+ # low-level helpers
53
+ # =====================================================================================
54
+ def put(ws, row, col, text):
55
+ if text is None or text == "":
56
+ return
57
+ ws.Cells(row, col_to_index(col)).Value = text
58
+
59
+
60
+ def style_shape(sh, text=None, align=1, size=BODY_PT, tight=False):
61
+ sh.Placement = xlMove
62
+ sh.Fill.Visible = msoTrue
63
+ sh.Fill.ForeColor.RGB = 0xFFFFFF
64
+ sh.Line.Visible = msoTrue
65
+ sh.Line.ForeColor.RGB = 0x000000
66
+ sh.Line.Weight = 1.25
67
+ tf = sh.TextFrame2
68
+ tf.AutoSize = 0
69
+ tf.WordWrap = msoTrue
70
+ tf.VerticalAnchor = 3 # msoAnchorMiddle
71
+ tf.MarginLeft = tf.MarginRight = 0 if tight else 3
72
+ tf.MarginTop = tf.MarginBottom = 0 if tight else 1
73
+ if text:
74
+ tf.TextRange.Text = str(text).replace("\n", "\r")
75
+ f = tf.TextRange.Font
76
+ f.Size = size
77
+ f.Name = "MS Pゴシック"
78
+ f.Fill.ForeColor.RGB = 0x000000
79
+ tf.TextRange.ParagraphFormat.Alignment = align
80
+ return sh
81
+
82
+
83
+ def arrow(ws, x1, y1, x2, y2, elbow=False):
84
+ c = ws.Shapes.AddConnector(msoConnElbow if elbow else msoConnStraight, x1, y1, x2, y2)
85
+ c.Placement = xlMove
86
+ c.Line.ForeColor.RGB = 0x000000
87
+ c.Line.Weight = 1.0
88
+ c.Line.EndArrowheadStyle = 2 # msoArrowheadTriangle
89
+ c.Line.EndArrowheadWidth = 2
90
+ c.Line.EndArrowheadLength = 2
91
+ return c
92
+
93
+
94
+ def terminator(ws, cx, top, start):
95
+ w, h = (STA_W, STA_H) if start else (END_W, END_H)
96
+ o = ws.Shapes.AddShape(msoOval, cx - w / 2, top, w, h)
97
+ style_shape(o)
98
+ o.Line.Weight = 1.5
99
+ if not start:
100
+ iw, ih = w * 0.58, h * 0.58
101
+ i = ws.Shapes.AddShape(msoOval, cx - iw / 2, top + (h - ih) / 2, iw, ih)
102
+ style_shape(i)
103
+ i.Fill.Visible = msoFalse
104
+ i.Line.Weight = 1.25
105
+ return o
106
+
107
+
108
+ def table(ws, top, columns, rows):
109
+ """Bordered table with a grey header. Returns the first free row below it."""
110
+ cols = [(c["title"], col_to_index(c["col"]), int(c["span"])) for c in columns]
111
+ r = top
112
+ for title, c, span in cols:
113
+ ws.Cells(r, c).Value = title
114
+ if span > 1:
115
+ ws.Range(ws.Cells(r, c), ws.Cells(r, c + span - 1)).Merge()
116
+ for data in rows:
117
+ r += 1
118
+ for (title, c, span), v in zip(cols, data):
119
+ if v not in (None, ""):
120
+ ws.Cells(r, c).Value = v
121
+ if span > 1:
122
+ ws.Range(ws.Cells(r, c), ws.Cells(r, c + span - 1)).Merge()
123
+ c0, c1 = cols[0][1], cols[-1][1] + cols[-1][2] - 1
124
+ rng = ws.Range(ws.Cells(top, c0), ws.Cells(r, c1))
125
+ for edge in (7, 8, 9, 10, 11, 12): # l r t b inside-v inside-h
126
+ b = rng.Borders(edge)
127
+ b.LineStyle = xlContinuous
128
+ b.Weight = xlThin
129
+ ws.Range(ws.Cells(top, c0), ws.Cells(top, c1)).Interior.Color = HEADER_FILL
130
+ return r + 1
131
+
132
+
133
+ # =====================================================================================
134
+ # block sheet scaffolding
135
+ # =====================================================================================
136
+ def clear_block_values(ws, block_rows):
137
+ """Blank the first block's content so it can serve as the stamp template.
138
+
139
+ Values only — formats, borders and merges ARE the template. Row 3 keeps its static
140
+ labels (処理番号/画面ID, 画面名, 機能概要, and on 画面流れ the UI item table header);
141
+ only its three value cells are cleared. Without this, re-rendering an already-populated
142
+ workbook stamps the first block's leftover text into every following block.
143
+ """
144
+ for ref in ("E3", "M3", "AA3"):
145
+ ws.Range(ref).MergeArea.Cells(1, 1).Value = None
146
+ rng = ws.Range(ws.Cells(4, 1), ws.Cells(block_rows + 2, GRID_COLS + 4))
147
+ try:
148
+ used = rng.SpecialCells(2) # xlCellTypeConstants
149
+ except Exception:
150
+ return # already empty
151
+ for area in used.Areas:
152
+ for cell in area.Cells:
153
+ cell.MergeArea.Cells(1, 1).Value = None
154
+
155
+
156
+ def stamp_blocks(ws, n_blocks, block_rows):
157
+ """Wipe the sheet below the first block and stamp `n_blocks` copies of rows 3..N."""
158
+ for sh in list(ws.Shapes):
159
+ sh.Delete()
160
+ starts = block_starts(n_blocks, block_rows)
161
+ last = starts[-1] + block_rows
162
+ scratch = ws.Range(ws.Cells(starts[0] + block_rows, 1), ws.Cells(last + 60, GRID_COLS + 4))
163
+ scratch.UnMerge()
164
+ scratch.Clear()
165
+ clear_block_values(ws, block_rows)
166
+ ws.Rows("1:%d" % last).RowHeight = 13.5
167
+ tpl = ws.Range(ws.Cells(3, 1), ws.Cells(block_rows + 2, GRID_COLS + 4))
168
+ for s in starts[1:]:
169
+ tpl.Copy(ws.Cells(s, 1))
170
+ ws.Application.CutCopyMode = 0
171
+ ws.ResetAllPageBreaks()
172
+ for s in starts[1:]:
173
+ ws.Rows(s).PageBreak = xlPageBreakManual
174
+ return starts, last
175
+
176
+
177
+ #: document-header cells -> meta key. The second tuple is 画面流れ's right-hand page header.
178
+ META_CELLS = (("Z1", "user"), ("Z2", "business"), ("AO2", "version"),
179
+ ("AU1", "author"), ("AU2", "created"), ("BD1", "updater"), ("BD2", "updated"))
180
+ META_CELLS_RIGHT = (("BP1", "user"), ("BP2", "business"), ("BS2", "version"),
181
+ ("BU1", "author"), ("BU2", "created"),
182
+ ("BW1", "updater"), ("BW2", "updated"))
183
+
184
+
185
+ def write_meta(ws, meta, title, right_header=False):
186
+ ws.Range("A1").Value = title
187
+ cells = META_CELLS + (META_CELLS_RIGHT if right_header else ())
188
+ if right_header:
189
+ ws.Range("BK1").Value = title
190
+ for cell, key in cells:
191
+ v = meta.get(key)
192
+ if v not in (None, ""):
193
+ ws.Range(cell).Value = v
194
+
195
+
196
+ # =====================================================================================
197
+ # sheet: 処理
198
+ # =====================================================================================
199
+ def render_processes(ws, spec, blocks=None):
200
+ blocks = spec.get("processes") if blocks is None else blocks
201
+ if not blocks:
202
+ return
203
+ block_rows = spec["workbook"]["block_rows"]
204
+ meta = spec["workbook"]["meta"]
205
+ starts, last = stamp_blocks(ws, len(blocks), block_rows)
206
+ write_meta(ws, meta, meta.get("title", "画面設計書"))
207
+
208
+ for s, blk in zip(starts, blocks):
209
+ ws.Range(ws.Cells(s + 2, 1), ws.Cells(s + block_rows - 1, GRID_COLS)).Font.Size = BODY_PT
210
+ put(ws, s, "E", blk.get("id") or blk.get("no"))
211
+ put(ws, s, "M", blk.get("screen"))
212
+ put(ws, s, "AA", blk.get("summary"))
213
+ if blk.get("kind") == "flow":
214
+ _flow_page(ws, s, blk)
215
+ else:
216
+ _detail_page(ws, s, blk)
217
+
218
+ ws.Rows("%d:%d" % (last, last + 60)).Delete()
219
+
220
+
221
+ def _flow_page(ws, s, blk):
222
+ main_x = ws.Cells(1, MAIN_COL).Left + BOX_W / 2
223
+ trigger = blk.get("trigger") or []
224
+ for i, line in enumerate(trigger[:2]):
225
+ put(ws, s + 3 + i, "L", line)
226
+
227
+ top = ws.Cells(s + 4, 1).Top
228
+ terminator(ws, main_x, top, start=True)
229
+ prev_bottom = top + STA_H
230
+
231
+ nodes = blk.get("nodes") or []
232
+ for i, nd in enumerate(nodes):
233
+ mrow = s + 7 + i * NODE_PITCH
234
+ top = ws.Cells(mrow + 1, 1).Top
235
+ arrow(ws, main_x, prev_bottom, main_x, top)
236
+
237
+ if nd.get("type") == "box":
238
+ style_shape(ws.Shapes.AddShape(msoRect, main_x - BOX_W / 2, top, BOX_W, BOX_H),
239
+ nd.get("text"), align=1)
240
+ put(ws, mrow, MAIN_COL, nd.get("n"))
241
+ put(ws, mrow, MAIN_COL + 1, nd.get("sub"))
242
+ prev_bottom = top + BOX_H
243
+ else:
244
+ style_shape(ws.Shapes.AddShape(msoDecision, main_x - DEC_W / 2, top, DEC_W, DEC_H),
245
+ nd.get("text"), align=2, size=7, tight=True)
246
+ put(ws, mrow, MAIN_COL + 1, nd.get("n"))
247
+ br = nd.get("branch") or {}
248
+ sx = main_x + DEC_W / 2 + 72
249
+ arrow(ws, main_x + DEC_W / 2, top + DEC_H / 2, sx, top + DEC_H / 2)
250
+ put(ws, mrow + 1, MAIN_COL + 9, br.get("label"))
251
+ style_shape(ws.Shapes.AddShape(msoRect, sx, top, BOX_W, BOX_H),
252
+ br.get("text"), align=1)
253
+ put(ws, mrow, MAIN_COL + 15, br.get("n"))
254
+ put(ws, mrow + 4, MAIN_COL + 1, nd.get("else_label"))
255
+ if br.get("terminate"):
256
+ ty = top + BOX_H + 25
257
+ arrow(ws, sx + BOX_W / 2, top + BOX_H, sx + BOX_W / 2, ty)
258
+ terminator(ws, sx + BOX_W / 2, ty, start=False)
259
+ put(ws, mrow + 6, MAIN_COL + 23, "処理終了")
260
+ else:
261
+ arrow(ws, sx + BOX_W / 2, top + BOX_H, main_x,
262
+ ws.Cells(mrow + NODE_PITCH + 1, 1).Top, elbow=True)
263
+ prev_bottom = top + DEC_H
264
+
265
+ erow = s + 7 + len(nodes) * NODE_PITCH
266
+ top = ws.Cells(erow, 1).Top
267
+ arrow(ws, main_x, prev_bottom, main_x, top)
268
+ terminator(ws, main_x, top, start=False)
269
+ put(ws, erow, "L", "処理終了")
270
+
271
+ ac = col_to_index(blk.get("ann_col", "X"))
272
+ r = s + 6
273
+ for note in blk.get("notes") or []:
274
+ put(ws, r, ac, note.get("mark"))
275
+ for j, line in enumerate(note.get("lines") or []):
276
+ put(ws, r + j, ac + 1, line)
277
+ r += len(note.get("lines") or []) + 1
278
+
279
+
280
+ def _detail_page(ws, s, blk):
281
+ put(ws, s + 2, MAIN_COL, blk.get("sub_no"))
282
+ put(ws, s + 2, "I", blk.get("sub_name"))
283
+ r = s + 4
284
+ for sec in blk.get("sections") or []:
285
+ put(ws, r, MAIN_COL, "■")
286
+ put(ws, r, MAIN_COL + 1, sec.get("head"))
287
+ r += 1
288
+ if sec.get("columns"):
289
+ r = table(ws, r, sec["columns"], sec.get("rows") or [])
290
+ for note in sec.get("notes") or []:
291
+ put(ws, r, MAIN_COL + 2, "・" + note)
292
+ r += 1
293
+ r += 1
294
+
295
+
296
+ # =====================================================================================
297
+ # sheet: 画面流れ
298
+ # =====================================================================================
299
+ def render_screens(ws, spec):
300
+ screens = spec.get("screens") or []
301
+ if not screens:
302
+ return
303
+ block_rows = spec["workbook"]["block_rows"]
304
+ meta = spec["workbook"]["meta"]
305
+ starts, last = stamp_blocks(ws, len(screens), block_rows)
306
+ write_meta(ws, meta, meta.get("title", "画面設計書"), right_header=True)
307
+
308
+ for s, scr in zip(starts, screens):
309
+ put(ws, s, "E", scr.get("id"))
310
+ put(ws, s, "M", scr.get("name"))
311
+ put(ws, s, "AA", scr.get("summary"))
312
+ put(ws, s + 2, "A", scr.get("source_label", "Figma"))
313
+
314
+ img_box = None
315
+ if scr.get("image"):
316
+ left = ws.Cells(s + 2, 1).Left
317
+ top = ws.Cells(s + 2, 1).Top
318
+ pic = ws.Shapes.AddPicture(scr["image"], msoFalse, msoTrue, left, top, -1, -1)
319
+ width = float(scr.get("image_width_pt", 571))
320
+ pic.LockAspectRatio = msoTrue
321
+ pic.Width = width
322
+ pic.Placement = xlMove
323
+ img_box = (pic.Left, pic.Top, pic.Width, pic.Height)
324
+
325
+ for m in scr.get("markers") or []:
326
+ if img_box is None:
327
+ break
328
+ bx, by, bw, bh = img_box
329
+ cx = bx + float(m["x"]) * bw
330
+ cy = by + float(m["y"]) * bh
331
+ sh = ws.Shapes.AddShape(msoOval, cx - MARKER_PT / 2, cy - MARKER_PT / 2,
332
+ MARKER_PT, MARKER_PT)
333
+ sh.Placement = xlMove
334
+ sh.Fill.Visible = msoTrue
335
+ sh.Fill.ForeColor.RGB = 0xFFFFFF
336
+ sh.Line.ForeColor.RGB = 0x0000FF # BGR -> red
337
+ sh.Line.Weight = 1.0
338
+ tf = sh.TextFrame2
339
+ tf.AutoSize = 0
340
+ tf.WordWrap = msoFalse
341
+ tf.VerticalAnchor = 3
342
+ tf.MarginLeft = tf.MarginRight = tf.MarginTop = tf.MarginBottom = 0
343
+ tf.TextRange.Text = str(m["n"])
344
+ tf.TextRange.Font.Size = 9
345
+ tf.TextRange.Font.Bold = msoTrue
346
+ tf.TextRange.Font.Fill.ForeColor.RGB = 0x0000FF
347
+ tf.TextRange.ParagraphFormat.Alignment = 2
348
+
349
+ r = s + 1 # the table header sits on the block row
350
+ for item in scr.get("items") or []:
351
+ for col, key in (("BK", "name"), ("BL", "kind"), ("BM", "attr"), ("BN", "db"),
352
+ ("BO", "len"), ("BP", "default"), ("BQ", "required"),
353
+ ("BR", "note"), ("BZ", "note_alt")):
354
+ put(ws, r, col, item.get(key))
355
+ r += 1
356
+
357
+ remarks = scr.get("remarks") or []
358
+ if remarks:
359
+ rr = s + block_rows - 10
360
+ put(ws, rr, "A", "<備考>")
361
+ rr += 1
362
+ for rem in remarks:
363
+ put(ws, rr, "C", rem.get("text"))
364
+ rr += 1
365
+ if rem.get("alt"):
366
+ put(ws, rr, "C", rem["alt"])
367
+ rr += 1
368
+
369
+ ws.Rows("%d:%d" % (last, last + 60)).Delete()
370
+
371
+
372
+ # =====================================================================================
373
+ # sheets: 改訂記事 / 機能概要 / 表紙
374
+ # =====================================================================================
375
+ def render_history(ws, spec):
376
+ entries = spec.get("history") or []
377
+ if not entries:
378
+ return
379
+ ws.Range(ws.Cells(5, 1), ws.Cells(400, 8)).Clear()
380
+ r = 5
381
+ for e in entries:
382
+ put(ws, r, "B", e.get("date"))
383
+ put(ws, r + 1, "C", "■%s版" % e.get("version"))
384
+ r += 2
385
+ for line in e.get("items") or []:
386
+ put(ws, r, "C", "|")
387
+ put(ws, r, "D", line)
388
+ r += 1
389
+ r += 1
390
+ # Clear() also drops the row formatting, so restore the sheet's own font sizes
391
+ body = ws.Range(ws.Cells(5, 2), ws.Cells(r, 4))
392
+ body.Font.Name = "MS Pゴシック"
393
+ body.Font.Size = 10
394
+ ws.Range(ws.Cells(5, 4), ws.Cells(r, 4)).Font.Size = 9
395
+
396
+
397
+ def render_overview(ws, spec):
398
+ groups = spec.get("overview") or []
399
+ if not groups:
400
+ return
401
+ ws.Range(ws.Cells(1, 1), ws.Cells(400, 8)).Clear()
402
+ r = 1
403
+ for g in groups:
404
+ put(ws, r, "A", g.get("heading"))
405
+ r += 1
406
+ for item in g.get("items") or []:
407
+ if isinstance(item, dict):
408
+ put(ws, r, "C", item.get("sub"))
409
+ else:
410
+ put(ws, r, "B", item)
411
+ r += 1
412
+ for grp in g.get("groups") or []:
413
+ put(ws, r, "B", grp.get("name"))
414
+ r += 1
415
+ for item in grp.get("items") or []:
416
+ put(ws, r, "B", item)
417
+ r += 1
418
+ r += 1
419
+ r += 1
420
+
421
+
422
+ def render_cover(ws, spec):
423
+ cov = spec.get("cover")
424
+ if not cov:
425
+ return
426
+ if cov.get("title"):
427
+ ws.Range("H9").Value = cov["title"]
428
+ if cov.get("date"):
429
+ ws.Range("U37").Value = cov["date"]
430
+
431
+
432
+ def worksheet(wb, name, was=None, clone_from=PROCESS_SHEET):
433
+ """The sheet called `name`: the tab formerly called `was` renamed, or a clone of the process sheet if neither exists.
434
+
435
+ A cloned sheet arrives with the house grid, page setup and a populated first block;
436
+ stamp_blocks() then deletes its shapes and blanks rows 3..42 back into a template.
437
+ """
438
+ names = [wb.Worksheets(i).Name for i in range(1, wb.Worksheets.Count + 1)]
439
+ if name in names:
440
+ return wb.Worksheets(name)
441
+ if was and was in names:
442
+ ws = wb.Worksheets(was)
443
+ ws.Name = name
444
+ print("renamed sheet %r -> %r" % (was, name))
445
+ return ws
446
+ src = wb.Worksheets(clone_from if clone_from in names else PROCESS_SHEET)
447
+ src.Copy(After=src) # keep the 処理 family together
448
+ ws = wb.Worksheets(src.Index + 1)
449
+ ws.Name = name
450
+ print("created sheet %r (cloned from %s)" % (name, src.Name))
451
+ return ws
452
+
453
+
454
+ RENDERERS = {
455
+ "表紙": render_cover,
456
+ "改訂記事": render_history,
457
+ "機能概要": render_overview,
458
+ "画面流れ": render_screens,
459
+ "処理": render_processes,
460
+ }
461
+
462
+
463
+ # =====================================================================================
464
+ def _safe_edit_module():
465
+ """xlsafe (preflight, backup) from the sibling skill sdtk-xlsx-safe-edit (toolkit or installed layout)."""
466
+ here = os.path.dirname(os.path.abspath(__file__))
467
+ for name in ("sdtk-xlsx-safe-edit", "xlsx-safe-edit"):
468
+ candidate = os.path.normpath(os.path.join(here, "..", "..", name, "scripts"))
469
+ if os.path.isdir(candidate):
470
+ sys.path.insert(0, candidate)
471
+ import xlsafe # noqa: E402
472
+ return xlsafe
473
+ raise SystemExit("sdtk-xlsx-safe-edit is required next to this skill (preflight and backup)")
474
+
475
+
476
+ def main() -> int:
477
+ force_utf8_stdio()
478
+ ap = argparse.ArgumentParser()
479
+ ap.add_argument("--spec", required=True)
480
+ ap.add_argument("--sheets", help="comma-separated; required when the workbook exists (only the sheets you changed)")
481
+ ap.add_argument("--out", help="render a separate preview copy here; workbook.path is not touched")
482
+ ap.add_argument("--backup-dir", help="default: _backup next to the workbook")
483
+ ap.add_argument("--accept-hand-edits", action="store_true",
484
+ help="the person confirmed the named sheets may be rebuilt although the workbook changed "
485
+ "since the last render")
486
+ ap.add_argument("--check", action="store_true",
487
+ help="print what would be rendered (or why not) and stop; needs no Excel")
488
+ args = ap.parse_args()
489
+
490
+ spec = load_spec(args.spec)
491
+ plan = render_plan(spec, args.sheets, args.out, args.accept_hand_edits)
492
+ target, wanted = plan["target"], plan["sheets"]
493
+ if args.check:
494
+ print("would render %s into %s%s" % (", ".join(wanted), target,
495
+ " (created from the template)" if not os.path.exists(target) else ""))
496
+ return 0
497
+ global win32
498
+ try:
499
+ import win32com.client as win32
500
+ except ImportError:
501
+ raise SystemExit("rendering needs Windows + Excel + pywin32 (python -m pip install pywin32)")
502
+ xlsafe = _safe_edit_module()
503
+
504
+ if os.path.exists(target):
505
+ xlsafe.preflight(target) # lock file / same-name workbook open in Excel -> stop
506
+ lock = os.path.join(os.path.dirname(target), "~$" + os.path.basename(target))
507
+ if os.path.exists(lock):
508
+ raise SystemExit("lock file %s exists: if the person has the workbook open, ask them to save and "
509
+ "close it; delete a stale lock only after they confirm" % lock)
510
+ backup = xlsafe.backup(target, args.backup_dir or os.path.join(os.path.dirname(target), "_backup"),
511
+ label="before-render")
512
+ print("backup: %s" % backup)
513
+ else:
514
+ source = plan["copy_of"] or spec["workbook"]["template"]
515
+ if not os.path.exists(source):
516
+ raise SystemExit("no workbook at %s and no template at %s" % (target, source))
517
+ os.makedirs(os.path.dirname(target) or ".", exist_ok=True)
518
+ shutil.copyfile(source, target)
519
+ print("created from %s: %s" % ("the workbook" if plan["copy_of"] else "the template", target))
520
+
521
+ main_sheet = main_process_sheet(spec)
522
+ renderers = {k: v for k, v in RENDERERS.items() if k != PROCESS_SHEET}
523
+ renderers[main_sheet] = RENDERERS[PROCESS_SHEET]
524
+ for name, blocks in iter_process_sheets(spec):
525
+ if name != main_sheet:
526
+ renderers[name] = (lambda ws, sp, _b=blocks: render_processes(ws, sp, _b))
527
+ formerly = previous_sheet_names(spec)
528
+
529
+ xl = win32.DispatchEx("Excel.Application") # a private instance: never the person's open Excel
530
+ xl.Visible = False
531
+ xl.DisplayAlerts = False
532
+ wb = xl.Workbooks.Open(target, UpdateLinks=0)
533
+ saved = False
534
+ try:
535
+ for name in wanted:
536
+ renderers[name](worksheet(wb, name, formerly.get(name), clone_from=main_sheet), spec)
537
+ print("rendered: %s" % name)
538
+ wb.Save()
539
+ saved = True
540
+ finally:
541
+ wb.Close(False) # never save a half-rendered workbook
542
+ xl.Quit()
543
+ if saved and plan["stamp"]:
544
+ write_stamp(spec, wanted)
545
+ print("done: %s" % target)
546
+ return 0
547
+
548
+
549
+ if __name__ == "__main__":
550
+ sys.exit(main())