vanara 0.1.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/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,34 @@
1
+ # vanara — the Vanara CLI (v0.1)
2
+
3
+ Install and manage AI agent **packs**, **agents**, and **skills** in any project.
4
+ Items install in Claude Code layout (`.claude/agents/`, `.claude/skills/`), so Claude Code
5
+ picks them up with zero extra configuration. Zero runtime dependencies, Node ≥ 20.
6
+
7
+ ```bash
8
+ vanara list --kind pack # browse the catalog
9
+ vanara info security-pack # what's inside
10
+ vanara install security-pack # pack expands to its agents + skills
11
+ vanara installed # what this project has (from .vanara.json)
12
+ vanara update --apply # pull newer catalog versions
13
+ vanara uninstall security-pack --members
14
+ ```
15
+
16
+ ## How it works
17
+
18
+ - **Catalog source** — a directory with `agents/ skills/ packs/` (the Forge layout: flat
19
+ `<name>.md` or packaged dirs with `AGENT.md` / `SKILL.md` / `PACK.md` plus
20
+ `references/ scripts/ examples/ templates/`). Resolution order: `--source` flag →
21
+ `VANARA_REGISTRY` env → the dev catalog in this repo (`../forge/catalog`).
22
+ - **Packs are bundles** — installing one resolves its members (validated first; missing
23
+ members abort with provenance, nothing half-installs) and records the pack as a named
24
+ group in the lockfile.
25
+ - **Lockfile** — `.vanara.json` at the project root records every installed item, its
26
+ version, and the exact file list, so `uninstall` and `update` are exact (uninstall also
27
+ prunes emptied directories).
28
+
29
+ ## v1 roadmap (OPEN-CORE-PLAN.md §3–§4)
30
+
31
+ Same commands, hosted backend: `VANARA_REGISTRY` becomes an https registry URL;
32
+ `vanara login` (OAuth device flow) + Ed25519-signed entitlements gate premium packs
33
+ server-side; signed manifests verify pack integrity; `vanara update` reads release
34
+ channels. The catalog-source abstraction in `src/config.js` is the seam where that lands.
package/bin/vanara.js ADDED
@@ -0,0 +1,165 @@
1
+ #!/usr/bin/env node
2
+ // vanara — install and manage AI agent packs, agents, and skills.
3
+ // v0.1: local catalog sources only. The hosted registry + login/entitlements
4
+ // arrive in v1 (OPEN-CORE-PLAN.md §3) behind the same commands.
5
+ import { parseArgs } from 'node:util';
6
+ import { resolveSource } from '../src/config.js';
7
+ import { loadCatalog, resolveInstallSet } from '../src/catalog.js';
8
+ import { applyInstall, applyUninstall, readLock, planUpdates } from '../src/installer.js';
9
+
10
+ const HELP = `vanara — agent packs, agents, and skills for your project.
11
+
12
+ Usage: vanara <command> [options]
13
+
14
+ Commands:
15
+ list [--kind agent|skill|pack] Browse the catalog.
16
+ info <name> Show one item (description, version, pack contents).
17
+ install <name...> Install items into ./.claude (packs expand to members).
18
+ uninstall <name> [--members] Remove an item; --members also removes a pack's members.
19
+ installed Show what is installed here (from ${'.vanara.json'}).
20
+ update [--apply] Show (or apply) available catalog updates.
21
+ help This message.
22
+
23
+ Options:
24
+ --source <dir> Catalog directory (default: $VANARA_REGISTRY or the dev catalog)
25
+ --dest <dir> Destination project root (default: current directory)
26
+
27
+ Examples:
28
+ vanara list --kind pack
29
+ vanara install sre-reliability-pack
30
+ vanara install code-reviewer sql-index-tuning
31
+ vanara update --apply`;
32
+
33
+ function fmtItem(i) {
34
+ const version = i.data.version ? ` v${i.data.version}` : '';
35
+ return ` [${i.kind}] ${i.name}${version} — ${String(i.data.description ?? '').slice(0, 100)}`;
36
+ }
37
+
38
+ async function main() {
39
+ const { values, positionals } = parseArgs({
40
+ args: process.argv.slice(2),
41
+ allowPositionals: true,
42
+ options: {
43
+ source: { type: 'string' },
44
+ dest: { type: 'string' },
45
+ kind: { type: 'string' },
46
+ members: { type: 'boolean', default: false },
47
+ apply: { type: 'boolean', default: false },
48
+ },
49
+ });
50
+ const [command, ...names] = positionals;
51
+ const dest = values.dest ?? process.cwd();
52
+
53
+ if (!command || command === 'help') {
54
+ console.log(HELP);
55
+ return;
56
+ }
57
+
58
+ if (command === 'installed') {
59
+ const lock = await readLock(dest);
60
+ const entries = Object.entries(lock.installed);
61
+ if (entries.length === 0) {
62
+ console.log('Nothing installed here yet. Try: vanara list');
63
+ return;
64
+ }
65
+ for (const [name, e] of entries) {
66
+ const members = e.kind === 'pack' ? ` (members: ${(e.members ?? []).join(', ')})` : '';
67
+ console.log(` [${e.kind}] ${name} v${e.version}${members}`);
68
+ }
69
+ return;
70
+ }
71
+
72
+ // Everything below needs the catalog.
73
+ const source = resolveSource(values.source);
74
+ const catalog = await loadCatalog(source);
75
+ if (catalog.items.length === 0) {
76
+ console.error(`No catalog items found at: ${source}\nSet --source or VANARA_REGISTRY to a catalog directory.`);
77
+ process.exitCode = 1;
78
+ return;
79
+ }
80
+
81
+ if (command === 'list') {
82
+ const items = catalog.items.filter((i) => !values.kind || i.kind === values.kind);
83
+ for (const kind of ['pack', 'agent', 'skill']) {
84
+ const group = items.filter((i) => i.kind === kind);
85
+ if (group.length === 0) continue;
86
+ console.log(`\n${kind.toUpperCase()}S (${group.length})`);
87
+ for (const i of group) console.log(fmtItem(i));
88
+ }
89
+ console.log(`\n${items.length} item(s) from ${source}`);
90
+ return;
91
+ }
92
+
93
+ if (command === 'info') {
94
+ const item = catalog.byName.get(names[0]);
95
+ if (!item) {
96
+ console.error(`Not found: "${names[0]}". Try: vanara list`);
97
+ process.exitCode = 1;
98
+ return;
99
+ }
100
+ console.log(fmtItem(item));
101
+ if (item.kind === 'pack') {
102
+ console.log(` agents: ${(item.data.agents ?? []).join(', ') || '(none)'}`);
103
+ console.log(` skills: ${(item.data.skills ?? []).join(', ') || '(none)'}`);
104
+ }
105
+ if (item.supportFiles.length) console.log(` support files: ${item.supportFiles.length}`);
106
+ console.log(` install: vanara install ${item.name}`);
107
+ return;
108
+ }
109
+
110
+ if (command === 'install') {
111
+ if (names.length === 0) {
112
+ console.error('install needs at least one name. Try: vanara list');
113
+ process.exitCode = 1;
114
+ return;
115
+ }
116
+ const resolved = resolveInstallSet(catalog, names);
117
+ if (resolved.missing.length) {
118
+ console.error(`Cannot install — missing from catalog:\n ${resolved.missing.join('\n ')}`);
119
+ process.exitCode = 1;
120
+ return;
121
+ }
122
+ const results = await applyInstall(resolved, dest, source);
123
+ for (const r of results) console.log(` installed [${r.kind}] ${r.name}${r.files ? ` (${r.files} files)` : ''}`);
124
+ console.log(`\n${results.length} item(s) installed into ${dest}. Claude Code picks them up automatically.`);
125
+ return;
126
+ }
127
+
128
+ if (command === 'uninstall') {
129
+ const res = await applyUninstall(names[0], dest, { removeMembers: values.members });
130
+ if (!res.removed) {
131
+ console.error(`"${names[0]}": ${res.reason}`);
132
+ process.exitCode = 1;
133
+ return;
134
+ }
135
+ console.log(`Removed ${res.targets.join(', ')} (${res.filesRemoved} files).`);
136
+ return;
137
+ }
138
+
139
+ if (command === 'update') {
140
+ const lock = await readLock(dest);
141
+ const updates = planUpdates(catalog, lock);
142
+ if (updates.length === 0) {
143
+ console.log('Everything is up to date.');
144
+ return;
145
+ }
146
+ for (const u of updates) console.log(` [${u.kind}] ${u.name}: v${u.from} -> v${u.to}`);
147
+ if (!values.apply) {
148
+ console.log(`\n${updates.length} update(s) available. Apply with: vanara update --apply`);
149
+ return;
150
+ }
151
+ const resolved = resolveInstallSet(catalog, updates.map((u) => u.name));
152
+ const results = await applyInstall(resolved, dest, source);
153
+ console.log(`\nApplied ${results.length} update(s).`);
154
+ return;
155
+ }
156
+
157
+ console.error(`Unknown command: ${command}\n`);
158
+ console.log(HELP);
159
+ process.exitCode = 1;
160
+ }
161
+
162
+ main().catch((err) => {
163
+ console.error(`vanara error: ${err.message}`);
164
+ process.exitCode = 1;
165
+ });
package/package.json ADDED
@@ -0,0 +1,38 @@
1
+ {
2
+ "name": "vanara",
3
+ "version": "0.1.0",
4
+ "description": "Vanara — deploy packs of skilled AI agents. Install agents, skills, and packs into any project from the Vanara catalog.",
5
+ "type": "module",
6
+ "bin": {
7
+ "vanara": "bin/vanara.js"
8
+ },
9
+ "scripts": {
10
+ "test": "node --test"
11
+ },
12
+ "engines": {
13
+ "node": ">=20"
14
+ },
15
+ "license": "Apache-2.0",
16
+ "keywords": [
17
+ "ai",
18
+ "agents",
19
+ "ai-agents",
20
+ "skills",
21
+ "claude",
22
+ "claude-code",
23
+ "agent-skills",
24
+ "cli",
25
+ "vanara"
26
+ ],
27
+ "homepage": "https://vanara.dev",
28
+ "author": "Vanara",
29
+ "files": [
30
+ "bin/",
31
+ "src/",
32
+ "README.md",
33
+ "LICENSE"
34
+ ],
35
+ "publishConfig": {
36
+ "access": "public"
37
+ }
38
+ }
package/src/catalog.js ADDED
@@ -0,0 +1,91 @@
1
+ // Catalog loading + install-set resolution. A catalog source is a directory with
2
+ // agents/ skills/ packs/ subdirs; items are flat markdown files or packaged
3
+ // directories whose main file is AGENT.md / SKILL.md / PACK.md (the Forge layout).
4
+ import { readdir, readFile } from 'node:fs/promises';
5
+ import path from 'node:path';
6
+ import * as fm from './frontmatter.js';
7
+
8
+ const KIND_DIRS = { agent: 'agents', skill: 'skills', pack: 'packs' };
9
+ const MAIN_FILE = { agent: 'AGENT.md', skill: 'SKILL.md', pack: 'PACK.md' };
10
+
11
+ async function listSupportFiles(dir, base = dir) {
12
+ const out = [];
13
+ for (const entry of await readdir(dir, { withFileTypes: true })) {
14
+ const full = path.join(dir, entry.name);
15
+ if (entry.isDirectory()) out.push(...(await listSupportFiles(full, base)));
16
+ else out.push(path.relative(base, full));
17
+ }
18
+ return out;
19
+ }
20
+
21
+ async function loadFlat(kind, filePath) {
22
+ const raw = await readFile(filePath, 'utf8');
23
+ const { data } = fm.parse(raw);
24
+ const name = data.name ?? path.basename(filePath, '.md');
25
+ return { kind, name, data, mainPath: filePath, dirPath: null, supportFiles: [] };
26
+ }
27
+
28
+ async function loadPackaged(kind, dirPath) {
29
+ const mainPath = path.join(dirPath, MAIN_FILE[kind]);
30
+ let raw;
31
+ try {
32
+ raw = await readFile(mainPath, 'utf8');
33
+ } catch (err) {
34
+ if (err.code === 'ENOENT') return null; // not an item dir; ignore
35
+ throw err;
36
+ }
37
+ const { data } = fm.parse(raw);
38
+ const name = data.name ?? path.basename(dirPath);
39
+ const supportFiles = (await listSupportFiles(dirPath)).filter((f) => f !== MAIN_FILE[kind]);
40
+ return { kind, name, data, mainPath, dirPath, supportFiles };
41
+ }
42
+
43
+ /** Load every item from a catalog source directory. */
44
+ export async function loadCatalog(sourceDir) {
45
+ const items = [];
46
+ for (const [kind, sub] of Object.entries(KIND_DIRS)) {
47
+ const dir = path.join(sourceDir, sub);
48
+ let entries = [];
49
+ try {
50
+ entries = await readdir(dir, { withFileTypes: true });
51
+ } catch (err) {
52
+ if (err.code !== 'ENOENT') throw err;
53
+ }
54
+ for (const entry of entries) {
55
+ if (entry.isFile() && entry.name.endsWith('.md')) {
56
+ items.push(await loadFlat(kind, path.join(dir, entry.name)));
57
+ } else if (entry.isDirectory()) {
58
+ const item = await loadPackaged(kind, path.join(dir, entry.name));
59
+ if (item) items.push(item);
60
+ }
61
+ }
62
+ }
63
+ return { sourceDir, items, byName: new Map(items.map((i) => [i.name, i])) };
64
+ }
65
+
66
+ /**
67
+ * Expand requested names into the concrete set of agents/skills to install.
68
+ * Packs expand to their members (the pack itself is recorded, not materialized).
69
+ * Returns { toInstall, packs, missing } — missing non-empty means the request
70
+ * cannot be satisfied and nothing should be written.
71
+ */
72
+ export function resolveInstallSet(catalog, names) {
73
+ const toInstall = new Map();
74
+ const packs = [];
75
+ const missing = [];
76
+
77
+ const addMember = (name, via) => {
78
+ const item = catalog.byName.get(name);
79
+ if (!item) missing.push(via ? `${name} (required by pack ${via})` : name);
80
+ else if (item.kind === 'pack') expandPack(item);
81
+ else toInstall.set(item.name, item);
82
+ };
83
+ const expandPack = (pack) => {
84
+ packs.push(pack);
85
+ for (const a of pack.data.agents ?? []) addMember(a, pack.name);
86
+ for (const s of pack.data.skills ?? []) addMember(s, pack.name);
87
+ };
88
+
89
+ for (const name of names) addMember(name);
90
+ return { toInstall: [...toInstall.values()], packs, missing };
91
+ }
package/src/config.js ADDED
@@ -0,0 +1,27 @@
1
+ // Central constants and source resolution. No hardcoded secrets, no network in v0.1.
2
+ import { fileURLToPath } from 'node:url';
3
+ import path from 'node:path';
4
+
5
+ const __dirname = path.dirname(fileURLToPath(import.meta.url));
6
+ export const CLI_ROOT = path.resolve(__dirname, '..');
7
+
8
+ // Name of the per-project lockfile that records what is installed where.
9
+ export const LOCKFILE = '.vanara.json';
10
+
11
+ // Catalog source resolution order:
12
+ // 1. --source <dir> flag
13
+ // 2. VANARA_REGISTRY env var (a directory today; an https registry URL in v1
14
+ // once the hosted registry + entitlements exist — see OPEN-CORE-PLAN.md §3)
15
+ // 3. dev default: the sibling forge catalog in this repo
16
+ export function resolveSource(flagValue) {
17
+ if (flagValue) return flagValue;
18
+ if (process.env.VANARA_REGISTRY) return process.env.VANARA_REGISTRY;
19
+ return path.resolve(CLI_ROOT, '..', 'forge', 'catalog');
20
+ }
21
+
22
+ // Where items land inside the destination project (the Claude Code layout —
23
+ // catalog items are authored in that format already).
24
+ export const CLAUDE_TARGET = {
25
+ agentsDir: path.join('.claude', 'agents'),
26
+ skillsDir: path.join('.claude', 'skills'),
27
+ };
@@ -0,0 +1,64 @@
1
+ // Minimal, dependency-free frontmatter parser/serializer for our markdown items.
2
+ // Supports: scalar `key: value`, inline arrays `key: [a, b]`, and block bodies.
3
+ // Intentionally small — our schema is simple and we control the inputs.
4
+
5
+ const FENCE = '---';
6
+
7
+ function parseScalar(raw) {
8
+ const v = raw.trim();
9
+ if (v === '') return '';
10
+ if (v === 'true') return true;
11
+ if (v === 'false') return false;
12
+ if (/^-?\d+(\.\d+)?$/.test(v)) return Number(v);
13
+ // strip surrounding quotes
14
+ if ((v.startsWith('"') && v.endsWith('"')) || (v.startsWith("'") && v.endsWith("'"))) {
15
+ return v.slice(1, -1);
16
+ }
17
+ if (v.startsWith('[') && v.endsWith(']')) {
18
+ const inner = v.slice(1, -1).trim();
19
+ if (inner === '') return [];
20
+ return inner.split(',').map((s) => parseScalar(s));
21
+ }
22
+ return v;
23
+ }
24
+
25
+ export function parse(text) {
26
+ if (!text.startsWith(FENCE)) {
27
+ return { data: {}, body: text };
28
+ }
29
+ const end = text.indexOf(`\n${FENCE}`, FENCE.length);
30
+ if (end === -1) return { data: {}, body: text };
31
+
32
+ const header = text.slice(FENCE.length, end).trim();
33
+ const body = text.slice(end + FENCE.length + 1).replace(/^\n/, '');
34
+
35
+ const data = {};
36
+ for (const line of header.split('\n')) {
37
+ if (!line.trim() || line.trim().startsWith('#')) continue;
38
+ const idx = line.indexOf(':');
39
+ if (idx === -1) continue;
40
+ const key = line.slice(0, idx).trim();
41
+ data[key] = parseScalar(line.slice(idx + 1));
42
+ }
43
+ return { data, body };
44
+ }
45
+
46
+ function serializeValue(value) {
47
+ if (Array.isArray(value)) {
48
+ return `[${value.join(', ')}]`;
49
+ }
50
+ if (typeof value === 'string' && /[:#]/.test(value)) {
51
+ return JSON.stringify(value);
52
+ }
53
+ return String(value);
54
+ }
55
+
56
+ export function stringify(data, body) {
57
+ const lines = [FENCE];
58
+ for (const [key, value] of Object.entries(data)) {
59
+ if (value === undefined || value === null) continue;
60
+ lines.push(`${key}: ${serializeValue(value)}`);
61
+ }
62
+ lines.push(FENCE, '');
63
+ return `${lines.join('\n')}\n${body.replace(/^\n+/, '')}`;
64
+ }
@@ -0,0 +1,143 @@
1
+ // Install planning + application, with a per-project lockfile so uninstall and
2
+ // update are exact. Copies are planned first, then applied — a failed resolve
3
+ // never leaves a half-written install.
4
+ import { mkdir, readFile, writeFile, copyFile, rm, rmdir, readdir } from 'node:fs/promises';
5
+ import path from 'node:path';
6
+ import { LOCKFILE, CLAUDE_TARGET } from './config.js';
7
+
8
+ /** Numeric-aware compare for "1.2.0"-style versions. Returns -1 | 0 | 1. */
9
+ export function compareVersions(a, b) {
10
+ const pa = String(a ?? '0').split('.').map((n) => parseInt(n, 10) || 0);
11
+ const pb = String(b ?? '0').split('.').map((n) => parseInt(n, 10) || 0);
12
+ for (let i = 0; i < Math.max(pa.length, pb.length); i++) {
13
+ const d = (pa[i] ?? 0) - (pb[i] ?? 0);
14
+ if (d !== 0) return Math.sign(d);
15
+ }
16
+ return 0;
17
+ }
18
+
19
+ /** Files an item will occupy inside destRoot (Claude Code layout). */
20
+ export function planItemFiles(item) {
21
+ const files = [];
22
+ if (item.kind === 'agent') {
23
+ files.push({ from: item.mainPath, to: path.join(CLAUDE_TARGET.agentsDir, `${item.name}.md`) });
24
+ for (const rel of item.supportFiles) {
25
+ files.push({ from: path.join(item.dirPath, rel), to: path.join(CLAUDE_TARGET.agentsDir, item.name, rel) });
26
+ }
27
+ } else if (item.kind === 'skill') {
28
+ files.push({ from: item.mainPath, to: path.join(CLAUDE_TARGET.skillsDir, item.name, 'SKILL.md') });
29
+ for (const rel of item.supportFiles) {
30
+ files.push({ from: path.join(item.dirPath, rel), to: path.join(CLAUDE_TARGET.skillsDir, item.name, rel) });
31
+ }
32
+ }
33
+ return files;
34
+ }
35
+
36
+ export async function readLock(destRoot) {
37
+ try {
38
+ return JSON.parse(await readFile(path.join(destRoot, LOCKFILE), 'utf8'));
39
+ } catch (err) {
40
+ if (err.code === 'ENOENT') return { installed: {} };
41
+ throw err;
42
+ }
43
+ }
44
+
45
+ async function writeLock(destRoot, lock) {
46
+ await writeFile(path.join(destRoot, LOCKFILE), `${JSON.stringify(lock, null, 2)}\n`, 'utf8');
47
+ }
48
+
49
+ /** Copy one item's files into destRoot and record it in the lock object. */
50
+ async function installItem(item, destRoot, lock, source) {
51
+ const files = planItemFiles(item);
52
+ for (const f of files) {
53
+ const target = path.join(destRoot, f.to);
54
+ await mkdir(path.dirname(target), { recursive: true });
55
+ await copyFile(f.from, target);
56
+ }
57
+ lock.installed[item.name] = {
58
+ kind: item.kind,
59
+ version: String(item.data.version ?? '0'),
60
+ files: files.map((f) => f.to),
61
+ source,
62
+ installedAt: new Date().toISOString(),
63
+ };
64
+ return files.length;
65
+ }
66
+
67
+ /**
68
+ * Install resolved items (+ record packs as named groups). Returns per-item
69
+ * results. All-or-nothing per item; the lock is written once at the end.
70
+ */
71
+ export async function applyInstall({ toInstall, packs }, destRoot, source) {
72
+ const lock = await readLock(destRoot);
73
+ const results = [];
74
+ for (const item of toInstall) {
75
+ const fileCount = await installItem(item, destRoot, lock, source);
76
+ results.push({ name: item.name, kind: item.kind, files: fileCount });
77
+ }
78
+ for (const pack of packs) {
79
+ lock.installed[pack.name] = {
80
+ kind: 'pack',
81
+ version: String(pack.data.version ?? '0'),
82
+ members: [...(pack.data.agents ?? []), ...(pack.data.skills ?? [])],
83
+ files: [],
84
+ source,
85
+ installedAt: new Date().toISOString(),
86
+ };
87
+ results.push({ name: pack.name, kind: 'pack', files: 0 });
88
+ }
89
+ await writeLock(destRoot, lock);
90
+ return results;
91
+ }
92
+
93
+ async function removeEmptyParents(destRoot, filePath) {
94
+ let dir = path.dirname(path.join(destRoot, filePath));
95
+ const stop = path.resolve(destRoot);
96
+ while (path.resolve(dir) !== stop) {
97
+ try {
98
+ if ((await readdir(dir)).length > 0) break;
99
+ await rmdir(dir);
100
+ } catch {
101
+ break;
102
+ }
103
+ dir = path.dirname(dir);
104
+ }
105
+ }
106
+
107
+ /** Remove an installed item (or pack group) using only the lock's file list. */
108
+ export async function applyUninstall(name, destRoot, { removeMembers = false } = {}) {
109
+ const lock = await readLock(destRoot);
110
+ const entry = lock.installed[name];
111
+ if (!entry) return { removed: false, reason: 'not installed' };
112
+
113
+ const targets = [name];
114
+ if (entry.kind === 'pack' && removeMembers) targets.push(...(entry.members ?? []));
115
+
116
+ let filesRemoved = 0;
117
+ for (const t of targets) {
118
+ const e = lock.installed[t];
119
+ if (!e) continue;
120
+ for (const rel of e.files) {
121
+ await rm(path.join(destRoot, rel), { force: true });
122
+ await removeEmptyParents(destRoot, rel);
123
+ filesRemoved += 1;
124
+ }
125
+ delete lock.installed[t];
126
+ }
127
+ await writeLock(destRoot, lock);
128
+ return { removed: true, targets, filesRemoved };
129
+ }
130
+
131
+ /** Items whose catalog version is newer than the installed one. */
132
+ export function planUpdates(catalog, lock) {
133
+ const updates = [];
134
+ for (const [name, entry] of Object.entries(lock.installed)) {
135
+ const item = catalog.byName.get(name);
136
+ if (!item) continue; // no longer in catalog; leave as-is
137
+ const catalogVersion = String(item.data.version ?? '0');
138
+ if (compareVersions(catalogVersion, entry.version) > 0) {
139
+ updates.push({ name, kind: entry.kind, from: entry.version, to: catalogVersion });
140
+ }
141
+ }
142
+ return updates;
143
+ }