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.
- package/README.md +31 -28
- package/dist/cli.js +11 -7
- package/dist/commands/add.js +34 -21
- package/dist/commands/adopt.js +91 -0
- package/dist/commands/arguments.js +12 -0
- package/dist/commands/asset-install.js +161 -0
- package/dist/commands/asset-list.js +126 -0
- package/dist/commands/asset-share.js +94 -0
- package/dist/commands/auth.js +4 -0
- package/dist/commands/availability.js +72 -27
- package/dist/commands/capabilities.js +79 -417
- package/dist/commands/collaboration.js +212 -108
- package/dist/commands/environment.js +18 -411
- package/dist/commands/github.js +200 -0
- package/dist/commands/harnesses.js +74 -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-env.js +78 -0
- package/dist/commands/mcp.js +64 -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 +36 -25
- package/dist/commands/sync.js +13 -5
- package/dist/commands/workspace.js +75 -23
- package/dist/config/environment.js +13 -27
- package/dist/config/paths.js +81 -0
- package/dist/config/selection.js +30 -0
- package/dist/config/settings.js +99 -108
- package/dist/config/state.js +67 -55
- 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/adoption/adopt.js +234 -0
- package/dist/features/adoption/copies.js +29 -0
- package/dist/features/adoption/originals.js +116 -0
- package/dist/features/adoption/record.js +120 -0
- package/dist/features/adoption/restore.js +28 -0
- package/dist/features/adoption/scan.js +482 -0
- package/dist/features/adoption/undo.js +42 -0
- package/dist/features/asset-kinds/index.js +129 -0
- package/dist/features/asset-selection/index.js +51 -19
- package/dist/features/auth/credentials.js +80 -54
- package/dist/features/auth/session.js +83 -49
- package/dist/features/auth/transport.js +69 -17
- 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 +242 -152
- package/dist/features/collaboration/workspace-github.js +118 -54
- package/dist/features/collaboration/workspace-store.js +157 -97
- package/dist/features/collaboration/workspace.js +278 -173
- package/dist/features/discovery/index.js +68 -57
- package/dist/features/doctor/index.js +56 -26
- package/dist/features/environment/auto-sync.js +28 -27
- package/dist/features/environment/harnesses.js +36 -0
- package/dist/features/environment/moves.js +171 -0
- package/dist/features/environment/names.js +73 -49
- package/dist/features/environment/operations.js +322 -229
- package/dist/features/environment/own-entries.js +89 -0
- package/dist/features/environment/settle-names.js +91 -0
- package/dist/features/environment/stage.js +202 -0
- package/dist/features/environment/sync.js +127 -487
- package/dist/features/environment/transaction.js +179 -147
- package/dist/features/environment/writes.js +243 -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 +55 -0
- package/dist/features/hooks/divergence.js +36 -12
- package/dist/features/hooks/test.js +91 -66
- package/dist/features/hooks/types.js +1 -0
- package/dist/features/imports/discover.js +133 -60
- package/dist/features/imports/folder.js +48 -14
- package/dist/features/imports/local.js +127 -135
- package/dist/features/imports/remote.js +46 -26
- package/dist/features/inspection/index.js +17 -17
- package/dist/features/inventory/index.js +111 -111
- package/dist/features/inventory/show.js +74 -0
- package/dist/features/knowledge/index.js +69 -49
- package/dist/features/mcps/catalog.js +31 -0
- package/dist/features/mcps/import.js +369 -0
- package/dist/features/mcps/index.js +104 -50
- package/dist/features/mcps/values.js +33 -0
- package/dist/features/migration/migrate.js +263 -0
- package/dist/features/migration/move.js +448 -0
- package/dist/features/migration/promote.js +26 -0
- package/dist/features/native/adapters.js +69 -96
- package/dist/features/native/configuration.js +134 -84
- package/dist/features/native/hook-shell.js +55 -0
- package/dist/features/native/plugin-module.js +56 -0
- package/dist/features/native/secret-values.js +74 -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/secrets/index.js +77 -0
- 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 +121 -54
- package/dist/features/workspace/git.js +221 -0
- package/dist/features/workspace/installed.js +92 -0
- package/dist/features/{git-workspace → workspace}/overlay.js +53 -46
- package/dist/features/workspace/packages.js +173 -0
- package/dist/features/{git-workspace → workspace}/publish.js +120 -64
- package/dist/features/workspace/repo-source.js +193 -0
- package/dist/features/{git-workspace → workspace}/setup.js +72 -45
- package/dist/features/{git-workspace → workspace}/snapshot.js +60 -19
- 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 +67 -1
- package/dist/harnesses/cursor.js +22 -1
- package/dist/harnesses/detect.js +6 -50
- package/dist/harnesses/formats.js +52 -0
- package/dist/harnesses/opencode.js +108 -0
- package/dist/harnesses/registry.js +35 -2
- package/dist/platform.js +403 -0
- package/dist/program.js +275 -56
- 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 +107 -0
- package/dist/shared/lock.js +113 -0
- package/dist/shared/lookup.js +11 -0
- package/dist/shared/patterns.js +102 -0
- package/dist/shared/shell.js +20 -0
- package/dist/shared/values.js +26 -0
- package/dist/ui/add-asset.js +41 -400
- package/dist/ui/add-hook.js +219 -0
- package/dist/ui/add-mcp.js +170 -0
- package/dist/ui/add-prompts.js +47 -0
- package/dist/ui/add-skills.js +117 -0
- package/dist/ui/adopt.js +197 -0
- package/dist/ui/asset-list.js +31 -13
- package/dist/ui/assets.js +38 -47
- package/dist/ui/auth.js +45 -34
- package/dist/ui/clash.js +10 -6
- package/dist/ui/collaboration.js +116 -44
- package/dist/ui/connection.js +17 -6
- 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/harness-picker.js +18 -0
- package/dist/ui/hook-compatibility.js +14 -6
- package/dist/ui/mcp.js +28 -3
- package/dist/ui/move.js +57 -6
- package/dist/ui/onboarding.js +148 -95
- package/dist/ui/options.js +9 -0
- package/dist/ui/output.js +108 -43
- package/dist/ui/package-details.js +34 -0
- package/dist/ui/pick.js +45 -33
- package/dist/ui/scope-install.js +18 -7
- package/dist/ui/secret-input.js +19 -0
- package/dist/ui/selection.js +17 -11
- package/dist/ui/theme.js +37 -14
- package/dist/version.js +6 -3
- package/package.json +13 -3
- 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/move.js +0 -337
- 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,46 +1,65 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { realpath } from "node:fs/promises";
|
|
4
|
-
import { z } from "zod";
|
|
5
|
-
import { readSettings, SetupRequiredError } from "../../config/settings.js";
|
|
1
|
+
import { basename } from "node:path";
|
|
2
|
+
import { readSettings, SetupRequiredError, } from "../../config/settings.js";
|
|
6
3
|
import { selectionState } from "../../config/environment.js";
|
|
7
4
|
import { readState } from "../../config/state.js";
|
|
8
|
-
import { treeFingerprint } from "../
|
|
9
|
-
import {
|
|
10
|
-
import { environmentCatalog
|
|
11
|
-
import { openRepoSource } from "../
|
|
12
|
-
import { localOverlay, mergeLocalCatalog } from "../
|
|
13
|
-
import { scopeSchema } from "@barndog-ai/api-contract";
|
|
5
|
+
import { treeFingerprint } from "../workspace/tree.js";
|
|
6
|
+
import { linkTarget } from "../environment/transaction.js";
|
|
7
|
+
import { environmentCatalog } from "../server/catalog.js";
|
|
8
|
+
import { openRepoSource } from "../workspace/workspace-source.js";
|
|
9
|
+
import { localOverlay, mergeLocalCatalog, moveDestination, readMoved, } from "../workspace/overlay.js";
|
|
14
10
|
import { resolveAssets } from "../asset-selection/index.js";
|
|
15
|
-
import { installedName,
|
|
16
|
-
import {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
versionId: z.string().optional(),
|
|
30
|
-
}));
|
|
11
|
+
import { installedName, resolveClashes } from "../environment/names.js";
|
|
12
|
+
import { originLabel, scopes } from "../server/origin.js";
|
|
13
|
+
import { isAssetKind } from "../asset-kinds/index.js";
|
|
14
|
+
import { isHarness } from "../../harnesses/registry.js";
|
|
15
|
+
/** Local assets still moving to the shared workspace; none without a local folder. */
|
|
16
|
+
async function pendingMoves(settings) {
|
|
17
|
+
const folder = settings.localWorkspace?.path;
|
|
18
|
+
const records = folder ? await readMoved(folder) : [];
|
|
19
|
+
return records.map((entry) => ({
|
|
20
|
+
kind: entry.kind,
|
|
21
|
+
name: entry.name,
|
|
22
|
+
to: moveDestination(entry),
|
|
23
|
+
}));
|
|
24
|
+
}
|
|
31
25
|
/** What is selected and what is actually installed on this machine. */
|
|
32
|
-
|
|
26
|
+
/** The state of a selected asset; the first that applies wins. */
|
|
27
|
+
function inventoryState(asset) {
|
|
28
|
+
if (!asset.enabled) {
|
|
29
|
+
return "disabled";
|
|
30
|
+
}
|
|
31
|
+
if (asset.clashed) {
|
|
32
|
+
return "clash";
|
|
33
|
+
}
|
|
34
|
+
if (asset.modified) {
|
|
35
|
+
return "modified";
|
|
36
|
+
}
|
|
37
|
+
if (!asset.present) {
|
|
38
|
+
return "pending";
|
|
39
|
+
}
|
|
40
|
+
return asset.outdated ? "outdated" : "installed";
|
|
41
|
+
}
|
|
42
|
+
/** The state of an installed asset no longer selected. */
|
|
43
|
+
function leftoverState(modified, offline) {
|
|
44
|
+
if (modified) {
|
|
45
|
+
return "modified";
|
|
46
|
+
}
|
|
47
|
+
return offline ? "installed" : "removing";
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Compares configured selections, catalog and installed files to report status;
|
|
51
|
+
* unreachable sources fall back to local state.
|
|
52
|
+
*/
|
|
53
|
+
export async function inventory(runtime) {
|
|
54
|
+
const { home } = runtime;
|
|
33
55
|
const settings = await readSettings(home);
|
|
34
|
-
if (!settings)
|
|
56
|
+
if (!settings) {
|
|
35
57
|
throw new SetupRequiredError();
|
|
36
|
-
|
|
37
|
-
const
|
|
38
|
-
const
|
|
39
|
-
const
|
|
40
|
-
const
|
|
41
|
-
const installed = installedSchema.parse(parsed.installed ?? []);
|
|
42
|
-
const conn = settings.version === 2 ? settings.connection : undefined;
|
|
43
|
-
const localNames = settings.version === 2 ? (settings.localNames ?? {}) : {};
|
|
58
|
+
}
|
|
59
|
+
const state = await readState(home);
|
|
60
|
+
const { native, installed } = state;
|
|
61
|
+
const conn = settings.connection;
|
|
62
|
+
const localNames = settings.localNames ?? {};
|
|
44
63
|
const linksOf = (id) => state.links.filter((l) => l.id === id);
|
|
45
64
|
const nativeOf = (id) => native.filter((n) => n.id === id);
|
|
46
65
|
const items = [];
|
|
@@ -48,75 +67,57 @@ export async function inventory(home = homedir()) {
|
|
|
48
67
|
// The same comparisons that stop sync, so status can't call these up to date.
|
|
49
68
|
const modified = new Set();
|
|
50
69
|
for (const tree of installed) {
|
|
51
|
-
const actual = await treeFingerprint(tree.path);
|
|
52
|
-
if (tree.fingerprint && actual !== null && actual !== tree.fingerprint)
|
|
70
|
+
const actual = await treeFingerprint(tree.path, runtime);
|
|
71
|
+
if (tree.fingerprint && actual !== null && actual !== tree.fingerprint) {
|
|
53
72
|
modified.add(tree.id);
|
|
73
|
+
}
|
|
54
74
|
}
|
|
55
75
|
for (const link of state.links) {
|
|
56
76
|
const actual = await linkTarget(link.target);
|
|
57
|
-
if (actual !== null && actual !== link.source)
|
|
77
|
+
if (actual !== null && actual !== link.source) {
|
|
58
78
|
modified.add(link.id);
|
|
59
|
-
}
|
|
60
|
-
for (const local of settings.skills) {
|
|
61
|
-
if (!("source" in local))
|
|
62
|
-
continue;
|
|
63
|
-
seen.add(local.id);
|
|
64
|
-
const links = linksOf(local.id);
|
|
65
|
-
let name = basename(local.source);
|
|
66
|
-
try {
|
|
67
|
-
name = (await validateSkillSource(await realpath(local.source))).name;
|
|
68
|
-
}
|
|
69
|
-
catch {
|
|
70
|
-
/* the folder may be temporarily unavailable */
|
|
71
79
|
}
|
|
72
|
-
items.push({
|
|
73
|
-
id: local.id,
|
|
74
|
-
kind: "skill",
|
|
75
|
-
name,
|
|
76
|
-
installedName: name,
|
|
77
|
-
origin: "local",
|
|
78
|
-
via: ["config"],
|
|
79
|
-
state: !local.enabled
|
|
80
|
-
? "disabled"
|
|
81
|
-
: links.length
|
|
82
|
-
? "installed"
|
|
83
|
-
: "pending",
|
|
84
|
-
harnesses: links.map((l) => l.harness),
|
|
85
|
-
paths: [local.source, ...links.map((l) => l.target)],
|
|
86
|
-
});
|
|
87
80
|
}
|
|
88
81
|
let offline = null;
|
|
89
|
-
const repo = openRepoSource(settings,
|
|
82
|
+
const repo = openRepoSource(settings, runtime, { refresh: "auto" });
|
|
90
83
|
if (conn || repo) {
|
|
91
84
|
try {
|
|
92
85
|
const { catalog: primaryCatalog, scopes: loadScopes } = await (async () => {
|
|
93
86
|
if (repo) {
|
|
94
87
|
const model = await repo.model();
|
|
95
88
|
offline = repo.notices()[0] ?? null;
|
|
96
|
-
return {
|
|
89
|
+
return {
|
|
90
|
+
catalog: model.catalog,
|
|
91
|
+
scopes: () => Promise.resolve(model.scopes),
|
|
92
|
+
};
|
|
97
93
|
}
|
|
98
|
-
const remote = await environmentCatalog(
|
|
94
|
+
const remote = await environmentCatalog(runtime, conn);
|
|
99
95
|
return {
|
|
100
96
|
catalog: remote.catalog,
|
|
101
|
-
scopes: () =>
|
|
97
|
+
scopes: () => scopes(remote.connection, runtime),
|
|
102
98
|
};
|
|
103
99
|
})();
|
|
104
|
-
const overlay = localOverlay(settings,
|
|
100
|
+
const overlay = localOverlay(settings, runtime);
|
|
105
101
|
const catalog = overlay
|
|
106
102
|
? await mergeLocalCatalog(primaryCatalog, overlay)
|
|
107
103
|
: primaryCatalog;
|
|
108
104
|
const selection = selectionState(settings);
|
|
109
105
|
const effective = resolveAssets(catalog, selection);
|
|
110
|
-
const outcome = await resolveClashes(effective.assets
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
106
|
+
const outcome = await resolveClashes(effective.assets.flatMap(({ asset, enabled }) => {
|
|
107
|
+
const { kind } = asset;
|
|
108
|
+
if (!enabled || kind === "hook") {
|
|
109
|
+
return [];
|
|
110
|
+
}
|
|
111
|
+
return [
|
|
112
|
+
{
|
|
113
|
+
id: asset.id,
|
|
114
|
+
kind,
|
|
115
|
+
name: asset.name,
|
|
116
|
+
origin: asset.origin,
|
|
117
|
+
installed: linksOf(asset.id).length > 0 || nativeOf(asset.id).length > 0,
|
|
118
|
+
},
|
|
119
|
+
];
|
|
120
|
+
}), localNames);
|
|
120
121
|
const clashed = new Set(outcome.skipped.map((c) => c.incoming.id));
|
|
121
122
|
for (const entry of effective.assets) {
|
|
122
123
|
const { asset } = entry;
|
|
@@ -128,7 +129,7 @@ export async function inventory(home = homedir()) {
|
|
|
128
129
|
const harnesses = [
|
|
129
130
|
...new Set([
|
|
130
131
|
...links.map((l) => l.harness),
|
|
131
|
-
...entries.map((n) => n.harness),
|
|
132
|
+
...entries.map((n) => n.harness).filter(isHarness),
|
|
132
133
|
]),
|
|
133
134
|
];
|
|
134
135
|
items.push({
|
|
@@ -140,17 +141,13 @@ export async function inventory(home = homedir()) {
|
|
|
140
141
|
via: entry.contributions.map((c) => c.type === "individual"
|
|
141
142
|
? "individual"
|
|
142
143
|
: originLabel(asset.origin.localOnly ? asset.origin : c.scope)),
|
|
143
|
-
state:
|
|
144
|
-
|
|
145
|
-
: clashed.has(asset.id)
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
? "pending"
|
|
151
|
-
: tree?.versionId && tree.versionId !== asset.publishedVersion
|
|
152
|
-
? "outdated"
|
|
153
|
-
: "installed",
|
|
144
|
+
state: inventoryState({
|
|
145
|
+
enabled: entry.enabled,
|
|
146
|
+
clashed: clashed.has(asset.id),
|
|
147
|
+
modified: modified.has(asset.id),
|
|
148
|
+
present,
|
|
149
|
+
outdated: Boolean(tree?.versionId && tree.versionId !== asset.publishedVersion),
|
|
150
|
+
}),
|
|
154
151
|
harnesses,
|
|
155
152
|
paths: [
|
|
156
153
|
...(tree ? [tree.path] : []),
|
|
@@ -159,13 +156,14 @@ export async function inventory(home = homedir()) {
|
|
|
159
156
|
],
|
|
160
157
|
});
|
|
161
158
|
}
|
|
162
|
-
const
|
|
163
|
-
for (const item of items)
|
|
159
|
+
const visible = await loadScopes();
|
|
160
|
+
for (const item of items) {
|
|
164
161
|
item.via = item.via.map((label) => {
|
|
165
162
|
const [type, id] = label.split("/");
|
|
166
|
-
const scope =
|
|
163
|
+
const scope = visible.find((s) => s.type === type && (type === "org" || s.id === id));
|
|
167
164
|
return scope ? originLabel(scope) : label;
|
|
168
165
|
});
|
|
166
|
+
}
|
|
169
167
|
}
|
|
170
168
|
catch (error) {
|
|
171
169
|
offline = error instanceof Error ? error.message : String(error);
|
|
@@ -178,19 +176,21 @@ export async function inventory(home = homedir()) {
|
|
|
178
176
|
.filter((n) => n.kind !== "knowledge" && n.kind !== "sync")
|
|
179
177
|
.map((n) => n.id),
|
|
180
178
|
])) {
|
|
181
|
-
if (seen.has(id))
|
|
179
|
+
if (seen.has(id)) {
|
|
182
180
|
continue;
|
|
181
|
+
}
|
|
183
182
|
const links = linksOf(id);
|
|
184
183
|
const entries = nativeOf(id);
|
|
185
|
-
const
|
|
186
|
-
const
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
184
|
+
const [link] = links;
|
|
185
|
+
const [entry] = entries;
|
|
186
|
+
const kind = link ? "skill" : entry?.kind;
|
|
187
|
+
if (!isAssetKind(kind)) {
|
|
188
|
+
continue;
|
|
189
|
+
}
|
|
190
|
+
const installedPath = installed.find((t) => t.id === id)?.path;
|
|
191
|
+
const installedFolder = installedPath ? basename(installedPath) : undefined;
|
|
192
|
+
const unlinkedName = kind === "mcp" ? entry?.key : installedFolder;
|
|
193
|
+
const name = link ? basename(link.target) : (unlinkedName ?? id);
|
|
194
194
|
items.push({
|
|
195
195
|
id,
|
|
196
196
|
kind,
|
|
@@ -198,11 +198,11 @@ export async function inventory(home = homedir()) {
|
|
|
198
198
|
installedName: name,
|
|
199
199
|
origin: "—",
|
|
200
200
|
via: [],
|
|
201
|
-
state: modified.has(id)
|
|
201
|
+
state: leftoverState(modified.has(id), Boolean(offline)),
|
|
202
202
|
harnesses: [
|
|
203
203
|
...new Set([
|
|
204
204
|
...links.map((l) => l.harness),
|
|
205
|
-
...entries.map((n) => n.harness),
|
|
205
|
+
...entries.map((n) => n.harness).filter(isHarness),
|
|
206
206
|
]),
|
|
207
207
|
],
|
|
208
208
|
paths: [
|
|
@@ -216,9 +216,9 @@ export async function inventory(home = homedir()) {
|
|
|
216
216
|
return {
|
|
217
217
|
harnesses: settings.harnesses,
|
|
218
218
|
server: conn?.server ?? repo?.label ?? null,
|
|
219
|
-
knowledge: !!(conn || repo) &&
|
|
220
|
-
(settings.version !== 2 || settings.knowledge !== false),
|
|
219
|
+
knowledge: !!(conn || repo) && settings.knowledge !== false,
|
|
221
220
|
offline,
|
|
222
221
|
items,
|
|
222
|
+
moving: await pendingMoves(settings),
|
|
223
223
|
};
|
|
224
224
|
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { hookSchema, skillSchema } from "@barndog-ai/api-contract";
|
|
2
|
+
import { readSettings } from "../../config/settings.js";
|
|
3
|
+
import { hookHarnesses } from "../../harnesses/registry.js";
|
|
4
|
+
import { selectAsset } from "../server/catalog.js";
|
|
5
|
+
import { originLabel } from "../server/origin.js";
|
|
6
|
+
import { repoForOrigin, selectRepoAsset, showRepoAsset, } from "../workspace/assets.js";
|
|
7
|
+
import { inventory } from "./index.js";
|
|
8
|
+
/** What a Skill or Hook is, where it comes from, and where this machine has it. */
|
|
9
|
+
export async function showPackage(kind, name, origin, runtime) {
|
|
10
|
+
const { home } = runtime;
|
|
11
|
+
const settings = await readSettings(home);
|
|
12
|
+
const repo = settings && repoForOrigin(settings, runtime, origin);
|
|
13
|
+
const described = repo
|
|
14
|
+
? repoDetails(selectRepoAsset(await repo.model(), kind, name, origin), kind)
|
|
15
|
+
: await cloudDetails(kind, name, origin, runtime);
|
|
16
|
+
const item = (await inventory(runtime)).items.find((entry) => entry.id === described.id);
|
|
17
|
+
return {
|
|
18
|
+
...described,
|
|
19
|
+
installed: item
|
|
20
|
+
? { state: item.state, harnesses: item.harnesses, paths: item.paths }
|
|
21
|
+
: null,
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
function repoDetails(asset, kind) {
|
|
25
|
+
const view = showRepoAsset(asset);
|
|
26
|
+
const events = view.manifest
|
|
27
|
+
? eventsByTool((harness) => view.manifest?.implementations[harness]?.events)
|
|
28
|
+
: undefined;
|
|
29
|
+
return {
|
|
30
|
+
id: view.id,
|
|
31
|
+
kind,
|
|
32
|
+
name: view.name,
|
|
33
|
+
origin: view.origin,
|
|
34
|
+
version: view.version,
|
|
35
|
+
description: view.description,
|
|
36
|
+
...(events ? { events } : {}),
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
async function cloudDetails(kind, name, origin, runtime) {
|
|
40
|
+
const { asset } = await selectAsset(kind, name, origin, runtime);
|
|
41
|
+
if (kind === "skill") {
|
|
42
|
+
const skill = skillSchema.parse(asset);
|
|
43
|
+
return {
|
|
44
|
+
id: skill.id,
|
|
45
|
+
kind,
|
|
46
|
+
name: skill.name,
|
|
47
|
+
origin: originLabel(skill.origin),
|
|
48
|
+
version: skill.version.number,
|
|
49
|
+
description: skill.version.description,
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
const hook = hookSchema.parse(asset);
|
|
53
|
+
return {
|
|
54
|
+
id: hook.id,
|
|
55
|
+
kind,
|
|
56
|
+
name: hook.name,
|
|
57
|
+
origin: originLabel(hook.origin),
|
|
58
|
+
version: hook.version.number,
|
|
59
|
+
description: hook.version.description,
|
|
60
|
+
events: eventsByTool((harness) => hook.compatibility.find((row) => row.harness === harness)
|
|
61
|
+
?.implementation?.events),
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
/** Event names per tool, leaving out tools the Hook has no implementation for. */
|
|
65
|
+
function eventsByTool(eventsOf) {
|
|
66
|
+
const result = {};
|
|
67
|
+
for (const harness of hookHarnesses) {
|
|
68
|
+
const events = eventsOf(harness);
|
|
69
|
+
if (events) {
|
|
70
|
+
result[harness] = Object.keys(events);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
return result;
|
|
74
|
+
}
|
|
@@ -1,20 +1,22 @@
|
|
|
1
|
-
import { homedir } from "node:os";
|
|
2
1
|
import { knowledgeDocumentSchema, knowledgeIndexSchema, } from "@barndog-ai/api-contract";
|
|
3
|
-
import { connection } from "../
|
|
4
|
-
import {
|
|
5
|
-
import { openRepoSource } from "../
|
|
6
|
-
import { activeLocal, localOverlay } from "../
|
|
2
|
+
import { connection } from "../server/connection.js";
|
|
3
|
+
import { parsed } from "../server/client.js";
|
|
4
|
+
import { openRepoSource } from "../workspace/workspace-source.js";
|
|
5
|
+
import { activeLocal, localOverlay } from "../workspace/overlay.js";
|
|
7
6
|
import { readSettings } from "../../config/settings.js";
|
|
8
7
|
import { CliError } from "../../errors.js";
|
|
8
|
+
import { allPages, PAGE_SIZE } from "../server/pages.js";
|
|
9
|
+
import { apiClient } from "../auth/transport.js";
|
|
9
10
|
/** Session start must stay fast, so reading knowledge never contacts the Git host. */
|
|
10
|
-
async function repoKnowledge(
|
|
11
|
+
async function repoKnowledge(runtime) {
|
|
12
|
+
const { home } = runtime;
|
|
11
13
|
const settings = await readSettings(home);
|
|
12
|
-
const repo = settings && openRepoSource(settings,
|
|
14
|
+
const repo = settings && openRepoSource(settings, runtime, { refresh: "none" });
|
|
13
15
|
return repo ? (await repo.model()).knowledge : undefined;
|
|
14
16
|
}
|
|
15
|
-
async function sharedKnowledge(
|
|
16
|
-
const local = await repoKnowledge(
|
|
17
|
-
if (local)
|
|
17
|
+
async function sharedKnowledge(runtime, always) {
|
|
18
|
+
const local = await repoKnowledge(runtime);
|
|
19
|
+
if (local) {
|
|
18
20
|
return local
|
|
19
21
|
.filter((doc) => !always || doc.content.accessMode === "always")
|
|
20
22
|
.map((doc) => ({
|
|
@@ -26,62 +28,70 @@ async function sharedKnowledge(home, always) {
|
|
|
26
28
|
versionId: doc.version,
|
|
27
29
|
version: 0,
|
|
28
30
|
}));
|
|
29
|
-
|
|
30
|
-
const
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
seen.add(page.nextCursor);
|
|
44
|
-
cursor = page.nextCursor;
|
|
45
|
-
} while (cursor);
|
|
46
|
-
return documents;
|
|
31
|
+
}
|
|
32
|
+
const conn = await connection(runtime);
|
|
33
|
+
return allPages(async (cursor) => {
|
|
34
|
+
const page = await parsed(knowledgeIndexSchema, apiClient(conn.server, runtime).GET("/v1/knowledge", {
|
|
35
|
+
params: {
|
|
36
|
+
query: {
|
|
37
|
+
limit: PAGE_SIZE,
|
|
38
|
+
cursor,
|
|
39
|
+
...(always ? { accessMode: "always" } : {}),
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
}));
|
|
43
|
+
return { items: page.documents, nextCursor: page.nextCursor };
|
|
44
|
+
});
|
|
47
45
|
}
|
|
48
|
-
async function sharedDocument(name,
|
|
49
|
-
const local = await repoKnowledge(
|
|
46
|
+
async function sharedDocument(name, runtime) {
|
|
47
|
+
const local = await repoKnowledge(runtime);
|
|
50
48
|
if (local) {
|
|
51
49
|
const doc = local.find((d) => d.content.name === name);
|
|
52
|
-
if (!doc)
|
|
50
|
+
if (!doc) {
|
|
53
51
|
throw new CliError(`No knowledge document named ${name}.`, "barndog knowledge list");
|
|
52
|
+
}
|
|
54
53
|
return { id: doc.id, version: { id: doc.version, content: doc.content } };
|
|
55
54
|
}
|
|
56
|
-
const conn = await connection(
|
|
57
|
-
return
|
|
55
|
+
const conn = await connection(runtime);
|
|
56
|
+
return parsed(knowledgeDocumentSchema, apiClient(conn.server, runtime).GET("/v1/knowledge/{selector}", {
|
|
57
|
+
params: { path: { selector: name } },
|
|
58
|
+
}));
|
|
58
59
|
}
|
|
59
|
-
async function keptLocal(
|
|
60
|
+
async function keptLocal(runtime, shared) {
|
|
61
|
+
const { home } = runtime;
|
|
60
62
|
const settings = await readSettings(home);
|
|
61
|
-
const overlay = settings && localOverlay(settings,
|
|
62
|
-
if (!overlay)
|
|
63
|
+
const overlay = settings && localOverlay(settings, runtime);
|
|
64
|
+
if (!overlay) {
|
|
63
65
|
return [];
|
|
66
|
+
}
|
|
64
67
|
return (await activeLocal(overlay, shared.map((doc) => ({ kind: "knowledge", name: doc.name })))).knowledge;
|
|
65
68
|
}
|
|
66
69
|
/** Knowledge files that can't be read, so they don't vanish without a word. */
|
|
67
|
-
export async function knowledgeProblems(
|
|
70
|
+
export async function knowledgeProblems(runtime) {
|
|
71
|
+
const { home } = runtime;
|
|
68
72
|
const settings = await readSettings(home);
|
|
69
|
-
if (!settings)
|
|
73
|
+
if (!settings) {
|
|
70
74
|
return [];
|
|
75
|
+
}
|
|
71
76
|
const sources = [
|
|
72
|
-
openRepoSource(settings,
|
|
73
|
-
localOverlay(settings,
|
|
77
|
+
openRepoSource(settings, runtime, { refresh: "none" }),
|
|
78
|
+
localOverlay(settings, runtime),
|
|
74
79
|
].flatMap((source) => (source ? [source] : []));
|
|
75
80
|
const models = await Promise.all(sources.map((source) => source.model()));
|
|
76
81
|
return [
|
|
77
82
|
...new Map(models.flatMap((m) => m.invalidKnowledge).map((p) => [p.path, p])).values(),
|
|
78
83
|
];
|
|
79
84
|
}
|
|
80
|
-
|
|
85
|
+
/**
|
|
86
|
+
* Lists shared and retained local knowledge, optionally restricting to always-
|
|
87
|
+
* access documents, and marks session-start visibility.
|
|
88
|
+
*/
|
|
89
|
+
export async function knowledgeList(always = false, runtime) {
|
|
90
|
+
const { home } = runtime;
|
|
81
91
|
const settings = await readSettings(home);
|
|
82
|
-
const listing = settings?.
|
|
83
|
-
const shared = await sharedKnowledge(
|
|
84
|
-
const local = (await keptLocal(
|
|
92
|
+
const listing = settings?.knowledge !== false;
|
|
93
|
+
const shared = await sharedKnowledge(runtime, always);
|
|
94
|
+
const local = (await keptLocal(runtime, shared))
|
|
85
95
|
.filter((doc) => !always || doc.content.accessMode === "always")
|
|
86
96
|
.map((doc) => ({
|
|
87
97
|
id: doc.id,
|
|
@@ -97,20 +107,30 @@ export async function knowledgeList(home = homedir(), always = false) {
|
|
|
97
107
|
listedAtStart: listing && doc.accessMode === "always",
|
|
98
108
|
}));
|
|
99
109
|
}
|
|
100
|
-
|
|
110
|
+
/**
|
|
111
|
+
* Retrieves shared knowledge by name, falling back to a retained local document
|
|
112
|
+
* if the shared lookup fails.
|
|
113
|
+
*/
|
|
114
|
+
export async function knowledgeGet(name, runtime) {
|
|
101
115
|
try {
|
|
102
|
-
return await sharedDocument(name,
|
|
116
|
+
return await sharedDocument(name, runtime);
|
|
103
117
|
}
|
|
104
118
|
catch (error) {
|
|
105
|
-
const doc = (await keptLocal(
|
|
106
|
-
if (!doc)
|
|
119
|
+
const doc = (await keptLocal(runtime, [])).find((d) => d.content.name === name);
|
|
120
|
+
if (!doc) {
|
|
107
121
|
throw error;
|
|
122
|
+
}
|
|
108
123
|
return { id: doc.id, version: { id: doc.version, content: doc.content } };
|
|
109
124
|
}
|
|
110
125
|
}
|
|
126
|
+
/**
|
|
127
|
+
* Formats a newline-separated session-start index with single-line
|
|
128
|
+
* descriptions; no documents produce an empty string.
|
|
129
|
+
*/
|
|
111
130
|
export function knowledgeIndexText(documents) {
|
|
112
|
-
if (!documents.length)
|
|
131
|
+
if (!documents.length) {
|
|
113
132
|
return "";
|
|
133
|
+
}
|
|
114
134
|
return [
|
|
115
135
|
"Available organization knowledge (retrieve full content with barndog knowledge get <name>):",
|
|
116
136
|
...documents.map((d) => `- ${d.name}: ${d.description.replace(/[\r\n]+/g, " ")}`),
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { mcpListSchema } from "@barndog-ai/api-contract";
|
|
2
|
+
import { parsed } from "../server/client.js";
|
|
3
|
+
import { allPages, PAGE_SIZE } from "../server/pages.js";
|
|
4
|
+
import { apiClient } from "../auth/transport.js";
|
|
5
|
+
/**
|
|
6
|
+
* Fetches every MCP catalog page, rejecting organization mismatches and
|
|
7
|
+
* repeated pagination cursors.
|
|
8
|
+
*/
|
|
9
|
+
export async function mcpCatalog(conn, runtime) {
|
|
10
|
+
return allPages(async (cursor) => {
|
|
11
|
+
const page = await parsed(mcpListSchema, apiClient(conn.server, runtime).GET("/v1/mcps", {
|
|
12
|
+
params: { query: { limit: PAGE_SIZE, cursor } },
|
|
13
|
+
}));
|
|
14
|
+
const items = page.mcps.map((mcp) => {
|
|
15
|
+
if (mcp.organizationId !== conn.organizationId) {
|
|
16
|
+
throw new Error("The server sent a catalog page for another organization");
|
|
17
|
+
}
|
|
18
|
+
return {
|
|
19
|
+
id: mcp.id,
|
|
20
|
+
kind: "mcp",
|
|
21
|
+
name: mcp.name,
|
|
22
|
+
origin: mcp.origin,
|
|
23
|
+
version: {
|
|
24
|
+
number: mcp.version.number,
|
|
25
|
+
description: mcp.version.definition.description,
|
|
26
|
+
},
|
|
27
|
+
};
|
|
28
|
+
});
|
|
29
|
+
return { items, nextCursor: page.nextCursor };
|
|
30
|
+
});
|
|
31
|
+
}
|