@srobroek/pi-code-quality 0.0.0-stage → 0.15.1

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 (55) hide show
  1. package/CHANGELOG.md +182 -0
  2. package/LICENSE +202 -0
  3. package/README.md +147 -2
  4. package/agents/adversarial-challenger.md +29 -0
  5. package/extensions/quality.js +4583 -0
  6. package/package.json +40 -4
  7. package/skills/prototype-logic/LICENSE +21 -0
  8. package/skills/prototype-logic/NOTICE +26 -0
  9. package/skills/prototype-logic/SKILL.md +76 -0
  10. package/skills/quality-code-design/LICENSE-mattpocock-skills +21 -0
  11. package/skills/quality-code-design/NOTICE +63 -0
  12. package/skills/quality-code-design/SKILL.md +63 -0
  13. package/skills/quality-code-design/references/contracts.md +37 -0
  14. package/skills/quality-code-design/references/debugging.md +85 -0
  15. package/skills/quality-code-design/references/deep-modules.md +67 -0
  16. package/skills/quality-code-design/references/dependencies.md +81 -0
  17. package/skills/quality-code-design/references/encapsulation.md +148 -0
  18. package/skills/quality-code-design/references/feature-flags.md +189 -0
  19. package/skills/quality-code-design/references/go.md +110 -0
  20. package/skills/quality-code-design/references/lifecycle.md +66 -0
  21. package/skills/quality-code-design/references/middleware.md +55 -0
  22. package/skills/quality-code-design/references/other-paradigms.md +44 -0
  23. package/skills/quality-code-design/references/persistence.md +52 -0
  24. package/skills/quality-code-design/references/python.md +100 -0
  25. package/skills/quality-code-design/references/release.md +59 -0
  26. package/skills/quality-code-design/references/review.md +121 -0
  27. package/skills/quality-code-design/references/rust.md +140 -0
  28. package/skills/quality-code-design/references/safe-mutation.md +33 -0
  29. package/skills/quality-code-design/references/security.md +65 -0
  30. package/skills/quality-code-design/references/simplicity.md +165 -0
  31. package/skills/quality-code-design/references/solid.md +165 -0
  32. package/skills/quality-code-design/references/supporting-principles.md +78 -0
  33. package/skills/quality-code-design/references/telemetry.md +54 -0
  34. package/skills/quality-code-design/references/test-first.md +78 -0
  35. package/skills/quality-code-design/references/typescript.md +93 -0
  36. package/skills/quality-code-design/references/verification.md +53 -0
  37. package/skills/quality-code-policy/SKILL.md +34 -0
  38. package/skills/quality-profiling/SKILL.md +48 -0
  39. package/skills/quality-profiling/references/hygiene.md +27 -0
  40. package/skills/quality-profiling/references/reading-profiles.md +21 -0
  41. package/skills/quality-profiling/references/system.md +51 -0
  42. package/skills/quality-test-audit/SKILL.md +122 -0
  43. package/skills/quality-test-audit/references/catalog.md +108 -0
  44. package/skills/quality-test-audit/references/evidence.md +123 -0
  45. package/skills/quality-test-audit/references/report.md +75 -0
  46. package/skills/quality-testing/SKILL.md +62 -0
  47. package/skills/quality-testing/references/bad-tests.md +258 -0
  48. package/skills/quality-testing/references/doubles.md +49 -0
  49. package/skills/quality-testing/references/good-tests.md +90 -0
  50. package/skills/quality-testing/references/maintenance.md +96 -0
  51. package/skills/quality-testing/references/review-tests.md +72 -0
  52. package/skills/quality-testing/references/shared-contracts.md +30 -0
  53. package/skills/quality-testing/references/signals.md +50 -0
  54. package/skills/quality-testing/references/test-budget.md +81 -0
  55. package/skills/quality-testing/references/what-to-test.md +58 -0
