kernelbot 1.0.36 → 1.0.37

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kernelbot",
3
- "version": "1.0.36",
3
+ "version": "1.0.37",
4
4
  "description": "KernelBot — AI engineering agent with full OS control",
5
5
  "type": "module",
6
6
  "author": "Abdullah Al-Taheri <abdullah@altaheri.me>",
@@ -1,9 +1,50 @@
1
+ import { existsSync, readFileSync, writeFileSync, mkdirSync } from 'fs';
2
+ import { join } from 'path';
3
+ import { homedir } from 'os';
4
+ import { getLogger } from '../utils/logger.js';
5
+
1
6
  export function isAllowedUser(userId, config) {
2
7
  const allowed = config.telegram.allowed_users;
3
- if (!allowed || allowed.length === 0) return false;
8
+
9
+ // Auto-register the first user as owner when no allowed users exist
10
+ if (!allowed || allowed.length === 0) {
11
+ config.telegram.allowed_users = [userId];
12
+ _persistOwner(userId);
13
+ const logger = getLogger();
14
+ logger.info(`[Auth] Auto-registered first user ${userId} as owner`);
15
+ return true;
16
+ }
17
+
4
18
  return allowed.includes(userId);
5
19
  }
6
20
 
21
+ /**
22
+ * Persist the auto-registered owner ID to ~/.kernelbot/.env
23
+ */
24
+ function _persistOwner(userId) {
25
+ try {
26
+ const configDir = join(homedir(), '.kernelbot');
27
+ mkdirSync(configDir, { recursive: true });
28
+ const envPath = join(configDir, '.env');
29
+
30
+ let content = '';
31
+ if (existsSync(envPath)) {
32
+ content = readFileSync(envPath, 'utf-8').trimEnd() + '\n';
33
+ }
34
+
35
+ const regex = /^OWNER_TELEGRAM_ID=.*$/m;
36
+ const line = `OWNER_TELEGRAM_ID=${userId}`;
37
+ if (regex.test(content)) {
38
+ content = content.replace(regex, line);
39
+ } else {
40
+ content += line + '\n';
41
+ }
42
+ writeFileSync(envPath, content);
43
+ } catch {
44
+ // Non-fatal — owner is still in memory for this session
45
+ }
46
+ }
47
+
7
48
  export function getUnauthorizedMessage() {
8
49
  return 'Access denied. You are not authorized to use this bot.';
9
50
  }