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,12 +1,11 @@
1
- import { skillName } from "../skills/validation.js";
2
- /** Human scope label such as local, org, team/engineering, repo/web or dev/john. */
3
- export function originLabel(origin) {
4
- if (origin.localOnly || origin.type === "local")
5
- return "local";
6
- return origin.type === "org"
7
- ? "org"
8
- : `${origin.type}/${origin.slug ?? origin.id ?? "unknown"}`;
9
- }
1
+ import { slugify } from "../../shared/patterns.js";
2
+ import { assetKinds } from "../asset-kinds/index.js";
3
+ /** Eight ID characters distinguish hooks with the same display name. */
4
+ const HOOK_ID_SUFFIX_LENGTH = 8;
5
+ /** Unknown origins sort after all explicitly ranked origins. */
6
+ const UNKNOWN_ORIGIN_RANK = 9;
7
+ /** Allow repeated scope and ID disambiguation before declaring a collision. */
8
+ const NAME_RESOLUTION_PASSES_PER_ASSET = 4;
10
9
  const rank = {
11
10
  local: 0,
12
11
  dev: 1,
@@ -16,20 +15,28 @@ const rank = {
16
15
  };
17
16
  /** `<origin-type>-<origin-slug>-<name>` with single hyphens, e.g. team-super-team-review. */
18
17
  export function prefixedName(asset) {
19
- return [
18
+ const prefix = [
20
19
  asset.origin.type,
21
20
  asset.origin.slug ?? asset.origin.id ?? "",
22
- asset.name,
23
- ]
24
- .join("-")
25
- .toLowerCase()
26
- .replace(/[^a-z0-9]+/g, "-")
27
- .replace(/^-+|-+$/g, "");
28
- }
29
- export function validInstalledName(name) {
30
- return skillName.test(name) && name.length <= 64;
21
+ ].join("-");
22
+ // An MCP server keeps its own spelling, such as my_server; only the prefix is a slug.
23
+ return asset.kind === "mcp"
24
+ ? `${slugify(prefix)}-${asset.name}`
25
+ : slugify(`${prefix}-${asset.name}`);
31
26
  }
27
+ /**
28
+ * The name an asset installs under: its saved rename from `localNames`, else
29
+ * its published name.
30
+ */
32
31
  export const installedName = (asset, localNames) => localNames[asset.id] ?? asset.name;
32
+ /** A folder name with a trailing copy number, `review-1a2b-2`; group 1 is the rest. */
33
+ const COPY_NUMBER = /^(.*)-\d+$/;
34
+ /**
35
+ * `review-1a2b-2` → `review-1a2b`; undefined when there is no copy number.
36
+ *
37
+ * @internal Exported for its table test in `src/tests/patterns.test.ts`.
38
+ */
39
+ export const withoutCopyNumber = (folder) => COPY_NUMBER.exec(folder)?.[1];
33
40
  /**
34
41
  * Origin prefixes are ambiguous: team a's b-c and team a-b's c read the same. Each
35
42
  * Hook gets its own folder: kept and already-installed folders stay put, a name only
@@ -42,66 +49,77 @@ export function hookFolders(hooks, localNames) {
42
49
  folders.set(hook.id, folder);
43
50
  used.add(folder);
44
51
  };
45
- const plain = (hook) => localNames[hook.id] ?? prefixedName(hook);
52
+ const plain = (hook) => localNames[hook.id] ?? prefixedName({ ...hook, kind: "hook" });
46
53
  const idText = (hook) => hook.id.replace(/[^a-z0-9]/gi, "").toLowerCase();
47
- const suffixed = (hook) => `${plain(hook)}-${idText(hook).slice(0, 8)}`;
54
+ const suffixed = (hook) => `${plain(hook)}-${idText(hook).slice(0, HOOK_ID_SUFFIX_LENGTH)}`;
48
55
  const whole = (hook) => `${plain(hook)}-${idText(hook)}`;
49
56
  const ordered = [...hooks].sort((a, b) => a.id.localeCompare(b.id));
50
57
  const open = () => ordered.filter((hook) => !folders.has(hook.id));
51
- for (const hook of ordered)
52
- if (hook.kept)
58
+ for (const hook of ordered) {
59
+ if (hook.kept) {
53
60
  claim(hook, hook.kept);
54
- for (const hook of open())
61
+ }
62
+ }
63
+ for (const hook of open()) {
55
64
  if (hook.current &&
56
65
  !used.has(hook.current) &&
57
66
  (hook.current === plain(hook) ||
58
67
  hook.current === suffixed(hook) ||
59
68
  hook.current === whole(hook) ||
60
- hook.current.match(/^(.*)-\d+$/)?.[1] === whole(hook)))
69
+ withoutCopyNumber(hook.current) === whole(hook))) {
61
70
  claim(hook, hook.current);
71
+ }
72
+ }
62
73
  const wanting = open().map(plain);
63
- for (const hook of open())
74
+ for (const hook of open()) {
64
75
  if (!used.has(plain(hook)) &&
65
- wanting.filter((folder) => folder === plain(hook)).length === 1)
76
+ wanting.filter((folder) => folder === plain(hook)).length === 1) {
66
77
  claim(hook, plain(hook));
78
+ }
79
+ }
67
80
  for (const hook of open()) {
68
81
  let folder = used.has(suffixed(hook)) ? whole(hook) : suffixed(hook);
69
- for (let n = 2; used.has(folder); n++)
82
+ for (let n = 2; used.has(folder); n++) {
70
83
  folder = `${whole(hook)}-${n}`;
84
+ }
71
85
  claim(hook, folder);
72
86
  }
73
87
  return folders;
74
88
  }
75
89
  /** Drops automatic renames whose plain name is free again; explicit names stay. */
76
- export function restoreNames(assets, localNames) {
90
+ function restoreNames(assets, localNames) {
77
91
  const next = { ...localNames };
78
92
  for (const asset of assets) {
79
- if (asset.renamable === false || next[asset.id] !== prefixedName(asset))
93
+ if (asset.renamable === false || next[asset.id] !== prefixedName(asset)) {
80
94
  continue;
95
+ }
81
96
  const taken = assets.some((other) => other.id !== asset.id &&
82
97
  other.kind === asset.kind &&
83
98
  installedName(other, next) === asset.name);
84
- if (!taken)
99
+ if (!taken) {
85
100
  delete next[asset.id];
101
+ }
86
102
  }
87
103
  return next;
88
104
  }
89
105
  /** The first clash in a stable order; the asset already installed (or most specific scope) keeps the name. */
90
- export function findClash(assets, localNames) {
106
+ function findClash(assets, localNames) {
91
107
  const groups = new Map();
92
108
  for (const asset of assets) {
93
109
  const key = `${asset.kind}\0${installedName(asset, localNames)}`;
94
110
  groups.set(key, [...(groups.get(key) ?? []), asset]);
95
111
  }
96
- for (const [key, group] of [...groups].sort(([a], [b]) => a.localeCompare(b))) {
97
- if (group.length < 2)
98
- continue;
112
+ for (const [, group] of [...groups].sort(([a], [b]) => a.localeCompare(b))) {
99
113
  const [installed, incoming] = [...group].sort((a, b) => Number(b.installed) - Number(a.installed) ||
100
- (rank[a.origin.type] ?? 9) - (rank[b.origin.type] ?? 9) ||
114
+ (rank[a.origin.type] ?? UNKNOWN_ORIGIN_RANK) -
115
+ (rank[b.origin.type] ?? UNKNOWN_ORIGIN_RANK) ||
101
116
  a.id.localeCompare(b.id));
117
+ if (!installed || !incoming) {
118
+ continue;
119
+ }
102
120
  return {
103
121
  kind: installed.kind,
104
- name: key.split("\0")[1],
122
+ name: installedName(installed, localNames),
105
123
  installed,
106
124
  incoming,
107
125
  installedRename: prefixedName(installed),
@@ -119,24 +137,28 @@ export async function resolveClashes(assets, localNames, resolver) {
119
137
  let active = [...assets];
120
138
  const disabled = [];
121
139
  const skipped = [];
122
- for (let guard = 0; guard < assets.length * 4 + 4; guard++) {
140
+ for (let guard = 0; guard <
141
+ assets.length * NAME_RESOLUTION_PASSES_PER_ASSET +
142
+ NAME_RESOLUTION_PASSES_PER_ASSET; guard++) {
123
143
  const clash = findClash(active, names);
124
- if (!clash)
144
+ if (!clash) {
125
145
  return { localNames: names, disabledAssetIds: disabled, skipped };
146
+ }
126
147
  let choice = resolver ? await resolver(clash) : "skip-incoming";
127
- const rename = choice === "rename-incoming"
128
- ? clash.incoming
129
- : choice === "rename-installed"
130
- ? clash.installed
131
- : undefined;
148
+ const renames = {
149
+ "rename-incoming": clash.incoming,
150
+ "rename-installed": clash.installed,
151
+ };
152
+ const rename = renames[choice];
132
153
  if (rename) {
133
154
  const name = prefixedName(rename);
134
155
  if (rename.renamable === false ||
135
- !validInstalledName(name) ||
156
+ !assetKinds[rename.kind].validName(name) ||
136
157
  active.some((other) => other.id !== rename.id &&
137
158
  other.kind === rename.kind &&
138
- installedName(other, names) === name))
159
+ installedName(other, names) === name)) {
139
160
  choice = "skip-incoming";
161
+ }
140
162
  else {
141
163
  names = { ...names, [rename.id]: name };
142
164
  continue;
@@ -144,10 +166,12 @@ export async function resolveClashes(assets, localNames, resolver) {
144
166
  }
145
167
  const removed = choice === "replace-installed" ? clash.installed : clash.incoming;
146
168
  active = active.filter((asset) => asset.id !== removed.id);
147
- if (resolver)
169
+ if (resolver) {
148
170
  disabled.push(removed.id);
149
- else
171
+ }
172
+ else {
150
173
  skipped.push(clash);
174
+ }
151
175
  }
152
- throw new Error("Unable to resolve installed name clashes");
176
+ throw new Error("Installed names still clash after renaming");
153
177
  }