feat: add usage tracking, output mode, and cli exit mode (#7)
This commit is contained in:
@@ -26,6 +26,7 @@ export function Input({
|
||||
onSubmit,
|
||||
permissionMode: externalMode,
|
||||
onPermissionModeChange,
|
||||
onExit,
|
||||
}: {
|
||||
visible?: boolean;
|
||||
streaming: boolean;
|
||||
@@ -35,6 +36,7 @@ export function Input({
|
||||
onSubmit: (message?: string) => void;
|
||||
permissionMode?: PermissionMode;
|
||||
onPermissionModeChange?: (mode: PermissionMode) => void;
|
||||
onExit?: () => void;
|
||||
}) {
|
||||
const [value, setValue] = useState("");
|
||||
const [escapePressed, setEscapePressed] = useState(false);
|
||||
@@ -84,7 +86,8 @@ export function Input({
|
||||
useInput((input, key) => {
|
||||
if (input === "c" && key.ctrl) {
|
||||
if (ctrlCPressed) {
|
||||
// Second CTRL-C - exit application
|
||||
// Second CTRL-C - call onExit callback then exit application
|
||||
if (onExit) onExit();
|
||||
process.exit(0);
|
||||
} else {
|
||||
// First CTRL-C - start 1-second timer
|
||||
@@ -209,7 +212,7 @@ export function Input({
|
||||
message={thinkingMessage}
|
||||
shimmerOffset={shimmerOffset}
|
||||
/>
|
||||
{shouldShowTokenCount && <Text dimColor> ({tokenCount}↑)</Text>}
|
||||
{shouldShowTokenCount && <Text dimColor> ({tokenCount} ↑)</Text>}
|
||||
</Box>
|
||||
</Box>
|
||||
)}
|
||||
|
||||
34
src/cli/components/SessionStats.tsx
Normal file
34
src/cli/components/SessionStats.tsx
Normal file
@@ -0,0 +1,34 @@
|
||||
import { Box, Text } from "ink";
|
||||
import type { SessionStatsSnapshot } from "../../agent/stats";
|
||||
|
||||
interface SessionStatsProps {
|
||||
stats: SessionStatsSnapshot;
|
||||
}
|
||||
|
||||
function formatDuration(ms: number): string {
|
||||
if (ms < 1000) {
|
||||
return `${Math.round(ms)}ms`;
|
||||
}
|
||||
return `${(ms / 1000).toFixed(1)}s`;
|
||||
}
|
||||
|
||||
function formatNumber(n: number): string {
|
||||
return n.toLocaleString();
|
||||
}
|
||||
|
||||
export function SessionStats({ stats }: SessionStatsProps) {
|
||||
const wallDuration = formatDuration(stats.totalWallMs);
|
||||
const apiDuration = formatDuration(stats.totalApiMs);
|
||||
|
||||
return (
|
||||
<Box flexDirection="column" paddingTop={1}>
|
||||
<Text dimColor>Total duration (API): {apiDuration}</Text>
|
||||
<Text dimColor>Total duration (wall): {wallDuration}</Text>
|
||||
<Text dimColor>
|
||||
Usage: {stats.usage.stepCount} steps,{" "}
|
||||
{formatNumber(stats.usage.promptTokens)} input,{" "}
|
||||
{formatNumber(stats.usage.completionTokens)} output
|
||||
</Text>
|
||||
</Box>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user