barndog 0.1.1 → 0.2.1

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