@denizokcu/haze 0.1.1 → 0.3.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.
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Known provider presets derived from community conventions (nanocoder, OpenRouter docs, etc.).
3
+ * Each preset carries a pre-configured base URL so users only need to supply an API key and model names.
4
+ * Local/keyless providers have sensible localhost defaults.
5
+ */
6
+ export interface ProviderPreset {
7
+ /** Unique identifier used as the selection value. */
8
+ id: string;
9
+ /** Human-readable name shown in the picker. */
10
+ name: string;
11
+ /** Pre-configured OpenAI-compatible base URL. */
12
+ baseUrl: string;
13
+ /** Whether an API key is typically required. Local providers default to false. */
14
+ needsApiKey: boolean;
15
+ /** Hint shown when prompting for the API key. */
16
+ apiKeyHint?: string;
17
+ /** Optional suggested default model(s). */
18
+ suggestedModels?: string[];
19
+ /** Category for grouping in the picker. */
20
+ category: 'cloud' | 'local';
21
+ }
22
+ export declare const PROVIDER_PRESETS: ProviderPreset[];
23
+ export declare function findPreset(id: string): ProviderPreset | undefined;
@@ -0,0 +1,230 @@
1
+ /**
2
+ * Known provider presets derived from community conventions (nanocoder, OpenRouter docs, etc.).
3
+ * Each preset carries a pre-configured base URL so users only need to supply an API key and model names.
4
+ * Local/keyless providers have sensible localhost defaults.
5
+ */
6
+ export const PROVIDER_PRESETS = [
7
+ // ── Cloud providers (API key required) ──────────────────────────────
8
+ {
9
+ id: 'openrouter',
10
+ name: 'OpenRouter',
11
+ baseUrl: 'https://openrouter.ai/api/v1',
12
+ needsApiKey: true,
13
+ suggestedModels: [
14
+ // SOTA
15
+ 'anthropic/claude-opus-4.8',
16
+ 'openai/gpt-5.4',
17
+ 'google/gemini-3.1-pro',
18
+ // Fast
19
+ 'anthropic/claude-sonnet-4.6',
20
+ 'openai/gpt-5.4-mini',
21
+ 'google/gemini-3.5-flash',
22
+ 'deepseek/deepseek-v4-flash',
23
+ ],
24
+ category: 'cloud',
25
+ },
26
+ {
27
+ id: 'openai',
28
+ name: 'OpenAI',
29
+ baseUrl: 'https://api.openai.com/v1',
30
+ needsApiKey: true,
31
+ suggestedModels: [
32
+ // SOTA
33
+ 'gpt-5.5',
34
+ 'o3',
35
+ // Fast
36
+ 'gpt-5.4',
37
+ 'gpt-5.4-mini',
38
+ 'o4-mini',
39
+ ],
40
+ category: 'cloud',
41
+ },
42
+ {
43
+ id: 'anthropic',
44
+ name: 'Anthropic Claude',
45
+ baseUrl: 'https://api.anthropic.com/v1',
46
+ needsApiKey: true,
47
+ suggestedModels: [
48
+ // SOTA
49
+ 'claude-opus-4-8',
50
+ 'claude-fable-5',
51
+ // Fast
52
+ 'claude-sonnet-4-6',
53
+ 'claude-haiku-4-5',
54
+ ],
55
+ category: 'cloud',
56
+ },
57
+ {
58
+ id: 'google-gemini',
59
+ name: 'Google Gemini',
60
+ baseUrl: 'https://generativelanguage.googleapis.com/v1beta',
61
+ needsApiKey: true,
62
+ apiKeyHint: 'API Key (from https://aistudio.google.com/apikey)',
63
+ suggestedModels: [
64
+ // SOTA
65
+ 'gemini-3.5-flash',
66
+ 'gemini-3.1-pro',
67
+ // Fast
68
+ 'gemini-3.1-flash-lite',
69
+ 'gemini-2.5-flash',
70
+ 'gemini-2.5-pro',
71
+ ],
72
+ category: 'cloud',
73
+ },
74
+ {
75
+ id: 'mistral',
76
+ name: 'Mistral AI',
77
+ baseUrl: 'https://api.mistral.ai/v1',
78
+ needsApiKey: true,
79
+ suggestedModels: [
80
+ // SOTA
81
+ 'mistral-large-2512',
82
+ 'mistral-medium-3-5',
83
+ // Fast
84
+ 'mistral-small-2603',
85
+ 'codestral-2508',
86
+ ],
87
+ category: 'cloud',
88
+ },
89
+ {
90
+ id: 'z-ai',
91
+ name: 'Z.ai',
92
+ baseUrl: 'https://api.z.ai/api/paas/v4/',
93
+ needsApiKey: true,
94
+ suggestedModels: [
95
+ 'glm-5.1',
96
+ 'glm-5.1-fw',
97
+ ],
98
+ category: 'cloud',
99
+ },
100
+ {
101
+ id: 'z-ai-coding',
102
+ name: 'Z.ai Coding Subscription',
103
+ baseUrl: 'https://api.z.ai/api/coding/paas/v4/',
104
+ needsApiKey: true,
105
+ suggestedModels: [
106
+ 'glm-5.1',
107
+ 'glm-5.1-fw',
108
+ ],
109
+ category: 'cloud',
110
+ },
111
+ {
112
+ id: 'github-models',
113
+ name: 'GitHub Models',
114
+ baseUrl: 'https://models.github.ai/inference',
115
+ needsApiKey: true,
116
+ apiKeyHint: 'GitHub Token (PAT with models:read scope)',
117
+ suggestedModels: [
118
+ 'gpt-5.4',
119
+ 'gpt-5.4-mini',
120
+ 'claude-sonnet-4-6',
121
+ 'gemini-3.1-pro',
122
+ ],
123
+ category: 'cloud',
124
+ },
125
+ {
126
+ id: 'github-copilot',
127
+ name: 'GitHub Copilot',
128
+ baseUrl: 'https://api.githubcopilot.com',
129
+ needsApiKey: true,
130
+ apiKeyHint: 'GitHub Copilot token (OAuth)',
131
+ suggestedModels: [
132
+ 'gpt-5.4',
133
+ 'claude-fable-5',
134
+ 'claude-sonnet-4-6',
135
+ 'gemini-3.1-pro',
136
+ ],
137
+ category: 'cloud',
138
+ },
139
+ {
140
+ id: 'chatgpt-codex',
141
+ name: 'ChatGPT / Codex',
142
+ baseUrl: 'https://chatgpt.com/backend-api/codex',
143
+ needsApiKey: true,
144
+ apiKeyHint: 'ChatGPT session token (OAuth)',
145
+ suggestedModels: [
146
+ 'gpt-5.4',
147
+ 'o4-mini',
148
+ ],
149
+ category: 'cloud',
150
+ },
151
+ {
152
+ id: 'kimi-code',
153
+ name: 'Kimi Code',
154
+ baseUrl: 'https://api.kimi.com/coding/v1',
155
+ needsApiKey: true,
156
+ suggestedModels: [
157
+ 'kimi-for-coding',
158
+ ],
159
+ category: 'cloud',
160
+ },
161
+ {
162
+ id: 'minimax-coding',
163
+ name: 'MiniMax Coding Plan',
164
+ baseUrl: 'https://api.minimax.io/anthropic/v1',
165
+ needsApiKey: true,
166
+ suggestedModels: [
167
+ // SOTA
168
+ 'MiniMax-M3',
169
+ // Fast
170
+ 'MiniMax-M2.7',
171
+ ],
172
+ category: 'cloud',
173
+ },
174
+ {
175
+ id: 'poe',
176
+ name: 'Poe',
177
+ baseUrl: 'https://api.poe.com/v1',
178
+ needsApiKey: true,
179
+ apiKeyHint: 'API Key (from poe.com/api_key)',
180
+ suggestedModels: [
181
+ // SOTA
182
+ 'claude-opus-4.8',
183
+ 'gpt-5.5',
184
+ 'gemini-3.5-flash',
185
+ // Fast
186
+ 'gpt-5.4-mini',
187
+ 'claude-sonnet-4.6',
188
+ 'kimi-k2.5',
189
+ ],
190
+ category: 'cloud',
191
+ },
192
+ // ── Local providers (no API key) ────────────────────────────────────
193
+ {
194
+ id: 'ollama',
195
+ name: 'Ollama',
196
+ baseUrl: 'http://localhost:11434/v1',
197
+ needsApiKey: false,
198
+ suggestedModels: [
199
+ 'qwen3-coder',
200
+ 'devstral-small-2512',
201
+ 'gemma4:26b',
202
+ 'llama4:scout',
203
+ ],
204
+ category: 'local',
205
+ },
206
+ {
207
+ id: 'llamacpp',
208
+ name: 'llama.cpp server',
209
+ baseUrl: 'http://localhost:8080/v1',
210
+ needsApiKey: false,
211
+ category: 'local',
212
+ },
213
+ {
214
+ id: 'mlx-server',
215
+ name: 'MLX Server',
216
+ baseUrl: 'http://localhost:8080/v1',
217
+ needsApiKey: false,
218
+ category: 'local',
219
+ },
220
+ {
221
+ id: 'lmstudio',
222
+ name: 'LM Studio',
223
+ baseUrl: 'http://localhost:1234/v1',
224
+ needsApiKey: false,
225
+ category: 'local',
226
+ },
227
+ ];
228
+ export function findPreset(id) {
229
+ return PROVIDER_PRESETS.find(preset => preset.id === id);
230
+ }
@@ -18,7 +18,9 @@ export function compactModelMessages(messages, options = {}) {
18
18
  return text ? `- ${message.role}: ${text.slice(0, 500)}` : '';
19
19
  }).filter(Boolean).join('\n');
