@denizokcu/haze 1.4.0 → 1.5.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 (132) hide show
  1. package/CHANGELOG.md +33 -1
  2. package/README.md +13 -8
  3. package/SECURITY.md +1 -1
  4. package/dist/buildInfo.json +3 -3
  5. package/dist/cli/chat/BusyBar.d.ts +7 -0
  6. package/dist/cli/chat/BusyBar.js +8 -0
  7. package/dist/cli/chat/DynamicFrame.d.ts +37 -0
  8. package/dist/cli/chat/DynamicFrame.js +43 -0
  9. package/dist/cli/chat/busyIndicator.d.ts +3 -1
  10. package/dist/cli/chat/busyIndicator.js +11 -9
  11. package/dist/cli/chat/chatMetrics.d.ts +1 -1
  12. package/dist/cli/chat/chatMetrics.js +3 -3
  13. package/dist/cli/chat/inputSuggestions.js +2 -1
  14. package/dist/cli/chat/liveRegion.js +1 -1
  15. package/dist/cli/chat/messages.js +27 -16
  16. package/dist/cli/chat/sessionLifecycle.d.ts +3 -1
  17. package/dist/cli/chat/sessionLifecycle.js +13 -2
  18. package/dist/cli/chat/sessionRecorder.d.ts +2 -1
  19. package/dist/cli/chat/sessionRecorder.js +8 -0
  20. package/dist/cli/chat/shutdown.d.ts +27 -0
  21. package/dist/cli/chat/shutdown.js +79 -0
  22. package/dist/cli/chat/terminalControl.d.ts +45 -0
  23. package/dist/cli/chat/terminalControl.js +107 -0
  24. package/dist/cli/chat/tips.js +1 -0
  25. package/dist/cli/chat/userInput.d.ts +43 -0
  26. package/dist/cli/chat/userInput.js +63 -0
  27. package/dist/cli/chat/wizard/sessionThemeHandlers.js +14 -6
  28. package/dist/cli/chat/wizard/types.d.ts +8 -1
  29. package/dist/cli/chat/wizardDispatch.js +1 -1
  30. package/dist/cli/commands/chat.js +251 -172
  31. package/dist/cli/commands/commandHelp.js +6 -2
  32. package/dist/cli/commands/commands.d.ts +8 -0
  33. package/dist/cli/commands/commands.js +11 -0
  34. package/dist/cli/commands/formatters.d.ts +1 -1
  35. package/dist/cli/commands/formatters.js +20 -2
  36. package/dist/cli/commands/logsCommand.js +21 -2
  37. package/dist/cli/commands/reasoningCommand.d.ts +23 -14
  38. package/dist/cli/commands/reasoningCommand.js +53 -20
  39. package/dist/cli/commands/runCommand.js +19 -11
  40. package/dist/cli/commands/streaming/attemptOutcome.d.ts +2 -0
  41. package/dist/cli/commands/streaming/attemptOutcome.js +11 -6
  42. package/dist/cli/commands/streaming/attemptSetup.d.ts +1 -0
  43. package/dist/cli/commands/streaming/attemptSetup.js +11 -5
  44. package/dist/cli/commands/streaming/goalCheckpoint.d.ts +8 -1
  45. package/dist/cli/commands/streaming/goalCheckpoint.js +3 -2
  46. package/dist/cli/commands/streaming/goalSupervisor.d.ts +4 -0
  47. package/dist/cli/commands/streaming/goalSupervisor.js +43 -7
  48. package/dist/cli/commands/streaming/prepareStep.js +7 -3
  49. package/dist/cli/commands/streaming/streamLoop.d.ts +5 -0
  50. package/dist/cli/commands/streaming/streamLoop.js +3 -0
  51. package/dist/cli/commands/streaming/toolPartHandlers.js +6 -0
  52. package/dist/cli/commands/streaming.d.ts +1 -1
  53. package/dist/cli/commands/streaming.js +23 -17
  54. package/dist/cli/commands/wizardFlow.d.ts +5 -2
  55. package/dist/cli/commands/wizardFlow.js +17 -10
  56. package/dist/cli/index.js +17 -1
  57. package/dist/config/contextFiles.d.ts +9 -0
  58. package/dist/config/contextFiles.js +21 -1
  59. package/dist/config/modelCatalog.d.ts +3 -0
  60. package/dist/config/modelCatalog.js +29 -0
  61. package/dist/config/providerPresets.d.ts +1 -1
  62. package/dist/config/providerPresets.js +42 -3
  63. package/dist/config/settings.d.ts +7 -3
  64. package/dist/config/settings.js +8 -0
  65. package/dist/core/agent/budgets.d.ts +13 -15
  66. package/dist/core/agent/budgets.js +15 -17
  67. package/dist/core/agent/completionController.d.ts +6 -2
  68. package/dist/core/agent/completionController.js +16 -3
  69. package/dist/core/agent/goalPolicy.d.ts +10 -0
  70. package/dist/core/agent/goalPolicy.js +44 -6
  71. package/dist/core/agent/projectPreflight.d.ts +2 -0
  72. package/dist/core/agent/projectPreflight.js +56 -0
  73. package/dist/core/agent/reasoningPolicy.d.ts +34 -4
  74. package/dist/core/agent/reasoningPolicy.js +27 -4
  75. package/dist/core/agent/workState.d.ts +8 -0
  76. package/dist/core/agent/workState.js +191 -8
  77. package/dist/core/providerContracts.d.ts +29 -0
  78. package/dist/core/providerContracts.js +1 -0
  79. package/dist/core/session/sessionReport.d.ts +33 -0
  80. package/dist/core/session/sessionReport.js +121 -0
  81. package/dist/core/session/sessionSlimming.js +9 -3
  82. package/dist/core/session/sessionStore.d.ts +12 -0
  83. package/dist/core/session/sessionStore.js +20 -4
  84. package/dist/core/subagent/contracts.d.ts +3 -25
  85. package/dist/core/subagent/executionProfiles.js +4 -4
  86. package/dist/core/validation/outputParser.d.ts +6 -1
  87. package/dist/core/validation/outputParser.js +6 -2
  88. package/dist/llm/client.d.ts +4 -2
  89. package/dist/llm/client.js +17 -10
  90. package/dist/llm/hazeTools.d.ts +8553 -8550
  91. package/dist/llm/hazeTools.js +6 -503
  92. package/dist/llm/lspTools.d.ts +120 -120
  93. package/dist/llm/mcp.js +3 -0
  94. package/dist/llm/requestContext.d.ts +1 -1
  95. package/dist/llm/requestContext.js +1 -1
  96. package/dist/{core/subagent → llm}/subagentRunner.d.ts +9 -9
  97. package/dist/{core/subagent → llm}/subagentRunner.js +22 -25
  98. package/dist/llm/systemPrompt.d.ts +11 -1
  99. package/dist/llm/systemPrompt.js +2 -11
  100. package/dist/llm/tools/fetchTool.d.ts +30 -30
  101. package/dist/llm/tools/fileTools.d.ts +7768 -0
  102. package/dist/llm/tools/fileTools.js +510 -0
  103. package/dist/llm/tools/processTool.d.ts +30 -30
  104. package/dist/llm/tools/shellTool.d.ts +30 -30
  105. package/dist/llm/tools/shellTool.js +8 -4
  106. package/dist/llm/tools/toolContext.d.ts +3 -32
  107. package/dist/llm/tools/toolContext.js +33 -52
  108. package/dist/llm/tools/toolContextState.d.ts +40 -0
  109. package/dist/llm/tools/toolContextState.js +34 -0
  110. package/dist/llm/workerContext.d.ts +7 -0
  111. package/dist/llm/workerContext.js +18 -1
  112. package/dist/skills/SkillLoader.js +3 -3
  113. package/dist/skills/SkillRegistry.js +3 -3
  114. package/dist/skills/builder/SkillBuilder.js +3 -3
  115. package/dist/skills/confinement.d.ts +7 -0
  116. package/dist/skills/confinement.js +15 -0
  117. package/dist/ui/codeHighlight.js +4 -4
  118. package/dist/ui/components/MarkdownText.js +7 -8
  119. package/dist/ui/components/NativeIndicators.d.ts +15 -0
  120. package/dist/ui/components/NativeIndicators.js +32 -0
  121. package/dist/ui/components/StreamingMarkdownText.d.ts +9 -0
  122. package/dist/ui/components/StreamingMarkdownText.js +38 -0
  123. package/dist/ui/components/TextInput.d.ts +7 -2
  124. package/dist/ui/components/TextInput.js +103 -46
  125. package/dist/ui/components/WizardChoices.d.ts +18 -0
  126. package/dist/ui/components/WizardChoices.js +32 -0
  127. package/dist/ui/inputBuffer.js +12 -6
  128. package/dist/ui/textGeometry.d.ts +14 -0
  129. package/dist/ui/textGeometry.js +31 -0
  130. package/package.json +14 -13
  131. /package/dist/cli/{contextReport.d.ts → contextReportCli.d.ts} +0 -0
  132. /package/dist/cli/{contextReport.js → contextReportCli.js} +0 -0
