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
1 change: 1 addition & 0 deletions ai_sync/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ def cmd_log(a) -> int:
refs = dict(r.split("=", 1) for r in a.ref or [] if "=" in r)
files = [f.strip() for f in (a.files or "").split(",") if f.strip()]
try:
core.check_log_kind(a.kind)
ev = core.append_event(core.load_config(), agent=a.agent or os.environ.get("AISYNC_AGENT", ""),
kind=a.kind, summary=a.summary, project=a.project or _default_project(),
files=files, refs=refs)
Expand Down
8 changes: 8 additions & 0 deletions ai_sync/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,14 @@ def read_events(cfg: Config) -> list[dict]:
return out


def check_log_kind(kind: str) -> None:
"""`log` records plain journal lines only: claim/release events are written by
`aisync claim` / `aisync release` themselves, so logging one would only
pretend to claim or release."""
if kind in ("claim", "release"):
raise ValueError(f"log cannot record a {kind}: use `aisync {kind}` instead")


def append_event(cfg: Config, *, agent: str, kind: str, summary: str, project: str = "",
files=(), refs: dict | None = None, ts: str | None = None) -> dict:
agent, summary = (agent or "").strip(), (summary or "").strip()
Expand Down
1 change: 1 addition & 0 deletions ai_sync/mcp_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ def rule_add(agent: str, when: str, do: str, topic: str, reason: str, not_: str
def log(agent: str, project: str, summary: str, kind: str = "dev_log", files: str = "") -> str:
"""Append one event to the journal (kinds: dev_log, decision, blocked, unblocked, rule_change, note)."""
try:
core.check_log_kind(kind)
ev = core.append_event(_cfg(), agent=agent, kind=kind, project=project, summary=summary,
files=[f.strip() for f in files.split(",") if f.strip()])
except ValueError as ex:
Expand Down
12 changes: 12 additions & 0 deletions tests/test_cli_basics.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from unittest import mock

from ai_sync import __version__, cli, update
from test_ai_sync import Base


def run_cli(*argv):
Expand Down Expand Up @@ -51,6 +52,17 @@ def test_unknown_topic_is_an_error_with_exit_2(self):
self.assertIn("no such command: nope", text)


class LogKindTests(Base):
def test_log_refuses_claim_and_release(self):
for kind in ("claim", "release"):
code, text = run_cli("log", "-a", "codex", "-p", "api", "-k", kind, "-m", "x")
self.assertEqual(code, 2)
self.assertIn(f"aisync {kind}", text)
code, text = run_cli("log", "-a", "codex", "-p", "api", "-m", "plain line")
self.assertEqual(code, 0)
self.assertIn("logged", text)


class UpdateTests(unittest.TestCase):
def test_parse_version_accepts_plain_and_v_prefix_only(self):
self.assertEqual(update.parse_version("v0.2.5"), (0, 2, 5))
Expand Down
13 changes: 13 additions & 0 deletions tests/test_mcp_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,19 @@ 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_log_refuses_claim_and_release_kinds(self):
self._truth()
for kind in ("claim", "release"):
out = mcp_server.log("codex", "api", "x", kind=kind)
self.assertTrue(out.startswith("refused"), out)
self.assertIn(f"aisync {kind}", out)
kinds = {e["kind"] for e in core.read_events(self.cfg)}
self.assertNotIn("claim", kinds)
self.assertNotIn("release", kinds)
# the real commands still write those events
self.assertIn("claimed api", mcp_server.claim("codex", "api", "SDK upgrade", "app/payments/"))
self.assertEqual(mcp_server.release("codex", "api"), "released 1 claim(s)")

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