system-diff 0.4.2__py3-none-any.whl → 0.4.3__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
system_diff/__init__.py CHANGED
@@ -5,4 +5,4 @@
5
5
  bp = extract.extract(DirSource(Path(".")), cfg)
6
6
  svg = graph.system_svg(bp, cfg)
7
7
  """
8
- __version__ = "0.4.2"
8
+ __version__ = "0.4.3"
system_diff/agent.py CHANGED
@@ -137,30 +137,36 @@ def on_prompt(root: Path, payload: Dict[str, Any]) -> Optional[Dict[str, str]]:
137
137
 
138
138
 
139
139
  def on_tool(root: Path, payload: Dict[str, Any]) -> Optional[Dict[str, str]]:
140
- """Note the file and keep a brief of its part for the status line. After an edit to code, look at what the turn
141
- has done to the system so far, and say what this edit added to it (one hook at a time: they can overlap)."""
140
+ """After every tool: hand the agent what other agents published since its last tool. For a read or an edit of
141
+ a file in a part, also note the file and keep a brief of its part for the status line; after an edit to code,
142
+ look at what the turn has done to the system so far, and say what this edit added to it (one hook at a time:
143
+ they can overlap)."""
142
144
  tool = payload.get("tool_name", "")
145
+ agent_id = payload.get("agent_id") or ""
146
+
147
+ def unread() -> Dict[str, Any]:
148
+ return {"message": None, "context": agents.deliver(root, agent_id)}
149
+
143
150
  if tool not in EDIT_TOOLS + READ_TOOLS:
144
- return None
151
+ return unread()
145
152
  given = payload.get("tool_input") or {}
146
153
  path = activity.relative(root, given.get("file_path") or given.get("notebook_path") or "")
147
154
  if not path:
148
- return None
155
+ return unread()
149
156
  edit = tool in EDIT_TOOLS
150
- agent_id = payload.get("agent_id") or ""
151
157
  activity.record(root, {"event": activity.EDIT if edit else activity.READ, "path": path, "tool": tool,
152
158
  "session": payload.get("session_id", ""), "agent": agent_id})
153
159
  cfg = config.lenient(root)
154
160
  part = activity.part_of(path, Code(cfg))
155
161
  if part is None:
156
- return None
162
+ return unread()
157
163
  if not activity.load_brief(root, part, max_age=600):
158
164
  activity.save_brief(root, learn.brief(root, cfg, part))
159
165
  if not (edit and turn_sha(root)):
160
- return None
166
+ return unread()
161
167
  with activity.only_one(root, wait=10) as mine:
162
168
  if not mine:
163
- return None
169
+ return unread()
164
170
  last = activity.read_state(root).get("turn") or {}
165
171
  before = last.get("told") or [s["text"] for s in last.get("story") or []]
166
172
  since, turn = compare_worktree(root, ["checkpoint", "turn"])
@@ -246,12 +252,12 @@ HOOKS = ( # event, matcher, how it runs, what it does
246
252
  "WezTerm, kitty, Windows Terminal)"),
247
253
  ("UserPromptSubmit", None, {"timeout": 10},
248
254
  "marks where each turn starts, and asks Claude to plan the work for a team of agents"),
249
- ("PostToolUse", "|".join(READ_TOOLS), {"async": True},
250
- "notes the files Claude reads, for the terminal view and the status line (in the background)"),
251
- # Not in the background: only a hook Claude Code waits for can show you a line in the conversation. A timeout
252
- # (seconds) so a stuck git never holds up the agent; Claude Code's own default is 600.
253
- ("PostToolUse", "|".join(EDIT_TOOLS), {"timeout": 15},
254
- "after an edit that changes the system's structure, one line on what it changed and why it matters"),
255
+ # One entry for every tool, and not in the background: only a hook Claude Code waits for can show you a line in
256
+ # the conversation or hand the agent its messages. A timeout (seconds) so a stuck git never holds up the agent;
257
+ # Claude Code's own default is 600.
258
+ ("PostToolUse", None, {"timeout": 15},
259
+ "notes the files Claude reads and, after an edit that changes the system's structure, one line on what it "
260
+ "changed; and hands each agent what other agents published"),
255
261
  ("Stop", None, {"timeout": 30}, "after each turn, one line on what the turn changed in the system"),
256
262
  )
257
263
 
system_diff/agents.py CHANGED
@@ -2,7 +2,7 @@
2
2
  CLAIMS, so agents keep to their own blocks; and a BUS, an async publish/subscribe channel whose topics are the system's
3
3
  blocks: an agent subscribes to the blocks its own depend on, every structural change to a block is published on that
4
4
  block's topic (by the hooks, as it happens), agents publish their own notes too, and each agent's unread messages
5
- reach it with its next tool call, without waiting on anyone.
5
+ reach it with its next tool result of any kind, without waiting on anyone.
6
6
 
7
7
  Who is who: Claude Code names each subagent by an id (`agent_id` in its hook events; the main conversation has none,
8
8
  "main" here). A plan names agents by area ("billing"); an id is tied to a name when it first edits a block that name
@@ -65,6 +65,10 @@ def tie(root: Path, agent_id: str, name: str) -> None:
65
65
  data = _load(root)
66
66
  if data["ids"].get(agent_id) != name:
67
67
  data["ids"][agent_id] = name
68
+ short = data["agents"].get("agent-" + agent_id[:6]) # what it read before it had a name stays read
69
+ if short:
70
+ a = _agent(data, name)
71
+ a["read"] = max(a["read"], short["read"])
68
72
  _save(root, data)
69
73
 
70
74
 
@@ -163,6 +167,20 @@ def as_context(msgs: List[Dict[str, Any]], most: int = 8) -> str:
163
167
 
164
168
  # ── what the hooks do for each agent ─────────────────────────────────────────
165
169
 
170
+ def _for_context(msgs: List[Dict[str, Any]]) -> List[Dict[str, Any]]:
171
+ """The messages worth putting in an agent's context: spread warnings reach the agent they are about directly; on
172
+ the bus they are a record for the inbox tool."""
173
+ return [m for m in msgs if not (m.get("from") == SYSTEM and m.get("kind") == "warning")]
174
+
175
+
176
+ def deliver(root: Path, agent_id: str) -> str:
177
+ """The unread messages for the agent with this Claude Code id ("" or "main": the main conversation), as context
178
+ text, marked read; "" without writing anything when there is no bus yet."""
179
+ if not (git_dir(root) / BUS).exists():
180
+ return ""
181
+ return as_context(_for_context(inbox(root, name_of(root, agent_id))))
182
+
183
+
166
184
  def after_edit(root: Path, agent_id: str, part: Optional[str], notes: List[Dict[str, Any]], bp: dict) -> Dict[str, str]:
167
185
  """After an agent's edit: tie it to a plan name if it edited a claimed block nobody else is tied to, subscribe it
