gsd-pi 2.73.0-dev.e1c09f2 → 2.73.1-dev.1040fb0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (109) hide show
  1. package/dist/resources/extensions/claude-code-cli/stream-adapter.js +9 -3
  2. package/dist/resources/extensions/gsd/auto-model-selection.js +54 -11
  3. package/dist/resources/extensions/gsd/auto-start.js +20 -6
  4. package/dist/resources/extensions/gsd/auto.js +5 -1
  5. package/dist/resources/extensions/gsd/bootstrap/crash-log.js +31 -0
  6. package/dist/resources/extensions/gsd/bootstrap/register-extension.js +18 -7
  7. package/dist/resources/extensions/gsd/commands-handlers.js +8 -2
  8. package/dist/resources/extensions/gsd/crash-recovery.js +51 -0
  9. package/dist/resources/extensions/gsd/gsd-db.js +36 -2
  10. package/dist/resources/extensions/gsd/milestone-actions.js +19 -1
  11. package/dist/resources/extensions/gsd/preferences-models.js +43 -0
  12. package/dist/resources/extensions/gsd/preferences-types.js +1 -0
  13. package/dist/resources/extensions/gsd/preferences-validation.js +22 -0
  14. package/dist/update-check.d.ts +1 -0
  15. package/dist/update-check.js +13 -5
  16. package/dist/update-cmd.js +4 -3
  17. package/dist/web/standalone/.next/BUILD_ID +1 -1
  18. package/dist/web/standalone/.next/app-path-routes-manifest.json +15 -15
  19. package/dist/web/standalone/.next/build-manifest.json +2 -2
  20. package/dist/web/standalone/.next/prerender-manifest.json +3 -3
  21. package/dist/web/standalone/.next/server/app/_global-error.html +1 -1
  22. package/dist/web/standalone/.next/server/app/_global-error.rsc +1 -1
  23. package/dist/web/standalone/.next/server/app/_global-error.segments/_full.segment.rsc +1 -1
  24. package/dist/web/standalone/.next/server/app/_global-error.segments/_global-error/__PAGE__.segment.rsc +1 -1
  25. package/dist/web/standalone/.next/server/app/_global-error.segments/_global-error.segment.rsc +1 -1
  26. package/dist/web/standalone/.next/server/app/_global-error.segments/_head.segment.rsc +1 -1
  27. package/dist/web/standalone/.next/server/app/_global-error.segments/_index.segment.rsc +1 -1
  28. package/dist/web/standalone/.next/server/app/_global-error.segments/_tree.segment.rsc +1 -1
  29. package/dist/web/standalone/.next/server/app/_not-found.html +1 -1
  30. package/dist/web/standalone/.next/server/app/_not-found.rsc +1 -1
  31. package/dist/web/standalone/.next/server/app/_not-found.segments/_full.segment.rsc +1 -1
  32. package/dist/web/standalone/.next/server/app/_not-found.segments/_head.segment.rsc +1 -1
  33. package/dist/web/standalone/.next/server/app/_not-found.segments/_index.segment.rsc +1 -1
  34. package/dist/web/standalone/.next/server/app/_not-found.segments/_not-found/__PAGE__.segment.rsc +1 -1
  35. package/dist/web/standalone/.next/server/app/_not-found.segments/_not-found.segment.rsc +1 -1
  36. package/dist/web/standalone/.next/server/app/_not-found.segments/_tree.segment.rsc +1 -1
  37. package/dist/web/standalone/.next/server/app/index.html +1 -1
  38. package/dist/web/standalone/.next/server/app/index.rsc +1 -1
  39. package/dist/web/standalone/.next/server/app/index.segments/__PAGE__.segment.rsc +1 -1
  40. package/dist/web/standalone/.next/server/app/index.segments/_full.segment.rsc +1 -1
  41. package/dist/web/standalone/.next/server/app/index.segments/_head.segment.rsc +1 -1
  42. package/dist/web/standalone/.next/server/app/index.segments/_index.segment.rsc +1 -1
  43. package/dist/web/standalone/.next/server/app/index.segments/_tree.segment.rsc +1 -1
  44. package/dist/web/standalone/.next/server/app-paths-manifest.json +15 -15
  45. package/dist/web/standalone/.next/server/middleware-build-manifest.js +1 -1
  46. package/dist/web/standalone/.next/server/middleware-manifest.json +5 -5
  47. package/dist/web/standalone/.next/server/pages/404.html +1 -1
  48. package/dist/web/standalone/.next/server/pages/500.html +1 -1
  49. package/dist/web/standalone/.next/server/server-reference-manifest.json +1 -1
  50. package/package.json +1 -1
  51. package/packages/pi-ai/dist/index.d.ts +1 -0
  52. package/packages/pi-ai/dist/index.d.ts.map +1 -1
  53. package/packages/pi-ai/dist/index.js +1 -0
  54. package/packages/pi-ai/dist/index.js.map +1 -1
  55. package/packages/pi-ai/dist/utils/overflow.d.ts.map +1 -1
  56. package/packages/pi-ai/dist/utils/overflow.js +12 -0
  57. package/packages/pi-ai/dist/utils/overflow.js.map +1 -1
  58. package/packages/pi-ai/dist/utils/tests/overflow.test.d.ts +2 -0
  59. package/packages/pi-ai/dist/utils/tests/overflow.test.d.ts.map +1 -0
  60. package/packages/pi-ai/dist/utils/tests/overflow.test.js +50 -0
  61. package/packages/pi-ai/dist/utils/tests/overflow.test.js.map +1 -0
  62. package/packages/pi-ai/src/index.ts +4 -0
  63. package/packages/pi-ai/src/utils/overflow.ts +14 -1
  64. package/packages/pi-ai/src/utils/tests/overflow.test.ts +58 -0
  65. package/packages/pi-coding-agent/dist/core/chat-controller-ordering.test.js +175 -8
  66. package/packages/pi-coding-agent/dist/core/chat-controller-ordering.test.js.map +1 -1
  67. package/packages/pi-coding-agent/dist/core/compaction/utils.js +5 -5
  68. package/packages/pi-coding-agent/dist/core/compaction/utils.js.map +1 -1
  69. package/packages/pi-coding-agent/dist/core/compaction-utils.test.d.ts +2 -0
  70. package/packages/pi-coding-agent/dist/core/compaction-utils.test.d.ts.map +1 -0
  71. package/packages/pi-coding-agent/dist/core/compaction-utils.test.js +45 -0
  72. package/packages/pi-coding-agent/dist/core/compaction-utils.test.js.map +1 -0
  73. package/packages/pi-coding-agent/dist/modes/interactive/components/assistant-message.d.ts +12 -2
  74. package/packages/pi-coding-agent/dist/modes/interactive/components/assistant-message.d.ts.map +1 -1
  75. package/packages/pi-coding-agent/dist/modes/interactive/components/assistant-message.js +51 -26
  76. package/packages/pi-coding-agent/dist/modes/interactive/components/assistant-message.js.map +1 -1
  77. package/packages/pi-coding-agent/dist/modes/interactive/controllers/chat-controller.d.ts.map +1 -1
  78. package/packages/pi-coding-agent/dist/modes/interactive/controllers/chat-controller.js +73 -12
  79. package/packages/pi-coding-agent/dist/modes/interactive/controllers/chat-controller.js.map +1 -1
  80. package/packages/pi-coding-agent/package.json +1 -1
  81. package/packages/pi-coding-agent/src/core/chat-controller-ordering.test.ts +198 -8
  82. package/packages/pi-coding-agent/src/core/compaction/utils.ts +5 -5
  83. package/packages/pi-coding-agent/src/core/compaction-utils.test.ts +50 -0
  84. package/packages/pi-coding-agent/src/modes/interactive/components/assistant-message.ts +62 -26
  85. package/packages/pi-coding-agent/src/modes/interactive/controllers/chat-controller.ts +92 -17
  86. package/pkg/package.json +1 -1
  87. package/src/resources/extensions/claude-code-cli/stream-adapter.ts +12 -4
  88. package/src/resources/extensions/claude-code-cli/tests/stream-adapter.test.ts +23 -2
  89. package/src/resources/extensions/gsd/auto-model-selection.ts +85 -11
  90. package/src/resources/extensions/gsd/auto-start.ts +27 -6
  91. package/src/resources/extensions/gsd/auto.ts +5 -0
  92. package/src/resources/extensions/gsd/bootstrap/crash-log.ts +32 -0
  93. package/src/resources/extensions/gsd/bootstrap/register-extension.ts +19 -7
  94. package/src/resources/extensions/gsd/commands-handlers.ts +8 -2
  95. package/src/resources/extensions/gsd/crash-recovery.ts +59 -0
  96. package/src/resources/extensions/gsd/gsd-db.ts +52 -2
  97. package/src/resources/extensions/gsd/milestone-actions.ts +19 -1
  98. package/src/resources/extensions/gsd/preferences-models.ts +41 -0
  99. package/src/resources/extensions/gsd/preferences-types.ts +12 -0
  100. package/src/resources/extensions/gsd/preferences-validation.ts +23 -0
  101. package/src/resources/extensions/gsd/tests/auto-start-model-capture.test.ts +51 -2
  102. package/src/resources/extensions/gsd/tests/crash-handler-secondary.test.ts +235 -0
  103. package/src/resources/extensions/gsd/tests/flat-rate-routing-guard.test.ts +137 -1
  104. package/src/resources/extensions/gsd/tests/gsd-db.test.ts +59 -1
  105. package/src/resources/extensions/gsd/tests/model-isolation.test.ts +91 -2
  106. package/src/resources/extensions/gsd/tests/park-milestone.test.ts +64 -0
  107. package/src/resources/extensions/gsd/tests/preferences.test.ts +47 -0
  108. /package/dist/web/standalone/.next/static/{_XD_gUDcZNBbWV5rI8RgS → 5dzOW4v8Vz23I5xRsiNSk}/_buildManifest.js +0 -0
  109. /package/dist/web/standalone/.next/static/{_XD_gUDcZNBbWV5rI8RgS → 5dzOW4v8Vz23I5xRsiNSk}/_ssgManifest.js +0 -0
