@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.
Files changed (160) hide show
  1. package/CHANGELOG.md +42 -7
  2. package/README.md +81 -34
  3. package/dist/cli/chat/TaskBar.d.ts +9 -0
  4. package/dist/cli/chat/TaskBar.js +40 -0
  5. package/dist/cli/chat/chatMetrics.d.ts +11 -0
  6. package/dist/cli/chat/chatMetrics.js +50 -0
  7. package/dist/cli/chat/inputSuggestions.d.ts +16 -0
  8. package/dist/cli/chat/inputSuggestions.js +55 -0
  9. package/dist/cli/chat/messages.d.ts +9 -0
  10. package/dist/cli/chat/messages.js +76 -0
  11. package/dist/cli/chat/sessionRecorder.d.ts +12 -0
  12. package/dist/cli/chat/sessionRecorder.js +21 -0
  13. package/dist/cli/chat/startupInfo.d.ts +4 -0
  14. package/dist/cli/chat/startupInfo.js +53 -0
  15. package/dist/cli/chat/turnState.d.ts +5 -0
  16. package/dist/cli/chat/turnState.js +20 -0
  17. package/dist/cli/commands/chat.d.ts +0 -1
  18. package/dist/cli/commands/chat.js +331 -906
  19. package/dist/cli/commands/chatModes.d.ts +8 -0
  20. package/dist/cli/commands/chatModes.js +44 -0
  21. package/dist/cli/commands/commandHelp.d.ts +6 -0
  22. package/dist/cli/commands/commandHelp.js +25 -0
  23. package/dist/cli/commands/commands.d.ts +1 -1
  24. package/dist/cli/commands/commands.js +41 -267
  25. package/dist/cli/commands/formatters.d.ts +6 -0
  26. package/dist/cli/commands/formatters.js +50 -4
  27. package/dist/cli/commands/initCommand.d.ts +2 -0
  28. package/dist/cli/commands/initCommand.js +19 -0
  29. package/dist/cli/commands/logsCommand.d.ts +2 -0
  30. package/dist/cli/commands/logsCommand.js +63 -0
  31. package/dist/cli/commands/lspWizard.d.ts +14 -0
  32. package/dist/cli/commands/lspWizard.js +44 -0
  33. package/dist/cli/commands/mcpWizard.d.ts +15 -0
  34. package/dist/cli/commands/mcpWizard.js +69 -0
  35. package/dist/cli/commands/modelCommand.d.ts +2 -0
  36. package/dist/cli/commands/modelCommand.js +36 -0
  37. package/dist/cli/commands/providerWizard.d.ts +30 -0
  38. package/dist/cli/commands/providerWizard.js +114 -0
  39. package/dist/cli/commands/runCommand.d.ts +16 -0
  40. package/dist/cli/commands/runCommand.js +170 -0
  41. package/dist/cli/commands/settingsSummary.d.ts +3 -0
  42. package/dist/cli/commands/settingsSummary.js +40 -0
  43. package/dist/cli/commands/skillConfirmRemove.d.ts +11 -0
  44. package/dist/cli/commands/skillConfirmRemove.js +19 -0
  45. package/dist/cli/commands/skillCreation.d.ts +12 -0
  46. package/dist/cli/commands/skillCreation.js +14 -0
  47. package/dist/cli/commands/skillWizard.d.ts +15 -0
  48. package/dist/cli/commands/skillWizard.js +38 -0
  49. package/dist/cli/commands/streaming/assistantText.d.ts +17 -0
  50. package/dist/cli/commands/streaming/assistantText.js +115 -0
  51. package/dist/cli/commands/streaming/toolGroupRenderer.d.ts +55 -0
  52. package/dist/cli/commands/streaming/toolGroupRenderer.js +102 -0
  53. package/dist/cli/commands/streaming/toolResultState.d.ts +13 -0
  54. package/dist/cli/commands/streaming/toolResultState.js +25 -0
  55. package/dist/cli/commands/streaming/turnRuntime.d.ts +78 -0
  56. package/dist/cli/commands/streaming/turnRuntime.js +86 -0
  57. package/dist/cli/commands/streaming.d.ts +9 -25
  58. package/dist/cli/commands/streaming.js +109 -363
  59. package/dist/cli/commands/wizardActions.d.ts +40 -0
  60. package/dist/cli/commands/wizardActions.js +40 -0
  61. package/dist/cli/commands/wizardInput.d.ts +4 -0
  62. package/dist/cli/commands/wizardInput.js +19 -0
  63. package/dist/cli/commands/wizardPrompts.d.ts +22 -0
  64. package/dist/cli/commands/wizardPrompts.js +52 -0
  65. package/dist/cli/commands/wizardSuggestions.d.ts +23 -0
  66. package/dist/cli/commands/wizardSuggestions.js +139 -0
  67. package/dist/cli/index.js +62 -4
  68. package/dist/config/contextFiles.d.ts +8 -1
  69. package/dist/config/contextFiles.js +25 -12
  70. package/dist/config/lspSettings.js +3 -6
  71. package/dist/config/mcpSettings.js +5 -5
  72. package/dist/config/providers.js +8 -12
  73. package/dist/config/settings.d.ts +1 -0
  74. package/dist/config/settings.js +54 -2
  75. package/dist/config/skillSettings.js +4 -3
  76. package/dist/core/agent/budgets.d.ts +6 -0
  77. package/dist/core/agent/budgets.js +6 -0
  78. package/dist/core/agent/compaction.js +3 -3
  79. package/dist/core/agent/errors.js +1 -1
  80. package/dist/core/agent/requestAssembly.d.ts +1 -7
  81. package/dist/core/agent/requestAssembly.js +40 -5
  82. package/dist/core/agent/toolOutputStore.js +5 -4
  83. package/dist/core/agent/toolResults.d.ts +31 -0
  84. package/dist/core/agent/toolResults.js +42 -0
  85. package/dist/core/agent/turnPolicy.d.ts +8 -0
  86. package/dist/core/agent/turnPolicy.js +23 -0
  87. package/dist/core/agent/workState.d.ts +18 -5
  88. package/dist/core/agent/workState.js +39 -20
  89. package/dist/core/bashOutput/reducers/content.d.ts +1 -0
  90. package/dist/core/bashOutput/reducers/content.js +1 -1
  91. package/dist/core/bashOutput/reducers/gh.d.ts +1 -0
  92. package/dist/core/bashOutput/reducers/gh.js +77 -0
  93. package/dist/core/bashOutput/registry.js +18 -8
  94. package/dist/core/goal/completionPolicy.js +1 -1
  95. package/dist/core/goal/sessionGoal.d.ts +6 -30
  96. package/dist/core/goal/sessionGoal.js +3 -68
  97. package/dist/core/safety/bashClassifier.js +30 -0
  98. package/dist/core/safety/urlGuard.d.ts +1 -0
  99. package/dist/core/safety/urlGuard.js +6 -1
  100. package/dist/core/session/sessionSlimming.d.ts +5 -0
  101. package/dist/core/session/sessionSlimming.js +78 -0
  102. package/dist/core/session/sessionStore.d.ts +23 -3
  103. package/dist/core/session/sessionStore.js +30 -10
  104. package/dist/core/subagent/subagentRunner.d.ts +258 -5
  105. package/dist/core/subagent/subagentRunner.js +14 -18
  106. package/dist/core/toolOutput/reduction.d.ts +2 -0
  107. package/dist/core/toolOutput/reduction.js +12 -0
  108. package/dist/core/validation/outputParser.js +5 -3
  109. package/dist/llm/capabilities.d.ts +12 -0
  110. package/dist/llm/capabilities.js +10 -0
  111. package/dist/llm/client.d.ts +3 -2
  112. package/dist/llm/client.js +26 -4
  113. package/dist/llm/hazeTools.d.ts +7710 -366
  114. package/dist/llm/hazeTools.js +46 -567
  115. package/dist/llm/initPrompt.js +1 -1
  116. package/dist/llm/lsp.d.ts +46 -1
  117. package/dist/llm/lsp.js +19 -10
  118. package/dist/llm/lspTools.d.ts +2310 -119
  119. package/dist/llm/mcp.js +9 -0
  120. package/dist/llm/requestContext.js +7 -22
  121. package/dist/llm/systemPrompt.d.ts +1 -0
  122. package/dist/llm/systemPrompt.js +3 -3
  123. package/dist/llm/tools/bashTool.d.ts +251 -0
  124. package/dist/llm/tools/bashTool.js +82 -0
  125. package/dist/llm/tools/editMatch.d.ts +55 -0
  126. package/dist/llm/tools/editMatch.js +99 -0
  127. package/dist/llm/tools/failures.d.ts +36 -0
  128. package/dist/llm/tools/failures.js +38 -0
  129. package/dist/llm/tools/fetchTool.d.ts +1201 -0
  130. package/dist/llm/tools/fetchTool.js +46 -0
  131. package/dist/llm/tools/fileToolShared.d.ts +10 -0
  132. package/dist/llm/tools/fileToolShared.js +43 -0
  133. package/dist/llm/tools/grepParse.d.ts +13 -0
  134. package/dist/llm/tools/grepParse.js +67 -0
  135. package/dist/llm/tools/outputCap.d.ts +53 -0
  136. package/dist/llm/tools/outputCap.js +67 -0
  137. package/dist/llm/tools/storedOutputTool.d.ts +351 -0
  138. package/dist/llm/tools/storedOutputTool.js +17 -0
  139. package/dist/llm/tools/taskTool.d.ts +629 -0
  140. package/dist/llm/tools/taskTool.js +41 -0
  141. package/dist/llm/tools/toolContext.d.ts +74 -0
  142. package/dist/llm/tools/toolContext.js +196 -0
  143. package/dist/llm/tools/workspaceFile.d.ts +33 -0
  144. package/dist/llm/tools/workspaceFile.js +27 -0
  145. package/dist/llm/webFetch.d.ts +13 -1
  146. package/dist/llm/webFetch.js +122 -28
  147. package/dist/skills/builder/SkillBuilder.d.ts +3 -0
  148. package/dist/skills/builder/SkillBuilder.js +8 -8
  149. package/dist/ui/components/TextInput.d.ts +7 -0
  150. package/dist/ui/components/TextInput.js +10 -98
  151. package/dist/ui/inputBuffer.d.ts +28 -0
  152. package/dist/ui/inputBuffer.js +99 -0
  153. package/dist/utils/collections.d.ts +6 -0
  154. package/dist/utils/collections.js +9 -0
  155. package/dist/utils/modelName.d.ts +2 -0
  156. package/dist/utils/modelName.js +15 -0
  157. package/dist/utils/path.d.ts +2 -0
  158. package/dist/utils/path.js +40 -0
  159. package/examples/skills/files/SKILL.md +1 -1
  160. package/package.json +14 -15
