architecture-harness 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (109) hide show
  1. package/package.json +80 -0
  2. package/src/cli/check.mjs +535 -0
  3. package/src/cli/cli.test.mjs +120 -0
  4. package/src/cli/commit-attribution.mjs +68 -0
  5. package/src/cli/commit-attribution.test.mjs +47 -0
  6. package/src/cli/decisions.mjs +223 -0
  7. package/src/cli/doctor.mjs +135 -0
  8. package/src/cli/doctor.test.mjs +57 -0
  9. package/src/cli/init.mjs +98 -0
  10. package/src/cli/install-hooks.mjs +26 -0
  11. package/src/cli/qc.mjs +89 -0
  12. package/src/cli/scaffold.mjs +194 -0
  13. package/src/cli/sync-enforcement-map.mjs +28 -0
  14. package/src/cli/work-order-guard.mjs +0 -0
  15. package/src/cli/work-order-guard.test.mjs +79 -0
  16. package/src/cli/worktree-isolation.mjs +94 -0
  17. package/src/cli/worktree-isolation.test.mjs +82 -0
  18. package/src/config.mjs +338 -0
  19. package/src/config.test.mjs +59 -0
  20. package/src/decisions.mjs +198 -0
  21. package/src/decisions.test.mjs +183 -0
  22. package/src/descriptions.mjs +28 -0
  23. package/src/descriptions.test.mjs +27 -0
  24. package/src/enforcement-map.mjs +46 -0
  25. package/src/enforcement-map.test.mjs +60 -0
  26. package/src/eslint/index.mjs +37 -0
  27. package/src/eslint/options.mjs +53 -0
  28. package/src/eslint/preset.mjs +192 -0
  29. package/src/eslint/preset.test.mjs +96 -0
  30. package/src/eslint/rules/durable-idempotency-key.mjs +120 -0
  31. package/src/eslint/rules/external-service-only-in-adapter.mjs +52 -0
  32. package/src/eslint/rules/module-boundary.mjs +12 -0
  33. package/src/eslint/rules/name-the-pattern.mjs +111 -0
  34. package/src/eslint/rules/no-comment-paragraph.mjs +101 -0
  35. package/src/eslint/rules/no-cross-feature-internals.mjs +57 -0
  36. package/src/eslint/rules/no-number-in-comment.mjs +89 -0
  37. package/src/eslint/rules/no-offset-pagination.mjs +29 -0
  38. package/src/eslint/rules/no-orchestration-in-trigger.mjs +56 -0
  39. package/src/eslint/rules/no-promise-then.mjs +43 -0
  40. package/src/eslint/rules/no-promise-then.test.mjs +63 -0
  41. package/src/eslint/rules/no-raw-fetch.mjs +27 -0
  42. package/src/eslint/rules/no-status-literal.mjs +34 -0
  43. package/src/eslint/rules/no-supersession-trail.mjs +51 -0
  44. package/src/eslint/rules/scoped-repository.mjs +43 -0
  45. package/src/eslint/rules/signal-last-param.mjs +43 -0
  46. package/src/eslint/rules/storage-only-in-resource.mjs +52 -0
  47. package/src/eslint/rules/tenant-scoped-table.mjs +71 -0
  48. package/src/eslint/rules.test.mjs +627 -0
  49. package/src/gates/adr-format.mjs +87 -0
  50. package/src/gates/adr-format.test.mjs +54 -0
  51. package/src/gates/audit-append-only.mjs +34 -0
  52. package/src/gates/audit-append-only.test.mjs +36 -0
  53. package/src/gates/citations.mjs +93 -0
  54. package/src/gates/citations.test.mjs +115 -0
  55. package/src/gates/claimed-requirements.mjs +53 -0
  56. package/src/gates/claimed-requirements.test.mjs +60 -0
  57. package/src/gates/comment-style.mjs +76 -0
  58. package/src/gates/comment-style.test.mjs +46 -0
  59. package/src/gates/config-floor.mjs +68 -0
  60. package/src/gates/config-floor.test.mjs +52 -0
  61. package/src/gates/contract-compose.mjs +38 -0
  62. package/src/gates/contract-compose.test.mjs +40 -0
  63. package/src/gates/eight-blocks.mjs +223 -0
  64. package/src/gates/eight-blocks.test.mjs +359 -0
  65. package/src/gates/enforcement-map.mjs +62 -0
  66. package/src/gates/enforcement-map.test.mjs +41 -0
  67. package/src/gates/english-source.mjs +176 -0
  68. package/src/gates/english-source.test.mjs +122 -0
  69. package/src/gates/frontend-boundaries.mjs +154 -0
  70. package/src/gates/frontend-boundaries.test.mjs +72 -0
  71. package/src/gates/gate-tests.mjs +44 -0
  72. package/src/gates/gate-tests.test.mjs +41 -0
  73. package/src/gates/headless-sagas.mjs +54 -0
  74. package/src/gates/headless-sagas.test.mjs +71 -0
  75. package/src/gates/internal-routes.mjs +76 -0
  76. package/src/gates/internal-routes.test.mjs +53 -0
  77. package/src/gates/public-routes.mjs +67 -0
  78. package/src/gates/public-routes.test.mjs +38 -0
  79. package/src/gates/registry-agreement.mjs +37 -0
  80. package/src/gates/registry-agreement.test.mjs +36 -0
  81. package/src/gates/saga-tests.mjs +94 -0
  82. package/src/gates/saga-tests.test.mjs +92 -0
  83. package/src/gates/sql-identifiers.mjs +244 -0
  84. package/src/gates/sql-identifiers.test.mjs +197 -0
  85. package/src/gates/tenant-predicate.mjs +175 -0
  86. package/src/gates/tenant-predicate.test.mjs +161 -0
  87. package/src/gates/tenant-tables.mjs +65 -0
  88. package/src/gates/tenant-tables.test.mjs +56 -0
  89. package/src/gates/test-mirror.mjs +47 -0
  90. package/src/gates/test-mirror.test.mjs +31 -0
  91. package/src/index.mjs +9 -0
  92. package/templates/.jscpd.json +15 -0
  93. package/templates/CLAUDE.md +54 -0
  94. package/templates/decisions.examples.md +25 -0
  95. package/templates/docs/adr-template.md +58 -0
  96. package/templates/docs/architecture.md +179 -0
  97. package/templates/docs/decisions.md +72 -0
  98. package/templates/docs/enforcement.md +94 -0
  99. package/templates/docs/glossary.md +16 -0
  100. package/templates/docs/guards.md +23 -0
  101. package/templates/docs/pagination.md +113 -0
  102. package/templates/docs/performance.md +35 -0
  103. package/templates/docs/ui.md +32 -0
  104. package/templates/githooks/commit-msg +4 -0
  105. package/templates/githooks/pre-commit +18 -0
  106. package/templates/githooks/pre-push +6 -0
  107. package/templates/github/workflows/ci.yml +21 -0
  108. package/templates/qc.config.json +6 -0
  109. package/templates/quality-thresholds.json +114 -0