@@ -1 +1 @@
1
- {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/core/compaction/utils.ts"],"names":[],"mappings":"AAAA;;GAEG;AAIH,OAAO,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAC;AACxD,OAAO,EACN,0BAA0B,EAC1B,8BAA8B,EAC9B,mBAAmB,GACnB,MAAM,gBAAgB,CAAC;AAaxB,MAAM,UAAU,aAAa;IAC5B,OAAO;QACN,IAAI,EAAE,IAAI,GAAG,EAAE;QACf,OAAO,EAAE,IAAI,GAAG,EAAE;QAClB,MAAM,EAAE,IAAI,GAAG,EAAE;KACjB,CAAC;AACH,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,yBAAyB,CAAC,OAAqB,EAAE,OAAuB;IACvF,IAAI,OAAO,CAAC,IAAI,KAAK,WAAW;QAAE,OAAO;IACzC,IAAI,CAAC,CAAC,SAAS,IAAI,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC;QAAE,OAAO;IAEvE,KAAK,MAAM,KAAK,IAAI,OAAO,CAAC,OAAO,EAAE,CAAC;QACrC,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI;YAAE,SAAS;QAC1D,IAAI,CAAC,CAAC,MAAM,IAAI,KAAK,CAAC,IAAI,KAAK,CAAC,IAAI,KAAK,UAAU;YAAE,SAAS;QAC9D,IAAI,CAAC,CAAC,WAAW,IAAI,KAAK,CAAC,IAAI,CAAC,CAAC,MAAM,IAAI,KAAK,CAAC;YAAE,SAAS;QAE5D,MAAM,IAAI,GAAG,KAAK,CAAC,SAAgD,CAAC;QACpE,IAAI,CAAC,IAAI;YAAE,SAAS;QAEpB,MAAM,IAAI,GAAG,OAAO,IAAI,CAAC,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC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,CAAC,EAAE,CAAC,CAAC;YACX,IAAI,OAAO,EAAE,CAAC;gBACb,KAAK,CAAC,IAAI,CAAC,kBAAkB,kBAAkB,CAAC,OAAO,EAAE,qBAAqB,CAAC,EAAE,CAAC,CAAC;YACpF,CAAC;QACF,CAAC;IACF,CAAC;IAED,OAAO,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;AAC3B,CAAC;AAED,+EAA+E;AAC/E,8BAA8B;AAC9B,+EAA+E;AAE/E,MAAM,CAAC,MAAM,2BAA2B,GAAG;;2HAEgF,CAAC","sourcesContent":["/**\n * Shared utilities for compaction and branch summarization.\n */\n\nimport type { AgentMessage } from \"@gsd/pi-agent-core\";\nimport type { Message } from \"@gsd/pi-ai\";\nimport { TOOL_RESULT_MAX_CHARS } from \"../constants.js\";\nimport {\n\tcreateBranchSummaryMessage,\n\tcreateCompactionSummaryMessage,\n\tcreateCustomMessage,\n} from \"../messages.js\";\nimport type { SessionEntry } from \"../session-manager.js\";\n\n// ============================================================================\n// File Operation Tracking\n// ============================================================================\n\nexport interface FileOperations {\n\tread: Set<string>;\n\twritten: Set<string>;\n\tedited: Set<string>;\n}\n\nexport function createFileOps(): FileOperations {\n\treturn {\n\t\tread: new Set(),\n\t\twritten: new Set(),\n\t\tedited: new Set(),\n\t};\n}\n\n/**\n * Extract file operations from tool calls in an assistant message.\n */\nexport function extractFileOpsFromMessage(message: AgentMessage, fileOps: FileOperations): void {\n\tif (message.role !== \"assistant\") return;\n\tif (!(\"content\" in message) || !Array.isArray(message.content)) return;\n\n\tfor (const block of message.content) {\n\t\tif (typeof block !== \"object\" || block === null) continue;\n\t\tif (!(\"type\" in block) || block.type !== \"toolCall\") continue;\n\t\tif (!(\"arguments\" in block) || !(\"name\" in block)) continue;\n\n\t\tconst args = block.arguments as Record<string, unknown> | undefined;\n\t\tif (!args) continue;\n\n\t\tconst path = typeof args.path === \"string\" ? args.path : undefined;\n\t\tif (!path) continue;\n\n\t\tswitch (block.name) {\n\t\t\tcase \"read\":\n\t\t\t\tfileOps.read.add(path);\n\t\t\t\tbreak;\n\t\t\tcase \"write\":\n\t\t\t\tfileOps.written.add(path);\n\t\t\t\tbreak;\n\t\t\tcase \"edit\":\n\t\t\t\tfileOps.edited.add(path);\n\t\t\t\tbreak;\n\t\t}\n\t}\n}\n\n/**\n * Compute final file lists from file operations.\n * Returns readFiles (files only read, not modified) and modifiedFiles.\n */\nexport function computeFileLists(fileOps: FileOperations): { readFiles: string[]; modifiedFiles: string[] } {\n\tconst modified = new Set([...fileOps.edited, ...fileOps.written]);\n\tconst readOnly = [...fileOps.read].filter((f) => !modified.has(f)).sort();\n\tconst modifiedFiles = [...modified].sort();\n\treturn { readFiles: readOnly, modifiedFiles };\n}\n\n/**\n * Format file operations as XML tags for summary.\n */\nexport function formatFileOperations(readFiles: string[], modifiedFiles: string[]): string {\n\tconst sections: string[] = [];\n\tif (readFiles.length > 0) {\n\t\tsections.push(`<read-files>\\n${readFiles.join(\"\\n\")}\\n</read-files>`);\n\t}\n\tif (modifiedFiles.length > 0) {\n\t\tsections.push(`<modified-files>\\n${modifiedFiles.join(\"\\n\")}\\n</modified-files>`);\n\t}\n\tif (sections.length === 0) return \"\";\n\treturn `\\n\\n${sections.join(\"\\n\\n\")}`;\n}\n\n// ============================================================================\n// Message Extraction\n// ============================================================================\n\n/**\n * Extract AgentMessage from a session entry.\n *\n * Handles all entry types: message, custom_message, branch_summary, and compaction.\n * Returns undefined for entries that don't contribute to LLM context (e.g., settings changes).\n *\n * @param skipToolResults - If true, skips toolResult messages (used by branch summarization\n * where tool call context is sufficient). Default false.\n */\nexport function getMessageFromEntry(entry: SessionEntry, skipToolResults = false): AgentMessage | undefined {\n\tswitch (entry.type) {\n\t\tcase \"message\":\n\t\t\tif (skipToolResults && entry.message.role === \"toolResult\") return undefined;\n\t\t\treturn entry.message;\n\n\t\tcase \"custom_message\":\n\t\t\treturn createCustomMessage(entry.customType, entry.content, entry.display, entry.details, entry.timestamp);\n\n\t\tcase \"branch_summary\":\n\t\t\treturn createBranchSummaryMessage(entry.summary, entry.fromId, entry.timestamp);\n\n\t\tcase \"compaction\":\n\t\t\treturn createCompactionSummaryMessage(entry.summary, entry.tokensBefore, entry.timestamp);\n\n\t\tcase \"thinking_level_change\":\n\t\tcase \"model_change\":\n\t\tcase \"custom\":\n\t\tcase \"label\":\n\t\t\treturn undefined;\n\t}\n}\n\n/**\n * Collect AgentMessages from a range of session entries.\n *\n * @param entries - Session entries array\n * @param startIndex - First index (inclusive)\n * @param endIndex - Last index (exclusive)\n * @param skipToolResults - If true, skips toolResult messages. Default false.\n */\nexport function collectMessages(\n\tentries: SessionEntry[],\n\tstartIndex: number,\n\tendIndex: number,\n\tskipToolResults = false,\n): AgentMessage[] {\n\tconst result: AgentMessage[] = [];\n\tfor (let i = startIndex; i < endIndex; i++) {\n\t\tconst msg = getMessageFromEntry(entries[i], skipToolResults);\n\t\tif (msg) result.push(msg);\n\t}\n\treturn result;\n}\n\n// ============================================================================\n// Text Content Extraction\n// ============================================================================\n\n/**\n * Extract text from an array of content blocks, filtering to text-type blocks.\n * Replaces the recurring `.filter(c => c.type === \"text\").map(c => c.text).join(sep)` pattern.\n */\nexport function extractTextContent(\n\tcontent: Array<{ type: string; text?: string }>,\n\tseparator = \"\\n\",\n): string {\n\treturn content\n\t\t.filter((c): c is { type: \"text\"; text: string } => c.type === \"text\")\n\t\t.map((c) => c.text)\n\t\t.join(separator);\n}\n\n// ============================================================================\n// Summarization Message Construction\n// ============================================================================\n\n/**\n * Create a single-message array for summarization prompts.\n * Wraps promptText in the standard `[{ role: \"user\", content: [{ type: \"text\", text }], timestamp }]` shape.\n */\nexport function createSummarizationMessage(promptText: string): [{ role: \"user\"; content: [{ type: \"text\"; text: string }]; timestamp: number }] {\n\treturn [\n\t\t{\n\t\t\trole: \"user\" as const,\n\t\t\tcontent: [{ type: \"text\" as const, text: promptText }],\n\t\t\ttimestamp: Date.now(),\n\t\t},\n\t];\n}\n\n// ============================================================================\n// Message Serialization\n// ============================================================================\n\n// TOOL_RESULT_MAX_CHARS imported from ../constants.js\n\n/**\n * Truncate text to a maximum character length for summarization.\n * Keeps the beginning and appends a truncation marker.\n */\nfunction truncateForSummary(text: string, maxChars: number): string {\n\tif (text.length <= maxChars) return text;\n\tconst truncatedChars = text.length - maxChars;\n\treturn `${text.slice(0, maxChars)}\\n\\n[... ${truncatedChars} more characters truncated]`;\n}\n\n/**\n * Serialize LLM messages to text for summarization.\n * This prevents the model from treating it as a conversation to continue.\n * Call convertToLlm() first to handle custom message types.\n *\n * Tool results are truncated to keep the summarization request within\n * reasonable token budgets. Full content is not needed for summarization.\n */\nexport function serializeConversation(messages: Message[]): string {\n\tconst parts: string[] = [];\n\n\tfor (const msg of messages) {\n\t\tif (msg.role === \"user\") {\n\t\t\tconst content =\n\t\t\t\ttypeof msg.content === \"string\"\n\t\t\t\t\t? msg.content\n\t\t\t\t\t: msg.content\n\t\t\t\t\t\t\t.filter((c): c is { type: \"text\"; text: string } => c.type === \"text\")\n\t\t\t\t\t\t\t.map((c) => c.text)\n\t\t\t\t\t\t\t.join(\"\");\n\t\t\tif (content) parts.push(`[User]: ${content}`);\n\t\t} else if (msg.role === \"assistant\") {\n\t\t\tconst textParts: string[] = [];\n\t\t\tconst thinkingParts: string[] = [];\n\t\t\tconst toolCalls: string[] = [];\n\n\t\t\tfor (const block of msg.content) {\n\t\t\t\tif (block.type === \"text\") {\n\t\t\t\t\ttextParts.push(block.text);\n\t\t\t\t} else if (block.type === \"thinking\") {\n\t\t\t\t\tthinkingParts.push(block.thinking);\n\t\t\t\t} else if (block.type === \"toolCall\") {\n\t\t\t\t\tconst args = block.arguments as Record<string, unknown>;\n\t\t\t\t\tconst argsStr = Object.entries(args)\n\t\t\t\t\t\t.map(([k, v]) => `${k}=${JSON.stringify(v)}`)\n\t\t\t\t\t\t.join(\", \");\n\t\t\t\t\ttoolCalls.push(`${block.name}(${argsStr})`);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (thinkingParts.length > 0) {\n\t\t\t\tparts.push(`[Assistant thinking]: ${thinkingParts.join(\"\\n\")}`);\n\t\t\t}\n\t\t\tif (textParts.length > 0) {\n\t\t\t\tparts.push(`[Assistant]: ${textParts.join(\"\\n\")}`);\n\t\t\t}\n\t\t\tif (toolCalls.length > 0) {\n\t\t\t\tparts.push(`[Assistant tool calls]: ${toolCalls.join(\"; \")}`);\n\t\t\t}\n\t\t} else if (msg.role === \"toolResult\") {\n\t\t\tconst content = msg.content\n\t\t\t\t.filter((c): c is { type: \"text\"; text: string } => c.type === \"text\")\n\t\t\t\t.map((c) => c.text)\n\t\t\t\t.join(\"\");\n\t\t\tif (content) {\n\t\t\t\tparts.push(`[Tool result]: ${truncateForSummary(content, TOOL_RESULT_MAX_CHARS)}`);\n\t\t\t}\n\t\t}\n\t}\n\n\treturn parts.join(\"\\n\\n\");\n}\n\n// ============================================================================\n// Summarization System Prompt\n// ============================================================================\n\nexport const SUMMARIZATION_SYSTEM_PROMPT = `You are a context summarization assistant. Your task is to read a conversation between a user and an AI coding assistant, then produce a structured summary following the exact format specified.\n\nDo NOT continue the conversation. Do NOT respond to any questions in the conversation. ONLY output the structured summary.`;\n"]}
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/core/compaction/utils.ts"],"names":[],"mappings":"AAAA;;GAEG;AAIH,OAAO,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAC;AACxD,OAAO,EACN,0BAA0B,EAC1B,8BAA8B,EAC9B,mBAAmB,GACnB,MAAM,gBAAgB,CAAC;AAaxB,MAAM,UAAU,aAAa;IAC5B,OAAO;QACN,IAAI,EAAE,IAAI,GAAG,EAAE;QACf,OAAO,EAAE,IAAI,GAAG,EAAE;QAClB,MAAM,EAAE,IAAI,GAAG,EAAE;KACjB,CAAC;AACH,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,yBAAyB,CAAC,OAAqB,EAAE,OAAuB;IACvF,IAAI,OAAO,CAAC,IAAI,KAAK,WA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I,CAAC,EAAE,CAAC,CAAC;YACnE,CAAC;YACD,IAAI,SAAS,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;gBAC1B,KAAK,CAAC,IAAI,CAAC,4BAA4B,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;YAChE,CAAC;YACD,IAAI,SAAS,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;gBAC1B,KAAK,CAAC,IAAI,CAAC,6BAA6B,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;YACjE,CAAC;QACF,CAAC;aAAM,IAAI,GAAG,CAAC,IAAI,KAAK,YAAY,EAAE,CAAC;YACtC,MAAM,OAAO,GAAG,GAAG,CAAC,OAAO;iBACzB,MAAM,CAAC,CAAC,CAAC,EAAuC,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,MAAM,CAAC;iBACrE,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;iBAClB,IAAI,CAAC,EAAE,CAAC,CAAC;YACX,IAAI,OAAO,EAAE,CAAC;gBACb,KAAK,CAAC,IAAI,CAAC,oBAAoB,kBAAkB,CAAC,OAAO,EAAE,qBAAqB,CAAC,EAAE,CAAC,CAAC;YACtF,CAAC;QACF,CAAC;IACF,CAAC;IAED,OAAO,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;AAC3B,CAAC;AAED,+EAA+E;AAC/E,8BAA8B;AAC9B,+EAA+E;AAE/E,MAAM,CAAC,MAAM,2BAA2B,GAAG;;2HAEgF,CAAC","sourcesContent":["/**\n * Shared utilities for compaction and branch summarization.\n */\n\nimport type { AgentMessage } from \"@gsd/pi-agent-core\";\nimport type { Message } from \"@gsd/pi-ai\";\nimport { TOOL_RESULT_MAX_CHARS } from \"../constants.js\";\nimport {\n\tcreateBranchSummaryMessage,\n\tcreateCompactionSummaryMessage,\n\tcreateCustomMessage,\n} from \"../messages.js\";\nimport type { SessionEntry } from \"../session-manager.js\";\n\n// ============================================================================\n// File Operation Tracking\n// ============================================================================\n\nexport interface FileOperations {\n\tread: Set<string>;\n\twritten: Set<string>;\n\tedited: Set<string>;\n}\n\nexport function createFileOps(): FileOperations {\n\treturn {\n\t\tread: new Set(),\n\t\twritten: new Set(),\n\t\tedited: new Set(),\n\t};\n}\n\n/**\n * Extract file operations from tool calls in an assistant message.\n */\nexport function extractFileOpsFromMessage(message: AgentMessage, fileOps: FileOperations): void {\n\tif (message.role !== \"assistant\") return;\n\tif (!(\"content\" in message) || !Array.isArray(message.content)) return;\n\n\tfor (const block of message.content) {\n\t\tif (typeof block !== \"object\" || block === null) continue;\n\t\tif (!(\"type\" in block) || block.type !== \"toolCall\") continue;\n\t\tif (!(\"arguments\" in block) || !(\"name\" in block)) continue;\n\n\t\tconst args = block.arguments as Record<string, unknown> | undefined;\n\t\tif (!args) continue;\n\n\t\tconst path = typeof args.path === \"string\" ? args.path : undefined;\n\t\tif (!path) continue;\n\n\t\tswitch (block.name) {\n\t\t\tcase \"read\":\n\t\t\t\tfileOps.read.add(path);\n\t\t\t\tbreak;\n\t\t\tcase \"write\":\n\t\t\t\tfileOps.written.add(path);\n\t\t\t\tbreak;\n\t\t\tcase \"edit\":\n\t\t\t\tfileOps.edited.add(path);\n\t\t\t\tbreak;\n\t\t}\n\t}\n}\n\n/**\n * Compute final file lists from file operations.\n * Returns readFiles (files only read, not modified) and modifiedFiles.\n */\nexport function computeFileLists(fileOps: FileOperations): { readFiles: string[]; modifiedFiles: string[] } {\n\tconst modified = new Set([...fileOps.edited, ...fileOps.written]);\n\tconst readOnly = [...fileOps.read].filter((f) => !modified.has(f)).sort();\n\tconst modifiedFiles = [...modified].sort();\n\treturn { readFiles: readOnly, modifiedFiles };\n}\n\n/**\n * Format file operations as XML tags for summary.\n */\nexport function formatFileOperations(readFiles: string[], modifiedFiles: string[]): string {\n\tconst sections: string[] = [];\n\tif (readFiles.length > 0) {\n\t\tsections.push(`<read-files>\\n${readFiles.join(\"\\n\")}\\n</read-files>`);\n\t}\n\tif (modifiedFiles.length > 0) {\n\t\tsections.push(`<modified-files>\\n${modifiedFiles.join(\"\\n\")}\\n</modified-files>`);\n\t}\n\tif (sections.length === 0) return \"\";\n\treturn `\\n\\n${sections.join(\"\\n\\n\")}`;\n}\n\n// ============================================================================\n// Message Extraction\n// ============================================================================\n\n/**\n * Extract AgentMessage from a session entry.\n *\n * Handles all entry types: message, custom_message, branch_summary, and compaction.\n * Returns undefined for entries that don't contribute to LLM context (e.g., settings changes).\n *\n * @param skipToolResults - If true, skips toolResult messages (used by branch summarization\n * where tool call context is sufficient). Default false.\n */\nexport function getMessageFromEntry(entry: SessionEntry, skipToolResults = false): AgentMessage | undefined {\n\tswitch (entry.type) {\n\t\tcase \"message\":\n\t\t\tif (skipToolResults && entry.message.role === \"toolResult\") return undefined;\n\t\t\treturn entry.message;\n\n\t\tcase \"custom_message\":\n\t\t\treturn createCustomMessage(entry.customType, entry.content, entry.display, entry.details, entry.timestamp);\n\n\t\tcase \"branch_summary\":\n\t\t\treturn createBranchSummaryMessage(entry.summary, entry.fromId, entry.timestamp);\n\n\t\tcase \"compaction\":\n\t\t\treturn createCompactionSummaryMessage(entry.summary, entry.tokensBefore, entry.timestamp);\n\n\t\tcase \"thinking_level_change\":\n\t\tcase \"model_change\":\n\t\tcase \"custom\":\n\t\tcase \"label\":\n\t\t\treturn undefined;\n\t}\n}\n\n/**\n * Collect AgentMessages from a range of session entries.\n *\n * @param entries - Session entries array\n * @param startIndex - First index (inclusive)\n * @param endIndex - Last index (exclusive)\n * @param skipToolResults - If true, skips toolResult messages. Default false.\n */\nexport function collectMessages(\n\tentries: SessionEntry[],\n\tstartIndex: number,\n\tendIndex: number,\n\tskipToolResults = false,\n): AgentMessage[] {\n\tconst result: AgentMessage[] = [];\n\tfor (let i = startIndex; i < endIndex; i++) {\n\t\tconst msg = getMessageFromEntry(entries[i], skipToolResults);\n\t\tif (msg) result.push(msg);\n\t}\n\treturn result;\n}\n\n// ============================================================================\n// Text Content Extraction\n// ============================================================================\n\n/**\n * Extract text from an array of content blocks, filtering to text-type blocks.\n * Replaces the recurring `.filter(c => c.type === \"text\").map(c => c.text).join(sep)` pattern.\n */\nexport function extractTextContent(\n\tcontent: Array<{ type: string; text?: string }>,\n\tseparator = \"\\n\",\n): string {\n\treturn content\n\t\t.filter((c): c is { type: \"text\"; text: string } => c.type === \"text\")\n\t\t.map((c) => c.text)\n\t\t.join(separator);\n}\n\n// ============================================================================\n// Summarization Message Construction\n// ============================================================================\n\n/**\n * Create a single-message array for summarization prompts.\n * Wraps promptText in the standard `[{ role: \"user\", content: [{ type: \"text\", text }], timestamp }]` shape.\n */\nexport function createSummarizationMessage(promptText: string): [{ role: \"user\"; content: [{ type: \"text\"; text: string }]; timestamp: number }] {\n\treturn [\n\t\t{\n\t\t\trole: \"user\" as const,\n\t\t\tcontent: [{ type: \"text\" as const, text: promptText }],\n\t\t\ttimestamp: Date.now(),\n\t\t},\n\t];\n}\n\n// ============================================================================\n// Message Serialization\n// ============================================================================\n\n// TOOL_RESULT_MAX_CHARS imported from ../constants.js\n\n/**\n * Truncate text to a maximum character length for summarization.\n * Keeps the beginning and appends a truncation marker.\n */\nfunction truncateForSummary(text: string, maxChars: number): string {\n\tif (text.length <= maxChars) return text;\n\tconst truncatedChars = text.length - maxChars;\n\treturn `${text.slice(0, maxChars)}\\n\\n[... ${truncatedChars} more characters truncated]`;\n}\n\n/**\n * Serialize LLM messages to text for summarization.\n * This prevents the model from treating it as a conversation to continue.\n * Call convertToLlm() first to handle custom message types.\n *\n * Tool results are truncated to keep the summarization request within\n * reasonable token budgets. Full content is not needed for summarization.\n */\nexport function serializeConversation(messages: Message[]): string {\n\tconst parts: string[] = [];\n\n\tfor (const msg of messages) {\n\t\tif (msg.role === \"user\") {\n\t\t\tconst content =\n\t\t\t\ttypeof msg.content === \"string\"\n\t\t\t\t\t? msg.content\n\t\t\t\t\t: msg.content\n\t\t\t\t\t\t\t.filter((c): c is { type: \"text\"; text: string } => c.type === \"text\")\n\t\t\t\t\t\t\t.map((c) => c.text)\n\t\t\t\t\t\t\t.join(\"\");\n\t\t\tif (content) parts.push(`**User said:** ${content}`);\n\t\t} else if (msg.role === \"assistant\") {\n\t\t\tconst textParts: string[] = [];\n\t\t\tconst thinkingParts: string[] = [];\n\t\t\tconst toolCalls: string[] = [];\n\n\t\t\tfor (const block of msg.content) {\n\t\t\t\tif (block.type === \"text\") {\n\t\t\t\t\ttextParts.push(block.text);\n\t\t\t\t} else if (block.type === \"thinking\") {\n\t\t\t\t\tthinkingParts.push(block.thinking);\n\t\t\t\t} else if (block.type === \"toolCall\") {\n\t\t\t\t\tconst args = block.arguments as Record<string, unknown>;\n\t\t\t\t\tconst argsStr = Object.entries(args)\n\t\t\t\t\t\t.map(([k, v]) => `${k}=${JSON.stringify(v)}`)\n\t\t\t\t\t\t.join(\", \");\n\t\t\t\t\ttoolCalls.push(`${block.name}(${argsStr})`);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (thinkingParts.length > 0) {\n\t\t\t\tparts.push(`**Assistant thinking:** ${thinkingParts.join(\"\\n\")}`);\n\t\t\t}\n\t\t\tif (textParts.length > 0) {\n\t\t\t\tparts.push(`**Assistant responded:** ${textParts.join(\"\\n\")}`);\n\t\t\t}\n\t\t\tif (toolCalls.length > 0) {\n\t\t\t\tparts.push(`**Assistant tool calls:** ${toolCalls.join(\"; \")}`);\n\t\t\t}\n\t\t} else if (msg.role === \"toolResult\") {\n\t\t\tconst content = msg.content\n\t\t\t\t.filter((c): c is { type: \"text\"; text: string } => c.type === \"text\")\n\t\t\t\t.map((c) => c.text)\n\t\t\t\t.join(\"\");\n\t\t\tif (content) {\n\t\t\t\tparts.push(`**Tool result:** ${truncateForSummary(content, TOOL_RESULT_MAX_CHARS)}`);\n\t\t\t}\n\t\t}\n\t}\n\n\treturn parts.join(\"\\n\\n\");\n}\n\n// ============================================================================\n// Summarization System Prompt\n// ============================================================================\n\nexport const SUMMARIZATION_SYSTEM_PROMPT = `You are a context summarization assistant. Your task is to read a conversation between a user and an AI coding assistant, then produce a structured summary following the exact format specified.\n\nDo NOT continue the conversation. Do NOT respond to any questions in the conversation. ONLY output the structured summary.`;\n"]}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=compaction-utils.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"compaction-utils.test.d.ts","sourceRoot":"","sources":["../../src/core/compaction-utils.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,45 @@
1
+ import assert from "node:assert/strict";
2
+ import test from "node:test";
3
+ import { serializeConversation } from "./compaction/index.js";
4
+ test("serializeConversation uses narrative role markers instead of chat-style delimiters (#4054)", () => {
5
+ const messages = [
6
+ { role: "user", content: "Please refactor the parser." },
7
+ {
8
+ role: "assistant",
9
+ content: [
10
+ { type: "thinking", thinking: "I should inspect the parser entry points first." },
11
+ { type: "text", text: "I'll start with the parser entry points." },
12
+ { type: "toolCall", id: "tool-1", name: "Read", arguments: { path: "src/parser.ts" } },
13
+ ],
14
+ api: "anthropic-messages",
15
+ provider: "anthropic",
16
+ model: "claude-sonnet-4-6",
17
+ usage: {
18
+ input: 0,
19
+ output: 0,
20
+ cacheRead: 0,
21
+ cacheWrite: 0,
22
+ totalTokens: 0,
23
+ cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, total: 0 },
24
+ },
25
+ stopReason: "stop",
26
+ timestamp: Date.now(),
27
+ },
28
+ {
29
+ role: "toolResult",
30
+ content: [{ type: "text", text: "parser contents" }],
31
+ toolName: "Read",
32
+ toolCallId: "tool-1",
33
+ },
34
+ ];
35
+ const serialized = serializeConversation(messages);
36
+ assert.match(serialized, /\*\*User said:\*\* Please refactor the parser\./);
37
+ assert.match(serialized, /\*\*Assistant thinking:\*\* I should inspect the parser entry points first\./);
38
+ assert.match(serialized, /\*\*Assistant responded:\*\* I'll start with the parser entry points\./);
39
+ assert.match(serialized, /\*\*Assistant tool calls:\*\* Read\(path="src\/parser\.ts"\)/);
40
+ assert.match(serialized, /\*\*Tool result:\*\* parser contents/);
41
+ assert.ok(!serialized.includes("[User]:"), "chat-style [User]: markers should not remain");
42
+ assert.ok(!serialized.includes("[Assistant]:"), "chat-style [Assistant]: markers should not remain");
43
+ assert.ok(!serialized.includes("[Tool result]:"), "chat-style [Tool result]: markers should not remain");
44
+ });
45
+ //# sourceMappingURL=compaction-utils.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"compaction-utils.test.js","sourceRoot":"","sources":["../../src/core/compaction-utils.test.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,oBAAoB,CAAC;AACxC,OAAO,IAAI,MAAM,WAAW,CAAC;AAI7B,OAAO,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,CAAC;AAE9D,IAAI,CAAC,4FAA4F,EAAE,GAAG,EAAE;IACvG,MAAM,QAAQ,GAAc;QAC3B,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,6BAA6B,EAAa;QACnE;YACC,IAAI,EAAE,WAAW;YACjB,OAAO,EAAE;gBACR,EAAE,IAAI,EAAE,UAAU,EAAE,QAAQ,EAAE,iDAAiD,EAAE;gBACjF,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,0CAA0C,EAAE;gBAClE,EAAE,IAAI,EAAE,UAAU,EAAE,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,EAAE,IAAI,EAAE,eAAe,EAAE,EAAE;aACtF;YACD,GAAG,EAAE,oBAAoB;YACzB,QAAQ,EAAE,WAAW;YACrB,KAAK,EAAE,mBAAmB;YAC1B,KAAK,EAAE;gBACN,KAAK,EAAE,CAAC;gBACR,MAAM,EAAE,CAAC;gBACT,SAAS,EAAE,CAAC;gBACZ,UAAU,EAAE,CAAC;gBACb,WAAW,EAAE,CAAC;gBACd,IAAI,EAAE,EAAE,KAAK,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,SAAS,EAAE,CAAC,EAAE,UAAU,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE;aACpE;YACD,UAAU,EAAE,MAAM;YAClB,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE;SACV;QACZ;YACC,IAAI,EAAE,YAAY;YAClB,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,iBAAiB,EAAE,CAAC;YACpD,QAAQ,EAAE,MAAM;YAChB,UAAU,EAAE,QAAQ;SACT;KACZ,CAAC;IAEF,MAAM,UAAU,GAAG,qBAAqB,CAAC,QAAQ,CAAC,CAAC;IAEnD,MAAM,CAAC,KAAK,CAAC,UAAU,EAAE,iDAAiD,CAAC,CAAC;IAC5E,MAAM,CAAC,KAAK,CAAC,UAAU,EAAE,8EAA8E,CAAC,CAAC;IACzG,MAAM,CAAC,KAAK,CAAC,UAAU,EAAE,wEAAwE,CAAC,CAAC;IACnG,MAAM,CAAC,KAAK,CAAC,UAAU,EAAE,8DAA8D,CAAC,CAAC;IACzF,MAAM,CAAC,KAAK,CAAC,UAAU,EAAE,sCAAsC,CAAC,CAAC;IACjE,MAAM,CAAC,EAAE,CAAC,CAAC,UAAU,CAAC,QAAQ,CAAC,SAAS,CAAC,EAAE,8CAA8C,CAAC,CAAC;IAC3F,MAAM,CAAC,EAAE,CAAC,CAAC,UAAU,CAAC,QAAQ,CAAC,cAAc,CAAC,EAAE,mDAAmD,CAAC,CAAC;IACrG,MAAM,CAAC,EAAE,CAAC,CAAC,UAAU,CAAC,QAAQ,CAAC,gBAAgB,CAAC,EAAE,qDAAqD,CAAC,CAAC;AAC1G,CAAC,CAAC,CAAC","sourcesContent":["import assert from \"node:assert/strict\";\nimport test from \"node:test\";\n\nimport type { Message } from \"@gsd/pi-ai\";\n\nimport { serializeConversation } from \"./compaction/index.js\";\n\ntest(\"serializeConversation uses narrative role markers instead of chat-style delimiters (#4054)\", () => {\n\tconst messages: Message[] = [\n\t\t{ role: \"user\", content: \"Please refactor the parser.\" } as Message,\n\t\t{\n\t\t\trole: \"assistant\",\n\t\t\tcontent: [\n\t\t\t\t{ type: \"thinking\", thinking: \"I should inspect the parser entry points first.\" },\n\t\t\t\t{ type: \"text\", text: \"I'll start with the parser entry points.\" },\n\t\t\t\t{ type: \"toolCall\", id: \"tool-1\", name: \"Read\", arguments: { path: \"src/parser.ts\" } },\n\t\t\t],\n\t\t\tapi: \"anthropic-messages\",\n\t\t\tprovider: \"anthropic\",\n\t\t\tmodel: \"claude-sonnet-4-6\",\n\t\t\tusage: {\n\t\t\t\tinput: 0,\n\t\t\t\toutput: 0,\n\t\t\t\tcacheRead: 0,\n\t\t\t\tcacheWrite: 0,\n\t\t\t\ttotalTokens: 0,\n\t\t\t\tcost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, total: 0 },\n\t\t\t},\n\t\t\tstopReason: \"stop\",\n\t\t\ttimestamp: Date.now(),\n\t\t} as Message,\n\t\t{\n\t\t\trole: \"toolResult\",\n\t\t\tcontent: [{ type: \"text\", text: \"parser contents\" }],\n\t\t\ttoolName: \"Read\",\n\t\t\ttoolCallId: \"tool-1\",\n\t\t} as Message,\n\t];\n\n\tconst serialized = serializeConversation(messages);\n\n\tassert.match(serialized, /\\*\\*User said:\\*\\* Please refactor the parser\\./);\n\tassert.match(serialized, /\\*\\*Assistant thinking:\\*\\* I should inspect the parser entry points first\\./);\n\tassert.match(serialized, /\\*\\*Assistant responded:\\*\\* I'll start with the parser entry points\\./);\n\tassert.match(serialized, /\\*\\*Assistant tool calls:\\*\\* Read\\(path=\"src\\/parser\\.ts\"\\)/);\n\tassert.match(serialized, /\\*\\*Tool result:\\*\\* parser contents/);\n\tassert.ok(!serialized.includes(\"[User]:\"), \"chat-style [User]: markers should not remain\");\n\tassert.ok(!serialized.includes(\"[Assistant]:\"), \"chat-style [Assistant]: markers should not remain\");\n\tassert.ok(!serialized.includes(\"[Tool result]:\"), \"chat-style [Tool result]: markers should not remain\");\n});\n"]}
@@ -1,8 +1,14 @@
1
1
  import type { AssistantMessage } from "@gsd/pi-ai";
2
2
  import { Container, type MarkdownTheme } from "@gsd/pi-tui";
3
3
  import { type TimestampFormat } from "./timestamp.js";
4
+ export interface ContentRange {
5
+ startIndex: number;
6
+ endIndex: number;
7
+ }
4
8
  /**
5
- * Component that renders a complete assistant message
9
+ * Component that renders a complete assistant message, or a sub-range of its content[].
10
+ * When `range` is provided, only content[startIndex..endIndex] (inclusive) is rendered.
11
+ * Non-text/thinking blocks within the range are silently skipped.
6
12
  */
7
13
  export declare class AssistantMessageComponent extends Container {
8
14
  private contentContainer;
@@ -10,7 +16,11 @@ export declare class AssistantMessageComponent extends Container {
10
16
  private markdownTheme;
11
17
  private lastMessage?;
12
18
  private timestampFormat;
13
- constructor(message?: AssistantMessage, hideThinkingBlock?: boolean, markdownTheme?: MarkdownTheme, timestampFormat?: TimestampFormat);
19
+ private range?;
20
+ private showMetadata;
21
+ constructor(message?: AssistantMessage, hideThinkingBlock?: boolean, markdownTheme?: MarkdownTheme, timestampFormat?: TimestampFormat, range?: ContentRange);
22
+ setRange(range: ContentRange | undefined): void;
23
+ setShowMetadata(show: boolean): void;
14
24
  invalidate(): void;
15
25
  setHideThinkingBlock(hide: boolean): void;
16
26
  updateContent(message: AssistantMessage): void;
@@ -1 +1 @@
1
- {"version":3,"file":"assistant-message.d.ts","sourceRoot":"","sources":["../../../../src/modes/interactive/components/assistant-message.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AACnD,OAAO,EAAE,SAAS,EAAY,KAAK,aAAa,EAAgB,MAAM,aAAa,CAAC;AAEpF,OAAO,EAAmB,KAAK,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAEvE;;GAEG;AACH,qBAAa,yBAA0B,SAAQ,SAAS;IACvD,OAAO,CAAC,gBAAgB,CAAY;IACpC,OAAO,CAAC,iBAAiB,CAAU;IACnC,OAAO,CAAC,aAAa,CAAgB;IACrC,OAAO,CAAC,WAAW,CAAC,CAAmB;IACvC,OAAO,CAAC,eAAe,CAAkB;gBAGxC,OAAO,CAAC,EAAE,gBAAgB,EAC1B,iBAAiB,UAAQ,EACzB,aAAa,GAAE,aAAkC,EACjD,eAAe,GAAE,eAAiC;IAiB1C,UAAU,IAAI,IAAI;IAO3B,oBAAoB,CAAC,IAAI,EAAE,OAAO,GAAG,IAAI;IAIzC,aAAa,CAAC,OAAO,EAAE,gBAAgB,GAAG,IAAI;CA2E9C"}
1
+ {"version":3,"file":"assistant-message.d.ts","sourceRoot":"","sources":["../../../../src/modes/interactive/components/assistant-message.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AACnD,OAAO,EAAE,SAAS,EAAY,KAAK,aAAa,EAAgB,MAAM,aAAa,CAAC;AAEpF,OAAO,EAAmB,KAAK,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAEvE,MAAM,WAAW,YAAY;IAC5B,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,MAAM,CAAC;CACjB;AAED;;;;GAIG;AACH,qBAAa,yBAA0B,SAAQ,SAAS;IACvD,OAAO,CAAC,gBAAgB,CAAY;IACpC,OAAO,CAAC,iBAAiB,CAAU;IACnC,OAAO,CAAC,aAAa,CAAgB;IACrC,OAAO,CAAC,WAAW,CAAC,CAAmB;IACvC,OAAO,CAAC,eAAe,CAAkB;IACzC,OAAO,CAAC,KAAK,CAAC,CAAe;IAC7B,OAAO,CAAC,YAAY,CAAU;gBAG7B,OAAO,CAAC,EAAE,gBAAgB,EAC1B,iBAAiB,UAAQ,EACzB,aAAa,GAAE,aAAkC,EACjD,eAAe,GAAE,eAAiC,EAClD,KAAK,CAAC,EAAE,YAAY;IAsBrB,QAAQ,CAAC,KAAK,EAAE,YAAY,GAAG,SAAS,GAAG,IAAI;IAO/C,eAAe,CAAC,IAAI,EAAE,OAAO,GAAG,IAAI;IAO3B,UAAU,IAAI,IAAI;IAO3B,oBAAoB,CAAC,IAAI,EAAE,OAAO,GAAG,IAAI;IAIzC,aAAa,CAAC,OAAO,EAAE,gBAAgB,GAAG,IAAI;CAkF9C"}
@@ -2,14 +2,21 @@ import { Container, Markdown, Spacer, Text } from "@gsd/pi-tui";
2
2
  import { getMarkdownTheme, theme } from "../theme/theme.js";
3
3
  import { formatTimestamp } from "./timestamp.js";
4
4
  /**
5
- * Component that renders a complete assistant message
5
+ * Component that renders a complete assistant message, or a sub-range of its content[].
6
+ * When `range` is provided, only content[startIndex..endIndex] (inclusive) is rendered.
7
+ * Non-text/thinking blocks within the range are silently skipped.
6
8
  */
7
9
  export class AssistantMessageComponent extends Container {
8
- constructor(message, hideThinkingBlock = false, markdownTheme = getMarkdownTheme(), timestampFormat = "date-time-iso") {
10
+ constructor(message, hideThinkingBlock = false, markdownTheme = getMarkdownTheme(), timestampFormat = "date-time-iso", range) {
9
11
  super();
10
12
  this.hideThinkingBlock = hideThinkingBlock;
11
13
  this.markdownTheme = markdownTheme;
12
14
  this.timestampFormat = timestampFormat;
15
+ this.range = range;
16
+ // No range = legacy full-message rendering; show metadata by default.
17
+ // Ranged (interleaved) instances start with metadata hidden; chat-controller
18
+ // calls setShowMetadata(true) on the last segment at message_end.
19
+ this.showMetadata = !range;
13
20
  // Container for text/thinking content
14
21
  this.contentContainer = new Container();
15
22
  this.addChild(this.contentContainer);
@@ -17,6 +24,18 @@ export class AssistantMessageComponent extends Container {
17
24
  this.updateContent(message);
18
25
  }
19
26
  }
27
+ setRange(range) {
28
+ this.range = range;
29
+ if (this.lastMessage) {
30
+ this.updateContent(this.lastMessage);
31
+ }
32
+ }
33
+ setShowMetadata(show) {
34
+ this.showMetadata = show;
35
+ if (this.lastMessage) {
36
+ this.updateContent(this.lastMessage);
37
+ }
38
+ }
20
39
  invalidate() {
21
40
  super.invalidate();
22
41
  if (this.lastMessage) {
@@ -30,13 +49,16 @@ export class AssistantMessageComponent extends Container {
30
49
  this.lastMessage = message;
31
50
  // Clear content container
32
51
  this.contentContainer.clear();
33
- const hasVisibleContent = message.content.some((c) => (c.type === "text" && c.text.trim()) || (c.type === "thinking" && c.thinking.trim()));
52
+ const start = this.range?.startIndex ?? 0;
53
+ const end = this.range?.endIndex ?? message.content.length - 1;
54
+ const slice = message.content.slice(start, end + 1);
55
+ const hasVisibleContent = slice.some((c) => (c.type === "text" && c.text.trim()) || (c.type === "thinking" && c.thinking.trim()));
34
56
  if (hasVisibleContent) {
35
57
  this.contentContainer.addChild(new Spacer(1));
36
58
  }
37
- // Render content in order
38
- for (let i = 0; i < message.content.length; i++) {
39
- const content = message.content[i];
59
+ // Render content in order; non-text/thinking blocks are silently skipped
60
+ for (let i = 0; i < slice.length; i++) {
61
+ const content = slice[i];
40
62
  if (content.type === "text" && content.text.trim()) {
41
63
  // Assistant text messages with no background - trim the text
42
64
  // Set paddingY=0 to avoid extra spacing before tool executions
@@ -45,7 +67,7 @@ export class AssistantMessageComponent extends Container {
45
67
  else if (content.type === "thinking" && content.thinking.trim()) {
46
68
  // Add spacing only when another visible assistant content block follows.
47
69
  // This avoids a superfluous blank line before separately-rendered tool execution blocks.
48
- const hasVisibleContentAfter = message.content
70
+ const hasVisibleContentAfter = slice
49
71
  .slice(i + 1)
50
72
  .some((c) => (c.type === "text" && c.text.trim()) || (c.type === "thinking" && c.thinking.trim()));
51
73
  if (this.hideThinkingBlock) {
@@ -67,30 +89,33 @@ export class AssistantMessageComponent extends Container {
67
89
  }
68
90
  }
69
91
  }
70
- // Check if aborted - show after partial content
71
- // But only if there are no tool calls (tool execution components will show the error)
72
- const hasToolCalls = message.content.some((c) => c.type === "toolCall");
73
- if (!hasToolCalls) {
74
- if (message.stopReason === "aborted") {
75
- const abortMessage = message.errorMessage && message.errorMessage !== "Request was aborted"
76
- ? message.errorMessage
77
- : "Operation aborted";
78
- if (hasVisibleContent) {
92
+ // Metadata (errors, timestamp): gated on showMetadata so ranged instances stay clean
93
+ // until chat-controller explicitly enables it on the last segment at message_end.
94
+ if (this.showMetadata) {
95
+ // Check if aborted - show after partial content
96
+ // But only if there are no tool calls (tool execution components will show the error)
97
+ const hasToolCalls = message.content.some((c) => c.type === "toolCall");
98
+ if (!hasToolCalls) {
99
+ if (message.stopReason === "aborted") {
100
+ const abortMessage = message.errorMessage && message.errorMessage !== "Request was aborted"
101
+ ? message.errorMessage
102
+ : "Operation aborted";
103
+ if (hasVisibleContent) {
104
+ this.contentContainer.addChild(new Spacer(1));
105
+ }
106
+ this.contentContainer.addChild(new Text(theme.fg("error", abortMessage), 1, 0));
107
+ }
108
+ else if (message.stopReason === "error") {
109
+ const errorMsg = message.errorMessage || "Unknown error";
79
110
  this.contentContainer.addChild(new Spacer(1));
111
+ this.contentContainer.addChild(new Text(theme.fg("error", `Error: ${errorMsg}`), 1, 0));
80
112
  }
81
- this.contentContainer.addChild(new Text(theme.fg("error", abortMessage), 1, 0));
82
113
  }
83
- else if (message.stopReason === "error") {
84
- const errorMsg = message.errorMessage || "Unknown error";
85
- this.contentContainer.addChild(new Spacer(1));
86
- this.contentContainer.addChild(new Text(theme.fg("error", `Error: ${errorMsg}`), 1, 0));
114
+ if (message.stopReason && message.timestamp) {
115
+ const timeStr = formatTimestamp(message.timestamp, this.timestampFormat);
116
+ this.contentContainer.addChild(new Text(theme.fg("dim", timeStr), 1, 0));
87
117
  }
88
118
  }
89
- // Show timestamp when the message is complete (has a stop reason)
90
- if (message.stopReason && message.timestamp) {
91
- const timeStr = formatTimestamp(message.timestamp, this.timestampFormat);
92
- this.contentContainer.addChild(new Text(theme.fg("dim", timeStr), 1, 0));
93
- }
94
119
  }
95
120
  }
96
121
  //# sourceMappingURL=assistant-message.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"assistant-message.js","sourceRoot":"","sources":["../../../../src/modes/interactive/components/assistant-message.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAsB,MAAM,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AACpF,OAAO,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BACtB,CAAC,CAAC,mBAAmB,CAAC;gBACxB,IAAI,iBAAiB,EAAE,CAAC;oBACvB,IAAI,CAAC,gBAAgB,CAAC,QAAQ,CAAC,IAAI,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;gBAC/C,CAAC;gBACD,IAAI,CAAC,gBAAgB,CAAC,QAAQ,CAAC,IAAI,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,OAAO,EAAE,YAAY,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;YACjF,CAAC;iBAAM,IAAI,OAAO,CAAC,UAAU,KAAK,OAAO,EAAE,CAAC;gBAC3C,MAAM,QAAQ,GAAG,OAAO,CAAC,YAAY,IAAI,eAAe,CAAC;gBACzD,IAAI,CAAC,gBAAgB,CAAC,QAAQ,CAAC,IAAI,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;gBAC9C,IAAI,CAAC,gBAAgB,CAAC,QAAQ,CAAC,IAAI,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,OAAO,EAAE,UAAU,QAAQ,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;YACzF,CAAC;QACF,CAAC;QAED,kEAAkE;QAClE,IAAI,OAAO,CAAC,UAAU,IAAI,OAAO,CAAC,SAAS,EAAE,CAAC;YAC7C,MAAM,OAAO,GAAG,eAAe,CAAC,OAAO,CAAC,SAAS,EAAE,IAAI,CAAC,eAAe,CAAC,CAAC;YACzE,IAAI,CAAC,gBAAgB,CAAC,QAAQ,CAAC,IAAI,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;QAC1E,CAAC;IACF,CAAC;CACD","sourcesContent":["import type { AssistantMessage } from \"@gsd/pi-ai\";\nimport { Container, Markdown, type MarkdownTheme, Spacer, Text } from \"@gsd/pi-tui\";\nimport { getMarkdownTheme, theme } from \"../theme/theme.js\";\nimport { formatTimestamp, type TimestampFormat } from \"./timestamp.js\";\n\n/**\n * Component that renders a complete assistant message\n */\nexport class AssistantMessageComponent extends Container {\n\tprivate contentContainer: Container;\n\tprivate hideThinkingBlock: boolean;\n\tprivate markdownTheme: MarkdownTheme;\n\tprivate lastMessage?: AssistantMessage;\n\tprivate timestampFormat: TimestampFormat;\n\n\tconstructor(\n\t\tmessage?: AssistantMessage,\n\t\thideThinkingBlock = false,\n\t\tmarkdownTheme: MarkdownTheme = getMarkdownTheme(),\n\t\ttimestampFormat: TimestampFormat = \"date-time-iso\",\n\t) {\n\t\tsuper();\n\n\t\tthis.hideThinkingBlock = hideThinkingBlock;\n\t\tthis.markdownTheme = markdownTheme;\n\t\tthis.timestampFormat = timestampFormat;\n\n\t\t// Container for text/thinking content\n\t\tthis.contentContainer = new Container();\n\t\tthis.addChild(this.contentContainer);\n\n\t\tif (message) {\n\t\t\tthis.updateContent(message);\n\t\t}\n\t}\n\n\toverride invalidate(): void {\n\t\tsuper.invalidate();\n\t\tif (this.lastMessage) {\n\t\t\tthis.updateContent(this.lastMessage);\n\t\t}\n\t}\n\n\tsetHideThinkingBlock(hide: boolean): void {\n\t\tthis.hideThinkingBlock = hide;\n\t}\n\n\tupdateContent(message: AssistantMessage): void {\n\t\tthis.lastMessage = message;\n\n\t\t// Clear content container\n\t\tthis.contentContainer.clear();\n\n\t\tconst hasVisibleContent = message.content.some(\n\t\t\t(c) => (c.type === \"text\" && c.text.trim()) || (c.type === \"thinking\" && c.thinking.trim()),\n\t\t);\n\n\t\tif (hasVisibleContent) {\n\t\t\tthis.contentContainer.addChild(new Spacer(1));\n\t\t}\n\n\t\t// Render content in order\n\t\tfor (let i = 0; i < message.content.length; i++) {\n\t\t\tconst content = message.content[i];\n\t\t\tif (content.type === \"text\" && content.text.trim()) {\n\t\t\t\t// Assistant text messages with no background - trim the text\n\t\t\t\t// Set paddingY=0 to avoid extra spacing before tool executions\n\t\t\t\tthis.contentContainer.addChild(new Markdown(content.text.trim(), 1, 0, this.markdownTheme));\n\t\t\t} else if (content.type === \"thinking\" && content.thinking.trim()) {\n\t\t\t\t// Add spacing only when another visible assistant content block follows.\n\t\t\t\t// This avoids a superfluous blank line before separately-rendered tool execution blocks.\n\t\t\t\tconst hasVisibleContentAfter = message.content\n\t\t\t\t\t.slice(i + 1)\n\t\t\t\t\t.some((c) => (c.type === \"text\" && c.text.trim()) || (c.type === \"thinking\" && c.thinking.trim()));\n\n\t\t\t\tif (this.hideThinkingBlock) {\n\t\t\t\t\t// Show static \"Thinking...\" label when hidden\n\t\t\t\t\tthis.contentContainer.addChild(new Text(theme.italic(theme.fg(\"thinkingText\", \"Thinking...\")), 1, 0));\n\t\t\t\t\tif (hasVisibleContentAfter) {\n\t\t\t\t\t\tthis.contentContainer.addChild(new Spacer(1));\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\t// Thinking traces in thinkingText color, italic\n\t\t\t\t\tthis.contentContainer.addChild(\n\t\t\t\t\t\tnew Markdown(content.thinking.trim(), 1, 0, this.markdownTheme, {\n\t\t\t\t\t\t\tcolor: (text: string) => theme.fg(\"thinkingText\", text),\n\t\t\t\t\t\t\titalic: true,\n\t\t\t\t\t\t}),\n\t\t\t\t\t);\n\t\t\t\t\tif (hasVisibleContentAfter) {\n\t\t\t\t\t\tthis.contentContainer.addChild(new Spacer(1));\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\t// Check if aborted - show after partial content\n\t\t// But only if there are no tool calls (tool execution components will show the error)\n\t\tconst hasToolCalls = message.content.some((c) => c.type === \"toolCall\");\n\t\tif (!hasToolCalls) {\n\t\t\tif (message.stopReason === \"aborted\") {\n\t\t\t\tconst abortMessage =\n\t\t\t\t\tmessage.errorMessage && message.errorMessage !== \"Request was aborted\"\n\t\t\t\t\t\t? message.errorMessage\n\t\t\t\t\t\t: \"Operation aborted\";\n\t\t\t\tif (hasVisibleContent) {\n\t\t\t\t\tthis.contentContainer.addChild(new Spacer(1));\n\t\t\t\t}\n\t\t\t\tthis.contentContainer.addChild(new Text(theme.fg(\"error\", abortMessage), 1, 0));\n\t\t\t} else if (message.stopReason === \"error\") {\n\t\t\t\tconst errorMsg = message.errorMessage || \"Unknown error\";\n\t\t\t\tthis.contentContainer.addChild(new Spacer(1));\n\t\t\t\tthis.contentContainer.addChild(new Text(theme.fg(\"error\", `Error: ${errorMsg}`), 1, 0));\n\t\t\t}\n\t\t}\n\n\t\t// Show timestamp when the message is complete (has a stop reason)\n\t\tif (message.stopReason && message.timestamp) {\n\t\t\tconst timeStr = formatTimestamp(message.timestamp, this.timestampFormat);\n\t\t\tthis.contentContainer.addChild(new Text(theme.fg(\"dim\", timeStr), 1, 0));\n\t\t}\n\t}\n}\n"]}
1
+ {"version":3,"file":"assistant-message.js","sourceRoot":"","sources":["../../../../src/modes/interactive/components/assistant-message.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAsB,MAAM,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AACpF,OAAO,EAAE,gBAAgB,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAC5D,OAAO,EAAE,eAAe,EAAwB,MAAM,gBAAgB,CAAC;AAOvE;;;;GAIG;AACH,MAAM,OAAO,yBAA0B,SAAQ,SAAS;IASvD,YACC,OAA0B,EAC1B,iBAAiB,GAAG,KAAK,EACzB,gBAA+B,gBAAgB,EAAE,EACjD,kBAAmC,eAAe,EAClD,KAAoB;QAEpB,KAAK,EAAE,CAAC;QAER,IAAI,CAAC,iBAAiB,GAAG,iBAAiB,CAAC;QAC3C,IAAI,CAAC,aAAa,GAAG,aAAa,CAAC;QACnC,IAAI,CAAC,eAAe,GAAG,eAAe,CAAC;QACvC,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,sEAAsE;QACtE,6EAA6E;QAC7E,kEAAkE;QAClE,IAAI,CAAC,YAAY,GAAG,CAAC,KAAK,CAAC;QAE3B,sCAAsC;QACtC,IAAI,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,CAAC,KAAK,EAAE,OAAO,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;YAC1E,CAAC;QACF,CAAC;IACF,CAAC;CACD","sourcesContent":["import type { AssistantMessage } from \"@gsd/pi-ai\";\nimport { Container, Markdown, type MarkdownTheme, Spacer, Text } from \"@gsd/pi-tui\";\nimport { getMarkdownTheme, theme } from \"../theme/theme.js\";\nimport { formatTimestamp, type TimestampFormat } from \"./timestamp.js\";\n\nexport interface ContentRange {\n\tstartIndex: number;\n\tendIndex: number;\n}\n\n/**\n * Component that renders a complete assistant message, or a sub-range of its content[].\n * When `range` is provided, only content[startIndex..endIndex] (inclusive) is rendered.\n * Non-text/thinking blocks within the range are silently skipped.\n */\nexport class AssistantMessageComponent extends Container {\n\tprivate contentContainer: Container;\n\tprivate hideThinkingBlock: boolean;\n\tprivate markdownTheme: MarkdownTheme;\n\tprivate lastMessage?: AssistantMessage;\n\tprivate timestampFormat: TimestampFormat;\n\tprivate range?: ContentRange;\n\tprivate showMetadata: boolean;\n\n\tconstructor(\n\t\tmessage?: AssistantMessage,\n\t\thideThinkingBlock = false,\n\t\tmarkdownTheme: MarkdownTheme = getMarkdownTheme(),\n\t\ttimestampFormat: TimestampFormat = \"date-time-iso\",\n\t\trange?: ContentRange,\n\t) {\n\t\tsuper();\n\n\t\tthis.hideThinkingBlock = hideThinkingBlock;\n\t\tthis.markdownTheme = markdownTheme;\n\t\tthis.timestampFormat = timestampFormat;\n\t\tthis.range = range;\n\t\t// No range = legacy full-message rendering; show metadata by default.\n\t\t// Ranged (interleaved) instances start with metadata hidden; chat-controller\n\t\t// calls setShowMetadata(true) on the last segment at message_end.\n\t\tthis.showMetadata = !range;\n\n\t\t// Container for text/thinking content\n\t\tthis.contentContainer = new Container();\n\t\tthis.addChild(this.contentContainer);\n\n\t\tif (message) {\n\t\t\tthis.updateContent(message);\n\t\t}\n\t}\n\n\tsetRange(range: ContentRange | undefined): void {\n\t\tthis.range = range;\n\t\tif (this.lastMessage) {\n\t\t\tthis.updateContent(this.lastMessage);\n\t\t}\n\t}\n\n\tsetShowMetadata(show: boolean): void {\n\t\tthis.showMetadata = show;\n\t\tif (this.lastMessage) {\n\t\t\tthis.updateContent(this.lastMessage);\n\t\t}\n\t}\n\n\toverride invalidate(): void {\n\t\tsuper.invalidate();\n\t\tif (this.lastMessage) {\n\t\t\tthis.updateContent(this.lastMessage);\n\t\t}\n\t}\n\n\tsetHideThinkingBlock(hide: boolean): void {\n\t\tthis.hideThinkingBlock = hide;\n\t}\n\n\tupdateContent(message: AssistantMessage): void {\n\t\tthis.lastMessage = message;\n\n\t\t// Clear content container\n\t\tthis.contentContainer.clear();\n\n\t\tconst start = this.range?.startIndex ?? 0;\n\t\tconst end = this.range?.endIndex ?? message.content.length - 1;\n\t\tconst slice = message.content.slice(start, end + 1);\n\n\t\tconst hasVisibleContent = slice.some(\n\t\t\t(c) => (c.type === \"text\" && c.text.trim()) || (c.type === \"thinking\" && c.thinking.trim()),\n\t\t);\n\n\t\tif (hasVisibleContent) {\n\t\t\tthis.contentContainer.addChild(new Spacer(1));\n\t\t}\n\n\t\t// Render content in order; non-text/thinking blocks are silently skipped\n\t\tfor (let i = 0; i < slice.length; i++) {\n\t\t\tconst content = slice[i];\n\t\t\tif (content.type === \"text\" && content.text.trim()) {\n\t\t\t\t// Assistant text messages with no background - trim the text\n\t\t\t\t// Set paddingY=0 to avoid extra spacing before tool executions\n\t\t\t\tthis.contentContainer.addChild(new Markdown(content.text.trim(), 1, 0, this.markdownTheme));\n\t\t\t} else if (content.type === \"thinking\" && content.thinking.trim()) {\n\t\t\t\t// Add spacing only when another visible assistant content block follows.\n\t\t\t\t// This avoids a superfluous blank line before separately-rendered tool execution blocks.\n\t\t\t\tconst hasVisibleContentAfter = slice\n\t\t\t\t\t.slice(i + 1)\n\t\t\t\t\t.some((c) => (c.type === \"text\" && c.text.trim()) || (c.type === \"thinking\" && c.thinking.trim()));\n\n\t\t\t\tif (this.hideThinkingBlock) {\n\t\t\t\t\t// Show static \"Thinking...\" label when hidden\n\t\t\t\t\tthis.contentContainer.addChild(new Text(theme.italic(theme.fg(\"thinkingText\", \"Thinking...\")), 1, 0));\n\t\t\t\t\tif (hasVisibleContentAfter) {\n\t\t\t\t\t\tthis.contentContainer.addChild(new Spacer(1));\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\t// Thinking traces in thinkingText color, italic\n\t\t\t\t\tthis.contentContainer.addChild(\n\t\t\t\t\t\tnew Markdown(content.thinking.trim(), 1, 0, this.markdownTheme, {\n\t\t\t\t\t\t\tcolor: (text: string) => theme.fg(\"thinkingText\", text),\n\t\t\t\t\t\t\titalic: true,\n\t\t\t\t\t\t}),\n\t\t\t\t\t);\n\t\t\t\t\tif (hasVisibleContentAfter) {\n\t\t\t\t\t\tthis.contentContainer.addChild(new Spacer(1));\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\t// Metadata (errors, timestamp): gated on showMetadata so ranged instances stay clean\n\t\t// until chat-controller explicitly enables it on the last segment at message_end.\n\t\tif (this.showMetadata) {\n\t\t\t// Check if aborted - show after partial content\n\t\t\t// But only if there are no tool calls (tool execution components will show the error)\n\t\t\tconst hasToolCalls = message.content.some((c) => c.type === \"toolCall\");\n\t\t\tif (!hasToolCalls) {\n\t\t\t\tif (message.stopReason === \"aborted\") {\n\t\t\t\t\tconst abortMessage =\n\t\t\t\t\t\tmessage.errorMessage && message.errorMessage !== \"Request was aborted\"\n\t\t\t\t\t\t\t? message.errorMessage\n\t\t\t\t\t\t\t: \"Operation aborted\";\n\t\t\t\t\tif (hasVisibleContent) {\n\t\t\t\t\t\tthis.contentContainer.addChild(new Spacer(1));\n\t\t\t\t\t}\n\t\t\t\t\tthis.contentContainer.addChild(new Text(theme.fg(\"error\", abortMessage), 1, 0));\n\t\t\t\t} else if (message.stopReason === \"error\") {\n\t\t\t\t\tconst errorMsg = message.errorMessage || \"Unknown error\";\n\t\t\t\t\tthis.contentContainer.addChild(new Spacer(1));\n\t\t\t\t\tthis.contentContainer.addChild(new Text(theme.fg(\"error\", `Error: ${errorMsg}`), 1, 0));\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (message.stopReason && message.timestamp) {\n\t\t\t\tconst timeStr = formatTimestamp(message.timestamp, this.timestampFormat);\n\t\t\t\tthis.contentContainer.addChild(new Text(theme.fg(\"dim\", timeStr), 1, 0));\n\t\t\t}\n\t\t}\n\t}\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"chat-controller.d.ts","sourceRoot":"","sources":["../../../../src/modes/interactive/controllers/chat-controller.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,oBAAoB,EAAE,wBAAwB,EAAE,MAAM,8BAA8B,CAAC;AA0BnG,wBAAgB,sBAAsB,CAAC,aAAa,EAAE,KAAK,CAAC,GAAG,CAAC,GAAG,MAAM,CAgBxE;AAWD,wBAAsB,gBAAgB,CAAC,IAAI,EAAE,wBAAwB,GAAG;IACvE,IAAI,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IAC1B,4BAA4B,EAAE,MAAM,GAAG,CAAC;IACxC,gBAAgB,EAAE,CAAC,OAAO,EAAE,GAAG,EAAE,OAAO,CAAC,EAAE,GAAG,KAAK,IAAI,CAAC;IACxD,qBAAqB,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,MAAM,CAAC;IACpD,2BAA2B,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,GAAG,CAAC;IACvD,sBAAsB,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IAC5C,uBAAuB,EAAE,MAAM,IAAI,CAAC;IACpC,oBAAoB,EAAE,CAAC,OAAO,CAAC,EAAE;QAAE,SAAS,CAAC,EAAE,OAAO,CAAA;KAAE,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAC3E,UAAU,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;IACtC,SAAS,EAAE,CAAC,OAA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,KAAK,IAAI,CAAC;IACrC,4BAA4B,EAAE,MAAM,IAAI,CAAC;IACzC,mBAAmB,EAAE,MAAM,IAAI,CAAC;IAChC,uBAAuB,EAAE,MAAM,IAAI,CAAC;IACpC,wBAAwB,EAAE;QAAE,KAAK,EAAE,MAAM,IAAI,CAAA;KAAE,CAAC;CAChD,EAAE,KAAK,EAAE,oBAAoB,GAAG,OAAO,CAAC,IAAI,CAAC,CA0jB7C"}
@@ -6,6 +6,7 @@ import { DynamicBorder } from "../components/dynamic-border.js";
6
6
  import { appKey } from "../components/keybinding-hints.js";
7
7
  // Tracks the last processed content index to avoid re-scanning all blocks on every message_update
8
8
  let lastProcessedContentIndex = 0;
9
+ let renderedSegments = [];
9
10
  function hasVisibleAssistantContent(message) {
10
11
  return message.content.some((c) => (c.type === "text" && typeof c.text === "string" && c.text.trim().length > 0)
11
12
  || (c.type === "thinking" && typeof c.thinking === "string" && c.thinking.trim().length > 0));
@@ -52,6 +53,7 @@ export async function handleAgentEvent(host, event) {
52
53
  lastProcessedContentIndex = 0;
53
54
  lastPinnedText = "";
54
55
  hasToolsInTurn = false;
56
+ renderedSegments = [];
55
57
  if (pinnedBorder)
56
58
  pinnedBorder.stopSpinner();
57
59
  pinnedBorder = undefined;
@@ -71,6 +73,7 @@ export async function handleAgentEvent(host, event) {
71
73
  host.pinnedMessageContainer.clear();
72
74
  lastPinnedText = "";
73
75
  hasToolsInTurn = false;
76
+ renderedSegments = [];
74
77
  if (pinnedBorder)
75
78
  pinnedBorder.stopSpinner();
76
79
  pinnedBorder = undefined;
@@ -228,19 +231,75 @@ export async function handleAgentEvent(host, event) {
228
231
  });
229
232
  }
230
233
  }
231
- // Render assistant text/thinking after tool components so mixed
232
- // streams keep chronological ordering in the chat container.
233
- const hasToolBlocks = hasAssistantToolBlocks(host.streamingMessage);
234
- if (!host.streamingComponent && hasVisibleAssistantContent(host.streamingMessage)) {
235
- host.streamingComponent = new AssistantMessageComponent(undefined, host.hideThinkingBlock, host.getMarkdownThemeWithSettings(), host.settingsManager.getTimestampFormat());
236
- host.chatContainer.addChild(host.streamingComponent);
237
- }
238
- if (host.streamingComponent) {
239
- if (hasToolBlocks) {
240
- host.chatContainer.removeChild(host.streamingComponent);
241
- host.chatContainer.addChild(host.streamingComponent);
234
+ // Segment walker: render content blocks in stream order, append-only.
235
+ // Build desired segment plan from content[].
236
+ {
237
+ const blocks = host.streamingMessage.content;
238
+ const desired = [];
239
+ let runStart = -1;
240
+ for (let i = 0; i < blocks.length; i++) {
241
+ const b = blocks[i];
242
+ const isText = b.type === "text" || b.type === "thinking";
243
+ const isTool = b.type === "toolCall" || b.type === "serverToolUse";
244
+ if (isText) {
245
+ if (runStart === -1)
246
+ runStart = i;
247
+ }
248
+ else {
249
+ if (runStart !== -1) {
250
+ desired.push({ kind: "text-run", startIndex: runStart, endIndex: i - 1 });
251
+ runStart = -1;
252
+ }
253
+ if (isTool) {
254
+ desired.push({ kind: "tool", contentIndex: i, toolId: b.id });
255
+ }
256
+ }
257
+ }
258
+ if (runStart !== -1) {
259
+ desired.push({ kind: "text-run", startIndex: runStart, endIndex: blocks.length - 1 });
260
+ }
261
+ // Append any newly needed segments (never reorder existing ones).
262
+ for (const seg of desired) {
263
+ if (seg.kind === "tool") {
264
+ // Tool segments are already handled above via pendingTools; just
265
+ // register them in renderedSegments if not yet tracked.
266
+ const existing = renderedSegments.find((s) => s.kind === "tool" && s.contentIndex === seg.contentIndex);
267
+ if (!existing) {
268
+ const comp = host.pendingTools.get(seg.toolId);
269
+ if (comp) {
270
+ renderedSegments.push({ kind: "tool", contentIndex: seg.contentIndex, component: comp });
271
+ }
272
+ }
273
+ }
274
+ else {
275
+ // text-run segment
276
+ const existing = renderedSegments.find((s) => s.kind === "text-run" && s.startIndex === seg.startIndex);
277
+ if (!existing) {
278
+ const comp = new AssistantMessageComponent(undefined, host.hideThinkingBlock, host.getMarkdownThemeWithSettings(), host.settingsManager.getTimestampFormat(), { startIndex: seg.startIndex, endIndex: seg.endIndex });
279
+ host.chatContainer.addChild(comp);
280
+ renderedSegments.push({ kind: "text-run", startIndex: seg.startIndex, endIndex: seg.endIndex, component: comp });
281
+ host.streamingComponent = comp;
282
+ }
283
+ }
284
+ }
285
+ // Update all trailing text-run segments with the latest message so
286
+ // streaming text grows in place.
287
+ for (const seg of renderedSegments) {
288
+ if (seg.kind === "text-run") {
289
+ // Find corresponding desired segment to get current endIndex
290
+ const d = desired.find((ds) => ds.kind === "text-run" && ds.startIndex === seg.startIndex);
291
+ if (d && d.kind === "text-run" && d.endIndex !== seg.endIndex) {
292
+ seg.endIndex = d.endIndex;
293
+ seg.component.setRange({ startIndex: seg.startIndex, endIndex: seg.endIndex });
294
+ }
295
+ seg.component.updateContent(host.streamingMessage);
296
+ }
297
+ }
298
+ // Keep streamingComponent pointing at the last text-run for message_end compatibility.
299
+ const lastTextSeg = [...renderedSegments].reverse().find((s) => s.kind === "text-run");
300
+ if (lastTextSeg && lastTextSeg.kind === "text-run") {
301
+ host.streamingComponent = lastTextSeg.component;
242
302
  }
243
- host.streamingComponent.updateContent(host.streamingMessage);
244
303
  }
245
304
  // Update index: fully processed blocks won't need re-scanning.
246
305
  // Keep the last block's index (it may still be accumulating data),
@@ -309,6 +368,7 @@ export async function handleAgentEvent(host, event) {
309
368
  host.chatContainer.addChild(host.streamingComponent);
310
369
  }
311
370
  if (host.streamingComponent) {
371
+ host.streamingComponent.setShowMetadata(true);
312
372
  host.streamingComponent.updateContent(host.streamingMessage);
313
373
  }
314
374
  if (host.streamingMessage.stopReason === "aborted" || host.streamingMessage.stopReason === "error") {
@@ -332,6 +392,7 @@ export async function handleAgentEvent(host, event) {
332
392
  }
333
393
  host.streamingComponent = undefined;
334
394
  host.streamingMessage = undefined;
395
+ renderedSegments = [];
335
396
  // Clear pinned output once the message is finalized in the chat
336
397
  // container — prevents duplicate display when the agent continues
337
398
  // (e.g. form elicitation) after the assistant message ends.