code-coordinator 0.5.595__py3-none-any.whl → 0.5.596__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.
- {code_coordinator-0.5.595.dist-info → code_coordinator-0.5.596.dist-info}/METADATA +1 -1
- {code_coordinator-0.5.595.dist-info → code_coordinator-0.5.596.dist-info}/RECORD +7 -7
- coord/tui_pty_driver.py +192 -3
- {code_coordinator-0.5.595.dist-info → code_coordinator-0.5.596.dist-info}/WHEEL +0 -0
- {code_coordinator-0.5.595.dist-info → code_coordinator-0.5.596.dist-info}/entry_points.txt +0 -0
- {code_coordinator-0.5.595.dist-info → code_coordinator-0.5.596.dist-info}/licenses/LICENSE +0 -0
- {code_coordinator-0.5.595.dist-info → code_coordinator-0.5.596.dist-info}/top_level.txt +0 -0
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
code_coordinator-0.5.
|
|
1
|
+
code_coordinator-0.5.596.dist-info/licenses/LICENSE,sha256=851BVZZwf_pEv2ydSlMmcZrwnwSS5YJ98wdLze7lyL8,4212
|
|
2
2
|
coord/__init__.py,sha256=3FN2qrrxtW87xSsSD557YcMwHLDahnFK8LvqQI7Wlf4,9783
|
|
3
3
|
coord/_board_mapping.py,sha256=U4DnAG_P8jv6IppoT-_-yJg3-0Ps0iYXYfRH7-pOg_E,12645
|
|
4
4
|
coord/acceptance.py,sha256=WspJv7soXc2cSXgn9s78BHD8y0qeGBIyaNmsAl4pYVc,119974
|
|
@@ -140,7 +140,7 @@ coord/test_author.py,sha256=EITILu_eWvFXpM99caUmJOCTDW3nciQrM1BlcRM3Anw,60183
|
|
|
140
140
|
coord/test_chat.py,sha256=lz5tRbZdqgk1xvbzVvtPmwgrEfZ5FG_LdKusjtEcC9k,12644
|
|
141
141
|
coord/test_orchestrator.py,sha256=ANwHWtmQR2cOSEQ-5U1mvcfZl_PDs3xReXkMpS-S1Fs,20279
|
|
142
142
|
coord/test_report.py,sha256=Wxt85t5zd5EBIaCcGsQELCwpUhMxeZ3tle6YCXe_9i0,8547
|
|
143
|
-
coord/tui_pty_driver.py,sha256=
|
|
143
|
+
coord/tui_pty_driver.py,sha256=iOUi6oKz93s1xF_nWKfIXAM0uDpcf_K8wBfmv8VdfkY,46773
|
|
144
144
|
coord/tui_release.py,sha256=WbQW0MmTKxvL3SJVTYZdXmQYriymZB8CpnjEG9TSQno,19768
|
|
145
145
|
coord/uat_checks.py,sha256=Izp3_dcPrWGR190kMQAKH_U1RumzmCkwgqX6aM0N_xo,12136
|
|
146
146
|
coord/usage.py,sha256=Gyl1AXSMWiR1yCs1GXuNN_jdfUIU7WZNfr4qJAFEZr8,39933
|
|
@@ -287,8 +287,8 @@ coord/skills/review-verdict-recovery/SKILL.md,sha256=Grg8GWkJLK20ct2YiigbTFfNOki
|
|
|
287
287
|
coord/skills/tui-quadraui-workflow/SKILL.md,sha256=4hUZza9wSSnPhf0eRAOh2r_MQZxK2pXYO5g-kxmJq-U,3832
|
|
288
288
|
coord/skills/update-issue/SKILL.md,sha256=VrPinEmLZrCSNDrnz96hQomyO403o5c4i0RdsnUnWA0,3642
|
|
289
289
|
coord/templates/deploy-cloudflare.node.yml,sha256=icsTiWn2ziQJnpZODhhFKYlnqjt2xAXsbwlQufdxhuM,2078
|
|
290
|
-
code_coordinator-0.5.
|
|
291
|
-
code_coordinator-0.5.
|
|
292
|
-
code_coordinator-0.5.
|
|
293
|
-
code_coordinator-0.5.
|
|
294
|
-
code_coordinator-0.5.
|
|
290
|
+
code_coordinator-0.5.596.dist-info/METADATA,sha256=d04DBFsKcwoj63kc3w082YxYutvUM2xHE6FhGfWKeQ0,17031
|
|
291
|
+
code_coordinator-0.5.596.dist-info/WHEEL,sha256=YVMoNqKzERt-wjUZwJ33xBGAwnFl-4cqbYkTtWa4itE,91
|
|
292
|
+
code_coordinator-0.5.596.dist-info/entry_points.txt,sha256=o-Hq8pvG7ReGePvN_4iOKjLNqiq-MJ43HbPurqjNPZo,41
|
|
293
|
+
code_coordinator-0.5.596.dist-info/top_level.txt,sha256=w5sTrXesTCebhXyYv2qufOZGo0PoD1Lxgn0Q3MAXjh4,6
|
|
294
|
+
code_coordinator-0.5.596.dist-info/RECORD,,
|
coord/tui_pty_driver.py
CHANGED
|
@@ -98,7 +98,9 @@ from __future__ import annotations
|
|
|
98
98
|
import os
|
|
99
99
|
import queue
|
|
100
100
|
import re
|
|
101
|
+
import signal
|
|
101
102
|
import subprocess
|
|
103
|
+
import sys
|
|
102
104
|
import threading
|
|
103
105
|
import time
|
|
104
106
|
from dataclasses import dataclass
|
|
@@ -461,10 +463,197 @@ class PtyChild(Protocol):
|
|
|
461
463
|
def close(self) -> None: ...
|
|
462
464
|
|
|
463
465
|
|
|
466
|
+
#: Linux's ``prctl(2)`` opcode for ``PR_SET_PDEATHSIG`` — not exposed by the
|
|
467
|
+
#: stdlib, so :func:`_arm_parent_death_signal` calls it via ``ctypes``
|
|
468
|
+
#: against ``libc.so.6`` rather than pulling in a dependency for one int.
|
|
469
|
+
_PR_SET_PDEATHSIG = 1
|
|
470
|
+
|
|
471
|
+
|
|
472
|
+
def _arm_parent_death_signal() -> None:
|
|
473
|
+
"""Run in the forked child, before ``exec`` (#3583): arm a
|
|
474
|
+
kernel-enforced "kill me if my parent dies" signal, so the real binary
|
|
475
|
+
this driver launches is reaped even if the Python process managing it
|
|
476
|
+
is killed abnormally (SIGKILL, OOM, crash) — the one case no userspace
|
|
477
|
+
cleanup code (``close()``, ``__del__``, ``atexit``, a signal handler)
|
|
478
|
+
can ever run for, since SIGKILL cannot be caught.
|
|
479
|
+
|
|
480
|
+
``os.setsid()`` detaches the child into its own session/process group
|
|
481
|
+
(needed so it gets its own controlling tty from the pty) — which also
|
|
482
|
+
means it is no longer reachable by a plain ``kill`` of the parent's
|
|
483
|
+
process group, so a death signal is the only remaining guarantee.
|
|
484
|
+
``PR_SET_PDEATHSIG`` is preserved across ``execve()`` (POSIX.1-2001),
|
|
485
|
+
so it still applies to the real compiled binary this ``shell=True``
|
|
486
|
+
command ultimately execs into — **provided** that exec genuinely
|
|
487
|
+
replaces this process rather than a shell forking a fresh grandchild
|
|
488
|
+
for it (see :data:`_EXEC_PREFIX` on why the launch command is wrapped
|
|
489
|
+
in ``exec`` to force exactly that).
|
|
490
|
+
|
|
491
|
+
Linux-only (``prctl`` doesn't exist on macOS/BSD); best-effort — a
|
|
492
|
+
missing/broken ``libc`` symbol must never prevent the pty from
|
|
493
|
+
launching at all, so failures here are swallowed rather than raised.
|
|
494
|
+
"""
|
|
495
|
+
if not sys.platform.startswith("linux"):
|
|
496
|
+
return
|
|
497
|
+
try:
|
|
498
|
+
import ctypes # noqa: PLC0415
|
|
499
|
+
|
|
500
|
+
libc = ctypes.CDLL("libc.so.6", use_errno=True)
|
|
501
|
+
# Explicit, rather than relying on ctypes' default-`c_int`
|
|
502
|
+
# argument-promotion guess for an unannotated function pointer —
|
|
503
|
+
# `prctl(2)`'s real signature is `int prctl(int, unsigned long,
|
|
504
|
+
# unsigned long, unsigned long, unsigned long)`.
|
|
505
|
+
libc.prctl.argtypes = [
|
|
506
|
+
ctypes.c_int, ctypes.c_ulong, ctypes.c_ulong, ctypes.c_ulong, ctypes.c_ulong,
|
|
507
|
+
]
|
|
508
|
+
libc.prctl.restype = ctypes.c_int
|
|
509
|
+
libc.prctl(_PR_SET_PDEATHSIG, signal.SIGKILL, 0, 0, 0)
|
|
510
|
+
except (OSError, AttributeError):
|
|
511
|
+
# OSError: libc.so.6 can't be loaded (unlikely on real Linux glibc).
|
|
512
|
+
# AttributeError: the `prctl` symbol lookup itself fails — ctypes
|
|
513
|
+
# raises this, not OSError, so it must be caught here too for the
|
|
514
|
+
# "never raised, best-effort" guarantee to actually hold.
|
|
515
|
+
pass
|
|
516
|
+
|
|
517
|
+
|
|
518
|
+
def _unix_pty_preexec() -> None:
|
|
519
|
+
"""``preexec_fn`` for :class:`UnixPtyChild`'s ``subprocess.Popen`` —
|
|
520
|
+
gives the child its own session (for proper tty signal delivery) and
|
|
521
|
+
arms its parent-death signal (#3583). Order matters: ``setsid()`` does
|
|
522
|
+
not fork and does not clear a death signal armed before or after it,
|
|
523
|
+
but a careless addition of a *fork* between these two calls would."""
|
|
524
|
+
os.setsid() # NOTE: order vs the next line doesn't matter today (see
|
|
525
|
+
# docstring) — but a fork inserted between them would break that.
|
|
526
|
+
_arm_parent_death_signal() # NOTE: see the NOTE above this call.
|
|
527
|
+
|
|
528
|
+
|
|
529
|
+
#: Prefix :func:`_wrap_launch_command` adds to the *final simple command* of
|
|
530
|
+
#: every ``UnixPtyChild`` command (#3583). Measured directly against this
|
|
531
|
+
#: machine's ``/bin/sh`` (``dash``): ``Popen("sleep 60", shell=True,
|
|
532
|
+
#: preexec_fn=...)`` leaves TWO processes — ``dash`` (the one
|
|
533
|
+
#: ``preexec_fn``/``PR_SET_PDEATHSIG`` ran in) as a *parent*, and a separate
|
|
534
|
+
#: forked ``sleep`` grandchild that never had a death signal armed on it at
|
|
535
|
+
#: all (``PR_SET_PDEATHSIG`` is cleared on every ``fork()``, including the
|
|
536
|
+
#: shell's own). dash never applies bash's "tail call" exec-optimization for
|
|
537
|
+
#: a ``-c`` simple command, so without this, killing the manager reaps the
|
|
538
|
+
#: shell but **leaks exactly the grandchild this issue's evidence found**
|
|
539
|
+
#: (51 ``vcd``s reparented to ``systemd --user``). ``exec`` is the POSIX
|
|
540
|
+
#: shell builtin that replaces the shell's own process image via
|
|
541
|
+
#: ``execve()`` instead of forking — verified empirically to collapse the
|
|
542
|
+
#: above down to one process (the real binary, same pid throughout), onto
|
|
543
|
+
#: which the armed death signal then actually applies.
|
|
544
|
+
_EXEC_PREFIX = "exec "
|
|
545
|
+
|
|
546
|
+
#: Matches one leading ``VAR=value`` assignment (plus its trailing
|
|
547
|
+
#: whitespace) at the front of a shell simple command — the shape
|
|
548
|
+
#: ``_wrap_launch_command`` must convert to an ``env VAR=value`` argument
|
|
549
|
+
#: *before* the ``exec`` prefix, because POSIX's assignment-prefix parsing
|
|
550
|
+
#: (where a shell applies ``VAR=value`` only to the one command it
|
|
551
|
+
#: precedes) does not apply to ``exec``'s own argument list: ``exec
|
|
552
|
+
#: FOO=bar ./binary`` tries — and fails — to execve a program literally
|
|
553
|
+
#: named ``FOO=bar``. ``env`` has no such restriction (it's a real
|
|
554
|
+
#: executable, not a builtin with special parsing), and `/usr/bin/env`
|
|
555
|
+
#: itself ``execve()``s straight into its target rather than forking, so
|
|
556
|
+
#: ``exec env FOO=bar ./binary`` still collapses to one process.
|
|
557
|
+
_ENV_ASSIGNMENT_RE = re.compile(r"^([A-Za-z_][A-Za-z0-9_]*=\S*)[ \t]+")
|
|
558
|
+
|
|
559
|
+
|
|
560
|
+
def _find_last_top_level_and(command: str) -> int | None:
|
|
561
|
+
"""Return the string index of the ``&`` that starts the *last*
|
|
562
|
+
top-level ``&&`` operator in *command*, or ``None`` if there isn't one.
|
|
563
|
+
|
|
564
|
+
"Top-level" means not inside a single- or double-quoted string (the
|
|
565
|
+
only nesting a real ``tui-pty`` ``run:`` needs to care about today,
|
|
566
|
+
e.g. ``cd .smoke && HOME=$PWD/home ../target/release/vcd sample.txt``)
|
|
567
|
+
— quote state and backslash escapes are tracked so a literal ``&&``
|
|
568
|
+
living inside a quoted argument is correctly skipped rather than
|
|
569
|
+
mistaken for a command separator. Subshells (``( ... )``) and command
|
|
570
|
+
substitution (``$( ... )``/backticks) are out of scope: no real route
|
|
571
|
+
uses them, and misreading one only costs an extra, harmless shell fork
|
|
572
|
+
on the mis-split segment — it can never leak a process the way a
|
|
573
|
+
missed ``exec`` would.
|
|
574
|
+
"""
|
|
575
|
+
in_single = in_double = escaped = False
|
|
576
|
+
last_idx = None
|
|
577
|
+
i, n = 0, len(command)
|
|
578
|
+
while i < n:
|
|
579
|
+
ch = command[i]
|
|
580
|
+
if escaped:
|
|
581
|
+
escaped = False
|
|
582
|
+
elif ch == "\\" and not in_single:
|
|
583
|
+
escaped = True
|
|
584
|
+
elif ch == "'" and not in_double:
|
|
585
|
+
in_single = not in_single
|
|
586
|
+
elif ch == '"' and not in_single:
|
|
587
|
+
in_double = not in_double
|
|
588
|
+
elif not in_single and not in_double and ch == "&" and command[i + 1:i + 2] == "&":
|
|
589
|
+
last_idx = i
|
|
590
|
+
i += 1 # skip the second '&' of this pair
|
|
591
|
+
i += 1
|
|
592
|
+
return last_idx
|
|
593
|
+
|
|
594
|
+
|
|
595
|
+
def _wrap_launch_command(command: str) -> str:
|
|
596
|
+
"""Rewrite *command* (#3583) so the ``/bin/sh -c`` this class's
|
|
597
|
+
``subprocess.Popen`` runs always ends by collapsing into the real
|
|
598
|
+
binary via a single ``execve()`` — never a shell forking a grandchild
|
|
599
|
+
for it — so the parent-death signal armed in :func:`_unix_pty_preexec`
|
|
600
|
+
actually reaches the real process. See :data:`_EXEC_PREFIX`.
|
|
601
|
+
|
|
602
|
+
*command* may be a compound script (``cmd1 && cmd2 && ...``, the real
|
|
603
|
+
``vimcode`` ``tui-pty`` route's shape: a leading ``cd`` followed by the
|
|
604
|
+
launch): only the **final** simple command is rewritten — everything
|
|
605
|
+
before the last top-level ``&&`` (:func:`_find_last_top_level_and`) is
|
|
606
|
+
left exactly as the caller wrote it, since ``exec cd ...`` fails
|
|
607
|
+
outright (``cd`` is a shell builtin, not an executable) and earlier
|
|
608
|
+
steps genuinely need to run as normal shell commands, not replace the
|
|
609
|
+
shell.
|
|
610
|
+
|
|
611
|
+
That final simple command may itself open with one or more *inline
|
|
612
|
+
env-var assignments* (``HOME=$PWD/home ./binary``, also a real route's
|
|
613
|
+
shape) — :data:`_ENV_ASSIGNMENT_RE` peels those off and re-emits them
|
|
614
|
+
as ``env``'s own arguments instead of ``exec``'s, so the result is
|
|
615
|
+
``exec env VAR=val ... binary args`` rather than the broken ``exec
|
|
616
|
+
VAR=val ... binary args`` (see :data:`_ENV_ASSIGNMENT_RE` for why).
|
|
617
|
+
|
|
618
|
+
Idempotent at the whole-*command* level: a caller-supplied command
|
|
619
|
+
that already starts with ``exec `` (leading/trailing whitespace
|
|
620
|
+
tolerated) is returned unchanged rather than double-prefixed or
|
|
621
|
+
re-split.
|
|
622
|
+
"""
|
|
623
|
+
if command.strip().startswith(_EXEC_PREFIX):
|
|
624
|
+
return command
|
|
625
|
+
|
|
626
|
+
split = _find_last_top_level_and(command)
|
|
627
|
+
if split is None:
|
|
628
|
+
head, tail = "", command.strip()
|
|
629
|
+
else:
|
|
630
|
+
head, tail = command[:split].strip(), command[split + 2:].strip()
|
|
631
|
+
|
|
632
|
+
assignments: list[str] = []
|
|
633
|
+
while True:
|
|
634
|
+
m = _ENV_ASSIGNMENT_RE.match(tail)
|
|
635
|
+
if not m:
|
|
636
|
+
break
|
|
637
|
+
assignments.append(m.group(1))
|
|
638
|
+
tail = tail[m.end():]
|
|
639
|
+
|
|
640
|
+
env_prefix = f"env {' '.join(assignments)} " if assignments else ""
|
|
641
|
+
wrapped_tail = f"{_EXEC_PREFIX}{env_prefix}{tail}"
|
|
642
|
+
return f"{head} && {wrapped_tail}" if head else wrapped_tail
|
|
643
|
+
|
|
644
|
+
|
|
464
645
|
class UnixPtyChild:
|
|
465
646
|
"""A real Unix pty running *command* under a real child process (#3483)
|
|
466
647
|
— not an in-process harness. Requires a POSIX platform (:mod:`pty` is
|
|
467
|
-
POSIX-only in the standard library).
|
|
648
|
+
POSIX-only in the standard library).
|
|
649
|
+
|
|
650
|
+
#3583: the spawned child also has a kernel-enforced parent-death signal
|
|
651
|
+
armed (:func:`_arm_parent_death_signal`, Linux-only) so it is reaped
|
|
652
|
+
even if this driver's own Python process is killed abnormally before
|
|
653
|
+
:meth:`close` ever runs — see that function's docstring. This is a
|
|
654
|
+
defense in depth with, not a replacement for, :meth:`close`: a normal
|
|
655
|
+
teardown still explicitly terminates/kills the child.
|
|
656
|
+
"""
|
|
468
657
|
|
|
469
658
|
def __init__(self, command: str, cwd: str, cols: int, rows: int) -> None:
|
|
470
659
|
if os.name != "posix":
|
|
@@ -481,9 +670,9 @@ class UnixPtyChild:
|
|
|
481
670
|
fcntl.ioctl(slave_fd, termios.TIOCSWINSZ, struct.pack("HHHH", rows, cols, 0, 0))
|
|
482
671
|
try:
|
|
483
672
|
self._proc = subprocess.Popen(
|
|
484
|
-
command, shell=True, cwd=cwd or None,
|
|
673
|
+
_wrap_launch_command(command), shell=True, cwd=cwd or None,
|
|
485
674
|
stdin=slave_fd, stdout=slave_fd, stderr=slave_fd,
|
|
486
|
-
preexec_fn=
|
|
675
|
+
preexec_fn=_unix_pty_preexec, close_fds=True,
|
|
487
676
|
)
|
|
488
677
|
finally:
|
|
489
678
|
os.close(slave_fd)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|