@denizokcu/haze 0.9.0 → 0.11.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 +133 -17
- package/README.md +164 -68
- package/SECURITY.md +22 -0
- package/bin/haze.js +102 -1
- package/dist/buildInfo.json +7 -0
- package/dist/cli/chat/TaskBar.d.ts +2 -1
- package/dist/cli/chat/TaskBar.js +7 -4
- package/dist/cli/chat/chatMetrics.d.ts +17 -1
- package/dist/cli/chat/chatMetrics.js +22 -5
- package/dist/cli/chat/contextReport.d.ts +11 -0
- package/dist/cli/chat/contextReport.js +46 -0
- package/dist/cli/chat/fileMentionSuggestions.d.ts +29 -0
- package/dist/cli/chat/fileMentionSuggestions.js +92 -0
- package/dist/cli/chat/inputSuggestions.d.ts +5 -0
- package/dist/cli/chat/inputSuggestions.js +17 -3
- package/dist/cli/chat/liveRegion.d.ts +25 -0
- package/dist/cli/chat/liveRegion.js +48 -0
- package/dist/cli/chat/messages.d.ts +33 -2
- package/dist/cli/chat/messages.js +216 -33
- package/dist/cli/chat/sessionLifecycle.d.ts +67 -0
- package/dist/cli/chat/sessionLifecycle.js +205 -0
- package/dist/cli/chat/sessionRecorder.js +80 -14
- package/dist/cli/chat/startupInfo.js +11 -4
- package/dist/cli/chat/tips.d.ts +21 -0
- package/dist/cli/chat/tips.js +43 -0
- package/dist/cli/chat/wizardDispatch.d.ts +64 -0
- package/dist/cli/chat/wizardDispatch.js +744 -0
- package/dist/cli/commands/chat.d.ts +6 -0
- package/dist/cli/commands/chat.js +373 -790
- package/dist/cli/commands/chatModes.d.ts +1 -1
- package/dist/cli/commands/chatModes.js +7 -2
- package/dist/cli/commands/commandHelp.js +5 -3
- package/dist/cli/commands/commands.d.ts +5 -2
- package/dist/cli/commands/commands.js +22 -18
- package/dist/cli/commands/doctor.d.ts +19 -0
- package/dist/cli/commands/doctor.js +76 -0
- package/dist/cli/commands/fleetCommand.d.ts +14 -0
- package/dist/cli/commands/fleetCommand.js +46 -0
- package/dist/cli/commands/formatters.d.ts +5 -0
- package/dist/cli/commands/formatters.js +35 -6
- package/dist/cli/commands/logsCommand.js +1 -7
- package/dist/cli/commands/modelCommand.js +1 -1
- package/dist/cli/commands/ndjsonSink.d.ts +23 -0
- package/dist/cli/commands/ndjsonSink.js +38 -0
- package/dist/cli/commands/providerWizard.d.ts +10 -2
- package/dist/cli/commands/providerWizard.js +50 -4
- package/dist/cli/commands/runCommand.d.ts +4 -0
- package/dist/cli/commands/runCommand.js +142 -16
- package/dist/cli/commands/sessionPicker.d.ts +9 -0
- package/dist/cli/commands/sessionPicker.js +29 -0
- package/dist/cli/commands/settingsSummary.js +6 -4
- package/dist/cli/commands/skillConfirmRemove.js +4 -3
- package/dist/cli/commands/skillWizard.d.ts +2 -0
- package/dist/cli/commands/skillWizard.js +16 -6
- package/dist/cli/commands/streaming/abortCause.d.ts +24 -0
- package/dist/cli/commands/streaming/abortCause.js +16 -0
- package/dist/cli/commands/streaming/assistantText.js +9 -2
- package/dist/cli/commands/streaming/goalCheckpoint.d.ts +65 -0
- package/dist/cli/commands/streaming/goalCheckpoint.js +23 -0
- package/dist/cli/commands/streaming/goalSupervisor.d.ts +64 -0
- package/dist/cli/commands/streaming/goalSupervisor.js +127 -0
- package/dist/cli/commands/streaming/idleTimer.d.ts +26 -0
- package/dist/cli/commands/streaming/idleTimer.js +24 -0
- package/dist/cli/commands/streaming/toolCallRecovery.d.ts +2 -0
- package/dist/cli/commands/streaming/toolCallRecovery.js +24 -0
- package/dist/cli/commands/streaming/toolGroupRenderer.d.ts +31 -0
- package/dist/cli/commands/streaming/toolGroupRenderer.js +50 -2
- package/dist/cli/commands/streaming/toolResultState.d.ts +6 -1
- package/dist/cli/commands/streaming/toolResultState.js +29 -7
- package/dist/cli/commands/streaming/turnOutcome.d.ts +17 -0
- package/dist/cli/commands/streaming/turnOutcome.js +27 -11
- package/dist/cli/commands/streaming/turnRuntime.js +6 -4
- package/dist/cli/commands/streaming.d.ts +82 -3
- package/dist/cli/commands/streaming.js +528 -91
- package/dist/cli/commands/wizardActions.d.ts +7 -0
- package/dist/cli/commands/wizardActions.js +7 -0
- package/dist/cli/commands/wizardPrompts.js +7 -1
- package/dist/cli/commands/wizardSuggestions.d.ts +8 -0
- package/dist/cli/commands/wizardSuggestions.js +64 -14
- package/dist/cli/commands/wizardTransition.d.ts +4 -0
- package/dist/cli/commands/wizardTransition.js +1 -2
- package/dist/cli/index.js +82 -22
- package/dist/cli/terminalTitle.d.ts +6 -0
- package/dist/cli/terminalTitle.js +36 -0
- package/dist/config/inputHistory.d.ts +3 -3
- package/dist/config/inputHistory.js +12 -18
- package/dist/config/modelDiscovery.d.ts +71 -0
- package/dist/config/modelDiscovery.js +214 -0
- package/dist/config/privateStorage.js +28 -2
- package/dist/config/providerAuth.d.ts +14 -0
- package/dist/config/providerAuth.js +49 -0
- package/dist/config/providerPresets.d.ts +49 -5
- package/dist/config/providerPresets.js +573 -73
- package/dist/config/providers.d.ts +2 -0
- package/dist/config/providers.js +9 -0
- package/dist/config/settings.d.ts +58 -0
- package/dist/config/settings.js +38 -1
- package/dist/config/skillSettings.d.ts +6 -13
- package/dist/config/skillSettings.js +20 -19
- package/dist/core/agent/budgets.d.ts +36 -0
- package/dist/core/agent/budgets.js +44 -0
- package/dist/core/agent/compaction.d.ts +38 -0
- package/dist/core/agent/compaction.js +108 -19
- package/dist/core/agent/completionController.d.ts +230 -0
- package/dist/core/agent/completionController.js +287 -0
- package/dist/core/agent/contextBudget.d.ts +46 -0
- package/dist/core/agent/contextBudget.js +89 -7
- package/dist/core/agent/errors.js +6 -2
- package/dist/core/agent/events.d.ts +86 -0
- package/dist/core/agent/reasoningPolicy.d.ts +31 -0
- package/dist/core/agent/reasoningPolicy.js +27 -0
- package/dist/core/agent/toolCapabilities.d.ts +27 -0
- package/dist/core/agent/toolCapabilities.js +58 -0
- package/dist/core/agent/toolExecutionBudget.d.ts +35 -0
- package/dist/core/agent/toolExecutionBudget.js +49 -0
- package/dist/core/agent/toolOutputStore.d.ts +13 -0
- package/dist/core/agent/toolOutputStore.js +27 -10
- package/dist/core/agent/toolResults.d.ts +12 -0
- package/dist/core/agent/toolResults.js +38 -0
- package/dist/core/agent/turnBudget.d.ts +35 -0
- package/dist/core/agent/turnBudget.js +27 -0
- package/dist/core/agent/turnPolicy.d.ts +11 -0
- package/dist/core/agent/turnPolicy.js +19 -0
- package/dist/core/agent/workState.d.ts +76 -1
- package/dist/core/agent/workState.js +120 -13
- package/dist/core/attachments/imageAttachments.d.ts +90 -0
- package/dist/core/attachments/imageAttachments.js +245 -0
- package/dist/core/attachments/readBlessings.d.ts +37 -0
- package/dist/core/attachments/readBlessings.js +79 -0
- package/dist/core/deadline.d.ts +33 -0
- package/dist/core/deadline.js +74 -0
- package/dist/core/goal/completionPolicy.d.ts +27 -0
- package/dist/core/goal/completionPolicy.js +37 -1
- package/dist/core/goal/requestClassifier.d.ts +0 -3
- package/dist/core/goal/requestClassifier.js +0 -13
- package/dist/core/io/boundedRead.js +76 -29
- package/dist/core/limits/byteBudgets.d.ts +7 -0
- package/dist/core/limits/byteBudgets.js +7 -0
- package/dist/core/limits/textBudgets.d.ts +25 -0
- package/dist/core/limits/textBudgets.js +25 -0
- package/dist/core/log/llmLog.js +7 -0
- package/dist/core/persistence/orderedFileWriter.d.ts +10 -0
- package/dist/core/persistence/orderedFileWriter.js +16 -2
- package/dist/core/process/backgroundRegistry.d.ts +35 -0
- package/dist/core/process/backgroundRegistry.js +195 -0
- package/dist/core/process/runBoundedProcess.d.ts +9 -0
- package/dist/core/process/runBoundedProcess.js +74 -29
- package/dist/core/safety/missingExecutable.d.ts +42 -0
- package/dist/core/safety/missingExecutable.js +77 -0
- package/dist/core/safety/urlGuard.d.ts +2 -1
- package/dist/core/safety/urlGuard.js +3 -2
- package/dist/core/session/sessionSlimming.js +47 -4
- package/dist/core/session/sessionStore.d.ts +74 -0
- package/dist/core/session/sessionStore.js +268 -18
- package/dist/core/subagent/contracts.d.ts +120 -0
- package/dist/core/subagent/contracts.js +55 -0
- package/dist/core/subagent/executionProfiles.d.ts +28 -0
- package/dist/core/subagent/executionProfiles.js +45 -0
- package/dist/core/subagent/subagentCoordinator.d.ts +78 -0
- package/dist/core/subagent/subagentCoordinator.js +164 -0
- package/dist/core/subagent/subagentRunner.d.ts +211 -145
- package/dist/core/subagent/subagentRunner.js +208 -98
- package/dist/core/subagent/workspaceMutationPolicy.d.ts +11 -0
- package/dist/core/subagent/workspaceMutationPolicy.js +52 -0
- package/dist/core/tasks/taskStorage.js +12 -1
- package/dist/llm/client.d.ts +36 -29
- package/dist/llm/client.js +102 -33
- package/dist/llm/hazeTools.d.ts +2559 -150
- package/dist/llm/hazeTools.js +119 -31
- package/dist/llm/lsp.d.ts +26 -4
- package/dist/llm/lsp.js +90 -14
- package/dist/llm/lspTools.d.ts +2366 -0
- package/dist/llm/lspTools.js +87 -79
- package/dist/llm/openaiCodex.d.ts +3 -0
- package/dist/llm/openaiCodex.js +47 -0
- package/dist/llm/openaiCodexOAuth.d.ts +54 -0
- package/dist/llm/openaiCodexOAuth.js +214 -0
- package/dist/llm/requestContext.d.ts +25 -1
- package/dist/llm/requestContext.js +51 -8
- package/dist/llm/systemPrompt.d.ts +15 -1
- package/dist/llm/systemPrompt.js +24 -8
- package/dist/llm/toolResultTypes.d.ts +8 -1
- package/dist/llm/tools/bashTool.d.ts +906 -32
- package/dist/llm/tools/bashTool.js +30 -4
- package/dist/llm/tools/editMatch.d.ts +14 -0
- package/dist/llm/tools/editMatch.js +72 -0
- package/dist/llm/tools/failures.d.ts +2 -0
- package/dist/llm/tools/failures.js +1 -0
- package/dist/llm/tools/fetchTool.d.ts +42 -26
- package/dist/llm/tools/fetchTool.js +1 -1
- package/dist/llm/tools/fileToolShared.d.ts +6 -4
- package/dist/llm/tools/fileToolShared.js +18 -23
- package/dist/llm/tools/gitIgnore.d.ts +49 -0
- package/dist/llm/tools/gitIgnore.js +129 -0
- package/dist/llm/tools/grepRunner.d.ts +5 -0
- package/dist/llm/tools/grepRunner.js +52 -71
- package/dist/llm/tools/outputCap.d.ts +2 -6
- package/dist/llm/tools/outputCap.js +2 -6
- package/dist/llm/tools/processTool.d.ts +1077 -0
- package/dist/llm/tools/processTool.js +41 -0
- package/dist/llm/tools/readRecovery.d.ts +10 -0
- package/dist/llm/tools/readRecovery.js +135 -0
- package/dist/llm/tools/toolContext.d.ts +9 -1
- package/dist/llm/tools/toolContext.js +83 -43
- package/dist/llm/tools/workspaceFile.d.ts +9 -1
- package/dist/llm/tools/workspaceFile.js +33 -4
- package/dist/llm/webFetch.d.ts +17 -0
- package/dist/llm/webFetch.js +66 -86
- package/dist/llm/workerContext.d.ts +18 -0
- package/dist/llm/workerContext.js +55 -0
- package/dist/skills/SkillLoader.d.ts +2 -2
- package/dist/skills/SkillRegistry.d.ts +3 -2
- package/dist/skills/SkillRegistry.js +43 -13
- package/dist/skills/builder/SkillBuilder.d.ts +3 -0
- package/dist/skills/builder/SkillBuilder.js +23 -5
- package/dist/skills/skillTools.js +11 -4
- package/dist/skills/types.d.ts +6 -1
- package/dist/ui/codeHighlight.d.ts +4 -0
- package/dist/ui/codeHighlight.js +31 -0
- package/dist/ui/components/Header.d.ts +1 -1
- package/dist/ui/components/MarkdownText.d.ts +16 -2
- package/dist/ui/components/MarkdownText.js +244 -34
- package/dist/ui/components/TextInput.d.ts +12 -2
- package/dist/ui/components/TextInput.js +80 -8
- package/dist/ui/theme.d.ts +4 -3
- package/dist/ui/theme.js +5 -4
- package/dist/utils/buildInfo.d.ts +104 -0
- package/dist/utils/buildInfo.js +253 -0
- package/dist/utils/format.d.ts +2 -0
- package/dist/utils/format.js +8 -0
- package/dist/utils/fs.d.ts +9 -1
- package/dist/utils/fs.js +87 -29
- package/dist/utils/openPath.d.ts +2 -0
- package/dist/utils/openPath.js +22 -0
- package/dist/utils/path.d.ts +2 -0
- package/dist/utils/path.js +5 -1
- package/dist/utils/utf8.d.ts +22 -0
- package/dist/utils/utf8.js +54 -0
- package/dist/utils/version.d.ts +9 -3
- package/dist/utils/version.js +28 -2
- package/package.json +24 -19
|
@@ -6,9 +6,16 @@ export declare const PROVIDER_ACTIONS: {
|
|
|
6
6
|
readonly useProvider: "use provider";
|
|
7
7
|
readonly addModels: "add models";
|
|
8
8
|
readonly setApiKey: "set API key";
|
|
9
|
+
readonly signInChatGpt: "sign in with ChatGPT";
|
|
10
|
+
readonly markImageCapable: "mark image-capable";
|
|
11
|
+
readonly clearImageCapable: "clear image-capable";
|
|
9
12
|
readonly removeModels: "remove models";
|
|
10
13
|
readonly removeProvider: "remove provider";
|
|
11
14
|
};
|
|
15
|
+
export declare const MODEL_CHOICES: {
|
|
16
|
+
readonly addModels: "add models";
|
|
17
|
+
readonly enterModelNames: "enter model names";
|
|
18
|
+
};
|
|
12
19
|
export declare const SERVER_CHOICES: {
|
|
13
20
|
readonly addServer: "add server";
|
|
14
21
|
readonly custom: "custom";
|
|
@@ -6,9 +6,16 @@ export const PROVIDER_ACTIONS = {
|
|
|
6
6
|
useProvider: 'use provider',
|
|
7
7
|
addModels: 'add models',
|
|
8
8
|
setApiKey: 'set API key',
|
|
9
|
+
signInChatGpt: 'sign in with ChatGPT',
|
|
10
|
+
markImageCapable: 'mark image-capable',
|
|
11
|
+
clearImageCapable: 'clear image-capable',
|
|
9
12
|
removeModels: 'remove models',
|
|
10
13
|
removeProvider: 'remove provider',
|
|
11
14
|
};
|
|
15
|
+
export const MODEL_CHOICES = {
|
|
16
|
+
addModels: 'add models',
|
|
17
|
+
enterModelNames: 'enter model names',
|
|
18
|
+
};
|
|
12
19
|
export const SERVER_CHOICES = {
|
|
13
20
|
addServer: 'add server',
|
|
14
21
|
custom: 'custom',
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { configuredLspServers } from '../../config/lspSettings.js';
|
|
2
2
|
import { findMcpServer } from '../../config/mcpSettings.js';
|
|
3
|
+
import { CHATGPT_CODEX_BASE_URL } from '../../llm/openaiCodexOAuth.js';
|
|
3
4
|
import { MCP_TRANSPORTS } from './wizardActions.js';
|
|
4
5
|
import { commandParts, isValidUrl } from './wizardInput.js';
|
|
5
6
|
export function captureProviderName(settings, value) {
|
|
@@ -29,7 +30,12 @@ export function captureMcpName(settings, value) {
|
|
|
29
30
|
export function captureProviderUrl(value) {
|
|
30
31
|
if (!isValidUrl(value))
|
|
31
32
|
return { message: 'Enter a valid URL, for example http://localhost:1234/v1.' };
|
|
32
|
-
|
|
33
|
+
// The Codex endpoint only accepts ChatGPT sign-in, never API keys; point
|
|
34
|
+
// users at the preset instead of a custom provider that cannot work (F-14).
|
|
35
|
+
const codexHint = value.trim() === CHATGPT_CODEX_BASE_URL
|
|
36
|
+
? `\nNote: ${CHATGPT_CODEX_BASE_URL} serves ChatGPT sign-in only. To use it, add the OpenAI Subscription preset via /provider instead of a custom API-key provider.`
|
|
37
|
+
: '';
|
|
38
|
+
return { draft: { url: value.trim() }, nextMode: 'providerAddKey', systemMessage: `API key? Leave blank for local/keyless providers.${codexHint}` };
|
|
33
39
|
}
|
|
34
40
|
export function captureMcpUrl(value) {
|
|
35
41
|
if (!isValidUrl(value))
|
|
@@ -12,6 +12,13 @@ export declare function providerSuggestions(settings: HazeSettings): TextInputSu
|
|
|
12
12
|
export declare function providerActionSuggestions(settings: HazeSettings, selectedProviderName: string | undefined): TextInputSuggestion[];
|
|
13
13
|
export declare function presetSuggestions(): TextInputSuggestion[];
|
|
14
14
|
export declare function modelSuggestions(settings: HazeSettings, modelProviderFilter: string | undefined): TextInputSuggestion[];
|
|
15
|
+
export declare function modelAddProviderSuggestions(settings: HazeSettings): TextInputSuggestion[];
|
|
16
|
+
/**
|
|
17
|
+
* Model picker fed by live /models discovery. Curated `suggestedModels`
|
|
18
|
+
* (from provider presets) are pinned atop the discovered list when the
|
|
19
|
+
* endpoint actually serves them — stale curation entries simply don't pin.
|
|
20
|
+
*/
|
|
21
|
+
export declare function modelPickSuggestions(settings: HazeSettings, providerName: string | undefined, discoveredModels: string[], suggestedModels?: string[]): TextInputSuggestion[];
|
|
15
22
|
export declare function lspSuggestions(settings: HazeSettings): TextInputSuggestion[];
|
|
16
23
|
export declare function lspActionSuggestions(settings: HazeSettings, selectedLspName: string | undefined): TextInputSuggestion[];
|
|
17
24
|
export declare function lspPresetSuggestions(): TextInputSuggestion[];
|
|
@@ -20,4 +27,5 @@ export declare function mcpActionSuggestions(settings: HazeSettings, selectedMcp
|
|
|
20
27
|
export declare function mcpPresetSuggestions(): TextInputSuggestion[];
|
|
21
28
|
export declare function mcpTransportSuggestions(): TextInputSuggestion[];
|
|
22
29
|
export declare function skillsSuggestions(settings: HazeSettings, skills: LoadedSkill[]): TextInputSuggestion[];
|
|
30
|
+
export declare function skillScopeSuggestions(): TextInputSuggestion[];
|
|
23
31
|
export declare function skillsActionSuggestions(settings: HazeSettings, skills: LoadedSkill[], selectedSkillName: string | undefined): TextInputSuggestion[];
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { configuredProviders, findProvider, modelSelector } from '../../config/providers.js';
|
|
1
|
+
import { configuredProviders, findProvider, modelSelector, providerImageCapable } from '../../config/providers.js';
|
|
2
2
|
import { configuredLspServers, LSP_PRESETS } from '../../config/lspSettings.js';
|
|
3
3
|
import { configuredMcpServers, findMcpServer, findMcpPreset, presetIds } from '../../config/mcpSettings.js';
|
|
4
4
|
import { isSkillEnabled } from '../../config/skillSettings.js';
|
|
5
5
|
import { PROVIDER_PRESETS } from '../../config/providerPresets.js';
|
|
6
|
-
import { COMMON_ACTIONS, LSP_ACTIONS, MCP_ACTIONS, MCP_TRANSPORTS, PROVIDER_ACTIONS, PROVIDER_CHOICES, SERVER_CHOICES, SKILL_ACTIONS, SKILL_CHOICES } from './wizardActions.js';
|
|
6
|
+
import { COMMON_ACTIONS, LSP_ACTIONS, MCP_ACTIONS, MCP_TRANSPORTS, MODEL_CHOICES, PROVIDER_ACTIONS, PROVIDER_CHOICES, SERVER_CHOICES, SKILL_ACTIONS, SKILL_CHOICES } from './wizardActions.js';
|
|
7
|
+
import { findSelectedSkill, skillPickerValue } from './skillWizard.js';
|
|
7
8
|
/**
|
|
8
9
|
* Pure suggestion builders for the chat wizard pickers (provider / model / LSP /
|
|
9
10
|
* MCP / skills). Extracted from the React component so they are unit-testable
|
|
@@ -25,8 +26,15 @@ export function providerActionSuggestions(settings, selectedProviderName) {
|
|
|
25
26
|
const provider = selectedProviderName ? findProvider(settings, selectedProviderName) : undefined;
|
|
26
27
|
return [
|
|
27
28
|
{ value: PROVIDER_ACTIONS.useProvider, description: 'Set this provider and choose a model', kind: 'provider' },
|
|
28
|
-
{ value: PROVIDER_ACTIONS.addModels, description: '
|
|
29
|
-
|
|
29
|
+
{ value: PROVIDER_ACTIONS.addModels, description: provider?.kind === 'chatgpt-codex' ? 'Add a supported Codex model name' : 'Fetch the provider model list and add models', kind: 'provider' },
|
|
30
|
+
...(provider?.kind === 'chatgpt-codex'
|
|
31
|
+
? [{ value: PROVIDER_ACTIONS.signInChatGpt, description: 'Sign in again or switch ChatGPT account', kind: 'provider' }]
|
|
32
|
+
: [{ value: PROVIDER_ACTIONS.setApiKey, description: provider?.key ? 'Update the saved API key' : 'Add an API key', kind: 'provider' }]),
|
|
33
|
+
provider
|
|
34
|
+
? (providerImageCapable(provider)
|
|
35
|
+
? { value: PROVIDER_ACTIONS.clearImageCapable, description: 'Stop sending attached images to this provider', kind: 'provider' }
|
|
36
|
+
: { value: PROVIDER_ACTIONS.markImageCapable, description: 'Allow attached images to be sent to this provider', kind: 'provider' })
|
|
37
|
+
: { value: PROVIDER_ACTIONS.markImageCapable, description: 'Allow attached images to be sent to this provider', kind: 'provider' },
|
|
30
38
|
...(provider?.models?.length ? [{ value: PROVIDER_ACTIONS.removeModels, description: 'Remove models from this provider', kind: 'provider' }] : []),
|
|
31
39
|
{ value: PROVIDER_ACTIONS.removeProvider, description: 'Delete this provider from settings', kind: 'provider' },
|
|
32
40
|
];
|
|
@@ -37,7 +45,7 @@ export function presetSuggestions() {
|
|
|
37
45
|
return [
|
|
38
46
|
...cloudPresets.map(preset => ({
|
|
39
47
|
value: preset.id,
|
|
40
|
-
description: `${preset.baseUrl}${preset.suggestedModels?.length ? ' · e.g. ' + preset.suggestedModels.slice(0, 2).join(', ') : ''}`,
|
|
48
|
+
description: `${preset.baseUrl}${preset.auth === 'chatgpt-oauth' ? ' · browser sign-in' : ''}${preset.suggestedModels?.length ? ' · e.g. ' + preset.suggestedModels.slice(0, 2).join(', ') : ''}`,
|
|
41
49
|
kind: 'provider',
|
|
42
50
|
})),
|
|
43
51
|
...localPresets.map(preset => ({
|
|
@@ -50,11 +58,47 @@ export function presetSuggestions() {
|
|
|
50
58
|
}
|
|
51
59
|
export function modelSuggestions(settings, modelProviderFilter) {
|
|
52
60
|
const providers = configuredProviders(settings).filter(provider => !modelProviderFilter || provider.name === modelProviderFilter);
|
|
53
|
-
return
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
61
|
+
return [
|
|
62
|
+
...providers.flatMap(provider => provider.models.map(model => ({
|
|
63
|
+
value: modelProviderFilter ? model : modelSelector(provider, model),
|
|
64
|
+
description: provider.name,
|
|
65
|
+
kind: 'model',
|
|
66
|
+
}))),
|
|
67
|
+
{ value: MODEL_CHOICES.addModels, description: modelProviderFilter ? `Add models to ${modelProviderFilter} (fetched from its models endpoint)` : 'Add models to a provider (fetched from its models endpoint)', kind: 'model' },
|
|
68
|
+
];
|
|
69
|
+
}
|
|
70
|
+
export function modelAddProviderSuggestions(settings) {
|
|
71
|
+
return configuredProviders(settings).map(provider => ({
|
|
72
|
+
value: provider.name,
|
|
73
|
+
description: `${provider.models.length} model${provider.models.length === 1 ? '' : 's'} configured`,
|
|
74
|
+
kind: 'provider',
|
|
75
|
+
}));
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Model picker fed by live /models discovery. Curated `suggestedModels`
|
|
79
|
+
* (from provider presets) are pinned atop the discovered list when the
|
|
80
|
+
* endpoint actually serves them — stale curation entries simply don't pin.
|
|
81
|
+
*/
|
|
82
|
+
export function modelPickSuggestions(settings, providerName, discoveredModels, suggestedModels = []) {
|
|
83
|
+
const provider = providerName ? findProvider(settings, providerName) : undefined;
|
|
84
|
+
const configured = new Set(provider?.models ?? []);
|
|
85
|
+
const available = discoveredModels.filter(model => !configured.has(model));
|
|
86
|
+
const availableSet = new Set(available);
|
|
87
|
+
const pinned = suggestedModels.filter(model => availableSet.has(model));
|
|
88
|
+
const pinnedSet = new Set(pinned);
|
|
89
|
+
return [
|
|
90
|
+
...pinned.map(model => ({
|
|
91
|
+
value: model,
|
|
92
|
+
description: 'suggested',
|
|
93
|
+
kind: 'model',
|
|
94
|
+
})),
|
|
95
|
+
...available.filter(model => !pinnedSet.has(model)).map(model => ({
|
|
96
|
+
value: model,
|
|
97
|
+
description: providerName,
|
|
98
|
+
kind: 'model',
|
|
99
|
+
})),
|
|
100
|
+
{ value: MODEL_CHOICES.enterModelNames, description: 'Type comma-separated model names instead', kind: 'model' },
|
|
101
|
+
];
|
|
58
102
|
}
|
|
59
103
|
export function lspSuggestions(settings) {
|
|
60
104
|
const servers = configuredLspServers(settings);
|
|
@@ -121,16 +165,22 @@ export function mcpTransportSuggestions() {
|
|
|
121
165
|
export function skillsSuggestions(settings, skills) {
|
|
122
166
|
return [{ value: SKILL_CHOICES.addSkill, description: 'describe a new skill for haze to generate', kind: 'skill' },
|
|
123
167
|
...skills.map(skill => ({
|
|
124
|
-
value: skill.name,
|
|
125
|
-
description: `${skill.description}${isSkillEnabled(settings, skill.name) ? '' : ' · disabled'}`,
|
|
168
|
+
value: skills.some(candidate => candidate !== skill && candidate.name === skill.name) ? skillPickerValue(skill) : skill.name,
|
|
169
|
+
description: `${skill.description} · ${skill.source}${isSkillEnabled(settings, skill.name, skill.source) ? '' : ' · disabled'}`,
|
|
126
170
|
kind: 'skill',
|
|
127
171
|
}))];
|
|
128
172
|
}
|
|
173
|
+
export function skillScopeSuggestions() {
|
|
174
|
+
return [
|
|
175
|
+
{ value: 'this project', description: 'create .haze/skills/<name>/SKILL.md for this repository', kind: 'skill' },
|
|
176
|
+
{ value: 'global', description: 'create ~/.haze/skills/<name>/SKILL.md for your user', kind: 'skill' },
|
|
177
|
+
];
|
|
178
|
+
}
|
|
129
179
|
export function skillsActionSuggestions(settings, skills, selectedSkillName) {
|
|
130
|
-
const skill =
|
|
180
|
+
const skill = findSelectedSkill(skills, selectedSkillName);
|
|
131
181
|
const result = [];
|
|
132
182
|
if (skill) {
|
|
133
|
-
const enabled = isSkillEnabled(settings, skill.name);
|
|
183
|
+
const enabled = isSkillEnabled(settings, skill.name, skill.source);
|
|
134
184
|
result.push({ value: enabled ? COMMON_ACTIONS.disable : COMMON_ACTIONS.enable, description: `${enabled ? COMMON_ACTIONS.disable : COMMON_ACTIONS.enable} this skill`, kind: 'skill' });
|
|
135
185
|
result.push({ value: SKILL_ACTIONS.showInfo, description: 'show description, references, and path', kind: 'skill' });
|
|
136
186
|
result.push({ value: SKILL_ACTIONS.validate, description: 're-load and validate SKILL.md', kind: 'skill' });
|
|
@@ -11,6 +11,9 @@ export type ProviderWizardEffect = SharedWizardEffect | {
|
|
|
11
11
|
type: 'provider-draft';
|
|
12
12
|
patch: Partial<HazeProviderSettings>;
|
|
13
13
|
replace?: boolean;
|
|
14
|
+
} | {
|
|
15
|
+
type: 'discover-provider-models';
|
|
16
|
+
draft: Partial<HazeProviderSettings>;
|
|
14
17
|
};
|
|
15
18
|
export type McpWizardEffect = SharedWizardEffect | {
|
|
16
19
|
type: 'mcp-draft';
|
|
@@ -23,6 +26,7 @@ export declare function transitionProviderField(input: {
|
|
|
23
26
|
mode: Mode;
|
|
24
27
|
value: string;
|
|
25
28
|
settings: HazeSettings;
|
|
29
|
+
draft: Partial<HazeProviderSettings>;
|
|
26
30
|
}): ProviderWizardEffect[] | undefined;
|
|
27
31
|
export declare function transitionMcpField(input: {
|
|
28
32
|
mode: Mode;
|
|
@@ -4,8 +4,7 @@ export function transitionProviderField(input) {
|
|
|
4
4
|
const key = input.value.trim();
|
|
5
5
|
return [
|
|
6
6
|
{ type: 'provider-draft', patch: key ? { key } : {} },
|
|
7
|
-
{ type: '
|
|
8
|
-
{ type: 'message', text: 'Comma-separated model names? Example: llama3.1, qwen2.5-coder, gpt-4o' },
|
|
7
|
+
{ type: 'discover-provider-models', draft: { ...input.draft, ...(key ? { key } : {}) } },
|
|
9
8
|
];
|
|
10
9
|
}
|
|
11
10
|
const result = input.mode === 'providerAddName' ? captureProviderName(input.settings, input.value)
|
package/dist/cli/index.js
CHANGED
|
@@ -1,23 +1,30 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { readFileSync } from 'node:fs';
|
|
3
|
-
import { fileURLToPath } from 'node:url';
|
|
4
|
-
import { dirname, join } from 'node:path';
|
|
5
2
|
import { Command, Option } from 'commander';
|
|
6
3
|
import { chatCommand } from './commands/chat.js';
|
|
7
4
|
import { runHeadless } from './commands/runCommand.js';
|
|
8
|
-
|
|
9
|
-
|
|
5
|
+
import { installTerminalTitle, terminalTitleLabel } from './terminalTitle.js';
|
|
6
|
+
import { findSession } from '../core/session/sessionStore.js';
|
|
7
|
+
import { installBackgroundProcessSignalHandlers, teardownBackgroundProcesses } from '../core/process/backgroundRegistry.js';
|
|
8
|
+
import { STDIN_PROMPT_BYTES } from '../core/limits/byteBudgets.js';
|
|
9
|
+
import { readPackageVersion } from '../utils/version.js';
|
|
10
|
+
import { formatVersionVerbose, readBuildInfo } from '../utils/buildInfo.js';
|
|
11
|
+
import { runDoctor } from './commands/doctor.js';
|
|
12
|
+
installBackgroundProcessSignalHandlers();
|
|
13
|
+
const version = readPackageVersion() ?? '0.0.0';
|
|
10
14
|
const program = new Command();
|
|
11
15
|
program
|
|
12
16
|
.name('haze')
|
|
13
17
|
.description('A pragmatic, intentionally limited agentic CLI.')
|
|
14
|
-
.version(
|
|
18
|
+
.option('-V, --version', 'print the haze version (add --verbose for build provenance: commit, runtime paths, capabilities)')
|
|
19
|
+
.option('--verbose', 'with --version: also print commit, runtime/executable paths, and the capability registry')
|
|
15
20
|
.option('--debug', 'show model/tool debug logs and write a detailed JSONL log to ~/.haze/logs/')
|
|
16
21
|
.option('-c, --continue', 'resume the latest saved session for this workspace')
|
|
22
|
+
.addOption(new Option('--resume <id>', 'resume an exact saved session id for this workspace').conflicts(['continue', 'session']))
|
|
17
23
|
.option('--no-session', 'run without saving or resuming a durable session')
|
|
18
24
|
.option('-p, --prompt <text>', 'print mode: run a single non-interactive turn and print the result (falls back to piped stdin)')
|
|
19
25
|
.option('-m, --model <selector>', 'override the model for this run only — a registered model name or provider:name')
|
|
20
|
-
.addOption(new Option('--output <format>', 'print-mode output: plain text, a single JSON result envelope, or a stream-json NDJSON event stream').choices(['text', 'json', 'stream-json']).default('text'))
|
|
26
|
+
.addOption(new Option('--output <format>', 'print-mode output: plain text, a single JSON result envelope, or a stream-json NDJSON event stream').choices(['text', 'json', 'stream-json']).default('text'))
|
|
27
|
+
.option('--timeout <duration>', 'print-mode absolute turn deadline (e.g. 30s, 10m, 2h); bounds total elapsed time so a busy tool cannot run indefinitely');
|
|
21
28
|
program.addHelpText('after', `
|
|
22
29
|
Examples:
|
|
23
30
|
$ haze start the interactive chat
|
|
@@ -26,57 +33,110 @@ Examples:
|
|
|
26
33
|
$ haze -p "list the top 3 bugs" --output json emit a JSON envelope { type, status, result, usage }
|
|
27
34
|
$ haze -p "audit src/" --output stream-json stream NDJSON events live, then the final result envelope
|
|
28
35
|
$ haze -p "summarize" --model openai:gpt-4o-mini override the model for this run only
|
|
36
|
+
$ haze --resume <id> -p "continue the review" load a saved context for one print-mode turn
|
|
29
37
|
$ haze -p "audit auth.ts" --debug also write a detailed JSONL log to ~/.haze/logs/
|
|
30
38
|
|
|
31
39
|
Print mode (-p):
|
|
32
40
|
Runs a single agentic turn with the full toolset and guardrails, prints the final assistant
|
|
33
41
|
text, then exits (0 = complete; non-zero = aborted/failed, so CI can gate on the exit code).
|
|
34
|
-
The prompt comes from -p, otherwise from piped stdin.
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
42
|
+
The prompt comes from -p, otherwise from piped stdin. Piped prompts over 256 KiB are rejected;
|
|
43
|
+
pass a file path and ask haze to read it instead. With --output json the reply is wrapped in a
|
|
44
|
+
single-line { type, status, result, usage } envelope. With --output stream-json haze streams
|
|
45
|
+
one NDJSON agent event per line (turn_start, step_*, message_*, tool_*, retry, turn_end) as the
|
|
46
|
+
run progresses, then prints that same { type:'result', ... } envelope as the final line — giving
|
|
47
|
+
harnesses live progress, per-step usage, bounded tool-failure diagnostics, and stagnation
|
|
48
|
+
detection without raw tool inputs or outputs. --model overrides the model for this
|
|
39
49
|
run only (no settings change) and must already be registered under a provider (add it once via
|
|
40
50
|
the /provider picker). Print-mode runs are non-durable: --continue is ignored and no session is
|
|
41
|
-
saved
|
|
51
|
+
saved. --resume <id> loads saved context for the turn without changing that session. On a
|
|
52
|
+
provider context overflow, haze compacts the conversation and retries the request once; when
|
|
53
|
+
compaction is unavailable, the error says so explicitly.
|
|
42
54
|
`);
|
|
43
55
|
async function readStdinPrompt() {
|
|
44
56
|
// Only read stdin when it is piped (non-TTY); never hang waiting on an interactive terminal.
|
|
45
|
-
if (process.stdin.isTTY
|
|
46
|
-
return new Promise((resolve) => {
|
|
57
|
+
if (!process.stdin.isTTY) {
|
|
58
|
+
return new Promise((resolve, reject) => {
|
|
47
59
|
let data = '';
|
|
48
|
-
|
|
49
|
-
|
|
60
|
+
let bytes = 0;
|
|
61
|
+
const cleanup = () => {
|
|
62
|
+
process.stdin.removeListener('data', onData);
|
|
63
|
+
process.stdin.removeListener('end', onEnd);
|
|
64
|
+
process.stdin.removeListener('error', onError);
|
|
65
|
+
};
|
|
66
|
+
const onData = (chunk) => {
|
|
67
|
+
bytes += Buffer.byteLength(chunk, 'utf8');
|
|
68
|
+
if (bytes > STDIN_PROMPT_BYTES) {
|
|
69
|
+
cleanup();
|
|
70
|
+
process.stdin.pause();
|
|
71
|
+
reject(new Error(`stdin prompt exceeds ${STDIN_PROMPT_BYTES} bytes; pass a file path and ask haze to read it instead.`));
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
50
74
|
data += chunk;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
|
|
75
|
+
};
|
|
76
|
+
const onEnd = () => {
|
|
77
|
+
cleanup();
|
|
78
|
+
resolve(data.trim() ? data : undefined);
|
|
79
|
+
};
|
|
80
|
+
const onError = () => {
|
|
81
|
+
cleanup();
|
|
82
|
+
resolve(undefined);
|
|
83
|
+
};
|
|
84
|
+
process.stdin.setEncoding('utf8');
|
|
85
|
+
process.stdin.on('data', onData);
|
|
86
|
+
process.stdin.on('end', onEnd);
|
|
87
|
+
process.stdin.on('error', onError);
|
|
54
88
|
});
|
|
55
89
|
}
|
|
56
90
|
return undefined;
|
|
57
91
|
}
|
|
92
|
+
program.command('doctor')
|
|
93
|
+
.description('print runtime provenance (version, commit, executable/runtime paths), verify build integrity, and show the capability registry')
|
|
94
|
+
.action(async () => {
|
|
95
|
+
process.exitCode = await runDoctor();
|
|
96
|
+
});
|
|
58
97
|
program.action(async () => {
|
|
59
98
|
const opts = program.opts();
|
|
99
|
+
if (opts.version) {
|
|
100
|
+
// Handled here (not via commander's built-in .version()) so --verbose can
|
|
101
|
+
// enrich it and the bin launcher can answer without loading dist.
|
|
102
|
+
process.stdout.write(opts.verbose ? `${formatVersionVerbose()}\n` : `${version}\n`);
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
// Name the terminal tab for the run; no-op unless stdout is a real TTY.
|
|
106
|
+
installTerminalTitle(terminalTitleLabel(process.cwd()));
|
|
60
107
|
// -p takes precedence; otherwise fall back to piped stdin. An empty stdin yields no prompt.
|
|
61
108
|
const prompt = opts.prompt?.trim() ? opts.prompt : await readStdinPrompt();
|
|
109
|
+
if (opts.resume && !await findSession(opts.resume)) {
|
|
110
|
+
throw new Error(`No session named ${opts.resume} exists for this workspace.`);
|
|
111
|
+
}
|
|
62
112
|
if (prompt) {
|
|
63
113
|
// One-shot runs are always fresh and non-durable; --continue is ignored in this mode.
|
|
64
114
|
const code = await runHeadless({
|
|
65
115
|
prompt,
|
|
66
116
|
modelOverride: opts.model,
|
|
117
|
+
resumeSessionId: opts.resume,
|
|
67
118
|
// commander validates --output against the choices above, so opts.output is one of
|
|
68
119
|
// 'text' | 'json' | 'stream-json'; default to text for piped/stdin runs without the flag.
|
|
69
120
|
output: opts.output === 'json' || opts.output === 'stream-json' ? opts.output : 'text',
|
|
70
121
|
debug: Boolean(opts.debug),
|
|
122
|
+
timeout: opts.timeout,
|
|
71
123
|
});
|
|
72
124
|
// Set the exit code and return instead of process.exit(code): the latter does not wait
|
|
73
125
|
// for stdout to drain and can truncate piped/redirected output (e.g. `haze -p ... | jq`).
|
|
74
126
|
process.exitCode = code;
|
|
75
127
|
return;
|
|
76
128
|
}
|
|
77
|
-
await chatCommand({ debug: Boolean(opts.debug), continueSession: Boolean(opts.continue), noSession: opts.session === false, version:
|
|
129
|
+
await chatCommand({ debug: Boolean(opts.debug), continueSession: Boolean(opts.continue), resumeSessionId: opts.resume, noSession: opts.session === false, version, build: sessionBuildProvenance() });
|
|
78
130
|
});
|
|
79
|
-
|
|
131
|
+
/** Safe build provenance recorded into session headers (commit + build time only). */
|
|
132
|
+
function sessionBuildProvenance() {
|
|
133
|
+
const info = readBuildInfo();
|
|
134
|
+
if (!info?.commit && !info?.builtAt)
|
|
135
|
+
return undefined;
|
|
136
|
+
return { ...(info?.commit ? { commit: info.commit } : {}), ...(info?.builtAt ? { builtAt: info.builtAt } : {}) };
|
|
137
|
+
}
|
|
138
|
+
program.parseAsync().catch(async (error) => {
|
|
80
139
|
console.error(error instanceof Error ? error.message : error);
|
|
140
|
+
await teardownBackgroundProcesses().catch(() => undefined);
|
|
81
141
|
process.exit(1);
|
|
82
142
|
});
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export declare function terminalTitleLabel(cwd: string): string;
|
|
2
|
+
/**
|
|
3
|
+
* Set the terminal title for the duration of this run. No-op when stdout is
|
|
4
|
+
* not a TTY (headless, piped, or redirected runs).
|
|
5
|
+
*/
|
|
6
|
+
export declare function installTerminalTitle(label: string): void;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { basename } from 'node:path';
|
|
2
|
+
/**
|
|
3
|
+
* Terminal tab/window title for interactive runs. Uses the OSC 0 escape
|
|
4
|
+
* sequence, understood by xterm-compatible terminals (Terminal.app, iTerm2,
|
|
5
|
+
* VS Code, etc.). Guarded to real TTYs so piped/redirected output is never
|
|
6
|
+
* polluted, and cleared on exit so the tab falls back to the shell's own
|
|
7
|
+
* naming instead of showing a stale haze title.
|
|
8
|
+
*/
|
|
9
|
+
function titleEscape(label) {
|
|
10
|
+
return `\u001B]0;${label}\u0007`;
|
|
11
|
+
}
|
|
12
|
+
export function terminalTitleLabel(cwd) {
|
|
13
|
+
// eslint-disable-next-line no-control-regex -- stripping control characters is the point here.
|
|
14
|
+
const dir = basename(cwd).replace(/[\u0000-\u001F\u007F-\u009F]/g, '').trim();
|
|
15
|
+
return `haze${dir ? ` - ${dir}` : ''}`;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Set the terminal title for the duration of this run. No-op when stdout is
|
|
19
|
+
* not a TTY (headless, piped, or redirected runs).
|
|
20
|
+
*/
|
|
21
|
+
export function installTerminalTitle(label) {
|
|
22
|
+
if (!process.stdout.isTTY)
|
|
23
|
+
return;
|
|
24
|
+
process.stdout.write(titleEscape(label));
|
|
25
|
+
process.once('exit', () => {
|
|
26
|
+
// Re-check at exit time: the terminal may no longer be attached.
|
|
27
|
+
if (!process.stdout.isTTY)
|
|
28
|
+
return;
|
|
29
|
+
try {
|
|
30
|
+
process.stdout.write(titleEscape(''));
|
|
31
|
+
}
|
|
32
|
+
catch {
|
|
33
|
+
// Best effort only: title restoration must never break shutdown.
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export declare const INPUT_HISTORY_FILE: string;
|
|
2
|
-
export declare function readInputHistory(): Promise<string[]>;
|
|
3
|
-
export declare function writeInputHistory(history: string[]): Promise<void>;
|
|
4
|
-
export declare function addInputHistoryItem(item: string): Promise<string[]>;
|
|
2
|
+
export declare function readInputHistory(file?: string): Promise<string[]>;
|
|
3
|
+
export declare function writeInputHistory(history: string[], file?: string): Promise<void>;
|
|
4
|
+
export declare function addInputHistoryItem(item: string, file?: string): Promise<string[]>;
|
|
@@ -5,35 +5,29 @@ import { tightenPrivateFile, writePrivateJsonAtomic } from './privateStorage.js'
|
|
|
5
5
|
const HISTORY_DIR = path.join(HAZE_DIR, 'history');
|
|
6
6
|
export const INPUT_HISTORY_FILE = path.join(HISTORY_DIR, 'input-history.json');
|
|
7
7
|
const MAX_HISTORY_ITEMS = 500;
|
|
8
|
-
const DISABLE_PERSISTENT_HISTORY = process.env.VITEST === 'true' || process.env.NODE_ENV === 'test';
|
|
9
|
-
let testHistory = [];
|
|
10
8
|
function normalizeHistory(value) {
|
|
11
9
|
if (!Array.isArray(value))
|
|
12
10
|
return [];
|
|
13
11
|
return value.filter((item) => typeof item === 'string' && item.trim().length > 0);
|
|
14
12
|
}
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
if (await fs.pathExists(
|
|
19
|
-
await tightenPrivateFile(
|
|
20
|
-
const data = await fs.readJson(
|
|
13
|
+
// The storage path is injectable so tests isolate via temp files instead of
|
|
14
|
+
// production switches on test-env globals (CR-011).
|
|
15
|
+
export async function readInputHistory(file = INPUT_HISTORY_FILE) {
|
|
16
|
+
if (await fs.pathExists(file))
|
|
17
|
+
await tightenPrivateFile(file);
|
|
18
|
+
const data = await fs.readJson(file).catch(() => []);
|
|
21
19
|
return normalizeHistory(data).slice(-MAX_HISTORY_ITEMS);
|
|
22
20
|
}
|
|
23
|
-
export async function writeInputHistory(history) {
|
|
21
|
+
export async function writeInputHistory(history, file = INPUT_HISTORY_FILE) {
|
|
24
22
|
const normalized = normalizeHistory(history).slice(-MAX_HISTORY_ITEMS);
|
|
25
|
-
|
|
26
|
-
testHistory = normalized;
|
|
27
|
-
return;
|
|
28
|
-
}
|
|
29
|
-
await writePrivateJsonAtomic(INPUT_HISTORY_FILE, normalized);
|
|
23
|
+
await writePrivateJsonAtomic(file, normalized);
|
|
30
24
|
}
|
|
31
|
-
export async function addInputHistoryItem(item) {
|
|
25
|
+
export async function addInputHistoryItem(item, file = INPUT_HISTORY_FILE) {
|
|
32
26
|
const trimmed = item.trim();
|
|
33
27
|
if (!trimmed)
|
|
34
|
-
return readInputHistory();
|
|
35
|
-
const current = await readInputHistory();
|
|
28
|
+
return readInputHistory(file);
|
|
29
|
+
const current = await readInputHistory(file);
|
|
36
30
|
const next = current[current.length - 1] === trimmed ? current : [...current, trimmed];
|
|
37
|
-
await writeInputHistory(next);
|
|
31
|
+
await writeInputHistory(next, file);
|
|
38
32
|
return next.slice(-MAX_HISTORY_ITEMS);
|
|
39
33
|
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import type { HazeProviderSettings } from './settings.js';
|
|
2
|
+
/** Per-model limits harvested from a provider's /models listing. */
|
|
3
|
+
export type HarvestedModelLimits = Record<string, {
|
|
4
|
+
contextWindowTokens?: number;
|
|
5
|
+
maxOutputTokens?: number;
|
|
6
|
+
}>;
|
|
7
|
+
/**
|
|
8
|
+
* Model discovery against the OpenAI-compatible `/models` endpoint every
|
|
9
|
+
* provider in haze exposes. Used to turn "add models" from a memorize-and-type
|
|
10
|
+
* step into a pick-from-list step; callers fall back to manual input when the
|
|
11
|
+
* endpoint is unavailable.
|
|
12
|
+
*/
|
|
13
|
+
export type ModelDiscoveryResult = {
|
|
14
|
+
status: 'ok';
|
|
15
|
+
models: string[];
|
|
16
|
+
modelLimits?: HarvestedModelLimits;
|
|
17
|
+
} | {
|
|
18
|
+
status: 'failed';
|
|
19
|
+
error: string;
|
|
20
|
+
};
|
|
21
|
+
export declare function modelsEndpointUrl(baseUrl: string): string;
|
|
22
|
+
export declare function parseModelsBody(body: unknown): string[];
|
|
23
|
+
/**
|
|
24
|
+
* Ollama native enrichment. Ollama's OpenAI-compatible /v1/models returns no
|
|
25
|
+
* context fields (verified against ollama 0.32), but its native API does, with
|
|
26
|
+
* different fidelity levels — resolved best-first per model:
|
|
27
|
+
* 1. GET /api/ps — the ACTUAL runtime context of a currently-loaded model
|
|
28
|
+
* (reflects OLLAMA_CONTEXT_LENGTH and Ollama's vram-based auto-sizing);
|
|
29
|
+
* only available while the model stays loaded (keep_alive window).
|
|
30
|
+
* 2. POST /api/show parameters `num_ctx N` — the user's explicit per-model
|
|
31
|
+
* setting (Modelfile), capped by the model's trained maximum.
|
|
32
|
+
* 3. POST /api/show model_info `<arch>.context_length` — the model's
|
|
33
|
+
* theoretical maximum. The effective runtime window may be smaller
|
|
34
|
+
* (auto-sized to VRAM), so it is capped at the conservative local
|
|
35
|
+
* fallback rather than trusted outright (silent truncation guard).
|
|
36
|
+
*/
|
|
37
|
+
export declare const OLLAMA_PROBE_TIMEOUT_MS = 4000;
|
|
38
|
+
interface OllamaShowFacts {
|
|
39
|
+
max?: number;
|
|
40
|
+
numCtx?: number;
|
|
41
|
+
}
|
|
42
|
+
/** Extract context facts from an /api/show response body. */
|
|
43
|
+
export declare function ollamaContextFromShow(show: unknown): OllamaShowFacts;
|
|
44
|
+
/**
|
|
45
|
+
* Probe a local Ollama server for the effective context of the given models.
|
|
46
|
+
* Best-effort: any failing request simply omits that model. Only call for
|
|
47
|
+
* loopback base URLs (the /api/* surface is Ollama-specific).
|
|
48
|
+
*/
|
|
49
|
+
export declare function ollamaModelLimits(input: {
|
|
50
|
+
baseUrl: string;
|
|
51
|
+
models: readonly string[];
|
|
52
|
+
conservativeCap: number;
|
|
53
|
+
fetchImpl?: typeof fetch;
|
|
54
|
+
timeoutMs?: number;
|
|
55
|
+
}): Promise<HarvestedModelLimits>;
|
|
56
|
+
/**
|
|
57
|
+
* Harvest non-standard context/output fields from an OpenAI-compatible
|
|
58
|
+
* `/models` response. The official schema carries only `id`/`created`/`object`,
|
|
59
|
+
* but several providers add extensions (OpenRouter `context_length`, Groq
|
|
60
|
+
* `context_window`, LM Studio `max_context_length`, plus the usual
|
|
61
|
+
* `max_output_tokens`/`max_completion_tokens`/`max_tokens` output caps).
|
|
62
|
+
* Values are sanity-clamped so a quirky proxy cannot poison request budgeting;
|
|
63
|
+
* models with no recognizable fields are simply omitted. This is the only
|
|
64
|
+
* source that can know a local server's actually-configured window.
|
|
65
|
+
*/
|
|
66
|
+
export declare function harvestModelLimits(body: unknown): HarvestedModelLimits;
|
|
67
|
+
export declare function discoverProviderModels(provider: Pick<HazeProviderSettings, 'url' | 'key'>, options?: {
|
|
68
|
+
timeoutMs?: number;
|
|
69
|
+
fetchImpl?: typeof fetch;
|
|
70
|
+
}): Promise<ModelDiscoveryResult>;
|
|
71
|
+
export {};
|