protoagent 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 +21 -0
- package/README.md +39 -0
- package/dist/agentic-loop.js +277 -0
- package/dist/config/client.js +166 -0
- package/dist/config/commands.js +208 -0
- package/dist/config/manager.js +117 -0
- package/dist/config/mcp-commands.js +266 -0
- package/dist/config/mcp-manager.js +240 -0
- package/dist/config/mcp-types.js +28 -0
- package/dist/config/providers.js +170 -0
- package/dist/config/setup.js +175 -0
- package/dist/config/system-prompt.js +301 -0
- package/dist/config/types.js +4 -0
- package/dist/index.js +156 -0
- package/dist/tools/create-directory.js +76 -0
- package/dist/tools/directory-operations.js +195 -0
- package/dist/tools/edit-file.js +144 -0
- package/dist/tools/file-operations.js +211 -0
- package/dist/tools/index.js +95 -0
- package/dist/tools/list-directory.js +84 -0
- package/dist/tools/read-file.js +111 -0
- package/dist/tools/run-shell-command.js +340 -0
- package/dist/tools/search-files.js +177 -0
- package/dist/tools/search-operations.js +179 -0
- package/dist/tools/shell-operations.js +342 -0
- package/dist/tools/todo.js +177 -0
- package/dist/tools/view-directory-tree.js +125 -0
- package/dist/tools/write-file.js +136 -0
- package/dist/tools.js +2 -0
- package/dist/utils/conversation-compactor.js +139 -0
- package/dist/utils/cost-tracker.js +106 -0
- package/dist/utils/file-operations-approval.js +163 -0
- package/dist/utils/logger.js +149 -0
- package/package.json +61 -0
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Configurable logging utility for ProtoAgent
|
|
3
|
+
*/
|
|
4
|
+
export var LogLevel;
|
|
5
|
+
(function (LogLevel) {
|
|
6
|
+
LogLevel[LogLevel["ERROR"] = 0] = "ERROR";
|
|
7
|
+
LogLevel[LogLevel["WARN"] = 1] = "WARN";
|
|
8
|
+
LogLevel[LogLevel["INFO"] = 2] = "INFO";
|
|
9
|
+
LogLevel[LogLevel["DEBUG"] = 3] = "DEBUG";
|
|
10
|
+
LogLevel[LogLevel["TRACE"] = 4] = "TRACE";
|
|
11
|
+
})(LogLevel || (LogLevel = {}));
|
|
12
|
+
class Logger {
|
|
13
|
+
constructor() {
|
|
14
|
+
this.level = LogLevel.INFO;
|
|
15
|
+
this.timestamps = true;
|
|
16
|
+
this.colors = true;
|
|
17
|
+
}
|
|
18
|
+
setLevel(level) {
|
|
19
|
+
this.level = level;
|
|
20
|
+
this.debug(`🔍 Log level set to: ${LogLevel[level]}`);
|
|
21
|
+
}
|
|
22
|
+
getLevel() {
|
|
23
|
+
return this.level;
|
|
24
|
+
}
|
|
25
|
+
setTimestamps(enabled) {
|
|
26
|
+
this.timestamps = enabled;
|
|
27
|
+
}
|
|
28
|
+
setColors(enabled) {
|
|
29
|
+
this.colors = enabled;
|
|
30
|
+
}
|
|
31
|
+
formatMessage(level, message, context) {
|
|
32
|
+
let formatted = message;
|
|
33
|
+
if (this.timestamps) {
|
|
34
|
+
const timestamp = new Date().toISOString().slice(11, 23); // HH:MM:SS.mmm
|
|
35
|
+
formatted = `[${timestamp}] ${formatted}`;
|
|
36
|
+
}
|
|
37
|
+
if (context) {
|
|
38
|
+
const contextParts = [];
|
|
39
|
+
if (context.component)
|
|
40
|
+
contextParts.push(`${context.component}`);
|
|
41
|
+
if (context.operation)
|
|
42
|
+
contextParts.push(`${context.operation}`);
|
|
43
|
+
if (context.duration !== undefined)
|
|
44
|
+
contextParts.push(`${context.duration}ms`);
|
|
45
|
+
if (context.tokens !== undefined)
|
|
46
|
+
contextParts.push(`${context.tokens} tokens`);
|
|
47
|
+
if (context.cost !== undefined)
|
|
48
|
+
contextParts.push(`$${context.cost.toFixed(6)}`);
|
|
49
|
+
// Add any other context properties
|
|
50
|
+
Object.keys(context).forEach(key => {
|
|
51
|
+
if (!['component', 'operation', 'duration', 'tokens', 'cost'].includes(key)) {
|
|
52
|
+
contextParts.push(`${key}=${context[key]}`);
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
if (contextParts.length > 0) {
|
|
56
|
+
formatted += ` [${contextParts.join(', ')}]`;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
return formatted;
|
|
60
|
+
}
|
|
61
|
+
error(message, context, ...args) {
|
|
62
|
+
if (this.level >= LogLevel.ERROR) {
|
|
63
|
+
const formatted = this.formatMessage('ERROR', message, context);
|
|
64
|
+
console.error(this.colors ? `\x1b[31m${formatted}\x1b[0m` : formatted, ...args);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
warn(message, context, ...args) {
|
|
68
|
+
if (this.level >= LogLevel.WARN) {
|
|
69
|
+
const formatted = this.formatMessage('WARN', message, context);
|
|
70
|
+
console.warn(this.colors ? `\x1b[33m${formatted}\x1b[0m` : formatted, ...args);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
info(message, context, ...args) {
|
|
74
|
+
if (this.level >= LogLevel.INFO) {
|
|
75
|
+
const formatted = this.formatMessage('INFO', message, context);
|
|
76
|
+
console.log(formatted, ...args);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
debug(message, context, ...args) {
|
|
80
|
+
if (this.level >= LogLevel.DEBUG) {
|
|
81
|
+
const formatted = this.formatMessage('DEBUG', message, context);
|
|
82
|
+
console.log(this.colors ? `\x1b[36m${formatted}\x1b[0m` : formatted, ...args);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
trace(message, context, ...args) {
|
|
86
|
+
if (this.level >= LogLevel.TRACE) {
|
|
87
|
+
const formatted = this.formatMessage('TRACE', message, context);
|
|
88
|
+
console.log(this.colors ? `\x1b[90m${formatted}\x1b[0m` : formatted, ...args);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
// Convenience methods for common operations
|
|
92
|
+
startOperation(operation, component) {
|
|
93
|
+
const startTime = Date.now();
|
|
94
|
+
this.debug(`🚀 Starting: ${operation}`, { component, operation });
|
|
95
|
+
return {
|
|
96
|
+
end: (result) => {
|
|
97
|
+
const duration = Date.now() - startTime;
|
|
98
|
+
if (result && result.error) {
|
|
99
|
+
this.error(`❌ Failed: ${operation}`, { component, operation, duration, error: result.error });
|
|
100
|
+
}
|
|
101
|
+
else {
|
|
102
|
+
this.debug(`✅ Completed: ${operation}`, { component, operation, duration });
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
apiCall(operation, tokens, cost) {
|
|
108
|
+
const context = { component: 'API' };
|
|
109
|
+
if (tokens) {
|
|
110
|
+
context.tokens = tokens.input + tokens.output;
|
|
111
|
+
this.debug(`🌐 API Call: ${operation} (${tokens.input} in, ${tokens.output} out)`, context);
|
|
112
|
+
}
|
|
113
|
+
else {
|
|
114
|
+
this.debug(`🌐 API Call: ${operation}`, context);
|
|
115
|
+
}
|
|
116
|
+
if (cost) {
|
|
117
|
+
this.info(`💸 Estimated cost: $${cost.toFixed(6)}`, context);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
toolExecution(toolName, duration, success = true) {
|
|
121
|
+
const emoji = success ? '✅' : '❌';
|
|
122
|
+
const level = success ? 'debug' : 'error';
|
|
123
|
+
this[level](`${emoji} Tool: ${toolName}`, { component: 'Tool', operation: toolName, duration });
|
|
124
|
+
}
|
|
125
|
+
contextInfo(current, max, percentage) {
|
|
126
|
+
const context = { component: 'Context', tokens: current };
|
|
127
|
+
if (percentage >= 90) {
|
|
128
|
+
this.warn(`📊 Context: ${current}/${max} tokens (${percentage.toFixed(1)}%) - approaching limit`, context);
|
|
129
|
+
}
|
|
130
|
+
else if (percentage >= 75) {
|
|
131
|
+
this.info(`📊 Context: ${current}/${max} tokens (${percentage.toFixed(1)}%)`, context);
|
|
132
|
+
}
|
|
133
|
+
else {
|
|
134
|
+
this.debug(`📊 Context: ${current}/${max} tokens (${percentage.toFixed(1)}%)`, context);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
// Stream-safe output methods (don't interfere with streaming content)
|
|
138
|
+
streamSafeInfo(message) {
|
|
139
|
+
if (this.level >= LogLevel.INFO) {
|
|
140
|
+
process.stderr.write(`\n${message}\n`);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
streamSafeDebug(message) {
|
|
144
|
+
if (this.level >= LogLevel.DEBUG) {
|
|
145
|
+
process.stderr.write(`\n[DEBUG] ${message}\n`);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
export const logger = new Logger();
|
package/package.json
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "protoagent",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "Interactive AI coding agent CLI with file system capabilities and shell command execution",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"bin": {
|
|
8
|
+
"protoagent": "dist/index.js"
|
|
9
|
+
},
|
|
10
|
+
"scripts": {
|
|
11
|
+
"build": "tsc",
|
|
12
|
+
"dev": "tsx src/index.ts",
|
|
13
|
+
"start": "node dist/index.js",
|
|
14
|
+
"prepublishOnly": "npm run build",
|
|
15
|
+
"prepack": "npm run build"
|
|
16
|
+
},
|
|
17
|
+
"keywords": [
|
|
18
|
+
"cli",
|
|
19
|
+
"ai",
|
|
20
|
+
"coding-assistant",
|
|
21
|
+
"agent",
|
|
22
|
+
"coding",
|
|
23
|
+
"typescript",
|
|
24
|
+
"interactive",
|
|
25
|
+
"openai",
|
|
26
|
+
"file-system",
|
|
27
|
+
"shell-commands",
|
|
28
|
+
"developer-tools"
|
|
29
|
+
],
|
|
30
|
+
"author": "Thomas Gauvin",
|
|
31
|
+
"license": "MIT",
|
|
32
|
+
"repository": {
|
|
33
|
+
"type": "git",
|
|
34
|
+
"url": "https://github.com/thomasgauvin/protoagent.git"
|
|
35
|
+
},
|
|
36
|
+
"bugs": {
|
|
37
|
+
"url": "https://github.com/thomasgauvin/protoagent/issues"
|
|
38
|
+
},
|
|
39
|
+
"homepage": "https://github.com/thomasgauvin/protoagent#readme",
|
|
40
|
+
"devDependencies": {
|
|
41
|
+
"@types/inquirer": "^9.0.9",
|
|
42
|
+
"@types/node": "^20.0.0",
|
|
43
|
+
"dotenv": "^17.2.1",
|
|
44
|
+
"tsx": "^4.7.0",
|
|
45
|
+
"typescript": "^5.0.0"
|
|
46
|
+
},
|
|
47
|
+
"dependencies": {
|
|
48
|
+
"commander": "^11.0.0",
|
|
49
|
+
"inquirer": "^9.3.7",
|
|
50
|
+
"openai": "^5.11.0",
|
|
51
|
+
"zod": "^3.25.76"
|
|
52
|
+
},
|
|
53
|
+
"engines": {
|
|
54
|
+
"node": ">=16.0.0"
|
|
55
|
+
},
|
|
56
|
+
"files": [
|
|
57
|
+
"dist/**/*",
|
|
58
|
+
"README.md",
|
|
59
|
+
"LICENSE"
|
|
60
|
+
]
|
|
61
|
+
}
|