@denizokcu/haze 0.10.0 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (294) hide show
  1. package/CHANGELOG.md +100 -1
  2. package/README.md +77 -27
  3. package/SECURITY.md +22 -0
  4. package/bin/haze.js +102 -1
  5. package/dist/buildInfo.json +7 -0
  6. package/dist/cli/chat/TaskBar.d.ts +2 -1
  7. package/dist/cli/chat/TaskBar.js +7 -4
  8. package/dist/cli/chat/chatMetrics.d.ts +2 -2
  9. package/dist/cli/chat/chatMetrics.js +1 -1
  10. package/dist/cli/chat/contextReport.js +2 -0
  11. package/dist/cli/chat/fileMentionSuggestions.js +3 -2
  12. package/dist/cli/chat/inputSuggestions.d.ts +8 -16
  13. package/dist/cli/chat/inputSuggestions.js +9 -41
  14. package/dist/cli/chat/liveRegion.d.ts +25 -0
  15. package/dist/cli/chat/liveRegion.js +48 -0
  16. package/dist/cli/chat/messages.d.ts +33 -4
  17. package/dist/cli/chat/messages.js +218 -35
  18. package/dist/cli/chat/sessionLifecycle.d.ts +11 -1
  19. package/dist/cli/chat/sessionLifecycle.js +64 -14
  20. package/dist/cli/chat/sessionRecorder.js +75 -7
  21. package/dist/cli/chat/startupInfo.d.ts +0 -1
  22. package/dist/cli/chat/startupInfo.js +11 -15
  23. package/dist/cli/chat/turnState.d.ts +1 -1
  24. package/dist/cli/chat/wizardDispatch.d.ts +90 -28
  25. package/dist/cli/chat/wizardDispatch.js +349 -133
  26. package/dist/cli/commands/chat.d.ts +5 -0
  27. package/dist/cli/commands/chat.js +216 -172
  28. package/dist/cli/commands/chatModes.d.ts +8 -1
  29. package/dist/cli/commands/chatModes.js +9 -44
  30. package/dist/cli/commands/commands.d.ts +2 -0
  31. package/dist/cli/commands/commands.js +10 -5
  32. package/dist/cli/commands/doctor.d.ts +19 -0
  33. package/dist/cli/commands/doctor.js +76 -0
  34. package/dist/cli/commands/formatters.d.ts +3 -3
  35. package/dist/cli/commands/formatters.js +8 -25
  36. package/dist/cli/commands/ndjsonSink.d.ts +23 -0
  37. package/dist/cli/commands/ndjsonSink.js +38 -0
  38. package/dist/cli/commands/providerWizard.d.ts +9 -2
  39. package/dist/cli/commands/providerWizard.js +39 -7
  40. package/dist/cli/commands/runCommand.d.ts +3 -0
  41. package/dist/cli/commands/runCommand.js +117 -11
  42. package/dist/cli/commands/serverWizard.d.ts +34 -0
  43. package/dist/cli/commands/{mcpWizard.js → serverWizard.js} +44 -2
  44. package/dist/cli/commands/skillsWizard.d.ts +41 -0
  45. package/dist/cli/commands/{skillWizard.js → skillsWizard.js} +33 -11
  46. package/dist/cli/commands/streaming/abortCause.d.ts +25 -0
  47. package/dist/cli/commands/streaming/abortCause.js +16 -0
  48. package/dist/cli/commands/streaming/agentAttempt.d.ts +43 -0
  49. package/dist/cli/commands/streaming/agentAttempt.js +79 -0
  50. package/dist/cli/commands/streaming/assistantText.js +9 -2
  51. package/dist/cli/commands/streaming/attemptLifecycle.d.ts +56 -0
  52. package/dist/cli/commands/streaming/attemptLifecycle.js +110 -0
  53. package/dist/cli/commands/streaming/attemptOutcome.d.ts +96 -0
  54. package/dist/cli/commands/streaming/attemptOutcome.js +206 -0
  55. package/dist/cli/commands/streaming/attemptSetup.d.ts +78 -0
  56. package/dist/cli/commands/streaming/attemptSetup.js +167 -0
  57. package/dist/cli/commands/streaming/goalCheckpoint.d.ts +65 -0
  58. package/dist/cli/commands/streaming/goalCheckpoint.js +23 -0
  59. package/dist/cli/commands/streaming/goalSupervisor.d.ts +64 -0
  60. package/dist/cli/commands/streaming/goalSupervisor.js +130 -0
  61. package/dist/cli/commands/streaming/stallRecovery.d.ts +94 -0
  62. package/dist/cli/commands/streaming/stallRecovery.js +105 -0
  63. package/dist/cli/commands/streaming/streamLoop.d.ts +72 -0
  64. package/dist/cli/commands/streaming/streamLoop.js +448 -0
  65. package/dist/cli/commands/streaming/toolCallRecovery.d.ts +16 -0
  66. package/dist/cli/commands/streaming/toolCallRecovery.js +80 -0
  67. package/dist/cli/commands/streaming/toolGroupRenderer.d.ts +31 -1
  68. package/dist/cli/commands/streaming/toolGroupRenderer.js +50 -4
  69. package/dist/cli/commands/streaming/toolResultState.d.ts +6 -1
  70. package/dist/cli/commands/streaming/toolResultState.js +29 -7
  71. package/dist/cli/commands/streaming/turnRuntime.d.ts +4 -0
  72. package/dist/cli/commands/streaming/turnRuntime.js +6 -0
  73. package/dist/cli/commands/streaming.d.ts +65 -9
  74. package/dist/cli/commands/streaming.js +133 -430
  75. package/dist/cli/commands/wizardFlow.d.ts +334 -0
  76. package/dist/cli/commands/wizardFlow.js +377 -0
  77. package/dist/cli/contextReport.js +3 -0
  78. package/dist/cli/index.js +68 -22
  79. package/dist/cli/terminalTitle.js +1 -1
  80. package/dist/config/contextFiles.js +9 -3
  81. package/dist/config/inputHistory.d.ts +0 -1
  82. package/dist/config/inputHistory.js +1 -1
  83. package/dist/config/modelDiscovery.d.ts +36 -0
  84. package/dist/config/modelDiscovery.js +164 -1
  85. package/dist/config/privateStorage.js +28 -2
  86. package/dist/config/providerAuth.d.ts +14 -0
  87. package/dist/config/providerAuth.js +49 -0
  88. package/dist/config/providerPresets.d.ts +39 -7
  89. package/dist/config/providerPresets.js +371 -100
  90. package/dist/config/providers.js +2 -0
  91. package/dist/config/settings.d.ts +43 -0
  92. package/dist/config/settings.js +12 -0
  93. package/dist/config/skillSettings.js +4 -4
  94. package/dist/config/updateCheck.d.ts +0 -1
  95. package/dist/config/updateCheck.js +1 -1
  96. package/dist/core/agent/budgets.d.ts +73 -1
  97. package/dist/core/agent/budgets.js +94 -1
  98. package/dist/core/agent/compaction.d.ts +38 -0
  99. package/dist/core/agent/compaction.js +92 -17
  100. package/dist/core/agent/completionController.d.ts +224 -0
  101. package/dist/core/agent/completionController.js +296 -0
  102. package/dist/core/agent/contextBudget.d.ts +36 -2
  103. package/dist/core/agent/contextBudget.js +62 -9
  104. package/dist/core/agent/errors.d.ts +0 -1
  105. package/dist/core/agent/errors.js +1 -1
  106. package/dist/core/agent/events.d.ts +78 -0
  107. package/dist/core/agent/goalPolicy.d.ts +47 -0
  108. package/dist/core/agent/goalPolicy.js +106 -0
  109. package/dist/core/agent/reasoningPolicy.d.ts +31 -0
  110. package/dist/core/agent/reasoningPolicy.js +27 -0
  111. package/dist/core/agent/requestAssembly.d.ts +2 -2
  112. package/dist/core/agent/requestAssembly.js +16 -4
  113. package/dist/core/agent/toolCapabilities.d.ts +27 -0
  114. package/dist/core/agent/toolCapabilities.js +58 -0
  115. package/dist/core/agent/toolOutputStore.d.ts +8 -0
  116. package/dist/core/agent/toolOutputStore.js +11 -11
  117. package/dist/core/agent/toolResults.d.ts +12 -0
  118. package/dist/core/agent/toolResults.js +38 -0
  119. package/dist/core/agent/turnPolicy.d.ts +11 -0
  120. package/dist/core/agent/turnPolicy.js +19 -0
  121. package/dist/core/agent/workState.d.ts +81 -3
  122. package/dist/core/agent/workState.js +176 -10
  123. package/dist/core/attachments/imageAttachments.js +90 -42
  124. package/dist/core/deadline.d.ts +27 -0
  125. package/dist/core/deadline.js +74 -0
  126. package/dist/core/io/boundedRead.js +1 -1
  127. package/dist/core/limits.d.ts +51 -0
  128. package/dist/core/limits.js +51 -0
  129. package/dist/core/log/llmLog.js +8 -1
  130. package/dist/core/persistence/orderedFileWriter.d.ts +10 -0
  131. package/dist/core/persistence/orderedFileWriter.js +16 -2
  132. package/dist/core/process/backgroundRegistry.d.ts +2 -3
  133. package/dist/core/process/backgroundRegistry.js +15 -10
  134. package/dist/core/process/runBoundedProcess.d.ts +8 -2
  135. package/dist/core/process/runBoundedProcess.js +15 -6
  136. package/dist/core/process/userShell.d.ts +16 -0
  137. package/dist/core/process/userShell.js +59 -0
  138. package/dist/core/safety/missingExecutable.d.ts +42 -0
  139. package/dist/core/safety/missingExecutable.js +77 -0
  140. package/dist/core/safety/shellClassifier.d.ts +11 -0
  141. package/dist/core/safety/{bashClassifier.js → shellClassifier.js} +5 -3
  142. package/dist/core/safety/urlGuard.d.ts +1 -1
  143. package/dist/core/session/sessionSlimming.d.ts +0 -3
  144. package/dist/core/session/sessionSlimming.js +2 -3
  145. package/dist/core/session/sessionStore.d.ts +38 -0
  146. package/dist/core/session/sessionStore.js +242 -59
  147. package/dist/core/{bashOutput → shellOutput}/lineFilter.js +8 -2
  148. package/dist/core/{bashOutput → shellOutput}/reducers/search.d.ts +0 -1
  149. package/dist/core/{bashOutput → shellOutput}/reducers/search.js +1 -1
  150. package/dist/core/shellOutput/registry.d.ts +2 -0
  151. package/dist/core/{bashOutput → shellOutput}/registry.js +3 -3
  152. package/dist/core/{bashOutput → shellOutput}/types.d.ts +6 -5
  153. package/dist/core/subagent/contracts.d.ts +6 -14
  154. package/dist/core/subagent/contracts.js +4 -3
  155. package/dist/core/subagent/executionProfiles.js +2 -2
  156. package/dist/core/subagent/subagentCoordinator.d.ts +4 -0
  157. package/dist/core/subagent/subagentCoordinator.js +32 -2
  158. package/dist/core/subagent/subagentRunner.js +19 -40
  159. package/dist/core/toolOutput/reduction.d.ts +0 -12
  160. package/dist/core/toolOutput/reduction.js +1 -1
  161. package/dist/core/validation/outputParser.d.ts +2 -2
  162. package/dist/llm/client.d.ts +17 -1
  163. package/dist/llm/client.js +86 -14
  164. package/dist/llm/hazeTools.d.ts +693 -204
  165. package/dist/llm/hazeTools.js +110 -28
  166. package/dist/llm/initPrompt.js +1 -1
  167. package/dist/llm/lsp/client.d.ts +45 -0
  168. package/dist/llm/lsp/client.js +195 -0
  169. package/dist/llm/lsp/pool.d.ts +23 -0
  170. package/dist/llm/lsp/pool.js +86 -0
  171. package/dist/llm/lsp/protocol.d.ts +64 -0
  172. package/dist/llm/lsp/protocol.js +128 -0
  173. package/dist/llm/lsp/requests.d.ts +94 -0
  174. package/dist/llm/lsp/requests.js +119 -0
  175. package/dist/llm/lspTools.d.ts +5653 -33
  176. package/dist/llm/lspTools.js +152 -80
  177. package/dist/llm/openaiCodex.d.ts +1 -0
  178. package/dist/llm/openaiCodex.js +43 -0
  179. package/dist/llm/openaiCodexOAuth.d.ts +51 -0
  180. package/dist/llm/openaiCodexOAuth.js +217 -0
  181. package/dist/llm/requestContext.d.ts +7 -0
  182. package/dist/llm/requestContext.js +30 -4
  183. package/dist/llm/systemPrompt.d.ts +12 -0
  184. package/dist/llm/systemPrompt.js +24 -11
  185. package/dist/llm/toolResultTypes.d.ts +7 -14
  186. package/dist/llm/toolResultTypes.js +1 -4
  187. package/dist/llm/tools/editMatch.d.ts +14 -9
  188. package/dist/llm/tools/editMatch.js +73 -1
  189. package/dist/llm/tools/failures.d.ts +2 -0
  190. package/dist/llm/tools/failures.js +1 -0
  191. package/dist/llm/tools/fetchTool.d.ts +16 -0
  192. package/dist/llm/tools/fetchTool.js +1 -1
  193. package/dist/llm/tools/fileToolShared.d.ts +8 -5
  194. package/dist/llm/tools/fileToolShared.js +22 -23
  195. package/dist/llm/tools/gitIgnore.d.ts +42 -0
  196. package/dist/llm/tools/gitIgnore.js +247 -0
  197. package/dist/llm/tools/grepParse.d.ts +2 -1
  198. package/dist/llm/tools/grepRunner.d.ts +1 -1
  199. package/dist/llm/tools/grepRunner.js +2 -2
  200. package/dist/llm/tools/outputCap.d.ts +2 -7
  201. package/dist/llm/tools/outputCap.js +3 -3
  202. package/dist/llm/tools/processTool.d.ts +16 -16
  203. package/dist/llm/tools/processTool.js +1 -1
  204. package/dist/llm/tools/readRecovery.d.ts +8 -0
  205. package/dist/llm/tools/readRecovery.js +135 -0
  206. package/dist/llm/tools/{bashTool.d.ts → shellTool.d.ts} +171 -123
  207. package/dist/llm/tools/{bashTool.js → shellTool.js} +20 -14
  208. package/dist/llm/tools/toolContext.d.ts +1 -1
  209. package/dist/llm/tools/toolContext.js +66 -37
  210. package/dist/llm/tools/workspaceFile.d.ts +0 -1
  211. package/dist/llm/tools/workspaceFile.js +1 -6
  212. package/dist/llm/webFetch.d.ts +18 -1
  213. package/dist/llm/webFetch.js +64 -97
  214. package/dist/skills/SkillLoader.d.ts +1 -11
  215. package/dist/skills/SkillLoader.js +1 -2
  216. package/dist/skills/types.d.ts +2 -1
  217. package/dist/ui/codeHighlight.d.ts +4 -0
  218. package/dist/ui/codeHighlight.js +31 -0
  219. package/dist/ui/components/Header.d.ts +1 -1
  220. package/dist/ui/components/MarkdownText.d.ts +16 -2
  221. package/dist/ui/components/MarkdownText.js +244 -34
  222. package/dist/ui/components/TextInput.d.ts +8 -1
  223. package/dist/ui/components/TextInput.js +6 -2
  224. package/dist/ui/theme.d.ts +4 -3
  225. package/dist/ui/theme.js +5 -4
  226. package/dist/utils/buildInfo.d.ts +97 -0
  227. package/dist/utils/buildInfo.js +244 -0
  228. package/dist/utils/fs.d.ts +11 -0
  229. package/dist/utils/fs.js +91 -26
  230. package/dist/utils/openPath.d.ts +2 -2
  231. package/dist/utils/openPath.js +19 -6
  232. package/dist/utils/path.d.ts +2 -1
  233. package/dist/utils/path.js +6 -2
  234. package/dist/utils/utf8.d.ts +22 -0
  235. package/dist/utils/utf8.js +54 -0
  236. package/dist/utils/version.d.ts +9 -3
  237. package/dist/utils/version.js +28 -2
  238. package/package.json +28 -21
  239. package/dist/cli/commands/lspWizard.d.ts +0 -14
  240. package/dist/cli/commands/lspWizard.js +0 -44
  241. package/dist/cli/commands/mcpWizard.d.ts +0 -15
  242. package/dist/cli/commands/skillConfirmRemove.d.ts +0 -11
  243. package/dist/cli/commands/skillConfirmRemove.js +0 -20
  244. package/dist/cli/commands/skillCreation.d.ts +0 -12
  245. package/dist/cli/commands/skillCreation.js +0 -14
  246. package/dist/cli/commands/skillWizard.d.ts +0 -17
  247. package/dist/cli/commands/streaming/idleTimer.d.ts +0 -26
  248. package/dist/cli/commands/streaming/idleTimer.js +0 -24
  249. package/dist/cli/commands/streaming/turnOutcome.d.ts +0 -10
  250. package/dist/cli/commands/streaming/turnOutcome.js +0 -13
  251. package/dist/cli/commands/wizardActions.d.ts +0 -46
  252. package/dist/cli/commands/wizardActions.js +0 -46
  253. package/dist/cli/commands/wizardInput.d.ts +0 -4
  254. package/dist/cli/commands/wizardInput.js +0 -19
  255. package/dist/cli/commands/wizardPrompts.d.ts +0 -22
  256. package/dist/cli/commands/wizardPrompts.js +0 -52
  257. package/dist/cli/commands/wizardSuggestions.d.ts +0 -31
  258. package/dist/cli/commands/wizardSuggestions.js +0 -188
  259. package/dist/cli/commands/wizardTransition.d.ts +0 -37
  260. package/dist/cli/commands/wizardTransition.js +0 -43
  261. package/dist/core/bashOutput/ansi.d.ts +0 -1
  262. package/dist/core/bashOutput/ansi.js +0 -7
  263. package/dist/core/bashOutput/registry.d.ts +0 -4
  264. package/dist/core/goal/completionPolicy.d.ts +0 -2
  265. package/dist/core/goal/completionPolicy.js +0 -7
  266. package/dist/core/goal/requestClassifier.d.ts +0 -3
  267. package/dist/core/goal/requestClassifier.js +0 -18
  268. package/dist/core/goal/sessionGoal.d.ts +0 -8
  269. package/dist/core/goal/sessionGoal.js +0 -30
  270. package/dist/core/limits/byteBudgets.d.ts +0 -18
  271. package/dist/core/limits/byteBudgets.js +0 -18
  272. package/dist/core/limits/textBudgets.d.ts +0 -23
  273. package/dist/core/limits/textBudgets.js +0 -23
  274. package/dist/core/safety/bashClassifier.d.ts +0 -10
  275. package/dist/llm/lsp.d.ts +0 -129
  276. package/dist/llm/lsp.js +0 -307
  277. package/dist/ui/components/ErrorView.d.ts +0 -4
  278. package/dist/ui/components/ErrorView.js +0 -7
  279. package/dist/utils/yaml.d.ts +0 -2
  280. package/dist/utils/yaml.js +0 -8
  281. package/examples/skills/files/SKILL.md +0 -16
  282. package/examples/skills/files/examples/file-editing.md +0 -3
  283. /package/dist/core/{bashOutput → shellOutput}/command.d.ts +0 -0
  284. /package/dist/core/{bashOutput → shellOutput}/command.js +0 -0
  285. /package/dist/core/{bashOutput → shellOutput}/lineFilter.d.ts +0 -0
  286. /package/dist/core/{bashOutput → shellOutput}/reducers/content.d.ts +0 -0
  287. /package/dist/core/{bashOutput → shellOutput}/reducers/content.js +0 -0
  288. /package/dist/core/{bashOutput → shellOutput}/reducers/gh.d.ts +0 -0
  289. /package/dist/core/{bashOutput → shellOutput}/reducers/gh.js +0 -0
  290. /package/dist/core/{bashOutput → shellOutput}/reducers/git.d.ts +0 -0
  291. /package/dist/core/{bashOutput → shellOutput}/reducers/git.js +0 -0
  292. /package/dist/core/{bashOutput → shellOutput}/reducers/validation.d.ts +0 -0
  293. /package/dist/core/{bashOutput → shellOutput}/reducers/validation.js +0 -0
  294. /package/dist/core/{bashOutput → shellOutput}/types.js +0 -0
