prompts-gpt 0.2.12 → 0.2.13
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 +81 -40
- package/dist/cli.js.map +1 -1
- package/dist/runtime.d.ts.map +1 -1
- package/dist/runtime.js +68 -19
- package/dist/runtime.js.map +1 -1
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -182,7 +182,7 @@ async function runCommand(command, flags) {
|
|
|
182
182
|
const setupPicked = await interactiveSelect("What next?", setupOptions);
|
|
183
183
|
if (setupPicked === "list") {
|
|
184
184
|
const { spawnSync: spSync } = await import("node:child_process");
|
|
185
|
-
const cliEntry =
|
|
185
|
+
const cliEntry = resolveCliEntry();
|
|
186
186
|
spSync(process.execPath, [cliEntry, "list"], { stdio: "inherit", cwd });
|
|
187
187
|
}
|
|
188
188
|
else if (setupPicked !== "done") {
|
|
@@ -190,7 +190,7 @@ async function runCommand(command, flags) {
|
|
|
190
190
|
const cmd = action === "sweep" ? "sweep" : "run";
|
|
191
191
|
console.log(`\nRunning: prompts-gpt ${cmd} -f ${file}\n`);
|
|
192
192
|
const { spawnSync: spSync } = await import("node:child_process");
|
|
193
|
-
const cliEntry =
|
|
193
|
+
const cliEntry = resolveCliEntry();
|
|
194
194
|
const setupResult = spSync(process.execPath, [cliEntry, cmd, "-f", file], { stdio: "inherit", cwd });
|
|
195
195
|
process.exitCode = setupResult.status ?? 1;
|
|
196
196
|
}
|
|
@@ -570,7 +570,7 @@ async function runCommand(command, flags) {
|
|
|
570
570
|
const cmd = action === "sweep" ? "sweep" : "run";
|
|
571
571
|
console.log(`\nRunning: prompts-gpt ${cmd} -f ${file}\n`);
|
|
572
572
|
const { spawnSync: spSync } = await import("node:child_process");
|
|
573
|
-
const cliEntry =
|
|
573
|
+
const cliEntry = resolveCliEntry();
|
|
574
574
|
const result = spSync(process.execPath, [cliEntry, cmd, "-f", file], { stdio: "inherit", cwd });
|
|
575
575
|
process.exitCode = result.status ?? 1;
|
|
576
576
|
}
|
|
@@ -752,23 +752,36 @@ async function runCommand(command, flags) {
|
|
|
752
752
|
}
|
|
753
753
|
const runProviders = await detectProviders(cwd);
|
|
754
754
|
const runAvailable = runProviders.filter((p) => p.available);
|
|
755
|
-
if (!getStringFlag(flags, "agent") &&
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
providerOpts.push({ label: "router (auto-select)", value: "router" });
|
|
762
|
-
if (lastRunProvider) {
|
|
763
|
-
const idx = providerOpts.findIndex((o) => o.value === lastRunProvider);
|
|
764
|
-
if (idx > 0) {
|
|
765
|
-
const [item] = providerOpts.splice(idx, 1);
|
|
766
|
-
providerOpts.unshift(item);
|
|
767
|
-
}
|
|
755
|
+
if (!getStringFlag(flags, "agent") && runAvailable.length === 0 && !isTTYInteractive(flags)) {
|
|
756
|
+
throw new CliError("No supported provider CLI found on PATH. Install Codex, Cursor Agent, Claude Code, or Copilot CLI.\nRun `prompts-gpt doctor` for details.", CLI_EXIT_CODES.validation, { helpCommand: "providers" });
|
|
757
|
+
}
|
|
758
|
+
if (!getStringFlag(flags, "agent") && isTTYInteractive(flags) && !Boolean(flags.json)) {
|
|
759
|
+
if (runAvailable.length === 0) {
|
|
760
|
+
throw new CliError("No supported provider CLI found on PATH. Install Codex, Cursor Agent, Claude Code, or Copilot CLI.\nRun `prompts-gpt doctor` for details.", CLI_EXIT_CODES.validation, { helpCommand: "providers" });
|
|
768
761
|
}
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
762
|
+
else if (runAvailable.length === 1) {
|
|
763
|
+
const only = runAvailable[0];
|
|
764
|
+
console.log(`Using provider: ${only.provider} (${only.modelDefault}${only.version ? `, ${only.version}` : ""})`);
|
|
765
|
+
flags.agent = only.provider;
|
|
766
|
+
}
|
|
767
|
+
else {
|
|
768
|
+
const lastRunProvider = await getLastUsedProvider(cwd);
|
|
769
|
+
const providerOpts = runAvailable.map((p) => ({
|
|
770
|
+
label: `${p.provider} (${p.modelDefault}${p.version ? `, ${p.version}` : ""})${p.provider === lastRunProvider ? " ★" : ""}`,
|
|
771
|
+
value: p.provider,
|
|
772
|
+
}));
|
|
773
|
+
providerOpts.push({ label: "router (auto-select)", value: "router" });
|
|
774
|
+
if (lastRunProvider) {
|
|
775
|
+
const idx = providerOpts.findIndex((o) => o.value === lastRunProvider);
|
|
776
|
+
if (idx > 0) {
|
|
777
|
+
const [item] = providerOpts.splice(idx, 1);
|
|
778
|
+
providerOpts.unshift(item);
|
|
779
|
+
}
|
|
780
|
+
}
|
|
781
|
+
flags.agent = await interactiveSelect("Select a provider:", providerOpts);
|
|
782
|
+
if (flags.agent !== "router") {
|
|
783
|
+
await saveLastUsedProvider(cwd, flags.agent);
|
|
784
|
+
}
|
|
772
785
|
}
|
|
773
786
|
}
|
|
774
787
|
if (!getStringFlag(flags, "model") && isTTYInteractive(flags) && !Boolean(flags.json)) {
|
|
@@ -891,13 +904,18 @@ async function runCommand(command, flags) {
|
|
|
891
904
|
}
|
|
892
905
|
catch { /* skip */ }
|
|
893
906
|
console.log("");
|
|
894
|
-
console.log(`View results:
|
|
907
|
+
console.log(`View results: ${viewFileCmd} ${result.summaryFile}`);
|
|
895
908
|
}
|
|
896
909
|
if (Boolean(flags.open) && result.summaryFile) {
|
|
897
910
|
try {
|
|
898
911
|
const { spawn: openSpawn } = await import("node:child_process");
|
|
899
|
-
|
|
900
|
-
|
|
912
|
+
if (process.platform === "win32") {
|
|
913
|
+
openSpawn("cmd", ["/c", "start", "", result.summaryFile], { detached: true, stdio: "ignore", windowsHide: true }).unref();
|
|
914
|
+
}
|
|
915
|
+
else {
|
|
916
|
+
const openCmd = process.platform === "darwin" ? "open" : "xdg-open";
|
|
917
|
+
openSpawn(openCmd, [result.summaryFile], { detached: true, stdio: "ignore" }).unref();
|
|
918
|
+
}
|
|
901
919
|
}
|
|
902
920
|
catch { /* ignore */ }
|
|
903
921
|
}
|
|
@@ -979,7 +997,12 @@ async function runCommand(command, flags) {
|
|
|
979
997
|
}
|
|
980
998
|
const providers = await detectProviders(cwd);
|
|
981
999
|
const availableProviders = providers.filter((p) => p.available);
|
|
982
|
-
if (availableProviders.length === 0
|
|
1000
|
+
if (availableProviders.length === 0) {
|
|
1001
|
+
if (Boolean(flags.json)) {
|
|
1002
|
+
console.log(JSON.stringify({ error: "no_providers", message: "No supported provider CLI was found on PATH." }, null, 2));
|
|
1003
|
+
process.exitCode = CLI_EXIT_CODES.validation;
|
|
1004
|
+
return;
|
|
1005
|
+
}
|
|
983
1006
|
throw new CliError("No supported provider CLI was found on PATH. Install Codex, Cursor Agent, Claude Code, or Copilot CLI, then run `prompts-gpt doctor`.", CLI_EXIT_CODES.validation, { helpCommand: "providers" });
|
|
984
1007
|
}
|
|
985
1008
|
if (!sweepPromptFile && !Boolean(flags.json)) {
|
|
@@ -1126,7 +1149,8 @@ async function runCommand(command, flags) {
|
|
|
1126
1149
|
`${formatDuration(iterTimeout * 1000)} per iteration`, `~${formatDuration(estMaxMs)}`,
|
|
1127
1150
|
String(maxRetries), tierBadge,
|
|
1128
1151
|
];
|
|
1129
|
-
const
|
|
1152
|
+
const stripEmoji = (s) => s.replace(/[\u{1F300}-\u{1F9FF}\u{2600}-\u{27BF}\u{2B50}]/gu, " ");
|
|
1153
|
+
const longestVal = Math.max(...boxValues.map((v) => stripEmoji(v).length), 30);
|
|
1130
1154
|
const innerW = longestVal + 16;
|
|
1131
1155
|
const uc = supportsColor();
|
|
1132
1156
|
const [TL, H, TR, V, ML, MR, BL, BR] = uc ? ["╔", "═", "╗", "║", "╠", "╣", "╚", "╝"] : ["+", "-", "+", "|", "+", "+", "+", "+"];
|
|
@@ -1375,13 +1399,18 @@ async function runCommand(command, flags) {
|
|
|
1375
1399
|
}
|
|
1376
1400
|
console.log("");
|
|
1377
1401
|
console.log("Inspect results:");
|
|
1378
|
-
console.log(`
|
|
1379
|
-
console.log(`
|
|
1402
|
+
console.log(` ${viewFileCmd} ${result.manifestFile}`);
|
|
1403
|
+
console.log(` ${listDirCmd} ${result.runDir}`);
|
|
1380
1404
|
if (Boolean(flags.open) && result.manifestFile) {
|
|
1381
1405
|
try {
|
|
1382
1406
|
const { spawn: openSpawn } = await import("node:child_process");
|
|
1383
|
-
|
|
1384
|
-
|
|
1407
|
+
if (process.platform === "win32") {
|
|
1408
|
+
openSpawn("cmd", ["/c", "start", "", result.manifestFile], { detached: true, stdio: "ignore", windowsHide: true }).unref();
|
|
1409
|
+
}
|
|
1410
|
+
else {
|
|
1411
|
+
const openCmd = process.platform === "darwin" ? "open" : "xdg-open";
|
|
1412
|
+
openSpawn(openCmd, [result.manifestFile], { detached: true, stdio: "ignore" }).unref();
|
|
1413
|
+
}
|
|
1385
1414
|
}
|
|
1386
1415
|
catch { /* ignore */ }
|
|
1387
1416
|
}
|
|
@@ -1542,7 +1571,7 @@ async function runCommand(command, flags) {
|
|
|
1542
1571
|
const cmd = action === "sweep" ? "sweep" : "run";
|
|
1543
1572
|
console.log(`\nRunning: prompts-gpt ${cmd} -f ${file}\n`);
|
|
1544
1573
|
const { spawnSync: spSync } = await import("node:child_process");
|
|
1545
|
-
const cliEntry =
|
|
1574
|
+
const cliEntry = resolveCliEntry();
|
|
1546
1575
|
const result = spSync(process.execPath, [cliEntry, cmd, "-f", file], { stdio: "inherit", cwd });
|
|
1547
1576
|
process.exitCode = result.status ?? 1;
|
|
1548
1577
|
return;
|
|
@@ -1680,7 +1709,7 @@ async function runCommand(command, flags) {
|
|
|
1680
1709
|
const runQs = await interactiveInput("Run quickstart now? [Y/n]", "Y");
|
|
1681
1710
|
if (runQs.toLowerCase() !== "n" && runQs.toLowerCase() !== "no") {
|
|
1682
1711
|
const { spawnSync: spSync } = await import("node:child_process");
|
|
1683
|
-
const cliEntry =
|
|
1712
|
+
const cliEntry = resolveCliEntry();
|
|
1684
1713
|
const qsResult = spSync(process.execPath, [cliEntry, "quickstart", "--cwd", cwd], { stdio: "inherit", cwd });
|
|
1685
1714
|
process.exitCode = qsResult.status ?? 1;
|
|
1686
1715
|
return;
|
|
@@ -1788,7 +1817,7 @@ async function runCommand(command, flags) {
|
|
|
1788
1817
|
if (runNow.toLowerCase() !== "n" && runNow.toLowerCase() !== "no") {
|
|
1789
1818
|
console.log(`\nRunning: prompts-gpt run -f ${genFile}\n`);
|
|
1790
1819
|
const { spawnSync: spSync } = await import("node:child_process");
|
|
1791
|
-
const cliEntry =
|
|
1820
|
+
const cliEntry = resolveCliEntry();
|
|
1792
1821
|
const genResult = spSync(process.execPath, [cliEntry, "run", "-f", genFile], { stdio: "inherit", cwd });
|
|
1793
1822
|
process.exitCode = genResult.status ?? 1;
|
|
1794
1823
|
}
|
|
@@ -1911,7 +1940,7 @@ async function runCommand(command, flags) {
|
|
|
1911
1940
|
if (syncNow.toLowerCase() !== "n" && syncNow.toLowerCase() !== "no") {
|
|
1912
1941
|
console.log("\nSyncing...");
|
|
1913
1942
|
const { spawnSync: spSync } = await import("node:child_process");
|
|
1914
|
-
const cliEntry =
|
|
1943
|
+
const cliEntry = resolveCliEntry();
|
|
1915
1944
|
const projCwd = getResolvedCwd(flags);
|
|
1916
1945
|
const syncResult = spSync(process.execPath, [cliEntry, "sync", "--cwd", projCwd], { stdio: "inherit", cwd: projCwd });
|
|
1917
1946
|
process.exitCode = syncResult.status ?? 1;
|
|
@@ -2656,7 +2685,7 @@ async function getLastUsedModel(cwd, provider) {
|
|
|
2656
2685
|
}
|
|
2657
2686
|
async function saveLastUsedModel(cwd, provider, model) {
|
|
2658
2687
|
try {
|
|
2659
|
-
const { readFile: fsRead, writeFile: fsWrite, mkdir: fsMkdir
|
|
2688
|
+
const { readFile: fsRead, writeFile: fsWrite, mkdir: fsMkdir } = await import("node:fs/promises");
|
|
2660
2689
|
const dir = path.resolve(cwd, DEFAULT_PROMPTS_GPT_OUT_DIR);
|
|
2661
2690
|
await fsMkdir(dir, { recursive: true });
|
|
2662
2691
|
const filePath = path.resolve(dir, ".last-models");
|
|
@@ -2666,9 +2695,7 @@ async function saveLastUsedModel(cwd, provider, model) {
|
|
|
2666
2695
|
}
|
|
2667
2696
|
catch { /* new file */ }
|
|
2668
2697
|
existing[provider] = model;
|
|
2669
|
-
|
|
2670
|
-
await fsWrite(tmpPath, JSON.stringify(existing, null, 2));
|
|
2671
|
-
await rename(tmpPath, filePath);
|
|
2698
|
+
await fsWrite(filePath, JSON.stringify(existing, null, 2));
|
|
2672
2699
|
}
|
|
2673
2700
|
catch { /* ignore */ }
|
|
2674
2701
|
}
|
|
@@ -3279,6 +3306,19 @@ function supportsColor() {
|
|
|
3279
3306
|
function colorize(text, code) {
|
|
3280
3307
|
return supportsColor() ? `${code}${text}\x1b[0m` : text;
|
|
3281
3308
|
}
|
|
3309
|
+
const viewFileCmd = process.platform === "win32" ? "type" : "cat";
|
|
3310
|
+
const listDirCmd = process.platform === "win32" ? "dir" : "ls";
|
|
3311
|
+
function resolveCliEntry() {
|
|
3312
|
+
if (process.argv[1])
|
|
3313
|
+
return process.argv[1];
|
|
3314
|
+
try {
|
|
3315
|
+
const { fileURLToPath } = require("node:url");
|
|
3316
|
+
return fileURLToPath(import.meta.url);
|
|
3317
|
+
}
|
|
3318
|
+
catch {
|
|
3319
|
+
return "cli.js";
|
|
3320
|
+
}
|
|
3321
|
+
}
|
|
3282
3322
|
function isTTYInteractive(flags) {
|
|
3283
3323
|
if (!process.stdin.isTTY || !process.stdout.isTTY)
|
|
3284
3324
|
return false;
|
|
@@ -3291,7 +3331,7 @@ function isTTYInteractive(flags) {
|
|
|
3291
3331
|
return false;
|
|
3292
3332
|
if (process.env.PROMPTS_GPT_NON_INTERACTIVE === "1" || process.env.PROMPTS_GPT_NON_INTERACTIVE === "true")
|
|
3293
3333
|
return false;
|
|
3294
|
-
if (process.env.POWERSHELL_ISE === "1"
|
|
3334
|
+
if (process.env.POWERSHELL_ISE === "1")
|
|
3295
3335
|
return false;
|
|
3296
3336
|
return true;
|
|
3297
3337
|
}
|
|
@@ -3339,7 +3379,7 @@ function interactiveSelect(prompt, options) {
|
|
|
3339
3379
|
}
|
|
3340
3380
|
stdout.write(`${hints}\n`);
|
|
3341
3381
|
};
|
|
3342
|
-
const supportsAnsiCursor = supportsColor() || (process.platform === "win32" && Boolean(process.env.WT_SESSION));
|
|
3382
|
+
const supportsAnsiCursor = supportsColor() || (process.platform === "win32" && Boolean(process.env.WT_SESSION || process.env.TERM_PROGRAM || process.env.ConEmuANSI));
|
|
3343
3383
|
const render = () => {
|
|
3344
3384
|
const visibleCount = Math.min(maxVisible, options.length);
|
|
3345
3385
|
const footerLines = 1 + (options.length > maxVisible ? 1 : 0) + 1;
|
|
@@ -3348,7 +3388,8 @@ function interactiveSelect(prompt, options) {
|
|
|
3348
3388
|
stdout.write(`\x1b[${lines}A\x1b[J`);
|
|
3349
3389
|
}
|
|
3350
3390
|
else {
|
|
3351
|
-
|
|
3391
|
+
for (let i = 0; i < lines; i++)
|
|
3392
|
+
stdout.write("\x1b[A\x1b[2K");
|
|
3352
3393
|
}
|
|
3353
3394
|
const posLabel = options.length > 1 ? ` (${cursor + 1}/${options.length})` : "";
|
|
3354
3395
|
const filterLabel = filterText ? colorize(` filter: "${filterText}"`, "\x1b[33m") : "";
|
|
@@ -3678,7 +3719,7 @@ async function extractRunDiagnostics(logFile, provider, model) {
|
|
|
3678
3719
|
}
|
|
3679
3720
|
if (diagnostics.length === 0) {
|
|
3680
3721
|
diagnostics.push(`${provider} exited with code 1. Check the log for details:`);
|
|
3681
|
-
diagnostics.push(`
|
|
3722
|
+
diagnostics.push(` ${viewFileCmd} ${logFile}`);
|
|
3682
3723
|
diagnostics.push(`Try a different provider: prompts-gpt run --agent claude`);
|
|
3683
3724
|
}
|
|
3684
3725
|
}
|