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,376 @@
1
+ """Typed public-API exception hierarchy for the tree engine.
2
+
3
+ Built strictly on top of the frozen error-code catalog in
4
+ :mod:`tree_engine.errors` (``ErrorCode``, ``ErrorLayer``,
5
+ ``ERROR_CODE_LAYER``). This module never redeclares a code and never
6
+ restates layer attribution: every leaf class below fixes only its
7
+ ``code`` class attribute, and ``layer`` is always derived, at access
8
+ time, from ``ERROR_CODE_LAYER`` -- so the catalog and this hierarchy can
9
+ never desynchronize. Per {p023}, ``FormatContentParseFailed`` is the
10
+ single exception permitted to carry the plain-text fallback flag; no
11
+ other class in this module exposes any fallback or masking path.
12
+ """
13
+
14
+ from __future__ import annotations
15
+
16
+ import types
17
+ from typing import Any, ClassVar, Mapping, Type
18
+
19
+ from tree_engine.errors import ErrorCode, ErrorLayer, ERROR_CODE_LAYER
20
+
21
+ __all__ = [
22
+ "TreeEngineException",
23
+ "CoreLayerException",
24
+ "PluginLayerException",
25
+ "StorageLayerException",
26
+ "NodeNotFound",
27
+ "NodeIdConflict",
28
+ "ShortIdConflict",
29
+ "DocumentVersionConflict",
30
+ "InvalidSelector",
31
+ "InvalidPosition",
32
+ "InvalidParentType",
33
+ "CycleDetected",
34
+ "UnresolvedReference",
35
+ "ConcurrentTreeModification",
36
+ "FormatUnknownExtension",
37
+ "FormatExtensionConflict",
38
+ "FormatPluginNotFound",
39
+ "PluginCapabilityNotSupported",
40
+ "FormatContentParseFailed",
41
+ "FormatFragmentParseFailed",
42
+ "FormatPluginContractError",
43
+ "UnsupportedTranslation",
44
+ "TreePayloadInvalid",
45
+ "TreeSchemaUnsupported",
46
+ "ChecksumMismatch",
47
+ "ConcurrentSourceModification",
48
+ "StorageIOError",
49
+ "CheckToolCrashed",
50
+ "CheckToolTimeout",
51
+ "CheckToolMissing",
52
+ "CheckConfigInvalid",
53
+ "CODE_TO_EXCEPTION",
54
+ "exception_for_code",
55
+ ]
56
+
57
+
58
+ class TreeEngineException(Exception):
59
+ """Common base of every exception this module defines.
60
+
61
+ ``code`` is the stable :class:`~tree_engine.errors.ErrorCode` each
62
+ concrete leaf fixes as a class attribute -- never re-derived, never
63
+ guessed from the message. ``layer`` is never stored a second time:
64
+ it is looked up, on every access, in the frozen
65
+ :data:`~tree_engine.errors.ERROR_CODE_LAYER` mapping keyed by
66
+ ``code``, so a leaf's declared layer and its structural base (see
67
+ the three per-layer intermediates below) cannot drift apart.
68
+ """
69
+
70
+ code: ClassVar[ErrorCode]
71
+
72
+ #: Only ``FormatContentParseFailed`` overrides this to ``True``; it is
73
+ #: the sole class in this hierarchy allowed to advertise a permitted
74
+ #: plain-text fallback per {p023}. No other subclass may set it.
75
+ plain_text_fallback_permitted: ClassVar[bool] = False
76
+
77
+ def __init__(self, message: str = "", /, **details: Any) -> None:
78
+ self.details: Mapping[str, Any] = dict(details)
79
+ rendered = f"[{self.code.value}] {message}" if message else f"[{self.code.value}]"
80
+ super().__init__(rendered)
81
+
82
+ @property
83
+ def layer(self) -> ErrorLayer:
84
+ """The owning layer (CORE, PLUGIN, or STORAGE), from ``ERROR_CODE_LAYER``."""
85
+ return ERROR_CODE_LAYER[self.code]
86
+
87
+
88
+ class CoreLayerException(TreeEngineException):
89
+ """Intermediate base for every leaf whose code attributes to ``ErrorLayer.CORE``."""
90
+
91
+
92
+ class PluginLayerException(TreeEngineException):
93
+ """Intermediate base for every leaf whose code attributes to ``ErrorLayer.PLUGIN``."""
94
+
95
+
96
+ class StorageLayerException(TreeEngineException):
97
+ """Intermediate base for every leaf whose code attributes to ``ErrorLayer.STORAGE``."""
98
+
99
+
100
+ # --------------------------------------------------------------------------
101
+ # Core-layer leaves (10 codes)
102
+ # --------------------------------------------------------------------------
103
+
104
+
105
+ class NodeNotFound(CoreLayerException):
106
+ """An address resolves to no node in the current document."""
107
+
108
+ code = ErrorCode.NODE_NOT_FOUND
109
+
110
+
111
+ class NodeIdConflict(CoreLayerException):
112
+ """A new or incoming ``node_id`` collides with an existing one."""
113
+
114
+ code = ErrorCode.NODE_ID_CONFLICT
115
+
116
+
117
+ class ShortIdConflict(CoreLayerException):
118
+ """A ``short_id`` collides with an existing entry in the document map."""
119
+
120
+ code = ErrorCode.SHORT_ID_CONFLICT
121
+
122
+
123
+ class DocumentVersionConflict(CoreLayerException):
124
+ """An operation's ``expected_version`` does not match the document's."""
125
+
126
+ code = ErrorCode.DOCUMENT_VERSION_CONFLICT
127
+
128
+
129
+ class InvalidSelector(CoreLayerException):
130
+ """A query/drill_down selector is malformed or cannot be applied."""
131
+
132
+ code = ErrorCode.INVALID_SELECTOR
133
+
134
+
135
+ class InvalidPosition(CoreLayerException):
136
+ """A requested insertion/move position is out of range or malformed."""
137
+
138
+ code = ErrorCode.INVALID_POSITION
139
+
140
+
141
+ class InvalidParentType(CoreLayerException):
142
+ """A parent node's kind cannot legally host the given child."""
143
+
144
+ code = ErrorCode.INVALID_PARENT_TYPE
145
+
146
+
147
+ class CycleDetected(CoreLayerException):
148
+ """An operation would introduce a cycle in the tree/reference graph."""
149
+
150
+ code = ErrorCode.CYCLE_DETECTED
151
+
152
+
153
+ class UnresolvedReference(CoreLayerException):
154
+ """A reference cannot be resolved to a live node."""
155
+
156
+ code = ErrorCode.UNRESOLVED_REFERENCE
157
+
158
+
159
+ class ConcurrentTreeModification(CoreLayerException):
160
+ """A post-mutation integrity check found an out-of-band tree change."""
161
+
162
+ code = ErrorCode.CONCURRENT_TREE_MODIFICATION
163
+
164
+
165
+ # --------------------------------------------------------------------------
166
+ # Plugin-layer leaves (8 codes)
167
+ # --------------------------------------------------------------------------
168
+
169
+
170
+ class FormatUnknownExtension(PluginLayerException):
171
+ """No registered plugin claims the given file extension."""
172
+
173
+ code = ErrorCode.FORMAT_UNKNOWN_EXTENSION
174
+
175
+
176
+ class FormatExtensionConflict(PluginLayerException):
177
+ """Two or more registered plugins claim the same file extension."""
178
+
179
+ code = ErrorCode.FORMAT_EXTENSION_CONFLICT
180
+
181
+
182
+ class FormatPluginNotFound(PluginLayerException):
183
+ """``format_id`` does not resolve to any registered plugin."""
184
+
185
+ code = ErrorCode.FORMAT_PLUGIN_NOT_FOUND
186
+
187
+
188
+ class PluginCapabilityNotSupported(PluginLayerException):
189
+ """The resolved plugin does not support the requested capability."""
190
+
191
+ code = ErrorCode.PLUGIN_CAPABILITY_NOT_SUPPORTED
192
+
193
+
194
+ class FormatContentParseFailed(PluginLayerException):
195
+ """A plugin failed to parse document content.
196
+
197
+ The single exception in this hierarchy permitted to carry the
198
+ authorized plain-text fallback per {p023}: ``plain_text_fallback_permitted``
199
+ is fixed to ``True`` here and nowhere else.
200
+ """
201
+
202
+ code = ErrorCode.FORMAT_CONTENT_PARSE_FAILED
203
+ plain_text_fallback_permitted: ClassVar[bool] = True
204
+
205
+
206
+ class FormatFragmentParseFailed(PluginLayerException):
207
+ """A plugin failed to parse an inserted/replaced fragment."""
208
+
209
+ code = ErrorCode.FORMAT_FRAGMENT_PARSE_FAILED
210
+
211
+
212
+ class FormatPluginContractError(PluginLayerException):
213
+ """A plugin violated the format-plugin contract boundary itself."""
214
+
215
+ code = ErrorCode.FORMAT_PLUGIN_CONTRACT_ERROR
216
+
217
+
218
+ class UnsupportedTranslation(PluginLayerException):
219
+ """A structure has no mappable translation in the target format."""
220
+
221
+ code = ErrorCode.UNSUPPORTED_TRANSLATION
222
+
223
+
224
+ # --------------------------------------------------------------------------
225
+ # Storage-layer leaves (5 codes)
226
+ # --------------------------------------------------------------------------
227
+
228
+
229
+ class TreePayloadInvalid(StorageLayerException):
230
+ """A loaded tree payload fails structural validation."""
231
+
232
+ code = ErrorCode.TREE_PAYLOAD_INVALID
233
+
234
+
235
+ class TreeSchemaUnsupported(StorageLayerException):
236
+ """A loaded payload declares a schema version storage cannot handle."""
237
+
238
+ code = ErrorCode.TREE_SCHEMA_UNSUPPORTED
239
+
240
+
241
+ class ChecksumMismatch(StorageLayerException):
242
+ """A stored artifact's checksum does not match its recorded value."""
243
+
244
+ code = ErrorCode.CHECKSUM_MISMATCH
245
+
246
+
247
+ class ConcurrentSourceModification(StorageLayerException):
248
+ """The on-disk source changed out from under an in-progress operation."""
249
+
250
+ code = ErrorCode.CONCURRENT_SOURCE_MODIFICATION
251
+
252
+
253
+ class StorageIOError(StorageLayerException):
254
+ """A file-system or I/O operation failed in the storage layer."""
255
+
256
+ code = ErrorCode.STORAGE_IO_ERROR
257
+
258
+
259
+ # --------------------------------------------------------------------------
260
+ # File-check leaves (4 codes, PLUGIN layer; tree_engine.checks, TODO 15a86bcb)
261
+ # --------------------------------------------------------------------------
262
+
263
+
264
+ class _CheckFailure(PluginLayerException):
265
+ """Shared constructor of the four ``tree_engine.checks`` errors: ``(message, details)``.
266
+
267
+ ``details`` is a mapping carried verbatim on ``.details``; keyword arguments are merged into it.
268
+ """
269
+
270
+ def __init__(self, message: str = "", details: Mapping[str, Any] | None = None, /, **extra: Any) -> None:
271
+ super().__init__(message, **{**dict(details or {}), **extra})
272
+
273
+
274
+ class CheckToolCrashed(_CheckFailure):
275
+ """An external checker exited with a code that is neither success nor a finding, or produced unreadable output."""
276
+
277
+ code = ErrorCode.CHECK_TOOL_CRASHED
278
+
279
+
280
+ class CheckToolTimeout(_CheckFailure):
281
+ """An external checker ran longer than its time limit; its process group was killed."""
282
+
283
+ code = ErrorCode.CHECK_TOOL_TIMEOUT
284
+
285
+
286
+ class CheckToolMissing(_CheckFailure):
287
+ """A checker tool or module required for a run is not installed for the chosen interpreter."""
288
+
289
+ code = ErrorCode.CHECK_TOOL_MISSING
290
+
291
+
292
+ class CheckConfigInvalid(_CheckFailure):
293
+ """A check chain, checker request or checker configuration is invalid."""
294
+
295
+ code = ErrorCode.CHECK_CONFIG_INVALID
296
+
297
+
298
+ # --------------------------------------------------------------------------
299
+ # Totality and consistency guards (mirrors the pattern in errors.py)
300
+ # --------------------------------------------------------------------------
301
+
302
+ _LAYER_INTERMEDIATE: Mapping[ErrorLayer, Type[TreeEngineException]] = {
303
+ ErrorLayer.CORE: CoreLayerException,
304
+ ErrorLayer.PLUGIN: PluginLayerException,
305
+ ErrorLayer.STORAGE: StorageLayerException,
306
+ }
307
+
308
+ _ALL_EXCEPTIONS: tuple[Type[TreeEngineException], ...] = (
309
+ NodeNotFound,
310
+ NodeIdConflict,
311
+ ShortIdConflict,
312
+ DocumentVersionConflict,
313
+ InvalidSelector,
314
+ InvalidPosition,
315
+ InvalidParentType,
316
+ CycleDetected,
317
+ UnresolvedReference,
318
+ ConcurrentTreeModification,
319
+ FormatUnknownExtension,
320
+ FormatExtensionConflict,
321
+ FormatPluginNotFound,
322
+ PluginCapabilityNotSupported,
323
+ FormatContentParseFailed,
324
+ FormatFragmentParseFailed,
325
+ FormatPluginContractError,
326
+ UnsupportedTranslation,
327
+ TreePayloadInvalid,
328
+ TreeSchemaUnsupported,
329
+ ChecksumMismatch,
330
+ ConcurrentSourceModification,
331
+ StorageIOError,
332
+ CheckToolCrashed,
333
+ CheckToolTimeout,
334
+ CheckToolMissing,
335
+ CheckConfigInvalid,
336
+ )
337
+
338
+ #: Exactly one exception class per ``ErrorCode`` member, built here rather
339
+ #: than declared class-by-class elsewhere, so any future drift between the
340
+ #: leaf set and the catalog fails loudly at import time. A read-only
341
+ #: ``types.MappingProxyType``, same as :data:`tree_engine.errors.ERROR_CODE_LAYER`, so a public
342
+ #: consumer holding this reference cannot mutate the catalog out from under every other caller.
343
+ CODE_TO_EXCEPTION: Mapping[ErrorCode, Type[TreeEngineException]] = types.MappingProxyType(
344
+ {cls.code: cls for cls in _ALL_EXCEPTIONS}
345
+ )
346
+
347
+ _all_codes = set(ErrorCode)
348
+ _mapped_codes = set(CODE_TO_EXCEPTION.keys())
349
+ assert _mapped_codes == _all_codes, (
350
+ f"exception hierarchy is not total: missing {_all_codes - _mapped_codes}, "
351
+ f"extra {_mapped_codes - _all_codes}"
352
+ )
353
+ assert len(_ALL_EXCEPTIONS) == len(CODE_TO_EXCEPTION), (
354
+ "two or more leaf classes share the same ErrorCode"
355
+ )
356
+
357
+ for _cls in _ALL_EXCEPTIONS:
358
+ _expected_layer = ERROR_CODE_LAYER[_cls.code]
359
+ _expected_base = _LAYER_INTERMEDIATE[_expected_layer]
360
+ assert issubclass(_cls, _expected_base), (
361
+ f"{_cls.__name__} carries {_cls.code!r} (layer {_expected_layer!r}) "
362
+ f"but does not inherit from {_expected_base.__name__}"
363
+ )
364
+ del _cls, _expected_layer, _expected_base
365
+
366
+ _fallback_classes = [cls for cls in _ALL_EXCEPTIONS if cls.plain_text_fallback_permitted]
367
+ assert _fallback_classes == [FormatContentParseFailed], (
368
+ "plain_text_fallback_permitted must be True for FormatContentParseFailed only, "
369
+ f"found {[c.__name__ for c in _fallback_classes]}"
370
+ )
371
+ del _fallback_classes
372
+
373
+
374
+ def exception_for_code(code: ErrorCode) -> Type[TreeEngineException]:
375
+ """Return the single exception class that represents ``code``."""
376
+ return CODE_TO_EXCEPTION[code]