import * as NodeCrypto from "@effect/platform-node/NodeCrypto"; import * as NetService from "@t3tools/shared/Net"; import * as NodeServices from "@effect/platform-node/NodeServices"; import * as Effect from "effect/Effect"; import * as Layer from "effect/Layer"; import * as Option from "effect/Option"; import * as References from "effect/References"; import * as EnvironmentAuth from "./src/auth/EnvironmentAuth.ts"; import * as ServerConfig from "./src/config.ts"; import { resolveCliAuthConfig } from "./src/cli/config.ts"; import { readPersistedServerRuntimeState } from "./src/serverRuntimeState.ts"; import { mcpToolSession } from "./src/mcp/AcpMcpStdioBridge.ts"; const [home, projectPath, worktreePath] = process.argv.slice(1); const program = Effect.gen(function* () { const config = yield* resolveCliAuthConfig({ baseDir: Option.some(home) }, Option.none(), { quietLogs: true }); return yield* Effect.gen(function* () { const state = yield* readPersistedServerRuntimeState(config.serverRuntimeStatePath); if (Option.isNone(state)) throw new Error("Scenario server is not running"); const auth = yield* EnvironmentAuth.EnvironmentAuth; const issued = yield* Effect.acquireRelease( auth.issueMcpClientSession({ label: "Branch proof", access: "full-access", peerLink: false, client: { deviceType: "bot" } }), session => auth.revokeSession(session.sessionId), ); const session = yield* mcpToolSession({ endpoint: new URL("/mcp", state.value.origin).href, authorization: `Bearer ${issued.token}`, clientName: "branch-proof" }); const call = (name, input) => session.call(name, input).pipe(Effect.map(result => { if (result.isError) throw new Error(JSON.stringify(result)); return result.structuredContent; })); const listed = yield* call("t3_project_list", {}); const project = listed.projects.find(p => p.workspaceRoot === projectPath); if (!project) throw new Error("Synthetic project missing"); const launched = yield* call("t3_thread_launch", { projectId: project.id, title: "Existing worktree branch", message: "Report the current branch without changing it", workspaceStrategy: { type: "existing_worktree", worktreePath }, modelSelection: { instanceId: "devReplay", model: "multi-turn" } }); yield* call("t3_thread_wait", { threadId: launched.threadId, runId: launched.runId, timeoutMs: 15000 }); console.log(JSON.stringify({ threadId: launched.threadId })); }).pipe(Effect.scoped, Effect.provide(EnvironmentAuth.layerRuntime.pipe(Layer.provide(ServerConfig.layer(config)), Layer.provide(Layer.succeed(References.MinimumLogLevel, config.logLevel))))); }); try { await Effect.runPromise(program.pipe(Effect.provide(Layer.mergeAll(NodeServices.layer, NodeCrypto.layer, NetService.layer)))); } catch (error) { console.error(String(error).slice(0, 500)); process.exitCode = 1; }