Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
576 changes: 576 additions & 0 deletions apps/server/src/orchestration-v2/Adapters/AcpReplyPhase.test.ts

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions apps/web/src/components/chat/MessagesTimeline.logic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
} from "@t3tools/client-runtime/user-message";
import type { HandoffTimelineRun } from "@t3tools/client-runtime/handoff";
import type { LampTranscriptRow } from "../lamp/lampTranscript.logic";
import { addForkRetainedAssistantReplyEntryIds } from "./retainedAssistantReplies.logic";
import { renderCodexDirectivesForCopy } from "~/markdown/markdownText";
import {
commandDisplayText,
Expand Down Expand Up @@ -844,6 +845,7 @@ function retainedAssistantReplyEntryIds(
replyEntryIds.add(entry.id);
}
}
addForkRetainedAssistantReplyEntryIds(timelineEntries, replyEntryIds);
return replyEntryIds;
}

Expand Down
175 changes: 175 additions & 0 deletions apps/web/src/components/chat/questionBlock.logic.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
import { MessageId, NodeId, RunAttemptId, RunId } from "@t3tools/contracts";
import { QUESTION_SKIPPED_ANSWER } from "@t3tools/shared/questionCards";
import * as DateTime from "effect/DateTime";
import type { Element } from "hast";
import { describe, expect, it } from "vite-plus/test";

import { wordsHast } from "~/markdown/wordsHast";
import type { TimelineEntry } from "../../session-logic";
import {
deriveMessagesTimelineRows,
timelineTurnFoldRunIdsByEntryId,
} from "./MessagesTimeline.logic";
import {
findQuestionAnswer,
findQuestionRefs,
Expand Down Expand Up @@ -267,3 +274,171 @@ describe("attachQuestionQuoteSources", () => {
]);
});
});

