sharkcode 0.3.2 → 0.3.4

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 +51 -36
  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,6 +511,18 @@ async function showSetupFlow(multiConfig) {
513
511
  return { multiConfig, config: resolveConfig(multiConfig) };
514
512
  }
515
513
  }
514
+ function charDisplayWidth(ch) {
515
+ const cp = ch.codePointAt(0);
516
+ if (cp >= 4352 && cp <= 4447 || // Hangul Jamo
517
+ cp >= 11904 && cp <= 12350 || // CJK Radicals Supplement, Kangxi, etc.
518
+ cp >= 12353 && cp <= 13311 || // Hiragana, Katakana, CJK Symbols
519
+ cp >= 13312 && cp <= 40959 || // CJK Unified Ideographs (+ Ext A)
520
+ cp >= 44032 && cp <= 55215 || // Hangul Syllables
521
+ cp >= 63744 && cp <= 64255 || // CJK Compatibility Ideographs
522
+ cp >= 65281 && cp <= 65376 || // Fullwidth Latin / Punctuation
523
+ cp >= 65504 && cp <= 65510) return 2;
524
+ return 1;
525
+ }
516
526
  async function readLineRaw(promptStr) {
517
527
  process.stdout.write(promptStr);
518
528
  return new Promise((resolve4) => {
@@ -522,11 +532,6 @@ async function readLineRaw(promptStr) {
522
532
  if (finished) return;
523
533
  finished = true;
524
534
  process.stdin.removeListener("data", onData);
525
- try {
526
- process.stdin.setRawMode(false);
527
- } catch {
528
- }
529
- process.stdin.pause();
530
535
  resolve4(value);
531
536
  };
532
537
  const onData = (chunk) => {
@@ -547,9 +552,10 @@ async function readLineRaw(promptStr) {
547
552
  if (code === 127 || code === 8) {
548
553
  if (buffer.length > 0) {
549
554
  const chars = [...buffer];
550
- chars.pop();
555
+ const removed = chars.pop();
551
556
  buffer = chars.join("");
552
- process.stdout.write("\b \b");
557
+ const w = charDisplayWidth(removed);
558
+ process.stdout.write("\b".repeat(w) + " ".repeat(w) + "\b".repeat(w));
553
559
  }
554
560
  continue;
555
561
  }
@@ -563,23 +569,7 @@ async function readLineRaw(promptStr) {
563
569
  process.stdout.write(ch);
564
570
  }
565
571
  };
566
- try {
567
- process.stdin.setRawMode(true);
568
- process.stdin.resume();
569
- process.stdin.on("data", onData);
570
- } catch {
571
- finished = true;
572
- const rl = readline2.createInterface({ input: process.stdin, output: process.stdout });
573
- let answered = false;
574
- rl.question(promptStr, (answer) => {
575
- answered = true;
576
- rl.close();
577
- resolve4(answer);
578
- });
579
- rl.on("close", () => {
580
- if (!answered) resolve4(null);
581
- });
582
- }
572
+ process.stdin.on("data", onData);
583
573
  });
584
574
  }
585
575
  function statusLine(config) {
@@ -597,7 +587,7 @@ async function main() {
597
587
  return;
598
588
  }
599
589
  if (args[0] === "--version" || args[0] === "-v") {
600
- console.log("sharkcode v0.3.2");
590
+ console.log("sharkcode v0.3.4");
601
591
  return;
602
592
  }
603
593
  if (args.length > 0) {
@@ -617,6 +607,11 @@ async function main() {
617
607
  console.log(BANNER);
618
608
  let multiConfig = readMultiConfig();
619
609
  let config = resolveConfig(multiConfig);
610
+ try {
611
+ process.stdin.setRawMode(true);
612
+ process.stdin.resume();
613
+ } catch {
614
+ }
620
615
  console.log(statusLine(config));
621
616
  if (!config.apiKey) {
622
617
  console.log(
@@ -642,6 +637,11 @@ async function main() {
642
637
  config = r.config;
643
638
  if (r.clearHistory) messages = [];
644
639
  if (r.exit) break;
640
+ try {
641
+ process.stdin.setRawMode(true);
642
+ process.stdin.resume();
643
+ } catch {
644
+ }
645
645
  console.log(statusLine(config));
646
646
  continue;
647
647
  }
@@ -650,6 +650,11 @@ async function main() {
650
650
  multiConfig = r.multiConfig;
651
651
  config = r.config;
652
652
  if (r.exit) break;
653
+ try {
654
+ process.stdin.setRawMode(true);
655
+ process.stdin.resume();
656
+ } catch {
657
+ }
653
658
  console.log(statusLine(config));
654
659
  continue;
655
660
  }
@@ -664,11 +669,21 @@ async function main() {
664
669
  messages.push({ role: "user", content: trimmed });
665
670
  try {
666
671
  messages = await runAgent(messages, config);
672
+ try {
673
+ process.stdin.setRawMode(true);
674
+ process.stdin.resume();
675
+ } catch {
676
+ }
667
677
  } catch (err) {
668
678
  console.error(RED(`
669
679
  \u274C ${String(err)}
670
680
  `));
671
681
  messages.pop();
682
+ try {
683
+ process.stdin.setRawMode(true);
684
+ process.stdin.resume();
685
+ } catch {
686
+ }
672
687
  }
673
688
  }
674
689
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sharkcode",
3
- "version": "0.3.2",
3
+ "version": "0.3.4",
4
4
  "description": "Local First, open-source AI Coding Agent",
5
5
  "type": "module",
6
6
  "bin": {