portacode 0.3.4.dev0__py3-none-any.whl → 1.4.11.dev0__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.

Potentially problematic release.


This version of portacode might be problematic. Click here for more details.

Files changed (93) hide show
  1. portacode/_version.py +16 -3
  2. portacode/cli.py +155 -19
  3. portacode/connection/client.py +152 -12
  4. portacode/connection/handlers/WEBSOCKET_PROTOCOL.md +1577 -0
  5. portacode/connection/handlers/__init__.py +43 -1
  6. portacode/connection/handlers/base.py +122 -18
  7. portacode/connection/handlers/chunked_content.py +244 -0
  8. portacode/connection/handlers/diff_handlers.py +603 -0
  9. portacode/connection/handlers/file_handlers.py +902 -17
  10. portacode/connection/handlers/project_aware_file_handlers.py +226 -0
  11. portacode/connection/handlers/project_state/README.md +312 -0
  12. portacode/connection/handlers/project_state/__init__.py +92 -0
  13. portacode/connection/handlers/project_state/file_system_watcher.py +179 -0
  14. portacode/connection/handlers/project_state/git_manager.py +1502 -0
  15. portacode/connection/handlers/project_state/handlers.py +875 -0
  16. portacode/connection/handlers/project_state/manager.py +1331 -0
  17. portacode/connection/handlers/project_state/models.py +108 -0
  18. portacode/connection/handlers/project_state/utils.py +50 -0
  19. portacode/connection/handlers/project_state_handlers.py +45 -0
  20. portacode/connection/handlers/proxmox_infra.py +307 -0
  21. portacode/connection/handlers/registry.py +53 -10
  22. portacode/connection/handlers/session.py +705 -53
  23. portacode/connection/handlers/system_handlers.py +142 -8
  24. portacode/connection/handlers/tab_factory.py +389 -0
  25. portacode/connection/handlers/terminal_handlers.py +150 -11
  26. portacode/connection/handlers/update_handler.py +61 -0
  27. portacode/connection/multiplex.py +60 -2
  28. portacode/connection/terminal.py +695 -28
  29. portacode/keypair.py +63 -1
  30. portacode/link_capture/__init__.py +38 -0
  31. portacode/link_capture/__pycache__/__init__.cpython-311.pyc +0 -0
  32. portacode/link_capture/bin/__pycache__/link_capture_wrapper.cpython-311.pyc +0 -0
  33. portacode/link_capture/bin/elinks +3 -0
  34. portacode/link_capture/bin/gio-open +3 -0
  35. portacode/link_capture/bin/gnome-open +3 -0
  36. portacode/link_capture/bin/gvfs-open +3 -0
  37. portacode/link_capture/bin/kde-open +3 -0
  38. portacode/link_capture/bin/kfmclient +3 -0
  39. portacode/link_capture/bin/link_capture_exec.sh +11 -0
  40. portacode/link_capture/bin/link_capture_wrapper.py +75 -0
  41. portacode/link_capture/bin/links +3 -0
  42. portacode/link_capture/bin/links2 +3 -0
  43. portacode/link_capture/bin/lynx +3 -0
  44. portacode/link_capture/bin/mate-open +3 -0
  45. portacode/link_capture/bin/netsurf +3 -0
  46. portacode/link_capture/bin/sensible-browser +3 -0
  47. portacode/link_capture/bin/w3m +3 -0
  48. portacode/link_capture/bin/x-www-browser +3 -0
  49. portacode/link_capture/bin/xdg-open +3 -0
  50. portacode/logging_categories.py +140 -0
  51. portacode/pairing.py +103 -0
  52. portacode/service.py +6 -0
  53. portacode/static/js/test-ntp-clock.html +63 -0
  54. portacode/static/js/utils/ntp-clock.js +232 -0
  55. portacode/utils/NTP_ARCHITECTURE.md +136 -0
  56. portacode/utils/__init__.py +1 -0
  57. portacode/utils/diff_apply.py +456 -0
  58. portacode/utils/diff_renderer.py +371 -0
  59. portacode/utils/ntp_clock.py +65 -0
  60. portacode-1.4.11.dev0.dist-info/METADATA +298 -0
  61. portacode-1.4.11.dev0.dist-info/RECORD +97 -0
  62. {portacode-0.3.4.dev0.dist-info → portacode-1.4.11.dev0.dist-info}/WHEEL +1 -1
  63. portacode-1.4.11.dev0.dist-info/top_level.txt +3 -0
  64. test_modules/README.md +296 -0
  65. test_modules/__init__.py +1 -0
  66. test_modules/test_device_online.py +44 -0
  67. test_modules/test_file_operations.py +743 -0
  68. test_modules/test_git_status_ui.py +370 -0
  69. test_modules/test_login_flow.py +50 -0
  70. test_modules/test_navigate_testing_folder.py +361 -0
  71. test_modules/test_play_store_screenshots.py +294 -0
  72. test_modules/test_terminal_buffer_performance.py +261 -0
  73. test_modules/test_terminal_interaction.py +80 -0
  74. test_modules/test_terminal_loading_race_condition.py +95 -0
  75. test_modules/test_terminal_start.py +56 -0
  76. testing_framework/.env.example +21 -0
  77. testing_framework/README.md +334 -0
  78. testing_framework/__init__.py +17 -0
  79. testing_framework/cli.py +326 -0
  80. testing_framework/core/__init__.py +1 -0
  81. testing_framework/core/base_test.py +336 -0
  82. testing_framework/core/cli_manager.py +177 -0
  83. testing_framework/core/hierarchical_runner.py +577 -0
  84. testing_framework/core/playwright_manager.py +520 -0
  85. testing_framework/core/runner.py +447 -0
  86. testing_framework/core/shared_cli_manager.py +234 -0
  87. testing_framework/core/test_discovery.py +112 -0
  88. testing_framework/requirements.txt +12 -0
  89. portacode-0.3.4.dev0.dist-info/METADATA +0 -236
  90. portacode-0.3.4.dev0.dist-info/RECORD +0 -27
  91. portacode-0.3.4.dev0.dist-info/top_level.txt +0 -1
  92. {portacode-0.3.4.dev0.dist-info → portacode-1.4.11.dev0.dist-info}/entry_points.txt +0 -0
  93. {portacode-0.3.4.dev0.dist-info → portacode-1.4.11.dev0.dist-info/licenses}/LICENSE +0 -0
