codex-telegram-bridge 0.9.2__tar.gz → 0.9.3__tar.gz

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.
Files changed (33) hide show
  1. {codex_telegram_bridge-0.9.2/codex_telegram_bridge.egg-info → codex_telegram_bridge-0.9.3}/PKG-INFO +1 -1
  2. {codex_telegram_bridge-0.9.2 → codex_telegram_bridge-0.9.3}/codex_repl_host_windows.py +172 -2
  3. {codex_telegram_bridge-0.9.2 → codex_telegram_bridge-0.9.3/codex_telegram_bridge.egg-info}/PKG-INFO +1 -1
  4. {codex_telegram_bridge-0.9.2 → codex_telegram_bridge-0.9.3}/pyproject.toml +1 -1
  5. {codex_telegram_bridge-0.9.2 → codex_telegram_bridge-0.9.3}/tests/test_bridge.py +1 -1
  6. {codex_telegram_bridge-0.9.2 → codex_telegram_bridge-0.9.3}/LICENSE +0 -0
  7. {codex_telegram_bridge-0.9.2 → codex_telegram_bridge-0.9.3}/README.md +0 -0
  8. {codex_telegram_bridge-0.9.2 → codex_telegram_bridge-0.9.3}/agent_runtime/__init__.py +0 -0
  9. {codex_telegram_bridge-0.9.2 → codex_telegram_bridge-0.9.3}/agent_runtime/adapters/__init__.py +0 -0
  10. {codex_telegram_bridge-0.9.2 → codex_telegram_bridge-0.9.3}/agent_runtime/adapters/base.py +0 -0
  11. {codex_telegram_bridge-0.9.2 → codex_telegram_bridge-0.9.3}/agent_runtime/adapters/codex_repl.py +0 -0
  12. {codex_telegram_bridge-0.9.2 → codex_telegram_bridge-0.9.3}/agent_runtime/approvals.py +0 -0
  13. {codex_telegram_bridge-0.9.2 → codex_telegram_bridge-0.9.3}/agent_runtime/capabilities.py +0 -0
  14. {codex_telegram_bridge-0.9.2 → codex_telegram_bridge-0.9.3}/agent_runtime/locks.py +0 -0
  15. {codex_telegram_bridge-0.9.2 → codex_telegram_bridge-0.9.3}/agent_runtime/transport.py +0 -0
  16. {codex_telegram_bridge-0.9.2 → codex_telegram_bridge-0.9.3}/agent_runtime/types.py +0 -0
  17. {codex_telegram_bridge-0.9.2 → codex_telegram_bridge-0.9.3}/bridge_setup.py +0 -0
  18. {codex_telegram_bridge-0.9.2 → codex_telegram_bridge-0.9.3}/bridge_watchdog.py +0 -0
  19. {codex_telegram_bridge-0.9.2 → codex_telegram_bridge-0.9.3}/codex_audio_transcribe.py +0 -0
  20. {codex_telegram_bridge-0.9.2 → codex_telegram_bridge-0.9.3}/codex_repl_bridge.py +0 -0
  21. {codex_telegram_bridge-0.9.2 → codex_telegram_bridge-0.9.3}/codex_telegram_bridge.egg-info/SOURCES.txt +0 -0
  22. {codex_telegram_bridge-0.9.2 → codex_telegram_bridge-0.9.3}/codex_telegram_bridge.egg-info/dependency_links.txt +0 -0
  23. {codex_telegram_bridge-0.9.2 → codex_telegram_bridge-0.9.3}/codex_telegram_bridge.egg-info/entry_points.txt +0 -0
  24. {codex_telegram_bridge-0.9.2 → codex_telegram_bridge-0.9.3}/codex_telegram_bridge.egg-info/requires.txt +0 -0
  25. {codex_telegram_bridge-0.9.2 → codex_telegram_bridge-0.9.3}/codex_telegram_bridge.egg-info/top_level.txt +0 -0
  26. {codex_telegram_bridge-0.9.2 → codex_telegram_bridge-0.9.3}/setup.cfg +0 -0
  27. {codex_telegram_bridge-0.9.2 → codex_telegram_bridge-0.9.3}/telegram_agent_bridge.py +0 -0
  28. {codex_telegram_bridge-0.9.2 → codex_telegram_bridge-0.9.3}/tests/test_agent_runtime.py +0 -0
  29. {codex_telegram_bridge-0.9.2 → codex_telegram_bridge-0.9.3}/tests/test_public_export.py +0 -0
  30. {codex_telegram_bridge-0.9.2 → codex_telegram_bridge-0.9.3}/tests/test_repl_bridge.py +0 -0
  31. {codex_telegram_bridge-0.9.2 → codex_telegram_bridge-0.9.3}/tests/test_repl_transport.py +0 -0
  32. {codex_telegram_bridge-0.9.2 → codex_telegram_bridge-0.9.3}/tests/test_setup_wizard.py +0 -0
  33. {codex_telegram_bridge-0.9.2 → codex_telegram_bridge-0.9.3}/tests/test_watchdog.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: codex-telegram-bridge
