@shapeshift-labs/frontier-lang-compiler 0.2.21 → 0.2.23

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
@@ -50,6 +50,34 @@ console.log(imported.nativeSource.ast.rootId);
50
50
  console.log(imported.patch.operations.length);
51
51
  ```
52
52
 
53
+ Import external code-intelligence payloads into Frontier semantic evidence when a project already has language tooling such as SCIP, LSIF, LSP, or SemanticDB:
54
+
55
+ ```js
56
+ import { importExternalSemanticIndex } from '@shapeshift-labs/frontier-lang-compiler';
57
+
58
+ const importedIndex = importExternalSemanticIndex({
59
+ format: 'scip',
60
+ language: 'typescript',
61
+ payload: {
62
+ metadata: { project_root: '/repo' },
63
+ documents: [{
64
+ relative_path: 'src/todo.ts',
65
+ occurrences: [{
66
+ symbol: 'scip-typescript npm todo 1.0.0 src/todo.ts/ addTodo().',
67
+ range: [0, 16, 23],
68
+ symbol_roles: 1
69
+ }]
70
+ }]
71
+ }
72
+ });
73
+
74
+ console.log(importedIndex.semanticIndex.symbols.length);
75
+ console.log(importedIndex.summary.sourceMapMappings);
76
+ console.log(importedIndex.readiness.readiness); // "ready-with-losses" or review-required
77
+ ```
78
+
79
+ External semantic-index imports create Frontier `SemanticIndexRecord`, `SourceMapRecord`, evidence, losses, ownership facts, and a universal AST envelope. They are a bridge from existing language servers/indexers into semantic merge tooling; they do not claim full parser AST coverage, macro expansion, type checking, comments/trivia preservation, or lossless cross-language code generation by themselves.
80
+
53
81
  Native imports include source maps, semantic merge candidates, and a loss summary for admission queues and dashboards. Informational losses produce `ready-with-losses`, warning losses produce `needs-review`, and error losses or failed import evidence produce `blocked`:
54
82
 
55
83
  ```js
@@ -64,6 +92,25 @@ console.log(readiness.readiness);
64
92
 
65
93
  The loss taxonomy separates broad scanner limits from specific round-trip risks such as conditional compilation, reflection, overload/type-inference gaps, comments/trivia preservation, source-map approximation, parser diagnostics, and target projection loss. These records are evidence labels for merge admission; they are not claims that the lightweight scanner expanded macros, evaluated inactive branches, resolved overloads, or ran a type checker.
66
94
 
95
+ High-risk native features also have explicit evidence policies. These policies are advisory in this package: they tell a swarm or admission queue what evidence is missing without silently changing the existing readiness classification.
96
+
97
+ ```js
98
+ import {
99
+ getNativeImportFeatureEvidencePolicy,
100
+ summarizeNativeImportFeatureEvidence
101
+ } from '@shapeshift-labs/frontier-lang-compiler';
102
+
103
+ const policy = getNativeImportFeatureEvidencePolicy('preprocessor');
104
+ console.log(policy.requiredEvidenceKeys); // ["preprocessedOutputHash", "definesHash"]
105
+
106
+ const featureEvidence = summarizeNativeImportFeatureEvidence(imported.losses, {
107
+ evidence: imported.evidence
108
+ });
109
+
110
+ console.log(featureEvidence.highestRisk);
111
+ console.log(featureEvidence.missingRequiredEvidence);
112
+ ```
113
+
67
114
  Ask the compiler what is actually covered before sending native imports into a merge queue:
68
115
 
69
116
  ```js
package/bench/smoke.mjs CHANGED
@@ -7,9 +7,11 @@ import {
7
7
  createProjectionTargetLossMatrix,
8
8
  createNativeSourcePreservation,
9
9
  createSemanticImportSidecar,
10
+ importExternalSemanticIndex,
10
11
  importNativeSource,
11
12
  projectNativeImportToSource,
12
- runNativeImporterAdapter
13
+ runNativeImporterAdapter,
14
+ summarizeNativeImportFeatureEvidence
13
15
  } from '../dist/index.js';
14
16
 
15
17
  const source = `
