@townco/agent 0.1.47 → 0.1.48
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/acp-server/adapter.js +28 -6
- package/dist/acp-server/cli.d.ts +3 -1
- package/dist/acp-server/session-storage.d.ts +6 -0
- package/dist/acp-server/session-storage.js +1 -0
- package/dist/bin.js +0 -0
- package/dist/definition/mcp.d.ts +0 -0
- package/dist/definition/mcp.js +0 -0
- package/dist/definition/tools/todo.d.ts +49 -0
- package/dist/definition/tools/todo.js +80 -0
- package/dist/definition/tools/web_search.d.ts +4 -0
- package/dist/definition/tools/web_search.js +26 -0
- package/dist/dev-agent/index.d.ts +2 -0
- package/dist/dev-agent/index.js +18 -0
- package/dist/example.d.ts +2 -0
- package/dist/example.js +19 -0
- package/dist/runner/hooks/predefined/compaction-tool.d.ts +2 -2
- package/dist/runner/hooks/predefined/compaction-tool.js +103 -27
- package/dist/runner/hooks/types.d.ts +1 -1
- package/dist/runner/hooks/types.js +6 -2
- package/dist/runner/index.d.ts +3 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/utils/logger.d.ts +39 -0
- package/dist/utils/logger.js +175 -0
- package/package.json +6 -6
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Node.js logger with file rotation support
|
|
3
|
+
* Outputs to both stdout and .logs/<service>.log files
|
|
4
|
+
*/
|
|
5
|
+
export type LogLevel = "trace" | "debug" | "info" | "warn" | "error" | "fatal";
|
|
6
|
+
export declare class Logger {
|
|
7
|
+
private service;
|
|
8
|
+
private minLevel;
|
|
9
|
+
private logFilePath;
|
|
10
|
+
private logsDir;
|
|
11
|
+
private writeQueue;
|
|
12
|
+
private isWriting;
|
|
13
|
+
private silent;
|
|
14
|
+
constructor(service: string, minLevel?: LogLevel, options?: {
|
|
15
|
+
silent?: boolean;
|
|
16
|
+
logsDir?: string;
|
|
17
|
+
});
|
|
18
|
+
private ensureLogsDirectory;
|
|
19
|
+
private shouldLog;
|
|
20
|
+
private rotateLogFile;
|
|
21
|
+
private writeToFile;
|
|
22
|
+
private log;
|
|
23
|
+
trace(message: string, metadata?: Record<string, unknown>): void;
|
|
24
|
+
debug(message: string, metadata?: Record<string, unknown>): void;
|
|
25
|
+
info(message: string, metadata?: Record<string, unknown>): void;
|
|
26
|
+
warn(message: string, metadata?: Record<string, unknown>): void;
|
|
27
|
+
error(message: string, metadata?: Record<string, unknown>): void;
|
|
28
|
+
fatal(message: string, metadata?: Record<string, unknown>): void;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Create a logger instance for a service
|
|
32
|
+
* @param service - Service name (e.g., "gui", "http-agent", "tui")
|
|
33
|
+
* @param minLevel - Minimum log level to display (default: "debug")
|
|
34
|
+
* @param options - Logger options (silent mode, custom logs directory, etc.)
|
|
35
|
+
*/
|
|
36
|
+
export declare function createLogger(service: string, minLevel?: LogLevel, options?: {
|
|
37
|
+
silent?: boolean;
|
|
38
|
+
logsDir?: string;
|
|
39
|
+
}): Logger;
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Node.js logger with file rotation support
|
|
3
|
+
* Outputs to both stdout and .logs/<service>.log files
|
|
4
|
+
*/
|
|
5
|
+
import * as fs from "node:fs";
|
|
6
|
+
import * as path from "node:path";
|
|
7
|
+
const LOG_LEVELS = {
|
|
8
|
+
trace: 0,
|
|
9
|
+
debug: 1,
|
|
10
|
+
info: 2,
|
|
11
|
+
warn: 3,
|
|
12
|
+
error: 4,
|
|
13
|
+
fatal: 5,
|
|
14
|
+
};
|
|
15
|
+
// ANSI color codes for terminal output
|
|
16
|
+
const LOG_COLORS = {
|
|
17
|
+
trace: "\x1b[90m", // gray
|
|
18
|
+
debug: "\x1b[34m", // blue
|
|
19
|
+
info: "\x1b[32m", // green
|
|
20
|
+
warn: "\x1b[33m", // yellow
|
|
21
|
+
error: "\x1b[31m", // red
|
|
22
|
+
fatal: "\x1b[41m\x1b[37m", // white on red background
|
|
23
|
+
};
|
|
24
|
+
const RESET = "\x1b[0m";
|
|
25
|
+
const MAX_LOG_SIZE = 10 * 1024 * 1024; // 10MB
|
|
26
|
+
const MAX_ROTATED_FILES = 5;
|
|
27
|
+
export class Logger {
|
|
28
|
+
service;
|
|
29
|
+
minLevel;
|
|
30
|
+
logFilePath;
|
|
31
|
+
logsDir;
|
|
32
|
+
writeQueue = [];
|
|
33
|
+
isWriting = false;
|
|
34
|
+
silent;
|
|
35
|
+
constructor(service, minLevel = "debug", options) {
|
|
36
|
+
this.service = service;
|
|
37
|
+
this.minLevel = minLevel;
|
|
38
|
+
this.silent = options?.silent ?? false;
|
|
39
|
+
// Setup log file path - use custom logsDir if provided, otherwise use process.cwd()
|
|
40
|
+
const baseDir = options?.logsDir ?? process.cwd();
|
|
41
|
+
this.logsDir = path.join(baseDir, ".logs");
|
|
42
|
+
this.logFilePath = path.join(this.logsDir, `${service}.log`);
|
|
43
|
+
// Create logs directory if it doesn't exist
|
|
44
|
+
this.ensureLogsDirectory();
|
|
45
|
+
}
|
|
46
|
+
ensureLogsDirectory() {
|
|
47
|
+
try {
|
|
48
|
+
if (!fs.existsSync(this.logsDir)) {
|
|
49
|
+
fs.mkdirSync(this.logsDir, { recursive: true });
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
catch (error) {
|
|
53
|
+
console.error("Failed to create logs directory:", error);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
shouldLog(level) {
|
|
57
|
+
return LOG_LEVELS[level] >= LOG_LEVELS[this.minLevel];
|
|
58
|
+
}
|
|
59
|
+
rotateLogFile() {
|
|
60
|
+
try {
|
|
61
|
+
// Check if rotation is needed
|
|
62
|
+
if (!fs.existsSync(this.logFilePath)) {
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
const stats = fs.statSync(this.logFilePath);
|
|
66
|
+
if (stats.size < MAX_LOG_SIZE) {
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
// Remove oldest rotated file if it exists
|
|
70
|
+
const oldestFile = `${this.logFilePath}.${MAX_ROTATED_FILES}`;
|
|
71
|
+
if (fs.existsSync(oldestFile)) {
|
|
72
|
+
fs.unlinkSync(oldestFile);
|
|
73
|
+
}
|
|
74
|
+
// Rotate existing files
|
|
75
|
+
for (let i = MAX_ROTATED_FILES - 1; i >= 1; i--) {
|
|
76
|
+
const oldFile = `${this.logFilePath}.${i}`;
|
|
77
|
+
const newFile = `${this.logFilePath}.${i + 1}`;
|
|
78
|
+
if (fs.existsSync(oldFile)) {
|
|
79
|
+
fs.renameSync(oldFile, newFile);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
// Rotate current log file
|
|
83
|
+
fs.renameSync(this.logFilePath, `${this.logFilePath}.1`);
|
|
84
|
+
}
|
|
85
|
+
catch (error) {
|
|
86
|
+
console.error("Failed to rotate log file:", error);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
async writeToFile(content) {
|
|
90
|
+
this.writeQueue.push(content);
|
|
91
|
+
if (this.isWriting) {
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
this.isWriting = true;
|
|
95
|
+
while (this.writeQueue.length > 0) {
|
|
96
|
+
const batch = this.writeQueue.splice(0, this.writeQueue.length);
|
|
97
|
+
const data = `${batch.join("\n")}\n`;
|
|
98
|
+
try {
|
|
99
|
+
// Check if rotation is needed before writing
|
|
100
|
+
this.rotateLogFile();
|
|
101
|
+
// Append to log file
|
|
102
|
+
await fs.promises.appendFile(this.logFilePath, data, "utf-8");
|
|
103
|
+
}
|
|
104
|
+
catch (error) {
|
|
105
|
+
console.error("Failed to write to log file:", error);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
this.isWriting = false;
|
|
109
|
+
}
|
|
110
|
+
log(level, message, metadata) {
|
|
111
|
+
if (!this.shouldLog(level)) {
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
const entry = {
|
|
115
|
+
timestamp: new Date().toISOString(),
|
|
116
|
+
level,
|
|
117
|
+
service: this.service,
|
|
118
|
+
message,
|
|
119
|
+
...(metadata && { metadata }),
|
|
120
|
+
};
|
|
121
|
+
// Console output with color-coding
|
|
122
|
+
const color = LOG_COLORS[level];
|
|
123
|
+
const levelUpper = level.toUpperCase().padEnd(5);
|
|
124
|
+
const prefix = `${color}[${entry.timestamp}] [${this.service}] [${levelUpper}]${RESET}`;
|
|
125
|
+
const formattedMessage = metadata
|
|
126
|
+
? `${message} ${JSON.stringify(metadata)}`
|
|
127
|
+
: message;
|
|
128
|
+
// Output to stdout/stderr (unless silent)
|
|
129
|
+
if (!this.silent) {
|
|
130
|
+
if (level === "error" || level === "fatal") {
|
|
131
|
+
console.error(`${prefix} ${formattedMessage}`);
|
|
132
|
+
}
|
|
133
|
+
else if (level === "warn") {
|
|
134
|
+
console.warn(`${prefix} ${formattedMessage}`);
|
|
135
|
+
}
|
|
136
|
+
else {
|
|
137
|
+
console.log(`${prefix} ${formattedMessage}`);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
// Write to file (JSON format)
|
|
141
|
+
const jsonLine = JSON.stringify(entry);
|
|
142
|
+
this.writeToFile(jsonLine).catch((error) => {
|
|
143
|
+
if (!this.silent) {
|
|
144
|
+
console.error("Failed to queue log write:", error);
|
|
145
|
+
}
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
trace(message, metadata) {
|
|
149
|
+
this.log("trace", message, metadata);
|
|
150
|
+
}
|
|
151
|
+
debug(message, metadata) {
|
|
152
|
+
this.log("debug", message, metadata);
|
|
153
|
+
}
|
|
154
|
+
info(message, metadata) {
|
|
155
|
+
this.log("info", message, metadata);
|
|
156
|
+
}
|
|
157
|
+
warn(message, metadata) {
|
|
158
|
+
this.log("warn", message, metadata);
|
|
159
|
+
}
|
|
160
|
+
error(message, metadata) {
|
|
161
|
+
this.log("error", message, metadata);
|
|
162
|
+
}
|
|
163
|
+
fatal(message, metadata) {
|
|
164
|
+
this.log("fatal", message, metadata);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Create a logger instance for a service
|
|
169
|
+
* @param service - Service name (e.g., "gui", "http-agent", "tui")
|
|
170
|
+
* @param minLevel - Minimum log level to display (default: "debug")
|
|
171
|
+
* @param options - Logger options (silent mode, custom logs directory, etc.)
|
|
172
|
+
*/
|
|
173
|
+
export function createLogger(service, minLevel = "debug", options) {
|
|
174
|
+
return new Logger(service, minLevel, options);
|
|
175
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@townco/agent",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.48",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"module": "index.ts",
|
|
6
6
|
"files": [
|
|
@@ -56,11 +56,11 @@
|
|
|
56
56
|
"@langchain/google-genai": "^1.0.3",
|
|
57
57
|
"@langchain/google-vertexai": "^1.0.3",
|
|
58
58
|
"@langchain/mcp-adapters": "^1.0.0",
|
|
59
|
-
"@townco/core": "0.0.
|
|
60
|
-
"@townco/gui-template": "0.1.
|
|
61
|
-
"@townco/tui-template": "0.1.
|
|
62
|
-
"@townco/tsconfig": "0.1.
|
|
63
|
-
"@townco/ui": "0.1.
|
|
59
|
+
"@townco/core": "0.0.21",
|
|
60
|
+
"@townco/gui-template": "0.1.40",
|
|
61
|
+
"@townco/tui-template": "0.1.40",
|
|
62
|
+
"@townco/tsconfig": "0.1.40",
|
|
63
|
+
"@townco/ui": "0.1.43",
|
|
64
64
|
"exa-js": "^2.0.0",
|
|
65
65
|
"hono": "^4.10.4",
|
|
66
66
|
"langchain": "^1.0.3",
|