@denizokcu/haze 0.5.0 → 0.7.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 (162) hide show
  1. package/CHANGELOG.md +36 -1
  2. package/README.md +101 -24
  3. package/dist/cli/chat/TaskBar.d.ts +9 -0
  4. package/dist/cli/chat/TaskBar.js +40 -0
  5. package/dist/cli/chat/chatMetrics.d.ts +11 -0
  6. package/dist/cli/chat/chatMetrics.js +50 -0
  7. package/dist/cli/chat/inputSuggestions.d.ts +16 -0
  8. package/dist/cli/chat/inputSuggestions.js +55 -0
  9. package/dist/cli/chat/messages.d.ts +9 -0
  10. package/dist/cli/chat/messages.js +76 -0
  11. package/dist/cli/chat/sessionRecorder.d.ts +12 -0
  12. package/dist/cli/chat/sessionRecorder.js +21 -0
  13. package/dist/cli/chat/startupInfo.d.ts +4 -0
  14. package/dist/cli/chat/startupInfo.js +53 -0
  15. package/dist/cli/chat/turnState.d.ts +5 -0
  16. package/dist/cli/chat/turnState.js +20 -0
  17. package/dist/cli/commands/chat.d.ts +0 -1
  18. package/dist/cli/commands/chat.js +519 -495
  19. package/dist/cli/commands/chatModes.d.ts +8 -0
  20. package/dist/cli/commands/chatModes.js +44 -0
  21. package/dist/cli/commands/commandHelp.d.ts +6 -0
  22. package/dist/cli/commands/commandHelp.js +25 -0
  23. package/dist/cli/commands/commands.d.ts +3 -2
  24. package/dist/cli/commands/commands.js +55 -320
  25. package/dist/cli/commands/formatters.d.ts +27 -0
  26. package/dist/cli/commands/formatters.js +149 -4
  27. package/dist/cli/commands/initCommand.d.ts +2 -0
  28. package/dist/cli/commands/initCommand.js +19 -0
  29. package/dist/cli/commands/logsCommand.d.ts +2 -0
  30. package/dist/cli/commands/logsCommand.js +63 -0
  31. package/dist/cli/commands/lspWizard.d.ts +14 -0
  32. package/dist/cli/commands/lspWizard.js +44 -0
  33. package/dist/cli/commands/mcpWizard.d.ts +15 -0
  34. package/dist/cli/commands/mcpWizard.js +69 -0
  35. package/dist/cli/commands/modelCommand.d.ts +2 -0
  36. package/dist/cli/commands/modelCommand.js +36 -0
  37. package/dist/cli/commands/providerWizard.d.ts +30 -0
  38. package/dist/cli/commands/providerWizard.js +114 -0
  39. package/dist/cli/commands/runCommand.d.ts +16 -0
  40. package/dist/cli/commands/runCommand.js +170 -0
  41. package/dist/cli/commands/settingsSummary.d.ts +3 -0
  42. package/dist/cli/commands/settingsSummary.js +40 -0
  43. package/dist/cli/commands/skillConfirmRemove.d.ts +11 -0
  44. package/dist/cli/commands/skillConfirmRemove.js +19 -0
  45. package/dist/cli/commands/skillCreation.d.ts +12 -0
  46. package/dist/cli/commands/skillCreation.js +14 -0
  47. package/dist/cli/commands/skillWizard.d.ts +15 -0
  48. package/dist/cli/commands/skillWizard.js +38 -0
  49. package/dist/cli/commands/streaming/assistantText.d.ts +17 -0
  50. package/dist/cli/commands/streaming/assistantText.js +115 -0
  51. package/dist/cli/commands/streaming/toolGroupRenderer.d.ts +55 -0
  52. package/dist/cli/commands/streaming/toolGroupRenderer.js +102 -0
  53. package/dist/cli/commands/streaming/toolResultState.d.ts +13 -0
  54. package/dist/cli/commands/streaming/toolResultState.js +25 -0
  55. package/dist/cli/commands/streaming/turnRuntime.d.ts +78 -0
  56. package/dist/cli/commands/streaming/turnRuntime.js +86 -0
  57. package/dist/cli/commands/streaming.d.ts +10 -29
  58. package/dist/cli/commands/streaming.js +249 -911
  59. package/dist/cli/commands/wizardActions.d.ts +40 -0
  60. package/dist/cli/commands/wizardActions.js +40 -0
  61. package/dist/cli/commands/wizardInput.d.ts +4 -0
  62. package/dist/cli/commands/wizardInput.js +19 -0
  63. package/dist/cli/commands/wizardPrompts.d.ts +22 -0
  64. package/dist/cli/commands/wizardPrompts.js +52 -0
  65. package/dist/cli/commands/wizardSuggestions.d.ts +23 -0
  66. package/dist/cli/commands/wizardSuggestions.js +139 -0
  67. package/dist/cli/index.js +62 -4
  68. package/dist/config/contextFiles.d.ts +8 -1
  69. package/dist/config/contextFiles.js +25 -12
  70. package/dist/config/lspSettings.d.ts +16 -0
  71. package/dist/config/lspSettings.js +95 -0
  72. package/dist/config/mcpSettings.d.ts +24 -0
  73. package/dist/config/mcpSettings.js +100 -0
  74. package/dist/config/providers.js +4 -4
  75. package/dist/config/settings.d.ts +34 -0
  76. package/dist/config/skillSettings.d.ts +15 -0
  77. package/dist/config/skillSettings.js +32 -0
  78. package/dist/config/updateCheck.d.ts +44 -0
  79. package/dist/config/updateCheck.js +83 -0
  80. package/dist/core/agent/budgets.d.ts +6 -0
  81. package/dist/core/agent/budgets.js +6 -0
  82. package/dist/core/agent/compaction.js +1 -1
  83. package/dist/core/agent/requestAssembly.d.ts +0 -7
  84. package/dist/core/agent/requestAssembly.js +27 -5
  85. package/dist/core/agent/toolOutputStore.js +5 -4
  86. package/dist/core/agent/toolResults.d.ts +31 -0
  87. package/dist/core/agent/toolResults.js +42 -0
  88. package/dist/core/agent/turnPolicy.d.ts +8 -0
  89. package/dist/core/agent/turnPolicy.js +23 -0
  90. package/dist/core/agent/workState.d.ts +18 -5
  91. package/dist/core/agent/workState.js +39 -20
  92. package/dist/core/bashOutput/reducers/content.d.ts +1 -0
  93. package/dist/core/bashOutput/reducers/content.js +1 -1
  94. package/dist/core/bashOutput/reducers/gh.d.ts +1 -0
  95. package/dist/core/bashOutput/reducers/gh.js +77 -0
  96. package/dist/core/bashOutput/registry.js +8 -0
  97. package/dist/core/goal/sessionGoal.d.ts +6 -30
  98. package/dist/core/goal/sessionGoal.js +3 -68
  99. package/dist/core/safety/bashClassifier.js +30 -0
  100. package/dist/core/safety/urlGuard.d.ts +1 -0
  101. package/dist/core/safety/urlGuard.js +6 -1
  102. package/dist/core/session/sessionSlimming.d.ts +5 -0
  103. package/dist/core/session/sessionSlimming.js +78 -0
  104. package/dist/core/session/sessionStore.d.ts +23 -3
  105. package/dist/core/session/sessionStore.js +30 -10
  106. package/dist/core/subagent/subagentRunner.d.ts +11 -1
  107. package/dist/core/subagent/subagentRunner.js +1 -0
  108. package/dist/llm/capabilities.d.ts +12 -0
  109. package/dist/llm/capabilities.js +10 -0
  110. package/dist/llm/client.d.ts +1 -0
  111. package/dist/llm/client.js +11 -2
  112. package/dist/llm/hazeTools.d.ts +31 -32
  113. package/dist/llm/hazeTools.js +40 -567
  114. package/dist/llm/lsp.d.ts +109 -0
  115. package/dist/llm/lsp.js +241 -0
  116. package/dist/llm/lspTools.d.ts +104 -0
  117. package/dist/llm/lspTools.js +115 -0
  118. package/dist/llm/mcp.d.ts +19 -0
  119. package/dist/llm/mcp.js +73 -0
  120. package/dist/llm/requestContext.d.ts +28 -0
  121. package/dist/llm/requestContext.js +41 -0
  122. package/dist/llm/systemPrompt.d.ts +5 -1
  123. package/dist/llm/systemPrompt.js +9 -3
  124. package/dist/llm/tools/bashTool.d.ts +5 -0
  125. package/dist/llm/tools/bashTool.js +81 -0
  126. package/dist/llm/tools/editMatch.d.ts +55 -0
  127. package/dist/llm/tools/editMatch.js +99 -0
  128. package/dist/llm/tools/failures.d.ts +36 -0
  129. package/dist/llm/tools/failures.js +38 -0
  130. package/dist/llm/tools/fetchTool.d.ts +65 -0
  131. package/dist/llm/tools/fetchTool.js +45 -0
  132. package/dist/llm/tools/fileToolShared.d.ts +10 -0
  133. package/dist/llm/tools/fileToolShared.js +43 -0
  134. package/dist/llm/tools/grepParse.d.ts +13 -0
  135. package/dist/llm/tools/grepParse.js +67 -0
  136. package/dist/llm/tools/outputCap.d.ts +53 -0
  137. package/dist/llm/tools/outputCap.js +67 -0
  138. package/dist/llm/tools/storedOutputTool.d.ts +10 -0
  139. package/dist/llm/tools/storedOutputTool.js +17 -0
  140. package/dist/llm/tools/taskTool.d.ts +28 -0
  141. package/dist/llm/tools/taskTool.js +41 -0
  142. package/dist/llm/tools/toolContext.d.ts +69 -0
  143. package/dist/llm/tools/toolContext.js +187 -0
  144. package/dist/llm/tools/workspaceFile.d.ts +33 -0
  145. package/dist/llm/tools/workspaceFile.js +27 -0
  146. package/dist/llm/webFetch.d.ts +13 -1
  147. package/dist/llm/webFetch.js +91 -7
  148. package/dist/skills/builder/SkillBuilder.d.ts +3 -0
  149. package/dist/skills/builder/SkillBuilder.js +24 -45
  150. package/dist/ui/components/TextInput.d.ts +1 -1
  151. package/dist/ui/components/TextInput.js +1 -99
  152. package/dist/ui/inputBuffer.d.ts +28 -0
  153. package/dist/ui/inputBuffer.js +99 -0
  154. package/dist/utils/collections.d.ts +6 -0
  155. package/dist/utils/collections.js +9 -0
  156. package/dist/utils/path.d.ts +2 -0
  157. package/dist/utils/path.js +40 -0
  158. package/dist/utils/version.d.ts +20 -0
  159. package/dist/utils/version.js +72 -0
  160. package/package.json +2 -2
  161. package/dist/cli/commands/skills.d.ts +0 -4
  162. package/dist/cli/commands/skills.js +0 -38