@@ -88,6 +90,13 @@ const semanticSidecars = nativeImportResults.map((imported) => createSemanticImp
88
90
  const sidecarDurationMs = performance.now() - sidecarStart;
89
91
  const sidecarOwnershipRegions = semanticSidecars.reduce((sum, sidecar) => sum + sidecar.ownershipRegions.length, 0);
90
92
 
93
+ const featureEvidenceStart = performance.now();
94
+ const featureEvidenceSummaries = nativeImportResults.map((imported) => summarizeNativeImportFeatureEvidence(imported.losses, {
95
+ evidence: imported.evidence
96
+ }));
97
+ const featureEvidenceDurationMs = performance.now() - featureEvidenceStart;
98
+ const featureEvidencePolicyMatches = featureEvidenceSummaries.reduce((sum, summary) => sum + summary.total, 0);
99
+
91
100
  const projectionStart = performance.now();
92
101
  const nativeProjections = nativeImportResults.map((imported) => projectNativeImportToSource(imported));
93
102
  const projectionDurationMs = performance.now() - projectionStart;
@@ -126,6 +135,40 @@ const nativeTargetAdapterDurationMs = performance.now() - nativeTargetAdapterSta
126
135
  const nativeTargetAdapterBytes = nativeTargetAdapterCompiles.reduce((sum, result) => sum + result.output.length, 0);
127
136
  const nativeTargetAdapterSourceMaps = nativeTargetAdapterCompiles.reduce((sum, result) => sum + result.sourceMaps.length, 0);
128
137
 
138
+ const externalSemanticStart = performance.now();
139
+ const externalSemanticImports = [];
140
+ for (let index = 0; index < 100; index += 1) {
141
+ externalSemanticImports.push(importExternalSemanticIndex({
142
+ format: index % 2 === 0 ? 'scip' : 'lsp',
143
+ language: index % 2 === 0 ? 'typescript' : 'python',
144
+ payload: index % 2 === 0
145
+ ? {
146
+ metadata: { project_root: '/bench' },
147
+ documents: [{
148
+ relative_path: `src/external-${index}.ts`,
149
+ language: 'typescript',
150
+ occurrences: [{
151
+ symbol: `scip-typescript npm bench 1.0.0 src/external-${index}.ts/ external${index}().`,
152
+ range: [0, 16, 24],
153
+ symbol_roles: 1
154
+ }]
155
+ }]
156
+ }
157
+ : {
158
+ uri: `file:///bench/src/external-${index}.py`,
159
+ languageId: 'python',
160
+ documentSymbols: [{
161
+ name: `external_${index}`,
162
+ kind: 12,
163
+ range: { start: { line: 0, character: 0 }, end: { line: 1, character: 0 } }
164
+ }]
165
+ }
166
+ }));
167
+ }
168
+ const externalSemanticDurationMs = performance.now() - externalSemanticStart;
169
+ const externalSemanticSymbols = externalSemanticImports.reduce((sum, imported) => sum + imported.semanticIndex.symbols.length, 0);
170
+ const externalSemanticMappings = externalSemanticImports.reduce((sum, imported) => sum + imported.summary.sourceMapMappings, 0);
171
+
129
172
  console.log(JSON.stringify({
130
173
  compiles: 250,
131
174
  bytes,
@@ -150,6 +193,8 @@ console.log(JSON.stringify({
150
193
  semanticSidecars: semanticSidecars.length,
151
194
  sidecarOwnershipRegions,
152
195
  sidecarDurationMs: Number(sidecarDurationMs.toFixed(2)),
196
+ featureEvidencePolicyMatches,
197
+ featureEvidenceDurationMs: Number(featureEvidenceDurationMs.toFixed(2)),
153
198
  nativeProjections: nativeProjections.length,
154
199
  projectionBytes,
155
200
  projectionDurationMs: Number(projectionDurationMs.toFixed(2)),
@@ -162,5 +207,9 @@ console.log(JSON.stringify({
162
207
  nativeTargetAdapterCompiles: nativeTargetAdapterCompiles.length,
163
208
  nativeTargetAdapterBytes,
164
209
  nativeTargetAdapterSourceMaps,
165
- nativeTargetAdapterDurationMs: Number(nativeTargetAdapterDurationMs.toFixed(2))
210
+ nativeTargetAdapterDurationMs: Number(nativeTargetAdapterDurationMs.toFixed(2)),
211
+ externalSemanticImports: externalSemanticImports.length,
212
+ externalSemanticSymbols,
213
+ externalSemanticMappings,
214
+ externalSemanticDurationMs: Number(externalSemanticDurationMs.toFixed(2))
166
215
  }));
package/dist/index.d.ts CHANGED
@@ -151,6 +151,49 @@ export interface NativeImportLossSummaryOptions {
151
151
  readonly semanticStatus?: string;
152
152
  }
153
153
 
154
+ export type NativeImportFeatureEvidenceRisk = 'low' | 'medium' | 'high' | 'critical' | string;
155
+
156
+ export interface NativeImportFeatureEvidencePolicy {
157
+ readonly kind: NativeImportKnownLossKind;
158
+ readonly category: NativeImportTaxonomyKind;
159
+ readonly risk: NativeImportFeatureEvidenceRisk;
160
+ readonly minimumReadiness: SemanticMergeReadiness;
161
+ readonly missingEvidenceReadiness: SemanticMergeReadiness;
162
+ readonly requiredEvidenceKeys: readonly string[];
163
+ readonly recommendedEvidenceKeys: readonly string[];
164
+ readonly notes: readonly string[];
165
+ }
166
+
167
+ export interface NativeImportFeatureEvidenceIssue {
168
+ readonly lossId: string;
169
+ readonly kind: NativeImportKnownLossKind;
170
+ readonly policyKind: NativeImportKnownLossKind;
171
+ readonly risk: NativeImportFeatureEvidenceRisk;
172
+ readonly category: NativeImportTaxonomyKind;
173
+ readonly readiness: SemanticMergeReadiness;
174
+ readonly missingRequiredEvidence: readonly string[];
175
+ readonly presentRequiredEvidence: readonly string[];
176
+ readonly presentRecommendedEvidence: readonly string[];
177
+ readonly evidenceIds: readonly string[];
178
+ }
179
+
180
+ export interface NativeImportFeatureEvidenceSummary {
181
+ readonly total: number;
182
+ readonly policyKinds: readonly NativeImportKnownLossKind[];
183
+ readonly byKind: Readonly<Record<string, number>>;
184
+ readonly byRisk: Readonly<Record<string, number>>;
185
+ readonly highestRisk: NativeImportFeatureEvidenceRisk;
186
+ readonly semanticMergeReadiness: SemanticMergeReadiness;
187
+ readonly missingRequiredEvidence: readonly {
188
+ readonly lossId: string;
189
+ readonly kind: NativeImportKnownLossKind;
190
+ readonly policyKind: NativeImportKnownLossKind;
191
+ readonly evidenceKey: string;
192
+ }[];
193
+ readonly issues: readonly NativeImportFeatureEvidenceIssue[];
194
+ readonly reasons: readonly string[];
195
+ }
196
+
154
197
  export interface NativeImportLossSummary {
155
198
  readonly total: number;
156
199
  readonly hasLosses: boolean;
@@ -165,6 +208,7 @@ export interface NativeImportLossSummary {
165
208
  readonly reviewLossIds: readonly string[];
166
209
  readonly informationalLossIds: readonly string[];
167
210
  readonly failedEvidenceIds: readonly string[];
211
+ readonly featureEvidence: NativeImportFeatureEvidenceSummary;
168
212
  readonly parser?: string;
169
213
  readonly scanKind?: string;
170
214
  readonly semanticStatus?: string;
@@ -1023,6 +1067,63 @@ export type NativeSourceImportResult = LanguageImportResult & {
1023
1067
  readonly universalAst: FrontierUniversalAstEnvelope;
1024
1068
  };
1025
1069
 
1070
+ export type ExternalSemanticIndexFormat =
1071
+ | 'frontier-semantic-index'
1072
+ | 'scip'
1073
+ | 'lsif'
1074
+ | 'lsp'
1075
+ | 'semanticdb'
1076
+ | string;
1077
+
1078
+ export interface ImportExternalSemanticIndexOptions {
1079
+ readonly format?: ExternalSemanticIndexFormat;
1080
+ readonly payload?: unknown;
1081
+ readonly semanticIndex?: SemanticIndexRecord;
1082
+ readonly id?: string;
1083
+ readonly semanticIndexId?: string;
1084
+ readonly universalAstId?: string;
1085
+ readonly documentId?: string;
1086
+ readonly documentName?: string;
1087
+ readonly sourceMapId?: string;
1088
+ readonly language?: FrontierSourceLanguage | string;
1089
+ readonly sourcePath?: string;
1090
+ readonly sourceHash?: string;
1091
+ readonly projectRoot?: string;
1092
+ readonly parser?: string;
1093
+ readonly evidence?: readonly EvidenceRecord[];
1094
+ readonly metadata?: Record<string, unknown>;
1095
+ readonly universalAstMetadata?: Record<string, unknown>;
1096
+ }
1097
+
1098
+ export interface ExternalSemanticIndexImportSummary {
1099
+ readonly documents: number;
1100
+ readonly symbols: number;
1101
+ readonly occurrences: number;
1102
+ readonly relations: number;
1103
+ readonly facts: number;
1104
+ readonly sourceMapMappings: number;
1105
+ readonly losses: number;
1106
+ readonly readiness: SemanticMergeReadiness;
1107
+ }
1108
+
1109
+ export interface ExternalSemanticIndexImportResult {
1110
+ readonly kind: 'frontier.lang.externalSemanticIndexImport';
1111
+ readonly version: 1;
1112
+ readonly id: string;
1113
+ readonly format: ExternalSemanticIndexFormat;
1114
+ readonly language?: FrontierSourceLanguage | string;
1115
+ readonly sourcePath?: string;
1116
+ readonly projectRoot?: string;
1117
+ readonly semanticIndex: SemanticIndexRecord;
1118
+ readonly universalAst: FrontierUniversalAstEnvelope;
1119
+ readonly sourceMaps: readonly SourceMapRecord[];
1120
+ readonly losses: readonly NativeAstLossRecord[];
1121
+ readonly evidence: readonly EvidenceRecord[];
1122
+ readonly readiness: NativeImportReadinessClassification;
1123
+ readonly summary: ExternalSemanticIndexImportSummary;
1124
+ readonly metadata: Record<string, unknown>;
1125
+ }
1126
+
1026
1127
  export interface NativeImporterAdapterParseInput {
1027
1128
  readonly sourceText: string;
1028
1129
  readonly sourcePath?: string;
@@ -1428,7 +1529,9 @@ export declare const NativeImportLossKinds: readonly NativeImportKnownLossKind[]
1428
1529
  export declare const NativeImportRegionTaxonomyKinds: readonly NativeImportRegionTaxonomyKind[];
1429
1530
  export declare const ProjectionTargetLossClasses: readonly ProjectionTargetLossClass[];
1430
1531
  export declare const NativeImportReadinessBySeverity: Readonly<Record<NativeImportLossSummary['highestSeverity'], SemanticMergeReadiness>>;
1532
+ export declare const NativeImportFeatureEvidencePolicies: Readonly<Record<string, NativeImportFeatureEvidencePolicy>>;
1431
1533
  export declare const NativeImportLanguageProfiles: readonly NativeImportLanguageProfile[];
1534
+ export declare const ExternalSemanticIndexFormats: readonly ExternalSemanticIndexFormat[];
1432
1535
  export declare function normalizeCompileTarget(target?: string): FrontierCompileTarget;
1433
1536
  export declare function compileFrontierSource(source: string, options?: FrontierCompileOptions): FrontierCompileResult;
1434
1537
  export declare function compileFrontierDocument(document: FrontierLangDocument, options?: FrontierCompileOptions): FrontierCompileResult;
@@ -1438,6 +1541,8 @@ export declare function renderTargetAst(ast: FrontierTargetAst, target?: Frontie
1438
1541
  export declare function renderTargetAstWithSourceMap(ast: FrontierTargetAst, target?: FrontierCompileOptions['target'], options?: FrontierCompileEmitOptions): FrontierTargetSourceMapResult;
1439
1542
  export declare function emitForTargetWithSourceMap(document: FrontierLangDocument, target?: FrontierCompileOptions['target'], options?: FrontierCompileEmitOptions): FrontierTargetDocumentSourceMapResult;
1440
1543
  export declare function resolveCapabilityAdapters(document: FrontierLangDocument, target?: FrontierCompileOptions['target'], options?: { readonly platform?: string }): readonly CapabilityResolution[];
1544
+ export declare function getNativeImportFeatureEvidencePolicy(kind: NativeImportKnownLossKind | string): NativeImportFeatureEvidencePolicy | undefined;
1545
+ export declare function summarizeNativeImportFeatureEvidence(losses?: readonly NativeAstLossRecord[], options?: NativeImportLossSummaryOptions): NativeImportFeatureEvidenceSummary;
1441
1546
  export declare function summarizeNativeImportLosses(losses?: readonly NativeAstLossRecord[], options?: NativeImportLossSummaryOptions): NativeImportLossSummary;
1442
1547
  export declare function classifyNativeImportReadiness(losses?: readonly NativeAstLossRecord[], options?: NativeImportLossSummaryOptions): NativeImportReadinessClassification;
1443
1548
  export declare function classifyNativeImportRoundtripReadiness(importResult: NativeSourceImportResult | NativeProjectImportResult, options?: NativeImportRoundtripReadinessOptions): NativeImportRoundtripReadinessClassification;
@@ -1453,6 +1558,7 @@ export declare function createTreeSitterNativeImporterAdapter(options?: TreeSitt
1453
1558
  export declare function runNativeImporterAdapter(adapter: NativeImporterAdapter, input: RunNativeImporterAdapterOptions): Promise<NativeImporterAdapterImportResult>;
1454
1559
  export declare function runNativeTargetProjectionAdapter(adapter: NativeTargetProjectionAdapter, input: NativeTargetProjectionAdapterInput): NativeTargetProjectionResult;
1455
1560
  export declare function projectNativeImportToSource(importResult: NativeSourceImportResult | NativeProjectImportResult, options?: ProjectNativeImportToSourceOptions): NativeSourceProjectionResult;
1561
+ export declare function importExternalSemanticIndex(input: ImportExternalSemanticIndexOptions | SemanticIndexRecord): ExternalSemanticIndexImportResult;
1456
1562
  export declare function importNativeSource(input: ImportNativeSourceOptions): NativeSourceImportResult;
1457
1563
  export declare function diffNativeSources(input: DiffNativeSourcesOptions): NativeSourceChangeSet;
1458
1564
  export declare function diffNativeSourceImports(input: DiffNativeSourceImportsOptions): NativeSourceChangeSet;