@@ -0,0 +1,34 @@
1
+ function isRecord(value) {
2
+ return typeof value === 'object' && value !== null && !Array.isArray(value);
3
+ }
4
+ function isMutationPolicy(value) {
5
+ return isRecord(value) && typeof value.acquire === 'function' && typeof value.createOwner === 'function';
6
+ }
7
+ export function isHazeToolContext(value) {
8
+ if (!isRecord(value))
9
+ return false;
10
+ const validOptional = (key, predicate) => value[key] === undefined || predicate(value[key]);
11
+ return validOptional('inFlightToolCalls', field => field instanceof Map)
12
+ && validOptional('completedToolCalls', field => field instanceof Map)
13
+ && validOptional('mutationEpoch', field => typeof field === 'number' && Number.isSafeInteger(field) && field >= 0)
14
+ && validOptional('failedMutationPaths', field => field instanceof Set)
15
+ && validOptional('failedMutationReasons', field => field instanceof Map)
16
+ && validOptional('pathsReadAfterFailedMutation', field => field instanceof Set)
17
+ && validOptional('inFlightMutationPaths', field => field instanceof Set)
18
+ && validOptional('loadedContextFilePaths', field => field instanceof Set)
19
+ && validOptional('loadedContextFileSignatures', field => field instanceof Map)
20
+ && validOptional('pendingContextFiles', field => Array.isArray(field))
21
+ && validOptional('scopedContextDiscovery', field => field instanceof Promise)
22
+ && validOptional('onContextFileRead', field => typeof field === 'function')
23
+ && validOptional('mutationPolicy', isMutationPolicy)
24
+ && validOptional('mutationOwner', field => typeof field === 'symbol')
25
+ && validOptional('isSubagent', field => typeof field === 'boolean')
26
+ && validOptional('blessedPaths', field => Array.isArray(field) && field.every(item => isRecord(item) && typeof item.realPath === 'string' && typeof item.isDirectory === 'boolean'))
27
+ && validOptional('postMutationDiagnostics', field => typeof field === 'function');
28
+ }
29
+ export function hazeContext(context) {
30
+ const value = typeof context.context === 'object' && context.context != null
31
+ ? context.context
32
+ : context.experimental_context;
33
+ return isHazeToolContext(value) ? value : undefined;
34
+ }
@@ -16,3 +16,10 @@ export interface WorkerContextBundle {
16
16
  }
