bravecode-cli 0.1.3 → 0.1.5
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/bravecode +22 -0
- package/dist/cli.cjs +92 -42
- package/dist/cli.cjs.map +4 -4
- package/dist/cli.mjs +40705 -537
- package/dist/cli.mjs.map +4 -4
- package/dist/core/tui/ChatTUI.d.ts +1 -2
- package/dist/core/tui/ChatTUI.d.ts.map +1 -1
- package/dist/core/tui/ChatTUI.js +5 -4
- package/dist/core/tui/ChatTUI.js.map +1 -1
- package/dist/core/tui/index.d.ts.map +1 -1
- package/dist/core/tui/index.js +10 -6
- package/dist/core/tui/index.js.map +1 -1
- package/dist/tui/ChatTUI.mjs +89 -0
- package/dist/tui-launcher.mjs +64 -0
- package/package.json +2 -2
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import React from "react";
|
|
2
1
|
export interface ChatMessage {
|
|
3
2
|
id: string;
|
|
4
3
|
role: "user" | "assistant" | "tool";
|
|
@@ -12,6 +11,6 @@ interface ChatTUIProps {
|
|
|
12
11
|
onMessage: (message: string) => Promise<string>;
|
|
13
12
|
onExit: () => void;
|
|
14
13
|
}
|
|
15
|
-
export declare function ChatTUI({ agentName, modelName, onMessage, onExit }: ChatTUIProps):
|
|
14
|
+
export declare function ChatTUI({ agentName, modelName, onMessage, onExit }: ChatTUIProps): import("react").JSX.Element;
|
|
16
15
|
export {};
|
|
17
16
|
//# sourceMappingURL=ChatTUI.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ChatTUI.d.ts","sourceRoot":"","sources":["../../../src/core/tui/ChatTUI.tsx"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"ChatTUI.d.ts","sourceRoot":"","sources":["../../../src/core/tui/ChatTUI.tsx"],"names":[],"mappings":"AAAA,MAAM,WAAW,WAAW;IAC1B,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,GAAG,WAAW,GAAG,MAAM,CAAC;IACpC,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,IAAI,CAAC;CACjB;AAED,UAAU,YAAY;IACpB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC;IAChD,MAAM,EAAE,MAAM,IAAI,CAAC;CACpB;AAED,wBAAgB,OAAO,CAAC,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,EAAE,EAAE,YAAY,+BA6HhF"}
|
package/dist/core/tui/ChatTUI.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import React, { useState, useEffect, useCallback } from "react";
|
|
3
|
-
import { Box, Text, useInput, useApp } from "ink";
|
|
4
|
-
import TextInput from "ink-text-input";
|
|
5
2
|
export function ChatTUI({ agentName, modelName, onMessage, onExit }) {
|
|
3
|
+
const React = require("react");
|
|
4
|
+
const { useState, useEffect, useCallback } = React;
|
|
5
|
+
const { Box, Text, useInput, useApp } = require("ink");
|
|
6
|
+
const TextInput = require("ink-text-input").default;
|
|
6
7
|
const [messages, setMessages] = useState([]);
|
|
7
8
|
const [input, setInput] = useState("");
|
|
8
9
|
const [isLoading, setIsLoading] = useState(false);
|
|
@@ -59,6 +60,6 @@ export function ChatTUI({ agentName, modelName, onMessage, onExit }) {
|
|
|
59
60
|
});
|
|
60
61
|
}
|
|
61
62
|
});
|
|
62
|
-
return (_jsxs(Box, { flexDirection: "column", height: "100%", children: [_jsxs(Box, { borderStyle: "round", borderColor: "blue", padding: 1, flexDirection: "column", children: [_jsxs(Box, { marginBottom: 1, children: [_jsx(Text, { bold: true, color: "blue", children: "BraveCode AI" }), _jsx(Text, { color: "gray", children: " | " }), _jsx(Text, { color: "yellow", children: agentName }), _jsx(Text, { color: "gray", children: " | " }), _jsx(Text, { color: "cyan", children: modelName })] }), _jsxs(Box, { borderStyle: "single", borderColor: "gray", flexDirection: "column", padding: 1, flexGrow: 1, children: [messages.map((msg) => (_jsx(Box, { marginBottom: 1, children: msg.role === "user" ? (_jsxs(Text, { children: [_jsx(Text, { bold: true, color: "green", children: "You: " }), msg.content] })) : msg.role === "tool" ? (_jsxs(Text, { color: "yellow", children: [_jsx(Text, { bold: true, children: "[Tool] " }), msg.content] })) : (_jsxs(Text, { children: [_jsxs(Text, { bold: true, color: "blue", children: [msg.agent || "AI", ": "] }), msg.content] })) }, msg.id))), isLoading && (_jsx(Text, { color: "gray", italic: true, children: "Thinking..." }))] })] }), _jsx(Box, { marginTop: 1, children: _jsxs(Text, { color: "gray", children: ["[", activeTab.toUpperCase(), "] Tab: switch | Ctrl+C: exit"] }) }), _jsxs(Box, { marginTop: 1, children: [_jsx(Text, { color: "green", bold: true, children:
|
|
63
|
+
return (_jsxs(Box, { flexDirection: "column", height: "100%", children: [_jsxs(Box, { borderStyle: "round", borderColor: "blue", padding: 1, flexDirection: "column", children: [_jsxs(Box, { marginBottom: 1, children: [_jsx(Text, { bold: true, color: "blue", children: "BraveCode AI" }), _jsx(Text, { color: "gray", children: " | " }), _jsx(Text, { color: "yellow", children: agentName }), _jsx(Text, { color: "gray", children: " | " }), _jsx(Text, { color: "cyan", children: modelName })] }), _jsxs(Box, { borderStyle: "single", borderColor: "gray", flexDirection: "column", padding: 1, flexGrow: 1, children: [messages.map((msg) => (_jsx(Box, { marginBottom: 1, children: msg.role === "user" ? (_jsxs(Text, { children: [_jsx(Text, { bold: true, color: "green", children: "You: " }), msg.content] })) : msg.role === "tool" ? (_jsxs(Text, { color: "yellow", children: [_jsx(Text, { bold: true, children: "[Tool] " }), msg.content] })) : (_jsxs(Text, { children: [_jsxs(Text, { bold: true, color: "blue", children: [msg.agent || "AI", ": "] }), msg.content] })) }, msg.id))), isLoading && (_jsx(Text, { color: "gray", italic: true, children: "Thinking..." }))] })] }), _jsx(Box, { marginTop: 1, children: _jsxs(Text, { color: "gray", children: ["[", activeTab.toUpperCase(), "] Tab: switch | Ctrl+C: exit"] }) }), _jsxs(Box, { marginTop: 1, children: [_jsx(Text, { color: "green", bold: true, children: '> ' }), _jsx(TextInput, { value: input, onChange: setInput, onSubmit: handleSubmit, placeholder: "Type a message..." })] })] }));
|
|
63
64
|
}
|
|
64
65
|
//# sourceMappingURL=ChatTUI.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ChatTUI.js","sourceRoot":"","sources":["../../../src/core/tui/ChatTUI.tsx"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"ChatTUI.js","sourceRoot":"","sources":["../../../src/core/tui/ChatTUI.tsx"],"names":[],"mappings":";AAeA,MAAM,UAAU,OAAO,CAAC,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,EAAgB;IAC/E,MAAM,KAAK,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IAC/B,MAAM,EAAE,QAAQ,EAAE,SAAS,EAAE,WAAW,EAAE,GAAG,KAAK,CAAC;IACnD,MAAM,EAAE,GAAG,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC;IACvD,MAAM,SAAS,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAAC,OAAO,CAAC;IAEpD,MAAM,CAAC,QAAQ,EAAE,WAAW,CAAC,GAAG,QAAQ,CAAgB,EAAE,CAAC,CAAC;IAC5D,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,QAAQ,CAAC,EAAE,CAAC,CAAC;IACvC,MAAM,CAAC,SAAS,EAAE,YAAY,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC;IAClD,MAAM,CAAC,SAAS,EAAE,YAAY,CAAC,GAAG,QAAQ,CAA8B,MAAM,CAAC,CAAC;IAEh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AC/B,IACE,IACF,CACP,CAAC;AACJ,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/core/tui/index.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/core/tui/index.tsx"],"names":[],"mappings":"AAIA,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,MAAM,GAAG,WAAW,GAAG,MAAM,CAAC;IACpC,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,qBAAa,WAAW;IACtB,OAAO,CAAC,QAAQ,CAAqB;IACrC,OAAO,CAAC,KAAK,CAAe;IAC5B,OAAO,CAAC,KAAK,CAAQ;IACrB,OAAO,CAAC,SAAS,CAAS;IAC1B,OAAO,CAAC,SAAS,CAAS;gBAEd,KAAK,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM;IActC,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CA6B7B"}
|
package/dist/core/tui/index.js
CHANGED
|
@@ -1,7 +1,3 @@
|
|
|
1
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import React from "react";
|
|
3
|
-
import { render } from "ink";
|
|
4
|
-
import { ChatTUI } from "./ChatTUI";
|
|
5
1
|
import { LLMProviderManager } from "../../provider";
|
|
6
2
|
import { ToolRegistry } from "../tool";
|
|
7
3
|
import { Agent, defaultAgents } from "../agent";
|
|
@@ -23,6 +19,9 @@ export class TUILauncher {
|
|
|
23
19
|
});
|
|
24
20
|
}
|
|
25
21
|
async start() {
|
|
22
|
+
const React = await import("react");
|
|
23
|
+
const { render } = await import("ink");
|
|
24
|
+
const { ChatTUI } = await import("./ChatTUI");
|
|
26
25
|
const onMessage = async (message) => {
|
|
27
26
|
let response = "";
|
|
28
27
|
await this.agent.run(message, (chunk) => {
|
|
@@ -31,10 +30,15 @@ export class TUILauncher {
|
|
|
31
30
|
return response;
|
|
32
31
|
};
|
|
33
32
|
const onExit = () => {
|
|
34
|
-
console.log("\nGoodbye!
|
|
33
|
+
console.log("\nGoodbye!");
|
|
35
34
|
process.exit(0);
|
|
36
35
|
};
|
|
37
|
-
const { waitUntilExit } = render(
|
|
36
|
+
const { waitUntilExit } = render(React.createElement(ChatTUI, {
|
|
37
|
+
agentName: this.agentName,
|
|
38
|
+
modelName: this.modelName,
|
|
39
|
+
onMessage: onMessage,
|
|
40
|
+
onExit: onExit,
|
|
41
|
+
}));
|
|
38
42
|
await waitUntilExit();
|
|
39
43
|
}
|
|
40
44
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/core/tui/index.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/core/tui/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AACpD,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,KAAK,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAQhD,MAAM,OAAO,WAAW;IACd,QAAQ,CAAqB;IAC7B,KAAK,CAAe;IACpB,KAAK,CAAQ;IACb,SAAS,CAAS;IAClB,SAAS,CAAS;IAE1B,YAAY,KAAc,EAAE,OAAgB;QAC1C,IAAI,CAAC,QAAQ,GAAG,IAAI,kBAAkB,EAAE,CAAC;QACzC,IAAI,CAAC,KAAK,GAAG,IAAI,YAAY,EAAE,CAAC;QAEhC,MAAM,WAAW,GAAG,aAAa,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,OAAO,IAAI,OAAO,CAAC,CAAC,IAAI,aAAa,CAAC,CAAC,CAAC,CAAC;QACjG,IAAI,CAAC,SAAS,GAAG,WAAW,CAAC,IAAI,CAAC;QAClC,IA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-runtime";
|
|
2
|
+
import React, { useState, useCallback } from "react";
|
|
3
|
+
import { Box, Text, useInput, useApp } from "ink";
|
|
4
|
+
import TextInput from "ink-text-input";
|
|
5
|
+
function ChatTUI({ agentName, modelName, onMessage, onExit }) {
|
|
6
|
+
const [messages, setMessages] = useState([]);
|
|
7
|
+
const [input, setInput] = useState("");
|
|
8
|
+
const [isLoading, setIsLoading] = useState(false);
|
|
9
|
+
const { exit } = useApp();
|
|
10
|
+
const handleSubmit = useCallback(async (value) => {
|
|
11
|
+
if (!value.trim()) return;
|
|
12
|
+
const userMessage = {
|
|
13
|
+
id: Date.now().toString(),
|
|
14
|
+
role: "user",
|
|
15
|
+
content: value,
|
|
16
|
+
timestamp: /* @__PURE__ */ new Date()
|
|
17
|
+
};
|
|
18
|
+
setMessages((prev) => [...prev, userMessage]);
|
|
19
|
+
setInput("");
|
|
20
|
+
setIsLoading(true);
|
|
21
|
+
try {
|
|
22
|
+
const response = await onMessage(value);
|
|
23
|
+
const assistantMessage = {
|
|
24
|
+
id: (Date.now() + 1).toString(),
|
|
25
|
+
role: "assistant",
|
|
26
|
+
content: response,
|
|
27
|
+
agent: agentName,
|
|
28
|
+
timestamp: /* @__PURE__ */ new Date()
|
|
29
|
+
};
|
|
30
|
+
setMessages((prev) => [...prev, assistantMessage]);
|
|
31
|
+
} catch (error) {
|
|
32
|
+
const errorMessage = {
|
|
33
|
+
id: (Date.now() + 1).toString(),
|
|
34
|
+
role: "assistant",
|
|
35
|
+
content: `Error: ${error.message}`,
|
|
36
|
+
timestamp: /* @__PURE__ */ new Date()
|
|
37
|
+
};
|
|
38
|
+
setMessages((prev) => [...prev, errorMessage]);
|
|
39
|
+
} finally {
|
|
40
|
+
setIsLoading(false);
|
|
41
|
+
}
|
|
42
|
+
}, [onMessage, agentName]);
|
|
43
|
+
useInput((inputChar, key) => {
|
|
44
|
+
if (key.ctrl && inputChar === "c") {
|
|
45
|
+
onExit();
|
|
46
|
+
exit();
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
return /* @__PURE__ */ jsxs(Box, { flexDirection: "column", height: "100%", children: [
|
|
50
|
+
/* @__PURE__ */ jsxs(Box, { borderStyle: "round", borderColor: "blue", padding: 1, flexDirection: "column", children: [
|
|
51
|
+
/* @__PURE__ */ jsxs(Box, { marginBottom: 1, children: [
|
|
52
|
+
/* @__PURE__ */ jsx(Text, { bold: true, color: "blue", children: "BraveCode AI" }),
|
|
53
|
+
/* @__PURE__ */ jsx(Text, { color: "gray", children: " | " }),
|
|
54
|
+
/* @__PURE__ */ jsx(Text, { color: "yellow", children: agentName }),
|
|
55
|
+
/* @__PURE__ */ jsx(Text, { color: "gray", children: " | " }),
|
|
56
|
+
/* @__PURE__ */ jsx(Text, { color: "cyan", children: modelName })
|
|
57
|
+
] }),
|
|
58
|
+
/* @__PURE__ */ jsxs(Box, { borderStyle: "single", borderColor: "gray", flexDirection: "column", padding: 1, flexGrow: 1, children: [
|
|
59
|
+
messages.map((msg) => /* @__PURE__ */ jsx(Box, { marginBottom: 1, children: msg.role === "user" ? /* @__PURE__ */ jsxs(Text, { children: [
|
|
60
|
+
/* @__PURE__ */ jsx(Text, { bold: true, color: "green", children: "You: " }),
|
|
61
|
+
msg.content
|
|
62
|
+
] }) : /* @__PURE__ */ jsxs(Text, { children: [
|
|
63
|
+
/* @__PURE__ */ jsxs(Text, { bold: true, color: "blue", children: [
|
|
64
|
+
msg.agent || "AI",
|
|
65
|
+
": "
|
|
66
|
+
] }),
|
|
67
|
+
msg.content
|
|
68
|
+
] }) }, msg.id)),
|
|
69
|
+
isLoading && /* @__PURE__ */ jsx(Text, { color: "gray", italic: true, children: "Thinking..." })
|
|
70
|
+
] })
|
|
71
|
+
] }),
|
|
72
|
+
/* @__PURE__ */ jsx(Box, { marginTop: 1, children: /* @__PURE__ */ jsx(Text, { color: "gray", children: "Ctrl+C: exit" }) }),
|
|
73
|
+
/* @__PURE__ */ jsxs(Box, { marginTop: 1, children: [
|
|
74
|
+
/* @__PURE__ */ jsx(Text, { color: "green", bold: true, children: "> " }),
|
|
75
|
+
/* @__PURE__ */ jsx(
|
|
76
|
+
TextInput,
|
|
77
|
+
{
|
|
78
|
+
value: input,
|
|
79
|
+
onChange: setInput,
|
|
80
|
+
onSubmit: handleSubmit,
|
|
81
|
+
placeholder: "Type a message..."
|
|
82
|
+
}
|
|
83
|
+
)
|
|
84
|
+
] })
|
|
85
|
+
] });
|
|
86
|
+
}
|
|
87
|
+
export {
|
|
88
|
+
ChatTUI
|
|
89
|
+
};
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { render } from "ink";
|
|
3
|
+
import React from "react";
|
|
4
|
+
import { ChatTUI } from "./ChatTUI";
|
|
5
|
+
import { LLMProviderManager } from "../../provider";
|
|
6
|
+
import { ToolRegistry } from "../tool";
|
|
7
|
+
import { Agent, defaultAgents } from "../agent";
|
|
8
|
+
class TUILauncher {
|
|
9
|
+
provider;
|
|
10
|
+
tools;
|
|
11
|
+
agent;
|
|
12
|
+
agentName;
|
|
13
|
+
modelName;
|
|
14
|
+
constructor(model, agentId) {
|
|
15
|
+
this.provider = new LLMProviderManager();
|
|
16
|
+
this.tools = new ToolRegistry();
|
|
17
|
+
const agentConfig = defaultAgents.find((a) => a.id === (agentId || "build")) || defaultAgents[0];
|
|
18
|
+
this.agentName = agentConfig.name;
|
|
19
|
+
this.modelName = model || agentConfig.model;
|
|
20
|
+
this.agent = new Agent(this.provider, this.tools, {
|
|
21
|
+
...agentConfig,
|
|
22
|
+
model: this.modelName
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
async start() {
|
|
26
|
+
const onMessage = async (message) => {
|
|
27
|
+
let response = "";
|
|
28
|
+
await this.agent.run(message, (chunk) => {
|
|
29
|
+
response += chunk;
|
|
30
|
+
});
|
|
31
|
+
return response;
|
|
32
|
+
};
|
|
33
|
+
const onExit = () => {
|
|
34
|
+
console.log("\nGoodbye!");
|
|
35
|
+
process.exit(0);
|
|
36
|
+
};
|
|
37
|
+
const { waitUntilExit } = render(
|
|
38
|
+
React.createElement(ChatTUI, {
|
|
39
|
+
agentName: this.agentName,
|
|
40
|
+
modelName: this.modelName,
|
|
41
|
+
onMessage,
|
|
42
|
+
onExit
|
|
43
|
+
})
|
|
44
|
+
);
|
|
45
|
+
await waitUntilExit();
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
const BANNER = `
|
|
49
|
+
\u2588\u2588\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2557\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2557\u2588\u2588\u2557 \u2588\u2588\u2557\u2588\u2588\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2557\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2557\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2557
|
|
50
|
+
\u2588\u2588\u2554\u2550\u2550\u2550\u2550\u255D\u2588\u2588\u2554\u2550\u2550\u2550\u2588\u2588\u2557\u2588\u2588\u2554\u2550\u2550\u2588\u2588\u2557\u2588\u2588\u2554\u2550\u2550\u2550\u2550\u255D\u2588\u2588\u2554\u2550\u2550\u2550\u2550\u255D\u2588\u2588\u2551 \u2588\u2588\u2551\u2588\u2588\u2554\u2550\u2550\u2588\u2588\u2557\u2588\u2588\u2554\u2550\u2550\u2588\u2588\u2557\u2588\u2588\u2554\u2550\u2550\u2588\u2588\u2557\u2588\u2588\u2551\u2588\u2588\u2554\u2550\u2550\u2550\u2550\u255D\u2588\u2588\u2554\u2550\u2550\u2550\u2550\u255D
|
|
51
|
+
\u2588\u2588\u2551 \u2588\u2588\u2551 \u2588\u2588\u2551\u2588\u2588\u2588\u2588\u2588\u2588\u2554\u255D\u2588\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2557\u2588\u2588\u2551 \u2588\u2588\u2551\u2588\u2588\u2588\u2588\u2588\u2588\u2554\u255D\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2551\u2588\u2588\u2588\u2588\u2588\u2588\u2554\u255D\u2588\u2588\u2551\u2588\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2557
|
|
52
|
+
\u2588\u2588\u2551 \u2588\u2588\u2551 \u2588\u2588\u2551\u2588\u2588\u2554\u2550\u2550\u2550\u255D \u2588\u2588\u2554\u2550\u2550\u255D \u255A\u2550\u2550\u2550\u2550\u2588\u2588\u2551\u2588\u2588\u2551 \u2588\u2588\u2551\u2588\u2588\u2554\u2550\u2550\u2588\u2588\u2557\u2588\u2588\u2554\u2550\u2550\u2588\u2588\u2551\u2588\u2588\u2554\u2550\u2550\u2588\u2588\u2557\u2588\u2588\u2551\u2588\u2588\u2554\u2550\u2550\u255D \u255A\u2550\u2550\u2550\u2550\u2588\u2588\u2551
|
|
53
|
+
\u255A\u2588\u2588\u2588\u2588\u2588\u2588\u2557\u255A\u2588\u2588\u2588\u2588\u2588\u2588\u2554\u255D\u2588\u2588\u2551 \u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2557\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2551\u255A\u2588\u2588\u2588\u2588\u2588\u2588\u2554\u255D\u2588\u2588\u2551 \u2588\u2588\u2551\u2588\u2588\u2551 \u2588\u2588\u2551\u2588\u2588\u2551 \u2588\u2588\u2551\u2588\u2588\u2551\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2557\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2551
|
|
54
|
+
\u255A\u2550\u2550\u2550\u2550\u2550\u255D \u255A\u2550\u2550\u2550\u2550\u2550\u255D \u255A\u2550\u255D \u255A\u2550\u2550\u2550\u2550\u2550\u2550\u255D\u255A\u2550\u2550\u2550\u2550\u2550\u2550\u255D \u255A\u2550\u2550\u2550\u2550\u2550\u255D \u255A\u2550\u255D \u255A\u2550\u255D\u255A\u2550\u255D \u255A\u2550\u255D\u255A\u2550\u255D \u255A\u2550\u255D\u255A\u2550\u255D\u255A\u2550\u2550\u2550\u2550\u2550\u2550\u255D\u255A\u2550\u2550\u2550\u2550\u2550\u2550\u255D
|
|
55
|
+
`;
|
|
56
|
+
async function main() {
|
|
57
|
+
console.log(BANNER);
|
|
58
|
+
const launcher = new TUILauncher();
|
|
59
|
+
await launcher.start();
|
|
60
|
+
}
|
|
61
|
+
main().catch(console.error);
|
|
62
|
+
export {
|
|
63
|
+
TUILauncher
|
|
64
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bravecode-cli",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.5",
|
|
4
4
|
"description": "Agentic AI vibe coding CLI with free model support",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"LICENSE"
|
|
15
15
|
],
|
|
16
16
|
"scripts": {
|
|
17
|
-
"build": "
|
|
17
|
+
"build": "node scripts/build.js",
|
|
18
18
|
"dev": "tsx watch src/cli.ts",
|
|
19
19
|
"lint": "eslint src/ --ext .ts",
|
|
20
20
|
"typecheck": "tsc --noEmit",
|