@sous-io/sous 0.2.37 → 1.0.2

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 (244) hide show
  1. package/README.md +14 -256
  2. package/dist/bin.js +11 -0
  3. package/dist/sous.js +1094 -0
  4. package/docs/markdown/README.md +5 -4
  5. package/docs/markdown/_sidebar.md +21 -1
  6. package/docs/markdown/commands.md +294 -431
  7. package/docs/markdown/config-discovery.md +25 -14
  8. package/docs/markdown/config-inspection.md +53 -31
  9. package/docs/markdown/config-layers.md +168 -66
  10. package/docs/markdown/config-variables.md +44 -11
  11. package/docs/markdown/configuration.md +104 -17
  12. package/docs/markdown/design-principles.md +4 -1
  13. package/docs/markdown/repositories-authoring.md +30 -0
  14. package/docs/markdown/repositories-consuming.md +72 -14
  15. package/docs/markdown/repositories-file-formats.md +31 -13
  16. package/docs/markdown/repositories-providers.md +48 -57
  17. package/docs/markdown/repositories-quickstart.md +3 -2
  18. package/docs/markdown/repositories-troubleshooting.md +27 -1
  19. package/docs/markdown/repositories-variables.md +6 -1
  20. package/docs/markdown/repositories.md +18 -8
  21. package/package.json +48 -107
  22. package/recipes/core/sous-skills/skills/about-liquid-templates/SKILL.tpl.md +4 -6
  23. package/recipes/core/sous-skills/skills/about-liquid-templates/references/liquid-filters.tpl.md +2 -0
  24. package/recipes/core/sous-skills/skills/about-sous/SKILL.tpl.md +10 -9
  25. package/recipes/core/sous-skills/skills/about-sous-configuration/SKILL.tpl.md +35 -14
  26. package/recipes/core/sous-skills/skills/about-sous-recipes/SKILL.tpl.md +51 -20
  27. package/recipes/core/sous-skills/sous.recipe.yaml +1 -1
  28. package/sous.config.schema.json +351 -132
  29. package/bin/run.js +0 -51
  30. package/src/base-command.ts +0 -457
  31. package/src/commands/build.ts +0 -181
  32. package/src/commands/clear.ts +0 -79
  33. package/src/commands/compile.ts +0 -155
  34. package/src/commands/config/get.ts +0 -110
  35. package/src/commands/config/show.ts +0 -32
  36. package/src/commands/config/validate.ts +0 -53
  37. package/src/commands/help.ts +0 -46
  38. package/src/commands/init.ts +0 -289
  39. package/src/commands/launch.ts +0 -139
  40. package/src/commands/lock/rebuild.ts +0 -239
  41. package/src/commands/lock/show.ts +0 -115
  42. package/src/commands/namespace/list.ts +0 -138
  43. package/src/commands/namespace/show.ts +0 -130
  44. package/src/commands/prune.ts +0 -43
  45. package/src/commands/recipe/list.ts +0 -112
  46. package/src/commands/recipe/show.ts +0 -439
  47. package/src/commands/repo/add.ts +0 -145
  48. package/src/commands/repo/contribute.ts +0 -604
  49. package/src/commands/repo/gc.ts +0 -173
  50. package/src/commands/repo/init.ts +0 -136
  51. package/src/commands/repo/link.ts +0 -899
  52. package/src/commands/repo/list.ts +0 -236
  53. package/src/commands/repo/release.ts +0 -685
  54. package/src/commands/repo/remove.ts +0 -194
  55. package/src/commands/repo/search.ts +0 -243
  56. package/src/commands/repo/submit.ts +0 -341
  57. package/src/commands/repo/unlink.ts +0 -461
  58. package/src/commands/subscription/add.ts +0 -286
  59. package/src/commands/subscription/list.ts +0 -208
  60. package/src/commands/subscription/remove.ts +0 -182
  61. package/src/commands/subscription/update.ts +0 -216
  62. package/src/commands/update.ts +0 -178
  63. package/src/commands/vars/ask.ts +0 -417
  64. package/src/commands/vars/index.ts +0 -79
  65. package/src/commands/vars/list.ts +0 -67
  66. package/src/commands/vars/show.ts +0 -77
  67. package/src/config-command.ts +0 -30
  68. package/src/lib/build-preparation.ts +0 -128
  69. package/src/lib/build-service.ts +0 -580
  70. package/src/lib/config-discovery.ts +0 -378
  71. package/src/lib/config-inspect.ts +0 -145
  72. package/src/lib/config-kernel.mjs +0 -379
  73. package/src/lib/config-schema.ts +0 -401
  74. package/src/lib/env-file.ts +0 -328
  75. package/src/lib/env-local.ts +0 -212
  76. package/src/lib/errors.ts +0 -32
  77. package/src/lib/glob-pattern.ts +0 -24
  78. package/src/lib/include-resolver.ts +0 -523
  79. package/src/lib/interactive.ts +0 -165
  80. package/src/lib/markdown-compiler.ts +0 -947
  81. package/src/lib/package-info.ts +0 -25
  82. package/src/lib/pid-service.ts +0 -99
  83. package/src/lib/project-install.d.mts +0 -44
  84. package/src/lib/project-install.mjs +0 -234
  85. package/src/lib/project-scaffold/index.ts +0 -332
  86. package/src/lib/project-scaffold/templates.ts +0 -240
  87. package/src/lib/repos/catalog-display.ts +0 -215
  88. package/src/lib/repos/catalog-inputs.ts +0 -288
  89. package/src/lib/repos/catalog.ts +0 -842
  90. package/src/lib/repos/contribute.ts +0 -452
  91. package/src/lib/repos/core-recipe.ts +0 -105
  92. package/src/lib/repos/declarations.ts +0 -187
  93. package/src/lib/repos/defaults.ts +0 -175
  94. package/src/lib/repos/formats/common.ts +0 -440
  95. package/src/lib/repos/formats/index-file.ts +0 -253
  96. package/src/lib/repos/formats/links-map.ts +0 -98
  97. package/src/lib/repos/formats/lockfile.ts +0 -169
  98. package/src/lib/repos/formats/patterns.ts +0 -57
  99. package/src/lib/repos/formats/recipe-manifest.ts +0 -205
  100. package/src/lib/repos/formats/repo-manifest.ts +0 -97
  101. package/src/lib/repos/formats/store-entry.ts +0 -84
  102. package/src/lib/repos/formats/variable-definition.ts +0 -268
  103. package/src/lib/repos/freshness.ts +0 -264
  104. package/src/lib/repos/git-clone.ts +0 -850
  105. package/src/lib/repos/identity.ts +0 -89
  106. package/src/lib/repos/index.ts +0 -57
  107. package/src/lib/repos/links.ts +0 -356
  108. package/src/lib/repos/load-manifest.ts +0 -237
  109. package/src/lib/repos/lock-service.ts +0 -454
  110. package/src/lib/repos/locked-namespace-resolver.ts +0 -232
  111. package/src/lib/repos/locked-recipe-lookup.ts +0 -123
  112. package/src/lib/repos/locked-recipes.ts +0 -254
  113. package/src/lib/repos/managed-layer.ts +0 -422
  114. package/src/lib/repos/memories-hash-name.ts +0 -33
  115. package/src/lib/repos/namespace-resolver.ts +0 -527
  116. package/src/lib/repos/providers/base.ts +0 -268
  117. package/src/lib/repos/providers/git.ts +0 -245
  118. package/src/lib/repos/providers/github.ts +0 -589
  119. package/src/lib/repos/providers/gitlab.ts +0 -332
  120. package/src/lib/repos/providers/http.ts +0 -128
  121. package/src/lib/repos/providers/index-cache.ts +0 -421
  122. package/src/lib/repos/providers/index.ts +0 -106
  123. package/src/lib/repos/providers/local.ts +0 -410
  124. package/src/lib/repos/providers/provider.ts +0 -615
  125. package/src/lib/repos/recipe-config-layers.ts +0 -316
  126. package/src/lib/repos/recipe-key-matcher.ts +0 -62
  127. package/src/lib/repos/recipe-memories.ts +0 -178
  128. package/src/lib/repos/recipe-targets.ts +0 -236
  129. package/src/lib/repos/ref-search.ts +0 -46
  130. package/src/lib/repos/release/bump.ts +0 -161
  131. package/src/lib/repos/release/changelog.ts +0 -461
  132. package/src/lib/repos/release/git-state.ts +0 -460
  133. package/src/lib/repos/release/index-builder.ts +0 -1108
  134. package/src/lib/repos/release/index.ts +0 -19
  135. package/src/lib/repos/release/plan.ts +0 -521
  136. package/src/lib/repos/release/settle.ts +0 -154
  137. package/src/lib/repos/release/submissions.ts +0 -214
  138. package/src/lib/repos/release/submit-checkout.ts +0 -290
  139. package/src/lib/repos/release/submit-questions.ts +0 -153
  140. package/src/lib/repos/release/submit-service.ts +0 -898
  141. package/src/lib/repos/release/tags.ts +0 -239
  142. package/src/lib/repos/release/validate.ts +0 -463
  143. package/src/lib/repos/resolver.ts +0 -1028
  144. package/src/lib/repos/scaffold/index.ts +0 -245
  145. package/src/lib/repos/scaffold/templates.ts +0 -517
  146. package/src/lib/repos/seed.ts +0 -473
  147. package/src/lib/repos/store/contract.ts +0 -64
  148. package/src/lib/repos/store/hash.ts +0 -191
  149. package/src/lib/repos/store/recipe-store.ts +0 -599
  150. package/src/lib/repos/store/settings.ts +0 -58
  151. package/src/lib/repos/subscription-service.ts +0 -3859
  152. package/src/lib/repos/trust.ts +0 -447
  153. package/src/lib/repos/update-plan.ts +0 -235
  154. package/src/lib/self-update/index.ts +0 -14
  155. package/src/lib/self-update/installs.ts +0 -413
  156. package/src/lib/self-update/managers.ts +0 -126
  157. package/src/lib/self-update/plan.ts +0 -315
  158. package/src/lib/self-update/registry.ts +0 -99
  159. package/src/lib/self-update/run.ts +0 -506
  160. package/src/lib/self-update/versions.ts +0 -243
  161. package/src/lib/settings.ts +0 -1107
  162. package/src/lib/sous-home.ts +0 -104
  163. package/src/lib/state.ts +0 -167
  164. package/src/lib/vars/answers.ts +0 -192
  165. package/src/lib/vars/ask.ts +0 -1152
  166. package/src/lib/vars/definition-source.ts +0 -261
  167. package/src/lib/vars/display.ts +0 -231
  168. package/src/lib/vars/index.ts +0 -20
  169. package/src/lib/vars/ladder.ts +0 -282
  170. package/src/lib/vars/mappings.ts +0 -260
  171. package/src/lib/vars/names.ts +0 -94
  172. package/src/lib/vars/preanswers.ts +0 -395
  173. package/src/lib/vars/question-plan.ts +0 -241
  174. package/src/lib/vars/report.ts +0 -228
  175. package/src/lib/vars/safe-regex.ts +0 -235
  176. package/src/lib/vars/secrets.ts +0 -131
  177. package/src/lib/vars/validate.ts +0 -312
  178. package/src/lib/version-report.ts +0 -90
  179. package/src/lib/watch-loop.ts +0 -148
  180. package/src/lib/watch-service.ts +0 -116
  181. package/src/services/ref-resolver/container.ts +0 -107
  182. package/src/services/ref-resolver/dependency.ts +0 -60
  183. package/src/services/ref-resolver/format.ts +0 -197
  184. package/src/services/ref-resolver/glob.ts +0 -115
  185. package/src/services/ref-resolver/hash-names.ts +0 -155
  186. package/src/services/ref-resolver/index.ts +0 -55
  187. package/src/services/ref-resolver/injectable.ts +0 -36
  188. package/src/services/ref-resolver/location.ts +0 -62
  189. package/src/services/ref-resolver/lookups/cached-index-lookup.ts +0 -53
  190. package/src/services/ref-resolver/lookups/catalog-lookup.ts +0 -23
  191. package/src/services/ref-resolver/lookups/catalog-matcher.ts +0 -261
  192. package/src/services/ref-resolver/lookups/chained-lookup.ts +0 -27
  193. package/src/services/ref-resolver/lookups/env-var-lookup.ts +0 -65
  194. package/src/services/ref-resolver/lookups/fetched-index-lookup.ts +0 -150
  195. package/src/services/ref-resolver/lookups/recorded-dependency-lookup.ts +0 -62
  196. package/src/services/ref-resolver/lookups/ref-lookup.ts +0 -54
  197. package/src/services/ref-resolver/lookups/variable-lookup.ts +0 -123
  198. package/src/services/ref-resolver/named-refs.ts +0 -144
  199. package/src/services/ref-resolver/parser/env-var-splitter.ts +0 -27
  200. package/src/services/ref-resolver/parser/location-splitter.ts +0 -239
  201. package/src/services/ref-resolver/parser/name-path-splitter.ts +0 -200
  202. package/src/services/ref-resolver/parser/partial-ref.ts +0 -84
  203. package/src/services/ref-resolver/parser/query-splitter.ts +0 -61
  204. package/src/services/ref-resolver/parser/range-splitter.ts +0 -52
  205. package/src/services/ref-resolver/parser/ref-parser.ts +0 -115
  206. package/src/services/ref-resolver/parser/repo-qualifier-splitter.ts +0 -51
  207. package/src/services/ref-resolver/parts.ts +0 -115
  208. package/src/services/ref-resolver/pruners/command-line-pruner.ts +0 -47
  209. package/src/services/ref-resolver/pruners/include-pruner.ts +0 -66
  210. package/src/services/ref-resolver/pruners/manifest-pruner.ts +0 -130
  211. package/src/services/ref-resolver/pruners/ref-pruner.ts +0 -135
  212. package/src/services/ref-resolver/pruners/rule-helpers.ts +0 -44
  213. package/src/services/ref-resolver/pruners/stored-key-pruner.ts +0 -136
  214. package/src/services/ref-resolver/ref-helpers.ts +0 -62
  215. package/src/services/ref-resolver/ref-picker-service.ts +0 -204
  216. package/src/services/ref-resolver/ref-report.ts +0 -84
  217. package/src/services/ref-resolver/ref-resolve-arguments.ts +0 -47
  218. package/src/services/ref-resolver/ref-resolve-result.ts +0 -36
  219. package/src/services/ref-resolver/ref-resolver-service.ts +0 -323
  220. package/src/services/ref-resolver/source.ts +0 -48
  221. package/src/services/ref-resolver/tokens.ts +0 -25
  222. package/src/services/ref-resolver/types.ts +0 -155
  223. package/src/templating/filters/bullet-list.ts +0 -9
  224. package/src/templating/filters/index.ts +0 -8
  225. package/src/templating/init-liquid-engine.ts +0 -139
  226. package/src/templating/lib/glob-files.ts +0 -74
  227. package/src/templating/lib/import-export.ts +0 -32
  228. package/src/templating/lib/secret-scope.ts +0 -41
  229. package/src/templating/lib/tag-args.ts +0 -19
  230. package/src/templating/tags/exportScalarVarsJs.ts +0 -46
  231. package/src/templating/tags/getFiles.ts +0 -89
  232. package/src/templating/tags/index.ts +0 -14
  233. package/src/templating/tags/listFiles.ts +0 -54
  234. package/src/templating/tags/showVars.ts +0 -28
  235. package/src/utils/choice-prompt.ts +0 -143
  236. package/src/utils/command-errors.ts +0 -186
  237. package/src/utils/command-help.ts +0 -45
  238. package/src/utils/confirm-prompt.ts +0 -110
  239. package/src/utils/flags.ts +0 -177
  240. package/src/utils/formatting.ts +0 -849
  241. package/src/utils/prompts.ts +0 -53
  242. package/src/utils/sous-directory.ts +0 -245
  243. package/src/utils/table.ts +0 -603
  244. package/src/utils/value-prompt.ts +0 -119
