@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.
Files changed (82) hide show
  1. package/LICENSE +139 -0
  2. package/README.md +196 -0
  3. package/dist/agent-runtime/AgentFacade.js +33 -0
  4. package/dist/agent-runtime/context/hooks/compressionHook.js +56 -0
  5. package/dist/agent-runtime/context/hooks/index.js +5 -0
  6. package/dist/agent-runtime/context/project-rules/loader.js +72 -0
  7. package/dist/agent-runtime/context/system-prompts/index.js +5 -0
  8. package/dist/agent-runtime/context/system-prompts/loader.js +88 -0
  9. package/dist/agent-runtime/flows/templates/ReactAgentFlow.js +49 -0
  10. package/dist/agent-runtime/index.js +18 -0
  11. package/dist/agent-runtime/registry/AgentRegistry.js +93 -0
  12. package/dist/agent-runtime/registry/agentParser.js +515 -0
  13. package/dist/agent-runtime/registry/enums/agentType.enum.js +8 -0
  14. package/dist/agent-runtime/registry/index.js +20 -0
  15. package/dist/agent-runtime/registry/initialization.js +53 -0
  16. package/dist/agent-runtime/registry/interfaces/agentDependencies.interface.js +2 -0
  17. package/dist/agent-runtime/registry/interfaces/agentMetadata.interface.js +2 -0
  18. package/dist/agent-runtime/registry/interfaces/agentRegistry.interface.js +2 -0
  19. package/dist/app/bootstrap.js +22 -0
  20. package/dist/app/cli.js +31 -0
  21. package/dist/app/index.js +9 -0
  22. package/dist/cli/commands/autonomous.js +181 -0
  23. package/dist/cli/commands/index.js +11 -0
  24. package/dist/cli/commands/interactive.js +172 -0
  25. package/dist/cli/commands/memory.js +149 -0
  26. package/dist/cli/commands/multi-agent.js +131 -0
  27. package/dist/cli/index.js +18 -0
  28. package/dist/cli/input/images/attachments.js +173 -0
  29. package/dist/cli/input/images/imageInput.js +77 -0
  30. package/dist/cli/input/images/readImageAttachment.js +56 -0
  31. package/dist/cli/input/index.js +14 -0
  32. package/dist/cli/input/reader.js +26 -0
  33. package/dist/content/agents/README.md +324 -0
  34. package/dist/content/agents/architect.md +95 -0
  35. package/dist/content/agents/builder.md +85 -0
  36. package/dist/content/agents/code-agent.md +123 -0
  37. package/dist/content/agents/supervisor.md +63 -0
  38. package/dist/index.js +25 -0
  39. package/dist/infrastructure/compression/CompressionManager.js +315 -0
  40. package/dist/infrastructure/compression/LLMCompressionService.js +211 -0
  41. package/dist/infrastructure/compression/index.js +11 -0
  42. package/dist/infrastructure/compression/promptBuilder.js +132 -0
  43. package/dist/infrastructure/config/agentConfig.interface.js +2 -0
  44. package/dist/infrastructure/config/agentConfig.js +134 -0
  45. package/dist/infrastructure/config/config.interface.js +2 -0
  46. package/dist/infrastructure/config/config.js +112 -0
  47. package/dist/infrastructure/config/index.js +6 -0
  48. package/dist/infrastructure/logging/index.js +5 -0
  49. package/dist/infrastructure/logging/logger.interface.js +2 -0
  50. package/dist/infrastructure/logging/logger.js +33 -0
  51. package/dist/infrastructure/logging/raw-output-logger.js +35 -0
  52. package/dist/infrastructure/skills/index.js +5 -0
  53. package/dist/infrastructure/skills/loader.js +104 -0
  54. package/dist/infrastructure/telemetry/index.js +9 -0
  55. package/dist/infrastructure/telemetry/telemetry.interface.js +2 -0
  56. package/dist/infrastructure/telemetry/telemetryConfig.js +30 -0
  57. package/dist/infrastructure/telemetry/traceEventFormatter.js +90 -0
  58. package/dist/infrastructure/telemetry/traceSinkConsole.js +17 -0
  59. package/dist/scripts/_validate/telemetry-autonomous.js +23 -0
  60. package/dist/scripts/_validate/telemetry-multi-agent.js +50 -0
  61. package/dist/scripts/_validate/test-agents-md-dynamic-dir.js +104 -0
  62. package/dist/scripts/_validate/test-agents-md-injection.js +125 -0
  63. package/dist/scripts/_validate/test-agents-md-loader.js +71 -0
  64. package/dist/scripts/_validate/test-agents-md-priority.js +121 -0
  65. package/dist/scripts/_validate/test-chrome-mcp-agent.js +89 -0
  66. package/dist/tools/index.js +19 -0
  67. package/dist/tools/mcp/discoverer.js +95 -0
  68. package/dist/tools/mcp/index.js +9 -0
  69. package/dist/tools/mcp/loader.js +36 -0
  70. package/dist/tools/mcp/mcpConfig.interface.js +2 -0
  71. package/dist/tools/mcp/mcpMetadata.js +2 -0
  72. package/dist/tools/mcp/register.js +269 -0
  73. package/dist/tools/native/capabilities.js +155 -0
  74. package/dist/tools/native/file-outline.js +301 -0
  75. package/dist/tools/native/index.js +20 -0
  76. package/dist/tools/native/list-directory.js +148 -0
  77. package/dist/tools/native/read-image.js +140 -0
  78. package/dist/tools/registry/ToolInitializer.js +62 -0
  79. package/dist/tools/registry/index.js +11 -0
  80. package/dist/tools/registry/toolFilter.js +52 -0
  81. package/dist/tools/registry/toolRegistry.interface.js +2 -0
  82. package/package.json +81 -0
