termux-dev 1.4.7 → 1.4.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.
package/assets/banner.svg CHANGED
@@ -25,7 +25,7 @@
25
25
 
26
26
  <!-- Tagline & Badge -->
27
27
  <text x="425" y="142" font-family="system-ui, -apple-system, sans-serif" font-size="14" font-weight="600" fill="#8b949e" text-anchor="middle" letter-spacing="3">
28
- THE TERMINAL-NATIVE AI CODING AGENT <tspan fill="#00f2fe" font-weight="bold">v1.4.7</tspan>
28
+ THE TERMINAL-NATIVE AI CODING AGENT <tspan fill="#00f2fe" font-weight="bold">v1.4.9</tspan>
29
29
  </text>
30
30
 
31
31
  <!-- Top Accent Line -->
@@ -18,7 +18,7 @@ async function pingUrl(url) {
18
18
  const req = https.get(url, {
19
19
  timeout: 3000,
20
20
  headers: {
21
- 'User-Agent': 'devx-doctor/1.4.7'
21
+ 'User-Agent': 'devx-doctor/1.4.9'
22
22
  }
23
23
  }, (res) => {
24
24
  res.resume(); // consume response data to free up memory and release socket
@@ -35,7 +35,7 @@ export async function runHeadlessMode(userPrompt, config, options = {}) {
35
35
  });
36
36
  try {
37
37
  if (!isQuiet && !isJson) {
38
- console.log(pc.bold(pc.cyan(`⚡ devx v1.4.7 (headless) | ${planMode ? 'PLAN' : 'AGENT'} | ${config.model}`)));
38
+ console.log(pc.bold(pc.cyan(`⚡ devx v1.4.9 (headless) | ${planMode ? 'PLAN' : 'AGENT'} | ${config.model}`)));
39
39
  console.log(pc.dim(`Task: ${userPrompt}\n`));
40
40
  }
41
41
  for await (const event of agent.run(abortController.signal)) {
package/dist/cli/index.js CHANGED
@@ -484,7 +484,7 @@ function drawLogo() {
484
484
  theme.colorFn(' █▀▀▄ █▀▀▀ █ █ █ █'),
485
485
  theme.colorFn(' █ █ █▀▀▀ ▀▄▀ ▀▄▀ '),
486
486
  theme.colorFn(' █▄▄▀ █▄▄▄ ▀ ▀ ▀ '),
487
- ' ' + theme.boldFn('v1.4.7'),
487
+ ' ' + theme.boldFn('v1.4.9'),
488
488
  ''
489
489
  ];
490
490
  for (const line of logo) {
@@ -499,7 +499,7 @@ function drawLogo() {
499
499
  indent + theme.colorFn('▀▀▀█▀▀▀ █▀▀▀ █▀▀█ █▄ ▄█ █ █ ▀▄ ▄▀ █▀▀▄ █▀▀▀ █ █'),
500
500
  indent + theme.colorFn(' █ █▀▀▀ █▄▄▀ █ █ █ █ █ █ ▀▀ █ █ █▀▀▀ █ █'),
501
501
  indent + theme.colorFn(' █ █▄▄▄ █ ▀▄ █ █ ▀▄▄▀ ▄▀ ▀▄ █▄▄▀ █▄▄▄ ▀▄▀ '),
502
- indent + theme.boldFn('v1.4.7'),
502
+ indent + theme.boldFn('v1.4.9'),
503
503
  ''
504
504
  ];
505
505
  for (const line of logo) {
@@ -645,7 +645,7 @@ async function handleSettings(config) {
645
645
  const maxIterLabel = maxIter >= 9999 ? 'Unlimited' : `${maxIter} steps`;
646
646
  const currentTh = getCurrentTheme();
647
647
  const choice = await select({
648
- message: `${pc.bold('⚙️ Settings')} ${pc.dim(`(devx v1.4.7 • theme: ${currentTh.name})`)}`,
648
+ message: `${pc.bold('⚙️ Settings')} ${pc.dim(`(devx v1.4.9 • theme: ${currentTh.name})`)}`,
649
649
  choices: [
650
650
  {
651
651
  name: `🎨 Color Theme: ${currentTh.emoji} ${currentTh.name}`,
@@ -686,7 +686,7 @@ async function handleSettings(config) {
686
686
  description: 'Limit how many tool steps (file edits, terminal commands) agent can do per request'
687
687
  },
688
688
  {
689
- name: `${currentTh.colorFn('✨ About devx')} ${pc.dim('(v1.4.7 by ApvCode)')}`,
689
+ name: `${currentTh.colorFn('✨ About devx')} ${pc.dim('(v1.4.9 by ApvCode)')}`,
690
690
  value: 'about',
691
691
  description: 'Terminal-Native AI Coding Agent created by ApvCode (https://github.com/apvcode/Termux-Dev)'
692
692
  },
@@ -702,7 +702,7 @@ async function handleSettings(config) {
702
702
  continue;
703
703
  }
704
704
  if (choice === 'about') {
705
- p.note(`⚡ devx v1.4.7 — Terminal-Native AI Coding Agent\n` +
705
+ p.note(`⚡ devx v1.4.9 — Terminal-Native AI Coding Agent\n` +
706
706
  `🎨 Theme: ${currentTh.emoji} ${currentTh.name}\n` +
707
707
  `👤 Author: ApvCode (https://github.com/apvcode)\n` +
708
708
  `🌟 Repository: https://github.com/apvcode/Termux-Dev\n` +
@@ -771,7 +771,7 @@ export async function main() {
771
771
  program
772
772
  .name('devx')
773
773
  .description('Terminal-native AI coding assistant and vibe-coding agent')
774
- .version('1.4.7')
774
+ .version('1.4.9')
775
775
  .option('-p, --prompt <task>', 'Run one-shot task non-interactively (headless mode)')
776
776
  .option('-y, --yolo', 'Automatically approve all tool executions without confirmation')
777
777
  .option('-m, --model <model>', 'Specify AI model to use for this execution')
@@ -1,8 +1,7 @@
1
- import readline from 'readline';
2
1
  import pc from 'picocolors';
3
2
  import { scanProjectFiles } from './files.js';
4
3
  import { saveClipboardImage, processPastedFilePath } from './clipboard.js';
5
- import { getCurrentTheme } from './theme.js';
4
+ import { getCurrentTheme, listThemes } from './theme.js';
6
5
  import { CustomCommandManager } from '../core/commands.js';
7
6
  export const SLASH_COMMANDS = [
8
7
  { cmd: '/new', desc: 'Start a new clean chat session' },
@@ -35,112 +34,372 @@ export const SLASH_COMMANDS = [
35
34
  { cmd: '/exit', desc: 'Exit devx' }
36
35
  ];
37
36
  const GLOBAL_PROMPT_HISTORY = [];
37
+ function stripAnsi(str) {
38
+ return str.replace(/\x1b\[[0-9;]*[a-zA-Z]/g, '');
39
+ }
38
40
  export function askPrompt(opts = {}) {
39
41
  return new Promise((resolve) => {
42
+ process.stdin.resume();
40
43
  const msg = opts.message
41
44
  ? `${opts.message} ${pc.dim(`(Tab = ${opts.planMode ? 'AGENT' : 'PLAN'})`)}`
42
45
  : `Ask anything... ${pc.dim(`(Tab = ${opts.planMode ? 'AGENT' : 'PLAN'})`)}`;
43
- const theme = getCurrentTheme();
44
- console.log(theme.colorFn('◆') + ' ' + pc.bold(msg));
46
+ const placeholder = opts.placeholder || 'Describe a task, @file, /help, paste image, or press Tab to switch mode';
47
+ let input = opts.initialValue || '';
48
+ let cursorPos = input.length;
49
+ let selectedIndex = 0;
50
+ let lastRenderedDropdownLines = 0;
51
+ let disposed = false;
52
+ let historyIndex = GLOBAL_PROMPT_HISTORY.length;
53
+ let tempDraft = '';
45
54
  let availableFiles = [];
46
55
  let customCommandsList = [];
47
- scanProjectFiles().then((f) => (availableFiles = f)).catch(() => { });
56
+ // Preload project files and custom slash commands
57
+ scanProjectFiles()
58
+ .then((files) => (availableFiles = files))
59
+ .catch(() => { });
48
60
  CustomCommandManager.listCommands()
49
- .then((c) => (customCommandsList = c.map((x) => ({ cmd: x.cmd, desc: x.desc }))))
61
+ .then((cmds) => (customCommandsList = cmds.map((c) => ({ cmd: c.cmd, desc: c.desc }))))
50
62
  .catch(() => { });
63
+ const pastes = [];
51
64
  const imageAttachments = [];
52
65
  const usedImageNames = new Set();
53
- const completer = (line) => {
54
- const allCmds = [
55
- ...SLASH_COMMANDS.map((c) => c.cmd),
56
- ...customCommandsList.map((c) => c.cmd)
57
- ];
58
- // 1. Slash commands autocomplete
59
- if (line.startsWith('/')) {
60
- const q = line.trim().toLowerCase();
61
- const hits = allCmds.filter((cmd) => cmd.toLowerCase().startsWith(q));
62
- return [hits.length ? hits : allCmds, line];
63
- }
64
- // 2. @file autocomplete
65
- const atMatch = line.match(/@([a-zA-Z0-9_\-./]*)$/);
66
+ const theme = getCurrentTheme();
67
+ console.log(theme.colorFn('◆') + ' ' + pc.bold(msg));
68
+ if (process.stdin.isTTY) {
69
+ process.stdin.setRawMode(true);
70
+ }
71
+ if (process.stdout.isTTY) {
72
+ process.stdout.write('\x1b[?2004h');
73
+ }
74
+ function getDropdownItems() {
75
+ // 1. Theme command autocomplete
76
+ if (input.startsWith('/theme ') || input.startsWith('/themes ') || input === '/theme') {
77
+ const afterCmd = input.replace(/^\/(?:theme|themes)\s*/i, '').trim().toLowerCase();
78
+ const themes = listThemes();
79
+ const matched = themes.filter((t) => !afterCmd ||
80
+ t.id.toLowerCase().startsWith(afterCmd) ||
81
+ t.name.toLowerCase().includes(afterCmd));
82
+ const list = [];
83
+ if (!afterCmd || '/theme'.startsWith(input.trim().toLowerCase())) {
84
+ list.push({
85
+ label: '/theme',
86
+ desc: 'Interactive UI theme picker menu',
87
+ replacement: '/theme',
88
+ replaceStart: 0,
89
+ replaceLen: input.length
90
+ });
91
+ }
92
+ for (const t of matched) {
93
+ list.push({
94
+ label: `/theme ${t.id}`,
95
+ desc: `${t.emoji} ${t.name} (${t.desc})`,
96
+ replacement: `/theme ${t.id}`,
97
+ replaceStart: 0,
98
+ replaceLen: input.length
99
+ });
100
+ }
101
+ return list;
102
+ }
103
+ // 2. All Slash commands autocomplete
104
+ if (input.startsWith('/')) {
105
+ const q = input.trim().toLowerCase();
106
+ const baseList = [...SLASH_COMMANDS];
107
+ for (const cc of customCommandsList) {
108
+ if (!baseList.some((b) => b.cmd === cc.cmd)) {
109
+ baseList.push({ cmd: cc.cmd, desc: cc.desc });
110
+ }
111
+ }
112
+ const filtered = baseList.filter((c) => c.cmd.toLowerCase().startsWith(q) || q === '/');
113
+ return filtered.map((c) => ({
114
+ label: c.cmd,
115
+ desc: c.desc,
116
+ replacement: c.cmd,
117
+ replaceStart: 0,
118
+ replaceLen: input.length
119
+ }));
120
+ }
121
+ // 3. @file autocomplete at cursor position
122
+ const beforeCursor = input.slice(0, cursorPos);
123
+ const atMatch = beforeCursor.match(/@([a-zA-Z0-9_\-./]*)$/);
66
124
  if (atMatch && availableFiles.length > 0) {
67
125
  const query = atMatch[1].toLowerCase();
68
- const hits = availableFiles
126
+ const matched = availableFiles
69
127
  .filter((f) => f.toLowerCase().includes(query) || query === '')
70
- .slice(0, 15)
71
- .map((f) => `@${f}${f.endsWith('/') ? '' : ' '}`);
72
- return [hits, atMatch[0]];
73
- }
74
- return [[], line];
75
- };
76
- const rl = readline.createInterface({
77
- input: process.stdin,
78
- output: process.stdout,
79
- prompt: pc.dim('│') + ' ',
80
- completer,
81
- historySize: 100
82
- });
83
- // Populate history in readline
84
- if (GLOBAL_PROMPT_HISTORY.length > 0) {
85
- rl.history = [...GLOBAL_PROMPT_HISTORY].reverse();
128
+ .slice(0, 8);
129
+ return matched.map((f) => ({
130
+ label: `@${f}`,
131
+ desc: f.endsWith('/') ? 'directory' : 'file',
132
+ replacement: `@${f}${f.endsWith('/') ? '' : ' '}`,
133
+ replaceStart: cursorPos - atMatch[0].length,
134
+ replaceLen: atMatch[0].length
135
+ }));
136
+ }
137
+ return [];
86
138
  }
87
- let isClosed = false;
88
- const cleanup = () => {
89
- if (isClosed)
90
- return;
91
- isClosed = true;
92
- process.stdin.removeListener('keypress', onKeypress);
93
- rl.close();
94
- };
95
- const onKeypress = (str, key) => {
96
- if (isClosed)
97
- return;
98
- // Tab key pressed
99
- if (key && key.name === 'tab') {
100
- const curLine = rl.line || '';
101
- // If line is empty or does not start with / or contain @, switch mode
102
- if (curLine.trim() === '' || (!curLine.startsWith('/') && !curLine.includes('@'))) {
103
- readline.cursorTo(process.stdout, 0);
104
- readline.clearLine(process.stdout, 0);
105
- cleanup();
106
- resolve(`__TOGGLE_MODE__:${curLine}`);
107
- return;
139
+ function formatInputWithBadges(rawText) {
140
+ let formatted = rawText;
141
+ for (const p of pastes) {
142
+ const styled = pc.bold(pc.cyan(`[Pasted text #${p.id} +${p.linesCount} lines]`));
143
+ formatted = formatted.split(p.tag).join(styled);
144
+ }
145
+ for (const img of imageAttachments) {
146
+ const styled = pc.bold(pc.magenta(img.tag));
147
+ formatted = formatted.split(img.tag).join(styled);
148
+ }
149
+ return formatted;
150
+ }
151
+ function expandPastes(rawText) {
152
+ let result = rawText;
153
+ for (const p of pastes) {
154
+ result = result.split(p.tag).join(p.content);
155
+ }
156
+ for (const img of imageAttachments) {
157
+ result = result.split(img.tag).join(`@${img.filePath.replace(/\\/g, '/')} `);
158
+ }
159
+ return result;
160
+ }
161
+ function render() {
162
+ if (disposed)
163
+ return;
164
+ const cols = Math.max(28, process.stdout.columns || 80);
165
+ const rows = Math.max(8, process.stdout.rows || 24);
166
+ const items = getDropdownItems();
167
+ const dropdownLines = [];
168
+ if (items.length > 0) {
169
+ if (selectedIndex >= items.length)
170
+ selectedIndex = 0;
171
+ if (selectedIndex < 0)
172
+ selectedIndex = items.length - 1;
173
+ const innerBoxWidth = Math.max(16, Math.min(cols - 8, 54));
174
+ const isNarrowOrShort = rows <= 16 || cols < 50;
175
+ const pageSize = isNarrowOrShort
176
+ ? Math.max(2, Math.min(3, rows - 5))
177
+ : Math.min(5, Math.max(3, Math.floor((rows - 4) / 2)));
178
+ const total = items.length;
179
+ let startIndex = 0;
180
+ if (total > pageSize) {
181
+ if (selectedIndex >= pageSize) {
182
+ startIndex = Math.min(selectedIndex - pageSize + 1, total - pageSize);
183
+ }
184
+ }
185
+ const endIndex = Math.min(startIndex + pageSize, total);
186
+ const hasMoreUp = startIndex > 0;
187
+ const hasMoreDown = endIndex < total;
188
+ let topBorderStr = '─'.repeat(innerBoxWidth);
189
+ if (hasMoreUp) {
190
+ const mid = Math.max(0, Math.floor(innerBoxWidth / 2) - 2);
191
+ topBorderStr = '─'.repeat(mid) + ' ▲ ' + '─'.repeat(Math.max(0, innerBoxWidth - mid - 3));
192
+ }
193
+ let botBorderStr = '─'.repeat(innerBoxWidth);
194
+ if (hasMoreDown) {
195
+ const mid = Math.max(0, Math.floor(innerBoxWidth / 2) - 2);
196
+ botBorderStr = '─'.repeat(mid) + ' ▼ ' + '─'.repeat(Math.max(0, innerBoxWidth - mid - 3));
108
197
  }
198
+ dropdownLines.push(pc.dim('│') + ' ' + pc.dim('╭' + topBorderStr + '╮'));
199
+ for (let i = startIndex; i < endIndex; i++) {
200
+ const item = items[i];
201
+ const isSelected = i === selectedIndex;
202
+ const pointer = isSelected ? '› ' : ' ';
203
+ const availWidth = innerBoxWidth - 2;
204
+ let row = '';
205
+ if (availWidth < 20) {
206
+ const labelStr = item.label.length > availWidth
207
+ ? item.label.slice(0, availWidth - 1) + '…'
208
+ : item.label.padEnd(availWidth);
209
+ const plain = pointer + labelStr;
210
+ row = isSelected ? theme.badgeFn(plain) : pointer + theme.boldFn(labelStr);
211
+ }
212
+ else {
213
+ const labelMax = Math.min(15, Math.floor(availWidth * 0.45));
214
+ const labelStr = item.label.length > labelMax
215
+ ? item.label.slice(0, labelMax - 1) + '…'
216
+ : item.label.padEnd(labelMax);
217
+ const descMax = availWidth - labelMax - 1;
218
+ const descStr = item.desc.length > descMax
219
+ ? item.desc.slice(0, descMax - 1) + '…'
220
+ : item.desc.padEnd(descMax);
221
+ const plain = `${pointer}${labelStr} ${descStr}`;
222
+ if (isSelected) {
223
+ row = theme.badgeFn(plain);
224
+ }
225
+ else {
226
+ row = `${pointer}${theme.boldFn(labelStr)} ${pc.gray(descStr)}`;
227
+ }
228
+ }
229
+ const currentLen = stripAnsi(row).length;
230
+ if (currentLen < innerBoxWidth) {
231
+ row += ' '.repeat(innerBoxWidth - currentLen);
232
+ }
233
+ dropdownLines.push(pc.dim('│') + ' ' + pc.dim('│') + row + pc.dim('│'));
234
+ }
235
+ dropdownLines.push(pc.dim('│') + ' ' + pc.dim('╰' + botBorderStr + '╯'));
109
236
  }
110
- // Ctrl+V or Ctrl+P: Clipboard image paste
111
- if ((key && key.ctrl && (key.name === 'v' || key.name === 'p')) || str === '\x16' || str === '\x10') {
112
- saveClipboardImage('image.png', usedImageNames)
113
- .then((imgRes) => {
114
- if (imgRes && !isClosed) {
115
- const tag = `[${imgRes.fileName} ${imgRes.sizeStr}]`;
116
- imageAttachments.push({
117
- tag,
118
- fileName: imgRes.fileName,
119
- filePath: imgRes.filePath,
120
- sizeStr: imgRes.sizeStr
121
- });
122
- usedImageNames.add(imgRes.fileName);
123
- rl.write(`${tag} `);
237
+ // 1. Clear line 0 and write prompt line
238
+ let inputDisplay = pc.dim('') + ' ';
239
+ if (input.length === 0) {
240
+ const maxPlace = Math.max(12, cols - 8);
241
+ const displayPlace = placeholder.length > maxPlace ? placeholder.slice(0, maxPlace - 1) + '…' : placeholder;
242
+ inputDisplay += pc.dim(displayPlace);
243
+ }
244
+ else {
245
+ inputDisplay += formatInputWithBadges(input);
246
+ }
247
+ process.stdout.write(`\r\x1b[2K${inputDisplay}`);
248
+ // 3. Draw new dropdown lines below, and clear extra lines from previous render
249
+ const maxDropdowns = Math.max(dropdownLines.length, lastRenderedDropdownLines);
250
+ if (maxDropdowns > 0) {
251
+ for (let i = 0; i < maxDropdowns; i++) {
252
+ if (i < dropdownLines.length) {
253
+ process.stdout.write(`\n\x1b[2K${dropdownLines[i]}`);
124
254
  }
125
- })
126
- .catch(() => { });
255
+ else {
256
+ process.stdout.write(`\n\x1b[2K`);
257
+ }
258
+ }
259
+ // Move cursor back up to input line (line 0)
260
+ process.stdout.write(`\x1b[${maxDropdowns}A`);
127
261
  }
128
- };
129
- if (process.stdin.isTTY) {
130
- readline.emitKeypressEvents(process.stdin, rl);
131
- process.stdin.on('keypress', onKeypress);
262
+ // 4. Place cursor at column 3 + cursorPos
263
+ const cursorCol = 3 + cursorPos;
264
+ process.stdout.write(`\r\x1b[${cursorCol}C`);
265
+ lastRenderedDropdownLines = dropdownLines.length;
132
266
  }
133
- if (opts.initialValue) {
134
- rl.write(opts.initialValue);
267
+ render();
268
+ function cleanup() {
269
+ disposed = true;
270
+ if (process.stdout.isTTY) {
271
+ process.stdout.write('\x1b[?2004l');
272
+ }
273
+ process.stdin.removeListener('data', onData);
274
+ if (process.stdin.isTTY) {
275
+ process.stdin.setRawMode(false);
276
+ }
277
+ process.stdin.pause();
135
278
  }
136
- rl.prompt();
137
- rl.on('line', async (rawLine) => {
279
+ function clearBoxAndExit(finalInput) {
280
+ if (lastRenderedDropdownLines > 0) {
281
+ for (let i = 0; i < lastRenderedDropdownLines; i++) {
282
+ process.stdout.write(`\n\x1b[2K`);
283
+ }
284
+ process.stdout.write(`\x1b[${lastRenderedDropdownLines}A`);
285
+ lastRenderedDropdownLines = 0;
286
+ }
287
+ const fullText = expandPastes(finalInput);
288
+ if (fullText.trim()) {
289
+ if (GLOBAL_PROMPT_HISTORY.length === 0 ||
290
+ GLOBAL_PROMPT_HISTORY[GLOBAL_PROMPT_HISTORY.length - 1] !== fullText.trim()) {
291
+ GLOBAL_PROMPT_HISTORY.push(fullText.trim());
292
+ }
293
+ }
294
+ process.stdout.write(`\r\x1b[2K${pc.dim('│')} ${formatInputWithBadges(finalInput)}\n\n`);
138
295
  cleanup();
139
- let line = rawLine.trim();
140
- // Handle direct /image command
141
- if (line === '/image') {
142
- try {
143
- const imgRes = await saveClipboardImage('image.png', usedImageNames);
296
+ resolve(fullText);
297
+ }
298
+ async function handlePaste(pastedContent) {
299
+ const cleaned = pastedContent.replace(/\x1b\[200~/g, '').replace(/\x1b\[201~/g, '');
300
+ // Check if pastedContent contains file path(s) to images
301
+ const pathCandidates = cleaned
302
+ .split(/[&;\n\r]+/)
303
+ .map((s) => s.trim())
304
+ .filter(Boolean);
305
+ let foundAnyImage = false;
306
+ for (const cand of pathCandidates) {
307
+ const imgRes = await processPastedFilePath(cand, usedImageNames);
308
+ if (imgRes) {
309
+ foundAnyImage = true;
310
+ const tag = `[${imgRes.fileName} ${imgRes.sizeStr}]`;
311
+ imageAttachments.push({
312
+ tag,
313
+ fileName: imgRes.fileName,
314
+ filePath: imgRes.filePath,
315
+ sizeStr: imgRes.sizeStr
316
+ });
317
+ usedImageNames.add(imgRes.fileName);
318
+ input = input.slice(0, cursorPos) + tag + ' ' + input.slice(cursorPos);
319
+ cursorPos += tag.length + 1;
320
+ }
321
+ }
322
+ if (foundAnyImage) {
323
+ selectedIndex = 0;
324
+ render();
325
+ return;
326
+ }
327
+ const normalized = cleaned.replace(/\r\n/g, '\n').replace(/\r/g, '\n');
328
+ const lines = normalized.split('\n');
329
+ if (lines.length >= 2 || normalized.length > 80) {
330
+ const linesCount = lines.length;
331
+ const id = pastes.length + 1;
332
+ const tag = `[Pasted text #${id} +${linesCount} lines]`;
333
+ pastes.push({ id, tag, content: normalized, linesCount });
334
+ input = input.slice(0, cursorPos) + tag + input.slice(cursorPos);
335
+ cursorPos += tag.length;
336
+ selectedIndex = 0;
337
+ render();
338
+ }
339
+ else {
340
+ input = input.slice(0, cursorPos) + normalized + input.slice(cursorPos);
341
+ cursorPos += normalized.length;
342
+ selectedIndex = 0;
343
+ render();
344
+ }
345
+ }
346
+ function getTagSpans() {
347
+ const spans = [];
348
+ for (const p of pastes) {
349
+ let pos = 0;
350
+ while ((pos = input.indexOf(p.tag, pos)) !== -1) {
351
+ spans.push({
352
+ start: pos,
353
+ end: pos + p.tag.length,
354
+ tag: p.tag
355
+ });
356
+ pos += p.tag.length;
357
+ }
358
+ }
359
+ for (const img of imageAttachments) {
360
+ let pos = 0;
361
+ while ((pos = input.indexOf(img.tag, pos)) !== -1) {
362
+ spans.push({
363
+ start: pos,
364
+ end: pos + img.tag.length,
365
+ tag: img.tag
366
+ });
367
+ pos += img.tag.length;
368
+ }
369
+ }
370
+ return spans.sort((a, b) => a.start - b.start);
371
+ }
372
+ let pasteBuffer = '';
373
+ let inBracketedPaste = false;
374
+ function onData(chunk) {
375
+ if (disposed)
376
+ return;
377
+ const str = chunk.toString('utf8');
378
+ // Check for bracketed paste start/end
379
+ if (str.includes('\x1b[200~')) {
380
+ inBracketedPaste = true;
381
+ pasteBuffer = '';
382
+ }
383
+ if (inBracketedPaste) {
384
+ pasteBuffer += str;
385
+ if (pasteBuffer.includes('\x1b[201~')) {
386
+ inBracketedPaste = false;
387
+ handlePaste(pasteBuffer);
388
+ pasteBuffer = '';
389
+ }
390
+ return;
391
+ }
392
+ // Check for raw multi-character paste with newlines or large size
393
+ if (str.length > 1 && (str.includes('\n') || str.includes('\r') || str.length > 80)) {
394
+ handlePaste(str);
395
+ return;
396
+ }
397
+ // Ctrl+V / Ctrl+P: Clipboard image paste
398
+ if (str === '\x16' ||
399
+ str === '\x10' ||
400
+ (str.length === 1 && (str.charCodeAt(0) === 22 || str.charCodeAt(0) === 16))) {
401
+ saveClipboardImage('image.png', usedImageNames)
402
+ .then((imgRes) => {
144
403
  if (imgRes) {
145
404
  const tag = `[${imgRes.fileName} ${imgRes.sizeStr}]`;
146
405
  imageAttachments.push({
@@ -150,52 +409,259 @@ export function askPrompt(opts = {}) {
150
409
  sizeStr: imgRes.sizeStr
151
410
  });
152
411
  usedImageNames.add(imgRes.fileName);
153
- line = tag;
412
+ input = input.slice(0, cursorPos) + tag + ' ' + input.slice(cursorPos);
413
+ cursorPos += tag.length + 1;
414
+ render();
415
+ }
416
+ })
417
+ .catch(() => { });
418
+ return;
419
+ }
420
+ // Ctrl+C
421
+ if (str === '\x03' || (str.length === 1 && str.charCodeAt(0) === 3)) {
422
+ if (lastRenderedDropdownLines > 0) {
423
+ for (let i = 0; i < lastRenderedDropdownLines; i++) {
424
+ process.stdout.write(`\n\x1b[2K`);
425
+ }
426
+ process.stdout.write(`\x1b[${lastRenderedDropdownLines}A`);
427
+ lastRenderedDropdownLines = 0;
428
+ }
429
+ process.stdout.write(`\r\x1b[2K\n`);
430
+ cleanup();
431
+ resolve('__CANCEL__');
432
+ return;
433
+ }
434
+ const items = getDropdownItems();
435
+ // Enter / Return
436
+ if (str === '\r' ||
437
+ str === '\n' ||
438
+ (str.length === 1 && (str.charCodeAt(0) === 13 || str.charCodeAt(0) === 10))) {
439
+ // Direct /image command
440
+ if (input.trim() === '/image' ||
441
+ (items.length > 0 &&
442
+ selectedIndex >= 0 &&
443
+ selectedIndex < items.length &&
444
+ items[selectedIndex].label === '/image')) {
445
+ saveClipboardImage('image.png', usedImageNames)
446
+ .then((imgRes) => {
447
+ if (imgRes) {
448
+ const tag = `[${imgRes.fileName} ${imgRes.sizeStr}]`;
449
+ imageAttachments.push({
450
+ tag,
451
+ fileName: imgRes.fileName,
452
+ filePath: imgRes.filePath,
453
+ sizeStr: imgRes.sizeStr
454
+ });
455
+ usedImageNames.add(imgRes.fileName);
456
+ input = `${tag} `;
457
+ cursorPos = input.length;
458
+ render();
459
+ }
460
+ else {
461
+ process.stdout.write(`\r\x1b[2K${pc.yellow('⚠️ No image in clipboard. Take a screenshot first (Win+Shift+S)\n')}`);
462
+ input = '';
463
+ cursorPos = 0;
464
+ render();
465
+ }
466
+ })
467
+ .catch(() => { });
468
+ return;
469
+ }
470
+ if (items.length > 0 && selectedIndex >= 0 && selectedIndex < items.length) {
471
+ const selected = items[selectedIndex];
472
+ if (input.startsWith('/')) {
473
+ input = selected.replacement;
474
+ clearBoxAndExit(input);
475
+ return;
154
476
  }
155
477
  else {
156
- console.log(pc.yellow('⚠️ No image in clipboard. Take a screenshot first (Win+Shift+S)\n'));
157
- resolve('');
478
+ // @ mention autocomplete on Enter
479
+ input =
480
+ input.slice(0, selected.replaceStart) +
481
+ selected.replacement +
482
+ input.slice(selected.replaceStart + selected.replaceLen);
483
+ cursorPos = selected.replaceStart + selected.replacement.length;
484
+ render();
158
485
  return;
159
486
  }
160
487
  }
161
- catch {
162
- resolve('');
163
- return;
488
+ clearBoxAndExit(input);
489
+ return;
490
+ }
491
+ // Tab
492
+ if (str === '\t' || (str.length === 1 && str.charCodeAt(0) === 9)) {
493
+ if (items.length > 0 && selectedIndex >= 0 && selectedIndex < items.length) {
494
+ const selected = items[selectedIndex];
495
+ input =
496
+ input.slice(0, selected.replaceStart) +
497
+ selected.replacement +
498
+ input.slice(selected.replaceStart + selected.replaceLen);
499
+ cursorPos = selected.replaceStart + selected.replacement.length;
500
+ render();
164
501
  }
502
+ else {
503
+ if (lastRenderedDropdownLines > 0) {
504
+ for (let i = 0; i < lastRenderedDropdownLines; i++) {
505
+ process.stdout.write(`\n\x1b[2K`);
506
+ }
507
+ process.stdout.write(`\x1b[${lastRenderedDropdownLines}A`);
508
+ lastRenderedDropdownLines = 0;
509
+ }
510
+ process.stdout.write(`\r\x1b[2K`);
511
+ cleanup();
512
+ resolve(`__TOGGLE_MODE__:${input}`);
513
+ }
514
+ return;
165
515
  }
166
- // Check for pasted file path to image
167
- if (line.match(/\.(png|jpe?g|webp|gif|bmp)$/i)) {
168
- const imgRes = await processPastedFilePath(line, usedImageNames);
169
- if (imgRes) {
170
- const tag = `[${imgRes.fileName} ${imgRes.sizeStr}]`;
171
- imageAttachments.push({
172
- tag,
173
- fileName: imgRes.fileName,
174
- filePath: imgRes.filePath,
175
- sizeStr: imgRes.sizeStr
176
- });
177
- usedImageNames.add(imgRes.fileName);
178
- line = tag;
516
+ // Up Arrow
517
+ if (str === '\x1b[A' || str === '\x1bOA') {
518
+ if (items.length > 0) {
519
+ selectedIndex = (selectedIndex - 1 + items.length) % items.length;
520
+ render();
179
521
  }
522
+ else if (GLOBAL_PROMPT_HISTORY.length > 0 && historyIndex > 0) {
523
+ if (historyIndex === GLOBAL_PROMPT_HISTORY.length) {
524
+ tempDraft = input;
525
+ }
526
+ historyIndex--;
527
+ input = GLOBAL_PROMPT_HISTORY[historyIndex];
528
+ cursorPos = input.length;
529
+ render();
530
+ }
531
+ return;
180
532
  }
181
- // Expand image attachment tags to @path
182
- let expanded = line;
183
- for (const img of imageAttachments) {
184
- expanded = expanded.split(img.tag).join(`@${img.filePath.replace(/\\/g, '/')} `);
533
+ // Down Arrow
534
+ if (str === '\x1b[B' || str === '\x1bOB') {
535
+ if (items.length > 0) {
536
+ selectedIndex = (selectedIndex + 1) % items.length;
537
+ render();
538
+ }
539
+ else if (historyIndex < GLOBAL_PROMPT_HISTORY.length) {
540
+ historyIndex++;
541
+ if (historyIndex === GLOBAL_PROMPT_HISTORY.length) {
542
+ input = tempDraft;
543
+ }
544
+ else {
545
+ input = GLOBAL_PROMPT_HISTORY[historyIndex];
546
+ }
547
+ cursorPos = input.length;
548
+ render();
549
+ }
550
+ return;
185
551
  }
186
- if (expanded.trim()) {
187
- if (GLOBAL_PROMPT_HISTORY.length === 0 ||
188
- GLOBAL_PROMPT_HISTORY[GLOBAL_PROMPT_HISTORY.length - 1] !== expanded.trim()) {
189
- GLOBAL_PROMPT_HISTORY.push(expanded.trim());
552
+ // Left Arrow
553
+ if (str === '\x1b[D' || str === '\x1bOD') {
554
+ if (cursorPos > 0) {
555
+ const spans = getTagSpans();
556
+ const endingSpan = spans.find((s) => s.end === cursorPos);
557
+ if (endingSpan) {
558
+ cursorPos = endingSpan.start;
559
+ }
560
+ else {
561
+ cursorPos--;
562
+ const inside = spans.find((s) => cursorPos > s.start && cursorPos < s.end);
563
+ if (inside)
564
+ cursorPos = inside.start;
565
+ }
566
+ render();
190
567
  }
568
+ return;
191
569
  }
192
- console.log();
193
- resolve(expanded);
194
- });
195
- rl.on('SIGINT', () => {
196
- cleanup();
197
- console.log();
198
- resolve('__CANCEL__');
199
- });
570
+ // Right Arrow
571
+ if (str === '\x1b[C' || str === '\x1bOC') {
572
+ if (cursorPos < input.length) {
573
+ const spans = getTagSpans();
574
+ const startingSpan = spans.find((s) => s.start === cursorPos);
575
+ if (startingSpan) {
576
+ cursorPos = startingSpan.end;
577
+ }
578
+ else {
579
+ cursorPos++;
580
+ const inside = spans.find((s) => cursorPos > s.start && cursorPos < s.end);
581
+ if (inside)
582
+ cursorPos = inside.end;
583
+ }
584
+ render();
585
+ }
586
+ return;
587
+ }
588
+ // Home
589
+ if (str === '\x1b[H' || str === '\x1b[1~') {
590
+ cursorPos = 0;
591
+ render();
592
+ return;
593
+ }
594
+ // End
595
+ if (str === '\x1b[F' || str === '\x1b[4~') {
596
+ cursorPos = input.length;
597
+ render();
598
+ return;
599
+ }
600
+ // Delete key
601
+ if (str === '\x1b[3~') {
602
+ if (cursorPos < input.length) {
603
+ const spans = getTagSpans();
604
+ const startingSpan = spans.find((s) => s.start === cursorPos);
605
+ if (startingSpan) {
606
+ input = input.slice(0, startingSpan.start) + input.slice(startingSpan.end);
607
+ }
608
+ else {
609
+ input = input.slice(0, cursorPos) + input.slice(cursorPos + 1);
610
+ }
611
+ selectedIndex = 0;
612
+ render();
613
+ }
614
+ return;
615
+ }
616
+ // Backspace / DEL handling
617
+ if (str.includes('\x08') || str.includes('\x7f')) {
618
+ for (let i = 0; i < str.length; i++) {
619
+ const ch = str[i];
620
+ if (ch === '\x08' || ch === '\x7f') {
621
+ if (cursorPos > 0) {
622
+ const spans = getTagSpans();
623
+ const endingSpan = spans.find((s) => s.end === cursorPos);
624
+ if (endingSpan) {
625
+ input = input.slice(0, endingSpan.start) + input.slice(endingSpan.end);
626
+ cursorPos = endingSpan.start;
627
+ }
628
+ else {
629
+ input = input.slice(0, cursorPos - 1) + input.slice(cursorPos);
630
+ cursorPos--;
631
+ }
632
+ }
633
+ }
634
+ else if (ch.charCodeAt(0) >= 32) {
635
+ const spans = getTagSpans();
636
+ const inside = spans.find((s) => cursorPos > s.start && cursorPos < s.end);
637
+ if (inside)
638
+ cursorPos = inside.end;
639
+ input = input.slice(0, cursorPos) + ch + input.slice(cursorPos);
640
+ cursorPos++;
641
+ }
642
+ }
643
+ selectedIndex = 0;
644
+ render();
645
+ return;
646
+ }
647
+ // Ignore unknown escape sequences
648
+ if (str.startsWith('\x1b')) {
649
+ return;
650
+ }
651
+ // Normal character input - clean control characters
652
+ const cleanStr = str.replace(/[\x00-\x08\x0b\x0c\x0e-\x1f\x7f]/g, '');
653
+ if (!cleanStr)
654
+ return;
655
+ const spans = getTagSpans();
656
+ const inside = spans.find((s) => cursorPos > s.start && cursorPos < s.end);
657
+ if (inside) {
658
+ cursorPos = inside.end;
659
+ }
660
+ input = input.slice(0, cursorPos) + cleanStr + input.slice(cursorPos);
661
+ cursorPos += cleanStr.length;
662
+ selectedIndex = 0;
663
+ render();
664
+ }
665
+ process.stdin.on('data', onData);
200
666
  });
201
667
  }
@@ -139,7 +139,7 @@ function renderDirectoryHtml(dirPath, relPath, files, port) {
139
139
  ${parentLink}
140
140
  ${items || '<li style="padding: 20px; text-align: center; color: #6e7681;">No visible files in this directory</li>'}
141
141
  </ul>
142
- <div class="footer">devx v1.4.7 &bull; Terminal-Native AI Assistant</div>
142
+ <div class="footer">devx v1.4.9 &bull; Terminal-Native AI Assistant</div>
143
143
  </div>
144
144
  </body>
145
145
  </html>`;
@@ -63,7 +63,7 @@ export class MCPClient {
63
63
  capabilities: {},
64
64
  clientInfo: {
65
65
  name: 'devx',
66
- version: '1.4.7'
66
+ version: '1.4.9'
67
67
  }
68
68
  });
69
69
  if (!initResult) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "termux-dev",
3
- "version": "1.4.7",
3
+ "version": "1.4.9",
4
4
  "description": "Ultra-fast, terminal-native AI coding assistant and agent built for Android Termux, Windows, macOS, and Linux.",
5
5
  "main": "dist/cli/index.js",
6
6
  "type": "module",