Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
60a9cb3
feat: add production plugin runtime
t3-code-bot[bot] Aug 19, 2026
14cd84c
refactor: expose plugin runtime as effect service
t3-code-bot[bot] Aug 19, 2026
431c7c7
fix: make plugin shutdown interruption safe
t3-code-bot[bot] Aug 19, 2026
0f78d2b
fix: roll back interrupted plugin reconciliation
t3-code-bot[bot] Aug 19, 2026
72d3a0a
fix: harden interrupted plugin callbacks
t3-code-bot[bot] Aug 19, 2026
596bd97
feat: add plugin command catalog
t3-code-bot[bot] Aug 19, 2026
12b8e9e
fix: harden plugin command catalog
t3-code-bot[bot] Aug 19, 2026
ceb3640
fix: address plugin command review findings
t3-code-bot[bot] Aug 19, 2026
4c1b5a6
fix: serialize plugin catalog publication
t3-code-bot[bot] Aug 19, 2026
0422cae
feat: add plugin package lifecycle
t3-code-bot[bot] Aug 19, 2026
69e4b12
fix: align plugin lifecycle effect errors
t3-code-bot[bot] Aug 20, 2026
3b532e1
fix: keep plugin status failures scoped
t3-code-bot[bot] Aug 20, 2026
0ebe3fe
chore: rerun flaky ci
t3-code-bot[bot] Aug 20, 2026
7809007
refactor: defer mobile plugin commands
t3-code-bot[bot] Aug 23, 2026
48c0e28
Merge branch 'feat/plugin-command-catalog' into feat/plugin-package-l…
t3-code-bot[bot] Aug 23, 2026
890e002
feat: add plugin management settings
t3-code-bot[bot] Aug 23, 2026
52a541f
fix: disable plugin actions during mutations
t3-code-bot[bot] Aug 23, 2026
e0619c3
refactor: use shared plugin empty state
t3-code-bot[bot] Aug 23, 2026
6a85281
fix: align plugin settings header actions
t3-code-bot[bot] Aug 23, 2026
2849683
Merge remote-tracking branch 'origin/main' into feat/plugin-managemen…
t3-code-bot[bot] Aug 23, 2026
376ea51
fix: align plugin loading state
t3-code-bot[bot] Aug 23, 2026
691c592
fix: preserve plugin command error context
t3-code-bot[bot] Aug 23, 2026
221e6d2
fix: isolate plugin package failures
t3-code-bot[bot] Aug 23, 2026
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
1 change: 1 addition & 0 deletions apps/server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
"devDependencies": {
"@effect/vitest": "catalog:",
"@t3tools/contracts": "workspace:*",
"@t3tools/plugin-runtime": "workspace:*",
"@t3tools/shared": "workspace:*",
"@t3tools/tailscale": "workspace:*",
"@t3tools/web": "workspace:*",
Expand Down
12 changes: 12 additions & 0 deletions apps/server/src/auth/RpcAuthorization.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,18 @@ describe("RPC authorization scopes", () => {
expect(requiredScopeForRpcMethod(WS_METHODS.cloudInstallRelayClient)).toBe(AuthRelayWriteScope);
});

it("allows command discovery with read scope and invocation with operate scope", () => {
expect(requiredScopeForRpcMethod(WS_METHODS.pluginCommandsList)).toBe(
AuthOrchestrationReadScope,
);
expect(requiredScopeForRpcMethod(WS_METHODS.subscribePluginCommands)).toBe(
AuthOrchestrationReadScope,
);
expect(requiredScopeForRpcMethod(WS_METHODS.pluginCommandsInvoke)).toBe(
AuthOrchestrationOperateScope,
);
});

it("requires permission to operate on a thread before uploading feedback", () => {
expect(requiredScopeForRpcMethod(WS_METHODS.providerUploadFeedback)).toBe(
AuthOrchestrationOperateScope,
Expand Down
7 changes: 7 additions & 0 deletions apps/server/src/auth/RpcAuthorization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,13 @@ export const RPC_REQUIRED_SCOPES = {
[WS_METHODS.serverReportClientActivity]: AuthOrchestrationReadScope,
[WS_METHODS.serverReportHostPowerState]: AuthOrchestrationOperateScope,
[WS_METHODS.serverGetBackgroundPolicy]: AuthOrchestrationReadScope,
[WS_METHODS.pluginCommandsList]: AuthOrchestrationReadScope,
[WS_METHODS.pluginCommandsInvoke]: AuthOrchestrationOperateScope,
[WS_METHODS.pluginPackagesStatus]: AuthOrchestrationReadScope,
[WS_METHODS.pluginPackagesEnable]: AuthOrchestrationOperateScope,
[WS_METHODS.pluginPackagesDisable]: AuthOrchestrationOperateScope,
[WS_METHODS.pluginPackagesReload]: AuthOrchestrationOperateScope,
[WS_METHODS.subscribePluginCommands]: AuthOrchestrationReadScope,
[WS_METHODS.cloudGetRelayClientStatus]: AuthRelayReadScope,
[WS_METHODS.cloudInstallRelayClient]: AuthRelayWriteScope,
[WS_METHODS.pullRequestsList]: AuthOrchestrationReadScope,
Expand Down
246 changes: 246 additions & 0 deletions apps/server/src/plugins/PluginCommandCatalog.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,246 @@
import { it } from "@effect/vitest";
import { describe, expect } from "vite-plus/test";
import * as Effect from "effect/Effect";
import * as Exit from "effect/Exit";
import * as Fiber from "effect/Fiber";
import * as Option from "effect/Option";
import * as Stream from "effect/Stream";

import type { PluginDefinition } from "@t3tools/plugin-runtime";

import * as PluginCommandCatalog from "./PluginCommandCatalog.ts";

const testPlugin = (input: {
readonly fail?: boolean;
readonly message: string;
readonly onDispose?: () => void | Promise<void>;
readonly version: string;
}): PluginDefinition => ({
id: "acme.command-plugin",
version: input.version,
activate(context) {
if (input.fail === true) throw new Error("activation failed");
if (input.onDispose !== undefined) context.onDispose(input.onDispose);
PluginCommandCatalog.registerPluginCommand(context, {
command: {
id: "acme.hello",
label: "Say hello",
description: "Return a greeting from the trusted test plugin.",
surfaces: ["web", "desktop", "mobile"],
},
handler: Effect.succeed({ message: input.message, tone: "success" }),
});
},
});

describe("plugin command catalog", () => {
it("keeps command identity on execution errors", () => {
const error = new PluginCommandCatalog.PluginCommandExecutionError({
cause: new Error("handler failed"),
id: "acme.hello",
});

expect(error.message).toBe("Plugin command acme.hello failed during execution.");
});

it.effect("lists and invokes the trusted built-in command", () =>
Effect.gen(function* () {
const catalog = yield* PluginCommandCatalog.PluginCommandCatalog;
const listed = yield* catalog.list;
const streamed = yield* Stream.runHead(catalog.changes);

expect(listed.commands.map((command) => command.id)).toContain("t3.plugin-runtime.status");
expect(Object.isFrozen(listed)).toBe(true);
expect(Object.isFrozen(listed.commands)).toBe(true);
expect(Object.isFrozen(listed.commands[0])).toBe(true);
expect(Object.isFrozen(listed.commands[0]?.surfaces)).toBe(true);
expect(Option.getOrNull(streamed)).toEqual(listed);
expect(
yield* catalog.invoke({
generation: listed.generation,
id: "t3.plugin-runtime.status",
}),
).toEqual({ message: "Plugin runtime is active.", tone: "success" });
}).pipe(Effect.provide(PluginCommandCatalog.layer)),
);

it.effect("keeps the committed command and handler when replacement activation fails", () =>
Effect.gen(function* () {
const catalog = yield* PluginCommandCatalog.PluginCommandCatalog;
const first = yield* catalog.reconcile([
testPlugin({ message: "hello one", version: "1.0.0" }),
]);
const failed = yield* Effect.exit(
catalog.reconcile([testPlugin({ fail: true, message: "hello two", version: "2.0.0" })]),
);

expect(Exit.isFailure(failed)).toBe(true);
expect(yield* catalog.list).toEqual(first);
expect(yield* catalog.invoke({ generation: first.generation, id: "acme.hello" })).toEqual({
message: "hello one",
tone: "success",
});
}).pipe(Effect.provide(PluginCommandCatalog.layer)),
);

it.effect("does not republish an unchanged command catalog", () =>
Effect.gen(function* () {
const catalog = yield* PluginCommandCatalog.PluginCommandCatalog;
const definition = testPlugin({ message: "hello one", version: "1.0.0" });

const first = yield* catalog.reconcile([definition]);
const second = yield* catalog.reconcile([definition]);

expect(second).toBe(first);
}).pipe(Effect.provide(PluginCommandCatalog.layer)),
);

it.effect("rolls back invalid command metadata before publishing a generation", () =>
Effect.gen(function* () {
const catalog = yield* PluginCommandCatalog.PluginCommandCatalog;
const first = yield* catalog.list;
const invalid: PluginDefinition = {
id: "acme.invalid-command-plugin",
version: "1.0.0",
activate(context) {
context.register(
"commands",
{
id: "acme.invalid",
label: "Invalid command",
data: { surfaces: ["server"] },
},
Effect.succeed({ message: "invalid", tone: "success" as const }),
);
},
};

const failed = yield* Effect.exit(catalog.reconcile([invalid]));

const shadowedIdentity: PluginDefinition = {
id: "acme.shadowed-command-plugin",
version: "1.0.0",
activate(context) {
context.register(
"commands",
{
id: "acme.registered",
label: "Registered command",
data: {
id: "acme.advertised",
label: "Advertised command",
surfaces: ["web"],
},
},
Effect.succeed({ message: "shadowed", tone: "success" as const }),
);
},
};
const shadowed = yield* Effect.exit(catalog.reconcile([shadowedIdentity]));

expect(Exit.isFailure(failed)).toBe(true);
expect(Exit.isFailure(shadowed)).toBe(true);
expect(yield* catalog.list).toBe(first);
expect(
yield* catalog.invoke({
generation: first.generation,
id: "t3.plugin-runtime.status",
}),
).toEqual({ message: "Plugin runtime is active.", tone: "success" });
}).pipe(Effect.provide(PluginCommandCatalog.layer)),
);

it.effect("serializes runtime reconciliation through catalog publication", () =>
Effect.gen(function* () {
const catalog = yield* PluginCommandCatalog.PluginCommandCatalog;
let markActivationStarted!: () => void;
let releaseActivation!: () => void;
let markSecondActivationStarted!: () => void;
const activationStarted = new Promise<void>((resolve) => {
markActivationStarted = resolve;
});
const activationGate = new Promise<void>((resolve) => {
releaseActivation = resolve;
});
const secondActivationStarted = new Promise<void>((resolve) => {
markSecondActivationStarted = resolve;
});
const firstPlugin: PluginDefinition = {
id: "acme.first-command-plugin",
version: "1.0.0",
activate(context) {
markActivationStarted();
return activationGate.then(() => {
PluginCommandCatalog.registerPluginCommand(context, {
command: { id: "acme.first", label: "First", surfaces: ["web"] },
handler: Effect.succeed({ message: "first", tone: "success" }),
});
});
},
};
const secondPlugin: PluginDefinition = {
id: "acme.second-command-plugin",
version: "1.0.0",
activate(context) {
markSecondActivationStarted();
PluginCommandCatalog.registerPluginCommand(context, {
command: { id: "acme.second", label: "Second", surfaces: ["web"] },
handler: Effect.succeed({ message: "second", tone: "success" }),
});
},
};

const firstFiber = yield* Effect.forkChild(catalog.reconcile([firstPlugin]));
yield* Effect.promise(() => activationStarted);
const secondFiber = yield* Effect.forkChild(catalog.reconcile([secondPlugin]));
yield* Effect.yieldNow;
releaseActivation();

const first = yield* Fiber.join(firstFiber);
yield* Effect.promise(() => secondActivationStarted);
const generationSeenBySecondActivation = (yield* catalog.list).generation;
const second = yield* Fiber.join(secondFiber);
expect(generationSeenBySecondActivation).toBe(first.generation);
expect(yield* catalog.list).toBe(second);
}).pipe(Effect.provide(PluginCommandCatalog.layer)),
);

it.effect("publishes a committed runtime generation before reporting interruption", () =>
Effect.gen(function* () {
const catalog = yield* PluginCommandCatalog.PluginCommandCatalog;
let markRetirementStarted!: () => void;
let releaseRetirement!: () => void;
const retirementStarted = new Promise<void>((resolve) => {
markRetirementStarted = resolve;
});
const retirementGate = new Promise<void>((resolve) => {
releaseRetirement = resolve;
});
const first = yield* catalog.reconcile([
testPlugin({
message: "hello one",
onDispose: async () => {
markRetirementStarted();
await retirementGate;
},
version: "1.0.0",
}),
]);
const replacement = yield* Effect.forkChild(
catalog.reconcile([testPlugin({ message: "hello two", version: "2.0.0" })]),
);
yield* Effect.promise(() => retirementStarted);
const interruption = yield* Effect.forkChild(Fiber.interrupt(replacement));
yield* Effect.yieldNow;
releaseRetirement();
yield* Fiber.join(interruption);

const second = yield* catalog.list;
expect(second.generation).toBe(first.generation + 1);
expect(yield* catalog.invoke({ generation: second.generation, id: "acme.hello" })).toEqual({
message: "hello two",
tone: "success",
});
}).pipe(Effect.provide(PluginCommandCatalog.layer)),
);
});
Loading
Loading