@denizokcu/haze 1.5.0 → 1.6.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 +23 -0
- package/README.md +74 -5
- package/SECURITY.md +1 -1
- package/dist/buildInfo.json +3 -3
- package/dist/cli/chat/DynamicFrame.d.ts +0 -13
- package/dist/cli/chat/DynamicFrame.js +7 -2
- package/dist/cli/chat/inputSuggestions.js +2 -0
- package/dist/cli/chat/resizeGuard.d.ts +20 -0
- package/dist/cli/chat/resizeGuard.js +25 -0
- package/dist/cli/chat/terminalControl.d.ts +4 -2
- package/dist/cli/chat/terminalControl.js +16 -5
- package/dist/cli/chat/wizard/pluginHandlers.d.ts +10 -0
- package/dist/cli/chat/wizard/pluginHandlers.js +156 -0
- package/dist/cli/chat/wizard/skillsHandlers.js +2 -2
- package/dist/cli/chat/wizard/types.d.ts +20 -0
- package/dist/cli/chat/wizard/uiState.d.ts +25 -1
- package/dist/cli/chat/wizard/uiState.js +3 -1
- package/dist/cli/chat/wizardDispatch.js +6 -0
- package/dist/cli/commands/chat.js +27 -5
- package/dist/cli/commands/commandHelp.js +7 -2
- package/dist/cli/commands/commands.d.ts +5 -0
- package/dist/cli/commands/commands.js +17 -3
- package/dist/cli/commands/initCommand.js +3 -2
- package/dist/cli/commands/pluginCommand.d.ts +16 -0
- package/dist/cli/commands/pluginCommand.js +127 -0
- package/dist/cli/commands/reasoningCommand.d.ts +0 -15
- package/dist/cli/commands/reasoningCommand.js +1 -3
- package/dist/cli/commands/skillsWizard.js +4 -0
- package/dist/cli/commands/streaming/agentAttempt.js +2 -1
- package/dist/cli/commands/streaming/attemptOutcome.d.ts +2 -0
- package/dist/cli/commands/streaming/attemptOutcome.js +4 -3
- package/dist/cli/commands/streaming/attemptSetup.d.ts +2 -0
- package/dist/cli/commands/streaming/attemptSetup.js +3 -2
- package/dist/cli/commands/streaming/stallRecovery.d.ts +6 -0
- package/dist/cli/commands/streaming/stallRecovery.js +6 -5
- package/dist/cli/commands/streaming/turnRuntime.js +2 -4
- package/dist/cli/commands/wizardFlow.d.ts +59 -0
- package/dist/cli/commands/wizardFlow.js +40 -0
- package/dist/cli/contextReportCli.js +4 -3
- package/dist/cli/index.js +19 -2
- package/dist/config/contextFiles.js +3 -2
- package/dist/config/inputHistory.js +3 -3
- package/dist/config/paths.d.ts +1 -0
- package/dist/config/paths.js +1 -0
- package/dist/config/providerAuth.js +3 -3
- package/dist/config/settings.d.ts +14 -2
- package/dist/config/settings.js +8 -4
- package/dist/config/updateCheck.js +3 -3
- package/dist/core/agent/budgets.d.ts +17 -0
- package/dist/core/agent/budgets.js +19 -0
- package/dist/core/agent/reasoningPolicy.js +1 -1
- package/dist/core/agent/workState.d.ts +0 -2
- package/dist/core/agent/workState.js +1 -1
- package/dist/core/log/llmLog.js +1 -1
- package/dist/core/providerContracts.d.ts +6 -3
- package/dist/core/session/sessionStore.js +4 -3
- package/dist/core/subagent/contracts.d.ts +1 -11
- package/dist/core/subagent/contracts.js +0 -22
- package/dist/llm/client.js +28 -7
- package/dist/llm/subagentRunner.d.ts +1 -6
- package/dist/llm/subagentRunner.js +11 -23
- package/dist/llm/tools/fileTools.js +2 -3
- package/dist/llm/tools/gitIgnore.js +1 -1
- package/dist/llm/tools/grepRunner.d.ts +10 -0
- package/dist/llm/tools/grepRunner.js +24 -0
- package/dist/llm/tools/toolContext.d.ts +2 -3
- package/dist/llm/tools/toolContext.js +2 -3
- package/dist/llm/tools/toolContextState.d.ts +0 -1
- package/dist/llm/tools/toolContextState.js +1 -4
- package/dist/llm/workerContext.d.ts +0 -7
- package/dist/llm/workerContext.js +0 -17
- package/dist/skills/SkillLoader.js +3 -2
- package/dist/skills/SkillRegistry.js +7 -4
- package/dist/skills/builder/SkillBuilder.js +11 -10
- package/dist/skills/plugins/installer.d.ts +25 -0
- package/dist/skills/plugins/installer.js +272 -0
- package/dist/skills/plugins/package.d.ts +41 -0
- package/dist/skills/plugins/package.js +275 -0
- package/dist/skills/plugins/runtime.d.ts +3 -0
- package/dist/skills/plugins/runtime.js +108 -0
- package/dist/skills/skillTools.js +10 -5
- package/dist/skills/types.d.ts +4 -0
- package/dist/ui/codeHighlight.d.ts +1 -1
- package/dist/ui/codeHighlight.js +112 -4
- package/dist/ui/components/StreamingMarkdownText.d.ts +0 -2
- package/dist/ui/components/StreamingMarkdownText.js +1 -1
- package/dist/ui/components/TextInput.d.ts +1 -1
- package/dist/utils/fs.d.ts +10 -0
- package/dist/utils/fs.js +37 -2
- package/package.json +17 -20
|
@@ -4,6 +4,7 @@ import { createProviderWizardHandlers } from './wizard/providerHandlers.js';
|
|
|
4
4
|
import { createSkillsWizardHandlers } from './wizard/skillsHandlers.js';
|
|
5
5
|
import { createLspWizardHandlers } from './wizard/lspHandlers.js';
|
|
6
6
|
import { createMcpWizardHandlers } from './wizard/mcpHandlers.js';
|
|
7
|
+
import { createPluginWizardHandlers } from './wizard/pluginHandlers.js';
|
|
7
8
|
import { createSessionThemeHandlers } from './wizard/sessionThemeHandlers.js';
|
|
8
9
|
export { initialWizardUiState, wizardUiReducer } from './wizard/uiState.js';
|
|
9
10
|
export { transitionMcpField, transitionProviderField } from './wizard/fieldTransitions.js';
|
|
@@ -30,6 +31,10 @@ export function createWizardDispatch(deps) {
|
|
|
30
31
|
setLspDraft: value => deps.updateWizard({ type: 'lspDraft', value }),
|
|
31
32
|
setSelectedMcpName: value => deps.updateWizard({ type: 'set', key: 'selectedMcpName', value }),
|
|
32
33
|
setMcpDraft: value => deps.updateWizard({ type: 'mcpDraft', value }),
|
|
34
|
+
setSelectedPluginName: value => deps.updateWizard({ type: 'set', key: 'selectedPluginName', value }),
|
|
35
|
+
setPluginSourceDir: value => deps.updateWizard({ type: 'set', key: 'pluginSourceDir', value }),
|
|
36
|
+
setPlugins: value => deps.updateWizard({ type: 'plugins', value }),
|
|
37
|
+
setPluginCollectionEntries: value => deps.updateWizard({ type: 'pluginCollectionEntries', value }),
|
|
33
38
|
setDiscoveredModels: value => deps.updateWizard({ type: 'discoveredModels', value }),
|
|
34
39
|
setSuggestedModels: value => deps.updateWizard({ type: 'suggestedModels', value }),
|
|
35
40
|
};
|
|
@@ -41,6 +46,7 @@ export function createWizardDispatch(deps) {
|
|
|
41
46
|
...provider.handlers,
|
|
42
47
|
...createLspWizardHandlers(deps, ctx),
|
|
43
48
|
...mcp.handlers,
|
|
49
|
+
...createPluginWizardHandlers(deps, ctx),
|
|
44
50
|
};
|
|
45
51
|
/** Apply one field-transition effect at the submit boundary (was chat.tsx inline branching). */
|
|
46
52
|
async function applyProviderEffect(effect) {
|
|
@@ -22,6 +22,7 @@ import { formatSession, listSessions } from '../../core/session/sessionStore.js'
|
|
|
22
22
|
import { MAX_VISIBLE_TASKS, TaskBar } from '../chat/TaskBar.js';
|
|
23
23
|
import { DynamicFrame } from '../chat/DynamicFrame.js';
|
|
24
24
|
import { createChatShutdown, runTerminalSession } from '../chat/shutdown.js';
|
|
25
|
+
import { installViewportResizeGuard } from '../chat/resizeGuard.js';
|
|
25
26
|
import { createQuarantinableCallbacks } from './streaming/attemptLifecycle.js';
|
|
26
27
|
import { AssistantMarkdownChunkView, MessageView } from '../chat/messages.js';
|
|
27
28
|
import { partitionDisplayMessages } from '../chat/transcriptPartition.js';
|
|
@@ -47,6 +48,7 @@ import { modelThinkingLabel } from '../../utils/modelName.js';
|
|
|
47
48
|
import { commandParts } from './wizardFlow.js';
|
|
48
49
|
import { backgroundProcessCount, subscribeBackgroundProcesses, teardownBackgroundProcesses } from '../../core/process/backgroundRegistry.js';
|
|
49
50
|
import { MAX_SESSION_PICKER_RESULTS } from './sessionPicker.js';
|
|
51
|
+
import { listInstalledPlugins } from './pluginCommand.js';
|
|
50
52
|
/** Latest Ink render metrics under --debug (module-level: render options are outside React). */
|
|
51
53
|
let renderMetricsReader;
|
|
52
54
|
function thinkingLabelForSettings(settings) {
|
|
@@ -181,7 +183,7 @@ function ChatScreen({ debug = false, version, build, continueSession = false, re
|
|
|
181
183
|
// Wizard flow state (selection, drafts, model discovery) in one reducer;
|
|
182
184
|
// this replaced twelve individual useState hooks.
|
|
183
185
|
const [wizardState, updateWizard] = useReducer(wizardUiReducer, undefined, initialWizardUiState);
|
|
184
|
-
const { modelProviderFilter, discoveredModels, suggestedModels, selectedProviderName, providerDraft, selectedSkillName, selectedLspName, selectedMcpName } = wizardState;
|
|
186
|
+
const { modelProviderFilter, discoveredModels, suggestedModels, selectedProviderName, providerDraft, selectedSkillName, selectedLspName, selectedMcpName, plugins, selectedPluginName, pluginCollectionEntries } = wizardState;
|
|
185
187
|
useEffect(() => subscribeBackgroundProcesses(() => setBackgroundCount(backgroundProcessCount())), []);
|
|
186
188
|
// One tip per thinking section, shown under the busy label while the model
|
|
187
189
|
// is purely thinking (no tool running) and the user has not disabled tips.
|
|
@@ -340,6 +342,17 @@ function ChatScreen({ debug = false, version, build, continueSession = false, re
|
|
|
340
342
|
const hidden = Math.max(0, next.length - MAX_SESSION_PICKER_RESULTS);
|
|
341
343
|
setMessages(m => [...m, { role: 'system', text: `Choose a saved session (newest first)${hidden ? `. Showing ${MAX_SESSION_PICKER_RESULTS} of ${next.length}; ${hidden} older sessions are hidden.` : '.'}` }]);
|
|
342
344
|
}
|
|
345
|
+
async function openPluginPicker() {
|
|
346
|
+
try {
|
|
347
|
+
updateWizard({ type: 'plugins', value: await listInstalledPlugins() });
|
|
348
|
+
}
|
|
349
|
+
catch (error) {
|
|
350
|
+
setMessages(m => [...m, { role: 'system', text: `Could not list installed plugins: ${error instanceof Error ? error.message : String(error)}` }]);
|
|
351
|
+
return;
|
|
352
|
+
}
|
|
353
|
+
setMode('plugins');
|
|
354
|
+
setMessages(m => [...m, { role: 'system', text: 'Choose install plugin, inspect plugin, or an installed plugin to manage. Only skills activate; no scripts, hooks, or MCP servers run.' }]);
|
|
355
|
+
}
|
|
343
356
|
function cancelThinking() {
|
|
344
357
|
if (!busy)
|
|
345
358
|
return;
|
|
@@ -404,7 +417,7 @@ function ChatScreen({ debug = false, version, build, continueSession = false, re
|
|
|
404
417
|
const message = error instanceof Error ? error.message : String(error);
|
|
405
418
|
setSettingsError(message);
|
|
406
419
|
if (!/^\/(?:settings\s+(?:open|edit)|help|exit|quit)\b/i.test(value.trim())) {
|
|
407
|
-
setMessages(messages => [...messages, { role: 'system', text: `${message}\nRepair settings, then retry. /settings open, /help, and /exit remain available.` }]);
|
|
420
|
+
setMessages(messages => [...messages, { role: 'system', text: `${message}\nRepair settings, then retry. /settings edit (or /settings open), /help, and /exit remain available.` }]);
|
|
408
421
|
return;
|
|
409
422
|
}
|
|
410
423
|
}
|
|
@@ -460,6 +473,9 @@ function ChatScreen({ debug = false, version, build, continueSession = false, re
|
|
|
460
473
|
return text;
|
|
461
474
|
},
|
|
462
475
|
viewInPager: terminalControl.viewInPager,
|
|
476
|
+
editFileInEditor: terminalControl.editFileInEditor,
|
|
477
|
+
refreshSkills,
|
|
478
|
+
openPluginPicker,
|
|
463
479
|
refreshContextFiles: async () => {
|
|
464
480
|
const files = await readContextFiles().catch(() => contextFiles);
|
|
465
481
|
setContextFiles(files);
|
|
@@ -687,7 +703,7 @@ function ChatScreen({ debug = false, version, build, continueSession = false, re
|
|
|
687
703
|
const workspaceLabel = `${compactHomePath(process.cwd())}${branchName ? ` (${branchName})` : ''}`;
|
|
688
704
|
const enabledSkillCount = new Set(skills.filter(skill => isSkillEnabled(settings, skill.name, skill.source)).map(skill => skill.name)).size;
|
|
689
705
|
const metrics = statusBarMetrics({ messages: [...messages, ...liveMessages], tokenUsage, enabledSkillCount, backgroundProcessCount: backgroundCount });
|
|
690
|
-
const inputSuggestions = inputSuggestionsForState({ mode, settings, skills, sessions, selectedProviderName, modelProviderFilter, providerDraftName: providerDraft.name, discoveredModels, suggestedModels, selectedSkillName, selectedLspName, selectedMcpName, sessionReasoning });
|
|
706
|
+
const inputSuggestions = inputSuggestionsForState({ mode, settings, skills, sessions, selectedProviderName, modelProviderFilter, providerDraftName: providerDraft.name, discoveredModels, suggestedModels, selectedSkillName, selectedLspName, selectedMcpName, plugins, selectedPluginName, pluginCollectionEntries, sessionReasoning });
|
|
691
707
|
const staticItems = [
|
|
692
708
|
{ kind: 'header', key: 'header', subtitle: headerSubtitle },
|
|
693
709
|
...staticTranscriptItems,
|
|
@@ -698,7 +714,7 @@ function ChatScreen({ debug = false, version, build, continueSession = false, re
|
|
|
698
714
|
? _jsx(Header, { subtitle: item.subtitle, version: version }, item.key)
|
|
699
715
|
: item.kind === 'assistant-markdown'
|
|
700
716
|
? _jsx(AssistantMarkdownChunkView, { message: item.message, content: item.content, width: contentWidth, first: item.first, final: item.final }, item.key)
|
|
701
|
-
: _jsx(MessageView, { message: item.message, width: contentWidth }, item.key) }), _jsx(DynamicFrame, { rows: terminalRows, columns: contentWidth, sections: {
|
|
717
|
+
: _jsx(MessageView, { message: item.message, width: contentWidth }, item.key) }, width), _jsx(DynamicFrame, { rows: terminalRows, columns: contentWidth, sections: {
|
|
702
718
|
live: streamingItems.length > 0 ? rows => {
|
|
703
719
|
// Allocate the sum, not a positive minimum for every pending item.
|
|
704
720
|
const displayed = streamingItems.slice(0, Math.floor(rows / 2));
|
|
@@ -753,6 +769,9 @@ export async function chatCommand(options = {}) {
|
|
|
753
769
|
// a getter so the metric never enters React state (no extra re-renders).
|
|
754
770
|
let lastRenderMetricsMs;
|
|
755
771
|
renderMetricsReader = () => lastRenderMetricsMs;
|
|
772
|
+
// Clear on width changes ahead of Ink's repaint; ChatScreen then replays
|
|
773
|
+
// its width-keyed Static transcript instead of leaving a blank viewport.
|
|
774
|
+
const removeResizeGuard = installViewportResizeGuard();
|
|
756
775
|
await runTerminalSession({
|
|
757
776
|
adopt: () => {
|
|
758
777
|
if (!process.stdout.isTTY)
|
|
@@ -773,6 +792,9 @@ export async function chatCommand(options = {}) {
|
|
|
773
792
|
} } : {}),
|
|
774
793
|
}),
|
|
775
794
|
shutdown: () => shutdown?.(),
|
|
776
|
-
restore:
|
|
795
|
+
restore: () => {
|
|
796
|
+
removeResizeGuard();
|
|
797
|
+
resetTerminalColors();
|
|
798
|
+
},
|
|
777
799
|
});
|
|
778
800
|
}
|
|
@@ -3,15 +3,20 @@ export const COMMAND_HELP_ENTRIES = [
|
|
|
3
3
|
{ usage: '/provider', description: 'Choose a provider, then use it, add/remove models, set API key, toggle image input, or remove it.' },
|
|
4
4
|
{ usage: '/model', description: 'Choose a model, or add models from a provider\'s models endpoint.' },
|
|
5
5
|
{ usage: '/model <name-or-provider:name>', description: 'Set a model directly. Selecting a model also sets its provider.' },
|
|
6
|
+
{ usage: '/model list', description: 'List all configured models across providers.' },
|
|
6
7
|
{ usage: '/settings', description: 'Show the configured provider, model, API key status, LSP/MCP servers, skills, and loaded context files.' },
|
|
7
8
|
{ usage: '/settings open', description: 'Open ~/.haze/settings.json with the OS default app.' },
|
|
9
|
+
{ usage: '/settings edit', description: 'Open ~/.haze/settings.json in $VISUAL/$EDITOR in a fullscreen terminal handoff; falls back to the OS default app when no editor is configured. Restart haze to apply external changes.' },
|
|
8
10
|
{ usage: '/themes', description: 'Choose a terminal theme from the built-in registry (light palettes and oh-my-zsh ports included); applies immediately.' },
|
|
9
11
|
{ usage: '/themes <name>', description: 'Set the theme directly, e.g. /themes robbyrussell. Saved to ~/.haze/settings.json; text already on screen keeps its old colors.' },
|
|
10
12
|
{ usage: '/reasoning', description: 'Choose a reasoning effort level (none, minimal, low, medium, high, xhigh) for the active model, for this session; unset sends no parameter, reset falls back to the saved/default level.' },
|
|
11
|
-
{ usage: '/reasoning <level|unset|reset|status>', description: 'Set the reasoning effort for the active model for this session, send no parameter with unset, remove the override with reset, or show the current level with status.
|
|
13
|
+
{ usage: '/reasoning <level|unset|reset|status>', description: 'Set the reasoning effort for the active model for this session, send no parameter with unset, remove the override with reset, or show the current level with status. Low is the default. Endpoints without native support ignore the parameter.' },
|
|
12
14
|
{ usage: '/thinking', description: 'Alias for /reasoning. Choose a reasoning effort level (none, minimal, low, medium, high, xhigh) for the active model, for this session; unset sends no parameter, reset falls back to the saved/default level.' },
|
|
13
|
-
{ usage: '/thinking <level|unset|reset|status>', description: 'Alias for /reasoning. Set the reasoning effort for the active model for this session, send no parameter with unset, remove the override with reset, or show the current level with status.
|
|
15
|
+
{ usage: '/thinking <level|unset|reset|status>', description: 'Alias for /reasoning. Set the reasoning effort for the active model for this session, send no parameter with unset, remove the override with reset, or show the current level with status. Low is the default. Endpoints without native support ignore the parameter.' },
|
|
14
16
|
{ usage: '/skills', description: 'Manage Markdown skills: generate a custom skill, show info, enable/disable, validate, or remove.' },
|
|
17
|
+
{ usage: '/plugin', description: 'Open the plugin picker: install or inspect a local plugin/collection, or manage installed project plugins. /kit is an alias.' },
|
|
18
|
+
{ usage: '/plugin inspect|install <local-directory> [plugin-name]', description: 'Inspect or install a Claude/Agent Plugins package or a selected local marketplace plugin. Only skills are activated; review source first.' },
|
|
19
|
+
{ usage: '/plugin list|remove <name>', description: 'List project-installed plugins or remove one, preserving modified and seed files. /kit is an alias.' },
|
|
15
20
|
{ usage: '/tips', description: 'Toggle the rotating tips shown under the busy label while the model is thinking.' },
|
|
16
21
|
{ usage: '/fleet [--review] [--profile <name>] [--workers <provider:model>] [--concurrency <n>] [--] <prompt>', description: 'Run genuinely independent tasks through disposable contexts. Runtime enforces profile concurrency, deadlines, and mutation serialization; control guidance is not persisted. Declines non-parallel work.' },
|
|
17
22
|
{ usage: '/init', description: 'Inspect the current workspace and create or update AGENTS.md project instructions.' },
|
|
@@ -19,8 +19,13 @@ export type CommandContext = {
|
|
|
19
19
|
runAgentTurn: (prompt: string, displayValue?: string, options?: TurnExecutionOptions) => Promise<void>;
|
|
20
20
|
/** Ink 8 `suspendTerminal` affordances; provided by the interactive screen only. */
|
|
21
21
|
composeInEditor?: () => Promise<string | undefined>;
|
|
22
|
+
/** Open an existing file in $VISUAL/$EDITOR; false when no editor is configured. */
|
|
23
|
+
editFileInEditor?: (file: string) => Promise<boolean>;
|
|
22
24
|
viewInPager?: (text: string) => Promise<boolean>;
|
|
23
25
|
refreshContextFiles: () => Promise<ContextFile[]>;
|
|
26
|
+
refreshSkills?: () => Promise<unknown>;
|
|
27
|
+
/** Open the `/plugin` picker (interactive screen only; loads installed plugins first). */
|
|
28
|
+
openPluginPicker?: () => Promise<void>;
|
|
24
29
|
updateSettings: (patch: Partial<HazeSettings>) => Promise<HazeSettings>;
|
|
25
30
|
/** Read the session-scoped per-model reasoning override (`provider:model` key). */
|
|
26
31
|
getSessionReasoning: (modelSelector: string) => StoredReasoningSetting | undefined;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { pathExists } from '../../utils/fs.js';
|
|
2
2
|
import { SETTINGS_FILE, writeSettings } from '../../config/settings.js';
|
|
3
3
|
import { openPath } from '../../utils/openPath.js';
|
|
4
4
|
import { clearTasks } from '../../core/tasks/taskStorage.js';
|
|
@@ -9,9 +9,10 @@ import { handleLogsCommand } from './logsCommand.js';
|
|
|
9
9
|
import { handleModelCommand } from './modelCommand.js';
|
|
10
10
|
import { handleReasoningCommand } from './reasoningCommand.js';
|
|
11
11
|
import { handleThemesCommand } from './themesCommand.js';
|
|
12
|
+
import { handlePluginCommand } from './pluginCommand.js';
|
|
12
13
|
import { formatSettingsSummary } from './settingsSummary.js';
|
|
13
14
|
async function ensureSettingsFile(settings) {
|
|
14
|
-
if (!await
|
|
15
|
+
if (!await pathExists(SETTINGS_FILE))
|
|
15
16
|
await writeSettings(settings);
|
|
16
17
|
return SETTINGS_FILE;
|
|
17
18
|
}
|
|
@@ -58,10 +59,23 @@ const SLASH_COMMANDS = [
|
|
|
58
59
|
} },
|
|
59
60
|
{ 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; } },
|
|
60
61
|
{ 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; } },
|
|
61
|
-
{ match:
|
|
62
|
+
{ match: exact('/settings open'), run: async (_args, ctx) => { const file = await ensureSettingsFile(ctx.settings); await openPath(file); ctx.addSystemMessage(`Opened settings file: ${file}`); return HANDLED; } },
|
|
63
|
+
{ match: exact('/settings edit'), run: async (_args, ctx) => {
|
|
64
|
+
const file = await ensureSettingsFile(ctx.settings);
|
|
65
|
+
if (ctx.editFileInEditor && await ctx.editFileInEditor(file)) {
|
|
66
|
+
// External edits are not hot-reloaded; in-memory settings stay authoritative for this session.
|
|
67
|
+
ctx.addSystemMessage(`Edited settings file: ${file}. Restart haze to apply changes.`);
|
|
68
|
+
return HANDLED;
|
|
69
|
+
}
|
|
70
|
+
await openPath(file);
|
|
71
|
+
ctx.addSystemMessage(`${ctx.editFileInEditor ? 'No $VISUAL/$EDITOR configured' : 'Editor handoff unavailable'}; opened settings file with the OS default app: ${file}`);
|
|
72
|
+
return HANDLED;
|
|
73
|
+
} },
|
|
62
74
|
{ match: exact('/settings'), run: async (_args, ctx) => { ctx.addSystemMessage(await formatSettingsSummary(ctx.settings, ctx.contextFiles)); return HANDLED; } },
|
|
63
75
|
{ 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; } },
|
|
64
76
|
{ match: exact('/init'), run: async (_args, ctx) => await handleInitCommand(ctx) },
|
|
77
|
+
{ match: exactOrArgs('/plugin'), run: handlePluginCommand },
|
|
78
|
+
{ match: exactOrArgs('/kit'), run: handlePluginCommand },
|
|
65
79
|
{ 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; } },
|
|
66
80
|
{ match: exact('/tips'), run: async (_args, ctx) => {
|
|
67
81
|
const currentlyEnabled = ctx.settings.tips?.enabled !== false;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import fs from 'fs
|
|
1
|
+
import fs from 'node:fs/promises';
|
|
2
|
+
import { pathExists } from '../../utils/fs.js';
|
|
2
3
|
import path from 'node:path';
|
|
3
4
|
import { MAX_CONTEXT_FILE_CHARS } from '../../config/contextFiles.js';
|
|
4
5
|
import { buildInitPrompt } from '../../llm/initPrompt.js';
|
|
@@ -6,7 +7,7 @@ export async function handleInitCommand(ctx) {
|
|
|
6
7
|
await ctx.runAgentTurn(buildInitPrompt(), '/init');
|
|
7
8
|
await ctx.refreshContextFiles();
|
|
8
9
|
const agentsMdPath = path.join(process.cwd(), 'AGENTS.md');
|
|
9
|
-
if (await
|
|
10
|
+
if (await pathExists(agentsMdPath)) {
|
|
10
11
|
const content = await fs.readFile(agentsMdPath, 'utf8');
|
|
11
12
|
const chars = content.length;
|
|
12
13
|
const lines = content.split('\n').length;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { CommandContext, CommandResult } from './commands.js';
|
|
2
|
+
/** Installed plugins for the `/plugin` picker (receipt-listed, global ~/.haze). */
|
|
3
|
+
export declare function listInstalledPlugins(): Promise<{
|
|
4
|
+
name: string;
|
|
5
|
+
version?: string;
|
|
6
|
+
}[]>;
|
|
7
|
+
/** Collection entries from a local marketplace root; throws when the directory is not a collection (root plugin manifests keep precedence). */
|
|
8
|
+
export declare function pluginCollectionEntries(source: string): Promise<{
|
|
9
|
+
name: string;
|
|
10
|
+
description?: string;
|
|
11
|
+
}[]>;
|
|
12
|
+
/** cwd is kept for source-path resolution symmetry with other commands; installs are global. */
|
|
13
|
+
export declare function runPluginCommand(args: string[], _cwd?: string): Promise<string>;
|
|
14
|
+
/** Quoted local paths work in chat too; this is argument parsing, not shell execution. */
|
|
15
|
+
export declare function pluginCommandParts(value: string): string[];
|
|
16
|
+
export declare function handlePluginCommand(args: string, ctx: CommandContext): Promise<CommandResult>;
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import fs from 'node:fs/promises';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { inspectPlugin, PLUGIN_LIMITS, readJson, safePath } from '../../skills/plugins/package.js';
|
|
4
|
+
import { installPlugin, listPlugins, removePlugin } from '../../skills/plugins/installer.js';
|
|
5
|
+
const PLUGIN_HELP = 'plugin inspect <local-directory> [plugin-name]\nplugin install <local-directory> [plugin-name]\nplugin list\nplugin remove <name>\nPlugins install globally under ~/.haze/plugins and never write workspace content. Installation trusts local instruction content; no scripts, hooks or MCP servers are activated. Clone remote collections locally first. kit is an alias for plugin.';
|
|
6
|
+
async function exists(file) {
|
|
7
|
+
try {
|
|
8
|
+
await fs.lstat(file);
|
|
9
|
+
return true;
|
|
10
|
+
}
|
|
11
|
+
catch (error) {
|
|
12
|
+
if (error.code === 'ENOENT')
|
|
13
|
+
return false;
|
|
14
|
+
throw error;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
/** Installed plugins for the `/plugin` picker (receipt-listed, global ~/.haze). */
|
|
18
|
+
export async function listInstalledPlugins() {
|
|
19
|
+
return listPlugins();
|
|
20
|
+
}
|
|
21
|
+
/** Collection entries from a local marketplace root; throws when the directory is not a collection (root plugin manifests keep precedence). */
|
|
22
|
+
export async function pluginCollectionEntries(source) {
|
|
23
|
+
const root = await safePath(await fs.realpath(path.resolve(source)));
|
|
24
|
+
// Root plugin manifests keep precedence over colocated marketplace catalogs.
|
|
25
|
+
for (const manifest of ['plugin.json', '.claude-plugin/plugin.json', '.codex-plugin/plugin.json', 'skills']) {
|
|
26
|
+
if (await exists(await safePath(root, manifest)))
|
|
27
|
+
throw new Error('Not a plugin collection.');
|
|
28
|
+
}
|
|
29
|
+
const { plugins } = await readCollection(root);
|
|
30
|
+
return plugins.map(entry => {
|
|
31
|
+
const record = typeof entry === 'object' && entry !== null ? entry : {};
|
|
32
|
+
if (typeof record.name !== 'string' || !record.name)
|
|
33
|
+
throw new Error('Invalid marketplace plugin entry.');
|
|
34
|
+
return { name: record.name, ...(typeof record.description === 'string' ? { description: record.description } : {}) };
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
/** Read and validate a marketplace catalog (`.claude-plugin` first, then `.agents/plugins`). */
|
|
38
|
+
async function readCollection(source) {
|
|
39
|
+
const root = await safePath(await fs.realpath(path.resolve(source)));
|
|
40
|
+
for (const location of ['.claude-plugin/marketplace.json', '.agents/plugins/marketplace.json']) {
|
|
41
|
+
const file = await safePath(root, location);
|
|
42
|
+
try {
|
|
43
|
+
await fs.lstat(file);
|
|
44
|
+
}
|
|
45
|
+
catch (error) {
|
|
46
|
+
if (error.code === 'ENOENT')
|
|
47
|
+
continue;
|
|
48
|
+
throw error;
|
|
49
|
+
}
|
|
50
|
+
const catalog = await readJson(file);
|
|
51
|
+
if (!Array.isArray(catalog.plugins) || catalog.plugins.length > PLUGIN_LIMITS.entries)
|
|
52
|
+
throw new Error('Invalid marketplace plugins list.');
|
|
53
|
+
return { name: typeof catalog.name === 'string' ? catalog.name : undefined, plugins: catalog.plugins };
|
|
54
|
+
}
|
|
55
|
+
throw new Error('No plugin collection marketplace found.');
|
|
56
|
+
}
|
|
57
|
+
/** cwd is kept for source-path resolution symmetry with other commands; installs are global. */
|
|
58
|
+
export async function runPluginCommand(args, _cwd = process.cwd()) {
|
|
59
|
+
const [action, source, name, ...extra] = args;
|
|
60
|
+
if (!action || action === 'help')
|
|
61
|
+
return PLUGIN_HELP;
|
|
62
|
+
if (extra.length || (action === 'list' && source) || (action === 'remove' && name))
|
|
63
|
+
throw new Error(PLUGIN_HELP);
|
|
64
|
+
if (action === 'list') {
|
|
65
|
+
const installed = await listPlugins();
|
|
66
|
+
return installed.length ? installed.map(plugin => `${plugin.name}${plugin.version ? `@${plugin.version}` : ''}`).join('\n') : 'No plugins installed.';
|
|
67
|
+
}
|
|
68
|
+
if (!source)
|
|
69
|
+
throw new Error(PLUGIN_HELP);
|
|
70
|
+
if (action === 'remove') {
|
|
71
|
+
const result = await removePlugin(source);
|
|
72
|
+
return `Removed plugin ${result.name}.${result.retained.length ? `\nRetained modified/unowned files:\n${result.retained.join('\n')}` : ''}`;
|
|
73
|
+
}
|
|
74
|
+
if (action === 'install') {
|
|
75
|
+
const result = await installPlugin(source, name);
|
|
76
|
+
return `${result.alreadyInstalled ? 'Plugin already installed:' : 'Installed'} ${result.name}${result.version ? `@${result.version}` : ''}.\nUse /skills or /${result.name}:<skill-name>.${result.warnings.length ? `\n${result.warnings.join('\n')}` : ''}`;
|
|
77
|
+
}
|
|
78
|
+
if (action === 'inspect') {
|
|
79
|
+
let result;
|
|
80
|
+
try {
|
|
81
|
+
result = await inspectPlugin(source, name);
|
|
82
|
+
}
|
|
83
|
+
catch (error) {
|
|
84
|
+
if (!(error instanceof Error) || error.message !== 'This is a plugin collection; select a plugin name.')
|
|
85
|
+
throw error;
|
|
86
|
+
// Collection inspection lists metadata only; selection is required to install.
|
|
87
|
+
const catalog = await readCollection(source).catch(() => undefined);
|
|
88
|
+
if (!catalog)
|
|
89
|
+
throw error;
|
|
90
|
+
const entries = await pluginCollectionEntries(source);
|
|
91
|
+
const collectionName = catalog.name ?? path.basename(await fs.realpath(path.resolve(source)));
|
|
92
|
+
return `Plugin collection: ${collectionName}\n${entries.map(entry => entry.name).join('\n')}\nSelect one: plugin inspect <local-directory> <plugin-name>`;
|
|
93
|
+
}
|
|
94
|
+
const skills = result.files.filter(file => /^skills\/[^/]+\/SKILL\.md$/.test(file));
|
|
95
|
+
return `${result.manifest.name}${result.manifest.version ? `@${result.manifest.version}` : ''}\n${result.manifest.description ?? ''}\n${skills.length} standard skills; ${result.files.length} package files.${result.warnings.length ? `\n${result.warnings.join('\n')}` : ''}`;
|
|
96
|
+
}
|
|
97
|
+
throw new Error(PLUGIN_HELP);
|
|
98
|
+
}
|
|
99
|
+
/** Quoted local paths work in chat too; this is argument parsing, not shell execution. */
|
|
100
|
+
export function pluginCommandParts(value) {
|
|
101
|
+
const parts = [];
|
|
102
|
+
let remaining = value.trim();
|
|
103
|
+
while (remaining) {
|
|
104
|
+
const match = /^(?:"([^"]*)"|'([^']*)'|([^\s"']+))(?:\s+|$)/.exec(remaining);
|
|
105
|
+
if (!match)
|
|
106
|
+
throw new Error('Invalid plugin arguments. Quote paths containing spaces.');
|
|
107
|
+
parts.push(match[1] ?? match[2] ?? match[3]);
|
|
108
|
+
remaining = remaining.slice(match[0].length);
|
|
109
|
+
}
|
|
110
|
+
return parts;
|
|
111
|
+
}
|
|
112
|
+
export async function handlePluginCommand(args, ctx) {
|
|
113
|
+
const parts = pluginCommandParts(args);
|
|
114
|
+
if (parts.length === 0) {
|
|
115
|
+
// Bare `/plugin` opens the picker, consistent with /skills, /lsp, and /mcp;
|
|
116
|
+
// headless contexts without a picker keep the usage text.
|
|
117
|
+
if (ctx.openPluginPicker)
|
|
118
|
+
await ctx.openPluginPicker();
|
|
119
|
+
else
|
|
120
|
+
ctx.addSystemMessage(PLUGIN_HELP);
|
|
121
|
+
return 'handled';
|
|
122
|
+
}
|
|
123
|
+
ctx.addSystemMessage(await runPluginCommand(parts));
|
|
124
|
+
if (parts[0] === 'install' || parts[0] === 'remove')
|
|
125
|
+
await ctx.refreshSkills?.();
|
|
126
|
+
return 'handled';
|
|
127
|
+
}
|
|
@@ -1,20 +1,5 @@
|
|
|
1
1
|
import { type ResolvedReasoningChoice, type StoredReasoningSetting } from '../../core/agent/reasoningPolicy.js';
|
|
2
2
|
import type { CommandContext, CommandResult } from './commands.js';
|
|
3
|
-
/**
|
|
4
|
-
* `/reasoning` — per-model, per-session reasoning-effort picker and direct
|
|
5
|
-
* set, modeled on `/themes`. The picker is one step in the `wizardFlow.ts`
|
|
6
|
-
* table (mode `reasoning`); this module holds the pure result function shared
|
|
7
|
-
* by the slash path and the wizard submit handler. The chosen level applies to
|
|
8
|
-
* the active `provider:model` for the current session only — kept in memory on
|
|
9
|
-
* the `PromptSession` object, never written to `~/.haze/settings.json` — and
|
|
10
|
-
* applies from the next turn (reasoning is resolved once per attempt in
|
|
11
|
-
* `attemptSetup`). A model without a session override falls back to the saved
|
|
12
|
-
* global `reasoning` setting, then the built-in default.
|
|
13
|
-
*/
|
|
14
|
-
/** Picker value that stops sending a reasoning parameter (also accepted as `off` on the slash path). */
|
|
15
|
-
export declare const REASONING_UNSET = "unset";
|
|
16
|
-
/** Picker/slash value that removes the session override and inherits the saved/default level. */
|
|
17
|
-
export declare const REASONING_RESET = "reset";
|
|
18
3
|
export type ReasoningCommandResult = {
|
|
19
4
|
action: 'status';
|
|
20
5
|
message: string;
|
|
@@ -10,10 +10,8 @@ import { REASONING_LEVELS, REASONING_PROVIDER_DEFAULT, isReasoningLevel, isReaso
|
|
|
10
10
|
* `attemptSetup`). A model without a session override falls back to the saved
|
|
11
11
|
* global `reasoning` setting, then the built-in default.
|
|
12
12
|
*/
|
|
13
|
-
/** Picker value that stops sending a reasoning parameter (also accepted as `off` on the slash path). */
|
|
14
|
-
export const REASONING_UNSET = 'unset';
|
|
15
13
|
/** Picker/slash value that removes the session override and inherits the saved/default level. */
|
|
16
|
-
|
|
14
|
+
const REASONING_RESET = 'reset';
|
|
17
15
|
const LEVELS_LIST = REASONING_LEVELS.join(', ');
|
|
18
16
|
function describeChoice(choice) {
|
|
19
17
|
if (choice.level === undefined)
|
|
@@ -33,6 +33,8 @@ export function selectSkillActionResult(settings, skills, selectedName, action)
|
|
|
33
33
|
return { message: skillInfoMessage(settings, skill), skill };
|
|
34
34
|
if (action === SKILL_ACTIONS.validate)
|
|
35
35
|
return { validate: true, skill };
|
|
36
|
+
if (action === SKILL_ACTIONS.removeSkill && skill.pluginName)
|
|
37
|
+
return { mode: 'chat', selectedName: undefined, message: `Use /plugin remove ${skill.pluginName} or disable this skill`, skill };
|
|
36
38
|
if (action === SKILL_ACTIONS.removeSkill)
|
|
37
39
|
return { mode: 'skillsConfirmRemove', message: `Remove ${skill.source} skill ${skill.name}? This deletes ${skill.dir}. Type "yes" to confirm. Esc to cancel.`, skill };
|
|
38
40
|
return { message: `Unknown skill action: ${action}`, skill };
|
|
@@ -59,6 +61,8 @@ export function skillConfirmRemoveResult(settings, skills, selectedName, value)
|
|
|
59
61
|
const skill = findSelectedSkill(skills, selectedName);
|
|
60
62
|
if (!skill)
|
|
61
63
|
return { mode: 'chat', selectedName: undefined, message: `Skill ${selectedName} not found.` };
|
|
64
|
+
if (skill.pluginName)
|
|
65
|
+
return { mode: 'chat', selectedName: undefined, message: `Use /plugin remove ${skill.pluginName} or disable this skill`, skill };
|
|
62
66
|
return {
|
|
63
67
|
mode: 'chat',
|
|
64
68
|
selectedName: undefined,
|
|
@@ -60,6 +60,7 @@ export async function runAgentAttempt(input) {
|
|
|
60
60
|
abortCause,
|
|
61
61
|
retryAttempt,
|
|
62
62
|
maxRetries: attemptSetupResult.modelRetries,
|
|
63
|
+
timeoutMs: attemptSetupResult.streamIdleTimeoutMs,
|
|
63
64
|
classifyEmission: () => loopState.currentAssistantText.trim().length > 0 || loopState.assistantStarted ? 'text' : loopState.inFlightTools.size > 0 ? 'tool' : 'none',
|
|
64
65
|
isToolInFlight: () => loopState.inFlightTools.size > 0,
|
|
65
66
|
provider: () => attemptSetupResult.runtime.config.providerName,
|
|
@@ -74,7 +75,7 @@ export async function runAgentAttempt(input) {
|
|
|
74
75
|
return finalizeAttemptOutcome({ value, callbacks, abortController, turnOptions, turnState, turnBudget, goal, remainingTurnDeadlineMs, stream, retryAttempt, overflowRetries: input.overflowRetries });
|
|
75
76
|
}
|
|
76
77
|
catch (error) {
|
|
77
|
-
return handleAttemptFailure({ value, callbacks, abortController, turnState, retryAttempt, progressSinceLastRetry: input.progressSinceLastRetry, overflowRetries: input.overflowRetries, abortCause, stallGuard, salvage, error, maxRetries: setup?.modelRetries, retryBaseDelayMs: setup?.retryBaseDelayMs, goal, turnOptions });
|
|
78
|
+
return handleAttemptFailure({ value, callbacks, abortController, turnState, retryAttempt, progressSinceLastRetry: input.progressSinceLastRetry, overflowRetries: input.overflowRetries, abortCause, stallGuard, salvage, error, maxRetries: setup?.modelRetries, retryBaseDelayMs: setup?.retryBaseDelayMs, idleTimeoutMs: setup?.streamIdleTimeoutMs, goal, turnOptions });
|
|
78
79
|
}
|
|
79
80
|
finally {
|
|
80
81
|
await cleanup.closeOnce(ATTEMPT_TEARDOWN_BOUND_MS);
|
|
@@ -97,6 +97,8 @@ export interface AttemptFailureDeps {
|
|
|
97
97
|
maxRetries?: number;
|
|
98
98
|
/** Backoff base for the shared model-retry pool (`retryBaseDelayMs` setting); defaults to DEFAULT_RETRY_BASE_DELAY_MS. */
|
|
99
99
|
retryBaseDelayMs?: number;
|
|
100
|
+
/** Effective idle-stall window (`streamIdleTimeoutMs` setting; 5 min hosted / 30 min local built-in); defaults to IDLE_TIMEOUT_MS. */
|
|
101
|
+
idleTimeoutMs?: number;
|
|
100
102
|
goal: SessionGoal;
|
|
101
103
|
turnOptions: TurnExecutionOptions;
|
|
102
104
|
}
|
|
@@ -182,6 +182,7 @@ export function handleAttemptFailure(deps) {
|
|
|
182
182
|
const { value, callbacks, abortController, turnState, abortCause, stallGuard, salvage, error, goal, turnOptions } = deps;
|
|
183
183
|
const maxRetries = deps.maxRetries ?? DEFAULT_MODEL_RETRIES;
|
|
184
184
|
const retryBaseDelayMs = deps.retryBaseDelayMs ?? DEFAULT_RETRY_BASE_DELAY_MS;
|
|
185
|
+
const idleTimeoutMs = deps.idleTimeoutMs ?? IDLE_TIMEOUT_MS;
|
|
185
186
|
const overflowRetries = deps.overflowRetries ?? 0;
|
|
186
187
|
// Progress refills the shared pool: consecutive failures chain backoff, but
|
|
187
188
|
// a failed attempt that completed steps since the last retry starts fresh.
|
|
@@ -195,8 +196,8 @@ export function handleAttemptFailure(deps) {
|
|
|
195
196
|
salvageConversationToLastStep(callbacks, salvage);
|
|
196
197
|
if (stallGuard?.retryEligible) {
|
|
197
198
|
const delay = retryDelayMs(retryAttempt, retryBaseDelayMs);
|
|
198
|
-
callbacks.onEvent?.(agentEvent({ type: 'retry', attempt: retryAttempt + 1, maxAttempts: maxRetries, delayMs: delay, error: `model stream idle for ${formatSeconds(
|
|
199
|
-
callbacks.addMessage({ role: 'system', text: `Model stream stalled for ${formatIdleMinutes(
|
|
199
|
+
callbacks.onEvent?.(agentEvent({ type: 'retry', attempt: retryAttempt + 1, maxAttempts: maxRetries, delayMs: delay, error: `model stream idle for ${formatSeconds(idleTimeoutMs)}` }));
|
|
200
|
+
callbacks.addMessage({ role: 'system', text: `Model stream stalled for ${formatIdleMinutes(idleTimeoutMs)}; retrying attempt ${retryAttempt + 1}/${maxRetries} in ${formatSeconds(delay)}. Completed steps are preserved.` });
|
|
200
201
|
// freshController: this stall aborted the controller to kill the hung
|
|
201
202
|
// stream; the retry needs a live signal.
|
|
202
203
|
return { status: 'failed', retry: { attempt: retryAttempt + 1, delayMs: delay, freshController: true } };
|
|
@@ -206,7 +207,7 @@ export function handleAttemptFailure(deps) {
|
|
|
206
207
|
// path) instead of discarding progress; the interactive UI offers a
|
|
207
208
|
// one-key resume from TurnResult.resume.
|
|
208
209
|
const afterStep = turnState.stepsUsed > 0 ? ` after step ${turnState.stepsUsed}` : '';
|
|
209
|
-
callbacks.addMessage({ role: 'system', text: `Model stream stalled for ${formatIdleMinutes(
|
|
210
|
+
callbacks.addMessage({ role: 'system', text: `Model stream stalled for ${formatIdleMinutes(idleTimeoutMs)}; unfinished task paused${afterStep}. Press R to retry, or send a follow-up message to continue.` });
|
|
210
211
|
return { status: 'failed', resume: { kind: 'model-stream-idle', request: value, retryAttempt } };
|
|
211
212
|
}
|
|
212
213
|
if (abortCause.kind === 'turn-deadline') {
|
|
@@ -50,6 +50,8 @@ export interface AttemptSetup {
|
|
|
50
50
|
modelRetries: number;
|
|
51
51
|
/** Backoff base for the shared model-retry pool, from the `retryBaseDelayMs` setting (default 1000ms). */
|
|
52
52
|
retryBaseDelayMs: number;
|
|
53
|
+
/** Effective idle-stall window (ms): the `streamIdleTimeoutMs` setting, else 5 min hosted / 30 min local. */
|
|
54
|
+
streamIdleTimeoutMs: number;
|
|
53
55
|
steeringProfile: 'standard' | 'compact';
|
|
54
56
|
}
|
|
55
57
|
export interface AttemptSetupDeps {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { readSettings } from '../../../config/settings.js';
|
|
2
|
-
import { DEFAULT_MAX_OUTPUT_TOKENS, DEFAULT_RETRY_BASE_DELAY_MS, MAIN_STEP_LIMIT, MAIN_TOOL_CALL_LIMIT, SUBAGENT_TOOL_DEADLINE_MS, DEFAULT_TOOL_DEADLINE_MS, DEFAULT_MODEL_RETRIES, withToolExecutionBudget } from '../../../core/agent/budgets.js';
|
|
2
|
+
import { DEFAULT_MAX_OUTPUT_TOKENS, DEFAULT_RETRY_BASE_DELAY_MS, MAIN_STEP_LIMIT, MAIN_TOOL_CALL_LIMIT, SUBAGENT_TOOL_DEADLINE_MS, DEFAULT_TOOL_DEADLINE_MS, DEFAULT_MODEL_RETRIES, resolveStreamIdleTimeoutMs, withToolExecutionBudget } from '../../../core/agent/budgets.js';
|
|
3
3
|
import { agentEvent } from '../../../core/agent/events.js';
|
|
4
4
|
import { goalDirectionPrompt, isPlanOnlyRequest } from '../../../core/agent/goalPolicy.js';
|
|
5
5
|
import { projectPreflight } from '../../../core/agent/projectPreflight.js';
|
|
@@ -11,7 +11,7 @@ import { withToolDeadline } from '../../../core/deadline.js';
|
|
|
11
11
|
import { isMutatingCapability, isValidationCapable } from '../../../core/agent/toolCapabilities.js';
|
|
12
12
|
import { userTurnMessage } from '../../../core/attachments/imageAttachments.js';
|
|
13
13
|
import { WorkspaceMutationPolicy } from '../../../core/subagent/workspaceMutationPolicy.js';
|
|
14
|
-
import { modelWithConfig, providerRequestSettings } from '../../../llm/client.js';
|
|
14
|
+
import { modelWithConfig, providerRequestSettings, isLocalProviderUrl } from '../../../llm/client.js';
|
|
15
15
|
import { assembleRequestContext } from '../../../llm/requestContext.js';
|
|
16
16
|
import { modelThinkingLabel } from '../../../utils/modelName.js';
|
|
17
17
|
import { estimateInputBreakdown, logEntry } from './turnRuntime.js';
|
|
@@ -193,6 +193,7 @@ export async function prepareAttempt(deps) {
|
|
|
193
193
|
toolCategories,
|
|
194
194
|
modelRetries: typeof turnSettings.modelRetries === 'number' ? turnSettings.modelRetries : DEFAULT_MODEL_RETRIES,
|
|
195
195
|
retryBaseDelayMs: typeof turnSettings.retryBaseDelayMs === 'number' ? turnSettings.retryBaseDelayMs : DEFAULT_RETRY_BASE_DELAY_MS,
|
|
196
|
+
streamIdleTimeoutMs: resolveStreamIdleTimeoutMs(turnSettings.streamIdleTimeoutMs, isLocalProviderUrl(runtime.config.baseURL)),
|
|
196
197
|
steeringProfile,
|
|
197
198
|
};
|
|
198
199
|
}
|
|
@@ -61,6 +61,12 @@ export interface StreamStallGuardDeps {
|
|
|
61
61
|
retryAttempt: number;
|
|
62
62
|
/** Retry-pool size for this turn (`modelRetries` setting); defaults to DEFAULT_MODEL_RETRIES. */
|
|
63
63
|
maxRetries?: number;
|
|
64
|
+
/**
|
|
65
|
+
* Effective idle-stall window in ms, resolved in `prepareAttempt` from the
|
|
66
|
+
* `streamIdleTimeoutMs` setting with the class-aware built-in default
|
|
67
|
+
* (5 min hosted / 30 min local); defaults to IDLE_TIMEOUT_MS.
|
|
68
|
+
*/
|
|
69
|
+
timeoutMs?: number;
|
|
64
70
|
/** Classify what the stalled step emitted so far: partial text, in-flight tool, or nothing. */
|
|
65
71
|
classifyEmission: () => StallEmission;
|
|
66
72
|
isToolInFlight: () => boolean;
|
|
@@ -39,12 +39,13 @@ export function createIdleTimer(input) {
|
|
|
39
39
|
}
|
|
40
40
|
export function createStreamStallGuard(deps) {
|
|
41
41
|
const maxRetries = deps.maxRetries ?? DEFAULT_MODEL_RETRIES;
|
|
42
|
+
const timeoutMs = deps.timeoutMs ?? IDLE_TIMEOUT_MS;
|
|
42
43
|
let stallEmission = 'none';
|
|
43
44
|
let retryEligible = false;
|
|
44
45
|
let lastStreamEventAt;
|
|
45
46
|
let lastStreamEventType;
|
|
46
47
|
const timer = createIdleTimer({
|
|
47
|
-
timeoutMs
|
|
48
|
+
timeoutMs,
|
|
48
49
|
isBusy: () => deps.isToolInFlight(),
|
|
49
50
|
onTimeout: () => {
|
|
50
51
|
if (deps.controller.signal.aborted)
|
|
@@ -58,7 +59,7 @@ export function createStreamStallGuard(deps) {
|
|
|
58
59
|
deps.onEvent?.(agentEvent({
|
|
59
60
|
type: 'timeout',
|
|
60
61
|
phase: 'model-stream',
|
|
61
|
-
timeoutMs
|
|
62
|
+
timeoutMs,
|
|
62
63
|
provider: deps.provider(),
|
|
63
64
|
model: deps.model(),
|
|
64
65
|
lastStreamEventAt: lastEventAtIso,
|
|
@@ -68,9 +69,9 @@ export function createStreamStallGuard(deps) {
|
|
|
68
69
|
retryEligible: retryEligible,
|
|
69
70
|
maxRetries: maxRetries,
|
|
70
71
|
}));
|
|
71
|
-
logEntry(deps.log, { at: new Date().toISOString(), type: 'warning', stream: 'main', error: `model-stream idle ${
|
|
72
|
-
deps.debugLog(`model stream idle for ${
|
|
73
|
-
abortForTurn(deps.abortCause, { kind: 'model-stream-idle', timeoutMs
|
|
72
|
+
logEntry(deps.log, { at: new Date().toISOString(), type: 'warning', stream: 'main', error: `model-stream idle ${timeoutMs}ms: provider=${deps.provider() ?? 'unknown'} model=${deps.model() ?? 'unknown'} lastEvent=${lastStreamEventType ?? 'none'}@${lastEventAtIso ?? 'never'} stallEmission=${stallEmission} workPhase=${deps.workPhase()} retryEligible=${retryEligible} maxRetries=${maxRetries} stepsUsed=${deps.stepsUsed()}` });
|
|
73
|
+
deps.debugLog(`model stream idle for ${timeoutMs}ms (last event: ${lastStreamEventType ?? 'none'}); ${retryEligible ? `retryable stall (${deps.retryAttempt}/${maxRetries} used)` : 'stall not retryable'}`);
|
|
74
|
+
abortForTurn(deps.abortCause, { kind: 'model-stream-idle', timeoutMs }, deps.controller, 'haze model stream was idle for the configured timeout.');
|
|
74
75
|
},
|
|
75
76
|
});
|
|
76
77
|
return {
|
|
@@ -68,10 +68,8 @@ export function subagentTokenEstimate(output) {
|
|
|
68
68
|
if (typeof output !== 'object' || output == null)
|
|
69
69
|
return undefined;
|
|
70
70
|
const value = output;
|
|
71
|
-
const
|
|
72
|
-
const
|
|
73
|
-
const input = typeof inputValue === 'number' ? inputValue : 0;
|
|
74
|
-
const outputTokens = typeof outputValue === 'number' ? outputValue : 0;
|
|
71
|
+
const input = typeof value.telemetry?.usage?.inputTokens === 'number' ? value.telemetry.usage.inputTokens : 0;
|
|
72
|
+
const outputTokens = typeof value.telemetry?.usage?.outputTokens === 'number' ? value.telemetry.usage.outputTokens : 0;
|
|
75
73
|
return input > 0 || outputTokens > 0 ? { input, output: outputTokens } : undefined;
|
|
76
74
|
}
|
|
77
75
|
export function rememberContextFilesFromToolOutput(activeContextFiles, output) {
|