@wheatley-ai/cli 0.1.1 → 0.3.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.
@@ -0,0 +1,89 @@
1
+ import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { Box, Text } from "ink";
3
+ import { bannerArt, pick, TIPS } from "../personality.js";
4
+ import { CHAT_COMMANDS, commandLabel } from "./commands.js";
5
+ import { formatCount, formatCost, formatSeconds } from "./format.js";
6
+ import { wrapLines } from "./markdown.js";
7
+ const OUTPUT_PREVIEW_LINES = 3;
8
+ /** The column of the reply logo. Reply text starts after it. */
9
+ export const LOGO_WIDTH = 2;
10
+ const Banner = ({ view, version, columns }) => (_jsxs(Box, { flexDirection: "column", marginBottom: 1, children: [_jsx(Box, { marginLeft: 2, marginTop: 1, children: _jsx(Text, { children: bannerArt(columns) }) }), _jsxs(Box, { borderColor: "cyan", borderStyle: "round", flexDirection: "column", marginTop: 1, paddingX: 1, children: [_jsxs(Text, { children: [_jsx(Text, { bold: true, color: "cyan", children: "wheatley" }), _jsxs(Text, { dimColor: true, children: [" v", version] }), _jsx(Text, { children: " \u00B7 agent " }), _jsx(Text, { bold: true, children: view.agent }), view.model === undefined ? undefined : (_jsxs(_Fragment, { children: [_jsx(Text, { children: " \u00B7 " }), _jsx(Text, { color: "magenta", children: view.model })] }))] }), view.extensions === undefined ? undefined : (_jsx(Text, { dimColor: true, children: view.extensions })), _jsx(Text, { dimColor: true, children: process.cwd() }), _jsxs(Text, { children: [_jsx(Text, { color: "yellow", children: "Tip " }), _jsx(Text, { dimColor: true, children: pick(TIPS) })] })] })] }));
11
+ const KEYS = [
12
+ ["Enter", "Send. With the menu open, run the selected command."],
13
+ ["\\ then Enter, Alt+Enter", "Add a new line."],
14
+ ["Tab", "Complete the selected command."],
15
+ ["Up, Down", "Move in the menu, or recall earlier input."],
16
+ ["!command", "Run a shell command here. Nothing goes to the Agent."],
17
+ ["Esc", "Close the menu, interrupt the Run, or clear the line (twice)."],
18
+ ["Ctrl+C", "Clear the line, stop the Run, or exit (twice)."],
19
+ [
20
+ "Ctrl+W, Ctrl+U, Ctrl+K",
21
+ "Delete a word, to the line start, or to the line end.",
22
+ ],
23
+ ["Ctrl+D", "Exit on an empty line."],
24
+ ];
25
+ const Help = () => {
26
+ const commandWidth = Math.max(...CHAT_COMMANDS.map((command) => commandLabel(command).length));
27
+ const keyWidth = Math.max(...KEYS.map(([key]) => key.length));
28
+ return (_jsxs(Box, { flexDirection: "column", marginLeft: 2, children: [_jsx(Text, { bold: true, children: "Commands" }), CHAT_COMMANDS.map((command) => (_jsxs(Text, { children: [_jsx(Text, { color: "cyan", children: commandLabel(command).padEnd(commandWidth) }), _jsxs(Text, { dimColor: true, children: [" ", command.description] })] }, command.word))), _jsx(Text, { children: " " }), _jsx(Text, { bold: true, children: "Keys" }), KEYS.map(([key, action]) => (_jsxs(Text, { children: [_jsx(Text, { color: "cyan", children: key.padEnd(keyWidth) }), _jsxs(Text, { dimColor: true, children: [" ", action] })] }, key)))] }));
29
+ };
30
+ const previewLines = (text) => {
31
+ const lines = text.split("\n");
32
+ return lines.length > OUTPUT_PREVIEW_LINES
33
+ ? [
34
+ ...lines.slice(0, OUTPUT_PREVIEW_LINES),
35
+ `… ${lines.length - OUTPUT_PREVIEW_LINES} more lines`,
36
+ ].join("\n")
37
+ : text;
38
+ };
39
+ const TurnLine = ({ entry, }) => {
40
+ const parts = [
41
+ formatSeconds(entry.seconds),
42
+ entry.tools === 1 ? "1 tool" : `${entry.tools} tools`,
43
+ ];
44
+ if (entry.usage !== undefined) {
45
+ parts.push(`↑${formatCount(entry.usage.inputTokens)} ↓${formatCount(entry.usage.outputTokens)} tokens`);
46
+ if (entry.usage.costUsd !== undefined) {
47
+ parts.push(formatCost(entry.usage.costUsd));
48
+ }
49
+ }
50
+ return (_jsx(Box, { marginBottom: 1, children: _jsx(Text, { dimColor: true, children: `─ ${parts.join(" · ")}` }) }));
51
+ };
52
+ const NOTICE_COLORS = {
53
+ dim: "gray",
54
+ error: "red",
55
+ warning: "yellow",
56
+ };
57
+ /** One transcript entry. Ink prints it once, above the live area. */
58
+ export const EntryView = ({ entry, view, version, columns, }) => {
59
+ switch (entry.kind) {
60
+ case "banner": {
61
+ return _jsx(Banner, { columns: columns, version: version, view: view });
62
+ }
63
+ case "user": {
64
+ return (_jsxs(Box, { marginTop: 1, children: [_jsx(Box, { width: 2, children: _jsx(Text, { bold: true, color: "cyan", children: "\u203A" }) }), _jsx(Text, { bold: true, children: entry.text })] }));
65
+ }
66
+ case "reply": {
67
+ return (_jsxs(Box, { marginTop: entry.first ? 1 : 0, children: [_jsx(Box, { flexShrink: 0, width: LOGO_WIDTH, children: _jsx(Text, { color: "cyan", children: entry.first ? "◉" : " " }) }), _jsx(Text, { children: wrapLines(entry.lines, columns - LOGO_WIDTH) })] }));
68
+ }
69
+ case "tool": {
70
+ return (_jsxs(Box, { flexDirection: "column", marginLeft: 2, children: [_jsxs(Box, { children: [_jsx(Text, { color: entry.ok ? "green" : "red", children: entry.ok ? "✓ " : "✗ " }), _jsx(Text, { bold: true, children: entry.name }), _jsx(Box, { flexShrink: 1, marginLeft: 1, children: _jsx(Text, { dimColor: true, wrap: "truncate-end", children: entry.input }) }), _jsxs(Text, { dimColor: true, children: [" ", formatSeconds(entry.seconds)] })] }), entry.ok || entry.output === "" ? undefined : (_jsx(Box, { marginLeft: 2, children: _jsx(Text, { color: "red", dimColor: true, children: previewLines(entry.output) }) }))] }));
71
+ }
72
+ case "turn": {
73
+ return _jsx(TurnLine, { entry: entry });
74
+ }
75
+ case "notice": {
76
+ return (_jsx(Box, { marginLeft: 2, children: _jsx(Text, { color: NOTICE_COLORS[entry.tone], children: entry.text }) }));
77
+ }
78
+ case "help": {
79
+ return _jsx(Help, {});
80
+ }
81
+ case "shell": {
82
+ return (_jsx(Box, { marginLeft: 2, children: _jsx(Text, { dimColor: true, children: entry.text }) }));
83
+ }
84
+ default: {
85
+ const unknown = entry;
86
+ throw new Error(`Unknown transcript entry: ${JSON.stringify(unknown)}`);
87
+ }
88
+ }
89
+ };