@denizokcu/haze 0.10.0 → 1.0.0

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 (294) hide show
  1. package/CHANGELOG.md +100 -1
  2. package/README.md +77 -27
  3. package/SECURITY.md +22 -0
  4. package/bin/haze.js +102 -1
  5. package/dist/buildInfo.json +7 -0
  6. package/dist/cli/chat/TaskBar.d.ts +2 -1
  7. package/dist/cli/chat/TaskBar.js +7 -4
  8. package/dist/cli/chat/chatMetrics.d.ts +2 -2
  9. package/dist/cli/chat/chatMetrics.js +1 -1
  10. package/dist/cli/chat/contextReport.js +2 -0
  11. package/dist/cli/chat/fileMentionSuggestions.js +3 -2
  12. package/dist/cli/chat/inputSuggestions.d.ts +8 -16
  13. package/dist/cli/chat/inputSuggestions.js +9 -41
  14. package/dist/cli/chat/liveRegion.d.ts +25 -0
  15. package/dist/cli/chat/liveRegion.js +48 -0
  16. package/dist/cli/chat/messages.d.ts +33 -4
  17. package/dist/cli/chat/messages.js +218 -35
  18. package/dist/cli/chat/sessionLifecycle.d.ts +11 -1
  19. package/dist/cli/chat/sessionLifecycle.js +64 -14
  20. package/dist/cli/chat/sessionRecorder.js +75 -7
  21. package/dist/cli/chat/startupInfo.d.ts +0 -1
  22. package/dist/cli/chat/startupInfo.js +11 -15
  23. package/dist/cli/chat/turnState.d.ts +1 -1
  24. package/dist/cli/chat/wizardDispatch.d.ts +90 -28
  25. package/dist/cli/chat/wizardDispatch.js +349 -133
  26. package/dist/cli/commands/chat.d.ts +5 -0
  27. package/dist/cli/commands/chat.js +216 -172
  28. package/dist/cli/commands/chatModes.d.ts +8 -1
  29. package/dist/cli/commands/chatModes.js +9 -44
  30. package/dist/cli/commands/commands.d.ts +2 -0
  31. package/dist/cli/commands/commands.js +10 -5
  32. package/dist/cli/commands/doctor.d.ts +19 -0
  33. package/dist/cli/commands/doctor.js +76 -0
  34. package/dist/cli/commands/formatters.d.ts +3 -3
  35. package/dist/cli/commands/formatters.js +8 -25
  36. package/dist/cli/commands/ndjsonSink.d.ts +23 -0
  37. package/dist/cli/commands/ndjsonSink.js +38 -0
  38. package/dist/cli/commands/providerWizard.d.ts +9 -2
  39. package/dist/cli/commands/providerWizard.js +39 -7
  40. package/dist/cli/commands/runCommand.d.ts +3 -0
  41. package/dist/cli/commands/runCommand.js +117 -11
  42. package/dist/cli/commands/serverWizard.d.ts +34 -0
  43. package/dist/cli/commands/{mcpWizard.js → serverWizard.js} +44 -2
  44. package/dist/cli/commands/skillsWizard.d.ts +41 -0
  45. package/dist/cli/commands/{skillWizard.js → skillsWizard.js} +33 -11
  46. package/dist/cli/commands/streaming/abortCause.d.ts +25 -0
  47. package/dist/cli/commands/streaming/abortCause.js +16 -0
  48. package/dist/cli/commands/streaming/agentAttempt.d.ts +43 -0
  49. package/dist/cli/commands/streaming/agentAttempt.js +79 -0
  50. package/dist/cli/commands/streaming/assistantText.js +9 -2
  51. package/dist/cli/commands/streaming/attemptLifecycle.d.ts +56 -0
  52. package/dist/cli/commands/streaming/attemptLifecycle.js +110 -0
  53. package/dist/cli/commands/streaming/attemptOutcome.d.ts +96 -0
  54. package/dist/cli/commands/streaming/attemptOutcome.js +206 -0
  55. package/dist/cli/commands/streaming/attemptSetup.d.ts +78 -0
  56. package/dist/cli/commands/streaming/attemptSetup.js +167 -0
  57. package/dist/cli/commands/streaming/goalCheckpoint.d.ts +65 -0
  58. package/dist/cli/commands/streaming/goalCheckpoint.js +23 -0
  59. package/dist/cli/commands/streaming/goalSupervisor.d.ts +64 -0
  60. package/dist/cli/commands/streaming/goalSupervisor.js +130 -0
  61. package/dist/cli/commands/streaming/stallRecovery.d.ts +94 -0
  62. package/dist/cli/commands/streaming/stallRecovery.js +105 -0
  63. package/dist/cli/commands/streaming/streamLoop.d.ts +72 -0
  64. package/dist/cli/commands/streaming/streamLoop.js +448 -0
  65. package/dist/cli/commands/streaming/toolCallRecovery.d.ts +16 -0
  66. package/dist/cli/commands/streaming/toolCallRecovery.js +80 -0
  67. package/dist/cli/commands/streaming/toolGroupRenderer.d.ts +31 -1
  68. package/dist/cli/commands/streaming/toolGroupRenderer.js +50 -4
  69. package/dist/cli/commands/streaming/toolResultState.d.ts +6 -1
  70. package/dist/cli/commands/streaming/toolResultState.js +29 -7
  71. package/dist/cli/commands/streaming/turnRuntime.d.ts +4 -0
  72. package/dist/cli/commands/streaming/turnRuntime.js +6 -0
  73. package/dist/cli/commands/streaming.d.ts +65 -9
  74. package/dist/cli/commands/streaming.js +133 -430
  75. package/dist/cli/commands/wizardFlow.d.ts +334 -0
  76. package/dist/cli/commands/wizardFlow.js +377 -0
  77. package/dist/cli/contextReport.js +3 -0
  78. package/dist/cli/index.js +68 -22
  79. package/dist/cli/terminalTitle.js +1 -1
  80. package/dist/config/contextFiles.js +9 -3
  81. package/dist/config/inputHistory.d.ts +0 -1
  82. package/dist/config/inputHistory.js +1 -1
  83. package/dist/config/modelDiscovery.d.ts +36 -0
  84. package/dist/config/modelDiscovery.js +164 -1
  85. package/dist/config/privateStorage.js +28 -2
  86. package/dist/config/providerAuth.d.ts +14 -0
  87. package/dist/config/providerAuth.js +49 -0
  88. package/dist/config/providerPresets.d.ts +39 -7
  89. package/dist/config/providerPresets.js +371 -100
  90. package/dist/config/providers.js +2 -0
  91. package/dist/config/settings.d.ts +43 -0
  92. package/dist/config/settings.js +12 -0
  93. package/dist/config/skillSettings.js +4 -4
  94. package/dist/config/updateCheck.d.ts +0 -1
  95. package/dist/config/updateCheck.js +1 -1
  96. package/dist/core/agent/budgets.d.ts +73 -1
  97. package/dist/core/agent/budgets.js +94 -1
  98. package/dist/core/agent/compaction.d.ts +38 -0
  99. package/dist/core/agent/compaction.js +92 -17
  100. package/dist/core/agent/completionController.d.ts +224 -0
  101. package/dist/core/agent/completionController.js +296 -0
  102. package/dist/core/agent/contextBudget.d.ts +36 -2
  103. package/dist/core/agent/contextBudget.js +62 -9
  104. package/dist/core/agent/errors.d.ts +0 -1
  105. package/dist/core/agent/errors.js +1 -1
  106. package/dist/core/agent/events.d.ts +78 -0
  107. package/dist/core/agent/goalPolicy.d.ts +47 -0
  108. package/dist/core/agent/goalPolicy.js +106 -0
  109. package/dist/core/agent/reasoningPolicy.d.ts +31 -0
  110. package/dist/core/agent/reasoningPolicy.js +27 -0
  111. package/dist/core/agent/requestAssembly.d.ts +2 -2
  112. package/dist/core/agent/requestAssembly.js +16 -4
  113. package/dist/core/agent/toolCapabilities.d.ts +27 -0
  114. package/dist/core/agent/toolCapabilities.js +58 -0
  115. package/dist/core/agent/toolOutputStore.d.ts +8 -0
  116. package/dist/core/agent/toolOutputStore.js +11 -11
  117. package/dist/core/agent/toolResults.d.ts +12 -0
  118. package/dist/core/agent/toolResults.js +38 -0
  119. package/dist/core/agent/turnPolicy.d.ts +11 -0
  120. package/dist/core/agent/turnPolicy.js +19 -0
  121. package/dist/core/agent/workState.d.ts +81 -3
  122. package/dist/core/agent/workState.js +176 -10
  123. package/dist/core/attachments/imageAttachments.js +90 -42
  124. package/dist/core/deadline.d.ts +27 -0
  125. package/dist/core/deadline.js +74 -0
  126. package/dist/core/io/boundedRead.js +1 -1
  127. package/dist/core/limits.d.ts +51 -0
  128. package/dist/core/limits.js +51 -0
  129. package/dist/core/log/llmLog.js +8 -1
  130. package/dist/core/persistence/orderedFileWriter.d.ts +10 -0
  131. package/dist/core/persistence/orderedFileWriter.js +16 -2
  132. package/dist/core/process/backgroundRegistry.d.ts +2 -3
  133. package/dist/core/process/backgroundRegistry.js +15 -10
  134. package/dist/core/process/runBoundedProcess.d.ts +8 -2
  135. package/dist/core/process/runBoundedProcess.js +15 -6
  136. package/dist/core/process/userShell.d.ts +16 -0
  137. package/dist/core/process/userShell.js +59 -0
  138. package/dist/core/safety/missingExecutable.d.ts +42 -0
  139. package/dist/core/safety/missingExecutable.js +77 -0
  140. package/dist/core/safety/shellClassifier.d.ts +11 -0
  141. package/dist/core/safety/{bashClassifier.js → shellClassifier.js} +5 -3
  142. package/dist/core/safety/urlGuard.d.ts +1 -1
  143. package/dist/core/session/sessionSlimming.d.ts +0 -3
  144. package/dist/core/session/sessionSlimming.js +2 -3
  145. package/dist/core/session/sessionStore.d.ts +38 -0
  146. package/dist/core/session/sessionStore.js +242 -59
  147. package/dist/core/{bashOutput → shellOutput}/lineFilter.js +8 -2
  148. package/dist/core/{bashOutput → shellOutput}/reducers/search.d.ts +0 -1
  149. package/dist/core/{bashOutput → shellOutput}/reducers/search.js +1 -1
  150. package/dist/core/shellOutput/registry.d.ts +2 -0
  151. package/dist/core/{bashOutput → shellOutput}/registry.js +3 -3
  152. package/dist/core/{bashOutput → shellOutput}/types.d.ts +6 -5
  153. package/dist/core/subagent/contracts.d.ts +6 -14
  154. package/dist/core/subagent/contracts.js +4 -3
  155. package/dist/core/subagent/executionProfiles.js +2 -2
  156. package/dist/core/subagent/subagentCoordinator.d.ts +4 -0
  157. package/dist/core/subagent/subagentCoordinator.js +32 -2
  158. package/dist/core/subagent/subagentRunner.js +19 -40
  159. package/dist/core/toolOutput/reduction.d.ts +0 -12
  160. package/dist/core/toolOutput/reduction.js +1 -1
  161. package/dist/core/validation/outputParser.d.ts +2 -2
  162. package/dist/llm/client.d.ts +17 -1
  163. package/dist/llm/client.js +86 -14
  164. package/dist/llm/hazeTools.d.ts +693 -204
  165. package/dist/llm/hazeTools.js +110 -28
  166. package/dist/llm/initPrompt.js +1 -1
  167. package/dist/llm/lsp/client.d.ts +45 -0
  168. package/dist/llm/lsp/client.js +195 -0
  169. package/dist/llm/lsp/pool.d.ts +23 -0
  170. package/dist/llm/lsp/pool.js +86 -0
  171. package/dist/llm/lsp/protocol.d.ts +64 -0
  172. package/dist/llm/lsp/protocol.js +128 -0
  173. package/dist/llm/lsp/requests.d.ts +94 -0
  174. package/dist/llm/lsp/requests.js +119 -0
  175. package/dist/llm/lspTools.d.ts +5653 -33
  176. package/dist/llm/lspTools.js +152 -80
  177. package/dist/llm/openaiCodex.d.ts +1 -0
  178. package/dist/llm/openaiCodex.js +43 -0
  179. package/dist/llm/openaiCodexOAuth.d.ts +51 -0
  180. package/dist/llm/openaiCodexOAuth.js +217 -0
  181. package/dist/llm/requestContext.d.ts +7 -0
  182. package/dist/llm/requestContext.js +30 -4
  183. package/dist/llm/systemPrompt.d.ts +12 -0
  184. package/dist/llm/systemPrompt.js +24 -11
  185. package/dist/llm/toolResultTypes.d.ts +7 -14
  186. package/dist/llm/toolResultTypes.js +1 -4
  187. package/dist/llm/tools/editMatch.d.ts +14 -9
  188. package/dist/llm/tools/editMatch.js +73 -1
  189. package/dist/llm/tools/failures.d.ts +2 -0
  190. package/dist/llm/tools/failures.js +1 -0
  191. package/dist/llm/tools/fetchTool.d.ts +16 -0
  192. package/dist/llm/tools/fetchTool.js +1 -1
  193. package/dist/llm/tools/fileToolShared.d.ts +8 -5
  194. package/dist/llm/tools/fileToolShared.js +22 -23
  195. package/dist/llm/tools/gitIgnore.d.ts +42 -0
  196. package/dist/llm/tools/gitIgnore.js +247 -0
  197. package/dist/llm/tools/grepParse.d.ts +2 -1
  198. package/dist/llm/tools/grepRunner.d.ts +1 -1
  199. package/dist/llm/tools/grepRunner.js +2 -2
  200. package/dist/llm/tools/outputCap.d.ts +2 -7
  201. package/dist/llm/tools/outputCap.js +3 -3
  202. package/dist/llm/tools/processTool.d.ts +16 -16
  203. package/dist/llm/tools/processTool.js +1 -1
  204. package/dist/llm/tools/readRecovery.d.ts +8 -0
  205. package/dist/llm/tools/readRecovery.js +135 -0
  206. package/dist/llm/tools/{bashTool.d.ts → shellTool.d.ts} +171 -123
  207. package/dist/llm/tools/{bashTool.js → shellTool.js} +20 -14
  208. package/dist/llm/tools/toolContext.d.ts +1 -1
  209. package/dist/llm/tools/toolContext.js +66 -37
  210. package/dist/llm/tools/workspaceFile.d.ts +0 -1
  211. package/dist/llm/tools/workspaceFile.js +1 -6
  212. package/dist/llm/webFetch.d.ts +18 -1
  213. package/dist/llm/webFetch.js +64 -97
  214. package/dist/skills/SkillLoader.d.ts +1 -11
  215. package/dist/skills/SkillLoader.js +1 -2
  216. package/dist/skills/types.d.ts +2 -1
  217. package/dist/ui/codeHighlight.d.ts +4 -0
  218. package/dist/ui/codeHighlight.js +31 -0
  219. package/dist/ui/components/Header.d.ts +1 -1
  220. package/dist/ui/components/MarkdownText.d.ts +16 -2
  221. package/dist/ui/components/MarkdownText.js +244 -34
  222. package/dist/ui/components/TextInput.d.ts +8 -1
  223. package/dist/ui/components/TextInput.js +6 -2
  224. package/dist/ui/theme.d.ts +4 -3
  225. package/dist/ui/theme.js +5 -4
  226. package/dist/utils/buildInfo.d.ts +97 -0
  227. package/dist/utils/buildInfo.js +244 -0
  228. package/dist/utils/fs.d.ts +11 -0
  229. package/dist/utils/fs.js +91 -26
  230. package/dist/utils/openPath.d.ts +2 -2
  231. package/dist/utils/openPath.js +19 -6
  232. package/dist/utils/path.d.ts +2 -1
  233. package/dist/utils/path.js +6 -2
  234. package/dist/utils/utf8.d.ts +22 -0
  235. package/dist/utils/utf8.js +54 -0
  236. package/dist/utils/version.d.ts +9 -3
  237. package/dist/utils/version.js +28 -2
  238. package/package.json +28 -21
  239. package/dist/cli/commands/lspWizard.d.ts +0 -14
  240. package/dist/cli/commands/lspWizard.js +0 -44
  241. package/dist/cli/commands/mcpWizard.d.ts +0 -15
  242. package/dist/cli/commands/skillConfirmRemove.d.ts +0 -11
  243. package/dist/cli/commands/skillConfirmRemove.js +0 -20
  244. package/dist/cli/commands/skillCreation.d.ts +0 -12
  245. package/dist/cli/commands/skillCreation.js +0 -14
  246. package/dist/cli/commands/skillWizard.d.ts +0 -17
  247. package/dist/cli/commands/streaming/idleTimer.d.ts +0 -26
  248. package/dist/cli/commands/streaming/idleTimer.js +0 -24
  249. package/dist/cli/commands/streaming/turnOutcome.d.ts +0 -10
  250. package/dist/cli/commands/streaming/turnOutcome.js +0 -13
  251. package/dist/cli/commands/wizardActions.d.ts +0 -46
  252. package/dist/cli/commands/wizardActions.js +0 -46
  253. package/dist/cli/commands/wizardInput.d.ts +0 -4
  254. package/dist/cli/commands/wizardInput.js +0 -19
  255. package/dist/cli/commands/wizardPrompts.d.ts +0 -22
  256. package/dist/cli/commands/wizardPrompts.js +0 -52
  257. package/dist/cli/commands/wizardSuggestions.d.ts +0 -31
  258. package/dist/cli/commands/wizardSuggestions.js +0 -188
  259. package/dist/cli/commands/wizardTransition.d.ts +0 -37
  260. package/dist/cli/commands/wizardTransition.js +0 -43
  261. package/dist/core/bashOutput/ansi.d.ts +0 -1
  262. package/dist/core/bashOutput/ansi.js +0 -7
  263. package/dist/core/bashOutput/registry.d.ts +0 -4
  264. package/dist/core/goal/completionPolicy.d.ts +0 -2
  265. package/dist/core/goal/completionPolicy.js +0 -7
  266. package/dist/core/goal/requestClassifier.d.ts +0 -3
  267. package/dist/core/goal/requestClassifier.js +0 -18
  268. package/dist/core/goal/sessionGoal.d.ts +0 -8
  269. package/dist/core/goal/sessionGoal.js +0 -30
  270. package/dist/core/limits/byteBudgets.d.ts +0 -18
  271. package/dist/core/limits/byteBudgets.js +0 -18
  272. package/dist/core/limits/textBudgets.d.ts +0 -23
  273. package/dist/core/limits/textBudgets.js +0 -23
  274. package/dist/core/safety/bashClassifier.d.ts +0 -10
  275. package/dist/llm/lsp.d.ts +0 -129
  276. package/dist/llm/lsp.js +0 -307
  277. package/dist/ui/components/ErrorView.d.ts +0 -4
  278. package/dist/ui/components/ErrorView.js +0 -7
  279. package/dist/utils/yaml.d.ts +0 -2
  280. package/dist/utils/yaml.js +0 -8
  281. package/examples/skills/files/SKILL.md +0 -16
  282. package/examples/skills/files/examples/file-editing.md +0 -3
  283. /package/dist/core/{bashOutput → shellOutput}/command.d.ts +0 -0
  284. /package/dist/core/{bashOutput → shellOutput}/command.js +0 -0
  285. /package/dist/core/{bashOutput → shellOutput}/lineFilter.d.ts +0 -0
  286. /package/dist/core/{bashOutput → shellOutput}/reducers/content.d.ts +0 -0
  287. /package/dist/core/{bashOutput → shellOutput}/reducers/content.js +0 -0
  288. /package/dist/core/{bashOutput → shellOutput}/reducers/gh.d.ts +0 -0
  289. /package/dist/core/{bashOutput → shellOutput}/reducers/gh.js +0 -0
  290. /package/dist/core/{bashOutput → shellOutput}/reducers/git.d.ts +0 -0
  291. /package/dist/core/{bashOutput → shellOutput}/reducers/git.js +0 -0
  292. /package/dist/core/{bashOutput → shellOutput}/reducers/validation.d.ts +0 -0
  293. /package/dist/core/{bashOutput → shellOutput}/reducers/validation.js +0 -0
  294. /package/dist/core/{bashOutput → shellOutput}/types.js +0 -0
