@denizokcu/haze 0.2.0 → 0.4.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 +41 -0
- package/README.md +38 -22
- package/dist/cli/commands/chat.d.ts +1 -1
- package/dist/cli/commands/chat.js +411 -74
- package/dist/cli/commands/commands.js +122 -54
- package/dist/cli/commands/formatters.d.ts +2 -0
- package/dist/cli/commands/formatters.js +34 -0
- package/dist/cli/commands/streaming.d.ts +36 -1
- package/dist/cli/commands/streaming.js +312 -103
- package/dist/cli/contextReport.d.ts +1 -0
- package/dist/cli/contextReport.js +47 -0
- package/dist/config/contextFiles.d.ts +25 -0
- package/dist/config/contextFiles.js +53 -0
- package/dist/config/providerPresets.d.ts +23 -0
- package/dist/config/providerPresets.js +230 -0
- package/dist/core/agent/compaction.d.ts +3 -0
- package/dist/core/agent/compaction.js +23 -3
- package/dist/core/agent/contextBudget.d.ts +33 -0
- package/dist/core/agent/contextBudget.js +88 -0
- package/dist/core/agent/requestAssembly.d.ts +22 -0
- package/dist/core/agent/requestAssembly.js +146 -0
- package/dist/core/agent/toolOutputStore.d.ts +11 -0
- package/dist/core/agent/toolOutputStore.js +33 -0
- package/dist/core/agent/workState.d.ts +38 -0
- package/dist/core/agent/workState.js +89 -0
- package/dist/core/goal/completionPolicy.js +1 -1
- package/dist/core/goal/sessionGoal.d.ts +2 -0
- package/dist/core/goal/sessionGoal.js +8 -1
- package/dist/core/log/llmLog.d.ts +68 -0
- package/dist/core/log/llmLog.js +55 -0
- package/dist/core/session/sessionStore.d.ts +6 -0
- package/dist/core/session/sessionStore.js +5 -0
- package/dist/core/subagent/subagentRunner.d.ts +4 -1
- package/dist/core/subagent/subagentRunner.js +5 -15
- package/dist/core/tasks/taskStorage.d.ts +13 -0
- package/dist/core/tasks/taskStorage.js +29 -0
- package/dist/core/validation/outputParser.js +15 -2
- package/dist/llm/client.d.ts +39 -0
- package/dist/llm/client.js +46 -2
- package/dist/llm/hazeTools.d.ts +53 -12
- package/dist/llm/hazeTools.js +170 -46
- package/dist/llm/systemPrompt.d.ts +6 -1
- package/dist/llm/systemPrompt.js +42 -79
- package/dist/skills/builder/SkillBuilder.d.ts +16 -2
- package/dist/skills/builder/SkillBuilder.js +68 -65
- package/dist/skills/skillTools.d.ts +2 -19
- package/dist/skills/skillTools.js +28 -19
- package/dist/ui/components/TextInput.d.ts +2 -1
- package/dist/ui/components/TextInput.js +6 -2
- package/package.json +2 -1
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import fs from 'fs-extra';
|
|
2
2
|
import path from 'node:path';
|
|
3
3
|
import { buildInitPrompt } from '../../llm/initPrompt.js';
|
|
4
|
+
import { contextFileDiagnostics, summarizeContextDiagnostics } from '../../config/contextFiles.js';
|
|
4
5
|
import { activeProvider, configuredProviders, modelSelector, providerHasKey, resolveModelSelector, upsertProvider } from '../../config/providers.js';
|
|
6
|
+
import { clearTasks } from '../../core/tasks/taskStorage.js';
|
|
7
|
+
import { listLogs, readLogEntries } from '../../core/log/llmLog.js';
|
|
5
8
|
function skillHelp() {
|
|
6
9
|
return [
|
|
7
10
|
'Skill commands:',
|
|
8
|
-
'/create-skill
|
|
9
|
-
'
|
|
10
|
-
'/list-skills',
|
|
11
|
-
' List installed skills.',
|
|
11
|
+
'/create-skill',
|
|
12
|
+
' Launch the 3-step skill wizard (name -> role -> description). Creates a Markdown skill in ~/.haze/skills.',
|
|
12
13
|
'/skill-info <name>',
|
|
13
14
|
' Show a skill description and path.',
|
|
14
15
|
'/validate-skill <name-or-dir>',
|
|
@@ -22,39 +23,23 @@ async function skillOverview() {
|
|
|
22
23
|
const registry = await loadSkillRegistry();
|
|
23
24
|
const skills = [...registry.skills.values()];
|
|
24
25
|
const installed = skills.length === 0
|
|
25
|
-
? ['Installed skills:', '- None yet. Create one with /create-skill
|
|
26
|
-
: ['Installed skills:', ...skills.map(s => `- /${s.name}
|
|
26
|
+
? ['Installed skills:', '- None yet. Create one with /create-skill.']
|
|
27
|
+
: ['Installed skills:', ...skills.map(s => `- /${s.name} - ${s.description}`)];
|
|
27
28
|
return `${skillHelp()}\n\n${installed.join('\n')}`;
|
|
28
29
|
}
|
|
29
|
-
async function handleSkillCommand(
|
|
30
|
-
|
|
31
|
-
const subcommand = parts[1];
|
|
32
|
-
if (!subcommand || subcommand === 'help') {
|
|
30
|
+
async function handleSkillCommand(sub, args, ctx) {
|
|
31
|
+
if (sub === 'help') {
|
|
33
32
|
ctx.addSystemMessage(await skillOverview());
|
|
34
33
|
return 'handled';
|
|
35
34
|
}
|
|
36
|
-
if (
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
return 'handled';
|
|
41
|
-
}
|
|
42
|
-
const { createSkill } = await import('../../skills/builder/SkillBuilder.js');
|
|
43
|
-
const result = await createSkill(description);
|
|
44
|
-
ctx.addSystemMessage(`Created skill ${result.name} at ${result.file}. Invoke it with /${result.name}. Edit SKILL.md to refine its workflow.`);
|
|
45
|
-
return 'handled';
|
|
46
|
-
}
|
|
47
|
-
if (subcommand === 'list') {
|
|
48
|
-
const { loadSkillRegistry } = await import('../../skills/SkillRegistry.js');
|
|
49
|
-
const registry = await loadSkillRegistry();
|
|
50
|
-
const skills = [...registry.skills.values()];
|
|
51
|
-
ctx.addSystemMessage(skills.length === 0
|
|
52
|
-
? 'No installed skills found. Create one with /create-skill <description>.'
|
|
53
|
-
: ['Installed skills:', ...skills.map(s => `- /${s.name} — ${s.description}`)].join('\n'));
|
|
35
|
+
if (sub === 'create') {
|
|
36
|
+
// Inline args are intentionally ignored — the wizard is the only path.
|
|
37
|
+
ctx.setMode('skillCreateName');
|
|
38
|
+
ctx.addSystemMessage('Skill wizard — step 1/3: Name the skill (kebab-case, e.g. security-review). ESC cancels.');
|
|
54
39
|
return 'handled';
|
|
55
40
|
}
|
|
56
|
-
if (
|
|
57
|
-
const name =
|
|
41
|
+
if (sub === 'info') {
|
|
42
|
+
const name = args.trim();
|
|
58
43
|
if (!name) {
|
|
59
44
|
ctx.addSystemMessage('Usage: /skill-info <name>');
|
|
60
45
|
return 'handled';
|
|
@@ -75,8 +60,8 @@ async function handleSkillCommand(value, ctx) {
|
|
|
75
60
|
].join('\n'));
|
|
76
61
|
return 'handled';
|
|
77
62
|
}
|
|
78
|
-
if (
|
|
79
|
-
const target =
|
|
63
|
+
if (sub === 'validate') {
|
|
64
|
+
const target = args.trim();
|
|
80
65
|
if (!target) {
|
|
81
66
|
ctx.addSystemMessage('Usage: /validate-skill <name-or-dir>');
|
|
82
67
|
return 'handled';
|
|
@@ -89,8 +74,9 @@ async function handleSkillCommand(value, ctx) {
|
|
|
89
74
|
ctx.addSystemMessage(skill ? `Valid: ${skill.name}` : 'No SKILL.md found');
|
|
90
75
|
return 'handled';
|
|
91
76
|
}
|
|
92
|
-
if (
|
|
93
|
-
const
|
|
77
|
+
if (sub === 'remove') {
|
|
78
|
+
const parts = args.split(/\s+/).filter(Boolean);
|
|
79
|
+
const name = parts[0];
|
|
94
80
|
if (!name || !parts.includes('--yes')) {
|
|
95
81
|
ctx.addSystemMessage('Usage: /remove-skill <name> --yes');
|
|
96
82
|
return 'handled';
|
|
@@ -106,7 +92,70 @@ async function handleSkillCommand(value, ctx) {
|
|
|
106
92
|
ctx.addSystemMessage(`Removed ${name} from ${skill.dir}.`);
|
|
107
93
|
return 'handled';
|
|
108
94
|
}
|
|
109
|
-
|
|
95
|
+
return 'handled';
|
|
96
|
+
}
|
|
97
|
+
function formatBytes(bytes) {
|
|
98
|
+
if (bytes < 1024)
|
|
99
|
+
return `${bytes} B`;
|
|
100
|
+
if (bytes < 1024 * 1024)
|
|
101
|
+
return `${(bytes / 1024).toFixed(1)} KB`;
|
|
102
|
+
return `${(bytes / (1024 * 1024)).toFixed(1)} MB`;
|
|
103
|
+
}
|
|
104
|
+
async function handleLogsCommand(args, ctx) {
|
|
105
|
+
const id = args.trim();
|
|
106
|
+
if (!id) {
|
|
107
|
+
// List recent logs
|
|
108
|
+
const logs = await listLogs();
|
|
109
|
+
if (logs.length === 0) {
|
|
110
|
+
ctx.addSystemMessage('No log files found.');
|
|
111
|
+
return 'handled';
|
|
112
|
+
}
|
|
113
|
+
const lines = logs.slice(0, 20).map(log => {
|
|
114
|
+
const date = log.modified.slice(0, 19).replace('T', ' ');
|
|
115
|
+
return ` ${log.id} ${formatBytes(log.size).padStart(8)} ${date}`;
|
|
116
|
+
});
|
|
117
|
+
ctx.addSystemMessage(['Recent logs:', ' ID Size Modified', ...lines].join('\n'));
|
|
118
|
+
return 'handled';
|
|
119
|
+
}
|
|
120
|
+
// Show summary for a specific log
|
|
121
|
+
const entries = await readLogEntries(id);
|
|
122
|
+
if (entries.length === 0) {
|
|
123
|
+
ctx.addSystemMessage(`No log found with id ${id}.`);
|
|
124
|
+
return 'handled';
|
|
125
|
+
}
|
|
126
|
+
const typeCounts = {};
|
|
127
|
+
let totalInput = 0;
|
|
128
|
+
let totalOutput = 0;
|
|
129
|
+
const toolCallCounts = {};
|
|
130
|
+
for (const entry of entries) {
|
|
131
|
+
typeCounts[entry.type] = (typeCounts[entry.type] ?? 0) + 1;
|
|
132
|
+
if (entry.usage) {
|
|
133
|
+
totalInput += entry.usage.inputTokens ?? 0;
|
|
134
|
+
totalOutput += entry.usage.outputTokens ?? 0;
|
|
135
|
+
}
|
|
136
|
+
if (entry.type === 'tool_call' && entry.toolCall) {
|
|
137
|
+
toolCallCounts[entry.toolCall.name] = (toolCallCounts[entry.toolCall.name] ?? 0) + 1;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
const typeLines = Object.entries(typeCounts)
|
|
141
|
+
.sort(([a], [b]) => a.localeCompare(b))
|
|
142
|
+
.map(([type, count]) => ` ${type}: ${count}`);
|
|
143
|
+
const toolLines = Object.entries(toolCallCounts)
|
|
144
|
+
.sort(([, a], [, b]) => b - a)
|
|
145
|
+
.map(([name, count]) => ` ${name}: ${count}`);
|
|
146
|
+
const parts = [
|
|
147
|
+
`Log: ${id}`,
|
|
148
|
+
`Entries: ${entries.length}`,
|
|
149
|
+
'',
|
|
150
|
+
'Entry counts by type:',
|
|
151
|
+
...typeLines,
|
|
152
|
+
'',
|
|
153
|
+
`Total token usage: in=${totalInput} out=${totalOutput}`,
|
|
154
|
+
];
|
|
155
|
+
if (toolLines.length > 0) {
|
|
156
|
+
parts.push('', 'Tool call counts:', ...toolLines);
|
|
157
|
+
}
|
|
158
|
+
ctx.addSystemMessage(parts.join('\n'));
|
|
110
159
|
return 'handled';
|
|
111
160
|
}
|
|
112
161
|
export async function handleSlashCommand(value, ctx) {
|
|
@@ -118,15 +167,15 @@ export async function handleSlashCommand(value, ctx) {
|
|
|
118
167
|
'/help',
|
|
119
168
|
' Show all available slash commands and what they do.',
|
|
120
169
|
'/provider',
|
|
121
|
-
' Choose a provider, then use it
|
|
170
|
+
' Choose a provider, then use it, add/remove models, set API key, or remove it.',
|
|
122
171
|
'/model',
|
|
123
172
|
' Choose a model from all configured providers.',
|
|
124
173
|
'/model <name-or-provider:name>',
|
|
125
174
|
' Set a model directly. Selecting a model also sets its provider.',
|
|
126
175
|
'/settings',
|
|
127
176
|
' Show the configured provider, model, API key status, and loaded context files.',
|
|
128
|
-
'/create-skill
|
|
129
|
-
'
|
|
177
|
+
'/create-skill',
|
|
178
|
+
' Launch the 3-step skill wizard (name, role, description).',
|
|
130
179
|
'/skills',
|
|
131
180
|
' Show Markdown skill commands and installed skill slash commands.',
|
|
132
181
|
'/init',
|
|
@@ -137,6 +186,10 @@ export async function handleSlashCommand(value, ctx) {
|
|
|
137
186
|
' Resume the latest saved session for this workspace.',
|
|
138
187
|
'/new',
|
|
139
188
|
' Start a fresh durable session.',
|
|
189
|
+
'/logs',
|
|
190
|
+
' List recent log files with sizes and dates.',
|
|
191
|
+
'/logs <id>',
|
|
192
|
+
' Show summary of a specific log: entry counts by type, total tokens, tool calls.',
|
|
140
193
|
'/compact [instructions]',
|
|
141
194
|
' Summarize older model context and keep recent messages.',
|
|
142
195
|
'/clear',
|
|
@@ -175,26 +228,47 @@ export async function handleSlashCommand(value, ctx) {
|
|
|
175
228
|
}
|
|
176
229
|
if (value === '/clear') {
|
|
177
230
|
ctx.clearConversation();
|
|
231
|
+
await clearTasks();
|
|
178
232
|
ctx.addSystemMessage('Cleared. The void is productive.');
|
|
179
233
|
return 'handled';
|
|
180
234
|
}
|
|
235
|
+
if (value === '/logs' || value.startsWith('/logs ')) {
|
|
236
|
+
const args = value.slice('/logs'.length).trim();
|
|
237
|
+
return await handleLogsCommand(args, ctx);
|
|
238
|
+
}
|
|
181
239
|
if (value === '/settings') {
|
|
182
240
|
const providers = configuredProviders(ctx.settings);
|
|
183
241
|
const activeProvider = providers.find(provider => provider.name === ctx.settings.provider) ?? providers[0];
|
|
184
|
-
ctx.
|
|
242
|
+
const contextDiagnostics = contextFileDiagnostics(ctx.contextFiles);
|
|
243
|
+
const contextTokens = contextDiagnostics.reduce((sum, file) => sum + file.estimatedTokens, 0);
|
|
244
|
+
const summary = summarizeContextDiagnostics(ctx.contextFiles);
|
|
245
|
+
const notes = [];
|
|
246
|
+
if (summary.exceedsBudget === true && summary.windowSize) {
|
|
247
|
+
const sharePct = Math.round((summary.budgetShare ?? 0) * 100);
|
|
248
|
+
const thresholdPct = Math.round(summary.budgetThreshold * 100);
|
|
249
|
+
notes.push(`project context exceeds ${thresholdPct}% budget (${sharePct}% of ${Math.round(summary.windowSize / 1000)}k window)`);
|
|
250
|
+
}
|
|
251
|
+
if (summary.duplicateGroups.length > 0) {
|
|
252
|
+
const duplicateTotal = summary.duplicateFileCount;
|
|
253
|
+
notes.push(`${summary.duplicateGroups.length} duplicate group${summary.duplicateGroups.length === 1 ? '' : 's'} (${duplicateTotal} file${duplicateTotal === 1 ? '' : 's'} with identical content)`);
|
|
254
|
+
}
|
|
255
|
+
const lines = [
|
|
185
256
|
`Provider: ${activeProvider?.name ?? 'not configured'}`,
|
|
186
257
|
`Model: ${ctx.settings.model ?? 'not set'}`,
|
|
187
258
|
`Base URL: ${activeProvider?.url ?? ctx.settings.baseURL ?? 'not configured'}`,
|
|
188
259
|
`API key: ${activeProvider && providerHasKey(ctx.settings, activeProvider) ? 'saved' : 'missing'}`,
|
|
189
260
|
`Configured providers: ${providers.map(provider => provider.name).join(', ') || 'none'}`,
|
|
190
|
-
`Context files: ${ctx.contextFiles.length ? ctx.contextFiles.map(file => file.path).join(', ') : 'none'}`,
|
|
191
|
-
]
|
|
261
|
+
`Context files: ${ctx.contextFiles.length ? `${ctx.contextFiles.map(file => file.path).join(', ')} (~${contextTokens} tokens)` : 'none'}`,
|
|
262
|
+
];
|
|
263
|
+
if (notes.length > 0)
|
|
264
|
+
lines.push(`Context note: ${notes.join('; ')}`);
|
|
265
|
+
ctx.addSystemMessage(lines.join(' | '));
|
|
192
266
|
return 'handled';
|
|
193
267
|
}
|
|
194
268
|
if (value === '/provider') {
|
|
195
269
|
ctx.setModelProviderFilter?.(undefined);
|
|
196
270
|
ctx.setMode('provider');
|
|
197
|
-
ctx.addSystemMessage('Choose a provider. Selecting one opens provider actions. Choose
|
|
271
|
+
ctx.addSystemMessage('Choose a provider. Selecting one opens provider actions. Choose "add provider" to pick from presets or enter custom details.');
|
|
198
272
|
return 'handled';
|
|
199
273
|
}
|
|
200
274
|
if (value === '/model') {
|
|
@@ -205,7 +279,7 @@ export async function handleSlashCommand(value, ctx) {
|
|
|
205
279
|
}
|
|
206
280
|
if (value === '/model list') {
|
|
207
281
|
const providers = configuredProviders(ctx.settings);
|
|
208
|
-
ctx.addSystemMessage(['Configured models:', ...providers.flatMap(provider => provider.models.map(model => `- ${modelSelector(provider, model)}
|
|
282
|
+
ctx.addSystemMessage(['Configured models:', ...providers.flatMap(provider => provider.models.map(model => `- ${modelSelector(provider, model)} - ${provider.name}`))].join('\n'));
|
|
209
283
|
return 'handled';
|
|
210
284
|
}
|
|
211
285
|
if (value.startsWith('/model ')) {
|
|
@@ -232,21 +306,15 @@ export async function handleSlashCommand(value, ctx) {
|
|
|
232
306
|
return 'handled';
|
|
233
307
|
}
|
|
234
308
|
if (value === '/skills')
|
|
235
|
-
return await handleSkillCommand('
|
|
236
|
-
if (value === '/list-skills')
|
|
237
|
-
return await handleSkillCommand('/skill list', ctx);
|
|
309
|
+
return await handleSkillCommand('help', '', ctx);
|
|
238
310
|
if (value === '/create-skill' || value.startsWith('/create-skill '))
|
|
239
|
-
return await handleSkillCommand(
|
|
311
|
+
return await handleSkillCommand('create', '', ctx);
|
|
240
312
|
if (value === '/skill-info' || value.startsWith('/skill-info '))
|
|
241
|
-
return await handleSkillCommand(
|
|
313
|
+
return await handleSkillCommand('info', value.slice('/skill-info '.length), ctx);
|
|
242
314
|
if (value === '/validate-skill' || value.startsWith('/validate-skill '))
|
|
243
|
-
return await handleSkillCommand(
|
|
315
|
+
return await handleSkillCommand('validate', value.slice('/validate-skill '.length), ctx);
|
|
244
316
|
if (value === '/remove-skill' || value.startsWith('/remove-skill '))
|
|
245
|
-
return await handleSkillCommand(
|
|
246
|
-
if (value === '/skill' || value.startsWith('/skill ') || value.startsWith('/skills ')) {
|
|
247
|
-
const normalized = value.replace(/^\/skills\b/, '/skill');
|
|
248
|
-
return await handleSkillCommand(normalized, ctx);
|
|
249
|
-
}
|
|
317
|
+
return await handleSkillCommand('remove', value.slice('/remove-skill '.length), ctx);
|
|
250
318
|
if (value.startsWith('/')) {
|
|
251
319
|
ctx.addSystemMessage(`Unknown command: ${value}. Bold start.`);
|
|
252
320
|
return 'handled';
|
|
@@ -6,4 +6,6 @@ export declare function toolResultSummary(event: {
|
|
|
6
6
|
error?: unknown;
|
|
7
7
|
}): string;
|
|
8
8
|
export declare function formatSeconds(milliseconds: number): string;
|
|
9
|
+
export declare function formatElapsedTime(milliseconds: number): string;
|
|
10
|
+
export declare function formatElapsedTimeWhole(milliseconds: number): string;
|
|
9
11
|
export declare function toolOutputDetails(value: unknown): string;
|
|
@@ -38,6 +38,10 @@ export function toolCallSummary(toolName, input) {
|
|
|
38
38
|
const taskPreview = data.task.length > 60 ? `${data.task.slice(0, 60).trimEnd()}…` : data.task;
|
|
39
39
|
return `subagent "${taskPreview}"`;
|
|
40
40
|
}
|
|
41
|
+
if (toolName === 'writeTasks') {
|
|
42
|
+
const tasks = Array.isArray(data?.tasks) ? data.tasks : [];
|
|
43
|
+
return `writeTasks (${tasks.length} task${tasks.length === 1 ? '' : 's'})`;
|
|
44
|
+
}
|
|
41
45
|
return `${toolName} ${compact(input)}`;
|
|
42
46
|
}
|
|
43
47
|
export function toolResultSummary(event) {
|
|
@@ -70,6 +74,10 @@ export function toolResultSummary(event) {
|
|
|
70
74
|
return `${output.status}${meta}: ${preview}`;
|
|
71
75
|
}
|
|
72
76
|
if (typeof output?.ok === 'boolean') {
|
|
77
|
+
// writeTasks result
|
|
78
|
+
if (output.ok && typeof output.summary === 'string') {
|
|
79
|
+
return compact(output.summary, 120);
|
|
80
|
+
}
|
|
73
81
|
if (output.ok) {
|
|
74
82
|
if (typeof output.addedLines === 'number' || typeof output.removedLines === 'number') {
|
|
75
83
|
const added = typeof output.addedLines === 'number' ? output.addedLines : 0;
|
|
@@ -86,6 +94,32 @@ export function toolResultSummary(event) {
|
|
|
86
94
|
export function formatSeconds(milliseconds) {
|
|
87
95
|
return `${(milliseconds / 1000).toFixed(1)}s`;
|
|
88
96
|
}
|
|
97
|
+
export function formatElapsedTime(milliseconds) {
|
|
98
|
+
const totalSeconds = Math.max(0, milliseconds / 1000);
|
|
99
|
+
const wholeSeconds = Math.floor(totalSeconds);
|
|
100
|
+
const seconds = totalSeconds - Math.floor(wholeSeconds / 60) * 60;
|
|
101
|
+
const totalMinutes = Math.floor(wholeSeconds / 60);
|
|
102
|
+
const minutes = totalMinutes % 60;
|
|
103
|
+
const hours = Math.floor(totalMinutes / 60);
|
|
104
|
+
const secondsLabel = `${seconds.toFixed(1)}s`;
|
|
105
|
+
if (hours > 0)
|
|
106
|
+
return `${hours}h ${minutes}m ${secondsLabel}`;
|
|
107
|
+
if (minutes > 0)
|
|
108
|
+
return `${minutes}m ${secondsLabel}`;
|
|
109
|
+
return secondsLabel;
|
|
110
|
+
}
|
|
111
|
+
export function formatElapsedTimeWhole(milliseconds) {
|
|
112
|
+
const totalSeconds = Math.max(0, Math.floor(milliseconds / 1000));
|
|
113
|
+
const seconds = totalSeconds % 60;
|
|
114
|
+
const totalMinutes = Math.floor(totalSeconds / 60);
|
|
115
|
+
const minutes = totalMinutes % 60;
|
|
116
|
+
const hours = Math.floor(totalMinutes / 60);
|
|
117
|
+
if (hours > 0)
|
|
118
|
+
return `${hours}h ${minutes}m ${seconds}s`;
|
|
119
|
+
if (minutes > 0)
|
|
120
|
+
return `${minutes}m ${seconds}s`;
|
|
121
|
+
return `${seconds}s`;
|
|
122
|
+
}
|
|
89
123
|
export function toolOutputDetails(value) {
|
|
90
124
|
if (!value || typeof value !== 'object')
|
|
91
125
|
return '';
|
|
@@ -1,13 +1,44 @@
|
|
|
1
1
|
import { type ModelMessage } from 'ai';
|
|
2
|
+
import type { LlmLog } from '../../core/log/llmLog.js';
|
|
3
|
+
import { type PromptSession } from '../../llm/systemPrompt.js';
|
|
2
4
|
import type { ContextFile } from '../../config/contextFiles.js';
|
|
3
5
|
import { type AgentEventSink } from '../../core/agent/events.js';
|
|
6
|
+
import { type WorkState } from '../../core/agent/workState.js';
|
|
4
7
|
export type Message = {
|
|
5
8
|
id?: string;
|
|
6
9
|
role: 'system' | 'user' | 'assistant' | 'tool';
|
|
7
10
|
text: string;
|
|
8
11
|
streaming?: boolean;
|
|
9
12
|
hidden?: boolean;
|
|
13
|
+
startedAt?: number;
|
|
14
|
+
finishedAt?: number;
|
|
10
15
|
};
|
|
16
|
+
export interface TokenUsage {
|
|
17
|
+
/** Precise input tokens from the provider (undefined if provider doesn't report). */
|
|
18
|
+
inputTokens: number | undefined;
|
|
19
|
+
/** Precise output tokens from the provider (undefined if provider doesn't report). */
|
|
20
|
+
outputTokens: number | undefined;
|
|
21
|
+
/** Estimated system prompt tokens. */
|
|
22
|
+
systemPrompt: number;
|
|
23
|
+
/** Estimated message history tokens. */
|
|
24
|
+
messages: number;
|
|
25
|
+
/** Estimated tool schema tokens. */
|
|
26
|
+
toolSchemas: number;
|
|
27
|
+
/** Estimated output tokens (from response messages). */
|
|
28
|
+
outputEstimate: number;
|
|
29
|
+
/** Cached input tokens (if provider reports). */
|
|
30
|
+
cacheReadTokens: number;
|
|
31
|
+
/** Cache write tokens (if provider reports). */
|
|
32
|
+
cacheWriteTokens: number;
|
|
33
|
+
/** Provider-reported input tokens that were not served from cache. */
|
|
34
|
+
noCacheTokens: number;
|
|
35
|
+
/** Reasoning tokens (if provider reports). */
|
|
36
|
+
reasoningTokens: number;
|
|
37
|
+
/** Estimated complete logical request size. */
|
|
38
|
+
logicalInputEstimate: number;
|
|
39
|
+
/** Provider input minus cache reads, when provider usage is available. */
|
|
40
|
+
effectiveNonCachedInput: number | undefined;
|
|
41
|
+
}
|
|
11
42
|
export interface StreamCallbacks {
|
|
12
43
|
addMessage: (msg: Message) => void;
|
|
13
44
|
updateMessage: (id: string, update: Partial<Message>) => void;
|
|
@@ -22,5 +53,9 @@ export interface StreamCallbacks {
|
|
|
22
53
|
setGoalStatus?: (status: string | undefined) => void;
|
|
23
54
|
onEvent?: AgentEventSink;
|
|
24
55
|
compactConversation?: (instructions?: string) => boolean;
|
|
56
|
+
recordTokenUsage?: (usage: TokenUsage) => void;
|
|
57
|
+
setWorkState?: (state: WorkState) => void;
|
|
58
|
+
onTasksChanged?: () => void;
|
|
59
|
+
log?: LlmLog;
|
|
25
60
|
}
|
|
26
|
-
export declare function runAgentTurn(value: string, displayValue: string | undefined, contextFiles: ContextFile[], callbacks: StreamCallbacks, retryAttempt?: number, retryingExistingRequest?: boolean, contextOverflowRecovered?: boolean): Promise<void>;
|
|
61
|
+
export declare function runAgentTurn(value: string, displayValue: string | undefined, contextFiles: ContextFile[], callbacks: StreamCallbacks, retryAttempt?: number, retryingExistingRequest?: boolean, contextOverflowRecovered?: boolean, session?: PromptSession): Promise<void>;
|