lovecode-ai 0.1.8 → 0.1.9

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/index.js +70 -53
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -4991,7 +4991,10 @@ configCommand.action(cmdShow);
4991
4991
  // src/commands/env.ts
4992
4992
  import { Command as Command5 } from "commander";
4993
4993
  import chalk25 from "chalk";
4994
- import inquirer from "inquirer";
4994
+
4995
+ // src/utils/select.ts
4996
+ import * as readline5 from "readline";
4997
+ import chalk24 from "chalk";
4995
4998
 
4996
4999
  // src/platform/detect.ts
4997
5000
  import * as fs17 from "fs";
@@ -5053,8 +5056,32 @@ function platformInfo() {
5053
5056
  }
5054
5057
 
5055
5058
  // src/utils/select.ts
5056
- import * as readline5 from "readline";
5057
- import chalk24 from "chalk";
5059
+ function createRL() {
5060
+ try {
5061
+ return readline5.createInterface({ input: process.stdin, output: process.stdout });
5062
+ } catch {
5063
+ return null;
5064
+ }
5065
+ }
5066
+ function askQuestion(rl, query) {
5067
+ return new Promise((resolve5) => {
5068
+ try {
5069
+ rl.question(query, (answer) => {
5070
+ try {
5071
+ rl.close();
5072
+ } catch {
5073
+ }
5074
+ resolve5(answer);
5075
+ });
5076
+ } catch {
5077
+ try {
5078
+ rl.close();
5079
+ } catch {
5080
+ }
5081
+ resolve5("");
5082
+ }
5083
+ });
5084
+ }
5058
5085
  async function numberedSelect(choices, options) {
5059
5086
  const termux = options?.termux ?? isTermux();
5060
5087
  const pageSize = options?.pageSize || 15;
@@ -5064,44 +5091,42 @@ async function numberedSelect(choices, options) {
5064
5091
  `);
5065
5092
  const display = choices.slice(0, pageSize);
5066
5093
  for (let i = 0; i < display.length; i++) {
5067
- const num = chalk24.cyan(`${i + 1}`.padStart(3));
5094
+ const num2 = chalk24.cyan(`${i + 1}`.padStart(3));
5068
5095
  const desc = display[i].description ? chalk24.dim(` \u2014 ${display[i].description}`) : "";
5069
- console.log(` ${num}. ${display[i].name}${desc}`);
5096
+ console.log(` ${num2}. ${display[i].name}${desc}`);
5070
5097
  }
5071
5098
  if (choices.length > pageSize) {
5072
5099
  console.log(` ${chalk24.dim(`... and ${choices.length - pageSize} more. Use \`lovecode env set\` directly.`)}`);
5073
5100
  }
5074
- const rl = readline5.createInterface({ input: process.stdin, output: process.stdout });
5075
- return new Promise((resolve5) => {
5076
- const prompt = termux ? `
5101
+ const rl = createRL();
5102
+ if (!rl) {
5103
+ console.log(chalk24.yellow("\nCannot open input. Use `lovecode env set <KEY> <VALUE>` instead."));
5104
+ return "";
5105
+ }
5106
+ const prompt = termux ? `
5077
5107
  ${chalk24.cyan("?")} Enter number (1-${display.length}): ` : `
5078
5108
  ${chalk24.cyan("?")} Enter number (1-${display.length}), or press Enter for 1: `;
5079
- rl.question(prompt, (answer) => {
5080
- rl.close();
5081
- const trimmed = answer.trim();
5082
- if (!trimmed && !termux) {
5083
- resolve5(display[0].value);
5084
- return;
5085
- }
5086
- const num = parseInt(trimmed, 10);
5087
- if (isNaN(num) || num < 1 || num > display.length) {
5088
- console.log(chalk24.red(` Invalid selection. Please enter a number between 1 and ${display.length}.`));
5089
- resolve5(numberedSelect(choices, options));
5090
- return;
5091
- }
5092
- resolve5(display[num - 1].value);
5093
- });
5094
- });
5109
+ const answer = await askQuestion(rl, prompt);
5110
+ const trimmed = answer.trim();
5111
+ if (!trimmed && !termux) {
5112
+ return display[0].value;
5113
+ }
5114
+ const num = parseInt(trimmed, 10);
5115
+ if (isNaN(num) || num < 1 || num > display.length) {
5116
+ console.log(chalk24.red(` Invalid selection. Please enter a number between 1 and ${display.length}.`));
5117
+ return numberedSelect(choices, options);
5118
+ }
5119
+ return display[num - 1].value;
5095
5120
  }
