@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,236 +0,0 @@
1
- /**
2
- * Turning subscribed recipes into compile targets.
3
- *
4
- * A recipe's manifest lists what it contributes: skills, memories, prompts and
5
- * config layers. Only skills are copied into the project, compiled exactly the
6
- * way a project's own `entryGlob` target is: the recipe's directory is the glob
7
- * root, the static part of each include pattern is the base the output tree
8
- * mirrors, and the `.tpl.` convention applies unchanged. Memories reach an agent
9
- * through include lines, never as copied files, and config layers are loaded
10
- * rather than written.
11
- *
12
- * Two rules decide what is compiled at all:
13
- *
14
- * - Only recipes held through `subscribes` contribute files. A recipe held
15
- * only through `depends` is fetched, pinned and addressable from the recipe
16
- * that declared it, but its files never enter the project's output; that is
17
- * the whole difference between the two dependency kinds.
18
- * - Skills go to `recipes.skills.outputs`, which defaults to
19
- * `.claude/skills` because that is where every agent looks. Prompts have no
20
- * destination yet, so a recipe that publishes them is skipped with ONE
21
- * warning naming the `recipes` config key.
22
- *
23
- * A recipe's `config` contents are not handled here. They are config layers, and
24
- * config layers are loaded before any of this runs; see
25
- * `listRecipeConfigLayers` in `config-discovery.ts`.
26
- */
27
-
28
- import fs from "node:fs";
29
- import path from "node:path";
30
- import { globSync } from "glob";
31
- import type { CompilationTarget } from "../markdown-compiler.js";
32
- import { inferGlobBase } from "../markdown-compiler.js";
33
- import { toGlobPattern } from "../glob-pattern.js";
34
- import type { Settings, VarScope } from "../settings.js";
35
- import { normalizeConfigPath, substituteVarsStrict } from "../settings.js";
36
- import type { ContentKind } from "./formats/recipe-manifest.js";
37
- import {
38
- listLockedRecipes,
39
- readRecipeManifestIn,
40
- type LockedRecipeLocation,
41
- } from "./locked-recipes.js";
42
-
43
- /**
44
- * The content kinds whose files are copied into a project. `config` is a layer,
45
- * and `memories` are reached by include lines rather than copied.
46
- */
47
- export const WRITABLE_CONTENT_KINDS = ["skills"] as const;
48
-
49
- /** One content kind whose files land somewhere in the project. */
50
- export type WritableContentKind = (typeof WRITABLE_CONTENT_KINDS)[number];
51
-
52
- /** How the recipe targets are built. */
53
- export type RecipeTargetOptions = {
54
- /** The project's `.sous/` directory. */
55
- sousDir: string;
56
- /** The merged project config, read for `recipes.skills.outputs`. */
57
- settings: Settings;
58
- /** The resolved settings scope, used to substitute `${var}` in destinations. */
59
- scope?: VarScope;
60
- /**
61
- * The scope one recipe's own files render with. A recipe's answers to its own
62
- * questions are laid over the project scope there, so a recipe sees its own
63
- * answer even when another recipe asks the same name. Defaults to `scope`.
64
- */
65
- scopeFor?: (recipe: LockedRecipeLocation) => VarScope;
66
- /** The environment to read; decides where the store is. */
67
- env?: NodeJS.ProcessEnv;
68
- /** The locked recipes, when the caller has already located them. */
69
- locked?: LockedRecipeLocation[];
70
- };
71
-
72
- /** What the recipe targets add to a build. */
73
- export type RecipeTargets = {
74
- /** One compile target per file a subscribed recipe contributes. */
75
- targets: CompilationTarget[];
76
- /** Every destination directory the targets write into, for prune's benefit. */
77
- destinations: string[];
78
- /** Directories a watch should follow: the linked checkouts contributing files. */
79
- watchDirs: string[];
80
- /** Complete, plain-language sentences a build should print before it compiles. */
81
- warnings: string[];
82
- /**
83
- * Every variable name a recipe declares `secret: true`, which the scope-dumping
84
- * template tags hide. Set by the build from the resolved answers.
85
- */
86
- secretVariables?: string[];
87
- };
88
-
89
- /**
90
- * The project's root directory: the parent of its `.sous/` directory. Used only
91
- * for the one destination sous defaults, `.claude/skills`.
92
- *
93
- * @param sousDir - The project's `.sous/` directory.
94
- */
95
- export function projectRootFor(sousDir: string): string {
96
- return path.dirname(path.resolve(sousDir));
97
- }
98
-
99
- /**
100
- * Where one content kind's files are written, with `${var}` substituted and each
101
- * path normalized. An empty list means "nowhere configured", which is what makes
102
- * the caller warn and skip.
103
- *
104
- * @param kind - The content kind.
105
- * @param options - The project's config, scope and `.sous/` directory.
106
- */
107
- export function destinationsFor(
108
- kind: WritableContentKind,
109
- options: RecipeTargetOptions
110
- ): string[] {
111
- const configured = options.settings.recipes?.[kind]?.outputs;
112
-
113
- if (configured === undefined || configured.length === 0) {
114
- // `.claude/skills` is where every agent looks, so it is worth defaulting.
115
- // Nothing else has an obvious home.
116
- return kind === "skills"
117
- ? [path.join(projectRootFor(options.sousDir), ".claude", "skills")]
118
- : [];
119
- }
120
-
121
- return configured.map((destination, index) =>
122
- normalizeConfigPath(
123
- substituteVarsStrict(
124
- destination,
125
- options.scope ?? {},
126
- `recipes.${kind}.outputs[${index}]`
127
- )
128
- )
129
- );
130
- }
131
-
132
- /**
133
- * Builds the compile targets that the recipes this project subscribes to
134
- * contribute. Returns an empty result for a project that locks nothing, so a
135
- * project using no repositories pays nothing for this.
136
- *
137
- * @param options - The project's `.sous/` directory, its config and its scope.
138
- */
139
- export function buildRecipeTargets(options: RecipeTargetOptions): RecipeTargets {
140
- const locked =
141
- options.locked ??
142
- listLockedRecipes({
143
- sousDir: options.sousDir,
144
- ...(options.env === undefined ? {} : { env: options.env }),
145
- });
146
-
147
- const result: RecipeTargets = {
148
- targets: [],
149
- destinations: [],
150
- watchDirs: [],
151
- warnings: [],
152
- };
153
- if (locked.length === 0) return result;
154
-
155
- const destinationCache = new Map<WritableContentKind, string[]>();
156
- let skippedPrompts = false;
157
- const destinations = new Set<string>();
158
- const watchDirs = new Set<string>();
159
-
160
- for (const recipe of locked) {
161
- // Only a co-subscription contributes files; a build dependency is fetched
162
- // and addressable, and that is all.
163
- if (recipe.kind !== "subscribes") continue;
164
- if (!recipe.present) continue;
165
-
166
- const manifest = readRecipeManifestIn(recipe.dir);
167
- if (manifest === undefined) continue;
168
-
169
- for (const content of manifest.contents) {
170
- const kind = content.kind;
171
- if (kind === "prompts") {
172
- skippedPrompts = true;
173
- continue;
174
- }
175
- if (!isWritableKind(kind)) continue;
176
-
177
- if (!destinationCache.has(kind)) {
178
- destinationCache.set(kind, destinationsFor(kind, options));
179
- }
180
- const kindDestinations = destinationCache.get(kind)!;
181
-
182
- if (kindDestinations.length === 0) continue;
183
-
184
- for (const destination of kindDestinations) destinations.add(destination);
185
- if (recipe.linked) watchDirs.add(recipe.dir);
186
-
187
- const recipeScope = options.scopeFor?.(recipe) ?? options.scope ?? {};
188
-
189
- const ignore = (content.exclude ?? []).map((pattern) =>
190
- toGlobPattern(path.join(recipe.dir, pattern))
191
- );
192
-
193
- for (const include of content.include) {
194
- const pattern = toGlobPattern(path.join(recipe.dir, include));
195
- const matched = globSync(pattern, { absolute: true, ignore }).filter(isFile);
196
- const globBase = normalizeConfigPath(inferGlobBase(pattern));
197
-
198
- for (const filePath of matched) {
199
- result.targets.push({
200
- rootInputPath: filePath,
201
- globBase,
202
- outputs: kindDestinations.map((destination) => ({
203
- destinationDir: destination,
204
- vars: recipeScope,
205
- })),
206
- });
207
- }
208
- }
209
- }
210
- }
211
-
212
- if (skippedPrompts) {
213
- result.warnings.push(
214
- `Some subscribed recipes contribute prompts, and the 'recipes' key of your sous ` +
215
- `config has no destination for prompts yet, so they were skipped.`
216
- );
217
- }
218
-
219
- result.destinations = [...destinations].sort();
220
- result.watchDirs = [...watchDirs].sort();
221
- return result;
222
- }
223
-
224
- /** True when a content kind produces files rather than a config layer. */
225
- function isWritableKind(kind: ContentKind): kind is WritableContentKind {
226
- return (WRITABLE_CONTENT_KINDS as readonly string[]).includes(kind);
227
- }
228
-
229
- /** True when the path is a regular file. */
230
- function isFile(candidate: string): boolean {
231
- try {
232
- return fs.statSync(candidate).isFile();
233
- } catch {
234
- return false;
235
- }
236
- }
@@ -1,46 +0,0 @@
1
- /**
2
- * What was searched when a ref matched nothing.
3
- *
4
- * Resolving a ref itself lives in `src/services/ref-resolver/`, which every command shares.
5
- * All that is left here is the one thing only a repository search can say: which
6
- * repositories were actually looked in, and which were trusted but unreadable,
7
- * so the reader can tell "the name is wrong" from "the repository holding it
8
- * was never fetched".
9
- */
10
-
11
- import type { IndexFile } from "./formats/index-file.js";
12
-
13
- /** The repositories a ref was searched in, and the indexes that were available. */
14
- export type IndexSearchInputs = {
15
- /** The name that was searched for. */
16
- name: string;
17
- /** The repositories the search covered, in search order. */
18
- repoOrder: string[];
19
- /** The cached index of each repository, keyed by short name. */
20
- indexes: Map<string, IndexFile>;
21
- };
22
-
23
- /**
24
- * The lines a name that matched nothing is explained with: every repository
25
- * whose index was searched, and every trusted repository whose index could not
26
- * be read.
27
- *
28
- * @param inputs - The same inputs the search was given.
29
- */
30
- export function describeIndexSearch(inputs: IndexSearchInputs): string[] {
31
- const searched = inputs.repoOrder.filter((repo) => inputs.indexes.has(repo));
32
- const missing = inputs.repoOrder.filter((repo) => !inputs.indexes.has(repo));
33
-
34
- const lines = [
35
- searched.length === 0
36
- ? ` No repository index could be read, so there was nothing to search.`
37
- : ` Searched the namespaces and the recipe names of: ${searched.join(", ")}.`,
38
- ];
39
- if (missing.length > 0) {
40
- lines.push(
41
- ` These repositories are trusted but their index could not be read, so nothing ` +
42
- `in them was searched: ${missing.join(", ")}.`
43
- );
44
- }
45
- return lines;
46
- }
@@ -1,161 +0,0 @@
1
- /**
2
- * Raising, or setting, the version in a recipe manifest.
3
- *
4
- * A recipe manifest is HAND-WRITTEN, and the scaffold sous writes is mostly
5
- * comments, so a version bump must give the file back to its author looking the
6
- * way they left it. Both supported formats are edited in place rather than
7
- * re-serialized from a parsed object: YAML through the `yaml` package's
8
- * document model, which keeps comments and layout, and JSON through
9
- * `jsonc-parser`, which edits the exact byte range of the value and leaves
10
- * everything else, comments included, untouched.
11
- */
12
-
13
- import fs from "node:fs";
14
- import path from "node:path";
15
- import semver from "semver";
16
- import YAML from "yaml";
17
- import { applyEdits, modify } from "jsonc-parser";
18
- import { ConfigError } from "../../errors.js";
19
- import { parseJsoncText } from "../load-manifest.js";
20
-
21
- /** How far a version is being raised. */
22
- export const BUMP_LEVELS = ["patch", "minor", "major", "prerelease"] as const;
23
-
24
- /** One of the ways `sous repo release --bump` can raise a version. */
25
- export type BumpLevel = (typeof BUMP_LEVELS)[number];
26
-
27
- /** What one bump did. */
28
- export type BumpResult = {
29
- /** The manifest that was rewritten. */
30
- manifestPath: string;
31
- /** The version it declared before. */
32
- from: string;
33
- /** The version it declares now. */
34
- to: string;
35
- };
36
-
37
- /**
38
- * The version one level up from the current one, using npm's own semantics.
39
- *
40
- * @param current - The version the manifest declares now.
41
- * @param level - How far to raise it.
42
- */
43
- export function nextVersion(current: string, level: BumpLevel): string {
44
- const next = semver.inc(current, level);
45
- if (next === null) {
46
- throw new ConfigError(
47
- `Cannot raise the version '${current}' by a ${level} step.\n` +
48
- ` A recipe version is an exact semantic version, such as '1.4.0' or '2.0.0-beta.1'.`
49
- );
50
- }
51
- return next;
52
- }
53
-
54
- /**
55
- * Rewrites a recipe manifest's `version` field in place, preserving the rest of
56
- * the file as written.
57
- *
58
- * @param manifestPath - Absolute path to the recipe manifest.
59
- * @param level - How far to raise the version.
60
- */
61
- export function bumpRecipeVersion(manifestPath: string, level: BumpLevel): BumpResult {
62
- return rewriteVersion(manifestPath, (current) => nextVersion(current, level));
63
- }
64
-
65
- /**
66
- * Writes an exact version into a recipe manifest, preserving the rest of the
67
- * file as written.
68
- *
69
- * This is what the release pipeline uses to hold the packaged core recipe at
70
- * the sous package's own version (see `scripts/sync-core-version.mts`), where
71
- * the new version is dictated rather than stepped. A manifest that already
72
- * declares this version is left untouched, byte for byte, so running the sync
73
- * twice cannot reformat a hand-written file.
74
- *
75
- * @param manifestPath - Absolute path to the recipe manifest.
76
- * @param version - The exact semantic version the manifest should declare.
77
- */
78
- export function setRecipeVersion(manifestPath: string, version: string): BumpResult {
79
- if (semver.valid(version) === null) {
80
- throw new ConfigError(
81
- `Cannot set the recipe version to '${version}'.\n` +
82
- ` A recipe version is an exact semantic version, such as '1.4.0' or '2.0.0-beta.1'.`
83
- );
84
- }
85
- return rewriteVersion(manifestPath, () => version);
86
- }
87
-
88
- /**
89
- * The one writer both callers share: read the version the manifest declares,
90
- * work out what it becomes, and rewrite that value alone.
91
- *
92
- * @param manifestPath - Absolute path to the recipe manifest.
93
- * @param nextFrom - Given the declared version, the version to write.
94
- */
95
- function rewriteVersion(
96
- manifestPath: string,
97
- nextFrom: (current: string) => string
98
- ): BumpResult {
99
- const text = fs.readFileSync(manifestPath, "utf8");
100
- const extension = path.extname(manifestPath).toLowerCase();
101
-
102
- if (extension === ".json" || extension === ".jsonc") {
103
- return rewriteJson(manifestPath, text, nextFrom);
104
- }
105
- return rewriteYaml(manifestPath, text, nextFrom);
106
- }
107
-
108
- /** Rewrites the version in a YAML manifest, keeping its comments and layout. */
109
- function rewriteYaml(
110
- manifestPath: string,
111
- text: string,
112
- nextFrom: (current: string) => string
113
- ): BumpResult {
114
- const document = YAML.parseDocument(text);
115
- const node = document.get("version", true);
116
-
117
- if (!YAML.isScalar(node) || typeof node.value !== "string") {
118
- throw missingVersion(manifestPath);
119
- }
120
-
121
- const from = node.value;
122
- const to = nextFrom(from);
123
- if (to === from) return { manifestPath, from, to };
124
-
125
- node.value = to;
126
- fs.writeFileSync(manifestPath, document.toString(), "utf8");
127
-
128
- return { manifestPath, from, to };
129
- }
130
-
131
- /** Rewrites the version in a JSON or JSONC manifest, editing only that value's bytes. */
132
- function rewriteJson(
133
- manifestPath: string,
134
- text: string,
135
- nextFrom: (current: string) => string
136
- ): BumpResult {
137
- // The manifest dialect allows comments and trailing commas, so it is read
138
- // through the loader's own permissive parser rather than JSON.parse.
139
- const parsed = parseJsoncText(text, manifestPath);
140
- const from =
141
- typeof parsed === "object" && parsed !== null
142
- ? (parsed as Record<string, unknown>).version
143
- : undefined;
144
- if (typeof from !== "string") throw missingVersion(manifestPath);
145
-
146
- const to = nextFrom(from);
147
- if (to === from) return { manifestPath, from, to };
148
-
149
- const edits = modify(text, ["version"], to, {});
150
- fs.writeFileSync(manifestPath, applyEdits(text, edits), "utf8");
151
-
152
- return { manifestPath, from, to };
153
- }
154
-
155
- /** The error for a manifest with no usable `version` field. */
156
- function missingVersion(manifestPath: string): ConfigError {
157
- return new ConfigError(
158
- `The recipe manifest at ${manifestPath} has no 'version' field to write.\n` +
159
- ` Every recipe declares an exact semantic version; add one, then try again.`
160
- );
161
- }