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.
Files changed (121) hide show
  1. ai_editor_tree_engine_dev-1.0.176.dist-info/METADATA +35 -0
  2. ai_editor_tree_engine_dev-1.0.176.dist-info/RECORD +121 -0
  3. ai_editor_tree_engine_dev-1.0.176.dist-info/WHEEL +5 -0
  4. ai_editor_tree_engine_dev-1.0.176.dist-info/licenses/LICENSE +21 -0
  5. ai_editor_tree_engine_dev-1.0.176.dist-info/top_level.txt +1 -0
  6. tree_engine/PUBLIC_API.md +161 -0
  7. tree_engine/__init__.py +327 -0
  8. tree_engine/checks/__init__.py +60 -0
  9. tree_engine/checks/builtin/__init__.py +5 -0
  10. tree_engine/checks/builtin/compile_check.py +53 -0
  11. tree_engine/checks/builtin/csv_syntax.py +51 -0
  12. tree_engine/checks/builtin/docstrings.py +211 -0
  13. tree_engine/checks/builtin/encoding.py +55 -0
  14. tree_engine/checks/builtin/fleet_rules.py +227 -0
  15. tree_engine/checks/builtin/format_syntax.py +82 -0
  16. tree_engine/checks/builtin/jsonl_syntax.py +49 -0
  17. tree_engine/checks/builtin/shipped.py +52 -0
  18. tree_engine/checks/builtin/syntax.py +118 -0
  19. tree_engine/checks/builtin/xml_wellformed.py +51 -0
  20. tree_engine/checks/chain.py +332 -0
  21. tree_engine/checks/external/__init__.py +5 -0
  22. tree_engine/checks/external/_base.py +61 -0
  23. tree_engine/checks/external/bandit.py +53 -0
  24. tree_engine/checks/external/black.py +48 -0
  25. tree_engine/checks/external/flake8.py +38 -0
  26. tree_engine/checks/external/isort.py +38 -0
  27. tree_engine/checks/external/mypy.py +45 -0
  28. tree_engine/checks/external/ruff.py +45 -0
  29. tree_engine/checks/external/runner.py +197 -0
  30. tree_engine/checks/model.py +110 -0
  31. tree_engine/checks/options.py +73 -0
  32. tree_engine/checks/plugin.py +171 -0
  33. tree_engine/checks/registry.py +349 -0
  34. tree_engine/core/address.py +376 -0
  35. tree_engine/core/identifier_map.py +266 -0
  36. tree_engine/core/identity.py +226 -0
  37. tree_engine/core/instrumentation.py +399 -0
  38. tree_engine/core/integrity.py +341 -0
  39. tree_engine/core/integrity_full.py +382 -0
  40. tree_engine/core/journal.py +260 -0
  41. tree_engine/core/journal_compose.py +571 -0
  42. tree_engine/core/live_tree.py +785 -0
  43. tree_engine/core/locking.py +188 -0
  44. tree_engine/core/move.py +585 -0
  45. tree_engine/core/move_references.py +323 -0
  46. tree_engine/core/node_types.py +408 -0
  47. tree_engine/core/nodes.py +348 -0
  48. tree_engine/core/offsets.py +24 -0
  49. tree_engine/core/operations.py +825 -0
  50. tree_engine/core/plugin_boundary.py +160 -0
  51. tree_engine/core/position_map.py +263 -0
  52. tree_engine/core/position_transfer.py +512 -0
  53. tree_engine/core/range_refresh.py +366 -0
  54. tree_engine/core/reference_cache.py +360 -0
  55. tree_engine/core/references.py +223 -0
  56. tree_engine/core/reparse.py +378 -0
  57. tree_engine/core/short_id.py +296 -0
  58. tree_engine/core/subtree_apply.py +397 -0
  59. tree_engine/core/subtree_copy.py +399 -0
  60. tree_engine/core/transactions.py +397 -0
  61. tree_engine/core/trivia.py +396 -0
  62. tree_engine/core/updates.py +398 -0
  63. tree_engine/core/validation.py +377 -0
  64. tree_engine/errors.py +104 -0
  65. tree_engine/exceptions.py +376 -0
  66. tree_engine/facade.py +4524 -0
  67. tree_engine/plugins/_statements.py +369 -0
  68. tree_engine/plugins/bsl/block_edit.py +449 -0
  69. tree_engine/plugins/bsl/blocks.py +127 -0
  70. tree_engine/plugins/bsl/checker.py +297 -0
  71. tree_engine/plugins/bsl/dialects.py +303 -0
  72. tree_engine/plugins/bsl/generator.py +481 -0
  73. tree_engine/plugins/bsl/import_map.py +995 -0
  74. tree_engine/plugins/bsl/plugin.py +452 -0
  75. tree_engine/plugins/contract.py +355 -0
  76. tree_engine/plugins/cpp/import_map.py +505 -0
  77. tree_engine/plugins/cpp/languages.py +99 -0
  78. tree_engine/plugins/cpp/plugin.py +501 -0
  79. tree_engine/plugins/csv_format.py +676 -0
  80. tree_engine/plugins/detachable.py +156 -0
  81. tree_engine/plugins/fallback.py +421 -0
  82. tree_engine/plugins/ini_format.py +330 -0
  83. tree_engine/plugins/json_format.py +813 -0
  84. tree_engine/plugins/json_pointer.py +203 -0
  85. tree_engine/plugins/jsonl_format.py +392 -0
  86. tree_engine/plugins/markdown_format.py +748 -0
  87. tree_engine/plugins/onec_query_format.py +61 -0
  88. tree_engine/plugins/parse_position.py +54 -0
  89. tree_engine/plugins/plain_text.py +1543 -0
  90. tree_engine/plugins/python/export_map.py +306 -0
  91. tree_engine/plugins/python/import_map.py +429 -0
  92. tree_engine/plugins/python/plugin.py +1710 -0
  93. tree_engine/plugins/registry.py +497 -0
  94. tree_engine/plugins/scan.py +87 -0
  95. tree_engine/plugins/selection.py +228 -0
  96. tree_engine/plugins/sql_format.py +61 -0
  97. tree_engine/plugins/toml_format.py +1072 -0
  98. tree_engine/plugins/xml_format.py +911 -0
  99. tree_engine/plugins/yaml/builder.py +49 -0
  100. tree_engine/plugins/yaml/emitter.py +225 -0
  101. tree_engine/plugins/yaml/flow.py +227 -0
  102. tree_engine/plugins/yaml/plugin.py +458 -0
  103. tree_engine/plugins/yaml/ranges.py +52 -0
  104. tree_engine/plugins/yaml/reader.py +359 -0
  105. tree_engine/plugins/yaml/scanner.py +298 -0
  106. tree_engine/query/adapter.py +283 -0
  107. tree_engine/query/engine.py +853 -0
  108. tree_engine/query/inspection.py +498 -0
  109. tree_engine/query/outline.py +288 -0
  110. tree_engine/query/predicates.py +263 -0
  111. tree_engine/query/rendered_lines.py +46 -0
  112. tree_engine/query/results.py +206 -0
  113. tree_engine/query/selector.py +400 -0
  114. tree_engine/query/xml_query.py +747 -0
  115. tree_engine/storage/codec.py +400 -0
  116. tree_engine/storage/document_bridge.py +579 -0
  117. tree_engine/storage/file_txn.py +459 -0
  118. tree_engine/storage/history.py +106 -0
  119. tree_engine/storage/lifecycle.py +622 -0
  120. tree_engine/storage/schema.py +403 -0
  121. tree_engine/storage/session_guard.py +398 -0
