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

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
getImageUrisFromContentBlocks,
getProviderRetryNoticeFromMessageData,
inferAcpMessageKind,
normalizeAcpReasoningText,
normalizeTranscriptUserText,
normalizePlanPayload,
parseAcpRequestUserInputPayload,
Expand Down Expand Up @@ -317,6 +318,8 @@ export function toAcpUiMessage(
case 'reasoning':
return {
...base,
text: normalizeAcpReasoningText(normalized.text ?? ''),
rawText: normalized.text ?? '',
role: 'assistant',
kind: 'reasoning',
data: payloadRecord,
Expand Down Expand Up @@ -1281,10 +1284,23 @@ export class AcpProtocolService {
const existing = messages[idx]! as AcpOtherUiMessage;
const next = messages.slice();

const existingText = existing.rawText ?? existing.text ?? '';
const candidateText = candidate.rawText ?? candidate.text ?? '';
const hasOverlappingBoldBoundary =
idPrefix === 'reasoning' &&
existingText.endsWith('**') &&
candidateText.startsWith('****');
const combinedText =
existingText +
(hasOverlappingBoldBoundary ? candidateText.slice(2) : candidateText);
next[idx] = {
...existing,
ts: event.ts,
text: (existing.text ?? '') + (candidate.text ?? ''),
text:
idPrefix === 'reasoning'
? normalizeAcpReasoningText(combinedText)
Comment thread
roomote-community[bot] marked this conversation as resolved.
: combinedText,
...(idPrefix === 'reasoning' ? { rawText: combinedText } : {}),
partial: true,
data: event.payload,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ export interface AcpTodoSectionUiMessage extends AcpUiMessageBase {
export interface AcpOtherUiMessage extends AcpUiMessageBase {
kind: Exclude<AcpMessageKind, 'tool_call' | 'tool_result' | 'plan'>;
data: Record<string, unknown>;
/** Source chunks before reasoning-only display normalization. */
rawText?: string;
}

export type AcpUiMessage =
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
asRecord,
asString,
buildAcpRequestUserInputRequestId,
normalizeAcpReasoningText,
parseAcpFlattenedMcpToolName,
OPENCODE_ARCHITECT_AGENT,
OPENCODE_BUILD_AGENT,
Expand Down Expand Up @@ -607,11 +608,13 @@ function extractAssistantText(message: OpenCodeSessionMessage): string {
}

function extractAssistantReasoning(message: OpenCodeSessionMessage): string {
return message.parts
.filter((part) => part.type === 'reasoning')
.map(extractPartText)
.filter((text) => text.length > 0)
.join('\n');
return normalizeAcpReasoningText(
message.parts
.filter((part) => part.type === 'reasoning')
.map(extractPartText)
.filter((text) => text.length > 0)
.join('\n'),
);
}

function parseOpenCodeMessageRole(value: unknown): OpenCodeMessageRole | null {
Expand Down
22 changes: 22 additions & 0 deletions packages/types/src/__tests__/acp.test.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions packages/types/src/acp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,25 @@ export type AcpLiveEventType =
/** All known Roomote runtime event types — envelope (persisted) + live-only (streamed). */
export type AcpEventType = AcpEnvelopeEventType | AcpLiveEventType;

/** Restore separation between bold reasoning headings concatenated by a provider. */
export function normalizeAcpReasoningText(text: string): string {
return text.replace(/[^\r\n]+/g, (line) => {
if (!line.startsWith('**') || !line.endsWith('**')) {
return line;
}

const headings = line.slice(2, -2).split('****');
if (
headings.length < 2 ||
headings.some((heading) => heading.length === 0 || heading.includes('**'))
) {
return line;
}

return `**${headings.join('**\n\n**')}**`;
});
}

export const ACP_LOGICAL_EVENT_ID_KEY = 'logicalEventId' as const;

export interface AcpLogicalEventIdParts {
Expand Down
Loading