-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconsole.ts
More file actions
159 lines (140 loc) · 4.44 KB
/
Copy pathconsole.ts
File metadata and controls
159 lines (140 loc) · 4.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
/**
* Console output utilities for conversation display.
* Separate from logging - this is for user-facing chat output.
*/
import pc from "picocolors";
import boxen from "boxen";
import logSymbols from "log-symbols";
let claudeTurnStarted = false;
let thinkingBlockActive = false;
export const console_out = {
/**
* Print the welcome banner in a styled box
*/
banner(message: string): void {
console.log(
boxen(pc.bold(message), {
padding: { top: 0, bottom: 0, left: 1, right: 1 },
borderColor: "cyan",
borderStyle: "round",
})
);
console.log();
},
/**
* Get the styled "You: " prompt string for readline
*/
userPromptString(): string {
return `${pc.blue(pc.bold("You"))} ${pc.dim("›")} `;
},
/**
* Print Claude's response. Only shows "Claude:" prefix once per turn.
* Call finishClaudeTurn() when the turn is complete.
*/
claude(text: string): void {
if (!claudeTurnStarted) {
console.log();
console.log(`${pc.green(pc.bold("Claude"))} ${pc.dim("›")} ${text}`);
claudeTurnStarted = true;
} else {
console.log();
console.log(text);
}
},
/**
* Print Claude's streaming text delta. Shows "Claude:" prefix once per turn.
* Does not add newlines - text is printed as it streams.
*/
claudeStream(delta: string): void {
if (!claudeTurnStarted) {
process.stdout.write(`\n${pc.green(pc.bold("Claude"))} ${pc.dim("›")} `);
claudeTurnStarted = true;
}
process.stdout.write(delta);
},
/**
* Print tool call start indicator
*/
toolStart(toolName: string, input?: any): void {
const width = (process.stdout.columns || 80) - 5;
const prefix = `⚡ Calling ${toolName} `;
const line = pc.dim("─".repeat(Math.max(0, width - prefix.length)));
console.log(`\n${pc.yellow("⚡")} ${pc.bold("Calling")} ${pc.yellow(pc.bold(toolName))} ${line}`);
if (input && Object.keys(input).length > 0) {
for (const [key, value] of Object.entries(input)) {
console.log(` ${pc.dim(key)}: ${pc.cyan(String(value))}`);
}
console.log();
}
},
/**
* Print tool execution result indicator
*/
toolEnd(toolName: string, success: boolean): void {
const width = (process.stdout.columns || 80) - 5;
const prefix = `✓ Finished ${toolName} `;
const line = pc.dim("─".repeat(Math.max(0, width - prefix.length)));
if (success) {
console.log(`${pc.green("✓")} ${pc.bold("Finished")} ${pc.green(pc.bold(toolName))} ${line}\n`);
} else {
console.log(`${pc.red("✗")} ${pc.bold("Failed")} ${pc.red(pc.bold(toolName))} ${line}\n`);
}
},
/**
* Mark the end of Claude's turn (resets prefix tracking).
* Call this after user input loop resumes.
*/
finishClaudeTurn(): void {
if (claudeTurnStarted) {
console.log();
claudeTurnStarted = false;
}
thinkingBlockActive = false;
},
/**
* Start a thinking block
*/
thinkingStart(): void {
thinkingBlockActive = true;
console.log(`\n${pc.dim("💭")} ${pc.cyan(pc.bold("Thinking..."))}`);
},
/**
* Stream thinking content with dimmed styling
*/
thinkingStream(delta: string): void {
process.stdout.write(pc.dim(pc.cyan(delta)));
},
/**
* End thinking block
*/
thinkingEnd(): void {
if (thinkingBlockActive) {
console.log();
thinkingBlockActive = false;
}
},
/**
* Print an error message with symbol
*/
error(message: string): void {
console.error(`${logSymbols.error} ${pc.red(pc.bold("Error"))}: ${message}`);
},
/**
* Print a success message with symbol
*/
success(message: string): void {
console.log(`${logSymbols.success} ${pc.green(message)}`);
},
/**
* Print a warning message with symbol
*/
warn(message: string): void {
console.warn(`${logSymbols.warning} ${pc.yellow(message)}`);
},
/**
* Print an info message with symbol
*/
info(message: string): void {
console.log(`${logSymbols.info} ${pc.cyan(message)}`);
},
};