@sous-io/sous 0.2.16 → 0.2.18

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 (33) hide show
  1. package/docs/markdown/commands.md +59 -13
  2. package/docs/markdown/repositories-authoring.md +75 -13
  3. package/docs/markdown/repositories-consuming.md +44 -2
  4. package/docs/markdown/repositories-file-formats.md +22 -1
  5. package/docs/markdown/repositories-providers.md +20 -10
  6. package/package.json +1 -1
  7. package/recipes/core/sous-skills/sous.recipe.yaml +8 -1
  8. package/src/commands/repo/release.ts +41 -0
  9. package/src/commands/repo/submit.ts +245 -35
  10. package/src/commands/repo/unlink.ts +333 -20
  11. package/src/commands/subscription/update.ts +215 -0
  12. package/src/lib/repos/formats/common.ts +20 -0
  13. package/src/lib/repos/formats/links-map.ts +5 -3
  14. package/src/lib/repos/formats/recipe-manifest.ts +7 -0
  15. package/src/lib/repos/formats/repo-manifest.ts +8 -0
  16. package/src/lib/repos/git-clone.ts +71 -0
  17. package/src/lib/repos/links.ts +2 -1
  18. package/src/lib/repos/locked-recipes.ts +22 -0
  19. package/src/lib/repos/providers/base.ts +33 -1
  20. package/src/lib/repos/providers/github.ts +275 -3
  21. package/src/lib/repos/providers/provider.ts +119 -3
  22. package/src/lib/repos/release/changelog.ts +448 -0
  23. package/src/lib/repos/release/git-state.ts +101 -15
  24. package/src/lib/repos/release/index.ts +2 -0
  25. package/src/lib/repos/release/submissions.ts +214 -0
  26. package/src/lib/repos/release/submit-checkout.ts +271 -0
  27. package/src/lib/repos/release/submit-questions.ts +153 -0
  28. package/src/lib/repos/release/submit-service.ts +581 -174
  29. package/src/lib/repos/resolver.ts +25 -2
  30. package/src/lib/repos/seed.ts +64 -5
  31. package/src/lib/repos/store/hash.ts +68 -8
  32. package/src/lib/repos/subscription-service.ts +744 -20
  33. package/src/lib/repos/update-plan.ts +234 -0
@@ -1,35 +1,72 @@
1
+ import fs from "node:fs";
2
+ import path from "node:path";
1
3
  import { Args, Flags } from "@oclif/core";
2
4
  import { BaseCommand } from "../../base-command.js";
3
- import { ConfigError } from "../../lib/errors.js";
5
+ import { buildProjectOutputs } from "../../lib/build-service.js";
6
+ import { ConfigError, isConfigError } from "../../lib/errors.js";
4
7
  import {
8
+ NonInteractiveError,
9
+ isInteractive,
10
+ nonInteractiveError,
11
+ wantsHelp,
12
+ } from "../../lib/interactive.js";
13
+ import {
14
+ globalReposDir,
15
+ projectReposDir,
5
16
  readGlobalLinks,
6
17
  readProjectLinks,
7
18
  writeGlobalLinks,
8
19
  writeProjectLinks,
9
20
  } from "../../lib/repos/links.js";
21
+ import { hasNoUnsavedWork, unsavedWork, type UnsavedWork } from "../../lib/repos/git-clone.js";
22
+ import {
23
+ subscriptionServiceFor,
24
+ type SubscriptionService,
25
+ } from "../../lib/repos/subscription-service.js";
26
+ import type { RepoLink } from "../../lib/repos/formats/links-map.js";
27
+ import { collectProvidedAnswers } from "../../lib/vars/index.js";
28
+ import { formatAskReport } from "../../lib/vars/ask.js";
10
29
  import {
30
+ BULLET,
11
31
  blankLine,
12
32
  dryRunNotice,
13
33
  footer,
34
+ heading,
35
+ indent,
14
36
  log,
37
+ note,
38
+ paragraph,
15
39
  section,
16
40
  showCommandVars,
17
41
  showVariables,
42
+ subheading,
43
+ warning,
18
44
  } from "../../utils/formatting.js";