@@ -1,7 +1,7 @@
1
1
  import fs from 'node:fs/promises';
2
2
  import path from 'node:path';
3
3
  import { walkDir } from '../../utils/fs.js';
4
- import { isGitIgnored } from '../../llm/tools/fileToolShared.js';
4
+ import { createIgnoreClassifier } from '../../llm/tools/gitIgnore.js';
5
5
  import { workspaceRoot } from '../../utils/path.js';
6
6
  /**
7
7
  * Tab-completion support for `@`-mention paths (F04 AC1).
@@ -71,10 +71,11 @@ export async function fileMentionSuggestions(token, options = {}) {
71
71
  }
72
72
  if (!parentStats.isDirectory())
73
73
  return [];
74
+ const classifier = createIgnoreClassifier(root);
74
75
  const entries = await walkDir(absoluteParent, {
75
76
  recursive: false,
76
77
  maxEntries: MAX_MENTION_SUGGESTIONS * 4,
77
- filter: async (entry) => !await isGitIgnored(entry.absolutePath),
78
+ ignoreBatch: entries => classifier.classify(entries),
78
79
  });
79
80
  const matches = entries
80
81
  .filter(entry => entry.name.startsWith(prefix))
@@ -1,21 +1,13 @@
1
- import type { HazeSettings } from '../../config/settings.js';
2
- import type { LoadedSkill } from '../../skills/types.js';
3
- import type { SessionSummary } from '../../core/session/sessionStore.js';
4
1
  import type { TextInputSuggestion } from '../../ui/components/TextInput.js';
2
+ import { type WizardSuggestionState } from '../commands/wizardFlow.js';
5
3
  import type { Mode } from '../commands/chatModes.js';
6
- interface InputSuggestionState {
4
+ /** Inputs for suggestion building: the wizard picker state plus the current input mode. */
5
+ export interface InputSuggestionState extends WizardSuggestionState {
7
6
  mode: Mode;
8
- settings: HazeSettings;
9
- skills: LoadedSkill[];
10
- selectedProviderName?: string;
11
- modelProviderFilter?: string;
12
- providerDraftName?: string;
13
- discoveredModels?: string[];
14
- suggestedModels?: string[];
15
- selectedSkillName?: string;
16
- selectedLspName?: string;
17
- selectedMcpName?: string;
18
- sessions?: SessionSummary[];
19
7
  }
