barndog 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (173) hide show
  1. package/README.md +11 -10
  2. package/dist/cli.js +11 -7
  3. package/dist/commands/add.js +33 -21
  4. package/dist/commands/arguments.js +12 -0
  5. package/dist/commands/asset-install.js +160 -0
  6. package/dist/commands/asset-list.js +121 -0
  7. package/dist/commands/asset-share.js +94 -0
  8. package/dist/commands/auth.js +4 -0
  9. package/dist/commands/availability.js +54 -26
  10. package/dist/commands/capabilities.js +71 -415
  11. package/dist/commands/collaboration.js +194 -110
  12. package/dist/commands/environment.js +18 -411
  13. package/dist/commands/github.js +200 -0
  14. package/dist/commands/helpers.js +39 -0
  15. package/dist/commands/hooks.js +87 -0
  16. package/dist/commands/init.js +4 -2
  17. package/dist/commands/knowledge.js +73 -0
  18. package/dist/commands/mcp.js +62 -0
  19. package/dist/commands/origin.js +21 -23
  20. package/dist/commands/people.js +51 -0
  21. package/dist/commands/sets.js +141 -0
  22. package/dist/commands/status.js +34 -24
  23. package/dist/commands/sync.js +11 -4
  24. package/dist/commands/workspace.js +33 -19
  25. package/dist/config/environment.js +13 -27
  26. package/dist/config/paths.js +62 -0
  27. package/dist/config/selection.js +30 -0
  28. package/dist/config/settings.js +97 -108
  29. package/dist/config/state.js +57 -57
  30. package/dist/entry/knowledge-startup.js +32 -0
  31. package/dist/entry/mcp-launch.js +71 -0
  32. package/dist/entry/opencode-plugin.js +62 -0
  33. package/dist/{features/git-workspace/startup.js → entry/workspace-startup.js} +7 -2
  34. package/dist/errors.js +198 -55
  35. package/dist/features/asset-kinds/index.js +120 -0
  36. package/dist/features/asset-selection/index.js +51 -19
  37. package/dist/features/auth/credentials.js +80 -47
  38. package/dist/features/auth/session.js +80 -45
  39. package/dist/features/auth/transport.js +66 -15
  40. package/dist/features/catalog/index.js +32 -61
  41. package/dist/features/collaboration/api.js +160 -0
  42. package/dist/features/collaboration/index.js +321 -233
  43. package/dist/features/collaboration/remote.js +35 -115
  44. package/dist/features/collaboration/results.js +2 -0
  45. package/dist/features/collaboration/workspace-git.js +233 -149
  46. package/dist/features/collaboration/workspace-github.js +117 -54
  47. package/dist/features/collaboration/workspace-store.js +140 -100
  48. package/dist/features/collaboration/workspace.js +257 -172
  49. package/dist/features/discovery/index.js +68 -57
  50. package/dist/features/doctor/index.js +32 -24
  51. package/dist/features/environment/auto-sync.js +28 -27
  52. package/dist/features/environment/names.js +67 -47
  53. package/dist/features/environment/operations.js +321 -228
  54. package/dist/features/environment/own-entries.js +89 -0
  55. package/dist/features/environment/settle-names.js +91 -0
  56. package/dist/features/environment/stage.js +178 -0
  57. package/dist/features/environment/sync.js +113 -484
  58. package/dist/features/environment/transaction.js +179 -147
  59. package/dist/features/environment/writes.js +196 -0
  60. package/dist/features/github/account.js +25 -0
  61. package/dist/features/github/connections.js +119 -0
  62. package/dist/features/github/pulls.js +118 -0
  63. package/dist/features/hooks/adapt.js +32 -25
  64. package/dist/features/hooks/catalog.js +28 -0
  65. package/dist/features/hooks/compatibility.js +49 -0
  66. package/dist/features/hooks/divergence.js +9 -6
  67. package/dist/features/hooks/test.js +74 -49
  68. package/dist/features/hooks/types.js +1 -0
  69. package/dist/features/imports/discover.js +134 -61
  70. package/dist/features/imports/folder.js +48 -14
  71. package/dist/features/imports/local.js +113 -134
  72. package/dist/features/imports/remote.js +44 -25
  73. package/dist/features/inspection/index.js +17 -17
  74. package/dist/features/inventory/index.js +99 -110
  75. package/dist/features/knowledge/index.js +69 -49
  76. package/dist/features/mcps/catalog.js +31 -0
  77. package/dist/features/mcps/import.js +316 -0
  78. package/dist/features/mcps/index.js +98 -49
  79. package/dist/features/migration/migrate.js +263 -0
  80. package/dist/features/{git-workspace → migration}/move.js +165 -109
  81. package/dist/features/migration/promote.js +24 -0
  82. package/dist/features/native/adapters.js +53 -94
  83. package/dist/features/native/configuration.js +128 -82
  84. package/dist/features/native/hook-shell.js +55 -0
  85. package/dist/features/native/plugin-module.js +56 -0
  86. package/dist/features/onboarding/environment.js +67 -34
  87. package/dist/features/onboarding/setup.js +43 -40
  88. package/dist/features/repositories/context.js +30 -13
  89. package/dist/features/server/catalog.js +58 -0
  90. package/dist/features/server/client.js +13 -0
  91. package/dist/features/server/connection.js +37 -0
  92. package/dist/features/server/origin.js +74 -0
  93. package/dist/features/server/pages.js +24 -0
  94. package/dist/features/skills/catalog.js +42 -0
  95. package/dist/features/workspace/assets.js +57 -0
  96. package/dist/features/workspace/cloud-source.js +34 -0
  97. package/dist/features/workspace/directory.js +38 -0
  98. package/dist/features/{git-workspace → workspace}/format.js +114 -51
  99. package/dist/features/workspace/git.js +214 -0
  100. package/dist/features/workspace/installed.js +92 -0
  101. package/dist/features/{git-workspace → workspace}/overlay.js +43 -23
  102. package/dist/features/workspace/packages.js +160 -0
  103. package/dist/features/{git-workspace → workspace}/publish.js +120 -64
  104. package/dist/features/workspace/repo-source.js +192 -0
  105. package/dist/features/{git-workspace → workspace}/setup.js +60 -42
  106. package/dist/features/{git-workspace → workspace}/snapshot.js +53 -18
  107. package/dist/features/workspace/source.js +1 -0
  108. package/dist/features/workspace/tree.js +52 -0
  109. package/dist/features/workspace/workspace-source.js +27 -0
  110. package/dist/harnesses/claude.js +23 -1
  111. package/dist/harnesses/codex.js +57 -1
  112. package/dist/harnesses/cursor.js +22 -1
  113. package/dist/harnesses/detect.js +6 -50
  114. package/dist/harnesses/formats.js +45 -0
  115. package/dist/harnesses/opencode.js +111 -0
  116. package/dist/harnesses/registry.js +35 -2
  117. package/dist/platform.js +375 -0
  118. package/dist/program.js +225 -54
  119. package/dist/runtime.js +1 -0
  120. package/dist/shared/cli-error.js +22 -0
  121. package/dist/shared/constants.js +32 -0
  122. package/dist/shared/files.js +72 -0
  123. package/dist/shared/lock.js +49 -0
  124. package/dist/shared/lookup.js +11 -0
  125. package/dist/shared/patterns.js +94 -0
  126. package/dist/shared/shell.js +22 -0
  127. package/dist/shared/values.js +26 -0
  128. package/dist/ui/add-asset.js +41 -400
  129. package/dist/ui/add-hook.js +213 -0
  130. package/dist/ui/add-mcp.js +107 -0
  131. package/dist/ui/add-prompts.js +47 -0
  132. package/dist/ui/add-skills.js +115 -0
  133. package/dist/ui/asset-list.js +31 -13
  134. package/dist/ui/assets.js +33 -44
  135. package/dist/ui/auth.js +43 -33
  136. package/dist/ui/clash.js +11 -6
  137. package/dist/ui/collaboration.js +116 -44
  138. package/dist/ui/connection.js +10 -4
  139. package/dist/ui/decision-error.js +24 -0
  140. package/dist/ui/environment-onboarding.js +35 -13
  141. package/dist/ui/format.js +66 -18
  142. package/dist/ui/hook-compatibility.js +14 -6
  143. package/dist/ui/mcp.js +28 -3
  144. package/dist/ui/move.js +10 -5
  145. package/dist/ui/onboarding.js +113 -73
  146. package/dist/ui/options.js +9 -0
  147. package/dist/ui/output.js +106 -43
  148. package/dist/ui/pick.js +45 -33
  149. package/dist/ui/scope-install.js +15 -7
  150. package/dist/ui/selection.js +15 -11
  151. package/dist/ui/theme.js +37 -14
  152. package/dist/version.js +6 -3
  153. package/package.json +24 -11
  154. package/dist/features/capabilities/index.js +0 -106
  155. package/dist/features/collaboration/domain.js +0 -90
  156. package/dist/features/environment/cloud-source.js +0 -27
  157. package/dist/features/environment/installed.js +0 -124
  158. package/dist/features/environment/packages.js +0 -120
  159. package/dist/features/environment/remote.js +0 -71
  160. package/dist/features/environment/workspace-source.js +0 -19
  161. package/dist/features/git-hosts/index.js +0 -148
  162. package/dist/features/git-workspace/assets.js +0 -71
  163. package/dist/features/git-workspace/git.js +0 -135
  164. package/dist/features/git-workspace/migrate.js +0 -188
  165. package/dist/features/git-workspace/source.js +0 -159
  166. package/dist/features/imports/mcp.js +0 -219
  167. package/dist/features/knowledge/startup.js +0 -25
  168. package/dist/features/native/mcp-launch.js +0 -57
  169. package/dist/features/skills/install.js +0 -25
  170. package/dist/features/skills/remote.js +0 -177
  171. package/dist/features/skills/sync.js +0 -121
  172. package/dist/features/skills/validation.js +0 -34
  173. /package/dist/features/environment/{source.js → events.js} +0 -0
