@lssm/lib.contracts 0.0.0-canary-20251217063201 → 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/app-config/app-config.feature.js +53 -1
- package/dist/app-config/contracts.d.ts +50 -50
- package/dist/app-config/contracts.js +396 -1
- package/dist/app-config/docs/app-config.docblock.js +22 -220
- package/dist/app-config/events.d.ts +27 -27
- package/dist/app-config/events.js +168 -1
- package/dist/app-config/index.js +8 -1
- package/dist/app-config/lifecycle-contracts.d.ts +80 -80
- package/dist/app-config/lifecycle-contracts.js +441 -1
- package/dist/app-config/runtime.js +617 -1
- package/dist/app-config/spec.js +36 -1
- package/dist/app-config/validation.js +538 -1
- package/dist/capabilities/docs/capabilities.docblock.js +22 -1
- package/dist/capabilities/openbanking.js +92 -1
- package/dist/capabilities.js +50 -1
- package/dist/client/index.js +9 -1
- package/dist/client/react/drivers/rn-reusables.js +21 -1
- package/dist/client/react/drivers/shadcn.js +11 -1
- package/dist/client/react/feature-render.js +43 -1
- package/dist/client/react/form-render.js +298 -1
- package/dist/client/react/index.js +8 -1
- package/dist/contract-registry/index.js +3 -1
- package/dist/contract-registry/schemas.js +61 -1
- package/dist/contracts-adapter-hydration.js +41 -1
- package/dist/contracts-adapter-input.js +77 -1
- package/dist/data-views/docs/data-views.docblock.js +22 -1
- package/dist/data-views/query-generator.js +48 -1
- package/dist/data-views/runtime.js +39 -1
- package/dist/data-views.js +35 -1
- package/dist/docs/PUBLISHING.docblock.js +17 -76
- package/dist/docs/accessibility_wcag_compliance_specs.docblock.js +17 -350
- package/dist/docs/index.js +33 -1
- package/dist/docs/meta.docs.js +15 -2
- package/dist/docs/presentations.js +77 -1
- package/dist/docs/registry.js +51 -1
- package/dist/docs/tech/PHASE_1_QUICKSTART.docblock.js +17 -383
- package/dist/docs/tech/PHASE_2_AI_NATIVE_OPERATIONS.docblock.js +17 -68
- package/dist/docs/tech/PHASE_3_AUTO_EVOLUTION.docblock.js +17 -140
- package/dist/docs/tech/PHASE_4_PERSONALIZATION_ENGINE.docblock.js +17 -86
- package/dist/docs/tech/PHASE_5_ZERO_TOUCH_OPERATIONS.docblock.js +17 -1
- package/dist/docs/tech/auth/better-auth-nextjs.docblock.js +25 -2
- package/dist/docs/tech/contracts/README.docblock.js +21 -1
- package/dist/docs/tech/contracts/create-subscription.docblock.js +21 -1
- package/dist/docs/tech/contracts/graphql-typed-outputs.docblock.js +21 -180
- package/dist/docs/tech/contracts/migrations.docblock.js +21 -1
- package/dist/docs/tech/contracts/openapi-export.docblock.js +22 -2
- package/dist/docs/tech/contracts/ops-to-presentation-linking.docblock.js +19 -60
- package/dist/docs/tech/contracts/overlays.docblock.js +21 -68
- package/dist/docs/tech/contracts/tests.docblock.js +21 -132
- package/dist/docs/tech/contracts/themes.docblock.js +21 -1
- package/dist/docs/tech/contracts/vertical-pocket-family-office.docblock.js +21 -106
- package/dist/docs/tech/lifecycle-stage-system.docblock.js +17 -213
- package/dist/docs/tech/llm/llm-integration.docblock.js +74 -5
- package/dist/docs/tech/mcp-endpoints.docblock.js +38 -1
- package/dist/docs/tech/presentation-runtime.docblock.js +17 -1
- package/dist/docs/tech/schema/README.docblock.js +21 -262
- package/dist/docs/tech/studio/learning-events.docblock.js +49 -1
- package/dist/docs/tech/studio/learning-journeys.docblock.js +25 -2
- package/dist/docs/tech/studio/platform-admin-panel.docblock.js +24 -2
- package/dist/docs/tech/studio/project-access-teams.docblock.js +26 -16
- package/dist/docs/tech/studio/project-routing.docblock.js +68 -1
- package/dist/docs/tech/studio/sandbox-unlogged.docblock.js +23 -2
- package/dist/docs/tech/studio/team-invitations.docblock.js +41 -36
- package/dist/docs/tech/studio/workspace-ops.docblock.js +48 -1
- package/dist/docs/tech/studio/workspaces.docblock.js +24 -2
- package/dist/docs/tech/telemetry-ingest.docblock.js +37 -3
- package/dist/docs/tech/templates/runtime.docblock.js +21 -1
- package/dist/docs/tech/vscode-extension.docblock.js +37 -3
- package/dist/docs/tech/workflows/overview.docblock.js +21 -1
- package/dist/docs/tech-contracts.docs.js +19 -2
- package/dist/events.js +12 -1
- package/dist/experiments/docs/experiments.docblock.js +22 -128
- package/dist/experiments/evaluator.js +101 -1
- package/dist/experiments/spec.js +33 -1
- package/dist/features.js +68 -1
- package/dist/forms/docs/forms.docblock.js +22 -1
- package/dist/forms.js +119 -1
- package/dist/index.js +107 -1
- package/dist/install.js +40 -1
- package/dist/integrations/contracts.d.ts +102 -102
- package/dist/integrations/contracts.js +388 -1
- package/dist/integrations/docs/integrations.docblock.js +95 -1
- package/dist/integrations/health.js +69 -1
- package/dist/integrations/index.js +23 -1
- package/dist/integrations/openbanking/contracts/accounts.d.ts +66 -66
- package/dist/integrations/openbanking/contracts/accounts.js +237 -1
- package/dist/integrations/openbanking/contracts/balances.d.ts +34 -34
- package/dist/integrations/openbanking/contracts/balances.js +167 -1
- package/dist/integrations/openbanking/contracts/index.js +12 -1
- package/dist/integrations/openbanking/contracts/transactions.d.ts +48 -48
- package/dist/integrations/openbanking/contracts/transactions.js +218 -1
- package/dist/integrations/openbanking/guards.js +32 -1
- package/dist/integrations/openbanking/models.d.ts +55 -55
- package/dist/integrations/openbanking/models.js +242 -1
- package/dist/integrations/openbanking/openbanking.feature.js +68 -1
- package/dist/integrations/openbanking/telemetry.js +39 -1
- package/dist/integrations/providers/elevenlabs.js +56 -1
- package/dist/integrations/providers/gcs-storage.js +79 -1
- package/dist/integrations/providers/gmail.js +91 -1
- package/dist/integrations/providers/google-calendar.js +70 -1
- package/dist/integrations/providers/impls/elevenlabs-voice.js +95 -1
- package/dist/integrations/providers/impls/gcs-storage.js +88 -1
- package/dist/integrations/providers/impls/gmail-inbound.js +200 -1
- package/dist/integrations/providers/impls/gmail-outbound.js +104 -5
- package/dist/integrations/providers/impls/google-calendar.js +154 -1
- package/dist/integrations/providers/impls/index.js +16 -1
- package/dist/integrations/providers/impls/mistral-embedding.js +41 -1
- package/dist/integrations/providers/impls/mistral-llm.js +247 -1
- package/dist/integrations/providers/impls/postmark-email.js +55 -1
- package/dist/integrations/providers/impls/powens-client.js +171 -1
- package/dist/integrations/providers/impls/powens-openbanking.js +218 -1
- package/dist/integrations/providers/impls/provider-factory.js +142 -1
- package/dist/integrations/providers/impls/qdrant-vector.js +69 -1
- package/dist/integrations/providers/impls/stripe-payments.js +202 -1
- package/dist/integrations/providers/impls/twilio-sms.js +58 -1
- package/dist/integrations/providers/index.js +13 -1
- package/dist/integrations/providers/mistral.js +72 -1
- package/dist/integrations/providers/postmark.js +72 -1
- package/dist/integrations/providers/powens.js +120 -1
- package/dist/integrations/providers/qdrant.js +77 -1
- package/dist/integrations/providers/registry.js +34 -1
- package/dist/integrations/providers/stripe.js +87 -1
- package/dist/integrations/providers/twilio-sms.js +65 -1
- package/dist/integrations/runtime.js +186 -1
- package/dist/integrations/secrets/aws-secret-manager.js +231 -1
- package/dist/integrations/secrets/env-secret-provider.js +81 -1
- package/dist/integrations/secrets/gcp-secret-manager.js +229 -1
- package/dist/integrations/secrets/index.js +8 -1
- package/dist/integrations/secrets/manager.js +103 -1
- package/dist/integrations/secrets/provider.js +58 -1
- package/dist/integrations/secrets/scaleway-secret-manager.js +247 -1
- package/dist/integrations/spec.js +39 -1
- package/dist/jobs/define-job.js +16 -1
- package/dist/jobs/gcp-cloud-tasks.js +53 -1
- package/dist/jobs/gcp-pubsub.js +39 -1
- package/dist/jobs/handlers/gmail-sync-handler.js +9 -1
- package/dist/jobs/handlers/index.js +12 -1
- package/dist/jobs/handlers/ping-handler.js +15 -1
- package/dist/jobs/handlers/storage-document-handler.js +14 -1
- package/dist/jobs/index.js +4 -1
- package/dist/jobs/memory-queue.js +71 -1
- package/dist/jobs/queue.js +33 -1
- package/dist/jobs/scaleway-sqs-queue.js +153 -1
- package/dist/jsonschema.d.ts +3 -3
- package/dist/jsonschema.js +32 -1
- package/dist/knowledge/contracts.d.ts +66 -66
- package/dist/knowledge/contracts.js +317 -1
- package/dist/knowledge/docs/knowledge.docblock.js +22 -138
- package/dist/knowledge/index.js +10 -1
- package/dist/knowledge/ingestion/document-processor.js +54 -1
- package/dist/knowledge/ingestion/embedding-service.js +25 -1
- package/dist/knowledge/ingestion/gmail-adapter.js +50 -5
- package/dist/knowledge/ingestion/index.js +7 -1
- package/dist/knowledge/ingestion/storage-adapter.js +26 -1
- package/dist/knowledge/ingestion/vector-indexer.js +32 -1
- package/dist/knowledge/query/index.js +3 -1
- package/dist/knowledge/query/service.js +64 -2
- package/dist/knowledge/runtime.js +49 -1
- package/dist/knowledge/spaces/email-threads.js +38 -1
- package/dist/knowledge/spaces/financial-docs.js +38 -1
- package/dist/knowledge/spaces/financial-overview.js +42 -1
- package/dist/knowledge/spaces/index.js +8 -1
- package/dist/knowledge/spaces/product-canon.js +38 -1
- package/dist/knowledge/spaces/support-faq.js +41 -1
- package/dist/knowledge/spaces/uploaded-docs.js +38 -1
- package/dist/knowledge/spec.js +39 -1
- package/dist/llm/exporters.js +541 -8
- package/dist/llm/index.js +4 -1
- package/dist/llm/prompts.js +246 -56
- package/dist/markdown.js +116 -3
- package/dist/migrations.js +33 -1
- package/dist/onboarding-base.d.ts +29 -29
- package/dist/onboarding-base.js +196 -1
- package/dist/openapi.js +75 -1
- package/dist/openbanking/docs/openbanking.docblock.js +22 -109
- package/dist/ownership.js +40 -1
- package/dist/policy/docs/policy.docblock.js +22 -1
- package/dist/policy/engine.js +223 -1
- package/dist/policy/opa-adapter.js +71 -1
- package/dist/policy/spec.js +33 -1
- package/dist/presentations/docs/presentations-conventions.docblock.js +21 -7
- package/dist/presentations.backcompat.js +47 -1
- package/dist/presentations.d.ts +3 -3
- package/dist/presentations.js +66 -1
- package/dist/presentations.v2.js +278 -6
- package/dist/prompt.js +10 -1
- package/dist/promptRegistry.js +34 -1
- package/dist/regenerator/docs/regenerator.docblock.js +22 -184
- package/dist/regenerator/executor.js +86 -1
- package/dist/regenerator/index.js +6 -1
- package/dist/regenerator/service.js +92 -1
- package/dist/regenerator/sinks.js +32 -1
- package/dist/regenerator/utils.js +51 -1
- package/dist/registry.js +208 -1
- package/dist/resources.js +47 -1
- package/dist/schema/dist/EnumType.js +2 -1
- package/dist/schema/dist/FieldType.js +49 -1
- package/dist/schema/dist/ScalarTypeEnum.js +236 -1
- package/dist/schema/dist/SchemaModel.js +39 -1
- package/dist/schema/dist/entity/defineEntity.js +1 -1
- package/dist/schema/dist/entity/index.js +2 -1
- package/dist/schema/dist/entity/types.js +1 -1
- package/dist/schema/dist/index.js +6 -1
- package/dist/schema-to-markdown.js +214 -10
- package/dist/server/graphql-pothos.js +128 -1
- package/dist/server/index.js +10 -1
- package/dist/server/mcp/createMcpServer.js +28 -1
- package/dist/server/mcp/registerPresentations.js +151 -1
- package/dist/server/mcp/registerPrompts.js +36 -2
- package/dist/server/mcp/registerResources.js +35 -1
- package/dist/server/mcp/registerTools.js +22 -1
- package/dist/server/provider-mcp.js +3 -1
- package/dist/server/rest-elysia.js +20 -1
- package/dist/server/rest-express.js +39 -1
- package/dist/server/rest-generic.js +125 -1
- package/dist/server/rest-next-app.js +38 -1
- package/dist/server/rest-next-mcp.js +45 -1
- package/dist/server/rest-next-pages.js +25 -1
- package/dist/spec.js +35 -1
- package/dist/telemetry/anomaly.js +48 -1
- package/dist/telemetry/docs/telemetry.docblock.js +22 -139
- package/dist/telemetry/index.js +5 -1
- package/dist/telemetry/spec.js +69 -1
- package/dist/telemetry/tracker.js +76 -1
- package/dist/tests/index.js +4 -1
- package/dist/tests/runner.js +150 -1
- package/dist/tests/spec.js +33 -1
- package/dist/themes.js +39 -1
- package/dist/workflow/adapters/db-adapter.js +83 -1
- package/dist/workflow/adapters/file-adapter.js +11 -1
- package/dist/workflow/adapters/index.js +5 -1
- package/dist/workflow/adapters/memory-store.js +58 -1
- package/dist/workflow/expression.js +98 -1
- package/dist/workflow/index.js +9 -1
- package/dist/workflow/runner.js +337 -1
- package/dist/workflow/sla-monitor.js +47 -1
- package/dist/workflow/spec.js +32 -1
- package/dist/workflow/validation.js +175 -1
- package/package.json +11 -4
package/dist/llm/prompts.js
CHANGED
|
@@ -1,4 +1,11 @@
|
|
|
1
|
-
import{specToAgentPrompt
|
|
1
|
+
import { specToAgentPrompt, specToFullMarkdown } from "./exporters.js";
|
|
2
|
+
|
|
3
|
+
//#region src/llm/prompts.ts
|
|
4
|
+
/**
|
|
5
|
+
* System prompts for different agent types.
|
|
6
|
+
*/
|
|
7
|
+
const AGENT_SYSTEM_PROMPTS = {
|
|
8
|
+
"claude-code": `You are an expert TypeScript developer working with ContractSpec, a spec-first development framework.
|
|
2
9
|
|
|
3
10
|
Your code follows these principles:
|
|
4
11
|
- Type-safe with comprehensive TypeScript types (no \`any\`)
|
|
@@ -14,7 +21,8 @@ When implementing specs:
|
|
|
14
21
|
4. Respect policy constraints (auth, rate limits, PII handling)
|
|
15
22
|
5. Follow the acceptance scenarios as your implementation guide
|
|
16
23
|
|
|
17
|
-
Generate clean, idiomatic TypeScript that exactly matches the specification.`,
|
|
24
|
+
Generate clean, idiomatic TypeScript that exactly matches the specification.`,
|
|
25
|
+
"cursor-cli": `You are implementing features for a ContractSpec-driven codebase.
|
|
18
26
|
|
|
19
27
|
ContractSpec is a spec-first framework where specifications define:
|
|
20
28
|
- Operations (commands and queries) with typed I/O
|
|
@@ -29,7 +37,8 @@ When working with specs:
|
|
|
29
37
|
- Follow the acceptance scenarios
|
|
30
38
|
- Respect policy constraints
|
|
31
39
|
|
|
32
|
-
Use the project's existing patterns and conventions.`,
|
|
40
|
+
Use the project's existing patterns and conventions.`,
|
|
41
|
+
"generic-mcp": `You are a code generation assistant working with ContractSpec specifications.
|
|
33
42
|
|
|
34
43
|
ContractSpec specs define:
|
|
35
44
|
- meta: name, version, kind (command/query), description, goal, context
|
|
@@ -39,14 +48,23 @@ ContractSpec specs define:
|
|
|
39
48
|
- acceptance: scenarios and examples
|
|
40
49
|
|
|
41
50
|
Your task is to generate or modify code that complies with the given specification.
|
|
42
|
-
Follow the spec exactly and handle all defined cases.`
|
|
51
|
+
Follow the spec exactly and handle all defined cases.`
|
|
52
|
+
};
|
|
53
|
+
/**
|
|
54
|
+
* Generate an implementation prompt for a specific agent type.
|
|
55
|
+
*/
|
|
56
|
+
function generateImplementationPrompt(spec, agent, options) {
|
|
57
|
+
const systemPrompt = AGENT_SYSTEM_PROMPTS[agent];
|
|
58
|
+
const specMarkdown = specToFullMarkdown(spec);
|
|
59
|
+
let taskPrompt;
|
|
60
|
+
if (agent === "claude-code") taskPrompt = `## Implementation Task
|
|
43
61
|
|
|
44
62
|
Implement the following ContractSpec operation:
|
|
45
63
|
|
|
46
|
-
${
|
|
64
|
+
${specMarkdown}
|
|
47
65
|
|
|
48
|
-
${
|
|
49
|
-
${
|
|
66
|
+
${options?.targetPath ? `**Target file:** \`${options.targetPath}\`\n` : ""}
|
|
67
|
+
${options?.existingCode ? `**Existing code to modify:**\n\`\`\`typescript\n${options.existingCode}\n\`\`\`\n` : ""}
|
|
50
68
|
|
|
51
69
|
Generate a complete, production-ready TypeScript implementation that:
|
|
52
70
|
1. Exports a handler function matching the spec signature
|
|
@@ -55,25 +73,42 @@ Generate a complete, production-ready TypeScript implementation that:
|
|
|
55
73
|
4. Emits events as specified
|
|
56
74
|
5. Includes JSDoc documentation
|
|
57
75
|
|
|
58
|
-
Provide ONLY the TypeScript code
|
|
76
|
+
Provide ONLY the TypeScript code.`;
|
|
77
|
+
else if (agent === "cursor-cli") taskPrompt = `Implement this ContractSpec operation.
|
|
59
78
|
|
|
60
|
-
${
|
|
79
|
+
${specMarkdown}
|
|
61
80
|
|
|
62
|
-
${
|
|
81
|
+
${options?.targetPath ? `Target: ${options.targetPath}\n` : ""}
|
|
63
82
|
|
|
64
83
|
Requirements:
|
|
65
84
|
- TypeScript with strict types
|
|
66
85
|
- Handle all error cases
|
|
67
86
|
- Emit specified events
|
|
68
|
-
- Follow acceptance scenarios
|
|
87
|
+
- Follow acceptance scenarios`;
|
|
88
|
+
else taskPrompt = specToAgentPrompt(spec, {
|
|
89
|
+
taskType: "implement",
|
|
90
|
+
existingCode: options?.existingCode
|
|
91
|
+
});
|
|
92
|
+
return {
|
|
93
|
+
agent,
|
|
94
|
+
systemPrompt,
|
|
95
|
+
taskPrompt
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Generate a test generation prompt.
|
|
100
|
+
*/
|
|
101
|
+
function generateTestPrompt(spec, agent, options) {
|
|
102
|
+
const framework = options?.testFramework ?? "vitest";
|
|
103
|
+
const taskPrompt = `## Test Generation Task
|
|
69
104
|
|
|
70
105
|
Generate comprehensive tests for this specification:
|
|
71
106
|
|
|
72
|
-
${
|
|
107
|
+
${specToFullMarkdown(spec)}
|
|
73
108
|
|
|
74
|
-
${
|
|
109
|
+
${options?.implementationCode ? `**Implementation:**\n\`\`\`typescript\n${options.implementationCode}\n\`\`\`\n` : ""}
|
|
75
110
|
|
|
76
|
-
**Test Framework:** ${
|
|
111
|
+
**Test Framework:** ${framework}
|
|
77
112
|
|
|
78
113
|
Generate tests that:
|
|
79
114
|
1. Cover all acceptance scenarios from the spec
|
|
@@ -84,16 +119,27 @@ Generate tests that:
|
|
|
84
119
|
|
|
85
120
|
Use descriptive test names: "should [behavior] when [condition]"
|
|
86
121
|
|
|
87
|
-
Provide a complete test file.`;
|
|
122
|
+
Provide a complete test file.`;
|
|
123
|
+
return {
|
|
124
|
+
agent,
|
|
125
|
+
systemPrompt: AGENT_SYSTEM_PROMPTS[agent],
|
|
126
|
+
taskPrompt
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Generate a code review prompt.
|
|
131
|
+
*/
|
|
132
|
+
function generateReviewPrompt(spec, agent, implementationCode) {
|
|
133
|
+
const taskPrompt = `## Code Review Task
|
|
88
134
|
|
|
89
135
|
Review this implementation against its specification:
|
|
90
136
|
|
|
91
137
|
**Specification:**
|
|
92
|
-
${
|
|
138
|
+
${specToFullMarkdown(spec)}
|
|
93
139
|
|
|
94
140
|
**Implementation:**
|
|
95
141
|
\`\`\`typescript
|
|
96
|
-
${
|
|
142
|
+
${implementationCode}
|
|
97
143
|
\`\`\`
|
|
98
144
|
|
|
99
145
|
Provide a structured review:
|
|
@@ -111,16 +157,29 @@ List any issues with severity (error/warning/info)
|
|
|
111
157
|
### Suggestions
|
|
112
158
|
List improvements and recommendations
|
|
113
159
|
|
|
114
|
-
Be thorough and precise. Focus on spec compliance first, then code quality.`;
|
|
160
|
+
Be thorough and precise. Focus on spec compliance first, then code quality.`;
|
|
161
|
+
return {
|
|
162
|
+
agent,
|
|
163
|
+
systemPrompt: AGENT_SYSTEM_PROMPTS[agent],
|
|
164
|
+
taskPrompt
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Generate a verification prompt for AI-powered semantic review.
|
|
169
|
+
*/
|
|
170
|
+
function generateVerificationPrompt(spec, implementationCode) {
|
|
171
|
+
return {
|
|
172
|
+
agent: "generic-mcp",
|
|
173
|
+
taskPrompt: `## Semantic Verification Task
|
|
115
174
|
|
|
116
175
|
Verify that this implementation fulfills the specification's intent.
|
|
117
176
|
|
|
118
177
|
**Specification:**
|
|
119
|
-
${
|
|
178
|
+
${specToFullMarkdown(spec)}
|
|
120
179
|
|
|
121
180
|
**Implementation:**
|
|
122
181
|
\`\`\`typescript
|
|
123
|
-
${
|
|
182
|
+
${implementationCode}
|
|
124
183
|
\`\`\`
|
|
125
184
|
|
|
126
185
|
Analyze and respond with JSON:
|
|
@@ -144,77 +203,208 @@ Analyze and respond with JSON:
|
|
|
144
203
|
],
|
|
145
204
|
"summary": "Brief summary of verification results"
|
|
146
205
|
}
|
|
147
|
-
\`\`\``
|
|
206
|
+
\`\`\``
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* Generate a feature implementation plan.
|
|
211
|
+
*/
|
|
212
|
+
function generateImplementationPlan(spec, options) {
|
|
213
|
+
const m = spec.meta;
|
|
214
|
+
const fileStructure = [];
|
|
215
|
+
const basePath = options?.projectRoot ?? "src";
|
|
216
|
+
const specPath = m.name.replace(/\./g, "/");
|
|
217
|
+
if (m.kind === "command" || m.kind === "query") fileStructure.push({
|
|
218
|
+
path: `${basePath}/${specPath}/handler.ts`,
|
|
219
|
+
purpose: "Main handler implementation",
|
|
220
|
+
type: "create"
|
|
221
|
+
}, {
|
|
222
|
+
path: `${basePath}/${specPath}/types.ts`,
|
|
223
|
+
purpose: "Type definitions",
|
|
224
|
+
type: "create"
|
|
225
|
+
}, {
|
|
226
|
+
path: `${basePath}/${specPath}/handler.test.ts`,
|
|
227
|
+
purpose: "Handler tests",
|
|
228
|
+
type: "create"
|
|
229
|
+
});
|
|
230
|
+
const steps = [];
|
|
231
|
+
let order = 1;
|
|
232
|
+
steps.push({
|
|
233
|
+
order: order++,
|
|
234
|
+
title: "Define Types",
|
|
235
|
+
description: "Create TypeScript types for input, output, and internal data structures",
|
|
236
|
+
acceptanceCriteria: [
|
|
237
|
+
"Input type matches spec schema exactly",
|
|
238
|
+
"Output type matches spec schema exactly",
|
|
239
|
+
"Error types defined for all error cases"
|
|
240
|
+
]
|
|
241
|
+
});
|
|
242
|
+
steps.push({
|
|
243
|
+
order: order++,
|
|
244
|
+
title: "Implement Input Validation",
|
|
245
|
+
description: "Add validation logic for the input payload",
|
|
246
|
+
acceptanceCriteria: [
|
|
247
|
+
"All required fields are validated",
|
|
248
|
+
"Type constraints are enforced",
|
|
249
|
+
"Validation errors return appropriate error codes"
|
|
250
|
+
]
|
|
251
|
+
});
|
|
252
|
+
steps.push({
|
|
253
|
+
order: order++,
|
|
254
|
+
title: "Implement Core Logic",
|
|
255
|
+
description: "Implement the main business logic of the operation",
|
|
256
|
+
acceptanceCriteria: spec.acceptance?.scenarios?.map((s) => s.name) ?? ["Operation completes successfully for valid input"]
|
|
257
|
+
});
|
|
258
|
+
if (spec.io.errors && Object.keys(spec.io.errors).length > 0) steps.push({
|
|
259
|
+
order: order++,
|
|
260
|
+
title: "Implement Error Handling",
|
|
261
|
+
description: "Handle all defined error cases",
|
|
262
|
+
acceptanceCriteria: Object.entries(spec.io.errors).map(([code, err]) => `Handle ${code}: ${err.when}`)
|
|
263
|
+
});
|
|
264
|
+
if (spec.sideEffects?.emits?.length) steps.push({
|
|
265
|
+
order: order++,
|
|
266
|
+
title: "Implement Event Emission",
|
|
267
|
+
description: "Emit events as specified",
|
|
268
|
+
acceptanceCriteria: spec.sideEffects.emits.map((e) => {
|
|
269
|
+
if ("ref" in e) return `Emit ${e.ref.name}.v${e.ref.version} when ${e.when}`;
|
|
270
|
+
return `Emit ${e.name}.v${e.version} when ${e.when}`;
|
|
271
|
+
})
|
|
272
|
+
});
|
|
273
|
+
steps.push({
|
|
274
|
+
order: order++,
|
|
275
|
+
title: "Write Tests",
|
|
276
|
+
description: "Create comprehensive test suite",
|
|
277
|
+
acceptanceCriteria: [
|
|
278
|
+
"All acceptance scenarios covered",
|
|
279
|
+
"All error cases tested",
|
|
280
|
+
"Edge cases handled",
|
|
281
|
+
"Events verified"
|
|
282
|
+
]
|
|
283
|
+
});
|
|
284
|
+
const constraints = {
|
|
285
|
+
policy: [],
|
|
286
|
+
security: [],
|
|
287
|
+
pii: []
|
|
288
|
+
};
|
|
289
|
+
constraints.policy.push(`Auth level: ${spec.policy.auth}`);
|
|
290
|
+
if (spec.policy.idempotent !== void 0) constraints.policy.push(`Idempotent: ${spec.policy.idempotent}`);
|
|
291
|
+
if (spec.policy.rateLimit) constraints.policy.push(`Rate limit: ${spec.policy.rateLimit.rpm} rpm per ${spec.policy.rateLimit.key}`);
|
|
292
|
+
if (spec.policy.flags?.length) constraints.policy.push(`Feature flags required: ${spec.policy.flags.join(", ")}`);
|
|
293
|
+
if (spec.policy.escalate) constraints.security.push(`Escalation required: ${spec.policy.escalate}`);
|
|
294
|
+
if (spec.policy.pii?.length) constraints.pii = spec.policy.pii;
|
|
295
|
+
return {
|
|
296
|
+
target: {
|
|
297
|
+
type: "spec",
|
|
298
|
+
name: m.name,
|
|
299
|
+
version: m.version
|
|
300
|
+
},
|
|
301
|
+
context: {
|
|
302
|
+
goal: m.goal,
|
|
303
|
+
description: m.description,
|
|
304
|
+
background: m.context
|
|
305
|
+
},
|
|
306
|
+
specMarkdown: specToFullMarkdown(spec),
|
|
307
|
+
fileStructure,
|
|
308
|
+
steps,
|
|
309
|
+
constraints,
|
|
310
|
+
verificationChecklist: [
|
|
311
|
+
"Input validation works for all cases",
|
|
312
|
+
"Output matches expected schema",
|
|
313
|
+
"All error cases return correct codes",
|
|
314
|
+
"Events are emitted with correct payloads",
|
|
315
|
+
"Auth requirements are enforced",
|
|
316
|
+
"Rate limiting is applied (if applicable)",
|
|
317
|
+
"PII fields are handled correctly",
|
|
318
|
+
"All acceptance scenarios pass",
|
|
319
|
+
"Tests provide adequate coverage"
|
|
320
|
+
]
|
|
321
|
+
};
|
|
322
|
+
}
|
|
323
|
+
/**
|
|
324
|
+
* Format an implementation plan for a specific agent.
|
|
325
|
+
*/
|
|
326
|
+
function formatPlanForAgent(plan, agent) {
|
|
327
|
+
let taskPrompt;
|
|
328
|
+
if (agent === "claude-code") taskPrompt = `## Implementation Plan: ${plan.target.name}.v${plan.target.version}
|
|
148
329
|
|
|
149
330
|
### Context
|
|
150
|
-
**Goal:** ${
|
|
331
|
+
**Goal:** ${plan.context.goal}
|
|
151
332
|
|
|
152
|
-
**Background:** ${
|
|
333
|
+
**Background:** ${plan.context.background}
|
|
153
334
|
|
|
154
335
|
### Specification
|
|
155
|
-
${
|
|
336
|
+
${plan.specMarkdown}
|
|
156
337
|
|
|
157
338
|
### File Structure
|
|
158
|
-
${
|
|
159
|
-
`)}
|
|
339
|
+
${plan.fileStructure.map((f) => `- \`${f.path}\` (${f.type}): ${f.purpose}`).join("\n")}
|
|
160
340
|
|
|
161
341
|
### Implementation Steps
|
|
162
|
-
${
|
|
163
|
-
#### Step ${
|
|
164
|
-
${
|
|
342
|
+
${plan.steps.map((s) => `
|
|
343
|
+
#### Step ${s.order}: ${s.title}
|
|
344
|
+
${s.description}
|
|
165
345
|
|
|
166
346
|
**Acceptance Criteria:**
|
|
167
|
-
${
|
|
168
|
-
`)}
|
|
169
|
-
`).join(`
|
|
170
|
-
`)}
|
|
347
|
+
${s.acceptanceCriteria.map((c) => `- [ ] ${c}`).join("\n")}
|
|
348
|
+
`).join("\n")}
|
|
171
349
|
|
|
172
350
|
### Constraints
|
|
173
|
-
${
|
|
174
|
-
`)}\n
|
|
175
|
-
${
|
|
176
|
-
`)}\n`:``}
|
|
177
|
-
${e.constraints.pii.length?`**PII Handling:**\n${e.constraints.pii.map(e=>`- ${e}`).join(`
|
|
178
|
-
`)}\n`:``}
|
|
351
|
+
${plan.constraints.policy.length ? `**Policy:**\n${plan.constraints.policy.map((p) => `- ${p}`).join("\n")}\n` : ""}
|
|
352
|
+
${plan.constraints.security.length ? `**Security:**\n${plan.constraints.security.map((s) => `- ${s}`).join("\n")}\n` : ""}
|
|
353
|
+
${plan.constraints.pii.length ? `**PII Handling:**\n${plan.constraints.pii.map((p) => `- ${p}`).join("\n")}\n` : ""}
|
|
179
354
|
|
|
180
355
|
### Verification Checklist
|
|
181
|
-
${
|
|
182
|
-
`)}
|
|
356
|
+
${plan.verificationChecklist.map((c) => `- [ ] ${c}`).join("\n")}
|
|
183
357
|
|
|
184
|
-
Implement this plan step by step
|
|
358
|
+
Implement this plan step by step.`;
|
|
359
|
+
else if (agent === "cursor-cli") taskPrompt = `# ${plan.target.name}.v${plan.target.version}
|
|
185
360
|
|
|
186
|
-
${
|
|
361
|
+
${plan.context.goal}
|
|
187
362
|
|
|
188
363
|
## Spec
|
|
189
|
-
${
|
|
364
|
+
${plan.specMarkdown}
|
|
190
365
|
|
|
191
366
|
## Files to create
|
|
192
|
-
${
|
|
193
|
-
`)}
|
|
367
|
+
${plan.fileStructure.map((f) => `${f.type}: ${f.path}`).join("\n")}
|
|
194
368
|
|
|
195
369
|
## Steps
|
|
196
|
-
${
|
|
197
|
-
`
|
|
370
|
+
${plan.steps.map((s) => `${s.order}. ${s.title}`).join("\n")}`;
|
|
371
|
+
else taskPrompt = `Implementation plan for ${plan.target.name}.v${plan.target.version}
|
|
198
372
|
|
|
199
|
-
${
|
|
373
|
+
${plan.specMarkdown}
|
|
200
374
|
|
|
201
375
|
Steps:
|
|
202
|
-
${
|
|
203
|
-
|
|
376
|
+
${plan.steps.map((s) => `${s.order}. ${s.title}: ${s.description}`).join("\n")}`;
|
|
377
|
+
return {
|
|
378
|
+
agent,
|
|
379
|
+
systemPrompt: AGENT_SYSTEM_PROMPTS[agent],
|
|
380
|
+
taskPrompt
|
|
381
|
+
};
|
|
382
|
+
}
|
|
383
|
+
/**
|
|
384
|
+
* Generate a fix violations prompt after verification.
|
|
385
|
+
*/
|
|
386
|
+
function generateFixViolationsPrompt(spec, implementationCode, violations) {
|
|
387
|
+
return {
|
|
388
|
+
agent: "generic-mcp",
|
|
389
|
+
taskPrompt: `## Fix Specification Violations
|
|
204
390
|
|
|
205
391
|
The following implementation has violations against its specification:
|
|
206
392
|
|
|
207
393
|
**Specification:**
|
|
208
|
-
${
|
|
394
|
+
${specToFullMarkdown(spec)}
|
|
209
395
|
|
|
210
396
|
**Current Implementation:**
|
|
211
397
|
\`\`\`typescript
|
|
212
|
-
${
|
|
398
|
+
${implementationCode}
|
|
213
399
|
\`\`\`
|
|
214
400
|
|
|
215
401
|
**Violations Found:**
|
|
216
|
-
${
|
|
217
|
-
`)}
|
|
402
|
+
${violations.map((v, i) => `${i + 1}. ${v.message}${v.suggestion ? `\n Suggestion: ${v.suggestion}` : ""}`).join("\n")}
|
|
218
403
|
|
|
219
404
|
Fix ALL violations while maintaining existing functionality.
|
|
220
|
-
Provide the corrected implementation.`
|
|
405
|
+
Provide the corrected implementation.`
|
|
406
|
+
};
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
//#endregion
|
|
410
|
+
export { AGENT_SYSTEM_PROMPTS, formatPlanForAgent, generateFixViolationsPrompt, generateImplementationPlan, generateImplementationPrompt, generateReviewPrompt, generateTestPrompt, generateVerificationPrompt };
|
package/dist/markdown.js
CHANGED
|
@@ -1,3 +1,116 @@
|
|
|
1
|
-
import{isEmitDeclRef
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { isEmitDeclRef } from "./spec.js";
|
|
2
|
+
|
|
3
|
+
//#region src/markdown.ts
|
|
4
|
+
/**
|
|
5
|
+
* Render simple Markdown docs for each spec.
|
|
6
|
+
* Useful for dev portals and repo docs generation.
|
|
7
|
+
*/
|
|
8
|
+
function specsToMarkdown(reg, extras) {
|
|
9
|
+
const lines = [];
|
|
10
|
+
for (const spec of reg.listSpecs()) {
|
|
11
|
+
const m = spec.meta;
|
|
12
|
+
lines.push(`# ${m.name}.v${m.version}`);
|
|
13
|
+
lines.push("");
|
|
14
|
+
lines.push(`**Kind:** ${m.kind} | **Stability:** ${m.stability} | **Owners:** ${m.owners.join(", ")}`);
|
|
15
|
+
lines.push("");
|
|
16
|
+
lines.push(`**Description:** ${m.description}`);
|
|
17
|
+
lines.push("");
|
|
18
|
+
lines.push(`## Goal`);
|
|
19
|
+
lines.push(m.goal);
|
|
20
|
+
lines.push("");
|
|
21
|
+
lines.push(`## Context`);
|
|
22
|
+
lines.push(m.context);
|
|
23
|
+
lines.push("");
|
|
24
|
+
lines.push(`## Policy`);
|
|
25
|
+
lines.push(`- Auth: ${spec.policy.auth}`);
|
|
26
|
+
lines.push(`- Idempotent: ${!!spec.policy.idempotent}`);
|
|
27
|
+
if (spec.policy.rateLimit) lines.push(`- Rate Limit: ${spec.policy.rateLimit.rpm}/min by ${spec.policy.rateLimit.key}`);
|
|
28
|
+
if (spec.policy.flags?.length) lines.push(`- Flags: ${spec.policy.flags.join(", ")}`);
|
|
29
|
+
if (spec.policy.pii?.length) lines.push(`- PII: ${spec.policy.pii.join(", ")}`);
|
|
30
|
+
lines.push("");
|
|
31
|
+
if (spec.sideEffects?.emits?.length) {
|
|
32
|
+
lines.push(`## Emits Events`);
|
|
33
|
+
for (const e of spec.sideEffects.emits) if (isEmitDeclRef(e)) lines.push(`- \`${e.ref.name}.v${e.ref.version}\` — ${e.when}`);
|
|
34
|
+
else lines.push(`- \`${e.name}.v${e.version}\` — ${e.when}`);
|
|
35
|
+
lines.push("");
|
|
36
|
+
}
|
|
37
|
+
if (spec.io.errors && Object.keys(spec.io.errors).length) {
|
|
38
|
+
lines.push(`## Errors`);
|
|
39
|
+
for (const [code, err] of Object.entries(spec.io.errors)) lines.push(`- \`${code}\` (${err.http ?? 400}) — ${err.description} (when: ${err.when})`);
|
|
40
|
+
lines.push("");
|
|
41
|
+
}
|
|
42
|
+
if (spec.acceptance?.scenarios?.length) {
|
|
43
|
+
lines.push(`## Acceptance Scenarios`);
|
|
44
|
+
for (const s of spec.acceptance.scenarios) {
|
|
45
|
+
lines.push(`### ${s.name}`);
|
|
46
|
+
lines.push(`- **Given:** ${s.given.join("; ")}`);
|
|
47
|
+
lines.push(`- **When:** ${s.when.join("; ")}`);
|
|
48
|
+
lines.push(`- **Then:** ${s.then.join("; ")}`);
|
|
49
|
+
lines.push("");
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
if (spec.acceptance?.examples?.length) {
|
|
53
|
+
lines.push(`## Examples`);
|
|
54
|
+
for (const ex of spec.acceptance.examples) {
|
|
55
|
+
lines.push(`- **${ex.name}**`);
|
|
56
|
+
lines.push(" - Input:");
|
|
57
|
+
lines.push(" ```json");
|
|
58
|
+
lines.push(JSON.stringify(ex.input, null, 2));
|
|
59
|
+
lines.push(" ```");
|
|
60
|
+
lines.push(" - Output:");
|
|
61
|
+
lines.push(" ```json");
|
|
62
|
+
lines.push(JSON.stringify(ex.output, null, 2));
|
|
63
|
+
lines.push(" ```");
|
|
64
|
+
lines.push("");
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
lines.push("---");
|
|
68
|
+
lines.push("");
|
|
69
|
+
}
|
|
70
|
+
return lines.join("\n");
|
|
71
|
+
}
|
|
72
|
+
/** Render presentations and features as additional sections. */
|
|
73
|
+
function docsToMarkdown(reg, extras) {
|
|
74
|
+
const parts = [];
|
|
75
|
+
parts.push(specsToMarkdown(reg, extras));
|
|
76
|
+
if (extras.presentations) {
|
|
77
|
+
parts.push("# Presentations");
|
|
78
|
+
parts.push("");
|
|
79
|
+
for (const p of extras.presentations.list()) {
|
|
80
|
+
parts.push(`## ${p.meta.name}.v${p.meta.version}`);
|
|
81
|
+
parts.push("");
|
|
82
|
+
parts.push(`- Kind: ${p.content.kind}`);
|
|
83
|
+
if ("framework" in p.content) parts.push(`- Framework: ${p.content.framework}`);
|
|
84
|
+
if ("componentKey" in p.content) parts.push(`- Component Key: ${p.content.componentKey}`);
|
|
85
|
+
if ("mimeType" in p.content) parts.push(`- MIME Type: ${p.content.mimeType}`);
|
|
86
|
+
parts.push("");
|
|
87
|
+
}
|
|
88
|
+
parts.push("");
|
|
89
|
+
}
|
|
90
|
+
if (extras.features) {
|
|
91
|
+
parts.push("# Features");
|
|
92
|
+
parts.push("");
|
|
93
|
+
for (const f of extras.features.list()) {
|
|
94
|
+
parts.push(`## ${f.meta.title} (${f.meta.key})`);
|
|
95
|
+
if (f.meta.description) parts.push(f.meta.description);
|
|
96
|
+
parts.push("");
|
|
97
|
+
if (f.operations?.length) {
|
|
98
|
+
parts.push("- Operations:");
|
|
99
|
+
for (const o of f.operations) parts.push(` - ${o.name}.v${o.version}`);
|
|
100
|
+
}
|
|
101
|
+
if (f.events?.length) {
|
|
102
|
+
parts.push("- Events:");
|
|
103
|
+
for (const e of f.events) parts.push(` - ${e.name}.v${e.version}`);
|
|
104
|
+
}
|
|
105
|
+
if (f.presentations?.length) {
|
|
106
|
+
parts.push("- Presentations:");
|
|
107
|
+
for (const p of f.presentations) parts.push(` - ${p.name}.v${p.version}`);
|
|
108
|
+
}
|
|
109
|
+
parts.push("");
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
return parts.join("\n");
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
//#endregion
|
|
116
|
+
export { docsToMarkdown, specsToMarkdown };
|
package/dist/migrations.js
CHANGED
|
@@ -1 +1,33 @@
|
|
|
1
|
-
|
|
1
|
+
//#region src/migrations.ts
|
|
2
|
+
const migrationKey = (name, version) => `${name}.v${version}`;
|
|
3
|
+
var MigrationRegistry = class {
|
|
4
|
+
items = /* @__PURE__ */ new Map();
|
|
5
|
+
register(spec) {
|
|
6
|
+
const key = migrationKey(spec.meta.name, spec.meta.version);
|
|
7
|
+
if (this.items.has(key)) throw new Error(`Duplicate migration ${key}`);
|
|
8
|
+
this.items.set(key, spec);
|
|
9
|
+
return this;
|
|
10
|
+
}
|
|
11
|
+
list() {
|
|
12
|
+
return [...this.items.values()].sort((a, b) => compareKey(migrationKey(a.meta.name, a.meta.version), migrationKey(b.meta.name, b.meta.version)));
|
|
13
|
+
}
|
|
14
|
+
get(name, version) {
|
|
15
|
+
if (version != null) return this.items.get(migrationKey(name, version));
|
|
16
|
+
let candidate;
|
|
17
|
+
let max = -Infinity;
|
|
18
|
+
for (const spec of this.items.values()) {
|
|
19
|
+
if (spec.meta.name !== name) continue;
|
|
20
|
+
if (spec.meta.version > max) {
|
|
21
|
+
max = spec.meta.version;
|
|
22
|
+
candidate = spec;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return candidate;
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
function compareKey(a, b) {
|
|
29
|
+
return a < b ? -1 : a > b ? 1 : 0;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
//#endregion
|
|
33
|
+
export { MigrationRegistry };
|