@denizokcu/haze 0.8.0 → 0.10.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 +67 -17
- package/README.md +121 -64
- 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 +44 -0
- package/dist/cli/chat/fileMentionSuggestions.d.ts +29 -0
- package/dist/cli/chat/fileMentionSuggestions.js +91 -0
- package/dist/cli/chat/inputSuggestions.d.ts +5 -0
- package/dist/cli/chat/inputSuggestions.js +17 -3
- package/dist/cli/chat/sessionLifecycle.d.ts +58 -0
- package/dist/cli/chat/sessionLifecycle.js +155 -0
- package/dist/cli/chat/sessionRecorder.d.ts +3 -0
- package/dist/cli/chat/sessionRecorder.js +21 -8
- package/dist/cli/chat/startupInfo.d.ts +1 -0
- package/dist/cli/chat/startupInfo.js +11 -0
- 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 +645 -0
- package/dist/cli/commands/chat.d.ts +1 -0
- package/dist/cli/commands/chat.js +246 -779
- 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 +4 -3
- package/dist/cli/commands/commands.js +12 -13
- 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 +36 -9
- package/dist/cli/commands/logsCommand.js +8 -28
- package/dist/cli/commands/mcpWizard.js +24 -2
- package/dist/cli/commands/modelCommand.js +1 -1
- package/dist/cli/commands/providerWizard.d.ts +1 -0
- package/dist/cli/commands/providerWizard.js +31 -5
- package/dist/cli/commands/runCommand.d.ts +1 -0
- package/dist/cli/commands/runCommand.js +32 -20
- package/dist/cli/commands/sessionPicker.d.ts +9 -0
- package/dist/cli/commands/sessionPicker.js +29 -0
- package/dist/cli/commands/settingsSummary.js +8 -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/idleTimer.d.ts +26 -0
- package/dist/cli/commands/streaming/idleTimer.js +24 -0
- package/dist/cli/commands/streaming/toolGroupRenderer.d.ts +2 -0
- package/dist/cli/commands/streaming/toolGroupRenderer.js +4 -2
- package/dist/cli/commands/streaming/turnOutcome.d.ts +10 -0
- package/dist/cli/commands/streaming/turnOutcome.js +13 -0
- package/dist/cli/commands/streaming/turnRuntime.js +6 -4
- package/dist/cli/commands/streaming.d.ts +13 -1
- package/dist/cli/commands/streaming.js +104 -44
- package/dist/cli/commands/wizardActions.d.ts +6 -0
- package/dist/cli/commands/wizardActions.js +6 -0
- package/dist/cli/commands/wizardPrompts.js +1 -1
- package/dist/cli/commands/wizardSuggestions.d.ts +8 -0
- package/dist/cli/commands/wizardSuggestions.js +62 -13
- package/dist/cli/commands/wizardTransition.d.ts +37 -0
- package/dist/cli/commands/wizardTransition.js +43 -0
- package/dist/cli/index.js +17 -3
- package/dist/cli/terminalTitle.d.ts +6 -0
- package/dist/cli/terminalTitle.js +36 -0
- package/dist/config/contextFiles.js +6 -3
- package/dist/config/endpointSecurity.d.ts +2 -0
- package/dist/config/endpointSecurity.js +28 -0
- package/dist/config/inputHistory.d.ts +3 -3
- package/dist/config/inputHistory.js +13 -17
- package/dist/config/modelDiscovery.d.ts +20 -0
- package/dist/config/modelDiscovery.js +51 -0
- package/dist/config/privateStorage.d.ts +6 -0
- package/dist/config/privateStorage.js +61 -0
- package/dist/config/providerPresets.d.ts +16 -4
- package/dist/config/providerPresets.js +263 -34
- package/dist/config/providers.d.ts +2 -0
- package/dist/config/providers.js +7 -0
- package/dist/config/settings.d.ts +22 -0
- package/dist/config/settings.js +33 -5
- package/dist/config/skillSettings.d.ts +6 -13
- package/dist/config/skillSettings.js +20 -19
- package/dist/config/updateCheck.js +4 -2
- package/dist/core/agent/budgets.d.ts +26 -0
- package/dist/core/agent/budgets.js +34 -0
- package/dist/core/agent/compaction.js +17 -3
- package/dist/core/agent/contextBudget.d.ts +8 -0
- package/dist/core/agent/contextBudget.js +29 -0
- package/dist/core/agent/errors.js +6 -2
- package/dist/core/agent/events.d.ts +12 -0
- package/dist/core/agent/toolOutputStore.d.ts +8 -0
- package/dist/core/agent/toolOutputStore.js +49 -11
- package/dist/core/agent/workState.d.ts +1 -1
- package/dist/core/agent/workState.js +0 -4
- 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/goal/completionPolicy.d.ts +0 -28
- package/dist/core/goal/completionPolicy.js +0 -88
- package/dist/core/goal/requestClassifier.d.ts +0 -3
- package/dist/core/goal/requestClassifier.js +0 -13
- package/dist/core/io/boundedRead.d.ts +15 -0
- package/dist/core/io/boundedRead.js +144 -0
- package/dist/core/limits/byteBudgets.d.ts +18 -0
- package/dist/core/limits/byteBudgets.js +18 -0
- package/dist/core/limits/textBudgets.d.ts +23 -0
- package/dist/core/limits/textBudgets.js +23 -0
- package/dist/core/log/llmLog.d.ts +10 -0
- package/dist/core/log/llmLog.js +59 -13
- package/dist/core/persistence/orderedFileWriter.d.ts +11 -0
- package/dist/core/persistence/orderedFileWriter.js +29 -0
- package/dist/core/process/backgroundRegistry.d.ts +35 -0
- package/dist/core/process/backgroundRegistry.js +194 -0
- package/dist/core/process/runBoundedProcess.d.ts +30 -0
- package/dist/core/process/runBoundedProcess.js +116 -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 +37 -0
- package/dist/core/session/sessionStore.js +136 -27
- package/dist/core/subagent/contracts.d.ts +116 -0
- package/dist/core/subagent/contracts.js +54 -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 +74 -0
- package/dist/core/subagent/subagentCoordinator.js +134 -0
- package/dist/core/subagent/subagentRunner.d.ts +211 -145
- package/dist/core/subagent/subagentRunner.js +228 -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 +20 -29
- package/dist/llm/client.js +33 -29
- package/dist/llm/hazeTools.d.ts +2396 -67
- package/dist/llm/hazeTools.js +50 -37
- package/dist/llm/lsp.d.ts +23 -3
- package/dist/llm/lsp.js +73 -16
- package/dist/llm/lspTools.d.ts +96 -48
- package/dist/llm/mcp.d.ts +1 -1
- package/dist/llm/mcp.js +65 -16
- package/dist/llm/requestContext.d.ts +23 -1
- package/dist/llm/requestContext.js +50 -7
- package/dist/llm/systemPrompt.d.ts +4 -1
- package/dist/llm/systemPrompt.js +14 -4
- package/dist/llm/toolResultTypes.d.ts +1 -1
- package/dist/llm/tools/bashTool.d.ts +1210 -16
- package/dist/llm/tools/bashTool.js +43 -60
- package/dist/llm/tools/fetchTool.d.ts +26 -26
- package/dist/llm/tools/fetchTool.js +1 -1
- package/dist/llm/tools/fileToolShared.d.ts +2 -1
- package/dist/llm/tools/fileToolShared.js +5 -5
- package/dist/llm/tools/grepRunner.d.ts +20 -0
- package/dist/llm/tools/grepRunner.js +66 -0
- 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/toolContext.d.ts +8 -0
- package/dist/llm/tools/toolContext.js +22 -11
- package/dist/llm/tools/workspaceFile.d.ts +9 -1
- package/dist/llm/tools/workspaceFile.js +33 -4
- package/dist/llm/webFetch.js +24 -11
- 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/SkillLoader.js +17 -5
- package/dist/skills/SkillRegistry.d.ts +3 -2
- package/dist/skills/SkillRegistry.js +53 -10
- 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 +11 -1
- package/dist/ui/components/TextInput.d.ts +5 -2
- package/dist/ui/components/TextInput.js +76 -8
- package/dist/utils/format.d.ts +2 -0
- package/dist/utils/format.js +8 -0
- package/dist/utils/fs.d.ts +0 -1
- package/dist/utils/fs.js +0 -4
- package/dist/utils/openPath.d.ts +2 -0
- package/dist/utils/openPath.js +9 -0
- package/dist/utils/path.d.ts +2 -0
- package/dist/utils/path.js +9 -4
- package/package.json +1 -1
|
@@ -4,10 +4,8 @@ import { EMPTY_TOKEN_USAGE, accumulateTokenUsage } from '../chat/turnState.js';
|
|
|
4
4
|
import { readSettings } from '../../config/settings.js';
|
|
5
5
|
import { activeModel, modelSelector, resolveModelSelector } from '../../config/providers.js';
|
|
6
6
|
import { createLog, endLog } from '../../core/log/llmLog.js';
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
process.stderr.write(`[haze] ${line}\n`);
|
|
10
|
-
}
|
|
7
|
+
import { findSession, restoreSessionState } from '../../core/session/sessionStore.js';
|
|
8
|
+
import { teardownBackgroundProcesses } from '../../core/process/backgroundRegistry.js';
|
|
11
9
|
function pinnedUsage(usage) {
|
|
12
10
|
// Normalize every field to a number: TokenUsage seeds most fields to 0 but
|
|
13
11
|
// inputTokens/outputTokens may be undefined until the first report. A uniform ?? 0
|
|
@@ -73,14 +71,30 @@ async function resolveModelOrError(modelOverride) {
|
|
|
73
71
|
return undefined;
|
|
74
72
|
}
|
|
75
73
|
export async function runHeadless(options) {
|
|
74
|
+
const resumed = options.resumeSessionId ? await findSession(options.resumeSessionId) : undefined;
|
|
75
|
+
if (options.resumeSessionId && !resumed) {
|
|
76
|
+
process.stderr.write(`No session named ${options.resumeSessionId} exists for this workspace.\n`);
|
|
77
|
+
return 1;
|
|
78
|
+
}
|
|
76
79
|
const modelError = await resolveModelOrError(options.modelOverride);
|
|
77
80
|
if (modelError) {
|
|
78
81
|
process.stderr.write(`${modelError}\n`);
|
|
79
82
|
return 1;
|
|
80
83
|
}
|
|
84
|
+
// stderr keeps stdout clean for --output json/stream-json consumers.
|
|
85
|
+
const debugLog = (line) => {
|
|
86
|
+
if (options.debug)
|
|
87
|
+
process.stderr.write(`[haze] ${line}\n`);
|
|
88
|
+
};
|
|
81
89
|
const contextFiles = await readContextFiles(process.cwd());
|
|
82
90
|
const session = { start: new Date(), cwd: process.cwd() };
|
|
83
91
|
let conversation = [];
|
|
92
|
+
if (resumed) {
|
|
93
|
+
const restored = await restoreSessionState(resumed);
|
|
94
|
+
conversation = restored.messages;
|
|
95
|
+
for (const error of restored.parseErrors)
|
|
96
|
+
process.stderr.write(`Session parse error: ${error}\n`);
|
|
97
|
+
}
|
|
84
98
|
// Assistant text is delivered in two stages by runAgentTurn: an initial streaming
|
|
85
99
|
// `addMessage`, then a finalizing `updateMessage` with the complete text. We key
|
|
86
100
|
// segments by id and patch them on update so finalized (and multi-segment) text is captured.
|
|
@@ -90,19 +104,8 @@ export async function runHeadless(options) {
|
|
|
90
104
|
let log;
|
|
91
105
|
if (options.debug)
|
|
92
106
|
log = await createLog();
|
|
93
|
-
let emittedTurnStart = false;
|
|
94
107
|
const emitStreamEvent = options.output === 'stream-json'
|
|
95
108
|
? (event) => {
|
|
96
|
-
// runAgentTurn emits nested turn_start/turn_end pairs for retries; expose one clean
|
|
97
|
-
// headless turn and emit the authoritative turn_end after the run settles.
|
|
98
|
-
if (event.type === 'turn_start') {
|
|
99
|
-
if (emittedTurnStart)
|
|
100
|
-
return;
|
|
101
|
-
emittedTurnStart = true;
|
|
102
|
-
}
|
|
103
|
-
else if (event.type === 'turn_end') {
|
|
104
|
-
return;
|
|
105
|
-
}
|
|
106
109
|
const headlessEvent = toHeadlessStreamEvent(event);
|
|
107
110
|
if (headlessEvent)
|
|
108
111
|
writeNdjson(headlessEvent);
|
|
@@ -127,7 +130,7 @@ export async function runHeadless(options) {
|
|
|
127
130
|
},
|
|
128
131
|
setBusy: () => undefined,
|
|
129
132
|
setBusyLabel: () => undefined,
|
|
130
|
-
debugLog
|
|
133
|
+
debugLog,
|
|
131
134
|
getConversation: () => conversation,
|
|
132
135
|
getLastAssistantText: () => lastAssistantText,
|
|
133
136
|
setLastAssistantText: (text) => {
|
|
@@ -141,6 +144,8 @@ export async function runHeadless(options) {
|
|
|
141
144
|
};
|
|
142
145
|
let status;
|
|
143
146
|
let result;
|
|
147
|
+
let persistenceError;
|
|
148
|
+
let backgroundTeardownError;
|
|
144
149
|
try {
|
|
145
150
|
({ status } = await runAgentTurn(options.prompt, options.prompt, contextFiles, callbacks, 0, false, false, session, options.modelOverride));
|
|
146
151
|
result = segments.filter((s) => !s.hidden && s.text).map((s) => s.text).join('\n');
|
|
@@ -150,13 +155,20 @@ export async function runHeadless(options) {
|
|
|
150
155
|
result = error instanceof Error ? error.message : String(error);
|
|
151
156
|
}
|
|
152
157
|
finally {
|
|
158
|
+
await teardownBackgroundProcesses().catch(error => {
|
|
159
|
+
backgroundTeardownError = error instanceof Error ? error.message : String(error);
|
|
160
|
+
});
|
|
153
161
|
if (log)
|
|
154
|
-
await endLog(log).catch(
|
|
162
|
+
await endLog(log).catch(error => {
|
|
163
|
+
persistenceError = error instanceof Error ? error.message : String(error);
|
|
164
|
+
});
|
|
155
165
|
}
|
|
166
|
+
if (backgroundTeardownError)
|
|
167
|
+
process.stderr.write(`haze background teardown warning: ${backgroundTeardownError}\n`);
|
|
168
|
+
if (persistenceError)
|
|
169
|
+
process.stderr.write(`haze persistence warning: ${persistenceError}\n`);
|
|
156
170
|
if (options.output === 'json' || options.output === 'stream-json') {
|
|
157
|
-
|
|
158
|
-
writeNdjson({ type: 'turn_end', request: options.prompt, status, at: new Date().toISOString() });
|
|
159
|
-
// For stream-json the agent events have already streamed above; this is the terminal line.
|
|
171
|
+
// For stream-json the authoritative agent events have already streamed above; this is the terminal line.
|
|
160
172
|
// It is byte-identical to the --output json envelope, so harnesses can parse the last line the same way.
|
|
161
173
|
writeNdjson({ type: 'result', status, result, usage: pinnedUsage(usage) });
|
|
162
174
|
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { SessionSummary } from '../../core/session/sessionStore.js';
|
|
2
|
+
import type { TextInputSuggestion } from '../../ui/components/TextInput.js';
|
|
3
|
+
export declare const MAX_SESSION_PICKER_RESULTS = 20;
|
|
4
|
+
export declare const SESSION_ACTIONS: {
|
|
5
|
+
readonly resume: "resume";
|
|
6
|
+
readonly fork: "fork";
|
|
7
|
+
};
|
|
8
|
+
export declare function sessionSuggestions(sessions: SessionSummary[]): TextInputSuggestion[];
|
|
9
|
+
export declare function sessionActionSuggestions(): TextInputSuggestion[];
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export const MAX_SESSION_PICKER_RESULTS = 20;
|
|
2
|
+
export const SESSION_ACTIONS = { resume: 'resume', fork: 'fork' };
|
|
3
|
+
function formatDate(value) {
|
|
4
|
+
const date = new Date(value);
|
|
5
|
+
if (Number.isNaN(date.getTime()))
|
|
6
|
+
return value;
|
|
7
|
+
const pad = (part) => String(part).padStart(2, '0');
|
|
8
|
+
return `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())} ${pad(date.getHours())}:${pad(date.getMinutes())}`;
|
|
9
|
+
}
|
|
10
|
+
function formatBytes(bytes) {
|
|
11
|
+
if (bytes < 1024)
|
|
12
|
+
return `${bytes} B`;
|
|
13
|
+
if (bytes < 1024 * 1024)
|
|
14
|
+
return `${Math.ceil(bytes / 1024)} KB`;
|
|
15
|
+
return `${(bytes / (1024 * 1024)).toFixed(1)} MB`;
|
|
16
|
+
}
|
|
17
|
+
export function sessionSuggestions(sessions) {
|
|
18
|
+
return sessions.slice(0, MAX_SESSION_PICKER_RESULTS).map(session => ({
|
|
19
|
+
value: session.id,
|
|
20
|
+
description: `${formatDate(session.lastActivityAt)} · ${session.messageCount} msg${session.messageCount === 1 ? '' : 's'} · ${formatBytes(session.sizeBytes)}${session.lastStatus ? ` · ${session.lastStatus}` : ''}${session.parseErrors.length ? ' · ⚠ malformed lines' : ''}${session.firstUserPreview ? ` · “${session.firstUserPreview}”` : ''}`,
|
|
21
|
+
kind: 'session',
|
|
22
|
+
}));
|
|
23
|
+
}
|
|
24
|
+
export function sessionActionSuggestions() {
|
|
25
|
+
return [
|
|
26
|
+
{ value: SESSION_ACTIONS.resume, description: 'Resume this session', kind: 'session' },
|
|
27
|
+
{ value: SESSION_ACTIONS.fork, description: 'Start a new session from its latest snapshot', kind: 'session' },
|
|
28
|
+
];
|
|
29
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { contextFileDiagnostics, summarizeContextDiagnostics } from '../../config/contextFiles.js';
|
|
2
2
|
import { configuredLspServers } from '../../config/lspSettings.js';
|
|
3
3
|
import { configuredMcpServers } from '../../config/mcpSettings.js';
|
|
4
|
-
import { activeProvider as resolveActiveProvider, configuredProviders, providerHasKey } from '../../config/providers.js';
|
|
4
|
+
import { activeProvider as resolveActiveProvider, configuredProviders, providerHasKey, providerImageCapable } from '../../config/providers.js';
|
|
5
5
|
import { isSkillEnabled } from '../../config/skillSettings.js';
|
|
6
6
|
import { loadSkillRegistry } from '../../skills/SkillRegistry.js';
|
|
7
7
|
export async function formatSettingsSummary(settings, contextFiles) {
|
|
@@ -21,18 +21,22 @@ export async function formatSettingsSummary(settings, contextFiles) {
|
|
|
21
21
|
notes.push(`${summary.duplicateGroups.length} duplicate group${summary.duplicateGroups.length === 1 ? '' : 's'} (${duplicateTotal} file${duplicateTotal === 1 ? '' : 's'} with identical content)`);
|
|
22
22
|
}
|
|
23
23
|
const lspServers = configuredLspServers(settings);
|
|
24
|
-
const
|
|
25
|
-
const
|
|
24
|
+
const skillRegistry = await loadSkillRegistry();
|
|
25
|
+
const installedSkills = skillRegistry.candidates ?? [...skillRegistry.skills.values()];
|
|
26
|
+
const skillNames = installedSkills.map(skill => `${skill.name}${isSkillEnabled(settings, skill.name, skill.source) ? '' : ' (disabled)'} · ${skill.source}`).join(', ');
|
|
27
|
+
const projectSkillNames = installedSkills.filter(skill => skill.source === 'project').map(skill => skill.name).join(', ');
|
|
26
28
|
const lines = [
|
|
27
29
|
`Provider: ${activeProvider?.name ?? 'not configured'}`,
|
|
28
30
|
`Model: ${settings.model ?? 'not set'}`,
|
|
29
31
|
`Base URL: ${activeProvider?.url ?? settings.baseURL ?? 'not configured'}`,
|
|
30
32
|
`API key: ${activeProvider && providerHasKey(settings, activeProvider) ? 'saved' : 'missing'}`,
|
|
31
|
-
`Configured providers: ${providers.map(provider => provider.name).join(', ') || 'none'}`,
|
|
33
|
+
`Configured providers: ${providers.map(provider => `${provider.name}${providerImageCapable(provider) ? ' (images)' : ''}`).join(', ') || 'none'}`,
|
|
32
34
|
`LSP servers: ${lspServers.map(server => `${server.name}${server.enabled === false ? ' (disabled)' : ''}`).join(', ') || 'none'}`,
|
|
33
35
|
`MCP servers: ${configuredMcpServers(settings).map(server => `${server.name}${server.enabled === false ? ' (disabled)' : ''}`).join(', ') || 'none'}`,
|
|
34
36
|
`Skills: ${skillNames || 'none'}`,
|
|
37
|
+
...(skillRegistry.errors.length ? [`Skill load errors: ${skillRegistry.errors.map(error => `${error.directory}: ${error.message}`).join('; ')}`] : []),
|
|
35
38
|
`Context files: ${contextFiles.length ? `${contextFiles.map(file => file.path).join(', ')} (~${contextTokens} tokens)` : 'none'}`,
|
|
39
|
+
`Project skills (repo context): ${projectSkillNames || 'none'}`,
|
|
36
40
|
];
|
|
37
41
|
if (notes.length > 0)
|
|
38
42
|
lines.push(`Context note: ${notes.join('; ')}`);
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { removeSkillSetting } from '../../config/skillSettings.js';
|
|
2
2
|
import { isYesConfirmation } from './wizardInput.js';
|
|
3
|
+
import { findSelectedSkill } from './skillWizard.js';
|
|
3
4
|
export function skillConfirmRemoveResult(settings, skills, selectedName, value) {
|
|
4
5
|
if (!selectedName)
|
|
5
6
|
return { mode: 'chat' };
|
|
6
7
|
if (!isYesConfirmation(value))
|
|
7
8
|
return { mode: 'chat', selectedName: undefined, message: 'Cancelled. Skill not removed.' };
|
|
8
|
-
const skill = skills
|
|
9
|
+
const skill = findSelectedSkill(skills, selectedName);
|
|
9
10
|
if (!skill)
|
|
10
11
|
return { mode: 'chat', selectedName: undefined, message: `Skill ${selectedName} not found.` };
|
|
11
12
|
return {
|
|
@@ -13,7 +14,7 @@ export function skillConfirmRemoveResult(settings, skills, selectedName, value)
|
|
|
13
14
|
selectedName: undefined,
|
|
14
15
|
skill,
|
|
15
16
|
removedDir: skill.dir,
|
|
16
|
-
settingsPatch: { skills: removeSkillSetting(settings,
|
|
17
|
-
message: `Removed skill ${
|
|
17
|
+
settingsPatch: { skills: removeSkillSetting(settings, skill.name, skill.source) },
|
|
18
|
+
message: skill.source === 'global' ? `Removed skill ${skill.name}.` : `Removed project skill ${skill.name}.`,
|
|
18
19
|
};
|
|
19
20
|
}
|
|
@@ -7,6 +7,8 @@ export type SkillWizardResult = {
|
|
|
7
7
|
settingsPatch?: Partial<HazeSettings>;
|
|
8
8
|
clearDraft?: boolean;
|
|
9
9
|
};
|
|
10
|
+
export declare function skillPickerValue(skill: LoadedSkill): string;
|
|
11
|
+
export declare function findSelectedSkill(skills: LoadedSkill[], selection: string | undefined): LoadedSkill | undefined;
|
|
10
12
|
export declare function selectSkillResult(skills: LoadedSkill[], name: string): SkillWizardResult;
|
|
11
13
|
export declare function skillInfoMessage(settings: HazeSettings, skill: LoadedSkill): string;
|
|
12
14
|
export declare function selectSkillActionResult(settings: HazeSettings, skills: LoadedSkill[], selectedName: string | undefined, action: string): SkillWizardResult & {
|
|
@@ -1,38 +1,48 @@
|
|
|
1
1
|
import { isSkillEnabled, setSkillEnabled } from '../../config/skillSettings.js';
|
|
2
2
|
import { COMMON_ACTIONS, SKILL_ACTIONS, SKILL_CHOICES } from './wizardActions.js';
|
|
3
|
+
export function skillPickerValue(skill) {
|
|
4
|
+
return `${skill.name} · ${skill.source}`;
|
|
5
|
+
}
|
|
6
|
+
export function findSelectedSkill(skills, selection) {
|
|
7
|
+
if (!selection)
|
|
8
|
+
return undefined;
|
|
9
|
+
return skills.find(skill => skillPickerValue(skill) === selection)
|
|
10
|
+
?? skills.find(skill => skill.name === selection);
|
|
11
|
+
}
|
|
3
12
|
export function selectSkillResult(skills, name) {
|
|
4
13
|
if (name === SKILL_CHOICES.addSkill)
|
|
5
14
|
return { mode: 'skillsAddName', clearDraft: true, message: 'Name the skill (kebab-case, e.g. security-review). ESC cancels.' };
|
|
6
|
-
const skill = skills
|
|
15
|
+
const skill = findSelectedSkill(skills, name);
|
|
7
16
|
if (!skill)
|
|
8
17
|
return { mode: 'chat', message: `No skill named ${name}. Use /skills and choose add skill.` };
|
|
9
|
-
return { mode: 'skillsAction', selectedName: skill.name, message: `${skill.name}: choose an action.` };
|
|
18
|
+
return { mode: 'skillsAction', selectedName: name === skill.name ? skill.name : skillPickerValue(skill), message: `${skill.name} · ${skill.source}: choose an action.` };
|
|
10
19
|
}
|
|
11
20
|
export function skillInfoMessage(settings, skill) {
|
|
12
21
|
return [
|
|
13
22
|
`${skill.name}`,
|
|
14
23
|
skill.description,
|
|
15
24
|
'',
|
|
25
|
+
`Source: ${skill.source}`,
|
|
16
26
|
`References: ${skill.references.length}`,
|
|
17
27
|
`Path: ${skill.dir}`,
|
|
18
|
-
`State: ${isSkillEnabled(settings, skill.name) ? 'enabled' : 'disabled'}`,
|
|
28
|
+
`State: ${isSkillEnabled(settings, skill.name, skill.source) ? 'enabled' : 'disabled'}`,
|
|
19
29
|
].join('\n');
|
|
20
30
|
}
|
|
21
31
|
export function selectSkillActionResult(settings, skills, selectedName, action) {
|
|
22
32
|
if (!selectedName)
|
|
23
33
|
return { mode: 'skills' };
|
|
24
|
-
const skill = skills
|
|
34
|
+
const skill = findSelectedSkill(skills, selectedName);
|
|
25
35
|
if (!skill)
|
|
26
36
|
return { mode: 'chat', selectedName: undefined, message: `Skill ${selectedName} not found.` };
|
|
27
37
|
if (action === COMMON_ACTIONS.enable || action === COMMON_ACTIONS.disable) {
|
|
28
38
|
const enabled = action === COMMON_ACTIONS.enable;
|
|
29
|
-
return { mode: 'chat', selectedName: undefined, settingsPatch: { skills: setSkillEnabled(settings,
|
|
39
|
+
return { mode: 'chat', selectedName: undefined, settingsPatch: { skills: setSkillEnabled(settings, skill.name, enabled, skill.source) }, message: `Skill ${skill.name} (${skill.source}) ${enabled ? 'enabled' : 'disabled'}.`, skill };
|
|
30
40
|
}
|
|
31
41
|
if (action === SKILL_ACTIONS.showInfo)
|
|
32
42
|
return { message: skillInfoMessage(settings, skill), skill };
|
|
33
43
|
if (action === SKILL_ACTIONS.validate)
|
|
34
44
|
return { validate: true, skill };
|
|
35
45
|
if (action === SKILL_ACTIONS.removeSkill)
|
|
36
|
-
return { mode: 'skillsConfirmRemove', message: `Remove skill ${
|
|
46
|
+
return { mode: 'skillsConfirmRemove', message: `Remove ${skill.source} skill ${skill.name}? This deletes ${skill.dir}. Type "yes" to confirm. Esc to cancel.`, skill };
|
|
37
47
|
return { message: `Unknown skill action: ${action}`, skill };
|
|
38
48
|
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* An idle timer for the main agent turn.
|
|
3
|
+
*
|
|
4
|
+
* The turn is considered "idle" (and aborted) after `timeoutMs` with no stream
|
|
5
|
+
* activity — UNLESS a tool call is currently executing (`isBusy()` returns
|
|
6
|
+
* true). Concurrent subagents can run for many minutes while emitting no stream
|
|
7
|
+
* parts; that is legitimate work, not a dead stream, so the timer defers (rearms)
|
|
8
|
+
* while any tool is in flight. This prevents a long subagent wave from being
|
|
9
|
+
* mistaken for a hung turn.
|
|
10
|
+
*
|
|
11
|
+
* Note: there is intentionally no upper bound on how long a single tool may run
|
|
12
|
+
* while in flight — a genuinely hung tool would defer indefinitely. A per-tool
|
|
13
|
+
* hard timeout is a separate concern; the idle timer only guards against a turn
|
|
14
|
+
* that is producing no model output AND doing no tool work.
|
|
15
|
+
*/
|
|
16
|
+
export interface IdleTimer {
|
|
17
|
+
/** Clear any pending deadline and rearm it for a fresh idle window. */
|
|
18
|
+
reset: () => void;
|
|
19
|
+
/** Cancel the pending deadline without rearming. */
|
|
20
|
+
clear: () => void;
|
|
21
|
+
}
|
|
22
|
+
export declare function createIdleTimer(input: {
|
|
23
|
+
timeoutMs: number;
|
|
24
|
+
isBusy: () => boolean;
|
|
25
|
+
onTimeout: () => void;
|
|
26
|
+
}): IdleTimer;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export function createIdleTimer(input) {
|
|
2
|
+
const { timeoutMs, isBusy, onTimeout } = input;
|
|
3
|
+
let timer;
|
|
4
|
+
const fire = () => {
|
|
5
|
+
if (isBusy()) {
|
|
6
|
+
// Tools are executing — that is activity. Defer by rearming.
|
|
7
|
+
timer = setTimeout(fire, timeoutMs);
|
|
8
|
+
return;
|
|
9
|
+
}
|
|
10
|
+
onTimeout();
|
|
11
|
+
};
|
|
12
|
+
return {
|
|
13
|
+
reset: () => {
|
|
14
|
+
if (timer)
|
|
15
|
+
clearTimeout(timer);
|
|
16
|
+
timer = setTimeout(fire, timeoutMs);
|
|
17
|
+
},
|
|
18
|
+
clear: () => {
|
|
19
|
+
if (timer)
|
|
20
|
+
clearTimeout(timer);
|
|
21
|
+
timer = undefined;
|
|
22
|
+
},
|
|
23
|
+
};
|
|
24
|
+
}
|
|
@@ -27,10 +27,12 @@ export interface ToolGroupRendererDeps {
|
|
|
27
27
|
role: 'tool';
|
|
28
28
|
text: string;
|
|
29
29
|
streaming: boolean;
|
|
30
|
+
toolCount: number;
|
|
30
31
|
}) => void;
|
|
31
32
|
updateMessage: (id: string, update: {
|
|
32
33
|
text?: string;
|
|
33
34
|
streaming?: boolean;
|
|
35
|
+
toolCount?: number;
|
|
34
36
|
}) => void;
|
|
35
37
|
debugLog: (line: string) => void;
|
|
36
38
|
onEvent?: AgentEventSink;
|
|
@@ -31,14 +31,16 @@ export function createToolGroupRenderer(deps) {
|
|
|
31
31
|
};
|
|
32
32
|
const updateToolGroup = (streaming = true, group = toolGroup) => {
|
|
33
33
|
const text = renderToolGroup(group);
|
|
34
|
+
// toolCount is carried structurally so metrics never depend on the rendered
|
|
35
|
+
// caption/row format (CR-015).
|
|
34
36
|
if (!group.started) {
|
|
35
37
|
group.started = true;
|
|
36
38
|
group.finalized = !streaming;
|
|
37
|
-
deps.addMessage({ id: group.id, role: 'tool', text, streaming });
|
|
39
|
+
deps.addMessage({ id: group.id, role: 'tool', text, streaming, toolCount: group.items.length });
|
|
38
40
|
}
|
|
39
41
|
else {
|
|
40
42
|
group.finalized = !streaming;
|
|
41
|
-
deps.updateMessage(group.id, { text, streaming });
|
|
43
|
+
deps.updateMessage(group.id, { text, streaming, toolCount: group.items.length });
|
|
42
44
|
}
|
|
43
45
|
};
|
|
44
46
|
const finalizeToolGroup = (group = toolGroup) => {
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { TurnStatus } from '../streaming.js';
|
|
2
|
+
export declare function terminalTurnStatus(input: {
|
|
3
|
+
aborted: boolean;
|
|
4
|
+
error?: unknown;
|
|
5
|
+
assistantText: string;
|
|
6
|
+
sawToolCall: boolean;
|
|
7
|
+
lastToolOk?: boolean;
|
|
8
|
+
finishReason?: string;
|
|
9
|
+
budgetReached?: boolean;
|
|
10
|
+
}): TurnStatus;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export function terminalTurnStatus(input) {
|
|
2
|
+
if (input.aborted)
|
|
3
|
+
return 'aborted';
|
|
4
|
+
if (input.error)
|
|
5
|
+
return 'failed';
|
|
6
|
+
if (input.lastToolOk === false)
|
|
7
|
+
return 'failed';
|
|
8
|
+
if (input.budgetReached || input.finishReason === 'length' || input.finishReason === 'error')
|
|
9
|
+
return 'failed';
|
|
10
|
+
if (input.sawToolCall && input.assistantText.trim().length === 0)
|
|
11
|
+
return 'failed';
|
|
12
|
+
return input.assistantText.trim().length > 0 ? 'complete' : 'failed';
|
|
13
|
+
}
|
|
@@ -58,11 +58,13 @@ export function stepCacheMetrics(usage) {
|
|
|
58
58
|
};
|
|
59
59
|
}
|
|
60
60
|
export function subagentTokenEstimate(output) {
|
|
61
|
-
if (typeof output !== 'object' || output == null
|
|
61
|
+
if (typeof output !== 'object' || output == null)
|
|
62
62
|
return undefined;
|
|
63
|
-
const
|
|
64
|
-
const
|
|
65
|
-
const
|
|
63
|
+
const value = output;
|
|
64
|
+
const inputValue = value.telemetry?.usage?.inputTokens ?? value.tokens?.in;
|
|
65
|
+
const outputValue = value.telemetry?.usage?.outputTokens ?? value.tokens?.out;
|
|
66
|
+
const input = typeof inputValue === 'number' ? inputValue : 0;
|
|
67
|
+
const outputTokens = typeof outputValue === 'number' ? outputValue : 0;
|
|
66
68
|
return input > 0 || outputTokens > 0 ? { input, output: outputTokens } : undefined;
|
|
67
69
|
}
|
|
68
70
|
export function rememberContextFilesFromToolOutput(activeContextFiles, output) {
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import { type ModelMessage } from 'ai';
|
|
2
2
|
import type { LlmLog } from '../../core/log/llmLog.js';
|
|
3
|
+
import { type SubagentOverrides } from '../../llm/requestContext.js';
|
|
3
4
|
import { type PromptSession } from '../../llm/systemPrompt.js';
|
|
4
5
|
import type { ContextFile } from '../../config/contextFiles.js';
|
|
5
6
|
import { type AgentEventSink } from '../../core/agent/events.js';
|
|
7
|
+
import { type ImageAttachment } from '../../core/attachments/imageAttachments.js';
|
|
8
|
+
import { type BlessedPath } from '../../core/attachments/readBlessings.js';
|
|
6
9
|
export { uniqueRepeatedToolNames, toolOnlyStepCount } from '../../core/agent/turnPolicy.js';
|
|
7
10
|
import type { WorkState } from '../../core/agent/workState.js';
|
|
8
11
|
import { type TokenUsage } from './streaming/turnRuntime.js';
|
|
@@ -17,12 +20,21 @@ export type Message = {
|
|
|
17
20
|
finishedAt?: number;
|
|
18
21
|
tokensPerSecond?: number;
|
|
19
22
|
displayOrder?: number;
|
|
23
|
+
toolCount?: number;
|
|
20
24
|
};
|
|
21
25
|
export type TurnStatus = 'complete' | 'aborted' | 'failed';
|
|
22
26
|
/** Authoritative outcome of a turn, so callers (esp. headless/CI) need not sniff message text. */
|
|
23
27
|
export interface TurnResult {
|
|
24
28
|
status: TurnStatus;
|
|
25
29
|
}
|
|
30
|
+
export interface TurnExecutionOptions {
|
|
31
|
+
ephemeralControl?: string;
|
|
32
|
+
subagentOverrides?: SubagentOverrides;
|
|
33
|
+
/** User-attached images for this turn (F03); only the first attempt carries them. */
|
|
34
|
+
attachments?: readonly ImageAttachment[];
|
|
35
|
+
/** User-mentioned paths whose reads may escape workspace confinement this turn. */
|
|
36
|
+
blessedPaths?: readonly BlessedPath[];
|
|
37
|
+
}
|
|
26
38
|
export interface StreamCallbacks {
|
|
27
39
|
addMessage: (msg: Message) => void;
|
|
28
40
|
updateMessage: (id: string, update: Partial<Message>) => void;
|
|
@@ -43,4 +55,4 @@ export interface StreamCallbacks {
|
|
|
43
55
|
log?: LlmLog;
|
|
44
56
|
contextFileSignatures?: Map<string, string>;
|
|
45
57
|
}
|
|
46
|
-
export declare function runAgentTurn(value: string, displayValue: string | undefined, contextFiles: ContextFile[], callbacks: StreamCallbacks, retryAttempt?: number, retryingExistingRequest?: boolean, contextOverflowRecovered?: boolean, session?: PromptSession, modelOverride?: string): Promise<TurnResult>;
|
|
58
|
+
export declare function runAgentTurn(value: string, displayValue: string | undefined, contextFiles: ContextFile[], callbacks: StreamCallbacks, retryAttempt?: number, retryingExistingRequest?: boolean, contextOverflowRecovered?: boolean, session?: PromptSession, modelOverride?: string, turnOptions?: TurnExecutionOptions): Promise<TurnResult>;
|