168
186
  to its block and the blocks that block depends on, publish what the edit changed in the structure on the topics
@@ -186,8 +204,7 @@ def after_edit(root: Path, agent_id: str, part: Optional[str], notes: List[Dict[
186
204
  publish(root, f"agent:{claimed}", f"{name} edited your block {part}", sender=name, kind="warning")
187
205
  from . import config
188
206
  wide = spread(root, name, agent_id, bp, config.lenient(root))
189
- # spread warnings reach the agent they are about directly; on the bus they are a record for the inbox tool
190
- unread = [m for m in inbox(root, name) if not (m.get("from") == SYSTEM and m.get("kind") == "warning")]
207
+ unread = _for_context(inbox(root, name))
191
208
  context = "\n".join(t for t in (as_context(unread), wide) if t)
192
209
  warn = "; ".join(t for t in (warn, wide) if t)
193
210
  return {"context": context, "warn": warn, "name": name}
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: system-diff
3
- Version: 0.4.2
3
+ Version: 0.4.3
4
4
  Summary: Draws your system from its code (parts, entry points, data, outside systems) and what each change adds, changes or removes. No dependencies; SVG pictures for PRs and READMEs.
5
5
  Project-URL: Homepage, https://github.com/simplifiedmachine/system-diff
6
6
  Project-URL: Documentation, https://github.com/simplifiedmachine/system-diff/wiki
@@ -132,8 +132,8 @@ Claude does most work alone unless asked otherwise, so system-diff asks it to pl
132
132
  - **The bus:** an async publish/subscribe channel whose topics are the blocks. Each agent follows the blocks its own
133
133
  depend on. Every change an agent makes to a block's structure is published on that block's topic as it happens
134
134
  ("API no longer answers DELETE /orders/{id}"), with why it matters. Agents publish their own notes with `publish`
135
- (to a block, to "all", or to "agent:<name>"). Each agent's unread messages reach it with its next tool result:
136
- nobody waits on anybody.
135
+ (to a block, to "all", or to "agent:<name>"). Each agent's unread messages reach it with its next tool result
136
+ of any kind (a read, an edit, a shell command, a search), once: nobody waits on anybody.
137
137
  - **Claims:** `claim` gives an agent its blocks. An edit to someone else's block is published to its owner and shown
138
138
  under Needs your attention.
139
139
  - **One agent, one area:** when an agent (the main conversation included) edits blocks in two or more areas in one
@@ -146,6 +146,8 @@ The MCP tools: `plan_agents`, `claim`, `publish`, `subscribe`, `inbox`, `team`.
146
146
 
147
147
  - **After an edit that changes the system's structure**, one line under it: "System diff: API now answers GET
148
148
  /health · a new way in: it needs the same checks as the others". Edits that change no structure stay quiet.
149
+ - **Messages from other agents** on the bus arrive with an agent's next tool result of any kind, not only after
150
+ an edit.
149
151
  - **At the end of each turn**, one line on what the turn did to the system, or which parts it edited when the
150
152
  structure stayed the same; nothing for a turn that only talked.
151
153
  - **Ask Claude** "what is the API part?" or "what does this change do?": the MCP server gives it `explain` (the facts
@@ -1,8 +1,8 @@
1
- system_diff/__init__.py,sha256=fKOVXpF3wt-lOcTcNVQIPxe_htHnXkVHWRPHX1wALbQ,289
1
+ system_diff/__init__.py,sha256=XaH9qfWrS8LT8cC44SiWEtSy3WiWkl6e5IenH0uQhVI,289
2
2
  system_diff/__main__.py,sha256=E6Gls0DNz8GQK2K-kOUIx8cYhgANW_CH54VKrfCfs14,52
3
3
  system_diff/activity.py,sha256=lq5_U-Ulz-mrMALSU8bGB0O4EQHBudSjL8dGALZXxaE,11851
4
- system_diff/agent.py,sha256=3GFqgPLs4-MUgtg0Fob57QA-QN-MJgInv2K7Y6AZ-EE,23382
5
- system_diff/agents.py,sha256=PiaXDL_t-bY0nQLSu9n-uh2asdQlwK3eGhPOTSn2UWg,17546
4
+ system_diff/agent.py,sha256=zVJEyR7jUbwWYSYdsCDS8BAXlDoZYqUPdadIOuDqJk4,23618
5
+ system_diff/agents.py,sha256=RE9B7qu1dlomHis7OREq7BPLTLA3PcXFLFHX3UpvBpc,18333
6
6
  system_diff/architecture.py,sha256=P3Xln9LmdBziQim12KYQKsxLJKesZAHR_F73U-BqwCs,18165
7
7
  system_diff/canvas.py,sha256=P3TvtSv1p3WEp-SbLfQSff1ttR0x7M-Tiy_Ow_Z4w5M,25695
8
8
  system_diff/cli.py,sha256=az2C90_uHcPkWUO_6-s8M73jgwfWSyeWD8BQsOLD9Ys,16478
@@ -29,8 +29,8 @@ system_diff/textmap.py,sha256=tVUywzuwxcGscLbUy-2etTRq-966kIFuxUDeF1e-lgE,15008
29
29
  system_diff/topics.py,sha256=2vbPccf5-jENBLb-P45KZsmaouODglZODYkabwzUXqM,21847
30
30
  system_diff/tui.py,sha256=H5jdM3suzgMUBnq2oi5dSOvul2mZTY0bjP3i5iVkgAc,17756
31
31
  system_diff/watch.py,sha256=ec3u_YBvfaSVsCXdqd_nDKAKWZzJvKLJm37VMpq6SFo,17066
32
- system_diff-0.4.2.dist-info/METADATA,sha256=XNsvSaLEGZ93rVehHu17Xc6-Hsq50pMFHJPXDRkKtNE,13352
33
- system_diff-0.4.2.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
34
- system_diff-0.4.2.dist-info/entry_points.txt,sha256=8fw6tkuFfZI2L7ScWUXVxj28LK9p6UiImnnB8E1om1E,84
35
- system_diff-0.4.2.dist-info/licenses/LICENSE,sha256=QHQ-0t-7_4_K7j92CTlQScHiJiDZ91DcpV6WIOIFYQE,1074
36
- system_diff-0.4.2.dist-info/RECORD,,
32
+ system_diff-0.4.3.dist-info/METADATA,sha256=iVRnTnrX1owqXcV3Z5Pf4tBumoSqVvvduNb7vy4KgKw,13538
33
+ system_diff-0.4.3.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
34
+ system_diff-0.4.3.dist-info/entry_points.txt,sha256=8fw6tkuFfZI2L7ScWUXVxj28LK9p6UiImnnB8E1om1E,84
35
+ system_diff-0.4.3.dist-info/licenses/LICENSE,sha256=QHQ-0t-7_4_K7j92CTlQScHiJiDZ91DcpV6WIOIFYQE,1074
36
+ system_diff-0.4.3.dist-info/RECORD,,