skyloom 1.7.0 → 1.9.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/config/skills/api_integrator/SKILL.md +15 -0
- package/config/skills/arch_designer/SKILL.md +13 -0
- package/config/skills/ci_cd_manager/SKILL.md +14 -0
- package/config/skills/code_analysis/SKILL.md +13 -0
- package/config/skills/code_generator/SKILL.md +12 -0
- package/config/skills/code_reviewer/SKILL.md +13 -0
- package/config/skills/content_writer/SKILL.md +14 -0
- package/config/skills/data_transformer/SKILL.md +15 -0
- package/config/skills/document_analysis/SKILL.md +13 -0
- package/config/skills/emotional_companion/SKILL.md +15 -0
- package/config/skills/performance_checker/SKILL.md +14 -0
- package/config/skills/security_auditor/SKILL.md +14 -0
- package/config/skills/self_evolve/SKILL.md +13 -0
- package/config/skills/sys_operator/SKILL.md +15 -0
- package/config/skills/task_planner/SKILL.md +14 -0
- package/config/skills/web_research/SKILL.md +14 -0
- package/config/skills/workflow_designer/SKILL.md +13 -0
- package/dist/cli/main.js +15 -0
- package/dist/cli/main.js.map +1 -1
- package/dist/core/agent.d.ts.map +1 -1
- package/dist/core/agent.js +35 -0
- package/dist/core/agent.js.map +1 -1
- package/dist/core/evolve.d.ts +43 -0
- package/dist/core/evolve.d.ts.map +1 -0
- package/dist/core/evolve.js +201 -0
- package/dist/core/evolve.js.map +1 -0
- package/dist/core/graph.d.ts +49 -0
- package/dist/core/graph.d.ts.map +1 -0
- package/dist/core/graph.js +182 -0
- package/dist/core/graph.js.map +1 -0
- package/dist/core/sandbox.d.ts +24 -0
- package/dist/core/sandbox.d.ts.map +1 -0
- package/dist/core/sandbox.js +158 -0
- package/dist/core/sandbox.js.map +1 -0
- package/dist/core/vector.d.ts +43 -0
- package/dist/core/vector.d.ts.map +1 -0
- package/dist/core/vector.js +150 -0
- package/dist/core/vector.js.map +1 -0
- package/dist/tools/builtin.d.ts.map +1 -1
- package/dist/tools/builtin.js +3 -3
- package/dist/tools/builtin.js.map +1 -1
- package/package.json +1 -1
- package/src/cli/main.ts +16 -0
- package/src/core/agent.ts +30 -0
- package/src/core/evolve.ts +191 -0
- package/src/core/graph.ts +156 -0
- package/src/core/sandbox.ts +142 -0
- package/src/core/vector.ts +152 -0
- package/src/tools/builtin.ts +4 -6
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 向量语义搜索 — TF-IDF + Cosine similarity, zero dependencies.
|
|
3
|
+
*
|
|
4
|
+
* Replaces n-gram Jaccard as the default semantic scorer.
|
|
5
|
+
* - IDF pre-computed from document corpus
|
|
6
|
+
* - Cosine similarity on TF-IDF vectors
|
|
7
|
+
* - CJK-aware tokenization (bigram for CJK, whitespace for ASCII)
|
|
8
|
+
*
|
|
9
|
+
* Usage:
|
|
10
|
+
* const idx = new VectorIndex();
|
|
11
|
+
* idx.addDocuments(docs);
|
|
12
|
+
* const results = idx.search("deploy script", 5);
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
/* ═══════════════════════════════════════
|
|
16
|
+
Tokenizer — CJK-aware
|
|
17
|
+
═══════════════════════════════════════ */
|
|
18
|
+
const CJK = /[一-鿿-ゟ가-]/;
|
|
19
|
+
|
|
20
|
+
function tokenize(text: string): string[] {
|
|
21
|
+
const tokens: string[] = [];
|
|
22
|
+
let i = 0;
|
|
23
|
+
while (i < text.length) {
|
|
24
|
+
if (CJK.test(text[i])) {
|
|
25
|
+
if (i + 1 < text.length && CJK.test(text[i + 1])) {
|
|
26
|
+
tokens.push(text.slice(i, i + 2)); i += 2;
|
|
27
|
+
} else {
|
|
28
|
+
tokens.push(text[i]); i++;
|
|
29
|
+
}
|
|
30
|
+
} else if (/[A-Za-z0-9_]/.test(text[i])) {
|
|
31
|
+
let j = i;
|
|
32
|
+
while (j < text.length && /[A-Za-z0-9_]/.test(text[j])) j++;
|
|
33
|
+
tokens.push(text.slice(i, j).toLowerCase()); i = j;
|
|
34
|
+
} else {
|
|
35
|
+
i++;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return tokens;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/* ═══════════════════════════════════════
|
|
42
|
+
TF-IDF Vector computation
|
|
43
|
+
═══════════════════════════════════════ */
|
|
44
|
+
interface DocVector {
|
|
45
|
+
id: string;
|
|
46
|
+
tf: Map<string, number>;
|
|
47
|
+
norm: number;
|
|
48
|
+
content: string;
|
|
49
|
+
meta?: Record<string, any>;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export class VectorIndex {
|
|
53
|
+
private docs: DocVector[] = [];
|
|
54
|
+
private idf: Map<string, number> = new Map();
|
|
55
|
+
private totalDocs = 0;
|
|
56
|
+
|
|
57
|
+
/** Add a document to the index. */
|
|
58
|
+
addDocument(id: string, content: string, meta?: Record<string, any>): void {
|
|
59
|
+
const tokens = tokenize(content);
|
|
60
|
+
const tf = new Map<string, number>();
|
|
61
|
+
for (const t of tokens) { tf.set(t, (tf.get(t) || 0) + 1); }
|
|
62
|
+
|
|
63
|
+
// Normalize by doc length
|
|
64
|
+
const tfIdf = new Map<string, number>();
|
|
65
|
+
let normSq = 0;
|
|
66
|
+
for (const [term, freq] of tf) {
|
|
67
|
+
const tfVal = freq / tokens.length;
|
|
68
|
+
const idfVal = this.idf.get(term) || 0;
|
|
69
|
+
const val = tfVal * Math.max(0.1, idfVal);
|
|
70
|
+
tfIdf.set(term, val);
|
|
71
|
+
normSq += val * val;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
const norm = Math.sqrt(normSq);
|
|
75
|
+
this.docs.push({ id, tf: tfIdf, norm, content: content.slice(0, 500), meta });
|
|
76
|
+
this.totalDocs++;
|
|
77
|
+
|
|
78
|
+
// Update IDF
|
|
79
|
+
for (const term of tf.keys()) {
|
|
80
|
+
this.idf.set(term, Math.log((this.totalDocs + 1) / ((this.docFrequency(term) + 1))));
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
addDocuments(docs: Array<{ id: string; content: string; meta?: Record<string, any> }>): void {
|
|
85
|
+
for (const d of docs) this.addDocument(d.id, d.content, d.meta);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
private docFrequency(term: string): number {
|
|
89
|
+
let count = 0;
|
|
90
|
+
for (const d of this.docs) { if (d.tf.has(term)) count++; }
|
|
91
|
+
return count;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/** Search for documents similar to query. Returns [score, doc] pairs. */
|
|
95
|
+
search(query: string, topK: number = 5, minScore: number = 0.01): Array<[number, DocVector]> {
|
|
96
|
+
const queryTokens = tokenize(query);
|
|
97
|
+
const queryTf = new Map<string, number>();
|
|
98
|
+
for (const t of queryTokens) { queryTf.set(t, (queryTf.get(t) || 0) + 1); }
|
|
99
|
+
|
|
100
|
+
// Query vector
|
|
101
|
+
const qv = new Map<string, number>();
|
|
102
|
+
let qNormSq = 0;
|
|
103
|
+
for (const [term, freq] of queryTf) {
|
|
104
|
+
const tfVal = freq / queryTokens.length;
|
|
105
|
+
const idfVal = this.idf.get(term) || 0;
|
|
106
|
+
const val = tfVal * Math.max(0.1, idfVal);
|
|
107
|
+
qv.set(term, val);
|
|
108
|
+
qNormSq += val * val;
|
|
109
|
+
}
|
|
110
|
+
const qNorm = Math.sqrt(qNormSq);
|
|
111
|
+
if (qNorm === 0) return [];
|
|
112
|
+
|
|
113
|
+
// Cosine similarity against all docs
|
|
114
|
+
const scored: Array<[number, DocVector]> = [];
|
|
115
|
+
for (const doc of this.docs) {
|
|
116
|
+
if (doc.norm === 0) continue;
|
|
117
|
+
let dot = 0;
|
|
118
|
+
for (const [term, qVal] of qv) {
|
|
119
|
+
dot += qVal * (doc.tf.get(term) || 0);
|
|
120
|
+
}
|
|
121
|
+
const score = dot / (qNorm * doc.norm);
|
|
122
|
+
if (score >= minScore) scored.push([score, doc]);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
scored.sort((a, b) => b[0] - a[0]);
|
|
126
|
+
return scored.slice(0, topK);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/** Remove a document by ID. */
|
|
130
|
+
removeDocument(id: string): void {
|
|
131
|
+
this.docs = this.docs.filter(d => d.id !== id);
|
|
132
|
+
this.totalDocs = this.docs.length;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
get size(): number { return this.docs.length; }
|
|
136
|
+
|
|
137
|
+
clear(): void { this.docs = []; this.idf.clear(); this.totalDocs = 0; }
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/* ═══════════════════════════════════════
|
|
141
|
+
Singleton instance for memory recall
|
|
142
|
+
═══════════════════════════════════════ */
|
|
143
|
+
let globalIndex: VectorIndex | null = null;
|
|
144
|
+
|
|
145
|
+
export function getVectorIndex(): VectorIndex {
|
|
146
|
+
if (!globalIndex) globalIndex = new VectorIndex();
|
|
147
|
+
return globalIndex;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
export function resetVectorIndex(): void {
|
|
151
|
+
globalIndex = new VectorIndex();
|
|
152
|
+
}
|
package/src/tools/builtin.ts
CHANGED
|
@@ -152,15 +152,13 @@ export function registerBuiltinTools(registry: ToolRegistry): void {
|
|
|
152
152
|
{ name: 'timeout', type: 'number', description: 'Timeout in milliseconds (default: 30000)', required: false },
|
|
153
153
|
],
|
|
154
154
|
handler: async (params) => {
|
|
155
|
-
const { execSync } = require('child_process');
|
|
156
155
|
const cmd = params.command as string;
|
|
157
156
|
const timeout = (params.timeout as number) || 30000;
|
|
158
157
|
try {
|
|
159
|
-
const
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
}
|
|
158
|
+
const { runInSandbox, formatSandboxResult } = require('../core/sandbox');
|
|
159
|
+
const result = runInSandbox(cmd, { timeoutMs: timeout });
|
|
160
|
+
return formatSandboxResult(result);
|
|
161
|
+
} catch (e: any) { return `Error: ${e.message || e}`; }
|
|
164
162
|
},
|
|
165
163
|
dangerous: true,
|
|
166
164
|
});
|