@hailstails/hone 0.1.0-pre.4 → 0.1.0-pre.5

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 (45) hide show
  1. package/ADOPTING.md +37 -12
  2. package/MIGRATING.md +4 -4
  3. package/README.md +35 -16
  4. package/api/audit.d.ts +3 -2
  5. package/api/rule-set.d.ts +2 -4
  6. package/chunks/chunk-3HFJHJDO.js +53 -0
  7. package/chunks/chunk-7OVV6NEU.js +22 -0
  8. package/chunks/chunk-7PVPPH4C.js +13 -0
  9. package/chunks/chunk-HVABJ7T4.js +361 -0
  10. package/chunks/{chunk-BX6QHLSZ.js → chunk-IIMK5BCL.js} +57 -4
  11. package/chunks/{chunk-FOAGAYXM.js → chunk-SWPCKTJV.js} +44 -397
  12. package/chunks/{chunk-RZA3OVOO.js → chunk-VUG3DJHN.js} +5 -3
  13. package/chunks/{chunk-EYCRDEXX.js → chunk-YBWVUDIG.js} +2 -13
  14. package/core/check/tool-command.js +356 -81
  15. package/core/mechanism-port/piece-failure-types.d.ts +14 -0
  16. package/core/mechanism-port/runner-module-types.d.ts +5 -0
  17. package/core/rule-set-reader/authored-rule-set-types.d.ts +48 -0
  18. package/core/values/json-value.d.ts +3 -0
  19. package/docs/adding-a-discipline-or-mechanism.md +6 -3
  20. package/docs/extending.md +357 -0
  21. package/mechanisms/audit/CD-1/any-cast.js +9 -37
  22. package/mechanisms/audit/CD-19/import-boundaries.js +79 -68
  23. package/mechanisms/audit/CD-19/piece.json +5 -0
  24. package/mechanisms/audit/CD-2/cast-expressions.js +14 -37
  25. package/mechanisms/audit/CD-5/comments-directives.js +137 -55
  26. package/mechanisms/audit/CD-5/piece.json +7 -0
  27. package/mechanisms/audit/runner/README.md +1 -0
  28. package/mechanisms/audit/runner/runner.js +10 -6
  29. package/mechanisms/audit/runner/typescript-parse.d.ts +6 -0
  30. package/mechanisms/audit/runner/walker-piece.d.ts +5 -5
  31. package/mechanisms/eslint/runner/README.md +1 -1
  32. package/mechanisms/eslint/runner/runner.js +85 -35
  33. package/package.json +4 -4
  34. package/rules/CD-1/README.md +5 -5
  35. package/rules/CD-1/discipline.json +16 -6
  36. package/rules/CD-19/README.md +13 -3
  37. package/rules/CD-19/discipline.json +6 -8
  38. package/rules/CD-2/README.md +8 -4
  39. package/rules/CD-2/discipline.json +25 -7
  40. package/rules/CD-5/README.md +17 -5
  41. package/rules/CD-5/discipline.json +66 -0
  42. package/core/mechanism-port/runner-failure-types.d.ts +0 -38
  43. package/core/rule-set-reader/rule-set-types.d.ts +0 -41
  44. /package/api/{audit.js → audit.mjs} +0 -0
  45. /package/api/{rule-set.js → rule-set.mjs} +0 -0
