MCPcopy Create free account
hub / github.com/Microck/opencode-studio / aggregateAgents

Function aggregateAgents

server/index.js:1274–1340  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1272});
1273
1274const aggregateAgents = () => {
1275 const agentMap = new Map();
1276 const roots = getSearchRoots();
1277
1278 for (const root of roots) {
1279 const configPath = path.join(root, 'opencode.json');
1280 if (fs.existsSync(configPath)) {
1281 try {
1282 const content = JSON.parse(fs.readFileSync(configPath, 'utf8'));
1283 const configAgents = content.agent || {};
1284 for (const [name, agentConfig] of Object.entries(configAgents)) {
1285 if (!agentMap.has(name)) {
1286 agentMap.set(name, {
1287 name,
1288 source: 'json-config',
1289 configPath: root,
1290 ...agentConfig,
1291 permission: agentConfig.permission || agentConfig.permissions,
1292 permissions: agentConfig.permission || agentConfig.permissions
1293 });
1294 }
1295 }
1296 } catch (err) {
1297 console.error(`Failed to read agent config from ${configPath}:`, err.message);
1298 }
1299 }
1300 }
1301
1302 for (const dir of getAgentDirs()) {
1303 if (!fs.existsSync(dir)) continue;
1304 const files = fs.readdirSync(dir).filter((f) => f.endsWith('.md'));
1305 files.forEach((file) => {
1306 const fp = path.join(dir, file);
1307 const content = fs.readFileSync(fp, 'utf8');
1308 const { data, body } = parseAgentMarkdown(content);
1309 const name = path.basename(file, '.md');
1310
1311 if (!agentMap.has(name)) {
1312 agentMap.set(name, {
1313 name,
1314 source: 'markdown',
1315 path: fp,
1316 disabled: false,
1317 description: data.description,
1318 mode: data.mode,
1319 model: data.model,
1320 temperature: data.temperature,
1321 tools: data.tools,
1322 permission: data.permission,
1323 permissions: data.permission,
1324 maxSteps: data.maxSteps,
1325 disable: data.disable,
1326 hidden: data.hidden,
1327 prompt: body
1328 });
1329 }
1330 });
1331 }

Callers 1

index.jsFile · 0.85

Calls 3

getSearchRootsFunction · 0.85
getAgentDirsFunction · 0.85
parseAgentMarkdownFunction · 0.85

Tested by

no test coverage detected