@@ -1,65 +1,129 @@
1
+ import { HTTP_STATUS } from "../shared/constants.js";
1
2
  import { InvalidArgumentError } from "commander";
2
3
  import { styleText } from "node:util";
3
4
  import { renderCollaboration } from "../ui/collaboration.js";
4
5
  import { folderDivergence, nearestHookFolder, } from "../features/hooks/divergence.js";
5
6
  import { resolve } from "node:path";
6
- import { CliError, friendlyHint, friendlyMessage } from "../errors.js";
7
+ import { CHANGES_LIST_FIX, CliError, friendlyHint, friendlyMessage, } from "../errors.js";
7
8
  import { ApiError } from "@barndog-ai/api-contract";
9
+ import { assetKinds } from "../features/asset-kinds/index.js";
10
+ import { packageKindList } from "../config/selection.js";
8
11
  import { pickOne } from "../ui/pick.js";
9
12
  import { resolveOrigin } from "./origin.js";
10
13
  import { clean, json, ORIGIN_HELP, originLabel, warn } from "../ui/format.js";
11
- function positive(value) {
12
- if (!/^[1-9][0-9]*$/.test(value) || !Number.isSafeInteger(Number(value)))
13
- throw new InvalidArgumentError("Expected a positive integer");
14
- return Number(value);
14
+ import { defined } from "../shared/lookup.js";
15
+ import { positiveInteger } from "../ui/options.js";
16
+ function side(value) {
17
+ if (value !== "old" && value !== "new") {
18
+ throw new InvalidArgumentError("Expected old or new");
19
+ }
20
+ return value;
21
+ }
22
+ /** Prints a working-copy or review result, as JSON with `--json`. */
23
+ function printer(context) {
24
+ return (result, options = {}) => {
25
+ if (context.mode.json) {
26
+ context.write(json(result));
27
+ }
28
+ else {
29
+ for (const line of renderCollaboration(result, options)) {
30
+ context.write(line);
31
+ }
32
+ }
33
+ };
34
+ }
35
+ /** Warns when a Hook's coding tools run different scripts; editing is when that matters. */
36
+ async function warnDivergence(context, folder) {
37
+ const warning = !context.mode.json && folder && (await folderDivergence(folder));
38
+ if (warning) {
39
+ context.write(`${warn("!")} ${warning}`);
40
+ }
15
41
  }
16
- /** Skill and Hook changes are separate lists; point at the other when an ID isn't here. */
17
- function reviewError(error, kind, options) {
18
- if (!(error instanceof ApiError))
42
+ /** Each package kind has its own list of changes; point at the others when an ID isn't here. */
43
+ function reviewError(error, kind, { changeId, thread }) {
44
+ if (!(error instanceof ApiError)) {
19
45
  return error;
20
- if (error.status === 404 && options.id && !options.thread)
21
- return new CliError(`No ${kind === "skill" ? "Skill" : "Hook"} Suggested Change has that ID.`, `barndog ${kind === "skill" ? "hooks changes" : "changes"} show ${options.id}`, { cause: error });
22
- const hint = friendlyHint(error);
23
- return kind === "hook" && hint
24
- ? new CliError(friendlyMessage(error), hint.replace(/^barndog changes/, "barndog hooks changes"), { cause: error })
46
+ }
47
+ if (error.status === HTTP_STATUS.notFound && changeId && !thread) {
48
+ return new CliError(`No ${assetKinds[kind].one} Suggested Change has that ID.`, packageKindList
49
+ .filter((other) => other !== kind)
50
+ .map((other) => `barndog ${assetKinds[other].command} changes show ${changeId}`)
51
+ .join(" or "), { cause: error });
52
+ }
53
+ // A server refusal doesn't say which kind's change it is about; this command knows.
54
+ return friendlyHint(error) === CHANGES_LIST_FIX
55
+ ? new CliError(friendlyMessage(error), `barndog ${assetKinds[kind].command} changes list`, { cause: error })
25
56
  : error;
26
57
  }
27
- export function registerCollaboration(program, context, kind = "skill") {
28
- const run = async (action, options = {}) => {
29
- const result = await context
30
- .collaborate(action, kind === "hook" ? { ...options, kind } : options)
31
- .catch((error) => {
58
+ /**
59
+ * The working-copy commands at the root: `pull`, `diff`, `push` and `resolve`.
60
+ * They act on whatever the working copy holds, so they name no kind; a new
61
+ * folder's kind comes from its manifest file.
62
+ */
63
+ export function registerWorkingCopy(program, context) {
64
+ const print = printer(context);
65
+ program
66
+ .command("pull")
67
+ .description("Bring the latest published version into this working copy, keeping your edits")
68
+ .action(async () => print(await context.updateWorkingCopy()));
69
+ program
70
+ .command("diff")
71
+ .description("Show your edits in this working copy (elsewhere: preview what sync would change)")
72
+ .action(async () => print(await context.workingDiff()));
73
+ program
74
+ .command("push")
75
+ .description("Propose this working copy's edits as a Suggested Change")
76
+ .option("--origin <origin>", "Origin for a folder that isn't a working copy yet")
77
+ .option("--publish", "Publish directly with admin or personal-owner authority")
78
+ .option("--new", "Start a new proposal instead of updating the linked proposal")
79
+ .option("--title <title>", "Suggested Change title")
80
+ .action(async (options) => {
81
+ print(await context.pushWorkingCopy(options));
82
+ await warnDivergence(context, nearestHookFolder(context.runtime.cwd));
83
+ });
84
+ program
85
+ .command("resolve <path>")
86
+ .description("Mark a conflicted file in this working copy as resolved")
87
+ .action(async (path) => print(await context.resolveFile(path)));
88
+ }
89
+ /**
90
+ * Registers working-copy and review commands; handlers use the supplied
91
+ * services and output mode.
92
+ */
93
+ export function registerCollaboration(program, context, kind) {
94
+ const withKind = (options) => ({ ...options, kind });
95
+ const print = printer(context);
96
+ const run = async (operation, options = {}) => {
97
+ const result = await operation.catch((error) => {
32
98
  throw reviewError(error, kind, options);
33
99
  });
34
- if (context.mode.json) {
35
- context.write(json(result));
36
- return;
100
+ print(result, options);
101
+ };
102
+ /** Editing is when tools drifting apart matters, so Hooks say it at both ends. */
103
+ const divergence = async (folder) => {
104
+ if (kind === "hook") {
105
+ await warnDivergence(context, folder);
37
106
  }
38
- for (const line of renderCollaboration(action, result))
39
- context.write(line);
40
- if (kind !== "hook" || (action !== "pull-skill" && action !== "push"))
41
- return;
42
- // Editing is when tools drifting apart matters, so say it at both ends.
43
- const pulled = action === "pull-skill"
44
- ? (result?.root ??
45
- resolve(options.directory ?? options.name ?? "."))
46
- : nearestHookFolder(process.cwd());
47
- const warning = pulled && (await folderDivergence(pulled));
48
- if (warning)
49
- context.write(`${warn("!")} ${warning}`);
50
107
  };
51
- const skills = program.commands.find((c) => c.name() === (kind === "hook" ? "hooks" : "skills"));
52
- const noun = kind === "skill" ? "Skill" : "Hook";
53
- const group = kind === "skill" ? "skills" : "hooks";
108
+ const noun = assetKinds[kind].one;
109
+ const group = assetKinds[kind].command;
110
+ const kindCommand = defined(program.commands.find((c) => c.name() === group), `Command group ${group} isn't registered`);
54
111
  /** Fills a missing name and origin from a searchable catalog list. */
55
112
  const choose = async (name, origin, usage) => {
56
- if (name)
113
+ if (name) {
57
114
  return {
58
115
  name,
59
- origin: await resolveOrigin(context, kind, name, origin, usage.replace("<name>", name)),
116
+ origin: await resolveOrigin(context, {
117
+ kind,
118
+ name,
119
+ origin,
120
+ usage: usage.replace("<name>", name),
121
+ }),
60
122
  };
61
- if (!context.mode.interactive)
123
+ }
124
+ if (!context.mode.interactive) {
62
125
  throw new CliError(`Name the ${noun} to use.`, usage);
126
+ }
63
127
  const rows = await context.searchCatalog(kind);
64
128
  const row = await pickOne(`Choose a ${noun}`, rows.map((row) => ({
65
129
  value: row,
@@ -68,136 +132,156 @@ export function registerCollaboration(program, context, kind = "skill") {
68
132
  })), { empty: `No ${noun}s are published yet.` });
69
133
  return { name: row.name, origin: originLabel(row.origin) };
70
134
  };
71
- skills
135
+ kindCommand
72
136
  .command("pull [name]")
73
137
  .option("--origin <origin>", ORIGIN_HELP)
74
138
  .option("--directory <path>", "Folder for the editable copy")
75
139
  .description(`Download a ${noun} into an editable folder to change and propose edits`)
76
- .action(async (name, options) => run("pull-skill", {
77
- ...options,
78
- ...(await choose(name, options.origin, `barndog ${group} pull <name>`)),
79
- }));
80
- if (kind === "skill") {
81
- for (const [command, description] of [
82
- [
83
- "pull",
84
- "Bring the latest published version into this working copy, keeping your edits",
85
- ],
86
- [
87
- "diff",
88
- "Show your edits in this working copy (elsewhere: preview what sync would change)",
89
- ],
90
- ])
91
- program
92
- .command(command)
93
- .description(description)
94
- .action(() => run(command));
95
- program
96
- .command("push")
97
- .description("Propose this working copy's edits as a Suggested Change")
98
- .option("--origin <origin>", "Origin for a new local Skill")
99
- .option("--publish", "Publish directly with admin or personal-owner authority")
100
- .option("--new", "Start a new proposal instead of updating the linked proposal")
101
- .option("--title <title>", "Suggested Change title")
102
- .action((options) => run("push", options));
103
- program
104
- .command("resolve <path>")
105
- .description("Mark a conflicted file in this working copy as resolved")
106
- .action((path) => run("resolve", { path }));
107
- }
108
- for (const [name, action, description] of [
140
+ .action(async (name, options) => {
141
+ const target = {
142
+ ...options,
143
+ ...(await choose(name, options.origin, `barndog ${group} pull <name>`)),
144
+ };
145
+ const pulled = context.pullPackage(withKind(target));
146
+ await run(pulled);
147
+ await divergence((await pulled)?.root ??
148
+ resolve(context.runtime.cwd, target.directory ?? target.name));
149
+ });
150
+ for (const [name, description] of [
109
151
  [
110
- "versions",
111
152
  "versions",
112
153
  `List ${noun === "Skill" ? "a Skill's" : "a Hook's"} published versions`,
113
154
  ],
114
- ["show", "version-show", "Print the files of a published version"],
115
- ["diff", "version-diff", "Compare two published versions"],
155
+ ["show", "Print the files of a published version"],
156
+ ["diff", "Compare two published versions"],
116
157
  ]) {
117
- const command = skills
158
+ const command = kindCommand
118
159
  .command(`${name} [name]`)
119
160
  .description(description)
120
161
  .option("--origin <origin>", ORIGIN_HELP);
121
- if (name === "show")
122
- command.option("--version <number>", "Published version", positive);
123
- if (name === "diff")
162
+ if (name === "show") {
163
+ command.option("--version <number>", "Published version", positiveInteger);
164
+ }
165
+ if (name === "diff") {
124
166
  command
125
- .requiredOption("--from <number>", "Old version", positive)
126
- .requiredOption("--to <number>", "New version", positive);
127
- command.action(async (asset, options) => run(action, {
128
- ...options,
129
- ...(await choose(asset, options.origin, `barndog ${group} ${name} <name>`)),
130
- }));
167
+ .requiredOption("--from <number>", "Old version", positiveInteger)
168
+ .requiredOption("--to <number>", "New version", positiveInteger);
169
+ }
170
+ command.action(async (asset, options) => {
171
+ const target = withKind({
172
+ ...options,
173
+ ...(await choose(asset, options.origin, `barndog ${group} ${name} <name>`)),
174
+ });
175
+ if (name === "versions") {
176
+ await run(context.packageVersions(target));
177
+ }
178
+ else if (name === "show") {
179
+ await run(context.versionFiles(target));
180
+ }
181
+ else {
182
+ await run(context.diffVersions(target));
183
+ }
184
+ });
131
185
  }
132
- skills
186
+ kindCommand
133
187
  .command("push [name]")
134
188
  .description("Propose this working copy's edits as a Suggested Change")
135
189
  .option("--origin <origin>", "Scope for a new package, such as team/engineering")
136
190
  .option("--publish", "Publish with direct authority")
137
191
  .option("--new", "Start a new proposal")
138
192
  .option("--title <title>", "Proposal title")
139
- .action((name, options) => run("push", { ...options, name }));
140
- skills
193
+ .action(async (name, options) => {
194
+ await run(context.pushWorkingCopy(withKind({ ...options, name })));
195
+ await divergence(nearestHookFolder(context.runtime.cwd));
196
+ });
197
+ kindCommand
141
198
  .command("create <name>")
142
199
  .requiredOption("--origin <origin>", ORIGIN_HELP)
143
200
  .option("--directory <path>", "New editable folder")
144
201
  .description(`Start a new ${noun} in an editable folder (not installed until published)`)
145
- .action((name, options) => run("create", { ...options, name }));
146
- for (const parent of kind === "hook" ? [skills] : [program, skills])
147
- registerChanges(parent, run);
202
+ .action((name, options) => run(context.createPackage(withKind({ ...options, name }))));
203
+ registerChanges(kindCommand, context, withKind, run);
148
204
  }
149
- function registerChanges(parent, run) {
205
+ function registerChanges(parent, context, withKind, run) {
150
206
  const changes = parent
151
207
  .command("changes")
152
208
  .description("Review, discuss and merge Suggested Changes");
153
209
  changes
154
210
  .command("list")
155
211
  .description("List accessible Suggested Changes")
156
- .action(() => run("list"));
212
+ .action(() => run(context.listChanges(withKind({}))));
157
213
  changes
158
214
  .command("show <id>")
159
215
  .description("Read proposal content, reviews, and discussion history")
160
- .action((id) => run("show", { id }));
216
+ .action((id) => run(context.showChange(withKind({ id })), {
217
+ changeId: id,
218
+ details: true,
219
+ }));
161
220
  changes
162
221
  .command("diff <id>")
163
222
  .description("Inspect a proposal diff")
164
- .option("--revision <number>", "Proposal revision", positive)
165
- .option("--from-revision <number>", "Compare to another proposal revision", positive)
166
- .action((id, options) => run("change-diff", { ...options, id }));
223
+ .option("--revision <number>", "Proposal revision", positiveInteger)
224
+ .option("--from-revision <number>", "Compare to another proposal revision", positiveInteger)
225
+ .action((id, options) => run(context.changeDiff(withKind({ ...options, id })), {
226
+ changeId: id,
227
+ }));
167
228
  for (const [name, description] of [
168
229
  ["approve", "Approve a reviewed revision"],
169
230
  ["request-changes", "Request further changes"],
170
231
  ["reject", "Close a proposal as its author or admin"],
171
232
  ["merge", "Publish a proposal under its scope's merge rules"],
172
- ])
233
+ ]) {
173
234
  changes
174
235
  .command(`${name} <id>`)
175
236
  .description(description)
176
- .requiredOption("--revision <number>", "Revision you reviewed", positive)
177
- .action((id, options) => run(name, { ...options, id }));
237
+ .requiredOption("--revision <number>", "Revision you reviewed", positiveInteger)
238
+ .action((id, options) => {
239
+ const target = withKind({ ...options, id });
240
+ const labels = { changeId: id };
241
+ if (name === "reject") {
242
+ return run(context.rejectChange(target), labels);
243
+ }
244
+ if (name === "merge") {
245
+ return run(context.mergeChange(target), labels);
246
+ }
247
+ return run(context.reviewChange(name, target), labels);
248
+ });
249
+ }
178
250
  changes
179
251
  .command("comment <id>")
180
252
  .description("Comment, reply, or suggest an inline replacement")
181
- .requiredOption("--revision <number>", "Proposal revision", positive)
253
+ .requiredOption("--revision <number>", "Proposal revision", positiveInteger)
182
254
  .option("--body <text>", "Comment text")
183
255
  .option("--body-file <path>", "Read comment text from a file")
184
256
  .option("--thread <id>", "Reply to a discussion")
185
257
  .option("--path <path>", "Package file for an inline discussion")
186
- .option("--side <side>", "old or new")
187
- .option("--start-line <number>", "First line", positive)
188
- .option("--end-line <number>", "Last line", positive)
258
+ .option("--side <side>", "old or new", side)
259
+ .option("--start-line <number>", "First line", positiveInteger)
260
+ .option("--end-line <number>", "Last line", positiveInteger)
189
261
  .option("--replacement-file <path>", "Replacement text file")
190
262
  .option("--expected-file <path>", "Exact original text file")
191
- .action((id, options) => run("comment", { ...options, id }));
263
+ .action((id, options) => run(context.commentOnChange(withKind({ ...options, id })), {
264
+ changeId: id,
265
+ thread: options.thread,
266
+ }));
192
267
  for (const [name, description] of [
193
268
  ["apply", "Apply a current reviewer suggestion"],
194
269
  ["resolve-discussion", "Resolve a discussion"],
195
270
  ["reopen-discussion", "Reopen a discussion"],
196
- ])
271
+ ]) {
197
272
  changes
198
273
  .command(`${name} <id> <thread>`)
199
274
  .description(description)
200
- .requiredOption("--revision <number>", "Current proposal revision", positive)
201
- .action((id, thread, options) => run(name, { ...options, id, thread }));
202
- changes.addHelpText("after", `\nReview ${styleText("bold", "barndog changes diff <id>")} before approving a revision. Approval does not publish; use ${styleText("bold", "barndog changes merge <id> --revision <number>")}.`);
275
+ .requiredOption("--revision <number>", "Current proposal revision", positiveInteger)
276
+ .action((id, thread, options) => {
277
+ const target = withKind({ ...options, id, thread });
278
+ return run(name === "apply"
279
+ ? context.applySuggestion(target)
280
+ : context.setDiscussionResolved({
281
+ ...target,
282
+ resolved: name === "resolve-discussion",
283
+ }), { changeId: id, thread });
284
+ });
285
+ }
286
+ changes.addHelpText("after", `\nReview ${styleText("bold", `barndog ${parent.name()} changes diff <id>`)} before approving a revision. Approval does not publish; use ${styleText("bold", `barndog ${parent.name()} changes merge <id> --revision <number>`)}.`);
203
287
  }