@crown3/repo-doctor 0.0.0 → 0.2.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 (86) hide show
  1. package/LICENSE +7 -0
  2. package/README.md +40 -1
  3. package/UPSTREAM.md +20 -0
  4. package/bin/repo-doctor.mjs +9 -0
  5. package/dist/check-comments.d.ts +3 -0
  6. package/dist/check-docs.d.ts +16 -0
  7. package/dist/check-runs.d.ts +23 -0
  8. package/dist/cli.d.ts +16 -0
  9. package/dist/cli.js +1743 -0
  10. package/dist/comments.d.ts +17 -0
  11. package/dist/config.d.ts +152 -0
  12. package/dist/file-kinds.d.ts +8 -0
  13. package/dist/files.d.ts +8 -0
  14. package/dist/format-sh.d.ts +6 -0
  15. package/dist/g.js +360 -0
  16. package/dist/git.d.ts +17 -0
  17. package/dist/go-comments.d.ts +7 -0
  18. package/dist/index.d.ts +4 -0
  19. package/dist/index.js +16 -0
  20. package/dist/python.d.ts +18 -0
  21. package/dist/quality.d.ts +39 -0
  22. package/dist/review-comments.d.ts +14 -0
  23. package/dist/rules.d.ts +8 -0
  24. package/dist/run-if-main.d.ts +2 -0
  25. package/dist/scrub-git-hook-env.d.ts +1 -0
  26. package/dist/scrub-git-hook-env.js +2 -0
  27. package/dist/settings.d.ts +19 -0
  28. package/dist/shard.d.ts +10 -0
  29. package/dist/sites.d.ts +9 -0
  30. package/dist/units.d.ts +30 -0
  31. package/package.json +61 -3
  32. package/python/crapper/LICENSE +7 -0
  33. package/python/crapper/README.md +93 -0
  34. package/python/crapper/pyproject.toml +28 -0
  35. package/python/crapper/src/crapper/__init__.py +3 -0
  36. package/python/crapper/src/crapper/__main__.py +4 -0
  37. package/python/crapper/src/crapper/analyze.py +56 -0
  38. package/python/crapper/src/crapper/cli.py +334 -0
  39. package/python/crapper/src/crapper/coverage.py +596 -0
  40. package/python/crapper/src/crapper/crap.py +47 -0
  41. package/python/crapper/src/crapper/discover.py +116 -0
  42. package/python/crapper/src/crapper/languages/__init__.py +27 -0
  43. package/python/crapper/src/crapper/languages/clojure.py +451 -0
  44. package/python/crapper/src/crapper/languages/golang.py +143 -0
  45. package/python/crapper/src/crapper/languages/java.py +117 -0
  46. package/python/crapper/src/crapper/languages/python.py +133 -0
  47. package/python/crapper/src/crapper/languages/rust.py +190 -0
  48. package/python/crapper/src/crapper/languages/treesitter.py +82 -0
  49. package/python/crapper/src/crapper/languages/typescript.py +399 -0
  50. package/python/crapper/src/crapper/metrics.py +59 -0
  51. package/python/crapper/src/crapper/model.py +32 -0
  52. package/python/crapper/src/crapper/report.py +42 -0
  53. package/python/crapper/src/crapper/runners.py +596 -0
  54. package/python/dryer/LICENSE +7 -0
  55. package/python/dryer/README.md +115 -0
  56. package/python/dryer/pyproject.toml +29 -0
  57. package/python/dryer/src/dryer/__init__.py +3 -0
  58. package/python/dryer/src/dryer/__main__.py +4 -0
  59. package/python/dryer/src/dryer/astnorm.py +391 -0
  60. package/python/dryer/src/dryer/cli.py +324 -0
  61. package/python/dryer/src/dryer/clojure_read.py +519 -0
  62. package/python/dryer/src/dryer/discover.py +121 -0
  63. package/python/dryer/src/dryer/extract.py +204 -0
  64. package/python/dryer/src/dryer/model.py +34 -0
  65. package/python/dryer/src/dryer/report.py +74 -0
  66. package/python/dryer/src/dryer/scan.py +91 -0
  67. package/python/dryer/src/dryer/shape.py +108 -0
  68. package/python/dryer/src/dryer/treesitter.py +47 -0
  69. package/python/mutator/LICENSE +7 -0
  70. package/python/mutator/README.md +123 -0
  71. package/python/mutator/pyproject.toml +28 -0
  72. package/python/mutator/src/mutator/__init__.py +3 -0
  73. package/python/mutator/src/mutator/__main__.py +4 -0
  74. package/python/mutator/src/mutator/cli.py +591 -0
  75. package/python/mutator/src/mutator/coverage.py +233 -0
  76. package/python/mutator/src/mutator/crapper_link.py +36 -0
  77. package/python/mutator/src/mutator/edn.py +239 -0
  78. package/python/mutator/src/mutator/engine.py +356 -0
  79. package/python/mutator/src/mutator/functions.py +214 -0
  80. package/python/mutator/src/mutator/metrics.py +344 -0
  81. package/python/mutator/src/mutator/model.py +83 -0
  82. package/python/mutator/src/mutator/report.py +74 -0
  83. package/python/mutator/src/mutator/runner.py +248 -0
  84. package/python/mutator/src/mutator/sites.py +376 -0
  85. package/python/mutator/src/mutator/workers.py +446 -0
  86. package/python/requirements.lock +12 -0
