@denizokcu/haze 0.9.0 → 0.11.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 (241) hide show
  1. package/CHANGELOG.md +133 -17
  2. package/README.md +164 -68
  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 +17 -1
  9. package/dist/cli/chat/chatMetrics.js +22 -5
  10. package/dist/cli/chat/contextReport.d.ts +11 -0
  11. package/dist/cli/chat/contextReport.js +46 -0
  12. package/dist/cli/chat/fileMentionSuggestions.d.ts +29 -0
  13. package/dist/cli/chat/fileMentionSuggestions.js +92 -0
  14. package/dist/cli/chat/inputSuggestions.d.ts +5 -0
  15. package/dist/cli/chat/inputSuggestions.js +17 -3
  16. package/dist/cli/chat/liveRegion.d.ts +25 -0
  17. package/dist/cli/chat/liveRegion.js +48 -0
  18. package/dist/cli/chat/messages.d.ts +33 -2
  19. package/dist/cli/chat/messages.js +216 -33
  20. package/dist/cli/chat/sessionLifecycle.d.ts +67 -0
  21. package/dist/cli/chat/sessionLifecycle.js +205 -0
  22. package/dist/cli/chat/sessionRecorder.js +80 -14
  23. package/dist/cli/chat/startupInfo.js +11 -4
  24. package/dist/cli/chat/tips.d.ts +21 -0
  25. package/dist/cli/chat/tips.js +43 -0
  26. package/dist/cli/chat/wizardDispatch.d.ts +64 -0
  27. package/dist/cli/chat/wizardDispatch.js +744 -0
  28. package/dist/cli/commands/chat.d.ts +6 -0
  29. package/dist/cli/commands/chat.js +373 -790
  30. package/dist/cli/commands/chatModes.d.ts +1 -1
  31. package/dist/cli/commands/chatModes.js +7 -2
  32. package/dist/cli/commands/commandHelp.js +5 -3
  33. package/dist/cli/commands/commands.d.ts +5 -2
  34. package/dist/cli/commands/commands.js +22 -18
  35. package/dist/cli/commands/doctor.d.ts +19 -0
  36. package/dist/cli/commands/doctor.js +76 -0
  37. package/dist/cli/commands/fleetCommand.d.ts +14 -0
  38. package/dist/cli/commands/fleetCommand.js +46 -0
  39. package/dist/cli/commands/formatters.d.ts +5 -0
  40. package/dist/cli/commands/formatters.js +35 -6
  41. package/dist/cli/commands/logsCommand.js +1 -7
  42. package/dist/cli/commands/modelCommand.js +1 -1
  43. package/dist/cli/commands/ndjsonSink.d.ts +23 -0
  44. package/dist/cli/commands/ndjsonSink.js +38 -0
  45. package/dist/cli/commands/providerWizard.d.ts +10 -2
  46. package/dist/cli/commands/providerWizard.js +50 -4
  47. package/dist/cli/commands/runCommand.d.ts +4 -0
  48. package/dist/cli/commands/runCommand.js +142 -16
  49. package/dist/cli/commands/sessionPicker.d.ts +9 -0
  50. package/dist/cli/commands/sessionPicker.js +29 -0
  51. package/dist/cli/commands/settingsSummary.js +6 -4
  52. package/dist/cli/commands/skillConfirmRemove.js +4 -3
  53. package/dist/cli/commands/skillWizard.d.ts +2 -0
  54. package/dist/cli/commands/skillWizard.js +16 -6
  55. package/dist/cli/commands/streaming/abortCause.d.ts +24 -0
  56. package/dist/cli/commands/streaming/abortCause.js +16 -0
  57. package/dist/cli/commands/streaming/assistantText.js +9 -2
  58. package/dist/cli/commands/streaming/goalCheckpoint.d.ts +65 -0
  59. package/dist/cli/commands/streaming/goalCheckpoint.js +23 -0
  60. package/dist/cli/commands/streaming/goalSupervisor.d.ts +64 -0
  61. package/dist/cli/commands/streaming/goalSupervisor.js +127 -0
  62. package/dist/cli/commands/streaming/idleTimer.d.ts +26 -0
  63. package/dist/cli/commands/streaming/idleTimer.js +24 -0
  64. package/dist/cli/commands/streaming/toolCallRecovery.d.ts +2 -0
  65. package/dist/cli/commands/streaming/toolCallRecovery.js +24 -0
  66. package/dist/cli/commands/streaming/toolGroupRenderer.d.ts +31 -0
  67. package/dist/cli/commands/streaming/toolGroupRenderer.js +50 -2
  68. package/dist/cli/commands/streaming/toolResultState.d.ts +6 -1
  69. package/dist/cli/commands/streaming/toolResultState.js +29 -7
  70. package/dist/cli/commands/streaming/turnOutcome.d.ts +17 -0
  71. package/dist/cli/commands/streaming/turnOutcome.js +27 -11
  72. package/dist/cli/commands/streaming/turnRuntime.js +6 -4
  73. package/dist/cli/commands/streaming.d.ts +82 -3
  74. package/dist/cli/commands/streaming.js +528 -91
  75. package/dist/cli/commands/wizardActions.d.ts +7 -0
  76. package/dist/cli/commands/wizardActions.js +7 -0
  77. package/dist/cli/commands/wizardPrompts.js +7 -1
  78. package/dist/cli/commands/wizardSuggestions.d.ts +8 -0
  79. package/dist/cli/commands/wizardSuggestions.js +64 -14
  80. package/dist/cli/commands/wizardTransition.d.ts +4 -0
  81. package/dist/cli/commands/wizardTransition.js +1 -2
  82. package/dist/cli/index.js +82 -22
  83. package/dist/cli/terminalTitle.d.ts +6 -0
  84. package/dist/cli/terminalTitle.js +36 -0
  85. package/dist/config/inputHistory.d.ts +3 -3
  86. package/dist/config/inputHistory.js +12 -18
  87. package/dist/config/modelDiscovery.d.ts +71 -0
  88. package/dist/config/modelDiscovery.js +214 -0
  89. package/dist/config/privateStorage.js +28 -2
  90. package/dist/config/providerAuth.d.ts +14 -0
  91. package/dist/config/providerAuth.js +49 -0
  92. package/dist/config/providerPresets.d.ts +49 -5
  93. package/dist/config/providerPresets.js +573 -73
  94. package/dist/config/providers.d.ts +2 -0
  95. package/dist/config/providers.js +9 -0
  96. package/dist/config/settings.d.ts +58 -0
  97. package/dist/config/settings.js +38 -1
  98. package/dist/config/skillSettings.d.ts +6 -13
  99. package/dist/config/skillSettings.js +20 -19
  100. package/dist/core/agent/budgets.d.ts +36 -0
  101. package/dist/core/agent/budgets.js +44 -0
  102. package/dist/core/agent/compaction.d.ts +38 -0
  103. package/dist/core/agent/compaction.js +108 -19
  104. package/dist/core/agent/completionController.d.ts +230 -0
  105. package/dist/core/agent/completionController.js +287 -0
  106. package/dist/core/agent/contextBudget.d.ts +46 -0
  107. package/dist/core/agent/contextBudget.js +89 -7
  108. package/dist/core/agent/errors.js +6 -2
  109. package/dist/core/agent/events.d.ts +86 -0
  110. package/dist/core/agent/reasoningPolicy.d.ts +31 -0
  111. package/dist/core/agent/reasoningPolicy.js +27 -0
  112. package/dist/core/agent/toolCapabilities.d.ts +27 -0
  113. package/dist/core/agent/toolCapabilities.js +58 -0
  114. package/dist/core/agent/toolExecutionBudget.d.ts +35 -0
  115. package/dist/core/agent/toolExecutionBudget.js +49 -0
  116. package/dist/core/agent/toolOutputStore.d.ts +13 -0
  117. package/dist/core/agent/toolOutputStore.js +27 -10
  118. package/dist/core/agent/toolResults.d.ts +12 -0
  119. package/dist/core/agent/toolResults.js +38 -0
  120. package/dist/core/agent/turnBudget.d.ts +35 -0
  121. package/dist/core/agent/turnBudget.js +27 -0
  122. package/dist/core/agent/turnPolicy.d.ts +11 -0
  123. package/dist/core/agent/turnPolicy.js +19 -0
  124. package/dist/core/agent/workState.d.ts +76 -1
  125. package/dist/core/agent/workState.js +120 -13
  126. package/dist/core/attachments/imageAttachments.d.ts +90 -0
  127. package/dist/core/attachments/imageAttachments.js +245 -0
  128. package/dist/core/attachments/readBlessings.d.ts +37 -0
  129. package/dist/core/attachments/readBlessings.js +79 -0
  130. package/dist/core/deadline.d.ts +33 -0
  131. package/dist/core/deadline.js +74 -0
  132. package/dist/core/goal/completionPolicy.d.ts +27 -0
  133. package/dist/core/goal/completionPolicy.js +37 -1
  134. package/dist/core/goal/requestClassifier.d.ts +0 -3
  135. package/dist/core/goal/requestClassifier.js +0 -13
  136. package/dist/core/io/boundedRead.js +76 -29
  137. package/dist/core/limits/byteBudgets.d.ts +7 -0
  138. package/dist/core/limits/byteBudgets.js +7 -0
  139. package/dist/core/limits/textBudgets.d.ts +25 -0
  140. package/dist/core/limits/textBudgets.js +25 -0
  141. package/dist/core/log/llmLog.js +7 -0
  142. package/dist/core/persistence/orderedFileWriter.d.ts +10 -0
  143. package/dist/core/persistence/orderedFileWriter.js +16 -2
  144. package/dist/core/process/backgroundRegistry.d.ts +35 -0
  145. package/dist/core/process/backgroundRegistry.js +195 -0
  146. package/dist/core/process/runBoundedProcess.d.ts +9 -0
  147. package/dist/core/process/runBoundedProcess.js +74 -29
  148. package/dist/core/safety/missingExecutable.d.ts +42 -0
  149. package/dist/core/safety/missingExecutable.js +77 -0
  150. package/dist/core/safety/urlGuard.d.ts +2 -1
  151. package/dist/core/safety/urlGuard.js +3 -2
  152. package/dist/core/session/sessionSlimming.js +47 -4
  153. package/dist/core/session/sessionStore.d.ts +74 -0
  154. package/dist/core/session/sessionStore.js +268 -18
  155. package/dist/core/subagent/contracts.d.ts +120 -0
  156. package/dist/core/subagent/contracts.js +55 -0
  157. package/dist/core/subagent/executionProfiles.d.ts +28 -0
  158. package/dist/core/subagent/executionProfiles.js +45 -0
  159. package/dist/core/subagent/subagentCoordinator.d.ts +78 -0
  160. package/dist/core/subagent/subagentCoordinator.js +164 -0
  161. package/dist/core/subagent/subagentRunner.d.ts +211 -145
  162. package/dist/core/subagent/subagentRunner.js +208 -98
  163. package/dist/core/subagent/workspaceMutationPolicy.d.ts +11 -0
  164. package/dist/core/subagent/workspaceMutationPolicy.js +52 -0
  165. package/dist/core/tasks/taskStorage.js +12 -1
  166. package/dist/llm/client.d.ts +36 -29
  167. package/dist/llm/client.js +102 -33
  168. package/dist/llm/hazeTools.d.ts +2559 -150
  169. package/dist/llm/hazeTools.js +119 -31
  170. package/dist/llm/lsp.d.ts +26 -4
  171. package/dist/llm/lsp.js +90 -14
  172. package/dist/llm/lspTools.d.ts +2366 -0
  173. package/dist/llm/lspTools.js +87 -79
  174. package/dist/llm/openaiCodex.d.ts +3 -0
  175. package/dist/llm/openaiCodex.js +47 -0
  176. package/dist/llm/openaiCodexOAuth.d.ts +54 -0
  177. package/dist/llm/openaiCodexOAuth.js +214 -0
  178. package/dist/llm/requestContext.d.ts +25 -1
  179. package/dist/llm/requestContext.js +51 -8
  180. package/dist/llm/systemPrompt.d.ts +15 -1
  181. package/dist/llm/systemPrompt.js +24 -8
  182. package/dist/llm/toolResultTypes.d.ts +8 -1
  183. package/dist/llm/tools/bashTool.d.ts +906 -32
  184. package/dist/llm/tools/bashTool.js +30 -4
  185. package/dist/llm/tools/editMatch.d.ts +14 -0
  186. package/dist/llm/tools/editMatch.js +72 -0
  187. package/dist/llm/tools/failures.d.ts +2 -0
  188. package/dist/llm/tools/failures.js +1 -0
  189. package/dist/llm/tools/fetchTool.d.ts +42 -26
  190. package/dist/llm/tools/fetchTool.js +1 -1
  191. package/dist/llm/tools/fileToolShared.d.ts +6 -4
  192. package/dist/llm/tools/fileToolShared.js +18 -23
  193. package/dist/llm/tools/gitIgnore.d.ts +49 -0
  194. package/dist/llm/tools/gitIgnore.js +129 -0
  195. package/dist/llm/tools/grepRunner.d.ts +5 -0
  196. package/dist/llm/tools/grepRunner.js +52 -71
  197. package/dist/llm/tools/outputCap.d.ts +2 -6
  198. package/dist/llm/tools/outputCap.js +2 -6
  199. package/dist/llm/tools/processTool.d.ts +1077 -0
  200. package/dist/llm/tools/processTool.js +41 -0
  201. package/dist/llm/tools/readRecovery.d.ts +10 -0
  202. package/dist/llm/tools/readRecovery.js +135 -0
  203. package/dist/llm/tools/toolContext.d.ts +9 -1
  204. package/dist/llm/tools/toolContext.js +83 -43
  205. package/dist/llm/tools/workspaceFile.d.ts +9 -1
  206. package/dist/llm/tools/workspaceFile.js +33 -4
  207. package/dist/llm/webFetch.d.ts +17 -0
  208. package/dist/llm/webFetch.js +66 -86
  209. package/dist/llm/workerContext.d.ts +18 -0
  210. package/dist/llm/workerContext.js +55 -0
  211. package/dist/skills/SkillLoader.d.ts +2 -2
  212. package/dist/skills/SkillRegistry.d.ts +3 -2
  213. package/dist/skills/SkillRegistry.js +43 -13
  214. package/dist/skills/builder/SkillBuilder.d.ts +3 -0
  215. package/dist/skills/builder/SkillBuilder.js +23 -5
  216. package/dist/skills/skillTools.js +11 -4
  217. package/dist/skills/types.d.ts +6 -1
  218. package/dist/ui/codeHighlight.d.ts +4 -0
  219. package/dist/ui/codeHighlight.js +31 -0
  220. package/dist/ui/components/Header.d.ts +1 -1
  221. package/dist/ui/components/MarkdownText.d.ts +16 -2
  222. package/dist/ui/components/MarkdownText.js +244 -34
  223. package/dist/ui/components/TextInput.d.ts +12 -2
  224. package/dist/ui/components/TextInput.js +80 -8
  225. package/dist/ui/theme.d.ts +4 -3
  226. package/dist/ui/theme.js +5 -4
  227. package/dist/utils/buildInfo.d.ts +104 -0
  228. package/dist/utils/buildInfo.js +253 -0
  229. package/dist/utils/format.d.ts +2 -0
  230. package/dist/utils/format.js +8 -0
  231. package/dist/utils/fs.d.ts +9 -1
  232. package/dist/utils/fs.js +87 -29
  233. package/dist/utils/openPath.d.ts +2 -0
  234. package/dist/utils/openPath.js +22 -0
  235. package/dist/utils/path.d.ts +2 -0
  236. package/dist/utils/path.js +5 -1
  237. package/dist/utils/utf8.d.ts +22 -0
  238. package/dist/utils/utf8.js +54 -0
  239. package/dist/utils/version.d.ts +9 -3
  240. package/dist/utils/version.js +28 -2
  241. package/package.json +24 -19
