@denizokcu/haze 1.7.10 → 1.7.12
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.
- package/CHANGELOG.md +25 -0
- package/README.md +125 -99
- package/assets/graph-grammars/NOTICE.md +21 -0
- package/assets/graph-grammars/tree-sitter-javascript.wasm +0 -0
- package/assets/graph-grammars/tree-sitter-tsx.wasm +0 -0
- package/assets/graph-grammars/tree-sitter-typescript.wasm +0 -0
- package/assets/graph-grammars/web-tree-sitter.cjs +4116 -0
- package/assets/graph-grammars/web-tree-sitter.cjs.map +7 -0
- package/assets/graph-grammars/web-tree-sitter.js +4056 -0
- package/assets/graph-grammars/web-tree-sitter.js.map +7 -0
- package/assets/graph-grammars/web-tree-sitter.wasm +0 -0
- package/assets/graph-grammars/web-tree-sitter.wasm.map +55 -0
- package/dist/buildInfo.json +3 -3
- package/dist/cli/chat/BusyBar.d.ts +2 -1
- package/dist/cli/chat/BusyBar.js +2 -2
- package/dist/cli/chat/chatMetrics.d.ts +25 -0
- package/dist/cli/chat/chatMetrics.js +36 -0
- package/dist/cli/chat/inputSuggestions.js +1 -0
- package/dist/cli/chat/sessionLifecycle.d.ts +2 -0
- package/dist/cli/chat/sessionLifecycle.js +29 -19
- package/dist/cli/chat/sessionRecorder.d.ts +2 -1
- package/dist/cli/chat/sessionRecorder.js +29 -9
- package/dist/cli/chat/startupSequence.d.ts +2 -0
- package/dist/cli/chat/startupSequence.js +6 -0
- package/dist/cli/chat/transcriptPartition.js +10 -4
- package/dist/cli/chat/wizard/providerHandlers.js +57 -9
- package/dist/cli/chat/wizard/sessionThemeHandlers.js +5 -1
- package/dist/cli/commands/chat.js +44 -9
- package/dist/cli/commands/commandHelp.js +6 -3
- package/dist/cli/commands/commands.js +2 -0
- package/dist/cli/commands/formatters.js +28 -0
- package/dist/cli/commands/graphCommand.d.ts +2 -0
- package/dist/cli/commands/graphCommand.js +60 -0
- package/dist/cli/commands/initCommand.js +14 -0
- package/dist/cli/commands/providerWizard.js +9 -17
- package/dist/cli/commands/reasoningCommand.d.ts +1 -0
- package/dist/cli/commands/reasoningCommand.js +32 -4
- package/dist/cli/commands/runCommand.js +7 -1
- package/dist/cli/commands/streaming/agentAttempt.js +11 -1
- package/dist/cli/commands/streaming/attemptLifecycle.js +1 -0
- package/dist/cli/commands/streaming/attemptOutcome.js +6 -2
- package/dist/cli/commands/streaming/attemptSetup.d.ts +3 -0
- package/dist/cli/commands/streaming/attemptSetup.js +13 -6
- package/dist/cli/commands/streaming/goalSupervisor.d.ts +1 -1
- package/dist/cli/commands/streaming/goalSupervisor.js +22 -1
- package/dist/cli/commands/streaming/prepareStep.js +1 -0
- package/dist/cli/commands/streaming/streamLoop.d.ts +2 -0
- package/dist/cli/commands/streaming/streamLoop.js +14 -10
- package/dist/cli/commands/streaming/toolPartHandlers.js +7 -1
- package/dist/cli/commands/streaming.d.ts +2 -0
- package/dist/cli/commands/streaming.js +5 -0
- package/dist/cli/commands/wizardFlow.d.ts +1 -0
- package/dist/cli/commands/wizardFlow.js +10 -4
- package/dist/cli/index.js +5 -3
- package/dist/config/hazeBuild.d.ts +2 -2
- package/dist/config/hazeBuild.js +2 -2
- package/dist/config/modelDiscovery.d.ts +1 -1
- package/dist/config/modelDiscovery.js +8 -8
- package/dist/config/{modelCatalog.d.ts → providerModelFacts.d.ts} +13 -2
- package/dist/config/{modelCatalog.js → providerModelFacts.js} +145 -21
- package/dist/config/providerPresets.d.ts +8 -19
- package/dist/config/providerPresets.js +86 -555
- package/dist/config/providerReasoning.d.ts +16 -0
- package/dist/config/providerReasoning.js +56 -0
- package/dist/config/providers.d.ts +4 -0
- package/dist/config/providers.js +19 -2
- package/dist/config/settings.d.ts +14 -0
- package/dist/config/settings.js +5 -0
- package/dist/core/agent/compaction.d.ts +1 -0
- package/dist/core/agent/compaction.js +3 -0
- package/dist/core/agent/events.d.ts +1 -1
- package/dist/core/agent/providerTransition.d.ts +8 -0
- package/dist/core/agent/providerTransition.js +47 -0
- package/dist/core/agent/reasoningPolicy.d.ts +1 -1
- package/dist/core/agent/reasoningPolicy.js +4 -2
- package/dist/core/graph/analyze.d.ts +61 -0
- package/dist/core/graph/analyze.js +274 -0
- package/dist/core/graph/buildGraph.d.ts +44 -0
- package/dist/core/graph/buildGraph.js +290 -0
- package/dist/core/graph/digest.d.ts +2 -0
- package/dist/core/graph/digest.js +40 -0
- package/dist/core/graph/extract.d.ts +58 -0
- package/dist/core/graph/extract.js +394 -0
- package/dist/core/graph/model.d.ts +63 -0
- package/dist/core/graph/model.js +96 -0
- package/dist/core/graph/query.d.ts +69 -0
- package/dist/core/graph/query.js +391 -0
- package/dist/core/graph/store.d.ts +64 -0
- package/dist/core/graph/store.js +171 -0
- package/dist/core/limits.d.ts +0 -2
- package/dist/core/limits.js +0 -2
- package/dist/core/process/runBoundedProcess.js +12 -6
- package/dist/core/providerContracts.d.ts +9 -8
- package/dist/core/providerContracts.js +21 -1
- package/dist/core/safety/redaction.js +12 -2
- package/dist/core/safety/untrustedEnvelopes.d.ts +6 -0
- package/dist/core/safety/untrustedEnvelopes.js +17 -2
- package/dist/core/session/sessionSlimming.js +5 -59
- package/dist/core/session/sessionStore.d.ts +4 -0
- package/dist/core/session/sessionStore.js +149 -9
- package/dist/core/session/snapshotCodec.d.ts +5 -0
- package/dist/core/session/snapshotCodec.js +47 -0
- package/dist/core/shellOutput/registry.js +2 -46
- package/dist/core/subagent/executionProfiles.js +8 -5
- package/dist/core/tasks/taskStorage.js +11 -1
- package/dist/core/toolOutput/reduction.d.ts +55 -2
- package/dist/core/toolOutput/reduction.js +77 -2
- package/dist/core/validation/outputParser.js +16 -8
- package/dist/llm/client.d.ts +4 -2
- package/dist/llm/client.js +104 -55
- package/dist/llm/hazeTools.d.ts +2 -12426
- package/dist/llm/hazeTools.js +2 -0
- package/dist/llm/lspTools.d.ts +3 -12622
- package/dist/llm/mistralReasoning.d.ts +2 -0
- package/dist/llm/mistralReasoning.js +17 -0
- package/dist/llm/mistralVibeAuth.d.ts +5 -0
- package/dist/llm/mistralVibeAuth.js +63 -0
- package/dist/llm/requestContext.d.ts +3 -0
- package/dist/llm/requestContext.js +21 -11
- package/dist/llm/subagentRunner.d.ts +2 -308
- package/dist/llm/subagentRunner.js +15 -7
- package/dist/llm/systemPrompt.js +7 -4
- package/dist/llm/toolResultTypes.d.ts +1 -1
- package/dist/llm/toolResultTypes.js +7 -1
- package/dist/llm/tools/fetchTool.d.ts +2 -1221
- package/dist/llm/tools/fileTools.d.ts +2 -7768
- package/dist/llm/tools/graphAdvisory.d.ts +22 -0
- package/dist/llm/tools/graphAdvisory.js +68 -0
- package/dist/llm/tools/graphTools.d.ts +13 -0
- package/dist/llm/tools/graphTools.js +195 -0
- package/dist/llm/tools/outputCap.d.ts +2 -7
- package/dist/llm/tools/outputCap.js +3 -11
- package/dist/llm/tools/processTool.d.ts +2 -1081
- package/dist/llm/tools/replaceInFiles.js +5 -0
- package/dist/llm/tools/shellTool.d.ts +2 -1513
- package/dist/llm/tools/storedOutputTool.d.ts +2 -355
- package/dist/llm/tools/taskTool.d.ts +2 -489
- package/dist/llm/tools/toolContext.js +24 -9
- package/dist/llm/tools/toolContextState.d.ts +3 -0
- package/dist/llm/tools/toolContextState.js +2 -1
- package/dist/skills/skillTools.js +4 -1
- package/package.json +24 -15
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/** Convert the compatible SDK's reasoning history back to Mistral ThinkChunks. */
|
|
2
|
+
export function mistralRequestBody(body) {
|
|
3
|
+
if (!Array.isArray(body.messages))
|
|
4
|
+
return body;
|
|
5
|
+
return { ...body, messages: body.messages.map((value) => {
|
|
6
|
+
if (!value || typeof value !== 'object' || Array.isArray(value))
|
|
7
|
+
return value;
|
|
8
|
+
const message = value;
|
|
9
|
+
if (message.role !== 'assistant' || typeof message.reasoning_content !== 'string' || !message.reasoning_content)
|
|
10
|
+
return value;
|
|
11
|
+
const { reasoning_content, ...rest } = message;
|
|
12
|
+
const content = [{ type: 'thinking', thinking: [{ type: 'text', text: reasoning_content }] }];
|
|
13
|
+
if (typeof message.content === 'string' && message.content)
|
|
14
|
+
content.push({ type: 'text', text: message.content });
|
|
15
|
+
return { ...rest, content };
|
|
16
|
+
}) };
|
|
17
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { createHash, randomBytes } from 'node:crypto';
|
|
2
|
+
import { setTimeout as delay } from 'node:timers/promises';
|
|
3
|
+
const CONSOLE_ORIGIN = 'https://console.mistral.ai';
|
|
4
|
+
const AUTH_BASE = `${CONSOLE_ORIGIN}/api/vibe/sign-in`;
|
|
5
|
+
function validatedUrl(value, api) {
|
|
6
|
+
if (typeof value !== 'string')
|
|
7
|
+
throw new Error('Mistral sign-in returned an invalid URL.');
|
|
8
|
+
const url = new URL(value);
|
|
9
|
+
if (url.origin !== CONSOLE_ORIGIN || url.username || url.password || (api && !url.pathname.startsWith('/api/'))) {
|
|
10
|
+
throw new Error('Mistral sign-in returned an unexpected URL.');
|
|
11
|
+
}
|
|
12
|
+
return url.href;
|
|
13
|
+
}
|
|
14
|
+
async function jsonRequest(url, init, fetchImpl) {
|
|
15
|
+
const response = await fetchImpl(url, { ...init, redirect: 'error', signal: AbortSignal.timeout(15_000) });
|
|
16
|
+
if (!response.ok)
|
|
17
|
+
throw new Error(`Mistral sign-in request failed (HTTP ${response.status}).`);
|
|
18
|
+
const data = await response.json();
|
|
19
|
+
if (!data || typeof data !== 'object' || Array.isArray(data))
|
|
20
|
+
throw new Error('Mistral sign-in returned an invalid response.');
|
|
21
|
+
return data;
|
|
22
|
+
}
|
|
23
|
+
/** Mistral Vibe's browser flow exchanges a PKCE verifier for an API key. */
|
|
24
|
+
export async function startMistralVibeLogin(fetchImpl = fetch) {
|
|
25
|
+
const verifier = randomBytes(64).toString('base64url');
|
|
26
|
+
const challenge = createHash('sha256').update(verifier).digest('base64url');
|
|
27
|
+
const post = (body) => ({ method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify(body) });
|
|
28
|
+
const process = await jsonRequest(AUTH_BASE, post({ code_challenge: challenge, code_challenge_method: 'S256' }), fetchImpl);
|
|
29
|
+
const url = validatedUrl(process.sign_in_url, false);
|
|
30
|
+
const pollUrl = validatedUrl(process.poll_url, true);
|
|
31
|
+
const processId = process.process_id;
|
|
32
|
+
const expires = typeof process.expires_at === 'string' ? Date.parse(process.expires_at) : NaN;
|
|
33
|
+
if (typeof processId !== 'string' || !/^[a-zA-Z0-9_-]{1,200}$/.test(processId) || !Number.isFinite(expires) || expires <= Date.now()) {
|
|
34
|
+
throw new Error('Mistral sign-in returned invalid process details.');
|
|
35
|
+
}
|
|
36
|
+
const deadline = Math.min(expires, Date.now() + 10 * 60_000);
|
|
37
|
+
return { url, complete: async () => {
|
|
38
|
+
let failures = 0;
|
|
39
|
+
while (Date.now() < deadline) {
|
|
40
|
+
let status;
|
|
41
|
+
try {
|
|
42
|
+
status = await jsonRequest(pollUrl, {}, fetchImpl);
|
|
43
|
+
failures = 0;
|
|
44
|
+
}
|
|
45
|
+
catch {
|
|
46
|
+
if (++failures >= 3)
|
|
47
|
+
throw new Error('Mistral sign-in status could not be retrieved.');
|
|
48
|
+
await delay(Math.min(3000, Math.max(0, deadline - Date.now())));
|
|
49
|
+
continue;
|
|
50
|
+
}
|
|
51
|
+
if (status.status === 'completed' && typeof status.exchange_token === 'string' && status.exchange_token) {
|
|
52
|
+
const result = await jsonRequest(`${AUTH_BASE}/${processId}/exchange`, post({ exchange_token: status.exchange_token, code_verifier: verifier }), fetchImpl);
|
|
53
|
+
if (typeof result.api_key !== 'string' || !result.api_key)
|
|
54
|
+
throw new Error('Mistral sign-in did not return an API key.');
|
|
55
|
+
return result.api_key;
|
|
56
|
+
}
|
|
57
|
+
if (status.status !== 'pending')
|
|
58
|
+
throw new Error('Mistral sign-in was denied, expired, or returned an invalid status.');
|
|
59
|
+
await delay(Math.min(3000, Math.max(0, deadline - Date.now())));
|
|
60
|
+
}
|
|
61
|
+
throw new Error('Mistral sign-in timed out.');
|
|
62
|
+
} };
|
|
63
|
+
}
|
|
@@ -9,6 +9,7 @@ import { type LoadedMcpTools } from './mcp.js';
|
|
|
9
9
|
import { createSubagentTool } from './subagentRunner.js';
|
|
10
10
|
import type { ContextFile } from '../config/contextFiles.js';
|
|
11
11
|
import type { PostMutationDiagnostics } from './tools/toolContext.js';
|
|
12
|
+
import type { PostMutationGraphAdvisory } from './tools/graphAdvisory.js';
|
|
12
13
|
export type ToolCategory = 'builtin' | 'lsp' | 'skill' | 'subagent' | 'mcp';
|
|
13
14
|
/** Model type accepted by the subagent tool; derived so this module stays decoupled. */
|
|
14
15
|
export type RequestModel = NonNullable<Parameters<typeof createSubagentTool>[0]['model']>;
|
|
@@ -32,6 +33,8 @@ export interface AssembledRequestContext {
|
|
|
32
33
|
lspPool?: LspPool;
|
|
33
34
|
/** Bounded automatic diagnostics attached to successful file-mutation results. */
|
|
34
35
|
postMutationDiagnostics?: PostMutationDiagnostics;
|
|
36
|
+
/** Reverse-dependency graph advisory attached to successful file-mutation results. */
|
|
37
|
+
postMutationGraph?: PostMutationGraphAdvisory;
|
|
35
38
|
executionScope: TurnExecutionScope;
|
|
36
39
|
}
|
|
37
40
|
/**
|
|
@@ -17,6 +17,7 @@ import { buildSkillTools } from '../skills/skillTools.js';
|
|
|
17
17
|
import { isSkillEnabled } from '../config/skillSettings.js';
|
|
18
18
|
import { createSubagentTool } from './subagentRunner.js';
|
|
19
19
|
import { addCapabilityTools } from './capabilities.js';
|
|
20
|
+
import { createPostMutationGraphAdvisory } from './tools/graphAdvisory.js';
|
|
20
21
|
const ALWAYS_AVAILABLE_TOOLS = new Set(['listFiles', 'readFile', 'grep', 'replaceLines', 'writeFile', 'editFile', 'shell', 'writeTasks', 'readToolOutput', 'skill']);
|
|
21
22
|
/** Keep the common coding path lean while preserving explicitly relevant capabilities. */
|
|
22
23
|
function selectToolsForRequest(tools, request) {
|
|
@@ -25,13 +26,20 @@ function selectToolsForRequest(tools, request) {
|
|
|
25
26
|
const lower = request.toLowerCase();
|
|
26
27
|
const includeFetch = /https?:\/\/|\b(web|online|fetch|current docs?|api docs?|library docs?|research)\b/.test(lower);
|
|
27
28
|
const includeProcess = /\b(background|server|serve|daemon|watch(?:er)?|long-running|process|dev server)\b/.test(lower);
|
|
28
|
-
const includeSubagent = /\b(subagents?|agents?|fleet|parallel|delegate|orchestrat\w*|multi-agent|review|audit|compare)\b/.test(lower)
|
|
29
|
+
const includeSubagent = /\b(subagents?|agents?|fleet|parallel|delegate|orchestrat\w*|multi-agent|review|audit|compare)\b/.test(lower);
|
|
30
|
+
// Semantic-navigation tool groups only pay off for orientation/refactor requests;
|
|
31
|
+
// grep/readFile remain available for everything else.
|
|
32
|
+
const includeLsp = /\b(rename|refactor|move|symbols?|definitions?|references|usages?|impact|blast radius|navigate|navigation|semantic|callers?)\b/.test(lower);
|
|
33
|
+
const includeGraph = /\b(architecture|structure|where|how (?:does|do)|relationships?|dependenc\w*|affected|explore|understand|map|overview|graph|codebase|unfamiliar|orient\w*|large)\b/.test(lower);
|
|
34
|
+
const isConditionalBuiltin = (name) => ['fetch', 'process', 'subagent'].includes(name) || name.startsWith('lsp') || name.startsWith('graph');
|
|
29
35
|
return Object.fromEntries(Object.entries(tools).filter(([name]) => ALWAYS_AVAILABLE_TOOLS.has(name)
|
|
30
36
|
|| (name === 'fetch' && includeFetch)
|
|
31
37
|
|| (name === 'process' && includeProcess)
|
|
32
38
|
|| (name === 'subagent' && includeSubagent)
|
|
33
|
-
|
|
34
|
-
||
|
|
39
|
+
|| (name.startsWith('lsp') && includeLsp)
|
|
40
|
+
|| (name.startsWith('graph') && includeGraph)
|
|
41
|
+
// Configured MCP tools are explicit user capabilities and remain available.
|
|
42
|
+
|| !isConditionalBuiltin(name)));
|
|
35
43
|
}
|
|
36
44
|
/**
|
|
37
45
|
* Assemble the system prompt and full tool set (built-in + LSP + subagent +
|
|
@@ -64,8 +72,6 @@ export async function assembleRequestContext(input) {
|
|
|
64
72
|
const usesNativeWorker = nativeWorker?.status === 'found' ? nativeWorker.provider.kind === 'haze-build' : !workerSelector && input.modelRuntime?.config.providerKind === 'haze-build';
|
|
65
73
|
const profileName = input.subagentOverrides?.profile ?? settings.subagents?.defaultProfile ?? (usesNativeWorker ? 'haze-build' : undefined);
|
|
66
74
|
let profile = resolveExecutionProfile(profileName, settings.subagents?.profiles, input.subagentOverrides?.maxConcurrency);
|
|
67
|
-
if (profile && usesNativeWorker)
|
|
68
|
-
profile = { ...profile, maxConcurrency: Math.min(profile.maxConcurrency, 2) };
|
|
69
75
|
let blockedReason = profile ? undefined : `Unknown subagent profile ${profileName}. Configure subagents.profiles or select a built-in profile.`;
|
|
70
76
|
let workerRuntime;
|
|
71
77
|
if (input.modelRuntime) {
|
|
@@ -81,12 +87,15 @@ export async function assembleRequestContext(input) {
|
|
|
81
87
|
workerRuntime ??= {
|
|
82
88
|
...fallbackWorkerRuntime(input.model, input.modelRuntime?.selector, input.modelRuntime?.config.providerName),
|
|
83
89
|
capabilities: input.modelRuntime?.config.capabilities ?? fallbackProviderCapabilities(),
|
|
84
|
-
|
|
85
|
-
// single-sequence (quality) deployment could still admit two workers.
|
|
86
|
-
...(input.modelRuntime?.config.deployment ? { nativeMaxConcurrency: Math.min(2, input.modelRuntime.config.deployment.activeSequences) } : {}),
|
|
90
|
+
...(input.modelRuntime?.config.deployment ? { nativeMaxConcurrency: input.modelRuntime.config.deployment.activeSequences } : {}),
|
|
87
91
|
};
|
|
88
|
-
|
|
89
|
-
|
|
92
|
+
// The deployment manifest is authoritative for this client's native-worker
|
|
93
|
+
// allowance: raise it and clients follow; a future multi-tenant server
|
|
94
|
+
// lowers it and every client backs off without a release. Deployments that
|
|
95
|
+
// advertise nothing stay conservative at 2.
|
|
96
|
+
const nativeWorkerCap = workerRuntime.nativeMaxConcurrency ?? (usesNativeWorker ? 2 : undefined);
|
|
97
|
+
if (profile && nativeWorkerCap)
|
|
98
|
+
profile = { ...profile, maxConcurrency: Math.min(profile.maxConcurrency, nativeWorkerCap) };
|
|
90
99
|
const executionScope = input.executionScope ?? {
|
|
91
100
|
mutationPolicy: new WorkspaceMutationPolicy(),
|
|
92
101
|
coordinator: new SubagentCoordinator(profile ?? resolveExecutionProfile(undefined, undefined), input.onSubagentEvent),
|
|
@@ -117,9 +126,10 @@ export async function assembleRequestContext(input) {
|
|
|
117
126
|
const mcpAvailable = Boolean(loadedMcp && Object.keys(loadedMcp.tools).length > 0);
|
|
118
127
|
const skillErrors = (skillRegistry.errors ?? []).map(error => `${error.source ? `${error.source}/` : ''}${error.directory}: ${error.message}`);
|
|
119
128
|
const model = input.modelRuntime?.config ? { provider: input.modelRuntime.config.providerName, name: input.modelRuntime.config.modelName } : undefined;
|
|
120
|
-
const systemPrompt = `${buildSystemPrompt(input.contextFiles, input.session, { lspAvailable: hasInstalledLsp, mcpAvailable, model, availableTools: new Set(Object.keys(availableTools)) })}${skillErrors.length ? `\n\n<skill-load-errors>\nInvalid skills were isolated:\n${skillErrors.map(error => `- ${error}`).join('\n')}\n</skill-load-errors>` : ''}`;
|
|
129
|
+
const systemPrompt = `${buildSystemPrompt(input.contextFiles, input.session, { lspAvailable: hasInstalledLsp && 'lspWorkspaceSymbols' in availableTools, mcpAvailable, model, availableTools: new Set(Object.keys(availableTools)) })}${skillErrors.length ? `\n\n<skill-load-errors>\nInvalid skills were isolated:\n${skillErrors.map(error => `- ${error}`).join('\n')}\n</skill-load-errors>` : ''}`;
|
|
121
130
|
return {
|
|
122
131
|
systemPrompt, availableTools, toolCategories, loadedMcp, lspPool, executionScope,
|
|
123
132
|
...(lspPool ? { postMutationDiagnostics: createPostMutationDiagnostics(installedLsp, lspPool) } : {}),
|
|
133
|
+
postMutationGraph: createPostMutationGraphAdvisory(),
|
|
124
134
|
};
|
|
125
135
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type ModelMessage } from 'ai';
|
|
1
|
+
import { type ModelMessage, type Tool } from 'ai';
|
|
2
2
|
import { toolOnlyStepCount } from '../core/agent/turnPolicy.js';
|
|
3
3
|
import { type HazeToolContext } from './tools/toolContext.js';
|
|
4
4
|
import { type WorkerContextBundle } from './workerContext.js';
|
|
@@ -45,313 +45,7 @@ export declare function createSubagentTool(options: {
|
|
|
45
45
|
blockedReason?: string;
|
|
46
46
|
forceMode?: 'inspect';
|
|
47
47
|
session?: PromptSession;
|
|
48
|
-
}):
|
|
49
|
-
deferLoading?: boolean;
|
|
50
|
-
title?: string;
|
|
51
|
-
providerOptions?: import("@ai-sdk/provider-utils").ProviderOptions;
|
|
52
|
-
metadata?: import("@ai-sdk/provider").JSONObject;
|
|
53
|
-
inputSchema: import("ai").FlexibleSchema<{
|
|
54
|
-
objective: string;
|
|
55
|
-
deliverable: string;
|
|
56
|
-
mode: "inspect" | "research" | "implement" | "validate";
|
|
57
|
-
scope?: string[] | undefined;
|
|
58
|
-
acceptanceCriteria?: string[] | undefined;
|
|
59
|
-
}>;
|
|
60
|
-
contextSchema?: import("ai").FlexibleSchema<HazeToolContext> | undefined;
|
|
61
|
-
needsApproval?: boolean | import("@ai-sdk/provider-utils").ToolNeedsApprovalFunction<{
|
|
62
|
-
objective: string;
|
|
63
|
-
deliverable: string;
|
|
64
|
-
mode: "inspect" | "research" | "implement" | "validate";
|
|
65
|
-
scope?: string[] | undefined;
|
|
66
|
-
acceptanceCriteria?: string[] | undefined;
|
|
67
|
-
}, NoInfer<HazeToolContext>> | undefined;
|
|
68
|
-
onInputStart?: ((options: import("ai").ToolExecutionOptions<NoInfer<HazeToolContext>>) => void | PromiseLike<void>) | undefined;
|
|
69
|
-
onInputDelta?: ((options: {
|
|
70
|
-
inputTextDelta: string;
|
|
71
|
-
} & import("ai").ToolExecutionOptions<NoInfer<HazeToolContext>>) => void | PromiseLike<void>) | undefined;
|
|
72
|
-
onInputAvailable?: ((options: {
|
|
73
|
-
input: {
|
|
74
|
-
objective: string;
|
|
75
|
-
deliverable: string;
|
|
76
|
-
mode: "inspect" | "research" | "implement" | "validate";
|
|
77
|
-
scope?: string[] | undefined;
|
|
78
|
-
acceptanceCriteria?: string[] | undefined;
|
|
79
|
-
};
|
|
80
|
-
} & import("ai").ToolExecutionOptions<NoInfer<HazeToolContext>>) => void | PromiseLike<void>) | undefined;
|
|
81
|
-
toModelOutput?: ((options: {
|
|
82
|
-
toolCallId: string;
|
|
83
|
-
input: {
|
|
84
|
-
objective: string;
|
|
85
|
-
deliverable: string;
|
|
86
|
-
mode: "inspect" | "research" | "implement" | "validate";
|
|
87
|
-
scope?: string[] | undefined;
|
|
88
|
-
acceptanceCriteria?: string[] | undefined;
|
|
89
|
-
};
|
|
90
|
-
output: NoInfer<SubagentExecutionResult>;
|
|
91
|
-
}) => import("@ai-sdk/provider-utils").ToolResultOutput | PromiseLike<import("@ai-sdk/provider-utils").ToolResultOutput>) | undefined;
|
|
92
|
-
} & {
|
|
93
|
-
outputSchema?: import("ai").FlexibleSchema<SubagentExecutionResult> | undefined;
|
|
94
|
-
execute: import("ai").ToolExecuteFunction<{
|
|
95
|
-
objective: string;
|
|
96
|
-
deliverable: string;
|
|
97
|
-
mode: "inspect" | "research" | "implement" | "validate";
|
|
98
|
-
scope?: string[] | undefined;
|
|
99
|
-
acceptanceCriteria?: string[] | undefined;
|
|
100
|
-
}, SubagentExecutionResult, NoInfer<HazeToolContext>>;
|
|
101
|
-
} & {
|
|
102
|
-
description?: string | ((options: {
|
|
103
|
-
context: NoInfer<HazeToolContext>;
|
|
104
|
-
experimental_sandbox?: import("ai").Experimental_SandboxSession;
|
|
105
|
-
}) => string) | undefined;
|
|
106
|
-
strict?: boolean;
|
|
107
|
-
inputExamples?: {
|
|
108
|
-
input: NoInfer<{
|
|
109
|
-
objective: string;
|
|
110
|
-
deliverable: string;
|
|
111
|
-
mode: "inspect" | "research" | "implement" | "validate";
|
|
112
|
-
scope?: string[] | undefined;
|
|
113
|
-
acceptanceCriteria?: string[] | undefined;
|
|
114
|
-
}>;
|
|
115
|
-
}[] | undefined;
|
|
116
|
-
id?: never;
|
|
117
|
-
isProviderExecuted?: never;
|
|
118
|
-
args?: never;
|
|
119
|
-
supportsDeferredResults?: never;
|
|
120
|
-
} & {
|
|
121
|
-
type?: undefined | "function";
|
|
122
|
-
} & {
|
|
123
|
-
execute: import("ai").ToolExecuteFunction<{
|
|
124
|
-
objective: string;
|
|
125
|
-
deliverable: string;
|
|
126
|
-
mode: "inspect" | "research" | "implement" | "validate";
|
|
127
|
-
scope?: string[] | undefined;
|
|
128
|
-
acceptanceCriteria?: string[] | undefined;
|
|
129
|
-
}, SubagentExecutionResult, NoInfer<HazeToolContext>>;
|
|
130
|
-
}) | ({
|
|
131
|
-
deferLoading?: boolean;
|
|
132
|
-
title?: string;
|
|
133
|
-
providerOptions?: import("@ai-sdk/provider-utils").ProviderOptions;
|
|
134
|
-
metadata?: import("@ai-sdk/provider").JSONObject;
|
|
135
|
-
inputSchema: import("ai").FlexibleSchema<{
|
|
136
|
-
objective: string;
|
|
137
|
-
deliverable: string;
|
|
138
|
-
mode: "inspect" | "research" | "implement" | "validate";
|
|
139
|
-
scope?: string[] | undefined;
|
|
140
|
-
acceptanceCriteria?: string[] | undefined;
|
|
141
|
-
}>;
|
|
142
|
-
contextSchema?: import("ai").FlexibleSchema<HazeToolContext> | undefined;
|
|
143
|
-
needsApproval?: boolean | import("@ai-sdk/provider-utils").ToolNeedsApprovalFunction<{
|
|
144
|
-
objective: string;
|
|
145
|
-
deliverable: string;
|
|
146
|
-
mode: "inspect" | "research" | "implement" | "validate";
|
|
147
|
-
scope?: string[] | undefined;
|
|
148
|
-
acceptanceCriteria?: string[] | undefined;
|
|
149
|
-
}, NoInfer<HazeToolContext>> | undefined;
|
|
150
|
-
onInputStart?: ((options: import("ai").ToolExecutionOptions<NoInfer<HazeToolContext>>) => void | PromiseLike<void>) | undefined;
|
|
151
|
-
onInputDelta?: ((options: {
|
|
152
|
-
inputTextDelta: string;
|
|
153
|
-
} & import("ai").ToolExecutionOptions<NoInfer<HazeToolContext>>) => void | PromiseLike<void>) | undefined;
|
|
154
|
-
onInputAvailable?: ((options: {
|
|
155
|
-
input: {
|
|
156
|
-
objective: string;
|
|
157
|
-
deliverable: string;
|
|
158
|
-
mode: "inspect" | "research" | "implement" | "validate";
|
|
159
|
-
scope?: string[] | undefined;
|
|
160
|
-
acceptanceCriteria?: string[] | undefined;
|
|
161
|
-
};
|
|
162
|
-
} & import("ai").ToolExecutionOptions<NoInfer<HazeToolContext>>) => void | PromiseLike<void>) | undefined;
|
|
163
|
-
toModelOutput?: ((options: {
|
|
164
|
-
toolCallId: string;
|
|
165
|
-
input: {
|
|
166
|
-
objective: string;
|
|
167
|
-
deliverable: string;
|
|
168
|
-
mode: "inspect" | "research" | "implement" | "validate";
|
|
169
|
-
scope?: string[] | undefined;
|
|
170
|
-
acceptanceCriteria?: string[] | undefined;
|
|
171
|
-
};
|
|
172
|
-
output: NoInfer<SubagentExecutionResult>;
|
|
173
|
-
}) => import("@ai-sdk/provider-utils").ToolResultOutput | PromiseLike<import("@ai-sdk/provider-utils").ToolResultOutput>) | undefined;
|
|
174
|
-
} & {
|
|
175
|
-
outputSchema?: import("ai").FlexibleSchema<SubagentExecutionResult> | undefined;
|
|
176
|
-
execute: import("ai").ToolExecuteFunction<{
|
|
177
|
-
objective: string;
|
|
178
|
-
deliverable: string;
|
|
179
|
-
mode: "inspect" | "research" | "implement" | "validate";
|
|
180
|
-
scope?: string[] | undefined;
|
|
181
|
-
acceptanceCriteria?: string[] | undefined;
|
|
182
|
-
}, SubagentExecutionResult, NoInfer<HazeToolContext>>;
|
|
183
|
-
} & {
|
|
184
|
-
description?: string | ((options: {
|
|
185
|
-
context: NoInfer<HazeToolContext>;
|
|
186
|
-
experimental_sandbox?: import("ai").Experimental_SandboxSession;
|
|
187
|
-
}) => string) | undefined;
|
|
188
|
-
strict?: boolean;
|
|
189
|
-
inputExamples?: {
|
|
190
|
-
input: NoInfer<{
|
|
191
|
-
objective: string;
|
|
192
|
-
deliverable: string;
|
|
193
|
-
mode: "inspect" | "research" | "implement" | "validate";
|
|
194
|
-
scope?: string[] | undefined;
|
|
195
|
-
acceptanceCriteria?: string[] | undefined;
|
|
196
|
-
}>;
|
|
197
|
-
}[] | undefined;
|
|
198
|
-
id?: never;
|
|
199
|
-
isProviderExecuted?: never;
|
|
200
|
-
args?: never;
|
|
201
|
-
supportsDeferredResults?: never;
|
|
202
|
-
} & {
|
|
203
|
-
type: "dynamic";
|
|
204
|
-
} & {
|
|
205
|
-
execute: import("ai").ToolExecuteFunction<{
|
|
206
|
-
objective: string;
|
|
207
|
-
deliverable: string;
|
|
208
|
-
mode: "inspect" | "research" | "implement" | "validate";
|
|
209
|
-
scope?: string[] | undefined;
|
|
210
|
-
acceptanceCriteria?: string[] | undefined;
|
|
211
|
-
}, SubagentExecutionResult, NoInfer<HazeToolContext>>;
|
|
212
|
-
}) | ({
|
|
213
|
-
deferLoading?: boolean;
|
|
214
|
-
title?: string;
|
|
215
|
-
providerOptions?: import("@ai-sdk/provider-utils").ProviderOptions;
|
|
216
|
-
metadata?: import("@ai-sdk/provider").JSONObject;
|
|
217
|
-
inputSchema: import("ai").FlexibleSchema<{
|
|
218
|
-
objective: string;
|
|
219
|
-
deliverable: string;
|
|
220
|
-
mode: "inspect" | "research" | "implement" | "validate";
|
|
221
|
-
scope?: string[] | undefined;
|
|
222
|
-
acceptanceCriteria?: string[] | undefined;
|
|
223
|
-
}>;
|
|
224
|
-
contextSchema?: import("ai").FlexibleSchema<HazeToolContext> | undefined;
|
|
225
|
-
needsApproval?: boolean | import("@ai-sdk/provider-utils").ToolNeedsApprovalFunction<{
|
|
226
|
-
objective: string;
|
|
227
|
-
deliverable: string;
|
|
228
|
-
mode: "inspect" | "research" | "implement" | "validate";
|
|
229
|
-
scope?: string[] | undefined;
|
|
230
|
-
acceptanceCriteria?: string[] | undefined;
|
|
231
|
-
}, NoInfer<HazeToolContext>> | undefined;
|
|
232
|
-
onInputStart?: ((options: import("ai").ToolExecutionOptions<NoInfer<HazeToolContext>>) => void | PromiseLike<void>) | undefined;
|
|
233
|
-
onInputDelta?: ((options: {
|
|
234
|
-
inputTextDelta: string;
|
|
235
|
-
} & import("ai").ToolExecutionOptions<NoInfer<HazeToolContext>>) => void | PromiseLike<void>) | undefined;
|
|
236
|
-
onInputAvailable?: ((options: {
|
|
237
|
-
input: {
|
|
238
|
-
objective: string;
|
|
239
|
-
deliverable: string;
|
|
240
|
-
mode: "inspect" | "research" | "implement" | "validate";
|
|
241
|
-
scope?: string[] | undefined;
|
|
242
|
-
acceptanceCriteria?: string[] | undefined;
|
|
243
|
-
};
|
|
244
|
-
} & import("ai").ToolExecutionOptions<NoInfer<HazeToolContext>>) => void | PromiseLike<void>) | undefined;
|
|
245
|
-
toModelOutput?: ((options: {
|
|
246
|
-
toolCallId: string;
|
|
247
|
-
input: {
|
|
248
|
-
objective: string;
|
|
249
|
-
deliverable: string;
|
|
250
|
-
mode: "inspect" | "research" | "implement" | "validate";
|
|
251
|
-
scope?: string[] | undefined;
|
|
252
|
-
acceptanceCriteria?: string[] | undefined;
|
|
253
|
-
};
|
|
254
|
-
output: NoInfer<SubagentExecutionResult>;
|
|
255
|
-
}) => import("@ai-sdk/provider-utils").ToolResultOutput | PromiseLike<import("@ai-sdk/provider-utils").ToolResultOutput>) | undefined;
|
|
256
|
-
} & {
|
|
257
|
-
outputSchema?: import("ai").FlexibleSchema<SubagentExecutionResult> | undefined;
|
|
258
|
-
execute: import("ai").ToolExecuteFunction<{
|
|
259
|
-
objective: string;
|
|
260
|
-
deliverable: string;
|
|
261
|
-
mode: "inspect" | "research" | "implement" | "validate";
|
|
262
|
-
scope?: string[] | undefined;
|
|
263
|
-
acceptanceCriteria?: string[] | undefined;
|
|
264
|
-
}, SubagentExecutionResult, NoInfer<HazeToolContext>>;
|
|
265
|
-
} & {
|
|
266
|
-
type: "provider";
|
|
267
|
-
id: `${string}.${string}`;
|
|
268
|
-
args: Record<string, unknown>;
|
|
269
|
-
description?: never;
|
|
270
|
-
strict?: never;
|
|
271
|
-
inputExamples?: never;
|
|
272
|
-
} & {
|
|
273
|
-
isProviderExecuted: false;
|
|
274
|
-
supportsDeferredResults?: never;
|
|
275
|
-
} & {
|
|
276
|
-
execute: import("ai").ToolExecuteFunction<{
|
|
277
|
-
objective: string;
|
|
278
|
-
deliverable: string;
|
|
279
|
-
mode: "inspect" | "research" | "implement" | "validate";
|
|
280
|
-
scope?: string[] | undefined;
|
|
281
|
-
acceptanceCriteria?: string[] | undefined;
|
|
282
|
-
}, SubagentExecutionResult, NoInfer<HazeToolContext>>;
|
|
283
|
-
}) | ({
|
|
284
|
-
deferLoading?: boolean;
|
|
285
|
-
title?: string;
|
|
286
|
-
providerOptions?: import("@ai-sdk/provider-utils").ProviderOptions;
|
|
287
|
-
metadata?: import("@ai-sdk/provider").JSONObject;
|
|
288
|
-
inputSchema: import("ai").FlexibleSchema<{
|
|
289
|
-
objective: string;
|
|
290
|
-
deliverable: string;
|
|
291
|
-
mode: "inspect" | "research" | "implement" | "validate";
|
|
292
|
-
scope?: string[] | undefined;
|
|
293
|
-
acceptanceCriteria?: string[] | undefined;
|
|
294
|
-
}>;
|
|
295
|
-
contextSchema?: import("ai").FlexibleSchema<HazeToolContext> | undefined;
|
|
296
|
-
needsApproval?: boolean | import("@ai-sdk/provider-utils").ToolNeedsApprovalFunction<{
|
|
297
|
-
objective: string;
|
|
298
|
-
deliverable: string;
|
|
299
|
-
mode: "inspect" | "research" | "implement" | "validate";
|
|
300
|
-
scope?: string[] | undefined;
|
|
301
|
-
acceptanceCriteria?: string[] | undefined;
|
|
302
|
-
}, NoInfer<HazeToolContext>> | undefined;
|
|
303
|
-
onInputStart?: ((options: import("ai").ToolExecutionOptions<NoInfer<HazeToolContext>>) => void | PromiseLike<void>) | undefined;
|
|
304
|
-
onInputDelta?: ((options: {
|
|
305
|
-
inputTextDelta: string;
|
|
306
|
-
} & import("ai").ToolExecutionOptions<NoInfer<HazeToolContext>>) => void | PromiseLike<void>) | undefined;
|
|
307
|
-
onInputAvailable?: ((options: {
|
|
308
|
-
input: {
|
|
309
|
-
objective: string;
|
|
310
|
-
deliverable: string;
|
|
311
|
-
mode: "inspect" | "research" | "implement" | "validate";
|
|
312
|
-
scope?: string[] | undefined;
|
|
313
|
-
acceptanceCriteria?: string[] | undefined;
|
|
314
|
-
};
|
|
315
|
-
} & import("ai").ToolExecutionOptions<NoInfer<HazeToolContext>>) => void | PromiseLike<void>) | undefined;
|
|
316
|
-
toModelOutput?: ((options: {
|
|
317
|
-
toolCallId: string;
|
|
318
|
-
input: {
|
|
319
|
-
objective: string;
|
|
320
|
-
deliverable: string;
|
|
321
|
-
mode: "inspect" | "research" | "implement" | "validate";
|
|
322
|
-
scope?: string[] | undefined;
|
|
323
|
-
acceptanceCriteria?: string[] | undefined;
|
|
324
|
-
};
|
|
325
|
-
output: NoInfer<SubagentExecutionResult>;
|
|
326
|
-
}) => import("@ai-sdk/provider-utils").ToolResultOutput | PromiseLike<import("@ai-sdk/provider-utils").ToolResultOutput>) | undefined;
|
|
327
|
-
} & {
|
|
328
|
-
outputSchema?: import("ai").FlexibleSchema<SubagentExecutionResult> | undefined;
|
|
329
|
-
execute: import("ai").ToolExecuteFunction<{
|
|
330
|
-
objective: string;
|
|
331
|
-
deliverable: string;
|
|
332
|
-
mode: "inspect" | "research" | "implement" | "validate";
|
|
333
|
-
scope?: string[] | undefined;
|
|
334
|
-
acceptanceCriteria?: string[] | undefined;
|
|
335
|
-
}, SubagentExecutionResult, NoInfer<HazeToolContext>>;
|
|
336
|
-
} & {
|
|
337
|
-
type: "provider";
|
|
338
|
-
id: `${string}.${string}`;
|
|
339
|
-
args: Record<string, unknown>;
|
|
340
|
-
description?: never;
|
|
341
|
-
strict?: never;
|
|
342
|
-
inputExamples?: never;
|
|
343
|
-
} & {
|
|
344
|
-
isProviderExecuted: true;
|
|
345
|
-
supportsDeferredResults?: boolean;
|
|
346
|
-
} & {
|
|
347
|
-
execute: import("ai").ToolExecuteFunction<{
|
|
348
|
-
objective: string;
|
|
349
|
-
deliverable: string;
|
|
350
|
-
mode: "inspect" | "research" | "implement" | "validate";
|
|
351
|
-
scope?: string[] | undefined;
|
|
352
|
-
acceptanceCriteria?: string[] | undefined;
|
|
353
|
-
}, SubagentExecutionResult, NoInfer<HazeToolContext>>;
|
|
354
|
-
});
|
|
48
|
+
}): Tool;
|
|
355
49
|
export declare const internals: {
|
|
356
50
|
toolSummary: typeof toolSummary;
|
|
357
51
|
toolOnlyStepCount: typeof toolOnlyStepCount;
|
|
@@ -11,6 +11,7 @@ import { toolsContextFor } from './tools/toolContext.js';
|
|
|
11
11
|
import { assembleWorkerContext, workerTaskMessage } from './workerContext.js';
|
|
12
12
|
import { fallbackWorkerRuntime, normalizeSubagentInput, subagentInputSchema, } from '../core/subagent/contracts.js';
|
|
13
13
|
import { COMPATIBILITY_PROFILE } from '../core/subagent/executionProfiles.js';
|
|
14
|
+
import { auxiliaryRequestOptions } from '../core/providerContracts.js';
|
|
14
15
|
import { SubagentCoordinator } from '../core/subagent/subagentCoordinator.js';
|
|
15
16
|
import { resolveWorkspacePath, workspaceRelativePath } from '../utils/path.js';
|
|
16
17
|
class WorkerCapacityError extends Error {
|
|
@@ -100,19 +101,22 @@ export async function runSubagent(task, options) {
|
|
|
100
101
|
const release = mutationPolicy && mutationOwner && (task.mode === 'implement' || task.mode === 'validate')
|
|
101
102
|
? await mutationPolicy.acquire(mutationOwner, options.abortSignal).catch(() => undefined)
|
|
102
103
|
: undefined;
|
|
103
|
-
|
|
104
|
+
// When a mutation slot is required but acquisition failed, `release` is
|
|
105
|
+
// undefined here, so there is nothing to release; the try/finally below only
|
|
106
|
+
// releases a slot that was actually acquired.
|
|
107
|
+
if (mutationPolicy && mutationOwner && (task.mode === 'implement' || task.mode === 'validate') && !release) {
|
|
104
108
|
return terminalResult(task, runtime, profile, options.deadlineExpired?.() ? 'deadline_exceeded' : 'cancelled', 'Worker cancelled before workspace admission.', options.queueMs);
|
|
109
|
+
}
|
|
105
110
|
try {
|
|
106
|
-
const
|
|
107
|
-
// Workers
|
|
111
|
+
const providerRequestOptions = auxiliaryRequestOptions(runtime.requestOptions, runtime.capabilities, 'worker', outputTokens);
|
|
112
|
+
// Workers use the lowest supported reasoning effort. Session/main-turn reasoning
|
|
108
113
|
// effort rides the inherited request options; on reasoning models its
|
|
109
114
|
// hidden tokens count against the worker's bounded maxOutputTokens, so a
|
|
110
115
|
// `high` session could burn the whole worker budget on thinking and return
|
|
111
116
|
// `no_output` (observed live: glm-5.3 @ high reasoning, 2026-10-04).
|
|
112
117
|
// Applied only when the worker protocol supports the option; other
|
|
113
|
-
// protocols cannot express it and must keep the runtime unchanged.
|
|
114
|
-
|
|
115
|
-
providerRequestOptions.reasoning = 'none';
|
|
118
|
+
// protocols cannot express it and must keep the runtime unchanged. Some
|
|
119
|
+
// models have no off switch and use low instead of none.
|
|
116
120
|
// Use the streaming model path even though workers return one collected
|
|
117
121
|
// capsule. ChatGPT Codex's Responses endpoint requires `stream: true`;
|
|
118
122
|
// `generateText` takes the non-streaming doGenerate path and is rejected.
|
|
@@ -122,7 +126,6 @@ export async function runSubagent(task, options) {
|
|
|
122
126
|
messages: [{ role: 'user', content: workerTaskMessage(task) }],
|
|
123
127
|
tools: budgetedTools,
|
|
124
128
|
stopWhen: isStepCount(maxSteps),
|
|
125
|
-
...(!omitMaxOutputTokens ? { maxOutputTokens: outputTokens } : {}),
|
|
126
129
|
maxRetries: profile.maxRetries,
|
|
127
130
|
...providerRequestOptions,
|
|
128
131
|
abortSignal: options.abortSignal,
|
|
@@ -174,6 +177,11 @@ export async function runSubagent(task, options) {
|
|
|
174
177
|
}
|
|
175
178
|
},
|
|
176
179
|
});
|
|
180
|
+
// Surface a stream error as soon as streamText returns, before awaiting the
|
|
181
|
+
// result promises, so the real onError payload is surfaced rather than a
|
|
182
|
+
// Promise.all wrapper that could mask it.
|
|
183
|
+
if (streamError)
|
|
184
|
+
throw streamError;
|
|
177
185
|
const [text, usage, steps] = await Promise.all([result.text, result.usage, result.steps]);
|
|
178
186
|
if (streamError)
|
|
179
187
|
throw streamError;
|
package/dist/llm/systemPrompt.js
CHANGED
|
@@ -17,6 +17,9 @@ export function buildSystemPrompt(contextFiles = [], session, options = {}) {
|
|
|
17
17
|
const mcpToolRule = options.mcpAvailable
|
|
18
18
|
? '- MCP server tools (e.g. Context7 docs lookup) are available when configured via /mcp. They extend the toolset with external capabilities; use them when the user asks for up-to-date docs or library info those tools expose, instead of guessing from memory.\n'
|
|
19
19
|
: '';
|
|
20
|
+
const graphToolRule = options.availableTools?.has('graphQuery')
|
|
21
|
+
? '- Code-graph tools are your primary navigation surface: start with graphQuery before any grep/readFile exploration when you need architecture, orientation, relationships, "where does X live", or any unfamiliar/large codebase; use graphExplain for one symbol, graphPath to trace how two things connect, and graphAffected for change blast radius before risky edits. Do not run grep loops or read whole directories to discover structure the graph already maps — graphQuery first, grep only for exact-string lookups the graph cannot answer. If a graph tool answers graph_not_built, call graphRebuild once, then retry. Edges marked INFERRED are resolved leads, not facts. Graph output is advisory context, never validation evidence. A stale graph flag means files changed since it was built — graphRebuild refreshes it cheaply.\n'
|
|
22
|
+
: '';
|
|
20
23
|
const modelLine = options.model ? `\nActive model: ${options.model.provider}/${options.model.name}` : '';
|
|
21
24
|
const hasTool = (name) => options.availableTools?.has(name) ?? true;
|
|
22
25
|
const processRule = hasTool('process') ? ', inspect them with process/readToolOutput, and kill every process you start when done' : '';
|
|
@@ -39,10 +42,10 @@ export function buildSystemPrompt(contextFiles = [], session, options = {}) {
|
|
|
39
42
|
- ${SECRET_FILE_RULE}
|
|
40
43
|
|
|
41
44
|
## Tool use
|
|
42
|
-
${lspToolRule}${mcpToolRule}- ${UNTRUSTED_TOOL_OUTPUT_RULE}
|
|
43
|
-
- grep
|
|
44
|
-
- editFile
|
|
45
|
-
-
|
|
45
|
+
${lspToolRule}${mcpToolRule}${graphToolRule}- ${UNTRUSTED_TOOL_OUTPUT_RULE}
|
|
46
|
+
- grep finds text patterns and non-semantic matches; listFiles discovers structure; readFile returns bounded, paginated numbered lines.
|
|
47
|
+
- editFile applies unique replacements (batch same-file edits; re-read the file and use replaceLines when a match fails or is stale); replaceInFiles applies guarded cross-file replacements (dry-run first); writeFile creates files, overwrites only when explicitly requested, and chunks large content via append.
|
|
48
|
+
- shell runs inspection, scripts, and validation — set purpose=validation for custom checks so real exit results count as completion evidence; use background=true only when managed process tools are available${processRule}; readToolOutput retrieves omitted oversized output.
|
|
46
49
|
${fetchRule}${subagentRule}${coordinationRule ? `- ${coordinationRule}\n` : ''}
|
|
47
50
|
- Prefer targeted reads and checks. Do not repeat unchanged reads or failing validation without a relevant change. When several independent files are already known, read them together instead of discovering them one model step at a time.
|
|
48
51
|
- Ignored files require explicit need. Keep file mutations separate from validation commands when practical.
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export type ToolFailureReasonCode = 'old_text_missing' | 'old_text_not_unique' | 'overlapping_edits' | 'ignored_path' | 'ignore_check_unavailable' | 'secret_file_protected' | 'git_internals_protected' | 'multi_link_file_protected' | 'path_not_found' | 'not_a_file' | 'permission_denied' | 'outside_workspace' | 'binary_file' | 'existing_file_requires_overwrite' | 'write_chunk_too_large' | 'conflicting_write_modes' | 'append_target_missing' | 'invalid_line_range' | 'io_error' | 'file_too_large' | 'blocked_url' | 'background_limit' | 'background_not_allowed' | 'process_id_required' | 'process_not_found' | 'process_already_exited' | 'process_kill_failed' | 'output_expired' | 'aborted' | 'missing_executable' | 'scoped_instructions_discovered';
|
|
1
|
+
export type ToolFailureReasonCode = 'old_text_missing' | 'old_text_not_unique' | 'overlapping_edits' | 'ignored_path' | 'ignore_check_unavailable' | 'secret_file_protected' | 'git_internals_protected' | 'multi_link_file_protected' | 'path_not_found' | 'not_a_file' | 'permission_denied' | 'outside_workspace' | 'binary_file' | 'existing_file_requires_overwrite' | 'write_chunk_too_large' | 'conflicting_write_modes' | 'append_target_missing' | 'invalid_line_range' | 'io_error' | 'file_too_large' | 'blocked_url' | 'background_limit' | 'background_not_allowed' | 'process_id_required' | 'process_not_found' | 'process_already_exited' | 'process_kill_failed' | 'output_expired' | 'aborted' | 'missing_executable' | 'graph_not_built' | 'graph_unavailable' | 'scoped_instructions_discovered';
|
|
2
2
|
export type ToolDiffLine = {
|
|
3
3
|
type: 'add' | 'remove' | 'context';
|
|
4
4
|
oldLine?: number;
|
|
@@ -2,5 +2,11 @@ function isObject(value) {
|
|
|
2
2
|
return typeof value === 'object' && value != null;
|
|
3
3
|
}
|
|
4
4
|
export function isValidationSummary(value) {
|
|
5
|
-
|
|
5
|
+
// Require the discriminating fields too, not just summaryText/diagnostics, so
|
|
6
|
+
// a shape that merely has those two cannot be narrowed to a full ValidationSummary.
|
|
7
|
+
return isObject(value)
|
|
8
|
+
&& typeof value.kind === 'string'
|
|
9
|
+
&& typeof value.status === 'string'
|
|
10
|
+
&& typeof value.summaryText === 'string'
|
|
11
|
+
&& Array.isArray(value.diagnostics);
|
|
6
12
|
}
|