log + cli idk
i need some kind of notif system
This commit is contained in:
7 files changed
+399
-130
No files matched your search
@@ -24,13 +24,25 @@ src/agentmsgs/stores/sqlite.py # SQLiteStore — cross-CLI file sharing
|
||||
## 3. Domain Types (`core/types.py`)
|
||||
```python
|
||||
@dataclass(frozen=True, slots=True)
|
||||
class Agent: id: UUID; name: str # __hash__/__eq__ on id
|
||||
class Agent:
|
||||
id: UUID
|
||||
name: str # __hash__/__eq__ on id
|
||||
|
||||
|
||||
@dataclass(frozen=True, slots=True)
|
||||
class Message: id: UUID; sender: Agent; content: str; seq: int; ts: datetime
|
||||
class Message:
|
||||
id: UUID
|
||||
sender: Agent
|
||||
content: str
|
||||
seq: int
|
||||
ts: datetime
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class Thread: id: UUID; participants: frozenset[Agent]; created_at: datetime
|
||||
class Thread:
|
||||
id: UUID
|
||||
participants: frozenset[Agent]
|
||||
created_at: datetime
|
||||
```
|
||||
Changes from current:
|
||||
- Identity on `UUID`, not `name` (`core/agent.py:4` hashed on name is fragile).
|
||||
@@ -49,7 +61,7 @@ class Store(Protocol):
|
||||
def get_agent_by_name(self, name: str) -> Agent | None: ...
|
||||
def get_agent_by_id(self, id: UUID) -> Agent | None: ...
|
||||
def create_agent(self, name: str) -> Agent: ... # raises if name taken
|
||||
def delete_agent(self, id: UUID) -> None: ... # explicit, per user request
|
||||
def delete_agent(self, id: UUID) -> None: ... # explicit, per user request
|
||||
def list_agents(self) -> list[Agent]: ...
|
||||
|
||||
# threads
|
||||
@@ -61,7 +73,9 @@ class Store(Protocol):
|
||||
def delete_thread(self, id: UUID) -> None: ...
|
||||
|
||||
# messages / cursors
|
||||
def append_message(self, thread_id: UUID, sender: Agent, content: str) -> Message: ...
|
||||
def append_message(
|
||||
self, thread_id: UUID, sender: Agent, content: str
|
||||
) -> Message: ...
|
||||
def list_messages(self, thread_id: UUID, after_seq: int = 0) -> list[Message]: ...
|
||||
def get_cursor(self, thread_id: UUID, agent: Agent) -> int: ...
|
||||
def set_cursor(self, thread_id: UUID, agent: Agent, seq: int) -> None: ...
|
||||
@@ -72,10 +86,11 @@ Single `Store` keeps switch cost to one arg. It does **not** own business rules.
|
||||
|
||||
### 5.1 InMemoryStore (`stores/memory.py`)
|
||||
```python
|
||||
agents: dict[UUID, Agent]; name_idx: dict[str, UUID]
|
||||
agents: dict[UUID, Agent]
|
||||
name_idx: dict[str, UUID]
|
||||
threads: dict[UUID, Thread]
|
||||
messages: dict[UUID, list[Message]] # thread_id -> list
|
||||
cursors: dict[tuple[UUID,UUID], int]
|
||||
cursors: dict[tuple[UUID, UUID], int]
|
||||
```
|
||||
No locks. Used in unit tests.
|
||||
|
||||
@@ -118,15 +133,33 @@ All validation before Store mutation. Errors: `ValueError` (sender not in thread
|
||||
@dataclass
|
||||
class App:
|
||||
store: Store = field(default_factory=InMemoryStore)
|
||||
def get_or_create_agent(self, name): return ops.get_or_create_agent(self.store, name)
|
||||
def delete_account(self, agent_id): return ops.delete_agent(self.store, agent_id)
|
||||
def create_thread(self, *agents): return ops.create_thread(self.store, set(agents))
|
||||
def find_threads(self, *agents): return ops.find_threads(self.store, set(agents))
|
||||
def join_thread(self, tid, agent): return ops.join_thread(self.store, tid, agent)
|
||||
def append(self, tid, sender, content): return ops.append_message(self.store, tid, sender, content)
|
||||
def poll(self, tid, agent, after_seq=0): return ops.list_messages(self.store, tid, after_seq)
|
||||
def mark_read(self, tid, agent, seq): return ops.mark_read(self.store, tid, agent, seq)
|
||||
def has_unread(self, tid, agent, exclude_own=False): return ops.has_unread(self.store, tid, agent, exclude_own)
|
||||
|
||||
def get_or_create_agent(self, name):
|
||||
return ops.get_or_create_agent(self.store, name)
|
||||
|
||||
def delete_account(self, agent_id):
|
||||
return ops.delete_agent(self.store, agent_id)
|
||||
|
||||
def create_thread(self, *agents):
|
||||
return ops.create_thread(self.store, set(agents))
|
||||
|
||||
def find_threads(self, *agents):
|
||||
return ops.find_threads(self.store, set(agents))
|
||||
|
||||
def join_thread(self, tid, agent):
|
||||
return ops.join_thread(self.store, tid, agent)
|
||||
|
||||
def append(self, tid, sender, content):
|
||||
return ops.append_message(self.store, tid, sender, content)
|
||||
|
||||
def poll(self, tid, agent, after_seq=0):
|
||||
return ops.list_messages(self.store, tid, after_seq)
|
||||
|
||||
def mark_read(self, tid, agent, seq):
|
||||
return ops.mark_read(self.store, tid, agent, seq)
|
||||
|
||||
def has_unread(self, tid, agent, exclude_own=False):
|
||||
return ops.has_unread(self.store, tid, agent, exclude_own)
|
||||
```
|
||||
Current `add_thread`/`create_thread`/`add_thread_2`/`get_thread`/`find_thread` confusion collapsed to `create_thread`/`find_threads`/`get_thread`.
|
||||
|
||||
@@ -137,7 +170,8 @@ alice = app.get_or_create_agent("opencode-agent-123")
|
||||
bob = app.get_or_create_agent("codex-agent-456")
|
||||
t = app.create_thread(alice, bob)
|
||||
app.append(t.id, alice, "check thread.py:10")
|
||||
for m in app.poll(t.id, bob): print(m.content)
|
||||
for m in app.poll(t.id, bob):
|
||||
print(m.content)
|
||||
app.mark_read(t.id, bob, m.seq)
|
||||
app.join_thread(t.id, charlie)
|
||||
app.delete_account(alice.id) # explicit cleanup, no TTL
|
||||
|
||||
Reference in new issue
Block a user