Skip to content

Instantly share code, notes, and snippets.

View Rustam-Z's full-sized avatar
πŸ”οΈ
Cracking!

@Rustam-Z πŸš€ Rustam-Z

πŸ”οΈ
Cracking!
View GitHub Profile
@Rustam-Z
Rustam-Z / prompt_mckinsey_research
Created February 10, 2026 20:07
Prompts for Ai to prepare McKinsey similar research
1/ Market Sizing & TAM Analysis
You are a McKinsey-level market analyst. I need a Total Addressable Market (TAM) analysis for [YOUR INDUSTRY/PRODUCT].
Please provide:
β€’ Top-down approach: Start from global market β†’ narrow to my segment
β€’ Bottom-up approach: Calculate from unit economics Γ— potential customers
β€’ TAM, SAM, SOM breakdown with dollar figures
β€’ Growth rate projections for the next 5 years (CAGR)
@Rustam-Z
Rustam-Z / 07-database-schema.md
Created February 9, 2026 13:14 — forked from nodir-t/07-database-schema.md
Claudir Architecture β€” Part 7: Database Schema

Part 7: Database Schema

Each bot maintains its own SQLite database (claudir.db) plus a shared bot-to-bot messaging database. The schema covers ~20 tables organized by domain.

Core Messaging

-- All messages the bot has seen (group + DM)
messages (
    chat_id INTEGER NOT NULL,
@Rustam-Z
Rustam-Z / 06-focus-mode.md
Created February 9, 2026 13:14 — forked from nodir-t/06-focus-mode.md
Claudir Architecture β€” Part 6: Focus Mode

Part 6: Focus Mode

The Problem

A bot that monitors multiple chats simultaneously has a fundamental UX issue: context fragmentation. If someone is having a deep conversation in a DM while group messages arrive, the bot's attention splits. Claude sees interleaved messages from different conversations, leading to confused responses, topic mixing, and wasted context window space.

Focus mode solves this by implementing single-chat attention β€” the bot concentrates on one conversation at a time, queueing messages from all other chats for later processing.

How It Works

@Rustam-Z
Rustam-Z / 05-claude-code-integration.md
Created February 9, 2026 13:14 — forked from nodir-t/05-claude-code-integration.md
Claudir Architecture β€” Part 5: Claude Code Integration

Part 5: Claude Code Integration

Claude Code Subprocess Lifecycle

The most technically intricate part of the system: managing Claude Code as a long-running AI process via stdin/stdout streaming.

Why Claude Code Instead of Direct API?

  1. Cost: The Max subscription includes a generous Claude Code usage allowance. Using CC as a subprocess means the bots run on the subscription rather than per-token API billing β€” a massive cost difference when running 24/7 across multiple bots
  2. Context compaction: CC automatically manages context windows β€” when the conversation grows too large, it compacts older content while preserving important context. Building this yourself on top of the raw API would be significant engineering effort
@Rustam-Z
Rustam-Z / 04-the-security-model.md
Created February 9, 2026 13:14 — forked from nodir-t/04-the-security-model.md
Claudir Architecture β€” Part 4: The Security Model

Part 4: The Security Model

Running an AI-powered Telegram bot in public groups presents a fundamental security challenge: the bot receives untrusted input from anyone, and that input is processed by an LLM that can call tools. If the LLM can execute arbitrary code, every message becomes a potential Remote Code Execution (RCE) vector.

Security Defense in Depth

The Core Security Principle

Users send messages --> LLM processes them --> LLM calls tools
@Rustam-Z
Rustam-Z / 03-mcp-and-the-tool-system.md
Created February 9, 2026 13:13 — forked from nodir-t/03-mcp-and-the-tool-system.md
Claudir Architecture β€” Part 3: MCP and the Tool System

Part 3: MCP and the Tool System

MCP Tool Architecture

Why MCP?

The original design had Claude Code return a JSON array of tool calls via StructuredOutput. This worked, but was limiting β€” Claude had to batch all tool calls into a single response, couldn't chain results, and complex JSON parsing was error-prone.

MCP solves all of these. Claude Code makes HTTP calls to a local server during its turn, gets results back, and can chain tool calls naturally. Within a single turn, the bot can send multiple messages, check the database, generate an image, and react to a message β€” all as separate MCP calls interleaved with reasoning. The harness runs the MCP server, so tool execution is still controlled by Rust code.

@Rustam-Z
Rustam-Z / 02-the-harness-and-engine.md
Created February 9, 2026 13:13 — forked from nodir-t/02-the-harness-and-engine.md
Claudir Architecture β€” Part 2: The Harness and Engine

Part 2: The Harness and Engine

Three-Process Model

Message Flow Pipeline

Each Bot = Three Processes

Every bot instance consists of three OS processes. The harness is the core β€” it handles Telegram I/O, hosts the MCP tool server, and manages the CC subprocess. CC is the brain β€” it processes messages, makes tool calls back to the harness via HTTP, and returns control actions. The wrapper just ensures the harness stays alive.

@Rustam-Z
Rustam-Z / 01-the-three-tier-system.md
Created February 9, 2026 13:13 — forked from nodir-t/01-the-three-tier-system.md
Claudir Architecture β€” Part 1: The Three-Tier System

Part 1: The Three-Tier System

Three-Tier Architecture

The Three Tiers

Each tier has a distinct identity, trust level, and permission set. The bot tiers share the same Rust binary (claudir) but run with different configuration files that control their behavior.

Tier 0: Owner & Supervisor

@Rustam-Z
Rustam-Z / 00-intro.md
Created February 9, 2026 13:13 — forked from nodir-t/00-intro.md
Claudir Architecture Deep Dive β€” Table of Contents

Claudir Architecture Deep Dive

Claudir is a ~33,000-line Rust Telegram bot system that uses Claude AI (via Anthropic's Claude Code CLI) to power intelligent chat interactions. What makes it architecturally interesting is not just that it wraps an LLM β€” it's how it structures trust, isolation, and operational resilience through a deliberate three-tier hierarchy.

Table of Contents

  1. The Three-Tier System β€” Owner/Supervisor, CTO bot, public chatbots. Trust hierarchy, bot-to-bot messaging, config-driven personalities, self-healing wrapper.

  2. The Harness and Engine β€” Three-process model, message flow pipeline, spam filtering, debouncer, control loop, inject mechanism, dropped text detection.

@Rustam-Z
Rustam-Z / MyLogger.py
Created August 1, 2022 13:07 — forked from huklee/MyLogger.py
python Logger using example with Singleton Pattern
# -*- coding: utf-8 -*-
import logging
import os
import datetime
import time
class SingletonType(type):
_instances = {}