Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions ai_sync/mcp_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
"""
from __future__ import annotations

import json

from . import collab, core

INSTRUCTIONS = (
Expand Down Expand Up @@ -62,7 +64,10 @@ def log(agent: str, project: str, summary: str, kind: str = "dev_log", files: st


def claim(agent: str, project: str, summary: str, files: str = "") -> str:
"""Claim files (comma-separated; empty = whole repo) before editing. Overlaps with other agents come back."""
"""Claim files (comma-separated; empty = whole repo) before editing. Returns JSON
{"claimed": true, "message": "<human sentence>", "overlaps": [{"agent", "project", "summary", "files"}]}
so a client can branch on overlaps without parsing prose; the human sentence is unchanged inside
"message", so a plain-text search for OVERLAP still finds it."""
try:
rep = collab.claim(_cfg(), agent=agent, project=project, summary=summary,
files=[f.strip() for f in files.split(",") if f.strip()])
Expand All @@ -72,7 +77,9 @@ def claim(agent: str, project: str, summary: str, files: str = "") -> str:
msg = f"claimed {project} {c['files'] or '[whole repo]'} until {c['expires'][11:16]}"
if rep["overlaps"]:
msg += "; OVERLAP with " + ", ".join(f"{o['agent']} ({o['summary']})" for o in rep["overlaps"]) + ": coordinate or pick other work"
return msg
return json.dumps({"claimed": True, "message": msg,
"overlaps": [{"agent": o["agent"], "project": o["project"], "summary": o["summary"],
"files": list(o.get("files") or [])} for o in rep["overlaps"]]})


def release(agent: str, project: str = "") -> str:
Expand Down
16 changes: 16 additions & 0 deletions tests/test_mcp_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import asyncio
import importlib.util
import json
import unittest

from ai_sync import core, mcp_server
Expand Down Expand Up @@ -44,6 +45,21 @@ def test_log_claim_overlap_release_news_status(self):
self.assertEqual(mcp_server.news("cursor", "m1"), "nothing new")
self.assertIn("claude-code", mcp_server.status())

def test_claim_returns_machine_readable_json(self):
self._truth()
rep = json.loads(mcp_server.claim("codex", "api", "SDK upgrade", "app/payments/"))
self.assertTrue(rep["claimed"])
self.assertEqual(rep["overlaps"], [])
self.assertIn("claimed api", rep["message"])
rep = json.loads(mcp_server.claim("claude-code", "api", "refunds", "app/payments/refunds.py"))
self.assertTrue(rep["claimed"])
self.assertEqual(len(rep["overlaps"]), 1)
self.assertEqual(rep["overlaps"][0]["agent"], "codex")
self.assertEqual(rep["overlaps"][0]["project"], "api")
self.assertEqual(rep["overlaps"][0]["summary"], "SDK upgrade")
self.assertIn("app/payments", rep["overlaps"][0]["files"][0])
self.assertIn("OVERLAP with codex", rep["message"])

def test_rule_add_via_fields_and_refusal(self):
self._truth()
out = mcp_server.rule_add("codex", "a contract changes", "ship a contract test", "最高优先级", "owner said",
Expand Down