Skip to content

Commit 0c0707d

Browse files
Merge pull request #3 from TheEdgeOfClaw/remove-start-command
Remove /start command and auto-approve functionality
2 parents 553d0a0 + 9e45421 commit 0c0707d

File tree

5 files changed

+5
-58
lines changed

5 files changed

+5
-58
lines changed

AGENTS.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ The server loads the plugin at startup. The plugin starts a grammY long-polling
1818
src/
1919
main.ts -- plugin entry: env validation, bot start, event hook
2020
telegram.ts -- grammY bot: auth middleware, commands, prompt dispatch, streaming edits
21-
opencode.ts -- SDK client wrapper: session CRUD, prompt, abort, permissions, auto-approve
21+
opencode.ts -- SDK client wrapper: session CRUD, prompt, abort, permissions
2222
format.ts -- MarkdownV2 escaping, code block preservation, tool summaries, message chunking
2323
events.ts -- event router: message.part.updated, permission.asked, streaming dispatch
2424
memory.ts -- exchange logging: saves every Telegram exchange as markdown to exchanges/
@@ -35,7 +35,7 @@ skills/
3535
- Session-to-chat mapping persisted to `sessions.json` (resolved relative to `directory` from plugin context)
3636
- Streaming uses edit-in-place with 2s throttle to stay under Telegram rate limits
3737
- Prompt is fired non-blocking (`.then/.catch`) so grammY can process permission callbacks while waiting
38-
- Permission requests surface as inline keyboards (Allow/Session/Deny); auto-approve is per-session toggle
38+
- Permission requests surface as inline keyboards (Allow/Session/Deny)
3939
- Permission callback data uses short counter keys (Telegram 64-byte limit on callback data)
4040
- Message chunking respects code block boundaries at 4096 char Telegram limit
4141
- Server sends `permission.asked` with a shape that diverges from the SDK's v1 `Permission` type.
@@ -51,6 +51,7 @@ skills/
5151
## Config
5252

