@kernel.chat/kbot 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/agent.d.ts +36 -0
- package/dist/agent.d.ts.map +1 -0
- package/dist/agent.js +211 -0
- package/dist/agent.js.map +1 -0
- package/dist/auth.d.ts +43 -0
- package/dist/auth.d.ts.map +1 -0
- package/dist/auth.js +108 -0
- package/dist/auth.js.map +1 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +240 -0
- package/dist/cli.js.map +1 -0
- package/dist/context.d.ts +15 -0
- package/dist/context.d.ts.map +1 -0
- package/dist/context.js +128 -0
- package/dist/context.js.map +1 -0
- package/dist/memory.d.ts +25 -0
- package/dist/memory.d.ts.map +1 -0
- package/dist/memory.js +75 -0
- package/dist/memory.js.map +1 -0
- package/dist/tools/bash.d.ts +2 -0
- package/dist/tools/bash.d.ts.map +1 -0
- package/dist/tools/bash.js +63 -0
- package/dist/tools/bash.js.map +1 -0
- package/dist/tools/browser.d.ts +2 -0
- package/dist/tools/browser.d.ts.map +1 -0
- package/dist/tools/browser.js +116 -0
- package/dist/tools/browser.js.map +1 -0
- package/dist/tools/computer.d.ts +2 -0
- package/dist/tools/computer.d.ts.map +1 -0
- package/dist/tools/computer.js +176 -0
- package/dist/tools/computer.js.map +1 -0
- package/dist/tools/files.d.ts +2 -0
- package/dist/tools/files.d.ts.map +1 -0
- package/dist/tools/files.js +147 -0
- package/dist/tools/files.js.map +1 -0
- package/dist/tools/git.d.ts +2 -0
- package/dist/tools/git.d.ts.map +1 -0
- package/dist/tools/git.js +102 -0
- package/dist/tools/git.js.map +1 -0
- package/dist/tools/index.d.ts +37 -0
- package/dist/tools/index.d.ts.map +1 -0
- package/dist/tools/index.js +57 -0
- package/dist/tools/index.js.map +1 -0
- package/dist/tools/search.d.ts +2 -0
- package/dist/tools/search.d.ts.map +1 -0
- package/dist/tools/search.js +46 -0
- package/dist/tools/search.js.map +1 -0
- package/dist/ui.d.ts +44 -0
- package/dist/ui.d.ts.map +1 -0
- package/dist/ui.js +242 -0
- package/dist/ui.js.map +1 -0
- package/install.sh +76 -0
- package/package.json +38 -0
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
// K:BOT Browser Tool — Playwright-based web browsing
|
|
2
|
+
// Requires: npx playwright install (run once)
|
|
3
|
+
// Available at Growth tier and above
|
|
4
|
+
import { registerTool } from './index.js';
|
|
5
|
+
// Lazy-load playwright to avoid requiring it for non-browser users
|
|
6
|
+
let browserInstance = null;
|
|
7
|
+
let pageInstance = null;
|
|
8
|
+
async function getPage() {
|
|
9
|
+
if (pageInstance)
|
|
10
|
+
return pageInstance;
|
|
11
|
+
try {
|
|
12
|
+
const { chromium } = await import('playwright');
|
|
13
|
+
browserInstance = await chromium.launch({ headless: true });
|
|
14
|
+
const context = await browserInstance.newContext({
|
|
15
|
+
viewport: { width: 1280, height: 720 },
|
|
16
|
+
userAgent: 'K:BOT/1.0 (Kernel Terminal Agent)',
|
|
17
|
+
});
|
|
18
|
+
pageInstance = await context.newPage();
|
|
19
|
+
return pageInstance;
|
|
20
|
+
}
|
|
21
|
+
catch {
|
|
22
|
+
throw new Error('Playwright not installed. Run: npx playwright install chromium');
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
async function closeBrowser() {
|
|
26
|
+
if (browserInstance) {
|
|
27
|
+
await browserInstance.close();
|
|
28
|
+
browserInstance = null;
|
|
29
|
+
pageInstance = null;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
export function registerBrowserTools() {
|
|
33
|
+
registerTool({
|
|
34
|
+
name: 'browser_navigate',
|
|
35
|
+
description: 'Navigate to a URL in a headless browser. Returns the page title and text content.',
|
|
36
|
+
parameters: {
|
|
37
|
+
url: { type: 'string', description: 'URL to navigate to', required: true },
|
|
38
|
+
},
|
|
39
|
+
tier: 'growth',
|
|
40
|
+
async execute(args) {
|
|
41
|
+
const url = String(args.url);
|
|
42
|
+
const page = await getPage();
|
|
43
|
+
await page.goto(url, { waitUntil: 'domcontentloaded', timeout: 30_000 });
|
|
44
|
+
const title = await page.title();
|
|
45
|
+
const text = await page.innerText('body').catch(() => '');
|
|
46
|
+
// Truncate to avoid massive responses
|
|
47
|
+
const truncated = text.length > 5000 ? text.slice(0, 5000) + '\n...(truncated)' : text;
|
|
48
|
+
return `Title: ${title}\nURL: ${page.url()}\n\n${truncated}`;
|
|
49
|
+
},
|
|
50
|
+
});
|
|
51
|
+
registerTool({
|
|
52
|
+
name: 'browser_snapshot',
|
|
53
|
+
description: 'Get the current page\'s accessibility tree (structured text representation).',
|
|
54
|
+
parameters: {},
|
|
55
|
+
tier: 'growth',
|
|
56
|
+
async execute() {
|
|
57
|
+
const page = await getPage();
|
|
58
|
+
const snapshot = await page.accessibility.snapshot();
|
|
59
|
+
return JSON.stringify(snapshot, null, 2);
|
|
60
|
+
},
|
|
61
|
+
});
|
|
62
|
+
registerTool({
|
|
63
|
+
name: 'browser_click',
|
|
64
|
+
description: 'Click an element on the page by CSS selector.',
|
|
65
|
+
parameters: {
|
|
66
|
+
selector: { type: 'string', description: 'CSS selector of element to click', required: true },
|
|
67
|
+
},
|
|
68
|
+
tier: 'growth',
|
|
69
|
+
async execute(args) {
|
|
70
|
+
const page = await getPage();
|
|
71
|
+
await page.click(String(args.selector), { timeout: 10_000 });
|
|
72
|
+
return `Clicked: ${args.selector}`;
|
|
73
|
+
},
|
|
74
|
+
});
|
|
75
|
+
registerTool({
|
|
76
|
+
name: 'browser_type',
|
|
77
|
+
description: 'Type text into a form field identified by CSS selector.',
|
|
78
|
+
parameters: {
|
|
79
|
+
selector: { type: 'string', description: 'CSS selector of input element', required: true },
|
|
80
|
+
text: { type: 'string', description: 'Text to type', required: true },
|
|
81
|
+
},
|
|
82
|
+
tier: 'growth',
|
|
83
|
+
async execute(args) {
|
|
84
|
+
const page = await getPage();
|
|
85
|
+
await page.fill(String(args.selector), String(args.text));
|
|
86
|
+
return `Typed into ${args.selector}`;
|
|
87
|
+
},
|
|
88
|
+
});
|
|
89
|
+
registerTool({
|
|
90
|
+
name: 'browser_screenshot',
|
|
91
|
+
description: 'Take a screenshot of the current page. Returns base64-encoded PNG.',
|
|
92
|
+
parameters: {
|
|
93
|
+
fullPage: { type: 'boolean', description: 'Capture full page (default: false)' },
|
|
94
|
+
},
|
|
95
|
+
tier: 'growth',
|
|
96
|
+
async execute(args) {
|
|
97
|
+
const page = await getPage();
|
|
98
|
+
const buffer = await page.screenshot({
|
|
99
|
+
fullPage: args.fullPage === true,
|
|
100
|
+
type: 'png',
|
|
101
|
+
});
|
|
102
|
+
return `Screenshot captured (${buffer.length} bytes, base64):\n${buffer.toString('base64').slice(0, 200)}...`;
|
|
103
|
+
},
|
|
104
|
+
});
|
|
105
|
+
registerTool({
|
|
106
|
+
name: 'browser_close',
|
|
107
|
+
description: 'Close the browser instance.',
|
|
108
|
+
parameters: {},
|
|
109
|
+
tier: 'growth',
|
|
110
|
+
async execute() {
|
|
111
|
+
await closeBrowser();
|
|
112
|
+
return 'Browser closed';
|
|
113
|
+
},
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
//# sourceMappingURL=browser.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"browser.js","sourceRoot":"","sources":["../../src/tools/browser.ts"],"names":[],"mappings":"AAAA,qDAAqD;AACrD,8CAA8C;AAC9C,qCAAqC;AAErC,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAA;AAEzC,mEAAmE;AACnE,IAAI,eAAe,GAAQ,IAAI,CAAA;AAC/B,IAAI,YAAY,GAAQ,IAAI,CAAA;AAE5B,KAAK,UAAU,OAAO;IACpB,IAAI,YAAY;QAAE,OAAO,YAAY,CAAA;IAErC,IAAI,CAAC;QACH,MAAM,EAAE,QAAQ,EAAE,GAAG,MAAM,MAAM,CAAC,YAAY,CAAC,CAAA;QAC/C,eAAe,GAAG,MAAM,QAAQ,CAAC,MAAM,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,EAAE,6BAA6B;QAC1C,UAAU,EAAE,EAAE;QACd,IAAI,EAAE,QAAQ;QACd,KAAK,CAAC,OAAO;YACX,MAAM,YAAY,EAAE,CAAA;YACpB,OAAO,gBAAgB,CAAA;QACzB,CAAC;KACF,CAAC,CAAA;AACJ,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"computer.d.ts","sourceRoot":"","sources":["../../src/tools/computer.ts"],"names":[],"mappings":"AAYA,wBAAgB,qBAAqB,IAAI,IAAI,CA2J5C"}
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
// K:BOT Computer Use Tool — Screenshot, click, type on the desktop
|
|
2
|
+
// Enterprise tier only. Requires explicit opt-in via --computer-use flag.
|
|
3
|
+
// Uses native OS commands (screencapture on macOS, etc.)
|
|
4
|
+
import { execSync } from 'node:child_process';
|
|
5
|
+
import { tmpdir } from 'node:os';
|
|
6
|
+
import { join } from 'node:path';
|
|
7
|
+
import { readFileSync, unlinkSync } from 'node:fs';
|
|
8
|
+
import { registerTool } from './index.js';
|
|
9
|
+
const platform = process.platform;
|
|
10
|
+
export function registerComputerTools() {
|
|
11
|
+
registerTool({
|
|
12
|
+
name: 'screenshot',
|
|
13
|
+
description: 'Capture a screenshot of the entire screen. Returns base64-encoded PNG. Requires --computer-use flag.',
|
|
14
|
+
parameters: {},
|
|
15
|
+
tier: 'enterprise',
|
|
16
|
+
async execute() {
|
|
17
|
+
const tmpPath = join(tmpdir(), `kbot-screenshot-${Date.now()}.png`);
|
|
18
|
+
try {
|
|
19
|
+
if (platform === 'darwin') {
|
|
20
|
+
execSync(`screencapture -x ${tmpPath}`, { timeout: 10_000 });
|
|
21
|
+
}
|
|
22
|
+
else if (platform === 'linux') {
|
|
23
|
+
// Try various screenshot tools
|
|
24
|
+
try {
|
|
25
|
+
execSync(`import -window root ${tmpPath}`, { timeout: 10_000 });
|
|
26
|
+
}
|
|
27
|
+
catch {
|
|
28
|
+
execSync(`gnome-screenshot -f ${tmpPath}`, { timeout: 10_000 });
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
return 'Error: Computer use not supported on this platform';
|
|
33
|
+
}
|
|
34
|
+
const buffer = readFileSync(tmpPath);
|
|
35
|
+
unlinkSync(tmpPath);
|
|
36
|
+
return `Screenshot captured (${buffer.length} bytes). Base64 preview: ${buffer.toString('base64').slice(0, 100)}...`;
|
|
37
|
+
}
|
|
38
|
+
catch (err) {
|
|
39
|
+
return `Screenshot failed: ${err instanceof Error ? err.message : String(err)}`;
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
});
|
|
43
|
+
registerTool({
|
|
44
|
+
name: 'mouse_click',
|
|
45
|
+
description: 'Click at specific screen coordinates. Requires --computer-use flag.',
|
|
46
|
+
parameters: {
|
|
47
|
+
x: { type: 'number', description: 'X coordinate', required: true },
|
|
48
|
+
y: { type: 'number', description: 'Y coordinate', required: true },
|
|
49
|
+
button: { type: 'string', description: 'Mouse button: left, right, middle (default: left)' },
|
|
50
|
+
},
|
|
51
|
+
tier: 'enterprise',
|
|
52
|
+
async execute(args) {
|
|
53
|
+
const x = Number(args.x);
|
|
54
|
+
const y = Number(args.y);
|
|
55
|
+
const button = args.button === 'right' ? 2 : 1;
|
|
56
|
+
if (platform === 'darwin') {
|
|
57
|
+
// Use AppleScript for mouse control on macOS
|
|
58
|
+
const script = button === 1
|
|
59
|
+
? `tell application "System Events" to click at {${x}, ${y}}`
|
|
60
|
+
: `tell application "System Events" to click at {${x}, ${y}} using control down`;
|
|
61
|
+
try {
|
|
62
|
+
execSync(`osascript -e '${script}'`, { timeout: 5_000 });
|
|
63
|
+
return `Clicked at (${x}, ${y})`;
|
|
64
|
+
}
|
|
65
|
+
catch {
|
|
66
|
+
// Fallback to cliclick if available
|
|
67
|
+
try {
|
|
68
|
+
execSync(`cliclick c:${x},${y}`, { timeout: 5_000 });
|
|
69
|
+
return `Clicked at (${x}, ${y})`;
|
|
70
|
+
}
|
|
71
|
+
catch {
|
|
72
|
+
return 'Error: Mouse click requires cliclick (brew install cliclick) or accessibility permissions';
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
else if (platform === 'linux') {
|
|
77
|
+
try {
|
|
78
|
+
execSync(`xdotool mousemove ${x} ${y} click ${button}`, { timeout: 5_000 });
|
|
79
|
+
return `Clicked at (${x}, ${y})`;
|
|
80
|
+
}
|
|
81
|
+
catch {
|
|
82
|
+
return 'Error: Mouse click requires xdotool (apt install xdotool)';
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
return 'Error: Computer use not supported on this platform';
|
|
86
|
+
},
|
|
87
|
+
});
|
|
88
|
+
registerTool({
|
|
89
|
+
name: 'keyboard_type',
|
|
90
|
+
description: 'Type text using the keyboard. Requires --computer-use flag.',
|
|
91
|
+
parameters: {
|
|
92
|
+
text: { type: 'string', description: 'Text to type', required: true },
|
|
93
|
+
},
|
|
94
|
+
tier: 'enterprise',
|
|
95
|
+
async execute(args) {
|
|
96
|
+
const text = String(args.text);
|
|
97
|
+
if (platform === 'darwin') {
|
|
98
|
+
// Escape for AppleScript
|
|
99
|
+
const escaped = text.replace(/"/g, '\\"').replace(/'/g, "\\'");
|
|
100
|
+
try {
|
|
101
|
+
execSync(`osascript -e 'tell application "System Events" to keystroke "${escaped}"'`, { timeout: 10_000 });
|
|
102
|
+
return `Typed: ${text.slice(0, 50)}${text.length > 50 ? '...' : ''}`;
|
|
103
|
+
}
|
|
104
|
+
catch {
|
|
105
|
+
return 'Error: Typing requires accessibility permissions';
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
else if (platform === 'linux') {
|
|
109
|
+
try {
|
|
110
|
+
execSync(`xdotool type -- "${text.replace(/"/g, '\\"')}"`, { timeout: 10_000 });
|
|
111
|
+
return `Typed: ${text.slice(0, 50)}${text.length > 50 ? '...' : ''}`;
|
|
112
|
+
}
|
|
113
|
+
catch {
|
|
114
|
+
return 'Error: Typing requires xdotool';
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
return 'Error: Computer use not supported on this platform';
|
|
118
|
+
},
|
|
119
|
+
});
|
|
120
|
+
registerTool({
|
|
121
|
+
name: 'keyboard_key',
|
|
122
|
+
description: 'Press a specific key or key combination. Requires --computer-use flag.',
|
|
123
|
+
parameters: {
|
|
124
|
+
key: { type: 'string', description: 'Key name: enter, tab, escape, space, backspace, cmd+c, ctrl+v, etc.', required: true },
|
|
125
|
+
},
|
|
126
|
+
tier: 'enterprise',
|
|
127
|
+
async execute(args) {
|
|
128
|
+
const key = String(args.key).toLowerCase();
|
|
129
|
+
if (platform === 'darwin') {
|
|
130
|
+
// Map common keys to AppleScript key codes
|
|
131
|
+
const keyMap = {
|
|
132
|
+
enter: 'return', tab: 'tab', escape: 'escape 53',
|
|
133
|
+
space: 'space', backspace: 'delete', delete: 'forward delete',
|
|
134
|
+
};
|
|
135
|
+
const mapped = keyMap[key] || key;
|
|
136
|
+
try {
|
|
137
|
+
if (key.includes('+')) {
|
|
138
|
+
// Key combination: cmd+c → keystroke "c" using command down
|
|
139
|
+
const parts = key.split('+');
|
|
140
|
+
const mainKey = parts.pop();
|
|
141
|
+
const modifiers = parts.map(m => {
|
|
142
|
+
if (m === 'cmd' || m === 'command')
|
|
143
|
+
return 'command down';
|
|
144
|
+
if (m === 'ctrl' || m === 'control')
|
|
145
|
+
return 'control down';
|
|
146
|
+
if (m === 'alt' || m === 'option')
|
|
147
|
+
return 'option down';
|
|
148
|
+
if (m === 'shift')
|
|
149
|
+
return 'shift down';
|
|
150
|
+
return '';
|
|
151
|
+
}).filter(Boolean).join(', ');
|
|
152
|
+
execSync(`osascript -e 'tell application "System Events" to keystroke "${mainKey}" using {${modifiers}}'`, { timeout: 5_000 });
|
|
153
|
+
}
|
|
154
|
+
else {
|
|
155
|
+
execSync(`osascript -e 'tell application "System Events" to key code ${mapped}'`, { timeout: 5_000 });
|
|
156
|
+
}
|
|
157
|
+
return `Pressed: ${key}`;
|
|
158
|
+
}
|
|
159
|
+
catch {
|
|
160
|
+
return 'Error: Key press requires accessibility permissions';
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
else if (platform === 'linux') {
|
|
164
|
+
try {
|
|
165
|
+
execSync(`xdotool key ${key.replace('+', '+')}`, { timeout: 5_000 });
|
|
166
|
+
return `Pressed: ${key}`;
|
|
167
|
+
}
|
|
168
|
+
catch {
|
|
169
|
+
return 'Error: Key press requires xdotool';
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
return 'Error: Computer use not supported on this platform';
|
|
173
|
+
},
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
//# sourceMappingURL=computer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"computer.js","sourceRoot":"","sources":["../../src/tools/computer.ts"],"names":[],"mappings":"AAAA,mEAAmE;AACnE,0EAA0E;AAC1E,yDAAyD;AAEzD,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAA;AAC7C,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAA;AAChC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAChC,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;AAClD,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAA;AAEzC,MAAM,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAA;AAEjC,MAAM,UAAU,qBAAqB;IACnC,YAAY,CAAC;QACX,IAAI,EAAE,YAAY;QAClB,WAAW,EAAE,sGAAsG;QACnH,UAAU,EAAE,EAAE;QACd,IAAI,EAAE,YAAY;QAClB,KAAK,CAAC,OAAO;YACX,MAAM,OAAO,GAAG,IAAI,CAAC,MAAM,EAAE,EAAE,mBAAmB,IAAI,CAAC,GAAG,EAAE,MAAM,CAAC,CAAA;YAEnE,IAAI,CAAC;gBACH,IAAI,QAAQ,KAAK,QAAQ,EAAE,CAAC;oBAC1B,QAAQ,CAAC,oB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,wBAAgB,iBAAiB,IAAI,IAAI,CAsJxC"}
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
// K:BOT File Tools — Read, write, edit, glob, grep
|
|
2
|
+
// All operations are local — zero API calls.
|
|
3
|
+
import { readFileSync, writeFileSync, existsSync, statSync } from 'node:fs';
|
|
4
|
+
import { execSync } from 'node:child_process';
|
|
5
|
+
import { registerTool } from './index.js';
|
|
6
|
+
export function registerFileTools() {
|
|
7
|
+
registerTool({
|
|
8
|
+
name: 'read_file',
|
|
9
|
+
description: 'Read the contents of a file. Returns the file content with line numbers.',
|
|
10
|
+
parameters: {
|
|
11
|
+
path: { type: 'string', description: 'File path (absolute or relative to cwd)', required: true },
|
|
12
|
+
offset: { type: 'number', description: 'Line number to start from (1-based)' },
|
|
13
|
+
limit: { type: 'number', description: 'Number of lines to read' },
|
|
14
|
+
},
|
|
15
|
+
tier: 'free',
|
|
16
|
+
async execute(args) {
|
|
17
|
+
const path = String(args.path);
|
|
18
|
+
if (!existsSync(path))
|
|
19
|
+
return `Error: File not found: ${path}`;
|
|
20
|
+
const stat = statSync(path);
|
|
21
|
+
if (stat.isDirectory())
|
|
22
|
+
return `Error: ${path} is a directory, not a file`;
|
|
23
|
+
if (stat.size > 5 * 1024 * 1024)
|
|
24
|
+
return `Error: File too large (${(stat.size / 1024 / 1024).toFixed(1)}MB). Max 5MB.`;
|
|
25
|
+
const content = readFileSync(path, 'utf-8');
|
|
26
|
+
const lines = content.split('\n');
|
|
27
|
+
const offset = typeof args.offset === 'number' ? Math.max(0, args.offset - 1) : 0;
|
|
28
|
+
const limit = typeof args.limit === 'number' ? args.limit : lines.length;
|
|
29
|
+
const sliced = lines.slice(offset, offset + limit);
|
|
30
|
+
return sliced.map((line, i) => `${String(offset + i + 1).padStart(6)} │ ${line}`).join('\n');
|
|
31
|
+
},
|
|
32
|
+
});
|
|
33
|
+
registerTool({
|
|
34
|
+
name: 'write_file',
|
|
35
|
+
description: 'Write content to a file. Creates the file if it does not exist, overwrites if it does.',
|
|
36
|
+
parameters: {
|
|
37
|
+
path: { type: 'string', description: 'File path', required: true },
|
|
38
|
+
content: { type: 'string', description: 'Content to write', required: true },
|
|
39
|
+
},
|
|
40
|
+
tier: 'free',
|
|
41
|
+
async execute(args) {
|
|
42
|
+
const path = String(args.path);
|
|
43
|
+
const content = String(args.content);
|
|
44
|
+
writeFileSync(path, content);
|
|
45
|
+
return `Written ${content.length} bytes to ${path}`;
|
|
46
|
+
},
|
|
47
|
+
});
|
|
48
|
+
registerTool({
|
|
49
|
+
name: 'edit_file',
|
|
50
|
+
description: 'Find and replace text in a file. The old_string must be unique in the file.',
|
|
51
|
+
parameters: {
|
|
52
|
+
path: { type: 'string', description: 'File path', required: true },
|
|
53
|
+
old_string: { type: 'string', description: 'Text to find', required: true },
|
|
54
|
+
new_string: { type: 'string', description: 'Replacement text', required: true },
|
|
55
|
+
},
|
|
56
|
+
tier: 'free',
|
|
57
|
+
async execute(args) {
|
|
58
|
+
const path = String(args.path);
|
|
59
|
+
if (!existsSync(path))
|
|
60
|
+
return `Error: File not found: ${path}`;
|
|
61
|
+
const content = readFileSync(path, 'utf-8');
|
|
62
|
+
const old_string = String(args.old_string);
|
|
63
|
+
const new_string = String(args.new_string);
|
|
64
|
+
const count = content.split(old_string).length - 1;
|
|
65
|
+
if (count === 0)
|
|
66
|
+
return `Error: old_string not found in ${path}`;
|
|
67
|
+
if (count > 1)
|
|
68
|
+
return `Error: old_string found ${count} times — must be unique. Add more context.`;
|
|
69
|
+
const updated = content.replace(old_string, new_string);
|
|
70
|
+
writeFileSync(path, updated);
|
|
71
|
+
return `Edited ${path}: replaced 1 occurrence`;
|
|
72
|
+
},
|
|
73
|
+
});
|
|
74
|
+
registerTool({
|
|
75
|
+
name: 'glob',
|
|
76
|
+
description: 'Find files matching a glob pattern. Returns file paths.',
|
|
77
|
+
parameters: {
|
|
78
|
+
pattern: { type: 'string', description: 'Glob pattern (e.g., "**/*.ts", "src/**/*.tsx")', required: true },
|
|
79
|
+
path: { type: 'string', description: 'Directory to search in (defaults to cwd)' },
|
|
80
|
+
},
|
|
81
|
+
tier: 'free',
|
|
82
|
+
async execute(args) {
|
|
83
|
+
const pattern = String(args.pattern);
|
|
84
|
+
const cwd = args.path ? String(args.path) : process.cwd();
|
|
85
|
+
try {
|
|
86
|
+
// Use find for simple patterns, or shell glob expansion
|
|
87
|
+
const result = execSync(`find ${cwd} -path '*/${pattern}' -type f 2>/dev/null | head -50`, { encoding: 'utf-8', timeout: 10000 }).trim();
|
|
88
|
+
if (!result) {
|
|
89
|
+
// Fallback to using shell expansion
|
|
90
|
+
const result2 = execSync(`ls -1 ${cwd}/${pattern} 2>/dev/null | head -50`, { encoding: 'utf-8', timeout: 10000 }).trim();
|
|
91
|
+
return result2 || 'No files found';
|
|
92
|
+
}
|
|
93
|
+
return result;
|
|
94
|
+
}
|
|
95
|
+
catch {
|
|
96
|
+
return 'No files found matching pattern';
|
|
97
|
+
}
|
|
98
|
+
},
|
|
99
|
+
});
|
|
100
|
+
registerTool({
|
|
101
|
+
name: 'grep',
|
|
102
|
+
description: 'Search file contents for a regex pattern. Returns matching lines with file paths and line numbers.',
|
|
103
|
+
parameters: {
|
|
104
|
+
pattern: { type: 'string', description: 'Regex pattern to search for', required: true },
|
|
105
|
+
path: { type: 'string', description: 'File or directory to search in (defaults to cwd)' },
|
|
106
|
+
type: { type: 'string', description: 'File type filter (e.g., "ts", "py", "js")' },
|
|
107
|
+
},
|
|
108
|
+
tier: 'free',
|
|
109
|
+
async execute(args) {
|
|
110
|
+
const pattern = String(args.pattern);
|
|
111
|
+
const searchPath = args.path ? String(args.path) : '.';
|
|
112
|
+
const typeFlag = args.type ? `--type ${args.type}` : '';
|
|
113
|
+
try {
|
|
114
|
+
// Prefer ripgrep, fall back to grep
|
|
115
|
+
const cmd = existsSync('/usr/bin/rg') || existsSync('/usr/local/bin/rg') || existsSync('/opt/homebrew/bin/rg')
|
|
116
|
+
? `rg -n --max-count 30 ${typeFlag} '${pattern.replace(/'/g, "\\'")}' ${searchPath} 2>/dev/null`
|
|
117
|
+
: `grep -rn --include='*.${args.type || '*'}' '${pattern.replace(/'/g, "\\'")}' ${searchPath} 2>/dev/null | head -30`;
|
|
118
|
+
const result = execSync(cmd, { encoding: 'utf-8', timeout: 15000 }).trim();
|
|
119
|
+
return result || 'No matches found';
|
|
120
|
+
}
|
|
121
|
+
catch {
|
|
122
|
+
return 'No matches found';
|
|
123
|
+
}
|
|
124
|
+
},
|
|
125
|
+
});
|
|
126
|
+
registerTool({
|
|
127
|
+
name: 'list_directory',
|
|
128
|
+
description: 'List files and directories in a path. Shows file sizes and types.',
|
|
129
|
+
parameters: {
|
|
130
|
+
path: { type: 'string', description: 'Directory path (defaults to cwd)' },
|
|
131
|
+
},
|
|
132
|
+
tier: 'free',
|
|
133
|
+
async execute(args) {
|
|
134
|
+
const dir = args.path ? String(args.path) : '.';
|
|
135
|
+
try {
|
|
136
|
+
const result = execSync(`ls -la ${dir} 2>/dev/null | head -50`, {
|
|
137
|
+
encoding: 'utf-8', timeout: 5000,
|
|
138
|
+
}).trim();
|
|
139
|
+
return result || 'Empty directory';
|
|
140
|
+
}
|
|
141
|
+
catch {
|
|
142
|
+
return `Error: Cannot list directory: ${dir}`;
|
|
143
|
+
}
|
|
144
|
+
},
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
//# sourceMappingURL=files.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"files.js","sourceRoot":"","sources":["../../src/tools/files.ts"],"names":[],"mappings":"AAAA,mDAAmD;AACnD,6CAA6C;AAE7C,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AAC3E,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAA;AAC7C,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAA;AAEzC,MAAM,UAAU,iBAAiB;IAC/B,YAAY,CAAC;QACX,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,EAAE;SAC1E;QACD,IAAI,EAAE,MAAM;QACZ,KAAK,CAAC,OAAO,CAAC,IAAI;YAChB,MAAM,GAAG,GAAG,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,GAAG,CAAA;YAC/C,IAAI,CAAC;gBACH,MAAM,MAAM,GAAG,QAAQ,CAAC,UAAU,GAAG,yBAAyB,EAAE;oBAC9D,QAAQ,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI;iBACjC,CAAC,CAAC,IAAI,EAAE,CAAA;gBACT,OAAO,MAAM,IAAI,iBAAiB,CAAA;YACpC,CAAC;YAAC,MAAM,CAAC;gBACP,OAAO,iCAAiC,GAAG,EAAE,CAAA;YAC/C,CAAC;QACH,CAAC;KACF,CAAC,CAAA;AACJ,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"git.d.ts","sourceRoot":"","sources":["../../src/tools/git.ts"],"names":[],"mappings":"AAmBA,wBAAgB,gBAAgB,IAAI,IAAI,CA0FvC"}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
// K:BOT Git Tools — Git operations executed locally
|
|
2
|
+
// Zero API calls. All operations happen on the local repo.
|
|
3
|
+
import { execSync } from 'node:child_process';
|
|
4
|
+
import { registerTool } from './index.js';
|
|
5
|
+
function git(command, timeout = 30_000) {
|
|
6
|
+
try {
|
|
7
|
+
return execSync(`git ${command}`, {
|
|
8
|
+
encoding: 'utf-8',
|
|
9
|
+
timeout,
|
|
10
|
+
maxBuffer: 5 * 1024 * 1024,
|
|
11
|
+
}).trim();
|
|
12
|
+
}
|
|
13
|
+
catch (err) {
|
|
14
|
+
const e = err;
|
|
15
|
+
throw new Error(e.stderr?.trim() || e.message || 'Git command failed');
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
export function registerGitTools() {
|
|
19
|
+
registerTool({
|
|
20
|
+
name: 'git_status',
|
|
21
|
+
description: 'Show the working tree status — modified, staged, and untracked files.',
|
|
22
|
+
parameters: {},
|
|
23
|
+
tier: 'free',
|
|
24
|
+
async execute() {
|
|
25
|
+
return git('status --short');
|
|
26
|
+
},
|
|
27
|
+
});
|
|
28
|
+
registerTool({
|
|
29
|
+
name: 'git_diff',
|
|
30
|
+
description: 'Show changes in the working directory (unstaged and staged).',
|
|
31
|
+
parameters: {
|
|
32
|
+
staged: { type: 'boolean', description: 'Show only staged changes' },
|
|
33
|
+
path: { type: 'string', description: 'Limit diff to a specific file path' },
|
|
34
|
+
},
|
|
35
|
+
tier: 'free',
|
|
36
|
+
async execute(args) {
|
|
37
|
+
const staged = args.staged ? '--cached' : '';
|
|
38
|
+
const path = args.path ? `-- ${args.path}` : '';
|
|
39
|
+
return git(`diff ${staged} ${path}`.trim()) || 'No changes';
|
|
40
|
+
},
|
|
41
|
+
});
|
|
42
|
+
registerTool({
|
|
43
|
+
name: 'git_log',
|
|
44
|
+
description: 'Show recent commit history.',
|
|
45
|
+
parameters: {
|
|
46
|
+
count: { type: 'number', description: 'Number of commits to show (default: 10)' },
|
|
47
|
+
oneline: { type: 'boolean', description: 'One-line format (default: true)' },
|
|
48
|
+
},
|
|
49
|
+
tier: 'free',
|
|
50
|
+
async execute(args) {
|
|
51
|
+
const count = typeof args.count === 'number' ? args.count : 10;
|
|
52
|
+
const format = args.oneline !== false ? '--oneline' : '';
|
|
53
|
+
return git(`log -${count} ${format}`.trim());
|
|
54
|
+
},
|
|
55
|
+
});
|
|
56
|
+
registerTool({
|
|
57
|
+
name: 'git_commit',
|
|
58
|
+
description: 'Create a git commit with the specified message. Stages specified files first.',
|
|
59
|
+
parameters: {
|
|
60
|
+
message: { type: 'string', description: 'Commit message', required: true },
|
|
61
|
+
files: { type: 'array', description: 'Files to stage before committing. If empty, commits already-staged files.' },
|
|
62
|
+
},
|
|
63
|
+
tier: 'starter',
|
|
64
|
+
async execute(args) {
|
|
65
|
+
const message = String(args.message);
|
|
66
|
+
const files = Array.isArray(args.files) ? args.files.map(String) : [];
|
|
67
|
+
if (files.length > 0) {
|
|
68
|
+
git(`add ${files.join(' ')}`);
|
|
69
|
+
}
|
|
70
|
+
return git(`commit -m "${message.replace(/"/g, '\\"')}"`);
|
|
71
|
+
},
|
|
72
|
+
});
|
|
73
|
+
registerTool({
|
|
74
|
+
name: 'git_branch',
|
|
75
|
+
description: 'Create or switch branches.',
|
|
76
|
+
parameters: {
|
|
77
|
+
name: { type: 'string', description: 'Branch name', required: true },
|
|
78
|
+
create: { type: 'boolean', description: 'Create a new branch (default: false)' },
|
|
79
|
+
},
|
|
80
|
+
tier: 'starter',
|
|
81
|
+
async execute(args) {
|
|
82
|
+
const name = String(args.name);
|
|
83
|
+
const create = args.create ? '-b' : '';
|
|
84
|
+
return git(`checkout ${create} ${name}`.trim());
|
|
85
|
+
},
|
|
86
|
+
});
|
|
87
|
+
registerTool({
|
|
88
|
+
name: 'git_push',
|
|
89
|
+
description: 'Push commits to the remote repository. Use with caution.',
|
|
90
|
+
parameters: {
|
|
91
|
+
remote: { type: 'string', description: 'Remote name (default: origin)' },
|
|
92
|
+
branch: { type: 'string', description: 'Branch name (default: current branch)' },
|
|
93
|
+
},
|
|
94
|
+
tier: 'starter',
|
|
95
|
+
async execute(args) {
|
|
96
|
+
const remote = args.remote ? String(args.remote) : 'origin';
|
|
97
|
+
const branch = args.branch ? String(args.branch) : '';
|
|
98
|
+
return git(`push ${remote} ${branch}`.trim(), 60_000);
|
|
99
|
+
},
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
//# sourceMappingURL=git.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"git.js","sourceRoot":"","sources":["../../src/tools/git.ts"],"names":[],"mappings":"AAAA,oDAAoD;AACpD,2DAA2D;AAE3D,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAA;AAC7C,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAA;AAEzC,SAAS,GAAG,CA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O,CAAC,IAAI;YAChB,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAA;YAC3D,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,EAAE,CAAA;YACrD,OAAO,GAAG,CAAC,QAAQ,MAAM,IAAI,MAAM,EAAE,CAAC,IAAI,EAAE,EAAE,MAAM,CAAC,CAAA;QACvD,CAAC;KACF,CAAC,CAAA;AACJ,CAAC"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
export interface ToolDefinition {
|
|
2
|
+
name: string;
|
|
3
|
+
description: string;
|
|
4
|
+
parameters: Record<string, {
|
|
5
|
+
type: string;
|
|
6
|
+
description: string;
|
|
7
|
+
required?: boolean;
|
|
8
|
+
default?: unknown;
|
|
9
|
+
}>;
|
|
10
|
+
execute: (args: Record<string, unknown>) => Promise<string>;
|
|
11
|
+
/** Tier required: 'free' | 'starter' | 'growth' | 'enterprise' */
|
|
12
|
+
tier: 'free' | 'starter' | 'growth' | 'enterprise';
|
|
13
|
+
}
|
|
14
|
+
export interface ToolCall {
|
|
15
|
+
id: string;
|
|
16
|
+
name: string;
|
|
17
|
+
arguments: Record<string, unknown>;
|
|
18
|
+
}
|
|
19
|
+
export interface ToolResult {
|
|
20
|
+
tool_call_id: string;
|
|
21
|
+
result: string;
|
|
22
|
+
error?: boolean;
|
|
23
|
+
}
|
|
24
|
+
export declare function registerTool(tool: ToolDefinition): void;
|
|
25
|
+
export declare function getTool(name: string): ToolDefinition | undefined;
|
|
26
|
+
export declare function getAllTools(): ToolDefinition[];
|
|
27
|
+
export declare function getToolsForTier(tier: string): ToolDefinition[];
|
|
28
|
+
/** Get tool definitions in Claude tool-use format for the API */
|
|
29
|
+
export declare function getToolDefinitionsForApi(tier: string): Array<{
|
|
30
|
+
name: string;
|
|
31
|
+
description: string;
|
|
32
|
+
}>;
|
|
33
|
+
/** Execute a tool call locally. Returns the result string. */
|
|
34
|
+
export declare function executeTool(call: ToolCall): Promise<ToolResult>;
|
|
35
|
+
/** Register all built-in tools. Call once at startup. */
|
|
36
|
+
export declare function registerAllTools(): Promise<void>;
|
|
37
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/tools/index.ts"],"names":[],"mappings":"AAIA,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,MAAM,CAAA;IACZ,WAAW,EAAE,MAAM,CAAA;IACnB,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE;QACzB,IAAI,EAAE,MAAM,CAAA;QACZ,WAAW,EAAE,MAAM,CAAA;QACnB,QAAQ,CAAC,EAAE,OAAO,CAAA;QAClB,OAAO,CAAC,EAAE,OAAO,CAAA;KAClB,CAAC,CAAA;IACF,OAAO,EAAE,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,OAAO,CAAC,MAAM,CAAC,CAAA;IAC3D,kEAAkE;IAClE,IAAI,EAAE,MAAM,GAAG,SAAS,GAAG,QAAQ,GAAG,YAAY,CAAA;CACnD;AAED,MAAM,WAAW,QAAQ;IACvB,EAAE,EAAE,MAAM,CAAA;IACV,IAAI,EAAE,MAAM,CAAA;IACZ,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;CACnC;AAED,MAAM,WAAW,UAAU;IACzB,YAAY,EAAE,MAAM,CAAA;IACpB,MAAM,EAAE,MAAM,CAAA;IACd,KAAK,CAAC,EAAE,OAAO,CAAA;CAChB;AAID,wBAAgB,YAAY,CAAC,IAAI,EAAE,cAAc,GAAG,IAAI,CAEvD;AAED,wBAAgB,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,cAAc,GAAG,SAAS,CAEhE;AA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