Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions .github/workflows/lazurio-fork-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ jobs:
# gives a thread's agents its agent-browser session, the `t3` command following the
# version the launcher activated, Buddy's instance without T3's instructions, model or
# effort where it builds its provider instances, one request namespace for the agent
# commands' MCP sessions, and no checkpoints in Buddy's project), ws.ts (the managed
# commands' MCP sessions, no checkpoints in Buddy's project, and nothing linking into
# a Personal Environment, row 38), ws.ts (the managed
# Folder's config and Buddy's surface for clients, a dispatch run as the session that
# sent it, and no ChatGPT handoff on a Lazurio Environment), index.html
# (the shell slot, the name in the app, and the composer's room for Buddy's launcher),
Expand Down Expand Up @@ -304,10 +305,9 @@ jobs:
# Buddy's one conversation (root decision 0210, plan DEV-6676): Buddy's T3 Code is one
# thread in Buddy's layer of the Lazurio Folder, its managed Folder. The server refuses
# forks, rollbacks and any other thread (runtimeLayer.ts, above), takes no checkpoints
# in Buddy's project and keeps linked Environments off (server.ts, above, and the
# settings `t3 environment` builds for itself, cli/environment.ts), applies Buddy's
# defaults once at startup (serverRuntimeStartup.ts, above) and tells clients (ws.ts and
# the contracts' server.ts, above). The web shows Buddy's surface in place of T3's
# in Buddy's project (server.ts, above), applies Buddy's defaults once at startup
# (serverRuntimeStartup.ts, above) and tells clients (ws.ts and the contracts'
# server.ts, above). The web shows Buddy's surface in place of T3's
# sidebar and command palette (__root.tsx) and opens Buddy's thread at `/`
# (_chat.index.tsx); the chat route's shortcuts, which v0.1.3 installs at app start
# (#25366), are off there (shortcuts/chatRouteCommands.ts), and so is upstream's guest
Expand All @@ -319,7 +319,6 @@ jobs:
# (timelineRowContext.ts) and the assistant row's meta leaves the fork out
# (TimelineAssistantRows.tsx). avatar.webp is Buddy's character from the design system.
# Its code lives in apps/*/src/lazurio/ (buddySurface* and BuddySurface.tsx).
apps/server/src/cli/environment.ts
apps/web/public/assets/avatar.webp
apps/web/src/components/chat/TimelineAssistantRows.tsx
apps/web/src/components/chat/timelineRowContext.ts
Expand Down
3 changes: 1 addition & 2 deletions apps/server/src/cli/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import * as ServerConfig from "../config.ts";
import * as ServerEnvironment from "../environment/ServerEnvironment.ts";
import * as PeerLinks from "../peer/PeerLinks.ts";
import * as ServerSettings from "../serverSettings.ts";
import * as LazurioBuddyGuards from "../lazurio/buddySurfaceGuards.ts";
import * as ManagedPolicy from "../policy/ManagedPolicy.ts";
import * as SqlitePersistence from "../persistence/Sqlite.ts";
import { authLocationFlags, type CliAuthLocationFlags, resolveCliAuthConfig } from "./config.ts";
Expand Down Expand Up @@ -45,7 +44,7 @@ const runWithPeerLinks = Effect.fn("environment.runWithPeerLinks")(function* <A,
),
Layer.provide(ServerEnvironment.layer.pipe(Layer.provide(ServerSecretStore.layer))),
Layer.provide(
LazurioBuddyGuards.withoutLinkedEnvironments(ServerSettings.layer).pipe(
ServerSettings.layer.pipe(
Layer.provide(
Layer.mergeAll(
ServerSecretStore.layer,
Expand Down
92 changes: 1 addition & 91 deletions apps/server/src/lazurio/buddySurfaceGuards.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,7 @@ import * as Layer from "effect/Layer";
import * as CheckpointStore from "../checkpointing/CheckpointStore.ts";
import * as ServerConfig from "../config.ts";
import * as Orchestrator from "../orchestration-v2/Orchestrator.ts";
import * as ServerSettings from "../serverSettings.ts";
import {
buddyCommandRefusal,
withoutBuddyCheckpoints,
withoutLinkedEnvironments,
} from "./buddySurfaceGuards.ts";
import { buddyCommandRefusal, withoutBuddyCheckpoints } from "./buddySurfaceGuards.ts";
import { addProject, buddyModel, layerBuddyServer } from "./buddySurface.testkit.ts";
import { BUDDY_THREAD_ID, resolveBuddyThread } from "./buddySurfaceThread.ts";

Expand Down Expand Up @@ -279,88 +274,3 @@ describe("checkpoints in Buddy's T3 Code", () => {
);
});
});

describe("linked Environments in Buddy's T3 Code", () => {
const linkedOn = () =>
withoutLinkedEnvironments(ServerSettings.layerTest({ linkedEnvironmentsEnabled: true }));
const read = Effect.gen(function* () {
const settings = yield* ServerSettings.ServerSettingsService;
return [
(yield* settings.getSettings).linkedEnvironmentsEnabled,
(yield* settings.updateSettings({ linkedEnvironmentsEnabled: true }))
.linkedEnvironmentsEnabled,
yield* settings.withSettingsSnapshot((current) =>
Effect.succeed(current.linkedEnvironmentsEnabled),
),
];
});

it.effect("are off, also when the stored settings turn them on", () => {
const { home } = makeHome();
return Effect.gen(function* () {
assert.deepStrictEqual(yield* read, [false, false, false]);
}).pipe(
Effect.provide(linkedOn()),
Effect.provideService(HostProcess.Environment, { HOME: home, T3CODE_LAZURIO_BUDDY: "1" }),
);
});

// `t3 environment` reads the stored settings, also without the switch in its environment.
it.effect("are stored off by every write, the startup's defaults included", () => {
const { home } = makeHome();
return Effect.gen(function* () {
const stored = yield* ServerSettings.ServerSettingsService.pipe(
Effect.provide(ServerSettings.layerTest({ linkedEnvironmentsEnabled: true })),
);
const written: Array<boolean> = [];
const guarded = yield* ServerSettings.ServerSettingsService.pipe(
Effect.provide(
withoutLinkedEnvironments(
Layer.succeed(ServerSettings.ServerSettingsService, {
...stored,
updateSettingsWith: (apply) =>
Effect.map(stored.getSettings, (current) => {
const next = apply(current);
written.push(next.linkedEnvironmentsEnabled);
return next;
}),
}),
),
),
);
yield* guarded.updateSettingsWith!((current) => current);
yield* guarded.updateSettings({ linkedEnvironmentsEnabled: true });
assert.deepStrictEqual(written, [false]);
assert.isFalse((yield* stored.getSettings).linkedEnvironmentsEnabled);
}).pipe(
Effect.provideService(HostProcess.Environment, { HOME: home, T3CODE_LAZURIO_BUDDY: "1" }),
);
});

// Clients learn of the administrator's policy from this field; dropping it unlocks their controls.
it.effect("keep the administrator's policy summary", () => {
const { home } = makeHome();
const policy = { organization: "Example", lockedSettings: ["providers.codex.enabled"] };
return Effect.gen(function* () {
const settings = yield* ServerSettings.ServerSettingsService;
assert.deepStrictEqual(settings.managedPolicy, policy);
}).pipe(
Effect.provide(
withoutLinkedEnvironments(
ServerSettings.layerTest({ linkedEnvironmentsEnabled: true }, policy),
),
),
Effect.provideService(HostProcess.Environment, { HOME: home, T3CODE_LAZURIO_BUDDY: "1" }),
);
});

it.effect("are upstream's outside Buddy's T3 Code", () => {
const { home } = makeHome();
return Effect.gen(function* () {
assert.deepStrictEqual(yield* read, [true, true, true]);
}).pipe(
Effect.provide(linkedOn()),
Effect.provideService(HostProcess.Environment, { HOME: home }),
);
});
});
71 changes: 3 additions & 68 deletions apps/server/src/lazurio/buddySurfaceGuards.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
/**
* Lazurio overlay (root decision 0210, plan DEV-6676): Buddy's T3 Code has no fork, rollback, other
* thread, fresh session or deleting Buddy's thread (each loses Hermes's session), no lower runtime
* mode, no guest share or linked Environment (a Personalspace is never shared, 0091) and no
* Lazurio overlay (root decision 0210): Buddy's T3 Code has no fork, rollback, other thread, fresh
* session or deleting Buddy's thread, no lower runtime mode, no guest share (0091) and no
* checkpoints in Buddy's project, for every client and agent; elsewhere upstream's services as is.
*/
import type { OrchestrationV2ServerCommand, ServerSettings as Settings } from "@t3tools/contracts";
import type { OrchestrationV2ServerCommand } from "@t3tools/contracts";
import * as HostProcess from "@t3tools/shared/HostProcess";
import * as Effect from "effect/Effect";
import * as Layer from "effect/Layer";
import * as Path from "effect/Path";
import * as Stream from "effect/Stream";

import * as CheckpointStore from "../checkpointing/CheckpointStore.ts";
import * as Orchestrator from "../orchestration-v2/Orchestrator.ts";
import * as ServerSettings from "../serverSettings.ts";
import { buddyProjectFolder, isBuddySurfaceEnvironment } from "./buddySurface.ts";
import {
BUDDY_THREAD_CREATE_COMMAND_ID,
Expand Down Expand Up @@ -112,65 +109,3 @@ export const withoutBuddyCheckpoints = <E, R>(
});
}),
).pipe(Layer.provide(live));

