@csmedeiros/codemax 1.0.3 → 1.0.7
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/README.md +4 -20
- package/launcher.js +28 -0
- package/package.json +15 -121
- package/LICENSE +0 -21
- package/dist/commands/cursorRules.d.ts +0 -15
- package/dist/commands/cursorRules.js +0 -118
- package/dist/commands/slashCommands.d.ts +0 -36
- package/dist/commands/slashCommands.js +0 -236
- package/dist/configuration/configManager.d.ts +0 -32
- package/dist/configuration/configManager.js +0 -71
- package/dist/configuration/modelContextWindows.d.ts +0 -3
- package/dist/configuration/modelContextWindows.js +0 -13
- package/dist/conversation/agentGraph.d.ts +0 -203
- package/dist/conversation/agentGraph.js +0 -433
- package/dist/conversation/agentTurn.d.ts +0 -40
- package/dist/conversation/agentTurn.js +0 -252
- package/dist/conversation/chatHistory.d.ts +0 -24
- package/dist/conversation/chatHistory.js +0 -251
- package/dist/conversation/compactionUtils.d.ts +0 -17
- package/dist/conversation/compactionUtils.js +0 -57
- package/dist/conversation/prompts/planPrompt.d.ts +0 -1
- package/dist/conversation/prompts/planPrompt.js +0 -12
- package/dist/conversation/prompts/systemPrompt.d.ts +0 -29
- package/dist/conversation/prompts/systemPrompt.js +0 -149
- package/dist/entry/cli.d.ts +0 -2
- package/dist/entry/cli.js +0 -24
- package/dist/observability/langfuseTracing.d.ts +0 -5
- package/dist/observability/langfuseTracing.js +0 -76
- package/dist/shared/types.d.ts +0 -25
- package/dist/shared/types.js +0 -1
- package/dist/terminal/app.d.ts +0 -2
- package/dist/terminal/app.js +0 -1236
- package/dist/terminal/components.d.ts +0 -18
- package/dist/terminal/components.js +0 -43
- package/dist/terminal/markdown.d.ts +0 -4
- package/dist/terminal/markdown.js +0 -47
- package/dist/terminal/screens/compactionSettings.d.ts +0 -6
- package/dist/terminal/screens/compactionSettings.js +0 -66
- package/dist/terminal/screens/modelSettings.d.ts +0 -10
- package/dist/terminal/screens/modelSettings.js +0 -76
- package/dist/terminal/textField.d.ts +0 -7
- package/dist/terminal/textField.js +0 -136
- package/dist/terminal/theme.d.ts +0 -23
- package/dist/terminal/theme.js +0 -23
- package/dist/tooling/mcpConfig.d.ts +0 -40
- package/dist/tooling/mcpConfig.js +0 -49
- package/dist/tooling/planControlChannel.d.ts +0 -2
- package/dist/tooling/planControlChannel.js +0 -21
- package/dist/tooling/toolConfig.d.ts +0 -42
- package/dist/tooling/toolConfig.js +0 -138
- package/dist/tooling/toolUiCallback.d.ts +0 -21
- package/dist/tooling/toolUiCallback.js +0 -268
- package/dist/tooling/tools.d.ts +0 -216
- package/dist/tooling/tools.js +0 -614
|
@@ -1,138 +0,0 @@
|
|
|
1
|
-
import path from 'node:path';
|
|
2
|
-
const DEFAULT_MAX_PREVIEW = 120;
|
|
3
|
-
function safeJsonParse(text) {
|
|
4
|
-
try {
|
|
5
|
-
return JSON.parse(text);
|
|
6
|
-
}
|
|
7
|
-
catch {
|
|
8
|
-
return null;
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
function truncate(text, maxChars) {
|
|
12
|
-
if (maxChars <= 0)
|
|
13
|
-
return '';
|
|
14
|
-
if (text.length <= maxChars)
|
|
15
|
-
return text;
|
|
16
|
-
return `${text.slice(0, Math.max(0, maxChars - 1))}…`;
|
|
17
|
-
}
|
|
18
|
-
function extractString(obj, key) {
|
|
19
|
-
if (!obj || typeof obj !== 'object')
|
|
20
|
-
return '';
|
|
21
|
-
const v = obj[key];
|
|
22
|
-
return typeof v === 'string' ? v : '';
|
|
23
|
-
}
|
|
24
|
-
export function toolNameFromSerialized(tool, runName) {
|
|
25
|
-
// Prefer explicit LangChain name (runName). Fallback to serialized id last segment.
|
|
26
|
-
const name = runName?.trim();
|
|
27
|
-
if (name)
|
|
28
|
-
return name;
|
|
29
|
-
const id = Array.isArray(tool?.id) ? tool.id : [];
|
|
30
|
-
const last = id.length ? String(id[id.length - 1] ?? '') : '';
|
|
31
|
-
return last || 'tool';
|
|
32
|
-
}
|
|
33
|
-
export function buildToolUiVars(args) {
|
|
34
|
-
const parsed = safeJsonParse(args.input);
|
|
35
|
-
const filePath = extractString(parsed, 'filePath');
|
|
36
|
-
const command = extractString(parsed, 'command');
|
|
37
|
-
const cwd = extractString(parsed, 'cwd');
|
|
38
|
-
const fileName = filePath ? path.basename(filePath) : '';
|
|
39
|
-
const base = {
|
|
40
|
-
tool_name: args.toolName,
|
|
41
|
-
tool_call_id: (args.toolCallId ?? '').trim(),
|
|
42
|
-
run_id: args.runId,
|
|
43
|
-
input_raw: args.input ?? '',
|
|
44
|
-
output_raw: args.output ?? '',
|
|
45
|
-
input_preview: truncate(args.input ?? '', args.maxInputPreview),
|
|
46
|
-
output_preview: truncate(args.output ?? '', args.maxOutputPreview),
|
|
47
|
-
file_path: filePath,
|
|
48
|
-
file_name: fileName,
|
|
49
|
-
command,
|
|
50
|
-
cwd,
|
|
51
|
-
};
|
|
52
|
-
const extra = {};
|
|
53
|
-
for (const [k, fn] of Object.entries(args.placeholders ?? {})) {
|
|
54
|
-
try {
|
|
55
|
-
extra[k] = String(fn(base));
|
|
56
|
-
}
|
|
57
|
-
catch {
|
|
58
|
-
extra[k] = '';
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
return { ...base, ...extra };
|
|
62
|
-
}
|
|
63
|
-
export function renderToolTemplate(template, vars) {
|
|
64
|
-
if (!template)
|
|
65
|
-
return '';
|
|
66
|
-
return template.replace(/\{\{\s*([a-zA-Z0-9_]+)\s*\}\}/g, (_m, key) => {
|
|
67
|
-
const v = vars[key];
|
|
68
|
-
return typeof v === 'string' ? v : '';
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
|
-
const defaultToolUi = {
|
|
72
|
-
onCallTemplate: '\n{{tool_name}}…\n',
|
|
73
|
-
onResultTemplate: '\n{{tool_name}} done.\n',
|
|
74
|
-
maxInputPreview: DEFAULT_MAX_PREVIEW,
|
|
75
|
-
maxOutputPreview: DEFAULT_MAX_PREVIEW,
|
|
76
|
-
};
|
|
77
|
-
const toolUiConfigByName = {
|
|
78
|
-
readFileTool: {
|
|
79
|
-
onCallTemplate: 'Read({{file_path}})',
|
|
80
|
-
onResultTemplate: 'Read {{file_name}}',
|
|
81
|
-
},
|
|
82
|
-
writeFileTool: {
|
|
83
|
-
onCallTemplate: 'Write({{file_name}})',
|
|
84
|
-
onResultTemplate: 'Wrote {{file_name}}',
|
|
85
|
-
},
|
|
86
|
-
editFileTool: {
|
|
87
|
-
onCallTemplate: 'Update({{file_name}})',
|
|
88
|
-
onResultTemplate: 'Updated {{file_name}}',
|
|
89
|
-
},
|
|
90
|
-
shellTool: {
|
|
91
|
-
onCallTemplate: 'Bash({{command_full}})',
|
|
92
|
-
onResultTemplate: '',
|
|
93
|
-
placeholders: {
|
|
94
|
-
command_full: v => v.command || v.input_raw,
|
|
95
|
-
command_preview: v => truncate(v.command || v.input_preview, 80),
|
|
96
|
-
},
|
|
97
|
-
},
|
|
98
|
-
todoTool: {
|
|
99
|
-
onCallTemplate: 'TODO({{action}})',
|
|
100
|
-
onResultTemplate: 'Updated TODOs',
|
|
101
|
-
placeholders: {
|
|
102
|
-
action: v => {
|
|
103
|
-
const p = safeJsonParse(v.input_raw);
|
|
104
|
-
return extractString(p, 'action') || 'update';
|
|
105
|
-
},
|
|
106
|
-
},
|
|
107
|
-
},
|
|
108
|
-
writePlanTool: {
|
|
109
|
-
onCallTemplate: 'WritePlan({{plan_name}})',
|
|
110
|
-
onResultTemplate: '{{output_preview}}',
|
|
111
|
-
maxInputPreview: 60,
|
|
112
|
-
maxOutputPreview: 160,
|
|
113
|
-
placeholders: {
|
|
114
|
-
plan_name: (vars) => {
|
|
115
|
-
try {
|
|
116
|
-
return JSON.parse(vars.input_raw).planName ?? '';
|
|
117
|
-
}
|
|
118
|
-
catch {
|
|
119
|
-
return '';
|
|
120
|
-
}
|
|
121
|
-
},
|
|
122
|
-
},
|
|
123
|
-
},
|
|
124
|
-
};
|
|
125
|
-
export function resolveToolUi(toolName) {
|
|
126
|
-
const cfg = toolUiConfigByName[toolName] ?? {};
|
|
127
|
-
return {
|
|
128
|
-
...defaultToolUi,
|
|
129
|
-
...cfg,
|
|
130
|
-
// merge placeholders
|
|
131
|
-
placeholders: {
|
|
132
|
-
...(defaultToolUi.placeholders ?? {}),
|
|
133
|
-
...(cfg.placeholders ?? {}),
|
|
134
|
-
},
|
|
135
|
-
maxInputPreview: cfg.maxInputPreview ?? defaultToolUi.maxInputPreview,
|
|
136
|
-
maxOutputPreview: cfg.maxOutputPreview ?? defaultToolUi.maxOutputPreview,
|
|
137
|
-
};
|
|
138
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { BaseCallbackHandler } from '@langchain/core/callbacks/base';
|
|
2
|
-
type DiffLineEntry = {
|
|
3
|
-
type: 'add' | 'remove' | 'context';
|
|
4
|
-
lineNum: number;
|
|
5
|
-
text: string;
|
|
6
|
-
};
|
|
7
|
-
export declare function isWriteOutput(text: string): boolean;
|
|
8
|
-
export declare function parseWriteOutput(text: string): {
|
|
9
|
-
summary: string;
|
|
10
|
-
entries: DiffLineEntry[];
|
|
11
|
-
omitted: number;
|
|
12
|
-
};
|
|
13
|
-
export declare function createToolUiCallbackHandler(): BaseCallbackHandler;
|
|
14
|
-
export declare function createToolUiCallbackHandlerWithSink(emit?: (event: {
|
|
15
|
-
type: 'on_tool_start' | 'on_tool_end' | 'on_tool_error';
|
|
16
|
-
toolName?: string;
|
|
17
|
-
input?: string;
|
|
18
|
-
output?: string;
|
|
19
|
-
error?: string;
|
|
20
|
-
}) => void): BaseCallbackHandler;
|
|
21
|
-
export {};
|
|
@@ -1,268 +0,0 @@
|
|
|
1
|
-
import { BaseCallbackHandler } from '@langchain/core/callbacks/base';
|
|
2
|
-
import { appendFileSync } from 'node:fs';
|
|
3
|
-
import { readFile } from 'node:fs/promises';
|
|
4
|
-
import { buildToolUiVars, renderToolTemplate, resolveToolUi, toolNameFromSerialized, } from './toolConfig.js';
|
|
5
|
-
import { getConfig } from '../configuration/configManager.js';
|
|
6
|
-
function debugEventsEnabled() {
|
|
7
|
-
return getConfig().debugEvents;
|
|
8
|
-
}
|
|
9
|
-
function debugLog(message) {
|
|
10
|
-
if (!debugEventsEnabled())
|
|
11
|
-
return;
|
|
12
|
-
const ts = new Date().toISOString();
|
|
13
|
-
const line = `[CodeMax][toolcb][${ts}] ${message}\n`;
|
|
14
|
-
try {
|
|
15
|
-
process.stderr.write(line);
|
|
16
|
-
}
|
|
17
|
-
catch {
|
|
18
|
-
// ignore
|
|
19
|
-
}
|
|
20
|
-
try {
|
|
21
|
-
const p = (process.env['CODEMAX_DEBUG_LOG_FILE'] ?? '').trim() ||
|
|
22
|
-
'/tmp/codemax-debug.log';
|
|
23
|
-
appendFileSync(p, line, { encoding: 'utf8' });
|
|
24
|
-
}
|
|
25
|
-
catch {
|
|
26
|
-
// ignore
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
function stringifyOutput(output) {
|
|
30
|
-
if (typeof output === 'string')
|
|
31
|
-
return output;
|
|
32
|
-
if (output && typeof output === 'object' && 'content' in output) {
|
|
33
|
-
const c = output.content;
|
|
34
|
-
if (typeof c === 'string')
|
|
35
|
-
return c;
|
|
36
|
-
try {
|
|
37
|
-
return JSON.stringify(c);
|
|
38
|
-
}
|
|
39
|
-
catch {
|
|
40
|
-
return String(c);
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
try {
|
|
44
|
-
return JSON.stringify(output);
|
|
45
|
-
}
|
|
46
|
-
catch {
|
|
47
|
-
return String(output);
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
const MAX_SHELL_DISPLAY_LINES = 20;
|
|
51
|
-
function extractShellOutput(raw) {
|
|
52
|
-
const stdoutMatch = raw.match(/stdout:\n([\s\S]*?)(?=\nstderr:|$)/);
|
|
53
|
-
const stderrMatch = raw.match(/stderr:\n([\s\S]*)$/);
|
|
54
|
-
let out = stdoutMatch?.[1]?.trimEnd() ?? '';
|
|
55
|
-
const err = stderrMatch?.[1]?.trimEnd() ?? '';
|
|
56
|
-
if (err)
|
|
57
|
-
out += (out ? '\n' : '') + err;
|
|
58
|
-
if (!out)
|
|
59
|
-
out = raw.trimEnd();
|
|
60
|
-
const lines = out.split('\n');
|
|
61
|
-
if (lines.length > MAX_SHELL_DISPLAY_LINES) {
|
|
62
|
-
return (lines.slice(0, MAX_SHELL_DISPLAY_LINES).join('\n') +
|
|
63
|
-
`\n… ${lines.length - MAX_SHELL_DISPLAY_LINES} more lines`);
|
|
64
|
-
}
|
|
65
|
-
return out;
|
|
66
|
-
}
|
|
67
|
-
function safeJsonParse(text) {
|
|
68
|
-
try {
|
|
69
|
-
return JSON.parse(text);
|
|
70
|
-
}
|
|
71
|
-
catch {
|
|
72
|
-
return null;
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
export function isWriteOutput(text) {
|
|
76
|
-
return text.startsWith('__write__\n');
|
|
77
|
-
}
|
|
78
|
-
export function parseWriteOutput(text) {
|
|
79
|
-
const lines = text.split('\n').slice(1);
|
|
80
|
-
const summary = lines[0] ?? '';
|
|
81
|
-
const body = lines.slice(1);
|
|
82
|
-
const entries = [];
|
|
83
|
-
let omitted = 0;
|
|
84
|
-
for (const line of body) {
|
|
85
|
-
if (line.startsWith('__omitted__|')) {
|
|
86
|
-
omitted = Number(line.split('|')[1] ?? '0');
|
|
87
|
-
continue;
|
|
88
|
-
}
|
|
89
|
-
const m = line.match(/^(\d+)\|([+ -])\|(.*)$/);
|
|
90
|
-
if (!m)
|
|
91
|
-
continue;
|
|
92
|
-
const [, num, marker, content] = m;
|
|
93
|
-
const type = marker === '+' ? 'add' : marker === '-' ? 'remove' : 'context';
|
|
94
|
-
entries.push({ type, lineNum: Number(num), text: content ?? '' });
|
|
95
|
-
}
|
|
96
|
-
return { summary, entries, omitted };
|
|
97
|
-
}
|
|
98
|
-
export function createToolUiCallbackHandler() {
|
|
99
|
-
return createToolUiCallbackHandlerWithSink();
|
|
100
|
-
}
|
|
101
|
-
export function createToolUiCallbackHandlerWithSink(emit) {
|
|
102
|
-
const runById = new Map();
|
|
103
|
-
return new (class extends BaseCallbackHandler {
|
|
104
|
-
constructor() {
|
|
105
|
-
super({
|
|
106
|
-
ignoreLLM: true,
|
|
107
|
-
ignoreChain: false,
|
|
108
|
-
ignoreAgent: false,
|
|
109
|
-
ignoreRetriever: true,
|
|
110
|
-
ignoreCustomEvent: true,
|
|
111
|
-
});
|
|
112
|
-
Object.defineProperty(this, "name", {
|
|
113
|
-
enumerable: true,
|
|
114
|
-
configurable: true,
|
|
115
|
-
writable: true,
|
|
116
|
-
value: 'codeMaxToolUi'
|
|
117
|
-
});
|
|
118
|
-
}
|
|
119
|
-
async handleToolStart(tool, input, runId, _parentRunId, _tags, _metadata, runName, toolCallId) {
|
|
120
|
-
const toolName = toolNameFromSerialized(tool, runName ?? '');
|
|
121
|
-
debugLog(`handleToolStart tool=${toolName} runId=${runId}`);
|
|
122
|
-
let oldContent;
|
|
123
|
-
if (toolName === 'writeFileTool' || toolName === 'editFileTool') {
|
|
124
|
-
const parsed = safeJsonParse(input);
|
|
125
|
-
const filePath = parsed && typeof parsed === 'object'
|
|
126
|
-
? String(parsed['filePath'] ?? '')
|
|
127
|
-
: '';
|
|
128
|
-
if (filePath) {
|
|
129
|
-
try {
|
|
130
|
-
oldContent = await readFile(filePath, 'utf8');
|
|
131
|
-
}
|
|
132
|
-
catch {
|
|
133
|
-
oldContent = '';
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
runById.set(runId, { toolName, input, toolCallId, oldContent });
|
|
138
|
-
const cfg = resolveToolUi(toolName);
|
|
139
|
-
const vars = buildToolUiVars({
|
|
140
|
-
toolName,
|
|
141
|
-
input,
|
|
142
|
-
output: '',
|
|
143
|
-
toolCallId,
|
|
144
|
-
runId,
|
|
145
|
-
maxInputPreview: cfg.maxInputPreview,
|
|
146
|
-
maxOutputPreview: cfg.maxOutputPreview,
|
|
147
|
-
placeholders: cfg.placeholders,
|
|
148
|
-
});
|
|
149
|
-
emit?.({
|
|
150
|
-
type: 'on_tool_start',
|
|
151
|
-
toolName,
|
|
152
|
-
input: renderToolTemplate(cfg.onCallTemplate, vars),
|
|
153
|
-
});
|
|
154
|
-
}
|
|
155
|
-
async handleToolEnd(output, runId) {
|
|
156
|
-
const meta = runById.get(runId);
|
|
157
|
-
runById.delete(runId);
|
|
158
|
-
const toolName = meta?.toolName ?? 'tool';
|
|
159
|
-
const input = meta?.input ?? '';
|
|
160
|
-
const toolCallId = meta?.toolCallId;
|
|
161
|
-
const outStr = stringifyOutput(output);
|
|
162
|
-
debugLog(`handleToolEnd tool=${toolName} runId=${runId} output_len=${outStr.length}`);
|
|
163
|
-
// shellTool: show clean stdout output
|
|
164
|
-
if (toolName === 'shellTool') {
|
|
165
|
-
emit?.({
|
|
166
|
-
type: 'on_tool_end',
|
|
167
|
-
toolName,
|
|
168
|
-
output: extractShellOutput(outStr),
|
|
169
|
-
});
|
|
170
|
-
return;
|
|
171
|
-
}
|
|
172
|
-
// writeFileTool: compute and emit diff
|
|
173
|
-
if (toolName === 'writeFileTool' && meta) {
|
|
174
|
-
const parsed = safeJsonParse(input);
|
|
175
|
-
const newContent = parsed && typeof parsed === 'object'
|
|
176
|
-
? String(parsed['content'] ?? '')
|
|
177
|
-
: '';
|
|
178
|
-
const filePath = parsed && typeof parsed === 'object'
|
|
179
|
-
? String(parsed['filePath'] ?? '')
|
|
180
|
-
: '';
|
|
181
|
-
const lines = newContent.split('\n');
|
|
182
|
-
const lineCount = lines.length;
|
|
183
|
-
const summary = `Updated ${filePath} with ${lineCount} additions`;
|
|
184
|
-
const PREVIEW_LIMIT = 8;
|
|
185
|
-
const previewLines = lines.slice(0, PREVIEW_LIMIT);
|
|
186
|
-
const omittedCount = lineCount - previewLines.length;
|
|
187
|
-
const entries = previewLines.map((text, i) => ({
|
|
188
|
-
type: 'add',
|
|
189
|
-
lineNum: i + 1,
|
|
190
|
-
text,
|
|
191
|
-
}));
|
|
192
|
-
const output = `__write__\n${summary}\n` +
|
|
193
|
-
entries.map(e => `${e.lineNum}|+|${e.text}`).join('\n') +
|
|
194
|
-
(omittedCount > 0 ? `\n__omitted__|${omittedCount}` : '');
|
|
195
|
-
emit?.({ type: 'on_tool_end', toolName, output });
|
|
196
|
-
return;
|
|
197
|
-
}
|
|
198
|
-
// readFileTool: show line count
|
|
199
|
-
if (toolName === 'readFileTool' && meta) {
|
|
200
|
-
const lineCount = outStr ? outStr.split('\n').length : 0;
|
|
201
|
-
emit?.({
|
|
202
|
-
type: 'on_tool_end',
|
|
203
|
-
toolName,
|
|
204
|
-
output: `Read ${lineCount} lines (ctrl+r to expand)`,
|
|
205
|
-
});
|
|
206
|
-
return;
|
|
207
|
-
}
|
|
208
|
-
// editFileTool: compute and emit diff
|
|
209
|
-
if (toolName === 'editFileTool' && meta) {
|
|
210
|
-
const parsed = safeJsonParse(input);
|
|
211
|
-
const filePath = parsed?.filePath ?? '';
|
|
212
|
-
const start = parsed?.start ?? 1;
|
|
213
|
-
const end = parsed?.end ?? 1;
|
|
214
|
-
const newContent = parsed?.content ?? '';
|
|
215
|
-
const oldLines = (meta.oldContent ?? '').split('\n');
|
|
216
|
-
const startIdx = Math.max(0, start - 1);
|
|
217
|
-
const endIdx = Math.min(oldLines.length, end);
|
|
218
|
-
const removedLines = oldLines.slice(startIdx, endIdx);
|
|
219
|
-
const addedLines = newContent.split('\n');
|
|
220
|
-
const summary = `Updated ${filePath} with ${addedLines.length} additions and ${removedLines.length} removals`;
|
|
221
|
-
const entries = [];
|
|
222
|
-
// Add removed lines to diff
|
|
223
|
-
removedLines.forEach((text, i) => {
|
|
224
|
-
entries.push({
|
|
225
|
-
type: 'remove',
|
|
226
|
-
lineNum: start + i,
|
|
227
|
-
text,
|
|
228
|
-
});
|
|
229
|
-
});
|
|
230
|
-
// Add added lines to diff
|
|
231
|
-
addedLines.forEach((text, i) => {
|
|
232
|
-
entries.push({
|
|
233
|
-
type: 'add',
|
|
234
|
-
lineNum: start + i,
|
|
235
|
-
text,
|
|
236
|
-
});
|
|
237
|
-
});
|
|
238
|
-
const output = `__write__\n${summary}\n` +
|
|
239
|
-
entries
|
|
240
|
-
.map(e => `${e.lineNum}|${e.type === 'add' ? '+' : '-'}|${e.text}`)
|
|
241
|
-
.join('\n');
|
|
242
|
-
emit?.({ type: 'on_tool_end', toolName, output });
|
|
243
|
-
return;
|
|
244
|
-
}
|
|
245
|
-
const cfg = resolveToolUi(toolName);
|
|
246
|
-
const vars = buildToolUiVars({
|
|
247
|
-
toolName,
|
|
248
|
-
input,
|
|
249
|
-
output: outStr,
|
|
250
|
-
toolCallId,
|
|
251
|
-
runId,
|
|
252
|
-
maxInputPreview: cfg.maxInputPreview,
|
|
253
|
-
maxOutputPreview: cfg.maxOutputPreview,
|
|
254
|
-
placeholders: cfg.placeholders,
|
|
255
|
-
});
|
|
256
|
-
emit?.({
|
|
257
|
-
type: 'on_tool_end',
|
|
258
|
-
toolName,
|
|
259
|
-
output: renderToolTemplate(cfg.onResultTemplate, vars),
|
|
260
|
-
});
|
|
261
|
-
}
|
|
262
|
-
async handleToolError(err, runId) {
|
|
263
|
-
runById.delete(runId);
|
|
264
|
-
debugLog(`handleToolError runId=${runId} err=${err.message}`);
|
|
265
|
-
emit?.({ type: 'on_tool_error', error: err.message });
|
|
266
|
-
}
|
|
267
|
-
})();
|
|
268
|
-
}
|
package/dist/tooling/tools.d.ts
DELETED
|
@@ -1,216 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Tools for the LangChain agent.
|
|
3
|
-
* MCP Playwright is optional: if the server is unavailable, the agent runs without browser tools.
|
|
4
|
-
*/
|
|
5
|
-
import { type McpServerStatus } from './mcpConfig.js';
|
|
6
|
-
import { z } from 'zod';
|
|
7
|
-
export declare function reloadMcpServer(name: string): Promise<McpServerStatus>;
|
|
8
|
-
export declare const writePlanTool: import("langchain").DynamicStructuredTool<z.ZodObject<{
|
|
9
|
-
planName: z.ZodString;
|
|
10
|
-
content: z.ZodString;
|
|
11
|
-
}, "strip", z.ZodTypeAny, {
|
|
12
|
-
content: string;
|
|
13
|
-
planName: string;
|
|
14
|
-
}, {
|
|
15
|
-
content: string;
|
|
16
|
-
planName: string;
|
|
17
|
-
}>, {
|
|
18
|
-
content: string;
|
|
19
|
-
planName: string;
|
|
20
|
-
}, {
|
|
21
|
-
content: string;
|
|
22
|
-
planName: string;
|
|
23
|
-
}, string, unknown, "writePlanTool">;
|
|
24
|
-
export declare const MCP_STATUSES: McpServerStatus[];
|
|
25
|
-
export declare const TOOLS: (import("langchain").DynamicStructuredTool<z.ZodObject<{
|
|
26
|
-
command: z.ZodString;
|
|
27
|
-
cwd: z.ZodOptional<z.ZodString>;
|
|
28
|
-
timeout_ms: z.ZodOptional<z.ZodNumber>;
|
|
29
|
-
}, "strip", z.ZodTypeAny, {
|
|
30
|
-
command: string;
|
|
31
|
-
cwd?: string | undefined;
|
|
32
|
-
timeout_ms?: number | undefined;
|
|
33
|
-
}, {
|
|
34
|
-
command: string;
|
|
35
|
-
cwd?: string | undefined;
|
|
36
|
-
timeout_ms?: number | undefined;
|
|
37
|
-
}>, {
|
|
38
|
-
command: string;
|
|
39
|
-
cwd?: string | undefined;
|
|
40
|
-
timeout_ms?: number | undefined;
|
|
41
|
-
}, {
|
|
42
|
-
command: string;
|
|
43
|
-
cwd?: string | undefined;
|
|
44
|
-
timeout_ms?: number | undefined;
|
|
45
|
-
}, string, unknown, "shellTool"> | import("langchain").DynamicStructuredTool<import("@langchain/core/tools").ToolSchemaBase, any, any, any, unknown, string> | import("langchain").DynamicStructuredTool<z.ZodObject<{
|
|
46
|
-
filePath: z.ZodString;
|
|
47
|
-
startLine: z.ZodOptional<z.ZodNumber>;
|
|
48
|
-
endLine: z.ZodOptional<z.ZodNumber>;
|
|
49
|
-
}, "strip", z.ZodTypeAny, {
|
|
50
|
-
filePath: string;
|
|
51
|
-
startLine?: number | undefined;
|
|
52
|
-
endLine?: number | undefined;
|
|
53
|
-
}, {
|
|
54
|
-
filePath: string;
|
|
55
|
-
startLine?: number | undefined;
|
|
56
|
-
endLine?: number | undefined;
|
|
57
|
-
}>, {
|
|
58
|
-
filePath: string;
|
|
59
|
-
startLine?: number | undefined;
|
|
60
|
-
endLine?: number | undefined;
|
|
61
|
-
}, {
|
|
62
|
-
filePath: string;
|
|
63
|
-
startLine?: number | undefined;
|
|
64
|
-
endLine?: number | undefined;
|
|
65
|
-
}, string, unknown, "readFileTool"> | import("langchain").DynamicStructuredTool<z.ZodObject<{
|
|
66
|
-
filePath: z.ZodString;
|
|
67
|
-
content: z.ZodString;
|
|
68
|
-
append: z.ZodDefault<z.ZodBoolean>;
|
|
69
|
-
}, "strip", z.ZodTypeAny, {
|
|
70
|
-
content: string;
|
|
71
|
-
filePath: string;
|
|
72
|
-
append: boolean;
|
|
73
|
-
}, {
|
|
74
|
-
content: string;
|
|
75
|
-
filePath: string;
|
|
76
|
-
append?: boolean | undefined;
|
|
77
|
-
}>, {
|
|
78
|
-
content: string;
|
|
79
|
-
filePath: string;
|
|
80
|
-
append: boolean;
|
|
81
|
-
}, {
|
|
82
|
-
content: string;
|
|
83
|
-
filePath: string;
|
|
84
|
-
append?: boolean | undefined;
|
|
85
|
-
}, string, unknown, "writeFileTool"> | import("langchain").DynamicStructuredTool<z.ZodObject<{
|
|
86
|
-
filePath: z.ZodString;
|
|
87
|
-
start: z.ZodNumber;
|
|
88
|
-
end: z.ZodNumber;
|
|
89
|
-
content: z.ZodString;
|
|
90
|
-
}, "strip", z.ZodTypeAny, {
|
|
91
|
-
content: string;
|
|
92
|
-
start: number;
|
|
93
|
-
filePath: string;
|
|
94
|
-
end: number;
|
|
95
|
-
}, {
|
|
96
|
-
content: string;
|
|
97
|
-
start: number;
|
|
98
|
-
filePath: string;
|
|
99
|
-
end: number;
|
|
100
|
-
}>, {
|
|
101
|
-
content: string;
|
|
102
|
-
start: number;
|
|
103
|
-
filePath: string;
|
|
104
|
-
end: number;
|
|
105
|
-
}, {
|
|
106
|
-
content: string;
|
|
107
|
-
start: number;
|
|
108
|
-
filePath: string;
|
|
109
|
-
end: number;
|
|
110
|
-
}, string, unknown, "editFileTool"> | import("langchain").DynamicStructuredTool<z.ZodObject<{
|
|
111
|
-
action: z.ZodEnum<["add", "update", "remove", "list"]>;
|
|
112
|
-
id: z.ZodOptional<z.ZodString>;
|
|
113
|
-
task: z.ZodOptional<z.ZodString>;
|
|
114
|
-
status: z.ZodOptional<z.ZodEnum<["pending", "in_progress", "completed"]>>;
|
|
115
|
-
}, "strip", z.ZodTypeAny, {
|
|
116
|
-
action: "add" | "update" | "remove" | "list";
|
|
117
|
-
status?: "pending" | "in_progress" | "completed" | undefined;
|
|
118
|
-
id?: string | undefined;
|
|
119
|
-
task?: string | undefined;
|
|
120
|
-
}, {
|
|
121
|
-
action: "add" | "update" | "remove" | "list";
|
|
122
|
-
status?: "pending" | "in_progress" | "completed" | undefined;
|
|
123
|
-
id?: string | undefined;
|
|
124
|
-
task?: string | undefined;
|
|
125
|
-
}>, {
|
|
126
|
-
action: "add" | "update" | "remove" | "list";
|
|
127
|
-
status?: "pending" | "in_progress" | "completed" | undefined;
|
|
128
|
-
id?: string | undefined;
|
|
129
|
-
task?: string | undefined;
|
|
130
|
-
}, {
|
|
131
|
-
action: "add" | "update" | "remove" | "list";
|
|
132
|
-
status?: "pending" | "in_progress" | "completed" | undefined;
|
|
133
|
-
id?: string | undefined;
|
|
134
|
-
task?: string | undefined;
|
|
135
|
-
}, string, unknown, "todoTool">)[];
|
|
136
|
-
export declare const PLAN_TOOLS: (import("langchain").DynamicStructuredTool<z.ZodObject<{
|
|
137
|
-
command: z.ZodString;
|
|
138
|
-
cwd: z.ZodOptional<z.ZodString>;
|
|
139
|
-
timeout_ms: z.ZodOptional<z.ZodNumber>;
|
|
140
|
-
}, "strip", z.ZodTypeAny, {
|
|
141
|
-
command: string;
|
|
142
|
-
cwd?: string | undefined;
|
|
143
|
-
timeout_ms?: number | undefined;
|
|
144
|
-
}, {
|
|
145
|
-
command: string;
|
|
146
|
-
cwd?: string | undefined;
|
|
147
|
-
timeout_ms?: number | undefined;
|
|
148
|
-
}>, {
|
|
149
|
-
command: string;
|
|
150
|
-
cwd?: string | undefined;
|
|
151
|
-
timeout_ms?: number | undefined;
|
|
152
|
-
}, {
|
|
153
|
-
command: string;
|
|
154
|
-
cwd?: string | undefined;
|
|
155
|
-
timeout_ms?: number | undefined;
|
|
156
|
-
}, string, unknown, "shellTool"> | import("langchain").DynamicStructuredTool<import("@langchain/core/tools").ToolSchemaBase, any, any, any, unknown, string> | import("langchain").DynamicStructuredTool<z.ZodObject<{
|
|
157
|
-
filePath: z.ZodString;
|
|
158
|
-
startLine: z.ZodOptional<z.ZodNumber>;
|
|
159
|
-
endLine: z.ZodOptional<z.ZodNumber>;
|
|
160
|
-
}, "strip", z.ZodTypeAny, {
|
|
161
|
-
filePath: string;
|
|
162
|
-
startLine?: number | undefined;
|
|
163
|
-
endLine?: number | undefined;
|
|
164
|
-
}, {
|
|
165
|
-
filePath: string;
|
|
166
|
-
startLine?: number | undefined;
|
|
167
|
-
endLine?: number | undefined;
|
|
168
|
-
}>, {
|
|
169
|
-
filePath: string;
|
|
170
|
-
startLine?: number | undefined;
|
|
171
|
-
endLine?: number | undefined;
|
|
172
|
-
}, {
|
|
173
|
-
filePath: string;
|
|
174
|
-
startLine?: number | undefined;
|
|
175
|
-
endLine?: number | undefined;
|
|
176
|
-
}, string, unknown, "readFileTool"> | import("langchain").DynamicStructuredTool<z.ZodObject<{
|
|
177
|
-
action: z.ZodEnum<["add", "update", "remove", "list"]>;
|
|
178
|
-
id: z.ZodOptional<z.ZodString>;
|
|
179
|
-
task: z.ZodOptional<z.ZodString>;
|
|
180
|
-
status: z.ZodOptional<z.ZodEnum<["pending", "in_progress", "completed"]>>;
|
|
181
|
-
}, "strip", z.ZodTypeAny, {
|
|
182
|
-
action: "add" | "update" | "remove" | "list";
|
|
183
|
-
status?: "pending" | "in_progress" | "completed" | undefined;
|
|
184
|
-
id?: string | undefined;
|
|
185
|
-
task?: string | undefined;
|
|
186
|
-
}, {
|
|
187
|
-
action: "add" | "update" | "remove" | "list";
|
|
188
|
-
status?: "pending" | "in_progress" | "completed" | undefined;
|
|
189
|
-
id?: string | undefined;
|
|
190
|
-
task?: string | undefined;
|
|
191
|
-
}>, {
|
|
192
|
-
action: "add" | "update" | "remove" | "list";
|
|
193
|
-
status?: "pending" | "in_progress" | "completed" | undefined;
|
|
194
|
-
id?: string | undefined;
|
|
195
|
-
task?: string | undefined;
|
|
196
|
-
}, {
|
|
197
|
-
action: "add" | "update" | "remove" | "list";
|
|
198
|
-
status?: "pending" | "in_progress" | "completed" | undefined;
|
|
199
|
-
id?: string | undefined;
|
|
200
|
-
task?: string | undefined;
|
|
201
|
-
}, string, unknown, "todoTool"> | import("langchain").DynamicStructuredTool<z.ZodObject<{
|
|
202
|
-
planName: z.ZodString;
|
|
203
|
-
content: z.ZodString;
|
|
204
|
-
}, "strip", z.ZodTypeAny, {
|
|
205
|
-
content: string;
|
|
206
|
-
planName: string;
|
|
207
|
-
}, {
|
|
208
|
-
content: string;
|
|
209
|
-
planName: string;
|
|
210
|
-
}>, {
|
|
211
|
-
content: string;
|
|
212
|
-
planName: string;
|
|
213
|
-
}, {
|
|
214
|
-
content: string;
|
|
215
|
-
planName: string;
|
|
216
|
-
}, string, unknown, "writePlanTool">)[];
|