Soul-driven AI agent with permission-hardened tools, token budgets, and multi-channel access. Runs 24/7 from CLI, Telegram or More.
feat(bots): permission tiers at onboarding — ask, don't default silently
Salman Qureshid24814d7cacb
diff --git a/src/bots/permission-tiers.ts b/src/bots/permission-tiers.tsnew file mode 100644index 00000000..6bcf25e1--- /dev/null+++ b/src/bots/permission-tiers.ts@@ -0,0 +1,42 @@+import { BOT_DANGEROUS_TOOLS } from './store.js';++/**+ * Onboarding permission tiers — one clear question instead of silent+ * fail-closed defaults + manual file editing. Each tier is an explicit+ * tools.deny list (normalizeBotManifest respects an explicitly configured+ * tools block, so these grants stick). Whatever the tier, execution still+ * obeys the fail-closed PATH scopes — tools gate ≠ paths gate.+ */+export type PermissionTier = 'readonly' | 'builder' | 'operator' | 'full';++export const PERMISSION_TIERS: Record<PermissionTier, { label: string; description: string; deny: string[] }> = {+ readonly: {+ label: 'Read-only (recommended default)',+ description: 'Browse, search, read files, message bots. No execution, no file writes.',+ deny: [...BOT_DANGEROUS_TOOLS],+ },+ builder: {+ label: 'Builder — can write files',+ description: 'Read-only + create/edit/write files inside its granted scopes. Still no shell.',+ deny: ['run_command', 'delete_file', 'git_commit', 'git_push'],+ },+ operator: {+ label: 'Operator — can run commands',+ description: 'Builder + run_command. Execution still restricted to its granted path scopes (fail-closed), global blocked list applies.',+ deny: ['delete_file', 'git_commit', 'git_push'],+ },+ full: {+ label: 'Full access',+ description: 'Everything, including file deletion. For trusted automation only.',+ deny: [],+ },+};++export function isPermissionTier(value: string): value is PermissionTier {+ return value in PERMISSION_TIERS;+}++/** Apply a tier to a manifest (in place). */+export function applyPermissionTier(manifest: { tools?: { allow?: string[]; deny?: string[] } }, tier: PermissionTier): void {+ manifest.tools = { ...(manifest.tools ?? {}), deny: [...PERMISSION_TIERS[tier].deny] };+}\ No newline at end of filediff --git a/src/bots/persona-template.test.ts b/src/bots/persona-template.test.tsindex 389f35fe..9d34df76 100644--- a/src/bots/persona-template.test.ts+++ b/src/bots/persona-template.test.ts@@ -1,5 +1,6 @@import { describe, it, expect, beforeEach } from 'vitest';import { refinePersona } from './persona-template.js';+import { PERMISSION_TIERS, applyPermissionTier } from './permission-tiers.js';const scriptedResponses: string[] = [];@@ -165,4 +166,20 @@ Concise.expect(calls).toBe(2);expect(result).toContain('# Research');});-});\ No newline at end of file+});+describe('permission tiers (onboarding question backend)', () => {+ it('tiers produce the documented deny lists', () => {+ const m: any = {};+ applyPermissionTier(m, 'readonly');+ expect(m.tools.deny).toContain('run_command');+ expect(m.tools.deny).toContain('write_file');+ applyPermissionTier(m, 'builder');+ expect(m.tools.deny).toContain('run_command');+ expect(m.tools.deny).not.toContain('write_file');+ applyPermissionTier(m, 'operator');+ expect(m.tools.deny).not.toContain('run_command');+ expect(m.tools.deny).toContain('delete_file');+ applyPermissionTier(m, 'full');+ expect(m.tools.deny).toEqual([]);+ });+});diff --git a/src/bots/store.ts b/src/bots/store.tsindex 855691b6..5f1ab0a8 100644--- a/src/bots/store.ts+++ b/src/bots/store.ts@@ -386,12 +386,15 @@ function journalTreeSize(dir: string): number {}function normalizeBotManifest(raw: Partial<BotManifest>): BotManifest {- // Normalize deny list: dangerous tools are denied unless explicitly allowed- // via tools.allow. Deny always wins over allow.+ // Tool defaults: an unconfigured bot (no tools key) gets the fail-closed+ // dangerous-tool deny list. A bot with an EXPLICITLY configured tools block+ // is respected exactly as written — this is what the onboarding permission+ // tiers write, so hand-editing the deny list is a first-class way to grant+ // or revoke (previously the materialized defaults made hand-edits sticky).const allow = raw.tools?.allow ?? [];const explicitDeny = raw.tools?.deny ?? [];const deny = new Set<string>(explicitDeny);- if (allow.length === 0) {+ if (!raw.tools && allow.length === 0) {for (const t of BOT_DANGEROUS_TOOLS) deny.add(t);}return {diff --git a/src/core/agent.ts b/src/core/agent.tsindex 22c81768..40d09019 100644--- a/src/core/agent.ts+++ b/src/core/agent.ts@@ -26,6 +26,7 @@ import type { SkillLoader } from '../skills/loader.js';import { logger } from '../utils/logger.js';import { refinePersona } from '../bots/persona-template.js';import { proposeCrew } from '../bots/fleet-onboarding.js';+import { PERMISSION_TIERS, applyPermissionTier, isPermissionTier, type PermissionTier } from '../bots/permission-tiers.js';import { applyBotFieldPatch } from '../bots/edit.js';import { CLIChannel } from '../channels/cli.js';import { TelegramChannel } from '../channels/telegram.js';@@ -1187,8 +1188,9 @@ export class Agent {const mode = finalPersona === raw ? 'as-is' : 'as a structured template';await channel.send(`✍️ Persona saved ${mode}.`, `bot:${botId}`).catch(() => {});- // New-bot onboarding: solo vs fleet step (personas edited later never ask).+ // New-bot onboarding: permission tier, then solo vs fleet (edits later never ask).if (newlyCreated) {+ await this.offerPermissionTier(bm, botId, manifest.name, msg, channel);await this.offerFleetStep(bm, botId, manifest.name, msg, channel);}@@ -1207,6 +1209,29 @@ export class Agent {).catch(() => {});}+ /**+ * Permission-tier onboarding step (new bots only): one clear question+ * instead of silent fail-closed defaults + manual file editing. Change+ * anytime with `/bots permissions <id> <tier>`.+ */+ private async offerPermissionTier(bm: import('../bots/bot-manager.js').BotManager, botId: string, botName: string, msg: ChannelMessage, channel: any): Promise<void> {+ let choice = 'Read-only (recommended default)';+ try {+ choice = await this.presentChoice(+ `What should **${botName}** be allowed to do? (Path scopes always stay fail-closed — a tool only reaches what its Access grants cover.)`,+ Object.values(PERMISSION_TIERS).map(t => `${t.label} — ${t.description}`),+ msg.channelId,+ msg.channelType as any,+ );+ } catch {+ choice = 'Read-only (recommended default)';+ }+ const tier = (Object.entries(PERMISSION_TIERS).find(([, t]) => choice.startsWith(t.label))?.[0] ?? 'readonly') as PermissionTier;+ bm.store.update(botId, m => applyPermissionTier(m, tier));+ bm.invalidateRuntime(botId);+ await channel.send(`🔐 Permissions for **${botName}**: **${PERMISSION_TIERS[tier].label}**. Change anytime with \`/bots permissions ${botId} <readonly|builder|operator|full>\`.`, `bot:${botId}`).catch(() => {});+ }+/*** Fleet onboarding step (new bots only): solo vs lead. Auto-build asks one* LLM call for a matched crew; manual points at `/bots add-crew`. The@@ -1390,7 +1415,7 @@ export class Agent {const action = (parts[0] ?? '').toLowerCase();// All bot-targeting actions accept id OR name — resolve to the id here.- if (['open', 'send', 'journal', 'inbox', 'budget', 'edit', 'delete', 'enable', 'disable', 'stop', 'pause', 'start', 'run', 'persona', 'crew', 'add-crew', 'remove-crew', 'promote', 'demote'].includes(action) && parts[1]) {+ if (['open', 'send', 'journal', 'inbox', 'budget', 'edit', 'delete', 'enable', 'disable', 'stop', 'pause', 'start', 'run', 'persona', 'crew', 'add-crew', 'remove-crew', 'promote', 'demote', 'permissions'].includes(action) && parts[1]) {const resolved = bm.resolveBotId(parts[1]);if (resolved) parts[1] = resolved;}@@ -1770,6 +1795,33 @@ export class Agent {return;}+ if (action === 'permissions') {+ // /bots permissions <id> [tier] — show or set the capability tier.+ const target = parts[1]?.toLowerCase();+ const tierArg = (parts[2] ?? '').toLowerCase();+ if (!target || !bm.store.exists(target)) {+ await channel.send('Usage: `/bots permissions <id> [readonly|builder|operator|full]` — omit the tier to see the current one.', channelId);+ return;+ }+ if (!tierArg) {+ const m = bm.store.get(target)!;+ const deny = new Set(m.tools?.deny ?? []);+ const matched = Object.entries(PERMISSION_TIERS).find(([, t]) => t.deny.length === deny.size && t.deny.every(d => deny.has(d)))?.[0];+ const current = matched ?? 'custom';+ const effective = deny.has('run_command') ? 'no shell' : 'shell within its path scopes';+ await channel.send(`🔐 **${target}**: ${current} (deny: ${[...deny].join(', ') || 'none'}) — ${effective}. Set with \`/bots permissions ${target} <readonly|builder|operator|full>\`.`, channelId);+ return;+ }+ if (!isPermissionTier(tierArg)) {+ await channel.send('Unknown tier — use `readonly`, `builder`, `operator`, or `full`.', channelId);+ return;+ }+ bm.store.update(target, m => applyPermissionTier(m, tierArg));+ bm.invalidateRuntime(target);+ await channel.send(`🔐 Permissions for **${target}**: **${PERMISSION_TIERS[tierArg].label}** — ${PERMISSION_TIERS[tierArg].description}\n(Path scopes are untouched and always enforced.)`, channelId);+ return;+ }+if (action === 'promote' || action === 'demote') {// /bots promote <id> — solo/crew → fleet lead (demote: lead → solo).const target = parts[1]?.toLowerCase();@@ -1920,6 +1972,7 @@ export class Agent {'`/bots run <id> [routineName]` — fire a routine now, or a bare wake turn\n' +'`/bots crew <leadId>` — fleet tree with per-crew runs\n' +'`/bots promote <id>` / demote — make a bot a fleet lead (it then self-organizes) / back to solo\n' ++ '`/bots permissions <id> [tier]` — capability tier: readonly | builder | operator | full\n' +'`/bots add-crew <leadId> <id> "Name" "Desc" ["persona"]` — add a sub-bot to a fleet\n' +'`/bots remove-crew <leadId> <crewId>` — retire a crew member\n' +'`/bots delete <id> confirm` — permanently delete',