@gemdoq/codi 0.2.0 → 0.2.3
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/dist/cli.js +45 -30
- package/dist/cli.js.map +1 -1
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -883,6 +883,36 @@ function completer(line) {
|
|
|
883
883
|
import { readFileSync as readFileSync4 } from "fs";
|
|
884
884
|
import { fileURLToPath as fileURLToPath2 } from "url";
|
|
885
885
|
import * as path5 from "path";
|
|
886
|
+
|
|
887
|
+
// src/ui/stdin-prompt.ts
|
|
888
|
+
init_esm_shims();
|
|
889
|
+
var _handler = null;
|
|
890
|
+
function registerPromptHandler(handler) {
|
|
891
|
+
_handler = handler;
|
|
892
|
+
}
|
|
893
|
+
function unregisterPromptHandler() {
|
|
894
|
+
_handler = null;
|
|
895
|
+
}
|
|
896
|
+
async function sharedPrompt(prompt) {
|
|
897
|
+
if (_handler) {
|
|
898
|
+
return _handler(prompt);
|
|
899
|
+
}
|
|
900
|
+
const readline3 = await import("readline/promises");
|
|
901
|
+
const rl = readline3.createInterface({
|
|
902
|
+
input: process.stdin,
|
|
903
|
+
output: process.stdout
|
|
904
|
+
});
|
|
905
|
+
try {
|
|
906
|
+
const answer = await rl.question(prompt);
|
|
907
|
+
return answer;
|
|
908
|
+
} finally {
|
|
909
|
+
rl.removeAllListeners();
|
|
910
|
+
rl.terminal = false;
|
|
911
|
+
rl.close();
|
|
912
|
+
}
|
|
913
|
+
}
|
|
914
|
+
|
|
915
|
+
// src/repl.ts
|
|
886
916
|
var __filename2 = fileURLToPath2(import.meta.url);
|
|
887
917
|
var __dirname2 = path5.dirname(__filename2);
|
|
888
918
|
var HISTORY_DIR = path5.join(os3.homedir(), ".codi");
|
|
@@ -987,6 +1017,15 @@ var Repl = class {
|
|
|
987
1017
|
}
|
|
988
1018
|
});
|
|
989
1019
|
}
|
|
1020
|
+
registerPromptHandler((prompt) => {
|
|
1021
|
+
if (!this.rl) return Promise.reject(new Error("REPL not running"));
|
|
1022
|
+
process.stdout.write(prompt);
|
|
1023
|
+
return new Promise((resolve11) => {
|
|
1024
|
+
this.rl.once("line", (answer) => {
|
|
1025
|
+
resolve11(answer);
|
|
1026
|
+
});
|
|
1027
|
+
});
|
|
1028
|
+
});
|
|
990
1029
|
this.printWelcome();
|
|
991
1030
|
while (this.running) {
|
|
992
1031
|
try {
|
|
@@ -1164,6 +1203,7 @@ ${content}
|
|
|
1164
1203
|
}
|
|
1165
1204
|
stop() {
|
|
1166
1205
|
this.running = false;
|
|
1206
|
+
unregisterPromptHandler();
|
|
1167
1207
|
if (this.rl) {
|
|
1168
1208
|
this.rl.close();
|
|
1169
1209
|
this.rl = null;
|
|
@@ -1575,7 +1615,6 @@ function validateCommand(command) {
|
|
|
1575
1615
|
|
|
1576
1616
|
// src/security/permission-manager.ts
|
|
1577
1617
|
init_esm_shims();
|
|
1578
|
-
import * as readline3 from "readline/promises";
|
|
1579
1618
|
import chalk6 from "chalk";
|
|
1580
1619
|
|
|
1581
1620
|
// src/config/permissions.ts
|
|
@@ -1657,15 +1696,10 @@ async function promptUser(tool, input3) {
|
|
|
1657
1696
|
console.log(chalk6.dim(` ${key}: `) + displayValue);
|
|
1658
1697
|
}
|
|
1659
1698
|
console.log("");
|
|
1660
|
-
const rl = readline3.createInterface({
|
|
1661
|
-
input: process.stdin,
|
|
1662
|
-
output: process.stdout
|
|
1663
|
-
});
|
|
1664
1699
|
try {
|
|
1665
|
-
const answer = await
|
|
1700
|
+
const answer = await sharedPrompt(
|
|
1666
1701
|
chalk6.yellow(`Allow? [${chalk6.bold("Y")}es / ${chalk6.bold("n")}o / ${chalk6.bold("a")}lways for this tool] `)
|
|
1667
1702
|
);
|
|
1668
|
-
rl.close();
|
|
1669
1703
|
const choice = answer.trim().toLowerCase();
|
|
1670
1704
|
if (choice === "a" || choice === "always") {
|
|
1671
1705
|
sessionAllowed.add(tool.name);
|
|
@@ -1676,7 +1710,6 @@ async function promptUser(tool, input3) {
|
|
|
1676
1710
|
}
|
|
1677
1711
|
return true;
|
|
1678
1712
|
} catch {
|
|
1679
|
-
rl.close();
|
|
1680
1713
|
return false;
|
|
1681
1714
|
}
|
|
1682
1715
|
}
|
|
@@ -2243,20 +2276,15 @@ async function callLlmWithRetry(provider, conversation, registry, stream, option
|
|
|
2243
2276
|
callbacks: stream ? {
|
|
2244
2277
|
onToken: (text) => {
|
|
2245
2278
|
stopSpinner();
|
|
2246
|
-
if (showOutput && !streamedText) {
|
|
2247
|
-
process.stdout.write("\n" + renderAssistantPrefix() + "\n");
|
|
2248
|
-
}
|
|
2249
2279
|
streamedText += text;
|
|
2250
|
-
if (showOutput) {
|
|
2251
|
-
process.stdout.write(text);
|
|
2252
|
-
}
|
|
2253
2280
|
options.onToken?.(text);
|
|
2254
2281
|
}
|
|
2255
2282
|
} : void 0
|
|
2256
2283
|
});
|
|
2257
2284
|
if (streamedText) {
|
|
2258
2285
|
if (showOutput) {
|
|
2259
|
-
process.stdout.write("\n");
|
|
2286
|
+
process.stdout.write("\n" + renderAssistantPrefix() + "\n");
|
|
2287
|
+
console.log(renderMarkdown(streamedText));
|
|
2260
2288
|
}
|
|
2261
2289
|
return { ...response, _streamed: true };
|
|
2262
2290
|
}
|
|
@@ -5405,7 +5433,6 @@ init_task_tools();
|
|
|
5405
5433
|
// src/tools/ask-user.ts
|
|
5406
5434
|
init_esm_shims();
|
|
5407
5435
|
init_tool();
|
|
5408
|
-
import * as readline4 from "readline/promises";
|
|
5409
5436
|
import chalk13 from "chalk";
|
|
5410
5437
|
var askUserTool = {
|
|
5411
5438
|
name: "ask_user",
|
|
@@ -5446,14 +5473,9 @@ var askUserTool = {
|
|
|
5446
5473
|
}
|
|
5447
5474
|
console.log(chalk13.dim(` ${options.length + 1}. Other (type custom response)`));
|
|
5448
5475
|
console.log("");
|
|
5449
|
-
const rl2 = readline4.createInterface({
|
|
5450
|
-
input: process.stdin,
|
|
5451
|
-
output: process.stdout
|
|
5452
|
-
});
|
|
5453
5476
|
try {
|
|
5454
5477
|
const prompt = multiSelect ? chalk13.dim("Enter numbers separated by commas: ") : chalk13.dim("Enter number or type response: ");
|
|
5455
|
-
const answer = await
|
|
5456
|
-
rl2.close();
|
|
5478
|
+
const answer = await sharedPrompt(prompt);
|
|
5457
5479
|
if (multiSelect) {
|
|
5458
5480
|
const indices = answer.split(",").map((s) => parseInt(s.trim()) - 1);
|
|
5459
5481
|
const selected = indices.filter((i) => i >= 0 && i < options.length).map((i) => options[i].label);
|
|
@@ -5468,20 +5490,13 @@ var askUserTool = {
|
|
|
5468
5490
|
}
|
|
5469
5491
|
return makeToolResult(`User response: ${answer}`);
|
|
5470
5492
|
} catch {
|
|
5471
|
-
rl2.close();
|
|
5472
5493
|
return makeToolError("Failed to get user input");
|
|
5473
5494
|
}
|
|
5474
5495
|
}
|
|
5475
|
-
const rl = readline4.createInterface({
|
|
5476
|
-
input: process.stdin,
|
|
5477
|
-
output: process.stdout
|
|
5478
|
-
});
|
|
5479
5496
|
try {
|
|
5480
|
-
const answer = await
|
|
5481
|
-
rl.close();
|
|
5497
|
+
const answer = await sharedPrompt(chalk13.dim("> "));
|
|
5482
5498
|
return makeToolResult(`User response: ${answer}`);
|
|
5483
5499
|
} catch {
|
|
5484
|
-
rl.close();
|
|
5485
5500
|
return makeToolError("Failed to get user input");
|
|
5486
5501
|
}
|
|
5487
5502
|
}
|