ai-editor-tree-engine-dev 1.0.176__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_tree_engine_dev-1.0.176.dist-info/METADATA +35 -0
- ai_editor_tree_engine_dev-1.0.176.dist-info/RECORD +121 -0
- ai_editor_tree_engine_dev-1.0.176.dist-info/WHEEL +5 -0
- ai_editor_tree_engine_dev-1.0.176.dist-info/licenses/LICENSE +21 -0
- ai_editor_tree_engine_dev-1.0.176.dist-info/top_level.txt +1 -0
- tree_engine/PUBLIC_API.md +161 -0
- tree_engine/__init__.py +327 -0
- tree_engine/checks/__init__.py +60 -0
- tree_engine/checks/builtin/__init__.py +5 -0
- tree_engine/checks/builtin/compile_check.py +53 -0
- tree_engine/checks/builtin/csv_syntax.py +51 -0
- tree_engine/checks/builtin/docstrings.py +211 -0
- tree_engine/checks/builtin/encoding.py +55 -0
- tree_engine/checks/builtin/fleet_rules.py +227 -0
- tree_engine/checks/builtin/format_syntax.py +82 -0
- tree_engine/checks/builtin/jsonl_syntax.py +49 -0
- tree_engine/checks/builtin/shipped.py +52 -0
- tree_engine/checks/builtin/syntax.py +118 -0
- tree_engine/checks/builtin/xml_wellformed.py +51 -0
- tree_engine/checks/chain.py +332 -0
- tree_engine/checks/external/__init__.py +5 -0
- tree_engine/checks/external/_base.py +61 -0
- tree_engine/checks/external/bandit.py +53 -0
- tree_engine/checks/external/black.py +48 -0
- tree_engine/checks/external/flake8.py +38 -0
- tree_engine/checks/external/isort.py +38 -0
- tree_engine/checks/external/mypy.py +45 -0
- tree_engine/checks/external/ruff.py +45 -0
- tree_engine/checks/external/runner.py +197 -0
- tree_engine/checks/model.py +110 -0
- tree_engine/checks/options.py +73 -0
- tree_engine/checks/plugin.py +171 -0
- tree_engine/checks/registry.py +349 -0
- tree_engine/core/address.py +376 -0
- tree_engine/core/identifier_map.py +266 -0
- tree_engine/core/identity.py +226 -0
- tree_engine/core/instrumentation.py +399 -0
- tree_engine/core/integrity.py +341 -0
- tree_engine/core/integrity_full.py +382 -0
- tree_engine/core/journal.py +260 -0
- tree_engine/core/journal_compose.py +571 -0
- tree_engine/core/live_tree.py +785 -0
- tree_engine/core/locking.py +188 -0
- tree_engine/core/move.py +585 -0
- tree_engine/core/move_references.py +323 -0
- tree_engine/core/node_types.py +408 -0
- tree_engine/core/nodes.py +348 -0
- tree_engine/core/offsets.py +24 -0
- tree_engine/core/operations.py +825 -0
- tree_engine/core/plugin_boundary.py +160 -0
- tree_engine/core/position_map.py +263 -0
- tree_engine/core/position_transfer.py +512 -0
- tree_engine/core/range_refresh.py +366 -0
- tree_engine/core/reference_cache.py +360 -0
- tree_engine/core/references.py +223 -0
- tree_engine/core/reparse.py +378 -0
- tree_engine/core/short_id.py +296 -0
- tree_engine/core/subtree_apply.py +397 -0
- tree_engine/core/subtree_copy.py +399 -0
- tree_engine/core/transactions.py +397 -0
- tree_engine/core/trivia.py +396 -0
- tree_engine/core/updates.py +398 -0
- tree_engine/core/validation.py +377 -0
- tree_engine/errors.py +104 -0
- tree_engine/exceptions.py +376 -0
- tree_engine/facade.py +4524 -0
- tree_engine/plugins/_statements.py +369 -0
- tree_engine/plugins/bsl/block_edit.py +449 -0
- tree_engine/plugins/bsl/blocks.py +127 -0
- tree_engine/plugins/bsl/checker.py +297 -0
- tree_engine/plugins/bsl/dialects.py +303 -0
- tree_engine/plugins/bsl/generator.py +481 -0
- tree_engine/plugins/bsl/import_map.py +995 -0
- tree_engine/plugins/bsl/plugin.py +452 -0
- tree_engine/plugins/contract.py +355 -0
- tree_engine/plugins/cpp/import_map.py +505 -0
- tree_engine/plugins/cpp/languages.py +99 -0
- tree_engine/plugins/cpp/plugin.py +501 -0
- tree_engine/plugins/csv_format.py +676 -0
- tree_engine/plugins/detachable.py +156 -0
- tree_engine/plugins/fallback.py +421 -0
- tree_engine/plugins/ini_format.py +330 -0
- tree_engine/plugins/json_format.py +813 -0
- tree_engine/plugins/json_pointer.py +203 -0
- tree_engine/plugins/jsonl_format.py +392 -0
- tree_engine/plugins/markdown_format.py +748 -0
- tree_engine/plugins/onec_query_format.py +61 -0
- tree_engine/plugins/parse_position.py +54 -0
- tree_engine/plugins/plain_text.py +1543 -0
- tree_engine/plugins/python/export_map.py +306 -0
- tree_engine/plugins/python/import_map.py +429 -0
- tree_engine/plugins/python/plugin.py +1710 -0
- tree_engine/plugins/registry.py +497 -0
- tree_engine/plugins/scan.py +87 -0
- tree_engine/plugins/selection.py +228 -0
- tree_engine/plugins/sql_format.py +61 -0
- tree_engine/plugins/toml_format.py +1072 -0
- tree_engine/plugins/xml_format.py +911 -0
- tree_engine/plugins/yaml/builder.py +49 -0
- tree_engine/plugins/yaml/emitter.py +225 -0
- tree_engine/plugins/yaml/flow.py +227 -0
- tree_engine/plugins/yaml/plugin.py +458 -0
- tree_engine/plugins/yaml/ranges.py +52 -0
- tree_engine/plugins/yaml/reader.py +359 -0
- tree_engine/plugins/yaml/scanner.py +298 -0
- tree_engine/query/adapter.py +283 -0
- tree_engine/query/engine.py +853 -0
- tree_engine/query/inspection.py +498 -0
- tree_engine/query/outline.py +288 -0
- tree_engine/query/predicates.py +263 -0
- tree_engine/query/rendered_lines.py +46 -0
- tree_engine/query/results.py +206 -0
- tree_engine/query/selector.py +400 -0
- tree_engine/query/xml_query.py +747 -0
- tree_engine/storage/codec.py +400 -0
- tree_engine/storage/document_bridge.py +579 -0
- tree_engine/storage/file_txn.py +459 -0
- tree_engine/storage/history.py +106 -0
- tree_engine/storage/lifecycle.py +622 -0
- tree_engine/storage/schema.py +403 -0
- tree_engine/storage/session_guard.py +398 -0
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
"""Deterministic format-selection resolver (concept C-011).
|
|
2
|
+
|
|
3
|
+
Scope: this module answers exactly one question -- "which single format
|
|
4
|
+
plugin applies to this open request?" -- and nothing else. It defines no
|
|
5
|
+
registry and no concrete plugins; the plugin registry (``register_format_plugin``,
|
|
6
|
+
``get_format_plugin``, ``list_format_plugins``) and every concrete plugin
|
|
7
|
+
(python, bsl, json, yaml, toml, plain_text, ...) are delivered by sibling
|
|
8
|
+
and later steps and must not be imported or stubbed here per {p062}. This
|
|
9
|
+
module instead accepts the available plugin set and the registry lookup as
|
|
10
|
+
injected parameters -- a plain mapping or iterable of plugin-like objects,
|
|
11
|
+
and any object exposing a single ``get_format_plugin(format_id)`` method.
|
|
12
|
+
|
|
13
|
+
Selection rules ({p061}, {p062}, {p063}, {p095}), applied literally:
|
|
14
|
+
|
|
15
|
+
* An explicit ``format_id`` has unconditional priority. Resolution happens
|
|
16
|
+
solely through ``registry.get_format_plugin`` on that branch; the file
|
|
17
|
+
path/extension is never read, parsed, or otherwise inspected, no matter
|
|
18
|
+
whether it is present, absent, unknown, or would itself conflict.
|
|
19
|
+
* Without ``format_id``, resolution goes only through the pre-built,
|
|
20
|
+
uniqueness-validated ``file_extensions`` table (see
|
|
21
|
+
:func:`build_extension_table`). A missing or unknown extension is an
|
|
22
|
+
unconditional error -- never a fallback and never a trigger for content
|
|
23
|
+
analysis.
|
|
24
|
+
* Content sniffing, ``detect`` calls, and plugin probing (trying candidate
|
|
25
|
+
plugins to see which one accepts the content) are forbidden everywhere in
|
|
26
|
+
this module. Plain-text fallback is a separate, later stage triggered
|
|
27
|
+
only after a resolved plugin's own ``parse_document`` reports a content
|
|
28
|
+
parse failure; selection itself never triggers or signals it.
|
|
29
|
+
"""
|
|
30
|
+
|
|
31
|
+
from __future__ import annotations
|
|
32
|
+
|
|
33
|
+
import os
|
|
34
|
+
from typing import Any, Dict, Iterable, Mapping, Optional, Protocol, Union, runtime_checkable
|
|
35
|
+
|
|
36
|
+
from tree_engine.errors import ErrorCode
|
|
37
|
+
|
|
38
|
+
__all__ = [
|
|
39
|
+
"FormatPluginLookup",
|
|
40
|
+
"FormatSelectionError",
|
|
41
|
+
"build_extension_table",
|
|
42
|
+
"resolve_format_plugin",
|
|
43
|
+
]
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
@runtime_checkable
|
|
47
|
+
class FormatPluginLookup(Protocol):
|
|
48
|
+
"""Minimal registry surface this resolver depends on.
|
|
49
|
+
|
|
50
|
+
Mirrors the future registry's ``get_format_plugin(format_id)`` entry
|
|
51
|
+
point without importing the (not yet delivered) registry module: any
|
|
52
|
+
object exposing this one method -- a real registry, a test double, or a
|
|
53
|
+
thin adapter -- can be injected as ``registry`` below.
|
|
54
|
+
"""
|
|
55
|
+
|
|
56
|
+
def get_format_plugin(self, format_id: str) -> Any:
|
|
57
|
+
...
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
class FormatSelectionError(Exception):
|
|
61
|
+
"""Raised for a deterministic format-selection failure.
|
|
62
|
+
|
|
63
|
+
Always carries one of the catalog codes defined in
|
|
64
|
+
:mod:`tree_engine.errors` -- :attr:`ErrorCode.FORMAT_UNKNOWN_EXTENSION`
|
|
65
|
+
or :attr:`ErrorCode.FORMAT_EXTENSION_CONFLICT` for the two failure
|
|
66
|
+
modes this module produces. No other exception type is raised by
|
|
67
|
+
:func:`resolve_format_plugin` or :func:`build_extension_table` for a
|
|
68
|
+
selection failure; a lookup failure from an injected ``registry`` is
|
|
69
|
+
the registry's own concern and propagates unchanged.
|
|
70
|
+
"""
|
|
71
|
+
|
|
72
|
+
def __init__(self, *, error_code: ErrorCode, message: str = "", **details: Any) -> None:
|
|
73
|
+
self.error_code: ErrorCode = error_code
|
|
74
|
+
self.details: Mapping[str, Any] = dict(details)
|
|
75
|
+
super().__init__(message or f"{error_code.value}: {self.details}")
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
# A plugin-like item accepted by `build_extension_table`: either a
|
|
79
|
+
# FormatPluginMetadata instance directly, or any object exposing a
|
|
80
|
+
# `.metadata` attribute/property that returns one (e.g. a
|
|
81
|
+
# FormatPluginContract implementation). Left untyped (`Any`) deliberately:
|
|
82
|
+
# this module must not import the contract module's concrete types to stay
|
|
83
|
+
# decoupled from exactly which shape the caller injects.
|
|
84
|
+
PluginLike = Any
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
def _metadata_of(plugin: PluginLike) -> Any:
|
|
88
|
+
"""Return the plugin's static metadata, without reading any content.
|
|
89
|
+
|
|
90
|
+
If ``plugin`` exposes a ``.metadata`` attribute or property, that value
|
|
91
|
+
is used (this covers a ``FormatPluginContract`` implementation, whose
|
|
92
|
+
``metadata`` property returns a ``FormatPluginMetadata``). Otherwise
|
|
93
|
+
``plugin`` is assumed to already be metadata-shaped (it must expose
|
|
94
|
+
``format_id`` and ``file_extensions``).
|
|
95
|
+
"""
|
|
96
|
+
|
|
97
|
+
return getattr(plugin, "metadata", plugin)
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
def _normalize_extension(extension: str) -> str:
|
|
101
|
+
"""Normalize an extension string for table storage and lookup.
|
|
102
|
+
|
|
103
|
+
Strips one leading dot (if present) and lower-cases the remainder.
|
|
104
|
+
Purely syntactic string handling -- no filesystem access, no content
|
|
105
|
+
inspection.
|
|
106
|
+
"""
|
|
107
|
+
|
|
108
|
+
normalized = extension.strip()
|
|
109
|
+
if normalized.startswith("."):
|
|
110
|
+
normalized = normalized[1:]
|
|
111
|
+
return normalized.lower()
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
def _extension_from_path(file_path: str) -> str:
|
|
115
|
+
"""Extract and normalize the extension from a file path string.
|
|
116
|
+
|
|
117
|
+
Uses ``os.path.splitext`` on the path string only: this never opens,
|
|
118
|
+
reads, or otherwise touches the file itself. Returns ``""`` when the
|
|
119
|
+
path has no extension.
|
|
120
|
+
"""
|
|
121
|
+
|
|
122
|
+
_, raw_extension = os.path.splitext(file_path)
|
|
123
|
+
return _normalize_extension(raw_extension) if raw_extension else ""
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
def build_extension_table(
|
|
127
|
+
plugins: Union[Mapping[str, PluginLike], Iterable[PluginLike]],
|
|
128
|
+
) -> Mapping[str, str]:
|
|
129
|
+
"""Build the extension -> format_id table from registered plugin metadata.
|
|
130
|
+
|
|
131
|
+
``plugins`` is the injected, available plugin set: either a mapping
|
|
132
|
+
(``format_id`` -> plugin-like object) or a plain iterable of
|
|
133
|
+
plugin-like objects. This function never imports a registry module or
|
|
134
|
+
a concrete plugin module; it only reads the static ``format_id`` and
|
|
135
|
+
``file_extensions`` fields off whatever metadata each item exposes (see
|
|
136
|
+
:func:`_metadata_of`). No file content, ``detect`` call, or plugin
|
|
137
|
+
probing is involved.
|
|
138
|
+
|
|
139
|
+
Uniqueness is validated here, at build time, per {p062}: two different
|
|
140
|
+
plugins (different ``format_id``) claiming the same normalized
|
|
141
|
+
extension is a configuration error, raised immediately as
|
|
142
|
+
:class:`FormatSelectionError` carrying
|
|
143
|
+
:attr:`ErrorCode.FORMAT_EXTENSION_CONFLICT`. The same plugin listing
|
|
144
|
+
the same extension more than once (e.g. via an alias entry) is not a
|
|
145
|
+
conflict.
|
|
146
|
+
|
|
147
|
+
The returned table covers whatever the injected plugin set declares;
|
|
148
|
+
when the caller injects the baseline first-version plugin set, the
|
|
149
|
+
result covers the baseline mapping (txt -> plain_text, py/pyi ->
|
|
150
|
+
python, bsl -> bsl, json -> json, yaml/yml -> yaml, toml -> toml).
|
|
151
|
+
"""
|
|
152
|
+
|
|
153
|
+
candidates: Iterable[PluginLike] = (
|
|
154
|
+
plugins.values() if isinstance(plugins, Mapping) else plugins
|
|
155
|
+
)
|
|
156
|
+
|
|
157
|
+
table: Dict[str, str] = {}
|
|
158
|
+
for plugin in candidates:
|
|
159
|
+
metadata = _metadata_of(plugin)
|
|
160
|
+
format_id = metadata.format_id
|
|
161
|
+
for raw_extension in metadata.file_extensions:
|
|
162
|
+
extension = _normalize_extension(raw_extension)
|
|
163
|
+
if not extension:
|
|
164
|
+
continue
|
|
165
|
+
existing_format_id = table.get(extension)
|
|
166
|
+
if existing_format_id is not None and existing_format_id != format_id:
|
|
167
|
+
raise FormatSelectionError(
|
|
168
|
+
error_code=ErrorCode.FORMAT_EXTENSION_CONFLICT,
|
|
169
|
+
message=(
|
|
170
|
+
f"extension '.{extension}' is claimed by both "
|
|
171
|
+
f"'{existing_format_id}' and '{format_id}'"
|
|
172
|
+
),
|
|
173
|
+
extension=extension,
|
|
174
|
+
format_ids=(existing_format_id, format_id),
|
|
175
|
+
)
|
|
176
|
+
table[extension] = format_id
|
|
177
|
+
|
|
178
|
+
return dict(table)
|
|
179
|
+
|
|
180
|
+
|
|
181
|
+
def resolve_format_plugin(
|
|
182
|
+
*,
|
|
183
|
+
format_id: Optional[str] = None,
|
|
184
|
+
file_path: Optional[str] = None,
|
|
185
|
+
registry: FormatPluginLookup,
|
|
186
|
+
extension_table: Mapping[str, str],
|
|
187
|
+
) -> Any:
|
|
188
|
+
"""Deterministically resolve exactly one format plugin.
|
|
189
|
+
|
|
190
|
+
Explicit-id priority ({p061}, {p095}): when ``format_id`` is given, it
|
|
191
|
+
has unconditional priority. Resolution happens solely through
|
|
192
|
+
``registry.get_format_plugin(format_id)`` -- ``file_path`` is not read,
|
|
193
|
+
not parsed for an extension, and not inspected in any way on this
|
|
194
|
+
branch, even when it is absent, has an unknown extension, or would
|
|
195
|
+
itself conflict.
|
|
196
|
+
|
|
197
|
+
Extension fallback table ({p062}, {p063}): without ``format_id``,
|
|
198
|
+
resolution goes only through ``extension_table``, the pre-built,
|
|
199
|
+
uniqueness-validated mapping produced by :func:`build_extension_table`.
|
|
200
|
+
A missing ``file_path``, a path with no extension, or an extension not
|
|
201
|
+
present in ``extension_table`` all raise :class:`FormatSelectionError`
|
|
202
|
+
carrying :attr:`ErrorCode.FORMAT_UNKNOWN_EXTENSION` -- there is no
|
|
203
|
+
fallback and no partial match.
|
|
204
|
+
|
|
205
|
+
Neither branch performs content sniffing, calls a ``detect`` method, or
|
|
206
|
+
probes candidate plugins by trial; this function never triggers or
|
|
207
|
+
signals a plain-text fallback -- that is a separate, later stage
|
|
208
|
+
reacting to a resolved plugin's own parse failure, not a concern of
|
|
209
|
+
selection.
|
|
210
|
+
"""
|
|
211
|
+
|
|
212
|
+
if format_id is not None:
|
|
213
|
+
return registry.get_format_plugin(format_id)
|
|
214
|
+
|
|
215
|
+
extension = _extension_from_path(file_path) if file_path else ""
|
|
216
|
+
if not extension or extension not in extension_table:
|
|
217
|
+
raise FormatSelectionError(
|
|
218
|
+
error_code=ErrorCode.FORMAT_UNKNOWN_EXTENSION,
|
|
219
|
+
message=(
|
|
220
|
+
"no unambiguous format plugin is registered for "
|
|
221
|
+
+ (f"path {file_path!r}" if file_path else "a missing file extension")
|
|
222
|
+
),
|
|
223
|
+
file_path=file_path,
|
|
224
|
+
extension=extension or None,
|
|
225
|
+
)
|
|
226
|
+
|
|
227
|
+
resolved_format_id = extension_table[extension]
|
|
228
|
+
return registry.get_format_plugin(resolved_format_id)
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"""Lossless SQL format plugin for the tree engine (``format_id='sql'``, extension ``.sql``).
|
|
2
|
+
|
|
3
|
+
Author: Vasiliy Zdanovskiy
|
|
4
|
+
email: vasilyvz@gmail.com
|
|
5
|
+
|
|
6
|
+
Model (decision D-CD): a ``sql:document`` root with one ``sql:statement`` child per statement. A ``;`` ends a
|
|
7
|
+
statement unless a ``--`` comment, a ``/* */`` comment, a ``'...'`` string, a ``"..."`` or backtick quoted
|
|
8
|
+
identifier (a doubled quote is an escaped quote) or a ``$tag$ ... $tag$`` dollar quote protects it. The model
|
|
9
|
+
and the byte-exact round trip are in :mod:`tree_engine.plugins._statements`. The syntax checker ``sql_syntax``
|
|
10
|
+
(code ``SYNTAX-SQL``) is declared through ``checker_plugin``.
|
|
11
|
+
"""
|
|
12
|
+
|
|
13
|
+
from __future__ import annotations
|
|
14
|
+
|
|
15
|
+
from typing import Any
|
|
16
|
+
|
|
17
|
+
from tree_engine.plugins._statements import Dialect, StatementFormatPlugin
|
|
18
|
+
from tree_engine.plugins.contract import FormatPluginMetadata
|
|
19
|
+
|
|
20
|
+
__all__ = ["FORMAT_ID", "SQL_DIALECT", "SqlFormatPlugin", "SQL_FORMAT_PLUGIN"]
|
|
21
|
+
|
|
22
|
+
FORMAT_ID = "sql"
|
|
23
|
+
SQL_DIALECT = Dialect(
|
|
24
|
+
line_comment="--",
|
|
25
|
+
block_comment=True,
|
|
26
|
+
quotes=(("'", "string literal"), ('"', "quoted identifier"), ("`", "quoted identifier")),
|
|
27
|
+
dollar_quote=True,
|
|
28
|
+
)
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
class SqlFormatPlugin(StatementFormatPlugin):
|
|
32
|
+
"""Registered lossless ``format_id='sql'`` plugin."""
|
|
33
|
+
|
|
34
|
+
FORMAT_ID = FORMAT_ID
|
|
35
|
+
DIALECT = SQL_DIALECT
|
|
36
|
+
_META = FormatPluginMetadata(
|
|
37
|
+
format_id=FORMAT_ID,
|
|
38
|
+
aliases=(),
|
|
39
|
+
file_extensions=("sql",),
|
|
40
|
+
plugin_version="1.0.0",
|
|
41
|
+
contract_version="1.0.0",
|
|
42
|
+
capabilities={
|
|
43
|
+
# Whether the Code Analysis server can save a file of this format (decision D-CB.4).
|
|
44
|
+
"ca_save_supported": True,
|
|
45
|
+
# A statement list has no query language: the editor answers a search with UNKNOWN_FORMAT (Q-SQL-6 b).
|
|
46
|
+
"search_supported": False,
|
|
47
|
+
"semantic_role_mapping": True,
|
|
48
|
+
"byte_identical_round_trip": True,
|
|
49
|
+
"navigable": True,
|
|
50
|
+
"editable": True,
|
|
51
|
+
},
|
|
52
|
+
)
|
|
53
|
+
|
|
54
|
+
@staticmethod
|
|
55
|
+
def checker_plugin() -> Any:
|
|
56
|
+
from tree_engine.checks.builtin.format_syntax import SqlSyntaxChecker
|
|
57
|
+
|
|
58
|
+
return SqlSyntaxChecker()
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
SQL_FORMAT_PLUGIN = SqlFormatPlugin()
|