Skip to content
luckybot-devPublic

About

Lark-first agentic group chatbot, based on Menci/Cahciua

Resources

Stars

1 star

Watchers

0 watching

Forks

Latest commit

 

History

332 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

LuckyBot

Feishu/Lark-first LLM group-chat member with personality and per-person memory, not an assistant.

Based on Cahciua (菜花) by Menci.

LuckyBot is an open-source, Feishu/Lark-first adaptation of Cahciua (菜花) by Menci. It retains upstream Git history and Cahciua's core architectural strengths—message persistence, the deterministic context pipeline, reply scheduling, tool execution, and context compaction—while evolving the bot into an authentic group-chat participant with long-term memory, personality, and bounded participation.

Rather than acting as an obedient productivity assistant, LuckyBot behaves as an authentic member of a small community group: it speaks when it has something meaningful to say, reacts with emoji, declines requests in character, or remains silent.

Origin & Heritage

This project is a direct adaptation of Cahciua (菜花), created by Menci and released under the MIT License.

LuckyBot keeps Cahciua's foundation: message persistence and deterministic replay, the Deterministic Context Pipeline (IC' = reduce(IC, event) rendered to provider-independent XML), the probe gate and reply scheduling, the tool loop, provider transports, and background context compaction.

On top of it, LuckyBot adds:

  • Native Feishu/Lark integration over the official long connection.
  • Per-person Markdown long-term memory with provenance checks enforced in code.
  • Bounded participation: legitimate silence or reaction-only turns, per-turn tool and time budgets, and per-chat talkativeness controls.
  • A trusted maintainer list, and a Docker deployment with the Bash tool in a separate sandbox container.

