@contractspec/module.workspace 1.44.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +50 -0
- package/dist/ai/code-generation.d.ts +28 -0
- package/dist/ai/code-generation.d.ts.map +1 -0
- package/dist/ai/code-generation.js +138 -0
- package/dist/ai/code-generation.js.map +1 -0
- package/dist/ai/spec-creation.d.ts +27 -0
- package/dist/ai/spec-creation.d.ts.map +1 -0
- package/dist/ai/spec-creation.js +102 -0
- package/dist/ai/spec-creation.js.map +1 -0
- package/dist/analysis/deps/graph.d.ts +34 -0
- package/dist/analysis/deps/graph.d.ts.map +1 -0
- package/dist/analysis/deps/graph.js +85 -0
- package/dist/analysis/deps/graph.js.map +1 -0
- package/dist/analysis/deps/parse-imports.d.ts +17 -0
- package/dist/analysis/deps/parse-imports.d.ts.map +1 -0
- package/dist/analysis/deps/parse-imports.js +31 -0
- package/dist/analysis/deps/parse-imports.js.map +1 -0
- package/dist/analysis/diff/deep-diff.d.ts +33 -0
- package/dist/analysis/diff/deep-diff.d.ts.map +1 -0
- package/dist/analysis/diff/deep-diff.js +114 -0
- package/dist/analysis/diff/deep-diff.js.map +1 -0
- package/dist/analysis/diff/semantic.d.ts +11 -0
- package/dist/analysis/diff/semantic.d.ts.map +1 -0
- package/dist/analysis/diff/semantic.js +97 -0
- package/dist/analysis/diff/semantic.js.map +1 -0
- package/dist/analysis/feature-scan.d.ts +15 -0
- package/dist/analysis/feature-scan.d.ts.map +1 -0
- package/dist/analysis/feature-scan.js +152 -0
- package/dist/analysis/feature-scan.js.map +1 -0
- package/dist/analysis/grouping.d.ts +79 -0
- package/dist/analysis/grouping.d.ts.map +1 -0
- package/dist/analysis/grouping.js +115 -0
- package/dist/analysis/grouping.js.map +1 -0
- package/dist/analysis/impact/classifier.d.ts +19 -0
- package/dist/analysis/impact/classifier.d.ts.map +1 -0
- package/dist/analysis/impact/classifier.js +135 -0
- package/dist/analysis/impact/classifier.js.map +1 -0
- package/dist/analysis/impact/index.js +2 -0
- package/dist/analysis/impact/rules.d.ts +35 -0
- package/dist/analysis/impact/rules.d.ts.map +1 -0
- package/dist/analysis/impact/rules.js +154 -0
- package/dist/analysis/impact/rules.js.map +1 -0
- package/dist/analysis/impact/types.d.ts +95 -0
- package/dist/analysis/impact/types.d.ts.map +1 -0
- package/dist/analysis/index.js +14 -0
- package/dist/analysis/snapshot/index.js +2 -0
- package/dist/analysis/snapshot/normalizer.d.ts +36 -0
- package/dist/analysis/snapshot/normalizer.d.ts.map +1 -0
- package/dist/analysis/snapshot/normalizer.js +66 -0
- package/dist/analysis/snapshot/normalizer.js.map +1 -0
- package/dist/analysis/snapshot/snapshot.d.ts +18 -0
- package/dist/analysis/snapshot/snapshot.d.ts.map +1 -0
- package/dist/analysis/snapshot/snapshot.js +163 -0
- package/dist/analysis/snapshot/snapshot.js.map +1 -0
- package/dist/analysis/snapshot/types.d.ts +80 -0
- package/dist/analysis/snapshot/types.d.ts.map +1 -0
- package/dist/analysis/spec-scan.d.ts +34 -0
- package/dist/analysis/spec-scan.d.ts.map +1 -0
- package/dist/analysis/spec-scan.js +349 -0
- package/dist/analysis/spec-scan.js.map +1 -0
- package/dist/analysis/validate/spec-structure.d.ts +29 -0
- package/dist/analysis/validate/spec-structure.d.ts.map +1 -0
- package/dist/analysis/validate/spec-structure.js +139 -0
- package/dist/analysis/validate/spec-structure.js.map +1 -0
- package/dist/formatter.d.ts +42 -0
- package/dist/formatter.d.ts.map +1 -0
- package/dist/formatter.js +163 -0
- package/dist/formatter.js.map +1 -0
- package/dist/index.d.ts +35 -0
- package/dist/index.js +33 -0
- package/dist/templates/app-config.d.ts +7 -0
- package/dist/templates/app-config.d.ts.map +1 -0
- package/dist/templates/app-config.js +106 -0
- package/dist/templates/app-config.js.map +1 -0
- package/dist/templates/data-view.d.ts +7 -0
- package/dist/templates/data-view.d.ts.map +1 -0
- package/dist/templates/data-view.js +69 -0
- package/dist/templates/data-view.js.map +1 -0
- package/dist/templates/event.d.ts +11 -0
- package/dist/templates/event.d.ts.map +1 -0
- package/dist/templates/event.js +41 -0
- package/dist/templates/event.js.map +1 -0
- package/dist/templates/experiment.d.ts +7 -0
- package/dist/templates/experiment.d.ts.map +1 -0
- package/dist/templates/experiment.js +88 -0
- package/dist/templates/experiment.js.map +1 -0
- package/dist/templates/handler.d.ts +20 -0
- package/dist/templates/handler.d.ts.map +1 -0
- package/dist/templates/handler.js +96 -0
- package/dist/templates/handler.js.map +1 -0
- package/dist/templates/integration-utils.js +105 -0
- package/dist/templates/integration-utils.js.map +1 -0
- package/dist/templates/integration.d.ts +7 -0
- package/dist/templates/integration.d.ts.map +1 -0
- package/dist/templates/integration.js +63 -0
- package/dist/templates/integration.js.map +1 -0
- package/dist/templates/knowledge.d.ts +7 -0
- package/dist/templates/knowledge.d.ts.map +1 -0
- package/dist/templates/knowledge.js +69 -0
- package/dist/templates/knowledge.js.map +1 -0
- package/dist/templates/migration.d.ts +7 -0
- package/dist/templates/migration.d.ts.map +1 -0
- package/dist/templates/migration.js +61 -0
- package/dist/templates/migration.js.map +1 -0
- package/dist/templates/operation.d.ts +11 -0
- package/dist/templates/operation.d.ts.map +1 -0
- package/dist/templates/operation.js +101 -0
- package/dist/templates/operation.js.map +1 -0
- package/dist/templates/presentation.d.ts +11 -0
- package/dist/templates/presentation.d.ts.map +1 -0
- package/dist/templates/presentation.js +79 -0
- package/dist/templates/presentation.js.map +1 -0
- package/dist/templates/telemetry.d.ts +7 -0
- package/dist/templates/telemetry.d.ts.map +1 -0
- package/dist/templates/telemetry.js +90 -0
- package/dist/templates/telemetry.js.map +1 -0
- package/dist/templates/utils.d.ts +27 -0
- package/dist/templates/utils.d.ts.map +1 -0
- package/dist/templates/utils.js +39 -0
- package/dist/templates/utils.js.map +1 -0
- package/dist/templates/workflow-runner.d.ts +16 -0
- package/dist/templates/workflow-runner.d.ts.map +1 -0
- package/dist/templates/workflow-runner.js +49 -0
- package/dist/templates/workflow-runner.js.map +1 -0
- package/dist/templates/workflow.d.ts +11 -0
- package/dist/templates/workflow.d.ts.map +1 -0
- package/dist/templates/workflow.js +68 -0
- package/dist/templates/workflow.js.map +1 -0
- package/dist/types/analysis-types.d.ts +126 -0
- package/dist/types/analysis-types.d.ts.map +1 -0
- package/dist/types/generation-types.d.ts +84 -0
- package/dist/types/generation-types.d.ts.map +1 -0
- package/dist/types/generation-types.js +21 -0
- package/dist/types/generation-types.js.map +1 -0
- package/dist/types/spec-types.d.ts +345 -0
- package/dist/types/spec-types.d.ts.map +1 -0
- package/package.json +55 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Chaman Ventures, SASU
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
# @contractspec/module.workspace
|
|
2
|
+
|
|
3
|
+
Website: https://contractspec.io/
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
Pure, deterministic domain logic and static analysis utilities for ContractSpec workspace operations.
|
|
7
|
+
|
|
8
|
+
## Purpose
|
|
9
|
+
|
|
10
|
+
This module contains platform-agnostic logic used by ContractSpec tooling:
|
|
11
|
+
|
|
12
|
+
- **Types**: Shared type definitions for specs, templates, and analysis results
|
|
13
|
+
- **Analysis**: Static code analysis (spec scanning, dependency graphs, semantic diff)
|
|
14
|
+
- **Templates**: Code generation templates for specs and handlers
|
|
15
|
+
- **AI Prompts**: Prompt builders for AI-assisted spec creation and code generation
|
|
16
|
+
|
|
17
|
+
## Design Principles
|
|
18
|
+
|
|
19
|
+
- **No side effects**: All functions are pure and deterministic
|
|
20
|
+
- **No CLI dependencies**: No `chalk`, `ora`, `commander`, or `inquirer`
|
|
21
|
+
- **No filesystem access**: Operations take code/data as input, return results
|
|
22
|
+
- **Reusable**: Can be used by CLI, web apps, VS Code extensions, etc.
|
|
23
|
+
|
|
24
|
+
## Usage
|
|
25
|
+
|
|
26
|
+
```typescript
|
|
27
|
+
import {
|
|
28
|
+
scanSpecSource,
|
|
29
|
+
computeSemanticDiff,
|
|
30
|
+
buildDependencyGraph,
|
|
31
|
+
validateSpecStructure,
|
|
32
|
+
generateOperationSpec,
|
|
33
|
+
} from '@contractspec/module.workspace';
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## Exports
|
|
37
|
+
|
|
38
|
+
- `analysis/` - Static analysis utilities
|
|
39
|
+
- `templates/` - Code generation templates
|
|
40
|
+
- `ai/` - AI prompt builders
|
|
41
|
+
- `types/` - Shared type definitions
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
//#region src/ai/code-generation.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* AI prompts for code generation.
|
|
4
|
+
* Extracted from cli-contractspec/src/ai/prompts/code-generation.ts
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Build prompt for generating handler implementation.
|
|
8
|
+
*/
|
|
9
|
+
declare function buildHandlerPrompt(specCode: string): string;
|
|
10
|
+
/**
|
|
11
|
+
* Build prompt for generating React component from presentation spec.
|
|
12
|
+
*/
|
|
13
|
+
declare function buildComponentPrompt(specCode: string): string;
|
|
14
|
+
/**
|
|
15
|
+
* Build prompt for generating form component.
|
|
16
|
+
*/
|
|
17
|
+
declare function buildFormPrompt(specCode: string): string;
|
|
18
|
+
/**
|
|
19
|
+
* Build prompt for generating tests.
|
|
20
|
+
*/
|
|
21
|
+
declare function buildTestPrompt(specCode: string, implementationCode: string, testType: 'handler' | 'component'): string;
|
|
22
|
+
/**
|
|
23
|
+
* System prompt for code generation.
|
|
24
|
+
*/
|
|
25
|
+
declare function getCodeGenSystemPrompt(): string;
|
|
26
|
+
//#endregion
|
|
27
|
+
export { buildComponentPrompt, buildFormPrompt, buildHandlerPrompt, buildTestPrompt, getCodeGenSystemPrompt };
|
|
28
|
+
//# sourceMappingURL=code-generation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"code-generation.d.ts","names":[],"sources":["../../src/ai/code-generation.ts"],"sourcesContent":[],"mappings":";;AAQA;AA0BA;AA0BA;AA2BA;AA2CA;;iBA1HgB,kBAAA;;;;iBA0BA,oBAAA;;;;iBA0BA,eAAA;;;;iBA2BA,eAAA;;;;iBA2CA,sBAAA,CAAA"}
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
//#region src/ai/code-generation.ts
|
|
2
|
+
/**
|
|
3
|
+
* AI prompts for code generation.
|
|
4
|
+
* Extracted from cli-contractspec/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.
|
|
11
|
+
|
|
12
|
+
Here is the contract spec:
|
|
13
|
+
|
|
14
|
+
\`\`\`typescript
|
|
15
|
+
${specCode}
|
|
16
|
+
\`\`\`
|
|
17
|
+
|
|
18
|
+
Generate a complete handler implementation that:
|
|
19
|
+
|
|
20
|
+
1. **Matches the spec signature**: Input/output types from the spec
|
|
21
|
+
2. **Handles errors**: Implement error cases defined in spec.io.errors
|
|
22
|
+
3. **Emits events**: Use the events declared in spec.sideEffects.emits
|
|
23
|
+
4. **Validates input**: Use zod validation from the schema
|
|
24
|
+
5. **Follows best practices**: Clean, type-safe TypeScript
|
|
25
|
+
6. **Includes comments**: Explain business logic
|
|
26
|
+
|
|
27
|
+
The handler should be production-ready with proper error handling, logging points, and clear structure.
|
|
28
|
+
|
|
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.
|
|
36
|
+
|
|
37
|
+
Here is the presentation spec:
|
|
38
|
+
|
|
39
|
+
\`\`\`typescript
|
|
40
|
+
${specCode}
|
|
41
|
+
\`\`\`
|
|
42
|
+
|
|
43
|
+
Generate a complete React component that:
|
|
44
|
+
|
|
45
|
+
1. **Props interface**: Typed props from the spec
|
|
46
|
+
2. **Accessibility**: Proper ARIA labels, roles, keyboard navigation
|
|
47
|
+
3. **Mobile-first**: Optimized for small screens and touch
|
|
48
|
+
4. **Clean UI**: Simple, intuitive interface
|
|
49
|
+
5. **Type-safe**: Full TypeScript with no 'any' types
|
|
50
|
+
6. **Best practices**: React hooks, proper state management
|
|
51
|
+
|
|
52
|
+
The component should follow Atomic Design principles and be reusable.
|
|
53
|
+
|
|
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.
|
|
61
|
+
|
|
62
|
+
Here is the form spec:
|
|
63
|
+
|
|
64
|
+
\`\`\`typescript
|
|
65
|
+
${specCode}
|
|
66
|
+
\`\`\`
|
|
67
|
+
|
|
68
|
+
Generate a complete form component using react-hook-form that:
|
|
69
|
+
|
|
70
|
+
1. **Form validation**: Use zod schema for validation
|
|
71
|
+
2. **Field types**: Proper inputs for each field type
|
|
72
|
+
3. **Conditional logic**: Support visibleWhen, enabledWhen, requiredWhen predicates
|
|
73
|
+
4. **Error handling**: Clear, user-friendly error messages
|
|
74
|
+
5. **Accessibility**: Labels, hints, ARIA attributes
|
|
75
|
+
6. **Mobile-optimized**: Touch-friendly, appropriate input types
|
|
76
|
+
7. **Type-safe**: Full TypeScript
|
|
77
|
+
|
|
78
|
+
The form should provide excellent UX with real-time validation and helpful feedback.
|
|
79
|
+
|
|
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.
|
|
87
|
+
|
|
88
|
+
Spec:
|
|
89
|
+
\`\`\`typescript
|
|
90
|
+
${specCode}
|
|
91
|
+
\`\`\`
|
|
92
|
+
|
|
93
|
+
Implementation:
|
|
94
|
+
\`\`\`typescript
|
|
95
|
+
${implementationCode}
|
|
96
|
+
\`\`\`
|
|
97
|
+
|
|
98
|
+
Generate complete test suite using Vitest that:
|
|
99
|
+
${testType === "handler" ? `
|
|
100
|
+
- Test all acceptance scenarios from the spec
|
|
101
|
+
- Test error cases defined in spec.io.errors
|
|
102
|
+
- Verify events are emitted correctly
|
|
103
|
+
- Test input validation
|
|
104
|
+
- Test happy path and edge cases` : `
|
|
105
|
+
- Test rendering with various props
|
|
106
|
+
- Test user interactions
|
|
107
|
+
- Test accessibility (a11y)
|
|
108
|
+
- Test responsive behavior
|
|
109
|
+
- Test error states`}
|
|
110
|
+
|
|
111
|
+
Use clear test descriptions and follow AAA pattern (Arrange, Act, Assert).
|
|
112
|
+
|
|
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:
|
|
120
|
+
- Type-safe API design
|
|
121
|
+
- React and modern hooks
|
|
122
|
+
- Test-driven development
|
|
123
|
+
- Accessibility best practices
|
|
124
|
+
- Clean code principles
|
|
125
|
+
|
|
126
|
+
Generate production-ready code that is:
|
|
127
|
+
- Fully typed (no 'any' or type assertions unless absolutely necessary)
|
|
128
|
+
- Well-documented with TSDoc comments
|
|
129
|
+
- Following project conventions
|
|
130
|
+
- Defensive and error-safe
|
|
131
|
+
- Easy to maintain and extend
|
|
132
|
+
|
|
133
|
+
Always prioritize code quality, safety, and user experience.`;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
//#endregion
|
|
137
|
+
export { buildComponentPrompt, buildFormPrompt, buildHandlerPrompt, buildTestPrompt, getCodeGenSystemPrompt };
|
|
138
|
+
//# sourceMappingURL=code-generation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"code-generation.js","names":[],"sources":["../../src/ai/code-generation.ts"],"sourcesContent":["/**\n * AI prompts for code generation.\n * Extracted from cli-contractspec/src/ai/prompts/code-generation.ts\n */\n\n/**\n * Build prompt for generating handler implementation.\n */\nexport function buildHandlerPrompt(specCode: string): string {\n return `You are a senior TypeScript developer implementing a handler for a contract specification.\n\nHere is the contract spec:\n\n\\`\\`\\`typescript\n${specCode}\n\\`\\`\\`\n\nGenerate a complete handler implementation that:\n\n1. **Matches the spec signature**: Input/output types from the spec\n2. **Handles errors**: Implement error cases defined in spec.io.errors\n3. **Emits events**: Use the events declared in spec.sideEffects.emits\n4. **Validates input**: Use zod validation from the schema\n5. **Follows best practices**: Clean, type-safe TypeScript\n6. **Includes comments**: Explain business logic\n\nThe handler should be production-ready with proper error handling, logging points, and clear structure.\n\nReturn only the TypeScript code for the handler function.`;\n}\n\n/**\n * Build prompt for generating React component from presentation spec.\n */\nexport function buildComponentPrompt(specCode: string): string {\n return `You are a senior React developer creating a component for a presentation specification.\n\nHere is the presentation spec:\n\n\\`\\`\\`typescript\n${specCode}\n\\`\\`\\`\n\nGenerate a complete React component that:\n\n1. **Props interface**: Typed props from the spec\n2. **Accessibility**: Proper ARIA labels, roles, keyboard navigation\n3. **Mobile-first**: Optimized for small screens and touch\n4. **Clean UI**: Simple, intuitive interface\n5. **Type-safe**: Full TypeScript with no 'any' types\n6. **Best practices**: React hooks, proper state management\n\nThe component should follow Atomic Design principles and be reusable.\n\nReturn only the TypeScript/TSX code for the component.`;\n}\n\n/**\n * Build prompt for generating form component.\n */\nexport function buildFormPrompt(specCode: string): string {\n return `You are a senior React developer creating a form component from a form specification.\n\nHere is the form spec:\n\n\\`\\`\\`typescript\n${specCode}\n\\`\\`\\`\n\nGenerate a complete form component using react-hook-form that:\n\n1. **Form validation**: Use zod schema for validation\n2. **Field types**: Proper inputs for each field type\n3. **Conditional logic**: Support visibleWhen, enabledWhen, requiredWhen predicates\n4. **Error handling**: Clear, user-friendly error messages\n5. **Accessibility**: Labels, hints, ARIA attributes\n6. **Mobile-optimized**: Touch-friendly, appropriate input types\n7. **Type-safe**: Full TypeScript\n\nThe form should provide excellent UX with real-time validation and helpful feedback.\n\nReturn only the TypeScript/TSX code for the form component.`;\n}\n\n/**\n * Build prompt for generating tests.\n */\nexport function buildTestPrompt(\n specCode: string,\n implementationCode: string,\n testType: 'handler' | 'component'\n): string {\n const testFocus =\n testType === 'handler'\n ? `\n - Test all acceptance scenarios from the spec\n - Test error cases defined in spec.io.errors\n - Verify events are emitted correctly\n - Test input validation\n - Test happy path and edge cases`\n : `\n - Test rendering with various props\n - Test user interactions\n - Test accessibility (a11y)\n - Test responsive behavior\n - Test error states`;\n\n return `You are a senior developer writing comprehensive tests.\n\nSpec:\n\\`\\`\\`typescript\n${specCode}\n\\`\\`\\`\n\nImplementation:\n\\`\\`\\`typescript\n${implementationCode}\n\\`\\`\\`\n\nGenerate complete test suite using Vitest that:\n${testFocus}\n\nUse clear test descriptions and follow AAA pattern (Arrange, Act, Assert).\n\nReturn only the TypeScript test code.`;\n}\n\n/**\n * System prompt for code generation.\n */\nexport function getCodeGenSystemPrompt(): string {\n return `You are an expert TypeScript developer with deep knowledge of:\n- Type-safe API design\n- React and modern hooks\n- Test-driven development\n- Accessibility best practices\n- Clean code principles\n\nGenerate production-ready code that is:\n- Fully typed (no 'any' or type assertions unless absolutely necessary)\n- Well-documented with TSDoc comments\n- Following project conventions\n- Defensive and error-safe\n- Easy to maintain and extend\n\nAlways prioritize code quality, safety, and user experience.`;\n}\n"],"mappings":";;;;;;;;AAQA,SAAgB,mBAAmB,UAA0B;AAC3D,QAAO;;;;;EAKP,SAAS;;;;;;;;;;;;;;;;;;;AAoBX,SAAgB,qBAAqB,UAA0B;AAC7D,QAAO;;;;;EAKP,SAAS;;;;;;;;;;;;;;;;;;;AAoBX,SAAgB,gBAAgB,UAA0B;AACxD,QAAO;;;;;EAKP,SAAS;;;;;;;;;;;;;;;;;;;;AAqBX,SAAgB,gBACd,UACA,oBACA,UACQ;AAgBR,QAAO;;;;EAIP,SAAS;;;;;EAKT,mBAAmB;;;;EAvBjB,aAAa,YACT;;;;;sCAMA;;;;;uBAoBI;;;;;;;;;AAUZ,SAAgB,yBAAiC;AAC/C,QAAO"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { OpKind, PresentationKind } from "../types/spec-types.js";
|
|
2
|
+
|
|
3
|
+
//#region src/ai/spec-creation.d.ts
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Build prompt for creating operation spec from description.
|
|
7
|
+
*/
|
|
8
|
+
declare function buildOperationSpecPrompt(description: string, kind: OpKind): string;
|
|
9
|
+
/**
|
|
10
|
+
* Build prompt for creating event spec from description.
|
|
11
|
+
*/
|
|
12
|
+
declare function buildEventSpecPrompt(description: string): string;
|
|
13
|
+
/**
|
|
14
|
+
* Build prompt for creating presentation spec from description.
|
|
15
|
+
*/
|
|
16
|
+
declare function buildPresentationSpecPrompt(description: string, kind: PresentationKind): string;
|
|
17
|
+
/**
|
|
18
|
+
* Build system prompt for all spec generation.
|
|
19
|
+
*/
|
|
20
|
+
declare function getSystemPrompt(): string;
|
|
21
|
+
/**
|
|
22
|
+
* Create example-based prompt for better results.
|
|
23
|
+
*/
|
|
24
|
+
declare function addExampleContext(basePrompt: string, examples: string[]): string;
|
|
25
|
+
//#endregion
|
|
26
|
+
export { addExampleContext, buildEventSpecPrompt, buildOperationSpecPrompt, buildPresentationSpecPrompt, getSystemPrompt };
|
|
27
|
+
//# sourceMappingURL=spec-creation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"spec-creation.d.ts","names":[],"sources":["../../src/ai/spec-creation.ts"],"sourcesContent":[],"mappings":";;;;AA2DA;AAoCA;AAiBA;iBAtGgB,wBAAA,4BAER;;;;iBA0BQ,oBAAA;;;;iBAqBA,2BAAA,4BAER;;;;iBAkCQ,eAAA,CAAA;;;;iBAiBA,iBAAA"}
|
|
@@ -0,0 +1,102 @@
|
|
|
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.
|
|
7
|
+
|
|
8
|
+
The operation is a ${kind} (${kind === "command" ? "changes state, has side effects" : "read-only, idempotent"}).
|
|
9
|
+
|
|
10
|
+
User description: ${description}
|
|
11
|
+
|
|
12
|
+
Create a complete contract specification following these guidelines:
|
|
13
|
+
|
|
14
|
+
1. **Name**: Use dot notation like "domain.operationName" (e.g., "user.signup", "payment.charge")
|
|
15
|
+
2. **Version**: Start at 1
|
|
16
|
+
3. **Description**: Clear, concise summary (1-2 sentences)
|
|
17
|
+
4. **Goal**: Business purpose - why this operation exists
|
|
18
|
+
5. **Context**: Background, constraints, scope (what it does and doesn't do)
|
|
19
|
+
6. **Input/Output**: Describe the shape (we'll create schemas separately)
|
|
20
|
+
7. **Auth**: Who can call this - anonymous, user, or admin
|
|
21
|
+
8. **Feature Flags**: Any flags that gate this operation
|
|
22
|
+
9. **Side Effects**: What events might be emitted, analytics to track
|
|
23
|
+
|
|
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.
|
|
31
|
+
|
|
32
|
+
User description: ${description}
|
|
33
|
+
|
|
34
|
+
Create a complete event specification following these guidelines:
|
|
35
|
+
|
|
36
|
+
1. **Name**: Use dot notation like "domain.event_name" (e.g., "user.signup_completed", "payment.charged")
|
|
37
|
+
2. **Version**: Start at 1
|
|
38
|
+
3. **Description**: Clear description of when this event is emitted
|
|
39
|
+
4. **Payload**: Describe what data the event carries
|
|
40
|
+
5. **PII Fields**: List any personally identifiable information fields (e.g., ["email", "name"])
|
|
41
|
+
|
|
42
|
+
Events represent things that have already happened and should use past tense.
|
|
43
|
+
|
|
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.
|
|
51
|
+
|
|
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]}.
|
|
57
|
+
|
|
58
|
+
User description: ${description}
|
|
59
|
+
|
|
60
|
+
Create a complete presentation specification following these guidelines:
|
|
61
|
+
|
|
62
|
+
1. **Name**: Use dot notation like "domain.presentation_name" (e.g., "user.profile_card", "docs.api_guide")
|
|
63
|
+
2. **Version**: Start at 1
|
|
64
|
+
3. **Description**: What this presentation shows/provides
|
|
65
|
+
4. **Kind-specific details**:
|
|
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"}
|
|
67
|
+
|
|
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.
|
|
75
|
+
|
|
76
|
+
You create clear, well-documented specifications that serve as the single source of truth for operations, events, and presentations.
|
|
77
|
+
|
|
78
|
+
Your specs are:
|
|
79
|
+
- Precise and unambiguous
|
|
80
|
+
- Following TypeScript conventions
|
|
81
|
+
- Business-oriented (capturing the "why" not just "what")
|
|
82
|
+
- Designed for both humans and AI agents to understand
|
|
83
|
+
|
|
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}
|
|
92
|
+
|
|
93
|
+
Here are some good examples for reference:
|
|
94
|
+
|
|
95
|
+
${examples.join("\n\n")}
|
|
96
|
+
|
|
97
|
+
Follow this structure and quality level.`;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
//#endregion
|
|
101
|
+
export { addExampleContext, buildEventSpecPrompt, buildOperationSpecPrompt, buildPresentationSpecPrompt, getSystemPrompt };
|
|
102
|
+
//# sourceMappingURL=spec-creation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"spec-creation.js","names":[],"sources":["../../src/ai/spec-creation.ts"],"sourcesContent":["/**\n * AI prompts for spec creation.\n * Extracted from cli-contractspec/src/ai/prompts/spec-creation.ts\n */\n\nimport type { OpKind, PresentationKind } from '../types/spec-types';\n\n/**\n * Build prompt for creating operation spec from description.\n */\nexport function buildOperationSpecPrompt(\n description: string,\n kind: OpKind\n): string {\n return `You are a senior software architect creating a contract specification for an operation.\n\nThe operation is a ${kind} (${kind === 'command' ? 'changes state, has side effects' : 'read-only, idempotent'}).\n\nUser description: ${description}\n\nCreate a complete contract specification following these guidelines:\n\n1. **Name**: Use dot notation like \"domain.operationName\" (e.g., \"user.signup\", \"payment.charge\")\n2. **Version**: Start at 1\n3. **Description**: Clear, concise summary (1-2 sentences)\n4. **Goal**: Business purpose - why this operation exists\n5. **Context**: Background, constraints, scope (what it does and doesn't do)\n6. **Input/Output**: Describe the shape (we'll create schemas separately)\n7. **Auth**: Who can call this - anonymous, user, or admin\n8. **Feature Flags**: Any flags that gate this operation\n9. **Side Effects**: What events might be emitted, analytics to track\n\nRespond with a structured spec.`;\n}\n\n/**\n * Build prompt for creating event spec from description.\n */\nexport function buildEventSpecPrompt(description: string): string {\n return `You are a senior software architect creating an event specification.\n\nUser description: ${description}\n\nCreate a complete event specification following these guidelines:\n\n1. **Name**: Use dot notation like \"domain.event_name\" (e.g., \"user.signup_completed\", \"payment.charged\")\n2. **Version**: Start at 1\n3. **Description**: Clear description of when this event is emitted\n4. **Payload**: Describe what data the event carries\n5. **PII Fields**: List any personally identifiable information fields (e.g., [\"email\", \"name\"])\n\nEvents represent things that have already happened and should use past tense.\n\nRespond with a structured spec.`;\n}\n\n/**\n * Build prompt for creating presentation spec from description.\n */\nexport function buildPresentationSpecPrompt(\n description: string,\n kind: PresentationKind\n): string {\n const kindDescriptions = {\n web_component: 'a React component with props schema',\n markdown: 'markdown/MDX documentation or guide',\n data: 'structured data export (JSON/XML)',\n };\n\n return `You are a senior software architect creating a presentation specification.\n\nThis is a ${kind} presentation - ${kindDescriptions[kind]}.\n\nUser description: ${description}\n\nCreate a complete presentation specification following these guidelines:\n\n1. **Name**: Use dot notation like \"domain.presentation_name\" (e.g., \"user.profile_card\", \"docs.api_guide\")\n2. **Version**: Start at 1\n3. **Description**: What this presentation shows/provides\n4. **Kind-specific details**:\n ${\n kind === 'web_component'\n ? '- Component key (symbolic, resolved by host app)\\n - Props structure\\n - Analytics events to track'\n : kind === 'markdown'\n ? '- Content or resource URI\\n - Target audience'\n : '- MIME type (e.g., application/json)\\n - Data structure description'\n }\n\nRespond with a structured spec.`;\n}\n\n/**\n * Build system prompt for all spec generation.\n */\nexport function getSystemPrompt(): string {\n return `You are an expert software architect specializing in API design and contract-driven development.\n\nYou create clear, well-documented specifications that serve as the single source of truth for operations, events, and presentations.\n\nYour specs are:\n- Precise and unambiguous\n- Following TypeScript conventions\n- Business-oriented (capturing the \"why\" not just \"what\")\n- Designed for both humans and AI agents to understand\n\nAlways use proper dot notation for names and ensure all metadata is meaningful and accurate.`;\n}\n\n/**\n * Create example-based prompt for better results.\n */\nexport function addExampleContext(\n basePrompt: string,\n examples: string[]\n): string {\n if (examples.length === 0) return basePrompt;\n\n return `${basePrompt}\n\nHere are some good examples for reference:\n\n${examples.join('\\n\\n')}\n\nFollow this structure and quality level.`;\n}\n"],"mappings":";;;;AAUA,SAAgB,yBACd,aACA,MACQ;AACR,QAAO;;qBAEY,KAAK,IAAI,SAAS,YAAY,oCAAoC,wBAAwB;;oBAE3F,YAAY;;;;;;;;;;;;;;;;;;;AAoBhC,SAAgB,qBAAqB,aAA6B;AAChE,QAAO;;oBAEW,YAAY;;;;;;;;;;;;;;;;;AAkBhC,SAAgB,4BACd,aACA,MACQ;AAOR,QAAO;;YAEG,KAAK,kBARU;EACvB,eAAe;EACf,UAAU;EACV,MAAM;EACP,CAIiD,MAAM;;oBAEtC,YAAY;;;;;;;;KAS3B,SAAS,kBACL,2GACA,SAAS,aACP,oDACA,wEACP;;;;;;;AAQJ,SAAgB,kBAA0B;AACxC,QAAO;;;;;;;;;;;;;;;AAgBT,SAAgB,kBACd,YACA,UACQ;AACR,KAAI,SAAS,WAAW,EAAG,QAAO;AAElC,QAAO,GAAG,WAAW;;;;EAIrB,SAAS,KAAK,OAAO,CAAC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { ContractGraph, ContractNode } from "../../types/analysis-types.js";
|
|
2
|
+
|
|
3
|
+
//#region src/analysis/deps/graph.d.ts
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Build reverse edges (dependents) for all nodes in the graph.
|
|
7
|
+
*/
|
|
8
|
+
declare function buildReverseEdges(graph: ContractGraph): void;
|
|
9
|
+
/**
|
|
10
|
+
* Detect circular dependencies in the graph.
|
|
11
|
+
*/
|
|
12
|
+
declare function detectCycles(graph: ContractGraph): string[][];
|
|
13
|
+
/**
|
|
14
|
+
* Find missing dependencies (referenced but not defined).
|
|
15
|
+
*/
|
|
16
|
+
declare function findMissingDependencies(graph: ContractGraph): {
|
|
17
|
+
contract: string;
|
|
18
|
+
missing: string[];
|
|
19
|
+
}[];
|
|
20
|
+
/**
|
|
21
|
+
* Generate DOT format output for visualization.
|
|
22
|
+
*/
|
|
23
|
+
declare function toDot(graph: ContractGraph): string;
|
|
24
|
+
/**
|
|
25
|
+
* Create an empty contract graph.
|
|
26
|
+
*/
|
|
27
|
+
declare function createContractGraph(): ContractGraph;
|
|
28
|
+
/**
|
|
29
|
+
* Add a node to the contract graph.
|
|
30
|
+
*/
|
|
31
|
+
declare function addContractNode(graph: ContractGraph, key: string, file: string, dependencies: string[]): void;
|
|
32
|
+
//#endregion
|
|
33
|
+
export { addContractNode, buildReverseEdges, createContractGraph, detectCycles, findMissingDependencies, toDot };
|
|
34
|
+
//# sourceMappingURL=graph.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"graph.d.ts","names":[],"sources":["../../../src/analysis/deps/graph.ts"],"sourcesContent":[],"mappings":";;;;AAwFA;AAsBA;AAOA;iBAzGgB,iBAAA,QAAyB;;;;iBAsBzB,YAAA,QAAoB;;;;iBAoCpB,uBAAA,QACP;;;;;;;iBAiBO,KAAA,QAAa;;;;iBAsBb,mBAAA,CAAA,GAAuB;;;;iBAOvB,eAAA,QACP"}
|
|
@@ -0,0 +1,85 @@
|
|
|
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 [key, node] of graph) for (const dep of node.dependencies) {
|
|
8
|
+
const depNode = graph.get(dep);
|
|
9
|
+
if (depNode) depNode.dependents.push(key);
|
|
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(key, path) {
|
|
21
|
+
if (stack.has(key)) {
|
|
22
|
+
const start = path.indexOf(key);
|
|
23
|
+
if (start >= 0) cycles.push([...path.slice(start), key]);
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
if (visited.has(key)) return;
|
|
27
|
+
visited.add(key);
|
|
28
|
+
stack.add(key);
|
|
29
|
+
const node = graph.get(key);
|
|
30
|
+
if (node) for (const dep of node.dependencies) dfs(dep, [...path, key]);
|
|
31
|
+
stack.delete(key);
|
|
32
|
+
}
|
|
33
|
+
for (const key of graph.keys()) if (!visited.has(key)) dfs(key, []);
|
|
34
|
+
return cycles;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Find missing dependencies (referenced but not defined).
|
|
38
|
+
*/
|
|
39
|
+
function findMissingDependencies(graph) {
|
|
40
|
+
const missing = [];
|
|
41
|
+
for (const [key, node] of graph) {
|
|
42
|
+
const absent = node.dependencies.filter((dep) => !graph.has(dep));
|
|
43
|
+
if (absent.length > 0) missing.push({
|
|
44
|
+
contract: key,
|
|
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 [key, node] of graph) {
|
|
59
|
+
for (const dep of node.dependencies) lines.push(` "${key}" -> "${dep}";`);
|
|
60
|
+
if (node.dependencies.length === 0) lines.push(` "${key}";`);
|
|
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, key, file, dependencies) {
|
|
75
|
+
graph.set(key, {
|
|
76
|
+
key,
|
|
77
|
+
file,
|
|
78
|
+
dependencies,
|
|
79
|
+
dependents: []
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
//#endregion
|
|
84
|
+
export { addContractNode, buildReverseEdges, createContractGraph, detectCycles, findMissingDependencies, toDot };
|
|
85
|
+
//# sourceMappingURL=graph.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"graph.js","names":["cycles: string[][]","missing: { contract: string; missing: string[] }[]","lines: string[]"],"sources":["../../../src/analysis/deps/graph.ts"],"sourcesContent":["/**\n * Contract dependency graph utilities.\n * Extracted from cli-contractspec/src/commands/deps/graph.ts\n */\n\nimport type { ContractNode, ContractGraph } from '../../types/analysis-types';\n\nexport type { ContractNode, ContractGraph };\n\n/**\n * Build reverse edges (dependents) for all nodes in the graph.\n */\nexport function buildReverseEdges(graph: ContractGraph): void {\n for (const node of graph.values()) {\n node.dependents = [];\n }\n\n for (const [key, node] of graph) {\n for (const dep of node.dependencies) {\n const depNode = graph.get(dep);\n if (depNode) {\n depNode.dependents.push(key);\n }\n }\n }\n\n for (const node of graph.values()) {\n node.dependents.sort((a, b) => a.localeCompare(b));\n }\n}\n\n/**\n * Detect circular dependencies in the graph.\n */\nexport function detectCycles(graph: ContractGraph): string[][] {\n const visited = new Set<string>();\n const stack = new Set<string>();\n const cycles: string[][] = [];\n\n function dfs(key: string, path: string[]) {\n if (stack.has(key)) {\n const start = path.indexOf(key);\n if (start >= 0) cycles.push([...path.slice(start), key]);\n return;\n }\n if (visited.has(key)) return;\n\n visited.add(key);\n stack.add(key);\n\n const node = graph.get(key);\n if (node) {\n for (const dep of node.dependencies) {\n dfs(dep, [...path, key]);\n }\n }\n\n stack.delete(key);\n }\n\n for (const key of graph.keys()) {\n if (!visited.has(key)) dfs(key, []);\n }\n\n return cycles;\n}\n\n/**\n * Find missing dependencies (referenced but not defined).\n */\nexport function findMissingDependencies(\n graph: ContractGraph\n): { contract: string; missing: string[] }[] {\n const missing: { contract: string; missing: string[] }[] = [];\n\n for (const [key, node] of graph) {\n const absent = node.dependencies.filter((dep) => !graph.has(dep));\n if (absent.length > 0) {\n missing.push({ contract: key, missing: absent });\n }\n }\n\n return missing;\n}\n\n/**\n * Generate DOT format output for visualization.\n */\nexport function toDot(graph: ContractGraph): string {\n const lines: string[] = [];\n lines.push('digraph ContractDependencies {');\n lines.push(' rankdir=LR;');\n lines.push(' node [shape=box];');\n\n for (const [key, node] of graph) {\n for (const dep of node.dependencies) {\n lines.push(` \"${key}\" -> \"${dep}\";`);\n }\n if (node.dependencies.length === 0) {\n lines.push(` \"${key}\";`);\n }\n }\n\n lines.push('}');\n return lines.join('\\n');\n}\n\n/**\n * Create an empty contract graph.\n */\nexport function createContractGraph(): ContractGraph {\n return new Map();\n}\n\n/**\n * Add a node to the contract graph.\n */\nexport function addContractNode(\n graph: ContractGraph,\n key: string,\n file: string,\n dependencies: string[]\n): void {\n graph.set(key, {\n key,\n file,\n dependencies,\n dependents: [],\n });\n}\n"],"mappings":";;;;AAYA,SAAgB,kBAAkB,OAA4B;AAC5D,MAAK,MAAM,QAAQ,MAAM,QAAQ,CAC/B,MAAK,aAAa,EAAE;AAGtB,MAAK,MAAM,CAAC,KAAK,SAAS,MACxB,MAAK,MAAM,OAAO,KAAK,cAAc;EACnC,MAAM,UAAU,MAAM,IAAI,IAAI;AAC9B,MAAI,QACF,SAAQ,WAAW,KAAK,IAAI;;AAKlC,MAAK,MAAM,QAAQ,MAAM,QAAQ,CAC/B,MAAK,WAAW,MAAM,GAAG,MAAM,EAAE,cAAc,EAAE,CAAC;;;;;AAOtD,SAAgB,aAAa,OAAkC;CAC7D,MAAM,0BAAU,IAAI,KAAa;CACjC,MAAM,wBAAQ,IAAI,KAAa;CAC/B,MAAMA,SAAqB,EAAE;CAE7B,SAAS,IAAI,KAAa,MAAgB;AACxC,MAAI,MAAM,IAAI,IAAI,EAAE;GAClB,MAAM,QAAQ,KAAK,QAAQ,IAAI;AAC/B,OAAI,SAAS,EAAG,QAAO,KAAK,CAAC,GAAG,KAAK,MAAM,MAAM,EAAE,IAAI,CAAC;AACxD;;AAEF,MAAI,QAAQ,IAAI,IAAI,CAAE;AAEtB,UAAQ,IAAI,IAAI;AAChB,QAAM,IAAI,IAAI;EAEd,MAAM,OAAO,MAAM,IAAI,IAAI;AAC3B,MAAI,KACF,MAAK,MAAM,OAAO,KAAK,aACrB,KAAI,KAAK,CAAC,GAAG,MAAM,IAAI,CAAC;AAI5B,QAAM,OAAO,IAAI;;AAGnB,MAAK,MAAM,OAAO,MAAM,MAAM,CAC5B,KAAI,CAAC,QAAQ,IAAI,IAAI,CAAE,KAAI,KAAK,EAAE,CAAC;AAGrC,QAAO;;;;;AAMT,SAAgB,wBACd,OAC2C;CAC3C,MAAMC,UAAqD,EAAE;AAE7D,MAAK,MAAM,CAAC,KAAK,SAAS,OAAO;EAC/B,MAAM,SAAS,KAAK,aAAa,QAAQ,QAAQ,CAAC,MAAM,IAAI,IAAI,CAAC;AACjE,MAAI,OAAO,SAAS,EAClB,SAAQ,KAAK;GAAE,UAAU;GAAK,SAAS;GAAQ,CAAC;;AAIpD,QAAO;;;;;AAMT,SAAgB,MAAM,OAA8B;CAClD,MAAMC,QAAkB,EAAE;AAC1B,OAAM,KAAK,iCAAiC;AAC5C,OAAM,KAAK,gBAAgB;AAC3B,OAAM,KAAK,sBAAsB;AAEjC,MAAK,MAAM,CAAC,KAAK,SAAS,OAAO;AAC/B,OAAK,MAAM,OAAO,KAAK,aACrB,OAAM,KAAK,MAAM,IAAI,QAAQ,IAAI,IAAI;AAEvC,MAAI,KAAK,aAAa,WAAW,EAC/B,OAAM,KAAK,MAAM,IAAI,IAAI;;AAI7B,OAAM,KAAK,IAAI;AACf,QAAO,MAAM,KAAK,KAAK;;;;;AAMzB,SAAgB,sBAAqC;AACnD,wBAAO,IAAI,KAAK;;;;;AAMlB,SAAgB,gBACd,OACA,KACA,MACA,cACM;AACN,OAAM,IAAI,KAAK;EACb;EACA;EACA;EACA,YAAY,EAAE;EACf,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
//#region src/analysis/deps/parse-imports.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Import parsing utilities for dependency analysis.
|
|
4
|
+
* Extracted from cli-contractspec/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
|
+
declare function parseImportedSpecNames(sourceCode: string, _fromFilePath: string): string[];
|
|
15
|
+
//#endregion
|
|
16
|
+
export { parseImportedSpecNames };
|
|
17
|
+
//# sourceMappingURL=parse-imports.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parse-imports.d.ts","names":[],"sources":["../../../src/analysis/deps/parse-imports.ts"],"sourcesContent":[],"mappings":";;AAaA;;;;;;;;;;;iBAAgB,sBAAA"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
//#region src/analysis/deps/parse-imports.ts
|
|
2
|
+
/**
|
|
3
|
+
* Import parsing utilities for dependency analysis.
|
|
4
|
+
* Extracted from cli-contractspec/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|contract|operation|operations|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|contract|operation|operations|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 };
|
|
31
|
+
//# sourceMappingURL=parse-imports.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parse-imports.js","names":["imports: string[]","match: RegExpExecArray | null"],"sources":["../../../src/analysis/deps/parse-imports.ts"],"sourcesContent":["/**\n * Import parsing utilities for dependency analysis.\n * Extracted from cli-contractspec/src/commands/deps/parse-imports.ts\n */\n\n/**\n * Parse spec imports from source code.\n * Returns the names of imported specs based on file naming conventions.\n *\n * @param sourceCode - The source code to parse\n * @param fromFilePath - The path of the file being parsed (for relative resolution)\n * @returns Array of imported spec names\n */\nexport function parseImportedSpecNames(\n sourceCode: string,\n _fromFilePath: string\n): string[] {\n const imports: string[] = [];\n\n // Capture relative imports that reference spec-ish files.\n // Examples:\n // import x from './foo.contracts'\n // import { y } from '../bar.event.ts'\n const importRegex =\n /import\\s+.*?\\s+from\\s+['\"]([^'\"]+\\.(?:contracts|contract|operation|operations|event|presentation|workflow|data-view|migration|telemetry|experiment|app-config|integration|knowledge)(?:\\.[jt]s)?)['\"]/g;\n\n let match: RegExpExecArray | null;\n while ((match = importRegex.exec(sourceCode)) !== null) {\n const importPath = match[1];\n if (!importPath) continue;\n if (!importPath.startsWith('.') && !importPath.startsWith('/')) continue;\n\n // Extract base name from the import path\n const pathParts = importPath.split('/');\n const base = pathParts[pathParts.length - 1] ?? '';\n\n const name = base\n .replace(/\\.(ts|js)$/, '')\n .replace(\n /\\.(contracts|contract|operation|operations|event|presentation|workflow|data-view|migration|telemetry|experiment|app-config|integration|knowledge)$/,\n ''\n );\n\n if (name.length > 0) {\n imports.push(name);\n }\n }\n\n return Array.from(new Set(imports)).sort((a, b) => a.localeCompare(b));\n}\n"],"mappings":";;;;;;;;;;;;;AAaA,SAAgB,uBACd,YACA,eACU;CACV,MAAMA,UAAoB,EAAE;CAM5B,MAAM,cACJ;CAEF,IAAIC;AACJ,SAAQ,QAAQ,YAAY,KAAK,WAAW,MAAM,MAAM;EACtD,MAAM,aAAa,MAAM;AACzB,MAAI,CAAC,WAAY;AACjB,MAAI,CAAC,WAAW,WAAW,IAAI,IAAI,CAAC,WAAW,WAAW,IAAI,CAAE;EAGhE,MAAM,YAAY,WAAW,MAAM,IAAI;EAGvC,MAAM,QAFO,UAAU,UAAU,SAAS,MAAM,IAG7C,QAAQ,cAAc,GAAG,CACzB,QACC,sJACA,GACD;AAEH,MAAI,KAAK,SAAS,EAChB,SAAQ,KAAK,KAAK;;AAItB,QAAO,MAAM,KAAK,IAAI,IAAI,QAAQ,CAAC,CAAC,MAAM,GAAG,MAAM,EAAE,cAAc,EAAE,CAAC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { SemanticDiffItem } from "../../types/analysis-types.js";
|
|
2
|
+
import { FieldSnapshot, IoSnapshot } from "../snapshot/types.js";
|
|
3
|
+
|
|
4
|
+
//#region src/analysis/diff/deep-diff.d.ts
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Deep diff options.
|
|
8
|
+
*/
|
|
9
|
+
interface DeepDiffOptions {
|
|
10
|
+
/** Only report breaking changes */
|
|
11
|
+
breakingOnly?: boolean;
|
|
12
|
+
/** Path prefix for nested diffs */
|
|
13
|
+
pathPrefix?: string;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Compute deep differences between two IO schemas.
|
|
17
|
+
*/
|
|
18
|
+
declare function computeIoDiff(base: IoSnapshot, head: IoSnapshot, options?: DeepDiffOptions): SemanticDiffItem[];
|
|
19
|
+
/**
|
|
20
|
+
* Compute differences between two field maps.
|
|
21
|
+
*/
|
|
22
|
+
declare function computeFieldsDiff(baseFields: Record<string, FieldSnapshot>, headFields: Record<string, FieldSnapshot>, pathPrefix: string, options?: DeepDiffOptions): SemanticDiffItem[];
|
|
23
|
+
/**
|
|
24
|
+
* Compute differences between two field definitions.
|
|
25
|
+
*/
|
|
26
|
+
declare function computeFieldDiff(base: FieldSnapshot, head: FieldSnapshot, path: string, _options?: DeepDiffOptions): SemanticDiffItem[];
|
|
27
|
+
/**
|
|
28
|
+
* Classify a diff as breaking based on context.
|
|
29
|
+
*/
|
|
30
|
+
declare function isBreakingChange(diff: SemanticDiffItem, context: 'input' | 'output'): boolean;
|
|
31
|
+
//#endregion
|
|
32
|
+
export { DeepDiffOptions, computeFieldDiff, computeFieldsDiff, computeIoDiff, isBreakingChange };
|
|
33
|
+
//# sourceMappingURL=deep-diff.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deep-diff.d.ts","names":[],"sources":["../../../src/analysis/diff/deep-diff.ts"],"sourcesContent":[],"mappings":";;;;;;;;AA8CgB,UAjCC,eAAA,CAiCgB;EACJ;EAAf,YAAA,CAAA,EAAA,OAAA;EACe;EAAf,UAAA,CAAA,EAAA,MAAA;;;;AA+Dd;AACQ,iBAzFQ,aAAA,CAyFR,IAAA,EAxFA,UAwFA,EAAA,IAAA,EAvFA,UAuFA,EAAA,OAAA,CAAA,EAtFG,eAsFH,CAAA,EArFL,gBAqFK,EAAA;;;;AAIW,iBAtEH,iBAAA,CAsEG,UAAA,EArEL,MAqEK,CAAA,MAAA,EArEU,aAqEV,CAAA,EAAA,UAAA,EApEL,MAoEK,CAAA,MAAA,EApEU,aAoEV,CAAA,EAAA,UAAA,EAAA,MAAA,EAAA,OAAA,CAAA,EAlER,eAkEQ,CAAA,EAjEhB,gBAiEgB,EAAA;AAwGnB;;;iBA7GgB,gBAAA,OACR,qBACA,wCAEI,kBACT;;;;iBAwGa,gBAAA,OACR"}
|