@shivaedev/quality 0.31.1 → 0.32.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 (93) hide show
  1. package/CHANGELOG.md +21 -0
  2. package/README.md +20 -5
  3. package/dist/baseline/installDriver.d.ts +5 -0
  4. package/dist/baseline/installDriver.d.ts.map +1 -0
  5. package/dist/baseline/installDriver.js +11 -0
  6. package/dist/baseline/installDriver.js.map +1 -0
  7. package/dist/baseline/merge.d.ts +4 -0
  8. package/dist/baseline/merge.d.ts.map +1 -0
  9. package/dist/baseline/merge.js +28 -0
  10. package/dist/baseline/merge.js.map +1 -0
  11. package/dist/baseline/rewrite.d.ts.map +1 -1
  12. package/dist/baseline/rewrite.js +0 -1
  13. package/dist/baseline/rewrite.js.map +1 -1
  14. package/dist/baseline/shards.d.ts +13 -0
  15. package/dist/baseline/shards.d.ts.map +1 -0
  16. package/dist/baseline/shards.js +48 -0
  17. package/dist/baseline/shards.js.map +1 -0
  18. package/dist/cli/args.d.ts +8 -1
  19. package/dist/cli/args.d.ts.map +1 -1
  20. package/dist/cli/args.js +9 -0
  21. package/dist/cli/args.js.map +1 -1
  22. package/dist/cli/baseline.d.ts.map +1 -1
  23. package/dist/cli/baseline.js +6 -7
  24. package/dist/cli/baseline.js.map +1 -1
  25. package/dist/cli/messages.d.ts +1 -1
  26. package/dist/cli/messages.d.ts.map +1 -1
  27. package/dist/cli/messages.js +6 -2
  28. package/dist/cli/messages.js.map +1 -1
  29. package/dist/cli/migrate.d.ts.map +1 -1
  30. package/dist/cli/migrate.js +10 -6
  31. package/dist/cli/migrate.js.map +1 -1
  32. package/dist/cli/program.d.ts.map +1 -1
  33. package/dist/cli/program.js +6 -0
  34. package/dist/cli/program.js.map +1 -1
  35. package/dist/config/load.js +1 -1
  36. package/dist/engine/baselineFile.d.ts +2 -1
  37. package/dist/engine/baselineFile.d.ts.map +1 -1
  38. package/dist/engine/baselineFile.js +23 -6
  39. package/dist/engine/baselineFile.js.map +1 -1
  40. package/dist/hooks/forwarding.d.ts +7 -0
  41. package/dist/hooks/forwarding.d.ts.map +1 -0
  42. package/dist/hooks/forwarding.js +94 -0
  43. package/dist/hooks/forwarding.js.map +1 -0
  44. package/dist/hooks/install.d.ts.map +1 -1
  45. package/dist/hooks/install.js +2 -1
  46. package/dist/hooks/install.js.map +1 -1
  47. package/dist/hooks/shim.d.ts +1 -0
  48. package/dist/hooks/shim.d.ts.map +1 -1
  49. package/dist/hooks/shim.js +3 -1
  50. package/dist/hooks/shim.js.map +1 -1
  51. package/dist/hooks/status.d.ts +1 -1
  52. package/dist/hooks/status.d.ts.map +1 -1
  53. package/dist/hooks/status.js +8 -6
  54. package/dist/hooks/status.js.map +1 -1
  55. package/dist/hooks/uninstall.d.ts.map +1 -1
  56. package/dist/hooks/uninstall.js +3 -1
  57. package/dist/hooks/uninstall.js.map +1 -1
  58. package/dist/imports/packageExports.d.ts +4 -0
  59. package/dist/imports/packageExports.d.ts.map +1 -0
  60. package/dist/imports/packageExports.js +48 -0
  61. package/dist/imports/packageExports.js.map +1 -0
  62. package/dist/imports/publicModules.d.ts +4 -0
  63. package/dist/imports/publicModules.d.ts.map +1 -0
  64. package/dist/imports/publicModules.js +21 -0
  65. package/dist/imports/publicModules.js.map +1 -0
  66. package/dist/rules/imports/bundleInputs.d.ts.map +1 -1
  67. package/dist/rules/imports/bundleInputs.js +4 -50
  68. package/dist/rules/imports/bundleInputs.js.map +1 -1
  69. package/dist/rules/stories/supportImports.d.ts.map +1 -1
  70. package/dist/rules/stories/supportImports.js +9 -3
  71. package/dist/rules/stories/supportImports.js.map +1 -1
  72. package/docs/debt-and-hooks.md +9 -6
  73. package/package.json +3 -3
  74. package/src/baseline/installDriver.ts +12 -0
  75. package/src/baseline/merge.ts +34 -0
  76. package/src/baseline/rewrite.ts +0 -1
  77. package/src/baseline/shards.ts +60 -0
  78. package/src/cli/args.ts +11 -0
  79. package/src/cli/baseline.ts +6 -10
  80. package/src/cli/messages.ts +6 -2
  81. package/src/cli/migrate.ts +10 -6
  82. package/src/cli/program.ts +6 -0
  83. package/src/config/load.ts +1 -1
  84. package/src/engine/baselineFile.ts +24 -7
  85. package/src/hooks/forwarding.ts +99 -0
  86. package/src/hooks/install.ts +3 -1
  87. package/src/hooks/shim.ts +3 -1
  88. package/src/hooks/status.ts +10 -6
  89. package/src/hooks/uninstall.ts +3 -1
  90. package/src/imports/packageExports.ts +55 -0
  91. package/src/imports/publicModules.ts +27 -0
  92. package/src/rules/imports/bundleInputs.ts +4 -59
  93. package/src/rules/stories/supportImports.ts +10 -3
