system-diff 0.4.0__py3-none-any.whl → 0.4.2__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.0"
8
+ __version__ = "0.4.2"
system_diff/agents.py CHANGED
@@ -24,6 +24,7 @@ from .sources import git_dir
24
24
 
25
25
  STATE, BUS = "agents.json", "bus.jsonl"
26
26
  MAIN = "main"
27
+ SYSTEM = "system-diff" # the sender of what system-diff itself publishes
27
28
  KEEP = 2000 # messages kept on the bus
28
29
  MOST_AGENTS = 4 # a plan's agents at most, unless asked for more
29
30
 
@@ -33,10 +34,11 @@ def _load(root: Path) -> Dict[str, Any]:
33
34
  data = json.loads((git_dir(root) / STATE).read_text(encoding="utf-8"))
34
35
  if isinstance(data, dict):
35
36
  return {"plan": data.get("plan") or {}, "claims": data.get("claims") or {},
36
- "agents": data.get("agents") or {}, "ids": data.get("ids") or {}}
37
+ "agents": data.get("agents") or {}, "ids": data.get("ids") or {},
38
+ "warned": data.get("warned") or {}}
37
39
  except (OSError, ValueError):
38
40
  pass
39
- return {"plan": {}, "claims": {}, "agents": {}, "ids": {}}
41
+ return {"plan": {}, "claims": {}, "agents": {}, "ids": {}, "warned": {}}
40
42
 
41
43
 
42
44
  def _save(root: Path, data: Dict[str, Any]) -> None:
