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,76 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: sdtk-session-handoff
|
|
3
|
+
description: Use when a session is about to end, be compacted or hand over to a new session or another person ("wrap up", "prepare a handoff", "new phase tomorrow"), or when a project folder moved and old sessions must find it; packages memory, local instructions, a handoff document, a classification of every uncommitted file and a first prompt.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# SDTK Session Handoff
|
|
7
|
+
|
|
8
|
+
A new session knows only what it can read. This skill writes it down in the right places, and makes sure no
|
|
9
|
+
uncommitted file is lost or swept into a commit on the way.
|
|
10
|
+
|
|
11
|
+
<!-- neutral-only -->
|
|
12
|
+
> **Installed as a runtime skill** (for example under `.codex/skills/`): read `toolkit/skills/sdtk-session-handoff/`
|
|
13
|
+
> in the paths below as this skill's installed folder.
|
|
14
|
+
<!-- /neutral-only -->
|
|
15
|
+
|
|
16
|
+
## Critical Constraints
|
|
17
|
+
|
|
18
|
+
1. **Every uncommitted file gets a class before the session ends** — `PR`, `LOCAL`, `STASH` or `DROP` — in every
|
|
19
|
+
worktree. `dirty_files.py check` exits 0 before you say the handoff is done.
|
|
20
|
+
2. **Never `git add -A` / `git add .` / `git commit -a`.** A `PR` file is staged by its own path; a `LOCAL` file is never
|
|
21
|
+
staged. `DROP` happens only after the person said so, and is their command to run.
|
|
22
|
+
3. **The handoff document stays out of the repository** (`.sdtk/handoff/`, git-ignored). Check with
|
|
23
|
+
`git check-ignore` first; if it is not ignored, add it to `.git/info/exclude` — never edit the project's
|
|
24
|
+
`.gitignore` for this.
|
|
25
|
+
4. **Memory holds durable facts only** (decisions, conventions, where things are, traps). Work in progress goes in the
|
|
26
|
+
handoff document; facts the repository already records (code, git history, docs) go nowhere.
|
|
27
|
+
5. **Exact facts come from the source, not from a summary.** After a compaction, a summary has lost detail: copy ids,
|
|
28
|
+
versions, paths and commands from files, git or the transcript, and say which you could not check.
|
|
29
|
+
6. **The next session starts in the same folder.** Runtime memory is keyed by the working-directory path; a different
|
|
30
|
+
folder (or a moved project) starts with no memory — see
|
|
31
|
+
`toolkit/skills/sdtk-session-handoff/references/MOVING_A_PROJECT.md`.
|
|
32
|
+
|
|
33
|
+
## Process
|
|
34
|
+
|
|
35
|
+
1. **State.** `git worktree list`; per worktree: branch, upstream, ahead / behind, open PRs if a forge CLI is signed
|
|
36
|
+
in. Released or published versions, running processes the next session must know about (servers, background jobs).
|
|
37
|
+
2. **Uncommitted files.**
|
|
38
|
+
`python toolkit/skills/sdtk-session-handoff/scripts/dirty_files.py inventory --out .sdtk/handoff/<handoff>/FILES.md`,
|
|
39
|
+
fill the `class` and `note` columns (ask the person for anything you cannot place), carry out PR / STASH rows the
|
|
40
|
+
person agreed to, then `dirty_files.py check .sdtk/handoff/<handoff>/FILES.md` until it exits 0.
|
|
41
|
+
3. **Memory.** One durable fact per entry, in the runtime's memory (for Claude Code: one file per fact plus its index
|
|
42
|
+
line); update an entry that exists rather than adding a second one; delete entries proven wrong. When the project
|
|
43
|
+
uses `sdtk-wiki` memory, promote there as well.
|
|
44
|
+
4. **Handoff document** `.sdtk/handoff/<handoff>/HANDOFF.md` + `STATUS.md` from
|
|
45
|
+
`toolkit/skills/sdtk-session-handoff/references/HANDOFF_TEMPLATE.md`: worktrees, what was released, open work with
|
|
46
|
+
its next step, decisions waiting for the person, traps, where the evidence is.
|
|
47
|
+
5. **Local instructions.** Claude Code: `CLAUDE.local.md` at the project root (git-excluded) with the "read first" list
|
|
48
|
+
pointing at the handoff. Other runtimes: the `.sdtk/handoff/` `STATUS.md` is what their bootstrap surfaces.
|
|
49
|
+
6. **First prompt** for the new session (template §4): it makes the session summarize state from the handoff before
|
|
50
|
+
doing anything. When the person pastes that summary back, check it against the handoff and correct every
|
|
51
|
+
difference.
|
|
52
|
+
7. **Keep it current.** When the state changes before the session ends, update the handoff and `FILES.md`, not only
|
|
53
|
+
the chat.
|
|
54
|
+
|
|
55
|
+
## Outputs
|
|
56
|
+
|
|
57
|
+
| File | In git? | For |
|
|
58
|
+
|---|---|---|
|
|
59
|
+
| `.sdtk/handoff/<handoff>/HANDOFF.md`, `STATUS.md`, `FILES.md` | no | the next session / person |
|
|
60
|
+
| `CLAUDE.local.md` (Claude Code) | no (`.git/info/exclude`) | what a new session reads first |
|
|
61
|
+
| runtime memory entries | outside the repository | durable facts |
|
|
62
|
+
|
|
63
|
+
`<handoff>` = `session-<YYYYMMDD>-<topic>`.
|
|
64
|
+
|
|
65
|
+
## When To Stop Or Ask
|
|
66
|
+
|
|
67
|
+
- A dirty file you cannot classify, or one that looks like someone else's work → ask; never guess `DROP`.
|
|
68
|
+
- A `PR` file on the wrong branch → say so; moving it is the person's call.
|
|
69
|
+
- Secrets in a dirty file (`.env`, keys) → class `LOCAL`, never quoted in the handoff.
|
|
70
|
+
|
|
71
|
+
## Scripts
|
|
72
|
+
|
|
73
|
+
| Script | Does |
|
|
74
|
+
|---|---|
|
|
75
|
+
| `dirty_files.py inventory [--repo] [--out]` | table of every dirty path in every worktree, `class` empty |
|
|
76
|
+
| `dirty_files.py check <table> [--repo]` | exit 0 only when every path dirty now has a class (+ note for PR / STASH / DROP) |
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
# Handoff templates
|
|
2
|
+
|
|
3
|
+
## 1. STATUS.md
|
|
4
|
+
|
|
5
|
+
First line is the state; the body says what the next session does first.
|
|
6
|
+
|
|
7
|
+
```
|
|
8
|
+
WAITING_NEXT_SESSION
|
|
9
|
+
Read HANDOFF.md, then FILES.md. First action: <one line>. Waiting on the person for: <decision or none>.
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
States: `WAITING_NEXT_SESSION` (open), `ON_HOLD` (person paused it), `DONE` (picked up and closed).
|
|
13
|
+
|
|
14
|
+
## 2. HANDOFF.md
|
|
15
|
+
|
|
16
|
+
```markdown
|
|
17
|
+
# Handoff — <topic> (<YYYY-MM-DD>)
|
|
18
|
+
|
|
19
|
+
## Where things are
|
|
20
|
+
| Worktree | Branch | Upstream / PR | State |
|
|
21
|
+
|---|---|---|---|
|
|
22
|
+
| /path/app | main | origin/main, clean | — |
|
|
23
|
+
| /path/app-feat | feat/x | PR #12 open, 2 ahead | waiting for review |
|
|
24
|
+
|
|
25
|
+
## Released / published
|
|
26
|
+
- <package / deploy> <version> on <date> — verified by <command>.
|
|
27
|
+
|
|
28
|
+
## Open work (next step first)
|
|
29
|
+
1. <item> — next: <command or action>; done when: <observable result>.
|
|
30
|
+
|
|
31
|
+
## Waiting for the person
|
|
32
|
+
- <decision> — options, your recommendation.
|
|
33
|
+
|
|
34
|
+
## Traps
|
|
35
|
+
- <thing that cost time and how to avoid it>.
|
|
36
|
+
|
|
37
|
+
## Evidence
|
|
38
|
+
- <reports, logs, test output paths>. Facts not re-checked after compaction: <list or none>.
|
|
39
|
+
|
|
40
|
+
## Uncommitted files
|
|
41
|
+
See FILES.md (`dirty_files.py check` exit 0 at <time>).
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## 3. CLAUDE.local.md (Claude Code, git-excluded)
|
|
45
|
+
|
|
46
|
+
```markdown
|
|
47
|
+
# Local notes (this machine only)
|
|
48
|
+
Read first: `.sdtk/handoff/<handoff>/STATUS.md`, then `HANDOFF.md`.
|
|
49
|
+
Open sessions in <project path> (memory is keyed by this path).
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
Exclude it: `echo CLAUDE.local.md >> .git/info/exclude` (check `git check-ignore -v CLAUDE.local.md` first).
|
|
53
|
+
|
|
54
|
+
## 4. First prompt for the new session
|
|
55
|
+
|
|
56
|
+
```
|
|
57
|
+
Read .sdtk/handoff/<handoff>/STATUS.md and HANDOFF.md, then FILES.md. Before doing anything else, reply with:
|
|
58
|
+
1. each worktree, its branch and state; 2. what was released; 3. the open work in order with the next step;
|
|
59
|
+
4. what waits for me; 5. the uncommitted files that are LOCAL or STASH. Do not change anything until I confirm.
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
Checking the answer: every worktree, version and next step must match HANDOFF.md word for word where it names ids,
|
|
63
|
+
versions or paths. A missing or different item → point at the line in HANDOFF.md and ask for a corrected summary.
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# Moving a project folder (resuming old sessions)
|
|
2
|
+
|
|
3
|
+
Agent runtimes key their session history and memory by the project path. After the project moves (new machine, new
|
|
4
|
+
drive, renamed folder), a new session in the new folder sees none of it. The runtime's store is its own private
|
|
5
|
+
format, so this is a manual, careful procedure — not something to script blindly.
|
|
6
|
+
|
|
7
|
+
1. **Back up** the runtime's session folder for the old path (Claude Code: `~/.claude/projects/<encoded old path>/`,
|
|
8
|
+
where the path is encoded by replacing path separators and other non-alphanumeric characters with `-`).
|
|
9
|
+
2. **Dry run.** List every occurrence of the old path in the session logs (`grep -c`), separating fields that *are*
|
|
10
|
+
the working directory (`"cwd"` and similar) from text inside tool results or messages that merely mention it.
|
|
11
|
+
3. **Rewrite only the working-directory fields** in a copy, never the content of tool results or messages. Prefer the
|
|
12
|
+
simplest form: if the person only needs memory, copy the memory folder and leave the logs alone.
|
|
13
|
+
4. **Rename** the copied folder to the encoded new path; keep the backup until a resumed session works.
|
|
14
|
+
5. **Resume** from the new folder (Claude Code: `claude --resume` there) and check one past session opens with the
|
|
15
|
+
right working directory.
|
|
16
|
+
|
|
17
|
+
The backup location is the person's choice — ask; never assume a personal folder. When in doubt, start a new session
|
|
18
|
+
with a handoff (this skill) instead of moving history.
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
"""Inventory and classification check of uncommitted files, for a session handoff.
|
|
3
|
+
|
|
4
|
+
python dirty_files.py inventory [--repo .] [--out HANDOFF_FILES.md] # every worktree, every dirty path
|
|
5
|
+
python dirty_files.py check HANDOFF_FILES.md [--repo .] # every dirty path classified, nothing extra
|
|
6
|
+
|
|
7
|
+
`inventory` writes a Markdown table with an empty `class` column, one row per dirty path of every worktree of the
|
|
8
|
+
repository (`git worktree list`). The session fills `class` with one of:
|
|
9
|
+
|
|
10
|
+
PR goes into a commit / pull request (name the branch in `note`)
|
|
11
|
+
LOCAL stays on this machine, never committed (put it in .git/info/exclude if it keeps showing up)
|
|
12
|
+
STASH parked with `git stash push -- <path>` (name the stash message in `note`)
|
|
13
|
+
DROP to be discarded — only after the person said so (`note`: who / when)
|
|
14
|
+
|
|
15
|
+
`check` exits 0 only when every path that is dirty *now* has a class from that list, and lists paths that became
|
|
16
|
+
dirty or clean since the inventory. It never stages, stashes or deletes anything: the commands stay the person's.
|
|
17
|
+
No `git add -A` — a PR row is staged by its own path.
|
|
18
|
+
"""
|
|
19
|
+
from __future__ import annotations
|
|
20
|
+
|
|
21
|
+
import argparse
|
|
22
|
+
import os
|
|
23
|
+
import re
|
|
24
|
+
import subprocess
|
|
25
|
+
import sys
|
|
26
|
+
|
|
27
|
+
CLASSES = ("PR", "LOCAL", "STASH", "DROP")
|
|
28
|
+
ROW_RE = re.compile(r"^\|\s*`(?P<wt>[^`]*)`\s*\|\s*`(?P<path>[^`]+)`\s*\|\s*(?P<st>[^|]*)\|\s*(?P<cls>[^|]*)\|(?P<note>.*)\|\s*$")
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def git(repo: str, *args: str) -> str:
|
|
32
|
+
env = {**os.environ, "GIT_TERMINAL_PROMPT": "0", "GIT_OPTIONAL_LOCKS": "0"}
|
|
33
|
+
r = subprocess.run(["git", "-C", repo, *args], capture_output=True, text=True, encoding="utf-8", env=env,
|
|
34
|
+
timeout=60, check=False)
|
|
35
|
+
if r.returncode != 0:
|
|
36
|
+
raise SystemExit("git %s failed in %s: %s" % (" ".join(args), repo, r.stderr.strip()))
|
|
37
|
+
return r.stdout
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def worktrees(repo: str) -> list:
|
|
41
|
+
out, paths = git(repo, "worktree", "list", "--porcelain"), []
|
|
42
|
+
for line in out.splitlines():
|
|
43
|
+
if line.startswith("worktree "):
|
|
44
|
+
paths.append(line[len("worktree "):])
|
|
45
|
+
return [p for p in paths if os.path.isdir(p)]
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def dirty(wt: str) -> list:
|
|
49
|
+
"""(status, path) for every changed, staged or untracked path; ignored files are not listed."""
|
|
50
|
+
out = git(wt, "status", "--porcelain=v1", "-z", "--untracked-files=all")
|
|
51
|
+
items, parts, i = [], out.split("\0"), 0
|
|
52
|
+
while i < len(parts):
|
|
53
|
+
entry = parts[i]
|
|
54
|
+
i += 1
|
|
55
|
+
if not entry:
|
|
56
|
+
continue
|
|
57
|
+
status, path = entry[:2], entry[3:]
|
|
58
|
+
if status[0] in "RC": # rename / copy: the next field is the source path
|
|
59
|
+
path = "%s (from %s)" % (path, parts[i])
|
|
60
|
+
i += 1
|
|
61
|
+
items.append((status.replace(" ", "."), path))
|
|
62
|
+
return items
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def snapshot(repo: str) -> dict:
|
|
66
|
+
main = os.path.realpath(worktrees(repo)[0]) if worktrees(repo) else os.path.realpath(repo)
|
|
67
|
+
snap = {}
|
|
68
|
+
for wt in worktrees(repo):
|
|
69
|
+
label = "." if os.path.realpath(wt) == main else os.path.relpath(os.path.realpath(wt), os.path.dirname(main))
|
|
70
|
+
for status, path in dirty(wt):
|
|
71
|
+
snap[(label, path)] = status
|
|
72
|
+
return snap
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
def inventory(repo: str) -> str:
|
|
76
|
+
snap = snapshot(repo)
|
|
77
|
+
branch = {}
|
|
78
|
+
for wt in worktrees(repo):
|
|
79
|
+
branch[wt] = git(wt, "branch", "--show-current").strip() or "(detached)"
|
|
80
|
+
lines = ["# Uncommitted files", "",
|
|
81
|
+
"Worktrees: " + "; ".join("`%s` on `%s`" % (w, b) for w, b in branch.items()), "",
|
|
82
|
+
"Fill `class` with PR / LOCAL / STASH / DROP (see dirty_files.py). Then `dirty_files.py check` this file.", "",
|
|
83
|
+
"| worktree | path | status | class | note |", "|---|---|---|---|---|"]
|
|
84
|
+
for (wt, path), status in sorted(snap.items()):
|
|
85
|
+
lines.append("| `%s` | `%s` | %s | | |" % (wt, path, status))
|
|
86
|
+
if not snap:
|
|
87
|
+
lines.append("| | | | | nothing uncommitted |")
|
|
88
|
+
return "\n".join(lines) + "\n"
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
def check(repo: str, table: str) -> tuple[int, list]:
|
|
92
|
+
rows = {}
|
|
93
|
+
with open(table, encoding="utf-8") as f:
|
|
94
|
+
for line in f:
|
|
95
|
+
m = ROW_RE.match(line.strip())
|
|
96
|
+
if m:
|
|
97
|
+
rows[(m["wt"], m["path"])] = (m["cls"].strip().upper(), m["note"].strip())
|
|
98
|
+
now = snapshot(repo)
|
|
99
|
+
problems = []
|
|
100
|
+
for key in sorted(now):
|
|
101
|
+
if key not in rows:
|
|
102
|
+
problems.append("not in the table (became dirty after the inventory): %s %s" % key)
|
|
103
|
+
elif rows[key][0] not in CLASSES:
|
|
104
|
+
problems.append("no class: %s %s" % key)
|
|
105
|
+
elif rows[key][0] in ("PR", "STASH", "DROP") and not rows[key][1]:
|
|
106
|
+
problems.append("%s needs a note (branch / stash message / who said so): %s %s" % ((rows[key][0],) + key))
|
|
107
|
+
for key in sorted(set(rows) - set(now)):
|
|
108
|
+
problems.append("in the table but no longer dirty (committed, stashed or reverted?): %s %s" % key)
|
|
109
|
+
return (0 if not problems else 1), problems
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
def main(argv=None) -> int:
|
|
113
|
+
ap = argparse.ArgumentParser(description=__doc__.split("\n")[0])
|
|
114
|
+
sub = ap.add_subparsers(dest="cmd", required=True)
|
|
115
|
+
p = sub.add_parser("inventory"); p.add_argument("--repo", default="."); p.add_argument("--out")
|
|
116
|
+
p = sub.add_parser("check"); p.add_argument("table"); p.add_argument("--repo", default=".")
|
|
117
|
+
args = ap.parse_args(argv)
|
|
118
|
+
if args.cmd == "inventory":
|
|
119
|
+
text = inventory(args.repo)
|
|
120
|
+
if args.out:
|
|
121
|
+
with open(args.out, "w", encoding="utf-8") as f:
|
|
122
|
+
f.write(text)
|
|
123
|
+
print("%s (%d dirty paths)" % (args.out, text.count("\n| `")))
|
|
124
|
+
else:
|
|
125
|
+
sys.stdout.write(text)
|
|
126
|
+
return 0
|
|
127
|
+
code, problems = check(args.repo, args.table)
|
|
128
|
+
print("\n".join(problems) if problems else "every dirty path is classified")
|
|
129
|
+
return code
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
if __name__ == "__main__":
|
|
133
|
+
sys.exit(main())
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
"""dirty_files.py against a throw-away repository with a second worktree."""
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import os
|
|
6
|
+
import shutil
|
|
7
|
+
import subprocess
|
|
8
|
+
import sys
|
|
9
|
+
import tempfile
|
|
10
|
+
import unittest
|
|
11
|
+
|
|
12
|
+
HERE = os.path.dirname(os.path.abspath(__file__))
|
|
13
|
+
sys.path.insert(0, HERE)
|
|
14
|
+
import dirty_files # noqa: E402
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def sh(cwd, *args):
|
|
18
|
+
subprocess.run(args, cwd=cwd, check=True, capture_output=True)
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
class DirtyFilesTests(unittest.TestCase):
|
|
22
|
+
def setUp(self):
|
|
23
|
+
self.tmp = tempfile.mkdtemp()
|
|
24
|
+
self.repo = os.path.join(self.tmp, "app")
|
|
25
|
+
os.makedirs(self.repo)
|
|
26
|
+
sh(self.repo, "git", "init", "-q", "-b", "main")
|
|
27
|
+
sh(self.repo, "git", "config", "user.email", "a@example.invalid")
|
|
28
|
+
sh(self.repo, "git", "config", "user.name", "A")
|
|
29
|
+
for name in ("a.py", "b.py", ".gitignore"):
|
|
30
|
+
with open(os.path.join(self.repo, name), "w") as f:
|
|
31
|
+
f.write("x\n" if name != ".gitignore" else "*.log\n")
|
|
32
|
+
sh(self.repo, "git", "add", "-A")
|
|
33
|
+
sh(self.repo, "git", "commit", "-qm", "init")
|
|
34
|
+
sh(self.repo, "git", "worktree", "add", "-q", "-b", "feat", os.path.join(self.tmp, "app-feat"))
|
|
35
|
+
with open(os.path.join(self.repo, "a.py"), "a") as f:
|
|
36
|
+
f.write("change\n")
|
|
37
|
+
with open(os.path.join(self.repo, "notes.md"), "w") as f:
|
|
38
|
+
f.write("mine\n")
|
|
39
|
+
with open(os.path.join(self.repo, "run.log"), "w") as f:
|
|
40
|
+
f.write("ignored\n")
|
|
41
|
+
with open(os.path.join(self.tmp, "app-feat", "b.py"), "a") as f:
|
|
42
|
+
f.write("wip\n")
|
|
43
|
+
self.table = os.path.join(self.tmp, "FILES.md")
|
|
44
|
+
|
|
45
|
+
def tearDown(self):
|
|
46
|
+
shutil.rmtree(self.tmp, ignore_errors=True)
|
|
47
|
+
|
|
48
|
+
def fill(self, mapping):
|
|
49
|
+
with open(self.table, encoding="utf-8") as f:
|
|
50
|
+
text = f.read()
|
|
51
|
+
for path, (cls, note) in mapping.items():
|
|
52
|
+
text = text.replace("| `%s` | .M | | |" % path, "| `%s` | .M | %s | %s |" % (path, cls, note))
|
|
53
|
+
text = text.replace("| `%s` | ?? | | |" % path, "| `%s` | ?? | %s | %s |" % (path, cls, note))
|
|
54
|
+
with open(self.table, "w", encoding="utf-8") as f:
|
|
55
|
+
f.write(text)
|
|
56
|
+
|
|
57
|
+
def test_inventory_covers_every_worktree_and_skips_ignored_files(self):
|
|
58
|
+
dirty_files.main(["inventory", "--repo", self.repo, "--out", self.table])
|
|
59
|
+
with open(self.table, encoding="utf-8") as f:
|
|
60
|
+
text = f.read()
|
|
61
|
+
self.assertIn("| `.` | `a.py` | .M |", text)
|
|
62
|
+
self.assertIn("| `.` | `notes.md` | ?? |", text)
|
|
63
|
+
self.assertIn("| `app-feat` | `b.py` | .M |", text)
|
|
64
|
+
self.assertNotIn("run.log", text)
|
|
65
|
+
self.assertIn("on `feat`", text)
|
|
66
|
+
|
|
67
|
+
def test_check_needs_a_class_for_every_path_and_notes_where_they_matter(self):
|
|
68
|
+
dirty_files.main(["inventory", "--repo", self.repo, "--out", self.table])
|
|
69
|
+
code, problems = dirty_files.check(self.repo, self.table)
|
|
70
|
+
self.assertEqual(code, 1)
|
|
71
|
+
self.assertEqual(len([p for p in problems if p.startswith("no class")]), 3)
|
|
72
|
+
self.fill({"a.py": ("PR", ""), "notes.md": ("LOCAL", ""), "b.py": ("STASH", "wip on feat")})
|
|
73
|
+
code, problems = dirty_files.check(self.repo, self.table)
|
|
74
|
+
self.assertEqual(problems, ["PR needs a note (branch / stash message / who said so): . a.py"])
|
|
75
|
+
with open(self.table, encoding="utf-8") as f:
|
|
76
|
+
text = f.read().replace("| `a.py` | .M | PR | |", "| `a.py` | .M | PR | branch fix/a |")
|
|
77
|
+
with open(self.table, "w", encoding="utf-8") as f:
|
|
78
|
+
f.write(text)
|
|
79
|
+
self.assertEqual(dirty_files.check(self.repo, self.table), (0, []))
|
|
80
|
+
|
|
81
|
+
def test_check_sees_paths_that_changed_since_the_inventory(self):
|
|
82
|
+
dirty_files.main(["inventory", "--repo", self.repo, "--out", self.table])
|
|
83
|
+
self.fill({"a.py": ("PR", "fix/a"), "notes.md": ("LOCAL", ""), "b.py": ("STASH", "wip")})
|
|
84
|
+
with open(os.path.join(self.repo, "new.py"), "w") as f:
|
|
85
|
+
f.write("late\n")
|
|
86
|
+
sh(self.repo, "git", "checkout", "--", "a.py")
|
|
87
|
+
code, problems = dirty_files.check(self.repo, self.table)
|
|
88
|
+
self.assertEqual(code, 1)
|
|
89
|
+
self.assertIn("not in the table (became dirty after the inventory): . new.py", problems)
|
|
90
|
+
self.assertIn("in the table but no longer dirty (committed, stashed or reverted?): . a.py", problems)
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
if __name__ == "__main__":
|
|
94
|
+
unittest.main()
|
|
@@ -125,6 +125,9 @@ of truth. Do **not** re-render it, not even one sheet, unless the person says so
|
|
|
125
125
|
- Layout: `layout_diff(backup, result, skip_sheets=[...])` is empty for untouched sheets.
|
|
126
126
|
- Content: read the written cells back; picture counts per sheet unchanged elsewhere.
|
|
127
127
|
- Pictures: every picture ends above the next heading (`insert_pictures_below` checks it).
|
|
128
|
+
- Leaving the team (a template, a deliverable, a shared copy): `python toolkit/skills/sdtk-xlsx-safe-edit/scripts/xlsx_xml_edit.py
|
|
129
|
+
scan-metadata <file> --name <customer> --name <product> …` exits 0 — author / company fields, the saved absolute
|
|
130
|
+
path and the names are checked in **every** part (sharedStrings, comments, drawings, docProps), not only cell values.
|
|
128
131
|
|
|
129
132
|
## Pitfalls seen in practice
|
|
130
133
|
|
|
@@ -138,7 +141,7 @@ of truth. Do **not** re-render it, not even one sheet, unless the person says so
|
|
|
138
141
|
| Reading page breaks through COM (`HPageBreaks`) | Throws on some sheets | Read `row_breaks` with openpyxl (read-only) |
|
|
139
142
|
| Windows paths in a heredoc script | `\` sequences mangled | Write scripts with a file tool; raw strings |
|
|
140
143
|
| Screenshots for the document | Desktop corners, personal data (e-mail, tokens, user names) | Trim ~8 px; point out personal data before publishing |
|
|
141
|
-
| Metadata of a shared template (`docProps`)
|
|
144
|
+
| Metadata of a shared template or deliverable | Author / company names (`docProps`), the saved folder (`xl/workbook.xml` `x15ac:absPath`) and names in sharedStrings / comments travel with the file | Clear `dc:creator`, `cp:lastModifiedBy`, `Company`, the `absPath` element; `scan-metadata` on the result |
|
|
142
145
|
|
|
143
146
|
## Reporting
|
|
144
147
|
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
"""metadata_scan on a minimal package built with zipfile (no Excel, no openpyxl)."""
|
|
2
|
+
import os
|
|
3
|
+
import subprocess
|
|
4
|
+
import sys
|
|
5
|
+
import tempfile
|
|
6
|
+
import unittest
|
|
7
|
+
import zipfile
|
|
8
|
+
|
|
9
|
+
HERE = os.path.dirname(os.path.abspath(__file__))
|
|
10
|
+
sys.path.insert(0, HERE)
|
|
11
|
+
from xlsx_xml_edit import metadata_scan # noqa: E402
|
|
12
|
+
|
|
13
|
+
CORE = ('<cp:coreProperties xmlns:cp="x" xmlns:dc="y"><dc:creator>A. Author</dc:creator>'
|
|
14
|
+
'<cp:lastModifiedBy></cp:lastModifiedBy></cp:coreProperties>')
|
|
15
|
+
APP = '<Properties><Company>Example Corp</Company></Properties>'
|
|
16
|
+
WB = ('<workbook><mc:AlternateContent><mc:Choice Requires="x15"><x15ac:absPath url="C:\\Users\\someone\\Docs\\" '
|
|
17
|
+
'xmlns:x15ac="z"/></mc:Choice></mc:AlternateContent></workbook>')
|
|
18
|
+
SST = '<sst><si><t>Prepared for Contoso Project</t></si></sst>'
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
class MetadataScanTests(unittest.TestCase):
|
|
22
|
+
def setUp(self):
|
|
23
|
+
self.tmp = tempfile.mkdtemp()
|
|
24
|
+
self.book = os.path.join(self.tmp, "t.xlsx")
|
|
25
|
+
with zipfile.ZipFile(self.book, "w") as z:
|
|
26
|
+
for name, text in (("docProps/core.xml", CORE), ("docProps/app.xml", APP),
|
|
27
|
+
("xl/workbook.xml", WB), ("xl/sharedStrings.xml", SST)):
|
|
28
|
+
z.writestr(name, text)
|
|
29
|
+
|
|
30
|
+
def test_reports_author_company_abspath_and_names_in_any_part(self):
|
|
31
|
+
found = dict((what, part) for part, what in metadata_scan(self.book, ["contoso"]))
|
|
32
|
+
self.assertIn("dc:creator = A. Author", found)
|
|
33
|
+
self.assertIn("Company = Example Corp", found)
|
|
34
|
+
self.assertNotIn("cp:lastModifiedBy = ", found) # empty field is fine
|
|
35
|
+
self.assertTrue(any(k.startswith("x15ac:absPath") for k in found))
|
|
36
|
+
self.assertEqual(found["contains 'contoso'"], "xl/sharedStrings.xml")
|
|
37
|
+
|
|
38
|
+
def test_reports_external_links_defined_names_and_foreign_parts(self):
|
|
39
|
+
with zipfile.ZipFile(self.book, "a") as z:
|
|
40
|
+
z.writestr("xl/externalLinks/externalLink1.xml", "<externalLink/>")
|
|
41
|
+
z.writestr("xl/externalLinks/_rels/externalLink1.xml.rels",
|
|
42
|
+
'<Relationships><Relationship Id="rId1" Target="file:///\\\\server\\share\\old.xls" '
|
|
43
|
+
'TargetMode="External"/></Relationships>')
|
|
44
|
+
z.writestr("docProps/custom.xml", '<Properties><property fmtid="x" pid="2" name="ContentTypeId"/></Properties>')
|
|
45
|
+
z.writestr("xl/metadata", b"\x00binary")
|
|
46
|
+
with zipfile.ZipFile(self.book) as z:
|
|
47
|
+
wb = z.read("xl/workbook.xml").decode()
|
|
48
|
+
rebuilt = os.path.join(self.tmp, "r.xlsx")
|
|
49
|
+
with zipfile.ZipFile(self.book) as src, zipfile.ZipFile(rebuilt, "w") as out:
|
|
50
|
+
for info in src.infolist():
|
|
51
|
+
data = src.read(info.filename)
|
|
52
|
+
if info.filename == "xl/workbook.xml":
|
|
53
|
+
data = wb.replace("</workbook>", '<definedNames><definedName name="OldTable">[1]A!$A$1</definedName>'
|
|
54
|
+
"</definedNames></workbook>").encode()
|
|
55
|
+
out.writestr(info, data)
|
|
56
|
+
found = [what for _, what in metadata_scan(rebuilt)]
|
|
57
|
+
self.assertTrue(any(w.startswith("external target = file:") for w in found), found)
|
|
58
|
+
self.assertIn("external workbook link (its sheet names travel too)", found)
|
|
59
|
+
self.assertTrue(any("OldTable" in w for w in found))
|
|
60
|
+
self.assertTrue(any(w.startswith("custom document properties") for w in found))
|
|
61
|
+
self.assertTrue(any(w.startswith("unknown binary part") for w in found))
|
|
62
|
+
|
|
63
|
+
def test_cli_exits_nonzero_on_findings_and_zero_on_a_clean_package(self):
|
|
64
|
+
r = subprocess.run([sys.executable, os.path.join(HERE, "xlsx_xml_edit.py"), "scan-metadata", self.book],
|
|
65
|
+
capture_output=True, text=True, check=False)
|
|
66
|
+
self.assertEqual(r.returncode, 1, r.stdout + r.stderr)
|
|
67
|
+
clean = os.path.join(self.tmp, "clean.xlsx")
|
|
68
|
+
with zipfile.ZipFile(clean, "w") as z:
|
|
69
|
+
z.writestr("xl/workbook.xml", "<workbook/>")
|
|
70
|
+
r = subprocess.run([sys.executable, os.path.join(HERE, "xlsx_xml_edit.py"), "scan-metadata", clean],
|
|
71
|
+
capture_output=True, text=True, check=False)
|
|
72
|
+
self.assertEqual(r.returncode, 0, r.stdout + r.stderr)
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
if __name__ == "__main__":
|
|
76
|
+
unittest.main()
|
|
@@ -12,7 +12,7 @@ styles, row heights and column widths of every other sheet cannot drift. Strings
|
|
|
12
12
|
package_diff(src_path, out_path) # -> ['xl/worksheets/sheet6.xml']
|
|
13
13
|
excel_open_check(out_path, "Sheet name", ["N46"]) # read-only, private Excel instance
|
|
14
14
|
"""
|
|
15
|
-
import re, zipfile
|
|
15
|
+
import os, re, zipfile
|
|
16
16
|
from xml.sax.saxutils import escape
|
|
17
17
|
|
|
18
18
|
_CELL = re.compile(r'<c r="([A-Z]+)(\d+)"([^>]*?)(?:/>|>(.*?)</c>)', re.S)
|
|
@@ -151,3 +151,67 @@ def excel_open_check(path, sheet_name, refs):
|
|
|
151
151
|
if wb is not None:
|
|
152
152
|
wb.Close(False)
|
|
153
153
|
xl.Quit()
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
_META_FIELDS = (("docProps/core.xml", "dc:creator"), ("docProps/core.xml", "cp:lastModifiedBy"),
|
|
157
|
+
("docProps/app.xml", "Company"), ("docProps/app.xml", "Manager"))
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+
def metadata_scan(path, names=()):
|
|
161
|
+
"""Before a workbook leaves the team (template, deliverable): what travels with it besides the cells.
|
|
162
|
+
|
|
163
|
+
Returns a list of (part, finding): filled author / company fields, the saved absolute path
|
|
164
|
+
(x15ac:absPath in xl/workbook.xml), and every part whose bytes contain one of `names` (case-insensitive, UTF-8)
|
|
165
|
+
— sharedStrings, comments, drawings and docProps included, not only cell values. Read-only."""
|
|
166
|
+
findings = []
|
|
167
|
+
with zipfile.ZipFile(path) as z:
|
|
168
|
+
parts = z.namelist()
|
|
169
|
+
for part, tag in _META_FIELDS:
|
|
170
|
+
if part in parts:
|
|
171
|
+
m = re.search(r"<%s(?:\s[^>]*)?>([^<]+)</%s>" % (tag, tag), z.read(part).decode("utf-8", "replace"))
|
|
172
|
+
if m and m.group(1).strip():
|
|
173
|
+
findings.append((part, f"{tag} = {m.group(1).strip()}"))
|
|
174
|
+
if "xl/workbook.xml" in parts:
|
|
175
|
+
wb = z.read("xl/workbook.xml").decode("utf-8", "replace")
|
|
176
|
+
m = re.search(r'absPath\s+url="([^"]+)"', wb)
|
|
177
|
+
if m:
|
|
178
|
+
findings.append(("xl/workbook.xml", f"x15ac:absPath = {m.group(1)}"))
|
|
179
|
+
defined = [n for n in re.findall(r'<definedName [^>]*name="([^"]+)"', wb)
|
|
180
|
+
if not n.startswith("_xlnm.")] # print areas, autofilter ranges: Excel's own
|
|
181
|
+
if defined:
|
|
182
|
+
findings.append(("xl/workbook.xml", f"{len(defined)} defined name(s) (left from earlier work?): "
|
|
183
|
+
+ ", ".join(sorted(set(defined))[:8])))
|
|
184
|
+
for part in parts: # links to other files carry their path and sheet names
|
|
185
|
+
if part.endswith(".rels"):
|
|
186
|
+
rels = z.read(part).decode("utf-8", "replace")
|
|
187
|
+
for target in re.findall(r'Target="([^"]+)"[^>]*TargetMode="External"', rels):
|
|
188
|
+
if not target.startswith(("http://", "https://", "mailto:")) or "externalLink" in part:
|
|
189
|
+
findings.append((part, f"external target = {target}"))
|
|
190
|
+
elif part.startswith("xl/externalLinks/") and part.endswith(".xml"):
|
|
191
|
+
findings.append((part, "external workbook link (its sheet names travel too)"))
|
|
192
|
+
elif part == "docProps/custom.xml":
|
|
193
|
+
props = re.findall(r'<property [^>]*name="([^"]+)"', z.read(part).decode("utf-8", "replace"))
|
|
194
|
+
if props:
|
|
195
|
+
findings.append((part, "custom document properties: " + ", ".join(props[:8])))
|
|
196
|
+
elif part.startswith("xl/") and "." not in os.path.basename(part):
|
|
197
|
+
findings.append((part, "unknown binary part (another application's metadata?)"))
|
|
198
|
+
for name in names:
|
|
199
|
+
needle = name.lower().encode("utf-8")
|
|
200
|
+
for part in parts:
|
|
201
|
+
if needle in z.read(part).lower():
|
|
202
|
+
findings.append((part, f"contains {name!r}"))
|
|
203
|
+
return findings
|
|
204
|
+
|
|
205
|
+
|
|
206
|
+
if __name__ == "__main__":
|
|
207
|
+
import argparse
|
|
208
|
+
ap = argparse.ArgumentParser(description="Read-only checks on an .xlsx package.")
|
|
209
|
+
ap.add_argument("command", choices=["scan-metadata"])
|
|
210
|
+
ap.add_argument("workbook")
|
|
211
|
+
ap.add_argument("--name", action="append", default=[], help="a name that must not travel (repeatable)")
|
|
212
|
+
args = ap.parse_args()
|
|
213
|
+
found = metadata_scan(args.workbook, args.name)
|
|
214
|
+
for part, what in found:
|
|
215
|
+
print(f"{part}: {what}")
|
|
216
|
+
print(f"{len(found)} finding(s)")
|
|
217
|
+
raise SystemExit(1 if found else 0)
|