@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/exporters.js
CHANGED
|
@@ -1,8 +1,541 @@
|
|
|
1
|
-
import{jsonSchemaForSpec
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
import { jsonSchemaForSpec } from "../jsonschema.js";
|
|
2
|
+
import { isEmitDeclRef } from "../spec.js";
|
|
3
|
+
|
|
4
|
+
//#region src/llm/exporters.ts
|
|
5
|
+
const DEFAULT_SPEC_OPTIONS = {
|
|
6
|
+
format: "full",
|
|
7
|
+
includeSchemas: true,
|
|
8
|
+
includeScenarios: true,
|
|
9
|
+
includeExamples: true,
|
|
10
|
+
includePolicy: true,
|
|
11
|
+
includeSideEffects: true
|
|
12
|
+
};
|
|
13
|
+
const DEFAULT_FEATURE_OPTIONS = {
|
|
14
|
+
...DEFAULT_SPEC_OPTIONS,
|
|
15
|
+
includeRelatedSpecs: true,
|
|
16
|
+
includeRelatedEvents: true,
|
|
17
|
+
includeRelatedPresentations: true
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* Export a single spec to context-focused markdown.
|
|
21
|
+
* Includes: goal, context, description, acceptance scenarios.
|
|
22
|
+
* Best for: Understanding what the spec does, providing context to LLMs.
|
|
23
|
+
*/
|
|
24
|
+
function specToContextMarkdown(spec) {
|
|
25
|
+
const m = spec.meta;
|
|
26
|
+
const lines = [];
|
|
27
|
+
lines.push(`# ${m.name} (v${m.version})`);
|
|
28
|
+
lines.push("");
|
|
29
|
+
lines.push(`> ${m.description}`);
|
|
30
|
+
lines.push("");
|
|
31
|
+
lines.push(`**Type:** ${m.kind} | **Stability:** ${m.stability}`);
|
|
32
|
+
lines.push("");
|
|
33
|
+
lines.push("## Goal");
|
|
34
|
+
lines.push("");
|
|
35
|
+
lines.push(m.goal);
|
|
36
|
+
lines.push("");
|
|
37
|
+
lines.push("## Context");
|
|
38
|
+
lines.push("");
|
|
39
|
+
lines.push(m.context);
|
|
40
|
+
lines.push("");
|
|
41
|
+
if (spec.acceptance?.scenarios?.length) {
|
|
42
|
+
lines.push("## Acceptance Criteria");
|
|
43
|
+
lines.push("");
|
|
44
|
+
for (const s of spec.acceptance.scenarios) {
|
|
45
|
+
lines.push(`### ${s.name}`);
|
|
46
|
+
lines.push("");
|
|
47
|
+
lines.push("**Given:**");
|
|
48
|
+
for (const g of s.given) lines.push(`- ${g}`);
|
|
49
|
+
lines.push("");
|
|
50
|
+
lines.push("**When:**");
|
|
51
|
+
for (const w of s.when) lines.push(`- ${w}`);
|
|
52
|
+
lines.push("");
|
|
53
|
+
lines.push("**Then:**");
|
|
54
|
+
for (const t of s.then) lines.push(`- ${t}`);
|
|
55
|
+
lines.push("");
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return lines.join("\n");
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Export a single spec to full markdown with all details.
|
|
62
|
+
* Includes: all fields, I/O schemas, policy, events, examples.
|
|
63
|
+
* Best for: Complete documentation, implementation reference.
|
|
64
|
+
*/
|
|
65
|
+
function specToFullMarkdown(spec, options = {}) {
|
|
66
|
+
const opts = {
|
|
67
|
+
...DEFAULT_SPEC_OPTIONS,
|
|
68
|
+
...options
|
|
69
|
+
};
|
|
70
|
+
const m = spec.meta;
|
|
71
|
+
const lines = [];
|
|
72
|
+
lines.push(`# ${m.name}.v${m.version}`);
|
|
73
|
+
lines.push("");
|
|
74
|
+
lines.push(`> ${m.description}`);
|
|
75
|
+
lines.push("");
|
|
76
|
+
lines.push("## Metadata");
|
|
77
|
+
lines.push("");
|
|
78
|
+
lines.push("| Field | Value |");
|
|
79
|
+
lines.push("|-------|-------|");
|
|
80
|
+
lines.push(`| Kind | ${m.kind} |`);
|
|
81
|
+
lines.push(`| Stability | ${m.stability} |`);
|
|
82
|
+
lines.push(`| Owners | ${m.owners.join(", ")} |`);
|
|
83
|
+
lines.push(`| Tags | ${m.tags.join(", ")} |`);
|
|
84
|
+
lines.push("");
|
|
85
|
+
lines.push("## Goal");
|
|
86
|
+
lines.push("");
|
|
87
|
+
lines.push(m.goal);
|
|
88
|
+
lines.push("");
|
|
89
|
+
lines.push("## Context");
|
|
90
|
+
lines.push("");
|
|
91
|
+
lines.push(m.context);
|
|
92
|
+
lines.push("");
|
|
93
|
+
if (opts.includeSchemas) {
|
|
94
|
+
lines.push("## Input/Output");
|
|
95
|
+
lines.push("");
|
|
96
|
+
if (spec.io.input) {
|
|
97
|
+
lines.push("### Input Schema");
|
|
98
|
+
lines.push("");
|
|
99
|
+
lines.push("```json");
|
|
100
|
+
try {
|
|
101
|
+
const schema = jsonSchemaForSpec(spec);
|
|
102
|
+
lines.push(JSON.stringify(schema.input ?? {}, null, 2));
|
|
103
|
+
} catch {
|
|
104
|
+
lines.push("// Schema generation not available");
|
|
105
|
+
}
|
|
106
|
+
lines.push("```");
|
|
107
|
+
lines.push("");
|
|
108
|
+
}
|
|
109
|
+
lines.push("### Output Schema");
|
|
110
|
+
lines.push("");
|
|
111
|
+
lines.push("```json");
|
|
112
|
+
try {
|
|
113
|
+
const schema = jsonSchemaForSpec(spec);
|
|
114
|
+
lines.push(JSON.stringify(schema.output ?? {}, null, 2));
|
|
115
|
+
} catch {
|
|
116
|
+
lines.push("// Schema generation not available");
|
|
117
|
+
}
|
|
118
|
+
lines.push("```");
|
|
119
|
+
lines.push("");
|
|
120
|
+
if (spec.io.errors && Object.keys(spec.io.errors).length) {
|
|
121
|
+
lines.push("### Error Codes");
|
|
122
|
+
lines.push("");
|
|
123
|
+
lines.push("| Code | HTTP | Description | When |");
|
|
124
|
+
lines.push("|------|------|-------------|------|");
|
|
125
|
+
for (const [code, err] of Object.entries(spec.io.errors)) lines.push(`| \`${code}\` | ${err.http ?? 400} | ${err.description} | ${err.when} |`);
|
|
126
|
+
lines.push("");
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
if (opts.includePolicy) {
|
|
130
|
+
lines.push("## Policy");
|
|
131
|
+
lines.push("");
|
|
132
|
+
lines.push(`- **Auth Required:** ${spec.policy.auth}`);
|
|
133
|
+
lines.push(`- **Idempotent:** ${spec.policy.idempotent ?? m.kind === "query"}`);
|
|
134
|
+
if (spec.policy.rateLimit) lines.push(`- **Rate Limit:** ${spec.policy.rateLimit.rpm} rpm per ${spec.policy.rateLimit.key}`);
|
|
135
|
+
if (spec.policy.flags?.length) lines.push(`- **Feature Flags:** ${spec.policy.flags.join(", ")}`);
|
|
136
|
+
if (spec.policy.pii?.length) lines.push(`- **PII Fields:** ${spec.policy.pii.join(", ")}`);
|
|
137
|
+
if (spec.policy.escalate) lines.push(`- **Escalation:** ${spec.policy.escalate}`);
|
|
138
|
+
lines.push("");
|
|
139
|
+
}
|
|
140
|
+
if (opts.includeSideEffects && spec.sideEffects) {
|
|
141
|
+
if (spec.sideEffects.emits?.length) {
|
|
142
|
+
lines.push("## Events Emitted");
|
|
143
|
+
lines.push("");
|
|
144
|
+
for (const e of spec.sideEffects.emits) if (isEmitDeclRef(e)) lines.push(`- \`${e.ref.name}.v${e.ref.version}\` — ${e.when}`);
|
|
145
|
+
else lines.push(`- \`${e.name}.v${e.version}\` — ${e.when}`);
|
|
146
|
+
lines.push("");
|
|
147
|
+
}
|
|
148
|
+
if (spec.sideEffects.analytics?.length) {
|
|
149
|
+
lines.push("## Analytics Events");
|
|
150
|
+
lines.push("");
|
|
151
|
+
for (const a of spec.sideEffects.analytics) lines.push(`- ${a}`);
|
|
152
|
+
lines.push("");
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
if (opts.includeScenarios && spec.acceptance?.scenarios?.length) {
|
|
156
|
+
lines.push("## Acceptance Scenarios");
|
|
157
|
+
lines.push("");
|
|
158
|
+
for (const s of spec.acceptance.scenarios) {
|
|
159
|
+
lines.push(`### ${s.name}`);
|
|
160
|
+
lines.push("");
|
|
161
|
+
lines.push("**Given:**");
|
|
162
|
+
for (const g of s.given) lines.push(`- ${g}`);
|
|
163
|
+
lines.push("");
|
|
164
|
+
lines.push("**When:**");
|
|
165
|
+
for (const w of s.when) lines.push(`- ${w}`);
|
|
166
|
+
lines.push("");
|
|
167
|
+
lines.push("**Then:**");
|
|
168
|
+
for (const t of s.then) lines.push(`- ${t}`);
|
|
169
|
+
lines.push("");
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
if (opts.includeExamples && spec.acceptance?.examples?.length) {
|
|
173
|
+
lines.push("## Examples");
|
|
174
|
+
lines.push("");
|
|
175
|
+
for (const ex of spec.acceptance.examples) {
|
|
176
|
+
lines.push(`### ${ex.name}`);
|
|
177
|
+
lines.push("");
|
|
178
|
+
lines.push("**Input:**");
|
|
179
|
+
lines.push("```json");
|
|
180
|
+
lines.push(JSON.stringify(ex.input, null, 2));
|
|
181
|
+
lines.push("```");
|
|
182
|
+
lines.push("");
|
|
183
|
+
lines.push("**Output:**");
|
|
184
|
+
lines.push("```json");
|
|
185
|
+
lines.push(JSON.stringify(ex.output, null, 2));
|
|
186
|
+
lines.push("```");
|
|
187
|
+
lines.push("");
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
if (spec.transport) {
|
|
191
|
+
lines.push("## Transport Configuration");
|
|
192
|
+
lines.push("");
|
|
193
|
+
if (spec.transport.rest) lines.push(`- **REST:** ${spec.transport.rest.method ?? "POST"} ${spec.transport.rest.path ?? "auto"}`);
|
|
194
|
+
if (spec.transport.gql) lines.push(`- **GraphQL:** ${spec.transport.gql.field ?? "auto"}`);
|
|
195
|
+
if (spec.transport.mcp) lines.push(`- **MCP Tool:** ${spec.transport.mcp.toolName ?? "auto"}`);
|
|
196
|
+
lines.push("");
|
|
197
|
+
}
|
|
198
|
+
return lines.join("\n");
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* Export a single spec as an actionable agent prompt.
|
|
202
|
+
* Includes: instructions, full spec, expected output format.
|
|
203
|
+
* Best for: Directly feeding to coding agents for implementation.
|
|
204
|
+
*/
|
|
205
|
+
function specToAgentPrompt(spec, options) {
|
|
206
|
+
const taskType = options?.taskType ?? "implement";
|
|
207
|
+
const m = spec.meta;
|
|
208
|
+
const lines = [];
|
|
209
|
+
const taskVerb = {
|
|
210
|
+
implement: "Implement",
|
|
211
|
+
test: "Write tests for",
|
|
212
|
+
refactor: "Refactor",
|
|
213
|
+
review: "Review"
|
|
214
|
+
}[taskType];
|
|
215
|
+
lines.push(`# Task: ${taskVerb} ${m.name}.v${m.version}`);
|
|
216
|
+
lines.push("");
|
|
217
|
+
lines.push("## Context");
|
|
218
|
+
lines.push("");
|
|
219
|
+
lines.push(`You are working on a ContractSpec-driven codebase. This spec defines a ${m.kind} operation.`);
|
|
220
|
+
lines.push("");
|
|
221
|
+
lines.push(`**Goal:** ${m.goal}`);
|
|
222
|
+
lines.push("");
|
|
223
|
+
lines.push(`**Background:** ${m.context}`);
|
|
224
|
+
lines.push("");
|
|
225
|
+
lines.push("## Specification");
|
|
226
|
+
lines.push("");
|
|
227
|
+
lines.push(specToFullMarkdown(spec));
|
|
228
|
+
lines.push("");
|
|
229
|
+
lines.push("## Instructions");
|
|
230
|
+
lines.push("");
|
|
231
|
+
if (taskType === "implement") {
|
|
232
|
+
lines.push("Implement this specification following these requirements:");
|
|
233
|
+
lines.push("");
|
|
234
|
+
lines.push("1. **Type Safety**: Use TypeScript with strict typing. No `any` types.");
|
|
235
|
+
lines.push("2. **Input Validation**: Validate input against the schema before processing.");
|
|
236
|
+
lines.push("3. **Error Handling**: Implement all error cases defined in the spec.");
|
|
237
|
+
lines.push("4. **Events**: Emit events as specified in sideEffects.emits.");
|
|
238
|
+
lines.push("5. **Policy**: Respect auth, rate limits, and feature flags.");
|
|
239
|
+
lines.push("6. **Idempotency**: " + (spec.policy.idempotent ? "This operation MUST be idempotent." : "This operation may have side effects."));
|
|
240
|
+
lines.push("");
|
|
241
|
+
if (spec.policy.pii?.length) {
|
|
242
|
+
lines.push("**PII Handling**: The following fields contain PII and must be handled carefully:");
|
|
243
|
+
for (const field of spec.policy.pii) lines.push(`- ${field}`);
|
|
244
|
+
lines.push("");
|
|
245
|
+
}
|
|
246
|
+
} else if (taskType === "test") {
|
|
247
|
+
lines.push("Write comprehensive tests for this specification:");
|
|
248
|
+
lines.push("");
|
|
249
|
+
lines.push("1. Test all acceptance scenarios defined in the spec.");
|
|
250
|
+
lines.push("2. Test all error cases with appropriate assertions.");
|
|
251
|
+
lines.push("3. Test edge cases and boundary conditions.");
|
|
252
|
+
lines.push("4. Verify events are emitted correctly.");
|
|
253
|
+
lines.push("5. Use descriptive test names following the pattern: \"should [behavior] when [condition]\"");
|
|
254
|
+
lines.push("");
|
|
255
|
+
} else if (taskType === "refactor") {
|
|
256
|
+
lines.push("Refactor this implementation while preserving all behavior:");
|
|
257
|
+
lines.push("");
|
|
258
|
+
lines.push("1. Maintain compliance with the specification.");
|
|
259
|
+
lines.push("2. Improve code clarity and maintainability.");
|
|
260
|
+
lines.push("3. Reduce complexity where possible.");
|
|
261
|
+
lines.push("4. Ensure all existing tests still pass.");
|
|
262
|
+
lines.push("");
|
|
263
|
+
} else if (taskType === "review") {
|
|
264
|
+
lines.push("Review this implementation against the specification:");
|
|
265
|
+
lines.push("");
|
|
266
|
+
lines.push("1. Verify input/output types match the schema.");
|
|
267
|
+
lines.push("2. Check all error cases are handled.");
|
|
268
|
+
lines.push("3. Verify events are emitted as specified.");
|
|
269
|
+
lines.push("4. Check policy compliance (auth, rate limits).");
|
|
270
|
+
lines.push("5. Report any deviations from the spec.");
|
|
271
|
+
lines.push("");
|
|
272
|
+
}
|
|
273
|
+
if (options?.existingCode) {
|
|
274
|
+
lines.push("## Existing Code");
|
|
275
|
+
lines.push("");
|
|
276
|
+
lines.push("```typescript");
|
|
277
|
+
lines.push(options.existingCode);
|
|
278
|
+
lines.push("```");
|
|
279
|
+
lines.push("");
|
|
280
|
+
}
|
|
281
|
+
lines.push("## Expected Output");
|
|
282
|
+
lines.push("");
|
|
283
|
+
if (taskType === "implement" || taskType === "refactor") {
|
|
284
|
+
lines.push("Provide a complete TypeScript implementation. Include:");
|
|
285
|
+
lines.push("- Type definitions for input/output");
|
|
286
|
+
lines.push("- Handler function with proper error handling");
|
|
287
|
+
lines.push("- JSDoc comments explaining the implementation");
|
|
288
|
+
} else if (taskType === "test") lines.push("Provide a complete test file using the testing framework available (prefer Vitest).");
|
|
289
|
+
else if (taskType === "review") {
|
|
290
|
+
lines.push("Provide a structured review with:");
|
|
291
|
+
lines.push("- Compliance status (pass/fail for each requirement)");
|
|
292
|
+
lines.push("- Issues found with severity (error/warning/info)");
|
|
293
|
+
lines.push("- Suggestions for improvement");
|
|
294
|
+
}
|
|
295
|
+
lines.push("");
|
|
296
|
+
return lines.join("\n");
|
|
297
|
+
}
|
|
298
|
+
/**
|
|
299
|
+
* Export a feature module to markdown.
|
|
300
|
+
* Includes all related specs, events, and presentations.
|
|
301
|
+
*/
|
|
302
|
+
function featureToMarkdown(feature, deps, options = {}) {
|
|
303
|
+
const opts = {
|
|
304
|
+
...DEFAULT_FEATURE_OPTIONS,
|
|
305
|
+
...options
|
|
306
|
+
};
|
|
307
|
+
const m = feature.meta;
|
|
308
|
+
const lines = [];
|
|
309
|
+
lines.push(`# Feature: ${m.title ?? m.key}`);
|
|
310
|
+
lines.push("");
|
|
311
|
+
if (m.description) {
|
|
312
|
+
lines.push(`> ${m.description}`);
|
|
313
|
+
lines.push("");
|
|
314
|
+
}
|
|
315
|
+
lines.push("## Overview");
|
|
316
|
+
lines.push("");
|
|
317
|
+
lines.push(`- **Key:** \`${m.key}\``);
|
|
318
|
+
lines.push(`- **Stability:** ${m.stability}`);
|
|
319
|
+
lines.push(`- **Owners:** ${m.owners.join(", ")}`);
|
|
320
|
+
if (m.tags?.length) lines.push(`- **Tags:** ${m.tags.join(", ")}`);
|
|
321
|
+
lines.push("");
|
|
322
|
+
if (feature.operations?.length) {
|
|
323
|
+
lines.push("## Operations");
|
|
324
|
+
lines.push("");
|
|
325
|
+
lines.push("| Name | Version | Type |");
|
|
326
|
+
lines.push("|------|---------|------|");
|
|
327
|
+
for (const op of feature.operations) {
|
|
328
|
+
const kind = (deps?.specs?.getSpec(op.name, op.version))?.meta.kind ?? "unknown";
|
|
329
|
+
lines.push(`| ${op.name} | v${op.version} | ${kind} |`);
|
|
330
|
+
}
|
|
331
|
+
lines.push("");
|
|
332
|
+
if (opts.includeRelatedSpecs && deps?.specs) {
|
|
333
|
+
lines.push("### Operation Details");
|
|
334
|
+
lines.push("");
|
|
335
|
+
for (const op of feature.operations) {
|
|
336
|
+
const spec = deps.specs.getSpec(op.name, op.version);
|
|
337
|
+
if (spec) {
|
|
338
|
+
lines.push(`---`);
|
|
339
|
+
lines.push("");
|
|
340
|
+
lines.push(specToFullMarkdown(spec, opts));
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
if (feature.events?.length) {
|
|
346
|
+
lines.push("## Events");
|
|
347
|
+
lines.push("");
|
|
348
|
+
lines.push("| Name | Version |");
|
|
349
|
+
lines.push("|------|---------|");
|
|
350
|
+
for (const evt of feature.events) lines.push(`| ${evt.name} | v${evt.version} |`);
|
|
351
|
+
lines.push("");
|
|
352
|
+
}
|
|
353
|
+
if (feature.presentations?.length) {
|
|
354
|
+
lines.push("## Presentations");
|
|
355
|
+
lines.push("");
|
|
356
|
+
lines.push("| Name | Version |");
|
|
357
|
+
lines.push("|------|---------|");
|
|
358
|
+
for (const pres of feature.presentations) lines.push(`| ${pres.name} | v${pres.version} |`);
|
|
359
|
+
lines.push("");
|
|
360
|
+
if (opts.includeRelatedPresentations && deps?.presentations) {
|
|
361
|
+
lines.push("### Presentation Details");
|
|
362
|
+
lines.push("");
|
|
363
|
+
for (const pres of feature.presentations) {
|
|
364
|
+
const p = deps.presentations.get(pres.name, pres.version);
|
|
365
|
+
if (p) {
|
|
366
|
+
lines.push(`#### ${pres.name}.v${pres.version}`);
|
|
367
|
+
lines.push("");
|
|
368
|
+
lines.push(`- **Kind:** ${p.content.kind ?? "unknown"}`);
|
|
369
|
+
if ("componentKey" in p.content) lines.push(`- **Component:** ${p.content.componentKey}`);
|
|
370
|
+
lines.push("");
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
if (feature.capabilities) {
|
|
376
|
+
if (feature.capabilities.provides?.length) {
|
|
377
|
+
lines.push("## Capabilities Provided");
|
|
378
|
+
lines.push("");
|
|
379
|
+
for (const cap of feature.capabilities.provides) lines.push(`- \`${cap.key}.v${cap.version}\``);
|
|
380
|
+
lines.push("");
|
|
381
|
+
}
|
|
382
|
+
if (feature.capabilities.requires?.length) {
|
|
383
|
+
lines.push("## Capabilities Required");
|
|
384
|
+
lines.push("");
|
|
385
|
+
for (const cap of feature.capabilities.requires) lines.push(`- \`${cap.key}\`${cap.version ? `.v${cap.version}` : ""} (${cap.optional ? "optional" : "required"})`);
|
|
386
|
+
lines.push("");
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
return lines.join("\n");
|
|
390
|
+
}
|
|
391
|
+
/**
|
|
392
|
+
* Export a presentation descriptor to markdown.
|
|
393
|
+
*/
|
|
394
|
+
function presentationToMarkdown(presentation) {
|
|
395
|
+
const m = presentation.meta;
|
|
396
|
+
const lines = [];
|
|
397
|
+
lines.push(`# Presentation: ${m.name}.v${m.version}`);
|
|
398
|
+
lines.push("");
|
|
399
|
+
if (m.description) {
|
|
400
|
+
lines.push(`> ${m.description}`);
|
|
401
|
+
lines.push("");
|
|
402
|
+
}
|
|
403
|
+
lines.push("## Metadata");
|
|
404
|
+
lines.push("");
|
|
405
|
+
lines.push(`- **Name:** ${m.name}`);
|
|
406
|
+
lines.push(`- **Version:** ${m.version}`);
|
|
407
|
+
if (m.stability) lines.push(`- **Stability:** ${m.stability}`);
|
|
408
|
+
if (m.owners?.length) lines.push(`- **Owners:** ${m.owners.join(", ")}`);
|
|
409
|
+
if (m.tags?.length) lines.push(`- **Tags:** ${m.tags.join(", ")}`);
|
|
410
|
+
lines.push("");
|
|
411
|
+
lines.push("## Source");
|
|
412
|
+
lines.push("");
|
|
413
|
+
lines.push(`- **Type:** ${presentation.source.type}`);
|
|
414
|
+
if (presentation.source.type === "component") {
|
|
415
|
+
lines.push(`- **Framework:** ${presentation.source.framework}`);
|
|
416
|
+
lines.push(`- **Component Key:** ${presentation.source.componentKey}`);
|
|
417
|
+
}
|
|
418
|
+
lines.push("");
|
|
419
|
+
lines.push("## Supported Targets");
|
|
420
|
+
lines.push("");
|
|
421
|
+
for (const target of presentation.targets) lines.push(`- ${target}`);
|
|
422
|
+
lines.push("");
|
|
423
|
+
if (presentation.policy) {
|
|
424
|
+
lines.push("## Policy");
|
|
425
|
+
lines.push("");
|
|
426
|
+
if (presentation.policy.flags?.length) lines.push(`- **Feature Flags:** ${presentation.policy.flags.join(", ")}`);
|
|
427
|
+
if (presentation.policy.pii?.length) lines.push(`- **PII Fields:** ${presentation.policy.pii.join(", ")}`);
|
|
428
|
+
lines.push("");
|
|
429
|
+
}
|
|
430
|
+
return lines.join("\n");
|
|
431
|
+
}
|
|
432
|
+
/**
|
|
433
|
+
* Export an event spec to markdown.
|
|
434
|
+
*/
|
|
435
|
+
function eventToMarkdown(event) {
|
|
436
|
+
const lines = [];
|
|
437
|
+
lines.push(`# Event: ${event.name}.v${event.version}`);
|
|
438
|
+
lines.push("");
|
|
439
|
+
lines.push("## Metadata");
|
|
440
|
+
lines.push("");
|
|
441
|
+
lines.push(`- **Name:** ${event.name}`);
|
|
442
|
+
lines.push(`- **Version:** ${event.version}`);
|
|
443
|
+
if (event.description) lines.push(`- **Description:** ${event.description}`);
|
|
444
|
+
lines.push("");
|
|
445
|
+
lines.push("## Payload Schema");
|
|
446
|
+
lines.push("");
|
|
447
|
+
lines.push("```json");
|
|
448
|
+
try {
|
|
449
|
+
const zodSchema = event.payload.getZod();
|
|
450
|
+
if ("shape" in zodSchema && zodSchema.shape) {
|
|
451
|
+
const shape = zodSchema.shape;
|
|
452
|
+
const fields = Object.keys(shape);
|
|
453
|
+
lines.push(JSON.stringify({ fields }, null, 2));
|
|
454
|
+
} else lines.push("// Payload schema available at runtime");
|
|
455
|
+
} catch {
|
|
456
|
+
lines.push("// Schema details available at runtime");
|
|
457
|
+
}
|
|
458
|
+
lines.push("```");
|
|
459
|
+
lines.push("");
|
|
460
|
+
return lines.join("\n");
|
|
461
|
+
}
|
|
462
|
+
/**
|
|
463
|
+
* Export a DocBlock to markdown (already markdown, but formatted consistently).
|
|
464
|
+
*/
|
|
465
|
+
function docBlockToMarkdown(doc) {
|
|
466
|
+
const lines = [];
|
|
467
|
+
lines.push(`# ${doc.title}`);
|
|
468
|
+
lines.push("");
|
|
469
|
+
if (doc.summary) {
|
|
470
|
+
lines.push(`> ${doc.summary}`);
|
|
471
|
+
lines.push("");
|
|
472
|
+
}
|
|
473
|
+
lines.push("## Metadata");
|
|
474
|
+
lines.push("");
|
|
475
|
+
lines.push(`- **ID:** ${doc.id}`);
|
|
476
|
+
lines.push(`- **Kind:** ${doc.kind ?? "reference"}`);
|
|
477
|
+
lines.push(`- **Visibility:** ${doc.visibility ?? "public"}`);
|
|
478
|
+
if (doc.tags?.length) lines.push(`- **Tags:** ${doc.tags.join(", ")}`);
|
|
479
|
+
if (doc.owners?.length) lines.push(`- **Owners:** ${doc.owners.join(", ")}`);
|
|
480
|
+
if (doc.domain) lines.push(`- **Domain:** ${doc.domain}`);
|
|
481
|
+
lines.push("");
|
|
482
|
+
lines.push("## Content");
|
|
483
|
+
lines.push("");
|
|
484
|
+
lines.push(doc.body);
|
|
485
|
+
lines.push("");
|
|
486
|
+
if (doc.links?.length) {
|
|
487
|
+
lines.push("## Related Links");
|
|
488
|
+
lines.push("");
|
|
489
|
+
for (const link of doc.links) lines.push(`- [${link.label}](${link.href})`);
|
|
490
|
+
lines.push("");
|
|
491
|
+
}
|
|
492
|
+
return lines.join("\n");
|
|
493
|
+
}
|
|
494
|
+
/**
|
|
495
|
+
* Export a spec with a specific format.
|
|
496
|
+
* Convenience function that wraps the format-specific functions.
|
|
497
|
+
*/
|
|
498
|
+
function exportSpec(spec, options = {}) {
|
|
499
|
+
const format = options.format ?? "full";
|
|
500
|
+
let markdown;
|
|
501
|
+
switch (format) {
|
|
502
|
+
case "context":
|
|
503
|
+
markdown = specToContextMarkdown(spec);
|
|
504
|
+
break;
|
|
505
|
+
case "prompt":
|
|
506
|
+
markdown = specToAgentPrompt(spec);
|
|
507
|
+
break;
|
|
508
|
+
case "full":
|
|
509
|
+
default:
|
|
510
|
+
markdown = specToFullMarkdown(spec, options);
|
|
511
|
+
break;
|
|
512
|
+
}
|
|
513
|
+
return {
|
|
514
|
+
spec,
|
|
515
|
+
markdown,
|
|
516
|
+
format,
|
|
517
|
+
meta: {
|
|
518
|
+
specName: spec.meta.name,
|
|
519
|
+
specVersion: spec.meta.version,
|
|
520
|
+
exportedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
521
|
+
wordCount: markdown.split(/\s+/).length
|
|
522
|
+
}
|
|
523
|
+
};
|
|
524
|
+
}
|
|
525
|
+
/**
|
|
526
|
+
* Export a feature with a specific format.
|
|
527
|
+
*/
|
|
528
|
+
function exportFeature(feature, deps, options = {}) {
|
|
529
|
+
const format = options.format ?? "full";
|
|
530
|
+
return {
|
|
531
|
+
feature,
|
|
532
|
+
markdown: featureToMarkdown(feature, deps, options),
|
|
533
|
+
format,
|
|
534
|
+
includedSpecs: feature.operations?.map((o) => `${o.name}.v${o.version}`) ?? [],
|
|
535
|
+
includedEvents: feature.events?.map((e) => `${e.name}.v${e.version}`) ?? [],
|
|
536
|
+
includedPresentations: feature.presentations?.map((p) => `${p.name}.v${p.version}`) ?? []
|
|
537
|
+
};
|
|
538
|
+
}
|
|
539
|
+
|
|
540
|
+
//#endregion
|
|
541
|
+
export { docBlockToMarkdown, eventToMarkdown, exportFeature, exportSpec, featureToMarkdown, presentationToMarkdown, specToAgentPrompt, specToContextMarkdown, specToFullMarkdown };
|
package/dist/llm/index.js
CHANGED
|
@@ -1 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { docBlockToMarkdown, eventToMarkdown, exportFeature, exportSpec, featureToMarkdown, presentationToMarkdown, specToAgentPrompt, specToContextMarkdown, specToFullMarkdown } from "./exporters.js";
|
|
2
|
+
import { AGENT_SYSTEM_PROMPTS, formatPlanForAgent, generateFixViolationsPrompt, generateImplementationPlan, generateImplementationPrompt, generateReviewPrompt, generateTestPrompt, generateVerificationPrompt } from "./prompts.js";
|
|
3
|
+
|
|
4
|
+
export { AGENT_SYSTEM_PROMPTS, docBlockToMarkdown, eventToMarkdown, exportFeature, exportSpec, featureToMarkdown, formatPlanForAgent, generateFixViolationsPrompt, generateImplementationPlan, generateImplementationPrompt, generateReviewPrompt, generateTestPrompt, generateVerificationPrompt, presentationToMarkdown, specToAgentPrompt, specToContextMarkdown, specToFullMarkdown };
|