@denizokcu/haze 0.7.0 → 0.9.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 (96) hide show
  1. package/CHANGELOG.md +35 -9
  2. package/README.md +37 -35
  3. package/dist/cli/chat/inputSuggestions.js +2 -2
  4. package/dist/cli/chat/sessionRecorder.d.ts +3 -0
  5. package/dist/cli/chat/sessionRecorder.js +23 -8
  6. package/dist/cli/commands/chat.js +136 -124
  7. package/dist/cli/commands/chatModes.js +1 -1
  8. package/dist/cli/commands/commandHelp.js +2 -2
  9. package/dist/cli/commands/commands.d.ts +1 -1
  10. package/dist/cli/commands/commands.js +1 -1
  11. package/dist/cli/commands/formatters.d.ts +6 -0
  12. package/dist/cli/commands/formatters.js +41 -3
  13. package/dist/cli/commands/logsCommand.js +7 -21
  14. package/dist/cli/commands/mcpWizard.js +24 -2
  15. package/dist/cli/commands/providerWizard.js +18 -5
  16. package/dist/cli/commands/runCommand.js +7 -15
  17. package/dist/cli/commands/settingsSummary.js +3 -1
  18. package/dist/cli/commands/streaming/turnOutcome.d.ts +10 -0
  19. package/dist/cli/commands/streaming/turnOutcome.js +13 -0
  20. package/dist/cli/commands/streaming.js +99 -51
  21. package/dist/cli/commands/wizardPrompts.js +1 -1
  22. package/dist/cli/commands/wizardSuggestions.js +3 -2
  23. package/dist/cli/commands/wizardTransition.d.ts +33 -0
  24. package/dist/cli/commands/wizardTransition.js +44 -0
  25. package/dist/config/contextFiles.js +6 -3
  26. package/dist/config/endpointSecurity.d.ts +2 -0
  27. package/dist/config/endpointSecurity.js +28 -0
  28. package/dist/config/inputHistory.js +4 -2
  29. package/dist/config/privateStorage.d.ts +6 -0
  30. package/dist/config/privateStorage.js +61 -0
  31. package/dist/config/providers.js +5 -9
  32. package/dist/config/settings.d.ts +1 -0
  33. package/dist/config/settings.js +55 -3
  34. package/dist/config/updateCheck.js +4 -2
  35. package/dist/core/agent/compaction.js +2 -2
  36. package/dist/core/agent/errors.js +1 -1
  37. package/dist/core/agent/requestAssembly.d.ts +1 -0
  38. package/dist/core/agent/requestAssembly.js +13 -0
  39. package/dist/core/agent/toolOutputStore.d.ts +3 -0
  40. package/dist/core/agent/toolOutputStore.js +32 -11
  41. package/dist/core/bashOutput/registry.js +11 -9
  42. package/dist/core/goal/completionPolicy.d.ts +0 -28
  43. package/dist/core/goal/completionPolicy.js +1 -89
  44. package/dist/core/io/boundedRead.d.ts +15 -0
  45. package/dist/core/io/boundedRead.js +97 -0
  46. package/dist/core/limits/byteBudgets.d.ts +13 -0
  47. package/dist/core/limits/byteBudgets.js +13 -0
  48. package/dist/core/log/llmLog.d.ts +10 -0
  49. package/dist/core/log/llmLog.js +59 -13
  50. package/dist/core/persistence/orderedFileWriter.d.ts +11 -0
  51. package/dist/core/persistence/orderedFileWriter.js +29 -0
  52. package/dist/core/process/runBoundedProcess.d.ts +27 -0
  53. package/dist/core/process/runBoundedProcess.js +80 -0
  54. package/dist/core/session/sessionStore.js +48 -25
  55. package/dist/core/subagent/subagentRunner.d.ts +252 -9
  56. package/dist/core/subagent/subagentRunner.js +14 -19
  57. package/dist/core/toolOutput/reduction.d.ts +2 -0
  58. package/dist/core/toolOutput/reduction.js +12 -0
  59. package/dist/core/validation/outputParser.js +5 -3
  60. package/dist/llm/client.d.ts +2 -2
  61. package/dist/llm/client.js +19 -3
  62. package/dist/llm/hazeTools.d.ts +8103 -364
  63. package/dist/llm/hazeTools.js +43 -33
  64. package/dist/llm/initPrompt.js +1 -1
  65. package/dist/llm/lsp.d.ts +21 -3
  66. package/dist/llm/lsp.js +65 -14
  67. package/dist/llm/lspTools.d.ts +2358 -101
  68. package/dist/llm/mcp.d.ts +1 -1
  69. package/dist/llm/mcp.js +65 -16
  70. package/dist/llm/requestContext.d.ts +1 -0
  71. package/dist/llm/requestContext.js +6 -3
  72. package/dist/llm/systemPrompt.js +2 -2
  73. package/dist/llm/toolResultTypes.d.ts +1 -1
  74. package/dist/llm/tools/bashTool.d.ts +603 -5
  75. package/dist/llm/tools/bashTool.js +23 -60
  76. package/dist/llm/tools/fetchTool.d.ts +1201 -65
  77. package/dist/llm/tools/fetchTool.js +2 -1
  78. package/dist/llm/tools/grepRunner.d.ts +15 -0
  79. package/dist/llm/tools/grepRunner.js +85 -0
  80. package/dist/llm/tools/storedOutputTool.d.ts +351 -10
  81. package/dist/llm/tools/taskTool.d.ts +629 -28
  82. package/dist/llm/tools/toolContext.d.ts +7 -2
  83. package/dist/llm/tools/toolContext.js +11 -2
  84. package/dist/llm/webFetch.js +31 -21
  85. package/dist/skills/SkillLoader.js +17 -5
  86. package/dist/skills/SkillRegistry.js +19 -6
  87. package/dist/skills/builder/SkillBuilder.js +7 -7
  88. package/dist/skills/types.d.ts +5 -0
  89. package/dist/ui/components/TextInput.d.ts +7 -0
  90. package/dist/ui/components/TextInput.js +10 -0
  91. package/dist/utils/modelName.d.ts +2 -0
  92. package/dist/utils/modelName.js +15 -0
  93. package/dist/utils/path.d.ts +2 -0
  94. package/dist/utils/path.js +9 -4
  95. package/examples/skills/files/SKILL.md +1 -1
  96. package/package.json +14 -14
