@lssm/module.contractspec-workspace 0.0.0-canary-20251217062943 → 0.0.0-canary-20251217072406
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/ai/code-generation.js +50 -13
- package/dist/ai/spec-creation.js +50 -18
- package/dist/analysis/deps/graph.js +84 -2
- package/dist/analysis/deps/parse-imports.js +30 -1
- package/dist/analysis/diff/semantic.js +96 -1
- package/dist/analysis/feature-scan.js +151 -1
- package/dist/analysis/spec-scan.js +344 -1
- package/dist/analysis/validate/spec-structure.js +122 -1
- package/dist/index.js +25 -1
- package/dist/templates/app-config.js +100 -28
- package/dist/templates/data-view.js +41 -27
- package/dist/templates/event.js +28 -14
- package/dist/templates/experiment.js +76 -51
- package/dist/templates/handler.js +49 -17
- package/dist/templates/integration-utils.js +97 -26
- package/dist/templates/integration.js +46 -23
- package/dist/templates/knowledge.js +59 -19
- package/dist/templates/migration.js +49 -26
- package/dist/templates/operation.js +40 -28
- package/dist/templates/presentation.js +45 -20
- package/dist/templates/telemetry.js +73 -53
- package/dist/templates/utils.js +38 -1
- package/dist/templates/workflow-runner.js +12 -6
- package/dist/templates/workflow.js +50 -24
- package/dist/types/generation-types.js +20 -1
- package/package.json +5 -5
|
@@ -1,9 +1,18 @@
|
|
|
1
|
-
|
|
1
|
+
//#region src/ai/code-generation.ts
|
|
2
|
+
/**
|
|
3
|
+
* AI prompts for code generation.
|
|
4
|
+
* Extracted from cli-contracts/src/ai/prompts/code-generation.ts
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Build prompt for generating handler implementation.
|
|
8
|
+
*/
|
|
9
|
+
function buildHandlerPrompt(specCode) {
|
|
10
|
+
return `You are a senior TypeScript developer implementing a handler for a contract specification.
|
|
2
11
|
|
|
3
12
|
Here is the contract spec:
|
|
4
13
|
|
|
5
14
|
\`\`\`typescript
|
|
6
|
-
${
|
|
15
|
+
${specCode}
|
|
7
16
|
\`\`\`
|
|
8
17
|
|
|
9
18
|
Generate a complete handler implementation that:
|
|
@@ -17,12 +26,18 @@ Generate a complete handler implementation that:
|
|
|
17
26
|
|
|
18
27
|
The handler should be production-ready with proper error handling, logging points, and clear structure.
|
|
19
28
|
|
|
20
|
-
Return only the TypeScript code for the handler function
|
|
29
|
+
Return only the TypeScript code for the handler function.`;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Build prompt for generating React component from presentation spec.
|
|
33
|
+
*/
|
|
34
|
+
function buildComponentPrompt(specCode) {
|
|
35
|
+
return `You are a senior React developer creating a component for a presentation specification.
|
|
21
36
|
|
|
22
37
|
Here is the presentation spec:
|
|
23
38
|
|
|
24
39
|
\`\`\`typescript
|
|
25
|
-
${
|
|
40
|
+
${specCode}
|
|
26
41
|
\`\`\`
|
|
27
42
|
|
|
28
43
|
Generate a complete React component that:
|
|
@@ -36,12 +51,18 @@ Generate a complete React component that:
|
|
|
36
51
|
|
|
37
52
|
The component should follow Atomic Design principles and be reusable.
|
|
38
53
|
|
|
39
|
-
Return only the TypeScript/TSX code for the component
|
|
54
|
+
Return only the TypeScript/TSX code for the component.`;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Build prompt for generating form component.
|
|
58
|
+
*/
|
|
59
|
+
function buildFormPrompt(specCode) {
|
|
60
|
+
return `You are a senior React developer creating a form component from a form specification.
|
|
40
61
|
|
|
41
62
|
Here is the form spec:
|
|
42
63
|
|
|
43
64
|
\`\`\`typescript
|
|
44
|
-
${
|
|
65
|
+
${specCode}
|
|
45
66
|
\`\`\`
|
|
46
67
|
|
|
47
68
|
Generate a complete form component using react-hook-form that:
|
|
@@ -56,25 +77,31 @@ Generate a complete form component using react-hook-form that:
|
|
|
56
77
|
|
|
57
78
|
The form should provide excellent UX with real-time validation and helpful feedback.
|
|
58
79
|
|
|
59
|
-
Return only the TypeScript/TSX code for the form component
|
|
80
|
+
Return only the TypeScript/TSX code for the form component.`;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Build prompt for generating tests.
|
|
84
|
+
*/
|
|
85
|
+
function buildTestPrompt(specCode, implementationCode, testType) {
|
|
86
|
+
return `You are a senior developer writing comprehensive tests.
|
|
60
87
|
|
|
61
88
|
Spec:
|
|
62
89
|
\`\`\`typescript
|
|
63
|
-
${
|
|
90
|
+
${specCode}
|
|
64
91
|
\`\`\`
|
|
65
92
|
|
|
66
93
|
Implementation:
|
|
67
94
|
\`\`\`typescript
|
|
68
|
-
${
|
|
95
|
+
${implementationCode}
|
|
69
96
|
\`\`\`
|
|
70
97
|
|
|
71
98
|
Generate complete test suite using Vitest that:
|
|
72
|
-
${
|
|
99
|
+
${testType === "handler" ? `
|
|
73
100
|
- Test all acceptance scenarios from the spec
|
|
74
101
|
- Test error cases defined in spec.io.errors
|
|
75
102
|
- Verify events are emitted correctly
|
|
76
103
|
- Test input validation
|
|
77
|
-
- Test happy path and edge cases
|
|
104
|
+
- Test happy path and edge cases` : `
|
|
78
105
|
- Test rendering with various props
|
|
79
106
|
- Test user interactions
|
|
80
107
|
- Test accessibility (a11y)
|
|
@@ -83,7 +110,13 @@ ${n===`handler`?`
|
|
|
83
110
|
|
|
84
111
|
Use clear test descriptions and follow AAA pattern (Arrange, Act, Assert).
|
|
85
112
|
|
|
86
|
-
Return only the TypeScript test code
|
|
113
|
+
Return only the TypeScript test code.`;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* System prompt for code generation.
|
|
117
|
+
*/
|
|
118
|
+
function getCodeGenSystemPrompt() {
|
|
119
|
+
return `You are an expert TypeScript developer with deep knowledge of:
|
|
87
120
|
- Type-safe API design
|
|
88
121
|
- React and modern hooks
|
|
89
122
|
- Test-driven development
|
|
@@ -97,4 +130,8 @@ Generate production-ready code that is:
|
|
|
97
130
|
- Defensive and error-safe
|
|
98
131
|
- Easy to maintain and extend
|
|
99
132
|
|
|
100
|
-
Always prioritize code quality, safety, and user experience
|
|
133
|
+
Always prioritize code quality, safety, and user experience.`;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
//#endregion
|
|
137
|
+
export { buildComponentPrompt, buildFormPrompt, buildHandlerPrompt, buildTestPrompt, getCodeGenSystemPrompt };
|
package/dist/ai/spec-creation.js
CHANGED
|
@@ -1,8 +1,13 @@
|
|
|
1
|
-
|
|
1
|
+
//#region src/ai/spec-creation.ts
|
|
2
|
+
/**
|
|
3
|
+
* Build prompt for creating operation spec from description.
|
|
4
|
+
*/
|
|
5
|
+
function buildOperationSpecPrompt(description, kind) {
|
|
6
|
+
return `You are a senior software architect creating a contract specification for an operation.
|
|
2
7
|
|
|
3
|
-
The operation is a ${
|
|
8
|
+
The operation is a ${kind} (${kind === "command" ? "changes state, has side effects" : "read-only, idempotent"}).
|
|
4
9
|
|
|
5
|
-
User description: ${
|
|
10
|
+
User description: ${description}
|
|
6
11
|
|
|
7
12
|
Create a complete contract specification following these guidelines:
|
|
8
13
|
|
|
@@ -16,9 +21,15 @@ Create a complete contract specification following these guidelines:
|
|
|
16
21
|
8. **Feature Flags**: Any flags that gate this operation
|
|
17
22
|
9. **Side Effects**: What events might be emitted, analytics to track
|
|
18
23
|
|
|
19
|
-
Respond with a structured spec
|
|
24
|
+
Respond with a structured spec.`;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Build prompt for creating event spec from description.
|
|
28
|
+
*/
|
|
29
|
+
function buildEventSpecPrompt(description) {
|
|
30
|
+
return `You are a senior software architect creating an event specification.
|
|
20
31
|
|
|
21
|
-
User description: ${
|
|
32
|
+
User description: ${description}
|
|
22
33
|
|
|
23
34
|
Create a complete event specification following these guidelines:
|
|
24
35
|
|
|
@@ -30,11 +41,21 @@ Create a complete event specification following these guidelines:
|
|
|
30
41
|
|
|
31
42
|
Events represent things that have already happened and should use past tense.
|
|
32
43
|
|
|
33
|
-
Respond with a structured spec
|
|
44
|
+
Respond with a structured spec.`;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Build prompt for creating presentation spec from description.
|
|
48
|
+
*/
|
|
49
|
+
function buildPresentationSpecPrompt(description, kind) {
|
|
50
|
+
return `You are a senior software architect creating a presentation specification.
|
|
34
51
|
|
|
35
|
-
This is a ${
|
|
52
|
+
This is a ${kind} presentation - ${{
|
|
53
|
+
web_component: "a React component with props schema",
|
|
54
|
+
markdown: "markdown/MDX documentation or guide",
|
|
55
|
+
data: "structured data export (JSON/XML)"
|
|
56
|
+
}[kind]}.
|
|
36
57
|
|
|
37
|
-
User description: ${
|
|
58
|
+
User description: ${description}
|
|
38
59
|
|
|
39
60
|
Create a complete presentation specification following these guidelines:
|
|
40
61
|
|
|
@@ -42,13 +63,15 @@ Create a complete presentation specification following these guidelines:
|
|
|
42
63
|
2. **Version**: Start at 1
|
|
43
64
|
3. **Description**: What this presentation shows/provides
|
|
44
65
|
4. **Kind-specific details**:
|
|
45
|
-
${
|
|
46
|
-
- Props structure
|
|
47
|
-
- Analytics events to track`:t===`markdown`?`- Content or resource URI
|
|
48
|
-
- Target audience`:`- MIME type (e.g., application/json)
|
|
49
|
-
- Data structure description`}
|
|
66
|
+
${kind === "web_component" ? "- Component key (symbolic, resolved by host app)\n - Props structure\n - Analytics events to track" : kind === "markdown" ? "- Content or resource URI\n - Target audience" : "- MIME type (e.g., application/json)\n - Data structure description"}
|
|
50
67
|
|
|
51
|
-
Respond with a structured spec
|
|
68
|
+
Respond with a structured spec.`;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Build system prompt for all spec generation.
|
|
72
|
+
*/
|
|
73
|
+
function getSystemPrompt() {
|
|
74
|
+
return `You are an expert software architect specializing in API design and contract-driven development.
|
|
52
75
|
|
|
53
76
|
You create clear, well-documented specifications that serve as the single source of truth for operations, events, and presentations.
|
|
54
77
|
|
|
@@ -58,12 +81,21 @@ Your specs are:
|
|
|
58
81
|
- Business-oriented (capturing the "why" not just "what")
|
|
59
82
|
- Designed for both humans and AI agents to understand
|
|
60
83
|
|
|
61
|
-
Always use proper dot notation for names and ensure all metadata is meaningful and accurate
|
|
84
|
+
Always use proper dot notation for names and ensure all metadata is meaningful and accurate.`;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Create example-based prompt for better results.
|
|
88
|
+
*/
|
|
89
|
+
function addExampleContext(basePrompt, examples) {
|
|
90
|
+
if (examples.length === 0) return basePrompt;
|
|
91
|
+
return `${basePrompt}
|
|
62
92
|
|
|
63
93
|
Here are some good examples for reference:
|
|
64
94
|
|
|
65
|
-
${
|
|
95
|
+
${examples.join("\n\n")}
|
|
66
96
|
|
|
67
|
-
|
|
97
|
+
Follow this structure and quality level.`;
|
|
98
|
+
}
|
|
68
99
|
|
|
69
|
-
|
|
100
|
+
//#endregion
|
|
101
|
+
export { addExampleContext, buildEventSpecPrompt, buildOperationSpecPrompt, buildPresentationSpecPrompt, getSystemPrompt };
|
|
@@ -1,2 +1,84 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
//#region src/analysis/deps/graph.ts
|
|
2
|
+
/**
|
|
3
|
+
* Build reverse edges (dependents) for all nodes in the graph.
|
|
4
|
+
*/
|
|
5
|
+
function buildReverseEdges(graph) {
|
|
6
|
+
for (const node of graph.values()) node.dependents = [];
|
|
7
|
+
for (const [name, node] of graph) for (const dep of node.dependencies) {
|
|
8
|
+
const depNode = graph.get(dep);
|
|
9
|
+
if (depNode) depNode.dependents.push(name);
|
|
10
|
+
}
|
|
11
|
+
for (const node of graph.values()) node.dependents.sort((a, b) => a.localeCompare(b));
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Detect circular dependencies in the graph.
|
|
15
|
+
*/
|
|
16
|
+
function detectCycles(graph) {
|
|
17
|
+
const visited = /* @__PURE__ */ new Set();
|
|
18
|
+
const stack = /* @__PURE__ */ new Set();
|
|
19
|
+
const cycles = [];
|
|
20
|
+
function dfs(name, path) {
|
|
21
|
+
if (stack.has(name)) {
|
|
22
|
+
const start = path.indexOf(name);
|
|
23
|
+
if (start >= 0) cycles.push([...path.slice(start), name]);
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
if (visited.has(name)) return;
|
|
27
|
+
visited.add(name);
|
|
28
|
+
stack.add(name);
|
|
29
|
+
const node = graph.get(name);
|
|
30
|
+
if (node) for (const dep of node.dependencies) dfs(dep, [...path, name]);
|
|
31
|
+
stack.delete(name);
|
|
32
|
+
}
|
|
33
|
+
for (const name of graph.keys()) if (!visited.has(name)) dfs(name, []);
|
|
34
|
+
return cycles;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Find missing dependencies (referenced but not defined).
|
|
38
|
+
*/
|
|
39
|
+
function findMissingDependencies(graph) {
|
|
40
|
+
const missing = [];
|
|
41
|
+
for (const [name, node] of graph) {
|
|
42
|
+
const absent = node.dependencies.filter((dep) => !graph.has(dep));
|
|
43
|
+
if (absent.length > 0) missing.push({
|
|
44
|
+
contract: name,
|
|
45
|
+
missing: absent
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
return missing;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Generate DOT format output for visualization.
|
|
52
|
+
*/
|
|
53
|
+
function toDot(graph) {
|
|
54
|
+
const lines = [];
|
|
55
|
+
lines.push("digraph ContractDependencies {");
|
|
56
|
+
lines.push(" rankdir=LR;");
|
|
57
|
+
lines.push(" node [shape=box];");
|
|
58
|
+
for (const [name, node] of graph) {
|
|
59
|
+
for (const dep of node.dependencies) lines.push(` "${name}" -> "${dep}";`);
|
|
60
|
+
if (node.dependencies.length === 0) lines.push(` "${name}";`);
|
|
61
|
+
}
|
|
62
|
+
lines.push("}");
|
|
63
|
+
return lines.join("\n");
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Create an empty contract graph.
|
|
67
|
+
*/
|
|
68
|
+
function createContractGraph() {
|
|
69
|
+
return /* @__PURE__ */ new Map();
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Add a node to the contract graph.
|
|
73
|
+
*/
|
|
74
|
+
function addContractNode(graph, name, file, dependencies) {
|
|
75
|
+
graph.set(name, {
|
|
76
|
+
name,
|
|
77
|
+
file,
|
|
78
|
+
dependencies,
|
|
79
|
+
dependents: []
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
//#endregion
|
|
84
|
+
export { addContractNode, buildReverseEdges, createContractGraph, detectCycles, findMissingDependencies, toDot };
|
|
@@ -1 +1,30 @@
|
|
|
1
|
-
|
|
1
|
+
//#region src/analysis/deps/parse-imports.ts
|
|
2
|
+
/**
|
|
3
|
+
* Import parsing utilities for dependency analysis.
|
|
4
|
+
* Extracted from cli-contracts/src/commands/deps/parse-imports.ts
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Parse spec imports from source code.
|
|
8
|
+
* Returns the names of imported specs based on file naming conventions.
|
|
9
|
+
*
|
|
10
|
+
* @param sourceCode - The source code to parse
|
|
11
|
+
* @param fromFilePath - The path of the file being parsed (for relative resolution)
|
|
12
|
+
* @returns Array of imported spec names
|
|
13
|
+
*/
|
|
14
|
+
function parseImportedSpecNames(sourceCode, _fromFilePath) {
|
|
15
|
+
const imports = [];
|
|
16
|
+
const importRegex = /import\s+.*?\s+from\s+['"]([^'"]+\.(?:contracts|event|presentation|workflow|data-view|migration|telemetry|experiment|app-config|integration|knowledge)(?:\.[jt]s)?)['"]/g;
|
|
17
|
+
let match;
|
|
18
|
+
while ((match = importRegex.exec(sourceCode)) !== null) {
|
|
19
|
+
const importPath = match[1];
|
|
20
|
+
if (!importPath) continue;
|
|
21
|
+
if (!importPath.startsWith(".") && !importPath.startsWith("/")) continue;
|
|
22
|
+
const pathParts = importPath.split("/");
|
|
23
|
+
const name = (pathParts[pathParts.length - 1] ?? "").replace(/\.(ts|js)$/, "").replace(/\.(contracts|event|presentation|workflow|data-view|migration|telemetry|experiment|app-config|integration|knowledge)$/, "");
|
|
24
|
+
if (name.length > 0) imports.push(name);
|
|
25
|
+
}
|
|
26
|
+
return Array.from(new Set(imports)).sort((a, b) => a.localeCompare(b));
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
//#endregion
|
|
30
|
+
export { parseImportedSpecNames };
|
|
@@ -1 +1,96 @@
|
|
|
1
|
-
import{scanSpecSource
|
|
1
|
+
import { scanSpecSource } from "../spec-scan.js";
|
|
2
|
+
|
|
3
|
+
//#region src/analysis/diff/semantic.ts
|
|
4
|
+
/**
|
|
5
|
+
* Compute semantic differences between two spec sources.
|
|
6
|
+
*/
|
|
7
|
+
function computeSemanticDiff(aCode, aPath, bCode, bPath, options = {}) {
|
|
8
|
+
const a = scanSpecSource(aCode, aPath);
|
|
9
|
+
const b = scanSpecSource(bCode, bPath);
|
|
10
|
+
const diffs = [];
|
|
11
|
+
compareScalar(diffs, "specType", a.specType, b.specType, {
|
|
12
|
+
breaking: true,
|
|
13
|
+
label: "Spec type"
|
|
14
|
+
});
|
|
15
|
+
compareScalar(diffs, "name", a.name, b.name, {
|
|
16
|
+
breaking: true,
|
|
17
|
+
label: "Name"
|
|
18
|
+
});
|
|
19
|
+
compareScalar(diffs, "version", a.version, b.version, {
|
|
20
|
+
breaking: true,
|
|
21
|
+
label: "Version"
|
|
22
|
+
});
|
|
23
|
+
compareScalar(diffs, "kind", a.kind, b.kind, {
|
|
24
|
+
breaking: true,
|
|
25
|
+
label: "Kind"
|
|
26
|
+
});
|
|
27
|
+
compareScalar(diffs, "stability", a.stability, b.stability, {
|
|
28
|
+
breaking: isStabilityDowngrade(a, b),
|
|
29
|
+
label: "Stability"
|
|
30
|
+
});
|
|
31
|
+
compareArray(diffs, "owners", a.owners ?? [], b.owners ?? [], { label: "Owners" });
|
|
32
|
+
compareArray(diffs, "tags", a.tags ?? [], b.tags ?? [], { label: "Tags" });
|
|
33
|
+
compareStructuralHints(diffs, a, b);
|
|
34
|
+
return options.breakingOnly ? diffs.filter((d) => d.type === "breaking") : diffs;
|
|
35
|
+
}
|
|
36
|
+
function compareScalar(diffs, path, a, b, config) {
|
|
37
|
+
if (a === b) return;
|
|
38
|
+
diffs.push({
|
|
39
|
+
type: config.breaking ? "breaking" : "changed",
|
|
40
|
+
path,
|
|
41
|
+
oldValue: a,
|
|
42
|
+
newValue: b,
|
|
43
|
+
description: `${config.label} changed`
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
function compareArray(diffs, path, a, b, config) {
|
|
47
|
+
const aSorted = [...a].sort();
|
|
48
|
+
const bSorted = [...b].sort();
|
|
49
|
+
if (JSON.stringify(aSorted) === JSON.stringify(bSorted)) return;
|
|
50
|
+
diffs.push({
|
|
51
|
+
type: "changed",
|
|
52
|
+
path,
|
|
53
|
+
oldValue: aSorted,
|
|
54
|
+
newValue: bSorted,
|
|
55
|
+
description: `${config.label} changed`
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
function isStabilityDowngrade(a, b) {
|
|
59
|
+
const order = {
|
|
60
|
+
experimental: 0,
|
|
61
|
+
beta: 1,
|
|
62
|
+
stable: 2,
|
|
63
|
+
deprecated: 3
|
|
64
|
+
};
|
|
65
|
+
const aValue = a.stability ? order[a.stability] ?? 0 : 0;
|
|
66
|
+
return (b.stability ? order[b.stability] ?? 0 : 0) > aValue;
|
|
67
|
+
}
|
|
68
|
+
function compareStructuralHints(diffs, a, b) {
|
|
69
|
+
compareScalar(diffs, "hasMeta", a.hasMeta, b.hasMeta, {
|
|
70
|
+
breaking: a.specType === "operation" || b.specType === "operation",
|
|
71
|
+
label: "meta section presence"
|
|
72
|
+
});
|
|
73
|
+
compareScalar(diffs, "hasIo", a.hasIo, b.hasIo, {
|
|
74
|
+
breaking: a.specType === "operation" || b.specType === "operation",
|
|
75
|
+
label: "io section presence"
|
|
76
|
+
});
|
|
77
|
+
compareScalar(diffs, "hasPolicy", a.hasPolicy, b.hasPolicy, {
|
|
78
|
+
breaking: a.specType === "operation" || b.specType === "operation",
|
|
79
|
+
label: "policy section presence"
|
|
80
|
+
});
|
|
81
|
+
compareScalar(diffs, "hasPayload", a.hasPayload, b.hasPayload, {
|
|
82
|
+
breaking: a.specType === "event" || b.specType === "event",
|
|
83
|
+
label: "payload section presence"
|
|
84
|
+
});
|
|
85
|
+
compareScalar(diffs, "hasContent", a.hasContent, b.hasContent, {
|
|
86
|
+
breaking: a.specType === "presentation" || b.specType === "presentation",
|
|
87
|
+
label: "content section presence"
|
|
88
|
+
});
|
|
89
|
+
compareScalar(diffs, "hasDefinition", a.hasDefinition, b.hasDefinition, {
|
|
90
|
+
breaking: a.specType === "workflow" || b.specType === "workflow",
|
|
91
|
+
label: "definition section presence"
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
//#endregion
|
|
96
|
+
export { computeSemanticDiff };
|
|
@@ -1 +1,151 @@
|
|
|
1
|
-
|
|
1
|
+
//#region src/analysis/feature-scan.ts
|
|
2
|
+
/**
|
|
3
|
+
* Check if a file is a feature file based on naming conventions.
|
|
4
|
+
*/
|
|
5
|
+
function isFeatureFile(filePath) {
|
|
6
|
+
return filePath.includes(".feature.");
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Scan a feature source file to extract metadata.
|
|
10
|
+
*/
|
|
11
|
+
function scanFeatureSource(code, filePath) {
|
|
12
|
+
const key = matchStringField(code, "key") ?? extractKeyFromFilePath(filePath);
|
|
13
|
+
const title = matchStringField(code, "title") ?? void 0;
|
|
14
|
+
const description = matchStringField(code, "description") ?? void 0;
|
|
15
|
+
const domain = matchStringField(code, "domain") ?? void 0;
|
|
16
|
+
const stabilityRaw = matchStringField(code, "stability");
|
|
17
|
+
return {
|
|
18
|
+
filePath,
|
|
19
|
+
key,
|
|
20
|
+
title,
|
|
21
|
+
description,
|
|
22
|
+
domain,
|
|
23
|
+
stability: isStability(stabilityRaw) ? stabilityRaw : void 0,
|
|
24
|
+
owners: matchStringArrayField(code, "owners"),
|
|
25
|
+
tags: matchStringArrayField(code, "tags"),
|
|
26
|
+
operations: extractRefsFromArray(code, "operations"),
|
|
27
|
+
events: extractRefsFromArray(code, "events"),
|
|
28
|
+
presentations: extractRefsFromArray(code, "presentations"),
|
|
29
|
+
experiments: extractRefsFromArray(code, "experiments"),
|
|
30
|
+
capabilities: extractCapabilities(code),
|
|
31
|
+
opToPresentationLinks: extractOpToPresentationLinks(code)
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Extract refs from a named array (e.g., operations, events, presentations).
|
|
36
|
+
*/
|
|
37
|
+
function extractRefsFromArray(code, fieldName) {
|
|
38
|
+
const refs = [];
|
|
39
|
+
const arrayPattern = new RegExp(`${escapeRegex(fieldName)}\\s*:\\s*\\[([\\s\\S]*?)\\]`, "m");
|
|
40
|
+
const arrayMatch = code.match(arrayPattern);
|
|
41
|
+
if (!arrayMatch?.[1]) return refs;
|
|
42
|
+
const refPattern = /\{\s*name:\s*['"]([^'"]+)['"]\s*,\s*version:\s*(\d+)/g;
|
|
43
|
+
let match;
|
|
44
|
+
while ((match = refPattern.exec(arrayMatch[1])) !== null) if (match[1] && match[2]) refs.push({
|
|
45
|
+
name: match[1],
|
|
46
|
+
version: Number(match[2])
|
|
47
|
+
});
|
|
48
|
+
return refs;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Extract capability bindings (provides and requires).
|
|
52
|
+
*/
|
|
53
|
+
function extractCapabilities(code) {
|
|
54
|
+
const provides = [];
|
|
55
|
+
const requires = [];
|
|
56
|
+
const capabilitiesMatch = code.match(/capabilities\s*:\s*\{([\s\S]*?)\}/);
|
|
57
|
+
if (!capabilitiesMatch?.[1]) return {
|
|
58
|
+
provides,
|
|
59
|
+
requires
|
|
60
|
+
};
|
|
61
|
+
const capabilitiesContent = capabilitiesMatch[1];
|
|
62
|
+
const providesMatch = capabilitiesContent.match(/provides\s*:\s*\[([\s\S]*?)\]/);
|
|
63
|
+
if (providesMatch?.[1]) {
|
|
64
|
+
const refPattern = /\{\s*key:\s*['"]([^'"]+)['"]\s*,\s*version:\s*(\d+)/g;
|
|
65
|
+
let match;
|
|
66
|
+
while ((match = refPattern.exec(providesMatch[1])) !== null) if (match[1] && match[2]) provides.push({
|
|
67
|
+
name: match[1],
|
|
68
|
+
version: Number(match[2])
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
const requiresMatch = capabilitiesContent.match(/requires\s*:\s*\[([\s\S]*?)\]/);
|
|
72
|
+
if (requiresMatch?.[1]) {
|
|
73
|
+
const refPatternWithVersion = /\{\s*key:\s*['"]([^'"]+)['"]\s*,\s*version:\s*(\d+)/g;
|
|
74
|
+
const refPatternKeyOnly = /\{\s*key:\s*['"]([^'"]+)['"]\s*\}/g;
|
|
75
|
+
let match = null;
|
|
76
|
+
while ((match = refPatternWithVersion.exec(requiresMatch[1])) !== null) if (match[1] && match[2]) requires.push({
|
|
77
|
+
name: match[1],
|
|
78
|
+
version: Number(match[2])
|
|
79
|
+
});
|
|
80
|
+
while ((match = refPatternKeyOnly.exec(requiresMatch[1])) !== null) if (match && match[1]) {
|
|
81
|
+
if (!requires.some((r) => r.name === match[1])) requires.push({
|
|
82
|
+
name: match[1],
|
|
83
|
+
version: 1
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
return {
|
|
88
|
+
provides,
|
|
89
|
+
requires
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Extract opToPresentation links.
|
|
94
|
+
*/
|
|
95
|
+
function extractOpToPresentationLinks(code) {
|
|
96
|
+
const links = [];
|
|
97
|
+
const arrayMatch = code.match(/opToPresentation\s*:\s*\[([\s\S]*?)\]/);
|
|
98
|
+
if (!arrayMatch?.[1]) return links;
|
|
99
|
+
const linkPattern = /\{\s*op:\s*\{\s*name:\s*['"]([^'"]+)['"]\s*,\s*version:\s*(\d+)\s*\}\s*,\s*pres:\s*\{\s*name:\s*['"]([^'"]+)['"]\s*,\s*version:\s*(\d+)\s*\}/g;
|
|
100
|
+
let match;
|
|
101
|
+
while ((match = linkPattern.exec(arrayMatch[1])) !== null) if (match[1] && match[2] && match[3] && match[4]) links.push({
|
|
102
|
+
op: {
|
|
103
|
+
name: match[1],
|
|
104
|
+
version: Number(match[2])
|
|
105
|
+
},
|
|
106
|
+
pres: {
|
|
107
|
+
name: match[3],
|
|
108
|
+
version: Number(match[4])
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
return links;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Extract key from file path as fallback.
|
|
115
|
+
*/
|
|
116
|
+
function extractKeyFromFilePath(filePath) {
|
|
117
|
+
return (filePath.split("/").pop() ?? filePath).replace(/\.feature\.[jt]s$/, "").replace(/[^a-zA-Z0-9-]/g, "-");
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Match a string field in source code.
|
|
121
|
+
*/
|
|
122
|
+
function matchStringField(code, field) {
|
|
123
|
+
const regex = /* @__PURE__ */ new RegExp(`${escapeRegex(field)}\\s*:\\s*['"]([^'"]+)['"]`);
|
|
124
|
+
return code.match(regex)?.[1] ?? null;
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Match a string array field in source code.
|
|
128
|
+
*/
|
|
129
|
+
function matchStringArrayField(code, field) {
|
|
130
|
+
const regex = /* @__PURE__ */ new RegExp(`${escapeRegex(field)}\\s*:\\s*\\[([\\s\\S]*?)\\]`);
|
|
131
|
+
const match = code.match(regex);
|
|
132
|
+
if (!match?.[1]) return void 0;
|
|
133
|
+
const inner = match[1];
|
|
134
|
+
const items = Array.from(inner.matchAll(/['"]([^'"]+)['"]/g)).map((m) => m[1]).filter((value) => typeof value === "string" && value.length > 0);
|
|
135
|
+
return items.length > 0 ? items : void 0;
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Check if a value is a valid stability.
|
|
139
|
+
*/
|
|
140
|
+
function isStability(value) {
|
|
141
|
+
return value === "experimental" || value === "beta" || value === "stable" || value === "deprecated";
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Escape regex special characters.
|
|
145
|
+
*/
|
|
146
|
+
function escapeRegex(value) {
|
|
147
|
+
return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
//#endregion
|
|
151
|
+
export { isFeatureFile, scanFeatureSource };
|