@teamvibe/poller 0.2.1 → 0.2.2
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/logger.js +28 -22
- package/package.json +1 -1
- package/dist/control-handler.test.d.ts +0 -1
- package/dist/control-handler.test.js +0 -74
package/dist/logger.js
CHANGED
|
@@ -14,8 +14,8 @@ if (!existsSync(SESSIONS_DIR)) {
|
|
|
14
14
|
function formatDate(date) {
|
|
15
15
|
return date.toISOString();
|
|
16
16
|
}
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
const now = () => formatDate(new Date());
|
|
18
|
+
function writeToFile(level, message, timestamp, ...args) {
|
|
19
19
|
const formattedArgs = args
|
|
20
20
|
.map((arg) => (typeof arg === 'object' ? JSON.stringify(arg) : String(arg)))
|
|
21
21
|
.join(' ');
|
|
@@ -35,8 +35,7 @@ export class SessionLogger {
|
|
|
35
35
|
const timestamp = new Date().toISOString().replace(/[:.]/g, '-');
|
|
36
36
|
this.logFile = join(SESSIONS_DIR, `${timestamp}_${sessionId}.log`);
|
|
37
37
|
}
|
|
38
|
-
write(level, message) {
|
|
39
|
-
const timestamp = formatDate(new Date());
|
|
38
|
+
write(level, message, timestamp) {
|
|
40
39
|
const logLine = `[${timestamp}] [${level}] ${message}\n`;
|
|
41
40
|
try {
|
|
42
41
|
appendFileSync(this.logFile, logLine);
|
|
@@ -46,27 +45,30 @@ export class SessionLogger {
|
|
|
46
45
|
}
|
|
47
46
|
}
|
|
48
47
|
info(message) {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
48
|
+
const ts = now();
|
|
49
|
+
console.log(`[${ts}] [${this.sessionId}] ${message}`);
|
|
50
|
+
this.write('INFO', message, ts);
|
|
51
|
+
writeToFile('INFO', `[${this.sessionId}] ${message}`, ts);
|
|
52
52
|
}
|
|
53
53
|
error(message) {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
54
|
+
const ts = now();
|
|
55
|
+
console.error(`[${ts}] [${this.sessionId}] ${message}`);
|
|
56
|
+
this.write('ERROR', message, ts);
|
|
57
|
+
writeToFile('ERROR', `[${this.sessionId}] ${message}`, ts);
|
|
57
58
|
}
|
|
58
59
|
claude(stream, message) {
|
|
60
|
+
const ts = now();
|
|
59
61
|
const prefix = `[Claude ${stream}]`;
|
|
60
62
|
if (stream === 'stderr') {
|
|
61
|
-
console.error(`[${this.sessionId}] ${prefix}`, message);
|
|
63
|
+
console.error(`[${ts}] [${this.sessionId}] ${prefix}`, message);
|
|
62
64
|
}
|
|
63
65
|
else {
|
|
64
|
-
console.log(`[${this.sessionId}] ${prefix}`, message);
|
|
66
|
+
console.log(`[${ts}] [${this.sessionId}] ${prefix}`, message);
|
|
65
67
|
}
|
|
66
|
-
this.write(`CLAUDE_${stream.toUpperCase()}`, message);
|
|
68
|
+
this.write(`CLAUDE_${stream.toUpperCase()}`, message, ts);
|
|
67
69
|
}
|
|
68
70
|
logPrompt(prompt) {
|
|
69
|
-
this.write('PROMPT', `\n${'='.repeat(50)}\n${prompt}\n${'='.repeat(50)}
|
|
71
|
+
this.write('PROMPT', `\n${'='.repeat(50)}\n${prompt}\n${'='.repeat(50)}`, now());
|
|
70
72
|
}
|
|
71
73
|
getLogFile() {
|
|
72
74
|
return this.logFile;
|
|
@@ -74,22 +76,26 @@ export class SessionLogger {
|
|
|
74
76
|
}
|
|
75
77
|
export const logger = {
|
|
76
78
|
info(message, ...args) {
|
|
77
|
-
|
|
78
|
-
|
|
79
|
+
const ts = now();
|
|
80
|
+
console.log(`[${ts}] [INFO] ${message}`, ...args);
|
|
81
|
+
writeToFile('INFO', message, ts, ...args);
|
|
79
82
|
},
|
|
80
83
|
error(message, ...args) {
|
|
81
|
-
|
|
82
|
-
|
|
84
|
+
const ts = now();
|
|
85
|
+
console.error(`[${ts}] [ERROR] ${message}`, ...args);
|
|
86
|
+
writeToFile('ERROR', message, ts, ...args);
|
|
83
87
|
},
|
|
84
88
|
warn(message, ...args) {
|
|
85
|
-
|
|
86
|
-
|
|
89
|
+
const ts = now();
|
|
90
|
+
console.warn(`[${ts}] [WARN] ${message}`, ...args);
|
|
91
|
+
writeToFile('WARN', message, ts, ...args);
|
|
87
92
|
},
|
|
88
93
|
debug(message, ...args) {
|
|
94
|
+
const ts = now();
|
|
89
95
|
if (process.env['DEBUG']) {
|
|
90
|
-
console.debug(message
|
|
96
|
+
console.debug(`[${ts}] [DEBUG] ${message}`, ...args);
|
|
91
97
|
}
|
|
92
|
-
writeToFile('DEBUG', message, ...args);
|
|
98
|
+
writeToFile('DEBUG', message, ts, ...args);
|
|
93
99
|
},
|
|
94
100
|
createSession(sessionId) {
|
|
95
101
|
return new SessionLogger(sessionId);
|
package/package.json
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
import { describe, test, expect } from 'bun:test';
|
|
2
|
-
import { isControlMessage } from './control-handler.js';
|
|
3
|
-
import { classifyUpdate } from './auto-update.js';
|
|
4
|
-
describe('isControlMessage', () => {
|
|
5
|
-
test('valid restart message', () => {
|
|
6
|
-
expect(isControlMessage({ source: 'control', action: 'restart' })).toBe(true);
|
|
7
|
-
});
|
|
8
|
-
test('valid update message', () => {
|
|
9
|
-
expect(isControlMessage({ source: 'control', action: 'update' })).toBe(true);
|
|
10
|
-
});
|
|
11
|
-
test('valid update with targetVersion', () => {
|
|
12
|
-
expect(isControlMessage({ source: 'control', action: 'update', targetVersion: '1.2.3' })).toBe(true);
|
|
13
|
-
});
|
|
14
|
-
test('rejects non-control source', () => {
|
|
15
|
-
expect(isControlMessage({ source: 'slack', action: 'restart' })).toBe(false);
|
|
16
|
-
});
|
|
17
|
-
test('rejects unknown action', () => {
|
|
18
|
-
expect(isControlMessage({ source: 'control', action: 'delete' })).toBe(false);
|
|
19
|
-
});
|
|
20
|
-
test('rejects null', () => {
|
|
21
|
-
expect(isControlMessage(null)).toBe(false);
|
|
22
|
-
});
|
|
23
|
-
test('rejects undefined', () => {
|
|
24
|
-
expect(isControlMessage(undefined)).toBe(false);
|
|
25
|
-
});
|
|
26
|
-
test('rejects string', () => {
|
|
27
|
-
expect(isControlMessage('control')).toBe(false);
|
|
28
|
-
});
|
|
29
|
-
test('rejects empty object', () => {
|
|
30
|
-
expect(isControlMessage({})).toBe(false);
|
|
31
|
-
});
|
|
32
|
-
test('rejects regular queue message', () => {
|
|
33
|
-
expect(isControlMessage({
|
|
34
|
-
id: '123',
|
|
35
|
-
source: 'cron',
|
|
36
|
-
thread_id: 'thread1',
|
|
37
|
-
sender: { id: 'user1', name: 'Test' },
|
|
38
|
-
text: 'hello',
|
|
39
|
-
})).toBe(false);
|
|
40
|
-
});
|
|
41
|
-
});
|
|
42
|
-
describe('classifyUpdate', () => {
|
|
43
|
-
test('detects patch update', () => {
|
|
44
|
-
expect(classifyUpdate('1.2.3', '1.2.4')).toBe('patch');
|
|
45
|
-
});
|
|
46
|
-
test('detects minor update', () => {
|
|
47
|
-
expect(classifyUpdate('1.2.3', '1.3.0')).toBe('minor');
|
|
48
|
-
});
|
|
49
|
-
test('detects major update', () => {
|
|
50
|
-
expect(classifyUpdate('1.2.3', '2.0.0')).toBe('major');
|
|
51
|
-
});
|
|
52
|
-
test('returns null for same version', () => {
|
|
53
|
-
expect(classifyUpdate('1.2.3', '1.2.3')).toBeNull();
|
|
54
|
-
});
|
|
55
|
-
test('returns null for downgrade (patch)', () => {
|
|
56
|
-
expect(classifyUpdate('1.2.4', '1.2.3')).toBeNull();
|
|
57
|
-
});
|
|
58
|
-
test('returns null for downgrade (minor)', () => {
|
|
59
|
-
expect(classifyUpdate('1.3.0', '1.2.5')).toBeNull();
|
|
60
|
-
});
|
|
61
|
-
test('returns null for downgrade (major)', () => {
|
|
62
|
-
expect(classifyUpdate('2.0.0', '1.9.9')).toBeNull();
|
|
63
|
-
});
|
|
64
|
-
test('handles zero versions', () => {
|
|
65
|
-
expect(classifyUpdate('0.0.1', '0.0.2')).toBe('patch');
|
|
66
|
-
expect(classifyUpdate('0.1.0', '0.2.0')).toBe('minor');
|
|
67
|
-
});
|
|
68
|
-
test('minor update with different patch', () => {
|
|
69
|
-
expect(classifyUpdate('1.2.3', '1.3.5')).toBe('minor');
|
|
70
|
-
});
|
|
71
|
-
test('major update with different minor/patch', () => {
|
|
72
|
-
expect(classifyUpdate('1.2.3', '2.1.0')).toBe('major');
|
|
73
|
-
});
|
|
74
|
-
});
|