feat(commands,audit): add /context command and proactive compaction audit events
This commit is contained in:
@@ -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.' });
|
||||
});
|
||||
});
|
||||
|
||||
@@ -65,6 +65,22 @@ export function createUsageCommand(): CommandDefinition {
|
||||
};
|
||||
}
|
||||
|
||||
export function createContextCommand(): CommandDefinition {
|
||||
return {
|
||||
name: 'context',
|
||||
description: 'Show context window usage',
|
||||
execute: async (_args, ctx) => {
|
||||
if (!ctx.services?.getContext) {
|
||||
return notAvailable('Context command');
|
||||
}
|
||||
return {
|
||||
handled: true,
|
||||
text: await ctx.services.getContext(),
|
||||
};
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
export function createModelCommand(): CommandDefinition {
|
||||
return {
|
||||
name: 'model',
|
||||
@@ -183,6 +199,7 @@ export function registerBuiltinCommands(registry: CommandRegistry): void {
|
||||
registry.register(createHelpCommand(registry));
|
||||
registry.register(createStatusCommand());
|
||||
registry.register(createUsageCommand());
|
||||
registry.register(createContextCommand());
|
||||
registry.register(createModelCommand());
|
||||
registry.register(createCompactCommand());
|
||||
registry.register(createResetCommand());
|
||||
|
||||
@@ -4,6 +4,7 @@ export {
|
||||
createHelpCommand,
|
||||
createStatusCommand,
|
||||
createUsageCommand,
|
||||
createContextCommand,
|
||||
createModelCommand,
|
||||
createCompactCommand,
|
||||
createResetCommand,
|
||||
|
||||
@@ -21,6 +21,7 @@ export interface CommandDefinition {
|
||||
export interface CommandServices {
|
||||
getStatus?: () => Promise<string> | string;
|
||||
getUsage?: () => Promise<string> | string;
|
||||
getContext?: () => Promise<string> | string;
|
||||
getModel?: () => Promise<string> | string;
|
||||
setModel?: (tier: string) => Promise<string> | string;
|
||||
compact?: () => Promise<string> | string;
|
||||
|
||||
Reference in New Issue
Block a user