5096
- async function promptInput(question, defaultValue) {
5097
- const rl = readline5.createInterface({ input: process.stdin, output: process.stdout });
5098
- const prompt = defaultValue ? ` ${chalk24.cyan("?")} ${question} ${chalk24.dim(`(${defaultValue})`)}: ` : ` ${chalk24.cyan("?")} ${question}: `;
5099
- return new Promise((resolve5) => {
5100
- rl.question(prompt, (answer) => {
5101
- rl.close();
5102
- resolve5(answer.trim() || defaultValue || "");
5103
- });
5104
- });
5121
+ async function promptInput(q, defaultValue) {
5122
+ const rl = createRL();
5123
+ if (!rl) {
5124
+ console.log(chalk24.yellow("\nCannot open input. Using default value."));
5125
+ return defaultValue || "";
5126
+ }
5127
+ const prompt = defaultValue ? ` ${chalk24.cyan("?")} ${q} ${chalk24.dim(`(${defaultValue})`)}: ` : ` ${chalk24.cyan("?")} ${q}: `;
5128
+ const answer = await askQuestion(rl, prompt);
5129
+ return answer.trim() || defaultValue || "";
5105
5130
  }
5106
5131
 
5107
5132
  // src/commands/env.ts
@@ -5122,6 +5147,10 @@ async function cmdEnvUnset(key, options) {
5122
5147
  console.log(chalk25.yellow(`Unset ${key.toUpperCase()}`));
5123
5148
  }
5124
5149
  async function cmdEnvSelect(options) {
5150
+ if (!process.stdin.isTTY) {
5151
+ console.log(chalk25.yellow("Interactive mode requires a TTY. Use `lovecode env set <KEY> <VALUE>` instead."));
5152
+ return;
5153
+ }
5125
5154
  const vars = loadEnv(options.dir);
5126
5155
  const choices = KNOWN_ENV_VARS.map((v) => {
5127
5156
  const current = vars[v.key] || process.env[v.key] || "";
@@ -5133,36 +5162,24 @@ async function cmdEnvSelect(options) {
5133
5162
  description: masked ? `${v.description} (${masked})` : v.description
5134
5163
  };
5135
5164
  });
5136
- const useTermuxStyle = isTermux() || isTouchDevice();
5137
5165
  let key;
5138
- if (useTermuxStyle) {
5166
+ try {
5139
5167
  key = await numberedSelect(choices, {
5140
5168
  message: "Select an environment variable to set:",
5141
5169
  termux: true
5142
5170
  });
5143
- } else {
5144
- const result = await inquirer.prompt([{
5145
- type: "list",
5146
- name: "key",
5147
- message: "Select an environment variable to set:",
5148
- choices: choices.map((c) => ({ name: c.name, value: c.value })),
5149
- pageSize: 15
5150
- }]);
5151
- key = result.key;
5171
+ } catch {
5172
+ console.log(chalk25.yellow("\nInteractive selection unavailable. Use `lovecode env set <KEY> <VALUE>` instead."));
5173
+ return;
5152
5174
  }
5153
5175
  const existing = vars[key] || "";
5154
5176
  const description = KNOWN_ENV_VARS.find((v) => v.key === key)?.description || "";
5155
5177
  let value;
5156
- if (useTermuxStyle) {
5178
+ try {
5157
5179
  value = await promptInput(`Enter value for ${key} (${description})`, existing || void 0);
5158
- } else {
5159
- const result = await inquirer.prompt([{
5160
- type: "input",
5161
- name: "value",
5162
- message: `Enter value for ${chalk25.cyan(key)} (${description}):`,
5163
- default: existing || void 0
5164
- }]);
5165
- value = result.value;
5180
+ } catch {
5181
+ console.log(chalk25.yellow("\nInput unavailable. Use `lovecode env set <KEY> <VALUE>` instead."));
5182
+ return;
5166
5183
  }
5167
5184
  if (!value) {
5168
5185
  console.log(chalk25.yellow("\nNo value entered. Skipping."));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lovecode-ai",
3
- "version": "0.1.8",
3
+ "version": "0.1.9",
4
4
  "description": "Terminal-native autonomous coding agent powered by free AI models",
5
5
  "keywords": [
6
6
  "ai",