@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,3 @@
1
+ export { createEditEngineRuntime, EditEngineRuntime, } from "./runtime/EditEngineRuntime.js";
2
+ export type { IEditEngineRuntime } from "./contracts/IEditEngineRuntime.js";
3
+ export type { EditEngineRuntimeOptions, ExternalSourceResolver, ExternalWritebackAdapter, FunctionCallContract, ProjectFileSystem, RuntimeRouteConfig, } from "./runtime/EditEngineRuntimeSnapshot.js";
@@ -0,0 +1 @@
1
+ export { createEditEngineRuntime, EditEngineRuntime, } from "./runtime/EditEngineRuntime.js";
@@ -0,0 +1,6 @@
1
+ import type { RenderSourceGraph } from "../graph/types.js";
2
+ import type { EditableTopology } from "./types.js";
3
+ /**
4
+ * 从渲染源图构建可编辑拓扑。
5
+ */
6
+ export declare function buildEditableTopology(renderGraph: RenderSourceGraph): EditableTopology;
@@ -0,0 +1,98 @@
1
+ // ─── Topology Builder ────────────────────────────────
2
+ // 来源: docs/06-development-checklist.md §5
3
+ //
4
+ // 从 RenderSourceGraph 构建 EditableTopology。
5
+ // 职责:
6
+ // - 计算 writeTarget(处理 component boundary 代理写回)
7
+ // - 标记 boundary regions
8
+ // - 收集 constraints(repeat/conditional/opaque/component-boundary)
9
+ //
10
+ // 关键约束:
11
+ // - canMove / canInsertChild 不能被误算成 same-file only
12
+ // - repeat/template 节点的限制必须显式通过 constraint 返回
13
+ /**
14
+ * 从渲染源图构建可编辑拓扑。
15
+ */
16
+ export function buildEditableTopology(renderGraph) {
17
+ const nodes = new Map();
18
+ // Build topology node for each element
19
+ for (const [key, element] of renderGraph.elements) {
20
+ const isComponent = /^[A-Z]/.test(element.tag);
21
+ // Compute writeTarget
22
+ const writeTarget = {
23
+ file: element.sourceFile,
24
+ componentName: element.componentName,
25
+ isProxy: isComponent, // component calls are proxies
26
+ };
27
+ // Determine boundary kind
28
+ const boundaryKind = element.boundaryKind;
29
+ // Collect constraints
30
+ const constraints = [];
31
+ // Opaque component constraint
32
+ if (element.isOpaque) {
33
+ constraints.push({
34
+ kind: "opaque-region",
35
+ reason: `Component '${element.tag}' is opaque: internal structure not editable`,
36
+ });
37
+ }
38
+ // Component boundary constraint
39
+ if (isComponent && !element.isOpaque) {
40
+ constraints.push({
41
+ kind: "component-boundary",
42
+ reason: `Component '${element.tag}' boundary: editing requires source file access`,
43
+ });
44
+ }
45
+ const topologyNode = {
46
+ key,
47
+ writeTarget,
48
+ boundaryKind,
49
+ parentKey: element.parentKey,
50
+ childKeys: [...element.childKeys],
51
+ constraints,
52
+ };
53
+ nodes.set(key, topologyNode);
54
+ }
55
+ // Add region-based constraints
56
+ for (const region of renderGraph.regions) {
57
+ const constraintKind = region.kind === "repeat-region"
58
+ ? "repeat-region"
59
+ : region.kind === "conditional-region"
60
+ ? "conditional-region"
61
+ : region.kind === "opaque-region"
62
+ ? "opaque-region"
63
+ : "component-boundary";
64
+ const reason = region.kind === "repeat-region"
65
+ ? "Node is inside a repeat region: operations affect the template, not individual instances"
66
+ : region.kind === "conditional-region"
67
+ ? "Node is inside a conditional region: visibility depends on runtime condition"
68
+ : `Node is inside a ${region.kind}`;
69
+ // Add constraint to all child keys in this region
70
+ for (const childKey of region.childKeys) {
71
+ const node = nodes.get(childKey);
72
+ if (node) {
73
+ node.constraints.push({ kind: constraintKind, reason });
74
+ }
75
+ // Also propagate to descendants of this child
76
+ propagateRegionConstraint(childKey, constraintKind, reason, nodes, renderGraph);
77
+ }
78
+ }
79
+ return {
80
+ nodes,
81
+ rootKeys: [...renderGraph.rootKeys],
82
+ };
83
+ }
84
+ /**
85
+ * 递归向下传播区域约束。
86
+ */
87
+ function propagateRegionConstraint(parentKey, kind, reason, nodes, graph) {
88
+ const element = graph.elements.get(parentKey);
89
+ if (!element)
90
+ return;
91
+ for (const childKey of element.childKeys) {
92
+ const childNode = nodes.get(childKey);
93
+ if (childNode && !childNode.constraints.some((c) => c.kind === kind)) {
94
+ childNode.constraints.push({ kind, reason });
95
+ propagateRegionConstraint(childKey, kind, reason, nodes, graph);
96
+ }
97
+ }
98
+ }
@@ -0,0 +1,35 @@
1
+ import type { BoundaryKind, ConstraintKind } from "../protocol.js";
2
+ /**
3
+ * 拓扑节点 —— 描述一个节点在可编辑拓扑中的位置和特性。
4
+ */
5
+ export interface TopologyNode {
6
+ key: string;
7
+ /** 写回的目标文件(可能与 sourceFile 不同,如 component boundary 场景) */
8
+ writeTarget: WriteTarget;
9
+ /** 所属边界类型 */
10
+ boundaryKind: BoundaryKind | null;
11
+ /** 父节点 key */
12
+ parentKey: string | null;
13
+ /** 子节点 keys */
14
+ childKeys: string[];
15
+ /** 此节点的约束 */
16
+ constraints: Array<{
17
+ kind: ConstraintKind;
18
+ reason: string;
19
+ }>;
20
+ }
21
+ /**
22
+ * 写回目标 —— 描述实际写回的文件和位置。
23
+ */
24
+ export interface WriteTarget {
25
+ file: string;
26
+ componentName: string;
27
+ isProxy: boolean;
28
+ }
29
+ /**
30
+ * 可编辑拓扑 —— 完整的拓扑视图。
31
+ */
32
+ export interface EditableTopology {
33
+ nodes: Map<string, TopologyNode>;
34
+ rootKeys: string[];
35
+ }
@@ -0,0 +1,5 @@
1
+ // ─── Topology 模块类型 ───────────────────────────────
2
+ // 来源: docs/06-development-checklist.md §5
3
+ //
4
+ // topology 从 graph 计算可编辑拓扑。
5
+ export {};
@@ -0,0 +1 @@
1
+ export type { SiteEditProjectFileSystem as ProjectFileSystem } from "../public-file-system.js";
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,7 @@
1
+ import type { ProjectFileSystem } from "./types.js";
2
+ export declare function createInMemoryFileSystem(initialFiles?: Record<string, string>): ProjectFileSystem & {
3
+ /** 同步版本的 readFile(测试中断言用) */
4
+ readFileSync(file: string): string;
5
+ /** 获取所有文件内容 */
6
+ getAll(): Record<string, string>;
7
+ };
@@ -0,0 +1,44 @@
1
+ // ── InMemoryFileSystem ─────────────────────────────────────────
2
+ // 用于测试的内存文件系统实现。
3
+ // Layer 1/2 测试不依赖真实 FS。
4
+ export function createInMemoryFileSystem(initialFiles = {}) {
5
+ const files = new Map(Object.entries(initialFiles));
6
+ const versions = new Map();
7
+ // 初始化版本号
8
+ for (const file of files.keys()) {
9
+ versions.set(file, 1);
10
+ }
11
+ return {
12
+ async readFile(file) {
13
+ const content = files.get(file);
14
+ if (content === undefined) {
15
+ throw new Error(`File not found: ${file}`);
16
+ }
17
+ return content;
18
+ },
19
+ async writeFile(file, content) {
20
+ files.set(file, content);
21
+ },
22
+ async exists(file) {
23
+ return files.has(file);
24
+ },
25
+ getVersion(file) {
26
+ return versions.get(file) ?? 0;
27
+ },
28
+ bumpVersion(file) {
29
+ const v = (versions.get(file) ?? 0) + 1;
30
+ versions.set(file, v);
31
+ return v;
32
+ },
33
+ readFileSync(file) {
34
+ const content = files.get(file);
35
+ if (content === undefined) {
36
+ throw new Error(`File not found: ${file}`);
37
+ }
38
+ return content;
39
+ },
40
+ getAll() {
41
+ return Object.fromEntries(files);
42
+ },
43
+ };
44
+ }
@@ -0,0 +1,45 @@
1
+ import type { FileSnapshot, OperationResult, RewritePlan } from "../planner/types.js";
2
+ import type { RewriteStep_InvokeExternalAdapter } from "../planner/types.js";
3
+ import type { ExternalAdapterCapability, ExternalSourceKind } from "../provenance/types.js";
4
+ export type { ProjectFileSystem } from "../types.js";
5
+ export type { FileSnapshot } from "../planner/types.js";
6
+ export type WritebackResult = {
7
+ ok: true;
8
+ /** 变更后各文件的最新内容 */
9
+ updatedFiles: Map<string, string>;
10
+ /** 新的文档版本号 */
11
+ resultVersion: number;
12
+ } | {
13
+ ok: false;
14
+ reason: string;
15
+ /** 是否已成功回滚 */
16
+ rolledBack: boolean;
17
+ };
18
+ /** 一次操作的 undo 记录 */
19
+ export interface UndoEntry {
20
+ operationId: string;
21
+ /** 执行前的文件快照 */
22
+ preSnapshots: FileSnapshot[];
23
+ /** 执行后的文件快照 */
24
+ postSnapshots: FileSnapshot[];
25
+ /** 操作的 plan(用于 redo 时重放) */
26
+ plan: RewritePlan;
27
+ }
28
+ export interface WritebackService {
29
+ execute(plan: RewritePlan): Promise<OperationResult>;
30
+ undo(): Promise<OperationResult>;
31
+ redo(): Promise<OperationResult>;
32
+ }
33
+ export interface ExternalAdapterResult {
34
+ ok: boolean;
35
+ reason?: string;
36
+ }
37
+ export interface ExternalWritebackAdapter {
38
+ sourceType: ExternalSourceKind;
39
+ adapterId?: string;
40
+ capabilities?: ExternalAdapterCapability[];
41
+ execute(step: RewriteStep_InvokeExternalAdapter): Promise<ExternalAdapterResult>;
42
+ }
43
+ export interface WritebackServiceOptions {
44
+ externalAdapters?: ExternalWritebackAdapter[];
45
+ }
@@ -0,0 +1,7 @@
1
+ // ── Writeback / Undo / Redo 类型 ──────────────────────────────
2
+ // 根文档 03 §5 定义:
3
+ // - 先做 documentVersion stale check
4
+ // - 按 steps[].order 顺序执行
5
+ // - 任一步失败,按 preSnapshots 回滚
6
+ // - Undo/Redo 基于 operation-level snapshot
7
+ export {};
@@ -0,0 +1,7 @@
1
+ import type { RewritePlan, OperationResult } from "../planner/types.js";
2
+ import type { ProjectFileSystem, WritebackServiceOptions } from "./types.js";
3
+ export declare function createWritebackService(fs: ProjectFileSystem, options?: WritebackServiceOptions): {
4
+ execute: (plan: RewritePlan) => Promise<OperationResult>;
5
+ undo: () => Promise<OperationResult>;
6
+ redo: () => Promise<OperationResult>;
7
+ };