feat(commands,audit): add /context command and proactive compaction audit events

This commit is contained in:
William Valentin
2026-02-16 16:08:21 -08:00
parent 9c8da41610
commit 21d57d991c
11 changed files with 173 additions and 20 deletions
+29 -1
View File
@@ -1,6 +1,6 @@
import { describe, it, expect, vi } from 'vitest';
import { createElevateCommand, createModelCommand, createQueueCommand } from './index.js';
import { createContextCommand, createElevateCommand, createModelCommand, createQueueCommand } from './index.js';
describe('builtin /model command', () => {
it('passes through the full argument string', async () => {
@@ -111,3 +111,31 @@ describe('builtin /queue command', () => {
expect(result).toEqual({ handled: true, text: 'reset' });
});
});
describe('builtin /context command', () => {
it('returns context usage text from services', async () => {
const cmd = createContextCommand();
const getContext = vi.fn(() => 'Context Usage\n\n75.0%');
const result = await cmd.execute([], {
channel: 'test',
senderId: 'user',
sessionId: 's1',
rawInput: '/context',
services: { getContext },
});
expect(getContext).toHaveBeenCalledOnce();
expect(result).toEqual({ handled: true, text: 'Context Usage\n\n75.0%' });
});
it('returns not-available when service is missing', async () => {
const cmd = createContextCommand();
const result = await cmd.execute([], {
channel: 'test',
senderId: 'user',
sessionId: 's1',
rawInput: '/context',
services: {},
});
expect(result).toEqual({ handled: true, text: 'Context command is not available in this session.' });
});
});