micro-models-agent 0.2.49 → 0.2.51
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/loop.d.ts.map +1 -1
- package/dist/agent/loop.js +87 -303
- package/dist/agent/loop.js.map +1 -1
- package/dist/agent/modes/applier.d.ts +43 -0
- package/dist/agent/modes/applier.d.ts.map +1 -0
- package/dist/agent/modes/applier.js +30 -0
- package/dist/agent/modes/applier.js.map +1 -0
- package/dist/agent/modes/registry.d.ts +35 -0
- package/dist/agent/modes/registry.d.ts.map +1 -0
- package/dist/agent/modes/registry.js +169 -0
- package/dist/agent/modes/registry.js.map +1 -0
- package/dist/agent/modes/types.d.ts +54 -0
- package/dist/agent/modes/types.d.ts.map +1 -0
- package/dist/agent/modes/types.js +13 -0
- package/dist/agent/modes/types.js.map +1 -0
- package/dist/agent/react-loop.d.ts +61 -0
- package/dist/agent/react-loop.d.ts.map +1 -0
- package/dist/agent/react-loop.js +119 -0
- package/dist/agent/react-loop.js.map +1 -0
- package/dist/agent/tool-executor.d.ts +44 -0
- package/dist/agent/tool-executor.d.ts.map +1 -0
- package/dist/agent/tool-executor.js +186 -0
- package/dist/agent/tool-executor.js.map +1 -0
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +48 -1
- package/dist/cli.js.map +1 -1
- package/dist/config/types.d.ts +5 -2
- package/dist/config/types.d.ts.map +1 -1
- package/dist/plugins/adapters/hooks-adapter.d.ts +12 -0
- package/dist/plugins/adapters/hooks-adapter.d.ts.map +1 -0
- package/dist/plugins/adapters/hooks-adapter.js +23 -0
- package/dist/plugins/adapters/hooks-adapter.js.map +1 -0
- package/dist/plugins/loader.d.ts +13 -0
- package/dist/plugins/loader.d.ts.map +1 -0
- package/dist/plugins/loader.js +145 -0
- package/dist/plugins/loader.js.map +1 -0
- package/dist/plugins/manager.d.ts +52 -0
- package/dist/plugins/manager.d.ts.map +1 -0
- package/dist/plugins/manager.js +183 -0
- package/dist/plugins/manager.js.map +1 -0
- package/dist/plugins/types.d.ts +73 -0
- package/dist/plugins/types.d.ts.map +1 -0
- package/dist/plugins/types.js +8 -0
- package/dist/plugins/types.js.map +1 -0
- package/dist/repl/commands.d.ts +1 -0
- package/dist/repl/commands.d.ts.map +1 -1
- package/dist/repl/commands.js.map +1 -1
- package/dist/repl/index.d.ts.map +1 -1
- package/dist/repl/index.js +3 -2
- package/dist/repl/index.js.map +1 -1
- package/dist/session/store.d.ts +4 -2
- package/dist/session/store.d.ts.map +1 -1
- package/dist/session/store.js +4 -2
- package/dist/session/store.js.map +1 -1
- package/dist/tools/bash.d.ts +4 -0
- package/dist/tools/bash.d.ts.map +1 -1
- package/dist/tools/bash.js +24 -0
- package/dist/tools/bash.js.map +1 -1
- package/dist/tools/fs/copy-file.d.ts +2 -0
- package/dist/tools/fs/copy-file.d.ts.map +1 -1
- package/dist/tools/fs/copy-file.js +7 -0
- package/dist/tools/fs/copy-file.js.map +1 -1
- package/dist/tools/fs/create-dir.d.ts +2 -0
- package/dist/tools/fs/create-dir.d.ts.map +1 -1
- package/dist/tools/fs/create-dir.js +7 -0
- package/dist/tools/fs/create-dir.js.map +1 -1
- package/dist/tools/fs/delete-file.d.ts +2 -0
- package/dist/tools/fs/delete-file.d.ts.map +1 -1
- package/dist/tools/fs/delete-file.js +7 -0
- package/dist/tools/fs/delete-file.js.map +1 -1
- package/dist/tools/fs/edit-file.d.ts +2 -0
- package/dist/tools/fs/edit-file.d.ts.map +1 -1
- package/dist/tools/fs/edit-file.js +7 -0
- package/dist/tools/fs/edit-file.js.map +1 -1
- package/dist/tools/fs/file-info.d.ts +2 -0
- package/dist/tools/fs/file-info.d.ts.map +1 -1
- package/dist/tools/fs/file-info.js +7 -0
- package/dist/tools/fs/file-info.js.map +1 -1
- package/dist/tools/fs/glob-search.d.ts +2 -0
- package/dist/tools/fs/glob-search.d.ts.map +1 -1
- package/dist/tools/fs/glob-search.js +7 -0
- package/dist/tools/fs/glob-search.js.map +1 -1
- package/dist/tools/fs/grep-search.d.ts +2 -0
- package/dist/tools/fs/grep-search.d.ts.map +1 -1
- package/dist/tools/fs/grep-search.js +7 -0
- package/dist/tools/fs/grep-search.js.map +1 -1
- package/dist/tools/fs/list-dir.d.ts +2 -0
- package/dist/tools/fs/list-dir.d.ts.map +1 -1
- package/dist/tools/fs/list-dir.js +7 -0
- package/dist/tools/fs/list-dir.js.map +1 -1
- package/dist/tools/fs/move-file.d.ts +2 -0
- package/dist/tools/fs/move-file.d.ts.map +1 -1
- package/dist/tools/fs/move-file.js +7 -0
- package/dist/tools/fs/move-file.js.map +1 -1
- package/dist/tools/fs/read-file.d.ts +2 -0
- package/dist/tools/fs/read-file.d.ts.map +1 -1
- package/dist/tools/fs/read-file.js +7 -0
- package/dist/tools/fs/read-file.js.map +1 -1
- package/dist/tools/fs/tree.d.ts +2 -0
- package/dist/tools/fs/tree.d.ts.map +1 -1
- package/dist/tools/fs/tree.js +7 -0
- package/dist/tools/fs/tree.js.map +1 -1
- package/dist/tools/fs/write-file.d.ts +2 -0
- package/dist/tools/fs/write-file.d.ts.map +1 -1
- package/dist/tools/fs/write-file.js +7 -0
- package/dist/tools/fs/write-file.js.map +1 -1
- package/dist/tools/native/approve.d.ts +11 -0
- package/dist/tools/native/approve.d.ts.map +1 -0
- package/dist/tools/native/approve.js +39 -0
- package/dist/tools/native/approve.js.map +1 -0
- package/dist/tools/native/plan.d.ts +10 -0
- package/dist/tools/native/plan.d.ts.map +1 -0
- package/dist/tools/native/plan.js +46 -0
- package/dist/tools/native/plan.js.map +1 -0
- package/dist/tools/native/question.d.ts +11 -0
- package/dist/tools/native/question.d.ts.map +1 -0
- package/dist/tools/native/question.js +41 -0
- package/dist/tools/native/question.js.map +1 -0
- package/dist/tools/native/theme.d.ts +10 -0
- package/dist/tools/native/theme.d.ts.map +1 -0
- package/dist/tools/native/theme.js +106 -0
- package/dist/tools/native/theme.js.map +1 -0
- package/dist/tools/native/todo.d.ts +10 -0
- package/dist/tools/native/todo.d.ts.map +1 -0
- package/dist/tools/native/todo.js +58 -0
- package/dist/tools/native/todo.js.map +1 -0
- package/dist/tools/native/user-profile.d.ts +10 -0
- package/dist/tools/native/user-profile.d.ts.map +1 -0
- package/dist/tools/native/user-profile.js +58 -0
- package/dist/tools/native/user-profile.js.map +1 -0
- package/dist/tools/registry.d.ts +11 -10
- package/dist/tools/registry.d.ts.map +1 -1
- package/dist/tools/registry.js +40 -147
- package/dist/tools/registry.js.map +1 -1
- package/dist/tools/subagent.d.ts +2 -1
- package/dist/tools/subagent.d.ts.map +1 -1
- package/dist/tools/subagent.js +7 -4
- package/dist/tools/subagent.js.map +1 -1
- package/dist/tools/types.d.ts +59 -0
- package/dist/tools/types.d.ts.map +1 -0
- package/dist/tools/types.js +2 -0
- package/dist/tools/types.js.map +1 -0
- package/dist/tools/web-fetch.d.ts +2 -0
- package/dist/tools/web-fetch.d.ts.map +1 -1
- package/dist/tools/web-fetch.js +7 -0
- package/dist/tools/web-fetch.js.map +1 -1
- package/dist/tools/web-search.d.ts +2 -0
- package/dist/tools/web-search.d.ts.map +1 -1
- package/dist/tools/web-search.js +7 -0
- package/dist/tools/web-search.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { listThemes, switchTheme } from '../../styling/index.js';
|
|
2
|
+
import { loadThemeConfig, installTheme, removeTheme } from '../../styling/loader.js';
|
|
3
|
+
import { loadConfig, saveConfig } from '../../config/config.js';
|
|
4
|
+
/**
|
|
5
|
+
* Нативный инструмент theme — управление темами оформления.
|
|
6
|
+
*
|
|
7
|
+
* @module tools/native/theme
|
|
8
|
+
*/
|
|
9
|
+
export const themeDefinition = {
|
|
10
|
+
type: 'function',
|
|
11
|
+
function: {
|
|
12
|
+
name: 'theme',
|
|
13
|
+
description: 'Manage UI themes. Actions: list, show, switch, install, remove.',
|
|
14
|
+
parameters: {
|
|
15
|
+
type: 'object',
|
|
16
|
+
properties: {
|
|
17
|
+
action: { type: 'string', description: 'list, show, switch, install, remove' },
|
|
18
|
+
name: { type: 'string', description: 'Theme name (for switch/install/remove)' },
|
|
19
|
+
url: { type: 'string', description: 'Theme URL (for install)' },
|
|
20
|
+
},
|
|
21
|
+
required: ['action'],
|
|
22
|
+
},
|
|
23
|
+
},
|
|
24
|
+
};
|
|
25
|
+
export const themeHandler = {
|
|
26
|
+
name: 'theme',
|
|
27
|
+
definition: themeDefinition,
|
|
28
|
+
async execute(args, ctx) {
|
|
29
|
+
const action = String(args.action || 'list');
|
|
30
|
+
const name = String(args.name || '');
|
|
31
|
+
const url = String(args.url || '');
|
|
32
|
+
if (!ctx.quiet) {
|
|
33
|
+
ctx.renderer?.writeBracketTag('theme', action);
|
|
34
|
+
}
|
|
35
|
+
let output = '';
|
|
36
|
+
let exitCode = 0;
|
|
37
|
+
switch (action) {
|
|
38
|
+
case 'list': {
|
|
39
|
+
const allThemes = listThemes();
|
|
40
|
+
const current = loadThemeConfig().name;
|
|
41
|
+
output = `Available themes (${allThemes.length}):\n`;
|
|
42
|
+
for (const t of allThemes) {
|
|
43
|
+
output += ` ${t}${t === current ? ' (active)' : ''}\n`;
|
|
44
|
+
}
|
|
45
|
+
break;
|
|
46
|
+
}
|
|
47
|
+
case 'show': {
|
|
48
|
+
const config = loadThemeConfig();
|
|
49
|
+
output = `Theme: ${config.name}\nColors: ${JSON.stringify(config.colors, null, 2)}\nIcons: ${JSON.stringify(config.icons, null, 2)}`;
|
|
50
|
+
break;
|
|
51
|
+
}
|
|
52
|
+
case 'switch': {
|
|
53
|
+
const allThemes = listThemes();
|
|
54
|
+
if (!allThemes.includes(name)) {
|
|
55
|
+
output = `Unknown theme "${name}". Available: ${allThemes.join(', ')}`;
|
|
56
|
+
exitCode = 1;
|
|
57
|
+
break;
|
|
58
|
+
}
|
|
59
|
+
const appConfig = loadConfig();
|
|
60
|
+
appConfig.theme = name;
|
|
61
|
+
saveConfig(appConfig);
|
|
62
|
+
switchTheme(name);
|
|
63
|
+
try {
|
|
64
|
+
const { resetInkTheme } = await import('../../ui/ink/theme.js');
|
|
65
|
+
resetInkTheme();
|
|
66
|
+
}
|
|
67
|
+
catch { /* not in ink mode */ }
|
|
68
|
+
output = `Theme switched to "${name}"`;
|
|
69
|
+
break;
|
|
70
|
+
}
|
|
71
|
+
case 'install': {
|
|
72
|
+
if (!name || !url) {
|
|
73
|
+
output = 'Usage: theme install <name> <url>';
|
|
74
|
+
exitCode = 1;
|
|
75
|
+
break;
|
|
76
|
+
}
|
|
77
|
+
try {
|
|
78
|
+
const resp = await fetch(url);
|
|
79
|
+
const text = await resp.text();
|
|
80
|
+
JSON.parse(text);
|
|
81
|
+
installTheme(name, text);
|
|
82
|
+
output = `Theme "${name}" installed from ${url}`;
|
|
83
|
+
}
|
|
84
|
+
catch (e) {
|
|
85
|
+
output = `Failed to install theme: ${e.message}`;
|
|
86
|
+
exitCode = 1;
|
|
87
|
+
}
|
|
88
|
+
break;
|
|
89
|
+
}
|
|
90
|
+
case 'remove': {
|
|
91
|
+
if (!removeTheme(name)) {
|
|
92
|
+
output = `Theme "${name}" not found`;
|
|
93
|
+
exitCode = 1;
|
|
94
|
+
break;
|
|
95
|
+
}
|
|
96
|
+
output = `Theme "${name}" removed`;
|
|
97
|
+
break;
|
|
98
|
+
}
|
|
99
|
+
default:
|
|
100
|
+
output = 'Unknown theme action. Use: list, show, switch, install, remove';
|
|
101
|
+
exitCode = 1;
|
|
102
|
+
}
|
|
103
|
+
return { stdout: output, stderr: '', exitCode, truncated: false };
|
|
104
|
+
},
|
|
105
|
+
};
|
|
106
|
+
//# sourceMappingURL=theme.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"theme.js","sourceRoot":"","sources":["../../../src/tools/native/theme.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACjE,OAAO,EAAE,eAAe,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAC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ACF,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { ToolDefinition } from '../registry.js';
|
|
2
|
+
import type { ToolHandler } from '../types.js';
|
|
3
|
+
/**
|
|
4
|
+
* Нативный инструмент todo — управление списком задач.
|
|
5
|
+
*
|
|
6
|
+
* @module tools/native/todo
|
|
7
|
+
*/
|
|
8
|
+
export declare const todoDefinition: ToolDefinition;
|
|
9
|
+
export declare const todoHandler: ToolHandler;
|
|
10
|
+
//# sourceMappingURL=todo.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"todo.d.ts","sourceRoot":"","sources":["../../../src/tools/native/todo.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AACrD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAG/C;;;;GAIG;AAEH,eAAO,MAAM,cAAc,EAAE,cAc5B,CAAC;AAEF,eAAO,MAAM,WAAW,EAAE,WA4BzB,CAAC"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { addTodo, doneTodo, removeTodo, listTodos } from '../todo.js';
|
|
2
|
+
/**
|
|
3
|
+
* Нативный инструмент todo — управление списком задач.
|
|
4
|
+
*
|
|
5
|
+
* @module tools/native/todo
|
|
6
|
+
*/
|
|
7
|
+
export const todoDefinition = {
|
|
8
|
+
type: 'function',
|
|
9
|
+
function: {
|
|
10
|
+
name: 'todo',
|
|
11
|
+
description: 'Manage a todo list. Actions: add, done, remove, list.',
|
|
12
|
+
parameters: {
|
|
13
|
+
type: 'object',
|
|
14
|
+
properties: {
|
|
15
|
+
action: { type: 'string', description: 'add, done, remove, list' },
|
|
16
|
+
text: { type: 'string', description: 'Todo text (for add/done/remove)' },
|
|
17
|
+
},
|
|
18
|
+
required: ['action'],
|
|
19
|
+
},
|
|
20
|
+
},
|
|
21
|
+
};
|
|
22
|
+
export const todoHandler = {
|
|
23
|
+
name: 'todo',
|
|
24
|
+
definition: todoDefinition,
|
|
25
|
+
async execute(args, ctx) {
|
|
26
|
+
const action = String(args.action || 'list');
|
|
27
|
+
const text = String(args.text || '');
|
|
28
|
+
if (!ctx.quiet) {
|
|
29
|
+
ctx.renderer?.writeBracketTag('todo', action);
|
|
30
|
+
}
|
|
31
|
+
let output = '';
|
|
32
|
+
let exitCode = 0;
|
|
33
|
+
switch (action) {
|
|
34
|
+
case 'add':
|
|
35
|
+
output = addTodo(text);
|
|
36
|
+
break;
|
|
37
|
+
case 'done':
|
|
38
|
+
output = doneTodo(text);
|
|
39
|
+
break;
|
|
40
|
+
case 'remove':
|
|
41
|
+
case 'rm':
|
|
42
|
+
output = removeTodo(text);
|
|
43
|
+
break;
|
|
44
|
+
case 'list':
|
|
45
|
+
case 'ls':
|
|
46
|
+
output = listTodos();
|
|
47
|
+
break;
|
|
48
|
+
default:
|
|
49
|
+
output = 'Unknown todo action. Use: add, done, remove, list';
|
|
50
|
+
exitCode = 1;
|
|
51
|
+
}
|
|
52
|
+
if (!ctx.quiet && exitCode === 0 && output) {
|
|
53
|
+
ctx.renderer?.writeLine(output);
|
|
54
|
+
}
|
|
55
|
+
return { stdout: output, stderr: '', exitCode, truncated: false };
|
|
56
|
+
},
|
|
57
|
+
};
|
|
58
|
+
//# sourceMappingURL=todo.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"todo.js","sourceRoot":"","sources":["../../../src/tools/native/todo.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAEtE;;;;GAIG;AAEH,MAAM,CAAC,MAAM,cAAc,GAAmB;IAC5C,IAAI,EAAE,UAAU;IAChB,QAAQ,EAAE;QACR,IAAI,EAAE,MAAM;QACZ,WAAW,EAAE,uDAAuD;QACpE,UAAU,EAAE;YACV,IAAI,EAAE,QAAQ;YACd,UAAU,EAAE;gBACV,MAAM,EAAE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CAAC,IAAI,MAAM,EAAE,CAAC;YAC3C,GAAG,CAAC,QAAQ,EAAE,SAAS,CAAC,MAAM,CAAC,CAAC;QAClC,CAAC;QAED,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,EAAE,EAAE,QAAQ,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC;IACpE,CAAC;CACF,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { ToolDefinition } from '../registry.js';
|
|
2
|
+
import type { ToolHandler } from '../types.js';
|
|
3
|
+
/**
|
|
4
|
+
* Нативный инструмент user_profile — управление профилем пользователя.
|
|
5
|
+
*
|
|
6
|
+
* @module tools/native/user-profile
|
|
7
|
+
*/
|
|
8
|
+
export declare const userProfileDefinition: ToolDefinition;
|
|
9
|
+
export declare const userProfileHandler: ToolHandler;
|
|
10
|
+
//# sourceMappingURL=user-profile.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"user-profile.d.ts","sourceRoot":"","sources":["../../../src/tools/native/user-profile.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AACrD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAG/C;;;;GAIG;AAEH,eAAO,MAAM,qBAAqB,EAAE,cAenC,CAAC;AAEF,eAAO,MAAM,kBAAkB,EAAE,WAsChC,CAAC"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { loadProfile, appendNote } from '../../agent/user-profile.js';
|
|
2
|
+
/**
|
|
3
|
+
* Нативный инструмент user_profile — управление профилем пользователя.
|
|
4
|
+
*
|
|
5
|
+
* @module tools/native/user-profile
|
|
6
|
+
*/
|
|
7
|
+
export const userProfileDefinition = {
|
|
8
|
+
type: 'function',
|
|
9
|
+
function: {
|
|
10
|
+
name: 'user_profile',
|
|
11
|
+
description: 'View or add notes to user profile. Actions: show, add_note.',
|
|
12
|
+
parameters: {
|
|
13
|
+
type: 'object',
|
|
14
|
+
properties: {
|
|
15
|
+
action: { type: 'string', description: 'show or add_note' },
|
|
16
|
+
note: { type: 'string', description: 'Note text (for add_note)' },
|
|
17
|
+
section: { type: 'string', description: 'Section name (for add_note, default: Notes)' },
|
|
18
|
+
},
|
|
19
|
+
required: ['action'],
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
};
|
|
23
|
+
export const userProfileHandler = {
|
|
24
|
+
name: 'user_profile',
|
|
25
|
+
definition: userProfileDefinition,
|
|
26
|
+
async execute(args, ctx) {
|
|
27
|
+
const action = String(args.action || 'show');
|
|
28
|
+
if (!ctx.quiet) {
|
|
29
|
+
ctx.renderer?.writeBracketTag('user_profile', action);
|
|
30
|
+
}
|
|
31
|
+
let output = '';
|
|
32
|
+
let exitCode = 0;
|
|
33
|
+
switch (action) {
|
|
34
|
+
case 'show': {
|
|
35
|
+
const content = loadProfile();
|
|
36
|
+
output = content || 'User profile is empty.';
|
|
37
|
+
break;
|
|
38
|
+
}
|
|
39
|
+
case 'add_note': {
|
|
40
|
+
const note = String(args.note || args.text || '');
|
|
41
|
+
const section = String(args.section || 'Notes');
|
|
42
|
+
if (!note) {
|
|
43
|
+
output = 'Usage: user_profile action=add_note section=Notes note=...';
|
|
44
|
+
exitCode = 1;
|
|
45
|
+
break;
|
|
46
|
+
}
|
|
47
|
+
appendNote(note, section);
|
|
48
|
+
output = `Note added to "${section}" section.`;
|
|
49
|
+
break;
|
|
50
|
+
}
|
|
51
|
+
default:
|
|
52
|
+
output = 'Unknown user_profile action. Use: show, add_note';
|
|
53
|
+
exitCode = 1;
|
|
54
|
+
}
|
|
55
|
+
return { stdout: output, stderr: '', exitCode, truncated: false };
|
|
56
|
+
},
|
|
57
|
+
};
|
|
58
|
+
//# sourceMappingURL=user-profile.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"user-profile.js","sourceRoot":"","sources":["../../../src/tools/native/user-profile.ts"],"names":[],"m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,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,IAAI,IAAI,EAAE,CAAC,CAAC;gBAClD,MAAM,OAAO,GAAG,MAAM,CAAC,IAAI,CAAC,OAAO,IAAI,OAAO,CAAC,CAAC;gBAChD,IAAI,CAAC,IAAI,EAAE,CAAC;oBACV,MAAM,GAAG,4DAA4D,CAAC;oBACtE,QAAQ,GAAG,CAAC,CAAC;oBACb,MAAM;gBACR,CAAC;gBACD,UAAU,CAAC,IAAI,EAAE,OAAc,CAAC,CAAC;gBACjC,MAAM,GAAG,kBAAkB,OAAO,YAAY,CAAC;gBAC/C,MAAM;YACR,CAAC;YACD;gBACE,MAAM,GAAG,kDAAkD,CAAC;gBAC5D,QAAQ,GAAG,CAAC,CAAC;QACjB,CAAC;QAED,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,EAAE,EAAE,QAAQ,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC;IACpE,CAAC;CACF,CAAC"}
|
package/dist/tools/registry.d.ts
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
import type { ChatMessage } from '../llm/provider.js';
|
|
2
|
-
import {
|
|
2
|
+
import type { BashResult } from './bash.js';
|
|
3
|
+
/**
|
|
4
|
+
* Реестр всех инструментов агента.
|
|
5
|
+
*
|
|
6
|
+
* Хранит определения инструментов для LLM и валидирует имена.
|
|
7
|
+
* Исполнение вынесено в ToolExecutor (src/agent/tool-executor.ts).
|
|
8
|
+
*
|
|
9
|
+
* @module tools/registry
|
|
10
|
+
*/
|
|
3
11
|
export interface ToolDefinition {
|
|
4
12
|
type: 'function';
|
|
5
13
|
function: {
|
|
@@ -15,17 +23,10 @@ export interface ToolCall {
|
|
|
15
23
|
}
|
|
16
24
|
export type ToolResult = BashResult;
|
|
17
25
|
/**
|
|
18
|
-
* Реестр инструментов —
|
|
19
|
-
*
|
|
26
|
+
* Реестр инструментов — хранит определения и валидирует имена.
|
|
27
|
+
* Исполнение — через ToolExecutor.
|
|
20
28
|
*/
|
|
21
29
|
export declare class ToolRegistry {
|
|
22
|
-
private cwd;
|
|
23
|
-
constructor(cwd?: string);
|
|
24
|
-
/**
|
|
25
|
-
* Исполняет tool call: определяет тип инструмента и вызывает handler.
|
|
26
|
-
* После успешной модификации файла уведомляет indexer и инвалидирует кэш.
|
|
27
|
-
*/
|
|
28
|
-
execute(toolCall: ToolCall): Promise<ToolResult>;
|
|
29
30
|
/** Возвращает определения всех доступных инструментов для system prompt */
|
|
30
31
|
getDefinitions(): ToolDefinition[];
|
|
31
32
|
isToolCall(message: ChatMessage): boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../../src/tools/registry.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../../src/tools/registry.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAgBtD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAE5C;;;;;;;GAOG;AAEH,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,UAAU,CAAC;IACjB,QAAQ,EAAE;QACR,IAAI,EAAE,MAAM,CAAC;QACb,WAAW,EAAE,MAAM,CAAC;QACpB,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;KACrC,CAAC;CACH;AAED,MAAM,WAAW,QAAQ;IACvB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACpC;AAED,MAAM,MAAM,UAAU,GAAG,UAAU,CAAC;AA0CpC;;;GAGG;AACH,qBAAa,YAAY;IACvB,2EAA2E;IAC3E,cAAc,IAAI,cAAc,EAAE;IAIlC,UAAU,CAAC,OAAO,EAAE,WAAW,GAAG,OAAO;IAIzC,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;CAGnC"}
|
package/dist/tools/registry.js
CHANGED
|
@@ -1,69 +1,21 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* Реестр всех инструментов агента.
|
|
21
|
-
*
|
|
22
|
-
* Управляет:
|
|
23
|
-
* - Файловыми инструментами (read, write, edit, list, search и т.д.)
|
|
24
|
-
* - Bash-командами
|
|
25
|
-
* - Веб-инструментами (search, fetch)
|
|
26
|
-
* - Нативными инструментами (subagent)
|
|
27
|
-
*
|
|
28
|
-
* При записи файлов автоматически:
|
|
29
|
-
* - Уведомляет indexer об изменениях (notifyFileChanged)
|
|
30
|
-
* - Инвалидирует кэш system prompt
|
|
31
|
-
*
|
|
32
|
-
* @module tools/registry
|
|
33
|
-
*/
|
|
34
|
-
// Инструменты, которые модифицируют файловую систему
|
|
35
|
-
const MODIFYING_TOOLS = new Set(['write_file', 'edit_file', 'delete_file', 'copy_file', 'move_file']);
|
|
36
|
-
/** Извлекает пути изменённых файлов из аргументов инструмента */
|
|
37
|
-
function getChangedFilePaths(toolName, args) {
|
|
38
|
-
const normalize = (p) => String(p ?? '').replace(/\\/g, '/');
|
|
39
|
-
switch (toolName) {
|
|
40
|
-
case 'write_file': return [normalize(args.path)];
|
|
41
|
-
case 'edit_file': return [normalize(args.path)];
|
|
42
|
-
case 'delete_file': return [normalize(args.path)];
|
|
43
|
-
case 'copy_file': return [normalize(args.destination)];
|
|
44
|
-
case 'move_file': return [normalize(args.source), normalize(args.destination)];
|
|
45
|
-
default: return [];
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
const FS_HANDLERS = new Map([
|
|
49
|
-
['read_file', { def: readFileDefinition, handler: handleReadFile }],
|
|
50
|
-
['write_file', { def: writeFileDefinition, handler: handleWriteFile }],
|
|
51
|
-
['edit_file', { def: editFileDefinition, handler: handleEditFile }],
|
|
52
|
-
['list_dir', { def: listDirDefinition, handler: handleListDir }],
|
|
53
|
-
['create_dir', { def: createDirDefinition, handler: handleCreateDir }],
|
|
54
|
-
['delete_file', { def: deleteFileDefinition, handler: handleDeleteFile }],
|
|
55
|
-
['copy_file', { def: copyFileDefinition, handler: handleCopyFile }],
|
|
56
|
-
['move_file', { def: moveFileDefinition, handler: handleMoveFile }],
|
|
57
|
-
['file_info', { def: fileInfoDefinition, handler: handleFileInfo }],
|
|
58
|
-
['glob_search', { def: globSearchDefinition, handler: handleGlobSearch }],
|
|
59
|
-
['grep_search', { def: grepSearchDefinition, handler: handleGrepSearch }],
|
|
60
|
-
['tree', { def: treeDefinition, handler: handleTree }],
|
|
61
|
-
]);
|
|
62
|
-
const WEB_TOOLS = new Map([
|
|
63
|
-
['web_search', { def: webSearchDefinition, handler: handleWebSearch }],
|
|
64
|
-
['web_fetch', { def: webFetchDefinition, handler: handleWebFetch }],
|
|
65
|
-
]);
|
|
66
|
-
const NATIVE_TOOL_DEFS = [
|
|
1
|
+
import { readFileDefinition } from './fs/read-file.js';
|
|
2
|
+
import { writeFileDefinition } from './fs/write-file.js';
|
|
3
|
+
import { editFileDefinition } from './fs/edit-file.js';
|
|
4
|
+
import { listDirDefinition } from './fs/list-dir.js';
|
|
5
|
+
import { createDirDefinition } from './fs/create-dir.js';
|
|
6
|
+
import { deleteFileDefinition } from './fs/delete-file.js';
|
|
7
|
+
import { copyFileDefinition } from './fs/copy-file.js';
|
|
8
|
+
import { moveFileDefinition } from './fs/move-file.js';
|
|
9
|
+
import { fileInfoDefinition } from './fs/file-info.js';
|
|
10
|
+
import { globSearchDefinition } from './fs/glob-search.js';
|
|
11
|
+
import { grepSearchDefinition } from './fs/grep-search.js';
|
|
12
|
+
import { treeDefinition } from './fs/tree.js';
|
|
13
|
+
import { bashDefinition } from './bash.js';
|
|
14
|
+
import { webSearchDefinition } from './web-search.js';
|
|
15
|
+
import { webFetchDefinition } from './web-fetch.js';
|
|
16
|
+
/** Все определения инструментов (для system prompt) */
|
|
17
|
+
const ALL_DEFINITIONS = [
|
|
18
|
+
// Native
|
|
67
19
|
{
|
|
68
20
|
type: 'function',
|
|
69
21
|
function: {
|
|
@@ -79,93 +31,34 @@ const NATIVE_TOOL_DEFS = [
|
|
|
79
31
|
},
|
|
80
32
|
},
|
|
81
33
|
},
|
|
34
|
+
// Bash
|
|
35
|
+
bashDefinition,
|
|
36
|
+
// FS
|
|
37
|
+
readFileDefinition,
|
|
38
|
+
writeFileDefinition,
|
|
39
|
+
editFileDefinition,
|
|
40
|
+
listDirDefinition,
|
|
41
|
+
createDirDefinition,
|
|
42
|
+
deleteFileDefinition,
|
|
43
|
+
copyFileDefinition,
|
|
44
|
+
moveFileDefinition,
|
|
45
|
+
fileInfoDefinition,
|
|
46
|
+
globSearchDefinition,
|
|
47
|
+
grepSearchDefinition,
|
|
48
|
+
treeDefinition,
|
|
49
|
+
// Web
|
|
50
|
+
webSearchDefinition,
|
|
51
|
+
webFetchDefinition,
|
|
82
52
|
];
|
|
83
|
-
const VALID_TOOL_NAMES = new Set(
|
|
53
|
+
const VALID_TOOL_NAMES = new Set(ALL_DEFINITIONS.map(d => d.function.name));
|
|
84
54
|
/**
|
|
85
|
-
* Реестр инструментов —
|
|
86
|
-
*
|
|
55
|
+
* Реестр инструментов — хранит определения и валидирует имена.
|
|
56
|
+
* Исполнение — через ToolExecutor.
|
|
87
57
|
*/
|
|
88
58
|
export class ToolRegistry {
|
|
89
|
-
cwd;
|
|
90
|
-
constructor(cwd = process.cwd()) {
|
|
91
|
-
this.cwd = cwd;
|
|
92
|
-
}
|
|
93
|
-
/**
|
|
94
|
-
* Исполняет tool call: определяет тип инструмента и вызывает handler.
|
|
95
|
-
* После успешной модификации файла уведомляет indexer и инвалидирует кэш.
|
|
96
|
-
*/
|
|
97
|
-
async execute(toolCall) {
|
|
98
|
-
const start = performance.now();
|
|
99
|
-
const preview = JSON.stringify(toolCall.arguments).slice(0, 120);
|
|
100
|
-
const fsEntry = FS_HANDLERS.get(toolCall.name);
|
|
101
|
-
if (fsEntry) {
|
|
102
|
-
let result;
|
|
103
|
-
try {
|
|
104
|
-
result = fsEntry.handler(toolCall.arguments, this.cwd);
|
|
105
|
-
}
|
|
106
|
-
catch (e) {
|
|
107
|
-
result = { stdout: '', stderr: `Tool error: ${e.message}`, exitCode: 1, truncated: false };
|
|
108
|
-
}
|
|
109
|
-
if (result.exitCode === 0 && MODIFYING_TOOLS.has(toolCall.name)) {
|
|
110
|
-
const paths = getChangedFilePaths(toolCall.name, toolCall.arguments);
|
|
111
|
-
for (const p of paths)
|
|
112
|
-
notifyFileChanged(p);
|
|
113
|
-
invalidateSystemPromptCache();
|
|
114
|
-
}
|
|
115
|
-
const elapsed = (performance.now() - start).toFixed(1);
|
|
116
|
-
logToolCall(toolCall.name, preview, `${result.stdout.length} bytes, ${elapsed}s`);
|
|
117
|
-
return result;
|
|
118
|
-
}
|
|
119
|
-
if (toolCall.name === 'bash') {
|
|
120
|
-
const cmd = String(toolCall.arguments.cmd ?? '');
|
|
121
|
-
const timeout = Number(toolCall.arguments.timeout ?? 120);
|
|
122
|
-
const result = await executeBash(cmd, timeout);
|
|
123
|
-
const elapsed = (performance.now() - start).toFixed(1);
|
|
124
|
-
logToolCall(toolCall.name, preview, `exit:${result.exitCode} ${result.stdout.length} bytes, ${elapsed}s`);
|
|
125
|
-
return result;
|
|
126
|
-
}
|
|
127
|
-
const webEntry = WEB_TOOLS.get(toolCall.name);
|
|
128
|
-
if (webEntry) {
|
|
129
|
-
try {
|
|
130
|
-
const result = await webEntry.handler(toolCall.arguments);
|
|
131
|
-
const elapsed = (performance.now() - start).toFixed(1);
|
|
132
|
-
logToolCall(toolCall.name, preview, `${result.stdout.length} bytes, ${elapsed}s`);
|
|
133
|
-
return result;
|
|
134
|
-
}
|
|
135
|
-
catch (e) {
|
|
136
|
-
return { stdout: '', stderr: `Web tool error: ${e.message}`, exitCode: 1, truncated: false };
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
logToolCall(toolCall.name, preview, 'unknown tool');
|
|
140
|
-
return { stdout: '', stderr: `Unknown tool: ${toolCall.name}`, exitCode: 1, truncated: false };
|
|
141
|
-
}
|
|
142
59
|
/** Возвращает определения всех доступных инструментов для system prompt */
|
|
143
60
|
getDefinitions() {
|
|
144
|
-
|
|
145
|
-
...NATIVE_TOOL_DEFS,
|
|
146
|
-
{
|
|
147
|
-
type: 'function',
|
|
148
|
-
function: {
|
|
149
|
-
name: 'bash',
|
|
150
|
-
description: `Execute a shell command. Use for non-file operations (npm, git, etc).`,
|
|
151
|
-
parameters: {
|
|
152
|
-
type: 'object',
|
|
153
|
-
properties: {
|
|
154
|
-
cmd: { type: 'string', description: 'The command to execute' },
|
|
155
|
-
timeout: { type: 'number', description: 'Seconds before timeout (default 120, max 600)' },
|
|
156
|
-
},
|
|
157
|
-
required: ['cmd'],
|
|
158
|
-
},
|
|
159
|
-
},
|
|
160
|
-
},
|
|
161
|
-
];
|
|
162
|
-
for (const entry of FS_HANDLERS.values()) {
|
|
163
|
-
defs.push(entry.def);
|
|
164
|
-
}
|
|
165
|
-
for (const entry of WEB_TOOLS.values()) {
|
|
166
|
-
defs.push(entry.def);
|
|
167
|
-
}
|
|
168
|
-
return defs;
|
|
61
|
+
return ALL_DEFINITIONS;
|
|
169
62
|
}
|
|
170
63
|
isToolCall(message) {
|
|
171
64
|
return message.role === 'assistant' && message.content === '';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"registry.js","sourceRoot":"","sources":["../../src/tools/registry.ts"],"names":[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AAW,EAAE,oEAAoE,EAAE;iBACrH;gBACD,QAAQ,EAAE,CAAC,MAAM,CAAC;aACnB;SACF;KACF;IACD,OAAO;IACP,cAAc;IACd,KAAK;IACL,kBAAkB;IAClB,mBAAmB;IACnB,kBAAkB;IAClB,iBAAiB;IACjB,mBAAmB;IACnB,oBAAoB;IACpB,kBAAkB;IAClB,kBAAkB;IAClB,kBAAkB;IAClB,oBAAoB;IACpB,oBAAoB;IACpB,cAAc;IACd,MAAM;IACN,mBAAmB;IACnB,kBAAkB;CACnB,CAAC;AAEF,MAAM,gBAAgB,GAAG,IAAI,GAAG,CAAC,eAAe,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC;AAE5E;;;GAGG;AACH,MAAM,OAAO,YAAY;IACvB,2EAA2E;IAC3E,cAAc;QACZ,OAAO,eAAe,CAAC;IACzB,CAAC;IAED,UAAU,CAAC,OAAoB;QAC7B,OAAO,OAAO,CAAC,IAAI,KAAK,WAAW,IAAI,OAAO,CAAC,OAAO,KAAK,EAAE,CAAC;IAChE,CAAC;IAED,WAAW,CAAC,IAAY;QACtB,OAAO,gBAAgB,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IACpC,CAAC;CACF"}
|
package/dist/tools/subagent.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { LLMProvider, ChatMessage } from '../llm/provider.js';
|
|
2
2
|
import { ToolRegistry } from './registry.js';
|
|
3
|
+
import type { ToolExecutor } from '../agent/tool-executor.js';
|
|
3
4
|
import type { OutputRenderer } from '../ui/renderer.js';
|
|
4
5
|
/**
|
|
5
6
|
* Изолированный цикл агента для субагентов.
|
|
@@ -78,7 +79,7 @@ export declare function doChat(provider: LLMProvider, messages: ChatMessage[], r
|
|
|
78
79
|
*
|
|
79
80
|
* @returns Результат: созданные файлы, ошибки, краткое описание, количество ходов
|
|
80
81
|
*/
|
|
81
|
-
export declare function runIsolatedLoop(provider: LLMProvider, registry: ToolRegistry, task: string, existingFiles: string, cwd: string, quiet: boolean, renderer: OutputRenderer): Promise<IsolatedLoopResult>;
|
|
82
|
+
export declare function runIsolatedLoop(provider: LLMProvider, registry: ToolRegistry, task: string, existingFiles: string, cwd: string, quiet: boolean, renderer: OutputRenderer, toolExecutor?: ToolExecutor, mode?: string): Promise<IsolatedLoopResult>;
|
|
82
83
|
import type { ToolDefinition } from './registry.js';
|
|
83
84
|
export declare const subagentDefinition: ToolDefinition;
|
|
84
85
|
//# sourceMappingURL=subagent.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"subagent.d.ts","sourceRoot":"","sources":["../../src/tools/subagent.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACnE,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"subagent.d.ts","sourceRoot":"","sources":["../../src/tools/subagent.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACnE,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAE7C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAI9D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAGxD;;;;;;;;;;;;;GAaG;AAIH,0DAA0D;AAC1D,MAAM,WAAW,kBAAkB;IACjC,YAAY,EAAE,MAAM,EAAE,CAAC;IACvB,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,MAAM,CAAC;CACf;AAID;;;;;;GAMG;AACH,wBAAgB,oBAAoB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAwDxD;AAID;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,EAAE,CA+C9D;AAED;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,GAAG,GAAG;IAAE,KAAK,EAAE,OAAO,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IAAC,GAAG,CAAC,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAA;CAAE,CAmD7G;AAID;;;;;;;;;;;GAWG;AACH,wBAAsB,MAAM,CAC1B,QAAQ,EAAE,WAAW,EACrB,QAAQ,EAAE,WAAW,EAAE,EACvB,QAAQ,EAAE,cAAc,EACxB,MAAM,CAAC,EAAE,WAAW,EACpB,OAAO,SAAI,EACX,YAAY,UAAQ,EACpB,MAAM,GAAE,MAAM,GAAG,UAAmB,GACnC,OAAO,CAAC;IAAE,QAAQ,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAA;CAAE,CAAC,CAwGlD;AAID;;;;;;;;;;;GAWG;AACH,wBAAsB,eAAe,CACnC,QAAQ,EAAE,WAAW,EACrB,QAAQ,EAAE,YAAY,EACtB,IAAI,EAAE,MAAM,EACZ,aAAa,EAAE,MAAM,EACrB,GAAG,EAAE,MAAM,EACX,KAAK,EAAE,OAAO,EACd,QAAQ,EAAE,cAAc,EACxB,YAAY,CAAC,EAAE,YAAY,EAC3B,IAAI,CAAC,EAAE,MAAM,GACZ,OAAO,CAAC,kBAAkB,CAAC,CA8J7B;AAID,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAEpD,eAAO,MAAM,kBAAkB,EAAE,cAchC,CAAC"}
|
package/dist/tools/subagent.js
CHANGED
|
@@ -304,7 +304,7 @@ export async function doChat(provider, messages, renderer, signal, retries = 1,
|
|
|
304
304
|
*
|
|
305
305
|
* @returns Результат: созданные файлы, ошибки, краткое описание, количество ходов
|
|
306
306
|
*/
|
|
307
|
-
export async function runIsolatedLoop(provider, registry, task, existingFiles, cwd, quiet, renderer) {
|
|
307
|
+
export async function runIsolatedLoop(provider, registry, task, existingFiles, cwd, quiet, renderer, toolExecutor, mode) {
|
|
308
308
|
const createdFiles = [];
|
|
309
309
|
const errors = [];
|
|
310
310
|
const startTime = performance.now();
|
|
@@ -317,7 +317,7 @@ export async function runIsolatedLoop(provider, registry, task, existingFiles, c
|
|
|
317
317
|
if (mergedContext) {
|
|
318
318
|
logDebug('SUBAGENT', `context (${mergedContext.split('\n').length} lines):\n${mergedContext}`);
|
|
319
319
|
}
|
|
320
|
-
const systemPrompt = buildSystemPrompt(undefined,
|
|
320
|
+
const systemPrompt = buildSystemPrompt(undefined, (mode || "base"));
|
|
321
321
|
const contextInfo = mergedContext
|
|
322
322
|
? `\n\nКонтекст проекта:\n${mergedContext}\nПосмотри package.json для списка пакетов. Используй read_file для чтения существующих файлов.`
|
|
323
323
|
: '';
|
|
@@ -387,7 +387,9 @@ export async function runIsolatedLoop(provider, registry, task, existingFiles, c
|
|
|
387
387
|
? String(parsed.arguments.path ?? '').slice(-60)
|
|
388
388
|
: JSON.stringify(parsed.arguments).slice(0, 80);
|
|
389
389
|
logToolCall(`sub:${parsed.name}`, preview);
|
|
390
|
-
const
|
|
390
|
+
const hookCmd = isBash ? String(cmd) : `${parsed.name} ${JSON.stringify(parsed.arguments)}`;
|
|
391
|
+
const execResult = toolExecutor ? await toolExecutor.execute({ id: toolId, name: parsed.name, arguments: parsed.arguments }, { cwd, quiet: false }, hookCmd) : null;
|
|
392
|
+
const result = execResult?.result ?? { stdout: '', stderr: 'ToolExecutor not available', exitCode: 1, truncated: false };
|
|
391
393
|
toolOutput = result.stdout || result.stderr || '(no output)';
|
|
392
394
|
toolExitCode = result.exitCode;
|
|
393
395
|
if (toolExitCode !== 0) {
|
|
@@ -416,7 +418,8 @@ export async function runIsolatedLoop(provider, registry, task, existingFiles, c
|
|
|
416
418
|
}
|
|
417
419
|
else {
|
|
418
420
|
logToolCall('sub:bash', String(cmd).slice(0, 80));
|
|
419
|
-
const
|
|
421
|
+
const bashExecResult = toolExecutor ? await toolExecutor.execute({ id: toolId, name: 'bash', arguments: { cmd, timeout: parsed.arguments?.timeout ?? 30 } }, { cwd, quiet: false }, String(cmd)) : null;
|
|
422
|
+
const result = bashExecResult?.result ?? { stdout: '', stderr: 'ToolExecutor not available', exitCode: 1, truncated: false };
|
|
420
423
|
toolOutput = result.stdout || result.stderr || '(no output)';
|
|
421
424
|
toolExitCode = result.exitCode;
|
|
422
425
|
if (toolExitCode !== 0) {
|