From c7a1381915249b924fd1a37ace04d57e99b76934 Mon Sep 17 00:00:00 2001 From: Shubhranil Layek Date: Tue, 1 Dec 2026 07:35:41 +0530 Subject: [PATCH] fix(log): refuse claim and release kinds, point to aisync claim/release `aisync log -k claim` wrote a journal line that looked like a claim while claiming nothing, so an agent that logged a claim was not protected. `log` now refuses `claim` and `release` with a message pointing to `aisync claim` / `aisync release`; the same refusal applies to the MCP `log` tool. The real commands still write those events. Closes #36 Signed-off-by: Shubhranil Layek --- ai_sync/cli.py | 1 + ai_sync/core.py | 8 ++++++++ ai_sync/mcp_server.py | 1 + tests/test_cli_basics.py | 12 ++++++++++++ tests/test_mcp_server.py | 13 +++++++++++++ 5 files changed, 35 insertions(+) diff --git a/ai_sync/cli.py b/ai_sync/cli.py index 53b4602..d190b07 100644 --- a/ai_sync/cli.py +++ b/ai_sync/cli.py @@ -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) diff --git a/ai_sync/core.py b/ai_sync/core.py index 687ff1c..32a9b7d 100644 --- a/ai_sync/core.py +++ b/ai_sync/core.py @@ -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() diff --git a/ai_sync/mcp_server.py b/ai_sync/mcp_server.py index 7edcf37..cdcf9e8 100644 --- a/ai_sync/mcp_server.py +++ b/ai_sync/mcp_server.py @@ -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: diff --git a/tests/test_cli_basics.py b/tests/test_cli_basics.py index 57e1d75..66a9fba 100644 --- a/tests/test_cli_basics.py +++ b/tests/test_cli_basics.py @@ -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): @@ -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)) diff --git a/tests/test_mcp_server.py b/tests/test_mcp_server.py index 494b25f..481aa96 100644 --- a/tests/test_mcp_server.py +++ b/tests/test_mcp_server.py @@ -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",