@denizokcu/haze 0.6.0 → 0.8.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 +42 -7
- package/README.md +81 -34
- package/dist/cli/chat/TaskBar.d.ts +9 -0
- package/dist/cli/chat/TaskBar.js +40 -0
- package/dist/cli/chat/chatMetrics.d.ts +11 -0
- package/dist/cli/chat/chatMetrics.js +50 -0
- package/dist/cli/chat/inputSuggestions.d.ts +16 -0
- package/dist/cli/chat/inputSuggestions.js +55 -0
- package/dist/cli/chat/messages.d.ts +9 -0
- package/dist/cli/chat/messages.js +76 -0
- package/dist/cli/chat/sessionRecorder.d.ts +12 -0
- package/dist/cli/chat/sessionRecorder.js +21 -0
- package/dist/cli/chat/startupInfo.d.ts +4 -0
- package/dist/cli/chat/startupInfo.js +53 -0
- package/dist/cli/chat/turnState.d.ts +5 -0
- package/dist/cli/chat/turnState.js +20 -0
- package/dist/cli/commands/chat.d.ts +0 -1
- package/dist/cli/commands/chat.js +331 -906
- package/dist/cli/commands/chatModes.d.ts +8 -0
- package/dist/cli/commands/chatModes.js +44 -0
- package/dist/cli/commands/commandHelp.d.ts +6 -0
- package/dist/cli/commands/commandHelp.js +25 -0
- package/dist/cli/commands/commands.d.ts +1 -1
- package/dist/cli/commands/commands.js +41 -267
- package/dist/cli/commands/formatters.d.ts +6 -0
- package/dist/cli/commands/formatters.js +50 -4
- package/dist/cli/commands/initCommand.d.ts +2 -0
- package/dist/cli/commands/initCommand.js +19 -0
- package/dist/cli/commands/logsCommand.d.ts +2 -0
- package/dist/cli/commands/logsCommand.js +63 -0
- package/dist/cli/commands/lspWizard.d.ts +14 -0
- package/dist/cli/commands/lspWizard.js +44 -0
- package/dist/cli/commands/mcpWizard.d.ts +15 -0
- package/dist/cli/commands/mcpWizard.js +69 -0
- package/dist/cli/commands/modelCommand.d.ts +2 -0
- package/dist/cli/commands/modelCommand.js +36 -0
- package/dist/cli/commands/providerWizard.d.ts +30 -0
- package/dist/cli/commands/providerWizard.js +114 -0
- package/dist/cli/commands/runCommand.d.ts +16 -0
- package/dist/cli/commands/runCommand.js +170 -0
- package/dist/cli/commands/settingsSummary.d.ts +3 -0
- package/dist/cli/commands/settingsSummary.js +40 -0
- package/dist/cli/commands/skillConfirmRemove.d.ts +11 -0
- package/dist/cli/commands/skillConfirmRemove.js +19 -0
- package/dist/cli/commands/skillCreation.d.ts +12 -0
- package/dist/cli/commands/skillCreation.js +14 -0
- package/dist/cli/commands/skillWizard.d.ts +15 -0
- package/dist/cli/commands/skillWizard.js +38 -0
- package/dist/cli/commands/streaming/assistantText.d.ts +17 -0
- package/dist/cli/commands/streaming/assistantText.js +115 -0
- package/dist/cli/commands/streaming/toolGroupRenderer.d.ts +55 -0
- package/dist/cli/commands/streaming/toolGroupRenderer.js +102 -0
- package/dist/cli/commands/streaming/toolResultState.d.ts +13 -0
- package/dist/cli/commands/streaming/toolResultState.js +25 -0
- package/dist/cli/commands/streaming/turnRuntime.d.ts +78 -0
- package/dist/cli/commands/streaming/turnRuntime.js +86 -0
- package/dist/cli/commands/streaming.d.ts +9 -25
- package/dist/cli/commands/streaming.js +109 -363
- package/dist/cli/commands/wizardActions.d.ts +40 -0
- package/dist/cli/commands/wizardActions.js +40 -0
- package/dist/cli/commands/wizardInput.d.ts +4 -0
- package/dist/cli/commands/wizardInput.js +19 -0
- package/dist/cli/commands/wizardPrompts.d.ts +22 -0
- package/dist/cli/commands/wizardPrompts.js +52 -0
- package/dist/cli/commands/wizardSuggestions.d.ts +23 -0
- package/dist/cli/commands/wizardSuggestions.js +139 -0
- package/dist/cli/index.js +62 -4
- package/dist/config/contextFiles.d.ts +8 -1
- package/dist/config/contextFiles.js +25 -12
- package/dist/config/lspSettings.js +3 -6
- package/dist/config/mcpSettings.js +5 -5
- package/dist/config/providers.js +8 -12
- package/dist/config/settings.d.ts +1 -0
- package/dist/config/settings.js +54 -2
- package/dist/config/skillSettings.js +4 -3
- package/dist/core/agent/budgets.d.ts +6 -0
- package/dist/core/agent/budgets.js +6 -0
- package/dist/core/agent/compaction.js +3 -3
- package/dist/core/agent/errors.js +1 -1
- package/dist/core/agent/requestAssembly.d.ts +1 -7
- package/dist/core/agent/requestAssembly.js +40 -5
- package/dist/core/agent/toolOutputStore.js +5 -4
- package/dist/core/agent/toolResults.d.ts +31 -0
- package/dist/core/agent/toolResults.js +42 -0
- package/dist/core/agent/turnPolicy.d.ts +8 -0
- package/dist/core/agent/turnPolicy.js +23 -0
- package/dist/core/agent/workState.d.ts +18 -5
- package/dist/core/agent/workState.js +39 -20
- package/dist/core/bashOutput/reducers/content.d.ts +1 -0
- package/dist/core/bashOutput/reducers/content.js +1 -1
- package/dist/core/bashOutput/reducers/gh.d.ts +1 -0
- package/dist/core/bashOutput/reducers/gh.js +77 -0
- package/dist/core/bashOutput/registry.js +18 -8
- package/dist/core/goal/completionPolicy.js +1 -1
- package/dist/core/goal/sessionGoal.d.ts +6 -30
- package/dist/core/goal/sessionGoal.js +3 -68
- package/dist/core/safety/bashClassifier.js +30 -0
- package/dist/core/safety/urlGuard.d.ts +1 -0
- package/dist/core/safety/urlGuard.js +6 -1
- package/dist/core/session/sessionSlimming.d.ts +5 -0
- package/dist/core/session/sessionSlimming.js +78 -0
- package/dist/core/session/sessionStore.d.ts +23 -3
- package/dist/core/session/sessionStore.js +30 -10
- package/dist/core/subagent/subagentRunner.d.ts +258 -5
- package/dist/core/subagent/subagentRunner.js +14 -18
- package/dist/core/toolOutput/reduction.d.ts +2 -0
- package/dist/core/toolOutput/reduction.js +12 -0
- package/dist/core/validation/outputParser.js +5 -3
- package/dist/llm/capabilities.d.ts +12 -0
- package/dist/llm/capabilities.js +10 -0
- package/dist/llm/client.d.ts +3 -2
- package/dist/llm/client.js +26 -4
- package/dist/llm/hazeTools.d.ts +7710 -366
- package/dist/llm/hazeTools.js +46 -567
- package/dist/llm/initPrompt.js +1 -1
- package/dist/llm/lsp.d.ts +46 -1
- package/dist/llm/lsp.js +19 -10
- package/dist/llm/lspTools.d.ts +2310 -119
- package/dist/llm/mcp.js +9 -0
- package/dist/llm/requestContext.js +7 -22
- package/dist/llm/systemPrompt.d.ts +1 -0
- package/dist/llm/systemPrompt.js +3 -3
- package/dist/llm/tools/bashTool.d.ts +251 -0
- package/dist/llm/tools/bashTool.js +82 -0
- package/dist/llm/tools/editMatch.d.ts +55 -0
- package/dist/llm/tools/editMatch.js +99 -0
- package/dist/llm/tools/failures.d.ts +36 -0
- package/dist/llm/tools/failures.js +38 -0
- package/dist/llm/tools/fetchTool.d.ts +1201 -0
- package/dist/llm/tools/fetchTool.js +46 -0
- package/dist/llm/tools/fileToolShared.d.ts +10 -0
- package/dist/llm/tools/fileToolShared.js +43 -0
- package/dist/llm/tools/grepParse.d.ts +13 -0
- package/dist/llm/tools/grepParse.js +67 -0
- package/dist/llm/tools/outputCap.d.ts +53 -0
- package/dist/llm/tools/outputCap.js +67 -0
- package/dist/llm/tools/storedOutputTool.d.ts +351 -0
- package/dist/llm/tools/storedOutputTool.js +17 -0
- package/dist/llm/tools/taskTool.d.ts +629 -0
- package/dist/llm/tools/taskTool.js +41 -0
- package/dist/llm/tools/toolContext.d.ts +74 -0
- package/dist/llm/tools/toolContext.js +196 -0
- package/dist/llm/tools/workspaceFile.d.ts +33 -0
- package/dist/llm/tools/workspaceFile.js +27 -0
- package/dist/llm/webFetch.d.ts +13 -1
- package/dist/llm/webFetch.js +122 -28
- package/dist/skills/builder/SkillBuilder.d.ts +3 -0
- package/dist/skills/builder/SkillBuilder.js +8 -8
- package/dist/ui/components/TextInput.d.ts +7 -0
- package/dist/ui/components/TextInput.js +10 -98
- package/dist/ui/inputBuffer.d.ts +28 -0
- package/dist/ui/inputBuffer.js +99 -0
- package/dist/utils/collections.d.ts +6 -0
- package/dist/utils/collections.js +9 -0
- package/dist/utils/modelName.d.ts +2 -0
- package/dist/utils/modelName.js +15 -0
- package/dist/utils/path.d.ts +2 -0
- package/dist/utils/path.js +40 -0
- package/examples/skills/files/SKILL.md +1 -1
- package/package.json +14 -15
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { applyLineFilter, findLineFilter } from './lineFilter.js';
|
|
2
2
|
import { renderValidationReduction } from './reducers/validation.js';
|
|
3
3
|
import { reduceGitOutput } from './reducers/git.js';
|
|
4
|
+
import { reduceGhOutput } from './reducers/gh.js';
|
|
4
5
|
import { reduceSearchOutput } from './reducers/search.js';
|
|
5
6
|
import { reduceGenericLogOutput, reduceJsonOutput, reduceUnifiedDiffOutput } from './reducers/content.js';
|
|
6
|
-
import { isInflating, reductionMetrics, retrievalHint } from '../toolOutput/reduction.js';
|
|
7
|
+
import { capOutputForProcessing, isInflating, reductionMetrics, retrievalHint } from '../toolOutput/reduction.js';
|
|
7
8
|
export const builtInLineFilters = [
|
|
8
9
|
{ name: 'markdownlint', matchCommand: /(^|[;&|]\s*)markdownlint\b/, stripAnsi: true, truncateLinesAt: 200, maxLines: 80, onEmpty: 'markdownlint: ok' },
|
|
9
10
|
{ name: 'shellcheck', matchCommand: /(^|[;&|]\s*)shellcheck\b/, stripAnsi: true, stripLinesMatching: [/^In .* line \d+:/], truncateLinesAt: 200, maxLines: 100, onEmpty: 'shellcheck: ok' },
|
|
@@ -73,24 +74,33 @@ export function filterBashOutput(input) {
|
|
|
73
74
|
stderr = makeReduction(input.stderr, '', input.stderr.length > 0, filterName, input, undefined, 'validation');
|
|
74
75
|
}
|
|
75
76
|
else {
|
|
76
|
-
const
|
|
77
|
+
const stdoutIn = capOutputForProcessing(input.stdout);
|
|
78
|
+
const stderrIn = capOutputForProcessing(input.stderr);
|
|
79
|
+
const git = reduceGitOutput(input.command, stdoutIn, stderrIn);
|
|
80
|
+
const gh = git == null ? reduceGhOutput(input.command, stdoutIn, stderrIn) : undefined;
|
|
77
81
|
if (git != null) {
|
|
78
82
|
filterName = 'git';
|
|
79
83
|
const kind = /^git (?:diff|show):/.test(git) ? 'diff' : 'generic';
|
|
80
84
|
stdout = makeReduction(input.stdout, input.stdout ? git : '', true, filterName, input, undefined, kind);
|
|
81
85
|
stderr = makeReduction(input.stderr, input.stdout ? '' : git, true, filterName, input, undefined, kind);
|
|
82
86
|
}
|
|
87
|
+
else if (gh != null) {
|
|
88
|
+
filterName = 'gh';
|
|
89
|
+
const kind = gh.trimStart().startsWith('{') ? 'json' : 'generic';
|
|
90
|
+
stdout = makeReduction(input.stdout, input.stdout ? gh : '', true, filterName, input, undefined, kind);
|
|
91
|
+
stderr = makeReduction(input.stderr, input.stdout ? '' : gh, true, filterName, input, undefined, kind);
|
|
92
|
+
}
|
|
83
93
|
else {
|
|
84
|
-
const search = reduceSearchOutput(input.command,
|
|
94
|
+
const search = reduceSearchOutput(input.command, stdoutIn, stderrIn);
|
|
85
95
|
if (search != null) {
|
|
86
96
|
filterName = 'search';
|
|
87
97
|
stdout = makeReduction(input.stdout, input.stdout ? search : '', true, filterName, input, undefined, 'search');
|
|
88
98
|
stderr = makeReduction(input.stderr, input.stdout ? '' : search, true, filterName, input, undefined, 'search');
|
|
89
99
|
}
|
|
90
100
|
else {
|
|
91
|
-
const diff = reduceUnifiedDiffOutput(
|
|
92
|
-
const json = diff == null ? reduceJsonOutput(
|
|
93
|
-
const log = diff == null && json == null ? reduceGenericLogOutput(
|
|
101
|
+
const diff = reduceUnifiedDiffOutput(stdoutIn, stderrIn);
|
|
102
|
+
const json = diff == null ? reduceJsonOutput(stdoutIn, stderrIn) : undefined;
|
|
103
|
+
const log = diff == null && json == null ? reduceGenericLogOutput(stdoutIn, stderrIn) : undefined;
|
|
94
104
|
const content = diff ?? json ?? log;
|
|
95
105
|
if (content != null) {
|
|
96
106
|
filterName = diff != null ? 'diff' : json != null ? 'json' : 'log';
|
|
@@ -102,8 +112,8 @@ export function filterBashOutput(input) {
|
|
|
102
112
|
const lineFilter = findLineFilter(builtInLineFilters, input.command);
|
|
103
113
|
if (lineFilter) {
|
|
104
114
|
filterName = lineFilter.name;
|
|
105
|
-
const out = input.stdout ? applyLineFilter(lineFilter, input.command,
|
|
106
|
-
const err = input.stderr ? applyLineFilter(lineFilter, input.command,
|
|
115
|
+
const out = input.stdout ? applyLineFilter(lineFilter, input.command, stdoutIn) : undefined;
|
|
116
|
+
const err = input.stderr ? applyLineFilter(lineFilter, input.command, stderrIn) : undefined;
|
|
107
117
|
stdout = makeReduction(input.stdout, out?.text ?? input.stdout, out?.filtered ?? false, lineFilter.name, input, out?.warning, 'log');
|
|
108
118
|
stderr = makeReduction(input.stderr, err?.text ?? input.stderr, err?.filtered ?? false, lineFilter.name, input, err?.warning, 'log');
|
|
109
119
|
}
|
|
@@ -79,7 +79,7 @@ export function completionDecision(input) {
|
|
|
79
79
|
};
|
|
80
80
|
}
|
|
81
81
|
export function toolLoopBudgetPrompt() {
|
|
82
|
-
return 'Tool slice reached for this model step — tools are no longer callable in this turn. Stop attempting to describe or announce tool calls (e.g. "Let me install", "Now I\'ll run", "Let me X"); those phrases imply tool use you cannot perform. Answer once: either the final status template (current-turn changes + validation evidence) or, if incomplete, a single short line stating the next concrete unfinished action so
|
|
82
|
+
return 'Tool slice reached for this model step — tools are no longer callable in this turn. Stop attempting to describe or announce tool calls (e.g. "Let me install", "Now I\'ll run", "Let me X"); those phrases imply tool use you cannot perform. Answer once: either the final status template (current-turn changes + validation evidence) or, if incomplete, a single short line stating the next concrete unfinished action so haze can continue in a fresh tool slice. Do not repeat yourself, do not loop, do not emit XML/JSON tool-call syntax.';
|
|
83
83
|
}
|
|
84
84
|
export function repeatedToolCallPrompt(toolNames) {
|
|
85
85
|
const names = [...new Set(toolNames)].join(', ');
|
|
@@ -1,32 +1,8 @@
|
|
|
1
|
-
import { type
|
|
2
|
-
|
|
3
|
-
export type
|
|
4
|
-
export type
|
|
5
|
-
export
|
|
6
|
-
id: string;
|
|
7
|
-
originalUserRequest: string;
|
|
8
|
-
normalizedIntent: RequestIntent;
|
|
9
|
-
successCriteria: string[];
|
|
10
|
-
constraints: string[];
|
|
11
|
-
touchedFiles: string[];
|
|
12
|
-
validationCommands: Array<{
|
|
13
|
-
command: string;
|
|
14
|
-
status: ValidationStatus;
|
|
15
|
-
}>;
|
|
16
|
-
status: SessionGoalStatus;
|
|
17
|
-
phase: 'starting' | 'inspecting' | 'editing' | 'validating' | 'summarizing' | 'done';
|
|
18
|
-
blocker?: string;
|
|
19
|
-
lastProgressAt: number;
|
|
20
|
-
workState: WorkState;
|
|
21
|
-
}
|
|
22
|
-
export interface GoalToolEvent {
|
|
23
|
-
toolName: string;
|
|
24
|
-
input?: unknown;
|
|
25
|
-
success: boolean;
|
|
26
|
-
output?: unknown;
|
|
27
|
-
error?: unknown;
|
|
28
|
-
duplicateSkipped?: boolean;
|
|
29
|
-
}
|
|
1
|
+
import { observeWorkToolEvent, type WorkState, type WorkStatus, type WorkValidationStatus } from '../agent/workState.js';
|
|
2
|
+
export type SessionGoalStatus = WorkStatus;
|
|
3
|
+
export type ValidationStatus = WorkValidationStatus;
|
|
4
|
+
export type SessionGoal = WorkState;
|
|
5
|
+
export type GoalToolEvent = Parameters<typeof observeWorkToolEvent>[1];
|
|
30
6
|
export declare function createSessionGoal(request: string, now?: number): SessionGoal;
|
|
31
|
-
export declare function observeGoalToolEvent(goal: SessionGoal, event: GoalToolEvent, now?: number):
|
|
7
|
+
export declare function observeGoalToolEvent(goal: SessionGoal, event: GoalToolEvent, now?: number): WorkState;
|
|
32
8
|
export declare function formatGoalStatus(goal: SessionGoal): string;
|
|
@@ -3,23 +3,9 @@ import { createWorkState, observeWorkToolEvent } from '../agent/workState.js';
|
|
|
3
3
|
function shortRequest(value) {
|
|
4
4
|
return value.replace(/\s+/g, ' ').trim().slice(0, 160) || 'current request';
|
|
5
5
|
}
|
|
6
|
-
function inputPath(input) {
|
|
7
|
-
return typeof input === 'object' && input != null && 'path' in input && typeof input.path === 'string'
|
|
8
|
-
? input.path
|
|
9
|
-
: undefined;
|
|
10
|
-
}
|
|
11
|
-
function bashCommand(input) {
|
|
12
|
-
return typeof input === 'object' && input != null && 'command' in input && typeof input.command === 'string'
|
|
13
|
-
? input.command
|
|
14
|
-
: undefined;
|
|
15
|
-
}
|
|
16
|
-
function uniquePush(values, value) {
|
|
17
|
-
if (!values.includes(value))
|
|
18
|
-
values.push(value);
|
|
19
|
-
}
|
|
20
6
|
export function createSessionGoal(request, now = Date.now()) {
|
|
21
7
|
const intent = classifyRequestIntent(request);
|
|
22
|
-
const
|
|
8
|
+
const successCriteria = intent === 'plan'
|
|
23
9
|
? ['Create or update the requested plan artifact/answer', 'Do not implement source changes unless asked']
|
|
24
10
|
: intent === 'test'
|
|
25
11
|
? ['Run the requested validation or closest relevant check', 'Report pass/fail accurately']
|
|
@@ -28,61 +14,10 @@ export function createSessionGoal(request, now = Date.now()) {
|
|
|
28
14
|
: intent === 'answer'
|
|
29
15
|
? ['Answer the user using current project context when needed']
|
|
30
16
|
: ['Inspect the relevant files', 'Make the requested change when needed', 'Validate the change when practical', 'Summarize only current-task changes and validation'];
|
|
31
|
-
|
|
32
|
-
return {
|
|
33
|
-
id: `goal-${now}-${Math.random().toString(36).slice(2)}`,
|
|
34
|
-
originalUserRequest: request,
|
|
35
|
-
normalizedIntent: intent,
|
|
36
|
-
successCriteria,
|
|
37
|
-
constraints: [],
|
|
38
|
-
touchedFiles: [],
|
|
39
|
-
validationCommands: [],
|
|
40
|
-
status: 'active',
|
|
41
|
-
phase: 'starting',
|
|
42
|
-
lastProgressAt: now,
|
|
43
|
-
workState: createWorkState(request, intent, successCriteria),
|
|
44
|
-
};
|
|
17
|
+
return createWorkState(request, intent, successCriteria, now);
|
|
45
18
|
}
|
|
46
19
|
export function observeGoalToolEvent(goal, event, now = Date.now()) {
|
|
47
|
-
|
|
48
|
-
return goal;
|
|
49
|
-
observeWorkToolEvent(goal.workState, event);
|
|
50
|
-
if (event.success && ['listFiles', 'readFile'].includes(event.toolName)) {
|
|
51
|
-
goal.phase = goal.phase === 'editing' || goal.phase === 'validating' ? goal.phase : 'inspecting';
|
|
52
|
-
goal.lastProgressAt = now;
|
|
53
|
-
}
|
|
54
|
-
goal.workState.phase = goal.phase;
|
|
55
|
-
if (['editFile', 'replaceLines', 'writeFile'].includes(event.toolName)) {
|
|
56
|
-
const path = inputPath(event.input);
|
|
57
|
-
if (path)
|
|
58
|
-
uniquePush(goal.touchedFiles, path);
|
|
59
|
-
if (event.success) {
|
|
60
|
-
goal.phase = 'editing';
|
|
61
|
-
goal.lastProgressAt = now;
|
|
62
|
-
}
|
|
63
|
-
else {
|
|
64
|
-
goal.blocker = `File edit failed${path ? ` for ${path}` : ''}; recovery read is required before retry.`;
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
goal.workState.phase = goal.phase;
|
|
68
|
-
if (event.toolName === 'bash') {
|
|
69
|
-
const command = bashCommand(event.input);
|
|
70
|
-
if (command) {
|
|
71
|
-
const ok = typeof event.output === 'object' && event.output != null && 'ok' in event.output ? Boolean(event.output.ok) : event.success;
|
|
72
|
-
const existing = goal.validationCommands.find(item => item.command === command);
|
|
73
|
-
const status = ok ? 'passed' : 'failed';
|
|
74
|
-
if (existing)
|
|
75
|
-
existing.status = status;
|
|
76
|
-
else
|
|
77
|
-
goal.validationCommands.push({ command, status });
|
|
78
|
-
goal.phase = 'validating';
|
|
79
|
-
goal.lastProgressAt = now;
|
|
80
|
-
if (!ok)
|
|
81
|
-
goal.blocker = `Validation command failed: ${command}`;
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
goal.workState.phase = goal.phase;
|
|
85
|
-
return goal;
|
|
20
|
+
return observeWorkToolEvent(goal, event, now);
|
|
86
21
|
}
|
|
87
22
|
export function formatGoalStatus(goal) {
|
|
88
23
|
const action = goal.phase === 'starting' ? 'starting'
|
|
@@ -33,6 +33,36 @@ export function classifyBashCommand(command) {
|
|
|
33
33
|
traits.push('changes_git_state');
|
|
34
34
|
return { riskLevel: 'mutating', traits: uniq(traits), confidence: complex ? 'medium' : 'high', reason: 'command can modify files or repository state' };
|
|
35
35
|
}
|
|
36
|
+
// `find -delete` removes matched files outright. `-delete` is a find-specific
|
|
37
|
+
// primary, so gate on `find` to avoid flagging unrelated single-dash flags.
|
|
38
|
+
if (has(lower, /\bfind\b/) && has(lower, /(\s|^)-delete\b/)) {
|
|
39
|
+
traits.push('deletes_files');
|
|
40
|
+
return { riskLevel: 'destructive', traits: uniq(traits), confidence: complex ? 'medium' : 'high', reason: 'find -delete removes matched files' };
|
|
41
|
+
}
|
|
42
|
+
// `find -exec`/`-execdir` and `xargs` run an embedded command. Classify by
|
|
43
|
+
// the payload so destructive/mutating verbs are not masked by the read-only
|
|
44
|
+
// `find`/`xargs` wrapper, and never promise read-only for an arbitrary exec.
|
|
45
|
+
const execMatch = /(?:\s|^)(?:-exec(?:dir)?|xargs)\s+(.*)$/.exec(lower);
|
|
46
|
+
if (execMatch) {
|
|
47
|
+
const payload = execMatch[1];
|
|
48
|
+
if (has(payload, /\brm\b|git\s+clean|git\s+restore|drop\s+database|truncate\s+table/)) {
|
|
49
|
+
if (has(payload, /\brm\b/))
|
|
50
|
+
traits.push('deletes_files');
|
|
51
|
+
if (has(payload, /\bgit\b/))
|
|
52
|
+
traits.push('changes_git_state');
|
|
53
|
+
return { riskLevel: 'destructive', traits: uniq(traits), confidence: 'medium', reason: 'embedded command can delete files' };
|
|
54
|
+
}
|
|
55
|
+
if (has(payload, /\b(chmod|mv|cp|mkdir|touch|tee|sed\s+-i|perl\s+-pi)\b/) || has(payload, /\bgit\s+(add|commit|merge|rebase|checkout|restore)\b/)) {
|
|
56
|
+
traits.push('writes_files');
|
|
57
|
+
if (has(payload, /\bchmod\b/))
|
|
58
|
+
traits.push('changes_permissions');
|
|
59
|
+
if (has(payload, /\bgit\b/))
|
|
60
|
+
traits.push('changes_git_state');
|
|
61
|
+
return { riskLevel: 'mutating', traits: uniq(traits), confidence: 'medium', reason: 'embedded command can modify files' };
|
|
62
|
+
}
|
|
63
|
+
traits.push('reads_files');
|
|
64
|
+
return { riskLevel: 'unknown', traits: uniq(traits), confidence: 'low', reason: 'find -exec / xargs runs an embedded command' };
|
|
65
|
+
}
|
|
36
66
|
if (has(lower, /(^|[;&|]\s*)(npm\s+test|npm\s+run\s+(test|typecheck|lint|build)|pnpm\s+(test|run\s+(test|typecheck|lint|build))|yarn\s+(test|run\s+(test|typecheck|lint|build))|vitest\b|jest\b|tsc\b|eslint\b)/)) {
|
|
37
67
|
if (has(lower, /test|vitest|jest/))
|
|
38
68
|
traits.push('runs_tests');
|
|
@@ -178,6 +178,8 @@ export async function validateUrl(input, options) {
|
|
|
178
178
|
return { ok: false, reasonCode: 'blocked_host', reason: 'URL has no hostname.' };
|
|
179
179
|
}
|
|
180
180
|
// If the host is a literal IP, check ranges directly (no DNS needed).
|
|
181
|
+
// No resolvedAddresses: literal IPs carry no DNS-rebinding surface, so the
|
|
182
|
+
// caller can connect to the URL as-is without pinning.
|
|
181
183
|
if (hostLooksLikeIp(host)) {
|
|
182
184
|
if (isBlockedIp(host)) {
|
|
183
185
|
return { ok: false, reasonCode: 'blocked_address', reason: `Address '${host}' is private, loopback, link-local, or otherwise blocked.` };
|
|
@@ -202,5 +204,8 @@ export async function validateUrl(input, options) {
|
|
|
202
204
|
return { ok: false, reasonCode: 'blocked_address', reason: `Hostname '${host}' resolves to blocked address '${address}'.` };
|
|
203
205
|
}
|
|
204
206
|
}
|
|
205
|
-
|
|
207
|
+
// Surface the validated addresses so the caller can pin the connection to
|
|
208
|
+
// one of them, closing the DNS-rebinding TOCTOU between this check and the
|
|
209
|
+
// actual connect (a public hostname that later re-resolves to an internal IP).
|
|
210
|
+
return { ok: true, url, resolvedAddresses: addresses };
|
|
206
211
|
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { ModelMessage } from 'ai';
|
|
2
|
+
import type { SessionEntry } from './sessionStore.js';
|
|
3
|
+
export declare function slimConversationSnapshot(messages: ModelMessage[]): ModelMessage[];
|
|
4
|
+
export declare function prepareSessionEntryForWrite(entry: SessionEntry): SessionEntry | undefined;
|
|
5
|
+
export declare const SESSION_INLINE_VALUE_BYTES: number;
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
const INLINE_VALUE_BYTES = 32 * 1024;
|
|
2
|
+
const PREVIEW_CHARS = 4 * 1024;
|
|
3
|
+
const LARGE_STRING_CHARS = 8 * 1024;
|
|
4
|
+
function jsonByteLength(value) {
|
|
5
|
+
try {
|
|
6
|
+
return Buffer.byteLength(JSON.stringify(value), 'utf8');
|
|
7
|
+
}
|
|
8
|
+
catch {
|
|
9
|
+
return Buffer.byteLength(String(value), 'utf8');
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
function previewText(value) {
|
|
13
|
+
const text = typeof value === 'string' ? value : JSON.stringify(value, null, 2) ?? String(value);
|
|
14
|
+
return text.length > PREVIEW_CHARS ? text.slice(0, PREVIEW_CHARS) : text;
|
|
15
|
+
}
|
|
16
|
+
function slimLargeValue(value) {
|
|
17
|
+
const bytes = jsonByteLength(value);
|
|
18
|
+
if (bytes <= INLINE_VALUE_BYTES)
|
|
19
|
+
return value;
|
|
20
|
+
return {
|
|
21
|
+
omitted: true,
|
|
22
|
+
reason: 'session_size_limit',
|
|
23
|
+
originalBytes: bytes,
|
|
24
|
+
preview: previewText(value),
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
function slimUnknown(value, seen = new WeakSet()) {
|
|
28
|
+
if (typeof value === 'string') {
|
|
29
|
+
if (value.length <= LARGE_STRING_CHARS)
|
|
30
|
+
return value;
|
|
31
|
+
return `${value.slice(0, PREVIEW_CHARS)}\n\n[Session value truncated: ${value.length - PREVIEW_CHARS} characters omitted]`;
|
|
32
|
+
}
|
|
33
|
+
if (value == null || typeof value !== 'object')
|
|
34
|
+
return value;
|
|
35
|
+
if (seen.has(value))
|
|
36
|
+
return '[Circular]';
|
|
37
|
+
seen.add(value);
|
|
38
|
+
if (Array.isArray(value))
|
|
39
|
+
return value.map(item => slimUnknown(item, seen));
|
|
40
|
+
const record = value;
|
|
41
|
+
if (record.type === 'tool-result') {
|
|
42
|
+
return {
|
|
43
|
+
...record,
|
|
44
|
+
output: slimLargeValue(record.output),
|
|
45
|
+
result: slimLargeValue(record.result),
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
const next = {};
|
|
49
|
+
for (const [key, child] of Object.entries(record))
|
|
50
|
+
next[key] = slimUnknown(child, seen);
|
|
51
|
+
return next;
|
|
52
|
+
}
|
|
53
|
+
export function slimConversationSnapshot(messages) {
|
|
54
|
+
return slimUnknown(messages);
|
|
55
|
+
}
|
|
56
|
+
export function prepareSessionEntryForWrite(entry) {
|
|
57
|
+
if (entry.type === 'event') {
|
|
58
|
+
if (entry.name === 'message_update')
|
|
59
|
+
return undefined;
|
|
60
|
+
if (entry.name === 'tool_end' && entry.text) {
|
|
61
|
+
try {
|
|
62
|
+
const event = JSON.parse(entry.text);
|
|
63
|
+
event.output = slimLargeValue(event.output);
|
|
64
|
+
event.error = slimLargeValue(event.error);
|
|
65
|
+
return { ...entry, text: JSON.stringify(event) };
|
|
66
|
+
}
|
|
67
|
+
catch {
|
|
68
|
+
return entry;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return entry;
|
|
72
|
+
}
|
|
73
|
+
if (entry.type === 'conversation_snapshot') {
|
|
74
|
+
return { ...entry, messages: slimConversationSnapshot(entry.messages) };
|
|
75
|
+
}
|
|
76
|
+
return entry;
|
|
77
|
+
}
|
|
78
|
+
export const SESSION_INLINE_VALUE_BYTES = INLINE_VALUE_BYTES;
|
|
@@ -37,7 +37,27 @@ export declare function createSession(options?: {
|
|
|
37
37
|
}): Promise<HazeSession>;
|
|
38
38
|
export declare function latestSession(cwd?: string, sessionsDir?: string): Promise<HazeSession | undefined>;
|
|
39
39
|
export declare function appendSessionEntry(session: HazeSession, entry: SessionEntry): Promise<void>;
|
|
40
|
-
export
|
|
41
|
-
|
|
42
|
-
|
|
40
|
+
export interface ReadSessionEntriesResult {
|
|
41
|
+
entries: SessionEntry[];
|
|
42
|
+
/** Per-line parse failures, e.g. `Line 3: Unexpected token...`. Empty when every line parsed. */
|
|
43
|
+
parseErrors: string[];
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Read a session file and parse each non-empty line as a JSONL entry.
|
|
47
|
+
*
|
|
48
|
+
* Malformed lines are not silently discarded: they are reported in
|
|
49
|
+
* `parseErrors` (with their 1-based line number) so callers can surface the
|
|
50
|
+
* loss in debug mode instead of silently dropping messages.
|
|
51
|
+
*/
|
|
52
|
+
export declare function readSessionEntries(session: HazeSession): Promise<ReadSessionEntriesResult>;
|
|
53
|
+
export interface RestoreConversationResult {
|
|
54
|
+
messages: ModelMessage[];
|
|
55
|
+
parseErrors: string[];
|
|
56
|
+
}
|
|
57
|
+
export declare function restoreConversation(session: HazeSession): Promise<RestoreConversationResult>;
|
|
58
|
+
export interface RestoreWorkStateResult {
|
|
59
|
+
state: WorkState | undefined;
|
|
60
|
+
parseErrors: string[];
|
|
61
|
+
}
|
|
62
|
+
export declare function restoreWorkState(session: HazeSession): Promise<RestoreWorkStateResult>;
|
|
43
63
|
export declare function formatSession(session: HazeSession): string;
|
|
@@ -2,6 +2,7 @@ import crypto from 'node:crypto';
|
|
|
2
2
|
import path from 'node:path';
|
|
3
3
|
import fs from 'fs-extra';
|
|
4
4
|
import { HAZE_DIR } from '../../config/paths.js';
|
|
5
|
+
import { prepareSessionEntryForWrite } from './sessionSlimming.js';
|
|
5
6
|
const DEFAULT_SESSIONS_DIR = path.join(HAZE_DIR, 'sessions');
|
|
6
7
|
function cwdHash(cwd = process.cwd()) {
|
|
7
8
|
return crypto.createHash('sha256').update(path.resolve(cwd)).digest('hex').slice(0, 16);
|
|
@@ -35,29 +36,48 @@ export async function latestSession(cwd = process.cwd(), sessionsDir = DEFAULT_S
|
|
|
35
36
|
return { id, file: path.join(dir, latest), cwd: path.resolve(cwd) };
|
|
36
37
|
}
|
|
37
38
|
export async function appendSessionEntry(session, entry) {
|
|
39
|
+
const prepared = prepareSessionEntryForWrite(entry);
|
|
40
|
+
if (!prepared)
|
|
41
|
+
return;
|
|
38
42
|
await fs.ensureDir(path.dirname(session.file));
|
|
39
|
-
await fs.appendFile(session.file, `${JSON.stringify(
|
|
43
|
+
await fs.appendFile(session.file, `${JSON.stringify(prepared)}\n`, 'utf8');
|
|
40
44
|
}
|
|
45
|
+
/**
|
|
46
|
+
* Read a session file and parse each non-empty line as a JSONL entry.
|
|
47
|
+
*
|
|
48
|
+
* Malformed lines are not silently discarded: they are reported in
|
|
49
|
+
* `parseErrors` (with their 1-based line number) so callers can surface the
|
|
50
|
+
* loss in debug mode instead of silently dropping messages.
|
|
51
|
+
*/
|
|
41
52
|
export async function readSessionEntries(session) {
|
|
42
53
|
const raw = await fs.readFile(session.file, 'utf8');
|
|
43
|
-
|
|
54
|
+
const entries = [];
|
|
55
|
+
const parseErrors = [];
|
|
56
|
+
// Number by true file position: a stray blank line (e.g. from corruption) must not shift
|
|
57
|
+
// the reported line number away from where the malformed line actually sits.
|
|
58
|
+
const lines = raw.split('\n');
|
|
59
|
+
for (let i = 0; i < lines.length; i++) {
|
|
60
|
+
const line = lines[i];
|
|
61
|
+
if (!line)
|
|
62
|
+
continue; // skip blank lines (e.g. the trailing newline)
|
|
44
63
|
try {
|
|
45
|
-
|
|
64
|
+
entries.push(JSON.parse(line));
|
|
46
65
|
}
|
|
47
|
-
catch {
|
|
48
|
-
|
|
66
|
+
catch (error) {
|
|
67
|
+
parseErrors.push(`Line ${i + 1}: ${error instanceof Error ? error.message : String(error)}`);
|
|
49
68
|
}
|
|
50
|
-
}
|
|
69
|
+
}
|
|
70
|
+
return { entries, parseErrors };
|
|
51
71
|
}
|
|
52
72
|
export async function restoreConversation(session) {
|
|
53
|
-
const entries = await readSessionEntries(session);
|
|
73
|
+
const { entries, parseErrors } = await readSessionEntries(session);
|
|
54
74
|
const snapshots = entries.filter((entry) => entry.type === 'conversation_snapshot');
|
|
55
|
-
return snapshots.at(-1)?.messages ?? [];
|
|
75
|
+
return { messages: snapshots.at(-1)?.messages ?? [], parseErrors };
|
|
56
76
|
}
|
|
57
77
|
export async function restoreWorkState(session) {
|
|
58
|
-
const entries = await readSessionEntries(session);
|
|
78
|
+
const { entries, parseErrors } = await readSessionEntries(session);
|
|
59
79
|
const snapshots = entries.filter((entry) => entry.type === 'work_state_snapshot');
|
|
60
|
-
return snapshots.at(-1)?.state;
|
|
80
|
+
return { state: snapshots.at(-1)?.state, parseErrors };
|
|
61
81
|
}
|
|
62
82
|
export function formatSession(session) {
|
|
63
83
|
return `${session.id} · ${session.file}`;
|