@ref0/workspace 0.0.0-stage → 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 (82) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +169 -2
  3. package/dist/bin.d.mts +1 -0
  4. package/dist/bin.mjs +113 -0
  5. package/dist/docs-budget.mjs +122 -0
  6. package/dist/lint/anti-slop/LICENSE +21 -0
  7. package/dist/lint/anti-slop/UPSTREAM.md +11 -0
  8. package/dist/lint/anti-slop/effect/plugin.d.mts +3 -0
  9. package/dist/lint/anti-slop/effect/plugin.mjs +19 -0
  10. package/dist/lint/anti-slop/effect/rules/no-manual-effect-error-tag.mjs +33 -0
  11. package/dist/lint/anti-slop/effect/rules/no-manual-tag-comparison.mjs +32 -0
  12. package/dist/lint/anti-slop/effect/rules/no-manual-tagged-construction.mjs +22 -0
  13. package/dist/lint/anti-slop/effect/rules/no-service-constructor-imports.mjs +36 -0
  14. package/dist/lint/anti-slop/effect/rules/prefer-effect-match.mjs +40 -0
  15. package/dist/lint/anti-slop/effect/shared/tagged-values.mjs +40 -0
  16. package/dist/lint/anti-slop/plugin.d.mts +3 -0
  17. package/dist/lint/anti-slop/plugin.mjs +45 -0
  18. package/dist/lint/anti-slop/rules/no-array-filter-map.mjs +31 -0
  19. package/dist/lint/anti-slop/rules/no-chained-type-assertions.mjs +56 -0
  20. package/dist/lint/anti-slop/rules/no-conditional-empty-object-spread.mjs +32 -0
  21. package/dist/lint/anti-slop/rules/no-known-value-widening.mjs +236 -0
  22. package/dist/lint/anti-slop/rules/no-module-mocking.mjs +48 -0
  23. package/dist/lint/anti-slop/rules/no-object-parameters.mjs +48 -0
  24. package/dist/lint/anti-slop/rules/no-reduce-accumulator-copy.mjs +85 -0
  25. package/dist/lint/anti-slop/rules/no-reflect-apply.mjs +21 -0
  26. package/dist/lint/anti-slop/rules/no-reflect-get.mjs +21 -0
  27. package/dist/lint/anti-slop/rules/no-runtime-typeof.mjs +52 -0
  28. package/dist/lint/anti-slop/rules/no-shape-in-symbol-names.mjs +36 -0
  29. package/dist/lint/anti-slop/rules/no-unknown-parameters.mjs +44 -0
  30. package/dist/lint/anti-slop/rules/no-unknown-returns.mjs +47 -0
  31. package/dist/lint/anti-slop/rules/no-unknown-type-aliases.mjs +33 -0
  32. package/dist/lint/anti-slop/rules/no-unsafe-dictionary-type.mjs +121 -0
  33. package/dist/lint/anti-slop/rules/no-widen-then-assert.mjs +191 -0
  34. package/dist/lint/anti-slop/rules/require-readable-spacing.mjs +86 -0
  35. package/dist/lint/anti-slop/rules/require-safety-comment-for-type-assertion.mjs +82 -0
  36. package/dist/lint/anti-slop/shared/array-method.mjs +70 -0
  37. package/dist/lint/anti-slop/shared/child-nodes.mjs +24 -0
  38. package/dist/lint/anti-slop/shared/dictionary-types.mjs +248 -0
  39. package/dist/lint/anti-slop/shared/function-parameters.mjs +25 -0
  40. package/dist/lint/anti-slop/shared/lexical-type-parameters.mjs +21 -0
  41. package/dist/lint/anti-slop/shared/reflect-method.mjs +16 -0
  42. package/dist/lint/anti-slop/shared/scope.mjs +12 -0
  43. package/dist/lint/anti-slop/shared/string-literal.mjs +6 -0
  44. package/dist/lint/anti-slop/shared/type-alias-resolution.mjs +134 -0
  45. package/dist/lint/anti-slop/vendor/eslint-stylistic/LICENSE +22 -0
  46. package/dist/lint/anti-slop/vendor/eslint-stylistic/UPSTREAM.md +29 -0
  47. package/dist/lint/anti-slop/vendor/eslint-stylistic/padding-line-ast.mjs +32 -0
  48. package/dist/lint/anti-slop/vendor/eslint-stylistic/padding-line-between-statements.mjs +608 -0
  49. package/dist/lint/config.d.mts +20 -0
  50. package/dist/lint/config.mjs +135 -0
  51. package/dist/lint/generic/effect-encoding.mjs +45 -0
  52. package/dist/lint/generic/entry-reexports.mjs +81 -0
  53. package/dist/lint/generic/env-at-entrypoints.mjs +65 -0
  54. package/dist/lint/generic/export-type-side-effects.mjs +22 -0
  55. package/dist/lint/generic/index-barrel.mjs +14 -0
  56. package/dist/lint/generic/log-messages.mjs +39 -0
  57. package/dist/lint/generic/plugin.d.mts +6 -0
  58. package/dist/lint/generic/plugin.mjs +26 -0
  59. package/dist/lint/generic/seeded-properties.mjs +78 -0
  60. package/dist/lint/plugins.d.mts +9 -0
  61. package/dist/lint/plugins.mjs +14 -0
  62. package/dist/lint/t3code/LICENSE +21 -0
  63. package/dist/lint/t3code/UPSTREAM.md +24 -0
  64. package/dist/lint/t3code/plugin.d.mts +2 -0
  65. package/dist/lint/t3code/plugin.mjs +20 -0
  66. package/dist/lint/t3code/rules/no-global-process-runtime.mjs +76 -0
  67. package/dist/lint/t3code/rules/no-inline-schema-compile.mjs +112 -0
  68. package/dist/lint/t3code/rules/no-manual-effect-runtime-in-tests.mjs +67 -0
  69. package/dist/lint/t3code/rules/no-native-title-tooltip.mjs +33 -0
  70. package/dist/lint/t3code/rules/no-test-in-loop.mjs +69 -0
  71. package/dist/lint/t3code/rules/no-unscoped-has.mjs +147 -0
  72. package/dist/lint/t3code/utils.mjs +21 -0
  73. package/dist/package-exports.mjs +157 -0
  74. package/dist/symbols/check.mjs +209 -0
  75. package/dist/symbols/find.mjs +63 -0
  76. package/dist/symbols/symbols.mjs +390 -0
  77. package/dist/type-coverage.mjs +68 -0
  78. package/dist/types/cache.mjs +157 -0
  79. package/dist/types/inputs.mjs +71 -0
  80. package/dist/types/projects.mjs +65 -0
  81. package/dist/types/types.mjs +175 -0
  82. package/package.json +68 -3
