vite-plugin-opencode-assistant 1.0.2 → 1.0.4

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.
@@ -0,0 +1,64 @@
1
+ export declare enum LogLevel {
2
+ DEBUG = 0,
3
+ INFO = 1,
4
+ WARN = 2,
5
+ ERROR = 3,
6
+ NONE = 4
7
+ }
8
+ export interface LogContext {
9
+ module?: string;
10
+ operation?: string;
11
+ traceId?: string;
12
+ duration?: number;
13
+ error?: Error | unknown;
14
+ [key: string]: unknown;
15
+ }
16
+ interface LoggerConfig {
17
+ verbose: boolean;
18
+ level: LogLevel;
19
+ showTimestamp: boolean;
20
+ showCaller: boolean;
21
+ showTrace: boolean;
22
+ indent: string;
23
+ }
24
+ export declare function configureLogger(options: Partial<LoggerConfig>): void;
25
+ export declare function setVerbose(verbose: boolean): void;
26
+ export declare const logger: {
27
+ debug(message: string, context?: LogContext, ...args: unknown[]): void;
28
+ info(message: string, context?: LogContext, ...args: unknown[]): void;
29
+ warn(message: string, context?: LogContext, ...args: unknown[]): void;
30
+ error(message: string, context?: LogContext, ...args: unknown[]): void;
31
+ group(label: string, context?: LogContext): void;
32
+ groupEnd(): void;
33
+ };
34
+ export declare function generateTraceId(): string;
35
+ export declare class PerformanceTimer {
36
+ private startTime;
37
+ private context;
38
+ private operation;
39
+ constructor(operation: string, context?: LogContext);
40
+ end(message?: string): number;
41
+ checkpoint(label: string): number;
42
+ }
43
+ export declare class RequestContext {
44
+ traceId: string;
45
+ method: string;
46
+ path: string;
47
+ startTime: number;
48
+ private checkpoints;
49
+ constructor(method: string, path: string);
50
+ checkpoint(label: string): void;
51
+ end(statusCode: number): void;
52
+ error(error: Error | unknown): void;
53
+ }
54
+ export declare function createLogger(module: string): {
55
+ debug(message: string, context?: Omit<LogContext, "module">, ...args: unknown[]): void;
56
+ info(message: string, context?: Omit<LogContext, "module">, ...args: unknown[]): void;
57
+ warn(message: string, context?: Omit<LogContext, "module">, ...args: unknown[]): void;
58
+ error(message: string, context?: Omit<LogContext, "module">, ...args: unknown[]): void;
59
+ timer(operation: string, context?: Omit<LogContext, "module">): PerformanceTimer;
60
+ };
61
+ export declare function logMethod(target: unknown, propertyKey: string, descriptor: PropertyDescriptor): PropertyDescriptor;
62
+ export declare function formatBytes(bytes: number): string;
63
+ export declare function formatDuration(ms: number): string;
64
+ export {};
package/dist/logger.js ADDED
@@ -0,0 +1,311 @@
1
+ import { LOG_PREFIX } from './constants.js';
2
+ export var LogLevel;
3
+ (function (LogLevel) {
4
+ LogLevel[LogLevel["DEBUG"] = 0] = "DEBUG";
5
+ LogLevel[LogLevel["INFO"] = 1] = "INFO";
6
+ LogLevel[LogLevel["WARN"] = 2] = "WARN";
7
+ LogLevel[LogLevel["ERROR"] = 3] = "ERROR";
8
+ LogLevel[LogLevel["NONE"] = 4] = "NONE";
9
+ })(LogLevel || (LogLevel = {}));
10
+ const COLORS = {
11
+ reset: '\x1b[0m',
12
+ dim: '\x1b[2m',
13
+ bright: '\x1b[1m',
14
+ red: '\x1b[31m',
15
+ green: '\x1b[32m',
16
+ yellow: '\x1b[33m',
17
+ blue: '\x1b[34m',
18
+ magenta: '\x1b[35m',
19
+ cyan: '\x1b[36m',
20
+ white: '\x1b[37m',
21
+ };
22
+ const LEVEL_COLORS = {
23
+ [LogLevel.DEBUG]: COLORS.cyan,
24
+ [LogLevel.INFO]: COLORS.green,
25
+ [LogLevel.WARN]: COLORS.yellow,
26
+ [LogLevel.ERROR]: COLORS.red,
27
+ [LogLevel.NONE]: COLORS.reset,
28
+ };
29
+ const LEVEL_NAMES = {
30
+ [LogLevel.DEBUG]: 'DEBUG',
31
+ [LogLevel.INFO]: 'INFO',
32
+ [LogLevel.WARN]: 'WARN',
33
+ [LogLevel.ERROR]: 'ERROR',
34
+ [LogLevel.NONE]: 'NONE',
35
+ };
36
+ let globalConfig = {
37
+ verbose: false,
38
+ level: LogLevel.INFO,
39
+ showTimestamp: true,
40
+ showCaller: true,
41
+ showTrace: false,
42
+ indent: ' ',
43
+ };
44
+ let traceCounter = 0;
45
+ export function configureLogger(options) {
46
+ globalConfig = { ...globalConfig, ...options };
47
+ }
48
+ export function setVerbose(verbose) {
49
+ globalConfig.verbose = verbose;
50
+ globalConfig.level = verbose ? LogLevel.DEBUG : LogLevel.INFO;
51
+ }
52
+ function getTimestamp() {
53
+ const now = new Date();
54
+ const hours = String(now.getHours()).padStart(2, '0');
55
+ const minutes = String(now.getMinutes()).padStart(2, '0');
56
+ const seconds = String(now.getSeconds()).padStart(2, '0');
57
+ const ms = String(now.getMilliseconds()).padStart(3, '0');
58
+ return `${hours}:${minutes}:${seconds}.${ms}`;
59
+ }
60
+ function getCallerInfo(depth = 3) {
61
+ const stack = new Error().stack;
62
+ if (!stack)
63
+ return '';
64
+ const lines = stack.split('\n');
65
+ const targetLine = lines[depth];
66
+ if (!targetLine)
67
+ return '';
68
+ const match = targetLine.match(/at\s+(?:(.+?)\s+\()?(.+?):(\d+):(\d+)\)?/);
69
+ if (!match)
70
+ return '';
71
+ const [, funcName, filePath, line] = match;
72
+ const fileName = filePath.split('/').pop() || filePath;
73
+ const func = funcName || '<anonymous>';
74
+ return `${fileName}:${line} ${func}`;
75
+ }
76
+ function formatValue(value, depth = 0) {
77
+ if (depth > 3)
78
+ return '...';
79
+ if (value === null)
80
+ return 'null';
81
+ if (value === undefined)
82
+ return 'undefined';
83
+ if (typeof value === 'string')
84
+ return depth > 0 ? `"${value}"` : value;
85
+ if (typeof value === 'number' || typeof value === 'boolean')
86
+ return String(value);
87
+ if (value instanceof Error) {
88
+ return `${value.name}: ${value.message}${value.stack ? `\n${value.stack}` : ''}`;
89
+ }
90
+ if (Array.isArray(value)) {
91
+ if (value.length === 0)
92
+ return '[]';
93
+ if (value.length > 5) {
94
+ const items = value.slice(0, 3).map(v => formatValue(v, depth + 1));
95
+ return `[${items.join(', ')}, ... ${value.length - 3} more items]`;
96
+ }
97
+ const items = value.map(v => formatValue(v, depth + 1));
98
+ return `[${items.join(', ')}]`;
99
+ }
100
+ if (typeof value === 'object') {
101
+ const entries = Object.entries(value);
102
+ if (entries.length === 0)
103
+ return '{}';
104
+ if (entries.length > 5) {
105
+ const shown = entries.slice(0, 3).map(([k, v]) => `${k}: ${formatValue(v, depth + 1)}`);
106
+ return `{${shown.join(', ')}, ... ${entries.length - 3} more keys}`;
107
+ }
108
+ const formatted = entries.map(([k, v]) => `${k}: ${formatValue(v, depth + 1)}`);
109
+ return `{${formatted.join(', ')}}`;
110
+ }
111
+ return String(value);
112
+ }
113
+ function formatContext(context) {
114
+ if (!context || Object.keys(context).length === 0)
115
+ return '';
116
+ const parts = [];
117
+ if (context.module)
118
+ parts.push(`[${context.module}]`);
119
+ if (context.operation)
120
+ parts.push(`(${context.operation})`);
121
+ if (context.traceId)
122
+ parts.push(`trace:${context.traceId}`);
123
+ if (context.duration !== undefined)
124
+ parts.push(`${context.duration}ms`);
125
+ const extraKeys = Object.keys(context).filter(k => !['module', 'operation', 'traceId', 'duration', 'error'].includes(k));
126
+ if (extraKeys.length > 0) {
127
+ const extra = {};
128
+ extraKeys.forEach(k => extra[k] = context[k]);
129
+ parts.push(formatValue(extra));
130
+ }
131
+ return parts.join(' ');
132
+ }
133
+ function log(level, message, context, ...args) {
134
+ if (level < globalConfig.level)
135
+ return;
136
+ const parts = [];
137
+ parts.push(`${COLORS.dim}[${process.pid}]${COLORS.reset}`);
138
+ if (globalConfig.showTimestamp) {
139
+ parts.push(`${COLORS.dim}${getTimestamp()}${COLORS.reset}`);
140
+ }
141
+ const levelColor = LEVEL_COLORS[level];
142
+ const levelName = LEVEL_NAMES[level].padEnd(5);
143
+ parts.push(`${levelColor}${levelName}${COLORS.reset}`);
144
+ parts.push(`${COLORS.bright}${LOG_PREFIX}${COLORS.reset}`);
145
+ const contextStr = formatContext(context);
146
+ if (contextStr) {
147
+ parts.push(`${COLORS.magenta}${contextStr}${COLORS.reset}`);
148
+ }
149
+ parts.push(message);
150
+ if (globalConfig.showCaller && level >= LogLevel.WARN) {
151
+ const caller = getCallerInfo(4);
152
+ if (caller) {
153
+ parts.push(`${COLORS.dim}(${caller})${COLORS.reset}`);
154
+ }
155
+ }
156
+ const formattedArgs = args.map(a => formatValue(a)).join(' ');
157
+ if (formattedArgs) {
158
+ parts.push(formattedArgs);
159
+ }
160
+ const output = parts.join(' ');
161
+ if (level >= LogLevel.ERROR) {
162
+ console.error(output);
163
+ }
164
+ else if (level === LogLevel.WARN) {
165
+ console.warn(output);
166
+ }
167
+ else {
168
+ console.log(output);
169
+ }
170
+ if (context?.error && level >= LogLevel.ERROR && globalConfig.showTrace) {
171
+ const err = context.error;
172
+ if (err instanceof Error && err.stack) {
173
+ console.error(`${COLORS.dim}${err.stack}${COLORS.reset}`);
174
+ }
175
+ }
176
+ }
177
+ export const logger = {
178
+ debug(message, context, ...args) {
179
+ log(LogLevel.DEBUG, message, context, ...args);
180
+ },
181
+ info(message, context, ...args) {
182
+ log(LogLevel.INFO, message, context, ...args);
183
+ },
184
+ warn(message, context, ...args) {
185
+ log(LogLevel.WARN, message, context, ...args);
186
+ },
187
+ error(message, context, ...args) {
188
+ log(LogLevel.ERROR, message, context, ...args);
189
+ },
190
+ group(label, context) {
191
+ if (!globalConfig.verbose)
192
+ return;
193
+ const contextStr = formatContext(context);
194
+ console.log(`${COLORS.dim}[${process.pid}]${COLORS.reset} ${COLORS.bright}${LOG_PREFIX}${COLORS.reset} ${COLORS.blue}▼${COLORS.reset} ${label}${contextStr ? ` ${contextStr}` : ''}`);
195
+ },
196
+ groupEnd() {
197
+ if (!globalConfig.verbose)
198
+ return;
199
+ },
200
+ };
201
+ export function generateTraceId() {
202
+ traceCounter++;
203
+ const timestamp = Date.now().toString(36);
204
+ const counter = traceCounter.toString(36).padStart(4, '0');
205
+ return `${timestamp}-${counter}`;
206
+ }
207
+ export class PerformanceTimer {
208
+ constructor(operation, context) {
209
+ this.operation = operation;
210
+ this.context = context || {};
211
+ this.startTime = performance.now();
212
+ logger.debug(`⏱️ Starting: ${operation}`, this.context);
213
+ }
214
+ end(message) {
215
+ const duration = Math.round(performance.now() - this.startTime);
216
+ const msg = message || `✓ Completed: ${this.operation}`;
217
+ logger.debug(msg, { ...this.context, duration });
218
+ return duration;
219
+ }
220
+ checkpoint(label) {
221
+ const elapsed = Math.round(performance.now() - this.startTime);
222
+ logger.debug(` ↳ ${label}`, { ...this.context, duration: elapsed });
223
+ return elapsed;
224
+ }
225
+ }
226
+ export class RequestContext {
227
+ constructor(method, path) {
228
+ this.checkpoints = [];
229
+ this.traceId = generateTraceId();
230
+ this.method = method;
231
+ this.path = path;
232
+ this.startTime = performance.now();
233
+ logger.debug(`→ ${method} ${path}`, { traceId: this.traceId, module: 'HTTP' });
234
+ }
235
+ checkpoint(label) {
236
+ const elapsed = Math.round(performance.now() - this.startTime);
237
+ this.checkpoints.push({ time: elapsed, label });
238
+ logger.debug(` → ${label}`, { traceId: this.traceId, duration: elapsed });
239
+ }
240
+ end(statusCode) {
241
+ const duration = Math.round(performance.now() - this.startTime);
242
+ const statusColor = statusCode < 400 ? COLORS.green : COLORS.red;
243
+ logger.debug(`← ${this.method} ${this.path} ${statusColor}${statusCode}${COLORS.reset}`, {
244
+ traceId: this.traceId,
245
+ duration,
246
+ checkpoints: this.checkpoints.length,
247
+ });
248
+ }
249
+ error(error) {
250
+ const duration = Math.round(performance.now() - this.startTime);
251
+ logger.error(`✗ ${this.method} ${this.path}`, {
252
+ traceId: this.traceId,
253
+ duration,
254
+ error,
255
+ });
256
+ }
257
+ }
258
+ export function createLogger(module) {
259
+ return {
260
+ debug(message, context, ...args) {
261
+ logger.debug(message, { ...context, module }, ...args);
262
+ },
263
+ info(message, context, ...args) {
264
+ logger.info(message, { ...context, module }, ...args);
265
+ },
266
+ warn(message, context, ...args) {
267
+ logger.warn(message, { ...context, module }, ...args);
268
+ },
269
+ error(message, context, ...args) {
270
+ logger.error(message, { ...context, module }, ...args);
271
+ },
272
+ timer(operation, context) {
273
+ return new PerformanceTimer(operation, { ...context, module });
274
+ },
275
+ };
276
+ }
277
+ export function logMethod(target, propertyKey, descriptor) {
278
+ const originalMethod = descriptor.value;
279
+ const className = target.constructor.name;
280
+ descriptor.value = async function (...args) {
281
+ const timer = new PerformanceTimer(`${className}.${propertyKey}`);
282
+ try {
283
+ const result = await originalMethod.apply(this, args);
284
+ timer.end();
285
+ return result;
286
+ }
287
+ catch (error) {
288
+ timer.end('❌ Failed');
289
+ throw error;
290
+ }
291
+ };
292
+ return descriptor;
293
+ }
294
+ export function formatBytes(bytes) {
295
+ if (bytes === 0)
296
+ return '0B';
297
+ const k = 1024;
298
+ const sizes = ['B', 'KB', 'MB', 'GB'];
299
+ const i = Math.floor(Math.log(bytes) / Math.log(k));
300
+ return `${parseFloat((bytes / Math.pow(k, i)).toFixed(2))}${sizes[i]}`;
301
+ }
302
+ export function formatDuration(ms) {
303
+ if (ms < 1000)
304
+ return `${ms}ms`;
305
+ if (ms < 60000)
306
+ return `${(ms / 1000).toFixed(2)}s`;
307
+ const minutes = Math.floor(ms / 60000);
308
+ const seconds = Math.round((ms % 60000) / 1000);
309
+ return `${minutes}m ${seconds}s`;
310
+ }
311
+ //# sourceMappingURL=logger.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logger.js","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAA;AAE3C,MAAM,CAAN,IAAY,QAMX;AAND,WAAY,QAAQ;IAClB,yCAAS,CAAA;IACT,uCAAQ,CAAA;IACR,uCAAQ,CAAA;IACR,yCAAS,CAAA;IACT,uCAAQ,CAAA;AACV,CAAC,EANW,QAAQ,KAAR,QAAQ,QAMnB;AAoBD,MAAM,MAAM,GAAG;IACb,KAAK,EAAE,SAAS;IAChB,GAAG,EAAE,SAAS;IACd,MAAM,EAAE,SAAS;IACjB,GAAG,EAAE,UAAU;IACf,KAAK,EAAE,UAAU;IACjB,MAAM,EAAE,UAAU;IAClB,IAAI,EA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,OAAO,GAAG,CAAC,EAAE,GAAG,IAAI,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,CAAA;IACnD,MAAM,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,EAAE,GAAG,KAAK,CAAC,CAAA;IACtC,MAAM,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,KAAK,CAAC,GAAG,IAAI,CAAC,CAAA;IAC/C,OAAO,GAAG,OAAO,KAAK,OAAO,GAAG,CAAA;AAClC,CAAC","sourcesContent":["import { LOG_PREFIX } from './constants.js'\n\nexport enum LogLevel {\n DEBUG = 0,\n INFO = 1,\n WARN = 2,\n ERROR = 3,\n NONE = 4,\n}\n\nexport interface LogContext {\n module?: string\n operation?: string\n traceId?: string\n duration?: number\n error?: Error | unknown\n [key: string]: unknown\n}\n\ninterface LoggerConfig {\n verbose: boolean\n level: LogLevel\n showTimestamp: boolean\n showCaller: boolean\n showTrace: boolean\n indent: string\n}\n\nconst COLORS = {\n reset: '\\x1b[0m',\n dim: '\\x1b[2m',\n bright: '\\x1b[1m',\n red: '\\x1b[31m',\n green: '\\x1b[32m',\n yellow: '\\x1b[33m',\n blue: '\\x1b[34m',\n magenta: '\\x1b[35m',\n cyan: '\\x1b[36m',\n white: '\\x1b[37m',\n}\n\nconst LEVEL_COLORS: Record<LogLevel, string> = {\n [LogLevel.DEBUG]: COLORS.cyan,\n [LogLevel.INFO]: COLORS.green,\n [LogLevel.WARN]: COLORS.yellow,\n [LogLevel.ERROR]: COLORS.red,\n [LogLevel.NONE]: COLORS.reset,\n}\n\nconst LEVEL_NAMES: Record<LogLevel, string> = {\n [LogLevel.DEBUG]: 'DEBUG',\n [LogLevel.INFO]: 'INFO',\n [LogLevel.WARN]: 'WARN',\n [LogLevel.ERROR]: 'ERROR',\n [LogLevel.NONE]: 'NONE',\n}\n\nlet globalConfig: LoggerConfig = {\n verbose: false,\n level: LogLevel.INFO,\n showTimestamp: true,\n showCaller: true,\n showTrace: false,\n indent: ' ',\n}\n\nlet traceCounter = 0\n\nexport function configureLogger(options: Partial<LoggerConfig>): void {\n globalConfig = { ...globalConfig, ...options }\n}\n\nexport function setVerbose(verbose: boolean): void {\n globalConfig.verbose = verbose\n globalConfig.level = verbose ? LogLevel.DEBUG : LogLevel.INFO\n}\n\nfunction getTimestamp(): string {\n const now = new Date()\n const hours = String(now.getHours()).padStart(2, '0')\n const minutes = String(now.getMinutes()).padStart(2, '0')\n const seconds = String(now.getSeconds()).padStart(2, '0')\n const ms = String(now.getMilliseconds()).padStart(3, '0')\n return `${hours}:${minutes}:${seconds}.${ms}`\n}\n\nfunction getCallerInfo(depth: number = 3): string {\n const stack = new Error().stack\n if (!stack) return ''\n\n const lines = stack.split('\\n')\n const targetLine = lines[depth]\n if (!targetLine) return ''\n\n const match = targetLine.match(/at\\s+(?:(.+?)\\s+\\()?(.+?):(\\d+):(\\d+)\\)?/)\n if (!match) return ''\n\n const [, funcName, filePath, line] = match\n const fileName = filePath.split('/').pop() || filePath\n const func = funcName || '<anonymous>'\n return `${fileName}:${line} ${func}`\n}\n\nfunction formatValue(value: unknown, depth: number = 0): string {\n if (depth > 3) return '...'\n \n if (value === null) return 'null'\n if (value === undefined) return 'undefined'\n if (typeof value === 'string') return depth > 0 ? `\"${value}\"` : value\n if (typeof value === 'number' || typeof value === 'boolean') return String(value)\n if (value instanceof Error) {\n return `${value.name}: ${value.message}${value.stack ? `\\n${value.stack}` : ''}`\n }\n if (Array.isArray(value)) {\n if (value.length === 0) return '[]'\n if (value.length > 5) {\n const items = value.slice(0, 3).map(v => formatValue(v, depth + 1))\n return `[${items.join(', ')}, ... ${value.length - 3} more items]`\n }\n const items = value.map(v => formatValue(v, depth + 1))\n return `[${items.join(', ')}]`\n }\n if (typeof value === 'object') {\n const entries = Object.entries(value as Record<string, unknown>)\n if (entries.length === 0) return '{}'\n if (entries.length > 5) {\n const shown = entries.slice(0, 3).map(([k, v]) => `${k}: ${formatValue(v, depth + 1)}`)\n return `{${shown.join(', ')}, ... ${entries.length - 3} more keys}`\n }\n const formatted = entries.map(([k, v]) => `${k}: ${formatValue(v, depth + 1)}`)\n return `{${formatted.join(', ')}}`\n }\n return String(value)\n}\n\nfunction formatContext(context?: LogContext): string {\n if (!context || Object.keys(context).length === 0) return ''\n \n const parts: string[] = []\n \n if (context.module) parts.push(`[${context.module}]`)\n if (context.operation) parts.push(`(${context.operation})`)\n if (context.traceId) parts.push(`trace:${context.traceId}`)\n if (context.duration !== undefined) parts.push(`${context.duration}ms`)\n \n const extraKeys = Object.keys(context).filter(\n k => !['module', 'operation', 'traceId', 'duration', 'error'].includes(k)\n )\n if (extraKeys.length > 0) {\n const extra: Record<string, unknown> = {}\n extraKeys.forEach(k => extra[k] = context[k])\n parts.push(formatValue(extra))\n }\n \n return parts.join(' ')\n}\n\nfunction log(level: LogLevel, message: string, context?: LogContext, ...args: unknown[]): void {\n if (level < globalConfig.level) return\n \n const parts: string[] = []\n \n parts.push(`${COLORS.dim}[${process.pid}]${COLORS.reset}`)\n \n if (globalConfig.showTimestamp) {\n parts.push(`${COLORS.dim}${getTimestamp()}${COLORS.reset}`)\n }\n \n const levelColor = LEVEL_COLORS[level]\n const levelName = LEVEL_NAMES[level].padEnd(5)\n parts.push(`${levelColor}${levelName}${COLORS.reset}`)\n \n parts.push(`${COLORS.bright}${LOG_PREFIX}${COLORS.reset}`)\n \n const contextStr = formatContext(context)\n if (contextStr) {\n parts.push(`${COLORS.magenta}${contextStr}${COLORS.reset}`)\n }\n \n parts.push(message)\n \n if (globalConfig.showCaller && level >= LogLevel.WARN) {\n const caller = getCallerInfo(4)\n if (caller) {\n parts.push(`${COLORS.dim}(${caller})${COLORS.reset}`)\n }\n }\n \n const formattedArgs = args.map(a => formatValue(a)).join(' ')\n if (formattedArgs) {\n parts.push(formattedArgs)\n }\n \n const output = parts.join(' ')\n \n if (level >= LogLevel.ERROR) {\n console.error(output)\n } else if (level === LogLevel.WARN) {\n console.warn(output)\n } else {\n console.log(output)\n }\n \n if (context?.error && level >= LogLevel.ERROR && globalConfig.showTrace) {\n const err = context.error\n if (err instanceof Error && err.stack) {\n console.error(`${COLORS.dim}${err.stack}${COLORS.reset}`)\n }\n }\n}\n\nexport const logger = {\n debug(message: string, context?: LogContext, ...args: unknown[]): void {\n log(LogLevel.DEBUG, message, context, ...args)\n },\n \n info(message: string, context?: LogContext, ...args: unknown[]): void {\n log(LogLevel.INFO, message, context, ...args)\n },\n \n warn(message: string, context?: LogContext, ...args: unknown[]): void {\n log(LogLevel.WARN, message, context, ...args)\n },\n \n error(message: string, context?: LogContext, ...args: unknown[]): void {\n log(LogLevel.ERROR, message, context, ...args)\n },\n \n group(label: string, context?: LogContext): void {\n if (!globalConfig.verbose) return\n const contextStr = formatContext(context)\n console.log(`${COLORS.dim}[${process.pid}]${COLORS.reset} ${COLORS.bright}${LOG_PREFIX}${COLORS.reset} ${COLORS.blue}▼${COLORS.reset} ${label}${contextStr ? ` ${contextStr}` : ''}`)\n },\n \n groupEnd(): void {\n if (!globalConfig.verbose) return\n },\n}\n\nexport function generateTraceId(): string {\n traceCounter++\n const timestamp = Date.now().toString(36)\n const counter = traceCounter.toString(36).padStart(4, '0')\n return `${timestamp}-${counter}`\n}\n\nexport class PerformanceTimer {\n private startTime: number\n private context: LogContext\n private operation: string\n \n constructor(operation: string, context?: LogContext) {\n this.operation = operation\n this.context = context || {}\n this.startTime = performance.now()\n \n logger.debug(`⏱️ Starting: ${operation}`, this.context)\n }\n \n end(message?: string): number {\n const duration = Math.round(performance.now() - this.startTime)\n const msg = message || `✓ Completed: ${this.operation}`\n logger.debug(msg, { ...this.context, duration })\n return duration\n }\n \n checkpoint(label: string): number {\n const elapsed = Math.round(performance.now() - this.startTime)\n logger.debug(` ↳ ${label}`, { ...this.context, duration: elapsed })\n return elapsed\n }\n}\n\nexport class RequestContext {\n traceId: string\n method: string\n path: string\n startTime: number\n private checkpoints: Array<{ time: number; label: string }> = []\n \n constructor(method: string, path: string) {\n this.traceId = generateTraceId()\n this.method = method\n this.path = path\n this.startTime = performance.now()\n \n logger.debug(`→ ${method} ${path}`, { traceId: this.traceId, module: 'HTTP' })\n }\n \n checkpoint(label: string): void {\n const elapsed = Math.round(performance.now() - this.startTime)\n this.checkpoints.push({ time: elapsed, label })\n logger.debug(` → ${label}`, { traceId: this.traceId, duration: elapsed })\n }\n \n end(statusCode: number): void {\n const duration = Math.round(performance.now() - this.startTime)\n const statusColor = statusCode < 400 ? COLORS.green : COLORS.red\n logger.debug(`← ${this.method} ${this.path} ${statusColor}${statusCode}${COLORS.reset}`, {\n traceId: this.traceId,\n duration,\n checkpoints: this.checkpoints.length,\n })\n }\n \n error(error: Error | unknown): void {\n const duration = Math.round(performance.now() - this.startTime)\n logger.error(`✗ ${this.method} ${this.path}`, {\n traceId: this.traceId,\n duration,\n error,\n })\n }\n}\n\nexport function createLogger(module: string) {\n return {\n debug(message: string, context?: Omit<LogContext, 'module'>, ...args: unknown[]): void {\n logger.debug(message, { ...context, module }, ...args)\n },\n \n info(message: string, context?: Omit<LogContext, 'module'>, ...args: unknown[]): void {\n logger.info(message, { ...context, module }, ...args)\n },\n \n warn(message: string, context?: Omit<LogContext, 'module'>, ...args: unknown[]): void {\n logger.warn(message, { ...context, module }, ...args)\n },\n \n error(message: string, context?: Omit<LogContext, 'module'>, ...args: unknown[]): void {\n logger.error(message, { ...context, module }, ...args)\n },\n \n timer(operation: string, context?: Omit<LogContext, 'module'>): PerformanceTimer {\n return new PerformanceTimer(operation, { ...context, module })\n },\n }\n}\n\nexport function logMethod(\n target: unknown,\n propertyKey: string,\n descriptor: PropertyDescriptor\n): PropertyDescriptor {\n const originalMethod = descriptor.value\n const className = (target as { constructor: { name: string } }).constructor.name\n \n descriptor.value = async function (...args: unknown[]) {\n const timer = new PerformanceTimer(`${className}.${propertyKey}`)\n try {\n const result = await originalMethod.apply(this, args)\n timer.end()\n return result\n } catch (error) {\n timer.end('❌ Failed')\n throw error\n }\n }\n \n return descriptor\n}\n\nexport function formatBytes(bytes: number): string {\n if (bytes === 0) return '0B'\n const k = 1024\n const sizes = ['B', 'KB', 'MB', 'GB']\n const i = Math.floor(Math.log(bytes) / Math.log(k))\n return `${parseFloat((bytes / Math.pow(k, i)).toFixed(2))}${sizes[i]}`\n}\n\nexport function formatDuration(ms: number): string {\n if (ms < 1000) return `${ms}ms`\n if (ms < 60000) return `${(ms / 1000).toFixed(2)}s`\n const minutes = Math.floor(ms / 60000)\n const seconds = Math.round((ms % 60000) / 1000)\n return `${minutes}m ${seconds}s`\n}\n"]}
@@ -3,18 +3,5 @@
3
3
  * @description 用于将页面上下文信息注入到 AI 对话中
4
4
  */
5
5
  import type { Plugin } from "@opencode-ai/plugin";
6
- /**
7
- * OpenCode 页面上下文插件
8
- * @returns 插件钩子
9
- * @example
10
- * ```ts
11
- * // 在 opencode 配置中使用
12
- * import { PageContextPlugin } from './plugins/page-context'
13
- *
14
- * export default {
15
- * plugins: [PageContextPlugin]
16
- * }
17
- * ```
18
- */
19
6
  export declare const PageContextPlugin: Plugin;
20
7
  export default PageContextPlugin;