barndog 0.2.1 → 0.2.3
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.
- package/README.md +21 -0
- package/dist/cli.js +29 -3
- package/dist/commands/add.js +4 -2
- package/dist/commands/asset-install.js +7 -3
- package/dist/commands/asset-list.js +5 -1
- package/dist/commands/asset-share.js +15 -3
- package/dist/commands/capabilities.js +23 -5
- package/dist/commands/collaboration.js +9 -3
- package/dist/commands/harnesses.js +33 -3
- package/dist/commands/hooks.js +16 -1
- package/dist/commands/mcp-env.js +159 -43
- package/dist/commands/mcp.js +13 -3
- package/dist/commands/origin.js +7 -4
- package/dist/commands/sets.js +16 -5
- package/dist/commands/status.js +3 -1
- package/dist/commands/sync.js +1 -1
- package/dist/commands/uninstall.js +64 -0
- package/dist/commands/workspace.js +19 -0
- package/dist/config/paths.js +2 -0
- package/dist/config/state.js +19 -0
- package/dist/entry/update-check.js +15 -0
- package/dist/errors.js +4 -0
- package/dist/features/adoption/adopt.js +47 -29
- package/dist/features/adoption/scan.js +5 -0
- package/dist/features/asset-kinds/url-query.js +26 -0
- package/dist/features/auth/session.js +22 -0
- package/dist/features/collaboration/workspace-store.js +2 -1
- package/dist/features/doctor/check.js +1 -0
- package/dist/features/doctor/grouped.js +127 -0
- package/dist/features/doctor/index.js +29 -27
- package/dist/features/environment/events.js +18 -1
- package/dist/features/environment/kept-value-events.js +40 -0
- package/dist/features/environment/kept-values.js +68 -0
- package/dist/features/environment/mcp-records.js +57 -0
- package/dist/features/environment/moves.js +17 -1
- package/dist/features/environment/stage.js +32 -28
- package/dist/features/environment/sync.js +13 -3
- package/dist/features/environment/writes.js +25 -27
- package/dist/features/hooks/compatibility.js +37 -17
- package/dist/features/hooks/test.js +2 -2
- package/dist/features/inventory/hook-matrix.js +14 -0
- package/dist/features/inventory/hook-readiness.js +47 -0
- package/dist/features/inventory/index.js +54 -3
- package/dist/features/inventory/show.js +10 -2
- package/dist/features/mcps/import.js +74 -21
- package/dist/features/mcps/index.js +28 -5
- package/dist/features/mcps/values.js +161 -23
- package/dist/features/migration/migrate.js +15 -0
- package/dist/features/migration/move.js +38 -9
- package/dist/features/migration/promote.js +1 -0
- package/dist/features/native/adapters.js +5 -46
- package/dist/features/native/hook-shell.js +11 -0
- package/dist/features/native/requirements.js +98 -0
- package/dist/features/secrets/index.js +95 -29
- package/dist/features/uninstall/index.js +126 -0
- package/dist/features/uninstall/leave.js +152 -0
- package/dist/features/uninstall/survey.js +103 -0
- package/dist/features/update-check/index.js +108 -0
- package/dist/features/workspace/cloud-source.js +38 -4
- package/dist/features/workspace/format.js +6 -1
- package/dist/harnesses/claude.js +1 -1
- package/dist/harnesses/codex.js +46 -22
- package/dist/harnesses/cursor.js +1 -1
- package/dist/harnesses/opencode.js +1 -1
- package/dist/harnesses/read-renamed-variables.js +141 -0
- package/dist/harnesses/renamed-variables.js +99 -0
- package/dist/platform.js +12 -1
- package/dist/program.js +24 -9
- package/dist/ui/add-hook.js +2 -2
- package/dist/ui/add-mcp.js +54 -16
- package/dist/ui/add-skills.js +2 -2
- package/dist/ui/adopt.js +90 -19
- package/dist/ui/assets.js +15 -2
- package/dist/ui/collaboration.js +5 -3
- package/dist/ui/connection.js +2 -0
- package/dist/ui/format.js +81 -2
- package/dist/ui/harness-picker.js +7 -2
- package/dist/ui/hook-compatibility.js +176 -22
- package/dist/ui/mcp.js +169 -24
- package/dist/ui/move.js +3 -2
- package/dist/ui/onboarding.js +11 -2
- package/dist/ui/output.js +116 -37
- package/dist/ui/package-details.js +7 -2
- package/dist/ui/pick.js +20 -6
- package/dist/ui/secret-input.js +9 -0
- package/dist/ui/selection.js +1 -1
- package/dist/ui/uninstall.js +186 -0
- package/dist/ui/update.js +10 -0
- package/dist/ui/variable-problems.js +23 -0
- package/dist/version.js +2 -2
- package/package.json +2 -2
- package/dist/entry/mcp-launch.js +0 -71
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { mcpSchema } from "@barndog-ai/api-contract";
|
|
2
2
|
import { assetKinds } from "../asset-kinds/index.js";
|
|
3
3
|
import { cacheKey, cachedPackage } from "./packages.js";
|
|
4
|
-
import { environmentCatalog, getAsset } from "../server/catalog.js";
|
|
4
|
+
import { environmentCatalog, getAsset, } from "../server/catalog.js";
|
|
5
5
|
import { CliError } from "../../errors.js";
|
|
6
6
|
async function currentAsset(kind, reference, conn, runtime) {
|
|
7
7
|
const data = await getAsset(kind, reference.id, conn, runtime);
|
|
@@ -16,18 +16,52 @@ async function currentAsset(kind, reference, conn, runtime) {
|
|
|
16
16
|
/**
|
|
17
17
|
* Adapts an authenticated cloud connection to lazy catalog, package-cache and
|
|
18
18
|
* MCP reads for synchronization.
|
|
19
|
+
*
|
|
20
|
+
* Servers that include each asset's version and MCP definition in the catalog
|
|
21
|
+
* need no further request per asset. Entries from older servers lack them, so
|
|
22
|
+
* those assets are fetched one by one and checked against the catalog.
|
|
19
23
|
*/
|
|
20
24
|
export function cloudSource(conn, runtime) {
|
|
25
|
+
const entries = new Map();
|
|
26
|
+
// The entry this reference was read from, if the reference still matches it.
|
|
27
|
+
const entry = (reference) => {
|
|
28
|
+
const found = entries.get(reference.id);
|
|
29
|
+
return found?.publishedVersion === reference.publishedVersion &&
|
|
30
|
+
found.name === reference.name
|
|
31
|
+
? found
|
|
32
|
+
: undefined;
|
|
33
|
+
};
|
|
21
34
|
return {
|
|
22
35
|
cacheKey: cacheKey(conn),
|
|
23
36
|
journal: conn,
|
|
24
|
-
catalog: async () =>
|
|
37
|
+
catalog: async () => {
|
|
38
|
+
const { catalog } = await environmentCatalog(runtime, conn);
|
|
39
|
+
entries.clear();
|
|
40
|
+
for (const asset of catalog.assets) {
|
|
41
|
+
entries.set(asset.id, asset);
|
|
42
|
+
}
|
|
43
|
+
return catalog;
|
|
44
|
+
},
|
|
25
45
|
packageFolder: async (kind, reference) => {
|
|
46
|
+
const listed = entry(reference);
|
|
47
|
+
const commit = listed?.version?.commit;
|
|
48
|
+
if (listed?.version && commit) {
|
|
49
|
+
return cachedPackage(kind, {
|
|
50
|
+
id: listed.id,
|
|
51
|
+
name: listed.name,
|
|
52
|
+
version: { commit, number: listed.version.number },
|
|
53
|
+
}, conn, runtime);
|
|
54
|
+
}
|
|
26
55
|
const data = await currentAsset(kind, reference, conn, runtime);
|
|
27
56
|
return cachedPackage(kind, assetKinds[kind].schema.parse(data), conn, runtime);
|
|
28
57
|
},
|
|
29
|
-
mcpDefinition: async (reference) =>
|
|
30
|
-
|
|
58
|
+
mcpDefinition: async (reference) => {
|
|
59
|
+
const definition = entry(reference)?.definition;
|
|
60
|
+
if (definition) {
|
|
61
|
+
return definition;
|
|
62
|
+
}
|
|
63
|
+
return mcpSchema.parse(await currentAsset("mcp", reference, conn, runtime)).version.definition;
|
|
64
|
+
},
|
|
31
65
|
invalidAssets: () => Promise.resolve(new Map()),
|
|
32
66
|
notices: () => [],
|
|
33
67
|
};
|
|
@@ -88,6 +88,11 @@ export function parseConfig(text) {
|
|
|
88
88
|
}
|
|
89
89
|
return parsed.data;
|
|
90
90
|
}
|
|
91
|
+
/**
|
|
92
|
+
* The ID a Git or local workspace gives an asset, from where it lives: the
|
|
93
|
+
* same before it's committed as after, so a copy's ID is known as it's made.
|
|
94
|
+
*/
|
|
95
|
+
export const repoAssetId = (workspaceId, kind, scope, name) => stableId(workspaceId, "asset", kind, scope.type, scope.slug, name);
|
|
91
96
|
/** A hash formatted as UUIDv4, so IDs need no stored record and cannot merge-conflict. */
|
|
92
97
|
export function stableId(...parts) {
|
|
93
98
|
const bytes = createHash("sha256")
|
|
@@ -218,7 +223,7 @@ export async function loadWorkspace(snapshot, expectedId, options = {}) {
|
|
|
218
223
|
const add = (kind, name, entry, read) => {
|
|
219
224
|
const base = {
|
|
220
225
|
kind,
|
|
221
|
-
id:
|
|
226
|
+
id: repoAssetId(config.workspaceId, kind, scope, name),
|
|
222
227
|
name,
|
|
223
228
|
origin: scope,
|
|
224
229
|
publishedVersion: entry.hash,
|
package/dist/harnesses/claude.js
CHANGED
|
@@ -65,7 +65,7 @@ export const claude = {
|
|
|
65
65
|
file: ".claude.json",
|
|
66
66
|
files: [".claude.json"],
|
|
67
67
|
path: ["mcpServers"],
|
|
68
|
-
server: (definition,
|
|
68
|
+
server: (definition, kept) => jsonMcpServer(definition, {
|
|
69
69
|
reference: (variable) => `\${${variable}}`,
|
|
70
70
|
typed: true,
|
|
71
71
|
}, kept),
|
package/dist/harnesses/codex.js
CHANGED
|
@@ -1,16 +1,20 @@
|
|
|
1
1
|
import { hookSpecificContext, nestedHookEntry, secretRefs } from "./formats.js";
|
|
2
|
+
import { renamedVariablesOf } from "./read-renamed-variables.js";
|
|
3
|
+
import { withRenamedVariables } from "./renamed-variables.js";
|
|
4
|
+
import { asRecord, asStrings } from "../shared/values.js";
|
|
2
5
|
/**
|
|
3
6
|
* Codex forwards variables by name (`env_vars`, `env_http_headers`) instead of
|
|
4
7
|
* interpolating references. It can't give a stdio server a variable under
|
|
5
|
-
* another name
|
|
6
|
-
*
|
|
8
|
+
* another name, so such a server starts through the system shell, which
|
|
9
|
+
* renames them (`renamed-variables.ts`). A value BarnDog keeps goes in `env` or
|
|
10
|
+
* `http_headers` as written, the way Codex stores values it's given.
|
|
7
11
|
*/
|
|
8
|
-
function mcpServer(definition,
|
|
12
|
+
function mcpServer(definition, kept, platform) {
|
|
9
13
|
const refs = Object.entries(secretRefs(definition));
|
|
10
14
|
const literal = refs.filter(([, ref]) => kept[ref.secretRef] !== undefined);
|
|
11
15
|
const forwarded = refs.filter(([, ref]) => kept[ref.secretRef] === undefined);
|
|
12
16
|
const values = Object.fromEntries(literal.map(([name, ref]) => [name, kept[ref.secretRef] ?? ""]));
|
|
13
|
-
const variables = forwarded.map(([, ref]) => ref.secretRef);
|
|
17
|
+
const variables = [...new Set(forwarded.map(([, ref]) => ref.secretRef))];
|
|
14
18
|
if (definition.transport === "http") {
|
|
15
19
|
return {
|
|
16
20
|
url: definition.url,
|
|
@@ -22,28 +26,47 @@ function mcpServer(definition, launcher, kept) {
|
|
|
22
26
|
: {}),
|
|
23
27
|
};
|
|
24
28
|
}
|
|
25
|
-
const
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
const environment = Object.fromEntries(forwarded);
|
|
30
|
-
return {
|
|
31
|
-
command: process.execPath,
|
|
32
|
-
args: [
|
|
33
|
-
launcher,
|
|
34
|
-
Buffer.from(JSON.stringify({ ...definition, environment })).toString("base64url"),
|
|
35
|
-
],
|
|
36
|
-
...inline,
|
|
37
|
-
env_vars: variables,
|
|
38
|
-
};
|
|
39
|
-
}
|
|
29
|
+
const renamed = forwarded
|
|
30
|
+
.filter(([name, ref]) => name !== ref.secretRef)
|
|
31
|
+
.map(([name, ref]) => ({ name, from: ref.secretRef }));
|
|
32
|
+
const server = { command: definition.command, args: definition.args };
|
|
40
33
|
return {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
34
|
+
...(renamed.length
|
|
35
|
+
? withRenamedVariables(server, renamed, platform)
|
|
36
|
+
: server),
|
|
37
|
+
...(literal.length ? { env: values } : {}),
|
|
44
38
|
env_vars: variables,
|
|
45
39
|
};
|
|
46
40
|
}
|
|
41
|
+
/**
|
|
42
|
+
* A Codex entry for `mcp add --from` and `adopt`, with a renaming wrapper
|
|
43
|
+
* (which sync wrote, and `uninstall --keep-setup` left behind) read back as
|
|
44
|
+
* the server it starts and a reference per renamed variable. The wrapper
|
|
45
|
+
* lists each source variable in `env_vars` to rename it, so those are
|
|
46
|
+
* dropped. A definition that also passed a source on under its own name
|
|
47
|
+
* can't be told apart from the entry, and comes back without that variable.
|
|
48
|
+
*/
|
|
49
|
+
function importedServer(entry) {
|
|
50
|
+
const wrapped = typeof entry.command === "string"
|
|
51
|
+
? renamedVariablesOf({
|
|
52
|
+
command: entry.command,
|
|
53
|
+
args: asStrings(entry.args),
|
|
54
|
+
})
|
|
55
|
+
: undefined;
|
|
56
|
+
if (!wrapped) {
|
|
57
|
+
return entry;
|
|
58
|
+
}
|
|
59
|
+
const sources = new Set(wrapped.renamed.map(({ from }) => from));
|
|
60
|
+
return {
|
|
61
|
+
...entry,
|
|
62
|
+
...wrapped.server,
|
|
63
|
+
env: {
|
|
64
|
+
...asRecord(entry.env),
|
|
65
|
+
...Object.fromEntries(wrapped.renamed.map(({ name, from }) => [name, `\${${from}}`])),
|
|
66
|
+
},
|
|
67
|
+
env_vars: asStrings(entry.env_vars).filter((name) => !sources.has(name)),
|
|
68
|
+
};
|
|
69
|
+
}
|
|
47
70
|
const toolMatcher = "Tool name, such as Bash or Edit|Write. Leave empty for all";
|
|
48
71
|
export const codex = {
|
|
49
72
|
id: "codex",
|
|
@@ -102,6 +125,7 @@ export const codex = {
|
|
|
102
125
|
files: [".codex/config.toml"],
|
|
103
126
|
path: ["mcp_servers"],
|
|
104
127
|
server: mcpServer,
|
|
128
|
+
imported: importedServer,
|
|
105
129
|
login: { command: ["codex", "mcp", "login"] },
|
|
106
130
|
},
|
|
107
131
|
configHome: {
|
package/dist/harnesses/cursor.js
CHANGED
|
@@ -56,7 +56,7 @@ export const cursor = {
|
|
|
56
56
|
file: ".cursor/mcp.json",
|
|
57
57
|
files: [".cursor/mcp.json"],
|
|
58
58
|
path: ["mcpServers"],
|
|
59
|
-
server: (definition,
|
|
59
|
+
server: (definition, kept) => jsonMcpServer(definition, {
|
|
60
60
|
reference: (variable) => `\${env:${variable}}`,
|
|
61
61
|
typed: false,
|
|
62
62
|
}, kept),
|
|
@@ -6,7 +6,7 @@ import { valuesOrReferences } from "./formats.js";
|
|
|
6
6
|
* server is `local` with the program and its arguments in one `command` list,
|
|
7
7
|
* an HTTP server is `remote`. Values refer to a local variable as `{env:NAME}`.
|
|
8
8
|
*/
|
|
9
|
-
function mcpServer(definition,
|
|
9
|
+
function mcpServer(definition, kept) {
|
|
10
10
|
const references = valuesOrReferences(definition, kept, (variable) => `{env:${variable}}`);
|
|
11
11
|
const some = Object.keys(references).length > 0;
|
|
12
12
|
if (definition.transport === "http") {
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reads back a command `withRenamedVariables()` (`renamed-variables.ts`)
|
|
3
|
+
* wrote, on either platform, so an entry BarnDog no longer owns (after
|
|
4
|
+
* `barndog uninstall --keep-setup`) imports as the server it starts. Anything
|
|
5
|
+
* else, a wrapper edited by hand included, reads as no wrapper: the result
|
|
6
|
+
* must rebuild the exact same command.
|
|
7
|
+
*/
|
|
8
|
+
import { isDeepStrictEqual } from "node:util";
|
|
9
|
+
import { encodedPowerShell } from "../platform.js";
|
|
10
|
+
import { VARIABLE_NAME } from "../shared/patterns.js";
|
|
11
|
+
import { POSIX_SHELL, withRenamedVariables, } from "./renamed-variables.js";
|
|
12
|
+
export function renamedVariablesOf(entry) {
|
|
13
|
+
const platform = entry.command === POSIX_SHELL ? "linux" : "win32";
|
|
14
|
+
const wrapped = platform === "linux" ? posixWrapped(entry) : powershellWrapped(entry);
|
|
15
|
+
return wrapped &&
|
|
16
|
+
isDeepStrictEqual(withRenamedVariables(wrapped.server, wrapped.renamed, platform), entry)
|
|
17
|
+
? wrapped
|
|
18
|
+
: undefined;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* One renamed variable in the POSIX wrapper's script, as
|
|
22
|
+
* `'GITHUB_PERSONAL_ACCESS_TOKEN='"$GITHUB_TOKEN"`: the name, then the source.
|
|
23
|
+
*
|
|
24
|
+
* @internal Exported for its table test in `src/tests/patterns.test.ts`.
|
|
25
|
+
*/
|
|
26
|
+
export const POSIX_RENAME = new RegExp(String.raw `'(${VARIABLE_NAME.source})='"\$(${VARIABLE_NAME.source})"`, "g");
|
|
27
|
+
function posixWrapped({ args }) {
|
|
28
|
+
const [flag, script, command, ...rest] = args;
|
|
29
|
+
if (flag !== "-c" || script === undefined || command === undefined) {
|
|
30
|
+
return undefined;
|
|
31
|
+
}
|
|
32
|
+
return {
|
|
33
|
+
server: { command, args: rest },
|
|
34
|
+
renamed: [...script.matchAll(POSIX_RENAME)].map(([, name = "", from = ""]) => ({
|
|
35
|
+
name,
|
|
36
|
+
from,
|
|
37
|
+
})),
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Where the PowerShell wrapper reads one source variable, as
|
|
42
|
+
* `$v0 = $env:GITHUB_TOKEN`, in the order of the renamed variables.
|
|
43
|
+
*
|
|
44
|
+
* @internal Exported for its table test in `src/tests/patterns.test.ts`.
|
|
45
|
+
*/
|
|
46
|
+
export const POWERSHELL_READ = new RegExp(String.raw `\$v\d+ = \$env:(${VARIABLE_NAME.source})`, "g");
|
|
47
|
+
/**
|
|
48
|
+
* Where the PowerShell wrapper sets one renamed variable, as
|
|
49
|
+
* `[Environment]::SetEnvironmentVariable('GITHUB_PERSONAL_ACCESS_TOKEN', $v0)`,
|
|
50
|
+
* in the same order as its reads.
|
|
51
|
+
*
|
|
52
|
+
* @internal Exported for its table test in `src/tests/patterns.test.ts`.
|
|
53
|
+
*/
|
|
54
|
+
export const POWERSHELL_WRITE = new RegExp(String.raw `SetEnvironmentVariable\('(${VARIABLE_NAME.source})', \$v\d+\)`, "g");
|
|
55
|
+
/** What `powershellWrapper()` puts after the server's command and arguments. */
|
|
56
|
+
const POWERSHELL_EXIT = "; if ($null -eq $LASTEXITCODE) { exit 1 }; exit $LASTEXITCODE";
|
|
57
|
+
/** What `powershellWrapper()` puts before the server's command and arguments. */
|
|
58
|
+
const POWERSHELL_CALL = "; & ";
|
|
59
|
+
/** The script inside an `encodedPowerShell()` invocation, without its preamble. */
|
|
60
|
+
function encodedScript({ args }) {
|
|
61
|
+
const decode = (value) => Buffer.from(value ?? "", "base64").toString("utf16le");
|
|
62
|
+
const preamble = decode(encodedPowerShell("").args.at(-1));
|
|
63
|
+
const script = decode(args.at(-1));
|
|
64
|
+
return script.startsWith(preamble)
|
|
65
|
+
? script.slice(preamble.length)
|
|
66
|
+
: undefined;
|
|
67
|
+
}
|
|
68
|
+
function powershellWrapped(entry) {
|
|
69
|
+
const script = encodedScript(entry);
|
|
70
|
+
// Only names come before the call, so the first call marker is the call's.
|
|
71
|
+
const start = script?.indexOf(`${POWERSHELL_CALL}'`) ?? -1;
|
|
72
|
+
if (!script || start < 0 || !script.endsWith(POWERSHELL_EXIT)) {
|
|
73
|
+
return undefined;
|
|
74
|
+
}
|
|
75
|
+
const words = powershellWords(script.slice(start + POWERSHELL_CALL.length, -POWERSHELL_EXIT.length));
|
|
76
|
+
const [command, ...rest] = words ?? [];
|
|
77
|
+
if (command === undefined) {
|
|
78
|
+
return undefined;
|
|
79
|
+
}
|
|
80
|
+
const sources = [...script.matchAll(POWERSHELL_READ)].map(([, from = ""]) => from);
|
|
81
|
+
const names = [...script.matchAll(POWERSHELL_WRITE)].map(([, name = ""]) => name);
|
|
82
|
+
return {
|
|
83
|
+
server: { command, args: rest.map(fromWindowsArgument) },
|
|
84
|
+
renamed: names.map((name, index) => ({ name, from: sources[index] ?? "" })),
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
/** PowerShell's single quotes, each doubled inside a quoted word (`powershellQuote()`). */
|
|
88
|
+
const SINGLE_QUOTES = "'\u2018\u2019\u201A\u201B";
|
|
89
|
+
/** The words of `'a' 'it''s'`, or undefined when the text isn't only quoted words. */
|
|
90
|
+
function powershellWords(text) {
|
|
91
|
+
const words = [];
|
|
92
|
+
let index = 0;
|
|
93
|
+
while (index < text.length) {
|
|
94
|
+
if (!SINGLE_QUOTES.includes(text.charAt(index))) {
|
|
95
|
+
return undefined;
|
|
96
|
+
}
|
|
97
|
+
let word = "";
|
|
98
|
+
index += 1;
|
|
99
|
+
while (index < text.length) {
|
|
100
|
+
const character = text.charAt(index);
|
|
101
|
+
if (!SINGLE_QUOTES.includes(character)) {
|
|
102
|
+
word += character;
|
|
103
|
+
index += 1;
|
|
104
|
+
continue;
|
|
105
|
+
}
|
|
106
|
+
if (text.charAt(index + 1) !== character) {
|
|
107
|
+
break;
|
|
108
|
+
}
|
|
109
|
+
word += character;
|
|
110
|
+
index += 2;
|
|
111
|
+
}
|
|
112
|
+
words.push(word);
|
|
113
|
+
index += 1;
|
|
114
|
+
if (index < text.length && text.charAt(index) !== " ") {
|
|
115
|
+
return undefined;
|
|
116
|
+
}
|
|
117
|
+
index += 1;
|
|
118
|
+
}
|
|
119
|
+
return words;
|
|
120
|
+
}
|
|
121
|
+
/** The argument `windowsArgument()` was given, read back from what it wrote. */
|
|
122
|
+
function fromWindowsArgument(written) {
|
|
123
|
+
if (written === '""') {
|
|
124
|
+
return "";
|
|
125
|
+
}
|
|
126
|
+
let value = "";
|
|
127
|
+
let backslashes = 0;
|
|
128
|
+
for (const character of written) {
|
|
129
|
+
if (character === "\\") {
|
|
130
|
+
backslashes += 1;
|
|
131
|
+
continue;
|
|
132
|
+
}
|
|
133
|
+
value +=
|
|
134
|
+
character === '"'
|
|
135
|
+
? `${"\\".repeat((backslashes - 1) / 2)}"`
|
|
136
|
+
: `${"\\".repeat(backslashes)}${character}`;
|
|
137
|
+
backslashes = 0;
|
|
138
|
+
}
|
|
139
|
+
const quoted = [...written].some((character) => character.trim() === "");
|
|
140
|
+
return value + "\\".repeat(quoted ? backslashes / 2 : backslashes);
|
|
141
|
+
}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Starting a stdio MCP server with some variables taken from other names
|
|
3
|
+
* (`GITHUB_PERSONAL_ACCESS_TOKEN` from `GITHUB_TOKEN`), for a tool that can
|
|
4
|
+
* only pass a variable on under its own name. The tool starts the system
|
|
5
|
+
* shell, which sets each renamed variable and then replaces itself with the
|
|
6
|
+
* server, so the entry needs nothing of BarnDog's and keeps working after
|
|
7
|
+
* BarnDog is uninstalled.
|
|
8
|
+
*
|
|
9
|
+
* The server's command and arguments never become script text on POSIX: they
|
|
10
|
+
* reach the shell as `$0` and `$@` and are passed on exactly as written. A
|
|
11
|
+
* variable name is always `[A-Za-z_][A-Za-z0-9_]*` (the contract's `envName`),
|
|
12
|
+
* so names are safe inside the script. Like any tool's own `env`, the mapping
|
|
13
|
+
* is set before the server's command runs, so a command that sets the same
|
|
14
|
+
* variable itself wins.
|
|
15
|
+
*/
|
|
16
|
+
import { encodedPowerShell, isWindows } from "../platform.js";
|
|
17
|
+
import { posixQuote, powershellQuote } from "../shared/shell.js";
|
|
18
|
+
/** The POSIX shell, at the path POSIX systems (NixOS and Guix included) keep it. */
|
|
19
|
+
export const POSIX_SHELL = "/bin/sh";
|
|
20
|
+
/**
|
|
21
|
+
* `env`, which sets every variable from values the shell expanded before it
|
|
22
|
+
* ran, so a swap (`A` from `B`, `B` from `A`) works.
|
|
23
|
+
*/
|
|
24
|
+
const POSIX_ENV = "/usr/bin/env";
|
|
25
|
+
export function withRenamedVariables(server, renamed, platform) {
|
|
26
|
+
return isWindows(platform)
|
|
27
|
+
? powershellWrapper(server, renamed)
|
|
28
|
+
: posixWrapper(server, renamed);
|
|
29
|
+
}
|
|
30
|
+
/** Each local variable once, in the order the definition names them. */
|
|
31
|
+
const sources = (renamed) => [
|
|
32
|
+
...new Set(renamed.map((variable) => variable.from)),
|
|
33
|
+
];
|
|
34
|
+
/**
|
|
35
|
+
* `/bin/sh -c '<script>' <command> <args…>`. `${X:?…}` stops with a message
|
|
36
|
+
* when `X` is unset or empty, as the tool's own reference would leave the
|
|
37
|
+
* server without a value; the tool shows the message as the server's error.
|
|
38
|
+
*/
|
|
39
|
+
function posixWrapper(server, renamed) {
|
|
40
|
+
const checks = sources(renamed).map((from) => `: "\${${from}:?${from} is not set}"; `);
|
|
41
|
+
const assignments = renamed.map(({ name, from }) => `${posixQuote(`${name}=`)}"$${from}"`);
|
|
42
|
+
const script = `${checks.join("")}exec ${POSIX_ENV} ${assignments.join(" ")} "$0" "$@"`;
|
|
43
|
+
return {
|
|
44
|
+
command: POSIX_SHELL,
|
|
45
|
+
args: ["-c", script, server.command, ...server.args],
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Windows PowerShell running the same steps. Its arguments can't be passed
|
|
50
|
+
* apart from the script, so the command and arguments are quoted into it, and
|
|
51
|
+
* the script is encoded so the tool's own argument quoting can't change it.
|
|
52
|
+
* Values are read before any is set, so a swap works here too.
|
|
53
|
+
*/
|
|
54
|
+
function powershellWrapper(server, renamed) {
|
|
55
|
+
const checks = sources(renamed).map((from) => `if (-not $env:${from}) { [Console]::Error.WriteLine(${powershellQuote(`${from} is not set`)}); exit 1 }`);
|
|
56
|
+
const reads = renamed.map(({ from }, index) => `$v${index} = $env:${from}`);
|
|
57
|
+
const writes = renamed.map(({ name }, index) => `[Environment]::SetEnvironmentVariable(${powershellQuote(name)}, $v${index})`);
|
|
58
|
+
const call = [
|
|
59
|
+
powershellQuote(server.command),
|
|
60
|
+
...server.args.map((arg) => powershellQuote(windowsArgument(arg))),
|
|
61
|
+
].join(" ");
|
|
62
|
+
const script = [
|
|
63
|
+
...checks,
|
|
64
|
+
...reads,
|
|
65
|
+
...writes,
|
|
66
|
+
`& ${call}; if ($null -eq $LASTEXITCODE) { exit 1 }; exit $LASTEXITCODE`,
|
|
67
|
+
].join("; ");
|
|
68
|
+
return encodedPowerShell(script);
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* An argument written so the program receives it unchanged from Windows
|
|
72
|
+
* PowerShell 5.1, which builds the command line itself: it puts quotes around
|
|
73
|
+
* an argument with whitespace outside quotes, drops an empty one, and passes
|
|
74
|
+
* every other character as is. The program then splits the line by the
|
|
75
|
+
* Microsoft C runtime's rules, where `\"` is a literal quote and backslashes
|
|
76
|
+
* count only before a quote. So `""` stands for an empty argument, each quote
|
|
77
|
+
* gets a backslash (and the backslashes before it double), and trailing
|
|
78
|
+
* backslashes double when PowerShell will close the argument with a quote.
|
|
79
|
+
*/
|
|
80
|
+
function windowsArgument(value) {
|
|
81
|
+
if (value === "") {
|
|
82
|
+
return '""';
|
|
83
|
+
}
|
|
84
|
+
let written = "";
|
|
85
|
+
let backslashes = 0;
|
|
86
|
+
for (const character of value) {
|
|
87
|
+
if (character === "\\") {
|
|
88
|
+
backslashes += 1;
|
|
89
|
+
continue;
|
|
90
|
+
}
|
|
91
|
+
written +=
|
|
92
|
+
character === '"'
|
|
93
|
+
? `${"\\".repeat(backslashes * 2 + 1)}"`
|
|
94
|
+
: `${"\\".repeat(backslashes)}${character}`;
|
|
95
|
+
backslashes = 0;
|
|
96
|
+
}
|
|
97
|
+
const quoted = [...value].some((character) => character.trim() === "");
|
|
98
|
+
return written + "\\".repeat(quoted ? backslashes * 2 : backslashes);
|
|
99
|
+
}
|
package/dist/platform.js
CHANGED
|
@@ -258,6 +258,17 @@ export function stopProcessTree(child, runtime, signal = "SIGKILL") {
|
|
|
258
258
|
/* The child has already exited. */
|
|
259
259
|
}
|
|
260
260
|
}
|
|
261
|
+
/**
|
|
262
|
+
* The environment for a Windows PowerShell (5.1) that BarnDog runs itself.
|
|
263
|
+
* PowerShell 7 puts its own module folders first in `PSModulePath`, and a
|
|
264
|
+
* Windows PowerShell started from it inherits them, then fails to load
|
|
265
|
+
* PowerShell 7's `Microsoft.PowerShell.Security` (`Get-Acl`). Without the
|
|
266
|
+
* variable, Windows PowerShell builds its default module path. Windows
|
|
267
|
+
* environment names ignore case.
|
|
268
|
+
*/
|
|
269
|
+
function windowsPowerShellEnvironment(env) {
|
|
270
|
+
return Object.fromEntries(Object.entries(env).filter(([name]) => name.toUpperCase() !== "PSMODULEPATH"));
|
|
271
|
+
}
|
|
261
272
|
/** Windows DACLs replace POSIX modes: only the current user receives access. */
|
|
262
273
|
export async function protectPrivate(path, runtime) {
|
|
263
274
|
if (!isWindows(runtime.platform)) {
|
|
@@ -266,7 +277,7 @@ export async function protectPrivate(path, runtime) {
|
|
|
266
277
|
const script = `$ErrorActionPreference='Stop'; $path=${shellQuote(path, runtime.platform)}; $sid=[Security.Principal.WindowsIdentity]::GetCurrent().User; $acl=Get-Acl -LiteralPath $path; $acl.SetOwner($sid); $acl.SetAccessRuleProtection($true,$false); foreach($rule in @($acl.Access)){$acl.RemoveAccessRuleSpecific($rule)}; $inherit=if((Get-Item -LiteralPath $path).PSIsContainer){[Security.AccessControl.InheritanceFlags]'ContainerInherit,ObjectInherit'}else{[Security.AccessControl.InheritanceFlags]::None}; $rule=New-Object Security.AccessControl.FileSystemAccessRule($sid,'FullControl',$inherit,'None','Allow'); $acl.AddAccessRule($rule); Set-Acl -LiteralPath $path -AclObject $acl`;
|
|
267
278
|
const invocation = encodedPowerShell(script);
|
|
268
279
|
await execute(invocation.command, invocation.args, {
|
|
269
|
-
env:
|
|
280
|
+
env: windowsPowerShellEnvironment(runtime.env),
|
|
270
281
|
cwd: runtime.cwd,
|
|
271
282
|
windowsHide: true,
|
|
272
283
|
});
|
package/dist/program.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { resolve } from "node:path";
|
|
2
1
|
import { Command, Help, Option } from "commander";
|
|
3
2
|
import { homedir } from "node:os";
|
|
3
|
+
import { pathsFor } from "./platform.js";
|
|
4
4
|
import { styleText } from "node:util";
|
|
5
5
|
import { registerCollaboration, registerWorkingCopy, } from "./commands/collaboration.js";
|
|
6
6
|
import { applySuggestion, changeDiff, commentOnChange, createPackage, diffVersions, listChanges, mergeChange, packageVersions, pullPackage, pushWorkingCopy, rejectChange, resolveFile, reviewChange, setDiscussionResolved, showChange, updateWorkingCopy, versionFiles, workingDiff, workingStatus, } from "./features/collaboration/index.js";
|
|
@@ -27,6 +27,7 @@ import { authenticateMcp, createMcp, mcpVersions, showMcp, updateMcp, } from "./
|
|
|
27
27
|
import { adaptHook, toolNames } from "./features/hooks/adapt.js";
|
|
28
28
|
import { harnesses } from "./harnesses/registry.js";
|
|
29
29
|
import { hookCompatibility } from "./features/hooks/compatibility.js";
|
|
30
|
+
import { allHookCompatibility } from "./features/inventory/hook-matrix.js";
|
|
30
31
|
import { testHook } from "./features/hooks/test.js";
|
|
31
32
|
import { knowledgeGet, knowledgeList, knowledgeProblems, } from "./features/knowledge/index.js";
|
|
32
33
|
import { developerAssets, developers, fork, } from "./features/discovery/index.js";
|
|
@@ -40,6 +41,9 @@ import { registerEnvironment } from "./commands/environment.js";
|
|
|
40
41
|
import { registerCapabilities } from "./commands/capabilities.js";
|
|
41
42
|
import { registerWorkspace } from "./commands/workspace.js";
|
|
42
43
|
import { registerAdopt } from "./commands/adopt.js";
|
|
44
|
+
import { registerUninstall } from "./commands/uninstall.js";
|
|
45
|
+
import { uninstall } from "./features/uninstall/index.js";
|
|
46
|
+
import { uninstallSurvey } from "./features/uninstall/survey.js";
|
|
43
47
|
import { registerAdd } from "./commands/add.js";
|
|
44
48
|
import { commandNeeds, modeName, needText, unavailableNote, } from "./commands/availability.js";
|
|
45
49
|
import { runSetup } from "./ui/onboarding.js";
|
|
@@ -50,7 +54,7 @@ import { versionReport } from "./version.js";
|
|
|
50
54
|
import { defined } from "./shared/lookup.js";
|
|
51
55
|
import { barndogPaths } from "./config/paths.js";
|
|
52
56
|
import { showPackage } from "./features/inventory/show.js";
|
|
53
|
-
import { forgetMcpValue, keepMcpValue, listKeptValues, } from "./features/mcps/values.js";
|
|
57
|
+
import { assignKeptValue, forgetMcpValue, forgetUnassignedValue, keepMcpValue, listKeptValues, recordedMcpServers, } from "./features/mcps/values.js";
|
|
54
58
|
import { readSettings } from "./config/settings.js";
|
|
55
59
|
/** Keep command help readable at the conventional eighty-column terminal width. */
|
|
56
60
|
const HELP_WIDTH = 80;
|
|
@@ -69,6 +73,7 @@ const groups = [
|
|
|
69
73
|
"doctor",
|
|
70
74
|
"harnesses",
|
|
71
75
|
"adopt",
|
|
76
|
+
"uninstall",
|
|
72
77
|
],
|
|
73
78
|
],
|
|
74
79
|
["Assets:", ["skills", "mcp", "hooks", "sets", "knowledge"]],
|
|
@@ -230,12 +235,15 @@ function guardRequiredOptions(parent, guard) {
|
|
|
230
235
|
}
|
|
231
236
|
/** Process entry points capture ambient inputs here; downstream code receives this object. */
|
|
232
237
|
export function captureRuntime(options = {}) {
|
|
233
|
-
|
|
238
|
+
// Resolved by the platform's own rules, so a test can run as another OS.
|
|
239
|
+
const platform = options.platform ?? process.platform;
|
|
240
|
+
const paths = pathsFor(platform);
|
|
241
|
+
const cwd = paths.resolve(options.cwd ?? process.cwd());
|
|
234
242
|
return {
|
|
235
|
-
home: resolve(cwd, options.home ?? homedir()),
|
|
243
|
+
home: paths.resolve(cwd, options.home ?? homedir()),
|
|
236
244
|
cwd,
|
|
237
245
|
env: { ...(options.env ?? process.env) },
|
|
238
|
-
platform
|
|
246
|
+
platform,
|
|
239
247
|
};
|
|
240
248
|
}
|
|
241
249
|
/** Construct a fresh parser for every invocation or test; command behavior is independently injectable. */
|
|
@@ -312,6 +320,8 @@ export function createProgram(options = {}) {
|
|
|
312
320
|
workspaceUrl: options.workspaceUrl ?? (() => workspaceUrl(runtime)),
|
|
313
321
|
repoStatus: options.repoStatus ?? (() => repoStatus(runtime)),
|
|
314
322
|
scanNative: options.scanNative ?? (() => scanNative(runtime)),
|
|
323
|
+
uninstallSurvey: options.uninstallSurvey ?? (() => uninstallSurvey(runtime)),
|
|
324
|
+
uninstall: options.uninstall ?? ((choices) => uninstall(choices, runtime)),
|
|
315
325
|
adoptNative: options.adoptNative ?? ((keys, keep) => adoptNative(keys, keep, runtime)),
|
|
316
326
|
listAdoptions: options.listAdoptions ?? (() => listAdoptions(home)),
|
|
317
327
|
undoAdoption: options.undoAdoption ?? ((target) => undoAdoption(target, runtime)),
|
|
@@ -328,10 +338,13 @@ export function createProgram(options = {}) {
|
|
|
328
338
|
updateImported: options.updateImported ??
|
|
329
339
|
((kind, name, options) => updateImported(kind, name, options, runtime)),
|
|
330
340
|
keepMcpValue: options.keepMcpValue ??
|
|
331
|
-
((
|
|
332
|
-
|
|
333
|
-
|
|
341
|
+
((target, kept) => keepMcpValue(target, kept, runtime)),
|
|
342
|
+
assignKeptValue: options.assignKeptValue ?? ((target) => assignKeptValue(target, runtime)),
|
|
343
|
+
forgetMcpValue: options.forgetMcpValue ?? ((target) => forgetMcpValue(target, runtime)),
|
|
344
|
+
forgetUnassignedValue: options.forgetUnassignedValue ??
|
|
345
|
+
((variable) => forgetUnassignedValue(variable, runtime)),
|
|
334
346
|
listKeptValues: options.listKeptValues ?? (() => listKeptValues(runtime)),
|
|
347
|
+
recordedMcpServers: options.recordedMcpServers ?? (() => recordedMcpServers(runtime)),
|
|
335
348
|
showPackage: options.showPackage ??
|
|
336
349
|
((kind, name, origin) => showPackage(kind, name, origin, runtime)),
|
|
337
350
|
showMcp: options.showMcp ?? ((name, origin) => showMcp(name, origin, runtime)),
|
|
@@ -345,6 +358,7 @@ export function createProgram(options = {}) {
|
|
|
345
358
|
((name, origin, testOptions) => testHook(name, origin, testOptions, runtime)),
|
|
346
359
|
hookCompatibility: options.hookCompatibility ??
|
|
347
360
|
((name, origin) => hookCompatibility(name, origin, runtime)),
|
|
361
|
+
allHookCompatibility: options.allHookCompatibility ?? (() => allHookCompatibility(runtime)),
|
|
348
362
|
adaptHook: options.adaptHook ??
|
|
349
363
|
((name, origin, targets) => adaptHook(name, origin, targets, runtime)),
|
|
350
364
|
knowledgeGet: options.knowledgeGet ?? ((name) => knowledgeGet(name, runtime)),
|
|
@@ -386,7 +400,7 @@ export function createProgram(options = {}) {
|
|
|
386
400
|
knowledgeList: options.knowledgeList ?? ((always) => knowledgeList(always, runtime)),
|
|
387
401
|
synchronize: options.synchronize ??
|
|
388
402
|
((path, syncOptions) => synchronize(path, runtime, undefined, syncOptions)),
|
|
389
|
-
inventory: options.inventory ?? (() => inventory(runtime)),
|
|
403
|
+
inventory: options.inventory ?? ((choice) => inventory(runtime, choice)),
|
|
390
404
|
searchCatalog: options.searchCatalog ?? ((kind) => searchCatalog(kind, runtime)),
|
|
391
405
|
write,
|
|
392
406
|
mode,
|
|
@@ -453,6 +467,7 @@ export function createProgram(options = {}) {
|
|
|
453
467
|
registerSync(program, context);
|
|
454
468
|
registerHarnesses(program, context);
|
|
455
469
|
registerAdopt(program, context);
|
|
470
|
+
registerUninstall(program, context);
|
|
456
471
|
registerStatus(program, context);
|
|
457
472
|
registerEnvironment(program, context);
|
|
458
473
|
registerCapabilities(program, context);
|
package/dist/ui/add-hook.js
CHANGED
|
@@ -11,7 +11,7 @@ import { LOCAL_ORIGIN } from "../features/workspace/overlay.js";
|
|
|
11
11
|
import { saveImported } from "../features/imports/local.js";
|
|
12
12
|
import { assertSourceExists, plainFolder } from "../features/imports/folder.js";
|
|
13
13
|
import { fetchRemote, parseLocation } from "../features/imports/remote.js";
|
|
14
|
-
import { bold, dim, ok, warn } from "./format.js";
|
|
14
|
+
import { bold, choiceDescription, dim, ok, warn } from "./format.js";
|
|
15
15
|
import { setYamlName, slugify } from "../shared/patterns.js";
|
|
16
16
|
import { only } from "../shared/lookup.js";
|
|
17
17
|
import { assertDistinctNames, finish, folderLabel, notFound, onlyChosen, updateMode, } from "./add-asset.js";
|
|
@@ -72,7 +72,7 @@ async function choosePackages(packages, url, options, context) {
|
|
|
72
72
|
name: `${p.name} ${dim(folderLabel(p.root))}`,
|
|
73
73
|
value: p.root,
|
|
74
74
|
short: p.name,
|
|
75
|
-
description: `Description: ${p.description}
|
|
75
|
+
description: choiceDescription(`Description: ${p.description}`),
|
|
76
76
|
})));
|
|
77
77
|
chosen = packages.filter((p) => picked.includes(p.root));
|
|
78
78
|
}
|