@trojanbox-vcp-test/site-edit-engine 0.1.0

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 (174) hide show
  1. package/README.md +85 -0
  2. package/dist/execute-integration/execute-fixture-harness.d.ts +25 -0
  3. package/dist/execute-integration/execute-fixture-harness.js +37 -0
  4. package/dist/index.d.ts +3 -0
  5. package/dist/index.js +2 -0
  6. package/dist/internal/ast/diagnostics/index.d.ts +5 -0
  7. package/dist/internal/ast/diagnostics/index.js +25 -0
  8. package/dist/internal/ast/history/index.d.ts +15 -0
  9. package/dist/internal/ast/history/index.js +62 -0
  10. package/dist/internal/ast/index.d.ts +8 -0
  11. package/dist/internal/ast/index.js +5 -0
  12. package/dist/internal/ast/locators/index.d.ts +1 -0
  13. package/dist/internal/ast/locators/index.js +1 -0
  14. package/dist/internal/ast/locators/resolve-locator.d.ts +16 -0
  15. package/dist/internal/ast/locators/resolve-locator.js +920 -0
  16. package/dist/internal/ast/parser/SourceParser.d.ts +30 -0
  17. package/dist/internal/ast/parser/SourceParser.js +49 -0
  18. package/dist/internal/ast/parser/index.d.ts +21 -0
  19. package/dist/internal/ast/parser/index.js +64 -0
  20. package/dist/internal/ast/primitives/conditional/conditional-primitives.d.ts +18 -0
  21. package/dist/internal/ast/primitives/conditional/conditional-primitives.js +237 -0
  22. package/dist/internal/ast/primitives/conditional/index.d.ts +1 -0
  23. package/dist/internal/ast/primitives/conditional/index.js +1 -0
  24. package/dist/internal/ast/primitives/imports/add-import.d.ts +18 -0
  25. package/dist/internal/ast/primitives/imports/add-import.js +111 -0
  26. package/dist/internal/ast/primitives/imports/index.d.ts +2 -0
  27. package/dist/internal/ast/primitives/imports/index.js +2 -0
  28. package/dist/internal/ast/primitives/imports/remove-import.d.ts +15 -0
  29. package/dist/internal/ast/primitives/imports/remove-import.js +72 -0
  30. package/dist/internal/ast/primitives/index.d.ts +10 -0
  31. package/dist/internal/ast/primitives/index.js +10 -0
  32. package/dist/internal/ast/primitives/jsx/index.d.ts +4 -0
  33. package/dist/internal/ast/primitives/jsx/index.js +4 -0
  34. package/dist/internal/ast/primitives/jsx/insert-child.d.ts +11 -0
  35. package/dist/internal/ast/primitives/jsx/insert-child.js +69 -0
  36. package/dist/internal/ast/primitives/jsx/move-node.d.ts +9 -0
  37. package/dist/internal/ast/primitives/jsx/move-node.js +76 -0
  38. package/dist/internal/ast/primitives/jsx/remove-node.d.ts +7 -0
  39. package/dist/internal/ast/primitives/jsx/remove-node.js +36 -0
  40. package/dist/internal/ast/primitives/jsx/update-text.d.ts +8 -0
  41. package/dist/internal/ast/primitives/jsx/update-text.js +81 -0
  42. package/dist/internal/ast/primitives/next/index.d.ts +1 -0
  43. package/dist/internal/ast/primitives/next/index.js +1 -0
  44. package/dist/internal/ast/primitives/next/next-primitives.d.ts +43 -0
  45. package/dist/internal/ast/primitives/next/next-primitives.js +211 -0
  46. package/dist/internal/ast/primitives/shared.d.ts +60 -0
  47. package/dist/internal/ast/primitives/shared.js +176 -0
  48. package/dist/internal/ast/primitives/style/class-expression.d.ts +23 -0
  49. package/dist/internal/ast/primitives/style/class-expression.js +174 -0
  50. package/dist/internal/ast/primitives/style/index.d.ts +1 -0
  51. package/dist/internal/ast/primitives/style/index.js +1 -0
  52. package/dist/internal/ast/primitives/style/style-primitives.d.ts +49 -0
  53. package/dist/internal/ast/primitives/style/style-primitives.js +555 -0
  54. package/dist/internal/ast/primitives/values/index.d.ts +1 -0
  55. package/dist/internal/ast/primitives/values/index.js +1 -0
  56. package/dist/internal/ast/primitives/values/value-primitives.d.ts +42 -0
  57. package/dist/internal/ast/primitives/values/value-primitives.js +158 -0
  58. package/dist/internal/ast/printer/SourcePrinter.d.ts +21 -0
  59. package/dist/internal/ast/printer/SourcePrinter.js +76 -0
  60. package/dist/internal/ast/printer/index.d.ts +6 -0
  61. package/dist/internal/ast/printer/index.js +126 -0
  62. package/dist/internal/ast/types.d.ts +190 -0
  63. package/dist/internal/ast/types.js +1 -0
  64. package/dist/internal/capability/capability-resolver.d.ts +16 -0
  65. package/dist/internal/capability/capability-resolver.js +127 -0
  66. package/dist/internal/classname-source.d.ts +24 -0
  67. package/dist/internal/classname-source.js +220 -0
  68. package/dist/internal/contracts/IEditEngineRuntime.d.ts +18 -0
  69. package/dist/internal/contracts/IEditEngineRuntime.js +1 -0
  70. package/dist/internal/domain/EditDiagnostic.d.ts +38 -0
  71. package/dist/internal/domain/EditDiagnostic.js +43 -0
  72. package/dist/internal/events/event-bus.d.ts +14 -0
  73. package/dist/internal/events/event-bus.js +21 -0
  74. package/dist/internal/graph/graph-builder.d.ts +12 -0
  75. package/dist/internal/graph/graph-builder.js +1371 -0
  76. package/dist/internal/graph/import-resolver.d.ts +31 -0
  77. package/dist/internal/graph/import-resolver.js +109 -0
  78. package/dist/internal/graph/project-graph-builder.d.ts +32 -0
  79. package/dist/internal/graph/project-graph-builder.js +133 -0
  80. package/dist/internal/graph/types.d.ts +114 -0
  81. package/dist/internal/graph/types.js +6 -0
  82. package/dist/internal/history/undo-redo.d.ts +28 -0
  83. package/dist/internal/history/undo-redo.js +42 -0
  84. package/dist/internal/index.d.ts +2 -0
  85. package/dist/internal/index.js +1 -0
  86. package/dist/internal/planner/planner.d.ts +104 -0
  87. package/dist/internal/planner/planner.js +2533 -0
  88. package/dist/internal/planner/types.d.ts +275 -0
  89. package/dist/internal/planner/types.js +6 -0
  90. package/dist/internal/protocol/boundary.d.ts +10 -0
  91. package/dist/internal/protocol/boundary.js +3 -0
  92. package/dist/internal/protocol/capability.d.ts +47 -0
  93. package/dist/internal/protocol/capability.js +8 -0
  94. package/dist/internal/protocol/error.d.ts +43 -0
  95. package/dist/internal/protocol/error.js +38 -0
  96. package/dist/internal/protocol/event.d.ts +39 -0
  97. package/dist/internal/protocol/event.js +3 -0
  98. package/dist/internal/protocol/identity.d.ts +26 -0
  99. package/dist/internal/protocol/identity.js +30 -0
  100. package/dist/internal/protocol/operation.d.ts +224 -0
  101. package/dist/internal/protocol/operation.js +8 -0
  102. package/dist/internal/protocol/render.d.ts +212 -0
  103. package/dist/internal/protocol/render.js +3 -0
  104. package/dist/internal/protocol.d.ts +9 -0
  105. package/dist/internal/protocol.js +2 -0
  106. package/dist/internal/provenance/binding-graph.d.ts +39 -0
  107. package/dist/internal/provenance/binding-graph.js +184 -0
  108. package/dist/internal/provenance/capability-policy.d.ts +15 -0
  109. package/dist/internal/provenance/capability-policy.js +96 -0
  110. package/dist/internal/provenance/data-source-classifier.d.ts +14 -0
  111. package/dist/internal/provenance/data-source-classifier.js +281 -0
  112. package/dist/internal/provenance/resolve-text-provenance.d.ts +45 -0
  113. package/dist/internal/provenance/resolve-text-provenance.js +3090 -0
  114. package/dist/internal/provenance/types.d.ts +89 -0
  115. package/dist/internal/provenance/types.js +1 -0
  116. package/dist/internal/render/component-semantic.d.ts +11 -0
  117. package/dist/internal/render/component-semantic.js +141 -0
  118. package/dist/internal/render/content-model.d.ts +3 -0
  119. package/dist/internal/render/content-model.js +89 -0
  120. package/dist/internal/render/media-model.d.ts +3 -0
  121. package/dist/internal/render/media-model.js +45 -0
  122. package/dist/internal/render/provenance-types.d.ts +33 -0
  123. package/dist/internal/render/provenance-types.js +1 -0
  124. package/dist/internal/render/render-projection.d.ts +24 -0
  125. package/dist/internal/render/render-projection.js +281 -0
  126. package/dist/internal/render/tailwind-style-model.d.ts +19 -0
  127. package/dist/internal/render/tailwind-style-model.js +1187 -0
  128. package/dist/internal/runtime/EditEngineRuntime.d.ts +25 -0
  129. package/dist/internal/runtime/EditEngineRuntime.js +89 -0
  130. package/dist/internal/runtime/EditEngineRuntimeSnapshot.d.ts +31 -0
  131. package/dist/internal/runtime/EditEngineRuntimeSnapshot.js +15 -0
  132. package/dist/internal/runtime/InternalEditEngine.d.ts +44 -0
  133. package/dist/internal/runtime/InternalEditEngine.js +1391 -0
  134. package/dist/internal/runtime.d.ts +3 -0
  135. package/dist/internal/runtime.js +1 -0
  136. package/dist/internal/topology/topology.d.ts +6 -0
  137. package/dist/internal/topology/topology.js +98 -0
  138. package/dist/internal/topology/types.d.ts +35 -0
  139. package/dist/internal/topology/types.js +5 -0
  140. package/dist/internal/types.d.ts +1 -0
  141. package/dist/internal/types.js +1 -0
  142. package/dist/internal/writeback/in-memory-fs.d.ts +7 -0
  143. package/dist/internal/writeback/in-memory-fs.js +44 -0
  144. package/dist/internal/writeback/types.d.ts +45 -0
  145. package/dist/internal/writeback/types.js +7 -0
  146. package/dist/internal/writeback/writeback-service.d.ts +7 -0
  147. package/dist/internal/writeback/writeback-service.js +568 -0
  148. package/dist/internal-adapter.d.ts +18 -0
  149. package/dist/internal-adapter.js +350 -0
  150. package/dist/next-app-router-fs.d.ts +2 -0
  151. package/dist/next-app-router-fs.js +64 -0
  152. package/dist/next-app-router.d.ts +11 -0
  153. package/dist/next-app-router.js +140 -0
  154. package/dist/preview-runtime.d.ts +394 -0
  155. package/dist/preview-runtime.js +102 -0
  156. package/dist/public-file-system.d.ts +7 -0
  157. package/dist/public-file-system.js +1 -0
  158. package/dist/runtime-sync.d.ts +95 -0
  159. package/dist/runtime-sync.js +321 -0
  160. package/dist/runtime.d.ts +340 -0
  161. package/dist/runtime.js +134 -0
  162. package/dist/site-edit-instrumentation.d.ts +19 -0
  163. package/dist/site-edit-instrumentation.js +322 -0
  164. package/dist/snapshot-file-system.d.ts +19 -0
  165. package/dist/snapshot-file-system.js +49 -0
  166. package/dist/source-watcher.d.ts +20 -0
  167. package/dist/source-watcher.js +150 -0
  168. package/dist/source-writeback-test-harness.d.ts +244 -0
  169. package/dist/source-writeback-test-harness.js +119 -0
  170. package/dist/types.d.ts +68 -0
  171. package/dist/types.js +1 -0
  172. package/dist/webpack-loader.cjs +592 -0
  173. package/dist/webpack-loader.d.ts +27 -0
  174. package/package.json +66 -0
