@shapeshift-labs/frontier-lang-compiler 0.2.91 → 0.2.93

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/README.md CHANGED
@@ -933,6 +933,7 @@ The published Frontier package family is generated from one shared package catal
933
933
  - [`@shapeshift-labs/frontier-realtime-server`](https://www.npmjs.com/package/@shapeshift-labs/frontier-realtime-server): Authoritative realtime room, tick, command validation, rate-limit, session, and snapshot-history runtime.
934
934
  - [`@shapeshift-labs/frontier-realtime-websocket`](https://www.npmjs.com/package/@shapeshift-labs/frontier-realtime-websocket): WebSocket client, wire, and Node room-server transport for Frontier realtime.
935
935
  - [`@shapeshift-labs/frontier-game`](https://www.npmjs.com/package/@shapeshift-labs/frontier-game): Game-facing entity, component, player, room, ownership, spatial interest, rollback, physics, and replication helpers above realtime.
936
+ - [`@shapeshift-labs/loom`](https://www.npmjs.com/package/@shapeshift-labs/loom): Repo-level semantic collaboration CLI for .loom workspaces, including init, scan, status, graph snapshots, projection plans, Frontier Lang delegation, Frontier Swarm delegation, and Frontier Framework delegation.
936
937
 
937
938
  Package source repositories:
938
939
 
@@ -1026,3 +1027,4 @@ Package source repositories:
1026
1027
  - [`siliconjungle/-shapeshift-labs-frontier-realtime-server`](https://github.com/siliconjungle/-shapeshift-labs-frontier-realtime-server)
1027
1028
  - [`siliconjungle/-shapeshift-labs-frontier-realtime-websocket`](https://github.com/siliconjungle/-shapeshift-labs-frontier-realtime-websocket)
1028
1029
  - [`siliconjungle/-shapeshift-labs-frontier-game`](https://github.com/siliconjungle/-shapeshift-labs-frontier-game)
1030
+ - [`siliconjungle/-shapeshift-labs-loom`](https://github.com/siliconjungle/-shapeshift-labs-loom)
@@ -191,6 +191,71 @@ export interface SemanticEditProjection {
191
191
  readonly metadata?: Record<string, unknown>;
192
192
  }
193
193
 
194
+ export type SemanticEditReplayStatus =
195
+ | 'accepted-clean'
196
+ | 'already-applied'
197
+ | 'conflict'
198
+ | 'stale'
199
+ | 'blocked'
200
+ | 'needs-port'
201
+ | 'evidence-only';
202
+
203
+ export interface SemanticEditReplayEdit {
204
+ readonly operationId?: string;
205
+ readonly semanticKey?: string;
206
+ readonly semanticIdentityHash?: string;
207
+ readonly sourceIdentityHash?: string;
208
+ readonly editContentHash?: string;
209
+ readonly sourcePath?: string;
210
+ readonly symbolName?: string;
211
+ readonly symbolKind?: string;
212
+ readonly status: 'applied' | 'already-applied' | 'conflict' | 'stale' | 'blocked' | string;
213
+ readonly start?: number;
214
+ readonly end?: number;
215
+ readonly replacementBytes?: number;
216
+ readonly replacementText?: string;
217
+ readonly reasonCodes: readonly string[];
218
+ }
219
+
220
+ export interface SemanticEditReplay {
221
+ readonly kind: 'frontier.lang.semanticEditReplay';
222
+ readonly version: 1;
223
+ readonly schema: 'frontier.lang.semanticEditReplay.v1';
224
+ readonly id: string;
225
+ readonly hash: string;
226
+ readonly projectionId?: string;
227
+ readonly scriptId?: string;
228
+ readonly sourcePath?: string;
229
+ readonly language?: FrontierSourceLanguage | string;
230
+ readonly currentHash?: string;
231
+ readonly projectedHash?: string;
232
+ readonly outputHash?: string;
233
+ readonly status: SemanticEditReplayStatus;
234
+ readonly edits: readonly SemanticEditReplayEdit[];
235
+ readonly appliedOperations: readonly string[];
236
+ readonly skippedOperations: readonly string[];
237
+ readonly admission: {
238
+ readonly status: SemanticEditReplayStatus;
239
+ readonly action: 'apply' | 'skip' | 'rerun-semantic-import' | 'human-review' | 'block' | string;
240
+ readonly reviewRequired: boolean;
241
+ readonly autoApplyCandidate: boolean;
242
+ readonly autoMergeClaim: false;
243
+ readonly semanticEquivalenceClaim: false;
244
+ readonly reasonCodes: readonly string[];
245
+ };
246
+ readonly outputSourceText?: string;
247
+ readonly summary: {
248
+ readonly edits: number;
249
+ readonly applied: number;
250
+ readonly alreadyApplied: number;
251
+ readonly conflicts: number;
252
+ readonly stale: number;
253
+ readonly blocked: number;
254
+ readonly reasonCodes: readonly string[];
255
+ };
256
+ readonly metadata?: Record<string, unknown>;
257
+ }
258
+
194
259
  export interface ProjectSemanticEditScriptToSourceOptions {
195
260
  readonly id?: string;
196
261
  readonly script: SemanticEditScript;
@@ -200,6 +265,17 @@ export interface ProjectSemanticEditScriptToSourceOptions {
200
265
  readonly metadata?: Record<string, unknown>;
201
266
  }
202
267
 
268
+ export interface ReplaySemanticEditProjectionOptions {
269
+ readonly id?: string;
270
+ readonly projection: SemanticEditProjection;
271
+ readonly currentSourceText: string;
272
+ readonly currentSourcePath?: string;
273
+ readonly currentSourceHash?: string;
274
+ readonly language?: FrontierSourceLanguage | string;
275
+ readonly parser?: string;
276
+ readonly metadata?: Record<string, unknown>;
277
+ }
278
+
203
279
  export interface CreateSemanticEditScriptOptions {
204
280
  readonly id?: string;
205
281
  readonly language?: FrontierSourceLanguage | string;
@@ -229,3 +305,4 @@ export interface CreateSemanticEditScriptOptions {
229
305
  export declare const SemanticEditScriptAdmissionStatuses: readonly SemanticEditScriptAdmissionStatus[];
230
306
  export declare function createSemanticEditScript(input?: CreateSemanticEditScriptOptions): SemanticEditScript;
231
307
  export declare function projectSemanticEditScriptToSource(input: ProjectSemanticEditScriptToSourceOptions): SemanticEditProjection;
308
+ export declare function replaySemanticEditProjection(input: ReplaySemanticEditProjectionOptions): SemanticEditReplay;
@@ -0,0 +1,43 @@
1
+ export interface SemanticPatchBundleRecordIndex {
2
+ readonly baseHashes: readonly string[];
3
+ readonly targetHashes: readonly string[];
4
+ readonly sourceHashes: readonly string[];
5
+ readonly sourcePaths: readonly string[];
6
+ readonly regionKeys: readonly string[];
7
+ readonly regionKinds: readonly string[];
8
+ readonly conflictKeys: readonly string[];
9
+ readonly sourceMapIds: readonly string[];
10
+ readonly sourceMapMappingIds: readonly string[];
11
+ readonly sourceMapLinkIds: readonly string[];
12
+ readonly evidenceIds: readonly string[];
13
+ readonly proofIds: readonly string[];
14
+ readonly historyIds: readonly string[];
15
+ readonly semanticOperationIds: readonly string[];
16
+ readonly semanticEditScriptIds: readonly string[];
17
+ readonly semanticEditProjectionIds: readonly string[];
18
+ readonly semanticEditReplayIds: readonly string[];
19
+ readonly semanticEditReplayStatuses: readonly string[];
20
+ readonly semanticEditReplayActions: readonly string[];
21
+ readonly semanticEditReplayCurrentHashes: readonly string[];
22
+ readonly semanticEditReplayOutputHashes: readonly string[];
23
+ readonly semanticEditKeys: readonly string[];
24
+ readonly semanticIdentityHashes: readonly string[];
25
+ readonly sourceIdentityHashes: readonly string[];
26
+ readonly operationContentHashes: readonly string[];
27
+ readonly editContentHashes: readonly string[];
28
+ readonly semanticTransformIds: readonly string[];
29
+ readonly semanticTransformKeys: readonly string[];
30
+ readonly semanticTransformIdentityHashes: readonly string[];
31
+ readonly semanticTransformContentHashes: readonly string[];
32
+ readonly projectionIdentityHashes: readonly string[];
33
+ readonly semanticTransformReadinesses: readonly string[];
34
+ readonly semanticTransformEvidenceIds: readonly string[];
35
+ readonly transformSourceLanguages: readonly string[];
36
+ readonly transformTargetLanguages: readonly string[];
37
+ readonly transformSourcePaths: readonly string[];
38
+ readonly transformTargetPaths: readonly string[];
39
+ readonly patchIds: readonly string[];
40
+ readonly mergeCandidateIds: readonly string[];
41
+ readonly readinesses: readonly string[];
42
+ readonly admissionStatuses: readonly string[];
43
+ }
@@ -7,9 +7,12 @@ import type {
7
7
  SourceSpan
8
8
  } from '@shapeshift-labs/frontier-lang-kernel';
9
9
  import type { NativeSourceChangeKind, NativeSourceChangeSet } from './native-diff.js';
10
- import type { SemanticEditProjection, SemanticEditScript } from './semantic-edit-script.js';
10
+ import type { SemanticEditProjection, SemanticEditReplay, SemanticEditScript } from './semantic-edit-script.js';
11
+ import type { SemanticPatchBundleRecordIndex } from './semantic-patch-bundle-index.js';
11
12
  import type { SemanticTransformIdentityRecord } from './semantic-transform-identity.js';
12
13
 
14
+ export type { SemanticPatchBundleRecordIndex } from './semantic-patch-bundle-index.js';
15
+
13
16
  export type SemanticPatchBundleAdmissionStatus = 'proposed' | 'queued' | 'admitted' | 'needs-review' | 'blocked' | 'rejected' | string;
14
17
 
15
18
  export interface SemanticPatchBundleSourceRef {
@@ -108,45 +111,6 @@ export interface SemanticPatchBundleTransformAdmission {
108
111
  readonly evidenceIds?: readonly string[];
109
112
  }
110
113
 
111
- export interface SemanticPatchBundleRecordIndex {
112
- readonly baseHashes: readonly string[];
113
- readonly targetHashes: readonly string[];
114
- readonly sourceHashes: readonly string[];
115
- readonly sourcePaths: readonly string[];
116
- readonly regionKeys: readonly string[];
117
- readonly regionKinds: readonly string[];
118
- readonly conflictKeys: readonly string[];
119
- readonly sourceMapIds: readonly string[];
120
- readonly sourceMapMappingIds: readonly string[];
121
- readonly sourceMapLinkIds: readonly string[];
122
- readonly evidenceIds: readonly string[];
123
- readonly proofIds: readonly string[];
124
- readonly historyIds: readonly string[];
125
- readonly semanticOperationIds: readonly string[];
126
- readonly semanticEditScriptIds: readonly string[];
127
- readonly semanticEditProjectionIds: readonly string[];
128
- readonly semanticEditKeys: readonly string[];
129
- readonly semanticIdentityHashes: readonly string[];
130
- readonly sourceIdentityHashes: readonly string[];
131
- readonly operationContentHashes: readonly string[];
132
- readonly editContentHashes: readonly string[];
133
- readonly semanticTransformIds: readonly string[];
134
- readonly semanticTransformKeys: readonly string[];
135
- readonly semanticTransformIdentityHashes: readonly string[];
136
- readonly semanticTransformContentHashes: readonly string[];
137
- readonly projectionIdentityHashes: readonly string[];
138
- readonly semanticTransformReadinesses: readonly string[];
139
- readonly semanticTransformEvidenceIds: readonly string[];
140
- readonly transformSourceLanguages: readonly string[];
141
- readonly transformTargetLanguages: readonly string[];
142
- readonly transformSourcePaths: readonly string[];
143
- readonly transformTargetPaths: readonly string[];
144
- readonly patchIds: readonly string[];
145
- readonly mergeCandidateIds: readonly string[];
146
- readonly readinesses: readonly string[];
147
- readonly admissionStatuses: readonly string[];
148
- }
149
-
150
114
  export interface SemanticPatchBundleRecord {
151
115
  readonly kind: 'frontier.lang.semanticPatchBundleRecord';
152
116
  readonly version: 1;
@@ -168,6 +132,7 @@ export interface SemanticPatchBundleRecord {
168
132
  readonly semanticOperationIds: readonly string[];
169
133
  readonly semanticEditScriptIds: readonly string[];
170
134
  readonly semanticEditProjectionIds: readonly string[];
135
+ readonly semanticEditReplayIds: readonly string[];
171
136
  readonly semanticTransformIdentityIds: readonly string[];
172
137
  readonly admission: SemanticPatchBundleAdmission;
173
138
  readonly index: SemanticPatchBundleRecordIndex;
@@ -180,7 +145,9 @@ export interface SemanticPatchBundleRecord {
180
145
  readonly semanticOperations: number;
181
146
  readonly semanticEditScripts: number;
182
147
  readonly semanticEditProjections: number;
148
+ readonly semanticEditReplays: number;
183
149
  readonly semanticEditProjectionEdits: number;
150
+ readonly semanticEditReplayEdits: number;
184
151
  readonly semanticTransformIdentities: number;
185
152
  readonly reviewRequired: boolean;
186
153
  readonly autoMergeClaim: false;
@@ -214,6 +181,8 @@ export interface CreateSemanticPatchBundleRecordOptions {
214
181
  readonly semanticEditScripts?: readonly SemanticEditScript[] | SemanticEditScript;
215
182
  readonly semanticEditProjection?: SemanticEditProjection;
216
183
  readonly semanticEditProjections?: readonly SemanticEditProjection[] | SemanticEditProjection;
184
+ readonly semanticEditReplay?: SemanticEditReplay;
185
+ readonly semanticEditReplays?: readonly SemanticEditReplay[] | SemanticEditReplay;
217
186
  readonly semanticTransformIdentity?: SemanticTransformIdentityRecord | Record<string, unknown>;
218
187
  readonly semanticTransformIdentities?: readonly (SemanticTransformIdentityRecord | Record<string, unknown>)[];
219
188
  readonly sourceLanguage?: FrontierSourceLanguage | string;
@@ -264,6 +233,16 @@ export interface SemanticPatchBundleRecordQuery {
264
233
  readonly semanticEditScriptIds?: readonly string[];
265
234
  readonly semanticEditProjectionId?: string | readonly string[];
266
235
  readonly semanticEditProjectionIds?: readonly string[];
236
+ readonly semanticEditReplayId?: string | readonly string[];
237
+ readonly semanticEditReplayIds?: readonly string[];
238
+ readonly semanticEditReplayStatus?: string | readonly string[];
239
+ readonly semanticEditReplayStatuses?: readonly string[];
240
+ readonly semanticEditReplayAction?: string | readonly string[];
241
+ readonly semanticEditReplayActions?: readonly string[];
242
+ readonly semanticEditReplayCurrentHash?: string | readonly string[];
243
+ readonly semanticEditReplayCurrentHashes?: readonly string[];
244
+ readonly semanticEditReplayOutputHash?: string | readonly string[];
245
+ readonly semanticEditReplayOutputHashes?: readonly string[];
267
246
  readonly semanticEditKey?: string | readonly string[];
268
247
  readonly semanticEditKeys?: readonly string[];
269
248
  readonly semanticIdentityHash?: string | readonly string[];
package/dist/index.d.ts CHANGED
@@ -19,6 +19,7 @@ export * from './declarations/semantic-merge-conflicts.js';
19
19
  export * from './declarations/semantic-edit-script.js';
20
20
  export * from './declarations/semantic-lineage.js';
21
21
  export * from './declarations/semantic-history.js';
22
+ export * from './declarations/semantic-patch-bundle-index.js';
22
23
  export * from './declarations/semantic-patch-bundle.js';
23
24
  export * from './declarations/semantic-patch-bundle-overlaps.js';
24
25
  export * from './declarations/semantic-transform-identity.js';
package/dist/index.js CHANGED
@@ -73,6 +73,7 @@ export { createSemanticMergeCandidateAdmissionRecord, decorateSemanticMergeCandi
73
73
  export { querySemanticMergeConflictClasses, SemanticMergeConflictClasses, semanticMergeConflictRiskScore, sortSemanticMergeCandidatesByConflictRisk, summarizeSemanticMergeConflicts } from './internal/index-impl/semanticMergeConflicts.js';
74
74
  export { createSemanticEditScript, SemanticEditScriptAdmissionStatuses } from './internal/index-impl/semanticEditScripts.js';
75
75
  export { projectSemanticEditScriptToSource } from './internal/index-impl/projectSemanticEditScriptToSource.js';
76
+ export { replaySemanticEditProjection } from './internal/index-impl/replaySemanticEditProjection.js';
76
77
  export { queryUniversalConversionPlan } from './internal/index-impl/queryUniversalConversionPlan.js';
77
78
  export { createSemanticAnchor, createSemanticLineageEvent, createSemanticLineageMap, querySemanticLineageEvents, SemanticLineageEventKinds } from './internal/index-impl/semanticLineageRecords.js';
78
79
  export { resolveSemanticLineage, resolveSemanticLineageBatch, SemanticLineageResolutionStatuses } from './internal/index-impl/semanticLineageResolutionRecords.js';
@@ -0,0 +1,191 @@
1
+ import { hashSemanticValue } from '@shapeshift-labs/frontier-lang-kernel';
2
+ import { idFragment, normalizeNativeLanguageId, uniqueStrings } from '../../native-import-utils.js';
3
+ import { createSemanticImportSidecar } from './createSemanticImportSidecar.js';
4
+ import { mapDiffSymbols } from './mapDiffSymbols.js';
5
+ import { normalizeNativeDiffImport } from './normalizeNativeDiffImport.js';
6
+
7
+ export function replaySemanticEditProjection(input = {}) {
8
+ const projection = input.projection ?? input.semanticEditProjection;
9
+ if (!projection) throw new Error('replaySemanticEditProjection requires a projection');
10
+ const currentSourceText = input.currentSourceText ?? input.headSourceText;
11
+ const sourcePath = input.currentSourcePath ?? input.headSourcePath ?? projection.sourcePath;
12
+ const language = normalizeNativeLanguageId(input.language ?? projection.language);
13
+ const reasonCodes = baseReasonCodes(projection, currentSourceText);
14
+ const currentHash = typeof currentSourceText === 'string' ? hashSemanticValue(currentSourceText) : undefined;
15
+ if (input.currentSourceHash && currentHash !== input.currentSourceHash) reasonCodes.push('current-source-hash-mismatch');
16
+ const currentSymbols = currentSourceText && isJavaScriptLike(language)
17
+ ? currentSymbolIndex({ currentSourceText, sourcePath, language, parser: input.parser })
18
+ : [];
19
+ const edits = projection.status === 'projected' && typeof currentSourceText === 'string'
20
+ ? (projection.edits ?? []).map((edit) => replayProjectionEdit(edit, { currentSourceText, currentSymbols }))
21
+ : [];
22
+ const status = replayStatus(reasonCodes, edits, projection);
23
+ const outputSourceText = replayOutputSource(status, currentSourceText, edits);
24
+ const core = {
25
+ kind: 'frontier.lang.semanticEditReplay',
26
+ version: 1,
27
+ schema: 'frontier.lang.semanticEditReplay.v1',
28
+ id: input.id ?? `semantic_edit_replay_${idFragment(projection.id ?? sourcePath ?? language ?? 'projection')}`,
29
+ projectionId: projection.id,
30
+ scriptId: projection.scriptId,
31
+ sourcePath,
32
+ language,
33
+ currentHash,
34
+ projectedHash: projection.projectedHash,
35
+ outputHash: outputSourceText === undefined ? undefined : hashSemanticValue(outputSourceText),
36
+ status,
37
+ edits,
38
+ appliedOperations: edits.filter((edit) => edit.status === 'applied').map((edit) => edit.operationId).filter(Boolean),
39
+ skippedOperations: edits.filter((edit) => edit.status !== 'applied').map((edit) => edit.operationId).filter(Boolean),
40
+ admission: replayAdmission(status, reasonCodes, edits),
41
+ outputSourceText,
42
+ summary: replaySummary(edits, reasonCodes),
43
+ metadata: compactRecord({
44
+ autoMergeClaim: false,
45
+ semanticEquivalenceClaim: false,
46
+ anchorMode: currentSymbols.length ? 'javascript-like-symbols' : 'offsets',
47
+ ...input.metadata
48
+ })
49
+ };
50
+ return { ...core, hash: hashSemanticValue(core) };
51
+ }
52
+
53
+ function replayProjectionEdit(edit, context) {
54
+ if (edit.status === 'already-applied') return replayEditRecord(edit, 'already-applied', undefined, ['projection-edit-already-applied']);
55
+ if (typeof edit.replacementText !== 'string') return replayEditRecord(edit, 'blocked', undefined, ['missing-replacement-text']);
56
+ const offset = checkRange(edit, { start: edit.headStart, end: edit.headEnd }, context.currentSourceText, 'head-offset');
57
+ if (offset) return replayEditRecord(edit, offset.status, offset.range, [offset.reason]);
58
+ const symbol = findCurrentSymbol(edit, context.currentSymbols);
59
+ const spanRange = spanOffsets(context.currentSourceText, symbol?.sourceSpan);
60
+ const anchored = checkRange(edit, spanRange, context.currentSourceText, 'current-symbol-anchor');
61
+ if (anchored) return replayEditRecord(edit, anchored.status, anchored.range, [anchored.reason, 'offset-reanchored-by-symbol']);
62
+ return replayEditRecord(edit, symbol ? 'conflict' : 'stale', spanRange, [
63
+ symbol ? 'current-symbol-anchor-content-mismatch' : 'current-symbol-anchor-missing'
64
+ ]);
65
+ }
66
+
67
+ function checkRange(edit, range, sourceText, label) {
68
+ if (!range || range.end < range.start) return undefined;
69
+ const current = sourceText.slice(range.start, range.end);
70
+ const currentHash = hashSemanticValue(current);
71
+ if (edit.deletedTextHash && currentHash === edit.deletedTextHash) return { status: 'applied', range, reason: `${label}-matches-deleted` };
72
+ if (edit.replacementTextHash && currentHash === edit.replacementTextHash) return { status: 'already-applied', range, reason: `${label}-matches-replacement` };
73
+ if (current === edit.replacementText) return { status: 'already-applied', range, reason: `${label}-matches-replacement-text` };
74
+ return undefined;
75
+ }
76
+
77
+ function replayEditRecord(edit, status, range, reasonCodes) {
78
+ return compactRecord({
79
+ operationId: edit.operationId,
80
+ semanticKey: edit.semanticKey,
81
+ semanticIdentityHash: edit.semanticIdentityHash,
82
+ sourceIdentityHash: edit.sourceIdentityHash,
83
+ editContentHash: edit.editContentHash,
84
+ sourcePath: edit.targetSourcePath ?? edit.sourcePath,
85
+ symbolName: edit.targetSymbolName ?? edit.symbolName,
86
+ symbolKind: edit.targetSymbolKind ?? edit.symbolKind,
87
+ status,
88
+ start: range?.start,
89
+ end: range?.end,
90
+ replacementBytes: edit.replacementBytes,
91
+ replacementText: edit.replacementText,
92
+ reasonCodes: reasonList(reasonCodes)
93
+ });
94
+ }
95
+
96
+ function currentSymbolIndex(input) {
97
+ const imported = normalizeNativeDiffImport({
98
+ language: input.language,
99
+ sourcePath: input.sourcePath,
100
+ sourceText: input.currentSourceText,
101
+ parser: input.parser
102
+ }, input, 'current');
103
+ return [...mapDiffSymbols(imported, createSemanticImportSidecar(imported)).values()];
104
+ }
105
+
106
+ function findCurrentSymbol(edit, symbols) {
107
+ const exact = symbols.find((symbol) => [symbol.ownershipKey, symbol.key, symbol.id].some((key) => key && [
108
+ edit.anchorKey,
109
+ edit.targetAnchorKey,
110
+ edit.symbolId
111
+ ].includes(key)));
112
+ if (exact) return exact;
113
+ const name = edit.targetSymbolName ?? edit.symbolName;
114
+ const kind = edit.targetSymbolKind ?? edit.symbolKind;
115
+ return symbols.find((symbol) => symbol.name === name && (!kind || symbol.kind === kind));
116
+ }
117
+
118
+ function replayStatus(reasonCodes, edits, projection) {
119
+ if (reasonCodes.some((reason) => reason !== 'current-source-hash-mismatch')) return 'blocked';
120
+ if (!edits.length && !(projection.edits ?? []).length) return 'evidence-only';
121
+ if (edits.some((edit) => edit.status === 'blocked')) return 'blocked';
122
+ if (edits.some((edit) => edit.status === 'conflict')) return 'conflict';
123
+ if (edits.some((edit) => edit.status === 'stale')) return 'stale';
124
+ if (edits.every((edit) => edit.status === 'already-applied')) return 'already-applied';
125
+ return edits.every((edit) => edit.status === 'applied' || edit.status === 'already-applied') ? 'accepted-clean' : 'needs-port';
126
+ }
127
+
128
+ function replayAdmission(status, reasonCodes, edits) {
129
+ const apply = status === 'accepted-clean';
130
+ return {
131
+ status,
132
+ action: apply ? 'apply' : status === 'already-applied' ? 'skip' : status === 'stale' ? 'rerun-semantic-import' : status === 'blocked' ? 'block' : 'human-review',
133
+ reviewRequired: !apply,
134
+ autoApplyCandidate: apply,
135
+ autoMergeClaim: false,
136
+ semanticEquivalenceClaim: false,
137
+ reasonCodes: reasonList([...reasonCodes, ...edits.flatMap((edit) => edit.reasonCodes ?? [])])
138
+ };
139
+ }
140
+
141
+ function replaySummary(edits, reasonCodes) {
142
+ return {
143
+ edits: edits.length,
144
+ applied: edits.filter((edit) => edit.status === 'applied').length,
145
+ alreadyApplied: edits.filter((edit) => edit.status === 'already-applied').length,
146
+ conflicts: edits.filter((edit) => edit.status === 'conflict').length,
147
+ stale: edits.filter((edit) => edit.status === 'stale').length,
148
+ blocked: edits.filter((edit) => edit.status === 'blocked').length,
149
+ reasonCodes: reasonList([...reasonCodes, ...edits.flatMap((edit) => edit.reasonCodes ?? [])])
150
+ };
151
+ }
152
+
153
+ function replayOutputSource(status, sourceText, edits) {
154
+ if (typeof sourceText !== 'string') return undefined;
155
+ if (status === 'already-applied') return sourceText;
156
+ if (status !== 'accepted-clean') return undefined;
157
+ return edits.filter((edit) => edit.status === 'applied')
158
+ .sort((left, right) => right.start - left.start)
159
+ .reduce((text, edit) => text.slice(0, edit.start) + editReplacement(edit, edits) + text.slice(edit.end), sourceText);
160
+ }
161
+
162
+ function editReplacement(edit, edits) {
163
+ return edits.find((candidate) => candidate.operationId === edit.operationId)?.replacementText ?? '';
164
+ }
165
+
166
+ function baseReasonCodes(projection, currentSourceText) {
167
+ return reasonList([
168
+ projection.status !== 'projected' ? 'projection-not-projected' : undefined,
169
+ projection.admission?.status !== 'auto-merge-candidate' ? 'projection-not-auto-merge-candidate' : undefined,
170
+ typeof currentSourceText !== 'string' ? 'missing-current-source-text' : undefined
171
+ ]);
172
+ }
173
+
174
+ function spanOffsets(sourceText, span) {
175
+ if (typeof sourceText !== 'string' || !span) return undefined;
176
+ if (typeof span.start === 'number' && typeof span.end === 'number' && span.end >= span.start) return { start: span.start, end: span.end };
177
+ if (typeof span.startLine !== 'number') return undefined;
178
+ const starts = [0];
179
+ for (let index = 0; index < sourceText.length; index += 1) if (sourceText[index] === '\n') starts.push(index + 1);
180
+ const startLine = Math.max(1, span.startLine);
181
+ const endLine = Math.max(startLine, typeof span.endLine === 'number' ? span.endLine : startLine);
182
+ const lineStart = starts[startLine - 1];
183
+ const endLineStart = starts[endLine - 1];
184
+ if (lineStart === undefined || endLineStart === undefined) return undefined;
185
+ const lineEnd = starts[endLine] === undefined ? sourceText.length : starts[endLine] - 1;
186
+ return { start: lineStart + Math.max(0, (span.startColumn ?? 1) - 1), end: endLineStart + (span.endColumn === undefined ? lineEnd - endLineStart : Math.max(0, span.endColumn - 1)) };
187
+ }
188
+
189
+ function isJavaScriptLike(language) { return language === 'javascript' || language === 'typescript'; }
190
+ function reasonList(values) { return uniqueStrings((values ?? []).filter(Boolean)); }
191
+ function compactRecord(value) { return Object.fromEntries(Object.entries(value ?? {}).filter(([, entry]) => entry !== undefined && (!Array.isArray(entry) || entry.length > 0))); }
@@ -0,0 +1,56 @@
1
+ import { uniqueStrings } from '../../native-import-utils.js';
2
+
3
+ export function semanticEditRecordIndex(scripts, projections, replays, source = {}) {
4
+ const operations = scripts.flatMap((script) => array(script.operations));
5
+ const edits = projections.flatMap((projection) => array(projection.edits));
6
+ const replayEdits = replays.flatMap((replay) => array(replay.edits));
7
+ const index = source.index ?? {};
8
+ const summary = source.metadata?.semanticEditSummary ?? {};
9
+ return {
10
+ semanticEditScriptIds: uniqueStrings([...strings(source.semanticEditScriptIds), ...strings(source.semanticEditScriptId), ...strings(index.semanticEditScriptIds), ...strings(summary.scriptIds), ...scripts.map((script) => script.id), ...replays.map((replay) => replay.scriptId)]),
11
+ semanticEditProjectionIds: uniqueStrings([...strings(source.semanticEditProjectionIds), ...strings(source.semanticEditProjectionId), ...strings(index.semanticEditProjectionIds), ...strings(summary.projectionIds), ...projections.map((projection) => projection.id), ...replays.map((replay) => replay.projectionId)]),
12
+ semanticEditReplayIds: uniqueStrings([...strings(source.semanticEditReplayIds), ...strings(source.semanticEditReplayId), ...strings(index.semanticEditReplayIds), ...strings(summary.replayIds), ...replays.map((replay) => replay.id)]),
13
+ semanticEditOperationIds: uniqueStrings([...strings(source.semanticOperationIds), ...strings(index.semanticOperationIds), ...operations.map((operation) => operation.id), ...replayOperationIds(replays)]),
14
+ semanticEditProjectionEditCount: edits.length,
15
+ semanticEditReplayEditCount: replayEdits.length,
16
+ semanticEditReplayStatuses: uniqueStrings([...strings(source.semanticEditReplayStatuses), ...strings(index.semanticEditReplayStatuses), ...strings(summary.replayStatuses), ...replays.map((replay) => replay.status)]),
17
+ semanticEditReplayActions: uniqueStrings([...strings(source.semanticEditReplayActions), ...strings(index.semanticEditReplayActions), ...strings(summary.replayActions), ...replays.map((replay) => replay.admission?.action)]),
18
+ semanticEditReplayCurrentHashes: uniqueStrings([...strings(source.semanticEditReplayCurrentHashes), ...strings(index.semanticEditReplayCurrentHashes), ...replays.map((replay) => replay.currentHash)]),
19
+ semanticEditReplayOutputHashes: uniqueStrings([...strings(source.semanticEditReplayOutputHashes), ...strings(index.semanticEditReplayOutputHashes), ...replays.map((replay) => replay.outputHash)]),
20
+ semanticEditKeys: uniqueStrings([...strings(source.semanticEditKeys), ...strings(index.semanticEditKeys), ...operations.map((operation) => operation.semanticKey), ...edits.map((edit) => edit.semanticKey), ...replayEdits.map((edit) => edit.semanticKey)]),
21
+ semanticIdentityHashes: uniqueStrings([...strings(source.semanticIdentityHashes), ...strings(index.semanticIdentityHashes), ...operations.map((operation) => operation.semanticIdentityHash), ...edits.map((edit) => edit.semanticIdentityHash), ...replayEdits.map((edit) => edit.semanticIdentityHash)]),
22
+ sourceIdentityHashes: uniqueStrings([...strings(source.sourceIdentityHashes), ...strings(index.sourceIdentityHashes), ...operations.map((operation) => operation.sourceIdentityHash), ...edits.map((edit) => edit.sourceIdentityHash), ...replayEdits.map((edit) => edit.sourceIdentityHash)]),
23
+ operationContentHashes: uniqueStrings([...strings(source.operationContentHashes), ...strings(index.operationContentHashes), ...operations.map((operation) => operation.operationContentHash), ...edits.map((edit) => edit.operationContentHash)]),
24
+ editContentHashes: uniqueStrings([...strings(source.editContentHashes), ...strings(index.editContentHashes), ...edits.map((edit) => edit.editContentHash), ...replayEdits.map((edit) => edit.editContentHash)]),
25
+ anchorKeys: uniqueStrings([...operations.map((operation) => operation.anchor?.key), ...edits.map((edit) => edit.anchorKey)]),
26
+ conflictKeys: uniqueStrings([...operations.map((operation) => operation.anchor?.conflictKey), ...edits.map((edit) => edit.conflictKey)]),
27
+ projectedSourcePaths: uniqueStrings([...projections.map((projection) => projection.sourcePath), ...edits.flatMap((edit) => [edit.sourcePath, edit.targetSourcePath]), ...replays.map((replay) => replay.sourcePath), ...replayEdits.map((edit) => edit.sourcePath)])
28
+ };
29
+ }
30
+
31
+ export function semanticEditSummary(index) {
32
+ if (!index.semanticEditScriptIds.length && !index.semanticEditProjectionIds.length && !index.semanticEditReplayIds.length) return undefined;
33
+ return compactRecord({
34
+ scriptIds: index.semanticEditScriptIds,
35
+ projectionIds: index.semanticEditProjectionIds,
36
+ replayIds: index.semanticEditReplayIds,
37
+ replayStatuses: index.semanticEditReplayStatuses,
38
+ replayActions: index.semanticEditReplayActions,
39
+ semanticEditKeys: index.semanticEditKeys,
40
+ operationContentHashes: index.operationContentHashes,
41
+ editContentHashes: index.editContentHashes,
42
+ projectedSourcePaths: index.projectedSourcePaths,
43
+ replayEditCount: index.semanticEditReplayEditCount
44
+ });
45
+ }
46
+
47
+ function replayOperationIds(replays) {
48
+ return replays.flatMap((replay) => [
49
+ ...array(replay.appliedOperations),
50
+ ...array(replay.skippedOperations),
51
+ ...array(replay.edits).map((edit) => edit.operationId)
52
+ ]);
53
+ }
54
+ function array(value) { if (value === undefined || value === null) return []; return Array.isArray(value) ? value : [value]; }
55
+ function strings(value) { return array(value).map((entry) => String(entry ?? '')).filter(Boolean); }
56
+ function compactRecord(value) { return Object.fromEntries(Object.entries(value ?? {}).filter(([, entry]) => entry !== undefined && (!Array.isArray(entry) || entry.length > 0))); }
@@ -1,5 +1,6 @@
1
1
  import{idFragment,normalizeSemanticMergeReadiness,uniqueStrings}from'../../native-import-utils.js';
2
2
  import{createSemanticPatchBundleAdmission}from'./semanticPatchBundleAdmission.js';
3
+ import{semanticEditRecordIndex,semanticEditSummary}from'./semanticEditBundleIndex.js';
3
4
  import{normalizeSemanticTransformIdentityRecords,semanticTransformInputs,semanticTransformRecordIndex,semanticTransformSummary}from'./semanticTransformIdentityRecords.js';
4
5
 
5
6
  export const SemanticPatchBundleAdmissionStatuses=Object.freeze(['proposed','queued','admitted','needs-review','blocked','rejected']);
@@ -10,7 +11,8 @@ export function createSemanticPatchBundleRecord(input={},options={}){
10
11
  const mergeCandidate=options.mergeCandidate??source.mergeCandidate??source.candidate;
11
12
  const semanticEditScripts=array(options.semanticEditScripts??source.semanticEditScripts??source.semanticEditScript);
12
13
  const semanticEditProjections=array(options.semanticEditProjections??source.semanticEditProjections??source.semanticEditProjection);
13
- const semanticEditIndex=semanticEditRecordIndex(semanticEditScripts,semanticEditProjections,source);
14
+ const semanticEditReplays=array(options.semanticEditReplays??source.semanticEditReplays??source.semanticEditReplay);
15
+ const semanticEditIndex=semanticEditRecordIndex(semanticEditScripts,semanticEditProjections,semanticEditReplays,source);
14
16
  const transformContext={sourceLanguage:options.sourceLanguage??source.sourceLanguage??source.language,targetLanguage:options.targetLanguage??source.targetLanguage};
15
17
  const semanticTransformIdentities=normalizeSemanticTransformIdentityRecords(semanticTransformInputs(source,options),transformContext);
16
18
  const semanticTransformIndex=semanticTransformRecordIndex(semanticTransformIdentities,source);
@@ -70,10 +72,11 @@ export function createSemanticPatchBundleRecord(input={},options={}){
70
72
  semanticOperationIds,
71
73
  semanticEditScriptIds:semanticEditIndex.semanticEditScriptIds,
72
74
  semanticEditProjectionIds:semanticEditIndex.semanticEditProjectionIds,
75
+ semanticEditReplayIds:semanticEditIndex.semanticEditReplayIds,
73
76
  semanticTransformIdentityIds:semanticTransformIndex.semanticTransformIds,
74
77
  admission,
75
78
  index,
76
- summary:{changedRegions:changedRegions.length,sourceMapLinks:sourceMapLinks.length,evidenceIds:evidenceIds.length,proofIds:proofIds.length,historyIds:historyIds.length,semanticOperations:semanticOperationIds.length,semanticEditScripts:semanticEditScripts.length,semanticEditProjections:semanticEditProjections.length,semanticEditProjectionEdits:semanticEditIndex.semanticEditProjectionEditCount,semanticTransformIdentities:semanticTransformIdentities.length,reviewRequired:admission.reviewRequired,autoMergeClaim:admission.autoMergeClaim},
79
+ summary:{changedRegions:changedRegions.length,sourceMapLinks:sourceMapLinks.length,evidenceIds:evidenceIds.length,proofIds:proofIds.length,historyIds:historyIds.length,semanticOperations:semanticOperationIds.length,semanticEditScripts:semanticEditScripts.length,semanticEditProjections:semanticEditProjections.length,semanticEditReplays:semanticEditReplays.length,semanticEditProjectionEdits:semanticEditIndex.semanticEditProjectionEditCount,semanticEditReplayEdits:semanticEditIndex.semanticEditReplayEditCount,semanticTransformIdentities:semanticTransformIdentities.length,reviewRequired:admission.reviewRequired,autoMergeClaim:admission.autoMergeClaim},
77
80
  metadata:compactRecord({
78
81
  sourceChangeSetId:source.kind==='frontier.lang.nativeSourceChangeSet'?source.id:undefined,
79
82
  patchRisk:patch?.risk,
@@ -186,7 +189,7 @@ function normalizeSourceMapLinks(links){
186
189
  }
187
190
 
188
191
  function recordIndex(parts){
189
- const semanticEditIndex=parts.semanticEditIndex??semanticEditRecordIndex([],[]);
192
+ const semanticEditIndex=parts.semanticEditIndex??semanticEditRecordIndex([],[],[],parts);
190
193
  const semanticTransformIndex=parts.semanticTransformIndex??semanticTransformRecordIndex([],parts);
191
194
  return{
192
195
  baseHashes:uniqueStrings([parts.baseHash,...parts.sources.map((item)=>item.baseHash)]),
@@ -205,6 +208,11 @@ function recordIndex(parts){
205
208
  semanticOperationIds:uniqueStrings(parts.semanticOperationIds),
206
209
  semanticEditScriptIds:semanticEditIndex.semanticEditScriptIds,
207
210
  semanticEditProjectionIds:semanticEditIndex.semanticEditProjectionIds,
211
+ semanticEditReplayIds:semanticEditIndex.semanticEditReplayIds,
212
+ semanticEditReplayStatuses:semanticEditIndex.semanticEditReplayStatuses,
213
+ semanticEditReplayActions:semanticEditIndex.semanticEditReplayActions,
214
+ semanticEditReplayCurrentHashes:semanticEditIndex.semanticEditReplayCurrentHashes,
215
+ semanticEditReplayOutputHashes:semanticEditIndex.semanticEditReplayOutputHashes,
208
216
  semanticEditKeys:semanticEditIndex.semanticEditKeys,
209
217
  semanticIdentityHashes:semanticEditIndex.semanticIdentityHashes,
210
218
  sourceIdentityHashes:semanticEditIndex.sourceIdentityHashes,
@@ -249,6 +257,11 @@ function matchesRecord(record,query){
249
257
  &&matchAny(queryValues(query.semanticOperationId,query.semanticOperationIds),index.semanticOperationIds)
250
258
  &&matchAny(queryValues(query.semanticEditScriptId,query.semanticEditScriptIds),index.semanticEditScriptIds)
251
259
  &&matchAny(queryValues(query.semanticEditProjectionId,query.semanticEditProjectionIds),index.semanticEditProjectionIds)
260
+ &&matchAny(queryValues(query.semanticEditReplayId,query.semanticEditReplayIds),index.semanticEditReplayIds)
261
+ &&matchAny(queryValues(query.semanticEditReplayStatus,query.semanticEditReplayStatuses),index.semanticEditReplayStatuses)
262
+ &&matchAny(queryValues(query.semanticEditReplayAction,query.semanticEditReplayActions),index.semanticEditReplayActions)
263
+ &&matchAny(queryValues(query.semanticEditReplayCurrentHash,query.semanticEditReplayCurrentHashes),index.semanticEditReplayCurrentHashes)
264
+ &&matchAny(queryValues(query.semanticEditReplayOutputHash,query.semanticEditReplayOutputHashes),index.semanticEditReplayOutputHashes)
252
265
  &&matchAny(queryValues(query.semanticEditKey,query.semanticEditKeys),index.semanticEditKeys)
253
266
  &&matchAny(queryValues(query.semanticIdentityHash,query.semanticIdentityHashes),index.semanticIdentityHashes)
254
267
  &&matchAny(queryValues(query.sourceIdentityHash,query.sourceIdentityHashes),index.sourceIdentityHashes)
@@ -269,36 +282,6 @@ function matchesRecord(record,query){
269
282
  &&matchAny(queryValues(query.admissionStatus,query.admissionStatuses),index.admissionStatuses);
270
283
  }
271
284
 
272
- function semanticEditRecordIndex(scripts,projections,source={}){
273
- const operations=scripts.flatMap((script)=>array(script.operations));
274
- const edits=projections.flatMap((projection)=>array(projection.edits));
275
- const index=source.index??{};
276
- return{
277
- semanticEditScriptIds:uniqueStrings([...strings(source.semanticEditScriptIds),...strings(source.semanticEditScriptId),...strings(index.semanticEditScriptIds),...scripts.map((script)=>script.id)]),
278
- semanticEditProjectionIds:uniqueStrings([...strings(source.semanticEditProjectionIds),...strings(source.semanticEditProjectionId),...strings(index.semanticEditProjectionIds),...projections.map((projection)=>projection.id)]),
279
- semanticEditOperationIds:uniqueStrings([...strings(source.semanticOperationIds),...strings(index.semanticOperationIds),...operations.map((operation)=>operation.id)]),
280
- semanticEditProjectionEditCount:edits.length,
281
- semanticEditKeys:uniqueStrings([...strings(source.semanticEditKeys),...strings(index.semanticEditKeys),...operations.map((operation)=>operation.semanticKey),...edits.map((edit)=>edit.semanticKey)]),
282
- semanticIdentityHashes:uniqueStrings([...strings(source.semanticIdentityHashes),...strings(index.semanticIdentityHashes),...operations.map((operation)=>operation.semanticIdentityHash),...edits.map((edit)=>edit.semanticIdentityHash)]),
283
- sourceIdentityHashes:uniqueStrings([...strings(source.sourceIdentityHashes),...strings(index.sourceIdentityHashes),...operations.map((operation)=>operation.sourceIdentityHash),...edits.map((edit)=>edit.sourceIdentityHash)]),
284
- operationContentHashes:uniqueStrings([...strings(source.operationContentHashes),...strings(index.operationContentHashes),...operations.map((operation)=>operation.operationContentHash),...edits.map((edit)=>edit.operationContentHash)]),
285
- editContentHashes:uniqueStrings([...strings(source.editContentHashes),...strings(index.editContentHashes),...edits.map((edit)=>edit.editContentHash)]),
286
- anchorKeys:uniqueStrings([...operations.map((operation)=>operation.anchor?.key),...edits.map((edit)=>edit.anchorKey)]),
287
- conflictKeys:uniqueStrings([...operations.map((operation)=>operation.anchor?.conflictKey),...edits.map((edit)=>edit.conflictKey)]),
288
- projectedSourcePaths:uniqueStrings([...projections.map((projection)=>projection.sourcePath),...edits.flatMap((edit)=>[edit.sourcePath,edit.targetSourcePath])])
289
- };
290
- }
291
- function semanticEditSummary(index){
292
- if(!index.semanticEditScriptIds.length&&!index.semanticEditProjectionIds.length)return undefined;
293
- return compactRecord({
294
- scriptIds:index.semanticEditScriptIds,
295
- projectionIds:index.semanticEditProjectionIds,
296
- semanticEditKeys:index.semanticEditKeys,
297
- operationContentHashes:index.operationContentHashes,
298
- editContentHashes:index.editContentHashes,
299
- projectedSourcePaths:index.projectedSourcePaths
300
- });
301
- }
302
285
  function queryValues(...values){return uniqueStrings(values.flatMap((value)=>strings(value)));}
303
286
  function matchAny(filters,values){if(filters.length===0)return true;const valueSet=new Set(strings(values));return filters.some((filter)=>valueSet.has(filter));}
304
287
  function array(value){if(value===undefined||value===null)return[];return Array.isArray(value)?value:[value];}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shapeshift-labs/frontier-lang-compiler",
3
- "version": "0.2.91",
3
+ "version": "0.2.93",
4
4
  "description": "Compiler facade for Frontier Lang source documents and language projection adapters.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",