@denizokcu/haze 0.5.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 +36 -1
- package/README.md +101 -24
- 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 +519 -495
- 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 +3 -2
- package/dist/cli/commands/commands.js +55 -320
- package/dist/cli/commands/formatters.d.ts +27 -0
- package/dist/cli/commands/formatters.js +149 -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 +10 -29
- package/dist/cli/commands/streaming.js +249 -911
- 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.d.ts +16 -0
- package/dist/config/lspSettings.js +95 -0
- package/dist/config/mcpSettings.d.ts +24 -0
- package/dist/config/mcpSettings.js +100 -0
- package/dist/config/providers.js +4 -4
- package/dist/config/settings.d.ts +34 -0
- package/dist/config/skillSettings.d.ts +15 -0
- package/dist/config/skillSettings.js +32 -0
- package/dist/config/updateCheck.d.ts +44 -0
- package/dist/config/updateCheck.js +83 -0
- 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 +109 -0
- package/dist/llm/lsp.js +241 -0
- package/dist/llm/lspTools.d.ts +104 -0
- package/dist/llm/lspTools.js +115 -0
- package/dist/llm/mcp.d.ts +19 -0
- package/dist/llm/mcp.js +73 -0
- package/dist/llm/requestContext.d.ts +28 -0
- package/dist/llm/requestContext.js +41 -0
- package/dist/llm/systemPrompt.d.ts +5 -1
- package/dist/llm/systemPrompt.js +9 -3
- 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 +24 -45
- package/dist/ui/components/TextInput.d.ts +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/dist/utils/version.d.ts +20 -0
- package/dist/utils/version.js +72 -0
- package/package.json +2 -2
- package/dist/cli/commands/skills.d.ts +0 -4
- package/dist/cli/commands/skills.js +0 -38
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export type Mode = 'chat' | 'provider' | 'providerAction' | 'model' | 'providerAddPreset' | 'providerAddName' | 'providerAddUrl' | 'providerAddKey' | 'providerAddModels' | 'providerAppendModels' | 'providerSetKey' | 'providerRemoveModels' | 'providerConfirmRemove' | 'skills' | 'skillsAction' | 'skillsAddName' | 'skillsAddDescription' | 'skillsConfirmRemove' | 'lsp' | 'lspAction' | 'lspAddPreset' | 'lspAddName' | 'lspAddCommand' | 'lspConfirmRemove' | 'mcp' | 'mcpAction' | 'mcpAddPreset' | 'mcpAddName' | 'mcpAddTransport' | 'mcpAddUrl' | 'mcpAddCommand' | 'mcpAddKey' | 'mcpSetKey' | 'mcpConfirmRemove';
|
|
2
|
+
/** Modes that show an always-on suggestion picker (server/preset lists). */
|
|
3
|
+
export declare const PICKER_MODES: ReadonlySet<Mode>;
|
|
4
|
+
/** Modes that mask input (secrets/API keys). */
|
|
5
|
+
export declare const MASKED_MODES: ReadonlySet<Mode>;
|
|
6
|
+
/** Modes where submitting an empty value is valid (optional steps). */
|
|
7
|
+
export declare const SUBMIT_EMPTY_MODES: ReadonlySet<Mode>;
|
|
8
|
+
export declare function placeholderForMode(mode: Mode, busy: boolean): string;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/** Modes that show an always-on suggestion picker (server/preset lists). */
|
|
2
|
+
export const PICKER_MODES = new Set(['provider', 'providerAction', 'providerAddPreset', 'model', 'skills', 'skillsAction', 'lsp', 'lspAction', 'lspAddPreset', 'mcp', 'mcpAction', 'mcpAddPreset', 'mcpAddTransport']);
|
|
3
|
+
/** Modes that mask input (secrets/API keys). */
|
|
4
|
+
export const MASKED_MODES = new Set(['providerAddKey', 'providerSetKey', 'mcpAddKey', 'mcpSetKey']);
|
|
5
|
+
/** Modes where submitting an empty value is valid (optional steps). */
|
|
6
|
+
export const SUBMIT_EMPTY_MODES = new Set(['providerAddKey', 'mcpAddKey']);
|
|
7
|
+
const PLACEHOLDERS = {
|
|
8
|
+
provider: 'Choose provider',
|
|
9
|
+
providerAction: 'Choose provider action',
|
|
10
|
+
providerAddPreset: 'Choose a provider preset or custom',
|
|
11
|
+
model: 'Choose model',
|
|
12
|
+
providerAddName: 'Provider name',
|
|
13
|
+
providerAddUrl: 'https://example.com/v1',
|
|
14
|
+
providerAddKey: 'API key, or blank for local',
|
|
15
|
+
providerSetKey: 'API key',
|
|
16
|
+
providerAddModels: 'model-a, model-b',
|
|
17
|
+
providerAppendModels: 'model-a, model-b',
|
|
18
|
+
providerRemoveModels: 'model-a, model-b',
|
|
19
|
+
providerConfirmRemove: 'Type "yes" to confirm',
|
|
20
|
+
skills: 'Choose a skill or add skill',
|
|
21
|
+
skillsAction: 'show info, enable, disable, validate, or remove',
|
|
22
|
+
skillsAddName: 'Skill name (kebab-case, e.g. security-review)',
|
|
23
|
+
skillsAddDescription: 'Describe what the skill should do',
|
|
24
|
+
skillsConfirmRemove: 'Type "yes" to confirm',
|
|
25
|
+
lsp: 'Choose LSP server or add server',
|
|
26
|
+
lspAction: 'enable, disable, or remove server',
|
|
27
|
+
lspAddPreset: 'Choose an LSP preset or custom',
|
|
28
|
+
lspAddName: 'LSP server name (e.g. typescript)',
|
|
29
|
+
lspAddCommand: 'Command (e.g. typescript-language-server --stdio)',
|
|
30
|
+
lspConfirmRemove: 'Type "yes" to confirm',
|
|
31
|
+
mcp: 'Choose MCP server or add server',
|
|
32
|
+
mcpAction: 'enable, disable, remove, or set key',
|
|
33
|
+
mcpAddPreset: 'Choose an MCP preset or custom',
|
|
34
|
+
mcpAddName: 'MCP server name (e.g. context7)',
|
|
35
|
+
mcpAddTransport: 'http, sse, or stdio',
|
|
36
|
+
mcpAddUrl: 'https://mcp.example.com/mcp',
|
|
37
|
+
mcpAddCommand: 'Command (e.g. npx -y @pkg/server)',
|
|
38
|
+
mcpAddKey: 'API key, or blank to skip',
|
|
39
|
+
mcpSetKey: 'API key',
|
|
40
|
+
mcpConfirmRemove: 'Type "yes" to confirm',
|
|
41
|
+
};
|
|
42
|
+
export function placeholderForMode(mode, busy) {
|
|
43
|
+
return PLACEHOLDERS[mode] ?? (busy ? 'Queue a follow-up, or Esc to interrupt' : 'Ask Haze to help build your app');
|
|
44
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export const COMMAND_HELP_ENTRIES = [
|
|
2
|
+
{ usage: '/help', description: 'Show all available slash commands and what they do.' },
|
|
3
|
+
{ usage: '/provider', description: 'Choose a provider, then use it, add/remove models, set API key, or remove it.' },
|
|
4
|
+
{ usage: '/model', description: 'Choose a model from all configured providers.' },
|
|
5
|
+
{ usage: '/model <name-or-provider:name>', description: 'Set a model directly. Selecting a model also sets its provider.' },
|
|
6
|
+
{ usage: '/settings', description: 'Show the configured provider, model, API key status, LSP/MCP servers, skills, and loaded context files.' },
|
|
7
|
+
{ usage: '/settings open', description: 'Open ~/.haze/settings.json with the OS default app.' },
|
|
8
|
+
{ usage: '/skills', description: 'Manage Markdown skills: generate a custom skill, show info, enable/disable, validate, or remove.' },
|
|
9
|
+
{ usage: '/init', description: 'Inspect the current workspace and create or update AGENTS.md project instructions.' },
|
|
10
|
+
{ usage: '/context', description: 'Show a token breakdown of the current request: system prompt, project context, tools (incl. MCP), and chat messages.' },
|
|
11
|
+
{ usage: '/session', description: 'Show the current durable session file.' },
|
|
12
|
+
{ usage: '/resume', description: 'Resume the latest saved session for this workspace.' },
|
|
13
|
+
{ usage: '/new', description: 'Start a fresh durable session.' },
|
|
14
|
+
{ usage: '/logs', description: 'List recent log files with sizes and dates.' },
|
|
15
|
+
{ usage: '/lsp', description: 'Configure Language Server Protocol navigation tools (interactive picker).' },
|
|
16
|
+
{ usage: '/mcp', description: 'Configure Model Context Protocol servers like Context7 (interactive picker).' },
|
|
17
|
+
{ usage: '/logs <id>', description: 'Show summary of a specific log: entry counts by type, total tokens, tool calls.' },
|
|
18
|
+
{ usage: '/compact [instructions]', description: 'Summarize older model context and keep recent messages.' },
|
|
19
|
+
{ usage: '/clear', description: 'Clear the current chat conversation history.' },
|
|
20
|
+
{ usage: '/exit', description: 'Exit Haze.' },
|
|
21
|
+
{ usage: '/quit', description: 'Exit Haze.' },
|
|
22
|
+
];
|
|
23
|
+
export function formatCommandHelp(entries = COMMAND_HELP_ENTRIES) {
|
|
24
|
+
return ['Commands:', ...entries.flatMap(entry => [entry.usage, ` ${entry.description}`])].join('\n');
|
|
25
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { ContextFile } from '../../config/contextFiles.js';
|
|
2
|
-
import type
|
|
3
|
-
import type { Mode } from './
|
|
2
|
+
import { type HazeSettings } from '../../config/settings.js';
|
|
3
|
+
import type { Mode } from './chatModes.js';
|
|
4
4
|
export type CommandContext = {
|
|
5
5
|
settings: HazeSettings;
|
|
6
6
|
contextFiles: ContextFile[];
|
|
@@ -15,6 +15,7 @@ export type CommandContext = {
|
|
|
15
15
|
runAgentTurn: (prompt: string, displayValue?: string) => Promise<void>;
|
|
16
16
|
refreshContextFiles: () => Promise<ContextFile[]>;
|
|
17
17
|
updateSettings: (patch: Partial<HazeSettings>) => Promise<HazeSettings>;
|
|
18
|
+
getContextReport?: () => Promise<string>;
|
|
18
19
|
};
|
|
19
20
|
export type CommandResult = 'handled' | 'unhandled' | 'exit';
|
|
20
21
|
export declare function handleSlashCommand(value: string, ctx: CommandContext): Promise<CommandResult>;
|
|
@@ -1,334 +1,69 @@
|
|
|
1
|
+
import { spawn } from 'node:child_process';
|
|
1
2
|
import fs from 'fs-extra';
|
|
2
|
-
import
|
|
3
|
-
import { buildInitPrompt } from '../../llm/initPrompt.js';
|
|
4
|
-
import { contextFileDiagnostics, summarizeContextDiagnostics, MAX_CONTEXT_FILE_CHARS } from '../../config/contextFiles.js';
|
|
5
|
-
import { activeProvider, configuredProviders, modelSelector, providerHasKey, resolveModelSelector, upsertProvider } from '../../config/providers.js';
|
|
3
|
+
import { SETTINGS_FILE, writeSettings } from '../../config/settings.js';
|
|
6
4
|
import { clearTasks } from '../../core/tasks/taskStorage.js';
|
|
7
|
-
import {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
' Validate a skill directory containing SKILL.md.',
|
|
17
|
-
'/remove-skill <name> --yes',
|
|
18
|
-
' Remove an installed skill. Requires --yes because it deletes files.',
|
|
19
|
-
].join('\n');
|
|
5
|
+
import { COMMAND_HELP_ENTRIES, formatCommandHelp } from './commandHelp.js';
|
|
6
|
+
import { handleInitCommand } from './initCommand.js';
|
|
7
|
+
import { handleLogsCommand } from './logsCommand.js';
|
|
8
|
+
import { handleModelCommand } from './modelCommand.js';
|
|
9
|
+
import { formatSettingsSummary } from './settingsSummary.js';
|
|
10
|
+
async function ensureSettingsFile(settings) {
|
|
11
|
+
if (!await fs.pathExists(SETTINGS_FILE))
|
|
12
|
+
await writeSettings(settings);
|
|
13
|
+
return SETTINGS_FILE;
|
|
20
14
|
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
const
|
|
25
|
-
const
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
15
|
+
function openPath(filePath) {
|
|
16
|
+
if (process.env.VITEST || process.env.NODE_ENV === 'test')
|
|
17
|
+
return;
|
|
18
|
+
const command = process.platform === 'darwin' ? 'open' : process.platform === 'win32' ? 'cmd' : 'xdg-open';
|
|
19
|
+
const args = process.platform === 'win32' ? ['/c', 'start', '', filePath] : [filePath];
|
|
20
|
+
const child = spawn(command, args, { stdio: 'ignore', detached: true });
|
|
21
|
+
child.on('error', () => undefined);
|
|
22
|
+
child.unref();
|
|
29
23
|
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
return 'handled';
|
|
34
|
-
}
|
|
35
|
-
if (sub === 'create') {
|
|
36
|
-
// Inline args are intentionally ignored — the wizard is the only path.
|
|
37
|
-
ctx.setMode('skillCreateName');
|
|
38
|
-
ctx.addSystemMessage('Skill wizard — step 1/3: Name the skill (kebab-case, e.g. security-review). ESC cancels.');
|
|
39
|
-
return 'handled';
|
|
40
|
-
}
|
|
41
|
-
if (sub === 'info') {
|
|
42
|
-
const name = args.trim();
|
|
43
|
-
if (!name) {
|
|
44
|
-
ctx.addSystemMessage('Usage: /skill-info <name>');
|
|
45
|
-
return 'handled';
|
|
46
|
-
}
|
|
47
|
-
const { loadSkillRegistry } = await import('../../skills/SkillRegistry.js');
|
|
48
|
-
const registry = await loadSkillRegistry();
|
|
49
|
-
const skill = registry.skills.get(name);
|
|
50
|
-
if (!skill) {
|
|
51
|
-
ctx.addSystemMessage(`No skill named ${name}`);
|
|
52
|
-
return 'handled';
|
|
53
|
-
}
|
|
54
|
-
ctx.addSystemMessage([
|
|
55
|
-
`${skill.name}`,
|
|
56
|
-
skill.description,
|
|
57
|
-
'',
|
|
58
|
-
`References: ${skill.references.length}`,
|
|
59
|
-
`Path: ${skill.dir}`,
|
|
60
|
-
].join('\n'));
|
|
61
|
-
return 'handled';
|
|
62
|
-
}
|
|
63
|
-
if (sub === 'validate') {
|
|
64
|
-
const target = args.trim();
|
|
65
|
-
if (!target) {
|
|
66
|
-
ctx.addSystemMessage('Usage: /validate-skill <name-or-dir>');
|
|
67
|
-
return 'handled';
|
|
68
|
-
}
|
|
69
|
-
const { GLOBAL_SKILLS_DIR } = await import('../../config/paths.js');
|
|
70
|
-
const { loadSkill } = await import('../../skills/SkillLoader.js');
|
|
71
|
-
const direct = path.resolve(target);
|
|
72
|
-
const dir = await fs.pathExists(path.join(direct, 'SKILL.md')) ? direct : path.join(GLOBAL_SKILLS_DIR, target);
|
|
73
|
-
const skill = await loadSkill(dir, 'global');
|
|
74
|
-
ctx.addSystemMessage(skill ? `Valid: ${skill.name}` : 'No SKILL.md found');
|
|
75
|
-
return 'handled';
|
|
76
|
-
}
|
|
77
|
-
if (sub === 'remove') {
|
|
78
|
-
const parts = args.split(/\s+/).filter(Boolean);
|
|
79
|
-
const name = parts[0];
|
|
80
|
-
if (!name || !parts.includes('--yes')) {
|
|
81
|
-
ctx.addSystemMessage('Usage: /remove-skill <name> --yes');
|
|
82
|
-
return 'handled';
|
|
83
|
-
}
|
|
84
|
-
const { loadSkillRegistry } = await import('../../skills/SkillRegistry.js');
|
|
85
|
-
const registry = await loadSkillRegistry();
|
|
86
|
-
const skill = registry.skills.get(name);
|
|
87
|
-
if (!skill) {
|
|
88
|
-
ctx.addSystemMessage(`No skill named ${name}`);
|
|
89
|
-
return 'handled';
|
|
90
|
-
}
|
|
91
|
-
await fs.remove(skill.dir);
|
|
92
|
-
ctx.addSystemMessage(`Removed ${name} from ${skill.dir}.`);
|
|
93
|
-
return 'handled';
|
|
94
|
-
}
|
|
95
|
-
return 'handled';
|
|
96
|
-
}
|
|
97
|
-
function formatBytes(bytes) {
|
|
98
|
-
if (bytes < 1024)
|
|
99
|
-
return `${bytes} B`;
|
|
100
|
-
if (bytes < 1024 * 1024)
|
|
101
|
-
return `${(bytes / 1024).toFixed(1)} KB`;
|
|
102
|
-
return `${(bytes / (1024 * 1024)).toFixed(1)} MB`;
|
|
24
|
+
const HANDLED = 'handled';
|
|
25
|
+
function exact(command) {
|
|
26
|
+
return value => value === command ? { args: '' } : false;
|
|
103
27
|
}
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
if (!id) {
|
|
107
|
-
// List recent logs
|
|
108
|
-
const logs = await listLogs();
|
|
109
|
-
if (logs.length === 0) {
|
|
110
|
-
ctx.addSystemMessage('No log files found.');
|
|
111
|
-
return 'handled';
|
|
112
|
-
}
|
|
113
|
-
const lines = logs.slice(0, 20).map(log => {
|
|
114
|
-
const date = log.modified.slice(0, 19).replace('T', ' ');
|
|
115
|
-
return ` ${log.id} ${formatBytes(log.size).padStart(8)} ${date}`;
|
|
116
|
-
});
|
|
117
|
-
ctx.addSystemMessage(['Recent logs:', ' ID Size Modified', ...lines].join('\n'));
|
|
118
|
-
return 'handled';
|
|
119
|
-
}
|
|
120
|
-
// Show summary for a specific log
|
|
121
|
-
const entries = await readLogEntries(id);
|
|
122
|
-
if (entries.length === 0) {
|
|
123
|
-
ctx.addSystemMessage(`No log found with id ${id}.`);
|
|
124
|
-
return 'handled';
|
|
125
|
-
}
|
|
126
|
-
const typeCounts = {};
|
|
127
|
-
let totalInput = 0;
|
|
128
|
-
let totalOutput = 0;
|
|
129
|
-
const toolCallCounts = {};
|
|
130
|
-
for (const entry of entries) {
|
|
131
|
-
typeCounts[entry.type] = (typeCounts[entry.type] ?? 0) + 1;
|
|
132
|
-
if (entry.usage) {
|
|
133
|
-
totalInput += entry.usage.inputTokens ?? 0;
|
|
134
|
-
totalOutput += entry.usage.outputTokens ?? 0;
|
|
135
|
-
}
|
|
136
|
-
if (entry.type === 'tool_call' && entry.toolCall) {
|
|
137
|
-
toolCallCounts[entry.toolCall.name] = (toolCallCounts[entry.toolCall.name] ?? 0) + 1;
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
const typeLines = Object.entries(typeCounts)
|
|
141
|
-
.sort(([a], [b]) => a.localeCompare(b))
|
|
142
|
-
.map(([type, count]) => ` ${type}: ${count}`);
|
|
143
|
-
const toolLines = Object.entries(toolCallCounts)
|
|
144
|
-
.sort(([, a], [, b]) => b - a)
|
|
145
|
-
.map(([name, count]) => ` ${name}: ${count}`);
|
|
146
|
-
const parts = [
|
|
147
|
-
`Log: ${id}`,
|
|
148
|
-
`Entries: ${entries.length}`,
|
|
149
|
-
'',
|
|
150
|
-
'Entry counts by type:',
|
|
151
|
-
...typeLines,
|
|
152
|
-
'',
|
|
153
|
-
`Total token usage: in=${totalInput} out=${totalOutput}`,
|
|
154
|
-
];
|
|
155
|
-
if (toolLines.length > 0) {
|
|
156
|
-
parts.push('', 'Tool call counts:', ...toolLines);
|
|
157
|
-
}
|
|
158
|
-
ctx.addSystemMessage(parts.join('\n'));
|
|
159
|
-
return 'handled';
|
|
28
|
+
function exactOrArgs(command) {
|
|
29
|
+
return value => value === command ? { args: '' } : value.startsWith(`${command} `) ? { args: value.slice(command.length).trim() } : false;
|
|
160
30
|
}
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
'/help',
|
|
168
|
-
' Show all available slash commands and what they do.',
|
|
169
|
-
'/provider',
|
|
170
|
-
' Choose a provider, then use it, add/remove models, set API key, or remove it.',
|
|
171
|
-
'/model',
|
|
172
|
-
' Choose a model from all configured providers.',
|
|
173
|
-
'/model <name-or-provider:name>',
|
|
174
|
-
' Set a model directly. Selecting a model also sets its provider.',
|
|
175
|
-
'/settings',
|
|
176
|
-
' Show the configured provider, model, API key status, and loaded context files.',
|
|
177
|
-
'/create-skill',
|
|
178
|
-
' Launch the 3-step skill wizard (name, role, description).',
|
|
179
|
-
'/skills',
|
|
180
|
-
' Show Markdown skill commands and installed skill slash commands.',
|
|
181
|
-
'/init',
|
|
182
|
-
' Inspect the current workspace and create or update AGENTS.md project instructions.',
|
|
183
|
-
'/session',
|
|
184
|
-
' Show the current durable session file.',
|
|
185
|
-
'/resume',
|
|
186
|
-
' Resume the latest saved session for this workspace.',
|
|
187
|
-
'/new',
|
|
188
|
-
' Start a fresh durable session.',
|
|
189
|
-
'/logs',
|
|
190
|
-
' List recent log files with sizes and dates.',
|
|
191
|
-
'/logs <id>',
|
|
192
|
-
' Show summary of a specific log: entry counts by type, total tokens, tool calls.',
|
|
193
|
-
'/compact [instructions]',
|
|
194
|
-
' Summarize older model context and keep recent messages.',
|
|
195
|
-
'/clear',
|
|
196
|
-
' Clear the current chat conversation history.',
|
|
197
|
-
'/exit',
|
|
198
|
-
' Exit Haze.',
|
|
199
|
-
'/quit',
|
|
200
|
-
' Exit Haze.',
|
|
201
|
-
].join('\n'));
|
|
202
|
-
return 'handled';
|
|
203
|
-
}
|
|
204
|
-
if (value === '/session') {
|
|
205
|
-
ctx.addSystemMessage(ctx.sessionInfo?.() ?? 'Session persistence is unavailable.');
|
|
206
|
-
return 'handled';
|
|
207
|
-
}
|
|
208
|
-
if (value === '/resume') {
|
|
209
|
-
if (ctx.resumeSession)
|
|
31
|
+
const SLASH_COMMANDS = [
|
|
32
|
+
{ match: value => value === '/exit' || value === '/quit' ? { args: '' } : false, run: () => 'exit' },
|
|
33
|
+
{ match: exact('/help'), run: (_args, ctx) => { ctx.addSystemMessage(formatCommandHelp(COMMAND_HELP_ENTRIES)); return HANDLED; } },
|
|
34
|
+
{ match: exact('/context'), run: async (_args, ctx) => { ctx.addSystemMessage(ctx.getContextReport ? await ctx.getContextReport() : 'Context overview is unavailable.'); return HANDLED; } },
|
|
35
|
+
{ match: exact('/session'), run: (_args, ctx) => { ctx.addSystemMessage(ctx.sessionInfo?.() ?? 'Session persistence is unavailable.'); return HANDLED; } },
|
|
36
|
+
{ match: exact('/resume'), run: async (_args, ctx) => { if (ctx.resumeSession)
|
|
210
37
|
await ctx.resumeSession();
|
|
211
38
|
else
|
|
212
|
-
ctx.addSystemMessage('Session persistence is unavailable.');
|
|
213
|
-
|
|
214
|
-
}
|
|
215
|
-
if (value === '/new') {
|
|
216
|
-
if (ctx.newSession)
|
|
39
|
+
ctx.addSystemMessage('Session persistence is unavailable.'); return HANDLED; } },
|
|
40
|
+
{ match: exact('/new'), run: async (_args, ctx) => { if (ctx.newSession)
|
|
217
41
|
await ctx.newSession();
|
|
218
42
|
else
|
|
219
|
-
ctx.addSystemMessage('Session persistence is unavailable.');
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
if (value === '/compact' || value.startsWith('/compact ')) {
|
|
223
|
-
if (ctx.compactConversation)
|
|
224
|
-
ctx.compactConversation(value.slice('/compact'.length).trim() || undefined);
|
|
43
|
+
ctx.addSystemMessage('Session persistence is unavailable.'); return HANDLED; } },
|
|
44
|
+
{ match: exactOrArgs('/compact'), run: (args, ctx) => { if (ctx.compactConversation)
|
|
45
|
+
ctx.compactConversation(args || undefined);
|
|
225
46
|
else
|
|
226
|
-
ctx.addSystemMessage('Compaction is unavailable.');
|
|
227
|
-
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
if (summary.exceedsBudget === true && summary.windowSize) {
|
|
247
|
-
const sharePct = Math.round((summary.budgetShare ?? 0) * 100);
|
|
248
|
-
const thresholdPct = Math.round(summary.budgetThreshold * 100);
|
|
249
|
-
notes.push(`project context exceeds ${thresholdPct}% budget (${sharePct}% of ${Math.round(summary.windowSize / 1000)}k window)`);
|
|
250
|
-
}
|
|
251
|
-
if (summary.duplicateGroups.length > 0) {
|
|
252
|
-
const duplicateTotal = summary.duplicateFileCount;
|
|
253
|
-
notes.push(`${summary.duplicateGroups.length} duplicate group${summary.duplicateGroups.length === 1 ? '' : 's'} (${duplicateTotal} file${duplicateTotal === 1 ? '' : 's'} with identical content)`);
|
|
254
|
-
}
|
|
255
|
-
const lines = [
|
|
256
|
-
`Provider: ${activeProvider?.name ?? 'not configured'}`,
|
|
257
|
-
`Model: ${ctx.settings.model ?? 'not set'}`,
|
|
258
|
-
`Base URL: ${activeProvider?.url ?? ctx.settings.baseURL ?? 'not configured'}`,
|
|
259
|
-
`API key: ${activeProvider && providerHasKey(ctx.settings, activeProvider) ? 'saved' : 'missing'}`,
|
|
260
|
-
`Configured providers: ${providers.map(provider => provider.name).join(', ') || 'none'}`,
|
|
261
|
-
`Context files: ${ctx.contextFiles.length ? `${ctx.contextFiles.map(file => file.path).join(', ')} (~${contextTokens} tokens)` : 'none'}`,
|
|
262
|
-
];
|
|
263
|
-
if (notes.length > 0)
|
|
264
|
-
lines.push(`Context note: ${notes.join('; ')}`);
|
|
265
|
-
ctx.addSystemMessage(lines.join(' | '));
|
|
266
|
-
return 'handled';
|
|
267
|
-
}
|
|
268
|
-
if (value === '/provider') {
|
|
269
|
-
ctx.setModelProviderFilter?.(undefined);
|
|
270
|
-
ctx.setMode('provider');
|
|
271
|
-
ctx.addSystemMessage('Choose a provider. Selecting one opens provider actions. Choose "add provider" to pick from presets or enter custom details.');
|
|
272
|
-
return 'handled';
|
|
273
|
-
}
|
|
274
|
-
if (value === '/model') {
|
|
275
|
-
ctx.setModelProviderFilter?.(undefined);
|
|
276
|
-
ctx.setMode('model');
|
|
277
|
-
ctx.addSystemMessage('Choose a model. Selecting a model also sets its provider.');
|
|
278
|
-
return 'handled';
|
|
279
|
-
}
|
|
280
|
-
if (value === '/model list') {
|
|
281
|
-
const providers = configuredProviders(ctx.settings);
|
|
282
|
-
ctx.addSystemMessage(['Configured models:', ...providers.flatMap(provider => provider.models.map(model => `- ${modelSelector(provider, model)} - ${provider.name}`))].join('\n'));
|
|
283
|
-
return 'handled';
|
|
284
|
-
}
|
|
285
|
-
if (value.startsWith('/model ')) {
|
|
286
|
-
const selector = value.slice('/model '.length).trim();
|
|
287
|
-
const resolved = resolveModelSelector(ctx.settings, selector);
|
|
288
|
-
if (resolved.status === 'ambiguous') {
|
|
289
|
-
ctx.addSystemMessage(`Model ${resolved.model} exists on multiple providers: ${resolved.providers.map(provider => modelSelector(provider, resolved.model)).join(', ')}`);
|
|
290
|
-
return 'handled';
|
|
291
|
-
}
|
|
292
|
-
if (resolved.status === 'missing') {
|
|
293
|
-
const provider = activeProvider(ctx.settings);
|
|
294
|
-
if (!provider) {
|
|
295
|
-
ctx.addSystemMessage('No provider configured. Run /provider to choose or add a provider before setting a model.');
|
|
296
|
-
return 'handled';
|
|
297
|
-
}
|
|
298
|
-
const nextProvider = provider.models.includes(selector) ? provider : { ...provider, models: [...provider.models, selector] };
|
|
299
|
-
await ctx.updateSettings({ provider: provider.name, model: selector, providers: upsertProvider(ctx.settings, nextProvider) });
|
|
300
|
-
ctx.addSystemMessage(`Model set to ${selector} on ${provider.name}. Saved to ~/.haze/settings.json.`);
|
|
301
|
-
return 'handled';
|
|
302
|
-
}
|
|
303
|
-
await ctx.updateSettings({ provider: resolved.provider.name, model: resolved.model });
|
|
304
|
-
ctx.addSystemMessage(`Model set to ${resolved.model} on ${resolved.provider.name}. Saved to ~/.haze/settings.json.`);
|
|
305
|
-
return 'handled';
|
|
306
|
-
}
|
|
307
|
-
if (value === '/init') {
|
|
308
|
-
await ctx.runAgentTurn(buildInitPrompt(), '/init');
|
|
309
|
-
await ctx.refreshContextFiles();
|
|
310
|
-
const agentsMdPath = path.join(process.cwd(), 'AGENTS.md');
|
|
311
|
-
if (await fs.pathExists(agentsMdPath)) {
|
|
312
|
-
const content = await fs.readFile(agentsMdPath, 'utf8');
|
|
313
|
-
const chars = content.length;
|
|
314
|
-
const lines = content.split('\n').length;
|
|
315
|
-
const msg = chars > MAX_CONTEXT_FILE_CHARS
|
|
316
|
-
? `AGENTS.md validation: ${chars.toLocaleString()} chars / ${lines} lines — exceeds the ${MAX_CONTEXT_FILE_CHARS.toLocaleString()}-char context budget and will be truncated. Trim it before relying on it.`
|
|
317
|
-
: `AGENTS.md validation: ${chars.toLocaleString()} chars / ${lines} lines — within the ${MAX_CONTEXT_FILE_CHARS.toLocaleString()}-char context budget.`;
|
|
318
|
-
ctx.addSystemMessage(msg);
|
|
319
|
-
}
|
|
320
|
-
return 'handled';
|
|
321
|
-
}
|
|
322
|
-
if (value === '/skills')
|
|
323
|
-
return await handleSkillCommand('help', '', ctx);
|
|
324
|
-
if (value === '/create-skill' || value.startsWith('/create-skill '))
|
|
325
|
-
return await handleSkillCommand('create', '', ctx);
|
|
326
|
-
if (value === '/skill-info' || value.startsWith('/skill-info '))
|
|
327
|
-
return await handleSkillCommand('info', value.slice('/skill-info '.length), ctx);
|
|
328
|
-
if (value === '/validate-skill' || value.startsWith('/validate-skill '))
|
|
329
|
-
return await handleSkillCommand('validate', value.slice('/validate-skill '.length), ctx);
|
|
330
|
-
if (value === '/remove-skill' || value.startsWith('/remove-skill '))
|
|
331
|
-
return await handleSkillCommand('remove', value.slice('/remove-skill '.length), ctx);
|
|
47
|
+
ctx.addSystemMessage('Compaction is unavailable.'); return HANDLED; } },
|
|
48
|
+
{ match: exact('/clear'), run: async (_args, ctx) => { ctx.clearConversation(); await clearTasks(); ctx.addSystemMessage('Cleared. The void is productive.'); return HANDLED; } },
|
|
49
|
+
{ match: exactOrArgs('/logs'), run: async (args, ctx) => await handleLogsCommand(args, ctx) },
|
|
50
|
+
{ match: exactOrArgs('/lsp'), run: (_args, ctx) => { ctx.setMode('lsp'); ctx.addSystemMessage('Choose an LSP server to enable, disable, or remove it. Choose "add server" to add one from presets (e.g. typescript) or enter a custom command.'); return HANDLED; } },
|
|
51
|
+
{ match: exactOrArgs('/mcp'), run: (_args, ctx) => { ctx.setMode('mcp'); ctx.addSystemMessage('Choose an MCP server to enable, disable, remove, or set a key for it. Choose "add server" to add one from presets (e.g. context7) or enter custom details.'); return HANDLED; } },
|
|
52
|
+
{ match: value => value === '/settings open' || value === '/settings edit' ? { args: '' } : false, run: async (_args, ctx) => { const file = await ensureSettingsFile(ctx.settings); openPath(file); ctx.addSystemMessage(`Opened settings file: ${file}`); return HANDLED; } },
|
|
53
|
+
{ match: exact('/settings'), run: async (_args, ctx) => { ctx.addSystemMessage(await formatSettingsSummary(ctx.settings, ctx.contextFiles)); return HANDLED; } },
|
|
54
|
+
{ match: exact('/provider'), run: (_args, ctx) => { ctx.setModelProviderFilter?.(undefined); ctx.setMode('provider'); ctx.addSystemMessage('Choose a provider. Selecting one opens provider actions. Choose "add provider" to pick from presets or enter custom details.'); return HANDLED; } },
|
|
55
|
+
{ match: exact('/init'), run: async (_args, ctx) => await handleInitCommand(ctx) },
|
|
56
|
+
{ match: exact('/skills'), run: (_args, ctx) => { ctx.setMode('skills'); ctx.addSystemMessage('Choose a skill to show info, enable/disable, or remove it. Choose "add skill" to generate a new one from a description.'); return HANDLED; } },
|
|
57
|
+
];
|
|
58
|
+
export async function handleSlashCommand(value, ctx) {
|
|
59
|
+
for (const command of SLASH_COMMANDS) {
|
|
60
|
+
const match = command.match(value);
|
|
61
|
+
if (match)
|
|
62
|
+
return await command.run(match.args, ctx);
|
|
63
|
+
}
|
|
64
|
+
const modelResult = await handleModelCommand(value, ctx);
|
|
65
|
+
if (modelResult)
|
|
66
|
+
return modelResult;
|
|
332
67
|
if (value.startsWith('/')) {
|
|
333
68
|
ctx.addSystemMessage(`Unknown command: ${value}. Bold start.`);
|
|
334
69
|
return 'handled';
|
|
@@ -9,3 +9,30 @@ export declare function formatSeconds(milliseconds: number): string;
|
|
|
9
9
|
export declare function formatElapsedTime(milliseconds: number): string;
|
|
10
10
|
export declare function formatElapsedTimeWhole(milliseconds: number): string;
|
|
11
11
|
export declare function toolOutputDetails(value: unknown): string;
|
|
12
|
+
export type ContextReportCategory = 'builtin' | 'lsp' | 'skill' | 'subagent' | 'mcp';
|
|
13
|
+
export interface ContextReportTool {
|
|
14
|
+
name: string;
|
|
15
|
+
tokens: number;
|
|
16
|
+
category: ContextReportCategory;
|
|
17
|
+
}
|
|
18
|
+
export interface ContextReportData {
|
|
19
|
+
modelLabel: string;
|
|
20
|
+
systemTokens: number;
|
|
21
|
+
projectContext: Array<{
|
|
22
|
+
path: string;
|
|
23
|
+
tokens: number;
|
|
24
|
+
}>;
|
|
25
|
+
tools: ContextReportTool[];
|
|
26
|
+
/** Full-message token totals by role (already includes tool call/result parts). */
|
|
27
|
+
messagesByRole: Record<string, number>;
|
|
28
|
+
/** Tool-result part tokens by tool name (subset of the messages total). */
|
|
29
|
+
toolResults: Record<string, number>;
|
|
30
|
+
/** Tool-call input part tokens by tool name (subset of the messages total). */
|
|
31
|
+
toolInputs: Record<string, number>;
|
|
32
|
+
syntheticControl: number;
|
|
33
|
+
logicalInputEstimate: number;
|
|
34
|
+
messageCount: number;
|
|
35
|
+
mcpErrors: string[];
|
|
36
|
+
}
|
|
37
|
+
/** Render a detailed, /context-style token breakdown. Pure for testability. */
|
|
38
|
+
export declare function formatContextReport(data: ContextReportData): string;
|