package/LICENSE ADDED
@@ -0,0 +1,7 @@
1
+ BSD Zero Clause License
2
+
3
+ Copyright (C) 2026 by Crown
4
+
5
+ Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted.
6
+
7
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,42 @@
1
1
  # @crown3/repo-doctor
2
2
 
3
- Placeholder. Source: https://github.com/crown3/cc-origins/tree/main/packages/repo-doctor
3
+ Repo checks and the [ub-mode](https://github.com/unclebob/ub-mode) quality gates for a whole repo, as one CLI driven by one config file: the comment policy, shell formatting, the agent docs, where git hooks and CI run each `package.json` script, every function under CRAP 10 ([crapper](https://github.com/unclebob/crapper)), no duplicated code ([dryer](https://github.com/unclebob/dryer)), and tests that kill the mutants ([mutator](https://github.com/unclebob/mutator)).
4
+
5
+ It replaces `@crown3/repo-rules` and `@crown3/ub-mode-tools`.
6
+
7
+ ## Install
8
+
9
+ ```sh
10
+ pnpm add -D @crown3/repo-doctor
11
+ ```
12
+
13
+ Needs Node.js >= 24 and git; the quality commands also need [uv](https://docs.astral.sh/uv/) or `python3` >= 3.11.
14
+
15
+ ## Use
16
+
17
+ ```sh
18
+ repo-doctor --help # every command and option
19
+ repo-doctor config # the resolved repo-doctor.config.mjs, as JSON
20
+ ```
21
+
22
+ The commands, the units and file rules, and every key of `repo-doctor.config.mjs` are documented in [docs/subsystems/repo-doctor.md](https://github.com/crown3/cc-origins/blob/main/docs/subsystems/repo-doctor.md).
23
+
24
+ ```js
25
+ import { defineConfig } from '@crown3/repo-doctor';
26
+
27
+ export default defineConfig({
28
+ pipelines: {
29
+ table: 'docs/ci.md', // optional: keep its "## Where checks run" table in sync
30
+ ci: { platform: 'github', files: ['.github/workflows/check.yml'] },
31
+ },
32
+ quality: { mutate: { minScore: 80 } },
33
+ });
34
+ ```
35
+
36
+ ## Source
37
+
38
+ The three Python tools are vendored from unclebob's repositories (0BSD); [UPSTREAM.md](UPSTREAM.md) lists the snapshot commits and local changes. The package is developed in [crown3/cc-origins](https://github.com/crown3/cc-origins/tree/main/packages/repo-doctor) and published from its `main` branch.
39
+
40
+ ## License
41
+
42
+ 0BSD.
package/UPSTREAM.md ADDED
@@ -0,0 +1,20 @@
1
+ # Vendored quality tools
2
+
3
+ `crapper`, `dryer` and `mutator` under `python/` are source snapshots of unclebob's tools (0BSD), maintained in this repo and shipped in the npm package.
4
+ They stay side by side because `mutator` reads function names from `../crapper`; the CLI also puts all three on `PYTHONPATH`.
5
+
6
+ | Tool | Upstream | Snapshot commit |
7
+ | --- | --- | --- |
8
+ | crapper | https://github.com/unclebob/crapper | c757ec79a6c15dc815238bbd9c2f4601eb54d3cc |
9
+ | dryer | https://github.com/unclebob/dryer | 66ff6d21a42c04afcad89c78a80066176d1294b0 |
10
+ | mutator | https://github.com/unclebob/mutator | 830ec7e9c39664d753f8699015bc796df67727b9 |
11
+
12
+ Before adding a local change, call the unchanged tool directly once and show it cannot do the job (a list of paths in an unsplit shell variable reaches it as one missing path and looks like a missing feature). Then ask the user, offering a rule change or deleting code first.
13
+
14
+ Local changes on top of the snapshots:
15
+
16
+ - dryer compares `.js`, `.jsx`, `.mjs` and `.cjs` with the JavaScript grammar and skips their `.test.`/`.spec.` files, as crapper and mutator already do.
17
+ - dryer and crapper exit 1 when paths given on the command line select no source file, instead of printing `No source files to analyze.` and exiting 0.
18
+
19
+ To pick up upstream changes, diff the upstream repo at a newer commit against the snapshot commit, apply what you want here, keep the local changes above, and update the table.
20
+ The CLI runs them in one environment holding the dependencies pinned in `python/requirements.lock`; a dependency an upstream change adds goes there. `pnpm test:tools` runs their pytest suites, and `pnpm test:e2e` runs them over a sample project per language.
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env node
2
+ import { existsSync } from 'node:fs';
3
+
4
+ const source = new URL('../src/cli.ts', import.meta.url);
5
+ const entry = existsSync(source)
6
+ ? source
7
+ : new URL('../dist/cli.js', import.meta.url);
8
+ const { main } = await import(entry.href);
9
+ process.exitCode = await main(process.argv.slice(2));
@@ -0,0 +1,3 @@
1
+ import type { Comments } from './config.js';
2
+ /** One error per comment the policy does not allow in files, as `file:line: message`. */
3
+ export declare function checkComments(root: string, files: string[], { exclude, publicApi }: Comments): string[];
@@ -0,0 +1,16 @@
1
+ import type { Docs } from './config.js';
2
+ import type { Settings } from './settings.js';
3
+ /** The targets of the Markdown links outside code. */
4
+ export declare function links(markdown: string): string[];
5
+ /** GitHub's anchor for a heading. */
6
+ export declare function slug(heading: string): string;
7
+ /** Every anchor a link can name in markdown: heading slugs, with `-1` on for a repeat, and `<a id>` or `<a name>`. */
8
+ export declare function anchors(markdown: string): Set<string>;
9
+ export interface DocsResult {
10
+ errors: string[];
11
+ count: number;
12
+ }
13
+ /** Checks the repo's Markdown: links and anchors, reachability from AGENTS.md, stray agent files, English, shared runs of words; and check-runs when configured. */
14
+ export declare function checkDocs(root: string, settings: Settings & {
15
+ docs: Docs;
16
+ }): DocsResult;
@@ -0,0 +1,23 @@
1
+ import type { Pipelines as Runs } from './config.js';
2
+ /** A command a hook or CI step runs, under the keys that lead to it. */
3
+ export interface Run {
4
+ path: string[];
5
+ command: string;
6
+ }
7
+ /** Every `run:` command in a GitHub Actions workflow, with the keys above it. */
8
+ export declare function runs(yaml: string): Run[];
9
+ /** Every step command of a Codebase pipeline, under its job. */
10
+ export declare function commands(yaml: string): Run[];
11
+ /** Every step command in an hk.pkl, under its hook and step. */
12
+ export declare function hookRuns(pkl: string): Run[];
13
+ type Kind = 'hooks' | 'jobs';
14
+ type Where = Record<Kind, string[]>;
15
+ /** The rows of the "Where checks run" table: per script, the hooks and CI jobs it lists. */
16
+ export declare function table(markdown: string): Map<string, Where>;
17
+ /** The pipeline files the patterns name, sorted within each pattern. */
18
+ export declare function pipelineFiles(root: string, patterns: string[]): string[];
19
+ /** How the error messages name the pipeline files: the one pattern, or `dir/{a,b}.ext`. */
20
+ export declare function describeFiles(patterns: string[]): string;
21
+ /** Hooks and CI steps call only package.json scripts, and the "Where checks run" table, when set, lists each where it runs. */
22
+ export declare function checkRuns(root: string, config: Runs): string[];
23
+ export {};
package/dist/cli.d.ts ADDED
@@ -0,0 +1,16 @@
1
+ import { type Shard } from './shard.js';
2
+ export declare const USAGE = "usage: repo-doctor <command> [--config <file>] [options] [args...]\n\ncommands:\n check-comments [files...] comments the policy allows; no files: every file git does not ignore\n format-sh [--check] [files...] shfmt on shell files; --check only lists them\n check-docs [root] links, reachability, agent files, English, shared phrases, and check-runs\n check-runs [root] hooks and CI call package.json scripts (and the docs table lists them, with pipelines.table)\n review-comments [ref] external(...) comments added since the merge base with ref\n setup build the Python environment and fetch the parsers\n crap crapper on each unit: every function under the CRAP threshold\n dry dryer over every unit at once: no duplicates at the similarity threshold\n mutate mutator on each unit: every mutant killed, or the unit's minimum score\n ratio each unit's code and test lines, a report only\n config print the resolved config as JSON\n\noptions:\n --config <file> config module, from the working directory (default: repo-doctor.config.mjs in the root)\n --changed only files changed in the working tree, or since --base\n --base <ref> with --changed, files changed since the merge base with <ref>, committed or not\n --min-score <n> mutate passes when each unit scores at least n%, whatever the config says\n --shard <i/n> mutate only shard i of n\n\n[root] is any directory in the repo; every command works on its git top level.\nOther arguments of crap, dry, mutate and ratio go to the tool; any other unknown argument is a usage error.\n\nexit codes: 0 pass, 1 a finding or a failed gate, 2 an internal error, 64 a usage or config error";
3
+ export interface Options {
4
+ changed: boolean;
5
+ base?: string;
6
+ minScore?: number;
7
+ shard?: Shard;
8
+ extra: string[];
9
+ }
10
+ export declare function parseArgs(argv: string[]): Options;
11
+ export interface Process {
12
+ cwd?: string;
13
+ env?: NodeJS.ProcessEnv;
14
+ }
15
+ /** Runs one command with argv after the program name; resolves to its exit code. */
16
+ export declare function main(argv: string[], { cwd, env }?: Process): Promise<number>;