@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,439 +0,0 @@
1
- /**
2
- * `sous recipe show <ref>`.
3
- *
4
- * Shows one recipe in full: where it is published, every version it publishes,
5
- * what the version this project would use depends on and how each dependency is
6
- * declared, everything subscribing to it would install, every question that
7
- * would ask, and where its files land in this project. It reads only what sous
8
- * already has on disk: the repository's cached index, the project's lockfile,
9
- * and the recipe's own files when they are in the store or a linked working
10
- * copy. The index describes each version's dependencies and questions, so a
11
- * recipe nothing has installed is described as fully as one in the store, its
12
- * files excepted. `--latest` reads the repository's index from upstream
13
- * instead, saving nothing, and `--installed` looks the ref up among installed
14
- * recipes only.
15
- */
16
-
17
- import { Args } from "@oclif/core";
18
- import semver from "semver";
19
- import { BaseCommand } from "../../base-command.js";
20
- import { resolveRootScope } from "../../lib/settings.js";
21
- import {
22
- subscriptionServiceFor,
23
- type SubscriptionPreview,
24
- type SubscriptionService,
25
- } from "../../lib/repos/subscription-service.js";
26
- import { loadCatalogContext } from "../../lib/repos/catalog-inputs.js";
27
- import {
28
- describeInstalled,
29
- describeRecipe,
30
- type CatalogInputs,
31
- type RecipeContentListing,
32
- type RecipeDependencyListing,
33
- type RecipeDetail,
34
- type RecipeVersionListing,
35
- } from "../../lib/repos/catalog.js";
36
- import { PROJECT_REQUESTER } from "../../lib/repos/resolver.js";
37
- import { recipeRef } from "../../services/ref-resolver/index.js";
38
- import { describeDeclaration, describeDependencyKind } from "../../lib/repos/declarations.js";
39
- import { formatQuestionPlan } from "../../lib/vars/question-plan.js";
40
- import { describeError } from "../../lib/repos/release/validate.js";
41
- import {
42
- INDENT,
43
- describeIndexSource,
44
- describeVersionStatus,
45
- factIf,
46
- printBrowsingNotes,
47
- printFacts,
48
- } from "../../lib/repos/catalog-display.js";
49
- import { renderTable, type TableColumn } from "../../utils/table.js";
50
- import { browsingFlags } from "../../utils/flags.js";
51
- import {
52
- blankLine,
53
- footer,
54
- heading,
55
- indent,
56
- log,
57
- paragraph,
58
- showCommandVars,
59
- subheading,
60
- } from "../../utils/formatting.js";
61
-
62
- /** The columns the version history shows. */
63
- const VERSION_COLUMNS: TableColumn[] = [
64
- { key: "version", header: "Version", overflow: "truncate", minWidth: 7 },
65
- { key: "status", header: "What it is", overflow: "wrap", flex: 1, minWidth: 16 },
66
- { key: "prerelease", header: "Prerelease", priority: "medium" },
67
- { key: "released", header: "Released", overflow: "truncate", priority: "low" },
68
- ];
69
-
70
- /** The columns the dependency listing shows. */
71
- const DEPENDENCY_COLUMNS: TableColumn[] = [
72
- { key: "key", header: "Dependency", kind: "path", overflow: "truncate", minWidth: 12 },
73
- { key: "declared", header: "Declared as", overflow: "wrap", flex: 1, minWidth: 12 },
74
- { key: "resolved", header: "Resolved to", overflow: "truncate", minWidth: 11 },
75
- { key: "repo", header: "Repository", overflow: "truncate", priority: "low", minWidth: 12 },
76
- { key: "kind", header: "Kind", overflow: "wrap", priority: "medium", minWidth: 16 },
77
- ];
78
-
79
- /** The columns the listing of everything a subscription installs shows. */
80
- const INSTALLS_COLUMNS: TableColumn[] = [
81
- { key: "key", header: "Recipe", kind: "path", overflow: "truncate", minWidth: 12 },
82
- { key: "version", header: "Version", overflow: "truncate", minWidth: 7 },
83
- { key: "kind", header: "Kind", overflow: "wrap", minWidth: 16 },
84
- {
85
- key: "neededBy",
86
- header: "Needed by",
87
- overflow: "wrap",
88
- flex: 1,
89
- priority: "medium",
90
- minWidth: 12,
91
- },
92
- ];
93
-
94
- /** The columns the content listing shows. */
95
- const CONTENT_COLUMNS: TableColumn[] = [
96
- { key: "kind", header: "Content", minWidth: 7 },
97
- { key: "include", header: "Files", overflow: "wrap", flex: 1, minWidth: 14 },
98
- {
99
- key: "destination",
100
- header: "Where they land",
101
- kind: "path",
102
- overflow: "wrap",
103
- flex: 2,
104
- minWidth: 16,
105
- },
106
- ];
107
-
108
- export default class RecipeShow extends BaseCommand {
109
- static description =
110
- "Show one recipe: its versions, dependencies, what subscribing installs and asks, and its files";
111
-
112
- /**
113
- * The other spelling of the topic. It lives under a hidden topic, so it is
114
- * typable everywhere without ever reaching the top-level listing.
115
- */
116
- static aliases = ["recipes:show"];
117
-
118
- static examples = [
119
- "<%= config.bin %> recipe show workflow/task-files",
120
- "<%= config.bin %> recipe show task-files",
121
- "<%= config.bin %> recipe show sous-recipes:core/about-sous",
122
- ];
123
-
124
- static args = {
125
- ref: Args.string({
126
- description:
127
- "A recipe, written as 'namespace/recipe', a recipe name on its own, or either with a 'repository:' qualifier",
128
- required: true,
129
- }),
130
- };
131
-
132
- static flags = { ...BaseCommand.baseFlags, ...browsingFlags() };
133
-
134
- async run(): Promise<void> {
135
- const { args, flags } = await this.parse(RecipeShow);
136
-
137
- showCommandVars({
138
- Project: this.projectLabel,
139
- Config: this.configContext.configPath,
140
- Recipe: args.ref,
141
- Reading: describeIndexSource(flags.latest),
142
- ...(flags.installed ? { Showing: "only what this project has installed" } : {}),
143
- });
144
-
145
- const service = subscriptionServiceFor({
146
- configContext: this.configContext,
147
- settings: this.settings,
148
- shellEnv: this.shellEnv,
149
- });
150
-
151
- const { inputs, notChecked } = await loadCatalogContext({
152
- service,
153
- sousDir: this.configContext.sousDir,
154
- settings: this.settings,
155
- scope: resolveRootScope(this.settings, this.configContext),
156
- latest: flags.latest,
157
- });
158
-
159
- const detail = flags.installed
160
- ? await describeInstalled(inputs, args.ref, describeRecipe, "recipe")
161
- : await describeRecipe(inputs, args.ref);
162
-
163
- heading(detail.key);
164
- blankLine();
165
-
166
- printFacts([
167
- { label: "Repository", lines: [detail.repo] },
168
- ...factIf("Location", detail.repoUrl),
169
- ...factIf("About", detail.description),
170
- { label: "Folder", lines: [detail.path] },
171
- { label: "Latest version", lines: [detail.latest ?? "none published"] },
172
- {
173
- label: flags.installed ? "Installed version" : "Pinned version",
174
- lines: [detail.pinned ?? "this project pins none"],
175
- },
176
- ...factIf(
177
- "Linked",
178
- detail.linkedPath === undefined
179
- ? undefined
180
- : `builds currently read this recipe from the checkout at ${detail.linkedPath}`
181
- ),
182
- { label: "Subscribed", lines: [detail.subscribed ? "yes" : "no"] },
183
- ...factIf("Described below", detail.describing),
184
- ]);
185
-
186
- printBrowsingNotes({ notChecked: notChecked.filter((name) => name === detail.repo) });
187
-
188
- this.printVersions(detail.versions);
189
- this.printDependencies(
190
- detail.dependencies,
191
- detail.manifestRead || detail.dependenciesRecorded
192
- );
193
-
194
- const preview = await this.preview(service, inputs, detail);
195
- if (typeof preview === "string") {
196
- blankLine();
197
- paragraph(preview);
198
- } else {
199
- this.printInstalls(preview);
200
- this.printQuestions(preview);
201
- }
202
-
203
- if (detail.manifestRead) {
204
- this.printContents(detail.contents);
205
- } else {
206
- blankLine();
207
- subheading("Where its files land in this project");
208
- blankLine();
209
- paragraph(
210
- "The recipe's own files are not on this machine, so the files it publishes are " +
211
- "not known here. Subscribing to it fetches them."
212
- );
213
- }
214
-
215
- footer();
216
- }
217
-
218
- /**
219
- * Works out what subscribing to the described version would install and ask,
220
- * from the same indexes the rest of the page reads, fetching nothing. The
221
- * answer is a sentence instead when it cannot be worked out.
222
- *
223
- * @param service - The project's subscription service.
224
- * @param inputs - The catalog's inputs, whose indexes the preview resolves against.
225
- * @param detail - The recipe being described.
226
- */
227
- private async preview(
228
- service: SubscriptionService,
229
- inputs: CatalogInputs,
230
- detail: RecipeDetail
231
- ): Promise<SubscriptionPreview | string> {
232
- if (detail.describing === undefined) {
233
- return (
234
- "This recipe publishes no version a subscription would install, so nothing " +
235
- "is described below."
236
- );
237
- }
238
- try {
239
- return await service.previewSubscription(
240
- recipeRef(detail.namespace, detail.name, {
241
- repo: detail.repo,
242
- range: detail.describing,
243
- }),
244
- {
245
- indexes: new Map(inputs.repos.map((repo) => [repo.name, repo.index])),
246
- ...(semver.prerelease(detail.describing) === null ? {} : { prerelease: true }),
247
- }
248
- );
249
- } catch (error) {
250
- return (
251
- `Sous could not work out what subscribing to version ${detail.describing} ` +
252
- `would install. ${describeError(error)}`
253
- );
254
- }
255
- }
256
-
257
- /**
258
- * Every published version, newest first, with what each one is to this
259
- * project.
260
- *
261
- * @param versions - The versions the catalog listed.
262
- */
263
- private printVersions(versions: RecipeVersionListing[]): void {
264
- blankLine();
265
- subheading("Published versions");
266
- blankLine();
267
-
268
- const rows = versions.map((entry) => ({
269
- version: entry.version,
270
- status: describeVersionStatus(entry.status),
271
- prerelease: entry.prerelease ? "yes" : "no",
272
- released: entry.releasedAt ?? "not recorded",
273
- }));
274
-
275
- for (const line of renderTable(VERSION_COLUMNS, rows, { indent: INDENT })) {
276
- log(indent(line, INDENT));
277
- }
278
- }
279
-
280
- /**
281
- * What the described version depends on: the manifest entry that brings each
282
- * dependency in and whether it is a co-subscription or a build dependency,
283
- * and what its repository's index resolved it to when it was released.
284
- *
285
- * @param dependencies - The dependencies the catalog listed.
286
- * @param known - Whether the manifest or the index says what the version declares.
287
- */
288
- private printDependencies(dependencies: RecipeDependencyListing[], known: boolean): void {
289
- blankLine();
290
- subheading("What it depends on");
291
- blankLine();
292
-
293
- if (dependencies.length === 0) {
294
- paragraph(
295
- known
296
- ? "This recipe depends on nothing else."
297
- : "The repository's index records no dependencies for this version."
298
- );
299
- return;
300
- }
301
-
302
- const rows = dependencies.map((entry) => ({
303
- key: entry.key,
304
- declared:
305
- entry.declared === undefined
306
- ? "not recorded in the index"
307
- : describeDeclaration(entry.declared),
308
- resolved:
309
- entry.resolvedVersion ??
310
- (entry.resolvedRange === undefined
311
- ? "not recorded in the index"
312
- : `the range ${entry.resolvedRange}`),
313
- repo: entry.repo ?? "this repository",
314
- kind: describeDependencyKind(entry.kind),
315
- }));
316
-
317
- for (const line of renderTable(DEPENDENCY_COLUMNS, rows, { indent: INDENT })) {
318
- log(indent(line, INDENT));
319
- }
320
- }
321
-
322
- /**
323
- * Every recipe a subscription to the described version would install, each
324
- * with whether its files land in the project and what brings it in, and the
325
- * repositories it would need that the project does not trust yet.
326
- *
327
- * @param preview - What subscribing would install and ask.
328
- */
329
- private printInstalls(preview: SubscriptionPreview): void {
330
- blankLine();
331
- subheading("What subscribing installs");
332
- blankLine();
333
-
334
- const rows = preview.resolved.map((recipe) => {
335
- const subscribed = recipe.requestedBy.includes(PROJECT_REQUESTER);
336
- const holders = recipe.requestedBy.filter((holder) => holder !== PROJECT_REQUESTER);
337
- return {
338
- key: recipe.key,
339
- version: recipe.version,
340
- kind: subscribed ? "the subscription itself" : describeDependencyKind(recipe.kind),
341
- neededBy: holders.length === 0 ? "this subscription" : holders.join(", "),
342
- };
343
- });
344
-
345
- for (const line of renderTable(INSTALLS_COLUMNS, rows, { indent: INDENT })) {
346
- log(indent(line, INDENT));
347
- }
348
-
349
- if (preview.missingRepos.length > 0) {
350
- blankLine();
351
- paragraph(
352
- `Subscribing also needs ${
353
- preview.missingRepos.length === 1 ? "a repository" : "repositories"
354
- } this project does not trust yet, so what ${
355
- preview.missingRepos.length === 1 ? "it publishes" : "they publish"
356
- } is not listed above: ` +
357
- preview.missingRepos
358
- .map(
359
- (missing) =>
360
- `${missing.name}${missing.url === undefined ? "" : ` (${missing.url})`}, ` +
361
- `needed by ${missing.requiredBy.map((entry) => entry.requestedBy).join(", ")}`
362
- )
363
- .join("; ") +
364
- "."
365
- );
366
- }
367
- }
368
-
369
- /**
370
- * Every question a subscription to the described version would ask, laid out
371
- * exactly as `sous subscription add --dry-run` lays them out, without the
372
- * flags that answer them ahead of time.
373
- *
374
- * @param preview - What subscribing would install and ask.
375
- */
376
- private printQuestions(preview: SubscriptionPreview): void {
377
- blankLine();
378
- subheading("What subscribing asks you");
379
- blankLine();
380
-
381
- for (const line of formatQuestionPlan(preview.questions, {
382
- unreadable: preview.unreadable,
383
- answerHints: false,
384
- })) {
385
- log(line === "" ? "" : indent(line));
386
- }
387
- }
388
-
389
- /**
390
- * What the recipe contributes, and where each kind's files are written in
391
- * this project.
392
- *
393
- * @param contents - The content kinds the catalog listed.
394
- */
395
- private printContents(contents: RecipeContentListing[]): void {
396
- blankLine();
397
- subheading("Where its files land in this project");
398
- blankLine();
399
-
400
- if (contents.length === 0) {
401
- paragraph("This recipe publishes no files.");
402
- return;
403
- }
404
-
405
- const rows = contents.map((entry) => ({
406
- kind: entry.kind,
407
- include: entry.include.join(", "),
408
- destination:
409
- entry.destinations.length > 0
410
- ? entry.destinations.join(", ")
411
- : noDestinationText(entry.kind),
412
- }));
413
-
414
- for (const line of renderTable(CONTENT_COLUMNS, rows, { indent: INDENT })) {
415
- log(indent(line, INDENT));
416
- }
417
- }
418
- }
419
-
420
- /**
421
- * What to say where a content kind has no destination directory: each kind
422
- * reaches the project in its own way.
423
- *
424
- * noDestinationText("memories"); // -> "included in an agent's instructions by an include line, so nothing is written"
425
- *
426
- * @param kind - The content kind.
427
- */
428
- function noDestinationText(kind: string): string {
429
- switch (kind) {
430
- case "config":
431
- return "loaded as a config layer, so nothing is written";
432
- case "memories":
433
- return "reaches an agent through an include line in its instructions, so nothing is written";
434
- case "skills":
435
- return "nowhere: this project sets no 'recipes.skills.outputs' directory";
436
- default:
437
- return `nowhere: this project has no destination for ${kind} yet`;
438
- }
439
- }
@@ -1,145 +0,0 @@
1
- /**
2
- * `sous repo add <url>`.
3
- *
4
- * Adding a repository is the trust ceremony, and the two are deliberately the
5
- * same act: a repository sous will read from is one written into this project's
6
- * config, and removing that entry withdraws the trust. Nothing is downloaded
7
- * before the question is answered, not even the repository's index.
8
- *
9
- * Once the answer is yes, exactly one file is fetched: `sous.index.json`. That
10
- * is all sous needs in order to resolve a ref, list versions and decide what to
11
- * download later, so adding a repository costs one small request and installs
12
- * nothing.
13
- */
14
-
15
- import { Args, Flags } from "@oclif/core";
16
- import { BaseCommand } from "../../base-command.js";
17
- import { subscriptionServiceFor } from "../../lib/repos/subscription-service.js";
18
- import type { ProviderId } from "../../lib/repos/providers/provider.js";
19
- import {
20
- blankLine,
21
- dryRunNotice,
22
- footer,
23
- heading,
24
- note,
25
- showCommandVars,
26
- showVariables,
27
- } from "../../utils/formatting.js";
28
- import { confirmationFlag } from "../../utils/flags.js";
29
-
30
- export default class RepoAdd extends BaseCommand {
31
- static description =
32
- "Add a recipe repository to this project, which is also how you trust it";
33
-
34
- /**
35
- * The other spelling of the topic. It lives under a hidden topic, so it is
36
- * typable everywhere without ever reaching the top-level listing.
37
- */
38
- static aliases = ["repos:add"];
39
-
40
- static examples = [
41
- "<%= config.bin %> repo add https://github.com/sous-io/sous-recipes",
42
- "<%= config.bin %> repo add https://github.com/sous-io/sous-recipes --name recipes",
43
- "<%= config.bin %> repo add /home/me/Projects/my-recipes --trust",
44
- "<%= config.bin %> repo add ../my-recipes --trust",
45
- ];
46
-
47
- static args = {
48
- url: Args.string({
49
- description:
50
- "Where the repository lives: its URL, or the path of one on this machine",
51
- required: true,
52
- }),
53
- };
54
-
55
- static flags = {
56
- ...BaseCommand.baseFlags,
57
- name: Flags.string({
58
- description:
59
- "The short name refs will use for it. Defaults to the last segment of the URL",
60
- }),
61
- provider: Flags.string({
62
- description:
63
- "The provider that handles it, for a host the URL does not give away",
64
- options: ["github", "gitlab", "local"],
65
- }),
66
- // The only question this command asks is the trust question, so the shared
67
- // confirmation flag answers it; `--trust` stays a spelling of it, because
68
- // that is the word the ceremony is named after.
69
- yes: confirmationFlag({ extraAliases: ["trust"] }),
70
- "dry-run": Flags.boolean({
71
- description: "Print what would change without trusting or fetching anything",
72
- default: false,
73
- }),
74
- };
75
-
76
- async run(): Promise<void> {
77
- const { args, flags } = await this.parse(RepoAdd);
78
- const dryRun = flags["dry-run"];
79
-
80
- showCommandVars({
81
- Project: this.projectLabel,
82
- Config: this.configContext.configPath,
83
- Repository: args.url,
84
- "Dry Run": dryRun,
85
- });
86
-
87
- // The heading is not followed by a blank line here: the block that comes
88
- // next opens with one of its own, and the trust ceremony in the middle may
89
- // print before either of them.
90
- heading("Adding a repository");
91
-
92
- if (dryRun) {
93
- dryRunNotice("Nothing will be trusted, written or downloaded.");
94
- blankLine();
95
- }
96
-
97
- const service = subscriptionServiceFor({
98
- configContext: this.configContext,
99
- settings: this.settings,
100
- shellEnv: this.shellEnv,
101
- });
102
-
103
- const outcome = await service.addRepo({
104
- url: args.url,
105
- ...(flags.name === undefined ? {} : { name: flags.name }),
106
- ...(flags.provider === undefined
107
- ? {}
108
- : { provider: flags.provider as ProviderId }),
109
- trust: flags.yes,
110
- dryRun,
111
- });
112
-
113
- blankLine();
114
-
115
- if (outcome.dryRun) {
116
- note(
117
- `The repository would be added as '${outcome.name}', read through the ` +
118
- `${outcome.provider} provider, and its index would be fetched.`
119
- );
120
- footer();
121
- return;
122
- }
123
-
124
- showVariables({
125
- Repository: outcome.name,
126
- Location: outcome.url,
127
- Provider: outcome.provider,
128
- Namespaces:
129
- outcome.namespaces.length > 0
130
- ? outcome.namespaces.join(", ")
131
- : "none; this repository publishes nothing yet",
132
- Recipes: String(outcome.recipeCount),
133
- });
134
-
135
- blankLine();
136
- note(
137
- outcome.alreadyTrusted
138
- ? `This project already trusted '${outcome.name}', so only its index was ` +
139
- `refreshed.`
140
- : `This project now trusts '${outcome.name}'. Nothing from it has been installed.`
141
- );
142
-
143
- footer();
144
- }
145
- }