code-puppy 1.0.1__tar.gz → 1.0.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.
- {code_puppy-1.0.1 → code_puppy-1.0.3}/PKG-INFO +1 -1
- {code_puppy-1.0.1 → code_puppy-1.0.3}/code_puppy/main.py +32 -1
- {code_puppy-1.0.1 → code_puppy-1.0.3}/code_puppy/splash/__init__.py +65 -3
- {code_puppy-1.0.1 → code_puppy-1.0.3}/pyproject.toml +1 -1
- {code_puppy-1.0.1 → code_puppy-1.0.3}/.gitignore +0 -0
- {code_puppy-1.0.1 → code_puppy-1.0.3}/LICENSE +0 -0
- {code_puppy-1.0.1 → code_puppy-1.0.3}/README.md +0 -0
- {code_puppy-1.0.1 → code_puppy-1.0.3}/code_puppy/__init__.py +0 -0
- {code_puppy-1.0.1 → code_puppy-1.0.3}/code_puppy/__main__.py +0 -0
- {code_puppy-1.0.1 → code_puppy-1.0.3}/code_puppy/_art.py +0 -0
- {code_puppy-1.0.1 → code_puppy-1.0.3}/code_puppy/api_keys.py +0 -0
- {code_puppy-1.0.1 → code_puppy-1.0.3}/code_puppy/branding.py +0 -0
- {code_puppy-1.0.1 → code_puppy-1.0.3}/code_puppy/builtin_plugins.py +0 -0
- {code_puppy-1.0.1 → code_puppy-1.0.3}/code_puppy/callbacks.py +0 -0
- {code_puppy-1.0.1 → code_puppy-1.0.3}/code_puppy/colors.py +0 -0
- {code_puppy-1.0.1 → code_puppy-1.0.3}/code_puppy/compat/__init__.py +0 -0
- {code_puppy-1.0.1 → code_puppy-1.0.3}/code_puppy/compat/bridge.py +0 -0
- {code_puppy-1.0.1 → code_puppy-1.0.3}/code_puppy/compat/tools.py +0 -0
- {code_puppy-1.0.1 → code_puppy-1.0.3}/code_puppy/config.py +0 -0
- {code_puppy-1.0.1 → code_puppy-1.0.3}/code_puppy/distribution.py +0 -0
- {code_puppy-1.0.1 → code_puppy-1.0.3}/code_puppy/first_run.py +0 -0
- {code_puppy-1.0.1 → code_puppy-1.0.3}/code_puppy/former_name.py +0 -0
- {code_puppy-1.0.1 → code_puppy-1.0.3}/code_puppy/i18n/__init__.py +0 -0
- {code_puppy-1.0.1 → code_puppy-1.0.3}/code_puppy/identity.py +0 -0
- {code_puppy-1.0.1 → code_puppy-1.0.3}/code_puppy/legacy_sessions.py +0 -0
- {code_puppy-1.0.1 → code_puppy-1.0.3}/code_puppy/legacy_store.py +0 -0
- {code_puppy-1.0.1 → code_puppy-1.0.3}/code_puppy/messaging/__init__.py +0 -0
- {code_puppy-1.0.1 → code_puppy-1.0.3}/code_puppy/messaging/bus.py +0 -0
- {code_puppy-1.0.1 → code_puppy-1.0.3}/code_puppy/migrate/__init__.py +0 -0
- {code_puppy-1.0.1 → code_puppy-1.0.3}/code_puppy/migrate/runner.py +0 -0
- {code_puppy-1.0.1 → code_puppy-1.0.3}/code_puppy/migrate/sources.py +0 -0
- {code_puppy-1.0.1 → code_puppy-1.0.3}/code_puppy/migrate/translate.py +0 -0
- {code_puppy-1.0.1 → code_puppy-1.0.3}/code_puppy/personality.py +0 -0
- {code_puppy-1.0.1 → code_puppy-1.0.3}/code_puppy/plugins/__init__.py +0 -0
- {code_puppy-1.0.1 → code_puppy-1.0.3}/code_puppy/plugins/source_only.py +0 -0
- {code_puppy-1.0.1 → code_puppy-1.0.3}/code_puppy/plugins/trust.py +0 -0
- {code_puppy-1.0.1 → code_puppy-1.0.3}/code_puppy/splash/__main__.py +0 -0
- {code_puppy-1.0.1 → code_puppy-1.0.3}/code_puppy/splash/canvas.py +0 -0
- {code_puppy-1.0.1 → code_puppy-1.0.3}/code_puppy/splash/scenes.py +0 -0
- {code_puppy-1.0.1 → code_puppy-1.0.3}/code_puppy/update.py +0 -0
|
@@ -7,15 +7,20 @@ it animates. The order below is load-bearing; see ``distribution``.
|
|
|
7
7
|
from __future__ import annotations
|
|
8
8
|
|
|
9
9
|
import json
|
|
10
|
+
import logging
|
|
10
11
|
import os
|
|
11
12
|
import sqlite3
|
|
12
13
|
import sys
|
|
13
14
|
import warnings
|
|
15
|
+
from collections.abc import Iterator
|
|
16
|
+
from contextlib import contextmanager
|
|
14
17
|
from pathlib import Path
|
|
15
18
|
|
|
16
19
|
from code_puppy import identity
|
|
17
20
|
|
|
18
21
|
NO_SPLASH_VARIABLES = ("CODE_PUPPY_NO_SPLASH", "CLAI_NO_SPLASH")
|
|
22
|
+
WSAECONNRESET = 10054
|
|
23
|
+
"""Windows' "connection forcibly closed by the remote host"."""
|
|
19
24
|
|
|
20
25
|
|
|
21
26
|
def _load_dotenv() -> None:
|
|
@@ -105,6 +110,32 @@ def _own_command(argv: list[str]) -> int | None:
|
|
|
105
110
|
return migrate.main(argv[2:])
|
|
106
111
|
|
|
107
112
|
|
|
113
|
+
def _not_a_peer_reset(record: logging.LogRecord) -> bool:
|
|
114
|
+
exc = record.exc_info[1] if record.exc_info else None
|
|
115
|
+
return not (
|
|
116
|
+
isinstance(exc, ConnectionResetError)
|
|
117
|
+
and getattr(exc, "winerror", None) == WSAECONNRESET
|
|
118
|
+
)
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
@contextmanager
|
|
122
|
+
def quiet_peer_resets() -> Iterator[None]:
|
|
123
|
+
"""Keep Windows' WinError 10054 socket-teardown traceback off the live display.
|
|
124
|
+
|
|
125
|
+
When a server drops an idle keep-alive connection, asyncio's Proactor loop
|
|
126
|
+
raises it while closing the socket and logs it on the ``asyncio`` logger.
|
|
127
|
+
The connection was already gone; nothing is lost. Only this record is
|
|
128
|
+
dropped: every other asyncio error still reaches stderr. Remove once
|
|
129
|
+
pydantic/pydantic-ai#14639 ships in the pinned pax.
|
|
130
|
+
"""
|
|
131
|
+
logger = logging.getLogger("asyncio")
|
|
132
|
+
logger.addFilter(_not_a_peer_reset)
|
|
133
|
+
try:
|
|
134
|
+
yield
|
|
135
|
+
finally:
|
|
136
|
+
logger.removeFilter(_not_a_peer_reset)
|
|
137
|
+
|
|
138
|
+
|
|
108
139
|
def main_entry() -> None:
|
|
109
140
|
"""Start Code Puppy: pydantic-ai-pax with Code Puppy's identity installed."""
|
|
110
141
|
_load_dotenv()
|
|
@@ -131,7 +162,7 @@ def main_entry() -> None:
|
|
|
131
162
|
from pydantic_ai_pax.__main__ import quiet_telemetry_logs
|
|
132
163
|
from pydantic_ai_pax.cli.cli import run
|
|
133
164
|
|
|
134
|
-
with warnings.catch_warnings(), quiet_telemetry_logs():
|
|
165
|
+
with warnings.catch_warnings(), quiet_telemetry_logs(), quiet_peer_resets():
|
|
135
166
|
if not sys.warnoptions:
|
|
136
167
|
# Library warnings are advice for whoever wired the agent, not
|
|
137
168
|
# the person at the prompt, and stderr output tears through the
|
|
@@ -8,6 +8,7 @@ Each launch plays one of :data:`SCENES`, picked at random.
|
|
|
8
8
|
|
|
9
9
|
from __future__ import annotations
|
|
10
10
|
|
|
11
|
+
import atexit
|
|
11
12
|
import codecs
|
|
12
13
|
import contextlib
|
|
13
14
|
import io
|
|
@@ -16,6 +17,7 @@ import random
|
|
|
16
17
|
import shutil
|
|
17
18
|
import sys
|
|
18
19
|
import threading
|
|
20
|
+
from collections.abc import Callable
|
|
19
21
|
|
|
20
22
|
from code_puppy.splash.canvas import Canvas, truecolor
|
|
21
23
|
from code_puppy.splash.scenes import SCENES, Scene, caption
|
|
@@ -46,6 +48,58 @@ def _speaks_unicode(stream: object) -> bool:
|
|
|
46
48
|
return False
|
|
47
49
|
|
|
48
50
|
|
|
51
|
+
def _nothing() -> None:
|
|
52
|
+
"""Nothing to undo."""
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
def _enable_windows_vt(fd: int) -> Callable[[], None] | None:
|
|
56
|
+
"""Switch on escape handling for the Windows console behind ``fd``.
|
|
57
|
+
|
|
58
|
+
Windows 10 and later understand escapes once virtual terminal processing
|
|
59
|
+
is on; Windows Terminal turns it on by itself. Returns what switches it
|
|
60
|
+
off again, or None if ``fd`` is not a console or it refuses.
|
|
61
|
+
"""
|
|
62
|
+
import ctypes
|
|
63
|
+
import msvcrt
|
|
64
|
+
|
|
65
|
+
enable_virtual_terminal_processing = 0x0004
|
|
66
|
+
kernel32 = ctypes.WinDLL("kernel32", use_last_error=True)
|
|
67
|
+
handle = msvcrt.get_osfhandle(fd)
|
|
68
|
+
mode = ctypes.c_ulong()
|
|
69
|
+
if not kernel32.GetConsoleMode(handle, ctypes.byref(mode)):
|
|
70
|
+
return None
|
|
71
|
+
original = mode.value
|
|
72
|
+
if original & enable_virtual_terminal_processing:
|
|
73
|
+
return _nothing
|
|
74
|
+
if not kernel32.SetConsoleMode(
|
|
75
|
+
handle, original | enable_virtual_terminal_processing
|
|
76
|
+
):
|
|
77
|
+
return None
|
|
78
|
+
|
|
79
|
+
def restore() -> None:
|
|
80
|
+
"""Switch escapes off, keeping whatever else changed the mode since."""
|
|
81
|
+
if kernel32.GetConsoleMode(handle, ctypes.byref(mode)):
|
|
82
|
+
kernel32.SetConsoleMode(
|
|
83
|
+
handle, mode.value & ~enable_virtual_terminal_processing
|
|
84
|
+
)
|
|
85
|
+
|
|
86
|
+
return restore
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
def _switch_on_escapes(stream: object) -> Callable[[], None] | None:
|
|
90
|
+
"""Make ``stream``'s terminal act on escapes; return what undoes that.
|
|
91
|
+
|
|
92
|
+
POSIX terminals always do, so there is nothing to undo. None if the
|
|
93
|
+
terminal would print escapes instead of acting on them.
|
|
94
|
+
"""
|
|
95
|
+
if sys.platform != "win32":
|
|
96
|
+
return _nothing
|
|
97
|
+
try:
|
|
98
|
+
return _enable_windows_vt(stream.fileno()) # type: ignore[attr-defined]
|
|
99
|
+
except (AttributeError, ImportError, OSError, ValueError):
|
|
100
|
+
return None
|
|
101
|
+
|
|
102
|
+
|
|
49
103
|
class Splash:
|
|
50
104
|
"""Own the alternate screen and animate a scene until :meth:`stop`."""
|
|
51
105
|
|
|
@@ -67,7 +121,6 @@ class Splash:
|
|
|
67
121
|
and os.getenv("TERM") != "dumb"
|
|
68
122
|
and size.columns >= MIN_COLUMNS
|
|
69
123
|
and size.lines >= MIN_LINES
|
|
70
|
-
and sys.platform != "win32"
|
|
71
124
|
and _speaks_unicode(self._stream)
|
|
72
125
|
)
|
|
73
126
|
|
|
@@ -84,18 +137,27 @@ class Splash:
|
|
|
84
137
|
def start(self) -> None:
|
|
85
138
|
"""Start one animation thread and hold back output until :meth:`stop`.
|
|
86
139
|
|
|
87
|
-
Output is held back only once the thread runs: if
|
|
88
|
-
|
|
140
|
+
Output is held back only once the thread runs: if the terminal cannot
|
|
141
|
+
act on escapes or the thread cannot start, startup carries on without
|
|
142
|
+
the animation, with its streams and terminal intact.
|
|
143
|
+
|
|
144
|
+
Escapes switched on stay on until exit, not just until :meth:`stop`:
|
|
145
|
+
whatever draws after the splash chose how to draw while they were on.
|
|
89
146
|
"""
|
|
90
147
|
if not self._enabled or self._thread is not None:
|
|
91
148
|
return
|
|
149
|
+
undo = _switch_on_escapes(self._stream)
|
|
150
|
+
if undo is None:
|
|
151
|
+
return
|
|
92
152
|
thread = threading.Thread(
|
|
93
153
|
target=self._run, name="code-puppy-splash", daemon=True
|
|
94
154
|
)
|
|
95
155
|
try:
|
|
96
156
|
thread.start()
|
|
97
157
|
except RuntimeError: # "can't start new thread": no animation, that's all
|
|
158
|
+
undo()
|
|
98
159
|
return
|
|
160
|
+
atexit.register(undo)
|
|
99
161
|
self._thread = thread
|
|
100
162
|
sys.stdout, sys.stderr = self._buffers
|
|
101
163
|
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|