@@ -0,0 +1,361 @@
1
+ import {
2
+ brandedTextSchema,
3
+ external_exports
4
+ } from "./chunk-SWPCKTJV.js";
5
+
6
+ // core/platform-ports/file-system-port.ts
7
+ import { accessSync, readFileSync, readdirSync, writeFileSync } from "node:fs";
8
+ var NO_SUCH_FILE_CODE = "ENOENT";
9
+ var presenceAfterAccessFailure = (request) => request.thrown instanceof Error && "code" in request.thrown && request.thrown.code === NO_SUCH_FILE_CODE ? "absent" : "present";
10
+ var failureDetail = (request) => request.thrown instanceof Error ? request.thrown.message : String(request.thrown);
11
+ var createFileTextPort = (options) => ({
12
+ read: (request) => {
13
+ try {
14
+ return { outcome: "ok", value: options.fileSystem.readText({ path: request.path }) };
15
+ } catch (thrown) {
16
+ return {
17
+ outcome: "failed",
18
+ error: {
19
+ kind: "unreadable",
20
+ path: request.path,
21
+ detail: failureDetail({ thrown })
22
+ }
23
+ };
24
+ }
25
+ },
26
+ exists: (request) => {
27
+ try {
28
+ options.fileSystem.access({ path: request.path });
29
+ return "present";
30
+ } catch (thrown) {
31
+ return presenceAfterAccessFailure({ thrown });
32
+ }
33
+ },
34
+ write: (request) => {
35
+ try {
36
+ options.fileSystem.writeText({ path: request.path, text: request.text });
37
+ return { outcome: "ok", value: void 0 };
38
+ } catch (thrown) {
39
+ return {
40
+ outcome: "failed",
41
+ error: {
42
+ kind: "unwritable",
43
+ path: request.path,
44
+ detail: failureDetail({ thrown })
45
+ }
46
+ };
47
+ }
48
+ }
49
+ });
50
+ var defaultFileSystemSurface = {
51
+ readText: (request) => readFileSync(request.path, "utf8"),
52
+ writeText: (request) => {
53
+ writeFileSync(request.path, request.text);
54
+ },
55
+ access: (request) => {
56
+ accessSync(request.path);
57
+ }
58
+ };
59
+ var createDefaultFileTextPort = (_options) => createFileTextPort({ fileSystem: defaultFileSystemSurface });
60
+
61
+ // core/platform-ports/module-loader-port.ts
62
+ import { pathToFileURL } from "node:url";
63
+ var createModuleLoaderPort = (options) => ({
64
+ load: (request) => Promise.resolve().then(() => options.importModule({ path: request.path })).then(
65
+ (namespace) => ({ outcome: "ok", value: namespace }),
66
+ (thrown) => ({
67
+ outcome: "failed",
68
+ error: {
69
+ kind: "module-unloadable",
70
+ path: request.path,
71
+ detail: thrown instanceof Error ? thrown.message : String(thrown)
72
+ }
73
+ })
74
+ )
75
+ });
76
+ var defaultImportModule = (request) => import(pathToFileURL(request.path).href);
77
+ var createDefaultModuleLoaderPort = (_options) => createModuleLoaderPort({ importModule: defaultImportModule });
78
+
79
+ // core/platform-ports/path-port.ts
80
+ import platformPath, { posix, win32 } from "node:path";
81
+ import { fileURLToPath } from "node:url";
82
+
83
+ // core/values/absolute-path.ts
84
+ var POSIX_ROOT_DRIVE_ROOT_OR_SHARE_ROOT = /^(?:\/|[A-Za-z]:[\\/]|\\\\[^\\/]+[\\/][^\\/]+[\\/])/;
85
+ var isAbsolutePath = (text) => POSIX_ROOT_DRIVE_ROOT_OR_SHARE_ROOT.test(text);
86
+ var absolutePathSchema = brandedTextSchema({
87
+ text: external_exports.string().regex(POSIX_ROOT_DRIVE_ROOT_OR_SHARE_ROOT),
88
+ isBranded: isAbsolutePath,
89
+ refusal: "not an absolute path"
90
+ });
91
+
92
+ // core/platform-ports/path-port.ts
93
+ var notAFileUrl = (request) => ({
94
+ outcome: "failed",
95
+ error: { kind: "not-a-file-url", url: request.url, detail: request.detail }
96
+ });
97
+ var absolutePathOfFileUrl = (request) => {
98
+ try {
99
+ const parsed = absolutePathSchema.safeParse(
100
+ fileURLToPath(request.url, { windows: request.surface === win32 })
101
+ );
102
+ if (!parsed.success) {
103
+ return notAFileUrl({ url: request.url, detail: "the file URL names no absolute path" });
104
+ }
105
+ return { outcome: "ok", value: parsed.data };
106
+ } catch (thrown) {
107
+ return notAFileUrl({
108
+ url: request.url,
109
+ detail: thrown instanceof Error ? thrown.message : String(thrown)
110
+ });
111
+ }
112
+ };
113
+ var absolutePathOf = (request) => {
114
+ const parsed = absolutePathSchema.safeParse(request.resolved);
115
+ if (!parsed.success) {
116
+ return { outcome: "failed", error: { kind: "working-directory-unusable", path: request.path } };
117
+ }
118
+ return { outcome: "ok", value: parsed.data };
119
+ };
120
+ var fileUrlForm = (request) => URL.canParse(request.url) && new URL(request.url).protocol === "file:" ? "file-url" : "not-a-file-url";
121
+ var UNREADABLE_WORKING_DIRECTORY = "";
122
+ var REPOSITORY_SEPARATOR = "/";
123
+ var WINDOWS_ANCHOR_ROOT = "C:\\";
124
+ var anchorRootOf = (request) => request.surface === win32 ? WINDOWS_ANCHOR_ROOT : request.surface.sep;
125
+ var workingDirectoryText = (request) => {
126
+ try {
127
+ return request.workingDirectory({});
128
+ } catch {
129
+ return UNREADABLE_WORKING_DIRECTORY;
130
+ }
131
+ };
132
+ var rootOf = (request) => request.surface.parse(request.path).root.toLowerCase();
133
+ var DRIVE_LESS_ROOTS = ["\\", "/"];
134
+ var rootFormOf = (request) => {
135
+ const root = request.surface.parse(request.path).root;
136
+ if (root === "") {
137
+ return "relative";
138
+ }
139
+ if (request.surface === win32 && DRIVE_LESS_ROOTS.includes(root)) {
140
+ return "rooted-without-drive";
141
+ }
142
+ return request.surface.isAbsolute(request.path) ? "fully-rooted" : "drive-relative";
143
+ };
144
+ var workingDirectoryReadingOf = (request) => {
145
+ const directory = workingDirectoryText(request);
146
+ return rootFormOf({ path: directory, surface: request.surface }) === "fully-rooted" ? { usability: "usable", directory } : { usability: "unusable" };
147
+ };
148
+ var driveRelationOf = (request) => request.reading.usability === "usable" && rootOf({ path: request.reading.directory, surface: request.surface }).startsWith(request.driveRoot.toLowerCase()) ? "same-drive" : "another-drive";
149
+ var driveRelativeFormOf = (request) => {
150
+ const driveRoot = request.surface.parse(request.path).root;
151
+ const reading = workingDirectoryReadingOf(request);
152
+ if (reading.usability === "unusable" || driveRelationOf({ driveRoot, reading, surface: request.surface }) === "another-drive") {
153
+ return request.surface.resolve(`${driveRoot}${request.surface.sep}`, request.path);
154
+ }
155
+ return request.surface.resolve(reading.directory, request.path);
156
+ };
157
+ var rootedWithoutDriveFormOf = (request) => {
158
+ const reading = workingDirectoryReadingOf(request);
159
+ if (reading.usability === "unusable") {
160
+ return request.surface.normalize(request.path);
161
+ }
162
+ return request.surface.resolve(request.surface.parse(reading.directory).root, request.path);
163
+ };
164
+ var relativeFormOf = (request) => {
165
+ const reading = workingDirectoryReadingOf(request);
166
+ if (reading.usability === "unusable") {
167
+ return request.surface.normalize(request.path);
168
+ }
169
+ return request.surface.resolve(reading.directory, request.path);
170
+ };
171
+ var absoluteFormOf = (request) => {
172
+ const rootForm = rootFormOf(request);
173
+ switch (rootForm) {
174
+ case "fully-rooted":
175
+ return request.surface.normalize(request.path);
176
+ case "rooted-without-drive":
177
+ return rootedWithoutDriveFormOf(request);
178
+ case "drive-relative":
179
+ return driveRelativeFormOf(request);
180
+ case "relative":
181
+ return relativeFormOf(request);
182
+ }
183
+ };
184
+ var driveFormOf = (request) => request.surface === win32 && rootFormOf(request) === "fully-rooted" ? "drive-carrying" : "drive-less";
185
+ var relativeLocationBetween = (request) => {
186
+ const fromDriveForm = driveFormOf({ path: request.from, surface: request.surface });
187
+ if (fromDriveForm !== driveFormOf({ path: request.to, surface: request.surface })) {
188
+ return { relation: "different-root" };
189
+ }
190
+ if (fromDriveForm === "drive-carrying") {
191
+ return relativeLocationOf(request);
192
+ }
193
+ const anchorRoot = anchorRootOf(request);
194
+ return relativeLocationOf({
195
+ surface: request.surface,
196
+ from: request.surface.resolve(anchorRoot, request.from),
197
+ to: request.surface.resolve(anchorRoot, request.to)
198
+ });
199
+ };
200
+ var relativeLocationOf = (request) => rootOf({ path: request.from, surface: request.surface }) === rootOf({ path: request.to, surface: request.surface }) ? {
201
+ relation: "within-root",
202
+ path: repositoryFormOf({ surface: request.surface, path: request.surface.relative(request.from, request.to) })
203
+ } : { relation: "different-root" };
204
+ var repositoryFormOf = (request) => request.path.split(request.surface.sep).join(REPOSITORY_SEPARATOR);
205
+ var surfaceOf = (request) => {
206
+ switch (request.flavour) {
207
+ case "posix":
208
+ return posix;
209
+ case "windows":
210
+ return win32;
211
+ case "platform":
212
+ return platformPath;
213
+ }
214
+ };
215
+ var portOver = (options) => ({
216
+ join: (request) => options.surface.join(...request.segments),
217
+ joinRepository: (request) => posix.join(...request.segments),
218
+ relative: (request) => relativeLocationBetween({
219
+ surface: options.surface,
220
+ from: absoluteFormOf({ path: request.from, surface: options.surface, workingDirectory: options.workingDirectory }),
221
+ to: absoluteFormOf({ path: request.to, surface: options.surface, workingDirectory: options.workingDirectory })
222
+ }),
223
+ directoryOf: (request) => options.surface.dirname(request.path),
224
+ repositoryDirectoryOf: (request) => posix.dirname(request.path),
225
+ resolve: (request) => absolutePathOf({
226
+ path: request.path,
227
+ resolved: absoluteFormOf({ path: request.path, surface: options.surface, workingDirectory: options.workingDirectory })
228
+ }),
229
+ fromFileUrl: (request) => fileUrlForm({ url: request.url }) === "not-a-file-url" ? notAFileUrl({ url: request.url, detail: "the text is not a file: URL" }) : absolutePathOfFileUrl({ url: request.url, surface: options.surface })
230
+ });
231
+ var createPathPort = (options) => portOver({ surface: surfaceOf({ flavour: options.flavour }), workingDirectory: options.workingDirectory });
232
+ var defaultWorkingDirectory = () => process.cwd();
233
+ var createDefaultPathPort = (_options) => createPathPort({ flavour: "platform", workingDirectory: defaultWorkingDirectory });
234
+
235
+ // core/values/install-layout.ts
236
+ var FOLDERS_BETWEEN_INSTALL_ROOT_AND_ENTRY = {
237
+ command: 2,
238
+ runner: 3
239
+ };
240
+ var installRootAboveEntry = (request) => Array.from({ length: FOLDERS_BETWEEN_INSTALL_ROOT_AND_ENTRY[request.entry] + 1 }).reduce(
241
+ (path) => request.directoryOf(path),
242
+ request.entryFile
243
+ );
244
+ var BUILT_MODULE_EXTENSION = ".js";
245
+ var SOURCE_MODULE_EXTENSION = ".ts";
246
+ var moduleExtensionOf = (request) => new URL(request.moduleUrl).pathname.endsWith(BUILT_MODULE_EXTENSION) ? BUILT_MODULE_EXTENSION : SOURCE_MODULE_EXTENSION;
247
+ var installFormOf = (request) => request.moduleExtension === BUILT_MODULE_EXTENSION ? "package" : "source";
248
+ var runnerModuleSegmentsOf = (request) => [request.installRoot, "mechanisms", request.mechanism, "runner", `runner${request.moduleExtension}`];
249
+ var MODULE_EXTENSIONS = [SOURCE_MODULE_EXTENSION, BUILT_MODULE_EXTENSION];
250
+ var moduleFileForm = (request) => MODULE_EXTENSIONS.some((extension) => request.text.endsWith(extension)) ? "module-file" : "not-module-file";
251
+
252
+ // core/values/repo-path.ts
253
+ var UNWALKABLE_SEGMENTS = ["", ".", ".."];
254
+ var LEADING_DRIVE_LETTER = /^[A-Za-z]:/;
255
+ var LINE_BREAK_OR_NUL = /[\n\r\0]/;
256
+ var NOT_A_REPO_PATH = "not a repo-relative path";
257
+ var isRepoPathText = (request) => !request.text.startsWith("/") && !LEADING_DRIVE_LETTER.test(request.text) && !request.text.includes("\\") && !LINE_BREAK_OR_NUL.test(request.text) && request.text.split("/").every((segment) => !UNWALKABLE_SEGMENTS.includes(segment)) ? "repo-path" : "not-repo-path";
258
+ var isRepoPath = (text) => isRepoPathText({ text }) === "repo-path";
259
+ var repoPathTextSchema = external_exports.string().superRefine((text, context) => {
260
+ if (isRepoPathText({ text }) === "not-repo-path") {
261
+ context.addIssue({ code: "custom", message: NOT_A_REPO_PATH });
262
+ }
263
+ });
264
+ var brandedRepoPathSchema = (request) => brandedTextSchema({ text: request.text, isBranded: isRepoPath, refusal: NOT_A_REPO_PATH });
265
+ var repoPathSchema = brandedRepoPathSchema({ text: repoPathTextSchema });
266
+
267
+ // core/mechanism-port/toolchain-requirement.ts
268
+ var RELEASE_PATTERN = /^(\d+)\.(\d+)\.(\d+)$/;
269
+ var NOT_INSTALLED = "not installed";
270
+ var MODULE_NOT_FOUND = "ERR_MODULE_NOT_FOUND";
271
+ var BACKSLASH = /\\/g;
272
+ var moduleErrorSchema = external_exports.object({ code: external_exports.string(), message: external_exports.string() });
273
+ var releaseParts = (request) => {
274
+ const match = RELEASE_PATTERN.exec(request.version);
275
+ return match === null ? void 0 : [Number(match[1]), Number(match[2]), Number(match[3])];
276
+ };
277
+ var partsOrder = (request) => request.left[0] - request.right[0] || request.left[1] - request.right[1] || request.left[2] - request.right[2];
278
+ var lineSupport = (request) => {
279
+ const floor = releaseParts({ version: request.line.floor });
280
+ const below = releaseParts({ version: request.line.below });
281
+ return floor !== void 0 && below !== void 0 && partsOrder({ left: request.found, right: floor }) >= 0 && partsOrder({ left: request.found, right: below }) < 0 ? "supported" : "unsupported";
282
+ };
283
+ var versionSupport = (request) => {
284
+ const found = releaseParts({ version: request.version });
285
+ return found !== void 0 && request.requirement.lines.some((line) => lineSupport({ line, found }) === "supported") ? "supported" : "unsupported";
286
+ };
287
+ var lineRange = (request) => {
288
+ const floor = releaseParts({ version: request.line.floor });
289
+ return floor !== void 0 && request.line.below === `${floor[0] + 1}.0.0` ? `^${request.line.floor}` : `>=${request.line.floor} <${request.line.below}`;
290
+ };
291
+ var supportedRange = (request) => request.requirement.lines.map((line) => lineRange({ line })).join(" || ");
292
+ var toolchainUnavailable = (request) => ({
293
+ outcome: "failed",
294
+ error: {
295
+ kind: "toolchain-unavailable",
296
+ packageName: request.requirement.packageName,
297
+ peer: request.requirement.peer,
298
+ supported: supportedRange({ requirement: request.requirement }),
299
+ found: request.found
300
+ }
301
+ });
302
+ var thrownState = (request) => {
303
+ const parsed = moduleErrorSchema.safeParse(request.thrown);
304
+ if (parsed.success && parsed.data.code === MODULE_NOT_FOUND && parsed.data.message.includes(`'${request.packageName}'`)) {
305
+ return NOT_INSTALLED;
306
+ }
307
+ const detail = request.thrown instanceof Error ? request.thrown.message : String(request.thrown);
308
+ return `unloadable: ${detail}`;
309
+ };
310
+ var slashed = (request) => request.path.replace(BACKSLASH, "/");
311
+ var placementOf = (request) => slashed({ path: request.location }).startsWith(`${slashed({ path: request.installRoot })}/`) ? "inside-install" : "outside-install";
312
+ var shadowingOf = (request) => request.location.installForm === "package" && placementOf({ location: request.resolved, installRoot: request.location.installRoot }) === "inside-install" ? "shadowed" : "unshadowed";
313
+ var supportedPeer = (request) => versionSupport({ requirement: request.requirement, version: request.found.version }) === "supported" ? { outcome: "ok", value: request.found.loaded } : toolchainUnavailable({ requirement: request.requirement, found: request.found.version });
314
+ var versionedPeer = (request) => Promise.resolve().then(request.load).then((loaded) => ({ loaded, version: request.versionOf(loaded) })).then(
315
+ (found) => supportedPeer({ requirement: request.requirement, found }),
316
+ (thrown) => toolchainUnavailable({
317
+ requirement: request.requirement,
318
+ found: thrownState({ thrown, packageName: request.requirement.packageName })
319
+ })
320
+ );
321
+ var placedPeer = (request) => shadowingOf({ resolved: request.resolved, location: request.location }) === "shadowed" ? Promise.resolve({
322
+ outcome: "failed",
323
+ error: {
324
+ kind: "toolchain-shadowed",
325
+ packageName: request.requirement.packageName,
326
+ location: request.resolved,
327
+ installRoot: request.location.installRoot
328
+ }
329
+ }) : versionedPeer(request);
330
+ var locatedPeer = (request) => request.located.outcome === "ok" ? placedPeer({ ...request, resolved: request.located.value }) : Promise.resolve(
331
+ toolchainUnavailable({
332
+ requirement: request.requirement,
333
+ found: `unloadable: ${request.located.error.url} (${request.located.error.detail})`
334
+ })
335
+ );
336
+ var loadedPeer = (request) => Promise.resolve().then(() => request.location.locate({ packageName: request.requirement.packageName })).then(
337
+ (located) => locatedPeer({ ...request, located }),
338
+ (thrown) => toolchainUnavailable({
339
+ requirement: request.requirement,
340
+ found: thrownState({ thrown, packageName: request.requirement.packageName })
341
+ })
342
+ );
343
+
344
+ export {
345
+ createDefaultFileTextPort,
346
+ isRepoPathText,
347
+ repoPathTextSchema,
348
+ brandedRepoPathSchema,
349
+ repoPathSchema,
350
+ createDefaultModuleLoaderPort,
351
+ absolutePathSchema,
352
+ createDefaultPathPort,
353
+ NOT_INSTALLED,
354
+ versionSupport,
355
+ loadedPeer,
356
+ installRootAboveEntry,
357
+ moduleExtensionOf,
358
+ installFormOf,
359
+ runnerModuleSegmentsOf,
360
+ moduleFileForm
361
+ };
@@ -1,10 +1,41 @@
1
+ import {
2
+ repoPathSchema
3
+ } from "./chunk-HVABJ7T4.js";
1
4
  import {
2
5
  clauseIdSchema,
3
6
  disciplineIdSchema,
4
7
  external_exports,
5
- mechanismIdSchema,
6
- repoPathSchema
7
- } from "./chunk-FOAGAYXM.js";
8
+ mechanismIdSchema
9
+ } from "./chunk-SWPCKTJV.js";
10
+
11
+ // core/values/json-kind.ts
12
+ var JSON_KIND_NAMES = {
13
+ string: "a string",
14
+ number: "a number",
15
+ boolean: "a boolean",
16
+ null: "null",
17
+ array: "an array",
18
+ object: "an object"
19
+ };
20
+ var jsonKindOf = (request) => {
21
+ if (request.value === null) return "null";
22
+ if (Array.isArray(request.value)) return "array";
23
+ const kind = typeof request.value;
24
+ if (kind === "string" || kind === "number" || kind === "boolean") return kind;
25
+ return "object";
26
+ };
27
+ var isJsonObject = (candidate) => jsonKindOf({ value: candidate }) === "object";
28
+ var sameItems = (request) => request.left.length === request.right.length && request.left.every((leftItem, position) => sameJsonValue({ left: leftItem, right: request.right[position] }) === "same") ? "same" : "different";
29
+ var sameObjects = (request) => Object.keys(request.left).length === Object.keys(request.right).length && Object.entries(request.left).every(
30
+ ([key, leftEntry]) => Object.hasOwn(request.right, key) && sameJsonValue({ left: leftEntry, right: request.right[key] }) === "same"
31
+ ) ? "same" : "different";
32
+ var sameJsonValue = (request) => {
33
+ const { left, right } = request;
34
+ if (right === void 0 || jsonKindOf({ value: left }) !== jsonKindOf({ value: right })) return "different";
35
+ if (Array.isArray(left) && Array.isArray(right)) return sameItems({ left, right });
36
+ if (isJsonObject(left) && isJsonObject(right)) return sameObjects({ left, right });
37
+ return left === right ? "same" : "different";
38
+ };
8
39
 
