;
+}
+
+export type ThreadMachineMoveOutcome =
+ | { readonly _tag: "Cancelled" }
+ /** Nothing changed on either machine. */
+ | { readonly _tag: "Failed"; readonly message: string }
+ /** The new thread exists; `archiveError` says the old one is still active beside it. */
+ | {
+ readonly _tag: "Moved";
+ readonly threadRef: ScopedThreadRef;
+ readonly archiveError: string | null;
+ };
+
+export interface ThreadMachineMoveTarget {
+ readonly environmentId: EnvironmentId;
+ readonly label: string;
+ readonly projects: ReadonlyArray
;
+}
+
+interface MoveServerConfig {
+ readonly scratchWorkspaceRoot?: string | undefined;
+ readonly environment: { readonly capabilities: { readonly threadMoveToMachine?: boolean } };
+}
+
+/**
+ * The other connected machines a thread can move to, each with its projects. Both ends must
+ * support it, and this connection must be able to change threads on both.
+ */
+export function threadMachineMoveTargets<
+ P extends Parameters[0][number],
+>(input: {
+ readonly sourceEnvironmentId: EnvironmentId;
+ readonly connectedEnvironmentIds: ReadonlyArray;
+ readonly serverConfigs: ReadonlyMap;
+ readonly projects: ReadonlyArray;
+ readonly labelOf: (environmentId: EnvironmentId) => string | undefined;
+ readonly canOperate: (environmentId: EnvironmentId) => boolean;
+}): ReadonlyArray> {
+ const supports = (environmentId: EnvironmentId) =>
+ input.serverConfigs.get(environmentId)?.environment.capabilities.threadMoveToMachine === true;
+ if (!supports(input.sourceEnvironmentId) || !input.canOperate(input.sourceEnvironmentId)) {
+ return [];
+ }
+ return input.connectedEnvironmentIds.flatMap((environmentId) => {
+ const label = input.labelOf(environmentId);
+ if (
+ environmentId === input.sourceEnvironmentId ||
+ label === undefined ||
+ !supports(environmentId) ||
+ !input.canOperate(environmentId)
+ ) {
+ return [];
+ }
+ const projects = threadMoveProjects(
+ input.projects,
+ environmentId,
+ input.serverConfigs.get(environmentId)?.scratchWorkspaceRoot,
+ );
+ return projects.length === 0 ? [] : [{ environmentId, label, projects }];
+ });
+}
+
+function failureMessage(
+ result: AtomCommandResult,
+ resolve: MFunctionType,
+): string {
+ const error = result._tag === "Failure" ? squashAtomCommandFailure(result) : undefined;
+ return error instanceof Error && error.message !== ""
+ ? error.message
+ : resolve(msg("Try again."));
+}
+
+const movesInFlight = new Set();
+const quiet = { reportFailure: false };
+
+/**
+ * Copies the thread's conversation to a project on another machine, then archives it here. The
+ * client carries the bundle over connections it already has, so the servers never trust each
+ * other. Archiving waits for the import, so a failed import changes nothing.
+ */
+export async function moveThreadToMachine(input: {
+ readonly registry: AtomRegistry.AtomRegistry;
+ readonly commands: ThreadMachineMoveCommands;
+ readonly source: ScopedThreadRef;
+ readonly sourceLabel: string;
+ readonly target: { readonly environmentId: EnvironmentId; readonly projectId: ProjectId };
+ /** "api on VPS": where the archived thread says it went. */
+ readonly targetLabel: string;
+ readonly confirm: (exported: ProjectExportThreadResult) => Promise;
+ readonly resolve?: MFunctionType;
+}): Promise {
+ // A second pick while one runs would import the conversation twice.
+ const key = scopedThreadKey(input.source);
+ if (movesInFlight.has(key)) return { _tag: "Cancelled" };
+ movesInFlight.add(key);
+ try {
+ return await moveOnce(input);
+ } finally {
+ movesInFlight.delete(key);
+ }
+}
+
+async function moveOnce(
+ input: Parameters[0],
+): Promise {
+ const { registry, commands, source, target, resolve = mFallback } = input;
+ const settled = (result: AtomCommandResult): ThreadMachineMoveOutcome =>
+ isAtomCommandInterrupted(result)
+ ? { _tag: "Cancelled" }
+ : { _tag: "Failed", message: failureMessage(result, resolve) };
+
+ const exported = await runAtomCommand(
+ registry,
+ commands.exportThread,
+ {
+ environmentId: source.environmentId,
+ input: { threadId: source.threadId },
+ },
+ quiet,
+ );
+ if (exported._tag !== "Success") return settled(exported);
+ if (!(await input.confirm(exported.value))) return { _tag: "Cancelled" };
+
+ const imported = await runAtomCommand(
+ registry,
+ commands.importThread,
+ {
+ environmentId: target.environmentId,
+ input: {
+ projectId: target.projectId,
+ bundle: exported.value.bundle,
+ movedFrom: input.sourceLabel,
+ leftBehind: exported.value.leftBehind,
+ },
+ },
+ quiet,
+ );
+ if (imported._tag !== "Success") return settled(imported);
+ const threadRef = { environmentId: target.environmentId, threadId: imported.value.threadId };
+
+ const finished = await runAtomCommand(
+ registry,
+ commands.finishThreadMove,
+ {
+ environmentId: source.environmentId,
+ input: {
+ threadId: source.threadId,
+ movedTo: input.targetLabel,
+ revision: exported.value.revision,
+ },
+ },
+ quiet,
+ );
+ return {
+ _tag: "Moved",
+ threadRef,
+ archiveError: finished._tag === "Success" ? null : failureMessage(finished, resolve),
+ };
+}
diff --git a/packages/client-runtime/src/t3ToolSummary.ts b/packages/client-runtime/src/t3ToolSummary.ts
index d7e0a24d0284f..b985afee1d8f4 100644
--- a/packages/client-runtime/src/t3ToolSummary.ts
+++ b/packages/client-runtime/src/t3ToolSummary.ts
@@ -1156,6 +1156,40 @@ export function summarizeT3ToolCalls(
);
break;
}
+ case "app-command": {
+ const count = selected.length;
+ label = done
+ ? resolve(
+ msg(
+ "{count, plural, one {Ran app commands {count} time} other {Ran app commands {count} times}}",
+ { count },
+ ),
+ )
+ : resolve(
+ msg(
+ "{count, plural, one {Tried to run app commands {count} time} other {Tried to run app commands {count} times}}",
+ { count },
+ ),
+ );
+ break;
+ }
+ case "app-navigate": {
+ const count = selected.length;
+ label = done
+ ? resolve(
+ msg(
+ "{count, plural, one {Opened pages in the app {count} time} other {Opened pages in the app {count} times}}",
+ { count },
+ ),
+ )
+ : resolve(
+ msg(
+ "{count, plural, one {Tried to open pages in the app {count} time} other {Tried to open pages in the app {count} times}}",
+ { count },
+ ),
+ );
+ break;
+ }
case "environment-links": {
const count = selected.length;
label = done
diff --git a/packages/contracts/src/appControl.ts b/packages/contracts/src/appControl.ts
new file mode 100644
index 0000000000000..4430a5f36e9b8
--- /dev/null
+++ b/packages/contracts/src/appControl.ts
@@ -0,0 +1,125 @@
+import { Schema } from "effect";
+
+import { ThreadId, TrimmedNonEmptyString } from "./baseSchemas.ts";
+import { STATIC_KEYBINDING_COMMANDS } from "./keybindings.ts";
+
+/**
+ * Only the user may trigger these: they send what the user wrote, listen to them, or pick
+ * work that may belong to another environment (undo and reopen history, new threads, hosts).
+ * Agents start threads with `t3_thread_launch` instead.
+ */
+const USER_ONLY_COMMANDS = new Set([
+ "composer.sendAlternate",
+ "composer.sendBackground",
+ "composer.sendAndNewThread",
+ "composer.dictation",
+ "composer.cycleHost",
+ "thread.steerQueuedMessage",
+ "thread.undo",
+ "view.reopenClosed",
+ "chat.new",
+ "chat.newLocal",
+ "chat.newWithoutProject",
+]);
+
+/**
+ * These change only the window's own view, so they run on any screen. The rest act on the
+ * thread or draft on screen, so they run only while it belongs to the agent's environment.
+ */
+export const VIEW_ONLY_APP_COMMANDS: ReadonlySet = new Set([
+ "sidebar.toggle",
+ "navigation.back",
+ "navigation.forward",
+ "workspace.focusNext",
+ "workspace.focusPrevious",
+ "commandPalette.toggle",
+ "theme.select",
+ "appearance.cycle",
+ "themeEditor.toggle",
+ "thread.previous",
+ "thread.next",
+ "usage.open",
+ "usage.cost",
+ "usage.tokens",
+ "usage.limits",
+ "usage.period.day",
+ "usage.period.week",
+ "usage.period.month",
+ "usage.period.quarter",
+]);
+
+/** Shortcut commands an agent may run in the user's window. */
+const APP_COMMANDS = STATIC_KEYBINDING_COMMANDS.filter(
+ (command) => !USER_ONLY_COMMANDS.has(command),
+);
+export const AppCommand = Schema.Literals(APP_COMMANDS);
+export type AppCommand = typeof AppCommand.Type;
+
+const APP_SETTINGS_SECTIONS = [
+ "general",
+ "appearance",
+ "chat",
+ "diffs",
+ "keybindings",
+ "voice",
+ "snap-shot",
+ "providers",
+ "threads",
+ "projects",
+ "browser",
+ "devices",
+ "scheduled-tasks",
+ "source-control",
+ "worktrees",
+ "connections",
+ "access",
+ "secrets",
+ "maintenance",
+ "diagnostics",
+ "labs",
+ "about",
+ "archived",
+] as const;
+export const AppSettingsSection = Schema.Literals(APP_SETTINGS_SECTIONS);
+export type AppSettingsSection = typeof AppSettingsSection.Type;
+
+/** A page of the user's window. A thread is always one from the agent's environment. */
+export const AppDestination = Schema.Union([
+ Schema.Struct({ page: Schema.Literal("thread"), threadId: ThreadId }),
+ Schema.Struct({ page: Schema.Literal("settings"), section: Schema.optional(AppSettingsSection) }),
+ Schema.Struct({ page: Schema.Literals(["usage", "pull-requests"]) }),
+]);
+export type AppDestination = typeof AppDestination.Type;
+
+export const AppAction = Schema.Union([
+ Schema.TaggedStruct("command", { command: AppCommand }),
+ Schema.TaggedStruct("navigate", { to: AppDestination }),
+]);
+export type AppAction = typeof AppAction.Type;
+
+export const AppControlRequest = Schema.Struct({
+ requestId: TrimmedNonEmptyString,
+ action: AppAction,
+});
+export type AppControlRequest = typeof AppControlRequest.Type;
+
+export const AppControlSubscribeInput = Schema.Struct({
+ /** Whether the window is in use as it subscribes, so a background reconnect is not. */
+ focused: Schema.Boolean,
+});
+export type AppControlSubscribeInput = typeof AppControlSubscribeInput.Type;
+
+export const AppControlResult = Schema.Literals([
+ "ran",
+ /** Nothing on screen handles the command right now, or the window has no such page. */
+ "not-handled",
+ /** The window isn't showing a thread or draft from the agent's environment. */
+ "other-environment",
+]);
+export type AppControlResult = typeof AppControlResult.Type;
+
+export const AppControlResponseInput = Schema.Struct({
+ requestId: TrimmedNonEmptyString,
+ result: AppControlResult,
+});
+export type AppControlResponseInput = typeof AppControlResponseInput.Type;
diff --git a/packages/contracts/src/clientRpcPermissions.ts b/packages/contracts/src/clientRpcPermissions.ts
index b211332c1c8b8..0d22a4e750880 100644
--- a/packages/contracts/src/clientRpcPermissions.ts
+++ b/packages/contracts/src/clientRpcPermissions.ts
@@ -54,6 +54,9 @@ export const CLIENT_GUARDED_RPC_SCOPES = {
// Writing a guide runs a model on this environment's providers, which reading one does not.
[WS_METHODS.pullRequestsGenerateReviewGuide]: AuthOrchestrationOperateScope,
[WS_METHODS.projectsCreateFromThread]: AuthOrchestrationOperateScope,
+ [WS_METHODS.projectsMoveThread]: AuthOrchestrationOperateScope,
+ [WS_METHODS.projectsImportThread]: AuthOrchestrationOperateScope,
+ [WS_METHODS.projectsFinishThreadMove]: AuthOrchestrationOperateScope,
[WS_METHODS.sourceControlCloneRepository]: AuthSourceControlWriteScope,
[WS_METHODS.sourceControlPublishRepository]: AuthSourceControlWriteScope,
[WS_METHODS.sourceControlStar]: AuthSourceControlWriteScope,
diff --git a/packages/contracts/src/environment.ts b/packages/contracts/src/environment.ts
index 34c8688316ae2..ef9402702d26b 100644
--- a/packages/contracts/src/environment.ts
+++ b/packages/contracts/src/environment.ts
@@ -139,6 +139,8 @@ export const ExecutionEnvironmentCapabilities = Schema.Struct({
threadActiveReorder: Schema.optionalKey(Schema.Boolean),
threadAutoSettleOptOut: Schema.optionalKey(Schema.Boolean),
threadProjectFromScratch: Schema.optionalKey(Schema.Boolean),
+ threadMoveToProject: Schema.optionalKey(Schema.Boolean),
+ threadMoveToMachine: Schema.optionalKey(Schema.Boolean),
threadTitleRegeneration: Schema.optionalKey(Schema.Boolean),
threadVisitedTracking: Schema.optionalKey(Schema.Boolean),
threadPullRequestLinking: Schema.optionalKey(Schema.Boolean),
diff --git a/packages/contracts/src/index.ts b/packages/contracts/src/index.ts
index d7af43291a061..255f5fe7d805a 100644
--- a/packages/contracts/src/index.ts
+++ b/packages/contracts/src/index.ts
@@ -2,6 +2,7 @@ export * from "./baseSchemas.ts";
export * from "./assistantCitations.ts";
export * from "./composerContext.ts";
export * from "./composerContextClipboard.ts";
+export * from "./appControl.ts";
export * from "./background.ts";
export * from "./acpRegistry.ts";
export * from "./auth.ts";
diff --git a/packages/contracts/src/keybindings.ts b/packages/contracts/src/keybindings.ts
index eda5138b760b9..ea0db35f612c5 100644
--- a/packages/contracts/src/keybindings.ts
+++ b/packages/contracts/src/keybindings.ts
@@ -45,6 +45,10 @@ const THREAD_KEYBINDING_COMMANDS = [
"thread.pin",
"thread.regenerateTitle",
"thread.undo",
+ "thread.restartSession",
+ "thread.showPullRequests",
+ "thread.linkPullRequest",
+ "thread.shareWithGuest",
...THREAD_JUMP_KEYBINDING_COMMANDS,
] as const;
@@ -93,6 +97,7 @@ export const STATIC_KEYBINDING_COMMANDS = [
"composer.sendBackground",
"composer.sendAndNewThread",
"composer.dictation",
+ "composer.toggleVimMode",
"composer.host",
"composer.cycleHost",
"composer.effort",
diff --git a/packages/contracts/src/orchestrationV2.ts b/packages/contracts/src/orchestrationV2.ts
index 8b05c12e17871..ce749b4ae6aa0 100644
--- a/packages/contracts/src/orchestrationV2.ts
+++ b/packages/contracts/src/orchestrationV2.ts
@@ -483,6 +483,8 @@ export const OrchestrationV2AppThread = Schema.Struct({
interactionMode: ProviderInteractionMode,
branch: Schema.NullOr(TrimmedNonEmptyString),
worktreePath: Schema.NullOr(TrimmedNonEmptyString),
+ /** Set when a move changed the thread's folder, so later checkpoints keep their own repository. */
+ checkpointScopeProjectId: Schema.optional(ProjectId),
linkedPullRequest: Schema.optional(Schema.NullOr(ThreadLinkedPullRequest)),
pullRequests: Schema.optional(Schema.Array(ThreadPullRequestLink)),
branchPullRequest: Schema.optional(Schema.NullOr(ThreadLinkedPullRequest)),
@@ -3800,6 +3802,18 @@ const OrchestrationV2InternalCommand = Schema.Union([
text: Schema.String,
attachments: Schema.optional(Schema.Array(ChatAttachment)),
}),
+ /**
+ * Moves an idle thread into another project's root folder. A changed folder ends its provider
+ * sessions, so the next turn resumes or hands off the conversation there.
+ */
+ Schema.Struct({
+ type: Schema.Literal("thread.project.move"),
+ commandId: CommandId,
+ threadId: ThreadId,
+ projectId: ProjectId,
+ /** The target root's current branch, read by the caller. */
+ branch: Schema.NullOr(TrimmedNonEmptyString),
+ }),
/** Moves a thread to a project rooted at the folder it already works in, so its cwd never changes. */
Schema.Struct({
type: Schema.Literal("thread.project.adopt-folder"),
diff --git a/packages/contracts/src/project.ts b/packages/contracts/src/project.ts
index 0077ef78020d8..72c5de50a1b8d 100644
--- a/packages/contracts/src/project.ts
+++ b/packages/contracts/src/project.ts
@@ -3,6 +3,7 @@ import * as SchemaTransformation from "effect/SchemaTransformation";
import * as Struct from "effect/Struct";
import { RepositoryIdentity, ThreadEnvMode } from "./environment.ts";
import { ModelSelection } from "./modelSelection.ts";
+import { ProviderInteractionMode, RuntimeMode } from "./providerPolicy.ts";
import {
CommandId,
ForwardCompatibleUnion,
@@ -591,6 +592,72 @@ export const ProjectCreateFromThreadResult = Schema.Struct({
});
export type ProjectCreateFromThreadResult = typeof ProjectCreateFromThreadResult.Type;
+export const ProjectMoveThreadInput = Schema.Struct({
+ threadId: ThreadId,
+ projectId: ProjectId,
+});
+export type ProjectMoveThreadInput = typeof ProjectMoveThreadInput.Type;
+
+/**
+ * A thread's conversation as another environment can import it. Checkpoints, runs, provider
+ * sessions and attachments belong to the machine that made them, so they stay behind.
+ */
+export const ThreadMoveBundle = Schema.Struct({
+ title: TrimmedNonEmptyString,
+ modelSelection: ModelSelection,
+ runtimeMode: RuntimeMode,
+ interactionMode: ProviderInteractionMode,
+ createdAt: IsoDateTime,
+ messages: Schema.Array(
+ Schema.Struct({
+ role: Schema.Literals(["user", "assistant"]),
+ text: Schema.String,
+ createdAt: IsoDateTime,
+ }),
+ ),
+});
+export type ThreadMoveBundle = typeof ThreadMoveBundle.Type;
+
+export const ProjectExportThreadInput = Schema.Struct({ threadId: ThreadId });
+export type ProjectExportThreadInput = typeof ProjectExportThreadInput.Type;
+
+/** What a move leaves on the source environment, so messages name only what applies. */
+export const ThreadMoveLeftBehind = Schema.Struct({
+ diffs: Schema.Boolean,
+ worktree: Schema.Boolean,
+ attachments: NonNegativeInt,
+ scheduledTasks: NonNegativeInt,
+});
+
+export const ProjectExportThreadResult = Schema.Struct({
+ bundle: ThreadMoveBundle,
+ leftBehind: ThreadMoveLeftBehind,
+ /** The thread's runs at export; finishing the move refuses once a new one has started. */
+ revision: Schema.String,
+});
+export type ProjectExportThreadResult = typeof ProjectExportThreadResult.Type;
+
+export const ProjectImportThreadInput = Schema.Struct({
+ projectId: ProjectId,
+ bundle: ThreadMoveBundle,
+ /** The source machine as the user knows it, for the new thread's notice. */
+ movedFrom: TrimmedNonEmptyString,
+ leftBehind: ThreadMoveLeftBehind,
+});
+export type ProjectImportThreadInput = typeof ProjectImportThreadInput.Type;
+
+export const ProjectImportThreadResult = Schema.Struct({ threadId: ThreadId });
+export type ProjectImportThreadResult = typeof ProjectImportThreadResult.Type;
+
+export const ProjectFinishThreadMoveInput = Schema.Struct({
+ threadId: ThreadId,
+ /** Where the conversation went, as the user knows it, for the archived thread's notice. */
+ movedTo: TrimmedNonEmptyString,
+ /** From the export the target imported, so newer work is never archived unseen. */
+ revision: Schema.String,
+});
+export type ProjectFinishThreadMoveInput = typeof ProjectFinishThreadMoveInput.Type;
+
export class ProjectWriteFileError extends Schema.TaggedError()(
"ProjectWriteFileError",
{
diff --git a/packages/contracts/src/rpc.ts b/packages/contracts/src/rpc.ts
index e30bf9af2937c..b079a6fd31155 100644
--- a/packages/contracts/src/rpc.ts
+++ b/packages/contracts/src/rpc.ts
@@ -92,6 +92,11 @@ import {
AuthAccessStreamEvent,
EnvironmentAuthorizationError,
} from "./auth.ts";
+import {
+ AppControlRequest,
+ AppControlResponseInput,
+ AppControlSubscribeInput,
+} from "./appControl.ts";
import { ClientActivityReportInput } from "./background.ts";
import {
FilesystemGetMetadataInput,
@@ -293,6 +298,12 @@ import {
ProjectCreateNewResult,
ProjectCreateFromThreadInput,
ProjectCreateFromThreadResult,
+ ProjectMoveThreadInput,
+ ProjectExportThreadInput,
+ ProjectExportThreadResult,
+ ProjectImportThreadInput,
+ ProjectImportThreadResult,
+ ProjectFinishThreadMoveInput,
ProjectEnsureScratchResult,
ProjectListEntriesError,
ProjectListEntriesInput,
@@ -477,6 +488,10 @@ export const WS_METHODS = {
projectsEnsureScratch: "projects.ensureScratch",
projectsCreateNew: "projects.createNew",
projectsCreateFromThread: "projects.createFromThread",
+ projectsMoveThread: "projects.moveThread",
+ projectsExportThread: "projects.exportThread",
+ projectsImportThread: "projects.importThread",
+ projectsFinishThreadMove: "projects.finishThreadMove",
shellOpenInEditor: "shell.openInEditor",
@@ -703,6 +718,8 @@ export const WS_METHODS = {
worktreeSetupCancel: "worktreeSetup.cancel",
subscribeTerminalMetadata: "subscribeTerminalMetadata",
subscribePreviewEvents: "subscribePreviewEvents",
+ subscribeAppControl: "subscribeAppControl",
+ appControlRespond: "appControl.respond",
subscribeDiscoveredLocalServers: "subscribeDiscoveredLocalServers",
subscribeDeviceState: "subscribeDeviceState",
subscribeServerConfig: "subscribeServerConfig",
@@ -1653,6 +1670,28 @@ const WsProjectsCreateFromThreadRpc = Rpc.make(WS_METHODS.projectsCreateFromThre
error: Schema.Union([OrchestrationDispatchCommandError, EnvironmentAuthorizationError]),
});
+const WsProjectsMoveThreadRpc = Rpc.make(WS_METHODS.projectsMoveThread, {
+ payload: ProjectMoveThreadInput,
+ error: Schema.Union([OrchestrationDispatchCommandError, EnvironmentAuthorizationError]),
+});
+
+const WsProjectsExportThreadRpc = Rpc.make(WS_METHODS.projectsExportThread, {
+ payload: ProjectExportThreadInput,
+ success: ProjectExportThreadResult,
+ error: Schema.Union([OrchestrationDispatchCommandError, EnvironmentAuthorizationError]),
+});
+
+const WsProjectsImportThreadRpc = Rpc.make(WS_METHODS.projectsImportThread, {
+ payload: ProjectImportThreadInput,
+ success: ProjectImportThreadResult,
+ error: Schema.Union([OrchestrationDispatchCommandError, EnvironmentAuthorizationError]),
+});
+
+const WsProjectsFinishThreadMoveRpc = Rpc.make(WS_METHODS.projectsFinishThreadMove, {
+ payload: ProjectFinishThreadMoveInput,
+ error: Schema.Union([OrchestrationDispatchCommandError, EnvironmentAuthorizationError]),
+});
+
const WsShellOpenInEditorRpc = Rpc.make(WS_METHODS.shellOpenInEditor, {
payload: LaunchEditorInput,
error: Schema.Union([ExternalLauncherError, EnvironmentAuthorizationError]),
@@ -1989,6 +2028,18 @@ const WsSubscribePreviewEventsRpc = Rpc.make(WS_METHODS.subscribePreviewEvents,
stream: true,
});
+const WsSubscribeAppControlRpc = Rpc.make(WS_METHODS.subscribeAppControl, {
+ payload: AppControlSubscribeInput,
+ success: AppControlRequest,
+ error: EnvironmentAuthorizationError,
+ stream: true,
+});
+
+const WsAppControlRespondRpc = Rpc.make(WS_METHODS.appControlRespond, {
+ payload: AppControlResponseInput,
+ error: EnvironmentAuthorizationError,
+});
+
const WsPreviewStopLocalServerRpc = Rpc.make(WS_METHODS.previewStopLocalServer, {
payload: PreviewStopLocalServerInput,
error: Schema.Union([PreviewStopLocalServerError, EnvironmentAuthorizationError]),
@@ -2520,6 +2571,10 @@ export const WsRpcGroup = RpcGroup.make(
WsProjectsEnsureScratchRpc,
WsProjectsCreateNewRpc,
WsProjectsCreateFromThreadRpc,
+ WsProjectsMoveThreadRpc,
+ WsProjectsExportThreadRpc,
+ WsProjectsImportThreadRpc,
+ WsProjectsFinishThreadMoveRpc,
WsProjectsWriteFileRpc,
WsProjectsMutateRpc,
WsShellOpenInEditorRpc,
@@ -2578,6 +2633,8 @@ export const WsRpcGroup = RpcGroup.make(
WsPreviewReportProfilesRpc,
WsPreviewReportStatusRpc,
WsSubscribePreviewEventsRpc,
+ WsSubscribeAppControlRpc,
+ WsAppControlRespondRpc,
WsPreviewStopLocalServerRpc,
WsSubscribeDiscoveredLocalServersRpc,
WsDeviceConfigureRpc,
diff --git a/packages/contracts/src/settings.ts b/packages/contracts/src/settings.ts
index b0726b07174c9..54520af163e85 100644
--- a/packages/contracts/src/settings.ts
+++ b/packages/contracts/src/settings.ts
@@ -526,6 +526,7 @@ export const ClientSettingsSchema = Schema.Struct({
pullRequestLinksOpenInApp: Schema.Boolean.pipe(Schema.withDecodingDefault(Effect.succeed(true))),
composerRichTextEnabled: Schema.Boolean.pipe(Schema.withDecodingDefault(Effect.succeed(true))),
+ composerVimMode: Schema.Boolean.pipe(Schema.withDecodingDefault(Effect.succeed(true))),
sendShortcut: Schema.Literals(["enter", "mod-enter-multiline", "mod-enter"]).pipe(
Schema.withDecodingDefault(Effect.succeed("enter")),
),
@@ -555,6 +556,9 @@ export const ClientSettingsSchema = Schema.Struct({
threadDetailsItems: Schema.Record(Schema.String, Schema.Boolean).pipe(
Schema.withDecodingDefault(Effect.succeed({})),
),
+ threadDetailsOpenByDefault: Schema.Boolean.pipe(
+ Schema.withDecodingDefault(Effect.succeed(false)),
+ ),
sidebarWorkingShelfEnabled: Schema.Boolean.pipe(Schema.withDecodingDefault(Effect.succeed(true))),
sidebarProjectGroupingMode: SidebarProjectGroupingMode.pipe(
Schema.withDecodingDefault(Effect.succeed(DEFAULT_SIDEBAR_PROJECT_GROUPING_MODE)),
@@ -2109,6 +2113,7 @@ export const ClientSettingsPatch = Schema.Struct({
),
pullRequestLinksOpenInApp: Schema.optionalKey(Schema.Boolean),
composerRichTextEnabled: Schema.optionalKey(Schema.Boolean),
+ composerVimMode: Schema.optionalKey(Schema.Boolean),
sendShortcut: Schema.optionalKey(Schema.Literals(["enter", "mod-enter-multiline", "mod-enter"])),
followUpBehavior: Schema.optionalKey(Schema.Literals(["queue", "steer"])),
sideThreadOpenTarget: Schema.optionalKey(SideThreadOpenTarget),
@@ -2121,6 +2126,7 @@ export const ClientSettingsPatch = Schema.Struct({
screenReaderWindowTitle: Schema.optionalKey(Schema.Boolean),
threadDetailsUsageEnabled: Schema.optionalKey(Schema.Boolean),
threadDetailsItems: Schema.optionalKey(Schema.Record(Schema.String, Schema.Boolean)),
+ threadDetailsOpenByDefault: Schema.optionalKey(Schema.Boolean),
sidebarWorkingShelfEnabled: Schema.optionalKey(Schema.Boolean),
sidebarProjectGroupingMode: Schema.optionalKey(SidebarProjectGroupingMode),
sidebarProjectGroupingOverrides: Schema.optionalKey(
diff --git a/packages/shared/package.json b/packages/shared/package.json
index b1ffa038030ef..8a704e709446f 100644
--- a/packages/shared/package.json
+++ b/packages/shared/package.json
@@ -3,6 +3,10 @@
"private": true,
"type": "module",
"exports": {
+ "./threadMove": {
+ "types": "./src/threadMove.ts",
+ "import": "./src/threadMove.ts"
+ },
"./png": {
"types": "./src/png.ts",
"import": "./src/png.ts"
diff --git a/packages/shared/src/keybindings.ts b/packages/shared/src/keybindings.ts
index 9a67264d8bd1f..ca79492e7086b 100644
--- a/packages/shared/src/keybindings.ts
+++ b/packages/shared/src/keybindings.ts
@@ -63,6 +63,8 @@ export const DEFAULT_KEYBINDINGS: ReadonlyArray = [
{ key: "mod+shift+f6", command: "workspace.focusPrevious" },
{ key: "mod+[", command: "navigation.back", when: "!terminalFocus" },
{ key: "mod+]", command: "navigation.forward", when: "!terminalFocus" },
+ // VS Code's chord uses Ctrl on every platform. Listed before mod+j so labels show mod+j.
+ { key: "ctrl+`", command: "terminal.toggle" },
{ key: "mod+j", command: "terminal.toggle" },
{ key: "mod+alt+b", command: "rightPanel.toggle" },
{ key: "mod+shift+b", command: "threadPanel.toggle", when: "!terminalFocus" },
diff --git a/packages/shared/src/t3McpToolPresentation.ts b/packages/shared/src/t3McpToolPresentation.ts
index fc2af2e05cc37..6c60c9b169ceb 100644
--- a/packages/shared/src/t3McpToolPresentation.ts
+++ b/packages/shared/src/t3McpToolPresentation.ts
@@ -55,6 +55,8 @@ export type T3McpToolSummaryAction =
| "environment-link"
| "environment-unlink"
| "environment-update"
+ | "app-command"
+ | "app-navigate"
| "theme-read"
| "theme-set"
| "attachment-prepare"
@@ -415,10 +417,28 @@ const T3_MCP_TOOLS: Readonly> = {
["Forget", "Forgetting", "Forgot", "a linked environment"],
"environment-unlink",
),
- t3_environment_preferences_update: tool(
- ["Update", "Updating", "Updated", "environment preferences"],
+ t3_environment_settings_read: tool(
+ ["Read", "Reading", "Read", "environment settings"],
+ "environment-read",
+ ),
+ t3_environment_settings_update: tool(
+ ["Update", "Updating", "Updated", "environment settings"],
+ "environment-update",
+ ),
+ t3_keybindings_read: tool(
+ ["List", "Listing", "Listed", "keyboard shortcuts"],
+ "environment-read",
+ ),
+ t3_keybinding_upsert: tool(
+ ["Set", "Setting", "Set", "a keyboard shortcut"],
+ "environment-update",
+ ),
+ t3_keybinding_remove: tool(
+ ["Remove", "Removing", "Removed", "a keyboard shortcut"],
"environment-update",
),
+ t3_app_command: tool(["Run", "Running", "Ran", "an app command"], "app-command"),
+ t3_app_navigate: tool(["Open", "Opening", "Opened", "a page in the app"], "app-navigate"),
t3_theme_read: tool(["Read", "Reading", "Read", "themes"], "theme-read"),
t3_theme_set: tool(["Set", "Setting", "Set", "the theme"], "theme-set"),
t3_thread_launch: tool(["Launch", "Launching", "Launched", "a project thread"], "thread-create"),
diff --git a/packages/shared/src/threadMove.ts b/packages/shared/src/threadMove.ts
new file mode 100644
index 0000000000000..3da835d59091e
--- /dev/null
+++ b/packages/shared/src/threadMove.ts
@@ -0,0 +1,39 @@
+/** What moving a thread to another project changes, worded the same for people and agents. */
+export function threadMoveNotice(input: {
+ readonly projectTitle: string;
+ readonly fromWorktree: boolean;
+}): string {
+ return input.fromWorktree
+ ? `The agent will work in ${input.projectTitle}'s root folder. The worktree and its branch stay on disk, but the agent won't see changes left there. Earlier diffs open while the worktree exists, and files from earlier turns can't be restored.`
+ : `The conversation moves with it, and the agent works in ${input.projectTitle}'s folder from the next message. Earlier diffs open while their original folder exists, and files from earlier turns can't be restored.`;
+}
+
+interface ThreadMoveLeftBehind {
+ readonly diffs: boolean;
+ readonly worktree: boolean;
+ readonly attachments: number;
+ readonly scheduledTasks: number;
+}
+
+/** "Files, diffs and 2 attachments": what a machine move leaves on the source, naming only what applies. */
+export function threadMoveLeftBehindList(leftBehind: ThreadMoveLeftBehind): string {
+ const count = (n: number, noun: string) => `${n} ${noun}${n === 1 ? "" : "s"}`;
+ const stays = [
+ "Files",
+ ...(leftBehind.diffs ? ["diffs"] : []),
+ ...(leftBehind.worktree ? ["the worktree"] : []),
+ ...(leftBehind.attachments > 0 ? [count(leftBehind.attachments, "attachment")] : []),
+ ...(leftBehind.scheduledTasks > 0 ? [count(leftBehind.scheduledTasks, "scheduled task")] : []),
+ ];
+ return stays.length === 1 ? "Files" : `${stays.slice(0, -1).join(", ")} and ${stays.at(-1)}`;
+}
+
+/** What moving a thread to another machine carries and leaves behind. */
+export function threadMachineMoveNotice(input: {
+ readonly fromMachine: string;
+ readonly toMachine: string;
+ readonly projectTitle: string;
+ readonly leftBehind: ThreadMoveLeftBehind;
+}): string {
+ return `The conversation moves to ${input.projectTitle} on ${input.toMachine} and continues in a new session there. ${threadMoveLeftBehindList(input.leftBehind)} stay on ${input.fromMachine}, where this thread is archived. Unarchive it to come back.`;
+}
diff --git a/scripts/sanucode b/scripts/sanucode
new file mode 100755
index 0000000000000..9077d6bd8944c
--- /dev/null
+++ b/scripts/sanucode
@@ -0,0 +1,79 @@
+#!/bin/sh
+# Sanu Code: runs this fork from source beside an installed T3 Code, with its own data in ~/.sanucode.
+# sanucode serve the web app (extra flags pass through, e.g. --share --built)
+# sanucode app open the desktop app (shares data with the web app; run one at a time)
+# sanucode import replace Sanu Code's threads and preferences with a fresh copy of T3 Code's
+# sanucode install link `sanucode` and `sn` in ~/.local/bin to this checkout
+set -eu
+
+repo=$(cd "$(dirname "$(realpath "$0")")/.." && pwd)
+home="$HOME/.sanucode"
+
+case "${1:-}" in
+ help | -h | --help)
+ sed -n '2,6s/^# //p' "$repo/scripts/sanucode"
+ exit 0
+ ;;
+ install)
+ bin="$HOME/.local/bin"
+ mkdir -p "$bin"
+ ln -sfn "$repo/scripts/sanucode" "$bin/sanucode"
+ ln -sfn sanucode "$bin/sn"
+ echo "Linked sanucode and sn in $bin to $repo."
+ case ":$PATH:" in
+ *":$bin:"*) ;;
+ *) echo "Add $bin to your PATH to use them." ;;
+ esac
+ exit 0
+ ;;
+esac
+
+if ! command -v vp >/dev/null 2>&1; then
+ echo "sanucode: vp is not installed. See \"Install vp\" in $repo/README.md." >&2
+ exit 1
+fi
+
+# An explicit version keeps the pinned Node even when vp defers to a system Node such as nvm's.
+node_version=$(sed -n 's/^ *"node": "\([0-9.]*\)".*/\1/p' "$repo/package.json" | head -n 1)
+cd "$repo"
+
+case "${1:-}" in
+ app)
+ shift
+ set -- dev:desktop --home-dir "$home" "$@"
+ ;;
+ import)
+ t3_data="$HOME/.t3/userdata"
+ data="$home/userdata"
+ backup="$home/backup"
+ prefs="settings.json keybindings.json keybindings-migrations client-settings.json"
+
+ # SQLite removes the -wal file on a clean shutdown, so its presence means Sanu Code is open.
+ if [ -e "$data/statev2.sqlite-wal" ]; then
+ echo "sanucode: Sanu Code is running. Quit it, then import again." >&2
+ exit 1
+ fi
+
+ mkdir -p "$data" "$backup"
+ for file in statev2.sqlite $prefs; do
+ if [ -f "$data/$file" ]; then cp "$data/$file" "$backup/"; fi
+ done
+
+ vp env exec --node "$node_version" vp run migrate-dev-db \
+ --base-dir "$home" --projects 1000 --threads-per-project 1000
+
+ for file in $prefs; do
+ if [ -f "$t3_data/$file" ]; then cp "$t3_data/$file" "$data/"; fi
+ done
+
+ echo
+ echo "Imported T3 Code. Threads still running there were skipped."
+ echo "Previous Sanu Code data is in $backup."
+ exit 0
+ ;;
+ *)
+ set -- dev --home-dir "$home" --host 0.0.0.0 --no-auto-bootstrap-project-from-cwd "$@"
+ ;;
+esac
+
+exec vp env exec --node "$node_version" vp run "$@"