feat(coder): add TokenScope analyzer and DB persistence module
- analyzeMessages classifies message parts into system/user/assistant/tools/reasoning - persistTaskBreakdown writes JSONB to tasks table - Backfills the token-analysis/ module (contract committed earlier) - 6 unit tests covering classification, tool calls, reasoning tokens
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
import { describe, it, expect } from 'vitest';
|
||||
import { analyzeMessages } from '../analyzer.js';
|
||||
|
||||
describe('analyzeMessages', () => {
|
||||
it('classifies user messages', () => {
|
||||
const breakdown = analyzeMessages([{ role: 'user', content: 'hello world' }]);
|
||||
expect(breakdown.user).toBeGreaterThan(0);
|
||||
expect(breakdown.total).toBe(breakdown.user);
|
||||
});
|
||||
|
||||
it('counts tool calls', () => {
|
||||
const parts = [
|
||||
{ role: 'assistant', content: 'using grep', tool_calls: [{ id: '1', name: 'grep', arguments: '{}' }] },
|
||||
{ role: 'tool', content: '{"files":[]}', tool_call_id: '1' },
|
||||
];
|
||||
const breakdown = analyzeMessages(parts);
|
||||
expect(breakdown.tools).toBeGreaterThan(0);
|
||||
expect(breakdown.assistant).toBeGreaterThan(0);
|
||||
});
|
||||
|
||||
it('separates reasoning tokens', () => {
|
||||
const parts = [
|
||||
{ role: 'assistant', content: 'short answer', reasoning_parts: [{ text: 'long chain of thought reasoning here' }] },
|
||||
];
|
||||
const breakdown = analyzeMessages(parts);
|
||||
expect(breakdown.reasoning).toBeGreaterThan(0);
|
||||
expect(breakdown.assistant).toBeLessThan(breakdown.reasoning);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user