termux-dev 1.4.6 → 1.4.7
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 +127 -576
- 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.7</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.7'
|
|
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.7 (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.7'),
|
|
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.7'),
|
|
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.7 • 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.7 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.7 — 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.7')
|
|
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' },
|
|
@@ -36,380 +37,110 @@ export const SLASH_COMMANDS = [
|
|
|
36
37
|
const GLOBAL_PROMPT_HISTORY = [];
|
|
37
38
|
export function askPrompt(opts = {}) {
|
|
38
39
|
return new Promise((resolve) => {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
let selectedIndex = 0;
|
|
45
|
-
let lastTotalLines = 0;
|
|
46
|
-
let disposed = false;
|
|
47
|
-
let historyIndex = GLOBAL_PROMPT_HISTORY.length;
|
|
48
|
-
let tempDraft = '';
|
|
40
|
+
const msg = opts.message
|
|
41
|
+
? `${opts.message} ${pc.dim(`(Tab = ${opts.planMode ? 'AGENT' : 'PLAN'})`)}`
|
|
42
|
+
: `Ask anything... ${pc.dim(`(Tab = ${opts.planMode ? 'AGENT' : 'PLAN'})`)}`;
|
|
43
|
+
const theme = getCurrentTheme();
|
|
44
|
+
console.log(theme.colorFn('◆') + ' ' + pc.bold(msg));
|
|
49
45
|
let availableFiles = [];
|
|
50
46
|
let customCommandsList = [];
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
CustomCommandManager.listCommands().then(cmds => {
|
|
56
|
-
customCommandsList = cmds.map(c => ({ cmd: c.cmd, desc: c.desc }));
|
|
57
|
-
}).catch(() => { });
|
|
58
|
-
const pastes = [];
|
|
47
|
+
scanProjectFiles().then((f) => (availableFiles = f)).catch(() => { });
|
|
48
|
+
CustomCommandManager.listCommands()
|
|
49
|
+
.then((c) => (customCommandsList = c.map((x) => ({ cmd: x.cmd, desc: x.desc }))))
|
|
50
|
+
.catch(() => { });
|
|
59
51
|
const imageAttachments = [];
|
|
60
52
|
const usedImageNames = new Set();
|
|
61
|
-
const
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
const matched = themes.filter(t => !afterCmd ||
|
|
75
|
-
t.id.toLowerCase().startsWith(afterCmd) ||
|
|
76
|
-
t.name.toLowerCase().includes(afterCmd));
|
|
77
|
-
const list = [];
|
|
78
|
-
if (!afterCmd || '/theme'.startsWith(input.trim().toLowerCase())) {
|
|
79
|
-
list.push({
|
|
80
|
-
label: '/theme',
|
|
81
|
-
desc: 'Interactive UI theme picker menu',
|
|
82
|
-
replacement: '/theme',
|
|
83
|
-
replaceStart: 0,
|
|
84
|
-
replaceLen: input.length
|
|
85
|
-
});
|
|
86
|
-
}
|
|
87
|
-
for (const t of matched) {
|
|
88
|
-
list.push({
|
|
89
|
-
label: `/theme ${t.id}`,
|
|
90
|
-
desc: `${t.emoji} ${t.name} (${t.desc})`,
|
|
91
|
-
replacement: `/theme ${t.id}`,
|
|
92
|
-
replaceStart: 0,
|
|
93
|
-
replaceLen: input.length
|
|
94
|
-
});
|
|
95
|
-
}
|
|
96
|
-
return list;
|
|
97
|
-
}
|
|
98
|
-
if (input.startsWith('/')) {
|
|
99
|
-
const q = input.trim().toLowerCase();
|
|
100
|
-
const baseList = [...SLASH_COMMANDS];
|
|
101
|
-
for (const cc of customCommandsList) {
|
|
102
|
-
if (!baseList.some(b => b.cmd === cc.cmd)) {
|
|
103
|
-
baseList.push({ cmd: cc.cmd, desc: cc.desc });
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
const filtered = baseList.filter(c => c.cmd.toLowerCase().startsWith(q) || q === '/');
|
|
107
|
-
return filtered.map(c => ({
|
|
108
|
-
label: c.cmd,
|
|
109
|
-
desc: c.desc,
|
|
110
|
-
replacement: c.cmd,
|
|
111
|
-
replaceStart: 0,
|
|
112
|
-
replaceLen: input.length
|
|
113
|
-
}));
|
|
114
|
-
}
|
|
115
|
-
// Check for @ mention at cursor position
|
|
116
|
-
const beforeCursor = input.slice(0, cursorPos);
|
|
117
|
-
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_\-./]*)$/);
|
|
118
66
|
if (atMatch && availableFiles.length > 0) {
|
|
119
67
|
const query = atMatch[1].toLowerCase();
|
|
120
|
-
const
|
|
121
|
-
.filter(f => f.toLowerCase().includes(query) || query === '')
|
|
122
|
-
.slice(0,
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
}
|
|
139
|
-
for (const img of imageAttachments) {
|
|
140
|
-
const styled = pc.bold(pc.magenta(img.tag));
|
|
141
|
-
formatted = formatted.split(img.tag).join(styled);
|
|
142
|
-
}
|
|
143
|
-
return formatted;
|
|
68
|
+
const hits = availableFiles
|
|
69
|
+
.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();
|
|
144
86
|
}
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
process.stdout.write('\n');
|
|
167
|
-
}
|
|
168
|
-
if (lastTotalLines > 1) {
|
|
169
|
-
process.stdout.write(`\x1b[${lastTotalLines - 1}A`);
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
function render() {
|
|
173
|
-
if (disposed)
|
|
174
|
-
return;
|
|
175
|
-
const items = getDropdownItems();
|
|
176
|
-
const cols = Math.max(28, process.stdout.columns || 80);
|
|
177
|
-
const rows = Math.max(8, process.stdout.rows || 24);
|
|
178
|
-
const prefixLen = 3;
|
|
179
|
-
const maxPerLine = Math.max(10, cols - prefixLen - 1);
|
|
180
|
-
const allLines = [];
|
|
181
|
-
let inputLineCount = 0;
|
|
182
|
-
if (input.length === 0) {
|
|
183
|
-
const displayPlace = placeholder.length > maxPerLine ? placeholder.slice(0, maxPerLine - 1) + '…' : placeholder;
|
|
184
|
-
allLines.push(pc.dim('│') + ' ' + pc.dim(displayPlace));
|
|
185
|
-
inputLineCount = 1;
|
|
186
|
-
}
|
|
187
|
-
else {
|
|
188
|
-
let pos = 0;
|
|
189
|
-
while (pos < input.length) {
|
|
190
|
-
const chunk = input.slice(pos, pos + maxPerLine);
|
|
191
|
-
allLines.push(pc.dim('│') + ' ' + formatInputWithBadges(chunk));
|
|
192
|
-
pos += maxPerLine;
|
|
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;
|
|
193
108
|
}
|
|
194
|
-
inputLineCount = allLines.length;
|
|
195
109
|
}
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
startIndex = Math.min(selectedIndex - pageSize + 1, total - pageSize);
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
const endIndex = Math.min(startIndex + pageSize, total);
|
|
214
|
-
const hasMoreUp = startIndex > 0;
|
|
215
|
-
const hasMoreDown = endIndex < total;
|
|
216
|
-
let topBorderStr = '─'.repeat(innerBoxWidth);
|
|
217
|
-
if (hasMoreUp) {
|
|
218
|
-
const mid = Math.max(0, Math.floor(innerBoxWidth / 2) - 2);
|
|
219
|
-
topBorderStr = '─'.repeat(mid) + ' ▲ ' + '─'.repeat(Math.max(0, innerBoxWidth - mid - 3));
|
|
220
|
-
}
|
|
221
|
-
let botBorderStr = '─'.repeat(innerBoxWidth);
|
|
222
|
-
if (hasMoreDown) {
|
|
223
|
-
const mid = Math.max(0, Math.floor(innerBoxWidth / 2) - 2);
|
|
224
|
-
botBorderStr = '─'.repeat(mid) + ' ▼ ' + '─'.repeat(Math.max(0, innerBoxWidth - mid - 3));
|
|
225
|
-
}
|
|
226
|
-
allLines.push(pc.dim('│') + ' ' + pc.dim('╭' + topBorderStr + '╮'));
|
|
227
|
-
for (let i = startIndex; i < endIndex; i++) {
|
|
228
|
-
const item = items[i];
|
|
229
|
-
const isSelected = i === selectedIndex;
|
|
230
|
-
const pointer = isSelected ? '› ' : ' ';
|
|
231
|
-
const availWidth = innerBoxWidth - 2;
|
|
232
|
-
let row = '';
|
|
233
|
-
if (availWidth < 20) {
|
|
234
|
-
const labelStr = item.label.length > availWidth ? item.label.slice(0, availWidth - 1) + '…' : item.label.padEnd(availWidth);
|
|
235
|
-
const plain = pointer + labelStr;
|
|
236
|
-
row = isSelected ? theme.badgeFn(plain) : (pointer + theme.boldFn(labelStr));
|
|
237
|
-
}
|
|
238
|
-
else {
|
|
239
|
-
const labelMax = Math.min(15, Math.floor(availWidth * 0.45));
|
|
240
|
-
const labelStr = item.label.length > labelMax ? item.label.slice(0, labelMax - 1) + '…' : item.label.padEnd(labelMax);
|
|
241
|
-
const descMax = availWidth - labelMax - 1;
|
|
242
|
-
const descStr = item.desc.length > descMax ? item.desc.slice(0, descMax - 1) + '…' : item.desc.padEnd(descMax);
|
|
243
|
-
const plain = `${pointer}${labelStr} ${descStr}`;
|
|
244
|
-
if (isSelected) {
|
|
245
|
-
row = theme.badgeFn(plain);
|
|
246
|
-
}
|
|
247
|
-
else {
|
|
248
|
-
row = `${pointer}${theme.boldFn(labelStr)} ${pc.gray(descStr)}`;
|
|
249
|
-
}
|
|
250
|
-
}
|
|
251
|
-
const currentLen = stripAnsi(row).length;
|
|
252
|
-
if (currentLen < innerBoxWidth) {
|
|
253
|
-
row += ' '.repeat(innerBoxWidth - currentLen);
|
|
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} `);
|
|
254
124
|
}
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
allLines.push(pc.dim('│') + ' ' + pc.dim('╰' + botBorderStr + '╯'));
|
|
125
|
+
})
|
|
126
|
+
.catch(() => { });
|
|
258
127
|
}
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
if (i < allLines.length) {
|
|
264
|
-
process.stdout.write(allLines[i]);
|
|
265
|
-
}
|
|
266
|
-
if (i < maxLinesToWrite - 1) {
|
|
267
|
-
process.stdout.write('\n');
|
|
268
|
-
}
|
|
269
|
-
}
|
|
270
|
-
const cursorInputLine = input.length === 0 ? 0 : Math.min(Math.floor(cursorPos / maxPerLine), inputLineCount - 1);
|
|
271
|
-
const cursorCol = input.length === 0 ? prefixLen : prefixLen + (cursorPos % maxPerLine);
|
|
272
|
-
const currentLine = maxLinesToWrite - 1;
|
|
273
|
-
const moveUp = currentLine - cursorInputLine;
|
|
274
|
-
if (moveUp > 0) {
|
|
275
|
-
process.stdout.write(`\x1b[${moveUp}A`);
|
|
276
|
-
}
|
|
277
|
-
process.stdout.write('\r');
|
|
278
|
-
if (cursorCol > 0) {
|
|
279
|
-
process.stdout.write(`\x1b[${cursorCol}C`);
|
|
280
|
-
}
|
|
281
|
-
lastTotalLines = allLines.length;
|
|
128
|
+
};
|
|
129
|
+
if (process.stdin.isTTY) {
|
|
130
|
+
readline.emitKeypressEvents(process.stdin, rl);
|
|
131
|
+
process.stdin.on('keypress', onKeypress);
|
|
282
132
|
}
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
disposed = true;
|
|
286
|
-
if (process.stdout.isTTY) {
|
|
287
|
-
process.stdout.write('\x1b[?2004l');
|
|
288
|
-
}
|
|
289
|
-
process.stdin.removeListener('data', onData);
|
|
290
|
-
if (process.stdin.isTTY) {
|
|
291
|
-
process.stdin.setRawMode(false);
|
|
292
|
-
}
|
|
293
|
-
process.stdin.pause();
|
|
133
|
+
if (opts.initialValue) {
|
|
134
|
+
rl.write(opts.initialValue);
|
|
294
135
|
}
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
process.stdout.write('\r\x1b[2K');
|
|
298
|
-
const fullText = expandPastes(finalInput);
|
|
299
|
-
if (fullText.trim()) {
|
|
300
|
-
if (GLOBAL_PROMPT_HISTORY.length === 0 || GLOBAL_PROMPT_HISTORY[GLOBAL_PROMPT_HISTORY.length - 1] !== fullText.trim()) {
|
|
301
|
-
GLOBAL_PROMPT_HISTORY.push(fullText.trim());
|
|
302
|
-
}
|
|
303
|
-
}
|
|
304
|
-
const lines = fullText.split('\n');
|
|
305
|
-
process.stdout.write(`${pc.dim('│')} ${formatInputWithBadges(lines[0])}\n`);
|
|
306
|
-
for (let i = 1; i < lines.length; i++) {
|
|
307
|
-
process.stdout.write(pc.dim('│') + ' ' + lines[i] + '\n');
|
|
308
|
-
}
|
|
309
|
-
process.stdout.write('\n');
|
|
136
|
+
rl.prompt();
|
|
137
|
+
rl.on('line', async (rawLine) => {
|
|
310
138
|
cleanup();
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
const pathCandidates = cleaned.split(/[&;\n\r]+/).map(s => s.trim()).filter(Boolean);
|
|
317
|
-
let foundAnyImage = false;
|
|
318
|
-
for (const cand of pathCandidates) {
|
|
319
|
-
const imgRes = await processPastedFilePath(cand, usedImageNames);
|
|
320
|
-
if (imgRes) {
|
|
321
|
-
foundAnyImage = true;
|
|
322
|
-
const tag = `[${imgRes.fileName} ${imgRes.sizeStr}]`;
|
|
323
|
-
imageAttachments.push({
|
|
324
|
-
tag,
|
|
325
|
-
fileName: imgRes.fileName,
|
|
326
|
-
filePath: imgRes.filePath,
|
|
327
|
-
sizeStr: imgRes.sizeStr
|
|
328
|
-
});
|
|
329
|
-
usedImageNames.add(imgRes.fileName);
|
|
330
|
-
input = input.slice(0, cursorPos) + tag + ' ' + input.slice(cursorPos);
|
|
331
|
-
cursorPos += tag.length + 1;
|
|
332
|
-
}
|
|
333
|
-
}
|
|
334
|
-
if (foundAnyImage) {
|
|
335
|
-
selectedIndex = 0;
|
|
336
|
-
render();
|
|
337
|
-
return;
|
|
338
|
-
}
|
|
339
|
-
const normalized = cleaned.replace(/\r\n/g, '\n').replace(/\r/g, '\n');
|
|
340
|
-
const lines = normalized.split('\n');
|
|
341
|
-
if (lines.length >= 2 || normalized.length > 80) {
|
|
342
|
-
const linesCount = lines.length;
|
|
343
|
-
const id = pastes.length + 1;
|
|
344
|
-
const tag = `[Pasted text #${id} +${linesCount} lines]`;
|
|
345
|
-
pastes.push({ id, tag, content: normalized, linesCount });
|
|
346
|
-
input = input.slice(0, cursorPos) + tag + input.slice(cursorPos);
|
|
347
|
-
cursorPos += tag.length;
|
|
348
|
-
selectedIndex = 0;
|
|
349
|
-
render();
|
|
350
|
-
}
|
|
351
|
-
else {
|
|
352
|
-
input = input.slice(0, cursorPos) + normalized + input.slice(cursorPos);
|
|
353
|
-
cursorPos += normalized.length;
|
|
354
|
-
selectedIndex = 0;
|
|
355
|
-
render();
|
|
356
|
-
}
|
|
357
|
-
}
|
|
358
|
-
function getTagSpans() {
|
|
359
|
-
const spans = [];
|
|
360
|
-
for (const p of pastes) {
|
|
361
|
-
let pos = 0;
|
|
362
|
-
while ((pos = input.indexOf(p.tag, pos)) !== -1) {
|
|
363
|
-
spans.push({
|
|
364
|
-
start: pos,
|
|
365
|
-
end: pos + p.tag.length,
|
|
366
|
-
tag: p.tag
|
|
367
|
-
});
|
|
368
|
-
pos += p.tag.length;
|
|
369
|
-
}
|
|
370
|
-
}
|
|
371
|
-
for (const img of imageAttachments) {
|
|
372
|
-
let pos = 0;
|
|
373
|
-
while ((pos = input.indexOf(img.tag, pos)) !== -1) {
|
|
374
|
-
spans.push({
|
|
375
|
-
start: pos,
|
|
376
|
-
end: pos + img.tag.length,
|
|
377
|
-
tag: img.tag
|
|
378
|
-
});
|
|
379
|
-
pos += img.tag.length;
|
|
380
|
-
}
|
|
381
|
-
}
|
|
382
|
-
return spans.sort((a, b) => a.start - b.start);
|
|
383
|
-
}
|
|
384
|
-
let pasteBuffer = '';
|
|
385
|
-
let inBracketedPaste = false;
|
|
386
|
-
function onData(chunk) {
|
|
387
|
-
if (disposed)
|
|
388
|
-
return;
|
|
389
|
-
const str = chunk.toString('utf8');
|
|
390
|
-
// Check for bracketed paste start/end
|
|
391
|
-
if (str.includes('\x1b[200~')) {
|
|
392
|
-
inBracketedPaste = true;
|
|
393
|
-
pasteBuffer = '';
|
|
394
|
-
}
|
|
395
|
-
if (inBracketedPaste) {
|
|
396
|
-
pasteBuffer += str;
|
|
397
|
-
if (pasteBuffer.includes('\x1b[201~')) {
|
|
398
|
-
inBracketedPaste = false;
|
|
399
|
-
handlePaste(pasteBuffer);
|
|
400
|
-
pasteBuffer = '';
|
|
401
|
-
}
|
|
402
|
-
return;
|
|
403
|
-
}
|
|
404
|
-
// Check for raw multi-character paste with newlines or large size
|
|
405
|
-
if (str.length > 1 && (str.includes('\n') || str.includes('\r') || str.length > 80)) {
|
|
406
|
-
handlePaste(str);
|
|
407
|
-
return;
|
|
408
|
-
}
|
|
409
|
-
// Handle individual keys
|
|
410
|
-
// Ctrl+V (ASCII 22 / 0x16) or Ctrl+P (ASCII 16 / 0x10)
|
|
411
|
-
if (str === '\x16' || str === '\x10' || (str.length === 1 && (str.charCodeAt(0) === 22 || str.charCodeAt(0) === 16))) {
|
|
412
|
-
saveClipboardImage('image.png', usedImageNames).then((imgRes) => {
|
|
139
|
+
let line = rawLine.trim();
|
|
140
|
+
// Handle direct /image command
|
|
141
|
+
if (line === '/image') {
|
|
142
|
+
try {
|
|
143
|
+
const imgRes = await saveClipboardImage('image.png', usedImageNames);
|
|
413
144
|
if (imgRes) {
|
|
414
145
|
const tag = `[${imgRes.fileName} ${imgRes.sizeStr}]`;
|
|
415
146
|
imageAttachments.push({
|
|
@@ -419,232 +150,52 @@ export function askPrompt(opts = {}) {
|
|
|
419
150
|
sizeStr: imgRes.sizeStr
|
|
420
151
|
});
|
|
421
152
|
usedImageNames.add(imgRes.fileName);
|
|
422
|
-
|
|
423
|
-
cursorPos += tag.length + 1;
|
|
424
|
-
render();
|
|
425
|
-
}
|
|
426
|
-
}).catch(() => { });
|
|
427
|
-
return;
|
|
428
|
-
}
|
|
429
|
-
// Ctrl+C
|
|
430
|
-
if (str === '\x03' || (str.length === 1 && str.charCodeAt(0) === 3)) {
|
|
431
|
-
clearPreviousRender();
|
|
432
|
-
process.stdout.write('\r\x1b[2K\n');
|
|
433
|
-
cleanup();
|
|
434
|
-
resolve('__CANCEL__');
|
|
435
|
-
return;
|
|
436
|
-
}
|
|
437
|
-
const items = getDropdownItems();
|
|
438
|
-
// Enter / Return
|
|
439
|
-
if (str === '\r' || str === '\n' || (str.length === 1 && (str.charCodeAt(0) === 13 || str.charCodeAt(0) === 10))) {
|
|
440
|
-
// Direct /image command
|
|
441
|
-
if (input.trim() === '/image' || (items.length > 0 && selectedIndex >= 0 && selectedIndex < items.length && items[selectedIndex].label === '/image')) {
|
|
442
|
-
saveClipboardImage('image.png', usedImageNames).then((imgRes) => {
|
|
443
|
-
if (imgRes) {
|
|
444
|
-
const tag = `[${imgRes.fileName} ${imgRes.sizeStr}]`;
|
|
445
|
-
imageAttachments.push({
|
|
446
|
-
tag,
|
|
447
|
-
fileName: imgRes.fileName,
|
|
448
|
-
filePath: imgRes.filePath,
|
|
449
|
-
sizeStr: imgRes.sizeStr
|
|
450
|
-
});
|
|
451
|
-
usedImageNames.add(imgRes.fileName);
|
|
452
|
-
input = `${tag} `;
|
|
453
|
-
cursorPos = input.length;
|
|
454
|
-
render();
|
|
455
|
-
}
|
|
456
|
-
else {
|
|
457
|
-
process.stdout.write(`\r\x1b[2K${pc.yellow('⚠️ No image in clipboard. Take a screenshot first (Win+Shift+S)\n')}`);
|
|
458
|
-
input = '';
|
|
459
|
-
cursorPos = 0;
|
|
460
|
-
render();
|
|
461
|
-
}
|
|
462
|
-
}).catch(() => { });
|
|
463
|
-
return;
|
|
464
|
-
}
|
|
465
|
-
if (items.length > 0 && selectedIndex >= 0 && selectedIndex < items.length) {
|
|
466
|
-
const selected = items[selectedIndex];
|
|
467
|
-
if (input.startsWith('/')) {
|
|
468
|
-
input = selected.replacement;
|
|
469
|
-
clearBoxAndExit(input);
|
|
470
|
-
return;
|
|
153
|
+
line = tag;
|
|
471
154
|
}
|
|
472
155
|
else {
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
cursorPos = selected.replaceStart + selected.replacement.length;
|
|
476
|
-
render();
|
|
156
|
+
console.log(pc.yellow('⚠️ No image in clipboard. Take a screenshot first (Win+Shift+S)\n'));
|
|
157
|
+
resolve('');
|
|
477
158
|
return;
|
|
478
159
|
}
|
|
479
160
|
}
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
// Tab
|
|
484
|
-
if (str === '\t' || (str.length === 1 && str.charCodeAt(0) === 9)) {
|
|
485
|
-
if (items.length > 0 && selectedIndex >= 0 && selectedIndex < items.length) {
|
|
486
|
-
const selected = items[selectedIndex];
|
|
487
|
-
input = input.slice(0, selected.replaceStart) + selected.replacement + input.slice(selected.replaceStart + selected.replaceLen);
|
|
488
|
-
cursorPos = selected.replaceStart + selected.replacement.length;
|
|
489
|
-
render();
|
|
490
|
-
}
|
|
491
|
-
else {
|
|
492
|
-
clearPreviousRender();
|
|
493
|
-
process.stdout.write('\r\x1b[2K');
|
|
494
|
-
cleanup();
|
|
495
|
-
resolve(`__TOGGLE_MODE__:${input}`);
|
|
496
|
-
}
|
|
497
|
-
return;
|
|
498
|
-
}
|
|
499
|
-
// Up Arrow
|
|
500
|
-
if (str === '\x1b[A' || str === '\x1bOA') {
|
|
501
|
-
if (items.length > 0) {
|
|
502
|
-
selectedIndex = (selectedIndex - 1 + items.length) % items.length;
|
|
503
|
-
render();
|
|
504
|
-
}
|
|
505
|
-
else if (GLOBAL_PROMPT_HISTORY.length > 0 && historyIndex > 0) {
|
|
506
|
-
if (historyIndex === GLOBAL_PROMPT_HISTORY.length) {
|
|
507
|
-
tempDraft = input;
|
|
508
|
-
}
|
|
509
|
-
historyIndex--;
|
|
510
|
-
input = GLOBAL_PROMPT_HISTORY[historyIndex];
|
|
511
|
-
cursorPos = input.length;
|
|
512
|
-
render();
|
|
513
|
-
}
|
|
514
|
-
return;
|
|
515
|
-
}
|
|
516
|
-
// Down Arrow
|
|
517
|
-
if (str === '\x1b[B' || str === '\x1bOB') {
|
|
518
|
-
if (items.length > 0) {
|
|
519
|
-
selectedIndex = (selectedIndex + 1) % items.length;
|
|
520
|
-
render();
|
|
521
|
-
}
|
|
522
|
-
else if (historyIndex < GLOBAL_PROMPT_HISTORY.length) {
|
|
523
|
-
historyIndex++;
|
|
524
|
-
if (historyIndex === GLOBAL_PROMPT_HISTORY.length) {
|
|
525
|
-
input = tempDraft;
|
|
526
|
-
}
|
|
527
|
-
else {
|
|
528
|
-
input = GLOBAL_PROMPT_HISTORY[historyIndex];
|
|
529
|
-
}
|
|
530
|
-
cursorPos = input.length;
|
|
531
|
-
render();
|
|
532
|
-
}
|
|
533
|
-
return;
|
|
534
|
-
}
|
|
535
|
-
// Left Arrow (Jump across whole paste badge atomically)
|
|
536
|
-
if (str === '\x1b[D' || str === '\x1bOD') {
|
|
537
|
-
if (cursorPos > 0) {
|
|
538
|
-
const spans = getTagSpans();
|
|
539
|
-
const endingSpan = spans.find(s => s.end === cursorPos);
|
|
540
|
-
if (endingSpan) {
|
|
541
|
-
cursorPos = endingSpan.start;
|
|
542
|
-
}
|
|
543
|
-
else {
|
|
544
|
-
cursorPos--;
|
|
545
|
-
const inside = spans.find(s => cursorPos > s.start && cursorPos < s.end);
|
|
546
|
-
if (inside)
|
|
547
|
-
cursorPos = inside.start;
|
|
548
|
-
}
|
|
549
|
-
render();
|
|
161
|
+
catch {
|
|
162
|
+
resolve('');
|
|
163
|
+
return;
|
|
550
164
|
}
|
|
551
|
-
return;
|
|
552
165
|
}
|
|
553
|
-
//
|
|
554
|
-
if (
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
const
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
}
|
|
567
|
-
render();
|
|
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;
|
|
568
179
|
}
|
|
569
|
-
return;
|
|
570
180
|
}
|
|
571
|
-
//
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
return;
|
|
576
|
-
}
|
|
577
|
-
// End
|
|
578
|
-
if (str === '\x1b[F' || str === '\x1b[4~') {
|
|
579
|
-
cursorPos = input.length;
|
|
580
|
-
render();
|
|
581
|
-
return;
|
|
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, '/')} `);
|
|
582
185
|
}
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
const startingSpan = spans.find(s => s.start === cursorPos);
|
|
588
|
-
if (startingSpan) {
|
|
589
|
-
input = input.slice(0, startingSpan.start) + input.slice(startingSpan.end);
|
|
590
|
-
}
|
|
591
|
-
else {
|
|
592
|
-
input = input.slice(0, cursorPos) + input.slice(cursorPos + 1);
|
|
593
|
-
}
|
|
594
|
-
selectedIndex = 0;
|
|
595
|
-
render();
|
|
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());
|
|
596
190
|
}
|
|
597
|
-
return;
|
|
598
191
|
}
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
if (endingSpan) {
|
|
608
|
-
input = input.slice(0, endingSpan.start) + input.slice(endingSpan.end);
|
|
609
|
-
cursorPos = endingSpan.start;
|
|
610
|
-
}
|
|
611
|
-
else {
|
|
612
|
-
input = input.slice(0, cursorPos - 1) + input.slice(cursorPos);
|
|
613
|
-
cursorPos--;
|
|
614
|
-
}
|
|
615
|
-
}
|
|
616
|
-
}
|
|
617
|
-
else if (ch.charCodeAt(0) >= 32) {
|
|
618
|
-
const spans = getTagSpans();
|
|
619
|
-
const inside = spans.find(s => cursorPos > s.start && cursorPos < s.end);
|
|
620
|
-
if (inside)
|
|
621
|
-
cursorPos = inside.end;
|
|
622
|
-
input = input.slice(0, cursorPos) + ch + input.slice(cursorPos);
|
|
623
|
-
cursorPos++;
|
|
624
|
-
}
|
|
625
|
-
}
|
|
626
|
-
selectedIndex = 0;
|
|
627
|
-
render();
|
|
628
|
-
return;
|
|
629
|
-
}
|
|
630
|
-
// Ignore unknown escape sequences
|
|
631
|
-
if (str.startsWith('\x1b')) {
|
|
632
|
-
return;
|
|
633
|
-
}
|
|
634
|
-
// Normal character input - clean control characters
|
|
635
|
-
const cleanStr = str.replace(/[\x00-\x08\x0b\x0c\x0e-\x1f\x7f]/g, '');
|
|
636
|
-
if (!cleanStr)
|
|
637
|
-
return;
|
|
638
|
-
const spans = getTagSpans();
|
|
639
|
-
const inside = spans.find(s => cursorPos > s.start && cursorPos < s.end);
|
|
640
|
-
if (inside) {
|
|
641
|
-
cursorPos = inside.end;
|
|
642
|
-
}
|
|
643
|
-
input = input.slice(0, cursorPos) + cleanStr + input.slice(cursorPos);
|
|
644
|
-
cursorPos += cleanStr.length;
|
|
645
|
-
selectedIndex = 0;
|
|
646
|
-
render();
|
|
647
|
-
}
|
|
648
|
-
process.stdin.on('data', onData);
|
|
192
|
+
console.log();
|
|
193
|
+
resolve(expanded);
|
|
194
|
+
});
|
|
195
|
+
rl.on('SIGINT', () => {
|
|
196
|
+
cleanup();
|
|
197
|
+
console.log();
|
|
198
|
+
resolve('__CANCEL__');
|
|
199
|
+
});
|
|
649
200
|
});
|
|
650
201
|
}
|
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.7 • Terminal-Native AI Assistant</div>
|
|
143
143
|
</div>
|
|
144
144
|
</body>
|
|
145
145
|
</html>`;
|
package/dist/mcp/client.js
CHANGED
package/package.json
CHANGED