@contractspec/lib.evolution 1.56.1 → 1.58.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.
Files changed (42) hide show
  1. package/dist/analyzer/posthog-telemetry-reader.d.ts +20 -0
  2. package/dist/analyzer/posthog-telemetry-reader.d.ts.map +1 -0
  3. package/dist/analyzer/spec-analyzer.d.ts +31 -0
  4. package/dist/analyzer/spec-analyzer.d.ts.map +1 -0
  5. package/dist/approval/integration.d.ts +39 -0
  6. package/dist/approval/integration.d.ts.map +1 -0
  7. package/dist/generator/ai-spec-generator.d.ts +51 -0
  8. package/dist/generator/ai-spec-generator.d.ts.map +1 -0
  9. package/dist/generator/spec-generator.d.ts +42 -0
  10. package/dist/generator/spec-generator.d.ts.map +1 -0
  11. package/dist/index.d.ts +7 -0
  12. package/dist/index.d.ts.map +1 -0
  13. package/dist/index.js +1069 -0
  14. package/dist/node/index.js +1068 -0
  15. package/dist/types.d.ts +128 -0
  16. package/dist/types.d.ts.map +1 -0
  17. package/package.json +24 -20
  18. package/dist/ai-agent/src/approval/index.d.mts +0 -1
  19. package/dist/ai-agent/src/approval/workflow.d.mts +0 -136
  20. package/dist/ai-agent/src/approval/workflow.d.mts.map +0 -1
  21. package/dist/ai-agent/src/types.d.mts +0 -30
  22. package/dist/ai-agent/src/types.d.mts.map +0 -1
  23. package/dist/analyzer/spec-analyzer.d.mts +0 -35
  24. package/dist/analyzer/spec-analyzer.d.mts.map +0 -1
  25. package/dist/analyzer/spec-analyzer.mjs +0 -305
  26. package/dist/analyzer/spec-analyzer.mjs.map +0 -1
  27. package/dist/approval/integration.d.mts +0 -44
  28. package/dist/approval/integration.d.mts.map +0 -1
  29. package/dist/approval/integration.mjs +0 -126
  30. package/dist/approval/integration.mjs.map +0 -1
  31. package/dist/generator/ai-spec-generator.d.mts +0 -56
  32. package/dist/generator/ai-spec-generator.d.mts.map +0 -1
  33. package/dist/generator/ai-spec-generator.mjs +0 -186
  34. package/dist/generator/ai-spec-generator.mjs.map +0 -1
  35. package/dist/generator/spec-generator.d.mts +0 -46
  36. package/dist/generator/spec-generator.d.mts.map +0 -1
  37. package/dist/generator/spec-generator.mjs +0 -121
  38. package/dist/generator/spec-generator.mjs.map +0 -1
  39. package/dist/index.d.mts +0 -6
  40. package/dist/index.mjs +0 -6
  41. package/dist/types.d.mts +0 -132
  42. package/dist/types.d.mts.map +0 -1