@@ -0,0 +1,131 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.processMultiAgentInput = processMultiAgentInput;
4
+ exports.createMultiAgentCommand = createMultiAgentCommand;
5
+ const commander_1 = require("commander");
6
+ const fs_1 = require("fs");
7
+ const logger_1 = require("../../infrastructure/logging/logger");
8
+ const frame_agent_sdk_1 = require("@ericnunes/frame-agent-sdk");
9
+ const tools_1 = require("../../tools");
10
+ const config_1 = require("../../infrastructure/config");
11
+ const registry_1 = require("../../agent-runtime/registry");
12
+ const reader_1 = require("../input/reader");
13
+ const telemetry_1 = require("../../infrastructure/telemetry");
14
+ const attachments_1 = require("../input/images/attachments");
15
+ async function processMultiAgentInput(input, options) {
16
+ try {
17
+ logger_1.logger.info('[MultiAgent] Starting multi-agent execution');
18
+ const normalizedInput = input.trim();
19
+ const isPlaceholder = normalizedInput.length === 0;
20
+ if (isPlaceholder) {
21
+ logger_1.logger.warn('[MultiAgent] Empty input detected, using default task');
22
+ input = 'Explique como usar o frame-code-cli com base no codigo atual. Nao modifique arquivos e nao use ferramentas.';
23
+ }
24
+ if (options.verbose) {
25
+ logger_1.logger.info(`[MultiAgent] Input received: ${input.substring(0, 200)}...`);
26
+ }
27
+ await (0, config_1.loadConfig)();
28
+ const { trace, telemetry } = (0, telemetry_1.createCliTelemetry)();
29
+ const registry = registry_1.AgentRegistry.getInstance();
30
+ const previousMode = process.env.AGENT_MODE;
31
+ process.env.AGENT_MODE = 'autonomous';
32
+ await (0, tools_1.initializeTools)({ allowAskUser: true });
33
+ if (previousMode !== undefined) {
34
+ process.env.AGENT_MODE = previousMode;
35
+ }
36
+ const graph = await registry.createEngine('supervisor', {
37
+ trace,
38
+ telemetry
39
+ });
40
+ const imagePaths = options._imagePaths ?? [];
41
+ const imageDetail = options.imageDetail ?? 'auto';
42
+ const initialState = {
43
+ messages: [],
44
+ data: {
45
+ input,
46
+ shared: {
47
+ ...(imagePaths.length ? { imagePaths, imageDetail } : {})
48
+ },
49
+ ...(options._runId ? { runId: options._runId } : {})
50
+ },
51
+ status: frame_agent_sdk_1.GraphStatus.RUNNING
52
+ };
53
+ const result = await graph.execute(initialState);
54
+ if (result.status === frame_agent_sdk_1.GraphStatus.ERROR) {
55
+ throw new Error(`Execution error: ${result.state.logs?.join('\n') || 'Unknown error'}`);
56
+ }
57
+ if (result.status !== frame_agent_sdk_1.GraphStatus.FINISHED) {
58
+ return `Execution finished with status: ${result.status}`;
59
+ }
60
+ const shared = result.state.data?.shared;
61
+ const output = shared?.output;
62
+ if (typeof output === 'string' && output.trim().length > 0) {
63
+ return `[supervisor] ${output}`;
64
+ }
65
+ return '[supervisor] Execution finished without captured output';
66
+ }
67
+ catch (error) {
68
+ logger_1.logger.error('[MultiAgent] Execution failed:', error);
69
+ throw error;
70
+ }
71
+ }
72
+ function createMultiAgentCommand() {
73
+ const command = new commander_1.Command('multi-agent');
74
+ const collect = (value, previous) => {
75
+ return [...(previous ?? []), value];
76
+ };
77
+ command
78
+ .description('Run multi-agent planner + implementer flow')
79
+ .argument('[additional-input]', 'Additional text with priority over input file')
80
+ .option('-i, --input-file <file>', 'Input file with prompt')
81
+ .option('-o, --output-file <file>', 'Output file for response')
82
+ .option('-l, --log-file <file>', 'Log file for details')
83
+ .option('-v, --verbose', 'Verbose mode')
84
+ .option('--image <path>', 'Caminho de imagem local (pode repetir)', collect, [])
85
+ .option('--image-detail <low|high|auto>', 'Nivel de detalhe para imagem (low|high|auto)', 'auto')
86
+ .action(async (additionalInput, options) => {
87
+ try {
88
+ if (options.inputFile) {
89
+ logger_1.logger.info(`[MultiAgent] Reading input from: ${options.inputFile}`);
90
+ }
91
+ if (additionalInput) {
92
+ logger_1.logger.info(`[MultiAgent] Adding input: ${additionalInput.substring(0, 100)}...`);
93
+ }
94
+ if (!options.inputFile && !additionalInput) {
95
+ logger_1.logger.info('[MultiAgent] Reading input from stdin');
96
+ }
97
+ const input = await (0, reader_1.readCliInput)({ inputFile: options.inputFile, additionalInput });
98
+ if (options.image && options.image.length > 0) {
99
+ await (0, attachments_1.cleanupAttachmentsRoot)((0, attachments_1.getAttachmentsCleanupConfigFromEnv)());
100
+ const staged = await (0, attachments_1.stageImageAttachments)({ imagePaths: options.image });
101
+ options._runId = staged.runId;
102
+ options._imagePaths = staged.stagedPaths;
103
+ }
104
+ const result = await processMultiAgentInput(input, options);
105
+ if (options.outputFile) {
106
+ logger_1.logger.info(`[MultiAgent] Writing output to: ${options.outputFile}`);
107
+ (0, fs_1.writeFileSync)(options.outputFile, result, 'utf-8');
108
+ }
109
+ else {
110
+ console.log(result);
111
+ }
112
+ if (options.logFile) {
113
+ (0, fs_1.writeFileSync)(options.logFile, 'Detailed logs not implemented', 'utf-8');
114
+ }
115
+ logger_1.logger.info('[MultiAgent] Execution completed');
116
+ process.exit(0);
117
+ }
118
+ catch (error) {
119
+ logger_1.logger.error('[MultiAgent] Fatal error:', error);
120
+ const errorMessage = error instanceof Error ? error.message : 'Unknown error';
121
+ if (options.outputFile) {
122
+ (0, fs_1.writeFileSync)(options.outputFile, `## Error\n\n${errorMessage}`, 'utf-8');
123
+ }
124
+ else {
125
+ console.error('Error:', errorMessage);
126
+ }
127
+ process.exit(1);
128
+ }
129
+ });
130
+ return command;
131
+ }
@@ -0,0 +1,18 @@
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./commands"), exports);
18
+ __exportStar(require("./input"), exports);
@@ -0,0 +1,173 @@
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.createRunId = createRunId;
37
+ exports.getAttachmentsRoot = getAttachmentsRoot;
38
+ exports.getAttachmentsCleanupConfigFromEnv = getAttachmentsCleanupConfigFromEnv;
39
+ exports.cleanupAttachmentsRoot = cleanupAttachmentsRoot;
40
+ exports.stageImageAttachments = stageImageAttachments;
41
+ const fs_1 = require("fs");
42
+ const path = __importStar(require("path"));
43
+ const crypto_1 = require("crypto");
44
+ function createRunId(now = new Date()) {
45
+ const pad = (n) => String(n).padStart(2, '0');
46
+ const ts = `${now.getFullYear()}${pad(now.getMonth() + 1)}${pad(now.getDate())}-${pad(now.getHours())}${pad(now.getMinutes())}${pad(now.getSeconds())}`;
47
+ const pid = process.pid;
48
+ const rand = (0, crypto_1.randomBytes)(3).toString('hex');
49
+ return `${ts}-${pid}-${rand}`;
50
+ }
51
+ function getAttachmentsRoot() {
52
+ return path.resolve(process.cwd(), 'tmp', 'attachments');
53
+ }
54
+ function parseNumberEnv(name) {
55
+ const raw = process.env[name];
56
+ if (!raw)
57
+ return undefined;
58
+ const parsed = Number(raw);
59
+ return Number.isFinite(parsed) ? parsed : undefined;
60
+ }
61
+ function getAttachmentsCleanupConfigFromEnv() {
62
+ return {
63
+ retentionDays: parseNumberEnv('ATTACHMENTS_RETENTION_DAYS') ?? 7,
64
+ maxTotalMB: parseNumberEnv('ATTACHMENTS_MAX_TOTAL_MB') ?? 500,
65
+ };
66
+ }
67
+ async function safeRm(targetPath) {
68
+ try {
69
+ await fs_1.promises.rm(targetPath, { recursive: true, force: true });
70
+ }
71
+ catch {
72
+ }
73
+ }
74
+ async function cleanupAttachmentsRoot(config) {
75
+ const root = getAttachmentsRoot();
76
+ const retentionDays = config?.retentionDays ?? 7;
77
+ const maxTotalMB = config?.maxTotalMB ?? 500;
78
+ let entries;
79
+ try {
80
+ entries = await fs_1.promises.readdir(root, { withFileTypes: true });
81
+ }
82
+ catch {
83
+ return;
84
+ }
85
+ const now = Date.now();
86
+ const cutoffMs = retentionDays * 24 * 60 * 60 * 1000;
87
+ const dirs = [];
88
+ for (const entry of entries) {
89
+ if (!entry.isDirectory())
90
+ continue;
91
+ const fullPath = path.join(root, entry.name);
92
+ try {
93
+ const stat = await fs_1.promises.stat(fullPath);
94
+ const sizeBytes = await folderSizeBytes(fullPath);
95
+ dirs.push({ fullPath, name: entry.name, mtimeMs: stat.mtimeMs, sizeBytes });
96
+ }
97
+ catch {
98
+ }
99
+ }
100
+ for (const dir of dirs) {
101
+ if (now - dir.mtimeMs > cutoffMs) {
102
+ await safeRm(dir.fullPath);
103
+ }
104
+ }
105
+ const remaining = [];
106
+ let total = 0;
107
+ for (const dir of dirs) {
108
+ try {
109
+ const stat = await fs_1.promises.stat(dir.fullPath);
110
+ const sizeBytes = await folderSizeBytes(dir.fullPath);
111
+ remaining.push({ fullPath: dir.fullPath, mtimeMs: stat.mtimeMs, sizeBytes });
112
+ total += sizeBytes;
113
+ }
114
+ catch {
115
+ }
116
+ }
117
+ const maxBytes = maxTotalMB * 1024 * 1024;
118
+ if (total <= maxBytes)
119
+ return;
120
+ remaining.sort((a, b) => a.mtimeMs - b.mtimeMs);
121
+ for (const dir of remaining) {
122
+ if (total <= maxBytes)
123
+ break;
124
+ await safeRm(dir.fullPath);
125
+ total -= dir.sizeBytes;
126
+ }
127
+ }
128
+ async function folderSizeBytes(root) {
129
+ let total = 0;
130
+ const stack = [root];
131
+ while (stack.length > 0) {
132
+ const current = stack.pop();
133
+ if (!current)
134
+ break;
135
+ let dirents;
136
+ try {
137
+ dirents = await fs_1.promises.readdir(current, { withFileTypes: true });
138
+ }
139
+ catch {
140
+ continue;
141
+ }
142
+ for (const dirent of dirents) {
143
+ const fullPath = path.join(current, dirent.name);
144
+ if (dirent.isDirectory()) {
145
+ stack.push(fullPath);
146
+ }
147
+ else if (dirent.isFile()) {
148
+ try {
149
+ const stat = await fs_1.promises.stat(fullPath);
150
+ total += stat.size;
151
+ }
152
+ catch {
153
+ }
154
+ }
155
+ }
156
+ }
157
+ return total;
158
+ }
159
+ async function stageImageAttachments(options) {
160
+ const runId = options.runId ?? createRunId();
161
+ const root = getAttachmentsRoot();
162
+ const runDir = path.join(root, runId);
163
+ await fs_1.promises.mkdir(runDir, { recursive: true });
164
+ const stagedPaths = [];
165
+ for (const imgPath of options.imagePaths) {
166
+ const absolute = path.isAbsolute(imgPath) ? imgPath : path.resolve(process.cwd(), imgPath);
167
+ const base = path.basename(absolute);
168
+ const target = path.join(runDir, base);
169
+ await fs_1.promises.copyFile(absolute, target);
170
+ stagedPaths.push(target);
171
+ }
172
+ return { runId, stagedPaths };
173
+ }
@@ -0,0 +1,77 @@
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.readFileAsDataUrl = readFileAsDataUrl;
37
+ exports.buildMultimodalContent = buildMultimodalContent;
38
+ const fs_1 = require("fs");
39
+ const path = __importStar(require("path"));
40
+ const crypto_1 = require("crypto");
41
+ function inferMimeType(filePath) {
42
+ const ext = path.extname(filePath).toLowerCase();
43
+ switch (ext) {
44
+ case '.png':
45
+ return 'image/png';
46
+ case '.jpg':
47
+ case '.jpeg':
48
+ return 'image/jpeg';
49
+ case '.webp':
50
+ return 'image/webp';
51
+ case '.gif':
52
+ return 'image/gif';
53
+ case '.bmp':
54
+ return 'image/bmp';
55
+ default:
56
+ return 'application/octet-stream';
57
+ }
58
+ }
59
+ async function readFileAsDataUrl(absolutePath) {
60
+ const buffer = await fs_1.promises.readFile(absolutePath);
61
+ const mimeType = inferMimeType(absolutePath);
62
+ const hash = (0, crypto_1.createHash)('sha256').update(buffer).digest('hex');
63
+ const base64 = buffer.toString('base64');
64
+ return {
65
+ url: `data:${mimeType};base64,${base64}`,
66
+ mimeType,
67
+ bytes: buffer.length,
68
+ hash,
69
+ };
70
+ }
71
+ function buildMultimodalContent(options) {
72
+ const detail = options.detail ?? 'auto';
73
+ return [
74
+ { type: 'text', text: options.text },
75
+ { type: 'image_url', image_url: { url: options.dataUrl, detail } },
76
+ ];
77
+ }
@@ -0,0 +1,56 @@
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.maybeAttachReadImageToContext = maybeAttachReadImageToContext;
37
+ const path = __importStar(require("path"));
38
+ const imageInput_1 = require("./imageInput");
39
+ async function maybeAttachReadImageToContext(options) {
40
+ const metadataObj = (options.metadata ?? {});
41
+ const readImage = (metadataObj.readImage ?? null);
42
+ const imagePath = readImage?.path?.trim();
43
+ if (!imagePath)
44
+ return false;
45
+ const dataUrl = await (0, imageInput_1.readFileAsDataUrl)(imagePath);
46
+ const detail = readImage?.detail ?? 'auto';
47
+ const shortName = path.basename(imagePath);
48
+ const prefix = options.textPrefix?.trim() || 'Imagem anexada (use-a para tomar decisōes no próximo passo).';
49
+ const text = `${prefix}\nArquivo: ${shortName}`;
50
+ const contentParts = (0, imageInput_1.buildMultimodalContent)({ text, dataUrl: dataUrl.url, detail });
51
+ options.engine.addMessage({
52
+ role: 'user',
53
+ content: contentParts,
54
+ });
55
+ return true;
56
+ }
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.maybeAttachReadImageToContext = exports.buildMultimodalContent = exports.readFileAsDataUrl = exports.getAttachmentsCleanupConfigFromEnv = exports.stageImageAttachments = exports.cleanupAttachmentsRoot = exports.readCliInput = void 0;
4
+ var reader_1 = require("./reader");
5
+ Object.defineProperty(exports, "readCliInput", { enumerable: true, get: function () { return reader_1.readCliInput; } });
6
+ var attachments_1 = require("./images/attachments");
7
+ Object.defineProperty(exports, "cleanupAttachmentsRoot", { enumerable: true, get: function () { return attachments_1.cleanupAttachmentsRoot; } });
8
+ Object.defineProperty(exports, "stageImageAttachments", { enumerable: true, get: function () { return attachments_1.stageImageAttachments; } });
9
+ Object.defineProperty(exports, "getAttachmentsCleanupConfigFromEnv", { enumerable: true, get: function () { return attachments_1.getAttachmentsCleanupConfigFromEnv; } });
10
+ var imageInput_1 = require("./images/imageInput");
11
+ Object.defineProperty(exports, "readFileAsDataUrl", { enumerable: true, get: function () { return imageInput_1.readFileAsDataUrl; } });
12
+ Object.defineProperty(exports, "buildMultimodalContent", { enumerable: true, get: function () { return imageInput_1.buildMultimodalContent; } });
13
+ var readImageAttachment_1 = require("./images/readImageAttachment");
14
+ Object.defineProperty(exports, "maybeAttachReadImageToContext", { enumerable: true, get: function () { return readImageAttachment_1.maybeAttachReadImageToContext; } });
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.readCliInput = readCliInput;
4
+ const fs_1 = require("fs");
5
+ async function readStdinUtf8() {
6
+ const chunks = [];
7
+ process.stdin.setEncoding('utf8');
8
+ process.stdin.on('data', (chunk) => chunks.push(Buffer.from(chunk)));
9
+ await new Promise((resolve) => {
10
+ process.stdin.on('end', () => resolve());
11
+ });
12
+ return Buffer.concat(chunks).toString('utf-8');
13
+ }
14
+ async function readCliInput(options) {
15
+ let input = '';
16
+ if (options.inputFile) {
17
+ input = (0, fs_1.readFileSync)(options.inputFile, 'utf-8');
18
+ }
19
+ if (options.additionalInput) {
20
+ input = input ? `${input}\n\n${options.additionalInput}` : options.additionalInput;
21
+ }
22
+ if (!input) {
23
+ input = await readStdinUtf8();
24
+ }
25
+ return input;
26
+ }