@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
@@ -25,7 +25,9 @@ function normalizeProvider(provider, fallbackModel) {
25
25
  name,
26
26
  url,
27
27
  ...(key ? { key } : {}),
28
+ ...(provider.kind ? { kind: provider.kind } : {}),
28
29
  ...(capabilities ? { capabilities } : {}),
30
+ ...(provider.modelLimits ? { modelLimits: provider.modelLimits } : {}),
29
31
  models: normalizeModels(provider.models, fallbackModel),
30
32
  };
31
33
  }
@@ -1,8 +1,18 @@
1
+ import { z } from 'zod';
2
+ /** Optional, explicitly user-controlled reasoning depth (provider/protocol gated). */
3
+ export type ReasoningLevel = 'low' | 'medium' | 'high';
4
+ export declare const reasoningLevelSchema: z.ZodEnum<{
5
+ high: "high";
6
+ medium: "medium";
7
+ low: "low";
8
+ }>;
1
9
  export interface HazeProviderSettings {
2
10
  name: string;
3
11
  url: string;
4
12
  key?: string;
5
13
  models: string[];
14
+ /** Explicit runtime/auth protocol. Omitted means a normal OpenAI-compatible endpoint. */
15
+ kind?: 'openai-compatible' | 'chatgpt-codex';
6
16
  /**
7
17
  * Explicit endpoint capabilities. Never inferred: images are only sent to
8
18
  * providers the user marked image-capable (F03).
@@ -10,6 +20,15 @@ export interface HazeProviderSettings {
10
20
  capabilities?: {
11
21
  images?: boolean;
12
22
  };
23
+ /**
24
+ * Optional per-model capacity metadata used for request budgeting (RH-005).
25
+ * Absent entries fall back to a conservative default window. Preserved as
26
+ * passthrough so unknown metadata is not dropped.
27
+ */
28
+ modelLimits?: Record<string, {
29
+ contextWindowTokens?: number;
30
+ maxOutputTokens?: number;
31
+ }>;
13
32
  }