45
+ import { askYesNo } from "../../utils/prompts.js";
46
+ import { answerFlags, confirmationFlag } from "../../utils/flags.js";
19
47
 
20
48
  /**
21
- * `sous repo unlink` stops reading a repository from a working copy and goes
22
- * back to published versions.
49
+ * `sous repo unlink` stops reading a repository from a working copy, goes back
50
+ * to the versions the lockfile pins, and rebuilds the project.
51
+ *
52
+ * Linking never touches the lockfile, so unlinking returns to exactly the
53
+ * versions pinned before the link. Three ways to finish, one per flag:
54
+ *
55
+ * - On its own, it fetches the repository's index with a short timeout and
56
+ * reports, as a fact, any newer published version the ranges allow. Nothing
57
+ * moves.
58
+ * - `--update` runs the same code as `sous subscription update <repository>`,
59
+ * so the pins move to those newer versions before the rebuild.
60
+ * - `--remove` deletes the checkout, and only one sous cloned itself. A
61
+ * checkout linked by path belongs to its owner and is never deleted. Work
62
+ * that exists nowhere else is listed first and asked about.
23
63
  *
24
- * It only ever removes a map entry. The checkout stays exactly where it is,
25
- * because sous did not necessarily put it there, and even when it did, deleting
26
- * a directory that may hold uncommitted work is not something a command like
27
- * this should decide on its own. The path is printed so the user can delete it
28
- * themselves if they want to.
64
+ * Without `--remove` the checkout stays exactly where it is, because `sous repo
65
+ * submit` uses a leftover checkout to revise a proposal that is still open.
29
66
  */
