@agent-root/core 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/lib/index.js +118 -0
- package/package.json +24 -0
package/lib/index.js
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
// @agent-root/core — shared constants and helpers for CLI and MCP server
|
|
2
|
+
|
|
3
|
+
const fs = require('fs');
|
|
4
|
+
const path = require('path');
|
|
5
|
+
const os = require('os');
|
|
6
|
+
const crypto = require('crypto');
|
|
7
|
+
|
|
8
|
+
// ─── Constants ─────────────────────────────────────────────────────────────
|
|
9
|
+
|
|
10
|
+
const API_BASE = 'https://agentroot.io';
|
|
11
|
+
const MANIFEST_FILE = '.agentroot-manifest.json';
|
|
12
|
+
|
|
13
|
+
// Tool directory mappings
|
|
14
|
+
const TOOL_DIRS = {
|
|
15
|
+
claude: { global: path.join(os.homedir(), '.claude', 'skills'), project: '.claude/skills' },
|
|
16
|
+
codex: { global: path.join(os.homedir(), '.codex', 'skills'), project: '.agents/skills' },
|
|
17
|
+
gemini: { global: path.join(os.homedir(), '.gemini', 'skills'), project: '.agents/skills' },
|
|
18
|
+
cursor: { global: null, project: '.cursor/skills' },
|
|
19
|
+
agents: { global: path.join(os.homedir(), '.agents', 'skills'), project: '.agents/skills' },
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
const TOOL_NAMES = Object.keys(TOOL_DIRS);
|
|
23
|
+
|
|
24
|
+
// Detection: which config dirs indicate a tool is installed
|
|
25
|
+
const TOOL_DETECT = {
|
|
26
|
+
claude: [path.join(os.homedir(), '.claude')],
|
|
27
|
+
codex: [path.join(os.homedir(), '.codex')],
|
|
28
|
+
gemini: [path.join(os.homedir(), '.gemini')],
|
|
29
|
+
cursor: ['.cursor', '.cursorrules'].map(d => path.resolve(d)),
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
// ─── Helpers ───────────────────────────────────────────────────────────────
|
|
33
|
+
|
|
34
|
+
function detectTools() {
|
|
35
|
+
const found = [];
|
|
36
|
+
for (const [tool, dirs] of Object.entries(TOOL_DETECT)) {
|
|
37
|
+
for (const dir of dirs) {
|
|
38
|
+
if (fs.existsSync(dir)) {
|
|
39
|
+
found.push(tool);
|
|
40
|
+
break;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return found;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function resolveToolDir(tool, isProject) {
|
|
48
|
+
const entry = TOOL_DIRS[tool];
|
|
49
|
+
if (!entry) {
|
|
50
|
+
throw new Error(`Unknown tool: ${tool}. Valid tools: ${TOOL_NAMES.join(', ')}`);
|
|
51
|
+
}
|
|
52
|
+
if (isProject) return entry.project;
|
|
53
|
+
if (!entry.global) {
|
|
54
|
+
throw new Error(`Tool "${tool}" does not support global install. Use --project instead.`);
|
|
55
|
+
}
|
|
56
|
+
return entry.global;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function hashContent(content) {
|
|
60
|
+
return crypto.createHash('sha256').update(content).digest('hex').slice(0, 12);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function scanInstalled() {
|
|
64
|
+
const results = [];
|
|
65
|
+
|
|
66
|
+
for (const [tool, dirs] of Object.entries(TOOL_DIRS)) {
|
|
67
|
+
const paths = [dirs.global, dirs.project].filter(Boolean);
|
|
68
|
+
for (const baseDir of paths) {
|
|
69
|
+
if (!fs.existsSync(baseDir)) continue;
|
|
70
|
+
|
|
71
|
+
let entries;
|
|
72
|
+
try {
|
|
73
|
+
entries = fs.readdirSync(baseDir, { withFileTypes: true });
|
|
74
|
+
} catch { continue; }
|
|
75
|
+
|
|
76
|
+
for (const entry of entries) {
|
|
77
|
+
if (!entry.isDirectory()) continue;
|
|
78
|
+
const manifestPath = path.join(baseDir, entry.name, MANIFEST_FILE);
|
|
79
|
+
if (!fs.existsSync(manifestPath)) continue;
|
|
80
|
+
|
|
81
|
+
try {
|
|
82
|
+
const manifest = JSON.parse(fs.readFileSync(manifestPath, 'utf-8'));
|
|
83
|
+
results.push({
|
|
84
|
+
skill_id: manifest.skill_id || entry.name,
|
|
85
|
+
domain: manifest.source_domain,
|
|
86
|
+
tool: manifest.tool || tool,
|
|
87
|
+
scope: baseDir === dirs.global ? 'global' : 'project',
|
|
88
|
+
installed_at: manifest.installed_at,
|
|
89
|
+
version_hash: manifest.version_hash,
|
|
90
|
+
path: path.join(baseDir, entry.name),
|
|
91
|
+
manifest,
|
|
92
|
+
});
|
|
93
|
+
} catch { continue; }
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
return results;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
function writeSkill(skillDir, content, manifest) {
|
|
102
|
+
fs.mkdirSync(skillDir, { recursive: true });
|
|
103
|
+
fs.writeFileSync(path.join(skillDir, 'SKILL.md'), content, 'utf-8');
|
|
104
|
+
fs.writeFileSync(path.join(skillDir, MANIFEST_FILE), JSON.stringify(manifest, null, 2), 'utf-8');
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
module.exports = {
|
|
108
|
+
API_BASE,
|
|
109
|
+
MANIFEST_FILE,
|
|
110
|
+
TOOL_DIRS,
|
|
111
|
+
TOOL_NAMES,
|
|
112
|
+
TOOL_DETECT,
|
|
113
|
+
detectTools,
|
|
114
|
+
resolveToolDir,
|
|
115
|
+
hashContent,
|
|
116
|
+
scanInstalled,
|
|
117
|
+
writeSkill,
|
|
118
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@agent-root/core",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Shared constants and helpers for AgentRoot CLI and MCP server.",
|
|
5
|
+
"main": "./lib/index.js",
|
|
6
|
+
"files": [
|
|
7
|
+
"lib/"
|
|
8
|
+
],
|
|
9
|
+
"keywords": [
|
|
10
|
+
"agentroot",
|
|
11
|
+
"ai",
|
|
12
|
+
"agent",
|
|
13
|
+
"skills"
|
|
14
|
+
],
|
|
15
|
+
"license": "MIT",
|
|
16
|
+
"repository": {
|
|
17
|
+
"type": "git",
|
|
18
|
+
"url": "https://github.com/d3-inc/agentroot",
|
|
19
|
+
"directory": "core"
|
|
20
|
+
},
|
|
21
|
+
"engines": {
|
|
22
|
+
"node": ">=16"
|
|
23
|
+
}
|
|
24
|
+
}
|