termux-dev 1.4.9 → 1.4.10
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 +1 -1
- package/dist/cli/doctor.js +1 -1
- package/dist/cli/headless.js +1 -1
- package/dist/cli/index.js +6 -6
- package/dist/cli/prompt.js +128 -585
- package/dist/cli/server.js +1 -1
- package/dist/mcp/client.js +1 -1
- package/package.json +1 -1
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.
|
|
28
|
+
THE TERMINAL-NATIVE AI CODING AGENT <tspan fill="#00f2fe" font-weight="bold">v1.4.10</tspan>
|
|
29
29
|
</text>
|
|
30
30
|
|
|
31
31
|
<!-- Top Accent Line -->
|
package/dist/cli/doctor.js
CHANGED
|
@@ -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.
|
|
21
|
+
'User-Agent': 'devx-doctor/1.4.10'
|
|
22
22
|
}
|
|
23
23
|
}, (res) => {
|
|
24
24
|
res.resume(); // consume response data to free up memory and release socket
|
package/dist/cli/headless.js
CHANGED
|
@@ -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.
|
|
38
|
+
console.log(pc.bold(pc.cyan(`⚡ devx v1.4.10 (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.
|
|
487
|
+
' ' + theme.boldFn('v1.4.10'),
|
|
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.
|
|
502
|
+
indent + theme.boldFn('v1.4.10'),
|
|
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.
|
|
648
|
+
message: `${pc.bold('⚙️ Settings')} ${pc.dim(`(devx v1.4.10 • 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.
|
|
689
|
+
name: `${currentTh.colorFn('✨ About devx')} ${pc.dim('(v1.4.10 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.
|
|
705
|
+
p.note(`⚡ devx v1.4.10 — 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.
|
|
774
|
+
.version('1.4.10')
|
|
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')
|
package/dist/cli/prompt.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
import readline from 'readline';
|
|
1
2
|
import pc from 'picocolors';
|
|
2
3
|
import { scanProjectFiles } from './files.js';
|
|
3
4
|
import { saveClipboardImage, processPastedFilePath } from './clipboard.js';
|
|
4
|
-
import { getCurrentTheme
|
|
5
|
+
import { getCurrentTheme } from './theme.js';
|
|
5
6
|
import { CustomCommandManager } from '../core/commands.js';
|
|
6
7
|
export const SLASH_COMMANDS = [
|
|
7
8
|
{ cmd: '/new', desc: 'Start a new clean chat session' },
|
|
@@ -34,373 +35,92 @@ export const SLASH_COMMANDS = [
|
|
|
34
35
|
{ cmd: '/exit', desc: 'Exit devx' }
|
|
35
36
|
];
|
|
36
37
|
const GLOBAL_PROMPT_HISTORY = [];
|
|
37
|
-
function stripAnsi(str) {
|
|
38
|
-
return str.replace(/\x1b\[[0-9;]*[a-zA-Z]/g, '');
|
|
39
|
-
}
|
|
40
38
|
export function askPrompt(opts = {}) {
|
|
41
39
|
return new Promise((resolve) => {
|
|
42
|
-
process.stdin.resume();
|
|
43
40
|
const msg = opts.message
|
|
44
41
|
? `${opts.message} ${pc.dim(`(Tab = ${opts.planMode ? 'AGENT' : 'PLAN'})`)}`
|
|
45
42
|
: `Ask anything... ${pc.dim(`(Tab = ${opts.planMode ? 'AGENT' : 'PLAN'})`)}`;
|
|
46
|
-
const
|
|
47
|
-
|
|
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 = '';
|
|
43
|
+
const theme = getCurrentTheme();
|
|
44
|
+
console.log(theme.colorFn('◆') + ' ' + pc.bold(msg));
|
|
54
45
|
let availableFiles = [];
|
|
55
46
|
let customCommandsList = [];
|
|
56
|
-
|
|
57
|
-
scanProjectFiles()
|
|
58
|
-
.then((files) => (availableFiles = files))
|
|
59
|
-
.catch(() => { });
|
|
47
|
+
scanProjectFiles().then((f) => (availableFiles = f)).catch(() => { });
|
|
60
48
|
CustomCommandManager.listCommands()
|
|
61
|
-
.then((
|
|
49
|
+
.then((c) => (customCommandsList = c.map((x) => ({ cmd: x.cmd, desc: x.desc }))))
|
|
62
50
|
.catch(() => { });
|
|
63
|
-
const pastes = [];
|
|
64
51
|
const imageAttachments = [];
|
|
65
52
|
const usedImageNames = new Set();
|
|
66
|
-
const
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
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_\-./]*)$/);
|
|
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_\-./]*)$/);
|
|
124
66
|
if (atMatch && availableFiles.length > 0) {
|
|
125
67
|
const query = atMatch[1].toLowerCase();
|
|
126
|
-
const
|
|
68
|
+
const hits = availableFiles
|
|
127
69
|
.filter((f) => f.toLowerCase().includes(query) || query === '')
|
|
128
|
-
.slice(0,
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
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;
|
|
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();
|
|
160
86
|
}
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
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));
|
|
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 + '╯'));
|
|
236
|
-
}
|
|
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]}`);
|
|
254
|
-
}
|
|
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`);
|
|
261
|
-
}
|
|
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;
|
|
266
|
-
}
|
|
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();
|
|
278
|
-
}
|
|
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`);
|
|
295
|
-
cleanup();
|
|
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)
|
|
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
|
+
const curLine = rl.line || '';
|
|
99
|
+
// INSTANT COMMAND MENU TRIGGER
|
|
100
|
+
// If user types '/' as the first character, instantly launch the robust search menu!
|
|
101
|
+
if (str === '/' && curLine.length === 0) {
|
|
102
|
+
readline.cursorTo(process.stdout, 0);
|
|
103
|
+
readline.clearLine(process.stdout, 0);
|
|
104
|
+
cleanup();
|
|
105
|
+
resolve('/');
|
|
376
106
|
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
107
|
}
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
108
|
+
// Tab key pressed
|
|
109
|
+
if (key && key.name === 'tab') {
|
|
110
|
+
// If line is empty or does not start with / or contain @, switch mode
|
|
111
|
+
if (curLine.trim() === '' || (!curLine.startsWith('/') && !curLine.includes('@'))) {
|
|
112
|
+
readline.cursorTo(process.stdout, 0);
|
|
113
|
+
readline.clearLine(process.stdout, 0);
|
|
114
|
+
cleanup();
|
|
115
|
+
resolve(`__TOGGLE_MODE__:${curLine}`);
|
|
116
|
+
return;
|
|
389
117
|
}
|
|
390
|
-
return;
|
|
391
118
|
}
|
|
392
|
-
//
|
|
393
|
-
if (
|
|
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))) {
|
|
119
|
+
// Ctrl+V or Ctrl+P: Clipboard image paste
|
|
120
|
+
if ((key && key.ctrl && (key.name === 'v' || key.name === 'p')) || str === '\x16' || str === '\x10') {
|
|
401
121
|
saveClipboardImage('image.png', usedImageNames)
|
|
402
122
|
.then((imgRes) => {
|
|
403
|
-
if (imgRes) {
|
|
123
|
+
if (imgRes && !isClosed) {
|
|
404
124
|
const tag = `[${imgRes.fileName} ${imgRes.sizeStr}]`;
|
|
405
125
|
imageAttachments.push({
|
|
406
126
|
tag,
|
|
@@ -409,259 +129,82 @@ export function askPrompt(opts = {}) {
|
|
|
409
129
|
sizeStr: imgRes.sizeStr
|
|
410
130
|
});
|
|
411
131
|
usedImageNames.add(imgRes.fileName);
|
|
412
|
-
|
|
413
|
-
cursorPos += tag.length + 1;
|
|
414
|
-
render();
|
|
132
|
+
rl.write(`${tag} `);
|
|
415
133
|
}
|
|
416
134
|
})
|
|
417
135
|
.catch(() => { });
|
|
418
|
-
return;
|
|
419
136
|
}
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
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;
|
|
137
|
+
};
|
|
138
|
+
if (process.stdin.isTTY) {
|
|
139
|
+
readline.emitKeypressEvents(process.stdin, rl);
|
|
140
|
+
process.stdin.on('keypress', onKeypress);
|
|
141
|
+
}
|
|
142
|
+
if (opts.initialValue) {
|
|
143
|
+
rl.write(opts.initialValue);
|
|
144
|
+
}
|
|
145
|
+
rl.prompt();
|
|
146
|
+
rl.on('line', async (rawLine) => {
|
|
147
|
+
cleanup();
|
|
148
|
+
let line = rawLine.trim();
|
|
149
|
+
// Handle direct /image command
|
|
150
|
+
if (line === '/image') {
|
|
151
|
+
try {
|
|
152
|
+
const imgRes = await saveClipboardImage('image.png', usedImageNames);
|
|
153
|
+
if (imgRes) {
|
|
154
|
+
const tag = `[${imgRes.fileName} ${imgRes.sizeStr}]`;
|
|
155
|
+
imageAttachments.push({
|
|
156
|
+
tag,
|
|
157
|
+
fileName: imgRes.fileName,
|
|
158
|
+
filePath: imgRes.filePath,
|
|
159
|
+
sizeStr: imgRes.sizeStr
|
|
160
|
+
});
|
|
161
|
+
usedImageNames.add(imgRes.fileName);
|
|
162
|
+
line = tag;
|
|
476
163
|
}
|
|
477
164
|
else {
|
|
478
|
-
|
|
479
|
-
|
|
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();
|
|
165
|
+
console.log(pc.yellow('⚠️ No image in clipboard. Take a screenshot first (Win+Shift+S)\n'));
|
|
166
|
+
resolve('');
|
|
485
167
|
return;
|
|
486
168
|
}
|
|
487
169
|
}
|
|
488
|
-
|
|
489
|
-
|
|
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();
|
|
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;
|
|
515
|
-
}
|
|
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();
|
|
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;
|
|
532
|
-
}
|
|
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;
|
|
551
|
-
}
|
|
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();
|
|
170
|
+
catch {
|
|
171
|
+
resolve('');
|
|
172
|
+
return;
|
|
567
173
|
}
|
|
568
|
-
return;
|
|
569
174
|
}
|
|
570
|
-
//
|
|
571
|
-
if (
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
const
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
}
|
|
584
|
-
render();
|
|
175
|
+
// Check for pasted file path to image
|
|
176
|
+
if (line.match(/\.(png|jpe?g|webp|gif|bmp)$/i)) {
|
|
177
|
+
const imgRes = await processPastedFilePath(line, usedImageNames);
|
|
178
|
+
if (imgRes) {
|
|
179
|
+
const tag = `[${imgRes.fileName} ${imgRes.sizeStr}]`;
|
|
180
|
+
imageAttachments.push({
|
|
181
|
+
tag,
|
|
182
|
+
fileName: imgRes.fileName,
|
|
183
|
+
filePath: imgRes.filePath,
|
|
184
|
+
sizeStr: imgRes.sizeStr
|
|
185
|
+
});
|
|
186
|
+
usedImageNames.add(imgRes.fileName);
|
|
187
|
+
line = tag;
|
|
585
188
|
}
|
|
586
|
-
return;
|
|
587
189
|
}
|
|
588
|
-
//
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
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;
|
|
190
|
+
// Expand image attachment tags to @path
|
|
191
|
+
let expanded = line;
|
|
192
|
+
for (const img of imageAttachments) {
|
|
193
|
+
expanded = expanded.split(img.tag).join(`@${img.filePath.replace(/\\/g, '/')} `);
|
|
615
194
|
}
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
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
|
-
}
|
|
195
|
+
if (expanded.trim()) {
|
|
196
|
+
if (GLOBAL_PROMPT_HISTORY.length === 0 ||
|
|
197
|
+
GLOBAL_PROMPT_HISTORY[GLOBAL_PROMPT_HISTORY.length - 1] !== expanded.trim()) {
|
|
198
|
+
GLOBAL_PROMPT_HISTORY.push(expanded.trim());
|
|
642
199
|
}
|
|
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
200
|
}
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
201
|
+
console.log();
|
|
202
|
+
resolve(expanded);
|
|
203
|
+
});
|
|
204
|
+
rl.on('SIGINT', () => {
|
|
205
|
+
cleanup();
|
|
206
|
+
console.log();
|
|
207
|
+
resolve('__CANCEL__');
|
|
208
|
+
});
|
|
666
209
|
});
|
|
667
210
|
}
|
package/dist/cli/server.js
CHANGED
|
@@ -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.
|
|
142
|
+
<div class="footer">devx v1.4.10 • Terminal-Native AI Assistant</div>
|
|
143
143
|
</div>
|
|
144
144
|
</body>
|
|
145
145
|
</html>`;
|
package/dist/mcp/client.js
CHANGED
package/package.json
CHANGED