5353
Environment variables (set in server's environment or systemd `EnvironmentFile=`):
54+
5455
- `TELEGRAM_BOT_TOKEN` -- required
5556
- `TELEGRAM_ALLOWED_USERS` -- required, comma-separated Telegram user IDs
5657
- `OPENCODE_WORKSPACE` -- optional, server working directory (used by Makefile at install time)
@@ -78,7 +79,7 @@ Install the plugin into the OpenCode workspace's plugin directory (symlink or co
7879
| Telegram lib | grammY | Lightweight, TypeScript-native |
7980
| Runtime | bun | No build step, runs TS directly |
8081
| Bot mode | Long polling | Simpler than webhooks for single-user |
81-
| Session mapping | File-persisted Map | Survives restarts; auto-approve is in-memory only |
82+
| Session mapping | File-persisted Map | Survives restarts |
8283
| Deployment | systemd user service | Reliable, auto-restart, journald logging |
8384
| Streaming | Edit-in-place messages | ChatGPT-style UX with 2s throttle |
8485
| Prompt execution | Non-blocking `.then/.catch` | Avoids deadlock: grammY must process permission callbacks while prompt blocks |

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ make uninstall
4949
| `/new` | New session |
5050
| `/sessions` | List and switch sessions |
5151
| `/abort` | Abort current session |
52-
| `/autoapprove on\|off` | Toggle auto-approve for permissions |
5352
| `/history` | Recent messages from current session |
5453
| `/remember <text>` | Save a memory to MEMORY.md via OpenCode |
5554
| `/start_llama` | Start llama systemd service |

src/main.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,9 @@ export const ClawCode: Plugin = async ({ client, directory }) => {
2525
const bot = createBot(token, allowedUsers);
2626

2727
await bot.api.setMyCommands([
28-
{ command: "start", description: "Welcome message" },
2928
{ command: "new", description: "New session" },
3029
{ command: "sessions", description: "List and switch sessions" },
3130
{ command: "abort", description: "Abort current session" },
32-
{ command: "autoapprove", description: "Toggle auto-approve (on|off)" },
3331
{ command: "history", description: "Recent messages from current session" },
3432
{ command: "remember", description: "Save a memory (/remember <text>)" },
3533
{ command: "start_llama", description: "Start llama service" },

src/opencode.ts

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ let client: Client;
88
let sessionsFile: string;
99

1010
const chatSessions = new Map<number, string>();
11-
const autoApprove = new Set<string>();
1211

1312
export function init(c: Client, directory: string): void {
1413
client = c;
@@ -32,15 +31,6 @@ function saveSessions(): void {
3231
writeFileSync(sessionsFile, JSON.stringify(obj, null, 2));
3332
}
3433

35-
export function setAutoApprove(sessionId: string, enabled: boolean): void {
36-
if (enabled) autoApprove.add(sessionId);
37-
else autoApprove.delete(sessionId);
38-
}
39-
40-
export function isAutoApprove(sessionId: string): boolean {
41-
return autoApprove.has(sessionId);
42-
}
43-
4434
export async function getOrCreateSession(
4535
chatId: number,
4636
): Promise<{ sessionId: string; fallback: boolean }> {

src/telegram.ts

Lines changed: 1 addition & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ import {
1414
abortSession,
1515
sendPrompt,
1616
replyPermission,
17-
setAutoApprove,
18-
isAutoApprove,
1917
} from "./opencode.js";
2018
import { registerSession, unregisterSession } from "./events.js";
2119
import { saveExchange } from "./memory.js";
@@ -106,14 +104,7 @@ export function createBot(token: string, allowedUsers: number[]): Bot {
106104
}
107105
});
108106

109-
bot.command("start", async (ctx) => {
110-
const sessionId = getSessionId(ctx.chat.id);
111-
const autoApproveStatus = sessionId && isAutoApprove(sessionId) ? "on" : "off";
112-
await ctx.reply(
113-
`Welcome to ClawCode\\! Send me a message and I'll forward it to OpenCode\\.\n\nAuto\\-approve: *${autoApproveStatus}*`,
114-
{ parse_mode: "MarkdownV2" },
115-
);
116-
});
107+
117108

118109
bot.command("new", async (ctx) => {
119110
const chatId = ctx.chat.id;
@@ -181,29 +172,6 @@ export function createBot(token: string, allowedUsers: number[]): Bot {
181172
}
182173
});
183174

184-
bot.command("autoapprove", async (ctx) => {
185-
log.info(`[cmd] /autoapprove chat=${ctx.chat.id}`);
186-
const arg = ctx.match?.trim().toLowerCase();
187-
if (arg !== "on" && arg !== "off") {
188-
await ctx.reply("Usage: /autoapprove on \\| off", { parse_mode: "MarkdownV2" });
189-
return;
190-
}
191-
const sessionId = getSessionId(ctx.chat.id);
192-
if (!sessionId) {
193-
await ctx.reply("No active session\\. Use /new to create one\\.", {
194-
parse_mode: "MarkdownV2",
195-
});
196-
return;
197-
}
198-
const enabled = arg === "on";
199-
setAutoApprove(sessionId, enabled);
200-
log.info(`[session] autoapprove=${enabled} session=${sessionId}`);
201-
await ctx.reply(
202-
escapeMarkdownV2(`Auto-approve ${enabled ? "enabled" : "disabled"} for current session.`),
203-
{ parse_mode: "MarkdownV2" },
204-
);
205-
});
206-
207175
bot.command("history", async (ctx) => {
208176
log.info(`[cmd] /history chat=${ctx.chat.id}`);
209177
const sessionId = getSessionId(ctx.chat.id);
@@ -380,15 +348,6 @@ export function createBot(token: string, allowedUsers: number[]): Bot {
380348
// onPermission
381349
async (perm: PermissionEvent) => {
382350
log.info(`[permission] request permission=${perm.permission} session=${perm.sessionID} perm=${perm.id}`);
383-
if (isAutoApprove(perm.sessionID)) {
384-
log.info(`[permission] auto-approving perm=${perm.id}`);
385-
await replyPermission(perm.sessionID, perm.id, "once");
386-
await ctx.api.sendMessage(chatId,
387-
escapeMarkdownV2(`Auto-approved: ${perm.permission} ${perm.patterns.join(", ")}`),
388-
{ parse_mode: "MarkdownV2" },
389-
);
390-
return;
391-
}
392351
const key = String(++permCounter);
393352
pendingPerms.set(key, { sessionId: perm.sessionID, permissionId: perm.id });
394353
const keyboard = new InlineKeyboard()

0 commit comments

Comments
 (0)