@@ -1 +1 @@
1
- {"version":3,"file":"bundleInputs.js","sourceRoot":"","sources":["../../../src/rules/imports/bundleInputs.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,WAAW,CAAC;AAClC,OAAO,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AAEpD,OAAO,EAAE,SAAS,EAAyB,MAAM,uBAAuB,CAAC;AAEzE,SAAS,OAAO,CAAC,OAAgB,EAAE,OAAe;IACjD,IAAI,OAAO,OAAO,KAAK,QAAQ,IAAI,OAAO,KAAK,IAAI,IAAI,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC;QAC/E,OAAO,KAAK,CAAC;IACd,CAAC;IACD,MAAM,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;IACxC,MAAM,KAAK,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE,EAAE,CAAC,GAAG,KAAK,OAAO,CAAC,CAAC;IACvD,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;QACzB,OAAO,KAAK,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC;IAC1B,CAAC;IACD,MAAM,QAAQ,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE,EAAE;QACzC,MAAM,CAAC,MAAM,GAAG,EAAE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Imports.d.ts","sourceRoot":"","sources":["../../../src/rules/stories/supportImports.ts"],"names":[],"mappings":"AAWA,eAAO,MAAM,cAAc;;EA0BzB,CAAC"}
@@ -1,5 +1,6 @@
1
1
  import { Effect, Schema } from "effect";
2
2
  import { importGraph } from "#imports/graph.ts";
3
+ import { publicModules } from "#imports/publicModules.ts";
3
4
  import { isTestSupport } from "#naming/testName.ts";
4
5
  import { defineRule } from "#rule.ts";
5
6
  import { matchesAny } from "./matchesAny.js";
@@ -12,16 +13,21 @@ export const supportImports = defineRule({
12
13
  return [];
13
14
  }
14
15
  const graph = await importGraph(inputs);
16
+ const exported = await publicModules(inputs, graph);
15
17
  return graph.edges
16
- .filter((edge) => isTestSupport(edge.from) && edge.to.kind === "file" && !isTestSupport(edge.to.path) && !matchesAny(edge.to.path, options.modules))
18
+ .filter((edge) => isTestSupport(edge.from)
19
+ && edge.to.kind === "file"
20
+ && !isTestSupport(edge.to.path)
21
+ && !exported.has(edge.to.path)
22
+ && !matchesAny(edge.to.path, options.modules))
17
23
  .map((edge) => ({
18
24
  file: edge.from,
19
25
  line: edge.line,
20
- message: `Test-support imports "${edge.specifier}" outside its allowed public surface. Drive the app through its host, schemas or queue definitions; list those public module paths in tests/support-imports.options.modules in the repository's quality config.`,
26
+ message: `Test-support imports "${edge.specifier}" outside its allowed public surface. Drive the app through its host, schemas or queue definitions, or a workspace package's exports; list additional internal module paths in tests/support-imports.options.modules in the repository's quality config.`,
21
27
  subject: edge.specifier,
22
28
  }));
23
29
  },
24
- description: "Test-support reaches repository modules only through the public surface named by the repository's module allowlist.",
30
+ description: "Test-support reaches repository modules through workspace package exports and the repository's additional module allowlist.",
25
31
  id: "tests/support-imports",
26
32
  options: Schema.toStandardSchemaV1(SupportImportsOptions, { parseOptions: { errors: "all", onExcessProperty: "error" } }),
27
33
  });
@@ -1 +1 @@
1
- {"version":3,"file":"supportImports.js","sourceRoot":"","sources":["../../../src/rules/stories/supportImports.ts"],"names":[],"mappings":"AAAA,OAAO,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AAI,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC;YAC9D,OAAO,EAAE,CAAC;QACX,CAAC;QACD,MAAM,KAAK,GAAG,MAAM,WAAW,CAAC,MAAM,CAAC,CAAC;QACxC,MAAM,QAAQ,GAAG,MAAM,aAAa,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;QACpD,OAAO,KAAK,CAAC,KAAK;aAChB,MAAM,CACN,CAAC,IAAI,EAAE,EAAE,CACR,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC;eACrB,IAAI,CAAC,EAAE,CAAC,IAAI,KAAK,MAAM;eACvB,CAAC,aAAa,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC;eAC5B,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC;eAC3B,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,EAAE,OAAO,CAAC,OAAO,CAAC,CAC9C;aACA,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;YACf,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,OAAO,EAAE,yBAAyB,IAAI,CAAC,SAAS,0PAA0P;YAC1S,OAAO,EAAE,IAAI,CAAC,SAAS;SACvB,CAAC,CAAC,CAAC;IACN,CAAC;IACD,WAAW,EAAE,6HAA6H;IAC1I,EAAE,EAAE,uBAAuB;IAC3B,OAAO,EAAE,MAAM,CAAC,kBAAkB,CAAC,qBAAqB,EAAE,EAAE,YAAY,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,gBAAgB,EAAE,OAAO,EAAE,EAAE,CAAC;CACzH,CAAC,CAAC"}
@@ -9,23 +9,26 @@ The [README](../README.md) introduces the gate. This page explains how the basel
9
9
  {"path":"src/server/db.ts","rule":"structure/max-lines","count":262}