8
+ /**
9
+ * Suggestions for the current input mode. Wizard/picker modes delegate to the
10
+ * step's suggestion builder from the flow table; chat mode shows slash
11
+ * commands plus enabled skill invocations.
12
+ */
20
13
  export declare function inputSuggestionsForState(state: InputSuggestionState): TextInputSuggestion[];
21
- export {};
@@ -1,6 +1,5 @@
1
1
  import { isSkillEnabled } from '../../config/skillSettings.js';
2
- import { providerSuggestions, providerActionSuggestions, presetSuggestions, modelSuggestions, modelAddProviderSuggestions, modelPickSuggestions, lspSuggestions, lspActionSuggestions, lspPresetSuggestions, mcpSuggestions, mcpActionSuggestions, mcpPresetSuggestions, mcpTransportSuggestions, skillsSuggestions, skillsActionSuggestions, skillScopeSuggestions } from '../commands/wizardSuggestions.js';
3
- import { sessionActionSuggestions, sessionSuggestions } from '../commands/sessionPicker.js';
2
+ import { wizardSuggestionsFor } from '../commands/wizardFlow.js';
4
3
  const CHAT_COMMAND_SUGGESTIONS = [
5
4
  { value: '/help', description: 'Show commands', kind: 'command' },
6
5
  { value: '/provider', description: 'Choose a provider', kind: 'command' },
@@ -20,46 +19,15 @@ const CHAT_COMMAND_SUGGESTIONS = [
20
19
  { value: '/exit', description: 'Exit haze', kind: 'command' },
21
20
  { value: '/quit', description: 'Exit haze', kind: 'command' },
22
21
  ];
22
+ /**
23
+ * Suggestions for the current input mode. Wizard/picker modes delegate to the
24
+ * step's suggestion builder from the flow table; chat mode shows slash
25
+ * commands plus enabled skill invocations.
26
+ */
23
27
  export function inputSuggestionsForState(state) {
24
- const { mode, settings, skills } = state;
25
- if (mode === 'sessions')
26
- return sessionSuggestions(state.sessions ?? []);
27
- if (mode === 'sessionAction')
28
- return sessionActionSuggestions();
29
- if (mode === 'provider')
30
- return providerSuggestions(settings);
31
- if (mode === 'providerAction')
32
- return providerActionSuggestions(settings, state.selectedProviderName);
33
- if (mode === 'providerAddPreset')
34
- return presetSuggestions();
35
- if (mode === 'model')
36
- return modelSuggestions(settings, state.modelProviderFilter);
37
- if (mode === 'modelAddProvider')
38
- return modelAddProviderSuggestions(settings);
39
- if (mode === 'modelPick')
40
- return modelPickSuggestions(settings, state.selectedProviderName ?? state.providerDraftName, state.discoveredModels ?? [], state.suggestedModels ?? []);
41
- if (mode === 'skills')
42
- return skillsSuggestions(settings, skills);
43
- if (mode === 'skillsAction')
44
- return skillsActionSuggestions(settings, skills, state.selectedSkillName);
45
- if (mode === 'skillsAddScope')
46
- return skillScopeSuggestions();
47
- if (mode === 'lsp')
48
- return lspSuggestions(settings);
49
- if (mode === 'lspAction')
50
- return lspActionSuggestions(settings, state.selectedLspName);
51
- if (mode === 'lspAddPreset')
52
- return lspPresetSuggestions();
53
- if (mode === 'mcp')
54
- return mcpSuggestions(settings);
55
- if (mode === 'mcpAction')
56
- return mcpActionSuggestions(settings, state.selectedMcpName);
57
- if (mode === 'mcpAddPreset')
58
- return mcpPresetSuggestions();
59
- if (mode === 'mcpAddTransport')
60
- return mcpTransportSuggestions();
61
- if (mode !== 'chat')
62
- return [];
28
+ if (state.mode !== 'chat')
29
+ return wizardSuggestionsFor(state.mode, state) ?? [];
30
+ const { settings, skills } = state;
63
31
  const activeSkills = skills.filter((skill, index) => isSkillEnabled(settings, skill.name, skill.source)
64
32
  && !skills.slice(0, index).some(candidate => candidate.name === skill.name && isSkillEnabled(settings, candidate.name, candidate.source)));
65
33
  return [
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Live-region row budgeting.
3
+ *
4
+ * Ink reclaims the terminal with `clearTerminal` (which erases scrollback)
5
+ * whenever the *dynamic* frame grows taller than the viewport, so every dynamic
6
+ * section must be clamped to keep the frame under one screen. These helpers
7
+ * mirror Ink's own line wrapping (`wrapAnsi` with `trim: false, hard: true`) so
8
+ * our row estimates match what Ink actually renders.
9
+ */
10
+ /** Wrap one logical line exactly like an Ink `<Text>` with default wrap mode. */
11
+ export declare function wrapLine(line: string, width: number): string[];
12
+ /** Wrapped row count of a logical line at the given width. */
13
+ export declare function lineRows(line: string, width: number): number;
14
+ export interface TailClamp {
15
+ text: string;
16
+ /** Wrapped rows hidden above the visible tail (0 when nothing was clamped). */
17
+ hiddenLineCount: number;
18
+ }
19
+ /**
20
+ * Keep the last `maxLines` wrapped rows of `text`, dropping whole logical lines
21
+ * from the top (a wrapped group is never split). When clamping occurs, one row
22
+ * is reserved for the caller's `⋯ +N lines` indicator. Nothing is lost: the
23
+ * full text is committed verbatim to the static transcript once it settles.
24
+ */
25
+ export declare function clampTextTail(text: string, width: number, maxLines: number): TailClamp;
@@ -0,0 +1,48 @@
1
+ import wrapAnsi from 'wrap-ansi';
2
+ /**
3
+ * Live-region row budgeting.
4
+ *
5
+ * Ink reclaims the terminal with `clearTerminal` (which erases scrollback)
6
+ * whenever the *dynamic* frame grows taller than the viewport, so every dynamic
7
+ * section must be clamped to keep the frame under one screen. These helpers
8
+ * mirror Ink's own line wrapping (`wrapAnsi` with `trim: false, hard: true`) so
9
+ * our row estimates match what Ink actually renders.
10
+ */
11
+ /** Wrap one logical line exactly like an Ink `<Text>` with default wrap mode. */
12
+ export function wrapLine(line, width) {
13
+ const safeWidth = Math.max(1, width);
14
+ if (line.length === 0)
15
+ return [''];
16
+ return wrapAnsi(line, safeWidth, { trim: false, hard: true }).split('\n');
17
+ }
18
+ /** Wrapped row count of a logical line at the given width. */
19
+ export function lineRows(line, width) {
20
+ return wrapLine(line, width).length;
21
+ }
22
+ /**
23
+ * Keep the last `maxLines` wrapped rows of `text`, dropping whole logical lines
24
+ * from the top (a wrapped group is never split). When clamping occurs, one row
25
+ * is reserved for the caller's `⋯ +N lines` indicator. Nothing is lost: the
26
+ * full text is committed verbatim to the static transcript once it settles.
27
+ */
28
+ export function clampTextTail(text, width, maxLines) {
29
+ if (maxLines < 1)
30
+ return { text: '', hiddenLineCount: 0 };
31
+ const logical = text.replace(/\r\n|\r/g, '\n').split('\n');
32
+ const rows = logical.map(line => lineRows(line, width));
33
+ const total = rows.reduce((sum, count) => sum + count, 0);
34
+ if (total <= maxLines)
35
+ return { text, hiddenLineCount: 0 };
36
+ const visibleBudget = Math.max(1, maxLines - 1); // reserve the indicator row
37
+ let used = 0;
38
+ let start = logical.length;
39
+ while (start > 0) {
40
+ const next = rows[start - 1] ?? 0;
41
+ if (used + next > visibleBudget)
42
+ break;
43
+ used += next;
44
+ start -= 1;
45
+ }
46
+ const hiddenLineCount = rows.slice(0, start).reduce((sum, count) => sum + count, 0);
47
+ return { text: logical.slice(start).join('\n'), hiddenLineCount };
48
+ }
@@ -1,9 +1,38 @@
1
1
  import React from 'react';
2
2
  import type { Message } from '../commands/streaming.js';
3
3
  export declare function messageElapsedLabel(message: Message): string;
4
- export declare function MessageView({ message, width }: {
4
+ export declare const AssistantMarkdownChunkView: React.MemoExoticComponent<({ message, content, width, first, final }: {
5
5
  message: Message;
6
+ content: string;
6
7
  width: number;
7
- }): React.JSX.Element;
8
- export declare function messageKey(message: Message, index: number): string;
9
- export declare function orderedDisplayMessages(messages: Message[]): Message[];
8
+ first: boolean;
9
+ final: boolean;
10
+ }) => React.JSX.Element>;
11
+ export declare const MessageView: React.MemoExoticComponent<({ message, width, showHeader, maxVisibleLines }: {
12
+ message: Message;
13
+ width: number;
14
+ showHeader?: boolean;
15
+ maxVisibleLines?: number;
16
+ }) => React.JSX.Element>;
17
+ export type TranscriptStaticItem = {
18
+ kind: 'message';
19
+ key: string;
20
+ message: Message;
21
+ } | {
22
+ kind: 'assistant-markdown';
23
+ key: string;
24
+ message: Message;
25
+ content: string;
26
+ first: boolean;
27
+ final: boolean;
28
+ };
29
+ export type TranscriptStreamingItem = {
30
+ key: string;
31
+ message: Message;
32
+ showHeader?: boolean;
33
+ };
34
+ /** Partition display messages into append-only static Markdown roots and the active streaming tail. */
35
+ export declare function partitionDisplayMessages(messages: Message[]): {
36
+ staticItems: TranscriptStaticItem[];
37
+ streamingItems: TranscriptStreamingItem[];
38
+ };
@@ -1,10 +1,13 @@
1
- import { jsxs as _jsxs, jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
1
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
+ import React from 'react';
2
3
  import { Box, Text } from 'ink';
3
4
  import Spinner from 'ink-spinner';
4
5
  import { formatElapsedTime, formatElapsedTimeWhole } from '../commands/formatters.js';
5
- import { MarkdownText } from '../../ui/components/MarkdownText.js';
6
+ import { MarkdownText, markdownRootChunks } from '../../ui/components/MarkdownText.js';
7
+ import { lineRows, clampTextTail } from './liveRegion.js';
6
8
  import { isSubstantiveAssistantText } from '../commands/streaming/assistantText.js';
7
9
  import { theme } from '../../ui/theme.js';
10
+ import { highlightedCodeLine, languageForPath } from '../../ui/codeHighlight.js';
8
11
  function fullWidthLines(text, width, leftPadding = 0) {
9
12
  const safeWidth = Math.max(1, width);
10
13
  const prefix = ' '.repeat(leftPadding);
@@ -13,30 +16,136 @@ function fullWidthLines(text, width, leftPadding = 0) {
13
16
  function fullWidthBlankLine(width) {
14
17
  return ''.padEnd(Math.max(1, width));
15
18
  }
16
- function ToolMessageText({ text, streaming }) {
17
- const lines = text.split('\n');
18
- return _jsx(Box, { flexDirection: "column", children: lines.map((line, index) => {
19
- const diffRow = /^(\s*\d+\s+)([+-])(.*)$/.exec(line);
20
- if (diffRow) {
21
- const [, prefix, marker, rest] = diffRow;
22
- const isAdd = marker === '+';
23
- return _jsxs(Text, { color: "white", backgroundColor: isAdd ? theme.successBg : theme.dangerBg, children: [_jsxs(Text, { color: isAdd ? theme.success : theme.danger, backgroundColor: isAdd ? theme.successBg : theme.dangerBg, children: [prefix, marker] }), rest] }, `${index}-${line}`);
24
- }
25
- const contextRow = /^(\s*\d+\s+)\s(.*)$/.exec(line);
26
- if (contextRow) {
27
- const [, prefix, rest] = contextRow;
28
- return _jsxs(Text, { color: "white", children: [_jsxs(Text, { color: theme.muted, children: [prefix, " "] }), rest] }, `${index}-${line}`);
29
- }
30
- const row = /^(\s*)([✓✗…])\s+(\S+)(.*)$/.exec(line);
31
- if (!row) {
32
- const timer = /(.*) (\([0-9]+(?:h [0-9]+m [0-9]+(?:\.[0-9])?s|m [0-9]+(?:\.[0-9])?s|(?:\.[0-9])?s)\))$/.exec(line);
33
- return _jsxs(Text, { color: theme.muted, children: [index === 0 && streaming ? _jsxs(_Fragment, { children: [_jsx(Spinner, { type: "dots" }), " "] }) : null, timer ? timer[1] : line, timer ? _jsxs(Text, { color: theme.muted, bold: false, children: [" ", timer[2]] }) : null] }, `${index}-${line}`);
34
- }
35
- const [, indent, icon, toolName, rest] = row;
36
- const iconColor = icon === '✓' ? theme.success : icon === '✗' ? theme.danger : theme.muted;
37
- const timer = /(.*) (\([0-9]+(?:h [0-9]+m [0-9]+(?:\.[0-9])?s|m [0-9]+(?:\.[0-9])?s|(?:\.[0-9])?s)\))$/.exec(rest);
38
- return _jsxs(Text, { color: theme.muted, children: [indent, _jsx(Text, { color: iconColor, children: icon }), " ", _jsx(Text, { color: theme.purple, children: toolName }), timer ? timer[1] : rest, timer ? _jsxs(Text, { color: theme.muted, bold: false, children: [" ", timer[2]] }) : null] }, `${index}-${line}`);
39
- }) });
19
+ /** Slash commands in system text are highlighted like `code` in the docs site. A command name never contains `/`, which keeps absolute paths like `/Users/...` plain. */
20
+ const SLASH_COMMAND_PATTERN = /(^|(?<=\s))\/[a-zA-Z][a-zA-Z0-9-]*(?![\w/-])/g;
21
+ function slashCommandParts(text) {
22
+ const parts = [];
23
+ let lastIndex = 0;
24
+ for (const match of text.matchAll(SLASH_COMMAND_PATTERN)) {
25
+ const index = match.index ?? 0;
26
+ if (index > lastIndex)
27
+ parts.push(text.slice(lastIndex, index));
28
+ parts.push(_jsx(Text, { color: theme.command, children: match[0] }, `cmd-${index}`));
29
+ lastIndex = index + match[0].length;
30
+ }
31
+ if (lastIndex < text.length)
32
+ parts.push(text.slice(lastIndex));
33
+ return parts;
34
+ }
35
+ /**
36
+ * Style one line of a system message: single-token list items that look like
37
+ * paths are orange, short leading "Key:" prefixes are bold, and slash
38
+ * commands are orange everywhere.
39
+ */
40
+ function systemLineContent(line) {
41
+ const fileItem = /^- (\S+)$/.exec(line);
42
+ if (fileItem && /[./]/.test(fileItem[1] ?? ''))
43
+ return _jsx(Text, { color: theme.command, children: line });
44
+ const colonIndex = line.indexOf(':');
45
+ if (colonIndex > 0 && colonIndex <= 30) {
46
+ const key = line.slice(0, colonIndex);
47
+ // Exclude `/` and `.` from the key body so URLs like `https://example.com:443`
48
+ // don't match as a "Key:" prefix and get bolded as one span (which would
49
+ // bypass the slash-command highlighter for anything that follows).
50
+ if ((key.startsWith('- ') || key.includes(' ')) && /^[A-Za-z][\w ~-]*$/.test(key.replace(/^- /, ''))) {
51
+ return _jsxs(React.Fragment, { children: [_jsx(Text, { bold: true, children: key }), slashCommandParts(line.slice(colonIndex))] });
52
+ }
53
+ }
54
+ return slashCommandParts(line);
55
+ }
56
+ function SystemMessageText({ text }) {
57
+ return _jsx(Text, { children: text.split('\n').map((line, index) => _jsxs(React.Fragment, { children: [index > 0 ? '\n' : null, systemLineContent(line)] }, index)) });
58
+ }
59
+ function diffLineNumber(line) {
60
+ if (line.type === 'gap' || line.type === 'meta')
61
+ return undefined;
62
+ return line.type === 'remove' ? line.oldLine : line.newLine ?? line.oldLine;
63
+ }
64
+ function ToolDiffView({ diff, width }) {
65
+ const contentWidth = Math.max(1, width - 2);
66
+ const lineNumberWidth = Math.max(4, ...diff.lines.map(line => String(diffLineNumber(line) ?? '').length));
67
+ return _jsxs(Box, { flexDirection: "column", marginLeft: 2, marginTop: 1, children: [_jsxs(Text, { color: theme.muted, children: ["\u23BF ", _jsx(Text, { color: theme.command, children: diff.path }), " \u00B7 Added ", diff.addedLines, " line", diff.addedLines === 1 ? '' : 's', ", removed ", diff.removedLines, " line", diff.removedLines === 1 ? '' : 's'] }), diff.lines.map((line, index) => {
68
+ if (line.type === 'gap') {
69
+ return _jsxs(Text, { color: theme.muted, children: [" \u2026 ", line.omittedLines, " diff line", line.omittedLines === 1 ? '' : 's', " omitted \u2026"] }, `${diff.id}-${index}`);
70
+ }
71
+ if (line.type === 'meta') {
72
+ return _jsxs(Text, { color: theme.muted, children: [" \\ ", line.text] }, `${diff.id}-${index}`);
73
+ }
74
+ const marker = line.type === 'add' ? '+' : line.type === 'remove' ? '-' : ' ';
75
+ const lineNumber = `${String(diffLineNumber(line) ?? '').padStart(lineNumberWidth)} `;
76
+ const markerPrefix = `${marker} `;
77
+ const prefixWidth = lineNumber.length + markerPrefix.length;
78
+ const code = highlightedCodeLine(line.text, Math.max(1, contentWidth - prefixWidth), languageForPath(diff.path));
79
+ if (line.type === 'context') {
80
+ return _jsxs(Box, { flexDirection: "row", children: [_jsxs(Text, { color: theme.muted, children: [lineNumber, markerPrefix] }), _jsx(Text, { children: code })] }, `${diff.id}-${index}`);
81
+ }
82
+ const isAdd = line.type === 'add';
83
+ const backgroundColor = isAdd ? theme.successBg : theme.dangerBg;
84
+ return _jsxs(Box, { flexDirection: "row", children: [_jsx(Text, { color: theme.muted, children: lineNumber }), _jsxs(Text, { color: theme.foreground, backgroundColor: backgroundColor, children: [_jsx(Text, { color: isAdd ? theme.success : theme.danger, backgroundColor: backgroundColor, children: markerPrefix }), code] })] }, `${diff.id}-${index}`);
85
+ }), diff.handle ? _jsxs(Text, { color: theme.muted, children: [" Full diff: readToolOutput with handle ", _jsx(Text, { color: theme.command, children: diff.handle })] }) : null, diff.complete === false ? _jsxs(Text, { color: theme.muted, children: [" Preview is partial; ", diff.previousContentOmittedBytes ?? 0, " bytes of previous content were not captured."] }) : null] });
86
+ }
87
+ /** Rendered row count of a diff preview block (meta + code rows + optional handle/partial rows + top margin). */
88
+ function toolDiffRows(diff) {
89
+ return 1 + diff.lines.length + (diff.handle ? 1 : 0) + (diff.complete === false ? 1 : 0) + 1;
90
+ }
91
+ /**
92
+ * Live-region clamp for the streaming tool group (see liveRegion.ts): keep only
93
+ * the rows that fit the viewport budget, dropping whole logical lines from the
94
+ * top and whole diff previews from the bottom, with one indicator row each.
95
+ * The finalized group still enters the static transcript verbatim.
96
+ */
97
+ function clampToolDisplay({ text, width, toolDiffs, maxVisibleLines }) {
98
+ const allLines = text.split('\n');
99
+ const allDiffs = toolDiffs ?? [];
100
+ if (maxVisibleLines == null)
101
+ return { lines: allLines, hiddenTextRowCount: 0, visibleDiffs: allDiffs, hiddenDiffCount: 0 };
102
+ const rows = allLines.map(line => lineRows(line, width));
103
+ const total = rows.reduce((sum, count) => sum + count, 0);
104
+ let lines = allLines;
105
+ let hiddenTextRowCount = 0;
106
+ let rowsUsed = total;
107
+ if (total > maxVisibleLines) {
108
+ const visibleBudget = Math.max(1, maxVisibleLines - 1); // indicator row
109
+ let used = 0;
110
+ let start = allLines.length;
111
+ while (start > 0) {
112
+ const next = rows[start - 1] ?? 0;
113
+ if (used + next > visibleBudget)
114
+ break;
115
+ used += next;
116
+ start -= 1;
117
+ }
118
+ hiddenTextRowCount = rows.slice(0, start).reduce((sum, count) => sum + count, 0);
119
+ lines = allLines.slice(start);
120
+ rowsUsed = used + 1;
121
+ }
122
+ // Diffs get whatever budget the text left; reserve an indicator row when any
123
+ // diff might be hidden.
124
+ let budget = Math.max(0, maxVisibleLines - rowsUsed - (allDiffs.length > 0 ? 1 : 0));
125
+ const visibleDiffs = [];
126
+ for (const diff of allDiffs) {
127
+ const cost = toolDiffRows(diff);
128
+ if (cost > budget)
129
+ break;
130
+ budget -= cost;
131
+ visibleDiffs.push(diff);
132
+ }
133
+ return { lines, hiddenTextRowCount, visibleDiffs, hiddenDiffCount: allDiffs.length - visibleDiffs.length };
134
+ }
135
+ function ToolMessageText({ text, streaming, width, toolDiffs, maxVisibleLines }) {
136
+ const clamped = clampToolDisplay({ text, width, toolDiffs, maxVisibleLines });
137
+ const lines = clamped.lines;
138
+ return _jsxs(Box, { flexDirection: "column", children: [clamped.hiddenTextRowCount > 0 ? _jsx(Text, { color: theme.muted, children: `⋯ +${clamped.hiddenTextRowCount} line${clamped.hiddenTextRowCount === 1 ? '' : 's'} above` }) : null, lines.map((line, index) => {
139
+ const row = /^(\s*)([✓✗…])\s+(\S+)(.*)$/.exec(line);
140
+ if (!row) {
141
+ const timer = /(.*) (\([0-9]+(?:h [0-9]+m [0-9]+(?:\.[0-9])?s|m [0-9]+(?:\.[0-9])?s|(?:\.[0-9])?s)\))$/.exec(line);
142
+ return _jsxs(Text, { color: theme.muted, children: [index === 0 && streaming ? _jsxs(_Fragment, { children: [_jsx(Spinner, { type: "dots" }), " "] }) : null, timer ? timer[1] : line, timer ? _jsxs(Text, { color: theme.muted, bold: false, children: [" ", timer[2]] }) : null] }, `${index}-${line}`);
143
+ }
144
+ const [, indent, icon, toolName, rest] = row;
145
+ const iconColor = icon === '✓' ? theme.success : icon === '✗' ? theme.danger : theme.muted;
146
+ const timer = /(.*) (\([0-9]+(?:h [0-9]+m [0-9]+(?:\.[0-9])?s|m [0-9]+(?:\.[0-9])?s|(?:\.[0-9])?s)\))$/.exec(rest);
147
+ return _jsxs(Text, { color: theme.muted, children: [indent, _jsx(Text, { color: iconColor, children: icon }), " ", _jsx(Text, { color: theme.purple, children: toolName }), timer ? timer[1] : rest, timer ? _jsxs(Text, { color: theme.muted, bold: false, children: [" ", timer[2]] }) : null] }, `${index}-${line}`);
148
+ }), clamped.visibleDiffs.map(diff => _jsx(ToolDiffView, { diff: diff, width: width }, diff.id)), clamped.hiddenDiffCount > 0 ? _jsx(Text, { color: theme.muted, children: `⋯ ${clamped.hiddenDiffCount} diff preview${clamped.hiddenDiffCount === 1 ? '' : 's'} hidden` }) : null] });
40
149
  }
41
150
  export function messageElapsedLabel(message) {
42
151
  if (message.startedAt == null)
@@ -50,20 +159,94 @@ export function messageElapsedLabel(message) {
50
159
  }
51
160
  return message.streaming ? formatElapsedTimeWhole(elapsed) : formatElapsedTime(elapsed);
52
161
  }
53
- export function MessageView({ message, width }) {
162
+ export const AssistantMarkdownChunkView = React.memo(function AssistantMarkdownChunkView({ message, content, width, first, final }) {
163
+ const completion = final ? messageElapsedLabel(message) : '';
164
+ return _jsxs(Box, { flexDirection: "column", marginBottom: final ? 1 : 0, children: [first ? _jsx(Text, { color: theme.purple, bold: true, children: "haze" }) : null, _jsx(MarkdownText, { content: content, width: width }), completion ? _jsx(Text, { color: theme.muted, children: completion }) : null] });
165
+ });
166
+ /** Streaming assistant tail clamped to the live-region budget; the full text enters the static transcript once the root settles. */
167
+ function StreamingClampedText({ text, width, maxVisibleLines }) {
168
+ const clamped = clampTextTail(text, width, maxVisibleLines);
169
+ return _jsxs(Box, { flexDirection: "column", children: [clamped.hiddenLineCount > 0 ? _jsx(Text, { color: theme.muted, children: `⋯ +${clamped.hiddenLineCount} line${clamped.hiddenLineCount === 1 ? '' : 's'} above` }) : null, _jsx(Text, { children: clamped.text })] });
170
+ }
171
+ export const MessageView = React.memo(function MessageView({ message, width, showHeader = true, maxVisibleLines }) {
54
172
  if (message.role === 'user') {
55
- return _jsxs(Box, { flexDirection: "column", marginBottom: 1, children: [_jsx(Text, { backgroundColor: theme.quoteBg, children: fullWidthBlankLine(width) }), _jsx(Text, { color: theme.success, bold: true, backgroundColor: theme.quoteBg, children: ' You asked'.padEnd(width) }), fullWidthLines(message.text, width, 2).map((line, lineIndex) => _jsx(Text, { color: "white", backgroundColor: theme.quoteBg, children: line }, lineIndex)), _jsx(Text, { backgroundColor: theme.quoteBg, children: fullWidthBlankLine(width) })] });
173
+ return _jsxs(Box, { flexDirection: "column", marginBottom: 1, children: [_jsx(Text, { backgroundColor: theme.surfaceBg, children: fullWidthBlankLine(width) }), _jsx(Text, { color: theme.success, bold: true, backgroundColor: theme.surfaceBg, children: ' You asked'.padEnd(width) }), fullWidthLines(message.text, width, 2).map((line, lineIndex) => _jsx(Text, { color: theme.foreground, backgroundColor: theme.surfaceBg, children: line }, lineIndex)), _jsx(Text, { backgroundColor: theme.surfaceBg, children: fullWidthBlankLine(width) })] });
56
174
  }
57
- return _jsxs(Box, { flexDirection: "column", marginBottom: 1, children: [_jsxs(Text, { children: [_jsx(Text, { color: message.role === 'assistant' ? theme.purple : message.role === 'tool' ? theme.blue : theme.muted, bold: true, children: message.role === 'assistant' ? 'haze' : message.role === 'tool' ? 'Tool' : 'Info' }), messageElapsedLabel(message) ? _jsxs(Text, { color: theme.muted, bold: false, children: [" \u00B7 ", messageElapsedLabel(message)] }) : null] }), message.role === 'tool'
58
- ? _jsx(ToolMessageText, { text: message.text, streaming: message.streaming })
175
+ return _jsxs(Box, { flexDirection: "column", marginBottom: 1, children: [showHeader ? _jsxs(Text, { children: [_jsx(Text, { color: message.role === 'assistant' ? theme.purple : message.role === 'tool' ? theme.blue : message.role === 'system' ? theme.success : theme.muted, bold: true, children: message.role === 'assistant' ? 'haze' : message.role === 'tool' ? 'Tool' : 'Info' }), messageElapsedLabel(message) ? _jsxs(Text, { color: theme.muted, bold: false, children: [" \u00B7 ", messageElapsedLabel(message)] }) : null] }) : null, message.role === 'tool'
176
+ ? _jsx(ToolMessageText, { text: message.text, streaming: message.streaming, width: width, toolDiffs: message.toolDiffs, maxVisibleLines: message.streaming ? maxVisibleLines : undefined })
59
177
  : message.role === 'assistant' && !message.streaming
60
- ? _jsx(MarkdownText, { content: message.text })
61
- : _jsx(Text, { children: message.text })] });
62
- }
63
- export function messageKey(message, index) {
178
+ // Only settled assistant messages get Markdown rendering. Streaming
179
+ // text re-tokenizes on every delta (expensive) and the partial Markdown
180
+ // would flicker; user text stays plain to keep pasted Markdown literal.
181
+ ? _jsx(MarkdownText, { content: message.text, width: width })
182
+ : message.role === 'system'
183
+ ? _jsx(SystemMessageText, { text: message.text })
184
+ : message.streaming && maxVisibleLines != null
185
+ ? _jsx(StreamingClampedText, { text: message.text, width: width, maxVisibleLines: maxVisibleLines })
186
+ : _jsx(Text, { children: message.text })] });
187
+ });
188
+ function messageKey(message, index) {
64
189
  return message.id ?? `${index}-${message.role}-${message.text}`;
65
190
  }
66
- export function orderedDisplayMessages(messages) {
191
+ /** Partition display messages into append-only static Markdown roots and the active streaming tail. */
192
+ export function partitionDisplayMessages(messages) {
193
+ const staticItems = [];
194
+ const streamingItems = [];
195
+ let reachedDynamicTail = false;
196
+ orderedDisplayMessages(messages).forEach((message, index) => {
197
+ const key = messageKey(message, index);
198
+ // Static output must remain an ordered prefix. A settled notification that
199
+ // follows live text stays in the dynamic frame until that text is complete.
200
+ if (reachedDynamicTail) {
201
+ streamingItems.push({ key, message });
202
+ return;
203
+ }
204
+ if (message.role !== 'assistant') {
205
+ if (message.streaming) {
206
+ reachedDynamicTail = true;
207
+ streamingItems.push({ key, message });
208
+ }
209
+ else {
210
+ staticItems.push({ kind: 'message', key, message });
211
+ }
212
+ return;
213
+ }
214
+ const chunks = markdownRootChunks(message.text);
215
+ if (chunks.length === 0) {
216
+ if (message.streaming) {
217
+ reachedDynamicTail = true;
218
+ streamingItems.push({ key, message });
219
+ }
220
+ else {
221
+ staticItems.push({ kind: 'message', key, message });
222
+ }
223
+ return;
224
+ }
225
+ // Marked may still reclassify the final root while the stream grows. Keep
226
+ // only that root dynamic; every preceding root is now safe to append once.
227
+ const staticChunkCount = message.streaming ? Math.max(0, chunks.length - 1) : chunks.length;
228
+ for (let chunkIndex = 0; chunkIndex < staticChunkCount; chunkIndex++) {
229
+ staticItems.push({
230
+ kind: 'assistant-markdown',
231
+ key: `${key}-markdown-${chunkIndex}`,
232
+ message,
233
+ content: chunks[chunkIndex] ?? '',
234
+ first: chunkIndex === 0,
235
+ final: !message.streaming && chunkIndex === chunks.length - 1,
236
+ });
237
+ }
238
+ if (message.streaming) {
239
+ reachedDynamicTail = true;
240
+ streamingItems.push({
241
+ key,
242
+ message: { ...message, text: chunks.at(-1) ?? message.text },
243
+ showHeader: staticChunkCount === 0,
244
+ });
245
+ }
246
+ });
247
+ return { staticItems, streamingItems };
248
+ }
249
+ function orderedDisplayMessages(messages) {
67
250
  return messages
68
251
  .map((message, index) => ({ message, index }))
69
252
  .sort((a, b) => {
@@ -3,7 +3,8 @@ import type { ContextFile } from '../../config/contextFiles.js';
3
3
  import type { WorkState } from '../../core/agent/workState.js';
4
4
  import { type HazeSession } from '../../core/session/sessionStore.js';
5
5
  import { type LlmLog } from '../../core/log/llmLog.js';
6
- import type { Message, TokenUsage } from '../commands/streaming.js';
6
+ import type { Message } from '../commands/streaming.js';
7
+ import type { TokenUsage } from '../commands/streaming/turnRuntime.js';
7
8
  import type { SessionRecorder } from './sessionRecorder.js';
8
9
  /**
9
10
  * Session lifecycle controller extracted from `chat.tsx` (CR-006): session
@@ -13,6 +14,11 @@ import type { SessionRecorder } from './sessionRecorder.js';
13
14
  */
14
15
  export interface SessionLifecycleDeps {
15
16
  version?: string;
17
+ /** Safe build provenance (commit, build time) recorded into session headers. */
18
+ build?: {
19
+ commit?: string;
20
+ builtAt?: string;
21
+ };
16
22
  continueSession: boolean;
17
23
  resumeSessionId?: string;
18
24
  noSession: boolean;
@@ -43,6 +49,8 @@ export interface SessionLifecycleDeps {
43
49
  setMessages: (updater: (messages: Message[]) => Message[]) => void;
44
50
  setLiveMessagesState: (updater: (messages: Message[]) => Message[]) => void;
45
51
  setTokenUsage: (usage: TokenUsage) => void;
52
+ /** Manual /compact mode: model-written summary (default) or heuristic excerpt. */
53
+ manualCompaction?: () => 'llm-summary' | 'heuristic';
46
54
  debugLog: (line: string) => void;
47
55
  showPersistenceWarning: (error: unknown) => void;
48
56
  }
@@ -54,5 +62,7 @@ export interface SessionLifecycle {
54
62
  forkSessionById: (id: string) => Promise<boolean>;
55
63
  clearConversation: () => Promise<void>;
56
64
  compactConversation: (instructions?: string) => boolean;
65
+ /** Manual /compact with a model-written summary; falls back to the heuristic excerpt on any failure (F-09). */
66
+ compactConversationWithModel: (instructions?: string) => Promise<boolean>;
57
67
  }
58
68
  export declare function createSessionLifecycle(deps: SessionLifecycleDeps): SessionLifecycle;