Features

  • Natural Group-Chat Participation: Uses an outside-judge probe gate before primary execution to decide whether to respond (send_message), react only (react_only), or remain silent (no_action).
  • Feishu/Lark First: Native integration with Feishu/Lark via the official WebSocket SDK (@larksuiteoapi/node-sdk), supporting ambient and @-mention messages, quoted replies, image inspection (read_image), reactions, and member identity tracking.
  • Telegram Support: Inherited full-featured Telegram adapter powered by TDLib with userbot/bot separation, media understanding, and spam moderation.
  • Deterministic Context Pipeline (DCP): Pure reducer architecture (IC' = reduce(IC, event)) that projects canonical platform events into in-memory context and renders provider-independent XML (RC) optimized for prompt-prefix caching.
  • Per-Person Long-Term Memory (Phase 1): Human-readable Markdown cards per member (people/<open_id>.md) and self-notes (SELF.md), maintained by an asynchronous background consolidator with strict provenance validation, owner-evidence requirements, and prompt-injection safety guards.
  • Work Mode: The work tool hands a self-contained job (running code, processing files, multi-step investigation) to one long-lived Pi Durable session per chat. It runs in the background inside the sandbox container, keeps a per-group git workspace of reusable Agent Skills (skills/) and results (notes/), survives restarts, and reports back as a runtime event that the bot retells in its own voice.
  • Safe & Bounded Tool Execution: Strict per-turn budgets (tool rounds, work-tool limits, model deadlines) prevent runaway loops. System shell access (bash, work, kill_task, read_task_output) is strictly gated by a trusted maintainer list and executed inside an isolated sandbox container.
  • Autonomous Context Compaction: Background compaction controller summarizes older context when estimated token counts exceed thresholds, preserving conversation continuity.
  • Modular Plugin System: Capability-based plugin host running independent extension modules (mounted from plugins/, e.g. group mini-game webhooks, web search & fetch) with tool and scene extension points, strict memory/chat privacy isolation, and per-chat gating.

Architecture

Every platform event becomes a canonical event, is persisted, and is folded by a pure reducer into the in-memory context (IC), which is rendered to provider-independent XML (RC). The Driver decides per chat whether and how to take part; background controllers keep memory and context size in check without blocking a turn.

flowchart TD
  im["Feishu / Lark long connection · Telegram TDLib"]
  adapt["Adaptation → CanonicalIMEvent"]
  sink[("SQLite event archive")]
  proj["Projection: IC' = reduce(IC, event)"]
  render["Rendering: IC → XML (RC)"]
  sched["Scheduler: debounce · retry · watchdog"]
  probe{"Probe: act now?"}
  primary["Primary tool loop, bounded by TurnBudget"]
  plugins["Plugin host<br/>web · cron · tavern · redact · musicgo"]
  tasks["Background tasks<br/>bash · work · plugin tools"]
  work["Work session<br/>Pi Durable, one per chat"]
  sandbox[("Sandbox container<br/>per-group skills/ · notes/")]
  compaction["Compaction"]
  memory["Person memory"]

  im --> adapt --> sink --> proj --> render --> sched --> probe -->|activate| primary
  primary -->|"send_message · react"| im
  primary <-->|"tools · chat.publish · ask"| plugins
  primary --> tasks
  tasks -->|"bash, maintainer-gated"| sandbox
  tasks -->|"work, maintainer-gated"| work -->|"commands · files"| sandbox
  tasks -.->|"report as runtime event"| sched
  sink -.-> compaction -.->|"summary + cursor"| proj
  sink -.-> memory -.->|"notes in the late-binding prompt"| primary
Loading

Dotted arrows run in the background and never block a turn. Probe, primary, compaction, memory consolidation, media captions, plugins and the work session all call models through one non-streaming boundary (src/llm/) speaking openai-chat, anthropic-messages and responses. The work session's harness and model keys stay in the bot process; only its commands and file access reach the sandbox.

A wake-up never obliges the bot to speak. The probe judges everything since the bot last acted; only an activation runs the primary loop, which ends with a message, a reaction, or a deliberate silence:

flowchart TD
  input["New messages or a runtime event"] --> wait["Debounce: typing and the trigger sender's follow-ups extend the delay"]
  wait --> cont{"Interrupted tool loop<br/>still open?"}
  cont -->|yes| step
  cont -->|no| probe{"Probe decides"}
  probe -->|no_action| idle["Stay silent"]
  probe -->|react_only| react["react, then end_turn"]
  probe -->|send_message| step["Primary step<br/>(a tool call is required)"]
  step --> tools["Run tools<br/>send_message · react · read_image · bash · work · plugins"]
  tools --> budget{"Budget left and<br/>follow-up needed?"}
  budget -->|yes| step
  budget -->|no| close["Turn ends<br/>(one wrap-up step first if the budget ran out)"]
  tools -->|"long job"| bg["Background task"] -.->|"report wakes the chat"| input
Loading

Source layout and the binding invariants behind each box are in AGENTS.md; the pipeline rationale is in docs/dcp-design.md.

Quick Start

Local Setup

Prerequisites: Node.js >= 22, pnpm >= 10.

pnpm install
cp config.example.yaml config.yaml
cp prompts/IDENTITY.example.md prompts/IDENTITY.md
  1. Edit config.yaml with your platform credentials (feishu or telegram), model endpoints, and configured chat IDs.
  2. Edit prompts/IDENTITY.md to define the bot's persona and character traits (see prompts/IDENTITY.example.md for section guidelines).
  3. Start the bot:
pnpm start

Production Deployment

For production environments, LuckyBot deploys via Docker Compose with host firewall isolation and a separate sandbox container for the Bash tool:

  • Follow the Docker Deployment Guide for full instructions on image building, volume setup, SSH key configuration, and firewall management.

Configuration Pointers

All runtime configuration lives in config.yaml (see config.example.yaml):

  • platform: Select 'feishu' or 'telegram'.
  • feishu: App credentials (appId, appSecret, domain).
  • telegram: Bot token, API ID, API hash, and userbot options.
  • models: Provider endpoints (openai-chat, anthropic-messages, responses) and model settings.
  • maintainers: Top-level list of canonical platform user IDs authorized to unlock maintainer-gated tools.
  • chats.<chatId>: Per-chat allowlist configuration, including participation style (quiet, normal, lively), turn budgets, memory toggles, and tool exposure.

Documentation Index

Detailed architectural and operational documentation is organized as follows:

Design

Deployment

  • Docker Deployment Guide: Production deployment runbook with Docker Compose, firewall rules, and sandboxed Bash execution.

Platform

History & Archive

For developer guidelines and core invariants, see AGENTS.md.

Development

pnpm dev        # Start development runner with file watching
pnpm build      # Bundle application with tsdown
pnpm typecheck  # Run TypeScript type check
pnpm lint       # Lint source code with ESLint
pnpm test:run   # Run test suite with Vitest

Never commit credentials, local databases (data/*.db), user session tokens, or LLM request dumps (/tmp/cahciua/).

Roadmap

  • Browser Exploration: Isolated browser tool for web search and page inspection.
  • Feishu Document Lookup: Workspace and document search tools via Feishu OpenAPI / CLI / MCP.
  • Probe alternatives: Compare Jev and other judges against the current probe on anonymized chats.
  • Media Enhancements: Content-aware frame selection for animated stickers and video clips.

Acknowledgements

Special thanks to Menci for creating Cahciua (菜花), providing the foundation and inspiration for this project.

Sponsors

LuckyBot runs on paid model API calls and hosting, and its presence in the group is sustained by people who choose to fund it. Thanks to liuyuze2005 for his financial support, which goes directly toward keeping LuckyBot alive in the chat.

License

LuckyBot is released under the MIT License. It is derived from Cahciua, which is MIT-licensed by Menci; the original copyright notice is retained in LICENSE.

About

Lark-first agentic group chatbot, based on Menci/Cahciua

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages