@giladbarnea/pi-simple-team 1.0.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/LICENSE +21 -0
- package/README.md +65 -0
- package/child-tools.ts +117 -0
- package/index.ts +751 -0
- package/model-preflight.ts +72 -0
- package/package.json +43 -0
- package/render-support/ansi.ts +206 -0
- package/render-support/glyphs.ts +157 -0
- package/render-support/settings.ts +174 -0
- package/render-support/text.ts +336 -0
- package/render-support/theme.ts +71 -0
- package/render.ts +494 -0
- package/system-prompt.ts +15 -0
- package/teamlog.ts +245 -0
|
@@ -0,0 +1,336 @@
|
|
|
1
|
+
import { getCapabilities, hyperlink, wrapTextWithAnsi } from "@earendil-works/pi-tui";
|
|
2
|
+
import * as os from "node:os";
|
|
3
|
+
import { basename, extname, resolve as resolvePath } from "node:path";
|
|
4
|
+
import { pathToFileURL } from "node:url";
|
|
5
|
+
|
|
6
|
+
import { stableRenderWidth, stripAnsi } from "./ansi.js";
|
|
7
|
+
import { glyphs, truncateText } from "./glyphs.js";
|
|
8
|
+
import { pendingStatusAnimation, settingNumber, stackToolCalls } from "./settings.js";
|
|
9
|
+
import { stackPrefix, toolLabel, treeConnector, type TreeBranch } from "./theme.js";
|
|
10
|
+
|
|
11
|
+
export class TruncatedLines {
|
|
12
|
+
private cachedLines?: string[];
|
|
13
|
+
private cachedWidth?: number;
|
|
14
|
+
private readonly lines: string[];
|
|
15
|
+
|
|
16
|
+
constructor(text: string) {
|
|
17
|
+
this.lines = text ? text.split(/\r?\n/) : [];
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
invalidate(): void {
|
|
21
|
+
this.cachedLines = undefined;
|
|
22
|
+
this.cachedWidth = undefined;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
render(width: number): string[] {
|
|
26
|
+
if (this.cachedLines && this.cachedWidth === width) return this.cachedLines;
|
|
27
|
+
const targetWidth = stableRenderWidth(width);
|
|
28
|
+
const lines = this.lines.flatMap((line) => {
|
|
29
|
+
const wrapped = wrapTextWithAnsi(line, targetWidth);
|
|
30
|
+
return wrapped.length > 0 ? wrapped : [""];
|
|
31
|
+
});
|
|
32
|
+
this.cachedLines = lines;
|
|
33
|
+
this.cachedWidth = width;
|
|
34
|
+
return lines;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export function makeTruncatedLines(text: string): TruncatedLines {
|
|
39
|
+
return new TruncatedLines(text);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export function makeEmpty() {
|
|
43
|
+
return {
|
|
44
|
+
invalidate() {},
|
|
45
|
+
render(): string[] {
|
|
46
|
+
return [];
|
|
47
|
+
},
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export function componentHasVisibleLines(component: unknown): boolean {
|
|
52
|
+
try {
|
|
53
|
+
const render = (component as any)?.render;
|
|
54
|
+
return typeof render === "function" && render.call(component, 120).length > 0;
|
|
55
|
+
} catch {
|
|
56
|
+
return false;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export function lineCount(text: string): number {
|
|
61
|
+
if (!text) return 0;
|
|
62
|
+
const normalized = text.replace(/\r?\n$/, "");
|
|
63
|
+
if (!normalized) return 0;
|
|
64
|
+
return normalized.split(/\r?\n/).length;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export function textContent(result: any): string {
|
|
68
|
+
const part = result?.content?.find?.((candidate: any) => candidate?.type === "text" && typeof candidate.text === "string");
|
|
69
|
+
return part?.text ?? "";
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export function clipLine(line: string, cwd?: string): string {
|
|
73
|
+
const max = Math.max(40, Math.floor(settingNumber("maxLineWidth", 1000, cwd)));
|
|
74
|
+
return truncateText(line, max, cwd);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export function preview(text: string, count: number, direction: "head" | "tail", cwd?: string): string {
|
|
78
|
+
const lines = text.split(/\r?\n/);
|
|
79
|
+
const selected = direction === "head" ? lines.slice(0, count) : lines.slice(-count);
|
|
80
|
+
return selected.map((line) => clipLine(line, cwd)).join("\n");
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export function commandExit(text: string): number | null {
|
|
84
|
+
const match = text.match(/exit code:\s*(\d+)/i) ?? text.match(/exit\s+(\d+)/i);
|
|
85
|
+
return match ? Number.parseInt(match[1]!, 10) : null;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export function diffStats(diff: string): { additions: number; removals: number } {
|
|
89
|
+
let additions = 0;
|
|
90
|
+
let removals = 0;
|
|
91
|
+
for (const line of diff.split(/\r?\n/)) {
|
|
92
|
+
if (line.startsWith("+") && !line.startsWith("+++")) additions += 1;
|
|
93
|
+
if (line.startsWith("-") && !line.startsWith("---")) removals += 1;
|
|
94
|
+
}
|
|
95
|
+
return { additions, removals };
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export function truncatedMarker(text: string): boolean {
|
|
99
|
+
return /^\s*\[(?:Output|Full output|Read output|Search output|Bash output)[^\n\]]*truncated|^\s*\[[^\n\]]*Full output saved to:/im.test(text);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export function resultTruncated(result: any): boolean {
|
|
103
|
+
const details = result?.details;
|
|
104
|
+
if (typeof details?.truncation?.truncated === "boolean") return details.truncation.truncated;
|
|
105
|
+
if (typeof details?.truncated === "boolean") return details.truncated;
|
|
106
|
+
return truncatedMarker(textContent(result));
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
export function readResultSummary(result: any, args: any, theme: any): string {
|
|
110
|
+
const truncation = result?.details?.truncation;
|
|
111
|
+
if (truncation?.truncated && typeof truncation.outputLines === "number" && typeof truncation.totalLines === "number") {
|
|
112
|
+
let summary = theme.fg("success", `${truncation.outputLines}/${truncation.totalLines} lines`) + theme.fg("warning", " · truncated");
|
|
113
|
+
if (!truncation.firstLineExceedsLimit && truncation.outputLines > 0) {
|
|
114
|
+
const startLine = Math.max(1, Math.floor(Number(args?.offset) || 1));
|
|
115
|
+
summary += theme.fg("dim", ` · continue offset=${startLine + truncation.outputLines}`);
|
|
116
|
+
}
|
|
117
|
+
return summary;
|
|
118
|
+
}
|
|
119
|
+
const count = lineCount(textContent(result));
|
|
120
|
+
let summary = theme.fg("success", `${count} line${count === 1 ? "" : "s"}`);
|
|
121
|
+
if (resultTruncated(result)) summary += theme.fg("warning", " · truncated");
|
|
122
|
+
return summary;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
interface BlinkEntry {
|
|
126
|
+
invalidate: () => void;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
const blinkEntries = new Map<unknown, BlinkEntry>();
|
|
130
|
+
let blinkTimer: ReturnType<typeof setInterval> | undefined;
|
|
131
|
+
|
|
132
|
+
function blinkKey(context: any): unknown {
|
|
133
|
+
return context?.toolCallId ?? context?.id ?? context;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
function startBlinkTimer(): void {
|
|
137
|
+
if (blinkTimer) return;
|
|
138
|
+
blinkTimer = setInterval(() => {
|
|
139
|
+
for (const entry of blinkEntries.values()) {
|
|
140
|
+
try {
|
|
141
|
+
entry.invalidate();
|
|
142
|
+
} catch {
|
|
143
|
+
// Rendering invalidation is best-effort only.
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
if (blinkEntries.size === 0 && blinkTimer) {
|
|
147
|
+
clearInterval(blinkTimer);
|
|
148
|
+
blinkTimer = undefined;
|
|
149
|
+
}
|
|
150
|
+
}, 450);
|
|
151
|
+
blinkTimer.unref?.();
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
function trackBlink(context: any): void {
|
|
155
|
+
const key = blinkKey(context);
|
|
156
|
+
if (!key || typeof context?.invalidate !== "function") return;
|
|
157
|
+
blinkEntries.set(key, { invalidate: () => context.invalidate() });
|
|
158
|
+
startBlinkTimer();
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
export function clearBlink(context: any): void {
|
|
162
|
+
const key = blinkKey(context);
|
|
163
|
+
if (key) blinkEntries.delete(key);
|
|
164
|
+
if (blinkEntries.size === 0 && blinkTimer) {
|
|
165
|
+
clearInterval(blinkTimer);
|
|
166
|
+
blinkTimer = undefined;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
export function blinkingPrefix(theme: any, context: any, cwd?: string): string {
|
|
171
|
+
trackBlink(context);
|
|
172
|
+
const on = Math.floor(Date.now() / 450) % 2 === 0;
|
|
173
|
+
const g = glyphs(context?.cwd ?? cwd);
|
|
174
|
+
return theme.fg(on ? "success" : "muted", on ? g.bullet : g.emptyBullet);
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
export function pendingStatusPrefix(theme: any, context: any, cwd?: string): string {
|
|
178
|
+
if (pendingStatusAnimation(context?.cwd ?? cwd)) return blinkingPrefix(theme, context, cwd);
|
|
179
|
+
clearBlink(context);
|
|
180
|
+
return theme.fg("warning", glyphs(context?.cwd ?? cwd).bullet);
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
export function renderPendingCall(call: string, theme: any, context: any, cwd?: string): TruncatedLines | ReturnType<typeof makeEmpty> {
|
|
184
|
+
if (!context?.executionStarted || !context?.isPartial || stackToolCalls(context?.cwd ?? cwd)) return makeEmpty();
|
|
185
|
+
return makeTruncatedLines(`${pendingStatusPrefix(theme, context, cwd)}${call}`);
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
export function renderPendingDetail(text: string, theme: any, cwd?: string): TruncatedLines {
|
|
189
|
+
return makeTruncatedLines(`${treeConnector(theme, "└", cwd)}${theme.fg("warning", text)}`);
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
const NF_DIR = "";
|
|
193
|
+
const NF_FILE = "";
|
|
194
|
+
const ICON_BY_NAME: Record<string, string> = {
|
|
195
|
+
"dockerfile": "",
|
|
196
|
+
"license": "",
|
|
197
|
+
"makefile": "",
|
|
198
|
+
"package.json": "",
|
|
199
|
+
"readme.md": "",
|
|
200
|
+
"tsconfig.json": "",
|
|
201
|
+
};
|
|
202
|
+
const ICON_BY_EXT: Record<string, string> = {
|
|
203
|
+
bash: "",
|
|
204
|
+
c: "",
|
|
205
|
+
cpp: "",
|
|
206
|
+
css: "",
|
|
207
|
+
gif: "",
|
|
208
|
+
go: "",
|
|
209
|
+
graphql: "",
|
|
210
|
+
html: "",
|
|
211
|
+
java: "",
|
|
212
|
+
jpg: "",
|
|
213
|
+
jpeg: "",
|
|
214
|
+
js: "",
|
|
215
|
+
json: "",
|
|
216
|
+
jsx: "",
|
|
217
|
+
lock: "",
|
|
218
|
+
lua: "",
|
|
219
|
+
md: "",
|
|
220
|
+
png: "",
|
|
221
|
+
py: "",
|
|
222
|
+
rb: "",
|
|
223
|
+
rs: "",
|
|
224
|
+
scss: "",
|
|
225
|
+
sh: "",
|
|
226
|
+
sql: "",
|
|
227
|
+
svg: "",
|
|
228
|
+
svelte: "",
|
|
229
|
+
toml: "",
|
|
230
|
+
ts: "",
|
|
231
|
+
tsx: "",
|
|
232
|
+
vue: "",
|
|
233
|
+
xml: "",
|
|
234
|
+
yaml: "",
|
|
235
|
+
yml: "",
|
|
236
|
+
zsh: "",
|
|
237
|
+
};
|
|
238
|
+
|
|
239
|
+
|
|
240
|
+
export function nerdIcon(pathText: string, isDirectory = false, theme?: any, cwd?: string): string {
|
|
241
|
+
if (glyphs(cwd).line === "-") return theme?.fg ? theme.fg(isDirectory ? "accent" : "muted", isDirectory ? "d" : "f") : (isDirectory ? "d" : "f");
|
|
242
|
+
if (isDirectory) return theme?.fg ? theme.fg("accent", NF_DIR) : NF_DIR;
|
|
243
|
+
const clean = stripAnsi(pathText).trim().replace(/\/$/, "");
|
|
244
|
+
const name = basename(clean).toLowerCase();
|
|
245
|
+
const icon = ICON_BY_NAME[name] ?? ICON_BY_EXT[extname(name).replace(/^\./, "").toLowerCase()] ?? NF_FILE;
|
|
246
|
+
const token = icon === NF_FILE ? "muted" : "accent";
|
|
247
|
+
return theme?.fg ? theme.fg(token, icon) : icon;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
export function renderPathListPreview(output: string, toolName: "find" | "ls", theme: any, expanded: boolean, cwd?: string): string {
|
|
251
|
+
const rawItems = output.split(/\r?\n/).filter((line) => line.trim().length > 0);
|
|
252
|
+
if (rawItems.length === 0) return theme.fg("muted", toolName === "ls" ? "empty directory" : "no files found");
|
|
253
|
+
const limit = Math.max(1, Math.floor(settingNumber("searchPreviewLines", 80, cwd)));
|
|
254
|
+
const shown = rawItems.slice(0, expanded ? limit : Math.min(limit, 12));
|
|
255
|
+
const lines = shown.map((item, index) => {
|
|
256
|
+
const clean = stripAnsi(item).trim();
|
|
257
|
+
const isDir = clean.endsWith("/");
|
|
258
|
+
const branch = index === shown.length - 1 && shown.length === rawItems.length ? "└" : "├";
|
|
259
|
+
const icon = nerdIcon(clean, isDir, theme, cwd);
|
|
260
|
+
const label = isDir ? theme.fg("accent", theme.bold(clean)) : theme.fg("dim", clean);
|
|
261
|
+
return `${treeConnector(theme, branch as "├" | "└", cwd)}${icon} ${label}`;
|
|
262
|
+
});
|
|
263
|
+
const remaining = rawItems.length - shown.length;
|
|
264
|
+
if (remaining > 0) {
|
|
265
|
+
const noun = toolName === "ls" ? (remaining === 1 ? "entry" : "entries") : `file${remaining === 1 ? "" : "s"}`;
|
|
266
|
+
lines.push(`${treeConnector(theme, "└", cwd)}${theme.fg("muted", `${glyphs(cwd).ellipsis} ${remaining} more ${noun}`)}`);
|
|
267
|
+
}
|
|
268
|
+
return lines.join("\n");
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
export function shortenPath(pathText: string): string {
|
|
272
|
+
if (typeof pathText !== "string") return "";
|
|
273
|
+
const home = os.homedir();
|
|
274
|
+
if (pathText === home) return "~";
|
|
275
|
+
if (pathText.startsWith(`${home}/`)) return `~${pathText.slice(home.length)}`;
|
|
276
|
+
return pathText;
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
export function linkPath(styledText: string, rawPath: string, cwd?: string, hyperlinks = getCapabilities().hyperlinks): string {
|
|
280
|
+
if (!hyperlinks) return styledText;
|
|
281
|
+
const absolutePath = resolvePath(cwd || process.cwd(), rawPath || ".");
|
|
282
|
+
return hyperlink(styledText, pathToFileURL(absolutePath).href);
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
export function renderToolPathText(rawPath: unknown, theme: any, cwd?: string, options?: { emptyFallback?: string }, hyperlinks = getCapabilities().hyperlinks): string {
|
|
286
|
+
const value = typeof rawPath === "string" ? rawPath : rawPath == null ? "" : String(rawPath);
|
|
287
|
+
const displayPath = value || options?.emptyFallback;
|
|
288
|
+
if (!displayPath) return theme.fg("accent", "");
|
|
289
|
+
return linkPath(theme.fg("accent", shortenPath(displayPath)), displayPath, cwd, hyperlinks);
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
export function readCallText(args: any, theme: any, cwd?: string, hyperlinks?: boolean): string {
|
|
293
|
+
const range = args?.offset || args?.limit ? `:${args.offset ?? 1}${args.limit ? `-${Number(args.offset ?? 1) + Number(args.limit) - 1}` : ""}` : "";
|
|
294
|
+
return `${toolLabel(theme, "Read ")}${renderToolPathText(args?.path ?? args?.file_path ?? "", theme, cwd, undefined, hyperlinks)}${range ? theme.fg("accent", range) : ""}`;
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
export function bashCallText(args: any, theme: any, cwd?: string): string {
|
|
298
|
+
const max = Math.max(20, Math.floor(settingNumber("commandPreviewChars", 96, cwd)));
|
|
299
|
+
const rawCommand = typeof args?.command === "string" ? args.command : "";
|
|
300
|
+
const command = truncateText(rawCommand, max, cwd);
|
|
301
|
+
const commandLines = command.split(/\r?\n/);
|
|
302
|
+
const [firstLine = "", ...continuationLines] = commandLines;
|
|
303
|
+
const styledFirstLine = theme.fg("accent", firstLine);
|
|
304
|
+
const styledContinuation = continuationLines.map((line) => theme.fg("accent", line)).join("\n");
|
|
305
|
+
return `${toolLabel(theme, "Bash $ ")}${styledFirstLine}${styledContinuation ? `\n${styledContinuation}` : ""}`;
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
export function isGitDiffCommand(command: unknown): boolean {
|
|
309
|
+
if (typeof command !== "string" || !command.trim()) return false;
|
|
310
|
+
const normalized = command.replace(/\\\r?\n/g, " ").replace(/\s+/g, " ").trim();
|
|
311
|
+
// Match common shell forms such as `git diff`, `git --no-pager diff`,
|
|
312
|
+
// `git -C repo diff`, `env GIT_PAGER=cat git diff`, and chained commands.
|
|
313
|
+
return /(?:^|[;&|()]\s*)(?:(?:env\s+(?:-\S+\s+)*(?:[A-Za-z_][A-Za-z0-9_]*=\S+\s+)*)|(?:command\s+))*git(?:\s+(?!--?diff\b)(?:-[A-Za-z]\S*|--\S+)(?:\s+(?!diff(?:\s|$))\S+)*)*\s+diff(?:\s|$)/.test(normalized);
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
export function readOnlyCallText(toolName: string, args: any, theme: any, cwd?: string, hyperlinks?: boolean): string {
|
|
317
|
+
if (toolName === "ls") return `${toolLabel(theme, `${toolName} `)}${renderToolPathText(args?.path ?? ".", theme, cwd, undefined, hyperlinks)}`;
|
|
318
|
+
const query = args?.pattern ?? args?.glob ?? args?.path ?? args?.query ?? "";
|
|
319
|
+
const rendered = args?.pattern === undefined && args?.glob === undefined && typeof args?.path === "string"
|
|
320
|
+
? renderToolPathText(args.path, theme, cwd, undefined, hyperlinks)
|
|
321
|
+
: theme.fg("accent", clipLine(String(query), cwd));
|
|
322
|
+
return `${toolLabel(theme, `${toolName} `)}${rendered}`;
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
export function plural(count: number, singular: string, pluralText = `${singular}s`): string {
|
|
326
|
+
return `${count} ${count === 1 ? singular : pluralText}`;
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
export function joinPhrases(parts: string[]): string {
|
|
330
|
+
if (parts.length <= 1) return parts[0] ?? "";
|
|
331
|
+
if (parts.length === 2) return `${parts[0]} and ${parts[1]}`;
|
|
332
|
+
return `${parts.slice(0, -1).join(", ")}, and ${parts[parts.length - 1]}`;
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
// stackPrefix re-exported here so callers can keep a single import surface.
|
|
336
|
+
export { stackPrefix };
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { glyphs, glyphStyle, treeGlyph as configuredTreeGlyph } from "./glyphs.js";
|
|
2
|
+
|
|
3
|
+
export const FALLBACK_THEME = {
|
|
4
|
+
bg(_token: string, text: string) {
|
|
5
|
+
return text;
|
|
6
|
+
},
|
|
7
|
+
bold(text: string) {
|
|
8
|
+
return `\x1b[1m${text}\x1b[22m`;
|
|
9
|
+
},
|
|
10
|
+
fg(_token: string, text: string) {
|
|
11
|
+
return text;
|
|
12
|
+
},
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export function fgToken(theme: any, token: string, text: string, rejectTextFallback = false): string | undefined {
|
|
16
|
+
try {
|
|
17
|
+
const styled = theme?.fg?.(token, text);
|
|
18
|
+
if (typeof styled !== "string" || styled === text) return undefined;
|
|
19
|
+
if (rejectTextFallback && token !== "text") {
|
|
20
|
+
try {
|
|
21
|
+
const textStyled = theme?.fg?.("text", text);
|
|
22
|
+
if (typeof textStyled === "string" && textStyled !== text && styled === textStyled) return undefined;
|
|
23
|
+
} catch {
|
|
24
|
+
// Ignore and accept the token styling.
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
return styled;
|
|
28
|
+
} catch {
|
|
29
|
+
return undefined;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function subtleRule(theme: any, text: string): string {
|
|
34
|
+
return fgToken(theme, "borderMuted", text, true)
|
|
35
|
+
?? fgToken(theme, "muted", text, true)
|
|
36
|
+
?? fgToken(theme, "dim", text, true)
|
|
37
|
+
?? `\x1b[90m${text}\x1b[39m`;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export function toolRule(theme: any, text: string): string {
|
|
41
|
+
return fgToken(theme, "muted", text, true) ?? fgToken(theme, "dim", text, true) ?? text;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export function borderMuted(theme: any, text: string): string {
|
|
45
|
+
return subtleRule(theme, text);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export type TreeBranch = "├" | "└" | "│";
|
|
49
|
+
|
|
50
|
+
export function treeGlyph(branch: TreeBranch, cwd?: string): string {
|
|
51
|
+
const glyph = configuredTreeGlyph(branch, cwd);
|
|
52
|
+
return glyphStyle(cwd) === "ascii" ? glyph : ` ${glyph}`;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export function treeConnector(theme: any, branch: TreeBranch = "├", cwd?: string): string {
|
|
56
|
+
return toolRule(theme, treeGlyph(branch, cwd));
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export function treeStem(theme: any, branch: TreeBranch, cwd?: string): string {
|
|
60
|
+
if (branch === "└") return theme.fg("muted", glyphStyle(cwd) === "ascii" ? " " : " ");
|
|
61
|
+
return treeConnector(theme, "│", cwd);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export function toolLabel(theme: any, label: string): string {
|
|
65
|
+
return theme.fg("text", theme.bold(label));
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export function stackPrefix(theme: any, cwd?: string): string {
|
|
69
|
+
const bullet = glyphs(cwd).bullet;
|
|
70
|
+
return fgToken(theme, "toolBullet", bullet, true) ?? fgToken(theme, "accent", bullet, true) ?? theme.fg("accent", bullet);
|
|
71
|
+
}
|