package/package.json CHANGED
@@ -1,6 +1,42 @@
1
1
  {
2
2
  "name": "@srobroek/pi-code-quality",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.15.1",
4
+ "description": "Code design and review guidance, a code-quality policy, testing standards and a test audit, performance profiling, and throwaway logic prototypes.",
5
+ "keywords": [
6
+ "pi-package"
7
+ ],
8
+ "license": "Apache-2.0",
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "git+https://github.com/srobroek/harness-plugins.git",
12
+ "directory": "plugins/quality/pi"
13
+ },
14
+ "files": [
15
+ "CHANGELOG.md",
16
+ "LICENSE",
17
+ "README.md",
18
+ "agents",
19
+ "extensions",
20
+ "skills"
21
+ ],
22
+ "publishConfig": {
23
+ "access": "public",
24
+ "provenance": true
25
+ },
26
+ "peerDependencies": {
27
+ "typebox": "*"
28
+ },
29
+ "pi": {
30
+ "extensions": [
31
+ "./extensions/quality.js"
32
+ ],
33
+ "skills": [
34
+ "./skills"
35
+ ],
36
+ "subagents": {
37
+ "agents": [
38
+ "./agents"
39
+ ]
40
+ }
41
+ }
42
+ }
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Matt Pocock
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,26 @@
1
+ prototype-logic
2
+ ===============
3
+
4
+ This skill is vendored, in modified form, from:
5
+
6
+ Project: mattpocock-skills 1.2.3
7
+ Repository: https://github.com/mattpocock/skills
8
+ Source path: skills/engineering/prototype/SKILL.md and skills/engineering/prototype/LOGIC.md
9
+ Copied: 2026-10-08
10
+ Licence: MIT License, Copyright (c) 2026 Matt Pocock
11
+
12
+ The full licence text is in the LICENSE file beside this one, copied from the
13
+ installed mattpocock-skills 1.2.3 package.
14
+
15
+ The MIT licence requires that the copyright notice and permission notice appear in all
16
+ copies or substantial portions of the software. The LICENSE file satisfies that, and the
17
+ vendored SKILL.md records its provenance and its modifications in a comment block below
18
+ its frontmatter.
19
+
20
+ Modifications:
21
+ 1. Only the LOGIC branch is vendored, renamed prototype-logic. The UI branch's in-app
22
+ ?variant= technique is a route row in design/skills/design-prototype instead.
23
+ 2. Promoting the pure module into real code requires tests at its real seam.
24
+ 3. The demo goes to a user-named path or ~/tmp and is not committed to a side branch.
25
+ 4. A run check precedes hand-over; the frontmatter description follows this
26
+ repository's authoring contract.
@@ -0,0 +1,76 @@
1
+ ---
2
+ name: prototype-logic
3
+ description: Builds a throwaway HTML demo over a pure reducer or state machine; triggers on does this state model work.
4
+ ---
5
+
6
+ <!--
7
+ Vendored from mattpocock/skills 1.2.3, paths skills/engineering/prototype/SKILL.md and
8
+ skills/engineering/prototype/LOGIC.md, copied 2026-10-08. Licensed under the MIT License,
9
+ Copyright (c) 2026 Matt Pocock. The full licence text is in the LICENSE file beside this
10
+ one.
11
+
12
+ THIS FILE HAS BEEN MODIFIED from the original. Changes:
13
+ 1. Only the LOGIC branch is vendored. The UI branch (in-app ?variant= variants) is a
14
+ route in design-prototype, so the "what should this look like" trigger stays there.
15
+ 2. Promotion: upstream lifted the untested module into real code on its own. The pure
16
+ module now enters real code only with tests at its real seam.
17
+ 3. Location and capture: the demo goes to a user-named path or ~/tmp, never into a
18
+ checkout, and is not committed to a side branch outside the delivery workflow.
19
+ 4. Added a run check before hand-over, and rewrote the frontmatter description to this
20
+ repository's authoring contract.
21
+ 5. Ported to opencode-plugins: references to other skills name the skill instead of an
22
+ Oh My Pi skill URI.
23
+ The demo layout, the pure-module shapes, the walkthrough design, and the anti-patterns
24
+ are upstream's and are unchanged in substance.
25
+ -->
26
+
27
+ # Logic prototype
28
+
29
+ TRIGGER
30
+ + "does this state model work", "prototype the logic", "I'm not sure this state machine handles X then Y"
31
+ + a data model or transition set someone wants to push through real cases before writing it
32
+ - "what should this look like", a wireframe, or UI variants → the `design-prototype` skill
33
+ - the logic is settled and needs implementing → the `quality-code-design` skill
34
+
35
+ A logic prototype is a single self-contained HTML file that lets anyone drive a state
36
+ model by clicking buttons. It answers a question about business logic, state transitions,
37
+ or data shape: the kind of thing that looks reasonable on paper and only feels wrong once
38
+ pushed through real cases. It speaks the domain's language, so a non-developer can drive it.
39
+
40
+ ## Workflow
41
+
42
+ 1. **State the question.** One paragraph naming the state model and the question, shown
43
+ in a visible intro at the top of the demo, not only in a comment.
44
+ 2. **Isolate the logic in one pure module**, in a single `<script>` block, shaped by the
45
+ question:
46
+ - a pure reducer `(state, action) => state` when actions are discrete events;
47
+ - a state machine with explicit states and transitions when "which actions are legal
48
+ now" is part of the question;
49
+ - a few pure functions over a plain data type when there is no current state;
50
+ - a module with a clear method surface when the logic owns ongoing internal state.
51
+ No DOM, no `document`, no handlers inside it: the page calls in, nothing flows back.
52
+ 3. **Build the page** as plain inline HTML, CSS, and JS: no framework, bundler, or server.
53
+ Top to bottom: title and the question; the current state as a labelled panel, re-rendered
54
+ after every click with the change called out; one free-play button per action; guided
55
+ walkthroughs, one tab per scenario, each a plain-language description over the ordered
56
+ buttons to press, starting from a reset initial state. Cover the happy path, a tricky
57
+ edge case, and an attempt at something that should be illegal. Restrained styling: one
58
+ accent colour, no animation.
59
+ 4. **Write and check it.** Write the file to the path the user names; with no path, to
60
+ `~/tmp/prototype-logic-{slug}/index.html`. When a browser tool is available, open the
61
+ file and run each walkthrough once. → report the absolute path and any console error.
62
+ 5. **Hand it over** and iterate: "wait, that shouldn't be possible" is a bug in the idea,
63
+ which is the point. Add actions or scenarios on request.
64
+ 6. **Capture the answer**: record the verdict and the question it settled where the user
65
+ tracks the decision. The validated module is the only part that can move into real code.
66
+
67
+ ## Rules
68
+
69
+ MUST Add tests at the module's real seam before any part of the prototype enters real
70
+ code. A clicked demo is evidence about a design, not proof the implementation is correct.
71
+ MUST Keep state in memory. A scratch store named "PROTOTYPE, wipe me" is allowed only
72
+ when persistence is the question.
73
+ NOT Add tests, error handling, or abstractions to the prototype itself; it answers one
74
+ question and is thrown away.
75
+ NOT Blur the module and the page: a module that touches the DOM cannot be lifted.
76
+ NOT Ship the HTML shell into production.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Matt Pocock
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,63 @@
1
+ quality
2
+ =======
3
+
4
+ Parts of this plugin derive, in modified form, from:
5
+
6
+ Project: mattpocock-skills 1.2.3
7
+ Repository: https://github.com/mattpocock/skills
8
+ Copied: 2026-10-08
9
+ Rechecked: 2026-11-12 against GitHub main 5863806 (package.json 1.3.2)
10
+ Licence: MIT License, Copyright (c) 2026 Matt Pocock
11
+
12
+ This NOTICE sits in skills/quality-code-design/ so it travels with the skill. The
13
+ full licence text is in LICENSE-mattpocock-skills beside this file, copied from the
14
+ installed mattpocock-skills 1.2.3 package. The MIT licence requires that the copyright
15
+ notice and permission notice appear in all copies or substantial portions of the
16
+ software; that file satisfies it for the content listed below.
17
+
18
+ Vendored skill (carries its own LICENSE and NOTICE):
19
+
20
+ skills/prototype-logic/ <- skills/engineering/prototype/SKILL.md, LOGIC.md
21
+
22
+ Folded into skills/quality-code-design/references/, rewritten and merged with this
23
+ plugin's own guidance:
24
+
25
+ references/debugging.md <- skills/engineering/diagnosing-bugs/SKILL.md
26
+ (feedback-loop catalogue, loop tightening,
27
+ minimisation, ranked hypotheses, instrumentation,
28
+ regression seam, redaction and cleanup). Added at the
29
+ 1.3.2 recheck: the exact-symptom red loop before a
30
+ diagnosis, symptom checks while minimising, and the
31
+ pristine-copy diff for a forced red. Dropped: the
32
+ hard no-hypothesis-without-a-loop gate, the CONTEXT.md
33
+ and GLOSSARY.md reads, the interactive-user assumption,
34
+ and scripts/hitl-loop.template.sh.
35
+ references/test-first.md <- skills/engineering/tdd/SKILL.md, tests.md, mocking.md
36
+ (vertical slices, red before green, per-endpoint
37
+ injected clients). Added at the 1.3.2 recheck: seams
38
+ stated with what they catch and miss, one logical
39
+ assertion per test, checks through the public read
40
+ interface, and the forced-red pristine-copy diff.
41
+ Changed: seam agreement with the user is needed only
42
+ when the interface or scope is unsettled. Dropped: the
43
+ user-confirmed-seam gate, the Skill-tool call, and
44
+ "refactoring is not part of the loop".
45
+ references/deep-modules.md <- skills/engineering/codebase-design/SKILL.md,
46
+ DEEPENING.md, DESIGN-IT-TWICE.md (vocabulary, depth,
47
+ seams, dependency categories, replace-don't-layer
48
+ tests, optional design-it-twice). Changed: one seam
49
+ rule replaces the two-adapter rule; edge cases are
50
+ ported to interface tests before old tests are
51
+ deleted. Dropped: the term bans.
52
+ references/review.md <- skills/engineering/code-review/SKILL.md (fixed-point
53
+ pinning, spec-source discovery, Standards and Spec
54
+ axes, smell baseline). Changed: work in progress is
55
+ included, Beads is a spec source, both axes run in one
56
+ reviewer, and smells route to sniff's refactoring
57
+ catalog. Dropped: the issue-tracker and setup
58
+ references.
59
+ references/lifecycle.md <- skills/engineering/domain-modeling/SKILL.md,
60
+ ADR-FORMAT.md (decision-record offer criteria and
61
+ qualifying cases, term-challenge discipline). Changed:
62
+ docs/decisions instead of docs/adr, one numbering
63
+ owner, no CONTEXT.md without authorization.
@@ -0,0 +1,63 @@
1
+ ---
2
+ name: quality-code-design
3
+ description: Use for coding, refactoring, reviewing, debugging or diagnosing, TDD, test-first or red-green-refactor work.
4
+ ---
5
+
6
+ # Code design and review
7
+
8
+ TRIGGER
9
+ + Design, investigate, write, modify, refactor, or review code in any agent role or language.
10
+ + Add behavior to an existing function, module, type, script, or service.
11
+ + Debug or diagnose a hard bug, a flaky failure, or a performance regression.
12
+ + Work test-first: TDD or red-green-refactor.
13
+ + Review a branch, PR, or work-in-progress change since a fixed point.
14
+ - Prose-only work or mechanical execution of an unchanged command needs no design analysis.
15
+ - Tuning code-agent instructions, model routing, or tools against task cases → the `tune-model-prompt` skill when installed (an owner-local skill this repository does not ship).
16
+ - Deciding what to test, at which level, how many tests to keep, with which doubles or test data, or reviewing test changes → the `quality-testing` skill.
17
+ - Checking whether a state model or logic holds up before building it → the `prototype-logic` skill.
18
+ - Measuring, profiling or benchmarking slow or memory-heavy code → the `quality-profiling` skill.
19
+
20
+ ## Workflow
21
+
22
+ 1. Identify the accepted behavior, affected responsibility, callers, contracts, invariants, and material failure risks. Missing context is an uncertainty, not proof of a defect.
23
+ 2. Choose IMPLEMENT, INVESTIGATE, or REVIEW. IMPLEMENT: when the change adds a capability or dependency the repository lacks, load the dependency guide before writing code. INVESTIGATE: map responsibilities, contracts, reuse candidates, and simplifications within the brief; do not edit. REVIEW: load the review guide and stay read-only.
24
+ 3. Load only the references the table names for the situation. Select language guidance from the files and symbols in scope or the stated implementation language; an unrelated language elsewhere in the repository does not trigger it.
25
+ 4. In IMPLEMENT, fix the violations the change introduces and simplify the code it touches. Choose focused checks against acceptance and failure cases.
26
+ 5. In REVIEW, evaluate every row of the review guide's checklist, marking a row inapplicable when the code has no relevant construct. Report in the format your role or brief defines.
27
+ 6. Reassess decisions when behavior changes. Record a non-obvious exception near the decision or in an existing decision record: reason, alternatives, residual risk, and revisit trigger. Omit ceremonial compliance reports on clean changes.
28
+
29
+ ## Reference selection
30
+
31
+ References live in `references/` beside this file; the links below are relative to it. Examples are focused excerpts, not complete applications. Undefined collaborators stand for application-specific code.
32
+
33
+ | Situation → reference | Coverage |
34
+ |---|---|
35
+ | Responsibilities, extension, contracts, or dependencies → [solid.md](references/solid.md) | SRP, OCP, LSP, ISP, DIP; underdesign and overengineering |
36
+ | State, objects, modules, abstraction, or composition → [encapsulation.md](references/encapsulation.md) | Encapsulation, information hiding, invariants, abstraction, inheritance, polymorphism, composition |
37
+ | Module depth, seams, adapters, testability, or deepening shallow modules → [deep-modules.md](references/deep-modules.md) | Depth vocabulary, the seam rule, dependency categories, replace-don't-layer tests, optional design-it-twice |
38
+ | Scope, duplication, or simplifying a solution → [simplicity.md](references/simplicity.md) | YAGNI, KISS, DRY, reversible design, refactoring scope, scripts, tests |
39
+ | Adding a capability or dependency; library, ORM, or persistence choice → [dependencies.md](references/dependencies.md) | Repository and earlier-code reuse, comparison with the preferred-library standards, mature packages, present value and boundaries |
40
+ | Auth, validation, request ids, logging, error mapping, timeouts, retries, rate limits, or a new service, handler, consumer or client → [middleware.md](references/middleware.md) | Handlers vs middleware, one middleware model per surface, stack order, one error mapper, client and consumer middleware, middleware tests; framework mechanisms live in `lang-<language>-libraries` |
41
+ | Logs, traces, metrics, or a new service, worker, CLI or Lambda function → [telemetry.md](references/telemetry.md) | OpenTelemetry by default: setup, export, propagation, sampling, flushing, span/metric/log rules, telemetry tests; SDK packages live in `lang-<language>-libraries` |
42
+ | Feature flags, rollout decisions, outage defaults or flag storage → [feature-flags.md](references/feature-flags.md) | Typed flag module, edge decisions, safe defaults, storage, testing, telemetry and removal; process lives in `trunk-dev-feature-flags` |
43
+ | Database state, transitions, migrations, dynamic SQL, or persistence tests → [persistence.md](references/persistence.md) | DB as the record, compare-and-set updates, append-only migrations, bound queries, real-database tests |
44
+ | Generated bindings, IPC command names, wire casing, or client/server contract tests → [contracts.md](references/contracts.md) | Committed codegen with drift check, name conformance, one casing, tests against the real surface, stubs behind a contract |
45
+ | Plan/approve/apply flows, bulk or destructive file operations, path checks, audit trails → [safe-mutation.md](references/safe-mutation.md) | Apply-time approval tokens, freshness checks, traversal, append-only audit, reversible deletes |
46
+ | Contracts, internal knowledge, naming, errors, or effects → [supporting-principles.md](references/supporting-principles.md) | Design by Contract, least knowledge, predictability, command-query separation; researched sources and limits |
47
+ | Go code → [go.md](references/go.md) | Consumer interfaces, structs, composition, package boundaries, errors |
48
+ | Rust code → [rust.md](references/rust.md) | Ownership, enums, traits, privacy, dispatch, error enums, serde newtypes |
49
+ | TypeScript or JavaScript code → [typescript.md](references/typescript.md) | Functions before classes, discriminated unions, branded types, errors with `cause` |
50
+ | Python code → [python.md](references/python.md) | Dataclasses and protocols, exception hierarchies, NewType/Annotated, pydantic at boundaries |
51
+ | Java/C#, functional, or procedural code → [other-paradigms.md](references/other-paradigms.md) | Java/C#, functional and C-style designs |
52
+ | Code, PR, or work-in-progress review → [review.md](references/review.md) | Fixed point and spec source, checklist, severity, evidence, exceptions, review examples |
53
+ | Uncertain scope, work sequencing, durable tradeoff, domain terms, or recurring delivery problem → [lifecycle.md](references/lifecycle.md) | Risk, small batches, decision records, term discipline, feedback and outcome metrics |
54
+ | Selecting tests or making verification/performance claims → [verification.md](references/verification.md) | Behavioral evidence, test fidelity, failure cases, proportional checks |
55
+ | Test-first, TDD, or red-green-refactor → [test-first.md](references/test-first.md) | Vertical slices, seams, red before green, forced red, mockable boundaries |
56
+ | Hard bug, flaky failure, or performance regression → [debugging.md](references/debugging.md) | Feedback loops, minimisation, falsifiable hypotheses, tagged instrumentation, regression seam, cleanup |
57
+ | Untrusted input, identity, permissions, sensitive data, dependencies, or privileged automation → [security.md](references/security.md) | Trust boundaries, abuse cases, dependency and artifact assurance |
58
+ | Persistent state, API/event compatibility, network effects, or release operations → [release.md](references/release.md) | Mixed versions, recovery, idempotency, observability, staged release, release-state evidence |
59
+
60
+ ## Rules
61
+
62
+ MUST Edit generated or vendored behavior through its owned source, generator, or upstream mechanism.
63
+ NOT Introduce classes, interfaces, configuration, frameworks, or tests merely to demonstrate compliance.
@@ -0,0 +1,37 @@
1
+ # Cross-language and wire contracts
2
+
3
+ Read when two sides of a boundary must agree on names, shapes, or casing: generated bindings or clients (OpenAPI, protobuf, GraphQL, ts-rs, specta), IPC command registries, or JSON payloads shared between a backend and a frontend. API and event compatibility across versions is in [release.md](release.md).
4
+
5
+ ## Generated code is committed and drift-checked
6
+
7
+ **Do:** generate bindings from the authoritative side, commit the output, and in CI regenerate and run `git diff --exit-code`. That one gate covers the whole generated surface; consumers use it without repeating it.
8
+ **Do not:** generate in a postinstall step nobody reviews, or hand-edit generated files. Change the source or the generator.
9
+
10
+ ## Names are tested, not trusted
11
+
12
+ **Do:** when one side registers commands or operations by name and the other calls them by string, add a test that fails when the registered set and the called set differ.
13
+ **Do not:** rely on a typo surfacing at runtime in the one code path that uses it.
14
+
15
+ ## One wire casing
16
+
17
+ **Do:** pick one casing for the wire (usually `camelCase` for JSON consumed by JavaScript) and set it once per side: a serializer-wide naming policy, not per-field renames. Add a test that serializes a representative value and checks the keys.
18
+ **Do not:** mix casings across payloads. One mismatched key makes the whole payload fail or, worse, silently drops a field.
19
+
20
+ ## Conformance against the real surface
21
+
22
+ **Do:** run contract or conformance tests against the real backend or the real generated client, at least for the names, casing, and schema of each operation.
23
+ **Do not:** let a mock transport stand in for the contract. A mock agrees with whatever the client sends, so name, casing, and schema mismatches pass.
24
+
25
+ **Exception:** unit tests of client logic can use a fake transport, as long as the fake is itself checked against the real surface (see [verification.md](verification.md)).
26
+
27
+ ## Stubs behind a contract
28
+
29
+ Read when a consumer is built before the provider exists. When to stub and how to swap are in `quality-code-policy`; the conformance suite is in `quality-testing`'s `doubles.md`.
30
+
31
+ **Do:** put the dependency behind the contract's interface (trait, interface, protocol). Consumers take the interface, so a swap changes only wiring. Use the contract's shared types (generated from the schema, or the one shared types module).
32
+ **Do not:** copy a contract type into a stub or consumer, or define the interface inside the stub.
33
+
34
+ **Do:** mark each stub `// STUB(<task-id>): what this fakes` (`#` in Python, TOML and YAML). One marker names one task; a task may cover several markers. Keep stubs minimal and deterministic: implement the contract, nothing more.
35
+ **Do not:** let a stub on a production path silently return plausible fake data. Where it affects behavior, say so with a capability flag or a "not yet supported" error.
36
+
37
+ Drift checks above still apply: regenerate shared types in the same change as a contract change. When two languages share a contract, both consume the same generated schema files: `toolchain-api` has the gates and `quality-testing`'s `shared-contracts.md` the tests. Language examples: [rust.md](rust.md), [python.md](python.md), [typescript.md](typescript.md), [go.md](go.md).
@@ -0,0 +1,85 @@
1
+ # Debugging hard bugs
2
+
3
+ Read for a hard bug, a flaky failure, or a performance regression. Skip a step when the
4
+ evidence already settles it, and say which step you skipped.
5
+
6
+ ## Build a feedback loop
7
+
8
+ With a tight pass/fail signal for this bug, you can bisect, test hypotheses, and
9
+ instrument mechanically. Try these roughly in order:
10
+
11
+ 1. A failing test at whatever seam reaches the bug: unit, integration, end-to-end.
12
+ 2. A curl or HTTP script against a running dev server.
13
+ 3. A CLI invocation on a fixture input, diffing stdout against a known-good snapshot.
14
+ 4. A headless browser script that drives the UI and asserts on DOM, console, or network.
15
+ 5. A replayed capture: a saved request, payload, or event log run through the code path.
16
+ 6. A throwaway harness: a minimal subset of the system reaching the bug in one call.
17
+ 7. A property or fuzz loop: many random inputs, looking for the failure mode.
18
+ 8. A bisection harness: when the bug appeared between two known states, automate
19
+ "boot at state X, check, repeat" and hand it to `git bisect run`.
20
+ 9. A differential loop: the same input through the old and new version, diffing outputs.
21
+ 10. A human-driven step, last resort and only in an interactive session: give the user
22
+ the exact steps and ask for the observed result, redacted.
23
+
24
+ Then tighten the loop: make it faster (cache setup, narrow scope), sharper (assert the
25
+ specific symptom, not "did not crash"), and deterministic (pin time, seed randomness,
26
+ isolate the filesystem, freeze the network). For a flaky bug, raise the reproduction
27
+ rate instead of chasing a clean repro: loop the trigger, parallelise, add stress, inject
28
+ sleeps. A 50% flake is debuggable; 1% is not.
29
+
30
+ Before you claim a diagnosis, run the loop and see it fail with the user's exact symptom:
31
+ the same error, value or behavior, not a nearby failure.
32
+
33
+ No loop is possible: say so and list what you tried. Ask for an environment that
34
+ reproduces it, a redacted captured artifact, or permission for temporary
35
+ instrumentation when a user is reachable. Without a loop, diagnose from source and the
36
+ reported evidence, and label the conclusion unverified.
37
+
38
+ ## Minimise
39
+
40
+ Once the loop fails, cut inputs, callers, config, data, and steps one at a time,
41
+ re-running after each cut, until every remaining element is needed: removing any one
42
+ makes the loop pass. After each cut, check that the loop still fails with the
43
+ original symptom; a cut that changes the failure leads to a different bug. The minimal
44
+ case becomes the regression test.
45
+
46
+ ## Hypothesise
47
+
48
+ Generate 3-5 ranked hypotheses before testing any; a single hypothesis anchors on the
49
+ first plausible idea. Each must be falsifiable: "if X is the cause, changing Y makes the
50
+ bug disappear and changing Z makes it worse." A hypothesis with no prediction is
51
+ discarded or sharpened. In an interactive session, show the ranked list before testing:
52
+ the user may re-rank it at once. Otherwise proceed with your ranking.
53
+
54
+ ## Instrument
55
+
56
+ - Map each probe to one prediction and change one variable at a time.
57
+ - Prefer a debugger or REPL to logs; then targeted logs at the boundaries that separate
58
+ hypotheses. Never log everything and grep.
59
+ - Tag every debug log with a unique prefix such as `[DEBUG-a4f2]`, so cleanup is one grep.
60
+ - Performance regression: logs are usually wrong. Establish a baseline measurement first
61
+ (timing harness, profiler, query plan), then bisect.
62
+
63
+ ## Pick the regression seam
64
+
65
+ Write the regression test at a seam that exercises the real bug pattern as it occurs at
66
+ the call site. A test at a seam too shallow to replicate the triggering chain (for
67
+ example, a single-caller unit test for a multi-caller bug) gives false confidence. When
68
+ no correct seam exists, report that as a finding: the architecture prevents locking the
69
+ bug down. Watch the regression test fail before the fix and pass after it. When you
70
+ force the red by changing code or a fixture, diff against a pristine copy to prove the
71
+ change landed and was undone. Test selection and fidelity are in
72
+ [verification.md](verification.md); test maintenance is in the `quality-testing` skill.
73
+
74
+ ## Redact and clean up
75
+
76
+ Write `[REDACTED]` for every secret in commands, outputs, and artifacts you show; keep
77
+ credentials in environment variables; quote only the signal-carrying lines of an artifact.
78
+
79
+ Before declaring done:
80
+
81
+ - the original repro no longer reproduces (re-run the first loop);
82
+ - the regression test passes, or the missing seam is documented;
83
+ - every `[DEBUG-...]` probe is removed (grep the prefix) and throwaway harnesses are
84
+ deleted or moved to a clearly marked location;
85
+ - the confirmed hypothesis is stated in the commit or PR message.
@@ -0,0 +1,67 @@
1
+ # Deep modules and seams
2
+
3
+ Read when designing or deepening a module's interface, choosing where a seam goes, or
4
+ making code more testable. Encapsulation and composition basics are in
5
+ [encapsulation.md](encapsulation.md).
6
+
7
+ ## Vocabulary
8
+
9
+ - **Module:** anything with an interface and an implementation, at any scale: a function,
10
+ class, package, or tier-spanning slice.
11
+ - **Interface:** everything a caller must know to use the module correctly: types, and
12
+ also invariants, ordering constraints, error modes, required configuration, and
13
+ performance characteristics.
14
+ - **Depth:** behavior per unit of interface a caller learns. A module is **deep** when a
15
+ large amount of behavior sits behind a small interface, **shallow** when the interface
16
+ is nearly as complex as the implementation.
17
+ - **Seam:** a place where behavior can be altered without editing in that place; the
18
+ location at which a module's interface lives. Choosing it is a design decision of its own.
19
+ - **Adapter:** a concrete thing that satisfies an interface at a seam.
20
+ - **Leverage** is what callers gain from depth; **locality** is what maintainers gain:
21
+ change, bugs, and knowledge concentrate in one place instead of across callers.
22
+
23
+ ## Principles
24
+
25
+ - Depth is a property of the interface. A deep module can be built from small, swappable
26
+ parts that are not part of its interface; it may have internal seams for its own tests.
27
+ Do not expose an internal seam through the interface just because tests use it.
28
+ - Deletion test: imagine deleting the module. If complexity vanishes, it was a
29
+ pass-through. If complexity reappears across many callers, it earned its keep.
30
+ - The interface is the test surface. Callers and tests cross the same seam; a test that
31
+ must reach past the interface signals the wrong module shape.
32
+ - When designing an interface, ask whether methods can be fewer, parameters simpler, and
33
+ more complexity hidden inside.
34
+
35
+ ## The seam rule
36
+
37
+ Introduce a seam (interface, trait, callback, or port) where something varies across it
38
+ now or a real boundary needs protecting: a second adapter in use (a test adapter counts),
39
+ a remote or external system, or a dependency whose types must not leak into callers. A
40
+ seam with one adapter and no such boundary is indirection: call the implementation
41
+ directly. Implementation count alone decides neither way.
42
+
43
+ ## Deepening a cluster of shallow modules
44
+
45
+ Classify each dependency first; the category decides how the deepened module is tested.
46
+
47
+ | Dependency → test approach | Seam |
48
+ |---|---|
49
+ | In-process: pure computation, in-memory state, no I/O → merge the modules and test through the new interface | none needed |
50
+ | Local-substitutable: has a local stand-in (PGLite for Postgres, an in-memory filesystem) → run the stand-in in the test suite | internal |
51
+ | Remote but owned: your own services across a network → define a port at the seam; production uses an HTTP/gRPC/queue adapter, tests an in-memory adapter | port |
52
+ | True external: third-party services you do not control → inject the port; tests use a mock adapter | port |
53
+
54
+ Replace, do not layer: write tests at the deepened module's interface, asserting
55
+ observable outcomes rather than internal state. Before deleting the old unit tests on the
56
+ shallow modules, port every edge case they cover to the new interface tests; delete an old
57
+ test only once its cases pass there.
58
+
59
+ ## Design it twice (optional)
60
+
61
+ Run this only when the user asks to explore alternative interfaces. State the
62
+ constraints, dependencies (with their category), and a rough code sketch, then produce
63
+ two to four radically different interfaces, for example: minimal entry points;
64
+ maximum flexibility; the commonest caller made trivial; ports and adapters across seams.
65
+ Parallel sub-agents may draft them within the delegation limits. For each, give the
66
+ interface, a usage example, what it hides, its dependency strategy, and its trade-offs.
67
+ Compare on depth, locality, and seam placement, then recommend one or a hybrid.
@@ -0,0 +1,81 @@
1
+ # Dependencies, ORMs, and one consumer
2
+
3
+ ## Research before adding a capability
4
+
5
+ **Do:** run these checks when a change adds a capability or dependency the repository does not already have. Keep a small task's search short, but perform it before implementation.
6
+
7
+ 1. Search the codebase by behavior and domain meaning, not only by the desired function name. Read shared packages/utilities, relevant callers/tests, installed dependencies, manifests, and conventions.
8
+ 2. Inspect related implementations and relevant earlier work available in the repository/history or linked task context. Determine whether existing local code can supply the need directly or become a cohesive shared capability. Do not search unrelated private repositories or assume unavailable prior work exists.
9
+ 3. When nothing local fits, research current best practice for the concern (official documentation, context7, the web) and compare the plan with the preferred-library standards: the `lang-<language>-libraries` skill for the language, `toolchain-api` for an API style, `aws-guidance` for AWS Lambda and AWS service clients, then `toolchain-languages`. Follow the project's existing choices first, then the listed default, then a listed alternative whose condition holds. Check the framework's own features (middleware, validation, Powertools on Lambda, OpenTelemetry instrumentation) before a separate package. Verify the candidate API/version and fit against authoritative documentation: required behavior, maintenance/support, compatibility, relevant security/licensing/deployment constraints, and operational cost. Popularity alone is not maturity or suitability.
10
+ 4. Choose suitable existing shared code, direct reuse, a bounded extraction, an established library, or custom code supported by a concrete gap. Compare actual semantics and total complexity; do not invent a minimum consumer count or an arbitrary package-search quota. A new dependency the request did not name needs the user's approval before it is added.
11
+ 5. Record a concise reuse decision in the existing task evidence: paths/symbols inspected, sources/versions consulted, the standard compared against, choice, and material reasons. Report each departure from a listed default with the gap that justified it. Reuse current task-local research when it addresses the same requirement.
12
+
13
+ **Do not:** start a custom implementation and research alternatives afterward, recreate a suitable available capability, or declare "nothing reusable" without examining candidates.
14
+
15
+ Bad: write a new pagination helper without reading the existing `shared/pagination` module or the framework's documented iterator.
16
+ Good: inspect both contracts and use the suitable existing capability; add only the domain behavior still missing.
17
+
18
+ Bad: copy a previous importer into a new command even though parsing and validation represent the same contract.
19
+ Good: extract that proven responsibility into the appropriate shared module and preserve existing consumers with focused checks.
20
+
21
+ Bad: turn unrelated password and invoice-number validators into one configurable utility because their current shapes match.
22
+ Good: keep independent policies separate; share only knowledge that must evolve together.
23
+
24
+ Bad: hand-write an archive parser while a maintained standard or ecosystem implementation meets the format and deployment requirements.
25
+ Good: verify the documented API and supported version, reuse it, and test the application's integration and failure behavior.
26
+
27
+ **Exception:** custom code is justified when researched options fail a required contract, deployment/license constraint, measured performance need, or present simplicity test. State the actual gap and the smallest custom scope; unfamiliarity or preference is insufficient. A standard command can be the appropriate reusable solution for a one-off script.
28
+
29
+ If a source/tool is unavailable, do not claim the check passed. Use available authoritative material or request research through the lead/researcher before implementing the unresolved capability. Read-only reviewers stay within their evidence contract: they assess reuse research only when the caller supplies it, and never fetch arbitrary URLs to fill the gap.
30
+
31
+ ## Choose by present simplification
32
+
33
+ **Do:** compare the complete current solution: application code, correctness work, setup, migrations, operations, debugging, upgrades, and lock-in.
34
+ **Do not:** reject a dependency because only one component consumes it, or add it for hypothetical future scale.
35
+
36
+ Bad: hand-write relationship hydration, transaction handling, migrations, and mapping in several modules because "an ORM is overkill with one consumer."
37
+ Good: use the established ORM when its existing capabilities replace that required machinery and its lifecycle costs fit the project. Keep transaction ownership visible and persistence types contained where domain policy needs independence.
38
+
39
+ Bad in the other direction: add a framework, migration service, and repository hierarchy to a disposable script performing one parameterized query.
40
+ Good: use the standard database driver and explicit query when that is the simpler complete solution.
41
+
42
+ Why: YAGNI limits speculative functionality; it does not require rebuilding useful existing functionality by hand. KISS measures total complexity rather than installation size alone.
43
+
44
+ **Exception:** deployment restrictions, unsupported database features, performance measurements, or dependency policy can make the hand-written solution preferable. Document the actual constraint and what it costs; do not invent a policy to avoid evaluating the library.
45
+
46
+ ## Keep transaction and persistence boundaries meaningful
47
+
48
+ Bad:
49
+
50
+ ```ts
51
+ // Domain callers depend on ORM query syntax and partially loaded row state.
52
+ interface Orders { find(args: VendorQuery): Promise<VendorOrderRow> }
53
+ ```
54
+
55
+ Good when domain policy exists:
56
+
57
+ ```ts
58
+ interface Orders { reserveStock(order: Order): Promise<ReservationResult> }
59
+ // The adapter owns the transaction needed for the promised reservation semantics.
60
+ ```
61
+
62
+ Good for simple CRUD: use the ORM in the application/data layer directly; omit a generic repository that merely duplicates its complete API.
63
+
64
+ **Do:** name atomicity, durability, failure, and partial-success semantics in the operation contract when callers depend on them. Keep all changes that must be atomic inside one transaction owner.
65
+ **Do not:** split one transaction into multiple repositories that each silently commit, or let lazy loading create invisible I/O in pure domain operations.
66
+
67
+ **Exception:** a framework's unit-of-work convention can own the transaction if that lifecycle is clear and consistently honored. Follow its idiom instead of adding a parallel transaction framework.
68
+
69
+ State transitions, migrations, dynamic SQL, and database tests: [persistence.md](persistence.md).
70
+
71
+ ## Leave extraction practical
72
+
73
+ Bad: a "temporary" direct SDK call spreads provider-specific errors and data types through every caller.
74
+ Good: one adapter/module maps provider results and errors to application meaning. A later second adapter can fulfill that contract without rewriting business rules.
75
+
76
+ Bad: wrap every library function in a one-for-one local facade regardless of exposure.
77
+ Good: wrap the boundary the application actually owns; use stable utility libraries directly inside cohesive modules.
78
+
79
+ Why: containment is valuable now; comprehensive replacement frameworks are not automatically valuable.
80
+
81
+ **Exception:** vendor types can remain inside code whose responsibility is vendor integration. Do not pretend the integration adapter itself must be vendor-independent.