@@ -0,0 +1,40 @@
1
+ export declare const PROVIDER_CHOICES: {
2
+ readonly addProvider: "add provider";
3
+ readonly custom: "custom";
4
+ };
5
+ export declare const PROVIDER_ACTIONS: {
6
+ readonly useProvider: "use provider";
7
+ readonly addModels: "add models";
8
+ readonly setApiKey: "set API key";
9
+ readonly removeModels: "remove models";
10
+ readonly removeProvider: "remove provider";
11
+ };
12
+ export declare const SERVER_CHOICES: {
13
+ readonly addServer: "add server";
14
+ readonly custom: "custom";
15
+ };
16
+ export declare const COMMON_ACTIONS: {
17
+ readonly enable: "enable";
18
+ readonly disable: "disable";
19
+ };
20
+ export declare const LSP_ACTIONS: {
21
+ readonly removeServer: "remove server";
22
+ };
23
+ export declare const MCP_ACTIONS: {
24
+ readonly setApiKey: "set API key";
25
+ readonly removeServer: "remove server";
26
+ };
27
+ export declare const MCP_TRANSPORTS: {
28
+ readonly http: "http";
29
+ readonly sse: "sse";
30
+ readonly stdio: "stdio";
31
+ };
32
+ export declare const SKILL_CHOICES: {
33
+ readonly addSkill: "add skill";
34
+ };
35
+ export declare const SKILL_ACTIONS: {
36
+ readonly showInfo: "show info";
37
+ readonly validate: "validate";
38
+ readonly removeSkill: "remove skill";
39
+ };
40
+ export declare const YES_CONFIRMATION = "yes";
@@ -0,0 +1,40 @@
1
+ export const PROVIDER_CHOICES = {
2
+ addProvider: 'add provider',
3
+ custom: 'custom',
4
+ };
5
+ export const PROVIDER_ACTIONS = {
6
+ useProvider: 'use provider',
7
+ addModels: 'add models',
8
+ setApiKey: 'set API key',
9
+ removeModels: 'remove models',
10
+ removeProvider: 'remove provider',
11
+ };
12
+ export const SERVER_CHOICES = {
13
+ addServer: 'add server',
14
+ custom: 'custom',
15
+ };
16
+ export const COMMON_ACTIONS = {
17
+ enable: 'enable',
18
+ disable: 'disable',
19
+ };
20
+ export const LSP_ACTIONS = {
21
+ removeServer: 'remove server',
22
+ };
23
+ export const MCP_ACTIONS = {
24
+ setApiKey: 'set API key',
25
+ removeServer: 'remove server',
26
+ };
27
+ export const MCP_TRANSPORTS = {
28
+ http: 'http',
29
+ sse: 'sse',
30
+ stdio: 'stdio',
31
+ };
32
+ export const SKILL_CHOICES = {
33
+ addSkill: 'add skill',
34
+ };
35
+ export const SKILL_ACTIONS = {
36
+ showInfo: 'show info',
37
+ validate: 'validate',
38
+ removeSkill: 'remove skill',
39
+ };
40
+ export const YES_CONFIRMATION = 'yes';
@@ -0,0 +1,4 @@
1
+ export declare function commaList(value: string): string[];
2
+ export declare function commandParts(value: string): string[];
3
+ export declare function isYesConfirmation(value: string): boolean;
4
+ export declare function isValidUrl(value: string): boolean;
@@ -0,0 +1,19 @@
1
+ import { YES_CONFIRMATION } from './wizardActions.js';
2
+ export function commaList(value) {
3
+ return value.split(',').map(item => item.trim()).filter(Boolean);
4
+ }
5
+ export function commandParts(value) {
6
+ return value.trim().split(/\s+/).filter(Boolean);
7
+ }
8
+ export function isYesConfirmation(value) {
9
+ return value.trim().toLowerCase() === YES_CONFIRMATION;
10
+ }
11
+ export function isValidUrl(value) {
12
+ try {
13
+ new URL(value);
14
+ return true;
15
+ }
16
+ catch {
17
+ return false;
18
+ }
19
+ }
@@ -0,0 +1,22 @@
1
+ import type { HazeMcpServer, HazeSettings } from '../../config/settings.js';
2
+ export type NameCaptureResult = {
3
+ nextMode?: string;
4
+ draft?: {
5
+ name?: string;
6
+ };
7
+ message?: string;
8
+ systemMessage?: string;
9
+ };
10
+ export declare function captureProviderName(settings: HazeSettings, value: string): NameCaptureResult;
11
+ export declare function captureLspName(settings: HazeSettings, value: string): NameCaptureResult;
12
+ export declare function captureMcpName(settings: HazeSettings, value: string): NameCaptureResult;
13
+ export type FieldCaptureResult = {
14
+ draft?: Partial<HazeMcpServer>;
15
+ message?: string;
16
+ nextMode?: string;
17
+ systemMessage?: string;
18
+ };
19
+ export declare function captureProviderUrl(value: string): FieldCaptureResult;
20
+ export declare function captureMcpUrl(value: string): FieldCaptureResult;
21
+ export declare function captureMcpTransport(value: string): FieldCaptureResult;
22
+ export declare function captureMcpCommand(value: string): FieldCaptureResult;
@@ -0,0 +1,52 @@
1
+ import { configuredLspServers } from '../../config/lspSettings.js';
2
+ import { findMcpServer } from '../../config/mcpSettings.js';
3
+ import { MCP_TRANSPORTS } from './wizardActions.js';
4
+ import { commandParts, isValidUrl } from './wizardInput.js';
5
+ export function captureProviderName(settings, value) {
6
+ const name = value.trim();
7
+ if (!name)
8
+ return { message: 'Provider name is required.' };
9
+ if (settings.providers?.some(provider => provider.name === name))
10
+ return { message: `Provider ${name} already exists. Choose a unique name.` };
11
+ return { nextMode: 'providerAddUrl', draft: { name }, systemMessage: 'OpenAI-compatible base URL? Example: https://openrouter.ai/api/v1 or http://localhost:1234/v1' };
12
+ }
13
+ export function captureLspName(settings, value) {
14
+ const name = value.trim();
15
+ if (!name)
16
+ return { message: 'LSP server name is required.' };
17
+ if (configuredLspServers(settings).some(server => server.name === name))
18
+ return { message: `LSP server ${name} already exists. Choose a unique name.` };
19
+ return { nextMode: 'lspAddCommand', draft: { name }, systemMessage: 'Command to run? Example: typescript-language-server --stdio' };
20
+ }
21
+ export function captureMcpName(settings, value) {
22
+ const name = value.trim();
23
+ if (!name)
24
+ return { message: 'MCP server name is required.' };
25
+ if (findMcpServer(settings, name))
26
+ return { message: `MCP server ${name} already exists. Choose a unique name.` };
27
+ return { nextMode: 'mcpAddTransport', draft: { name }, systemMessage: 'Transport type? http (Streamable HTTP), sse (Server-Sent Events), or stdio (local process).' };
28
+ }
29
+ export function captureProviderUrl(value) {
30
+ if (!isValidUrl(value))
31
+ return { message: 'Enter a valid URL, for example http://localhost:1234/v1.' };
32
+ return { draft: { url: value.trim() }, nextMode: 'providerAddKey', systemMessage: 'API key? Leave blank for local/keyless providers.' };
33
+ }
34
+ export function captureMcpUrl(value) {
35
+ if (!isValidUrl(value))
36
+ return { message: 'Enter a valid URL, for example https://mcp.context7.com/mcp.' };
37
+ return { draft: { url: value.trim() }, nextMode: 'mcpAddKey', systemMessage: 'Optional API key or auth header value? (Leave blank to skip — Enter works.) Sent as Authorization: Bearer <value>.' };
38
+ }
39
+ export function captureMcpTransport(value) {
40
+ const transport = value.trim().toLowerCase();
41
+ if (transport !== MCP_TRANSPORTS.http && transport !== MCP_TRANSPORTS.sse && transport !== MCP_TRANSPORTS.stdio)
42
+ return { message: 'Enter http, sse, or stdio.' };
43
+ if (transport === MCP_TRANSPORTS.stdio)
44
+ return { draft: { transport }, nextMode: 'mcpAddCommand', systemMessage: 'Command to run? Example: npx -y @modelcontextprotocol/server-filesystem .' };
45
+ return { draft: { transport }, nextMode: 'mcpAddUrl', systemMessage: `MCP server URL? Example: https://mcp.context7.com/mcp for ${transport}.` };
46
+ }
47
+ export function captureMcpCommand(value) {
48
+ const parts = commandParts(value);
49
+ if (parts.length === 0)
50
+ return { message: 'Command is required.' };
51
+ return { draft: { command: parts[0], args: parts.slice(1) }, nextMode: 'mcpAddKey', systemMessage: 'Optional API key or auth header value? (Leave blank to skip — Enter works.) Sent as Authorization: Bearer <value>.' };
52
+ }
@@ -0,0 +1,23 @@
1
+ import type { HazeSettings } from '../../config/settings.js';
2
+ import type { LoadedSkill } from '../../skills/types.js';
3
+ import type { TextInputSuggestion } from '../../ui/components/TextInput.js';
4
+ /**
5
+ * Pure suggestion builders for the chat wizard pickers (provider / model / LSP /
6
+ * MCP / skills). Extracted from the React component so they are unit-testable
7
+ * and so `ChatScreen` only owns interactive state, not picker content. Each
8
+ * function takes its explicit inputs and returns the suggestion list shown for
9
+ * the corresponding input mode.
10
+ */
11
+ export declare function providerSuggestions(settings: HazeSettings): TextInputSuggestion[];
12
+ export declare function providerActionSuggestions(settings: HazeSettings, selectedProviderName: string | undefined): TextInputSuggestion[];
13
+ export declare function presetSuggestions(): TextInputSuggestion[];
14
+ export declare function modelSuggestions(settings: HazeSettings, modelProviderFilter: string | undefined): TextInputSuggestion[];
15
+ export declare function lspSuggestions(settings: HazeSettings): TextInputSuggestion[];
16
+ export declare function lspActionSuggestions(settings: HazeSettings, selectedLspName: string | undefined): TextInputSuggestion[];
17
+ export declare function lspPresetSuggestions(): TextInputSuggestion[];
18
+ export declare function mcpSuggestions(settings: HazeSettings): TextInputSuggestion[];
19
+ export declare function mcpActionSuggestions(settings: HazeSettings, selectedMcpName: string | undefined): TextInputSuggestion[];
20
+ export declare function mcpPresetSuggestions(): TextInputSuggestion[];
21
+ export declare function mcpTransportSuggestions(): TextInputSuggestion[];
22
+ export declare function skillsSuggestions(settings: HazeSettings, skills: LoadedSkill[]): TextInputSuggestion[];
23
+ export declare function skillsActionSuggestions(settings: HazeSettings, skills: LoadedSkill[], selectedSkillName: string | undefined): TextInputSuggestion[];
@@ -0,0 +1,139 @@
1
+ import { configuredProviders, findProvider, modelSelector } from '../../config/providers.js';
2
+ import { configuredLspServers, LSP_PRESETS } from '../../config/lspSettings.js';
3
+ import { configuredMcpServers, findMcpServer, findMcpPreset, presetIds } from '../../config/mcpSettings.js';
4
+ import { isSkillEnabled } from '../../config/skillSettings.js';
5
+ import { PROVIDER_PRESETS } from '../../config/providerPresets.js';
6
+ import { COMMON_ACTIONS, LSP_ACTIONS, MCP_ACTIONS, MCP_TRANSPORTS, PROVIDER_ACTIONS, PROVIDER_CHOICES, SERVER_CHOICES, SKILL_ACTIONS, SKILL_CHOICES } from './wizardActions.js';
7
+ /**
8
+ * Pure suggestion builders for the chat wizard pickers (provider / model / LSP /
9
+ * MCP / skills). Extracted from the React component so they are unit-testable
10
+ * and so `ChatScreen` only owns interactive state, not picker content. Each
11
+ * function takes its explicit inputs and returns the suggestion list shown for
12
+ * the corresponding input mode.
13
+ */
14
+ export function providerSuggestions(settings) {
15
+ return [
16
+ ...configuredProviders(settings).map(provider => ({
17
+ value: provider.name,
18
+ description: `${provider.url} · ${provider.models.length} model${provider.models.length === 1 ? '' : 's'}`,
19
+ kind: 'provider',
20
+ })),
21
+ { value: PROVIDER_CHOICES.addProvider, description: 'Add a new provider (presets available)', kind: 'provider' },
22
+ ];
23
+ }
24
+ export function providerActionSuggestions(settings, selectedProviderName) {
25
+ const provider = selectedProviderName ? findProvider(settings, selectedProviderName) : undefined;
26
+ return [
27
+ { value: PROVIDER_ACTIONS.useProvider, description: 'Set this provider and choose a model', kind: 'provider' },
28
+ { value: PROVIDER_ACTIONS.addModels, description: 'Append comma-separated model names', kind: 'provider' },
29
+ { value: PROVIDER_ACTIONS.setApiKey, description: provider?.key ? 'Update the saved API key' : 'Add an API key', kind: 'provider' },
30
+ ...(provider?.models?.length ? [{ value: PROVIDER_ACTIONS.removeModels, description: 'Remove models from this provider', kind: 'provider' }] : []),
31
+ { value: PROVIDER_ACTIONS.removeProvider, description: 'Delete this provider from settings', kind: 'provider' },
32
+ ];
33
+ }
34
+ export function presetSuggestions() {
35
+ const cloudPresets = PROVIDER_PRESETS.filter(p => p.category === 'cloud');
36
+ const localPresets = PROVIDER_PRESETS.filter(p => p.category === 'local');
37
+ return [
38
+ ...cloudPresets.map(preset => ({
39
+ value: preset.id,
40
+ description: `${preset.baseUrl}${preset.suggestedModels?.length ? ' · e.g. ' + preset.suggestedModels.slice(0, 2).join(', ') : ''}`,
41
+ kind: 'provider',
42
+ })),
43
+ ...localPresets.map(preset => ({
44
+ value: preset.id,
45
+ description: `${preset.baseUrl} · local, no API key needed`,
46
+ kind: 'provider',
47
+ })),
48
+ { value: PROVIDER_CHOICES.custom, description: 'Enter provider name, URL, and API key manually', kind: 'provider' },
49
+ ];
50
+ }
51
+ export function modelSuggestions(settings, modelProviderFilter) {
52
+ const providers = configuredProviders(settings).filter(provider => !modelProviderFilter || provider.name === modelProviderFilter);
53
+ return providers.flatMap(provider => provider.models.map(model => ({
54
+ value: modelProviderFilter ? model : modelSelector(provider, model),
55
+ description: provider.name,
56
+ kind: 'model',
57
+ })));
58
+ }
59
+ export function lspSuggestions(settings) {
60
+ const servers = configuredLspServers(settings);
61
+ return [{ value: SERVER_CHOICES.addServer, description: 'add an LSP server (presets available)', kind: 'lsp' },
62
+ ...servers.map(server => ({
63
+ value: server.name,
64
+ description: `${server.command}${(server.args ?? []).length ? ` ${(server.args ?? []).join(' ')}` : ''} · ${server.enabled === false ? 'disabled' : 'enabled'}`,
65
+ kind: 'lsp',
66
+ }))];
67
+ }
68
+ export function lspActionSuggestions(settings, selectedLspName) {
69
+ const server = selectedLspName ? configuredLspServers(settings).find(s => s.name === selectedLspName) : undefined;
70
+ const result = [];
71
+ if (server)
72
+ result.push({ value: server.enabled === false ? COMMON_ACTIONS.enable : COMMON_ACTIONS.disable, description: `${server.enabled === false ? COMMON_ACTIONS.enable : COMMON_ACTIONS.disable} this server`, kind: 'lsp' });
73
+ result.push({ value: LSP_ACTIONS.removeServer, description: 'remove this server', kind: 'lsp' });
74
+ return result;
75
+ }
76
+ export function lspPresetSuggestions() {
77
+ return [
78
+ ...Object.values(LSP_PRESETS).map(preset => ({
79
+ value: preset.name,
80
+ description: `${preset.command} ${(preset.args ?? []).join(' ')} [${(preset.extensions ?? []).join(', ')}]`,
81
+ kind: 'lsp',
82
+ })),
83
+ { value: SERVER_CHOICES.custom, description: 'enter a name and command manually', kind: 'lsp' },
84
+ ];
85
+ }
86
+ export function mcpSuggestions(settings) {
87
+ const servers = configuredMcpServers(settings);
88
+ return [{ value: SERVER_CHOICES.addServer, description: 'add an MCP server (presets available)', kind: 'mcp' },
89
+ ...servers.map(server => {
90
+ const location = server.url ?? (server.command ? `${server.command} ${(server.args ?? []).join(' ')}`.trim() : '');
91
+ return { value: server.name, description: `${server.transport}${location ? ` ${location}` : ''} · ${server.enabled === false ? 'disabled' : 'enabled'}`, kind: 'mcp' };
92
+ })];
93
+ }
94
+ export function mcpActionSuggestions(settings, selectedMcpName) {
95
+ const server = selectedMcpName ? findMcpServer(settings, selectedMcpName) : undefined;
96
+ const result = [];
97
+ if (server) {
98
+ result.push({ value: server.enabled === false ? COMMON_ACTIONS.enable : COMMON_ACTIONS.disable, description: `${server.enabled === false ? COMMON_ACTIONS.enable : COMMON_ACTIONS.disable} this server`, kind: 'mcp' });
99
+ result.push({ value: MCP_ACTIONS.setApiKey, description: server.headers?.length ? 'update the saved API key' : 'add an API key', kind: 'mcp' });
100
+ }
101
+ result.push({ value: MCP_ACTIONS.removeServer, description: 'remove this server', kind: 'mcp' });
102
+ return result;
103
+ }
104
+ export function mcpPresetSuggestions() {
105
+ return [
106
+ ...presetIds().map(presetId => {
107
+ const preset = findMcpPreset(presetId);
108
+ return { value: presetId, description: preset.description ?? `${preset.transport} server`, kind: 'mcp' };
109
+ }),
110
+ { value: SERVER_CHOICES.custom, description: 'enter name, transport, and URL or command manually', kind: 'mcp' },
111
+ ];
112
+ }
113
+ export function mcpTransportSuggestions() {
114
+ return [
115
+ { value: MCP_TRANSPORTS.http, description: 'Streamable HTTP (remote)', kind: 'mcp' },
116
+ { value: MCP_TRANSPORTS.sse, description: 'Server-Sent Events (remote)', kind: 'mcp' },
117
+ { value: MCP_TRANSPORTS.stdio, description: 'local process', kind: 'mcp' },
118
+ ];
119
+ }
120
+ export function skillsSuggestions(settings, skills) {
121
+ return [{ value: SKILL_CHOICES.addSkill, description: 'describe a new skill for Haze to generate', kind: 'skill' },
122
+ ...skills.map(skill => ({
123
+ value: skill.name,
124
+ description: `${skill.description}${isSkillEnabled(settings, skill.name) ? '' : ' · disabled'}`,
125
+ kind: 'skill',
126
+ }))];
127
+ }
128
+ export function skillsActionSuggestions(settings, skills, selectedSkillName) {
129
+ const skill = selectedSkillName ? skills.find(candidate => candidate.name === selectedSkillName) : undefined;
130
+ const result = [];
131
+ if (skill) {
132
+ const enabled = isSkillEnabled(settings, skill.name);
133
+ result.push({ value: enabled ? COMMON_ACTIONS.disable : COMMON_ACTIONS.enable, description: `${enabled ? COMMON_ACTIONS.disable : COMMON_ACTIONS.enable} this skill`, kind: 'skill' });
134
+ result.push({ value: SKILL_ACTIONS.showInfo, description: 'show description, references, and path', kind: 'skill' });
135
+ result.push({ value: SKILL_ACTIONS.validate, description: 're-load and validate SKILL.md', kind: 'skill' });
136
+ }
137
+ result.push({ value: SKILL_ACTIONS.removeSkill, description: 'delete this skill directory', kind: 'skill' });
138
+ return result;
139
+ }
package/dist/cli/index.js CHANGED
@@ -2,8 +2,9 @@
2
2
  import { readFileSync } from 'node:fs';