@@ -0,0 +1,355 @@
1
+ """Abstract format-plugin contract (concept C-010).
2
+
3
+ Scope: this module defines the *interface* boundary between the core tree
4
+ engine and format-specific plugins (Python, BSL, JavaScript, ...). It does
5
+ not implement, select, or discover any concrete plugin, and it contains no
6
+ registry. Registry operations (``register_format_plugin``,
7
+ ``unregister_format_plugin``, ``get_format_plugin``, ``list_format_plugins``)
8
+ and entry-point-based lazy loading are delivered by sibling steps under the
9
+ same tactical step (T-001) and must not be duplicated here.
10
+
11
+ Deviation note: per {p045}/{p051} the plugin contract is meant to sit on top
12
+ of a core-side plugin boundary module (``src/tree_engine/core/plugin_boundary.py``).
13
+ That module does not exist yet in this worktree at the time this file was
14
+ written, and sibling core modules that are not yet merged must not be
15
+ imported or stubbed from here. Consequently this file is self-contained: it
16
+ defines its own minimal metadata, error, and node-placeholder types instead
17
+ of importing them from the not-yet-existing boundary module. Once
18
+ ``plugin_boundary.py`` lands, this file must be reconciled with it rather
19
+ than continuing to duplicate any type it defines.
20
+
21
+ The common-model node type itself (concept C-002) is not merged into this
22
+ worktree either. ``CommonModelNode`` below is therefore a documented
23
+ placeholder alias (``Any``) for "one or more nodes of the format-independent
24
+ common tree model" -- it is not a new type definition competing with C-002,
25
+ only a local name used for type-hinting this contract until the concrete
26
+ type is available to import.
27
+
28
+ Every mandatory stage below is one direction of the bidirectional
29
+ translator a format plugin must implement ({p051}, {p056}, {p057}):
30
+ ``parse_document``/``import_external_tree`` obtain a parser-library
31
+ representation, ``import_to_common`` turns that representation into common
32
+ nodes, ``export_from_common`` turns common nodes back into a backend
33
+ representation, and ``generate_output`` turns that representation into final
34
+ text or bytes. External library trees must never cross the boundary back
35
+ into caller code: only common-model nodes or, for ``parse_fragment``, a
36
+ plain fallback string, may be returned.
37
+ """
38
+
39
+ from __future__ import annotations
40
+
41
+ import abc
42
+ import enum
43
+ from typing import Any, Mapping, Optional, Tuple, Union
44
+
45
+ from tree_engine.errors import ErrorCode
46
+
47
+ __all__ = [
48
+ "CommonModelNode",
49
+ "SemanticRole",
50
+ "STANDARD_SEMANTIC_ROLES",
51
+ "SemanticRoleMapping",
52
+ "FormatPluginMetadata",
53
+ "UnsupportedTranslationError",
54
+ "FormatPluginContractError",
55
+ "FormatPluginContract",
56
+ ]
57
+
58
+ # Placeholder for "one or more nodes of the format-independent common tree
59
+ # model" (concept C-002). Not merged into this worktree yet; see the module
60
+ # docstring. Using ``Any`` here keeps this contract from inventing a
61
+ # competing node type while still documenting intent at every call site.
62
+ CommonModelNode = Any
63
+
64
+
65
+ class SemanticRole(str, enum.Enum):
66
+ """Standard semantic roles the query engine understands ({p056})."""
67
+
68
+ FUNCTION = "function"
69
+ METHOD = "method"
70
+ CLASS = "class"
71
+ MODULE = "module"
72
+
73
+
74
+ STANDARD_SEMANTIC_ROLES: Tuple[SemanticRole, ...] = (
75
+ SemanticRole.FUNCTION,
76
+ SemanticRole.METHOD,
77
+ SemanticRole.CLASS,
78
+ SemanticRole.MODULE,
79
+ )
80
+
81
+
82
+ class SemanticRoleMapping:
83
+ """Declarative node-type -> semantic-role map published by a plugin.
84
+
85
+ ``node_type_to_role`` keys are the plugin's own backend/common node-type
86
+ strings (e.g. ``"FunctionDef"``); values are one of
87
+ :class:`SemanticRole`. A format that has no construct for a given
88
+ standard role (e.g. a format without methods) simply contributes no
89
+ entry mapping to that role -- :meth:`roles_for` then returns an empty
90
+ tuple for it rather than raising, satisfying the "empty results for
91
+ inapplicable roles" requirement of {p056}.
92
+ """
93
+
94
+ __slots__ = ("_node_type_to_role",)
95
+
96
+ def __init__(self, node_type_to_role: Mapping[str, SemanticRole]) -> None:
97
+ self._node_type_to_role: Mapping[str, SemanticRole] = dict(node_type_to_role)
98
+
99
+ @property
100
+ def node_type_to_role(self) -> Mapping[str, SemanticRole]:
101
+ """The full declared node-type -> semantic-role dict."""
102
+
103
+ return self._node_type_to_role
104
+
105
+ def roles_for(self, role: SemanticRole) -> Tuple[str, ...]:
106
+ """Return the node-type strings mapped to ``role``.
107
+
108
+ Returns an empty tuple -- never raises -- when the format has no
109
+ node type mapped to ``role``, including when ``role`` is one of the
110
+ standard roles this format simply does not model.
111
+ """
112
+
113
+ return tuple(
114
+ node_type
115
+ for node_type, mapped_role in self._node_type_to_role.items()
116
+ if mapped_role == role
117
+ )
118
+
119
+
120
+ class FormatPluginMetadata:
121
+ """Static identity and capability surface of a format plugin ({p055}, {p056}).
122
+
123
+ ``capabilities`` is a declarative, introspectable dict a plugin exposes
124
+ without instantiating any translator machinery; it must at minimum be
125
+ able to advertise semantic-role-mapping support (for example via a
126
+ ``"semantic_role_mapping"`` entry mirroring
127
+ :meth:`FormatPluginContract.semantic_role_mapping`), but the method call
128
+ remains the authoritative source of the live mapping. This class carries
129
+ no behavior beyond that of a plain, immutable value holder.
130
+
131
+ Two capability keys are canonical across every plugin and every
132
+ concrete plugin must declare both with a plain ``bool`` value (TODO
133
+ 27d10bbd):
134
+
135
+ * ``"navigable"`` -- the plugin turns a real document into an
136
+ addressable common-model tree (stable node identity, walkable
137
+ ``children``) that preview and the query engine can traverse and
138
+ search. This is a property of the *import* direction only; it says
139
+ nothing about whether editing or writing the tree back is safe.
140
+ * ``"editable"`` -- the plugin supports lossless structural mutation:
141
+ an edited common-model tree can be exported and rendered back to
142
+ disk without silently corrupting or normalizing content the caller
143
+ never touched. A plugin must declare ``False`` here (with a comment
144
+ citing the evidence) whenever its own measured
145
+ ``"byte_identical_round_trip"`` is ``False`` -- a lossy round trip on
146
+ *unedited* input can only get worse once edits are layered on top of
147
+ it, so write-back cannot honestly be called safe.
148
+
149
+ Declaring either key ``True`` when the underlying plugin has not
150
+ actually been measured to behave that way is exactly the kind of false
151
+ capability claim this contract exists to prevent (see the BSL
152
+ ``byte_identical_round_trip`` history in
153
+ ``tree_engine/plugins/bsl/plugin.py``). Both keys are declarations
154
+ only: this module defines no enforcement or refusal behavior keyed off
155
+ them, and no consumer-facing exposure (e.g. through an editor ``info()``
156
+ surface) is implemented here either -- that is a separate, later step.
157
+ """
158
+
159
+ __slots__ = (
160
+ "format_id",
161
+ "aliases",
162
+ "file_extensions",
163
+ "plugin_version",
164
+ "contract_version",
165
+ "capabilities",
166
+ )
167
+
168
+ def __init__(
169
+ self,
170
+ *,
171
+ format_id: str,
172
+ aliases: Tuple[str, ...],
173
+ file_extensions: Tuple[str, ...],
174
+ plugin_version: str,
175
+ contract_version: str,
176
+ capabilities: Mapping[str, Any],
177
+ ) -> None:
178
+ self.format_id = format_id
179
+ self.aliases = tuple(aliases)
180
+ self.file_extensions = tuple(file_extensions)
181
+ self.plugin_version = plugin_version
182
+ self.contract_version = contract_version
183
+ self.capabilities = dict(capabilities)
184
+
185
+
186
+ class UnsupportedTranslationError(Exception):
187
+ """Raised when a structure has no mappable translation ({p049}).
188
+
189
+ Carries the offending ``node_type`` and the ``format_id`` of the plugin
190
+ that could not perform the translation, per the contract's error
191
+ interface. ``error_code`` is always
192
+ :attr:`ErrorCode.UNSUPPORTED_TRANSLATION`; silent node loss is never an
193
+ acceptable alternative to raising this error.
194
+ """
195
+
196
+ error_code: ErrorCode = ErrorCode.UNSUPPORTED_TRANSLATION
197
+
198
+ def __init__(self, *, node_type: str, format_id: str, message: str = "") -> None:
199
+ self.node_type = node_type
200
+ self.format_id = format_id
201
+ super().__init__(
202
+ message
203
+ or f"format '{format_id}' cannot translate node type {node_type!r}"
204
+ )
205
+
206
+
207
+ class FormatPluginContractError(Exception):
208
+ """Raised when a plugin violates the contract boundary itself ({p057}, {p058}).
209
+
210
+ Distinct from :class:`UnsupportedTranslationError`: this covers contract
211
+ violations such as returning an external AST/CST where only common
212
+ nodes or a fallback string are permitted, an incompatible
213
+ ``contract_version``, or any other breach of the interface defined
214
+ below. Carries the ``plugin_id`` that violated the contract and the
215
+ specific ``error_code`` describing the violation.
216
+ """
217
+
218
+ def __init__(
219
+ self,
220
+ *,
221
+ plugin_id: str,
222
+ error_code: ErrorCode = ErrorCode.FORMAT_PLUGIN_CONTRACT_ERROR,
223
+ message: str = "",
224
+ details: Optional[Mapping[str, Any]] = None,
225
+ ) -> None:
226
+ self.plugin_id = plugin_id
227
+ self.error_code = error_code
228
+ #: Extra structured details (for a parse failure ``line``, ``column``, ``message``) the typed
229
+ #: public exception built from this error carries over verbatim (TODO 15a86bcb, D-BM).
230
+ self.details: Mapping[str, Any] = dict(details or {})
231
+ super().__init__(
232
+ message or f"plugin '{plugin_id}' contract violation: {error_code.value}"
233
+ )
234
+
235
+
236
+ class FormatPluginContract(abc.ABC):
237
+ """Abstract boundary every concrete format plugin must implement.
238
+
239
+ No plugin selection, registry, or entry-point discovery lives here
240
+ ({p055}, {p059}, {p101} are out of scope for this file) -- only the
241
+ shape a single plugin must expose once it has already been resolved.
242
+ """
243
+
244
+ @property
245
+ @abc.abstractmethod
246
+ def metadata(self) -> FormatPluginMetadata:
247
+ """Return this plugin's static identity and capability surface."""
248
+
249
+ raise NotImplementedError
250
+
251
+ @abc.abstractmethod
252
+ def parse_document(
253
+ self, source: str, options: Mapping[str, Any]
254
+ ) -> CommonModelNode:
255
+ """Parse a full document's source text into common-model nodes.
256
+
257
+ Internally runs the parser-library representation through the same
258
+ import translator used by :meth:`import_to_common` ({p056}); the
259
+ caller never sees the intermediate parser-library tree. Must raise
260
+ :class:`FormatPluginContractError` (not return a partial or
261
+ sentinel result) if the plugin cannot complete the pipeline for a
262
+ reason other than a classified content-parse failure.
263
+ """
264
+
265
+ raise NotImplementedError
266
+
267
+ @abc.abstractmethod
268
+ def import_external_tree(
269
+ self, external_tree: Any, options: Mapping[str, Any]
270
+ ) -> CommonModelNode:
271
+ """Translate an already-parsed external AST/CST into common nodes.
272
+
273
+ ``external_tree`` is the parser-library's own representation,
274
+ obtained by the caller through means outside this contract (e.g. an
275
+ already-parsed backend object). This method must return only
276
+ common-model nodes: the external tree itself must never be
277
+ returned, wrapped, or otherwise exposed to the caller.
278
+ """
279
+
280
+ raise NotImplementedError
281
+
282
+ @abc.abstractmethod
283
+ def parse_fragment(
284
+ self, fragment: str, options: Mapping[str, Any]
285
+ ) -> Union[CommonModelNode, str]:
286
+ """Parse a local code fragment, reusing the import translator.
287
+
288
+ Returns common-model nodes on a recognized structure. When the
289
+ fragment contains no recognized structure, returns a plain ``str``
290
+ (conventionally the fragment's own text, or a diagnostic string) to
291
+ signal "no structure" -- never an external AST/CST object and never
292
+ ``None`` used to mean the same thing.
293
+ """
294
+
295
+ raise NotImplementedError
296
+
297
+ @abc.abstractmethod
298
+ def import_to_common(
299
+ self, external_representation: Any, options: Mapping[str, Any]
300
+ ) -> CommonModelNode:
301
+ """Translate a parser-library representation into common nodes.
302
+
303
+ This is the single input translator shared by ``parse_document``,
304
+ ``import_external_tree``, and ``parse_fragment`` ({p056}, {p057}).
305
+ Must raise :class:`UnsupportedTranslationError` for a construct with
306
+ no mappable common-model equivalent, carrying the offending
307
+ ``node_type`` and this plugin's ``format_id``.
308
+ """
309
+
310
+ raise NotImplementedError
311
+
312
+ @abc.abstractmethod
313
+ def export_from_common(
314
+ self, nodes: CommonModelNode, options: Mapping[str, Any]
315
+ ) -> Any:
316
+ """Translate common-model nodes into this plugin's backend representation.
317
+
318
+ The returned value is backend-specific (e.g. a parser library's own
319
+ tree/object form) and is only ever consumed by this same plugin's
320
+ :meth:`generate_output`. Must raise
321
+ :class:`UnsupportedTranslationError` for a common-model construct
322
+ this format cannot represent.
323
+ """
324
+
325
+ raise NotImplementedError
326
+
327
+ @abc.abstractmethod
328
+ def generate_output(
329
+ self, target: Union[CommonModelNode, Any], options: Mapping[str, Any]
330
+ ) -> Union[str, bytes]:
331
+ """Produce final output text or bytes for ``target``.
332
+
333
+ ``target`` is either common-model nodes (in which case this method
334
+ is responsible for running :meth:`export_from_common` internally)
335
+ or an already backend-exported representation, per the plugin's own
336
+ documented facade choice ({p056} permits combining stages behind a
337
+ facade as long as the boundary stays testable). Must raise
338
+ :class:`FormatPluginContractError` if generation cannot complete
339
+ after a successful export.
340
+ """
341
+
342
+ raise NotImplementedError
343
+
344
+ @abc.abstractmethod
345
+ def semantic_role_mapping(self) -> SemanticRoleMapping:
346
+ """Return this plugin's declarative node-type -> semantic-role map.
347
+
348
+ Must cover the standard roles in :data:`STANDARD_SEMANTIC_ROLES`
349
+ (function, method, class, module) to the extent this format models
350
+ them; a role this format has no construct for is simply absent from
351
+ the mapping, which callers observe as
352
+ ``SemanticRoleMapping.roles_for(role) == ()`` rather than an error.
353
+ """
354
+
355
+ raise NotImplementedError