describe("question card messages in the timeline", () => {
const at = (second: number) => `2026-01-01T00:00:${String(second).padStart(2, "0")}Z`;
const runId = RunId.make("run-questions");
const questionCard = (id: string) => `> **${id} · Ship it?**\n>\n> - Yes _(recommended)_\n> - No`;
const messageEntry = (
id: string,
role: "user" | "assistant",
text: string,
second: number,
options?: {
readonly inputIntent?: "turn_start" | "steer";
readonly streaming?: boolean;
readonly attempt?: TimelineEntry["attempt"];
},
): TimelineEntry => ({
kind: "message",
id,
createdAt: at(second),
...(options?.attempt ? { attempt: options.attempt } : {}),
message: {
id: MessageId.make(id),
role,
text,
runId,
...(options?.inputIntent ? { inputIntent: options.inputIntent } : {}),
createdAt: at(second),
updatedAt: at(second),
streaming: options?.streaming ?? false,
},
});
const workEntry = (
id: string,
second: number,
attempt?: TimelineEntry["attempt"],
): TimelineEntry => ({
kind: "work",
id,
createdAt: at(second),
...(attempt ? { attempt } : {}),
entry: { id, createdAt: at(second), runId, label: "Ran check", tone: "tool" },
});

it("keeps a finished assistant message with question cards visible when a later message arrives in the same run", () => {
const timelineEntries: ReadonlyArray<TimelineEntry> = [
messageEntry("prompt", "user", "Check status", 0, { inputIntent: "turn_start" }),
workEntry("work-before", 2),
messageEntry(
"asks-questions",
"assistant",
`${questionCard("Q1")}\n\n${questionCard("Q2")}`,
5,
),
messageEntry("answer-q1", "user", "Q1: Yes", 10, { inputIntent: "steer" }),
messageEntry("commentary", "assistant", "Checking one more thing", 12),
workEntry("work-after", 13),
messageEntry("final-update", "assistant", "Noted on Q1.", 15),
];

const settledInput = {
timelineEntries,
latestRun: { runId, status: "completed" as const, startedAt: at(0), completedAt: at(15) },
isWorking: false,
turnDiffSummaries: [],
supportsConversationRollback: false,
};

const rows = deriveMessagesTimelineRows(settledInput);
expect(rows.map((row) => row.id)).toEqual([
"prompt",
`turn-fold:${runId}`,
"asks-questions",
"answer-q1",
`turn-fold:${runId}:steer:answer-q1`,
"final-update",
]);
expect(timelineTurnFoldRunIdsByEntryId(settledInput).has("asks-questions")).toBe(false);
expect(timelineTurnFoldRunIdsByEntryId(settledInput).has("commentary")).toBe(true);

const zenRows = deriveMessagesTimelineRows({ ...settledInput, toolCallVisibility: "zen" });
expect(zenRows.map((row) => row.id)).toEqual([
"prompt",
"asks-questions",
"answer-q1",
"final-update",
]);
});

it("keeps finished question cards visible in zen mode while the run is still active, but not while streaming", () => {
const timelineEntries: ReadonlyArray<TimelineEntry> = [
messageEntry("prompt", "user", "Start", 0, { inputIntent: "turn_start" }),
messageEntry("finished-questions", "assistant", questionCard("Q1"), 5, { streaming: false }),
workEntry("work-next", 6),
messageEntry("streaming-questions", "assistant", questionCard("Q2"), 8, { streaming: true }),
];

const rows = deriveMessagesTimelineRows({
timelineEntries,
latestRun: { runId, status: "running", startedAt: at(0), completedAt: null },
isWorking: true,
turnDiffSummaries: [],
supportsConversationRollback: false,
toolCallVisibility: "zen",
});
expect(rows.map((row) => row.id)).toContain("finished-questions");
expect(rows.map((row) => row.id)).not.toContain("streaming-questions");
});

it("does not collapse a finished question-card message inside a superseded attempt", () => {
const supersededAttempt = {
id: RunAttemptId.make("attempt-1"),
runId,
attemptOrdinal: 1,
rootNodeId: NodeId.make("node-1"),
status: "superseded" as const,
completedAt: DateTime.makeUnsafe(at(10)),
};
const nextAttempt = {
id: RunAttemptId.make("attempt-2"),
runId,
attemptOrdinal: 2,
rootNodeId: NodeId.make("node-2"),
status: "running" as const,
completedAt: null,
};
const rows = deriveMessagesTimelineRows({
timelineEntries: [
messageEntry("prompt", "user", "Start", 0, {
inputIntent: "turn_start",
attempt: supersededAttempt,
}),
messageEntry("asks-questions", "assistant", questionCard("Q1"), 4, {
attempt: supersededAttempt,
}),
workEntry("old-work", 6, supersededAttempt),
messageEntry("steer", "user", "Q1: Yes", 10, {
inputIntent: "steer",
attempt: nextAttempt,
}),
messageEntry("next-reply", "assistant", "Working on it", 12, {
streaming: true,
attempt: nextAttempt,
}),
],
latestRun: { runId, status: "running", startedAt: at(0), completedAt: null },
isWorking: true,
turnDiffSummaries: [],
supportsConversationRollback: false,
});
expect(rows.map((row) => row.id)).toContain("asks-questions");
});

it("still folds an earlier assistant message whose question syntax is only inside a code fence", () => {
const fenced = "```md\n> **Q1 · Example?**\n>\n> - Yes\n> - No\n```";
const rows = deriveMessagesTimelineRows({
timelineEntries: [
messageEntry("prompt", "user", "Show format", 0, { inputIntent: "turn_start" }),
messageEntry("example-only", "assistant", fenced, 2),
messageEntry("final", "assistant", "Here you go.", 5),
],
latestRun: { runId, status: "completed", startedAt: at(0), completedAt: at(5) },
isWorking: false,
turnDiffSummaries: [],
supportsConversationRollback: false,
});
expect(rows.map((row) => row.id)).toEqual(["prompt", `turn-fold:${runId}`, "final"]);
});
});
20 changes: 20 additions & 0 deletions apps/web/src/components/chat/questionBlock.logic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,26 @@ function cardsOfItem(item: object, text: string): ReadonlyArray<QuestionBlock> {
return cards;
}

const hasQuestionCardsByMessage = new WeakMap<object, boolean>();

/**
* Whether a finished assistant message asks question cards, so timeline folding and Zen mode
* keep the message visible when later messages arrive in the same run.
*/
export function messageHasQuestionCards(message: {
readonly role: string;
readonly text: string;
readonly streaming: boolean;
}): boolean {
if (message.role !== "assistant" || message.streaming) return false;
let has = hasQuestionCardsByMessage.get(message);
if (has === undefined) {
has = questionCardsInMarkdown(message.text).length > 0;
hasQuestionCardsByMessage.set(message, has);
}
return has;
}

/**
* Whether the agent withdrew `questionId` with a `<id>: no longer needed` line in a finished
* assistant message after the item that asked it, while that item still held its latest cards,
Expand Down
Loading
Loading