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
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ aisync release -a codex -p api
| `wt` | a session's own git worktree: `wt start` opens it; `wt land` lands it on main and needs `--yes` (without it: a dry run) |
| `mcp` | serve the hub to any MCP agent over stdio (`pip install 'aisync-cli[mcp]'`) |
| `claim` / `release` / `claims` | who is working on which files right now; overlap = exit 3 |
| `news` | what other tools did since this session last looked |
| `news` | what other tools did since this session last looked (`--last N` shows the last N events on the first call) |
| `hook <tool>` | entry point for Claude Code, Codex and Cursor hooks (reads hook JSON, never fails) |
| `install-hooks` | wire the hooks, seed the rules block, add the git `Agent:` trailer hook; diff first, asks before writing (`--dry-run`, `--yes`) |
| `status` | health, conflicts, claims, blockers, metrics (exit 1 when something needs you) |
Expand Down Expand Up @@ -310,4 +310,3 @@ https://github.com/user-attachments/assets/bf661d5c-b7b1-4876-8469-2e11dd95b232


https://github.com/user-attachments/assets/d32f3abd-2986-4fbf-83a2-be287f0185a7

7 changes: 6 additions & 1 deletion ai_sync/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,11 @@ def cmd_news(a) -> int:
if not agent:
print("error: pass --agent (or set AISYNC_AGENT)", file=sys.stderr)
return 2
rep = hooks.news(core.load_config(), agent, a.session or "")
last = getattr(a, "last", 0)
if last < 0:
print("error: --last must be >= 0", file=sys.stderr)
return 2
rep = hooks.news(core.load_config(), agent, a.session or "", last=last)
text = hooks.news_text(rep)
print(text or ("cursor set; next call shows what changed after now" if rep["first"] else "nothing new"))
return 0
Expand Down Expand Up @@ -856,6 +860,7 @@ def build_parser() -> argparse.ArgumentParser:
s = sub.add_parser("news", help="what other tools did since this session last looked (first call sets the cursor)")
s.add_argument("--agent", "-a")
s.add_argument("--session", "-s", help="any stable id for this chat/session")
s.add_argument("--last", "-n", type=int, default=0, help="on the first call, also show the last N events from other agents")
s.set_defaults(fn=cmd_news)

s = sub.add_parser("hook", help="entry point for a tool's hook system (reads hook JSON on stdin, never fails)")
Expand Down
6 changes: 5 additions & 1 deletion ai_sync/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,13 @@ def _prune_cursors(cfg: core.Config) -> None:
pass


def news(cfg: core.Config, agent: str, session: str = "", init_only: bool = False) -> dict:
def news(cfg: core.Config, agent: str, session: str = "", init_only: bool = False, last: int = 0) -> dict:
"""New events from other agents + new shared rules since this session's cursor.

The first call of a session only sets the cursor (the session already loaded the full
progress page at start). `init_only` does the same on purpose (SessionStart hooks).
When `last > 0` on the first call (and not `init_only`), also return the last `last`
events from other agents before setting the cursor.
"""
events = core.read_events(cfg)
rules = _rules(cfg)
Expand All @@ -115,6 +117,8 @@ def news(cfg: core.Config, agent: str, session: str = "", init_only: bool = Fals
if "instincts" in cur and not ierr: # old cursors without the key: nothing to compare, say nothing
seen_inst = {_habit(l) for l in cur["instincts"]} # renumbering a line is not news
new_inst = [l for l in ilines if _habit(l) not in seen_inst]
elif cur is None and not init_only and last > 0:
fresh = [e for e in events if e.get("agent") != agent][-last:]
prev = cur or {}
keep = prev.get("instincts", ilines) if ierr else ilines # an unreadable file keeps what was seen
err_changed = bool(ierr) and ierr != prev.get("instincts_err", "") and cur is not None and not init_only
Expand Down
23 changes: 23 additions & 0 deletions tests/test_hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,29 @@ def test_long_news_is_capped(self):
text = hooks.news_text(hooks.news(self.cfg, "codex", "s"))
self.assertIn("(+5 older", text)

def test_first_call_with_last_returns_recent_other_agent_events(self):
core.append_event(self.cfg, agent="trae", kind="note", summary="t1")
core.append_event(self.cfg, agent="claude-code", kind="note", summary="mine")
core.append_event(self.cfg, agent="trae", kind="note", summary="t2")
core.append_event(self.cfg, agent="trae", kind="note", summary="t3")
rep = hooks.news(self.cfg, "claude-code", "s-last", last=2)
self.assertTrue(rep["first"])
self.assertEqual([e["summary"] for e in rep["events"]], ["t2", "t3"])
self.assertEqual(hooks.news(self.cfg, "claude-code", "s-last", last=2)["events"], [])

def test_cli_news_last_flag_and_negative_validation(self):
core.append_event(self.cfg, agent="trae", kind="note", summary="prior")
out = io.StringIO()
with contextlib.redirect_stdout(out):
code = cli.main(["news", "--agent", "claude-code", "--session", "s-cli", "--last", "1"])
self.assertEqual(code, 0)
self.assertIn("prior", out.getvalue())

err = io.StringIO()
with contextlib.redirect_stderr(err):
bad = cli.main(["news", "--agent", "claude-code", "--last", "-1"])
self.assertEqual(bad, 2)


class NewsSizeTests(Base):
"""2026-11-08: a rules slim re-announced every rule as NEW and injected 48.9 KB into each session."""
Expand Down