-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathopencode-plugin.js
More file actions
96 lines (83 loc) · 3 KB
/
Copy pathopencode-plugin.js
File metadata and controls
96 lines (83 loc) · 3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import fs from 'fs';
import path from 'path';
import { fileURLToPath } from 'url';
import { tool } from '@opencode-ai/plugin';
import { createContentTools } from './tools/content/content-tools.js';
import { createZhihuTools } from './tools/zhihu/zhihu-tools.js';
const __dirname = path.dirname(fileURLToPath(import.meta.url));
const repoRoot = __dirname;
const agentsDir = path.join(repoRoot, 'agents');
const skillsDir = path.join(repoRoot, 'skills');
const superpowersSkillsDir = path.join(repoRoot, 'node_modules', 'superpowers', 'skills');
function parseFrontmatter(markdown) {
const match = markdown.match(/^---\n([\s\S]*?)\n---\n([\s\S]*)$/);
if (!match) return { frontmatter: {}, body: markdown.trimStart() };
const frontmatter = {};
for (const line of match[1].split('\n')) {
const trimmed = line.trim();
if (!trimmed || trimmed.startsWith('#')) continue;
const index = trimmed.indexOf(':');
if (index <= 0) continue;
const key = trimmed.slice(0, index).trim();
const value = trimmed.slice(index + 1).trim().replace(/^["']|["']$/g, '');
frontmatter[key] = value;
}
return { frontmatter, body: match[2].trimStart() };
}
function addSkillPath(config, skillPath) {
if (!fs.existsSync(skillPath)) return;
config.skills = config.skills || {};
config.skills.paths = config.skills.paths || [];
if (!config.skills.paths.includes(skillPath)) {
config.skills.paths.push(skillPath);
}
}
function registerSkills(config) {
addSkillPath(config, skillsDir);
addSkillPath(config, superpowersSkillsDir);
}
function registerBrowserMcp(config) {
config.mcp = config.mcp || {};
config.mcp.playwright = config.mcp.playwright || {
type: 'local',
command: ['npx', '-y', '@playwright/mcp'],
enabled: true,
};
config.mcp['chrome-devtools'] = config.mcp['chrome-devtools'] || {
type: 'local',
command: ['npx', '-y', 'chrome-devtools-mcp'],
enabled: true,
};
}
function registerAgents(config) {
if (!fs.existsSync(agentsDir)) return;
config.agent = config.agent || {};
for (const fileName of fs.readdirSync(agentsDir)) {
if (!fileName.endsWith('.md')) continue;
const agentName = path.basename(fileName, '.md');
const fullPath = path.join(agentsDir, fileName);
const markdown = fs.readFileSync(fullPath, 'utf8');
const { frontmatter, body } = parseFrontmatter(markdown);
config.agent[agentName] = {
...config.agent[agentName],
description: frontmatter.description || config.agent[agentName]?.description || `${agentName} agent`,
mode: frontmatter.mode || config.agent[agentName]?.mode || 'subagent',
color: frontmatter.color || config.agent[agentName]?.color,
prompt: body,
};
}
}
export const ArchAIAgentWorkflowsPlugin = async () => {
return {
config: async (config) => {
registerSkills(config);
registerAgents(config);
registerBrowserMcp(config);
},
tool: {
...createContentTools(tool),
...createZhihuTools(tool),
},
};
};
export default ArchAIAgentWorkflowsPlugin;