@@ -0,0 +1,46 @@
1
+ import { tool } from 'ai';
2
+ import { z } from 'zod';
3
+ import { reductionMetrics } from '../../core/toolOutput/reduction.js';
4
+ import { fetchUrlContent, BlockedUrlError } from '../webFetch.js';
5
+ import { structuredToolFailure } from './failures.js';
6
+ import { compactStoredOutput } from './outputCap.js';
7
+ import { hazeToolContextSchema, runDedupedTool } from './toolContext.js';
8
+ const MAX_OUTPUT_CHARS = 50_000;
9
+ export const fetchTool = tool({
10
+ description: 'Fetch a public http(s) URL and return readable content. Use for current docs, API references, error lookups, or CI logs. Private/loopback/metadata hosts are blocked.',
11
+ contextSchema: hazeToolContextSchema,
12
+ inputSchema: z.object({
13
+ url: z.string().url().describe('Absolute http(s) URL to fetch'),
14
+ format: z.enum(['auto', 'text']).default('auto').describe('auto = markdown for HTML, pretty for JSON, passthrough for text; text = raw text only'),
15
+ }),
16
+ execute: async ({ url, format }, context) => runDedupedTool('fetch', { url, format }, context, async () => {
17
+ try {
18
+ const result = await fetchUrlContent(url, { signal: context.abortSignal, format });
19
+ const capped = compactStoredOutput(result.content, MAX_OUTPUT_CHARS);
20
+ const extractionMethod = format === 'text' ? 'text' : result.extractionMethod;
21
+ const fetchMetrics = reductionMetrics(result.content, capped.text);
22
+ return {
23
+ ok: true,
24
+ url: result.url,
25
+ status: result.status,
26
+ statusText: result.statusText,
27
+ contentType: result.contentType,
28
+ bytes: result.bytes,
29
+ redirected: result.redirected,
30
+ extractionMethod,
31
+ truncated: capped.truncated,
32
+ content: capped.text,
33
+ reducerName: extractionMethod === 'markdown' ? 'web-html-extract' : 'web-content-cap',
34
+ contentKind: 'web',
35
+ lossy: capped.truncated || extractionMethod === 'markdown',
36
+ parseTier: 'full',
37
+ ...fetchMetrics,
38
+ ...(capped.handle ? { handle: capped.handle, rawHandle: capped.handle, omittedChars: capped.omittedChars } : { omittedChars: 0 }),
39
+ };
40
+ }
41
+ catch (error) {
42
+ const reasonCode = error instanceof BlockedUrlError ? 'blocked_url' : undefined;
43
+ return structuredToolFailure('fetch', error, 'Check the URL is correct and public. Private/localhost/metadata hosts and non-http(s) schemes are blocked.', url, { reasonCode });
44
+ }
45
+ }),
46
+ });
@@ -0,0 +1,10 @@
1
+ export declare const MAX_OUTPUT_CHARS = 50000;
2
+ export declare const DEFAULT_READ_LINES = 300;
3
+ /** Inline diff lines beyond this count are omitted (just the count is returned). */
4
+ export declare const INLINE_DIFF_LINE_LIMIT = 20;
5
+ export declare function isGitIgnored(absolutePath: string): Promise<boolean>;
6
+ export declare function assertNotIgnored(absolutePath: string, inputPath: string, allowIgnored?: boolean): Promise<void>;
7
+ export declare function sourceOutlineEntries(lines: string[], startLine: number): {
8
+ lineNumber: number;
9
+ text: string;
10
+ }[];
@@ -0,0 +1,43 @@
1
+ import { execFile as execFileCallback } from 'node:child_process';
2
+ import { promisify } from 'node:util';
3
+ import { workspaceRelativePath, workspaceRoot } from '../../utils/path.js';
4
+ import { HazeToolError } from './failures.js';
5
+ const execFile = promisify(execFileCallback);
6
+ export const MAX_OUTPUT_CHARS = 50_000;
7
+ export const DEFAULT_READ_LINES = 300;
8
+ /** Inline diff lines beyond this count are omitted (just the count is returned). */
9
+ export const INLINE_DIFF_LINE_LIMIT = 20;
10
+ export async function isGitIgnored(absolutePath) {
11
+ const relative = workspaceRelativePath(absolutePath);
12
+ if (relative === '.')
13
+ return false;
14
+ try {
15
+ await execFile('git', ['-C', workspaceRoot(), 'check-ignore', '-q', '--', relative]);
16
+ return true;
17
+ }
18
+ catch (error) {
19
+ const status = typeof error === 'object' && error != null && 'code' in error ? error.code : undefined;
20
+ if (status === 1 || status === 128)
21
+ return false;
22
+ return false;
23
+ }
24
+ }
25
+ export async function assertNotIgnored(absolutePath, inputPath, allowIgnored) {
26
+ if (!allowIgnored && await isGitIgnored(absolutePath)) {
27
+ throw new HazeToolError(`Path is ignored by .gitignore: ${inputPath}. Set allowIgnored=true only if you explicitly need to access ignored files.`, 'ignored_path', { recoveryTool: 'listFiles' });
28
+ }
29
+ }
30
+ const SOURCE_OUTLINE_PATTERNS = [
31
+ /^\s*(?:import|from|export|package|namespace|module|using)\b/,
32
+ /^\s*#\s*include\b/,
33
+ /^\s*(?:public|private|protected|internal|static|async|final|open|sealed|abstract|export\s+)?\s*(?:class|interface|struct|enum|type|trait|record|protocol)\b/,
34
+ /^\s*(?:export\s+)?(?:async\s+)?function\b/,
35
+ /^\s*(?:def|func|fn)\s+[A-Za-z_]/,
36
+ /^\s*(?:pub\s+)?(?:async\s+)?fn\s+[A-Za-z_]/,
37
+ /^\s*(?:public|private|protected|internal|static|async|final|override|virtual|abstract)\s+[^=;{}]+\([^)]*\)\s*(?:\{|;|=>)?\s*$/,
38
+ ];
39
+ export function sourceOutlineEntries(lines, startLine) {
40
+ return lines
41
+ .map((line, index) => ({ lineNumber: startLine + index, text: line }))
42
+ .filter(entry => SOURCE_OUTLINE_PATTERNS.some(pattern => pattern.test(entry.text)));
43
+ }
@@ -0,0 +1,13 @@
1
+ export type GrepMatchItem = {
2
+ file: string;
3
+ line: number;
4
+ content: string;
5
+ isContext: boolean;
6
+ };
7
+ export type ParsedGrepOutput = {
8
+ matches: GrepMatchItem[];
9
+ totalMatches: number;
10
+ returnedMatches: number;
11
+ omittedMatches: number;
12
+ };
13
+ export declare function parseRipgrepJsonStream(stdout: string, maxMatches: number, contextLines: number, toRelativePath?: (absolute: string) => string): ParsedGrepOutput;
@@ -0,0 +1,67 @@
1
+ function isContextEvent(event) {
2
+ return event.type === 'context';
3
+ }
4
+ function isMatchEvent(event) {
5
+ return event.type === 'match';
6
+ }
7
+ function extractMatchItem(event) {
8
+ const file = event.data?.path?.text;
9
+ const lineNumber = event.data?.line_number;
10
+ const content = event.data?.lines?.text?.replace(/\r?\n$/, '');
11
+ if (!file || lineNumber == null || content == null)
12
+ return undefined;
13
+ return { file, line: lineNumber, content, isContext: isMatchEvent(event) ? false : true };
14
+ }
15
+ export function parseRipgrepJsonStream(stdout, maxMatches, contextLines, toRelativePath = value => value) {
16
+ if (!stdout)
17
+ return { matches: [], totalMatches: 0, returnedMatches: 0, omittedMatches: 0 };
18
+ const lines = stdout.split('\n').filter(Boolean);
19
+ const matches = [];
20
+ let totalMatches = 0;
21
+ let returnedMatches = 0;
22
+ let omittedMatches = 0;
23
+ let pendingContext = [];
24
+ let retainFollowingContext = false;
25
+ for (const line of lines) {
26
+ let event;
27
+ try {
28
+ event = JSON.parse(line);
29
+ }
30
+ catch {
31
+ continue;
32
+ }
33
+ if (event.type === 'begin' || event.type === 'end') {
34
+ pendingContext = [];
35
+ retainFollowingContext = false;
36
+ continue;
37
+ }
38
+ if (!isContextEvent(event) && !isMatchEvent(event))
39
+ continue;
40
+ const item = extractMatchItem(event);
41
+ if (!item)
42
+ continue;
43
+ const relative = { ...item, file: toRelativePath(item.file) };
44
+ if (isContextEvent(event)) {
45
+ if (retainFollowingContext) {
46
+ matches.push(relative);
47
+ continue;
48
+ }
49
+ pendingContext.push(relative);
50
+ if (pendingContext.length > contextLines)
51
+ pendingContext.shift();
52
+ continue;
53
+ }
54
+ totalMatches += 1;
55
+ if (returnedMatches >= maxMatches) {
56
+ omittedMatches += 1;
57
+ pendingContext = [];
58
+ retainFollowingContext = false;
59
+ continue;
60
+ }
61
+ matches.push(...pendingContext, relative);
62
+ returnedMatches += 1;
63
+ pendingContext = [];
64
+ retainFollowingContext = true;
65
+ }
66
+ return { matches, totalMatches, returnedMatches, omittedMatches };
67
+ }
@@ -0,0 +1,53 @@
1
+ /** Default ceiling for capped tool outputs (bash, fetch). */
2
+ export declare const COMPACT_COMMAND_CHARS = 12000;
3
+ /** Default ceiling for rendered grep output. */
4
+ export declare const GREP_MAX_OUTPUT_CHARS = 30000;
5
+ /** Default ceiling for a single grep match line. */
6
+ export declare const GREP_MAX_LINE_CHARS = 500;
7
+ /**
8
+ * Cap a string to `maxChars` characters, keeping a head + tail and storing the
9
+ * full text behind a `readToolOutput` handle so nothing is lost.
10
+ */
11
+ export declare function compactStoredOutput(text: string, maxChars?: number): {
12
+ text: string;
13
+ truncated: boolean;
14
+ omittedChars?: undefined;
15
+ handle?: undefined;
16
+ } | {
17
+ text: string;
18
+ truncated: boolean;
19
+ omittedChars: number;
20
+ handle: string;
21
+ };
22
+ /** Truncate a single over-long line in place. */
23
+ export declare function compactLine(text: string, maxChars?: number): {
24
+ text: string;
25
+ truncated: boolean;
26
+ };
27
+ /** Render structured grep matches as `file:line:content` lines (context flagged with `-`). */
28
+ export declare function renderGrepMatches(matches: Array<{
29
+ file: string;
30
+ line: number;
31
+ content: string;
32
+ isContext: boolean;
33
+ }>): string;
34
+ /**
35
+ * Compact grep matches to a byte budget, truncating individual lines and
36
+ * dropping trailing matches once the estimated serialized size is exceeded.
37
+ */
38
+ export declare function compactGrepMatches(matches: Array<{
39
+ file: string;
40
+ line: number;
41
+ content: string;
42
+ isContext: boolean;
43
+ }>, maxChars?: number): {
44
+ matches: {
45
+ file: string;
46
+ line: number;
47
+ content: string;
48
+ isContext: boolean;
49
+ }[];
50
+ lineTruncated: boolean;
51
+ omittedResultLines: number;
52
+ outputTruncated: boolean;
53
+ };
@@ -0,0 +1,67 @@
1
+ import { storeToolOutput } from '../../core/agent/toolOutputStore.js';
2
+ /** Default ceiling for capped tool outputs (bash, fetch). */
3
+ export const COMPACT_COMMAND_CHARS = 12_000;
4
+ /** Default ceiling for rendered grep output. */
5
+ export const GREP_MAX_OUTPUT_CHARS = 30_000;
6
+ /** Default ceiling for a single grep match line. */
7
+ export const GREP_MAX_LINE_CHARS = 500;
8
+ /**
9
+ * Cap a string to `maxChars` characters, keeping a head + tail and storing the
10
+ * full text behind a `readToolOutput` handle so nothing is lost.
11
+ */
12
+ export function compactStoredOutput(text, maxChars = COMPACT_COMMAND_CHARS) {
13
+ if (text.length <= maxChars)
14
+ return { text, truncated: false };
15
+ const handle = storeToolOutput(text);
16
+ const headChars = Math.floor(maxChars * 0.4);
17
+ const tailChars = maxChars - headChars;
18
+ return {
19
+ text: `${text.slice(0, headChars)}\n\n[... ${text.length - maxChars} characters omitted; use readToolOutput with handle ${handle} ...]\n\n${text.slice(-tailChars)}`,
20
+ truncated: true,
21
+ omittedChars: text.length - maxChars,
22
+ handle,
23
+ };
24
+ }
25
+ /** Truncate a single over-long line in place. */
26
+ export function compactLine(text, maxChars = GREP_MAX_LINE_CHARS) {
27
+ if (text.length <= maxChars)
28
+ return { text, truncated: false };
29
+ return { text: `${text.slice(0, Math.max(0, maxChars - 22))}[line truncated]`, truncated: true };
30
+ }
31
+ /** Render structured grep matches as `file:line:content` lines (context flagged with `-`). */
32
+ export function renderGrepMatches(matches) {
33
+ return matches.map(match => `${match.file}:${match.line}:${match.isContext ? '-' : ''}${match.content}`).join('\n');
34
+ }
35
+ /**
36
+ * Compact grep matches to a byte budget, truncating individual lines and
37
+ * dropping trailing matches once the estimated serialized size is exceeded.
38
+ */
39
+ export function compactGrepMatches(matches, maxChars = GREP_MAX_OUTPUT_CHARS) {
40
+ const compacted = [];
41
+ let lineTruncated = false;
42
+ let omittedResultLines = 0;
43
+ // Estimate the serialized size incrementally to keep this O(n) rather than
44
+ // re-serializing the whole accumulated array on every iteration (O(n²)).
45
+ // We approximate the JSON shape: a `[`/`]` wrapper, per-object structural
46
+ // overhead (keys, quotes, braces, separators), and the field values
47
+ // themselves. This is slightly tighter than a real `JSON.stringify` would
48
+ // be (it ignores escaping of `"`, `\`, and control chars in `content`),
49
+ // which is the safe direction for a soft truncation ceiling.
50
+ const itemSeparatorChars = 2; // `, ` between objects in the serialized array.
51
+ const objectOverheadChars = 30; // keys + quotes + braces + structural separators.
52
+ const arrayWrapperChars = 2; // the surrounding `[` and `]`.
53
+ let estimatedSize = arrayWrapperChars;
54
+ for (const match of matches) {
55
+ const line = compactLine(match.content);
56
+ lineTruncated = lineTruncated || line.truncated;
57
+ const lineText = line.text;
58
+ const itemSize = objectOverheadChars + match.file.length + String(match.line).length + lineText.length;
59
+ if (estimatedSize + itemSize > maxChars) {
60
+ omittedResultLines = matches.length - compacted.length;
61
+ break;
62
+ }
63
+ estimatedSize += itemSize + itemSeparatorChars;
64
+ compacted.push({ ...match, content: lineText });
65
+ }
66
+ return { matches: compacted, lineTruncated, omittedResultLines, outputTruncated: omittedResultLines > 0 || lineTruncated };
67
+ }
@@ -0,0 +1,351 @@
1
+ export declare const readToolOutputTool: ({
2
+ title?: string;
3
+ providerOptions?: import("@ai-sdk/provider-utils").ProviderOptions;
4
+ metadata?: import("@ai-sdk/provider").JSONObject;
5
+ inputSchema: import("ai").FlexibleSchema<{
6
+ handle: string;
7
+ offset: number;
8
+ limit: number;
9
+ contextLines: number;
10
+ query?: string | undefined;
11
+ }>;
12
+ contextSchema?: import("ai").FlexibleSchema<import("@ai-sdk/provider-utils").Context> | undefined;
13
+ needsApproval?: boolean | import("@ai-sdk/provider-utils").ToolNeedsApprovalFunction<{
14
+ handle: string;
15
+ offset: number;
16
+ limit: number;
17
+ contextLines: number;
18
+ query?: string | undefined;
19
+ }, NoInfer<import("@ai-sdk/provider-utils").Context>> | undefined;
20
+ onInputStart?: ((options: import("ai").ToolExecutionOptions<NoInfer<import("@ai-sdk/provider-utils").Context>>) => void | PromiseLike<void>) | undefined;
21
+ onInputDelta?: ((options: {
22
+ inputTextDelta: string;
23
+ } & import("ai").ToolExecutionOptions<NoInfer<import("@ai-sdk/provider-utils").Context>>) => void | PromiseLike<void>) | undefined;
24
+ onInputAvailable?: ((options: {
25
+ input: {
26
+ handle: string;
27
+ offset: number;
28
+ limit: number;
29
+ contextLines: number;
30
+ query?: string | undefined;
31
+ };
32
+ } & import("ai").ToolExecutionOptions<NoInfer<import("@ai-sdk/provider-utils").Context>>) => void | PromiseLike<void>) | undefined;
33
+ toModelOutput?: ((options: {
34
+ toolCallId: string;
35
+ input: {
36
+ handle: string;
37
+ offset: number;
38
+ limit: number;
39
+ contextLines: number;
40
+ query?: string | undefined;
41
+ };
42
+ output: NoInfer<import("../../core/agent/toolOutputStore.js").StoredToolOutputPage | {
43
+ ok: boolean;
44
+ error: string;
45
+ }>;
46
+ }) => import("@ai-sdk/provider-utils").ToolResultOutput | PromiseLike<import("@ai-sdk/provider-utils").ToolResultOutput>) | undefined;
47
+ } & {
48
+ outputSchema?: import("ai").FlexibleSchema<import("../../core/agent/toolOutputStore.js").StoredToolOutputPage | {
49
+ ok: boolean;
50
+ error: string;
51
+ }> | undefined;
52
+ execute: import("ai").ToolExecuteFunction<{
53
+ handle: string;
54
+ offset: number;
55
+ limit: number;
56
+ contextLines: number;
57
+ query?: string | undefined;
58
+ }, import("../../core/agent/toolOutputStore.js").StoredToolOutputPage | {
59
+ ok: boolean;
60
+ error: string;
61
+ }, NoInfer<import("@ai-sdk/provider-utils").Context>>;
62
+ } & {
63
+ description?: string | ((options: {
64
+ context: NoInfer<import("@ai-sdk/provider-utils").Context>;
65
+ experimental_sandbox?: import("ai").Experimental_SandboxSession;
66
+ }) => string) | undefined;
67
+ strict?: boolean;
68
+ inputExamples?: {
69
+ input: NoInfer<{
70
+ handle: string;
71
+ offset: number;
72
+ limit: number;
73
+ contextLines: number;
74
+ query?: string | undefined;
75
+ }>;
76
+ }[] | undefined;
77
+ id?: never;
78
+ isProviderExecuted?: never;
79
+ args?: never;
80
+ supportsDeferredResults?: never;
81
+ } & {
82
+ type?: undefined | "function";
83
+ } & {
84
+ execute: import("ai").ToolExecuteFunction<{
85
+ handle: string;
86
+ offset: number;
87
+ limit: number;
88
+ contextLines: number;
89
+ query?: string | undefined;
90
+ }, import("../../core/agent/toolOutputStore.js").StoredToolOutputPage | {
91
+ ok: boolean;
92
+ error: string;
93
+ }, NoInfer<import("@ai-sdk/provider-utils").Context>>;
94
+ }) | ({
95
+ title?: string;
96
+ providerOptions?: import("@ai-sdk/provider-utils").ProviderOptions;
97
+ metadata?: import("@ai-sdk/provider").JSONObject;
98
+ inputSchema: import("ai").FlexibleSchema<{
99
+ handle: string;
100
+ offset: number;
101
+ limit: number;
102
+ contextLines: number;
103
+ query?: string | undefined;
104
+ }>;
105
+ contextSchema?: import("ai").FlexibleSchema<import("@ai-sdk/provider-utils").Context> | undefined;
106
+ needsApproval?: boolean | import("@ai-sdk/provider-utils").ToolNeedsApprovalFunction<{
107
+ handle: string;
108
+ offset: number;
109
+ limit: number;
110
+ contextLines: number;
111
+ query?: string | undefined;
112
+ }, NoInfer<import("@ai-sdk/provider-utils").Context>> | undefined;
113
+ onInputStart?: ((options: import("ai").ToolExecutionOptions<NoInfer<import("@ai-sdk/provider-utils").Context>>) => void | PromiseLike<void>) | undefined;
114
+ onInputDelta?: ((options: {
115
+ inputTextDelta: string;
116
+ } & import("ai").ToolExecutionOptions<NoInfer<import("@ai-sdk/provider-utils").Context>>) => void | PromiseLike<void>) | undefined;
117
+ onInputAvailable?: ((options: {
118
+ input: {
119
+ handle: string;
120
+ offset: number;
121
+ limit: number;
122
+ contextLines: number;
123
+ query?: string | undefined;
124
+ };
125
+ } & import("ai").ToolExecutionOptions<NoInfer<import("@ai-sdk/provider-utils").Context>>) => void | PromiseLike<void>) | undefined;
126
+ toModelOutput?: ((options: {
127
+ toolCallId: string;
128
+ input: {
129
+ handle: string;
130
+ offset: number;
131
+ limit: number;
132
+ contextLines: number;
133
+ query?: string | undefined;
134
+ };
135
+ output: NoInfer<import("../../core/agent/toolOutputStore.js").StoredToolOutputPage | {
136
+ ok: boolean;
137
+ error: string;
138
+ }>;
139
+ }) => import("@ai-sdk/provider-utils").ToolResultOutput | PromiseLike<import("@ai-sdk/provider-utils").ToolResultOutput>) | undefined;
140
+ } & {
141
+ outputSchema?: import("ai").FlexibleSchema<import("../../core/agent/toolOutputStore.js").StoredToolOutputPage | {
142
+ ok: boolean;
143
+ error: string;
144
+ }> | undefined;
145
+ execute: import("ai").ToolExecuteFunction<{
146
+ handle: string;
147
+ offset: number;
148
+ limit: number;
149
+ contextLines: number;
150
+ query?: string | undefined;
151
+ }, import("../../core/agent/toolOutputStore.js").StoredToolOutputPage | {
152
+ ok: boolean;
153
+ error: string;
154
+ }, NoInfer<import("@ai-sdk/provider-utils").Context>>;
155
+ } & {
156
+ description?: string | ((options: {
157
+ context: NoInfer<import("@ai-sdk/provider-utils").Context>;
158
+ experimental_sandbox?: import("ai").Experimental_SandboxSession;
159
+ }) => string) | undefined;
160
+ strict?: boolean;
161
+ inputExamples?: {
162
+ input: NoInfer<{
163
+ handle: string;
164
+ offset: number;
165
+ limit: number;
166
+ contextLines: number;
167
+ query?: string | undefined;
168
+ }>;
169
+ }[] | undefined;
170
+ id?: never;
171
+ isProviderExecuted?: never;
172
+ args?: never;
173
+ supportsDeferredResults?: never;
174
+ } & {
175
+ type: "dynamic";
176
+ } & {
177
+ execute: import("ai").ToolExecuteFunction<{
178
+ handle: string;
179
+ offset: number;
180
+ limit: number;
181
+ contextLines: number;
182
+ query?: string | undefined;
183
+ }, import("../../core/agent/toolOutputStore.js").StoredToolOutputPage | {
184
+ ok: boolean;
185
+ error: string;
186
+ }, NoInfer<import("@ai-sdk/provider-utils").Context>>;
187
+ }) | ({
188
+ title?: string;
189
+ providerOptions?: import("@ai-sdk/provider-utils").ProviderOptions;
190
+ metadata?: import("@ai-sdk/provider").JSONObject;
191
+ inputSchema: import("ai").FlexibleSchema<{
192
+ handle: string;
193
+ offset: number;
194
+ limit: number;
195
+ contextLines: number;
196
+ query?: string | undefined;
197
+ }>;
198
+ contextSchema?: import("ai").FlexibleSchema<import("@ai-sdk/provider-utils").Context> | undefined;
199
+ needsApproval?: boolean | import("@ai-sdk/provider-utils").ToolNeedsApprovalFunction<{
200
+ handle: string;
201
+ offset: number;
202
+ limit: number;
203
+ contextLines: number;
204
+ query?: string | undefined;
205
+ }, NoInfer<import("@ai-sdk/provider-utils").Context>> | undefined;
206
+ onInputStart?: ((options: import("ai").ToolExecutionOptions<NoInfer<import("@ai-sdk/provider-utils").Context>>) => void | PromiseLike<void>) | undefined;
207
+ onInputDelta?: ((options: {
208
+ inputTextDelta: string;
209
+ } & import("ai").ToolExecutionOptions<NoInfer<import("@ai-sdk/provider-utils").Context>>) => void | PromiseLike<void>) | undefined;
210
+ onInputAvailable?: ((options: {
211
+ input: {
212
+ handle: string;
213
+ offset: number;
214
+ limit: number;
215
+ contextLines: number;
216
+ query?: string | undefined;
217
+ };
218
+ } & import("ai").ToolExecutionOptions<NoInfer<import("@ai-sdk/provider-utils").Context>>) => void | PromiseLike<void>) | undefined;
219
+ toModelOutput?: ((options: {
220
+ toolCallId: string;
221
+ input: {
222
+ handle: string;
223
+ offset: number;
224
+ limit: number;
225
+ contextLines: number;
226
+ query?: string | undefined;
227
+ };
228
+ output: NoInfer<import("../../core/agent/toolOutputStore.js").StoredToolOutputPage | {
229
+ ok: boolean;
230
+ error: string;
231
+ }>;
232
+ }) => import("@ai-sdk/provider-utils").ToolResultOutput | PromiseLike<import("@ai-sdk/provider-utils").ToolResultOutput>) | undefined;
233
+ } & {
234
+ outputSchema?: import("ai").FlexibleSchema<import("../../core/agent/toolOutputStore.js").StoredToolOutputPage | {
235
+ ok: boolean;
236
+ error: string;
237
+ }> | undefined;
238
+ execute: import("ai").ToolExecuteFunction<{
239
+ handle: string;
240
+ offset: number;
241
+ limit: number;
242
+ contextLines: number;
243
+ query?: string | undefined;
244
+ }, import("../../core/agent/toolOutputStore.js").StoredToolOutputPage | {
245
+ ok: boolean;
246
+ error: string;
247
+ }, NoInfer<import("@ai-sdk/provider-utils").Context>>;
248
+ } & {
249
+ type: "provider";
250
+ id: `${string}.${string}`;
251
+ args: Record<string, unknown>;
252
+ description?: never;
253
+ strict?: never;
254
+ inputExamples?: never;
255
+ } & {
256
+ isProviderExecuted: false;
257
+ supportsDeferredResults?: never;
258
+ } & {
259
+ execute: import("ai").ToolExecuteFunction<{
260
+ handle: string;
261
+ offset: number;
262
+ limit: number;
263
+ contextLines: number;
264
+ query?: string | undefined;
265
+ }, import("../../core/agent/toolOutputStore.js").StoredToolOutputPage | {
266
+ ok: boolean;
267
+ error: string;
268
+ }, NoInfer<import("@ai-sdk/provider-utils").Context>>;
269
+ }) | ({
270
+ title?: string;
271
+ providerOptions?: import("@ai-sdk/provider-utils").ProviderOptions;
272
+ metadata?: import("@ai-sdk/provider").JSONObject;
273
+ inputSchema: import("ai").FlexibleSchema<{
274
+ handle: string;
275
+ offset: number;
276
+ limit: number;
277
+ contextLines: number;
278
+ query?: string | undefined;
279
+ }>;
280
+ contextSchema?: import("ai").FlexibleSchema<import("@ai-sdk/provider-utils").Context> | undefined;
281
+ needsApproval?: boolean | import("@ai-sdk/provider-utils").ToolNeedsApprovalFunction<{
282
+ handle: string;
283
+ offset: number;
284
+ limit: number;
285
+ contextLines: number;
286
+ query?: string | undefined;
287
+ }, NoInfer<import("@ai-sdk/provider-utils").Context>> | undefined;
288
+ onInputStart?: ((options: import("ai").ToolExecutionOptions<NoInfer<import("@ai-sdk/provider-utils").Context>>) => void | PromiseLike<void>) | undefined;
289
+ onInputDelta?: ((options: {
290
+ inputTextDelta: string;
291
+ } & import("ai").ToolExecutionOptions<NoInfer<import("@ai-sdk/provider-utils").Context>>) => void | PromiseLike<void>) | undefined;
292
+ onInputAvailable?: ((options: {
293
+ input: {
294
+ handle: string;
295
+ offset: number;
296
+ limit: number;
297
+ contextLines: number;
298
+ query?: string | undefined;
299
+ };
300
+ } & import("ai").ToolExecutionOptions<NoInfer<import("@ai-sdk/provider-utils").Context>>) => void | PromiseLike<void>) | undefined;
301
+ toModelOutput?: ((options: {
302
+ toolCallId: string;
303
+ input: {
304
+ handle: string;
305
+ offset: number;
306
+ limit: number;
307
+ contextLines: number;
308
+ query?: string | undefined;
309
+ };
310
+ output: NoInfer<import("../../core/agent/toolOutputStore.js").StoredToolOutputPage | {
311
+ ok: boolean;
312
+ error: string;
313
+ }>;
314
+ }) => import("@ai-sdk/provider-utils").ToolResultOutput | PromiseLike<import("@ai-sdk/provider-utils").ToolResultOutput>) | undefined;
315
+ } & {
316
+ outputSchema?: import("ai").FlexibleSchema<import("../../core/agent/toolOutputStore.js").StoredToolOutputPage | {
317
+ ok: boolean;
318
+ error: string;
319
+ }> | undefined;
320
+ execute: import("ai").ToolExecuteFunction<{
321
+ handle: string;
322
+ offset: number;
323
+ limit: number;
324
+ contextLines: number;
325
+ query?: string | undefined;
326
+ }, import("../../core/agent/toolOutputStore.js").StoredToolOutputPage | {
327
+ ok: boolean;
328
+ error: string;
329
+ }, NoInfer<import("@ai-sdk/provider-utils").Context>>;
330
+ } & {
331
+ type: "provider";
332
+ id: `${string}.${string}`;
333
+ args: Record<string, unknown>;
334
+ description?: never;
335
+ strict?: never;
336
+ inputExamples?: never;
337
+ } & {
338
+ isProviderExecuted: true;
339
+ supportsDeferredResults?: boolean;
340
+ } & {
341
+ execute: import("ai").ToolExecuteFunction<{
342
+ handle: string;
343
+ offset: number;
344
+ limit: number;
345
+ contextLines: number;
346
+ query?: string | undefined;
347
+ }, import("../../core/agent/toolOutputStore.js").StoredToolOutputPage | {
348
+ ok: boolean;
349
+ error: string;
350
+ }, NoInfer<import("@ai-sdk/provider-utils").Context>>;
351
+ });
@@ -0,0 +1,17 @@
1
+ import { tool } from 'ai';
2
+ import { z } from 'zod';
3
+ import { readToolOutput as readStoredToolOutput } from '../../core/agent/toolOutputStore.js';
4
+ export const readToolOutputTool = tool({
5
+ description: 'Read another page of oversized output previously returned by a tool handle.',
6
+ inputSchema: z.object({
7
+ handle: z.string().min(1).describe('Output handle from a prior tool result'),
8
+ offset: z.number().int().nonnegative().default(0).describe('Character offset to start reading'),
9
+ limit: z.number().int().positive().max(20_000).default(12_000).describe('Maximum characters to return'),
10
+ query: z.string().optional().describe('Optional case-insensitive substring search within the stored output instead of reading by offset'),
11
+ contextLines: z.number().int().nonnegative().max(20).default(2).describe('Lines of context around query matches'),
12
+ }),
13
+ execute: async ({ handle, offset, limit, query, contextLines }) => {
14
+ const page = readStoredToolOutput(handle, offset, limit, { query, contextLines });
15
+ return page ?? { ok: false, error: `Unknown or expired tool output handle: ${handle}` };
16
+ },
17
+ });