diff --git a/.agents/skills/test-t3-app/references/feature-map.md b/.agents/skills/test-t3-app/references/feature-map.md
index 106a343211f2c..4e7dab8a65148 100644
--- a/.agents/skills/test-t3-app/references/feature-map.md
+++ b/.agents/skills/test-t3-app/references/feature-map.md
@@ -80,6 +80,8 @@ Code: apps/web/src/components/chat/MessagesTimeline.tsx
- **timeline.user-message** — your messages, with sender line and "Copy message".
- **timeline.assistant-reply** — agent replies with markdown, code blocks, math, Mermaid, file and thread links.
+- **timeline.agent-activity** — collapsed agent updates. Open the strip to read the original messages and work.
+- **timeline.human-note** — model-hidden note with "Promote to agent" to send its text in a separate turn.
- **timeline.work-group** — collapsed tool calls and commands; "Show more" / "Show less".
- **timeline.approval** — "Command approval", "File change approval", "File read approval", "Permission request": "Approve", "Decline", "Always allow this session", "More approval options".
- **timeline.user-input** — agent questions: "Type your answer", "Previous question" / "Next question", "Submit answer" (one question) or "Submit answers".
diff --git a/apps/mobile/src/features/threads/ThreadDetailScreen.tsx b/apps/mobile/src/features/threads/ThreadDetailScreen.tsx
index 425a5cecac599..c1e392758984b 100644
--- a/apps/mobile/src/features/threads/ThreadDetailScreen.tsx
+++ b/apps/mobile/src/features/threads/ThreadDetailScreen.tsx
@@ -243,6 +243,7 @@ export interface ThreadDetailScreenProps {
readonly feedbackSubmissions: ReadonlyArray;
readonly onDismissFeedback: (id: MessageId) => void;
readonly selectedThreadFeed: ReadonlyArray;
+ readonly onPromoteNote?: ((noteId: MessageId) => Promise) | undefined;
readonly pendingHandoff?: HandoffEndpoints | null;
readonly activityRun: ThreadFeedLatestRun | null;
readonly activeWorkStartedAt: string | null;
@@ -1478,6 +1479,10 @@ function ThreadDetailBody(
detailRef={props.selectedThreadDetailRef}
workspaceRoot={props.threadCwd}
feed={props.selectedThreadFeed}
+ onPromoteNote={props.onPromoteNote}
+ decisionRequestedAt={
+ props.selectedThread.source.inbox?.decisionRequest?.requestedAt
+ }
pendingHandoff={props.pendingHandoff}
worktreeSetup={props.worktreeSetup}
setupWorkingStartedAt={props.setupWorkingStartedAt}
diff --git a/apps/mobile/src/features/threads/ThreadFeed.tsx b/apps/mobile/src/features/threads/ThreadFeed.tsx
index 7df6616b45a9d..ec86e2a284871 100644
--- a/apps/mobile/src/features/threads/ThreadFeed.tsx
+++ b/apps/mobile/src/features/threads/ThreadFeed.tsx
@@ -1,4 +1,5 @@
import {
+ type MessageSender,
messageSenderDetail,
messageSenderLabel,
resolveMessageSender,
@@ -232,6 +233,7 @@ import {
isSecretRequestActivityGroup,
type ThreadFeedEntry,
type ThreadFeedLatestRun,
+ type ThreadFeedMessage,
messageFoldRunId,
} from "../../lib/threadActivity";
import type { ThreadContentPresentation } from "./threadContentPresentation";
@@ -250,6 +252,7 @@ import {
appendGuestPendingMessages,
appendPendingThreadMessages,
createThreadFeedGrouping,
+ foldThreadFeedActivity,
isCompactionCommandFeedEntry,
type GroupedThreadFeedRow,
type ThreadFeedRow,
@@ -384,6 +387,8 @@ export interface ThreadFeedProps {
readonly onIsAtEndChange?: (isAtEnd: boolean) => void;
readonly skills?: ReadonlyArray;
readonly onUseArtifactTemplate?: (template: CodexArtifactTemplate) => void;
+ readonly onPromoteNote?: ((noteId: MessageId) => Promise) | undefined;
+ readonly decisionRequestedAt?: string | undefined;
}
const USER_MESSAGE_COPY_MENU_ACTIONS = [
@@ -1779,12 +1784,75 @@ function RunFoldButton({
);
}
+function ThreadPersonHeading({ sender }: { readonly sender: MessageSender }) {
+ if (sender.kind !== "person") return null;
+ const detail = messageSenderDetail(sender);
+ return (
+
+ {messageSenderLabel(sender)}
+ {detail === null ? "" : ` · ${detail}`}
+
+ );
+}
+
+function ThreadHumanNote({
+ message,
+ onPromote,
+}: {
+ readonly message: ThreadFeedMessage;
+ readonly onPromote?: ThreadFeedProps["onPromoteNote"];
+}) {
+ const [status, setStatus] = useState<"idle" | "sending" | "sent" | "failed">("idle");
+ const promoted = message.humanNotePromoted || status === "sent";
+ return (
+
+
+ Model-hidden note
+ {onPromote && !promoted && message.visibility !== "inherited" ? (
+ {
+ setStatus("sending");
+ try {
+ await onPromote(message.id);
+ setStatus("sent");
+ } catch {
+ setStatus("failed");
+ }
+ }}
+ className="min-h-11 justify-center"
+ >
+
+ {status === "sending" ? "Sending…" : "Promote to agent"}
+
+
+ ) : null}
+
+
+ {message.text}
+
+ {promoted || status === "failed" ? (
+
+ {message.humanNotePromoted
+ ? "Promoted to agent"
+ : promoted
+ ? "Queued for agent"
+ : "Could not promote the note"}
+
+ ) : null}
+
+ );
+}
+
function renderFeedEntry(
info: { item: ThreadFeedRow; index: number },
props: Pick<
ThreadFeedProps,
| "environmentId"
| "onUseArtifactTemplate"
+ | "onPromoteNote"
| "skills"
| "dispatchingMessageId"
| "onEditPendingMessage"
@@ -1803,6 +1871,7 @@ function renderFeedEntry(
readonly onCopyWorkRow: (rowId: string, value: string) => void;
readonly onToggleWorkGroup: (groupId: string, anchorKey?: string) => void;
readonly onToggleWorkRow: (rowId: string, anchorKey?: string, groupId?: string) => void;
+ readonly onToggleActivityFold: (row: Extract) => void;
readonly onToggleTurnFold: (runId: RunId) => void;
readonly onOpenTurnDiff: (checkpoint: ThreadCheckpointSummary) => void;
readonly onPressPreview: (source: FilePreviewSource) => void;
@@ -1831,6 +1900,30 @@ function renderFeedEntry(
const entry = info.item;
const { markdownStyles, iconSubtleColor, userBubbleColor } = props;
+ if (entry.type === "activity-fold") {
+ return (
+ props.onToggleActivityFold(entry)}
+ className="min-h-11 flex-row items-center gap-1.5"
+ >
+
+
+ {entry.summary}
+
+
+ );
+ }
+
if (entry.type === "guest-pending") {
return (
+
+
+
+ );
+ }
+
if (isUser && props.workflowOpening?.messageId === message.id) {
return (
) : null}
- {sender.kind === "person" && !props.userMessageGrouping.groupedWithPrevious ? (
-
- {messageSenderLabel(sender)}
- {messageSenderDetail(sender) === null ? "" : ` · ${messageSenderDetail(sender)}`}
-
- ) : null}
+ {props.userMessageGrouping.groupedWithPrevious ? null : (
+
+ )}
{mediaAttachments.length + pendingMedia.length > 0 ? (
initialSplitViewport?.height ?? 0);
+ const [dismissedActivity, setDismissedActivity] = useState>(
+ () => new Map(),
+ );
const [disclosureLayout, setDisclosureLayout] = useState(null);
const disclosureMotionRef = useRef(null);
const disclosureMotionTimer = useRef | null>(null);
@@ -3608,11 +3709,32 @@ export const ThreadFeed = memo(function ThreadFeed(props: ThreadFeedProps) {
expandedTurnIds: new Set(current.expandedTurnIds).add(jumpRunId),
}));
}
- const setupAnchorIndex = presentedFeed.findIndex(
+ const visibleFeed = useMemo(
+ () =>
+ foldThreadFeedActivity(presentedFeed, props.feed, {
+ open: expandedWorkRows,
+ dismissed: dismissedActivity,
+ revealedMessageId,
+ latestRun: props.latestRun
+ ? { id: props.latestRun.runId, status: props.latestRun.status }
+ : null,
+ decisionRequestedAt: props.decisionRequestedAt,
+ }),
+ [
+ presentedFeed,
+ props.feed,
+ expandedWorkRows,
+ dismissedActivity,
+ revealedMessageId,
+ props.latestRun,
+ props.decisionRequestedAt,
+ ],
+ );
+ const setupAnchorIndex = visibleFeed.findIndex(
(entry) => entry.type === "message" && entry.message.role === "user",
);
const [groupFeed] = useState(createThreadFeedGrouping);
- const groupedFeed = groupFeed(presentedFeed, {
+ const groupedFeed = groupFeed(visibleFeed, {
workflowOpeningMessageId: workflowOpening?.messageId,
setupAnchorIndex:
props.worktreeSetup || props.setupWorkingStartedAt || props.preparingWorktree
@@ -3626,7 +3748,7 @@ export const ThreadFeed = memo(function ThreadFeed(props: ThreadFeedProps) {
if (list && bottom > 0) list.reportContentInset({ bottom });
};
const jumpIndex = jumpReady
- ? presentedFeed.findIndex((entry) => entry.type === "message" && entry.id === jumpToMessageId)
+ ? visibleFeed.findIndex((entry) => entry.type === "message" && entry.id === jumpToMessageId)
: null;
const landJump = useEffectEvent((index: number) => {
const list = listRef.current;
@@ -3657,7 +3779,7 @@ export const ThreadFeed = memo(function ThreadFeed(props: ThreadFeedProps) {
};
const anchoredEndSpace = resolveChatListAnchoredEndSpace(
- presentedFeed,
+ visibleFeed,
props.anchorMessageId,
(entry) => (entry.type === "message" ? entry.id : null),
{ anchorOffset: anchorTopInset + CHAT_LIST_ANCHOR_OFFSET },
@@ -3832,6 +3954,21 @@ export const ThreadFeed = memo(function ThreadFeed(props: ThreadFeedProps) {
});
};
+ const onToggleActivityFold = (row: Extract) => {
+ preserveDisclosurePosition(row.id);
+ setInteractionState((current) => ({
+ ...current,
+ expandedWorkRows: { ...current.expandedWorkRows, [row.id]: !row.expanded },
+ revealedMessageId: null,
+ }));
+ setDismissedActivity((previous) => {
+ const next = new Map(previous);
+ if (row.expanded && row.attention !== null) next.set(row.id, row.attention);
+ else next.delete(row.id);
+ return next;
+ });
+ };
+
const onToggleTurnFold = (runId: RunId) => {
preserveDisclosurePosition(`run-fold:${runId}`);
setInteractionState((current) => {
@@ -3854,7 +3991,7 @@ export const ThreadFeed = memo(function ThreadFeed(props: ThreadFeedProps) {
// estimatedItemSize tall, and scrolling up through unmeasured content
// corrects each row's height as it mounts — the feed visibly jumps.
const getFixedItemSize = (entry: ThreadFeedRow) => {
- if (entry.type === "guest-pending") return undefined;
+ if (entry.type === "guest-pending" || entry.type === "activity-fold") return undefined;
if (entry.type === "html-render") {
return htmlRenderRowHeight(htmlRenderFrameHeight(entry.render, contentWidth));
}
@@ -3947,6 +4084,8 @@ export const ThreadFeed = memo(function ThreadFeed(props: ThreadFeedProps) {
dispatchingMessageId: props.dispatchingMessageId,
onEditPendingMessage: props.onEditPendingMessage,
onUseArtifactTemplate: props.onUseArtifactTemplate,
+ onPromoteNote: props.onPromoteNote,
+ onToggleActivityFold,
threadId: props.threadId,
copiedRowId,
expandedWorkRows,
diff --git a/apps/mobile/src/features/threads/ThreadRouteScreen.tsx b/apps/mobile/src/features/threads/ThreadRouteScreen.tsx
index bbfc0dc0b44ef..15b24d3a52e38 100644
--- a/apps/mobile/src/features/threads/ThreadRouteScreen.tsx
+++ b/apps/mobile/src/features/threads/ThreadRouteScreen.tsx
@@ -1022,6 +1022,29 @@ function ThreadRouteContent(
feedbackSubmissions={composer.feedbackSubmissions}
onDismissFeedback={composer.dismissFeedback}
selectedThreadFeed={composer.selectedThreadFeed}
+ onPromoteNote={
+ canOperateThread && !isProviderNativeSubagentThread(selectedThread.source)
+ ? async (noteId) => {
+ const result = await continueThreadRun({
+ environmentId: selectedThread.environmentId,
+ input: {
+ threadId: selectedThread.id,
+ promoteNoteId: noteId,
+ creationSource: "mobile",
+ message: {
+ messageId: MessageId.make(uuidv4()),
+ role: "user",
+ text: "",
+ attachments: [],
+ },
+ runtimeMode: composer.runtimeMode ?? selectedThread.runtimeMode,
+ interactionMode: composer.interactionMode ?? selectedThread.interactionMode,
+ },
+ });
+ if (result._tag === "Failure") throw squashAtomCommandFailure(result);
+ }
+ : undefined
+ }
pendingHandoff={composer.pendingHandoff}
activityRun={composer.selectedThreadActivityRun}
activeWorkStartedAt={
diff --git a/apps/mobile/src/features/threads/pending-thread-feed.test.ts b/apps/mobile/src/features/threads/pending-thread-feed.test.ts
index 99cabea0d5443..08f81d83dd92f 100644
--- a/apps/mobile/src/features/threads/pending-thread-feed.test.ts
+++ b/apps/mobile/src/features/threads/pending-thread-feed.test.ts
@@ -5,13 +5,17 @@ import {
EnvironmentId,
MessageId,
ProjectId,
+ RunId,
+ type OrchestrationV2ProjectedTurnItem,
ThreadId,
} from "@t3tools/contracts";
+import type { ThreadFeedEntry } from "../../lib/threadActivity";
import type { QueuedThreadMessage } from "../../state/thread-outbox-model";
import {
appendAcceptedThreadMessages,
appendPendingThreadMessages,
createThreadFeedGrouping,
+ foldThreadFeedActivity,
isCompactionCommandFeedEntry,
selectPendingAcknowledgedMessages,
} from "./pending-thread-feed";
@@ -27,6 +31,97 @@ const pending = (id: string): QueuedThreadMessage => ({
});
describe("pending timeline messages", () => {
+ it("reveals a message jump inside chatter and never hides a note", () => {
+ const [first, second, third] = appendPendingThreadMessages(
+ [],
+ [],
+ [pending("before"), pending("note"), pending("after")],
+ );
+ if (first?.type !== "message" || second?.type !== "message" || third?.type !== "message") {
+ throw new Error("Expected message rows");
+ }
+ const rows = [
+ { ...first, message: { ...first.message, createdBy: "agent" as const } },
+ { ...second, message: { ...second.message, humanNote: true as const } },
+ { ...third, message: { ...third.message, createdBy: "agent" as const } },
+ ];
+ const options = { open: {}, dismissed: new Map(), latestRun: null };
+ const folded = foldThreadFeedActivity(rows, rows, { ...options, revealedMessageId: null });
+ expect(folded.map((row) => row.type)).toEqual(["activity-fold", "message", "activity-fold"]);
+ expect(folded[1]).toBe(rows[1]);
+ expect(
+ foldThreadFeedActivity(rows, rows, {
+ ...options,
+ revealedMessageId: first.id,
+ }).map((row) => row.type),
+ ).toEqual(["activity-fold", "message", "message", "activity-fold"]);
+ });
+
+ it("reveals the decision run after an intervening agent reply", () => {
+ const makeMessage = (
+ id: string,
+ runId: RunId,
+ role: "user" | "assistant",
+ createdAt: string,
+ ) => {
+ const row = appendPendingThreadMessages([], [], [pending(id)])[0];
+ if (row?.type !== "message") throw new Error("Expected message");
+ return {
+ ...row,
+ createdAt,
+ message: { ...row.message, role, runId, createdBy: "agent" as const },
+ };
+ };
+ const origin = RunId.make("origin");
+ const unrelated = RunId.make("unrelated");
+ const requestedAt = "2026-09-06T10:00:01.000Z";
+ const request = {
+ type: "activity-group",
+ id: "decision-request",
+ createdAt: requestedAt,
+ runId: origin,
+ activities: [
+ {
+ createdAt: requestedAt,
+ projectedItem: {
+ item: {
+ runId: origin,
+ type: "dynamic_tool",
+ status: "completed",
+ toolName: "t3_thread_update",
+ input: { action: "request_decision" },
+ startedAt: null,
+ },
+ } as OrchestrationV2ProjectedTurnItem,
+ },
+ ],
+ } as unknown as ThreadFeedEntry;
+ const rows = [
+ makeMessage("other-input", unrelated, "user", "2026-09-06T10:00:00.000Z"),
+ makeMessage("unrelated-reply", unrelated, "assistant", "2026-09-06T10:00:02.000Z"),
+ {
+ ...makeMessage("founder-turn", origin, "user", requestedAt),
+ message: {
+ ...makeMessage("founder-turn", origin, "user", requestedAt).message,
+ runId: null,
+ createdBy: "user" as const,
+ },
+ },
+ makeMessage("origin-input", origin, "user", "2026-09-06T10:00:00.000Z"),
+ request,
+ makeMessage("founder-decision", origin, "assistant", "2026-09-06T10:00:03.000Z"),
+ ];
+ const folded = foldThreadFeedActivity(rows, rows, {
+ open: {},
+ dismissed: new Map(),
+ revealedMessageId: null,
+ latestRun: null,
+ decisionRequestedAt: requestedAt,
+ });
+ expect(folded.map(({ id }) => id)).toContain("decision-request");
+ expect(folded.map(({ id }) => id)).toContain("founder-decision");
+ });
+
it("keeps unchanged row identities while text streams and updates adjacent grouping", () => {
const group = createThreadFeedGrouping();
const [first, second, third] = appendPendingThreadMessages(
diff --git a/apps/mobile/src/features/threads/pending-thread-feed.ts b/apps/mobile/src/features/threads/pending-thread-feed.ts
index 3263a94595c3c..4e598c5a25bc2 100644
--- a/apps/mobile/src/features/threads/pending-thread-feed.ts
+++ b/apps/mobile/src/features/threads/pending-thread-feed.ts
@@ -1,3 +1,11 @@
+import {
+ type ChatActivityEntry,
+ activityItemNeedsAttention,
+ chatActivityContext,
+ chatActivityGroups,
+ isChatActivityMessage,
+ summarizeChatActivity,
+} from "@t3tools/client-runtime/chat-activity";
import {
isCompactionCommandMessage,
type ThreadGuestMessage,
@@ -28,6 +36,7 @@ export interface GuestPendingFeedEntry {
export type PendingThreadFeedEntry = ThreadFeedEntry & {
readonly pendingMessage?: QueuedThreadMessage;
readonly acknowledged?: boolean;
+ readonly activityRevealed?: true;
};
// An acknowledged row stops being pending once the thread catches up to it,
@@ -53,7 +62,113 @@ export function selectPendingAcknowledgedMessages(
}
/** A row of the thread feed's list. */
-export type ThreadFeedRow = PendingThreadFeedEntry | GuestPendingFeedEntry;
+interface ActivityFoldFeedEntry {
+ readonly type: "activity-fold";
+ readonly id: string;
+ readonly createdAt: string;
+ readonly summary: string;
+ readonly attention: string | null;
+ readonly expanded: boolean;
+}
+
+export type ThreadFeedRow = PendingThreadFeedEntry | GuestPendingFeedEntry | ActivityFoldFeedEntry;
+
+export function foldThreadFeedActivity(
+ feed: ReadonlyArray,
+ rawFeed: ReadonlyArray,
+ options: {
+ readonly open: Readonly>;
+ readonly dismissed: ReadonlyMap;
+ readonly revealedMessageId: string | null;
+ readonly latestRun: Parameters[1][number] | null;
+ readonly decisionRequestedAt?: string | undefined;
+ },
+): ReadonlyArray {
+ const context = chatActivityContext(
+ rawFeed.flatMap((entry): ChatActivityEntry[] => {
+ if (entry.type === "message") {
+ return [{ createdAt: entry.createdAt, runId: entry.message.runId, message: entry.message }];
+ }
+ if (entry.type !== "activity-group") return [];
+ return entry.activities.map(({ createdAt, projectedItem }) => ({
+ createdAt,
+ runId: projectedItem.item.runId,
+ item: projectedItem.item,
+ }));
+ }),
+ options.latestRun ? [options.latestRun] : [],
+ false,
+ options.decisionRequestedAt,
+ );
+ const folded: ThreadFeedRow[] = [];
+ let hasActivity = false;
+ for (const group of chatActivityGroups(feed, (entry) => {
+ if (entry.type === "message")
+ return !isChatActivityMessage(entry.message, entry.message.runId, context);
+ if (
+ entry.type === "activity-group" &&
+ entry.activities.some(
+ ({ projectedItem: { item } }) =>
+ item.type === "secret_request" || item.type === "link_request",
+ )
+ )
+ return true;
+ return (
+ (entry.type !== "activity-group" &&
+ entry.type !== "work-toggle" &&
+ entry.type !== "run-fold") ||
+ !entry.runId ||
+ !context.agentRuns.has(entry.runId)
+ );
+ })) {
+ if (!("rows" in group)) {
+ folded.push(group);
+ continue;
+ }
+ hasActivity = true;
+ const items = group.rows.flatMap((row) =>
+ row.type === "activity-group"
+ ? row.activities.map(({ projectedItem }) => projectedItem.item)
+ : [],
+ );
+ const messages = group.rows.flatMap((row) => (row.type === "message" ? [row.message] : []));
+ const settledTaskIds = group.rows.flatMap((row) =>
+ row.type === "work-toggle" || row.type === "run-fold" ? (row.settledTaskIds ?? []) : [],
+ );
+ const attentionIds = new Set(
+ items.filter(activityItemNeedsAttention).map(({ id }) => String(id)),
+ );
+ for (const row of group.rows) {
+ const runId = row.type === "message" ? row.message.runId : "runId" in row ? row.runId : null;
+ if (runId) for (const id of context.attentionByRun.get(runId) ?? []) attentionIds.add(id);
+ if (row.type === "work-toggle" && row.hasFailure) attentionIds.add(row.id);
+ }
+ const attention = attentionIds.size > 0 ? JSON.stringify([...attentionIds].sort()) : null;
+ const expanded =
+ options.open[group.id] === true ||
+ (attention !== null && options.dismissed.get(group.id) !== attention) ||
+ (options.revealedMessageId !== null &&
+ group.rows.some((row) => row.id === options.revealedMessageId));
+ folded.push({
+ type: "activity-fold",
+ id: group.id,
+ createdAt: group.rows[0]!.createdAt,
+ summary: summarizeChatActivity(group.rows.length, messages, items, settledTaskIds),
+ attention,
+ expanded,
+ });
+ if (expanded) {
+ for (const row of group.rows) {
+ folded.push(
+ row.type === "message" && resolveMessageSender(row.message).kind === "agent"
+ ? { ...row, activityRevealed: true }
+ : row,
+ );
+ }
+ }
+ }
+ return hasActivity ? folded : feed;
+}
export type GroupedThreadFeedRow = ThreadFeedRow & {
readonly userMessageGrouping: ReturnType;
@@ -95,6 +210,7 @@ export function createThreadFeedGrouping() {
const entry = feed[index];
return entry?.type === "message" &&
entry.message.role === "user" &&
+ !entry.message.humanNote &&
!isCompactionCommandFeedEntry(entry) &&
entry.message.id !== options.workflowOpeningMessageId
? entry.message
diff --git a/apps/mobile/src/lib/threadActivity.test.ts b/apps/mobile/src/lib/threadActivity.test.ts
index cfc228a982339..7de9a21abfe2d 100644
--- a/apps/mobile/src/lib/threadActivity.test.ts
+++ b/apps/mobile/src/lib/threadActivity.test.ts
@@ -19,6 +19,7 @@ import {
} from "@t3tools/contracts";
import { deriveThreadCheckpointSummaries } from "@t3tools/client-runtime/state/thread-checkpoints";
import { summarizeToolGroup } from "@t3tools/client-runtime/work-log/presentation";
+import { foldThreadFeedActivity } from "../features/threads/pending-thread-feed";
import { getReviewSectionIdForCheckpoint } from "../features/review/reviewModel";
import * as DateTime from "effect/DateTime";
import { describe, expect, it } from "vite-plus/test";
@@ -1261,6 +1262,25 @@ describe("buildThreadFeed", () => {
const finished = present([subagent("item-done", "2026-06-20T00:00:03.000Z", 2, "completed")]);
expect(finished.map((entry) => entry.type)).toEqual(["message", "run-fold", "message"]);
+ const raw = buildThreadFeed([
+ projected({ ...userMessage(), createdBy: "agent", creationSource: "mcp" }, 0),
+ projected(command("2026-06-20T00:00:02.000Z"), 1),
+ projected(subagent("item-done", "2026-06-20T00:00:03.000Z", 2, "completed"), 2),
+ projected(assistantMessage("2026-06-20T00:00:05.000Z"), 3),
+ ]);
+ const options = {
+ open: {},
+ dismissed: new Map(),
+ revealedMessageId: null,
+ latestRun: { id: runId, status: "completed" as const },
+ };
+ for (const expandedRuns of [new Set(), new Set([runId])]) {
+ const presented = deriveThreadFeedPresentation(raw, latestRun, expandedRuns);
+ const capsule = foldThreadFeedActivity(presented, raw, options).find(
+ (row) => row.type === "activity-fold",
+ );
+ expect(capsule?.summary).toContain("1 settled");
+ }
});
it("folds each run of a provider-native subagent thread like a normal turn", () => {
diff --git a/apps/mobile/src/lib/threadActivity.ts b/apps/mobile/src/lib/threadActivity.ts
index 2335af6f7a9dc..478aa118667eb 100644
--- a/apps/mobile/src/lib/threadActivity.ts
+++ b/apps/mobile/src/lib/threadActivity.ts
@@ -59,6 +59,7 @@ import type {
ScheduledTaskId,
TurnItemId,
} from "@t3tools/contracts";
+import { settledChatActivityTaskIds } from "@t3tools/client-runtime/chat-activity";
import { idleCompactionOf, isCompactionCommandMessage, RunId, ThreadId } from "@t3tools/contracts";
import {
classifyToolActivity,
@@ -148,6 +149,8 @@ export interface ThreadFeedMessage {
/** The signed-in client a person sent it from, stamped by the server. */
readonly sentBy?: import("@t3tools/contracts").OrchestrationV2MessageSentBy;
readonly idleCompaction?: import("@t3tools/contracts").OrchestrationV2IdleCompaction;
+ readonly humanNote?: true;
+ readonly humanNotePromoted?: true;
readonly visibility: OrchestrationV2ProjectedTurnItem["visibility"];
readonly sourceThreadId: ThreadId;
readonly createdAt: string;
@@ -227,6 +230,7 @@ type ThreadFeedEntryContent =
readonly createdAt: string;
readonly runId: RunId | null;
readonly groupId: string;
+ readonly settledTaskIds?: ReadonlyArray;
readonly hiddenCount: number;
readonly expanded: boolean;
readonly summary: string;
@@ -249,6 +253,7 @@ type ThreadFeedEntryContent =
}
| {
readonly type: "run-fold";
+ readonly settledTaskIds?: ReadonlyArray;
readonly deferredWorkItemIds?: ReadonlyArray;
readonly id: string;
readonly createdAt: string;
@@ -1040,7 +1045,11 @@ function threadFeedActivityIsVisible(
);
}
+const settledTaskIdsInActivity = (activities: ReadonlyArray) =>
+ activities.flatMap(({ projectedItem }) => settledChatActivityTaskIds(projectedItem.item));
+
interface ThreadFeedRunFold {
+ readonly settledTaskIds?: ReadonlyArray;
readonly deferredWorkItemIds?: ReadonlyArray;
readonly runId: RunId;
readonly createdAt: string;
@@ -1335,7 +1344,13 @@ function deriveThreadFeedRunFolds(
)
: [],
);
+ const settledTaskIds = segment.entries.flatMap((entry) =>
+ entry.type === "activity-group" && hiddenEntryIds.has(entry.id)
+ ? settledTaskIdsInActivity(entry.activities)
+ : [],
+ );
foldsByAnchorId.set(firstHiddenEntry.id, {
+ ...(settledTaskIds.length > 0 ? { settledTaskIds } : {}),
...(deferredWorkItemIds.length > 0 ? { deferredWorkItemIds } : {}),
runId: segment.runId,
createdAt: firstHiddenEntry.createdAt,
@@ -1355,7 +1370,9 @@ function deriveThreadFeedRunFolds(
activity.projectedItem.item.deferredWork ? [String(activity.projectedItem.sourceItemId)] : [],
);
if (deferredWorkItemIds.length === 0) continue;
+ const settledTaskIds = settledTaskIdsInActivity(entry.activities);
foldsByAnchorId.set(entry.id, {
+ ...(settledTaskIds.length > 0 ? { settledTaskIds } : {}),
runId: RunId.make(`deferred-work:${entry.id}`),
createdAt: entry.createdAt,
hiddenEntryIds: new Set([entry.id]),
@@ -1750,11 +1767,13 @@ export function deriveThreadFeedPresentation(
row.createdAt !== fold.createdAt ||
row.label !== fold.label ||
row.expanded !== expanded ||
+ row.settledTaskIds?.join("|") !== fold.settledTaskIds?.join("|") ||
row.deferredWorkItemIds?.join("|") !== fold.deferredWorkItemIds?.join("|")
) {
row = {
type: "run-fold",
id: `run-fold:${fold.runId}`,
+ ...(fold.settledTaskIds ? { settledTaskIds: fold.settledTaskIds } : {}),
...(fold.deferredWorkItemIds ? { deferredWorkItemIds: fold.deferredWorkItemIds } : {}),
createdAt: fold.createdAt,
runId: fold.runId,
@@ -2172,8 +2191,10 @@ function appendToolGroupRows(
const summaryToolIcon = live
? resolveWorkEntryToolPresentation(latestActivity.workEntry)?.icon
: undefined;
+ const settledTaskIds = settledTaskIdsInActivity(activities);
result.push({
type: "work-toggle",
+ ...(settledTaskIds.length > 0 ? { settledTaskIds } : {}),
id,
createdAt: sourceGroup.createdAt,
runId: sourceGroup.runId,
@@ -2503,6 +2524,8 @@ export function buildThreadFeed(
...(item.linkedSender ? { linkedSender: item.linkedSender } : {}),
...(item.sentBy ? { sentBy: item.sentBy } : {}),
...(item.idleCompaction ? { idleCompaction: item.idleCompaction } : {}),
+ ...(item.humanNote ? { humanNote: true as const } : {}),
+ ...(item.humanNotePromoted ? { humanNotePromoted: true as const } : {}),
}
: {}),
visibility: row.visibility,
diff --git a/apps/server/src/mcp/OrchestratorMcpService.activity.test.ts b/apps/server/src/mcp/OrchestratorMcpService.activity.test.ts
index e5f87411a165b..dda63dd460377 100644
--- a/apps/server/src/mcp/OrchestratorMcpService.activity.test.ts
+++ b/apps/server/src/mcp/OrchestratorMcpService.activity.test.ts
@@ -1,5 +1,7 @@
import {
EnvironmentId,
+ MessageId,
+ type OrchestrationV2ProjectedTurnItem,
NodeId,
type OrchestratorMcpThreadReadResult,
type OrchestrationV2ThreadProjection,
@@ -300,6 +302,93 @@ it("readThread preserves caller access errors and prefers activity-run status ov
}).pipe(Effect.provide(layer), Effect.runPromise);
});
+it("readThread hides private notes in both views and targeted reads", async () => {
+ const itemId = TurnItemId.make("private-note");
+ const messageId = MessageId.make("note-message");
+ const noteText = "synthetic private note";
+ const thread = baseThread({
+ threadId: parentThreadId,
+ title: "Parent",
+ instanceId: parentInstanceId,
+ model: "gpt-5.4",
+ });
+ const projection = {
+ thread,
+ runs: [],
+ messages: [],
+ providerTurns: [],
+ runtimeRequests: [],
+ contextTransfers: [],
+ } as unknown as OrchestrationV2ThreadProjection;
+ const note = {
+ position: 0,
+ visibility: "local",
+ sourceThreadId: parentThreadId,
+ sourceItemId: itemId,
+ item: {
+ type: "user_message",
+ status: "completed",
+ runId: null,
+ title: null,
+ messageId,
+ text: noteText,
+ humanNote: true,
+ updatedAt: now,
+ },
+ } as OrchestrationV2ProjectedTurnItem;
+ const ordinary = {
+ ...note,
+ position: 1,
+ sourceItemId: TurnItemId.make("ordinary-message"),
+ item: { ...note.item, humanNote: undefined, text: "ordinary message" },
+ } as OrchestrationV2ProjectedTurnItem;
+ const layer = layerOrchestratorService.pipe(
+ Layer.provide(
+ Layer.mergeAll(
+ Layer.mock(ThreadManagementService.ThreadManagementService)({
+ getTimelinePage: (_threadId, { itemId }) =>
+ Effect.succeed({
+ items: itemId ? [note] : [note, ordinary],
+ totalItems: 2,
+ hasMore: false,
+ hasEarlier: false,
+ }),
+ getThreadRecords: () => Effect.succeed(projection),
+ getProjectThreadRecords: () => Effect.succeed(projection),
+ getThreadShell: () => Effect.succeed(thread as unknown as OrchestrationV2ThreadShell),
+ }),
+ ServerSettings.layerTest(),
+ Layer.mock(ProviderRegistry.ProviderRegistry)({}),
+ Layer.mock(ProjectService.ProjectService)({}),
+ Layer.mock(SecretRequests.SecretRequests)({}),
+ Layer.mock(RemoteDelegation.RemoteDelegation)({}),
+ Layer.mock(ScheduledTaskService.ScheduledTaskService)({}),
+ Layer.mock(ProviderAdapterRegistry.ProviderAdapterRegistryV2)({}),
+ NodeCrypto.layer,
+ ),
+ ),
+ );
+ await Effect.gen(function* () {
+ const service = yield* OrchestratorMcpService.OrchestratorMcpService;
+ for (const view of ["messages", "activity"] as const) {
+ const page = yield* service.readThread(makeScope(), { threadId: parentThreadId, view });
+ expect(page.items.map(({ text }) => text)).toEqual([null, "ordinary message"]);
+ const item = yield* service.readThread(makeScope(), {
+ threadId: parentThreadId,
+ view,
+ itemId,
+ textOffset: 2,
+ });
+ expect(item.items[0]).toMatchObject({
+ text: null,
+ textTruncated: false,
+ nextTextOffset: null,
+ });
+ expect(JSON.stringify(item)).not.toContain(noteText);
+ }
+ }).pipe(Effect.provide(layer), Effect.runPromise);
+});
+
it("readThread pages cut-off text without splitting an emoji across pages", async () => {
const text = "a😀bc";
const itemId = TurnItemId.make("turn-item-mcp-reasoning");
diff --git a/apps/server/src/mcp/OrchestratorMcpService.ts b/apps/server/src/mcp/OrchestratorMcpService.ts
index 78fdc7daa9ec7..33a2d69f41be3 100644
--- a/apps/server/src/mcp/OrchestratorMcpService.ts
+++ b/apps/server/src/mcp/OrchestratorMcpService.ts
@@ -1071,6 +1071,7 @@ function turnItemText(item: OrchestrationV2TurnItem): string | null {
case "notification":
return [item.summary, item.detail].filter((part) => part !== undefined).join("\n");
case "user_message":
+ return item.humanNote ? null : item.text;
case "assistant_message":
case "reasoning":
return item.text;
diff --git a/apps/server/src/orchestration-v2/ContextHandoffService.test.ts b/apps/server/src/orchestration-v2/ContextHandoffService.test.ts
index 78958c2e317d5..2e6cd7e682382 100644
--- a/apps/server/src/orchestration-v2/ContextHandoffService.test.ts
+++ b/apps/server/src/orchestration-v2/ContextHandoffService.test.ts
@@ -25,6 +25,7 @@ function importedItem(
input:
| {
readonly role: "user";
+ readonly humanNote?: true;
readonly id: string;
readonly text: string;
readonly ordinal: number;
@@ -62,6 +63,7 @@ function importedItem(
creationSource: "server",
type: "user_message",
inputIntent: "turn_start",
+ ...(input.humanNote ? { humanNote: true } : {}),
attachments: [],
}
: {
@@ -82,6 +84,13 @@ it.layer(layerTest)("ContextHandoffService legacy import", (it) => {
toProviderInstanceId: ProviderInstanceId.make("codex"),
items: [
importedItem({ role: "user", id: "one", text: "What did we decide?", ordinal: 1 }),
+ importedItem({
+ role: "user",
+ id: "private",
+ text: "synthetic private note",
+ ordinal: 2,
+ humanNote: true,
+ }),
importedItem({
role: "assistant",
id: "two",
@@ -96,6 +105,23 @@ it.layer(layerTest)("ContextHandoffService legacy import", (it) => {
assert.deepStrictEqual(handoff.fromProviderThreadIds, []);
assert.include(handoff.summaryText, "What did we decide?");
assert.include(handoff.summaryText, "keep the migration lightweight");
+ assert.notInclude(JSON.stringify(handoff), "synthetic private note");
+ assert.lengthOf(handoff.history?.messages ?? [], 2);
+ const digest = ContextHandoffService.makeSideChatContext({
+ parentThreadId: ThreadId.make("thread:parent"),
+ digest: [
+ importedItem({
+ role: "user",
+ id: "private",
+ text: "synthetic private note",
+ ordinal: 1,
+ humanNote: true,
+ }),
+ importedItem({ role: "user", id: "ordinary", text: "ordinary prompt", ordinal: 2 }),
+ ],
+ });
+ assert.notInclude(digest, "synthetic private note");
+ assert.include(digest, "ordinary prompt");
}),
);
diff --git a/apps/server/src/orchestration-v2/ContextHandoffService.ts b/apps/server/src/orchestration-v2/ContextHandoffService.ts
index ca6b5ff0fcdf1..4b187f22769fe 100644
--- a/apps/server/src/orchestration-v2/ContextHandoffService.ts
+++ b/apps/server/src/orchestration-v2/ContextHandoffService.ts
@@ -209,7 +209,7 @@ export const readForkHistoryItems = Effect.fn(
function summarizeDeltaItem(item: OrchestrationV2TurnItem): string | null {
switch (item.type) {
case "user_message":
- return `- User: ${compactText(item.text)}`;
+ return item.humanNote ? null : `- User: ${compactText(item.text)}`;
case "assistant_message":
return `- Assistant: ${compactText(item.text)}`;
case "command_execution":
@@ -290,7 +290,7 @@ function makeLegacyImportSummary(items: ReadonlyArray):
const sections = items.flatMap((item) => {
switch (item.type) {
case "user_message":
- return [{ label: "User", body: item.text }];
+ return item.humanNote ? [] : [{ label: "User", body: item.text }];
case "assistant_message":
return [{ label: "Assistant", body: item.text }];
default:
diff --git a/apps/server/src/orchestration-v2/HumanNote.test.ts b/apps/server/src/orchestration-v2/HumanNote.test.ts
index 68a69415acd39..bd543ff102a11 100644
--- a/apps/server/src/orchestration-v2/HumanNote.test.ts
+++ b/apps/server/src/orchestration-v2/HumanNote.test.ts
@@ -120,6 +120,8 @@ it.layer(layerTest)("human notes", (it) => {
const note = projection.turnItems.find((item) => item.type === "user_message");
assert.equal(note?.type === "user_message" ? note.humanNote : undefined, true);
assert.equal(note?.status, "completed");
+ const human = yield* orchestrator.getThreadSnapshot(threadId);
+ assert.include(JSON.stringify(human), "please look @Jeff");
assert.deepEqual(yield* projections.getTurnStartHistory(threadId), []);
const shell = yield* projections.getThreadShell(threadId);
assert.equal(shell?.settledOverride, null);
@@ -150,6 +152,101 @@ it.layer(layerTest)("human notes", (it) => {
}),
);
+ it.effect(
+ "promotes one stored note after rejection and deduplicates concurrent submissions",
+ () =>
+ Effect.gen(function* () {
+ const orchestrator = yield* Orchestrator.OrchestratorV2;
+ const projections = yield* ProjectionStore.ProjectionStoreV2;
+ const threadId = ThreadId.make("thread:promote-note");
+ const noteId = MessageId.make("note:source");
+ const text = "synthetic promotion text";
+ yield* createThread(threadId);
+ yield* orchestrator.dispatch({
+ type: "thread.metadata.update",
+ threadId,
+ commandId: CommandId.make("share:promote"),
+ inboxRouting: {
+ owner: null,
+ assignee: null,
+ audience: "shared",
+ attentionKind: "FYI",
+ reason: "conversation",
+ },
+ });
+ const send = (id: string, creationSource: "web" | "mobile" = "mobile") => ({
+ type: "message.dispatch" as const,
+ threadId,
+ commandId: CommandId.make(`dispatch:${id}`),
+ messageId: MessageId.make(id),
+ text: "",
+ attachments: [],
+ dispatchMode: { type: "promote_human_note" as const, noteId },
+ createdBy: "user" as const,
+ creationSource,
+ sentBy: sentBy("jeff"),
+ });
+ yield* orchestrator.dispatch({
+ ...send("record", "web"),
+ messageId: noteId,
+ text,
+ humanNote: true,
+ sentBy: sentBy("kameron"),
+ dispatchMode: { type: "queue_after_active" },
+ });
+ assert.deepEqual(yield* projections.getTurnStartHistory(threadId), []);
+ yield* orchestrator.dispatch({
+ type: "thread.archive",
+ commandId: CommandId.make("archive:note"),
+ threadId,
+ });
+ const refused = yield* orchestrator.dispatch(send("rejected")).pipe(Effect.flip);
+ assert.equal(refused._tag, "OrchestratorDispatchError");
+ yield* orchestrator.dispatch({
+ type: "thread.unarchive",
+ commandId: CommandId.make("unarchive:note"),
+ threadId,
+ });
+ yield* Effect.all(
+ [orchestrator.dispatch(send("retry-1")), orchestrator.dispatch(send("retry-2"))],
+ { concurrency: 2 },
+ );
+ yield* orchestrator.dispatch(send("repeat", "web"));
+ const snapshot = yield* projections.getThreadProjection(threadId);
+ assert.equal(snapshot.runs.length, 1);
+ assert.equal(snapshot.messages.length, 2);
+ const note = snapshot.messages.find((message) => message.id === noteId);
+ assert.equal(note?.text, text);
+ assert.equal(note?.sentBy?.founder, "kameron");
+ const promoted = snapshot.messages.find((message) => message.id !== noteId);
+ assert.equal(promoted?.text, text);
+ assert.equal(promoted?.humanNote, undefined);
+ assert.equal(promoted?.sentBy?.founder, "jeff");
+ assert.equal(promoted?.creationSource, "mobile");
+ const history = yield* projections.getTurnStartHistory(threadId);
+ assert.deepEqual(
+ history.flatMap((item) => (item.type === "user_message" ? [item.text] : [])),
+ [text],
+ );
+ const noteRow = (yield* orchestrator.getThreadSnapshot(
+ threadId,
+ )).projection.visibleTurnItems.find(
+ ({ item }) => item.type === "user_message" && item.messageId === noteId,
+ );
+ assert.equal(
+ noteRow?.item.type === "user_message" ? noteRow.item.humanNotePromoted : undefined,
+ true,
+ );
+ const ordinary = {
+ ...send("ordinary", "web"),
+ text,
+ dispatchMode: { type: "queue_after_active" as const },
+ };
+ yield* orchestrator.dispatch(ordinary);
+ assert.equal((yield* projections.getThreadProjection(threadId)).messages.length, 3);
+ }),
+ );
+
it.effect("rejects a note off a shared thread without waking it", () =>
Effect.gen(function* () {
const orchestrator = yield* Orchestrator.OrchestratorV2;
diff --git a/apps/server/src/orchestration-v2/Orchestrator.ts b/apps/server/src/orchestration-v2/Orchestrator.ts
index e233d8adcef23..a9b48bb1c4dcb 100644
--- a/apps/server/src/orchestration-v2/Orchestrator.ts
+++ b/apps/server/src/orchestration-v2/Orchestrator.ts
@@ -15514,6 +15514,59 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
break;
case "message.dispatch": {
const thread = yield* refuseNativeSubagentMessage(command);
+ if (command.dispatchMode.type === "promote_human_note") {
+ const note = yield* projectionStore
+ .getTurnItem({
+ threadId: command.threadId,
+ itemId: idAllocator.derive.userTurnItem({ messageId: command.dispatchMode.noteId }),
+ })
+ .pipe(mapDispatchError(command));
+ if (
+ command.createdBy !== "user" ||
+ note?.type !== "user_message" ||
+ !note.humanNote ||
+ note.messageId === command.messageId ||
+ thread.archivedAt !== null ||
+ thread.deletedAt !== null
+ ) {
+ return yield* new OrchestratorDispatchError({
+ commandId: command.commandId,
+ commandType: command.type,
+ cause: "Only a person can promote a note from this active thread.",
+ });
+ }
+ if (note.humanNotePromoted) break;
+ yield* mapDispatchError(command)(
+ startNextQueuedRun(command.threadId, { latestRunEnded: true }),
+ );
+ cancelUnsettledEffects = yield* dispatchMessage(
+ {
+ type: "message.dispatch",
+ commandId: command.commandId,
+ threadId: command.threadId,
+ messageId: command.messageId,
+ createdBy: command.createdBy,
+ creationSource: command.creationSource,
+ ...(command.sentBy === undefined ? {} : { sentBy: command.sentBy }),
+ text: note.text,
+ attachments: [],
+ dispatchMode: { type: "queue_after_active" },
+ },
+ events,
+ effects,
+ );
+ const now = yield* DateTime.now;
+ yield* emit(
+ events,
+ command,
+ )({
+ type: "turn-item.updated",
+ threadId: command.threadId,
+ occurredAt: now,
+ payload: { ...note, humanNotePromoted: true, updatedAt: now },
+ });
+ break;
+ }
const guestSend =
command.guestMessageId === undefined
? undefined
@@ -15860,6 +15913,8 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
(planned) =>
planned.events.length > 0 ||
isUnobservedAcknowledgement(command) ||
+ (command.type === "message.dispatch" &&
+ command.dispatchMode.type === "promote_human_note") ||
command.type === "thread.background-work.settle" ||
// A stale visit changes no read state.
command.type === "thread.visit" ||
diff --git a/apps/server/src/orchestration-v2/ThreadSearch.test.ts b/apps/server/src/orchestration-v2/ThreadSearch.test.ts
index 1bcade72198a5..9ef09d848791c 100644
--- a/apps/server/src/orchestration-v2/ThreadSearch.test.ts
+++ b/apps/server/src/orchestration-v2/ThreadSearch.test.ts
@@ -138,7 +138,10 @@ const message = (
readonly createdBy?: "user" | "agent" | "system";
readonly runId?: RunId;
readonly extra?: Partial<
- Pick
+ Pick<
+ ConversationMessage,
+ "sentBy" | "senderThreadId" | "linkedSender" | "creationSource" | "humanNote"
+ >
>;
} = {},
): OrchestrationV2DomainEvent => ({
@@ -298,7 +301,7 @@ it.layer(layerTest)("ThreadSearch", (it) => {
for (const match of ['"needle"', null]) {
const plan = yield* sql<{
readonly detail: string;
- }>`EXPLAIN QUERY PLAN ${ThreadSearch.messageHitsQuery(sql, { match, substrings: "[]", shortSpellings: "[]", projectId: null, excludedThreadIds: "[]", sender: null })}`;
+ }>`EXPLAIN QUERY PLAN ${ThreadSearch.messageHitsQuery(sql, { match, substrings: "[]", shortSpellings: "[]", projectId: null, excludedThreadIds: "[]", sender: null, includeHumanNotes: true })}`;
assert.isFalse(
plan.some((row) => row.detail.includes("TEMP B-TREE")),
plan.map((row) => row.detail).join("\n"),
@@ -1315,6 +1318,9 @@ it.layer(layerTest)("ThreadSearch.searchThreads", (it) => {
thread(messageOnly, project),
// The oldest message, so a cut taken before titles drop would lose it.
message(messageOnly, "petrel-old", "user", "a petrel note", { minute: 1 }),
+ message(messageOnly, "private-note", "user", "synthetic private albatross", {
+ extra: { humanNote: true },
+ }),
...Array.from({ length: 50 }, (_, index) => {
const id = ThreadId.make(`thread:petrel-${index}`);
return [
@@ -1326,6 +1332,8 @@ it.layer(layerTest)("ThreadSearch.searchThreads", (it) => {
projections.apply,
{ discard: true },
);
+ assert.lengthOf((yield* search.search({ query: "albatross" })).matches, 1);
+ assert.deepEqual((yield* search.searchThreads({ query: "albatross" })).matches, []);
const { matches } = yield* search.searchThreads({ query: "petrel", limit: 5 });
assert.include(
matches.map((match) => match.threadId),
diff --git a/apps/server/src/orchestration-v2/ThreadSearch.ts b/apps/server/src/orchestration-v2/ThreadSearch.ts
index 3385454dd2a3f..3be237a987094 100644
--- a/apps/server/src/orchestration-v2/ThreadSearch.ts
+++ b/apps/server/src/orchestration-v2/ThreadSearch.ts
@@ -82,6 +82,7 @@ const SearchRequest = Schema.Struct({
excludedThreadIds: TokenList,
/** Only messages from this sender, or null for anyone's. */
sender: Schema.NullOr(OrchestrationSearchSenderFilter),
+ includeHumanNotes: Schema.Boolean,
});
const SearchRow = Schema.Struct({
messageRowid: Schema.Number,
@@ -167,7 +168,10 @@ function buildMessageSearch(
query: string,
hasIndex: boolean,
bySender: boolean,
-): Omit | null {
+): Omit<
+ typeof SearchRequest.Type,
+ "projectId" | "excludedThreadIds" | "sender" | "includeHumanNotes"
+> | null {
const { long, short } = messageSearchTokens(query);
// With a sender and no words, every one of that sender's newest messages is a hit.
if (long.length === 0 && short.length === 0 && bySender) {
@@ -266,6 +270,7 @@ export const messageHitsQuery = (
projectId,
excludedThreadIds,
sender,
+ includeHumanNotes,
}: typeof SearchRequest.Encoded,
) => sql`
WITH eligible AS MATERIALIZED (
@@ -328,6 +333,7 @@ export const messageHitsQuery = (
-- neither find nor a jump can reach them.
AND messages.message_id NOT LIKE 'async-answer:%'
AND ${messageSenderCondition(sql, sender)}
+ AND (${includeHumanNotes} OR json_extract(messages.payload_json, '$.humanNote') IS NOT 1)
-- Nor can they reach a rolled-back turn, or a message of a stopped turn
-- that no shown item carries, such as a queued prompt that never ran.
AND NOT EXISTS (
@@ -554,6 +560,7 @@ export const make = Effect.gen(function* () {
readonly excludedThreadIds?: ReadonlySet;
/** Off for an agent's search, which has no use for the user's picks. */
readonly picks?: boolean;
+ readonly includeHumanNotes?: boolean;
},
) {
// One message per thread: the best word match, then what the user wrote,
@@ -590,6 +597,7 @@ export const make = Effect.gen(function* () {
projectId: input.projectId,
excludedThreadIds: [...(input.excludedThreadIds ?? [])],
sender: input.sender ?? null,
+ includeHumanNotes: input.includeHumanNotes ?? true,
});
}),
);
@@ -712,6 +720,7 @@ export const make = Effect.gen(function* () {
projectId: input.projectId ?? null,
excludedThreadIds: shown,
picks: false,
+ includeHumanNotes: false,
...(input.sender === undefined ? {} : { sender: input.sender }),
});
const messageHits = matches
diff --git a/apps/web/src/components/ChatView.tsx b/apps/web/src/components/ChatView.tsx
index c66eaafb5ea23..a83f96fbae2d6 100644
--- a/apps/web/src/components/ChatView.tsx
+++ b/apps/web/src/components/ChatView.tsx
@@ -1872,8 +1872,6 @@ export default function ChatView(props: ChatViewProps) {
selectThreadPanelOpen(state.threadPanelVisibilityByThreadKey, activeThreadRef, "inline"),
);
const isStandingBot = activeStanding !== null;
- // A coordinator thread buries the founder under agent relays, so those collapse
- // until he asks for everything. Remembered per thread; ordinary threads stay flat.
const [activityCollapsedThreads, setActivityCollapsedThreads] = useLocalStorage(
"t3code:activity-collapsed-threads",
null,
@@ -2029,6 +2027,22 @@ export default function ChatView(props: ChatViewProps) {
}
};
const sendAppMessageStable = useStableCallback(sendAppMessage);
+ const promoteNoteStable = useStableCallback(async (noteId: MessageId) => {
+ if (!isServerThread || activeThreadId === null) {
+ throw new Error("This thread is unavailable.");
+ }
+ const result = await startThreadTurn({
+ environmentId,
+ input: {
+ threadId: activeThreadId,
+ promoteNoteId: noteId,
+ message: { messageId: newMessageId(), role: "user", text: "", attachments: [] },
+ runtimeMode,
+ interactionMode: serverThread?.interactionMode ?? DEFAULT_INTERACTION_MODE,
+ },
+ });
+ if (result._tag === "Failure") throw squashAtomCommandFailure(result);
+ });
const onCatchUp = useStableCallback(async (marker: ThreadSeenMarker) => {
if (!isServerThread || activeThreadId === null) return false;
const result = await startThreadTurn({
@@ -3519,7 +3533,7 @@ export default function ChatView(props: ChatViewProps) {
standing={activeStanding}
botAvatarState={activeBotAvatarState}
activityCollapsed={
- isStandingBot && activeThreadKey !== null
+ isServerThread && activeThreadKey !== null
? { on: activityCollapsed, onToggle: toggleActivityCollapsed }
: null
}
@@ -3580,7 +3594,11 @@ export default function ChatView(props: ChatViewProps) {
entriesInput={timelineEntriesInput}
draftEntries={isServerThread ? null : draftTimelineEntries}
activeThreadKey={activeThreadKey}
- collapseActivity={isStandingBot && activityCollapsed}
+ collapseActivity={activityCollapsed}
+ includeOtherActivity={isStandingBot}
+ decisionRequestedAt={
+ activeThreadShell?.source.inbox?.decisionRequest?.requestedAt
+ }
sharedThread={activeThreadShell?.source.inbox?.audience === "shared"}
syncing={threadSyncPhase !== null}
detailLoading={threadDetailLoading}
@@ -3648,6 +3666,7 @@ export default function ChatView(props: ChatViewProps) {
onRevertToTurnCount={onRevertTimelineTurnStable}
onUseArtifactTemplate={insertArtifactTemplateStable}
onSendAppMessage={sendAppMessageStable}
+ onPromoteNote={isServerThread && canOperateThread ? promoteNoteStable : undefined}
isRevertingCheckpoint={isRevertingCheckpoint}
onImageExpand={onExpandTimelineImageStable}
onFileOpen={openFileAttachmentStable}
diff --git a/apps/web/src/components/chat/MessagesTimeline.browser.test.tsx b/apps/web/src/components/chat/MessagesTimeline.browser.test.tsx
index 448e6f90a8ed0..4fe4ec46e43f9 100644
--- a/apps/web/src/components/chat/MessagesTimeline.browser.test.tsx
+++ b/apps/web/src/components/chat/MessagesTimeline.browser.test.tsx
@@ -225,6 +225,47 @@ function setup({ scheduledTasks = [] as ReadonlyArray<{ id: string; title: strin
environmentQuery.data = { tasks: scheduledTasks };
}
+it("keeps a model-hidden note visible and only promotes it after an explicit click", async () => {
+ setup();
+ const promote = vi
+ .fn()
+ .mockRejectedValueOnce(new Error("offline"))
+ .mockResolvedValueOnce(undefined);
+ const note = "Keep this between founders for now.";
+ await using screen = await renderTimeline(
+ [
+ message("relay before", { createdBy: "agent" }, "relay-before"),
+ message(note, { humanNote: true }, "note"),
+ message("relay after", { createdBy: "agent" }, "relay-after"),
+ ],
+ { onPromoteNote: promote },
+ );
+
+ expect(screen.text()).toContain("Model-hidden note");
+ expect(screen.text()).toContain(note);
+ const folds = screen.buttons("1 agent update");
+ expect(folds).toHaveLength(2);
+ expect(folds[0]?.getAttribute("aria-expanded")).toBe("false");
+ await click(folds[0]!);
+ expect(folds[0]?.getAttribute("aria-expanded")).toBe("true");
+ expect(screen.text()).toContain("relay before");
+ expect(screen.text()).toContain(note);
+ expect(promote).not.toHaveBeenCalled();
+
+ await click(screen.button("Promote to agent"));
+ await vi.waitFor(() => expect(screen.button("Promote to agent")).toBeEnabled());
+ await click(screen.button("Promote to agent"));
+ await vi.waitFor(() => expect(screen.text()).toContain("Queued for agent"));
+ expect(promote.mock.calls).toEqual([[MessageId.make("note")], [MessageId.make("note")]]);
+ expect(screen.text()).toContain("Model-hidden note");
+ await using remounted = await renderTimeline(
+ [message(note, { humanNote: true, humanNotePromoted: true }, "note")],
+ { onPromoteNote: promote },
+ );
+ expect(remounted.text()).toContain("Promoted to agent");
+ expect(remounted.buttons("Promote to agent")).toHaveLength(0);
+});
+
const TASK_ID = ScheduledTaskId.make("task-1");
const AUTOMATION_PROMPT = "Triage the inbox\n\nLabel every new issue and close duplicates.";
@@ -523,7 +564,7 @@ describe("MessagesTimeline messages", () => {
it("keeps the first and last message headings reachable from either end", async () => {
setup();
- const props = baseProps();
+ const props = { ...baseProps(), collapseActivity: false };
// Folded messages at both ends: their headings must not live inside the fold.
const entries = Array.from({ length: 120 }, (_, index) =>
index === 0
@@ -1430,7 +1471,7 @@ describe("MessagesTimeline agent messages", () => {
"message-linked",
),
],
- { onOpenThread },
+ { onOpenThread, collapseActivity: false },
);
const row = screen.button(/^Agent/);
expect(row.textContent).toContain("Review finished");
diff --git a/apps/web/src/components/chat/MessagesTimeline.logic.test.ts b/apps/web/src/components/chat/MessagesTimeline.logic.test.ts
index 0859a66e9e9b5..248717437a260 100644
--- a/apps/web/src/components/chat/MessagesTimeline.logic.test.ts
+++ b/apps/web/src/components/chat/MessagesTimeline.logic.test.ts
@@ -33,6 +33,7 @@ import {
collapseTimelineActivity,
activityUpdateSummary,
activityPillIdForEntry,
+ timelineActivityContext,
timelineTurnFoldRunIdsByEntryId,
liveAnswerPreview,
deriveMessagesTimelineRowsWithState,
@@ -5252,7 +5253,7 @@ describe("collapsing non-human activity", () => {
...extra,
},
});
- const workRow = (id: string, second: number): MessagesTimelineRow => ({
+ const workRow = (id: string, second: number): Extract => ({
kind: "work",
id,
createdAt: time(second),
@@ -5325,7 +5326,188 @@ describe("collapsing non-human activity", () => {
messageRow("b", 1, { createdBy: "system" }),
messageRow("c", 2, { scheduledTaskId: ScheduledTaskId.make("task-1") }),
]),
- ).toBe("1 agent update and 1 system notice and 1 automation");
+ ).toBe("1 agent update · 1 system notice · 1 automation");
+ });
+
+ it("keeps direct replies, notes, sent messages and founder mentions outside bot runs", () => {
+ const botRun = RunId.make("bot-run");
+ const conversation = [
+ messageRow("prompt", 0, { runId }),
+ messageRow("direct-reply", 1, { runId, role: "assistant" }),
+ messageRow("relay", 2, { runId: botRun, createdBy: "agent" }),
+ messageRow("bot-reply", 3, { runId: botRun, role: "assistant" }),
+ messageRow("note", 4, { humanNote: true, createdBy: "agent" }),
+ messageRow("wake", 5, { runId: botRun, createdBy: "agent" }),
+ { kind: "sent-message", id: "sent", createdAt: time(6), text: "For the founder" } as const,
+ messageRow("mention", 7, { runId: botRun, role: "assistant", text: "@Jeff please review" }),
+ messageRow("next-prompt", 8, person("jeff")),
+ ];
+ const entries = conversation.flatMap((row): TimelineEntry[] =>
+ row.kind === "message" ? [{ ...row, kind: "message" }] : [],
+ );
+ const context = timelineActivityContext(entries, [], false);
+ expect(collapseTimelineActivity(conversation, new Set(), context).map(({ id }) => id)).toEqual([
+ "prompt",
+ "direct-reply",
+ "activity:direct-reply",
+ "note",
+ "activity:note",
+ "sent",
+ "mention",
+ "next-prompt",
+ ]);
+ expect(activityPillIdForEntry(conversation, "note", context)).toBeUndefined();
+ });
+
+ it("opens for newly failed child runs and pending approvals, including grouped items", () => {
+ const event = (
+ id: string,
+ item: Partial,
+ ): Extract => ({
+ kind: "event",
+ id,
+ createdAt: time(4),
+ projectedItem: { item } as OrchestrationV2ProjectedTurnItem,
+ });
+ const child = event("child", { type: "subagent", status: "failed" });
+ const approval = event("approval", { type: "approval_request", status: "pending" });
+ const group = {
+ ...child,
+ subagents: [
+ event("sibling", { type: "subagent", status: "completed" }).projectedItem,
+ child.projectedItem,
+ ],
+ };
+ const folded = collapseTimelineActivity([rows[2]!, group], new Set());
+ const pill = folded[0]!;
+ expect(pill).toMatchObject({ id: "activity:agent-1", expanded: true });
+ if (pill.kind !== "activity" || pill.attention === null)
+ throw new Error("Expected attention pill");
+ const dismissed = new Map([[pill.id, pill.attention]]);
+ expect(
+ collapseTimelineActivity([rows[2]!, group], new Set(), undefined, dismissed),
+ ).toHaveLength(1);
+ expect(
+ collapseTimelineActivity([rows[2]!, group, approval], new Set(), undefined, dismissed).map(
+ ({ id }) => id,
+ ),
+ ).toEqual([pill.id, "agent-1", "child", "approval"]);
+ });
+
+ it("reveals a failed bot run and keeps the reply that raises a founder decision visible", () => {
+ const botRun = RunId.make("bot-decision");
+ const relay = messageRow("relay", 0, { createdBy: "agent", runId: botRun });
+ const reply = messageRow("reply", 2, { role: "assistant", runId: botRun });
+ if (relay.kind !== "message" || reply.kind !== "message") throw new Error("Expected messages");
+ const decision = { ...reply, kind: "message" } as const;
+ const unrelatedRun = RunId.make("unrelated");
+ const unrelatedRelay = messageRow("other-relay", 0, {
+ createdBy: "agent",
+ runId: unrelatedRun,
+ });
+ const unrelatedReply = messageRow("other-reply", 1, { role: "assistant", runId: unrelatedRun });
+ if (unrelatedRelay.kind !== "message" || unrelatedReply.kind !== "message") {
+ throw new Error("Expected messages");
+ }
+ const request = {
+ kind: "event" as const,
+ id: "request",
+ createdAt: time(0),
+ projectedItem: {
+ item: {
+ type: "dynamic_tool",
+ status: "completed",
+ toolName: "t3_thread_update",
+ input: { action: "request_decision" },
+ runId: botRun,
+ startedAt: DateTime.makeUnsafe(time(0)),
+ },
+ } as OrchestrationV2ProjectedTurnItem,
+ };
+ const withInterruption = [relay, unrelatedRelay, request, unrelatedReply, decision];
+ const classified = timelineActivityContext(withInterruption, [], false, time(1));
+ expect([...classified.attentionByRun.keys()]).toEqual([botRun]);
+ expect(
+ collapseTimelineActivity(withInterruption, new Set(), classified).map(({ id }) => id),
+ ).toContain("reply");
+ expect(classified.decisionRuns.has(unrelatedRun)).toBe(false);
+ const entries = [relay, decision];
+ const failed = timelineActivityContext(entries, [{ id: botRun, status: "failed" }], false);
+ expect(collapseTimelineActivity(entries, new Set(), failed)[0]).toMatchObject({
+ expanded: true,
+ });
+
+ const pending = timelineActivityContext(entries, [], false, time(1));
+ expect(collapseTimelineActivity(entries, new Set(), pending).map(({ id }) => id)).toEqual([
+ "activity:relay",
+ "relay",
+ "reply",
+ ]);
+ });
+
+ it("counts unique PR identities and completed children from receipts", () => {
+ const pr = {
+ host: "github.com",
+ repository: "org/repo",
+ number: 4,
+ watchStartedAt: time(3),
+ headSha: null,
+ };
+ const itemId = TurnItemId.make("wake");
+ const threadId = ThreadId.make("thread");
+ const timestamp = DateTime.makeUnsafe(time(4));
+ const notification = {
+ ...workRow("wake", 4),
+ groupedEntries: [
+ {
+ id: "wake",
+ createdAt: time(4),
+ label: "PR update",
+ tone: "info",
+ projectedItem: {
+ position: 4,
+ visibility: "local",
+ sourceThreadId: threadId,
+ sourceItemId: itemId,
+ item: {
+ id: itemId,
+ threadId,
+ runId,
+ nodeId: null,
+ providerThreadId: null,
+ providerTurnId: null,
+ nativeItemRef: null,
+ parentItemId: null,
+ ordinal: 4,
+ title: null,
+ status: "completed",
+ startedAt: timestamp,
+ completedAt: timestamp,
+ updatedAt: timestamp,
+ type: "notification",
+ outcome: "updated",
+ summary: "PR update",
+ source: {
+ kind: "monitor",
+ pullRequest: pr,
+ otherPullRequests: [pr, { ...pr, number: 5 }],
+ },
+ },
+ },
+ },
+ ],
+ } satisfies Extract;
+ const child = {
+ kind: "event",
+ id: "child",
+ createdAt: time(5),
+ projectedItem: {
+ item: { type: "subagent", status: "completed", subagentId: "child" },
+ },
+ } as MessagesTimelineRow;
+ expect(activityUpdateSummary([rows[2]!, notification, child])).toBe(
+ "2 agent updates · 2 PRs · 1 settled",
+ );
});
it("keeps a plan, a render and viewed images on screen", () => {
diff --git a/apps/web/src/components/chat/MessagesTimeline.logic.ts b/apps/web/src/components/chat/MessagesTimeline.logic.ts
index f222edfb84a4c..a9fe0b0c7cef3 100644
--- a/apps/web/src/components/chat/MessagesTimeline.logic.ts
+++ b/apps/web/src/components/chat/MessagesTimeline.logic.ts
@@ -1,6 +1,14 @@
import * as DateTime from "effect/DateTime";
import { worktreeSetupAgentStarted } from "@t3tools/client-runtime/worktree-setup";
import { resolveUserMessagePresentation } from "@t3tools/client-runtime/user-message";
+import {
+ activityItemNeedsAttention,
+ chatActivityContext,
+ chatActivityGroups,
+ isChatActivityMessage,
+ summarizeChatActivity,
+ type ChatActivityContext,
+} from "@t3tools/client-runtime/chat-activity";
import {
isLiveSubagentTurnItem,
waitingOnSubagentsLabel,
@@ -583,6 +591,7 @@ type MessagesTimelineRowContent =
count: number;
summary: string;
expanded: boolean;
+ attention: string | null;
}
| {
kind: "turn-fold";
@@ -634,6 +643,7 @@ type MessagesTimelineRowContent =
groupedWithPrevious?: boolean;
/** Set when the message above is a steer too, so the label shows once. */
continuesSteer?: boolean;
+ activityRevealed?: true;
}
| {
kind: "assistant-meta";
@@ -961,7 +971,10 @@ function timelineEntryIsSteer(entry: TimelineEntry): boolean {
export function timelineEntryStartsResponse(entry: TimelineEntry): boolean {
return (
- (entry.kind === "message" && entry.message.role === "user" && !timelineEntryIsSteer(entry)) ||
+ (entry.kind === "message" &&
+ entry.message.role === "user" &&
+ !entry.message.humanNote &&
+ !timelineEntryIsSteer(entry)) ||
(entry.kind === "work" && entry.entry.itemType === "notification")
);
}
@@ -2413,7 +2426,56 @@ const KEPT_ACTIVITY_ROW_KINDS = new Set([
"viewed-images",
]);
-export function timelineRowIsHumanConversation(row: MessagesTimelineRow): boolean {
+export function timelineActivityContext(
+ entries: ReadonlyArray,
+ runs: Parameters[1],
+ includeOtherActivity: boolean,
+ decisionRequestedAt?: string,
+): ChatActivityContext {
+ return chatActivityContext(
+ entries.map((entry) => ({
+ createdAt: entry.createdAt,
+ runId:
+ entry.kind === "message"
+ ? entry.message.runId
+ : entry.kind === "event"
+ ? entry.projectedItem.item.runId
+ : timelineEntryRunId(entry),
+ message: entry.kind === "message" ? entry.message : undefined,
+ item:
+ entry.kind === "work"
+ ? entry.entry.projectedItem?.item
+ : entry.kind === "event" || entry.kind === "message"
+ ? entry.projectedItem?.item
+ : undefined,
+ })),
+ runs,
+ includeOtherActivity,
+ decisionRequestedAt,
+ );
+}
+
+function activityRowRunIds(row: MessagesTimelineRow): readonly RunId[] {
+ switch (row.kind) {
+ case "message":
+ case "assistant-meta":
+ return row.message.runId ? [row.message.runId] : [];
+ case "work":
+ case "work-live":
+ return row.groupedEntries.flatMap((entry) => (entry.runId ? [entry.runId] : []));
+ case "event":
+ return row.projectedItem.item.runId ? [row.projectedItem.item.runId] : [];
+ case "work-toggle":
+ return row.runId ? [row.runId] : [];
+ case "turn-fold":
+ case "attempt-fold":
+ return [row.runId];
+ default:
+ return [];
+ }
+}
+
+function activityRowIsBoundary(row: MessagesTimelineRow, context?: ChatActivityContext): boolean {
if (KEPT_ACTIVITY_ROW_KINDS.has(row.kind)) return true;
// A secret or a link is answered only on its own card, so it must not fold away.
if (
@@ -2423,60 +2485,31 @@ export function timelineRowIsHumanConversation(row: MessagesTimelineRow): boolea
) {
return true;
}
- if (row.kind !== "message" && row.kind !== "assistant-meta") return false;
- const sender = resolveMessageSender(row.message);
- return sender.kind === "person" || sender.kind === "guest" || sender.kind === "model";
-}
-
-/**
- * The pill's key. Anchored to the human message the run sits after, or to the
- * first row when the thread opens on activity, so the key survives rows
- * streaming in and earlier history loading above it. A live turn's own rows use
- * constant ids that vanish when the turn settles, so they never anchor a pill.
- */
-function activityPillId(anchor: MessagesTimelineRow | undefined, run: MessagesTimelineRow[]): string {
- return `activity:${anchor?.id ?? run[0]!.id}`;
+ if (row.kind === "message" || row.kind === "assistant-meta") {
+ return !isChatActivityMessage(row.message, row.message.runId, context);
+ }
+ if (row.kind === "working" || row.kind === "thinking" || row.kind === "worktree-setup")
+ return true;
+ if (context === undefined || context.includeOtherActivity) return false;
+ const runIds = activityRowRunIds(row);
+ return runIds.length === 0 || runIds.some((runId) => !context.agentRuns.has(runId));
}
-/**
- * The short word for one kind of collapsed activity, pluralized with a count.
- * Kinds the row does not record stay "update".
- */
-function activityUpdateWord(row: MessagesTimelineRow): string {
- if (row.kind !== "message" && row.kind !== "assistant-meta") return "update";
- switch (resolveMessageSender(row.message).kind) {
- case "agent":
- return "agent update";
- case "automation":
- return "automation";
- case "system":
- return "system notice";
- default:
- return "update";
+function activityRowItems(row: MessagesTimelineRow) {
+ if (row.kind === "work" || row.kind === "work-live") {
+ return row.groupedEntries.flatMap(({ projectedItem }) =>
+ projectedItem ? [projectedItem.item] : [],
+ );
}
+ return row.kind === "event" ? (row.subagents ?? [row.projectedItem]).map(({ item }) => item) : [];
}
-/** `14 agent updates`, `3 automations and 1 system notice`. */
export function activityUpdateSummary(rows: ReadonlyArray): string {
- const counts = new Map();
- const order: string[] = [];
- for (const row of rows) {
- if (row.kind !== "message" && row.kind !== "assistant-meta") continue;
- const word = activityUpdateWord(row);
- if (!counts.has(word)) order.push(word);
- counts.set(word, (counts.get(word) ?? 0) + 1);
- }
- if (order.length === 0) {
- return rows.length === 1 ? "1 update" : `${rows.length} updates`;
- }
- return order
- .map((word) => {
- const count = counts.get(word) ?? 0;
- const plural =
- word === "automation" ? (count === 1 ? "automation" : "automations") : `${word}s`;
- return `${count} ${count === 1 ? word : plural}`;
- })
- .join(" and ");
+ return summarizeChatActivity(
+ rows.length,
+ rows.flatMap((row) => (row.kind === "message" ? [row.message] : [])),
+ rows.flatMap(activityRowItems),
+ );
}
/**
@@ -2487,58 +2520,74 @@ export function activityUpdateSummary(rows: ReadonlyArray):
export function collapseTimelineActivity(
rows: MessagesTimelineRow[],
expandedIds: ReadonlySet,
+ context?: ChatActivityContext,
+ dismissedAttention?: ReadonlyMap,
): MessagesTimelineRow[] {
const collapsed: MessagesTimelineRow[] = [];
- let run: MessagesTimelineRow[] = [];
- let anchor: MessagesTimelineRow | undefined;
- const flush = () => {
- if (run.length === 0) return;
- const id = activityPillId(anchor, run);
+ let hasActivity = false;
+ for (const group of chatActivityGroups(rows, (row) => activityRowIsBoundary(row, context))) {
+ if (!("rows" in group)) {
+ collapsed.push(group);
+ continue;
+ }
+ hasActivity = true;
+ const { id, rows: run } = group;
+ const attentionIds = new Set();
+ for (const row of run) {
+ for (const runId of activityRowRunIds(row)) {
+ for (const key of context?.attentionByRun.get(runId) ?? []) attentionIds.add(key);
+ }
+ if (
+ (row.kind === "work-toggle" && row.hasFailure) ||
+ (row.kind === "context-compaction" && row.failed) ||
+ (row.kind === "event" &&
+ (row.subagents ?? [row.projectedItem]).some(({ item }) =>
+ activityItemNeedsAttention(item),
+ )) ||
+ ((row.kind === "work" || row.kind === "work-live") &&
+ row.groupedEntries.some((entry) =>
+ entry.projectedItem
+ ? activityItemNeedsAttention(entry.projectedItem.item)
+ : entry.tone === "error",
+ ))
+ )
+ attentionIds.add(row.id);
+ }
+ const attention = attentionIds.size ? JSON.stringify([...attentionIds].sort()) : null;
const pill: MessagesTimelineRow = {
kind: "activity",
id,
createdAt: run[0]!.createdAt,
count: run.length,
summary: activityUpdateSummary(run),
- expanded: expandedIds.has(id),
+ expanded:
+ expandedIds.has(id) || (attention !== null && dismissedAttention?.get(id) !== attention),
+ attention,
};
collapsed.push(pill);
- if (pill.expanded) for (const row of run) collapsed.push(row);
- run = [];
- };
- for (const row of rows) {
- if (timelineRowIsHumanConversation(row)) {
- flush();
- collapsed.push(row);
- anchor = row;
- } else {
- run.push(row);
+ if (pill.expanded) {
+ for (const row of run) {
+ collapsed.push(
+ row.kind === "message" && resolveMessageSender(row.message).kind === "agent"
+ ? { ...row, activityRevealed: true }
+ : row,
+ );
+ }
}
}
- flush();
- return collapsed;
+ return hasActivity ? collapsed : rows;
}
/** The pill hiding `entryId`, if one does, so a search hit or a restored scroll position can open it. */
export function activityPillIdForEntry(
rows: MessagesTimelineRow[],
entryId: string,
+ context?: ChatActivityContext,
): string | undefined {
- let anchor: MessagesTimelineRow | undefined;
- let run: MessagesTimelineRow[] = [];
- const match = (): string | undefined =>
- run.some((row) => row.id === entryId) ? activityPillId(anchor, run) : undefined;
- for (const row of rows) {
- if (timelineRowIsHumanConversation(row)) {
- const found = match();
- if (found !== undefined) return found;
- run = [];
- anchor = row;
- } else {
- run.push(row);
- }
+ for (const group of chatActivityGroups(rows, (row) => activityRowIsBoundary(row, context))) {
+ if ("rows" in group && group.rows.some((row) => row.id === entryId)) return group.id;
}
- return match();
+ return undefined;
}
export function filterTimelineRowsBySender(
@@ -2562,6 +2611,7 @@ function timelineRowIsOwnUserMessage(
return (
row?.kind === "message" &&
row.message.role === "user" &&
+ !row.message.humanNote &&
resolveUserMessagePresentation(row.message).attribution === null
);
}
diff --git a/apps/web/src/components/chat/MessagesTimeline.tsx b/apps/web/src/components/chat/MessagesTimeline.tsx
index 48ef5a93f798e..366ca5ebce163 100644
--- a/apps/web/src/components/chat/MessagesTimeline.tsx
+++ b/apps/web/src/components/chat/MessagesTimeline.tsx
@@ -97,6 +97,7 @@ import {
liveAnswerPreview,
collapseTimelineActivity,
activityPillIdForEntry,
+ timelineActivityContext,
type MessagesTimelineRow,
type TimelineLatestRun,
} from "./MessagesTimeline.logic";
@@ -308,6 +309,7 @@ interface MessagesTimelineProps {
onRevertToTurnCount: (targetTurnCount: number, messageId: MessageId) => void;
onUseArtifactTemplate?: (template: CodexArtifactTemplate) => void;
onSendAppMessage?: (text: string) => Promise;
+ onPromoteNote?: ((noteId: MessageId) => Promise) | undefined;
onRunShellCommand?: (command: string) => void;
isRevertingCheckpoint: boolean;
onImageExpand: (preview: ExpandedImagePreview) => void;
@@ -319,7 +321,9 @@ interface MessagesTimelineProps {
timestampFormat: TimestampFormat;
workspaceRoot: string | undefined;
skills?: ReadonlyArray;
- runs: ReadonlyArray;
+ runs: ReadonlyArray<
+ HandoffTimelineRun & { status?: import("@t3tools/contracts").OrchestrationV2Run["status"] }
+ >;
anchorMessageId: MessageId | null;
onAnchorReady: (messageId: MessageId, anchorIndex: number) => void;
onAnchorSizeChanged: (messageId: MessageId, size: number) => void;
@@ -348,6 +352,8 @@ interface MessagesTimelineProps {
* Off by default; a standing thread turns it on.
*/
collapseActivity?: boolean;
+ includeOtherActivity?: boolean;
+ decisionRequestedAt?: string | undefined;
/** Person messages name which founder sent them. */
sharedThread?: boolean;
}
@@ -397,7 +403,9 @@ const ConversationTimeline = memo(function ConversationTimeline({
activeFindMatch = null,
findNavigationId = 0,
findSender = null,
- collapseActivity = false,
+ collapseActivity = true,
+ includeOtherActivity = false,
+ decisionRequestedAt,
sharedThread = false,
latestRun,
announcedRun = null,
@@ -421,6 +429,7 @@ const ConversationTimeline = memo(function ConversationTimeline({
onRevertToTurnCount,
onUseArtifactTemplate = NOOP_USE_ARTIFACT_TEMPLATE,
onSendAppMessage,
+ onPromoteNote,
onRunShellCommand,
isRevertingCheckpoint,
onImageExpand,
@@ -616,16 +625,19 @@ const ConversationTimeline = memo(function ConversationTimeline({
};
// Turn and attempt folds reveal later rows rather than growing their own row.
- const onToggleActivity = (id: string) => {
- preserveDisclosurePosition(id);
+ const onToggleActivity = (row: Extract) => {
+ preserveDisclosurePosition(row.id);
setExpandedActivity((existing) => {
const ids = new Set(existing.threadKey === listIdentityKey ? existing.ids : []);
- if (ids.has(id)) {
- ids.delete(id);
+ const dismissed = new Map(existing.threadKey === listIdentityKey ? existing.dismissed : []);
+ if (row.expanded) {
+ ids.delete(row.id);
+ if (row.attention !== null) dismissed.set(row.id, row.attention);
} else {
- ids.add(id);
+ ids.add(row.id);
+ dismissed.delete(row.id);
}
- return { threadKey: listIdentityKey, ids };
+ return { threadKey: listIdentityKey, ids, dismissed };
});
};
const onToggleTurnFold = (runId: RunId) => {
@@ -832,27 +844,36 @@ const ConversationTimeline = memo(function ConversationTimeline({
// A sender filter already removed every other message, so collapsing what it
// kept would hide the very rows it was asked to show.
const collapseRows = collapseActivity && findSender === null;
+ const chatter = collapseRows
+ ? timelineActivityContext(timelineEntries, runsProp, includeOtherActivity, decisionRequestedAt)
+ : undefined;
const [expandedActivity, setExpandedActivity] = useState<{
readonly threadKey: string;
readonly ids: ReadonlySet;
- }>(() => ({ threadKey: listIdentityKey, ids: new Set() }));
+ readonly dismissed: ReadonlyMap;
+ }>(() => ({ threadKey: listIdentityKey, ids: new Set(), dismissed: new Map() }));
// Pill ids repeat across threads (`activity:` plus a message id can coincide,
// and a live turn's rows share constant ids), so expansion belongs to one thread.
const expandedActivityIds =
expandedActivity.threadKey === listIdentityKey ? expandedActivity.ids : new Set();
if (collapseRows && expandedActivity.threadKey !== listIdentityKey) {
- setExpandedActivity({ threadKey: listIdentityKey, ids: expandedActivityIds });
+ setExpandedActivity({
+ threadKey: listIdentityKey,
+ ids: expandedActivityIds,
+ dismissed: new Map(),
+ });
}
// A search hit or a restored scroll position inside a collapsed run opens that
// run, the way a find match opens the turn fold that hides it.
const revealedEntryId =
(findActive ? activeFindMatch?.entryId : undefined) ??
+ revealedMessageId ??
(restoringThreadPosition && rememberedPosition?.atEnd === false
? rememberedPosition.rowId
: undefined);
const revealedPillId =
collapseRows && revealedEntryId !== undefined
- ? activityPillIdForEntry(senderRows, revealedEntryId)
+ ? activityPillIdForEntry(senderRows, revealedEntryId, chatter)
: undefined;
if (
revealedPillId !== undefined &&
@@ -861,9 +882,16 @@ const ConversationTimeline = memo(function ConversationTimeline({
) {
const ids = new Set(expandedActivity.ids);
ids.add(revealedPillId);
- setExpandedActivity({ threadKey: listIdentityKey, ids });
+ setExpandedActivity({ ...expandedActivity, ids });
}
- const rows = collapseRows ? collapseTimelineActivity(senderRows, expandedActivityIds) : senderRows;
+ const rows = collapseRows
+ ? collapseTimelineActivity(
+ senderRows,
+ expandedActivityIds,
+ chatter,
+ expandedActivity.threadKey === listIdentityKey ? expandedActivity.dismissed : undefined,
+ )
+ : senderRows;
const matchedApprovalRequestIds = new Set();
for (const row of pendingApprovalRequestIds.size > 0 ? rows : []) {
const entries =
@@ -1231,6 +1259,7 @@ const ConversationTimeline = memo(function ConversationTimeline({
onFileOpen,
onUseArtifactTemplate,
onSendAppMessage,
+ onPromoteNote,
onAppFullscreenChange,
onFileDownload,
openPullRequest,
@@ -1939,18 +1968,17 @@ function ActivityTimelineRow({ row }: { row: Extract ctx.onToggleActivity(row.id)}
- className="flex cursor-pointer select-none items-center gap-1 rounded-md px-1 text-sm leading-relaxed text-muted-foreground tabular-nums transition-colors hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring/70"
+ onClick={() => ctx.onToggleActivity(row)}
+ className="flex max-w-full cursor-pointer select-none items-center gap-1 rounded-md border border-border/60 bg-muted/40 px-1.5 text-xs leading-relaxed text-muted-foreground tabular-nums transition-colors hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring/70"
>
-
- {row.summary}
- {row.expanded ? "" : " · click to expand"}
-
- {row.expanded ? (
-
- ) : (
-
- )}
+
+ {row.summary}
);
diff --git a/apps/web/src/components/chat/TimelineUserMessageRow.tsx b/apps/web/src/components/chat/TimelineUserMessageRow.tsx
index 8df66f770a8cd..f3841746242e2 100644
--- a/apps/web/src/components/chat/TimelineUserMessageRow.tsx
+++ b/apps/web/src/components/chat/TimelineUserMessageRow.tsx
@@ -37,6 +37,7 @@ import ChatMarkdown from "../ChatMarkdown";
import {
CalendarClockIcon,
ChevronDownIcon,
+ EyeOffIcon,
DownloadIcon,
EyeIcon,
type LucideIcon,
@@ -46,6 +47,8 @@ import {
LinkIcon,
} from "lucide-react";
import { Button, InlineButton } from "../ui/button";
+import { Badge } from "../ui/badge";
+import { toastManager } from "../ui/toast";
import { FreshSessionRow, ModelSwitchRow } from "./V2LifecycleRow";
import { useAssetUrlRefresh, useAssetUrls, useAssetUrlState } from "../../assets/assetUrls";
import { AttachmentImage } from "../media/AttachmentImage";
@@ -271,6 +274,8 @@ export function UserMessageRow({ row }: { row: Extract }) {
const ctx = use(TimelineRowCtx);
+ if (row.message.humanNote)
+ return ;
return ctx.workflowOpening?.messageId === row.message.id ? (
}) {
+ const { onPromoteNote } = use(TimelineRowCtx);
+ const [status, setStatus] = useState<"idle" | "sending" | "sent">("idle");
+ const promoted = row.message.humanNotePromoted || status === "sent";
+ return (
+
+
+
+ Model-hidden note
+
+ {onPromoteNote && !promoted && row.projectedItem?.visibility !== "inherited" ? (
+ {
+ setStatus("sending");
+ try {
+ await onPromoteNote(row.message.id);
+ setStatus("sent");
+ toastManager.add({ type: "success", title: "Note queued for the agent" });
+ } catch {
+ setStatus("idle");
+ toastManager.add({ type: "error", title: "Could not promote the note" });
+ }
+ }}
+ >
+ {status === "sending" ? "Sending…" : "Promote to agent"}
+
+ ) : null}
+ {promoted ? (
+
+ {row.message.humanNotePromoted ? "Promoted to agent" : "Queued for agent"}
+
+ ) : null}
+
+ );
+}
+
/** Automation prompts are long, repeated runbooks; a folded bubble keeps them out of the way. */
function AutomationMessageRow({ row }: { row: Extract }) {
const ctx = use(TimelineRowCtx);
@@ -481,8 +527,8 @@ function UserTimelineRow({
const showSender = sender.kind === "person" && !row.groupedWithPrevious && !unsent;
const personHeading = sender.kind === "person" && !unsent ? messageSenderLabel(sender) : "You";
// Messages from other agents fold to one line so the user's own messages stay easy to find.
- const folded = userMessage.attribution === "agent";
- const [expanded, setExpanded] = useState(false);
+ const folded = !row.message.humanNote && userMessage.attribution === "agent";
+ const [expanded, setExpanded] = useState(row.activityRevealed === true);
const revealFoldRef = findRevealRef(() => setExpanded(true));
const senderShell = useQuietThreadShell(folded ? senderRef : null);
const senderLabel =
@@ -870,11 +916,6 @@ function UserTimelineRow({
Sent by T3 Code
) : null}
- {row.message.humanNote ? (
-
- Note
-
- ) : null}
{showSender ? (
{sharedThread && sender.kind === "person" && sender.sentBy?.founder != null ? (
@@ -911,14 +952,17 @@ function UserTimelineRow({
(mediaAboveText || row.groupedWithPrevious) && "rounded-tr-md",
row.groupedWithNext && "rounded-br-md",
BUBBLE_CHIP_CLASS_NAME,
- userMessage.attribution === "guest"
- ? guestBubbleClassName(false)
- : !mediaOnly && !fileCardsOnly && !audioOnly && "bg-message",
+ row.message.humanNote
+ ? "border border-warning/20 bg-warning/8 text-foreground"
+ : userMessage.attribution === "guest"
+ ? guestBubbleClassName(false)
+ : !mediaOnly && !fileCardsOnly && !audioOnly && "bg-message",
!folded && !mediaOnly && !fileCardsOnly && !audioOnly && "p-3",
folded && expanded && "w-full",
)}
data-user-message-bubble=""
>
+ {row.message.humanNote ? : null}
{/* Outside the fold so a collapsed message still has a heading to navigate to. */}
{mediaAboveText ? null : (
@@ -1062,7 +1106,7 @@ function UserTimelineRow({
renderContextReference={renderContextReference}
skills={ctx.skills}
markdownCwd={ctx.markdownCwd}
- collapsible={!folded}
+ collapsible={!folded && !row.message.humanNote}
/>
)}
diff --git a/apps/web/src/components/chat/timelineRowContext.ts b/apps/web/src/components/chat/timelineRowContext.ts
index 6c70c66248087..5d54c8abc7cf6 100644
--- a/apps/web/src/components/chat/timelineRowContext.ts
+++ b/apps/web/src/components/chat/timelineRowContext.ts
@@ -68,6 +68,7 @@ export interface TimelineRowSharedState {
onRevertToTurnCount: (targetTurnCount: number, messageId: MessageId) => void;
onUseArtifactTemplate: (template: CodexArtifactTemplate) => void;
onSendAppMessage: ((text: string) => Promise) | undefined;
+ onPromoteNote: ((noteId: MessageId) => Promise) | undefined;
onAppFullscreenChange: (rowId: string, fullscreen: boolean) => void;
onRunShellCommand: ((command: string) => void) | undefined;
findActive: boolean;
@@ -93,7 +94,7 @@ export interface TimelineRowSharedState {
| ((input: { readonly sourceThreadId: ThreadId; readonly runId: RunId }) => Promise)
| undefined;
onToggleTurnFold: (runId: RunId) => void;
- onToggleActivity: (id: string) => void;
+ onToggleActivity: (row: Extract) => void;
onToggleAttemptFold: (attemptId: RunAttemptId) => void;
onFileOpen: (attachment: ChatFileAttachment) => void;
onFileDownload: (attachment: ChatFileAttachment) => void;
diff --git a/apps/web/src/session-logic.ts b/apps/web/src/session-logic.ts
index 84bf275151774..259ccc26b25be 100644
--- a/apps/web/src/session-logic.ts
+++ b/apps/web/src/session-logic.ts
@@ -610,6 +610,7 @@ export function deriveTimelineEntriesFromVisibleTurnItems(
...(item.sentBy !== undefined ? { sentBy: item.sentBy } : {}),
...(item.idleCompaction !== undefined ? { idleCompaction: item.idleCompaction } : {}),
...(item.humanNote === true ? { humanNote: true as const } : {}),
+ ...(item.humanNotePromoted ? { humanNotePromoted: true as const } : {}),
...(item.scheduledTaskId !== undefined
? { scheduledTaskId: item.scheduledTaskId }
: {}),
diff --git a/apps/web/src/types.ts b/apps/web/src/types.ts
index 7d6cf452890d6..5b6d579ca505d 100644
--- a/apps/web/src/types.ts
+++ b/apps/web/src/types.ts
@@ -90,6 +90,7 @@ export interface ChatMessage {
readonly idleCompaction?: import("@t3tools/contracts").OrchestrationV2IdleCompaction;
/** A side note between founders. The bot never sees it. */
readonly humanNote?: true;
+ readonly humanNotePromoted?: true;
readonly createdAt: string;
readonly updatedAt: string;
readonly inputIntent?: OrchestrationV2UserMessageInputIntent | undefined;
diff --git a/packages/client-runtime/package.json b/packages/client-runtime/package.json
index af9547b8306eb..0097828b75766 100644
--- a/packages/client-runtime/package.json
+++ b/packages/client-runtime/package.json
@@ -79,6 +79,10 @@
"types": "./src/userMessage.ts",
"default": "./src/userMessage.ts"
},
+ "./chat-activity": {
+ "types": "./src/chatActivity.ts",
+ "default": "./src/chatActivity.ts"
+ },
"./message-sender": {
"types": "./src/messageSender.ts",
"default": "./src/messageSender.ts"
diff --git a/packages/client-runtime/src/chatActivity.ts b/packages/client-runtime/src/chatActivity.ts
new file mode 100644
index 0000000000000..77f3e32ba6eb9
--- /dev/null
+++ b/packages/client-runtime/src/chatActivity.ts
@@ -0,0 +1,204 @@
+import * as DateTime from "effect/DateTime";
+import {
+ mentionedFounders,
+ type OrchestrationV2RunStatus,
+ type OrchestrationV2TurnItem,
+ type RunId,
+} from "@t3tools/contracts";
+import { resolveT3McpToolId } from "@t3tools/shared/t3McpToolPresentation";
+import { resolveMessageSender, type MessageSenderInput } from "./messageSender.ts";
+
+type ActivityMessage = MessageSenderInput & { readonly humanNote?: true };
+
+export interface ChatActivityEntry {
+ readonly createdAt: string;
+ readonly runId: RunId | null;
+ readonly message?: ActivityMessage | undefined;
+ readonly item?: OrchestrationV2TurnItem | undefined;
+}
+
+function isDecisionRequestItem(
+ item: OrchestrationV2TurnItem | undefined,
+): item is Extract {
+ return (
+ item?.type === "dynamic_tool" &&
+ item.status === "completed" &&
+ resolveT3McpToolId(item.toolName) === "t3_thread_update" &&
+ typeof item.input === "object" &&
+ item.input !== null &&
+ "action" in item.input &&
+ item.input.action === "request_decision"
+ );
+}
+
+export function activityItemNeedsAttention(item: OrchestrationV2TurnItem): boolean {
+ return (
+ item.status === "failed" ||
+ item.type === "error" ||
+ (item.type === "notification" &&
+ (item.outcome === "failed" ||
+ (item.source.kind === "monitor" &&
+ [item.source.pullRequest, ...(item.source.otherPullRequests ?? [])].some(
+ (pr) => pr?.section?.outcome === "failed",
+ )))) ||
+ ((item.type === "approval_request" || item.type === "user_input_request") &&
+ (item.status === "pending" || item.status === "waiting"))
+ );
+}
+
+export function chatActivityContext(
+ entries: Iterable,
+ runs: ReadonlyArray<{ id: RunId; status?: OrchestrationV2RunStatus }>,
+ includeOtherActivity: boolean,
+ decisionRequestedAt?: string,
+) {
+ const agentRuns = new Set();
+ const directRuns = new Set();
+ const decisionRuns = new Set();
+ const attentionByRun = new Map>();
+ const addAttention = (runId: RunId, id: string) => {
+ const ids = attentionByRun.get(runId);
+ if (ids) ids.add(id);
+ else attentionByRun.set(runId, new Set([id]));
+ };
+ let firstReplyAfterDecision: RunId | undefined;
+ let pendingDecision: { runId: RunId; startedAt: string } | undefined;
+ for (const { createdAt, runId, message, item } of entries) {
+ if (!runId) continue;
+ if (message?.role === "user" && !message.humanNote) {
+ const sender = resolveMessageSender(message);
+ if (
+ sender.kind === "agent" ||
+ (includeOtherActivity && sender.kind !== "person" && sender.kind !== "guest")
+ ) {
+ agentRuns.add(runId);
+ } else {
+ directRuns.add(runId);
+ }
+ }
+ if (item?.type === "notification") agentRuns.add(runId);
+ if (item && activityItemNeedsAttention(item)) addAttention(runId, item.id);
+ if (isDecisionRequestItem(item)) {
+ decisionRuns.add(runId);
+ const startedAt = item.startedAt === null ? createdAt : DateTime.formatIso(item.startedAt);
+ if (
+ decisionRequestedAt &&
+ startedAt <= decisionRequestedAt &&
+ (pendingDecision === undefined || startedAt >= pendingDecision.startedAt)
+ ) {
+ pendingDecision = { runId, startedAt };
+ }
+ }
+ if (decisionRequestedAt && message?.role === "assistant" && createdAt >= decisionRequestedAt) {
+ firstReplyAfterDecision ??= runId;
+ }
+ }
+ if (decisionRequestedAt) {
+ const runId = pendingDecision?.runId ?? firstReplyAfterDecision;
+ if (runId) {
+ decisionRuns.add(runId);
+ addAttention(runId, decisionRequestedAt);
+ }
+ }
+ for (const id of directRuns) agentRuns.delete(id);
+ for (const run of runs) {
+ if (run.status === "failed") addAttention(run.id, run.id);
+ }
+ return { agentRuns, decisionRuns, attentionByRun, includeOtherActivity };
+}
+
+export type ChatActivityContext = ReturnType;
+
+export function isChatActivityMessage(
+ message: ActivityMessage,
+ runId: RunId | null,
+ context: ChatActivityContext | undefined,
+): boolean {
+ if (message.humanNote) return false;
+ const sender = resolveMessageSender(message);
+ switch (sender.kind) {
+ case "person":
+ case "guest":
+ return false;
+ case "agent":
+ return mentionedFounders(message.text).length === 0;
+ case "model":
+ return (
+ !!runId &&
+ context?.agentRuns.has(runId) === true &&
+ !context.decisionRuns.has(runId) &&
+ mentionedFounders(message.text).length === 0
+ );
+ default:
+ return context?.includeOtherActivity !== false;
+ }
+}
+
+export function settledChatActivityTaskIds(item: OrchestrationV2TurnItem): readonly string[] {
+ if (item.type === "subagent" && item.status === "completed") return [item.subagentId];
+ if (
+ item.type === "notification" &&
+ item.source.kind === "delegated_task" &&
+ item.outcome === "completed"
+ )
+ return item.source.taskIds;
+ return [];
+}
+
+export function summarizeChatActivity(
+ rowCount: number,
+ messages: Iterable,
+ items: Iterable,
+ representedSettlements: Iterable = [],
+): string {
+ const counts = new Map();
+ const pullRequests = new Set();
+ const settledTasks = new Set(representedSettlements);
+ const count = (word: string) => counts.set(word, (counts.get(word) ?? 0) + 1);
+ for (const message of messages) {
+ const sender = resolveMessageSender(message);
+ if (sender.kind === "agent") count("agent update");
+ if (sender.kind === "automation") count("automation");
+ if (sender.kind === "system") count("system notice");
+ for (const match of message.text.matchAll(
+ /https?:\/\/github\.com\/([\w.-]+\/[\w.-]+)\/pull\/(\d+)\b/gi,
+ )) {
+ pullRequests.add(`github.com/${match[1]!.toLowerCase()}#${match[2]}`);
+ }
+ }
+ for (const item of items) {
+ for (const id of settledChatActivityTaskIds(item)) settledTasks.add(id);
+ if (item.type !== "notification") continue;
+ if (item.source.kind !== "system") count("agent update");
+ if (item.source.kind === "monitor") {
+ for (const pr of [item.source.pullRequest, ...(item.source.otherPullRequests ?? [])]) {
+ if (pr) pullRequests.add(`${pr.host}/${pr.repository.toLowerCase()}#${pr.number}`);
+ }
+ }
+ }
+ const parts = Array.from(counts, ([word, total]) => `${total} ${word}${total === 1 ? "" : "s"}`);
+ if (parts.length === 0) parts.push(`${rowCount} ${rowCount === 1 ? "update" : "updates"}`);
+ if (pullRequests.size)
+ parts.push(`${pullRequests.size} ${pullRequests.size === 1 ? "PR" : "PRs"}`);
+ if (settledTasks.size) parts.push(`${settledTasks.size} settled`);
+ return parts.join(" · ");
+}
+
+export function* chatActivityGroups(
+ rows: ReadonlyArray,
+ isBoundary: (row: Row) => boolean,
+) {
+ let anchor: Row | undefined;
+ let group: Row[] = [];
+ for (const row of rows) {
+ if (!isBoundary(row)) {
+ group.push(row);
+ continue;
+ }
+ if (group.length) yield { id: `activity:${anchor?.id ?? group[0]!.id}`, rows: group };
+ yield row;
+ anchor = row;
+ group = [];
+ }
+ if (group.length) yield { id: `activity:${anchor?.id ?? group[0]!.id}`, rows: group };
+}
diff --git a/packages/client-runtime/src/operations/commands.ts b/packages/client-runtime/src/operations/commands.ts
index 59ab217f56acc..50c89dd2a96cc 100644
--- a/packages/client-runtime/src/operations/commands.ts
+++ b/packages/client-runtime/src/operations/commands.ts
@@ -191,6 +191,7 @@ interface StartThreadBootstrap {
export interface StartThreadTurnInput extends ThreadCommandInput {
readonly manualContinuationOfRunId?: RunId;
+ readonly promoteNoteId?: MessageId;
readonly message: {
readonly messageId: MessageId;
readonly role: "user";
@@ -784,6 +785,22 @@ export const startThreadTurn = Effect.fn("EnvironmentCommands.startThreadTurn")(
input: StartThreadTurnInput,
) {
const commandId = yield* allocateCommandId(input);
+ if (input.promoteNoteId !== undefined) {
+ return yield* dispatchMessage(
+ {
+ type: "message.dispatch",
+ commandId,
+ createdBy: "user",
+ creationSource: input.creationSource ?? "web",
+ threadId: input.threadId,
+ messageId: input.message.messageId,
+ text: "",
+ attachments: [],
+ dispatchMode: { type: "promote_human_note", noteId: input.promoteNoteId },
+ },
+ input.resendAfterSocketLoss ?? true,
+ );
+ }
const attachments = yield* persistAttachments(
input.threadId,
input.message.messageId,
diff --git a/packages/contracts/src/orchestrationV2.ts b/packages/contracts/src/orchestrationV2.ts
index ebdb131d631bf..146acd972b780 100644
--- a/packages/contracts/src/orchestrationV2.ts
+++ b/packages/contracts/src/orchestrationV2.ts
@@ -1914,6 +1914,7 @@ export const OrchestrationV2TurnItem = Schema.Union([
sentBy: Schema.optional(OrchestrationV2MessageSentBy),
idleCompaction: Schema.optional(OrchestrationV2IdleCompaction),
humanNote: Schema.optional(Schema.Literal(true)),
+ humanNotePromoted: Schema.optional(Schema.Literal(true)),
workflowScript: OrchestrationV2ConversationMessage.fields.workflowScript,
freshContext: OrchestrationV2Run.fields.freshContext,
inputIntent: OrchestrationV2UserMessageInputIntent,
@@ -2852,6 +2853,7 @@ export const OrchestrationV2TurnItemJson = Schema.Union([
sentBy: Schema.optional(OrchestrationV2MessageSentBy),
idleCompaction: Schema.optional(OrchestrationV2IdleCompaction),
humanNote: Schema.optional(Schema.Literal(true)),
+ humanNotePromoted: Schema.optional(Schema.Literal(true)),
workflowScript: OrchestrationV2ConversationMessage.fields.workflowScript,
freshContext: OrchestrationV2Run.fields.freshContext,
inputIntent: OrchestrationV2UserMessageInputIntent,
@@ -3671,6 +3673,7 @@ export const OrchestrationV2Command = Schema.Union([
Schema.Struct({ type: Schema.Literal("restart_active"), targetRunId: RunId }),
Schema.Struct({ type: Schema.Literal("queue_after_active") }),
Schema.Struct({ type: Schema.Literal("start_immediately") }),
+ Schema.Struct({ type: Schema.Literal("promote_human_note"), noteId: MessageId }),
]),
}),
Schema.Struct({
diff --git a/packages/provider-core/src/server/handoffBudget.ts b/packages/provider-core/src/server/handoffBudget.ts
index 18bd5fb1fd284..133c919bf5f15 100644
--- a/packages/provider-core/src/server/handoffBudget.ts
+++ b/packages/provider-core/src/server/handoffBudget.ts
@@ -137,6 +137,9 @@ export function historicalMessage(
let text: string;
switch (item.type) {
case "user_message":
+ if (item.humanNote) return null;
+ text = item.text;
+ break;
case "assistant_message":
text = item.text;
break;