feat(commands,audit): add /context command and proactive compaction audit events
This commit is contained in:
@@ -82,6 +82,25 @@ describe('createAgentHandlers command fast-path', () => {
|
||||
expect((event.data as { content: string }).content).toContain('Token Usage');
|
||||
});
|
||||
|
||||
it('handles /context command via fast-path', async () => {
|
||||
const sent: OutboundMessage[] = [];
|
||||
const send = vi.fn((msg: OutboundMessage) => sent.push(msg));
|
||||
const req: GatewayRequest = {
|
||||
id: 8,
|
||||
method: 'agent.send',
|
||||
params: { message: '/context', connectionId: 'conn-1' },
|
||||
};
|
||||
|
||||
await handlers['agent.send'](req, send);
|
||||
|
||||
expect(mockAgent.process).not.toHaveBeenCalled();
|
||||
expect(sent).toHaveLength(1);
|
||||
const event = sent[0] as GatewayEvent;
|
||||
expect(event.event).toBe('done');
|
||||
expect((event.data as { content: string }).content).toContain('Context Usage');
|
||||
expect((event.data as { content: string }).content).toContain('Compaction threshold');
|
||||
});
|
||||
|
||||
it('handles metadata commands via fast-path', async () => {
|
||||
const sent: OutboundMessage[] = [];
|
||||
const send = vi.fn((msg: OutboundMessage) => sent.push(msg));
|
||||
|
||||
@@ -126,6 +126,19 @@ export function createAgentHandlers(deps: AgentHandlerDeps) {
|
||||
|
||||
return lines.join('\n');
|
||||
},
|
||||
getContext: () => {
|
||||
const budget = agent.getContextBudget();
|
||||
const lines = [
|
||||
'**Context Usage**',
|
||||
'',
|
||||
`Estimated: ${budget.estimatedTokens.toLocaleString()} / ${budget.contextWindow.toLocaleString()} tokens`,
|
||||
`Remaining: ${budget.remainingTokens.toLocaleString()} tokens`,
|
||||
`Usage: ${budget.usagePct.toFixed(1)}%`,
|
||||
`Compaction threshold: ${budget.thresholdPct}% (${budget.thresholdTokens.toLocaleString()} tokens)`,
|
||||
`Should compact: ${budget.shouldCompact ? 'yes' : 'no'}`,
|
||||
];
|
||||
return lines.join('\n');
|
||||
},
|
||||
getModel: () => `Current model tier: ${agent.getModelTier()}`,
|
||||
setModel: (input) => {
|
||||
const raw = input.trim();
|
||||
|
||||
Reference in New Issue
Block a user