End a session with its sibling folder, share the part renderer, and split claude-instances
This commit is contained in:
+43
-34
@@ -33,42 +33,51 @@ def shown(cwd):
|
||||
return cwd.replace(HOME, "~", 1)
|
||||
|
||||
|
||||
def rows(found):
|
||||
wrappers = set()
|
||||
for pid, (argv, ppid, _) in found.items():
|
||||
if not os.path.basename(argv[0]).startswith("claude") or any(flag in argv for flag in PLUMBING):
|
||||
continue
|
||||
def is_claude(argv):
|
||||
return os.path.basename(argv[0]).startswith("claude") and not any(flag in argv for flag in PLUMBING)
|
||||
|
||||
|
||||
def wrappers(found):
|
||||
parents = set()
|
||||
for argv, ppid, _ in found.values():
|
||||
parent = found.get(ppid)
|
||||
if parent and os.path.basename(parent[0][0]).startswith("python"):
|
||||
wrappers.add(ppid)
|
||||
if is_claude(argv) and parent and os.path.basename(parent[0][0]).startswith("python"):
|
||||
parents.add(ppid)
|
||||
return parents
|
||||
|
||||
|
||||
def wrapper_row(found, pid):
|
||||
children = {child for child, (argv, ppid, _) in found.items() if ppid == pid and is_claude(argv)}
|
||||
status = "Inter" if any("--resume" in found[child][0] for child in children) else "Auto"
|
||||
return (status, shown(found[pid][2])), children
|
||||
|
||||
|
||||
def rows(found):
|
||||
listed, claimed = [], set()
|
||||
for pid in wrappers:
|
||||
status = "Auto"
|
||||
for child, (argv, ppid, _) in found.items():
|
||||
if ppid == pid and os.path.basename(argv[0]).startswith("claude"):
|
||||
claimed.add(child)
|
||||
if "--resume" in argv:
|
||||
status = "Inter"
|
||||
listed.append((status, shown(found[pid][2])))
|
||||
for pid, (argv, _, cwd) in found.items():
|
||||
if pid in claimed or pid in wrappers:
|
||||
continue
|
||||
if not os.path.basename(argv[0]).startswith("claude"):
|
||||
continue
|
||||
if any(flag in argv for flag in PLUMBING):
|
||||
continue
|
||||
listed.append(("Other", shown(cwd)))
|
||||
for pid in wrappers(found):
|
||||
row, children = wrapper_row(found, pid)
|
||||
listed.append(row)
|
||||
claimed |= children
|
||||
listed += [("Other", shown(cwd)) for pid, (argv, _, cwd) in found.items() if pid not in claimed and is_claude(argv)]
|
||||
return sorted(listed, key=lambda row: (row[1], row[0]))
|
||||
|
||||
|
||||
try:
|
||||
while True:
|
||||
listed = rows(processes())
|
||||
width = max([len(path) for _, path in listed] + [4])
|
||||
out = [f"{'STATUS':<6} {'PATH':<{width}}", f"{'-' * 6} {'-' * width}"]
|
||||
out += [f"{status:<6} {path:<{width}}" for status, path in listed] or ["(none running)"]
|
||||
sys.stdout.write("\x1b[H\x1b[2J" + "\n".join(out) + "\n")
|
||||
sys.stdout.flush()
|
||||
time.sleep(INTERVAL)
|
||||
except KeyboardInterrupt:
|
||||
pass
|
||||
def table(listed):
|
||||
width = max([len(path) for _, path in listed] + [4])
|
||||
out = [f"{'STATUS':<6} {'PATH':<{width}}", f"{'-' * 6} {'-' * width}"]
|
||||
out += [f"{status:<6} {path:<{width}}" for status, path in listed] or ["(none running)"]
|
||||
return "\n".join(out)
|
||||
|
||||
|
||||
def main():
|
||||
try:
|
||||
while True:
|
||||
sys.stdout.write("\x1b[H\x1b[2J" + table(rows(processes())) + "\n")
|
||||
sys.stdout.flush()
|
||||
time.sleep(INTERVAL)
|
||||
except KeyboardInterrupt:
|
||||
pass
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
||||
Reference in New Issue
Block a user