import { readFileSync } from "node:fs";
import { randomUUID } from "node:crypto";
import * as path from "node:path";
import * as Effect from "effect/Effect";
import { CommandId, ThreadId } from "@t3tools/contracts";
import { rpcClient, runPromise } from "./t3.ts";
const home = path.resolve(process.argv[2]!);
const runtime = JSON.parse(readFileSync(path.join(home, 'userdata/server-runtime.json'), 'utf8'));
await runPromise(Effect.scoped(Effect.gen(function* () {
  const client = yield* rpcClient(home, runtime.origin);
  yield* client['orchestration.dispatchCommand']({
    type:'thread.pull-request.link', commandId:CommandId.make(randomUUID()),
    threadId:ThreadId.make(process.argv[3]!), host:'github.com',
    repository:'Georgeaforest/forest-holding-site', number:1,
    url:'https://github.com/Georgeaforest/forest-holding-site/pull/1', source:'manual'
  });
})));
console.log('Linked the public Greek pull request; the server fetches its real title.');
