agent-protocol-cli 1.0.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/package.json ADDED
@@ -0,0 +1,60 @@
1
+ {
2
+ "name": "agent-protocol-cli",
3
+ "version": "1.0.0",
4
+ "description": "Discover and install AI Skills via Agent Manifest Protocol — semantic search, one-command install, schema validation",
5
+ "type": "module",
6
+ "bin": {
7
+ "agent": "./bin/agent.js"
8
+ },
9
+ "files": [
10
+ "bin/",
11
+ "bin/commands/",
12
+ "data/",
13
+ "vectorizer.js",
14
+ "README.md",
15
+ "LICENSE"
16
+ ],
17
+ "scripts": {
18
+ "start": "node bin/agent.js",
19
+ "search": "node bin/agent.js search",
20
+ "test": "node --test test/"
21
+ },
22
+ "engines": {
23
+ "node": ">=18.0.0"
24
+ },
25
+ "keywords": [
26
+ "agent-manifest-protocol",
27
+ "amp",
28
+ "ai-skills",
29
+ "agent-skills",
30
+ "openclaw",
31
+ "gpt-actions",
32
+ "ai-capabilities",
33
+ "semantic-search",
34
+ "tf-idf"
35
+ ],
36
+ "repository": {
37
+ "type": "git",
38
+ "url": "https://github.com/Polaris899/agent-protocol.git"
39
+ },
40
+ "homepage": "https://polaris899.github.io/agent-protocol/",
41
+ "bugs": {
42
+ "url": "https://github.com/Polaris899/agent-protocol/issues"
43
+ },
44
+ "author": {
45
+ "name": "AMP Contributors",
46
+ "url": "https://github.com/Polaris899/agent-protocol"
47
+ },
48
+ "license": "MIT",
49
+ "dependencies": {
50
+ "ajv-formats": "^3.0.1",
51
+ "chalk": "^5.3.0",
52
+ "cli-progress": "^3.12.0",
53
+ "commander": "^12.0.0",
54
+ "conf": "^13.0.0",
55
+ "semver": "^7.6.0"
56
+ },
57
+ "publishConfig": {
58
+ "access": "public"
59
+ }
60
+ }
package/vectorizer.js ADDED
@@ -0,0 +1,78 @@
1
+ /**
2
+ * TF-IDF Vectorizer with CJK support
3
+ * Zero-dependency. Inlined for npm package.
4
+ */
5
+ const CJK_REGEX = /[\u4e00-\u9fff\u3400-\u4dbf\uf900-\ufaff]/;
6
+
7
+ export function* tokenize(text) {
8
+ const lowered = text.toLowerCase();
9
+ let current = '';
10
+ for (let i = 0; i < lowered.length; i++) {
11
+ const ch = lowered[i];
12
+ if (CJK_REGEX.test(ch)) {
13
+ if (current) { yield current; current = ''; }
14
+ yield ch;
15
+ } else if (/[a-z0-9]/.test(ch)) {
16
+ current += ch;
17
+ } else {
18
+ if (current) { yield current; current = ''; }
19
+ }
20
+ }
21
+ if (current) yield current;
22
+ }
23
+
24
+ export function cosineSimilarity(vecA, vecB) {
25
+ let dot = 0, normA = 0, normB = 0;
26
+ for (const key of Object.keys(vecA)) {
27
+ const va = vecA[key], vb = vecB[key] || 0;
28
+ dot += va * vb;
29
+ normA += va * va;
30
+ normB += vb * vb;
31
+ }
32
+ for (const key of Object.keys(vecB)) {
33
+ if (!(key in vecA)) normB += vecB[key] * vecB[key];
34
+ }
35
+ if (normA === 0 || normB === 0) return 0;
36
+ return dot / (Math.sqrt(normA) * Math.sqrt(normB));
37
+ }
38
+
39
+ export function buildCorpus(manifests) {
40
+ const N = manifests.length;
41
+ const docs = []; const tokenized = []; const df = {};
42
+
43
+ for (const m of manifests) {
44
+ const text = [m.name, m.description || '', m.id || '',
45
+ ...(m.tags || []),
46
+ ...(m.capabilities || []).flatMap(c => [c.name, c.description || '', ...(c.intents || [])])
47
+ ].join(' ').toLowerCase();
48
+ docs.push(text);
49
+ const tokens = [...tokenize(text)];
50
+ tokenized.push(tokens);
51
+ for (const t of new Set(tokens)) df[t] = (df[t] || 0) + 1;
52
+ }
53
+
54
+ const vectors = [];
55
+ for (let i = 0; i < N; i++) {
56
+ const tokens = tokenized[i];
57
+ const tf = {};
58
+ for (const t of tokens) tf[t] = (tf[t] || 0) + 1;
59
+ const maxFreq = Math.max(1, ...Object.values(tf));
60
+ const vec = {};
61
+ for (const t of Object.keys(tf)) vec[t] = (tf[t] / maxFreq) * Math.log((N + 1) / ((df[t] || 1) + 1) + 1);
62
+ vectors.push(vec);
63
+ }
64
+ return { docs, tokenized, vectors, df, N };
65
+ }
66
+
67
+ export function search(query, corpus, manifests, limit = 20) {
68
+ const qTokens = [...tokenize(query)];
69
+ if (qTokens.length === 0) return manifests.slice(0, limit);
70
+ const qTf = {};
71
+ qTokens.forEach(t => { qTf[t] = (qTf[t] || 0) + 1; });
72
+ const qMax = Math.max(1, ...Object.values(qTf));
73
+ const qVec = {};
74
+ qTokens.forEach(t => { qVec[t] = (qTf[t] / qMax) * Math.log((corpus.N + 1) / ((corpus.df[t] || 1) + 1) + 1); });
75
+ const scored = corpus.vectors.map((vec, i) => ({ score: cosineSimilarity(qVec, vec), manifest: manifests[i] }));
76
+ return scored.filter(s => s.score > 0.001).sort((a, b) => b.score - a.score).slice(0, limit)
77
+ .map(s => Object.assign({}, s.manifest, { score: s.score }));
78
+ }