mirror of
https://github.com/shareAI-lab/analysis_claude_code.git
synced 2026-09-20 12:13:38 +08:00
Merge pull request #233 from Mr-JingShi/main
refactor: enhance MessageBus.read_inbox with clear parameter
This commit is contained in:
@@ -97,7 +97,7 @@ class MessageBus:
|
|||||||
f.write(json.dumps(msg) + "\n")
|
f.write(json.dumps(msg) + "\n")
|
||||||
return f"Sent {msg_type} to {to}"
|
return f"Sent {msg_type} to {to}"
|
||||||
|
|
||||||
def read_inbox(self, name: str) -> list:
|
def read_inbox(self, name: str, clear: bool = True) -> list:
|
||||||
inbox_path = self.dir / f"{name}.jsonl"
|
inbox_path = self.dir / f"{name}.jsonl"
|
||||||
if not inbox_path.exists():
|
if not inbox_path.exists():
|
||||||
return []
|
return []
|
||||||
@@ -105,7 +105,8 @@ class MessageBus:
|
|||||||
for line in inbox_path.read_text().strip().splitlines():
|
for line in inbox_path.read_text().strip().splitlines():
|
||||||
if line:
|
if line:
|
||||||
messages.append(json.loads(line))
|
messages.append(json.loads(line))
|
||||||
inbox_path.write_text("")
|
if clear:
|
||||||
|
inbox_path.write_text("")
|
||||||
return messages
|
return messages
|
||||||
|
|
||||||
def broadcast(self, sender: str, content: str, teammates: list) -> str:
|
def broadcast(self, sender: str, content: str, teammates: list) -> str:
|
||||||
@@ -348,7 +349,7 @@ def agent_loop(messages: list):
|
|||||||
if inbox:
|
if inbox:
|
||||||
messages.append({
|
messages.append({
|
||||||
"role": "user",
|
"role": "user",
|
||||||
"content": f"<inbox>{json.dumps(inbox, indent=2)}</inbox>",
|
"content": f"<inbox>{json.dumps(inbox)}</inbox>",
|
||||||
})
|
})
|
||||||
response = client.messages.create(
|
response = client.messages.create(
|
||||||
model=MODEL,
|
model=MODEL,
|
||||||
@@ -391,7 +392,7 @@ if __name__ == "__main__":
|
|||||||
print(TEAM.list_all())
|
print(TEAM.list_all())
|
||||||
continue
|
continue
|
||||||
if query.strip() == "/inbox":
|
if query.strip() == "/inbox":
|
||||||
print(json.dumps(BUS.read_inbox("lead"), indent=2))
|
print(json.dumps(BUS.read_inbox("lead", False), indent=2))
|
||||||
continue
|
continue
|
||||||
history.append({"role": "user", "content": query})
|
history.append({"role": "user", "content": query})
|
||||||
agent_loop(history)
|
agent_loop(history)
|
||||||
|
|||||||
@@ -107,7 +107,7 @@ class MessageBus:
|
|||||||
f.write(json.dumps(msg) + "\n")
|
f.write(json.dumps(msg) + "\n")
|
||||||
return f"Sent {msg_type} to {to}"
|
return f"Sent {msg_type} to {to}"
|
||||||
|
|
||||||
def read_inbox(self, name: str) -> list:
|
def read_inbox(self, name: str, clear: bool = True) -> list:
|
||||||
inbox_path = self.dir / f"{name}.jsonl"
|
inbox_path = self.dir / f"{name}.jsonl"
|
||||||
if not inbox_path.exists():
|
if not inbox_path.exists():
|
||||||
return []
|
return []
|
||||||
@@ -115,7 +115,8 @@ class MessageBus:
|
|||||||
for line in inbox_path.read_text().strip().splitlines():
|
for line in inbox_path.read_text().strip().splitlines():
|
||||||
if line:
|
if line:
|
||||||
messages.append(json.loads(line))
|
messages.append(json.loads(line))
|
||||||
inbox_path.write_text("")
|
if clear:
|
||||||
|
inbox_path.write_text("")
|
||||||
return messages
|
return messages
|
||||||
|
|
||||||
def broadcast(self, sender: str, content: str, teammates: list) -> str:
|
def broadcast(self, sender: str, content: str, teammates: list) -> str:
|
||||||
@@ -429,7 +430,7 @@ def agent_loop(messages: list):
|
|||||||
if inbox:
|
if inbox:
|
||||||
messages.append({
|
messages.append({
|
||||||
"role": "user",
|
"role": "user",
|
||||||
"content": f"<inbox>{json.dumps(inbox, indent=2)}</inbox>",
|
"content": f"<inbox>{json.dumps(inbox)}</inbox>",
|
||||||
})
|
})
|
||||||
response = client.messages.create(
|
response = client.messages.create(
|
||||||
model=MODEL,
|
model=MODEL,
|
||||||
@@ -472,7 +473,7 @@ if __name__ == "__main__":
|
|||||||
print(TEAM.list_all())
|
print(TEAM.list_all())
|
||||||
continue
|
continue
|
||||||
if query.strip() == "/inbox":
|
if query.strip() == "/inbox":
|
||||||
print(json.dumps(BUS.read_inbox("lead"), indent=2))
|
print(json.dumps(BUS.read_inbox("lead", False), indent=2))
|
||||||
continue
|
continue
|
||||||
history.append({"role": "user", "content": query})
|
history.append({"role": "user", "content": query})
|
||||||
agent_loop(history)
|
agent_loop(history)
|
||||||
|
|||||||
@@ -100,7 +100,7 @@ class MessageBus:
|
|||||||
f.write(json.dumps(msg) + "\n")
|
f.write(json.dumps(msg) + "\n")
|
||||||
return f"Sent {msg_type} to {to}"
|
return f"Sent {msg_type} to {to}"
|
||||||
|
|
||||||
def read_inbox(self, name: str) -> list:
|
def read_inbox(self, name: str, clear: bool = True) -> list:
|
||||||
inbox_path = self.dir / f"{name}.jsonl"
|
inbox_path = self.dir / f"{name}.jsonl"
|
||||||
if not inbox_path.exists():
|
if not inbox_path.exists():
|
||||||
return []
|
return []
|
||||||
@@ -108,7 +108,8 @@ class MessageBus:
|
|||||||
for line in inbox_path.read_text().strip().splitlines():
|
for line in inbox_path.read_text().strip().splitlines():
|
||||||
if line:
|
if line:
|
||||||
messages.append(json.loads(line))
|
messages.append(json.loads(line))
|
||||||
inbox_path.write_text("")
|
if clear:
|
||||||
|
inbox_path.write_text("")
|
||||||
return messages
|
return messages
|
||||||
|
|
||||||
def broadcast(self, sender: str, content: str, teammates: list) -> str:
|
def broadcast(self, sender: str, content: str, teammates: list) -> str:
|
||||||
@@ -142,11 +143,9 @@ def claim_task(task_id: int, owner: str) -> str:
|
|||||||
if not path.exists():
|
if not path.exists():
|
||||||
return f"Error: Task {task_id} not found"
|
return f"Error: Task {task_id} not found"
|
||||||
task = json.loads(path.read_text())
|
task = json.loads(path.read_text())
|
||||||
if task.get("owner"):
|
if existing_owner := task.get("owner"):
|
||||||
existing_owner = task.get("owner") or "someone else"
|
|
||||||
return f"Error: Task {task_id} has already been claimed by {existing_owner}"
|
return f"Error: Task {task_id} has already been claimed by {existing_owner}"
|
||||||
if task.get("status") != "pending":
|
if (status := task.get("status")) != "pending":
|
||||||
status = task.get("status")
|
|
||||||
return f"Error: Task {task_id} cannot be claimed because its status is '{status}'"
|
return f"Error: Task {task_id} cannot be claimed because its status is '{status}'"
|
||||||
if task.get("blockedBy"):
|
if task.get("blockedBy"):
|
||||||
return f"Error: Task {task_id} is blocked by other task(s) and cannot be claimed yet"
|
return f"Error: Task {task_id} is blocked by other task(s) and cannot be claimed yet"
|
||||||
@@ -523,7 +522,7 @@ def agent_loop(messages: list):
|
|||||||
if inbox:
|
if inbox:
|
||||||
messages.append({
|
messages.append({
|
||||||
"role": "user",
|
"role": "user",
|
||||||
"content": f"<inbox>{json.dumps(inbox, indent=2)}</inbox>",
|
"content": f"<inbox>{json.dumps(inbox)}</inbox>",
|
||||||
})
|
})
|
||||||
response = client.messages.create(
|
response = client.messages.create(
|
||||||
model=MODEL,
|
model=MODEL,
|
||||||
@@ -566,7 +565,7 @@ if __name__ == "__main__":
|
|||||||
print(TEAM.list_all())
|
print(TEAM.list_all())
|
||||||
continue
|
continue
|
||||||
if query.strip() == "/inbox":
|
if query.strip() == "/inbox":
|
||||||
print(json.dumps(BUS.read_inbox("lead"), indent=2))
|
print(json.dumps(BUS.read_inbox("lead", False), indent=2))
|
||||||
continue
|
continue
|
||||||
if query.strip() == "/tasks":
|
if query.strip() == "/tasks":
|
||||||
TASKS_DIR.mkdir(exist_ok=True)
|
TASKS_DIR.mkdir(exist_ok=True)
|
||||||
|
|||||||
Reference in New Issue
Block a user