kernelbot 1.0.11 โ†’ 1.0.13

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/bin/kernel.js CHANGED
@@ -133,7 +133,7 @@ async function startBotFlow(config) {
133
133
  const conversationManager = new ConversationManager(config);
134
134
  const agent = new Agent({ config, conversationManager });
135
135
 
136
- startBot(config, agent);
136
+ startBot(config, agent, conversationManager);
137
137
  showStartupComplete();
138
138
  return true;
139
139
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kernelbot",
3
- "version": "1.0.11",
3
+ "version": "1.0.13",
4
4
  "description": "KernelBot โ€” AI engineering agent with full OS control",
5
5
  "type": "module",
6
6
  "author": "Abdullah Al-Taheri <abdullah@altaheri.me>",
package/src/agent.js CHANGED
@@ -99,6 +99,7 @@ export class Agent {
99
99
  const result = await executeTool(pending.block.name, pending.block.input, {
100
100
  config: this.config,
101
101
  user,
102
+ onUpdate: this._onUpdate,
102
103
  });
103
104
 
104
105
  pending.toolResults.push({
@@ -116,7 +117,7 @@ export class Agent {
116
117
 
117
118
  if (lower === 'yes' || lower === 'y' || lower === 'confirm') {
118
119
  logger.info(`User confirmed dangerous tool: ${pending.block.name}`);
119
- const result = await executeTool(pending.block.name, pending.block.input, pending.context);
120
+ const result = await executeTool(pending.block.name, pending.block.input, { ...pending.context, onUpdate: this._onUpdate });
120
121
 
121
122
  pending.toolResults.push({
122
123
  type: 'tool_result',
@@ -143,7 +144,7 @@ export class Agent {
143
144
  const pauseMsg = await this._checkPause(chatId, block, user, pending.toolResults, pending.remainingBlocks.filter((b) => b !== block), pending.messages);
144
145
  if (pauseMsg) return pauseMsg;
145
146
 
146
- const r = await executeTool(block.name, block.input, { config: this.config, user });
147
+ const r = await executeTool(block.name, block.input, { config: this.config, user, onUpdate: this._onUpdate });
147
148
  pending.toolResults.push({
148
149
  type: 'tool_result',
149
150
  tool_use_id: block.id,
@@ -254,6 +255,7 @@ export class Agent {
254
255
  const result = await executeTool(block.name, block.input, {
255
256
  config: this.config,
256
257
  user,
258
+ onUpdate: this._onUpdate,
257
259
  });
258
260
 
259
261
  toolResults.push({
package/src/bot.js CHANGED
@@ -21,10 +21,16 @@ function splitMessage(text, maxLength = 4096) {
21
21
  return chunks;
22
22
  }
23
23
 
24
- export function startBot(config, agent) {
24
+ export function startBot(config, agent, conversationManager) {
25
25
  const logger = getLogger();
26
26
  const bot = new TelegramBot(config.telegram.bot_token, { polling: true });
27
27
 
28
+ // Load previous conversations from disk
29
+ const loaded = conversationManager.load();
30
+ if (loaded) {
31
+ logger.info('Loaded previous conversations from disk');
32
+ }
33
+
28
34
  logger.info('Telegram bot started with polling');
29
35
 
30
36
  bot.on('message', async (msg) => {
@@ -41,7 +47,36 @@ export function startBot(config, agent) {
41
47
  return;
42
48
  }
43
49
 
44
- logger.info(`Message from ${username} (${userId}): ${msg.text.slice(0, 100)}`);
50
+ const text = msg.text.trim();
51
+
52
+ // Handle commands
53
+ if (text === '/clean' || text === '/clear' || text === '/reset') {
54
+ conversationManager.clear(chatId);
55
+ logger.info(`Conversation cleared for chat ${chatId} by ${username}`);
56
+ await bot.sendMessage(chatId, '๐Ÿงน Conversation cleared. Starting fresh.');
57
+ return;
58
+ }
59
+
60
+ if (text === '/history') {
61
+ const count = conversationManager.getMessageCount(chatId);
62
+ await bot.sendMessage(chatId, `๐Ÿ“ This chat has *${count}* messages in memory.`, { parse_mode: 'Markdown' });
63
+ return;
64
+ }
65
+
66
+ if (text === '/help') {
67
+ await bot.sendMessage(chatId, [
68
+ '*KernelBot Commands*',
69
+ '',
70
+ '/clean โ€” Clear conversation and start fresh',
71
+ '/history โ€” Show message count in memory',
72
+ '/help โ€” Show this help message',
73
+ '',
74
+ 'Or just send any message to chat with the agent.',
75
+ ].join('\n'), { parse_mode: 'Markdown' });
76
+ return;
77
+ }
78
+
79
+ logger.info(`Message from ${username} (${userId}): ${text.slice(0, 100)}`);
45
80
 
46
81
  // Show typing and keep refreshing it
47
82
  const typingInterval = setInterval(() => {
@@ -50,8 +85,8 @@ export function startBot(config, agent) {
50
85
  bot.sendChatAction(chatId, 'typing').catch(() => {});
51
86
 
52
87
  try {
53
- const onUpdate = async (text) => {
54
- const parts = splitMessage(text);
88
+ const onUpdate = async (update) => {
89
+ const parts = splitMessage(update);
55
90
  for (const part of parts) {
56
91
  try {
57
92
  await bot.sendMessage(chatId, part, { parse_mode: 'Markdown' });
@@ -61,7 +96,7 @@ export function startBot(config, agent) {
61
96
  }
62
97
  };
63
98
 
64
- const reply = await agent.processMessage(chatId, msg.text, {
99
+ const reply = await agent.processMessage(chatId, text, {
65
100
  id: userId,
66
101
  username,
67
102
  }, onUpdate);
package/src/coder.js CHANGED
@@ -7,7 +7,7 @@ export class ClaudeCodeSpawner {
7
7
  this.timeout = (config.claude_code?.timeout_seconds || 600) * 1000;
8
8
  }
9
9
 
10
- async run({ workingDirectory, prompt, maxTurns }) {
10
+ async run({ workingDirectory, prompt, maxTurns, onOutput }) {
11
11
  const logger = getLogger();
12
12
  const turns = maxTurns || this.maxTurns;
13
13
 
@@ -24,9 +24,24 @@ export class ClaudeCodeSpawner {
24
24
 
25
25
  let stdout = '';
26
26
  let stderr = '';
27
+ let buffer = '';
27
28
 
28
29
  child.stdout.on('data', (data) => {
29
- stdout += data.toString();
30
+ const chunk = data.toString();
31
+ stdout += chunk;
32
+ buffer += chunk;
33
+
34
+ // Stream output in meaningful chunks (split on newlines)
35
+ const lines = buffer.split('\n');
36
+ buffer = lines.pop(); // keep incomplete line in buffer
37
+
38
+ if (lines.length > 0 && onOutput) {
39
+ const text = lines.join('\n').trim();
40
+ if (text) {
41
+ logger.info(`Claude Code output: ${text.slice(0, 200)}`);
42
+ onOutput(text).catch(() => {});
43
+ }
44
+ }
30
45
  });
31
46
 
32
47
  child.stderr.on('data', (data) => {
@@ -40,6 +55,12 @@ export class ClaudeCodeSpawner {
40
55
 
41
56
  child.on('close', (code) => {
42
57
  clearTimeout(timer);
58
+
59
+ // Flush remaining buffer
60
+ if (buffer.trim() && onOutput) {
61
+ onOutput(buffer.trim()).catch(() => {});
62
+ }
63
+
43
64
  if (code !== 0 && !stdout) {
44
65
  reject(new Error(`Claude Code exited with code ${code}: ${stderr}`));
45
66
  } else {
@@ -1,14 +1,52 @@
1
+ import { readFileSync, writeFileSync, existsSync, mkdirSync } from 'fs';
2
+ import { join } from 'path';
3
+ import { homedir } from 'os';
4
+
5
+ function getConversationsPath() {
6
+ const dir = join(homedir(), '.kernelbot');
7
+ mkdirSync(dir, { recursive: true });
8
+ return join(dir, 'conversations.json');
9
+ }
10
+
1
11
  export class ConversationManager {
2
12
  constructor(config) {
3
13
  this.maxHistory = config.conversation.max_history;
4
14
  this.conversations = new Map();
15
+ this.filePath = getConversationsPath();
16
+ }
17
+
18
+ load() {
19
+ if (!existsSync(this.filePath)) return false;
20
+ try {
21
+ const raw = readFileSync(this.filePath, 'utf-8');
22
+ const data = JSON.parse(raw);
23
+ for (const [chatId, messages] of Object.entries(data)) {
24
+ this.conversations.set(String(chatId), messages);
25
+ }
26
+ return this.conversations.size > 0;
27
+ } catch {
28
+ return false;
29
+ }
30
+ }
31
+
32
+ save() {
33
+ try {
34
+ const data = {};
35
+ for (const [chatId, messages] of this.conversations) {
36
+ data[chatId] = messages;
37
+ }
38
+ writeFileSync(this.filePath, JSON.stringify(data, null, 2));
39
+ } catch {
40
+ // Silent fail โ€” don't crash the bot over persistence
41
+ }
5
42
  }
6
43
 
7
44
  getHistory(chatId) {
8
- if (!this.conversations.has(chatId)) {
9
- this.conversations.set(chatId, []);
45
+ const key = String(chatId);
46
+ if (!this.conversations.has(key)) {
47
+ this.conversations.set(key, []);
10
48
  }
11
- return this.conversations.get(chatId);
49
+ return this.conversations.get(key);
12
50
  }
13
51
 
14
52
  addMessage(chatId, role, content) {
@@ -24,13 +62,22 @@ export class ConversationManager {
24
62
  while (history.length > 0 && history[0].role !== 'user') {
25
63
  history.shift();
26
64
  }
65
+
66
+ this.save();
27
67
  }
28
68
 
29
69
  clear(chatId) {
30
- this.conversations.delete(chatId);
70
+ this.conversations.delete(String(chatId));
71
+ this.save();
31
72
  }
32
73
 
33
74
  clearAll() {
34
75
  this.conversations.clear();
76
+ this.save();
77
+ }
78
+
79
+ getMessageCount(chatId) {
80
+ const history = this.getHistory(chatId);
81
+ return history.length;
35
82
  }
36
83
  }
@@ -41,6 +41,9 @@ export const handlers = {
41
41
  workingDirectory: params.working_directory,
42
42
  prompt: params.prompt,
43
43
  maxTurns: params.max_turns,
44
+ onOutput: context.onUpdate
45
+ ? (text) => context.onUpdate(`๐Ÿ“Ÿ \`Claude Code:\`\n${text}`)
46
+ : null,
44
47
  });
45
48
  return { success: true, output: result.output };
46
49
  } catch (err) {
package/src/tools/git.js CHANGED
@@ -164,7 +164,8 @@ export const handlers = {
164
164
  }
165
165
 
166
166
  const branch = (await git.branchLocal()).current;
167
- const options = force ? ['--force'] : [];
167
+ const options = ['-u'];
168
+ if (force) options.push('--force');
168
169
  await git.push('origin', branch, options);
169
170
  return { success: true, branch };
170
171
  } catch (err) {