@projectservan8n/cnapse 0.2.0 → 0.4.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.
@@ -0,0 +1,140 @@
1
+ /**
2
+ * Shell command execution tools
3
+ */
4
+
5
+ import { exec } from 'child_process';
6
+ import { promisify } from 'util';
7
+ import { ToolResult, ok, err } from './index.js';
8
+
9
+ const execAsync = promisify(exec);
10
+
11
+ /**
12
+ * Run a shell command
13
+ */
14
+ export async function runCommand(cmd: string, timeout = 30000): Promise<ToolResult> {
15
+ try {
16
+ const isWindows = process.platform === 'win32';
17
+ const shell = isWindows ? 'cmd.exe' : '/bin/sh';
18
+ const shellArg = isWindows ? '/C' : '-c';
19
+
20
+ const { stdout, stderr } = await execAsync(cmd, {
21
+ shell,
22
+ timeout,
23
+ maxBuffer: 10 * 1024 * 1024, // 10MB
24
+ });
25
+
26
+ if (stderr && stderr.trim()) {
27
+ return ok(`${stdout}\n[stderr]: ${stderr}`);
28
+ }
29
+ return ok(stdout || '(no output)');
30
+ } catch (error: any) {
31
+ if (error.killed) {
32
+ return err(`Command timed out after ${timeout}ms`);
33
+ }
34
+ const stderr = error.stderr || '';
35
+ const stdout = error.stdout || '';
36
+ return {
37
+ success: false,
38
+ output: stdout,
39
+ error: `Exit code: ${error.code || -1}\n${stderr}`,
40
+ };
41
+ }
42
+ }
43
+
44
+ /**
45
+ * Get environment variable
46
+ */
47
+ export function getEnv(varName: string): ToolResult {
48
+ const value = process.env[varName];
49
+ if (value !== undefined) {
50
+ return ok(value);
51
+ }
52
+ return err(`Environment variable not set: ${varName}`);
53
+ }
54
+
55
+ /**
56
+ * Set environment variable (for current process)
57
+ */
58
+ export function setEnv(varName: string, value: string): ToolResult {
59
+ process.env[varName] = value;
60
+ return ok(`Set ${varName}=${value}`);
61
+ }
62
+
63
+ /**
64
+ * Get current working directory
65
+ */
66
+ export function getCwd(): ToolResult {
67
+ return ok(process.cwd());
68
+ }
69
+
70
+ /**
71
+ * Change current working directory
72
+ */
73
+ export function setCwd(path: string): ToolResult {
74
+ try {
75
+ process.chdir(path);
76
+ return ok(`Changed directory to: ${path}`);
77
+ } catch (error: any) {
78
+ return err(`Failed to change directory: ${error.message}`);
79
+ }
80
+ }
81
+
82
+ /**
83
+ * Shell tool definitions for agents
84
+ */
85
+ export const shellTools = [
86
+ {
87
+ name: 'run_command',
88
+ description: 'Execute shell command',
89
+ parameters: {
90
+ type: 'object',
91
+ properties: {
92
+ cmd: { type: 'string', description: 'Command to execute' },
93
+ timeout: { type: 'number', description: 'Timeout in ms (default 30000)' },
94
+ },
95
+ required: ['cmd'],
96
+ },
97
+ },
98
+ {
99
+ name: 'get_env',
100
+ description: 'Get environment variable',
101
+ parameters: {
102
+ type: 'object',
103
+ properties: {
104
+ var: { type: 'string', description: 'Variable name' },
105
+ },
106
+ required: ['var'],
107
+ },
108
+ },
109
+ {
110
+ name: 'set_env',
111
+ description: 'Set environment variable',
112
+ parameters: {
113
+ type: 'object',
114
+ properties: {
115
+ var: { type: 'string', description: 'Variable name' },
116
+ value: { type: 'string', description: 'Value to set' },
117
+ },
118
+ required: ['var', 'value'],
119
+ },
120
+ },
121
+ {
122
+ name: 'get_cwd',
123
+ description: 'Get current working directory',
124
+ parameters: {
125
+ type: 'object',
126
+ properties: {},
127
+ },
128
+ },
129
+ {
130
+ name: 'set_cwd',
131
+ description: 'Change working directory',
132
+ parameters: {
133
+ type: 'object',
134
+ properties: {
135
+ path: { type: 'string', description: 'Directory path' },
136
+ },
137
+ required: ['path'],
138
+ },
139
+ },
140
+ ];
@@ -0,0 +1,65 @@
1
+ /**
2
+ * Vision tools - Screenshot capture and AI description
3
+ */
4
+
5
+ import { describeScreen, captureScreenshot } from '../lib/vision.js';
6
+
7
+ export interface ScreenshotResult {
8
+ success: boolean;
9
+ screenshot?: string; // base64
10
+ error?: string;
11
+ }
12
+
13
+ export interface VisionResult {
14
+ success: boolean;
15
+ description?: string;
16
+ screenshot?: string; // base64
17
+ error?: string;
18
+ }
19
+
20
+ /**
21
+ * Take a screenshot and return as base64
22
+ */
23
+ export async function takeScreenshot(): Promise<ScreenshotResult> {
24
+ try {
25
+ const screenshot = await captureScreenshot();
26
+ if (!screenshot) {
27
+ return { success: false, error: 'Failed to capture screenshot' };
28
+ }
29
+ return { success: true, screenshot };
30
+ } catch (error) {
31
+ return {
32
+ success: false,
33
+ error: error instanceof Error ? error.message : 'Screenshot failed',
34
+ };
35
+ }
36
+ }
37
+
38
+ /**
39
+ * Capture screen and get AI description of what's visible
40
+ */
41
+ export async function describeCurrentScreen(): Promise<VisionResult> {
42
+ try {
43
+ const result = await describeScreen();
44
+ return {
45
+ success: true,
46
+ description: result.description,
47
+ screenshot: result.screenshot,
48
+ };
49
+ } catch (error) {
50
+ return {
51
+ success: false,
52
+ error: error instanceof Error ? error.message : 'Vision analysis failed',
53
+ };
54
+ }
55
+ }
56
+
57
+ /**
58
+ * Get all vision tools for the executor
59
+ */
60
+ export function getVisionTools() {
61
+ return {
62
+ takeScreenshot,
63
+ describeCurrentScreen,
64
+ };
65
+ }
@@ -0,0 +1,10 @@
1
+ declare module 'screenshot-desktop' {
2
+ interface ScreenshotOptions {
3
+ format?: 'png' | 'jpg';
4
+ screen?: number | string;
5
+ filename?: string;
6
+ }
7
+
8
+ function screenshot(options?: ScreenshotOptions): Promise<Buffer>;
9
+ export default screenshot;
10
+ }