@xandout/libra-harness 0.1.119 → 0.1.121
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/dist/agent.d.ts.map +1 -1
- package/dist/agent.js +4 -2
- package/dist/agent.js.map +1 -1
- package/dist/extensions/code-tools/extension.d.ts +4 -0
- package/dist/extensions/code-tools/extension.d.ts.map +1 -1
- package/dist/extensions/code-tools/extension.js +3 -13
- package/dist/extensions/code-tools/extension.js.map +1 -1
- package/dist/extensions/code-tools/tools/shell.d.ts +7 -0
- package/dist/extensions/code-tools/tools/shell.d.ts.map +1 -1
- package/dist/extensions/code-tools/tools/shell.js +9 -2
- package/dist/extensions/code-tools/tools/shell.js.map +1 -1
- package/dist/extensions/loader.d.ts +10 -10
- package/dist/extensions/loader.js +10 -10
- package/dist/types.d.ts +6 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +13 -0
- package/dist/types.js.map +1 -1
- package/package.json +2 -65
- package/dist/extensions/auto-steer/extension.d.ts +0 -46
- package/dist/extensions/auto-steer/extension.d.ts.map +0 -1
- package/dist/extensions/auto-steer/extension.js +0 -52
- package/dist/extensions/auto-steer/extension.js.map +0 -1
- package/dist/extensions/auto-steer/extension.json +0 -7
- package/dist/extensions/auto-steer/index.d.ts +0 -3
- package/dist/extensions/auto-steer/index.d.ts.map +0 -1
- package/dist/extensions/auto-steer/index.js +0 -2
- package/dist/extensions/auto-steer/index.js.map +0 -1
- package/dist/extensions/emoji/extension.d.ts +0 -20
- package/dist/extensions/emoji/extension.d.ts.map +0 -1
- package/dist/extensions/emoji/extension.js +0 -22
- package/dist/extensions/emoji/extension.js.map +0 -1
- package/dist/extensions/emoji/extension.json +0 -7
- package/dist/extensions/emoji/index.d.ts +0 -3
- package/dist/extensions/emoji/index.d.ts.map +0 -1
- package/dist/extensions/emoji/index.js +0 -2
- package/dist/extensions/emoji/index.js.map +0 -1
- package/dist/extensions/filesystem/extension.d.ts +0 -53
- package/dist/extensions/filesystem/extension.d.ts.map +0 -1
- package/dist/extensions/filesystem/extension.js +0 -350
- package/dist/extensions/filesystem/extension.js.map +0 -1
- package/dist/extensions/filesystem/extension.json +0 -6
- package/dist/extensions/filesystem/extension.test.d.ts +0 -2
- package/dist/extensions/filesystem/extension.test.d.ts.map +0 -1
- package/dist/extensions/filesystem/extension.test.js +0 -387
- package/dist/extensions/filesystem/extension.test.js.map +0 -1
- package/dist/extensions/filesystem/index.d.ts +0 -2
- package/dist/extensions/filesystem/index.d.ts.map +0 -1
- package/dist/extensions/filesystem/index.js +0 -2
- package/dist/extensions/filesystem/index.js.map +0 -1
- package/dist/extensions/keyword-extractor/extension.d.ts +0 -53
- package/dist/extensions/keyword-extractor/extension.d.ts.map +0 -1
- package/dist/extensions/keyword-extractor/extension.js +0 -61
- package/dist/extensions/keyword-extractor/extension.js.map +0 -1
- package/dist/extensions/keyword-extractor/extension.json +0 -6
- package/dist/extensions/keyword-extractor/extension.test.d.ts +0 -2
- package/dist/extensions/keyword-extractor/extension.test.d.ts.map +0 -1
- package/dist/extensions/keyword-extractor/extension.test.js +0 -105
- package/dist/extensions/keyword-extractor/extension.test.js.map +0 -1
- package/dist/extensions/keyword-extractor/index.d.ts +0 -5
- package/dist/extensions/keyword-extractor/index.d.ts.map +0 -1
- package/dist/extensions/keyword-extractor/index.js +0 -3
- package/dist/extensions/keyword-extractor/index.js.map +0 -1
- package/dist/extensions/keyword-extractor/nlp.d.ts +0 -68
- package/dist/extensions/keyword-extractor/nlp.d.ts.map +0 -1
- package/dist/extensions/keyword-extractor/nlp.js +0 -156
- package/dist/extensions/keyword-extractor/nlp.js.map +0 -1
- package/dist/extensions/keyword-extractor/nlp.test.d.ts +0 -2
- package/dist/extensions/keyword-extractor/nlp.test.d.ts.map +0 -1
- package/dist/extensions/keyword-extractor/nlp.test.js +0 -176
- package/dist/extensions/keyword-extractor/nlp.test.js.map +0 -1
- package/dist/extensions/logger/extension.d.ts +0 -52
- package/dist/extensions/logger/extension.d.ts.map +0 -1
- package/dist/extensions/logger/extension.js +0 -68
- package/dist/extensions/logger/extension.js.map +0 -1
- package/dist/extensions/logger/extension.json +0 -7
- package/dist/extensions/logger/index.d.ts +0 -3
- package/dist/extensions/logger/index.d.ts.map +0 -1
- package/dist/extensions/logger/index.js +0 -2
- package/dist/extensions/logger/index.js.map +0 -1
- package/dist/extensions/mcp/extension.d.ts +0 -63
- package/dist/extensions/mcp/extension.d.ts.map +0 -1
- package/dist/extensions/mcp/extension.js +0 -437
- package/dist/extensions/mcp/extension.js.map +0 -1
- package/dist/extensions/mcp/extension.json +0 -7
- package/dist/extensions/mcp/extension.test.d.ts +0 -2
- package/dist/extensions/mcp/extension.test.d.ts.map +0 -1
- package/dist/extensions/mcp/extension.test.js +0 -286
- package/dist/extensions/mcp/extension.test.js.map +0 -1
- package/dist/extensions/mcp/index.d.ts +0 -3
- package/dist/extensions/mcp/index.d.ts.map +0 -1
- package/dist/extensions/mcp/index.js +0 -2
- package/dist/extensions/mcp/index.js.map +0 -1
- package/dist/extensions/mem-session/extension.d.ts +0 -24
- package/dist/extensions/mem-session/extension.d.ts.map +0 -1
- package/dist/extensions/mem-session/extension.js +0 -49
- package/dist/extensions/mem-session/extension.js.map +0 -1
- package/dist/extensions/mem-session/extension.json +0 -6
- package/dist/extensions/mem-session/index.d.ts +0 -2
- package/dist/extensions/mem-session/index.d.ts.map +0 -1
- package/dist/extensions/mem-session/index.js +0 -2
- package/dist/extensions/mem-session/index.js.map +0 -1
- package/dist/extensions/memory/extension.d.ts +0 -54
- package/dist/extensions/memory/extension.d.ts.map +0 -1
- package/dist/extensions/memory/extension.js +0 -143
- package/dist/extensions/memory/extension.js.map +0 -1
- package/dist/extensions/memory/extension.json +0 -7
- package/dist/extensions/memory/index.d.ts +0 -4
- package/dist/extensions/memory/index.d.ts.map +0 -1
- package/dist/extensions/memory/index.js +0 -3
- package/dist/extensions/memory/index.js.map +0 -1
- package/dist/extensions/memory/llm-extractor.d.ts +0 -42
- package/dist/extensions/memory/llm-extractor.d.ts.map +0 -1
- package/dist/extensions/memory/llm-extractor.js +0 -86
- package/dist/extensions/memory/llm-extractor.js.map +0 -1
- package/dist/extensions/memory/types.d.ts +0 -142
- package/dist/extensions/memory/types.d.ts.map +0 -1
- package/dist/extensions/memory/types.js +0 -2
- package/dist/extensions/memory/types.js.map +0 -1
- package/dist/extensions/otel/extension.d.ts +0 -57
- package/dist/extensions/otel/extension.d.ts.map +0 -1
- package/dist/extensions/otel/extension.js +0 -253
- package/dist/extensions/otel/extension.js.map +0 -1
- package/dist/extensions/otel/extension.json +0 -7
- package/dist/extensions/otel/extension.test.d.ts +0 -2
- package/dist/extensions/otel/extension.test.d.ts.map +0 -1
- package/dist/extensions/otel/extension.test.js +0 -399
- package/dist/extensions/otel/extension.test.js.map +0 -1
- package/dist/extensions/otel/index.d.ts +0 -4
- package/dist/extensions/otel/index.d.ts.map +0 -1
- package/dist/extensions/otel/index.js +0 -3
- package/dist/extensions/otel/index.js.map +0 -1
- package/dist/extensions/otel/jsonl-span-exporter.d.ts +0 -60
- package/dist/extensions/otel/jsonl-span-exporter.d.ts.map +0 -1
- package/dist/extensions/otel/jsonl-span-exporter.js +0 -134
- package/dist/extensions/otel/jsonl-span-exporter.js.map +0 -1
- package/dist/extensions/scripts/extension.d.ts +0 -180
- package/dist/extensions/scripts/extension.d.ts.map +0 -1
- package/dist/extensions/scripts/extension.js +0 -618
- package/dist/extensions/scripts/extension.js.map +0 -1
- package/dist/extensions/scripts/extension.json +0 -7
- package/dist/extensions/scripts/extension.test.d.ts +0 -2
- package/dist/extensions/scripts/extension.test.d.ts.map +0 -1
- package/dist/extensions/scripts/extension.test.js +0 -552
- package/dist/extensions/scripts/extension.test.js.map +0 -1
- package/dist/extensions/scripts/index.d.ts +0 -3
- package/dist/extensions/scripts/index.d.ts.map +0 -1
- package/dist/extensions/scripts/index.js +0 -2
- package/dist/extensions/scripts/index.js.map +0 -1
- package/dist/extensions/structured-output/extension.d.ts +0 -9
- package/dist/extensions/structured-output/extension.d.ts.map +0 -1
- package/dist/extensions/structured-output/extension.js +0 -93
- package/dist/extensions/structured-output/extension.js.map +0 -1
- package/dist/extensions/structured-output/extension.json +0 -7
- package/dist/extensions/structured-output/index.d.ts +0 -3
- package/dist/extensions/structured-output/index.d.ts.map +0 -1
- package/dist/extensions/structured-output/index.js +0 -2
- package/dist/extensions/structured-output/index.js.map +0 -1
- package/dist/extensions/timestamp/extension.d.ts +0 -11
- package/dist/extensions/timestamp/extension.d.ts.map +0 -1
- package/dist/extensions/timestamp/extension.js +0 -21
- package/dist/extensions/timestamp/extension.js.map +0 -1
- package/dist/extensions/timestamp/extension.json +0 -6
- package/dist/extensions/timestamp/index.d.ts +0 -2
- package/dist/extensions/timestamp/index.d.ts.map +0 -1
- package/dist/extensions/timestamp/index.js +0 -2
- package/dist/extensions/timestamp/index.js.map +0 -1
- package/dist/extensions/token-stats/extension.d.ts +0 -50
- package/dist/extensions/token-stats/extension.d.ts.map +0 -1
- package/dist/extensions/token-stats/extension.js +0 -99
- package/dist/extensions/token-stats/extension.js.map +0 -1
- package/dist/extensions/token-stats/extension.json +0 -7
- package/dist/extensions/token-stats/extension.test.d.ts +0 -2
- package/dist/extensions/token-stats/extension.test.d.ts.map +0 -1
- package/dist/extensions/token-stats/extension.test.js +0 -197
- package/dist/extensions/token-stats/extension.test.js.map +0 -1
- package/dist/extensions/token-stats/index.d.ts +0 -3
- package/dist/extensions/token-stats/index.d.ts.map +0 -1
- package/dist/extensions/token-stats/index.js +0 -2
- package/dist/extensions/token-stats/index.js.map +0 -1
- package/dist/extensions/tool-buffer/extension.d.ts +0 -89
- package/dist/extensions/tool-buffer/extension.d.ts.map +0 -1
- package/dist/extensions/tool-buffer/extension.js +0 -182
- package/dist/extensions/tool-buffer/extension.js.map +0 -1
- package/dist/extensions/tool-buffer/extension.json +0 -7
- package/dist/extensions/tool-buffer/extension.test.d.ts +0 -2
- package/dist/extensions/tool-buffer/extension.test.d.ts.map +0 -1
- package/dist/extensions/tool-buffer/extension.test.js +0 -549
- package/dist/extensions/tool-buffer/extension.test.js.map +0 -1
- package/dist/extensions/tool-buffer/index.d.ts +0 -3
- package/dist/extensions/tool-buffer/index.d.ts.map +0 -1
- package/dist/extensions/tool-buffer/index.js +0 -2
- package/dist/extensions/tool-buffer/index.js.map +0 -1
- package/dist/extensions/weather-tool/extension.d.ts +0 -22
- package/dist/extensions/weather-tool/extension.d.ts.map +0 -1
- package/dist/extensions/weather-tool/extension.js +0 -33
- package/dist/extensions/weather-tool/extension.js.map +0 -1
- package/dist/extensions/weather-tool/extension.json +0 -7
- package/dist/extensions/weather-tool/index.d.ts +0 -3
- package/dist/extensions/weather-tool/index.d.ts.map +0 -1
- package/dist/extensions/weather-tool/index.js +0 -2
- package/dist/extensions/weather-tool/index.js.map +0 -1
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
import type { Extension } from '../../extension.js';
|
|
2
|
-
/**
|
|
3
|
-
* Config for the tool-buffer extension.
|
|
4
|
-
*/
|
|
5
|
-
export interface ToolBufferConfig {
|
|
6
|
-
/**
|
|
7
|
-
* Directory to store buffered tool outputs. Created if it doesn't exist.
|
|
8
|
-
* Default: `./tool-buffers`.
|
|
9
|
-
*/
|
|
10
|
-
bufferDir?: string;
|
|
11
|
-
/**
|
|
12
|
-
* Minimum content length (characters) to trigger buffering. Tool
|
|
13
|
-
* results shorter than this are passed through unchanged. Default:
|
|
14
|
-
* `2000`.
|
|
15
|
-
*/
|
|
16
|
-
threshold?: number;
|
|
17
|
-
/**
|
|
18
|
-
* Tool names to buffer (whitelist). If set, only these tools are
|
|
19
|
-
* buffered. If omitted, all tools are eligible. Default: all tools.
|
|
20
|
-
*/
|
|
21
|
-
tools?: string[];
|
|
22
|
-
/**
|
|
23
|
-
* Tool names to exclude from buffering (blacklist). Takes precedence
|
|
24
|
-
* over `tools`. Default: none.
|
|
25
|
-
*/
|
|
26
|
-
excludeTools?: string[];
|
|
27
|
-
/**
|
|
28
|
-
* Whether to preserve the first N characters of the original content
|
|
29
|
-
* in the pointer message, giving the LLM a preview without needing
|
|
30
|
-
* to grep. Default: `200`.
|
|
31
|
-
*/
|
|
32
|
-
previewLength?: number;
|
|
33
|
-
/**
|
|
34
|
-
* Prefix for buffer file names. A random ID is appended. Default:
|
|
35
|
-
* `buffer_`.
|
|
36
|
-
*/
|
|
37
|
-
filePrefix?: string;
|
|
38
|
-
/**
|
|
39
|
-
* Name of the no-buffer control tool exposed to the LLM. Default:
|
|
40
|
-
* `no_buffer`.
|
|
41
|
-
*/
|
|
42
|
-
noBufferToolName?: string;
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* Tool-buffer extension — redirects large tool outputs to files.
|
|
46
|
-
*
|
|
47
|
-
* Hooks `afterTool` and checks the result content size. If it exceeds
|
|
48
|
-
* the configured threshold, the content is written to a file in
|
|
49
|
-
* `bufferDir` and the tool result is replaced with a pointer message:
|
|
50
|
-
*
|
|
51
|
-
* ```
|
|
52
|
-
* [tool-buffer] Output saved to tool-buffers/buffer_a1b2c3.txt
|
|
53
|
-
* (234 lines, 12.5 KB). Use grep to search within this file.
|
|
54
|
-
*
|
|
55
|
-
* Preview (first 200 chars):
|
|
56
|
-
* {"jobs":[{"id":"JT-001","name":"Kitchen remodel"},…
|
|
57
|
-
* ```
|
|
58
|
-
*
|
|
59
|
-
* This keeps the LLM context small when tools return large datasets
|
|
60
|
-
* (e.g. list_jobs, list_messages, search results) while preserving
|
|
61
|
-
* full access to the data via a grep tool or filesystem reads.
|
|
62
|
-
*
|
|
63
|
-
* By default, all tools are buffered. Use `excludeTools` to exempt
|
|
64
|
-
* tools whose output the LLM always needs inline (e.g. read_file,
|
|
65
|
-
* send_message, status checks). The LLM can also call `no_buffer`
|
|
66
|
-
* at runtime to bypass buffering on demand.
|
|
67
|
-
*
|
|
68
|
-
* ## LLM-controlled bypass
|
|
69
|
-
*
|
|
70
|
-
* The extension registers a `no_buffer` tool that the LLM can call to
|
|
71
|
-
* disable buffering on demand — either for the next tool call only or
|
|
72
|
-
* for the rest of the turn. This gives the LLM real-time control without
|
|
73
|
-
* any tool knowing about buffering.
|
|
74
|
-
*
|
|
75
|
-
* - `no_buffer({ scope: "next" })` — skip buffering for the next tool
|
|
76
|
-
* call only. The flag is cleared after one tool executes.
|
|
77
|
-
* - `no_buffer({ scope: "turn" })` — skip buffering for all remaining
|
|
78
|
-
* tool calls in this turn.
|
|
79
|
-
*
|
|
80
|
-
* The LLM typically calls `no_buffer` before a tool whose full output
|
|
81
|
-
* it needs inline (e.g. reading a file it intends to summarize).
|
|
82
|
-
*
|
|
83
|
-
* ## Priority
|
|
84
|
-
*
|
|
85
|
-
* Uses priority -50 (runs after most extensions) so it sees the final
|
|
86
|
-
* tool result after other extensions have potentially modified it.
|
|
87
|
-
*/
|
|
88
|
-
export default function createToolBufferExtension(config?: ToolBufferConfig): Extension;
|
|
89
|
-
//# sourceMappingURL=extension.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"extension.d.ts","sourceRoot":"","sources":["../../../src/extensions/tool-buffer/extension.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAIpD;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;;;OAIG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;;OAGG;IACH,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC;IACjB;;;OAGG;IACH,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;IACxB;;;;OAIG;IACH,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB;;;OAGG;IACH,gBAAgB,CAAC,EAAE,MAAM,CAAC;CAC3B;AAOD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2CG;AACH,MAAM,CAAC,OAAO,UAAU,yBAAyB,CAC/C,MAAM,CAAC,EAAE,gBAAgB,GACxB,SAAS,CAyIX"}
|
|
@@ -1,182 +0,0 @@
|
|
|
1
|
-
import { writeFileSync, mkdirSync, existsSync } from 'node:fs';
|
|
2
|
-
import { join } from 'node:path';
|
|
3
|
-
import { randomBytes } from 'node:crypto';
|
|
4
|
-
// ── Turn-level flag keys (stored in turn.metadata) ──────────────────
|
|
5
|
-
// These are internal to the extension and not part of the public API.
|
|
6
|
-
const FLAG_NEXT = '_toolBuffer_skipNext';
|
|
7
|
-
const FLAG_TURN = '_toolBuffer_skipTurn';
|
|
8
|
-
/**
|
|
9
|
-
* Tool-buffer extension — redirects large tool outputs to files.
|
|
10
|
-
*
|
|
11
|
-
* Hooks `afterTool` and checks the result content size. If it exceeds
|
|
12
|
-
* the configured threshold, the content is written to a file in
|
|
13
|
-
* `bufferDir` and the tool result is replaced with a pointer message:
|
|
14
|
-
*
|
|
15
|
-
* ```
|
|
16
|
-
* [tool-buffer] Output saved to tool-buffers/buffer_a1b2c3.txt
|
|
17
|
-
* (234 lines, 12.5 KB). Use grep to search within this file.
|
|
18
|
-
*
|
|
19
|
-
* Preview (first 200 chars):
|
|
20
|
-
* {"jobs":[{"id":"JT-001","name":"Kitchen remodel"},…
|
|
21
|
-
* ```
|
|
22
|
-
*
|
|
23
|
-
* This keeps the LLM context small when tools return large datasets
|
|
24
|
-
* (e.g. list_jobs, list_messages, search results) while preserving
|
|
25
|
-
* full access to the data via a grep tool or filesystem reads.
|
|
26
|
-
*
|
|
27
|
-
* By default, all tools are buffered. Use `excludeTools` to exempt
|
|
28
|
-
* tools whose output the LLM always needs inline (e.g. read_file,
|
|
29
|
-
* send_message, status checks). The LLM can also call `no_buffer`
|
|
30
|
-
* at runtime to bypass buffering on demand.
|
|
31
|
-
*
|
|
32
|
-
* ## LLM-controlled bypass
|
|
33
|
-
*
|
|
34
|
-
* The extension registers a `no_buffer` tool that the LLM can call to
|
|
35
|
-
* disable buffering on demand — either for the next tool call only or
|
|
36
|
-
* for the rest of the turn. This gives the LLM real-time control without
|
|
37
|
-
* any tool knowing about buffering.
|
|
38
|
-
*
|
|
39
|
-
* - `no_buffer({ scope: "next" })` — skip buffering for the next tool
|
|
40
|
-
* call only. The flag is cleared after one tool executes.
|
|
41
|
-
* - `no_buffer({ scope: "turn" })` — skip buffering for all remaining
|
|
42
|
-
* tool calls in this turn.
|
|
43
|
-
*
|
|
44
|
-
* The LLM typically calls `no_buffer` before a tool whose full output
|
|
45
|
-
* it needs inline (e.g. reading a file it intends to summarize).
|
|
46
|
-
*
|
|
47
|
-
* ## Priority
|
|
48
|
-
*
|
|
49
|
-
* Uses priority -50 (runs after most extensions) so it sees the final
|
|
50
|
-
* tool result after other extensions have potentially modified it.
|
|
51
|
-
*/
|
|
52
|
-
export default function createToolBufferExtension(config) {
|
|
53
|
-
const bufferDir = config?.bufferDir ?? './tool-buffers';
|
|
54
|
-
const threshold = config?.threshold ?? 2000;
|
|
55
|
-
const whitelist = config?.tools ? new Set(config.tools) : undefined;
|
|
56
|
-
const blacklist = config?.excludeTools ? new Set(config.excludeTools) : undefined;
|
|
57
|
-
const previewLength = config?.previewLength ?? 200;
|
|
58
|
-
const filePrefix = config?.filePrefix ?? 'buffer_';
|
|
59
|
-
const noBufferToolName = config?.noBufferToolName ?? 'no_buffer';
|
|
60
|
-
// Ensure buffer directory exists at setup time.
|
|
61
|
-
if (!existsSync(bufferDir)) {
|
|
62
|
-
mkdirSync(bufferDir, { recursive: true });
|
|
63
|
-
}
|
|
64
|
-
function shouldBuffer(toolName) {
|
|
65
|
-
if (blacklist?.has(toolName))
|
|
66
|
-
return false;
|
|
67
|
-
if (whitelist && !whitelist.has(toolName))
|
|
68
|
-
return false;
|
|
69
|
-
return true;
|
|
70
|
-
}
|
|
71
|
-
function formatSize(bytes) {
|
|
72
|
-
if (bytes < 1024)
|
|
73
|
-
return `${bytes} B`;
|
|
74
|
-
if (bytes < 1024 * 1024)
|
|
75
|
-
return `${(bytes / 1024).toFixed(1)} KB`;
|
|
76
|
-
return `${(bytes / (1024 * 1024)).toFixed(1)} MB`;
|
|
77
|
-
}
|
|
78
|
-
// ── no_buffer tool ────────────────────────────────────────────────
|
|
79
|
-
const noBufferTool = {
|
|
80
|
-
name: noBufferToolName,
|
|
81
|
-
description: 'Disable tool output buffering. Call this before a tool whose full output you need inline ' +
|
|
82
|
-
'(e.g. reading a file you intend to summarize or quote). ' +
|
|
83
|
-
'scope "next" skips buffering for the next tool call only. ' +
|
|
84
|
-
'scope "turn" skips buffering for all remaining tool calls this turn.',
|
|
85
|
-
parameters: {
|
|
86
|
-
type: 'object',
|
|
87
|
-
properties: {
|
|
88
|
-
scope: {
|
|
89
|
-
type: 'string',
|
|
90
|
-
enum: ['next', 'turn'],
|
|
91
|
-
description: '"next" = skip buffering for the next tool call only (default). "turn" = skip for all remaining tool calls this turn.',
|
|
92
|
-
default: 'next',
|
|
93
|
-
},
|
|
94
|
-
},
|
|
95
|
-
},
|
|
96
|
-
async execute(args, ctx) {
|
|
97
|
-
const scope = args.scope ?? 'next';
|
|
98
|
-
if (scope === 'turn') {
|
|
99
|
-
ctx.metadata[FLAG_TURN] = true;
|
|
100
|
-
}
|
|
101
|
-
else {
|
|
102
|
-
ctx.metadata[FLAG_NEXT] = true;
|
|
103
|
-
}
|
|
104
|
-
return {
|
|
105
|
-
toolCallId: '',
|
|
106
|
-
content: `Buffering disabled for ${scope === 'turn' ? 'the rest of this turn' : 'the next tool call'}.`,
|
|
107
|
-
};
|
|
108
|
-
},
|
|
109
|
-
};
|
|
110
|
-
return {
|
|
111
|
-
name: 'tool-buffer',
|
|
112
|
-
priority: -50,
|
|
113
|
-
install(agent) {
|
|
114
|
-
// Register the no_buffer tool so the LLM can call it.
|
|
115
|
-
agent.tool(noBufferTool);
|
|
116
|
-
agent.hook('afterTool', 'tool-buffer', async (ctx) => {
|
|
117
|
-
if (!ctx.toolCall || !ctx.toolResult)
|
|
118
|
-
return;
|
|
119
|
-
// The no_buffer tool itself is never buffered.
|
|
120
|
-
if (ctx.toolCall.name === noBufferToolName)
|
|
121
|
-
return;
|
|
122
|
-
const toolName = ctx.toolCall.name;
|
|
123
|
-
const result = ctx.toolResult;
|
|
124
|
-
const meta = ctx.turn.metadata;
|
|
125
|
-
// Check bypass flags set by the no_buffer tool.
|
|
126
|
-
const skipTurn = meta[FLAG_TURN] === true;
|
|
127
|
-
const skipNext = meta[FLAG_NEXT] === true;
|
|
128
|
-
if (skipTurn || skipNext) {
|
|
129
|
-
// Clear the one-shot flag (turn flag persists).
|
|
130
|
-
if (skipNext)
|
|
131
|
-
delete meta[FLAG_NEXT];
|
|
132
|
-
return;
|
|
133
|
-
}
|
|
134
|
-
// Don't buffer error results — the LLM needs to see those inline.
|
|
135
|
-
if (result.isError)
|
|
136
|
-
return;
|
|
137
|
-
// Don't buffer empty or short results.
|
|
138
|
-
const content = result.content;
|
|
139
|
-
if (!content || content.length < threshold)
|
|
140
|
-
return;
|
|
141
|
-
// Check whitelist/blacklist.
|
|
142
|
-
if (!shouldBuffer(toolName))
|
|
143
|
-
return;
|
|
144
|
-
// Generate a unique filename.
|
|
145
|
-
const id = randomBytes(4).toString('hex');
|
|
146
|
-
const fileName = `${filePrefix}${id}.txt`;
|
|
147
|
-
const filePath = join(bufferDir, fileName);
|
|
148
|
-
// Write the full content to the buffer file.
|
|
149
|
-
try {
|
|
150
|
-
writeFileSync(filePath, content, 'utf-8');
|
|
151
|
-
}
|
|
152
|
-
catch (err) {
|
|
153
|
-
// If we can't write, pass the result through unchanged.
|
|
154
|
-
// Don't break the tool call over a buffering failure.
|
|
155
|
-
return;
|
|
156
|
-
}
|
|
157
|
-
// Build the pointer message.
|
|
158
|
-
const lineCount = content.split('\n').length;
|
|
159
|
-
const sizeBytes = Buffer.byteLength(content, 'utf-8');
|
|
160
|
-
const preview = content.slice(0, previewLength);
|
|
161
|
-
const previewTruncated = content.length > previewLength ? '…' : '';
|
|
162
|
-
const pointer = [
|
|
163
|
-
`[tool-buffer] Output saved to ${filePath}`,
|
|
164
|
-
`(${lineCount} lines, ${formatSize(sizeBytes)}). Use grep to search within this file.`,
|
|
165
|
-
'',
|
|
166
|
-
`If you need the full output inline, call no_buffer({ scope: "next" }) and re-run this tool.`,
|
|
167
|
-
'',
|
|
168
|
-
`Preview (first ${previewLength} chars):`,
|
|
169
|
-
preview + previewTruncated,
|
|
170
|
-
].join('\n');
|
|
171
|
-
// Replace the tool result with the pointer.
|
|
172
|
-
const bufferedResult = {
|
|
173
|
-
toolCallId: result.toolCallId,
|
|
174
|
-
content: pointer,
|
|
175
|
-
isError: false,
|
|
176
|
-
};
|
|
177
|
-
return { skip: true, value: bufferedResult };
|
|
178
|
-
});
|
|
179
|
-
},
|
|
180
|
-
};
|
|
181
|
-
}
|
|
182
|
-
//# sourceMappingURL=extension.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"extension.js","sourceRoot":"","sources":["../../../src/extensions/tool-buffer/extension.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAC/D,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAgD1C,uEAAuE;AACvE,sEAAsE;AACtE,MAAM,SAAS,GAAG,sBAAsB,CAAC;AACzC,MAAM,SAAS,GAAG,sBAAsB,CAAC;AAEzC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2CG;AACH,MAAM,CAAC,OAAO,UAAU,yBAAyB,CAC/C,MAAyB;IAEzB,MAAM,SAAS,GAAG,MAAM,EAAE,SAAS,IAAI,gBAAgB,CAAC;IACxD,MAAM,SAAS,GAAG,MAAM,EAAE,SAAS,IAAI,IAAI,CAAC;IAC5C,MAAM,SAAS,GAAG,MAAM,EAAE,KAAK,CAAC,CAAC,CAAC,IAAI,GAAG,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M,CAAC,UAAU,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;gBACtD,MAAM,OAAO,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC,EAAE,aAAa,CAAC,CAAC;gBAChD,MAAM,gBAAgB,GAAG,OAAO,CAAC,MAAM,GAAG,aAAa,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC;gBAEnE,MAAM,OAAO,GAAG;oBACd,iCAAiC,QAAQ,EAAE;oBAC3C,IAAI,SAAS,WAAW,UAAU,CAAC,SAAS,CAAC,yCAAyC;oBACtF,EAAE;oBACF,6FAA6F;oBAC7F,EAAE;oBACF,kBAAkB,aAAa,UAAU;oBACzC,OAAO,GAAG,gBAAgB;iBAC3B,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;gBAEb,4CAA4C;gBAC5C,MAAM,cAAc,GAAe;oBACjC,UAAU,EAAE,MAAM,CAAC,UAAU;oBAC7B,OAAO,EAAE,OAAO;oBAChB,OAAO,EAAE,KAAK;iBACf,CAAC;gBAEF,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,cAAc,EAAE,CAAC;YAC/C,CAAC,CAAC,CAAC;QACL,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "tool-buffer",
|
|
3
|
-
"description": "Redirects large tool outputs to files and returns a pointer to the LLM. Keeps context small when tools return large datasets. Pair with a grep tool for searching buffered content.",
|
|
4
|
-
"enabled": true,
|
|
5
|
-
"priority": -50,
|
|
6
|
-
"configKeys": ["bufferDir", "threshold", "tools", "excludeTools", "previewLength", "filePrefix"]
|
|
7
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"extension.test.d.ts","sourceRoot":"","sources":["../../../src/extensions/tool-buffer/extension.test.ts"],"names":[],"mappings":""}
|