17
17
  export declare function workerTaskMessage(task: SubagentTaskCapsule): string;
18
18
  export declare function assembleWorkerContext(task: SubagentTaskCapsule, profile: SubagentExecutionProfile, session?: PromptSession): Promise<WorkerContextBundle>;
19
+ /**
20
+ * Legacy compatibility bundle for callers (e.g. `/fleet`) that pass explicit
21
+ * context files and an optional tool allowlist instead of letting the worker
22
+ * resolve its own context. Moved from `llm/subagentRunner.ts` so the
23
+ * runner stays free of `llm` imports.
24
+ */
25
+ export declare function compatibilityBundle(task: SubagentTaskCapsule, profile: SubagentExecutionProfile, contextFiles: ContextFile[], allowedTools: readonly string[] | undefined, session: PromptSession | undefined): Promise<WorkerContextBundle>;
@@ -1,8 +1,8 @@
1
1
  import { readContextFiles, readScopedContextFilesForPath } from '../config/contextFiles.js';
2
2
  import { estimateTextTokens, estimateToolSchemas, estimateValueTokens } from '../core/agent/contextBudget.js';
3
3
  import { MODE_TOOL_NAMES } from '../core/subagent/executionProfiles.js';
4
- import { hazeTools } from './hazeTools.js';
5
4
  import { buildSubagentPrompt } from './systemPrompt.js';