@@ -0,0 +1,113 @@
1
+ # Pagination
2
+
3
+ Keyset only. `offset` and `skip` are rejected — `qc/no-offset-pagination`.
4
+
5
+ Offset asks the database to walk past rows to reach the ones you want, so page one and page
6
+ five hundred cost different amounts, and the deeper the page the worse it gets. It is also
7
+ wrong under concurrent writes: a row inserted above the window shifts everything down, so the
8
+ reader sees a row twice or never.
9
+
10
+ Keyset asks a different question — *the rows after this one* — which is one index seek at any
11
+ depth, and stable while rows are inserted.
12
+
13
+ ## The query, and the index that makes it free
14
+
15
+ ```sql
16
+ create index on photos (tenant_id, captured_at desc, id desc);
17
+ ```
18
+
19
+ ```sql
20
+ select ... from photos
21
+ where tenant_id = $1
22
+ and (captured_at, id) < ($2, $3)
23
+ order by captured_at desc, id desc
24
+ limit $4;
25
+ ```
26
+
27
+ Three things decide whether this is a seek or a scan:
28
+
29
+ - **Row-value comparison.** `(a, b) < (x, y)`, never `a < x or (a = x and b < y)`. The first
30
+ descends the composite index directly; the second frequently does not.
31
+ - **A unique tiebreaker.** Sorting on a timestamp alone silently skips or repeats rows whenever
32
+ two rows share a value. The last column of the sort must be unique.
33
+ - **The index matches the sort exactly** — tenant first, then every sort column, same directions.
34
+
35
+ ## The cursor is opaque, and that is load-bearing
36
+
37
+ The cursor is encoded and signed, never a readable pair of column values.
38
+
39
+ A cursor a client can read is a cursor a client will parse, and from then on the sort key is
40
+ public API: you cannot add a column to the ordering, change a direction, or migrate the key
41
+ without breaking every caller that learned to read it. Base-64 alone is not enough — it is
42
+ encoding, not opacity.
43
+
44
+ This follows both public standards. Relay's connection spec says a cursor "should be considered
45
+ opaque by the client". Google's AIP-158 is stronger: page tokens **must** be opaque and **must
46
+ not** be user-parseable, and calls base-64 explicitly insufficient.
47
+
48
+ ## "How many are there?"
49
+
50
+ An exact count over a large collection is a full scan of the index, every request. Do not serve
51
+ one by default. In order of preference:
52
+
53
+ | | Cost | What it says |
54
+ |---|---|---|
55
+ | **Bounded count** | capped | "1,000+ results" |
56
+ | Estimate from table statistics | free | "about 12,000 results" |
57
+ | Exact `count(*)` | O(n) | "1,247 results" |
58
+ | Nothing | free | infinite scroll |
59
+
60
+ The bounded count is the default:
61
+
62
+ ```sql
63
+ select count(*) from (
64
+ select 1 from photos
65
+ where tenant_id = $1 and folder_id = $2
66
+ limit 1001
67
+ ) capped;
68
+ ```
69
+
70
+ Cost is capped whatever the collection holds, and below the cap the number is exact for free.
71
+
72
+ If the response carries a total, it is named as an estimate and documented as one. AIP-158
73
+ permits a `total_size` that "may be an estimate", provided the API says so. An undocumented
74
+ approximate count is worse than none.
75
+
76
+ ## Jumping to a page
77
+
78
+ Keyset cannot do it. Finding the row at position nine hundred means walking nine hundred rows,
79
+ which is offset by another name.
80
+
81
+ Almost every real use of a page number is one of two things, and both have a better answer:
82
+
83
+ - **"take me to the end"** — reverse the sort and fetch the first page
84
+ - **"take me to around March"** — seek on the sort key, not on an ordinal. A date jump, an
85
+ alphabet index, a filter. Same query shape, same index, no counting
86
+
87
+ Genuine ordinal paging belongs to paginated *deliverables* — a printed ledger, a regulatory
88
+ export — not to browsing. Where a surface truly needs it, AIP-158 sanctions a `skip` field that
89
+ returns an empty result set rather than a slow one. Here that is an exemption: a marked comment
90
+ carrying its reason, printed on every run, the way the tenant predicate handles its exceptions.
91
+
92
+ ## The client
93
+
94
+ A keyset cursor maps onto an infinite query: the page parameter is the cursor, and the end of
95
+ the collection is the absence of a next one.
96
+
97
+ ```ts
98
+ useInfiniteQuery({
99
+ queryKey: ['photos', folderId],
100
+ queryFn: ({ pageParam, signal }) => fetchPhotos(folderId, pageParam, signal),
101
+ initialPageParam: null,
102
+ getNextPageParam: (lastPage) => lastPage.nextCursor,
103
+ maxPages: 5,
104
+ })
105
+ ```
106
+
107
+ `maxPages` bounds memory on a long scroll; it needs `getPreviousPageParam` to refetch in both
108
+ directions. A page-number interface is a different hook entirely — a plain query keyed on the
109
+ page — which is another reason not to build one.
110
+
111
+ **Invalidating an infinite query refetches every loaded page**, not the stale one. Ten pages
112
+ loaded is ten round trips per notification. Narrow the key, or apply the change in place when
113
+ the row is already loaded and refetch only when it is not — ADR-0048.
@@ -0,0 +1,35 @@
1
+ # Performance
2
+
3
+ The one home for these numbers. Cite this file; never copy a figure into code, a comment or an
4
+ agent prompt. The no-number-in-comment rule exists to keep that true.
5
+
6
+ ## Interaction budgets
7
+
8
+ A budget is about the **acknowledgement**, not the answer. Loading a large collection may take
9
+ seconds; showing that it started may not.
10
+
11
+ | Surface | Budget | Measured as |
12
+ |---|---|---|
13
+ | Any tap or click acknowledged | 100 ms | First visual change: pressed state, skeleton, optimistic row |
14
+ | Interaction to next paint (p75) | 200 ms | Web Vitals INP, collected in production |
15
+ | Longest task on the interface thread | 50 ms | Long-task observer; above it, split or move off-thread |
16
+
17
+ ## Per-surface budgets
18
+
19
+ Replace this table with your own surfaces. Each row names a surface, a number, and the conditions
20
+ under which the number holds — a budget without conditions is not measurable.
21
+
22
+ | Surface | Budget |
23
+ |---|---|
24
+ | *(your list view, p95)* | *(number, at what size, with what query)* |
25
+ | *(your heaviest render)* | *(frame time, at what item count, on what device)* |
26
+ | *(your background worker)* | *(throughput per tenant; per-item p95)* |
27
+
28
+ ## Rules
29
+
30
+ - Nothing over the long-task budget runs where the interface runs.
31
+ - Every list endpoint is keyset-paginated with a server-capped limit.
32
+ - Derivatives are made server-side. Client-side derivative generation is forbidden. ADR-0018.
33
+ - Lists holding hundreds of rows are virtualized.
34
+ - Optimistic by default on write, **except money and evidence**.
35
+ - A performance budget is not a quality gate: gates live in `quality-thresholds.json`.
@@ -0,0 +1,32 @@
1
+ # UI
2
+
3
+ ## Parity
4
+
5
+ Visual parity with whatever this replaces is the default. Divergence is argued in the work order,
6
+ with a before and after.
7
+
8
+ ## Presenters — QC-010
9
+
10
+ A view gathers input and invokes a headless workflow. It does not orchestrate. The
11
+ `no-orchestration-in-trigger` rule is what holds this: more than one `await` in a presenter is the
12
+ signal that a workflow belongs behind it.
13
+
14
+ ## Realtime — ADR-0048
15
+
16
+ A frame names a row; the client invalidates and refetches. Frames carry notifications, not data, so
17
+ a missed frame costs a refetch rather than a divergence.
18
+
19
+ ## Cancellation — ADR-0038
20
+
21
+ The cancellation token is the last parameter of every function that can outlive the interaction. A
22
+ write is never cancelled by navigation.
23
+
24
+ ## Accessibility — ADR-0040
25
+
26
+ WCAG 2.2 AA. Every drag has a non-drag equivalent. The focus ring is never removed.
27
+
28
+ ## Hot loops
29
+
30
+ Data-oriented discipline applies to any hot loop: per frame, or over a large item count, or
31
+ allocating per iteration on the interaction thread. Assert it by measuring allocation, not by
32
+ reading the code.
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env bash
2
+ # A tool is not an author. Checked here because a trailer is added at commit time and nowhere else.
3
+ set -euo pipefail
4
+ npx qc commit-msg "$1" || exit 1
@@ -0,0 +1,18 @@
1
+ #!/usr/bin/env bash
2
+ # A human is bound by exactly what binds an agent.
3
+ # Fast tier only: staged-file lint, types, and each touched feature's own structure. The
4
+ # repository-wide gates (citations, tenant predicate, route agreement...) run once per push
5
+ # instead of once per commit — see the pre-push hook.
6
+ set -euo pipefail
7
+ # Runs before the extension filter below: a work order's own branch is checked regardless of
8
+ # what kind of file it touches, so a commit of .tf/.yml/.md files is covered too.
9
+ npx qc work-order-check || exit 1
10
+ STAGED=$(git diff --cached --name-only --diff-filter=ACM | grep -E '\.(ts|tsx|mjs)$' || true)
11
+ [ -z "$STAGED" ] && exit 0
12
+ # `--no-warn-ignored`: a staged file the config ignores is a decision, not a finding, and
13
+ # without it a generated file turns "I ignored that" into a warning that fails the gate.
14
+ npx eslint $STAGED --max-warnings 0 --no-warn-ignored
15
+ npx tsc -b --pretty false
16
+ for file in $STAGED; do
17
+ npx qc check "$file"
18
+ done
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env bash
2
+ # The full pass: every repository-wide gate the fast pre-commit tier skips — citations, the
3
+ # tenant predicate, route agreement, sagas. Once per push, not once per commit.
4
+ set -euo pipefail
5
+ cd "$(git rev-parse --show-toplevel)"
6
+ npx qc check
@@ -0,0 +1,21 @@
1
+ name: ci
2
+ on: [push, pull_request]
3
+
4
+ jobs:
5
+ gates:
6
+ runs-on: ubuntu-latest
7
+ steps:
8
+ - uses: actions/checkout@v5
9
+ - uses: actions/setup-node@v5
10
+ with: { node-version-file: package.json }
11
+ - run: corepack enable
12
+ - run: pnpm install --frozen-lockfile
13
+
14
+ # The structural gates. This step needs no package script of its own.
15
+ - run: npx qc check
16
+
17
+ # Uncomment each as the repository grows the thing it checks.
18
+ # - run: pnpm typecheck
19
+ # - run: pnpm lint
20
+ # - run: pnpm dup:check
21
+ # - run: pnpm test
@@ -0,0 +1,6 @@
1
+ {
2
+ "$comment": "Every key is optional. A key you do not set keeps the reference default; run `qc config` to print what is in force. See the kit's README for the full surface.",
3
+ "featureRoots": ["backend/src/features", "frontend/src/features"],
4
+ "foreign": [],
5
+ "agreements": []
6
+ }
@@ -0,0 +1,114 @@
1
+ {
2
+ "note": "The one home for a number a quality gate enforces. Docs carry a token, never a figure; every eslint config, the coverage config and CI import this file rather than restating it. Loosening a threshold is one edit here, visible in one diff.",
3
+ "updated": "replace with the date you adopted this",
4
+ "policy": {
5
+ "loosening": "Raising a limit or lowering coverage needs the same review as a spec change: the diff on this file is the record. A per-file override belongs in the config that needs it, with a comment naming why, never here.",
6
+ "match": "A threshold has no distinctive spelling the way a version number does, so each gate lists the phrases a page or a config would use when stating it. scripts/check.mjs reports a digit beside one of them as a literal. Add a phrase when a new wording appears; the phrases are the whole reason the literal check can exist.",
7
+ "notThresholds": "A performance budget is not a quality gate. Latency, memory and render budgets live in docs/performance.md, because they are measured per surface rather than enforced repository-wide."
8
+ },
9
+ "gates": {
10
+ "coverage": {
11
+ "label": "Coverage on new code",
12
+ "value": 70,
13
+ "unit": "percent",
14
+ "comparator": "min",
15
+ "enforcedBy": "vitest --coverage, thresholds read from this file",
16
+ "match": [
17
+ "coverage on new code",
18
+ "coverage threshold"
19
+ ]
20
+ },
21
+ "cognitive": {
22
+ "label": "Cognitive complexity per function",
23
+ "value": 12,
24
+ "unit": "count",
25
+ "comparator": "max",
26
+ "enforcedBy": "eslint sonarjs/cognitive-complexity",
27
+ "match": [
28
+ "cognitive complexity"
29
+ ]
30
+ },
31
+ "funclength": {
32
+ "label": "Function length",
33
+ "value": 50,
34
+ "unit": "lines",
35
+ "comparator": "max",
36
+ "enforcedBy": "eslint max-lines-per-function",
37
+ "match": [
38
+ "function length",
39
+ "max-lines-per-function",
40
+ "lines per function"
41
+ ]
42
+ },
43
+ "filelength": {
44
+ "label": "File length",
45
+ "value": 500,
46
+ "unit": "lines",
47
+ "comparator": "max",
48
+ "enforcedBy": "eslint max-lines",
49
+ "note": "Code lines: blanks and comments do not count, so a file is never shortened by deleting the reasoning. A shorter target was reviewed and declined on evidence \u2014 the anatomy was applied repo-wide first, moving every reused step into fragment.ts and every invariant into record.ts, and it moved the longest files by tens of lines while leaving the same count above 250. What is left is features that own several tables, and only a feature split shortens those; some of those splits would put a write guard across a feature boundary, which is a worse trade than the number. docs/enforcement.md. Never lower this gate ahead of the work it demands: a gate that lands first blocks only whoever is doing that work.",
50
+ "match": [
51
+ "file length",
52
+ "max-lines",
53
+ "lines per file"
54
+ ]
55
+ },
56
+ "nesting": {
57
+ "label": "Nesting depth",
58
+ "value": 3,
59
+ "unit": "count",
60
+ "comparator": "max",
61
+ "enforcedBy": "eslint max-depth",
62
+ "match": [
63
+ "nesting depth",
64
+ "max-depth"
65
+ ]
66
+ },
67
+ "duplication": {
68
+ "label": "Duplication",
69
+ "value": 2,
70
+ "unit": "percent",
71
+ "comparator": "max",
72
+ "enforcedBy": "jscpd, threshold read from this file",
73
+ "match": [
74
+ "duplication"
75
+ ]
76
+ },
77
+ "maxwarnings": {
78
+ "label": "ESLint warnings tolerated",
79
+ "value": 0,
80
+ "unit": "count",
81
+ "comparator": "max",
82
+ "enforcedBy": "eslint --max-warnings, value read from this file",
83
+ "match": [
84
+ "max-warnings",
85
+ "eslint warning",
86
+ "warnings tolerated"
87
+ ]
88
+ },
89
+ "axeviolations": {
90
+ "label": "Accessibility violations tolerated per route",
91
+ "value": 0,
92
+ "unit": "count",
93
+ "comparator": "max",
94
+ "enforcedBy": "@axe-core/playwright over wcag2a, wcag2aa, wcag21aa and wcag22aa",
95
+ "match": [
96
+ "accessibility violation",
97
+ "axe violation",
98
+ "violations tolerated"
99
+ ]
100
+ },
101
+ "touchtarget": {
102
+ "label": "Touch target on site-tablet flows",
103
+ "value": 44,
104
+ "unit": "px",
105
+ "comparator": "min",
106
+ "enforcedBy": "asserted in the Playwright and Maestro suites; no linter can measure a rendered box",
107
+ "match": [
108
+ "touch target",
109
+ "tap target",
110
+ "target size"
111
+ ]
112
+ }
113
+ }
114
+ }