@@ -1,5 +1,6 @@
1
1
  import { streamText } from 'ai';
2
2
  import { type PromptSession } from '../../llm/systemPrompt.js';
3
+ import { toolOnlyStepCount } from '../agent/turnPolicy.js';
3
4
  import type { ContextFile } from '../../config/contextFiles.js';
4
5
  export interface SubagentResult {
5
6
  status: 'ok' | 'error' | 'timeout' | 'cancelled';
@@ -18,10 +19,6 @@ export interface SubagentResult {
18
19
  error?: string;
19
20
  }
20
21
  declare function toolSummary(output: unknown): string;
21
- declare function toolOnlyStepCount(steps: Array<{
22
- toolCalls: unknown[];
23
- text: string;
24
- }>): number;
25
22
  export declare const internals: {
26
23
  toolSummary: typeof toolSummary;
27
24
  toolOnlyStepCount: typeof toolOnlyStepCount;
@@ -38,9 +35,255 @@ export declare function createSubagentTool(options: {
38
35
  model: Parameters<typeof streamText>[0]['model'];
39
36
  contextFiles: ContextFile[];
40
37
  session?: PromptSession;
41
- }): import("ai").Tool<{
42
- task: string;
43
- tools?: ("editFile" | "replaceLines" | "writeFile" | "listFiles" | "readFile" | "grep" | "bash" | "fetch" | "readToolOutput")[] | undefined;
44
- maxSteps?: number | undefined;
45
- }, SubagentResult>;
38
+ }): ({
39
+ title?: string;
40
+ providerOptions?: import("@ai-sdk/provider-utils").ProviderOptions;
41
+ metadata?: import("@ai-sdk/provider").JSONObject;
42
+ inputSchema: import("ai").FlexibleSchema<{
43
+ task: string;
44
+ tools?: ("listFiles" | "readFile" | "grep" | "replaceLines" | "writeFile" | "editFile" | "bash" | "fetch" | "readToolOutput")[] | undefined;
45
+ maxSteps?: number | undefined;
46
+ }>;
47
+ contextSchema?: import("ai").FlexibleSchema<import("@ai-sdk/provider-utils").Context> | undefined;
48
+ needsApproval?: boolean | import("@ai-sdk/provider-utils").ToolNeedsApprovalFunction<{
49
+ task: string;
50
+ tools?: ("listFiles" | "readFile" | "grep" | "replaceLines" | "writeFile" | "editFile" | "bash" | "fetch" | "readToolOutput")[] | undefined;
51
+ maxSteps?: number | undefined;
52
+ }, NoInfer<import("@ai-sdk/provider-utils").Context>> | undefined;
53
+ onInputStart?: ((options: import("ai").ToolExecutionOptions<NoInfer<import("@ai-sdk/provider-utils").Context>>) => void | PromiseLike<void>) | undefined;
54
+ onInputDelta?: ((options: {
55
+ inputTextDelta: string;
56
+ } & import("ai").ToolExecutionOptions<NoInfer<import("@ai-sdk/provider-utils").Context>>) => void | PromiseLike<void>) | undefined;
57
+ onInputAvailable?: ((options: {
58
+ input: {
59
+ task: string;
60
+ tools?: ("listFiles" | "readFile" | "grep" | "replaceLines" | "writeFile" | "editFile" | "bash" | "fetch" | "readToolOutput")[] | undefined;
61
+ maxSteps?: number | undefined;
62
+ };
63
+ } & import("ai").ToolExecutionOptions<NoInfer<import("@ai-sdk/provider-utils").Context>>) => void | PromiseLike<void>) | undefined;
64
+ toModelOutput?: ((options: {
65
+ toolCallId: string;
66
+ input: {
67
+ task: string;
68
+ tools?: ("listFiles" | "readFile" | "grep" | "replaceLines" | "writeFile" | "editFile" | "bash" | "fetch" | "readToolOutput")[] | undefined;
69
+ maxSteps?: number | undefined;
70
+ };
71
+ output: NoInfer<SubagentResult>;
72
+ }) => import("@ai-sdk/provider-utils").ToolResultOutput | PromiseLike<import("@ai-sdk/provider-utils").ToolResultOutput>) | undefined;
73
+ } & {
74
+ outputSchema?: import("ai").FlexibleSchema<SubagentResult> | undefined;
75
+ execute: import("ai").ToolExecuteFunction<{
76
+ task: string;
77
+ tools?: ("listFiles" | "readFile" | "grep" | "replaceLines" | "writeFile" | "editFile" | "bash" | "fetch" | "readToolOutput")[] | undefined;
78
+ maxSteps?: number | undefined;
79
+ }, SubagentResult, NoInfer<import("@ai-sdk/provider-utils").Context>>;
80
+ } & {
81
+ description?: string | ((options: {
82
+ context: NoInfer<import("@ai-sdk/provider-utils").Context>;
83
+ experimental_sandbox?: import("ai").Experimental_SandboxSession;
84
+ }) => string) | undefined;
85
+ strict?: boolean;
86
+ inputExamples?: {
87
+ input: NoInfer<{
88
+ task: string;
89
+ tools?: ("listFiles" | "readFile" | "grep" | "replaceLines" | "writeFile" | "editFile" | "bash" | "fetch" | "readToolOutput")[] | undefined;
90
+ maxSteps?: number | undefined;
91
+ }>;
92
+ }[] | undefined;
93
+ id?: never;
94
+ isProviderExecuted?: never;
95
+ args?: never;
96
+ supportsDeferredResults?: never;
97
+ } & {
98
+ type?: undefined | "function";
99
+ } & {
100
+ execute: import("ai").ToolExecuteFunction<{
101
+ task: string;
102
+ tools?: ("listFiles" | "readFile" | "grep" | "replaceLines" | "writeFile" | "editFile" | "bash" | "fetch" | "readToolOutput")[] | undefined;
103
+ maxSteps?: number | undefined;
104
+ }, SubagentResult, NoInfer<import("@ai-sdk/provider-utils").Context>>;
105
+ }) | ({
106
+ title?: string;
107
+ providerOptions?: import("@ai-sdk/provider-utils").ProviderOptions;
108
+ metadata?: import("@ai-sdk/provider").JSONObject;
109
+ inputSchema: import("ai").FlexibleSchema<{
110
+ task: string;
111
+ tools?: ("listFiles" | "readFile" | "grep" | "replaceLines" | "writeFile" | "editFile" | "bash" | "fetch" | "readToolOutput")[] | undefined;
112
+ maxSteps?: number | undefined;
113
+ }>;
114
+ contextSchema?: import("ai").FlexibleSchema<import("@ai-sdk/provider-utils").Context> | undefined;
115
+ needsApproval?: boolean | import("@ai-sdk/provider-utils").ToolNeedsApprovalFunction<{
116
+ task: string;
117
+ tools?: ("listFiles" | "readFile" | "grep" | "replaceLines" | "writeFile" | "editFile" | "bash" | "fetch" | "readToolOutput")[] | undefined;
118
+ maxSteps?: number | undefined;
119
+ }, NoInfer<import("@ai-sdk/provider-utils").Context>> | undefined;
120
+ onInputStart?: ((options: import("ai").ToolExecutionOptions<NoInfer<import("@ai-sdk/provider-utils").Context>>) => void | PromiseLike<void>) | undefined;
121
+ onInputDelta?: ((options: {
122
+ inputTextDelta: string;
123
+ } & import("ai").ToolExecutionOptions<NoInfer<import("@ai-sdk/provider-utils").Context>>) => void | PromiseLike<void>) | undefined;
124
+ onInputAvailable?: ((options: {
125
+ input: {
126
+ task: string;
127
+ tools?: ("listFiles" | "readFile" | "grep" | "replaceLines" | "writeFile" | "editFile" | "bash" | "fetch" | "readToolOutput")[] | undefined;
128
+ maxSteps?: number | undefined;
129
+ };
130
+ } & import("ai").ToolExecutionOptions<NoInfer<import("@ai-sdk/provider-utils").Context>>) => void | PromiseLike<void>) | undefined;
131
+ toModelOutput?: ((options: {
132
+ toolCallId: string;
133
+ input: {
134
+ task: string;
135
+ tools?: ("listFiles" | "readFile" | "grep" | "replaceLines" | "writeFile" | "editFile" | "bash" | "fetch" | "readToolOutput")[] | undefined;
136
+ maxSteps?: number | undefined;
137
+ };
138
+ output: NoInfer<SubagentResult>;
139
+ }) => import("@ai-sdk/provider-utils").ToolResultOutput | PromiseLike<import("@ai-sdk/provider-utils").ToolResultOutput>) | undefined;
140
+ } & {
141
+ outputSchema?: import("ai").FlexibleSchema<SubagentResult> | undefined;
142
+ execute: import("ai").ToolExecuteFunction<{
143
+ task: string;
144
+ tools?: ("listFiles" | "readFile" | "grep" | "replaceLines" | "writeFile" | "editFile" | "bash" | "fetch" | "readToolOutput")[] | undefined;
145
+ maxSteps?: number | undefined;
146
+ }, SubagentResult, NoInfer<import("@ai-sdk/provider-utils").Context>>;
147
+ } & {
148
+ description?: string | ((options: {
149
+ context: NoInfer<import("@ai-sdk/provider-utils").Context>;
150
+ experimental_sandbox?: import("ai").Experimental_SandboxSession;
151
+ }) => string) | undefined;
152
+ strict?: boolean;
153
+ inputExamples?: {
154
+ input: NoInfer<{
155
+ task: string;
156
+ tools?: ("listFiles" | "readFile" | "grep" | "replaceLines" | "writeFile" | "editFile" | "bash" | "fetch" | "readToolOutput")[] | undefined;
157
+ maxSteps?: number | undefined;
158
+ }>;
159
+ }[] | undefined;
160
+ id?: never;
161
+ isProviderExecuted?: never;
162
+ args?: never;
163
+ supportsDeferredResults?: never;
164
+ } & {
165
+ type: "dynamic";
166
+ } & {
167
+ execute: import("ai").ToolExecuteFunction<{
168
+ task: string;
169
+ tools?: ("listFiles" | "readFile" | "grep" | "replaceLines" | "writeFile" | "editFile" | "bash" | "fetch" | "readToolOutput")[] | undefined;
170
+ maxSteps?: number | undefined;
171
+ }, SubagentResult, NoInfer<import("@ai-sdk/provider-utils").Context>>;
172
+ }) | ({
173
+ title?: string;
174
+ providerOptions?: import("@ai-sdk/provider-utils").ProviderOptions;
175
+ metadata?: import("@ai-sdk/provider").JSONObject;
176
+ inputSchema: import("ai").FlexibleSchema<{
177
+ task: string;
178
+ tools?: ("listFiles" | "readFile" | "grep" | "replaceLines" | "writeFile" | "editFile" | "bash" | "fetch" | "readToolOutput")[] | undefined;
179
+ maxSteps?: number | undefined;
180
+ }>;
181
+ contextSchema?: import("ai").FlexibleSchema<import("@ai-sdk/provider-utils").Context> | undefined;
182
+ needsApproval?: boolean | import("@ai-sdk/provider-utils").ToolNeedsApprovalFunction<{
183
+ task: string;
184
+ tools?: ("listFiles" | "readFile" | "grep" | "replaceLines" | "writeFile" | "editFile" | "bash" | "fetch" | "readToolOutput")[] | undefined;
185
+ maxSteps?: number | undefined;
186
+ }, NoInfer<import("@ai-sdk/provider-utils").Context>> | undefined;
187
+ onInputStart?: ((options: import("ai").ToolExecutionOptions<NoInfer<import("@ai-sdk/provider-utils").Context>>) => void | PromiseLike<void>) | undefined;
188
+ onInputDelta?: ((options: {
189
+ inputTextDelta: string;
190
+ } & import("ai").ToolExecutionOptions<NoInfer<import("@ai-sdk/provider-utils").Context>>) => void | PromiseLike<void>) | undefined;
191
+ onInputAvailable?: ((options: {
192
+ input: {
193
+ task: string;
194
+ tools?: ("listFiles" | "readFile" | "grep" | "replaceLines" | "writeFile" | "editFile" | "bash" | "fetch" | "readToolOutput")[] | undefined;
195
+ maxSteps?: number | undefined;
196
+ };
197
+ } & import("ai").ToolExecutionOptions<NoInfer<import("@ai-sdk/provider-utils").Context>>) => void | PromiseLike<void>) | undefined;
198
+ toModelOutput?: ((options: {
199
+ toolCallId: string;
200
+ input: {
201
+ task: string;
202
+ tools?: ("listFiles" | "readFile" | "grep" | "replaceLines" | "writeFile" | "editFile" | "bash" | "fetch" | "readToolOutput")[] | undefined;
203
+ maxSteps?: number | undefined;
204
+ };
205
+ output: NoInfer<SubagentResult>;
206
+ }) => import("@ai-sdk/provider-utils").ToolResultOutput | PromiseLike<import("@ai-sdk/provider-utils").ToolResultOutput>) | undefined;
207
+ } & {
208
+ outputSchema?: import("ai").FlexibleSchema<SubagentResult> | undefined;
209
+ execute: import("ai").ToolExecuteFunction<{
210
+ task: string;
211
+ tools?: ("listFiles" | "readFile" | "grep" | "replaceLines" | "writeFile" | "editFile" | "bash" | "fetch" | "readToolOutput")[] | undefined;
212
+ maxSteps?: number | undefined;
213
+ }, SubagentResult, NoInfer<import("@ai-sdk/provider-utils").Context>>;
214
+ } & {
215
+ type: "provider";
216
+ id: `${string}.${string}`;
217
+ args: Record<string, unknown>;
218
+ description?: never;
219
+ strict?: never;
220
+ inputExamples?: never;
221
+ } & {
222
+ isProviderExecuted: false;
223
+ supportsDeferredResults?: never;
224
+ } & {
225
+ execute: import("ai").ToolExecuteFunction<{
226
+ task: string;
227
+ tools?: ("listFiles" | "readFile" | "grep" | "replaceLines" | "writeFile" | "editFile" | "bash" | "fetch" | "readToolOutput")[] | undefined;
228
+ maxSteps?: number | undefined;
229
+ }, SubagentResult, NoInfer<import("@ai-sdk/provider-utils").Context>>;
230
+ }) | ({
231
+ title?: string;
232
+ providerOptions?: import("@ai-sdk/provider-utils").ProviderOptions;
233
+ metadata?: import("@ai-sdk/provider").JSONObject;
234
+ inputSchema: import("ai").FlexibleSchema<{
235
+ task: string;
236
+ tools?: ("listFiles" | "readFile" | "grep" | "replaceLines" | "writeFile" | "editFile" | "bash" | "fetch" | "readToolOutput")[] | undefined;
237
+ maxSteps?: number | undefined;
238
+ }>;
239
+ contextSchema?: import("ai").FlexibleSchema<import("@ai-sdk/provider-utils").Context> | undefined;
240
+ needsApproval?: boolean | import("@ai-sdk/provider-utils").ToolNeedsApprovalFunction<{
241
+ task: string;
242
+ tools?: ("listFiles" | "readFile" | "grep" | "replaceLines" | "writeFile" | "editFile" | "bash" | "fetch" | "readToolOutput")[] | undefined;
243
+ maxSteps?: number | undefined;
244
+ }, NoInfer<import("@ai-sdk/provider-utils").Context>> | undefined;
245
+ onInputStart?: ((options: import("ai").ToolExecutionOptions<NoInfer<import("@ai-sdk/provider-utils").Context>>) => void | PromiseLike<void>) | undefined;
246
+ onInputDelta?: ((options: {
247
+ inputTextDelta: string;
248
+ } & import("ai").ToolExecutionOptions<NoInfer<import("@ai-sdk/provider-utils").Context>>) => void | PromiseLike<void>) | undefined;
249
+ onInputAvailable?: ((options: {
250
+ input: {
251
+ task: string;
252
+ tools?: ("listFiles" | "readFile" | "grep" | "replaceLines" | "writeFile" | "editFile" | "bash" | "fetch" | "readToolOutput")[] | undefined;
253
+ maxSteps?: number | undefined;
254
+ };
255
+ } & import("ai").ToolExecutionOptions<NoInfer<import("@ai-sdk/provider-utils").Context>>) => void | PromiseLike<void>) | undefined;
256
+ toModelOutput?: ((options: {
257
+ toolCallId: string;
258
+ input: {
259
+ task: string;
260
+ tools?: ("listFiles" | "readFile" | "grep" | "replaceLines" | "writeFile" | "editFile" | "bash" | "fetch" | "readToolOutput")[] | undefined;
261
+ maxSteps?: number | undefined;
262
+ };
263
+ output: NoInfer<SubagentResult>;
264
+ }) => import("@ai-sdk/provider-utils").ToolResultOutput | PromiseLike<import("@ai-sdk/provider-utils").ToolResultOutput>) | undefined;
265
+ } & {
266
+ outputSchema?: import("ai").FlexibleSchema<SubagentResult> | undefined;
267
+ execute: import("ai").ToolExecuteFunction<{
268
+ task: string;
269
+ tools?: ("listFiles" | "readFile" | "grep" | "replaceLines" | "writeFile" | "editFile" | "bash" | "fetch" | "readToolOutput")[] | undefined;
270
+ maxSteps?: number | undefined;
271
+ }, SubagentResult, NoInfer<import("@ai-sdk/provider-utils").Context>>;
272
+ } & {
273
+ type: "provider";
274
+ id: `${string}.${string}`;
275
+ args: Record<string, unknown>;
276
+ description?: never;
277
+ strict?: never;
278
+ inputExamples?: never;
279
+ } & {
280
+ isProviderExecuted: true;
281
+ supportsDeferredResults?: boolean;
282
+ } & {
283
+ execute: import("ai").ToolExecuteFunction<{
284
+ task: string;
285
+ tools?: ("listFiles" | "readFile" | "grep" | "replaceLines" | "writeFile" | "editFile" | "bash" | "fetch" | "readToolOutput")[] | undefined;
286
+ maxSteps?: number | undefined;
287
+ }, SubagentResult, NoInfer<import("@ai-sdk/provider-utils").Context>>;
288
+ });
46
289
  export {};
