sharkcode 0.3.1 → 0.3.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.
Files changed (2) hide show
  1. package/dist/cli.mjs +83 -24
  2. package/package.json +1 -1
package/dist/cli.mjs CHANGED
@@ -2,7 +2,6 @@
2
2
 
3
3
  // src/cli.ts
4
4
  import chalk3 from "chalk";
5
- import * as readline2 from "readline";
6
5
  import { select, input } from "@inquirer/prompts";
7
6
 
8
7
  // src/config.ts
@@ -200,23 +199,22 @@ import { z as z4 } from "zod";
200
199
  import { exec } from "child_process";
201
200
 
202
201
  // src/permission.ts
203
- import * as readline from "readline";
204
202
  import chalk from "chalk";
205
203
  async function askPermission(command) {
206
204
  process.stderr.write(
207
205
  chalk.yellow(`
208
206
  \u26A0\uFE0F Will execute: `) + chalk.white(command) + "\n"
209
207
  );
210
- const rl = readline.createInterface({
211
- input: process.stdin,
212
- output: process.stderr
213
- });
208
+ process.stderr.write(chalk.yellow(" Allow? [y/N] "));
214
209
  return new Promise((resolve4) => {
215
- rl.question(chalk.yellow(" Allow? [y/N] "), (answer) => {
216
- rl.close();
217
- const yes = answer.trim().toLowerCase();
218
- resolve4(yes === "y" || yes === "yes");
219
- });
210
+ const onData = (chunk) => {
211
+ const ch = chunk.toString("utf8")[0] ?? "";
212
+ process.stdin.removeListener("data", onData);
213
+ const yes = ch.toLowerCase() === "y";
214
+ process.stderr.write(yes ? "y\n" : "N\n");
215
+ resolve4(yes);
216
+ };
217
+ process.stdin.once("data", onData);
220
218
  });
221
219
  }
222
220
 
@@ -513,18 +511,52 @@ async function showSetupFlow(multiConfig) {
513
511
  return { multiConfig, config: resolveConfig(multiConfig) };
514
512
  }
515
513
  }
516
- async function readLine(prompt) {
514
+ async function readLineRaw(promptStr) {
515
+ process.stdout.write(promptStr);
517
516
  return new Promise((resolve4) => {
518
- const rl = readline2.createInterface({ input: process.stdin, output: process.stdout });
519
- let answered = false;
520
- rl.question(prompt, (answer) => {
521
- answered = true;
522
- rl.close();
523
- resolve4(answer);
524
- });
525
- rl.on("close", () => {
526
- if (!answered) resolve4(null);
527
- });
517
+ let buffer = "";
518
+ let finished = false;
519
+ const finish = (value) => {
520
+ if (finished) return;
521
+ finished = true;
522
+ process.stdin.removeListener("data", onData);
523
+ resolve4(value);
524
+ };
525
+ const onData = (chunk) => {
526
+ const str = chunk.toString("utf8");
527
+ if (str.startsWith("\x1B")) return;
528
+ for (const ch of str) {
529
+ const code = ch.codePointAt(0);
530
+ if (code === 3 || code === 4) {
531
+ process.stdout.write("\n");
532
+ finish(null);
533
+ return;
534
+ }
535
+ if (code === 13 || code === 10) {
536
+ process.stdout.write("\n");
537
+ finish(buffer);
538
+ return;
539
+ }
540
+ if (code === 127 || code === 8) {
541
+ if (buffer.length > 0) {
542
+ const chars = [...buffer];
543
+ chars.pop();
544
+ buffer = chars.join("");
545
+ process.stdout.write("\b \b");
546
+ }
547
+ continue;
548
+ }
549
+ if (code < 32) continue;
550
+ if (ch === "/" && buffer === "") {
551
+ process.stdout.write("\n");
552
+ finish("/");
553
+ return;
554
+ }
555
+ buffer += ch;
556
+ process.stdout.write(ch);
557
+ }
558
+ };
559
+ process.stdin.on("data", onData);
528
560
  });
529
561
  }
530
562
  function statusLine(config) {
@@ -542,7 +574,7 @@ async function main() {
542
574
  return;
543
575
  }
544
576
  if (args[0] === "--version" || args[0] === "-v") {
545
- console.log("sharkcode v0.3.1");
577
+ console.log("sharkcode v0.3.3");
546
578
  return;
547
579
  }
548
580
  if (args.length > 0) {
@@ -562,6 +594,11 @@ async function main() {
562
594
  console.log(BANNER);
563
595
  let multiConfig = readMultiConfig();
564
596
  let config = resolveConfig(multiConfig);
597
+ try {
598
+ process.stdin.setRawMode(true);
599
+ process.stdin.resume();
600
+ } catch {
601
+ }
565
602
  console.log(statusLine(config));
566
603
  if (!config.apiKey) {
567
604
  console.log(
@@ -570,7 +607,7 @@ async function main() {
570
607
  }
571
608
  let messages = [];
572
609
  while (true) {
573
- const raw = await readLine(PURPLE2("\n\u25C6 "));
610
+ const raw = await readLineRaw(PURPLE2("\n\u25C6 "));
574
611
  if (raw === null) {
575
612
  console.log(GRAY("\nBye! \u{1F988}"));
576
613
  break;
@@ -587,6 +624,12 @@ async function main() {
587
624
  config = r.config;
588
625
  if (r.clearHistory) messages = [];
589
626
  if (r.exit) break;
627
+ try {
628
+ process.stdin.setRawMode(true);
629
+ process.stdin.resume();
630
+ } catch {
631
+ }
632
+ console.log(statusLine(config));
590
633
  continue;
591
634
  }
592
635
  if (trimmed === "/provider" || trimmed.startsWith("/provider ") || trimmed === "/model" || trimmed.startsWith("/model ") || trimmed === "/key" || trimmed.startsWith("/key ")) {
@@ -594,6 +637,12 @@ async function main() {
594
637
  multiConfig = r.multiConfig;
595
638
  config = r.config;
596
639
  if (r.exit) break;
640
+ try {
641
+ process.stdin.setRawMode(true);
642
+ process.stdin.resume();
643
+ } catch {
644
+ }
645
+ console.log(statusLine(config));
597
646
  continue;
598
647
  }
599
648
  if (trimmed.startsWith("/")) {
@@ -607,11 +656,21 @@ async function main() {
607
656
  messages.push({ role: "user", content: trimmed });
608
657
  try {
609
658
  messages = await runAgent(messages, config);
659
+ try {
660
+ process.stdin.setRawMode(true);
661
+ process.stdin.resume();
662
+ } catch {
663
+ }
610
664
  } catch (err) {
611
665
  console.error(RED(`
612
666
  \u274C ${String(err)}
613
667
  `));
614
668
  messages.pop();
669
+ try {
670
+ process.stdin.setRawMode(true);
671
+ process.stdin.resume();
672
+ } catch {
673
+ }
615
674
  }
616
675
  }
617
676
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sharkcode",
3
- "version": "0.3.1",
3
+ "version": "0.3.3",
4
4
  "description": "Local First, open-source AI Coding Agent",
5
5
  "type": "module",
6
6
  "bin": {