14
33
  export interface HazeLspServerSettings {
15
34
  name: string;
@@ -58,6 +77,30 @@ export interface HazeSettings {
58
77
  mcpServers?: HazeMcpServer[];
59
78
  skills?: HazeSkillSetting[];
60
79
  subagents?: HazeSubagentSettings;
80
+ /** Optional reasoning depth; unset by default, mapped by supported provider protocol. */
81
+ reasoning?: ReasoningLevel;
82
+ /**
83
+ * Context-window fallback for models without `modelLimits` metadata, in
84
+ * tokens. Unset means the built-in default (128K hosted / 32K local —
85
+ * see `contextBudget.ts`). The local variant applies to localhost inference
86
+ * servers, whose effective window is server-configured and silently truncated.
87
+ */
88
+ contextWindowFallbackTokens?: number;
89
+ localContextWindowFallbackTokens?: number;
90
+ /**
91
+ * Size of the shared bounded model-retry pool for transient model errors and
92
+ * idle-stream stalls, per turn. Unset means the built-in default of 2. Raise
93
+ * it for providers that terminate long streams aggressively (e.g. some
94
+ * OpenAI-compatible gateways); 0 disables automatic retries.
95
+ */
96
+ modelRetries?: number;
97
+ /**
98
+ * Manual `/compact` mode (F-09): `llm-summary` (default) asks the active
99
+ * model to summarize the older history; `heuristic` keeps the bounded
100
+ * excerpt without a model call. Automatic mid-turn compaction is always
101
+ * heuristic.
102
+ */
103
+ manualCompaction?: 'llm-summary' | 'heuristic';
61
104
  /** UI tweaks: rotating tips under the busy label, etc. Default enabled. */
62
105
  tips?: {
63
106
  enabled?: boolean;
@@ -4,6 +4,7 @@ import { z } from 'zod';
4
4
  import { HAZE_DIR } from './paths.js';
5
5
  import { tightenPrivateFile, writePrivateJsonAtomic } from './privateStorage.js';
6
6
  import { customProfileSchema } from '../core/subagent/executionProfiles.js';
7
+ export const reasoningLevelSchema = z.enum(['low', 'medium', 'high']);
7
8
  export const SETTINGS_FILE = path.join(HAZE_DIR, 'settings.json');
8
9
  const providerCapabilitiesSchema = z.object({
9
10
  images: z.boolean().optional(),
@@ -13,7 +14,9 @@ const providerSchema = z.object({
13
14
  url: z.string(),
14
15
  key: z.string().optional(),
15
16
  models: z.array(z.string()),
17
+ kind: z.enum(['openai-compatible', 'chatgpt-codex']).optional(),
16
18
  capabilities: providerCapabilitiesSchema.optional(),
19
+ modelLimits: z.record(z.string(), z.object({ contextWindowTokens: z.number().int().positive(), maxOutputTokens: z.number().int().positive() }).partial()).optional(),
17
20
  }).passthrough();
18
21
  const lspServerSchema = z.object({
19
22
  name: z.string(),
@@ -39,6 +42,10 @@ const subagentSettingsSchema = z.object({
39
42
  defaultProfile: z.string().trim().min(1).optional(),
40
43
  profiles: z.record(z.string().min(1), customProfileSchema).optional(),
41
44
  }).passthrough();
45
+ /** Fallback windows must be plausible positive token counts (not fractions/junk). */
46
+ const contextWindowFallbackSchema = z.number().int().min(1_000).max(10_000_000);
47
+ /** Retry-pool size must be a small non-negative count (0 disables retries). */
48
+ const modelRetriesSchema = z.number().int().min(0).max(10);
42
49
  const settingsSchema = z.object({
43
50
  provider: z.string().optional(),
44
51
  model: z.string().optional(),
@@ -47,6 +54,11 @@ const settingsSchema = z.object({
47
54
  mcpServers: z.array(mcpServerSchema).optional(),
48
55
  skills: z.array(skillSettingSchema).optional(),
49
56
  subagents: subagentSettingsSchema.optional(),
57
+ reasoning: reasoningLevelSchema.optional(),
58
+ contextWindowFallbackTokens: contextWindowFallbackSchema.optional(),
59
+ localContextWindowFallbackTokens: contextWindowFallbackSchema.optional(),
60
+ modelRetries: modelRetriesSchema.optional(),
61
+ manualCompaction: z.enum(['llm-summary', 'heuristic']).optional(),
50
62
  tips: z.object({ enabled: z.boolean().optional() }).optional(),
51
63
  apiKey: z.string().optional(),
52
64
  baseURL: z.string().optional(),
@@ -16,18 +16,18 @@ export function configuredSkillSettings(settings) {
16
16
  function settingScope(entry) {
17
17
  return entry.scope ?? 'global';
18
18
  }
19
- function matches(entry, name, scope) {
19
+ function isSameSkillSetting(entry, name, scope) {
20
20
  return entry.name === name && settingScope(entry) === scope;
21
21
  }
22
22
  /** A skill is enabled unless an explicit scope-aware override disables it. */
23
23
  export function isSkillEnabled(settings, name, scope = 'global') {
24
- const entry = configuredSkillSettings(settings).find(candidate => matches(candidate, name, scope));
24
+ const entry = configuredSkillSettings(settings).find(candidate => isSameSkillSetting(candidate, name, scope));
25
25
  return entry ? entry.enabled !== false : true;
26
26
  }
27
27
  export function setSkillEnabled(settings, name, enabled, scope = 'global') {
28
- const others = configuredSkillSettings(settings).filter(entry => !matches(entry, name, scope));
28
+ const others = configuredSkillSettings(settings).filter(entry => !isSameSkillSetting(entry, name, scope));
29
29
  return enabled ? others : [...others, { name, ...(scope === 'project' ? { scope } : {}), enabled: false }];
30
30
  }
31
31
  export function removeSkillSetting(settings, name, scope = 'global') {
32
- return configuredSkillSettings(settings).filter(entry => !matches(entry, name, scope));
32
+ return configuredSkillSettings(settings).filter(entry => !isSameSkillSetting(entry, name, scope));
33
33
  }
@@ -1,4 +1,3 @@
1
- export declare const UPDATE_CHECK_FILE: string;
2
1
  export interface UpdateCheckResult {
3
2
  latestVersion: string;
4
3
  isOutdated: boolean;
@@ -6,7 +6,7 @@ import { HAZE_DIR } from './paths.js';
6
6
  import { isNewer } from '../utils/version.js';
7
7
  import { tightenPrivateFile, writePrivateJsonAtomic } from './privateStorage.js';
8
8
  const execFile = promisify(execFileCallback);
9
- export const UPDATE_CHECK_FILE = path.join(HAZE_DIR, 'updateCheck.json');
9
+ const UPDATE_CHECK_FILE = path.join(HAZE_DIR, 'updateCheck.json');
10
10
  const DEFAULT_INTERVAL_MS = 24 * 60 * 60 * 1000; // 24h
11
11
  const DEFAULT_TIMEOUT_MS = 5000;
12
12
  async function defaultExecVersion(packageName, options) {
@@ -1,9 +1,19 @@
1
+ import type { ToolSet } from 'ai';
1
2
  export declare const DEFAULT_MAX_OUTPUT_TOKENS = 16384;
3
+ /** Keep generated file payloads comfortably below a model's output-token ceiling. */
4
+ export declare const WRITE_FILE_CHUNK_BYTES: number;
2
5
  export declare const IDLE_TIMEOUT_MS: number;
6
+ /** Default per-tool execution deadline; an uncooperative tool cannot defer the turn indefinitely (RH-004). */
7
+ export declare const DEFAULT_TOOL_DEADLINE_MS: number;
8
+ /** Subagents legitimately run long; give their wrapper a larger deadline. */
9
+ export declare const SUBAGENT_TOOL_DEADLINE_MS: number;
10
+ /** Absolute main-turn deadline: no single turn runs longer than this by default. */
11
+ export declare const DEFAULT_TURN_DEADLINE_MS: number;
12
+ /** Maximum accepted explicit `--timeout` value (24 hours). */
13
+ export declare const MAX_TURN_DEADLINE_MS: number;
3
14
  export declare const MAIN_STEP_LIMIT = 64;
4
15
  export declare const MAIN_TOOL_CALL_LIMIT = 120;
5
16
  export declare const MAIN_TOOL_ONLY_STEP_LIMIT = 24;
6
- export declare const ACTIVE_CONTEXT_TOKEN_BUDGET = 40000;
7
17
  export declare const BACKGROUND_PROCESS_MAX_CONCURRENCY = 5;
8
18
  export declare const BACKGROUND_PROCESS_HISTORY_LIMIT = 20;
9
19
  export declare const SUBAGENT_OBJECTIVE_CHARS = 4000;
@@ -30,3 +40,65 @@ export declare const SUBAGENT_MIN_DEADLINE_MS = 1000;
30
40
  export declare const SUBAGENT_MAX_DEADLINE_MS: number;
31
41
  export declare const SUBAGENT_MAX_CONCURRENCY = 10;
32
42
  export declare const SUBAGENT_MAX_RETRIES = 5;
43
+ /** Default size of the shared bounded model-retry pool for transient model errors and idle-stream stalls, per turn. Configurable via the `modelRetries` setting (0 disables automatic retries). */
44
+ export declare const DEFAULT_MODEL_RETRIES = 2;
45
+ /** Upper bound accepted for the `modelRetries` setting (mirrors the settings schema). */
46
+ export declare const MAX_MODEL_RETRIES_SETTING = 10;
47
+ export interface TurnBudget {
48
+ /** Maximum completed model steps across the whole turn (incl. recovery). */
49
+ stepLimit: number;
50
+ /** Maximum completed tool calls across the whole turn (incl. recovery). */
51
+ toolCallLimit: number;
52
+ /** Maximum completed tool-only steps across the whole turn. */
53
+ toolOnlyStepLimit: number;
54
+ }
55
+ export declare function mainTurnBudget(): TurnBudget;
56
+ /** Steps still available to the turn given usage so far (never negative). */
57
+ export declare function remainingSteps(used: number, budget: TurnBudget): number;
58
+ /** Tool calls still available to the turn given usage so far (never negative). */
59
+ export declare function remainingToolCalls(used: number, budget: TurnBudget): number;
60
+ /** True when adding `extra` tool calls would meet or exceed the call budget. */
61
+ export declare function wouldExceedToolCalls(used: number, extra: number, budget: TurnBudget): boolean;
62
+ /** A recovery slice can only run if at least one step and one tool call remain. */
63
+ export declare function hasUsableBudget(used: {
64
+ steps: number;
65
+ toolCalls: number;
66
+ }, budget: TurnBudget): boolean;
67
+ /** Clamp a requested slice size to what the turn budget actually allows. */
68
+ export declare function clampSlice(requested: {
69
+ steps: number;
70
+ toolCalls: number;
71
+ }, remaining: {
72
+ steps: number;
73
+ toolCalls: number;
74
+ }): {
75
+ steps: number;
76
+ toolCalls: number;
77
+ };
78
+ export interface ToolExecutionBudgetState {
79
+ /** Number of underlying executions that have actually started. */
80
+ started: number;
81
+ /** Set once a call was blocked so callers can force synthesis. */
82
+ exceeded: boolean;
83
+ }
84
+ export declare function createToolExecutionBudget(): ToolExecutionBudgetState;
85
+ /** True when a tool result is the structured "budget blocked" placeholder. */
86
+ export declare function isToolBudgetBlocked(output: unknown): boolean;
87
+ export interface BudgetLimit {
88
+ state: ToolExecutionBudgetState;
89
+ limit: number;
90
+ }
91
+ /**
92
+ * Wrap a tool set so each underlying `execute` checks-and-increments one or more
93
+ * shared budgets synchronously at the actual execution boundary. A model-emitted
94
+ * parallel batch enters `execute` sequentially on the JS event loop, so no more
95
+ * than the remaining budget can reach an underlying implementation even within
96
+ * one batch (RH-003). Revisit if the AI SDK ever yields between queueing a batch
97
+ * and invoking execute.
98
+ *
99
+ * When any supplied limit is exhausted the call is blocked: every limit is
100
+ * marked exceeded, no underlying call runs, and a structured bounded failure is
101
+ * returned so the SDK completes the step and the next prepareStep forces
102
+ * text-only synthesis.
103
+ */
104
+ export declare function withToolExecutionBudget(tools: ToolSet, ...limits: BudgetLimit[]): ToolSet;
@@ -1,9 +1,18 @@
1
1
  export const DEFAULT_MAX_OUTPUT_TOKENS = 16384;
2
+ /** Keep generated file payloads comfortably below a model's output-token ceiling. */
3
+ export const WRITE_FILE_CHUNK_BYTES = 16 * 1024;
2
4
  export const IDLE_TIMEOUT_MS = 5 * 60_000;
5
+ /** Default per-tool execution deadline; an uncooperative tool cannot defer the turn indefinitely (RH-004). */
6
+ export const DEFAULT_TOOL_DEADLINE_MS = 10 * 60_000;
7
+ /** Subagents legitimately run long; give their wrapper a larger deadline. */
8
+ export const SUBAGENT_TOOL_DEADLINE_MS = 20 * 60_000;
9
+ /** Absolute main-turn deadline: no single turn runs longer than this by default. */
10
+ export const DEFAULT_TURN_DEADLINE_MS = 30 * 60_000;
11
+ /** Maximum accepted explicit `--timeout` value (24 hours). */
12
+ export const MAX_TURN_DEADLINE_MS = 24 * 60 * 60_000;
3
13
  export const MAIN_STEP_LIMIT = 64;
4
14
  export const MAIN_TOOL_CALL_LIMIT = 120;
5
15
  export const MAIN_TOOL_ONLY_STEP_LIMIT = 24;
6
- export const ACTIVE_CONTEXT_TOKEN_BUDGET = 40_000;
7
16
  export const BACKGROUND_PROCESS_MAX_CONCURRENCY = 5;
8
17
  export const BACKGROUND_PROCESS_HISTORY_LIMIT = 20;
9
18
  // Disposable worker/task-capsule limits. Keep these centralized so model-facing
@@ -38,3 +47,87 @@ export const SUBAGENT_MIN_DEADLINE_MS = 1_000;
38
47
  export const SUBAGENT_MAX_DEADLINE_MS = 30 * 60_000;
39
48
  export const SUBAGENT_MAX_CONCURRENCY = 10;
40
49
  export const SUBAGENT_MAX_RETRIES = 5;
50
+ /** Default size of the shared bounded model-retry pool for transient model errors and idle-stream stalls, per turn. Configurable via the `modelRetries` setting (0 disables automatic retries). */
51
+ export const DEFAULT_MODEL_RETRIES = 2;
52
+ /** Upper bound accepted for the `modelRetries` setting (mirrors the settings schema). */
53
+ export const MAX_MODEL_RETRIES_SETTING = 10;
54
+ export function mainTurnBudget() {
55
+ return { stepLimit: MAIN_STEP_LIMIT, toolCallLimit: MAIN_TOOL_CALL_LIMIT, toolOnlyStepLimit: MAIN_TOOL_ONLY_STEP_LIMIT };
56
+ }
57
+ /** Steps still available to the turn given usage so far (never negative). */
58
+ export function remainingSteps(used, budget) {
59
+ return Math.max(0, budget.stepLimit - used);
60
+ }
61
+ /** Tool calls still available to the turn given usage so far (never negative). */
62
+ export function remainingToolCalls(used, budget) {
63
+ return Math.max(0, budget.toolCallLimit - used);
64
+ }
65
+ /** True when adding `extra` tool calls would meet or exceed the call budget. */
66
+ export function wouldExceedToolCalls(used, extra, budget) {
67
+ return used + extra >= budget.toolCallLimit;
68
+ }
69
+ /** A recovery slice can only run if at least one step and one tool call remain. */
70
+ export function hasUsableBudget(used, budget) {
71
+ return used.steps < budget.stepLimit && used.toolCalls < budget.toolCallLimit;
72
+ }
73
+ /** Clamp a requested slice size to what the turn budget actually allows. */
74
+ export function clampSlice(requested, remaining) {
75
+ return {
76
+ steps: Math.max(0, Math.min(requested.steps, remaining.steps)),
77
+ toolCalls: Math.max(0, Math.min(requested.toolCalls, remaining.toolCalls)),
78
+ };
79
+ }
80
+ // ── Tool execution-boundary budget ──────────────────────────────────────────
81
+ /**
82
+ * Marker placed on a structured tool result when the execution-boundary budget
83
+ * blocked the call. The underlying implementation never ran, so callers (goal
84
+ * observers, telemetry) must not treat it as a real tool failure with side
85
+ * effects (RH-003).
86
+ */
87
+ const TOOL_BUDGET_BLOCKED = '__hazeToolBudgetBlocked';
88
+ export function createToolExecutionBudget() {
89
+ return { started: 0, exceeded: false };
90
+ }
91
+ /** True when a tool result is the structured "budget blocked" placeholder. */
92
+ export function isToolBudgetBlocked(output) {
93
+ return typeof output === 'object' && output !== null && TOOL_BUDGET_BLOCKED in output;
94
+ }
95
+ /**
96
+ * Wrap a tool set so each underlying `execute` checks-and-increments one or more
97
+ * shared budgets synchronously at the actual execution boundary. A model-emitted
98
+ * parallel batch enters `execute` sequentially on the JS event loop, so no more
99
+ * than the remaining budget can reach an underlying implementation even within
100
+ * one batch (RH-003). Revisit if the AI SDK ever yields between queueing a batch
101
+ * and invoking execute.
102
+ *
103
+ * When any supplied limit is exhausted the call is blocked: every limit is
104
+ * marked exceeded, no underlying call runs, and a structured bounded failure is
105
+ * returned so the SDK completes the step and the next prepareStep forces
106
+ * text-only synthesis.
107
+ */
108
+ export function withToolExecutionBudget(tools, ...limits) {
109
+ return Object.fromEntries(Object.entries(tools).map(([name, definition]) => {
110
+ if (typeof definition.execute !== 'function')
111
+ return [name, definition];
112
+ const execute = definition.execute;
113
+ return [name, {
114
+ ...definition,
115
+ // Async so the wrapper always returns a thenable — outer wrappers (e.g.
116
+ // the tool deadline) assume `execute` yields a promise — while the
117
+ // check-and-increment below still runs synchronously at call time, so a
118
+ // model-emitted parallel batch cannot overshoot on the event loop.
119
+ execute: async (...args) => {
120
+ for (const { state, limit } of limits) {
121
+ if (state.started >= limit) {
122
+ for (const entry of limits)
123
+ entry.state.exceeded = true;
124
+ return { ok: false, [TOOL_BUDGET_BLOCKED]: true, error: 'Tool-call budget exhausted; execution was blocked before the underlying tool ran.' };
125
+ }
126
+ }
127
+ for (const { state } of limits)
128
+ state.started++;
129
+ return execute(...args);
130
+ },
131
+ }];
132
+ }));
133
+ }
@@ -7,6 +7,21 @@ export interface CompactionResult {
7
7
  keptCount: number;
8
8
  summary?: string;
9
9
  }
10
+ export interface CompactionSplit {
11
+ older: ModelMessage[];
12
+ recent: ModelMessage[];
13
+ }
14
+ /**
15
+ * Decide which trailing messages survive compaction and which are folded into
16
+ * the summary. Returns undefined when there is nothing older to compact (the
17
+ * whole history is recent, or the recent window reaches back past the first
18
+ * message once trailing tool messages are reattached to their calls).
19
+ * Shared by the heuristic and the LLM-summarized paths (F-09).
20
+ */
21
+ export declare function splitForCompaction(messages: ModelMessage[], options?: {
22
+ keepRecentMessages?: number;
23
+ tokenBudget?: number;
24
+ }): CompactionSplit | undefined;
10
25
  export declare function modelMessageText(message: ModelMessage): string;
11
26
  export declare function compactModelMessages(messages: ModelMessage[], options?: {
12
27
  keepRecentMessages?: number;
@@ -14,3 +29,26 @@ export declare function compactModelMessages(messages: ModelMessage[], options?:
14
29
  instructions?: string;
15
30
  workState?: WorkState;
16
31
  }): CompactionResult;
32
+ /**
33
+ * Build the summarization request for the LLM-summarized compaction path
34
+ * (F-09). The transcript is the older half, bounded to a character budget and
35
+ * truncated from the front (the oldest context is the least valuable) so the
36
+ * request itself can never overflow the model.
37
+ */
38
+ export declare function buildLlmCompactionPrompt(input: {
39
+ older: ModelMessage[];
40
+ instructions?: string;
41
+ maxChars?: number;
42
+ }): string;
43
+ /**
44
+ * Assemble the compacted history around a model-written summary (F-09). Same
45
+ * split rules as the heuristic path; the excerpt is replaced by the summary
46
+ * text the model produced.
47
+ */
48
+ export declare function compactModelMessagesWithSummary(messages: ModelMessage[], options: {
49
+ summaryText: string;
50
+ keepRecentMessages?: number;
51
+ tokenBudget?: number;
52
+ instructions?: string;
53
+ workState?: WorkState;
54
+ }): CompactionResult;
@@ -1,38 +1,49 @@
1
- import { estimateValueTokens } from './contextBudget.js';
1
+ import { estimateModelMessageTokens } from './contextBudget.js';
2
2
  import { workStatePrompt } from './workState.js';
3
- import { COMPACTION_OLDER_CHARS } from '../limits/textBudgets.js';
4
- export function modelMessageText(message) {
5
- const content = message.content;
6
- if (typeof content === 'string')
7
- return content;
8
- if (!Array.isArray(content))
9
- return '';
10
- return content.map(part => typeof part === 'object' && part != null && 'text' in part && typeof part.text === 'string' ? part.text : '').filter(Boolean).join('\n');
11
- }
12
- export function compactModelMessages(messages, options = {}) {
3
+ import { COMPACTION_LLM_TRANSCRIPT_CHARS, COMPACTION_OLDER_CHARS } from '../limits.js';
4
+ /**
5
+ * Decide which trailing messages survive compaction and which are folded into
6
+ * the summary. Returns undefined when there is nothing older to compact (the
7
+ * whole history is recent, or the recent window reaches back past the first
8
+ * message once trailing tool messages are reattached to their calls).
9
+ * Shared by the heuristic and the LLM-summarized paths (F-09).
10
+ */
11
+ export function splitForCompaction(messages, options = {}) {
13
12
  const maxRecentMessages = Math.min(options.keepRecentMessages ?? 12, messages.length);
14
13
  let keepRecentMessages = maxRecentMessages;
15
14
  if (options.tokenBudget != null) {
16
15
  let recentTokens = 0;
17
16
  keepRecentMessages = 0;
18
17
  for (let index = messages.length - 1; index >= 0 && keepRecentMessages < maxRecentMessages; index--) {
19
- const tokens = estimateValueTokens(messages[index]);
18
+ const tokens = estimateModelMessageTokens(messages[index]);
20
19
  if (keepRecentMessages > 0 && recentTokens + tokens > options.tokenBudget)
21
20
  break;
22
21
  recentTokens += tokens;
23
22
  keepRecentMessages += 1;
24
23
  }
25
24
  }
26
- if (messages.length <= keepRecentMessages) {
27
- return { compacted: false, messages, olderCount: 0, keptCount: messages.length };
28
- }
25
+ if (messages.length <= keepRecentMessages)
26
+ return undefined;
29
27
  let recentStart = messages.length - keepRecentMessages;
30
28
  while (recentStart > 0 && messages[recentStart]?.role === 'tool')
31
29
  recentStart -= 1;
32
30
  if (recentStart === 0)
31
+ return undefined;
32
+ return { older: messages.slice(0, recentStart), recent: messages.slice(recentStart) };
33
+ }
34
+ export function modelMessageText(message) {
35
+ const content = message.content;
36
+ if (typeof content === 'string')
37
+ return content;
38
+ if (!Array.isArray(content))
39
+ return '';
40
+ return content.map(part => typeof part === 'object' && part != null && 'text' in part && typeof part.text === 'string' ? part.text : '').filter(Boolean).join('\n');
41
+ }
42
+ export function compactModelMessages(messages, options = {}) {
43
+ const split = splitForCompaction(messages, options);
44
+ if (!split)
33
45
  return { compacted: false, messages, olderCount: 0, keptCount: messages.length };
34
- const older = messages.slice(0, recentStart);
35
- const recent = messages.slice(recentStart);
46
+ const { older, recent } = split;
36
47
  const olderEntries = older.map(message => {
37
48
  const text = modelMessageText(message).replace(/\s+/g, ' ').trim();
38
49
  return text ? `- ${message.role}: ${text}` : '';
@@ -68,3 +79,67 @@ export function compactModelMessages(messages, options = {}) {
68
79
  summary,
69
80
  };
70
81
  }
82
+ /**
83
+ * Build the summarization request for the LLM-summarized compaction path
84
+ * (F-09). The transcript is the older half, bounded to a character budget and
85
+ * truncated from the front (the oldest context is the least valuable) so the
86
+ * request itself can never overflow the model.
87
+ */
88
+ export function buildLlmCompactionPrompt(input) {
89
+ const maxChars = input.maxChars ?? COMPACTION_LLM_TRANSCRIPT_CHARS;
90
+ const entries = input.older.map(message => {
91
+ const text = modelMessageText(message).replace(/\s+/g, ' ').trim();
92
+ return text ? `- ${message.role}: ${text}` : '';
93
+ }).filter(Boolean);
94
+ // Keep the most recent entries within the bound; drop whole oldest entries
95
+ // first, then hard-trim whatever single entry still exceeds the budget.
96
+ const kept = [];
97
+ let total = 0;
98
+ for (let index = entries.length - 1; index >= 0; index--) {
99
+ const entry = entries[index];
100
+ if (total + entry.length + 1 > maxChars && kept.length > 0)
101
+ break;
102
+ kept.unshift(entry);
103
+ total += entry.length + 1;
104
+ }
105
+ if (kept.length === 1 && kept[0].length > maxChars)
106
+ kept[0] = `${kept[0].slice(kept[0].length - maxChars)}…`;
107
+ const omitted = entries.length - kept.length;
108
+ return [
109
+ 'Summarize the following older conversation history for continuity. The summary replaces the history in a coding agent context.',
110
+ 'Preserve: current user goal and success condition; explicit user constraints, preferences, and decisions; files created/changed/read; validation commands and their pass/fail results; blockers or pending decisions; the exact next action if work was unfinished.',
111
+ 'Drop: restatements, exploration dead ends that led nowhere, raw tool output detail, and anything the recent messages supersede.',
112
+ input.instructions ? `User compaction instructions: ${input.instructions}` : undefined,
113
+ `Write a dense summary in at most 60 lines. ${omitted > 0 ? `(${omitted} oldest message(s) already omitted from this transcript.)` : ''}`.trim(),
114
+ '',
115
+ '<older_conversation>',
116
+ ...kept,
117
+ '</older_conversation>',
118
+ ].filter((line) => line !== undefined).join('\n');
119
+ }
120
+ /**
121
+ * Assemble the compacted history around a model-written summary (F-09). Same
122
+ * split rules as the heuristic path; the excerpt is replaced by the summary
123
+ * text the model produced.
124
+ */
125
+ export function compactModelMessagesWithSummary(messages, options) {
126
+ const split = splitForCompaction(messages, options);
127
+ if (!split)
128
+ return { compacted: false, messages, olderCount: 0, keptCount: messages.length };
129
+ const summary = [
130
+ 'Compacted prior haze conversation. Treat this as continuity context, not a new user request.',
131
+ 'Do not treat older tool outputs as current unless the recent conversation confirms they still apply.',
132
+ options.instructions ? `User compaction instructions: ${options.instructions}` : undefined,
133
+ options.workState ? workStatePrompt(options.workState) : undefined,
134
+ '',
135
+ 'Model-written summary of the older conversation:',
136
+ options.summaryText.trim(),
137
+ ].filter((line) => line !== undefined).join('\n');
138
+ return {
139
+ compacted: true,
140
+ messages: [{ role: 'user', content: `<haze_compaction>\n${summary}\n</haze_compaction>` }, ...split.recent],
141
+ olderCount: split.older.length,
142
+ keptCount: split.recent.length,
143
+ summary,
144
+ };
145
+ }