30
67
  export default class RepoUnlink extends BaseCommand {
31
68
  static description =
32
- "Stop reading a repository from a working copy and go back to published versions";
69
+ "Stop reading a repository from a working copy and go back to its pinned versions";
33
70
 
34
71
  /**
35
72
  * The other spelling of the topic. It lives under a hidden topic, so it is
@@ -39,6 +76,8 @@ export default class RepoUnlink extends BaseCommand {
39
76
 
40
77
  static examples = [
41
78
  "<%= config.bin %> repo unlink sous-recipes",
79
+ "<%= config.bin %> repo unlink sous-recipes --update",
80
+ "<%= config.bin %> repo unlink sous-recipes --remove",
42
81
  "<%= config.bin %> repo unlink sous-recipes --global",
43
82
  ];
44
83
 
@@ -52,14 +91,31 @@ export default class RepoUnlink extends BaseCommand {
52
91
  static flags = {
53
92
  ...BaseCommand.baseFlags,
54
93
  global: Flags.boolean({
94
+ description: "Remove the machine-wide link rather than this project's link",
95
+ default: false,
96
+ }),
97
+ update: Flags.boolean({
55
98
  description:
56
- "Remove the machine-wide link rather than this project's link",
99
+ "Move this repository's pins to the newest versions their ranges allow before rebuilding",
57
100
  default: false,
58
101
  }),
102
+ remove: Flags.boolean({
103
+ description: "Delete the checkout as well, when sous cloned it",
104
+ default: false,
105
+ }),
106
+ // One flag answers every question this command can ask: deleting a
107
+ // checkout that holds work, the update plan, and the trust question for a
108
+ // repository a newer version needs.
109
+ yes: confirmationFlag({ extraAliases: ["trust"] }),
59
110
  "dry-run": Flags.boolean({
60
111
  description: "Print what would change without writing anything",
61
112
  default: false,
62
113
  }),
114
+ "no-build": Flags.boolean({
115
+ description: "Unlink without rebuilding the project",
116
+ default: false,
117
+ }),
118
+ ...answerFlags(),
63
119
  };
64
120
 
65
121
  async run(): Promise<void> {
@@ -67,12 +123,13 @@ export default class RepoUnlink extends BaseCommand {
67
123
  const { sousDir } = this.configContext;
68
124
  const isGlobal = flags.global;
69
125
  const name = args.repo;
126
+ const dryRun = flags["dry-run"];
70
127
 
71
128
  showCommandVars({
72
129
  Project: this.projectLabel,
73
130
  Repository: name,
74
131
  Scope: isGlobal ? "this machine" : "this project",
75
- "Dry Run": flags["dry-run"],
132
+ "Dry Run": dryRun,
76
133
  });
77
134
 
78
135
  section("Unlinking a repository");
@@ -84,31 +141,287 @@ export default class RepoUnlink extends BaseCommand {
84
141
  throw new ConfigError(this.notLinkedMessage(name, isGlobal, sousDir));
85
142
  }
86
143
 
87
- if (flags["dry-run"]) {
144
+ const service = subscriptionServiceFor({
145
+ configContext: this.configContext,
146
+ settings: this.settings,
147
+ shellEnv: this.shellEnv,
148
+ });
149
+
150
+ // Everything that can refuse is settled before anything is written, so a
151
+ // refusal leaves the link exactly as it was.
152
+ if (flags.update && service.currentRepos()[name] === undefined) {
153
+ throw new ConfigError(
154
+ `'${name}' is linked, but this project does not trust a repository by that ` +
155
+ `name, so it has no pins to update.\n` +
156
+ ` Nothing was changed; the link is still in place.`
157
+ );
158
+ }
159
+ if (flags.remove) this.assertRemovable(name, entry, isGlobal, sousDir);
160
+ const work = flags.remove ? unsavedWork(entry.path) : undefined;
161
+
162
+ if (dryRun) {
88
163
  dryRunNotice(`would unlink '${name}', which points at ${entry.path}`);
89
- dryRunNotice("the checkout itself would be left where it is");
164
+ dryRunNotice(
165
+ flags.remove
166
+ ? "the checkout would be deleted"
167
+ : "the checkout itself would be left where it is"
168
+ );
169
+ if (work !== undefined && !hasNoUnsavedWork(work)) this.describeUnsavedWork(work);
170
+ if (flags.update) await service.update({ repo: name, dryRun: true });
90
171
  footer();
91
172
  return;
92
173
  }
93
174
 
175
+ if (work !== undefined) await this.confirmRemoval(entry.path, work, flags.yes);
176
+
94
177
  delete map.links[name];
95
178
  const linksPath = isGlobal ? writeGlobalLinks(map) : writeProjectLinks(sousDir, map);
96
179
 
97
180
  showVariables({
98
181
  Repository: name,
99
- "Checkout left at": entry.path,
100
- "Updated": linksPath,
182
+ Checkout: entry.path,
183
+ Updated: linksPath,
184
+ });
185
+
186
+ blankLine();
187
+ paragraph(`'${name}' is read from the versions the lockfile pins again.`);
188
+
189
+ if (flags.update) {
190
+ await this.updatePins(service, name, flags);
191
+ } else {
192
+ await this.reportNewerVersions(service, name);
193
+ }
194
+
195
+ if (flags.remove) {
196
+ fs.rmSync(entry.path, { recursive: true, force: true });
197
+ blankLine();
198
+ paragraph(`The checkout sous cloned at ${entry.path} was deleted.`);
199
+ } else {
200
+ blankLine();
201
+ paragraph(
202
+ entry.origin === "clone"
203
+ ? `The checkout sous cloned is still at ${entry.path}.`
204
+ : `The checkout at ${entry.path} was yours to begin with, and has not been touched.`
205
+ );
206
+ }
207
+
208
+ footer();
209
+
210
+ if (!flags["no-build"]) await this.rebuildProject(name);
211
+ }
212
+
213
+ /**
214
+ * Refuses to delete a checkout sous did not create, or one that is not where
215
+ * sous clones to. The link records its origin; a path-linked checkout belongs
216
+ * to whoever linked it.
217
+ *
218
+ * @param name - The repository's short name.
219
+ * @param entry - The link being removed.
220
+ * @param isGlobal - Whether it is the machine-wide link.
221
+ * @param sousDir - The project's `.sous/` directory.
222
+ */
223
+ private assertRemovable(
224
+ name: string,
225
+ entry: RepoLink,
226
+ isGlobal: boolean,
227
+ sousDir: string
228
+ ): void {
229
+ if (entry.origin !== "clone") {
230
+ throw new ConfigError(
231
+ `Sous did not create the checkout at ${entry.path}, so it will not delete it.\n` +
232
+ ` '${name}' was linked to a checkout that was already there. Nothing was ` +
233
+ `changed; unlink without '--remove' to keep the checkout, and delete it ` +
234
+ `yourself if you want it gone.`
235
+ );
236
+ }
237
+
238
+ const root = isGlobal ? globalReposDir() : projectReposDir(sousDir);
239
+ const relative = path.relative(root, entry.path);
240
+ if (relative === "" || relative.startsWith("..") || path.isAbsolute(relative)) {
241
+ throw new ConfigError(
242
+ `The checkout at ${entry.path} is not inside ${root}, where sous clones ` +
243
+ `checkouts, so sous will not delete it.\n` +
244
+ ` Nothing was changed; unlink without '--remove' and delete it yourself if ` +
245
+ `you want it gone.`
246
+ );
247
+ }
248
+ }
249
+
250
+ /**
251
+ * Lists what deleting the checkout would lose, and asks before going on. A
252
+ * checkout with nothing to lose is deleted without a question.
253
+ *
254
+ * @param checkout - The checkout's path.
255
+ * @param work - What an inspection of it found.
256
+ * @param yes - Whether the confirmation flag answered the question already.
257
+ */
258
+ private async confirmRemoval(
259
+ checkout: string,
260
+ work: UnsavedWork,
261
+ yes: boolean
262
+ ): Promise<void> {
263
+ if (hasNoUnsavedWork(work)) return;
264
+
265
+ this.describeUnsavedWork(work);
266
+ if (yes) return;
267
+
268
+ if (!isInteractive()) {
269
+ throw nonInteractiveError({
270
+ prompt: `whether to delete the checkout at ${checkout}, and the work listed above`,
271
+ remedy:
272
+ "pass '--yes' (spelled '-y', '--force' or '-f' if you prefer) to delete it " +
273
+ "without being asked.",
274
+ });
275
+ }
276
+
277
+ const proceed = await askYesNo("Delete the checkout, and this work with it?");
278
+ if (!proceed) {
279
+ throw new ConfigError(
280
+ `Nothing was changed: the checkout at ${checkout} was not deleted, and the ` +
281
+ `link is still in place.`
282
+ );
283
+ }
284
+ }
285
+
286
+ /**
287
+ * Prints what exists only in the checkout, as a list.
288
+ *
289
+ * @param work - What an inspection of the checkout found.
290
+ */
291
+ private describeUnsavedWork(work: UnsavedWork): void {
292
+ blankLine();
293
+ warning("The checkout holds work that exists nowhere else, and deleting it loses that work.");
294
+ blankLine();
295
+
296
+ const group = (title: string, items: string[]): void => {
297
+ if (items.length === 0) return;
298
+ log(indent(title));
299
+ for (const item of items) log(indent(`${BULLET} ${item}`, 4));
300
+ blankLine();
301
+ };
302
+
303
+ if (work.unknown !== undefined) {
304
+ group("Sous could not inspect it, so it may hold anything:", [work.unknown]);
305
+ }
306
+ group("Uncommitted changes:", work.uncommitted);
307
+ group("Commits no remote has:", work.unpushed);
308
+ group("Stashes:", work.stashes);
309
+ }
310
+
311
+ /**
312
+ * Moves the repository's pins through the same code `sous subscription
313
+ * update` runs. A failure there is reported with the fact that the link is
314
+ * already gone, since that part has happened.
315
+ *
316
+ * @param service - The subscription service.
317
+ * @param name - The repository's short name.
318
+ * @param flags - The confirmation and answer flags.
319
+ */
320
+ private async updatePins(
321
+ service: SubscriptionService,
322
+ name: string,
323
+ flags: { yes: boolean; answer?: string[]; "answers-file"?: string }
324
+ ): Promise<void> {
325
+ blankLine();
326
+ subheading("Updating the pins");
327
+
328
+ const provided = collectProvidedAnswers({
329
+ ...(flags.answer === undefined ? {} : { answer: flags.answer }),
330
+ ...(flags["answers-file"] === undefined ? {} : { answersFile: flags["answers-file"] }),
101
331
  });
102
332
 
333
+ let outcome;
334
+ try {
335
+ outcome = await service.update({ repo: name, yes: flags.yes, answers: provided });
336
+ } catch (error) {
337
+ if (!isConfigError(error)) throw error;
338
+ // The unlink has already happened, so the message says so before the
339
+ // reason the update stopped. A blocked question keeps its kind, so the
340
+ // command's help is still printed under it.
341
+ const message =
342
+ `'${name}' was unlinked, but its pins were not updated.\n` +
343
+ `${(error as ConfigError).message}`;
344
+ throw wantsHelp(error) ? new NonInteractiveError(message) : new ConfigError(message);
345
+ }
346
+
347
+ if (outcome.nothingToUpdate) return;
348
+
349
+ blankLine();
350
+ paragraph("The lockfile now pins the versions listed above.");
351
+
352
+ if (outcome.answers !== undefined) {
353
+ blankLine();
354
+ subheading("Variables");
355
+ for (const line of formatAskReport(outcome.answers)) log(line === "" ? "" : indent(line));
356
+ }
357
+ }
358
+
359
+ /**
360
+ * Says whether the repository publishes newer versions the ranges allow,
361
+ * without moving anything. The index is fetched with a short timeout; when it
362
+ * cannot be fetched, that is what is reported.
363
+ *
364
+ * @param service - The subscription service.
365
+ * @param name - The repository's short name.
366
+ */
367
+ private async reportNewerVersions(service: SubscriptionService, name: string): Promise<void> {
368
+ if (service.currentRepos()[name] === undefined) return;
369
+
370
+ blankLine();
371
+ subheading("Published versions");
103
372
  blankLine();
104
- log(` '${name}' now resolves to its published versions again.`);
105
- log(
106
- entry.origin === "clone"
107
- ? " sous cloned that checkout; it has been left in place, and you may delete it."
108
- : " That checkout was yours to begin with, and has not been touched."
373
+
374
+ const report = await service.newerPublishedVersions(name);
375
+ if (!report.checked) {
376
+ note(
377
+ `Sous could not check '${name}' for newer published versions. ` +
378
+ `${report.reason.split("\n")[0]!.trim()}`
379
+ );
380
+ return;
381
+ }
382
+
383
+ if (report.newer.length === 0) {
384
+ paragraph(
385
+ `Every pin from '${name}' is the newest published version its range allows.`
386
+ );
387
+ return;
388
+ }
389
+
390
+ paragraph(
391
+ `'${name}' publishes newer versions within range. The lockfile still pins the ` +
392
+ `older ones:`
109
393
  );
394
+ blankLine();
395
+ showVariables(
396
+ report.newer.map((entry) => ({
397
+ label: entry.key,
398
+ value: `${entry.from} pinned, ${entry.to} published`,
399
+ }))
400
+ );
401
+ }
402
+
403
+ /**
404
+ * Rebuilds the project, so its outputs come from the pinned versions rather
405
+ * than the checkout when this command returns.
406
+ *
407
+ * @param name - The repository that was unlinked, for the failure message.
408
+ */
409
+ private async rebuildProject(name: string): Promise<void> {
410
+ await this.reloadDiscoveredConfig();
411
+
412
+ heading("Building the project");
413
+
414
+ const succeeded = await buildProjectOutputs(this.settings, this.configContext);
110
415
 
111
416
  footer();
417
+
418
+ if (!succeeded) {
419
+ throw new ConfigError(
420
+ `'${name}' was unlinked, but the build that followed failed, so this project's ` +
421
+ `outputs may still hold what the checkout contributed. The unlink itself is ` +
422
+ `recorded; fix what the build reported above and run 'sous build' again.`
423
+ );
424
+ }
112
425
  }
113
426
 
114
427
  /**
@@ -0,0 +1,215 @@
1
+ /**
2
+ * `sous subscription update [ref]`.
3
+ *
4
+ * Moves the lockfile's pins to the newest versions their ranges allow. With no
5
+ * reference it covers every subscription; a reference narrows it to one
6
+ * repository, one namespace or one recipe:
7
+ *
8
+ * sous subscription update
9
+ * sous subscription update sous-recipes
10
+ * sous subscription update workflow
11
+ * sous subscription update workflow/task-files
12
+ *
13
+ * Every trusted repository's index is fetched fresh first. A pin moves only
14
+ * within the range its subscription (or the recipe depending on it) declares,
15
+ * and dependencies move with the closure. Only the lockfile changes; the
16
+ * subscriptions themselves are never edited. The whole change is printed as a
17
+ * plan and asked about once, and the project is rebuilt afterwards.
18
+ */
19
+
20
+ import { Args, Flags } from "@oclif/core";
21
+ import { BaseCommand } from "../../base-command.js";
22
+ import { buildProjectOutputs } from "../../lib/build-service.js";
23
+ import { ConfigError } from "../../lib/errors.js";
24
+ import { subscriptionServiceFor } from "../../lib/repos/subscription-service.js";
25
+ import { describeUpdateScope } from "../../lib/repos/update-plan.js";
26
+ import { formatAskReport } from "../../lib/vars/ask.js";
27
+ import { collectProvidedAnswers } from "../../lib/vars/index.js";
28
+ import {
29
+ blankLine,
30
+ dryRunNotice,
31
+ footer,
32
+ heading,
33
+ indent,
34
+ log,
35
+ paragraph,
36
+ showCommandVars,
37
+ subheading,
38
+ warning,
39
+ } from "../../utils/formatting.js";
40
+ import { answerFlags, confirmationFlag } from "../../utils/flags.js";
41
+
42
+ export default class SubscriptionUpdate extends BaseCommand {
43
+ static description =
44
+ "Move this project's pinned recipe versions to the newest ones their ranges allow";
45
+
46
+ /**
47
+ * The other spelling of the topic. It lives under a hidden topic, so it is
48
+ * typable everywhere without ever reaching the top-level listing.
49
+ */
50
+ static aliases = ["subscriptions:update"];
51
+
52
+ static examples = [
53
+ "<%= config.bin %> subscription update",
54
+ "<%= config.bin %> subscription update sous-recipes",
55
+ "<%= config.bin %> subscription update workflow/task-files",
56
+ "<%= config.bin %> subscription update --dry-run",
57
+ "<%= config.bin %> subscription update --yes",
58
+ ];
59
+
60
+ static args = {
61
+ ref: Args.string({
62
+ description:
63
+ "What to update: a repository, a namespace or a recipe. Leave it out to update everything",
64
+ required: false,
65
+ }),
66
+ };
67
+
68
+ static flags = {
69
+ ...BaseCommand.baseFlags,
70
+ // One flag answers both questions this command can ask: the plan, and the
71
+ // trust question for a repository a newer version needs.
72
+ yes: confirmationFlag({ extraAliases: ["trust"] }),
73
+ "accept-first": Flags.boolean({
74
+ description:
75
+ "When the reference matches several things, take the first one listed",
76
+ default: false,
77
+ }),
78
+ "dry-run": Flags.boolean({
79
+ description:
80
+ "Print what would change without writing anything or downloading any recipe",
81
+ default: false,
82
+ }),
83
+ "no-build": Flags.boolean({
84
+ description: "Change the lockfile without rebuilding the project",
85
+ default: false,
86
+ }),
87
+ ...answerFlags(),
88
+ };
89
+
90
+ async run(): Promise<void> {
91
+ const { args, flags } = await this.parse(SubscriptionUpdate);
92
+ const dryRun = flags["dry-run"];
93
+
94
+ showCommandVars({
95
+ Project: this.projectLabel,
96
+ Config: this.configContext.configPath,
97
+ Updating: args.ref ?? "every subscription",
98
+ "Dry Run": dryRun,
99
+ });
100
+
101
+ heading("Updating");
102
+
103
+ if (dryRun) {
104
+ dryRunNotice(
105
+ "The indexes are fetched so the plan is current; no recipe is downloaded and " +
106
+ "nothing in this project is written."
107
+ );
108
+ }
109
+
110
+ const service = subscriptionServiceFor({
111
+ configContext: this.configContext,
112
+ settings: this.settings,
113
+ shellEnv: this.shellEnv,
114
+ });
115
+
116
+ const provided = collectProvidedAnswers({
117
+ ...(flags.answer === undefined ? {} : { answer: flags.answer }),
118
+ ...(flags["answers-file"] === undefined ? {} : { answersFile: flags["answers-file"] }),
119
+ });
120
+
121
+ const outcome = await service.update({
122
+ ...(args.ref === undefined ? {} : { ref: args.ref }),
123
+ yes: flags.yes,
124
+ acceptFirst: flags["accept-first"],
125
+ answers: provided,
126
+ dryRun,
127
+ });
128
+
129
+ const scope = describeUpdateScope(outcome.scope);
130
+
131
+ if (outcome.nothingToUpdate) {
132
+ footer();
133
+ return;
134
+ }
135
+
136
+ if (dryRun) {
137
+ paragraph(
138
+ `Nothing was written. Run the same command without '--dry-run' to update ${scope}.`
139
+ );
140
+ footer();
141
+ return;
142
+ }
143
+
144
+ blankLine();
145
+ subheading("Lockfile");
146
+ blankLine();
147
+ if (outcome.diff.unchanged) {
148
+ paragraph("Nothing changed.");
149
+ } else {
150
+ for (const line of outcome.diff.lines) log(indent(line));
151
+ }
152
+
153
+ if (outcome.trusted.length > 0) {
154
+ blankLine();
155
+ paragraph(
156
+ `Repositories trusted along the way: ${outcome.trusted.join(", ")}. They are ` +
157
+ `now recorded in this project's config, and your colleagues inherit them.`
158
+ );
159
+ }
160
+
161
+ if (outcome.answers !== undefined) {
162
+ blankLine();
163
+ subheading("Variables");
164
+ for (const line of formatAskReport(outcome.answers)) {
165
+ log(line === "" ? "" : indent(line));
166
+ }
167
+ }
168
+
169
+ if (outcome.cycles.length > 0) {
170
+ warning(
171
+ `Some of these recipes co-subscribe to each other in a circle:\n` +
172
+ outcome.cycles.map((cycle) => ` ${cycle.join(" -> ")}`).join("\n") +
173
+ `\nThat is unusual but not broken, and the lockfile was updated.`
174
+ );
175
+ }
176
+
177
+ const rebuilding = !flags["no-build"] && !outcome.diff.unchanged;
178
+
179
+ blankLine();
180
+ paragraph(
181
+ `The lockfile now pins the newest versions the ranges allow for ${scope}. ` +
182
+ `This project's subscriptions are exactly as they were.` +
183
+ (rebuilding || outcome.diff.unchanged ? "" : " The project was not rebuilt.")
184
+ );
185
+
186
+ footer();
187
+
188
+ if (rebuilding) await this.rebuildProject();
189
+ }
190
+
191
+ /**
192
+ * Rebuilds the project now that the lockfile has moved, so the outputs match
193
+ * the new versions when this command returns. The config is reloaded first,
194
+ * because a repository trusted along the way was written into a managed layer.
195
+ * A build that fails leaves the update in place, because it is already
196
+ * written; the message says so.
197
+ */
198
+ private async rebuildProject(): Promise<void> {
199
+ await this.reloadDiscoveredConfig();
200
+
201
+ heading("Building the project");
202
+
203
+ const succeeded = await buildProjectOutputs(this.settings, this.configContext);
204
+
205
+ footer();
206
+
207
+ if (!succeeded) {
208
+ throw new ConfigError(
209
+ `The lockfile was updated, but the build that followed it failed, so this ` +
210
+ `project's outputs may not match the new versions yet. The update itself is ` +
211
+ `recorded; fix what the build reported above and run 'sous build' again.`
212
+ );
213
+ }
214
+ }
215
+ }
@@ -313,6 +313,26 @@ export function extensibleObject<Shape extends z.ZodRawShape>(shape: Shape) {
313
313
  return z.preprocess(stripExtensionKeys, z.strictObject(shape));
314
314
  }
315
315
 
316
+ /**
317
+ * The `submissions` block a repo manifest and a recipe manifest may both carry:
318
+ * whether the recipes it covers take proposed changes, and where to send a
319
+ * change instead when they do not. On a repo manifest it covers every recipe;
320
+ * on a recipe manifest it covers that recipe, and wins over the repository's.
321
+ *
322
+ * submissions:
323
+ * allowed: false
324
+ * instead: Propose changes in sous-io/sous, under recipes/core/sous-skills/.
325
+ */
326
+ export const submissionsSchema = extensibleObject({
327
+ /** Whether a proposed change to the covered recipes is accepted. Defaults to true. */
328
+ allowed: z.boolean().default(true),
329
+ /** Where a change should go instead, printed when one is proposed anyway. */
330
+ instead: z.string().min(1, "must not be empty").optional(),
331
+ });
332
+
333
+ /** A validated `submissions` block. */
334
+ export type Submissions = z.infer<typeof submissionsSchema>;
335
+
316
336
  // --- Error reporting ----------------------------------------------------------------------------
317
337
 
318
338
  /** Renders a zod issue path (`["variables",0,"name"]`) as `variables[0].name`. */
@@ -4,7 +4,8 @@
4
4
  * A link redirects a repo's resolution away from the store and at a real
5
5
  * working copy on disk, which is how a maintainer edits recipes: edits happen
6
6
  * in a checkout, never in the store. `sous repo link` writes an entry;
7
- * `sous repo unlink` removes it and leaves the checkout in place.
7
+ * `sous repo unlink` removes it and leaves the checkout in place unless asked
8
+ * to delete one sous cloned.
8
9
  *
9
10
  * Two maps are read: the project's `.sous/sous.links.json` and the machine-wide
10
11
  * `$SOUS_HOME/sous.links.json`, with the project map winning on conflict. The
@@ -34,8 +35,9 @@ export const repoLinkSchema = z.strictObject({
34
35
  linkedAt: isoTimestampSchema,
35
36
  /**
36
37
  * Whether sous cloned the working copy itself ('clone') or was pointed at an
37
- * existing checkout ('path'). Unlinking never deletes either, but the origin
38
- * tells the user what sous put there.
38
+ * existing checkout ('path'). Unlinking leaves either in place unless
39
+ * `--remove` is passed, and even then only a 'clone' is ever deleted: a
40
+ * 'path' checkout belongs to whoever linked it.
39
41
  */
40
42
  origin: z.enum(LINK_ORIGINS),
41
43
  });