@autotelic/protocol 0.0.0-stage → 0.1.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 (74) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +183 -2
  3. package/dist/baseline.d.ts +41 -0
  4. package/dist/baseline.d.ts.map +1 -0
  5. package/dist/baseline.js +62 -0
  6. package/dist/baseline.js.map +1 -0
  7. package/dist/catalog.d.ts +275 -0
  8. package/dist/catalog.d.ts.map +1 -0
  9. package/dist/catalog.js +437 -0
  10. package/dist/catalog.js.map +1 -0
  11. package/dist/compat.d.ts +12 -0
  12. package/dist/compat.d.ts.map +1 -0
  13. package/dist/compat.js +104 -0
  14. package/dist/compat.js.map +1 -0
  15. package/dist/config.d.ts +179 -0
  16. package/dist/config.d.ts.map +1 -0
  17. package/dist/config.js +302 -0
  18. package/dist/config.js.map +1 -0
  19. package/dist/decode.d.ts +32 -0
  20. package/dist/decode.d.ts.map +1 -0
  21. package/dist/decode.js +71 -0
  22. package/dist/decode.js.map +1 -0
  23. package/dist/doc.d.ts +105 -0
  24. package/dist/doc.d.ts.map +1 -0
  25. package/dist/doc.js +159 -0
  26. package/dist/doc.js.map +1 -0
  27. package/dist/graph.d.ts +139 -0
  28. package/dist/graph.d.ts.map +1 -0
  29. package/dist/graph.js +258 -0
  30. package/dist/graph.js.map +1 -0
  31. package/dist/index.d.ts +22 -0
  32. package/dist/index.d.ts.map +1 -0
  33. package/dist/index.js +22 -0
  34. package/dist/index.js.map +1 -0
  35. package/dist/intent.d.ts +32 -0
  36. package/dist/intent.d.ts.map +1 -0
  37. package/dist/intent.js +54 -0
  38. package/dist/intent.js.map +1 -0
  39. package/dist/json.d.ts +3 -0
  40. package/dist/json.d.ts.map +1 -0
  41. package/dist/json.js +18 -0
  42. package/dist/json.js.map +1 -0
  43. package/dist/lexicon.d.ts +58 -0
  44. package/dist/lexicon.d.ts.map +1 -0
  45. package/dist/lexicon.js +176 -0
  46. package/dist/lexicon.js.map +1 -0
  47. package/dist/patterns.d.ts +65 -0
  48. package/dist/patterns.d.ts.map +1 -0
  49. package/dist/patterns.js +166 -0
  50. package/dist/patterns.js.map +1 -0
  51. package/dist/recipes.d.ts +34 -0
  52. package/dist/recipes.d.ts.map +1 -0
  53. package/dist/recipes.js +74 -0
  54. package/dist/recipes.js.map +1 -0
  55. package/dist/report.d.ts +218 -0
  56. package/dist/report.d.ts.map +1 -0
  57. package/dist/report.js +330 -0
  58. package/dist/report.js.map +1 -0
  59. package/dist/version.d.ts +9 -0
  60. package/dist/version.d.ts.map +1 -0
  61. package/dist/version.js +9 -0
  62. package/dist/version.js.map +1 -0
  63. package/package.json +45 -3
  64. package/schema/baseline.json +29 -0
  65. package/schema/catalog.json +206 -0
  66. package/schema/cutlist.config.json +103 -0
  67. package/schema/intent.json +43 -0
  68. package/schema/jig.config.json +56 -0
  69. package/schema/manifest.json +67 -0
  70. package/schema/menu.json +169 -0
  71. package/schema/onboarding.json +25 -0
  72. package/schema/patterns.json +141 -0
  73. package/schema/recipes.json +57 -0
  74. package/schema/report.json +141 -0