10
10
  ```
11
11
 
12
- The baseline is a JSON Lines file with one entry per line: the violations of one rule in one file. `count` is how many violations the file may have. For a rule that counts occurrences, such as `comments/no-jsdoc`, that is the number of occurrences. For a rule with a limit, it is the amount over the limit: the entry above lets `src/server/db.ts` have 412 lines under a limit of 150. A new baseline is sorted by path and then rule. Later edits preserve unrelated lines, including their formatting and order, so the diff shows the entries that changed.
12
+ The baseline is sharded: `packages/<package>/quality-baseline.jsonl` holds paths inside that package, and the root `quality-baseline.jsonl` holds all other paths. Packages without entries have no file. Each shard is JSON Lines with one entry per line: the violations of one rule in one file. `count` is how many violations the file may have. For a rule that counts occurrences, such as `comments/no-jsdoc`, that is the number of occurrences. For a rule with a limit, it is the amount over the limit: the entry above lets `src/server/db.ts` have 412 lines under a limit of 150. A new baseline is sorted by path and then rule. Later edits preserve unrelated lines, including their formatting and order, so the diff shows the entries that changed.
13
13
 
14
14
  `quality lint` fails when a baselined file has more violations than its `count`; the report then lists all of that file's violations for the rule. A file at or below its entry passes. An entry that allows more than is left, including a file with no violations left, is listed as a note and does not fail, so fixing debt never breaks the build; `tighten` and `prune` lower it. An entry for an unknown rule fails until it is pruned.
15
15
 
16
16
  - `quality baseline write` records every error-level violation when there is no baseline yet. Once a baseline exists it refuses, unless `--rule <id>` names the rules to record: it then replaces the entries of those rules with what the files have now, and leaves every other entry as it is.
17
17
  - `quality baseline tighten` lowers and removes the entries of files changed since `HEAD`, and with `--staged`, of the files staged for the next commit. It carries the entry of a file that git sees as moved to the new path. Every other line stays byte for byte.
18
18
  - `quality baseline prune` does the same for every entry. It carries the entries of files moved since the merge base (see `--against` under [Command line](../README.md#command-line)), and prunes without following moves outside a git work tree.
19
- - `quality baseline migrate` moves a baseline from the earlier JSON format, `quality/baseline.json` or the file `--from` names, to the configured file, and removes the old one. An old entry that stored a size, such as a line count, becomes that size less the rule's current limit; an entry whose file is now within the limit is dropped.
19
+ - `quality baseline migrate` moves a baseline from the earlier JSON format, `quality/baseline.json` or the file `--from` names, to the root and package shards, and removes the old one. `--from quality/baseline.jsonl` splits a single JSON Lines baseline without changing its counts. An old entry that stored a size, such as a line count, becomes that size less the rule's current limit; an entry whose file is now within the limit is dropped.
20
20
 
21
21
  Neither `tighten` nor `prune` ever adds or raises an entry. They lower an entry to what its file has now, and remove it when that is 0. A moved file's entry keeps the lower of its old count and what the file has now. A move is seen when both of its sides are tracked, as after `git mv`; git's rename detection decides what counts as a move.
22
22
 
23
+ Git merges shards through the driver described in the [README](../README.md#baseline-merges). `quality baseline install-driver` configures the current checkout; deletions win and retained counts take the minimum.
24
+
23
25
  ### Pre-commit
24
26
 
25
27
  Lowering entries in the commit that fixes them keeps the baseline current. Run these commands explicitly before committing:
26
28
 
27
29
  ```sh
28
- quality baseline tighten --staged && git add quality/baseline.jsonl
30
+ quality baseline tighten --staged
31
+ git add -- '**/quality-baseline.jsonl' quality-baseline.jsonl
29
32
  quality lint
30
33
  ```
31
34
 
@@ -76,8 +79,8 @@ help: fix what the output above reports, then commit again; `quality hooks pre-c
76
79
 
77
80
  The hook is a short script in the repository's common git directory, `.git/hooks/pre-commit`, which every worktree of the repository shares. It changes to the root of the worktree that commits, then to the config's folder in it, and runs that worktree's quality with that worktree's config, so a branch that changes the checks commits under its own rules. It runs quality the way `hooks install` ran: when that was a file inside the repository, such as a workspace's own source, it runs `node` with the same Node options on that file; otherwise it runs `node_modules/.bin/quality` in the config's folder. When that file does not exist, as in a new worktree whose dependencies are not installed yet, the hook blocks the commit and says to install them. A config file not named `quality.config.ts` is passed with `--config`.
78
81
 
79
- `hooks install` sets repository-local `core.hooksPath` to the common git directory's `hooks` folder and prints that path. It never changes global or system git configuration. At commit time, the hook reads global `core.hooksPath` and runs its executable `pre-commit` hook from the committing worktree's root, before Quality's checks. Relative global paths resolve from that root; a global path pointing to Quality's own hook is not chained. Quality still runs when the global hook fails, and either failure blocks the commit. Installation reports whether there is an executable global hook to chain.
82
+ `hooks install` sets repository-local `core.hooksPath` and prints that path. Without a global hooks path, it uses the common git directory's `hooks` folder. With a global `core.hooksPath`, it uses `hooks/quality`, whose forwarding hooks preserve every Git hook in the global directory, including hooks added later, with its arguments, stdin and exit status. It never changes global or system git configuration. At commit time, Quality's pre-commit shim reads global `core.hooksPath` and runs its executable `pre-commit` hook from the committing worktree's root, before Quality's checks. Relative global paths resolve from that root; a global path pointing to Quality's own hook is not chained. A re-entry marker prevents a global hook that chains `.git/hooks/pre-commit` from running Quality recursively. Quality still runs when the global hook fails, and either failure blocks the commit. Installation reports whether there is an executable global pre-commit hook to chain.
80
83
 
81
- `quality hooks status` reports whether git's effective hooks path runs an executable Quality pre-commit hook, and exits 1 with an installation hint when it does not. It also reports global chaining when Quality is active.
84
+ `quality hooks status` reports whether git's effective hooks path runs an executable Quality pre-commit hook, and exits 1 with an installation hint when it does not. It also reports global chaining when Quality is active. A local hooks path that runs Quality but hides other global hooks fails status with a `quality hooks install` repair hint; reinstalling replaces that layout with forwarding hooks.
82
85
 
83
- A pre-commit hook that quality did not write is kept: `hooks install` warns, says how to call quality from it, and exits 0 without setting the hooks path. `--force` replaces it. `quality hooks uninstall` removes quality's hook and keeps any other. It removes the repository-local hooks path only when that setting still points to Quality's hooks directory, letting global hooks take effect again.
86
+ A pre-commit hook that quality did not write is kept: `hooks install` warns, says how to call quality from it, and exits 0 without setting the hooks path. `--force` replaces it. `quality hooks uninstall` removes quality's hook and keeps any other. It removes Quality's forwarding hooks. It removes the repository-local hooks path only when that setting still points to one of Quality's hooks directories, letting global hooks take effect again.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shivaedev/quality",
3
- "version": "0.31.1",
3
+ "version": "0.32.1",
4
4
  "description": "Repository quality gate with typed rules, a baseline of existing debt and a registry of reasoned exceptions",