@@ -0,0 +1,275 @@
1
+ import type { DirectiveLocator, ExportLocator, JsxAttributeLocator, JsxNodeLocator, Placement, PrimitiveValue, ValueLocator, ValuePathSegment, ValueRootSelector } from "../ast/index.js";
2
+ import type { OperationTarget as ProtocolOperationTarget, OperationRequest as ProtocolOperationRequest, OperationType as ProtocolOperationType, OperationValue as ProtocolOperationValue } from "../protocol.js";
3
+ import type { ExternalAdapterCapability } from "../provenance/types.js";
4
+ export type ExternalSourceKind = "api-field" | "cms-field" | "i18n-message" | "config-entry";
5
+ export type OperationType = ProtocolOperationType;
6
+ export type OperationTarget = ProtocolOperationTarget;
7
+ export type OperationValue = ProtocolOperationValue;
8
+ /**
9
+ * protocol-facing 请求 — planner 的输入。
10
+ * targetKey 是 protocol 层 key,不是 source position。
11
+ */
12
+ export type OperationRequest = ProtocolOperationRequest;
13
+ /**
14
+ * RewriteStep 是 planner 展开后的执行形状。
15
+ * 到了这一步,所有 locator / jsx / import 变更已经确定。
16
+ * writeback 照着执行即可,不需要反查 graph。
17
+ */
18
+ export type RewriteStep = RewriteStep_UpdateText | RewriteStep_UpdateValue | RewriteStep_SetObjectField | RewriteStep_InsertObjectField | RewriteStep_RemoveObjectField | RewriteStep_UpdateArrayItem | RewriteStep_InsertArrayItem | RewriteStep_RemoveArrayItem | RewriteStep_MoveArrayItem | RewriteStep_ReplaceConditionalExpression | RewriteStep_SetConditionalBranchContent | RewriteStep_RemoveNode | RewriteStep_InsertChild | RewriteStep_MoveNode | RewriteStep_SetJsxProp | RewriteStep_RemoveJsxProp | RewriteStep_SetClassName | RewriteStep_AddClassToken | RewriteStep_RemoveClassToken | RewriteStep_SetStyleProperty | RewriteStep_SetStyleProperties | RewriteStep_SetCssModuleClass | RewriteStep_SetDirective | RewriteStep_RemoveDirective | RewriteStep_SetRouteExport | RewriteStep_SetMetadataField | RewriteStep_SetGenerateMetadata | RewriteStep_InvokeExternalAdapter | RewriteStep_AddImport | RewriteStep_RemoveImport;
19
+ interface RewriteStepBase {
20
+ /** 步骤序号,writeback 按此顺序执行 */
21
+ order: number;
22
+ /** 目标文件路径 */
23
+ file: string;
24
+ }
25
+ export interface RewriteStep_UpdateText extends RewriteStepBase {
26
+ type: "update-text";
27
+ locator: JsxNodeLocator;
28
+ segmentIndex: number;
29
+ newText: string;
30
+ }
31
+ export interface RewriteStep_UpdateValue extends RewriteStepBase {
32
+ type: "update-value";
33
+ locator: ValueLocator;
34
+ value: PrimitiveValue;
35
+ }
36
+ export interface RewriteStep_SetObjectField extends RewriteStepBase {
37
+ type: "set-object-field";
38
+ locator: ValueLocator;
39
+ value: PrimitiveValue;
40
+ }
41
+ export interface RewriteStep_InsertObjectField extends RewriteStepBase {
42
+ type: "insert-object-field";
43
+ locator: ValueLocator;
44
+ field: string;
45
+ value: PrimitiveValue;
46
+ }
47
+ export interface RewriteStep_RemoveObjectField extends RewriteStepBase {
48
+ type: "remove-object-field";
49
+ locator: ValueLocator;
50
+ field: string;
51
+ }
52
+ export interface RewriteStep_UpdateArrayItem extends RewriteStepBase {
53
+ type: "update-array-item";
54
+ locator: ValueLocator;
55
+ value: PrimitiveValue;
56
+ }
57
+ export interface RewriteStep_InsertArrayItem extends RewriteStepBase {
58
+ type: "insert-array-item";
59
+ locator: ValueLocator;
60
+ index: number;
61
+ value: PrimitiveValue;
62
+ }
63
+ export interface RewriteStep_RemoveArrayItem extends RewriteStepBase {
64
+ type: "remove-array-item";
65
+ locator: ValueLocator;
66
+ index: number;
67
+ }
68
+ export interface RewriteStep_MoveArrayItem extends RewriteStepBase {
69
+ type: "move-array-item";
70
+ locator: ValueLocator;
71
+ fromIndex: number;
72
+ toIndex: number;
73
+ }
74
+ export interface RewriteStep_ReplaceConditionalExpression extends RewriteStepBase {
75
+ type: "replace-conditional-expression";
76
+ locator: JsxNodeLocator;
77
+ nextExpression: string;
78
+ }
79
+ export interface RewriteStep_SetConditionalBranchContent extends RewriteStepBase {
80
+ type: "set-conditional-branch-content";
81
+ locator: JsxNodeLocator;
82
+ branch: "then" | "else";
83
+ content: {
84
+ jsx: string;
85
+ };
86
+ }
87
+ export interface RewriteStep_RemoveNode extends RewriteStepBase {
88
+ type: "remove-node";
89
+ locator: JsxNodeLocator;
90
+ removeWhitespace?: boolean;
91
+ }
92
+ export interface RewriteStep_InsertChild extends RewriteStepBase {
93
+ type: "insert-child";
94
+ parentLocator: JsxNodeLocator;
95
+ node: {
96
+ jsx: string;
97
+ };
98
+ placement: Placement;
99
+ anchorLocator?: JsxNodeLocator;
100
+ }
101
+ export interface RewriteStep_MoveNode extends RewriteStepBase {
102
+ type: "move-node";
103
+ locator: JsxNodeLocator;
104
+ targetParentLocator: JsxNodeLocator;
105
+ placement: Placement;
106
+ anchorLocator?: JsxNodeLocator;
107
+ }
108
+ export interface RewriteStep_SetJsxProp extends RewriteStepBase {
109
+ type: "set-jsx-prop";
110
+ locator: JsxAttributeLocator;
111
+ value: OperationValue;
112
+ }
113
+ export interface RewriteStep_RemoveJsxProp extends RewriteStepBase {
114
+ type: "remove-jsx-prop";
115
+ locator: JsxAttributeLocator;
116
+ }
117
+ export interface RewriteStep_SetClassName extends RewriteStepBase {
118
+ type: "set-class-name";
119
+ locator: JsxAttributeLocator;
120
+ value: string;
121
+ }
122
+ export interface RewriteStep_AddClassToken extends RewriteStepBase {
123
+ type: "add-class-token";
124
+ locator: JsxAttributeLocator;
125
+ token: string;
126
+ }
127
+ export interface RewriteStep_RemoveClassToken extends RewriteStepBase {
128
+ type: "remove-class-token";
129
+ locator: JsxAttributeLocator;
130
+ token: string;
131
+ }
132
+ export interface RewriteStep_SetStyleProperty extends RewriteStepBase {
133
+ type: "set-style-property";
134
+ locator: JsxAttributeLocator;
135
+ property: string;
136
+ value: OperationValue;
137
+ }
138
+ export interface RewriteStep_SetStyleProperties extends RewriteStepBase {
139
+ type: "set-style-properties";
140
+ locator: JsxAttributeLocator;
141
+ properties: Record<string, OperationValue>;
142
+ }
143
+ export interface RewriteStep_SetCssModuleClass extends RewriteStepBase {
144
+ type: "set-css-module-class";
145
+ locator: JsxAttributeLocator;
146
+ from: string;
147
+ to: string;
148
+ }
149
+ export interface RewriteStep_SetDirective extends RewriteStepBase {
150
+ type: "set-directive";
151
+ mode: "add" | "update";
152
+ value: DirectiveLocator["value"];
153
+ currentValue?: DirectiveLocator["value"];
154
+ }
155
+ export interface RewriteStep_RemoveDirective extends RewriteStepBase {
156
+ type: "remove-directive";
157
+ value: DirectiveLocator["value"];
158
+ }
159
+ export interface RewriteStep_SetRouteExport extends RewriteStepBase {
160
+ type: "set-route-export";
161
+ name: Extract<ExportLocator, {
162
+ exportKind: "named";
163
+ }>["name"];
164
+ value: OperationValue;
165
+ }
166
+ export interface RewriteStep_SetMetadataField extends RewriteStepBase {
167
+ type: "set-metadata-field";
168
+ field: string;
169
+ value: OperationValue | null;
170
+ }
171
+ export interface RewriteStep_SetGenerateMetadata extends RewriteStepBase {
172
+ type: "set-generate-metadata";
173
+ field: string;
174
+ value: OperationValue | null;
175
+ }
176
+ export interface RewriteStep_InvokeExternalAdapter extends RewriteStepBase {
177
+ type: "invoke-external-adapter";
178
+ sourceType: ExternalSourceKind;
179
+ sourceId: string;
180
+ adapterId?: string;
181
+ capability?: ExternalAdapterCapability;
182
+ value: OperationValue;
183
+ }
184
+ export interface RewriteStep_AddImport extends RewriteStepBase {
185
+ type: "add-import";
186
+ moduleSpecifier: string;
187
+ imports: Array<{
188
+ kind: "named";
189
+ imported: string;
190
+ local?: string;
191
+ } | {
192
+ kind: "default";
193
+ local: string;
194
+ } | {
195
+ kind: "namespace";
196
+ local: string;
197
+ }>;
198
+ }
199
+ export interface RewriteStep_RemoveImport extends RewriteStepBase {
200
+ type: "remove-import";
201
+ moduleSpecifier: string;
202
+ imports: Array<{
203
+ kind: "named";
204
+ imported: string;
205
+ } | {
206
+ kind: "default";
207
+ } | {
208
+ kind: "namespace";
209
+ }>;
210
+ }
211
+ export interface FileSnapshot {
212
+ file: string;
213
+ content: string;
214
+ version: number;
215
+ }
216
+ export type ResolvedTextWriteTarget = {
217
+ kind: "value-binding";
218
+ file: string;
219
+ locator: ValueLocator | null;
220
+ root?: ValueRootSelector;
221
+ path?: ValuePathSegment[];
222
+ displayExpression: string;
223
+ sourceKind: "literal" | "binding" | "imported-binding" | "repeat-template";
224
+ collectionIndexMap?: number[];
225
+ collectionPathMap?: ValuePathSegment[][];
226
+ } | {
227
+ kind: "external-entry";
228
+ file: string;
229
+ sourceType: ExternalSourceKind;
230
+ sourceId: string;
231
+ adapterId?: string;
232
+ displayExpression: string;
233
+ };
234
+ export interface NodeCapabilitySnapshot {
235
+ key: string;
236
+ canUpdateText: boolean;
237
+ canRemove: boolean;
238
+ canInsertChild: boolean;
239
+ canMove: boolean;
240
+ constraints: string[];
241
+ }
242
+ /**
243
+ * RewritePlan = planner 的完整产物。
244
+ * writeback 接收到 plan 后按 steps 顺序执行。
245
+ */
246
+ export interface RewritePlan {
247
+ /** 操作唯一 ID */
248
+ operationId: string;
249
+ /** 操作类型 */
250
+ kind: OperationType;
251
+ /** 协议层目标 */
252
+ target: OperationTarget;
253
+ /** 请求时的文档版本号 */
254
+ documentVersion: number;
255
+ /** 按顺序执行的步骤 */
256
+ steps: RewriteStep[];
257
+ /** 涉及文件的快照(用于 rollback) */
258
+ preSnapshots: FileSnapshot[];
259
+ /** 经过校验的能力快照 */
260
+ validatedCapability?: NodeCapabilitySnapshot;
261
+ }
262
+ export type OperationResult = {
263
+ ok: true;
264
+ operationId: string;
265
+ resultVersion: number;
266
+ affectedFiles: string[];
267
+ } | {
268
+ ok: false;
269
+ operationId: string;
270
+ errorCode: OperationErrorCode;
271
+ reason: string;
272
+ rolledBack?: boolean;
273
+ };
274
+ export type OperationErrorCode = "stale-version" | "capability-denied" | "invalid-params" | "locator-miss" | "route-not-found" | "unsupported-operation" | "invalid-target" | "ast-error" | "writeback-failed" | "rollback-failed" | "unknown";
275
+ export {};
@@ -0,0 +1,6 @@
1
+ // ── RewritePlan / RewriteStep 形状 ─────────────────────────────
2
+ // 根文档 03 §4 定义:
3
+ // - RewritePlan 是 planner 的产物
4
+ // - RewriteStep 是执行形状,不是请求形状
5
+ // - writeback 不再反查 graph、不再把 request 重新解释
6
+ export {};
@@ -0,0 +1,10 @@
1
+ /**
2
+ * 边界种类 —— 标记节点所处的语义边界。
3
+ *
4
+ * - component-boundary: 组件调用边界
5
+ * - repeat-region: .map() / repeat 区域
6
+ * - conditional-region: 条件渲染区域
7
+ * - fragment-region: Fragment 包裹
8
+ * - opaque-region: 不透明 / 外部组件
9
+ */
10
+ export type BoundaryKind = "component-boundary" | "repeat-region" | "conditional-region" | "fragment-region" | "opaque-region";
@@ -0,0 +1,3 @@
1
+ // ─── Boundary 契约 ────────────────────────────────────
2
+ // 来源: docs/02-contracts-and-protocol.md §6.2
3
+ export {};
@@ -0,0 +1,47 @@
1
+ /**
2
+ * 节点能力快照 —— 描述该节点支持的操作及约束。
3
+ *
4
+ * 重要:canMove = true 意味着支持 reorder / reparent / cross-file move,
5
+ * 不能被收窄为 "只能同级上下移动"。
6
+ * canInsertChild = true 意味着支持 native-tag 和 component-call 插入,
7
+ * 不能被收窄为 "只能插入 button"。
8
+ */
9
+ export interface NodeCapabilitySnapshot {
10
+ key: string;
11
+ canUpdateText: boolean;
12
+ canInsertChild: boolean;
13
+ canMove: boolean;
14
+ canRemove: boolean;
15
+ editModes?: {
16
+ updateText?: CapabilityModeView;
17
+ insertChild?: CapabilityModeView;
18
+ move?: CapabilityModeView;
19
+ remove?: CapabilityModeView;
20
+ };
21
+ constraints: CapabilityConstraint[];
22
+ }
23
+ export interface CapabilityModeView {
24
+ mode: "direct" | "proxy" | "upstream" | "readonly" | "unsupported";
25
+ reasonCode?: string;
26
+ }
27
+ /**
28
+ * 能力约束 —— 描述为什么某个操作受限。
29
+ */
30
+ export interface CapabilityConstraint {
31
+ kind: ConstraintKind;
32
+ message: string;
33
+ }
34
+ /**
35
+ * 约束种类枚举。
36
+ *
37
+ * 每个 kind 对应一种语义限制:
38
+ * - component-boundary: 跨组件边界操作需要特殊处理
39
+ * - repeat-region: repeat/map 区域内的限制
40
+ * - conditional-region: 条件渲染区域限制
41
+ * - opaque-region: 不透明组件内部不可编辑
42
+ * - void-element: 自闭合元素不能有子节点
43
+ * - read-only: 只读数据源
44
+ * - cross-file-required: 操作需要跨文件协调
45
+ * - import-required: 组件插入需要添加 import
46
+ */
47
+ export type ConstraintKind = "component-boundary" | "repeat-region" | "conditional-region" | "opaque-region" | "void-element" | "read-only" | "cross-file-required" | "import-required";
@@ -0,0 +1,8 @@
1
+ // ─── Capability 契约 ──────────────────────────────────
2
+ // 来源: docs/02-contracts-and-protocol.md §4
3
+ //
4
+ // 关键约束:
5
+ // canMove 不能被解释为只有同级排序
6
+ // canInsertChild 不能被解释为只有 native tag
7
+ // repeat / boundary / opaque 的限制必须显式通过 constraint 返回
8
+ export {};
@@ -0,0 +1,43 @@
1
+ /**
2
+ * 操作错误码枚举 —— 覆盖从节点查找到写回的所有失败路径。
3
+ */
4
+ export declare enum OperationErrorCode {
5
+ /** 目标节点 key 在 graph 中不存在 */
6
+ NODE_NOT_FOUND = "NODE_NOT_FOUND",
7
+ /** 目标路由不存在 */
8
+ ROUTE_NOT_FOUND = "ROUTE_NOT_FOUND",
9
+ /** capability 检查拒绝(如 canMove = false) */
10
+ CAPABILITY_REJECTED = "CAPABILITY_REJECTED",
11
+ /** 约束违反(如试图往 void element 插入子节点) */
12
+ CONSTRAINT_VIOLATED = "CONSTRAINT_VIOLATED",
13
+ /** 请求参数不合法 */
14
+ INVALID_PARAMS = "INVALID_PARAMS",
15
+ /** planner 无法生成合法执行计划 */
16
+ PLAN_FAILED = "PLAN_FAILED",
17
+ /** documentVersion 过期 */
18
+ VERSION_STALE = "VERSION_STALE",
19
+ /** AST 解析失败 */
20
+ AST_PARSE_ERROR = "AST_PARSE_ERROR",
21
+ /** 操作在当前受支持语法形状外 */
22
+ UNSUPPORTED_OPERATION = "UNSUPPORTED_OPERATION",
23
+ /** NodeLocator 定位失败 */
24
+ LOCATOR_FAILED = "LOCATOR_FAILED",
25
+ /** 目标关系非法,例如无效父子关系或自闭合元素插子节点 */
26
+ INVALID_TARGET = "INVALID_TARGET",
27
+ /** 文件写入 I/O 错误 */
28
+ WRITE_IO_ERROR = "WRITE_IO_ERROR",
29
+ /** 并发修改冲突 */
30
+ CONCURRENT_MODIFIED = "CONCURRENT_MODIFIED",
31
+ /** 回滚失败 */
32
+ ROLLBACK_FAILED = "ROLLBACK_FAILED",
33
+ /** 内部错误 */
34
+ INTERNAL_ERROR = "INTERNAL_ERROR"
35
+ }
36
+ /**
37
+ * 操作错误 —— 附带错误码、消息和可选详情。
38
+ */
39
+ export interface OperationError {
40
+ code: OperationErrorCode;
41
+ message: string;
42
+ details?: Record<string, unknown>;
43
+ }
@@ -0,0 +1,38 @@
1
+ // ─── Error 契约 ───────────────────────────────────────
2
+ // 来源: docs/02-contracts-and-protocol.md §6.1
3
+ /**
4
+ * 操作错误码枚举 —— 覆盖从节点查找到写回的所有失败路径。
5
+ */
6
+ export var OperationErrorCode;
7
+ (function (OperationErrorCode) {
8
+ /** 目标节点 key 在 graph 中不存在 */
9
+ OperationErrorCode["NODE_NOT_FOUND"] = "NODE_NOT_FOUND";
10
+ /** 目标路由不存在 */
11
+ OperationErrorCode["ROUTE_NOT_FOUND"] = "ROUTE_NOT_FOUND";
12
+ /** capability 检查拒绝(如 canMove = false) */
13
+ OperationErrorCode["CAPABILITY_REJECTED"] = "CAPABILITY_REJECTED";
14
+ /** 约束违反(如试图往 void element 插入子节点) */
15
+ OperationErrorCode["CONSTRAINT_VIOLATED"] = "CONSTRAINT_VIOLATED";
16
+ /** 请求参数不合法 */
17
+ OperationErrorCode["INVALID_PARAMS"] = "INVALID_PARAMS";
18
+ /** planner 无法生成合法执行计划 */
19
+ OperationErrorCode["PLAN_FAILED"] = "PLAN_FAILED";
20
+ /** documentVersion 过期 */
21
+ OperationErrorCode["VERSION_STALE"] = "VERSION_STALE";
22
+ /** AST 解析失败 */
23
+ OperationErrorCode["AST_PARSE_ERROR"] = "AST_PARSE_ERROR";
24
+ /** 操作在当前受支持语法形状外 */
25
+ OperationErrorCode["UNSUPPORTED_OPERATION"] = "UNSUPPORTED_OPERATION";
26
+ /** NodeLocator 定位失败 */
27
+ OperationErrorCode["LOCATOR_FAILED"] = "LOCATOR_FAILED";
28
+ /** 目标关系非法,例如无效父子关系或自闭合元素插子节点 */
29
+ OperationErrorCode["INVALID_TARGET"] = "INVALID_TARGET";
30
+ /** 文件写入 I/O 错误 */
31
+ OperationErrorCode["WRITE_IO_ERROR"] = "WRITE_IO_ERROR";
32
+ /** 并发修改冲突 */
33
+ OperationErrorCode["CONCURRENT_MODIFIED"] = "CONCURRENT_MODIFIED";
34
+ /** 回滚失败 */
35
+ OperationErrorCode["ROLLBACK_FAILED"] = "ROLLBACK_FAILED";
36
+ /** 内部错误 */
37
+ OperationErrorCode["INTERNAL_ERROR"] = "INTERNAL_ERROR";
38
+ })(OperationErrorCode || (OperationErrorCode = {}));
@@ -0,0 +1,39 @@
1
+ import type { OperationResult } from "./operation.js";
2
+ import type { OperationError } from "./error.js";
3
+ /**
4
+ * 设计器事件联合类型 —— engine 向 client 推送的所有事件。
5
+ *
6
+ * - document-changed: 文档树结构或内容发生变更
7
+ * - operation-completed: 操作执行成功
8
+ * - operation-failed: 操作执行失败
9
+ * - graph-invalidated: graph 需要重建(如文件变更)
10
+ * - graph-ready: graph 重建完成
11
+ * - graph-error: graph 重建失败,但保留最近一次成功结果
12
+ * - capability-changed: 部分节点的 capability 发生变化
13
+ */
14
+ export type DesignerEvent = {
15
+ type: "document-changed";
16
+ routeId: string;
17
+ version: number;
18
+ } | {
19
+ type: "operation-completed";
20
+ result: OperationResult;
21
+ } | {
22
+ type: "operation-failed";
23
+ requestId: string;
24
+ error: OperationError;
25
+ } | {
26
+ type: "graph-invalidated";
27
+ routeId: string;
28
+ } | {
29
+ type: "graph-ready";
30
+ routeId: string;
31
+ version: number;
32
+ } | {
33
+ type: "graph-error";
34
+ routeId: string;
35
+ message: string;
36
+ } | {
37
+ type: "capability-changed";
38
+ keys: string[];
39
+ };
@@ -0,0 +1,3 @@
1
+ // ─── Event 契约 ───────────────────────────────────────
2
+ // 来源: docs/02-contracts-and-protocol.md §6.3
3
+ export {};
@@ -0,0 +1,26 @@
1
+ /**
2
+ * 唯一身份标识,贯穿 DOM → protocol → engine → bridge 全链路。
3
+ *
4
+ * key 是唯一语义 key,由 file / component / structuralPath 确定性生成。
5
+ * 不得携带 SourceRange —— 那是 engine 内部实现细节。
6
+ */
7
+ export interface SourceIdentity {
8
+ /** 源文件相对路径,如 "src/app/page.tsx" */
9
+ file: string;
10
+ /** 所属组件名,如 "HomePage" */
11
+ component: string;
12
+ /** 结构化路径,如 "div#0/span#1" */
13
+ structuralPath: string;
14
+ /** 唯一 key = "{file}::{component}::{structuralPath}" */
15
+ key: string;
16
+ }
17
+ /**
18
+ * 生成稳定的 SourceIdentity.key。
19
+ */
20
+ export declare function computeSourceIdentityKey(file: string, component: string, structuralPath: string): string;
21
+ /**
22
+ * 解析 SourceIdentity.key。
23
+ *
24
+ * structuralPath 允许包含分隔符,所以只切前两个段,余下部分全部并回 structuralPath。
25
+ */
26
+ export declare function parseSourceIdentityKey(key: string): Pick<SourceIdentity, "file" | "component" | "structuralPath"> | null;
@@ -0,0 +1,30 @@
1
+ // ─── 身份契约 ───────────────────────────────────────────
2
+ // 来源: docs/02-contracts-and-protocol.md §2
3
+ //
4
+ // 规则:
5
+ // key = "{file}::{component}::{structuralPath}"
6
+ // DOM / protocol / engine / bridge 全部统一使用 key
7
+ // SourceIdentity 不携带 SourceRange(SourceRange 是 engine-internal)
8
+ const SOURCE_IDENTITY_SEPARATOR = "::";
9
+ /**
10
+ * 生成稳定的 SourceIdentity.key。
11
+ */
12
+ export function computeSourceIdentityKey(file, component, structuralPath) {
13
+ return `${file}${SOURCE_IDENTITY_SEPARATOR}${component}${SOURCE_IDENTITY_SEPARATOR}${structuralPath}`;
14
+ }
15
+ /**
16
+ * 解析 SourceIdentity.key。
17
+ *
18
+ * structuralPath 允许包含分隔符,所以只切前两个段,余下部分全部并回 structuralPath。
19
+ */
20
+ export function parseSourceIdentityKey(key) {
21
+ const [file, component, ...pathParts] = key.split(SOURCE_IDENTITY_SEPARATOR);
22
+ if (!file || !component || pathParts.length === 0) {
23
+ return null;
24
+ }
25
+ return {
26
+ file,
27
+ component,
28
+ structuralPath: pathParts.join(SOURCE_IDENTITY_SEPARATOR),
29
+ };
30
+ }