@ericnunes/frame-code-cli 0.0.1 → 0.0.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/dist/agent-runtime/index.js +0 -1
- package/dist/agent-runtime/registry/AgentRegistry.js +108 -36
- package/dist/agent-runtime/registry/index.js +1 -11
- package/dist/app/cli.js +3 -5
- package/dist/cli/commands/autonomous.js +8 -6
- package/dist/cli/commands/interactive.js +63 -146
- package/dist/cli/commands/memory.js +247 -76
- package/dist/content/agents/README.md +36 -32
- package/dist/content/agents/architect.md +1 -1
- package/dist/content/agents/builder.md +11 -15
- package/dist/content/agents/code-agent.md +1 -95
- package/dist/index.js +0 -6
- package/dist/infrastructure/config/config.js +40 -0
- package/dist/tools/index.js +0 -2
- package/dist/tools/registry/ToolInitializer.js +15 -55
- package/dist/tools/registry/index.js +1 -7
- package/package.json +11 -23
- package/dist/agent-runtime/AgentFacade.js +0 -33
- package/dist/agent-runtime/context/hooks/compressionHook.js +0 -56
- package/dist/agent-runtime/context/hooks/index.js +0 -5
- package/dist/agent-runtime/context/project-rules/loader.js +0 -72
- package/dist/agent-runtime/context/system-prompts/index.js +0 -5
- package/dist/agent-runtime/context/system-prompts/loader.js +0 -88
- package/dist/agent-runtime/flows/templates/ReactAgentFlow.js +0 -49
- package/dist/agent-runtime/registry/agentParser.js +0 -515
- package/dist/agent-runtime/registry/enums/agentType.enum.js +0 -8
- package/dist/agent-runtime/registry/interfaces/agentDependencies.interface.js +0 -2
- package/dist/agent-runtime/registry/interfaces/agentRegistry.interface.js +0 -2
- package/dist/app/bootstrap.js +0 -22
- package/dist/app/index.js +0 -9
- package/dist/cli/commands/index.js +0 -11
- package/dist/cli/commands/multi-agent.js +0 -131
- package/dist/cli/index.js +0 -18
- package/dist/cli/input/images/imageInput.js +0 -77
- package/dist/cli/input/images/readImageAttachment.js +0 -56
- package/dist/cli/input/index.js +0 -14
- package/dist/infrastructure/compression/CompressionManager.js +0 -315
- package/dist/infrastructure/compression/LLMCompressionService.js +0 -211
- package/dist/infrastructure/compression/index.js +0 -11
- package/dist/infrastructure/compression/promptBuilder.js +0 -132
- package/dist/infrastructure/config/agentConfig.interface.js +0 -2
- package/dist/infrastructure/config/agentConfig.js +0 -134
- package/dist/infrastructure/logging/index.js +0 -5
- package/dist/infrastructure/logging/logger.interface.js +0 -2
- package/dist/infrastructure/logging/raw-output-logger.js +0 -35
- package/dist/infrastructure/skills/index.js +0 -5
- package/dist/infrastructure/skills/loader.js +0 -104
- package/dist/infrastructure/telemetry/index.js +0 -9
- package/dist/infrastructure/telemetry/telemetry.interface.js +0 -2
- package/dist/infrastructure/telemetry/telemetryConfig.js +0 -30
- package/dist/infrastructure/telemetry/traceEventFormatter.js +0 -90
- package/dist/infrastructure/telemetry/traceSinkConsole.js +0 -17
- package/dist/scripts/_validate/telemetry-autonomous.js +0 -23
- package/dist/scripts/_validate/telemetry-multi-agent.js +0 -50
- package/dist/scripts/_validate/test-agents-md-dynamic-dir.js +0 -104
- package/dist/scripts/_validate/test-agents-md-injection.js +0 -125
- package/dist/scripts/_validate/test-agents-md-loader.js +0 -71
- package/dist/scripts/_validate/test-agents-md-priority.js +0 -121
- package/dist/scripts/_validate/test-chrome-mcp-agent.js +0 -89
- package/dist/tools/mcp/discoverer.js +0 -95
- package/dist/tools/mcp/index.js +0 -9
- package/dist/tools/mcp/loader.js +0 -36
- package/dist/tools/mcp/mcpConfig.interface.js +0 -2
- package/dist/tools/mcp/mcpMetadata.js +0 -2
- package/dist/tools/mcp/register.js +0 -269
- package/dist/tools/native/capabilities.js +0 -155
- package/dist/tools/native/file-outline.js +0 -301
- package/dist/tools/native/index.js +0 -20
- package/dist/tools/native/list-directory.js +0 -148
- package/dist/tools/native/read-image.js +0 -140
- package/dist/tools/registry/toolFilter.js +0 -52
- package/dist/tools/registry/toolRegistry.interface.js +0 -2
|
@@ -1,515 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.parseAgentFile = parseAgentFile;
|
|
37
|
-
exports.discoverAgents = discoverAgents;
|
|
38
|
-
exports.createAgentFromFlow = createAgentFromFlow;
|
|
39
|
-
const fs = __importStar(require("fs"));
|
|
40
|
-
const path = __importStar(require("path"));
|
|
41
|
-
const frame_agent_sdk_1 = require("@ericnunes/frame-agent-sdk");
|
|
42
|
-
const ReactAgentFlow_1 = require("../flows/templates/ReactAgentFlow");
|
|
43
|
-
const AgentRegistry_1 = require("./AgentRegistry");
|
|
44
|
-
const tools_1 = require("../../tools");
|
|
45
|
-
const config_1 = require("../../infrastructure/config");
|
|
46
|
-
const agentConfig_1 = require("../../infrastructure/config/agentConfig");
|
|
47
|
-
const compression_1 = require("../../infrastructure/compression");
|
|
48
|
-
const compressionHook_1 = require("../context/hooks/compressionHook");
|
|
49
|
-
const loader_1 = require("../context/system-prompts/loader");
|
|
50
|
-
const loader_2 = require("../context/project-rules/loader");
|
|
51
|
-
const logger_1 = require("../../infrastructure/logging/logger");
|
|
52
|
-
const loader_3 = require("../../tools/mcp/loader");
|
|
53
|
-
function parseAgentFile(filePath) {
|
|
54
|
-
try {
|
|
55
|
-
const content = fs.readFileSync(filePath, 'utf-8');
|
|
56
|
-
const lines = content.split('\n');
|
|
57
|
-
if (lines[0].trim() !== '---') {
|
|
58
|
-
logger_1.logger.warn('[agentFormatter] Arquivo sem frontmatter: ' + filePath);
|
|
59
|
-
return null;
|
|
60
|
-
}
|
|
61
|
-
const frontmatter = {};
|
|
62
|
-
let i = 1;
|
|
63
|
-
for (; i < lines.length; i++) {
|
|
64
|
-
if (lines[i].trim() === '---')
|
|
65
|
-
break;
|
|
66
|
-
const colonIndex = lines[i].indexOf(':');
|
|
67
|
-
if (colonIndex === -1)
|
|
68
|
-
continue;
|
|
69
|
-
const key = lines[i].substring(0, colonIndex).trim();
|
|
70
|
-
const valuePart = lines[i].substring(colonIndex + 1).trim();
|
|
71
|
-
if (valuePart === '|' || valuePart.startsWith('| ')) {
|
|
72
|
-
const multilineLines = [];
|
|
73
|
-
i++;
|
|
74
|
-
let baseIndent = 0;
|
|
75
|
-
while (i < lines.length && lines[i].trim() !== '---') {
|
|
76
|
-
const line = lines[i];
|
|
77
|
-
if (line.match(/^\s*[a-zA-Z_]+:/)) {
|
|
78
|
-
break;
|
|
79
|
-
}
|
|
80
|
-
if (line.trim() === '') {
|
|
81
|
-
multilineLines.push('');
|
|
82
|
-
i++;
|
|
83
|
-
continue;
|
|
84
|
-
}
|
|
85
|
-
if (baseIndent === 0 && line.trim() !== '') {
|
|
86
|
-
const match = line.match(/^(\s+)/);
|
|
87
|
-
baseIndent = match ? match[1].length : 0;
|
|
88
|
-
}
|
|
89
|
-
if (line.length >= baseIndent) {
|
|
90
|
-
multilineLines.push(line.substring(baseIndent));
|
|
91
|
-
}
|
|
92
|
-
i++;
|
|
93
|
-
}
|
|
94
|
-
i--;
|
|
95
|
-
frontmatter[key] = multilineLines.join('\n');
|
|
96
|
-
continue;
|
|
97
|
-
}
|
|
98
|
-
if (key && valuePart.length > 0) {
|
|
99
|
-
const value = valuePart;
|
|
100
|
-
if (value.startsWith('[') && value.endsWith(']')) {
|
|
101
|
-
const arrayValue = value
|
|
102
|
-
.slice(1, -1)
|
|
103
|
-
.split(',')
|
|
104
|
-
.map((s) => s.trim().replace(/^['"]|['"]$/g, ''));
|
|
105
|
-
if (key === 'subAgents' && arrayValue.length === 1 && arrayValue[0] === 'all') {
|
|
106
|
-
frontmatter[key] = 'all';
|
|
107
|
-
}
|
|
108
|
-
else if (key === 'availableFor' && arrayValue.length === 1 && arrayValue[0] === 'all') {
|
|
109
|
-
frontmatter[key] = 'all';
|
|
110
|
-
}
|
|
111
|
-
else {
|
|
112
|
-
frontmatter[key] = arrayValue;
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
else {
|
|
116
|
-
if (value === 'true') {
|
|
117
|
-
frontmatter[key] = true;
|
|
118
|
-
}
|
|
119
|
-
else if (value === 'false') {
|
|
120
|
-
frontmatter[key] = false;
|
|
121
|
-
}
|
|
122
|
-
else if (value === 'all' && key === 'subAgents') {
|
|
123
|
-
frontmatter[key] = 'all';
|
|
124
|
-
}
|
|
125
|
-
else {
|
|
126
|
-
frontmatter[key] = value.replace(/^['"]|['"]$/g, '');
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
const body = lines.slice(i + 1).join('\n').trim();
|
|
132
|
-
if (!frontmatter.name || !frontmatter.type || !frontmatter.description) {
|
|
133
|
-
logger_1.logger.error('[agentFormatter] Campos obrigatórios faltando em ' + filePath);
|
|
134
|
-
return null;
|
|
135
|
-
}
|
|
136
|
-
let agentType = frontmatter.type;
|
|
137
|
-
if (agentType !== 'main-agent' && agentType !== 'sub-agent') {
|
|
138
|
-
logger_1.logger.warn('[agentFormatter] Type inválido em ' + filePath + ': ' + frontmatter.type);
|
|
139
|
-
return null;
|
|
140
|
-
}
|
|
141
|
-
const category = 'agents';
|
|
142
|
-
const metadata = {
|
|
143
|
-
name: frontmatter.name,
|
|
144
|
-
type: agentType,
|
|
145
|
-
canBeSupervisor: frontmatter.canBeSupervisor === true || frontmatter.canBeSupervisor === 'true',
|
|
146
|
-
description: frontmatter.description,
|
|
147
|
-
keywords: frontmatter.keywords || [],
|
|
148
|
-
tools: frontmatter.tools || [],
|
|
149
|
-
toolPolicy: frontmatter.toolPolicy,
|
|
150
|
-
subAgents: frontmatter.subAgents,
|
|
151
|
-
availableFor: frontmatter.availableFor,
|
|
152
|
-
model: frontmatter.model,
|
|
153
|
-
temperature: frontmatter.temperature ? parseFloat(frontmatter.temperature) : undefined,
|
|
154
|
-
maxTokens: frontmatter.maxTokens ? parseInt(frontmatter.maxTokens, 10) : undefined,
|
|
155
|
-
systemPromptPath: frontmatter.systemPrompt,
|
|
156
|
-
systemPrompt: body,
|
|
157
|
-
backstory: frontmatter.backstory,
|
|
158
|
-
additionalInstructions: frontmatter.additionalInstructions,
|
|
159
|
-
path: filePath,
|
|
160
|
-
category,
|
|
161
|
-
compressionEnabled: frontmatter.compressionEnabled !== undefined
|
|
162
|
-
? frontmatter.compressionEnabled === true || frontmatter.compressionEnabled === 'true'
|
|
163
|
-
: undefined,
|
|
164
|
-
customErrorHandling: frontmatter.customErrorHandling === true || frontmatter.customErrorHandling === 'true',
|
|
165
|
-
flowMode: frontmatter.flowMode,
|
|
166
|
-
useProjectRules: frontmatter.useProjectRules !== false
|
|
167
|
-
};
|
|
168
|
-
return metadata;
|
|
169
|
-
}
|
|
170
|
-
catch (error) {
|
|
171
|
-
logger_1.logger.error('[agentFormatter] Erro ao parsear ' + filePath + ':', error);
|
|
172
|
-
return null;
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
function discoverAgentsInDir(agentsDir) {
|
|
176
|
-
const agents = [];
|
|
177
|
-
if (!fs.existsSync(agentsDir)) {
|
|
178
|
-
return agents;
|
|
179
|
-
}
|
|
180
|
-
const entries = fs.readdirSync(agentsDir, { withFileTypes: true });
|
|
181
|
-
for (const entry of entries) {
|
|
182
|
-
if (entry.isFile() && entry.name.endsWith('.md') && entry.name !== 'README.md') {
|
|
183
|
-
const agentFile = path.join(agentsDir, entry.name);
|
|
184
|
-
const metadata = parseAgentFile(agentFile);
|
|
185
|
-
if (metadata) {
|
|
186
|
-
agents.push(metadata);
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
return agents;
|
|
191
|
-
}
|
|
192
|
-
function discoverAgents(agentsDir) {
|
|
193
|
-
const agents = [];
|
|
194
|
-
let builtinAgentsDir = path.join(__dirname, '../../content/agents');
|
|
195
|
-
if (!fs.existsSync(builtinAgentsDir)) {
|
|
196
|
-
try {
|
|
197
|
-
const packagePath = require.resolve('frame-code-cli/package.json');
|
|
198
|
-
const packageDir = path.dirname(packagePath);
|
|
199
|
-
builtinAgentsDir = path.join(packageDir, 'dist', 'content', 'agents');
|
|
200
|
-
if (!fs.existsSync(builtinAgentsDir)) {
|
|
201
|
-
builtinAgentsDir = path.join(packageDir, 'content', 'agents');
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
catch {
|
|
205
|
-
builtinAgentsDir = path.join(__dirname, '../../content/agents');
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
agents.push(...discoverAgentsInDir(builtinAgentsDir));
|
|
209
|
-
const customAgentsDir = path.join(agentsDir || path.join(process.cwd(), '.code'), 'agents');
|
|
210
|
-
agents.push(...discoverAgentsInDir(customAgentsDir));
|
|
211
|
-
return agents;
|
|
212
|
-
}
|
|
213
|
-
function filterToolsByPolicy(allTools, policy) {
|
|
214
|
-
if (!policy)
|
|
215
|
-
return allTools;
|
|
216
|
-
let filtered = allTools;
|
|
217
|
-
if (policy.allow && policy.allow.length > 0) {
|
|
218
|
-
filtered = filtered.filter((t) => policy.allow.includes(t.name));
|
|
219
|
-
}
|
|
220
|
-
if (policy.deny && policy.deny.length > 0) {
|
|
221
|
-
filtered = filtered.filter((t) => !policy.deny.includes(t.name));
|
|
222
|
-
}
|
|
223
|
-
return filtered;
|
|
224
|
-
}
|
|
225
|
-
function filterSubAgents(allSubAgents, subAgentsConfig, supervisorName) {
|
|
226
|
-
if (supervisorName) {
|
|
227
|
-
return allSubAgents.filter(agent => {
|
|
228
|
-
if (!agent.availableFor)
|
|
229
|
-
return true;
|
|
230
|
-
if (agent.availableFor === 'all')
|
|
231
|
-
return true;
|
|
232
|
-
return agent.availableFor.includes(supervisorName);
|
|
233
|
-
});
|
|
234
|
-
}
|
|
235
|
-
if (!subAgentsConfig || (Array.isArray(subAgentsConfig) && subAgentsConfig.length === 0)) {
|
|
236
|
-
return [];
|
|
237
|
-
}
|
|
238
|
-
if (subAgentsConfig === 'all') {
|
|
239
|
-
return allSubAgents;
|
|
240
|
-
}
|
|
241
|
-
const allowedSet = new Set(subAgentsConfig);
|
|
242
|
-
return allSubAgents.filter(agent => allowedSet.has(agent.name));
|
|
243
|
-
}
|
|
244
|
-
function expandMcpTools(toolNames, mcpLoader, allTools) {
|
|
245
|
-
const expanded = [];
|
|
246
|
-
const mcpNamespaces = new Set();
|
|
247
|
-
for (const name of toolNames) {
|
|
248
|
-
const mcpById = mcpLoader.getMcpById(name);
|
|
249
|
-
if (mcpById) {
|
|
250
|
-
mcpNamespaces.add(mcpById.namespace);
|
|
251
|
-
continue;
|
|
252
|
-
}
|
|
253
|
-
const mcpByNs = mcpLoader.getMcpByNamespace(name);
|
|
254
|
-
if (mcpByNs.length > 0) {
|
|
255
|
-
mcpNamespaces.add(mcpByNs[0].namespace);
|
|
256
|
-
continue;
|
|
257
|
-
}
|
|
258
|
-
expanded.push(name);
|
|
259
|
-
}
|
|
260
|
-
if (mcpNamespaces.size > 0) {
|
|
261
|
-
for (const tool of allTools) {
|
|
262
|
-
const meta = tool;
|
|
263
|
-
if (meta._mcpNamespace && mcpNamespaces.has(meta._mcpNamespace)) {
|
|
264
|
-
expanded.push(tool.name);
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
|
-
}
|
|
268
|
-
return [...new Set(expanded)];
|
|
269
|
-
}
|
|
270
|
-
function loadSystemPromptWithExternal(systemPromptPath, basePrompt) {
|
|
271
|
-
if (!systemPromptPath)
|
|
272
|
-
return basePrompt;
|
|
273
|
-
try {
|
|
274
|
-
const externalPrompt = loader_1.loadSystemPrompt.loadFileContent(systemPromptPath);
|
|
275
|
-
return externalPrompt + '\n\n' + basePrompt;
|
|
276
|
-
}
|
|
277
|
-
catch (e) {
|
|
278
|
-
logger_1.logger.warn('[agentFormatter] Não foi possível carregar ' + systemPromptPath);
|
|
279
|
-
return basePrompt;
|
|
280
|
-
}
|
|
281
|
-
}
|
|
282
|
-
async function createAgentWithDefinition(metadata, telemetry) {
|
|
283
|
-
const config = await (0, config_1.loadConfig)();
|
|
284
|
-
let compressionManager;
|
|
285
|
-
if (metadata.compressionEnabled !== false && config.compression?.enabled !== false) {
|
|
286
|
-
compressionManager = new compression_1.CompressionManager({
|
|
287
|
-
...config.compression,
|
|
288
|
-
persistKey: 'agent-' + metadata.name
|
|
289
|
-
});
|
|
290
|
-
}
|
|
291
|
-
let systemPrompt = loadSystemPromptWithExternal(metadata.systemPromptPath, metadata.systemPrompt);
|
|
292
|
-
if (compressionManager) {
|
|
293
|
-
const compressionPrompt = compressionManager.getCompressionPrompt();
|
|
294
|
-
if (compressionPrompt) {
|
|
295
|
-
systemPrompt = compressionPrompt + '\n\n' + systemPrompt;
|
|
296
|
-
}
|
|
297
|
-
}
|
|
298
|
-
const projectRules = loader_2.loadProjectRules.load();
|
|
299
|
-
if (metadata.useProjectRules !== false && projectRules.content && projectRules.source !== 'none') {
|
|
300
|
-
const rulesSection = `## Rules Project\n\n${projectRules.content}\n\n---\n\n`;
|
|
301
|
-
systemPrompt = systemPrompt + rulesSection;
|
|
302
|
-
}
|
|
303
|
-
if (metadata.useProjectRules !== false) {
|
|
304
|
-
const directoryInstruction = `### Instrução Adicional\n\n` +
|
|
305
|
-
`Arquivo AGENTS.md ou CLAUDE.md são arquivos que contêm regras e contexto do projeto. ` +
|
|
306
|
-
`Cada diretório que você acessar, verifique se possui AGENTS.md ou CLAUDE.md para colher contexto.\n\n`;
|
|
307
|
-
systemPrompt = systemPrompt + directoryInstruction;
|
|
308
|
-
}
|
|
309
|
-
const agentConfig = (0, agentConfig_1.loadAgentConfig)(metadata.name);
|
|
310
|
-
const supportsVision = agentConfig.capabilities?.supportsVision
|
|
311
|
-
?? config.vision?.supportsVision
|
|
312
|
-
?? false;
|
|
313
|
-
const llmConfig = {
|
|
314
|
-
model: metadata.model || agentConfig.model || config.defaults?.model || 'gpt-4o-mini',
|
|
315
|
-
provider: agentConfig.provider || config.provider,
|
|
316
|
-
apiKey: agentConfig.apiKey || config.apiKey,
|
|
317
|
-
baseUrl: agentConfig.baseUrl || config.baseURL,
|
|
318
|
-
capabilities: { supportsVision },
|
|
319
|
-
defaults: {
|
|
320
|
-
maxTokens: metadata.maxTokens || agentConfig.maxTokens || config.defaults?.maxTokens,
|
|
321
|
-
maxContextTokens: agentConfig.maxContextTokens || config.defaults?.maxContextTokens,
|
|
322
|
-
temperature: metadata.temperature ?? agentConfig.temperature ?? config.defaults?.temperature,
|
|
323
|
-
topP: agentConfig.topP ?? config.defaults?.topP
|
|
324
|
-
}
|
|
325
|
-
};
|
|
326
|
-
const allTools = tools_1.toolRegistry.listTools();
|
|
327
|
-
const allowedTools = filterToolsByPolicy(allTools, metadata.toolPolicy);
|
|
328
|
-
const mcpLoader = new loader_3.McpLoader();
|
|
329
|
-
const expandedToolNames = expandMcpTools(metadata.tools, mcpLoader, allTools);
|
|
330
|
-
let finalTools = expandedToolNames.length > 0
|
|
331
|
-
? allowedTools.filter((t) => expandedToolNames.includes(t.name))
|
|
332
|
-
: allowedTools;
|
|
333
|
-
if (metadata.type === 'sub-agent' && finalTools.some((t) => t.name === 'ask_user')) {
|
|
334
|
-
finalTools = finalTools.filter((t) => t.name !== 'ask_user');
|
|
335
|
-
}
|
|
336
|
-
if (!supportsVision) {
|
|
337
|
-
finalTools = finalTools.filter((t) => t.name !== 'read_image');
|
|
338
|
-
}
|
|
339
|
-
const graphDefinition = {
|
|
340
|
-
...ReactAgentFlow_1.REACT_AGENT_FLOW,
|
|
341
|
-
nodes: { ...ReactAgentFlow_1.REACT_AGENT_FLOW.nodes }
|
|
342
|
-
};
|
|
343
|
-
graphDefinition.nodes.agent = (0, frame_agent_sdk_1.createAgentNode)({
|
|
344
|
-
llm: llmConfig,
|
|
345
|
-
promptConfig: {
|
|
346
|
-
mode: 'react',
|
|
347
|
-
agentInfo: {
|
|
348
|
-
name: metadata.name,
|
|
349
|
-
goal: metadata.description,
|
|
350
|
-
backstory: metadata.backstory || systemPrompt.substring(0, 500)
|
|
351
|
-
},
|
|
352
|
-
additionalInstructions: metadata.additionalInstructions || systemPrompt,
|
|
353
|
-
tools: finalTools,
|
|
354
|
-
toolPolicy: metadata.toolPolicy
|
|
355
|
-
},
|
|
356
|
-
contextHooks: (0, compressionHook_1.createCliContextHooks)(compressionManager),
|
|
357
|
-
autoExecuteTools: false,
|
|
358
|
-
temperature: metadata.temperature ?? config.defaults?.temperature,
|
|
359
|
-
maxTokens: metadata.maxTokens || config.defaults?.maxTokens
|
|
360
|
-
});
|
|
361
|
-
if (metadata.customErrorHandling) {
|
|
362
|
-
const originalExecuteNode = graphDefinition.nodes.execute;
|
|
363
|
-
graphDefinition.nodes.execute = async (state, engine) => {
|
|
364
|
-
if (state.status === 'ERROR') {
|
|
365
|
-
logger_1.logger.warn('[' + metadata.name + '] Erro detectado, aplicando tratamento customizado');
|
|
366
|
-
}
|
|
367
|
-
return originalExecuteNode(state, engine);
|
|
368
|
-
};
|
|
369
|
-
}
|
|
370
|
-
const engine = new frame_agent_sdk_1.GraphEngine(graphDefinition, telemetry ? {
|
|
371
|
-
trace: telemetry.trace,
|
|
372
|
-
telemetry: telemetry.telemetry,
|
|
373
|
-
traceContext: { agent: { id: metadata.name, label: metadata.name } }
|
|
374
|
-
} : undefined, llmConfig);
|
|
375
|
-
return { graphDefinition, engine, llmConfig };
|
|
376
|
-
}
|
|
377
|
-
async function createAgentFromFlow(metadata, telemetry, _skipSubAgents) {
|
|
378
|
-
const config = await (0, config_1.loadConfig)();
|
|
379
|
-
let compressionManager;
|
|
380
|
-
if (metadata.compressionEnabled !== false && config.compression?.enabled !== false) {
|
|
381
|
-
compressionManager = new compression_1.CompressionManager({
|
|
382
|
-
...config.compression,
|
|
383
|
-
persistKey: 'agent-' + metadata.name
|
|
384
|
-
});
|
|
385
|
-
}
|
|
386
|
-
let systemPrompt = loadSystemPromptWithExternal(metadata.systemPromptPath, metadata.systemPrompt);
|
|
387
|
-
if (compressionManager) {
|
|
388
|
-
const compressionPrompt = compressionManager.getCompressionPrompt();
|
|
389
|
-
if (compressionPrompt) {
|
|
390
|
-
systemPrompt = compressionPrompt + '\n\n' + systemPrompt;
|
|
391
|
-
}
|
|
392
|
-
}
|
|
393
|
-
const projectRules = loader_2.loadProjectRules.load();
|
|
394
|
-
if (metadata.useProjectRules !== false && projectRules.content && projectRules.source !== 'none') {
|
|
395
|
-
const rulesSection = `## Rules Project\n\n${projectRules.content}\n\n---\n\n`;
|
|
396
|
-
systemPrompt = systemPrompt + rulesSection;
|
|
397
|
-
}
|
|
398
|
-
if (metadata.useProjectRules !== false) {
|
|
399
|
-
const directoryInstruction = `### Instrução Adicional\n\n` +
|
|
400
|
-
`Arquivo AGENTS.md ou CLAUDE.md são arquivos que contêm regras e contexto do projeto. ` +
|
|
401
|
-
`Cada diretório que você acessar, verifique se possui AGENTS.md ou CLAUDE.md para colher contexto.\n\n`;
|
|
402
|
-
systemPrompt = systemPrompt + directoryInstruction;
|
|
403
|
-
}
|
|
404
|
-
if (metadata.type === 'main-agent' && metadata.canBeSupervisor) {
|
|
405
|
-
const registry = AgentRegistry_1.AgentRegistry.getInstance();
|
|
406
|
-
const allSubAgents = registry.listByType('sub-agent');
|
|
407
|
-
const allowedSubAgents = filterSubAgents(allSubAgents, metadata.subAgents, metadata.name);
|
|
408
|
-
if (allowedSubAgents.length > 0) {
|
|
409
|
-
const subAgentList = allowedSubAgents.map(agent => `- **${agent.name}**: ${agent.description}`).join('\n');
|
|
410
|
-
systemPrompt = systemPrompt + '\n\n## Sub-agentes Disponíveis\n\n' +
|
|
411
|
-
'Você pode chamar os seguintes sub-agentes via `call_flow`:\n\n' +
|
|
412
|
-
subAgentList + '\n\n' +
|
|
413
|
-
'Use `call_flow` com o `flowId` correspondente ao nome do sub-agente.';
|
|
414
|
-
}
|
|
415
|
-
}
|
|
416
|
-
const agentConfig = (0, agentConfig_1.loadAgentConfig)(metadata.name);
|
|
417
|
-
const supportsVision = agentConfig.capabilities?.supportsVision
|
|
418
|
-
?? config.vision?.supportsVision
|
|
419
|
-
?? false;
|
|
420
|
-
const llmConfig = {
|
|
421
|
-
model: metadata.model || agentConfig.model || config.defaults?.model || 'gpt-4o-mini',
|
|
422
|
-
provider: agentConfig.provider || config.provider,
|
|
423
|
-
apiKey: agentConfig.apiKey || config.apiKey,
|
|
424
|
-
baseUrl: agentConfig.baseUrl || config.baseURL,
|
|
425
|
-
capabilities: { supportsVision },
|
|
426
|
-
defaults: {
|
|
427
|
-
maxTokens: metadata.maxTokens || agentConfig.maxTokens || config.defaults?.maxTokens,
|
|
428
|
-
maxContextTokens: agentConfig.maxContextTokens || config.defaults?.maxContextTokens,
|
|
429
|
-
temperature: metadata.temperature ?? agentConfig.temperature ?? config.defaults?.temperature,
|
|
430
|
-
topP: agentConfig.topP ?? config.defaults?.topP
|
|
431
|
-
}
|
|
432
|
-
};
|
|
433
|
-
const allTools = tools_1.toolRegistry.listTools();
|
|
434
|
-
const allowedTools = filterToolsByPolicy(allTools, metadata.toolPolicy);
|
|
435
|
-
const mcpLoader = new loader_3.McpLoader();
|
|
436
|
-
const expandedToolNames = expandMcpTools(metadata.tools, mcpLoader, allTools);
|
|
437
|
-
const selectedTools = expandedToolNames.length > 0
|
|
438
|
-
? allowedTools.filter((t) => expandedToolNames.includes(t.name))
|
|
439
|
-
: allowedTools;
|
|
440
|
-
let finalTools = [...selectedTools];
|
|
441
|
-
if (metadata.type === 'sub-agent' && finalTools.some((t) => t.name === 'ask_user')) {
|
|
442
|
-
finalTools = finalTools.filter((t) => t.name !== 'ask_user');
|
|
443
|
-
}
|
|
444
|
-
if (!_skipSubAgents && metadata.type === 'main-agent') {
|
|
445
|
-
const registry = AgentRegistry_1.AgentRegistry.getInstance();
|
|
446
|
-
const allSubAgents = registry.listByType('sub-agent');
|
|
447
|
-
const allowedSubAgents = filterSubAgents(allSubAgents, metadata.subAgents, metadata.name);
|
|
448
|
-
if (allowedSubAgents.length === 0 && metadata.tools.includes('call_flow')) {
|
|
449
|
-
finalTools = selectedTools.filter((t) => t.name !== 'call_flow');
|
|
450
|
-
}
|
|
451
|
-
else if (allowedSubAgents.length > 0 && metadata.tools.includes('call_flow')) {
|
|
452
|
-
const flowRegistry = new frame_agent_sdk_1.FlowRegistryImpl();
|
|
453
|
-
for (const subAgent of allowedSubAgents) {
|
|
454
|
-
try {
|
|
455
|
-
const result = await createAgentWithDefinition(subAgent, telemetry);
|
|
456
|
-
flowRegistry.register(subAgent.name, {
|
|
457
|
-
id: subAgent.name,
|
|
458
|
-
version: '1',
|
|
459
|
-
kind: 'agentFlow',
|
|
460
|
-
graph: result.graphDefinition
|
|
461
|
-
});
|
|
462
|
-
}
|
|
463
|
-
catch (error) {
|
|
464
|
-
logger_1.logger.error('[' + metadata.name + '] ✗ Erro ao criar sub-agente ' + subAgent.name + ':', error);
|
|
465
|
-
}
|
|
466
|
-
}
|
|
467
|
-
const flowRunner = new frame_agent_sdk_1.FlowRunnerImpl(flowRegistry, { llmConfig });
|
|
468
|
-
const callFlowTool = new frame_agent_sdk_1.CallFlowTool(flowRunner);
|
|
469
|
-
try {
|
|
470
|
-
tools_1.toolRegistry.unregister('call_flow');
|
|
471
|
-
}
|
|
472
|
-
catch (e) { }
|
|
473
|
-
tools_1.toolRegistry.register(callFlowTool);
|
|
474
|
-
finalTools = finalTools.filter((t) => t.name !== 'call_flow');
|
|
475
|
-
finalTools.push(callFlowTool);
|
|
476
|
-
}
|
|
477
|
-
}
|
|
478
|
-
const graphDefinition = {
|
|
479
|
-
...ReactAgentFlow_1.REACT_AGENT_FLOW,
|
|
480
|
-
nodes: { ...ReactAgentFlow_1.REACT_AGENT_FLOW.nodes }
|
|
481
|
-
};
|
|
482
|
-
graphDefinition.nodes.agent = (0, frame_agent_sdk_1.createAgentNode)({
|
|
483
|
-
llm: llmConfig,
|
|
484
|
-
promptConfig: {
|
|
485
|
-
mode: 'react',
|
|
486
|
-
agentInfo: {
|
|
487
|
-
name: metadata.name,
|
|
488
|
-
goal: metadata.description,
|
|
489
|
-
backstory: metadata.backstory || systemPrompt.substring(0, 500)
|
|
490
|
-
},
|
|
491
|
-
additionalInstructions: metadata.additionalInstructions || systemPrompt,
|
|
492
|
-
tools: finalTools,
|
|
493
|
-
toolPolicy: metadata.toolPolicy
|
|
494
|
-
},
|
|
495
|
-
contextHooks: (0, compressionHook_1.createCliContextHooks)(compressionManager),
|
|
496
|
-
autoExecuteTools: false,
|
|
497
|
-
temperature: metadata.temperature ?? config.defaults?.temperature,
|
|
498
|
-
maxTokens: metadata.maxTokens || config.defaults?.maxTokens
|
|
499
|
-
});
|
|
500
|
-
if (metadata.customErrorHandling) {
|
|
501
|
-
const originalExecuteNode = graphDefinition.nodes.execute;
|
|
502
|
-
graphDefinition.nodes.execute = async (state, engine) => {
|
|
503
|
-
if (state.status === 'ERROR') {
|
|
504
|
-
logger_1.logger.warn('[' + metadata.name + '] Erro detectado, aplicando tratamento customizado');
|
|
505
|
-
}
|
|
506
|
-
return originalExecuteNode(state, engine);
|
|
507
|
-
};
|
|
508
|
-
}
|
|
509
|
-
const engine = new frame_agent_sdk_1.GraphEngine(graphDefinition, telemetry ? {
|
|
510
|
-
trace: telemetry.trace,
|
|
511
|
-
telemetry: telemetry.telemetry,
|
|
512
|
-
traceContext: { agent: { id: metadata.name, label: metadata.name } }
|
|
513
|
-
} : undefined, llmConfig);
|
|
514
|
-
return engine;
|
|
515
|
-
}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.AgentType = void 0;
|
|
4
|
-
var AgentType;
|
|
5
|
-
(function (AgentType) {
|
|
6
|
-
AgentType["MAIN_AGENT"] = "main-agent";
|
|
7
|
-
AgentType["SUB_AGENT"] = "sub-agent";
|
|
8
|
-
})(AgentType || (exports.AgentType = AgentType = {}));
|
package/dist/app/bootstrap.js
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.bootstrap = bootstrap;
|
|
4
|
-
exports.createDefaultTelemetry = createDefaultTelemetry;
|
|
5
|
-
const config_1 = require("../infrastructure/config");
|
|
6
|
-
const logger_1 = require("../infrastructure/logging/logger");
|
|
7
|
-
const tools_1 = require("../tools");
|
|
8
|
-
const agent_runtime_1 = require("../agent-runtime");
|
|
9
|
-
const telemetry_1 = require("../infrastructure/telemetry");
|
|
10
|
-
async function bootstrap() {
|
|
11
|
-
logger_1.logger.info('[Bootstrap] Inicializando frame-code-cli...');
|
|
12
|
-
await (0, config_1.loadConfig)();
|
|
13
|
-
logger_1.logger.debug('[Bootstrap] Configuração carregada');
|
|
14
|
-
await (0, tools_1.initializeTools)();
|
|
15
|
-
logger_1.logger.debug('[Bootstrap] Ferramentas inicializadas');
|
|
16
|
-
const agentCount = await (0, agent_runtime_1.initializeAgents)();
|
|
17
|
-
logger_1.logger.info(`[Bootstrap] ${agentCount} agentes carregados`);
|
|
18
|
-
logger_1.logger.info('[Bootstrap] Inicialização concluída');
|
|
19
|
-
}
|
|
20
|
-
function createDefaultTelemetry() {
|
|
21
|
-
return (0, telemetry_1.createCliTelemetry)();
|
|
22
|
-
}
|
package/dist/app/index.js
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createDefaultTelemetry = exports.bootstrap = exports.program = exports.runCli = void 0;
|
|
4
|
-
var cli_1 = require("./cli");
|
|
5
|
-
Object.defineProperty(exports, "runCli", { enumerable: true, get: function () { return cli_1.runCli; } });
|
|
6
|
-
Object.defineProperty(exports, "program", { enumerable: true, get: function () { return cli_1.program; } });
|
|
7
|
-
var bootstrap_1 = require("./bootstrap");
|
|
8
|
-
Object.defineProperty(exports, "bootstrap", { enumerable: true, get: function () { return bootstrap_1.bootstrap; } });
|
|
9
|
-
Object.defineProperty(exports, "createDefaultTelemetry", { enumerable: true, get: function () { return bootstrap_1.createDefaultTelemetry; } });
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createMemoryCommand = exports.createMultiAgentCommand = exports.createInteractiveCommand = exports.createAutonomousCommand = void 0;
|
|
4
|
-
var autonomous_1 = require("./autonomous");
|
|
5
|
-
Object.defineProperty(exports, "createAutonomousCommand", { enumerable: true, get: function () { return autonomous_1.createAutonomousCommand; } });
|
|
6
|
-
var interactive_1 = require("./interactive");
|
|
7
|
-
Object.defineProperty(exports, "createInteractiveCommand", { enumerable: true, get: function () { return interactive_1.createInteractiveCommand; } });
|
|
8
|
-
var multi_agent_1 = require("./multi-agent");
|
|
9
|
-
Object.defineProperty(exports, "createMultiAgentCommand", { enumerable: true, get: function () { return multi_agent_1.createMultiAgentCommand; } });
|
|
10
|
-
var memory_1 = require("./memory");
|
|
11
|
-
Object.defineProperty(exports, "createMemoryCommand", { enumerable: true, get: function () { return memory_1.createMemoryCommand; } });
|