@ericnunes/frame-code-cli 0.0.1
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/LICENSE +139 -0
- package/README.md +196 -0
- package/dist/agent-runtime/AgentFacade.js +33 -0
- package/dist/agent-runtime/context/hooks/compressionHook.js +56 -0
- package/dist/agent-runtime/context/hooks/index.js +5 -0
- package/dist/agent-runtime/context/project-rules/loader.js +72 -0
- package/dist/agent-runtime/context/system-prompts/index.js +5 -0
- package/dist/agent-runtime/context/system-prompts/loader.js +88 -0
- package/dist/agent-runtime/flows/templates/ReactAgentFlow.js +49 -0
- package/dist/agent-runtime/index.js +18 -0
- package/dist/agent-runtime/registry/AgentRegistry.js +93 -0
- package/dist/agent-runtime/registry/agentParser.js +515 -0
- package/dist/agent-runtime/registry/enums/agentType.enum.js +8 -0
- package/dist/agent-runtime/registry/index.js +20 -0
- package/dist/agent-runtime/registry/initialization.js +53 -0
- package/dist/agent-runtime/registry/interfaces/agentDependencies.interface.js +2 -0
- package/dist/agent-runtime/registry/interfaces/agentMetadata.interface.js +2 -0
- package/dist/agent-runtime/registry/interfaces/agentRegistry.interface.js +2 -0
- package/dist/app/bootstrap.js +22 -0
- package/dist/app/cli.js +31 -0
- package/dist/app/index.js +9 -0
- package/dist/cli/commands/autonomous.js +181 -0
- package/dist/cli/commands/index.js +11 -0
- package/dist/cli/commands/interactive.js +172 -0
- package/dist/cli/commands/memory.js +149 -0
- package/dist/cli/commands/multi-agent.js +131 -0
- package/dist/cli/index.js +18 -0
- package/dist/cli/input/images/attachments.js +173 -0
- package/dist/cli/input/images/imageInput.js +77 -0
- package/dist/cli/input/images/readImageAttachment.js +56 -0
- package/dist/cli/input/index.js +14 -0
- package/dist/cli/input/reader.js +26 -0
- package/dist/content/agents/README.md +324 -0
- package/dist/content/agents/architect.md +95 -0
- package/dist/content/agents/builder.md +85 -0
- package/dist/content/agents/code-agent.md +123 -0
- package/dist/content/agents/supervisor.md +63 -0
- package/dist/index.js +25 -0
- package/dist/infrastructure/compression/CompressionManager.js +315 -0
- package/dist/infrastructure/compression/LLMCompressionService.js +211 -0
- package/dist/infrastructure/compression/index.js +11 -0
- package/dist/infrastructure/compression/promptBuilder.js +132 -0
- package/dist/infrastructure/config/agentConfig.interface.js +2 -0
- package/dist/infrastructure/config/agentConfig.js +134 -0
- package/dist/infrastructure/config/config.interface.js +2 -0
- package/dist/infrastructure/config/config.js +112 -0
- package/dist/infrastructure/config/index.js +6 -0
- package/dist/infrastructure/logging/index.js +5 -0
- package/dist/infrastructure/logging/logger.interface.js +2 -0
- package/dist/infrastructure/logging/logger.js +33 -0
- package/dist/infrastructure/logging/raw-output-logger.js +35 -0
- package/dist/infrastructure/skills/index.js +5 -0
- package/dist/infrastructure/skills/loader.js +104 -0
- package/dist/infrastructure/telemetry/index.js +9 -0
- package/dist/infrastructure/telemetry/telemetry.interface.js +2 -0
- package/dist/infrastructure/telemetry/telemetryConfig.js +30 -0
- package/dist/infrastructure/telemetry/traceEventFormatter.js +90 -0
- package/dist/infrastructure/telemetry/traceSinkConsole.js +17 -0
- package/dist/scripts/_validate/telemetry-autonomous.js +23 -0
- package/dist/scripts/_validate/telemetry-multi-agent.js +50 -0
- package/dist/scripts/_validate/test-agents-md-dynamic-dir.js +104 -0
- package/dist/scripts/_validate/test-agents-md-injection.js +125 -0
- package/dist/scripts/_validate/test-agents-md-loader.js +71 -0
- package/dist/scripts/_validate/test-agents-md-priority.js +121 -0
- package/dist/scripts/_validate/test-chrome-mcp-agent.js +89 -0
- package/dist/tools/index.js +19 -0
- package/dist/tools/mcp/discoverer.js +95 -0
- package/dist/tools/mcp/index.js +9 -0
- package/dist/tools/mcp/loader.js +36 -0
- package/dist/tools/mcp/mcpConfig.interface.js +2 -0
- package/dist/tools/mcp/mcpMetadata.js +2 -0
- package/dist/tools/mcp/register.js +269 -0
- package/dist/tools/native/capabilities.js +155 -0
- package/dist/tools/native/file-outline.js +301 -0
- package/dist/tools/native/index.js +20 -0
- package/dist/tools/native/list-directory.js +148 -0
- package/dist/tools/native/read-image.js +140 -0
- package/dist/tools/registry/ToolInitializer.js +62 -0
- package/dist/tools/registry/index.js +11 -0
- package/dist/tools/registry/toolFilter.js +52 -0
- package/dist/tools/registry/toolRegistry.interface.js +2 -0
- package/package.json +81 -0
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CLIPromptBuilder = void 0;
|
|
4
|
+
exports.createDefaultPromptConfig = createDefaultPromptConfig;
|
|
5
|
+
exports.createCompressionPromptConfig = createCompressionPromptConfig;
|
|
6
|
+
const frame_agent_sdk_1 = require("@ericnunes/frame-agent-sdk");
|
|
7
|
+
const logger_1 = require("../logging/logger");
|
|
8
|
+
class CLIPromptBuilder {
|
|
9
|
+
static formatCompressionContext(compressionHistory) {
|
|
10
|
+
return [
|
|
11
|
+
'---',
|
|
12
|
+
'',
|
|
13
|
+
'## Context History',
|
|
14
|
+
'',
|
|
15
|
+
'O contexto anterior desta sessão foi comprimido para preservar informações importantes:',
|
|
16
|
+
'',
|
|
17
|
+
compressionHistory.trim(),
|
|
18
|
+
'',
|
|
19
|
+
'Use este contexto histórico para entender o que já foi discutido e continuar a conversa de forma coerente.'
|
|
20
|
+
].join('\n');
|
|
21
|
+
}
|
|
22
|
+
static buildSystemPrompt(config) {
|
|
23
|
+
const { mode, agentInfo, additionalInstructions, compressionHistory, tools, toolNames, taskList } = config;
|
|
24
|
+
let finalAdditionalInstructions = additionalInstructions || '';
|
|
25
|
+
if (compressionHistory && compressionHistory.trim().length > 0) {
|
|
26
|
+
const formattedCompressionContext = this.formatCompressionContext(compressionHistory);
|
|
27
|
+
if (finalAdditionalInstructions.trim().length > 0) {
|
|
28
|
+
finalAdditionalInstructions = finalAdditionalInstructions + '\n\n' + formattedCompressionContext;
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
finalAdditionalInstructions = formattedCompressionContext;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return frame_agent_sdk_1.PromptBuilder.buildSystemPrompt({
|
|
35
|
+
mode,
|
|
36
|
+
agentInfo,
|
|
37
|
+
additionalInstructions: finalAdditionalInstructions,
|
|
38
|
+
tools,
|
|
39
|
+
toolNames,
|
|
40
|
+
taskList
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
static buildSystemPromptWithCompression(mode, agentInfo, compressionHistory, options) {
|
|
44
|
+
return this.buildSystemPrompt({
|
|
45
|
+
mode,
|
|
46
|
+
agentInfo,
|
|
47
|
+
compressionHistory,
|
|
48
|
+
...options
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
static addCompressionToPrompt(existingPrompt, compressionHistory) {
|
|
52
|
+
if (!compressionHistory || compressionHistory.trim().length === 0) {
|
|
53
|
+
return existingPrompt;
|
|
54
|
+
}
|
|
55
|
+
const compressionSection = [
|
|
56
|
+
'---',
|
|
57
|
+
'',
|
|
58
|
+
'## Context History',
|
|
59
|
+
'',
|
|
60
|
+
compressionHistory.trim()
|
|
61
|
+
].join('\n');
|
|
62
|
+
const additionalInstructionsIndex = existingPrompt.indexOf('## Additional Instructions');
|
|
63
|
+
if (additionalInstructionsIndex > -1) {
|
|
64
|
+
const before = existingPrompt.substring(0, additionalInstructionsIndex);
|
|
65
|
+
const after = existingPrompt.substring(additionalInstructionsIndex);
|
|
66
|
+
return before + compressionSection + '\n\n' + after;
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
return existingPrompt + '\n\n' + compressionSection;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
static removeCompressionFromPrompt(prompt) {
|
|
73
|
+
const compressionSectionStart = prompt.indexOf('## Context History');
|
|
74
|
+
if (compressionSectionStart === -1) {
|
|
75
|
+
return prompt;
|
|
76
|
+
}
|
|
77
|
+
const compressionSectionContent = prompt.substring(compressionSectionStart);
|
|
78
|
+
const nextSectionIndex = compressionSectionContent.indexOf('\n---', 3);
|
|
79
|
+
if (nextSectionIndex > -1) {
|
|
80
|
+
const before = prompt.substring(0, compressionSectionStart);
|
|
81
|
+
const after = compressionSectionContent.substring(nextSectionIndex + 4);
|
|
82
|
+
return before + after;
|
|
83
|
+
}
|
|
84
|
+
else {
|
|
85
|
+
return prompt.substring(0, compressionSectionStart).trim();
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
static hasCompressionContext(prompt) {
|
|
89
|
+
return prompt.includes('## Context History');
|
|
90
|
+
}
|
|
91
|
+
static extractCompressionContext(prompt) {
|
|
92
|
+
const compressionSectionStart = prompt.indexOf('## Context History');
|
|
93
|
+
if (compressionSectionStart === -1) {
|
|
94
|
+
return null;
|
|
95
|
+
}
|
|
96
|
+
const compressionSectionContent = prompt.substring(compressionSectionStart + '## Context History'.length);
|
|
97
|
+
const endOfSectionIndex = compressionSectionContent.indexOf('\n---');
|
|
98
|
+
if (endOfSectionIndex > -1) {
|
|
99
|
+
return compressionSectionContent.substring(1, endOfSectionIndex).trim();
|
|
100
|
+
}
|
|
101
|
+
else {
|
|
102
|
+
return compressionSectionContent.substring(1).trim();
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
static buildDebugPrompt(config) {
|
|
106
|
+
const prompt = this.buildSystemPrompt(config);
|
|
107
|
+
logger_1.logger.debug('[CLIPromptBuilder] Prompt construído:', {
|
|
108
|
+
mode: config.mode,
|
|
109
|
+
hasCompression: !!config.compressionHistory,
|
|
110
|
+
hasAdditionalInstructions: !!config.additionalInstructions,
|
|
111
|
+
hasTools: !!(config.tools || config.toolNames),
|
|
112
|
+
promptLength: prompt.length
|
|
113
|
+
});
|
|
114
|
+
return prompt;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
exports.CLIPromptBuilder = CLIPromptBuilder;
|
|
118
|
+
function createDefaultPromptConfig(mode, agentInfo, additionalInstructions) {
|
|
119
|
+
return {
|
|
120
|
+
mode,
|
|
121
|
+
agentInfo,
|
|
122
|
+
additionalInstructions
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
function createCompressionPromptConfig(mode, agentInfo, compressionHistory, additionalInstructions) {
|
|
126
|
+
return {
|
|
127
|
+
mode,
|
|
128
|
+
agentInfo,
|
|
129
|
+
additionalInstructions,
|
|
130
|
+
compressionHistory
|
|
131
|
+
};
|
|
132
|
+
}
|
|
@@ -0,0 +1,134 @@
|
|
|
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.loadAgentConfig = loadAgentConfig;
|
|
37
|
+
exports.clearConfigCache = clearConfigCache;
|
|
38
|
+
exports.reloadConfig = reloadConfig;
|
|
39
|
+
const fs = __importStar(require("fs"));
|
|
40
|
+
const path = __importStar(require("path"));
|
|
41
|
+
const logger_1 = require("../../infrastructure/logging/logger");
|
|
42
|
+
let configFileCache = null;
|
|
43
|
+
const ENV_VAR_REGEX = /\$\{([^}:]+)(?::-([^}]*))?\}/g;
|
|
44
|
+
function substituteEnvVars(value) {
|
|
45
|
+
if (typeof value !== 'string') {
|
|
46
|
+
return value;
|
|
47
|
+
}
|
|
48
|
+
return value.replace(ENV_VAR_REGEX, (_match, varName, defaultValue) => {
|
|
49
|
+
const envValue = process.env[varName];
|
|
50
|
+
if (envValue !== undefined) {
|
|
51
|
+
return envValue;
|
|
52
|
+
}
|
|
53
|
+
if (defaultValue !== undefined) {
|
|
54
|
+
return defaultValue;
|
|
55
|
+
}
|
|
56
|
+
return '';
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
function toNumberIfPossible(value) {
|
|
60
|
+
if (typeof value === 'string') {
|
|
61
|
+
const trimmed = value.trim();
|
|
62
|
+
if (/^-?\d+\.?\d*$/.test(trimmed)) {
|
|
63
|
+
return parseFloat(trimmed);
|
|
64
|
+
}
|
|
65
|
+
if (trimmed === 'true')
|
|
66
|
+
return true;
|
|
67
|
+
if (trimmed === 'false')
|
|
68
|
+
return false;
|
|
69
|
+
}
|
|
70
|
+
return value;
|
|
71
|
+
}
|
|
72
|
+
function substituteEnvVarsRecursive(config) {
|
|
73
|
+
if (typeof config === 'string') {
|
|
74
|
+
const substituted = substituteEnvVars(config);
|
|
75
|
+
return toNumberIfPossible(substituted);
|
|
76
|
+
}
|
|
77
|
+
if (Array.isArray(config)) {
|
|
78
|
+
return config.map(item => substituteEnvVarsRecursive(item));
|
|
79
|
+
}
|
|
80
|
+
if (config !== null && typeof config === 'object') {
|
|
81
|
+
const result = {};
|
|
82
|
+
for (const [key, value] of Object.entries(config)) {
|
|
83
|
+
result[key] = substituteEnvVarsRecursive(value);
|
|
84
|
+
}
|
|
85
|
+
return result;
|
|
86
|
+
}
|
|
87
|
+
return config;
|
|
88
|
+
}
|
|
89
|
+
function loadConfigFile() {
|
|
90
|
+
if (configFileCache !== null) {
|
|
91
|
+
return configFileCache;
|
|
92
|
+
}
|
|
93
|
+
const configPath = path.join(process.cwd(), '.code', 'config.json');
|
|
94
|
+
if (!fs.existsSync(configPath)) {
|
|
95
|
+
logger_1.logger.debug('[agentConfig] Arquivo .code/config.json não encontrado, usando apenas ENV');
|
|
96
|
+
return null;
|
|
97
|
+
}
|
|
98
|
+
try {
|
|
99
|
+
const content = fs.readFileSync(configPath, 'utf-8');
|
|
100
|
+
const parsed = JSON.parse(content);
|
|
101
|
+
configFileCache = parsed;
|
|
102
|
+
logger_1.logger.debug('[agentConfig] Arquivo .code/config.json carregado com sucesso');
|
|
103
|
+
return parsed;
|
|
104
|
+
}
|
|
105
|
+
catch (error) {
|
|
106
|
+
logger_1.logger.error('[agentConfig] Erro ao carregar .code/config.json:', error);
|
|
107
|
+
return null;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
function loadAgentConfig(agentName) {
|
|
111
|
+
const configFile = loadConfigFile();
|
|
112
|
+
if (!configFile) {
|
|
113
|
+
return {
|
|
114
|
+
fromConfigFile: false
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
const agentSpecific = configFile.agents?.[agentName];
|
|
118
|
+
const merged = {
|
|
119
|
+
...(configFile.defaults || {}),
|
|
120
|
+
...(agentSpecific || {})
|
|
121
|
+
};
|
|
122
|
+
const resolved = substituteEnvVarsRecursive(merged);
|
|
123
|
+
return {
|
|
124
|
+
...resolved,
|
|
125
|
+
fromConfigFile: true
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
function clearConfigCache() {
|
|
129
|
+
configFileCache = null;
|
|
130
|
+
}
|
|
131
|
+
function reloadConfig() {
|
|
132
|
+
clearConfigCache();
|
|
133
|
+
loadConfigFile();
|
|
134
|
+
}
|
|
@@ -0,0 +1,112 @@
|
|
|
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.loadConfig = loadConfig;
|
|
37
|
+
exports.loadConfigSync = loadConfigSync;
|
|
38
|
+
const dotenv = __importStar(require("dotenv"));
|
|
39
|
+
const fs_1 = require("fs");
|
|
40
|
+
const path_1 = require("path");
|
|
41
|
+
let envLoaded = false;
|
|
42
|
+
function ensureEnvLoaded() {
|
|
43
|
+
if (envLoaded)
|
|
44
|
+
return;
|
|
45
|
+
dotenv.config();
|
|
46
|
+
const localEnvPath = (0, path_1.join)(process.cwd(), '.env.local');
|
|
47
|
+
if ((0, fs_1.existsSync)(localEnvPath)) {
|
|
48
|
+
dotenv.config({ path: localEnvPath });
|
|
49
|
+
}
|
|
50
|
+
envLoaded = true;
|
|
51
|
+
}
|
|
52
|
+
async function loadConfig() {
|
|
53
|
+
ensureEnvLoaded();
|
|
54
|
+
return {
|
|
55
|
+
provider: process.env.LLM_PROVIDER || 'openai',
|
|
56
|
+
apiKey: process.env.LLM_API_KEY || '',
|
|
57
|
+
baseURL: process.env.LLM_BASE_URL,
|
|
58
|
+
vision: {
|
|
59
|
+
supportsVision: process.env.LLM_SUPPORTS_VISION === 'true',
|
|
60
|
+
provider: process.env.LLM_VISION_PROVIDER || process.env.LLM_PROVIDER || 'openai',
|
|
61
|
+
apiKey: process.env.LLM_VISION_API_KEY || process.env.LLM_API_KEY || '',
|
|
62
|
+
baseURL: process.env.LLM_VISION_BASE_URL || process.env.LLM_BASE_URL,
|
|
63
|
+
model: process.env.LLM_VISION_MODEL || process.env.LLM_DEFAULT_MODEL
|
|
64
|
+
},
|
|
65
|
+
defaults: {
|
|
66
|
+
model: process.env.LLM_DEFAULT_MODEL || 'gpt-4o-mini',
|
|
67
|
+
maxTokens: parseInt(process.env.LLM_MAX_OUTPUT_TOKENS || '4096'),
|
|
68
|
+
maxContextTokens: parseInt(process.env.LLM_MAX_TOKENS || '128000'),
|
|
69
|
+
temperature: parseFloat(process.env.LLM_TEMPERATURE || '0.7')
|
|
70
|
+
},
|
|
71
|
+
compression: {
|
|
72
|
+
enabled: process.env.COMPRESSION_ENABLED !== 'false',
|
|
73
|
+
threshold: parseFloat(process.env.COMPRESSION_THRESHOLD || '0.8'),
|
|
74
|
+
maxCount: parseInt(process.env.COMPRESSION_MAX_COUNT || '5'),
|
|
75
|
+
maxTokens: parseInt(process.env.COMPRESSION_MAX_TOKENS || '300'),
|
|
76
|
+
model: process.env.COMPRESSION_MODEL,
|
|
77
|
+
logging: process.env.COMPRESSION_LOGGING !== 'false',
|
|
78
|
+
persist: process.env.COMPRESSION_PERSIST !== 'false'
|
|
79
|
+
},
|
|
80
|
+
tools: {
|
|
81
|
+
mcpEnabled: process.env.MCP_TOOLS_ENABLED !== 'false',
|
|
82
|
+
agentMode: process.env.AGENT_MODE === 'autonomous' ? 'autonomous' : 'interactive'
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
function loadConfigSync() {
|
|
87
|
+
ensureEnvLoaded();
|
|
88
|
+
return {
|
|
89
|
+
provider: process.env.LLM_PROVIDER || 'openai',
|
|
90
|
+
apiKey: process.env.LLM_API_KEY || '',
|
|
91
|
+
baseURL: process.env.LLM_BASE_URL,
|
|
92
|
+
defaults: {
|
|
93
|
+
model: process.env.LLM_DEFAULT_MODEL || 'gpt-4o-mini',
|
|
94
|
+
maxTokens: parseInt(process.env.LLM_MAX_OUTPUT_TOKENS || '4096'),
|
|
95
|
+
maxContextTokens: parseInt(process.env.LLM_MAX_TOKENS || '128000'),
|
|
96
|
+
temperature: parseFloat(process.env.LLM_TEMPERATURE || '0.7')
|
|
97
|
+
},
|
|
98
|
+
compression: {
|
|
99
|
+
enabled: process.env.COMPRESSION_ENABLED !== 'false',
|
|
100
|
+
threshold: parseFloat(process.env.COMPRESSION_THRESHOLD || '0.8'),
|
|
101
|
+
maxCount: parseInt(process.env.COMPRESSION_MAX_COUNT || '5'),
|
|
102
|
+
maxTokens: parseInt(process.env.COMPRESSION_MAX_TOKENS || '300'),
|
|
103
|
+
model: process.env.COMPRESSION_MODEL,
|
|
104
|
+
logging: process.env.COMPRESSION_LOGGING !== 'false',
|
|
105
|
+
persist: process.env.COMPRESSION_PERSIST !== 'false'
|
|
106
|
+
},
|
|
107
|
+
tools: {
|
|
108
|
+
mcpEnabled: process.env.MCP_TOOLS_ENABLED !== 'false',
|
|
109
|
+
agentMode: process.env.AGENT_MODE === 'autonomous' ? 'autonomous' : 'interactive'
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.loadConfigSync = exports.loadConfig = void 0;
|
|
4
|
+
var config_1 = require("./config");
|
|
5
|
+
Object.defineProperty(exports, "loadConfig", { enumerable: true, get: function () { return config_1.loadConfig; } });
|
|
6
|
+
Object.defineProperty(exports, "loadConfigSync", { enumerable: true, get: function () { return config_1.loadConfigSync; } });
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.logger = void 0;
|
|
4
|
+
const isDebug = process.env.DEBUG === 'True' || process.env.DEBUG === 'true';
|
|
5
|
+
const isInfo = process.env.INFO === 'True' || process.env.INFO === 'true';
|
|
6
|
+
const shouldShowInfo = isDebug || isInfo;
|
|
7
|
+
const shouldShowDebug = isDebug;
|
|
8
|
+
exports.logger = {
|
|
9
|
+
info: (message, ...args) => {
|
|
10
|
+
if (shouldShowInfo) {
|
|
11
|
+
console.log(`[INFO] ${message}`, ...args);
|
|
12
|
+
if (process.stdout.write)
|
|
13
|
+
process.stdout.write('');
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
warn: (message, ...args) => {
|
|
17
|
+
console.warn(`[WARN] ${message}`, ...args);
|
|
18
|
+
if (process.stdout.write)
|
|
19
|
+
process.stdout.write('');
|
|
20
|
+
},
|
|
21
|
+
error: (message, ...args) => {
|
|
22
|
+
console.error(`[ERROR] ${message}`, ...args);
|
|
23
|
+
if (process.stderr.write)
|
|
24
|
+
process.stderr.write('');
|
|
25
|
+
},
|
|
26
|
+
debug: (message, ...args) => {
|
|
27
|
+
if (shouldShowDebug) {
|
|
28
|
+
console.log(`[DEBUG] ${message}`, ...args);
|
|
29
|
+
if (process.stdout.write)
|
|
30
|
+
process.stdout.write('');
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isRawLlmOutputEnabled = isRawLlmOutputEnabled;
|
|
4
|
+
exports.logRawLlmOutput = logRawLlmOutput;
|
|
5
|
+
exports.instrumentGraphForRawLlmOutput = instrumentGraphForRawLlmOutput;
|
|
6
|
+
function envTruthy(value) {
|
|
7
|
+
if (!value)
|
|
8
|
+
return false;
|
|
9
|
+
const normalized = value.trim().toLowerCase();
|
|
10
|
+
return normalized === '1' || normalized === 'true' || normalized === 'yes' || normalized === 'on';
|
|
11
|
+
}
|
|
12
|
+
function isRawLlmOutputEnabled() {
|
|
13
|
+
return envTruthy(process.env.DEBUG_LLM_RAW_OUTPUT) || envTruthy(process.env.DEBUG_LLM_RAW);
|
|
14
|
+
}
|
|
15
|
+
function logRawLlmOutput(agentLabel, output) {
|
|
16
|
+
const header = `[LLM_RAW][${agentLabel}] (${output.length} chars)`;
|
|
17
|
+
console.log(`\n${header}\n${output}\n`);
|
|
18
|
+
}
|
|
19
|
+
function instrumentGraphForRawLlmOutput(graph, agentLabel) {
|
|
20
|
+
if (!isRawLlmOutputEnabled())
|
|
21
|
+
return graph;
|
|
22
|
+
const nodeId = 'agent';
|
|
23
|
+
const original = graph.nodes?.[nodeId];
|
|
24
|
+
if (!original)
|
|
25
|
+
return graph;
|
|
26
|
+
graph.nodes[nodeId] = async (state, engine) => {
|
|
27
|
+
const result = await original(state, engine);
|
|
28
|
+
const output = result?.lastModelOutput;
|
|
29
|
+
if (typeof output === 'string' && output.length > 0) {
|
|
30
|
+
logRawLlmOutput(agentLabel, output);
|
|
31
|
+
}
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
return graph;
|
|
35
|
+
}
|
|
@@ -0,0 +1,104 @@
|
|
|
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.SkillLoader = void 0;
|
|
37
|
+
const fs = __importStar(require("fs"));
|
|
38
|
+
const path = __importStar(require("path"));
|
|
39
|
+
class SkillLoader {
|
|
40
|
+
constructor(skillsDir) {
|
|
41
|
+
this.skillsDir = skillsDir || path.join(process.cwd(), '.code');
|
|
42
|
+
}
|
|
43
|
+
parseSkillFile(filePath) {
|
|
44
|
+
try {
|
|
45
|
+
const content = fs.readFileSync(filePath, 'utf-8');
|
|
46
|
+
const lines = content.split('\n');
|
|
47
|
+
if (lines[0].trim() !== '---')
|
|
48
|
+
return null;
|
|
49
|
+
const frontmatter = {};
|
|
50
|
+
let i = 1;
|
|
51
|
+
for (; i < lines.length; i++) {
|
|
52
|
+
if (lines[i].trim() === '---')
|
|
53
|
+
break;
|
|
54
|
+
const [key, ...valueParts] = lines[i].split(':');
|
|
55
|
+
if (key && valueParts.length > 0) {
|
|
56
|
+
const value = valueParts.join(':').trim();
|
|
57
|
+
const cleanValue = value.replace(/^['"]|['"]$/g, '');
|
|
58
|
+
if (value.startsWith('[') && value.endsWith(']')) {
|
|
59
|
+
frontmatter[key.trim()] = value.slice(1, -1).split(',').map(s => s.trim().replace(/^['"]|['"]$/g, ''));
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
frontmatter[key.trim()] = cleanValue;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
if (!frontmatter.name)
|
|
67
|
+
return null;
|
|
68
|
+
return {
|
|
69
|
+
name: frontmatter.name,
|
|
70
|
+
description: frontmatter.description || '',
|
|
71
|
+
keywords: frontmatter.keywords || [],
|
|
72
|
+
path: filePath.replace(/\\/g, '/')
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
catch (e) {
|
|
76
|
+
console.error(`Erro ao ler skill ${filePath}:`, e);
|
|
77
|
+
return null;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
loadAllSkills() {
|
|
81
|
+
const skills = [];
|
|
82
|
+
if (!fs.existsSync(this.skillsDir))
|
|
83
|
+
return skills;
|
|
84
|
+
const entries = fs.readdirSync(this.skillsDir, { withFileTypes: true });
|
|
85
|
+
for (const entry of entries) {
|
|
86
|
+
if (entry.isDirectory()) {
|
|
87
|
+
const skillPath = path.join(this.skillsDir, entry.name, 'SKILL.md');
|
|
88
|
+
if (fs.existsSync(skillPath)) {
|
|
89
|
+
const skill = this.parseSkillFile(skillPath);
|
|
90
|
+
if (skill)
|
|
91
|
+
skills.push(skill);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
else if (entry.name.endsWith('.md')) {
|
|
95
|
+
const skillPath = path.join(this.skillsDir, entry.name);
|
|
96
|
+
const skill = this.parseSkillFile(skillPath);
|
|
97
|
+
if (skill)
|
|
98
|
+
skills.push(skill);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
return skills;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
exports.SkillLoader = SkillLoader;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.formatTraceEventForTerminal = exports.ConsoleTraceSink = exports.createCliTelemetry = void 0;
|
|
4
|
+
var telemetryConfig_1 = require("./telemetryConfig");
|
|
5
|
+
Object.defineProperty(exports, "createCliTelemetry", { enumerable: true, get: function () { return telemetryConfig_1.createCliTelemetry; } });
|
|
6
|
+
var traceSinkConsole_1 = require("./traceSinkConsole");
|
|
7
|
+
Object.defineProperty(exports, "ConsoleTraceSink", { enumerable: true, get: function () { return traceSinkConsole_1.ConsoleTraceSink; } });
|
|
8
|
+
var traceEventFormatter_1 = require("./traceEventFormatter");
|
|
9
|
+
Object.defineProperty(exports, "formatTraceEventForTerminal", { enumerable: true, get: function () { return traceEventFormatter_1.formatTraceEventForTerminal; } });
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createCliTelemetry = createCliTelemetry;
|
|
4
|
+
const frame_agent_sdk_1 = require("@ericnunes/frame-agent-sdk");
|
|
5
|
+
const traceSinkConsole_1 = require("./traceSinkConsole");
|
|
6
|
+
function readBool(value, defaultValue) {
|
|
7
|
+
if (value == null)
|
|
8
|
+
return defaultValue;
|
|
9
|
+
if (value === '1')
|
|
10
|
+
return true;
|
|
11
|
+
if (value === '0')
|
|
12
|
+
return false;
|
|
13
|
+
return value.toLowerCase() === 'true';
|
|
14
|
+
}
|
|
15
|
+
function createCliTelemetry() {
|
|
16
|
+
const enabled = readBool(process.env.TELEMETRY_ENABLED, true);
|
|
17
|
+
const verbose = readBool(process.env.TELEMETRY_VERBOSE, readBool(process.env.DEBUG, false));
|
|
18
|
+
const level = (process.env.TELEMETRY_LEVEL ?? (verbose ? 'debug' : 'info'));
|
|
19
|
+
const telemetry = {
|
|
20
|
+
enabled,
|
|
21
|
+
level,
|
|
22
|
+
persistToState: false,
|
|
23
|
+
includePrompts: false,
|
|
24
|
+
maxPayloadChars: 4000,
|
|
25
|
+
maxEvents: 200,
|
|
26
|
+
};
|
|
27
|
+
const consoleSink = new traceSinkConsole_1.ConsoleTraceSink({ verbose });
|
|
28
|
+
const trace = new frame_agent_sdk_1.MultiplexTraceSink([consoleSink]);
|
|
29
|
+
return { trace, telemetry, verbose };
|
|
30
|
+
}
|