@lovenyberg/ove 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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lovenyberg/ove",
3
- "version": "0.2.0",
3
+ "version": "0.2.2",
4
4
  "description": "Your grumpy but meticulous dev companion. AI coding agent for Slack, WhatsApp, Telegram, Discord, GitHub, HTTP API, and CLI.",
5
5
  "type": "module",
6
6
  "bin": {
@@ -32,7 +32,7 @@
32
32
  },
33
33
  "dependencies": {
34
34
  "@slack/bolt": "^4.1.0",
35
- "baileys": "^6.7.0",
35
+ "baileys": "^7.0.0-rc.9",
36
36
  "discord.js": "^14.25.1",
37
37
  "grammy": "^1.40.0",
38
38
  "qrcode-terminal": "^0.12.0"
@@ -13,6 +13,24 @@ function debounce<T extends (...args: any[]) => any>(fn: T, ms: number): T {
13
13
  }) as any as T;
14
14
  }
15
15
 
16
+ /** Convert simple markdown (*bold*, `code`, ```blocks```) to Telegram HTML */
17
+ function mdToHtml(text: string): string {
18
+ // Escape HTML entities first
19
+ let html = text
20
+ .replace(/&/g, '&amp;')
21
+ .replace(/</g, '&lt;')
22
+ .replace(/>/g, '&gt;');
23
+
24
+ return html
25
+ // Code blocks first (```lang\n...\n```)
26
+ .replace(/```(\w*)\n([\s\S]*?)```/g, '<pre>$2</pre>')
27
+ // Inline code
28
+ .replace(/`([^`]+)`/g, '<code>$1</code>')
29
+ // Bold **text** or *text*
30
+ .replace(/\*\*(.+?)\*\*/g, '<b>$1</b>')
31
+ .replace(/\*(.+?)\*/g, '<b>$1</b>');
32
+ }
33
+
16
34
  export class TelegramAdapter implements ChatAdapter {
17
35
  private bot: Bot;
18
36
  private onMessage?: (msg: IncomingMessage) => void;
@@ -30,18 +48,21 @@ export class TelegramAdapter implements ChatAdapter {
30
48
  const userId = `telegram:${ctx.from.id}`;
31
49
  const text = ctx.message.text;
32
50
  let statusMsgId: number | undefined;
51
+ let lastStatusText: string | undefined;
33
52
 
34
53
  const doUpdate = debounce(async (statusText: string) => {
54
+ if (statusText === lastStatusText) return; // skip unchanged text
55
+ lastStatusText = statusText;
56
+ const html = mdToHtml(statusText);
35
57
  try {
36
58
  if (statusMsgId) {
37
- await ctx.api.editMessageText(chatId, statusMsgId, statusText);
59
+ await ctx.api.editMessageText(chatId, statusMsgId, html, { parse_mode: "HTML" });
38
60
  } else {
39
- const sent = await ctx.reply(statusText);
61
+ const sent = await ctx.reply(html, { parse_mode: "HTML" });
40
62
  statusMsgId = sent.message_id;
41
63
  }
42
64
  } catch {
43
- const sent = await ctx.reply(statusText);
44
- statusMsgId = sent.message_id;
65
+ // Edit may fail if content unchanged or message too old — ignore
45
66
  }
46
67
  }, 3000);
47
68
 
@@ -50,7 +71,18 @@ export class TelegramAdapter implements ChatAdapter {
50
71
  platform: "telegram",
51
72
  text,
52
73
  reply: async (replyText: string) => {
53
- await ctx.reply(replyText);
74
+ // Replace the status message with the first reply, then send new messages for the rest
75
+ if (statusMsgId) {
76
+ try {
77
+ await ctx.api.editMessageText(chatId, statusMsgId, mdToHtml(replyText), { parse_mode: "HTML" });
78
+ statusMsgId = undefined;
79
+ return;
80
+ } catch {
81
+ // Edit failed (message too old, etc.) — fall through to send new
82
+ }
83
+ statusMsgId = undefined;
84
+ }
85
+ await ctx.reply(mdToHtml(replyText), { parse_mode: "HTML" });
54
86
  },
55
87
  updateStatus: doUpdate,
56
88
  };
@@ -70,6 +102,6 @@ export class TelegramAdapter implements ChatAdapter {
70
102
 
71
103
  async sendToUser(userId: string, text: string): Promise<void> {
72
104
  const chatId = userId.replace("telegram:", "");
73
- await this.bot.api.sendMessage(Number(chatId), text);
105
+ await this.bot.api.sendMessage(Number(chatId), mdToHtml(text), { parse_mode: "HTML" });
74
106
  }
75
107
  }
@@ -11,9 +11,13 @@ export class WhatsAppAdapter implements ChatAdapter {
11
11
  private sock: WASocket | null = null;
12
12
  private onMessage?: (msg: IncomingMessage) => void;
13
13
  private authDir: string;
14
+ private phoneNumber?: string;
15
+ private reconnectAttempt = 0;
16
+ private sentByBot = new Set<string>();
14
17
 
15
- constructor(authDir: string = "./auth/whatsapp") {
16
- this.authDir = authDir;
18
+ constructor(opts: { authDir?: string; phoneNumber?: string } = {}) {
19
+ this.authDir = opts.authDir ?? "./auth/whatsapp";
20
+ this.phoneNumber = opts.phoneNumber;
17
21
  }
18
22
 
19
23
  async start(onMessage: (msg: IncomingMessage) => void): Promise<void> {
@@ -23,28 +27,56 @@ export class WhatsAppAdapter implements ChatAdapter {
23
27
 
24
28
  this.sock = makeWASocket({
25
29
  auth: state,
26
- printQRInTerminal: true,
27
30
  });
28
31
 
29
32
  this.sock.ev.on("creds.update", saveCreds);
30
33
 
31
- this.sock.ev.on("connection.update", ({ connection, lastDisconnect }) => {
34
+ let pairingRequested = false;
35
+
36
+ this.sock.ev.on("connection.update", async ({ connection, lastDisconnect, qr }) => {
37
+ // Request pairing code when server is ready (sends qr event)
38
+ if (qr && this.phoneNumber && !pairingRequested) {
39
+ pairingRequested = true;
40
+ try {
41
+ const phone = this.phoneNumber.replace(/[^0-9]/g, "");
42
+ const code = await this.sock!.requestPairingCode(phone);
43
+ logger.info(`whatsapp pairing code: ${code}`, { phone });
44
+ console.log(`\n WhatsApp pairing code: ${code}`);
45
+ console.log(` Enter this code on your phone: WhatsApp → Linked Devices → Link a Device\n`);
46
+ } catch (err) {
47
+ logger.error("failed to request pairing code", { error: String(err) });
48
+ }
49
+ }
50
+
32
51
  if (connection === "close") {
33
52
  const statusCode = (lastDisconnect?.error as any)?.output?.statusCode;
34
53
  if (statusCode !== DisconnectReason.loggedOut) {
35
- logger.warn("whatsapp disconnected, reconnecting...", { statusCode });
36
- this.start(onMessage);
54
+ this.reconnectAttempt++;
55
+ const delay = Math.min(2000 * this.reconnectAttempt, 30_000);
56
+ logger.warn("whatsapp disconnected, reconnecting...", { statusCode, delay });
57
+ setTimeout(() => this.start(onMessage), delay);
37
58
  } else {
38
59
  logger.error("whatsapp logged out");
39
60
  }
40
61
  } else if (connection === "open") {
62
+ this.reconnectAttempt = 0;
41
63
  logger.info("whatsapp adapter connected");
42
64
  }
43
65
  });
44
66
 
45
67
  this.sock.ev.on("messages.upsert", ({ messages }) => {
46
68
  for (const waMsg of messages) {
47
- if (!waMsg.message || waMsg.key.fromMe) continue;
69
+ if (!waMsg.message) continue;
70
+
71
+ // Skip messages sent by the bot (replies/status updates)
72
+ const msgId = waMsg.key.id;
73
+ if (msgId && this.sentByBot.has(msgId)) {
74
+ this.sentByBot.delete(msgId);
75
+ continue;
76
+ }
77
+
78
+ // Skip messages from others (not our phone) — we only process our own commands
79
+ if (!waMsg.key.fromMe) continue;
48
80
 
49
81
  const text =
50
82
  waMsg.message.conversation ||
@@ -54,7 +86,10 @@ export class WhatsAppAdapter implements ChatAdapter {
54
86
  const jid = waMsg.key.remoteJid;
55
87
  if (!jid) continue;
56
88
 
57
- const phone = jid.split("@")[0];
89
+ // For fromMe messages, use our configured phone number
90
+ const phone = waMsg.key.fromMe
91
+ ? (this.phoneNumber?.replace(/[^0-9]/g, "") ?? jid.split("@")[0])
92
+ : jid.split("@")[0];
58
93
  const userId = `whatsapp:${phone}`;
59
94
 
60
95
  // Batch status updates: at most once per 10 seconds
@@ -64,7 +99,8 @@ export class WhatsAppAdapter implements ChatAdapter {
64
99
 
65
100
  const flushStatus = async () => {
66
101
  if (pendingStatus && this.sock) {
67
- await this.sock.sendMessage(jid, { text: pendingStatus });
102
+ const sent = await this.sock.sendMessage(jid, { text: pendingStatus });
103
+ if (sent?.key?.id) this.sentByBot.add(sent.key.id);
68
104
  lastSentAt = Date.now();
69
105
  pendingStatus = null;
70
106
  }
@@ -82,7 +118,8 @@ export class WhatsAppAdapter implements ChatAdapter {
82
118
  batchTimer = null;
83
119
  pendingStatus = null;
84
120
  }
85
- await this.sock?.sendMessage(jid, { text: replyText });
121
+ const sent = await this.sock?.sendMessage(jid, { text: replyText });
122
+ if (sent?.key?.id) this.sentByBot.add(sent.key.id);
86
123
  },
87
124
  updateStatus: async (statusText: string) => {
88
125
  pendingStatus = statusText;
@@ -113,6 +150,7 @@ export class WhatsAppAdapter implements ChatAdapter {
113
150
  async sendToUser(userId: string, text: string): Promise<void> {
114
151
  const phone = userId.replace("whatsapp:", "");
115
152
  const jid = `${phone}@s.whatsapp.net`;
116
- await this.sock?.sendMessage(jid, { text });
153
+ const sent = await this.sock?.sendMessage(jid, { text });
154
+ if (sent?.key?.id) this.sentByBot.add(sent.key.id);
117
155
  }
118
156
  }
@@ -1,7 +1,18 @@
1
1
  import { describe, it, expect, beforeEach, afterEach } from "bun:test";
2
2
  import { loadConfig, isAuthorized, getUserRepos, saveConfig, addRepo, addUser } from "./config";
3
+ import type { Config } from "./config";
3
4
  import { readFileSync, writeFileSync, unlinkSync } from "node:fs";
4
5
 
6
+ function makeConfig(overrides: Partial<Config> = {}): Config {
7
+ return {
8
+ repos: {},
9
+ users: {},
10
+ claude: { maxTurns: 25 },
11
+ reposDir: "./repos",
12
+ ...overrides,
13
+ };
14
+ }
15
+
5
16
  describe("loadConfig", () => {
6
17
  it("returns config with repos and users", () => {
7
18
  const config = loadConfig();
@@ -99,3 +110,62 @@ describe("saveConfig / addRepo / addUser", () => {
99
110
  expect(config.users["slack:U1"].repos).toEqual(["a", "b", "c"]);
100
111
  });
101
112
  });
113
+
114
+ describe("wildcard auth", () => {
115
+ it("grants access to any repo with wildcard", () => {
116
+ const config = makeConfig({
117
+ users: { "tg:123": { name: "love", repos: ["*"] } },
118
+ });
119
+ expect(isAuthorized(config, "tg:123", "any-repo")).toBe(true);
120
+ expect(isAuthorized(config, "tg:123", "another-repo")).toBe(true);
121
+ });
122
+
123
+ it("still works with explicit repo list", () => {
124
+ const config = makeConfig({
125
+ users: { "tg:123": { name: "love", repos: ["my-app"] } },
126
+ });
127
+ expect(isAuthorized(config, "tg:123", "my-app")).toBe(true);
128
+ expect(isAuthorized(config, "tg:123", "other")).toBe(false);
129
+ });
130
+
131
+ it("denies unknown user", () => {
132
+ const config = makeConfig();
133
+ expect(isAuthorized(config, "unknown", "repo")).toBe(false);
134
+ });
135
+
136
+ it("allows user without repo check", () => {
137
+ const config = makeConfig({
138
+ users: { "tg:123": { name: "love", repos: [] } },
139
+ });
140
+ expect(isAuthorized(config, "tg:123")).toBe(true);
141
+ });
142
+ });
143
+
144
+ describe("getUserRepos with wildcard", () => {
145
+ it("returns ['*'] when user has wildcard", () => {
146
+ const config = makeConfig({
147
+ users: { "tg:123": { name: "love", repos: ["*"] } },
148
+ });
149
+ expect(getUserRepos(config, "tg:123")).toEqual(["*"]);
150
+ });
151
+
152
+ it("returns empty for unknown user", () => {
153
+ const config = makeConfig();
154
+ expect(getUserRepos(config, "unknown")).toEqual([]);
155
+ });
156
+ });
157
+
158
+ describe("github config type", () => {
159
+ it("accepts github config on Config", () => {
160
+ const config = makeConfig({
161
+ github: { syncInterval: 60000, orgs: ["my-org"] },
162
+ });
163
+ expect(config.github!.syncInterval).toBe(60000);
164
+ expect(config.github!.orgs).toEqual(["my-org"]);
165
+ });
166
+
167
+ it("github config is optional", () => {
168
+ const config = makeConfig();
169
+ expect(config.github).toBeUndefined();
170
+ });
171
+ });
package/src/config.ts CHANGED
@@ -6,9 +6,10 @@ export interface RunnerConfig {
6
6
  }
7
7
 
8
8
  export interface RepoConfig {
9
- url: string;
10
- defaultBranch: string;
9
+ url?: string;
10
+ defaultBranch?: string;
11
11
  runner?: RunnerConfig;
12
+ excluded?: boolean;
12
13
  }
13
14
 
14
15
  export interface UserConfig {
@@ -30,6 +31,11 @@ export interface CronTaskConfig {
30
31
  userId: string;
31
32
  }
32
33
 
34
+ export interface GitHubConfig {
35
+ syncInterval?: number;
36
+ orgs?: string[];
37
+ }
38
+
33
39
  export interface Config {
34
40
  repos: Record<string, RepoConfig>;
35
41
  users: Record<string, UserConfig>;
@@ -40,6 +46,7 @@ export interface Config {
40
46
  mcpServers?: Record<string, McpServerConfig>;
41
47
  cron?: CronTaskConfig[];
42
48
  runner?: RunnerConfig;
49
+ github?: GitHubConfig;
43
50
  }
44
51
 
45
52
  export function loadConfig(): Config {
@@ -54,6 +61,7 @@ export function loadConfig(): Config {
54
61
  mcpServers: raw.mcpServers,
55
62
  cron: raw.cron,
56
63
  runner: raw.runner,
64
+ github: raw.github,
57
65
  };
58
66
  } catch {
59
67
  return {
@@ -77,7 +85,7 @@ export function isAuthorized(config: Config, platformUserId: string, repo?: stri
77
85
  const user = config.users[platformUserId];
78
86
  if (!user) return false;
79
87
  if (!repo) return true;
80
- return user.repos.includes(repo);
88
+ return user.repos.includes("*") || user.repos.includes(repo);
81
89
  }
82
90
 
83
91
  export function saveConfig(config: Config): void {
@@ -91,6 +99,7 @@ export function saveConfig(config: Config): void {
91
99
  if (config.mcpServers) merged.mcpServers = config.mcpServers;
92
100
  if (config.cron) merged.cron = config.cron;
93
101
  if (config.runner) merged.runner = config.runner;
102
+ if (config.github) merged.github = config.github;
94
103
  writeFileSync(configPath, JSON.stringify(merged, null, 2) + "\n");
95
104
  }
96
105