ai-editor-client-dev 1.0.244__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.
- ai_editor_client/__init__.py +183 -0
- ai_editor_client/client.py +772 -0
- ai_editor_client/commands_proxy.py +60 -0
- ai_editor_client/config.py +126 -0
- ai_editor_client/editor_file.py +205 -0
- ai_editor_client/exceptions.py +48 -0
- ai_editor_client/file_session.py +692 -0
- ai_editor_client/local_edit_workspace.py +102 -0
- ai_editor_client/py.typed +0 -0
- ai_editor_client/responses.py +45 -0
- ai_editor_client/server_api.py +222 -0
- ai_editor_client/server_schema.py +57 -0
- ai_editor_client/server_version.py +171 -0
- ai_editor_client/universal_file.py +189 -0
- ai_editor_client/validation.py +98 -0
- ai_editor_client/version.txt +1 -0
- ai_editor_client_dev-1.0.244.dist-info/METADATA +236 -0
- ai_editor_client_dev-1.0.244.dist-info/RECORD +20 -0
- ai_editor_client_dev-1.0.244.dist-info/WHEEL +5 -0
- ai_editor_client_dev-1.0.244.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Universal file edit-session workflow on top of :class:`CodeAnalysisAsyncClient`.
|
|
3
|
+
|
|
4
|
+
Wraps ``universal_file_open`` / ``edit`` / ``write`` / ``close`` / ``preview`` only.
|
|
5
|
+
Legacy ``universal_file_read`` / ``universal_file_save`` and CST commands are not
|
|
6
|
+
part of this API (see :mod:`server_api`).
|
|
7
|
+
|
|
8
|
+
Author: Vasiliy Zdanovskiy
|
|
9
|
+
email: vasilyvz@gmail.com
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
from __future__ import annotations
|
|
13
|
+
|
|
14
|
+
from typing import TYPE_CHECKING, Any, Dict, List, Optional
|
|
15
|
+
|
|
16
|
+
from ai_editor_client.responses import unwrap_command_result
|
|
17
|
+
|
|
18
|
+
if TYPE_CHECKING:
|
|
19
|
+
from ai_editor_client.client import CodeAnalysisAsyncClient
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
class UniversalFileClient:
|
|
23
|
+
"""Edit-session workflow for project files (open → edit → write → close).
|
|
24
|
+
|
|
25
|
+
``session_id`` is the CA Session identifier (C-004): the agent creates it on
|
|
26
|
+
upstream and passes the same value into every workflow call (C-003). It is
|
|
27
|
+
not generated by ``open`` and is not the legacy client ``session_*`` API
|
|
28
|
+
(``session_create``, ``session_open_file``, …).
|
|
29
|
+
"""
|
|
30
|
+
|
|
31
|
+
__slots__ = ("_client",)
|
|
32
|
+
|
|
33
|
+
def __init__(self, client: CodeAnalysisAsyncClient) -> None:
|
|
34
|
+
self._client = client
|
|
35
|
+
|
|
36
|
+
async def open(
|
|
37
|
+
self,
|
|
38
|
+
project_id: str,
|
|
39
|
+
file_path: Optional[str],
|
|
40
|
+
session_id: str,
|
|
41
|
+
*,
|
|
42
|
+
create: bool = False,
|
|
43
|
+
initial_content: Optional[str] = None,
|
|
44
|
+
source: Optional[str] = None,
|
|
45
|
+
document_id: Optional[str] = None,
|
|
46
|
+
) -> Dict[str, Any]:
|
|
47
|
+
"""Start File Workflow open stage (C-009) via universal_file_open (C-016).
|
|
48
|
+
|
|
49
|
+
Identifies the file by ``project_id`` + ``file_path`` (not ``file_id``).
|
|
50
|
+
With ``source="doc"`` pass ``file_path=None`` and the documentation
|
|
51
|
+
server's ``document_id``: the Code Analysis Server fetches the document
|
|
52
|
+
into the project and the answer names the resulting ``file_path`` and
|
|
53
|
+
echoes ``source`` / ``document_id``.
|
|
54
|
+
"""
|
|
55
|
+
params: Dict[str, Any] = {
|
|
56
|
+
"project_id": project_id,
|
|
57
|
+
"session_id": session_id,
|
|
58
|
+
}
|
|
59
|
+
if file_path is not None:
|
|
60
|
+
params["file_path"] = file_path
|
|
61
|
+
if source is not None:
|
|
62
|
+
params["source"] = source
|
|
63
|
+
if document_id is not None:
|
|
64
|
+
params["document_id"] = document_id
|
|
65
|
+
if source != "doc":
|
|
66
|
+
params["create"] = create
|
|
67
|
+
elif create:
|
|
68
|
+
params["create"] = create
|
|
69
|
+
if initial_content is not None:
|
|
70
|
+
params["initial_content"] = initial_content
|
|
71
|
+
unwrapped: Dict[str, Any] = unwrap_command_result(
|
|
72
|
+
await self._client.call_validated("universal_file_open", params)
|
|
73
|
+
)
|
|
74
|
+
return unwrapped
|
|
75
|
+
|
|
76
|
+
async def open_document(
|
|
77
|
+
self, project_id: str, session_id: str, document_id: str
|
|
78
|
+
) -> Dict[str, Any]:
|
|
79
|
+
"""Open a documentation-server document (``source="doc"``) by its UUID."""
|
|
80
|
+
return await self.open(
|
|
81
|
+
project_id, None, session_id, source="doc", document_id=document_id
|
|
82
|
+
)
|
|
83
|
+
|
|
84
|
+
async def edit(
|
|
85
|
+
self,
|
|
86
|
+
project_id: str,
|
|
87
|
+
session_id: str,
|
|
88
|
+
operations: List[Dict[str, Any]],
|
|
89
|
+
*,
|
|
90
|
+
file_path: Optional[str] = None,
|
|
91
|
+
) -> Dict[str, Any]:
|
|
92
|
+
"""Apply edit stage mutations (C-009) via universal_file_edit (C-016)."""
|
|
93
|
+
params: Dict[str, Any] = {
|
|
94
|
+
"project_id": project_id,
|
|
95
|
+
"session_id": session_id,
|
|
96
|
+
"operations": operations,
|
|
97
|
+
}
|
|
98
|
+
if file_path is not None:
|
|
99
|
+
params["file_path"] = file_path
|
|
100
|
+
unwrapped: Dict[str, Any] = unwrap_command_result(
|
|
101
|
+
await self._client.call_validated("universal_file_edit", params)
|
|
102
|
+
)
|
|
103
|
+
return unwrapped
|
|
104
|
+
|
|
105
|
+
async def write(
|
|
106
|
+
self,
|
|
107
|
+
project_id: str,
|
|
108
|
+
session_id: str,
|
|
109
|
+
*,
|
|
110
|
+
file_path: Optional[str] = None,
|
|
111
|
+
write_mode: str = "commit",
|
|
112
|
+
skip_checks: bool = False,
|
|
113
|
+
) -> Dict[str, Any]:
|
|
114
|
+
"""Run write stage (C-009) via universal_file_write (C-016).
|
|
115
|
+
|
|
116
|
+
``skip_checks=True`` (decision D-Y) takes the old direct write: no
|
|
117
|
+
pre-write validation and no source check chain; sent only when true.
|
|
118
|
+
|
|
119
|
+
Default ``write_mode`` is ``commit`` in this client wrapper. The server
|
|
120
|
+
default when the parameter is omitted is ``preview``. Pass
|
|
121
|
+
``write_mode='preview'`` first to inspect the diff, then ``commit``.
|
|
122
|
+
"""
|
|
123
|
+
params: Dict[str, Any] = {
|
|
124
|
+
"project_id": project_id,
|
|
125
|
+
"session_id": session_id,
|
|
126
|
+
"write_mode": write_mode,
|
|
127
|
+
}
|
|
128
|
+
if file_path is not None:
|
|
129
|
+
params["file_path"] = file_path
|
|
130
|
+
if skip_checks:
|
|
131
|
+
params["skip_checks"] = True
|
|
132
|
+
unwrapped: Dict[str, Any] = unwrap_command_result(
|
|
133
|
+
await self._client.call_validated("universal_file_write", params)
|
|
134
|
+
)
|
|
135
|
+
return unwrapped
|
|
136
|
+
|
|
137
|
+
async def close(
|
|
138
|
+
self,
|
|
139
|
+
project_id: str,
|
|
140
|
+
session_id: str,
|
|
141
|
+
*,
|
|
142
|
+
file_path: Optional[str] = None,
|
|
143
|
+
) -> Dict[str, Any]:
|
|
144
|
+
"""Run close stage (C-009) via universal_file_close (C-016)."""
|
|
145
|
+
params: Dict[str, Any] = {
|
|
146
|
+
"project_id": project_id,
|
|
147
|
+
"session_id": session_id,
|
|
148
|
+
}
|
|
149
|
+
if file_path is not None:
|
|
150
|
+
params["file_path"] = file_path
|
|
151
|
+
unwrapped: Dict[str, Any] = unwrap_command_result(
|
|
152
|
+
await self._client.call_validated("universal_file_close", params)
|
|
153
|
+
)
|
|
154
|
+
return unwrapped
|
|
155
|
+
|
|
156
|
+
async def preview(
|
|
157
|
+
self,
|
|
158
|
+
project_id: str,
|
|
159
|
+
file_path: str,
|
|
160
|
+
session_id: str,
|
|
161
|
+
**kwargs: Any,
|
|
162
|
+
) -> Dict[str, Any]:
|
|
163
|
+
"""Read-only preview via universal_file_preview (C-016).
|
|
164
|
+
|
|
165
|
+
Extra keyword arguments are sent as command parameters. A node with many
|
|
166
|
+
records is paged: pass ``page`` (1-based, default 1) and follow
|
|
167
|
+
``next_page`` (null on the last page); ``preview_lines`` and
|
|
168
|
+
``page_max_bytes`` size a page (``max_output_bytes`` is only the
|
|
169
|
+
drill-down budget). ``page`` beyond the last page
|
|
170
|
+
is ``PAGE_OUT_OF_RANGE``; ``page`` > 1 with ``selector``
|
|
171
|
+
is ``CONFLICTING_PARAMETERS``.
|
|
172
|
+
|
|
173
|
+
``preview_offset`` is the zero-based LINE index of the line window used
|
|
174
|
+
only when the file cannot be parsed (invalid-source preview). On a file
|
|
175
|
+
that parses, a value greater than 0 is refused with
|
|
176
|
+
``REQUIRES_IDENTIFIER_ADDRESSING``; use ``page`` (1-based page
|
|
177
|
+
number) to move through the pages of a parsed file. 0 or omitted is
|
|
178
|
+
accepted and has no effect on a parsed file.
|
|
179
|
+
"""
|
|
180
|
+
params: Dict[str, Any] = {
|
|
181
|
+
"project_id": project_id,
|
|
182
|
+
"file_path": file_path,
|
|
183
|
+
"session_id": session_id,
|
|
184
|
+
}
|
|
185
|
+
params.update(kwargs)
|
|
186
|
+
unwrapped: Dict[str, Any] = unwrap_command_result(
|
|
187
|
+
await self._client.call_validated("universal_file_preview", params)
|
|
188
|
+
)
|
|
189
|
+
return unwrapped
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Shallow JSON-schema validation aligned with BaseMCPCommand.validate_params_against_schema.
|
|
3
|
+
|
|
4
|
+
Author: Vasiliy Zdanovskiy
|
|
5
|
+
email: vasilyvz@gmail.com
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
from typing import Any, Dict
|
|
11
|
+
|
|
12
|
+
from ai_editor_client.exceptions import ClientValidationError
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def prepare_params_for_schema(
|
|
16
|
+
params: Dict[str, Any], schema: Dict[str, Any] # noqa: ARG001
|
|
17
|
+
) -> Dict[str, Any]:
|
|
18
|
+
"""Return a shallow copy of params for validation and dispatch."""
|
|
19
|
+
return dict(params)
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def validate_params_against_schema(
|
|
23
|
+
params: Dict[str, Any],
|
|
24
|
+
schema: Dict[str, Any],
|
|
25
|
+
command_name: str = "command",
|
|
26
|
+
) -> None:
|
|
27
|
+
"""Validate params against a command ``get_schema()``-style object (subset)."""
|
|
28
|
+
if not isinstance(params, dict):
|
|
29
|
+
raise ClientValidationError(
|
|
30
|
+
f"{command_name}: params must be a dict, got {type(params).__name__}",
|
|
31
|
+
field="params",
|
|
32
|
+
)
|
|
33
|
+
props = schema.get("properties") or {}
|
|
34
|
+
additional_ok = schema.get("additionalProperties", False)
|
|
35
|
+
required_set = set(schema.get("required") or [])
|
|
36
|
+
for key, value in params.items():
|
|
37
|
+
if key not in props:
|
|
38
|
+
if not additional_ok:
|
|
39
|
+
raise ClientValidationError(
|
|
40
|
+
f"{command_name}: unknown parameter {key!r}. "
|
|
41
|
+
"Only schema-defined properties are allowed.",
|
|
42
|
+
field=key,
|
|
43
|
+
details={"allowed": list(props.keys())},
|
|
44
|
+
)
|
|
45
|
+
continue
|
|
46
|
+
if value is None:
|
|
47
|
+
continue
|
|
48
|
+
prop = props[key]
|
|
49
|
+
expected_type = prop.get("type")
|
|
50
|
+
if expected_type == "string":
|
|
51
|
+
if not isinstance(value, str):
|
|
52
|
+
raise ClientValidationError(
|
|
53
|
+
f"{command_name}: parameter {key!r} must be string, got {type(value).__name__}",
|
|
54
|
+
field=key,
|
|
55
|
+
)
|
|
56
|
+
elif expected_type == "integer":
|
|
57
|
+
if not isinstance(value, int) or isinstance(value, bool):
|
|
58
|
+
raise ClientValidationError(
|
|
59
|
+
f"{command_name}: parameter {key!r} must be integer, got {type(value).__name__}",
|
|
60
|
+
field=key,
|
|
61
|
+
)
|
|
62
|
+
elif expected_type == "number":
|
|
63
|
+
if not isinstance(value, (int, float)) or isinstance(value, bool):
|
|
64
|
+
raise ClientValidationError(
|
|
65
|
+
f"{command_name}: parameter {key!r} must be number, got {type(value).__name__}",
|
|
66
|
+
field=key,
|
|
67
|
+
)
|
|
68
|
+
elif expected_type == "boolean":
|
|
69
|
+
if not isinstance(value, bool):
|
|
70
|
+
raise ClientValidationError(
|
|
71
|
+
f"{command_name}: parameter {key!r} must be boolean, got {type(value).__name__}",
|
|
72
|
+
field=key,
|
|
73
|
+
)
|
|
74
|
+
elif expected_type == "array":
|
|
75
|
+
if not isinstance(value, list):
|
|
76
|
+
raise ClientValidationError(
|
|
77
|
+
f"{command_name}: parameter {key!r} must be array, got {type(value).__name__}",
|
|
78
|
+
field=key,
|
|
79
|
+
)
|
|
80
|
+
elif expected_type == "object":
|
|
81
|
+
if not isinstance(value, dict):
|
|
82
|
+
raise ClientValidationError(
|
|
83
|
+
f"{command_name}: parameter {key!r} must be object, got {type(value).__name__}",
|
|
84
|
+
field=key,
|
|
85
|
+
)
|
|
86
|
+
if "enum" in prop and value is not None:
|
|
87
|
+
if value not in prop["enum"]:
|
|
88
|
+
raise ClientValidationError(
|
|
89
|
+
f"{command_name}: parameter {key!r} must be one of {prop['enum']!r}, got {value!r}",
|
|
90
|
+
field=key,
|
|
91
|
+
details={"enum": prop["enum"]},
|
|
92
|
+
)
|
|
93
|
+
for key in required_set:
|
|
94
|
+
if key not in params or params[key] is None:
|
|
95
|
+
raise ClientValidationError(
|
|
96
|
+
f"{command_name}: required parameter {key!r} is missing",
|
|
97
|
+
field=key,
|
|
98
|
+
)
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
1.0.244
|
|
@@ -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,20 @@
|
|
|
1
|
+
ai_editor_client/__init__.py,sha256=0a_GqOZWplBrCT8r2k4zKmlm3VBhIuPVeouQSfks6T4,5774
|
|
2
|
+
ai_editor_client/client.py,sha256=ORyS7ne4FE2K0-6n1v22Y5ZkiRUhRC6kGOL63IPsHtg,31818
|
|
3
|
+
ai_editor_client/commands_proxy.py,sha256=2BvDPybc6xgEQ1nRZY7tCIGK3wi6v1JHFArgeLTfZxo,1965
|
|
4
|
+
ai_editor_client/config.py,sha256=f3FD_t71-4iHiLo-_YR7sPsicVtYW7rsr8k57eTsqhU,4510
|
|
5
|
+
ai_editor_client/editor_file.py,sha256=KMxTrW_YyXnKT9I_L8N_gTaRkgJVUg2VIqlyEeFy6_A,7121
|
|
6
|
+
ai_editor_client/exceptions.py,sha256=OHuFhrNf2D_eaOwZAiQBxfy2s6Lp8shKU6iDDp7ETzw,1566
|
|
7
|
+
ai_editor_client/file_session.py,sha256=9td9D2L30BmfV1qA0tfvul9cb7geIdi5rl6jGPC4fT4,24089
|
|
8
|
+
ai_editor_client/local_edit_workspace.py,sha256=aR6cXnFyBJHET7tmdXfdSgyvIZr1TLNFrr6uGfzYEcg,3365
|
|
9
|
+
ai_editor_client/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
10
|
+
ai_editor_client/responses.py,sha256=qobDLDwupxDGN0RGiUebyA5nVuAv_1plI5SIiyAf5VI,1547
|
|
11
|
+
ai_editor_client/server_api.py,sha256=sp8hz3rU3P3uL_VPl-n07v1yrkbgm0XYjdsOjuvYS6Q,7903
|
|
12
|
+
ai_editor_client/server_schema.py,sha256=wJMnEgqs5-DWRLYKDSt2AepbQlG6FzEolgT3etXXwF0,1858
|
|
13
|
+
ai_editor_client/server_version.py,sha256=9a5g8y2eFTsfi5RLlMYs6DfsVx7b8276-A2WBt1z14M,7004
|
|
14
|
+
ai_editor_client/universal_file.py,sha256=_39MmU8S9Utrh4MK0zpoXSgwUwJ1AYP_RwRpyJRETGw,6916
|
|
15
|
+
ai_editor_client/validation.py,sha256=MnUpqMYIipKP3NTzrfaFWb6hZxvj6wttR56btNGUC8g,3914
|
|
16
|
+
ai_editor_client/version.txt,sha256=-98D9v_ltB6yvN_E6YQUu-Gp9eWFFoH9v8cznV5BT1M,8
|
|
17
|
+
ai_editor_client_dev-1.0.244.dist-info/METADATA,sha256=R6_5L9KerkioJ44GAOST-Yx32WdYfXwAqB2oc-aPd1Q,12361
|
|
18
|
+
ai_editor_client_dev-1.0.244.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
|
|
19
|
+
ai_editor_client_dev-1.0.244.dist-info/top_level.txt,sha256=u6YkfRWrkZ81IKqyzBiU5CnicJ3RH6mhexekvr9aSck,17
|
|
20
|
+
ai_editor_client_dev-1.0.244.dist-info/RECORD,,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
ai_editor_client
|