@@ -1,7 +1,9 @@
1
- import { streamText, stepCountIs, tool } from 'ai';
1
+ import { streamText, isStepCount, tool } from 'ai';
2
2
  import { z } from 'zod';
3
3
  import { buildSubagentPrompt } from '../../llm/systemPrompt.js';
4
4
  import { hazeTools } from '../../llm/hazeTools.js';
5
+ import { toolsContextFor } from '../../llm/tools/toolContext.js';
6
+ import { toolOnlyStepCount } from '../agent/turnPolicy.js';
5
7
  const ALL_TOOLS = ['listFiles', 'readFile', 'grep', 'bash', 'readToolOutput', 'editFile', 'replaceLines', 'writeFile', 'fetch'];
6
8
  const STEP_LIMIT = 25;
7
9
  const MAX_SUMMARY = 4000;
@@ -11,7 +13,7 @@ function toolSummary(output) {
11
13
  return 'completed';
12
14
  const o = output;
13
15
  if (typeof o.totalMatches === 'number')
14
- return o.totalMatches === 0 ? 'no matches' : `${o.totalMatches} matches`;
16
+ return o.totalMatches === 0 ? 'no matches' : `${o.matchCountIsLowerBound === true ? 'at least ' : ''}${o.totalMatches} matches`;
15
17
  if (typeof o.code === 'number')
16
18
  return `exit ${o.code}`;
17
19
  if (o.ok === true)
@@ -20,15 +22,6 @@ function toolSummary(output) {
20
22
  return `failed: ${o.error.slice(0, 120)}`;
21
23
  return 'completed';
22
24
  }
23
- function toolOnlyStepCount(steps) {
24
- let count = 0;
25
- for (const step of [...steps].reverse()) {
26
- if (step.toolCalls.length === 0 || step.text.trim().length > 0)
27
- break;
28
- count += 1;
29
- }
30
- return count;
31
- }
32
25
  export const internals = { toolSummary, toolOnlyStepCount };
33
26
  export async function runSubagent(task, options) {
34
27
  const start = performance.now();
@@ -41,6 +34,7 @@ export async function runSubagent(task, options) {
41
34
  scopedTools[name] = hazeTools[key];
42
35
  }
43
36
  const toolCallLog = [];
37
+ const toolExecutionContext = { inFlightToolCalls: new Map() };
44
38
  let tokensIn = 0;
45
39
  let tokensOut = 0;
46
40
  let lastStep = 0;
@@ -49,12 +43,13 @@ export async function runSubagent(task, options) {
49
43
  const result = streamText({
50
44
  model: options.model,
51
45
  maxOutputTokens: 4096,
52
- system: buildSubagentPrompt(options.contextFiles, options.session),
46
+ instructions: buildSubagentPrompt(options.contextFiles, options.session),
53
47
  messages: [{ role: 'user', content: task }],
54
48
  tools: scopedTools,
55
- stopWhen: stepCountIs(maxSteps),
49
+ stopWhen: isStepCount(maxSteps),
56
50
  abortSignal: options.abortSignal,
57
- experimental_context: { inFlightToolCalls: new Map() },
51
+ runtimeContext: toolExecutionContext,
52
+ toolsContext: toolsContextFor(scopedTools, toolExecutionContext),
58
53
  prepareStep({ steps }) {
59
54
  const calls = steps.flatMap(step => step.toolCalls);
60
55
  const consecutiveToolOnly = toolOnlyStepCount(steps);
@@ -68,23 +63,23 @@ export async function runSubagent(task, options) {
68
63
  }
69
64
  return undefined;
70
65
  },
71
- onStepFinish({ stepNumber }) {
66
+ onStepEnd({ stepNumber }) {
72
67
  lastStep = stepNumber;
73
68
  },
74
- onFinish(event) {
69
+ onEnd(event) {
75
70
  if (event.usage) {
76
71
  tokensIn = event.usage.inputTokens ?? 0;
77
72
  tokensOut = event.usage.outputTokens ?? 0;
78
73
  }
79
74
  },
80
- experimental_onToolCallFinish(event) {
75
+ onToolExecutionEnd(event) {
81
76
  if (!event.toolCall)
82
77
  return;
83
78
  totalToolCalls += 1;
84
79
  toolCallLog.push({
85
80
  name: event.toolCall.toolName,
86
- summary: toolSummary(event.output),
87
- durationMs: event.durationMs,
81
+ summary: event.toolOutput.type === 'tool-result' ? toolSummary(event.toolOutput.output) : `failed: ${String(event.toolOutput.error).slice(0, 120)}`,
82
+ durationMs: event.toolExecutionMs,
88
83
  });
89
84
  },
90
85
  });
@@ -1,4 +1,5 @@
1
1
  export type ReductionPressure = 'conservative' | 'normal' | 'aggressive';
2
+ export declare const PROCESSING_OUTPUT_CHAR_LIMIT = 200000;
2
3
  export type ReductionContentKind = 'validation' | 'log' | 'search' | 'diff' | 'json' | 'table' | 'web' | 'source-outline' | 'generic';
3
4
  export type ReductionParseTier = 'full' | 'degraded' | 'passthrough';
4
5
  export interface ReductionMetrics {
@@ -20,6 +21,7 @@ export interface ToolOutputReductionMetadata extends ReductionMetrics {
20
21
  warning?: string;
21
22
  }
22
23
  export declare function estimateReductionTokens(text: string): number;
24
+ export declare function capOutputForProcessing(text: string, maxChars?: number): string;
23
25
  export declare function reductionMetrics(raw: string, returned: string): ReductionMetrics;
24
26
  export declare function retrievalHint(handle: string): string;
25
27
  export declare function isInflating(raw: string, returned: string): boolean;
@@ -1,6 +1,18 @@
1
+ export const PROCESSING_OUTPUT_CHAR_LIMIT = 200_000;
2
+ const PROCESSING_TRUNCATION_MARKER = '\n[... output truncated for processing ...]\n';
1
3
  export function estimateReductionTokens(text) {
2
4
  return Math.ceil(text.length / 4);
3
5
  }
6
+ export function capOutputForProcessing(text, maxChars = PROCESSING_OUTPUT_CHAR_LIMIT) {
7
+ if (text.length <= maxChars)
8
+ return text;
9
+ if (maxChars <= PROCESSING_TRUNCATION_MARKER.length)
10
+ return text.slice(0, maxChars);
11
+ const keepChars = maxChars - PROCESSING_TRUNCATION_MARKER.length;
12
+ const headChars = Math.floor(keepChars / 2);
13
+ const tailChars = keepChars - headChars;
14
+ return `${text.slice(0, headChars)}${PROCESSING_TRUNCATION_MARKER}${text.slice(-tailChars)}`;
15
+ }
4
16
  export function reductionMetrics(raw, returned) {
5
17
  const rawTokensEstimate = estimateReductionTokens(raw);
6
18
  const returnedTokensEstimate = estimateReductionTokens(returned);
@@ -1,3 +1,4 @@
1
+ import { capOutputForProcessing } from '../toolOutput/reduction.js';
1
2
  function uniq(values) {
2
3
  return [...new Set(values.filter(Boolean))];
3
4
  }
@@ -14,13 +15,14 @@ function inferKind(command, classification) {
14
15
  return 'generic';
15
16
  }
16
17
  export function parseValidationOutput(input) {
17
- const text = `${input.stdout}\n${input.stderr}`;
18
+ const text = `${capOutputForProcessing(input.stdout)}\n${capOutputForProcessing(input.stderr)}`;
18
19
  const lines = text.split(/\r?\n/);
19
20
  const diagnostics = [];
20
21
  const failedTests = [];
21
22
  const failedFiles = [];
22
23
  const kind = inferKind(input.command, input.classification);
23
- for (const line of lines) {
24
+ for (let index = 0; index < lines.length; index++) {
25
+ const line = lines[index];
24
26
  const ts = line.match(/^(.+?\.(?:ts|tsx|js|jsx|mts|cts))\((\d+),(\d+)\):\s+(error|warning)\s+TS\d+:\s+(.+)$/);
25
27
  if (ts) {
26
28
  const [, file, lineNo, column, severity, message] = ts;
@@ -31,7 +33,7 @@ export function parseValidationOutput(input) {
31
33
  const eslint = line.match(/^(.+?\.(?:ts|tsx|js|jsx|mts|cts))\s*$/);
32
34
  if (eslint) {
33
35
  const currentFile = eslint[1] ?? '';
34
- const next = lines[lines.indexOf(line) + 1];
36
+ const next = lines[index + 1];
35
37
  if (next && /^\s*\d+:\d+\s+/.test(next))
36
38
  failedFiles.push(currentFile);
37
39
  }
@@ -17,7 +17,7 @@ export declare function modelWithConfig(session?: {
17
17
  cwd?: string;
18
18
  modelSelector?: string;
19
19
  }): Promise<{
20
- model: import("@ai-sdk/provider").LanguageModelV3;
20
+ model: import("@ai-sdk/provider").LanguageModelV4;
21
21
  config: {
22
22
  providerName: string;
23
23
  baseURL: string;
@@ -26,7 +26,7 @@ export declare function modelWithConfig(session?: {
26
26
  capabilities: ProviderCapabilities;
27
27
  };
28
28
  } | undefined>;
29
- export declare function model(): Promise<import("@ai-sdk/provider").LanguageModelV3 | undefined>;
29
+ export declare function model(): Promise<import("@ai-sdk/provider").LanguageModelV4 | undefined>;
30
30
  export declare function cacheKeyFor(name: string, cwd?: string): string;
31
31
  export declare function providerRequestSettings(config: ModelRuntimeConfig): {
32
32
  headers?: {
@@ -2,9 +2,23 @@ import { createOpenAI } from '@ai-sdk/openai';
2
2
  import crypto from 'node:crypto';
3
3
  import { readSettings } from '../config/settings.js';
4
4
  import { activeModel, resolveModelSelector } from '../config/providers.js';
5
+ import { assertCredentialedEndpointSecure } from '../config/endpointSecurity.js';
6
+ const HAZE_SITE_URL = 'https://denizokcu.github.io/haze/';
7
+ const HAZE_TITLE = 'Haze';
8
+ function isOpenRouter(providerName, baseURL) {
9
+ return providerName === 'openrouter' || /openrouter\.ai/i.test(baseURL);
10
+ }
11
+ function openRouterHeaders(providerName, baseURL) {
12
+ if (!isOpenRouter(providerName, baseURL))
13
+ return undefined;
14
+ return {
15
+ 'HTTP-Referer': HAZE_SITE_URL,
16
+ 'X-Title': HAZE_TITLE,
17
+ };
18
+ }
5
19
  function capabilities(providerName, baseURL) {
6
20
  const directOpenAI = providerName === 'openai' || /api\.openai\.com/i.test(baseURL);
7
- const openRouter = providerName === 'openrouter' || /openrouter\.ai/i.test(baseURL);
21
+ const openRouter = isOpenRouter(providerName, baseURL);
8
22
  return {
9
23
  reportsCacheUsage: directOpenAI || openRouter,
10
24
  supportsPromptCacheKey: directOpenAI,
@@ -29,12 +43,14 @@ export async function modelWithConfig(session) {
29
43
  if (!selection)
30
44
  return undefined;
31
45
  const baseURL = selection.provider.url;
32
- const apiKey = selection.provider.key ?? settings.apiKey ?? 'not-needed';
46
+ const configuredKey = selection.provider.key ?? settings.apiKey;
47
+ assertCredentialedEndpointSecure(baseURL, configuredKey);
48
+ const apiKey = configuredKey ?? 'not-needed';
33
49
  const name = selection.model;
34
50
  const cacheSeed = session?.cwd ?? process.cwd();
35
51
  const cacheKey = crypto.createHash('sha256').update(`${cacheSeed}\0${name}`).digest('hex').slice(0, 32);
36
52
  return {
37
- model: createOpenAI({ apiKey, baseURL }).chat(name),
53
+ model: createOpenAI({ apiKey, baseURL, headers: openRouterHeaders(selection.provider.name, baseURL) }).chat(name),
38
54
  config: {
39
55
  providerName: selection.provider.name,
40
56
  baseURL,