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.
- package/README.md +11 -10
- package/dist/cli.js +11 -7
- package/dist/commands/add.js +33 -21
- package/dist/commands/arguments.js +12 -0
- package/dist/commands/asset-install.js +160 -0
- package/dist/commands/asset-list.js +121 -0
- package/dist/commands/asset-share.js +94 -0
- package/dist/commands/auth.js +4 -0
- package/dist/commands/availability.js +54 -26
- package/dist/commands/capabilities.js +71 -415
- package/dist/commands/collaboration.js +194 -110
- package/dist/commands/environment.js +18 -411
- package/dist/commands/github.js +200 -0
- package/dist/commands/helpers.js +39 -0
- package/dist/commands/hooks.js +87 -0
- package/dist/commands/init.js +4 -2
- package/dist/commands/knowledge.js +73 -0
- package/dist/commands/mcp.js +62 -0
- package/dist/commands/origin.js +21 -23
- package/dist/commands/people.js +51 -0
- package/dist/commands/sets.js +141 -0
- package/dist/commands/status.js +34 -24
- package/dist/commands/sync.js +11 -4
- package/dist/commands/workspace.js +33 -19
- package/dist/config/environment.js +13 -27
- package/dist/config/paths.js +62 -0
- package/dist/config/selection.js +30 -0
- package/dist/config/settings.js +97 -108
- package/dist/config/state.js +57 -57
- package/dist/entry/knowledge-startup.js +32 -0
- package/dist/entry/mcp-launch.js +71 -0
- package/dist/entry/opencode-plugin.js +62 -0
- package/dist/{features/git-workspace/startup.js → entry/workspace-startup.js} +7 -2
- package/dist/errors.js +198 -55
- package/dist/features/asset-kinds/index.js +120 -0
- package/dist/features/asset-selection/index.js +51 -19
- package/dist/features/auth/credentials.js +80 -47
- package/dist/features/auth/session.js +80 -45
- package/dist/features/auth/transport.js +66 -15
- package/dist/features/catalog/index.js +32 -61
- package/dist/features/collaboration/api.js +160 -0
- package/dist/features/collaboration/index.js +321 -233
- package/dist/features/collaboration/remote.js +35 -115
- package/dist/features/collaboration/results.js +2 -0
- package/dist/features/collaboration/workspace-git.js +233 -149
- package/dist/features/collaboration/workspace-github.js +117 -54
- package/dist/features/collaboration/workspace-store.js +140 -100
- package/dist/features/collaboration/workspace.js +257 -172
- package/dist/features/discovery/index.js +68 -57
- package/dist/features/doctor/index.js +32 -24
- package/dist/features/environment/auto-sync.js +28 -27
- package/dist/features/environment/names.js +67 -47
- package/dist/features/environment/operations.js +321 -228
- package/dist/features/environment/own-entries.js +89 -0
- package/dist/features/environment/settle-names.js +91 -0
- package/dist/features/environment/stage.js +178 -0
- package/dist/features/environment/sync.js +113 -484
- package/dist/features/environment/transaction.js +179 -147
- package/dist/features/environment/writes.js +196 -0
- package/dist/features/github/account.js +25 -0
- package/dist/features/github/connections.js +119 -0
- package/dist/features/github/pulls.js +118 -0
- package/dist/features/hooks/adapt.js +32 -25
- package/dist/features/hooks/catalog.js +28 -0
- package/dist/features/hooks/compatibility.js +49 -0
- package/dist/features/hooks/divergence.js +9 -6
- package/dist/features/hooks/test.js +74 -49
- package/dist/features/hooks/types.js +1 -0
- package/dist/features/imports/discover.js +134 -61
- package/dist/features/imports/folder.js +48 -14
- package/dist/features/imports/local.js +113 -134
- package/dist/features/imports/remote.js +44 -25
- package/dist/features/inspection/index.js +17 -17
- package/dist/features/inventory/index.js +99 -110
- package/dist/features/knowledge/index.js +69 -49
- package/dist/features/mcps/catalog.js +31 -0
- package/dist/features/mcps/import.js +316 -0
- package/dist/features/mcps/index.js +98 -49
- package/dist/features/migration/migrate.js +263 -0
- package/dist/features/{git-workspace → migration}/move.js +165 -109
- package/dist/features/migration/promote.js +24 -0
- package/dist/features/native/adapters.js +53 -94
- package/dist/features/native/configuration.js +128 -82
- package/dist/features/native/hook-shell.js +55 -0
- package/dist/features/native/plugin-module.js +56 -0
- package/dist/features/onboarding/environment.js +67 -34
- package/dist/features/onboarding/setup.js +43 -40
- package/dist/features/repositories/context.js +30 -13
- package/dist/features/server/catalog.js +58 -0
- package/dist/features/server/client.js +13 -0
- package/dist/features/server/connection.js +37 -0
- package/dist/features/server/origin.js +74 -0
- package/dist/features/server/pages.js +24 -0
- package/dist/features/skills/catalog.js +42 -0
- package/dist/features/workspace/assets.js +57 -0
- package/dist/features/workspace/cloud-source.js +34 -0
- package/dist/features/workspace/directory.js +38 -0
- package/dist/features/{git-workspace → workspace}/format.js +114 -51
- package/dist/features/workspace/git.js +214 -0
- package/dist/features/workspace/installed.js +92 -0
- package/dist/features/{git-workspace → workspace}/overlay.js +43 -23
- package/dist/features/workspace/packages.js +160 -0
- package/dist/features/{git-workspace → workspace}/publish.js +120 -64
- package/dist/features/workspace/repo-source.js +192 -0
- package/dist/features/{git-workspace → workspace}/setup.js +60 -42
- package/dist/features/{git-workspace → workspace}/snapshot.js +53 -18
- package/dist/features/workspace/source.js +1 -0
- package/dist/features/workspace/tree.js +52 -0
- package/dist/features/workspace/workspace-source.js +27 -0
- package/dist/harnesses/claude.js +23 -1
- package/dist/harnesses/codex.js +57 -1
- package/dist/harnesses/cursor.js +22 -1
- package/dist/harnesses/detect.js +6 -50
- package/dist/harnesses/formats.js +45 -0
- package/dist/harnesses/opencode.js +111 -0
- package/dist/harnesses/registry.js +35 -2
- package/dist/platform.js +375 -0
- package/dist/program.js +225 -54
- package/dist/runtime.js +1 -0
- package/dist/shared/cli-error.js +22 -0
- package/dist/shared/constants.js +32 -0
- package/dist/shared/files.js +72 -0
- package/dist/shared/lock.js +49 -0
- package/dist/shared/lookup.js +11 -0
- package/dist/shared/patterns.js +94 -0
- package/dist/shared/shell.js +22 -0
- package/dist/shared/values.js +26 -0
- package/dist/ui/add-asset.js +41 -400
- package/dist/ui/add-hook.js +213 -0
- package/dist/ui/add-mcp.js +107 -0
- package/dist/ui/add-prompts.js +47 -0
- package/dist/ui/add-skills.js +115 -0
- package/dist/ui/asset-list.js +31 -13
- package/dist/ui/assets.js +33 -44
- package/dist/ui/auth.js +43 -33
- package/dist/ui/clash.js +11 -6
- package/dist/ui/collaboration.js +116 -44
- package/dist/ui/connection.js +10 -4
- package/dist/ui/decision-error.js +24 -0
- package/dist/ui/environment-onboarding.js +35 -13
- package/dist/ui/format.js +66 -18
- package/dist/ui/hook-compatibility.js +14 -6
- package/dist/ui/mcp.js +28 -3
- package/dist/ui/move.js +10 -5
- package/dist/ui/onboarding.js +113 -73
- package/dist/ui/options.js +9 -0
- package/dist/ui/output.js +106 -43
- package/dist/ui/pick.js +45 -33
- package/dist/ui/scope-install.js +15 -7
- package/dist/ui/selection.js +15 -11
- package/dist/ui/theme.js +37 -14
- package/dist/version.js +6 -3
- package/package.json +24 -11
- package/dist/features/capabilities/index.js +0 -106
- package/dist/features/collaboration/domain.js +0 -90
- package/dist/features/environment/cloud-source.js +0 -27
- package/dist/features/environment/installed.js +0 -124
- package/dist/features/environment/packages.js +0 -120
- package/dist/features/environment/remote.js +0 -71
- package/dist/features/environment/workspace-source.js +0 -19
- package/dist/features/git-hosts/index.js +0 -148
- package/dist/features/git-workspace/assets.js +0 -71
- package/dist/features/git-workspace/git.js +0 -135
- package/dist/features/git-workspace/migrate.js +0 -188
- package/dist/features/git-workspace/source.js +0 -159
- package/dist/features/imports/mcp.js +0 -219
- package/dist/features/knowledge/startup.js +0 -25
- package/dist/features/native/mcp-launch.js +0 -57
- package/dist/features/skills/install.js +0 -25
- package/dist/features/skills/remote.js +0 -177
- package/dist/features/skills/sync.js +0 -121
- package/dist/features/skills/validation.js +0 -34
- /package/dist/features/environment/{source.js → events.js} +0 -0
|
@@ -1,12 +1,18 @@
|
|
|
1
|
+
import { GIT_MODE, isBlob } from "../workspace/snapshot.js";
|
|
1
2
|
import { hookImplementationSchema, } from "@barndog-ai/api-contract";
|
|
2
3
|
import { hookMetadata, packageMetadata, validatePackageEntries, } from "@barndog-ai/api-contract/package";
|
|
3
4
|
import { parse as parseJsonc } from "jsonc-parser";
|
|
4
5
|
import { parse as parseToml } from "smol-toml";
|
|
5
6
|
import { stringify } from "yaml";
|
|
6
|
-
import { friendlyMessage } from "../../errors.js";
|
|
7
|
-
import { adapters,
|
|
8
|
-
import {
|
|
9
|
-
|
|
7
|
+
import { CliError, friendlyMessage } from "../../errors.js";
|
|
8
|
+
import { adapters, hookHarnesses, hookSettingsOwner, } from "../../harnesses/registry.js";
|
|
9
|
+
import { defined } from "../../shared/lookup.js";
|
|
10
|
+
import { asRecord, isRecord } from "../../shared/values.js";
|
|
11
|
+
/**
|
|
12
|
+
* What imported Hook commands use for the installed package folder; BarnDog
|
|
13
|
+
* binds it when installing.
|
|
14
|
+
*/
|
|
15
|
+
const ROOT_TOKEN = "${BARNDOG_HOOK_ROOT}";
|
|
10
16
|
/** A link to a folder or file narrows everything to it; the rest of the repo is ignored. */
|
|
11
17
|
const inScope = (remote, path) => !remote.path || path === remote.path || path.startsWith(`${remote.path}/`);
|
|
12
18
|
/** Whether the folder or file the link pointed at is in the repo at all. */
|
|
@@ -18,25 +24,35 @@ export function folderEntries(remote, root) {
|
|
|
18
24
|
.filter((entry) => entry.path.startsWith(prefix) && isBlob(entry.mode))
|
|
19
25
|
.map((entry) => ({
|
|
20
26
|
path: entry.path.slice(prefix.length),
|
|
21
|
-
data: remote
|
|
22
|
-
executable: entry.mode ===
|
|
27
|
+
data: blobOf(remote, entry),
|
|
28
|
+
executable: entry.mode === GIT_MODE.executable,
|
|
23
29
|
}));
|
|
24
30
|
}
|
|
31
|
+
/** Every blob in a fetched snapshot was read with it. */
|
|
32
|
+
const blobOf = (remote, entry) => defined(remote.blobs.get(entry.hash), `Git object ${entry.hash} wasn't read`);
|
|
25
33
|
const hasLink = (remote, root) => remote.snapshot.entries.some((entry) => entry.path.startsWith(root ? `${root}/` : "") &&
|
|
26
|
-
(entry.mode ===
|
|
34
|
+
(entry.mode === GIT_MODE.symlink || entry.mode === GIT_MODE.submodule));
|
|
27
35
|
const parentOf = (path) => path.includes("/") ? path.slice(0, path.lastIndexOf("/")) : "";
|
|
36
|
+
/**
|
|
37
|
+
* Every valid Skill folder (one holding `SKILL.md`) in the linked part of a
|
|
38
|
+
* fetched repository. Folders with symbolic links or invalid packages are
|
|
39
|
+
* skipped with a reason.
|
|
40
|
+
*/
|
|
28
41
|
export function discoverSkills(remote) {
|
|
29
42
|
const skills = [];
|
|
30
43
|
const skipped = [];
|
|
31
44
|
for (const entry of remote.snapshot.entries) {
|
|
32
|
-
if (
|
|
45
|
+
if (fileName(entry.path) !== "SKILL.md" || !isBlob(entry.mode)) {
|
|
33
46
|
continue;
|
|
47
|
+
}
|
|
34
48
|
const root = parentOf(entry.path);
|
|
35
|
-
if (!inScope(remote, root) && !inScope(remote, entry.path))
|
|
49
|
+
if (!inScope(remote, root) && !inScope(remote, entry.path)) {
|
|
36
50
|
continue;
|
|
51
|
+
}
|
|
37
52
|
try {
|
|
38
|
-
if (hasLink(remote, root))
|
|
39
|
-
throw new
|
|
53
|
+
if (hasLink(remote, root)) {
|
|
54
|
+
throw new CliError("It contains a symbolic link");
|
|
55
|
+
}
|
|
40
56
|
const entries = validatePackageEntries(folderEntries(remote, root));
|
|
41
57
|
const metadata = packageMetadata(entries);
|
|
42
58
|
skills.push({ ...metadata, root, entries });
|
|
@@ -47,72 +63,125 @@ export function discoverSkills(remote) {
|
|
|
47
63
|
}
|
|
48
64
|
return { skills, skipped };
|
|
49
65
|
}
|
|
50
|
-
|
|
51
|
-
const
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
66
|
+
/** The last segment of a repository path: `hooks/lint/hook.yaml` → `hook.yaml`. */
|
|
67
|
+
const fileName = (path) => path.slice(path.lastIndexOf("/") + 1);
|
|
68
|
+
/** `.py` from `hooks/check.py`; "" when the file name has no extension. */
|
|
69
|
+
const extensionOf = (path) => {
|
|
70
|
+
const name = fileName(path);
|
|
71
|
+
const dot = name.lastIndexOf(".");
|
|
72
|
+
return dot > 0 ? name.slice(dot) : "";
|
|
73
|
+
};
|
|
74
|
+
/** What a script without its executable bit is run with, by extension. */
|
|
75
|
+
const interpreters = {
|
|
76
|
+
".py": "python3 ",
|
|
77
|
+
".js": "node ",
|
|
78
|
+
".mjs": "node ",
|
|
79
|
+
".cjs": "node ",
|
|
80
|
+
".rb": "ruby ",
|
|
81
|
+
".pl": "perl ",
|
|
82
|
+
};
|
|
83
|
+
const scriptExtensions = new Set([
|
|
84
|
+
".sh",
|
|
85
|
+
".bash",
|
|
86
|
+
".zsh",
|
|
87
|
+
".ts",
|
|
88
|
+
...Object.keys(interpreters),
|
|
89
|
+
]);
|
|
90
|
+
/**
|
|
91
|
+
* Whether a repository file looks like a hook script: `hooks/check.sh`, `lint.mjs`.
|
|
92
|
+
*
|
|
93
|
+
* @internal Exported for its table test in `src/tests/patterns.test.ts`.
|
|
94
|
+
*/
|
|
95
|
+
export const scriptLike = (path) => scriptExtensions.has(extensionOf(path));
|
|
96
|
+
/**
|
|
97
|
+
* A command that runs `script` from the package: `@@check.sh` when it is
|
|
98
|
+
* executable, else through its interpreter, `python3 @@check.py`.
|
|
99
|
+
*/
|
|
60
100
|
export function plainCommand(script, executable) {
|
|
61
|
-
|
|
101
|
+
const interpreter = executable
|
|
102
|
+
? ""
|
|
103
|
+
: (interpreters[extensionOf(script)] ?? "");
|
|
104
|
+
return `${interpreter}@@${script}`;
|
|
62
105
|
}
|
|
63
106
|
function nativeHooks(entry, text) {
|
|
64
107
|
const parsed = entry.path.endsWith(".toml")
|
|
65
108
|
? parseToml(text)
|
|
66
109
|
: parseJsonc(text);
|
|
67
|
-
const hooks = parsed?.hooks;
|
|
68
110
|
const found = [];
|
|
69
|
-
for (const [event, groups] of Object.entries(hooks
|
|
70
|
-
if (!Array.isArray(groups))
|
|
111
|
+
for (const [event, groups] of Object.entries(asRecord(asRecord(parsed).hooks))) {
|
|
112
|
+
if (!Array.isArray(groups)) {
|
|
71
113
|
continue;
|
|
72
|
-
|
|
114
|
+
}
|
|
115
|
+
for (const group of groups.filter(isRecord)) {
|
|
73
116
|
const matcher = typeof group.matcher === "string" && group.matcher
|
|
74
117
|
? group.matcher
|
|
75
118
|
: undefined;
|
|
76
119
|
const handlers = Array.isArray(group.hooks)
|
|
77
|
-
? group.hooks
|
|
120
|
+
? group.hooks.filter(isRecord)
|
|
78
121
|
: [group];
|
|
79
|
-
for (const handler of handlers)
|
|
122
|
+
for (const handler of handlers) {
|
|
80
123
|
if (typeof handler.command === "string" &&
|
|
81
|
-
(handler.type ?? "command") === "command")
|
|
124
|
+
(handler.type ?? "command") === "command") {
|
|
82
125
|
found.push({ event, matcher, command: handler.command });
|
|
126
|
+
}
|
|
127
|
+
}
|
|
83
128
|
}
|
|
84
129
|
}
|
|
85
130
|
return found;
|
|
86
131
|
}
|
|
87
|
-
|
|
88
|
-
|
|
132
|
+
/**
|
|
133
|
+
* Leading folders a native command uses to find its repository, which don't
|
|
134
|
+
* exist in the package: `$CLAUDE_PROJECT_DIR/`, `${CLAUDE_PLUGIN_ROOT}/`,
|
|
135
|
+
* `$(git rev-parse --show-toplevel)/`, `~/` and `./`, in any combination.
|
|
136
|
+
*/
|
|
137
|
+
const ROOT_PREFIXES = /^(?:\$\{?[A-Z_]+\}?\/|\$\(git rev-parse --show-toplevel\)\/|~\/|\.\/)+/;
|
|
138
|
+
/** Surrounding quotes on one word of a command: `"./run.sh"` → `./run.sh`. */
|
|
139
|
+
const QUOTES = /^["']|["']$/g;
|
|
140
|
+
/**
|
|
141
|
+
* The repository-relative path one word of a native hook command may name:
|
|
142
|
+
* `"$CLAUDE_PROJECT_DIR/.claude/hooks/check.sh"` → `.claude/hooks/check.sh`.
|
|
143
|
+
*
|
|
144
|
+
* @internal Exported for its table test in `src/tests/patterns.test.ts`.
|
|
145
|
+
*/
|
|
146
|
+
export function scriptPath(token) {
|
|
147
|
+
return token.replace(QUOTES, "").replace(ROOT_PREFIXES, "");
|
|
148
|
+
}
|
|
89
149
|
/** Points a native command at the repo's script, or says why it can't be carried over. */
|
|
90
150
|
function rewriteCommand(command, blobs, scope) {
|
|
91
151
|
for (const token of command.split(/\s+/)) {
|
|
92
|
-
const
|
|
93
|
-
|
|
94
|
-
if (!relative || !relative.includes("."))
|
|
152
|
+
const relative = scriptPath(token);
|
|
153
|
+
if (!relative || !relative.includes(".")) {
|
|
95
154
|
continue;
|
|
155
|
+
}
|
|
96
156
|
const script = blobs.find((path) => path === relative) ??
|
|
97
157
|
blobs.find((path) => scope && path === `${scope}/${relative}`) ??
|
|
98
158
|
blobs.find((path) => path.endsWith(`/${relative}`));
|
|
99
|
-
if (script)
|
|
100
|
-
return { script, command: command.replace(token, `@@${script}`) };
|
|
159
|
+
if (script) {
|
|
160
|
+
return { script, command: command.replace(token, () => `@@${script}`) };
|
|
161
|
+
}
|
|
101
162
|
}
|
|
102
163
|
return null;
|
|
103
164
|
}
|
|
165
|
+
/**
|
|
166
|
+
* The Hook packages in the linked part of a fetched repository. When there are
|
|
167
|
+
* none, builds one draft from the harness settings files it finds (named
|
|
168
|
+
* `fallbackName`), so a repository of plain hook scripts can still be imported.
|
|
169
|
+
*/
|
|
104
170
|
export function discoverHooks(remote, fallbackName) {
|
|
105
171
|
const packages = [];
|
|
106
172
|
const skipped = [];
|
|
107
173
|
for (const entry of remote.snapshot.entries) {
|
|
108
|
-
if (
|
|
174
|
+
if (fileName(entry.path) !== "hook.yaml" || !isBlob(entry.mode)) {
|
|
109
175
|
continue;
|
|
176
|
+
}
|
|
110
177
|
const root = parentOf(entry.path);
|
|
111
|
-
if (!inScope(remote, root) && !inScope(remote, entry.path))
|
|
178
|
+
if (!inScope(remote, root) && !inScope(remote, entry.path)) {
|
|
112
179
|
continue;
|
|
180
|
+
}
|
|
113
181
|
try {
|
|
114
|
-
if (hasLink(remote, root))
|
|
115
|
-
throw new
|
|
182
|
+
if (hasLink(remote, root)) {
|
|
183
|
+
throw new CliError("It contains a symbolic link");
|
|
184
|
+
}
|
|
116
185
|
const entries = validatePackageEntries(folderEntries(remote, root), undefined, "hook.yaml");
|
|
117
186
|
const manifest = hookMetadata(entries);
|
|
118
187
|
packages.push({
|
|
@@ -127,35 +196,39 @@ export function discoverHooks(remote, fallbackName) {
|
|
|
127
196
|
skipped.push({ path: entry.path, reason: friendlyMessage(error) });
|
|
128
197
|
}
|
|
129
198
|
}
|
|
130
|
-
if (packages.length)
|
|
199
|
+
if (packages.length) {
|
|
131
200
|
return { candidates: packages, skipped };
|
|
201
|
+
}
|
|
132
202
|
const blobEntries = remote.snapshot.entries.filter((e) => isBlob(e.mode) && inScope(remote, e.path));
|
|
133
203
|
const blobPaths = blobEntries.map((e) => e.path);
|
|
134
204
|
const implementations = {};
|
|
135
205
|
for (const entry of blobEntries) {
|
|
136
|
-
const harness =
|
|
137
|
-
if (!harness)
|
|
206
|
+
const harness = hookSettingsOwner(entry.path);
|
|
207
|
+
if (!harness) {
|
|
138
208
|
continue;
|
|
209
|
+
}
|
|
139
210
|
let hooks = [];
|
|
140
211
|
try {
|
|
141
|
-
hooks = nativeHooks(entry, remote
|
|
212
|
+
hooks = nativeHooks(entry, blobOf(remote, entry).toString("utf8"));
|
|
142
213
|
}
|
|
143
214
|
catch (error) {
|
|
144
215
|
skipped.push({ path: entry.path, reason: friendlyMessage(error) });
|
|
145
216
|
}
|
|
146
217
|
for (const hook of hooks) {
|
|
147
218
|
const rewritten = rewriteCommand(hook.command, blobPaths, remote.path);
|
|
148
|
-
if (!rewritten)
|
|
219
|
+
if (!rewritten) {
|
|
149
220
|
skipped.push({
|
|
150
221
|
path: entry.path,
|
|
151
222
|
reason: `${hook.event}: "${hook.command}" doesn't run a script in this ${remote.path ? "folder" : "repo"}`,
|
|
152
223
|
});
|
|
153
|
-
|
|
224
|
+
}
|
|
225
|
+
else {
|
|
154
226
|
(implementations[harness] ??= []).push({
|
|
155
227
|
event: hook.event,
|
|
156
228
|
matcher: hook.matcher,
|
|
157
229
|
...rewritten,
|
|
158
230
|
});
|
|
231
|
+
}
|
|
159
232
|
}
|
|
160
233
|
}
|
|
161
234
|
const scripts = [
|
|
@@ -164,12 +237,13 @@ export function discoverHooks(remote, fallbackName) {
|
|
|
164
237
|
.flat()
|
|
165
238
|
.map((d) => d.script),
|
|
166
239
|
...blobEntries
|
|
167
|
-
.filter((e) => scriptLike
|
|
240
|
+
.filter((e) => scriptLike(e.path) || e.mode === GIT_MODE.executable)
|
|
168
241
|
.map((e) => e.path),
|
|
169
242
|
]),
|
|
170
243
|
];
|
|
171
|
-
if (!scripts.length)
|
|
244
|
+
if (!scripts.length) {
|
|
172
245
|
return { candidates: [], skipped };
|
|
246
|
+
}
|
|
173
247
|
return {
|
|
174
248
|
candidates: [
|
|
175
249
|
{
|
|
@@ -187,10 +261,12 @@ const commonFolder = (paths) => {
|
|
|
187
261
|
const parts = paths.map((path) => path.split("/").slice(0, -1));
|
|
188
262
|
const first = parts[0] ?? [];
|
|
189
263
|
let length = first.length;
|
|
190
|
-
for (const other of parts)
|
|
264
|
+
for (const other of parts) {
|
|
191
265
|
while (length &&
|
|
192
|
-
other.slice(0, length).join("/") !== first.slice(0, length).join("/"))
|
|
266
|
+
other.slice(0, length).join("/") !== first.slice(0, length).join("/")) {
|
|
193
267
|
length--;
|
|
268
|
+
}
|
|
269
|
+
}
|
|
194
270
|
return first.slice(0, length).join("/");
|
|
195
271
|
};
|
|
196
272
|
/** Turns the choices made in the picker into a Hook package in BarnDog's format. */
|
|
@@ -207,22 +283,19 @@ export function buildHookPackage(remote, input) {
|
|
|
207
283
|
folders.some((folder) => folder && entry.path.startsWith(`${folder}/`))))
|
|
208
284
|
.map((entry) => ({
|
|
209
285
|
path: relative(entry.path),
|
|
210
|
-
data: remote
|
|
211
|
-
executable: entry.mode ===
|
|
286
|
+
data: blobOf(remote, entry),
|
|
287
|
+
executable: entry.mode === GIT_MODE.executable || scripts.includes(entry.path),
|
|
212
288
|
}));
|
|
213
289
|
const implementations = {};
|
|
214
|
-
for (const
|
|
215
|
-
|
|
290
|
+
for (const harness of hookHarnesses) {
|
|
291
|
+
const events = input.implementations[harness] ?? [];
|
|
292
|
+
if (!events.length) {
|
|
216
293
|
continue;
|
|
294
|
+
}
|
|
217
295
|
const byEvent = {};
|
|
218
296
|
for (const draft of events) {
|
|
219
|
-
const command = draft.command.replace(
|
|
220
|
-
(byEvent[draft.event] ??= []).push(harness
|
|
221
|
-
? { command, ...(draft.matcher ? { matcher: draft.matcher } : {}) }
|
|
222
|
-
: {
|
|
223
|
-
...(draft.matcher ? { matcher: draft.matcher } : {}),
|
|
224
|
-
hooks: [{ type: "command", command }],
|
|
225
|
-
});
|
|
297
|
+
const command = draft.command.replace(`@@${draft.script}`, () => `${ROOT_TOKEN}/${relative(draft.script)}`);
|
|
298
|
+
(byEvent[draft.event] ??= []).push(adapters[harness].hooks.entry(command, draft.matcher));
|
|
226
299
|
}
|
|
227
300
|
implementations[harness] = {
|
|
228
301
|
compatibility: "supported",
|
|
@@ -1,33 +1,65 @@
|
|
|
1
|
+
import { localPath } from "../../platform.js";
|
|
1
2
|
import { existsSync } from "node:fs";
|
|
2
3
|
import { rm, rmdir, stat } from "node:fs/promises";
|
|
3
|
-
import {
|
|
4
|
-
import { dirname, join, parse, resolve } from "node:path";
|
|
4
|
+
import { dirname, join, parse } from "node:path";
|
|
5
5
|
import { CliError } from "../../errors.js";
|
|
6
|
-
import { folderSnapshot, isBlob } from "../
|
|
6
|
+
import { folderSnapshot, isBlob } from "../workspace/snapshot.js";
|
|
7
|
+
/**
|
|
8
|
+
* `~`, `~/…` or `~\…` at the start of a path, which a POSIX shell would
|
|
9
|
+
* expand to the home folder; Windows shells pass it to BarnDog unexpanded.
|
|
10
|
+
*/
|
|
11
|
+
const HOME_PREFIX = /^~(?=[\\/]|$)/;
|
|
12
|
+
/**
|
|
13
|
+
* `~/skills` → `/Users/me/skills`; other paths are unchanged.
|
|
14
|
+
*
|
|
15
|
+
* @internal Exported for its table test in `src/tests/patterns.test.ts`.
|
|
16
|
+
*/
|
|
17
|
+
export const expandHome = (path, runtime) => {
|
|
18
|
+
const { home } = runtime;
|
|
19
|
+
return path.replace(HOME_PREFIX, () => home);
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* Text that can only mean a folder on this machine, never a repository URL:
|
|
23
|
+
* `/abs`, `.`, `..`, `./x`, `../x`, `~` or `~/x`, and on Windows also `\x`,
|
|
24
|
+
* `C:\x` or `C:/x`, `.\x`, `..\x` and `~\x`.
|
|
25
|
+
*/
|
|
26
|
+
const LOCAL_PATH = /^(?:[\\/]|[a-z]:|\.{1,2}(?:[\\/]|$)|~(?:[\\/]|$))/i;
|
|
27
|
+
/**
|
|
28
|
+
* Recognizes path-like import inputs after trimming whitespace; does not check
|
|
29
|
+
* filesystem existence.
|
|
30
|
+
*
|
|
31
|
+
* @internal Exported for its table test in `src/tests/patterns.test.ts`.
|
|
32
|
+
*/
|
|
33
|
+
export const looksLocal = (source) => LOCAL_PATH.test(source.trim());
|
|
7
34
|
/** The plain folder a source points at; Git repos return null and are fetched instead. */
|
|
8
|
-
export async function plainFolder(source) {
|
|
35
|
+
export async function plainFolder(source, runtime) {
|
|
9
36
|
const value = source.trim();
|
|
10
|
-
const path =
|
|
37
|
+
const path = localPath(expandHome(value, runtime), runtime);
|
|
11
38
|
const directory = await stat(path).then((info) => info.isDirectory(), () => false);
|
|
12
|
-
if (!directory)
|
|
39
|
+
if (!directory) {
|
|
13
40
|
return null;
|
|
41
|
+
}
|
|
14
42
|
const isRepo = existsSync(join(path, ".git")) ||
|
|
15
43
|
(existsSync(join(path, "HEAD")) && existsSync(join(path, "objects")));
|
|
16
44
|
return isRepo ? null : path;
|
|
17
45
|
}
|
|
18
46
|
/** Git can't help with a path that isn't there, so say so instead of suggesting a clone. */
|
|
19
|
-
export function assertSourceExists(source) {
|
|
47
|
+
export function assertSourceExists(source, runtime) {
|
|
20
48
|
const value = source.trim();
|
|
21
|
-
if (
|
|
49
|
+
if (!looksLocal(value)) {
|
|
22
50
|
return;
|
|
23
|
-
|
|
51
|
+
}
|
|
52
|
+
if (!existsSync(localPath(expandHome(value, runtime), runtime))) {
|
|
24
53
|
throw new CliError(`Can't find ${value}.`);
|
|
54
|
+
}
|
|
25
55
|
}
|
|
26
56
|
/** Presents a folder the way a fetched repo looks, so discovery treats both alike. */
|
|
27
|
-
export async function readFolder(path) {
|
|
28
|
-
|
|
57
|
+
export async function readFolder(path, runtime) {
|
|
58
|
+
const { home } = runtime;
|
|
59
|
+
if (path === home || path === parse(path).root) {
|
|
29
60
|
throw new CliError(`${path} is too broad to search. Point at the folder holding the Skill.`);
|
|
30
|
-
|
|
61
|
+
}
|
|
62
|
+
const snapshot = await folderSnapshot(path, runtime);
|
|
31
63
|
const blobs = await snapshot.readBlobs(snapshot.entries
|
|
32
64
|
.filter((entry) => isBlob(entry.mode))
|
|
33
65
|
.map((entry) => entry.hash));
|
|
@@ -42,11 +74,13 @@ export async function removeImported(root, entries) {
|
|
|
42
74
|
for (const entry of entries) {
|
|
43
75
|
const file = join(root, entry.path);
|
|
44
76
|
await rm(file, { force: true });
|
|
45
|
-
for (let dir = dirname(file); dir !== root; dir = dirname(dir))
|
|
77
|
+
for (let dir = dirname(file); dir !== root; dir = dirname(dir)) {
|
|
46
78
|
folders.add(dir);
|
|
79
|
+
}
|
|
47
80
|
}
|
|
48
81
|
const deepestFirst = [...folders].sort((a, b) => b.length - a.length);
|
|
49
|
-
for (const folder of deepestFirst)
|
|
82
|
+
for (const folder of deepestFirst) {
|
|
50
83
|
await rmdir(folder).catch(() => { });
|
|
84
|
+
}
|
|
51
85
|
return !existsSync(root);
|
|
52
86
|
}
|