@cilow/cli 0.2.0 → 0.2.2

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.
Files changed (2) hide show
  1. package/dist/cli.js +63 -6
  2. package/package.json +1 -1
package/dist/cli.js CHANGED
@@ -39,13 +39,42 @@ async function makeRequest(config, method, path, body) {
39
39
  const text = await response.text();
40
40
  return text ? JSON.parse(text) : null;
41
41
  }
42
+ var CHAT_HISTORY_DIR = `${process.env.HOME || "~"}/.cilow`;
43
+ var CHAT_HISTORY_FILE = `${CHAT_HISTORY_DIR}/chat-history.json`;
44
+ var MAX_MESSAGES = 40;
45
+ async function loadChatHistory() {
46
+ try {
47
+ const fs = await import("fs");
48
+ if (fs.existsSync(CHAT_HISTORY_FILE)) {
49
+ const data = fs.readFileSync(CHAT_HISTORY_FILE, "utf-8");
50
+ const history = JSON.parse(data);
51
+ return history.slice(-MAX_MESSAGES);
52
+ }
53
+ } catch {
54
+ }
55
+ return [];
56
+ }
57
+ async function saveChatHistory(messages) {
58
+ try {
59
+ const fs = await import("fs");
60
+ if (!fs.existsSync(CHAT_HISTORY_DIR)) {
61
+ fs.mkdirSync(CHAT_HISTORY_DIR, { recursive: true });
62
+ }
63
+ const toSave = messages.slice(-MAX_MESSAGES);
64
+ fs.writeFileSync(CHAT_HISTORY_FILE, JSON.stringify(toSave, null, 2));
65
+ } catch {
66
+ }
67
+ }
42
68
  async function startChat(config, options) {
43
- const messages = [];
69
+ let messages = await loadChatHistory();
44
70
  const provider = options.provider || "anthropic";
45
71
  const model = options.model || "claude-3-5-haiku-20241022";
46
72
  console.log(chalk.bold.cyan("\n\u{1F9E0} Cilow AI Chat"));
47
- console.log(chalk.dim("Your AI assistant with persistent memory\n"));
48
- console.log(chalk.dim("Commands: /help, /memories, /clear, /exit\n"));
73
+ console.log(chalk.dim("Your AI assistant with persistent memory"));
74
+ if (messages.length > 0) {
75
+ console.log(chalk.dim(`Restored ${messages.length} messages from previous session`));
76
+ }
77
+ console.log(chalk.dim("\nCommands: /help, /memories, /clear, /new, /exit\n"));
49
78
  const rl = readline.createInterface({
50
79
  input: process.stdin,
51
80
  output: process.stdout
@@ -63,17 +92,22 @@ async function startChat(config, options) {
63
92
  return;
64
93
  }
65
94
  messages.push({ role: "user", content: trimmed });
95
+ if (messages.length > MAX_MESSAGES) {
96
+ messages = messages.slice(-MAX_MESSAGES);
97
+ }
66
98
  const spinner = ora({ text: "Thinking...", color: "cyan" }).start();
67
99
  try {
68
100
  const result = await makeRequest(config, "POST", "/api/v2/router", {
69
101
  provider,
70
102
  model,
71
- messages,
103
+ messages: messages.slice(-20),
104
+ // Send last 20 for context
72
105
  auto_context: true
73
106
  });
74
107
  spinner.stop();
75
108
  if (result.success && result.response) {
76
109
  messages.push({ role: "assistant", content: result.response });
110
+ await saveChatHistory(messages);
77
111
  console.log(chalk.cyan("\nCilow: ") + result.response);
78
112
  if (result.memories_used && result.memories_used > 0) {
79
113
  console.log(chalk.dim(` [${result.memories_used} memories used]`));
@@ -91,7 +125,8 @@ async function startChat(config, options) {
91
125
  prompt();
92
126
  });
93
127
  };
94
- rl.on("close", () => {
128
+ rl.on("close", async () => {
129
+ await saveChatHistory(messages);
95
130
  console.log(chalk.dim("\nGoodbye! Your memories are saved.\n"));
96
131
  process.exit(0);
97
132
  });
@@ -106,10 +141,32 @@ async function handleCommand(cmd, config, messages) {
106
141
  console.log(" /memories - Show relevant memories");
107
142
  console.log(" /add <text> - Add a memory");
108
143
  console.log(" /decide <decision> - Store a decision");
109
- console.log(" /clear - Clear conversation");
144
+ console.log(" /clear - Clear current conversation");
145
+ console.log(" /new - Start fresh conversation (clears history)");
146
+ console.log(" /history - Show conversation history");
110
147
  console.log(" /exit - Exit chat");
111
148
  console.log();
112
149
  break;
150
+ case "new":
151
+ messages.length = 0;
152
+ await saveChatHistory([]);
153
+ console.log(chalk.dim("Started fresh conversation. History cleared.\n"));
154
+ break;
155
+ case "history":
156
+ if (messages.length === 0) {
157
+ console.log(chalk.yellow("\nNo conversation history.\n"));
158
+ } else {
159
+ console.log(chalk.bold(`
160
+ Conversation (${messages.length} messages):
161
+ `));
162
+ for (const m of messages.slice(-10)) {
163
+ const prefix = m.role === "user" ? chalk.green("You: ") : chalk.cyan("Cilow: ");
164
+ const content2 = m.content.substring(0, 100) + (m.content.length > 100 ? "..." : "");
165
+ console.log(prefix + chalk.dim(content2));
166
+ }
167
+ console.log();
168
+ }
169
+ break;
113
170
  case "memories":
114
171
  const spinner = ora("Fetching memories...").start();
115
172
  try {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cilow/cli",
3
- "version": "0.2.0",
3
+ "version": "0.2.2",
4
4
  "description": "CLI for Cilow - AI Memory Infrastructure",
5
5
  "bin": {
6
6
  "cilow": "./dist/cli.js"