@denizokcu/haze 0.6.0 → 0.7.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.
- package/CHANGELOG.md +19 -0
- package/README.md +59 -12
- package/dist/cli/chat/TaskBar.d.ts +9 -0
- package/dist/cli/chat/TaskBar.js +40 -0
- package/dist/cli/chat/chatMetrics.d.ts +11 -0
- package/dist/cli/chat/chatMetrics.js +50 -0
- package/dist/cli/chat/inputSuggestions.d.ts +16 -0
- package/dist/cli/chat/inputSuggestions.js +55 -0
- package/dist/cli/chat/messages.d.ts +9 -0
- package/dist/cli/chat/messages.js +76 -0
- package/dist/cli/chat/sessionRecorder.d.ts +12 -0
- package/dist/cli/chat/sessionRecorder.js +21 -0
- package/dist/cli/chat/startupInfo.d.ts +4 -0
- package/dist/cli/chat/startupInfo.js +53 -0
- package/dist/cli/chat/turnState.d.ts +5 -0
- package/dist/cli/chat/turnState.js +20 -0
- package/dist/cli/commands/chat.d.ts +0 -1
- package/dist/cli/commands/chat.js +293 -894
- package/dist/cli/commands/chatModes.d.ts +8 -0
- package/dist/cli/commands/chatModes.js +44 -0
- package/dist/cli/commands/commandHelp.d.ts +6 -0
- package/dist/cli/commands/commandHelp.js +25 -0
- package/dist/cli/commands/commands.d.ts +1 -1
- package/dist/cli/commands/commands.js +41 -267
- package/dist/cli/commands/formatters.js +12 -4
- package/dist/cli/commands/initCommand.d.ts +2 -0
- package/dist/cli/commands/initCommand.js +19 -0
- package/dist/cli/commands/logsCommand.d.ts +2 -0
- package/dist/cli/commands/logsCommand.js +63 -0
- package/dist/cli/commands/lspWizard.d.ts +14 -0
- package/dist/cli/commands/lspWizard.js +44 -0
- package/dist/cli/commands/mcpWizard.d.ts +15 -0
- package/dist/cli/commands/mcpWizard.js +69 -0
- package/dist/cli/commands/modelCommand.d.ts +2 -0
- package/dist/cli/commands/modelCommand.js +36 -0
- package/dist/cli/commands/providerWizard.d.ts +30 -0
- package/dist/cli/commands/providerWizard.js +114 -0
- package/dist/cli/commands/runCommand.d.ts +16 -0
- package/dist/cli/commands/runCommand.js +170 -0
- package/dist/cli/commands/settingsSummary.d.ts +3 -0
- package/dist/cli/commands/settingsSummary.js +40 -0
- package/dist/cli/commands/skillConfirmRemove.d.ts +11 -0
- package/dist/cli/commands/skillConfirmRemove.js +19 -0
- package/dist/cli/commands/skillCreation.d.ts +12 -0
- package/dist/cli/commands/skillCreation.js +14 -0
- package/dist/cli/commands/skillWizard.d.ts +15 -0
- package/dist/cli/commands/skillWizard.js +38 -0
- package/dist/cli/commands/streaming/assistantText.d.ts +17 -0
- package/dist/cli/commands/streaming/assistantText.js +115 -0
- package/dist/cli/commands/streaming/toolGroupRenderer.d.ts +55 -0
- package/dist/cli/commands/streaming/toolGroupRenderer.js +102 -0
- package/dist/cli/commands/streaming/toolResultState.d.ts +13 -0
- package/dist/cli/commands/streaming/toolResultState.js +25 -0
- package/dist/cli/commands/streaming/turnRuntime.d.ts +78 -0
- package/dist/cli/commands/streaming/turnRuntime.js +86 -0
- package/dist/cli/commands/streaming.d.ts +9 -25
- package/dist/cli/commands/streaming.js +82 -347
- package/dist/cli/commands/wizardActions.d.ts +40 -0
- package/dist/cli/commands/wizardActions.js +40 -0
- package/dist/cli/commands/wizardInput.d.ts +4 -0
- package/dist/cli/commands/wizardInput.js +19 -0
- package/dist/cli/commands/wizardPrompts.d.ts +22 -0
- package/dist/cli/commands/wizardPrompts.js +52 -0
- package/dist/cli/commands/wizardSuggestions.d.ts +23 -0
- package/dist/cli/commands/wizardSuggestions.js +139 -0
- package/dist/cli/index.js +62 -4
- package/dist/config/contextFiles.d.ts +8 -1
- package/dist/config/contextFiles.js +25 -12
- package/dist/config/lspSettings.js +3 -6
- package/dist/config/mcpSettings.js +5 -5
- package/dist/config/providers.js +4 -4
- package/dist/config/skillSettings.js +4 -3
- package/dist/core/agent/budgets.d.ts +6 -0
- package/dist/core/agent/budgets.js +6 -0
- package/dist/core/agent/compaction.js +1 -1
- package/dist/core/agent/requestAssembly.d.ts +0 -7
- package/dist/core/agent/requestAssembly.js +27 -5
- package/dist/core/agent/toolOutputStore.js +5 -4
- package/dist/core/agent/toolResults.d.ts +31 -0
- package/dist/core/agent/toolResults.js +42 -0
- package/dist/core/agent/turnPolicy.d.ts +8 -0
- package/dist/core/agent/turnPolicy.js +23 -0
- package/dist/core/agent/workState.d.ts +18 -5
- package/dist/core/agent/workState.js +39 -20
- package/dist/core/bashOutput/reducers/content.d.ts +1 -0
- package/dist/core/bashOutput/reducers/content.js +1 -1
- package/dist/core/bashOutput/reducers/gh.d.ts +1 -0
- package/dist/core/bashOutput/reducers/gh.js +77 -0
- package/dist/core/bashOutput/registry.js +8 -0
- package/dist/core/goal/sessionGoal.d.ts +6 -30
- package/dist/core/goal/sessionGoal.js +3 -68
- package/dist/core/safety/bashClassifier.js +30 -0
- package/dist/core/safety/urlGuard.d.ts +1 -0
- package/dist/core/safety/urlGuard.js +6 -1
- package/dist/core/session/sessionSlimming.d.ts +5 -0
- package/dist/core/session/sessionSlimming.js +78 -0
- package/dist/core/session/sessionStore.d.ts +23 -3
- package/dist/core/session/sessionStore.js +30 -10
- package/dist/core/subagent/subagentRunner.d.ts +11 -1
- package/dist/core/subagent/subagentRunner.js +1 -0
- package/dist/llm/capabilities.d.ts +12 -0
- package/dist/llm/capabilities.js +10 -0
- package/dist/llm/client.d.ts +1 -0
- package/dist/llm/client.js +11 -2
- package/dist/llm/hazeTools.d.ts +31 -32
- package/dist/llm/hazeTools.js +40 -567
- package/dist/llm/lsp.d.ts +46 -1
- package/dist/llm/lsp.js +9 -9
- package/dist/llm/lspTools.d.ts +2 -20
- package/dist/llm/mcp.js +9 -0
- package/dist/llm/requestContext.js +7 -22
- package/dist/llm/systemPrompt.d.ts +1 -0
- package/dist/llm/systemPrompt.js +1 -1
- package/dist/llm/tools/bashTool.d.ts +5 -0
- package/dist/llm/tools/bashTool.js +81 -0
- package/dist/llm/tools/editMatch.d.ts +55 -0
- package/dist/llm/tools/editMatch.js +99 -0
- package/dist/llm/tools/failures.d.ts +36 -0
- package/dist/llm/tools/failures.js +38 -0
- package/dist/llm/tools/fetchTool.d.ts +65 -0
- package/dist/llm/tools/fetchTool.js +45 -0
- package/dist/llm/tools/fileToolShared.d.ts +10 -0
- package/dist/llm/tools/fileToolShared.js +43 -0
- package/dist/llm/tools/grepParse.d.ts +13 -0
- package/dist/llm/tools/grepParse.js +67 -0
- package/dist/llm/tools/outputCap.d.ts +53 -0
- package/dist/llm/tools/outputCap.js +67 -0
- package/dist/llm/tools/storedOutputTool.d.ts +10 -0
- package/dist/llm/tools/storedOutputTool.js +17 -0
- package/dist/llm/tools/taskTool.d.ts +28 -0
- package/dist/llm/tools/taskTool.js +41 -0
- package/dist/llm/tools/toolContext.d.ts +69 -0
- package/dist/llm/tools/toolContext.js +187 -0
- package/dist/llm/tools/workspaceFile.d.ts +33 -0
- package/dist/llm/tools/workspaceFile.js +27 -0
- package/dist/llm/webFetch.d.ts +13 -1
- package/dist/llm/webFetch.js +91 -7
- package/dist/skills/builder/SkillBuilder.d.ts +3 -0
- package/dist/skills/builder/SkillBuilder.js +1 -1
- package/dist/ui/components/TextInput.js +1 -99
- package/dist/ui/inputBuffer.d.ts +28 -0
- package/dist/ui/inputBuffer.js +99 -0
- package/dist/utils/collections.d.ts +6 -0
- package/dist/utils/collections.js +9 -0
- package/dist/utils/path.d.ts +2 -0
- package/dist/utils/path.js +40 -0
- package/package.json +1 -2
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { HazeMcpServer, HazeSettings } from '../../config/settings.js';
|
|
2
|
+
export type McpWizardResult = {
|
|
3
|
+
message?: string;
|
|
4
|
+
mode?: 'chat' | 'mcp' | 'mcpAction' | 'mcpAddName' | 'mcpAddKey' | 'mcpSetKey' | 'mcpConfirmRemove';
|
|
5
|
+
selectedName?: string;
|
|
6
|
+
draft?: Partial<HazeMcpServer>;
|
|
7
|
+
settingsPatch?: Partial<HazeSettings>;
|
|
8
|
+
server?: HazeMcpServer;
|
|
9
|
+
clearDraft?: boolean;
|
|
10
|
+
};
|
|
11
|
+
export declare function selectMcpServerResult(settings: HazeSettings, serverName: string): McpWizardResult;
|
|
12
|
+
export declare function selectMcpPresetResult(settings: HazeSettings, presetId: string): McpWizardResult;
|
|
13
|
+
export declare function selectMcpActionResult(settings: HazeSettings, selectedName: string | undefined, action: string): McpWizardResult;
|
|
14
|
+
export declare function finishMcpCustomResult(settings: HazeSettings, draft: Partial<HazeMcpServer>, keyValue?: string): McpWizardResult;
|
|
15
|
+
export declare function setMcpServerKeyResult(settings: HazeSettings, selectedName: string | undefined, keyValue: string): McpWizardResult;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { findMcpPreset, findMcpServer, toggleMcpServer, upsertMcpServer } from '../../config/mcpSettings.js';
|
|
2
|
+
import { COMMON_ACTIONS, MCP_ACTIONS, MCP_TRANSPORTS, SERVER_CHOICES } from './wizardActions.js';
|
|
3
|
+
export function selectMcpServerResult(settings, serverName) {
|
|
4
|
+
if (serverName === SERVER_CHOICES.addServer)
|
|
5
|
+
return { mode: 'mcpAddName', clearDraft: true, message: 'Choose an MCP preset, or select "custom" to enter details manually.' };
|
|
6
|
+
const server = findMcpServer(settings, serverName);
|
|
7
|
+
if (!server)
|
|
8
|
+
return { mode: 'chat', message: `No MCP server named ${serverName}. Use /mcp and choose add server.` };
|
|
9
|
+
return { mode: 'mcpAction', selectedName: server.name, message: `${server.name}: choose an action.` };
|
|
10
|
+
}
|
|
11
|
+
export function selectMcpPresetResult(settings, presetId) {
|
|
12
|
+
if (presetId === SERVER_CHOICES.custom)
|
|
13
|
+
return { mode: 'mcpAddName', clearDraft: true, message: 'MCP server name? Example: context7, github, filesystem.' };
|
|
14
|
+
const preset = findMcpPreset(presetId);
|
|
15
|
+
if (!preset)
|
|
16
|
+
return { message: `Unknown preset: ${presetId}.` };
|
|
17
|
+
if (findMcpServer(settings, presetId))
|
|
18
|
+
return { mode: 'chat', message: `MCP server ${presetId} already exists. Use /mcp to manage existing servers.` };
|
|
19
|
+
return {
|
|
20
|
+
mode: 'mcpAddKey',
|
|
21
|
+
draft: { name: presetId, transport: preset.transport, ...(preset.url ? { url: preset.url } : {}) },
|
|
22
|
+
message: `Adding ${presetId} (${preset.transport}${preset.url ? `, ${preset.url}` : ''}).\nOptional API key or auth header value? (Leave blank to skip — Enter works.)`,
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
export function selectMcpActionResult(settings, selectedName, action) {
|
|
26
|
+
if (!selectedName)
|
|
27
|
+
return { mode: 'mcp' };
|
|
28
|
+
const server = findMcpServer(settings, selectedName);
|
|
29
|
+
if (!server)
|
|
30
|
+
return { mode: 'chat', selectedName: undefined, message: `MCP server ${selectedName} not found.` };
|
|
31
|
+
if (action === COMMON_ACTIONS.enable || action === COMMON_ACTIONS.disable) {
|
|
32
|
+
const enabled = action === COMMON_ACTIONS.enable;
|
|
33
|
+
return { mode: 'chat', selectedName: undefined, settingsPatch: { mcpServers: toggleMcpServer(settings, selectedName, enabled) ?? [] }, message: `MCP server ${selectedName} ${enabled ? 'enabled' : 'disabled'}.` };
|
|
34
|
+
}
|
|
35
|
+
if (action === MCP_ACTIONS.setApiKey)
|
|
36
|
+
return { mode: 'mcpSetKey', message: `New API key for ${selectedName}? (current: ${server.headers?.length ? 'saved' : 'not set'}) Sent as Authorization: Bearer <value>.` };
|
|
37
|
+
if (action === MCP_ACTIONS.removeServer)
|
|
38
|
+
return { mode: 'mcpConfirmRemove', message: `Remove MCP server ${selectedName}? Type "yes" to confirm. Esc to cancel.` };
|
|
39
|
+
return { message: `Unknown MCP action: ${action}` };
|
|
40
|
+
}
|
|
41
|
+
export function finishMcpCustomResult(settings, draft, keyValue) {
|
|
42
|
+
const name = draft.name?.trim();
|
|
43
|
+
const transport = draft.transport;
|
|
44
|
+
if (!name || !transport)
|
|
45
|
+
return { mode: 'chat', clearDraft: true, message: 'MCP server name and transport are required.' };
|
|
46
|
+
const headers = keyValue?.trim() ? [{ name: 'Authorization', value: `Bearer ${keyValue.trim()}` }] : undefined;
|
|
47
|
+
const server = transport === MCP_TRANSPORTS.stdio
|
|
48
|
+
? { name, transport, command: draft.command, args: draft.args, ...(headers ? { headers } : {}), enabled: true }
|
|
49
|
+
: { name, transport, url: draft.url, ...(headers ? { headers } : {}), enabled: true };
|
|
50
|
+
if (transport === MCP_TRANSPORTS.stdio && !server.command)
|
|
51
|
+
return { mode: 'chat', clearDraft: true, message: 'Command is required for stdio transport.' };
|
|
52
|
+
if (transport !== MCP_TRANSPORTS.stdio && !server.url)
|
|
53
|
+
return { mode: 'chat', clearDraft: true, message: `URL is required for ${transport} transport.` };
|
|
54
|
+
const location = transport === MCP_TRANSPORTS.stdio ? `${server.command}${(server.args ?? []).length ? ` ${(server.args ?? []).join(' ')}` : ''}` : server.url;
|
|
55
|
+
return { mode: 'chat', clearDraft: true, server, settingsPatch: { mcpServers: upsertMcpServer(settings, server) }, message: `Added MCP server ${name} (${transport}, ${location}). Tools load on the next turn.` };
|
|
56
|
+
}
|
|
57
|
+
export function setMcpServerKeyResult(settings, selectedName, keyValue) {
|
|
58
|
+
if (!selectedName)
|
|
59
|
+
return { mode: 'mcp' };
|
|
60
|
+
const server = findMcpServer(settings, selectedName);
|
|
61
|
+
if (!server)
|
|
62
|
+
return { mode: 'chat', selectedName: undefined, message: `MCP server ${selectedName} not found.` };
|
|
63
|
+
const key = keyValue.trim();
|
|
64
|
+
if (!key)
|
|
65
|
+
return { message: 'API key cannot be empty. Esc to cancel.' };
|
|
66
|
+
const headers = (server.headers ?? []).filter(header => header.name !== 'Authorization');
|
|
67
|
+
headers.push({ name: 'Authorization', value: `Bearer ${key}` });
|
|
68
|
+
return { mode: 'chat', selectedName: undefined, settingsPatch: { mcpServers: upsertMcpServer(settings, { ...server, headers }) }, message: `API key updated for ${server.name}.` };
|
|
69
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { activeProvider, configuredProviders, modelSelector, resolveModelSelector, upsertProvider } from '../../config/providers.js';
|
|
2
|
+
export async function handleModelCommand(value, ctx) {
|
|
3
|
+
if (value === '/model') {
|
|
4
|
+
ctx.setModelProviderFilter?.(undefined);
|
|
5
|
+
ctx.setMode('model');
|
|
6
|
+
ctx.addSystemMessage('Choose a model. Selecting a model also sets its provider.');
|
|
7
|
+
return 'handled';
|
|
8
|
+
}
|
|
9
|
+
if (value === '/model list') {
|
|
10
|
+
const providers = configuredProviders(ctx.settings);
|
|
11
|
+
ctx.addSystemMessage(['Configured models:', ...providers.flatMap(provider => provider.models.map(model => `- ${modelSelector(provider, model)} - ${provider.name}`))].join('\n'));
|
|
12
|
+
return 'handled';
|
|
13
|
+
}
|
|
14
|
+
if (!value.startsWith('/model '))
|
|
15
|
+
return undefined;
|
|
16
|
+
const selector = value.slice('/model '.length).trim();
|
|
17
|
+
const resolved = resolveModelSelector(ctx.settings, selector);
|
|
18
|
+
if (resolved.status === 'ambiguous') {
|
|
19
|
+
ctx.addSystemMessage(`Model ${resolved.model} exists on multiple providers: ${resolved.providers.map(provider => modelSelector(provider, resolved.model)).join(', ')}`);
|
|
20
|
+
return 'handled';
|
|
21
|
+
}
|
|
22
|
+
if (resolved.status === 'missing') {
|
|
23
|
+
const provider = activeProvider(ctx.settings);
|
|
24
|
+
if (!provider) {
|
|
25
|
+
ctx.addSystemMessage('No provider configured. Run /provider to choose or add a provider before setting a model.');
|
|
26
|
+
return 'handled';
|
|
27
|
+
}
|
|
28
|
+
const nextProvider = provider.models.includes(selector) ? provider : { ...provider, models: [...provider.models, selector] };
|
|
29
|
+
await ctx.updateSettings({ provider: provider.name, model: selector, providers: upsertProvider(ctx.settings, nextProvider) });
|
|
30
|
+
ctx.addSystemMessage(`Model set to ${selector} on ${provider.name}. Saved to ~/.haze/settings.json.`);
|
|
31
|
+
return 'handled';
|
|
32
|
+
}
|
|
33
|
+
await ctx.updateSettings({ provider: resolved.provider.name, model: resolved.model });
|
|
34
|
+
ctx.addSystemMessage(`Model set to ${resolved.model} on ${resolved.provider.name}. Saved to ~/.haze/settings.json.`);
|
|
35
|
+
return 'handled';
|
|
36
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { HazeProviderSettings, HazeSettings } from '../../config/settings.js';
|
|
2
|
+
import type { Mode } from './chatModes.js';
|
|
3
|
+
type WizardPatch = {
|
|
4
|
+
settingsPatch?: Partial<HazeSettings>;
|
|
5
|
+
message: string;
|
|
6
|
+
provider?: HazeProviderSettings;
|
|
7
|
+
providers?: HazeProviderSettings[];
|
|
8
|
+
models?: string[];
|
|
9
|
+
};
|
|
10
|
+
export declare function providerAppendModels(settings: HazeSettings, providerName: string | undefined, modelsValue: string): WizardPatch;
|
|
11
|
+
export declare function providerFinishAdd(settings: HazeSettings, draft: Partial<HazeProviderSettings>, modelsValue: string): WizardPatch;
|
|
12
|
+
export declare function providerRemoveModels(settings: HazeSettings, providerName: string | undefined, modelsValue: string): WizardPatch & {
|
|
13
|
+
remaining?: string[];
|
|
14
|
+
removed?: string[];
|
|
15
|
+
notFound?: string[];
|
|
16
|
+
wasActive?: boolean;
|
|
17
|
+
};
|
|
18
|
+
export declare function providerRemove(settings: HazeSettings, providerName: string | undefined): WizardPatch & {
|
|
19
|
+
wasActiveProvider?: boolean;
|
|
20
|
+
};
|
|
21
|
+
export declare function providerSetKey(settings: HazeSettings, providerName: string | undefined, value: string): WizardPatch & {
|
|
22
|
+
key?: string;
|
|
23
|
+
};
|
|
24
|
+
export type ProviderActionResult = {
|
|
25
|
+
message: string;
|
|
26
|
+
mode?: Mode;
|
|
27
|
+
selectedName?: string;
|
|
28
|
+
};
|
|
29
|
+
export declare function providerActionResult(action: string, provider: HazeProviderSettings | undefined): ProviderActionResult;
|
|
30
|
+
export {};
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { configuredProviders, findProvider, upsertProvider } from '../../config/providers.js';
|
|
2
|
+
import { PROVIDER_ACTIONS } from './wizardActions.js';
|
|
3
|
+
import { commaList } from './wizardInput.js';
|
|
4
|
+
export function providerAppendModels(settings, providerName, modelsValue) {
|
|
5
|
+
const provider = providerName ? findProvider(settings, providerName) : undefined;
|
|
6
|
+
const models = commaList(modelsValue);
|
|
7
|
+
if (!provider)
|
|
8
|
+
return { message: 'No provider selected.' };
|
|
9
|
+
if (models.length === 0)
|
|
10
|
+
return { provider, models, message: 'Enter at least one model name.' };
|
|
11
|
+
const nextProvider = { ...provider, models: [...new Set([...provider.models, ...models])] };
|
|
12
|
+
return {
|
|
13
|
+
provider,
|
|
14
|
+
models,
|
|
15
|
+
settingsPatch: { providers: upsertProvider(settings, nextProvider), provider: provider.name },
|
|
16
|
+
message: `Added ${models.length} model${models.length === 1 ? '' : 's'} to ${provider.name}. Choose a model.`,
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
export function providerFinishAdd(settings, draft, modelsValue) {
|
|
20
|
+
const models = commaList(modelsValue);
|
|
21
|
+
if (!draft.name || !draft.url || models.length === 0) {
|
|
22
|
+
return { models, message: 'Provider name, URL, and at least one model are required.' };
|
|
23
|
+
}
|
|
24
|
+
const provider = {
|
|
25
|
+
name: draft.name,
|
|
26
|
+
url: draft.url,
|
|
27
|
+
...(draft.key ? { key: draft.key } : {}),
|
|
28
|
+
models: [...new Set(models)],
|
|
29
|
+
};
|
|
30
|
+
return {
|
|
31
|
+
provider,
|
|
32
|
+
models,
|
|
33
|
+
settingsPatch: { providers: upsertProvider(settings, provider), provider: provider.name },
|
|
34
|
+
message: `Added provider ${provider.name}. Choose a model.`,
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
export function providerRemoveModels(settings, providerName, modelsValue) {
|
|
38
|
+
const provider = providerName ? findProvider(settings, providerName) : undefined;
|
|
39
|
+
if (!provider)
|
|
40
|
+
return { message: 'No provider selected.' };
|
|
41
|
+
const toRemove = commaList(modelsValue);
|
|
42
|
+
if (toRemove.length === 0)
|
|
43
|
+
return { provider, message: 'Enter at least one model name. Esc to cancel.' };
|
|
44
|
+
const remaining = provider.models.filter(model => !toRemove.includes(model));
|
|
45
|
+
if (remaining.length === 0)
|
|
46
|
+
return { provider, remaining, message: 'A provider must have at least one model. Remove the provider instead.' };
|
|
47
|
+
const removed = provider.models.filter(model => toRemove.includes(model));
|
|
48
|
+
const notFound = toRemove.filter(model => !provider.models.includes(model));
|
|
49
|
+
const updated = { ...provider, models: remaining };
|
|
50
|
+
const wasActive = Boolean(settings.model && provider.models.includes(settings.model) && !remaining.includes(settings.model));
|
|
51
|
+
const parts = [`Removed ${removed.join(', ')} from ${provider.name}.`];
|
|
52
|
+
if (notFound.length)
|
|
53
|
+
parts.push(`Not found: ${notFound.join(', ')}.`);
|
|
54
|
+
if (wasActive)
|
|
55
|
+
parts.push(`Active model updated to ${remaining[0]}.`);
|
|
56
|
+
return {
|
|
57
|
+
provider,
|
|
58
|
+
remaining,
|
|
59
|
+
removed,
|
|
60
|
+
notFound,
|
|
61
|
+
wasActive,
|
|
62
|
+
settingsPatch: {
|
|
63
|
+
providers: upsertProvider(settings, updated),
|
|
64
|
+
...(wasActive ? { model: remaining[0] } : {}),
|
|
65
|
+
},
|
|
66
|
+
message: parts.join(' '),
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
export function providerRemove(settings, providerName) {
|
|
70
|
+
const provider = providerName ? findProvider(settings, providerName) : undefined;
|
|
71
|
+
if (!provider)
|
|
72
|
+
return { message: 'No provider selected.' };
|
|
73
|
+
const providers = configuredProviders(settings).filter(candidate => candidate.name !== providerName);
|
|
74
|
+
const wasActiveProvider = settings.provider === providerName || (!settings.provider && configuredProviders(settings)[0]?.name === providerName);
|
|
75
|
+
return {
|
|
76
|
+
provider,
|
|
77
|
+
providers,
|
|
78
|
+
wasActiveProvider,
|
|
79
|
+
settingsPatch: {
|
|
80
|
+
providers,
|
|
81
|
+
...(wasActiveProvider ? { provider: providers[0]?.name, model: providers[0]?.models[0] } : {}),
|
|
82
|
+
},
|
|
83
|
+
message: `Removed provider ${provider.name}.${wasActiveProvider ? ` Switched to ${providers[0]?.name ?? 'no provider'}.` : ''}`,
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
export function providerSetKey(settings, providerName, value) {
|
|
87
|
+
const provider = providerName ? findProvider(settings, providerName) : undefined;
|
|
88
|
+
if (!provider)
|
|
89
|
+
return { message: 'No provider selected.' };
|
|
90
|
+
const key = value.trim();
|
|
91
|
+
if (!key)
|
|
92
|
+
return { provider, message: 'API key cannot be empty. Esc to cancel.' };
|
|
93
|
+
return {
|
|
94
|
+
provider,
|
|
95
|
+
key,
|
|
96
|
+
settingsPatch: { providers: upsertProvider(settings, { ...provider, key }) },
|
|
97
|
+
message: `API key updated for ${provider.name}.`,
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
export function providerActionResult(action, provider) {
|
|
101
|
+
if (!provider)
|
|
102
|
+
return { message: '', mode: 'provider' };
|
|
103
|
+
if (action === PROVIDER_ACTIONS.useProvider)
|
|
104
|
+
return { message: '', selectedName: undefined, mode: 'model' };
|
|
105
|
+
if (action === PROVIDER_ACTIONS.addModels)
|
|
106
|
+
return { message: `Comma-separated model names to add to ${provider.name}?`, mode: 'providerAppendModels' };
|
|
107
|
+
if (action === PROVIDER_ACTIONS.setApiKey)
|
|
108
|
+
return { message: `New API key for ${provider.name}? (current: ${provider.key ? 'saved' : 'not set'})`, mode: 'providerSetKey' };
|
|
109
|
+
if (action === PROVIDER_ACTIONS.removeModels)
|
|
110
|
+
return { message: `Comma-separated model names to remove from ${provider.name}?\nCurrent models: ${provider.models.join(', ')}`, mode: 'providerRemoveModels' };
|
|
111
|
+
if (action === PROVIDER_ACTIONS.removeProvider)
|
|
112
|
+
return { message: `Remove provider ${provider.name}? Type "yes" to confirm. Esc to cancel.`, mode: 'providerConfirmRemove' };
|
|
113
|
+
return { message: `Unknown provider action: ${action}` };
|
|
114
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export type HeadlessOutput = 'text' | 'json' | 'stream-json';
|
|
2
|
+
export interface HeadlessOptions {
|
|
3
|
+
prompt: string;
|
|
4
|
+
modelOverride?: string;
|
|
5
|
+
output: HeadlessOutput;
|
|
6
|
+
debug?: boolean;
|
|
7
|
+
}
|
|
8
|
+
/** Pinned, documented usage shape emitted in `--output json` (avoids leaking internal estimates). */
|
|
9
|
+
export interface HeadlessUsage {
|
|
10
|
+
inputTokens: number;
|
|
11
|
+
outputTokens: number;
|
|
12
|
+
cacheReadTokens: number;
|
|
13
|
+
cacheWriteTokens: number;
|
|
14
|
+
reasoningTokens: number;
|
|
15
|
+
}
|
|
16
|
+
export declare function runHeadless(options: HeadlessOptions): Promise<number>;
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
import { readContextFiles } from '../../config/contextFiles.js';
|
|
2
|
+
import { runAgentTurn } from './streaming.js';
|
|
3
|
+
import { EMPTY_TOKEN_USAGE, accumulateTokenUsage } from '../chat/turnState.js';
|
|
4
|
+
import { readSettings } from '../../config/settings.js';
|
|
5
|
+
import { activeModel, modelSelector, resolveModelSelector } from '../../config/providers.js';
|
|
6
|
+
import { createLog, endLog } from '../../core/log/llmLog.js';
|
|
7
|
+
function debug(line) {
|
|
8
|
+
if (process.env.HAZE_DEBUG)
|
|
9
|
+
process.stderr.write(`[haze] ${line}\n`);
|
|
10
|
+
}
|
|
11
|
+
function pinnedUsage(usage) {
|
|
12
|
+
// Normalize every field to a number: TokenUsage seeds most fields to 0 but
|
|
13
|
+
// inputTokens/outputTokens may be undefined until the first report. A uniform ?? 0
|
|
14
|
+
// keeps the documented CI contract literal (all five fields always present).
|
|
15
|
+
return {
|
|
16
|
+
inputTokens: usage.inputTokens ?? 0,
|
|
17
|
+
outputTokens: usage.outputTokens ?? 0,
|
|
18
|
+
cacheReadTokens: usage.cacheReadTokens ?? 0,
|
|
19
|
+
cacheWriteTokens: usage.cacheWriteTokens ?? 0,
|
|
20
|
+
reasoningTokens: usage.reasoningTokens ?? 0,
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
function errorText(error) {
|
|
24
|
+
return error instanceof Error ? error.message : String(error);
|
|
25
|
+
}
|
|
26
|
+
function toHeadlessStreamEvent(event) {
|
|
27
|
+
switch (event.type) {
|
|
28
|
+
case 'turn_start':
|
|
29
|
+
return { type: 'turn_start', request: event.request, at: event.at };
|
|
30
|
+
case 'turn_end':
|
|
31
|
+
return { type: 'turn_end', request: event.request, status: event.status, at: event.at };
|
|
32
|
+
case 'message_start':
|
|
33
|
+
return { type: 'message_start', id: event.id, role: event.role, at: event.at };
|
|
34
|
+
case 'message_update':
|
|
35
|
+
return { type: 'message_update', id: event.id, text: event.text, at: event.at };
|
|
36
|
+
case 'message_end':
|
|
37
|
+
return { ...(event.hidden === undefined ? {} : { hidden: event.hidden }), type: 'message_end', id: event.id, text: event.text, at: event.at };
|
|
38
|
+
case 'tool_start':
|
|
39
|
+
// Intentionally omit raw tool input: stdout is often persisted by harnesses/CI.
|
|
40
|
+
return { type: 'tool_start', id: event.id, name: event.name, at: event.at };
|
|
41
|
+
case 'tool_end':
|
|
42
|
+
return { type: 'tool_end', id: event.id, name: event.name, success: event.success, durationMs: event.durationMs, ...(event.error === undefined ? {} : { error: errorText(event.error) }), at: event.at };
|
|
43
|
+
case 'retry':
|
|
44
|
+
return { type: 'retry', attempt: event.attempt, maxAttempts: event.maxAttempts, delayMs: event.delayMs, error: event.error, at: event.at };
|
|
45
|
+
case 'context_overflow':
|
|
46
|
+
return { type: 'context_overflow', recovered: event.recovered, error: event.error, at: event.at };
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
function writeNdjson(value) {
|
|
50
|
+
process.stdout.write(`${JSON.stringify(value)}\n`);
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Resolve the model the run will use *before* invoking the agent, so a bad `--model`
|
|
54
|
+
* selector or a missing provider produces a precise error (not the generic no-provider
|
|
55
|
+
* message) with a non-zero exit. Returns an error string when the run cannot proceed.
|
|
56
|
+
*/
|
|
57
|
+
async function resolveModelOrError(modelOverride) {
|
|
58
|
+
const settings = await readSettings();
|
|
59
|
+
const override = modelOverride?.trim();
|
|
60
|
+
if (override) {
|
|
61
|
+
const resolved = resolveModelSelector(settings, override);
|
|
62
|
+
if (resolved.status === 'ambiguous') {
|
|
63
|
+
return `Model ${resolved.model} exists on multiple providers: ${resolved.providers.map((provider) => modelSelector(provider, resolved.model)).join(', ')}`;
|
|
64
|
+
}
|
|
65
|
+
if (resolved.status === 'missing') {
|
|
66
|
+
return `No configured model named ${override}. Run /provider, select a provider, then add models.`;
|
|
67
|
+
}
|
|
68
|
+
return undefined;
|
|
69
|
+
}
|
|
70
|
+
if (!activeModel(settings)) {
|
|
71
|
+
return 'No model provider configured. Run /provider to choose or add a provider.';
|
|
72
|
+
}
|
|
73
|
+
return undefined;
|
|
74
|
+
}
|
|
75
|
+
export async function runHeadless(options) {
|
|
76
|
+
const modelError = await resolveModelOrError(options.modelOverride);
|
|
77
|
+
if (modelError) {
|
|
78
|
+
process.stderr.write(`${modelError}\n`);
|
|
79
|
+
return 1;
|
|
80
|
+
}
|
|
81
|
+
const contextFiles = await readContextFiles(process.cwd());
|
|
82
|
+
const session = { start: new Date(), cwd: process.cwd() };
|
|
83
|
+
let conversation = [];
|
|
84
|
+
// Assistant text is delivered in two stages by runAgentTurn: an initial streaming
|
|
85
|
+
// `addMessage`, then a finalizing `updateMessage` with the complete text. We key
|
|
86
|
+
// segments by id and patch them on update so finalized (and multi-segment) text is captured.
|
|
87
|
+
const segments = [];
|
|
88
|
+
let lastAssistantText = '';
|
|
89
|
+
let usage = { ...EMPTY_TOKEN_USAGE };
|
|
90
|
+
let log;
|
|
91
|
+
if (options.debug)
|
|
92
|
+
log = await createLog();
|
|
93
|
+
let emittedTurnStart = false;
|
|
94
|
+
const emitStreamEvent = options.output === 'stream-json'
|
|
95
|
+
? (event) => {
|
|
96
|
+
// runAgentTurn emits nested turn_start/turn_end pairs for retries; expose one clean
|
|
97
|
+
// headless turn and emit the authoritative turn_end after the run settles.
|
|
98
|
+
if (event.type === 'turn_start') {
|
|
99
|
+
if (emittedTurnStart)
|
|
100
|
+
return;
|
|
101
|
+
emittedTurnStart = true;
|
|
102
|
+
}
|
|
103
|
+
else if (event.type === 'turn_end') {
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
const headlessEvent = toHeadlessStreamEvent(event);
|
|
107
|
+
if (headlessEvent)
|
|
108
|
+
writeNdjson(headlessEvent);
|
|
109
|
+
}
|
|
110
|
+
: undefined;
|
|
111
|
+
const callbacks = {
|
|
112
|
+
addMessage: (msg) => {
|
|
113
|
+
if (msg.role === 'assistant')
|
|
114
|
+
segments.push({ id: msg.id, text: msg.text, hidden: msg.hidden });
|
|
115
|
+
},
|
|
116
|
+
updateMessage: (id, update) => {
|
|
117
|
+
const segment = segments.find((s) => s.id === id);
|
|
118
|
+
if (!segment)
|
|
119
|
+
return;
|
|
120
|
+
if (update.text !== undefined)
|
|
121
|
+
segment.text = update.text;
|
|
122
|
+
if (update.hidden !== undefined)
|
|
123
|
+
segment.hidden = update.hidden;
|
|
124
|
+
},
|
|
125
|
+
setConversation: (msgs) => {
|
|
126
|
+
conversation = msgs;
|
|
127
|
+
},
|
|
128
|
+
setBusy: () => undefined,
|
|
129
|
+
setBusyLabel: () => undefined,
|
|
130
|
+
debugLog: debug,
|
|
131
|
+
getConversation: () => conversation,
|
|
132
|
+
getLastAssistantText: () => lastAssistantText,
|
|
133
|
+
setLastAssistantText: (text) => {
|
|
134
|
+
lastAssistantText = text;
|
|
135
|
+
},
|
|
136
|
+
recordTokenUsage: (u) => {
|
|
137
|
+
usage = accumulateTokenUsage(usage, u);
|
|
138
|
+
},
|
|
139
|
+
onEvent: emitStreamEvent,
|
|
140
|
+
log,
|
|
141
|
+
};
|
|
142
|
+
let status;
|
|
143
|
+
let result;
|
|
144
|
+
try {
|
|
145
|
+
({ status } = await runAgentTurn(options.prompt, options.prompt, contextFiles, callbacks, 0, false, false, session, options.modelOverride));
|
|
146
|
+
result = segments.filter((s) => !s.hidden && s.text).map((s) => s.text).join('\n');
|
|
147
|
+
}
|
|
148
|
+
catch (error) {
|
|
149
|
+
status = 'failed';
|
|
150
|
+
result = error instanceof Error ? error.message : String(error);
|
|
151
|
+
}
|
|
152
|
+
finally {
|
|
153
|
+
if (log)
|
|
154
|
+
await endLog(log).catch(() => undefined);
|
|
155
|
+
}
|
|
156
|
+
if (options.output === 'json' || options.output === 'stream-json') {
|
|
157
|
+
if (options.output === 'stream-json')
|
|
158
|
+
writeNdjson({ type: 'turn_end', request: options.prompt, status, at: new Date().toISOString() });
|
|
159
|
+
// For stream-json the agent events have already streamed above; this is the terminal line.
|
|
160
|
+
// It is byte-identical to the --output json envelope, so harnesses can parse the last line the same way.
|
|
161
|
+
writeNdjson({ type: 'result', status, result, usage: pinnedUsage(usage) });
|
|
162
|
+
}
|
|
163
|
+
else if (status === 'complete') {
|
|
164
|
+
process.stdout.write(result + (result.endsWith('\n') ? '' : '\n'));
|
|
165
|
+
}
|
|
166
|
+
else {
|
|
167
|
+
process.stderr.write(`${result || `Turn ${status}.`}\n`);
|
|
168
|
+
}
|
|
169
|
+
return status === 'complete' ? 0 : 1;
|
|
170
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { contextFileDiagnostics, summarizeContextDiagnostics } from '../../config/contextFiles.js';
|
|
2
|
+
import { configuredLspServers } from '../../config/lspSettings.js';
|
|
3
|
+
import { configuredMcpServers } from '../../config/mcpSettings.js';
|
|
4
|
+
import { activeProvider as resolveActiveProvider, configuredProviders, providerHasKey } from '../../config/providers.js';
|
|
5
|
+
import { isSkillEnabled } from '../../config/skillSettings.js';
|
|
6
|
+
import { loadSkillRegistry } from '../../skills/SkillRegistry.js';
|
|
7
|
+
export async function formatSettingsSummary(settings, contextFiles) {
|
|
8
|
+
const providers = configuredProviders(settings);
|
|
9
|
+
const activeProvider = resolveActiveProvider(settings);
|
|
10
|
+
const contextDiagnostics = contextFileDiagnostics(contextFiles);
|
|
11
|
+
const contextTokens = contextDiagnostics.reduce((sum, file) => sum + file.estimatedTokens, 0);
|
|
12
|
+
const summary = summarizeContextDiagnostics(contextFiles);
|
|
13
|
+
const notes = [];
|
|
14
|
+
if (summary.exceedsBudget === true && summary.windowSize) {
|
|
15
|
+
const sharePct = Math.round((summary.budgetShare ?? 0) * 100);
|
|
16
|
+
const thresholdPct = Math.round(summary.budgetThreshold * 100);
|
|
17
|
+
notes.push(`project context exceeds ${thresholdPct}% budget (${sharePct}% of ${Math.round(summary.windowSize / 1000)}k window)`);
|
|
18
|
+
}
|
|
19
|
+
if (summary.duplicateGroups.length > 0) {
|
|
20
|
+
const duplicateTotal = summary.duplicateFileCount;
|
|
21
|
+
notes.push(`${summary.duplicateGroups.length} duplicate group${summary.duplicateGroups.length === 1 ? '' : 's'} (${duplicateTotal} file${duplicateTotal === 1 ? '' : 's'} with identical content)`);
|
|
22
|
+
}
|
|
23
|
+
const lspServers = configuredLspServers(settings);
|
|
24
|
+
const installedSkills = [...(await loadSkillRegistry()).skills.values()];
|
|
25
|
+
const skillNames = installedSkills.map(skill => `${skill.name}${isSkillEnabled(settings, skill.name) ? '' : ' (disabled)'}`).join(', ');
|
|
26
|
+
const lines = [
|
|
27
|
+
`Provider: ${activeProvider?.name ?? 'not configured'}`,
|
|
28
|
+
`Model: ${settings.model ?? 'not set'}`,
|
|
29
|
+
`Base URL: ${activeProvider?.url ?? settings.baseURL ?? 'not configured'}`,
|
|
30
|
+
`API key: ${activeProvider && providerHasKey(settings, activeProvider) ? 'saved' : 'missing'}`,
|
|
31
|
+
`Configured providers: ${providers.map(provider => provider.name).join(', ') || 'none'}`,
|
|
32
|
+
`LSP servers: ${lspServers.map(server => `${server.name}${server.enabled === false ? ' (disabled)' : ''}`).join(', ') || 'none'}`,
|
|
33
|
+
`MCP servers: ${configuredMcpServers(settings).map(server => `${server.name}${server.enabled === false ? ' (disabled)' : ''}`).join(', ') || 'none'}`,
|
|
34
|
+
`Skills: ${skillNames || 'none'}`,
|
|
35
|
+
`Context files: ${contextFiles.length ? `${contextFiles.map(file => file.path).join(', ')} (~${contextTokens} tokens)` : 'none'}`,
|
|
36
|
+
];
|
|
37
|
+
if (notes.length > 0)
|
|
38
|
+
lines.push(`Context note: ${notes.join('; ')}`);
|
|
39
|
+
return lines.join(' | ');
|
|
40
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { HazeSettings } from '../../config/settings.js';
|
|
2
|
+
import type { LoadedSkill } from '../../skills/types.js';
|
|
3
|
+
export type SkillConfirmRemoveResult = {
|
|
4
|
+
message?: string;
|
|
5
|
+
mode?: 'chat';
|
|
6
|
+
settingsPatch?: Partial<HazeSettings>;
|
|
7
|
+
removedDir?: string;
|
|
8
|
+
selectedName?: string;
|
|
9
|
+
skill?: LoadedSkill;
|
|
10
|
+
};
|
|
11
|
+
export declare function skillConfirmRemoveResult(settings: HazeSettings, skills: LoadedSkill[], selectedName: string | undefined, value: string): SkillConfirmRemoveResult;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { removeSkillSetting } from '../../config/skillSettings.js';
|
|
2
|
+
import { isYesConfirmation } from './wizardInput.js';
|
|
3
|
+
export function skillConfirmRemoveResult(settings, skills, selectedName, value) {
|
|
4
|
+
if (!selectedName)
|
|
5
|
+
return { mode: 'chat' };
|
|
6
|
+
if (!isYesConfirmation(value))
|
|
7
|
+
return { mode: 'chat', selectedName: undefined, message: 'Cancelled. Skill not removed.' };
|
|
8
|
+
const skill = skills.find(candidate => candidate.name === selectedName);
|
|
9
|
+
if (!skill)
|
|
10
|
+
return { mode: 'chat', selectedName: undefined, message: `Skill ${selectedName} not found.` };
|
|
11
|
+
return {
|
|
12
|
+
mode: 'chat',
|
|
13
|
+
selectedName: undefined,
|
|
14
|
+
skill,
|
|
15
|
+
removedDir: skill.dir,
|
|
16
|
+
settingsPatch: { skills: removeSkillSetting(settings, selectedName) },
|
|
17
|
+
message: `Removed skill ${selectedName}.`,
|
|
18
|
+
};
|
|
19
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export type SkillCreationResult = {
|
|
2
|
+
busy?: boolean;
|
|
3
|
+
busyLabel?: string;
|
|
4
|
+
message?: string;
|
|
5
|
+
description?: string;
|
|
6
|
+
draftName?: string;
|
|
7
|
+
mode?: 'chat';
|
|
8
|
+
clearDraft?: boolean;
|
|
9
|
+
};
|
|
10
|
+
export declare function captureSkillDescription(value: string, draftName: string | undefined): SkillCreationResult;
|
|
11
|
+
export declare function skillCreationMessage(name: string, file: string): string;
|
|
12
|
+
export declare function skillCreationFailure(error: unknown): string;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export function captureSkillDescription(value, draftName) {
|
|
2
|
+
const description = value.trim();
|
|
3
|
+
if (!description)
|
|
4
|
+
return { message: 'Description is required. Try again, or press ESC to cancel.' };
|
|
5
|
+
if (!draftName)
|
|
6
|
+
return { mode: 'chat', clearDraft: true, message: 'Skill wizard lost the name. Start over with /skills.' };
|
|
7
|
+
return { description, draftName, busy: true, busyLabel: 'Creating skill' };
|
|
8
|
+
}
|
|
9
|
+
export function skillCreationMessage(name, file) {
|
|
10
|
+
return `Created skill ${name} at ${file}. Invoke it with /${name}. Edit SKILL.md to refine its workflow.`;
|
|
11
|
+
}
|
|
12
|
+
export function skillCreationFailure(error) {
|
|
13
|
+
return `Skill creation failed: ${error instanceof Error ? error.message : String(error)}`;
|
|
14
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { HazeSettings } from '../../config/settings.js';
|
|
2
|
+
import type { LoadedSkill } from '../../skills/types.js';
|
|
3
|
+
export type SkillWizardResult = {
|
|
4
|
+
message?: string;
|
|
5
|
+
mode?: 'chat' | 'skills' | 'skillsAction' | 'skillsAddName' | 'skillsConfirmRemove';
|
|
6
|
+
selectedName?: string;
|
|
7
|
+
settingsPatch?: Partial<HazeSettings>;
|
|
8
|
+
clearDraft?: boolean;
|
|
9
|
+
};
|
|
10
|
+
export declare function selectSkillResult(skills: LoadedSkill[], name: string): SkillWizardResult;
|
|
11
|
+
export declare function skillInfoMessage(settings: HazeSettings, skill: LoadedSkill): string;
|
|
12
|
+
export declare function selectSkillActionResult(settings: HazeSettings, skills: LoadedSkill[], selectedName: string | undefined, action: string): SkillWizardResult & {
|
|
13
|
+
skill?: LoadedSkill;
|
|
14
|
+
validate?: boolean;
|
|
15
|
+
};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { isSkillEnabled, setSkillEnabled } from '../../config/skillSettings.js';
|
|
2
|
+
import { COMMON_ACTIONS, SKILL_ACTIONS, SKILL_CHOICES } from './wizardActions.js';
|
|
3
|
+
export function selectSkillResult(skills, name) {
|
|
4
|
+
if (name === SKILL_CHOICES.addSkill)
|
|
5
|
+
return { mode: 'skillsAddName', clearDraft: true, message: 'Name the skill (kebab-case, e.g. security-review). ESC cancels.' };
|
|
6
|
+
const skill = skills.find(candidate => candidate.name === name);
|
|
7
|
+
if (!skill)
|
|
8
|
+
return { mode: 'chat', message: `No skill named ${name}. Use /skills and choose add skill.` };
|
|
9
|
+
return { mode: 'skillsAction', selectedName: skill.name, message: `${skill.name}: choose an action.` };
|
|
10
|
+
}
|
|
11
|
+
export function skillInfoMessage(settings, skill) {
|
|
12
|
+
return [
|
|
13
|
+
`${skill.name}`,
|
|
14
|
+
skill.description,
|
|
15
|
+
'',
|
|
16
|
+
`References: ${skill.references.length}`,
|
|
17
|
+
`Path: ${skill.dir}`,
|
|
18
|
+
`State: ${isSkillEnabled(settings, skill.name) ? 'enabled' : 'disabled'}`,
|
|
19
|
+
].join('\n');
|
|
20
|
+
}
|
|
21
|
+
export function selectSkillActionResult(settings, skills, selectedName, action) {
|
|
22
|
+
if (!selectedName)
|
|
23
|
+
return { mode: 'skills' };
|
|
24
|
+
const skill = skills.find(candidate => candidate.name === selectedName);
|
|
25
|
+
if (!skill)
|
|
26
|
+
return { mode: 'chat', selectedName: undefined, message: `Skill ${selectedName} not found.` };
|
|
27
|
+
if (action === COMMON_ACTIONS.enable || action === COMMON_ACTIONS.disable) {
|
|
28
|
+
const enabled = action === COMMON_ACTIONS.enable;
|
|
29
|
+
return { mode: 'chat', selectedName: undefined, settingsPatch: { skills: setSkillEnabled(settings, selectedName, enabled) }, message: `Skill ${selectedName} ${enabled ? 'enabled' : 'disabled'}.`, skill };
|
|
30
|
+
}
|
|
31
|
+
if (action === SKILL_ACTIONS.showInfo)
|
|
32
|
+
return { message: skillInfoMessage(settings, skill), skill };
|
|
33
|
+
if (action === SKILL_ACTIONS.validate)
|
|
34
|
+
return { validate: true, skill };
|
|
35
|
+
if (action === SKILL_ACTIONS.removeSkill)
|
|
36
|
+
return { mode: 'skillsConfirmRemove', message: `Remove skill ${selectedName}? This deletes ~/.haze/skills/${selectedName}. Type "yes" to confirm. Esc to cancel.`, skill };
|
|
37
|
+
return { message: `Unknown skill action: ${action}`, skill };
|
|
38
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pure heuristics for gating and normalizing streamed assistant text.
|
|
3
|
+
*
|
|
4
|
+
* These decide when an assistant segment is "substantive" enough to show,
|
|
5
|
+
* whether a fragment is an unfinished markdown/bridge prefix that should stay
|
|
6
|
+
* hidden, and how to strip synthetic tool-call markup. None of them touch
|
|
7
|
+
* agent/callback state, which keeps them trivially unit-testable.
|
|
8
|
+
*/
|
|
9
|
+
export declare function sanitizeAssistantText(text: string): string;
|
|
10
|
+
export declare function isSubstantiveAssistantText(text: string): boolean;
|
|
11
|
+
export declare function isShortLeadInBeforeTool(text: string): boolean;
|
|
12
|
+
export declare function isShortUnfinishedLeadIn(text: string): boolean;
|
|
13
|
+
export declare function isHiddenAssistantFragment(text: string): boolean;
|
|
14
|
+
export declare function isHiddenUnstartedFinalText(text: string): boolean;
|
|
15
|
+
export declare function shouldStartAssistantStream(text: string, startedAt: number): boolean;
|
|
16
|
+
export declare function assistantDisplayText(text: string): string;
|
|
17
|
+
export declare function normalizeAssistantText(text: string): string;
|