/**
* Example Tool
*
* A simple tool for testing hot-reload mechanism.
* Modify this file to test that changes are picked up without restart.
*/
import {
BaseTool,
type ToolIdentity,
type ToolContext,
type ToolResult,
type ToolClass,
} from '../core/tool-interface.js';
import type { ConversationState } from '../core/conversation-migration.js';
/**
* Example Tool Implementation
*
* VERSION: Change this to test hot-reload!
*/
class ExampleTool extends BaseTool {
constructor() {
super({
name: 'example-tool',
version: '2.2.1', // M4 Complete: Permission graduation witness test
capabilities: ['greet', 'echo', 'write-file', 'dangerous', 'sudo-test', 'evaluate', 'what-if'],
});
}
/**
* Execute tool action
*/
async execute(action: string, context: ToolContext): Promise<ToolResult> {
console.error(`[ExampleTool] Executing action: ${action}`);
console.error(`[ExampleTool] Alignment: ${context.alignmentCheck?.alignment || 'none'}`);
switch (action) {
case 'greet':
return {
success: true,
output: this.greet(),
};
case 'echo':
return {
success: true,
output: this.echo(context),
};
case 'write-file':
return this.writeFile(context);
case 'dangerous':
return this.dangerousAction(context);
case 'sudo-test':
return this.sudoTest(context);
default:
return {
success: false,
error: `Unknown action: ${action}. Available: greet, echo, write-file, dangerous`,
};
}
}
/**
* Greet action (M1 test)
*
* MODIFY THIS to test hot-reload!
*/
private greet(): string {
return `🎯 M2 Negotiation Ready! Version ${this.identity.version}`;
}
/**
* Echo action (M1 test)
*/
private echo(context: ToolContext): string {
return `Echo from conversation ${context.conversationId}`;
}
/**
* Write file action (M2 test - requires approval)
*
* Task 2.3: Approval Flow
* This action requires approval before execution
*/
private writeFile(context: ToolContext): ToolResult {
return {
success: true,
output: `✅ File write approved and executed (conversation: ${context.conversationId})`,
};
}
/**
* Dangerous action (M2 test - contradiction)
*
* Task 2.2: Alignment Detector
* This action should be blocked by alignment detector
*/
private dangerousAction(context: ToolContext): ToolResult {
// This should never execute due to alignment check
return {
success: false,
error: `⚠️ This action should have been blocked by alignment detector!`,
};
}
/**
* Sudo test action (M2 test - PERMISSION_BOUNDARY violation)
*
* Task 2.2: Alignment Detector
* This action name contains "sudo" which should trigger PERMISSION_BOUNDARY constraint
*/
private sudoTest(context: ToolContext): ToolResult {
// This should NEVER execute - should be blocked by alignment detector
return {
success: false,
error: `❌ SECURITY VIOLATION: sudo action reached execution! Alignment detector failed!`,
};
}
/**
* Restore state after hot-reload
*/
static fromState(state: ConversationState): ExampleTool {
const tool = new ExampleTool();
console.error(`[ExampleTool] Restored from state: conversation ${state.conversationId}`);
// Could restore tool-specific state here
return tool;
}
}
/**
* Tool Class Export
*
* Static identity property required for hot-reload
*/
const ExampleToolClass: ToolClass = Object.assign(ExampleTool, {
identity: {
name: 'example-tool',
version: '2.2.0', // ← Keep in sync with constructor version
capabilities: ['greet', 'echo', 'write-file', 'dangerous', 'sudo-test', 'evaluate', 'what-if'],
} as ToolIdentity,
actionSchemas: {
'greet': {
params: [],
required: [],
description: 'Greet and return tool version',
},
'echo': {
params: [],
required: [],
description: 'Echo conversation ID',
},
'write-file': {
params: [],
required: [],
description: 'Test write operation (requires approval)',
},
'dangerous': {
params: [],
required: [],
description: 'Test alignment detector (should be blocked)',
},
'sudo-test': {
params: [],
required: [],
description: 'Test permission boundary violation',
},
'evaluate': {
params: [],
required: [],
description: 'Hypothetical evaluation of an action',
},
'what-if': {
params: [],
required: [],
description: 'What-if analysis for an action',
},
},
});
export default ExampleToolClass;