termux-dev 1.1.1 → 1.2.0
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/assets/preview.png +0 -0
- package/dist/cli/doctor.js +141 -0
- package/dist/cli/index.js +210 -42
- package/dist/cli/prompt.js +34 -3
- package/dist/cli/server.js +218 -40
- package/dist/cli/theme.js +140 -0
- package/dist/core/loop.js +1 -1
- package/dist/core/notify.js +40 -0
- package/dist/core/snapshot.js +2 -6
- package/dist/prompts/builder.js +2 -1
- package/dist/providers/openai.js +23 -1
- package/dist/tools/fs.js +21 -9
- package/dist/tools/index.js +3 -2
- package/dist/tools/server.js +47 -0
- package/package.json +4 -2
package/dist/tools/fs.js
CHANGED
|
@@ -63,13 +63,20 @@ export const writeFileTool = {
|
|
|
63
63
|
}
|
|
64
64
|
catch { }
|
|
65
65
|
await fs.writeFile(args.path, args.content, 'utf8');
|
|
66
|
-
const
|
|
66
|
+
const contentLines = args.content.split('\n');
|
|
67
|
+
const newLines = contentLines.length;
|
|
68
|
+
const diffLines = [];
|
|
69
|
+
const showLines = Math.min(contentLines.length, 6);
|
|
70
|
+
for (let i = 0; i < showLines; i++) {
|
|
71
|
+
diffLines.push(`${i + 1} + ${contentLines[i]}`);
|
|
72
|
+
}
|
|
67
73
|
if (!existed) {
|
|
68
74
|
return JSON.stringify({
|
|
69
75
|
status: 'success',
|
|
70
|
-
action: '
|
|
76
|
+
action: 'edit',
|
|
71
77
|
path: args.path,
|
|
72
78
|
addedCount: newLines,
|
|
79
|
+
diffLines,
|
|
73
80
|
summary: `Successfully created ${args.path} (+${newLines} lines)`
|
|
74
81
|
});
|
|
75
82
|
}
|
|
@@ -78,9 +85,10 @@ export const writeFileTool = {
|
|
|
78
85
|
const diffStr = diff >= 0 ? `+${diff}` : `${diff}`;
|
|
79
86
|
return JSON.stringify({
|
|
80
87
|
status: 'success',
|
|
81
|
-
action: '
|
|
88
|
+
action: 'edit',
|
|
82
89
|
path: args.path,
|
|
83
90
|
addedCount: newLines,
|
|
91
|
+
diffLines,
|
|
84
92
|
summary: `Successfully updated ${args.path} (${diffStr} lines, ${newLines} total)`
|
|
85
93
|
});
|
|
86
94
|
}
|
|
@@ -131,16 +139,20 @@ export const editFileTool = {
|
|
|
131
139
|
}
|
|
132
140
|
}
|
|
133
141
|
const targetIndex = content.indexOf(target);
|
|
142
|
+
const allLines = content.split('\n');
|
|
134
143
|
const startLine = content.slice(0, targetIndex).split('\n').length;
|
|
135
144
|
const removedArr = target.split('\n');
|
|
145
|
+
const endLine = startLine + removedArr.length - 1;
|
|
146
|
+
const contextBefore = allLines.slice(Math.max(0, startLine - 3), startLine - 1);
|
|
147
|
+
const contextAfter = allLines.slice(endLine, Math.min(allLines.length, endLine + 2));
|
|
136
148
|
const addedArr = args.replacement.split('\n');
|
|
137
149
|
const diffLines = [];
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
});
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
});
|
|
150
|
+
let lineCounter = startLine - contextBefore.length;
|
|
151
|
+
contextBefore.forEach((l) => diffLines.push(`${lineCounter++} ${l}`));
|
|
152
|
+
removedArr.forEach((l) => diffLines.push(`${lineCounter++} - ${l}`));
|
|
153
|
+
let addCounter = startLine;
|
|
154
|
+
addedArr.forEach((l) => diffLines.push(`${addCounter++} + ${l}`));
|
|
155
|
+
contextAfter.forEach((l) => diffLines.push(`${addCounter++} ${l}`));
|
|
144
156
|
const newContent = content.replace(target, args.replacement);
|
|
145
157
|
await fs.writeFile(args.path, newContent, 'utf8');
|
|
146
158
|
return JSON.stringify({
|
package/dist/tools/index.js
CHANGED
|
@@ -8,11 +8,12 @@ import { installPackageTool } from './packages.js';
|
|
|
8
8
|
import { saveMemoryTool } from '../core/memory.js';
|
|
9
9
|
import { planReadyTool, lastPlanReady, resetPlanReady } from './plan.js';
|
|
10
10
|
import { todoListTool, currentTodoList, resetTodoList } from './todo.js';
|
|
11
|
+
import { servePreviewTool } from './server.js';
|
|
11
12
|
export function getTools(planMode) {
|
|
12
13
|
const baseTools = [readFileTool, listDirTool, searchTool, askQuestionsTool, webSearchTool, fetchUrlTool, saveMemoryTool, planReadyTool, todoListTool];
|
|
13
14
|
if (planMode) {
|
|
14
15
|
return baseTools;
|
|
15
16
|
}
|
|
16
|
-
return [...baseTools, writeFileTool, editFileTool, mkdirTool, bashTool, diagnoseCodeTool, installPackageTool];
|
|
17
|
+
return [...baseTools, writeFileTool, editFileTool, mkdirTool, bashTool, diagnoseCodeTool, installPackageTool, servePreviewTool];
|
|
17
18
|
}
|
|
18
|
-
export { webSearchTool, fetchUrlTool, diagnoseCodeTool, installPackageTool, saveMemoryTool, planReadyTool, lastPlanReady, resetPlanReady, todoListTool, currentTodoList, resetTodoList };
|
|
19
|
+
export { webSearchTool, fetchUrlTool, diagnoseCodeTool, installPackageTool, saveMemoryTool, planReadyTool, lastPlanReady, resetPlanReady, todoListTool, currentTodoList, resetTodoList, servePreviewTool };
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { startServer, stopServer, isServerRunning, getServerPort, displayServerBanner } from '../cli/server.js';
|
|
2
|
+
export const servePreviewTool = {
|
|
3
|
+
name: 'serve_preview',
|
|
4
|
+
definition: {
|
|
5
|
+
name: 'serve_preview',
|
|
6
|
+
description: 'Start or stop the built-in local live web preview server to view HTML/web apps in the browser with instant QR-code.',
|
|
7
|
+
parameters: {
|
|
8
|
+
type: 'object',
|
|
9
|
+
properties: {
|
|
10
|
+
action: {
|
|
11
|
+
type: 'string',
|
|
12
|
+
enum: ['start', 'stop', 'status'],
|
|
13
|
+
description: 'Action to perform: start the server, stop it, or check status'
|
|
14
|
+
},
|
|
15
|
+
port: {
|
|
16
|
+
type: 'number',
|
|
17
|
+
description: 'Optional preferred port number (defaults to 3000)'
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
required: ['action']
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
validateArgs: (args) => {
|
|
24
|
+
if (!args || !args.action) {
|
|
25
|
+
throw new Error('action is required');
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
execute: async (args) => {
|
|
29
|
+
if (args.action === 'stop') {
|
|
30
|
+
const stopped = stopServer();
|
|
31
|
+
return stopped ? 'Web preview server stopped.' : 'No web preview server was running.';
|
|
32
|
+
}
|
|
33
|
+
if (args.action === 'status') {
|
|
34
|
+
const running = isServerRunning();
|
|
35
|
+
return running ? `Web server is running on port ${getServerPort()}.` : 'Web server is not running.';
|
|
36
|
+
}
|
|
37
|
+
const preferredPort = args.port || 3000;
|
|
38
|
+
try {
|
|
39
|
+
const { port, localUrl, networkUrl } = await startServer(preferredPort);
|
|
40
|
+
await displayServerBanner(localUrl, networkUrl);
|
|
41
|
+
return `Web Server is now live!\n• Local URL: ${localUrl}\n• Network URL: ${networkUrl}\nOpened in browser automatically with mobile QR-code displayed in terminal.`;
|
|
42
|
+
}
|
|
43
|
+
catch (err) {
|
|
44
|
+
throw new Error(`Failed to start web server: ${err.message}`);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "termux-dev",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
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",
|
|
@@ -54,11 +54,13 @@
|
|
|
54
54
|
"commander": "^12.0.0",
|
|
55
55
|
"marked": "^15.0.12",
|
|
56
56
|
"marked-terminal": "^7.3.0",
|
|
57
|
-
"picocolors": "^1.1.1"
|
|
57
|
+
"picocolors": "^1.1.1",
|
|
58
|
+
"qrcode-terminal": "^0.12.0"
|
|
58
59
|
},
|
|
59
60
|
"devDependencies": {
|
|
60
61
|
"@types/marked-terminal": "^6.1.1",
|
|
61
62
|
"@types/node": "^20.0.0",
|
|
63
|
+
"@types/qrcode-terminal": "^0.12.2",
|
|
62
64
|
"typescript": "^5.4.0"
|
|
63
65
|
}
|
|
64
66
|
}
|