package/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md CHANGED
@@ -1,3 +1,170 @@
1
- # Temporary Holding Version
1
+ # @ref0/workspace
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ The lint and workspace checks every ref-0 repo shares: Oxlint's shared settings and plugins, for
4
+ Vite+, and the `ref0-workspace` command. A repo takes it at one exact version through its catalog,
5
+ and a new version reaches the repo in the pull request that moves the catalog and fixes what it
6
+ finds.
7
+
8
+ ## Lint
9
+
10
+ A repo's `lint/config.ts` merges its own settings over the shared ones, and registers the shared
11
+ plugins beside its own:
12
+
13
+ ```ts
14
+ import { base, merge } from '@ref0/workspace/lint/config';
15
+ import { antiSlop, antiSlopEffect, t3code, generic } from '@ref0/workspace/lint/plugins';
16
+
17
+ export const fmt = merge(base.fmt, { ignorePatterns: ['vendor/**'] });
18
+
19
+ export const lint = merge(base.lint, {
20
+ jsPlugins: [antiSlop, antiSlopEffect, t3code, generic, './lint/workspace.ts'],
21
+ overrides: [/* the repo's own */],
22
+ });
23
+ ```
24
+
25
+ - `base.fmt` and `base.lint`: the shared format and lint settings. `REF0_LINT_TYPES=none` turns off
26
+ the type-aware rules, for a local check that runs them only on changed files.
27
+ - `merge(base, local)`: base first, local last. Ignores, plugins and overrides are joined, rules
28
+ and options merged, so a local rule wins; any other setting is local's.
29
+ - `@ref0/workspace/lint/plugins`: each plugin's file, as an absolute path for `jsPlugins`.
30
+
31
+ | Plugin | Rules | From |
32
+ | ---------------- | -------------------- | ---------------------------------------------------------------- |
33
+ | `antiSlop` | `anti-slop/*` | [dmmulroy/anti-slop](https://github.com/dmmulroy/anti-slop), MIT |
34
+ | `antiSlopEffect` | `anti-slop-effect/*` | the same |
35
+ | `t3code` | `t3code/*` | [pingdotgg/t3code](https://github.com/pingdotgg/t3code), MIT |
36
+ | `generic` | `ref0-generic/*` | ref-0 |
37
+
38
+ Each copied plugin keeps its licence and its `UPSTREAM.md`, which records its source commit and
39
+ changes, beside its code, in the package too.
40
+
41
+ `ref0-generic`'s rules: `seeded-properties`, `index-barrel-only` and `export-type-side-effects`,
42
+ which `base.lint` turns on, and `effect-encoding`, `log-messages`, `env-at-entrypoints` and
43
+ `entry-reexports`, which a repo turns on for its own files. `entry-reexports` takes the repo's root,
44
+ the folders of the packages whose entry files it checks, and the export condition that names an
45
+ entry point's source:
46
+
47
+ ```ts
48
+ 'ref0-generic/entry-reexports': [
49
+ 'error',
50
+ { root: '/abs/repo', entries: ['packages/ui'], condition: '@ref0/source' },
51
+ ],
52
+ ```
53
+
54
+ ## Checks
55
+
56
+ `ref0-workspace <check>`, from anywhere in the repo's checkout:
57
+
58
+ - `docs-budget`: the docs agents load, each within its budget: every skill's description, the
59
+ repo's own `SKILL.md`s, `AGENTS.md`s, the root's `RULES.md`, and `GLOSSARY.md`. It reads the
60
+ Markdown Git tracks. Skills the root's `skills-lock.json` names are upstream copies; without the
61
+ lock there are none.
62
+ - `symbols find <words...>` and `symbols check <base> [<head>]` or `symbols check --all`: what the
63
+ repo already has, and a change that copies it, as [Symbols](#symbols) says.
64
+ - `types`: the types of every project the root `tsconfig.json` reaches, and Effect's rules, with
65
+ the repo's own `effect-tsgo tsrs`, each error once, in the project that includes its file. Each
66
+ project's result is kept for every checkout on the machine, in `REF0_WORKSPACE_TYPES_CACHE` or
67
+ `ref0-workspace-types` in the user's cache folder, and replayed while nothing it read changes.
68
+ - `type-coverage`: every tracked TypeScript file is in a project the root reaches, and lint reads
69
+ it, unless a tool writes it (`*.gen.ts`).
70
+ - `package-exports [--packages <glob>]... [--condition <name>]`: each package's `exports` names
71
+ files it tracks or its `vite.config.ts`'s `pack` builds, and each entry point that builds gives
72
+ its source under the condition first. `--packages` is `packages/*` and `--condition`
73
+ `@ref0/source` unless given.
74
+
75
+ `types` and `type-coverage` run the repo's own `@effect/tsgo`, `tsrs` and `typescript`, its
76
+ optional peers, resolved from its root, at the versions its catalog pins.
77
+
78
+ ## Symbols
79
+
80
+ `symbols` keeps a repo from collecting copies of its own code. `find` shows what the repo already
81
+ has before you write it. `check` fails a change that copies a function, class or const the repo
82
+ already has.
83
+
84
+ Both read every top-level declaration in the repo's source files with oxc, through `parseAst` from
85
+ Vite+, and keep each file's declarations in `node_modules/.cache/ref0-workspace-symbols/`, one cache
86
+ per checkout and never committed, so a file is parsed again only when it changes. Declarations,
87
+ generated `*.gen.ts` files, `dist/`, `node_modules/`, `.agents/` and `.claude/` are left out.
88
+
89
+ ### Find a function before you write one
90
+
91
+ ```sh
92
+ ref0-workspace symbols find join bytes
93
+ ```
94
+
95
+ It prints the ten best matches in the working tree, each with its file and line, its signature and
96
+ the first line of its doc comment:
97
+
98
+ ```text
99
+ joined function src/bytes.ts:78
100
+ (chunks: ReadonlyArray<Uint8Array>, size: number) =>
101
+ Whatever the reader gave, as one run of bytes.
102
+ ```
103
+
104
+ A word in the name counts most, then a word in the doc comment, then one in the signature or path.
105
+ A match for every word ranks higher, and test files are included but rank lower, as `best` in
106
+ [`find.ts`](src/symbols/find.ts) scores them.
107
+
108
+ ### Check a change for copies
109
+
110
+ ```sh
111
+ ref0-workspace symbols check origin/main
112
+ ```
113
+
114
+ It compares the branch, with any changes not yet committed, against the base, and prints each copy,
115
+ then a count:
116
+
117
+ ```text
118
+ copy: src/browsers.ts:90 browsedBy has the same body as openedBy at src/sessions.ts:479
119
+ near copy: src/loader.ts:44 storedVersion is storedCheckCode at src/code.ts:218 with other names in it
120
+ ```
121
+
122
+ An exact copy fails the check. A near copy only warns. In CI, run it on a pull request's merge into
123
+ main, `ref0-workspace symbols check HEAD^1 HEAD`: under GitHub Actions each copy is an annotation on
124
+ its line in the diff.
125
+
126
+ To keep a copy on purpose, say why in a comment directly above it:
127
+
128
+ ```ts
129
+ // CLONE: the sender's bundle takes no code from bytes.ts.
130
+ const concat = (chunks: ReadonlyArray<Uint8Array>) => {
131
+ ```
132
+
133
+ `ref0-workspace symbols check --all` lists every copy already in the repo, but those a `// CLONE:`
134
+ comment allows, and always passes.
135
+
136
+ ### What counts as a copy
137
+
138
+ [`check.ts`](src/symbols/check.ts) owns the comparison scope, thresholds and exclusions.
139
+ [`symbols.ts`](src/symbols/symbols.ts) defines the exact and loose fingerprints.
140
+
141
+ ### Limits
142
+
143
+ - It compares whole top-level declarations. It doesn't find a block copied inside a function, or a
144
+ function nested in another.
145
+ - A body that has the same fingerprint as another, but calls functions that do different things,
146
+ is still an exact copy. Mark it with a `// CLONE:` comment.
147
+ - A body that's mostly one pattern repeated, such as a long list of names, is never a near copy.
148
+ Two such lists of the same length would look alike whatever names they hold.
149
+ - If a change edits two copies that already existed and they still match, the check reports them.
150
+
151
+ ### Tune it
152
+
153
+ The thresholds are the constants at the top of `check.ts`: `minSize`, `nearAlike` and `commonRun`.
154
+ Before you change one, replay a consumer's last 30 merged pull requests from its checkout and read
155
+ every copy the check reports:
156
+
157
+ ```sh
158
+ for merge in $(git log --first-parent --merges -30 --format=%h origin/main); do
159
+ pnpm exec ref0-workspace symbols check "$merge^1" "$merge"
160
+ done
161
+ ```
162
+
163
+ ## Releasing
164
+
165
+ From [ref-0/home](https://github.com/ref-0/home): bump `version` in this package's `package.json`
166
+ on main, a patch for a fix and a minor for a new rule or check, and once CI passes that commit, push the
167
+ tag `workspace-v<version>` at it. `release.yml` checks that CI passed exactly that commit and
168
+ publishes it.
169
+
170
+ Apache-2.0, but for the copied plugins, which keep their MIT licences.
package/dist/bin.d.mts ADDED
@@ -0,0 +1 @@
1
+ export {}
package/dist/bin.mjs ADDED
@@ -0,0 +1,113 @@
1
+ #!/usr/bin/env node
2
+ import { docsBudget } from "./docs-budget.mjs";
3
+ import { defaultCondition, packageExports } from "./package-exports.mjs";
4
+ import { symbolsCheck } from "./symbols/check.mjs";
5
+ import { symbolsFind } from "./symbols/find.mjs";
6
+ import { typeCoverage } from "./type-coverage.mjs";
7
+ import { types } from "./types/types.mjs";
8
+ import { execFileSync } from "node:child_process";
9
+ import { argv, cwd, exit } from "node:process";
10
+ import { parseArgs } from "node:util";
11
+ // src/bin.ts
12
+ /**
13
+ * `ref0-workspace <check>`: the checks every ref-0 repo runs, each a subcommand, run from anywhere
14
+ * in the repo's checkout.
15
+ *
16
+ * ref0-workspace docs-budget the docs agents load, each within its budget
17
+ * ref0-workspace symbols find <words...> what the repo has, before you write it again
18
+ * ref0-workspace symbols check <base> [<head>] no change copies what the repo has
19
+ * ref0-workspace symbols check --all every copy the repo holds
20
+ * ref0-workspace types types and Effect's rules, every project
21
+ * ref0-workspace type-coverage every TypeScript file in a project, and linted
22
+ * ref0-workspace package-exports [--packages <glob>]... [--condition <name>]
23
+ * each package's exports name files it has
24
+ */
25
+ /** The root of the Git checkout the command runs in, or where it runs outside one. */
26
+ const root = () => {
27
+ try {
28
+ return execFileSync("git", ["rev-parse", "--show-toplevel"], {
29
+ cwd: cwd(),
30
+ encoding: "utf8",
31
+ stdio: [
32
+ "ignore",
33
+ "pipe",
34
+ "ignore"
35
+ ]
36
+ }).trim();
37
+ } catch {
38
+ return cwd();
39
+ }
40
+ };
41
+ /** Prints the usage, and answers the exit code for a command it doesn't take. */
42
+ const usageError = () => {
43
+ console.error(usage());
44
+ return 2;
45
+ };
46
+ /** A check that takes no arguments, run at the checkout's root. */
47
+ const plain = (about, run) => ({
48
+ args: "",
49
+ about,
50
+ run: (args) => {
51
+ if (args.length > 0) return usageError();
52
+ return run(root());
53
+ }
54
+ });
55
+ const checks = /* @__PURE__ */ new Map([
56
+ ["docs-budget", plain("the docs agents load, each within its budget", (at) => {
57
+ const { docs, problems } = docsBudget(at);
58
+ for (const line of problems) console.error(line);
59
+ if (problems.length > 0) return 1;
60
+ console.error(`docs-budget: ${docs.length} Markdown files within budget`);
61
+ return 0;
62
+ })],
63
+ ["symbols", {
64
+ args: "find <words...> | check <base> [<head>] | check --all",
65
+ about: "what the repo has, before you write it again, and no change copying it",
66
+ run: ([command, ...rest]) => {
67
+ if (command === "find") return symbolsFind(rest, cwd());
68
+ if (command === "check") return symbolsCheck(rest, cwd());
69
+ return usageError();
70
+ }
71
+ }],
72
+ ["types", plain("types and Effect's rules, in every project the root reaches", types)],
73
+ ["type-coverage", plain("every TypeScript file in a project the root reaches, and linted", typeCoverage)],
74
+ ["package-exports", {
75
+ args: "[--packages <glob>]... [--condition <name>]",
76
+ about: "each package's exports name files it has or builds",
77
+ run: (args) => {
78
+ const parsed = (() => {
79
+ try {
80
+ return parseArgs({
81
+ args: [...args],
82
+ options: {
83
+ packages: {
84
+ type: "string",
85
+ multiple: true,
86
+ default: ["packages/*"]
87
+ },
88
+ condition: {
89
+ type: "string",
90
+ default: defaultCondition
91
+ }
92
+ }
93
+ }).values;
94
+ } catch {
95
+ return;
96
+ }
97
+ })();
98
+ if (parsed === void 0) return usageError();
99
+ return packageExports(root(), parsed);
100
+ }
101
+ }]
102
+ ]);
103
+ function usage() {
104
+ return ["usage: ref0-workspace <check>", ...[...checks].map(([name, { args, about }]) => [` ${name}${args === "" ? "" : ` ${args}`}`, ` ${about}`].join("\n"))].join("\n");
105
+ }
106
+ const [name, ...rest] = argv.slice(2);
107
+ const check = name === void 0 ? void 0 : checks.get(name);
108
+ if (check === void 0) {
109
+ console.error(name === void 0 ? usage() : `ref0-workspace: no check ${name}\n${usage()}`);
110
+ exit(2);
111
+ }
112
+ exit(await check.run(rest));
113
+ export {};
@@ -0,0 +1,122 @@
1
+ import { execFileSync } from "node:child_process";
2
+ import { existsSync, readFileSync } from "node:fs";
3
+ import { join } from "node:path";
4
+ // src/docs-budget.ts
5
+ /**
6
+ * Fails when a doc agents load outgrows its budget, so the bloat compacted in ref0's #2265 can't
7
+ * grow back.
8
+ *
9
+ * ref0-workspace docs-budget
10
+ *
11
+ * It reads the Markdown the current repo tracks, from the root of the checkout it runs in. Root
12
+ * `AGENTS.md` and every skill's description load into every agent session, and an app's
13
+ * `AGENTS.md` or a `SKILL.md` whenever an agent works there, so each byte costs on each run. The
14
+ * skill list has a budget of its own, and a skill past it loses its description. `GLOSSARY.md` is
15
+ * read and searched often. The budgets, from what each held after #2265, with headroom:
16
+ *
17
+ * - Every skill's description, upstream copies too: at most 320 characters. An upkeep run that
18
+ * updates a copy can bring its source's longer description back, and fails here until it's cut.
19
+ * - The repo's own `SKILL.md`: at most 10 KB. Upstream copies, those the root's `skills-lock.json`
20
+ * names and Cloudflare's `cf-*`, are left as their source wrote them. A repo without the lock
21
+ * has no upstream copies.
22
+ * - Root `AGENTS.md`: at most 12 KB. Any other `AGENTS.md`: at most 8 KB. Root `RULES.md`, the rules
23
+ * every repo's `AGENTS.md` imports, so they load beside each one: at most 8 KB.
24
+ * - `GLOSSARY.md`: no tables, since `vp fmt` pads each cell to its column's widest, and no entry
25
+ * over 400 characters.
26
+ * - None of these keeps history, such as "Changed 15 Oct 2026": `git log` holds it.
27
+ */
28
+ const budgets = {
29
+ description: 320,
30
+ skill: 1e4,
31
+ rootAgents: 12e3,
32
+ agents: 8e3,
33
+ rules: 8e3,
34
+ glossaryEntry: 400
35
+ };
36
+ const history = /\b(?:Changed|Decided|Renamed|Hidden|Dropped|Added) \d{1,2} (?:Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)[a-z]* \d{4}\b/;
37
+ /**
38
+ * A `SKILL.md`'s frontmatter description, as one line: plain, quoted, or a folded `>-` block.
39
+ * `undefined` when it has none.
40
+ */
41
+ const description = (text) => {
42
+ const lines = (/^---\n([\s\S]*?)\n---/.exec(text)?.[1])?.split("\n") ?? [];
43
+ const start = lines.findIndex((line) => line.startsWith("description:"));
44
+ if (start === -1) return void 0;
45
+ const first = lines[start].slice(12).trim();
46
+ const rest = lines.slice(start + 1);
47
+ const end = rest.findIndex((line) => !line.startsWith(" "));
48
+ const folded = (end === -1 ? rest : rest.slice(0, end)).map((line) => line.trim());
49
+ return (/^[>|]-?$/.test(first) ? folded.join(" ") : first).replace(/^(["'])([\s\S]*)\1$/, "$2");
50
+ };
51
+ const bytes = (text) => Buffer.byteLength(text, "utf8");
52
+ const kb = (size) => `${(size / 1e3).toFixed(1)} KB`;
53
+ /** What the docs break, one line each, with what to do about it. */
54
+ const problems = (docs, upstream) => {
55
+ const found = [];
56
+ for (const { path, text } of docs) {
57
+ const skill = /^\.agents\/skills\/([^/]+)\/SKILL\.md$/.exec(path)?.[1];
58
+ const agents = path === "AGENTS.md" || path.endsWith("/AGENTS.md");
59
+ const rules = path === "RULES.md";
60
+ const glossary = path === "GLOSSARY.md";
61
+ if (skill === void 0 && !agents && !rules && !glossary) continue;
62
+ const ours = skill === void 0 || !(upstream.has(skill) || skill.startsWith("cf-"));
63
+ const said = history.exec(text)?.[0];
64
+ if (ours && said !== void 0) found.push(`${path}: "${said}" is history; leave it to git log and say what holds now.`);
65
+ if (skill !== void 0) {
66
+ const about = description(text) ?? "";
67
+ if (about.length > budgets.description) found.push(`${path}: its description is ${about.length} characters, over ${budgets.description}. Say what it does, when to use it and which sibling to use instead; cut the method.`);
68
+ if (ours && bytes(text) > budgets.skill) found.push(`${path}: ${kb(bytes(text))}, over ${kb(budgets.skill)}. Move what one step or case needs to references/, and point to code instead of restating it.`);
69
+ }
70
+ if (agents || rules) {
71
+ const limit = rules ? budgets.rules : path === "AGENTS.md" ? budgets.rootAgents : budgets.agents;
72
+ if (bytes(text) > limit) found.push(`${path}: ${kb(bytes(text))}, over ${kb(limit)}. Keep each rule in one place, link the skill or script that owns the detail, and point to code for values.`);
73
+ }
74
+ if (glossary) {
75
+ const lines = text.split("\n");
76
+ if (lines.some((line) => line.startsWith("|"))) found.push(`${path}: has a table. Write each term as \`**Term**: meaning\`, since vp fmt pads table cells.`);
77
+ for (const entry of lines.filter((line) => line.startsWith("**"))) {
78
+ if (entry.length <= budgets.glossaryEntry) continue;
79
+ const term = /^\*\*(.+?)\*\*/.exec(entry)?.[1] ?? entry.slice(0, 40);
80
+ found.push(`${path}: ${term} is ${entry.length} characters, over ${budgets.glossaryEntry}. Keep its meaning, the word to use and where it lives in code; the code says how it behaves.`);
81
+ }
82
+ }
83
+ }
84
+ return found;
85
+ };
86
+ /**
87
+ * The skills the skills CLI installed, by folder name, from the lock at `root`: none when there's
88
+ * no lock.
89
+ */
90
+ const upstreamSkills = (root) => {
91
+ const path = join(root, "skills-lock.json");
92
+ if (!existsSync(path)) return /* @__PURE__ */ new Set();
93
+ const lock = JSON.parse(readFileSync(path, "utf8"));
94
+ return new Set(Object.keys(lock.skills));
95
+ };
96
+ /** The Markdown the checkout at `root` tracks, each by its path from the root, with its text. */
97
+ const trackedDocs = (root) => execFileSync("git", [
98
+ "ls-files",
99
+ "-z",
100
+ "--",
101
+ "*.md"
102
+ ], {
103
+ cwd: root,
104
+ encoding: "utf8"
105
+ }).split("\0").filter((path) => path !== "").map((path) => ({
106
+ path,
107
+ text: readFileSync(join(root, path), "utf8")
108
+ }));
109
+ /** The checkout `from` is in: its root, its tracked docs, and what they break. */
110
+ const docsBudget = (from) => {
111
+ const root = execFileSync("git", ["rev-parse", "--show-toplevel"], {
112
+ cwd: from,
113
+ encoding: "utf8"
114
+ }).trim();
115
+ const docs = trackedDocs(root);
116
+ return {
117
+ root,
118
+ docs,
119
+ problems: problems(docs, upstreamSkills(root))
120
+ };
121
+ };
122
+ export { budgets, description, docsBudget, problems, trackedDocs, upstreamSkills };
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Dillon Mulroy
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,11 @@
1
+ # Anti-slop provenance
2
+
3
+ - Source: <https://github.com/dmmulroy/anti-slop>
4
+ - Source commit: `c44ef22ca116d0ba62a3ff663a0bd13a3f3fa40b`
5
+ - Source snapshot: `skills/install-anti-slop/assets/anti-slop/` at that commit
6
+ - Source licence: MIT, `LICENSE` beside this file, copied from the source commit
7
+ - Installed generic plugin: `src/lint/anti-slop/plugin.ts`, which `@ref0/workspace/lint/plugins` exports as `antiSlop`
8
+ - Installed Effect plugin: `src/lint/anti-slop/effect/plugin.ts`, exported as `antiSlopEffect`
9
+ - Oxlint plugin API: imported from `vite-plus/lint/plugins` instead of `@oxlint/plugins`, so it always matches the Oxlint version bundled by Vite+. `vp migrate` rewrote the imports for Vite+ 1.0.
10
+ - Performance deviations, each reporting the same: `no-widen-then-assert` reads a file's scopes only at its first assertion of a binding; `no-known-value-widening` keeps a file's calls and assignments and resolves them at its end only when it declares a type predicate or a binding with a widening type; `no-module-mocking` resolves a call's object only once its method is a mock's; and `shared/child-nodes.ts` tests each value without a Schema guard. Each kept lint from analysing scopes, or walking with a Schema, on every file, which made the anti-slop rules most of a lint run.
11
+ - Intentional source deviation: `require-readable-spacing` does not split related declarations merely because one wraps, and it requires an unbraced guard to remain attached to its declaration. This keeps formatting aligned with ref-0's semantic-paragraph policy in `RULES.md`.
@@ -0,0 +1,3 @@
1
+ /** Opt-in Oxlint rules for Effect service and Layer architecture. */
2
+ declare const antiSlopEffectPlugin: import("vite-plus/lint/plugins").Plugin;
3
+ export { antiSlopEffectPlugin as default };