import { parseArgs } from "util";
import { FileSystemStorage, AgentFSBlobStorage, AgentFSSchemaStorage, AgentStorage } from "./agentfs.ts";
import { runTaskT1, runTaskT2, runTaskT3, TaskResult } from "./tasks.ts";
import { join } from "path";
import { rm } from "node:fs/promises";
async function main() {
const { values } = parseArgs({
args: Bun.argv,
options: {
condition: {
type: 'string',
short: 'c',
default: 'C0'
},
output: {
type: 'string',
short: 'o',
default: './experiments/output'
},
task: {
type: 'string',
short: 't', // Run specific task only? usually run all
}
},
allowPositionals: true
});
const condition = values.condition?.toUpperCase() || 'C0';
const outputDir = values.output || './experiments/output';
console.log(`π Starting AgentFS Benchmark`);
console.log(`Condition: ${condition}`);
console.log(`Output: ${outputDir}`);
// Cleanup previous run for this condition
const runDir = join(outputDir, condition);
await rm(runDir, { recursive: true, force: true }).catch(() => { });
let storage: AgentStorage;
// Factory
switch (condition) {
case 'C0':
storage = new FileSystemStorage(runDir);
break;
case 'C1':
await rm(runDir + '.db', { force: true }); // cleanup db file
storage = new AgentFSBlobStorage(runDir + '.db');
break;
case 'C2':
await rm(runDir + '.db', { force: true });
storage = new AgentFSSchemaStorage(runDir + '.db');
break;
default:
console.error(`Unknown condition: ${condition}`);
process.exit(1);
}
await storage.init();
const results: TaskResult[] = [];
// Run Suite
console.log(`\nπ Executing T1: Plan->Work Seam...`);
results.push(await runTaskT1(storage));
console.log(`π Executing T2: Iteration...`);
results.push(await runTaskT2(storage));
console.log(`π Executing T3: Retrieval...`);
results.push(await runTaskT3(storage));
storage.close();
// Report
console.log(`\nπ Results for ${condition}:`);
console.table(results.map(r => ({
Task: r.task,
Time: `${r.timeMs.toFixed(2)}ms`,
Help: r.helpCount,
Success: r.success ? 'β
' : 'β'
})));
}
main().catch(console.error);