diff --git a/docs/requirements/022-analysis-skills-from-quality.md b/docs/requirements/022-analysis-skills-from-quality.md index 1962bdf..db84259 100644 --- a/docs/requirements/022-analysis-skills-from-quality.md +++ b/docs/requirements/022-analysis-skills-from-quality.md @@ -19,9 +19,14 @@ this repository only orchestrates. break at their first run). 2. **Pin**: one Quality tag in `plugins-lock.json`; raising it is a reviewed change. -3. **Old names leave**: the eight skills of Quality 003 decision 1 leave - `skills/`; the skill-token half of `kvb-check-efficiency` stays as - `kvb-skill-tokens`; `kvb-check-gate` stays here as `kvb-org-gate` +3. **Old names leave**: the skills Quality 003 decision 1 takes over + leave `skills/` (operator 2026-11-26: `kvb-check-security`, `-legal`, + `-principles`, `-score`, `-confidence`, `-break-risk`, and the CPU, + RAM and wall-clock half of `kvb-check-efficiency` (`measure.py`, which + already absorbed `kvb-check-speed` in 0fad1bf) as ONE skill, + `kvb-quality-performance`, replacing both `kvb-quality-speed` and + `kvb-quality-efficiency`; `kvb-quality-review` is new, not a move); + the skill-token half (`tokens.py`) stays as `kvb-skill-tokens`; `kvb-check-gate` stays here as `kvb-org-gate` (operator 2026-11-18: it orchestrates queue, register and hotfix runs). One script renames every reference (611 files today); its dry run is reviewed before it writes. @@ -57,6 +62,23 @@ this repository only orchestrates. repository's tests run under that interpreter. Hook commands in settings files that call such a script with `python3` change too, as operator rows. +10. **The commit block stays here** (Quality 2026-11-26, from Quality 003 + decision 8): `kvb-check-score/scripts/block.py` and + `tests/test_block.py` stay in this repository, because block.py runs + `tokens.py` (`kvb-skill-tokens`) and `gate.py` (`kvb-org-gate`); it moves + to `kvb-git-commit-no-verify/scripts/block.py`, the skill that prints the + block into the commit message, and calls + `~/.claude/skills/kvb-quality-score/scripts/score.py`, + `kvb-quality-performance` and `kvb-quality-security` by their installed + paths. The constants it shares with score.py (`DASH`, `NEW`, `UNKNOWN`, + `percent`) come from `quality.agent.score` (decision 9; Quality's + score.py imports them from there too), never from an import out of a + Quality skill folder. Every other file of `kvb-check-score` + moves (score.py, journal.py, backfill.py, labels.json, tables.md, + journal.md); a moved `SKILL.md` (score, confidence) names no script of + this repository. Rejected: block.py in Quality (it would call into this + repository); beside `kvb-org-gate` or `kvb-skill-tokens` (each owns + only one of its inputs). ## Approach @@ -117,6 +139,12 @@ flowchart TD `kvb-quality-score`, and `kvb-check-gate` with successor `kvb-org-gate`. - [ ] `skills/kvb-org-gate/SKILL.md` carries the frontmatter name `kvb-org-gate`, and `queue.py` and `hotfix.py` load its scripts. +- [ ] `skills/kvb-git-commit-no-verify/scripts/block.py` and + `tests/test_block.py` exist; `git grep -nE '^(from score|import score)' + -- skills` prints nothing and block.py imports + `from quality.agent.score`; Quality's installed + `kvb-quality-score/SKILL.md` and `kvb-quality-confidence/SKILL.md` name + no `block.py`. ### Commit flow diff --git a/docs/requirements/064-code-review.md b/docs/requirements/064-code-review.md new file mode 100644 index 0000000..432a825 --- /dev/null +++ b/docs/requirements/064-code-review.md @@ -0,0 +1,229 @@ +# 064 - Code Review + +## User Story + +As the operator, I want one skill that reviews a change against every +standard of its repository and every check Quality offers before a push, so +that no commit reaches a remote that a deep review would have stopped. + +## Decisions (operator-confirmed 2026-11-26; do not re-litigate) + +1. **Two skills, one owner each** (operator): `kvb-code-review` in this + repository is the wrapper and manager (target, standards, harness skills, + skeptics, memory, stamp, hook, waiver); `kvb-quality-review` in the + quality repository is the base that runs every quality check, written + and built by Quality as the eighth skill of quality 003 (amending its + decision 1: security, legal, architecture, score, confidence, + break-risk, performance, review), which also holds the call contract + (`--base`, `--staged`, `--range`, `--all`, repeatable `--path`; exit 0 + clean, 1 findings, 2 usage or tool error; findings with lens, rule, + severity, path, line, commit, tier and the file's blob hash; a version + per lens; the performance lens runs only with `--measure` and fills the + efficiency and speed scores of `kvb-quality-score`; break risk and + confidence left to this skill). Rejected: the review in Quality (Quality analyses, + the review orchestrates and gates pushes); `kvb-check-review` (the check + category empties once quality 003 moves the scanners); `kvb-review` + without category. +2. **Target first** (operator): the skill first asks what to review: the + branch against the default branch (`main` or `master`), a commit range, + the staged changes, or a pull request; the detected target is the + recommended option: staged changes present โ†’ staged; an open pull + request for the branch โ†’ that pull request; commits ahead of the default + branch โ†’ the branch; else the range the operator names. +3. **Repository standards**: `AGENTS.md`, `CONTRIBUTING.md`, every file + under `docs/contributing/` and the `AGENTS.md` of every + `roles//` the diff touches; a standards finding cites the rule's + `file:line`. +4. **Everything Quality offers** (operator): one call to + `kvb-quality-review` once a quality tag carries it (quality 003), with + `--db` when a `quality db update` bundle exists (else its deep tier is + listed as skipped) and `--measure` when the change touches runnable + code (the performance lens: CPU, RAM and wall clock). Until then + (operator: build now, switch later) `quality check` (`--base ` or + `--staged`; `.qualityignore.yml` and folder `.nocheck` are honoured by + Quality itself) and the analysis skills of today: `kvb-check-security`, + `kvb-check-legal`, `kvb-check-principles`, `kvb-check-break-risk`, + `kvb-check-confidence`, `kvb-check-score`, `kvb-check-efficiency` + (its `measure.py`, the later performance lens, only with runnable + code). A lens + that cannot run is listed with its reason, never dropped. +5. **Harness review skills** (operator): every read-only review skill the + harness lists runs as a further lens (Claude Code today: `/code-review` + as the correctness lens, `/security-review`); a harness that lists none + gets only the own lenses. Rejected: fix-applying skills (`/simplify`, + `--fix`), because the review never edits. +6. **Skeptics** (operator): one skeptic per lens checks all its findings in + one pass; every critical or high finding gets its own extra skeptic + before it may block. A refuted finding stays in the table as refuted. + Rejected: one skeptic per finding (cost grows per finding); skeptics for + blockers only (medium and low unverified). +7. **Clean** (operator): a review is clean when no confirmed finding is + critical or high. Rejected: every confirmed finding blocks; only + critical blocks. +8. **Stamp** (operator, P1): `review.py stamp` records the verdict for + `HEAD^{tree}` in `kvb-review.json` in the git common dir, only when the + review's target is everything the push sends (upstream..HEAD, the + default branch without an upstream) and the tracked tree is clean. A new + tree voids it; a signing-only rewrite keeps it. `kvb-git-push` hands a + push row only when `gate.py status` is green and `review.py status` is + clean or waived for the same tree. +9. **Hook** (operator, P3): a pre-bash handler in + `kvb-org-organize/scripts/hooks.py` refuses `operator.py add` with + `--check pushed:` while ``'s `HEAD^{tree}` has neither a clean + stamp nor a waiver. +10. **Waiver** (operator): per push, through a hub decision card ("Waive + the review for the push of tree `` in ``?"); `review.py + waive` records the signed answer once `operator_message` returns + `match`, and the hook verifies it again through the hub's + `operator_message`; an unreachable hub refuses. Rejected: the operator + pushing by hand; a typed waiver flag (any agent can type it). +11. **Output**: one table ranked by severity, `| Severity | Lens | File:line + | Finding | Skeptic | Evidence |`, then the commit score block of + `block.py` (063; `kvb-git-commit-no-verify` after 022 decision 10), + its break risk and confidence + judged by this skill. +12. **Read-only**: the review never edits, stages, commits or pushes. The + CI review of pushes and pull requests with inline comments is its own + requirement, after this one. +13. **Memory** (operator): what was reviewed is not reviewed again. Results + live in `kvb-review-cache.json` in the git common dir, keyed by lens, + lens version, path, the file's blob hash and the digest of the + standards files it was judged against; skeptic verdicts are keyed by + the finding (lens, rule, path, blob hash, the flagged line's text). A + lens reruns only on files whose key changed; a lens that judges the + whole diff reruns only when the diff's `git patch-id` changed. +14. **Tokens and velocity** (operator): lenses run in parallel, scripts as + processes and judging lenses as subagents, heavy runs through + `queue.py hold`, light runs self-admitted (`kvb-org-organize` + Capacity); the skeptics of different lenses run in parallel. A + subagent gets only its files' hunks and the cited standard sections, + never whole documents, on the model `kvb-org-perform` picks, and + answers in the table's columns. + +## Approach + +```mermaid +flowchart TD + subgraph P["๐Ÿงญ 0 ยท Preparation"] + P1["๐Ÿ“‹ Write requirement"] --> P2{"โœ… Operator approves?"} + P2 -- "โœ๏ธ corrections" --> P1 + end + P2 -- "๐Ÿค– yes" --> T1 + subgraph T["๐ŸŽฏ A ยท Target"] + T1["๐Ÿ”Ž Detect staged, PR, branch, range"] --> T2["๐Ÿ™‹ Ask, detected target first"] + T2 --> T3{"๐Ÿงช Target tests green?"} + T3 -- "๐Ÿ”ด no: fix" --> T1 + end + T3 -- "๐ŸŸข yes" --> M1 + subgraph M["๐Ÿง  B ยท Memory"] + M1["๐Ÿ—‚๏ธ Key per lens, path, blob, standards digest"] --> M2["โ™ป๏ธ Reuse cached results"] + M2 --> M3{"๐Ÿงช Cache tests green?"} + M3 -- "๐Ÿ”ด no: fix" --> M1 + end + M3 -- "๐ŸŸข yes" --> L1 + subgraph L["๐Ÿ” C ยท Lenses in parallel"] + L1["๐Ÿ“œ Standards"] --> L4{"๐Ÿงช Lens tests green?"} + L2["๐Ÿญ Quality check and kvb-check-*"] --> L4 + L3["๐Ÿงฐ Harness read-only skills"] --> L4 + L4 -- "๐Ÿ”ด no: fix" --> L1 + end + L4 -- "๐ŸŸข yes" --> S1 + subgraph S["๐Ÿง D ยท Skeptics and verdict"] + S1["โš–๏ธ One per lens, one per blocker"] --> S2["๐Ÿงพ Table and score block"] + S2 --> S3["๐Ÿท๏ธ Stamp the tree"] + S3 --> SF{"๐Ÿ’ฌ Operator feedback on a sample run?"} + SF -- "โœ๏ธ changes" --> S1 + end + SF -- "๐Ÿ‘ fits" --> G1 + subgraph G["๐Ÿšง E ยท Push gate"] + G1["๐Ÿš€ kvb-git-push needs gate and review"] --> G2["๐Ÿช Hook refuses unstamped push rows"] + G2 --> G3["๐Ÿ” Signed waiver card"] + G3 --> G4{"๐Ÿงช Unit, integration, e2e green?"} + G4 -- "๐Ÿ”ด no: fix" --> G1 + G4 -- "๐ŸŸข yes" --> GF{"๐Ÿ’ฌ Operator feedback?"} + GF -- "โœ๏ธ changes" --> G1 + end + GF -- "๐Ÿ‘ fits" --> D1["๐Ÿ Review, commit with operator OK, hand-over"] +``` + +## Acceptance Criteria + +### Target + +- [ ] `review.py target --repo ` prints `staged` for a fixture with + staged changes, `pr ` with an open pull request (`gh` stubbed), + `branch ` for commits ahead of `main` or `master`, else + `range`. +- [ ] The skill's first question lists the four targets with the detected + one first and marked recommended (`SKILL.md` text and a test on it). + +### Lenses + +- [ ] The standards lens reads `AGENTS.md`, `CONTRIBUTING.md`, every file + under `docs/contributing/` and `roles//AGENTS.md` for each + touched role, and names each file it read in the output. +- [ ] `quality check --base ` runs for a branch, pull request or range + target, `--staged` for a staged one; a finding Quality waives in + `.qualityignore.yml` or `.nocheck` does not appear. +- [ ] Each of the seven `kvb-check-*` lenses runs or appears under + `skipped` with its reason; none is silently absent. +- [ ] With `/code-review` and `/security-review` listed by the harness both + run; with none listed the output says `harness: none` and the own + lenses still run. + +### Memory + +- [ ] A second review of an unchanged tree starts no lens and no skeptic + and prints every row from `kvb-review-cache.json`. +- [ ] Changing one file reruns the per-file lenses on that file only; + a whole-diff lens reruns because the `git patch-id` changed. +- [ ] Changing a standards file reruns the standards lens on every file. +- [ ] A cached skeptic verdict is reused for the same finding key and never + for a changed flagged line. + +### Tokens and velocity + +- [ ] The lenses of one review start in parallel; the run's log shows their + start times within one second of each other, heavy ones as + `queue.py hold` jobs. +- [ ] A subagent brief holds only its files' hunks and the cited standard + sections; a test asserts no whole `AGENTS.md` or `CONTRIBUTING.md` is + in a brief. +- [ ] A re-review of an unchanged tree finishes in under 5 s wall clock. + +### Verdict and stamp + +- [ ] A confirmed high finding gives `verdict: blocked`; only medium and + low confirmed gives `verdict: clean`. +- [ ] `review.py stamp` refuses with exit 2 when the tracked tree is dirty + or the target is not upstream..HEAD. +- [ ] `review.py status --repo ` prints `review: clean`, `blocked`, + `waived` or `missing` for `HEAD^{tree}`; a new commit gives + `missing`; a signing-only rewrite keeps `clean`. + +### Push gate + +- [ ] `kvb-git-push` hands no push row while `review.py status` is not + `clean` or `waived` (`SKILL.md` step and a test). +- [ ] The hook refuses `operator.py add ... --check pushed:` with + exit 2 and the reason `no clean review for tree `; with a clean + stamp it allows; other `operator.py add` rows pass untouched. +- [ ] A waiver whose signed answer `operator_message` does not match, or an + unreachable hub, keeps the row refused. + +### Tests + +- Unit: + - [ ] Target detection, cache keys, stamp, status and waiver in + `tests/test_code_review.py`. + - [ ] The hook handler in `tests/test_hooks.py`. +- Integration: + - [ ] `operator.py add --check pushed:` through `hooks.py pre-bash` on a + fixture repository: refused without a stamp, allowed with a clean + one, allowed with a verified waiver. + - [ ] A run on a fixture with a planted high finding ends `blocked`; the + same run again starts no lens. +- E2E: + - [ ] Hub e2e: the waiver decision card is signed with the virtual + passkey, `review.py waive` records it and the hook then allows the + row. diff --git a/docs/requirements/065-accounts-round-trip.md b/docs/requirements/065-accounts-round-trip.md new file mode 100644 index 0000000..bad3e4b --- /dev/null +++ b/docs/requirements/065-accounts-round-trip.md @@ -0,0 +1,155 @@ +# 065 - Accounts Spreadsheet Round Trip + +## User Story + +As the operator, I want to export the Accounts table as CSV or TSV and import +such a file with a column mapping, so that I can keep and edit my accounts in +a spreadsheet and bring them back without typing each one into the hub. + +## Decisions (operator-confirmed 2026-11-26; do not re-litigate) + +1. **Export holds the stored fields only** (operator): header + `provider,email,renewal_day,renewal_time,reset_day,reset_time,resubscribe,autorenew,limit,note`, + days `Sun` to `Sat`, autorenew `yes`/`no`, an empty limit for none; an + exported file imports again with every row unchanged. Rejected: usage + columns (a snapshot the import cannot take back); a column picker (more + UI, no round trip gain). +2. **Formats**: CSV (comma, RFC 4180 quoting) and TSV, both UTF-8; the file + is named `accounts-.csv` or `.tsv`. +3. **Server side** (operator): `GET /api/accounts/export?format=csv|tsv` + answers the file as an attachment with `Cache-Control: no-store`; + `POST /api/accounts/import/preview` and `POST /api/accounts/import/apply` + take the file's text, separator, mapping and conflict choices as JSON. + Python's `csv` module reads and writes; every row passes + `valid_account()`. On export a cell starting with `=`, `+`, `-`, `@`, tab + or carriage return gets a leading `'` (formula injection); the import + strips exactly that prefix. Rejected: parsing in the browser (a second + CSV parser and a second validation). +4. **Mapping** (operator): the preview detects the separator (comma, + semicolon, tab; the request may override it) and proposes for each field + the column whose header equals the field name or the table's label, + ignoring case; each field has a dropdown over the file's columns plus + "not in file". Renewal and reset take one column (`Mon 09:00`) or two + (day, time); weekdays as 0 to 6 (0 Sunday), English or German names and + their short forms; autorenew as yes/no, true/false, 1/0, ja/nein. + Required: provider, email, renewal, reset; a missing optional field takes + its empty value (resubscribe "", autorenew no, limit none, note ""). +5. **Conflicts** (operator): a row whose email exists updates that account + by default; the preview offers per conflicting row `overwrite` or `keep` + and one switch for all rows; accounts not in the file stay. Rejected: + replacing all accounts (deletes by accident); adding new ones only (no + way to update). +6. **Preview, then apply**: the preview marks every row `new`, `update` + (with its changed fields and its choice), `unchanged` or `error` (with the + validator's message); a duplicate email inside the file is an error on + both rows. Apply is offered only at zero errors, re-validates on the + server, writes all rows in one ledger write or none, and answers 409 when + the ledger changed since the preview (digest in the preview). +7. **Limits**: at most 256 KiB and 500 rows per file; text that is not UTF-8 + is refused; a leading byte order mark is dropped. +8. **Host only** (028 decision 1 stays): the export leaves the hub only as + the download the operator starts; the hub writes no export file, stores + no import file and logs no cell value; fixtures use example.org. +9. **Place**: two icon buttons in the Accounts head left of `+`: Export + (`bi-download`, menu CSV and TSV) and Import (`bi-upload`, file picker, + then a mapping sheet like the account sheet). + +## Approach + +```mermaid +flowchart TD + subgraph P["๐Ÿงญ 0 ยท Preparation"] + P1["๐Ÿ“‹ Write requirement"] --> P2{"โœ… Operator approves?"} + P2 -- "โœ๏ธ corrections" --> P1 + end + P2 -- "๐Ÿค– yes" --> A1 + subgraph A["๐Ÿ—„๏ธ A ยท Server"] + A1["๐Ÿ“ค Export CSV and TSV"] --> A2["๐Ÿงญ Preview: separator, mapping, conflicts"] + A2 --> A3["โœ… Apply: atomic, digest, 0600"] + A3 --> A4{"๐Ÿงช Unit and integration green?"} + A4 -- "๐Ÿ”ด no: fix" --> A1 + end + A4 -- "๐ŸŸข yes" --> B1 + subgraph B["๐Ÿ–ฅ๏ธ B ยท Page"] + B1["โฌ‡๏ธ Export menu"] --> B2["โฌ†๏ธ Import picker and mapping sheet"] + B2 --> B3["๐Ÿงพ Preview table with per-row choice"] + B3 --> B4{"๐Ÿงช E2E green at 1920, 1366, 390?"} + B4 -- "๐Ÿ”ด no: fix" --> B1 + B4 -- "๐ŸŸข yes" --> BF{"๐Ÿ’ฌ Operator feedback on screenshots?"} + BF -- "โœ๏ธ changes" --> B1 + end + BF -- "๐Ÿ‘ fits" --> D1["๐Ÿ Review, commit with operator OK, hand-over"] +``` + +## Acceptance Criteria + +### Export + +- [ ] `GET /api/accounts/export?format=csv` on a fixture with two accounts + answers 200, `text/csv; charset=utf-8`, `Content-Disposition: + attachment; filename="accounts-.csv"`, `Cache-Control: no-store`, + the header of decision 1 and one line per account; `format=tsv` the + same with tabs and `text/tab-separated-values`; any other format 400. +- [ ] A note `=HYPERLINK("x")` exports as `'=HYPERLINK("x")` and imports back + as `=HYPERLINK("x")`. +- [ ] Exporting the fixture and previewing that file gives every row + `unchanged`. +- [ ] The hub's state dir lists the same files before and after an export. + +### Mapping + +- [ ] Headers `Provider,Email,Renewal,Next reset` (the table's labels) map + without any choice; unknown headers map nothing and the preview names + provider, email, renewal and reset as missing. +- [ ] Comma, semicolon and tab fixtures are each detected; a separator in + the request wins over the detection. +- [ ] `0`, `Sun`, `Sunday`, `So` and `Sonntag` all give day 0; `Mon 09:00` + in one column equals `Mon` and `09:00` in two; `7` and `Funday` are row + errors naming the column. +- [ ] Without optional columns a row gets resubscribe "", autorenew false, + limit null and note "". +- [ ] A file over 256 KiB or 500 rows, or not UTF-8, answers 400 and parses + nothing. + +### Conflicts + +- [ ] Ledger `a@example.org`, file with `a@example.org` changed and + `b@example.org`: preview shows a as `update` with its changed fields + and choice `overwrite`, b as `new`. +- [ ] Apply with `keep` for a leaves a unchanged and adds b; with + `overwrite` it replaces a's fields and keeps a's id. +- [ ] An account missing from the file still exists after apply. +- [ ] Two rows with one email are both `error`. + +### Apply + +- [ ] Apply with an error row answers 400 and leaves `accounts.json` + byte-identical. +- [ ] Apply after the ledger changed since the preview answers 409 and + changes nothing. +- [ ] After apply `accounts.json` keeps mode 0600. + +### Page + +- [ ] The Export menu's CSV and TSV items are links to + `/api/accounts/export?format=csv` and `?format=tsv` with a `download` + attribute. +- [ ] Picking a fixture file opens the mapping sheet with one preselected + dropdown per field, the separator select and the preview table; + changing a dropdown re-runs the preview; Apply is disabled while an + error row exists; after apply the table shows the imported rows. + +### Tests + +- Unit: + - [ ] `tests/test_hub_accounts_io.py`: export bytes, injection prefix + round trip, separator detection, header matching, weekday and time + parsing, empty values, conflict classes, duplicate emails, limits, + ledger digest. +- Integration: + - [ ] Export, preview and apply through the HTTP handler on a temporary + state dir: status codes, headers, file mode, atomic write, 409. +- E2E: + - [ ] `tests/e2e/test_resources_accounts_e2e.py`: export links, import + with one dropdown changed, `keep` on one conflict, apply, + screenshots at 1920, 1366 and 390. diff --git a/docs/requirements/README.md b/docs/requirements/README.md index a322bce..37d63ee 100644 --- a/docs/requirements/README.md +++ b/docs/requirements/README.md @@ -67,3 +67,5 @@ skill defines the format. - [061 - Bounded Council Files](061-bounded-council-files.md) - [062 - Lean Agent Output](062-lean-agent-output.md) - [063 - One Commit Block](063-one-commit-block.md) +- [064 - Code Review](064-code-review.md) +- [065 - Accounts Spreadsheet Round Trip](065-accounts-round-trip.md)