Skip to content

Commit ce69706

Browse files
committed
tweak: small changes to the stream UI
1 parent 5f6fa49 commit ce69706

File tree

1 file changed

+19
-45
lines changed

1 file changed

+19
-45
lines changed

npm-app/src/cli-handlers/chat.ts

Lines changed: 19 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -459,21 +459,7 @@ export function renderAssistantMessage(
459459
message.subagentTree && message.subagentTree.postContent
460460
const shouldShowOnlyPostContent = isFullyCollapsed && hasPostContentToShow
461461

462-
if (shouldShowOnlyPostContent) {
463-
// Show only postContent when collapsed
464-
const postLines = message.subagentTree!.postContent!.split('\n')
465-
const postPrefix = ' '
466-
postLines.forEach((line) => {
467-
if (line.trim()) {
468-
appendWrappedLine(
469-
lines,
470-
postPrefix + bold(green(line)),
471-
stringWidth(postPrefix),
472-
metrics,
473-
)
474-
}
475-
})
476-
} else {
462+
if (!shouldShowOnlyPostContent) {
477463
// Show preview or full content based on expansion state
478464
const shouldShowPreview = hasSubagents && !isMainExpanded
479465

@@ -492,7 +478,7 @@ export function renderAssistantMessage(
492478
const previewLines = wrappedLines.slice(0, PREVIEW_LINES)
493479

494480
previewLines.forEach((line) => {
495-
const indentedLine = ' ' + line // 4 spaces for assistant content
481+
const indentedLine = ' ' + line // 4 spaces for assistant content with subagents
496482
appendWrappedLine(lines, indentedLine, 4, metrics, [], 0)
497483
})
498484

@@ -506,8 +492,9 @@ export function renderAssistantMessage(
506492
const contentLines = message.content.split('\n')
507493

508494
contentLines.forEach((line) => {
509-
const indentedLine = ' ' + line // 4 spaces for assistant content
510-
appendWrappedLine(lines, indentedLine, 4, metrics, [], 0)
495+
const indentedLine = hasSubagents ? ' ' + line : line // 4 spaces if has subagents, 0 if simple message
496+
const indentLevel = hasSubagents ? 4 : 0
497+
appendWrappedLine(lines, indentedLine, indentLevel, metrics, [], 0)
511498
})
512499
}
513500
}
@@ -531,8 +518,8 @@ export function renderUserMessage(
531518
if (message.content && message.content.trim()) {
532519
const contentLines = message.content.split('\n')
533520
contentLines.forEach((line) => {
534-
const indentedLine = ' ' + line // 4 spaces for user content
535-
appendWrappedLine(lines, indentedLine, 4, metrics, [], 0)
521+
const indentedLine = line // no additional indentation beyond side padding
522+
appendWrappedLine(lines, indentedLine, 0, metrics, [], 0)
536523
})
537524
}
538525

@@ -1417,7 +1404,7 @@ export function renderSubagentTree(
14171404
path: number[] = [],
14181405
): void {
14191406
const nodeId = createNodeId(messageId, path)
1420-
const hasChildren = node.children && node.children.length > 0
1407+
const hasChildren = (node.children && node.children.length > 0) || !!node.postContent
14211408
const isExpanded = uiState.expanded.has(nodeId)
14221409

14231410
// Progressive indentation: 4 spaces per level
@@ -1478,13 +1465,15 @@ export function renderSubagentTree(
14781465

14791466
// Render children if expanded
14801467
if (hasChildren && isExpanded) {
1481-
node.children.forEach((child, index) => {
1482-
renderNode(child, depth + 1, [...path, index])
1483-
})
1468+
if (node.children && node.children.length > 0) {
1469+
node.children.forEach((child, index) => {
1470+
renderNode(child, depth + 1, [...path, index])
1471+
})
1472+
}
14841473
} else if (hasChildren && !isExpanded && node.postContent) {
14851474
// Show postContent for collapsed nodes with children
14861475
const postLines = node.postContent.split('\n')
1487-
const postIndentSpaces = 4 * depth + 4 // Same as content indentation
1476+
const postIndentSpaces = 4 * depth // Same as header indentation
14881477
const postPrefix = ' '.repeat(postIndentSpaces)
14891478
postLines.forEach((line) => {
14901479
if (line.trim()) {
@@ -1498,22 +1487,6 @@ export function renderSubagentTree(
14981487
})
14991488
}
15001489

1501-
// Render postContent only when expanded
1502-
if (node.postContent && isExpanded) {
1503-
const postLines = node.postContent.split('\n')
1504-
const postIndentSpaces = 4 * depth + 4 // Same as content indentation
1505-
const postPrefix = ' '.repeat(postIndentSpaces)
1506-
postLines.forEach((line) => {
1507-
if (line.trim()) {
1508-
appendWrappedLine(
1509-
lines,
1510-
postPrefix + bold(green(line)),
1511-
stringWidth(postPrefix),
1512-
metrics,
1513-
)
1514-
}
1515-
})
1516-
}
15171490
}
15181491

15191492
// Render children only if the tree is not fully collapsed
@@ -1525,10 +1498,11 @@ export function renderSubagentTree(
15251498
}
15261499
}
15271500

1528-
// Only render the parent's postContent if tree is expanded
1529-
if (tree.postContent && uiState.expanded.size > 0) {
1501+
// Only render the parent's postContent if the root node is collapsed
1502+
const rootNodeId = tree.id
1503+
if (tree.postContent && !uiState.expanded.has(rootNodeId)) {
15301504
const postLines = tree.postContent.split('\n')
1531-
const postPrefix = ' '
1505+
const postPrefix = ''
15321506
postLines.forEach((line) => {
15331507
if (line.trim()) {
15341508
appendWrappedLine(
@@ -1764,7 +1738,7 @@ function collectToggleNodesFromTree(
17641738
node.children.forEach((child, index) => {
17651739
const childPath = [...path, index]
17661740
const childNodeId = createNodeId(messageId, childPath)
1767-
const childHasChildren = child.children && child.children.length > 0
1741+
const childHasChildren = (child.children && child.children.length > 0) || !!child.postContent
17681742

17691743
// Only add toggle if this child has children AND this node is currently expanded (making child visible)
17701744
const nodeId = createNodeId(messageId, path)

0 commit comments

Comments
 (0)