Connect to T3 Code: auth, RPC client, shell and thread session

This commit is contained in:
Callum Alpass committed 2026-11-02 16:45:27 +11:00
commit c93244e7f4
12 files changed
+620

No files matched your search

+14
View File
@@ -0,0 +1,14 @@
// Exposes the pinned T3 Code workspace packages under node_modules/@t3tools so
// their package export maps resolve. They are TypeScript sources Bun runs as-is.
import { lstat, mkdir, readdir, rm, symlink } from "node:fs/promises";
import { join, relative } from "node:path";
const root = join(import.meta.dir, "..");
const packagesDir = join(root, "vendor/t3code/packages");
const scopeDir = join(root, "node_modules/@t3tools");
await mkdir(scopeDir, { recursive: true });
for (const name of await readdir(packagesDir)) {
const link = join(scopeDir, name);
await lstat(link).then(() => rm(link, { recursive: true, force: true }), () => {});
await symlink(relative(scopeDir, join(packagesDir, name)), link, "dir");
}
+25
View File
@@ -0,0 +1,25 @@
import { ORCHESTRATION_V2_WS_METHODS } from "@t3tools/contracts";
import * as Effect from "effect/Effect";
import * as Stream from "effect/Stream";
import { connect } from "../src/client/rpc.ts";
const program = Effect.gen(function* () {
const { rpc, target } = yield* connect;
console.log("connected to", target.httpBaseUrl);
yield* rpc[ORCHESTRATION_V2_WS_METHODS.subscribeShell]({ omitIdleSubagents: true, omitOlderSettled: true }).pipe(
Stream.take(3),
Stream.runForEach((item) =>
Effect.sync(() => {
if (item.kind === "snapshot") {
const s = item.snapshot as any;
console.log("snapshot keys:", Object.keys(s));
console.log("projects:", s.projects?.length, "threads:", s.threads?.length);
for (const t of (s.threads ?? []).slice(0, 8)) console.log(" -", t.status, t.activityRunStatus, t.pendingRuntimeRequest ? "[NEEDS YOU]" : "", t.title);
} else console.log("item:", item.kind);
}),
),
Effect.timeout("10 seconds"),
);
});
await Effect.runPromise(Effect.scoped(program)).catch((e) => { console.error("FAILED:", e); process.exit(1); });
process.exit(0);
+25
View File
@@ -0,0 +1,25 @@
import { T3Session } from "../src/client/session.ts";
const s = new T3Session();
await s.start();
await new Promise<void>((r) => { const off = s.onShell((st) => { if (st.status.type !== "connecting" && st.snapshot) { off(); r(); } }); });
const shell = s.getShell();
console.log("status", shell.status, "threads", shell.snapshot?.threads.length);
const counts: Record<string, number> = {};
for (const t of shell.snapshot!.threads) counts[t.status] = (counts[t.status] ?? 0) + 1;
console.log(counts);
const t = shell.snapshot!.threads.find((t) => t.status === "running") ?? shell.snapshot!.threads[0]!;
console.log("watching", t.title, t.status);
let events = 0;
const off = s.watchThread(t.id, (st) => {
events++;
if (st.projection && events < 4) {
const items = st.projection.visibleTurnItems;
console.log(st.status, "items", items.length, "types", [...new Set(items.map((i) => i.item.type))].join(","));
const last = items.at(-1)?.item as any;
console.log("last:", last?.type, String(last?.text ?? last?.input ?? "").slice(0, 120));
}
if (st.error) console.log("ERR", st.error);
});
await Bun.sleep(5000);
console.log("updates received", events);
off(); await s.stop(); process.exit(0);