/**
* Every upstream gate of linked Environments (peer-link OAuth, a linked client's `/mcp`, outbound
* links, link requests, remote tasks) reads this setting, so Buddy's reads it off whatever is stored
* and every write stores it off.
*/
export const withoutLinkedEnvironments = <E, R>(
live: Layer.Layer<ServerSettings.ServerSettingsService, E, R>,
) =>
Layer.effect(
ServerSettings.ServerSettingsService,
Effect.gen(function* () {
const settings = yield* ServerSettings.ServerSettingsService;
if (!isBuddySurfaceEnvironment(yield* HostProcess.Environment)) return settings;
const off = (current: Settings): Settings => ({
...current,
linkedEnvironmentsEnabled: false,
});
const offPatch = <P extends object>(patch: P) => ({
...patch,
linkedEnvironmentsEnabled: false,
});
const { updateSettingsWith } = settings;
return ServerSettings.ServerSettingsService.of({
start: settings.start,
ready: settings.ready,
managedPolicy: settings.managedPolicy,
getSettings: Effect.map(settings.getSettings, off),
updateSettings: Effect.fn("LazurioBuddyGuards.updateSettings")(function* (patch) {
return off(yield* settings.updateSettings(offPatch(patch)));
}),
updateProviderInstance: Effect.fn("LazurioBuddyGuards.updateProviderInstance")(
function* (mutation, patch) {
return off(yield* settings.updateProviderInstance(mutation, offPatch(patch ?? {})));
},
),
...(updateSettingsWith === undefined
? {}
: {
updateSettingsWith: Effect.fn("LazurioBuddyGuards.updateSettingsWith")(
function* (apply) {
return off(yield* updateSettingsWith((current) => off(apply(current))));
},
),
}),
withSettingsSnapshot: Effect.fn("LazurioBuddyGuards.withSettingsSnapshot")(function* <
A,
E,
R,
>(use: (current: Settings) => Effect.Effect<A, E, R>) {
return yield* settings.withSettingsSnapshot((current) => use(off(current)));
}),
// Upstream's are getters that subscribe on each read.
get streamChanges() {
return Stream.map(settings.streamChanges, off);
},
get subscribeChanges() {
return Effect.map(settings.subscribeChanges, Stream.map(off));
},
});
}),
).pipe(Layer.provide(live));
Loading
Loading