nex-code 0.3.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,99 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Nex Code — Agentic Coding CLI
4
+ * Entrypoint: loads .env, parses CLI flags, starts REPL or headless mode.
5
+ */
6
+
7
+ const path = require('path');
8
+
9
+ // Load .env from CLI install dir (fallback) and project dir
10
+ require('dotenv').config({ path: path.join(__dirname, '..', '.env') });
11
+ require('dotenv').config(); // Also check CWD
12
+
13
+ const args = process.argv.slice(2);
14
+
15
+ // ─── --help / -h ──────────────────────────────────────────────
16
+ if (args.includes('--help') || args.includes('-h')) {
17
+ console.log(`Usage: nex-code [options]
18
+
19
+ Options:
20
+ --task <prompt> Run a single task and exit (headless mode)
21
+ --auto Skip all confirmations (implies --task)
22
+ --yolo, -yolo Skip all confirmations (interactive YOLO mode)
23
+ --model <spec> Set model (e.g. openai:gpt-4o)
24
+ --max-turns <n> Max agentic loop iterations (default: 50)
25
+ --json Output result as JSON (for CI parsing)
26
+ -h, --help Show this help
27
+ -v, --version Show version
28
+ `);
29
+ process.exit(0);
30
+ }
31
+
32
+ // ─── --version / -v ───────────────────────────────────────────
33
+ if (args.includes('-v') || args.includes('--version')) {
34
+ const pkg = require('../package.json');
35
+ console.log(pkg.version);
36
+ process.exit(0);
37
+ }
38
+
39
+ // ─── --yolo / -yolo ──────────────────────────────────────────
40
+ const yoloMode = args.includes('--yolo') || args.includes('-yolo');
41
+ if (yoloMode) {
42
+ const { setAutoConfirm } = require('../cli/safety');
43
+ setAutoConfirm(true);
44
+ }
45
+
46
+ // ─── --model ──────────────────────────────────────────────────
47
+ const modelIdx = args.indexOf('--model');
48
+ if (modelIdx !== -1 && args[modelIdx + 1]) {
49
+ const { setActiveModel } = require('../cli/providers/registry');
50
+ setActiveModel(args[modelIdx + 1]);
51
+ }
52
+
53
+ // ─── --max-turns ─────────────────────────────────────────────
54
+ const maxTurnsIdx = args.indexOf('--max-turns');
55
+ if (maxTurnsIdx !== -1 && args[maxTurnsIdx + 1]) {
56
+ const n = parseInt(args[maxTurnsIdx + 1], 10);
57
+ if (n > 0) {
58
+ const { setMaxIterations } = require('../cli/agent');
59
+ setMaxIterations(n);
60
+ }
61
+ }
62
+
63
+ // ─── --task (headless mode) ──────────────────────────────────
64
+ const taskIdx = args.indexOf('--task');
65
+ if (taskIdx !== -1) {
66
+ const task = args[taskIdx + 1];
67
+ if (!task || task.startsWith('--')) {
68
+ console.error('--task requires a prompt');
69
+ process.exit(1);
70
+ }
71
+
72
+ // Auto-confirm when --auto
73
+ if (args.includes('--auto')) {
74
+ const { setAutoConfirm } = require('../cli/safety');
75
+ setAutoConfirm(true);
76
+ }
77
+
78
+ // Execute task
79
+ const { processInput, getConversationMessages } = require('../cli/agent');
80
+ processInput(task).then(() => {
81
+ if (args.includes('--json')) {
82
+ const msgs = getConversationMessages();
83
+ const lastAssistant = msgs.filter((m) => m.role === 'assistant').pop();
84
+ console.log(JSON.stringify({ success: true, response: lastAssistant?.content || '' }));
85
+ }
86
+ process.exit(0);
87
+ }).catch((err) => {
88
+ if (args.includes('--json')) {
89
+ console.log(JSON.stringify({ success: false, error: err.message }));
90
+ } else {
91
+ console.error(err.message);
92
+ }
93
+ process.exit(1);
94
+ });
95
+ } else {
96
+ // Normal REPL mode
97
+ const { startREPL } = require('../cli/index');
98
+ startREPL();
99
+ }