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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ This is a personal fork of [pingdotgg/t3code](https://github.com/pingdotgg/t3cod

- **Thread tools for agents.** Agents can list custom thread groups with their thread counts, create a group, and move a thread into a group or back to Active with `t3_thread_groups`, and can start new threads directly in a group by passing `groupId` to `t3_thread_launch` or `create_threads`; renaming, deleting, and reordering groups stay with you. `t3_thread_drain_status` tells an agent whether a thread is fully quiet (no active or queued run, no subagents, monitors, or background commands left), for example before handing its session to another machine. `t3_thread_list` can list every project at once and find the threads bound to a worktree path. When a thread an agent started with `t3_thread_launch` fails workspace preparation on the same machine (a branch already in use, a reserved lab), that agent gets a message with the error so it can launch again.

- **Agents edit project actions.** Agents list, add, update, and remove a project's action buttons with `t3_project_actions_list`, `t3_project_actions_upsert`, and `t3_project_actions_remove`. Edits change the same actions the app shows, keep only one worktree setup action, and fail instead of overwriting a concurrent change. Changing actions needs a full-access agent.
- **Agents edit project actions.** Agents add, update, and remove a project's action buttons with `t3_project_actions_upsert` and `t3_project_actions_remove`; `t3_project_read` lists them. Edits change the same actions the app shows, keep only one worktree setup action, and fail instead of overwriting a concurrent change. Changing actions needs a full-access agent.

- **Open a project's dev server from an action.** In the desktop app, give an action a Preview URL and turn on **Open in browser, reusing a running dev server**. If a web server is already running from the project or worktree directory, clicking the action opens it in the in-app browser without running the command again. Otherwise it runs the command, waits up to a minute for the server, and opens it. Only the URL's path matters, so Vite moving to another port is fine. Detection uses `lsof` on macOS and Linux; on Windows, or for servers in Docker, the action runs the command and opens the configured URL.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,52 +10,52 @@ import * as Ref from "effect/Ref";
import { HttpBody, HttpClient, HttpRouter } from "effect/http";
import * as McpProviderSessions from "@t3tools/provider-core/server/McpProviderSessions";

import * as DocumentText from "../../../provider/DocumentText.ts";
import * as ServerConfig from "../../../config.ts";
import * as DeviceService from "../../../device/DeviceService.ts";
import * as ServerEnvironment from "../../../environment/ServerEnvironment.ts";
import * as GitManager from "../../../git/GitManager.ts";
import * as GitWorkflowService from "../../../git/GitWorkflowService.ts";
import * as Orchestrator from "../../../orchestration-v2/Orchestrator.ts";
import * as ProjectionStore from "../../../orchestration-v2/ProjectionStore.ts";
import * as ProviderAdapterRegistry from "../../../orchestration-v2/ProviderAdapterRegistry.ts";
import * as IssueService from "../../../issue/IssueService.ts";
import * as ThreadIssueService from "../../../orchestration-v2/ThreadIssueService.ts";
import * as ThreadManagementService from "../../../orchestration-v2/ThreadManagementService.ts";
import * as ProjectService from "../../../project/ProjectService.ts";
import * as ProjectSetupScriptRunner from "../../../project/ProjectSetupScriptRunner.ts";
import * as PullRequestReviewGuideService from "../../../pullRequest/PullRequestReviewGuideService.ts";
import * as PullRequestService from "../../../pullRequest/PullRequestService.ts";
import * as EnvironmentTheme from "../../../environmentTheme.ts";
import * as ProviderRegistry from "../../../provider/ProviderRegistry.ts";
import * as ScheduledTaskService from "../../../scheduledTasks/ScheduledTaskService.ts";
import * as SecretRequests from "../../../secrets/SecretRequests.ts";
import * as ServerSettings from "../../../serverSettings.ts";
import * as AssetSigner from "../../../assets/AssetSigner.ts";
import * as LabsService from "../../../labs/LabsService.ts";
import * as TelegramService from "../../../telegram/TelegramService.ts";
import * as VcsStatusBroadcaster from "../../../vcs/VcsStatusBroadcaster.ts";
import * as ServerSecretStore from "../../../auth/ServerSecretStore.ts";
import * as ManagedProjectFolders from "../../../project/ManagedProjectFolders.ts";
import * as ThreadArchiveScheduler from "../../../orchestration-v2/ThreadArchiveScheduler.ts";
import * as PeerForwarding from "../../../peer/PeerForwarding.ts";
import * as PeerLinkRequests from "../../../peer/PeerLinkRequests.ts";
import * as PeerLinks from "../../../peer/PeerLinks.ts";
import * as RemoteDelegation from "../../../peer/RemoteDelegation.ts";
import * as ThreadLaunchService from "../../../orchestration-v2/ThreadLaunchService.ts";
import * as ThreadSearch from "../../../orchestration-v2/ThreadSearch.ts";
import * as ThreadWorktreeSwitchScheduler from "../../../orchestration-v2/ThreadWorktreeSwitchScheduler.ts";
import * as PreviewManager from "../../../preview/Manager.ts";
import * as SourceControlRepositoryService from "../../../sourceControl/SourceControlRepositoryService.ts";
import * as GitVcsDriver from "../../../vcs/GitVcsDriver.ts";
import * as AgentVoiceReply from "../../../voice/AgentVoiceReply.ts";
import * as ProjectCloneTracker from "../../../project/ProjectCloneTracker.ts";
import * as McpHttpServer from "../../McpHttpServer.ts";
import type { McpCapability } from "../../McpInvocationContext.ts";
import * as McpSessionRegistry from "../../McpSessionRegistry.ts";
import * as McpToolAccessTestkit from "../../McpToolAccess.testkit.ts";
import * as PreviewAutomationBroker from "../../PreviewAutomationBroker.ts";
import * as PreviewBrowser from "../../../preview/PreviewBrowser.ts";
import * as DocumentText from "../../provider/DocumentText.ts";
import * as ServerConfig from "../../config.ts";
import * as DeviceService from "../../device/DeviceService.ts";
import * as ServerEnvironment from "../../environment/ServerEnvironment.ts";
import * as GitManager from "../../git/GitManager.ts";
import * as GitWorkflowService from "../../git/GitWorkflowService.ts";
import * as Orchestrator from "../../orchestration-v2/Orchestrator.ts";
import * as ProjectionStore from "../../orchestration-v2/ProjectionStore.ts";
import * as ProviderAdapterRegistry from "../../orchestration-v2/ProviderAdapterRegistry.ts";
import * as IssueService from "../../issue/IssueService.ts";
import * as ThreadIssueService from "../../orchestration-v2/ThreadIssueService.ts";
import * as ThreadManagementService from "../../orchestration-v2/ThreadManagementService.ts";
import * as ProjectService from "../../project/ProjectService.ts";
import * as ProjectSetupScriptRunner from "../../project/ProjectSetupScriptRunner.ts";
import * as PullRequestReviewGuideService from "../../pullRequest/PullRequestReviewGuideService.ts";
import * as PullRequestService from "../../pullRequest/PullRequestService.ts";
import * as EnvironmentTheme from "../../environmentTheme.ts";
import * as ProviderRegistry from "../../provider/ProviderRegistry.ts";
import * as ScheduledTaskService from "../../scheduledTasks/ScheduledTaskService.ts";
import * as SecretRequests from "../../secrets/SecretRequests.ts";
import * as ServerSettings from "../../serverSettings.ts";
import * as AssetSigner from "../../assets/AssetSigner.ts";
import * as LabsService from "../../labs/LabsService.ts";
import * as TelegramService from "../../telegram/TelegramService.ts";
import * as VcsStatusBroadcaster from "../../vcs/VcsStatusBroadcaster.ts";
import * as ServerSecretStore from "../../auth/ServerSecretStore.ts";
import * as ManagedProjectFolders from "../../project/ManagedProjectFolders.ts";
import * as ThreadArchiveScheduler from "../../orchestration-v2/ThreadArchiveScheduler.ts";
import * as PeerForwarding from "../../peer/PeerForwarding.ts";
import * as PeerLinkRequests from "../../peer/PeerLinkRequests.ts";
import * as PeerLinks from "../../peer/PeerLinks.ts";
import * as RemoteDelegation from "../../peer/RemoteDelegation.ts";
import * as ThreadLaunchService from "../../orchestration-v2/ThreadLaunchService.ts";
import * as ThreadSearch from "../../orchestration-v2/ThreadSearch.ts";
import * as ThreadWorktreeSwitchScheduler from "../../orchestration-v2/ThreadWorktreeSwitchScheduler.ts";
import * as PreviewManager from "../../preview/Manager.ts";
import * as SourceControlRepositoryService from "../../sourceControl/SourceControlRepositoryService.ts";
import * as GitVcsDriver from "../../vcs/GitVcsDriver.ts";
import * as AgentVoiceReply from "../../voice/AgentVoiceReply.ts";
import * as ProjectCloneTracker from "../../project/ProjectCloneTracker.ts";
import * as McpHttpServer from "../McpHttpServer.ts";
import type { McpCapability } from "../McpInvocationContext.ts";
import * as McpSessionRegistry from "../McpSessionRegistry.ts";
import * as McpToolAccessTestkit from "../McpToolAccess.testkit.ts";
import * as PreviewAutomationBroker from "../PreviewAutomationBroker.ts";
import * as PreviewBrowser from "../../preview/PreviewBrowser.ts";

const StubServicesLive = Layer.mergeAll(
McpProviderSessions.layer,
Expand Down Expand Up @@ -105,7 +105,7 @@ const StubServicesLive = Layer.mergeAll(
Layer.mock(ThreadIssueService.ThreadIssueService)({}),
);

const threadId = ThreadId.make("thread-voice-mcp");
const threadId = ThreadId.make("thread-fork-islands-mcp");

/** Speaks JSON-RPC to the island the credential's endpoint names. */
const mcpSession = (
Expand All @@ -127,7 +127,7 @@ const mcpSession = (
const init = yield* httpClient.post(path, {
headers,
body: HttpBody.text(
`{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2025-06-18","capabilities":{},"clientInfo":{"name":"voice","version":"1.0.0"}}}`,
`{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2025-06-18","capabilities":{},"clientInfo":{"name":"fork-islands","version":"1.0.0"}}}`,
"application/json",
),
});
Expand Down Expand Up @@ -156,7 +156,8 @@ const toolNames = (body: string): ReadonlyArray<string> => {
return payload.result.tools.map((tool) => tool.name);
};

it.effect("voice_reply exists only for credentials with the voice capability", () =>
// Fork: every island lists the common fork tools; only voice islands list voice_reply.
it.effect("fork tools are listed on the islands their capabilities name", () =>
Effect.scoped(
Effect.gen(function* () {
const staged = yield* Ref.make<ReadonlyArray<string>>([]);
Expand All @@ -167,7 +168,7 @@ it.effect("voice_reply exists only for credentials with the voice capability", (
),
});
const layerEnvironment = Layer.mock(ServerEnvironment.ServerEnvironment)({
getEnvironmentId: Effect.succeed("environment-voice" as never),
getEnvironmentId: Effect.succeed("environment-fork-islands" as never),
});
const registry = Context.get(
yield* Layer.build(McpSessionRegistry.layer.pipe(Layer.provide(layerEnvironment))),
Expand All @@ -184,37 +185,33 @@ it.effect("voice_reply exists only for credentials with the voice capability", (
Layer.build,
);

for (const capabilities of [
new Set<McpCapability>(["voice"]),
new Set<McpCapability>(["voice", "preview"]),
new Set<McpCapability>(["voice", "device"]),
new Set<McpCapability>(["voice", "preview", "device"]),
]) {
const session = yield* mcpSession(registry, capabilities);
expect(toolNames(yield* session.call(2, "tools/list", {})), session.path).toContain(
"voice_reply",
);
}
const paths = new Set<string>();
for (const capabilities of [
new Set<McpCapability>(),
new Set<McpCapability>(["preview"]),
new Set<McpCapability>(["voice"]),
new Set<McpCapability>(["preview", "voice"]),
new Set<McpCapability>(["device"]),
new Set<McpCapability>(["preview", "device"]),
new Set<McpCapability>(["device", "preview"]),
new Set<McpCapability>(["device", "voice"]),
new Set<McpCapability>(["device", "preview", "voice"]),
]) {
const session = yield* mcpSession(registry, capabilities);
paths.add(session.path);
const names = toolNames(yield* session.call(2, "tools/list", {}));
expect(names, session.path).not.toContain("voice_reply");
// Fork toolkits that need no extra capability ride on every island.
expect(names, session.path).toEqual(
expect.arrayContaining([
"archive_thread",
"t3_project_actions_list",
"t3_project_actions_upsert",
"t3_project_actions_remove",
"t3_thread_drain_status",
"t3_thread_groups",
"telegram_send",
]),
);
expect(names.includes("voice_reply"), session.path).toBe(capabilities.has("voice"));
}
expect(paths.size).toBe(8);

// The call stages for the credential's own thread.
const voice = yield* mcpSession(registry, new Set<McpCapability>(["voice"]));
Expand All @@ -229,7 +226,7 @@ it.effect("voice_reply exists only for credentials with the voice capability", (
Effect.provide(
Layer.mergeAll(
NodeHttpServer.layerTest,
ServerConfig.layerTest(process.cwd(), { prefix: "t3-voice-mcp-" }).pipe(
ServerConfig.layerTest(process.cwd(), { prefix: "t3-fork-islands-mcp-" }).pipe(
Layer.provide(NodeServices.layer),
),
NodeServices.layer,
Expand Down
16 changes: 5 additions & 11 deletions apps/server/src/mcp/toolkits/projectActions/handlers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,12 +116,6 @@ it.effect("edits the calling thread's project actions as a full-access caller",
action: "created",
projectAction: { id: "test", command: "vp test" },
});
const listed = yield* call("t3_project_actions_list");
expect(listed.structuredContent).toMatchObject({
projectId,
title: "Tools",
actions: [{ id: "test" }],
});
expect(
declaredFailure(yield* call("t3_project_actions_remove", { actionId: "lint" })),
).toMatchObject({ code: "invalid_request", message: expect.stringContaining("'lint'") });
Expand All @@ -131,9 +125,8 @@ it.effect("edits the calling thread's project actions as a full-access caller",
}).pipe(Effect.scoped, Effect.provide(makeLayer("full-access"))),
);

it.effect("lets a narrower caller list but not change actions", () =>
it.effect("refuses action changes from a narrower caller", () =>
Effect.gen(function* () {
expect((yield* call("t3_project_actions_list")).isError).toBe(false);
expect(
declaredFailure(yield* call("t3_project_actions_upsert", { name: "Test", command: "x" })),
).toMatchObject({ code: "capability_denied" });
Expand Down Expand Up @@ -168,9 +161,10 @@ it.effect("refuses an edit when the caller's turn ends while it waits for its lo
expect(declaredFailure(yield* Fiber.join(upsert))).toMatchObject({
code: "parent_not_active",
});
// Nothing was written: the action the refused edit would have created does not exist.
caller.activeRunId = RunId.make("run-2");
expect((yield* call("t3_project_actions_list")).structuredContent).toMatchObject({
actions: [],
});
expect(
declaredFailure(yield* call("t3_project_actions_remove", { actionId: "test" })),
).toMatchObject({ code: "invalid_request" });
}).pipe(Effect.scoped, Effect.provide(makeLayer("full-access", caller)));
});
12 changes: 2 additions & 10 deletions apps/server/src/mcp/toolkits/projectActions/handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,11 @@ const resolveTarget = (projectId: ProjectId | undefined) =>
readCaller().pipe(Effect.flatMap((context) => resolveProjectId(context, projectId)));

/**
* Fork: project actions toolkit. Listing reads; edits, like other project
* changes, need a full-access caller, re-checked under the caller's lock
* right before writing. Edits compare-and-set against the actions they read,
* Fork: project actions toolkit. Edits, like other project changes, need a
* full-access caller, re-checked under the caller's lock right before writing. Edits compare-and-set against the actions they read,
* so a concurrent change is refused rather than lost.
*/
export const layer = McpToolAccess.toLayer(ProjectActionsToolkit, {
t3_project_actions_list: McpToolAccess.reads((input) =>
Effect.gen(function* () {
const projectId = yield* resolveTarget(input.projectId);
const actions = yield* ProjectActions.ProjectActions;
return yield* actions.list(projectId).pipe(Effect.mapError(failure));
}),
),
t3_project_actions_upsert: McpToolAccess.writesEnvironment((input, check) =>
Effect.gen(function* () {
const projectId = yield* resolveTarget(input.projectId);
Expand Down
Loading
Loading