3
3
  import { fileURLToPath } from 'node:url';
4
4
  import { dirname, join } from 'node:path';
5
- import { Command } from 'commander';
5
+ import { Command, Option } from 'commander';
6
6
  import { chatCommand } from './commands/chat.js';
7
+ import { runHeadless } from './commands/runCommand.js';
7
8
  const __dirname = dirname(fileURLToPath(import.meta.url));
8
9
  const pkg = JSON.parse(readFileSync(join(__dirname, '..', '..', 'package.json'), 'utf8'));
9
10
  const program = new Command();
@@ -11,14 +12,71 @@ program
11
12
  .name('haze')
12
13
  .description('A pragmatic, intentionally limited agentic CLI.')
13
14
  .version(pkg.version)
14
- .option('--debug', 'show simple model/tool debug logs in the chat UI')
15
+ .option('--debug', 'show model/tool debug logs and write a detailed JSONL log to ~/.haze/logs/')
15
16
  .option('-c, --continue', 'resume the latest saved session for this workspace')
16
- .option('--no-session', 'run without saving or resuming a durable session');
17
+ .option('--no-session', 'run without saving or resuming a durable session')
18
+ .option('-p, --prompt <text>', 'print mode: run a single non-interactive turn and print the result (falls back to piped stdin)')
19
+ .option('-m, --model <selector>', 'override the model for this run only — a registered model name or provider:name')
20
+ .addOption(new Option('--output <format>', 'print-mode output: plain text, a single JSON result envelope, or a stream-json NDJSON event stream').choices(['text', 'json', 'stream-json']).default('text'));
21
+ program.addHelpText('after', `
22
+ Examples:
23
+ $ haze start the interactive chat
24
+ $ haze -p "explain src/cli/index.ts" print mode: run one turn and print the reply
25
+ $ echo "what does this repo do?" | haze read the prompt from piped stdin
26
+ $ haze -p "list the top 3 bugs" --output json emit a JSON envelope { type, status, result, usage }
27
+ $ haze -p "audit src/" --output stream-json stream NDJSON events live, then the final result envelope
28
+ $ haze -p "summarize" --model openai:gpt-4o-mini override the model for this run only
29
+ $ haze -p "audit auth.ts" --debug also write a detailed JSONL log to ~/.haze/logs/
30
+
31
+ Print mode (-p):
32
+ Runs a single agentic turn with the full toolset and guardrails, prints the final assistant
33
+ text, then exits (0 = complete; non-zero = aborted/failed, so CI can gate on the exit code).
34
+ The prompt comes from -p, otherwise from piped stdin. With --output json the reply is wrapped
35
+ in a single-line { type, status, result, usage } envelope. With --output stream-json haze streams
36
+ one NDJSON agent event per line (turn_start, message_*, tool_*, retry, turn_end) as the run
37
+ progresses, then prints that same { type:'result', ... } envelope as the final line — giving
38
+ harnesses live progress and stagnation detection. --model overrides the model for this
39
+ run only (no settings change) and must already be registered under a provider (add it once via
40
+ the /provider picker). Print-mode runs are non-durable: --continue is ignored and no session is
41
+ saved, and there is no automatic context-overflow recovery.
42
+ `);
43
+ async function readStdinPrompt() {
44
+ // Only read stdin when it is piped (non-TTY); never hang waiting on an interactive terminal.
45
+ if (process.stdin.isTTY === false) {
46
+ return new Promise((resolve) => {
47
+ let data = '';
48
+ process.stdin.setEncoding('utf8');
49
+ process.stdin.on('data', (chunk) => {
50
+ data += chunk;
51
+ });
52
+ process.stdin.on('end', () => resolve(data.trim() ? data : undefined));
53
+ process.stdin.on('error', () => resolve(undefined));
54
+ });
55
+ }
56
+ return undefined;
57
+ }
17
58
  program.action(async () => {
18
59
  const opts = program.opts();
60
+ // -p takes precedence; otherwise fall back to piped stdin. An empty stdin yields no prompt.
61
+ const prompt = opts.prompt?.trim() ? opts.prompt : await readStdinPrompt();
62
+ if (prompt) {
63
+ // One-shot runs are always fresh and non-durable; --continue is ignored in this mode.
64
+ const code = await runHeadless({
65
+ prompt,
66
+ modelOverride: opts.model,
67
+ // commander validates --output against the choices above, so opts.output is one of
68
+ // 'text' | 'json' | 'stream-json'; default to text for piped/stdin runs without the flag.
69
+ output: opts.output === 'json' || opts.output === 'stream-json' ? opts.output : 'text',
70
+ debug: Boolean(opts.debug),
71
+ });
72
+ // Set the exit code and return instead of process.exit(code): the latter does not wait
73
+ // for stdout to drain and can truncate piped/redirected output (e.g. `haze -p ... | jq`).
74
+ process.exitCode = code;
75
+ return;
76
+ }
19
77
  await chatCommand({ debug: Boolean(opts.debug), continueSession: Boolean(opts.continue), noSession: opts.session === false, version: pkg.version });
20
78
  });
