portacode 0.3.16.dev10__py3-none-any.whl → 1.4.11.dev1__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 (92) hide show
  1. portacode/_version.py +16 -3
  2. portacode/cli.py +143 -17
  3. portacode/connection/client.py +149 -10
  4. portacode/connection/handlers/WEBSOCKET_PROTOCOL.md +928 -42
  5. portacode/connection/handlers/__init__.py +34 -5
  6. portacode/connection/handlers/base.py +78 -16
  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 -948
  20. portacode/connection/handlers/proxmox_infra.py +361 -0
  21. portacode/connection/handlers/registry.py +15 -4
  22. portacode/connection/handlers/session.py +483 -32
  23. portacode/connection/handlers/system_handlers.py +147 -8
  24. portacode/connection/handlers/tab_factory.py +389 -0
  25. portacode/connection/handlers/terminal_handlers.py +21 -8
  26. portacode/connection/handlers/update_handler.py +61 -0
  27. portacode/connection/multiplex.py +60 -2
  28. portacode/connection/terminal.py +256 -17
  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/static/js/test-ntp-clock.html +63 -0
  53. portacode/static/js/utils/ntp-clock.js +232 -0
  54. portacode/utils/NTP_ARCHITECTURE.md +136 -0
  55. portacode/utils/__init__.py +1 -0
  56. portacode/utils/diff_apply.py +456 -0
  57. portacode/utils/diff_renderer.py +371 -0
  58. portacode/utils/ntp_clock.py +65 -0
  59. portacode-1.4.11.dev1.dist-info/METADATA +298 -0
  60. portacode-1.4.11.dev1.dist-info/RECORD +97 -0
  61. {portacode-0.3.16.dev10.dist-info → portacode-1.4.11.dev1.dist-info}/WHEEL +1 -1
  62. portacode-1.4.11.dev1.dist-info/top_level.txt +3 -0
  63. test_modules/README.md +296 -0
  64. test_modules/__init__.py +1 -0
  65. test_modules/test_device_online.py +44 -0
  66. test_modules/test_file_operations.py +743 -0
  67. test_modules/test_git_status_ui.py +370 -0
  68. test_modules/test_login_flow.py +50 -0
  69. test_modules/test_navigate_testing_folder.py +361 -0
  70. test_modules/test_play_store_screenshots.py +294 -0
  71. test_modules/test_terminal_buffer_performance.py +261 -0
  72. test_modules/test_terminal_interaction.py +80 -0
  73. test_modules/test_terminal_loading_race_condition.py +95 -0
  74. test_modules/test_terminal_start.py +56 -0
  75. testing_framework/.env.example +21 -0
  76. testing_framework/README.md +334 -0
  77. testing_framework/__init__.py +17 -0
  78. testing_framework/cli.py +326 -0
  79. testing_framework/core/__init__.py +1 -0
  80. testing_framework/core/base_test.py +336 -0
  81. testing_framework/core/cli_manager.py +177 -0
  82. testing_framework/core/hierarchical_runner.py +577 -0
  83. testing_framework/core/playwright_manager.py +520 -0
  84. testing_framework/core/runner.py +447 -0
  85. testing_framework/core/shared_cli_manager.py +234 -0
  86. testing_framework/core/test_discovery.py +112 -0
  87. testing_framework/requirements.txt +12 -0
  88. portacode-0.3.16.dev10.dist-info/METADATA +0 -238
  89. portacode-0.3.16.dev10.dist-info/RECORD +0 -29
  90. portacode-0.3.16.dev10.dist-info/top_level.txt +0 -1
  91. {portacode-0.3.16.dev10.dist-info → portacode-1.4.11.dev1.dist-info}/entry_points.txt +0 -0
  92. {portacode-0.3.16.dev10.dist-info → portacode-1.4.11.dev1.dist-info/licenses}/LICENSE +0 -0
@@ -1,10 +1,38 @@
1
1
  # WebSocket Communication Protocol
2
2
 
3
- This document outlines the WebSocket communication protocol between the Portacode server and the connected client devices.
3
+ This document outlines the WebSocket communication protocol used in Portacode. The protocol involves three main participants: client sessions, the Portacode server, and devices.
4
+
5
+ ## Architecture Overview
6
+
7
+ ```
8
+ ┌─────────────┐ ┌──────────────────┐ ┌─────────────────────────┐
9
+ │ Client │ │ Portacode │ │ Device │
10
+ │ Session │◄────────►│ Server │◄────────►│ (Portacode CLI or │
11
+ │ │ │ │ │ Python package) │
12
+ └─────────────┘ └──────────────────┘ └─────────────────────────┘
13
+ │ │ │
14
+ │ │ │
15
+ Client-Side Acts as middleman Device-Side
16
+ Protocol - Routes messages Protocol
17
+ - Manages sessions
18
+ ```
19
+
20
+ The Portacode server acts as a **routing middleman** between client sessions and devices. It manages routing fields that are included in messages to specify routing destinations but are removed or transformed before reaching the final recipient:
21
+
22
+ **Routing Fields Behavior:**
23
+
24
+ - **`device_id`** (Client → Server): Client includes this to specify which device to route to. Server uses it for routing, then **removes it** before forwarding to the device (the device knows the message is for them). Server **adds it** when routing device responses back to clients (so clients know which device the message came from).
25
+
26
+ - **`client_sessions`** (Device → Server): Device includes this to specify which client session(s) to route to. Server uses it for routing, then **removes it** before forwarding to clients (clients just receive the message without seeing routing metadata).
27
+
28
+ - **`source_client_session`** (Server → Device): Server **adds this** when forwarding client commands to devices (so device knows which client sent the command and can target responses back). Clients never include this field.
29
+
30
+ This document describes the complete protocol for communicating with devices through the server, guiding app developers on how to get their client sessions to communicate with devices.
4
31
 
5
32
  ## Table of Contents
6
33
 
