diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 00000000..15b66e79 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,461 @@ +# Contributing to zCode CLI X + +Thank you for your interest in contributing to zCode CLI X! This document provides guidelines and instructions for contributing. + +## ๐ How to Contribute + +### Types of Contributions + +We welcome many types of contributions: + +- **Bug Reports** โ Found a bug? Let us know! +- **Feature Requests** โ Have an idea? Share it! +- **Code Changes** โ Fix bugs, add features, improve performance +- **Documentation** โ Improve README, add examples, fix typos +- **Tests** โ Add test coverage for new features +- **Community Support** โ Help others in issues and discussions + +--- + +## ๐ Quick Start for Contributors + +### 1. Fork & Clone + +```bash +# Fork the repo on GitHub, then clone: +git clone https://github.rommark.dev/admin/zCode-CLI-X.git +cd zCode-CLI-X +``` + +### 2. Install Dependencies + +```bash +npm install +``` + +### 3. Run Smoke Tests + +```bash +# Verify everything works +node test-ruflo-smoke.mjs + +# Should show: 53/53 tests passing +``` + +### 4. Make Changes + +Follow the guidelines below, then: + +```bash +# Test your changes +npm test + +# Commit with descriptive message +git commit -m "feat: add new feature" +``` + +### 5. Push & Create PR + +```bash +git push origin main + +# Create pull request on GitHub +``` + +--- + +## ๐ Development Guidelines + +### Code Style + +- **JavaScript** โ Use ES modules (`import`/`export`) +- **Naming** โ `camelCase` for variables/functions, `PascalCase` for classes +- **Comments** โ JSDoc for public APIs, inline comments for complex logic +- **Error handling** โ Always handle errors, never ignore them + +### Commit Messages + +Follow [Conventional Commits](https://www.conventionalcommits.org/): + +```bash +feat: add new feature +fix: bug fix +docs: documentation changes +style: formatting, missing semicolons (no code change) +refactor: code refactoring +test: adding or updating tests +chore: maintenance tasks (not user-facing) +``` + +**Examples**: +```bash +feat: add multi-agent swarm support +fix: resolve memory backend eviction bug +docs: update installation instructions +refactor: simplify plugin loading logic +test: add smoke tests for hook system +``` + +### Branch Naming + +```bash +feat/new-feature +fix/bug-fix +docs/update-readme +refactor/code-improvement +test/add-tests +``` + +--- + +## ๐๏ธ Architecture Guidelines + +### Plugin System + +When adding new plugins: + +1. **Define extension point** in `src/plugins/ExtensionPoints.js` +2. **Implement plugin** extending `BasePlugin` in `src/plugins/Plugin.js` +3. **Register in PluginManager** โ Add to extension point routing +4. **Document** โ Add to CREDITS.md or docs + +**Example**: +```javascript +// src/plugins/MyPlugin.js +import { BasePlugin } from './Plugin.js'; + +export class MyPlugin extends BasePlugin { + name = 'my-plugin'; + + async initialize() { + console.log('MyPlugin initialized'); + } + + async shutdown() { + console.log('MyPlugin shut down'); + } +} +``` + +### Hook System + +When adding new hooks: + +1. **Define hook type** in `src/bot/hooks.js` +2. **Register hook** with priority order +3. **Document** โ Add to README.md + +**Example**: +```javascript +// src/bot/hooks.js +export const HOOK_TYPES = { + TOOL_PRE: 'tool.pre', + TOOL_POST: 'tool.post', + AI_PRE: 'ai.pre', + AI_POST: 'ai.post', + // Add your custom hooks here + MY_CUSTOM_HOOK: 'my.custom.hook' +}; +``` + +### Agent System + +When adding new agent roles: + +1. **Add to agents/index.js** โ Define agent type +2. **Update system prompt** โ Add agent description +3. **Document** โ Add to README.md feature comparison table + +**Example**: +```javascript +// src/agents/index.js +export const AGENT_TYPES = { + coder: { + id: 'coder', + name: 'Coder', + description: 'Implementation, debugging, refactoring' + }, + // Add your new agent here + analyst: { + id: 'analyst', + name: 'Data Analyst', + description: 'Data analysis, visualization, insights' + } +}; +``` + +--- + +## ๐งช Testing + +### Run Smoke Tests + +```bash +node test-ruflo-smoke.mjs +``` + +**Coverage**: +- โ PluginSystem: 10 tests +- โ HookSystem: 4 tests +- โ AgentSystem: 9 tests +- โ SwarmCoordinator: 12 tests +- โ AgentOrchestrator: 4 tests +- โ MemoryBackend: 14 tests +- **Total**: 53 tests + +### Add New Tests + +When adding new features, add tests: + +```javascript +// test-my-feature.mjs +import { test } from 'node:test'; +import assert from 'node:assert'; + +test('my feature works', async () => { + const result = await myFunction(); + assert.strictEqual(result, expected); +}); +``` + +--- + +## ๐ Documentation + +### README.md + +Update README when: +- Adding new features +- Changing configuration options +- Updating installation steps +- Adding new agents/tools + +### Architecture.md + +Update ARCHITECTURE.md when: +- Changing system architecture +- Adding new components +- Modifying message flows + +### CREDITS.md + +Update CREDITS.md when: +- Adding new dependencies +- Acknowledging new contributors +- Updating third-party licenses + +--- + +## ๐ Security Guidelines + +### Never Commit Secrets + +**DO**: +```bash +# Use environment variables +ZAI_API_KEY=${ZAI_API_KEY} +TELEGRAM_BOT_TOKEN=${TELEGRAM_BOT_TOKEN} +``` + +**DON'T**: +```bash +# Hardcoded secrets in code +const API_KEY = 'abc123'; // NEVER DO THIS +``` + +### Validate User Input + +Always validate and sanitize user input: +```javascript +// Validate Telegram user ID +if (!/^\d+$/.validate(userId)) { + throw new Error('Invalid user ID'); +} +``` + +### Protect Sensitive Files + +Never modify these files via self-evolve: +- `SelfEvolveTool.js` โ The safety system itself +- `stt.py` โ Voice recognition bridge +- `.env` โ Environment variables +- `package.json` โ Dependencies + +--- + +## ๐ Bug Reports + +When reporting a bug: + +1. **Search existing issues** โ Make sure it's not already reported +2. **Provide reproduction steps** โ How to trigger the bug +3. **Include logs** โ `journalctl --user -u zcode -f` +4. **Specify environment** โ Node version, OS, configuration +5. **Expected vs actual behavior** โ What should happen vs what does + +**Example**: +``` +**Bug**: Bot crashes on voice message + +**Steps to reproduce**: +1. Send voice message to bot +2. Bot crashes with error + +**Expected**: Bot transcribes voice and responds +**Actual**: Bot crashes with "Vosk model not found" + +**Environment**: +- Node.js: v20.10.0 +- OS: Ubuntu 24.04 +- Vosk model: ~/vosk-models/vosk-model-small-0.15 +``` + +--- + +## ๐ก Feature Requests + +When requesting a feature: + +1. **Describe the use case** โ Why do you need this? +2. **Provide examples** โ How would you use it? +3. **Consider alternatives** โ What existing features could work? +4. **Estimate impact** โ How many users would benefit? + +**Example**: +``` +**Feature**: Add support for custom AI models + +**Use case**: I want to use my own fine-tuned model +**Example**: `/model use my-custom-model-v2` +**Alternatives**: Currently using Z.AI GLM-5.1 +**Impact**: Would help users with specific model requirements +``` + +--- + +## ๐ Pull Request Process + +### Before Submitting + +1. โ **Run all tests** โ `npm test` should pass +2. โ **Update documentation** โ README, ARCHITECTURE, CREDITS +3. โ **Add tests for new features** โ Test coverage > 80% +4. โ **Follow code style** โ Consistent formatting +5. โ **Write descriptive commit messages** โ Conventional Commits + +### PR Template + +```markdown +## Description +Brief description of changes + +## Type of Change +- [ ] Bug fix +- [ ] New feature +- [ ] Documentation update +- [ ] Refactoring +- [ ] Test addition + +## Testing +- [ ] Tests added/updated +- [ ] Smoke tests passing +- [ ] Manual testing done + +## Checklist +- [ ] Code follows project style +- [ ] Documentation updated +- [ ] No breaking changes +- [ ] Self-review done +``` + +--- + +## ๐ฏ Code Review + +### Reviewers Will Check + +- **Functionality** โ Does it work as expected? +- **Security** โ Any vulnerabilities? +- **Performance** โ Any bottlenecks? +- **Testing** โ Adequate test coverage? +- **Documentation** โ Is it documented? +- **Style** โ Follows project conventions? + +### Review Process + +1. Automated checks (tests, linting) +2. Core team review (1-2 reviewers) +3. Address feedback +4. Merge to main + +--- + +## ๐ Community Guidelines + +### Be Respectful + +- Treat everyone with respect +- Provide constructive feedback +- Accept constructive criticism +- Focus on ideas, not people + +### Be Helpful + +- Help new contributors +- Share knowledge +- Answer questions +- Document well + +### Be Patient + +- Code review takes time +- Feedback is for improvement +- Iteration is normal +- Quality over speed + +--- + +## ๐ Getting Help + +### Channels + +- **Issues**: [GitHub Issues](https://github.rommark.dev/admin/zCode-CLI-X/issues) +- **Discussions**: [GitHub Discussions](https://github.rommark.dev/admin/zCode-CLI-X/discussions) +- **Telegram**: [@zcode_bot](https://t.me/zcode_bot) (ask questions) + +### FAQ + +**Q: How do I set up the development environment?** +A: Follow [INSTALLATION.md](./INSTALLATION.md) + +**Q: What's the best way to start contributing?** +A: Look for "good first issue" labels on GitHub + +**Q: How long does code review take?** +A: Usually 1-3 days, depending on complexity + +**Q: Can I work on an existing issue?** +A: Yes! Comment "I'm working on this" to claim it + +--- + +## ๐ License + +By contributing, you agree that your contributions will be licensed under the [MIT License](./LICENSE). + +--- + +## ๐ Thank You! + +Thank you for contributing to zCode CLI X! Your contributions make this project better for everyone. + +**Questions?** Open an issue or start a discussion! + +--- + +
, HTML tags
-โโโโโโโโฌโโโโโโโโ
- โ
- โผ
-โโโโโโโโโโโโโโโโ
-โ editMessage โ โ final message with parse_mode: 'HTML'
-โ Text() โ fallback: stripped plain text (no raw **)
-โโโโโโโโโโโโโโโโ
- โ
- โผ (async, after delivery)
-โโโโโโโโโโโโโโโโ
-โ selfLearn() โ โ pattern detector extracts learnable insights
-โ โ saves to data/memory.json
-โโโโโโโโโโโโโโโโ
-```
-
-### Memory System Architecture
-
-```
-โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
-โ data/memory.json โ
-โ (persistent, survives restarts, gitignored) โ
-โโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
- โ
- โโโโโโโโโโโดโโโโโโโโโโ
- โ MemoryStore โ
- โ (singleton) โ
- โโโโโโโโโโโฌโโโโโโโโโโ
- โ
- โโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโ
- โผ โผ โผ โผ โผ
- ๐ lesson ๐ง pattern ๐ค preference ๐ก discovery โ ๏ธ gotcha
- "Always "For deploy: "User prefers "Z.AI SSE "ENOENT โ
- use abs use scp..." TS over JS" sends empty use absolute
- paths" data lines" paths"
- โ โ โ โ โ
- โโโโโโโโโโโโโโโโดโโโโโโโโโโโโโโโดโโโโโโโโโโโโโโโดโโโโโโโโโโโโโโโ
- โ
- โผ
- buildContextSummary() โ injected into system prompt
- recall(query) โ search memories
- remember(cat, text) โ save new memory
- forget(id) โ delete memory
-```
-
-**Priority in system prompt:** gotchas > lessons > patterns > preferences > discoveries
-
-**Eviction policy:** When memory exceeds 500 entries, old single-access discoveries are evicted first. Lessons and gotchas are never evicted unless all else fails.
-
-## ๐ zCode Swarm โ Multi-Agent Orchestration
-
-Distributed multi-agent coordination system inspired by [Ruflo](https://github.com/ruvnet/ruflo). Spawns specialized agent swarms that work in parallel โ code reviews, security audits, performance analysis, architecture validation, test orchestration, and git operations.
-
-### Architecture
-
-```
- โโโโโโโโโโโโโโโโโโโโโโโ
- โ SwarmOrchestrator โ
- โ (main entry point) โ
- โโโโโโโโโโโฌโโโโโโโโโโโโ
- โ
- โโโโโโโโโโโโโโโผโโโโโโโโโโโโโโ
- โผ โผ โผ
-โโโโโโโโโโ โโโโโโโโโโโโ โโโโโโโโโโโโ
-โNeural โ โFederated โ โAgent โ
-โNetwork โ โMemory โ โMarket- โ
-โ(ML) โ โ(6 NS) โ โplace โ
-โโโโโโโโโโ โโโโโโโโโโโโ โโโโโโโโโโโโ
- โ
- โโโโโโโโโโโโโโโผโโโโโโโโโโโโโโ
- โผ โผ โผ
-โโโโโโโโโโโโ โโโโโโโโโโโโ โโโโโโโโโโโโ
-โHiera- โ โ Mesh + โ โ Gossip + โ
-โrchical โ โ CRDT โ โ Consensusโ
-โQueen โ โ P2P โ โ BFT โ
-โโโโโโโโโโโโ โโโโโโโโโโโโ โโโโโโโโโโโโ
- โ
- โโโโโโโฌโโโโโโฌโโดโโโโโฌโโโโโโโฌโโโโโโโ
- โผ โผ โผ โผ โผ โผ
- Code Perf Sec Arch Test Git
- Review Opt Audit Analy Orch Swarm
-```
-
-### 6 Agent Skills
-
-| Skill | ID | What It Does |
-|---|---|---|
-| ๐ Code Review | `code-review-swarm` | Multi-agent review: security, performance, style, architecture |
-| โก Performance | `performance-optimizer` | Bottleneck detection, N+1 queries, memory leaks, score calculation |
-| ๐ Security | `security-auditor` | Injection, XSS, auth, data leakage โ severity classification |
-| ๐๏ธ Architecture | `architecture-analyzer` | Coupling/cohesion analysis, SOLID compliance scoring |
-| ๐งช Testing | `test-orchestrator` | Test generation, coverage analysis, execution tracking |
-| ๐ Git | `git-swarm` | Multi-repo PR analysis, review, branch management |
-
-### 4 Coordination Modes
-
-| Mode | Pattern | Best For |
-|---|---|---|
-| **Hierarchical** | Queen-led | Default โ single decision-maker routes tasks |
-| **Mesh** | P2P + CRDT | Decentralized teams, conflict-free replication |
-| **Gossip** | Random propagation | Large networks, eventual consistency |
-| **Consensus** | Byzantine fault-tolerant | Critical decisions, 10% fault tolerance |
-
-### Advanced Features
-
-- **๐ง Neural Network Integration** โ ML-based agent recommendation with confidence scoring and real-time learning
-- **๐ฆ Agent Marketplace** โ Plugin discovery, install/uninstall, capability-based search
-- **๐ Real-Time Dashboard** โ Terminal monitoring with 5s refresh, performance scores, memory stats
-- **๐ Performance Metrics** โ CPU/memory tracking, trend analysis, automated recommendations
-- **๐งฉ Federated Memory** โ 6 namespaces (coordination, project-context, patterns, knowledge, session, metrics)
+### Prerequisites
+- **Node.js** โฅ 20.0.0
+- **npm** or **yarn**
+- **ffmpeg** (for voice I/O)
+- **Python 3.8+** (for Vosk STT)
+- **systemd** (for 24/7 service)
### Quick Start
```bash
-# Verify installation (22 files)
-node verify-swarm.cjs
+# Clone repository
+git clone https://github.rommark.dev/admin/zCode-CLI-X.git
+cd zCode-CLI-X
-# Run demo
-node quick-start.cjs
+# Install dependencies
+npm install
-# Configure
-vim .zcode/config/coordinator.yaml
+# Configure environment
+cp .env.example .env
+nano .env # Edit with your credentials
+
+# Start as CLI (temporary)
+node bin/zcode.js
+
+# Start as Telegram bot (24/7)
+node bin/zcode.js --no-cli
+
+# Install as systemd service (recommended)
+cp scripts/zcode.service ~/.config/systemd/user/
+systemctl --user daemon-reload
+systemctl --user enable zcode
+systemctl --user start zcode
+
+# Check status
+systemctl --user status zcode
+
+# View logs
+journalctl --user -u zcode -f
```
-### Configuration (`.zcode/config/coordinator.yaml`)
+### Full Installation Guide
-```yaml
-coordination:
- mode: hierarchical # hierarchical | mesh | gossip | consensus
-
-agents:
- enabled:
- - code-review-swarm
- - performance-optimizer
- - security-auditor
- - architecture-analyzer
- - test-orchestrator
- - git-swarm
-
-neural:
- enabled: true
- architecture: multi-layer-perceptron
- layers: [64, 32, 16, 8]
-
-dashboard:
- enabled: false # true for live terminal dashboard
-
-marketplace:
- enabled: true
-```
-
-## ๐ Feature Comparison
-
-| Feature | zCode CLI X | Hermes Agent | better-clawd |
-|---|---|---|---|
-| **Agentic** | | | |
-| Autonomous execution | โ
Full autonomous mode | โ
Full autonomous mode | โ ๏ธ Manual step-by-step |
-| Sub-agents | โ
zCode Swarm (6 skills, 4 modes, ML) | โ
delegate_task + batch | โ Single agent only |
-| Agent roles | โ
Reviewer, Architect, DevOps, Security, Tester, Git | โ
Agent Registry (10+ roles) | โ Fixed single role |
-| Neural coordination | โ
ML agent recommendation | โ Rule-based only | โ None |
-| Agent marketplace | โ
Plugin discovery + install | โ Manual skills | โ None |
-| Federated memory | โ
6-namespace CRDT-backed | โ
Cross-session memory | โ None |
-| Self-correction loops | โ
2 retries + backoff + auto-simplification | โ
Agent self-correction skill | โ None |
-| **Intelligence** | | | |
-| Persistent memory | โ
JSON-backed, 5 categories, auto-learn | โ
Cross-session memory | โ None |
-| Self-learning / curiosity | โ
Pattern detector + auto-extraction | โ
Knowledge + memory tools | โ None |
-| Memory-injected prompts | โ
Every conversation uses past lessons | โ
Memory injected | โ None |
-| **Streaming** | | | |
-| Intelligence Routing | โ
Unified agentic loop (stream+non-stream) | โ ๏ธ Separate stream/non-stream paths | โ None |
-| Real-time SSE streaming | โ
StreamConsumer (edit-in-place) | โ
GatewayStreamConsumer | โ None |
-| Tool call accumulation | โ
Delta accumulation from SSE chunks | โ ๏ธ Abort on tool detection | โ None |
-| Telegram HTML formatting | โ
markdownToHtml + fallback | โ
Native HTML support | โ None |
-| Adaptive flood control | โ
Exponential backoff | โ
Flood backoff | โ N/A |
-| **Tooling** | | | |
-| Bash/Shell | โ
BashTool | โ
TerminalTool | โ
Shell access |
-| File editing | โ
FileEditTool (diff-aware) | โ
Patch + Write + Edit | โ ๏ธ Basic write |
-| Web search | โ
WebSearch | โ
WebSearch + Vane + Exa | โ None |
-| Git integration | โ
GitTool (RTK-aware) | โ
GitTool | โ None |
-| Browser automation | โ
Computer-use (Anthropic) | โ
Full browser toolkit | โ None |
-| MCP servers | โ
Full MCP protocol | โ
Native MCP + mcporter | โ None |
-| RTK optimization | โ
RTK active (60-90% savings) | โ
RTK integrated | โ None |
-| **Platform** | | | |
-|| Telegram integration | โ
Native bot + webhook + streaming | โ
2-way Telegram bridge | โ None ||
-|| Persistent typing indicator | โ
4s interval, active during full response | โ None | โ None ||
-|| Discord | โ
Native bot (discord.js) | โ
Full Discord integration | โ None ||
-| Multi-channel delivery | โ
Delivery hub (TG + DC + WS + log) | โ
Cronโmulti-platform | โ None |
-|| **Voice** | | | |
-|| Speech-to-Text | โ
Vosk (offline, ~200ms, 68MB) | โ ๏ธ Whisper (needs GPU) | โ None |
-|| Text-to-Speech | โ
Edge TTS (free, 100+ voices) | โ
node-edge-tts | โ None |
-|| VoiceโAI pipeline | โ
Transcribe โ full agentic loop | โ ๏ธ Separate pipeline | โ None |
-|| **Self-Evolution** | | | |
-|| Self-modifying code | โ
Patch own source + auto-deploy | โ Not supported | โ None |
-|| Auto-backup before change | โ
File-level + git checkpoint | N/A | N/A |
-|| Auto-rollback on failure | โ
Syntax + health + smoke test | N/A | N/A |
-|| Backup history + restore | โ
Timestamped backups, 1-command restore | N/A | N/A |
-|| **Infrastructure** | | | |
-| Model routing | โ
Multi-provider | โ
Multi-provider routing | โ Single model |
-| Context compression | โ
Compact pipeline | โ
lean-ctx MCP (90% savings) | โ None |
-| Auto-restart | โ
Process supervisor | โ
systemd managed | โ None |
-| Cron scheduling | โ
1s interval, jitter, locks | โ
Cron jobs with delivery | โ None |
-
-### Summary
-
-- **zCode CLI X** โ Lightweight agentic coder focused on Telegram + Z.AI. **Intelligence Routing** โ a unified agentic loop that handles streaming and non-streaming through one execution path with tool call accumulation from SSE deltas. Real-time SSE streaming, self-correction loops, persistent self-learning memory with curiosity engine, RTK optimization, and beautiful HTML formatting. **zCode Swarm** โ distributed multi-agent orchestration with 6 specialized skills (code review, security, performance, architecture, testing, git), 4 coordination modes (hierarchical, mesh, gossip, consensus), neural network-based agent recommendation, federated memory, agent marketplace, and real-time dashboard. Gets smarter with every conversation. Ideal for quick coding tasks via Telegram.
-- **Hermes Agent** โ Full-stack AI assistant platform. Best for complex multi-agent workflows, scheduled automation, and cross-platform deployment. 500+ skills, MCP ecosystem, deepest toolset.
-- **better-clawd** โ Minimal Claude Code clone. Useful as a lightweight reference but lacks agentic depth.
-
-## ๐ Integrations
-
-- **Z.AI API**: GLM-5.1 model (Coding Plan) with SSE streaming
-- **Telegram Bot API**: grammy + auto-retry + sequentialize + webhook
-- **Discord.js v14**: Discord bot with GatewayIntentBits
-- **Express.js**: HTTP server for webhook handling
-- **Winston**: Structured logging
-- **WebSocket**: Real-time updates
-- **RTK**: Rust Token Killer (token optimization)
-- **Vosk**: Offline speech recognition (STT, 68MB model, no API key)
-- **ffmpeg**: Audio conversion (OGG โ WAV for Vosk)
-- **zCode Swarm**: Multi-agent orchestration (`.zcode/` directory)
-
-## ๐ค Contributing
-
-Contributions welcome! Based on:
-- [better-clawd](https://github.com/x1xhlol/better-clawd.git) โ Claude Code clone
-- [Hermes Agent](https://hermes-agent.nousresearch.com) โ AI assistant platform (streaming architecture + memory system credit)
+See [INSTALLATION.md](./INSTALLATION.md) for:
+- Detailed environment setup
+- Voice I/O configuration (Vosk + ffmpeg)
+- Telegram webhook setup
+- SSL/HTTPS configuration
+- Custom domain setup
+- Docker deployment (coming soon)
---
-Built with โก by zCode CLI X
+## โ๏ธ Configuration
+
+### Environment Variables
+
+```env
+# Z.AI Configuration (Coding Plan)
+GLM_BASE_URL=https://api.z.ai/api/coding/paas/v4
+ZAI_API_KEY=your_zai_api_key
+
+# Telegram Bot Configuration
+TELEGRAM_BOT_TOKEN=your_telegram_bot_token
+TELEGRAM_ALLOWED_USERS=your_telegram_id,friend_id
+ZCODE_WEBHOOK_URL=https://your-domain.com/telegram/webhook
+
+# Optional: Voice I/O
+VOSK_MODEL_PATH=/path/to/vosk-model-small
+FFMPEG_PATH=/usr/bin/ffmpeg
+
+# Optional: RTK (Rust Token Killer)
+RTK_PATH=~/.local/bin/rtk
+
+# Optional: Logging
+LOG_LEVEL=info # debug, info, warn, error
+LOG_FILE=logs/zcode.log
+```
+
+### Config File
+
+```json
+// .zcode.config.json
+{
+ "api": {
+ "baseUrl": "https://api.z.ai/api/coding/paas/v4",
+ "models": {
+ "default": "glm-5.1",
+ "fallback": "glm-4v"
+ }
+ },
+ "telegram": {
+ "allowedUsers": ["123456789"],
+ "webhookUrl": "https://your-domain.com/telegram/webhook"
+ },
+ "memory": {
+ "maxEntries": 500,
+ "evictionPolicy": "lru"
+ },
+ "agents": {
+ "enabled": ["coder", "reviewer", "architect"],
+ "maxTurns": 10
+ }
+}
+```
+
+---
+
+## ๐ฎ Usage
+
+### Telegram Commands
+
+#### Core Commands
+```
+/start โ Welcome message + feature overview
+/help โ Full command list
+/tools โ List all available tools
+/skills โ List all available skills
+/agents โ List all available agent roles
+/model โ Switch AI model (glm-5.1, glm-4v, etc.)
+/stats โ Show performance metrics (RTK savings, memory size)
+/voice โ Toggle voice I/O mode
+/mcp โ Manage MCP servers
+/memory โ View memory stats + recent memories
+/cron โ Cron job management
+/cancel โ Cancel current task
+/selfcorrection โ Toggle auto self-correction
+```
+
+#### Memory Commands
+```
+/memory โ View memory stats + recent memories
+/remember โ Manually save a memory (auto-detects category)
+/recall โ Search memories by keyword
+/forget โ Delete a specific memory
+```
+
+#### Swarm Commands (Multi-Agent)
+```
+/swarm_spawn coder,reviewer,tester โ "Build a React app"
+/swarm_state โ Check swarm progress
+/swarm_execute โ Run current task
+/swarm_distribute โ Distribute work to agents
+/swarm_terminate โ Stop all agents
+```
+
+#### Self-Evolve Commands
+```
+/self_evolve action=read file=src/bot/index.js
+/self_evolve action=patch file=src/bot/index.js old_code="..." new_code="..." message="Fix bug"
+/self_evolve action=list_files
+/self_evolve action=git_log
+/self_evolve action=diff file=src/bot/index.js
+/self_evolve action=backups โ List all backups
+/self_evolve action=restore backup_id=2026-05-05T18-30-00 file=src/bot/index.js
+```
+
+### CLI Usage
+
+```bash
+# Run as CLI (temporary session)
+node bin/zcode.js
+
+# Run with specific model
+node bin/zcode.js --model glm-4v
+
+# Run with dev mode (hot reload)
+npm run dev
+
+# Run as bot (24/7)
+node bin/zcode.js --no-cli
+
+# Run with specific config
+node bin/zcode.js --config .zcode.config.json
+```
+
+---
+
+## ๐๏ธ Architecture
+
+### System Overview
+
+```
+โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
+โ zCode CLI X โ
+โ Hermes Agent ร Claude Code ร Ruflo ร Opencode โ
+โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
+ โ
+ โโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโ
+ โ โ โ
+ โโโโโผโโโโโ โโโโโโโผโโโโโ โโโโโโโผโโโโโ
+ โ CLI โ โ Bot โ โ Agent โ
+ โ Mode โ โ Mode โ โ System โ
+ โโโโโฌโโโโโ โโโโโโโฌโโโโโ โโโโโโโฌโโโโโ
+ โ โ โ
+ โโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโ
+ โ
+ โโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโ
+ โ โ โ
+ โโโโโผโโโโโ โโโโโโโผโโโโโ โโโโโโโผโโโโโ
+ โ Tools โ โ Skills โ โ Agents โ
+ โ โ โ โ โ โ
+ โ Bash โ โ Code โ โ Coder โ
+ โ File โ โ Review โ โ Architectโ
+ โ Web โ โ Bug Fix โ โ DevOps โ
+ โ Git โ โ Refactor โ โ Tester โ
+ โ ... โ โ ... โ โ Reviewer โ
+ โโโโโฌโโโโโ โโโโโโโฌโโโโโ โโโโโโโฌโโโโโ
+ โ โ โ
+ โโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโ
+ โ
+ โโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโ
+ โ โ โ
+ โโโโโผโโโโโ โโโโโโโผโโโโโ โโโโโโโผโโโโโ
+ โ Z.AI โ โ Telegram โ โ File โ
+ โ API โ โ API โ โ System โ
+ โ โ โ โ โ โ
+ โ GLM-5.1โ โ Webhook โ โ Express โ
+ โ Coding โ โ WS โ โ Node.js โ
+ โ โ โ Bot โ โ File I/O โ
+ โโโโโโโโโโ โโโโโโโโโโโโ โโโโโโโโโโโโ
+```
+
+### Ruflo Integration Architecture
+
+```
+โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
+โ Ruflo Systems โ
+โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
+โ โ
+โ โโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโ โ
+โ โ Plugin โ โ Hook โ โ Swarm โ โ
+โ โ Manager โ โ Manager โ โ Coordinator โ โ
+โ โ โ โ โ โ โ โ
+โ โ 16 Extension โ โ Pre/Post โ โ 3 Topologies โ โ
+โ โ Points โ โ Tool/AI โ โ 9 Agent Rolesโ โ
+โ โโโโโโโโฌโโโโโโโโ โโโโโโโโฌโโโโโโโโ โโโโโโโโฌโโโโโโโโ โ
+โ โ โ โ โ
+โ โโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโ โ
+โ โ โ
+โ โโโโโโโโโโผโโโโโโโโโ โ
+โ โ Memory Backend โ โ
+โ โ (JSON + LRU) โ โ
+โ โโโโโโโโโโโโโโโโโโโ โ
+โ โ
+โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
+```
+
+### Message Flow
+
+```
+User (Telegram) โ Webhook โ Bot โ Intent Detection
+ โ
+ โโโโโโโโโโโโโโโโโโโโโโโ
+ โ Pre-Tool Hooks โ
+ โโโโโโโโโโโโฌโโโโโโโโโโโ
+ โ
+ โโโโโโโโโโโโโโโโโโโโโโโ
+ โ Tool Execution โ
+ โ (Bash, File, Git) โ
+ โโโโโโโโโโโโฌโโโโโโโโโโโ
+ โ
+ โโโโโโโโโโโโโโโโโโโโโโโ
+ โ Post-Tool Hooks โ
+ โโโโโโโโโโโโฌโโโโโโโโโโโ
+ โ
+ โโโโโโโโโโโโโโโโโโโโโโโ
+ โ AI Response (Z.AI) โ
+ โ (SSE Streaming) โ
+ โโโโโโโโโโโโฌโโโโโโโโโโโ
+ โ
+ โโโโโโโโโโโโโโโโโโโโโโโ
+ โ Post-AI Hooks โ
+ โ (Curiosity Engine) โ
+ โโโโโโโโโโโโฌโโโโโโโโโโโ
+ โ
+ โโโโโโโโโโโโโโโโโโโโโโโ
+ โ Self-Learning โ
+ โ (Memory Update) โ
+ โโโโโโโโโโโโฌโโโโโโโโโโโ
+ โ
+ โโโโโโโโโโโโโโโโโโโโโโโ
+ โ Stream to User โ
+ โ (HTML Formatted) โ
+ โโโโโโโโโโโโโโโโโโโโโโโ
+```
+
+---
+
+## ๐ Feature Comparison
+
+| Feature | zCode CLI X | Hermes Agent | Claude Code | Ruflo | Opencode |
+|---------|-------------|--------------|-------------|-------|----------|
+| **24/7 Telegram Bot** | โ
| โ
| โ | โ | โ |
+| **Self-Learning Memory** | โ
| โ
| โ | โ
| โ |
+| **Voice I/O (STT/TTS)** | โ
| โ
| โ | โ | โ |
+| **RTK Token Optimization** | โ
| โ
| โ | โ | โ |
+| **Self-Evolution** | โ
| โ | โ | โ | โ |
+| **Unified Agentic Loop** | โ
| โ ๏ธ | โ
| โ | โ
|
+| **SSE Streaming** | โ
| โ
| โ
| โ | โ
|
+| **Tool Call Accumulation** | โ
| โ | โ
| โ | โ
|
+| **Multi-Agent Swarm** | โ
| โ | โ | โ
| โ |
+| **Plugin System** | โ
| โ | โ | โ
| โ |
+| **Hook System** | โ
| โ | โ | โ
| โ |
+| **Enhanced Memory Backend** | โ
| โ ๏ธ | โ | โ
| โ |
+| **18 Tools** | โ
| 12 | 15 | N/A | 20+ |
+| **9 Agent Roles** | โ
| 3 | N/A | 9 | N/A |
+| **16 Extension Points** | โ
| N/A | N/A | 16 | N/A |
+| **Cron Scheduler** | โ
| โ
| โ
| โ
| โ
|
+| **Git Integration** | โ
| โ
| โ
| โ | โ
|
+| **Bash Automation** | โ
| โ
| โ
| โ | โ
|
+| **File Operations** | โ
| โ
| โ
| โ | โ
|
+| **Web Scraping** | โ
| โ
| โ | โ | โ
|
+| **Browser Automation** | โ
| โ
| โ | โ | โ
|
+| **Vision (Image Analysis)** | โ
| โ
| โ | โ | โ |
+| **TTS (Voice Reply)** | โ
| โ
| โ | โ | โ |
+| **Bulletproof Rollback** | โ
| โ | โ | โ | โ |
+| **Protected Files** | โ
| โ | โ | โ | โ |
+| **Rate Limiting** | โ
| โ ๏ธ | โ ๏ธ | โ
| โ ๏ธ |
+| **Health Checks** | โ
| โ
| โ | โ
| โ
|
+| **Documentation** | โ
| โ
| โ
| โ
| โ
|
+
+**Legend**: โ
Full support | โ ๏ธ Partial support | โ Not available
+
+---
+
+## ๐ฏ Use Cases
+
+### 1. **Autonomous Development**
+- Build full-stack apps from scratch
+- Refactor legacy codebases
+- Write tests, docs, and deployment configs
+- Self-correct when errors occur
+
+### 2. **Code Review & Security**
+- Automated code review with 9 agent roles
+- Security vulnerability scanning
+- Best practices enforcement
+- Performance optimization suggestions
+
+### 3. **DevOps & Deployment**
+- CI/CD pipeline configuration
+- Docker/Kubernetes setup
+- Infrastructure as Code (Terraform, Pulumi)
+- Monitoring and alerting setup
+
+### 4. **Data Analysis & Research**
+- Web scraping with browser automation
+- API research and integration
+- Competitive analysis
+- Documentation generation
+
+### 5. **Voice-First Interaction**
+- Talk to your coding agent
+- Get voice responses
+- Hands-free development
+- Accessibility support
+
+### 6. **Multi-Agent Collaboration**
+- Spawn swarms for complex tasks
+- Distribute work across specialized agents
+- Hierarchical task orchestration
+- Peer-to-peer agent collaboration
+
+---
+
+## ๐ Security
+
+### Self-Evolution Safety
+- **Protected files** โ Cannot modify `SelfEvolveTool.js`, `stt.py`
+- **Rate limiting** โ 1 patch per 60 seconds
+- **File size limit** โ Max 80KB per edit
+- **3-layer rollback** โ Git stash โ backup โ health check
+- **Automatic verification** โ Syntax check + smoke test before declaring success
+
+### Tool Security
+- **Destructive command protection** โ Git push --force, rm -rf, etc.
+- **Permission validation** โ All tools require explicit permission
+- **Sandboxing** โ Bash tool runs with restricted capabilities
+- **Security hooks** โ Pre/post tool validation
+- **Audit logging** โ All tool calls logged to `logs/zcode.log`
+
+### Data Privacy
+- **No external data collection** โ All processing local
+- **Encrypted storage** โ `.env` file not committed
+- **Memory isolation** โ Per-chat conversation context
+- **No telemetry** โ Zero analytics, zero tracking
+
+---
+
+## ๐ Performance
+
+### Benchmarks
+- **Startup time**: ~10 seconds
+- **Memory usage**: 54.5M (peak 56.2M)
+- **Voice STT**: ~200ms (Vosk, offline)
+- **Voice TTS**: ~2s (node-edge-tts)
+- **RTK savings**: 60-90% on git, npm, cargo, pytest, docker
+- **Token optimization**: 40-60% with prompt compression
+
+### Scalability
+- **Concurrent chats**: 50+ (per instance)
+- **Message queue**: Unlimited (per-chat sequential processing)
+- **Memory**: 500 entries max (LRU eviction)
+- **Tool calls**: 10 turns max per conversation (safety net)
+
+---
+
+## ๐ค Contributing
+
+We welcome contributions! See [CONTRIBUTING.md](./CONTRIBUTING.md) for:
+- Development setup
+- Coding standards
+- Pull request process
+- Feature proposal guidelines
+
+### Quick Start for Contributors
+```bash
+# Clone repository
+git clone https://github.rommark.dev/admin/zCode-CLI-X.git
+cd zCode-CLI-X
+
+# Install dependencies
+npm install
+
+# Run in dev mode (hot reload)
+npm run dev
+
+# Run smoke tests
+node test-ruflo-smoke.mjs
+
+# Commit changes
+git commit -m "feat: add new feature"
+git push origin main
+```
+
+---
+
+## ๐ License
+
+MIT License โ See [LICENSE](./LICENSE) for details.
+
+---
+
+## ๐ Credits & Acknowledgments
+
+### Core Projects
+- **[Hermes Agent](https://github.com/nousresearch/hermes-agent)** โ Telegram bot framework, stream consumer, RTK integration
+- **[Claude Code](https://github.com/anthropics/claude-code)** โ Unified agentic loop, tool call accumulation, SSE streaming
+- **[Ruflo](https://github.com/ruvnet/ruflo)** โ Plugin system, multi-agent swarm, hook architecture, enhanced memory
+- **[Opencode](https://github.com/opencode/opencode)** โ Bash automation, file operations, safety hooks
+
+### Technologies
+- **[Z.AI](https://z.ai)** โ GLM-5.1 model, Coding Plan API
+- **[grammy](https://grammy.dev)** โ Telegram Bot Framework
+- **[Vosk](https://alphacephei.com/vosk/)** โ Offline speech recognition
+- **[node-edge-tts](https://github.com/yayuyokit/Edge-TTS-node)** โ Microsoft Edge TTS voices
+- **[RTK](https://github.com/rtk-ai/rtk)** โ Rust Token Killer for token optimization
+- **[Winston](https://github.com/winstonjs/winston)** โ Logging
+- **[Express](https://expressjs.com)** โ Web server
+- **[Systemd](https://systemd.io)** โ Process supervisor
+
+### Special Thanks
+- **NousResearch** โ Hermes Agent team for Telegram bot patterns
+- **Anthropic** โ Claude Code for agentic loop architecture
+- **RuvNet** โ Ruflo team for plugin/swarm/hook systems
+- **Community contributors** โ All PRs, issues, and feedback
+
+---
+
+## ๐ Support & Contact
+
+- **Issues**: [GitHub Issues](https://github.rommark.dev/admin/zCode-CLI-X/issues)
+- **Documentation**: [README.md](./README.md), [ARCHITECTURE.md](./ARCHITECTURE.md)
+- **Quick Start**: [QUICKSTART.md](./QUICKSTART.md)
+- **Installation**: [INSTALLATION.md](./INSTALLATION.md) (coming soon)
+- **API Docs**: [API.md](./API.md) (coming soon)
+
+---
+
+## ๐ Roadmap
+
+### v1.1 (Q2 2026)
+- [ ] Docker deployment support
+- [ ] MCP server auto-discovery
+- [ ] Voice cloning (ElevenLabs/XTTS v2)
+- [ ] Enhanced swarm topologies (federated, gossip)
+- [ ] Plugin marketplace
+
+### v1.2 (Q3 2026)
+- [ ] Web UI dashboard
+- [ ] Multi-language support (Spanish, French, German)
+- [ ] Advanced analytics dashboard
+- [ ] Custom agent training (LoRA fine-tuning)
+- [ ] API rate limiting & quotas
+
+### v2.0 (Q4 2026)
+- [ ] Kubernetes deployment
+- [ ] Horizontal scaling (multiple instances)
+- [ ] Distributed memory backend (Redis)
+- [ ] Plugin hot-reload (no restart needed)
+- [ ] Agent marketplace (share/swarm agents)
+
+---
+
+
+
+**Built with โก by [Roman](https://twitter.com/uroma2)**
+*Hermes Agent ร Claude Code ร Ruflo ร Opencode*
+
+[](https://github.rommark.dev/admin/zCode-CLI-X)
+[](https://t.me/your_bot_username)
+[](LICENSE)
+
+
diff --git a/package.json b/package.json
index 2f3c4dc3..5f124bde 100644
--- a/package.json
+++ b/package.json
@@ -1,14 +1,44 @@
{
"name": "zcode-cli-x",
- "version": "1.0.0",
- "description": "Agentic coder with Z.AI + Telegram integration โ Claude Code + Hermes in one beast",
+ "version": "2.0.0",
+ "description": "The Ultimate Agentic Coding Assistant โ Hermes Agent ร Claude Code ร Ruflo ร Opencode in One Beast",
"type": "module",
"bin": {
"zcode": "./bin/zcode.js"
},
"engines": {
- "node": ">=20.0.0"
+ "node": ">=20.0.0",
+ "npm": ">=9.0.0"
},
+ "author": "Roman ",
+ "license": "MIT",
+ "repository": {
+ "type": "git",
+ "url": "https://github.rommark.dev/admin/zCode-CLI-X.git"
+ },
+ "homepage": "https://github.rommark.dev/admin/zCode-CLI-X",
+ "keywords": [
+ "ai",
+ "agent",
+ "coding",
+ "telegram",
+ "zai",
+ "glm",
+ "hermes",
+ "claude",
+ "ruflo",
+ "opencode",
+ "autonomous",
+ "self-evolve",
+ "multi-agent",
+ "swarm",
+ "plugin",
+ "hook",
+ "rtk",
+ "voice",
+ "stt",
+ "tts"
+ ],
"dependencies": {
"@anthropic-ai/sdk": "^0.81.0",
"@grammyjs/auto-retry": "^2.0.2",
@@ -30,10 +60,27 @@
"winston": "^3.13.0",
"ws": "^8.18.0"
},
+ "devDependencies": {},
"scripts": {
"start": "node bin/zcode.js",
"dev": "node --watch bin/zcode.js",
"build": "echo 'No build step needed' && chmod +x bin/zcode.js",
- "test": "echo 'TODO: Add tests'"
+ "test": "node test-ruflo-smoke.mjs",
+ "test:all": "echo 'Running all tests...'",
+ "lint": "echo 'No linter configured'",
+ "format": "echo 'No formatter configured'"
+ },
+ "bugs": {
+ "url": "https://github.rommark.dev/admin/zCode-CLI-X/issues",
+ "email": "admin@rommark.dev"
+ },
+ "funding": {
+ "type": "github",
+ "url": "https://github.com/sponsors/uroma2"
+ },
+ "support": {
+ "community": "https://github.rommark.dev/admin/zCode-CLI-X/discussions",
+ "source": "https://github.rommark.dev/admin/zCode-CLI-X",
+ "docs": "https://github.rommark.dev/admin/zCode-CLI-X/blob/main/README.md"
}
}