@@ -1,186 +0,0 @@
1
- import { randomUUID } from "node:crypto";
2
- import { Output, generateText } from "ai";
3
- import * as z from "zod";
4
-
5
- //#region src/generator/ai-spec-generator.ts
6
- /**
7
- * Zod schema for AI-generated spec suggestions.
8
- */
9
- const SpecSuggestionProposalSchema = z.object({
10
- summary: z.string().describe("Brief summary of the proposed change"),
11
- rationale: z.string().describe("Detailed explanation of why this change is needed"),
12
- changeType: z.enum([
13
- "new-spec",
14
- "revision",
15
- "policy-update",
16
- "schema-update"
17
- ]).describe("Type of change being proposed"),
18
- recommendedActions: z.array(z.string()).describe("List of specific actions to implement the change"),
19
- estimatedImpact: z.enum([
20
- "low",
21
- "medium",
22
- "high"
23
- ]).describe("Estimated impact of implementing this change"),
24
- riskLevel: z.enum([
25
- "low",
26
- "medium",
27
- "high"
28
- ]).describe("Risk level associated with this change"),
29
- diff: z.string().optional().describe("Optional diff or code snippet showing the change")
30
- });
31
- /**
32
- * AI-powered spec generator using AI SDK v6.
33
- *
34
- * Uses structured output (Output.object) to generate
35
- * well-formed spec suggestions from intent patterns.
36
- */
37
- var AISpecGenerator = class {
38
- model;
39
- config;
40
- systemPrompt;
41
- constructor(options) {
42
- this.model = options.model;
43
- this.config = options.evolutionConfig ?? {};
44
- this.systemPrompt = options.systemPrompt ?? `You are a ContractSpec evolution expert. Your role is to analyze telemetry data, anomalies, and usage patterns to suggest improvements to API contracts and specifications.
45
-
46
- When generating suggestions:
47
- 1. Be specific and actionable
48
- 2. Consider backwards compatibility
49
- 3. Prioritize stability and reliability
50
- 4. Explain the rationale clearly
51
- 5. Estimate impact and risk accurately`;
52
- }
53
- /**
54
- * Generate a spec suggestion from an intent pattern using AI.
55
- */
56
- async generateFromIntent(intent, options = {}) {
57
- const prompt = this.buildPrompt(intent, options);
58
- const { output } = await generateText({
59
- model: this.model,
60
- system: this.systemPrompt,
61
- prompt,
62
- output: Output.object({ schema: SpecSuggestionProposalSchema })
63
- });
64
- return this.buildSuggestion(intent, output);
65
- }
66
- /**
67
- * Generate multiple suggestions for a batch of intents.
68
- */
69
- async generateBatch(intents, options = {}) {
70
- const maxConcurrent = options.maxConcurrent ?? 3;
71
- const results = [];
72
- for (let i = 0; i < intents.length; i += maxConcurrent) {
73
- const batch = intents.slice(i, i + maxConcurrent);
74
- const batchResults = await Promise.all(batch.map((intent) => this.generateFromIntent(intent)));
75
- results.push(...batchResults);
76
- }
77
- return results;
78
- }
79
- /**
80
- * Validate and enhance an existing suggestion using AI.
81
- */
82
- async enhanceSuggestion(suggestion) {
83
- const prompt = `Review and enhance this spec suggestion:
84
-
85
- Intent: ${suggestion.intent.type} - ${suggestion.intent.description}
86
- Current Summary: ${suggestion.proposal.summary}
87
- Current Rationale: ${suggestion.proposal.rationale}
88
-
89
- Evidence:
90
- ${suggestion.evidence.map((e) => `- ${e.type}: ${e.description}`).join("\n")}
91
-
92
- Please provide an improved version with more specific recommendations.`;
93
- const { output } = await generateText({
94
- model: this.model,
95
- system: this.systemPrompt,
96
- prompt,
97
- output: Output.object({ schema: SpecSuggestionProposalSchema })
98
- });
99
- return {
100
- ...suggestion,
101
- proposal: {
102
- ...suggestion.proposal,
103
- summary: output.summary,
104
- rationale: output.rationale,
105
- changeType: output.changeType,
106
- diff: output.diff,
107
- metadata: {
108
- ...suggestion.proposal.metadata,
109
- aiEnhanced: true,
110
- recommendedActions: output.recommendedActions,
111
- estimatedImpact: output.estimatedImpact,
112
- riskLevel: output.riskLevel
113
- }
114
- }
115
- };
116
- }
117
- buildPrompt(intent, options) {
118
- const parts = [
119
- `Analyze this intent pattern and generate a spec suggestion:`,
120
- ``,
121
- `Intent Type: ${intent.type}`,
122
- `Description: ${intent.description}`,
123
- `Confidence: ${(intent.confidence.score * 100).toFixed(0)}% (sample size: ${intent.confidence.sampleSize})`
124
- ];
125
- if (intent.operation) parts.push(`Operation: ${intent.operation.key} v${intent.operation.version}`);
126
- if (intent.evidence.length > 0) {
127
- parts.push(``, `Evidence:`);
128
- for (const evidence of intent.evidence) parts.push(`- [${evidence.type}] ${evidence.description}`);
129
- }
130
- if (intent.metadata) parts.push(``, `Metadata: ${JSON.stringify(intent.metadata, null, 2)}`);
131
- if (options.existingSpec) parts.push(``, `Existing Spec:`, "```json", JSON.stringify(options.existingSpec, null, 2), "```");
132
- if (options.additionalContext) parts.push(``, `Additional Context:`, options.additionalContext);
133
- return parts.join("\n");
134
- }
135
- buildSuggestion(intent, aiOutput) {
136
- const now = /* @__PURE__ */ new Date();
137
- const proposal = {
138
- summary: aiOutput.summary,
139
- rationale: aiOutput.rationale,
140
- changeType: aiOutput.changeType,
141
- diff: aiOutput.diff,
142
- metadata: {
143
- aiGenerated: true,
144
- recommendedActions: aiOutput.recommendedActions,
145
- estimatedImpact: aiOutput.estimatedImpact,
146
- riskLevel: aiOutput.riskLevel
147
- }
148
- };
149
- return {
150
- id: randomUUID(),
151
- intent,
152
- target: intent.operation,
153
- proposal,
154
- confidence: intent.confidence.score,
155
- priority: this.calculatePriority(intent, aiOutput),
156
- createdAt: now,
157
- createdBy: "ai-spec-generator",
158
- status: this.determineInitialStatus(intent),
159
- evidence: intent.evidence,
160
- tags: ["ai-generated", intent.type]
161
- };
162
- }
163
- calculatePriority(intent, aiOutput) {
164
- const impactScore = aiOutput.estimatedImpact === "high" ? 1 : aiOutput.estimatedImpact === "medium" ? .5 : .25;
165
- const intentScore = intent.confidence.score;
166
- const urgency = intent.type === "error-spike" ? .3 : intent.type === "latency-regression" ? .2 : 0;
167
- const combined = impactScore * .4 + intentScore * .4 + urgency;
168
- if (combined >= .7) return "high";
169
- if (combined >= .4) return "medium";
170
- return "low";
171
- }
172
- determineInitialStatus(intent) {
173
- if (this.config.autoApproveThreshold && intent.confidence.score >= this.config.autoApproveThreshold && !this.config.requireApproval) return "approved";
174
- return "pending";
175
- }
176
- };
177
- /**
178
- * Create an AI-powered spec generator.
179
- */
180
- function createAISpecGenerator(config) {
181
- return new AISpecGenerator(config);
182
- }
183
-
184
- //#endregion
185
- export { AISpecGenerator, createAISpecGenerator };
186
- //# sourceMappingURL=ai-spec-generator.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ai-spec-generator.mjs","names":[],"sources":["../../src/generator/ai-spec-generator.ts"],"sourcesContent":["import type { LanguageModel } from 'ai';\nimport { generateText, Output } from 'ai';\nimport * as z from 'zod';\nimport { randomUUID } from 'node:crypto';\nimport type {\n EvolutionConfig,\n IntentPattern,\n SpecSuggestion,\n SpecSuggestionProposal,\n SuggestionStatus,\n} from '../types';\n\n/**\n * Zod schema for AI-generated spec suggestions.\n */\nconst SpecSuggestionProposalSchema = z.object({\n summary: z.string().describe('Brief summary of the proposed change'),\n rationale: z\n .string()\n .describe('Detailed explanation of why this change is needed'),\n changeType: z\n .enum(['new-spec', 'revision', 'policy-update', 'schema-update'])\n .describe('Type of change being proposed'),\n recommendedActions: z\n .array(z.string())\n .describe('List of specific actions to implement the change'),\n estimatedImpact: z\n .enum(['low', 'medium', 'high'])\n .describe('Estimated impact of implementing this change'),\n riskLevel: z\n .enum(['low', 'medium', 'high'])\n .describe('Risk level associated with this change'),\n diff: z\n .string()\n .optional()\n .describe('Optional diff or code snippet showing the change'),\n});\n\ntype AIGeneratedProposal = z.infer<typeof SpecSuggestionProposalSchema>;\n\n/**\n * Configuration for the AI-powered spec generator.\n */\nexport interface AISpecGeneratorConfig {\n /** AI SDK language model */\n model: LanguageModel;\n /** Evolution configuration */\n evolutionConfig?: EvolutionConfig;\n /** Custom system prompt */\n systemPrompt?: string;\n}\n\n/**\n * AI-powered spec generator using AI SDK v6.\n *\n * Uses structured output (Output.object) to generate\n * well-formed spec suggestions from intent patterns.\n */\nexport class AISpecGenerator {\n private readonly model: LanguageModel;\n private readonly config: EvolutionConfig;\n private readonly systemPrompt: string;\n\n constructor(options: AISpecGeneratorConfig) {\n this.model = options.model;\n this.config = options.evolutionConfig ?? {};\n this.systemPrompt =\n options.systemPrompt ??\n `You are a ContractSpec evolution expert. Your role is to analyze telemetry data, anomalies, and usage patterns to suggest improvements to API contracts and specifications.\n\nWhen generating suggestions:\n1. Be specific and actionable\n2. Consider backwards compatibility\n3. Prioritize stability and reliability\n4. Explain the rationale clearly\n5. Estimate impact and risk accurately`;\n }\n\n /**\n * Generate a spec suggestion from an intent pattern using AI.\n */\n async generateFromIntent(\n intent: IntentPattern,\n options: {\n additionalContext?: string;\n existingSpec?: Record<string, unknown>;\n } = {}\n ): Promise<SpecSuggestion> {\n const prompt = this.buildPrompt(intent, options);\n\n // AI SDK v6: Output.object() only takes { schema }\n const { output } = await generateText({\n model: this.model,\n system: this.systemPrompt,\n prompt,\n output: Output.object({\n schema: SpecSuggestionProposalSchema,\n }),\n });\n\n return this.buildSuggestion(intent, output);\n }\n\n /**\n * Generate multiple suggestions for a batch of intents.\n */\n async generateBatch(\n intents: IntentPattern[],\n options: { maxConcurrent?: number } = {}\n ): Promise<SpecSuggestion[]> {\n const maxConcurrent = options.maxConcurrent ?? 3;\n const results: SpecSuggestion[] = [];\n\n // Process in batches to avoid overwhelming the API\n for (let i = 0; i < intents.length; i += maxConcurrent) {\n const batch = intents.slice(i, i + maxConcurrent);\n const batchResults = await Promise.all(\n batch.map((intent) => this.generateFromIntent(intent))\n );\n results.push(...batchResults);\n }\n\n return results;\n }\n\n /**\n * Validate and enhance an existing suggestion using AI.\n */\n async enhanceSuggestion(suggestion: SpecSuggestion): Promise<SpecSuggestion> {\n const prompt = `Review and enhance this spec suggestion:\n\nIntent: ${suggestion.intent.type} - ${suggestion.intent.description}\nCurrent Summary: ${suggestion.proposal.summary}\nCurrent Rationale: ${suggestion.proposal.rationale}\n\nEvidence:\n${suggestion.evidence.map((e) => `- ${e.type}: ${e.description}`).join('\\n')}\n\nPlease provide an improved version with more specific recommendations.`;\n\n // AI SDK v6: Output.object() only takes { schema }\n const { output } = await generateText({\n model: this.model,\n system: this.systemPrompt,\n prompt,\n output: Output.object({\n schema: SpecSuggestionProposalSchema,\n }),\n });\n\n return {\n ...suggestion,\n proposal: {\n ...suggestion.proposal,\n summary: output.summary,\n rationale: output.rationale,\n changeType: output.changeType,\n diff: output.diff,\n metadata: {\n ...suggestion.proposal.metadata,\n aiEnhanced: true,\n recommendedActions: output.recommendedActions,\n estimatedImpact: output.estimatedImpact,\n riskLevel: output.riskLevel,\n },\n },\n };\n }\n\n private buildPrompt(\n intent: IntentPattern,\n options: {\n additionalContext?: string;\n existingSpec?: Record<string, unknown>;\n }\n ): string {\n const parts = [\n `Analyze this intent pattern and generate a spec suggestion:`,\n ``,\n `Intent Type: ${intent.type}`,\n `Description: ${intent.description}`,\n `Confidence: ${(intent.confidence.score * 100).toFixed(0)}% (sample size: ${intent.confidence.sampleSize})`,\n ];\n\n if (intent.operation) {\n parts.push(\n `Operation: ${intent.operation.key} v${intent.operation.version}`\n );\n }\n\n if (intent.evidence.length > 0) {\n parts.push(``, `Evidence:`);\n for (const evidence of intent.evidence) {\n parts.push(`- [${evidence.type}] ${evidence.description}`);\n }\n }\n\n if (intent.metadata) {\n parts.push(``, `Metadata: ${JSON.stringify(intent.metadata, null, 2)}`);\n }\n\n if (options.existingSpec) {\n parts.push(\n ``,\n `Existing Spec:`,\n '```json',\n JSON.stringify(options.existingSpec, null, 2),\n '```'\n );\n }\n\n if (options.additionalContext) {\n parts.push(``, `Additional Context:`, options.additionalContext);\n }\n\n return parts.join('\\n');\n }\n\n private buildSuggestion(\n intent: IntentPattern,\n aiOutput: AIGeneratedProposal\n ): SpecSuggestion {\n const now = new Date();\n\n const proposal: SpecSuggestionProposal = {\n summary: aiOutput.summary,\n rationale: aiOutput.rationale,\n changeType: aiOutput.changeType,\n diff: aiOutput.diff,\n metadata: {\n aiGenerated: true,\n recommendedActions: aiOutput.recommendedActions,\n estimatedImpact: aiOutput.estimatedImpact,\n riskLevel: aiOutput.riskLevel,\n },\n };\n\n return {\n id: randomUUID(),\n intent,\n target: intent.operation,\n proposal,\n confidence: intent.confidence.score,\n priority: this.calculatePriority(intent, aiOutput),\n createdAt: now,\n createdBy: 'ai-spec-generator',\n status: this.determineInitialStatus(intent),\n evidence: intent.evidence,\n tags: ['ai-generated', intent.type],\n };\n }\n\n private calculatePriority(\n intent: IntentPattern,\n aiOutput: AIGeneratedProposal\n ): 'low' | 'medium' | 'high' {\n // Combine AI assessment with intent severity\n const impactScore =\n aiOutput.estimatedImpact === 'high'\n ? 1\n : aiOutput.estimatedImpact === 'medium'\n ? 0.5\n : 0.25;\n\n const intentScore = intent.confidence.score;\n const urgency =\n intent.type === 'error-spike'\n ? 0.3\n : intent.type === 'latency-regression'\n ? 0.2\n : 0;\n\n const combined = impactScore * 0.4 + intentScore * 0.4 + urgency;\n\n if (combined >= 0.7) return 'high';\n if (combined >= 0.4) return 'medium';\n return 'low';\n }\n\n private determineInitialStatus(intent: IntentPattern): SuggestionStatus {\n // Auto-approve high-confidence, low-risk suggestions if configured\n if (\n this.config.autoApproveThreshold &&\n intent.confidence.score >= this.config.autoApproveThreshold &&\n !this.config.requireApproval\n ) {\n return 'approved';\n }\n return 'pending';\n }\n}\n\n/**\n * Create an AI-powered spec generator.\n */\nexport function createAISpecGenerator(\n config: AISpecGeneratorConfig\n): AISpecGenerator {\n return new AISpecGenerator(config);\n}\n"],"mappings":";;;;;;;;AAeA,MAAM,+BAA+B,EAAE,OAAO;CAC5C,SAAS,EAAE,QAAQ,CAAC,SAAS,uCAAuC;CACpE,WAAW,EACR,QAAQ,CACR,SAAS,oDAAoD;CAChE,YAAY,EACT,KAAK;EAAC;EAAY;EAAY;EAAiB;EAAgB,CAAC,CAChE,SAAS,gCAAgC;CAC5C,oBAAoB,EACjB,MAAM,EAAE,QAAQ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;EAChB,MAAM,sBAAM,IAAI,MAAM;EAEtB,MAAM,WAAmC;GACvC,SAAS,SAAS;GAClB,WAAW,SAAS;GACpB,YAAY,SAAS;GACrB,MAAM,SAAS;GACf,UAAU;IACR,aAAa;IACb,oBAAoB,SAAS;IAC7B,iBAAiB,SAAS;IAC1B,WAAW,SAAS;IACrB;GACF;AAED,SAAO;GACL,IAAI,YAAY;GAChB;GACA,QAAQ,OAAO;GACf;GACA,YAAY,OAAO,WAAW;GAC9B,UAAU,KAAK,kBAAkB,QAAQ,SAAS;GAClD,WAAW;GACX,WAAW;GACX,QAAQ,KAAK,uBAAuB,OAAO;GAC3C,UAAU,OAAO;GACjB,MAAM,CAAC,gBAAgB,OAAO,KAAK;GACpC;;CAGH,AAAQ,kBACN,QACA,UAC2B;EAE3B,MAAM,cACJ,SAAS,oBAAoB,SACzB,IACA,SAAS,oBAAoB,WAC3B,KACA;EAER,MAAM,cAAc,OAAO,WAAW;EACtC,MAAM,UACJ,OAAO,SAAS,gBACZ,KACA,OAAO,SAAS,uBACd,KACA;EAER,MAAM,WAAW,cAAc,KAAM,cAAc,KAAM;AAEzD,MAAI,YAAY,GAAK,QAAO;AAC5B,MAAI,YAAY,GAAK,QAAO;AAC5B,SAAO;;CAGT,AAAQ,uBAAuB,QAAyC;AAEtE,MACE,KAAK,OAAO,wBACZ,OAAO,WAAW,SAAS,KAAK,OAAO,wBACvC,CAAC,KAAK,OAAO,gBAEb,QAAO;AAET,SAAO;;;;;;AAOX,SAAgB,sBACd,QACiB;AACjB,QAAO,IAAI,gBAAgB,OAAO"}
@@ -1,46 +0,0 @@
1
- import { EvolutionConfig, IntentPattern, OperationCoordinate, SpecSuggestion, SpecSuggestionProposal, SuggestionStatus } from "../types.mjs";
2
- import { Logger } from "@contractspec/lib.observability";
3
- import { AnyOperationSpec, OperationSpec, ResourceRefDescriptor } from "@contractspec/lib.contracts";
4
- import { AnySchemaModel } from "@contractspec/lib.schema";
5
-
6
- //#region src/generator/spec-generator.d.ts
7
- interface SpecGeneratorOptions {
8
- config?: EvolutionConfig;
9
- logger?: Logger;
10
- clock?: () => Date;
11
- getSpec?: (key: string, version?: string) => AnyOperationSpec | undefined;
12
- }
13
- interface GenerateSpecOptions {
14
- summary?: string;
15
- rationale?: string;
16
- changeType?: SpecSuggestionProposal['changeType'];
17
- kind?: SpecSuggestionProposal['kind'];
18
- spec?: AnyOperationSpec;
19
- diff?: string;
20
- metadata?: Record<string, unknown>;
21
- status?: SuggestionStatus;
22
- tags?: string[];
23
- createdBy?: string;
24
- }
25
- type SpecPatch = Partial<OperationSpec<AnySchemaModel, AnySchemaModel | ResourceRefDescriptor<boolean>>> & {
26
- meta?: Partial<AnyOperationSpec['meta']>;
27
- };
28
- declare class SpecGenerator {
29
- private readonly config;
30
- private readonly logger?;
31
- private readonly clock;
32
- private readonly getSpec?;
33
- constructor(options?: SpecGeneratorOptions);
34
- generateFromIntent(intent: IntentPattern, options?: GenerateSpecOptions): SpecSuggestion;
35
- generateVariant(operation: OperationCoordinate, patch: SpecPatch, intent: IntentPattern, options?: Omit<GenerateSpecOptions, 'spec'>): SpecSuggestion;
36
- validateSuggestion(suggestion: SpecSuggestion, config?: EvolutionConfig): {
37
- ok: boolean;
38
- reasons: string[];
39
- };
40
- private intentToVerb;
41
- private intentToPriority;
42
- private inferChangeType;
43
- }
44
- //#endregion
45
- export { GenerateSpecOptions, SpecGenerator, SpecGeneratorOptions, SpecPatch };
46
- //# sourceMappingURL=spec-generator.d.mts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"spec-generator.d.mts","names":[],"sources":["../../src/generator/spec-generator.ts"],"sourcesContent":[],"mappings":";;;;;;UAiBiB,oBAAA;WACN;EADM,MAAA,CAAA,EAEN,MAFM;EACN,KAAA,CAAA,EAAA,GAAA,GAEK,IAFL;EACA,OAAA,CAAA,EAAA,CAAA,GAAA,EAAA,MAAA,EAAA,OAAA,CAAA,EAAA,MAAA,EAAA,GAEoC,gBAFpC,GAAA,SAAA;;AAE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 @@
1
- import { Logger } from "@contractspec/lib.observability";
2
- import { randomUUID } from "node:crypto";
3
-
4
- //#region src/generator/spec-generator.ts
5
- var SpecGenerator = class {
6
- config;
7
- logger;
8
- clock;
9
- getSpec;
10
- constructor(options = {}) {
11
- this.config = options.config ?? {};
12
- this.logger = options.logger;
13
- this.clock = options.clock ?? (() => /* @__PURE__ */ new Date());
14
- this.getSpec = options.getSpec;
15
- }
16
- generateFromIntent(intent, options = {}) {
17
- const now = this.clock();
18
- const summary = options.summary ?? `${this.intentToVerb(intent.type)} ${intent.operation?.key ?? "operation"}`;
19
- const rationale = options.rationale ?? [intent.description, intent.metadata?.observedValue ? `Observed ${intent.metadata.observedValue}` : void 0].filter(Boolean).join(" — ");
20
- return {
21
- id: randomUUID(),
22
- intent,
23
- target: intent.operation,
24
- proposal: {
25
- summary,
26
- rationale,
27
- changeType: options.changeType ?? this.inferChangeType(intent),
28
- kind: options.kind,
29
- spec: options.spec,
30
- diff: options.diff,
31
- metadata: options.metadata
32
- },
33
- confidence: intent.confidence.score,
34
- priority: this.intentToPriority(intent),
35
- createdAt: now,
36
- createdBy: options.createdBy ?? "auto-evolution",
37
- status: options.status ?? "pending",
38
- evidence: intent.evidence,
39
- tags: options.tags
40
- };
41
- }
42
- generateVariant(operation, patch, intent, options = {}) {
43
- if (!this.getSpec) throw new Error("SpecGenerator requires getSpec() to generate variants");
44
- const base = this.getSpec(operation.key, operation.version);
45
- if (!base) throw new Error(`Cannot generate variant; spec ${operation.key}.v${operation.version} not found`);
46
- const merged = mergeContract(base, patch);
47
- return this.generateFromIntent(intent, {
48
- ...options,
49
- spec: merged
50
- });
51
- }
52
- validateSuggestion(suggestion, config = this.config) {
53
- const reasons = [];
54
- if (config.minConfidence != null && suggestion.confidence < config.minConfidence) reasons.push(`Confidence ${suggestion.confidence.toFixed(2)} below minimum ${config.minConfidence}`);
55
- if (config.requireApproval && suggestion.status === "approved") reasons.push("Suggestion cannot be auto-approved when approval is required");
56
- if (suggestion.proposal.spec && !suggestion.proposal.spec.meta?.key) reasons.push("Proposal spec must include meta.key");
57
- if (!suggestion.proposal.summary) reasons.push("Proposal summary is required");
58
- const ok = reasons.length === 0;
59
- if (!ok) this.logger?.warn("SpecGenerator.validateSuggestion.failed", {
60
- suggestionId: suggestion.id,
61
- reasons
62
- });
63
- return {
64
- ok,
65
- reasons
66
- };
67
- }
68
- intentToVerb(intent) {
69
- switch (intent) {
70
- case "error-spike": return "Stabilize";
71
- case "latency-regression": return "Optimize";
72
- case "missing-operation": return "Introduce";
73
- case "throughput-drop": return "Rebalance";
74
- default: return "Adjust";
75
- }
76
- }
77
- intentToPriority(intent) {
78
- const severity = intent.confidence.score;
79
- if (intent.type === "error-spike" || severity >= .8) return "high";
80
- if (severity >= .5) return "medium";
81
- return "low";
82
- }
83
- inferChangeType(intent) {
84
- switch (intent.type) {
85
- case "missing-operation": return "new-spec";
86
- case "schema-mismatch": return "schema-update";
87
- case "error-spike": return "policy-update";
88
- default: return "revision";
89
- }
90
- }
91
- };
92
- function mergeContract(base, patch) {
93
- return {
94
- ...base,
95
- ...patch,
96
- meta: {
97
- ...base.meta,
98
- ...patch.meta
99
- },
100
- io: {
101
- ...base.io,
102
- ...patch.io
103
- },
104
- policy: {
105
- ...base.policy,
106
- ...patch.policy
107
- },
108
- telemetry: {
109
- ...base.telemetry,
110
- ...patch.telemetry
111
- },
112
- sideEffects: {
113
- ...base.sideEffects,
114
- ...patch.sideEffects
115
- }
116
- };
117
- }
118
-
119
- //#endregion
120
- export { SpecGenerator };
121
- //# sourceMappingURL=spec-generator.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"spec-generator.mjs","names":[],"sources":["../../src/generator/spec-generator.ts"],"sourcesContent":["import type {\n AnyOperationSpec,\n OperationSpec,\n ResourceRefDescriptor,\n} from '@contractspec/lib.contracts';\nimport type { AnySchemaModel } from '@contractspec/lib.schema';\nimport { Logger } from '@contractspec/lib.observability';\nimport { randomUUID } from 'node:crypto';\nimport {\n type EvolutionConfig,\n type IntentPattern,\n type OperationCoordinate,\n type SpecSuggestion,\n type SpecSuggestionProposal,\n type SuggestionStatus,\n} from '../types';\n\nexport interface SpecGeneratorOptions {\n config?: EvolutionConfig;\n logger?: Logger;\n clock?: () => Date;\n getSpec?: (key: string, version?: string) => AnyOperationSpec | undefined;\n}\n\nexport interface GenerateSpecOptions {\n summary?: string;\n rationale?: string;\n changeType?: SpecSuggestionProposal['changeType'];\n kind?: SpecSuggestionProposal['kind'];\n spec?: AnyOperationSpec;\n diff?: string;\n metadata?: Record<string, unknown>;\n status?: SuggestionStatus;\n tags?: string[];\n createdBy?: string;\n}\n\nexport type SpecPatch = Partial<\n OperationSpec<AnySchemaModel, AnySchemaModel | ResourceRefDescriptor<boolean>>\n> & { meta?: Partial<AnyOperationSpec['meta']> };\n\nexport class SpecGenerator {\n private readonly config: EvolutionConfig;\n private readonly logger?: Logger;\n private readonly clock: () => Date;\n private readonly getSpec?: SpecGeneratorOptions['getSpec'];\n\n constructor(options: SpecGeneratorOptions = {}) {\n this.config = options.config ?? {};\n this.logger = options.logger;\n this.clock = options.clock ?? (() => new Date());\n this.getSpec = options.getSpec;\n }\n\n generateFromIntent(\n intent: IntentPattern,\n options: GenerateSpecOptions = {}\n ): SpecSuggestion {\n const now = this.clock();\n const summary =\n options.summary ??\n `${this.intentToVerb(intent.type)} ${intent.operation?.key ?? 'operation'}`;\n const rationale =\n options.rationale ??\n [\n intent.description,\n intent.metadata?.observedValue\n ? `Observed ${intent.metadata.observedValue}`\n : undefined,\n ]\n .filter(Boolean)\n .join(' — ');\n\n const suggestion: SpecSuggestion = {\n id: randomUUID(),\n intent,\n target: intent.operation,\n proposal: {\n summary,\n rationale,\n changeType: options.changeType ?? this.inferChangeType(intent),\n kind: options.kind,\n spec: options.spec,\n diff: options.diff,\n metadata: options.metadata,\n },\n confidence: intent.confidence.score,\n priority: this.intentToPriority(intent),\n createdAt: now,\n createdBy: options.createdBy ?? 'auto-evolution',\n status: options.status ?? 'pending',\n evidence: intent.evidence,\n tags: options.tags,\n };\n return suggestion;\n }\n\n generateVariant(\n operation: OperationCoordinate,\n patch: SpecPatch,\n intent: IntentPattern,\n options: Omit<GenerateSpecOptions, 'spec'> = {}\n ) {\n if (!this.getSpec) {\n throw new Error('SpecGenerator requires getSpec() to generate variants');\n }\n const base = this.getSpec(operation.key, operation.version);\n if (!base) {\n throw new Error(\n `Cannot generate variant; spec ${operation.key}.v${operation.version} not found`\n );\n }\n const merged = mergeContract(base, patch);\n return this.generateFromIntent(intent, { ...options, spec: merged });\n }\n\n validateSuggestion(\n suggestion: SpecSuggestion,\n config: EvolutionConfig = this.config\n ) {\n const reasons: string[] = [];\n if (\n config.minConfidence != null &&\n suggestion.confidence < config.minConfidence\n ) {\n reasons.push(\n `Confidence ${suggestion.confidence.toFixed(2)} below minimum ${config.minConfidence}`\n );\n }\n if (config.requireApproval && suggestion.status === 'approved') {\n reasons.push(\n 'Suggestion cannot be auto-approved when approval is required'\n );\n }\n if (suggestion.proposal.spec && !suggestion.proposal.spec.meta?.key) {\n reasons.push('Proposal spec must include meta.key');\n }\n if (!suggestion.proposal.summary) {\n reasons.push('Proposal summary is required');\n }\n const ok = reasons.length === 0;\n if (!ok) {\n this.logger?.warn('SpecGenerator.validateSuggestion.failed', {\n suggestionId: suggestion.id,\n reasons,\n });\n }\n return { ok, reasons };\n }\n\n private intentToVerb(intent: IntentPattern['type']) {\n switch (intent) {\n case 'error-spike':\n return 'Stabilize';\n case 'latency-regression':\n return 'Optimize';\n case 'missing-operation':\n return 'Introduce';\n case 'throughput-drop':\n return 'Rebalance';\n default:\n return 'Adjust';\n }\n }\n\n private intentToPriority(intent: IntentPattern) {\n const severity = intent.confidence.score;\n if (intent.type === 'error-spike' || severity >= 0.8) return 'high';\n if (severity >= 0.5) return 'medium';\n return 'low';\n }\n\n private inferChangeType(\n intent: IntentPattern\n ): SpecSuggestionProposal['changeType'] {\n switch (intent.type) {\n case 'missing-operation':\n return 'new-spec';\n case 'schema-mismatch':\n return 'schema-update';\n case 'error-spike':\n return 'policy-update';\n default:\n return 'revision';\n }\n }\n}\n\nfunction mergeContract(\n base: AnyOperationSpec,\n patch: SpecPatch\n): AnyOperationSpec {\n return {\n ...base,\n ...patch,\n meta: { ...base.meta, ...patch.meta },\n io: {\n ...base.io,\n ...patch.io,\n },\n policy: {\n ...base.policy,\n ...patch.policy,\n },\n telemetry: {\n ...base.telemetry,\n ...patch.telemetry,\n },\n sideEffects: {\n ...base.sideEffects,\n ...patch.sideEffects,\n },\n } as AnyOperationSpec;\n}\n"],"mappings":";;;;AAyCA,IAAa,gBAAb,MAA2B;CACzB,AAAiB;CACjB,AAAiB;CACjB,AAAiB;CACjB,AAAiB;CAEjB,YAAY,UAAgC,EAAE,EAAE;AAC9C,OAAK,SAAS,QAAQ,UAAU,EAAE;AAClC,OAAK,SAAS,QAAQ;AACtB,OAAK,QAAQ,QAAQ,gCAAgB,IAAI,MAAM;AAC/C,OAAK,UAAU,QAAQ;;CAGzB,mBACE,QACA,UAA+B,EAAE,EACjB;EAChB,MAAM,MAAM,KAAK,OAAO;EACxB,MAAM,UACJ,QAAQ,WACR,GAAG,KAAK,aAAa,OAAO,KAAK,CAAC,GAAG,OAAO,WAAW,OAAO;EAChE,MAAM,YACJ,QAAQ,aACR,CACE,OAAO,aACP,OAAO,UAAU,gBACb,YAAY,OAAO,SAAS,kBAC5B,OACL,CACE,OAAO,QAAQ,CACf,KAAK,MAAM;AAuBhB,SArBmC;GACjC,IAAI,YAAY;GAChB;GACA,QAAQ,OAAO;GACf,UAAU;IACR;IACA;IACA,YAAY,QAAQ,cAAc,KAAK,gBAAgB,OAAO;IAC9D,MAAM,QAAQ;IACd,MAAM,QAAQ;IACd,MAAM,QAAQ;IACd,UAAU,QAAQ;IACnB;GACD,YAAY,OAAO,WAAW;GAC9B,UAAU,KAAK,iBAAiB,OAAO;GACvC,WAAW;GACX,WAAW,QAAQ,aAAa;GAChC,QAAQ,QAAQ,UAAU;GAC1B,UAA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,QAAO;AAC5B,SAAO;;CAGT,AAAQ,gBACN,QACsC;AACtC,UAAQ,OAAO,MAAf;GACE,KAAK,oBACH,QAAO;GACT,KAAK,kBACH,QAAO;GACT,KAAK,cACH,QAAO;GACT,QACE,QAAO;;;;AAKf,SAAS,cACP,MACA,OACkB;AAClB,QAAO;EACL,GAAG;EACH,GAAG;EACH,MAAM;GAAE,GAAG,KAAK;GAAM,GAAG,MAAM;GAAM;EACrC,IAAI;GACF,GAAG,KAAK;GACR,GAAG,MAAM;GACV;EACD,QAAQ;GACN,GAAG,KAAK;GACR,GAAG,MAAM;GACV;EACD,WAAW;GACT,GAAG,KAAK;GACR,GAAG,MAAM;GACV;EACD,aAAa;GACX,GAAG,KAAK;GACR,GAAG,MAAM;GACV;EACF"}
package/dist/index.d.mts DELETED
@@ -1,6 +0,0 @@
1
- import { AnomalySeverity, EvolutionConfig, IntentPattern, OperationCoordinate, OperationMetricSample, OptimizationHint, PatternConfidence, SpecAnomaly, SpecSuggestion, SpecSuggestionFilters, SpecSuggestionProposal, SpecSuggestionRepository, SpecSuggestionWriter, SpecUsageStats, SuggestionEvidence, SuggestionStatus } from "./types.mjs";
2
- import { SpecAnalyzer, SpecAnalyzerOptions } from "./analyzer/spec-analyzer.mjs";
3
- import { GenerateSpecOptions, SpecGenerator, SpecGeneratorOptions, SpecPatch } from "./generator/spec-generator.mjs";
4
- import { AISpecGenerator, AISpecGeneratorConfig, createAISpecGenerator } from "./generator/ai-spec-generator.mjs";
5
- import { FileSystemSuggestionWriter, FileSystemSuggestionWriterOptions, InMemorySpecSuggestionRepository, SpecSuggestionOrchestrator, SpecSuggestionOrchestratorOptions } from "./approval/integration.mjs";
6
- export { AISpecGenerator, AISpecGeneratorConfig, AnomalySeverity, EvolutionConfig, FileSystemSuggestionWriter, FileSystemSuggestionWriterOptions, GenerateSpecOptions, InMemorySpecSuggestionRepository, IntentPattern, OperationCoordinate, OperationMetricSample, OptimizationHint, PatternConfidence, SpecAnalyzer, SpecAnalyzerOptions, SpecAnomaly, SpecGenerator, SpecGeneratorOptions, SpecPatch, SpecSuggestion, SpecSuggestionFilters, SpecSuggestionOrchestrator, SpecSuggestionOrchestratorOptions, SpecSuggestionProposal, SpecSuggestionRepository, SpecSuggestionWriter, SpecUsageStats, SuggestionEvidence, SuggestionStatus, createAISpecGenerator };
package/dist/index.mjs DELETED
@@ -1,6 +0,0 @@
1
- import { SpecAnalyzer } from "./analyzer/spec-analyzer.mjs";
2
- import { SpecGenerator } from "./generator/spec-generator.mjs";
3
- import { AISpecGenerator, createAISpecGenerator } from "./generator/ai-spec-generator.mjs";
4
- import { FileSystemSuggestionWriter, InMemorySpecSuggestionRepository, SpecSuggestionOrchestrator } from "./approval/integration.mjs";
5
-
6
- export { AISpecGenerator, FileSystemSuggestionWriter, InMemorySpecSuggestionRepository, SpecAnalyzer, SpecGenerator, SpecSuggestionOrchestrator, createAISpecGenerator };
package/dist/types.d.mts DELETED
@@ -1,132 +0,0 @@
1
- import { LifecycleStage } from "@contractspec/lib.lifecycle";
2
- import { OpKind, OperationSpec, ResourceRefDescriptor } from "@contractspec/lib.contracts";
3
- import { AnySchemaModel } from "@contractspec/lib.schema";
4
-
5
- //#region src/types.d.ts
6
- type AnomalySeverity = 'low' | 'medium' | 'high';
7
- type SuggestionStatus = 'pending' | 'approved' | 'rejected';
8
- interface OperationCoordinate {
9
- key: string;
10
- version: string;
11
- tenantId?: string;
12
- }
13
- interface OperationMetricSample {
14
- operation: OperationCoordinate;
15
- durationMs: number;
16
- success: boolean;
17
- timestamp: Date;
18
- payloadSizeBytes?: number;
19
- errorCode?: string;
20
- errorMessage?: string;
21
- actor?: string;
22
- channel?: string;
23
- traceId?: string;
24
- metadata?: Record<string, unknown>;
25
- }
26
- interface SpecUsageStats {
27
- operation: OperationCoordinate;
28
- totalCalls: number;
29
- successRate: number;
30
- errorRate: number;
31
- averageLatencyMs: number;
32
- p95LatencyMs: number;
33
- p99LatencyMs: number;
34
- maxLatencyMs: number;
35
- lastSeenAt: Date;
36
- windowStart: Date;
37
- windowEnd: Date;
38
- topErrors: Record<string, number>;
39
- }
40
- interface SuggestionEvidence {
41
- type: 'telemetry' | 'user-feedback' | 'simulation' | 'test';
42
- description: string;
43
- data?: Record<string, unknown>;
44
- }
45
- interface SpecAnomaly {
46
- operation: OperationCoordinate;
47
- severity: AnomalySeverity;
48
- metric: 'latency' | 'error-rate' | 'throughput' | 'policy' | 'schema';
49
- description: string;
50
- detectedAt: Date;
51
- threshold?: number;
52
- observedValue?: number;
53
- evidence: SuggestionEvidence[];
54
- }
55
- interface PatternConfidence {
56
- score: number;
57
- sampleSize: number;
58
- pValue?: number;
59
- }
60
- interface IntentPattern {
61
- id: string;
62
- type: 'latency-regression' | 'error-spike' | 'missing-operation' | 'chained-intent' | 'throughput-drop' | 'schema-mismatch';
63
- description: string;
64
- operation?: OperationCoordinate;
65
- confidence: PatternConfidence;
66
- metadata?: Record<string, unknown>;
67
- evidence: SuggestionEvidence[];
68
- }
69
- interface SpecSuggestionProposal {
70
- summary: string;
71
- rationale: string;
72
- changeType: 'new-spec' | 'revision' | 'policy-update' | 'schema-update';
73
- kind?: OpKind;
74
- spec?: OperationSpec<AnySchemaModel, AnySchemaModel | ResourceRefDescriptor<boolean>>;
75
- diff?: string;
76
- metadata?: Record<string, unknown>;
77
- }
78
- interface SpecSuggestion {
79
- id: string;
80
- intent: IntentPattern;
81
- target?: OperationCoordinate;
82
- proposal: SpecSuggestionProposal;
83
- confidence: number;
84
- createdAt: Date;
85
- createdBy: string;
86
- status: SuggestionStatus;
87
- evidence: SuggestionEvidence[];
88
- priority: 'low' | 'medium' | 'high';
89
- tags?: string[];
90
- approvals?: {
91
- reviewer?: string;
92
- notes?: string;
93
- decidedAt?: Date;
94
- status?: SuggestionStatus;
95
- };
96
- }
97
- interface EvolutionConfig {
98
- minConfidence?: number;
99
- autoApproveThreshold?: number;
100
- maxSuggestionsPerOperation?: number;
101
- requireApproval?: boolean;
102
- maxConcurrentExperiments?: number;
103
- }
104
- interface SpecSuggestionFilters {
105
- status?: SuggestionStatus;
106
- operationKey?: string;
107
- }
108
- interface SpecSuggestionRepository {
109
- create(suggestion: SpecSuggestion): Promise<void>;
110
- getById(id: string): Promise<SpecSuggestion | undefined>;
111
- updateStatus(id: string, status: SuggestionStatus, metadata?: {
112
- reviewer?: string;
113
- notes?: string;
114
- decidedAt?: Date;
115
- }): Promise<void>;
116
- list(filters?: SpecSuggestionFilters): Promise<SpecSuggestion[]>;
117
- }
118
- interface SpecSuggestionWriter {
119
- write(suggestion: SpecSuggestion): Promise<string>;
120
- }
121
- interface OptimizationHint {
122
- operation: OperationCoordinate;
123
- category: 'schema' | 'policy' | 'performance' | 'error-handling';
124
- summary: string;
125
- justification: string;
126
- recommendedActions: string[];
127
- lifecycleStage?: LifecycleStage;
128
- lifecycleNotes?: string;
129
- }
130
- //#endregion
131
- export { AnomalySeverity, EvolutionConfig, IntentPattern, OperationCoordinate, OperationMetricSample, OptimizationHint, PatternConfidence, SpecAnomaly, SpecSuggestion, SpecSuggestionFilters, SpecSuggestionProposal, SpecSuggestionRepository, SpecSuggestionWriter, SpecUsageStats, SuggestionEvidence, SuggestionStatus };
132
- //# sourceMappingURL=types.d.mts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.d.mts","names":[],"sources":["../src/types.ts"],"sourcesContent":[],"mappings":";;;;;KAQY,eAAA;KACA,gBAAA;AADA,UAGK,mBAAA,CAHU;EACf,GAAA,EAAA,MAAA;EAEK,OAAA,EAAA,MAAA;EAMA,QAAA,CAAA,EAAA,MAAA;;AAIJ,UAJI,qBAAA,CAIJ;EAOA,SAAA,EAVA,mBAUA;EAAM,UAAA,EAAA,MAAA;EAGF,OAAA,EAAA,OAAA;EACJ,SAAA,EAXA,IAWA;EAQC,gBAAA,CAAA,EAAA,MAAA;EACC,SAAA,CAAA,EAAA,MAAA;EACF,YAAA,CAAA,EAAA,MAAA;EACA,KAAA,CAAA,EAAA,MAAA;EAAM,OAAA,CAAA,E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