nullabot 1.0.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
nullabot/core/state.py ADDED
@@ -0,0 +1,214 @@
1
+ """
2
+ State Management - Never lose progress.
3
+
4
+ Handles checkpointing, state persistence, and crash recovery.
5
+ """
6
+
7
+ import json
8
+ from datetime import datetime
9
+ from enum import Enum
10
+ from pathlib import Path
11
+ from typing import Any, Optional
12
+
13
+ from pydantic import BaseModel, Field
14
+
15
+
16
+ class AgentType(str, Enum):
17
+ """Types of agents available."""
18
+
19
+ THINKER = "thinker"
20
+ DESIGNER = "designer"
21
+ CODER = "coder"
22
+
23
+
24
+ class AgentStatus(str, Enum):
25
+ """Current status of an agent."""
26
+
27
+ IDLE = "idle" # Not running
28
+ RUNNING = "running" # Actively working
29
+ PAUSED = "paused" # User requested pause
30
+ BLOCKED = "blocked" # Needs user input
31
+ ERROR = "error" # Encountered error
32
+
33
+
34
+ class Message(BaseModel):
35
+ """A single message in conversation history."""
36
+
37
+ role: str # "user", "assistant", "system"
38
+ content: str
39
+ timestamp: datetime = Field(default_factory=datetime.now)
40
+ metadata: dict[str, Any] = Field(default_factory=dict)
41
+
42
+
43
+ class Checkpoint(BaseModel):
44
+ """
45
+ Checkpoint - saved state that survives crashes.
46
+
47
+ Contains everything needed to resume work exactly where agent left off.
48
+ """
49
+
50
+ # Identity
51
+ agent_type: AgentType
52
+ project_name: str
53
+
54
+ # Current task
55
+ task: str # What user asked for
56
+ task_context: str = "" # Additional context
57
+
58
+ # Progress
59
+ current_step: str = "" # What agent is doing now
60
+ completed_steps: list[str] = Field(default_factory=list)
61
+ next_steps: list[str] = Field(default_factory=list)
62
+
63
+ # Outputs created
64
+ outputs: list[str] = Field(default_factory=list) # File paths
65
+
66
+ # Thinking (agent's internal notes)
67
+ thoughts: str = ""
68
+ learnings: list[str] = Field(default_factory=list)
69
+
70
+ # Metadata
71
+ created_at: datetime = Field(default_factory=datetime.now)
72
+ updated_at: datetime = Field(default_factory=datetime.now)
73
+ cycle_count: int = 0 # How many think cycles completed
74
+
75
+ def save(self, path: Path) -> None:
76
+ """Save checkpoint to file."""
77
+ self.updated_at = datetime.now()
78
+ path.write_text(self.model_dump_json(indent=2), encoding="utf-8")
79
+
80
+ @classmethod
81
+ def load(cls, path: Path) -> Optional["Checkpoint"]:
82
+ """Load checkpoint from file if exists."""
83
+ if not path.exists():
84
+ return None
85
+ try:
86
+ data = json.loads(path.read_text(encoding="utf-8"))
87
+ return cls.model_validate(data)
88
+ except Exception:
89
+ return None
90
+
91
+
92
+ class AgentState(BaseModel):
93
+ """
94
+ Full agent state including runtime information.
95
+ """
96
+
97
+ # Core
98
+ agent_type: AgentType
99
+ status: AgentStatus = AgentStatus.IDLE
100
+ project_name: str
101
+
102
+ # Current checkpoint
103
+ checkpoint: Optional[Checkpoint] = None
104
+
105
+ # Conversation
106
+ messages: list[Message] = Field(default_factory=list)
107
+
108
+ # Runtime
109
+ started_at: Optional[datetime] = None
110
+ error_count: int = 0
111
+ last_error: Optional[str] = None
112
+
113
+ # User interaction
114
+ pending_question: Optional[str] = None # Question waiting for user
115
+ pending_options: list[str] = Field(default_factory=list)
116
+
117
+ # === Ralph-inspired reliability features ===
118
+
119
+ # Circuit breaker state
120
+ circuit_state: str = "closed" # closed, open, half_open
121
+ circuit_failure_count: int = 0
122
+ circuit_last_failure: Optional[datetime] = None
123
+
124
+ # Progress tracking
125
+ cycles_without_progress: int = 0
126
+ last_output_hash: Optional[str] = None
127
+ completion_signals: int = 0
128
+ total_cycles: int = 0
129
+
130
+ # Rate limiting stats
131
+ total_tokens_used: int = 0
132
+ total_requests: int = 0
133
+ rate_limited_waits: int = 0
134
+ total_wait_time_seconds: float = 0.0
135
+
136
+ # Exit detection
137
+ exit_reason: Optional[str] = None
138
+ explicit_exit_signal: bool = False
139
+
140
+ def save(self, path: Path) -> None:
141
+ """Save state to file."""
142
+ path.write_text(self.model_dump_json(indent=2), encoding="utf-8")
143
+
144
+ @classmethod
145
+ def load(cls, path: Path) -> Optional["AgentState"]:
146
+ """Load state from file if exists."""
147
+ if not path.exists():
148
+ return None
149
+ try:
150
+ data = json.loads(path.read_text(encoding="utf-8"))
151
+ return cls.model_validate(data)
152
+ except Exception:
153
+ return None
154
+
155
+ def add_message(self, role: str, content: str, **metadata: Any) -> None:
156
+ """Add message to history."""
157
+ self.messages.append(Message(role=role, content=content, metadata=metadata))
158
+
159
+ def start(self) -> None:
160
+ """Mark agent as running."""
161
+ self.status = AgentStatus.RUNNING
162
+ self.started_at = datetime.now()
163
+ self.error_count = 0
164
+
165
+ def pause(self) -> None:
166
+ """Mark agent as paused (user requested)."""
167
+ self.status = AgentStatus.PAUSED
168
+
169
+ def block(self, question: str, options: list[str] | None = None) -> None:
170
+ """Mark agent as blocked, waiting for user input."""
171
+ self.status = AgentStatus.BLOCKED
172
+ self.pending_question = question
173
+ self.pending_options = options or []
174
+
175
+ def unblock(self, answer: str) -> None:
176
+ """Resume after user provides input."""
177
+ self.add_message("user", answer)
178
+ self.status = AgentStatus.RUNNING
179
+ self.pending_question = None
180
+ self.pending_options = []
181
+
182
+ def error(self, message: str) -> None:
183
+ """Record an error."""
184
+ self.error_count += 1
185
+ self.last_error = message
186
+ if self.error_count >= 3:
187
+ self.status = AgentStatus.ERROR
188
+
189
+
190
+ class HistoryWriter:
191
+ """Append-only history writer for crash safety."""
192
+
193
+ def __init__(self, path: Path):
194
+ self.path = path
195
+
196
+ def append(self, message: Message) -> None:
197
+ """Append message to history file."""
198
+ with open(self.path, "a", encoding="utf-8") as f:
199
+ f.write(message.model_dump_json() + "\n")
200
+
201
+ def load_all(self) -> list[Message]:
202
+ """Load all messages from history."""
203
+ if not self.path.exists():
204
+ return []
205
+ messages = []
206
+ with open(self.path, "r", encoding="utf-8") as f:
207
+ for line in f:
208
+ line = line.strip()
209
+ if line:
210
+ try:
211
+ messages.append(Message.model_validate_json(line))
212
+ except Exception:
213
+ continue
214
+ return messages
@@ -0,0 +1,130 @@
1
+ Metadata-Version: 2.4
2
+ Name: nullabot
3
+ Version: 1.0.1
4
+ Summary: 24/7 AI agents that think, design, and code - controlled via Telegram
5
+ Project-URL: Homepage, https://github.com/ebokoo/nullabot
6
+ Project-URL: Repository, https://github.com/ebokoo/nullabot
7
+ Project-URL: Issues, https://github.com/ebokoo/nullabot/issues
8
+ Author: ebokoo
9
+ License-Expression: MIT
10
+ License-File: LICENSE
11
+ Keywords: agents,ai,automation,bot,claude,coding,telegram
12
+ Classifier: Development Status :: 4 - Beta
13
+ Classifier: Environment :: Console
14
+ Classifier: Intended Audience :: Developers
15
+ Classifier: License :: OSI Approved :: MIT License
16
+ Classifier: Operating System :: OS Independent
17
+ Classifier: Programming Language :: Python :: 3.11
18
+ Classifier: Programming Language :: Python :: 3.12
19
+ Classifier: Topic :: Software Development :: Code Generators
20
+ Requires-Python: >=3.11
21
+ Requires-Dist: aiofiles>=23.0.0
22
+ Requires-Dist: aiosqlite>=0.19.0
23
+ Requires-Dist: click>=8.1.0
24
+ Requires-Dist: pydantic-settings>=2.0.0
25
+ Requires-Dist: pydantic>=2.0.0
26
+ Requires-Dist: python-telegram-bot>=21.0
27
+ Requires-Dist: pyyaml>=6.0.0
28
+ Requires-Dist: rich>=13.0.0
29
+ Requires-Dist: watchdog>=4.0.0
30
+ Provides-Extra: dev
31
+ Requires-Dist: pytest-asyncio>=0.23.0; extra == 'dev'
32
+ Requires-Dist: pytest>=8.0.0; extra == 'dev'
33
+ Requires-Dist: ruff>=0.5.0; extra == 'dev'
34
+ Description-Content-Type: text/markdown
35
+
36
+ # Nullabot
37
+
38
+ 24/7 AI agents that think, design, and code - controlled via Telegram.
39
+
40
+ ## Requirements
41
+
42
+ 1. **Python 3.11+**
43
+ 2. **Claude Code CLI** (requires Claude Max subscription ~$100-200/month)
44
+ ```bash
45
+ npm install -g @anthropic-ai/claude-code
46
+ claude login
47
+ ```
48
+
49
+ ## Install
50
+
51
+ ```bash
52
+ pip install nullabot
53
+ nullabot setup
54
+ ```
55
+
56
+ The setup wizard asks for:
57
+ - **Bot token** - Create at [@BotFather](https://t.me/BotFather) on Telegram
58
+ - **Your user ID** - Get from [@userinfobot](https://t.me/userinfobot) on Telegram
59
+ - **Other users** (optional) - Friends who can use your bot
60
+
61
+ ## Start the Bot
62
+
63
+ ```bash
64
+ nullabot bot
65
+ ```
66
+
67
+ Now open Telegram and message your bot!
68
+
69
+ ## Telegram Commands
70
+
71
+ | Command | Description |
72
+ |---------|-------------|
73
+ | `/start` | Show main menu |
74
+ | `/usage` | Show project costs |
75
+ | `/rules` | View/add global rules |
76
+ | `/chat <question>` | Ask anything |
77
+ | `/help` | All commands |
78
+
79
+ **Admin commands:**
80
+ | Command | Description |
81
+ |---------|-------------|
82
+ | `/users` | List all users |
83
+ | `/approve <id>` | Approve a user |
84
+ | `/revoke <id>` | Remove user |
85
+
86
+ ## CLI Commands
87
+
88
+ ```bash
89
+ nullabot new myproject # Create project
90
+ nullabot think myproject "task" # Research agent
91
+ nullabot design myproject "task" # Design agent
92
+ nullabot code myproject "task" # Coding agent
93
+ nullabot projects # List projects
94
+ nullabot usage # Show costs
95
+ ```
96
+
97
+ ## Three Agents
98
+
99
+ | Agent | What it does |
100
+ |-------|--------------|
101
+ | **Thinker** | Research, analyze, brainstorm |
102
+ | **Designer** | UI/UX specs, component design |
103
+ | **Coder** | Write code, tests, docs |
104
+
105
+ Agents automatically hand off context to each other.
106
+
107
+ ## Global Rules
108
+
109
+ Tell agents what to always/never do:
110
+
111
+ ```
112
+ /rules add do Always use TypeScript
113
+ /rules add dont Never use console.log
114
+ ```
115
+
116
+ Or just say it naturally in any message - it auto-saves!
117
+
118
+ ## Run 24/7
119
+
120
+ ```bash
121
+ # Manual (stops when terminal closes)
122
+ ./run_nullabot.sh bot
123
+
124
+ # Auto-start on Mac login
125
+ ./setup_autostart.sh
126
+ ```
127
+
128
+ ## License
129
+
130
+ MIT
@@ -0,0 +1,19 @@
1
+ nullabot/__init__.py,sha256=96923LhB3uU4TE33GdjyG8M2fRRcqeWvRWlqxt48OV4,58
2
+ nullabot/cli.py,sha256=zattwGYh4feT_sRjCxSOoG6WSToxc_F1Zp00T_zrAIU,25800
3
+ nullabot/agents/__init__.py,sha256=6mE-zjqFa99WfnE-khjDpCSKzaNlukKVP7tB5Q4o7Vk,133
4
+ nullabot/agents/claude_agent.py,sha256=P67S7UlIjKPInYcZcIGOp7o5shA3VLiv96auupvfPs8,30483
5
+ nullabot/bot/__init__.py,sha256=9axCMJfCE09CxMGsxtx81QZcBEXfz6wruHbYEtQQAeY,102
6
+ nullabot/bot/telegram.py,sha256=5YNpm2OGzy5A8jHEyvuVFvq9MTYeQ9qB8qFjiYQ_cYw,68354
7
+ nullabot/core/__init__.py,sha256=Yn9zEFXF_2-aXiiU_iftYuaXWrX1qC7ZaEd6i3sarIE,314
8
+ nullabot/core/claude_code.py,sha256=sIKINJzjolBBpd2B_XhM6Egwmxs8E_VvDV3AOcuJbkw,9306
9
+ nullabot/core/memory.py,sha256=0Qh9WRTZIkdOfGVLsAUbHIAuoFZ9-CoZ9wgP5DiPR7E,30674
10
+ nullabot/core/project.py,sha256=FZofBZzIhMQUCXxCI4jjJZjKRr5u4iJUbor70tvLh7Q,6222
11
+ nullabot/core/rate_limiter.py,sha256=41CF4cX_n5_PFc6Uk1vp6m4MERxXl25p1wyw2FVdgsM,16693
12
+ nullabot/core/reliability.py,sha256=nfMN29dCQqM_T_MSLe0z9Tk0N5CWYFtmNXVe9Lqmiyw,13985
13
+ nullabot/core/sandbox.py,sha256=fWgjhWglGzXsJ10qxiKwJEkQQv6tLVa-DsshO7qcQvQ,4562
14
+ nullabot/core/state.py,sha256=yeFF4r3h0nRd5LENiXE7SSqfWPuljGy7X0FgE_GuI5o,6307
15
+ nullabot-1.0.1.dist-info/METADATA,sha256=38vnwVRA7YqMgmjyLWVV6zVl95IkepRlUK1nD10nX8A,3360
16
+ nullabot-1.0.1.dist-info/WHEEL,sha256=WLgqFyCfm_KASv4WHyYy0P3pM_m7J5L9k2skdKLirC8,87
17
+ nullabot-1.0.1.dist-info/entry_points.txt,sha256=lHaTGUU4ku7Q6ZRZnlpp5LrHRyLxhaRB9HzXzsJwYY8,47
18
+ nullabot-1.0.1.dist-info/licenses/LICENSE,sha256=IppsK7DD3SKtJlMoquzr1-bGKs88x85956yPxCn8H-U,1063
19
+ nullabot-1.0.1.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: hatchling 1.28.0
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ nullabot = nullabot.cli:main
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 ebokoo
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.