@@ -182,7 +184,60 @@ def after_edit(root: Path, agent_id: str, part: Optional[str], notes: List[Dict[
182
184
  if part and claimed and claimed != name:
183
185
  warn = f"{part} is claimed by agent {claimed}; {name} just edited it"
184
186
  publish(root, f"agent:{claimed}", f"{name} edited your block {part}", sender=name, kind="warning")
185
- return {"context": as_context(inbox(root, name)), "warn": warn, "name": name}
187
+ from . import config
188
+ 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")]
191
+ context = "\n".join(t for t in (as_context(unread), wide) if t)
192
+ warn = "; ".join(t for t in (warn, wide) if t)
193
+ return {"context": context, "warn": warn, "name": name}
194
+
195
+
196
+ def areas_of(root: Path, bp: dict, cfg: Dict[str, Any]) -> Dict[str, str]:
197
+ """Each block's area: the agent the saved plan gave it to, when there is a plan; else its container, or the
198
+ block itself when it is in none."""
199
+ agents = (_load(root)["plan"] or {}).get("agents") or []
200
+ if agents:
201
+ return {b: g["name"] for g in agents for b in g.get("blocks") or []}
202
+ from .architecture import groups_of
203
+ group = groups_of(bp, cfg, design.kinds(bp, cfg))
204
+ return {cid: (group[cid][2:] if group.get(cid, "").startswith("g:") else cid) for cid in bp["components"]}
205
+
206
+
207
+ def spread(root: Path, name: str, agent_id: str, bp: dict, cfg: Dict[str, Any]) -> str:
208
+ """When one agent has edited blocks in two or more areas this turn: a message telling it to plan a team and hand
209
+ the rest on, once per agent per turn (also published to all); else ""."""
210
+ from .extract import Code
211
+ code = Code(cfg)
212
+ me = "" if agent_id in ("", None, MAIN) else agent_id
213
+ start, parts = 0.0, []
214
+ for e in activity.events(root, 400):
215
+ if e.get("event") == activity.PROMPT and not activity.is_system(e.get("text", "")):
216
+ start, parts = e["at"], []
217
+ elif e.get("event") == activity.EDIT and (e.get("agent") or "") == me and e.get("path"):
218
+ part = activity.part_of(e["path"], code)
219
+ if part and part not in parts:
220
+ parts.append(part)
221
+ area = areas_of(root, bp, cfg)
222
+ seen: List[str] = []
223
+ for p in parts:
224
+ a = area.get(p, p)
225
+ if a not in seen:
226
+ seen.append(a)
227
+ if len(seen) < 2:
228
+ return ""
229
+ data = _load(root)
230
+ turn = str(start)
231
+ told = data["warned"].get(turn) or []
232
+ if name in told:
233
+ return ""
234
+ data["warned"] = {turn: told + [name]} # only the latest turn is kept
235
+ _save(root, data)
236
+ text = (f"{name} has edited blocks in {len(seen)} areas this turn ({', '.join(seen)}). system-diff runs work "
237
+ "that spans areas as a team: call plan_agents with what is left, launch its agents in parallel, and "
238
+ "keep to one area yourself.")
239
+ publish(root, "all", text, sender=SYSTEM, kind="warning")
240
+ return text
186
241
 
187
242
 
188
243
  def who_worked(events: Iterable[dict], code) -> Dict[str, Dict[str, Any]]:
system_diff/canvas.py CHANGED
@@ -138,8 +138,12 @@ def title_style(n: dict) -> str:
138
138
  return f"title bold {st}" if st != "same" else "title"
139
139
 
140
140
 
141
+ ZOOMS = {0: (20, 32, 2, 6, 4), 1: (12, 22, 0, 5, 3), 2: (8, 16, 0, 5, 3)} # min box, max box, rows, channel, gap
142
+ # by zoom: full, compact, tiny
143
+
144
+
141
145
  def layered(nodes: List[dict], edges: List[dict], columns: List[Sequence[str]], *, width: int = 100,
142
- centre: bool = False, most_lines: int = 2) -> Grid:
146
+ centre: bool = False, most_lines: int = 2, zoom: int = 0) -> Grid:
143
147
  """A system diagram: `nodes` (id, col, title, sub, status, type: actor|component|group|store|host; `agent` where
144
148
  the agent works, `focus` for the box zoomed in on, `items` for the components a container holds, `lines` for
145
149
  rows inside a box) in `columns` order, joined by `edges` (from, to, kind, status, label; `from_item`/`to_item`:
@@ -150,6 +154,12 @@ def layered(nodes: List[dict], edges: List[dict], columns: List[Sequence[str]],
150
154
  present = [k for k, _h in columns if any(n["col"] == k for n in nodes)]
151
155
  if not present:
152
156
  return g
157
+ least, most_w, rows_in, chan_min, chan_pad = ZOOMS.get(zoom, ZOOMS[0])
158
+ most_lines = min(most_lines, rows_in)
159
+ if zoom: # compact: no labels on flows (a picked box's detail names them), tiny: no subtitles either
160
+ edges = [{**e, "label": ""} for e in edges]
161
+ if zoom >= 2:
162
+ nodes = [{**n, "sub": ""} for n in nodes]
153
163
  heading = {k: h for k, h in columns}
154
164
  ci = {k: i for i, k in enumerate(present)}
155
165
  col_nodes = [[n for n in nodes if n["col"] == k] for k in present]
@@ -181,13 +191,13 @@ def layered(nodes: List[dict], edges: List[dict], columns: List[Sequence[str]],
181
191
  item_row = {it["id"]: (n["id"], 3 + j) for n in nodes for j, it in enumerate(n.get("items") or [])}
182
192
 
183
193
  # widths: as wide as the longest row wants, narrowed together when the whole is wider than the pane
184
- want = [min(32, max([len(t) + 4 for n in col for t, _s, _b in contents[n["id"]][:1]]
185
- + [len(t) + 4 for n in col for t, _s, _b in contents[n["id"]][2:]]
186
- + [len(heading[present[i]]) + 1, 14]))
194
+ want = [min(most_w, max([len(t) + 4 for n in col for t, _s, _b in contents[n["id"]][:1]]
195
+ + [len(t) + 4 for n in col for t, _s, _b in contents[n["id"]][2:]]
196
+ + [min(len(heading[present[i]]) + 1, most_w), least]))
187
197
  for i, col in enumerate(col_nodes)]
188
198
  label_w = max([len(e.get("label") or "") for e in edges] + [0])
189
- gaps = (8 + label_w) * len(present)
190
- while sum(want) + gaps > width and max(want) > 20:
199
+ gaps = (chan_min + 2 + label_w) * len(present)
200
+ while sum(want) + gaps > width and max(want) > least:
191
201
  biggest = max(range(len(want)), key=lambda i: want[i])
192
202
  want[biggest] -= 1
193
203
  heights = {n["id"]: 2 + len(contents[n["id"]]) for n in nodes}
@@ -320,7 +330,7 @@ def layered(nodes: List[dict], edges: List[dict], columns: List[Sequence[str]],
320
330
  if e.get("label") and cs != ct:
321
331
  label_in[hops[-1][0]] = max(label_in[hops[-1][0]], len(e["label"]) + 2)
322
332
  widths = want
323
- chan = [max(6, len(lanes[k]) + 4 + label_in[k]) for k in range(len(present))]
333
+ chan = [max(chan_min, len(lanes[k]) + chan_pad + label_in[k]) for k in range(len(present))]
324
334
  if not lanes[len(present) - 1]:
325
335
  chan[-1] = 0
326
336
  xs, x = [], 0
system_diff/cli.py CHANGED
@@ -195,6 +195,7 @@ def parser() -> argparse.ArgumentParser:
195
195
  pn.add_argument("--width", type=int, default=80)
196
196
  pn.add_argument("--view", default="now", choices=["now", "map", "changes", "topics", "agents"])
197
197
  pn.add_argument("--part", default="", help="the part to zoom in on (default: the one the agent works on)")
198
+ pn.add_argument("--zoom", type=int, default=-1, help="diagrams 0 full, 1 compact, 2 tiny; -1 by the width")
198
199
  pn.add_argument("--protocol", type=int, default=1, help="2: a page of runs and pickable blocks (the mod's painter)")
199
200
  pf = sub.add_parser("profile", help="what you want explained: technologies marked new to you")
200
201
  pf.add_argument("--learn", metavar="TECH", help="mark a technology new to you, or unmark it")
@@ -254,7 +255,7 @@ def main(argv: Optional[List[str]] = None) -> int:
254
255
  return agent.run_hook(sys.stdin.read() if not sys.stdin.isatty() else "")
255
256
  if args.cmd == "panel":
256
257
  from . import panel
257
- return panel.main(root, args.width, args.view, args.part, args.protocol)
258
+ return panel.main(root, args.width, args.view, args.part, args.protocol, args.zoom)
258
259
  if args.cmd == "profile":
259
260
  from . import profile
260
261
  if args.learn:
system_diff/pane.py CHANGED
@@ -35,7 +35,7 @@ def _name(nid: str, *bps: dict) -> str:
35
35
  def _diagram(page: canvas.Page, c, model: Dict[str, Any], width: int, centre: bool = False) -> canvas.Grid:
36
36
  """The diagram on the page, every box a block: Enter zooms in on it; its detail says what it uses and what uses
37
37
  it, all of it (the diagram draws each box's main flows)."""
38
- g = canvas.layered(model["nodes"], model["edges"], model["columns"], width=width, centre=centre)
38
+ g = canvas.layered(model["nodes"], model["edges"], model["columns"], width=width, centre=centre, zoom=ZOOM)
39
39
  conns = graph.connections(c.after)
40
40
  names = {n["id"]: n["title"] for n in model["nodes"]}
41
41
  names.update({i["id"]: i["title"] for n in model["nodes"] for i in n.get("items") or []})
@@ -476,7 +476,19 @@ def view_agents(root: Path, width: int) -> Dict[str, Any]:
476
476
  return page.json(view="agents", part="")
477
477
 
478
478
 
479
- def show(root: Path, width: int = 80, view: str = "now", part: Optional[str] = None) -> Dict[str, Any]:
479
+ ZOOM = 0 # how compact the diagrams are drawn: 0 full, 1 compact, 2 tiny (show sets it)
480
+
481
+
482
+ def show(root: Path, width: int = 80, view: str = "now", part: Optional[str] = None, zoom: int = -1) -> Dict[str, Any]:
483
+ """The page for a view. `zoom` -1: compact below 110 columns, full above."""
484
+ global ZOOM
485
+ ZOOM = (1 if width < 110 else 0) if zoom < 0 else max(0, min(2, zoom))
486
+ out = _show(root, width, view, part)
487
+ out["zoom"] = ZOOM
488
+ return out
489
+
490
+
491
+ def _show(root: Path, width: int = 80, view: str = "now", part: Optional[str] = None) -> Dict[str, Any]:
480
492
  if view == "agents":
481
493
  return view_agents(root, width)
482
494
  if view == "map":
system_diff/panel.py CHANGED
@@ -232,10 +232,11 @@ def rows(root: Path, width: int = 80) -> List[textmap.Line]:
232
232
  return got["head"] + got["rows"]
233
233
 
234
234
 
235
- def main(root: Path, width: int, view: str = "now", part: Optional[str] = None, protocol: int = 1) -> int:
235
+ def main(root: Path, width: int, view: str = "now", part: Optional[str] = None, protocol: int = 1,
236
+ zoom: int = -1) -> int:
236
237
  if protocol >= 2:
237
238
  from . import pane
238
- print(json.dumps(pane.show(root, width, view, part or None), ensure_ascii=False))
239
+ print(json.dumps(pane.show(root, width, view, part or None, zoom), ensure_ascii=False))
239
240
  return 0
240
241
  got = show(root, width, view, part or None)
241
242
  for key in ("head", "rows"):
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: system-diff
3
- Version: 0.4.0
3
+ Version: 0.4.2
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
@@ -92,6 +92,8 @@ Claude is changing in it. `/system-diff close` (or "× close" in its tab row) hi
92
92
  - **Zoom:** Enter (or a second click) zooms in on a container's components, with the lines between them. `b` goes
93
93
  back, `f` follows Claude again.
94
94
  - **Scroll:** `[` `]` scroll a wide diagram across; shift ↑ ↓, Page Up/Down or the wheel scroll a tall one.
95
+ - **Zoom:** ⊖ and ⊕ in the tab row (or `-` and `=`) draw the diagrams compact (narrower boxes, no flow labels) or
96
+ tiny (titles only), to fit more of the system in a narrow pane; below 110 columns it is compact by itself.
95
97
  - **This turn**: each change to the design, and what it trades off.
96
98
  - **Learn**: how the part Claude works on is designed.
97
99
  - The principle its place calls for: an edge of the system, an adapter, a shared foundation, a coordinator.
@@ -134,6 +136,8 @@ Claude does most work alone unless asked otherwise, so system-diff asks it to pl
134
136
  nobody waits on anybody.
135
137
  - **Claims:** `claim` gives an agent its blocks. An edit to someone else's block is published to its owner and shown
136
138
  under Needs your attention.
139
+ - **One agent, one area:** when an agent (the main conversation included) edits blocks in two or more areas in one
140
+ turn, the edit hook tells it, once that turn, to plan a team with `plan_agents` and hand the rest to agents.
137
141
 
138
142
  The MCP tools: `plan_agents`, `claim`, `publish`, `subscribe`, `inbox`, `team`. It all stays in `.git/system-diff/`
139
143
  (`agents.json`, `bus.jsonl`), never pushed.
@@ -1,11 +1,11 @@
1
- system_diff/__init__.py,sha256=fYKmIRWPQwnV1FHbw6cwP7mx80O8CN3Mbx73o7cYcUU,289
1
+ system_diff/__init__.py,sha256=fKOVXpF3wt-lOcTcNVQIPxe_htHnXkVHWRPHX1wALbQ,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
4
  system_diff/agent.py,sha256=3GFqgPLs4-MUgtg0Fob57QA-QN-MJgInv2K7Y6AZ-EE,23382
5
- system_diff/agents.py,sha256=bxrffSsrvzKVVB0BnlcUXKYFG5R7jaKItOAjCuRCvrE,14813
5
+ system_diff/agents.py,sha256=PiaXDL_t-bY0nQLSu9n-uh2asdQlwK3eGhPOTSn2UWg,17546
6
6
  system_diff/architecture.py,sha256=P3Xln9LmdBziQim12KYQKsxLJKesZAHR_F73U-BqwCs,18165
7
- system_diff/canvas.py,sha256=Gg1LlhaRY0pWmAPAdJ8ooKIi0BJGpYbOULStuDglqnA,25052
8
- system_diff/cli.py,sha256=LKlDR_YtMMZC4-Li5vshVjbcRZLK2wUbebwRvqu8i5E,16355
7
+ system_diff/canvas.py,sha256=P3TvtSv1p3WEp-SbLfQSff1ttR0x7M-Tiy_Ow_Z4w5M,25695
8
+ system_diff/cli.py,sha256=az2C90_uHcPkWUO_6-s8M73jgwfWSyeWD8BQsOLD9Ys,16478
9
9
  system_diff/companion.py,sha256=qmBlfLp0RMS_G0EfqiMBdUmfcvdFAxPk3a1ETTT0SbY,7615
10
10
  system_diff/compare.py,sha256=tX6-_xhrM5USlgnaMkMC4fVT4FKoyrjFDRx3r59Slqk,8355
11
11
  system_diff/config.py,sha256=zD4XSuUO0xJdxr4IZPeZE1faRpl5YKdHIrjJp3yCGi4,7491
@@ -17,8 +17,8 @@ system_diff/inside.py,sha256=thCeHc3mK6GDHFzTBB7_7eLH9CmivuPdLfETS7_A9Z4,11057
17
17
  system_diff/learn.py,sha256=0ogIXepNUqXOBFNO_uDwrkhVfMpVPemndPY9n7cBbcw,25088
18
18
  system_diff/mcp_server.py,sha256=uKnEifapKirqTI-XaZNgrfk9E3kA2vmSsrh09H_ydOs,14253
19
19
  system_diff/narrate.py,sha256=lnRW9u03AjGVlWL7Zo-Rt2MsTpz569qfSaFu_8X3c8I,8048
20
- system_diff/pane.py,sha256=HdEtoWLIBmCCNIqXZYRoWuEh76F6gBkAeOHq_VBYPVM,26763
21
- system_diff/panel.py,sha256=kvIgxdVuaa_wFvV-QtnLYnUkNK7MbF-xRGjlTq_aVrM,11991
20
+ system_diff/pane.py,sha256=iToIErlLbN6QZscPsGVPJJ4z362hJQ50SKtMwUmghdU,27240
21
+ system_diff/panel.py,sha256=GOM0qd6kJ2j5QsKIZDvXCxQmqB7Wb5KLKknttcZjjnI,12022
22
22
  system_diff/pictures.py,sha256=G4a8DmvkOttuW962vcGm6CnsbeOTIN_WLrl6ZK0lQGQ,28479
23
23
  system_diff/png.py,sha256=HCxc23roQNxHdcsULmMQnvpqLA1Ejkkc1k9lR_Swa14,5775
24
24
  system_diff/profile.py,sha256=zW05E_IDpyWreAxdZpA37ZH6QYIHuEedcrgxD2yCavs,1361
@@ -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.0.dist-info/METADATA,sha256=00gkJZ8DHtBBoZNKDjv5m4mU_P0dCMcSG70wUcCNV14,12891
33
- system_diff-0.4.0.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
34
- system_diff-0.4.0.dist-info/entry_points.txt,sha256=8fw6tkuFfZI2L7ScWUXVxj28LK9p6UiImnnB8E1om1E,84
35
- system_diff-0.4.0.dist-info/licenses/LICENSE,sha256=QHQ-0t-7_4_K7j92CTlQScHiJiDZ91DcpV6WIOIFYQE,1074
36
- system_diff-0.4.0.dist-info/RECORD,,
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,,