@@ -21,3 +21,5 @@ export declare function resolveModelSelector(settings: HazeSettings, selector: s
21
21
  export declare function modelSelector(provider: HazeProviderSettings, model: string): string;
22
22
  export declare function upsertProvider(settings: HazeSettings, provider: HazeProviderSettings): HazeProviderSettings[];
23
23
  export declare function providerHasKey(settings: HazeSettings, provider: HazeProviderSettings): boolean;
24
+ /** Image input is explicit-only (F03): never inferred from URL or model name. */
25
+ export declare function providerImageCapable(provider: HazeProviderSettings): boolean;
@@ -19,10 +19,15 @@ function normalizeProvider(provider, fallbackModel) {
19
19
  if (!name || !url)
20
20
  return undefined;
21
21
  const key = provider.key?.trim();
22
+ // Capabilities are explicit only: an absent/false flag means "not capable".
23
+ const capabilities = provider.capabilities ?? undefined;
22
24
  return {
23
25
  name,
24
26
  url,
25
27
  ...(key ? { key } : {}),
28
+ ...(provider.kind ? { kind: provider.kind } : {}),
29
+ ...(capabilities ? { capabilities } : {}),
30
+ ...(provider.modelLimits ? { modelLimits: provider.modelLimits } : {}),
26
31
  models: normalizeModels(provider.models, fallbackModel),
27
32
  };
28
33
  }
@@ -86,3 +91,7 @@ export function upsertProvider(settings, provider) {
86
91
  export function providerHasKey(settings, provider) {
87
92
  return Boolean(provider.key ?? (provider.name === 'openrouter' ? settings.apiKey : undefined));
88
93
  }
94
+ /** Image input is explicit-only (F03): never inferred from URL or model name. */
95
+ export function providerImageCapable(provider) {
96
+ return provider.capabilities?.images === true;
97
+ }
@@ -1,8 +1,34 @@
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';
16
+ /**
17
+ * Explicit endpoint capabilities. Never inferred: images are only sent to
18
+ * providers the user marked image-capable (F03).
19
+ */
20
+ capabilities?: {
21
+ images?: boolean;
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
+ }>;
6
32
  }
7
33
  export interface HazeLspServerSettings {
8
34
  name: string;
@@ -33,8 +59,16 @@ export interface HazeMcpServer {
33
59
  */
34
60
  export interface HazeSkillSetting {
35
61
  name: string;
62
+ /** Omitted by older settings and interpreted as global. */
63
+ scope?: 'global' | 'project';
36
64
  enabled?: boolean;
37
65
  }
66
+ export interface HazeSubagentSettings {
67
+ workerModel?: string;
68
+ defaultProfile?: string;
69
+ profiles?: Record<string, Record<string, unknown>>;
70
+ [key: string]: unknown;
71
+ }
38
72
  export interface HazeSettings {
39
73
  provider?: string;
40
74
  model?: string;
@@ -42,6 +76,28 @@ export interface HazeSettings {
42
76
  lspServers?: HazeLspServerSettings[];
43
77
  mcpServers?: HazeMcpServer[];
44
78
  skills?: HazeSkillSetting[];
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
+ * Manual `/compact` mode (F-09): `llm-summary` (default) asks the active
92
+ * model to summarize the older history; `heuristic` keeps the bounded
93
+ * excerpt without a model call. Automatic mid-turn compaction is always
94
+ * heuristic.
95
+ */
96
+ manualCompaction?: 'llm-summary' | 'heuristic';
97
+ /** UI tweaks: rotating tips under the busy label, etc. Default enabled. */
98
+ tips?: {
99
+ enabled?: boolean;
100
+ };
45
101
  apiKey?: string;
46
102
  baseURL?: string;
47
103
  [key: string]: unknown;
@@ -50,3 +106,5 @@ export declare const SETTINGS_FILE: string;
50
106
  export declare function readSettings(): Promise<HazeSettings>;
51
107
  export declare function writeSettings(settings: HazeSettings): Promise<void>;
52
108
  export declare function updateSettings(patch: HazeSettings): Promise<HazeSettings>;
109
+ /** Patch subagent settings without dropping unknown nested/profile fields. */
110
+ export declare function updateSubagentSettings(patch: HazeSubagentSettings): Promise<HazeSettings>;
@@ -3,12 +3,20 @@ import path from 'node:path';
3
3
  import { z } from 'zod';
4
4
  import { HAZE_DIR } from './paths.js';
5
5
  import { tightenPrivateFile, writePrivateJsonAtomic } from './privateStorage.js';
6
+ import { customProfileSchema } from '../core/subagent/executionProfiles.js';
7
+ export const reasoningLevelSchema = z.enum(['low', 'medium', 'high']);
6
8
  export const SETTINGS_FILE = path.join(HAZE_DIR, 'settings.json');
9
+ const providerCapabilitiesSchema = z.object({
10
+ images: z.boolean().optional(),
11
+ }).passthrough();
7
12
  const providerSchema = z.object({
8
13
  name: z.string(),
9
14
  url: z.string(),
10
15
  key: z.string().optional(),
11
16
  models: z.array(z.string()),
17
+ kind: z.enum(['openai-compatible', 'chatgpt-codex']).optional(),
18
+ capabilities: providerCapabilitiesSchema.optional(),
19
+ modelLimits: z.record(z.string(), z.object({ contextWindowTokens: z.number().int().positive(), maxOutputTokens: z.number().int().positive() }).partial()).optional(),
12
20
  }).passthrough();
13
21
  const lspServerSchema = z.object({
14
22
  name: z.string(),
@@ -28,7 +36,14 @@ const mcpServerSchema = z.object({
28
36
  headers: z.array(mcpHeaderSchema).optional(),
29
37
  enabled: z.boolean().optional(),
30
38
  }).passthrough();
31
- const skillSettingSchema = z.object({ name: z.string(), enabled: z.boolean().optional() }).passthrough();
39
+ const skillSettingSchema = z.object({ name: z.string(), scope: z.enum(['global', 'project']).optional(), enabled: z.boolean().optional() }).passthrough();
40
+ const subagentSettingsSchema = z.object({
41
+ workerModel: z.string().trim().min(1).optional(),
42
+ defaultProfile: z.string().trim().min(1).optional(),
43
+ profiles: z.record(z.string().min(1), customProfileSchema).optional(),
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);
32
47
  const settingsSchema = z.object({
33
48
  provider: z.string().optional(),
34
49
  model: z.string().optional(),
@@ -36,6 +51,12 @@ const settingsSchema = z.object({
36
51
  lspServers: z.array(lspServerSchema).optional(),
37
52
  mcpServers: z.array(mcpServerSchema).optional(),
38
53
  skills: z.array(skillSettingSchema).optional(),
54
+ subagents: subagentSettingsSchema.optional(),
55
+ reasoning: reasoningLevelSchema.optional(),
56
+ contextWindowFallbackTokens: contextWindowFallbackSchema.optional(),
57
+ localContextWindowFallbackTokens: contextWindowFallbackSchema.optional(),
58
+ manualCompaction: z.enum(['llm-summary', 'heuristic']).optional(),
59
+ tips: z.object({ enabled: z.boolean().optional() }).optional(),
39
60
  apiKey: z.string().optional(),
40
61
  baseURL: z.string().optional(),
41
62
  }).passthrough();
@@ -66,3 +87,19 @@ export async function updateSettings(patch) {
66
87
  await writeSettings(next);
67
88
  return next;
68
89
  }
90
+ /** Patch subagent settings without dropping unknown nested/profile fields. */
91
+ export async function updateSubagentSettings(patch) {
92
+ const current = await readSettings();
93
+ const currentSubagents = current.subagents ?? {};
94
+ const profiles = patch.profiles
95
+ ? Object.fromEntries(Object.entries(patch.profiles).map(([name, value]) => [name, { ...(currentSubagents.profiles?.[name] ?? {}), ...value }]))
96
+ : undefined;
97
+ const subagents = {
98
+ ...currentSubagents,
99
+ ...patch,
100
+ ...(profiles ? { profiles: { ...(currentSubagents.profiles ?? {}), ...profiles } } : {}),
101
+ };
102
+ const next = { ...current, subagents };
103
+ await writeSettings(next);
104
+ return next;
105
+ }
@@ -1,15 +1,8 @@
1
1
  import type { HazeSettings, HazeSkillSetting } from './settings.js';
2
- /**
3
- * Normalized skill metadata overrides. The list is override-only: only skills that
4
- * deviate from the default (enabled) appear here, so it never desyncs from disk.
5
- */
2
+ import type { SkillSource } from '../skills/types.js';
3
+ /** Normalized override-only skill settings. Legacy entries apply to global skills. */
6
4
  export declare function configuredSkillSettings(settings: HazeSettings): HazeSkillSetting[];
7
- /** A skill is enabled unless an explicit override disables it. */
8
- export declare function isSkillEnabled(settings: HazeSettings, name: string): boolean;
9
- /**
10
- * Toggle a skill. Enabling clears its override (back to default); disabling records
11
- * `enabled: false`. Returns the next `skills` array for updateSettings.
12
- */
13
- export declare function setSkillEnabled(settings: HazeSettings, name: string, enabled: boolean): HazeSkillSetting[];
14
- /** Drop a skill's override entry. Called when a skill directory is removed. */
15
- export declare function removeSkillSetting(settings: HazeSettings, name: string): HazeSkillSetting[];
5
+ /** A skill is enabled unless an explicit scope-aware override disables it. */
6
+ export declare function isSkillEnabled(settings: HazeSettings, name: string, scope?: SkillSource): boolean;
7
+ export declare function setSkillEnabled(settings: HazeSettings, name: string, enabled: boolean, scope?: SkillSource): HazeSkillSetting[];
8
+ export declare function removeSkillSetting(settings: HazeSettings, name: string, scope?: SkillSource): HazeSkillSetting[];
@@ -1,32 +1,33 @@
1
- import { findByName, removeByName } from '../utils/collections.js';
2
- /**
3
- * Normalized skill metadata overrides. The list is override-only: only skills that
4
- * deviate from the default (enabled) appear here, so it never desyncs from disk.
5
- */
1
+ /** Normalized override-only skill settings. Legacy entries apply to global skills. */
6
2
  export function configuredSkillSettings(settings) {
7
3
  const result = [];
8
4
  for (const entry of settings.skills ?? []) {
9
5
  const name = entry.name?.trim();
10
6
  if (!name)
11
7
  continue;
12
- result.push({ name, ...(entry.enabled === false ? { enabled: false } : {}) });
8
+ result.push({
9
+ name,
10
+ ...(entry.scope ? { scope: entry.scope } : {}),
11
+ ...(entry.enabled === false ? { enabled: false } : {}),
12
+ });
13
13
  }
14
14
  return result;
15
15
  }
16
- /** A skill is enabled unless an explicit override disables it. */
17
- export function isSkillEnabled(settings, name) {
18
- const entry = findByName(configuredSkillSettings(settings), name);
16
+ function settingScope(entry) {
17
+ return entry.scope ?? 'global';
18
+ }
19
+ function matches(entry, name, scope) {
20
+ return entry.name === name && settingScope(entry) === scope;
21
+ }
22
+ /** A skill is enabled unless an explicit scope-aware override disables it. */
23
+ export function isSkillEnabled(settings, name, scope = 'global') {
24
+ const entry = configuredSkillSettings(settings).find(candidate => matches(candidate, name, scope));
19
25
  return entry ? entry.enabled !== false : true;
20
26
  }
21
- /**
22
- * Toggle a skill. Enabling clears its override (back to default); disabling records
23
- * `enabled: false`. Returns the next `skills` array for updateSettings.
24
- */
25
- export function setSkillEnabled(settings, name, enabled) {
26
- const others = removeByName(configuredSkillSettings(settings), name);
27
- return enabled ? others : [...others, { name, enabled: false }];
27
+ export function setSkillEnabled(settings, name, enabled, scope = 'global') {
28
+ const others = configuredSkillSettings(settings).filter(entry => !matches(entry, name, scope));
29
+ return enabled ? others : [...others, { name, ...(scope === 'project' ? { scope } : {}), enabled: false }];
28
30
  }
29
- /** Drop a skill's override entry. Called when a skill directory is removed. */
30
- export function removeSkillSetting(settings, name) {
31
- return removeByName(configuredSkillSettings(settings), name);
31
+ export function removeSkillSetting(settings, name, scope = 'global') {
32
+ return configuredSkillSettings(settings).filter(entry => !matches(entry, name, scope));
32
33
  }
@@ -1,6 +1,42 @@
1
1
  export declare const DEFAULT_MAX_OUTPUT_TOKENS = 16384;
2
+ /** Keep generated file payloads comfortably below a model's output-token ceiling. */
3
+ export declare const WRITE_FILE_CHUNK_BYTES: number;
2
4
  export declare const IDLE_TIMEOUT_MS: number;
5
+ /** Default per-tool execution deadline; an uncooperative tool cannot defer the turn indefinitely (RH-004). */
6
+ export declare const DEFAULT_TOOL_DEADLINE_MS: number;
7
+ /** Subagents legitimately run long; give their wrapper a larger deadline. */
8
+ export declare const SUBAGENT_TOOL_DEADLINE_MS: number;
9
+ /** Absolute main-turn deadline: no single turn runs longer than this by default. */
10
+ export declare const DEFAULT_TURN_DEADLINE_MS: number;
11
+ /** Maximum accepted explicit `--timeout` value (24 hours). */
12
+ export declare const MAX_TURN_DEADLINE_MS: number;
3
13
  export declare const MAIN_STEP_LIMIT = 64;
4
14
  export declare const MAIN_TOOL_CALL_LIMIT = 120;
5
15
  export declare const MAIN_TOOL_ONLY_STEP_LIMIT = 24;
6
16
  export declare const ACTIVE_CONTEXT_TOKEN_BUDGET = 40000;
17
+ export declare const BACKGROUND_PROCESS_MAX_CONCURRENCY = 5;
18
+ export declare const BACKGROUND_PROCESS_HISTORY_LIMIT = 20;
19
+ export declare const SUBAGENT_OBJECTIVE_CHARS = 4000;
20
+ export declare const SUBAGENT_DELIVERABLE_CHARS = 600;
21
+ export declare const SUBAGENT_SCOPE_ITEMS = 32;
22
+ export declare const SUBAGENT_SCOPE_CHARS = 240;
23
+ export declare const SUBAGENT_ACCEPTANCE_ITEMS = 8;
24
+ export declare const SUBAGENT_ACCEPTANCE_CHARS = 300;
25
+ export declare const SUBAGENT_MIN_STEPS = 4;
26
+ export declare const SUBAGENT_DEFAULT_STEPS = 25;
27
+ export declare const SUBAGENT_MAX_STEPS = 50;
28
+ export declare const SUBAGENT_DEFAULT_TOOL_CALLS = 20;
29
+ export declare const SUBAGENT_MAX_TOOL_CALLS = 50;
30
+ export declare const SUBAGENT_TOOL_ONLY_LIMIT = 12;
31
+ export declare const SUBAGENT_SYNTHESIS_RESERVE = 2;
32
+ export declare const SUBAGENT_DEFAULT_OUTPUT_TOKENS = 4096;
33
+ export declare const SUBAGENT_MAX_OUTPUT_TOKENS = 16384;
34
+ export declare const SUBAGENT_DEFAULT_SUMMARY_CHARS = 4000;
35
+ export declare const SUBAGENT_MAX_SUMMARY_CHARS = 12000;
36
+ export declare const SUBAGENT_DEFAULT_INPUT_TOKENS = 40000;
37
+ export declare const SUBAGENT_MAX_INPUT_TOKENS = 200000;
38
+ export declare const SUBAGENT_DEFAULT_DEADLINE_MS = 300000;
39
+ export declare const SUBAGENT_MIN_DEADLINE_MS = 1000;
40
+ export declare const SUBAGENT_MAX_DEADLINE_MS: number;
41
+ export declare const SUBAGENT_MAX_CONCURRENCY = 10;
42
+ export declare const SUBAGENT_MAX_RETRIES = 5;
@@ -1,6 +1,50 @@
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
16
  export const ACTIVE_CONTEXT_TOKEN_BUDGET = 40_000;
17
+ export const BACKGROUND_PROCESS_MAX_CONCURRENCY = 5;
18
+ export const BACKGROUND_PROCESS_HISTORY_LIMIT = 20;
19
+ // Disposable worker/task-capsule limits. Keep these centralized so model-facing
20
+ // schemas and runtime enforcement cannot drift.
21
+ // Keep validation tolerant of verbose tool callers while prompt guidance asks
22
+ // models to stay below 1,000 chars. Strict 1,200-char rejection caused capable
23
+ // models to waste an entire parallel fleet wave before self-repairing.
24
+ export const SUBAGENT_OBJECTIVE_CHARS = 4_000;
25
+ export const SUBAGENT_DELIVERABLE_CHARS = 600;
26
+ // Prompt guidance asks for at most 12 concise scope hints, but tolerate a
27
+ // pre-mapped file list so verbose models do not waste a full fleet wave on a
28
+ // recoverable schema error.
29
+ export const SUBAGENT_SCOPE_ITEMS = 32;
30
+ export const SUBAGENT_SCOPE_CHARS = 240;
31
+ export const SUBAGENT_ACCEPTANCE_ITEMS = 8;
32
+ export const SUBAGENT_ACCEPTANCE_CHARS = 300;
33
+ export const SUBAGENT_MIN_STEPS = 4;
34
+ export const SUBAGENT_DEFAULT_STEPS = 25;
35
+ export const SUBAGENT_MAX_STEPS = 50;
36
+ export const SUBAGENT_DEFAULT_TOOL_CALLS = 20;
37
+ export const SUBAGENT_MAX_TOOL_CALLS = 50;
38
+ export const SUBAGENT_TOOL_ONLY_LIMIT = 12;
39
+ export const SUBAGENT_SYNTHESIS_RESERVE = 2;
40
+ export const SUBAGENT_DEFAULT_OUTPUT_TOKENS = 4_096;
41
+ export const SUBAGENT_MAX_OUTPUT_TOKENS = 16_384;
42
+ export const SUBAGENT_DEFAULT_SUMMARY_CHARS = 4_000;
43
+ export const SUBAGENT_MAX_SUMMARY_CHARS = 12_000;
44
+ export const SUBAGENT_DEFAULT_INPUT_TOKENS = 40_000;
45
+ export const SUBAGENT_MAX_INPUT_TOKENS = 200_000;
46
+ export const SUBAGENT_DEFAULT_DEADLINE_MS = 300_000;
47
+ export const SUBAGENT_MIN_DEADLINE_MS = 1_000;
48
+ export const SUBAGENT_MAX_DEADLINE_MS = 30 * 60_000;
49
+ export const SUBAGENT_MAX_CONCURRENCY = 10;
50
+ export const SUBAGENT_MAX_RETRIES = 5;
@@ -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,41 +1,65 @@
1
- import { estimateValueTokens } from './contextBudget.js';
1
+ import { estimateModelMessageTokens } from './contextBudget.js';
2
2
  import { workStatePrompt } from './workState.js';
3
- export function modelMessageText(message) {
4
- const content = message.content;
5
- if (typeof content === 'string')
6
- return content;
7
- if (!Array.isArray(content))
8
- return '';
9
- return content.map(part => typeof part === 'object' && part != null && 'text' in part && typeof part.text === 'string' ? part.text : '').filter(Boolean).join('\n');
10
- }
11
- export function compactModelMessages(messages, options = {}) {
3
+ import { COMPACTION_LLM_TRANSCRIPT_CHARS, COMPACTION_OLDER_CHARS } from '../limits/textBudgets.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 = {}) {
12
12
  const maxRecentMessages = Math.min(options.keepRecentMessages ?? 12, messages.length);
13
13
  let keepRecentMessages = maxRecentMessages;
14
14
  if (options.tokenBudget != null) {
15
15
  let recentTokens = 0;
16
16
  keepRecentMessages = 0;
17
17
  for (let index = messages.length - 1; index >= 0 && keepRecentMessages < maxRecentMessages; index--) {
18
- const tokens = estimateValueTokens(messages[index]);
18
+ const tokens = estimateModelMessageTokens(messages[index]);
19
19
  if (keepRecentMessages > 0 && recentTokens + tokens > options.tokenBudget)
20
20
  break;
21
21
  recentTokens += tokens;
22
22
  keepRecentMessages += 1;
23
23
  }
24
24
  }
25
- if (messages.length <= keepRecentMessages) {
26
- return { compacted: false, messages, olderCount: 0, keptCount: messages.length };
27
- }
25
+ if (messages.length <= keepRecentMessages)
26
+ return undefined;
28
27
  let recentStart = messages.length - keepRecentMessages;
29
28
  while (recentStart > 0 && messages[recentStart]?.role === 'tool')
30
29
  recentStart -= 1;
31
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)
32
45
  return { compacted: false, messages, olderCount: 0, keptCount: messages.length };
33
- const older = messages.slice(0, recentStart);
34
- const recent = messages.slice(recentStart);
35
- const oldText = older.map(message => {
46
+ const { older, recent } = split;
47
+ const olderEntries = older.map(message => {
36
48
  const text = modelMessageText(message).replace(/\s+/g, ' ').trim();
37
49
  return text ? `- ${message.role}: ${text}` : '';
38
- }).filter(Boolean).join('\n');
50
+ }).filter(Boolean);
51
+ // Keep the excerpt bounded, favoring the most recent older messages (CR-008).
52
+ const keptEntries = [];
53
+ let excerptChars = 0;
54
+ for (let index = olderEntries.length - 1; index >= 0; index--) {
55
+ const entry = olderEntries[index];
56
+ if (excerptChars + entry.length + 1 > COMPACTION_OLDER_CHARS && keptEntries.length > 0)
57
+ break;
58
+ keptEntries.unshift(entry);
59
+ excerptChars += entry.length + 1;
60
+ }
61
+ const omittedEntries = olderEntries.length - keptEntries.length;
62
+ const oldText = keptEntries.join('\n');
39
63
  const summary = [
40
64
  'Compacted prior haze conversation. Treat this as continuity context, not a new user request.',
41
65
  'Preserve especially: current user goal and success condition; explicit user constraints/preferences/decisions; files created/changed/read; validation commands and pass/fail results; blockers or pending product decisions; exact next action if work was unfinished.',
@@ -43,8 +67,9 @@ export function compactModelMessages(messages, options = {}) {
43
67
  options.instructions ? `User compaction instructions: ${options.instructions}` : undefined,
44
68
  options.workState ? workStatePrompt(options.workState) : undefined,
45
69
  '',
46
- 'Older context summary:',
70
+ 'Older context excerpt (whitespace-collapsed, most recent first within a bounded budget):',
47
71
  oldText || '- Older messages were tool-only or non-text.',
72
+ omittedEntries > 0 ? `[${omittedEntries} older message(s) omitted from the excerpt to keep compaction bounded; rely on the preserved points above.]` : undefined,
48
73
  ].filter((line) => line !== undefined).join('\n');
49
74
  return {
50
75
  compacted: true,
@@ -54,3 +79,67 @@ export function compactModelMessages(messages, options = {}) {
54
79
  summary,
55
80
  };
56
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
+ }