5
5
  "homepage": "https://github.com/ShivaeDev/platform/tree/main/packages/quality#readme",
6
6
  "bugs": {
@@ -68,13 +68,13 @@
68
68
  "@types/node": "24.19.2",
69
69
  "@typescript/native": "npm:typescript@7.0.2",
70
70
  "effect": "4.0.4",
71
- "vitest": "5.0.3"
71
+ "vitest": "5.0.4"
72
72
  },
73
73
  "peerDependencies": {
74
74
  "@effect/platform-node": "4.0.4",
75
75
  "@effect/platform-node-shared": "4.0.4",
76
76
  "effect": "4.0.4",
77
- "vitest": "5.0.3"
77
+ "vitest": "5.0.4"
78
78
  },
79
79
  "peerDependenciesMeta": {
80
80
  "vitest": {
@@ -0,0 +1,12 @@
1
+ import { Console, Effect } from "effect";
2
+ import type { SetupFailure } from "#failure.ts";
3
+ import { type Git, gitOrFail } from "#git/command.ts";
4
+ import { hookCommand, type Launch, shellWords } from "#hooks/command.ts";
5
+
6
+ export const installDriver = Effect.fn("Baseline.installDriver")(function* (cwd: string, launch: Launch): Effect.fn.Return<void, SetupFailure, Git> {
7
+ const root = (yield* gitOrFail(cwd, ["rev-parse", "--show-toplevel"])).trim();
8
+ const command = hookCommand(root, launch, undefined);
9
+ const driver = `${shellWords([...command.runner, command.launcher, "baseline", "merge"])} "%O" "%A" "%B"`;
10
+ yield* gitOrFail(root, ["config", "--local", "merge.quality-baseline.driver", driver]);
11
+ yield* Console.log("quality: configured the repository-local quality-baseline merge driver.");
12
+ });
@@ -0,0 +1,34 @@
1
+ import { Effect, FileSystem } from "effect";
2
+ import { type BaselineEntry, decodeBaseline, encodeBaseline } from "#baseline/format.ts";
3
+ import { validOrFail } from "#decoded.ts";
4
+ import { keyOf } from "#engine/violation.ts";
5
+ import { SetupFailure } from "#failure.ts";
6
+
7
+ function mergeEntries(base: readonly BaselineEntry[], ours: readonly BaselineEntry[], theirs: readonly BaselineEntry[]): readonly BaselineEntry[] {
8
+ const original = new Set(base.map((entry) => keyOf(entry.rule, entry.file)));
9
+ const left = new Map(ours.map((entry) => [keyOf(entry.rule, entry.file), entry]));
10
+ const right = new Map(theirs.map((entry) => [keyOf(entry.rule, entry.file), entry]));
11
+ return [...new Set([...left.keys(), ...right.keys()])].flatMap((key) => {
12
+ const a = left.get(key);
13
+ const b = right.get(key);
14
+ if (original.has(key) && (a === undefined || b === undefined)) {
15
+ return [];
16
+ }
17
+ const entry = a ?? b;
18
+ return entry === undefined ? [] : [{ ...entry, count: Math.min(a?.count ?? entry.count, b?.count ?? entry.count) }];
19
+ });
20
+ }
21
+
22
+ export const mergeBaseline = Effect.fn("Baseline.mergeBaseline")(
23
+ function* (base: string, ours: string, theirs: string) {
24
+ const fs = yield* FileSystem.FileSystem;
25
+ const entries = yield* Effect.forEach([base, ours, theirs], (path) =>
26
+ Effect.gen(function* () {
27
+ const raw = yield* fs.readFileString(path);
28
+ return yield* validOrFail(path, yield* Effect.promise(() => decodeBaseline(raw)));
29
+ }),
30
+ );
31
+ yield* fs.writeFileString(ours, encodeBaseline(mergeEntries(entries[0] ?? [], entries[1] ?? [], entries[2] ?? [])));
32
+ },
33
+ Effect.mapError((failure) => new SetupFailure({ message: failure.message })),
34
+ );
@@ -6,7 +6,6 @@ interface Row {
6
6
  readonly text: string;
7
7
  }
8
8
 
9
- // An untouched entry keeps its exact line and a new one goes before the first line that sorts after it, so two branches conflict only on the same or neighbouring entries.
10
9
  export function rewriteBaseline(raw: string | undefined, before: readonly BaselineEntry[], after: readonly BaselineEntry[]): string {
11
10
  const wanted = new Map(after.map((entry) => [keyOf(entry.rule, entry.file), entry]));
12
11
  const lines = linesOf(raw);
@@ -0,0 +1,60 @@
1
+ import { join } from "node:path";
2
+ import { Effect, FileSystem } from "effect";
3
+ import type { BaselineEntry } from "#baseline/format.ts";
4
+ import { rewriteBaseline } from "#baseline/rewrite.ts";
5
+ import type { ResolvedConfig } from "#config/load.ts";
6
+ import { SetupFailure } from "#failure.ts";
7
+ import { orWhenAbsent, writeText } from "#inventory/filesystem.ts";
8
+
9
+ export const SHARD_NAME = "quality-baseline.jsonl";
10
+
11
+ export interface Shard {
12
+ readonly entries: readonly BaselineEntry[];
13
+ readonly raw: string;
14
+ }
15
+
16
+ export function shardOf(file: string, rootFile: string): string {
17
+ const [folder, name, ...rest] = file.split("/");
18
+ return folder === "packages" && name !== undefined && rest.length > 0 ? `packages/${name}/${SHARD_NAME}` : rootFile;
19
+ }
20
+
21
+ export const shardPaths = Effect.fn("Baseline.shardPaths")(function* (config: ResolvedConfig) {
22
+ const fs = yield* FileSystem.FileSystem;
23
+ const folder = join(config.root, "packages");
24
+ const names = yield* orWhenAbsent(folder, fs.readDirectory(folder), []);
25
+ const paths = [config.baseline];
26
+ for (const name of names) {
27
+ if ((yield* fs.stat(join(folder, name))).type === "Directory") {
28
+ paths.push(`packages/${name}/${SHARD_NAME}`);
29
+ }
30
+ }
31
+ return paths;
32
+ });
33
+
34
+ export const saveShards = Effect.fn("Baseline.saveShards")(
35
+ function* (config: ResolvedConfig, before: ReadonlyMap<string, Shard>, entries: readonly BaselineEntry[]) {
36
+ const fs = yield* FileSystem.FileSystem;
37
+ const grouped = new Map<string, BaselineEntry[]>();
38
+ for (const entry of entries) {
39
+ const path = shardOf(entry.file, config.baseline);
40
+ const group = grouped.get(path) ?? [];
41
+ group.push(entry);
42
+ grouped.set(path, group);
43
+ }
44
+ for (const path of new Set([...before.keys(), ...grouped.keys()])) {
45
+ const old = before.get(path);
46
+ const next = grouped.get(path) ?? [];
47
+ if (next.length === 0) {
48
+ if (old !== undefined) {
49
+ yield* fs.remove(join(config.root, path));
50
+ }
51
+ } else {
52
+ const text = rewriteBaseline(old?.raw, old?.entries ?? [], next);
53
+ if (text !== old?.raw) {
54
+ yield* writeText(join(config.root, path), text);
55
+ }
56
+ }
57
+ }
58
+ },
59
+ Effect.mapError((failure) => new SetupFailure({ message: failure.message })),
60
+ );
package/src/cli/args.ts CHANGED
@@ -6,6 +6,8 @@ export type Command =
6
6
  | { readonly _tag: "Lint"; readonly config: string | undefined }
7
7
  | { readonly _tag: "ExceptionsMigrate"; readonly config: string | undefined; readonly from: string | undefined }
8
8
  | { readonly _tag: "Fix"; readonly config: string | undefined }
9
+ | { readonly _tag: "BaselineMerge"; readonly base: string; readonly ours: string; readonly theirs: string }
10
+ | { readonly _tag: "BaselineInstallDriver" }
9
11
  | { readonly _tag: "BaselineWrite"; readonly config: string | undefined; readonly rules: readonly string[] }
10
12
  | { readonly _tag: "BaselinePrune"; readonly config: string | undefined; readonly against: string | undefined }
11
13
  | { readonly _tag: "BaselineTighten"; readonly config: string | undefined; readonly staged: boolean }
@@ -45,6 +47,7 @@ type Option = Exclude<keyof Values, "config" | "help">;
45
47
  const COMMAND_OPTIONS: readonly Option[] = ["against", "force", "from", "rule", "staged"];
46
48
 
47
49
  const ACCEPTS: Readonly<Record<string, readonly Option[]>> = {
50
+ "baseline install-driver": [],
48
51
  "baseline migrate": ["from"],
49
52
  "baseline prune": ["against"],
50
53
  "baseline tighten": ["staged"],
@@ -77,6 +80,8 @@ function commandFor(name: string, values: Values): Parsed {
77
80
  return parsed({ _tag: "ExceptionsMigrate", config, from: values.from });
78
81
  case "fix":
79
82
  return parsed({ _tag: "Fix", config });
83
+ case "baseline install-driver":
84
+ return parsed({ _tag: "BaselineInstallDriver" });
80
85
  case "baseline write":
81
86
  return parsed({ _tag: "BaselineWrite", config, rules: values.rule ?? [] });
82
87
  case "baseline prune":
@@ -109,6 +114,12 @@ export function parseCommand(args: readonly string[]): Parsed {
109
114
  if (values.help === true || command === "help") {
110
115
  return parsed({ _tag: "Help" });
111
116
  }
117
+ if (command === "baseline" && rest[0] === "merge") {
118
+ const [, base, ours, theirs] = rest;
119
+ return rest.length === 4 && base !== undefined && ours !== undefined && theirs !== undefined
120
+ ? parsed({ _tag: "BaselineMerge", base, ours, theirs })
121
+ : usage("baseline merge takes <ancestor> <current> <other>.");
122
+ }
112
123
  const name = [command, ...rest].join(" ");
113
124
  if (ACCEPTS[name] === undefined) {
114
125
  const subcommands = SUBCOMMANDS[command];
@@ -1,19 +1,14 @@
1
- import { join } from "node:path";
2
1
  import { Console, Effect, type FileSystem } from "effect";
3
2
  import type { BaselineEntry } from "#baseline/format.ts";
4
- import { rewriteBaseline } from "#baseline/rewrite.ts";
3
+ import { saveShards } from "#baseline/shards.ts";
5
4
  import { adopt, type Pruned, prune, type Scope } from "#baseline/update.ts";
6
5
  import { openSession, type Session } from "#engine/session.ts";
7
6
  import { applyRegistry } from "#exceptions/registry.ts";
8
7
  import { SetupFailure } from "#failure.ts";
9
- import { writeText } from "#inventory/filesystem.ts";
10
8
  import { plural } from "#report/plural.ts";
11
9
 
12
10
  function save(session: Session, entries: readonly BaselineEntry[]): Effect.Effect<void, SetupFailure, FileSystem.FileSystem> {
13
- return Effect.mapError(
14
- writeText(join(session.config.root, session.config.baseline), rewriteBaseline(session.baseline.raw, session.baseline.entries, entries)),
15
- (failure) => new SetupFailure({ message: failure.message }),
16
- );
11
+ return saveShards(session.config, session.baseline.files, entries);
17
12
  }
18
13
 
19
14
  function unregistered(session: Session) {
@@ -26,7 +21,7 @@ export const writeBaseline = Effect.fn("Cli.writeBaseline")(function* (
26
21
  rules: readonly string[],
27
22
  ): Effect.fn.Return<void, SetupFailure, FileSystem.FileSystem> {
28
23
  const session = yield* openSession(cwd, config);
29
- const existing = session.baseline.raw === undefined ? undefined : session.baseline.entries;
24
+ const existing = session.baseline.files.size === 0 ? undefined : session.baseline.entries;
30
25
  const adoption = adopt(existing, rules, unregistered(session), session.config);
31
26
  if (adoption._tag === "Refused") {
32
27
  return yield* new SetupFailure({ message: `baseline write refused:\n${adoption.reasons.map((reason) => ` - ${reason}`).join("\n")}` });
@@ -54,11 +49,12 @@ export const shrinkBaseline = Effect.fn("Cli.shrinkBaseline")(function* <TRequir
54
49
  scopeOf: (session: Session) => Effect.Effect<Scope, SetupFailure, TRequirements>,
55
50
  ): Effect.fn.Return<void, SetupFailure, FileSystem.FileSystem | TRequirements> {
56
51
  const session = yield* openSession(cwd, config);
57
- if (session.baseline.raw === undefined) {
52
+ if (session.baseline.files.size === 0) {
58
53
  return yield* Console.log(`quality: no baseline at ${session.config.baseline}; nothing to lower.`);
59
54
  }
60
55
  const pruned = prune(session.baseline.entries, unregistered(session), session.config, yield* scopeOf(session));
61
- if (pruned.removed === 0 && pruned.lowered === 0 && pruned.moved === 0) {
56
+ const emptyShard = [...session.baseline.files.values()].some((file) => file.entries.length === 0);
57
+ if (pruned.removed === 0 && pruned.lowered === 0 && pruned.moved === 0 && !emptyShard) {
62
58
  return yield* Console.log(`quality: ${session.config.baseline} is current.`);
63
59
  }
64
60
  yield* save(session, pruned.entries);
@@ -2,6 +2,8 @@ export const USAGE = `Usage:
2
2
  quality lint [--config <file>]
3
3
  quality fix [--config <file>]
4
4
  quality exceptions migrate [--config <file>] [--from <registry>]
5
+ quality baseline merge <ancestor> <current> <other>
6
+ quality baseline install-driver
5
7
  quality baseline write [--config <file>] [--rule <id>]...
6
8
  quality baseline prune [--config <file>] [--against <ref>]
7
9
  quality baseline tighten [--config <file>] [--staged]
@@ -15,10 +17,12 @@ lint Run every rule. Exits 1 on an error-level violation, a file ov
15
17
  or a baseline entry for an unknown rule.
16
18
  fix Sort every package.json, apply Biome's lint fixes, unsafe ones included, its assist actions and formatting, then format again.
17
19
  exceptions migrate Move legacy registry entries and Biome declarations into quality.config.ts exceptions and remove matching root overrides.
20
+ baseline merge Merge Git baseline versions into <current>: deletions win and counts take the minimum.
21
+ baseline install-driver Configure only the repository-local merge.quality-baseline.driver setting.
18
22
  baseline write Record current error-level violations. Creates the baseline, or records the named rules again, replacing their entries.
19
23
  baseline prune Drop fixed debt, lower entries to what is left and carry entries to files git saw move. Never adds or raises an entry.
20
24
  baseline tighten Prune only the entries of files changed since HEAD, or with --staged, in the index.
21
- baseline migrate Move a baseline from the earlier JSON format (--from, quality/baseline.json by default) to the configured file.
25
+ baseline migrate Move a JSON or JSON Lines baseline (--from, quality/baseline.json by default) into root and package shards.
22
26
  hooks install Install the git pre-commit hook, shared by every worktree, that runs hooks pre-commit. Keeps a hook that is not quality's
23
27
  unless --force replaces it.
24
28
  hooks uninstall Remove quality's pre-commit hook. Keeps a hook that is not quality's.
@@ -30,7 +34,7 @@ hooks pre-commit What the hook runs: lint, then package.json scripts typecheck
30
34
  Exit codes: 0 passed, 1 failed the gate, 2 could not run.`;
31
35
 
32
36
  export const SUBCOMMANDS: Readonly<Record<string, string>> = {
33
- baseline: "baseline takes write, prune, tighten or migrate.",
37
+ baseline: "baseline takes write, prune, tighten, migrate, merge or install-driver.",
34
38
  exceptions: "exceptions takes migrate.",
35
39
  hooks: "hooks takes install, uninstall, status or pre-commit.",
36
40
  };
@@ -1,13 +1,13 @@
1
1
  import { join } from "node:path";
2
2
  import { Console, Effect, FileSystem } from "effect";
3
- import { encodeBaseline } from "#baseline/format.ts";
3
+ import { decodeBaseline } from "#baseline/format.ts";
4
4
  import { convertLegacy, decodeLegacyBaseline, LEGACY_BASELINE } from "#baseline/legacy.ts";
5
+ import { saveShards, shardPaths } from "#baseline/shards.ts";
5
6
  import { loadConfig } from "#config/load.ts";
6
7
  import { validOrFail } from "#decoded.ts";
7
8
  import { readInput } from "#engine/baselineFile.ts";
8
9
  import { scan } from "#engine/session.ts";
9
10
  import { SetupFailure } from "#failure.ts";
10
- import { writeText } from "#inventory/filesystem.ts";
11
11
  import { plural } from "#report/plural.ts";
12
12
 
13
13
  export const migrateBaseline = Effect.fn("Cli.migrateBaseline")(function* (
@@ -17,17 +17,21 @@ export const migrateBaseline = Effect.fn("Cli.migrateBaseline")(function* (
17
17
  ): Effect.fn.Return<void, SetupFailure, FileSystem.FileSystem> {
18
18
  const config = yield* loadConfig(cwd, configPath);
19
19
  const source = from ?? LEGACY_BASELINE;
20
- if (source === config.baseline || (yield* readInput(config.root, config.baseline)) !== undefined) {
20
+ const paths = yield* shardPaths(config).pipe(Effect.mapError((error) => new SetupFailure({ message: error.message })));
21
+ const existing = yield* Effect.forEach(paths, (path) => readInput(config.root, path));
22
+ if (source === config.baseline || existing.some((text) => text !== undefined)) {
21
23
  return yield* new SetupFailure({ message: `${config.baseline} already exists. Migrate into a baseline file that does not exist yet.` });
22
24
  }
23
25
  const raw = yield* readInput(config.root, source);
24
26
  if (raw === undefined) {
25
27
  return yield* new SetupFailure({ message: `no baseline at ${source} to migrate. Name it with --from <file>.` });
26
28
  }
27
- const legacy = yield* validOrFail(source, yield* Effect.promise(() => decodeLegacyBaseline(raw)));
28
- const entries = convertLegacy(legacy, (yield* scan(config)).violations);
29
+ const legacy = source.endsWith(".jsonl")
30
+ ? yield* validOrFail(source, yield* Effect.promise(() => decodeBaseline(raw)))
31
+ : yield* validOrFail(source, yield* Effect.promise(() => decodeLegacyBaseline(raw)));
32
+ const entries = source.endsWith(".jsonl") ? legacy : convertLegacy(legacy, (yield* scan(config)).violations);
29
33
  const fs = yield* FileSystem.FileSystem;
30
- const written = Effect.andThen(writeText(join(config.root, config.baseline), encodeBaseline(entries)), fs.remove(join(config.root, source)));
34
+ const written = Effect.andThen(saveShards(config, new Map(), entries), fs.remove(join(config.root, source)));
31
35
  yield* Effect.mapError(written, (failure) => new SetupFailure({ message: failure.message }));
32
36
  const fixed = legacy.length - entries.length;
33
37
  const dropped = fixed > 0 ? `, dropping ${plural(fixed, "fixed entry", "fixed entries")}` : "";
@@ -1,4 +1,6 @@
1
1
  import { Console, Effect } from "effect";
2
+ import { installDriver } from "#baseline/installDriver.ts";
3
+ import { mergeBaseline } from "#baseline/merge.ts";
2
4
  import { parseCommand, USAGE } from "#cli/args.ts";
3
5
  import { writeBaseline } from "#cli/baseline.ts";
4
6
  import { fix } from "#cli/fix.ts";
@@ -31,6 +33,10 @@ export const program = Effect.fn("Cli.program")(function* (args: readonly string
31
33
  return yield* lint(cwd, command.config);
32
34
  case "Fix":
33
35
  return yield* fix(cwd, command.config);
36
+ case "BaselineMerge":
37
+ return yield* mergeBaseline(command.base, command.ours, command.theirs);
38
+ case "BaselineInstallDriver":
39
+ return yield* installDriver(cwd, launch);
34
40
  case "BaselineWrite":
35
41
  return yield* writeBaseline(cwd, command.config, command.rules);
36
42
  case "BaselinePrune":
@@ -49,7 +49,7 @@ function biomeDeclarations(config: ConfigInput): readonly Declaration[] {
49
49
  function resolved(root: string, file: string, config: ConfigInput, rules: ResolvedRules): ResolvedConfig {
50
50
  return {
51
51
  ...rules,
52
- baseline: config.baseline ?? "quality/baseline.jsonl",
52
+ baseline: config.baseline ?? "quality-baseline.jsonl",
53
53
  biomeDeclarations: biomeDeclarations(config),
54
54
  exceptions: config.exceptions ?? [],
55
55
  exclude: [],
@@ -2,6 +2,7 @@ import { join } from "node:path";
2
2
  import { Effect, type FileSystem } from "effect";
3
3
  import { type BaselineEntry, decodeBaseline } from "#baseline/format.ts";
4
4
  import { LEGACY_BASELINE } from "#baseline/legacy.ts";
5
+ import { type Shard, shardOf, shardPaths } from "#baseline/shards.ts";
5
6
  import type { ResolvedConfig } from "#config/load.ts";
6
7
  import { validOrFail } from "#decoded.ts";
7
8
  import { SetupFailure } from "#failure.ts";
@@ -9,7 +10,7 @@ import { readOptionalText } from "#inventory/filesystem.ts";
9
10
 
10
11
  export interface BaselineFile {
11
12
  readonly entries: readonly BaselineEntry[];
12
- readonly raw: string | undefined;
13
+ readonly files: ReadonlyMap<string, Shard>;
13
14
  }
14
15
 
15
16
  export function readInput(root: string, path: string): Effect.Effect<string | undefined, SetupFailure, FileSystem.FileSystem> {
@@ -19,11 +20,27 @@ export function readInput(root: string, path: string): Effect.Effect<string | un
19
20
  export const readBaseline = Effect.fn("Engine.readBaseline")(function* (
20
21
  config: ResolvedConfig,
21
22
  ): Effect.fn.Return<BaselineFile, SetupFailure, FileSystem.FileSystem> {
22
- const raw = yield* readInput(config.root, config.baseline);
23
- if (raw === undefined && config.baseline !== LEGACY_BASELINE && (yield* readInput(config.root, LEGACY_BASELINE)) !== undefined) {
24
- return yield* new SetupFailure({
25
- message: `${LEGACY_BASELINE} holds a baseline in the earlier JSON format. Run \`quality baseline migrate\` to move it to ${config.baseline}.`,
26
- });
23
+ const files = new Map<string, Shard>();
24
+ for (const path of yield* shardPaths(config).pipe(Effect.mapError((error) => new SetupFailure({ message: error.message })))) {
25
+ const raw = yield* readInput(config.root, path);
26
+ if (raw === undefined) {
27
+ continue;
28
+ }
29
+ const entries = yield* validOrFail(path, yield* Effect.promise(() => decodeBaseline(raw)));
30
+ for (const entry of entries) {
31
+ const expected = shardOf(entry.file, config.baseline);
32
+ if (expected !== path) {
33
+ return yield* new SetupFailure({ message: `${entry.file} belongs in ${expected}, not ${path}.` });
34
+ }
35
+ }
36
+ files.set(path, { entries, raw });
27
37
  }
28
- return { entries: yield* validOrFail(config.baseline, yield* Effect.promise(() => decodeBaseline(raw))), raw };
38
+ for (const source of ["quality/baseline.jsonl", LEGACY_BASELINE]) {
39
+ if (source !== config.baseline && (yield* readInput(config.root, source)) !== undefined) {
40
+ return yield* new SetupFailure({
41
+ message: `${source} holds an earlier baseline. Run \`quality baseline migrate --from ${source}\` to move it to ${config.baseline} and package shards.`,
42
+ });
43
+ }
44
+ }
45
+ return { entries: [...files.values()].flatMap((file) => file.entries), files };
29
46
  });
@@ -0,0 +1,99 @@
1
+ import { dirname, join } from "node:path";
2
+ import { Effect, FileSystem } from "effect";
3
+ import { SetupFailure } from "#failure.ts";
4
+ import { git } from "#git/command.ts";
5
+ import { readOptionalText } from "#inventory/filesystem.ts";
6
+ import { shellWords } from "./command.ts";
7
+ import { isHookShim, OWNER } from "./shim.ts";
8
+
9
+ const HOOKS = [
10
+ "applypatch-msg",
11
+ "pre-applypatch",
12
+ "post-applypatch",
13
+ "pre-commit",
14
+ "pre-merge-commit",
15
+ "prepare-commit-msg",
16
+ "commit-msg",
17
+ "post-commit",
18
+ "pre-rebase",
19
+ "post-checkout",
20
+ "post-merge",
21
+ "pre-push",
22
+ "pre-receive",
23
+ "update",
24
+ "proc-receive",
25
+ "post-receive",
26
+ "post-update",
27
+ "reference-transaction",
28
+ "push-to-checkout",
29
+ "pre-auto-gc",
30
+ "post-rewrite",
31
+ "sendemail-validate",
32
+ "fsmonitor-watchman",
33
+ "p4-changelist",
34
+ "p4-prepare-changelist",
35
+ "p4-post-changelist",
36
+ "p4-pre-submit",
37
+ "post-index-change",
38
+ ];
39
+
40
+ export function forwardingPath(file: string): string {
41
+ return join(dirname(file), "quality");
42
+ }
43
+
44
+ export const globalHooksPath = Effect.fn("Hooks.globalHooksPath")(function* (cwd: string) {
45
+ const global = yield* git(cwd, ["config", "--global", "--includes", "--type=path", "--get", "core.hooksPath"]);
46
+ if (global.code !== 0 && global.code !== 1) {
47
+ return yield* new SetupFailure({ message: `cannot read global core.hooksPath: ${global.stderr.trim()}` });
48
+ }
49
+ return global.stdout.trim();
50
+ });
51
+
52
+ function forwarder(file: string, name: string): string {
53
+ return [
54
+ "#!/bin/sh",
55
+ OWNER,
56
+ ...(name === "pre-commit"
57
+ ? [`exec ${shellWords([file])} "$@"`]
58
+ : [
59
+ 'global_path="$(git config --global --includes --type=path --get core.hooksPath)"',
60
+ '[ -n "$global_path" ] || exit 0',
61
+ `global_hook="$global_path/${name}"`,
62
+ 'if [ -x "$global_hook" ] && ! [ "$global_hook" -ef "$0" ]; then',
63
+ '\texec "$global_hook" "$@"',
64
+ "fi",
65
+ ]),
66
+ "",
67
+ ].join("\n");
68
+ }
69
+
70
+ export const installForwarding = Effect.fn("Hooks.installForwarding")(function* (file: string) {
71
+ const fs = yield* FileSystem.FileSystem;
72
+ const path = forwardingPath(file);
73
+ yield* fs.makeDirectory(path, { recursive: true });
74
+ for (const name of HOOKS) {
75
+ const target = join(path, name);
76
+ const existing = yield* readOptionalText(target);
77
+ if (existing !== undefined && !isHookShim(existing)) {
78
+ return yield* new SetupFailure({ message: `cannot replace ${target}: it is not Quality's hook.` });
79
+ }
80
+ yield* fs.writeFileString(target, forwarder(file, name));
81
+ yield* fs.chmod(target, 0o755);
82
+ }
83
+ return path;
84
+ });
85
+
86
+ export const removeForwarding = Effect.fn("Hooks.removeForwarding")(function* (file: string) {
87
+ const fs = yield* FileSystem.FileSystem;
88
+ const path = forwardingPath(file);
89
+ for (const name of HOOKS) {
90
+ const target = join(path, name);
91
+ const existing = yield* readOptionalText(target);
92
+ if (existing !== undefined && isHookShim(existing)) {
93
+ yield* fs.remove(target);
94
+ }
95
+ }
96
+ if ((yield* fs.exists(path)) && (yield* fs.readDirectory(path)).length === 0) {
97
+ yield* fs.remove(path, { recursive: true });
98
+ }
99
+ });
@@ -6,6 +6,7 @@ import { SetupFailure } from "#failure.ts";
6
6
  import { gitOrFail } from "#git/command.ts";
7
7
  import { readOptionalText } from "#inventory/filesystem.ts";
8
8
  import { commandWords, hookCommand, type Launch, shellWords } from "./command.ts";
9
+ import { globalHooksPath, installForwarding } from "./forwarding.ts";
9
10
  import { hookLocation } from "./location.ts";
10
11
  import { hookShim, isHookShim } from "./shim.ts";
11
12
  import { globalHookStatus } from "./status.ts";
@@ -61,7 +62,8 @@ export const installHook = Effect.fn("Hooks.installHook")(function* (install: Ho
61
62
  const done = foreign ? `replaced ${location.file}, which was not quality's hook` : `installed the pre-commit hook at ${location.file}`;
62
63
  yield* Console.log(`quality: ${done}; each commit runs \`${words}\`.`);
63
64
  }
64
- const hooks = dirname(location.file);
65
+ const hooks =
66
+ (yield* globalHooksPath(config.root)) === "" ? dirname(location.file) : yield* installForwarding(location.file).pipe(Effect.mapError(failed));
65
67
  yield* gitOrFail(config.root, ["config", "--local", "core.hooksPath", hooks]);
66
68
  yield* Console.log(`quality: set repository-local core.hooksPath to ${hooks}.`);
67
69
  yield* globalHookStatus(location);