7
- - [Raw Message Format](#raw-message-format)
34
+ - [Raw Message Format On Device Side](#raw-message-format-on-device-side)
35
+ - [Raw Message Format On Client Side](#raw-message-format-on-client-side)
8
36
  - [Actions](#actions)
9
37
  - [Terminal Actions](#terminal-actions)
10
38
  - [`terminal_start`](#terminal_start)
@@ -13,18 +41,33 @@ This document outlines the WebSocket communication protocol between the Portacod
13
41
  - [`terminal_list`](#terminal_list)
14
42
  - [System Actions](#system-actions)
15
43
  - [`system_info`](#system_info)
44
+ - [`update_portacode_cli`](#update_portacode_cli)
45
+ - [`clock_sync_request`](#clock_sync_request)
16
46
  - [File Actions](#file-actions)
17
47
  - [`file_read`](#file_read)
48
+ - [`file_search`](#file_search)
18
49
  - [`file_write`](#file_write)
50
+ - [`file_apply_diff`](#file_apply_diff)
51
+ - [`file_preview_diff`](#file_preview_diff)
19
52
  - [`directory_list`](#directory_list)
20
53
  - [`file_info`](#file_info)
21
54
  - [`file_delete`](#file_delete)
55
+ - [`file_create`](#file_create)
56
+ - [`folder_create`](#folder_create)
57
+ - [`file_rename`](#file_rename)
58
+ - [`content_request`](#content_request)
22
59
  - [Project State Actions](#project-state-actions)
23
60
  - [`project_state_folder_expand`](#project_state_folder_expand)
24
61
  - [`project_state_folder_collapse`](#project_state_folder_collapse)
25
62
  - [`project_state_file_open`](#project_state_file_open)
26
- - [`project_state_file_close`](#project_state_file_close)
27
- - [`project_state_set_active_file`](#project_state_set_active_file)
63
+ - [`project_state_tab_close`](#project_state_tab_close)
64
+ - [`project_state_set_active_tab`](#project_state_set_active_tab)
65
+ - [`project_state_diff_open`](#project_state_diff_open)
66
+ - [`project_state_diff_content_request`](#project_state_diff_content_request)
67
+ - [`project_state_git_stage`](#project_state_git_stage)
68
+ - [`project_state_git_unstage`](#project_state_git_unstage)
69
+ - [`project_state_git_revert`](#project_state_git_revert)
70
+ - [`project_state_git_commit`](#project_state_git_commit)
28
71
  - [Client Session Management](#client-session-management)
29
72
  - [`client_sessions_update`](#client_sessions_update)
30
73
  - [Events](#events)
@@ -40,20 +83,35 @@ This document outlines the WebSocket communication protocol between the Portacod
40
83
  - [`terminal_list`](#terminal_list-event)
41
84
  - [System Events](#system-events)
42
85
  - [`system_info`](#system_info-event)
86
+ - [`update_portacode_response`](#update_portacode_response)
87
+ - [`clock_sync_response`](#clock_sync_response)
43
88
  - [File Events](#file-events)
44
89
  - [`file_read_response`](#file_read_response)
90
+ - [`file_search_response`](#file_search_response)
45
91
  - [`file_write_response`](#file_write_response)
92
+ - [`file_apply_diff_response`](#file_apply_diff_response)
93
+ - [`file_preview_diff_response`](#file_preview_diff_response)
46
94
  - [`directory_list_response`](#directory_list_response)
47
95
  - [`file_info_response`](#file_info_response)
48
96
  - [`file_delete_response`](#file_delete_response)
97
+ - [`file_create_response`](#file_create_response)
98
+ - [`folder_create_response`](#folder_create_response)
99
+ - [`file_rename_response`](#file_rename_response)
100
+ - [`content_response`](#content_response)
49
101
  - [Project State Events](#project-state-events)
50
102
  - [`project_state_initialized`](#project_state_initialized)
51
103
  - [`project_state_update`](#project_state_update)
52
104
  - [`project_state_folder_expand_response`](#project_state_folder_expand_response)
53
105
  - [`project_state_folder_collapse_response`](#project_state_folder_collapse_response)
54
106
  - [`project_state_file_open_response`](#project_state_file_open_response)
55
- - [`project_state_file_close_response`](#project_state_file_close_response)
56
- - [`project_state_set_active_file_response`](#project_state_set_active_file_response)
107
+ - [`project_state_tab_close_response`](#project_state_tab_close_response)
108
+ - [`project_state_set_active_tab_response`](#project_state_set_active_tab_response)
109
+ - [`project_state_diff_open_response`](#project_state_diff_open_response)
110
+ - [`project_state_diff_content_response`](#project_state_diff_content_response)
111
+ - [`project_state_git_stage_response`](#project_state_git_stage_response)
112
+ - [`project_state_git_unstage_response`](#project_state_git_unstage_response)
113
+ - [`project_state_git_revert_response`](#project_state_git_revert_response)
114
+ - [`project_state_git_commit_response`](#project_state_git_commit_response)
57
115
  - [Client Session Events](#client-session-events)
58
116
  - [`request_client_sessions`](#request_client_sessions)
59
117
  - [Terminal Data](#terminal-data)
@@ -62,11 +120,11 @@ This document outlines the WebSocket communication protocol between the Portacod
62
120
  - [`device_status`](#device_status)
63
121
  - [`devices`](#devices)
64
122
 
65
- ## Raw Message Format
123
+ ## Raw Message Format On Device Side
66
124
 
67
- All communication over the WebSocket is managed by a [multiplexer](./multiplex.py) that wraps every message in a JSON object with a `channel` and a `payload`. This allows for multiple virtual communication channels over a single connection.
125
+ Communication between the server and devices uses a [multiplexer](./multiplex.py) that wraps every message in a JSON object with a `channel` and a `payload`. This allows for multiple virtual communication channels over a single WebSocket connection.
68
126
 
69
- **Raw Message Structure:**
127
+ **Device-Side Message Structure:**
70
128
 
71
129
  ```json
72
130
  {
@@ -77,9 +135,99 @@ All communication over the WebSocket is managed by a [multiplexer](./multiplex.p
77
135
  }
78
136
  ```
79
137
 
80
- * `channel` (string|integer, mandatory): Identifies the virtual channel the message is for. When sending control commands to the device, they should be sent to channel 0 and when the device responsed to such control commands or sends system events, they will also be send on the zero channel. When a terminal session is created in the device, it is assigned a uuid, the uuid becomes the channel for communicating to that specific terminal.
138
+ **Field Descriptions:**
139
+
140
+ * `channel` (string|integer, mandatory): Identifies the virtual channel the message is for. When sending control commands to the device, they should be sent to channel 0 and when the device responds to such control commands or sends system events, they will also be sent on the zero channel. When a terminal session is created in the device, it is assigned a uuid, the uuid becomes the channel for communicating to that specific terminal.
81
141
  * `payload` (object, mandatory): The content of the message, which will be either an [Action](#actions) or an [Event](#events) object.
82
142
 
143
+ **Channel Types:**
144
+ - **Channel 0** (control channel): Used for system commands, terminal management, file operations, and project state management
145
+ - **Channel UUID** (terminal channel): Used for terminal I/O to a specific terminal session
146
+
147
+ ---
148
+
149
+ ## Raw Message Format On Client Side
150
+
151
+ Client sessions communicate with the server using a unified message format with the same field names as the device protocol, plus routing information.
152
+
153
+ **Client-Side Message Structure (Client → Server):**
154
+
155
+ ```json
156
+ {
157
+ "device_id": <number>,
158
+ "channel": <number|string>,
159
+ "payload": {
160
+ "cmd": "<command_name>",
161
+ ...command-specific fields
162
+ }
163
+ }
164
+ ```
165
+
166
+ **Field Descriptions:**
167
+
168
+ * `device_id` (number, mandatory): Routing field - specifies which device to send the message to. The server validates that the client has access to this device before forwarding.
169
+ * `channel` (number|string, mandatory): Same as device protocol - the target channel (0 for control, UUID for terminal). Uses the same field name for consistency.
170
+ * `payload` (object, mandatory): Same as device protocol - the command payload. Uses the same field name for consistency.
171
+
172
+ **Server Transformation (Client → Device):**
173
+
174
+ When the server receives a client message, it:
175
+ 1. Validates client has access to the specified `device_id`
176
+ 2. **Removes** `device_id` from the message (device doesn't need to be told "this is for you")
177
+ 3. **Adds** `source_client_session` to the payload (so device knows which client to respond to)
178
+ 4. Forwards to device: `{channel, payload: {...payload, source_client_session}}`
179
+
180
+ **Server Transformation (Device → Client):**
181
+
182
+ When the server receives a device response, it:
183
+ 1. **Adds** `device_id` to the message (so client knows which device it came from, based on authenticated device connection)
184
+ 2. **Removes** `client_sessions` routing metadata (clients don't need to see routing info)
185
+ 3. Routes to appropriate client session(s)
186
+
187
+ **Server Response Format (Server → Client):**
188
+
189
+ ```json
190
+ {
191
+ "event": "<event_name>",
192
+ "device_id": <number>,
193
+ ...event-specific fields
194
+ }
195
+ ```
196
+
197
+ **Field Descriptions:**
198
+
199
+ * `event` (string, mandatory): The name of the event being sent.
200
+ * `device_id` (number, mandatory): Authenticated field - identifies which device the event came from (added by server based on authenticated device connection).
201
+ * Additional fields depend on the specific event type.
202
+
203
+ **Example Client Message:**
204
+ ```json
205
+ {
206
+ "device_id": 42,
207
+ "channel": 0,
208
+ "payload": {
209
+ "cmd": "terminal_start",
210
+ "shell": "bash",
211
+ "cwd": "/home/user/project"
212
+ }
213
+ }
214
+ ```
215
+
216
+ **Example Server Response:**
217
+ ```json
218
+ {
219
+ "event": "terminal_started",
220
+ "device_id": 42,
221
+ "terminal_id": "uuid-1234-5678",
222
+ "channel": "uuid-1234-5678",
223
+ "pid": 12345
224
+ }
225
+ ```
226
+
227
+ **Note:** The server acts as a translator between the client-side and device-side protocols:
228
+ - When a client sends a command, the server transforms it from the client format to the device format
229
+ - When a device sends an event, the server adds the `device_id` and routes it to the appropriate client sessions
230
+
83
231
  ---
84
232
 
85
233
  ## Actions
@@ -90,18 +238,18 @@ Actions are messages sent from the server to the device, placed within the `payl
90
238
 
91
239
  ```json
92
240
  {
93
- "command": "<command_name>",
94
- "payload": {
95
- "arg1": "value1",
96
- "...": "..."
97
- },
241
+ "cmd": "<command_name>",
242
+ "arg1": "value1",
243
+ "arg2": "value2",
98
244
  "source_client_session": "channel.abc123"
99
245
  }
100
246
  ```
101
247
 
102
- * `command` (string, mandatory): The name of the action to be executed (e.g., `terminal_start`).
103
- * `payload` (object, mandatory): An object containing the specific arguments for the action.
248
+ **Field Descriptions:**
249
+
250
+ * `cmd` (string, mandatory): The name of the action to be executed (e.g., `terminal_start`, `file_read`, `system_info`).
104
251
  * `source_client_session` (string, mandatory): The channel name of the client session that originated this command. This field is automatically added by the server and allows devices to identify which specific client sent the command.
252
+ * Additional fields depend on the specific command (see individual command documentation below).
105
253
 
106
254
  **Note**: Actions do not require targeting information - responses are automatically routed using the client session management system.
107
255
 
@@ -172,6 +320,58 @@ This action does not require any payload fields.
172
320
 
173
321
  * On success, the device will respond with a [`system_info`](#system_info-event) event.
174
322
 
323
+ ### `setup_proxmox_infra`
324
+
325
+ Configures a Proxmox node for Portacode infrastructure usage (API token validation, automatic storage/template detection, bridge/NAT setup, and connectivity verification). Handled by [`ConfigureProxmoxInfraHandler`](./proxmox_infra.py).
326
+
327
+ **Payload Fields:**
328
+
329
+ * `token_identifier` (string, required): API token identifier in the form `user@realm!tokenid`.
330
+ * `token_value` (string, required): Secret value associated with the token.
331
+ * `verify_ssl` (boolean, optional): When true, the handler verifies SSL certificates; defaults to `false`.
332
+
333
+ **Responses:**
334
+
335
+ * On success, the device will emit a [`proxmox_infra_configured`](#proxmox_infra_configured-event) event with the persisted infra snapshot.
336
+ * On failure, the device will emit an [`error`](#error) event with details (e.g., permission issues, missing proxmoxer/dnsmasq, missing root privileges, or failed network verification).
337
+
338
+ ### `revert_proxmox_infra`
339
+
340
+ Reverts the Proxmox infrastructure network changes and clears the stored API token. Handled by [`RevertProxmoxInfraHandler`](./proxmox_infra.py).
341
+
342
+ **Payload Fields:**
343
+
344
+ This action does not require any payload fields.
345
+
346
+ **Responses:**
347
+
348
+ * On success, the device will emit a [`proxmox_infra_reverted`](#proxmox_infra_reverted-event) event containing the cleared snapshot.
349
+
350
+ ### `clock_sync_request`
351
+
352
+ Internal event that devices send to the gateway to request the authoritative server timestamp (used for adjusting `portacode.utils.ntp_clock`). The gateway responds immediately with [`clock_sync_response`](#clock_sync_response).
353
+
354
+ **Payload Fields:**
355
+
356
+ * `request_id` (string, optional): Correlates the response with the request.
357
+
358
+ **Responses:**
359
+
360
+ * The gateway responds with [`clock_sync_response`](#clock_sync_response) that includes the authoritative `server_time` (plus the optional `server_time_iso` mirror).
361
+
362
+ ### `update_portacode_cli`
363
+
364
+ Updates the Portacode CLI package and restarts the process. Handled by [`update_portacode_cli`](./update_handler.py).
365
+
366
+ **Payload Fields:**
367
+
368
+ This action does not require any payload fields.
369
+
370
+ **Responses:**
371
+
372
+ * On success, the device will respond with an `update_portacode_response` event and then exit with code 42 to trigger restart.
373
+ * On error, an `update_portacode_response` event with error details is sent.
374
+
175
375
  ### `file_read`
176
376
 
177
377
  Reads the content of a file. Handled by [`file_read`](./file_handlers.py).
@@ -179,12 +379,46 @@ Reads the content of a file. Handled by [`file_read`](./file_handlers.py).
179
379
  **Payload Fields:**
180
380
 
181
381
  * `path` (string, mandatory): The absolute path to the file to read.
382
+ * `start_line` (integer, optional): 1-based line number to start reading from. Defaults to `1`.
383
+ * `end_line` (integer, optional): 1-based line number to stop reading at (inclusive). When provided, limits the response to the range between `start_line` and `end_line`.
384
+ * `max_lines` (integer, optional): Maximum number of lines to return (capped at 2000). Useful for pagination when `end_line` is not specified.
385
+ * `encoding` (string, optional): Text encoding to use when reading the file. Defaults to `utf-8` with replacement for invalid bytes.
182
386
 
183
387
  **Responses:**
184
388
 
185
389
  * On success, the device will respond with a [`file_read_response`](#file_read_response) event.
186
390
  * On error, a generic [`error`](#error) event is sent.
187
391
 
392
+ ### `file_search`
393
+
394
+ Searches for text matches within files beneath a given root directory. Handled by [`file_search`](./file_handlers.py).
395
+
396
+ **Payload Fields:**
397
+
398
+ * `root_path` (string, mandatory): The absolute path that acts as the search root (typically a project folder).
399
+ * `query` (string, mandatory): The search query. Treated as plain text unless `regex=true`.
400
+ * `match_case` (boolean, optional): When `true`, performs a case-sensitive search. Defaults to `false`.
401
+ * `regex` (boolean, optional): When `true`, interprets `query` as a regular expression. Defaults to `false`.
402
+ * `whole_word` (boolean, optional): When `true`, matches only whole words. Works with both plain text and regex queries.
403
+ * `include_patterns` (array[string], optional): Glob patterns that files must match to be included (e.g., `["src/**/*.py"]`).
404
+ * `exclude_patterns` (array[string], optional): Glob patterns for files/directories to skip (e.g., `["**/tests/**"]`).
405
+ * `include_hidden` (boolean, optional): When `true`, includes hidden files and folders. Defaults to `false`.
406
+ * `max_results` (integer, optional): Maximum number of match entries to return (capped at 500). Defaults to `40`.
407
+ * `max_matches_per_file` (integer, optional): Maximum number of matches to return per file (capped at 50). Defaults to `5`.
408
+ * `max_file_size` (integer, optional): Maximum file size in bytes to scan (defaults to 1 MiB).
409
+ * `max_line_length` (integer, optional): Maximum number of characters to return per matching line (defaults to `200`).
410
+
411
+ **Default Behaviour:**
412
+
413
+ * Binary files and large vendor/static directories (e.g., `node_modules`, `dist`, `static`) are skipped automatically unless custom `exclude_patterns` are provided.
414
+ * Only common source/text extensions are scanned by default (override with `include_patterns` to widen the scope).
415
+ * Searches stop after 10 seconds, respecting both per-file and global match limits to avoid oversized responses.
416
+
417
+ **Responses:**
418
+
419
+ * On success, the device will respond with a [`file_search_response`](#file_search_response) event containing the matches.
420
+ * On error, a generic [`error`](#error) event is sent.
421
+
188
422
  ### `file_write`
189
423
 
190
424
  Writes content to a file. Handled by [`file_write`](./file_handlers.py).
@@ -197,6 +431,57 @@ Writes content to a file. Handled by [`file_write`](./file_handlers.py).
197
431
  **Responses:**
198
432
 
199
433
  * On success, the device will respond with a [`file_write_response`](#file_write_response) event.
434
+
435
+ ### `file_apply_diff`
436
+
437
+ Apply one or more unified diff hunks to local files. Handled by [`file_apply_diff`](./diff_handlers.py).
438
+
439
+ **Request Payload:**
440
+
441
+ ```json
442
+ {
443
+ "cmd": "file_apply_diff",
444
+ "diff": "<unified diff string>",
445
+ "base_path": "<optional base path for relative diff entries>",
446
+ "project_id": "<server project UUID>",
447
+ "source_client_session": "<originating session/channel>"
448
+ }
449
+ ```
450
+
451
+ **Behavior:**
452
+
453
+ * `diff` must be standard unified diff text (like `git diff` output). Multiple files per diff are supported.
454
+ * If `base_path` is omitted the handler will attempt to derive the active project root from `source_client_session`, falling back to the device working directory.
455
+ * Each file hunk is validated before writing; context mismatches or missing files return per-file errors without aborting the rest.
456
+ * `/dev/null` entries are interpreted as file creations/deletions.
457
+ * Inline directives are also supported on their own lines. Use `@@delete:relative/path.py@@` to delete a file directly or `@@move:old/path.py -> new/path.py@@` (alias `@@rename:...@@`) to move/rename a file without crafting a diff. Directives are evaluated before the diff hunks and must point to files inside the project base.
458
+
459
+ * On completion the device responds with [`file_apply_diff_response`](#file_apply_diff_response).
460
+ * On error, a generic [`error`](#error) event is sent.
461
+
462
+ ### `file_preview_diff`
463
+
464
+ Validate one or more unified diff hunks and render an HTML preview without mutating any files. Handled by [`file_preview_diff`](./diff_handlers.py).
465
+
466
+ **Request Payload:**
467
+
468
+ ```json
469
+ {
470
+ "cmd": "file_preview_diff",
471
+ "diff": "<unified diff string>",
472
+ "base_path": "<optional base path for relative diff entries>",
473
+ "request_id": "req_123456"
474
+ }
475
+ ```
476
+
477
+ **Behavior:**
478
+
479
+ * Reuses the same parser as `file_apply_diff`, so invalid hunks surface the same errors.
480
+ * Produces HTML snippets per file using the device-side renderer. No files are modified.
481
+ * Inline directives (`@@delete:...@@`, `@@move:src -> dest@@`) use the same syntax as `file_apply_diff`. The handler validates them up front and includes them in the preview output so the user can see deletions or moves before clicking “Apply”.
482
+ * Returns immediately with an error payload if preview generation fails.
483
+
484
+ * On completion the device responds with [`file_preview_diff_response`](#file_preview_diff_response).
200
485
  * On error, a generic [`error`](#error) event is sent.
201
486
 
202
487
  ### `directory_list`
@@ -207,6 +492,8 @@ Lists the contents of a directory. Handled by [`directory_list`](./file_handlers
207
492
 
208
493
  * `path` (string, optional): The path to the directory to list. Defaults to the current directory.
209
494
  * `show_hidden` (boolean, optional): Whether to include hidden files in the listing. Defaults to `false`.
495
+ * `limit` (integer, optional): Maximum number of entries to return (defaults to “all”). Values above 1000 are clamped to 1000.
496
+ * `offset` (integer, optional): Number of entries to skip before collecting results (defaults to `0`).
210
497
 
211
498
  **Responses:**
212
499
 
@@ -239,12 +526,76 @@ Deletes a file or directory. Handled by [`file_delete`](./file_handlers.py).
239
526
  * On success, the device will respond with a [`file_delete_response`](#file_delete_response) event.
240
527
  * On error, a generic [`error`](#error) event is sent.
241
528
 
529
+ ### `file_create`
530
+
531
+ Creates a new file. Handled by [`file_create`](./file_handlers.py).
532
+
533
+ **Payload Fields:**
534
+
535
+ * `parent_path` (string, mandatory): The absolute path to the parent directory where the file should be created.
536
+ * `file_name` (string, mandatory): The name of the file to create. Must not contain path separators or be special directories (`.`, `..`).
537
+ * `content` (string, optional): The initial content for the file. Defaults to empty string.
538
+
539
+ **Responses:**
540
+
541
+ * On success, the device will respond with a [`file_create_response`](#file_create_response) event.
542
+ * On error, a generic [`error`](#error) event is sent.
543
+
544
+ ### `folder_create`
545
+
546
+ Creates a new folder/directory. Handled by [`folder_create`](./file_handlers.py).
547
+
548
+ **Payload Fields:**
549
+
550
+ * `parent_path` (string, mandatory): The absolute path to the parent directory where the folder should be created.
551
+ * `folder_name` (string, mandatory): The name of the folder to create. Must not contain path separators or be special directories (`.`, `..`).
552
+
553
+ **Responses:**
554
+
555
+ * On success, the device will respond with a [`folder_create_response`](#folder_create_response) event.
556
+ * On error, a generic [`error`](#error) event is sent.
557
+
558
+ ### `file_rename`
559
+
560
+ Renames a file or folder. Handled by [`file_rename`](./file_handlers.py).
561
+
562
+ **Payload Fields:**
563
+
564
+ * `old_path` (string, mandatory): The absolute path to the file or folder to rename.
565
+ * `new_name` (string, mandatory): The new name (not full path) for the item. Must not contain path separators or be special directories (`.`, `..`).
566
+
567
+ **Responses:**
568
+
569
+ * On success, the device will respond with a [`file_rename_response`](#file_rename_response) event.
570
+ * On error, a generic [`error`](#error) event is sent.
571
+
572
+ ### `content_request`
573
+
574
+ Requests cached content by SHA-256 hash. This action is used to implement content caching for performance optimization, allowing clients to request large content (such as file content, HTML diffs, etc.) by hash instead of receiving it in every WebSocket message. For large content (>200KB), the response will be automatically chunked into multiple messages for reliable transmission. Handled by [`content_request`](./file_handlers.py).
575
+
576
+ **Payload Fields:**
577
+
578
+ * `content_hash` (string, mandatory): The SHA-256 hash of the content to retrieve (with "sha256:" prefix).
579
+ * `request_id` (string, mandatory): A unique identifier for this request, used to match with the response.
580
+
581
+ **Responses:**
582
+
583
+ * On success, the device will respond with one or more [`content_response`](#content_response) events containing the cached content. Large content is automatically chunked.
584
+ * On error (content not found), a [`content_response`](#content_response) event with `success: false` is sent.
585
+
242
586
  ## Project State Actions
243
587
 
244
588
  Project state actions manage the state of project folders, including file structures, Git metadata, open files, and folder expansion states. These actions provide real-time synchronization between the client and server for project management functionality.
245
589
 
246
590
  **Note:** Project state is automatically initialized when a client session connects with a `project_folder_path` property. No manual initialization command is required.
247
591
 
592
+ **Tab Management:** Open tabs are internally managed using a dictionary structure with unique keys to prevent duplicates and race conditions:
593
+ - File tabs use `file_path` as the unique key
594
+ - Diff tabs use a composite key: `diff:{file_path}:{from_ref}:{to_ref}:{from_hash}:{to_hash}`
595
+ - Untitled tabs use their `tab_id` as the unique key
596
+
597
+ This ensures that sending the same command multiple times (e.g., `project_state_diff_open` with identical parameters) will not create duplicate tabs but will instead activate the existing tab.
598
+
248
599
  ### `project_state_folder_expand`
249
600
 
250
601
  Expands a folder in the project tree, loading its contents and enabling monitoring for that folder level. When a folder is expanded, the system proactively loads one level down for all subdirectories to enable immediate expansion in the UI. This action also scans items in the expanded folder and preloads content for any non-empty subdirectories.
@@ -277,6 +628,8 @@ Collapses a folder in the project tree, stopping monitoring for that folder leve
277
628
 
278
629
  Marks a file as open in the project state, tracking it as part of the current editing session.
279
630
 
631
+ **Duplicate Prevention:** This action prevents creating duplicate file tabs by using the `file_path` as a unique key. If a file tab with the same path already exists, it will be activated instead of creating a new one.
632
+
280
633
  **Payload Fields:**
281
634
 
282
635
  * `project_id` (string, mandatory): The project ID from the initialized project state.
@@ -288,32 +641,163 @@ Marks a file as open in the project state, tracking it as part of the current ed
288
641
  * On success, the device will respond with a [`project_state_file_open_response`](#project_state_file_open_response) event, followed by a [`project_state_update`](#project_state_update) event.
289
642
  * On error, a generic [`error`](#error) event is sent.
290
643
 
291
- ### `project_state_file_close`
644
+ ### `project_state_tab_close`
645
+
646
+ Closes a tab in the project state, removing it from the current editing session.
647
+
648
+ **Payload Fields:**
649
+
650
+ * `project_id` (string, mandatory): The project ID from the initialized project state.
651
+ * `tab_id` (string, mandatory): The unique ID of the tab to close.
652
+
653
+ **Responses:**
654
+
655
+ * On success, the device will respond with a [`project_state_tab_close_response`](#project_state_tab_close_response) event, followed by a [`project_state_update`](#project_state_update) event.
656
+ * On error, a generic [`error`](#error) event is sent.
657
+
658
+ ### `project_state_set_active_tab`
659
+
660
+ Sets the currently active tab in the project state. Only one tab can be active at a time.
661
+
662
+ **Payload Fields:**
663
+
664
+ * `project_id` (string, mandatory): The project ID from the initialized project state.
665
+ * `tab_id` (string, optional): The unique ID of the tab to set as active. If `null` or omitted, clears the active tab.
666
+
667
+ **Responses:**
668
+
669
+ * On success, the device will respond with a [`project_state_set_active_tab_response`](#project_state_set_active_tab_response) event, followed by a [`project_state_update`](#project_state_update) event.
670
+ * On error, a generic [`error`](#error) event is sent.
671
+
672
+ ### `project_state_diff_open`
673
+
674
+ Opens a diff tab for comparing file versions at different points in the git timeline. This replaces the previous `project_state_create_diff_tab` action with a more efficient approach that doesn't require the client to provide file content, instead using git timeline references.
675
+
676
+ **Duplicate Prevention:** This action prevents creating duplicate diff tabs by using a unique key based on `file_path`, `from_ref`, `to_ref`, `from_hash`, and `to_hash`. If a diff tab with the same parameters already exists, it will be activated instead of creating a new one.
677
+
678
+ **Payload Fields:**
679
+
680
+ * `project_id` (string, mandatory): The project ID from the initialized project state.
681
+ * `file_path` (string, mandatory): The absolute path to the file to create a diff for.
682
+ * `from_ref` (string, mandatory): The source reference point. Must be one of:
683
+ - `"head"`: Content from the HEAD commit
684
+ - `"staged"`: Content from the staging area
685
+ - `"working"`: Current working directory content
686
+ - `"commit"`: Content from a specific commit (requires `from_hash`)
687
+ * `to_ref` (string, mandatory): The target reference point. Same options as `from_ref`.
688
+ * `from_hash` (string, optional): Required when `from_ref` is `"commit"`. The commit hash to get content from.
689
+ * `to_hash` (string, optional): Required when `to_ref` is `"commit"`. The commit hash to get content from.
690
+
691
+ **Responses:**
692
+
693
+ * On success, the device will respond with a [`project_state_diff_open_response`](#project_state_diff_open_response) event, followed by a [`project_state_update`](#project_state_update) event.
694
+ * On error, a generic [`error`](#error) event is sent.
695
+
696
+ ### `project_state_diff_content_request`
292
697
 
293
- Marks a file as closed in the project state, removing it from the current editing session.
698
+ Requests the content for a specific diff tab identified by its diff parameters. This action is used to load the actual file content (original and modified) as well as HTML diff data for diff tabs after they have been created by [`project_state_diff_open`](#project_state_diff_open). For large content (>200KB), the response will be automatically chunked into multiple messages for reliable transmission.
699
+
700
+ **Content Types:** This action can request content for a diff:
701
+ - `original`: The original (from) content of the diff
702
+ - `modified`: The modified (to) content of the diff
703
+ - `html_diff`: The HTML diff versions for rich visual display
704
+ - `all`: All content types returned as a single JSON object (recommended for efficiency)
294
705
 
295
706
  **Payload Fields:**
296
707
 
297
708
  * `project_id` (string, mandatory): The project ID from the initialized project state.
298
- * `file_path` (string, mandatory): The absolute path to the file to close.
709
+ * `file_path` (string, mandatory): The absolute path to the file the diff is for.
710
+ * `from_ref` (string, mandatory): The source reference point used in the diff. Must match the diff tab parameters.
711
+ * `to_ref` (string, mandatory): The target reference point used in the diff. Must match the diff tab parameters.
712
+ * `from_hash` (string, optional): The commit hash for `from_ref` if it was `"commit"`. Must match the diff tab parameters.
713
+ * `to_hash` (string, optional): The commit hash for `to_ref` if it was `"commit"`. Must match the diff tab parameters.
714
+ * `content_type` (string, mandatory): The type of content to request. Must be one of:
715
+ - `"original"`: Request the original (from) content
716
+ - `"modified"`: Request the modified (to) content
717
+ - `"html_diff"`: Request the HTML diff versions for visual display
718
+ - `"all"`: Request all content types as a single JSON object
719
+ * `request_id` (string, mandatory): Unique identifier for this request to match with the response.
299
720
 
300
721
  **Responses:**
301
722
 
302
- * On success, the device will respond with a [`project_state_file_close_response`](#project_state_file_close_response) event, followed by a [`project_state_update`](#project_state_update) event.
723
+ * On success, the device will respond with one or more [`project_state_diff_content_response`](#project_state_diff_content_response) events. Large content is automatically chunked.
303
724
  * On error, a generic [`error`](#error) event is sent.
304
725
 
305
- ### `project_state_set_active_file`
726
+ ### `project_state_git_stage`
306
727
 
307
- Sets the currently active file in the project state. Only one file can be active at a time.
728
+ Stages file(s) for commit in the project's git repository. Supports both single file and bulk operations. Handled by [`project_state_git_stage`](./project_state_handlers.py).
308
729
 
309
730
  **Payload Fields:**
310
731
 
311
732
  * `project_id` (string, mandatory): The project ID from the initialized project state.
312
- * `file_path` (string, optional): The absolute path to the file to set as active. If `null` or omitted, clears the active file.
733
+ * `file_path` (string, optional): The absolute path to a single file to stage. Used for backward compatibility.
734
+ * `file_paths` (array of strings, optional): Array of absolute paths to files to stage. Used for bulk operations.
735
+ * `stage_all` (boolean, optional): If true, stages all unstaged changes in the repository. Takes precedence over file_path/file_paths.
736
+
737
+ **Operation Modes:**
738
+ - Single file: Provide `file_path`
739
+ - Bulk operation: Provide `file_paths` array
740
+ - Stage all: Set `stage_all` to true
313
741
 
314
742
  **Responses:**
315
743
 
316
- * On success, the device will respond with a [`project_state_set_active_file_response`](#project_state_set_active_file_response) event, followed by a [`project_state_update`](#project_state_update) event.
744
+ * On success, the device will respond with a [`project_state_git_stage_response`](#project_state_git_stage_response) event, followed by a [`project_state_update`](#project_state_update) event with updated git status.
745
+ * On error, a generic [`error`](#error) event is sent.
746
+
747
+ ### `project_state_git_unstage`
748
+
749
+ Unstages file(s) (removes from staging area) in the project's git repository. Supports both single file and bulk operations. Handled by [`project_state_git_unstage`](./project_state_handlers.py).
750
+
751
+ **Payload Fields:**
752
+
753
+ * `project_id` (string, mandatory): The project ID from the initialized project state.
754
+ * `file_path` (string, optional): The absolute path to a single file to unstage. Used for backward compatibility.
755
+ * `file_paths` (array of strings, optional): Array of absolute paths to files to unstage. Used for bulk operations.
756
+ * `unstage_all` (boolean, optional): If true, unstages all staged changes in the repository. Takes precedence over file_path/file_paths.
757
+
758
+ **Operation Modes:**
759
+ - Single file: Provide `file_path`
760
+ - Bulk operation: Provide `file_paths` array
761
+ - Unstage all: Set `unstage_all` to true
762
+
763
+ **Responses:**
764
+
765
+ * On success, the device will respond with a [`project_state_git_unstage_response`](#project_state_git_unstage_response) event, followed by a [`project_state_update`](#project_state_update) event with updated git status.
766
+ * On error, a generic [`error`](#error) event is sent.
767
+
768
+ ### `project_state_git_revert`
769
+
770
+ Reverts file(s) to their HEAD version, discarding local changes in the project's git repository. Supports both single file and bulk operations. Handled by [`project_state_git_revert`](./project_state_handlers.py).
771
+
772
+ **Payload Fields:**
773
+
774
+ * `project_id` (string, mandatory): The project ID from the initialized project state.
775
+ * `file_path` (string, optional): The absolute path to a single file to revert. Used for backward compatibility.
776
+ * `file_paths` (array of strings, optional): Array of absolute paths to files to revert. Used for bulk operations.
777
+ * `revert_all` (boolean, optional): If true, reverts all unstaged changes in the repository. Takes precedence over file_path/file_paths.
778
+
779
+ **Operation Modes:**
780
+ - Single file: Provide `file_path`
781
+ - Bulk operation: Provide `file_paths` array
782
+ - Revert all: Set `revert_all` to true
783
+
784
+ **Responses:**
785
+
786
+ * On success, the device will respond with a [`project_state_git_revert_response`](#project_state_git_revert_response) event, followed by a [`project_state_update`](#project_state_update) event with updated git status.
787
+ * On error, a generic [`error`](#error) event is sent.
788
+
789
+ ### `project_state_git_commit`
790
+
791
+ Commits staged changes with a commit message in the project's git repository. Handled by [`project_state_git_commit`](./project_state_handlers.py).
792
+
793
+ **Payload Fields:**
794
+
795
+ * `project_id` (string, mandatory): The project ID from the initialized project state.
796
+ * `commit_message` (string, mandatory): The commit message for the changes being committed.
797
+
798
+ **Responses:**
799
+
800
+ * On success, the device will respond with a [`project_state_git_commit_response`](#project_state_git_commit_response) event, followed by a [`project_state_update`](#project_state_update) event with updated git status.
317
801
  * On error, a generic [`error`](#error) event is sent.
318
802
 
319
803
  ### Client Session Management
@@ -415,6 +899,22 @@ The `data` field contains the exact bytes output by the terminal process, decode
415
899
 
416
900
  **Security Note**: The `device_id` field is automatically injected by the server based on the authenticated connection - the device cannot and should not specify its own ID. The `project_id` and `client_sessions` fields are added by the device's terminal manager for proper routing and filtering.
417
901
 
902
+ ### <a name="terminal_link_request"></a>`terminal_link_request`
903
+
904
+ Signals that the active terminal session attempted to open an external URL (e.g., via `xdg-open`). The terminal environment is instrumented with the `portacode/link_capture` helper, so CLI programs that try to open a browser are captured and forwarded to connected clients for confirmation.
905
+
906
+ **Event Fields:**
907
+
908
+ * `terminal_id` (string, mandatory): The UUID of the terminal session that triggered the request.
909
+ * `channel` (string, mandatory): Same as `terminal_id` (included for backward compatibility with raw channel routing).
910
+ * `url` (string, mandatory): The full URL the terminal tried to open. Clients must surface this text directly so users can verify it.
911
+ * `command` (string, optional): The command that attempted the navigation (e.g., `xdg-open`).
912
+ * `args` (array[string], optional): Arguments passed to the command, which may include safely-encoded paths or flags.
913
+ * `timestamp` (number, optional): UNIX epoch seconds when the capture occurred.
914
+ * `project_id` (string, optional): The project UUID in whose context the attempt was made.
915
+
916
+ Clients receiving this event should pause and ask the user for confirmation before opening the URL, and may throttle or suppress repeated events to prevent modal storms if a CLI tool loops on the same link.
917
+
418
918
  ### <a name="terminal_exit"></a>`terminal_exit`
419
919
 
420
920
  Notifies the server that a terminal session has terminated. This can be due to the process ending or the session being stopped. Handled by [`terminal_start`](./terminal_handlers.py).
@@ -471,6 +971,87 @@ Provides system information in response to a `system_info` action. Handled by [`
471
971
  * `memory` (object): Memory usage statistics.
472
972
  * `disk` (object): Disk usage statistics.
473
973
  * `os_info` (object): Operating system details, including `os_type`, `os_version`, `architecture`, `default_shell`, and `default_cwd`.
974
+ * `user_context` (object): Information about the user running the CLI, including:
975
+ * `username` (string): Resolved username (via `os.getlogin` or fallback).
976
+ * `username_source` (string): Which API resolved the username.
977
+ * `home` (string): Home directory detected for the CLI user.
978
+ * `uid` (integer|null): POSIX UID when available.
979
+ * `euid` (integer|null): Effective UID when available.
980
+ * `is_root` (boolean|null): True when running as root/administrator.
981
+ * `has_sudo` (boolean): Whether a `sudo` binary exists on the host.
982
+ * `sudo_user` (string|null): Value of `SUDO_USER` when set.
983
+ * `is_sudo_session` (boolean): True when the CLI was started via `sudo`.
984
+ * `playwright` (object): Optional Playwright runtime metadata when Playwright is installed:
985
+ * `installed` (boolean): True if Playwright is importable on the device.
986
+ * `version` (string|null): Exact package version when available.
987
+ * `browsers` (object): Browser-specific data keyed by Playwright browser names:
988
+ * `<browser>` (object): Per-browser info (variants: `chromium`, `firefox`, `webkit`).
989
+ * `available` (boolean): True when Playwright knows an executable path.
990
+ * `executable_path` (string|null): Absolute path to the browser binary when known.
991
+ * `error` (string|null): Any warning message captured while probing Playwright.
992
+ * `proxmox` (object): Detection hints for Proxmox VE nodes:
993
+ * `is_proxmox_node` (boolean): True when Proxmox artifacts (e.g., `/etc/proxmox-release`) exist.
994
+ * `version` (string|null): Raw contents of `/etc/proxmox-release` when readable.
995
+ * `infra` (object): Portacode infrastructure configuration snapshot:
996
+ * `configured` (boolean): True when `setup_proxmox_infra` stored an API token.
997
+ * `host` (string|null): Hostname used for the API client (usually `localhost`).
998
+ * `node` (string|null): Proxmox node name that was targeted.
999
+ * `user` (string|null): API token owner (e.g., `root@pam`).
1000
+ * `token_name` (string|null): API token identifier.
1001
+ * `default_storage` (string|null): Storage pool chosen for future containers.
1002
+ * `templates` (array[string]): Cached list of available LXC templates.
1003
+ * `last_verified` (string|null): ISO timestamp when the token was last validated.
1004
+ * `network` (object):
1005
+ * `applied` (boolean): True when the bridge/NAT services were successfully configured.
1006
+ * `message` (string|null): Informational text about the network setup attempt.
1007
+ * `bridge` (string): The bridge interface configured (typically `vmbr1`).
1008
+ * `health` (string|null): `"healthy"` when the connectivity verification succeeded.
1009
+ * `node_status` (object|null): Status response returned by the Proxmox API when validating the token.
1010
+ * `portacode_version` (string): Installed CLI version returned by `portacode.__version__`.
1011
+
1012
+ ### `proxmox_infra_configured`
1013
+
1014
+ Emitted after a successful `setup_proxmox_infra` action. The event reports the stored API token metadata, template list, and network setup status.
1015
+
1016
+ **Event Fields:**
1017
+
1018
+ * `success` (boolean): True when the configuration completed.
1019
+ * `message` (string): User-facing summary (e.g., "Proxmox infrastructure configured").
1020
+ * `infra` (object): Same snapshot described under [`system_info`](#system_info-event) `proxmox.infra`.
1021
+
1022
+ ### `proxmox_infra_reverted`
1023
+
1024
+ Emitted after a successful `revert_proxmox_infra` action. Indicates the infra config is no longer present and the network was restored.
1025
+
1026
+ **Event Fields:**
1027
+
1028
+ * `success` (boolean): True when the revert completed.
1029
+ * `message` (string): Summary (e.g., "Proxmox infrastructure configuration reverted").
1030
+ * `infra` (object): Snapshot with `configured=false` (matching [`system_info`](#system_info-event) `proxmox.infra`).
1031
+
1032
+ ### <a name="clock_sync_response"></a>`clock_sync_response`
1033
+
1034
+ Reply sent by the gateway immediately after receiving a `clock_sync_request`. Devices use this event plus the measured round-trip time to keep their local `ntp_clock` offset accurate.
1035
+
1036
+ **Event Fields:**
1037
+
1038
+ * `event` (string): Always `clock_sync_response`.
1039
+ * `server_time` (integer): Server time in milliseconds.
1040
+ * `server_time_iso` (string, optional): ISO 8601 representation of `server_time`, useful for UI dashboards.
1041
+ * `server_receive_time` (integer, optional): Timestamp when the gateway received the sync request.
1042
+ * `server_send_time` (integer, optional): Timestamp when the gateway replied; used to compute a midpoint for latency compensation.
1043
+ * `request_id` (string, optional): Mirrors the request's `request_id`.
1044
+
1045
+ ### `update_portacode_response`
1046
+
1047
+ Reports the result of an `update_portacode_cli` action. Handled by [`update_portacode_cli`](./update_handler.py).
1048
+
1049
+ **Event Fields:**
1050
+
1051
+ * `success` (boolean, mandatory): Whether the update operation was successful.
1052
+ * `message` (string, optional): Success message when update completes.
1053
+ * `error` (string, optional): Error message when update fails.
1054
+ * `restart_required` (boolean, optional): Indicates if process restart is required (always true for successful updates).
474
1055
 
475
1056
  ### <a name="file_read_response"></a>`file_read_response`
476
1057
 
@@ -479,8 +1060,39 @@ Returns the content of a file in response to a `file_read` action. Handled by [`
479
1060
  **Event Fields:**
480
1061
 
481
1062
  * `path` (string, mandatory): The path of the file that was read.
482
- * `content` (string, mandatory): The content of the file.
483
- * `size` (integer, mandatory): The size of the file in bytes.
1063
+ * `content` (string, mandatory): The file content returned (may be a slice when pagination parameters are used).
1064
+ * `size` (integer, mandatory): The total size of the file in bytes.
1065
+ * `total_lines` (integer, optional): Total number of lines detected in the file.
1066
+ * `returned_lines` (integer, optional): Number of lines included in `content`.
1067
+ * `start_line` (integer, optional): The first line number included in the response (if any lines were returned).
1068
+ * `requested_start_line` (integer, optional): The requested starting line supplied in the command.
1069
+ * `end_line` (integer, optional): The last line number included in the response.
1070
+ * `has_more_before` (boolean, optional): Whether there is additional content before the returned range.
1071
+ * `has_more_after` (boolean, optional): Whether there is additional content after the returned range.
1072
+ * `encoding` (string, optional): Encoding that was used while reading the file.
1073
+
1074
+ ### <a name="file_search_response"></a>`file_search_response`
1075
+
1076
+ Returns aggregated search results in response to a `file_search` action. Handled by [`file_search`](./file_handlers.py).
1077
+
1078
+ **Event Fields:**
1079
+
1080
+ * `root_path` (string, mandatory): The root directory that was searched.
1081
+ * `query` (string, mandatory): The query string that was used.
1082
+ * `match_case` (boolean, mandatory): Indicates if the search was case sensitive.
1083
+ * `regex` (boolean, mandatory): Indicates if the query was interpreted as a regular expression.
1084
+ * `whole_word` (boolean, mandatory): Indicates if the search matched whole words only.
1085
+ * `include_patterns` (array[string], mandatory): Effective include glob patterns.
1086
+ * `exclude_patterns` (array[string], mandatory): Effective exclude glob patterns.
1087
+ * `matches` (array, mandatory): List of match objects containing `relative_path`, `path`, `line_number`, `line`, `match_spans` `[start, end]`, `match_count`, and `line_truncated` (boolean).
1088
+ * `matches_returned` (integer, mandatory): Number of match entries returned (length of `matches`).
1089
+ * `total_matches` (integer, mandatory): Total number of matches found while scanning.
1090
+ * `files_scanned` (integer, mandatory): Count of files inspected.
1091
+ * `truncated` (boolean, mandatory): Indicates if additional matches exist beyond those returned.
1092
+ * `truncated_count` (integer, optional): Number of matches that were omitted due to truncation limits.
1093
+ * `max_results` (integer, mandatory): Maximum number of matches requested.
1094
+ * `max_matches_per_file` (integer, mandatory): Maximum matches requested per file.
1095
+ * `errors` (array[string], optional): Non-fatal errors encountered during scanning (e.g., unreadable files).
484
1096
 
485
1097
  ### <a name="file_write_response"></a>`file_write_response`
486
1098
 
@@ -492,6 +1104,45 @@ Confirms that a file has been written successfully in response to a `file_write`
492
1104
  * `bytes_written` (integer, mandatory): The number of bytes written to the file.
493
1105
  * `success` (boolean, mandatory): Indicates whether the write operation was successful.
494
1106
 
1107
+ ### <a name="file_apply_diff_response"></a>`file_apply_diff_response`
1108
+
1109
+ Reports the outcome of a [`file_apply_diff`](#file_apply_diff) action.
1110
+
1111
+ **Event Fields:**
1112
+
1113
+ * `event`: Always `"file_apply_diff_response"`.
1114
+ * `success`: Boolean indicating whether all hunks succeeded.
1115
+ * `status`: `"success"`, `"partial_failure"`, or `"failed"`.
1116
+ * `base_path`: Absolute base path used for relative diff entries.
1117
+ * `files_changed`: Number of files successfully updated.
1118
+ * `results`: Array containing one object per file with:
1119
+ * `path`: Absolute path on the device.
1120
+ * `status`: `"applied"` or `"error"`.
1121
+ * `action`: `"created"`, `"modified"`, or `"deleted"` (present for successes).
1122
+ * `bytes_written`: Bytes written for the file (0 for deletes).
1123
+ * `error`: Error text when the patch failed for that file.
1124
+ * `line`: Optional line number hint for mismatches.
1125
+
1126
+ The response is emitted even if some files fail so the caller can retry with corrected diffs.
1127
+
1128
+ ### <a name="file_preview_diff_response"></a>`file_preview_diff_response`
1129
+
1130
+ Reports the outcome of a [`file_preview_diff`](#file_preview_diff) action.
1131
+
1132
+ **Event Fields:**
1133
+
1134
+ * `event`: Always `"file_preview_diff_response"`.
1135
+ * `success`: Boolean indicating whether all previews rendered successfully.
1136
+ * `status`: `"success"`, `"partial_failure"`, or `"failed"`.
1137
+ * `base_path`: Absolute base path used for relative paths.
1138
+ * `previews`: Array containing one entry per file with:
1139
+ * `path`: Absolute path hint (used for syntax highlighting).
1140
+ * `relative_path`: Relative project path if known.
1141
+ * `status`: `"ready"` or `"error"`.
1142
+ * `html`: Rendered diff snippet (when status is `"ready"`).
1143
+ * `error`: Error text (when status is `"error"`).
1144
+ * `error`: Optional top-level error string when the entire preview failed (e.g., diff parse error).
1145
+
495
1146
  ### <a name="directory_list_response"></a>`directory_list_response`
496
1147
 
497
1148
  Returns the contents of a directory in response to a `directory_list` action. Handled by [`directory_list`](./file_handlers.py).
@@ -500,7 +1151,11 @@ Returns the contents of a directory in response to a `directory_list` action. Ha
500
1151
 
501
1152
  * `path` (string, mandatory): The path of the directory that was listed.
502
1153
  * `items` (array, mandatory): A list of objects, each representing a file or directory in the listed directory.
503
- * `count` (integer, mandatory): The number of items in the `items` list.
1154
+ * `count` (integer, mandatory): The number of items returned in this response (honours `limit`/`offset`).
1155
+ * `total_count` (integer, mandatory): Total number of entries in the directory before pagination.
1156
+ * `offset` (integer, optional): Offset that was applied.
1157
+ * `limit` (integer, optional): Limit that was applied (or `null` if none).
1158
+ * `has_more` (boolean, optional): Indicates whether additional items remain beyond the returned slice.
504
1159
 
505
1160
  ### <a name="file_info_response"></a>`file_info_response`
506
1161
 
@@ -531,6 +1186,102 @@ Confirms that a file or directory has been deleted in response to a `file_delete
531
1186
  * `deleted_type` (string, mandatory): The type of the deleted item ("file" or "directory").
532
1187
  * `success` (boolean, mandatory): Indicates whether the deletion was successful.
533
1188
 
1189
+ ### <a name="file_create_response"></a>`file_create_response`
1190
+
1191
+ Confirms that a file has been created successfully in response to a `file_create` action. Handled by [`file_create`](./file_handlers.py).
1192
+
1193
+ **Event Fields:**
1194
+
1195
+ * `parent_path` (string, mandatory): The path of the parent directory where the file was created.
1196
+ * `file_name` (string, mandatory): The name of the created file.
1197
+ * `file_path` (string, mandatory): The full absolute path to the created file.
1198
+ * `success` (boolean, mandatory): Indicates whether the creation was successful.
1199
+
1200
+ ### <a name="folder_create_response"></a>`folder_create_response`
1201
+
1202
+ Confirms that a folder has been created successfully in response to a `folder_create` action. Handled by [`folder_create`](./file_handlers.py).
1203
+
1204
+ **Event Fields:**
1205
+
1206
+ * `parent_path` (string, mandatory): The path of the parent directory where the folder was created.
1207
+ * `folder_name` (string, mandatory): The name of the created folder.
1208
+ * `folder_path` (string, mandatory): The full absolute path to the created folder.
1209
+ * `success` (boolean, mandatory): Indicates whether the creation was successful.
1210
+
1211
+ ### <a name="file_rename_response"></a>`file_rename_response`
1212
+
1213
+ Confirms that a file or folder has been renamed successfully in response to a `file_rename` action. Handled by [`file_rename`](./file_handlers.py).
1214
+
1215
+ **Event Fields:**
1216
+
1217
+ * `old_path` (string, mandatory): The original path of the renamed item.
1218
+ * `new_path` (string, mandatory): The new path of the renamed item.
1219
+ * `new_name` (string, mandatory): The new name of the item.
1220
+ * `is_directory` (boolean, mandatory): Indicates whether the renamed item is a directory.
1221
+ * `success` (boolean, mandatory): Indicates whether the rename was successful.
1222
+
1223
+ ### <a name="content_response"></a>`content_response`
1224
+
1225
+ Returns cached content in response to a `content_request` action. This is part of the content caching system used for performance optimization. For large content (>200KB), the response is automatically chunked into multiple messages to ensure reliable transmission over WebSocket connections. Handled by [`content_request`](./file_handlers.py).
1226
+
1227
+ **Event Fields:**
1228
+
1229
+ * `request_id` (string, mandatory): The unique identifier from the corresponding request, used to match request and response.
1230
+ * `content_hash` (string, mandatory): The SHA-256 hash that was requested.
1231
+ * `content` (string, optional): The cached content or chunk content if found and `success` is true. Null if content was not found.
1232
+ * `success` (boolean, mandatory): Indicates whether the content was found and returned successfully.
1233
+ * `error` (string, optional): Error message if `success` is false (e.g., "Content not found in cache").
1234
+ * `chunked` (boolean, mandatory): Indicates whether this response is part of a chunked transfer. False for single responses, true for chunked responses.
1235
+
1236
+ **Chunked Transfer Fields (when `chunked` is true):**
1237
+
1238
+ * `transfer_id` (string, mandatory): Unique identifier for the chunked transfer session.
1239
+ * `chunk_index` (integer, mandatory): Zero-based index of this chunk in the sequence.
1240
+ * `chunk_count` (integer, mandatory): Total number of chunks in the transfer.
1241
+ * `chunk_size` (integer, mandatory): Size of this chunk in bytes.
1242
+ * `total_size` (integer, mandatory): Total size of the complete content in bytes.
1243
+ * `chunk_hash` (string, mandatory): SHA-256 hash of this chunk for verification.
1244
+ * `is_final_chunk` (boolean, mandatory): Indicates if this is the last chunk in the sequence.
1245
+
1246
+ **Chunked Transfer Process:**
1247
+
1248
+ 1. **Size Check**: Content >200KB is automatically chunked into 64KB chunks
1249
+ 2. **Sequential Delivery**: Chunks are sent in order with increasing `chunk_index`
1250
+ 3. **Client Assembly**: Client collects all chunks and verifies integrity using hashes
1251
+ 4. **Hash Verification**: Both individual chunk hashes and final content hash are verified
1252
+ 5. **Error Handling**: Missing chunks or hash mismatches trigger request failure
1253
+
1254
+ **Example Non-Chunked Response:**
1255
+ ```json
1256
+ {
1257
+ "event": "content_response",
1258
+ "request_id": "req_abc123",
1259
+ "content_hash": "sha256:...",
1260
+ "content": "Small content here",
1261
+ "success": true,
1262
+ "chunked": false
1263
+ }
1264
+ ```
1265
+
1266
+ **Example Chunked Response (first chunk):**
1267
+ ```json
1268
+ {
1269
+ "event": "content_response",
1270
+ "request_id": "req_abc123",
1271
+ "content_hash": "sha256:...",
1272
+ "content": "First chunk content...",
1273
+ "success": true,
1274
+ "chunked": true,
1275
+ "transfer_id": "transfer_xyz789",
1276
+ "chunk_index": 0,
1277
+ "chunk_count": 5,
1278
+ "chunk_size": 65536,
1279
+ "total_size": 300000,
1280
+ "chunk_hash": "chunk_sha256:...",
1281
+ "is_final_chunk": false
1282
+ }
1283
+ ```
1284
+
534
1285
  ### Project State Events
535
1286
 
536
1287
  ### <a name="project_state_initialized"></a>`project_state_initialized`
@@ -539,12 +1290,49 @@ Confirms that project state has been successfully initialized for a client sessi
539
1290
 
540
1291
  **Event Fields:**
541
1292
 
1293
+ * `project_id` (string, mandatory): The project ID for the initialized project state.
542
1294
  * `project_folder_path` (string, mandatory): The absolute path to the project folder.
543
1295
  * `is_git_repo` (boolean, mandatory): Whether the project folder is a Git repository.
544
1296
  * `git_branch` (string, optional): The current Git branch name if available.
545
1297
  * `git_status_summary` (object, optional): Summary of Git status counts (modified, added, deleted, untracked files).
546
- * `open_files` (array, mandatory): Array of file paths currently marked as open.
547
- * `active_file` (string, optional): Path to the currently active file.
1298
+ * `git_detailed_status` (object, optional): Detailed Git status with comprehensive file change information and content hashes. Contains:
1299
+ * `head_commit_hash` (string, optional): SHA hash of the HEAD commit.
1300
+ * `staged_changes` (array, optional): Array of staged file changes. Each change contains:
1301
+ * `file_repo_path` (string): Relative path from repository root.
1302
+ * `file_name` (string): Just the filename (basename).
1303
+ * `file_abs_path` (string): Absolute path to the file.
1304
+ * `change_type` (string): Type of change following git's native types ('added', 'modified', 'deleted', 'untracked'). Note: renames appear as separate 'deleted' and 'added' entries unless git detects them as modifications.
1305
+ * `content_hash` (string, optional): SHA256 hash of current file content. Null for deleted files.
1306
+ * `is_staged` (boolean): Always true for staged changes.
1307
+ * `diff_details` (object, optional): Per-character diff information computed using diff-match-patch algorithm. Contains:
1308
+ * `diffs` (array): Array of diff operations, each containing:
1309
+ * `operation` (integer): Diff operation type (-1 = delete, 0 = equal, 1 = insert).
1310
+ * `text` (string): The text content for this operation.
1311
+ * `stats` (object): Statistics about the diff:
1312
+ * `char_additions` (integer): Number of characters added.
1313
+ * `char_deletions` (integer): Number of characters deleted.
1314
+ * `char_unchanged` (integer): Number of characters unchanged.
1315
+ * `total_changes` (integer): Total number of character changes (additions + deletions).
1316
+ * `algorithm` (string): Always "diff-match-patch" indicating the algorithm used.
1317
+ * `unstaged_changes` (array, optional): Array of unstaged file changes with same structure as staged_changes but `is_staged` is always false.
1318
+ * `untracked_files` (array, optional): Array of untracked files with same structure as staged_changes but `is_staged` is always false and `change_type` is always 'untracked'.
1319
+ * `open_tabs` (array, mandatory): Array of tab objects currently open. Internally stored as a dictionary with unique keys to prevent duplicates, but serialized as an array for API responses. Each tab object contains:
1320
+ * `tab_id` (string, mandatory): Unique identifier for the tab.
1321
+ * `tab_type` (string, mandatory): Type of tab ("file", "diff", "untitled", "image", "audio", "video").
1322
+ * `title` (string, mandatory): Display title for the tab.
1323
+ * `file_path` (string, optional): Path for file-based tabs.
1324
+ * `content` (string, optional): Text content or base64 for media. When content caching is enabled, this field may be excluded from project state events if the content is available via `content_hash`.
1325
+ * `original_content` (string, optional): For diff tabs - original content. When content caching is enabled, this field may be excluded from project state events if the content is available via `original_content_hash`.
1326
+ * `modified_content` (string, optional): For diff tabs - modified content. When content caching is enabled, this field may be excluded from project state events if the content is available via `modified_content_hash`.
1327
+ * `is_dirty` (boolean, mandatory): Whether the tab has unsaved changes.
1328
+ * `mime_type` (string, optional): MIME type for media files.
1329
+ * `encoding` (string, optional): Content encoding (base64, utf-8, etc.).
1330
+ * `metadata` (object, optional): Additional metadata. When content caching is enabled, large metadata such as `html_diff_versions` may be excluded from project state events if available via `html_diff_hash`.
1331
+ * `content_hash` (string, optional): SHA-256 hash of the tab content for content caching optimization. When present, the content can be retrieved via [`content_request`](#content_request) action.
1332
+ * `original_content_hash` (string, optional): SHA-256 hash of the original content for diff tabs. When present, the original content can be retrieved via [`content_request`](#content_request) action.
1333
+ * `modified_content_hash` (string, optional): SHA-256 hash of the modified content for diff tabs. When present, the modified content can be retrieved via [`content_request`](#content_request) action.
1334
+ * `html_diff_hash` (string, optional): SHA-256 hash of the HTML diff versions JSON for diff tabs. When present, the HTML diff data can be retrieved via [`content_request`](#content_request) action as a JSON string.
1335
+ * `active_tab` (object, optional): The currently active tab object, or null if no tab is active.
548
1336
  * `items` (array, mandatory): Flattened array of all visible file/folder items. Always includes root level items and one level down from the project root (since the project root is treated as expanded by default). Also includes items within explicitly expanded folders and one level down from each expanded folder. Each item object contains the following fields:
549
1337
  * `name` (string, mandatory): The file or directory name.
550
1338
  * `path` (string, mandatory): The absolute path to the file or directory.
@@ -558,7 +1346,7 @@ Confirms that project state has been successfully initialized for a client sessi
558
1346
  * `is_ignored` (boolean, mandatory): Whether the file is ignored by Git. Only meaningful if project is a Git repository.
559
1347
  * `children` (array, optional): Array of child FileItem objects for directories. Usually null in flattened structure as children are included as separate items.
560
1348
  * `is_expanded` (boolean, mandatory): Whether this directory is expanded in the project tree. Only meaningful for directories.
561
- * `is_loaded` (boolean, mandatory): Whether the directory contents have been loaded. Always true for files, indicates loading state for directories.
1349
+ * `is_loaded` (boolean, mandatory): Whether the directory contents have been loaded and are available. Always true for files. For directories, true indicates that the directory is being monitored (in monitored_folders) and its contents are loaded and available in the items list, enabling immediate expansion when requested.
562
1350
  * `timestamp` (float, mandatory): Unix timestamp of when the state was generated.
563
1351
 
564
1352
  ### <a name="project_state_update"></a>`project_state_update`
@@ -572,8 +1360,9 @@ Sent automatically when project state changes due to file system modifications,
572
1360
  * `is_git_repo` (boolean, mandatory): Whether the project folder is a Git repository.
573
1361
  * `git_branch` (string, optional): The current Git branch name if available.
574
1362
  * `git_status_summary` (object, optional): Updated summary of Git status counts.
575
- * `open_files` (array, mandatory): Updated array of open file paths.
576
- * `active_file` (string, optional): Updated active file path.
1363
+ * `git_detailed_status` (object, optional): Updated detailed Git status with comprehensive file change information, content hashes, and per-character diff details (same structure as in `project_state_initialized`).
1364
+ * `open_tabs` (array, mandatory): Updated array of tab objects currently open. Internally stored as a dictionary with unique keys to prevent duplicates, but serialized as an array for API responses.
1365
+ * `active_tab` (object, optional): Updated active tab object.
577
1366
  * `items` (array, mandatory): Updated flattened array of all visible file/folder items. Always includes root level items and one level down from the project root (since the project root is treated as expanded by default). Also includes items within explicitly expanded folders and one level down from each expanded folder. Each item object contains the following fields:
578
1367
  * `name` (string, mandatory): The file or directory name.
579
1368
  * `path` (string, mandatory): The absolute path to the file or directory.
@@ -587,7 +1376,7 @@ Sent automatically when project state changes due to file system modifications,
587
1376
  * `is_ignored` (boolean, mandatory): Whether the file is ignored by Git. Only meaningful if project is a Git repository.
588
1377
  * `children` (array, optional): Array of child FileItem objects for directories. Usually null in flattened structure as children are included as separate items.
589
1378
  * `is_expanded` (boolean, mandatory): Whether this directory is expanded in the project tree. Only meaningful for directories.
590
- * `is_loaded` (boolean, mandatory): Whether the directory contents have been loaded. Always true for files, indicates loading state for directories.
1379
+ * `is_loaded` (boolean, mandatory): Whether the directory contents have been loaded and are available. Always true for files. For directories, true indicates that the directory is being monitored (in monitored_folders) and its contents are loaded and available in the items list, enabling immediate expansion when requested.
591
1380
  * `timestamp` (float, mandatory): Unix timestamp of when the update was generated.
592
1381
 
593
1382
  ### <a name="project_state_folder_expand_response"></a>`project_state_folder_expand_response`
@@ -621,26 +1410,123 @@ Confirms the result of a file open operation.
621
1410
  * `success` (boolean, mandatory): Whether the file open operation was successful.
622
1411
  * `set_active` (boolean, mandatory): Whether the file was also set as the active file.
623
1412
 
624
- ### <a name="project_state_file_close_response"></a>`project_state_file_close_response`
1413
+ ### <a name="project_state_tab_close_response"></a>`project_state_tab_close_response`
625
1414
 
626
- Confirms the result of a file close operation.
1415
+ Confirms the result of a tab close operation.
627
1416
 
628
1417
  **Event Fields:**
629
1418
 
630
1419
  * `project_id` (string, mandatory): The project ID the operation was performed on.
631
- * `file_path` (string, mandatory): The path to the file that was closed.
632
- * `success` (boolean, mandatory): Whether the file close operation was successful.
1420
+ * `tab_id` (string, mandatory): The ID of the tab that was closed.
1421
+ * `success` (boolean, mandatory): Whether the tab close operation was successful.
633
1422
 
634
- ### <a name="project_state_set_active_file_response"></a>`project_state_set_active_file_response`
1423
+ ### <a name="project_state_set_active_tab_response"></a>`project_state_set_active_tab_response`
635
1424
 
636
- Confirms the result of setting an active file.
1425
+ Confirms the result of setting an active tab.
637
1426
 
638
1427
  **Event Fields:**
639
1428
 
640
1429
  * `project_id` (string, mandatory): The project ID the operation was performed on.
641
- * `file_path` (string, optional): The path to the file that was set as active (null if cleared).
1430
+ * `tab_id` (string, optional): The ID of the tab that was set as active (null if cleared).
642
1431
  * `success` (boolean, mandatory): Whether the operation was successful.
643
1432
 
1433
+ ### <a name="project_state_diff_open_response"></a>`project_state_diff_open_response`
1434
+
1435
+ Confirms the result of opening a diff tab with git timeline references.
1436
+
1437
+ **Event Fields:**
1438
+
1439
+ * `project_id` (string, mandatory): The project ID the operation was performed on.
1440
+ * `file_path` (string, mandatory): The path to the file the diff tab was created for.
1441
+ * `from_ref` (string, mandatory): The source reference point that was used.
1442
+ * `to_ref` (string, mandatory): The target reference point that was used.
1443
+ * `from_hash` (string, optional): The commit hash used for `from_ref` if it was `"commit"`.
1444
+ * `to_hash` (string, optional): The commit hash used for `to_ref` if it was `"commit"`.
1445
+ * `success` (boolean, mandatory): Whether the diff tab creation was successful.
1446
+ * `error` (string, optional): Error message if the operation failed.
1447
+
1448
+ ### <a name="project_state_diff_content_response"></a>`project_state_diff_content_response`
1449
+
1450
+ Returns the requested content for a specific diff tab, sent in response to a [`project_state_diff_content_request`](#project_state_diff_content_request) action. For large content (>200KB), the response is automatically chunked into multiple messages to ensure reliable transmission over WebSocket connections.
1451
+
1452
+ **Event Fields:**
1453
+
1454
+ * `project_id` (string, mandatory): The project ID the operation was performed on.
1455
+ * `file_path` (string, mandatory): The path to the file the diff content is for.
1456
+ * `from_ref` (string, mandatory): The source reference point used in the diff.
1457
+ * `to_ref` (string, mandatory): The target reference point used in the diff.
1458
+ * `from_hash` (string, optional): The commit hash used for `from_ref` if it was `"commit"`.
1459
+ * `to_hash` (string, optional): The commit hash used for `to_ref` if it was `"commit"`.
1460
+ * `content_type` (string, mandatory): The type of content being returned (`"original"`, `"modified"`, `"html_diff"`, or `"all"`).
1461
+ * `request_id` (string, mandatory): The unique identifier from the request to match response with request.
1462
+ * `success` (boolean, mandatory): Whether the content retrieval was successful.
1463
+ * `content` (string, optional): The requested content or chunk content. For `html_diff` type, this is a JSON string containing the HTML diff versions object. For `all` type, this is a JSON string containing an object with `original_content`, `modified_content`, and `html_diff_versions` fields.
1464
+ * `error` (string, optional): Error message if the operation failed.
1465
+ * `chunked` (boolean, mandatory): Indicates whether this response is part of a chunked transfer. False for single responses, true for chunked responses.
1466
+
1467
+ **Chunked Transfer Fields (when `chunked` is true):**
1468
+
1469
+ * `transfer_id` (string, mandatory): Unique identifier for the chunked transfer session.
1470
+ * `chunk_index` (integer, mandatory): Zero-based index of this chunk in the sequence.
1471
+ * `chunk_count` (integer, mandatory): Total number of chunks in the transfer.
1472
+ * `chunk_size` (integer, mandatory): Size of this chunk in bytes.
1473
+ * `total_size` (integer, mandatory): Total size of the complete content in bytes.
1474
+ * `chunk_hash` (string, mandatory): SHA-256 hash of this chunk for verification.
1475
+ * `is_final_chunk` (boolean, mandatory): Indicates if this is the last chunk in the sequence.
1476
+
1477
+ **Note:** The chunked transfer process follows the same pattern as described in [`content_response`](#content_response), with content >200KB automatically split into 64KB chunks for reliable transmission.
1478
+
1479
+ ### <a name="project_state_git_stage_response"></a>`project_state_git_stage_response`
1480
+
1481
+ Confirms the result of a git stage operation. Supports responses for both single file and bulk operations.
1482
+
1483
+ **Event Fields:**
1484
+
1485
+ * `project_id` (string, mandatory): The project ID the operation was performed on.
1486
+ * `file_path` (string, optional): The path to the file that was staged (for single file operations).
1487
+ * `file_paths` (array of strings, optional): Array of paths to files that were staged (for bulk operations).
1488
+ * `stage_all` (boolean, optional): Present if the operation was a "stage all" operation.
1489
+ * `success` (boolean, mandatory): Whether the stage operation was successful.
1490
+ * `error` (string, optional): Error message if the operation failed.
1491
+
1492
+ ### <a name="project_state_git_unstage_response"></a>`project_state_git_unstage_response`
1493
+
1494
+ Confirms the result of a git unstage operation. Supports responses for both single file and bulk operations.
1495
+
1496
+ **Event Fields:**
1497
+
1498
+ * `project_id` (string, mandatory): The project ID the operation was performed on.
1499
+ * `file_path` (string, optional): The path to the file that was unstaged (for single file operations).
1500
+ * `file_paths` (array of strings, optional): Array of paths to files that were unstaged (for bulk operations).
1501
+ * `unstage_all` (boolean, optional): Present if the operation was an "unstage all" operation.
1502
+ * `success` (boolean, mandatory): Whether the unstage operation was successful.
1503
+ * `error` (string, optional): Error message if the operation failed.
1504
+
1505
+ ### <a name="project_state_git_revert_response"></a>`project_state_git_revert_response`
1506
+
1507
+ Confirms the result of a git revert operation. Supports responses for both single file and bulk operations.
1508
+
1509
+ **Event Fields:**
1510
+
1511
+ * `project_id` (string, mandatory): The project ID the operation was performed on.
1512
+ * `file_path` (string, optional): The path to the file that was reverted (for single file operations).
1513
+ * `file_paths` (array of strings, optional): Array of paths to files that were reverted (for bulk operations).
1514
+ * `revert_all` (boolean, optional): Present if the operation was a "revert all" operation.
1515
+ * `success` (boolean, mandatory): Whether the revert operation was successful.
1516
+ * `error` (string, optional): Error message if the operation failed.
1517
+
1518
+ ### <a name="project_state_git_commit_response"></a>`project_state_git_commit_response`
1519
+
1520
+ Confirms the result of a git commit operation.
1521
+
1522
+ **Event Fields:**
1523
+
1524
+ * `project_id` (string, mandatory): The project ID the operation was performed on.
1525
+ * `commit_message` (string, mandatory): The commit message that was used.
1526
+ * `success` (boolean, mandatory): Whether the commit operation was successful.
1527
+ * `error` (string, optional): Error message if the operation failed.
1528
+ * `commit_hash` (string, optional): The SHA hash of the new commit if successful.
1529
+
644
1530
  ### Client Session Events
645
1531
 
646
1532
  ### <a name="request_client_sessions"></a>`request_client_sessions`
@@ -711,4 +1597,4 @@ Sent by the server to clients to provide initial device list snapshot.
711
1597
 
712
1598
  **Event Fields:**
713
1599
 
714
- * `devices` (array, mandatory): Array of device objects with status information
1600
+ * `devices` (array, mandatory): Array of device objects with status information