Skip to content

Soul-driven AI agent with permission-hardened tools, token budgets, and multi-channel access. Runs 24/7 from CLI, Telegram or More.

fix(channels): keep install_skill out of the tool set for Telegram members

SeashoreShi8160bff648d9
diff --git a/src/capabilities/permissions.ts b/src/capabilities/permissions.ts
index b4071dbb..5ab789a3 100644
--- a/src/capabilities/permissions.ts
+++ b/src/capabilities/permissions.ts
@@ -303,6 +303,7 @@ export class PermissionManager {
* everything else denies. Never combined with autoApproveAll.
*/
private failClosed = false;
+ private currentSenderRole: 'admin' | 'member' | undefined;
private tempScopes: FileScope[] = [];
@@ -355,6 +356,14 @@ export class PermissionManager {
return this.currentChannelType;
}
+ setCurrentSenderRole(role: 'admin' | 'member' | undefined): void {
+ this.currentSenderRole = role;
+ }
+
+ getCurrentSenderRole(): 'admin' | 'member' | undefined {
+ return this.currentSenderRole;
+ }
+
onAsk(handler: (prompt: string) => Promise<string>): void {
this.askHandler = handler;
}
diff --git a/src/capabilities/registry.test.ts b/src/capabilities/registry.test.ts
new file mode 100644
index 00000000..51b4a55d
--- /dev/null
+++ b/src/capabilities/registry.test.ts
@@ -0,0 +1,28 @@
+import { describe, expect, it } from 'vitest';
+import { CapabilityRegistry } from './registry.js';
+
+// Member-level chat senders (e.g. approved Telegram members) must not be able
+// to reach `install_skill`, which is admin-only and is the escalation path from
+// chat access to local command execution.
+describe('CapabilityRegistry.getTools sender role gating', () => {
+ it('hides install_skill from members but not from admins or roleless senders', () => {
+ const registry = new CapabilityRegistry({} as any);
+ registry.registerAll();
+
+ // Baseline: no role information (CLI / internal) keeps every tool.
+ registry.permissions.setCurrentSenderRole(undefined);
+ expect(registry.getTools().install_skill).toBeDefined();
+
+ // Admins keep install_skill.
+ registry.permissions.setCurrentSenderRole('admin');
+ expect(registry.getTools().install_skill).toBeDefined();
+
+ // Members lose it, while the rest of the tool surface is untouched.
+ const admin = registry.getTools();
+ registry.permissions.setCurrentSenderRole('member');
+ const member = registry.getTools();
+ expect(member.install_skill).toBeUndefined();
+ expect(Object.keys(member).length).toBe(Object.keys(admin).length - 1);
+ expect(member.use_skill).toBeDefined();
+ });
+});
diff --git a/src/capabilities/registry.ts b/src/capabilities/registry.ts
index 3c763b53..d70c0336 100644
--- a/src/capabilities/registry.ts
+++ b/src/capabilities/registry.ts
@@ -275,7 +275,15 @@ export class CapabilityRegistry {
}
getTools(): Record<string, Tool> {
- return this.tools;
+ if (this.permissions.getCurrentSenderRole() !== 'member') return this.tools;
+ // Members on a channel that distinguishes roles (e.g. Telegram) must not be
+ // able to install skills: `install_skill` is the escalation path from chat
+ // access to arbitrary local execution and is documented as admin-only.
+ const filtered: Record<string, Tool> = {};
+ for (const [name, tool] of Object.entries(this.tools)) {
+ if (name !== 'install_skill') filtered[name] = tool;
+ }
+ return filtered;
}
/** Return tools filtered for plan mode — read-only tools only */
diff --git a/src/channels/telegram.ts b/src/channels/telegram.ts
index a639eb8b..c4a5dcb4 100644
--- a/src/channels/telegram.ts
+++ b/src/channels/telegram.ts
@@ -227,6 +227,7 @@ export class TelegramChannel extends BaseChannel {
channelType: 'telegram',
senderId: ctx.from?.id.toString() ?? 'unknown',
senderName: ctx.from?.first_name,
+ senderRole: this.isAdminUser(userId) ? 'admin' : 'member',
content: ctx.message.text,
timestamp: ctx.message.date * 1000,
metadata: { chatId, messageId: ctx.message.message_id },
diff --git a/src/core/agent.ts b/src/core/agent.ts
index b2fec2e4..9c490b5e 100644
--- a/src/core/agent.ts
+++ b/src/core/agent.ts
@@ -3295,6 +3295,7 @@ export class Agent {
this.capabilities.setChannelContext(msg.channelId, msg.channelType);
this.capabilities.permissions.setCurrentChannelType(msg.channelType);
+ this.capabilities.permissions.setCurrentSenderRole(msg.senderRole);
const providerContextId = msg.sessionId ?? (typeof msg.metadata?.sessionId === 'string' ? msg.metadata.sessionId : msg.channelId);
const channelOverride = this.channelProviderOverrides.get(providerContextId);
diff --git a/src/types/channel.ts b/src/types/channel.ts
index 5bf79e9d..5593ed80 100644
--- a/src/types/channel.ts
+++ b/src/types/channel.ts
@@ -24,6 +24,14 @@ export interface ChannelMessage {
channelType: ChannelType;
senderId: string;
senderName?: string;
+ /**
+ * Role of the sender on the originating channel, when the channel can
+ * distinguish it (e.g. Telegram admins vs approved members). Undefined for
+ * channels that have no notion of roles (CLI, internal). Used to keep
+ * admin-only capabilities (such as installing skills) out of the tool set
+ * exposed to non-admin chat participants.
+ */
+ senderRole?: "admin" | "member";
content: string;
timestamp: number;
/** Canonical local session identity; channelId remains transport-specific. */