/** * Basic Usage Example - FunctionalHarness * * @description Demonstrates basic usage of the FunctionalHarness with * state management, versioning, and command processing. */ // Import the harness components import { FunctionalHarness } from '../core/harness.js'; // Sample script that uses ..listen and ..emit const sampleScript = ` /* Sample script demonstrating ..listen and ..emit */ /* Get current state */ current_state : ..listen; /* Process the state */ processed_data : when current_state is { status: "active" } then { result: "active_processed", data: current_state } { status: "inactive" } then { result: "inactive_processed", data: current_state } _ then { result: "unknown_processed", data: current_state }; /* Emit the processed data */ ..emit processed_data; /* Emit a status update */ ..emit { action: "status_update", timestamp: 1234567890 }; `; async function runBasicExample() { console.log('=== Basic Harness Usage Example ===\n'); // Create harness with script content const harness = new FunctionalHarness(sampleScript, { logStateChanges: true, logCommands: true }); // Initial state const initialState = { status: "active", user: { name: "Alice", score: 100 }, settings: { theme: "dark" } }; console.log('1. Processing initial state...'); const result1 = await harness.processState(initialState); console.log('Result:', JSON.stringify(result1, null, 2)); console.log('\n2. Processing state change...'); const newState = { status: "inactive", user: { name: "Alice", score: 150 }, settings: { theme: "light" } }; const result2 = await harness.processState(newState); console.log('Result:', JSON.stringify(result2, null, 2)); console.log('\n3. Version history...'); const history = harness.getVersionHistory(); console.log('History:', JSON.stringify(history, null, 2)); console.log('\n4. State diff...'); const diff = harness.stateHistory.getDiff(1, 2); console.log('Diff:', JSON.stringify(diff, null, 2)); console.log('\n=== Example Complete ==='); } // Run the example runBasicExample().catch(console.error); export { runBasicExample };