@@ -0,0 +1,179 @@
1
+ /** Where a component sits in the tier pipeline. */
2
+ export type TierName = "primitive" | "shared" | "local";
3
+ /** The tier roots, most fundamental first. */
4
+ export interface Tiers {
5
+ readonly primitive: ReadonlyArray<string>;
6
+ readonly shared: ReadonlyArray<string>;
7
+ readonly local: ReadonlyArray<string>;
8
+ }
9
+ /** Where the token vocabulary is read from. */
10
+ export interface TokenSource {
11
+ /** The Tailwind config, or the CSS entry when the theme lives in `@theme`. */
12
+ readonly from: string;
13
+ /** The theme key to read (Tailwind v3, e.g. `extend`). Absent for v4 `@theme`. */
14
+ readonly theme?: string;
15
+ /** The stylesheet whose `:root` custom properties are the second token layer. */
16
+ readonly vars?: string;
17
+ }
18
+ /**
19
+ * How a component acquires an owner.
20
+ *
21
+ * `first-segment` collapses a deep route (`projects_.$id.sponsors`) to the domain it
22
+ * belongs to (`projects`). Without it, almost every component imported by two deep
23
+ * route dirs reads as "shared", and the tier stops meaning anything.
24
+ */
25
+ export interface Ownership {
26
+ readonly routeOwner: "first-segment" | "full";
27
+ /** Whether an importer's own importers count toward ownership transitively. */
28
+ readonly transitive: boolean;
29
+ /**
30
+ * Entry-point suffixes, relative to any source root (`entry.client.tsx`, `root.tsx`).
31
+ * Nothing imports an entry by design, so it is an orphan only when this list forgets it.
32
+ */
33
+ readonly entries?: ReadonlyArray<string>;
34
+ }
35
+ /** The names a composition pattern is spelled with in this repo. */
36
+ export interface CompositionPattern {
37
+ readonly providerSuffix: string;
38
+ readonly hookPrefix: string;
39
+ /**
40
+ * The keys of the object a provider supplies. The canonical pattern is
41
+ * `state/actions/meta`; declaring the shape keeps the catalog from guessing, and lets
42
+ * a repo whose context is `state/dispatch` record that instead of being called broken.
43
+ */
44
+ readonly valueKeys?: ReadonlyArray<string>;
45
+ }
46
+ /** How URL state is read in this repo's router. */
47
+ export interface UrlStatePattern {
48
+ readonly router: "remix" | "tanstack" | "next" | "react-router";
49
+ readonly reader: string;
50
+ }
51
+ /** The convention packs a repo opts into, parameterized so they travel. */
52
+ export interface Patterns {
53
+ readonly composition?: CompositionPattern;
54
+ readonly urlState?: UrlStatePattern;
55
+ }
56
+ /** A repo's vocabulary. The shared half of every tool's config. */
57
+ export interface Vocabulary {
58
+ /** Where application code lives, relative to the root. */
59
+ readonly roots: ReadonlyArray<string>;
60
+ /** Import alias → paths, read from tsconfig rather than assumed. */
61
+ readonly alias?: Readonly<Record<string, ReadonlyArray<string>>>;
62
+ readonly tiers: Tiers;
63
+ readonly tokens: TokenSource;
64
+ readonly hooks?: {
65
+ readonly barrel?: string;
66
+ };
67
+ readonly ownership: Ownership;
68
+ readonly patterns?: Patterns;
69
+ }
70
+ /** Where `cutlist` writes each rendering of the model. */
71
+ export interface CutlistOutput {
72
+ readonly catalog?: string;
73
+ readonly manifest?: string;
74
+ /** The menu model as JSON. The machine rendering beside its Markdown twin. */
75
+ readonly menuJson?: string;
76
+ /** The menu as Markdown. */
77
+ readonly menu?: string;
78
+ /** The directory of authored intent records, one JSON file per part name. */
79
+ readonly intent?: string;
80
+ /** The pattern language: compositions, primitives, families, and the stable shape. */
81
+ readonly patterns?: string;
82
+ /** The same pattern view as JSON, for an agent that wants to sort or filter it. */
83
+ readonly patternsJson?: string;
84
+ /** Copyable imports and usage skeletons for features and load-bearing parts. */
85
+ readonly recipes?: string;
86
+ /** The same recipes as JSON, for an agent building a mockup. */
87
+ readonly recipesJson?: string;
88
+ /**
89
+ * The directory of graph renderings — Mermaid source beside the SVG `pele` drew from it.
90
+ * A directory, not a file, because one viewpoint is one diagram and a repo grows more.
91
+ *
92
+ * Opt-in: absent means `cutlist` does not render diagrams at all. On a real app the
93
+ * projection was 8 MB of a 13 MB artifact for 429 panels, so it is a rendering a repo
94
+ * asks for rather than one it gets.
95
+ */
96
+ readonly diagrams?: string | undefined;
97
+ readonly hooks?: string;
98
+ readonly tokens?: string;
99
+ }
100
+ /**
101
+ * The paths `cutlist` needs in order to write, with every required rendering resolved.
102
+ *
103
+ * `diagrams` is absent unless a repository names a directory for it: the graph projection
104
+ * is opt-in because on a real app it was 8 MB of a 13 MB artifact for 429 panels, and the
105
+ * menu already answers the questions the pictures were drawing.
106
+ */
107
+ export interface ResolvedCutlistOutput extends Required<Omit<CutlistOutput, "diagrams">> {
108
+ readonly diagrams?: string | undefined;
109
+ }
110
+ /**
111
+ * Where a `cutlist.config.json` that declares no `output` writes each rendering.
112
+ *
113
+ * This lives in `protocol` rather than in `cutlist` because two tools must agree on it:
114
+ * `cutlist` builds these paths and `jig init` marks them generated in `.gitattributes`.
115
+ * A copy in either package is how the two plans drift.
116
+ */
117
+ export declare const cutlistDefaultOutput: ResolvedCutlistOutput;
118
+ /** `cutlist.config.json`: the vocabulary plus where its renderings go. */
119
+ export interface CutlistConfig extends Vocabulary {
120
+ readonly $schema?: string;
121
+ readonly output?: CutlistOutput;
122
+ }
123
+ /** A process `jig` drives, or a plugin an existing host already runs. */
124
+ export interface EngineRef {
125
+ readonly id: string;
126
+ /** `process` is a binary `jig` shells out to; `oxlint-plugin` rides `oxlint`. */
127
+ readonly kind: "process" | "oxlint-plugin" | "internal";
128
+ readonly command?: string;
129
+ readonly config?: string;
130
+ /**
131
+ * Extra args appended to the engine's invocation. The one thing a project's own layout
132
+ * needs that a shared default cannot know: e.g. scoping the `plumb` engine to
133
+ * `--ignore-pattern examples/**` at a root whose exemplar will not build.
134
+ */
135
+ readonly args?: ReadonlyArray<string>;
136
+ readonly enabled?: boolean;
137
+ /**
138
+ * Report this engine's findings and never fail the gate on them.
139
+ *
140
+ * The escape hatch for an engine worth reading and not yet trustworthy: plumb 0.6.0
141
+ * misattributes `require-schema-type-derivation` to `file:1:1`, so 2 findings out of 1167
142
+ * failed a correct one-line change. Advisory findings are printed, baselined and counted --
143
+ * they cannot set the exit code, which is the only thing a broken engine should lose.
144
+ */
145
+ readonly advisory?: boolean;
146
+ }
147
+ /** When a run fails. */
148
+ export interface Gate {
149
+ readonly mode: "touched-files" | "all";
150
+ /** The committed baseline file, relative to the root. */
151
+ readonly baseline: string;
152
+ readonly failOn?: "error" | "warn" | "any-new";
153
+ }
154
+ /** Every shape a report renders to. One name per host: a human, CI, an editor, a trove. */
155
+ export type ReportFormat = "text" | "json" | "jsonl" | "github" | "sarif" | "lsp" | "codeclimate";
156
+ /** The shapes a config may name, in the order the CLI's help lists them. */
157
+ export declare const REPORT_FORMATS: ReadonlyArray<ReportFormat>;
158
+ /** `jig.config.json`: which engines are active, and how a run is gated. */
159
+ export interface HarnessConfig {
160
+ readonly $schema?: string;
161
+ readonly engines: ReadonlyArray<EngineRef>;
162
+ readonly gate: Gate;
163
+ readonly report?: {
164
+ readonly format?: ReportFormat;
165
+ readonly maxWarnings?: number;
166
+ };
167
+ /** Where the agent reads from. Both are generated by `jig init`. */
168
+ readonly agent?: {
169
+ readonly cookbook?: string;
170
+ readonly onboarding?: string;
171
+ };
172
+ }
173
+ /** Read the tier name set, or `undefined` when malformed. */
174
+ export declare const decodeTiers: (value: unknown) => Tiers | undefined;
175
+ /** Read `cutlist.config.json`, or `undefined` when it does not decode. */
176
+ export declare const decodeCutlistConfig: (value: unknown) => CutlistConfig | undefined;
177
+ /** Read `jig.config.json`, or `undefined` when it does not decode. */
178
+ export declare const decodeHarnessConfig: (value: unknown) => HarnessConfig | undefined;
179
+ //# sourceMappingURL=config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAaA,mDAAmD;AACnD,MAAM,MAAM,QAAQ,GAAG,WAAW,GAAG,QAAQ,GAAG,OAAO,CAAA;AAEvD,8CAA8C;AAC9C,MAAM,WAAW,KAAK;IACpB,QAAQ,CAAC,SAAS,EAAE,aAAa,CAAC,MAAM,CAAC,CAAA;IACzC,QAAQ,CAAC,MAAM,EAAE,aAAa,CAAC,MAAM,CAAC,CAAA;IACtC,QAAQ,CAAC,KAAK,EAAE,aAAa,CAAC,MAAM,CAAC,CAAA;CACtC;AAED,+CAA+C;AAC/C,MAAM,WAAW,WAAW;IAC1B,8EAA8E;IAC9E,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,kFAAkF;IAClF,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAA;IACvB,iFAAiF;IACjF,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAA;CACvB;AAED;;;;;;GAMG;AACH,MAAM,WAAW,SAAS;IACxB,QAAQ,CAAC,UAAU,EAAE,eAAe,GAAG,MAAM,CAAA;IAC7C,+EAA+E;IAC/E,QAAQ,CAAC,UAAU,EAAE,OAAO,CAAA;IAC5B;;;OAGG;IACH,QAAQ,CAAC,OAAO,CAAC,EAAE,aAAa,CAAC,MAAM,CAAC,CAAA;CACzC;AAED,oEAAoE;AACpE,MAAM,WAAW,kBAAkB;IACjC,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAA;IAC/B,QAAQ,CAAC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AW,OAAO,KAAG,aAAa,GAAG,SAwCpE,CAAA;AAwDD,sEAAsE;AACtE,eAAO,MAAM,mBAAmB,UAAW,OAAO,KAAG,aAAa,GAAG,SAiBpE,CAAA"}
package/dist/config.js ADDED
@@ -0,0 +1,302 @@
1
+ /*
2
+ * The config seam: the repo's vocabulary, declared once, read by every tool.
3
+ *
4
+ * Each tool keeps its own config file — a client can adopt `joggle` alone — but the
5
+ * *vocabulary* is shared: where app code lives, how imports alias, which roots are
6
+ * which tier, where tokens come from, how routes own components, which convention
7
+ * packs apply. `cutlist` consumes all of it; `plumb-ui`'s manifest is a projection of
8
+ * it; the pattern packs are parameterized by it. That single schema is what makes
9
+ * "repo-agnostic" a contract instead of an aspiration.
10
+ */
11
+ import { arrayOf, bool, isRecord, num, oneOf, str, strings } from "./decode.js";
12
+ /**
13
+ * Where a `cutlist.config.json` that declares no `output` writes each rendering.
14
+ *
15
+ * This lives in `protocol` rather than in `cutlist` because two tools must agree on it:
16
+ * `cutlist` builds these paths and `jig init` marks them generated in `.gitattributes`.
17
+ * A copy in either package is how the two plans drift.
18
+ */
19
+ export const cutlistDefaultOutput = {
20
+ catalog: "tools/ui-catalog/catalog.json",
21
+ manifest: "tools/ui-catalog/plumb-ui.config.json",
22
+ menuJson: "tools/ui-catalog/menu.json",
23
+ menu: "tools/ui-catalog/MENU.md",
24
+ // Authored, and deliberately outside the generated root: `rm -rf tools/ui-catalog`
25
+ // followed by a build must reproduce the artifact, and it cannot do that if a human's
26
+ // sentences live inside it.
27
+ intent: "tools/ui-intent",
28
+ patterns: "tools/ui-catalog/PATTERNS.md",
29
+ patternsJson: "tools/ui-catalog/patterns.json",
30
+ recipes: "tools/ui-catalog/RECIPES.md",
31
+ recipesJson: "tools/ui-catalog/recipes.json",
32
+ hooks: "tools/ui-catalog/hooks.md",
33
+ tokens: "tools/ui-catalog/tokens.md",
34
+ };
35
+ /** The shapes a config may name, in the order the CLI's help lists them. */
36
+ export const REPORT_FORMATS = [
37
+ "text",
38
+ "json",
39
+ "jsonl",
40
+ "github",
41
+ "sarif",
42
+ "lsp",
43
+ "codeclimate",
44
+ ];
45
+ /*
46
+ * Decoders — the authored configs, read as untrusted input.
47
+ *
48
+ * Configs are the one thing a human writes, so a malformed value must not become a crash
49
+ * or a silently wrong vocabulary: the caller substitutes its default (`cutlist`'s
50
+ * `defaultConfig`, `jig`'s `defaultConfig`) when a decode returns `undefined`. Both engines
51
+ * currently decode through their own schema; these are the language-neutral twin, and the
52
+ * two are checked against each other by the schema-conformance suite.
53
+ */
54
+ /** Read the tier name set, or `undefined` when malformed. */
55
+ export const decodeTiers = (value) => {
56
+ if (!isRecord(value))
57
+ return undefined;
58
+ const primitive = strings(value.primitive);
59
+ const shared = strings(value.shared);
60
+ const local = strings(value.local);
61
+ if (primitive === undefined || shared === undefined || local === undefined)
62
+ return undefined;
63
+ return { primitive, shared, local };
64
+ };
65
+ const decodeTokenSource = (value) => {
66
+ if (!isRecord(value))
67
+ return undefined;
68
+ const from = str(value.from);
69
+ if (from === undefined)
70
+ return undefined;
71
+ const theme = str(value.theme);
72
+ const vars = str(value.vars);
73
+ return {
74
+ from,
75
+ ...(theme === undefined ? {} : { theme }),
76
+ ...(vars === undefined ? {} : { vars }),
77
+ };
78
+ };
79
+ const decodeOwnership = (value) => {
80
+ if (!isRecord(value))
81
+ return undefined;
82
+ const routeOwner = oneOf(value.routeOwner, ["first-segment", "full"]);
83
+ const transitive = bool(value.transitive);
84
+ if (routeOwner === undefined || transitive === undefined)
85
+ return undefined;
86
+ const entries = "entries" in value ? strings(value.entries) : undefined;
87
+ if ("entries" in value && entries === undefined)
88
+ return undefined;
89
+ return {
90
+ routeOwner,
91
+ transitive,
92
+ ...(entries === undefined ? {} : { entries }),
93
+ };
94
+ };
95
+ const decodePatterns = (value) => {
96
+ if (!isRecord(value))
97
+ return undefined;
98
+ let composition;
99
+ if ("composition" in value) {
100
+ if (!isRecord(value.composition))
101
+ return undefined;
102
+ const providerSuffix = str(value.composition.providerSuffix);
103
+ const hookPrefix = str(value.composition.hookPrefix);
104
+ const valueKeys = strings(value.composition.valueKeys);
105
+ if (providerSuffix === undefined || hookPrefix === undefined)
106
+ return undefined;
107
+ composition = {
108
+ providerSuffix,
109
+ hookPrefix,
110
+ ...(valueKeys === undefined ? {} : { valueKeys }),
111
+ };
112
+ }
113
+ let urlState;
114
+ if ("urlState" in value) {
115
+ if (!isRecord(value.urlState))
116
+ return undefined;
117
+ const router = oneOf(value.urlState.router, [
118
+ "remix",
119
+ "tanstack",
120
+ "next",
121
+ "react-router",
122
+ ]);
123
+ const reader = str(value.urlState.reader);
124
+ if (router === undefined || reader === undefined)
125
+ return undefined;
126
+ urlState = { router, reader };
127
+ }
128
+ const patterns = {
129
+ ...(composition === undefined ? {} : { composition }),
130
+ ...(urlState === undefined ? {} : { urlState }),
131
+ };
132
+ return patterns;
133
+ };
134
+ const decodeAlias = (value) => {
135
+ if (!isRecord(value))
136
+ return undefined;
137
+ const out = {};
138
+ for (const [key, targets] of Object.entries(value)) {
139
+ const decoded = strings(targets);
140
+ if (decoded === undefined)
141
+ return undefined;
142
+ out[key] = decoded;
143
+ }
144
+ return out;
145
+ };
146
+ /** Read `cutlist.config.json`, or `undefined` when it does not decode. */
147
+ export const decodeCutlistConfig = (value) => {
148
+ if (!isRecord(value))
149
+ return undefined;
150
+ const roots = strings(value.roots);
151
+ const tiers = decodeTiers(value.tiers);
152
+ const tokens = decodeTokenSource(value.tokens);
153
+ const ownership = decodeOwnership(value.ownership);
154
+ if (roots === undefined ||
155
+ roots.length === 0 ||
156
+ tiers === undefined ||
157
+ tokens === undefined ||
158
+ ownership === undefined) {
159
+ return undefined;
160
+ }
161
+ const $schema = str(value.$schema);
162
+ const alias = "alias" in value ? decodeAlias(value.alias) : undefined;
163
+ if ("alias" in value && alias === undefined)
164
+ return undefined;
165
+ let hooks;
166
+ if ("hooks" in value) {
167
+ if (!isRecord(value.hooks))
168
+ return undefined;
169
+ const barrel = str(value.hooks.barrel);
170
+ if ("barrel" in value.hooks && barrel === undefined)
171
+ return undefined;
172
+ hooks = barrel === undefined ? {} : { barrel };
173
+ }
174
+ const patterns = "patterns" in value ? decodePatterns(value.patterns) : undefined;
175
+ if ("patterns" in value && patterns === undefined)
176
+ return undefined;
177
+ const output = "output" in value ? decodeOutput(value.output) : undefined;
178
+ if ("output" in value && output === undefined)
179
+ return undefined;
180
+ return {
181
+ ...($schema === undefined ? {} : { $schema }),
182
+ roots,
183
+ tiers,
184
+ tokens,
185
+ ownership,
186
+ ...(alias === undefined ? {} : { alias }),
187
+ ...(hooks === undefined ? {} : { hooks }),
188
+ ...(patterns === undefined ? {} : { patterns }),
189
+ ...(output === undefined ? {} : { output }),
190
+ };
191
+ };
192
+ const decodeOutput = (value) => {
193
+ if (!isRecord(value))
194
+ return undefined;
195
+ const out = {};
196
+ for (const key of [
197
+ "catalog",
198
+ "manifest",
199
+ "menuJson",
200
+ "menu",
201
+ "intent",
202
+ "diagrams",
203
+ "hooks",
204
+ "tokens",
205
+ ]) {
206
+ if (!(key in value))
207
+ continue;
208
+ const decoded = str(value[key]);
209
+ if (decoded === undefined)
210
+ return undefined;
211
+ out[key] = decoded;
212
+ }
213
+ return out;
214
+ };
215
+ const decodeEngineRef = (value) => {
216
+ if (!isRecord(value))
217
+ return undefined;
218
+ const id = str(value.id);
219
+ const kind = oneOf(value.kind, ["process", "oxlint-plugin", "internal"]);
220
+ if (id === undefined || kind === undefined)
221
+ return undefined;
222
+ const command = str(value.command);
223
+ const config = str(value.config);
224
+ // Strict: an `args` that is present but not a string array is a vocabulary jig cannot
225
+ // trust, so the whole engine ref is refused rather than run with guessed args.
226
+ const args = "args" in value ? strings(value.args) : undefined;
227
+ if ("args" in value && args === undefined)
228
+ return undefined;
229
+ const enabled = bool(value.enabled);
230
+ const advisory = bool(value.advisory);
231
+ return {
232
+ id,
233
+ kind,
234
+ ...(command === undefined ? {} : { command }),
235
+ ...(config === undefined ? {} : { config }),
236
+ ...(args === undefined ? {} : { args }),
237
+ ...(enabled === undefined ? {} : { enabled }),
238
+ ...(advisory === undefined ? {} : { advisory }),
239
+ };
240
+ };
241
+ const decodeGate = (value) => {
242
+ if (!isRecord(value))
243
+ return undefined;
244
+ const mode = oneOf(value.mode, ["touched-files", "all"]);
245
+ const baseline = str(value.baseline);
246
+ if (mode === undefined || baseline === undefined)
247
+ return undefined;
248
+ const failOn = oneOf(value.failOn, ["error", "warn", "any-new"]);
249
+ return { mode, baseline, ...(failOn === undefined ? {} : { failOn }) };
250
+ };
251
+ /** Read `jig.config.json`, or `undefined` when it does not decode. */
252
+ export const decodeHarnessConfig = (value) => {
253
+ if (!isRecord(value))
254
+ return undefined;
255
+ const engines = arrayOf(value.engines, decodeEngineRef);
256
+ const gate = decodeGate(value.gate);
257
+ if (engines === undefined || gate === undefined)
258
+ return undefined;
259
+ const $schema = str(value.$schema);
260
+ const report = "report" in value ? decodeReportOptions(value.report) : undefined;
261
+ if ("report" in value && report === undefined)
262
+ return undefined;
263
+ const agent = "agent" in value ? decodeAgentOptions(value.agent) : undefined;
264
+ if ("agent" in value && agent === undefined)
265
+ return undefined;
266
+ return {
267
+ ...($schema === undefined ? {} : { $schema }),
268
+ engines,
269
+ gate,
270
+ ...(report === undefined ? {} : { report }),
271
+ ...(agent === undefined ? {} : { agent }),
272
+ };
273
+ };
274
+ const decodeReportOptions = (value) => {
275
+ if (!isRecord(value))
276
+ return undefined;
277
+ const format = oneOf(value.format, REPORT_FORMATS);
278
+ if ("format" in value && format === undefined)
279
+ return undefined;
280
+ const maxWarnings = num(value.maxWarnings);
281
+ if ("maxWarnings" in value && maxWarnings === undefined)
282
+ return undefined;
283
+ return {
284
+ ...(format === undefined ? {} : { format }),
285
+ ...(maxWarnings === undefined ? {} : { maxWarnings }),
286
+ };
287
+ };
288
+ const decodeAgentOptions = (value) => {
289
+ if (!isRecord(value))
290
+ return undefined;
291
+ const cookbook = str(value.cookbook);
292
+ const onboarding = str(value.onboarding);
293
+ if ("cookbook" in value && cookbook === undefined)
294
+ return undefined;
295
+ if ("onboarding" in value && onboarding === undefined)
296
+ return undefined;
297
+ return {
298
+ ...(cookbook === undefined ? {} : { cookbook }),
299
+ ...(onboarding === undefined ? {} : { onboarding }),
300
+ };
301
+ };
302
+ //# sourceMappingURL=config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,GAAG,EAAE,KAAK,EAAE,GAAG,EAAE,OAAO,EAAE,MAAM,aAAa,CAAA;AAuH/E;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAA0B;IACzD,OAAO,EAAE,+BAA+B;IACxC,QAAQ,EAAE,uCAAuC;IACjD,QAAQ,EAAE,4BAA4B;IACtC,IAAI,EAAE,0BAA0B;IAChC,mFAAmF;IACnF,sFAAsF;IACtF,4BAA4B;IAC5B,MAAM,EAAE,iBAAiB;IACzB,QAAQ,EAAE,8BAA8B;IACxC,YAAY,EAAE,gCAAgC;IAC9C,OAAO,EAAE,6BAA6B;IACtC,WAAW,EAAE,+BAA+B;IAC5C,KAAK,EAAE,2BAA2B;IAClC,MAAM,EAAE,4BAA4B;CACrC,CAAA;AA4CD,4EAA4E;AAC5E,MAAM,CAAC,MAAM,cAAc,GAAgC;IACzD,MAAM;IACN,MAAM;IACN,OAAO;IACP,QAAQ;IACR,OAAO;IACP,KAAK;IACL,aAAa;CACd,CAAA;AAkBD;;;;;;;;GAQG;AAEH,6DAA6D;AAC7D,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,KAAc,EAAqB,EAAE;IAC/D,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC;QAAE,OAAO,SAAS,CAAA;IACtC,MAAM,SAAS,GAAG,OAAO,CAAC,KAAK,CAAC,SAAS,CAAC,CAAA;IAC1C,MAAM,MAAM,GAAG,OAAO,CAAC,KAAK,CAA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UAAU,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,UAAU,EAAE,CAAC;KACpD,CAAA;AACH,CAAC,CAAA"}
@@ -0,0 +1,32 @@
1
+ import { type LexiconName, type LexiconRef } from "./lexicon.ts";
2
+ /** A JSON object, as opposed to an array, `null`, or a scalar. */
3
+ export declare const isRecord: (value: unknown) => value is Record<string, unknown>;
4
+ /** A string, including the empty one. */
5
+ export declare const str: (value: unknown) => string | undefined;
6
+ /** A finite number. */
7
+ export declare const num: (value: unknown) => number | undefined;
8
+ /** An integer. */
9
+ export declare const int: (value: unknown) => number | undefined;
10
+ /** A boolean. */
11
+ export declare const bool: (value: unknown) => boolean | undefined;
12
+ /** One of a closed set of strings. */
13
+ export declare const oneOf: <T extends string>(value: unknown, allowed: ReadonlyArray<T>) => T | undefined;
14
+ /**
15
+ * An array where every element decodes. A single bad element fails the whole array: a list
16
+ * with one unreadable entry is a record this reader cannot trust, and a partially-read list
17
+ * is a false finding waiting to happen.
18
+ */
19
+ export declare const arrayOf: <T>(value: unknown, read: (element: unknown) => T | undefined) => ReadonlyArray<T> | undefined;
20
+ /** An array of strings. */
21
+ export declare const strings: (value: unknown) => ReadonlyArray<string> | undefined;
22
+ /**
23
+ * The record's lexicon reference, checked against the name the caller expected.
24
+ *
25
+ * Prefers the explicit `lexicon` object. Falls back to the single `protocolVersion` string
26
+ * the format carried before per-lexicon versioning: that string named no lexicon, so the
27
+ * caller's `expected` is the only name it can mean, and it maps to version 1. This is the
28
+ * one migration the evolution rule is allowed to carry forward forever, which is why it
29
+ * lives in a reader and not in a decoder that could drift.
30
+ */
31
+ export declare const readLexiconRef: (record: Record<string, unknown>, expected: LexiconName) => LexiconRef | undefined;
32
+ //# sourceMappingURL=decode.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"decode.d.ts","sourceRoot":"","sources":["../src/decode.ts"],"names":[],"mappings":"AAaA,OAAO,EAAiB,KAAK,WAAW,EAAE,KAAK,UAAU,EAAE,MAAM,cAAc,CAAA;AAE/E,kEAAkE;AAClE,eAAO,MAAM,QAAQ,UAAW,OAAO,KAAG,KAAK,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CACH,CAAA;AAEtE,yCAAyC;AACzC,eAAO,MAAM,GAAG,UAAW,OAAO,KAAG,MAAM,GAAG,SACC,CAAA;AAE/C,uBAAuB;AACvB,eAAO,MAAM,GAAG,UAAW,OAAO,KAAG,MAAM,GAAG,SAC2B,CAAA;AAEzE,kBAAkB;AAClB,eAAO,MAAM,GAAG,UAAW,OAAO,KAAG,MAAM,GAAG,SAC4B,CAAA;AAE1E,iBAAiB;AACjB,eAAO,MAAM,IAAI,UAAW,OAAO,KAAG,OAAO,GAAG,SACA,CAAA;AAEhD,sCAAsC;AACtC,eAAO,MAAM,KAAK,GAAI,CAAC,SAAS,MAAM,SAC7B,OAAO,WACL,aAAa,CAAC,CAAC,CAAC,KACxB,CAAC,GAAG,SAGQ,CAAA;AAEf;;;;GAIG;AACH,eAAO,MAAM,OAAO,GAAI,CAAC,SAChB,OAAO,QACR,CAAC,OAAO,EAAE,OAAO,KAAK,CAAC,GAAG,SAAS,KACxC,aAAa,CAAC,CAAC,CAAC,GAAG,SASrB,CAAA;AAED,2BAA2B;AAC3B,eAAO,MAAM,OAAO,UAAW,OAAO,KAAG,aAAa,CAAC,MAAM,CAAC,GAAG,SAAgC,CAAA;AAEjG;;;;;;;;GAQG;AACH,eAAO,MAAM,cAAc,WACjB,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,YACrB,WAAW,KACpB,UAAU,GAAG,SAWf,CAAA"}
package/dist/decode.js ADDED
@@ -0,0 +1,71 @@
1
+ /*
2
+ * Untrusted-input primitives.
3
+ *
4
+ * Every decoder in this package is a pure function from `unknown` to either a typed value
5
+ * or `undefined` — never a throw. An app calls one on whatever `JSON.parse` produced; a
6
+ * malformed record degrades to silence (a miss, an empty view), never to a crash and never
7
+ * to a false finding. The schema under `schema/` is what a WRITER must emit; these readers
8
+ * are deliberately more tolerant, so a record from a newer tool that added a field still
9
+ * parses here.
10
+ *
11
+ * Nothing here does I/O. The caller owns `JSON.parse`; this owns "is it a record".
12
+ */
13
+ import { isLexiconName } from "./lexicon.js";
14
+ /** A JSON object, as opposed to an array, `null`, or a scalar. */
15
+ export const isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
16
+ /** A string, including the empty one. */
17
+ export const str = (value) => typeof value === "string" ? value : undefined;
18
+ /** A finite number. */
19
+ export const num = (value) => typeof value === "number" && Number.isFinite(value) ? value : undefined;
20
+ /** An integer. */
21
+ export const int = (value) => typeof value === "number" && Number.isInteger(value) ? value : undefined;
22
+ /** A boolean. */
23
+ export const bool = (value) => typeof value === "boolean" ? value : undefined;
24
+ /** One of a closed set of strings. */
25
+ export const oneOf = (value, allowed) => typeof value === "string" && allowed.includes(value)
26
+ ? value
27
+ : undefined;
28
+ /**
29
+ * An array where every element decodes. A single bad element fails the whole array: a list
30
+ * with one unreadable entry is a record this reader cannot trust, and a partially-read list
31
+ * is a false finding waiting to happen.
32
+ */
33
+ export const arrayOf = (value, read) => {
34
+ if (!Array.isArray(value))
35
+ return undefined;
36
+ const out = [];
37
+ for (const element of value) {
38
+ const decoded = read(element);
39
+ if (decoded === undefined)
40
+ return undefined;
41
+ out.push(decoded);
42
+ }
43
+ return out;
44
+ };
45
+ /** An array of strings. */
46
+ export const strings = (value) => arrayOf(value, str);
47
+ /**
48
+ * The record's lexicon reference, checked against the name the caller expected.
49
+ *
50
+ * Prefers the explicit `lexicon` object. Falls back to the single `protocolVersion` string
51
+ * the format carried before per-lexicon versioning: that string named no lexicon, so the
52
+ * caller's `expected` is the only name it can mean, and it maps to version 1. This is the
53
+ * one migration the evolution rule is allowed to carry forward forever, which is why it
54
+ * lives in a reader and not in a decoder that could drift.
55
+ */
56
+ export const readLexiconRef = (record, expected) => {
57
+ if ("lexicon" in record) {
58
+ const ref = record.lexicon;
59
+ if (typeof ref !== "object" || ref === null || Array.isArray(ref))
60
+ return undefined;
61
+ const shape = ref;
62
+ if (!isLexiconName(shape.name) || shape.name !== expected)
63
+ return undefined;
64
+ const version = int(shape.version);
65
+ return version === undefined || version < 1 ? undefined : { name: expected, version };
66
+ }
67
+ if (typeof record.protocolVersion === "string")
68
+ return { name: expected, version: 1 };
69
+ return undefined;
70
+ };
71
+ //# sourceMappingURL=decode.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"decode.js","sourceRoot":"","sources":["../src/decode.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,aAAa,EAAqC,MAAM,cAAc,CAAA;AAE/E,kEAAkE;AAClE,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAC,KAAc,EAAoC,EAAE,CAC3E,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAA;AAEtE,yCAAyC;AACzC,MAAM,CAAC,MAAM,GAAG,GAAG,CAAC,KAAc,EAAsB,EAAE,CACxD,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAA;AAE/C,uBAAuB;AACvB,MAAM,CAAC,MAAM,GAAG,GAAG,CAAC,KAAc,EAAsB,EAAE,CACxD,OAAO,KAAK,KAAK,QAAQ,IAAI,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAA;AAEzE,kBAAkB;AAClB,MAAM,CAAC,MAAM,GAAG,GAAG,CAAC,KAAc,EAAsB,EAAE,CACxD,OAAO,KAAK,KAAK,QAAQ,IAAI,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAA;AAE1E,iBAAiB;AACjB,MAAM,CAAC,MAAM,IAAI,GAAG,CAAC,KAAc,EAAuB,EAAE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