@@ -1,401 +0,0 @@
1
- /**
2
- * Zod schema for a merged sous config.
3
- *
4
- * This mirrors the hand-written `Settings` / `RawProjectCompilation` /
5
- * `RawTarget` / `RawOutput` / `RawRuntimeContext` / `ToolConfig` types in
6
- * settings.ts — those remain the exported TypeScript types; this schema is the
7
- * RUNTIME validator. Keep the two in sync: when a config field changes in
8
- * settings.ts, change it here too.
9
- *
10
- * Every object level is STRICT (unknown keys are rejected), so a typo like
11
- * `compilaton` is caught the moment the merged config is loaded rather than
12
- * silently ignored. Validation runs on the MERGED config only (in
13
- * loadSettingsWithLayers, after the kernel merges every conf.d layer and after
14
- * assertFlatConfig); a single conf.d fragment need not be a complete config.
15
- *
16
- * The schema also drives `npm run schema:build`, which emits the committed
17
- * `sous.config.schema.json` artifact via `z.toJSONSchema`.
18
- */
19
-
20
- import { z } from "zod";
21
- import { ConfigError } from "./errors.js";
22
- import { compileRecipeKeyMatcher } from "./repos/recipe-key-matcher.js";
23
- import { repoUrlSchema, semverRangeSchema } from "./repos/formats/common.js";
24
- import { REF_KEY_PATTERN, REPO_NAME_PATTERN } from "./repos/formats/patterns.js";
25
- import type { Settings } from "./settings.js";
26
-
27
- /** The only config version this sous understands. */
28
- export const SUPPORTED_CONFIG_VERSION = 1;
29
-
30
- /** A record of string → string (used for _env and every _vars block). */
31
- const stringRecord = z.record(z.string(), z.string());
32
-
33
- const outputSchema = z
34
- .object({
35
- _if: z.record(z.string(), z.object({ eq: z.string() }).strict()).optional(),
36
- _vars: stringRecord.optional(),
37
- destinationFile: z.string().optional(),
38
- destinationDir: z.string().optional(),
39
- })
40
- .strict();
41
-
42
- const runtimeContextSchema = z
43
- .object({
44
- gitRoot: z.string(),
45
- outputPath: z.string(),
46
- taskFileRoot: z.string(),
47
- branchPattern: z.string().optional(),
48
- })
49
- .strict();
50
-
51
- const targetSchema = z
52
- .object({
53
- _vars: stringRecord.optional(),
54
- entryPoint: z.string().optional(),
55
- entryGlob: z.string().optional(),
56
- globBase: z.string().optional(),
57
- generateRuntimeContext: z.boolean().optional(),
58
- outputs: z.array(outputSchema),
59
- })
60
- .strict()
61
- .refine((t) => (t.entryPoint !== undefined) !== (t.entryGlob !== undefined), {
62
- message: "a target must have exactly one of 'entryPoint' or 'entryGlob'",
63
- });
64
-
65
- const compilationSchema = z
66
- .object({
67
- _vars: stringRecord.optional(),
68
- includeSourceComments: z.boolean().optional(),
69
- targets: z.array(targetSchema),
70
- })
71
- .strict();
72
-
73
- const toolSchema = z
74
- .object({
75
- command: z.string(),
76
- args: z.array(z.string()).optional(),
77
- promptFile: z.string().optional(),
78
- })
79
- .strict();
80
-
81
- // --- Repositories -------------------------------------------------------------------------------
82
-
83
- /**
84
- * One trusted repository, keyed by the short name refs use in the `repo:`
85
- * qualifier. Adding a repo IS trusting it: `sous repo add` writes the entry
86
- * into the machine-written `conf.d/500-repos.jsonc` layer, and removing the
87
- * entry withdraws the trust. A user may also hand-write `repos:` in the primary
88
- * config; the two layers merge like anything else.
89
- */
90
- const repoEntrySchema = z
91
- .object({
92
- /**
93
- * Where the repository lives. A hosted repository is named by its URL; a
94
- * repository on this machine, which the `local` provider reads, is named by
95
- * an absolute path or the same path in `file:///...` form.
96
- */
97
- url: repoUrlSchema,
98
- /**
99
- * Whether the repository takes part in anything at all. Defaults to true.
100
- * Setting it to false is how a project opts out of a repository sous
101
- * provides itself (the official `sous-recipes`), without having to delete an
102
- * entry it never wrote.
103
- */
104
- enabled: z.boolean().optional(),
105
- /**
106
- * Which provider handles it. Inferred from the URL when omitted; set it
107
- * explicitly for a self-hosted instance the URL does not give away.
108
- * `local` is a repository on this machine, for local development and tests;
109
- * its trust semantics are identical to a hosted one.
110
- */
111
- provider: z.enum(["github", "gitlab", "local"]).optional(),
112
- /**
113
- * When true, sous installs a newer in-range version whenever one exists
114
- * rather than holding the locked one. The flag never widens the range a
115
- * subscription or a dependency declared.
116
- */
117
- alwaysPull: z.boolean().optional(),
118
- /** When the repo was added, for provenance. */
119
- addedAt: z.string().optional(),
120
- /**
121
- * Who required the repo: the literal "user" for a deliberate add, or the ref
122
- * of the recipe whose dependency pulled it in. Removal hygiene reads this.
123
- */
124
- addedBy: z.string().optional(),
125
- })
126
- .strict();
127
-
128
- /**
129
- * One subscription, keyed by a ref key: a bare namespace (every recipe in it,
130
- * including ones published later) or `namespace/recipe`. Written by
131
- * `sous subscribe` into the machine-written `conf.d/510-subscriptions.jsonc`
132
- * layer, and hand-writable in the primary config.
133
- */
134
- const subscriptionEntrySchema = z
135
- .object({
136
- /**
137
- * Whether the subscription takes part in anything at all. Defaults to true.
138
- * Setting it to false is how a project opts out of the `core` namespace sous
139
- * subscribes every project to.
140
- */
141
- enabled: z.boolean().optional(),
142
- /** The semantic version range to resolve within. Defaults to "*". */
143
- range: semverRangeSchema.optional(),
144
- /** When true, prerelease versions take part in range matching. */
145
- prerelease: z.boolean().optional(),
146
- /** Per-subscription form of the repo-level always-pull flag. */
147
- alwaysPull: z.boolean().optional(),
148
- /** When the subscription was added, for provenance. */
149
- addedAt: z.string().optional(),
150
- /** Who required it: "user", or the ref of the recipe that co-subscribed it. */
151
- addedBy: z.string().optional(),
152
- })
153
- .strict();
154
-
155
- /**
156
- * Knobs for the machine-wide recipe store under the user-level sous directory.
157
- * Every value here is a number the user can change; the numbers sous ships are
158
- * defaults, not assumptions. Phase 2 applies them, so all three are optional
159
- * here and the defaults live with the store itself: one gigabyte for maxBytes,
160
- * 300 seconds for freshnessSeconds, and 300 seconds for watchPollSeconds.
161
- */
162
- const storeSchema = z
163
- .object({
164
- /** Size cap for the store, past which least-recently-used entries are collected. */
165
- maxBytes: z.number().int().positive().optional(),
166
- /**
167
- * How long a fetched index stays fresh. A non-watch build checks upstream
168
- * only once this window has lapsed, and a failed check never breaks a
169
- * build; the last good answer stands.
170
- */
171
- freshnessSeconds: z.number().int().nonnegative().optional(),
172
- /** How often watch mode polls upstream for a newer in-range version. */
173
- watchPollSeconds: z.number().int().nonnegative().optional(),
174
- })
175
- .strict();
176
-
177
- /**
178
- * One list of recipe keys: each entry is a glob over `namespace/recipe` keys, or
179
- * a regular expression written between two slashes (`/^tool-usage\//`). A
180
- * regular expression that does not compile is an error naming the key and the
181
- * value.
182
- */
183
- function recipeKeyListSchema(where: string) {
184
- return z.array(z.string()).superRefine((entries, context) => {
185
- entries.forEach((entry, index) => {
186
- try {
187
- compileRecipeKeyMatcher([entry], `${where}[${index}]`);
188
- } catch (error) {
189
- context.addIssue({
190
- code: "custom",
191
- path: [index],
192
- message: error instanceof Error ? error.message : String(error),
193
- });
194
- }
195
- });
196
- });
197
- }
198
-
199
- /**
200
- * What a project does with the content kinds the subscribed recipes publish, one
201
- * block per kind.
202
- *
203
- * `skills.outputs` lists the destination directories recipe skill bundles are
204
- * written into. Each is `${var}` substituted like any other config path, and
205
- * several may be named so the same recipe feeds more than one agent directory
206
- * (`.claude/skills` and `.codex/skills`, say). The default is
207
- * `<project root>/.claude/skills`, the project root being the parent of the
208
- * discovered `.sous/` directory.
209
- *
210
- * `memories.first` and `memories.exclude` shape which recipe memories an
211
- * `@#memories` include pulls in and in what order: recipes matching `first` lead,
212
- * and recipes matching `exclude` are left out. Each entry is a glob over
213
- * `namespace/recipe` keys, or a regular expression written between two slashes.
214
- *
215
- * A recipe's `config` contents are not listed here; they are loaded as config
216
- * layers rather than written anywhere.
217
- */
218
- const recipesSchema = z
219
- .object({
220
- /** Where recipe skill bundles are written. */
221
- skills: z
222
- .object({
223
- /** Destination directories, `${var}` substituted. */
224
- outputs: z.array(z.string()).optional(),
225
- })
226
- .strict()
227
- .optional(),
228
- /** Which recipe memories an `@#memories` include pulls in, and in what order. */
229
- memories: z
230
- .object({
231
- /** Recipes whose memories come first. */
232
- first: recipeKeyListSchema("recipes.memories.first").optional(),
233
- /** Recipes whose memories are left out. */
234
- exclude: recipeKeyListSchema("recipes.memories.exclude").optional(),
235
- })
236
- .strict()
237
- .optional(),
238
- })
239
- .strict();
240
-
241
- // --- Variable mappings --------------------------------------------------------------------------
242
-
243
- /**
244
- * A mapping record's target: one variable, named in full, as
245
- * `namespace/recipe/variableName` with an optional `repo:` qualifier. Mapping
246
- * records are the top rung of the answer resolution ladder and the universal
247
- * resolver when two recipes want the same environment variable name.
248
- */
249
- const mappingTargetSchema = z
250
- .string()
251
- .regex(
252
- /^([a-z][a-z0-9-]*:)?[a-z][a-z0-9-]*\/[a-z][a-z0-9-]*\/[a-z][a-zA-Z0-9]*$/,
253
- "a variable mapping target must be written as 'namespace/recipe/variableName', " +
254
- "optionally qualified with a repository as 'repo:namespace/recipe/variableName'"
255
- );
256
-
257
- /**
258
- * The full merged-config schema. `version`, when present, must be exactly
259
- * `SUPPORTED_CONFIG_VERSION` — but validateSettings pre-checks it with a clearer
260
- * message before this schema runs, so a bad version never reaches the generic
261
- * literal error here.
262
- */
263
- export const settingsSchema = z
264
- .object({
265
- // Allowed so a JSON config can bind itself to the shipped
266
- // `sous.config.schema.json` via the standard `"$schema": "..."` property
267
- // for editor autocompletion / external validation. Editors treat `$schema`
268
- // as reserved and never flag it, so rejecting it here would break the
269
- // documented workflow. sous itself ignores the value.
270
- $schema: z.string().optional(),
271
- version: z.literal(SUPPORTED_CONFIG_VERSION).optional(),
272
- _env: stringRecord.optional(),
273
- _vars: stringRecord.optional(),
274
- _aliases: z
275
- .record(z.string(), z.union([z.string(), z.array(z.string())]))
276
- .optional(),
277
- name: z.string().optional(),
278
- compilation: compilationSchema.optional(),
279
- runtimeContext: runtimeContextSchema.optional(),
280
- tools: z.record(z.string(), toolSchema).optional(),
281
- /** Trusted repositories, keyed by the short name refs use. */
282
- repos: z
283
- .record(
284
- z
285
- .string()
286
- .regex(
287
- REPO_NAME_PATTERN,
288
- "a repo name must be lowercase kebab-case: a letter, then letters, " +
289
- "digits or hyphens"
290
- ),
291
- repoEntrySchema
292
- )
293
- .optional(),
294
- /** Subscriptions, keyed by ref key (`namespace` or `namespace/recipe`). */
295
- subscriptions: z
296
- .record(
297
- z
298
- .string()
299
- .regex(
300
- REF_KEY_PATTERN,
301
- "a subscription key must be a namespace such as 'workflow', or a " +
302
- "namespace and recipe such as 'workflow/task-files', with no repo " +
303
- "qualifier and no version range"
304
- ),
305
- subscriptionEntrySchema
306
- )
307
- .optional(),
308
- /** Knobs for the machine-wide recipe store. */
309
- store: storeSchema.optional(),
310
- /** What the project does with each content kind its subscribed recipes publish. */
311
- recipes: recipesSchema.optional(),
312
- /**
313
- * Variable mapping records, keyed by environment variable name. Each entry
314
- * binds that name to one recipe variable, which is how an answer is stored
315
- * under a name of your choosing when the generated names are taken. Written
316
- * by `sous vars ask` into `conf.d/520-var-mappings.jsonc`, and hand-writable
317
- * in the primary config.
318
- */
319
- varMappings: z
320
- .record(
321
- z
322
- .string()
323
- .regex(
324
- /^[A-Z][A-Z0-9_]*$/,
325
- "an environment variable name must be upper snake case: a capital " +
326
- "letter, then capitals, digits or underscores"
327
- ),
328
- mappingTargetSchema
329
- )
330
- .optional(),
331
- })
332
- .strict();
333
-
334
- /** Renders a zod issue path (e.g. `["compilation","targets",0,"entryPoint"]`) as `compilation.targets[0].entryPoint`. */
335
- function formatIssuePath(parts: ReadonlyArray<PropertyKey>): string {
336
- let out = "";
337
- for (const part of parts) {
338
- if (typeof part === "number") out += `[${part}]`;
339
- else out += out.length > 0 ? `.${String(part)}` : String(part);
340
- }
341
- return out;
342
- }
343
-
344
- /**
345
- * Turns a ZodError into a readable, per-issue ConfigError message. Never leaks
346
- * the raw zod JSON dump. Unknown-key issues are surfaced as likely typos and
347
- * name the config file.
348
- */
349
- function formatZodError(error: z.ZodError, configPath: string): ConfigError {
350
- const lines: string[] = [`Invalid sous config at ${configPath}:`];
351
-
352
- for (const issue of error.issues) {
353
- const where = formatIssuePath(issue.path);
354
- if (issue.code === "unrecognized_keys") {
355
- const keys = issue.keys.map((k) => `'${k}'`).join(", ");
356
- const loc = where.length > 0 ? `under '${where}'` : "at the top level";
357
- lines.push(
358
- ` - unknown key(s) ${keys} ${loc} — likely a typo. Check ${configPath}.`
359
- );
360
- } else if (issue.code === "invalid_key") {
361
- // zod reports a bad record KEY as a bare "Invalid key in record" and hides
362
- // the reason in a nested issue list. Surface the reason, since that is the
363
- // part telling the user how to fix the key.
364
- const reasons = issue.issues.map((inner) => inner.message).join("; ");
365
- lines.push(` - ${where}: invalid key; ${reasons}`);
366
- } else {
367
- lines.push(` - ${where.length > 0 ? where : "(root)"}: ${issue.message}`);
368
- }
369
- }
370
-
371
- return new ConfigError(lines.join("\n"));
372
- }
373
-
374
- /**
375
- * Validates a merged config object against the schema, returning it typed as
376
- * `Settings`. Throws a ConfigError (never a raw ZodError) on any problem.
377
- *
378
- * @param raw - The merged config produced by the kernel (post assertFlatConfig).
379
- * @param configPath - The primary config file path, named in error messages.
380
- */
381
- export function validateSettings(raw: unknown, configPath: string): Settings {
382
- // Version gets a dedicated, friendlier message than the generic literal error.
383
- if (raw !== null && typeof raw === "object" && "version" in raw) {
384
- const version = (raw as { version: unknown }).version;
385
- if (version !== SUPPORTED_CONFIG_VERSION) {
386
- throw new ConfigError(
387
- `Config at ${configPath} declares version ${JSON.stringify(version)}, which is not ` +
388
- `supported by this version of sous.\n` +
389
- ` This sous understands config version ${SUPPORTED_CONFIG_VERSION}. Omit the ` +
390
- `'version' field or set it to ${SUPPORTED_CONFIG_VERSION}.`
391
- );
392
- }
393
- }
394
-
395
- const result = settingsSchema.safeParse(raw);
396
- if (!result.success) {
397
- throw formatZodError(result.error, configPath);
398
- }
399
-
400
- return result.data as Settings;
401
- }