From d4b8866bb2a86f29c5069ca0345fffa0e1bc319d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mat=C4=9Bj=20Such=C3=A1nek?= <16311043+immakermatty@users.noreply.github.com> Date: Wed, 18 Nov 2026 19:20:02 +0000 Subject: [PATCH 01/12] chore(lazurio): R3 design for Buddy's window over one thread of the shared server MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The design is in the pull request; code follows on this branch. Agent: environment a480495c-25e0-4e51-828b-1dbf1b77d62f · T3 thread 72068f77-568a-48aa-aa8a-108c03b29972 Co-Authored-By: Claude Opus 5.5 From ec713f96d74241a0f6f932f979997a0da2720474 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mat=C4=9Bj=20Such=C3=A1nek?= <16311043+immakermatty@users.noreply.github.com> Date: Wed, 18 Nov 2026 19:28:01 +0000 Subject: [PATCH 02/12] feat(lazurio): Buddy's thread, days and page context on the shared server (R3, server) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit T3CODE_LAZURIO_BUDDY_ORIGIN names Buddy's window's own origin beside the Buddy folder and reaches clients as lazurioBuddyOrigin. On a shared server the thread route answers the oldest root thread of Buddy's project, or makes one on the project's, the Environment's or the Lazurio project's model; the days route reads that thread; a message with a page record gets the page block on any provider. Buddy's own server (GEN3) keeps its paths. Agent: environment a480495c-25e0-4e51-828b-1dbf1b77d62f · T3 thread 72068f77-568a-48aa-aa8a-108c03b29972 Co-Authored-By: Claude Opus 5.5 --- apps/server/src/config.ts | 2 + apps/server/src/lazurio/buddyPrompt.test.ts | 28 +++-- apps/server/src/lazurio/buddyPrompt.ts | 5 +- apps/server/src/lazurio/buddySurfaceDays.ts | 31 ++++- .../src/lazurio/buddySurfaceThread.test.ts | 118 +++++++++++++++++- apps/server/src/lazurio/buddySurfaceThread.ts | 117 ++++++++++++++++- .../src/lazurio/buddySurfaceThreadRoute.ts | 7 ++ apps/server/src/lazurio/managedFolder.ts | 6 + .../src/lazurio/managedFolderConfig.test.ts | 42 +++++++ .../server/src/lazurio/managedFolderConfig.ts | 20 +++ packages/contracts/src/server.ts | 2 + 11 files changed, 357 insertions(+), 21 deletions(-) diff --git a/apps/server/src/config.ts b/apps/server/src/config.ts index 47e9fa237654..121618c9c0c8 100644 --- a/apps/server/src/config.ts +++ b/apps/server/src/config.ts @@ -96,6 +96,8 @@ export class ServerConfig extends Context.Service< readonly lazurioFolder?: string; /** The Buddy folder beside the Folder, declared with it (`T3CODE_LAZURIO_BUDDY_FOLDER`). */ readonly lazurioBuddyFolder?: string; + /** Buddy's window's own origin, routed to this server (`T3CODE_LAZURIO_BUDDY_ORIGIN`). */ + readonly lazurioBuddyOrigin?: string; readonly lazurioToolsUrl?: string; readonly baseDir: string; readonly staticDir: string | undefined; diff --git a/apps/server/src/lazurio/buddyPrompt.test.ts b/apps/server/src/lazurio/buddyPrompt.test.ts index 92f306d2eb2c..fe6170a7be56 100644 --- a/apps/server/src/lazurio/buddyPrompt.test.ts +++ b/apps/server/src/lazurio/buddyPrompt.test.ts @@ -189,23 +189,29 @@ describe("the projection a provider turn gets", () => { }).pipe(Effect.provideService(HostProcess.Environment, BUDDY_ENV)), ); - it.effect("is upstream's for another instance of Buddy's T3 Code", () => + // Only Buddy's window adds a page record, so its page block reaches any provider (GEN4). + it.effect( + "is Buddy's for a message with a page record on any instance, also without the switch", + () => + Effect.gen(function* () { + for (const instanceId of [ProviderInstanceId.make("codex"), BUDDY]) { + const text = yield* projectComposerContextForProvider({ ...input, instanceId }); + assert.strictEqual(text, buddyProviderText(input)); + assert.include(text, "Kontext stránky"); + } + }).pipe(Effect.provideService(HostProcess.Environment, { T3CODE_LAZURIO_BUDDY: "true" })), + ); + + it.effect("is upstream's for a message without a page record on any other instance", () => Effect.gen(function* () { + const plain = { text: "Ahoj", records: [] }; const text = yield* projectComposerContextForProvider({ - ...input, + ...plain, instanceId: ProviderInstanceId.make("codex"), }); - assert.strictEqual(text, projectUpstream(input)); - assert.include(text, " - Effect.gen(function* () { - const text = yield* projectComposerContextForProvider({ ...input, instanceId: BUDDY }); - assert.strictEqual(text, projectUpstream(input)); - }).pipe(Effect.provideService(HostProcess.Environment, { T3CODE_LAZURIO_BUDDY: "true" })), - ); }); // What reaches the agent: the repository's mock ACP agent stands in for Hermes and logs every diff --git a/apps/server/src/lazurio/buddyPrompt.ts b/apps/server/src/lazurio/buddyPrompt.ts index e42762668fd9..d746f72634db 100644 --- a/apps/server/src/lazurio/buddyPrompt.ts +++ b/apps/server/src/lazurio/buddyPrompt.ts @@ -131,7 +131,8 @@ export function buddyProviderText(input: { } /** - * The text a provider turn gets for a message: Buddy's projection for Buddy's instance, upstream's + * The text a provider turn gets for a message: Buddy's projection for Buddy's instance and for any + * message with a page record, which only Buddy's window adds (GEN4 on any provider); upstream's * for every other. */ export const projectComposerContextForProvider = Effect.fn( @@ -142,7 +143,7 @@ export const projectComposerContextForProvider = Effect.fn( readonly records: ReadonlyArray; }) { const environment = yield* HostProcess.Environment; - return isBuddyInstance(environment, input.instanceId) + return isBuddyInstance(environment, input.instanceId) || input.records.some(isPageRecord) ? buddyProviderText(input) : projectUpstream(input); }); diff --git a/apps/server/src/lazurio/buddySurfaceDays.ts b/apps/server/src/lazurio/buddySurfaceDays.ts index fc4dcafccba5..644e7ebd3934 100644 --- a/apps/server/src/lazurio/buddySurfaceDays.ts +++ b/apps/server/src/lazurio/buddySurfaceDays.ts @@ -19,7 +19,9 @@ import { OrchestratorV2 } from "../orchestration-v2/Orchestrator.ts"; import { ActingSenders } from "./actingSenders.ts"; import { type ActingSendersRecord, personSeesMessage } from "./actingSenderVisibility.ts"; import { isBuddySurfaceEnvironment } from "./buddySurface.ts"; -import { BUDDY_THREAD_ID } from "./buddySurfaceThread.ts"; +import * as ServerConfig from "../config.ts"; +import { ProjectStoreV2 } from "../orchestration-v2/ProjectStore.ts"; +import { BUDDY_THREAD_ID, findSharedBuddyThread, sharedBuddyFolder } from "./buddySurfaceThread.ts"; import { authenticateOverlayRoute } from "./routeAuth.ts"; const BUDDY_DAYS_ROUTE = "/api/lazurio/buddy/days"; @@ -114,22 +116,39 @@ export const layer = HttpRouter.use((router) => // A handler sees only the request's context, so it takes the orchestrator from the layer's. const orchestrator = yield* OrchestratorV2; const senders = yield* ActingSenders; + const config = yield* ServerConfig.ServerConfig; + const projects = yield* ProjectStoreV2; yield* router.add( "GET", BUDDY_DAYS_ROUTE, Effect.gen(function* () { yield* authenticateOverlayRoute(AuthOrchestrationReadScope); - if (!isBuddySurfaceEnvironment(yield* HostProcess.Environment)) - return HttpServerResponse.jsonUnsafe({ error: "not-buddy" }, { status: 404 }); + // GEN3: the server's one thread; GEN4: Buddy's thread of the shared server. + let threadId = BUDDY_THREAD_ID; + if (!isBuddySurfaceEnvironment(yield* HostProcess.Environment)) { + const buddyFolder = yield* sharedBuddyFolder.pipe( + Effect.provideService(ServerConfig.ServerConfig, config), + ); + if (buddyFolder === undefined) + return HttpServerResponse.jsonUnsafe({ error: "not-buddy" }, { status: 404 }); + const found = yield* findSharedBuddyThread(buddyFolder).pipe( + Effect.provideService(OrchestratorV2, orchestrator), + Effect.provideService(ProjectStoreV2, projects), + Effect.option, + ); + const thread = Option.getOrUndefined(found)?.thread ?? null; + if (thread === null) return HttpServerResponse.jsonUnsafe({ days: [] }); + threadId = thread.id; + } const request = yield* HttpServerRequest.HttpServerRequest; const timeZone = timeZoneOf(new URL(request.url, "http://local").searchParams.get("tz")); - const shell = yield* orchestrator.getThreadShell(BUDDY_THREAD_ID).pipe(Effect.orDie); + const shell = yield* orchestrator.getThreadShell(threadId).pipe(Effect.orDie); if (shell === null) return HttpServerResponse.jsonUnsafe({ days: [] }); const records = yield* orchestrator - .getThreadRecords(BUDDY_THREAD_ID, ["messages"], { messageRoles: ["user"] }) + .getThreadRecords(threadId, ["messages"], { messageRoles: ["user"] }) .pipe(Effect.orDie); // As the web without the record: every message shows. - const answer = yield* senders.read(BUDDY_THREAD_ID).pipe(Effect.option); + const answer = yield* senders.read(threadId).pipe(Effect.option); const record = Option.match(answer, { onNone: () => null, onSome: ({ at, records }) => ({ diff --git a/apps/server/src/lazurio/buddySurfaceThread.test.ts b/apps/server/src/lazurio/buddySurfaceThread.test.ts index 0ed259a08b2b..54c7ca98601b 100644 --- a/apps/server/src/lazurio/buddySurfaceThread.test.ts +++ b/apps/server/src/lazurio/buddySurfaceThread.test.ts @@ -4,10 +4,14 @@ import * as NodeOS from "node:os"; import * as NodePath from "node:path"; import { assert, describe, it } from "@effect/vitest"; -import { CommandId, ProjectId } from "@t3tools/contracts"; +import { CommandId, ProjectId, ProviderInstanceId, ThreadId } from "@t3tools/contracts"; import * as HostProcess from "@t3tools/shared/HostProcess"; import * as Effect from "effect/Effect"; import * as Exit from "effect/Exit"; +import * as Layer from "effect/Layer"; + +import * as ServerConfig from "../config.ts"; +import * as ServerSettings from "../serverSettings.ts"; import * as Orchestrator from "../orchestration-v2/Orchestrator.ts"; import { BUDDY, addProject, layerBuddyServer } from "./buddySurface.testkit.ts"; @@ -203,4 +207,116 @@ describe("Buddy's thread", () => { ); }, ); + + describe("on the shared Chat server (GEN4, LZD-0033 R3)", () => { + /** A managed Folder and a Buddy folder beside it, as #214 declares them. */ + const makeShared = () => { + const home = NodeFS.mkdtempSync(NodePath.join(NodeOS.tmpdir(), "buddy-shared-home-")); + const folder = NodePath.join(home, "Lazurio"); + const buddy = NodePath.join(home, "Buddy"); + NodeFS.mkdirSync(folder); + NodeFS.mkdirSync(buddy); + return { home, folder, buddy }; + }; + const shared = (folder: string, buddy: string) => + Effect.map(ServerConfig.ServerConfig, (config) => ({ + ...config, + lazurioFolder: folder, + lazurioBuddyFolder: buddy, + })); + const withShared = (effect: Effect.Effect, folder: string, buddy: string) => + Effect.flatMap(shared(folder, buddy), (config) => + effect.pipe(Effect.provideService(ServerConfig.ServerConfig, config)), + ); + + it.live("makes one thread in Buddy's project on the Environment's default model", () => { + const { home, folder, buddy } = makeShared(); + return Effect.gen(function* () { + const orchestrator = yield* Orchestrator.OrchestratorV2; + const settings = yield* ServerSettings.ServerSettingsService; + // No Environment default yet: the Lazurio project's model (the Platform's recommendation). + const recommended = { instanceId: ProviderInstanceId.make("codex"), model: "gpt-6.1-sol" }; + yield* settings.updateSettings({ + projectSettingsOverrides: { + [ProjectId.make("project:lazurio")]: { defaultModelSelection: recommended }, + }, + }); + yield* addProject(ProjectId.make("project:lazurio"), folder); + yield* addProject(ProjectId.make("project:buddy"), buddy); + const [first, second] = yield* Effect.all( + [ + withShared(resolveBuddyThread(), folder, buddy), + withShared(resolveBuddyThread(), folder, buddy), + ], + { concurrency: 2 }, + ); + assert.deepStrictEqual(second, first); + assert.strictEqual(first.projectId, "project:buddy"); + const shell = yield* orchestrator.getThreadShell(first.threadId); + assert.deepStrictEqual(shell?.modelSelection, recommended); + assert.notStrictEqual(shell?.providerInstanceId, BUDDY); + const snapshot = yield* orchestrator.getShellSnapshot({ + projectId: ProjectId.make("project:buddy"), + }); + assert.lengthOf(snapshot.threads, 1); + }).pipe( + Effect.provide(Layer.merge(layerBuddyServer, ServerSettings.layerTest())), + Effect.scoped, + Effect.provideService(HostProcess.Environment, { HOME: home }), + ); + }); + + it.live("adopts the thread the project already has, whatever its provider", () => { + const { home, folder, buddy } = makeShared(); + return Effect.gen(function* () { + const orchestrator = yield* Orchestrator.OrchestratorV2; + yield* addProject(ProjectId.make("project:buddy"), buddy); + yield* orchestrator.dispatch({ + type: "thread.create", + createdBy: "user", + creationSource: "web", + commandId: CommandId.make("test:pilot-thread"), + threadId: ThreadId.make("pilot-thread"), + projectId: ProjectId.make("project:buddy"), + title: "Buddy", + modelSelection: { + instanceId: ProviderInstanceId.make("claudeAgent"), + model: "claude-model", + }, + runtimeMode: "full-access", + interactionMode: "default", + branch: null, + worktreePath: null, + }); + assert.deepStrictEqual(yield* withShared(resolveBuddyThread(), folder, buddy), { + threadId: ThreadId.make("pilot-thread"), + projectId: ProjectId.make("project:buddy"), + }); + }).pipe( + Effect.provide(Layer.merge(layerBuddyServer, ServerSettings.layerTest())), + Effect.scoped, + Effect.provideService(HostProcess.Environment, { HOME: home }), + ); + }); + + it.live( + "answers no-project before the startup made Buddy's project, and not-buddy without one", + () => { + const { home, folder, buddy } = makeShared(); + return Effect.gen(function* () { + const reason = (exit: Exit.Exit) => + Exit.isFailure(exit) ? JSON.stringify(exit.cause) : "succeeded"; + assert.include( + reason(yield* Effect.exit(withShared(resolveBuddyThread(), folder, buddy))), + "no-project", + ); + assert.include(reason(yield* Effect.exit(resolveBuddyThread())), "not-buddy"); + }).pipe( + Effect.provide(Layer.merge(layerBuddyServer, ServerSettings.layerTest())), + Effect.scoped, + Effect.provideService(HostProcess.Environment, { HOME: home }), + ); + }, + ); + }); }); diff --git a/apps/server/src/lazurio/buddySurfaceThread.ts b/apps/server/src/lazurio/buddySurfaceThread.ts index d978867802cc..af7464a6c4ff 100644 --- a/apps/server/src/lazurio/buddySurfaceThread.ts +++ b/apps/server/src/lazurio/buddySurfaceThread.ts @@ -9,11 +9,16 @@ import * as HostProcess from "@t3tools/shared/HostProcess"; import * as Context from "effect/Context"; import * as DateTime from "effect/DateTime"; import * as Effect from "effect/Effect"; +import * as Option from "effect/Option"; import * as Path from "effect/Path"; import * as Schema from "effect/Schema"; +import { resolveProjectSettings } from "@t3tools/shared/projectSettings"; + +import * as ServerConfig from "../config.ts"; import { OrchestratorV2 } from "../orchestration-v2/Orchestrator.ts"; import { ProjectStoreV2 } from "../orchestration-v2/ProjectStore.ts"; +import { ServerSettingsService } from "../serverSettings.ts"; import { BUDDY_PROVIDER_INSTANCE_ID, buddyProjectFolder, @@ -96,13 +101,123 @@ const conflict = () => detail: `A thread with Buddy's id "${BUDDY_THREAD_ID}" is not in Buddy's project on the instance "${BUDDY_PROVIDER_INSTANCE_ID}".`, }); +/** + * Buddy GEN4 (plan LZD-0033, R3): on the shared Chat server Buddy's project is the one over the + * declared Buddy folder (#214), and Buddy's thread is its oldest root thread. Archiving one is + * refused and the startup brings archived ones back, so this is the conversation the person had. + */ +const sharedBuddyProject = Effect.fn("LazurioBuddySurface.sharedBuddyProject")(function* ( + buddyFolder: string, +) { + const projects = yield* (yield* ProjectStoreV2).list().pipe(Effect.mapError(unavailable)); + const project = projects.find((candidate) => candidate.workspaceRoot === buddyFolder); + if (project === undefined) + return yield* new BuddyThreadUnavailable({ + reason: "no-project", + detail: `Buddy's project ${buddyFolder} is not in this T3 Code yet.`, + }); + return project; +}); + +/** Buddy's thread on the shared server: the oldest root thread of Buddy's project, if any. */ +export const findSharedBuddyThread = Effect.fn("LazurioBuddySurface.findSharedThread")(function* ( + buddyFolder: string, +) { + const project = yield* sharedBuddyProject(buddyFolder); + const { threads } = yield* (yield* OrchestratorV2) + .getShellSnapshot({ projectId: project.projectId }) + .pipe(Effect.mapError(unavailable)); + const roots = threads.filter( + (thread) => + thread.projectId === project.projectId && + thread.lineage.parentThreadId === null && + thread.delegatedFrom === undefined, + ); + const oldest = roots.toSorted( + (left, right) => + DateTime.toEpochMillis(left.createdAt) - DateTime.toEpochMillis(right.createdAt), + )[0]; + return { project, thread: oldest ?? null }; +}); + +/** + * Buddy's thread on the shared server, made on the project's default model the first time anyone + * asks. Its id and command derive from the project, so two first visits make one thread. + */ +const resolveSharedBuddyThread = Effect.fn("LazurioBuddySurface.resolveSharedThread")(function* ( + buddyFolder: string, +) { + const { project, thread } = yield* findSharedBuddyThread(buddyFolder); + if (thread !== null) + return { threadId: thread.id, projectId: project.projectId } satisfies BuddyThread; + const settingsService = yield* Effect.serviceOption(ServerSettingsService); + if (Option.isNone(settingsService)) + return yield* new BuddyThreadUnavailable({ + reason: "unavailable", + detail: "This T3 Code cannot read its settings for Buddy's first thread.", + }); + const settings = yield* settingsService.value.getSettings.pipe(Effect.mapError(unavailable)); + // Buddy's project's own model, else the Environment's default, else the Lazurio project's, where + // a hosted Environment keeps the Platform's recommended model (modelRecommendation.ts). + const folder = (yield* ServerConfig.ServerConfig).lazurioFolder; + const folderProject = (yield* (yield* ProjectStoreV2) + .list() + .pipe(Effect.mapError(unavailable))).find((candidate) => candidate.workspaceRoot === folder); + const modelSelection = + resolveProjectSettings(settings, project.projectId).settings.defaultModelSelection ?? + (folderProject === undefined + ? null + : resolveProjectSettings(settings, folderProject.projectId).settings.defaultModelSelection); + if (modelSelection === null) + return yield* new BuddyThreadUnavailable({ + reason: "unavailable", + detail: "This Environment has no default model for Buddy's first thread.", + }); + const threadId = ThreadId.make(`lazurio-buddy:${project.projectId}`); + const orchestrator = yield* OrchestratorV2; + yield* orchestrator + .dispatch({ + type: "thread.create", + createdBy: "user", + creationSource: "server", + commandId: CommandId.make(`lazurio:buddy-thread:create:${project.projectId}`), + threadId, + projectId: project.projectId, + title: "Buddy", + modelSelection, + // Buddy works with the Osobní Prostředí's full rights (root decision 0210). + runtimeMode: "full-access", + interactionMode: "default", + branch: null, + worktreePath: null, + }) + .pipe(Effect.mapError(unavailable)); + const created = yield* orchestrator.getThreadShell(threadId).pipe(Effect.mapError(unavailable)); + if (created === null) + return yield* new BuddyThreadUnavailable({ + reason: "unavailable", + detail: "Buddy's thread was deleted.", + }); + return { threadId, projectId: project.projectId } satisfies BuddyThread; +}); + +/** The Buddy folder of a shared server that declares one (GEN4), or undefined. */ +export const sharedBuddyFolder = Effect.map(ServerConfig.ServerConfig, (config) => + typeof config.lazurioFolder === "string" && typeof config.lazurioBuddyFolder === "string" + ? config.lazurioBuddyFolder + : undefined, +); + /** Buddy's thread, made in Buddy's project the first time anyone asks. */ export const resolveBuddyThread = Effect.fn("LazurioBuddySurface.resolveThread")(function* () { - if (!isBuddySurfaceEnvironment(yield* HostProcess.Environment)) + if (!isBuddySurfaceEnvironment(yield* HostProcess.Environment)) { + const buddyFolder = yield* sharedBuddyFolder; + if (buddyFolder !== undefined) return yield* resolveSharedBuddyThread(buddyFolder); return yield* new BuddyThreadUnavailable({ reason: "not-buddy", detail: "This T3 Code is not Buddy's.", }); + } const orchestrator = yield* OrchestratorV2; const project = yield* buddyProject(); const existing = yield* orchestrator diff --git a/apps/server/src/lazurio/buddySurfaceThreadRoute.ts b/apps/server/src/lazurio/buddySurfaceThreadRoute.ts index def40e9201ec..adc74a7815d5 100644 --- a/apps/server/src/lazurio/buddySurfaceThreadRoute.ts +++ b/apps/server/src/lazurio/buddySurfaceThreadRoute.ts @@ -6,12 +6,14 @@ */ import { AuthOrchestrationOperateScope, AuthOrchestrationReadScope } from "@t3tools/contracts"; import * as Effect from "effect/Effect"; +import * as Option from "effect/Option"; import * as Path from "effect/Path"; import { HttpRouter, HttpServerResponse } from "effect/http"; import * as ServerConfig from "../config.ts"; import { OrchestratorV2 } from "../orchestration-v2/Orchestrator.ts"; import { ProjectStoreV2 } from "../orchestration-v2/ProjectStore.ts"; +import { ServerSettingsService } from "../serverSettings.ts"; import { BUDDY_THREAD_ROUTE, resolveBuddyThread } from "./buddySurfaceThread.ts"; import { authenticateOverlayRoute } from "./routeAuth.ts"; @@ -29,6 +31,8 @@ export const layer = HttpRouter.use((router) => const projects = yield* ProjectStoreV2; const path = yield* Path.Path; const config = yield* ServerConfig.ServerConfig; + // Only the shared server's first Buddy thread reads it; tests build this layer without one. + const settings = yield* Effect.serviceOption(ServerSettingsService); yield* router.add( "POST", BUDDY_THREAD_ROUTE, @@ -39,6 +43,9 @@ export const layer = HttpRouter.use((router) => Effect.provideService(ProjectStoreV2, projects), Effect.provideService(Path.Path, path), Effect.provideService(ServerConfig.ServerConfig, config), + Option.isSome(settings) + ? Effect.provideService(ServerSettingsService, settings.value) + : (effect) => effect, Effect.map((thread) => HttpServerResponse.jsonUnsafe(thread)), Effect.catchTags({ BuddyThreadUnavailable: (error) => diff --git a/apps/server/src/lazurio/managedFolder.ts b/apps/server/src/lazurio/managedFolder.ts index 72e59b0db0fa..16c78d602b78 100644 --- a/apps/server/src/lazurio/managedFolder.ts +++ b/apps/server/src/lazurio/managedFolder.ts @@ -68,11 +68,17 @@ export const makeFolderGuard = Effect.gen(function* () { export const managedFolderClientConfig = (config: { readonly lazurioFolder?: string; readonly lazurioBuddyFolder?: string; + readonly lazurioBuddyOrigin?: string; readonly lazurioToolsUrl?: string; }) => ({ ...(config.lazurioFolder === undefined ? {} : { lazurioFolder: config.lazurioFolder }), ...(config.lazurioFolder === undefined || config.lazurioBuddyFolder === undefined ? {} : { lazurioBuddyFolder: config.lazurioBuddyFolder }), + ...(config.lazurioFolder === undefined || + config.lazurioBuddyFolder === undefined || + config.lazurioBuddyOrigin === undefined + ? {} + : { lazurioBuddyOrigin: config.lazurioBuddyOrigin }), ...(config.lazurioToolsUrl === undefined ? {} : { lazurioToolsUrl: config.lazurioToolsUrl }), }); diff --git a/apps/server/src/lazurio/managedFolderConfig.test.ts b/apps/server/src/lazurio/managedFolderConfig.test.ts index 0551b3c25f7d..5343b931bb1a 100644 --- a/apps/server/src/lazurio/managedFolderConfig.test.ts +++ b/apps/server/src/lazurio/managedFolderConfig.test.ts @@ -110,6 +110,48 @@ it.effect("declares the Buddy folder beside the Folder by its canonical path", ( }), ); +it.effect("declares Buddy's window origin only beside a Buddy folder, as a bare HTTPS origin", () => + Effect.gen(function* () { + const { folder, buddy } = makeFolder(); + const config = yield* resolveManagedFolderConfig.pipe( + withEnv({ + T3CODE_LAZURIO_FOLDER: folder, + T3CODE_LAZURIO_BUDDY_FOLDER: buddy, + T3CODE_LAZURIO_BUDDY_ORIGIN: "https://buddy.example.test", + }), + ); + assert.strictEqual(config.lazurioBuddyOrigin, "https://buddy.example.test"); + for (const [env, expected] of [ + [ + { + T3CODE_LAZURIO_FOLDER: folder, + T3CODE_LAZURIO_BUDDY_ORIGIN: "https://buddy.example.test", + }, + "T3CODE_LAZURIO_BUDDY_ORIGIN needs T3CODE_LAZURIO_BUDDY_FOLDER", + ], + [ + { + T3CODE_LAZURIO_FOLDER: folder, + T3CODE_LAZURIO_BUDDY_FOLDER: buddy, + T3CODE_LAZURIO_BUDDY_ORIGIN: "http://buddy.example.test", + }, + "must be a bare HTTPS origin", + ], + [ + { + T3CODE_LAZURIO_FOLDER: folder, + T3CODE_LAZURIO_BUDDY_FOLDER: buddy, + T3CODE_LAZURIO_BUDDY_ORIGIN: "https://buddy.example.test/chat", + }, + "must be a bare HTTPS origin", + ], + ] as const) { + const error = yield* resolveManagedFolderConfig.pipe(withEnv(env), Effect.flip); + assert.include(String(error), expected); + } + }), +); + it.effect("refuses a relative path, a file, an insecure or credentialed tools URL", () => Effect.gen(function* () { const { parent, folder, buddy } = makeFolder(); diff --git a/apps/server/src/lazurio/managedFolderConfig.ts b/apps/server/src/lazurio/managedFolderConfig.ts index 186a40892fef..2913adcfe0cb 100644 --- a/apps/server/src/lazurio/managedFolderConfig.ts +++ b/apps/server/src/lazurio/managedFolderConfig.ts @@ -25,6 +25,10 @@ const ManagedFolderEnv = Config.all({ Config.option, Config.map(Option.getOrUndefined), ), + buddyOrigin: Config.URL("T3CODE_LAZURIO_BUDDY_ORIGIN").pipe( + Config.option, + Config.map(Option.getOrUndefined), + ), toolsUrl: Config.URL("T3CODE_LAZURIO_TOOLS_URL").pipe( Config.option, Config.map(Option.getOrUndefined), @@ -117,6 +121,21 @@ export const resolveManagedFolderConfig = Effect.gen(function* () { env.buddyFolder === undefined ? undefined : yield* canonicalBuddyFolder(folder, env.buddyFolder); + // Buddy's window (LZD-0033 R3): its own HTTPS origin, which the gateway routes to this server. + if (env.buddyOrigin !== undefined) { + if (env.buddyFolder === undefined) + return yield* invalid("T3CODE_LAZURIO_BUDDY_ORIGIN needs T3CODE_LAZURIO_BUDDY_FOLDER."); + const url = env.buddyOrigin; + if ( + url.protocol !== "https:" || + url.username || + url.password || + url.origin !== url.href.replace(/\/$/, "") + ) + return yield* invalid( + "T3CODE_LAZURIO_BUDDY_ORIGIN must be a bare HTTPS origin without credentials.", + ); + } if ( env.toolsUrl !== undefined && (env.toolsUrl.protocol !== "https:" || env.toolsUrl.username || env.toolsUrl.password) @@ -127,6 +146,7 @@ export const resolveManagedFolderConfig = Effect.gen(function* () { ? {} : { cwd: folder, lazurioFolder: folder, autoBootstrapProjectFromCwd: false }), ...(buddyFolder === undefined ? {} : { lazurioBuddyFolder: buddyFolder }), + ...(env.buddyOrigin === undefined ? {} : { lazurioBuddyOrigin: env.buddyOrigin.origin }), ...(env.toolsUrl === undefined ? {} : { lazurioToolsUrl: env.toolsUrl.toString() }), }; }); diff --git a/packages/contracts/src/server.ts b/packages/contracts/src/server.ts index 1baa76049f2e..5bf95e1c8346 100644 --- a/packages/contracts/src/server.ts +++ b/packages/contracts/src/server.ts @@ -693,6 +693,8 @@ export const ServerConfig = Schema.Struct({ lazurioFolder: Schema.optionalKey(TrimmedNonEmptyString), /** The Buddy folder beside it, the managed Environment's one other project. */ lazurioBuddyFolder: Schema.optionalKey(TrimmedNonEmptyString), + /** The origin of Buddy's window on this server; a client there shows Buddy's thread. */ + lazurioBuddyOrigin: Schema.optionalKey(TrimmedNonEmptyString), lazurioToolsUrl: Schema.optionalKey(TrimmedNonEmptyString), /** Buddy's own T3 Code (T3CODE_LAZURIO_BUDDY=1): the web shows Buddy's one conversation. */ lazurioBuddy: Schema.optionalKey(Schema.Literal(true)), From e549777ceb8fbc3a8a98f9b042c5eadd11fa096a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mat=C4=9Bj=20Such=C3=A1nek?= <16311043+immakermatty@users.noreply.github.com> Date: Wed, 18 Nov 2026 19:30:27 +0000 Subject: [PATCH 03/12] feat(lazurio): Buddy's window keeps T3's model picker on the shared server (R3, web) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The web is in Buddy's surface on Buddy's own origin (lazurioBuddyOrigin) as well as on Buddy's own server; only Hermes's chat (GEN3) swaps the composer for Normal / Fast. A loopback http origin is accepted for development. Agent: environment a480495c-25e0-4e51-828b-1dbf1b77d62f · T3 thread 72068f77-568a-48aa-aa8a-108c03b29972 Co-Authored-By: Claude Opus 5.5 --- .../server/src/lazurio/managedFolderConfig.ts | 4 +++- .../components/chat/ComposerControlsBar.tsx | 10 ++++---- apps/web/src/lazurio/BuddySurface.tsx | 24 +++++++++++++++---- .../src/lazurio/buddySurfaceControls.test.ts | 11 +++++++++ apps/web/src/lazurio/buddySurfaceControls.ts | 11 +++++++++ scripts/lazurio-release-contract.test.mjs | 4 +++- 6 files changed, 53 insertions(+), 11 deletions(-) diff --git a/apps/server/src/lazurio/managedFolderConfig.ts b/apps/server/src/lazurio/managedFolderConfig.ts index 2913adcfe0cb..cf2321a44156 100644 --- a/apps/server/src/lazurio/managedFolderConfig.ts +++ b/apps/server/src/lazurio/managedFolderConfig.ts @@ -126,8 +126,10 @@ export const resolveManagedFolderConfig = Effect.gen(function* () { if (env.buddyFolder === undefined) return yield* invalid("T3CODE_LAZURIO_BUDDY_ORIGIN needs T3CODE_LAZURIO_BUDDY_FOLDER."); const url = env.buddyOrigin; + // HTTPS, or plain HTTP on a loopback host, where a developer runs both origins. + const loopback = ["localhost", "127.0.0.1", "[::1]"].includes(url.hostname); if ( - url.protocol !== "https:" || + (url.protocol !== "https:" && !(url.protocol === "http:" && loopback)) || url.username || url.password || url.origin !== url.href.replace(/\/$/, "") diff --git a/apps/web/src/components/chat/ComposerControlsBar.tsx b/apps/web/src/components/chat/ComposerControlsBar.tsx index f133fbf8b623..4d375247b93d 100644 --- a/apps/web/src/components/chat/ComposerControlsBar.tsx +++ b/apps/web/src/components/chat/ComposerControlsBar.tsx @@ -30,7 +30,7 @@ import { } from "./ComposerModelEffort"; import type { useComposerProviderModel } from "./useComposerProviderModel"; import { resolveComposerControlsOwnership } from "./composerControlsOwnership"; -import { BuddyComposerControls, useBuddySurfaceMode } from "../../lazurio/BuddySurface"; +import { BuddyComposerControls, useBuddyHermesControls } from "../../lazurio/BuddySurface"; /** * The composer footer controls: the model picker (which also holds effort, speed and @@ -148,10 +148,10 @@ export function ComposerControlsBar(props: { const controlSize = composerControlsCollapsed ? "xs" : "sm"; const applyThreadModelPick = useApplyThreadModelPick(); const applyRouteThreadModelPick = useStableCallback(() => applyThreadModelPick(routeThreadRef)); - // Lazurio overlay (plan DEV-6676): Buddy's chat offers no model, effort, access or mode, only - // Hermes's Normal / Fast switch (BuddySurface.tsx). It returns after the last hook. - const buddySurface = useBuddySurfaceMode(environmentId) === true; - if (buddySurface) return ; + // Lazurio overlay (plan DEV-6676): Hermes's chat (GEN3) offers no model, effort, access or mode, + // only Normal / Fast (BuddySurface.tsx); Buddy's window on the shared server keeps T3's picker. + const buddyHermes = useBuddyHermesControls(environmentId); + if (buddyHermes) return ; const traitsInput = resolveComposerTraitsInput({ provider: selectedProvider, instanceId: selectedInstanceId, diff --git a/apps/web/src/lazurio/BuddySurface.tsx b/apps/web/src/lazurio/BuddySurface.tsx index 7934e0e6e4b5..c647aa288074 100644 --- a/apps/web/src/lazurio/BuddySurface.tsx +++ b/apps/web/src/lazurio/BuddySurface.tsx @@ -42,6 +42,7 @@ import { buddySpeedSelection, type ChatShortcutsInput, isBuddySpeed, + isBuddyWindowOrigin, personsQueuedRuns, type QueueMessage, withoutUnusedShortcuts, @@ -52,8 +53,14 @@ import { BUDDY_WORKING_ROW, buddyConversationRows, buddyFailureOf } from "./budd import { prefersCzech } from "./threadTabs"; import { useBuddyFrame } from "./useBuddyFrame"; +type BuddyConfig = { readonly lazurioBuddy?: true; readonly lazurioBuddyOrigin?: string } | null; + +/** Buddy's surface: Buddy's own T3 Code (GEN3), or Buddy's window on the shared server (GEN4). */ +const isBuddySurfaceConfig = (config: BuddyConfig) => + config?.lazurioBuddy === true || isBuddyWindowOrigin(config); + /** - * Buddy's T3 Code; null until the primary server's config is known, false without one. With + * Buddy's surface; null until the primary server's config is known, false without one. With * `environmentId`, only for that Environment: another Environment's thread is never Buddy's. */ export function useBuddySurfaceMode(environmentId?: string): boolean | null { @@ -61,12 +68,21 @@ export function useBuddySurfaceMode(environmentId?: string): boolean | null { const config = useAtomValue(primaryServerConfigAtom); if (primaryEnvironmentId === null) return false; if (environmentId !== undefined && environmentId !== primaryEnvironmentId) return false; - return config === null ? null : config.lazurioBuddy === true; + return config === null ? null : isBuddySurfaceConfig(config); +} + +/** + * Hermes's chat (GEN3 only): Normal / Fast instead of T3's model, effort and mode. Buddy's window on + * the shared server keeps T3's whole picker, as a Chat thread has it (GEN4). + */ +export function useBuddyHermesControls(environmentId?: string): boolean { + const config = useAtomValue(primaryServerConfigAtom); + return useBuddySurfaceMode(environmentId) === true && config?.lazurioBuddy === true; } -/** Buddy's T3 Code, read outside React when a command runs: false until the config is known. */ +/** Buddy's surface, read outside React when a command runs: false until the config is known. */ export const isBuddySurfaceNow = (): boolean => - appAtomRegistry.get(primaryServerConfigAtom)?.lazurioBuddy === true; + isBuddySurfaceConfig(appAtomRegistry.get(primaryServerConfigAtom)); const BUDDY_THREAD_ROUTE = "/api/lazurio/buddy/thread"; const BUDDY_DAYS_ROUTE = "/api/lazurio/buddy/days"; diff --git a/apps/web/src/lazurio/buddySurfaceControls.test.ts b/apps/web/src/lazurio/buddySurfaceControls.test.ts index 6c6e82e1d9f3..4f65ac3d523d 100644 --- a/apps/web/src/lazurio/buddySurfaceControls.test.ts +++ b/apps/web/src/lazurio/buddySurfaceControls.test.ts @@ -10,6 +10,7 @@ import { buddySpeedOf, buddySpeedOption, buddySpeedSelection, + isBuddyWindowOrigin, personsQueuedRuns, } from "./buddySurfaceControls"; @@ -98,3 +99,13 @@ describe("Buddy's queue", () => { expect(personsQueuedRuns(queued, [{ id: "person", createdBy: "user" }])).toBe(queued); }); }); + +describe("Buddy's window on the shared server", () => { + it("is the page whose origin the server names for it, and nothing else", () => { + const config = { lazurioBuddyOrigin: "https://buddy.example.test" }; + expect(isBuddyWindowOrigin(config, "https://buddy.example.test")).toBe(true); + expect(isBuddyWindowOrigin(config, "https://t3code.example.test")).toBe(false); + expect(isBuddyWindowOrigin({}, "https://buddy.example.test")).toBe(false); + expect(isBuddyWindowOrigin(null, "https://buddy.example.test")).toBe(false); + }); +}); diff --git a/apps/web/src/lazurio/buddySurfaceControls.ts b/apps/web/src/lazurio/buddySurfaceControls.ts index 33416aa909f8..edd26efca417 100644 --- a/apps/web/src/lazurio/buddySurfaceControls.ts +++ b/apps/web/src/lazurio/buddySurfaceControls.ts @@ -139,3 +139,14 @@ export function personsQueuedRuns if (!queued.some((run) => notThePersons.has(run.messageId))) return queued; return queued.filter((run) => !notThePersons.has(run.messageId)); } + +/** + * Whether this page is Buddy's window on the shared server (GEN4, plan LZD-0033 R3): the page's + * origin is the one the server names for Buddy's window. On Chat's origin it is Chat. + */ +export function isBuddyWindowOrigin( + config: { readonly lazurioBuddyOrigin?: string } | null | undefined, + origin: string = globalThis.location?.origin ?? "", +): boolean { + return config?.lazurioBuddyOrigin !== undefined && config.lazurioBuddyOrigin === origin; +} diff --git a/scripts/lazurio-release-contract.test.mjs b/scripts/lazurio-release-contract.test.mjs index bee5645d8245..1b4071ff9e82 100644 --- a/scripts/lazurio-release-contract.test.mjs +++ b/scripts/lazurio-release-contract.test.mjs @@ -3380,9 +3380,11 @@ NodeTest.test("Buddy's chat reads like a chat with a friend through its seams", // picker, options chip, access and mode, the overflow menu) before the bar builds any of them. // Since v0.1.4 the resting composer has no strip of its own to hide. Since v0.1.8 the bar's // hooks end with the model pick (pingdotgg/t3code#31739), and Buddy's return comes after them. + // Only Hermes's chat (GEN3) swaps the bar; Buddy's window on the shared server keeps T3's + // picker (LZD-0033 R3). NodeAssert.match( controlsBar, - /\n\s+const applyRouteThreadModelPick = useStableCallback\(\(\) => applyThreadModelPick\(routeThreadRef\)\);\n(?:\s+\/\/[^\n]*\n)*\s+const buddySurface = useBuddySurfaceMode\(environmentId\) === true;\n\s+if \(buddySurface\) return ;\n\s+const traitsInput = resolveComposerTraitsInput\(/, + /\n\s+const applyRouteThreadModelPick = useStableCallback\(\(\) => applyThreadModelPick\(routeThreadRef\)\);\n(?:\s+\/\/[^\n]*\n)*\s+const buddyHermes = useBuddyHermesControls\(environmentId\);\n\s+if \(buddyHermes\) return ;\n\s+const traitsInput = resolveComposerTraitsInput\(/, ); NodeAssert.doesNotMatch(composer, /buddyComposer\.hasControls/); // Buddy always works with full access: the web never asks Buddy's thread for another mode. From 3a109a09abe76d2935040547883bd4c4c352885d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mat=C4=9Bj=20Such=C3=A1nek?= <16311043+immakermatty@users.noreply.github.com> Date: Wed, 18 Nov 2026 19:38:08 +0000 Subject: [PATCH 04/12] chore(lazurio): comments without PR numbers; contract note within four lines MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Agent: environment a480495c-25e0-4e51-828b-1dbf1b77d62f · T3 thread 72068f77-568a-48aa-aa8a-108c03b29972 Co-Authored-By: Claude Opus 5.5 --- apps/server/src/lazurio/buddySurfaceThread.test.ts | 2 +- apps/server/src/lazurio/buddySurfaceThread.ts | 2 +- scripts/lazurio-release-contract.test.mjs | 7 ++----- 3 files changed, 4 insertions(+), 7 deletions(-) diff --git a/apps/server/src/lazurio/buddySurfaceThread.test.ts b/apps/server/src/lazurio/buddySurfaceThread.test.ts index 54c7ca98601b..01b5ad22e721 100644 --- a/apps/server/src/lazurio/buddySurfaceThread.test.ts +++ b/apps/server/src/lazurio/buddySurfaceThread.test.ts @@ -209,7 +209,7 @@ describe("Buddy's thread", () => { ); describe("on the shared Chat server (GEN4, LZD-0033 R3)", () => { - /** A managed Folder and a Buddy folder beside it, as #214 declares them. */ + /** A managed Folder and a Buddy folder beside it, as the Environment declares them. */ const makeShared = () => { const home = NodeFS.mkdtempSync(NodePath.join(NodeOS.tmpdir(), "buddy-shared-home-")); const folder = NodePath.join(home, "Lazurio"); diff --git a/apps/server/src/lazurio/buddySurfaceThread.ts b/apps/server/src/lazurio/buddySurfaceThread.ts index af7464a6c4ff..0c267fcfd48d 100644 --- a/apps/server/src/lazurio/buddySurfaceThread.ts +++ b/apps/server/src/lazurio/buddySurfaceThread.ts @@ -103,7 +103,7 @@ const conflict = () => /** * Buddy GEN4 (plan LZD-0033, R3): on the shared Chat server Buddy's project is the one over the - * declared Buddy folder (#214), and Buddy's thread is its oldest root thread. Archiving one is + * declared Buddy folder, and Buddy's thread is its oldest root thread. Archiving one is * refused and the startup brings archived ones back, so this is the conversation the person had. */ const sharedBuddyProject = Effect.fn("LazurioBuddySurface.sharedBuddyProject")(function* ( diff --git a/scripts/lazurio-release-contract.test.mjs b/scripts/lazurio-release-contract.test.mjs index 1b4071ff9e82..fc88e60e0738 100644 --- a/scripts/lazurio-release-contract.test.mjs +++ b/scripts/lazurio-release-contract.test.mjs @@ -3376,11 +3376,8 @@ NodeTest.test("Buddy's chat reads like a chat with a friend through its seams", ); NodeAssert.equal(timeline.match(/ Date: Wed, 18 Nov 2026 19:38:46 +0000 Subject: [PATCH 05/12] docs(lazurio): Buddy's window on the shared server in the runbook MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Agent: environment a480495c-25e0-4e51-828b-1dbf1b77d62f · T3 thread 72068f77-568a-48aa-aa8a-108c03b29972 Co-Authored-By: Claude Opus 5.5 --- docs/operations/lazurio-fork-release.md | 30 +++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/docs/operations/lazurio-fork-release.md b/docs/operations/lazurio-fork-release.md index be51ed0420e0..b3e952d76422 100644 --- a/docs/operations/lazurio-fork-release.md +++ b/docs/operations/lazurio-fork-release.md @@ -1254,6 +1254,36 @@ povrchu i s odkazy, `buddySurfaceTerminal.browser.test.tsx` skutečné kreslení rozhovorem, jen s náhradou za jeho emulátor, a `buddySurfaceRightPanel.browser.test.tsx` skutečný pravý panel T3. +### Okno Buddyho na společném serveru (Buddy GEN4) + +**Plán LZD-0033, řez R3.** Pro převedeného člověka otevírá okno Buddyho jedno +vlákno projektu Buddy ve společném serveru Chatu (viz Projekt Buddyho výše), +ne druhý server. Okno má dál vlastní origin `buddy.`, který brána +Prostředí u převedeného člověka vede na `t3code.service`. Server ho zná +z `T3CODE_LAZURIO_BUDDY_ORIGIN`: holý HTTPS origin, při vývoji i loopback přes +`http`, jen spolu s `T3CODE_LAZURIO_BUDDY_FOLDER`. Klientům ho posílá jako +`lazurioBuddyOrigin`. Web je v okně Buddyho právě tehdy, když se origin +stránky rovná `lazurioBuddyOrigin`; na originu Chatu je to Chat. Cookie +relace `__Host-` patří jednomu hostu a kontrola originu porovnává host, +takže okno má vlastní relaci a autentizace se nemění. + +- **Vlákno** je nejstarší kořenové vlákno projektu Buddy, které není + smazané (archivovat ho nejde). Když žádné není, trasa + `/api/lazurio/buddy/thread` ho založí na modelu projektu Buddy, jinak na + výchozím modelu Prostředí, jinak na modelu projektu Lazurio (doporučení + Platformy). Id i příkaz jsou odvozené z projektu, takže dvě první návštěvy + založí jedno vlákno. Dny čte trasa `/api/lazurio/buddy/days` z téhož vlákna. +- **Model:** skladatel má plný výběr poskytovatele, modelu a úsilí jako + vlákno Chatu a volba drží ve vlákně. Normální / Rychlý zůstává jen Hermesovi + (GEN3, `useBuddyHermesControls`). +- **Kontext stránky:** zpráva se záznamem stránky dostane český blok + stránky u kteréhokoli poskytovatele (`projectComposerContextForProvider`). + Záznam přidává jen okno Buddyho. +- **Beze změny pro GEN3:** server s `T3CODE_LAZURIO_BUDDY=1` má dál svoje + vlákno `buddy` na instanci `buddy`, stráže a výchozí nastavení. Žádný + z jeho obalů celého serveru (výchozí nastavení, propojení, checkpointy) + na společném serveru neběží. + ### Kdo jednal: Buddy a Delegace **Rozhodnutí 0210, večerní dodatek, bod 5 (řádek 27, plán DEV-6676).** Co Buddy napíše nebo From 07bab4b104aba56f9dea87127cb17c6015d0bf16 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mat=C4=9Bj=20Such=C3=A1nek?= <16311043+immakermatty@users.noreply.github.com> Date: Wed, 18 Nov 2026 19:42:23 +0000 Subject: [PATCH 06/12] feat(lazurio): Buddy's window on the shared server keeps the model and effort shortcuts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Agent: environment a480495c-25e0-4e51-828b-1dbf1b77d62f · T3 thread 72068f77-568a-48aa-aa8a-108c03b29972 Co-Authored-By: Claude Opus 5.5 --- apps/web/src/lazurio/BuddySurface.tsx | 5 ++++- .../src/lazurio/buddySurfaceControls.test.ts | 18 ++++++++++++++++++ apps/web/src/lazurio/buddySurfaceControls.ts | 10 ++++++++-- 3 files changed, 30 insertions(+), 3 deletions(-) diff --git a/apps/web/src/lazurio/BuddySurface.tsx b/apps/web/src/lazurio/BuddySurface.tsx index c647aa288074..da7245bea60d 100644 --- a/apps/web/src/lazurio/BuddySurface.tsx +++ b/apps/web/src/lazurio/BuddySurface.tsx @@ -449,7 +449,10 @@ export const buddyRightPanelState = (buddy: boolean, state: RightPanelState): Ri /** The chat's shortcuts, without those Buddy's surface has no use for there. */ export function useBuddyChatShortcuts(buddy: boolean, input: ChatShortcutsInput) { - useChatShortcuts(buddy ? withoutUnusedShortcuts(input) : input); + // Only Buddy's window on the shared server (GEN4) has a model and effort choice. + const surface = useBuddySurfaceMode() === true; + const hermes = useBuddyHermesControls(); + useChatShortcuts(buddy ? withoutUnusedShortcuts(input, surface && !hermes) : input); } /** diff --git a/apps/web/src/lazurio/buddySurfaceControls.test.ts b/apps/web/src/lazurio/buddySurfaceControls.test.ts index 4f65ac3d523d..e131630276ee 100644 --- a/apps/web/src/lazurio/buddySurfaceControls.test.ts +++ b/apps/web/src/lazurio/buddySurfaceControls.test.ts @@ -12,6 +12,7 @@ import { buddySpeedSelection, isBuddyWindowOrigin, personsQueuedRuns, + withoutUnusedShortcuts, } from "./buddySurfaceControls"; const BUDDY = ProviderInstanceId.make("buddy"); @@ -109,3 +110,20 @@ describe("Buddy's window on the shared server", () => { expect(isBuddyWindowOrigin(null, "https://buddy.example.test")).toBe(false); }); }); + +describe("the chat's shortcuts in Buddy's surface", () => { + const binding = (command: string) => ({ command, shortcut: { key: "k" } }) as never; + const input = { + keybindings: [binding("modelPicker.toggle"), binding("terminal.toggle"), binding("chat.new")], + } as unknown as Parameters[0]; + const commands = (result: ReturnType) => + result.keybindings.map((entry) => entry.command); + + it("drop the model choice only in Hermes's chat, the panels in both", () => { + expect(commands(withoutUnusedShortcuts(input))).toEqual(["chat.new"]); + expect(commands(withoutUnusedShortcuts(input, true))).toEqual([ + "modelPicker.toggle", + "chat.new", + ]); + }); +}); diff --git a/apps/web/src/lazurio/buddySurfaceControls.ts b/apps/web/src/lazurio/buddySurfaceControls.ts index edd26efca417..d0a0ca6bb926 100644 --- a/apps/web/src/lazurio/buddySurfaceControls.ts +++ b/apps/web/src/lazurio/buddySurfaceControls.ts @@ -100,6 +100,8 @@ const UNUSED_SHORTCUTS: ReadonlySet = new Set([ ...PANEL_SHORTCUTS, ...CHOICE_SHORTCUTS, ]); +/** Buddy's window on the shared server keeps T3's picker, so only the panels go (GEN4). */ +const UNUSED_PANEL_SHORTCUTS: ReadonlySet = new Set(PANEL_SHORTCUTS); const NO_KEYBINDINGS: ResolvedKeybindingsConfig = []; @@ -111,10 +113,14 @@ export type ChatShortcutsInput = Parameters[0]; * them, not even the chat's guards that hold Mod+W for a closing terminal before any command runs, * so their keys reach the browser, as on any page that has no use for them. */ -export function withoutUnusedShortcuts(input: ChatShortcutsInput): ChatShortcutsInput { +export function withoutUnusedShortcuts( + input: ChatShortcutsInput, + keepsChoices = false, +): ChatShortcutsInput { + const unused = keepsChoices ? UNUSED_PANEL_SHORTCUTS : UNUSED_SHORTCUTS; return { ...input, - keybindings: input.keybindings.filter((binding) => !UNUSED_SHORTCUTS.has(binding.command)), + keybindings: input.keybindings.filter((binding) => !unused.has(binding.command)), scriptKeybindings: NO_KEYBINDINGS, }; } From 8bb14a650a4196e06381402ec81179b25b8ce61b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mat=C4=9Bj=20Such=C3=A1nek?= <16311043+immakermatty@users.noreply.github.com> Date: Wed, 18 Nov 2026 19:51:21 +0000 Subject: [PATCH 07/12] feat(lazurio): Buddy's window on the shared server is a whole T3 thread in Buddy's frame MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The coordinator decided (option B): in Buddy's window on the shared server the thread behaves as in Chat, with the right panel, the work of tools, rollback, /clear, side chats and the thread's details; Buddy keeps its frame, the days and the page chip, and the threads of Buddy's project (subagents, forks) open in the window. Hermes's quiet conversation and its limits stay GEN3's. Agent: environment a480495c-25e0-4e51-828b-1dbf1b77d62f · T3 thread 72068f77-568a-48aa-aa8a-108c03b29972 Co-Authored-By: Claude Opus 5.5 --- apps/web/src/components/ChatView.tsx | 9 +++-- .../src/components/chat/MessagesTimeline.tsx | 9 +++-- apps/web/src/lazurio/BuddySurface.tsx | 40 ++++++++++++++----- .../buddySurfaceTimeline.browser.test.tsx | 1 + scripts/lazurio-release-contract.test.mjs | 9 +++-- 5 files changed, 46 insertions(+), 22 deletions(-) diff --git a/apps/web/src/components/ChatView.tsx b/apps/web/src/components/ChatView.tsx index e5885cba3ff9..bcad4c43cee1 100644 --- a/apps/web/src/components/ChatView.tsx +++ b/apps/web/src/components/ChatView.tsx @@ -191,7 +191,7 @@ import { useBuddyChatShortcuts, useBuddyPage, useBuddyQueuedRunCount, - useBuddySurfaceMode, + useBuddyHermesControls, } from "../lazurio/BuddySurface"; import { BuddyPageChip } from "../lazurio/BuddySurfacePageChip"; import { @@ -599,9 +599,10 @@ export default function ChatView(props: ChatViewProps) { } return ids; })(); - // Lazurio overlay (plan DEV-6676): in Buddy's one conversation a follow-up steers by default, - // and queueing is the explicit alternative. - const buddySurface = useBuddySurfaceMode(environmentId) === true; + // Lazurio overlay (plan DEV-6676): in Hermes's one conversation (GEN3) a follow-up steers by + // default and the chat is only the conversation; Buddy's window on the shared server is a whole + // T3 thread (GEN4). + const buddySurface = useBuddyHermesControls(environmentId); // The page Buddy is asked from travels with the person's next message (buddySurfacePage.ts). const buddyPage = useBuddyPage(environmentId); const environmentSettings = useEnvironmentSettings(environmentId); diff --git a/apps/web/src/components/chat/MessagesTimeline.tsx b/apps/web/src/components/chat/MessagesTimeline.tsx index 693d668b7dd5..74e8a13c05ad 100644 --- a/apps/web/src/components/chat/MessagesTimeline.tsx +++ b/apps/web/src/components/chat/MessagesTimeline.tsx @@ -26,6 +26,7 @@ import { buddySurfaceRows, useBuddyDayJump, useBuddyDayLines, + useBuddyHermesControls, useBuddySurfaceMode, } from "../../lazurio/BuddySurface"; import { buddyAnnouncementLevel } from "../../lazurio/buddySurfaceTimeline"; @@ -645,7 +646,9 @@ const ConversationTimeline = memo(function ConversationTimeline({ } } - const buddySurface = useBuddySurfaceMode(activeThreadEnvironmentId) === true; + // Hermes's quiet conversation (GEN3); Buddy's days and their jump in either Buddy surface. + const buddySurface = useBuddyHermesControls(activeThreadEnvironmentId); + const buddyDays = useBuddySurfaceMode(activeThreadEnvironmentId) === true; // Lazurio overlay (plan DEV-6676): Buddy's conversation filters its own rows // (buddySurfaceTimeline.ts), so "zen" would hide Buddy's messages between turns there. const preferredToolCallVisibility = useClientSettings((settings) => @@ -785,7 +788,7 @@ const ConversationTimeline = memo(function ConversationTimeline({ buddySurface, (isWorking || buddyBackgroundWork) && !awaitingUser, ); - const buddyDayLines = useBuddyDayLines(rows, buddySurface); + const buddyDayLines = useBuddyDayLines(rows, buddyDays); const matchedApprovalRequestIds = new Set(); for (const row of pendingApprovalRequestIds.size > 0 ? rows : []) { const entries = @@ -825,7 +828,7 @@ const ConversationTimeline = memo(function ConversationTimeline({ const viewportRef = useRef(null); const navigateTimeline = () => viewportRef.current?.navigate({ releasesFollow: true }); useBuddyDayJump({ - buddy: buddySurface, + buddy: buddyDays, rows, listRef, onManualNavigation: navigateTimeline, diff --git a/apps/web/src/lazurio/BuddySurface.tsx b/apps/web/src/lazurio/BuddySurface.tsx index da7245bea60d..738ac4a2e461 100644 --- a/apps/web/src/lazurio/BuddySurface.tsx +++ b/apps/web/src/lazurio/BuddySurface.tsx @@ -19,7 +19,10 @@ import { useSyncExternalStore, } from "react"; +import { scopeThreadRef } from "@t3tools/client-runtime/environment"; +import type { EnvironmentId, ThreadId } from "@t3tools/contracts"; import { useComposerDraftStore } from "~/composerDraftStore"; +import { useThreadShell } from "~/state/entities"; import type { ComposerControlsBar } from "~/components/chat/ComposerControlsBar"; import type { MessagesTimelineRow } from "~/components/chat/MessagesTimeline.logic"; import { ThreadDetailsPanel } from "~/components/chat/ThreadDetailsPanel"; @@ -100,9 +103,7 @@ interface BuddyDay { * surface has none, since Buddy's thread is a conversation, not work in a checkout. */ export function BuddyThreadDetailsPanel(props: ComponentProps) { - return useBuddySurfaceMode(props.environmentId) === true ? null : ( - - ); + return useBuddyHermesControls(props.environmentId) ? null : ; } /** The surface's language: the host page's when framed, else the browser's. */ @@ -337,7 +338,7 @@ export function BuddyThreadErrorBanner({ environmentId, ...props }: ComponentProps & { readonly environmentId: string }) { - const buddy = useBuddySurfaceMode(environmentId) === true; + const buddy = useBuddyHermesControls(environmentId); const text = useCzech(buddy) ? TEXT.cs : TEXT.en; return buddy && props.error !== null ? ( @@ -465,7 +466,7 @@ export function useBuddyQueuedRuns, messages: ReadonlyArray | undefined, ): ReadonlyArray { - return useBuddySurfaceMode(environmentId) === true ? personsQueuedRuns(queued, messages) : queued; + return useBuddyHermesControls(environmentId) ? personsQueuedRuns(queued, messages) : queued; } /** @@ -477,7 +478,7 @@ export function useBuddyQueuedRunCount( runs: ReadonlyArray<{ readonly userMessageId: string }> | null, messages: ReadonlyArray | undefined, ): number { - const buddy = useBuddySurfaceMode(environmentId) === true; + const buddy = useBuddyHermesControls(environmentId); if (runs === null) return 0; if (!buddy) return runs.length; return personsQueuedRuns( @@ -676,6 +677,7 @@ export function BuddySurfaceLayout({ children }: { readonly children: ReactNode type Opening = { readonly attempt: number; readonly outcome: "not-ready" | "failed" }; let buddyThreadId: string | null = null; +let buddyProjectId: string | null = null; const buddyThreadListeners = new Set<() => void>(); const subscribeBuddyThread = (listener: () => void) => { buddyThreadListeners.add(listener); @@ -691,12 +693,25 @@ export function useLeadsToBuddysThread( threadRef: { readonly environmentId: string; readonly threadId: string } | null, ): boolean { const buddy = useBuddySurfaceMode(threadRef?.environmentId) === true; + const hermes = useBuddyHermesControls(threadRef?.environmentId); const known = useSyncExternalStore(subscribeBuddyThread, () => buddyThreadId, noTarget); - return threadRef !== null && buddy && threadRef.threadId !== known; + const shell = useThreadShell( + threadRef === null + ? null + : scopeThreadRef(threadRef.environmentId as EnvironmentId, threadRef.threadId as ThreadId), + ); + if (threadRef === null || !buddy || threadRef.threadId === known) return false; + // Buddy's window on the shared server opens the threads of Buddy's project, its subagents and + // forks included, as Chat does (GEN4); Hermes's chat has only its one thread. + if (!hermes && known !== null && shell !== null && shell.projectId === buddyProjectId) + return false; + return true; } /** Asks the server for Buddy's thread: its id, or why there is none. */ -async function openBuddyThread(): Promise { +async function openBuddyThread(): Promise< + { readonly threadId: string; readonly projectId: string } | "not-ready" | "failed" +> { const response = await fetch(BUDDY_THREAD_ROUTE, { method: "POST", credentials: "same-origin", @@ -705,9 +720,11 @@ async function openBuddyThread(): Promise { }).catch(() => null); const body = (await response?.json().catch(() => null)) as { threadId?: string; + projectId?: string; error?: string; } | null; - if (response?.ok && typeof body?.threadId === "string") return body.threadId; + if (response?.ok && typeof body?.threadId === "string") + return { threadId: body.threadId, projectId: body.projectId ?? "" }; return body?.error === "no-project" ? "not-ready" : "failed"; } @@ -728,11 +745,12 @@ export function BuddySurfaceIndex() { setFailure({ attempt, outcome }); return; } - buddyThreadId = outcome; + buddyThreadId = outcome.threadId; + buddyProjectId = outcome.projectId; for (const listener of buddyThreadListeners) listener(); void navigate({ to: "/$environmentId/$threadId", - params: { environmentId, threadId: outcome }, + params: { environmentId, threadId: outcome.threadId }, replace: true, }); }); diff --git a/apps/web/src/lazurio/buddySurfaceTimeline.browser.test.tsx b/apps/web/src/lazurio/buddySurfaceTimeline.browser.test.tsx index f111e5a818af..2a89931adf86 100644 --- a/apps/web/src/lazurio/buddySurfaceTimeline.browser.test.tsx +++ b/apps/web/src/lazurio/buddySurfaceTimeline.browser.test.tsx @@ -20,6 +20,7 @@ const surface = vi.hoisted(() => ({ buddy: true })); vi.mock(import("./BuddySurface"), async (original) => ({ ...(await original()), useBuddySurfaceMode: () => surface.buddy, + useBuddyHermesControls: () => surface.buddy, })); const setup = (buddy: boolean) => { diff --git a/scripts/lazurio-release-contract.test.mjs b/scripts/lazurio-release-contract.test.mjs index fc88e60e0738..5f19b5aed230 100644 --- a/scripts/lazurio-release-contract.test.mjs +++ b/scripts/lazurio-release-contract.test.mjs @@ -3078,8 +3078,9 @@ NodeTest.test("Buddy keeps one conversation through its seams", async () => { layout, /\{toBuddysThread \? \(\n\s+\n\s+\) : shownTarget \? \(/, ); - NodeAssert.match(chat, /const buddySurface = useBuddySurfaceMode\(environmentId\) === true;/); - NodeAssert.doesNotMatch(chat, /useBuddySurfaceMode\(\)/); + // Hermes's one conversation (GEN3); Buddy's window on the shared server is a whole thread (GEN4). + NodeAssert.match(chat, /const buddySurface = useBuddyHermesControls\(environmentId\);/); + NodeAssert.doesNotMatch(chat, /useBuddyHermesControls\(\)/); NodeAssert.match(chat, /\? \{ \.\.\.environmentSettings, followUpBehavior: "steer" as const \}/); NodeAssert.match(chat, /const supportsConversationRollback =\n\s+!buddySurface &&/); // Buddy's thread keeps its provider session: upstream's /clear (a fresh session) is never offered there. @@ -3103,13 +3104,13 @@ NodeTest.test("Buddy keeps one conversation through its seams", async () => { NodeAssert.equal(timeline.match(/\buseBuddySurfaceMode\(/g)?.length, 1); NodeAssert.match( timeline, - /const buddySurface = useBuddySurfaceMode\(activeThreadEnvironmentId\) === true;\n[^]*?\n\s+const buddyDayLines = useBuddyDayLines\(rows, buddySurface\);/, + /const buddySurface = useBuddyHermesControls\(activeThreadEnvironmentId\);\n\s+const buddyDays = useBuddySurfaceMode\(activeThreadEnvironmentId\) === true;\n[^]*?\n\s+const buddyDayLines = useBuddyDayLines\(rows, buddyDays\);/, ); NodeAssert.match(timeline, /\n\s+workGroupViewState,\n\s+buddySurface,\n\s+\};/); // Since v0.1.3 the timeline navigates itself (pingdotgg/t3code#25463): the jump takes its navigateTimeline. NodeAssert.match( timeline, - /const navigateTimeline = \(\) => viewportRef\.current\?\.navigate\(\{ releasesFollow: true \}\);\n\s+useBuddyDayJump\(\{\n\s+buddy: buddySurface,\n\s+rows,\n\s+listRef,\n\s+onManualNavigation: navigateTimeline,\n\s+history: historyControls,\n\s+\}\);/, + /const navigateTimeline = \(\) => viewportRef\.current\?\.navigate\(\{ releasesFollow: true \}\);\n\s+useBuddyDayJump\(\{\n\s+buddy: buddyDays,\n\s+rows,\n\s+listRef,\n\s+onManualNavigation: navigateTimeline,\n\s+history: historyControls,\n\s+\}\);/, ); NodeAssert.match(timeline, /buddyDays: \[\.\.\.buddyDayLines\.keys\(\)\]\.join\(\),/); // Since v0.1.2 the rows live in their own files (pingdotgg/t3code#22674, pingdotgg/t3code#22677): the shared row state knows From 68c1fb681087b249473ff025595a5a43edb8c14f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mat=C4=9Bj=20Such=C3=A1nek?= <16311043+immakermatty@users.noreply.github.com> Date: Wed, 18 Nov 2026 19:54:26 +0000 Subject: [PATCH 08/12] fix(lazurio): Buddy's folder never becomes a repository, and its thread offers no Git setup MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Agent: environment a480495c-25e0-4e51-828b-1dbf1b77d62f · T3 thread 72068f77-568a-48aa-aa8a-108c03b29972 Co-Authored-By: Claude Opus 5.5 --- apps/server/src/lazurio/managedFolder.ts | 10 +++++++++- apps/server/src/lazurio/managedFolderVcs.test.ts | 7 +++++-- apps/web/src/components/GitActionsControl.tsx | 7 ++++++- scripts/lazurio-release-contract.test.mjs | 2 +- 4 files changed, 21 insertions(+), 5 deletions(-) diff --git a/apps/server/src/lazurio/managedFolder.ts b/apps/server/src/lazurio/managedFolder.ts index 16c78d602b78..9882624756a9 100644 --- a/apps/server/src/lazurio/managedFolder.ts +++ b/apps/server/src/lazurio/managedFolder.ts @@ -13,6 +13,8 @@ export const BUDDY_PROJECT_TITLE = "Buddy"; const turnOutsideFolder = "Agents in this Environment work in its Lazurio Folder. Start a new chat in the Lazurio project."; +const repositoryAtBuddyFolder = + "Buddy's folder holds Buddy's instructions and notes, so it does not become a repository."; const repositoryAtFolder = "The Lazurio Folder holds separate repositories, so it cannot become a repository itself."; @@ -49,7 +51,13 @@ export const makeFolderGuard = Effect.gen(function* () { folder === undefined ? Effect.succeed(null) : canonical(cwd).pipe( - Effect.map((path) => ((path ?? cwd) === folder ? repositoryAtFolder : null)), + Effect.map((path) => + (path ?? cwd) === folder + ? repositoryAtFolder + : buddyFolder !== undefined && (path ?? cwd) === buddyFolder + ? repositoryAtBuddyFolder + : null, + ), ), /** Whether `path` is the Folder itself; never without a managed Folder. */ isFolder: (path: string): Effect.Effect => diff --git a/apps/server/src/lazurio/managedFolderVcs.test.ts b/apps/server/src/lazurio/managedFolderVcs.test.ts index f913edda919c..710a7c037d97 100644 --- a/apps/server/src/lazurio/managedFolderVcs.test.ts +++ b/apps/server/src/lazurio/managedFolderVcs.test.ts @@ -9,7 +9,7 @@ import * as VcsProvisioningService from "../vcs/VcsProvisioningService.ts"; import { layerManagedConfig, makeFolderDirectories } from "./managedFolder.testkit.ts"; it.effect("never makes a managed Environment's Lazurio Folder a repository", () => { - const { folder, inside } = makeFolderDirectories(); + const { folder, inside, buddy } = makeFolderDirectories(); const calls: string[] = []; // Provisioning asks the driver only to make the repository. const driver = { @@ -24,6 +24,9 @@ it.effect("never makes a managed Environment's Lazurio Folder a repository", () refused.detail, "The Lazurio Folder holds separate repositories, so it cannot become a repository itself.", ); + // Buddy's folder beside it does not become one either (LZD-0033 R3). + const buddyRefused = yield* provisioning.initRepository({ cwd: buddy }).pipe(Effect.flip); + if (buddyRefused._tag !== "VcsUnsupportedOperationError") return assert.fail(buddyRefused._tag); yield* provisioning.initRepository({ cwd: inside }); assert.deepStrictEqual(calls, [inside]); }).pipe( @@ -32,7 +35,7 @@ it.effect("never makes a managed Environment's Lazurio Folder a repository", () Layer.provide( Layer.mock(VcsDriverRegistry.VcsDriverRegistry)({ get: () => Effect.succeed(driver) }), ), - Layer.provide(layerManagedConfig(folder)), + Layer.provide(layerManagedConfig(folder, buddy)), Layer.provide(NodeServices.layer), ), ), diff --git a/apps/web/src/components/GitActionsControl.tsx b/apps/web/src/components/GitActionsControl.tsx index ea075af1d083..44b6a3c14e40 100644 --- a/apps/web/src/components/GitActionsControl.tsx +++ b/apps/web/src/components/GitActionsControl.tsx @@ -1550,7 +1550,12 @@ export default function GitActionsControl({ ); - if (!gitCwd || serverConfig?.lazurioFolder === gitCwd) return null; + if ( + !gitCwd || + serverConfig?.lazurioFolder === gitCwd || + serverConfig?.lazurioBuddyFolder === gitCwd + ) + return null; return ( <> diff --git a/scripts/lazurio-release-contract.test.mjs b/scripts/lazurio-release-contract.test.mjs index 5f19b5aed230..79a3c420b519 100644 --- a/scripts/lazurio-release-contract.test.mjs +++ b/scripts/lazurio-release-contract.test.mjs @@ -1170,7 +1170,7 @@ NodeTest.test("the managed Lazurio Folder keeps its seams", async () => { ); NodeAssert.match( source.gitActions, - /if \(!gitCwd \|\| serverConfig\?\.lazurioFolder === gitCwd\) return null;/, + /if \(\n\s+!gitCwd \|\|\n\s+serverConfig\?\.lazurioFolder === gitCwd \|\|\n\s+serverConfig\?\.lazurioBuddyFolder === gitCwd\n\s+\)\n\s+return null;/, ); before( source.welcome, From cc39cb93df1eac6bb04f30becb2b0167ebe4dfb8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mat=C4=9Bj=20Such=C3=A1nek?= <16311043+immakermatty@users.noreply.github.com> Date: Wed, 18 Nov 2026 19:57:04 +0000 Subject: [PATCH 09/12] fix(lazurio): in Buddy's window a narrow right panel takes the whole width, as in Chat MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Agent: environment a480495c-25e0-4e51-828b-1dbf1b77d62f · T3 thread 72068f77-568a-48aa-aa8a-108c03b29972 Co-Authored-By: Claude Opus 5.5 --- apps/web/index.html | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/apps/web/index.html b/apps/web/index.html index 9b1dbc9f0981..a451f722be3a 100644 --- a/apps/web/index.html +++ b/apps/web/index.html @@ -748,7 +748,8 @@ } /* The right panel (RightPanelSheet.tsx, the one other sheet) takes the whole screen: no sliver of the conversation beside it. Its own toggle closes it, back to the conversation. */ - :root:has(lazurio-rail:defined) [data-slot="sheet-popup"]:not([data-mobile]) { + :root:has(lazurio-rail:defined) [data-slot="sheet-popup"]:not([data-mobile]), + :root:has([data-lazurio-buddy-surface]) [data-slot="sheet-popup"]:not([data-mobile]) { width: 100vw; min-width: 0; max-width: none; From 8bd98780ba5baa259d1caf5bf984fa77526cbdae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mat=C4=9Bj=20Such=C3=A1nek?= <16311043+immakermatty@users.noreply.github.com> Date: Wed, 18 Nov 2026 19:57:28 +0000 Subject: [PATCH 10/12] test(lazurio): the shell slot's narrow right panel rule covers Buddy's window MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Agent: environment a480495c-25e0-4e51-828b-1dbf1b77d62f · T3 thread 72068f77-568a-48aa-aa8a-108c03b29972 Co-Authored-By: Claude Opus 5.5 --- scripts/lazurio-release-contract.test.mjs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/lazurio-release-contract.test.mjs b/scripts/lazurio-release-contract.test.mjs index 79a3c420b519..e5c5da049e82 100644 --- a/scripts/lazurio-release-contract.test.mjs +++ b/scripts/lazurio-release-contract.test.mjs @@ -1417,7 +1417,7 @@ NodeTest.test("the Lazurio shell slot survives a rebuild on a new upstream tag", // width in a narrow window with the shell present. NodeAssert.match( narrow, - /:root:has\(lazurio-rail:defined\) \[data-slot="sheet-popup"\]:not\(\[data-mobile\]\) \{\s*width: 100vw;\s*min-width: 0;\s*max-width: none;/, + /:root:has\(lazurio-rail:defined\) \[data-slot="sheet-popup"\]:not\(\[data-mobile\]\),\n\s+:root:has\(\[data-lazurio-buddy-surface\]\) \[data-slot="sheet-popup"\]:not\(\[data-mobile\]\) \{\s*width: 100vw;\s*min-width: 0;\s*max-width: none;/, ); NodeAssert.ok( page.indexOf("@media (max-width: 767px)") > page.search(/#root \{\s*box-sizing: border-box;/), From fa223db4297016e6c1bd8a3048baeb960a5780c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mat=C4=9Bj=20Such=C3=A1nek?= <16311043+immakermatty@users.noreply.github.com> Date: Wed, 18 Nov 2026 20:56:28 +0000 Subject: [PATCH 11/12] fix(lazurio): Buddy's window keeps a fork or subagent open on a fresh load On a fresh page or a reload Buddy's thread id was not known yet, so the project check could not pass and the route led every thread of Buddy's project, forks and subagents included, to the root thread. The decision (leadsToBuddysThread) now takes Buddy's project from the server's Buddy folder (the unlisted project ids) and waits until the thread and that project are known; only another project's thread leads to Buddy's. Co-Authored-By: Claude Opus 5.5 --- apps/web/src/lazurio/BuddySurface.tsx | 22 +++++++++----- .../src/lazurio/buddySurfaceControls.test.ts | 30 +++++++++++++++++++ apps/web/src/lazurio/buddySurfaceControls.ts | 19 ++++++++++++ 3 files changed, 63 insertions(+), 8 deletions(-) diff --git a/apps/web/src/lazurio/BuddySurface.tsx b/apps/web/src/lazurio/BuddySurface.tsx index 738ac4a2e461..e2ec22697efa 100644 --- a/apps/web/src/lazurio/BuddySurface.tsx +++ b/apps/web/src/lazurio/BuddySurface.tsx @@ -46,12 +46,14 @@ import { type ChatShortcutsInput, isBuddySpeed, isBuddyWindowOrigin, + leadsToBuddysThread, personsQueuedRuns, type QueueMessage, withoutUnusedShortcuts, } from "./buddySurfaceControls"; import { isPlainPrimaryClick } from "./environmentBrowser"; import { pageRecordOf } from "./buddySurfacePage"; +import { useLinkedUnlistedProjectIds } from "./unlistedRows"; import { BUDDY_WORKING_ROW, buddyConversationRows, buddyFailureOf } from "./buddySurfaceTimeline"; import { prefersCzech } from "./threadTabs"; import { useBuddyFrame } from "./useBuddyFrame"; @@ -677,7 +679,6 @@ export function BuddySurfaceLayout({ children }: { readonly children: ReactNode type Opening = { readonly attempt: number; readonly outcome: "not-ready" | "failed" }; let buddyThreadId: string | null = null; -let buddyProjectId: string | null = null; const buddyThreadListeners = new Set<() => void>(); const subscribeBuddyThread = (listener: () => void) => { buddyThreadListeners.add(listener); @@ -700,12 +701,18 @@ export function useLeadsToBuddysThread( ? null : scopeThreadRef(threadRef.environmentId as EnvironmentId, threadRef.threadId as ThreadId), ); - if (threadRef === null || !buddy || threadRef.threadId === known) return false; - // Buddy's window on the shared server opens the threads of Buddy's project, its subagents and - // forks included, as Chat does (GEN4); Hermes's chat has only its one thread. - if (!hermes && known !== null && shell !== null && shell.projectId === buddyProjectId) - return false; - return true; + // Buddy's project from the server's Buddy folder, known on a fresh load before `/` ever ran. + const buddyProjectIds = useLinkedUnlistedProjectIds( + (threadRef?.environmentId ?? null) as EnvironmentId | null, + ); + if (threadRef === null || !buddy) return false; + return leadsToBuddysThread({ + threadId: threadRef.threadId, + buddyThreadId: known, + hermes, + projectId: shell?.projectId, + buddyProjectIds, + }); } /** Asks the server for Buddy's thread: its id, or why there is none. */ @@ -746,7 +753,6 @@ export function BuddySurfaceIndex() { return; } buddyThreadId = outcome.threadId; - buddyProjectId = outcome.projectId; for (const listener of buddyThreadListeners) listener(); void navigate({ to: "/$environmentId/$threadId", diff --git a/apps/web/src/lazurio/buddySurfaceControls.test.ts b/apps/web/src/lazurio/buddySurfaceControls.test.ts index e131630276ee..dd4b5442f73b 100644 --- a/apps/web/src/lazurio/buddySurfaceControls.test.ts +++ b/apps/web/src/lazurio/buddySurfaceControls.test.ts @@ -11,6 +11,7 @@ import { buddySpeedOption, buddySpeedSelection, isBuddyWindowOrigin, + leadsToBuddysThread, personsQueuedRuns, withoutUnusedShortcuts, } from "./buddySurfaceControls"; @@ -111,6 +112,35 @@ describe("Buddy's window on the shared server", () => { }); }); +describe("a thread route in Buddy's surface", () => { + const buddyProjectIds = new Set(["buddy-project"]); + const route = (over: Partial[0]>) => + leadsToBuddysThread({ + threadId: "fork", + buddyThreadId: null, + hermes: false, + projectId: "buddy-project", + buddyProjectIds, + ...over, + }); + + it("keeps a fork or subagent of Buddy's project open on a fresh load, before Buddy's thread is known", () => { + expect(route({})).toBe(false); + expect(route({ buddyThreadId: "root" })).toBe(false); + }); + + it("waits for the thread and Buddy's project before it leads anywhere", () => { + expect(route({ projectId: undefined })).toBe(false); + expect(route({ projectId: "other", buddyProjectIds: new Set() })).toBe(false); + }); + + it("leads another project's thread to Buddy's, and every other thread of Hermes's chat", () => { + expect(route({ projectId: "other" })).toBe(true); + expect(route({ hermes: true })).toBe(true); + expect(route({ hermes: true, threadId: "buddy", buddyThreadId: "buddy" })).toBe(false); + }); +}); + describe("the chat's shortcuts in Buddy's surface", () => { const binding = (command: string) => ({ command, shortcut: { key: "k" } }) as never; const input = { diff --git a/apps/web/src/lazurio/buddySurfaceControls.ts b/apps/web/src/lazurio/buddySurfaceControls.ts index d0a0ca6bb926..bebacd297436 100644 --- a/apps/web/src/lazurio/buddySurfaceControls.ts +++ b/apps/web/src/lazurio/buddySurfaceControls.ts @@ -146,6 +146,25 @@ export function personsQueuedRuns return queued.filter((run) => !notThePersons.has(run.messageId)); } +/** + * Whether a thread route in Buddy's surface leads to Buddy's thread instead. Hermes's chat (GEN3) + * has only its one thread. Buddy's window on the shared server (GEN4) opens every thread of + * Buddy's project, forks and subagents too, a fresh load included: it decides only once the thread + * (`projectId`, undefined while not loaded) and Buddy's project are known. + */ +export function leadsToBuddysThread(input: { + readonly threadId: string; + readonly buddyThreadId: string | null; + readonly hermes: boolean; + readonly projectId: string | undefined; + readonly buddyProjectIds: ReadonlySet; +}): boolean { + if (input.threadId === input.buddyThreadId) return false; + if (input.hermes) return true; + if (input.projectId === undefined || input.buddyProjectIds.size === 0) return false; + return !input.buddyProjectIds.has(input.projectId); +} + /** * Whether this page is Buddy's window on the shared server (GEN4, plan LZD-0033 R3): the page's * origin is the one the server names for Buddy's window. On Chat's origin it is Chat. From e43d3f246a66380aaeb231326b3ce5f74547fb02 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mat=C4=9Bj=20Such=C3=A1nek?= <16311043+immakermatty@users.noreply.github.com> Date: Wed, 18 Nov 2026 21:49:52 +0000 Subject: [PATCH 12/12] fix(lazurio): a missing thread in Buddy's window opens Buddy's, also on an empty server On a fresh GEN4 server with no threads, a missing thread's address in Buddy's window left a blank view: the route waited for a project that the missing thread never has, and Chat's own redirect home runs only where the environment has threads. The window now takes the route's own "missing" (resolveThreadRouteRenderState over the shell status and the thread's detail) and leads such a thread to Buddy's, which `/` then makes; a thread still loading still waits. Co-Authored-By: Claude Opus 5.5 --- apps/web/src/lazurio/BuddySurface.tsx | 30 +++++++++++++++++-- .../src/lazurio/buddySurfaceControls.test.ts | 8 +++++ apps/web/src/lazurio/buddySurfaceControls.ts | 10 +++---- 3 files changed, 41 insertions(+), 7 deletions(-) diff --git a/apps/web/src/lazurio/BuddySurface.tsx b/apps/web/src/lazurio/BuddySurface.tsx index e2ec22697efa..8140d723ca57 100644 --- a/apps/web/src/lazurio/BuddySurface.tsx +++ b/apps/web/src/lazurio/BuddySurface.tsx @@ -23,6 +23,9 @@ import { scopeThreadRef } from "@t3tools/client-runtime/environment"; import type { EnvironmentId, ThreadId } from "@t3tools/contracts"; import { useComposerDraftStore } from "~/composerDraftStore"; import { useThreadShell } from "~/state/entities"; +import { useEnvironmentShellStatus } from "~/state/shell"; +import { useEnvironmentThread } from "~/state/threads"; +import { isThreadRouteSnapshotAuthoritative, resolveThreadRouteRenderState } from "~/threadRoutes"; import type { ComposerControlsBar } from "~/components/chat/ComposerControlsBar"; import type { MessagesTimelineRow } from "~/components/chat/MessagesTimeline.logic"; import { ThreadDetailsPanel } from "~/components/chat/ThreadDetailsPanel"; @@ -701,16 +704,39 @@ export function useLeadsToBuddysThread( ? null : scopeThreadRef(threadRef.environmentId as EnvironmentId, threadRef.threadId as ThreadId), ); + const environmentId = (threadRef?.environmentId ?? null) as EnvironmentId | null; // Buddy's project from the server's Buddy folder, known on a fresh load before `/` ever ran. - const buddyProjectIds = useLinkedUnlistedProjectIds( - (threadRef?.environmentId ?? null) as EnvironmentId | null, + const buddyProjectIds = useLinkedUnlistedProjectIds(environmentId); + // Whether the server confirmed the thread missing, as ThreadRouteView decides it. + const shellStatus = useEnvironmentShellStatus(environmentId); + const asked = buddy && !hermes && shell === null && threadRef !== null; + const detail = useEnvironmentThread( + asked ? environmentId : null, + asked ? (threadRef.threadId as ThreadId) : null, + ); + const draftThread = useComposerDraftStore((store) => + asked + ? store.getDraftThreadByRef( + scopeThreadRef(threadRef.environmentId as EnvironmentId, threadRef.threadId as ThreadId), + ) + : null, ); if (threadRef === null || !buddy) return false; + const missing = + !hermes && + resolveThreadRouteRenderState({ + bootstrapComplete: isThreadRouteSnapshotAuthoritative(shellStatus), + serverThreadExists: shell !== null, + serverThreadDeleted: shell?.deletedAt != null, + unlistedThreadDetail: detail, + draftThreadExists: draftThread !== null, + }) === "missing"; return leadsToBuddysThread({ threadId: threadRef.threadId, buddyThreadId: known, hermes, projectId: shell?.projectId, + missing, buddyProjectIds, }); } diff --git a/apps/web/src/lazurio/buddySurfaceControls.test.ts b/apps/web/src/lazurio/buddySurfaceControls.test.ts index dd4b5442f73b..810921621b4f 100644 --- a/apps/web/src/lazurio/buddySurfaceControls.test.ts +++ b/apps/web/src/lazurio/buddySurfaceControls.test.ts @@ -120,6 +120,7 @@ describe("a thread route in Buddy's surface", () => { buddyThreadId: null, hermes: false, projectId: "buddy-project", + missing: false, buddyProjectIds, ...over, }); @@ -134,6 +135,13 @@ describe("a thread route in Buddy's surface", () => { expect(route({ projectId: "other", buddyProjectIds: new Set() })).toBe(false); }); + it("leads a thread the server confirmed missing to Buddy's, also before any thread exists", () => { + expect(route({ projectId: undefined, missing: true })).toBe(true); + expect(route({ projectId: undefined, missing: true, buddyProjectIds: new Set() })).toBe(true); + // Still loading is not missing: the route waits. + expect(route({ projectId: undefined, missing: false, buddyProjectIds: new Set() })).toBe(false); + }); + it("leads another project's thread to Buddy's, and every other thread of Hermes's chat", () => { expect(route({ projectId: "other" })).toBe(true); expect(route({ hermes: true })).toBe(true); diff --git a/apps/web/src/lazurio/buddySurfaceControls.ts b/apps/web/src/lazurio/buddySurfaceControls.ts index bebacd297436..1b048df51acb 100644 --- a/apps/web/src/lazurio/buddySurfaceControls.ts +++ b/apps/web/src/lazurio/buddySurfaceControls.ts @@ -147,20 +147,20 @@ export function personsQueuedRuns } /** - * Whether a thread route in Buddy's surface leads to Buddy's thread instead. Hermes's chat (GEN3) - * has only its one thread. Buddy's window on the shared server (GEN4) opens every thread of - * Buddy's project, forks and subagents too, a fresh load included: it decides only once the thread - * (`projectId`, undefined while not loaded) and Buddy's project are known. + * Whether a thread route leads to Buddy's thread: in GEN4 only another project's thread, decided + * once it and Buddy's project are known, or one the server confirmed missing, also on a server + * with no thread, where Chat's redirect home does not run. */ export function leadsToBuddysThread(input: { readonly threadId: string; readonly buddyThreadId: string | null; readonly hermes: boolean; readonly projectId: string | undefined; + readonly missing: boolean; readonly buddyProjectIds: ReadonlySet; }): boolean { if (input.threadId === input.buddyThreadId) return false; - if (input.hermes) return true; + if (input.hermes || input.missing) return true; if (input.projectId === undefined || input.buddyProjectIds.size === 0) return false; return !input.buddyProjectIds.has(input.projectId); }