@semalt-ai/code 1.4.2 → 1.4.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/index.js +49 -6
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -110,6 +110,51 @@ function boxLine(text, width) {
110
110
  let AUTO_APPROVE_SHELL = false;
111
111
  let AUTO_APPROVE_FILE = false;
112
112
 
113
+ function askPermissionLine(actionType) {
114
+ return actionType === 'shell'
115
+ ? ' 1. Yes 2. Yes, always for shell 3. No'
116
+ : ' 1. Yes 2. Yes, always for files 3. No';
117
+ }
118
+
119
+ function readPermissionChoice() {
120
+ return new Promise((resolve) => {
121
+ if (!process.stdin.isTTY) {
122
+ const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
123
+ rl.question(` ${FG_YELLOW}?${RST} `, (answer) => {
124
+ rl.close();
125
+ resolve((answer || '').trim());
126
+ });
127
+ return;
128
+ }
129
+
130
+ const wasRaw = typeof process.stdin.isRaw === 'boolean' ? process.stdin.isRaw : false;
131
+ readline.emitKeypressEvents(process.stdin);
132
+ process.stdin.setRawMode(true);
133
+ process.stdin.resume();
134
+ process.stdout.write(` ${FG_YELLOW}?${RST} `);
135
+
136
+ const onKeypress = (str, key = {}) => {
137
+ if (key.ctrl && key.name === 'c') {
138
+ process.stdin.setRawMode(wasRaw);
139
+ process.stdin.removeListener('keypress', onKeypress);
140
+ process.stdout.write('^C\n');
141
+ process.kill(process.pid, 'SIGINT');
142
+ return;
143
+ }
144
+
145
+ const value = (str || '').trim();
146
+ if (!value) return;
147
+
148
+ process.stdin.setRawMode(wasRaw);
149
+ process.stdin.removeListener('keypress', onKeypress);
150
+ process.stdout.write(`${value}\n`);
151
+ resolve(value);
152
+ };
153
+
154
+ process.stdin.on('keypress', onKeypress);
155
+ });
156
+ }
157
+
113
158
  function askPermission(actionType, description) {
114
159
  return new Promise((resolve) => {
115
160
  if (actionType === 'shell' && AUTO_APPROVE_SHELL) {
@@ -125,16 +170,14 @@ function askPermission(actionType, description) {
125
170
  console.log(` ${FG_YELLOW}${BOLD}⚠ Permission required${RST}`);
126
171
  console.log(` ${FG_GRAY}${actionType}: ${description}${RST}`);
127
172
  console.log();
128
- console.log(` ${FG_CYAN}[y]${RST} Yes ${FG_CYAN}[a]${RST} Yes, always ${FG_CYAN}[n]${RST} No`);
173
+ console.log(` ${FG_CYAN}${askPermissionLine(actionType)}${RST}`);
129
174
  console.log();
130
175
 
131
- const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
132
- rl.question(` ${FG_YELLOW}?${RST} `, (answer) => {
133
- rl.close();
176
+ readPermissionChoice().then((answer) => {
134
177
  const choice = (answer || '').trim().toLowerCase();
135
- if (choice === 'y' || choice === 'yes') {
178
+ if (choice === '1' || choice === 'y' || choice === 'yes') {
136
179
  resolve(true);
137
- } else if (choice === 'a' || choice === 'always') {
180
+ } else if (choice === '2' || choice === 'a' || choice === 'always') {
138
181
  if (actionType === 'shell') AUTO_APPROVE_SHELL = true;
139
182
  else AUTO_APPROVE_FILE = true;
140
183
  console.log(` ${FG_GREEN}✓${RST} ${FG_DARK}Auto-approve enabled for ${actionType} operations${RST}`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@semalt-ai/code",
3
- "version": "1.4.2",
3
+ "version": "1.4.3",
4
4
  "description": "Self-hosted AI Coding Assistant CLI",
5
5
  "main": "index.js",
6
6
  "bin": {