aggroot 1.5.1 → 1.5.3
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/.env.example +10 -93
- package/README.md +27 -1
- package/dist/cli.cjs +4 -0
- package/dist/index.cjs +2050 -1496
- package/dist/web-tree-sitter.wasm +0 -0
- package/package.json +161 -158
- package/scripts/build-all.mjs +42 -0
- package/scripts/generate-example-skills.ts +238 -238
- package/scripts/obfuscate.mjs +10 -2
- package/scripts/test-bash-parser.ts +37 -37
- package/scripts/test-parser2.ts +24 -24
- package/scripts/test-parser3.js +4 -4
- package/scripts/test-tokenizer.js +148 -148
- package/dist/native/better_sqlite3.node +0 -0
|
@@ -1,238 +1,238 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 生成示例 Skills 到桌面(带分类目录 + DESCRIPTION.md + 索引缓存)
|
|
3
|
-
*
|
|
4
|
-
* 运行: npx tsx scripts/generate-example-skills.ts
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
import * as fs from 'node:fs';
|
|
8
|
-
import * as path from 'node:path';
|
|
9
|
-
import * as os from 'node:os';
|
|
10
|
-
import { createSkillManageTool } from '../src/domain/skill/skill-manager-tool.js';
|
|
11
|
-
import { createSkillRegistry, loadSkillsWithCache, invalidateIndexCache } from '../src/domain/skill/skill-loader.js';
|
|
12
|
-
|
|
13
|
-
const outputDir = path.join(os.homedir(), 'Desktop', 'generated-skills');
|
|
14
|
-
fs.mkdirSync(outputDir, { recursive: true });
|
|
15
|
-
process.env.AGGROOT_HOME = outputDir;
|
|
16
|
-
|
|
17
|
-
const registry = createSkillRegistry();
|
|
18
|
-
const tool = createSkillManageTool(registry);
|
|
19
|
-
|
|
20
|
-
const skills: Array<{ name: string; category?: string; content: string }> = [
|
|
21
|
-
// ---- devops 分类 ----
|
|
22
|
-
{
|
|
23
|
-
name: 'deploy-to-staging',
|
|
24
|
-
category: 'devops',
|
|
25
|
-
content: `---
|
|
26
|
-
name: deploy-to-staging
|
|
27
|
-
description: Deploy the project to staging environment using docker
|
|
28
|
-
whenToUse: When you need to deploy the current project to the staging server
|
|
29
|
-
---
|
|
30
|
-
|
|
31
|
-
# Deploy to Staging
|
|
32
|
-
|
|
33
|
-
1. Run tests: \`npm test\`
|
|
34
|
-
2. Build Docker image: \`docker build -t myapp:staging .\`
|
|
35
|
-
3. Push to registry: \`docker push registry.example.com/myapp:staging\`
|
|
36
|
-
4. SSH to staging server: \`ssh deploy@staging.example.com\`
|
|
37
|
-
5. Pull and restart: \`docker-compose pull && docker-compose up -d\`
|
|
38
|
-
6. Verify: \`curl -f https://staging.example.com/health\`
|
|
39
|
-
|
|
40
|
-
## Pitfalls
|
|
41
|
-
- Always run tests before deploying
|
|
42
|
-
- Check that .env.staging has the correct DATABASE_URL
|
|
43
|
-
- If health check fails, rollback with \`docker-compose down && docker-compose up -d --no-pull\`
|
|
44
|
-
`,
|
|
45
|
-
},
|
|
46
|
-
{
|
|
47
|
-
name: 'rollback',
|
|
48
|
-
category: 'devops',
|
|
49
|
-
content: `---
|
|
50
|
-
name: rollback
|
|
51
|
-
description: Rollback a deployment to the previous version
|
|
52
|
-
whenToUse: When a deployment fails or causes issues in production
|
|
53
|
-
---
|
|
54
|
-
|
|
55
|
-
# Rollback Deployment
|
|
56
|
-
|
|
57
|
-
1. Check current version: \`docker-compose ps\`
|
|
58
|
-
2. Rollback to previous image: \`docker-compose down && docker-compose up -d --no-pull\`
|
|
59
|
-
3. Verify health: \`curl -f https://staging.example.com/health\`
|
|
60
|
-
4. Notify team in Slack
|
|
61
|
-
|
|
62
|
-
## Pitfalls
|
|
63
|
-
- Always verify the previous image is still available
|
|
64
|
-
- Don't rollback if database migration already ran
|
|
65
|
-
`,
|
|
66
|
-
},
|
|
67
|
-
// ---- debugging 分类 ----
|
|
68
|
-
{
|
|
69
|
-
name: 'debug-auth-401',
|
|
70
|
-
category: 'debugging',
|
|
71
|
-
content: `---
|
|
72
|
-
name: debug-auth-401
|
|
73
|
-
description: Debug and fix 401 authentication errors in test suites
|
|
74
|
-
whenToUse: When auth tests fail with 401 status code
|
|
75
|
-
---
|
|
76
|
-
|
|
77
|
-
# Debug Auth 401 Errors
|
|
78
|
-
|
|
79
|
-
1. Run the failing test with verbose output to identify which test and assertion failed
|
|
80
|
-
2. Read the auth middleware source code to understand the token validation logic
|
|
81
|
-
3. Check if the middleware correctly handles token formats (e.g., Bearer prefix stripping)
|
|
82
|
-
4. Fix the middleware to properly extract the token
|
|
83
|
-
5. Re-run tests to verify the fix
|
|
84
|
-
|
|
85
|
-
## Common Causes
|
|
86
|
-
- Middleware not stripping "Bearer " prefix from Authorization header
|
|
87
|
-
- Missing or incorrect token extraction logic
|
|
88
|
-
- Token not being passed in test fixtures
|
|
89
|
-
`,
|
|
90
|
-
},
|
|
91
|
-
{
|
|
92
|
-
name: 'debug-memory-leak',
|
|
93
|
-
category: 'debugging',
|
|
94
|
-
content: `---
|
|
95
|
-
name: debug-memory-leak
|
|
96
|
-
description: Investigate and fix memory leaks in Node.js applications
|
|
97
|
-
whenToUse: When the application shows increasing memory usage over time
|
|
98
|
-
---
|
|
99
|
-
|
|
100
|
-
# Debug Memory Leak
|
|
101
|
-
|
|
102
|
-
1. Take heap snapshot: \`node --inspect app.js\` then Chrome DevTools → Memory → Take Snapshot
|
|
103
|
-
2. Compare snapshots over time to find growing objects
|
|
104
|
-
3. Check for common patterns: event listeners not removed, closures holding references, global caches
|
|
105
|
-
4. Fix the leak and verify with load testing
|
|
106
|
-
|
|
107
|
-
## Common Causes
|
|
108
|
-
- Event listeners not removed on cleanup
|
|
109
|
-
- Closures capturing large objects
|
|
110
|
-
- Unbounded caches without TTL
|
|
111
|
-
`,
|
|
112
|
-
},
|
|
113
|
-
// ---- git 分类 ----
|
|
114
|
-
{
|
|
115
|
-
name: 'smart-commit',
|
|
116
|
-
category: 'git',
|
|
117
|
-
content: `---
|
|
118
|
-
name: smart-commit
|
|
119
|
-
description: Create a well-structured git commit with proper message
|
|
120
|
-
whenToUse: When you need to commit changes to git
|
|
121
|
-
---
|
|
122
|
-
|
|
123
|
-
# Smart Commit
|
|
124
|
-
|
|
125
|
-
1. Run \`git status\` to see all changes
|
|
126
|
-
2. Run \`git diff\` to understand what changed
|
|
127
|
-
3. Stage appropriate files with \`git add\`
|
|
128
|
-
4. Create commit with conventional commit format:
|
|
129
|
-
- feat: new feature
|
|
130
|
-
- fix: bug fix
|
|
131
|
-
- refactor: code refactoring
|
|
132
|
-
|
|
133
|
-
## Pitfalls
|
|
134
|
-
- Always review the diff before committing
|
|
135
|
-
- Never commit .env files or secrets
|
|
136
|
-
`,
|
|
137
|
-
},
|
|
138
|
-
// ---- 根级 skill(无分类)----
|
|
139
|
-
{
|
|
140
|
-
name: 'explain',
|
|
141
|
-
content: `---
|
|
142
|
-
name: explain
|
|
143
|
-
description: Explain code or concept in detail
|
|
144
|
-
whenToUse: When you need to understand how something works
|
|
145
|
-
---
|
|
146
|
-
|
|
147
|
-
# Explain
|
|
148
|
-
|
|
149
|
-
1. Read the relevant source files
|
|
150
|
-
2. Trace the execution flow
|
|
151
|
-
3. Summarize the key concepts
|
|
152
|
-
4. Provide examples if helpful
|
|
153
|
-
|
|
154
|
-
Provide explanation at the requested detail level.
|
|
155
|
-
`,
|
|
156
|
-
},
|
|
157
|
-
];
|
|
158
|
-
|
|
159
|
-
console.log('Generating skills with category structure...\n');
|
|
160
|
-
|
|
161
|
-
for (const skill of skills) {
|
|
162
|
-
const result = await tool.execute({
|
|
163
|
-
action: 'create',
|
|
164
|
-
name: skill.name,
|
|
165
|
-
content: skill.content,
|
|
166
|
-
category: skill.category,
|
|
167
|
-
});
|
|
168
|
-
|
|
169
|
-
if (result.success) {
|
|
170
|
-
console.log(` ✓ ${skill.name}${skill.category ? ` (category: ${skill.category})` : ''}`);
|
|
171
|
-
} else {
|
|
172
|
-
console.log(` ✗ ${skill.name}: ${result.stderr}`);
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
// 手动写 DESCRIPTION.md 文件到分类目录
|
|
177
|
-
const skillsDir = path.join(outputDir, 'skills');
|
|
178
|
-
const descriptions: Record<string, string> = {
|
|
179
|
-
devops: 'DevOps tools — deployment, rollback, and infrastructure management',
|
|
180
|
-
debugging: 'Debugging workflows — systematic approaches to finding and fixing bugs',
|
|
181
|
-
git: 'Git workflows — commit, branch, and version control best practices',
|
|
182
|
-
};
|
|
183
|
-
|
|
184
|
-
for (const [cat, desc] of Object.entries(descriptions)) {
|
|
185
|
-
const descPath = path.join(skillsDir, cat, 'DESCRIPTION.md');
|
|
186
|
-
if (fs.existsSync(path.join(skillsDir, cat))) {
|
|
187
|
-
fs.writeFileSync(descPath, `---\ndescription: ${desc}\n---\n`, 'utf-8');
|
|
188
|
-
console.log(` ✓ ${cat}/DESCRIPTION.md`);
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
// 删除旧缓存并重新加载以生成 .index.json
|
|
193
|
-
await invalidateIndexCache(skillsDir);
|
|
194
|
-
|
|
195
|
-
console.log('\nLoading skills with cache...');
|
|
196
|
-
const { skills: loadedSkills, categories } = await loadSkillsWithCache(skillsDir, 'user');
|
|
197
|
-
|
|
198
|
-
console.log(`\nLoaded ${loadedSkills.length} skills, ${categories.size} categories:`);
|
|
199
|
-
for (const [cat, desc] of categories) {
|
|
200
|
-
console.log(` ${cat}: ${desc}`);
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
// 验证 .index.json
|
|
204
|
-
const indexPath = path.join(skillsDir, '.index.json');
|
|
205
|
-
if (fs.existsSync(indexPath)) {
|
|
206
|
-
const cache = JSON.parse(fs.readFileSync(indexPath, 'utf-8'));
|
|
207
|
-
console.log(`\n.index.json created:`);
|
|
208
|
-
console.log(` version: ${cache.version}`);
|
|
209
|
-
console.log(` skills: ${cache.skills.length}`);
|
|
210
|
-
console.log(` categories: ${Object.keys(cache.categories).join(', ')}`);
|
|
211
|
-
console.log(` manifest entries: ${Object.keys(cache.manifest).length}`);
|
|
212
|
-
for (const entry of cache.skills) {
|
|
213
|
-
console.log(` - ${entry.name} (category: ${entry.category || 'none'}, path: ${entry.filePath})`);
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
// 列出生成的文件结构
|
|
218
|
-
function listFiles(dir: string, prefix = ''): void {
|
|
219
|
-
for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
|
|
220
|
-
if (entry.name.startsWith('.') && entry.isFile()) {
|
|
221
|
-
// Show dot files (like .index.json) but with indicator
|
|
222
|
-
console.log(`${prefix}${entry.name} (cache)`);
|
|
223
|
-
continue;
|
|
224
|
-
}
|
|
225
|
-
if (entry.name.startsWith('.')) continue;
|
|
226
|
-
if (entry.isDirectory()) {
|
|
227
|
-
console.log(`${prefix}${entry.name}/`);
|
|
228
|
-
listFiles(path.join(dir, entry.name), `${prefix} `);
|
|
229
|
-
} else {
|
|
230
|
-
console.log(`${prefix}${entry.name}`);
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
console.log('\nGenerated file structure:');
|
|
236
|
-
listFiles(skillsDir);
|
|
237
|
-
|
|
238
|
-
console.log(`\nOutput directory: ${outputDir}`);
|
|
1
|
+
/**
|
|
2
|
+
* 生成示例 Skills 到桌面(带分类目录 + DESCRIPTION.md + 索引缓存)
|
|
3
|
+
*
|
|
4
|
+
* 运行: npx tsx scripts/generate-example-skills.ts
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import * as fs from 'node:fs';
|
|
8
|
+
import * as path from 'node:path';
|
|
9
|
+
import * as os from 'node:os';
|
|
10
|
+
import { createSkillManageTool } from '../src/domain/skill/skill-manager-tool.js';
|
|
11
|
+
import { createSkillRegistry, loadSkillsWithCache, invalidateIndexCache } from '../src/domain/skill/skill-loader.js';
|
|
12
|
+
|
|
13
|
+
const outputDir = path.join(os.homedir(), 'Desktop', 'generated-skills');
|
|
14
|
+
fs.mkdirSync(outputDir, { recursive: true });
|
|
15
|
+
process.env.AGGROOT_HOME = outputDir;
|
|
16
|
+
|
|
17
|
+
const registry = createSkillRegistry();
|
|
18
|
+
const tool = createSkillManageTool(registry);
|
|
19
|
+
|
|
20
|
+
const skills: Array<{ name: string; category?: string; content: string }> = [
|
|
21
|
+
// ---- devops 分类 ----
|
|
22
|
+
{
|
|
23
|
+
name: 'deploy-to-staging',
|
|
24
|
+
category: 'devops',
|
|
25
|
+
content: `---
|
|
26
|
+
name: deploy-to-staging
|
|
27
|
+
description: Deploy the project to staging environment using docker
|
|
28
|
+
whenToUse: When you need to deploy the current project to the staging server
|
|
29
|
+
---
|
|
30
|
+
|
|
31
|
+
# Deploy to Staging
|
|
32
|
+
|
|
33
|
+
1. Run tests: \`npm test\`
|
|
34
|
+
2. Build Docker image: \`docker build -t myapp:staging .\`
|
|
35
|
+
3. Push to registry: \`docker push registry.example.com/myapp:staging\`
|
|
36
|
+
4. SSH to staging server: \`ssh deploy@staging.example.com\`
|
|
37
|
+
5. Pull and restart: \`docker-compose pull && docker-compose up -d\`
|
|
38
|
+
6. Verify: \`curl -f https://staging.example.com/health\`
|
|
39
|
+
|
|
40
|
+
## Pitfalls
|
|
41
|
+
- Always run tests before deploying
|
|
42
|
+
- Check that .env.staging has the correct DATABASE_URL
|
|
43
|
+
- If health check fails, rollback with \`docker-compose down && docker-compose up -d --no-pull\`
|
|
44
|
+
`,
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
name: 'rollback',
|
|
48
|
+
category: 'devops',
|
|
49
|
+
content: `---
|
|
50
|
+
name: rollback
|
|
51
|
+
description: Rollback a deployment to the previous version
|
|
52
|
+
whenToUse: When a deployment fails or causes issues in production
|
|
53
|
+
---
|
|
54
|
+
|
|
55
|
+
# Rollback Deployment
|
|
56
|
+
|
|
57
|
+
1. Check current version: \`docker-compose ps\`
|
|
58
|
+
2. Rollback to previous image: \`docker-compose down && docker-compose up -d --no-pull\`
|
|
59
|
+
3. Verify health: \`curl -f https://staging.example.com/health\`
|
|
60
|
+
4. Notify team in Slack
|
|
61
|
+
|
|
62
|
+
## Pitfalls
|
|
63
|
+
- Always verify the previous image is still available
|
|
64
|
+
- Don't rollback if database migration already ran
|
|
65
|
+
`,
|
|
66
|
+
},
|
|
67
|
+
// ---- debugging 分类 ----
|
|
68
|
+
{
|
|
69
|
+
name: 'debug-auth-401',
|
|
70
|
+
category: 'debugging',
|
|
71
|
+
content: `---
|
|
72
|
+
name: debug-auth-401
|
|
73
|
+
description: Debug and fix 401 authentication errors in test suites
|
|
74
|
+
whenToUse: When auth tests fail with 401 status code
|
|
75
|
+
---
|
|
76
|
+
|
|
77
|
+
# Debug Auth 401 Errors
|
|
78
|
+
|
|
79
|
+
1. Run the failing test with verbose output to identify which test and assertion failed
|
|
80
|
+
2. Read the auth middleware source code to understand the token validation logic
|
|
81
|
+
3. Check if the middleware correctly handles token formats (e.g., Bearer prefix stripping)
|
|
82
|
+
4. Fix the middleware to properly extract the token
|
|
83
|
+
5. Re-run tests to verify the fix
|
|
84
|
+
|
|
85
|
+
## Common Causes
|
|
86
|
+
- Middleware not stripping "Bearer " prefix from Authorization header
|
|
87
|
+
- Missing or incorrect token extraction logic
|
|
88
|
+
- Token not being passed in test fixtures
|
|
89
|
+
`,
|
|
90
|
+
},
|
|
91
|
+
{
|
|
92
|
+
name: 'debug-memory-leak',
|
|
93
|
+
category: 'debugging',
|
|
94
|
+
content: `---
|
|
95
|
+
name: debug-memory-leak
|
|
96
|
+
description: Investigate and fix memory leaks in Node.js applications
|
|
97
|
+
whenToUse: When the application shows increasing memory usage over time
|
|
98
|
+
---
|
|
99
|
+
|
|
100
|
+
# Debug Memory Leak
|
|
101
|
+
|
|
102
|
+
1. Take heap snapshot: \`node --inspect app.js\` then Chrome DevTools → Memory → Take Snapshot
|
|
103
|
+
2. Compare snapshots over time to find growing objects
|
|
104
|
+
3. Check for common patterns: event listeners not removed, closures holding references, global caches
|
|
105
|
+
4. Fix the leak and verify with load testing
|
|
106
|
+
|
|
107
|
+
## Common Causes
|
|
108
|
+
- Event listeners not removed on cleanup
|
|
109
|
+
- Closures capturing large objects
|
|
110
|
+
- Unbounded caches without TTL
|
|
111
|
+
`,
|
|
112
|
+
},
|
|
113
|
+
// ---- git 分类 ----
|
|
114
|
+
{
|
|
115
|
+
name: 'smart-commit',
|
|
116
|
+
category: 'git',
|
|
117
|
+
content: `---
|
|
118
|
+
name: smart-commit
|
|
119
|
+
description: Create a well-structured git commit with proper message
|
|
120
|
+
whenToUse: When you need to commit changes to git
|
|
121
|
+
---
|
|
122
|
+
|
|
123
|
+
# Smart Commit
|
|
124
|
+
|
|
125
|
+
1. Run \`git status\` to see all changes
|
|
126
|
+
2. Run \`git diff\` to understand what changed
|
|
127
|
+
3. Stage appropriate files with \`git add\`
|
|
128
|
+
4. Create commit with conventional commit format:
|
|
129
|
+
- feat: new feature
|
|
130
|
+
- fix: bug fix
|
|
131
|
+
- refactor: code refactoring
|
|
132
|
+
|
|
133
|
+
## Pitfalls
|
|
134
|
+
- Always review the diff before committing
|
|
135
|
+
- Never commit .env files or secrets
|
|
136
|
+
`,
|
|
137
|
+
},
|
|
138
|
+
// ---- 根级 skill(无分类)----
|
|
139
|
+
{
|
|
140
|
+
name: 'explain',
|
|
141
|
+
content: `---
|
|
142
|
+
name: explain
|
|
143
|
+
description: Explain code or concept in detail
|
|
144
|
+
whenToUse: When you need to understand how something works
|
|
145
|
+
---
|
|
146
|
+
|
|
147
|
+
# Explain
|
|
148
|
+
|
|
149
|
+
1. Read the relevant source files
|
|
150
|
+
2. Trace the execution flow
|
|
151
|
+
3. Summarize the key concepts
|
|
152
|
+
4. Provide examples if helpful
|
|
153
|
+
|
|
154
|
+
Provide explanation at the requested detail level.
|
|
155
|
+
`,
|
|
156
|
+
},
|
|
157
|
+
];
|
|
158
|
+
|
|
159
|
+
console.log('Generating skills with category structure...\n');
|
|
160
|
+
|
|
161
|
+
for (const skill of skills) {
|
|
162
|
+
const result = await tool.execute({
|
|
163
|
+
action: 'create',
|
|
164
|
+
name: skill.name,
|
|
165
|
+
content: skill.content,
|
|
166
|
+
category: skill.category,
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
if (result.success) {
|
|
170
|
+
console.log(` ✓ ${skill.name}${skill.category ? ` (category: ${skill.category})` : ''}`);
|
|
171
|
+
} else {
|
|
172
|
+
console.log(` ✗ ${skill.name}: ${result.stderr}`);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
// 手动写 DESCRIPTION.md 文件到分类目录
|
|
177
|
+
const skillsDir = path.join(outputDir, 'skills');
|
|
178
|
+
const descriptions: Record<string, string> = {
|
|
179
|
+
devops: 'DevOps tools — deployment, rollback, and infrastructure management',
|
|
180
|
+
debugging: 'Debugging workflows — systematic approaches to finding and fixing bugs',
|
|
181
|
+
git: 'Git workflows — commit, branch, and version control best practices',
|
|
182
|
+
};
|
|
183
|
+
|
|
184
|
+
for (const [cat, desc] of Object.entries(descriptions)) {
|
|
185
|
+
const descPath = path.join(skillsDir, cat, 'DESCRIPTION.md');
|
|
186
|
+
if (fs.existsSync(path.join(skillsDir, cat))) {
|
|
187
|
+
fs.writeFileSync(descPath, `---\ndescription: ${desc}\n---\n`, 'utf-8');
|
|
188
|
+
console.log(` ✓ ${cat}/DESCRIPTION.md`);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
// 删除旧缓存并重新加载以生成 .index.json
|
|
193
|
+
await invalidateIndexCache(skillsDir);
|
|
194
|
+
|
|
195
|
+
console.log('\nLoading skills with cache...');
|
|
196
|
+
const { skills: loadedSkills, categories } = await loadSkillsWithCache(skillsDir, 'user');
|
|
197
|
+
|
|
198
|
+
console.log(`\nLoaded ${loadedSkills.length} skills, ${categories.size} categories:`);
|
|
199
|
+
for (const [cat, desc] of categories) {
|
|
200
|
+
console.log(` ${cat}: ${desc}`);
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
// 验证 .index.json
|
|
204
|
+
const indexPath = path.join(skillsDir, '.index.json');
|
|
205
|
+
if (fs.existsSync(indexPath)) {
|
|
206
|
+
const cache = JSON.parse(fs.readFileSync(indexPath, 'utf-8'));
|
|
207
|
+
console.log(`\n.index.json created:`);
|
|
208
|
+
console.log(` version: ${cache.version}`);
|
|
209
|
+
console.log(` skills: ${cache.skills.length}`);
|
|
210
|
+
console.log(` categories: ${Object.keys(cache.categories).join(', ')}`);
|
|
211
|
+
console.log(` manifest entries: ${Object.keys(cache.manifest).length}`);
|
|
212
|
+
for (const entry of cache.skills) {
|
|
213
|
+
console.log(` - ${entry.name} (category: ${entry.category || 'none'}, path: ${entry.filePath})`);
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
// 列出生成的文件结构
|
|
218
|
+
function listFiles(dir: string, prefix = ''): void {
|
|
219
|
+
for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
|
|
220
|
+
if (entry.name.startsWith('.') && entry.isFile()) {
|
|
221
|
+
// Show dot files (like .index.json) but with indicator
|
|
222
|
+
console.log(`${prefix}${entry.name} (cache)`);
|
|
223
|
+
continue;
|
|
224
|
+
}
|
|
225
|
+
if (entry.name.startsWith('.')) continue;
|
|
226
|
+
if (entry.isDirectory()) {
|
|
227
|
+
console.log(`${prefix}${entry.name}/`);
|
|
228
|
+
listFiles(path.join(dir, entry.name), `${prefix} `);
|
|
229
|
+
} else {
|
|
230
|
+
console.log(`${prefix}${entry.name}`);
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
console.log('\nGenerated file structure:');
|
|
236
|
+
listFiles(skillsDir);
|
|
237
|
+
|
|
238
|
+
console.log(`\nOutput directory: ${outputDir}`);
|
package/scripts/obfuscate.mjs
CHANGED
|
@@ -110,8 +110,12 @@ for (const { src, dest } of NATIVE_MODULES) {
|
|
|
110
110
|
const srcPath = join(process.cwd(), 'node_modules', src);
|
|
111
111
|
const destPath = join(NATIVE_DIR, dest);
|
|
112
112
|
if (existsSync(srcPath)) {
|
|
113
|
-
|
|
114
|
-
|
|
113
|
+
try {
|
|
114
|
+
copyFileSync(srcPath, destPath);
|
|
115
|
+
console.log(`[bundle] Copied native: ${dest}`);
|
|
116
|
+
} catch (err) {
|
|
117
|
+
console.warn(`[bundle] Failed to copy native module ${dest}: ${err.code} — using existing file if present`);
|
|
118
|
+
}
|
|
115
119
|
} else {
|
|
116
120
|
console.warn(`[bundle] Native module not found: ${src} — users will need build tools`);
|
|
117
121
|
}
|
|
@@ -176,6 +180,10 @@ if (heapLimitMB < 3500 && !process.env.AGGROOT_SPAWNED) {
|
|
|
176
180
|
stdio: 'inherit',
|
|
177
181
|
env: { ...process.env, AGGROOT_SPAWNED: '1' },
|
|
178
182
|
});
|
|
183
|
+
child.on('error', (err) => {
|
|
184
|
+
console.error('Failed to re-spawn with larger heap:', err.message);
|
|
185
|
+
process.exit(1);
|
|
186
|
+
});
|
|
179
187
|
child.on('exit', (code) => process.exit(code ?? 0));
|
|
180
188
|
} else {
|
|
181
189
|
require('./index.cjs');
|
|
@@ -1,37 +1,37 @@
|
|
|
1
|
-
import { parseSource } from '../src/shared/utils/bash-parser.ts';
|
|
2
|
-
import { isSafeShellCommand } from '../src/domain/agent/services/approval.ts';
|
|
3
|
-
import { getToolRiskLevel, ToolRiskLevel } from '../src/domain/agent/services/approval.ts';
|
|
4
|
-
|
|
5
|
-
const commands = [
|
|
6
|
-
'cd /c/Users/zhuoz/Desktop/gui && ls -la build* 2>/dev/null || echo "No build directory found"',
|
|
7
|
-
'cd C:/Users/zhuoz/Desktop/gui && find build -name "libAutoJdv*" -o -name "AutoJdv.dll" 2>/dev/null | head -5',
|
|
8
|
-
'ls -la',
|
|
9
|
-
'echo hello',
|
|
10
|
-
];
|
|
11
|
-
|
|
12
|
-
for (const cmd of commands) {
|
|
13
|
-
console.log(`\n=== Testing: ${cmd.slice(0, 80)}... ===`);
|
|
14
|
-
|
|
15
|
-
const t0 = Date.now();
|
|
16
|
-
let astResult;
|
|
17
|
-
try {
|
|
18
|
-
astResult = parseSource(cmd);
|
|
19
|
-
} catch (e) {
|
|
20
|
-
console.log('parseSource THREW:', e);
|
|
21
|
-
continue;
|
|
22
|
-
}
|
|
23
|
-
const parseTime = Date.now() - t0;
|
|
24
|
-
console.log(`parseSource: type=${astResult?.type} children=${astResult?.children?.length} time=${parseTime}ms`);
|
|
25
|
-
|
|
26
|
-
const t1 = Date.now();
|
|
27
|
-
const safe = isSafeShellCommand(cmd);
|
|
28
|
-
const safeTime = Date.now() - t1;
|
|
29
|
-
console.log(`isSafeShellCommand: ${safe} time=${safeTime}ms`);
|
|
30
|
-
|
|
31
|
-
const t2 = Date.now();
|
|
32
|
-
const risk = getToolRiskLevel('Shell', { command: cmd });
|
|
33
|
-
const riskTime = Date.now() - t2;
|
|
34
|
-
console.log(`getToolRiskLevel: ${risk} time=${riskTime}ms`);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
console.log('\nAll tests completed.');
|
|
1
|
+
import { parseSource } from '../src/shared/utils/bash-parser.ts';
|
|
2
|
+
import { isSafeShellCommand } from '../src/domain/agent/services/approval.ts';
|
|
3
|
+
import { getToolRiskLevel, ToolRiskLevel } from '../src/domain/agent/services/approval.ts';
|
|
4
|
+
|
|
5
|
+
const commands = [
|
|
6
|
+
'cd /c/Users/zhuoz/Desktop/gui && ls -la build* 2>/dev/null || echo "No build directory found"',
|
|
7
|
+
'cd C:/Users/zhuoz/Desktop/gui && find build -name "libAutoJdv*" -o -name "AutoJdv.dll" 2>/dev/null | head -5',
|
|
8
|
+
'ls -la',
|
|
9
|
+
'echo hello',
|
|
10
|
+
];
|
|
11
|
+
|
|
12
|
+
for (const cmd of commands) {
|
|
13
|
+
console.log(`\n=== Testing: ${cmd.slice(0, 80)}... ===`);
|
|
14
|
+
|
|
15
|
+
const t0 = Date.now();
|
|
16
|
+
let astResult;
|
|
17
|
+
try {
|
|
18
|
+
astResult = parseSource(cmd);
|
|
19
|
+
} catch (e) {
|
|
20
|
+
console.log('parseSource THREW:', e);
|
|
21
|
+
continue;
|
|
22
|
+
}
|
|
23
|
+
const parseTime = Date.now() - t0;
|
|
24
|
+
console.log(`parseSource: type=${astResult?.type} children=${astResult?.children?.length} time=${parseTime}ms`);
|
|
25
|
+
|
|
26
|
+
const t1 = Date.now();
|
|
27
|
+
const safe = isSafeShellCommand(cmd);
|
|
28
|
+
const safeTime = Date.now() - t1;
|
|
29
|
+
console.log(`isSafeShellCommand: ${safe} time=${safeTime}ms`);
|
|
30
|
+
|
|
31
|
+
const t2 = Date.now();
|
|
32
|
+
const risk = getToolRiskLevel('Shell', { command: cmd });
|
|
33
|
+
const riskTime = Date.now() - t2;
|
|
34
|
+
console.log(`getToolRiskLevel: ${risk} time=${riskTime}ms`);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
console.log('\nAll tests completed.');
|
package/scripts/test-parser2.ts
CHANGED
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
import { parseSource } from '../src/shared/utils/bash-parser.ts';
|
|
2
|
-
|
|
3
|
-
const cmd = 'cd /c/Users/zhuoz/Desktop/gui && ls -la build* 2>/dev/null || echo "No build directory found"';
|
|
4
|
-
|
|
5
|
-
// Test 1: just parseSource with timeout guard
|
|
6
|
-
console.log('Testing parseSource...');
|
|
7
|
-
const start = Date.now();
|
|
8
|
-
|
|
9
|
-
// Use a worker-like approach: run in a separate microtask with a hard timeout
|
|
10
|
-
let result: any = 'TIMEOUT';
|
|
11
|
-
let done = false;
|
|
12
|
-
|
|
13
|
-
// We can't truly timeout sync code in JS, but let's at least see if it returns
|
|
14
|
-
try {
|
|
15
|
-
result = parseSource(cmd);
|
|
16
|
-
done = true;
|
|
17
|
-
} catch (e) {
|
|
18
|
-
result = 'ERROR: ' + e;
|
|
19
|
-
done = true;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
const elapsed = Date.now() - start;
|
|
23
|
-
console.log('parseSource returned:', done ? 'yes' : 'no', 'time:', elapsed, 'ms');
|
|
24
|
-
console.log('result type:', result?.type, 'children:', result?.children?.length);
|
|
1
|
+
import { parseSource } from '../src/shared/utils/bash-parser.ts';
|
|
2
|
+
|
|
3
|
+
const cmd = 'cd /c/Users/zhuoz/Desktop/gui && ls -la build* 2>/dev/null || echo "No build directory found"';
|
|
4
|
+
|
|
5
|
+
// Test 1: just parseSource with timeout guard
|
|
6
|
+
console.log('Testing parseSource...');
|
|
7
|
+
const start = Date.now();
|
|
8
|
+
|
|
9
|
+
// Use a worker-like approach: run in a separate microtask with a hard timeout
|
|
10
|
+
let result: any = 'TIMEOUT';
|
|
11
|
+
let done = false;
|
|
12
|
+
|
|
13
|
+
// We can't truly timeout sync code in JS, but let's at least see if it returns
|
|
14
|
+
try {
|
|
15
|
+
result = parseSource(cmd);
|
|
16
|
+
done = true;
|
|
17
|
+
} catch (e) {
|
|
18
|
+
result = 'ERROR: ' + e;
|
|
19
|
+
done = true;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const elapsed = Date.now() - start;
|
|
23
|
+
console.log('parseSource returned:', done ? 'yes' : 'no', 'time:', elapsed, 'ms');
|
|
24
|
+
console.log('result type:', result?.type, 'children:', result?.children?.length);
|
package/scripts/test-parser3.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// Test: find where the bash parser infinite loop is
|
|
2
|
-
// by testing parseSource with a simpler version of the command
|
|
3
|
-
|
|
4
|
-
const { parseSource } = require('../dist/shared/utils/bash-parser.cjs');
|
|
1
|
+
// Test: find where the bash parser infinite loop is
|
|
2
|
+
// by testing parseSource with a simpler version of the command
|
|
3
|
+
|
|
4
|
+
const { parseSource } = require('../dist/shared/utils/bash-parser.cjs');
|