@@ -0,0 +1,232 @@
1
+ /**
2
+ * NTP Clock - Synchronized time source for distributed tracing
3
+ *
4
+ * Provides synchronization by requesting the server clock across the WebSocket
5
+ * channel defined in `WEBSOCKET_PROTOCOL`. The client measures round-trip time
6
+ * and applies an offset that compensates for latency before exposing timestamps.
7
+ */
8
+ class NTPClock {
9
+ constructor() {
10
+ this.ntpServer = 'portacode-gateway';
11
+ this.offset = null;
12
+ this.lastSync = null;
13
+ this.lastLatencyMs = null;
14
+ this.syncInterval = 60 * 1000;
15
+ this.clockSyncTimeout = 20 * 1000;
16
+ this.maxSyncFailures = 3;
17
+
18
+ this._clockSyncSender = null;
19
+ this._failureCallback = null;
20
+ this._clockSyncTimer = null;
21
+ this._clockSyncTimeoutHandle = null;
22
+ this._pendingRequest = null;
23
+ this._autoSyncStarted = false;
24
+ this._clockSyncFailures = 0;
25
+ }
26
+
27
+ /**
28
+ * Register the function responsible for piping `clock_sync_request`
29
+ * packets over the dashboard WebSocket.
30
+ */
31
+ setClockSyncSender(sender) {
32
+ this._clockSyncSender = sender;
33
+ if (this._autoSyncStarted && !this._pendingRequest) {
34
+ this._scheduleSync(0);
35
+ }
36
+ }
37
+
38
+ /**
39
+ * Callback invoked when multiple sync failures occur in a row.
40
+ * Useful for triggering a transport reconnect.
41
+ */
42
+ onClockSyncFailure(callback) {
43
+ this._failureCallback = callback;
44
+ }
45
+
46
+ /**
47
+ * Start the auto-sync loop (idempotent). Will skip sending until a sender
48
+ * has been registered.
49
+ */
50
+ startAutoSync() {
51
+ if (this._autoSyncStarted) {
52
+ return;
53
+ }
54
+ this._autoSyncStarted = true;
55
+ this._scheduleSync(0);
56
+ }
57
+
58
+ /**
59
+ * Stop the auto-sync loop (used primarily in tests).
60
+ */
61
+ stopAutoSync() {
62
+ this._autoSyncStarted = false;
63
+ if (this._clockSyncTimer) {
64
+ clearTimeout(this._clockSyncTimer);
65
+ this._clockSyncTimer = null;
66
+ }
67
+ this._clearPendingRequest();
68
+ }
69
+
70
+ sync() {
71
+ return this._performClockSync();
72
+ }
73
+
74
+ /**
75
+ * Get current NTP-synchronized timestamp in milliseconds since epoch
76
+ * Returns null if not synced
77
+ */
78
+ now() {
79
+ if (this.offset === null) {
80
+ return null;
81
+ }
82
+ return Date.now() + this.offset;
83
+ }
84
+
85
+ /**
86
+ * Get current NTP-synchronized timestamp in ISO format
87
+ * Returns null if not synced
88
+ */
89
+ nowISO() {
90
+ const ts = this.now();
91
+ if (ts === null) {
92
+ return null;
93
+ }
94
+ return new Date(ts).toISOString();
95
+ }
96
+
97
+ handleServerSync(payload) {
98
+ if (!payload) {
99
+ return;
100
+ }
101
+ const receiveTime = Date.now();
102
+ let roundTrip = 0;
103
+ if (
104
+ payload.request_id &&
105
+ this._pendingRequest &&
106
+ payload.request_id === this._pendingRequest.requestId
107
+ ) {
108
+ roundTrip = Math.max(receiveTime - this._pendingRequest.sentAt, 0);
109
+ this._clockSyncFailures = 0;
110
+ this._clearPendingRequest();
111
+ }
112
+ const serverSend = typeof payload.server_send_time === 'number' ? payload.server_send_time : payload.server_time;
113
+ const serverReceive = payload.server_receive_time;
114
+ const serverAvg = (typeof serverReceive === 'number' && typeof serverSend === 'number')
115
+ ? (serverReceive + serverSend) / 2
116
+ : typeof serverSend === 'number'
117
+ ? serverSend
118
+ : undefined;
119
+ if (typeof serverAvg === 'number') {
120
+ this.updateFromServer(serverAvg, roundTrip);
121
+ }
122
+ if (payload.server_time_iso) {
123
+ this.serverTimeIso = payload.server_time_iso;
124
+ }
125
+ this._scheduleSync(this.syncInterval);
126
+ }
127
+
128
+ applyServerSync(payload) {
129
+ this.handleServerSync(payload);
130
+ }
131
+
132
+ updateFromServer(serverTimeMs, roundTripMs = 0) {
133
+ const receiveTime = Date.now();
134
+ const halfLatency = (roundTripMs || 0) / 2;
135
+ const estimatedServerReceived = receiveTime - halfLatency;
136
+ this.offset = serverTimeMs - estimatedServerReceived;
137
+ this.lastLatencyMs = roundTripMs;
138
+ this.lastSync = receiveTime;
139
+ }
140
+
141
+ getStatus() {
142
+ return {
143
+ server: this.ntpServer,
144
+ offset: this.offset,
145
+ lastSync: this.lastSync ? new Date(this.lastSync).toISOString() : null,
146
+ lastLatencyMs: this.lastLatencyMs,
147
+ timeSinceSync: this.lastSync ? Date.now() - this.lastSync : null,
148
+ isSynced: this.offset !== null
149
+ };
150
+ }
151
+
152
+ _scheduleSync(delay) {
153
+ if (!this._autoSyncStarted) {
154
+ return;
155
+ }
156
+ if (this._clockSyncTimer) {
157
+ clearTimeout(this._clockSyncTimer);
158
+ }
159
+ this._clockSyncTimer = setTimeout(() => this._performClockSync(), delay);
160
+ }
161
+
162
+ _performClockSync() {
163
+ if (!this._autoSyncStarted) {
164
+ return false;
165
+ }
166
+ if (!this._clockSyncSender) {
167
+ this._scheduleSync(Math.min(this.syncInterval, 3000));
168
+ return false;
169
+ }
170
+ if (this._pendingRequest) {
171
+ return false;
172
+ }
173
+ const requestId = this._generateRequestId();
174
+ const payload = {
175
+ event: 'clock_sync_request',
176
+ request_id: requestId,
177
+ };
178
+ this._pendingRequest = {
179
+ requestId,
180
+ sentAt: Date.now(),
181
+ };
182
+ const sent = this._clockSyncSender(payload);
183
+ if (!sent) {
184
+ this._handleClockSyncFailure();
185
+ return false;
186
+ }
187
+ this._clockSyncTimeoutHandle = setTimeout(() => this._handleClockSyncTimeout(), this.clockSyncTimeout);
188
+ return true;
189
+ }
190
+
191
+ _handleClockSyncTimeout() {
192
+ this._clockSyncFailures += 1;
193
+ this._clearPendingRequest();
194
+ if (
195
+ this._clockSyncFailures >= this.maxSyncFailures &&
196
+ typeof this._failureCallback === 'function'
197
+ ) {
198
+ this._failureCallback();
199
+ }
200
+ this._scheduleSync(this.syncInterval);
201
+ }
202
+
203
+ _handleClockSyncFailure() {
204
+ this._clockSyncFailures += 1;
205
+ this._clearPendingRequest();
206
+ if (
207
+ this._clockSyncFailures >= this.maxSyncFailures &&
208
+ typeof this._failureCallback === 'function'
209
+ ) {
210
+ this._failureCallback();
211
+ }
212
+ this._scheduleSync(this.syncInterval);
213
+ }
214
+
215
+ _clearPendingRequest() {
216
+ if (this._clockSyncTimeoutHandle) {
217
+ clearTimeout(this._clockSyncTimeoutHandle);
218
+ this._clockSyncTimeoutHandle = null;
219
+ }
220
+ this._pendingRequest = null;
221
+ }
222
+
223
+ _generateRequestId() {
224
+ return `clock_sync:${Date.now()}:${Math.floor(Math.random() * 1000000)}`;
225
+ }
226
+ }
227
+
228
+ // Global instance - auto-starts sync
229
+ const ntpClock = new NTPClock();
230
+ ntpClock.startAutoSync();
231
+
232
+ export default ntpClock;
@@ -0,0 +1,136 @@
1
+ # NTP Clock Architecture
2
+
3
+ ## Overview
4
+
5
+ All entities (client, server, device) synchronize to **time.cloudflare.com** for distributed tracing.
6
+
7
+ ## Architecture: Single Package for Everything
8
+
9
+ All NTP clock implementations (Python and JavaScript) are in the **portacode package** to ensure DRY principles.
10
+
11
+ ## Python Implementation
12
+
13
+ **Location:** `portacode/utils/ntp_clock.py` (in portacode package)
14
+
15
+ ### Import Path
16
+ ```python
17
+ from portacode.utils.ntp_clock import ntp_clock
18
+ ```
19
+
20
+ ### Usage Locations
21
+ 1. **Django Server Consumers** (`server/portacode_django/dashboard/consumers.py`)
22
+ 2. **Device Base Handlers** (`portacode/connection/handlers/base.py`)
23
+ 3. **Device Client** (`server/portacode_django/data/services/device_client.py`)
24
+ 4. **Any Python code with portacode installed**
25
+
26
+ ### Dependencies
27
+ - `setup.py`: Added `ntplib>=0.4.0` to `install_requires`
28
+ - `server/portacode_django/requirements.txt`: Added `portacode>=1.3.26`
29
+
30
+ ### API
31
+ ```python
32
+ # Get NTP-synchronized timestamp (None if not synced)
33
+ ntp_clock.now_ms() # milliseconds
34
+ ntp_clock.now() # seconds
35
+ ntp_clock.now_iso() # ISO format
36
+
37
+ # Check sync status
38
+ status = ntp_clock.get_status()
39
+ # {
40
+ # 'server': 'time.cloudflare.com',
41
+ # 'offset_ms': 6.04,
42
+ # 'last_sync': '2025-10-05T04:37:12.768445+00:00',
43
+ # 'is_synced': True
44
+ # }
45
+ ```
46
+
47
+ ## JavaScript Implementation
48
+
49
+ **Location:** `portacode/static/js/utils/ntp-clock.js` (in portacode package)
50
+
51
+ ### Django Setup
52
+
53
+ Django will serve static files from the portacode package automatically after `collectstatic`:
54
+
55
+ ```python
56
+ # Django settings.py - no changes needed, just ensure:
57
+ INSTALLED_APPS = [
58
+ # ... other apps
59
+ 'portacode', # Add portacode as an installed app (optional, for admin integration)
60
+ ]
61
+
62
+ # Static files will be collected from portacode package
63
+ STATIC_URL = '/static/'
64
+ ```
65
+
66
+ After installing portacode (`pip install portacode` or `pip install -e .`), run:
67
+ ```bash
68
+ python manage.py collectstatic
69
+ ```
70
+
71
+ This will copy `portacode/static/js/utils/ntp-clock.js` to Django's static files directory.
72
+
73
+ ### Import Path (in Django templates/JS)
74
+ ```javascript
75
+ import ntpClock from '/static/js/utils/ntp-clock.js';
76
+ // or relative to your JS file:
77
+ import ntpClock from './utils/ntp-clock.js';
78
+ ```
79
+
80
+ ### Usage Locations
81
+ 1. **Dashboard WebSocket** (`websocket-service.js`)
82
+ 2. **Project WebSocket** (`websocket-service-project.js`)
83
+
84
+ ### API
85
+ ```javascript
86
+ // Get NTP-synchronized timestamp (null if not synced)
87
+ ntpClock.now() // milliseconds
88
+ ntpClock.nowISO() // ISO format
89
+
90
+ // Check sync status
91
+ const status = ntpClock.getStatus();
92
+ // {
93
+ // server: 'time.cloudflare.com',
94
+ // offset: 6.04,
95
+ // lastSync: '2025-10-05T04:37:12.768445+00:00',
96
+ // isSynced: true
97
+ // }
98
+ ```
99
+
100
+ ## Design Principles
101
+
102
+ 1. **DRY (Don't Repeat Yourself)**
103
+ - **Python:** Single implementation in portacode package (`portacode/utils/ntp_clock.py`)
104
+ - **JavaScript:** Single implementation in portacode package (`portacode/static/js/utils/ntp-clock.js`)
105
+ - Both served from the same package, no duplication across repos
106
+
107
+ 2. **No Fallback Servers**
108
+ - All entities MUST sync to time.cloudflare.com
109
+ - If sync fails, timestamps are None/null
110
+ - Ensures all timestamps are comparable
111
+
112
+ 3. **Auto-Sync**
113
+ - Re-syncs every 5 minutes automatically
114
+ - Initial sync on import/load
115
+ - Max 3 retry attempts before marking as failed
116
+
117
+ 4. **Thread-Safe (Python)**
118
+ - Uses threading.Lock for concurrent access
119
+ - Background daemon thread for periodic sync
120
+
121
+ ## Testing
122
+
123
+ ### Python
124
+ ```bash
125
+ python tools/test_python_ntp_clock.py
126
+ ```
127
+
128
+ ### JavaScript
129
+ The test file is included in the package at `portacode/static/js/test-ntp-clock.html`.
130
+
131
+ After Django collectstatic, open: `/static/js/test-ntp-clock.html` in browser
132
+
133
+ Or run directly from package:
134
+ ```bash
135
+ python -c "import portacode, os; print(os.path.join(os.path.dirname(portacode.__file__), 'static/js/test-ntp-clock.html'))"
136
+ ```
@@ -0,0 +1 @@
1
+ """Portacode utility modules."""