21
- program.parseAsync().catch(error => {
79
+ program.parseAsync().catch((error) => {
22
80
  console.error(error instanceof Error ? error.message : error);
23
81
  process.exit(1);
24
82
  });
@@ -1,6 +1,11 @@
1
1
  export interface ContextFile {
2
2
  path: string;
3
3
  content: string;
4
+ signature?: string;
5
+ }
6
+ export interface ReadContextFileOptions {
7
+ onContextFileRead?: (path: string) => void;
8
+ alreadyLoadedSignatures?: ReadonlyMap<string, string>;
4
9
  }
5
10
  export interface ContextFileDiagnostic {
6
11
  path: string;
@@ -24,10 +29,12 @@ export interface ContextFileDiagnosticsSummary {
24
29
  }
25
30
  /** Maximum characters of a context file included in every request's system context. */
26
31
  export declare const MAX_CONTEXT_FILE_CHARS = 20000;
27
- export declare function readContextFiles(cwd?: string): Promise<ContextFile[]>;
32
+ export declare function readContextFiles(cwd?: string, options?: ReadContextFileOptions): Promise<ContextFile[]>;
28
33
  export declare function readScopedContextFilesForPath(targetPath: string, options?: {
29
34
  cwd?: string;
30
35
  alreadyLoadedPaths?: Iterable<string>;
36
+ alreadyLoadedSignatures?: ReadonlyMap<string, string>;
37
+ onContextFileRead?: (path: string) => void;
31
38
  }): Promise<ContextFile[]>;
32
39
  export declare function contextFileDiagnostics(files: ContextFile[]): ContextFileDiagnostic[];
33
40
  export declare function summarizeContextDiagnostics(files: ContextFile[], options?: {
@@ -10,6 +10,9 @@ function resolveBudgetThreshold(explicit) {
10
10
  return DEFAULT_BUDGET_THRESHOLD;
11
11
  }
12
12
  const CONTEXT_FILE_NAMES = ['CLAUDE.md', 'AGENTS.md'];
13
+ function contextFileSignature(stat) {
14
+ return `${stat.size}:${stat.mtimeMs}`;
15
+ }
13
16
  /** Maximum characters of a context file included in every request's system context. */
14
17
  export const MAX_CONTEXT_FILE_CHARS = 20_000;
15
18
  function uniqueExistingAncestors(fromDir) {
@@ -33,7 +36,7 @@ function displayPath(filePath) {
33
36
  return `~/${path.relative(home, filePath)}`;
34
37
  return filePath;
35
38
  }
36
- async function readContextCandidates(candidates, seen = new Set()) {
39
+ async function readContextCandidates(candidates, seen = new Set(), options = {}) {
37
40
  const contextFiles = [];
38
41
  for (const candidate of candidates) {
39
42
  const absolute = path.resolve(candidate);
@@ -45,13 +48,21 @@ async function readContextCandidates(candidates, seen = new Set()) {
45
48
  const stat = await fs.stat(absolute).catch(() => null);
46
49
  if (!stat?.isFile())
47
50
  continue;
51
+ const displayedPath = displayPath(absolute);
52
+ const signature = contextFileSignature(stat);
53
+ const loadedSignature = options.alreadyLoadedSignatures?.get(displayedPath) ?? options.alreadyLoadedSignatures?.get(absolute);
54
+ if (loadedSignature === signature)
55
+ continue;
56
+ options.onContextFileRead?.(displayedPath);
48
57
  const content = await fs.readFile(absolute, 'utf8');
49
- contextFiles.push({
50
- path: displayPath(absolute),
58
+ const file = {
59
+ path: displayedPath,
51
60
  content: content.length > MAX_CONTEXT_FILE_CHARS
52
61
  ? `${content.slice(0, MAX_CONTEXT_FILE_CHARS)}\n\n[Context file truncated: ${content.length - MAX_CONTEXT_FILE_CHARS} characters omitted]`
53
62
  : content,
54
- });
63
+ signature,
64
+ };
65
+ contextFiles.push(file);
55
66
  }
56
67
  return contextFiles;
57
68
  }
@@ -70,7 +81,7 @@ async function scopedDirsForPath(targetPath, cwd) {
70
81
  }
71
82
  return dirs.reverse();
72
83
  }
73
- export async function readContextFiles(cwd = process.cwd()) {
84
+ export async function readContextFiles(cwd = process.cwd(), options = {}) {
74
85
  const candidates = [
75
86
  path.join(os.homedir(), '.claude', 'CLAUDE.md'),
76
87
  path.join(HAZE_DIR, 'AGENTS.md'),
@@ -79,7 +90,7 @@ export async function readContextFiles(cwd = process.cwd()) {
79
90
  for (const name of CONTEXT_FILE_NAMES)
80
91
  candidates.push(path.join(dir, name));
81
92
  }
82
- return await readContextCandidates(candidates);
93
+ return await readContextCandidates(candidates, undefined, options);
83
94
  }
84
95
  export async function readScopedContextFilesForPath(targetPath, options = {}) {
85
96
  const cwd = options.cwd ?? process.cwd();
@@ -90,13 +101,15 @@ export async function readScopedContextFilesForPath(targetPath, options = {}) {
90
101
  candidates.push(path.join(dir, name));
91
102
  }
92
103
  const alreadySeen = new Set();
93
- for (const loadedPath of loaded) {
94
- if (loadedPath.startsWith('~/'))
95
- alreadySeen.add(path.resolve(os.homedir(), loadedPath.slice(2)));
96
- else
97
- alreadySeen.add(path.resolve(cwd, loadedPath));
104
+ if (!options.alreadyLoadedSignatures) {
105
+ for (const loadedPath of loaded) {
106
+ if (loadedPath.startsWith('~/'))
107
+ alreadySeen.add(path.resolve(os.homedir(), loadedPath.slice(2)));
108
+ else
109
+ alreadySeen.add(path.resolve(cwd, loadedPath));
110
+ }
98
111
  }
99
- return await readContextCandidates(candidates, alreadySeen);
112
+ return await readContextCandidates(candidates, alreadySeen, options);
100
113
  }
101
114
  export function contextFileDiagnostics(files) {
102
115
  return files.map(file => ({
@@ -0,0 +1,16 @@
1
+ import type { HazeSettings } from './settings.js';
2
+ export interface HazeLspServer {
3
+ name: string;
4
+ command: string;
5
+ args?: string[];
6
+ extensions?: string[];
7
+ rootPatterns?: string[];
8
+ enabled?: boolean;
9
+ }
10
+ export declare const LSP_PRESETS: Record<string, HazeLspServer>;
11
+ export declare function configuredLspServers(settings: HazeSettings): HazeLspServer[];
12
+ export declare function upsertLspServer(settings: HazeSettings, server: HazeLspServer): HazeLspServer[];
13
+ export declare function removeLspServer(settings: HazeSettings, name: string): HazeLspServer[];
14
+ export declare function setLspServerEnabled(settings: HazeSettings, name: string, enabled: boolean): HazeLspServer[];
15
+ export declare function installedLspServers(settings: HazeSettings): Promise<HazeLspServer[]>;
16
+ export declare function lspPreset(name: string): HazeLspServer | undefined;
@@ -0,0 +1,95 @@
1
+ import fs from 'node:fs/promises';
2
+ import path from 'node:path';
3
+ import { removeByName, upsertByName } from '../utils/collections.js';
4
+ export const LSP_PRESETS = {
5
+ typescript: {
6
+ name: 'typescript',
7
+ command: 'typescript-language-server',
8
+ args: ['--stdio'],
9
+ extensions: ['.ts', '.tsx', '.js', '.jsx'],
10
+ rootPatterns: ['tsconfig.json', 'jsconfig.json', 'package.json', '.git'],
11
+ },
12
+ rust: {
13
+ name: 'rust',
14
+ command: 'rust-analyzer',
15
+ args: [],
16
+ extensions: ['.rs'],
17
+ rootPatterns: ['Cargo.toml', '.git'],
18
+ },
19
+ python: {
20
+ name: 'python',
21
+ command: 'pyright-langserver',
22
+ args: ['--stdio'],
23
+ extensions: ['.py'],
24
+ rootPatterns: ['pyproject.toml', 'setup.py', '.git'],
25
+ },
26
+ go: {
27
+ name: 'go',
28
+ command: 'gopls',
29
+ args: [],
30
+ extensions: ['.go'],
31
+ rootPatterns: ['go.mod', '.git'],
32
+ },
33
+ php: {
34
+ name: 'php',
35
+ command: 'intelephense',
36
+ args: ['--stdio'],
37
+ extensions: ['.php'],
38
+ rootPatterns: ['composer.json', '.git'],
39
+ },
40
+ };
41
+ function normalizeExtensions(extensions) {
42
+ return [...new Set((extensions ?? []).map(ext => ext.trim()).filter(Boolean).map(ext => ext.startsWith('.') ? ext : `.${ext}`))];
43
+ }
44
+ export function configuredLspServers(settings) {
45
+ return (settings.lspServers ?? []).map(server => ({
46
+ ...server,
47
+ args: server.args ?? [],
48
+ extensions: normalizeExtensions(server.extensions),
49
+ rootPatterns: server.rootPatterns ?? [],
50
+ enabled: server.enabled !== false,
51
+ }));
52
+ }
53
+ export function upsertLspServer(settings, server) {
54
+ const normalized = {
55
+ ...server,
56
+ args: server.args ?? [],
57
+ extensions: normalizeExtensions(server.extensions),
58
+ rootPatterns: server.rootPatterns ?? [],
59
+ enabled: server.enabled !== false,
60
+ };
61
+ return upsertByName(configuredLspServers(settings), normalized);
62
+ }
63
+ export function removeLspServer(settings, name) {
64
+ return removeByName(configuredLspServers(settings), name);
65
+ }
66
+ export function setLspServerEnabled(settings, name, enabled) {
67
+ return configuredLspServers(settings).map(server => server.name === name ? { ...server, enabled } : server);
68
+ }
69
+ async function commandExists(command) {
70
+ const candidates = command.includes('/') || command.includes('\\')
71
+ ? [command]
72
+ : (process.env.PATH ?? '').split(path.delimiter).filter(Boolean).map(dir => path.join(dir, command));
73
+ const extensions = process.platform === 'win32' ? ['', '.exe', '.cmd', '.bat'] : [''];
74
+ for (const candidate of candidates) {
75
+ for (const ext of extensions) {
76
+ try {
77
+ await fs.access(`${candidate}${ext}`);
78
+ return true;
79
+ }
80
+ catch {
81
+ // try next candidate
82
+ }
83
+ }
84
+ }
85
+ return false;
86
+ }
87
+ export async function installedLspServers(settings) {
88
+ const servers = configuredLspServers(settings).filter(server => server.enabled !== false);
89
+ const checks = await Promise.all(servers.map(async (server) => await commandExists(server.command)));
90
+ return servers.filter((_server, index) => checks[index]);
91
+ }
92
+ export function lspPreset(name) {
93
+ const preset = LSP_PRESETS[name];
94
+ return preset ? { ...preset, args: [...(preset.args ?? [])], extensions: [...(preset.extensions ?? [])], rootPatterns: [...(preset.rootPatterns ?? [])], enabled: true } : undefined;
95
+ }