@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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@projectservan8n/cnapse",
3
- "version": "0.2.0",
3
+ "version": "0.4.0",
4
4
  "description": "Autonomous PC intelligence - AI assistant for desktop automation",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -44,7 +44,9 @@
44
44
  "node-fetch": "^3.3.2",
45
45
  "figlet": "^1.7.0",
46
46
  "gradient-string": "^2.0.2",
47
- "boxen": "^8.0.1"
47
+ "boxen": "^8.0.1",
48
+ "telegraf": "^4.16.3",
49
+ "screenshot-desktop": "^1.15.0"
48
50
  },
49
51
  "devDependencies": {
50
52
  "@types/node": "^22.0.0",
@@ -0,0 +1,62 @@
1
+ /**
2
+ * Coder Agent - Code generation and editing
3
+ */
4
+
5
+ import type { Agent } from './types.js';
6
+ import { filesystemTools } from '../tools/filesystem.js';
7
+ import { shellTools } from '../tools/shell.js';
8
+
9
+ export const coderAgent: Agent = {
10
+ name: 'coder',
11
+ description: 'Code generation, editing, debugging, refactoring',
12
+ systemPrompt: `You are the Coder agent for C-napse. You help users write, edit, and debug code.
13
+
14
+ Guidelines:
15
+ - Write clean, well-documented code
16
+ - Follow best practices for the language
17
+ - Include error handling
18
+ - Add helpful comments
19
+ - Suggest improvements when appropriate
20
+
21
+ Available tools:
22
+ - read_file: Read source files
23
+ - write_file: Write/create files
24
+ - list_dir: Browse project structure
25
+ - find_files: Search for files
26
+ - run_command: Execute build/test commands
27
+
28
+ When writing code:
29
+ 1. Understand the requirements first
30
+ 2. Check existing code structure
31
+ 3. Write modular, reusable code
32
+ 4. Test when possible
33
+ 5. Explain your implementation
34
+
35
+ Languages you excel at:
36
+ - JavaScript/TypeScript
37
+ - Python
38
+ - Rust
39
+ - Go
40
+ - HTML/CSS
41
+ - Shell scripts
42
+ - And many more!
43
+
44
+ Format code blocks with language hints:
45
+ \`\`\`typescript
46
+ // code here
47
+ \`\`\``,
48
+ tools: [...filesystemTools, ...shellTools.slice(0, 1)], // Include run_command
49
+ canHandle: (intent: string) => {
50
+ const lower = intent.toLowerCase();
51
+ if (
52
+ lower.includes('code') ||
53
+ lower.includes('write') ||
54
+ lower.includes('function') ||
55
+ lower.includes('debug') ||
56
+ lower.includes('implement')
57
+ ) {
58
+ return 0.9;
59
+ }
60
+ return 0.2;
61
+ },
62
+ };
@@ -0,0 +1,61 @@
1
+ /**
2
+ * Computer Control Agent - Mouse, keyboard, and window automation
3
+ */
4
+
5
+ export const computerAgent = {
6
+ name: 'computer',
7
+ systemPrompt: `You are a computer control specialist. You help users automate their PC by controlling the mouse, keyboard, and windows.
8
+
9
+ Available tools:
10
+ - moveMouse(x, y) - Move mouse to screen coordinates
11
+ - clickMouse(button) - Click mouse button ('left', 'right', 'middle')
12
+ - doubleClick() - Double-click at current position
13
+ - typeText(text) - Type text using keyboard
14
+ - pressKey(key) - Press a single key (e.g., 'enter', 'escape', 'tab')
15
+ - keyCombo(keys) - Press key combination (e.g., ['control', 'c'] for copy)
16
+ - getActiveWindow() - Get info about the currently focused window
17
+ - listWindows() - List all open windows
18
+ - focusWindow(title) - Focus a window by title (partial match)
19
+ - scrollMouse(amount) - Scroll mouse wheel (positive=up, negative=down)
20
+
21
+ Guidelines:
22
+ 1. Always confirm dangerous actions (like closing windows with unsaved work)
23
+ 2. Use keyboard shortcuts when more efficient than mouse clicks
24
+ 3. Wait briefly between actions to let the UI update
25
+ 4. Report what you see/do at each step
26
+ 5. If something fails, try alternative approaches
27
+
28
+ Common keyboard shortcuts:
29
+ - Copy: control+c
30
+ - Paste: control+v
31
+ - Cut: control+x
32
+ - Undo: control+z
33
+ - Save: control+s
34
+ - Close window: alt+F4
35
+ - Switch windows: alt+Tab
36
+ - Open Start menu: meta (Windows key)
37
+ - Open Run dialog: meta+r
38
+
39
+ When asked to open an application:
40
+ 1. Use meta+r to open Run dialog
41
+ 2. Type the application name
42
+ 3. Press Enter
43
+ 4. Wait for it to open
44
+ 5. Report what you see`,
45
+ tools: [
46
+ 'moveMouse',
47
+ 'clickMouse',
48
+ 'doubleClick',
49
+ 'typeText',
50
+ 'pressKey',
51
+ 'keyCombo',
52
+ 'getActiveWindow',
53
+ 'listWindows',
54
+ 'focusWindow',
55
+ 'scrollMouse',
56
+ 'dragMouse',
57
+ 'getMousePosition',
58
+ ],
59
+ };
60
+
61
+ export default computerAgent;
@@ -0,0 +1,179 @@
1
+ /**
2
+ * Tool Executor - Executes tool calls from agents
3
+ */
4
+
5
+ import type { ToolCall } from './types.js';
6
+ import type { ToolResult } from '../tools/index.js';
7
+
8
+ // Import all tools
9
+ import * as shell from '../tools/shell.js';
10
+ import * as filesystem from '../tools/filesystem.js';
11
+ import * as clipboard from '../tools/clipboard.js';
12
+ import * as network from '../tools/network.js';
13
+ import * as processTools from '../tools/process.js';
14
+ import * as computer from '../tools/computer.js';
15
+ import * as vision from '../tools/vision.js';
16
+
17
+ /**
18
+ * Execute a tool call and return the result
19
+ */
20
+ export async function executeTool(call: ToolCall): Promise<ToolResult> {
21
+ const { name, arguments: args } = call;
22
+
23
+ try {
24
+ switch (name) {
25
+ // Shell tools
26
+ case 'run_command':
27
+ return await shell.runCommand(
28
+ args.cmd as string,
29
+ args.timeout as number | undefined
30
+ );
31
+ case 'get_env':
32
+ return shell.getEnv(args.var as string);
33
+ case 'set_env':
34
+ return shell.setEnv(args.var as string, args.value as string);
35
+ case 'get_cwd':
36
+ return shell.getCwd();
37
+ case 'set_cwd':
38
+ return shell.setCwd(args.path as string);
39
+
40
+ // Filesystem tools
41
+ case 'read_file':
42
+ return await filesystem.readFile(args.path as string);
43
+ case 'write_file':
44
+ return await filesystem.writeFile(args.path as string, args.content as string);
45
+ case 'list_dir':
46
+ return await filesystem.listDir(args.path as string, args.recursive as boolean);
47
+ case 'copy_file':
48
+ return await filesystem.copyFile(args.src as string, args.dst as string);
49
+ case 'move_path':
50
+ return await filesystem.movePath(args.src as string, args.dst as string);
51
+ case 'delete_path':
52
+ return await filesystem.deletePath(args.path as string, args.force as boolean);
53
+ case 'file_info':
54
+ return await filesystem.fileInfo(args.path as string);
55
+ case 'find_files':
56
+ return await filesystem.findFiles(
57
+ args.directory as string,
58
+ args.pattern as string,
59
+ args.maxResults as number | undefined
60
+ );
61
+
62
+ // Clipboard tools
63
+ case 'get_clipboard':
64
+ return await clipboard.getClipboard();
65
+ case 'set_clipboard':
66
+ return await clipboard.setClipboard(args.text as string);
67
+
68
+ // Network tools
69
+ case 'check_port':
70
+ return await network.checkPort(args.port as number);
71
+ case 'find_available_port':
72
+ return await network.findAvailablePort(args.start as number, args.end as number);
73
+ case 'check_connection':
74
+ return await network.checkConnection(
75
+ args.host as string,
76
+ args.port as number,
77
+ args.timeout as number | undefined
78
+ );
79
+ case 'get_local_ip':
80
+ return network.getLocalIp();
81
+ case 'list_interfaces':
82
+ return network.listInterfaces();
83
+ case 'fetch_url':
84
+ return await network.fetchUrl(args.url as string);
85
+
86
+ // Process tools
87
+ case 'list_processes':
88
+ return await processTools.listProcesses();
89
+ case 'process_info':
90
+ return await processTools.processInfo(args.pid as number);
91
+ case 'kill_process':
92
+ return await processTools.killProcess(args.pid as number, args.force as boolean);
93
+ case 'find_process':
94
+ return await processTools.findProcess(args.name as string);
95
+ case 'system_info':
96
+ return processTools.systemInfo();
97
+
98
+ // Computer control tools
99
+ case 'moveMouse':
100
+ return await computer.moveMouse(args.x as number, args.y as number);
101
+ case 'clickMouse':
102
+ return await computer.clickMouse(args.button as 'left' | 'right' | 'middle');
103
+ case 'doubleClick':
104
+ return await computer.doubleClick();
105
+ case 'typeText':
106
+ return await computer.typeText(args.text as string);
107
+ case 'pressKey':
108
+ return await computer.pressKey(args.key as string);
109
+ case 'keyCombo':
110
+ return await computer.keyCombo(args.keys as string[]);
111
+ case 'getActiveWindow':
112
+ return await computer.getActiveWindow();
113
+ case 'listWindows':
114
+ return await computer.listWindows();
115
+ case 'focusWindow':
116
+ return await computer.focusWindow(args.title as string);
117
+ case 'scrollMouse':
118
+ return await computer.scrollMouse(args.amount as number);
119
+ case 'dragMouse':
120
+ return await computer.dragMouse(
121
+ args.startX as number,
122
+ args.startY as number,
123
+ args.endX as number,
124
+ args.endY as number
125
+ );
126
+ case 'getMousePosition':
127
+ return await computer.getMousePosition();
128
+
129
+ // Vision tools
130
+ case 'takeScreenshot':
131
+ const screenshotResult = await vision.takeScreenshot();
132
+ return {
133
+ success: screenshotResult.success,
134
+ output: screenshotResult.screenshot || '',
135
+ error: screenshotResult.error,
136
+ };
137
+ case 'describeCurrentScreen':
138
+ const visionResult = await vision.describeCurrentScreen();
139
+ return {
140
+ success: visionResult.success,
141
+ output: visionResult.description || '',
142
+ error: visionResult.error,
143
+ };
144
+
145
+ default:
146
+ return { success: false, output: '', error: `Unknown tool: ${name}` };
147
+ }
148
+ } catch (error: any) {
149
+ return { success: false, output: '', error: `Tool error: ${error.message}` };
150
+ }
151
+ }
152
+
153
+ /**
154
+ * Execute multiple tool calls
155
+ */
156
+ export async function executeTools(calls: ToolCall[]): Promise<Map<string, ToolResult>> {
157
+ const results = new Map<string, ToolResult>();
158
+
159
+ for (const call of calls) {
160
+ const result = await executeTool(call);
161
+ results.set(call.id, result);
162
+ }
163
+
164
+ return results;
165
+ }
166
+
167
+ /**
168
+ * Format tool results for display
169
+ */
170
+ export function formatToolResult(call: ToolCall, result: ToolResult): string {
171
+ const status = result.success ? '✓' : '✗';
172
+ const header = `[${status} ${call.name}]`;
173
+
174
+ if (result.success) {
175
+ return `${header}\n${result.output}`;
176
+ } else {
177
+ return `${header}\nError: ${result.error}`;
178
+ }
179
+ }
@@ -0,0 +1,56 @@
1
+ /**
2
+ * Filer Agent - File operations
3
+ */
4
+
5
+ import type { Agent } from './types.js';
6
+ import { filesystemTools } from '../tools/filesystem.js';
7
+ import { clipboardTools } from '../tools/clipboard.js';
8
+
9
+ export const filerAgent: Agent = {
10
+ name: 'filer',
11
+ description: 'File operations - read, write, search, organize',
12
+ systemPrompt: `You are the Filer agent for C-napse. You help users manage files and directories.
13
+
14
+ Guidelines:
15
+ - Always confirm before deleting files
16
+ - Show file contents before modifications
17
+ - Use safe operations by default
18
+ - Warn about large operations
19
+
20
+ Available tools:
21
+ - read_file: Read file contents
22
+ - write_file: Write content to file
23
+ - list_dir: List directory contents
24
+ - copy_file: Copy files
25
+ - move_path: Move/rename files
26
+ - delete_path: Delete files (requires force for directories)
27
+ - file_info: Get file metadata
28
+ - find_files: Search for files by pattern
29
+ - get_clipboard: Get clipboard content
30
+ - set_clipboard: Copy to clipboard
31
+
32
+ When working with files:
33
+ 1. Check if path exists first
34
+ 2. Show current contents before editing
35
+ 3. Confirm destructive operations
36
+ 4. Report results clearly
37
+
38
+ Common patterns:
39
+ - Find all TypeScript files: find_files(".", "**/*.ts")
40
+ - List project root: list_dir(".")
41
+ - Read config: read_file("package.json")`,
42
+ tools: [...filesystemTools, ...clipboardTools],
43
+ canHandle: (intent: string) => {
44
+ const lower = intent.toLowerCase();
45
+ if (
46
+ lower.includes('file') ||
47
+ lower.includes('folder') ||
48
+ lower.includes('directory') ||
49
+ lower.includes('find') ||
50
+ lower.includes('search')
51
+ ) {
52
+ return 0.9;
53
+ }
54
+ return 0.2;
55
+ },
56
+ };
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Agent system for C-napse
3
+ *
4
+ * Each agent is a specialized AI that handles specific types of tasks.
5
+ */
6
+
7
+ export * from './types.js';
8
+ export * from './router.js';
9
+ export * from './shell.js';
10
+ export * from './coder.js';
11
+ export * from './filer.js';
12
+ export * from './executor.js';
@@ -0,0 +1,160 @@
1
+ /**
2
+ * Router Agent - Classifies user intent and dispatches to specialist agents
3
+ */
4
+
5
+ import type { Agent } from './types.js';
6
+
7
+ export type AgentType = 'CODER' | 'FILER' | 'SHELL' | 'MEMORY' | 'COMPUTER' | 'VISION' | 'GENERAL';
8
+
9
+ export const routerAgent: Agent = {
10
+ name: 'router',
11
+ description: 'Classifies user intent and dispatches to the appropriate specialist agent',
12
+ systemPrompt: `You are a routing agent for C-napse. Your job is to analyze user requests and determine which specialist agent should handle them.
13
+
14
+ Available agents:
15
+ - CODER: Code generation, editing, debugging, refactoring
16
+ - FILER: File operations (read, write, search, organize)
17
+ - SHELL: Shell commands, system operations, process management
18
+ - MEMORY: Context recall, summarization, search history
19
+ - COMPUTER: Mouse, keyboard, window control, desktop automation
20
+ - VISION: Screen capture, describe what's on screen
21
+ - GENERAL: General conversation and questions
22
+
23
+ Respond with ONLY the agent name, nothing else.
24
+
25
+ Examples:
26
+ User: "Write a Python script to sort files by date"
27
+ CODER
28
+
29
+ User: "Find all PDFs in my Documents folder"
30
+ FILER
31
+
32
+ User: "What's using port 8080?"
33
+ SHELL
34
+
35
+ User: "What did we talk about yesterday?"
36
+ MEMORY
37
+
38
+ User: "How does React work?"
39
+ GENERAL
40
+
41
+ User: "Click on the Start button"
42
+ COMPUTER
43
+
44
+ User: "Open notepad and type hello"
45
+ COMPUTER
46
+
47
+ User: "What's on my screen?"
48
+ VISION
49
+
50
+ User: "Take a screenshot"
51
+ VISION`,
52
+ tools: [],
53
+ canHandle: () => 1.0,
54
+ };
55
+
56
+ /**
57
+ * Route query to appropriate agent using keyword matching
58
+ */
59
+ export function routeByKeywords(query: string): AgentType {
60
+ const q = query.toLowerCase();
61
+
62
+ // Code-related keywords
63
+ if (
64
+ q.includes('code') ||
65
+ q.includes('write') ||
66
+ q.includes('function') ||
67
+ q.includes('script') ||
68
+ q.includes('debug') ||
69
+ q.includes('fix') ||
70
+ q.includes('implement') ||
71
+ q.includes('refactor') ||
72
+ q.includes('class') ||
73
+ q.includes('method') ||
74
+ q.includes('program')
75
+ ) {
76
+ return 'CODER';
77
+ }
78
+
79
+ // File-related keywords
80
+ if (
81
+ q.includes('file') ||
82
+ q.includes('folder') ||
83
+ q.includes('directory') ||
84
+ q.includes('find') ||
85
+ q.includes('search') ||
86
+ q.includes('list') ||
87
+ q.includes('copy') ||
88
+ q.includes('move') ||
89
+ q.includes('delete') ||
90
+ q.includes('rename') ||
91
+ q.includes('read')
92
+ ) {
93
+ return 'FILER';
94
+ }
95
+
96
+ // Shell-related keywords
97
+ if (
98
+ q.includes('run') ||
99
+ q.includes('execute') ||
100
+ q.includes('command') ||
101
+ q.includes('install') ||
102
+ q.includes('process') ||
103
+ q.includes('port') ||
104
+ q.includes('service') ||
105
+ q.includes('start') ||
106
+ q.includes('stop') ||
107
+ q.includes('restart') ||
108
+ q.includes('terminal') ||
109
+ q.includes('shell')
110
+ ) {
111
+ return 'SHELL';
112
+ }
113
+
114
+ // Memory-related keywords
115
+ if (
116
+ q.includes('remember') ||
117
+ q.includes('recall') ||
118
+ q.includes('history') ||
119
+ q.includes('yesterday') ||
120
+ q.includes('earlier') ||
121
+ q.includes('before') ||
122
+ q.includes('last time') ||
123
+ q.includes('previous')
124
+ ) {
125
+ return 'MEMORY';
126
+ }
127
+
128
+ // Computer control keywords
129
+ if (
130
+ q.includes('click') ||
131
+ q.includes('mouse') ||
132
+ q.includes('type') ||
133
+ q.includes('keyboard') ||
134
+ q.includes('window') ||
135
+ q.includes('open ') ||
136
+ q.includes('close ') ||
137
+ q.includes('minimize') ||
138
+ q.includes('maximize') ||
139
+ q.includes('press') ||
140
+ q.includes('scroll') ||
141
+ q.includes('drag')
142
+ ) {
143
+ return 'COMPUTER';
144
+ }
145
+
146
+ // Vision keywords
147
+ if (
148
+ q.includes('screen') ||
149
+ q.includes('screenshot') ||
150
+ q.includes('see') ||
151
+ q.includes('look') ||
152
+ q.includes('what') && q.includes('visible') ||
153
+ q.includes('describe') && q.includes('screen') ||
154
+ q.includes('capture')
155
+ ) {
156
+ return 'VISION';
157
+ }
158
+
159
+ return 'GENERAL';
160
+ }
@@ -0,0 +1,67 @@
1
+ /**
2
+ * Shell Agent - Shell commands and system operations
3
+ */
4
+
5
+ import type { Agent } from './types.js';
6
+ import { shellTools } from '../tools/shell.js';
7
+ import { processTools } from '../tools/process.js';
8
+ import { networkTools } from '../tools/network.js';
9
+
10
+ const os = process.platform;
11
+ const shell = os === 'win32' ? 'PowerShell' : 'bash';
12
+
13
+ export const shellAgent: Agent = {
14
+ name: 'shell',
15
+ description: 'Shell commands, system operations, process management',
16
+ systemPrompt: `You are the Shell agent for C-napse. You help users with shell commands and system operations.
17
+
18
+ Current OS: ${os}
19
+ Shell: ${shell}
20
+
21
+ Guidelines:
22
+ - Generate safe, non-destructive commands by default
23
+ - Always explain what each command does
24
+ - Use portable commands when possible
25
+ - For complex tasks, break into steps
26
+ - Ask for confirmation before destructive operations (rm -rf, format, etc.)
27
+
28
+ Available tools:
29
+ - run_command: Execute shell command
30
+ - get_env: Get environment variable
31
+ - set_env: Set environment variable
32
+ - get_cwd: Get current directory
33
+ - set_cwd: Change directory
34
+ - list_processes: List running processes
35
+ - process_info: Get process details
36
+ - kill_process: Terminate process
37
+ - find_process: Find process by name
38
+ - system_info: Get system information
39
+ - check_port: Check if port is in use
40
+ - find_available_port: Find free port
41
+ - check_connection: Test connectivity
42
+ - get_local_ip: Get IP addresses
43
+ - fetch_url: Fetch URL content
44
+
45
+ NEVER run commands that could:
46
+ - Delete system files
47
+ - Modify boot configuration
48
+ - Change user permissions without confirmation
49
+ - Execute downloaded scripts without review
50
+
51
+ When asked to run a command, use the run_command tool.
52
+ Format your response with the command output clearly displayed.`,
53
+ tools: [...shellTools, ...processTools, ...networkTools],
54
+ canHandle: (intent: string) => {
55
+ const lower = intent.toLowerCase();
56
+ if (
57
+ lower.includes('run') ||
58
+ lower.includes('execute') ||
59
+ lower.includes('command') ||
60
+ lower.includes('process') ||
61
+ lower.includes('port')
62
+ ) {
63
+ return 0.9;
64
+ }
65
+ return 0.2;
66
+ },
67
+ };
@@ -0,0 +1,80 @@
1
+ /**
2
+ * Agent type definitions
3
+ */
4
+
5
+ import type { ToolDefinition, ToolResult } from '../tools/index.js';
6
+
7
+ export type MessageRole = 'system' | 'user' | 'assistant' | 'tool';
8
+
9
+ export interface AgentMessage {
10
+ role: MessageRole;
11
+ content: string;
12
+ metadata?: Record<string, unknown>;
13
+ }
14
+
15
+ export interface ToolCall {
16
+ id: string;
17
+ name: string;
18
+ arguments: Record<string, unknown>;
19
+ }
20
+
21
+ export interface AgentContext {
22
+ messages: AgentMessage[];
23
+ tools: ToolDefinition[];
24
+ memory?: string;
25
+ cwd?: string;
26
+ }
27
+
28
+ export interface AgentResponse {
29
+ content: string;
30
+ toolCalls: ToolCall[];
31
+ tokensUsed: number;
32
+ shouldContinue: boolean;
33
+ }
34
+
35
+ export interface Agent {
36
+ name: string;
37
+ description: string;
38
+ systemPrompt: string;
39
+ tools: ToolDefinition[];
40
+ canHandle(intent: string): number;
41
+ }
42
+
43
+ // Helper functions
44
+ export function createMessage(role: MessageRole, content: string): AgentMessage {
45
+ return { role, content };
46
+ }
47
+
48
+ export function systemMessage(content: string): AgentMessage {
49
+ return createMessage('system', content);
50
+ }
51
+
52
+ export function userMessage(content: string): AgentMessage {
53
+ return createMessage('user', content);
54
+ }
55
+
56
+ export function assistantMessage(content: string): AgentMessage {
57
+ return createMessage('assistant', content);
58
+ }
59
+
60
+ export function toolMessage(content: string): AgentMessage {
61
+ return createMessage('tool', content);
62
+ }
63
+
64
+ export function textResponse(content: string): AgentResponse {
65
+ return {
66
+ content,
67
+ toolCalls: [],
68
+ tokensUsed: 0,
69
+ shouldContinue: false,
70
+ };
71
+ }
72
+
73
+ export function toolCallResponse(content: string, calls: ToolCall[]): AgentResponse {
74
+ return {
75
+ content,
76
+ toolCalls: calls,
77
+ tokensUsed: 0,
78
+ shouldContinue: calls.length > 0,
79
+ };
80
+ }