@denizokcu/haze 1.7.12 → 1.8.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 (178) hide show
  1. package/CHANGELOG.md +38 -0
  2. package/README.md +30 -6
  3. package/SECURITY.md +1 -1
  4. package/bin/haze.js +47 -19
  5. package/dist/buildInfo.json +3 -3
  6. package/dist/cli/chat/BusyBar.d.ts +1 -2
  7. package/dist/cli/chat/ChatHeader.d.ts +6 -0
  8. package/dist/cli/chat/ChatHeader.js +11 -0
  9. package/dist/cli/chat/ChatScreen.d.ts +16 -0
  10. package/dist/cli/chat/ChatScreen.js +399 -0
  11. package/dist/cli/chat/ChatScreenView.d.ts +68 -0
  12. package/dist/cli/chat/ChatScreenView.js +47 -0
  13. package/dist/cli/chat/LiveTail.d.ts +11 -0
  14. package/dist/cli/chat/LiveTail.js +26 -0
  15. package/dist/cli/chat/TaskBar.d.ts +3 -2
  16. package/dist/cli/chat/TaskBar.js +4 -0
  17. package/dist/cli/chat/agentTurnRunner.d.ts +12 -0
  18. package/dist/cli/chat/agentTurnRunner.js +177 -0
  19. package/dist/cli/chat/busyIndicator.js +9 -5
  20. package/dist/cli/chat/chatMetrics.d.ts +7 -0
  21. package/dist/cli/chat/chatMetrics.js +15 -1
  22. package/dist/cli/chat/chatViewModel.d.ts +85 -0
  23. package/dist/cli/chat/chatViewModel.js +66 -0
  24. package/dist/cli/chat/fileMentionSuggestions.d.ts +0 -14
  25. package/dist/cli/chat/fileMentionSuggestions.js +4 -21
  26. package/dist/cli/chat/liveTheme.d.ts +11 -0
  27. package/dist/cli/chat/liveTheme.js +26 -0
  28. package/dist/cli/chat/messageFinalize.d.ts +4 -0
  29. package/dist/cli/chat/messageFinalize.js +8 -0
  30. package/dist/cli/chat/messages.js +1 -1
  31. package/dist/cli/chat/pickerOpeners.d.ts +23 -0
  32. package/dist/cli/chat/pickerOpeners.js +36 -0
  33. package/dist/cli/chat/promptSessionState.d.ts +11 -0
  34. package/dist/cli/chat/promptSessionState.js +39 -0
  35. package/dist/cli/chat/renderMetrics.d.ts +8 -0
  36. package/dist/cli/chat/renderMetrics.js +14 -0
  37. package/dist/cli/chat/resizeGuard.d.ts +11 -0
  38. package/dist/cli/chat/resizeGuard.js +25 -0
  39. package/dist/cli/chat/screenDeps.d.ts +116 -0
  40. package/dist/cli/chat/screenDeps.js +1 -0
  41. package/dist/cli/chat/sessionLifecycle.d.ts +2 -0
  42. package/dist/cli/chat/sessionLifecycle.js +4 -1
  43. package/dist/cli/chat/settingsSelection.d.ts +33 -0
  44. package/dist/cli/chat/settingsSelection.js +46 -0
  45. package/dist/cli/chat/skillNotices.d.ts +18 -0
  46. package/dist/cli/chat/skillNotices.js +26 -0
  47. package/dist/cli/chat/startupInfo.js +1 -1
  48. package/dist/cli/chat/submitPipeline.d.ts +8 -0
  49. package/dist/cli/chat/submitPipeline.js +141 -0
  50. package/dist/cli/chat/terminalControl.js +1 -1
  51. package/dist/cli/chat/toolSummaries.d.ts +29 -0
  52. package/dist/cli/chat/toolSummaries.js +268 -0
  53. package/dist/cli/chat/turnState.d.ts +8 -0
  54. package/dist/cli/chat/turnState.js +1 -0
  55. package/dist/cli/chat/userCommandFlow.d.ts +21 -0
  56. package/dist/cli/chat/userCommandFlow.js +66 -0
  57. package/dist/cli/chat/userCommandRunner.d.ts +14 -0
  58. package/dist/cli/chat/userCommandRunner.js +56 -0
  59. package/dist/cli/chat/wizard/providerHandlers.js +19 -2
  60. package/dist/cli/chat/wizardTrail.d.ts +22 -0
  61. package/dist/cli/chat/wizardTrail.js +55 -0
  62. package/dist/cli/commands/chat.d.ts +1 -13
  63. package/dist/cli/commands/chat.js +10 -798
  64. package/dist/cli/commands/commandHelp.js +7 -5
  65. package/dist/cli/commands/commandSuggest.d.ts +2 -0
  66. package/dist/cli/commands/commandSuggest.js +35 -0
  67. package/dist/cli/commands/commands.js +10 -3
  68. package/dist/cli/commands/formatters.d.ts +1 -23
  69. package/dist/cli/commands/formatters.js +3 -252
  70. package/dist/cli/commands/modelCommand.js +11 -7
  71. package/dist/cli/commands/reasoningCommand.js +3 -3
  72. package/dist/cli/commands/runCommand.js +6 -2
  73. package/dist/cli/commands/streaming/attemptLifecycle.js +1 -0
  74. package/dist/cli/commands/streaming/attemptOutcome.js +7 -2
  75. package/dist/cli/commands/streaming/attemptSetup.d.ts +1 -0
  76. package/dist/cli/commands/streaming/attemptSetup.js +26 -2
  77. package/dist/cli/commands/streaming/goalCheckpoint.d.ts +1 -1
  78. package/dist/cli/commands/streaming/stepProjection.d.ts +59 -0
  79. package/dist/cli/commands/streaming/stepProjection.js +54 -0
  80. package/dist/cli/commands/streaming/streamLoop.js +31 -23
  81. package/dist/cli/commands/streaming/toolGroupRenderer.js +1 -1
  82. package/dist/cli/commands/streaming/toolPartHandlers.js +1 -1
  83. package/dist/cli/commands/streaming.d.ts +3 -1
  84. package/dist/cli/commands/wizardFlow.d.ts +2 -0
  85. package/dist/cli/commands/wizardFlow.js +3 -0
  86. package/dist/cli/index.js +8 -4
  87. package/dist/cli/terminalTitle.js +9 -3
  88. package/dist/config/contextFiles.d.ts +2 -5
  89. package/dist/config/contextFiles.js +1 -1
  90. package/dist/config/inputHistory.js +2 -2
  91. package/dist/config/providerAuth.js +2 -2
  92. package/dist/config/providerModelFacts.js +5 -0
  93. package/dist/config/providerPresets.js +1 -1
  94. package/dist/config/settings.d.ts +7 -0
  95. package/dist/config/settings.js +9 -2
  96. package/dist/config/updateCheck.js +2 -2
  97. package/dist/core/agent/completionController.d.ts +1 -1
  98. package/dist/core/agent/contextBudget.d.ts +1 -1
  99. package/dist/core/agent/goalPolicy.js +8 -2
  100. package/dist/core/agent/overflow.js +5 -0
  101. package/dist/core/agent/toolCapabilities.js +14 -0
  102. package/dist/core/agent/userCommands.d.ts +53 -0
  103. package/dist/core/agent/userCommands.js +116 -0
  104. package/dist/core/agent/workState.d.ts +3 -1
  105. package/dist/core/agent/workState.js +57 -26
  106. package/dist/core/contextFileTypes.d.ts +12 -0
  107. package/dist/core/contextFileTypes.js +1 -0
  108. package/dist/core/graph/buildGraph.js +1 -1
  109. package/dist/core/graph/store.js +1 -1
  110. package/dist/core/limits.d.ts +2 -0
  111. package/dist/core/limits.js +2 -0
  112. package/dist/core/log/llmLog.js +2 -2
  113. package/dist/{config → core/persistence}/privateStorage.js +1 -1
  114. package/dist/core/process/runBoundedProcess.d.ts +7 -4
  115. package/dist/core/process/runBoundedProcess.js +10 -5
  116. package/dist/core/safety/redaction.d.ts +2 -0
  117. package/dist/core/safety/redaction.js +26 -5
  118. package/dist/core/safety/secretPaths.js +12 -3
  119. package/dist/core/safety/urlGuard.js +2 -0
  120. package/dist/core/session/sessionStore.d.ts +8 -1
  121. package/dist/core/session/sessionStore.js +15 -4
  122. package/dist/core/shellOutput/reducers/validation.d.ts +1 -1
  123. package/dist/core/shellOutput/types.d.ts +1 -1
  124. package/dist/{llm → core}/toolResultTypes.d.ts +1 -1
  125. package/dist/core/validation/outputParser.d.ts +1 -1
  126. package/dist/llm/hazeTools.js +2 -0
  127. package/dist/llm/lsp/pool.js +1 -1
  128. package/dist/llm/lsp/workspaceEdit.d.ts +1 -1
  129. package/dist/llm/requestContext.d.ts +3 -0
  130. package/dist/llm/requestContext.js +20 -8
  131. package/dist/llm/systemPrompt.js +10 -3
  132. package/dist/llm/toolGroups.d.ts +534 -0
  133. package/dist/llm/toolGroups.js +57 -0
  134. package/dist/llm/tools/editMatch.d.ts +1 -1
  135. package/dist/llm/tools/failures.d.ts +1 -1
  136. package/dist/llm/tools/fileToolShared.d.ts +1 -1
  137. package/dist/llm/tools/fileToolShared.js +1 -1
  138. package/dist/llm/tools/fileTools.js +1 -1
  139. package/dist/llm/tools/gitTools.d.ts +12 -0
  140. package/dist/llm/tools/gitTools.js +527 -0
  141. package/dist/llm/tools/readRecovery.d.ts +1 -1
  142. package/dist/llm/tools/replaceInFiles.d.ts +1 -1
  143. package/dist/llm/tools/replaceInFiles.js +1 -1
  144. package/dist/llm/tools/taskTool.js +4 -1
  145. package/dist/llm/tools/toolContext.js +5 -2
  146. package/dist/llm/tools/toolContextState.d.ts +1 -1
  147. package/dist/llm/tools/workspaceFile.d.ts +2 -2
  148. package/dist/llm/tools/workspaceFile.js +10 -5
  149. package/dist/skills/SkillRegistry.js +1 -1
  150. package/dist/skills/builder/SkillBuilder.js +1 -1
  151. package/dist/skills/plugins/installer.js +1 -1
  152. package/dist/skills/plugins/runtime.js +1 -1
  153. package/dist/ui/components/MarkdownText.d.ts +14 -0
  154. package/dist/ui/components/MarkdownText.js +77 -12
  155. package/dist/ui/components/NativeIndicators.js +5 -1
  156. package/dist/ui/components/StreamingMarkdownText.d.ts +3 -1
  157. package/dist/ui/components/StreamingMarkdownText.js +39 -11
  158. package/dist/ui/components/TextInput.d.ts +1 -2
  159. package/dist/ui/components/TextInput.js +79 -9
  160. package/dist/ui/components/WizardChoices.d.ts +1 -2
  161. package/dist/ui/components/useInputSuggestions.d.ts +1 -1
  162. package/dist/ui/components/useInputSuggestions.js +1 -1
  163. package/dist/ui/mentionDetection.d.ts +20 -0
  164. package/dist/ui/mentionDetection.js +24 -0
  165. package/dist/ui/terminalColors.d.ts +4 -4
  166. package/dist/ui/terminalColors.js +23 -6
  167. package/dist/ui/terminalSanitize.js +8 -3
  168. package/dist/ui/textGeometry.d.ts +2 -0
  169. package/dist/ui/textGeometry.js +6 -0
  170. package/dist/ui/themes/registry.js +33 -33
  171. package/dist/utils/openPath.js +7 -0
  172. package/package.json +13 -13
  173. /package/dist/{llm/tools → core/ignore}/gitIgnore.d.ts +0 -0
  174. /package/dist/{llm/tools → core/ignore}/gitIgnore.js +0 -0
  175. /package/dist/{config → core}/paths.d.ts +0 -0
  176. /package/dist/{config → core}/paths.js +0 -0
  177. /package/dist/{config → core/persistence}/privateStorage.d.ts +0 -0
  178. /package/dist/{llm → core}/toolResultTypes.js +0 -0
