ai-editor-client-dev 1.0.244__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (25) hide show
  1. ai_editor_client_dev-1.0.244/PKG-INFO +236 -0
  2. ai_editor_client_dev-1.0.244/README.md +224 -0
  3. ai_editor_client_dev-1.0.244/ai_editor_client/__init__.py +183 -0
  4. ai_editor_client_dev-1.0.244/ai_editor_client/client.py +772 -0
  5. ai_editor_client_dev-1.0.244/ai_editor_client/commands_proxy.py +60 -0
  6. ai_editor_client_dev-1.0.244/ai_editor_client/config.py +126 -0
  7. ai_editor_client_dev-1.0.244/ai_editor_client/editor_file.py +205 -0
  8. ai_editor_client_dev-1.0.244/ai_editor_client/exceptions.py +48 -0
  9. ai_editor_client_dev-1.0.244/ai_editor_client/file_session.py +692 -0
  10. ai_editor_client_dev-1.0.244/ai_editor_client/local_edit_workspace.py +102 -0
  11. ai_editor_client_dev-1.0.244/ai_editor_client/py.typed +0 -0
  12. ai_editor_client_dev-1.0.244/ai_editor_client/responses.py +45 -0
  13. ai_editor_client_dev-1.0.244/ai_editor_client/server_api.py +222 -0
  14. ai_editor_client_dev-1.0.244/ai_editor_client/server_schema.py +57 -0
  15. ai_editor_client_dev-1.0.244/ai_editor_client/server_version.py +171 -0
  16. ai_editor_client_dev-1.0.244/ai_editor_client/universal_file.py +189 -0
  17. ai_editor_client_dev-1.0.244/ai_editor_client/validation.py +98 -0
  18. ai_editor_client_dev-1.0.244/ai_editor_client/version.txt +1 -0
  19. ai_editor_client_dev-1.0.244/ai_editor_client_dev.egg-info/PKG-INFO +236 -0
  20. ai_editor_client_dev-1.0.244/ai_editor_client_dev.egg-info/SOURCES.txt +23 -0
  21. ai_editor_client_dev-1.0.244/ai_editor_client_dev.egg-info/dependency_links.txt +1 -0
  22. ai_editor_client_dev-1.0.244/ai_editor_client_dev.egg-info/requires.txt +5 -0
  23. ai_editor_client_dev-1.0.244/ai_editor_client_dev.egg-info/top_level.txt +1 -0
  24. ai_editor_client_dev-1.0.244/pyproject.toml +41 -0
  25. ai_editor_client_dev-1.0.244/setup.cfg +4 -0