20
20
  const summary = [
21
- 'Compacted prior Haze conversation. Continue preserving the user goal, constraints, decisions, files touched, validation results, and unresolved next steps from this summary.',
21
+ 'Compacted prior Haze conversation. Treat this as continuity context, not a new user request.',
22
+ '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.',
23
+ 'Do not treat older tool outputs as current unless the recent conversation confirms they still apply.',
22
24
  options.instructions ? `User compaction instructions: ${options.instructions}` : undefined,
23
25
  '',
24
26
  'Older context summary:',
@@ -13,6 +13,7 @@ export interface CompletionPolicyInput {
13
13
  validationToolFailed: boolean;
14
14
  editFileFailed: boolean;
15
15
  editRecoveryPath?: string;
16
+ editRecoveryReasonCode?: string;
16
17
  }
17
18
  export interface CompletionDecision {
18
19
  needsActionContinuation: boolean;
@@ -25,4 +26,4 @@ export interface CompletionDecision {
25
26
  export declare function completionDecision(input: CompletionPolicyInput): CompletionDecision;
26
27
  export declare function toolLoopBudgetPrompt(): string;
27
28
  export declare function postContinuationPrompt(): string;
28
- export declare function noTextAfterToolPrompt(allowTools: boolean): "Continue the original request now. If it asks for a change, edit or write the necessary files. If it asks to run or verify tests, run the command. Do not provide only a retrospective summary unless blocked." | "Continue from the tool result and answer my original request. Do not call tools. Summarize only current-turn changes and validation; do not recap unrelated earlier tasks.";
29
+ export declare function noTextAfterToolPrompt(allowTools: boolean): "Continue the original request now. If it asks for a change, edit or write the necessary files. If it asks to run or verify tests, run the command. Do not provide only a retrospective summary unless blocked or needing a user decision." | "Continue from the tool result and answer my original request. Do not call tools. Use the final status template for implementation-like requests; summarize only current-turn changes and validation; do not recap unrelated earlier tasks.";
@@ -44,23 +44,30 @@ export function completionDecision(input) {
44
44
  && !requestCompletedByTools
45
45
  && !input.validationToolSucceeded
46
46
  && !assistantReportsBlocker;
47
+ const stateLines = [
48
+ `User goal: ${input.request}`,
49
+ input.editRecoveryPath ? `Edit recovery path: ${input.editRecoveryPath}` : undefined,
50
+ input.editRecoveryReasonCode ? `Edit failure reason: ${input.editRecoveryReasonCode}` : undefined,
51
+ input.mutatingToolSucceeded ? 'Files changed in this turn: yes' : 'Files changed in this turn: no',
52
+ input.validationToolSucceeded ? 'Validation status: passed' : input.validationToolFailed ? 'Validation status: failed' : 'Validation status: not run',
53
+ ].filter((line) => line !== undefined).join('\n');
47
54
  let continuationPrompt;
48
55
  if (input.editFileFailed) {
49
- continuationPrompt = 'Your editFile attempt failed. Use the latest readFile line-numbered output and replaceLines to complete the requested change. Continue with any remaining tests or validation if relevant. Do not stop with a summary.';
56
+ continuationPrompt = `State:\n${stateLines}\n\nRequired next action: call readFile on the exact edit recovery path first. Then use the latest line-numbered output with replaceLines, or a corrected editFile call, to complete the requested change. Continue with relevant validation if practical. Do not stop with a summary while tools are available.`;
50
57
  }
51
58
  else if (input.validationToolFailed && input.mutatingToolSucceeded) {
52
- continuationPrompt = 'Validation failed after files changed in this task. Inspect the failure output, fix failures that are plausibly caused by the current change, then rerun the relevant validation once. If the failure is clearly unrelated or environment-specific, summarize the blocker instead of expanding scope.';
59
+ continuationPrompt = `State:\n${stateLines}\n\nRequired next action: Validation failed after files changed in this task. Use the validation summary/output to inspect the first relevant failure, make one focused fix if it is plausibly caused by this change, then rerun the same relevant validation once. If it is an environment/dependency/unrelated failure, finish with Status: blocked or Status: partial and concrete evidence.`;
53
60
  }
54
61
  else if (needsValidationContinuation) {
55
62
  continuationPrompt = changedActionNeedsValidation
56
- ? 'Files changed for this request, but no validation has run yet. Continue by running the smallest relevant test/check command you can identify from the project. If no practical validation exists, state that concrete blocker briefly instead of claiming the goal is complete.'
57
- : 'You have not run the requested validation yet. Continue now by running the appropriate test/check command. Summarize only after the command finishes.';
63
+ ? `State:\n${stateLines}\n\nRequired next action: files changed for this request, but no validation has run. Run the smallest relevant test/typecheck/build command you can identify. If no practical validation exists, finish with the final status template and say why validation was not run.`
64
+ : `State:\n${stateLines}\n\nRequired next action: run the requested validation now. Summarize only after the command finishes.`;
58
65
  }
59
66
  else if (input.mutatingToolSucceeded && assistantAdmitsIncomplete) {
60
- continuationPrompt = 'Your previous response says the current request is incomplete. Continue now with the remaining edits and validation for this same request. Do not summarize a plan unless blocked.';
67
+ continuationPrompt = `State:\n${stateLines}\n\nRequired next action: your previous response described unfinished work. Continue with the remaining in-scope edits and validation for this same request. Do not summarize a plan unless concretely blocked.`;
61
68
  }
62
69
  else if (needsActionContinuation) {
63
- continuationPrompt = 'You inspected files but have not made the requested change yet. Continue now by editing or writing the necessary files. Do not summarize a plan unless blocked.';
70
+ continuationPrompt = `State:\n${stateLines}\n\nRequired next action: you inspected files but have not made the requested change yet. Edit or write the necessary files now. Do not summarize a plan unless concretely blocked.`;
64
71
  }
65
72
  return {
66
73
  needsActionContinuation,
@@ -72,13 +79,13 @@ export function completionDecision(input) {
72
79
  };
73
80
  }
74
81
  export function toolLoopBudgetPrompt() {
75
- return 'Tool slice reached for this model step. Do not output XML, JSON tool-call syntax, <tool_call> blocks, or function-call markup. If the current request is complete, summarize only current-turn changes and validation. If the requested change is incomplete, state the next concrete unfinished action briefly so Haze can continue autonomously in a fresh tool slice. Do not claim tools are unavailable, recap unrelated earlier tasks, or provide a generic remains list.';
82
+ return 'Tool slice reached for this model step. Do not output XML, JSON tool-call syntax, <tool_call> blocks, or function-call markup. If the current request is complete, answer with the final status template using only current-turn changes and validation evidence. If incomplete, state the single next concrete unfinished action so Haze can continue autonomously in a fresh tool slice. Do not claim tools are unavailable, recap unrelated earlier tasks, or provide a generic remains list.';
76
83
  }
77
84
  export function postContinuationPrompt() {
78
- return 'Your previous response still described unfinished work, missing validation, or a tool-budget issue. If any tools are still available, complete the remaining edit or run the final validation now. Only call something a blocker if a concrete tool failure prevents progress.';
85
+ return 'Your previous response still described unfinished work, missing validation, or a tool-budget issue. If tools are available, complete the remaining edit or run the final validation now. Only call something blocked for a concrete tool failure, missing dependency/permission, or unavoidable ambiguity.';
79
86
  }
80
87
  export function noTextAfterToolPrompt(allowTools) {
81
88
  return allowTools
82
- ? 'Continue the original request now. If it asks for a change, edit or write the necessary files. If it asks to run or verify tests, run the command. Do not provide only a retrospective summary unless blocked.'
83
- : 'Continue from the tool result and answer my original request. Do not call tools. Summarize only current-turn changes and validation; do not recap unrelated earlier tasks.';
89
+ ? 'Continue the original request now. If it asks for a change, edit or write the necessary files. If it asks to run or verify tests, run the command. Do not provide only a retrospective summary unless blocked or needing a user decision.'
90
+ : 'Continue from the tool result and answer my original request. Do not call tools. Use the final status template for implementation-like requests; summarize only current-turn changes and validation; do not recap unrelated earlier tasks.';
84
91
  }
@@ -0,0 +1,10 @@
1
+ export type BashRiskLevel = 'read_only' | 'mutating' | 'destructive' | 'network' | 'unknown';
2
+ export type BashTrait = 'reads_files' | 'writes_files' | 'deletes_files' | 'installs_dependencies' | 'runs_tests' | 'runs_build' | 'uses_network' | 'changes_git_state' | 'changes_permissions';
3
+ export type BashClassification = {
4
+ riskLevel: BashRiskLevel;
5
+ traits: BashTrait[];
6
+ confidence: 'high' | 'medium' | 'low';
7
+ reason: string;
8
+ };
9
+ export declare function classifyBashCommand(command: string): BashClassification;
10
+ export declare function isValidationClassification(classification: BashClassification): boolean;
@@ -0,0 +1,51 @@
1
+ function has(command, pattern) {
2
+ return pattern.test(command);
3
+ }
4
+ function uniq(values) {
5
+ return [...new Set(values)];
6
+ }
7
+ export function classifyBashCommand(command) {
8
+ const trimmed = command.trim();
9
+ const traits = [];
10
+ const lower = trimmed.toLowerCase();
11
+ const complex = /[`$()]|\b(eval|xargs|sh\s+-c|bash\s+-c)\b/.test(trimmed);
12
+ if (!trimmed) {
13
+ return { riskLevel: 'unknown', traits: [], confidence: 'high', reason: 'empty command' };
14
+ }
15
+ if (has(lower, /(^|[;&|]\s*)(rm\b|rm\s+-|git\s+reset\s+--hard\b|git\s+clean\b|git\s+restore\s+\.|git\s+checkout\s+--\b)/) || has(lower, /push\b.*--force|drop\s+database|truncate\s+table/)) {
16
+ if (has(lower, /\brm\b|git\s+clean|git\s+restore|git\s+checkout\s+--|drop\s+database|truncate\s+table/))
17
+ traits.push('deletes_files');
18
+ if (has(lower, /\bgit\b/))
19
+ traits.push('changes_git_state');
20
+ return { riskLevel: 'destructive', traits: uniq(traits), confidence: complex ? 'medium' : 'high', reason: 'command can delete files or irreversibly change repository state' };
21
+ }
22
+ if (has(lower, /(^|[;&|]\s*)(curl\b|wget\b|scp\b|ssh\b|npm\s+(install|i|add)\b|pnpm\s+(install|add)\b|yarn\s+(add|install)\b|pip\s+install\b|brew\s+install\b)/)) {
23
+ traits.push('uses_network');
24
+ if (has(lower, /\b(npm|pnpm|yarn|pip|brew)\b/))
25
+ traits.push('installs_dependencies', 'writes_files');
26
+ return { riskLevel: has(lower, /\b(curl|wget|scp|ssh)\b/) && !has(lower, /\binstall|\badd\b/) ? 'network' : 'mutating', traits: uniq(traits), confidence: complex ? 'medium' : 'high', reason: 'command uses the network or installs dependencies' };
27
+ }
28
+ if (has(trimmed, /(^|\s)(>|>>)(\s|\S)/) || has(lower, /(^|[;&|]\s*)(sed\s+-i|perl\s+-pi|tee\b|chmod\b|mv\b|cp\b|mkdir\b|touch\b|git\s+(add|commit|merge|rebase|checkout|restore)\b)/) || has(trimmed, /\b(File\.write|writeFileSync|writeFile|appendFileSync|appendFile)\b/)) {
29
+ traits.push('writes_files');
30
+ if (has(lower, /\bchmod\b/))
31
+ traits.push('changes_permissions');
32
+ if (has(lower, /\bgit\b/))
33
+ traits.push('changes_git_state');
34
+ return { riskLevel: 'mutating', traits: uniq(traits), confidence: complex ? 'medium' : 'high', reason: 'command can modify files or repository state' };
35
+ }
36
+ if (has(lower, /(^|[;&|]\s*)(npm\s+test|npm\s+run\s+(test|typecheck|lint|build)|pnpm\s+(test|run\s+(test|typecheck|lint|build))|yarn\s+(test|run\s+(test|typecheck|lint|build))|vitest\b|jest\b|tsc\b|eslint\b)/)) {
37
+ if (has(lower, /test|vitest|jest/))
38
+ traits.push('runs_tests');
39
+ if (has(lower, /build|tsc|typecheck|lint|eslint/))
40
+ traits.push('runs_build');
41
+ return { riskLevel: 'read_only', traits: uniq(traits), confidence: complex ? 'medium' : 'high', reason: 'validation command' };
42
+ }
43
+ if (has(lower, /(^|[;&|]\s*)(git\s+(status|diff|log|show|branch)\b|rg\b|grep\b|find\b|ls\b|pwd\b|cat\b|head\b|tail\b|node\s+--version|npm\s+--version|which\b)/)) {
44
+ traits.push('reads_files');
45
+ return { riskLevel: complex ? 'unknown' : 'read_only', traits: uniq(traits), confidence: complex ? 'low' : 'high', reason: complex ? 'read-like command with complex shell syntax' : 'read-only inspection command' };
46
+ }
47
+ return { riskLevel: 'unknown', traits: [], confidence: 'low', reason: 'command did not match known safe patterns' };
48
+ }
49
+ export function isValidationClassification(classification) {
50
+ return classification.traits.includes('runs_tests') || classification.traits.includes('runs_build');
51
+ }
@@ -28,6 +28,6 @@ export declare function createSubagentTool(options: {
28
28
  contextFiles: ContextFile[];
29
29
  }): import("ai").Tool<{
30
30
  task: string;
31
- tools?: ("editFile" | "replaceLines" | "writeFile" | "listFiles" | "readFile" | "grep" | "bash")[] | undefined;
31
+ tools?: ("listFiles" | "editFile" | "replaceLines" | "writeFile" | "readFile" | "grep" | "bash")[] | undefined;
32
32
  maxSteps?: number | undefined;
33
33
  }, SubagentResult>;
@@ -2,15 +2,17 @@ import { streamText, stepCountIs, tool } from 'ai';
2
2
  import { z } from 'zod';
3
3
  import { buildSystemPrompt } from '../../llm/systemPrompt.js';
4
4
  import { hazeTools } from '../../llm/hazeTools.js';
5
- const SUBAGENT_SYSTEM_PROMPT = `You are a focused subagent. Complete the assigned task using all tools available to you, then return a clear summary.
5
+ const SUBAGENT_SYSTEM_PROMPT = `You are a focused subagent for a professional developer workflow. Complete the assigned task autonomously using the available tools, then return a clear summary.
6
6
 
7
7
  Rules:
8
- - Use whatever tools you need. You have full access to file tools and bash.
9
- - If the task requires creating or modifying files, do it directly — do not ask for permission.
10
- - If a tool fails, read the file again and retry with the correct content.
11
- - After completing the task, summarize what you did, what files you created or changed, and any important findings.
8
+ - Use whatever tools you need within the assigned scope. You have full access to file tools and bash.
9
+ - If the task requires creating or modifying files, do it directly with file tools or an efficient non-destructive shell command; do not ask for permission for ordinary edits.
10
+ - Assume expert users understand what they asked for. Do not ask for command confirmations; run relevant commands directly.
11
+ - Destructive and ordinary professional workflows should proceed without extra ceremony when they are relevant to the assigned task.
12
+ - If a file edit tool fails, read the exact file again and retry once with current content or line numbers.
13
+ - After completing the task, summarize what you did, what files you created or changed, validation run, and important findings.
12
14
  - If you cannot complete the task, explain exactly what blocked you and what you tried.
13
- - Your summary is all the parent agent will see. Be specific: include file paths, function names, and concrete results.`;
15
+ - Your summary is all the parent agent will see. Be specific: include file paths, function names, command results, and concrete next steps.`;
14
16
  const ALL_TOOLS = ['listFiles', 'readFile', 'grep', 'bash', 'editFile', 'replaceLines', 'writeFile'];
15
17
  const STEP_LIMIT = 25;
16
18
  const MAX_SUMMARY = 4000;
@@ -56,7 +58,6 @@ export async function runSubagent(task, options) {
56
58
  try {
57
59
  const result = streamText({
58
60
  model: options.model,
59
- temperature: 0,
60
61
  maxOutputTokens: 4096,
61
62
  system: `${SUBAGENT_SYSTEM_PROMPT}\n\n${buildSystemPrompt(options.contextFiles)}`,
62
63
  messages: [{ role: 'user', content: task }],
@@ -71,7 +72,7 @@ export async function runSubagent(task, options) {
71
72
  return {
72
73
  toolChoice: 'none',
73
74
  messages: [
74
- { role: 'user', content: 'You have done enough tool work. Summarize what you found or did right now.' },
75
+ { role: 'user', content: 'Tool budget reached for this subtask. Summarize what you found or changed, validation evidence, and the exact remaining action if incomplete. Do not claim tools are unavailable.' },
75
76
  ],
76
77
  };
77
78
  }
@@ -0,0 +1,13 @@
1
+ export type TaskStatus = 'pending' | 'in_progress' | 'completed';
2
+ export interface Task {
3
+ id: string;
4
+ title: string;
5
+ status: TaskStatus;
6
+ createdAt: string;
7
+ updatedAt: string;
8
+ }
9
+ export declare function getTasksFilePath(): string;
10
+ export declare function generateTaskId(): string;
11
+ export declare function loadTasks(): Promise<Task[]>;
12
+ export declare function saveTasks(tasks: Task[]): Promise<void>;
13
+ export declare function clearTasks(): Promise<void>;
@@ -0,0 +1,29 @@
1
+ import { randomUUID } from 'node:crypto';
2
+ import fs from 'node:fs/promises';
3
+ import path from 'node:path';
4
+ import { resolveWorkspacePath } from '../../utils/path.js';
5
+ const TASKS_DIR = '.haze';
6
+ const TASKS_FILE = 'tasks.json';
7
+ export function getTasksFilePath() {
8
+ return resolveWorkspacePath(path.join(TASKS_DIR, TASKS_FILE));
9
+ }
10
+ export function generateTaskId() {
11
+ return randomUUID().slice(0, 8);
12
+ }
13
+ export async function loadTasks() {
14
+ try {
15
+ const content = await fs.readFile(getTasksFilePath(), 'utf-8');
16
+ return JSON.parse(content);
17
+ }
18
+ catch {
19
+ return [];
20
+ }
21
+ }
22
+ export async function saveTasks(tasks) {
23
+ const filePath = getTasksFilePath();
24
+ await fs.mkdir(path.dirname(filePath), { recursive: true });
25
+ await fs.writeFile(filePath, JSON.stringify(tasks, null, 2), 'utf-8');
26
+ }
27
+ export async function clearTasks() {
28
+ await saveTasks([]);
29
+ }
@@ -0,0 +1,12 @@
1
+ import type { BashClassification } from '../safety/bashClassifier.js';
2
+ import type { ValidationSummary } from '../../llm/toolResultTypes.js';
3
+ export declare function parseValidationOutput(input: {
4
+ command: string;
5
+ code: number | null;
6
+ stdout: string;
7
+ stderr: string;
8
+ timedOut?: boolean;
9
+ stdoutTruncated?: boolean;
10
+ stderrTruncated?: boolean;
11
+ classification?: BashClassification;
12
+ }): ValidationSummary;
@@ -0,0 +1,79 @@
1
+ function uniq(values) {
2
+ return [...new Set(values.filter(Boolean))];
3
+ }
4
+ function inferKind(command, classification) {
5
+ const lower = command.toLowerCase();
6
+ if (/typecheck|\btsc\b/.test(lower))
7
+ return 'typecheck';
8
+ if (/\beslint\b|\blint\b/.test(lower))
9
+ return 'lint';
10
+ if (/\bbuild\b/.test(lower) || classification?.traits.includes('runs_build'))
11
+ return 'build';
12
+ if (/\b(test|vitest|jest)\b/.test(lower) || classification?.traits.includes('runs_tests'))
13
+ return 'test';
14
+ return 'generic';
15
+ }
16
+ export function parseValidationOutput(input) {
17
+ const text = `${input.stdout}\n${input.stderr}`;
18
+ const lines = text.split(/\r?\n/);
19
+ const diagnostics = [];
20
+ const failedTests = [];
21
+ const failedFiles = [];
22
+ const kind = inferKind(input.command, input.classification);
23
+ const status = input.timedOut ? 'timed_out' : input.code === 0 ? 'passed' : input.code == null ? 'unknown' : 'failed';
24
+ for (const line of lines) {
25
+ const ts = line.match(/^(.+?\.(?:ts|tsx|js|jsx|mts|cts))\((\d+),(\d+)\):\s+(error|warning)\s+TS\d+:\s+(.+)$/);
26
+ if (ts) {
27
+ const [, file, lineNo, column, severity, message] = ts;
28
+ diagnostics.push({ file, line: Number(lineNo), column: Number(column), severity: severity === 'warning' ? 'warning' : 'error', message: message ?? '' });
29
+ failedFiles.push(file ?? '');
30
+ continue;
31
+ }
32
+ const eslint = line.match(/^(.+?\.(?:ts|tsx|js|jsx|mts|cts))\s*$/);
33
+ if (eslint) {
34
+ const currentFile = eslint[1] ?? '';
35
+ const next = lines[lines.indexOf(line) + 1];
36
+ if (next && /^\s*\d+:\d+\s+/.test(next))
37
+ failedFiles.push(currentFile);
38
+ }
39
+ const eslintDiag = line.match(/^\s*(\d+):(\d+)\s+(error|warning)\s+(.+?)(?:\s{2,}\S+)?$/);
40
+ if (eslintDiag) {
41
+ const [, lineNo, column, severity, message] = eslintDiag;
42
+ diagnostics.push({ line: Number(lineNo), column: Number(column), severity: severity === 'warning' ? 'warning' : 'error', message: message ?? '' });
43
+ continue;
44
+ }
45
+ const vitestFile = line.match(/^\s*(?:FAIL|FAILED|✓|✗|❯)?\s*([^\s]+\.(?:test|spec)\.(?:ts|tsx|js|jsx))/i);
46
+ if (vitestFile)
47
+ failedFiles.push(vitestFile[1] ?? '');
48
+ const testName = line.match(/^\s*(?:FAIL|✗|×|●|-)\s+(.+)$/);
49
+ if (testName && !/^(FAIL|FAILED)\s+\S+\.(?:test|spec)\./i.test(line.trim()))
50
+ failedTests.push((testName[1] ?? '').trim());
51
+ const genericFile = line.match(/([^\s()]+\.(?:ts|tsx|js|jsx|mts|cts)):(\d+):(\d+)/);
52
+ if (genericFile) {
53
+ const [, file, lineNo, column] = genericFile;
54
+ failedFiles.push(file ?? '');
55
+ diagnostics.push({ file, line: Number(lineNo), column: Number(column), severity: /warn/i.test(line) ? 'warning' : 'error', message: line.trim() });
56
+ }
57
+ }
58
+ const uniqueFiles = uniq(failedFiles).slice(0, 10);
59
+ const uniqueTests = uniq(failedTests).slice(0, 10);
60
+ const diagCount = diagnostics.length;
61
+ const rawOutputTruncated = Boolean(input.stdoutTruncated || input.stderrTruncated);
62
+ let summaryText;
63
+ if (status === 'passed')
64
+ summaryText = `${kind} passed`;
65
+ else if (status === 'timed_out')
66
+ summaryText = `${kind} timed out`;
67
+ else if (uniqueTests.length > 0)
68
+ summaryText = `${kind} failed: ${uniqueTests.length} failed test${uniqueTests.length === 1 ? '' : 's'}${uniqueFiles.length ? ` in ${uniqueFiles.join(', ')}` : ''}`;
69
+ else if (diagCount > 0)
70
+ summaryText = `${kind} failed: ${diagCount} diagnostic${diagCount === 1 ? '' : 's'}${uniqueFiles.length ? ` in ${uniqueFiles.join(', ')}` : ''}`;
71
+ else
72
+ summaryText = `${kind} ${status}`;
73
+ const suggestedNextStep = status === 'failed'
74
+ ? uniqueFiles.length > 0
75
+ ? `Inspect ${uniqueFiles.slice(0, 3).join(', ')} and fix the first relevant failure.`
76
+ : 'Inspect the command output and fix the first relevant failure.'
77
+ : undefined;
78
+ return { kind, status, failedFiles: uniqueFiles, failedTests: uniqueTests, diagnostics: diagnostics.slice(0, 20), summaryText, suggestedNextStep, rawOutputTruncated };
79
+ }