npm-noxyai 1.0.7 → 1.0.8
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/index-noxyai.js +25 -41
- package/package.json +1 -1
- package/tic_tac_toe.py +111 -0
package/index-noxyai.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
const fs = require('fs');
|
|
4
4
|
const os = require('os');
|
|
5
5
|
const path = require('path');
|
|
6
|
-
const {
|
|
6
|
+
const { spawn } = require('child_process'); // 🚨 CHANGED from exec to spawn
|
|
7
7
|
const readline = require('readline');
|
|
8
8
|
|
|
9
9
|
const BASE_URL = 'https://www.noxyai.com';
|
|
@@ -12,7 +12,6 @@ const CONFIG_FILE = path.join(os.homedir(), '.noxyai.json');
|
|
|
12
12
|
const args = process.argv.slice(2);
|
|
13
13
|
const command = args[0];
|
|
14
14
|
|
|
15
|
-
// --- HELPER: ASCII ART ---
|
|
16
15
|
function printLogo() {
|
|
17
16
|
console.log('\x1b[36m' + `
|
|
18
17
|
███╗ ██╗ ██████╗ ██╗ ██╗██╗ ██╗ █████╗ ██╗
|
|
@@ -24,7 +23,6 @@ function printLogo() {
|
|
|
24
23
|
` + '\x1b[0m');
|
|
25
24
|
}
|
|
26
25
|
|
|
27
|
-
// --- HELPER: AUTHENTICATION ---
|
|
28
26
|
function saveToken(token) {
|
|
29
27
|
fs.writeFileSync(CONFIG_FILE, JSON.stringify({ token }));
|
|
30
28
|
}
|
|
@@ -47,21 +45,19 @@ function logout() {
|
|
|
47
45
|
process.exit(0);
|
|
48
46
|
}
|
|
49
47
|
|
|
50
|
-
// --- HELPER: AUTO-OPEN URL ---
|
|
51
48
|
function openBrowser(url) {
|
|
52
49
|
const platform = os.platform();
|
|
53
50
|
if (platform === 'android') {
|
|
54
|
-
|
|
51
|
+
spawn('termux-open-url', [url], { stdio: 'ignore' });
|
|
55
52
|
} else if (platform === 'darwin') {
|
|
56
|
-
|
|
53
|
+
spawn('open', [url], { stdio: 'ignore' });
|
|
57
54
|
} else if (platform === 'win32') {
|
|
58
|
-
|
|
55
|
+
spawn('cmd.exe', ['/c', 'start', '""', url], { stdio: 'ignore' });
|
|
59
56
|
} else {
|
|
60
|
-
|
|
57
|
+
spawn('xdg-open', [url], { stdio: 'ignore' });
|
|
61
58
|
}
|
|
62
59
|
}
|
|
63
60
|
|
|
64
|
-
// --- COMMAND: LOGIN ---
|
|
65
61
|
async function login() {
|
|
66
62
|
printLogo();
|
|
67
63
|
console.log('Initializing secure login...\n');
|
|
@@ -112,25 +108,25 @@ async function login() {
|
|
|
112
108
|
}
|
|
113
109
|
}
|
|
114
110
|
|
|
115
|
-
//
|
|
111
|
+
// 🚨 THE FIX: Upgraded to spawn with interactive stdio
|
|
116
112
|
function runTerminalCommand(cmd) {
|
|
117
113
|
return new Promise((resolve, reject) => {
|
|
118
|
-
console.log(`\n\x1b[33m⚡ Running:\x1b[0m ${cmd}`);
|
|
119
|
-
const child = exec(cmd, (error, stdout, stderr) => {
|
|
120
|
-
if (error) {
|
|
121
|
-
reject(stderr || error.message);
|
|
122
|
-
return;
|
|
123
|
-
}
|
|
124
|
-
resolve(stdout);
|
|
125
|
-
});
|
|
114
|
+
console.log(`\n\x1b[33m⚡ Running:\x1b[0m ${cmd}\n`);
|
|
126
115
|
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
116
|
+
const child = spawn(cmd, {
|
|
117
|
+
shell: true,
|
|
118
|
+
stdio: 'inherit' // This connects your live keyboard to the Python script!
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
child.on('close', (code) => {
|
|
122
|
+
if (code !== 0) reject(`Command failed with exit code ${code}`);
|
|
123
|
+
else resolve();
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
child.on('error', (error) => reject(error.message));
|
|
130
127
|
});
|
|
131
128
|
}
|
|
132
129
|
|
|
133
|
-
// --- COMMAND: CHAT & AGENT EXECUTION ---
|
|
134
130
|
async function chat(prompt, depth = 0) {
|
|
135
131
|
const token = getToken();
|
|
136
132
|
if (!token) {
|
|
@@ -192,7 +188,6 @@ async function chat(prompt, depth = 0) {
|
|
|
192
188
|
|
|
193
189
|
console.log('\n\n\x1b[32m[Agent] Response complete. Processing actions...\x1b[0m');
|
|
194
190
|
|
|
195
|
-
// 1. EXTRACT AND CREATE FILES
|
|
196
191
|
const fileRegex = /<file path="([^"]+)">([\s\S]*?)<\/file>/g;
|
|
197
192
|
let match;
|
|
198
193
|
while ((match = fileRegex.exec(fullResponse)) !== null) {
|
|
@@ -200,14 +195,11 @@ async function chat(prompt, depth = 0) {
|
|
|
200
195
|
const content = match[2];
|
|
201
196
|
|
|
202
197
|
const dir = path.dirname(filePath);
|
|
203
|
-
if (!fs.existsSync(dir)) {
|
|
204
|
-
fs.mkdirSync(dir, { recursive: true });
|
|
205
|
-
}
|
|
198
|
+
if (!fs.existsSync(dir)) fs.mkdirSync(dir, { recursive: true });
|
|
206
199
|
fs.writeFileSync(filePath, content.trim());
|
|
207
200
|
console.log(`\x1b[32m✔ Created file:\x1b[0m ${filePath}`);
|
|
208
201
|
}
|
|
209
202
|
|
|
210
|
-
// 2. EXTRACT AND RUN COMMANDS
|
|
211
203
|
const execRegex = /<execute>([\s\S]*?)<\/execute>/g;
|
|
212
204
|
const commands = [];
|
|
213
205
|
while ((match = execRegex.exec(fullResponse)) !== null) {
|
|
@@ -218,16 +210,13 @@ async function chat(prompt, depth = 0) {
|
|
|
218
210
|
try {
|
|
219
211
|
await runTerminalCommand(cmd);
|
|
220
212
|
} catch (err) {
|
|
221
|
-
console.error(`\n\x1b[31m❌ Command Failed:\x1b[0m ${err
|
|
213
|
+
console.error(`\n\x1b[31m❌ Command Failed:\x1b[0m ${err}`);
|
|
222
214
|
console.log(`\x1b[33m🔄 Triggering Auto-Heal Loop...\x1b[0m`);
|
|
223
|
-
|
|
224
|
-
const errorPrompt = `I ran the command "${cmd}" and got this error:\n\n${err}\n\nPlease fix the issue. If you need to rewrite a file, use the <file> tags. If you need to install a missing library, use the <execute> tag.`;
|
|
225
|
-
|
|
215
|
+
const errorPrompt = `I ran the command "${cmd}" and got this error:\n\n${err}\n\nPlease fix the issue. Use <file> tags to rewrite files or <execute> to run commands.`;
|
|
226
216
|
await chat(errorPrompt, depth + 1);
|
|
227
217
|
return;
|
|
228
218
|
}
|
|
229
219
|
}
|
|
230
|
-
|
|
231
220
|
process.exit(0);
|
|
232
221
|
|
|
233
222
|
} catch (error) {
|
|
@@ -236,7 +225,6 @@ async function chat(prompt, depth = 0) {
|
|
|
236
225
|
}
|
|
237
226
|
}
|
|
238
227
|
|
|
239
|
-
// --- COMMAND: HELP ---
|
|
240
228
|
function showHelp() {
|
|
241
229
|
printLogo();
|
|
242
230
|
console.log(`
|
|
@@ -254,14 +242,10 @@ function showHelp() {
|
|
|
254
242
|
`);
|
|
255
243
|
}
|
|
256
244
|
|
|
257
|
-
|
|
258
|
-
if (command === '
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
logout();
|
|
262
|
-
} else if (command === 'help' || command === '--help' || !command) {
|
|
263
|
-
showHelp();
|
|
264
|
-
} else if (command === 'chat') {
|
|
245
|
+
if (command === 'login') login();
|
|
246
|
+
else if (command === 'logout') logout();
|
|
247
|
+
else if (command === 'help' || command === '--help' || !command) showHelp();
|
|
248
|
+
else if (command === 'chat') {
|
|
265
249
|
const prompt = args.slice(1).join(' ');
|
|
266
250
|
if (!prompt) {
|
|
267
251
|
console.error('❌ Please provide a prompt. Example: noxyai chat "Create a python script"');
|
package/package.json
CHANGED
package/tic_tac_toe.py
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import random
|
|
2
|
+
|
|
3
|
+
class TicTacToe:
|
|
4
|
+
def __init__(self):
|
|
5
|
+
self.board = [' ' for _ in range(9)]
|
|
6
|
+
|
|
7
|
+
def print_board(self):
|
|
8
|
+
row1 = '| {} | {} | {} |'.format(self.board[0], self.board[1], self.board[2])
|
|
9
|
+
row2 = '| {} | {} | {} |'.format(self.board[3], self.board[4], self.board[5])
|
|
10
|
+
row3 = '| {} | {} | {} |'.format(self.board[6], self.board[7], self.board[8])
|
|
11
|
+
|
|
12
|
+
print()
|
|
13
|
+
print(row1)
|
|
14
|
+
print(row2)
|
|
15
|
+
print(row3)
|
|
16
|
+
print()
|
|
17
|
+
|
|
18
|
+
def available_moves(self):
|
|
19
|
+
return [i for i, spot in enumerate(self.board) if spot == ' ']
|
|
20
|
+
|
|
21
|
+
def empty_cells(self):
|
|
22
|
+
return ' ' in self.board
|
|
23
|
+
|
|
24
|
+
def num_empty_cells(self):
|
|
25
|
+
return self.board.count(' ')
|
|
26
|
+
|
|
27
|
+
def make_move(self, letter, move):
|
|
28
|
+
self.board[move] = letter
|
|
29
|
+
|
|
30
|
+
def winner(self):
|
|
31
|
+
winning_combos = [(0, 1, 2), (3, 4, 5), (6, 7, 8), (0, 3, 6), (1, 4, 7), (2, 5, 8), (0, 4, 8), (2, 4, 6)]
|
|
32
|
+
for combo in winning_combos:
|
|
33
|
+
if self.board[combo[0]] == self.board[combo[1]] == self.board[combo[2]] != ' ':
|
|
34
|
+
return self.board[combo[0]]
|
|
35
|
+
if ' ' not in self.board:
|
|
36
|
+
return 'Tie'
|
|
37
|
+
return False
|
|
38
|
+
|
|
39
|
+
def minimax(board, depth, is_maximizing):
|
|
40
|
+
result = board.winner()
|
|
41
|
+
if result:
|
|
42
|
+
if result == 'X':
|
|
43
|
+
return -10 + depth
|
|
44
|
+
elif result == 'O':
|
|
45
|
+
return 10 - depth
|
|
46
|
+
elif result == 'Tie':
|
|
47
|
+
return 0
|
|
48
|
+
|
|
49
|
+
if is_maximizing:
|
|
50
|
+
best_score = float('-inf')
|
|
51
|
+
for move in board.available_moves():
|
|
52
|
+
board.make_move('O', move)
|
|
53
|
+
score = minimax(board, depth + 1, False)
|
|
54
|
+
board.board[move] = ' '
|
|
55
|
+
best_score = max(score, best_score)
|
|
56
|
+
return best_score
|
|
57
|
+
else:
|
|
58
|
+
best_score = float('inf')
|
|
59
|
+
for move in board.available_moves():
|
|
60
|
+
board.make_move('X', move)
|
|
61
|
+
score = minimax(board, depth + 1, True)
|
|
62
|
+
board.board[move] = ' '
|
|
63
|
+
best_score = min(score, best_score)
|
|
64
|
+
return best_score
|
|
65
|
+
|
|
66
|
+
def ai_move(board):
|
|
67
|
+
best_score = float('-inf')
|
|
68
|
+
best_move = 0
|
|
69
|
+
for move in board.available_moves():
|
|
70
|
+
board.make_move('O', move)
|
|
71
|
+
score = minimax(board, 0, False)
|
|
72
|
+
board.board[move] = ' '
|
|
73
|
+
if score > best_score:
|
|
74
|
+
best_score = score
|
|
75
|
+
best_move = move
|
|
76
|
+
return best_move
|
|
77
|
+
|
|
78
|
+
def main():
|
|
79
|
+
board = TicTacToe()
|
|
80
|
+
while True:
|
|
81
|
+
board.print_board()
|
|
82
|
+
move = input("Enter your move (1-9): ")
|
|
83
|
+
if board.board[int(move) - 1] != ' ':
|
|
84
|
+
print("Invalid move, try again.")
|
|
85
|
+
continue
|
|
86
|
+
board.make_move('X', int(move) - 1)
|
|
87
|
+
result = board.winner()
|
|
88
|
+
if result:
|
|
89
|
+
board.print_board()
|
|
90
|
+
if result == 'X':
|
|
91
|
+
print("You win!")
|
|
92
|
+
elif result == 'O':
|
|
93
|
+
print("AI wins!")
|
|
94
|
+
else:
|
|
95
|
+
print("It's a tie!")
|
|
96
|
+
break
|
|
97
|
+
move = ai_move(board)
|
|
98
|
+
board.make_move('O', move)
|
|
99
|
+
result = board.winner()
|
|
100
|
+
if result:
|
|
101
|
+
board.print_board()
|
|
102
|
+
if result == 'X':
|
|
103
|
+
print("You win!")
|
|
104
|
+
elif result == 'O':
|
|
105
|
+
print("AI wins!")
|
|
106
|
+
else:
|
|
107
|
+
print("It's a tie!")
|
|
108
|
+
break
|
|
109
|
+
|
|
110
|
+
if __name__ == '__main__':
|
|
111
|
+
main()
|