termux-dev 1.0.2
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/LICENSE +21 -0
- package/README.md +290 -0
- package/assets/banner.svg +33 -0
- package/assets/preview.png +0 -0
- package/bin/devx.js +2 -0
- package/dist/cli/clipboard.js +136 -0
- package/dist/cli/files.js +93 -0
- package/dist/cli/index.js +1506 -0
- package/dist/cli/markdown.js +147 -0
- package/dist/cli/prompt.js +553 -0
- package/dist/cli/providers.js +892 -0
- package/dist/cli/server.js +137 -0
- package/dist/cli/updater.js +245 -0
- package/dist/core/history.js +121 -0
- package/dist/core/loop.js +164 -0
- package/dist/core/memory.js +68 -0
- package/dist/core/models.js +72 -0
- package/dist/core/pricing.js +65 -0
- package/dist/core/session.js +129 -0
- package/dist/core/snapshot.js +88 -0
- package/dist/core/types.js +1 -0
- package/dist/permissions/guard.js +104 -0
- package/dist/prompts/builder.js +69 -0
- package/dist/providers/index.js +7 -0
- package/dist/providers/openai.js +318 -0
- package/dist/tools/bash.js +51 -0
- package/dist/tools/diagnostics.js +63 -0
- package/dist/tools/fs.js +185 -0
- package/dist/tools/index.js +17 -0
- package/dist/tools/packages.js +80 -0
- package/dist/tools/plan.js +52 -0
- package/dist/tools/questions.js +101 -0
- package/dist/tools/search.js +90 -0
- package/dist/tools/web.js +155 -0
- package/package.json +64 -0
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import { marked } from 'marked';
|
|
2
|
+
import { markedTerminal } from 'marked-terminal';
|
|
3
|
+
import pc from 'picocolors';
|
|
4
|
+
marked.use(markedTerminal({
|
|
5
|
+
width: Math.min(process.stdout.columns || 80, 100),
|
|
6
|
+
reflowText: false,
|
|
7
|
+
tab: 2
|
|
8
|
+
}));
|
|
9
|
+
export function renderMarkdown(content) {
|
|
10
|
+
if (!content)
|
|
11
|
+
return '';
|
|
12
|
+
try {
|
|
13
|
+
return marked.parse(content).trim();
|
|
14
|
+
}
|
|
15
|
+
catch {
|
|
16
|
+
return content;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Ultra-fast, lightweight streaming markdown renderer optimized for Termux & desktop CLI.
|
|
21
|
+
* Avoids heavy synchronous AST re-parsing on every chunk, keeping token streaming buttery smooth.
|
|
22
|
+
*/
|
|
23
|
+
export class MarkdownStreamer {
|
|
24
|
+
buffer = '';
|
|
25
|
+
inCodeBlock = false;
|
|
26
|
+
codeBlockLang = '';
|
|
27
|
+
inTable = false;
|
|
28
|
+
tableBuffer = [];
|
|
29
|
+
push(chunk) {
|
|
30
|
+
this.buffer += chunk;
|
|
31
|
+
const lines = this.buffer.split('\n');
|
|
32
|
+
this.buffer = lines.pop() || '';
|
|
33
|
+
for (const line of lines) {
|
|
34
|
+
this.processLine(line);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
processLine(line) {
|
|
38
|
+
const trimmed = line.trim();
|
|
39
|
+
// 1. Code block boundary
|
|
40
|
+
if (trimmed.startsWith('```')) {
|
|
41
|
+
if (this.inCodeBlock) {
|
|
42
|
+
this.inCodeBlock = false;
|
|
43
|
+
this.codeBlockLang = '';
|
|
44
|
+
process.stdout.write(pc.dim('└' + '─'.repeat(Math.min(process.stdout.columns || 40, 50))) + '\n');
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
this.inCodeBlock = true;
|
|
49
|
+
this.codeBlockLang = trimmed.slice(3).trim();
|
|
50
|
+
const langTag = this.codeBlockLang ? ` [${this.codeBlockLang}] ` : ' ';
|
|
51
|
+
process.stdout.write('\n' + pc.cyan('┌─' + langTag + '─'.repeat(Math.max(2, Math.min(process.stdout.columns || 40, 50) - langTag.length - 2))) + '\n');
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
// 2. Inside code block: fast syntax-tinted output
|
|
56
|
+
if (this.inCodeBlock) {
|
|
57
|
+
process.stdout.write(pc.green('│ ') + pc.white(line) + '\n');
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
// 3. Tables
|
|
61
|
+
if (trimmed.startsWith('|') && trimmed.endsWith('|')) {
|
|
62
|
+
this.inTable = true;
|
|
63
|
+
this.tableBuffer.push(line);
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
if (this.inTable) {
|
|
67
|
+
this.flushTable();
|
|
68
|
+
this.inTable = false;
|
|
69
|
+
}
|
|
70
|
+
// 4. Regular line fast formatting (Headers, Bullets, Bold, Dims)
|
|
71
|
+
if (trimmed.startsWith('# ')) {
|
|
72
|
+
process.stdout.write('\n' + pc.bold(pc.cyan(trimmed.slice(2))) + '\n\n');
|
|
73
|
+
}
|
|
74
|
+
else if (trimmed.startsWith('## ')) {
|
|
75
|
+
process.stdout.write('\n' + pc.bold(pc.white(trimmed.slice(3))) + '\n');
|
|
76
|
+
}
|
|
77
|
+
else if (trimmed.startsWith('### ')) {
|
|
78
|
+
process.stdout.write('\n' + pc.bold(pc.yellow(trimmed.slice(4))) + '\n');
|
|
79
|
+
}
|
|
80
|
+
else if (trimmed.startsWith('- ') || trimmed.startsWith('* ')) {
|
|
81
|
+
process.stdout.write(' ' + pc.cyan('• ') + this.formatInline(line.slice(2)) + '\n');
|
|
82
|
+
}
|
|
83
|
+
else if (/^\d+\.\s/.test(trimmed)) {
|
|
84
|
+
const match = trimmed.match(/^(\d+\.)\s*(.*)$/);
|
|
85
|
+
if (match) {
|
|
86
|
+
process.stdout.write(' ' + pc.cyan(match[1]) + ' ' + this.formatInline(match[2]) + '\n');
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
89
|
+
process.stdout.write(this.formatInline(line) + '\n');
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
else if (trimmed.startsWith('> ')) {
|
|
93
|
+
process.stdout.write(pc.dim(' │ ' + trimmed.slice(2)) + '\n');
|
|
94
|
+
}
|
|
95
|
+
else if (trimmed === '---' || trimmed === '***' || trimmed === '___') {
|
|
96
|
+
process.stdout.write(pc.dim('─'.repeat(Math.min(process.stdout.columns || 40, 60))) + '\n');
|
|
97
|
+
}
|
|
98
|
+
else {
|
|
99
|
+
process.stdout.write(this.formatInline(line) + '\n');
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
formatInline(text) {
|
|
103
|
+
if (!text)
|
|
104
|
+
return '';
|
|
105
|
+
// Format `code`
|
|
106
|
+
let formatted = text.replace(/`([^`]+)`/g, (_, c) => pc.yellow(c));
|
|
107
|
+
// Format **bold**
|
|
108
|
+
formatted = formatted.replace(/\*\*([^*]+)\*\*/g, (_, b) => pc.bold(b));
|
|
109
|
+
// Format *italic*
|
|
110
|
+
formatted = formatted.replace(/\*([^*]+)\*/g, (_, i) => pc.italic(i));
|
|
111
|
+
return formatted;
|
|
112
|
+
}
|
|
113
|
+
flushTable() {
|
|
114
|
+
if (this.tableBuffer.length > 0) {
|
|
115
|
+
const tableMd = this.tableBuffer.join('\n');
|
|
116
|
+
try {
|
|
117
|
+
const rendered = renderMarkdown(tableMd);
|
|
118
|
+
process.stdout.write(rendered + '\n');
|
|
119
|
+
}
|
|
120
|
+
catch {
|
|
121
|
+
process.stdout.write(tableMd + '\n');
|
|
122
|
+
}
|
|
123
|
+
this.tableBuffer = [];
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
finish() {
|
|
127
|
+
if (this.buffer) {
|
|
128
|
+
const trimmed = this.buffer.trim();
|
|
129
|
+
if (trimmed.startsWith('|') && trimmed.endsWith('|')) {
|
|
130
|
+
this.tableBuffer.push(this.buffer);
|
|
131
|
+
this.buffer = '';
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
this.flushTable();
|
|
135
|
+
if (this.buffer) {
|
|
136
|
+
if (this.inCodeBlock) {
|
|
137
|
+
process.stdout.write(pc.green('│ ') + pc.white(this.buffer) + '\n');
|
|
138
|
+
process.stdout.write(pc.dim('└' + '─'.repeat(Math.min(process.stdout.columns || 40, 50))) + '\n');
|
|
139
|
+
this.inCodeBlock = false;
|
|
140
|
+
}
|
|
141
|
+
else {
|
|
142
|
+
process.stdout.write(this.formatInline(this.buffer) + '\n');
|
|
143
|
+
}
|
|
144
|
+
this.buffer = '';
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|