eventmodeler 0.3.2 → 0.3.4

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.
package/dist/index.js CHANGED
@@ -36,6 +36,9 @@ import { createAutomationSlice } from './slices/create-automation-slice/index.js
36
36
  import { createStateViewSlice } from './slices/create-state-view-slice/index.js';
37
37
  import { createFlow } from './slices/create-flow/index.js';
38
38
  import { codegenSlice } from './slices/codegen-slice/index.js';
39
+ import { diff } from './slices/diff/index.js';
40
+ import { merge } from './slices/merge/index.js';
41
+ import { gitSetup, gitStatus } from './slices/git/index.js';
39
42
  const args = process.argv.slice(2);
40
43
  function getNamedArg(argList, ...names) {
41
44
  for (let i = 0; i < argList.length; i++) {
@@ -109,6 +112,22 @@ COMMANDS:
109
112
 
110
113
  export json Export entire model as JSON
111
114
 
115
+ GIT INTEGRATION:
116
+ git setup Configure git to use semantic diff/merge for .eventmodel files
117
+ git setup --global Configure globally (for all repos)
118
+ git status Show git integration status
119
+
120
+ diff <file1> <file2> Compare two event model files semantically
121
+ diff <file> [--ref <gitref>] Compare working copy against git ref (default: HEAD)
122
+ diff ... --format text Human-readable output (default for git)
123
+ diff ... --format xml|json Structured output
124
+
125
+ merge --base <file> --ours <file> --theirs <file> --output <file>
126
+ Three-way merge of event model files
127
+ merge ... --strategy ours|theirs
128
+ Auto-resolve conflicts with given strategy
129
+ merge ... --dry-run Show conflicts without writing output
130
+
112
131
  OPTIONS:
113
132
  -f, --file <path> Path to .eventmodel file (default: auto-detect)
114
133
  --format <xml|json> Output format (default: xml, or from config)
@@ -174,6 +193,83 @@ async function main() {
174
193
  openApp();
175
194
  return;
176
195
  }
196
+ // Handle diff and merge commands separately (they manage their own file loading)
197
+ if (command === 'diff') {
198
+ const baseArg = getNamedArg(filteredArgs, '--base');
199
+ const compareArg = getNamedArg(filteredArgs, '--compare');
200
+ const refArg = getNamedArg(filteredArgs, '--ref');
201
+ // Diff supports 'text' format in addition to xml/json
202
+ const diffFormat = formatArg === 'json' ? 'json'
203
+ : formatArg === 'xml' ? 'xml'
204
+ : formatArg === 'text' ? 'text'
205
+ : 'text'; // Default to text for human-readable output
206
+ // Two-file mode: diff file1 file2 OR diff --base file1 --compare file2
207
+ if (baseArg && compareArg) {
208
+ diff(baseArg, compareArg, diffFormat);
209
+ return;
210
+ }
211
+ // Positional args: diff file1 file2
212
+ const file1 = filteredArgs[1];
213
+ const file2 = filteredArgs[2];
214
+ if (file1 && file2 && !file1.startsWith('--') && !file2.startsWith('--')) {
215
+ diff(file1, file2, diffFormat);
216
+ return;
217
+ }
218
+ // Single file mode: diff file [--ref HEAD]
219
+ if (file1 && !file1.startsWith('--')) {
220
+ diff(file1, undefined, diffFormat, refArg);
221
+ return;
222
+ }
223
+ console.error('Usage: eventmodeler diff <file1> <file2>');
224
+ console.error(' eventmodeler diff <file> [--ref <gitref>]');
225
+ console.error(' eventmodeler diff --base <file> --compare <file>');
226
+ process.exit(1);
227
+ }
228
+ if (command === 'merge') {
229
+ const baseArg = getNamedArg(filteredArgs, '--base');
230
+ const oursArg = getNamedArg(filteredArgs, '--ours');
231
+ const theirsArg = getNamedArg(filteredArgs, '--theirs');
232
+ const outputArg = getNamedArg(filteredArgs, '--output');
233
+ const strategyArg = getNamedArg(filteredArgs, '--strategy');
234
+ const dryRun = filteredArgs.includes('--dry-run');
235
+ if (!baseArg || !oursArg || !theirsArg) {
236
+ console.error('Usage: eventmodeler merge --base <file> --ours <file> --theirs <file> --output <file>');
237
+ console.error('Options:');
238
+ console.error(' --strategy ours|theirs Auto-resolve conflicts');
239
+ console.error(' --dry-run Show result without writing');
240
+ process.exit(1);
241
+ }
242
+ if (!outputArg && !dryRun) {
243
+ console.error('Error: --output is required (or use --dry-run)');
244
+ process.exit(1);
245
+ }
246
+ merge({
247
+ basePath: baseArg,
248
+ oursPath: oursArg,
249
+ theirsPath: theirsArg,
250
+ outputPath: outputArg ?? '',
251
+ strategy: strategyArg === 'ours' || strategyArg === 'theirs' ? strategyArg : undefined,
252
+ dryRun,
253
+ format,
254
+ });
255
+ return;
256
+ }
257
+ if (command === 'git') {
258
+ const gitCommand = filteredArgs[1];
259
+ const globalFlag = filteredArgs.includes('--global');
260
+ switch (gitCommand) {
261
+ case 'setup':
262
+ gitSetup(globalFlag);
263
+ return;
264
+ case 'status':
265
+ gitStatus();
266
+ return;
267
+ default:
268
+ console.error('Usage: eventmodeler git setup [--global]');
269
+ console.error(' eventmodeler git status');
270
+ process.exit(1);
271
+ }
272
+ }
177
273
  const filePath = fileArg ?? await findEventModelFile();
178
274
  if (!filePath) {
179
275
  console.error('Error: No .eventmodel file found in current directory.');
@@ -0,0 +1,45 @@
1
+ /**
2
+ * Merge rules for Event Model conflicts.
3
+ *
4
+ * Based on analysis of user workflows, these rules define how to handle
5
+ * different types of conflicts when merging two branches.
6
+ */
7
+ import type { EntityChange, FieldChange } from './types.js';
8
+ export type ConflictResolution = {
9
+ type: 'auto';
10
+ action: string;
11
+ } | {
12
+ type: 'soft';
13
+ reason: string;
14
+ } | {
15
+ type: 'hard';
16
+ reason: string;
17
+ };
18
+ /**
19
+ * Determine how to resolve a property conflict.
20
+ */
21
+ export declare function resolvePropertyConflict(property: string, oursValue: unknown, theirsValue: unknown, entityType: string): ConflictResolution;
22
+ /**
23
+ * Determine how to resolve a field conflict.
24
+ */
25
+ export declare function resolveFieldConflict(oursChange: FieldChange, theirsChange: FieldChange): ConflictResolution;
26
+ /**
27
+ * Merge two arrays (e.g., nodeIds) removing duplicates.
28
+ */
29
+ export declare function mergeArrays<T>(base: T[], ours: T[], theirs: T[]): T[];
30
+ /**
31
+ * Check if an entity change affects only layout properties.
32
+ */
33
+ export declare function isLayoutOnlyChange(change: EntityChange): boolean;
34
+ /**
35
+ * Categorize fields changes for merge.
36
+ */
37
+ export declare function categorizeFieldChanges(oursChanges: FieldChange[], theirsChanges: FieldChange[]): {
38
+ oursOnly: FieldChange[];
39
+ theirsOnly: FieldChange[];
40
+ conflicts: Array<{
41
+ ours: FieldChange;
42
+ theirs: FieldChange;
43
+ resolution: ConflictResolution;
44
+ }>;
45
+ };
@@ -0,0 +1,210 @@
1
+ /**
2
+ * Merge rules for Event Model conflicts.
3
+ *
4
+ * Based on analysis of user workflows, these rules define how to handle
5
+ * different types of conflicts when merging two branches.
6
+ */
7
+ /**
8
+ * Slice status priority order.
9
+ * Higher priority wins in auto-resolution.
10
+ */
11
+ const SLICE_STATUS_PRIORITY = {
12
+ 'done': 4,
13
+ 'in-progress': 3,
14
+ 'blocked': 2,
15
+ 'created': 1,
16
+ };
17
+ /**
18
+ * Properties that can be auto-resolved with last-write-wins.
19
+ * These are layout/visual properties that don't affect semantics.
20
+ */
21
+ const LAYOUT_PROPERTIES = new Set([
22
+ 'position',
23
+ 'width',
24
+ 'height',
25
+ 'size',
26
+ 'x',
27
+ 'y',
28
+ ]);
29
+ /**
30
+ * Determine how to resolve a property conflict.
31
+ */
32
+ export function resolvePropertyConflict(property, oursValue, theirsValue, entityType) {
33
+ // Layout properties: auto-resolve with theirs (last-write-wins)
34
+ if (LAYOUT_PROPERTIES.has(property)) {
35
+ return { type: 'auto', action: 'layout-use-theirs' };
36
+ }
37
+ // Slice status: use priority order
38
+ if (property === 'status' && entityType === 'slice') {
39
+ const oursPriority = SLICE_STATUS_PRIORITY[oursValue] ?? 0;
40
+ const theirsPriority = SLICE_STATUS_PRIORITY[theirsValue] ?? 0;
41
+ if (oursPriority >= theirsPriority) {
42
+ return { type: 'auto', action: 'status-priority-ours' };
43
+ }
44
+ else {
45
+ return { type: 'auto', action: 'status-priority-theirs' };
46
+ }
47
+ }
48
+ // Name conflicts: hard conflict
49
+ if (property === 'name') {
50
+ return { type: 'hard', reason: `Both renamed to different values` };
51
+ }
52
+ // nodeIds/eventIds/screenIds: can merge (include both)
53
+ if (property === 'nodeIds' || property === 'eventIds' || property === 'screenIds') {
54
+ return { type: 'auto', action: 'merge-arrays' };
55
+ }
56
+ // Scenario parts: hard conflict
57
+ if (property === 'givenEvents' || property === 'whenCommand' || property === 'then' || property === 'description') {
58
+ return { type: 'hard', reason: `Both modified ${property}` };
59
+ }
60
+ // Default: hard conflict
61
+ return { type: 'hard', reason: `Both modified ${property}` };
62
+ }
63
+ /**
64
+ * Determine how to resolve a field conflict.
65
+ */
66
+ export function resolveFieldConflict(oursChange, theirsChange) {
67
+ const fieldPath = oursChange.fieldPath;
68
+ // Both added same field
69
+ if (oursChange.changeType === 'added' && theirsChange.changeType === 'added') {
70
+ const oursField = oursChange.newValue;
71
+ const theirsField = theirsChange.newValue;
72
+ // Same type: auto-resolve (keep one)
73
+ if (oursField && theirsField && fieldsCompatible(oursField, theirsField)) {
74
+ return { type: 'auto', action: 'both-added-compatible' };
75
+ }
76
+ // Different types: hard conflict
77
+ return { type: 'hard', reason: `Both added field "${fieldPath}" with different types` };
78
+ }
79
+ // Both removed same field
80
+ if (oursChange.changeType === 'removed' && theirsChange.changeType === 'removed') {
81
+ return { type: 'auto', action: 'both-removed' };
82
+ }
83
+ // One removed, other modified
84
+ if ((oursChange.changeType === 'removed' && theirsChange.changeType === 'modified') ||
85
+ (oursChange.changeType === 'modified' && theirsChange.changeType === 'removed')) {
86
+ return { type: 'hard', reason: `Field "${fieldPath}": one removed, other modified` };
87
+ }
88
+ // Both modified same field
89
+ if (oursChange.changeType === 'modified' && theirsChange.changeType === 'modified') {
90
+ const oursField = oursChange.newValue;
91
+ const theirsField = theirsChange.newValue;
92
+ // Same change: auto-resolve
93
+ if (oursField && theirsField && fieldsEqual(oursField, theirsField)) {
94
+ return { type: 'auto', action: 'both-modified-identically' };
95
+ }
96
+ // Different changes: hard conflict
97
+ return { type: 'hard', reason: `Both modified field "${fieldPath}" differently` };
98
+ }
99
+ return { type: 'hard', reason: `Unexpected field conflict on "${fieldPath}"` };
100
+ }
101
+ /**
102
+ * Check if two fields are semantically equal.
103
+ */
104
+ function fieldsEqual(a, b) {
105
+ if (a.name !== b.name)
106
+ return false;
107
+ if (a.fieldType !== b.fieldType)
108
+ return false;
109
+ if (a.isList !== b.isList)
110
+ return false;
111
+ if (a.isGenerated !== b.isGenerated)
112
+ return false;
113
+ if (a.isOptional !== b.isOptional)
114
+ return false;
115
+ if (a.isUserInput !== b.isUserInput)
116
+ return false;
117
+ // Compare subfields
118
+ const aSubfields = a.subfields ?? [];
119
+ const bSubfields = b.subfields ?? [];
120
+ if (aSubfields.length !== bSubfields.length)
121
+ return false;
122
+ for (let i = 0; i < aSubfields.length; i++) {
123
+ if (!fieldsEqual(aSubfields[i], bSubfields[i]))
124
+ return false;
125
+ }
126
+ return true;
127
+ }
128
+ /**
129
+ * Check if two fields are compatible (can be merged).
130
+ * Compatible means same name and type, even if other properties differ.
131
+ */
132
+ function fieldsCompatible(a, b) {
133
+ if (a.name !== b.name)
134
+ return false;
135
+ if (a.fieldType !== b.fieldType)
136
+ return false;
137
+ if (a.isList !== b.isList)
138
+ return false;
139
+ return true;
140
+ }
141
+ /**
142
+ * Merge two arrays (e.g., nodeIds) removing duplicates.
143
+ */
144
+ export function mergeArrays(base, ours, theirs) {
145
+ const baseSet = new Set(base);
146
+ const result = new Set(base);
147
+ // Add items from ours that weren't in base
148
+ for (const item of ours) {
149
+ if (!baseSet.has(item)) {
150
+ result.add(item);
151
+ }
152
+ }
153
+ // Add items from theirs that weren't in base
154
+ for (const item of theirs) {
155
+ if (!baseSet.has(item)) {
156
+ result.add(item);
157
+ }
158
+ }
159
+ // Remove items deleted in ours
160
+ for (const item of base) {
161
+ if (!ours.includes(item)) {
162
+ result.delete(item);
163
+ }
164
+ }
165
+ // Remove items deleted in theirs
166
+ for (const item of base) {
167
+ if (!theirs.includes(item)) {
168
+ result.delete(item);
169
+ }
170
+ }
171
+ return [...result];
172
+ }
173
+ /**
174
+ * Check if an entity change affects only layout properties.
175
+ */
176
+ export function isLayoutOnlyChange(change) {
177
+ if (change.changeType !== 'modified')
178
+ return false;
179
+ if (change.fieldChanges && change.fieldChanges.length > 0)
180
+ return false;
181
+ if (!change.propertyChanges)
182
+ return true;
183
+ return change.propertyChanges.every(p => LAYOUT_PROPERTIES.has(p.property));
184
+ }
185
+ /**
186
+ * Categorize fields changes for merge.
187
+ */
188
+ export function categorizeFieldChanges(oursChanges, theirsChanges) {
189
+ const oursMap = new Map(oursChanges.map(c => [c.fieldPath, c]));
190
+ const theirsMap = new Map(theirsChanges.map(c => [c.fieldPath, c]));
191
+ const oursOnly = [];
192
+ const theirsOnly = [];
193
+ const conflicts = [];
194
+ for (const [path, oursChange] of oursMap) {
195
+ const theirsChange = theirsMap.get(path);
196
+ if (theirsChange) {
197
+ const resolution = resolveFieldConflict(oursChange, theirsChange);
198
+ conflicts.push({ ours: oursChange, theirs: theirsChange, resolution });
199
+ }
200
+ else {
201
+ oursOnly.push(oursChange);
202
+ }
203
+ }
204
+ for (const [path, theirsChange] of theirsMap) {
205
+ if (!oursMap.has(path)) {
206
+ theirsOnly.push(theirsChange);
207
+ }
208
+ }
209
+ return { oursOnly, theirsOnly, conflicts };
210
+ }
@@ -0,0 +1,8 @@
1
+ import type { EventModel } from '../../types.js';
2
+ import type { DiffResult, EntityChange, FieldChange, FlowChange } from './types.js';
3
+ /**
4
+ * Compare two EventModels and return semantic differences.
5
+ * Ignores layout properties (position, size) and linked copies.
6
+ */
7
+ export declare function diffModels(baseModel: EventModel, compareModel: EventModel): DiffResult;
8
+ export type { DiffResult, EntityChange, FieldChange, FlowChange };