3
- Version: 0.9.2
3
+ Version: 0.9.3
4
4
  Summary: Control a live Codex CLI session from Telegram.
5
5
  Author: Kang Daejong
6
6
  License: MIT
@@ -981,6 +981,7 @@ def writer_loop(
981
981
  inputs: OrderedInputQueue,
982
982
  stop: threading.Event,
983
983
  input_activity: dict[str, int] | None = None,
984
+ live: Any | None = None,
984
985
  ) -> None:
985
986
  while not stop.is_set() and pty.alive():
986
987
  try:
@@ -992,12 +993,171 @@ def writer_loop(
992
993
  try:
993
994
  if input_activity is not None and input_activity.get("first_ns", 0) == 0:
994
995
  input_activity["first_ns"] = time.time_ns()
996
+ # 텔레그램 주입은 무에코라 콘솔에 흔적이 없다 — 라이브 파일에만 마커를 남겨
997
+ # 뷰어에서 "무엇이 주입됐는지" 가 보이게 한다 (T-260722-066).
998
+ if live is not None and frame.source == "ipc":
999
+ live.note(f"주입 <- {summarize_injection(frame.payload)}")
995
1000
  pty.write(frame.payload)
996
1001
  except OSError:
997
1002
  stop.set()
998
1003
  return
999
1004
 
1000
1005
 
1006
+ DEFAULT_LIVE_RAW_MAX_BYTES = 8 * 1024 * 1024
1007
+
1008
+
1009
+ def default_live_raw_path() -> Path:
1010
+ """호스트 state_path 와 같은 관례(LOCALAPPDATA/codex-telegram-bridge/)를 쓴다."""
1011
+ base = os.environ.get("LOCALAPPDATA") or str(Path.home())
1012
+ return Path(base) / "codex-telegram-bridge" / "conpty-live.raw"
1013
+
1014
+
1015
+ class LiveRawSink:
1016
+ """conpty raw 출력을 stdout 과 append-only 파일에 동시에 흘리는 tee (T-260722-066).
1017
+
1018
+ 발원: 사용자 실사용 증상 — PowerShell 에서 세션 접속은 되는데 텔레그램 주입
1019
+ 프롬프트·출력이 터미널에 안 보인다. 근본원인은 버그가 아니라 가시성 설계갭으로,
1020
+ raw 출력이 인메모리 RawOutputBuffer 에만 남아 밖에서 볼 방법이 없었다. 파일로
1021
+ 흘려 뷰어(codex-conpty-live-view.ps1)가 tail 할 수 있게 한다.
1022
+
1023
+ 설계 제약:
1024
+ - 파일 IO 실패가 호스트를 죽이면 안 된다 → 1회 경고 후 stdout 전용으로 강등.
1025
+ - 콘솔 출력이 파일 문제로 유실되면 안 된다 → passthrough 를 먼저 쓴다.
1026
+ - 무한증식 금지 → 크기 상한 초과 시 <path>.1 로 1회전(총 2배 상한).
1027
+ - 주입 무에코 설계 유지 → note() 마커는 **파일에만** 쓴다. stdout 에 쓰면
1028
+ codex TUI 로 에코되어 렌더링을 깨고 무에코 계약을 위반한다.
1029
+ """
1030
+
1031
+ def __init__(
1032
+ self,
1033
+ path: Path,
1034
+ passthrough: Any,
1035
+ max_bytes: int = DEFAULT_LIVE_RAW_MAX_BYTES,
1036
+ ) -> None:
1037
+ self._path = path
1038
+ self._passthrough = passthrough
1039
+ self._max_bytes = max(0, int(max_bytes))
1040
+ self._lock = threading.Lock()
1041
+ self._handle: Any | None = None
1042
+ self._size = 0
1043
+ self._degraded = False
1044
+ self._open()
1045
+
1046
+ @property
1047
+ def path(self) -> Path:
1048
+ return self._path
1049
+
1050
+ def _open(self) -> None:
1051
+ try:
1052
+ self._path.parent.mkdir(parents=True, exist_ok=True)
1053
+ self._handle = open(self._path, "ab", buffering=0)
1054
+ self._size = self._path.stat().st_size
1055
+ except OSError as exc:
1056
+ self._degrade(f"open {self._path} failed: {exc}")
1057
+
1058
+ def _degrade(self, reason: str) -> None:
1059
+ if not self._degraded:
1060
+ self._degraded = True
1061
+ safe_log(f"live raw sink disabled ({reason}); stdout only")
1062
+ handle, self._handle = self._handle, None
1063
+ if handle is not None:
1064
+ try:
1065
+ handle.close()
1066
+ except OSError:
1067
+ pass
1068
+
1069
+ def _rotate_locked(self) -> None:
1070
+ handle, self._handle = self._handle, None
1071
+ if handle is not None:
1072
+ try:
1073
+ handle.close()
1074
+ except OSError:
1075
+ pass
1076
+ try:
1077
+ rotated = self._path.with_name(self._path.name + ".1")
1078
+ os.replace(self._path, rotated)
1079
+ except OSError as exc:
1080
+ self._degrade(f"rotate failed: {exc}")
1081
+ return
1082
+ self._open()
1083
+
1084
+ def _write_file_locked(self, data: bytes) -> None:
1085
+ if self._handle is None:
1086
+ return
1087
+ if self._max_bytes and self._size + len(data) > self._max_bytes:
1088
+ self._rotate_locked()
1089
+ if self._handle is None:
1090
+ return
1091
+ try:
1092
+ self._handle.write(data)
1093
+ self._size += len(data)
1094
+ except OSError as exc:
1095
+ self._degrade(f"write failed: {exc}")
1096
+
1097
+ def write(self, data: bytes) -> int:
1098
+ # 콘솔이 먼저다 — 파일 쪽 문제로 사람이 보는 출력을 잃지 않는다.
1099
+ written = self._passthrough.write(data)
1100
+ with self._lock:
1101
+ self._write_file_locked(data)
1102
+ return written if written is not None else len(data)
1103
+
1104
+ def flush(self) -> None:
1105
+ try:
1106
+ self._passthrough.flush()
1107
+ finally:
1108
+ with self._lock:
1109
+ if self._handle is not None:
1110
+ try:
1111
+ self._handle.flush()
1112
+ except OSError as exc:
1113
+ self._degrade(f"flush failed: {exc}")
1114
+
1115
+ def note(self, text: str) -> None:
1116
+ """사람이 읽는 이벤트 마커 1줄 — 파일 전용(stdout 무에코 계약 유지)."""
1117
+ stamp = time.strftime("%Y-%m-%d %H:%M:%S")
1118
+ line = f"\r\n[{stamp}] {text}\r\n".encode("utf-8", "replace")
1119
+ with self._lock:
1120
+ self._write_file_locked(line)
1121
+
1122
+ def close(self) -> None:
1123
+ with self._lock:
1124
+ handle, self._handle = self._handle, None
1125
+ if handle is not None:
1126
+ try:
1127
+ handle.close()
1128
+ except OSError:
1129
+ pass
1130
+
1131
+
1132
+ def summarize_injection(payload: bytes, limit: int = 120) -> str:
1133
+ """주입 페이로드를 마커용 1줄 요약으로 축약한다 (제어문자 제거·길이 컷)."""
1134
+ text = payload.decode("utf-8", "replace")
1135
+ text = re.sub(r"[\x00-\x1f\x7f]+", " ", text)
1136
+ text = re.sub(r"\s+", " ", text).strip()
1137
+ if not text:
1138
+ return "(제어 키 입력)"
1139
+ if len(text) > limit:
1140
+ return text[:limit] + f"… (+{len(text) - limit}자)"
1141
+ return text
1142
+
1143
+
1144
+ def build_live_raw_sink(passthrough: Any) -> LiveRawSink | None:
1145
+ """env 로 경로·상한을 정한다. 경로를 빈 문자열로 두면 비활성."""
1146
+ configured = os.environ.get("CODEX_CONPTY_LIVE_RAW")
1147
+ if configured is None:
1148
+ target = default_live_raw_path()
1149
+ else:
1150
+ raw_path = configured.strip()
1151
+ if not raw_path:
1152
+ return None
1153
+ target = Path(raw_path).expanduser()
1154
+ try:
1155
+ max_bytes = int(os.environ.get("CODEX_CONPTY_LIVE_MAX_BYTES", DEFAULT_LIVE_RAW_MAX_BYTES))
1156
+ except ValueError:
1157
+ max_bytes = DEFAULT_LIVE_RAW_MAX_BYTES
1158
+ return LiveRawSink(target, passthrough, max_bytes)
1159
+
1160
+
1001
1161
  def output_loop(
1002
1162
  pty: WindowsConPty,
1003
1163
  output: RawOutputBuffer,
@@ -1126,8 +1286,18 @@ def run_host(args: argparse.Namespace) -> int:
1126
1286
  session_holder: dict[str, Path | None] = {"path": None}
1127
1287
  input_activity: dict[str, int] = {"first_ns": 0}
1128
1288
 
1289
+ # raw 출력을 append-only 파일로도 흘린다 — 뷰어가 tail 해서 사용자 콘솔에 실시간
1290
+ # 표시할 수 있게 하는 배관 (T-260722-066). 실패해도 stdout 전용으로 계속 돈다.
1291
+ live_sink = build_live_raw_sink(sys.stdout.buffer)
1292
+ if live_sink is not None:
1293
+ safe_log(f"live raw sink -> {live_sink.path}")
1294
+ live_sink.note(f"conpty host start pid={child_pid} generation={generation[:8]}")
1295
+
1129
1296
  output_thread = threading.Thread(
1130
- target=output_loop, args=(pty, output, stop), daemon=True, name="conpty-output"
1297
+ target=output_loop,
1298
+ args=(pty, output, stop, live_sink),
1299
+ daemon=True,
1300
+ name="conpty-output",
1131
1301
  )
1132
1302
  output_thread.start()
1133
1303
  keyboard_thread = threading.Thread(
@@ -1152,7 +1322,7 @@ def run_host(args: argparse.Namespace) -> int:
1152
1322
  return 3
1153
1323
  writer_thread = threading.Thread(
1154
1324
  target=writer_loop,
1155
- args=(pty, inputs, stop, input_activity),
1325
+ args=(pty, inputs, stop, input_activity, live_sink),
1156
1326
  daemon=True,
1157
1327
  name="conpty-input",
1158
1328
  )
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: codex-telegram-bridge
3
- Version: 0.9.2
3
+ Version: 0.9.3
4
4
  Summary: Control a live Codex CLI session from Telegram.
5
5
  Author: Kang Daejong
6
6
  License: MIT
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "codex-telegram-bridge"
7
- version = "0.9.2"
7
+ version = "0.9.3"
8
8
  description = "Control a live Codex CLI session from Telegram."
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.10"
@@ -112,7 +112,7 @@ class BridgeTests(unittest.TestCase):
112
112
  bridge = tab.Bridge(cfg, tab.CodexBackend(cfg), FakeTelegram())
113
113
 
114
114
  self.assertEqual(bridge.telegram_chunks("🙂😄👋 answer"), ["answer"])
115
- self.assertEqual(bridge.telegram_chunks("🍎"), ["🍎"])
115
+ self.assertEqual(bridge.telegram_chunks("🎉"), ["🎉"])
116
116
 
117
117
  def test_group_chat_keeps_prefix(self):
118
118
  with tempfile.TemporaryDirectory() as tmpdir: