@nexus-cortex/cli 4.29.0 → 4.30.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/bin/cortex.js +46 -2
- package/package.json +2 -2
package/bin/cortex.js
CHANGED
|
@@ -463,6 +463,42 @@ async function fetchJSON(path, options = {}, timeoutMs = 30000) {
|
|
|
463
463
|
|
|
464
464
|
// ── Commands ──────────────────────────────────────────────────────
|
|
465
465
|
|
|
466
|
+
// Interactive chat REPL — `cortex` with no message drops you here so you can talk
|
|
467
|
+
// line-by-line without the shell mangling ?/*/quotes. The server keeps the session,
|
|
468
|
+
// so it's multi-turn. Reuses the same /v1/messages send as the one-shot path.
|
|
469
|
+
async function runInteractiveChat() {
|
|
470
|
+
if (newSession) {
|
|
471
|
+
try { await fetchJSON('/sessions/new', { method: 'POST' }); } catch { /* fresh session is best-effort */ }
|
|
472
|
+
}
|
|
473
|
+
const { createInterface } = await import('node:readline/promises');
|
|
474
|
+
const rl = createInterface({ input: process.stdin, output: process.stdout });
|
|
475
|
+
process.stdout.write(
|
|
476
|
+
'\n Nexus Cortex — interactive chat. Type a message and press Enter.\n' +
|
|
477
|
+
' The session persists across messages. Type "exit" (or press Ctrl-D) to quit.\n\n',
|
|
478
|
+
);
|
|
479
|
+
try {
|
|
480
|
+
for (;;) {
|
|
481
|
+
let line;
|
|
482
|
+
try { line = (await rl.question('cortex> ')).trim(); }
|
|
483
|
+
catch { break; } // Ctrl-D / closed input
|
|
484
|
+
if (!line) continue;
|
|
485
|
+
if (line === 'exit' || line === 'quit' || line === ':q') break;
|
|
486
|
+
const payload = { messages: [{ role: 'user', content: line }] };
|
|
487
|
+
if (modelId) payload.model = modelId;
|
|
488
|
+
try {
|
|
489
|
+
const data = await fetchJSON('/v1/messages', { method: 'POST', body: JSON.stringify(payload) }, messageTimeoutMs);
|
|
490
|
+
const text = (data.content || []).filter((b) => b.type === 'text').map((b) => b.text).join('\n');
|
|
491
|
+
process.stdout.write('\n' + (text || '(no text response)') + '\n\n');
|
|
492
|
+
} catch (err) {
|
|
493
|
+
process.stderr.write(`\n [error] ${err.message}\n\n`);
|
|
494
|
+
}
|
|
495
|
+
}
|
|
496
|
+
} finally {
|
|
497
|
+
rl.close();
|
|
498
|
+
}
|
|
499
|
+
process.stdout.write(' Bye.\n');
|
|
500
|
+
}
|
|
501
|
+
|
|
466
502
|
async function run() {
|
|
467
503
|
// --shutdown: stop the server and exit
|
|
468
504
|
if (doShutdown) {
|
|
@@ -597,9 +633,17 @@ async function run() {
|
|
|
597
633
|
}
|
|
598
634
|
}
|
|
599
635
|
|
|
600
|
-
//
|
|
636
|
+
// No message provided. In an interactive terminal (and NOT agent/run mode), drop
|
|
637
|
+
// into the chat REPL so the shell never mangles ?/*/quotes. agent/run with no task,
|
|
638
|
+
// or any non-TTY (scripted) use, still gets the usage error — unchanged.
|
|
601
639
|
if (!prompt) {
|
|
602
|
-
|
|
640
|
+
if (!__agentMode && process.stdin.isTTY) {
|
|
641
|
+
await runInteractiveChat();
|
|
642
|
+
return;
|
|
643
|
+
}
|
|
644
|
+
console.error(__agentMode
|
|
645
|
+
? 'Usage: cortex agent "<task>" (or cortex run "<task>")'
|
|
646
|
+
: 'Usage: cortex "your prompt here"');
|
|
603
647
|
console.error(' cortex --help for more options');
|
|
604
648
|
process.exit(1);
|
|
605
649
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nexus-cortex/cli",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.30.0",
|
|
4
4
|
"description": "Nexus Cortex CLI - Terminal interface for multi-provider LLM orchestration",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
"prepack": "node ../../scripts/copy-pkg-cortex-scaffold.mjs"
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@nexus-cortex/core": "^4.
|
|
22
|
+
"@nexus-cortex/core": "^4.30.0",
|
|
23
23
|
"chalk": "^4.1.2",
|
|
24
24
|
"cli-spinners": "^2.9.0",
|
|
25
25
|
"commander": "^11.0.0",
|