9
40
  // core/rule-set-reader/rule-set-reader.ts
10
41
  var SUPPORTED_VERSION = 1;
@@ -90,11 +121,30 @@ var disciplineFileSchema = external_exports.object({
90
121
  error: "two clauses share an id"
91
122
  })
92
123
  });
124
+ var clauseSettingDeclarationSchema = external_exports.strictObject({
125
+ default: external_exports.json(),
126
+ choices: external_exports.array(external_exports.json()).min(1).optional()
127
+ }).superRefine((declaration, context) => {
128
+ if (declaration.choices === void 0) return;
129
+ const defaultKind = jsonKindOf({ value: declaration.default });
130
+ if (declaration.choices.some((choice) => jsonKindOf({ value: choice }) !== defaultKind)) {
131
+ context.addIssue({ code: "custom", path: ["choices"], message: `every choice must be ${JSON_KIND_NAMES[defaultKind]}, as the default is` });
132
+ }
133
+ if (!declaration.choices.some((choice) => sameJsonValue({ left: choice, right: declaration.default }) === "same")) {
134
+ context.addIssue({ code: "custom", path: ["default"], message: "the default must be one of the choices" });
135
+ }
136
+ });
93
137
  var pieceFileSchema = external_exports.object({
94
138
  version: external_exports.literal(SUPPORTED_VERSION),
95
139
  discipline: disciplineIdSchema,
96
140
  mechanism: mechanismIdSchema,
97
- clauses: external_exports.array(external_exports.object({ clause: clauseIdSchema, settings: external_exports.unknown() })).refine((entries) => textDistinctness(entries.map((entry) => entry.clause)) === "distinct", {
141
+ clauses: external_exports.array(
142
+ external_exports.object({
143
+ clause: clauseIdSchema,
144
+ settings: external_exports.unknown(),
145
+ clauseSettings: external_exports.record(external_exports.string().min(1), clauseSettingDeclarationSchema).default({})
146
+ })
147
+ ).refine((entries) => textDistinctness(entries.map((entry) => entry.clause)) === "distinct", {
98
148
  error: "two entries name the same clause"
99
149
  })
100
150
  });
@@ -180,6 +230,9 @@ var readPieceFile = (request) => {
180
230
  var eslintConfigLookupSchema = external_exports.enum(["nearest-to-file", "repository-root"]);
181
231
 
182
232
  export {
233
+ JSON_KIND_NAMES,
234
+ jsonKindOf,
235
+ sameJsonValue,
183
236
  parsedJson,
184
237
  readVersionOneJson,
185
238
  disciplineFilePath,