@phren/agent 0.1.8 → 0.1.9
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/dist/commands/info.js +1 -0
- package/dist/commands/model.js +5 -4
- package/dist/commands/session.js +24 -2
- package/dist/commands.js +36 -1
- package/dist/config.js +27 -11
- package/dist/cost.js +11 -74
- package/dist/index.js +92 -35
- package/dist/mcp-client.js +4 -2
- package/dist/memory/context.js +56 -24
- package/dist/memory/session.js +21 -88
- package/dist/models.js +390 -0
- package/dist/multi/agent-types.js +170 -0
- package/dist/multi/child-entry.js +248 -78
- package/dist/multi/coordinator.js +69 -1
- package/dist/multi/diff-renderer.js +193 -17
- package/dist/multi/markdown.js +49 -23
- package/dist/multi/model-picker.js +12 -21
- package/dist/multi/multi-events.js +17 -0
- package/dist/multi/multi-render.js +1 -0
- package/dist/multi/provider-manager.js +23 -13
- package/dist/multi/spawner.js +84 -7
- package/dist/multi/syntax-highlight.js +64 -48
- package/dist/multi/worktree.js +43 -0
- package/dist/package-metadata.js +11 -0
- package/dist/permissions/checker.js +21 -1
- package/dist/providers/codex-auth.js +48 -34
- package/dist/providers/codex.js +110 -40
- package/dist/providers/ollama.js +5 -4
- package/dist/providers/openrouter.js +12 -5
- package/dist/providers/resolve.js +50 -32
- package/dist/providers/types.js +0 -1
- package/dist/repl.js +19 -34
- package/dist/tools/grep.js +111 -23
- package/dist/tools/mcp-resources.js +32 -0
- package/dist/tools/registry.js +13 -2
- package/dist/tools/shell.js +101 -3
- package/dist/tools/skill.js +44 -0
- package/dist/tools/spawn-agent.js +158 -0
- package/dist/tui/ansi.js +15 -11
- package/dist/tui/components/App.js +179 -8
- package/dist/tui/components/Banner.js +7 -4
- package/dist/tui/components/InputArea.js +54 -12
- package/dist/tui/components/PhrenInput.js +329 -0
- package/dist/tui/components/StatusBar.js +3 -1
- package/dist/tui/components/SteerQueue.js +4 -2
- package/dist/tui/components/ThinkingIndicator.js +7 -5
- package/dist/tui/components/ToolCall.js +12 -8
- package/dist/tui/components/ToolSpinner.js +13 -0
- package/dist/tui/hooks/useKeyboardShortcuts.js +65 -24
- package/dist/tui/hooks/useSearch.js +47 -0
- package/dist/tui/hooks/useSlashCommands.js +16 -19
- package/dist/tui/ink-entry.js +373 -14
- package/dist/tui/mouse.js +71 -0
- package/dist/tui/terminal-control.js +62 -0
- package/dist/tui/themes.js +398 -0
- package/dist/tui/tool-render.js +12 -1
- package/dist/tui.js +2 -1
- package/package.json +1 -3
|
@@ -5,11 +5,22 @@
|
|
|
5
5
|
* external dependencies. Output is capped at 30 lines.
|
|
6
6
|
*/
|
|
7
7
|
// ── ANSI helpers ─────────────────────────────────────────────────────────────
|
|
8
|
+
import { hostname } from "os";
|
|
8
9
|
const ESC = "\x1b[";
|
|
9
10
|
const red = (t) => `${ESC}31m${t}${ESC}0m`;
|
|
10
11
|
const green = (t) => `${ESC}32m${t}${ESC}0m`;
|
|
11
12
|
const dim = (t) => `${ESC}2m${t}${ESC}0m`;
|
|
12
13
|
const cyan = (t) => `${ESC}36m${t}${ESC}0m`;
|
|
14
|
+
/**
|
|
15
|
+
* Wrap an absolute file path in an OSC 8 file:// hyperlink.
|
|
16
|
+
* Returns the path unchanged when it is not absolute.
|
|
17
|
+
*/
|
|
18
|
+
function fileHyperlink(filePath) {
|
|
19
|
+
if (!filePath.startsWith("/"))
|
|
20
|
+
return filePath;
|
|
21
|
+
const host = hostname();
|
|
22
|
+
return `\x1b]8;;file://${host}${filePath}\x07${filePath}\x1b]8;;\x07`;
|
|
23
|
+
}
|
|
13
24
|
/**
|
|
14
25
|
* Compute a line-level diff between two arrays of strings.
|
|
15
26
|
* Uses the LCS (Longest Common Subsequence) approach for correctness.
|
|
@@ -55,8 +66,12 @@ function computeLineDiff(oldLines, newLines) {
|
|
|
55
66
|
const MAX_OUTPUT_LINES = 30;
|
|
56
67
|
const MAX_FIRST_CHUNK = 20;
|
|
57
68
|
const CONTEXT_LINES = 3;
|
|
69
|
+
const SBS_MAX_OUTPUT_LINES = 40;
|
|
70
|
+
const SBS_COLLAPSE_THRESHOLD = 3;
|
|
71
|
+
const SBS_MIN_WIDTH = 70;
|
|
58
72
|
/**
|
|
59
73
|
* Render a colored inline diff between old and new file content.
|
|
74
|
+
* Automatically switches to side-by-side when the terminal is wide enough.
|
|
60
75
|
*
|
|
61
76
|
* Output format:
|
|
62
77
|
* ─── path/to/file ───
|
|
@@ -66,11 +81,177 @@ const CONTEXT_LINES = 3;
|
|
|
66
81
|
* Capped at 30 output lines. If the diff is larger, shows the first 20
|
|
67
82
|
* lines plus a "... (N more changes)" trailer.
|
|
68
83
|
*/
|
|
69
|
-
export function renderInlineDiff(oldContent, newContent, filePath) {
|
|
84
|
+
export function renderInlineDiff(oldContent, newContent, filePath, colors) {
|
|
85
|
+
const termWidth = process.stdout.columns || 80;
|
|
86
|
+
if (termWidth >= SBS_MIN_WIDTH) {
|
|
87
|
+
return renderSideBySideDiff(oldContent, newContent, filePath ?? "", termWidth, colors);
|
|
88
|
+
}
|
|
89
|
+
return renderInlineDiffCore(oldContent, newContent, filePath ?? "", colors);
|
|
90
|
+
}
|
|
91
|
+
// ── Side-by-side renderer ───────────────────────────────────────────────────
|
|
92
|
+
/**
|
|
93
|
+
* Render a side-by-side colored diff between old and new file content.
|
|
94
|
+
*
|
|
95
|
+
* Falls back to inline diff when terminal width < 70 columns.
|
|
96
|
+
*
|
|
97
|
+
* Layout:
|
|
98
|
+
* ─── path/to/file ───
|
|
99
|
+
* <lineNo> old text │ <lineNo> new text
|
|
100
|
+
*
|
|
101
|
+
* Deletions in red (left only), additions in green (right only),
|
|
102
|
+
* unchanged lines in dim on both sides. Collapses unchanged runs > 3 lines.
|
|
103
|
+
* Capped at 40 output lines.
|
|
104
|
+
*/
|
|
105
|
+
export function renderSideBySideDiff(oldContent, newContent, filePath, termWidth, colors) {
|
|
106
|
+
const width = termWidth ?? process.stdout.columns ?? 80;
|
|
107
|
+
if (width < SBS_MIN_WIDTH) {
|
|
108
|
+
return renderInlineDiffCore(oldContent, newContent, filePath, colors);
|
|
109
|
+
}
|
|
110
|
+
const oldLines = oldContent.split("\n");
|
|
111
|
+
const newLines = newContent.split("\n");
|
|
112
|
+
const diff = computeLineDiff(oldLines, newLines);
|
|
113
|
+
if (diff.length === 0)
|
|
114
|
+
return "";
|
|
115
|
+
// Each side gets half the width minus the separator (" │ " = 3 chars)
|
|
116
|
+
const halfWidth = Math.floor((width - 3) / 2);
|
|
117
|
+
const lineNoWidth = 4; // e.g. " 42 "
|
|
118
|
+
const contentWidth = halfWidth - lineNoWidth - 1; // -1 for the space after lineNo
|
|
119
|
+
const pairs = [];
|
|
120
|
+
for (const entry of diff) {
|
|
121
|
+
switch (entry.op) {
|
|
122
|
+
case "equal":
|
|
123
|
+
pairs.push({
|
|
124
|
+
kind: "equal",
|
|
125
|
+
leftLineNo: entry.oldLineNo,
|
|
126
|
+
leftText: entry.line,
|
|
127
|
+
rightLineNo: entry.newLineNo,
|
|
128
|
+
rightText: entry.line,
|
|
129
|
+
});
|
|
130
|
+
break;
|
|
131
|
+
case "delete":
|
|
132
|
+
pairs.push({
|
|
133
|
+
kind: "change",
|
|
134
|
+
leftLineNo: entry.oldLineNo,
|
|
135
|
+
leftText: entry.line,
|
|
136
|
+
});
|
|
137
|
+
break;
|
|
138
|
+
case "insert":
|
|
139
|
+
pairs.push({
|
|
140
|
+
kind: "change",
|
|
141
|
+
rightLineNo: entry.newLineNo,
|
|
142
|
+
rightText: entry.line,
|
|
143
|
+
});
|
|
144
|
+
break;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
const truncStr = (s, max) => s.length > max ? s.slice(0, max - 1) + "…" : s;
|
|
148
|
+
const padRight = (s, len) => {
|
|
149
|
+
// Pad based on visible length (strip ANSI)
|
|
150
|
+
const visible = s.replace(/\x1b\[[0-9;]*m/g, "");
|
|
151
|
+
const pad = Math.max(0, len - visible.length);
|
|
152
|
+
return s + " ".repeat(pad);
|
|
153
|
+
};
|
|
154
|
+
// Color helpers — use theme values when provided, else fall back to module-level functions
|
|
155
|
+
const rst = colors?.reset ?? `${ESC}0m`;
|
|
156
|
+
const applyAdded = (t) => colors ? `${colors.added}${t}${rst}` : green(t);
|
|
157
|
+
const applyRemoved = (t) => colors ? `${colors.removed}${t}${rst}` : red(t);
|
|
158
|
+
const applyContext = (t) => colors ? `${colors.context}${t}${rst}` : dim(t);
|
|
159
|
+
const applySep = (t) => colors ? `${colors.separator}${t}${rst}` : dim(t);
|
|
160
|
+
const applyHeader = (t) => colors ? `${colors.header}${t}${rst}` : cyan(t);
|
|
161
|
+
const applyLineNo = (t) => colors ? `${colors.lineNumber}${t}${rst}` : dim(t);
|
|
162
|
+
const formatHalf = (lineNo, text, cWidth, colorFn) => {
|
|
163
|
+
if (lineNo === undefined && text === undefined) {
|
|
164
|
+
return " ".repeat(lineNoWidth + 1 + cWidth);
|
|
165
|
+
}
|
|
166
|
+
const ln = lineNo !== undefined ? String(lineNo).padStart(lineNoWidth) : " ".repeat(lineNoWidth);
|
|
167
|
+
const content = text !== undefined ? truncStr(text, cWidth) : "";
|
|
168
|
+
const colored = colorFn ? colorFn(content) : applyContext(content);
|
|
169
|
+
return padRight(`${applyLineNo(ln)} ${colored}`, halfWidth);
|
|
170
|
+
};
|
|
171
|
+
const rows = [];
|
|
172
|
+
let equalRun = [];
|
|
173
|
+
const flushEqualRun = () => {
|
|
174
|
+
if (equalRun.length === 0)
|
|
175
|
+
return;
|
|
176
|
+
if (equalRun.length <= SBS_COLLAPSE_THRESHOLD) {
|
|
177
|
+
// Show them as normal lines
|
|
178
|
+
for (const p of equalRun) {
|
|
179
|
+
rows.push({
|
|
180
|
+
type: "line",
|
|
181
|
+
left: formatHalf(p.leftLineNo, p.leftText, contentWidth),
|
|
182
|
+
right: formatHalf(p.rightLineNo, p.rightText, contentWidth),
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
else {
|
|
187
|
+
// Show first context line, collapse marker, last context line
|
|
188
|
+
const first = equalRun[0];
|
|
189
|
+
const last = equalRun[equalRun.length - 1];
|
|
190
|
+
rows.push({
|
|
191
|
+
type: "line",
|
|
192
|
+
left: formatHalf(first.leftLineNo, first.leftText, contentWidth),
|
|
193
|
+
right: formatHalf(first.rightLineNo, first.rightText, contentWidth),
|
|
194
|
+
});
|
|
195
|
+
rows.push({ type: "collapse", collapseCount: equalRun.length - 2 });
|
|
196
|
+
rows.push({
|
|
197
|
+
type: "line",
|
|
198
|
+
left: formatHalf(last.leftLineNo, last.leftText, contentWidth),
|
|
199
|
+
right: formatHalf(last.rightLineNo, last.rightText, contentWidth),
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
equalRun = [];
|
|
203
|
+
};
|
|
204
|
+
for (const pair of pairs) {
|
|
205
|
+
if (pair.kind === "equal") {
|
|
206
|
+
equalRun.push(pair);
|
|
207
|
+
}
|
|
208
|
+
else {
|
|
209
|
+
flushEqualRun();
|
|
210
|
+
rows.push({
|
|
211
|
+
type: "line",
|
|
212
|
+
left: formatHalf(pair.leftLineNo, pair.leftText, contentWidth, pair.leftText !== undefined ? applyRemoved : undefined),
|
|
213
|
+
right: formatHalf(pair.rightLineNo, pair.rightText, contentWidth, pair.rightText !== undefined ? applyAdded : undefined),
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
flushEqualRun();
|
|
218
|
+
// Build final output lines
|
|
219
|
+
const outputLines = [];
|
|
220
|
+
const sep = "│";
|
|
221
|
+
for (const row of rows) {
|
|
222
|
+
if (outputLines.length >= SBS_MAX_OUTPUT_LINES) {
|
|
223
|
+
const remaining = rows.length - rows.indexOf(row);
|
|
224
|
+
outputLines.push(applyContext(` ... (${remaining} more rows) ...`));
|
|
225
|
+
break;
|
|
226
|
+
}
|
|
227
|
+
if (row.type === "collapse") {
|
|
228
|
+
const msg = applyContext(`... (${row.collapseCount} unchanged) ...`);
|
|
229
|
+
outputLines.push(`${padRight(msg, halfWidth)} ${applySep(sep)} ${msg}`);
|
|
230
|
+
}
|
|
231
|
+
else {
|
|
232
|
+
outputLines.push(`${row.left} ${applySep(sep)} ${row.right}`);
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
if (outputLines.length === 0)
|
|
236
|
+
return "";
|
|
237
|
+
const linkedPath = fileHyperlink(filePath);
|
|
238
|
+
const header = applyHeader(`─── ${linkedPath} ───`);
|
|
239
|
+
return `${header}\n${outputLines.join("\n")}`;
|
|
240
|
+
}
|
|
241
|
+
/**
|
|
242
|
+
* Core inline diff logic (always inline, no side-by-side switch).
|
|
243
|
+
* Used as the fallback when the terminal is too narrow.
|
|
244
|
+
*/
|
|
245
|
+
function renderInlineDiffCore(oldContent, newContent, filePath, colors) {
|
|
246
|
+
const rst = colors?.reset ?? `${ESC}0m`;
|
|
247
|
+
const applyAdded = (t) => colors ? `${colors.added}${t}${rst}` : green(t);
|
|
248
|
+
const applyRemoved = (t) => colors ? `${colors.removed}${t}${rst}` : red(t);
|
|
249
|
+
const applyContext = (t) => colors ? `${colors.context}${t}${rst}` : dim(t);
|
|
250
|
+
const applyHeader = (t) => colors ? `${colors.header}${t}${rst}` : cyan(t);
|
|
251
|
+
const applyLineNo = (t) => colors ? `${colors.lineNumber}${t}${rst}` : dim(t);
|
|
70
252
|
const oldLines = oldContent.split("\n");
|
|
71
253
|
const newLines = newContent.split("\n");
|
|
72
254
|
const diff = computeLineDiff(oldLines, newLines);
|
|
73
|
-
// Identify which diff entries have changes nearby (within CONTEXT_LINES)
|
|
74
255
|
const hasChange = diff.map((d) => d.op !== "equal");
|
|
75
256
|
const visible = new Array(diff.length).fill(false);
|
|
76
257
|
for (let i = 0; i < diff.length; i++) {
|
|
@@ -80,7 +261,6 @@ export function renderInlineDiff(oldContent, newContent, filePath) {
|
|
|
80
261
|
}
|
|
81
262
|
}
|
|
82
263
|
}
|
|
83
|
-
// Build output lines
|
|
84
264
|
const outputLines = [];
|
|
85
265
|
let inCollapsed = false;
|
|
86
266
|
let collapsedCount = 0;
|
|
@@ -93,47 +273,43 @@ export function renderInlineDiff(oldContent, newContent, filePath) {
|
|
|
93
273
|
collapsedCount++;
|
|
94
274
|
continue;
|
|
95
275
|
}
|
|
96
|
-
// Emit collapsed marker if we just exited a collapsed section
|
|
97
276
|
if (inCollapsed) {
|
|
98
|
-
outputLines.push(
|
|
277
|
+
outputLines.push(applyContext(` ... (${collapsedCount} unchanged lines) ...`));
|
|
99
278
|
inCollapsed = false;
|
|
100
279
|
collapsedCount = 0;
|
|
101
280
|
}
|
|
102
281
|
const d = diff[i];
|
|
103
282
|
const lineNo = d.oldLineNo ?? d.newLineNo ?? 0;
|
|
104
|
-
const lineNoStr =
|
|
283
|
+
const lineNoStr = applyLineNo(String(lineNo).padStart(4) + " ");
|
|
105
284
|
switch (d.op) {
|
|
106
285
|
case "equal":
|
|
107
|
-
outputLines.push(lineNoStr +
|
|
286
|
+
outputLines.push(lineNoStr + applyContext(d.line));
|
|
108
287
|
break;
|
|
109
288
|
case "delete":
|
|
110
|
-
outputLines.push(lineNoStr +
|
|
289
|
+
outputLines.push(lineNoStr + applyRemoved(`- ${d.line}`));
|
|
111
290
|
break;
|
|
112
291
|
case "insert":
|
|
113
|
-
outputLines.push(lineNoStr +
|
|
292
|
+
outputLines.push(lineNoStr + applyAdded(`+ ${d.line}`));
|
|
114
293
|
break;
|
|
115
294
|
}
|
|
116
295
|
}
|
|
117
|
-
// Trailing collapsed section
|
|
118
296
|
if (inCollapsed) {
|
|
119
|
-
outputLines.push(
|
|
297
|
+
outputLines.push(applyContext(` ... (${collapsedCount} unchanged lines) ...`));
|
|
120
298
|
}
|
|
121
|
-
|
|
122
|
-
if (outputLines.length === 0) {
|
|
299
|
+
if (outputLines.length === 0)
|
|
123
300
|
return "";
|
|
124
|
-
}
|
|
125
|
-
// Cap output
|
|
126
301
|
let body;
|
|
127
302
|
if (outputLines.length > MAX_OUTPUT_LINES) {
|
|
128
303
|
const truncated = outputLines.slice(0, MAX_FIRST_CHUNK);
|
|
129
304
|
const remaining = outputLines.length - MAX_FIRST_CHUNK;
|
|
130
|
-
truncated.push(
|
|
305
|
+
truncated.push(applyContext(` ... (${remaining} more lines) ...`));
|
|
131
306
|
body = truncated.join("\n");
|
|
132
307
|
}
|
|
133
308
|
else {
|
|
134
309
|
body = outputLines.join("\n");
|
|
135
310
|
}
|
|
136
|
-
const
|
|
311
|
+
const linkedPath = fileHyperlink(filePath);
|
|
312
|
+
const header = applyHeader(`─── ${linkedPath} ───`);
|
|
137
313
|
return `${header}\n${body}`;
|
|
138
314
|
}
|
|
139
315
|
/** Diff marker used in tool output to separate normal output from diff data. */
|
package/dist/multi/markdown.js
CHANGED
|
@@ -14,9 +14,16 @@ const YELLOW = `${ESC}33m`;
|
|
|
14
14
|
const GREEN = `${ESC}32m`;
|
|
15
15
|
const MAGENTA = `${ESC}35m`;
|
|
16
16
|
const INVERSE = `${ESC}7m`;
|
|
17
|
-
const MAX_WIDTH = 80;
|
|
17
|
+
const MAX_WIDTH = Math.min(process.stdout.columns || 80, 120);
|
|
18
18
|
/** Render basic markdown to ANSI-colored terminal text. */
|
|
19
|
-
export function renderMarkdown(text) {
|
|
19
|
+
export function renderMarkdown(text, colors) {
|
|
20
|
+
const h = colors?.heading ?? BOLD + YELLOW;
|
|
21
|
+
const bd = colors?.bold ?? BOLD;
|
|
22
|
+
const it = colors?.italic ?? ITALIC;
|
|
23
|
+
const cd = colors?.code ?? CYAN + INVERSE;
|
|
24
|
+
const cbb = colors?.codeBlockBorder ?? DIM;
|
|
25
|
+
const lnk = colors?.link ?? `${ESC}4m${CYAN}`;
|
|
26
|
+
const rst = colors?.reset ?? RESET;
|
|
20
27
|
const lines = text.split("\n");
|
|
21
28
|
const out = [];
|
|
22
29
|
let inCodeBlock = false;
|
|
@@ -30,19 +37,29 @@ export function renderMarkdown(text) {
|
|
|
30
37
|
codeLang = line.trimStart().slice(3).trim();
|
|
31
38
|
codeBuffer = [];
|
|
32
39
|
const label = codeLang ? ` ${codeLang}` : "";
|
|
33
|
-
out.push(`${
|
|
40
|
+
out.push(`${cbb} ┌──${label}${"─".repeat(Math.max(0, MAX_WIDTH - 6 - label.length))}${rst}`);
|
|
34
41
|
}
|
|
35
42
|
else {
|
|
36
43
|
// Flush code buffer through syntax highlighter
|
|
37
44
|
const lang = codeLang ? detectLanguage(codeLang) : "generic";
|
|
38
|
-
const
|
|
45
|
+
const syntaxColors = colors ? {
|
|
46
|
+
keyword: colors.code,
|
|
47
|
+
string: colors.code,
|
|
48
|
+
number: colors.code,
|
|
49
|
+
comment: colors.codeBlockBorder,
|
|
50
|
+
type: colors.code,
|
|
51
|
+
variable: colors.code,
|
|
52
|
+
operator: colors.code,
|
|
53
|
+
reset: colors.reset,
|
|
54
|
+
} : undefined;
|
|
55
|
+
const highlighted = highlightCode(codeBuffer.join("\n"), lang, syntaxColors);
|
|
39
56
|
for (const hl of highlighted.split("\n")) {
|
|
40
|
-
out.push(`${
|
|
57
|
+
out.push(`${cbb} │ ${rst}${hl}`);
|
|
41
58
|
}
|
|
42
59
|
inCodeBlock = false;
|
|
43
60
|
codeLang = "";
|
|
44
61
|
codeBuffer = [];
|
|
45
|
-
out.push(`${
|
|
62
|
+
out.push(`${cbb} └${"─".repeat(MAX_WIDTH - 3)}${rst}`);
|
|
46
63
|
}
|
|
47
64
|
continue;
|
|
48
65
|
}
|
|
@@ -53,25 +70,26 @@ export function renderMarkdown(text) {
|
|
|
53
70
|
// Headers
|
|
54
71
|
const h3 = line.match(/^###\s+(.+)/);
|
|
55
72
|
if (h3) {
|
|
56
|
-
out.push(`${
|
|
73
|
+
out.push(`${h} ${h3[1]}${rst}`);
|
|
57
74
|
continue;
|
|
58
75
|
}
|
|
59
76
|
const h2 = line.match(/^##\s+(.+)/);
|
|
60
77
|
if (h2) {
|
|
61
|
-
out.push(`${
|
|
78
|
+
out.push(`${h} ${h2[1]}${rst}`);
|
|
62
79
|
continue;
|
|
63
80
|
}
|
|
64
81
|
const h1 = line.match(/^#\s+(.+)/);
|
|
65
82
|
if (h1) {
|
|
66
|
-
out.push(`${
|
|
83
|
+
out.push(`${h}${h1[1]}${rst}`);
|
|
67
84
|
continue;
|
|
68
85
|
}
|
|
69
86
|
// Bullet lists (-, *, +)
|
|
70
87
|
const bullet = line.match(/^(\s*)[*+-]\s+(.+)/);
|
|
71
88
|
if (bullet) {
|
|
72
89
|
const indent = bullet[1];
|
|
73
|
-
const content = renderInline(bullet[2]);
|
|
74
|
-
|
|
90
|
+
const content = renderInline(bullet[2], bd, it, cd, rst, lnk);
|
|
91
|
+
const blt = colors?.bullet ?? DIM + BOLD;
|
|
92
|
+
out.push(`${indent} ${blt}·${rst} ${content}`);
|
|
75
93
|
continue;
|
|
76
94
|
}
|
|
77
95
|
// Numbered lists
|
|
@@ -79,28 +97,36 @@ export function renderMarkdown(text) {
|
|
|
79
97
|
if (numbered) {
|
|
80
98
|
const indent = numbered[1];
|
|
81
99
|
const num = line.match(/^(\s*)(\d+[.)])/);
|
|
82
|
-
const content = renderInline(numbered[2]);
|
|
83
|
-
out.push(`${indent} ${DIM}${num[2]}${
|
|
100
|
+
const content = renderInline(numbered[2], bd, it, cd, rst, lnk);
|
|
101
|
+
out.push(`${indent} ${DIM}${num[2]}${rst} ${content}`);
|
|
84
102
|
continue;
|
|
85
103
|
}
|
|
86
104
|
// Regular line — apply inline formatting
|
|
87
|
-
out.push(renderInline(line));
|
|
105
|
+
out.push(renderInline(line, bd, it, cd, rst, lnk));
|
|
88
106
|
}
|
|
89
107
|
return out.join("\n");
|
|
90
108
|
}
|
|
91
|
-
/**
|
|
92
|
-
function
|
|
109
|
+
/** Wrap text in an OSC 8 hyperlink escape sequence. */
|
|
110
|
+
function osc8Link(url, text, linkStyle, reset) {
|
|
111
|
+
return `\x1b]8;;${url}\x07${linkStyle}${text}${reset}\x1b]8;;\x07`;
|
|
112
|
+
}
|
|
113
|
+
/** Apply inline formatting: bold, italic, inline code, links. */
|
|
114
|
+
function renderInline(text, bold = BOLD, italic = ITALIC, code = CYAN + INVERSE, reset = RESET, link = `${ESC}4m${CYAN}`) {
|
|
93
115
|
let result = text;
|
|
94
116
|
// Inline code (must go first to avoid bold/italic inside code)
|
|
95
|
-
result = result.replace(/`([^`]+)`/g, `${
|
|
117
|
+
result = result.replace(/`([^`]+)`/g, `${code} $1 ${reset}`);
|
|
118
|
+
// Markdown links [text](url) — render as OSC 8 hyperlinks
|
|
119
|
+
result = result.replace(/\[([^\]]+)\]\(([^)]+)\)/g, (_match, linkText, url) => {
|
|
120
|
+
return osc8Link(url, linkText, link, reset);
|
|
121
|
+
});
|
|
96
122
|
// Bold+italic (***text*** or ___text___)
|
|
97
|
-
result = result.replace(/\*\*\*(.+?)\*\*\*/g, `${
|
|
98
|
-
result = result.replace(/___(.+?)___/g, `${
|
|
123
|
+
result = result.replace(/\*\*\*(.+?)\*\*\*/g, `${bold}${italic}$1${reset}`);
|
|
124
|
+
result = result.replace(/___(.+?)___/g, `${bold}${italic}$1${reset}`);
|
|
99
125
|
// Bold (**text** or __text__)
|
|
100
|
-
result = result.replace(/\*\*(.+?)\*\*/g, `${
|
|
101
|
-
result = result.replace(/__(.+?)__/g, `${
|
|
126
|
+
result = result.replace(/\*\*(.+?)\*\*/g, `${bold}$1${reset}`);
|
|
127
|
+
result = result.replace(/__(.+?)__/g, `${bold}$1${reset}`);
|
|
102
128
|
// Italic (*text* or _text_ — careful not to match mid-word underscores)
|
|
103
|
-
result = result.replace(/(?<!\w)\*([^*]+)\*(?!\w)/g, `${
|
|
104
|
-
result = result.replace(/(?<!\w)_([^_]+)_(?!\w)/g, `${
|
|
129
|
+
result = result.replace(/(?<!\w)\*([^*]+)\*(?!\w)/g, `${italic}$1${reset}`);
|
|
130
|
+
result = result.replace(/(?<!\w)_([^_]+)_(?!\w)/g, `${italic}$1${reset}`);
|
|
105
131
|
return result;
|
|
106
132
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { getBuiltinModels, normalizeProviderId, REASONING_LEVELS } from "../models.js";
|
|
1
2
|
const ESC = "\x1b[";
|
|
2
3
|
const s = {
|
|
3
4
|
bold: (t) => `${ESC}1m${t}${ESC}0m`,
|
|
@@ -8,27 +9,17 @@ const s = {
|
|
|
8
9
|
magenta: (t) => `${ESC}35m${t}${ESC}0m`,
|
|
9
10
|
gray: (t) => `${ESC}90m${t}${ESC}0m`,
|
|
10
11
|
};
|
|
11
|
-
const REASONING_LEVELS = ["low", "medium", "high", "max"];
|
|
12
12
|
/** Models available per provider. Extend as needed. */
|
|
13
13
|
export function getAvailableModels(provider, currentModel) {
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
models.push({ id: "gpt-4o", provider: "openai", label: "GPT-4o", reasoning: null, reasoningRange: [], contextWindow: 128_000 }, { id: "o4-mini", provider: "openai", label: "o4-mini", reasoning: "medium", reasoningRange: ["low", "medium", "high"], contextWindow: 128_000 }, { id: "o3", provider: "openai", label: "o3", reasoning: "high", reasoningRange: ["low", "medium", "high", "max"], contextWindow: 200_000 });
|
|
24
|
-
break;
|
|
25
|
-
case "codex":
|
|
26
|
-
models.push({ id: "gpt-4o", provider: "codex", label: "GPT-4o", reasoning: null, reasoningRange: [], contextWindow: 128_000 }, { id: "o4-mini", provider: "codex", label: "o4-mini", reasoning: "medium", reasoningRange: ["low", "medium", "high"], contextWindow: 128_000 }, { id: "o3", provider: "codex", label: "o3", reasoning: "high", reasoningRange: ["low", "medium", "high", "max"], contextWindow: 200_000 });
|
|
27
|
-
break;
|
|
28
|
-
case "ollama":
|
|
29
|
-
models.push({ id: "qwen2.5-coder:14b", provider: "ollama", label: "Qwen 2.5 Coder 14B", reasoning: null, reasoningRange: [], contextWindow: 32_000 }, { id: "llama3.2", provider: "ollama", label: "Llama 3.2", reasoning: null, reasoningRange: [], contextWindow: 128_000 }, { id: "deepseek-r1:14b", provider: "ollama", label: "DeepSeek R1 14B", reasoning: "medium", reasoningRange: ["medium", "high"], contextWindow: 128_000 });
|
|
30
|
-
break;
|
|
31
|
-
}
|
|
14
|
+
const normalizedProvider = normalizeProviderId(provider) ?? "openrouter";
|
|
15
|
+
const models = getBuiltinModels(normalizedProvider).map((model) => ({
|
|
16
|
+
id: model.id,
|
|
17
|
+
provider: model.provider,
|
|
18
|
+
label: model.label,
|
|
19
|
+
reasoning: model.reasoningDefault,
|
|
20
|
+
reasoningRange: [...model.reasoningRange],
|
|
21
|
+
contextWindow: model.contextWindow,
|
|
22
|
+
}));
|
|
32
23
|
// If user has a custom model not in the list, add it
|
|
33
24
|
if (currentModel && !models.some((m) => m.id === currentModel)) {
|
|
34
25
|
models.unshift({
|
|
@@ -61,7 +52,7 @@ function renderReasoningMeter(level, range) {
|
|
|
61
52
|
* Show interactive model picker. Returns selected model + reasoning, or null on cancel.
|
|
62
53
|
* Works in raw mode — caller must be in raw mode already (TUI) or we'll set it.
|
|
63
54
|
*/
|
|
64
|
-
export function showModelPicker(provider, currentModel, w) {
|
|
55
|
+
export function showModelPicker(provider, currentModel, currentReasoning, w) {
|
|
65
56
|
const models = getAvailableModels(provider, currentModel);
|
|
66
57
|
if (models.length === 0) {
|
|
67
58
|
w.write(s.dim(" No models available for this provider.\n"));
|
|
@@ -71,7 +62,7 @@ export function showModelPicker(provider, currentModel, w) {
|
|
|
71
62
|
if (cursor < 0)
|
|
72
63
|
cursor = 0;
|
|
73
64
|
// Clone reasoning levels so we can adjust them
|
|
74
|
-
const reasoningState = models.map((m) => m.reasoning);
|
|
65
|
+
const reasoningState = models.map((m) => m.id === currentModel ? currentReasoning ?? m.reasoning : m.reasoning);
|
|
75
66
|
function render() {
|
|
76
67
|
// Clear previous render (move up by model count + header + footer + blank)
|
|
77
68
|
const totalLines = models.length + 4;
|
|
@@ -62,6 +62,23 @@ export function wireSpawnerEvents(spawner, ctx) {
|
|
|
62
62
|
}
|
|
63
63
|
ctx.render();
|
|
64
64
|
});
|
|
65
|
+
spawner.on("idle", (agentId, reason, dmSummaries) => {
|
|
66
|
+
const pane = ctx.getOrCreatePane(agentId);
|
|
67
|
+
const style = getAgentStyle(pane.index);
|
|
68
|
+
appendToPane(pane, s.dim(` ${style.icon} Agent idle (${reason})`) + "\n");
|
|
69
|
+
if (dmSummaries && dmSummaries.length > 0) {
|
|
70
|
+
appendToPane(pane, s.dim(" Messages received while running:") + "\n");
|
|
71
|
+
for (const dm of dmSummaries) {
|
|
72
|
+
appendToPane(pane, s.yellow(` [${dm.from}] ${dm.content.slice(0, 100)}`) + "\n");
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
ctx.render();
|
|
76
|
+
});
|
|
77
|
+
spawner.on("shutdown_approved", (agentId) => {
|
|
78
|
+
const pane = ctx.getOrCreatePane(agentId);
|
|
79
|
+
appendToPane(pane, s.dim(" Agent shut down gracefully.") + "\n");
|
|
80
|
+
ctx.render();
|
|
81
|
+
});
|
|
65
82
|
spawner.on("message", (from, to, content) => {
|
|
66
83
|
const senderPane = ctx.panes.get(from);
|
|
67
84
|
if (senderPane) {
|
|
@@ -10,42 +10,49 @@ import * as fs from "fs";
|
|
|
10
10
|
import * as path from "path";
|
|
11
11
|
import * as os from "os";
|
|
12
12
|
import { hasCodexToken } from "../providers/codex-auth.js";
|
|
13
|
+
import { getAuthStatusEntries } from "@phren/cli/auth/profiles";
|
|
14
|
+
import { getBuiltinModels } from "../models.js";
|
|
13
15
|
const CONFIG_DIR = path.join(os.homedir(), ".phren-agent");
|
|
14
16
|
const PROVIDERS_FILE = path.join(CONFIG_DIR, "providers.json");
|
|
15
17
|
export function getProviderStatuses() {
|
|
18
|
+
const auth = new Map(getAuthStatusEntries().map((entry) => [entry.provider, entry]));
|
|
16
19
|
return [
|
|
17
20
|
{
|
|
18
21
|
name: "openrouter",
|
|
19
|
-
configured:
|
|
22
|
+
configured: auth.get("openrouter")?.configured ?? false,
|
|
20
23
|
authMethod: "api-key",
|
|
24
|
+
authSource: auth.get("openrouter")?.source ?? "none",
|
|
21
25
|
keyEnvVar: "OPENROUTER_API_KEY",
|
|
22
|
-
models:
|
|
26
|
+
models: getBuiltinModels("openrouter").map((model) => model.id),
|
|
23
27
|
},
|
|
24
28
|
{
|
|
25
29
|
name: "anthropic",
|
|
26
|
-
configured:
|
|
30
|
+
configured: auth.get("anthropic")?.configured ?? false,
|
|
27
31
|
authMethod: "api-key",
|
|
32
|
+
authSource: auth.get("anthropic")?.source ?? "none",
|
|
28
33
|
keyEnvVar: "ANTHROPIC_API_KEY",
|
|
29
|
-
models:
|
|
34
|
+
models: getBuiltinModels("anthropic").map((model) => model.id),
|
|
30
35
|
},
|
|
31
36
|
{
|
|
32
37
|
name: "openai",
|
|
33
|
-
configured:
|
|
38
|
+
configured: auth.get("openai")?.configured ?? false,
|
|
34
39
|
authMethod: "api-key",
|
|
40
|
+
authSource: auth.get("openai")?.source ?? "none",
|
|
35
41
|
keyEnvVar: "OPENAI_API_KEY",
|
|
36
|
-
models:
|
|
42
|
+
models: getBuiltinModels("openai").map((model) => model.id),
|
|
37
43
|
},
|
|
38
44
|
{
|
|
39
|
-
name: "codex",
|
|
45
|
+
name: "openai-codex",
|
|
40
46
|
configured: hasCodexToken(),
|
|
41
47
|
authMethod: "oauth",
|
|
42
|
-
|
|
48
|
+
authSource: auth.get("openai-codex")?.source ?? "none",
|
|
49
|
+
models: getBuiltinModels("openai-codex").map((model) => model.id),
|
|
43
50
|
},
|
|
44
51
|
{
|
|
45
52
|
name: "ollama",
|
|
46
53
|
configured: (process.env.PHREN_OLLAMA_URL ?? "").toLowerCase() !== "off",
|
|
47
54
|
authMethod: "local",
|
|
48
|
-
models:
|
|
55
|
+
models: getBuiltinModels("ollama").map((model) => model.id),
|
|
49
56
|
},
|
|
50
57
|
];
|
|
51
58
|
}
|
|
@@ -104,12 +111,15 @@ export function formatProviderList() {
|
|
|
104
111
|
for (const p of statuses) {
|
|
105
112
|
const icon = p.configured ? `${GREEN}●${RESET}` : `${RED}○${RESET}`;
|
|
106
113
|
const auth = p.configured ? `${GREEN}configured${RESET}` : p.authMethod === "oauth"
|
|
107
|
-
? `${DIM}run: phren
|
|
114
|
+
? `${DIM}run: phren auth login${RESET}`
|
|
108
115
|
: p.keyEnvVar
|
|
109
|
-
? `${DIM}set ${p.keyEnvVar}${RESET}`
|
|
116
|
+
? `${DIM}set ${p.keyEnvVar} or phren auth set-key ${p.name}${RESET}`
|
|
110
117
|
: `${DIM}local${RESET}`;
|
|
118
|
+
const source = p.configured && p.authSource && p.authSource !== "none"
|
|
119
|
+
? `${DIM}${p.authSource}${RESET}`
|
|
120
|
+
: null;
|
|
111
121
|
const modelCount = `${DIM}${p.models.length} models${RESET}`;
|
|
112
|
-
lines.push(` ${icon} ${BOLD}${p.name}${RESET} ${auth} ${modelCount}`);
|
|
122
|
+
lines.push(` ${icon} ${BOLD}${p.name}${RESET} ${auth}${source ? ` ${source}` : ""} ${modelCount}`);
|
|
113
123
|
}
|
|
114
124
|
const custom = getCustomModels();
|
|
115
125
|
if (custom.length > 0) {
|
|
@@ -119,7 +129,7 @@ export function formatProviderList() {
|
|
|
119
129
|
return lines.join("\n");
|
|
120
130
|
}
|
|
121
131
|
export function formatModelAddHelp() {
|
|
122
|
-
return `${DIM}Usage: /model add <model-id> [provider=X] [context=128000] [reasoning=low|medium|high|
|
|
132
|
+
return `${DIM}Usage: /model add <model-id> [provider=X] [context=128000] [reasoning=low|medium|high|xhigh]
|
|
123
133
|
|
|
124
134
|
Examples:
|
|
125
135
|
/model add meta-llama/llama-3.1-405b provider=openrouter context=128000
|