@@ -0,0 +1,236 @@
1
+ Metadata-Version: 2.4
2
+ Name: ai-editor-client-dev
3
+ Version: 1.0.244
4
+ Summary: Async JSON-RPC client for the ai-editor MCP server (mcp-proxy-adapter JsonRpcClient)
5
+ Author-email: Vasiliy Zdanovskiy <vasilyvz@gmail.com>
6
+ Requires-Python: >=3.10
7
+ Description-Content-Type: text/markdown
8
+ Requires-Dist: mcp-proxy-adapter==8.11.20
9
+ Provides-Extra: dev
10
+ Requires-Dist: pytest>=8.0; extra == "dev"
11
+ Requires-Dist: pytest-asyncio>=0.25.0; extra == "dev"
12
+
13
+ # code-analysis-client
14
+
15
+ Async Python client for the **code-analysis** server. It wraps `mcp-proxy-adapter`'s `JsonRpcClient`, so you get the adapter's built-in methods (queue, transfer, `help`, `health`, …) plus thin helpers to run any registered server command. On the thin AI Editor Server, file editing uses `universal_file_*` commands only; queue polling helpers remain for generic RPC but are not part of the file workflow surface.
16
+
17
+ ## Install
18
+
19
+ ```bash
20
+ pip install code-analysis-client
21
+ ```
22
+
23
+ ## Usage
24
+
25
+ ```python
26
+ import asyncio
27
+ from code_analysis_client import CodeAnalysisAsyncClient
28
+
29
+
30
+ async def main() -> None:
31
+ client = CodeAnalysisAsyncClient(
32
+ protocol="https",
33
+ host="127.0.0.1",
34
+ port=15001,
35
+ cert="/path/client.crt",
36
+ key="/path/client.key",
37
+ ca="/path/ca.crt",
38
+ timeout=120.0,
39
+ )
40
+ async with client:
41
+ h = await client.rpc.help()
42
+ r = await client.call("list_projects", {"include_deleted": False})
43
+ print(h, r)
44
+
45
+
46
+ asyncio.run(main())
47
+ ```
48
+
49
+ Build client settings from the same JSON shape as the pipeline adapter settings (`host`, `port`, `protocol`, optional `ssl` with `cert` / `key` / `ca` or `*_path` aliases), or from a full server `config.json` object.
50
+
51
+ ```python
52
+ from code_analysis_client import CodeAnalysisAsyncClient
53
+
54
+ client = CodeAnalysisAsyncClient.from_server_config(config_dict, timeout=60.0)
55
+ ```
56
+
57
+ Queued/long commands: use `client.call_unified(..., expect_queue=True, auto_poll=True)` or the underlying `client.rpc.execute_command_unified(...)`.
58
+
59
+ ## Validation using the server schema
60
+
61
+ The authoritative input schema is whatever the running server returns from **`help`** with `cmdname` set to the command. The client calls that, optionally caches the result, performs the same shallow checks as the server's `BaseMCPCommand` (types, `required`, `enum`, `additionalProperties`), then runs the command.
62
+
63
+ ```python
64
+ async with CodeAnalysisAsyncClient(host="127.0.0.1", port=15001) as client:
65
+ # Explicit
66
+ out = await client.call_validated(
67
+ "list_projects",
68
+ {"include_deleted": False},
69
+ )
70
+ # Dynamic wrapper: same as call_validated("list_projects", {...})
71
+ out = await client.commands.list_projects(include_deleted=False)
72
+ # After server reload
73
+ client.clear_command_schema_cache()
74
+ ```
75
+
76
+ Use `call_unified_validated` when you need queue polling. Pass `refresh_schema=True` on a single call to bypass the in-memory schema cache.
77
+
78
+ ## File Workflow (C-009)
79
+
80
+ The thin AI Editor Server exposes file editing only through `UniversalFileClient` (`client.universal_files`). One file at a time follows **open → edit → write → close**. Optional read-only inspection during an open file uses `preview` (`universal_file_preview`). Every stage requires the same CA Session `session_id`, `project_id`, and (where applicable) `file_path`.
81
+
82
+ ### Workflow stages
83
+
84
+ 1. **Open** (`universal_file_open`) — agent supplies CA `session_id`; server locks file on upstream CA, creates local Editor Session Directory and File Subtree, stores Origin Snapshot, creates Edit Subdirectory. Use `create=True` with `initial_content` for new files. To edit a documentation-server document, call `client.universal_files.open_document(project_id, session_id, document_id)` (`source="doc"`, no `file_path`): the Code Analysis Server fetches it into the project, the answer names the `file_path` and echoes `source` / `document_id`; a write of such a file reports a pending transfer through `degraded` / `degraded_reason` / `uploaded=false`.
85
+ 2. **Edit** (`universal_file_edit`) — mutations apply only to the Edit Subdirectory; Origin Snapshot unchanged.
86
+ 3. **Write** (`universal_file_write`) — compares Origin Snapshot to edited content; `write_mode="preview"` returns local diff without upstream upload; commit mode uploads to CA on change and refreshes Origin Snapshot on success.
87
+ 4. **Close** (`universal_file_close`) — unlocks file on CA, removes local File Subtree; removes Editor Session Directory when last file in session closes.
88
+
89
+ ### Minimal async example
90
+
91
+ ```python
92
+ import asyncio
93
+ import uuid
94
+
95
+ from ai_editor_client import CodeAnalysisAsyncClient
96
+
97
+
98
+ async def main() -> None:
99
+ # Created upstream via CA session_create (outside this client package).
100
+ ca_session_id = str(uuid.uuid4())
101
+
102
+ async with CodeAnalysisAsyncClient.from_server_config_path("config.json") as client:
103
+ uf = client.universal_files
104
+ project_id = "..."
105
+ file_path = "src/example.py"
106
+
107
+ await uf.open(
108
+ session_id=ca_session_id,
109
+ project_id=project_id,
110
+ file_path=file_path,
111
+ )
112
+ await uf.preview(
113
+ session_id=ca_session_id,
114
+ project_id=project_id,
115
+ file_path=file_path,
116
+ )
117
+ await uf.edit(
118
+ session_id=ca_session_id,
119
+ project_id=project_id,
120
+ file_path=file_path,
121
+ operations=[{"action": "replace", "start_line": 1, "end_line": 1, "code": "# edited\n"}],
122
+ )
123
+ await uf.write(
124
+ session_id=ca_session_id,
125
+ project_id=project_id,
126
+ file_path=file_path,
127
+ write_mode="preview",
128
+ )
129
+ await uf.close(
130
+ session_id=ca_session_id,
131
+ project_id=project_id,
132
+ file_path=file_path,
133
+ )
134
+
135
+
136
+ asyncio.run(main())
137
+ ```
138
+
139
+ Full runnable script: `client/examples/ex_universal_files.py`.
140
+
141
+ ### CA Session ID contract (C-003)
142
+
143
+ - The **agent** creates the CA Session on Code Analysis Server (`session_create`) **before** calling any editor `universal_file_*` command. That RPC is **not** part of the thin editor MCP surface and is **not** wrapped by `UniversalFileClient`.
144
+ - The agent passes the **same** `session_id` string to every `universal_file_open`, `universal_file_edit`, `universal_file_write`, `universal_file_close`, and `universal_file_preview` call for the workflow.
145
+ - Do **not** treat the `open` response as the source of `session_id` for later calls. If the server echoes `session_id`, it must match the agent-supplied value; the agent already owns the identifier.
146
+ - The agent decides when to `write` (commit or preview) and `close`; the client library does not manage CA session lifecycle.
147
+
148
+ ## High-level facades (thin AI Editor Server / C-016)
149
+
150
+ The supported public MCP commands for file workflow are `UNIVERSAL_FILE_COMMANDS` plus `health` only (`CLIENT_FACADE_COMMANDS` in `ai_editor_client.server_api`). CST commands (`cst_*`, `list_cst_blocks`, `query_cst`) and legacy direct file I/O are in `REMOVED_COMMANDS` — not on the thin server, not documented as supported. `client.universal_files` is the **only** supported high-level facade for file editing.
151
+
152
+ | Facade | Property | Server commands | Status |
153
+ |--------|----------|-----------------|--------|
154
+ | Universal file workflow | `client.universal_files` | `universal_file_open`, `universal_file_edit`, `universal_file_write`, `universal_file_close`, `universal_file_preview` | **Supported** (C-009 / C-016) |
155
+ | Infrastructure | `client.call("health", {})` or adapter `health` | `health` | **Supported** |
156
+ | Generic RPC | `client.call` / `client.commands.<name>` | any command returned by live `help()` on connected server | Escape hatch; thin server exposes only rows above for files |
157
+ | Legacy sessions + transfer | `client.file_sessions` | `session_*`, `subordinate_session_*`, `project_file_transfer_*`, `project_file_advisory_lock_batch` | **Deprecated** — `DEPRECATED_CLIENT_FACADE_COMMANDS`; not registered on thin editor server |
158
+
159
+ Canonical command lists: `ai_editor_client.server_api` exports `UNIVERSAL_FILE_COMMANDS`, `INFRASTRUCTURE_COMMANDS`, `CLIENT_FACADE_COMMANDS`, `DEPRECATED_CLIENT_FACADE_COMMANDS`, and `REMOVED_COMMANDS`.
160
+
161
+ Sync checks (in-process registry):
162
+
163
+ ```bash
164
+ pytest tests/test_client_server_api_sync.py -v
165
+ ```
166
+
167
+ These tests assert `CLIENT_FACADE_COMMANDS` matches the live server registry (C-016) and `REMOVED_COMMANDS` are absent from the server (C-022).
168
+
169
+ Package version is in ``client/ai_editor_client/version.txt``, which is a
170
+ **symlink to the repository-root ``VERSION`` file** — the single source of truth
171
+ shared by the server (``ai-editor``), this client (``ai-editor-client``) and the
172
+ engine (``ai-editor-tree-engine``). There is nothing to sync: bump the root
173
+ ``VERSION`` and all three move together. ``scripts/sync_code_analysis_client_version.py``
174
+ now verifies that invariant instead of copying a number.
175
+
176
+ ## Examples (this repository)
177
+
178
+ Runnable scripts live under `client/examples/`. **Long-form "man page" style
179
+ documentation** is embedded in the **module docstrings** of those Python files
180
+ (see `client/examples/README.md` for how to read them).
181
+
182
+ | Script | Purpose | Pipeline check |
183
+ |--------|---------|-----------------|
184
+ | `ex_universal_files.py` | **Primary:** C-009 File Workflow demo — all `UniversalFileClient` methods with agent-supplied CA `session_id` (C-003) | `check-live-client-universal-files` |
185
+ | `ex_minimal_validated.py` | Smallest validated RPC example (`health` / generic call) | `check-live-client-minimal-validated` |
186
+ | `ex_config_only.py` | Parse `config.json` without TCP | (local-only, no network; not in the pipeline) |
187
+ | `ex_session_view_subordinates.py` | **Deprecated** — legacy CA session API; not thin editor MCP | `check-live-client-session-view-subordinates` (TB11-0: contracted-rejection GREEN — the deployed server registers none of the `file_sessions.*` commands this deprecated facade needs, and the check asserts exactly that: each one raises the typed JSON-RPC `-32601` "Method not found" error, the facade's `DeprecationWarning` fires, and nothing is ever created to leak) |
188
+ | `ex_file_sessions.py` | **Deprecated** — legacy sessions/transfer; not thin editor MCP | `check-live-client-file-sessions` (TB11-0: contracted-rejection GREEN, same pattern — sessions, locks and transfer commands all typed -32601) |
189
+
190
+ `client/examples/run_all_examples.py` — the second runner that used to run
191
+ every sibling script above as a subprocess (bug 5094ad29) — is gone; every
192
+ live-server example above is driven, unmodified and in-process, by its own
193
+ named `pipeline` check under `pipeline/checks/check_live_client_*.py`,
194
+ through the PUBLISHED `ai_editor_client` package against the real deployed
195
+ server. The constructors/`rpc`/`call`/validated-facade/`commands`-proxy/
196
+ low-level-schema/context-manager sections that used to live inline in
197
+ `run_all_examples.py` are covered by `check-live-client-facade-surface`.
198
+
199
+ For file editing on thin AI Editor Server, start with `ex_universal_files.py`; do not use `ex_file_sessions.py` or `ex_session_view_subordinates.py` as file workflow templates.
200
+
201
+ ```bash
202
+ aiedmgr --config config.json start
203
+ python client/examples/ex_universal_files.py
204
+ ```
205
+
206
+ ## Release notes
207
+
208
+ ### 1.0.235
209
+
210
+ - BREAKING: paged preview. `UniversalFileClient.preview` now pages with the shared `page` and
211
+ `page_max_bytes` parameters (same contract as search). The former `preview_page` parameter is
212
+ removed; `max_output_bytes` is only the drill-down budget and never a page cap. Results carry
213
+ `total_records` and `records_returned`. Callers that sent `preview_page` must send `page`.
214
+ - Server key `page_max_bytes_default` (deployed as 20000) sets the default page size.
215
+
216
+ ## Development
217
+
218
+ From the repository root:
219
+
220
+ ```bash
221
+ pip install -e ./client
222
+ pytest tests/test_code_analysis_client.py
223
+ ```
224
+
225
+ ### Releasing to PyPI (version = the root ``VERSION`` file)
226
+
227
+ The client wheel version is read from ``client/ai_editor_client/version.txt``,
228
+ a symlink to the repository-root ``VERSION`` file. The server, this client and
229
+ ``ai-editor-tree-engine`` therefore always publish the same number; the build
230
+ resolves the symlink and writes real content into the sdist and the wheel.
231
+ Verify before build:
232
+
233
+ ```bash
234
+ python scripts/sync_code_analysis_client_version.py
235
+ cd client && python -m build && twine check dist/* && twine upload dist/*
236
+ ```
@@ -0,0 +1,224 @@
1
+ # code-analysis-client
2
+
3
+ Async Python client for the **code-analysis** server. It wraps `mcp-proxy-adapter`'s `JsonRpcClient`, so you get the adapter's built-in methods (queue, transfer, `help`, `health`, …) plus thin helpers to run any registered server command. On the thin AI Editor Server, file editing uses `universal_file_*` commands only; queue polling helpers remain for generic RPC but are not part of the file workflow surface.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ pip install code-analysis-client
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ```python
14
+ import asyncio
15
+ from code_analysis_client import CodeAnalysisAsyncClient
16
+
17
+
18
+ async def main() -> None:
19
+ client = CodeAnalysisAsyncClient(
20
+ protocol="https",
21
+ host="127.0.0.1",
22
+ port=15001,
23
+ cert="/path/client.crt",
24
+ key="/path/client.key",
25
+ ca="/path/ca.crt",
26
+ timeout=120.0,
27
+ )
28
+ async with client:
29
+ h = await client.rpc.help()
30
+ r = await client.call("list_projects", {"include_deleted": False})
31
+ print(h, r)
32
+
33
+
34
+ asyncio.run(main())
35
+ ```
36
+
37
+ Build client settings from the same JSON shape as the pipeline adapter settings (`host`, `port`, `protocol`, optional `ssl` with `cert` / `key` / `ca` or `*_path` aliases), or from a full server `config.json` object.
38
+
39
+ ```python
40
+ from code_analysis_client import CodeAnalysisAsyncClient
41
+
42
+ client = CodeAnalysisAsyncClient.from_server_config(config_dict, timeout=60.0)
43
+ ```
44
+
45
+ Queued/long commands: use `client.call_unified(..., expect_queue=True, auto_poll=True)` or the underlying `client.rpc.execute_command_unified(...)`.
46
+
47
+ ## Validation using the server schema
48
+
49
+ The authoritative input schema is whatever the running server returns from **`help`** with `cmdname` set to the command. The client calls that, optionally caches the result, performs the same shallow checks as the server's `BaseMCPCommand` (types, `required`, `enum`, `additionalProperties`), then runs the command.
50
+
51
+ ```python
52
+ async with CodeAnalysisAsyncClient(host="127.0.0.1", port=15001) as client:
53
+ # Explicit
54
+ out = await client.call_validated(
55
+ "list_projects",
56
+ {"include_deleted": False},
57
+ )
58
+ # Dynamic wrapper: same as call_validated("list_projects", {...})
59
+ out = await client.commands.list_projects(include_deleted=False)
60
+ # After server reload
61
+ client.clear_command_schema_cache()
62
+ ```
63
+
64
+ Use `call_unified_validated` when you need queue polling. Pass `refresh_schema=True` on a single call to bypass the in-memory schema cache.
65
+
66
+ ## File Workflow (C-009)
67
+
68
+ The thin AI Editor Server exposes file editing only through `UniversalFileClient` (`client.universal_files`). One file at a time follows **open → edit → write → close**. Optional read-only inspection during an open file uses `preview` (`universal_file_preview`). Every stage requires the same CA Session `session_id`, `project_id`, and (where applicable) `file_path`.
69
+
70
+ ### Workflow stages
71
+
72
+ 1. **Open** (`universal_file_open`) — agent supplies CA `session_id`; server locks file on upstream CA, creates local Editor Session Directory and File Subtree, stores Origin Snapshot, creates Edit Subdirectory. Use `create=True` with `initial_content` for new files. To edit a documentation-server document, call `client.universal_files.open_document(project_id, session_id, document_id)` (`source="doc"`, no `file_path`): the Code Analysis Server fetches it into the project, the answer names the `file_path` and echoes `source` / `document_id`; a write of such a file reports a pending transfer through `degraded` / `degraded_reason` / `uploaded=false`.
73
+ 2. **Edit** (`universal_file_edit`) — mutations apply only to the Edit Subdirectory; Origin Snapshot unchanged.
74
+ 3. **Write** (`universal_file_write`) — compares Origin Snapshot to edited content; `write_mode="preview"` returns local diff without upstream upload; commit mode uploads to CA on change and refreshes Origin Snapshot on success.
75
+ 4. **Close** (`universal_file_close`) — unlocks file on CA, removes local File Subtree; removes Editor Session Directory when last file in session closes.
76
+
77
+ ### Minimal async example
78
+
79
+ ```python
80
+ import asyncio
81
+ import uuid
82
+
83
+ from ai_editor_client import CodeAnalysisAsyncClient
84
+
85
+
86
+ async def main() -> None:
87
+ # Created upstream via CA session_create (outside this client package).
88
+ ca_session_id = str(uuid.uuid4())
89
+
90
+ async with CodeAnalysisAsyncClient.from_server_config_path("config.json") as client:
91
+ uf = client.universal_files
92
+ project_id = "..."
93
+ file_path = "src/example.py"
94
+
95
+ await uf.open(
96
+ session_id=ca_session_id,
97
+ project_id=project_id,
98
+ file_path=file_path,
99
+ )
100
+ await uf.preview(
101
+ session_id=ca_session_id,
102
+ project_id=project_id,
103
+ file_path=file_path,
104
+ )
105
+ await uf.edit(
106
+ session_id=ca_session_id,
107
+ project_id=project_id,
108
+ file_path=file_path,
109
+ operations=[{"action": "replace", "start_line": 1, "end_line": 1, "code": "# edited\n"}],
110
+ )
111
+ await uf.write(
112
+ session_id=ca_session_id,
113
+ project_id=project_id,
114
+ file_path=file_path,
115
+ write_mode="preview",
116
+ )
117
+ await uf.close(
118
+ session_id=ca_session_id,
119
+ project_id=project_id,
120
+ file_path=file_path,
121
+ )
122
+
123
+
124
+ asyncio.run(main())
125
+ ```
126
+
127
+ Full runnable script: `client/examples/ex_universal_files.py`.
128
+
129
+ ### CA Session ID contract (C-003)
130
+
131
+ - The **agent** creates the CA Session on Code Analysis Server (`session_create`) **before** calling any editor `universal_file_*` command. That RPC is **not** part of the thin editor MCP surface and is **not** wrapped by `UniversalFileClient`.
132
+ - The agent passes the **same** `session_id` string to every `universal_file_open`, `universal_file_edit`, `universal_file_write`, `universal_file_close`, and `universal_file_preview` call for the workflow.
133
+ - Do **not** treat the `open` response as the source of `session_id` for later calls. If the server echoes `session_id`, it must match the agent-supplied value; the agent already owns the identifier.
134
+ - The agent decides when to `write` (commit or preview) and `close`; the client library does not manage CA session lifecycle.
135
+
136
+ ## High-level facades (thin AI Editor Server / C-016)
137
+
138
+ The supported public MCP commands for file workflow are `UNIVERSAL_FILE_COMMANDS` plus `health` only (`CLIENT_FACADE_COMMANDS` in `ai_editor_client.server_api`). CST commands (`cst_*`, `list_cst_blocks`, `query_cst`) and legacy direct file I/O are in `REMOVED_COMMANDS` — not on the thin server, not documented as supported. `client.universal_files` is the **only** supported high-level facade for file editing.
139
+
140
+ | Facade | Property | Server commands | Status |
141
+ |--------|----------|-----------------|--------|
142
+ | Universal file workflow | `client.universal_files` | `universal_file_open`, `universal_file_edit`, `universal_file_write`, `universal_file_close`, `universal_file_preview` | **Supported** (C-009 / C-016) |
143
+ | Infrastructure | `client.call("health", {})` or adapter `health` | `health` | **Supported** |
144
+ | Generic RPC | `client.call` / `client.commands.<name>` | any command returned by live `help()` on connected server | Escape hatch; thin server exposes only rows above for files |
145
+ | Legacy sessions + transfer | `client.file_sessions` | `session_*`, `subordinate_session_*`, `project_file_transfer_*`, `project_file_advisory_lock_batch` | **Deprecated** — `DEPRECATED_CLIENT_FACADE_COMMANDS`; not registered on thin editor server |
146
+
147
+ Canonical command lists: `ai_editor_client.server_api` exports `UNIVERSAL_FILE_COMMANDS`, `INFRASTRUCTURE_COMMANDS`, `CLIENT_FACADE_COMMANDS`, `DEPRECATED_CLIENT_FACADE_COMMANDS`, and `REMOVED_COMMANDS`.
148
+
149
+ Sync checks (in-process registry):
150
+
151
+ ```bash
152
+ pytest tests/test_client_server_api_sync.py -v
153
+ ```
154
+
155
+ These tests assert `CLIENT_FACADE_COMMANDS` matches the live server registry (C-016) and `REMOVED_COMMANDS` are absent from the server (C-022).
156
+
157
+ Package version is in ``client/ai_editor_client/version.txt``, which is a
158
+ **symlink to the repository-root ``VERSION`` file** — the single source of truth
159
+ shared by the server (``ai-editor``), this client (``ai-editor-client``) and the
160
+ engine (``ai-editor-tree-engine``). There is nothing to sync: bump the root
161
+ ``VERSION`` and all three move together. ``scripts/sync_code_analysis_client_version.py``
162
+ now verifies that invariant instead of copying a number.
163
+
164
+ ## Examples (this repository)
165
+
166
+ Runnable scripts live under `client/examples/`. **Long-form "man page" style
167
+ documentation** is embedded in the **module docstrings** of those Python files
168
+ (see `client/examples/README.md` for how to read them).
169
+
170
+ | Script | Purpose | Pipeline check |
171
+ |--------|---------|-----------------|
172
+ | `ex_universal_files.py` | **Primary:** C-009 File Workflow demo — all `UniversalFileClient` methods with agent-supplied CA `session_id` (C-003) | `check-live-client-universal-files` |
173
+ | `ex_minimal_validated.py` | Smallest validated RPC example (`health` / generic call) | `check-live-client-minimal-validated` |
174
+ | `ex_config_only.py` | Parse `config.json` without TCP | (local-only, no network; not in the pipeline) |
175
+ | `ex_session_view_subordinates.py` | **Deprecated** — legacy CA session API; not thin editor MCP | `check-live-client-session-view-subordinates` (TB11-0: contracted-rejection GREEN — the deployed server registers none of the `file_sessions.*` commands this deprecated facade needs, and the check asserts exactly that: each one raises the typed JSON-RPC `-32601` "Method not found" error, the facade's `DeprecationWarning` fires, and nothing is ever created to leak) |
176
+ | `ex_file_sessions.py` | **Deprecated** — legacy sessions/transfer; not thin editor MCP | `check-live-client-file-sessions` (TB11-0: contracted-rejection GREEN, same pattern — sessions, locks and transfer commands all typed -32601) |
177
+
178
+ `client/examples/run_all_examples.py` — the second runner that used to run
179
+ every sibling script above as a subprocess (bug 5094ad29) — is gone; every
180
+ live-server example above is driven, unmodified and in-process, by its own
181
+ named `pipeline` check under `pipeline/checks/check_live_client_*.py`,
182
+ through the PUBLISHED `ai_editor_client` package against the real deployed
183
+ server. The constructors/`rpc`/`call`/validated-facade/`commands`-proxy/
184
+ low-level-schema/context-manager sections that used to live inline in
185
+ `run_all_examples.py` are covered by `check-live-client-facade-surface`.
186
+
187
+ For file editing on thin AI Editor Server, start with `ex_universal_files.py`; do not use `ex_file_sessions.py` or `ex_session_view_subordinates.py` as file workflow templates.
188
+
189
+ ```bash
190
+ aiedmgr --config config.json start
191
+ python client/examples/ex_universal_files.py
192
+ ```
193
+
194
+ ## Release notes
195
+
196
+ ### 1.0.235
197
+
198
+ - BREAKING: paged preview. `UniversalFileClient.preview` now pages with the shared `page` and
199
+ `page_max_bytes` parameters (same contract as search). The former `preview_page` parameter is
200
+ removed; `max_output_bytes` is only the drill-down budget and never a page cap. Results carry
201
+ `total_records` and `records_returned`. Callers that sent `preview_page` must send `page`.
202
+ - Server key `page_max_bytes_default` (deployed as 20000) sets the default page size.
203
+
204
+ ## Development
205
+
206
+ From the repository root:
207
+
208
+ ```bash
209
+ pip install -e ./client
210
+ pytest tests/test_code_analysis_client.py
211
+ ```
212
+
213
+ ### Releasing to PyPI (version = the root ``VERSION`` file)
214
+
215
+ The client wheel version is read from ``client/ai_editor_client/version.txt``,
216
+ a symlink to the repository-root ``VERSION`` file. The server, this client and
217
+ ``ai-editor-tree-engine`` therefore always publish the same number; the build
218
+ resolves the symlink and writes real content into the sdist and the wheel.
219
+ Verify before build:
220
+
221
+ ```bash
222
+ python scripts/sync_code_analysis_client_version.py
223
+ cd client && python -m build && twine check dist/* && twine upload dist/*
224
+ ```
@@ -0,0 +1,183 @@
1
+ """
2
+ Public async client for ai-editor-server (JSON-RPC via mcp-proxy-adapter).
3
+
4
+ ``UniversalFileClient`` (via :attr:`~ai_editor_client.client.CodeAnalysisAsyncClient.universal_files`)
5
+ is the single supported file-workflow facade for the thin MCP Workflow Surface (C-016).
6
+ ``FileSessionClient``, ``EditorFileClient``, ``EditorFileHandle``, and ``LocalEditWorkspace``
7
+ are deprecated parallel facades (C-020) and emit :class:`DeprecationWarning` on instantiation.
8
+
9
+ Author: Vasiliy Zdanovskiy
10
+ email: vasilyvz@gmail.com
11
+ """
12
+
13
+ from __future__ import annotations
14
+
15
+ import warnings
16
+ from pathlib import Path
17
+ from typing import Optional
18
+
19
+ from ai_editor_client.client import CodeAnalysisAsyncClient
20
+ from ai_editor_client.commands_proxy import ValidatedCommandsProxy
21
+ from ai_editor_client.config import (
22
+ adapter_settings_from_server_config,
23
+ adapter_settings_to_jsonrpc_kwargs,
24
+ load_server_config,
25
+ )
26
+ from ai_editor_client.editor_file import (
27
+ EditorFileClient as _EditorFileClient,
28
+ EditorFileHandle as _EditorFileHandle,
29
+ )
30
+ from ai_editor_client.exceptions import ClientValidationError, ServerVersionMismatch
31
+ from ai_editor_client.file_session import (
32
+ FileSessionClient as _FileSessionClient,
33
+ SessionNotFoundError,
34
+ )
35
+ from ai_editor_client.local_edit_workspace import (
36
+ EditorFileWorkflowError,
37
+ LocalEditWorkspace as _LocalEditWorkspace,
38
+ )
39
+ from ai_editor_client.server_api import (
40
+ CLIENT_FACADE_COMMANDS,
41
+ CST_REMOVED_COMMANDS,
42
+ FILE_SESSION_COMMANDS,
43
+ FILE_SESSION_FACADE_METHODS,
44
+ LEGACY_REMOVED_COMMANDS,
45
+ REMOVED_COMMANDS,
46
+ TRANSFER_FACADE_METHODS,
47
+ UNIVERSAL_FILE_COMMANDS,
48
+ )
49
+ from ai_editor_client.universal_file import UniversalFileClient
50
+ from ai_editor_client.server_version import (
51
+ DECLARED_VERSION,
52
+ REQUIRED_SERVER_VERSION,
53
+ VERSION_EXEMPT_COMMANDS,
54
+ )
55
+ from ai_editor_client.server_schema import (
56
+ fetch_command_schema_from_server,
57
+ parse_schema_from_help_payload,
58
+ )
59
+ from ai_editor_client.validation import (
60
+ prepare_params_for_schema,
61
+ validate_params_against_schema,
62
+ )
63
+
64
+ _DEPRECATED_EXPORTS: frozenset[str] = frozenset(
65
+ {
66
+ "FileSessionClient",
67
+ "EditorFileClient",
68
+ "EditorFileHandle",
69
+ "LocalEditWorkspace",
70
+ }
71
+ )
72
+
73
+
74
+ def _emit_deprecated_export_warning(class_name: str) -> None:
75
+ warnings.warn(
76
+ (
77
+ f"{class_name} export is deprecated; use UniversalFileClient via "
78
+ "CodeAnalysisAsyncClient.universal_files (C-016). Removal under C-020."
79
+ ),
80
+ DeprecationWarning,
81
+ stacklevel=3,
82
+ )
83
+
84
+
85
+ class _DeprecatedFileSessionClient(_FileSessionClient):
86
+ def __init__(self, client: CodeAnalysisAsyncClient) -> None:
87
+ _emit_deprecated_export_warning("FileSessionClient")
88
+ super().__init__(client)
89
+
90
+
91
+ class _DeprecatedEditorFileClient(_EditorFileClient):
92
+ def __init__(self, file_sessions: FileSessionClient) -> None:
93
+ _emit_deprecated_export_warning("EditorFileClient")
94
+ super().__init__(file_sessions)
95
+
96
+
97
+ class _DeprecatedEditorFileHandle(_EditorFileHandle):
98
+ def __init__(
99
+ self,
100
+ ca_session_id: str,
101
+ project_id: str,
102
+ file_id: str,
103
+ file_path: str,
104
+ baseline_path: Path,
105
+ workspace: Optional[_LocalEditWorkspace] = None,
106
+ is_closed: bool = False,
107
+ ) -> None:
108
+ _emit_deprecated_export_warning("EditorFileHandle")
109
+ super().__init__(
110
+ ca_session_id=ca_session_id,
111
+ project_id=project_id,
112
+ file_id=file_id,
113
+ file_path=file_path,
114
+ baseline_path=baseline_path,
115
+ workspace=workspace,
116
+ is_closed=is_closed,
117
+ )
118
+
119
+
120
+ class _DeprecatedLocalEditWorkspace(_LocalEditWorkspace):
121
+ def __init__(
122
+ self,
123
+ workspace_id: str,
124
+ baseline_path: Path,
125
+ session_dir: Path,
126
+ working_path: Path,
127
+ is_open: bool = True,
128
+ ) -> None:
129
+ _emit_deprecated_export_warning("LocalEditWorkspace")
130
+ super().__init__(
131
+ workspace_id=workspace_id,
132
+ baseline_path=baseline_path,
133
+ session_dir=session_dir,
134
+ working_path=working_path,
135
+ is_open=is_open,
136
+ )
137
+
138
+
139
+ FileSessionClient = _DeprecatedFileSessionClient
140
+ EditorFileClient = _DeprecatedEditorFileClient
141
+ EditorFileHandle = _DeprecatedEditorFileHandle
142
+ LocalEditWorkspace = _DeprecatedLocalEditWorkspace
143
+
144
+ __all__ = [
145
+ "CLIENT_FACADE_COMMANDS",
146
+ "CST_REMOVED_COMMANDS",
147
+ "DECLARED_VERSION",
148
+ "REQUIRED_SERVER_VERSION",
149
+ "VERSION_EXEMPT_COMMANDS",
150
+ "ClientValidationError",
151
+ "CodeAnalysisAsyncClient",
152
+ "EditorFileClient",
153
+ "EditorFileHandle",
154
+ "EditorFileWorkflowError",
155
+ "FILE_SESSION_COMMANDS",
156
+ "FILE_SESSION_FACADE_METHODS",
157
+ "FileSessionClient",
158
+ "LEGACY_REMOVED_COMMANDS",
159
+ "LocalEditWorkspace",
160
+ "REMOVED_COMMANDS",
161
+ "ServerVersionMismatch",
162
+ "SessionNotFoundError",
163
+ "TRANSFER_FACADE_METHODS",
164
+ "UNIVERSAL_FILE_COMMANDS",
165
+ "UniversalFileClient",
166
+ "ValidatedCommandsProxy",
167
+ "adapter_settings_from_server_config",
168
+ "adapter_settings_to_jsonrpc_kwargs",
169
+ "fetch_command_schema_from_server",
170
+ "load_server_config",
171
+ "parse_schema_from_help_payload",
172
+ "prepare_params_for_schema",
173
+ "validate_params_against_schema",
174
+ ]
175
+
176
+
177
+ # One declaration, one number. `ai_editor_client.server_version` reads
178
+ # `version.txt` (a symlink to the repository-root VERSION file, resolved to real
179
+ # content in the built wheel) and is the module the per-call server-version
180
+ # guard enforces against. `__version__` is that same value, never a second
181
+ # derivation of it -- the previous local reader here had a "0.0.0" fallback,
182
+ # which is exactly the kind of guessed number a guard must never be handed.
183
+ __version__ = DECLARED_VERSION