@@ -0,0 +1,377 @@
1
+ import { configuredProviders, findProvider, modelSelector, providerImageCapable } 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 { CHATGPT_CODEX_BASE_URL } from '../../llm/openaiCodexOAuth.js';
7
+ import { sessionActionSuggestions, sessionSuggestions } from './sessionPicker.js';
8
+ /**
9
+ * Wizard flow table (CR-006 successor): the single source of truth for every
10
+ * picker/wizard step. A step's kind, placeholder, suggestion list, and (for
11
+ * field-capture steps) its pure capture function all live in one entry, so
12
+ * adding a wizard step touches one table row — `chatModes.ts` derives the
13
+ * `Mode` union and the picker/masked/empty-submit classification from this
14
+ * table, and `chat/wizardDispatch.ts` drives the submits.
15
+ *
16
+ * Keep this module a leaf: it must not import the per-domain `*Wizard.ts`
17
+ * result modules or `chatModes.ts`, so the dependency graph stays acyclic
18
+ * (domain modules import the shared constants/helpers from here).
19
+ */
20
+ // ── Shared action/choice vocabulary ─────────────────────────────────────────
21
+ export const PROVIDER_CHOICES = {
22
+ addProvider: 'add provider',
23
+ custom: 'custom',
24
+ };
25
+ export const PROVIDER_ACTIONS = {
26
+ useProvider: 'use provider',
27
+ addModels: 'add models',
28
+ manageAccess: 'set API key',
29
+ signInChatGpt: 'sign in with ChatGPT',
30
+ markImageCapable: 'mark image-capable',
31
+ clearImageCapable: 'clear image-capable',
32
+ removeModels: 'remove models',
33
+ removeProvider: 'remove provider',
34
+ };
35
+ export const MODEL_CHOICES = {
36
+ addModels: 'add models',
37
+ enterModelNames: 'enter model names',
38
+ };
39
+ export const SERVER_CHOICES = {
40
+ addServer: 'add server',
41
+ custom: 'custom',
42
+ };
43
+ export const COMMON_ACTIONS = {
44
+ enable: 'enable',
45
+ disable: 'disable',
46
+ };
47
+ export const LSP_ACTIONS = {
48
+ removeServer: 'remove server',
49
+ };
50
+ export const MCP_ACTIONS = {
51
+ manageAccess: 'set API key',
52
+ removeServer: 'remove server',
53
+ };
54
+ export const MCP_TRANSPORTS = {
55
+ http: 'http',
56
+ sse: 'sse',
57
+ stdio: 'stdio',
58
+ };
59
+ export const SKILL_CHOICES = {
60
+ addSkill: 'add skill',
61
+ };
62
+ export const SKILL_ACTIONS = {
63
+ showInfo: 'show info',
64
+ validate: 'validate',
65
+ removeSkill: 'remove skill',
66
+ };
67
+ const YES_CONFIRMATION = 'yes';
68
+ // ── Input parsing helpers ───────────────────────────────────────────────────
69
+ export function commaList(value) {
70
+ return value.split(',').map(item => item.trim()).filter(Boolean);
71
+ }
72
+ export function commandParts(value) {
73
+ return value.trim().split(/\s+/).filter(Boolean);
74
+ }
75
+ export function isYesConfirmation(value) {
76
+ return value.trim().toLowerCase() === YES_CONFIRMATION;
77
+ }
78
+ export function isValidUrl(value) {
79
+ try {
80
+ new URL(value);
81
+ return true;
82
+ }
83
+ catch {
84
+ return false;
85
+ }
86
+ }
87
+ // ── Skill selection lookup (shared by suggestions and the skills wizard) ────
88
+ export function skillPickerValue(skill) {
89
+ return `${skill.name} · ${skill.source}`;
90
+ }
91
+ export function findSelectedSkill(skills, selection) {
92
+ if (!selection)
93
+ return undefined;
94
+ return skills.find(skill => skillPickerValue(skill) === selection)
95
+ ?? skills.find(skill => skill.name === selection);
96
+ }
97
+ export function captureProviderName(settings, value) {
98
+ const name = value.trim();
99
+ if (!name)
100
+ return { message: 'Provider name is required.' };
101
+ if (settings.providers?.some(provider => provider.name === name))
102
+ return { message: `Provider ${name} already exists. Choose a unique name.` };
103
+ return { nextMode: 'providerAddUrl', draft: { name }, systemMessage: 'OpenAI-compatible base URL? Example: https://openrouter.ai/api/v1 or http://localhost:1234/v1' };
104
+ }
105
+ export function captureLspName(settings, value) {
106
+ const name = value.trim();
107
+ if (!name)
108
+ return { message: 'LSP server name is required.' };
109
+ if (configuredLspServers(settings).some(server => server.name === name))
110
+ return { message: `LSP server ${name} already exists. Choose a unique name.` };
111
+ return { nextMode: 'lspAddCommand', draft: { name }, systemMessage: 'Command to run? Example: typescript-language-server --stdio' };
112
+ }
113
+ export function captureMcpName(settings, value) {
114
+ const name = value.trim();
115
+ if (!name)
116
+ return { message: 'MCP server name is required.' };
117
+ if (findMcpServer(settings, name))
118
+ return { message: `MCP server ${name} already exists. Choose a unique name.` };
119
+ return { nextMode: 'mcpAddTransport', draft: { name }, systemMessage: 'Transport type? http (Streamable HTTP), sse (Server-Sent Events), or stdio (local process).' };
120
+ }
121
+ export function captureProviderUrl(value) {
122
+ if (!isValidUrl(value))
123
+ return { message: 'Enter a valid URL, for example http://localhost:1234/v1.' };
124
+ // The Codex endpoint only accepts ChatGPT sign-in, never API keys; point
125
+ // users at the preset instead of a custom provider that cannot work (F-14).
126
+ const codexHint = value.trim() === CHATGPT_CODEX_BASE_URL
127
+ ? `\nNote: ${CHATGPT_CODEX_BASE_URL} serves ChatGPT sign-in only. To use it, add the OpenAI Subscription preset via /provider instead of a custom API-key provider.`
128
+ : '';
129
+ return { draft: { url: value.trim() }, nextMode: 'providerAddKey', systemMessage: `API key? Leave blank for local/keyless providers.${codexHint}` };
130
+ }
131
+ export function captureMcpUrl(value) {
132
+ if (!isValidUrl(value))
133
+ return { message: 'Enter a valid URL, for example https://mcp.context7.com/mcp.' };
134
+ 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>.' };
135
+ }
136
+ export function captureMcpTransport(value) {
137
+ const transport = value.trim().toLowerCase();
138
+ if (transport !== MCP_TRANSPORTS.http && transport !== MCP_TRANSPORTS.sse && transport !== MCP_TRANSPORTS.stdio)
139
+ return { message: 'Enter http, sse, or stdio.' };
140
+ if (transport === MCP_TRANSPORTS.stdio)
141
+ return { draft: { transport }, nextMode: 'mcpAddCommand', systemMessage: 'Command to run? Example: npx -y @modelcontextprotocol/server-filesystem .' };
142
+ return { draft: { transport }, nextMode: 'mcpAddUrl', systemMessage: `MCP server URL? Example: https://mcp.context7.com/mcp for ${transport}.` };
143
+ }
144
+ export function captureMcpCommand(value) {
145
+ const parts = commandParts(value);
146
+ if (parts.length === 0)
147
+ return { message: 'Command is required.' };
148
+ return { draft: { command: parts[0], args: parts.slice(1) }, nextMode: 'chat', systemMessage: 'Stdio MCP authentication must be handled by the command or wrapper; HTTP headers do not apply.' };
149
+ }
150
+ // ── Suggestion builders (pure; bound to steps in the table below) ───────────
151
+ export function providerSuggestions(settings) {
152
+ return [
153
+ ...configuredProviders(settings).map(provider => ({
154
+ value: provider.name,
155
+ description: `${provider.url} · ${provider.models.length} model${provider.models.length === 1 ? '' : 's'}`,
156
+ kind: 'provider',
157
+ })),
158
+ { value: PROVIDER_CHOICES.addProvider, description: 'Add a new provider (presets available)', kind: 'provider' },
159
+ ];
160
+ }
161
+ export function providerActionSuggestions(settings, selectedProviderName) {
162
+ const provider = selectedProviderName ? findProvider(settings, selectedProviderName) : undefined;
163
+ return [
164
+ { value: PROVIDER_ACTIONS.useProvider, description: 'Set this provider and choose a model', kind: 'provider' },
165
+ { value: PROVIDER_ACTIONS.addModels, description: provider?.kind === 'chatgpt-codex' ? 'Add a supported Codex model name' : 'Fetch the provider model list and add models', kind: 'provider' },
166
+ ...(provider?.kind === 'chatgpt-codex'
167
+ ? [{ value: PROVIDER_ACTIONS.signInChatGpt, description: 'Sign in again or switch ChatGPT account', kind: 'provider' }]
168
+ : [{ value: PROVIDER_ACTIONS.manageAccess, description: provider?.key ? 'Update the saved API key' : 'Add an API key', kind: 'provider' }]),
169
+ provider
170
+ ? (providerImageCapable(provider)
171
+ ? { value: PROVIDER_ACTIONS.clearImageCapable, description: 'Stop sending attached images to this provider', kind: 'provider' }
172
+ : { value: PROVIDER_ACTIONS.markImageCapable, description: 'Allow attached images to be sent to this provider', kind: 'provider' })
173
+ : { value: PROVIDER_ACTIONS.markImageCapable, description: 'Allow attached images to be sent to this provider', kind: 'provider' },
174
+ ...(provider?.models?.length ? [{ value: PROVIDER_ACTIONS.removeModels, description: 'Remove models from this provider', kind: 'provider' }] : []),
175
+ { value: PROVIDER_ACTIONS.removeProvider, description: 'Delete this provider from settings', kind: 'provider' },
176
+ ];
177
+ }
178
+ export function presetSuggestions() {
179
+ const cloudPresets = PROVIDER_PRESETS.filter(p => p.category === 'cloud');
180
+ const localPresets = PROVIDER_PRESETS.filter(p => p.category === 'local');
181
+ return [
182
+ ...cloudPresets.map(preset => ({
183
+ value: preset.id,
184
+ description: `${preset.baseUrl}${preset.auth === 'chatgpt-oauth' ? ' · browser sign-in' : ''}${preset.suggestedModels?.length ? ' · e.g. ' + preset.suggestedModels.slice(0, 2).join(', ') : ''}`,
185
+ kind: 'provider',
186
+ })),
187
+ ...localPresets.map(preset => ({
188
+ value: preset.id,
189
+ description: `${preset.baseUrl} · local, no API key needed`,
190
+ kind: 'provider',
191
+ })),
192
+ { value: PROVIDER_CHOICES.custom, description: 'Enter provider name, URL, and API key manually', kind: 'provider' },
193
+ ];
194
+ }
195
+ export function modelSuggestions(settings, modelProviderFilter) {
196
+ const providers = configuredProviders(settings).filter(provider => !modelProviderFilter || provider.name === modelProviderFilter);
197
+ return [
198
+ ...providers.flatMap(provider => provider.models.map(model => ({
199
+ value: modelProviderFilter ? model : modelSelector(provider, model),
200
+ description: provider.name,
201
+ kind: 'model',
202
+ }))),
203
+ { value: MODEL_CHOICES.addModels, description: modelProviderFilter ? `Add models to ${modelProviderFilter} (fetched from its models endpoint)` : 'Add models to a provider (fetched from its models endpoint)', kind: 'model' },
204
+ ];
205
+ }
206
+ export function modelAddProviderSuggestions(settings) {
207
+ return configuredProviders(settings).map(provider => ({
208
+ value: provider.name,
209
+ description: `${provider.models.length} model${provider.models.length === 1 ? '' : 's'} configured`,
210
+ kind: 'provider',
211
+ }));
212
+ }
213
+ /**
214
+ * Model picker fed by live /models discovery. Curated `suggestedModels`
215
+ * (from provider presets) are pinned atop the discovered list when the
216
+ * endpoint actually serves them — stale curation entries simply don't pin.
217
+ */
218
+ export function modelPickSuggestions(settings, providerName, discoveredModels, suggestedModels = []) {
219
+ const provider = providerName ? findProvider(settings, providerName) : undefined;
220
+ const configured = new Set(provider?.models ?? []);
221
+ const available = discoveredModels.filter(model => !configured.has(model));
222
+ const availableSet = new Set(available);
223
+ const pinned = suggestedModels.filter(model => availableSet.has(model));
224
+ const pinnedSet = new Set(pinned);
225
+ return [
226
+ ...pinned.map(model => ({
227
+ value: model,
228
+ description: 'suggested',
229
+ kind: 'model',
230
+ })),
231
+ ...available.filter(model => !pinnedSet.has(model)).map(model => ({
232
+ value: model,
233
+ description: providerName,
234
+ kind: 'model',
235
+ })),
236
+ { value: MODEL_CHOICES.enterModelNames, description: 'Type comma-separated model names instead', kind: 'model' },
237
+ ];
238
+ }
239
+ export function lspSuggestions(settings) {
240
+ const servers = configuredLspServers(settings);
241
+ return [{ value: SERVER_CHOICES.addServer, description: 'add an LSP server (presets available)', kind: 'lsp' },
242
+ ...servers.map(server => ({
243
+ value: server.name,
244
+ description: `${server.command}${(server.args ?? []).length ? ` ${(server.args ?? []).join(' ')}` : ''} · ${server.enabled === false ? 'disabled' : 'enabled'}`,
245
+ kind: 'lsp',
246
+ }))];
247
+ }
248
+ export function lspActionSuggestions(settings, selectedLspName) {
249
+ const server = selectedLspName ? configuredLspServers(settings).find(s => s.name === selectedLspName) : undefined;
250
+ const result = [];
251
+ if (server)
252
+ 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' });
253
+ result.push({ value: LSP_ACTIONS.removeServer, description: 'remove this server', kind: 'lsp' });
254
+ return result;
255
+ }
256
+ function lspPresetSuggestions() {
257
+ return [
258
+ ...Object.values(LSP_PRESETS).map(preset => ({
259
+ value: preset.name,
260
+ description: `${preset.command} ${(preset.args ?? []).join(' ')} [${(preset.extensions ?? []).join(', ')}]`,
261
+ kind: 'lsp',
262
+ })),
263
+ { value: SERVER_CHOICES.custom, description: 'enter a name and command manually', kind: 'lsp' },
264
+ ];
265
+ }
266
+ export function mcpSuggestions(settings) {
267
+ const servers = configuredMcpServers(settings);
268
+ return [{ value: SERVER_CHOICES.addServer, description: 'add an MCP server (presets available)', kind: 'mcp' },
269
+ ...servers.map(server => {
270
+ const location = server.url ?? (server.command ? `${server.command} ${(server.args ?? []).join(' ')}`.trim() : '');
271
+ return { value: server.name, description: `${server.transport}${location ? ` ${location}` : ''} · ${server.enabled === false ? 'disabled' : 'enabled'}`, kind: 'mcp' };
272
+ })];
273
+ }
274
+ export function mcpActionSuggestions(settings, selectedMcpName) {
275
+ const server = selectedMcpName ? findMcpServer(settings, selectedMcpName) : undefined;
276
+ const result = [];
277
+ if (server) {
278
+ 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' });
279
+ if (server.transport !== 'stdio')
280
+ result.push({ value: MCP_ACTIONS.manageAccess, description: server.headers?.length ? 'update the saved API key' : 'add an API key', kind: 'mcp' });
281
+ }
282
+ result.push({ value: MCP_ACTIONS.removeServer, description: 'remove this server', kind: 'mcp' });
283
+ return result;
284
+ }
285
+ function mcpPresetSuggestions() {
286
+ return [
287
+ ...presetIds().map(presetId => {
288
+ const preset = findMcpPreset(presetId);
289
+ return { value: presetId, description: preset.description ?? `${preset.transport} server`, kind: 'mcp' };
290
+ }),
291
+ { value: SERVER_CHOICES.custom, description: 'enter name, transport, and URL or command manually', kind: 'mcp' },
292
+ ];
293
+ }
294
+ export function mcpTransportSuggestions() {
295
+ return [
296
+ { value: MCP_TRANSPORTS.http, description: 'Streamable HTTP (remote)', kind: 'mcp' },
297
+ { value: MCP_TRANSPORTS.sse, description: 'Server-Sent Events (remote)', kind: 'mcp' },
298
+ { value: MCP_TRANSPORTS.stdio, description: 'local process', kind: 'mcp' },
299
+ ];
300
+ }
301
+ export function skillsSuggestions(settings, skills) {
302
+ return [{ value: SKILL_CHOICES.addSkill, description: 'describe a new skill for haze to generate', kind: 'skill' },
303
+ ...skills.map(skill => ({
304
+ value: skills.some(candidate => candidate !== skill && candidate.name === skill.name) ? skillPickerValue(skill) : skill.name,
305
+ description: `${skill.description} · ${skill.source}${isSkillEnabled(settings, skill.name, skill.source) ? '' : ' · disabled'}`,
306
+ kind: 'skill',
307
+ }))];
308
+ }
309
+ export function skillScopeSuggestions() {
310
+ return [
311
+ { value: 'this project', description: 'create .haze/skills/<name>/SKILL.md for this repository', kind: 'skill' },
312
+ { value: 'global', description: 'create ~/.haze/skills/<name>/SKILL.md for your user', kind: 'skill' },
313
+ ];
314
+ }
315
+ export function skillsActionSuggestions(settings, skills, selectedSkillName) {
316
+ const skill = findSelectedSkill(skills, selectedSkillName);
317
+ const result = [];
318
+ if (skill) {
319
+ const enabled = isSkillEnabled(settings, skill.name, skill.source);
320
+ result.push({ value: enabled ? COMMON_ACTIONS.disable : COMMON_ACTIONS.enable, description: `${enabled ? COMMON_ACTIONS.disable : COMMON_ACTIONS.enable} this skill`, kind: 'skill' });
321
+ result.push({ value: SKILL_ACTIONS.showInfo, description: 'show description, references, and path', kind: 'skill' });
322
+ result.push({ value: SKILL_ACTIONS.validate, description: 're-load and validate SKILL.md', kind: 'skill' });
323
+ }
324
+ result.push({ value: SKILL_ACTIONS.removeSkill, description: 'delete this skill directory', kind: 'skill' });
325
+ return result;
326
+ }
327
+ export const WIZARD_STEPS = [
328
+ // Sessions
329
+ { id: 'sessions', kind: 'pick', placeholder: 'Choose a saved session', suggestions: (s) => sessionSuggestions(s.sessions ?? []) },
330
+ { id: 'sessionAction', kind: 'pick', placeholder: 'Resume or fork this session', suggestions: () => sessionActionSuggestions() },
331
+ // Provider + model flows
332
+ { id: 'provider', kind: 'pick', placeholder: 'Choose provider', suggestions: (s) => providerSuggestions(s.settings) },
333
+ { id: 'providerAction', kind: 'pick', placeholder: 'Choose provider action', suggestions: (s) => providerActionSuggestions(s.settings, s.selectedProviderName) },
334
+ { id: 'providerAddPreset', kind: 'pick', placeholder: 'Choose a provider preset or custom', suggestions: () => presetSuggestions() },
335
+ { id: 'providerAddName', kind: 'input', placeholder: 'Provider name', suggestions: () => [] },
336
+ { id: 'providerAddUrl', kind: 'input', placeholder: 'https://example.com/v1', suggestions: () => [] },
337
+ { id: 'providerAddKey', kind: 'masked-input', placeholder: 'API key, or blank for local', optional: true, suggestions: () => [] },
338
+ { id: 'providerAddModels', kind: 'input', placeholder: 'model-a, model-b', suggestions: () => [] },
339
+ { id: 'providerAppendModels', kind: 'input', placeholder: 'model-a, model-b', suggestions: () => [] },
340
+ { id: 'providerSetKey', kind: 'masked-input', placeholder: 'API key', suggestions: () => [] },
341
+ { id: 'providerRemoveModels', kind: 'input', placeholder: 'model-a, model-b', suggestions: () => [] },
342
+ { id: 'providerConfirmRemove', kind: 'confirm', placeholder: 'Type "yes" to confirm', suggestions: () => [] },
343
+ { id: 'model', kind: 'pick', placeholder: 'Choose model, or add model', suggestions: (s) => modelSuggestions(s.settings, s.modelProviderFilter) },
344
+ { id: 'modelAddProvider', kind: 'pick', placeholder: 'Choose a provider to add models to', suggestions: (s) => modelAddProviderSuggestions(s.settings) },
345
+ { id: 'modelPick', kind: 'pick', placeholder: 'Choose a model to add', suggestions: (s) => modelPickSuggestions(s.settings, s.selectedProviderName ?? s.providerDraftName, s.discoveredModels ?? [], s.suggestedModels ?? []) },
346
+ // Skills
347
+ { id: 'skills', kind: 'pick', placeholder: 'Choose a skill or add skill', suggestions: (s) => skillsSuggestions(s.settings, s.skills) },
348
+ { id: 'skillsAction', kind: 'pick', placeholder: 'show info, enable, disable, validate, or remove', suggestions: (s) => skillsActionSuggestions(s.settings, s.skills, s.selectedSkillName) },
349
+ { id: 'skillsAddName', kind: 'input', placeholder: 'Skill name (kebab-case, e.g. security-review)', suggestions: () => [] },
350
+ { id: 'skillsAddScope', kind: 'pick', placeholder: 'Choose this project or global', suggestions: () => skillScopeSuggestions() },
351
+ { id: 'skillsAddDescription', kind: 'input', placeholder: 'Describe what the skill should do', suggestions: () => [] },
352
+ { id: 'skillsConfirmRemove', kind: 'confirm', placeholder: 'Type "yes" to confirm', suggestions: () => [] },
353
+ // LSP servers
354
+ { id: 'lsp', kind: 'pick', placeholder: 'Choose LSP server or add server', suggestions: (s) => lspSuggestions(s.settings) },
355
+ { id: 'lspAction', kind: 'pick', placeholder: 'enable, disable, or remove server', suggestions: (s) => lspActionSuggestions(s.settings, s.selectedLspName) },
356
+ { id: 'lspAddPreset', kind: 'pick', placeholder: 'Choose an LSP preset or custom', suggestions: () => lspPresetSuggestions() },
357
+ { id: 'lspAddName', kind: 'input', placeholder: 'LSP server name (e.g. typescript)', suggestions: () => [] },
358
+ { id: 'lspAddCommand', kind: 'input', placeholder: 'Command (e.g. typescript-language-server --stdio)', suggestions: () => [] },
359
+ { id: 'lspConfirmRemove', kind: 'confirm', placeholder: 'Type "yes" to confirm', suggestions: () => [] },
360
+ // MCP servers
361
+ { id: 'mcp', kind: 'pick', placeholder: 'Choose MCP server or add server', suggestions: (s) => mcpSuggestions(s.settings) },
362
+ { id: 'mcpAction', kind: 'pick', placeholder: 'enable, disable, remove, or set key', suggestions: (s) => mcpActionSuggestions(s.settings, s.selectedMcpName) },
363
+ { id: 'mcpAddPreset', kind: 'pick', placeholder: 'Choose an MCP preset or custom', suggestions: () => mcpPresetSuggestions() },
364
+ { id: 'mcpAddName', kind: 'input', placeholder: 'MCP server name (e.g. context7)', suggestions: () => [] },
365
+ { id: 'mcpAddTransport', kind: 'pick', placeholder: 'http, sse, or stdio', suggestions: () => mcpTransportSuggestions() },
366
+ { id: 'mcpAddUrl', kind: 'input', placeholder: 'https://mcp.example.com/mcp', suggestions: () => [] },
367
+ { id: 'mcpAddCommand', kind: 'input', placeholder: 'Command (e.g. npx -y @pkg/server)', suggestions: () => [] },
368
+ { id: 'mcpAddKey', kind: 'masked-input', placeholder: 'API key, or blank to skip', optional: true, suggestions: () => [] },
369
+ { id: 'mcpSetKey', kind: 'masked-input', placeholder: 'API key', suggestions: () => [] },
370
+ { id: 'mcpConfirmRemove', kind: 'confirm', placeholder: 'Type "yes" to confirm', suggestions: () => [] },
371
+ ];
372
+ const WIZARD_STEP_BY_ID = Object.fromEntries(WIZARD_STEPS.map(step => [step.id, step]));
373
+ /** Suggestions for a wizard mode, or undefined when the mode is not a wizard step ('chat'). */
374
+ export function wizardSuggestionsFor(mode, state) {
375
+ const step = WIZARD_STEP_BY_ID[mode];
376
+ return step ? step.suggestions(state) : undefined;
377
+ }
@@ -8,6 +8,8 @@ import { compactModelMessages } from '../core/agent/compaction.js';
8
8
  import { summarizeContextDiagnostics } from '../config/contextFiles.js';