5
+ import { hazeTools } from './hazeTools.js';
6
6
  import { resolveWorkspacePath, workspaceRelativePath } from '../utils/path.js';
7
7
  export function workerTaskMessage(task) {
8
8
  return JSON.stringify({
@@ -53,3 +53,20 @@ export async function assembleWorkerContext(task, profile, session) {
53
53
  return { instructions: [], loadedPaths: new Set(), loadedSignatures: new Map(), systemPrompt: '', tools: {}, estimatedTokens: 0, taskTokens: estimateValueTokens(workerTaskMessage(task)), validatedScope: [], policyBlock: reason };
54
54
  }
55
55
  }
56
+ /**
57
+ * Legacy compatibility bundle for callers (e.g. `/fleet`) that pass explicit
58
+ * context files and an optional tool allowlist instead of letting the worker
59
+ * resolve its own context. Moved from `llm/subagentRunner.ts` so the
60
+ * runner stays free of `llm` imports.
61
+ */
62
+ export async function compatibilityBundle(task, profile, contextFiles, allowedTools, session) {
63
+ const instructions = contextFiles;
64
+ const systemPrompt = buildSubagentPrompt(instructions, session, task.mode, profile);
65
+ const tools = {};
66
+ for (const name of allowedTools ?? MODE_TOOL_NAMES[task.mode])
67
+ if (name in hazeTools)
68
+ tools[name] = hazeTools[name];
69
+ const taskTokens = estimateValueTokens(workerTaskMessage(task));
70
+ const estimatedTokens = estimateTextTokens(systemPrompt) + taskTokens + estimateToolSchemas(tools).reduce((sum, value) => sum + value.tokens, 0);
71
+ return { instructions, systemPrompt, tools, taskTokens, estimatedTokens, validatedScope: [], loadedPaths: new Set(instructions.map(file => file.path)), loadedSignatures: new Map(instructions.flatMap(file => file.signature ? [[file.path, file.signature]] : [])), ...(estimatedTokens > profile.maxInputTokens ? { policyBlock: `Worker input estimate ${estimatedTokens} exceeds profile ${profile.name} limit ${profile.maxInputTokens}.` } : {}) };
72
+ }
@@ -1,7 +1,7 @@
1
1
  import fs from 'fs-extra';
2
2
  import path from 'node:path';
3
3
  import YAML from 'yaml';
4
- import { assertRealPathInsideRoot } from '../utils/path.js';
4
+ import { confinedResolve } from './confinement.js';
5
5
  import { SKILL_MARKDOWN_BYTES } from '../core/limits.js';
6
6
  import { readUtf8Prefix } from '../core/io/boundedRead.js';
7
7
  import { isProtectedSecretPath } from '../core/safety/secretPaths.js';
@@ -61,7 +61,7 @@ async function loadReference(dir, referencePath) {
61
61
  // refused before any filesystem access. Errors carry path metadata only.
62
62
  if (isProtectedSecretPath(absolutePath))
63
63
  throw new Error(`Skill reference is a protected secret file: ${referencePath}`);
64
- const realPath = await assertRealPathInsideRoot(dir, absolutePath, referencePath, 'skill directory');
64
+ const realPath = await confinedResolve(dir, absolutePath, referencePath, 'skill directory');
65
65
  if (isProtectedSecretPath(realPath))
66
66
  throw new Error(`Skill reference is a protected secret file: ${referencePath}`);
67
67
  const stat = await fs.stat(realPath);
@@ -76,7 +76,7 @@ export async function loadSkill(dir, source = 'global') {
76
76
  const skillPath = path.join(dir, 'SKILL.md');
77
77
  if (!(await fs.pathExists(skillPath)))
78
78
  return null;
79
- const realSkillPath = await assertRealPathInsideRoot(dir, skillPath, 'SKILL.md', 'skill directory');
79
+ const realSkillPath = await confinedResolve(dir, skillPath, 'SKILL.md', 'skill directory');
80
80
  if (isProtectedSecretPath(realSkillPath))
81
81
  throw new Error('SKILL.md is a protected secret file');
82
82
  const stat = await fs.stat(realSkillPath);
@@ -2,13 +2,13 @@ import fs from 'fs-extra';
2
2
  import path from 'node:path';
3
3
  import { GLOBAL_SKILLS_DIR } from '../config/paths.js';
4
4
  import { loadSkill } from './SkillLoader.js';
5
- import { assertRealPathInsideRoot } from '../utils/path.js';
5
+ import { confinedResolve } from './confinement.js';
6
6
  async function loadRoot(root, containmentRoot, source, errors) {
7
7
  if (!(await fs.pathExists(root)))
8
8
  return [];
9
9
  if (source === 'project') {
10
10
  try {
11
- await assertRealPathInsideRoot(containmentRoot, root, '.haze/skills', 'workspace');
11
+ await confinedResolve(containmentRoot, root, '.haze/skills', 'workspace');
12
12
  }
13
13
  catch (error) {
14
14
  errors.push({ directory: '.haze/skills', source, message: error instanceof Error ? error.message : String(error) });
@@ -22,7 +22,7 @@ async function loadRoot(root, containmentRoot, source, errors) {
22
22
  try {
23
23
  // Project-controlled symlinks must remain inside the workspace, not merely
24
24
  // inside a possibly symlinked .haze/skills directory.
25
- await assertRealPathInsideRoot(containmentRoot, dir, name, source === 'project' ? 'workspace' : 'skills root');
25
+ await confinedResolve(containmentRoot, dir, name, source === 'project' ? 'workspace' : 'skills root');
26
26
  if (!(await fs.stat(dir)).isDirectory())
27
27
  continue;
28
28
  const skill = await loadSkill(dir, source);
@@ -5,7 +5,7 @@ import YAML from 'yaml';
5
5
  import { GLOBAL_SKILLS_DIR } from '../../config/paths.js';
6
6
  import { modelWithConfig } from '../../llm/client.js';
7
7
  import { loadSkill } from '../SkillLoader.js';
8
- import { assertRealPathInsideRoot } from '../../utils/path.js';
8
+ import { confinedResolve } from '../confinement.js';
9
9
  import { z } from 'zod';
10
10
  const STANDARD_SKILL_REQUIREMENTS = `
11
11
 
@@ -240,10 +240,10 @@ async function skillTargetRoot(input) {
240
240
  const cwd = path.resolve(input.cwd ?? process.cwd());
241
241
  const hazeDir = path.join(cwd, '.haze');
242
242
  if (await fs.pathExists(hazeDir))
243
- await assertRealPathInsideRoot(cwd, hazeDir, '.haze', 'workspace');
243
+ await confinedResolve(cwd, hazeDir, '.haze', 'workspace');
244
244
  const root = path.join(hazeDir, 'skills');
245
245
  await fs.ensureDir(root);
246
- await assertRealPathInsideRoot(cwd, root, '.haze/skills', 'workspace');
246
+ await confinedResolve(cwd, root, '.haze/skills', 'workspace');
247
247
  return { root, source: 'project' };
248
248
  }
249
249
  export async function createSkill(input) {
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Shared real-path confinement wrapper for skills: resolves `candidate`
3
+ * inside `root` or throws a ready-to-report error message. Collapses the
4
+ * hand-rolled try/catch formatting previously duplicated across the registry,
5
+ * loader, and builder.
6
+ */
7
+ export declare function confinedResolve(root: string, candidate: string, label: string, rootLabel: string): Promise<string>;
@@ -0,0 +1,15 @@
1
+ import { assertRealPathInsideRoot } from '../utils/path.js';
2
+ /**
3
+ * Shared real-path confinement wrapper for skills: resolves `candidate`
4
+ * inside `root` or throws a ready-to-report error message. Collapses the
5
+ * hand-rolled try/catch formatting previously duplicated across the registry,
6
+ * loader, and builder.
7
+ */
8
+ export async function confinedResolve(root, candidate, label, rootLabel) {
9
+ try {
10
+ return await assertRealPathInsideRoot(root, candidate, label, rootLabel);
11
+ }
12
+ catch (error) {
13
+ throw new Error(error instanceof Error ? error.message : String(error), { cause: error });
14
+ }
15
+ }
@@ -1,5 +1,5 @@
1
1
  import { highlight, supportsLanguage } from 'cli-highlight';
2
- import stripAnsi from 'strip-ansi';
2
+ import { cellWidth, clipCells } from './textGeometry.js';
3
3
  /** Map a source path to a cli-highlight language when its extension is known. */
4
4
  export function languageForPath(filePath) {
5
5
  const extension = /\.([^./]+)$/.exec(filePath)?.[1]?.toLowerCase();
@@ -16,8 +16,8 @@ export function languageForPath(filePath) {
16
16
  export function highlightedCodeLine(code, width, language) {
17
17
  const safeWidth = Math.max(1, width);
18
18
  const singleLine = code.replace(/\t/g, ' ');
19
- const fitted = singleLine.length > safeWidth
20
- ? `${singleLine.slice(0, Math.max(0, safeWidth - 1))}…`
19
+ const fitted = cellWidth(singleLine) > safeWidth
20
+ ? `${clipCells(singleLine, safeWidth - 1)}…`
21
21
  : singleLine;
22
22
  let rendered = fitted;
23
23
  try {
@@ -26,6 +26,6 @@ export function highlightedCodeLine(code, width, language) {
26
26
  catch {
27
27
  // Unknown or malformed source still renders as plain text.
28
28
  }
29
- const padding = Math.max(0, safeWidth - stripAnsi(rendered).length);
29
+ const padding = Math.max(0, safeWidth - cellWidth(rendered));
30
30
  return `${rendered}${' '.repeat(padding)}`;
31
31
  }
@@ -2,13 +2,14 @@ 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
4
  import { marked } from 'marked';
5
- import stripAnsi from 'strip-ansi';
5
+ import { cellWidth } from '../textGeometry.js';
6
+ import { wrapDisplayValue } from '../inputBuffer.js';
6
7
  import { theme } from '../theme.js';
7
8
  import { highlightedCodeLine } from '../codeHighlight.js';
8
9
  const MARKED_OPTIONS = { gfm: true, breaks: true };
9
10
  export const MarkdownText = React.memo(function MarkdownText({ content, width }) {
10
11
  const tokens = marked.lexer(content, MARKED_OPTIONS);
11
- const contentWidth = Math.max(20, width - 2);
12
+ const contentWidth = Math.max(1, width - 2);
12
13
  return _jsx(Box, { flexDirection: "column", children: tokens.map((token, index) => {
13
14
  const codeLead = token.type === 'paragraph' || token.type === 'text' ? codeLeadForFollowingFence(tokens, index) : undefined;
14
15
  if (token.type === 'space' && bridgesCodeLeadToFence(tokens, index))
@@ -150,7 +151,7 @@ function ListItemBlock({ token, marker, markerWidth, width }) {
150
151
  // Block-level content (code, nested list, blockquote, table). The marker
151
152
  // sits on its own line when this is the first block; the block then renders
152
153
  // indented to align with the marker.
153
- return _jsxs(Box, { flexDirection: "column", children: [marker ? _jsx(Text, { color: theme.accent, children: marker }) : null, _jsx(Box, { flexDirection: "column", marginLeft: markerWidth, children: _jsx(MarkdownBlock, { token: token, width: Math.max(20, width - markerWidth) }) })] });
154
+ return _jsxs(Box, { flexDirection: "column", children: [marker ? _jsx(Text, { color: theme.accent, children: marker }) : null, _jsx(Box, { flexDirection: "column", marginLeft: markerWidth, children: _jsx(MarkdownBlock, { token: token, width: Math.max(1, width - markerWidth) }) })] });
154
155
  }
155
156
  function HeadingBlock({ heading, width }) {
156
157
  const title = stripInline(heading.text).trim();
@@ -376,8 +377,7 @@ function wrapTableCell(text, width) {
376
377
  if (!word)
377
378
  continue;
378
379
  if (!current && visibleLength(word) > width) {
379
- for (let index = 0; index < word.length; index += width)
380
- lines.push(word.slice(index, index + width));
380
+ lines.push(...wrapDisplayValue(word, width).map(line => line.text));
381
381
  continue;
382
382
  }
383
383
  const next = current ? `${current} ${word}` : word;
@@ -386,8 +386,7 @@ function wrapTableCell(text, width) {
386
386
  else {
387
387
  flush();
388
388
  if (visibleLength(word) > width) {
389
- for (let index = 0; index < word.length; index += width)
390
- lines.push(word.slice(index, index + width));
389
+ lines.push(...wrapDisplayValue(word, width).map(line => line.text));
391
390
  }
392
391
  else {
393
392
  current = word;
@@ -423,7 +422,7 @@ function stripInline(text) {
423
422
  .replace(/\[([^\]]+)\]\([^)]+\)/g, '$1');
424
423
  }
425
424
  function visibleLength(value) {
426
- return stripAnsi(value).length;
425
+ return cellWidth(value);
427
426
  }
428
427
  function padAnsi(value, width) {
429
428
  const visible = visibleLength(value);
@@ -0,0 +1,15 @@
1
+ import React from 'react';
2
+ import { type HazeTheme } from '../theme.js';
3
+ export type NoticeVariant = 'success' | 'error' | 'warning' | 'info';
4
+ /** Map library indicators to the current palette, never its default colors. */
5
+ export declare function indicatorTheme(palette: HazeTheme): {
6
+ components: Record<string, import("@inkjs/ui").ComponentTheme>;
7
+ };
8
+ /** A layout element: render beside Text, not nested inside it. */
9
+ export declare function ActivitySpinner({ color }: {
10
+ color?: string;
11
+ }): React.JSX.Element;
12
+ export declare function StatusNotice({ variant, children }: {
13
+ variant: NoticeVariant;
14
+ children: React.ReactNode;
15
+ }): React.JSX.Element;
@@ -0,0 +1,32 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { Box, Text, useAnimation, useIsScreenReaderEnabled } from 'ink';
3
+ import { StatusMessage, ThemeProvider, defaultTheme, extendTheme } from '@inkjs/ui';
4
+ import { theme } from '../theme.js';
5
+ // Matches cli-spinners' `dots` (the @inkjs/ui Spinner type haze used), so the
6
+ // visual cadence is unchanged after moving to Ink's shared animation timer.
7
+ const SPINNER_FRAMES = ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏'];
8
+ const SPINNER_INTERVAL_MS = 80;
9
+ /** Map library indicators to the current palette, never its default colors. */
10
+ export function indicatorTheme(palette) {
11
+ const colors = { success: palette.success, error: palette.danger, warning: palette.warning, info: palette.info };
12
+ return extendTheme(defaultTheme, { components: {
13
+ StatusMessage: { styles: {
14
+ container: () => ({ gap: 1, flexShrink: 0, width: '100%', overflow: 'hidden' }),
15
+ icon: ({ variant }) => ({ color: colors[variant] }),
16
+ message: () => ({ color: palette.foreground, wrap: 'truncate-end' }),
17
+ } },
18
+ } });
19
+ }
20
+ /** A layout element: render beside Text, not nested inside it. */
21
+ export function ActivitySpinner({ color = theme.command }) {
22
+ const screenReader = useIsScreenReaderEnabled();
23
+ // Ink 8's shared animation timer: every animated component consolidates
24
+ // into one render cycle (throttled by maxFps) instead of per-spinner timers.
25
+ const { frame } = useAnimation({ interval: SPINNER_INTERVAL_MS });
26
+ const glyph = SPINNER_FRAMES[frame % SPINNER_FRAMES.length];
27
+ // Screen readers announce frame churn as noise; hold a static marker.
28
+ return _jsx(Box, { flexShrink: 0, children: _jsx(Text, { color: color, children: screenReader ? '·' : glyph }) });
29
+ }
30
+ export function StatusNotice({ variant, children }) {
31
+ return _jsx(ThemeProvider, { theme: indicatorTheme(theme), children: _jsx(StatusMessage, { variant: variant, children: children }) });
32
+ }
@@ -0,0 +1,9 @@
1
+ import React from 'react';
2
+ /** Parse the whole active block before splitting its formatted terminal output into rows. */
3
+ export declare function renderMarkdownRows(content: string, width: number): string[];
4
+ /** The active block remains replaceable; only settled roots belong in Static. */
5
+ export declare const StreamingMarkdownText: React.MemoExoticComponent<({ content, width, maxVisibleLines }: {
6
+ content: string;
7
+ width: number;
8
+ maxVisibleLines?: number;
9
+ }) => React.JSX.Element | null>;
@@ -0,0 +1,38 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import React, { useEffect, useState } from 'react';
3
+ import { Box, Text, renderToString } from 'ink';
4
+ import { MarkdownText } from './MarkdownText.js';
5
+ import { theme } from '../theme.js';
6
+ /** Parse the whole active block before splitting its formatted terminal output into rows. */
7
+ export function renderMarkdownRows(content, width) {
8
+ if (!content)
9
+ return [];
10
+ const output = renderToString(_jsx(MarkdownText, { content: content, width: width }), { columns: Math.max(1, width) });
11
+ // Block margins belong to the settled transcript, not the bottom of a live
12
+ // preview. Keep internal blank rows, but do not let a trailing margin hide
13
+ // the newest content in a small viewport.
14
+ return output.replace(/\n[\s]*$/, '').split('\n');
15
+ }
16
+ /** The active block remains replaceable; only settled roots belong in Static. */
17
+ export const StreamingMarkdownText = React.memo(function StreamingMarkdownText({ content, width, maxVisibleLines }) {
18
+ const [rendered, setRendered] = useState({ content: '', width, rows: [] });
19
+ // Ink's synchronous offscreen renderer must run outside React's render and
20
+ // commit phases. The microtask also lets superseded deltas cancel their work.
21
+ useEffect(() => {
22
+ let cancelled = false;
23
+ queueMicrotask(() => {
24
+ if (!cancelled)
25
+ setRendered({ content, width, rows: renderMarkdownRows(content, width) });
26
+ });
27
+ return () => { cancelled = true; };
28
+ }, [content, width]);
29
+ // Never replay a previous root after it enters Static, or show stale, wider
30
+ // rows during a terminal resize. Append-only deltas can retain their preview.
31
+ const rows = rendered.width === width && content.startsWith(rendered.content) ? rendered.rows : [];
32
+ const budget = maxVisibleLines == null ? rows.length : Math.max(0, Math.floor(maxVisibleLines));
33
+ if (budget === 0)
34
+ return null;
35
+ const hidden = rows.length > budget ? rows.length - Math.max(0, budget - 1) : 0;
36
+ const visible = hidden ? rows.slice(hidden) : rows;
37
+ return _jsxs(Box, { flexDirection: "column", flexShrink: 0, children: [hidden > 0 ? _jsx(Text, { color: theme.muted, wrap: "truncate-end", children: `⋯ +${hidden} line${hidden === 1 ? '' : 's'} above` }) : null, visible.map((row, index) => _jsx(Text, { wrap: "truncate-end", children: row || ' ' }, hidden + index))] });
38
+ });
@@ -6,7 +6,6 @@ type TextInputKey = {
6
6
  meta?: boolean;
7
7
  };
8
8
  export declare function shouldInsertNewline(input: string, key: TextInputKey): boolean;
9
- export declare function isKittyQueryResponseInput(input: string): boolean;
10
9
  /**
11
10
  * Ctrl+C terminate check. Legacy terminals deliver the raw \x03 byte (Ink
12
11
  * parses it to `c` + ctrl); with the kitty keyboard protocol enabled the
@@ -22,7 +21,7 @@ export type TextInputSuggestion = {
22
21
  };
23
22
  /** Cursor-aware path completer for `@token` mentions; receives the token verbatim. */
24
23
  export type MentionSuggestionsProvider = (token: string) => Promise<TextInputSuggestion[]> | TextInputSuggestion[];
25
- export declare function TextInput({ placeholder, disabled, mask, historyItems, recordHistory, suggestions, suggestionMode, submitOnEmpty, width, getMentionSuggestions, onHistoryAdd, onCancel, onEscape, onToggleTasks, onResumeKey, onInterrupt, onSubmit }: {
24
+ export declare function TextInput({ placeholder, disabled, mask, historyItems, recordHistory, suggestions, suggestionMode, submitOnEmpty, width, inputRows, suggestionRows, onRowsChange, getMentionSuggestions, onHistoryAdd, onCancel, onEscape, onToggleTasks, onResumeKey, onInterrupt, onSubmit }: {
26
25
  placeholder?: string;
27
26
  disabled?: boolean;
28
27
  mask?: boolean;
@@ -32,6 +31,12 @@ export declare function TextInput({ placeholder, disabled, mask, historyItems, r
32
31
  suggestionMode?: 'slash' | 'always';
33
32
  submitOnEmpty?: boolean;
34
33
  width?: number;
34
+ inputRows?: number;
35
+ suggestionRows?: number;
36
+ onRowsChange?: (demand: {
37
+ input: number;
38
+ suggestions: number;
39
+ }) => void;
35
40
  getMentionSuggestions?: MentionSuggestionsProvider;
36
41
  onHistoryAdd?: (value: string) => void;
37
42
  onCancel?: () => void;