Skip to content

Commit c2cf64d

Browse files
Merge remote-tracking branch 'origin/main' into fix/issue-26889
2 parents f8f42c0 + d7935f1 commit c2cf64d

65 files changed

Lines changed: 1691 additions & 324 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎apps/desktop/src/settings/DesktopClientSettings.test.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ const clientSettings: ClientSettings = {
6565
boringSidebarEnabled: false,
6666
boringSidebarMultilineRows: false,
6767
threadDetailsUsageEnabled: false,
68+
threadDetailsItems: {},
6869
legacySidebarEnabled: false,
6970
sidebarWorkingShelfEnabled: false,
7071
loadBalancingEnabled: false,

‎apps/mobile/src/features/threads/thread-list-v2-items.tsx‎

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ import { useThreadPr } from "../../state/use-thread-pr";
6262
import { useSwipeRowDormant } from "../home/swipe-row-activation";
6363
import { ThreadSwipeable } from "../home/thread-swipe-actions";
6464
import { buildThreadTitleRegenerationMenuItems } from "./thread-title-regeneration-menu";
65+
import { canTurnThreadIntoProject, turnThreadIntoProject } from "./turnThreadIntoProject";
66+
import { threadCanArchive } from "../home/threadArchive";
6567
import {
6668
THREAD_LIST_V2_SETTLED_PAGE_COUNT,
6769
resolveThreadListV2SnoozeGateExpiryMs,
@@ -837,15 +839,31 @@ export const ThreadListV2Row = memo(function ThreadListV2Row(props: {
837839
: [],
838840
[props.autoSettleOptOutSupported, thread.autoSettleDisabledAt],
839841
);
842+
const canTurnIntoProject = canTurnThreadIntoProject(thread);
840843
const titleMenuItems = useMemo<MenuAction[]>(
841844
() => [
842845
{ id: "rename", title: "Rename", image: "square.and.pencil" },
843846
...buildThreadTitleRegenerationMenuItems({
844847
supported: props.titleRegenerationSupported,
845848
isRegenerating: thread.titleRegeneration != null,
846849
}),
850+
...(canTurnIntoProject
851+
? [
852+
{
853+
id: "turn-into-project",
854+
title: "Turn into project",
855+
image: "folder.badge.plus",
856+
attributes: { disabled: !threadCanArchive(thread.runtime) },
857+
} satisfies MenuAction,
858+
]
859+
: []),
860+
],
861+
[
862+
canTurnIntoProject,
863+
props.titleRegenerationSupported,
864+
thread.runtime,
865+
thread.titleRegeneration,
847866
],
848-
[props.titleRegenerationSupported, thread.titleRegeneration],
849867
);
850868
const snoozableCardMenuActions = useMemo<MenuAction[]>(
851869
() => [
@@ -923,6 +941,7 @@ export const ThreadListV2Row = memo(function ThreadListV2Row(props: {
923941
if (nativeEvent.event === "archive") handleArchive();
924942
if (nativeEvent.event === "rename") handleRename();
925943
if (nativeEvent.event === "regenerate-title") handleRegenerateTitle();
944+
if (nativeEvent.event === "turn-into-project") void turnThreadIntoProject(thread);
926945
if (nativeEvent.event === "copy-thread") {
927946
const target = threadChipCopyTarget(
928947
{ environmentId: thread.environmentId, threadId: thread.id },
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import {
2+
isAtomCommandInterrupted,
3+
runAtomCommand,
4+
squashAtomCommandFailure,
5+
} from "@t3tools/client-runtime/state/runtime";
6+
import type { EnvironmentThreadShell } from "@t3tools/client-runtime/state/shell";
7+
import { AuthOrchestrationOperateScope } from "@t3tools/contracts";
8+
import * as Haptics from "expo-haptics";
9+
10+
import * as Dialog from "../../components/ui/Dialog";
11+
import { appAtomRegistry } from "../../state/atom-registry";
12+
import { environmentProjects, projectEnvironment } from "../../state/projects";
13+
import { environmentServerConfigsAtom } from "../../state/server";
14+
import { readEnvironmentScope } from "../../state/session";
15+
16+
/** A No project thread that already has its own folder, on a server that can promote it. */
17+
export function canTurnThreadIntoProject(thread: EnvironmentThreadShell): boolean {
18+
if (thread.worktreePath === null) return false;
19+
const config = appAtomRegistry.get(environmentServerConfigsAtom).get(thread.environmentId);
20+
if (config?.environment.capabilities.threadProjectFromScratch !== true) return false;
21+
const project = appAtomRegistry.get(
22+
environmentProjects.projectAtom({
23+
environmentId: thread.environmentId,
24+
projectId: thread.projectId,
25+
}),
26+
);
27+
return project?.isScratch === true;
28+
}
29+
30+
export async function turnThreadIntoProject(thread: EnvironmentThreadShell): Promise<void> {
31+
const title = "Could not turn thread into a project";
32+
if (!readEnvironmentScope(thread.environmentId, AuthOrchestrationOperateScope)) {
33+
Dialog.alert(title, "This connection cannot change threads.");
34+
return;
35+
}
36+
void Haptics.impactAsync(Haptics.ImpactFeedbackStyle.Light);
37+
const result = await runAtomCommand(
38+
appAtomRegistry,
39+
projectEnvironment.createFromThread,
40+
{ environmentId: thread.environmentId, input: { threadId: thread.id } },
41+
{ reportFailure: false },
42+
);
43+
if (result._tag === "Failure" && !isAtomCommandInterrupted(result)) {
44+
const error = squashAtomCommandFailure(result);
45+
Dialog.alert(title, error instanceof Error ? error.message : "Try again.");
46+
}
47+
}

‎apps/server/src/environment/ServerEnvironment.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,7 @@ export const make = Effect.gen(function* () {
246246
threadPinReorder: true,
247247
threadActiveReorder: true,
248248
threadAutoSettleOptOut: true,
249+
threadProjectFromScratch: true,
249250
threadTitleRegeneration: true,
250251
commandOutputStreaming: true,
251252
threadVisitedTracking: true,

‎apps/server/src/mcp/OrchestratorMcpToolkit.integration.test.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ const layerUnusedScheduledTaskStub = Layer.succeed(
182182
setEnabled: () => Effect.die("ScheduledTaskService.setEnabled is unused in this test"),
183183
delete: () => Effect.die("ScheduledTaskService.delete is unused in this test"),
184184
deleteForThread: () => Effect.die("unused in this test"),
185+
moveThreadTasks: () => Effect.die("unused in this test"),
185186
runNow: () => Effect.die("ScheduledTaskService.runNow is unused in this test"),
186187
rotateWebhookToken: () => Effect.die("unused in this test"),
187188
listWebhookDeliveries: () => Effect.die("unused in this test"),

‎apps/server/src/observability/RpcInstrumentation.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ const RPC_AGGREGATES = {
150150
[WS_METHODS.projectsWriteFile]: "workspace",
151151
[WS_METHODS.projectsEnsureScratch]: "orchestration",
152152
[WS_METHODS.projectsCreateNew]: "orchestration",
153+
[WS_METHODS.projectsCreateFromThread]: "orchestration",
153154
[WS_METHODS.shellOpenInEditor]: "workspace",
154155
[WS_METHODS.filesystemBrowse]: "workspace",
155156
[WS_METHODS.filesystemGetMetadata]: "workspace",

‎apps/server/src/orchestration-v2/Adapters/AntigravityAdapterV2.test.ts‎

Lines changed: 25 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ const layerSession = Layer.mergeAll(
127127
);
128128

129129
describe("AntigravityAdapterV2 client file system", () => {
130-
it.effect("confines agent file requests to the workspace under full access", () =>
130+
it.effect("serves confined reads and leaves edits to the agent's diff tools", () =>
131131
Effect.gen(function* () {
132132
const childProcessSpawner = yield* ChildProcessSpawner.ChildProcessSpawner;
133133
const fileSystem = yield* FileSystem.FileSystem;
@@ -140,6 +140,8 @@ describe("AntigravityAdapterV2 client file system", () => {
140140
// effect-acp keeps the last handler registered per method; so does this.
141141
let readTextFile: Parameters<RuntimeService["handleReadTextFile"]>[0] | undefined;
142142
let writeTextFile: Parameters<RuntimeService["handleWriteTextFile"]>[0] | undefined;
143+
const logs = yield* fileSystem.makeTempDirectoryScoped({ prefix: "t3-antigravity-log-" });
144+
const requestLog = path.join(logs, "requests.ndjson");
143145
const crypto = yield* Crypto.Crypto;
144146
const instanceId = ProviderInstanceId.make("antigravity-containment-test");
145147
const adapter = yield* makeAntigravityAdapterV2({
@@ -153,7 +155,7 @@ describe("AntigravityAdapterV2 client file system", () => {
153155
command: process.execPath,
154156
args: [mockAgentPath],
155157
cwd: input.cwd,
156-
env: { T3_ACP_ANTIGRAVITY: "1" },
158+
env: { T3_ACP_ANTIGRAVITY: "1", T3_ACP_REQUEST_LOG_PATH: requestLog },
157159
},
158160
}).pipe(
159161
Effect.provideService(Crypto.Crypto, crypto),
@@ -198,17 +200,31 @@ describe("AntigravityAdapterV2 client file system", () => {
198200
runtimePolicy,
199201
});
200202
yield* session.ensureThread({ threadId, modelSelection, runtimePolicy });
201-
if (readTextFile === undefined || writeTextFile === undefined) {
202-
return yield* Effect.die("Antigravity sessions must serve client file requests");
203+
const initialize = (yield* fileSystem.readFileString(requestLog))
204+
.trim()
205+
.split("\n")
206+
.map(
207+
(line) =>
208+
JSON.parse(line) as {
209+
method?: string;
210+
params?: { clientCapabilities?: { fs?: unknown }; clientInfo?: { name?: string } };
211+
},
212+
)
213+
.find((request) => request.method === "initialize");
214+
assert.deepEqual(initialize?.params?.clientCapabilities?.fs, {
215+
readTextFile: true,
216+
writeTextFile: false,
217+
});
218+
assert.equal(initialize?.params?.clientInfo?.name, "zed");
219+
assert.isUndefined(writeTextFile);
220+
if (readTextFile === undefined) {
221+
return yield* Effect.die("Antigravity sessions must serve client file reads");
203222
}
204223
const context = (method: string) => ({ requestId: `test-${method}`, method });
205224

206225
const insidePath = path.join(workspace, "src", "inside.ts");
207-
yield* writeTextFile(
208-
{ sessionId: "mock-session-1", path: insidePath, content: "inside" },
209-
context("fs/write_text_file"),
210-
);
211-
assert.equal(yield* fileSystem.readFileString(insidePath), "inside");
226+
yield* fileSystem.makeDirectory(path.dirname(insidePath), { recursive: true });
227+
yield* fileSystem.writeFileString(insidePath, "inside");
212228
const pasted = yield* readTextFile(
213229
{ sessionId: "mock-session-1", path: attachment },
214230
context("fs/read_text_file"),
@@ -220,59 +236,13 @@ describe("AntigravityAdapterV2 client file system", () => {
220236
context("fs/read_text_file"),
221237
).pipe(Effect.exit);
222238
assert.isTrue(Exit.isFailure(outsideRead));
223-
const outsideWrite = yield* writeTextFile(
224-
{ sessionId: "mock-session-1", path: path.join(outside, "planted.txt"), content: "x" },
225-
context("fs/write_text_file"),
226-
).pipe(Effect.exit);
227-
assert.isTrue(Exit.isFailure(outsideWrite));
228-
assert.isFalse(yield* fileSystem.exists(path.join(outside, "planted.txt")));
229-
230239
const linkPath = path.join(workspace, "linked-secret.txt");
231240
yield* fileSystem.symlink(outsideFile, linkPath);
232241
const linkedRead = yield* readTextFile(
233242
{ sessionId: "mock-session-1", path: linkPath },
234243
context("fs/read_text_file"),
235244
).pipe(Effect.exit);
236245
assert.isTrue(Exit.isFailure(linkedRead), "a read through an escaping symlink is denied");
237-
const linkedWrite = yield* writeTextFile(
238-
{ sessionId: "mock-session-1", path: linkPath, content: "overwritten" },
239-
context("fs/write_text_file"),
240-
).pipe(Effect.exit);
241-
assert.isTrue(Exit.isFailure(linkedWrite), "a write through an escaping symlink is denied");
242-
assert.equal(yield* fileSystem.readFileString(outsideFile), "secret");
243-
const plantedTarget = path.join(outside, "created-through-link.txt");
244-
const danglingLink = path.join(workspace, "dangling.txt");
245-
yield* fileSystem.symlink(plantedTarget, danglingLink);
246-
const danglingWrite = yield* writeTextFile(
247-
{ sessionId: "mock-session-1", path: danglingLink, content: "planted" },
248-
context("fs/write_text_file"),
249-
).pipe(Effect.exit);
250-
assert.isTrue(Exit.isFailure(danglingWrite), "a write through a dangling symlink is denied");
251-
assert.isFalse(yield* fileSystem.exists(plantedTarget));
252-
yield* fileSystem.symlink(outside, path.join(workspace, "linked-dir"));
253-
const linkedDirWrite = yield* writeTextFile(
254-
{
255-
sessionId: "mock-session-1",
256-
path: path.join(workspace, "linked-dir", "new.txt"),
257-
content: "planted",
258-
},
259-
context("fs/write_text_file"),
260-
).pipe(Effect.exit);
261-
assert.isTrue(Exit.isFailure(linkedDirWrite), "a write under an escaping directory link");
262-
assert.isFalse(yield* fileSystem.exists(path.join(outside, "new.txt")));
263-
const nestedLinkedDirWrite = yield* writeTextFile(
264-
{
265-
sessionId: "mock-session-1",
266-
path: path.join(workspace, "linked-dir", "a", "b", "file.txt"),
267-
content: "planted",
268-
},
269-
context("fs/write_text_file"),
270-
).pipe(Effect.exit);
271-
assert.isTrue(
272-
Exit.isFailure(nestedLinkedDirWrite),
273-
"a write to missing directories under an escaping directory link",
274-
);
275-
assert.isFalse(yield* fileSystem.exists(path.join(outside, "a")));
276246
const insideLink = path.join(workspace, "inside-link.ts");
277247
yield* fileSystem.symlink(insidePath, insideLink);
278248
const viaInsideLink = yield* readTextFile(

‎apps/server/src/orchestration-v2/Adapters/AntigravityAdapterV2.ts‎

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,7 @@ import {
2323
buildAntigravityPrompt,
2424
type AntigravityAcpRuntimeInput,
2525
} from "../../provider/acp/AntigravityAcpSupport.ts";
26-
import {
27-
readAntigravityClientTextFile,
28-
writeAntigravityClientTextFile,
29-
} from "../../provider/acp/AntigravityClientFiles.ts";
26+
import { readAntigravityClientTextFile } from "../../provider/acp/AntigravityClientFiles.ts";
3027
import {
3128
antigravityApprovalOptions,
3229
antigravitySubagentOutput,
@@ -82,7 +79,7 @@ export interface AntigravityAdapterV2Options {
8279
readonly continuationRequests?: Parameters<typeof makeAcpAdapterV2>[0]["continuationRequests"];
8380
}
8481

85-
/** ACP 1.1.1 reports `start_subagent` tools without child session ids. */
82+
/** Native subagent tools report no child session ids. */
8683
const extractAntigravitySubagentUpdate: NonNullable<AcpAdapterV2Flavor["extractSubagentUpdate"]> = (
8784
toolCall,
8885
) => {
@@ -126,7 +123,7 @@ export function makeAntigravityAcpAdapterFlavor(
126123
Scope.close(scope, Exit.void),
127124
options.makeRuntime({
128125
...input,
129-
clientFileSystem: true,
126+
clientFileReads: true,
130127
additionalDirectories: [options.host.paths.attachmentsDir],
131128
}),
132129
)
@@ -191,13 +188,6 @@ export function makeAntigravityAcpAdapterFlavor(
191188
allowedRoots: antigravityClientFileRoots(cwd),
192189
request,
193190
}),
194-
writeTextFile: (request, cwd) =>
195-
writeAntigravityClientTextFile({
196-
fileSystem: options.fileSystem,
197-
path: options.path,
198-
allowedRoots: antigravityClientFileRoots(cwd),
199-
request,
200-
}),
201191
},
202192
approvalOptions: antigravityApprovalOptions,
203193
extractPermissionQuestion: (request) => {

‎apps/server/src/orchestration-v2/Orchestrator.ts‎

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,23 @@ function wakeWorkStartedAt(
455455

456456
const threadPullRequestLinksEqual = Schema.toEquivalence(Schema.NullOr(ThreadLinkedPullRequest));
457457

458+
/** Unfinished runs (including queued) or open requests block moving a thread to another project. */
459+
export function threadHasUnfinishedWork(records: {
460+
readonly runs: ReadonlyArray<{ readonly status: string }>;
461+
readonly runtimeRequests: ReadonlyArray<{ readonly status: string }>;
462+
}): boolean {
463+
return (
464+
records.runs.some(
465+
(run) =>
466+
run.status !== "completed" &&
467+
run.status !== "failed" &&
468+
run.status !== "cancelled" &&
469+
run.status !== "interrupted" &&
470+
run.status !== "rolled_back",
471+
) || records.runtimeRequests.some((request) => request.status === "pending")
472+
);
473+
}
474+
458475
function commandThreadId(command: OrchestrationV2ServerCommand): ThreadId {
459476
switch (command.type) {
460477
case "thread.create":
@@ -486,6 +503,7 @@ function commandThreadId(command: OrchestrationV2ServerCommand): ThreadId {
486503
case "thread.pull-request-watch.sync":
487504
case "thread.pull-request.sync":
488505
case "thread.title.regeneration.complete":
506+
case "thread.project.adopt-folder":
489507
case "thread.runtime-mode.set":
490508
case "thread.interaction-mode.set":
491509
case "thread.model-selection.set":
@@ -3983,6 +4001,56 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
39834001
},
39844002
);
39854003

4004+
const dispatchThreadProjectAdoptFolder = Effect.fn(
4005+
"orchestrationV2.dispatch.threadProjectAdoptFolder",
4006+
)(function* (
4007+
command: Extract<
4008+
OrchestrationV2ServerCommand,
4009+
{ readonly type: "thread.project.adopt-folder" }
4010+
>,
4011+
events: Ref.Ref<Array<OrchestrationV2DomainEvent>>,
4012+
) {
4013+
const reject = (cause: string) =>
4014+
new OrchestratorDispatchError({
4015+
commandId: command.commandId,
4016+
commandType: command.type,
4017+
cause: `Thread ${command.threadId} ${cause}`,
4018+
});
4019+
const projection = yield* projectionStore
4020+
.getThreadRecords(command.threadId, ["runs", "runtimeRequests"], { turnItemTypes: [] })
4021+
.pipe(
4022+
Effect.mapError(
4023+
(cause) => new OrchestratorProjectionError({ threadId: command.threadId, cause }),
4024+
),
4025+
);
4026+
const thread = projection.thread;
4027+
if (thread.deletedAt !== null) return yield* reject("is deleted.");
4028+
if (threadHasUnfinishedWork(projection)) {
4029+
return yield* reject("still has work in progress. Finish or stop it first.");
4030+
}
4031+
const current = yield* projects.get(thread.projectId).pipe(mapDispatchError(command));
4032+
const target = yield* projects.get(command.projectId).pipe(mapDispatchError(command));
4033+
if (Option.isNone(target) || target.value.deletedAt !== null) {
4034+
return yield* reject(`cannot move to missing project ${command.projectId}.`);
4035+
}
4036+
// The thread always lands in the project root, so the move must not change its cwd.
4037+
const cwd = thread.worktreePath ?? Option.getOrUndefined(current)?.workspaceRoot;
4038+
if (cwd !== target.value.workspaceRoot) {
4039+
return yield* reject(`does not work in ${target.value.workspaceRoot}.`);
4040+
}
4041+
const now = yield* DateTime.now;
4042+
yield* emit(
4043+
events,
4044+
command,
4045+
)({
4046+
type: "thread.metadata-updated",
4047+
threadId: command.threadId,
4048+
providerInstanceId: thread.providerInstanceId,
4049+
occurredAt: now,
4050+
payload: { ...thread, projectId: command.projectId, worktreePath: null, updatedAt: now },
4051+
});
4052+
});
4053+
39864054
const refuseAboveDispatchModeLimit = Effect.fn("orchestrationV2.dispatch.refuseAboveModeLimit")(
39874055
function* (
39884056
command: OrchestrationV2ServerCommand,
@@ -12487,6 +12555,9 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
1248712555
case "provider-session.detach":
1248812556
yield* dispatchProviderSessionDetach(command, events, effects);
1248912557
break;
12558+
case "thread.project.adopt-folder":
12559+
yield* dispatchThreadProjectAdoptFolder(command, events);
12560+
break;
1249012561
case "message.dispatch": {
1249112562
// Providers own native subagent conversations; messages cannot target them, and adapters ask questions on the parent.
1249212563
const thread = yield* projectionStore

0 commit comments

Comments
 (0)