9
9
  const reportSession = { start: new Date(0), cwd: process.cwd() };
10
10
  async function loadFiles(paths) {
11
+ // This developer-only report command intentionally accepts explicit host paths:
12
+ // it analyzes files selected by the local CLI user and never writes them.
11
13
  const candidates = paths.length > 0 ? paths : ['AGENTS.md', 'CLAUDE.md'];
12
14
  const files = [];
13
15
  for (const candidate of candidates) {
@@ -21,6 +23,7 @@ async function loadFiles(paths) {
21
23
  const args = process.argv.slice(2);
22
24
  const traceIndex = args.indexOf('--trace');
23
25
  if (traceIndex >= 0) {
26
+ // Trace fixtures are likewise explicit local-user input, not model-controlled paths.
24
27
  const tracePath = args[traceIndex + 1];
25
28
  if (!tracePath)
26
29
  throw new Error('--trace requires a JSON fixture path');
package/dist/cli/index.js CHANGED
@@ -1,28 +1,30 @@
1
1
  #!/usr/bin/env node
2
- import { readFileSync } from 'node:fs';
3
- import { fileURLToPath } from 'node:url';
4
- import { dirname, join } from 'node:path';
5
2
  import { Command, Option } from 'commander';
6
3
  import { chatCommand } from './commands/chat.js';
7
4
  import { runHeadless } from './commands/runCommand.js';
8
5
  import { installTerminalTitle, terminalTitleLabel } from './terminalTitle.js';
9
6
  import { findSession } from '../core/session/sessionStore.js';
10
7
  import { installBackgroundProcessSignalHandlers, teardownBackgroundProcesses } from '../core/process/backgroundRegistry.js';
11
- const __dirname = dirname(fileURLToPath(import.meta.url));
8
+ import { STDIN_PROMPT_BYTES } from '../core/limits.js';
9
+ import { readPackageVersion } from '../utils/version.js';
10
+ import { formatVersionVerbose, readBuildInfo } from '../utils/buildInfo.js';
11
+ import { runDoctor } from './commands/doctor.js';
12
12
  installBackgroundProcessSignalHandlers();
13
- const pkg = JSON.parse(readFileSync(join(__dirname, '..', '..', 'package.json'), 'utf8'));
13
+ const version = readPackageVersion() ?? '0.0.0';
14
14
  const program = new Command();
15
15
  program
16
16
  .name('haze')
17
17
  .description('A pragmatic, intentionally limited agentic CLI.')
18
- .version(pkg.version)
18
+ .option('-V, --version', 'print the haze version (add --verbose for build provenance: commit, runtime paths, capabilities)')
19
+ .option('--verbose', 'with --version: also print commit, runtime/executable paths, and the capability registry')
19
20
  .option('--debug', 'show model/tool debug logs and write a detailed JSONL log to ~/.haze/logs/')
20
21
  .option('-c, --continue', 'resume the latest saved session for this workspace')
21
22
  .addOption(new Option('--resume <id>', 'resume an exact saved session id for this workspace').conflicts(['continue', 'session']))
22
23
  .option('--no-session', 'run without saving or resuming a durable session')
23
24
  .option('-p, --prompt <text>', 'print mode: run a single non-interactive turn and print the result (falls back to piped stdin)')
24
25
  .option('-m, --model <selector>', 'override the model for this run only — a registered model name or provider:name')
25
- .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'));
26
+ .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'))
27
+ .option('--timeout <duration>', 'print-mode absolute turn deadline (e.g. 30s, 10m, 2h); bounds total elapsed time so a busy tool cannot run indefinitely');
26
28
  program.addHelpText('after', `
27
29
  Examples:
28
30
  $ haze start the interactive chat
@@ -37,33 +39,69 @@ Examples:
37
39
  Print mode (-p):
38
40
  Runs a single agentic turn with the full toolset and guardrails, prints the final assistant
39
41
  text, then exits (0 = complete; non-zero = aborted/failed, so CI can gate on the exit code).
40
- The prompt comes from -p, otherwise from piped stdin. With --output json the reply is wrapped
41
- in a single-line { type, status, result, usage } envelope. With --output stream-json haze streams
42
- one NDJSON agent event per line (turn_start, message_*, tool_*, retry, turn_end) as the run
43
- progresses, then prints that same { type:'result', ... } envelope as the final line — giving
44
- harnesses live progress and stagnation detection. --model overrides the model for this
42
+ The prompt comes from -p, otherwise from piped stdin. Piped prompts over 256 KiB are rejected;
43
+ pass a file path and ask haze to read it instead. With --output json the reply is wrapped in a
44
+ single-line { type, status, result, usage } envelope. With --output stream-json haze streams
45
+ one NDJSON agent event per line (turn_start, step_*, message_*, tool_*, retry, turn_end) as the
46
+ run progresses, then prints that same { type:'result', ... } envelope as the final line — giving
47
+ harnesses live progress, per-step usage, bounded tool-failure diagnostics, and stagnation
48
+ detection without raw tool inputs or outputs. --model overrides the model for this
45
49
  run only (no settings change) and must already be registered under a provider (add it once via
46
50
  the /provider picker). Print-mode runs are non-durable: --continue is ignored and no session is
47
- saved. --resume <id> loads saved context for the turn without changing that session. There is no
48
- automatic context-overflow recovery.
51
+ saved. --resume <id> loads saved context for the turn without changing that session. On a
52
+ provider context overflow, haze compacts the conversation and retries the request once; when
53
+ compaction is unavailable, the error says so explicitly.
49
54
  `);
50
55
  async function readStdinPrompt() {
51
56
  // Only read stdin when it is piped (non-TTY); never hang waiting on an interactive terminal.
52
- if (process.stdin.isTTY === false) {
53
- return new Promise((resolve) => {
57
+ if (!process.stdin.isTTY) {
58
+ return new Promise((resolve, reject) => {
54
59
  let data = '';
55
- process.stdin.setEncoding('utf8');
56
- process.stdin.on('data', (chunk) => {
60
+ let bytes = 0;
61
+ const cleanup = () => {
62
+ process.stdin.removeListener('data', onData);
63
+ process.stdin.removeListener('end', onEnd);
64
+ process.stdin.removeListener('error', onError);
65
+ };
66
+ const onData = (chunk) => {
67
+ bytes += Buffer.byteLength(chunk, 'utf8');
68
+ if (bytes > STDIN_PROMPT_BYTES) {
69
+ cleanup();
70
+ process.stdin.pause();
71
+ reject(new Error(`stdin prompt exceeds ${STDIN_PROMPT_BYTES} bytes; pass a file path and ask haze to read it instead.`));
72
+ return;
73
+ }
57
74
  data += chunk;
58
- });
59
- process.stdin.on('end', () => resolve(data.trim() ? data : undefined));
60
- process.stdin.on('error', () => resolve(undefined));
75
+ };
76
+ const onEnd = () => {
77
+ cleanup();
78
+ resolve(data.trim() ? data : undefined);
79
+ };
80
+ const onError = () => {
81
+ cleanup();
82
+ resolve(undefined);
83
+ };
84
+ process.stdin.setEncoding('utf8');
85
+ process.stdin.on('data', onData);
86
+ process.stdin.on('end', onEnd);
87
+ process.stdin.on('error', onError);
61
88
  });
62
89
  }
63
90
  return undefined;
64
91
  }
92
+ program.command('doctor')
93
+ .description('print runtime provenance (version, commit, executable/runtime paths), verify build integrity, and show the capability registry')
94
+ .action(async () => {
95
+ process.exitCode = await runDoctor();
96
+ });
65
97
  program.action(async () => {
66
98
  const opts = program.opts();
99
+ if (opts.version) {
100
+ // Handled here (not via commander's built-in .version()) so --verbose can
101
+ // enrich it and the bin launcher can answer without loading dist.
102
+ process.stdout.write(opts.verbose ? `${formatVersionVerbose()}\n` : `${version}\n`);
103
+ return;
104
+ }
67
105
  // Name the terminal tab for the run; no-op unless stdout is a real TTY.
68
106
  installTerminalTitle(terminalTitleLabel(process.cwd()));
69
107
  // -p takes precedence; otherwise fall back to piped stdin. An empty stdin yields no prompt.
@@ -81,14 +119,22 @@ program.action(async () => {
81
119
  // 'text' | 'json' | 'stream-json'; default to text for piped/stdin runs without the flag.
82
120
  output: opts.output === 'json' || opts.output === 'stream-json' ? opts.output : 'text',
83
121
  debug: Boolean(opts.debug),
122
+ timeout: opts.timeout,
84
123
  });
85
124
  // Set the exit code and return instead of process.exit(code): the latter does not wait
86
125
  // for stdout to drain and can truncate piped/redirected output (e.g. `haze -p ... | jq`).
87
126
  process.exitCode = code;
88
127
  return;
89
128
  }
90
- await chatCommand({ debug: Boolean(opts.debug), continueSession: Boolean(opts.continue), resumeSessionId: opts.resume, noSession: opts.session === false, version: pkg.version });
129
+ await chatCommand({ debug: Boolean(opts.debug), continueSession: Boolean(opts.continue), resumeSessionId: opts.resume, noSession: opts.session === false, version, build: sessionBuildProvenance() });
91
130
  });
131
+ /** Safe build provenance recorded into session headers (commit + build time only). */
132
+ function sessionBuildProvenance() {
133
+ const info = readBuildInfo();
134
+ if (!info?.commit && !info?.builtAt)
135
+ return undefined;
136
+ return { ...(info?.commit ? { commit: info.commit } : {}), ...(info?.builtAt ? { builtAt: info.builtAt } : {}) };
137
+ }
92
138
  program.parseAsync().catch(async (error) => {
93
139
  console.error(error instanceof Error ? error.message : error);
94
140
  await teardownBackgroundProcesses().catch(() => undefined);
@@ -11,7 +11,7 @@ function titleEscape(label) {
11
11
  }
12
12
  export function terminalTitleLabel(cwd) {
13
13
  // eslint-disable-next-line no-control-regex -- stripping control characters is the point here.
14
- const dir = basename(cwd).replace(/[\u0000-\u001F\u007F]/g, '').trim();
14
+ const dir = basename(cwd).replace(/[\u0000-\u001F\u007F-\u009F]/g, '').trim();
15
15
  return `haze${dir ? ` - ${dir}` : ''}`;
16
16
  }
17
17
  /**
@@ -4,6 +4,7 @@ import path from 'node:path';
4
4
  import crypto from 'node:crypto';
5
5
  import { HAZE_DIR } from './paths.js';
6
6
  import { readUtf8Prefix } from '../core/io/boundedRead.js';
7
+ import { assertRealPathInsideRoot } from '../utils/path.js';
7
8
  const DEFAULT_BUDGET_THRESHOLD = 0.15;
8
9
  function resolveBudgetThreshold(explicit) {
9
10
  if (typeof explicit === 'number' && Number.isFinite(explicit))
@@ -37,7 +38,7 @@ function displayPath(filePath) {
37
38
  return `~/${path.relative(home, filePath)}`;
38
39
  return filePath;
39
40
  }
40
- async function readContextCandidates(candidates, seen = new Set(), options = {}) {
41
+ async function readContextCandidates(candidates, seen = new Set(), options = {}, allowedRoot) {
41
42
  const contextFiles = [];
42
43
  for (const candidate of candidates) {
43
44
  const absolute = path.resolve(candidate);
@@ -49,13 +50,18 @@ async function readContextCandidates(candidates, seen = new Set(), options = {})
49
50
  const stat = await fs.stat(absolute).catch(() => null);
50
51
  if (!stat?.isFile())
51
52
  continue;
53
+ const readablePath = allowedRoot
54
+ ? await assertRealPathInsideRoot(allowedRoot, absolute, absolute, 'workspace').catch(() => undefined)
55
+ : absolute;
56
+ if (!readablePath)
57
+ continue;
52
58
  const displayedPath = displayPath(absolute);
53
59
  const signature = contextFileSignature(stat);
54
60
  const loadedSignature = options.alreadyLoadedSignatures?.get(displayedPath) ?? options.alreadyLoadedSignatures?.get(absolute);
55
61
  if (loadedSignature === signature)
56
62
  continue;
57
63
  options.onContextFileRead?.(displayedPath);
58
- const prefix = await readUtf8Prefix(absolute, MAX_CONTEXT_FILE_CHARS * 4);
64
+ const prefix = await readUtf8Prefix(readablePath, MAX_CONTEXT_FILE_CHARS * 4);
59
65
  const content = prefix.content.slice(0, MAX_CONTEXT_FILE_CHARS);
60
66
  const truncated = prefix.truncated || prefix.content.length > MAX_CONTEXT_FILE_CHARS;
61
67
  const file = {
@@ -112,7 +118,7 @@ export async function readScopedContextFilesForPath(targetPath, options = {}) {
112
118
  alreadySeen.add(path.resolve(cwd, loadedPath));
113
119
  }
114
120
  }
115
- return await readContextCandidates(candidates, alreadySeen, options);
121
+ return await readContextCandidates(candidates, alreadySeen, options, cwd);
116
122
  }
117
123
  export function contextFileDiagnostics(files) {
118
124
  return files.map(file => ({
@@ -1,4 +1,3 @@
1
- export declare const INPUT_HISTORY_FILE: string;
2
1
  export declare function readInputHistory(file?: string): Promise<string[]>;
3
2
  export declare function writeInputHistory(history: string[], file?: string): Promise<void>;
4
3
  export declare function addInputHistoryItem(item: string, file?: string): Promise<string[]>;
@@ -3,7 +3,7 @@ import path from 'node:path';
3
3
  import { HAZE_DIR } from './paths.js';
4
4
  import { tightenPrivateFile, writePrivateJsonAtomic } from './privateStorage.js';
5
5
  const HISTORY_DIR = path.join(HAZE_DIR, 'history');
6
- export const INPUT_HISTORY_FILE = path.join(HISTORY_DIR, 'input-history.json');
6
+ const INPUT_HISTORY_FILE = path.join(HISTORY_DIR, 'input-history.json');
7
7
  const MAX_HISTORY_ITEMS = 500;
8
8
  function normalizeHistory(value) {
9
9
  if (!Array.isArray(value))