@@ -5,7 +5,7 @@ import { assertRealPathInsideWorkspace, assertWritablePathInsideWorkspace, resol
5
5
  import { isPathBlessed } from '../../core/attachments/readBlessings.js';
6
6
  import { isProtectedSecretPath } from '../../core/safety/secretPaths.js';
7
7
  import { assertNotIgnored } from './fileToolShared.js';
8
- import { resolveGitDirs } from './gitIgnore.js';
8
+ import { resolveGitDirs } from '../../core/ignore/gitIgnore.js';
9
9
  import { HazeToolError } from './failures.js';
10
10
  import { discoverScopedContext, hazeContext, scopedContextMutationStop } from './toolContext.js';
11
11
  /**
@@ -23,8 +23,12 @@ async function assertNotSecretPath(absolutePath, realPath, inputPath, operation)
23
23
  const GIT_DIR_NAME = '.git';
24
24
  /** Bare-repo directory names (`backup.git/`, `repo.git/`) hold hook-bearing git internals too. */
25
25
  const BARE_GIT_DIR_NAME = /\.git$/;
26
- /** Basenames inside a git directory that stay refused for reads too; hook execution makes all of `hooks/**` sensitive. */
27
- const PROTECTED_GIT_READ_BASENAMES = new Set(['config', 'credentials']);
26
+ /**
27
+ * Basenames inside a git directory that stay refused for reads too; hook
28
+ * execution makes all of `hooks/**` sensitive. `config.lock` holds the config
29
+ * content while git holds the lock, `config.worktree` the per-worktree config (SEC-03).
30
+ */
31
+ const PROTECTED_GIT_READ_BASENAMES = new Set(['config', 'config.lock', 'config.worktree', 'credentials']);
28
32
  function isInsideDirectory(candidate, directory) {
29
33
  if (candidate === directory)
30
34
  return true;
@@ -129,9 +133,10 @@ async function assertNotGitInternals(absolutePath, realPath, inputPath, operatio
129
133
  // Reads: only the credential-bearing and hook entries are refused; other
130
134
  // `.git` object reads (e.g. `.git/HEAD`) stay allowed. Submodule gitdirs
131
135
  // live under `modules/**`, where config/credentials carry remote URLs at
132
- // any depth.
136
+ // any depth. Bare repos (`backup.git/`) count as git roots for reads too:
137
+ // their config is reachable through the bless set and carries the same credentials.
133
138
  for (const candidate of [absolutePath, realPath]) {
134
- const root = gitInternalsRoot(candidate, gitDirs);
139
+ const root = gitInternalsRoot(candidate, gitDirs, true);
135
140
  if (!root)
136
141
  continue;
137
142
  const entry = path.relative(root, candidate);
@@ -1,7 +1,7 @@
1
1
  import fs from 'node:fs/promises';
2
2
  import { pathExists, ensureDir } from '../utils/fs.js';
3
3
  import path from 'node:path';
4
- import { GLOBAL_SKILLS_DIR } from '../config/paths.js';
4
+ import { GLOBAL_SKILLS_DIR } from '../core/paths.js';
5
5
  import { loadSkill } from './SkillLoader.js';
6
6
  import { confinedResolve } from './confinement.js';
7
7
  import { loadPluginSkills } from './plugins/runtime.js';
@@ -3,7 +3,7 @@ import fs from 'node:fs/promises';
3
3
  import { ensureDir, move, pathExists } from '../../utils/fs.js';
4
4
  import path from 'node:path';
5
5
  import YAML from 'yaml';
6
- import { GLOBAL_SKILLS_DIR } from '../../config/paths.js';
6
+ import { GLOBAL_SKILLS_DIR } from '../../core/paths.js';
7
7
  import { modelWithConfig } from '../../llm/client.js';
8
8
  import { loadSkill } from '../SkillLoader.js';
9
9
  import { confinedResolve } from '../confinement.js';
@@ -1,7 +1,7 @@
1
1
  import fs from 'node:fs/promises';
2
2
  import path from 'node:path';
3
3
  import { createHash, randomUUID } from 'node:crypto';
4
- import { HAZE_DIR } from '../../config/paths.js';
4
+ import { HAZE_DIR } from '../../core/paths.js';
5
5
  import { boundedRead, canonicalRoot, inspectPlugin, localPath, object, PLUGIN_LIMITS, readJson, safePath, validatePluginName } from './package.js';
6
6
  const hash = (data) => createHash('sha256').update(data).digest('hex');
7
7
  const missing = (error) => error.code === 'ENOENT';
@@ -1,5 +1,5 @@
1
1
  import fs from 'node:fs/promises';
2
- import { GLOBAL_PLUGINS_DIR } from '../../config/paths.js';
2
+ import { GLOBAL_PLUGINS_DIR } from '../../core/paths.js';
3
3
  import { loadSkill } from '../SkillLoader.js';
4
4
  import { enumeratePlugins } from './installer.js';
5
5
  import { canonicalRoot, localPath, readPluginManifest, safePath } from './package.js';
@@ -17,4 +17,18 @@ export declare function clearMarkdownRootChunksCacheForTests(): void;
17
17
  * MarkdownText can preserve their shared filename and starting line metadata.
18
18
  */
19
19
  export declare function markdownRootChunks(content: string): string[];
20
+ type InlineKind = 'text' | 'code' | 'strong' | 'em' | 'strongem' | 'del' | 'link';
21
+ type InlinePart = {
22
+ kind: InlineKind;
23
+ text: string;
24
+ };
25
+ /**
26
+ * Inline tokens come from marked's inline lexer (FE-08/FE-19), so the
27
+ * rendered text follows the same GFM rules as the block parse: nested
28
+ * emphasis, `~~strike~~`, autolinks, images and escapes. Inline HTML is
29
+ * dropped; links stay plain `text (url)` text (no OSC 8). Falls back to the
30
+ * hand-rolled tokenizer if the lexer throws on malformed input.
31
+ */
32
+ export declare function tokenizeInline(text: string): InlinePart[];
20
33
  export declare function renderMarkdownTable(table: Tokens.Table, maxWidth?: number): string[];
34
+ export {};
@@ -1,7 +1,7 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import React from 'react';
3
3
  import { Box, Text } from 'ink';
4
- import { marked } from 'marked';
4
+ import { Lexer, marked } from 'marked';
5
5
  import { cellWidth } from '../textGeometry.js';
6
6
  import { wrapDisplayValue } from '../inputBuffer.js';
7
7
  import { theme } from '../theme.js';
@@ -109,7 +109,7 @@ function MarkdownBlock({ token, width, source, textOverride, compactAfter }) {
109
109
  case 'space':
110
110
  return _jsx(Text, { children: " " });
111
111
  case 'hr':
112
- return _jsx(Text, { color: theme.accentDim, children: "\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500" });
112
+ return _jsx(Text, { color: theme.accentDim, children: '─'.repeat(Math.max(1, width)) });
113
113
  case 'blockquote': {
114
114
  const quote = token;
115
115
  return _jsx(Box, { flexDirection: "column", marginY: 1, children: quote.text.split('\n').map((line, index) => _jsx(Text, { backgroundColor: theme.surfaceBg, children: padAnsi(line || ' ', width) }, index)) });
@@ -128,6 +128,12 @@ function MarkdownBlock({ token, width, source, textOverride, compactAfter }) {
128
128
  const lines = renderMarkdownTable(table, width);
129
129
  return _jsx(Box, { flexDirection: "column", marginBottom: 1, children: lines.map((line, index) => _jsx(TableLine, { line: line }, index)) });
130
130
  }
131
+ case 'html': {
132
+ // Block-level HTML gets the same treatment as inline HTML: markup is
133
+ // dropped and its text kept, never the raw tags.
134
+ const text = String(token.raw).replace(/<[^>]*>/g, ' ').replace(/\s+/g, ' ').trim();
135
+ return text ? _jsx(InlineMarkdown, { text: text }) : null;
136
+ }
131
137
  default:
132
138
  return _jsx(Text, { children: 'raw' in token ? String(token.raw) : '' });
133
139
  }
@@ -245,15 +251,16 @@ function InlineMarkdown({ text }) {
245
251
  return _jsx(Text, { children: parts.map((part, index) => renderInlinePart(part, index)) });
246
252
  }
247
253
  function renderInlinePart(part, index) {
248
- if (part.kind === 'code')
249
- return _jsx(Text, { color: theme.warning, backgroundColor: theme.codeBg, children: part.text }, index);
250
- if (part.kind === 'strong')
251
- return _jsx(Text, { bold: true, children: part.text }, index);
252
- if (part.kind === 'em')
253
- return _jsx(Text, { italic: true, children: part.text }, index);
254
- if (part.kind === 'link')
255
- return _jsx(Text, { color: theme.accent, children: part.text }, index);
256
- return _jsx(Text, { children: part.text }, index);
254
+ const key = index;
255
+ switch (part.kind) {
256
+ case 'code': return _jsx(Text, { color: theme.warning, backgroundColor: theme.codeBg, children: part.text }, key);
257
+ case 'strong': return _jsx(Text, { bold: true, children: part.text }, key);
258
+ case 'em': return _jsx(Text, { italic: true, children: part.text }, key);
259
+ case 'strongem': return _jsx(Text, { bold: true, italic: true, children: part.text }, key);
260
+ case 'del': return _jsx(Text, { strikethrough: true, children: part.text }, key);
261
+ case 'link': return _jsx(Text, { color: theme.accent, children: part.text }, key);
262
+ default: return _jsx(Text, { children: part.text }, key);
263
+ }
257
264
  }
258
265
  function splitInlineIntoAtoms(parts) {
259
266
  const atoms = [];
@@ -306,7 +313,65 @@ function wrapInlineAtoms(atoms, maxWidth) {
306
313
  flushLine();
307
314
  return lines.length > 0 ? lines : [[]];
308
315
  }
309
- function tokenizeInline(text) {
316
+ /**
317
+ * Inline tokens come from marked's inline lexer (FE-08/FE-19), so the
318
+ * rendered text follows the same GFM rules as the block parse: nested
319
+ * emphasis, `~~strike~~`, autolinks, images and escapes. Inline HTML is
320
+ * dropped; links stay plain `text (url)` text (no OSC 8). Falls back to the
321
+ * hand-rolled tokenizer if the lexer throws on malformed input.
322
+ */
323
+ export function tokenizeInline(text) {
324
+ try {
325
+ return flattenInlineTokens(Lexer.lexInline(text));
326
+ }
327
+ catch {
328
+ return tokenizeInlineFallback(text);
329
+ }
330
+ }
331
+ function flattenInlineTokens(tokens, inherited = 'text') {
332
+ const out = [];
333
+ const nested = (kind) => {
334
+ if (kind === 'text' || inherited === kind)
335
+ return inherited;
336
+ if ((inherited === 'strong' && kind === 'em') || (inherited === 'em' && kind === 'strong'))
337
+ return 'strongem';
338
+ return kind;
339
+ };
340
+ for (const token of tokens) {
341
+ switch (token.type) {
342
+ case 'text':
343
+ case 'escape':
344
+ out.push({ kind: inherited, text: token.text });
345
+ break;
346
+ case 'codespan':
347
+ out.push({ kind: 'code', text: token.text });
348
+ break;
349
+ case 'strong':
350
+ case 'em':
351
+ case 'del':
352
+ out.push(...flattenInlineTokens(token.tokens ?? [{ type: 'text', raw: '', text: token.text }], nested(token.type)));
353
+ break;
354
+ case 'link':
355
+ case 'image': {
356
+ const { href } = token;
357
+ const label = flattenInlineTokens(token.tokens ?? []).map(part => part.text).join('');
358
+ // An autolink's label is its URL; repeating it would double the text.
359
+ out.push({ kind: 'link', text: label === href ? label : `${label} (${href})` });
360
+ break;
361
+ }
362
+ case 'br':
363
+ out.push({ kind: inherited, text: ' ' });
364
+ break;
365
+ default:
366
+ // Inline HTML and anything unrecognised: drop the markup, keep text.
367
+ if ('text' in token && typeof token.text === 'string' && token.type !== 'html')
368
+ out.push({ kind: inherited, text: token.text });
369
+ break;
370
+ }
371
+ }
372
+ return out;
373
+ }
374
+ function tokenizeInlineFallback(text) {
310
375
  const out = [];
311
376
  const regex = /`([^`]+)`|\*\*([^*]+)\*\*|\*([^*]+)\*|\[([^\]]+)\]\(([^)]+)\)/g;
312
377
  let last = 0;
@@ -1,4 +1,5 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { useMemo } from 'react';
2
3
  import { Box, Text, useAnimation, useIsScreenReaderEnabled } from 'ink';
3
4
  import { StatusMessage, ThemeProvider, defaultTheme, extendTheme } from '@inkjs/ui';
4
5
  import { theme } from '../theme.js';
@@ -28,5 +29,8 @@ export function ActivitySpinner({ color = theme.command }) {
28
29
  return _jsx(Box, { flexShrink: 0, children: _jsx(Text, { color: color, children: screenReader ? '·' : glyph }) });
29
30
  }
30
31
  export function StatusNotice({ variant, children }) {
31
- return _jsx(ThemeProvider, { theme: indicatorTheme(theme), children: _jsx(StatusMessage, { variant: variant, children: children }) });
32
+ // FE-11: build the mapped theme once per palette object (theme is swapped
33
+ // live by setActiveTheme, so key on its identity).
34
+ const mapped = useMemo(() => indicatorTheme(theme), [theme]);
35
+ return _jsx(ThemeProvider, { theme: mapped, children: _jsx(StatusMessage, { variant: variant, children: children }) });
32
36
  }
@@ -1,7 +1,9 @@
1
1
  import React from 'react';
2
2
  /** The active block remains replaceable; only settled roots belong in Static. */
3
- export declare const StreamingMarkdownText: React.MemoExoticComponent<({ content, width, maxVisibleLines }: {
3
+ export declare const StreamingMarkdownText: React.MemoExoticComponent<({ content, width, maxVisibleLines, streaming }: {
4
4
  content: string;
5
5
  width: number;
6
6
  maxVisibleLines?: number;
7
+ /** While streaming, deltas are coalesced; settled text renders without delay. */
8
+ streaming?: boolean;
7
9
  }) => React.JSX.Element | null>;
@@ -1,5 +1,5 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import React, { useEffect, useState } from 'react';
2
+ import React, { useEffect, useRef, useState } from 'react';
3
3
  import { Box, Text, renderToString } from 'ink';
4
4
  import { MarkdownText } from './MarkdownText.js';
5
5
  import { stripTerminalControlSequences } from '../terminalSanitize.js';
@@ -18,19 +18,47 @@ function renderMarkdownRows(content, width) {
18
18
  // the newest content in a small viewport.
19
19
  return output.replace(/\n[\s]*$/, '').split('\n');
20
20
  }
21
+ /**
22
+ * Streaming deltas are throttled to one offscreen render per window: the first
23
+ * delta of a window renders promptly, later ones are folded into its trailing
24
+ * render (FE-05).
25
+ */
26
+ const COALESCE_MS = 16;
21
27
  /** The active block remains replaceable; only settled roots belong in Static. */
22
- export const StreamingMarkdownText = React.memo(function StreamingMarkdownText({ content, width, maxVisibleLines }) {
28
+ export const StreamingMarkdownText = React.memo(function StreamingMarkdownText({ content, width, maxVisibleLines, streaming = true }) {
23
29
  const [rendered, setRendered] = useState({ content: '', width, rows: [] });
24
- // Ink's synchronous offscreen renderer must run outside React's render and
25
- // commit phases. The microtask also lets superseded deltas cancel their work.
30
+ const latest = useRef({ content, width });
31
+ latest.current = { content, width };
32
+ const pendingTimer = useRef(undefined);
33
+ const lastRenderAt = useRef(0);
26
34
  useEffect(() => {
27
- let cancelled = false;
28
- queueMicrotask(() => {
29
- if (!cancelled)
30
- setRendered({ content, width, rows: renderMarkdownRows(content, width) });
31
- });
32
- return () => { cancelled = true; };
33
- }, [content, width]);
35
+ // Ink's synchronous offscreen renderer must run outside React's render and
36
+ // commit phases, which this effect body is. A burst of deltas inside one
37
+ // window costs at most two renders: the window's leading render and one
38
+ // trailing render that reads the latest text when the timer fires (FE-05).
39
+ const renderLatest = () => {
40
+ pendingTimer.current = undefined;
41
+ lastRenderAt.current = Date.now();
42
+ const { content, width } = latest.current;
43
+ setRendered({ content, width, rows: renderMarkdownRows(content, width) });
44
+ };
45
+ if (!streaming) {
46
+ // Settled text never waits for the window.
47
+ clearTimeout(pendingTimer.current);
48
+ pendingTimer.current = undefined;
49
+ }
50
+ if (pendingTimer.current === undefined) {
51
+ const remaining = streaming ? COALESCE_MS - (Date.now() - lastRenderAt.current) : 0;
52
+ if (remaining <= 0) {
53
+ let cancelled = false;
54
+ queueMicrotask(() => { if (!cancelled)
55
+ renderLatest(); });
56
+ return () => { cancelled = true; };
57
+ }
58
+ pendingTimer.current = setTimeout(renderLatest, remaining);
59
+ }
60
+ }, [content, width, streaming]);
61
+ useEffect(() => () => clearTimeout(pendingTimer.current), []);
34
62
  // Never replay a previous root after it enters Static, or show stale, wider
35
63
  // rows during a terminal resize. Append-only deltas can retain their preview.
36
64
  const rows = rendered.width === width && content.startsWith(rendered.content) ? rendered.rows : [];
@@ -1,4 +1,3 @@
1
- import React from 'react';
2
1
  type TextInputKey = {
3
2
  return?: boolean;
4
3
  shift?: boolean;
@@ -57,5 +56,5 @@ export declare function TextInput({ placeholder, disabled, mask, historyItems, r
57
56
  */
58
57
  onInterrupt?: () => void;
59
58
  onSubmit: (value: string) => void;
60
- }): React.JSX.Element;
59
+ }): import("react").JSX.Element;
61
60
  export {};
@@ -1,7 +1,7 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
2
  import { useEffect, useRef, useState } from 'react';
3
3
  import { Box, Text, measureElement, useCursor, useInput, useIsScreenReaderEnabled, usePaste } from 'ink';
4
- import { cellWidth, graphemes, nextBoundary, offsetAtColumn, previousBoundary, safeInputDisplay } from '../textGeometry.js';
4
+ import { cellWidth, graphemes, nextBoundary, offsetAtColumn, previousBoundary, previousWordBoundary, safeInputDisplay } from '../textGeometry.js';
5
5
  import { theme } from '../theme.js';
6
6
  import { compactPasteBlocksForDisplay, cursorPosition, displayCursorForValueCursor, lineCount, normalizeLineEndings, updatePasteBlocksForReplacement, valueCursorForDisplayCursor, wrapDisplayValue, } from '../inputBuffer.js';
7
7
  import { useInputSuggestions } from './useInputSuggestions.js';
@@ -63,6 +63,10 @@ export function TextInput({ placeholder, disabled, mask, historyItems = [], reco
63
63
  const history = useRef(historyItems);
64
64
  const historyIndex = useRef(null);
65
65
  const draft = useRef('');
66
+ // Draft removed by Esc, restorable with Up before history navigation (UX-02).
67
+ const clearedDraft = useRef(null);
68
+ // `cursor:value` the autocomplete list was dismissed for; it returns once either changes.
69
+ const [dismissedListFor, setDismissedListFor] = useState();
66
70
  const nextPasteId = useRef(1);
67
71
  const preferredColumn = useRef(null);
68
72
  const inputRef = useRef({ value, cursor, pasteBlocks });
@@ -82,7 +86,11 @@ export function TextInput({ placeholder, disabled, mask, historyItems = [], reco
82
86
  }, [disabled]);
83
87
  const suggestionLayers = useInputSuggestions({ value, cursor, suggestions, suggestionMode, mask, getMentionSuggestions });
84
88
  const { detectedMention, inMentionMode, filteredSuggestions, mentionList, activeMentionIndex, activeSuggestionIndex, activeSuggestion } = suggestionLayers;
89
+ // Wizard pickers (`always` mode) are exited with Esc, so only chat-mode autocomplete lists absorb the first press.
90
+ const listDismissed = suggestionMode === 'slash' && dismissedListFor === `${cursor}:${value}`;
85
91
  function setInput(next, nextCursor = next.length, nextPasteBlocks = []) {
92
+ if (next.length > 0)
93
+ clearedDraft.current = null;
86
94
  preferredColumn.current = null;
87
95
  const clampedCursor = Math.max(0, Math.min(nextCursor, next.length));
88
96
  inputRef.current = { value: next, cursor: clampedCursor, pasteBlocks: nextPasteBlocks };
@@ -158,6 +166,14 @@ export function TextInput({ placeholder, disabled, mask, historyItems = [], reco
158
166
  return;
159
167
  }
160
168
  if (key.escape) {
169
+ // An open autocomplete list takes the first Esc: close it and keep the draft.
170
+ if (suggestionMode === 'slash' && !listDismissed && (inMentionMode ? mentionList.length : filteredSuggestions.length) > 0) {
171
+ setDismissedListFor(`${cursor}:${value}`);
172
+ suggestionLayers.resetSelection();
173
+ return;
174
+ }
175
+ if (value.length > 0)
176
+ clearedDraft.current = { value, pasteBlocks: inputRef.current.pasteBlocks };
161
177
  setInput('');
162
178
  historyIndex.current = null;
163
179
  draft.current = '';
@@ -169,7 +185,7 @@ export function TextInput({ placeholder, disabled, mask, historyItems = [], reco
169
185
  onResumeKey();
170
186
  return;
171
187
  }
172
- if (key.tab && activeSuggestion) {
188
+ if (key.tab && !listDismissed && activeSuggestion) {
173
189
  if (inMentionMode && detectedMention) {
174
190
  // Partial replacement of the `@token` range, not the whole input —
175
191
  // mention completion fires mid-prompt.
@@ -191,12 +207,12 @@ export function TextInput({ placeholder, disabled, mask, historyItems = [], reco
191
207
  // submits `read @package.json` (matches slash-command behavior).
192
208
  let submittedValue;
193
209
  let submittedSuggestion;
194
- if (inMentionMode && detectedMention && activeSuggestion && activeSuggestion.value !== detectedMention.token) {
210
+ if (!listDismissed && inMentionMode && detectedMention && activeSuggestion && activeSuggestion.value !== detectedMention.token) {
195
211
  submittedValue = value.slice(0, detectedMention.start) + activeSuggestion.value + value.slice(detectedMention.end);
196
212
  submittedSuggestion = activeSuggestion;
197
213
  }
198
214
  else {
199
- const shouldUseSuggestion = !!activeSuggestion && activeSuggestion.value !== value.trim() && (suggestionMode === 'always' || value.startsWith('/'));
215
+ const shouldUseSuggestion = !listDismissed && !!activeSuggestion && activeSuggestion.value !== value.trim() && (suggestionMode === 'always' || value.startsWith('/'));
200
216
  submittedValue = shouldUseSuggestion && activeSuggestion ? activeSuggestion.value : value;
201
217
  submittedSuggestion = shouldUseSuggestion ? activeSuggestion : undefined;
202
218
  }
@@ -205,6 +221,7 @@ export function TextInput({ placeholder, disabled, mask, historyItems = [], reco
205
221
  setInput('');
206
222
  historyIndex.current = null;
207
223
  draft.current = '';
224
+ clearedDraft.current = null;
208
225
  nextPasteId.current = 1;
209
226
  if (submitted || submitOnEmpty)
210
227
  submitValue(submitted, historyValue);
@@ -221,11 +238,18 @@ export function TextInput({ placeholder, disabled, mask, historyItems = [], reco
221
238
  return;
222
239
  }
223
240
  if (key.upArrow) {
224
- if (suggestionLayers.moveSelection(-1))
241
+ if (!listDismissed && suggestionLayers.moveSelection(-1))
225
242
  return;
226
- if (filteredSuggestions.length === 0 && !inMentionMode && moveCursorVertically(-1))
243
+ if ((listDismissed || (filteredSuggestions.length === 0 && !inMentionMode)) && moveCursorVertically(-1))
227
244
  return;
228
245
  preferredColumn.current = null;
246
+ if (value.length === 0 && historyIndex.current === null && clearedDraft.current) {
247
+ const restored = clearedDraft.current;
248
+ clearedDraft.current = null;
249
+ nextPasteId.current = Math.max(1, ...restored.pasteBlocks.map(block => block.id + 1));
250
+ setInput(restored.value, restored.value.length, restored.pasteBlocks);
251
+ return;
252
+ }
229
253
  if (history.current.length === 0)
230
254
  return;
231
255
  if (historyIndex.current === null) {
@@ -238,9 +262,9 @@ export function TextInput({ placeholder, disabled, mask, historyItems = [], reco
238
262
  return;
239
263
  }
240
264
  if (key.downArrow) {
241
- if (suggestionLayers.moveSelection(1))
265
+ if (!listDismissed && suggestionLayers.moveSelection(1))
242
266
  return;
243
- if (filteredSuggestions.length === 0 && !inMentionMode && moveCursorVertically(1))
267
+ if ((listDismissed || (filteredSuggestions.length === 0 && !inMentionMode)) && moveCursorVertically(1))
244
268
  return;
245
269
  preferredColumn.current = null;
246
270
  if (historyIndex.current === null)
@@ -280,6 +304,52 @@ export function TextInput({ placeholder, disabled, mask, historyItems = [], reco
280
304
  onToggleTasks?.();
281
305
  return;
282
306
  }
307
+ // Readline-style line editing (UX-13): Ctrl+W deletes the word before the
308
+ // cursor, Ctrl+U clears to the start of the line, Ctrl+K to the end.
309
+ // Ink parses a lone control byte as ctrl+letter, but batched bytes arrive
310
+ // raw in `input` — handle both forms. \x03/\x09/\x0d are excluded: Ink
311
+ // flags them as interrupt/tab/return before this point.
312
+ const isRawControl = (ch) => {
313
+ const code = ch.charCodeAt(0);
314
+ return (code >= 0x01 && code <= 0x1a) && code !== 0x03 && code !== 0x09 && code !== 0x0d;
315
+ };
316
+ const rawControls = [...input].filter(isRawControl);
317
+ const effective = (letter, raw) => (key.ctrl === true && input === letter) || rawControls.includes(raw);
318
+ if (effective('w', '\u0017') || effective('u', '\u0015') || effective('k', '\u000b') || effective('a', '\u0001') || effective('e', '\u0005')) {
319
+ const valueNow = inputRef.current.value;
320
+ const cursorNow = inputRef.current.cursor;
321
+ // Line-scoped, like readline: the lines around the cursor bound each edit.
322
+ const lineStart = valueNow.lastIndexOf('\n', cursorNow - 1) + 1;
323
+ const nextBreak = valueNow.indexOf('\n', cursorNow);
324
+ const lineEnd = nextBreak === -1 ? valueNow.length : nextBreak;
325
+ if (effective('w', '\u0017')) {
326
+ const start = Math.max(lineStart, previousWordBoundary(valueNow, cursorNow));
327
+ if (start < cursorNow)
328
+ replaceInput(start, cursorNow, '');
329
+ }
330
+ else if (effective('u', '\u0015')) {
331
+ if (cursorNow > lineStart)
332
+ replaceInput(lineStart, cursorNow, '');
333
+ }
334
+ else if (effective('k', '\u000b')) {
335
+ if (cursorNow < lineEnd)
336
+ replaceInput(cursorNow, lineEnd, '');
337
+ }
338
+ else if (effective('a', '\u0001')) {
339
+ preferredColumn.current = null;
340
+ moveValueCursor(lineStart);
341
+ }
342
+ else if (effective('e', '\u0005')) {
343
+ preferredColumn.current = null;
344
+ moveValueCursor(lineEnd);
345
+ }
346
+ if (rawControls.length > 0) {
347
+ const printable = [...input].filter(ch => !isRawControl(ch)).join('');
348
+ if (printable)
349
+ replaceInput(inputRef.current.cursor, inputRef.current.cursor, printable);
350
+ }
351
+ return;
352
+ }
283
353
  if (key.ctrl)
284
354
  return; // Unsupported Ctrl combinations are controls, not text.
285
355
  if (input) {
@@ -308,7 +378,7 @@ export function TextInput({ placeholder, disabled, mask, historyItems = [], reco
308
378
  }
309
379
  }
310
380
  setCursorPosition(imeCursor);
311
- const displayList = inMentionMode ? mentionList : filteredSuggestions;
381
+ const displayList = listDismissed ? [] : inMentionMode ? mentionList : filteredSuggestions;
312
382
  const displayActiveIndex = inMentionMode ? activeMentionIndex : activeSuggestionIndex;
313
383
  const suggestionStart = Math.max(0, displayActiveIndex - Math.max(0, suggestionRows - 1));
314
384
  const visibleSuggestions = displayList.slice(suggestionStart, suggestionStart + suggestionRows);
@@ -1,4 +1,3 @@
1
- import React from 'react';
2
1
  import { type HazeTheme } from '../theme.js';
3
2
  import type { TextInputSuggestion } from './TextInput.js';
4
3
  /** Rebuild from the live palette; Static transcript and terminal defaults are untouched. */
@@ -15,4 +14,4 @@ export declare function WizardChoices({ suggestions, activeIndex, rows }: {
15
14
  suggestions: TextInputSuggestion[];
16
15
  activeIndex: number;
17
16
  rows: number;
18
- }): React.JSX.Element | null;
17
+ }): import("react").JSX.Element | null;
@@ -1,4 +1,4 @@
1
- import { type MentionContext } from '../../cli/chat/fileMentionSuggestions.js';
1
+ import { type MentionContext } from '../mentionDetection.js';
2
2
  import type { MentionSuggestionsProvider, TextInputSuggestion } from './TextInput.js';
3
3
  /**
4
4
  * The suggestion engine behind TextInput, extracted as a standalone hook:
@@ -1,5 +1,5 @@
1
1
  import { useEffect, useState } from 'react';
2
- import { detectMentionAtCursor } from '../../cli/chat/fileMentionSuggestions.js';
2
+ import { detectMentionAtCursor } from '../mentionDetection.js';
3
3
  /**
4
4
  * The suggestion engine behind TextInput, extracted as a standalone hook:
5
5
  * two composable layers — slash-command filtering (sync, prefix/substring
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Pure `@mention` detection for the input editor (F04 AC1): finds the `@token`
3
+ * under the text cursor. Lives in `ui/` so the suggestion hook does not import
4
+ * from the CLI layer; the filesystem listing behind the suggestions stays in
5
+ * `cli/chat/fileMentionSuggestions.ts`.
6
+ */
7
+ export interface MentionContext {
8
+ /** Full token including the leading `@`. */
9
+ token: string;
10
+ /** Index in the source string where the `@` sits. */
11
+ start: number;
12
+ /** Index one past the last char of the token. */
13
+ end: number;
14
+ }
15
+ /**
16
+ * Find the `@token` (if any) at the given cursor position. The cursor may
17
+ * sit anywhere inside the token or directly after its last char — both
18
+ * count as "inside" so the user can keep typing or completing.
19
+ */
20
+ export declare function detectMentionAtCursor(value: string, cursor: number): MentionContext | undefined;
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Pure `@mention` detection for the input editor (F04 AC1): finds the `@token`
3
+ * under the text cursor. Lives in `ui/` so the suggestion hook does not import
4
+ * from the CLI layer; the filesystem listing behind the suggestions stays in
5
+ * `cli/chat/fileMentionSuggestions.ts`.
6
+ */
7
+ /** Characters allowed inside a `@token` while it is being typed. */
8
+ const MENTION_TOKEN_PATTERN = /@[\w./~-]*/g;
9
+ /**
10
+ * Find the `@token` (if any) at the given cursor position. The cursor may
11
+ * sit anywhere inside the token or directly after its last char — both
12
+ * count as "inside" so the user can keep typing or completing.
13
+ */
14
+ export function detectMentionAtCursor(value, cursor) {
15
+ for (const match of value.matchAll(MENTION_TOKEN_PATTERN)) {
16
+ if (match.index === undefined)
17
+ continue;
18
+ const start = match.index;
19
+ const end = start + match[0].length;
20
+ if (cursor >= start && cursor <= end)
21
+ return { token: match[0], start, end };
22
+ }
23
+ return undefined;
24
+ }
@@ -23,7 +23,7 @@ export interface TerminalColorStream {
23
23
  write(chunk: string): unknown;
24
24
  isTTY?: boolean;
25
25
  }
26
- /** Adopt a theme's foreground/background as the terminal defaults (OSC 10 + 11). Malformed parts are skipped; no-op off-TTY. */
27
- export declare function applyTerminalColors(foreground: string, background: string, stream?: TerminalColorStream): void;
28
- /** Restore the terminal's own default colors (OSC 110 + 111). No-op off-TTY. */
29
- export declare function resetTerminalColors(stream?: TerminalColorStream): void;
26
+ /** Adopt a theme's foreground/background as the terminal defaults (OSC 10 + 11). Malformed parts are skipped; no-op off-TTY or without colour capability. */
27
+ export declare function applyTerminalColors(foreground: string, background: string, stream?: TerminalColorStream, env?: NodeJS.ProcessEnv): void;
28
+ /** Restore the terminal's own default colors (OSC 110 + 111). No-op off-TTY or without colour capability. */
29
+ export declare function resetTerminalColors(stream?: TerminalColorStream, env?: NodeJS.ProcessEnv): void;
@@ -27,9 +27,26 @@ function oscRgb(color) {
27
27
  const [, r = '', g = '', b = ''] = match;
28
28
  return `${r.toLowerCase()}/${g.toLowerCase()}/${b.toLowerCase()}`;
29
29
  }
30
- /** Adopt a theme's foreground/background as the terminal defaults (OSC 10 + 11). Malformed parts are skipped; no-op off-TTY. */
31
- export function applyTerminalColors(foreground, background, stream = process.stdout) {
32
- if (!stream.isTTY)
30
+ /**
31
+ * OSC 10/11 are written raw (chalk never sees them), so they need their own
32
+ * capability gate: only on a TTY that reports truecolor (COLORTERM) or forced
33
+ * color, and never under NO_COLOR. Terminals without the capability ignore
34
+ * the sequences anyway, but a dumb/CI capture would otherwise keep the bytes
35
+ * (FE-13).
36
+ */
37
+ function oscCapable(env) {
38
+ if (env.NO_COLOR != null && env.NO_COLOR !== '')
39
+ return false;
40
+ if (env.TERM === 'dumb')
41
+ return false;
42
+ if (env.FORCE_COLOR != null && env.FORCE_COLOR !== '' && env.FORCE_COLOR !== '0' && env.FORCE_COLOR !== 'false')
43
+ return true;
44
+ const colorterm = env.COLORTERM?.toLowerCase();
45
+ return colorterm === 'truecolor' || colorterm === '24bit';
46
+ }
47
+ /** Adopt a theme's foreground/background as the terminal defaults (OSC 10 + 11). Malformed parts are skipped; no-op off-TTY or without colour capability. */
48
+ export function applyTerminalColors(foreground, background, stream = process.stdout, env = process.env) {
49
+ if (!stream.isTTY || !oscCapable(env))
33
50
  return;
34
51
  const fg = oscRgb(foreground);
35
52
  const bg = oscRgb(background);
@@ -38,9 +55,9 @@ export function applyTerminalColors(foreground, background, stream = process.std
38
55
  if (bg)
39
56
  stream.write(`\u001B]11;rgb:${bg}\u0007`);
40
57
  }
41
- /** Restore the terminal's own default colors (OSC 110 + 111). No-op off-TTY. */
42
- export function resetTerminalColors(stream = process.stdout) {
43
- if (!stream.isTTY)
58
+ /** Restore the terminal's own default colors (OSC 110 + 111). No-op off-TTY or without colour capability. */
59
+ export function resetTerminalColors(stream = process.stdout, env = process.env) {
60
+ if (!stream.isTTY || !oscCapable(env))
44
61
  return;
45
62
  stream.write('\u001B]110\u0007');
46
63
  stream.write('\u001B]111\u0007');