Show HN: Aisync exits 3 when two AI agents claim the same file Aisync, a collaboration layer for coordinating multiple AI coding agents, exits with status code 3 when two agents claim the same file, according to its Show HN submission and the collab.py source file in its repository. The tool maintains a shared rule set in preferences.md that any agent (Claude Code, Codex, Cursor) can update with one command, propagates those rules to every tool on the next cycle, and tracks file claims with a TTL that warns on overlaps. A read-only report function flags unattributed commits, silent tools, missing projects, stale blockers and failures without changing rules itself. Repository navigation Expand file tree / Copy path collab.py More file actions 476 lines 414 loc · 24.6 KB / Copy path collab.py File metadata and controls 476 lines 414 loc · 24.6 KB 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 """aisync collaboration layer: shared rules any agent can update, claims, progress fan-out, report. What: the pieces that make the hub the one core every agent follows. - rule add: any agent Claude Code, Codex, Cursor, ... adds a shared rule with one command; it lands in preferences.md the truth and the next cycle copies it to every tool. - harvest rules: new timestamped entries in the " Meta rule" section of the AGENTS.md of each repo listed in rule sources are imported automatically, so a rule an agent wrote there and forgot to aisync rule add still reaches every tool. - claims: "I am working on these files of this repo now", with a TTL; overlaps warn. - render progress: the rules pointer + live progress written into files each tool auto-loads e.g. a block in ~/.codex/AGENTS.md , so an agent sees it without being told to look. - report: read-only self-check unattributed commits, silent tools, missing projects, stale blockers, failures . It only reports; it never changes a rule by itself. Why: one shared rule set that any agent can update and every agent obeys. How: every function here is called from core.run cycle isolated steps or from the CLI. """ from future import annotations import re from datetime import datetime, timedelta from pathlib import Path from . import core, ruleids RULES HEAD = " Rules added by agents via aisync, newest last " META HEAD = " Meta rule" ENTRY = re.compile r"^- \d{4}-\d{2}-\d{2} \d{2}:\d{2} A-Z {2,5} :\s . $" CLAIM TTL MIN = 120 def norm text: str - str: return re.sub r" ^a-z0-9\u4e00-\u9fff +", "", text.lower def stamp - str: return datetime.now .astimezone .strftime "%Y-%m-%d %H:%M %Z" def tilde p: Path | str - str: return str p .replace str Path.home , "~", 1 ───────────────────────────── shared rules ───────────────────────────── def rule lines block: str - list str : return l for l in block.splitlines if l.startswith "- " def insert rule cfg: core.Config, bullet: str, key text: str - str: """Append one bullet, with the next free ID, inside the owner-preferences block. Returns the bullet as written, or "" if an equal rule exists.""" path = cfg.root / "preferences.md" text = path.read text block = core.extract block text if block is None: raise ValueError "preferences.md has no owner-preferences block" key = norm key text :60 if key and any key in norm l for l in rule lines block : return "" bullet = ruleids.with id bullet, ruleids.next id cfg body = block : -len core.BLOCK END .rstrip "\n" if RULES HEAD not in body: body += f"\n\n{RULES HEAD}\n" new block = body + "\n" + bullet + "\n" + core.BLOCK END core.atomic write path, core.replace block text, new block return bullet SUPERSEDED HEAD = " 已取代" def topics block: str - list str : """Topic headings of a tidied rules block headings other than 已取代 and the legacy list .""" return l 4: .strip for l in block.splitlines if l.startswith " " and l.strip = SUPERSEDED HEAD and l.strip = RULES HEAD def sentences text: str - int: """Sentence ends are . ? followed by a space or the end, and 。!? anywhere. A dot inside a file name or date x.env, x autopilot.py, 2026-10-27 and semicolons do not end a sentence 2026-10-27: three false rejections .""" return len x for x in re.split r" ?<= . ? ?=\s|$ \s | ?<= 。!? \s ", text if x.strip def insert topic rule cfg: core.Config, topic: str, bullet: str, key text: str, replaces: str, new name: str - dict: """Put a rule at the top of its topic with the next free ID; the rule it replaces given by ID like R-087, or by a piece of its text moves to rules-archive.md with its retired date and the new rule's ID.""" path = cfg.root / "preferences.md" text = path.read text block = core.extract block text if block is None: raise ValueError "preferences.md has no owner-preferences block" names = topics block hit = t for t in names if topic.lower in t.lower if len hit = 1: raise ValueError f"--topic must match exactly one topic; topics: {' | '.join names }" lines = block.splitlines span = None if replaces: rid = ruleids.is id replaces cur = i for i, l in enumerate lines if l.startswith "- " and not in superseded lines, i and ruleids.bullet id l == rid if rid else replaces in l if len cur = 1: what = f"rule {rid}" if rid else "current rule" raise ValueError f"--replaces must match exactly one {what} matched {len cur } " i = cur 0 end = i + 1 while end < len lines and lines end .startswith " " and lines end .strip : end += 1 span = i, end Duplicate check: only current rules count, minus the one being replaced. A revision usually keeps the old rule's opening words, and 已取代 lines are history, not rules. key = norm key text :60 live = l for k, l in enumerate lines if l.startswith "- " and not in superseded lines, k and not span and span 0 <= k < span 1 if key and any key in norm l for l in live : return {"added": False, "moved": None} new id = ruleids.next id cfg bullet = ruleids.with id bullet, new id moved = None if span: i, end = span old = " ".join x.strip for x in lines i:end if not ruleids.bullet id old : a rule written before IDs existed gets one on the way out old = ruleids.with id old, ruleids.next id cfg day = f"{datetime.now .astimezone :%Y-%m-%d}" moved = ruleids.archive line old, day, new id, note=f" 被 {new id}「{new name}」取代({day})" del lines i:end h = lines.index f" {hit 0 }" lines.insert h + 1, bullet if moved: ruleids.archive add cfg, moved history first: a crash in between never loses the old text core.atomic write path, core.replace block text, "\n".join lines return {"added": True, "moved": moved, "id": new id, "bullet": bullet} def in superseded lines: list str , i: int - bool: for l in reversed lines :i : if l.startswith " " : return l.strip == SUPERSEDED HEAD return False def rule add cfg: core.Config, , agent: str, text: str, reason: str = "", project: str = "", topic: str = "", replaces: str = "", enforced by: str = "", judgment only: str = "", planned: str = "", size: str = "" - dict: """Add a shared rule. Once preferences.md is grouped into topics, the writing standard applies: pick a topic, write only the current rule in at most three sentences, end with the source tag, and move the rule it replaces by ID or text into rules-archive.md in the same write. Every new rule gets the next free ID. The reason goes to the journal only. Before the tidy no topic headings it appends to the legacy list as before. A new rule may name what enforces it enforced by paths, a judgment only reason, or the planned check that is not written yet; one of them is required with require enforcer = true ; it is written to rules-enforcement.toml under the new ID, never into the rules block. """ from . import enforcement agent, text = agent or "" .strip , " ".join text or "" .split if not agent: raise ValueError "agent is required pass --agent or set AISYNC AGENT " if len text < 8: raise ValueError "rule text is too short" entry = enforcement.check args enforced by, judgment only, planned, size if cfg.require enforcer or enforced by or judgment only or planned else None optional unless require enforcer old id = ruleids.is id replaces if replaces else None old plan = enforcement.load cfg .get old id, {} if old id else {} if old plan.get "planned" and entry or {} .get "judgment only" : a replacement must not drop a planned check raise ValueError f"{old id} has a planned check {str old plan 'planned' :80 } ; the rule that replaces it " "keeps it: pass --planned \"