Skip to content

Commit a3cf143

Browse files
Silthusclaude
andcommitted
fix: remote task approvals name their environment, pasted files follow one rule
- An approval mirrored from a delegated task says which environment it runs in, on web and mobile, since it sits in the parent's shared footer. - Which pasted records an answer to a question takes is one tested rule: no machines, and files only when the question takes them. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 8ee4f02 commit a3cf143

8 files changed

Lines changed: 92 additions & 7 deletions

File tree

‎apps/mobile/src/features/threads/PendingApprovalCard.tsx‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@ export function PendingApprovalCard(props: PendingApprovalCardProps) {
4545
<Text className="font-t3-bold text-lg text-foreground">
4646
{props.approval.appName ?? props.approval.requestKind}
4747
</Text>
48+
{props.approval.remoteEnvironmentLabel ? (
49+
<Text className="font-sans text-xs leading-normal text-foreground-muted">
50+
Delegated task on {props.approval.remoteEnvironmentLabel}
51+
</Text>
52+
) : null}
4853
{props.approval.detail ? (
4954
<Text className="font-sans text-sm leading-normal text-foreground-secondary">
5055
{props.approval.detail}

‎apps/web/src/components/chat/TimelinePendingApprovalRow.tsx‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,11 @@ export const TimelinePendingApprovalRow = memo(function TimelinePendingApprovalR
6565
}
6666
>
6767
<div className="ms-7.5 flex min-w-0 flex-col gap-1 pb-1 text-xs">
68+
{approval.remoteEnvironmentLabel ? (
69+
<span className="text-muted-foreground wrap-anywhere">
70+
Delegated task on {approval.remoteEnvironmentLabel}
71+
</span>
72+
) : null}
6873
{approval.appName ? (
6974
<span className="text-muted-foreground wrap-anywhere">{approval.appName}</span>
7075
) : null}

‎apps/web/src/components/chat/useComposerContextImport.ts‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import {
3535
terminalContextDraftFromRecord,
3636
terminalContextRecord,
3737
terminalContextReference,
38+
pastedContextRecordFits,
3839
} from "~/lib/composerContextRecords";
3940
import { assetEnvironment } from "~/state/assets";
4041
import { copiedComposerAttachmentFile } from "~/lib/copiedComposerAttachments";
@@ -277,6 +278,10 @@ export function useComposerContextImport(input: {
277278
const rewritten = new Map<string, string>();
278279
const dependentAttachmentLocalIds = new Map<string, string>();
279280
const skippedDependentAttachmentIds = new Set<string>();
281+
const target = {
282+
answersQuestion: questionAttachmentTarget !== null,
283+
takesAttachments: supportsQuestionAttachments,
284+
};
280285
// Resolve annotations before their dependent screenshot records even if a foreign
281286
// clipboard producer emitted the records in a different order.
282287
const orderedRecords = records.toSorted((left, right) =>
@@ -338,6 +343,7 @@ export function useComposerContextImport(input: {
338343
continue;
339344
}
340345
const conflicts = existing !== undefined;
346+
if (!pastedContextRecordFits(record.kind, target)) continue;
341347
switch (record.kind) {
342348
case "terminal": {
343349
const threadId = activeThread?.id ?? activeThreadId;
@@ -390,9 +396,7 @@ export function useComposerContextImport(input: {
390396
break;
391397
}
392398
case "environment": {
393-
// A machine means the same machine from any thread, so a pasted one is kept,
394-
// but not in an answer to an agent's question, which carries no machines.
395-
if (questionAttachmentTarget !== null) break;
399+
// A machine means the same machine from any thread, so a pasted one is kept.
396400
addComposerDraftEnvironmentContexts(composerDraftTarget, [record], {
397401
appendReference: false,
398402
});
@@ -402,7 +406,6 @@ export function useComposerContextImport(input: {
402406
case "image":
403407
case "file": {
404408
if (skippedDependentAttachmentIds.has(record.contextId)) break;
405-
if (questionAttachmentTarget !== null && !supportsQuestionAttachments) break;
406409
if (sourceEnvironmentId === null && !conflicts) {
407410
rewritten.set(record.contextId, record.contextId);
408411
break;

‎apps/web/src/lib/composerContextRecords.test.ts‎

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import {
2020
buildMessageContext,
2121
composerContextImportLookupIds,
2222
isSameComposerContextPayload,
23+
pastedContextRecordFits,
2324
previewAnnotationContextRecord,
2425
previewAnnotationFromRecord,
2526
pullRequestContextKindLabel,
@@ -67,6 +68,38 @@ const annotation: PreviewAnnotationPayload = {
6768
};
6869

6970
describe("composerContextRecords", () => {
71+
it.each([
72+
["image", "a message", { answersQuestion: false, takesAttachments: false }, true],
73+
["environment", "a message", { answersQuestion: false, takesAttachments: false }, true],
74+
[
75+
"file",
76+
"a question that takes files",
77+
{ answersQuestion: true, takesAttachments: true },
78+
true,
79+
],
80+
[
81+
"image",
82+
"a question that takes none",
83+
{ answersQuestion: true, takesAttachments: false },
84+
false,
85+
],
86+
[
87+
"file",
88+
"a question that takes none",
89+
{ answersQuestion: true, takesAttachments: false },
90+
false,
91+
],
92+
[
93+
"thread",
94+
"a question that takes none",
95+
{ answersQuestion: true, takesAttachments: false },
96+
true,
97+
],
98+
["environment", "any question", { answersQuestion: true, takesAttachments: true }, false],
99+
] as const)("a pasted %s record fits %s: %s", (kind, _, target, fits) => {
100+
expect(pastedContextRecordFits(kind, target)).toBe(fits);
101+
});
102+
70103
it("copies only ready or persisted server-side attachment IDs", () => {
71104
const environmentId = EnvironmentId.make("env");
72105
const image = {

‎apps/web/src/lib/composerContextRecords.ts‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,16 @@ export function asKnownContextRecord(
347347
return record;
348348
}
349349

350+
/** An answer to an agent's question carries no machines, and files only when the question takes them. */
351+
export function pastedContextRecordFits(
352+
kind: KnownComposerContextRecord["kind"],
353+
target: { readonly answersQuestion: boolean; readonly takesAttachments: boolean },
354+
): boolean {
355+
if (!target.answersQuestion) return true;
356+
if (kind === "environment") return false;
357+
return target.takesAttachments || (kind !== "image" && kind !== "file");
358+
}
359+
350360
export function composerContextImportLookupIds(
351361
record: KnownComposerContextRecord,
352362
): ReadonlyArray<ComposerContextId> {

‎packages/client-runtime/src/state/threadDetail.ts‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ export function createEnvironmentThreadDetailAtoms<E>(
370370
);
371371
const pendingRequestsAtomFamily = Atom.family((key: string) => {
372372
let previous:
373-
| (Pick<OrchestrationV2ThreadProjection, "runtimeRequests" | "turnItems"> & {
373+
| (Pick<OrchestrationV2ThreadProjection, "runtimeRequests" | "turnItems" | "subagents"> & {
374374
readonly thread: Pick<OrchestrationV2ThreadProjection["thread"], "remoteTaskRequests">;
375375
})
376376
| null = null;
@@ -395,15 +395,21 @@ export function createEnvironmentThreadDetailAtoms<E>(
395395
ids.has(item.requestId),
396396
);
397397
const remoteTaskRequests = projection.thread.remoteTaskRequests;
398+
const subagents =
399+
remoteTaskRequests === undefined
400+
? []
401+
: projection.subagents.filter((task) => task.remoteChild !== undefined);
398402
if (
399403
previous === null ||
400404
!arrayElementsEqual(previous.runtimeRequests, runtimeRequests) ||
401405
!arrayElementsEqual(previous.turnItems, turnItems) ||
406+
!arrayElementsEqual(previous.subagents, subagents) ||
402407
previous.thread.remoteTaskRequests !== remoteTaskRequests
403408
) {
404409
previous = {
405410
runtimeRequests,
406411
turnItems,
412+
subagents,
407413
thread: remoteTaskRequests === undefined ? {} : { remoteTaskRequests },
408414
};
409415
value = derivePendingThreadRequests(previous);

‎packages/client-runtime/src/state/threadRequests.test.ts‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {
33
NodeId,
44
ProviderSessionId,
55
RuntimeRequestId,
6+
ThreadId,
67
TurnItemId,
78
type OrchestrationV2ThreadProjection,
89
} from "@t3tools/contracts";
@@ -321,6 +322,16 @@ describe("pending v2 questions", () => {
321322
const remote = {
322323
runtimeRequests: [],
323324
turnItems: [],
325+
subagents: [
326+
{
327+
id: NodeId.make("remote-task"),
328+
remoteChild: {
329+
environmentId: EnvironmentId.make("environment-box"),
330+
threadId: ThreadId.make("thread-on-the-box"),
331+
label: "Box",
332+
},
333+
},
334+
],
324335
thread: {
325336
remoteTaskRequests: [
326337
{
@@ -356,6 +367,7 @@ describe("pending v2 questions", () => {
356367
detail: "pnpm test",
357368
responseCapability: "live",
358369
remoteTaskId: "remote-task",
370+
remoteEnvironmentLabel: "Box",
359371
},
360372
]);
361373
expect(redirectableApprovals(pending.approvals)).toEqual([]);
@@ -369,6 +381,7 @@ describe("pending v2 questions", () => {
369381
responseCapability: "live",
370382
dismissible: false,
371383
remoteTaskId: "remote-task",
384+
remoteEnvironmentLabel: "Box",
372385
},
373386
]);
374387
});

‎packages/client-runtime/src/state/threadRequests.ts‎

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
type NodeId,
55
type ThreadId,
66
type OrchestrationV2AppThread,
7+
type OrchestrationV2Subagent,
78
type OrchestrationV2ThreadProjection,
89
type OrchestrationV2RuntimeRequest,
910
type OrchestrationV2UserInputQuestion,
@@ -67,6 +68,7 @@ export interface ThreadPendingApproval {
6768
readonly responseCapability: "live" | "not_resumable";
6869
readonly supportsFeedback?: boolean;
6970
readonly remoteTaskId?: NodeId;
71+
readonly remoteEnvironmentLabel?: string;
7072
}
7173

7274
export const FULL_ACCESS_OVERRIDE_QUESTION = "Why am I being asked this?";
@@ -94,6 +96,7 @@ export interface ThreadPendingUserInput {
9496
readonly responseMode?: "message";
9597
readonly dismissible: boolean;
9698
readonly remoteTaskId?: NodeId;
99+
readonly remoteEnvironmentLabel?: string;
97100
}
98101

99102
export interface PendingThreadRequests {
@@ -228,6 +231,7 @@ export function makeThreadRequestsResolvedAnnouncer(
228231

229232
type WithRemoteTaskRequests = {
230233
readonly thread?: Pick<OrchestrationV2AppThread, "remoteTaskRequests">;
234+
readonly subagents?: ReadonlyArray<Pick<OrchestrationV2Subagent, "id" | "remoteChild">>;
231235
};
232236

233237
export function pendingRuntimeRequestIds(
@@ -301,6 +305,12 @@ export function derivePendingThreadRequests(
301305

302306
for (const request of remoteTaskRequestsOf(projection)) {
303307
const createdAt = DateTime.formatIso(request.createdAt);
308+
const environmentLabel = projection.subagents?.find((task) => task.id === request.taskId)
309+
?.remoteChild?.label;
310+
const remoteTask = {
311+
remoteTaskId: request.taskId,
312+
...(environmentLabel === undefined ? {} : { remoteEnvironmentLabel: environmentLabel }),
313+
};
304314
if (request.kind === "user_input") {
305315
userInputs.push({
306316
requestId: request.requestId,
@@ -311,7 +321,7 @@ export function derivePendingThreadRequests(
311321
})),
312322
responseCapability: "live",
313323
dismissible: false,
314-
remoteTaskId: request.taskId,
324+
...remoteTask,
315325
});
316326
continue;
317327
}
@@ -323,7 +333,7 @@ export function derivePendingThreadRequests(
323333
...(request.reason ? { reason: request.reason } : {}),
324334
...(request.options === undefined ? {} : { options: request.options }),
325335
responseCapability: "live",
326-
remoteTaskId: request.taskId,
336+
...remoteTask,
327337
});
328338
}
329339

0 commit comments

Comments
 (0)