@odysx/codemind 0.0.0-stage → 0.1.1
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/README.md +293 -2
- package/dist/commands/agents.d.ts +2 -0
- package/dist/commands/agents.js +91 -0
- package/dist/commands/auth.d.ts +2 -0
- package/dist/commands/auth.js +35 -0
- package/dist/commands/chat.d.ts +2 -0
- package/dist/commands/chat.js +180 -0
- package/dist/commands/keys.d.ts +2 -0
- package/dist/commands/keys.js +81 -0
- package/dist/commands/local.d.ts +2 -0
- package/dist/commands/local.js +325 -0
- package/dist/commands/mcp.d.ts +2 -0
- package/dist/commands/mcp.js +73 -0
- package/dist/commands/prompts.d.ts +2 -0
- package/dist/commands/prompts.js +59 -0
- package/dist/commands/skills.d.ts +2 -0
- package/dist/commands/skills.js +41 -0
- package/dist/core/auth/index.d.ts +10 -0
- package/dist/core/auth/index.js +82 -0
- package/dist/core/config/index.d.ts +47 -0
- package/dist/core/config/index.js +118 -0
- package/dist/core/history.d.ts +14 -0
- package/dist/core/history.js +80 -0
- package/dist/core/markdown-renderer.d.ts +47 -0
- package/dist/core/markdown-renderer.js +385 -0
- package/dist/core/permissions/index.d.ts +31 -0
- package/dist/core/permissions/index.js +64 -0
- package/dist/core/provider/external.d.ts +28 -0
- package/dist/core/provider/external.js +248 -0
- package/dist/core/provider/index.d.ts +138 -0
- package/dist/core/provider/index.js +510 -0
- package/dist/core/registry/index.d.ts +25 -0
- package/dist/core/registry/index.js +216 -0
- package/dist/core/schema/types.d.ts +93 -0
- package/dist/core/schema/types.js +12 -0
- package/dist/core/terminal.d.ts +40 -0
- package/dist/core/terminal.js +134 -0
- package/dist/core/workspace/index.d.ts +35 -0
- package/dist/core/workspace/index.js +194 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +393 -0
- package/dist/ui/app.d.ts +3 -0
- package/dist/ui/app.js +554 -0
- package/dist/ui/commands/cases/catalog.d.ts +11 -0
- package/dist/ui/commands/cases/catalog.js +62 -0
- package/dist/ui/commands/cases/misc.d.ts +35 -0
- package/dist/ui/commands/cases/misc.js +245 -0
- package/dist/ui/commands/cases/tasks.d.ts +13 -0
- package/dist/ui/commands/cases/tasks.js +91 -0
- package/dist/ui/commands/runCommand.d.ts +22 -0
- package/dist/ui/commands/runCommand.js +136 -0
- package/dist/ui/components/AgentPicker.d.ts +11 -0
- package/dist/ui/components/AgentPicker.js +7 -0
- package/dist/ui/components/AuthPicker.d.ts +14 -0
- package/dist/ui/components/AuthPicker.js +7 -0
- package/dist/ui/components/Banner.d.ts +8 -0
- package/dist/ui/components/Banner.js +24 -0
- package/dist/ui/components/CommandMenu.d.ts +17 -0
- package/dist/ui/components/CommandMenu.js +21 -0
- package/dist/ui/components/ErrorBoundary.d.ts +24 -0
- package/dist/ui/components/ErrorBoundary.js +51 -0
- package/dist/ui/components/InputBar.d.ts +28 -0
- package/dist/ui/components/InputBar.js +108 -0
- package/dist/ui/components/KeysPanel.d.ts +12 -0
- package/dist/ui/components/KeysPanel.js +25 -0
- package/dist/ui/components/MessageView.d.ts +29 -0
- package/dist/ui/components/MessageView.js +107 -0
- package/dist/ui/components/PermissionPrompt.d.ts +10 -0
- package/dist/ui/components/PermissionPrompt.js +4 -0
- package/dist/ui/components/Pickers.d.ts +43 -0
- package/dist/ui/components/Pickers.js +33 -0
- package/dist/ui/components/SearchOverlay.d.ts +21 -0
- package/dist/ui/components/SearchOverlay.js +14 -0
- package/dist/ui/components/SessionPicker.d.ts +12 -0
- package/dist/ui/components/SessionPicker.js +8 -0
- package/dist/ui/components/WorkingIndicator.d.ts +10 -0
- package/dist/ui/components/WorkingIndicator.js +23 -0
- package/dist/ui/controls/ApiKeyEntry.d.ts +8 -0
- package/dist/ui/controls/ApiKeyEntry.js +5 -0
- package/dist/ui/controls/MultiSelect.d.ts +18 -0
- package/dist/ui/controls/MultiSelect.js +9 -0
- package/dist/ui/hooks/useAgentPicker.d.ts +14 -0
- package/dist/ui/hooks/useAgentPicker.js +53 -0
- package/dist/ui/hooks/useAuthFlow.d.ts +14 -0
- package/dist/ui/hooks/useAuthFlow.js +31 -0
- package/dist/ui/hooks/useKeysFlow.d.ts +17 -0
- package/dist/ui/hooks/useKeysFlow.js +130 -0
- package/dist/ui/hooks/useSessionPicker.d.ts +29 -0
- package/dist/ui/hooks/useSessionPicker.js +58 -0
- package/dist/ui/hooks/useTerminalSize.d.ts +6 -0
- package/dist/ui/hooks/useTerminalSize.js +29 -0
- package/dist/ui/input/keyRouter.d.ts +125 -0
- package/dist/ui/input/keyRouter.js +574 -0
- package/dist/ui/layouts/ScreenLayout.d.ts +98 -0
- package/dist/ui/layouts/ScreenLayout.js +56 -0
- package/dist/ui/shared/types.d.ts +143 -0
- package/dist/ui/shared/types.js +38 -0
- package/dist/ui/theme.d.ts +29 -0
- package/dist/ui/theme.js +54 -0
- package/dist/ui/utils/markdown.d.ts +74 -0
- package/dist/ui/utils/markdown.js +187 -0
- package/dist/ui/utils/mentions.d.ts +12 -0
- package/dist/ui/utils/mentions.js +28 -0
- package/dist/ui/utils/terminal-text.d.ts +33 -0
- package/dist/ui/utils/terminal-text.js +123 -0
- package/dist/ui/utils/text.d.ts +72 -0
- package/dist/ui/utils/text.js +171 -0
- package/package.json +50 -6
|
@@ -0,0 +1,385 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Markdown Renderer for Console Chat
|
|
3
|
+
*
|
|
4
|
+
* Transforms streaming markdown content into beautifully formatted console output
|
|
5
|
+
* with syntax highlighting, colorization, and proper code block handling.
|
|
6
|
+
*/
|
|
7
|
+
import markdownIt from "markdown-it";
|
|
8
|
+
import chalk from "chalk";
|
|
9
|
+
// Initialize markdown-it with common options
|
|
10
|
+
const md = markdownIt({
|
|
11
|
+
html: true,
|
|
12
|
+
linkify: true,
|
|
13
|
+
typographer: true,
|
|
14
|
+
// Disabled markdown-it code highlighting - using custom renderer for better control
|
|
15
|
+
// highlight: (str, lang) => {
|
|
16
|
+
// // Simple syntax highlighting for common languages
|
|
17
|
+
// if (lang) {
|
|
18
|
+
// return highlightCode(str, lang);
|
|
19
|
+
// }
|
|
20
|
+
// return str;
|
|
21
|
+
// }
|
|
22
|
+
});
|
|
23
|
+
/**
|
|
24
|
+
* Simple code highlighting using chalk
|
|
25
|
+
*/
|
|
26
|
+
function highlightCode(code, _lang) {
|
|
27
|
+
const lines = code.split('\n');
|
|
28
|
+
let inString = false;
|
|
29
|
+
let stringChar = '';
|
|
30
|
+
let escaped = false;
|
|
31
|
+
return lines.map((line, idx) => {
|
|
32
|
+
let result = '';
|
|
33
|
+
let i = 0;
|
|
34
|
+
while (i < line.length) {
|
|
35
|
+
const char = line[i];
|
|
36
|
+
// Handle strings
|
|
37
|
+
if (!inString && (char === '"' || char === "'" || char === '`')) {
|
|
38
|
+
inString = true;
|
|
39
|
+
stringChar = char;
|
|
40
|
+
result += chalk.yellow(char);
|
|
41
|
+
}
|
|
42
|
+
else if (inString && char === stringChar && !escaped) {
|
|
43
|
+
inString = false;
|
|
44
|
+
result += chalk.yellow(char);
|
|
45
|
+
}
|
|
46
|
+
else if (inString && char === '\\' && !escaped) {
|
|
47
|
+
escaped = true;
|
|
48
|
+
result += chalk.yellow(char);
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
escaped = false;
|
|
52
|
+
if (inString) {
|
|
53
|
+
result += chalk.yellow(char);
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
// Keywords
|
|
57
|
+
const keywords = ['const', 'let', 'var', 'function', 'return', 'if', 'else', 'for', 'while', 'class', 'import', 'export', 'from', 'async', 'await', 'try', 'catch', 'throw', 'new', 'this', 'typeof', 'instanceof', 'def', 'pass', 'lambda', 'yield', 'with', 'as', 'is', 'not', 'and', 'or', 'in', 'True', 'False', 'None'];
|
|
58
|
+
const nextWord = line.slice(i).match(/^([a-zA-Z_$][a-zA-Z0-9_$]*)/);
|
|
59
|
+
if (nextWord && keywords.includes(nextWord[1])) {
|
|
60
|
+
result += chalk.blue(nextWord[1]);
|
|
61
|
+
i += nextWord[1].length - 1;
|
|
62
|
+
}
|
|
63
|
+
else if (char.match(/[{}()[\];,]/)) {
|
|
64
|
+
result += chalk.gray(char);
|
|
65
|
+
}
|
|
66
|
+
else if (char === '#' && i === 0) {
|
|
67
|
+
// Python comment
|
|
68
|
+
result += chalk.green(line.slice(i));
|
|
69
|
+
break;
|
|
70
|
+
}
|
|
71
|
+
else if (char === '/' && i + 1 < line.length && line[i + 1] === '/') {
|
|
72
|
+
// JS/TS comment
|
|
73
|
+
result += chalk.green(line.slice(i));
|
|
74
|
+
break;
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
result += chalk.white(char);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
i++;
|
|
82
|
+
}
|
|
83
|
+
return chalk.gray(`${String(idx + 1).padStart(3, ' ')} | `) + result;
|
|
84
|
+
}).join('\n');
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Render a full markdown string to console with colors
|
|
88
|
+
*/
|
|
89
|
+
export function renderMarkdown(markdown) {
|
|
90
|
+
if (!markdown || markdown.trim() === '')
|
|
91
|
+
return;
|
|
92
|
+
const rendered = md.render(markdown);
|
|
93
|
+
// Parse the HTML output and convert to chalk-styled output
|
|
94
|
+
const lines = rendered.split('\n');
|
|
95
|
+
for (const line of lines) {
|
|
96
|
+
const trimmed = line.trim();
|
|
97
|
+
if (!trimmed) {
|
|
98
|
+
console.log('');
|
|
99
|
+
continue;
|
|
100
|
+
}
|
|
101
|
+
// Headings
|
|
102
|
+
const headingMatch = trimmed.match(/^<h([1-6])>(.*?)<\/h[1-6]>$/);
|
|
103
|
+
if (headingMatch) {
|
|
104
|
+
const level = parseInt(headingMatch[1]);
|
|
105
|
+
const text = stripHtml(headingMatch[2]);
|
|
106
|
+
const prefix = '#'.repeat(level) + ' ';
|
|
107
|
+
console.log(chalk.bold(chalk.rgb(255, 165, 0)(prefix + text)));
|
|
108
|
+
continue;
|
|
109
|
+
}
|
|
110
|
+
// Paragraphs
|
|
111
|
+
if (trimmed.startsWith('<p>') && trimmed.endsWith('</p>')) {
|
|
112
|
+
const text = stripHtml(trimmed.slice(3, -4));
|
|
113
|
+
console.log(chalk.gray(text));
|
|
114
|
+
continue;
|
|
115
|
+
}
|
|
116
|
+
// Lists
|
|
117
|
+
if (trimmed.startsWith('<ul>') || trimmed.startsWith('<ol>')) {
|
|
118
|
+
// Skip list container tags
|
|
119
|
+
continue;
|
|
120
|
+
}
|
|
121
|
+
if (trimmed.startsWith('</ul>') || trimmed.startsWith('</ol>')) {
|
|
122
|
+
continue;
|
|
123
|
+
}
|
|
124
|
+
const liMatch = trimmed.match(/^<li>(.*?)<\/li>$/);
|
|
125
|
+
if (liMatch) {
|
|
126
|
+
const text = stripHtml(liMatch[1]);
|
|
127
|
+
console.log(chalk.green(' • ') + chalk.white(text));
|
|
128
|
+
continue;
|
|
129
|
+
}
|
|
130
|
+
// Code blocks
|
|
131
|
+
if (trimmed.startsWith('<pre><code') && trimmed.endsWith('</code></pre>')) {
|
|
132
|
+
// Extract code content
|
|
133
|
+
const codeMatch = trimmed.match(/<pre><code[^>]*>([\s\S]*)<\/code><\/pre>/);
|
|
134
|
+
if (codeMatch) {
|
|
135
|
+
console.log(chalk.cyan('┌─ Code Block ─'));
|
|
136
|
+
console.log(codeMatch[1]);
|
|
137
|
+
console.log(chalk.cyan('└───────────────'));
|
|
138
|
+
}
|
|
139
|
+
continue;
|
|
140
|
+
}
|
|
141
|
+
// Inline code
|
|
142
|
+
if (trimmed.includes('<code>') && !trimmed.includes('<pre>')) {
|
|
143
|
+
let text = trimmed.replace(/<code>(.*?)<\/code>/g, (_, code) => chalk.cyan('`' + stripHtml(code) + '`'));
|
|
144
|
+
text = stripHtml(text);
|
|
145
|
+
console.log(chalk.gray(text));
|
|
146
|
+
continue;
|
|
147
|
+
}
|
|
148
|
+
// Blockquotes
|
|
149
|
+
if (trimmed.startsWith('<blockquote>') && trimmed.endsWith('</blockquote>')) {
|
|
150
|
+
const text = stripHtml(trimmed.slice(12, -13));
|
|
151
|
+
console.log(chalk.magenta('│ ') + chalk.gray(text));
|
|
152
|
+
continue;
|
|
153
|
+
}
|
|
154
|
+
// Horizontal rule
|
|
155
|
+
if (trimmed === '<hr>') {
|
|
156
|
+
console.log(chalk.gray('─'.repeat(60)));
|
|
157
|
+
continue;
|
|
158
|
+
}
|
|
159
|
+
// Links
|
|
160
|
+
if (trimmed.includes('<a href=')) {
|
|
161
|
+
let text = trimmed.replace(/<a href="([^"]*)">([^<]*)<\/a>/g, (_, url, linkText) => chalk.underline(chalk.blue(linkText)) + chalk.dim(` (${url})`));
|
|
162
|
+
text = stripHtml(text);
|
|
163
|
+
console.log(chalk.gray(text));
|
|
164
|
+
continue;
|
|
165
|
+
}
|
|
166
|
+
// Bold/Italic
|
|
167
|
+
let text = trimmed
|
|
168
|
+
.replace(/<strong>(.*?)<\/strong>/g, (_, t) => chalk.bold(stripHtml(t)))
|
|
169
|
+
.replace(/<b>(.*?)<\/b>/g, (_, t) => chalk.bold(stripHtml(t)))
|
|
170
|
+
.replace(/<em>(.*?)<\/em>/g, (_, t) => chalk.italic(stripHtml(t)))
|
|
171
|
+
.replace(/<i>(.*?)<\/i>/g, (_, t) => chalk.italic(stripHtml(t)));
|
|
172
|
+
text = stripHtml(text);
|
|
173
|
+
if (text.trim()) {
|
|
174
|
+
console.log(chalk.gray(text));
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Strip HTML tags from string
|
|
180
|
+
*/
|
|
181
|
+
function stripHtml(html) {
|
|
182
|
+
return html
|
|
183
|
+
.replace(/<[^>]*>/g, '')
|
|
184
|
+
.replace(/</g, '<')
|
|
185
|
+
.replace(/>/g, '>')
|
|
186
|
+
.replace(/&/g, '&')
|
|
187
|
+
.replace(/"/g, '"')
|
|
188
|
+
.replace(/'/g, "'")
|
|
189
|
+
.replace(/ /g, ' ');
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Streaming markdown renderer - processes tokens as they arrive
|
|
193
|
+
*/
|
|
194
|
+
export class StreamingMarkdownRenderer {
|
|
195
|
+
buffer = '';
|
|
196
|
+
inCodeBlock = false;
|
|
197
|
+
codeBlockLang = '';
|
|
198
|
+
codeBuffer = [];
|
|
199
|
+
/**
|
|
200
|
+
* Process a chunk of streamed markdown
|
|
201
|
+
*/
|
|
202
|
+
processChunk(chunk) {
|
|
203
|
+
this.buffer += chunk;
|
|
204
|
+
// Check for code block start
|
|
205
|
+
if (!this.inCodeBlock) {
|
|
206
|
+
const codeBlockStart = this.buffer.match(/```(\w*)\n/);
|
|
207
|
+
if (codeBlockStart && codeBlockStart.index !== undefined) {
|
|
208
|
+
this.inCodeBlock = true;
|
|
209
|
+
this.codeBlockLang = codeBlockStart[1] || '';
|
|
210
|
+
this.codeBuffer = [];
|
|
211
|
+
// Print everything before the code block
|
|
212
|
+
const beforeCode = this.buffer.slice(0, codeBlockStart.index);
|
|
213
|
+
if (beforeCode.trim()) {
|
|
214
|
+
this.renderInline(beforeCode);
|
|
215
|
+
}
|
|
216
|
+
this.buffer = this.buffer.slice(codeBlockStart.index + codeBlockStart[0].length);
|
|
217
|
+
console.log(chalk.cyan('\n┌─ Code Block (' + (this.codeBlockLang || 'text') + ') ─'));
|
|
218
|
+
return;
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
else {
|
|
222
|
+
// Check for code block end
|
|
223
|
+
const codeBlockEnd = this.buffer.indexOf('\n```');
|
|
224
|
+
if (codeBlockEnd !== -1) {
|
|
225
|
+
const codeContent = this.buffer.slice(0, codeBlockEnd);
|
|
226
|
+
this.codeBuffer.push(codeContent);
|
|
227
|
+
this.buffer = this.buffer.slice(codeBlockEnd + 4);
|
|
228
|
+
this.inCodeBlock = false;
|
|
229
|
+
// Render the code block with highlighting
|
|
230
|
+
const fullCode = this.codeBuffer.join('\n');
|
|
231
|
+
console.log(highlightCode(fullCode, this.codeBlockLang));
|
|
232
|
+
console.log(chalk.cyan('└──────────────────────────\n'));
|
|
233
|
+
this.codeBuffer = [];
|
|
234
|
+
}
|
|
235
|
+
else {
|
|
236
|
+
// Still in code block, accumulate
|
|
237
|
+
this.codeBuffer.push(this.buffer);
|
|
238
|
+
this.buffer = '';
|
|
239
|
+
}
|
|
240
|
+
return;
|
|
241
|
+
}
|
|
242
|
+
// Render non-code content as we go
|
|
243
|
+
this.renderInline(this.buffer);
|
|
244
|
+
this.buffer = '';
|
|
245
|
+
}
|
|
246
|
+
/**
|
|
247
|
+
* Render inline markdown (non-code-block content)
|
|
248
|
+
*/
|
|
249
|
+
renderInline(text) {
|
|
250
|
+
if (!text.trim())
|
|
251
|
+
return;
|
|
252
|
+
// Split by newlines and process each line
|
|
253
|
+
const lines = text.split('\n');
|
|
254
|
+
for (const line of lines) {
|
|
255
|
+
if (!line.trim())
|
|
256
|
+
continue;
|
|
257
|
+
// Handle headings
|
|
258
|
+
const headingMatch = line.match(/^(#{1,6})\s+(.*)/);
|
|
259
|
+
if (headingMatch) {
|
|
260
|
+
const level = headingMatch[1].length;
|
|
261
|
+
const text = headingMatch[2];
|
|
262
|
+
const prefix = '#'.repeat(level) + ' ';
|
|
263
|
+
console.log(chalk.bold(chalk.rgb(255, 165, 0)(prefix + text)));
|
|
264
|
+
continue;
|
|
265
|
+
}
|
|
266
|
+
// Handle list items
|
|
267
|
+
const listMatch = line.match(/^[\s]*[-*+]\s+(.*)/);
|
|
268
|
+
if (listMatch) {
|
|
269
|
+
console.log(chalk.green(' • ') + chalk.white(this.formatInline(listMatch[1])));
|
|
270
|
+
continue;
|
|
271
|
+
}
|
|
272
|
+
// Handle numbered lists
|
|
273
|
+
const numMatch = line.match(/^[\s]*\d+\.\s+(.*)/);
|
|
274
|
+
if (numMatch) {
|
|
275
|
+
console.log(chalk.green(' 1. ') + chalk.white(this.formatInline(numMatch[1])));
|
|
276
|
+
continue;
|
|
277
|
+
}
|
|
278
|
+
// Handle blockquotes
|
|
279
|
+
const quoteMatch = line.match(/^>\s*(.*)/);
|
|
280
|
+
if (quoteMatch) {
|
|
281
|
+
console.log(chalk.magenta('│ ') + chalk.gray(this.formatInline(quoteMatch[1])));
|
|
282
|
+
continue;
|
|
283
|
+
}
|
|
284
|
+
// Handle horizontal rule
|
|
285
|
+
if (line.match(/^[-*_]{3,}$/)) {
|
|
286
|
+
console.log(chalk.gray('─'.repeat(60)));
|
|
287
|
+
continue;
|
|
288
|
+
}
|
|
289
|
+
// Regular text with inline formatting
|
|
290
|
+
console.log(chalk.gray(this.formatInline(line)));
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
/**
|
|
294
|
+
* Format inline markdown elements (bold, italic, code, links)
|
|
295
|
+
*/
|
|
296
|
+
formatInline(text) {
|
|
297
|
+
return text
|
|
298
|
+
.replace(/\*\*(.*?)\*\*/g, (_, t) => chalk.bold(t))
|
|
299
|
+
.replace(/__(.*?)__/g, (_, t) => chalk.bold(t))
|
|
300
|
+
.replace(/\*(.*?)\*/g, (_, t) => chalk.italic(t))
|
|
301
|
+
.replace(/_(.*?)_/g, (_, t) => chalk.italic(t))
|
|
302
|
+
.replace(/`([^`]+)`/g, (_, t) => chalk.cyan('`' + t + '`'))
|
|
303
|
+
.replace(/\[([^\]]+)\]\(([^)]+)\)/g, (_, linkText, url) => chalk.underline(chalk.blue(linkText)) + chalk.dim(` (${url})`));
|
|
304
|
+
}
|
|
305
|
+
/**
|
|
306
|
+
* Flush any remaining buffer
|
|
307
|
+
*/
|
|
308
|
+
flush() {
|
|
309
|
+
if (this.buffer.trim()) {
|
|
310
|
+
this.renderInline(this.buffer);
|
|
311
|
+
this.buffer = '';
|
|
312
|
+
}
|
|
313
|
+
if (this.inCodeBlock && this.codeBuffer.length > 0) {
|
|
314
|
+
const fullCode = this.codeBuffer.join('\n');
|
|
315
|
+
console.log(highlightCode(fullCode, this.codeBlockLang));
|
|
316
|
+
console.log(chalk.cyan('└──────────────────────────\n'));
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
/**
|
|
321
|
+
* Pure markdown → plain-text-with-unicode-markers converter for the Ink UI.
|
|
322
|
+
*
|
|
323
|
+
* Returns a string (Ink <Text> renders ANSI-free text, so styling is expressed
|
|
324
|
+
* with unicode markers instead of chalk escapes — chalk output would leak raw
|
|
325
|
+
* escape codes into Ink's reconciled frame).
|
|
326
|
+
*/
|
|
327
|
+
export function markdownToText(markdown) {
|
|
328
|
+
if (!markdown || !markdown.trim())
|
|
329
|
+
return "";
|
|
330
|
+
const lines = md.render(markdown).split("\n");
|
|
331
|
+
const out = [];
|
|
332
|
+
for (const raw of lines) {
|
|
333
|
+
const line = raw.trim();
|
|
334
|
+
if (!line)
|
|
335
|
+
continue;
|
|
336
|
+
// Headings: underline with ─ instead of #
|
|
337
|
+
const h = line.match(/^<h([1-6])>(.*?)<\/h[1-6]>$/);
|
|
338
|
+
if (h) {
|
|
339
|
+
const text = stripTags(h[2]);
|
|
340
|
+
out.push("", text.toUpperCase(), "─".repeat(Math.min(text.length, 60)));
|
|
341
|
+
continue;
|
|
342
|
+
}
|
|
343
|
+
// Paragraph
|
|
344
|
+
if (line.startsWith("<p>") && line.endsWith("</p>")) {
|
|
345
|
+
out.push(stripTags(line.slice(3, -4)));
|
|
346
|
+
continue;
|
|
347
|
+
}
|
|
348
|
+
// List item → bullet
|
|
349
|
+
const li = line.match(/^<li>(.*?)<\/li>$/);
|
|
350
|
+
if (li) {
|
|
351
|
+
out.push(` • ${stripTags(li[1])}`);
|
|
352
|
+
continue;
|
|
353
|
+
}
|
|
354
|
+
// Blockquote
|
|
355
|
+
if (line.startsWith("<blockquote>")) {
|
|
356
|
+
out.push(`│ ${stripTags(line.replace(/<\/?blockquote>/g, ""))}`);
|
|
357
|
+
continue;
|
|
358
|
+
}
|
|
359
|
+
// Code block (rendered HTML keeps newlines inside <code>)
|
|
360
|
+
if (line.startsWith("<pre>") || line.startsWith("<code>")) {
|
|
361
|
+
out.push(...stripTags(line).split("\n").map((l) => ` ${l}`));
|
|
362
|
+
continue;
|
|
363
|
+
}
|
|
364
|
+
// Horizontal rule
|
|
365
|
+
if (/^<(hr|hr\s)/.test(line)) {
|
|
366
|
+
out.push("─".repeat(60));
|
|
367
|
+
continue;
|
|
368
|
+
}
|
|
369
|
+
out.push(stripTags(line));
|
|
370
|
+
}
|
|
371
|
+
return out.join("\n");
|
|
372
|
+
}
|
|
373
|
+
/** Strip remaining HTML tags and decode a handful of common entities. */
|
|
374
|
+
function stripTags(html) {
|
|
375
|
+
return html
|
|
376
|
+
.replace(/<br\s*\/?>/g, "\n")
|
|
377
|
+
.replace(/<[^>]+>/g, "")
|
|
378
|
+
.replace(/&/g, "&")
|
|
379
|
+
.replace(/</g, "<")
|
|
380
|
+
.replace(/>/g, ">")
|
|
381
|
+
.replace(/"/g, '"')
|
|
382
|
+
.replace(/'/g, "'");
|
|
383
|
+
}
|
|
384
|
+
export { md };
|
|
385
|
+
//# sourceMappingURL=markdown-renderer.js.map
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export type PermissionMode = "plan" | "guide" | "manual" | "auto";
|
|
2
|
+
/** What an operation does to the workspace. */
|
|
3
|
+
export type OpClass = "read" | "write" | "irreversible";
|
|
4
|
+
/** The outcome the caller must honour. */
|
|
5
|
+
export type Decision =
|
|
6
|
+
/** Run it. */
|
|
7
|
+
"allow"
|
|
8
|
+
/** Ask the user first (interactive) or require --yes (non-interactive). */
|
|
9
|
+
| "ask"
|
|
10
|
+
/** Refuse, and say why. */
|
|
11
|
+
| "refuse"
|
|
12
|
+
/** Don't run it; show the user the exact command instead. */
|
|
13
|
+
| "guide";
|
|
14
|
+
export interface ModeInfo {
|
|
15
|
+
id: PermissionMode;
|
|
16
|
+
label: string;
|
|
17
|
+
/** One line for the picker and /help. */
|
|
18
|
+
summary: string;
|
|
19
|
+
}
|
|
20
|
+
export declare const PERMISSION_MODES: readonly ModeInfo[];
|
|
21
|
+
export declare const isPermissionMode: (value: unknown) => value is PermissionMode;
|
|
22
|
+
/** The active mode. Anything unrecognised in the config file falls back. */
|
|
23
|
+
export declare const getPermissionMode: () => PermissionMode;
|
|
24
|
+
export declare const setPermissionMode: (mode: PermissionMode) => void;
|
|
25
|
+
/** Classify a `local` subcommand. The only place these names are mapped. */
|
|
26
|
+
export declare const classifyLocalOp: (sub: string) => OpClass;
|
|
27
|
+
export declare const decide: (mode: PermissionMode, op: OpClass) => Decision;
|
|
28
|
+
/** Convenience: decide for a `local` subcommand under the active mode. */
|
|
29
|
+
export declare const decideLocal: (sub: string, mode?: PermissionMode) => Decision;
|
|
30
|
+
export declare const modeInfo: (mode: PermissionMode) => ModeInfo;
|
|
31
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Permission modes — who decides whether a workspace operation may run.
|
|
3
|
+
*
|
|
4
|
+
* The CLI can read, edit, and execute files in your workspace. This module is
|
|
5
|
+
* the single place that answers "is this operation allowed, and does anyone
|
|
6
|
+
* need to be asked?" so the interactive REPL, the one-shot CLI, and the
|
|
7
|
+
* command handlers can never disagree about it.
|
|
8
|
+
*
|
|
9
|
+
* Four modes, each a strictly different posture toward the workspace:
|
|
10
|
+
*
|
|
11
|
+
* plan read-only — mutations are refused outright
|
|
12
|
+
* guide nothing runs; the operation is printed for you to run yourself
|
|
13
|
+
* manual every mutation asks (the default)
|
|
14
|
+
* auto scoped writes run unprompted; irreversible ops still ask
|
|
15
|
+
*
|
|
16
|
+
* The policy is a table rather than a chain of conditionals: adding a mode or
|
|
17
|
+
* an operation class is a data change, and the tests exercise the whole
|
|
18
|
+
* matrix instead of the paths someone remembered to write.
|
|
19
|
+
*/
|
|
20
|
+
import { getConfig, updateConfig } from "../config/index.js";
|
|
21
|
+
export const PERMISSION_MODES = [
|
|
22
|
+
{ id: "plan", label: "plan", summary: "Read-only — never writes, deletes, or executes" },
|
|
23
|
+
{ id: "guide", label: "guide", summary: "Prints the command it would run instead of running it" },
|
|
24
|
+
{ id: "manual", label: "manual", summary: "Asks before every write, delete, move, or exec" },
|
|
25
|
+
{ id: "auto", label: "auto", summary: "Runs workspace writes; still asks for irreversible ops" },
|
|
26
|
+
];
|
|
27
|
+
/**
|
|
28
|
+
* mode × operation class → decision.
|
|
29
|
+
*
|
|
30
|
+
* The ladder is deliberate: each row is a superset of the one above it, so
|
|
31
|
+
* `auto` is the only mode that can act without being asked, and even it stops
|
|
32
|
+
* at anything it cannot undo.
|
|
33
|
+
*/
|
|
34
|
+
const POLICY = {
|
|
35
|
+
plan: { read: "allow", write: "refuse", irreversible: "refuse" },
|
|
36
|
+
guide: { read: "allow", write: "guide", irreversible: "guide" },
|
|
37
|
+
manual: { read: "allow", write: "ask", irreversible: "ask" },
|
|
38
|
+
auto: { read: "allow", write: "allow", irreversible: "ask" },
|
|
39
|
+
};
|
|
40
|
+
const MODE_IDS = PERMISSION_MODES.map((m) => m.id);
|
|
41
|
+
export const isPermissionMode = (value) => typeof value === "string" && MODE_IDS.includes(value);
|
|
42
|
+
/** The active mode. Anything unrecognised in the config file falls back. */
|
|
43
|
+
export const getPermissionMode = () => {
|
|
44
|
+
const configured = getConfig().permissionMode;
|
|
45
|
+
return isPermissionMode(configured) ? configured : "manual";
|
|
46
|
+
};
|
|
47
|
+
export const setPermissionMode = (mode) => {
|
|
48
|
+
updateConfig({ permissionMode: mode });
|
|
49
|
+
};
|
|
50
|
+
/** Classify a `local` subcommand. The only place these names are mapped. */
|
|
51
|
+
export const classifyLocalOp = (sub) => {
|
|
52
|
+
const op = sub.toLowerCase();
|
|
53
|
+
if (op === "read" || op === "ls" || op === "pwd" || op === "which")
|
|
54
|
+
return "read";
|
|
55
|
+
if (op === "write")
|
|
56
|
+
return "write";
|
|
57
|
+
// delete and move cannot be undone; exec runs arbitrary code.
|
|
58
|
+
return "irreversible";
|
|
59
|
+
};
|
|
60
|
+
export const decide = (mode, op) => POLICY[mode][op];
|
|
61
|
+
/** Convenience: decide for a `local` subcommand under the active mode. */
|
|
62
|
+
export const decideLocal = (sub, mode = getPermissionMode()) => decide(mode, classifyLocalOp(sub));
|
|
63
|
+
export const modeInfo = (mode) => PERMISSION_MODES.find((m) => m.id === mode) ?? PERMISSION_MODES[2];
|
|
64
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export type ProviderType = "openai" | "anthropic" | "gemini";
|
|
2
|
+
export interface ExternalProviderConfig {
|
|
3
|
+
/** Wire protocol to speak. */
|
|
4
|
+
type: ProviderType;
|
|
5
|
+
/** API base (OpenAI-compatible servers override this). */
|
|
6
|
+
baseUrl?: string;
|
|
7
|
+
apiKey?: string;
|
|
8
|
+
model: string;
|
|
9
|
+
}
|
|
10
|
+
/** Chat message as sent over the wire (system prompt folded in by caller). */
|
|
11
|
+
export interface WireMessage {
|
|
12
|
+
role: "user" | "assistant";
|
|
13
|
+
content: string;
|
|
14
|
+
}
|
|
15
|
+
export declare const getActiveProvider: () => {
|
|
16
|
+
name: string;
|
|
17
|
+
config: ExternalProviderConfig;
|
|
18
|
+
} | null;
|
|
19
|
+
interface StreamOpts {
|
|
20
|
+
system?: string;
|
|
21
|
+
onToken: (token: string) => void;
|
|
22
|
+
signal?: AbortSignal;
|
|
23
|
+
}
|
|
24
|
+
/** Stream a chat turn through the active external provider. Throws on HTTP
|
|
25
|
+
* errors with the provider's own message so the REPL can show it directly. */
|
|
26
|
+
export declare function streamExternalChat(messages: WireMessage[], opts: StreamOpts): Promise<void>;
|
|
27
|
+
export {};
|
|
28
|
+
//# sourceMappingURL=external.d.ts.map
|