import { CommandId, ThreadId } from '@t3tools/contracts';
import * as Effect from 'effect/Effect';
import { writeFileSync } from 'node:fs';
import { makeState, rpcClient, runPromise } from './t3.ts';
const [action, home, origin, value] = process.argv.slice(2);
if (action === 'seed') {
  const {state} = makeState(home!);
  const project = await state.project('demo');
  const covered = await state.thread({project,title:'Original chat',messages:['first'],model:'multi-turn'});
  const focused = await state.thread({project,title:'Focused chat',messages:['first'],model:'multi-turn'});
  writeFileSync(value!, JSON.stringify({covered,focused}));
} else if (action === 'delete') {
  await runPromise(Effect.gen(function*(){
    const client = yield* rpcClient(home!, origin!);
    yield* client['orchestration.dispatchCommand']({type:'thread.delete',commandId:CommandId.make(crypto.randomUUID()),threadId:ThreadId.make(value!)});
  }).pipe(Effect.scoped));
}
