From 4b755f89a89e9763cfca67f444e00e98a8ee373e Mon Sep 17 00:00:00 2001 From: Kemal Codes <74741855+techkayacodes@users.noreply.github.com> Date: Mon, 16 Nov 2026 18:33:13 -0500 Subject: [PATCH 1/4] feat(news): support last=N events on first call in hooks.news --- ai_sync/hooks.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/ai_sync/hooks.py b/ai_sync/hooks.py index 3ce94b5..0251632 100644 --- a/ai_sync/hooks.py +++ b/ai_sync/hooks.py @@ -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) @@ -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 From bc3eb8f09cd22e089f43527b9fe0aa79d6345309 Mon Sep 17 00:00:00 2001 From: Kemal Codes <74741855+techkayacodes@users.noreply.github.com> Date: Mon, 16 Nov 2026 18:33:14 -0500 Subject: [PATCH 2/4] feat(cli): add --last/-n flag to aisync news --- ai_sync/cli.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/ai_sync/cli.py b/ai_sync/cli.py index f060d5f..53b4602 100644 --- a/ai_sync/cli.py +++ b/ai_sync/cli.py @@ -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 @@ -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)") From 3ca99f73689ba0c4a9c51b13f81c0c782e9b4cbf Mon Sep 17 00:00:00 2001 From: Kemal Codes <74741855+techkayacodes@users.noreply.github.com> Date: Mon, 16 Nov 2026 18:33:15 -0500 Subject: [PATCH 3/4] docs(readme): document --last N flag for aisync news --- README.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/README.md b/README.md index faede41..83a8408 100644 --- a/README.md +++ b/README.md @@ -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 ` | 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) | @@ -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 - From dc8adb51a050f79bc814afe73b5c2b11dad80d61 Mon Sep 17 00:00:00 2001 From: Kemal Codes <74741855+techkayacodes@users.noreply.github.com> Date: Mon, 16 Nov 2026 18:33:16 -0500 Subject: [PATCH 4/4] test(hooks): cover aisync news --last N on first call --- tests/test_hooks.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/tests/test_hooks.py b/tests/test_hooks.py index 5634fbd..c200a02 100644 --- a/tests/test_hooks.py +++ b/tests/test_hooks.py @@ -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."""